Skip to content

Commit

Permalink
Merge pull request #59 from reedsy/catchup
Browse files Browse the repository at this point in the history
Catch up to upstream
  • Loading branch information
alecgibson authored Mar 26, 2024
2 parents 9eed99f + 1ae8f90 commit 403794e
Show file tree
Hide file tree
Showing 17 changed files with 358 additions and 72 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
# [Unreleased]

- **Clipboard** Add support for Quill v1 list attributes
- Fix overload declarations for `quill.formatText()` and other methods

# 2.0.0-rc.4

- Include source maps for Parchment
- **Clipboard** Support pasting links copied from iOS share sheets
- Fix config parsing where undefined values were kept
- Expose types for Quill options
- Remove empty .css.js files generated by bundlers

# 2.0.0-rc.3

Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Instantiate a new Quill object with a css selector for the div that should becom
```html
<!-- Include Quill stylesheet -->
<link
href="https://cdn.jsdelivr.net/npm/[email protected].2/dist/quill.snow.css"
href="https://cdn.jsdelivr.net/npm/[email protected].4/dist/quill.snow.css"
rel="stylesheet"
/>

Expand All @@ -67,7 +67,7 @@ Instantiate a new Quill object with a css selector for the div that should becom
</div>

<!-- Include the Quill library -->
<script src="https://cdn.jsdelivr.net/npm/[email protected].2/dist/quill.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected].4/dist/quill.js"></script>

<!-- Initialize Quill editor -->
<script>
Expand All @@ -89,24 +89,24 @@ npm install quill@rc

```html
<!-- Main Quill library -->
<script src="https://cdn.jsdelivr.net/npm/[email protected].2/dist/quill.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected].4/dist/quill.js"></script>

<!-- Theme included stylesheets -->
<link
href="https://cdn.jsdelivr.net/npm/[email protected].2/dist/quill.snow.css"
href="https://cdn.jsdelivr.net/npm/[email protected].4/dist/quill.snow.css"
rel="stylesheet"
/>
<link
href="https://cdn.jsdelivr.net/npm/[email protected].2/dist/quill.bubble.css"
href="https://cdn.jsdelivr.net/npm/[email protected].4/dist/quill.bubble.css"
rel="stylesheet"
/>

