@quillmark/svelte 0.32.0 → 0.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +73 -1
- package/THEMING.md +11 -10
- package/dist/core/codec/anchor.d.ts +12 -0
- package/dist/core/codec/anchor.js +39 -0
- package/dist/core/codec/drag-move.d.ts +11 -0
- package/dist/core/codec/drag-move.js +143 -0
- package/dist/core/codec/encode.d.ts +2 -1
- package/dist/core/codec/encode.js +16 -6
- package/dist/core/codec/field.d.ts +47 -1
- package/dist/core/codec/field.js +201 -37
- package/dist/core/codec/index.d.ts +8 -2
- package/dist/core/codec/index.js +9 -2
- package/dist/core/codec/islands.d.ts +4 -1
- package/dist/core/codec/islands.js +6 -0
- package/dist/core/codec/keymap.d.ts +3 -0
- package/dist/core/codec/keymap.js +13 -12
- package/dist/core/codec/leave.d.ts +17 -0
- package/dist/core/codec/leave.js +78 -0
- package/dist/core/codec/prose.css +217 -0
- package/dist/core/codec/review-diff.d.ts +12 -0
- package/dist/core/codec/review-diff.js +131 -0
- package/dist/core/codec/review.d.ts +131 -0
- package/dist/core/codec/review.js +1077 -0
- package/dist/core/codec/shortcuts.d.ts +20 -4
- package/dist/core/codec/shortcuts.js +27 -7
- package/dist/core/codec/slash.d.ts +3 -0
- package/dist/core/codec/slash.js +2 -1
- package/dist/core/codec/table-view.js +163 -25
- package/dist/core/codec/undo.d.ts +6 -0
- package/dist/core/codec/undo.js +25 -2
- package/dist/core/dragfollow.d.ts +18 -0
- package/dist/core/dragfollow.js +63 -0
- package/dist/core/theme.css +36 -7
- package/dist/preview/controller.js +16 -0
- package/dist/preview/strings.d.ts +4 -0
- package/dist/preview/strings.js +3 -1
- package/dist/visual/ArrayField.svelte +363 -57
- package/dist/visual/ArrayField.svelte.d.ts +5 -0
- package/dist/visual/BooleanField.svelte +60 -5
- package/dist/visual/BooleanField.svelte.d.ts +2 -1
- package/dist/visual/Card.svelte +27 -17
- package/dist/visual/CardControls.svelte +17 -7
- package/dist/visual/CardControls.svelte.d.ts +2 -0
- package/dist/visual/DateField.svelte +90 -39
- package/dist/visual/DateField.svelte.d.ts +2 -2
- package/dist/visual/Field.svelte +126 -6
- package/dist/visual/FieldHint.svelte +24 -9
- package/dist/visual/FieldLabel.svelte +128 -22
- package/dist/visual/FieldLabel.svelte.d.ts +9 -0
- package/dist/visual/FormatPopover.svelte +125 -20
- package/dist/visual/MatrixAdd.svelte +13 -6
- package/dist/visual/MatrixAdd.svelte.d.ts +3 -2
- package/dist/visual/MatrixField.svelte +36 -8
- package/dist/visual/NumberField.svelte +27 -6
- package/dist/visual/NumberField.svelte.d.ts +3 -0
- package/dist/visual/ObjectField.svelte +25 -1
- package/dist/visual/ObjectField.svelte.d.ts +6 -0
- package/dist/visual/ProseField.svelte +23 -0
- package/dist/visual/ProseField.svelte.d.ts +3 -0
- package/dist/visual/ProseValue.svelte +107 -17
- package/dist/visual/ProseValue.svelte.d.ts +18 -4
- package/dist/visual/ReviewPopover.svelte +179 -0
- package/dist/visual/ReviewPopover.svelte.d.ts +16 -0
- package/dist/visual/ReviewProposal.svelte +149 -0
- package/dist/visual/ReviewProposal.svelte.d.ts +15 -0
- package/dist/visual/ReviewRows.svelte +68 -0
- package/dist/visual/ReviewRows.svelte.d.ts +11 -0
- package/dist/visual/SlashMenu.svelte +13 -1
- package/dist/visual/SlashMenu.svelte.d.ts +2 -0
- package/dist/visual/VisualEditor.svelte +23 -0
- package/dist/visual/VisualEditor.svelte.d.ts +7 -0
- package/dist/visual/VisualEditorInner.svelte +671 -22
- package/dist/visual/VisualEditorInner.svelte.d.ts +7 -0
- package/dist/visual/controls.css +17 -2
- package/dist/visual/guidance.d.ts +12 -0
- package/dist/visual/guidance.js +37 -2
- package/dist/visual/icons/nodes.d.ts +14 -2
- package/dist/visual/icons/nodes.js +12 -1
- package/dist/visual/index.d.ts +6 -0
- package/dist/visual/index.js +2 -0
- package/dist/visual/listhistory.d.ts +36 -0
- package/dist/visual/listhistory.js +53 -0
- package/dist/visual/proposals.d.ts +40 -0
- package/dist/visual/proposals.js +219 -0
- package/dist/visual/props.d.ts +35 -0
- package/dist/visual/removed.d.ts +20 -0
- package/dist/visual/removed.js +30 -0
- package/dist/visual/review.d.ts +170 -0
- package/dist/visual/review.js +269 -0
- package/dist/visual/review.svelte.d.ts +106 -0
- package/dist/visual/review.svelte.js +356 -0
- package/dist/visual/rowdrag.svelte.js +44 -55
- package/dist/visual/strings.d.ts +48 -7
- package/dist/visual/strings.js +32 -7
- package/dist/visual/structure.d.ts +5 -0
- package/dist/visual/structure.js +1 -1
- package/dist/visual/undo.svelte.d.ts +40 -7
- package/dist/visual/undo.svelte.js +98 -25
- package/package.json +1 -1
package/dist/core/codec/field.js
CHANGED
|
@@ -26,11 +26,14 @@ import { anchorsFromContent } from './marks.js';
|
|
|
26
26
|
import { contentEqual, createReconciler } from './reconcile.js';
|
|
27
27
|
import { inputRulesPlugin, undoRuleKeymap } from './inputrules.js';
|
|
28
28
|
import { linebreakPlugin } from './breaks.js';
|
|
29
|
-
import { bodyKeymap } from './keymap.js';
|
|
29
|
+
import { bodyKeymap, holdsTab } from './keymap.js';
|
|
30
|
+
import { DEFAULT_LEAVE_STRINGS, leavePlugin } from './leave.js';
|
|
30
31
|
import { FIELD_KEYS, markKeymap } from './shortcuts.js';
|
|
31
32
|
import { remoteKey } from './remote.js';
|
|
33
|
+
import { DEFAULT_REVIEW_STRINGS, renameBlocks, reviewLayer } from './review.js';
|
|
32
34
|
import { blockSchema, isBlockSchema, isInlineSchema, leafSchema, plainSchema } from './schema.js';
|
|
33
35
|
import { linkPastePlugin } from './link-paste.js';
|
|
36
|
+
import { dragMovePlugin } from './drag-move.js';
|
|
34
37
|
import { linePastePlugin } from './line-paste.js';
|
|
35
38
|
import { listPastePlugin } from './list-paste.js';
|
|
36
39
|
import { markdownPastePlugin } from './markdown-paste.js';
|
|
@@ -43,6 +46,7 @@ import { taskPlugin } from './tasks.js';
|
|
|
43
46
|
import { DEFAULT_TABLE_STRINGS, tableNodeView } from './table-view.js';
|
|
44
47
|
import { DEFAULT_SLASH_STRINGS, focusSlashItem, runSlashItem, slashPlugin } from './slash.js';
|
|
45
48
|
const anchorKey = new PluginKey('quill-anchors');
|
|
49
|
+
const NO_ANCHORS = [];
|
|
46
50
|
const GHOSTS = 100;
|
|
47
51
|
/**
|
|
48
52
|
* Plugin-held anchors (PM coords), mapped through every edit's `StepMap` and mutated by an {@link
|
|
@@ -73,6 +77,11 @@ function anchorPlugin(seed) {
|
|
|
73
77
|
}
|
|
74
78
|
else if (edit?.op === 'reset')
|
|
75
79
|
anchors = edit.anchors;
|
|
80
|
+
else if (edit?.op === 'restore') {
|
|
81
|
+
const back = new Set(edit.anchors.map((a) => a.id));
|
|
82
|
+
anchors = [...anchors.filter((a) => !back.has(a.id)), ...edit.anchors];
|
|
83
|
+
ghosts = ghosts.filter((g) => !back.has(g.id));
|
|
84
|
+
}
|
|
76
85
|
return { anchors, ghosts: ghosts.slice(-GHOSTS) };
|
|
77
86
|
}
|
|
78
87
|
},
|
|
@@ -239,6 +248,8 @@ export function createField(opts) {
|
|
|
239
248
|
/** Whether the leaf holds a default nobody has written: the `data-default` mark. */
|
|
240
249
|
const unwritten = () => !!fallback && doc.getStored(addr) == null;
|
|
241
250
|
let defaulted = unwritten();
|
|
251
|
+
/** The document the leaf last held as its unwritten default, which an undo can return to. */
|
|
252
|
+
let unwrittenDoc;
|
|
242
253
|
// `known` is the codec's view of what the leaf holds: kept in sync after every
|
|
243
254
|
// own-edit so `reconcile` can tell an external change from the field's own.
|
|
244
255
|
const reconciler = createReconciler(shown());
|
|
@@ -250,6 +261,38 @@ export function createField(opts) {
|
|
|
250
261
|
// The views nested inside this leaf, one per table cell (`table-view.ts`): chrome asks the leaf
|
|
251
262
|
// which view holds the caret.
|
|
252
263
|
const nested = new Set();
|
|
264
|
+
// The review layer's live cells: the items and the lit one move by assignment and a re-render.
|
|
265
|
+
let reviewItems = [];
|
|
266
|
+
let reviewLit;
|
|
267
|
+
const parsed = new Map();
|
|
268
|
+
const review = plaintext
|
|
269
|
+
? undefined
|
|
270
|
+
: reviewLayer({
|
|
271
|
+
items: () => reviewItems,
|
|
272
|
+
lit: () => reviewLit,
|
|
273
|
+
strings: () => opts.reviewStrings?.() ?? DEFAULT_REVIEW_STRINGS,
|
|
274
|
+
anchors: (state) => anchorKey.getState(state)?.anchors ?? NO_ANCHORS,
|
|
275
|
+
restore: (tr, anchors) => tr.setMeta(anchorKey, { op: 'restore', anchors }),
|
|
276
|
+
parse: (markdown) => {
|
|
277
|
+
if (!parsed.has(markdown)) {
|
|
278
|
+
let node;
|
|
279
|
+
try {
|
|
280
|
+
node = decode(core().importMarkdown(markdown).content, schema);
|
|
281
|
+
}
|
|
282
|
+
catch {
|
|
283
|
+
node = undefined;
|
|
284
|
+
}
|
|
285
|
+
parsed.set(markdown, node);
|
|
286
|
+
}
|
|
287
|
+
return parsed.get(markdown);
|
|
288
|
+
},
|
|
289
|
+
shown: () => opts.reviewShown?.(),
|
|
290
|
+
dismiss: () => opts.onReviewDismiss?.(),
|
|
291
|
+
act: (id, action, chord) => opts.onReview?.(id, action, chord),
|
|
292
|
+
writing: (on) => opts.onReviewWriting?.(on),
|
|
293
|
+
point: (id, via) => opts.onReviewPoint?.(id, via),
|
|
294
|
+
drew: (report) => opts.onReviewDrawn?.(report)
|
|
295
|
+
});
|
|
253
296
|
// The menu's report channel; the vocabulary is the codec's own constant (`slash.ts`).
|
|
254
297
|
const slash = block ? opts.onSlash : undefined;
|
|
255
298
|
// Judged of the value being mounted rather than read off a diagnostic: a routed set
|
|
@@ -258,11 +301,19 @@ export function createField(opts) {
|
|
|
258
301
|
const holds = (rt) => !fitsLeaf(rt, { inline, plaintext, islands: true });
|
|
259
302
|
let held = holds(reconciler.last);
|
|
260
303
|
const named = proseAttributes(opts) ?? {};
|
|
261
|
-
const defaultNamed = {
|
|
304
|
+
const defaultNamed = {
|
|
305
|
+
...proseAttributes({
|
|
306
|
+
...opts,
|
|
307
|
+
describedBy: [opts.describedBy, opts.defaultNoteId].filter(Boolean).join(' ') || undefined
|
|
308
|
+
}),
|
|
309
|
+
'data-default': ''
|
|
310
|
+
};
|
|
262
311
|
const heldNamed = heldAttributes(opts, opts.heldNoteId);
|
|
263
312
|
const seeded = buildState(reconciler.last);
|
|
264
313
|
const state = seeded.state;
|
|
265
314
|
index = seeded.index;
|
|
315
|
+
if (defaulted)
|
|
316
|
+
unwrittenDoc = state.doc;
|
|
266
317
|
// The clearance PM's reveal keeps around the caret, in this leaf's own line box: PM's 5px
|
|
267
318
|
// default leaves the next typed line past the fold. Measured off the mounted box and dropped
|
|
268
319
|
// where the derivation is out of reach (jsdom).
|
|
@@ -313,8 +364,14 @@ export function createField(opts) {
|
|
|
313
364
|
// (d) the change signal, only for what actually landed.
|
|
314
365
|
const anchors = plaintext ? [] : readAnchors();
|
|
315
366
|
const newRt = scan ? scanContent(scan, anchors) : pmToContent(next.doc, anchors);
|
|
316
|
-
|
|
367
|
+
// An undo back to the default the leaf held unwritten takes the write back too.
|
|
368
|
+
const unwrite = !!unwrittenDoc && isHistoryTransaction(tr) && next.doc.eq(unwrittenDoc);
|
|
369
|
+
if (unwrite ? commitUnset() : commitEdit(oldRt, newRt))
|
|
317
370
|
opts.onChange?.(addr);
|
|
371
|
+
if (unwrite) {
|
|
372
|
+
defaulted = unwritten();
|
|
373
|
+
view.setProps({});
|
|
374
|
+
}
|
|
318
375
|
}
|
|
319
376
|
// The caret, for structural and selection-only changes, reported after the commit.
|
|
320
377
|
opts.onCaretMove?.(addr, pmToOffset(index, next.selection.head));
|
|
@@ -349,17 +406,50 @@ export function createField(opts) {
|
|
|
349
406
|
inline,
|
|
350
407
|
slash,
|
|
351
408
|
slashHint: () => (opts.slashStrings?.() ?? DEFAULT_SLASH_STRINGS).slashHint,
|
|
409
|
+
leaveStrings: opts.leaveStrings,
|
|
352
410
|
noInputRules: opts.noInputRules,
|
|
353
411
|
// Always installed, so a leaf that mounts without a ghost can still be
|
|
354
412
|
// given one later; the plugin draws nothing while the text is empty.
|
|
355
413
|
placeholder: () => placeholderText,
|
|
356
414
|
placeholderUntilEdit: opts.placeholderUntilEdit,
|
|
357
415
|
cap: opts.cap,
|
|
358
|
-
afterHistory: [anchorPlugin(seededAnchors)]
|
|
416
|
+
afterHistory: [anchorPlugin(seededAnchors), ...(review ? [review.plugin] : [])]
|
|
359
417
|
})
|
|
360
418
|
});
|
|
361
419
|
return { state: built, index: seedIndex };
|
|
362
420
|
}
|
|
421
|
+
/** Re-read the leaf from the document: the reconciler's own edit, a landed remote replace, or
|
|
422
|
+
* a rebuild. */
|
|
423
|
+
function reread(delta) {
|
|
424
|
+
const current = shown();
|
|
425
|
+
const flipped = holds(current) !== held;
|
|
426
|
+
const wasDefaulted = defaulted;
|
|
427
|
+
defaulted = unwritten();
|
|
428
|
+
if (!flipped && !reconciler.shouldRehydrate(current)) {
|
|
429
|
+
// Own edit / no change; a default written as itself changes the mark alone.
|
|
430
|
+
if (defaulted !== wasDefaulted)
|
|
431
|
+
view.setProps({});
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
if (!flipped && !held && landRemote(current, delta)) {
|
|
435
|
+
reconciler.commit(current);
|
|
436
|
+
if (defaulted !== wasDefaulted)
|
|
437
|
+
view.setProps({});
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
if (flipped)
|
|
441
|
+
held = !held;
|
|
442
|
+
const caret = pmToOffset(index, view.state.selection.head);
|
|
443
|
+
const fresh = buildState(current);
|
|
444
|
+
index = fresh.index;
|
|
445
|
+
// Best-effort caret continuity across an external change: keep the offset. Set
|
|
446
|
+
// rather than dispatched, so a leaf the caret is not in reports no caret move.
|
|
447
|
+
const sel = Selection.near(fresh.state.doc.resolve(offsetToPM(index, caret)));
|
|
448
|
+
view.updateState(fresh.state.apply(fresh.state.tr.setSelection(sel)));
|
|
449
|
+
reconciler.commit(current);
|
|
450
|
+
if (flipped)
|
|
451
|
+
opts.onHold?.(held);
|
|
452
|
+
}
|
|
363
453
|
// (b)+(c): lower the edit to a change and commit, or `replace` a field not yet at content rest.
|
|
364
454
|
// Keeps the optimistic PM on throw. Returns whether anything landed, independent of which
|
|
365
455
|
// branch ran.
|
|
@@ -376,8 +466,12 @@ export function createField(opts) {
|
|
|
376
466
|
doc.replace(at, newRt);
|
|
377
467
|
else {
|
|
378
468
|
const change = lower(oldRt, newRt);
|
|
379
|
-
if (change)
|
|
469
|
+
if (change) {
|
|
470
|
+
const asked = askCore(oldRt, change);
|
|
380
471
|
doc.apply(at, change);
|
|
472
|
+
if (asked.size)
|
|
473
|
+
adopt();
|
|
474
|
+
}
|
|
381
475
|
}
|
|
382
476
|
reconciler.commit(readLeaf(reader, addr));
|
|
383
477
|
return true;
|
|
@@ -409,6 +503,63 @@ export function createField(opts) {
|
|
|
409
503
|
}
|
|
410
504
|
}
|
|
411
505
|
}
|
|
506
|
+
/**
|
|
507
|
+
* Each block id the projection minted for a block the store does not hold, swapped in
|
|
508
|
+
* `change` for a placeholder the write fills, so the store is the one minter of block ids:
|
|
509
|
+
* placeholder → projected id.
|
|
510
|
+
*/
|
|
511
|
+
function askCore(oldRt, change) {
|
|
512
|
+
const held = new Set(oldRt.blocks.map((b) => b.id));
|
|
513
|
+
const asked = new Map();
|
|
514
|
+
const named = new Map();
|
|
515
|
+
for (const step of change.steps) {
|
|
516
|
+
if (!('splice' in step))
|
|
517
|
+
continue;
|
|
518
|
+
for (const b of step.splice.blocks ?? []) {
|
|
519
|
+
if (held.has(b.id))
|
|
520
|
+
continue;
|
|
521
|
+
const p = `?${asked.size}`;
|
|
522
|
+
asked.set(p, b.id);
|
|
523
|
+
named.set(b.id, p);
|
|
524
|
+
b.id = p;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
for (const step of change.steps)
|
|
528
|
+
if ('setBlock' in step && named.has(step.setBlock.id))
|
|
529
|
+
step.setBlock.id = named.get(step.setBlock.id);
|
|
530
|
+
return asked;
|
|
531
|
+
}
|
|
532
|
+
/** Each block node takes the id the store holds for the block it projects to. */
|
|
533
|
+
function adopt() {
|
|
534
|
+
const stored = readLeaf(reader, addr).blocks.map((b) => b.id);
|
|
535
|
+
const nodes = [];
|
|
536
|
+
view.state.doc.descendants((node, pos) => {
|
|
537
|
+
if (node.type.name === 'island_block') {
|
|
538
|
+
nodes.push({ pos, key: 'block', id: node.attrs.block });
|
|
539
|
+
return false;
|
|
540
|
+
}
|
|
541
|
+
if (node.isTextblock || node.type.name === 'horizontal_rule') {
|
|
542
|
+
nodes.push({ pos, key: 'id', id: node.attrs.id });
|
|
543
|
+
return false;
|
|
544
|
+
}
|
|
545
|
+
return true;
|
|
546
|
+
});
|
|
547
|
+
if (nodes.length !== stored.length)
|
|
548
|
+
return;
|
|
549
|
+
const tr = view.state.tr;
|
|
550
|
+
const renamed = [];
|
|
551
|
+
nodes.forEach((n, i) => {
|
|
552
|
+
if (n.id === stored[i])
|
|
553
|
+
return;
|
|
554
|
+
tr.setNodeAttribute(n.pos, n.key, stored[i]);
|
|
555
|
+
// A split's copy of an id the first half keeps is no rename.
|
|
556
|
+
if (typeof n.id === 'string' && !stored.includes(n.id))
|
|
557
|
+
renamed.push([n.id, stored[i]]);
|
|
558
|
+
});
|
|
559
|
+
renameBlocks(tr, renamed);
|
|
560
|
+
if (tr.docChanged)
|
|
561
|
+
view.updateState(view.state.apply(tr.setMeta('addToHistory', false)));
|
|
562
|
+
}
|
|
412
563
|
/**
|
|
413
564
|
* A `text` leaf's commit: its whole text through the typed writer, resting the field as that
|
|
414
565
|
* literal string (INVARIANTS §"Inline mode"). The content-object rest form would emit markdown
|
|
@@ -463,6 +614,7 @@ export function createField(opts) {
|
|
|
463
614
|
const next = decode(rt, schema);
|
|
464
615
|
const tr = before.tr.setMeta('addToHistory', false).setMeta(remoteKey, true);
|
|
465
616
|
const start = before.doc.content.findDiffStart(next.content);
|
|
617
|
+
let span;
|
|
466
618
|
try {
|
|
467
619
|
if (start != null) {
|
|
468
620
|
let { a: endA, b: endB } = before.doc.content.findDiffEnd(next.content);
|
|
@@ -472,13 +624,22 @@ export function createField(opts) {
|
|
|
472
624
|
endB += overlap;
|
|
473
625
|
}
|
|
474
626
|
tr.replace(start, endA, next.slice(start, endB));
|
|
627
|
+
span = [start, endA];
|
|
475
628
|
}
|
|
476
629
|
if (!tr.doc.eq(next))
|
|
477
630
|
return false;
|
|
478
631
|
const after = buildLineIndex(tr.doc);
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
632
|
+
const { selection } = before;
|
|
633
|
+
// With no delta to map through, a caret inside the replaced span keeps its offset, as a
|
|
634
|
+
// rebuild keeps it: mapped, it would leave the span, and a span can be wider than what
|
|
635
|
+
// changed where a block's container ids differ from the store's.
|
|
636
|
+
const replaced = !!span && span[0] <= selection.from && selection.to <= span[1];
|
|
637
|
+
if (selection instanceof TextSelection && (delta || replaced)) {
|
|
638
|
+
const at = (pm) => {
|
|
639
|
+
const offset = pmToOffset(index, pm);
|
|
640
|
+
return offsetToPM(after, delta ? mapThroughDelta(delta, offset) : offset);
|
|
641
|
+
};
|
|
642
|
+
tr.setSelection(TextSelection.between(tr.doc.resolve(at(selection.anchor)), tr.doc.resolve(at(selection.head))));
|
|
482
643
|
}
|
|
483
644
|
if (!plaintext)
|
|
484
645
|
tr.setMeta(anchorKey, {
|
|
@@ -518,34 +679,8 @@ export function createField(opts) {
|
|
|
518
679
|
view.dispatch(view.state.tr.setSelection(sel).scrollIntoView());
|
|
519
680
|
},
|
|
520
681
|
applyExternal(delta) {
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
const wasDefaulted = defaulted;
|
|
524
|
-
defaulted = unwritten();
|
|
525
|
-
if (!flipped && !reconciler.shouldRehydrate(current)) {
|
|
526
|
-
// Own edit / no change; a default written as itself changes the mark alone.
|
|
527
|
-
if (defaulted !== wasDefaulted)
|
|
528
|
-
view.setProps({});
|
|
529
|
-
return;
|
|
530
|
-
}
|
|
531
|
-
if (!flipped && !held && landRemote(current, delta)) {
|
|
532
|
-
reconciler.commit(current);
|
|
533
|
-
if (defaulted !== wasDefaulted)
|
|
534
|
-
view.setProps({});
|
|
535
|
-
return;
|
|
536
|
-
}
|
|
537
|
-
if (flipped)
|
|
538
|
-
held = !held;
|
|
539
|
-
const caret = pmToOffset(index, view.state.selection.head);
|
|
540
|
-
const fresh = buildState(current);
|
|
541
|
-
index = fresh.index;
|
|
542
|
-
// Best-effort caret continuity across an external change: keep the offset. Set
|
|
543
|
-
// rather than dispatched, so a leaf the caret is not in reports no caret move.
|
|
544
|
-
const sel = Selection.near(fresh.state.doc.resolve(offsetToPM(index, caret)));
|
|
545
|
-
view.updateState(fresh.state.apply(fresh.state.tr.setSelection(sel)));
|
|
546
|
-
reconciler.commit(current);
|
|
547
|
-
if (flipped)
|
|
548
|
-
opts.onHold?.(held);
|
|
682
|
+
reread(delta);
|
|
683
|
+
unwrittenDoc = defaulted ? view.state.doc : undefined;
|
|
549
684
|
},
|
|
550
685
|
setPlaceholder(text) {
|
|
551
686
|
if (text === placeholderText)
|
|
@@ -586,6 +721,31 @@ export function createField(opts) {
|
|
|
586
721
|
return; // absent: nothing to commit
|
|
587
722
|
view.dispatch(view.state.tr.setMeta(anchorKey, { op: 'remove', id }));
|
|
588
723
|
},
|
|
724
|
+
setReview(items, lit) {
|
|
725
|
+
if (!review || (items === reviewItems && lit === reviewLit))
|
|
726
|
+
return;
|
|
727
|
+
reviewItems = items;
|
|
728
|
+
reviewLit = lit;
|
|
729
|
+
for (const markdown of parsed.keys())
|
|
730
|
+
if (!items.some((item) => item.after === markdown))
|
|
731
|
+
parsed.delete(markdown);
|
|
732
|
+
review.refresh(view);
|
|
733
|
+
},
|
|
734
|
+
reviewElements(id) {
|
|
735
|
+
return review?.elements(view, id) ?? [];
|
|
736
|
+
},
|
|
737
|
+
answerReview(id, action) {
|
|
738
|
+
return review?.answer(id, action) ?? false;
|
|
739
|
+
},
|
|
740
|
+
reopenReview(id) {
|
|
741
|
+
review?.reopen(view, id);
|
|
742
|
+
},
|
|
743
|
+
undoReview() {
|
|
744
|
+
return review?.undo(view) ?? false;
|
|
745
|
+
},
|
|
746
|
+
enterReview(id) {
|
|
747
|
+
return review?.enter(view, id) ?? false;
|
|
748
|
+
},
|
|
589
749
|
anchorsInRange(from, to) {
|
|
590
750
|
return heldAnchors()
|
|
591
751
|
.filter((a) => pmToOffset(index, a.end) >= from && pmToOffset(index, a.start) <= to)
|
|
@@ -629,7 +789,8 @@ export function createField(opts) {
|
|
|
629
789
|
* `ProseValue` so the two never fork the plugin ordering. History first with the step-splitting
|
|
630
790
|
* plugin (`undo.ts`), then `afterHistory` plugins (the addressed leaf's anchor plugin), {@link
|
|
631
791
|
* linebreakPlugin}, the markdown-shorthand input rules and their Backspace, the field keymap over
|
|
632
|
-
* the base keymap, the URL paste that links a selection (`link-paste.ts`),
|
|
792
|
+
* the base keymap, the URL paste that links a selection (`link-paste.ts`), the drag that moves
|
|
793
|
+
* between leaves (`drag-move.ts`), and last the block
|
|
633
794
|
* leaf's own shapes: the gap cursor, {@link pastAtomPlugin}, the island paste (`islands.ts`), table
|
|
634
795
|
* paste (`table-paste.ts`), markdown paste (`markdown-paste.ts`) and the task checkbox
|
|
635
796
|
* (`tasks.ts`). A one-line leaf's paste joins its lines (`line-paste.ts`).
|
|
@@ -647,12 +808,15 @@ export function proseLeafPlugins(schema, opts) {
|
|
|
647
808
|
];
|
|
648
809
|
if (opts.slash)
|
|
649
810
|
list.push(slashPlugin(opts.slash, opts.slashHint));
|
|
811
|
+
if (!opts.inline && holdsTab(schema))
|
|
812
|
+
list.push(leavePlugin(opts.leaveStrings ?? (() => DEFAULT_LEAVE_STRINGS)));
|
|
650
813
|
if (!opts.noInputRules)
|
|
651
814
|
list.push(inputRulesPlugin(schema), undoRuleKeymap());
|
|
652
815
|
list.push(keymap(editorKeymap(schema, opts.inline, !!opts.slash)));
|
|
653
816
|
list.push(keymap(baseKeymap));
|
|
654
817
|
if (schema.marks.link)
|
|
655
818
|
list.push(linkPastePlugin(schema.marks.link));
|
|
819
|
+
list.push(dragMovePlugin());
|
|
656
820
|
// Each answers to something only the block schema holds.
|
|
657
821
|
if (isBlockSchema(schema))
|
|
658
822
|
list.push(gapCursor(), pastAtomPlugin(), islandPastePlugin(), tablePastePlugin(), tableCopyPlugin(), markdownPastePlugin(), wordPastePlugin(), listPastePlugin(), taskPlugin(), nestingPlugin());
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { rangeAnchor } from './anchor.js';
|
|
1
|
+
export { markAnchor, rangeAnchor } from './anchor.js';
|
|
2
2
|
export type { RangeAnchor } from './anchor.js';
|
|
3
3
|
export { createField, emptyContent, heldAttributes, isEmptyContent, proseAttributes, proseLeafPlugins } from './field.js';
|
|
4
4
|
export type { CreateFieldOpts, FieldController, LeafViews } from './field.js';
|
|
@@ -9,7 +9,13 @@ export { DEFAULT_TABLE_STRINGS } from './table-view.js';
|
|
|
9
9
|
export type { TableChromeStrings } from './table-view.js';
|
|
10
10
|
export { DEFAULT_SLASH_STRINGS } from './slash.js';
|
|
11
11
|
export type { SlashState, SlashStrings } from './slash.js';
|
|
12
|
-
export {
|
|
12
|
+
export { DEFAULT_LEAVE_STRINGS } from './leave.js';
|
|
13
|
+
export type { LeaveStrings } from './leave.js';
|
|
14
|
+
export { DEFAULT_REVIEW_STRINGS } from './review.js';
|
|
15
|
+
export type { BlockPlace, LeafUndrawn, ReviewAction, ReviewReport, ReviewStrings, ReviewVia, TextReview } from './review.js';
|
|
16
|
+
export { wordDiff } from './review-diff.js';
|
|
17
|
+
export type { DiffHunk } from './review-diff.js';
|
|
18
|
+
export { DEFAULT_SHORTCUT_STRINGS, FIELD_KEYS, REVIEW_KEYS, editorShortcuts } from './shortcuts.js';
|
|
13
19
|
export type { EditorShortcut, ShortcutScope, ShortcutStrings } from './shortcuts.js';
|
|
14
20
|
export { blockSchema, inlineSchema, plaintextSchema, plainSchema, leafSchema, hasMarks } from './schema.js';
|
|
15
21
|
export { rendersHref, storableUrl } from './urls.js';
|
package/dist/core/codec/index.js
CHANGED
|
@@ -11,7 +11,7 @@ import 'prosemirror-gapcursor/style/gapcursor.css';
|
|
|
11
11
|
import './prose.css';
|
|
12
12
|
// What a floating surface anchors to. The visual tier's own surfaces mint one over a
|
|
13
13
|
// selection (`visual/FormatPopover.svelte`), so it is reached off-barrel.
|
|
14
|
-
export { rangeAnchor } from './anchor.js';
|
|
14
|
+
export { markAnchor, rangeAnchor } from './anchor.js';
|
|
15
15
|
// The prose leaf.
|
|
16
16
|
export { createField, emptyContent, heldAttributes, isEmptyContent, proseAttributes, proseLeafPlugins } from './field.js';
|
|
17
17
|
export { capCount } from './cap.js';
|
|
@@ -22,10 +22,17 @@ export { DEFAULT_TABLE_STRINGS } from './table-view.js';
|
|
|
22
22
|
// The slash menu: the codec owns the model and the picks, the chrome the words and
|
|
23
23
|
// the pixels (`visual/SlashMenu.svelte` is the only off-barrel caller).
|
|
24
24
|
export { DEFAULT_SLASH_STRINGS } from './slash.js';
|
|
25
|
+
// The body's way out by the keyboard: the codec owns the keys and the hint's element,
|
|
26
|
+
// the visual tier's `strings` set its wording.
|
|
27
|
+
export { DEFAULT_LEAVE_STRINGS } from './leave.js';
|
|
28
|
+
// The review layer a leaf draws over its blocks: the visual tier's `strings` set extends its
|
|
29
|
+
// wording and its `ReviewItem` narrows to the leaf's own.
|
|
30
|
+
export { DEFAULT_REVIEW_STRINGS } from './review.js';
|
|
31
|
+
export { wordDiff } from './review-diff.js';
|
|
25
32
|
// The rich editor's shortcuts as a host lists them, read off the tables the keymaps bind from;
|
|
26
33
|
// the visual tier's `strings` set extends their wording, and the formatting popover binds its
|
|
27
34
|
// link chord from `FIELD_KEYS`.
|
|
28
|
-
export { DEFAULT_SHORTCUT_STRINGS, FIELD_KEYS, editorShortcuts } from './shortcuts.js';
|
|
35
|
+
export { DEFAULT_SHORTCUT_STRINGS, FIELD_KEYS, REVIEW_KEYS, editorShortcuts } from './shortcuts.js';
|
|
29
36
|
// Schemas (the decode/encode target; the VisualEditor mounts them). `hasMarks` is
|
|
30
37
|
// what a mark surface asks before offering itself over a leaf.
|
|
31
38
|
export { blockSchema, inlineSchema, plaintextSchema, plainSchema, leafSchema, hasMarks } from './schema.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Node as PMNode, type NodeSpec } from 'prosemirror-model';
|
|
1
|
+
import { Fragment, type Node as PMNode, type NodeSpec } from 'prosemirror-model';
|
|
2
2
|
import { Plugin } from 'prosemirror-state';
|
|
3
3
|
import type { Content, ContentIsland, TableProps } from '@quillmark/wasm';
|
|
4
4
|
/** The `U+2028` line separator that is a break inside a block's text. */
|
|
@@ -39,6 +39,9 @@ export declare function islandEntryFromNode(attrs: IslandNodeAttrs): ContentIsla
|
|
|
39
39
|
export declare function isTableProps(props: unknown): props is TableProps;
|
|
40
40
|
/** The next island id for a field: one draw from {@link islandMinter}. */
|
|
41
41
|
export declare function mintIslandId(doc: PMNode): string;
|
|
42
|
+
/** `fragment` as it lands in `doc` from outside it: an island whose id the document holds, or
|
|
43
|
+
* that carries none, takes a fresh one. */
|
|
44
|
+
export declare function arriving(doc: PMNode, fragment: Fragment): Fragment;
|
|
42
45
|
/**
|
|
43
46
|
* The paste's island pass: an id the field already holds is re-minted on the way in, and an island
|
|
44
47
|
* arriving with none (a table read off foreign markup, `table-paste.ts`) takes its first.
|
|
@@ -222,6 +222,12 @@ function remintIslands(fragment, taken, mint) {
|
|
|
222
222
|
});
|
|
223
223
|
return changed ? Fragment.fromArray(out) : null;
|
|
224
224
|
}
|
|
225
|
+
/** `fragment` as it lands in `doc` from outside it: an island whose id the document holds, or
|
|
226
|
+
* that carries none, takes a fresh one. */
|
|
227
|
+
export function arriving(doc, fragment) {
|
|
228
|
+
const { held, mint } = islandState(doc);
|
|
229
|
+
return remintIslands(fragment, held, mint) ?? fragment;
|
|
230
|
+
}
|
|
225
231
|
/**
|
|
226
232
|
* The paste's island pass: an id the field already holds is re-minted on the way in, and an island
|
|
227
233
|
* arriving with none (a table read off foreign markup, `table-paste.ts`) takes its first.
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type { Schema } from 'prosemirror-model';
|
|
2
2
|
import type { Command } from 'prosemirror-state';
|
|
3
|
+
/** Whether a body over `schema` holds Tab: `false` over `plainSchema`, a form field whose
|
|
4
|
+
* Tab is field navigation. */
|
|
5
|
+
export declare function holdsTab(schema: Schema): boolean;
|
|
3
6
|
/** A multi-block leaf's structural keys, each link binding only what its schema
|
|
4
7
|
* declares: over `plainSchema`, which holds neither lists nor code blocks nor islands,
|
|
5
8
|
* the block link and the break link alone. The argument list is the precedence order
|
|
@@ -5,6 +5,7 @@ import { breakKeymap } from './breaks.js';
|
|
|
5
5
|
import { codeKeymap } from './code.js';
|
|
6
6
|
import { listKeymap } from './lists.js';
|
|
7
7
|
import { listMoveKeymap } from './list-move.js';
|
|
8
|
+
import { armLeave, teachLeave } from './leave.js';
|
|
8
9
|
import { slashKeymap } from './slash.js';
|
|
9
10
|
import { BODY_KEYS } from './shortcuts.js';
|
|
10
11
|
/** One chain per key, the maps taken in precedence order: on a key several bind, an
|
|
@@ -19,22 +20,22 @@ function chainKeymaps(...maps) {
|
|
|
19
20
|
}
|
|
20
21
|
return out;
|
|
21
22
|
}
|
|
23
|
+
/** Whether a body over `schema` holds Tab: `false` over `plainSchema`, a form field whose
|
|
24
|
+
* Tab is field navigation. */
|
|
25
|
+
export function holdsTab(schema) {
|
|
26
|
+
return !!schema.nodes.list_item;
|
|
27
|
+
}
|
|
22
28
|
/** The last link of a document body: Tab and Shift-Tab held wherever no surface took
|
|
23
|
-
* them,
|
|
24
|
-
* `{}`
|
|
29
|
+
* them, each naming the way out, and Escape handing the next one to the browser
|
|
30
|
+
* (`leave.ts`). `{}` where the body does not hold Tab. */
|
|
25
31
|
function exitKeymap(schema) {
|
|
26
|
-
if (!schema
|
|
32
|
+
if (!holdsTab(schema))
|
|
27
33
|
return {};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
[BODY_KEYS.leave]: (_state, _dispatch, view) => {
|
|
32
|
-
if (!view)
|
|
33
|
-
return false;
|
|
34
|
-
view.dom.blur();
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
34
|
+
const held = (state, dispatch) => {
|
|
35
|
+
teachLeave(state, dispatch);
|
|
36
|
+
return true;
|
|
37
37
|
};
|
|
38
|
+
return { Tab: held, 'Shift-Tab': held, [BODY_KEYS.leave]: armLeave };
|
|
38
39
|
}
|
|
39
40
|
/** A multi-block leaf's structural keys, each link binding only what its schema
|
|
40
41
|
* declares: over `plainSchema`, which holds neither lists nor code blocks nor islands,
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Plugin, type Command } from 'prosemirror-state';
|
|
2
|
+
/** The hint's wording, in each of its two states. */
|
|
3
|
+
export interface LeaveStrings {
|
|
4
|
+
/** After a Tab the body held to no effect: the way out, in keys. */
|
|
5
|
+
leaveTaught: string;
|
|
6
|
+
/** After Escape, while the next Tab leaves. */
|
|
7
|
+
leaveArmed: string;
|
|
8
|
+
}
|
|
9
|
+
/** The package's English, beside the surface that draws it; the visual `strings` set extends it. */
|
|
10
|
+
export declare const DEFAULT_LEAVE_STRINGS: LeaveStrings;
|
|
11
|
+
type Leave = 'idle' | 'taught' | 'armed';
|
|
12
|
+
/** Hand the next Tab to the browser. Declines in a state without {@link leavePlugin}. */
|
|
13
|
+
export declare const armLeave: Command;
|
|
14
|
+
/** Name the way out, after a Tab the body held. Declines as {@link armLeave}. */
|
|
15
|
+
export declare const teachLeave: Command;
|
|
16
|
+
export declare function leavePlugin(strings: () => LeaveStrings): Plugin<Leave>;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// The body's way out by the keyboard.
|
|
2
|
+
//
|
|
3
|
+
// A body holds Tab (`keymap.ts`), so a keyboard that walked into one cannot walk out by
|
|
4
|
+
// the key that brought it. Escape opens the way: the next Tab or Shift-Tab is the
|
|
5
|
+
// browser's, which moves the focus on from the leaf in either direction, and any other
|
|
6
|
+
// key, a press or an edit hands Tab back to the body. The focus stays in the leaf between
|
|
7
|
+
// the two keys, so the place is drawn and announced throughout, and Shift-Tab leaves
|
|
8
|
+
// backwards as Tab leaves forwards.
|
|
9
|
+
//
|
|
10
|
+
// The leaf says so at the point of need. A Tab the body held and did nothing with names
|
|
11
|
+
// the way out, and Escape names the key it now waits for. The words stand in a status
|
|
12
|
+
// region beside the editable, empty at rest, so a reader hears them as they arrive.
|
|
13
|
+
import { Plugin, PluginKey } from 'prosemirror-state';
|
|
14
|
+
/** The package's English, beside the surface that draws it; the visual `strings` set extends it. */
|
|
15
|
+
export const DEFAULT_LEAVE_STRINGS = {
|
|
16
|
+
leaveTaught: 'Esc, then Tab, to move on',
|
|
17
|
+
leaveArmed: 'Tab to move on'
|
|
18
|
+
};
|
|
19
|
+
const leaveKey = new PluginKey('qm.leave');
|
|
20
|
+
/** Keys that are part of the chord still being pressed, or the key that arms. */
|
|
21
|
+
const KEPT = new Set(['Shift', 'Control', 'Alt', 'Meta', 'Escape']);
|
|
22
|
+
const enter = (to) => (state, dispatch) => {
|
|
23
|
+
if (leaveKey.getState(state) === undefined)
|
|
24
|
+
return false;
|
|
25
|
+
dispatch?.(state.tr.setMeta(leaveKey, to));
|
|
26
|
+
return true;
|
|
27
|
+
};
|
|
28
|
+
/** Hand the next Tab to the browser. Declines in a state without {@link leavePlugin}. */
|
|
29
|
+
export const armLeave = enter('armed');
|
|
30
|
+
/** Name the way out, after a Tab the body held. Declines as {@link armLeave}. */
|
|
31
|
+
export const teachLeave = enter('taught');
|
|
32
|
+
export function leavePlugin(strings) {
|
|
33
|
+
const rest = (view) => {
|
|
34
|
+
if (leaveKey.getState(view.state) !== 'idle')
|
|
35
|
+
view.dispatch(view.state.tr.setMeta(leaveKey, 'idle'));
|
|
36
|
+
return false;
|
|
37
|
+
};
|
|
38
|
+
return new Plugin({
|
|
39
|
+
key: leaveKey,
|
|
40
|
+
state: {
|
|
41
|
+
init: () => 'idle',
|
|
42
|
+
apply: (tr, prev) => tr.getMeta(leaveKey) ??
|
|
43
|
+
(tr.docChanged || tr.selectionSet ? 'idle' : prev)
|
|
44
|
+
},
|
|
45
|
+
props: {
|
|
46
|
+
handleDOMEvents: {
|
|
47
|
+
// Ahead of every keymap, and answering `true` without preventing the default:
|
|
48
|
+
// the view then runs no binding for the key, a list's indent included, and the
|
|
49
|
+
// browser moves the focus.
|
|
50
|
+
keydown: (view, e) => {
|
|
51
|
+
const at = leaveKey.getState(view.state);
|
|
52
|
+
if (at === 'idle' || KEPT.has(e.key))
|
|
53
|
+
return false;
|
|
54
|
+
if (e.key === 'Tab')
|
|
55
|
+
return at === 'armed' && !e.ctrlKey && !e.altKey && !e.metaKey;
|
|
56
|
+
return rest(view);
|
|
57
|
+
},
|
|
58
|
+
blur: rest,
|
|
59
|
+
mousedown: rest
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
view: (view) => {
|
|
63
|
+
const note = document.createElement('span');
|
|
64
|
+
note.className = 'qm-leave-hint';
|
|
65
|
+
note.setAttribute('role', 'status');
|
|
66
|
+
view.dom.after(note);
|
|
67
|
+
const draw = () => {
|
|
68
|
+
const at = leaveKey.getState(view.state);
|
|
69
|
+
const words = strings();
|
|
70
|
+
const text = at === 'armed' ? words.leaveArmed : at === 'taught' ? words.leaveTaught : '';
|
|
71
|
+
if (note.textContent !== text)
|
|
72
|
+
note.textContent = text;
|
|
73
|
+
};
|
|
74
|
+
draw();
|
|
75
|
+
return { update: draw, destroy: () => note.remove() };
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|