Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12,332 changes: 7,316 additions & 5,016 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,8 @@
"devDependencies": {
"execa": "^9.0.2",
"npm-run-all": "^4.1.5"
},
"resolutions": {
"@types/react": "^18.2.0"
}
}
5 changes: 4 additions & 1 deletion packages/quill/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@
"webpack": "^5.89.0",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^4.15.1",
"webpack-merge": "^5.10.0"
"webpack-merge": "^5.10.0",
"@types/jest": "^29.5.0",
"expect": "^29.7.0",
"pretty-format": "^29.7.0"
},
"license": "BSD-3-Clause",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/quill/src/core/quill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class Quill {
const overwrite = !!args[2];

if (this.imports[path] != null && !overwrite) {
debug.warn(`Overwriting ${path} with`, target);
// debug.warn(`Overwriting ${path} with`, target);
}
this.imports[path] = target;
if (
Expand Down
112 changes: 80 additions & 32 deletions packages/quill/src/modules/keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,19 @@ class Keyboard extends Module<KeyboardOptions> {
const matches = bindings.filter((binding) =>
Keyboard.match(evt, binding),
);
if (matches.length === 0) return;
const range = this.quill.getSelection();
if (range == null || !this.quill.hasFocus()) return;
if (matches.length === 0) {
// Customized for TextJam: Allows us to prevent typing in read-only areas
this.handleUnboundKeyEvent(evt, range);
return;
}
else if (!this.handleBoundKeyEvent(evt, range)) {
return;
}
// @ts-expect-error
const blot = Quill.find(evt.target, true);
if (blot && blot.scroll !== this.quill.scroll) return;
const range = this.quill.getSelection();
if (range == null || !this.quill.hasFocus()) return;
const [line, offset] = this.quill.getLine(range.index);
const [leafStart, offsetStart] = this.quill.getLeaf(range.index);
const [leafEnd, offsetEnd] =
Expand All @@ -215,6 +222,7 @@ class Keyboard extends Module<KeyboardOptions> {
suffix: suffixText,
event: evt,
};

const prevented = matches.some((binding) => {
if (
binding.collapsed != null &&
Expand Down Expand Up @@ -259,12 +267,20 @@ class Keyboard extends Module<KeyboardOptions> {
// @ts-expect-error Fix me later
return binding.handler.call(this, range, curContext, binding) !== true;
});

if (prevented) {
evt.preventDefault();
}
});
}

handleUnboundKeyEvent(evt: KeyboardEvent, range: Range) {
}

handleBoundKeyEvent(evt: KeyboardEvent, range: Range) {
return true;
}

handleBackspace(range: Range, context: Context) {
// Check for astral symbols
const length = /[\uD800-\uDBFF][\uDC00-\uDFFF]$/.test(context.prefix)
Expand Down Expand Up @@ -332,6 +348,7 @@ class Keyboard extends Module<KeyboardOptions> {
}

handleEnter(range: Range, context: Context) {
//console.log('🪶 Quill - handleEnter: ', range, context);
const lineFormats = Object.keys(context.format).reduce(
(formats: Record<string, unknown>, format) => {
if (
Expand All @@ -344,13 +361,65 @@ class Keyboard extends Module<KeyboardOptions> {
},
{},
);

// [Customized for TextJam]
// If there is a space character at the end of the line when we hit enter, delete it
//const isSpaceAtEnd = range.index + range.length - 1 > 0 && this.quill.getText(range.index + range.length - 1, 1) === ' ';
//const deleteExtraLength = isSpaceAtEnd ? 1 : 0;
const deleteExtraLength = 0;

// [Customized for TextJam]
// Go ahead and apply our deltas now, and adjust if we're deleting a space
const delta = new Delta()
.retain(range.index)
.delete(range.length)
.retain(range.index - deleteExtraLength)
.delete(range.length + deleteExtraLength)
.insert('\n', lineFormats);
this.quill.updateContents(delta, Quill.sources.USER);
this.quill.setSelection(range.index + 1, Quill.sources.SILENT);
this.quill.setSelection(range.index + 1 - deleteExtraLength, Quill.sources.SILENT);
this.quill.focus();

// [Customized for TextJam]
// Preserve the format of the text from the prior line
// Reverted from earlier version of Quill
/*
Object.keys(context.format).forEach(name => {
if (lineFormats[name] != null) return;
if (Array.isArray(context.format[name])) return;
if (name === 'code' || name === 'link') return;
this.quill.format(name, context.format[name], Quill.sources.USER);
});*/

}

handleEnterOnCheckedListItem(range: Range, context: Context) {
const [line, offset] = this.quill.getLine(range.index);
const formats = {
// @ts-expect-error Fix me later
...line.formats(),
list: 'checked',
};
const delta = new Delta()
.retain(range.index)
.insert('\n', formats)
// @ts-expect-error Fix me later
.retain(line.length() - offset - 1)
.retain(1, { list: 'unchecked' });
this.quill.updateContents(delta, Quill.sources.USER);
this.quill.setSelection(range.index + 1, Quill.sources.SILENT);
this.quill.scrollSelectionIntoView();
}

handleEnterOnHeaderLine(range: Range, context: Context) {
const [line, offset] = this.quill.getLine(range.index);
const delta = new Delta()
.retain(range.index)
.insert('\n', context.format)
// @ts-expect-error Fix me later
.retain(line.length() - offset - 1)
.retain(1, { header: null });
this.quill.updateContents(delta, Quill.sources.USER);
this.quill.setSelection(range.index + 1, Quill.sources.SILENT);
this.quill.scrollSelectionIntoView();
}
}

Expand Down Expand Up @@ -454,22 +523,9 @@ const defaultOptions: KeyboardOptions = {
key: 'Enter',
collapsed: true,
format: { list: 'checked' },
handler(range) {
const [line, offset] = this.quill.getLine(range.index);
const formats = {
// @ts-expect-error Fix me later
...line.formats(),
list: 'checked',
};
const delta = new Delta()
.retain(range.index)
.insert('\n', formats)
// @ts-expect-error Fix me later
.retain(line.length() - offset - 1)
.retain(1, { list: 'unchecked' });
this.quill.updateContents(delta, Quill.sources.USER);
this.quill.setSelection(range.index + 1, Quill.sources.SILENT);
this.quill.scrollSelectionIntoView();
handler(range, context) {
const keyboard = this.quill.getModule('keyboard') as Keyboard;
return keyboard.handleEnterOnCheckedListItem(range, context);
},
},
'header enter': {
Expand All @@ -478,16 +534,8 @@ const defaultOptions: KeyboardOptions = {
format: ['header'],
suffix: /^$/,
handler(range, context) {
const [line, offset] = this.quill.getLine(range.index);
const delta = new Delta()
.retain(range.index)
.insert('\n', context.format)
// @ts-expect-error Fix me later
.retain(line.length() - offset - 1)
.retain(1, { header: null });
this.quill.updateContents(delta, Quill.sources.USER);
this.quill.setSelection(range.index + 1, Quill.sources.SILENT);
this.quill.scrollSelectionIntoView();
const keyboard = this.quill.getModule('keyboard') as Keyboard;
return keyboard.handleEnterOnHeaderLine(range, context);
},
},
'table backspace': {
Expand Down
17 changes: 12 additions & 5 deletions packages/quill/src/modules/uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ import Emitter from '../core/emitter.js';
import Module from '../core/module.js';
import type { Range } from '../core/selection.js';

declare global {
interface Document {
caretPositionFromPoint(x: number, y: number): { offsetNode: Node; offset: number } | null;
caretRangeFromPoint(x: number, y: number): globalThis.Range | null;
}
}

interface UploaderOptions {
mimetypes: string[];
handler: (this: { quill: Quill }, range: Range, files: File[]) => void;
Expand All @@ -19,13 +26,13 @@ class Uploader extends Module<UploaderOptions> {
let native: ReturnType<typeof document.createRange> | null = null;
if (document.caretRangeFromPoint) {
native = document.caretRangeFromPoint(e.clientX, e.clientY);
// @ts-expect-error
} else if (document.caretPositionFromPoint) {
// @ts-expect-error
const position = document.caretPositionFromPoint(e.clientX, e.clientY);
native = document.createRange();
native.setStart(position.offsetNode, position.offset);
native.setEnd(position.offsetNode, position.offset);
if (position) {
native = document.createRange();
native.setStart(position.offsetNode, position.offset);
native.setEnd(position.offsetNode, position.offset);
}
}

const normalized = native && quill.selection.normalizeNative(native);
Expand Down
7 changes: 5 additions & 2 deletions packages/quill/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
"moduleResolution": "bundler",
"strictNullChecks": true,
"noImplicitAny": true,
"noUnusedLocals": true
"noUnusedLocals": true,
"jsx": "react",
"skipLibCheck": true
},
"include": ["src/**/*", "test/**/*"]
"include": ["src/**/*", "test/**/*"],
"exclude": ["node_modules"]
}