@quillmark/svelte 0.37.1 → 0.38.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/dist/core/codec/field.d.ts +3 -3
- package/dist/core/codec/field.js +7 -17
- package/dist/core/codec/review.js +8 -4
- package/dist/core/codec/value-diff.d.ts +4 -3
- package/dist/core/codec/value-diff.js +12 -7
- package/dist/core/codec/value-plan.d.ts +9 -0
- package/dist/core/codec/value-plan.js +110 -0
- package/dist/visual/ArrayField.svelte +73 -21
- package/dist/visual/Card.svelte +4 -3
- package/dist/visual/Card.svelte.d.ts +3 -2
- package/dist/visual/Field.svelte +12 -10
- package/dist/visual/Field.svelte.d.ts +3 -3
- package/dist/visual/ObjectField.svelte +24 -12
- package/dist/visual/ObjectField.svelte.d.ts +5 -0
- package/dist/visual/ProseField.svelte +16 -8
- package/dist/visual/ProseField.svelte.d.ts +3 -2
- package/dist/visual/ProseValue.svelte +22 -22
- package/dist/visual/ProseValue.svelte.d.ts +3 -2
- package/dist/visual/VisualEditorInner.svelte +29 -8
- package/dist/visual/proposals.d.ts +14 -11
- package/dist/visual/proposals.js +44 -28
- package/dist/visual/props.d.ts +6 -4
- package/dist/visual/review-order.d.ts +1 -0
- package/dist/visual/review-order.js +4 -3
- package/dist/visual/review.d.ts +15 -2
- package/dist/visual/review.js +29 -1
- package/dist/visual/review.svelte.d.ts +6 -1
- package/dist/visual/review.svelte.js +37 -10
- package/dist/visual/structure.d.ts +17 -9
- package/dist/visual/structure.js +20 -17
- package/package.json +1 -1
package/dist/visual/review.js
CHANGED
|
@@ -11,6 +11,8 @@ export const NO_PROJECTION = {
|
|
|
11
11
|
toProjection: (at) => at,
|
|
12
12
|
toLive: (at) => at
|
|
13
13
|
};
|
|
14
|
+
/** Whether a field item puts new members into a list in front of one it holds. */
|
|
15
|
+
export const putsIn = (item) => 'ahead' in item;
|
|
14
16
|
/** One rung of a nested item's walk: the items naming this rung's own value, and the rest by
|
|
15
17
|
* the step they take next, that step consumed. */
|
|
16
18
|
export function splitReview(list) {
|
|
@@ -64,11 +66,22 @@ export function valueWith(value, steps, to) {
|
|
|
64
66
|
record[step] = next;
|
|
65
67
|
return record;
|
|
66
68
|
}
|
|
69
|
+
/** `value` with `members` put into the list `steps` reach, in front of the member at its last
|
|
70
|
+
* step, or at its end past the last. */
|
|
71
|
+
export function valueInserting(value, steps, members) {
|
|
72
|
+
const head = steps.slice(0, -1);
|
|
73
|
+
const held = valueIn(value, head);
|
|
74
|
+
const list = Array.isArray(held) ? [...held] : [];
|
|
75
|
+
const at = steps.at(-1);
|
|
76
|
+
list.splice(typeof at === 'number' ? Math.min(at, list.length) : list.length, 0, ...(Array.isArray(members) ? members : [members]));
|
|
77
|
+
return valueWith(value, head, list);
|
|
78
|
+
}
|
|
67
79
|
/**
|
|
68
80
|
* Where a field proposal's steps land in `value` as it stands. A list's member is found by its
|
|
69
81
|
* index where it holds `before`, else as the nearest member holding `before` that `claimed`
|
|
70
82
|
* does not already hold, so one member taken out does not move another's proposal onto the
|
|
71
|
-
* wrong row.
|
|
83
|
+
* wrong row. An insert lands in front of the nearest member holding its `ahead`, and claims
|
|
84
|
+
* none. `found` is false where the proposal has a `before` or an `ahead` nothing holds.
|
|
72
85
|
*/
|
|
73
86
|
export function locate(value, steps, item, claimed) {
|
|
74
87
|
const read = 'before' in item;
|
|
@@ -80,6 +93,15 @@ export function locate(value, steps, item, claimed) {
|
|
|
80
93
|
claimed.add(JSON.stringify(out));
|
|
81
94
|
return out;
|
|
82
95
|
};
|
|
96
|
+
if (putsIn(item)) {
|
|
97
|
+
if (typeof at !== 'number' || !Array.isArray(list))
|
|
98
|
+
return { steps, found: false };
|
|
99
|
+
for (let d = 0; d <= Math.max(at, list.length - 1 - at); d++)
|
|
100
|
+
for (const i of d ? [at - d, at + d] : [at])
|
|
101
|
+
if (i >= 0 && i < list.length && sameValue(list[i], item.ahead))
|
|
102
|
+
return { steps: [...head, i], found: true };
|
|
103
|
+
return { steps, found: false };
|
|
104
|
+
}
|
|
83
105
|
if (!read || before === undefined || typeof at !== 'number' || !Array.isArray(list)) {
|
|
84
106
|
const found = !read || sameValue(valueIn(value, steps), before);
|
|
85
107
|
return { steps: claim(steps), found };
|
|
@@ -244,6 +266,12 @@ export function textProposal(item, cleared) {
|
|
|
244
266
|
return undefined;
|
|
245
267
|
return { id: item.id, after, ...(before && { before }) };
|
|
246
268
|
}
|
|
269
|
+
/** A place's proposals over a leaf of words, each run of one answer, or `undefined` where any
|
|
270
|
+
* of them is not words or there are none. */
|
|
271
|
+
export function textsOf(items, cleared) {
|
|
272
|
+
const list = items.map((item) => textProposal(item, cleared));
|
|
273
|
+
return list.length && list.every((p) => p !== undefined) ? list : undefined;
|
|
274
|
+
}
|
|
247
275
|
/** A number's proposal, drawn over its input as the struck and the proposed figures; `undefined`
|
|
248
276
|
* for one that clears it, which the input shows as what Accept leaves. */
|
|
249
277
|
export function numberProposal(item) {
|
|
@@ -32,7 +32,8 @@ export interface Review {
|
|
|
32
32
|
id: string;
|
|
33
33
|
reason: ReviewUndrawn;
|
|
34
34
|
}[];
|
|
35
|
-
/** The field proposals whose field no longer holds the value their `before` says was read
|
|
35
|
+
/** The field proposals whose field no longer holds the value their `before` says was read,
|
|
36
|
+
* and the removals of a card the reader has written in since they arrived. */
|
|
36
37
|
readonly fieldOutdated: ReadonlySet<string>;
|
|
37
38
|
/** The open items drawn, in the page's order. */
|
|
38
39
|
readonly order: readonly string[];
|
|
@@ -48,6 +49,7 @@ export interface Review {
|
|
|
48
49
|
* each with the steps to the value it names as the field holds it now. */
|
|
49
50
|
at(key: string): {
|
|
50
51
|
proposed?: FieldProposal;
|
|
52
|
+
more?: readonly FieldProposal[];
|
|
51
53
|
nested?: readonly DeepReview[];
|
|
52
54
|
};
|
|
53
55
|
/** Whether anything draws at leaf `key`: a field's own item, or a text item in its leaf. */
|
|
@@ -68,6 +70,9 @@ export interface Review {
|
|
|
68
70
|
answer(ids: readonly string[] | 'all', action: 'accept' | 'dismiss'): string[];
|
|
69
71
|
/** An edit landed that is no answer's: the answers before it can no longer be taken back. */
|
|
70
72
|
settled(): void;
|
|
73
|
+
/** The reader wrote in a field or the body of the card at session key `card`: a removal
|
|
74
|
+
* standing on it is outdated, an answer's own write excepted. */
|
|
75
|
+
edited(card: string): void;
|
|
71
76
|
/** A reader's commit of `value` on a control that shows one value, under the proposal `id`:
|
|
72
77
|
* the proposed value accepts it, any other is written and dismisses it, both one answer.
|
|
73
78
|
* False where it could not be made, and the commit is the caller's. */
|
|
@@ -16,8 +16,16 @@
|
|
|
16
16
|
import { getContext, setContext } from 'svelte';
|
|
17
17
|
import { SvelteMap } from 'svelte/reactivity';
|
|
18
18
|
import { asContent, planValue } from '../core/codec/index.js';
|
|
19
|
-
import { byBlocks, byCard, locate, onField, sameValue, textProposal, valueIn, writesProposed } from './review.js';
|
|
19
|
+
import { byBlocks, byCard, locate, onField, putsIn, sameValue, textProposal, valueIn, writesProposed } from './review.js';
|
|
20
20
|
import { orderOf } from './review-order.js';
|
|
21
|
+
/** Whether two proposals on one place are runs of one answer over its words: each reads the
|
|
22
|
+
* value its writer read alike, and writes words. A place takes every such run. */
|
|
23
|
+
const runsOfOne = (a, b) => 'before' in a &&
|
|
24
|
+
'before' in b &&
|
|
25
|
+
sameValue(a.before, b.before) &&
|
|
26
|
+
asContent(a.after) !== undefined &&
|
|
27
|
+
asContent(b.after) !== undefined &&
|
|
28
|
+
asContent(a.before) !== undefined;
|
|
21
29
|
export function createReview(source) {
|
|
22
30
|
/** The ids answered, each until a list arrives without it. */
|
|
23
31
|
const answered = new Set();
|
|
@@ -126,7 +134,9 @@ export function createReview(source) {
|
|
|
126
134
|
claims.set(deep.key, claimed);
|
|
127
135
|
const held = out.get(deep.key) ?? {};
|
|
128
136
|
const { steps, found } = locate(deep.value, deep.steps, item, claimed);
|
|
129
|
-
if ((held.nested ?? []).some((e) => sameValue(e.steps, steps)
|
|
137
|
+
if ((held.nested ?? []).some((e) => sameValue(e.steps, steps) &&
|
|
138
|
+
putsIn(e.item) === putsIn(item) &&
|
|
139
|
+
!runsOfOne(e.item, item))) {
|
|
130
140
|
undrawn.push({ id: item.id, reason: 'taken' });
|
|
131
141
|
continue;
|
|
132
142
|
}
|
|
@@ -143,7 +153,10 @@ export function createReview(source) {
|
|
|
143
153
|
}
|
|
144
154
|
const held = out.get(key) ?? {};
|
|
145
155
|
if (held.proposed !== undefined) {
|
|
146
|
-
|
|
156
|
+
if (runsOfOne(held.proposed, item))
|
|
157
|
+
held.more = [...(held.more ?? []), item];
|
|
158
|
+
else
|
|
159
|
+
undrawn.push({ id: item.id, reason: 'taken' });
|
|
147
160
|
continue;
|
|
148
161
|
}
|
|
149
162
|
held.proposed = item;
|
|
@@ -152,17 +165,23 @@ export function createReview(source) {
|
|
|
152
165
|
return { fields: out, undrawn, moved };
|
|
153
166
|
});
|
|
154
167
|
const fields = $derived(placed.fields);
|
|
168
|
+
/** The removals the reader has written in the card of since they arrived, each by the item
|
|
169
|
+
* it was recorded against, so a list set anew reads its removals afresh. */
|
|
170
|
+
const touched = new SvelteMap();
|
|
155
171
|
/** Each proposal of words a leaf draws, by id: how it stands against what the leaf holds. */
|
|
156
172
|
const carried = new SvelteMap();
|
|
157
|
-
// A proposal made from a value the field no longer holds would write over the reader's
|
|
158
|
-
//
|
|
173
|
+
// A proposal made from a value the field no longer holds would write over the reader's, as a
|
|
174
|
+
// removal would take what the reader wrote in its card. One a leaf of words carries is
|
|
175
|
+
// outdated only where the reader's writing meets it.
|
|
159
176
|
const outdated = $derived.by(() => {
|
|
160
177
|
const out = new Set(placed.moved);
|
|
161
|
-
for (const
|
|
162
|
-
if (
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
178
|
+
for (const item of cards.removes.values())
|
|
179
|
+
if (touched.get(item.id) === item)
|
|
180
|
+
out.add(item.id);
|
|
181
|
+
for (const { proposed, more } of fields.values())
|
|
182
|
+
for (const p of proposed ? [proposed, ...(more ?? [])] : [])
|
|
183
|
+
if ('before' in p && !sameValue(source.valueAt(p.field), p.before))
|
|
184
|
+
out.add(p.id);
|
|
166
185
|
for (const [id, state] of carried)
|
|
167
186
|
if (state === 'outdated')
|
|
168
187
|
out.add(id);
|
|
@@ -404,6 +423,13 @@ export function createReview(source) {
|
|
|
404
423
|
offer = undefined;
|
|
405
424
|
source.undo.settle();
|
|
406
425
|
},
|
|
426
|
+
edited(card) {
|
|
427
|
+
if (writing)
|
|
428
|
+
return;
|
|
429
|
+
const item = cards.removes.get(card);
|
|
430
|
+
if (item && touched.get(item.id) !== item)
|
|
431
|
+
touched.set(item.id, item);
|
|
432
|
+
},
|
|
407
433
|
answerWith(id, value) {
|
|
408
434
|
const item = byId.get(id);
|
|
409
435
|
if (!item || !onField(item))
|
|
@@ -469,6 +495,7 @@ const NO_REVIEW = {
|
|
|
469
495
|
act: () => false,
|
|
470
496
|
answer: () => [],
|
|
471
497
|
settled() { },
|
|
498
|
+
edited() { },
|
|
472
499
|
answerWith: () => false,
|
|
473
500
|
planned() { },
|
|
474
501
|
current: () => undefined,
|
|
@@ -18,7 +18,7 @@ export interface FieldModel {
|
|
|
18
18
|
label: string;
|
|
19
19
|
/** Chrome-only; never gates. */
|
|
20
20
|
description: string | undefined;
|
|
21
|
-
/** Prose-leaf flags
|
|
21
|
+
/** Prose-leaf flags, from {@link leafFlags}. */
|
|
22
22
|
inline: boolean;
|
|
23
23
|
plaintext: boolean;
|
|
24
24
|
paragraphs: boolean;
|
|
@@ -141,13 +141,21 @@ export declare function optionalCell(f: QuillFieldSchema): boolean;
|
|
|
141
141
|
* nothing else.
|
|
142
142
|
*/
|
|
143
143
|
export declare function baseType(f: QuillFieldSchema): QuillFieldType;
|
|
144
|
-
/**
|
|
145
|
-
*
|
|
146
|
-
export
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
144
|
+
/** A text field's kind: how its characters read, literally (`text`) or as marks (`richtext`), and
|
|
145
|
+
* how much it holds, each shape holding all the one before it does. */
|
|
146
|
+
export interface TextKind {
|
|
147
|
+
type: 'text' | 'richtext';
|
|
148
|
+
shape: 'line' | 'lines' | 'blocks';
|
|
149
|
+
}
|
|
150
|
+
/** A field's text kind, read once from its schema; `undefined` for a field that is not text. A
|
|
151
|
+
* field that declares no `shape` is one line. */
|
|
152
|
+
export declare function textKind(f: QuillFieldSchema): TextKind | undefined;
|
|
153
|
+
/** What a prose leaf is built from: the kind, spelled as the leaf schema reads it. */
|
|
154
|
+
export declare function leafFlags(f: QuillFieldSchema | undefined): {
|
|
155
|
+
inline: boolean;
|
|
156
|
+
plaintext: boolean;
|
|
157
|
+
paragraphs: boolean;
|
|
158
|
+
};
|
|
151
159
|
/** The character cap a content field's `max:` declares, `undefined` on any other. */
|
|
152
160
|
export declare function textCap(f: QuillFieldSchema | undefined): TextCap | undefined;
|
|
153
161
|
/**
|
|
@@ -165,7 +173,7 @@ export declare function printedText(v: unknown): string | undefined;
|
|
|
165
173
|
*/
|
|
166
174
|
export declare function declaredContent(v: unknown, markdown: boolean): Content | undefined;
|
|
167
175
|
/** A field's `{#each}` key: its name and what a mounted leaf reads once, its type,
|
|
168
|
-
*
|
|
176
|
+
* `shape` and `max:`, and its elements'. A retype or a quill swap that changes
|
|
169
177
|
* any of them under a name remounts the field, where a kept leaf would commit on the old
|
|
170
178
|
* schema. */
|
|
171
179
|
export declare function mountKey(name: string, f: QuillFieldSchema): string;
|
package/dist/visual/structure.js
CHANGED
|
@@ -69,24 +69,29 @@ export function optionalCell(f) {
|
|
|
69
69
|
export function baseType(f) {
|
|
70
70
|
return (optionalCell(f) ? f.type.slice(0, -1) : f.type);
|
|
71
71
|
}
|
|
72
|
-
/**
|
|
73
|
-
*
|
|
74
|
-
export function
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return baseType(f) === 'richtext' && f.shape === 'lines';
|
|
72
|
+
/** A field's text kind, read once from its schema; `undefined` for a field that is not text. A
|
|
73
|
+
* field that declares no `shape` is one line. */
|
|
74
|
+
export function textKind(f) {
|
|
75
|
+
const type = baseType(f);
|
|
76
|
+
if (type !== 'text' && type !== 'richtext')
|
|
77
|
+
return undefined;
|
|
78
|
+
return { type, shape: f.shape ?? 'line' };
|
|
80
79
|
}
|
|
81
|
-
/**
|
|
82
|
-
export function
|
|
83
|
-
|
|
80
|
+
/** What a prose leaf is built from: the kind, spelled as the leaf schema reads it. */
|
|
81
|
+
export function leafFlags(f) {
|
|
82
|
+
const kind = f && textKind(f);
|
|
83
|
+
return {
|
|
84
|
+
inline: kind?.shape === 'line',
|
|
85
|
+
plaintext: kind?.type === 'text',
|
|
86
|
+
paragraphs: kind?.type === 'richtext' && kind.shape === 'lines'
|
|
87
|
+
};
|
|
84
88
|
}
|
|
85
89
|
/** The character cap a content field's `max:` declares, `undefined` on any other. */
|
|
86
90
|
export function textCap(f) {
|
|
87
91
|
if (f?.max == null || controlKind(f) !== 'prose')
|
|
88
92
|
return undefined;
|
|
89
|
-
|
|
93
|
+
const kind = textKind(f);
|
|
94
|
+
return { max: f.max, trimEnd: kind?.type === 'text' && kind.shape === 'line' };
|
|
90
95
|
}
|
|
91
96
|
/**
|
|
92
97
|
* A scalar `default:` as the text an unset control holds, where it prints: as
|
|
@@ -113,7 +118,7 @@ export function declaredContent(v, markdown) {
|
|
|
113
118
|
return { text: text.replaceAll('\n', '\u2028'), blocks: [{ id: 'b0', kind: 'para' }] };
|
|
114
119
|
}
|
|
115
120
|
/** A field's `{#each}` key: its name and what a mounted leaf reads once, its type,
|
|
116
|
-
*
|
|
121
|
+
* `shape` and `max:`, and its elements'. A retype or a quill swap that changes
|
|
117
122
|
* any of them under a name remounts the field, where a kept leaf would commit on the old
|
|
118
123
|
* schema. */
|
|
119
124
|
export function mountKey(name, f) {
|
|
@@ -417,7 +422,7 @@ export function rankAt(field, steps, value) {
|
|
|
417
422
|
export function shortCell(sub) {
|
|
418
423
|
const kind = controlKind(sub);
|
|
419
424
|
if (kind === 'prose')
|
|
420
|
-
return
|
|
425
|
+
return textKind(sub)?.shape === 'line';
|
|
421
426
|
return (kind === 'text' || kind === 'enum' || kind === 'number' || kind === 'boolean' || kind === 'date');
|
|
422
427
|
}
|
|
423
428
|
/**
|
|
@@ -508,9 +513,7 @@ export function fieldModels(cardSchema) {
|
|
|
508
513
|
compact: schema.ui?.compact ?? packsByDefault(control),
|
|
509
514
|
label: fieldTitle(name, schema),
|
|
510
515
|
description: schema.description,
|
|
511
|
-
|
|
512
|
-
plaintext: literalText(schema),
|
|
513
|
-
paragraphs: linesOnly(schema)
|
|
516
|
+
...leafFlags(schema)
|
|
514
517
|
};
|
|
515
518
|
});
|
|
516
519
|
}
|