<!-- Core build with no theme, formatting, non-essential modules -->
<link
href="https://cdn.jsdelivr.net/npm/[email protected].2/dist/quill.core.css"
href="https://cdn.jsdelivr.net/npm/[email protected].4/dist/quill.core.css"
rel="stylesheet"
/>
<script src="https://cdn.jsdelivr.net/npm/[email protected].2/dist/quill.core.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected].4/dist/quill.core.js"></script>
```

## Community
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "quill-monorepo",
"version": "2.0.0-rc.3",
"version": "2.0.0-rc.4",
"description": "Quill development environment",
"private": true,
"author": "Jason Chen <[email protected]>",
Expand Down
2 changes: 1 addition & 1 deletion packages/quill/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@reedsy/quill",
"version": "2.0.0-reedsy-5.0.3",
"version": "2.0.0-reedsy-5.0.4",
"description": "Your powerful, rich text editor",
"author": "Jason Chen <[email protected]>",
"homepage": "https://quilljs.com",
Expand Down
2 changes: 2 additions & 0 deletions packages/quill/scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ mv $TMPDIR/src/* $DIST
rm -rf $TMPDIR
npx babel src --out-dir $DIST --copy-files --no-copy-ignored --extensions .ts --source-maps
npx webpack -- --mode $1
# https://github.com/webpack-contrib/mini-css-extract-plugin/issues/151
rm -rf $DIST/dist/*.css.js $DIST/dist/*.css.js.*
cp package.json $DIST
cp README.md $DIST
cp LICENSE $DIST
11 changes: 9 additions & 2 deletions packages/quill/src/core.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import Quill from './core/quill.js';
import Quill, { Parchment, Range } from './core/quill.js';
import type {
DebugLevel,
EmitterSource,
ExpandedQuillOptions,
QuillOptions,
} from './core/quill.js';

import Block, { BlockEmbed } from './blots/block.js';
import Break from './blots/break.js';
Expand All @@ -19,7 +25,8 @@ import Composition from './core/composition.js';
import Selection from './core/selection.js';
import UINode from './modules/uiNode.js';

export { Delta, Op, OpIterator, AttributeMap };
export { Delta, Op, OpIterator, AttributeMap, Parchment, Range };
export type { DebugLevel, EmitterSource, ExpandedQuillOptions, QuillOptions };

Quill.register({
'blots/block': Block,
Expand Down
66 changes: 49 additions & 17 deletions packages/quill/src/core/quill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,41 @@ const debug = logger('quill');
const globalRegistry = new Parchment.Registry();
Parchment.ParentBlot.uiClass = 'ql-ui';

interface Options {
/**
* Options for initializing a Quill instance
*/
export interface QuillOptions {
theme?: string;
debug?: DebugLevel | boolean;
registry?: Parchment.Registry;
/**
* Whether to disable the editing
* @default false
*/
readOnly?: boolean;

/**
* Placeholder text to display when the editor is empty
* @default ""
*/
placeholder?: string;
bounds?: HTMLElement | string | null;
modules?: Record<string, unknown>;

/**
* A list of formats that are recognized and can exist within the editor contents.
* `null` means all formats are allowed.
* @default null
*/
formats?: string[] | null;
}

interface ExpandedOptions extends Omit<Options, 'theme' | 'formats'> {
/**
* Similar to QuillOptions, but with all properties expanded to their default values,
* and all selectors resolved to HTMLElements.
*/
export interface ExpandedQuillOptions
extends Omit<QuillOptions, 'theme' | 'formats'> {
theme: ThemeConstructor;
registry: Parchment.Registry;
container: HTMLElement;
Expand All @@ -64,7 +87,7 @@ class Quill {
readOnly: false,
registry: globalRegistry,
theme: 'default',
} satisfies Partial<Options>;
} satisfies Partial<QuillOptions>;
static events = Emitter.events;
static sources = Emitter.sources;
static version = typeof QUILL_VERSION === 'undefined' ? 'dev' : QUILL_VERSION;
Expand Down Expand Up @@ -146,7 +169,7 @@ class Quill {
root: HTMLDivElement;
scroll: Scroll;
emitter: Emitter;
allowReadOnlyEdits: boolean;
protected allowReadOnlyEdits: boolean;
editor: Editor;
composition: Composition;
selection: Selection;
Expand All @@ -157,9 +180,9 @@ class Quill {
history: History;
uploader: Uploader;

options: ExpandedOptions;
options: ExpandedQuillOptions;

constructor(container: HTMLElement | string, options: Options = {}) {
constructor(container: HTMLElement | string, options: QuillOptions = {}) {
this.options = expandConfig(container, options);
this.container = this.options.container;
if (this.container == null) {
Expand Down Expand Up @@ -390,7 +413,13 @@ class Quill {
length: number,
name: string,
value: unknown,
source: EmitterSource,
source?: EmitterSource,
): Delta;
formatText(
index: number,
length: number,
formats: Record<string, unknown>,
source?: EmitterSource,
): Delta;
formatText(
index: number | { index: number; length: number },
Expand Down Expand Up @@ -546,24 +575,24 @@ class Quill {
);
}

insertText(index: number, text: string, source: EmitterSource): Delta;
insertText(index: number, text: string, source?: EmitterSource): Delta;
insertText(
index: number,
text: string,
formats: Record<string, unknown>,
source: EmitterSource,
source?: EmitterSource,
): Delta;
insertText(
index: number,
text: string,
name: string,
value: unknown,
source: EmitterSource,
source?: EmitterSource,
): Delta;
insertText(
index: number,
text: string,
name: string | Record<string, unknown> | EmitterSource,
name?: string | Record<string, unknown> | EmitterSource,
value?: unknown,
source?: EmitterSource,
): Delta {
Expand Down Expand Up @@ -625,8 +654,8 @@ class Quill {
return this.emitter.once(...args);
}

removeFormat(...args: Parameters<typeof overload>) {
const [index, length, , source] = overload(...args);
removeFormat(index: number, length: number, source?: EmitterSource) {
[index, length, , source] = overload(index, length, source);
return modify.call(
this,
() => {
Expand Down Expand Up @@ -748,16 +777,16 @@ function expandModuleConfig(config: Record<string, unknown> | undefined) {
);
}

function omitUndefinedValuesFromOptions(obj: Options) {
function omitUndefinedValuesFromOptions(obj: QuillOptions) {
return Object.fromEntries(
Object.entries(obj).filter((entry) => entry[1] !== undefined),
);
}

function expandConfig(
containerOrSelector: HTMLElement | string,
options: Options,
): ExpandedOptions {
options: QuillOptions,
): ExpandedQuillOptions {
const container = resolveSelector(containerOrSelector);
if (!container) {
throw new Error('Invalid Quill container');
Expand All @@ -775,7 +804,7 @@ function expandConfig(
const { modules: quillModuleDefaults, ...quillDefaults } = Quill.DEFAULTS;
const { modules: themeModuleDefaults, ...themeDefaults } = theme.DEFAULTS;

const modules: ExpandedOptions['modules'] = merge(
const modules: ExpandedQuillOptions['modules'] = merge(
{},
expandModuleConfig(quillModuleDefaults),
expandModuleConfig(themeModuleDefaults),
Expand Down Expand Up @@ -1005,4 +1034,7 @@ function shiftRange(
return new Range(start, end - start);
}

export type { DebugLevel, EmitterSource };
export { Parchment, Range };

export { globalRegistry, expandConfig, overload, Quill as default };
10 changes: 8 additions & 2 deletions packages/quill/src/modules/clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,14 @@ function matchIndent(node: Node, delta: Delta, scroll: ScrollBlot) {
}

function matchList(node: Node, delta: Delta, scroll: ScrollBlot) {
// @ts-expect-error
const list = node.tagName === 'OL' ? 'ordered' : 'bullet';
const element = node as Element;
let list = element.tagName === 'OL' ? 'ordered' : 'bullet';

const checkedAttr = element.getAttribute('data-checked');
if (checkedAttr) {
list = checkedAttr === 'true' ? 'checked' : 'unchecked';
}

return applyFormat(delta, 'list', list, scroll);
}

Expand Down
11 changes: 10 additions & 1 deletion packages/quill/src/quill.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import Quill from './core.js';
import Quill, { Parchment, Range } from './core.js';
import type {
DebugLevel,
EmitterSource,
ExpandedQuillOptions,
QuillOptions,
} from './core.js';

import { AlignClass, AlignStyle } from './formats/align.js';
import {
Expand Down Expand Up @@ -108,4 +114,7 @@ Quill.register(
true,
);

export type { DebugLevel, EmitterSource, ExpandedQuillOptions, QuillOptions };
export { Parchment, Range };

export default Quill;
Loading

0 comments on commit 403794e

Please sign in to comment.