@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
|
@@ -172,9 +172,9 @@ export interface FieldController {
|
|
|
172
172
|
* `text` leaf holds no anchors and draws none.
|
|
173
173
|
*/
|
|
174
174
|
setReview(items: readonly TextReview[], lit?: string): void;
|
|
175
|
-
/** Draw
|
|
176
|
-
* (`value-diff.ts`).
|
|
177
|
-
|
|
175
|
+
/** Draw proposed values over the leaf as a word diff, a whole value or each run of one
|
|
176
|
+
* answer, or none (`value-diff.ts`). */
|
|
177
|
+
setValueProposals(proposals: readonly ValueProposal[]): void;
|
|
178
178
|
/** The elements the review item `id` draws, in document order; `[]` for one not drawn. */
|
|
179
179
|
reviewElements(id: string): HTMLElement[];
|
|
180
180
|
/** Put the caret in the review item `id` and focus the leaf; false for one not drawn. */
|
package/dist/core/codec/field.js
CHANGED
|
@@ -287,10 +287,8 @@ export function createField(opts) {
|
|
|
287
287
|
point: (id) => opts.onReviewPoint?.(id),
|
|
288
288
|
drew: (report) => opts.onReviewDrawn?.(report)
|
|
289
289
|
});
|
|
290
|
-
let
|
|
291
|
-
const valueDiff =
|
|
292
|
-
? valueDiffPlugin(() => valueProposal, (id, state) => opts.onValuePlanned?.(id, state))
|
|
293
|
-
: undefined;
|
|
290
|
+
let valueProposals = [];
|
|
291
|
+
const valueDiff = valueDiffPlugin(() => valueProposals, (id, state) => opts.onValuePlanned?.(id, state));
|
|
294
292
|
// The menu's report channel; the vocabulary is the codec's own constant (`slash.ts`).
|
|
295
293
|
const slash = block ? opts.onSlash : undefined;
|
|
296
294
|
// Judged of the value being mounted rather than read off a diagnostic: a routed set
|
|
@@ -416,11 +414,7 @@ export function createField(opts) {
|
|
|
416
414
|
placeholder: () => placeholderText,
|
|
417
415
|
placeholderUntilEdit: opts.placeholderUntilEdit,
|
|
418
416
|
cap: opts.cap,
|
|
419
|
-
afterHistory: [
|
|
420
|
-
anchorPlugin(seededAnchors),
|
|
421
|
-
...(review ? [review.plugin] : []),
|
|
422
|
-
...(valueDiff ? [valueDiff] : [])
|
|
423
|
-
]
|
|
417
|
+
afterHistory: [anchorPlugin(seededAnchors), ...(review ? [review.plugin] : []), valueDiff]
|
|
424
418
|
})
|
|
425
419
|
});
|
|
426
420
|
return { state: built, index: seedIndex };
|
|
@@ -738,15 +732,11 @@ export function createField(opts) {
|
|
|
738
732
|
parsed.delete(markdown);
|
|
739
733
|
review.refresh(view);
|
|
740
734
|
},
|
|
741
|
-
|
|
742
|
-
|
|
735
|
+
setValueProposals(proposals) {
|
|
736
|
+
const key = (list) => JSON.stringify(list.map((p) => [p.id, p.lit, p.after, p.before]));
|
|
737
|
+
if (key(proposals) === key(valueProposals))
|
|
743
738
|
return;
|
|
744
|
-
|
|
745
|
-
p?.lit === valueProposal?.lit &&
|
|
746
|
-
JSON.stringify([p?.after, p?.before]) ===
|
|
747
|
-
JSON.stringify([valueProposal?.after, valueProposal?.before]))
|
|
748
|
-
return;
|
|
749
|
-
valueProposal = p;
|
|
739
|
+
valueProposals = proposals;
|
|
750
740
|
view.setProps({});
|
|
751
741
|
},
|
|
752
742
|
reviewElements(id) {
|
|
@@ -136,13 +136,17 @@ function reach(leaf) {
|
|
|
136
136
|
? [leaf.pos + 1, leaf.pos + leaf.node.nodeSize - 1]
|
|
137
137
|
: [leaf.pos, leaf.pos + leaf.node.nodeSize];
|
|
138
138
|
}
|
|
139
|
+
/** `node`'s attributes without the id of the stored part it decodes from. */
|
|
140
|
+
const unnamed = (node) => 'id' in node.attrs ? { ...node.attrs, id: null } : node.attrs;
|
|
139
141
|
/** `doc`'s blocks from its `from`th leaf on, in the containers they sat in. A numbered list
|
|
140
|
-
* that lost its head keeps counting from where the kept items stood.
|
|
142
|
+
* that lost its head keeps counting from where the kept items stood. They carry no ids: the
|
|
143
|
+
* ones `doc` was read under are its own, and a leaf's block wearing one would lose it to an
|
|
144
|
+
* added block that stands ahead of it. */
|
|
141
145
|
function tail(doc, from) {
|
|
142
146
|
let seen = 0;
|
|
143
147
|
const keep = (node) => {
|
|
144
148
|
if (node.isTextblock || node.isAtom)
|
|
145
|
-
return seen++ >= from ? node : undefined;
|
|
149
|
+
return seen++ >= from ? node.type.create(unnamed(node), node.content, node.marks) : undefined;
|
|
146
150
|
const kids = [];
|
|
147
151
|
let dropped = 0;
|
|
148
152
|
node.forEach((child) => {
|
|
@@ -155,8 +159,8 @@ function tail(doc, from) {
|
|
|
155
159
|
if (!kids.length)
|
|
156
160
|
return undefined;
|
|
157
161
|
const attrs = node.type.name === 'ordered_list'
|
|
158
|
-
? { ...node
|
|
159
|
-
: node
|
|
162
|
+
? { ...unnamed(node), start: node.attrs.start + dropped }
|
|
163
|
+
: unnamed(node);
|
|
160
164
|
return node.type.create(attrs, kids);
|
|
161
165
|
};
|
|
162
166
|
const out = [];
|
|
@@ -15,7 +15,8 @@ export interface ValueProposal {
|
|
|
15
15
|
export type ValueState = 'open' | 'outdated' | 'applied';
|
|
16
16
|
export declare const valueDiffKey: PluginKey<void>;
|
|
17
17
|
/**
|
|
18
|
-
* The plugin, reading the
|
|
19
|
-
* `planned` hears, on each draw, how
|
|
18
|
+
* The plugin, reading the proposals live: a caller that moves them redraws with `setProps`.
|
|
19
|
+
* Each is a run of one answer or a whole value, drawn apart. `planned` hears, on each draw, how
|
|
20
|
+
* each stands against what the leaf holds.
|
|
20
21
|
*/
|
|
21
|
-
export declare function valueDiffPlugin(read: () => ValueProposal
|
|
22
|
+
export declare function valueDiffPlugin(read: () => readonly ValueProposal[], planned?: (id: string, state: ValueState) => void): Plugin;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// A field's whole
|
|
1
|
+
// A field's proposed values, a whole one or each run of one answer, drawn as a word diff over a leaf of lines: the words Accept would
|
|
2
2
|
// strike struck where they stand, the words it would write tinted beside them in their own
|
|
3
3
|
// formatting, nothing written. What is drawn is the difference between the leaf as it reads and
|
|
4
4
|
// what Accept would write (`planValue`), so the reader's words beside a proposal stay unstruck.
|
|
@@ -31,11 +31,15 @@ function inserted(schema, c, from, to) {
|
|
|
31
31
|
const inline = doc.firstChild?.isTextblock ? doc.firstChild.content : doc.content;
|
|
32
32
|
return DOMSerializer.fromSchema(schema).serializeFragment(inline);
|
|
33
33
|
}
|
|
34
|
-
function draw(state,
|
|
34
|
+
function draw(state, proposals, planned) {
|
|
35
35
|
const scan = scanDoc(state.doc);
|
|
36
36
|
const live = scanContent(scan);
|
|
37
37
|
const index = lineIndexOf(scan);
|
|
38
38
|
const at = (offset) => offsetToPM(index, offset);
|
|
39
|
+
return DecorationSet.create(state.doc, proposals.flatMap((p) => decorations(state, live, at, p, planned)));
|
|
40
|
+
}
|
|
41
|
+
/** One proposal's marks over the leaf as it reads, `live`. */
|
|
42
|
+
function decorations(state, live, at, p, planned) {
|
|
39
43
|
const { merged, outdated } = planValue(p.before, live, p.after);
|
|
40
44
|
const changes = valueChanges(live, merged);
|
|
41
45
|
planned?.(p.id, !changes.length ? 'applied' : outdated ? 'outdated' : 'open');
|
|
@@ -64,19 +68,20 @@ function draw(state, p, planned) {
|
|
|
64
68
|
key: `value:${p.id}:${n}:${start}:${JSON.stringify(slice(merged, start, to).marks)}:${text}:${p.lit}`
|
|
65
69
|
}));
|
|
66
70
|
});
|
|
67
|
-
return
|
|
71
|
+
return decos;
|
|
68
72
|
}
|
|
69
73
|
/**
|
|
70
|
-
* The plugin, reading the
|
|
71
|
-
* `planned` hears, on each draw, how
|
|
74
|
+
* The plugin, reading the proposals live: a caller that moves them redraws with `setProps`.
|
|
75
|
+
* Each is a run of one answer or a whole value, drawn apart. `planned` hears, on each draw, how
|
|
76
|
+
* each stands against what the leaf holds.
|
|
72
77
|
*/
|
|
73
78
|
export function valueDiffPlugin(read, planned) {
|
|
74
79
|
return new Plugin({
|
|
75
80
|
key: valueDiffKey,
|
|
76
81
|
props: {
|
|
77
82
|
decorations(state) {
|
|
78
|
-
const
|
|
79
|
-
return
|
|
83
|
+
const proposals = read();
|
|
84
|
+
return proposals.length ? draw(state, proposals, planned) : null;
|
|
80
85
|
}
|
|
81
86
|
}
|
|
82
87
|
});
|
|
@@ -27,3 +27,12 @@ export declare function valueChanges(a: Content, b: Content): ValueChange[];
|
|
|
27
27
|
* the value already reads as `after`.
|
|
28
28
|
*/
|
|
29
29
|
export declare function planValue(before: Content | undefined, live: Content, after: Content): ValuePlan;
|
|
30
|
+
/**
|
|
31
|
+
* `after` as one proposal per run of lines it changes in `before`: each `before` with that run
|
|
32
|
+
* alone written as `after` has it, in reading order. Lines pair by their words and formatting
|
|
33
|
+
* along their longest common run, so a line added or taken out is one run, never every line below
|
|
34
|
+
* it. By `'run'`, runs at most two unchanged lines apart are one; by `'paragraph'`, a run that
|
|
35
|
+
* rewrites as many lines as it reads is one proposal per line, as the body proposes paragraphs. A
|
|
36
|
+
* value that holds more than lines of words, or one that changes a single line or run, is `[after]`.
|
|
37
|
+
*/
|
|
38
|
+
export declare function lineRuns(before: Content, after: Content, unit?: 'run' | 'paragraph'): Content[];
|
|
@@ -155,3 +155,113 @@ export function planValue(before, live, after) {
|
|
|
155
155
|
}
|
|
156
156
|
return { merged, outdated: false };
|
|
157
157
|
}
|
|
158
|
+
/** Unchanged lines that may stand between two runs of changed lines on one proposal. */
|
|
159
|
+
const RUN_GAP = 2;
|
|
160
|
+
/** Line `k` of `c`, as a value of its own. */
|
|
161
|
+
function lineOf(c, starts, k) {
|
|
162
|
+
const from = starts[k];
|
|
163
|
+
const to = k + 1 < starts.length ? starts[k + 1] - 1 : c.text.length;
|
|
164
|
+
return { text: c.text.slice(from, to), marks: marksIn(c, from, to, 0) };
|
|
165
|
+
}
|
|
166
|
+
/** Where each line of `c` starts. */
|
|
167
|
+
function lineStarts(c) {
|
|
168
|
+
const out = [0];
|
|
169
|
+
for (let i = 0; i < c.text.length; i++)
|
|
170
|
+
if (c.text[i] === '\n')
|
|
171
|
+
out.push(i + 1);
|
|
172
|
+
return out;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* `after` as one proposal per run of lines it changes in `before`: each `before` with that run
|
|
176
|
+
* alone written as `after` has it, in reading order. Lines pair by their words and formatting
|
|
177
|
+
* along their longest common run, so a line added or taken out is one run, never every line below
|
|
178
|
+
* it. By `'run'`, runs at most two unchanged lines apart are one; by `'paragraph'`, a run that
|
|
179
|
+
* rewrites as many lines as it reads is one proposal per line, as the body proposes paragraphs. A
|
|
180
|
+
* value that holds more than lines of words, or one that changes a single line or run, is `[after]`.
|
|
181
|
+
*/
|
|
182
|
+
export function lineRuns(before, after, unit = 'run') {
|
|
183
|
+
if ([before, after].some(structured))
|
|
184
|
+
return [after];
|
|
185
|
+
const bs = lineStarts(before);
|
|
186
|
+
const as = lineStarts(after);
|
|
187
|
+
if (bs.length !== before.blocks.length || as.length !== after.blocks.length)
|
|
188
|
+
return [after];
|
|
189
|
+
const key = (c, starts, k) => JSON.stringify(lineOf(c, starts, k));
|
|
190
|
+
const bk = bs.map((_, k) => key(before, bs, k));
|
|
191
|
+
const ak = as.map((_, k) => key(after, as, k));
|
|
192
|
+
const m = bk.length;
|
|
193
|
+
const n = ak.length;
|
|
194
|
+
const lcs = Array.from({ length: m + 1 }, () => new Array(n + 1).fill(0));
|
|
195
|
+
for (let i = m - 1; i >= 0; i--)
|
|
196
|
+
for (let j = n - 1; j >= 0; j--)
|
|
197
|
+
lcs[i][j] = bk[i] === ak[j] ? lcs[i + 1][j + 1] + 1 : Math.max(lcs[i + 1][j], lcs[i][j + 1]);
|
|
198
|
+
const runs = [];
|
|
199
|
+
let i = 0;
|
|
200
|
+
let j = 0;
|
|
201
|
+
let open;
|
|
202
|
+
const close = () => {
|
|
203
|
+
if (!open)
|
|
204
|
+
return;
|
|
205
|
+
const last = runs.at(-1);
|
|
206
|
+
if (unit === 'run' && last && open.b - last.be <= RUN_GAP) {
|
|
207
|
+
last.be = i;
|
|
208
|
+
last.ae = j;
|
|
209
|
+
}
|
|
210
|
+
else
|
|
211
|
+
runs.push({ b: open.b, be: i, a: open.a, ae: j });
|
|
212
|
+
open = undefined;
|
|
213
|
+
};
|
|
214
|
+
while (i < m || j < n) {
|
|
215
|
+
if (i < m && j < n && bk[i] === ak[j]) {
|
|
216
|
+
close();
|
|
217
|
+
i++;
|
|
218
|
+
j++;
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
open ??= { b: i, a: j };
|
|
222
|
+
if (j >= n || (i < m && lcs[i + 1][j] >= lcs[i][j + 1]))
|
|
223
|
+
i++;
|
|
224
|
+
else
|
|
225
|
+
j++;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
close();
|
|
229
|
+
const apart = unit === 'paragraph'
|
|
230
|
+
? runs.flatMap((r) => r.be - r.b === r.ae - r.a && r.be - r.b > 1
|
|
231
|
+
? Array.from({ length: r.be - r.b }, (_, k) => ({
|
|
232
|
+
b: r.b + k,
|
|
233
|
+
be: r.b + k + 1,
|
|
234
|
+
a: r.a + k,
|
|
235
|
+
ae: r.a + k + 1
|
|
236
|
+
}))
|
|
237
|
+
: [r])
|
|
238
|
+
: runs;
|
|
239
|
+
if (apart.length < 2)
|
|
240
|
+
return [after];
|
|
241
|
+
return apart.map((run) => {
|
|
242
|
+
const lines = [
|
|
243
|
+
...bs.slice(0, run.b).map((_, k) => lineOf(before, bs, k)),
|
|
244
|
+
...as.slice(run.a, run.ae).map((_, k) => lineOf(after, as, run.a + k)),
|
|
245
|
+
...bs.slice(run.be).map((_, k) => lineOf(before, bs, run.be + k))
|
|
246
|
+
];
|
|
247
|
+
const blocks = [
|
|
248
|
+
...before.blocks.slice(0, run.b),
|
|
249
|
+
...after.blocks.slice(run.a, run.ae),
|
|
250
|
+
...before.blocks.slice(run.be)
|
|
251
|
+
].map((b, k) => ({ ...b, id: `b${k}` }));
|
|
252
|
+
let at = 0;
|
|
253
|
+
const marks = [];
|
|
254
|
+
for (const line of lines) {
|
|
255
|
+
for (const mark of line.marks)
|
|
256
|
+
marks.push({ ...mark, start: mark.start + at, end: mark.end + at });
|
|
257
|
+
at += line.text.length + 1;
|
|
258
|
+
}
|
|
259
|
+
const out = { ...before, text: lines.map((l) => l.text).join('\n'), blocks };
|
|
260
|
+
if (marks.length)
|
|
261
|
+
out.marks = marks;
|
|
262
|
+
else
|
|
263
|
+
delete out.marks;
|
|
264
|
+
delete out.anchors;
|
|
265
|
+
return out;
|
|
266
|
+
});
|
|
267
|
+
}
|
|
@@ -108,9 +108,7 @@
|
|
|
108
108
|
firstShortText,
|
|
109
109
|
declaredContent,
|
|
110
110
|
fieldTitle,
|
|
111
|
-
|
|
112
|
-
literalText,
|
|
113
|
-
oneLine,
|
|
111
|
+
leafFlags,
|
|
114
112
|
renderedBoolean,
|
|
115
113
|
schemaAt,
|
|
116
114
|
textCap,
|
|
@@ -118,7 +116,8 @@
|
|
|
118
116
|
} from './structure.js';
|
|
119
117
|
import {
|
|
120
118
|
numberProposal,
|
|
121
|
-
|
|
119
|
+
putsIn,
|
|
120
|
+
textsOf,
|
|
122
121
|
type TextProposal,
|
|
123
122
|
splitReview,
|
|
124
123
|
valueIn,
|
|
@@ -224,7 +223,7 @@
|
|
|
224
223
|
const control = $derived(items ? controlKind(items) : 'text');
|
|
225
224
|
/** A prose element whose `items` declares a `shape`: its own lines, which Enter breaks and
|
|
226
225
|
* ⌘/Ctrl+Enter leaves for a sibling. */
|
|
227
|
-
const multiline = $derived(control === 'prose' &&
|
|
226
|
+
const multiline = $derived(control === 'prose' && !leafFlags(items).inline);
|
|
228
227
|
const table = $derived(layout === 'table' && control === 'object');
|
|
229
228
|
const columns = $derived(Object.entries(items?.properties ?? {}));
|
|
230
229
|
/** A column's track. A cell that fills its width takes a share of what the field has
|
|
@@ -265,9 +264,21 @@
|
|
|
265
264
|
unrouted(routed, (step) => typeof step === 'number' && step >= 0 && step < arr.length)
|
|
266
265
|
);
|
|
267
266
|
const reviewed = $derived(splitReview(review));
|
|
267
|
+
/** An item on a row that adds members in front of it, which the row does not draw. */
|
|
268
|
+
const inserting = (e: DeepReview): boolean => !e.steps.length && putsIn(e.item);
|
|
268
269
|
/** A row's review items: the member's own, and those inside it. */
|
|
269
270
|
const rowReview = (k: number): DeepReview[] =>
|
|
270
|
-
k < arr.length ? (reviewed.below.get(k) ?? []) : [];
|
|
271
|
+
k < arr.length ? (reviewed.below.get(k) ?? []).filter((e) => !inserting(e)) : [];
|
|
272
|
+
/** The members a review would put in front of row `k`, each with the item that adds it. */
|
|
273
|
+
const insertedAt = (k: number): { item: FieldProposal; after: unknown }[] =>
|
|
274
|
+
k < arr.length
|
|
275
|
+
? (reviewed.below.get(k) ?? []).filter(inserting).flatMap(({ item }) =>
|
|
276
|
+
(Array.isArray(item.after) ? item.after : [item.after]).map((after) => ({
|
|
277
|
+
item,
|
|
278
|
+
after
|
|
279
|
+
}))
|
|
280
|
+
)
|
|
281
|
+
: [];
|
|
271
282
|
const ownReview = (k: number): DeepReview[] => rowReview(k).filter((e) => !e.steps.length);
|
|
272
283
|
/** A row's own removal: the proposal that takes the member out, drawn on the whole row. */
|
|
273
284
|
const removal = (k: number): FieldProposal | undefined =>
|
|
@@ -284,11 +295,17 @@
|
|
|
284
295
|
scalar || control === 'prose'
|
|
285
296
|
? ownReview(k).find((e) => e.item.after !== undefined)?.item
|
|
286
297
|
: undefined;
|
|
287
|
-
const rowText = (k: number): TextProposal | undefined =>
|
|
288
|
-
control === 'prose'
|
|
298
|
+
const rowText = (k: number): TextProposal[] | undefined =>
|
|
299
|
+
control === 'prose'
|
|
300
|
+
? textsOf(
|
|
301
|
+
ownReview(k)
|
|
302
|
+
.filter((e) => e.item.after !== undefined)
|
|
303
|
+
.map((e) => e.item)
|
|
304
|
+
)
|
|
305
|
+
: undefined;
|
|
289
306
|
const rowNumber = (k: number): { id: string; after: string } | undefined =>
|
|
290
307
|
control === 'number' ? numberProposal(rowOwn(k)) : undefined;
|
|
291
|
-
const rowWorded = (k: number): { id: string } | undefined => rowText(k) ?? rowNumber(k);
|
|
308
|
+
const rowWorded = (k: number): { id: string } | undefined => rowText(k)?.[0] ?? rowNumber(k);
|
|
292
309
|
const rowShown = (k: number): unknown => {
|
|
293
310
|
const own = rowWorded(k) ? undefined : rowOwn(k);
|
|
294
311
|
return own ? own.after : arr[k];
|
|
@@ -302,8 +319,8 @@
|
|
|
302
319
|
};
|
|
303
320
|
/** A row's marks: its proposals less the one its control draws as words. */
|
|
304
321
|
const rowMarks = (k: number): DeepReview[] => {
|
|
305
|
-
const
|
|
306
|
-
return
|
|
322
|
+
const drawn = new Set([...(rowText(k) ?? []), rowNumber(k)].map((p) => p?.id));
|
|
323
|
+
return rowKept(k).filter((e) => !drawn.has(e.item.id));
|
|
307
324
|
};
|
|
308
325
|
/** What a row taken out carries: its item's id and the current one lit, so the row is where
|
|
309
326
|
* the answer card stands. */
|
|
@@ -324,7 +341,9 @@
|
|
|
324
341
|
...[...reviewed.below].flatMap(([step, list]) => {
|
|
325
342
|
const held = typeof step === 'number' && step >= 0 && step < arr.length;
|
|
326
343
|
return list
|
|
327
|
-
.filter(
|
|
344
|
+
.filter(
|
|
345
|
+
(e) => !held || (table && !inserting(e) && !e.steps.length && e.item.after !== undefined)
|
|
346
|
+
)
|
|
328
347
|
.map((e) => ({ steps: [step, ...e.steps], item: e.item }));
|
|
329
348
|
})
|
|
330
349
|
]);
|
|
@@ -335,6 +354,7 @@
|
|
|
335
354
|
e.steps.length === 1 &&
|
|
336
355
|
typeof e.steps[0] === 'number' &&
|
|
337
356
|
e.steps[0] >= arr.length &&
|
|
357
|
+
!putsIn(e.item) &&
|
|
338
358
|
e.item.after !== undefined
|
|
339
359
|
)
|
|
340
360
|
);
|
|
@@ -1049,6 +1069,11 @@
|
|
|
1049
1069
|
<span class="qm-array-table-head-end"></span>
|
|
1050
1070
|
</div>
|
|
1051
1071
|
{#each ids as id, k (id)}
|
|
1072
|
+
{#each insertedAt(k) as { item, after }, n (`${item.id}:${n}`)}{@render addedRow(
|
|
1073
|
+
item,
|
|
1074
|
+
after,
|
|
1075
|
+
k
|
|
1076
|
+
)}{/each}
|
|
1052
1077
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
1053
1078
|
<div
|
|
1054
1079
|
class={['qm-array-row qm-array-table-row qm-wash', { lifted: drag.lifted(k) }]}
|
|
@@ -1075,7 +1100,11 @@
|
|
|
1075
1100
|
{@render removeButton(k, true)}
|
|
1076
1101
|
</div>
|
|
1077
1102
|
{/each}
|
|
1078
|
-
{#each added as { item }, n (item.id)}{@render addedRow(
|
|
1103
|
+
{#each added as { item }, n (item.id)}{@render addedRow(
|
|
1104
|
+
item,
|
|
1105
|
+
item.after,
|
|
1106
|
+
arr.length + n
|
|
1107
|
+
)}{/each}
|
|
1079
1108
|
</div>
|
|
1080
1109
|
</div>
|
|
1081
1110
|
{:else if control === 'object'}
|
|
@@ -1084,6 +1113,8 @@
|
|
|
1084
1113
|
data-default={defaulted ? '' : undefined}
|
|
1085
1114
|
bind:this={rowsEl}
|
|
1086
1115
|
>
|
|
1116
|
+
<!-- A row animates its moves, so it is its keyed block's only child, and a member a review
|
|
1117
|
+
puts in front of it is drawn after the rows and set in place by its flex order. -->
|
|
1087
1118
|
{#each ids as id, k (id)}
|
|
1088
1119
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
1089
1120
|
<!-- The handler catches a key from the controls inside the row and adds no
|
|
@@ -1093,6 +1124,7 @@
|
|
|
1093
1124
|
'qm-array-row qm-element qm-wash',
|
|
1094
1125
|
{ open: open.has(id), lifted: drag.lifted(k) }
|
|
1095
1126
|
]}
|
|
1127
|
+
style:order={2 * k + 1}
|
|
1096
1128
|
data-drop={drag.dropSide(k)}
|
|
1097
1129
|
data-qm-index={k}
|
|
1098
1130
|
bind:this={rowEls[id]}
|
|
@@ -1153,7 +1185,18 @@
|
|
|
1153
1185
|
{/if}
|
|
1154
1186
|
</div>
|
|
1155
1187
|
{/each}
|
|
1156
|
-
{#each
|
|
1188
|
+
{#each ids as _, k (k)}{#each insertedAt(k) as { item, after }, n (`${item.id}:${n}`)}{@render addedRow(
|
|
1189
|
+
item,
|
|
1190
|
+
after,
|
|
1191
|
+
k,
|
|
1192
|
+
2 * k
|
|
1193
|
+
)}{/each}{/each}
|
|
1194
|
+
{#each added as { item }, n (item.id)}{@render addedRow(
|
|
1195
|
+
item,
|
|
1196
|
+
item.after,
|
|
1197
|
+
arr.length + n,
|
|
1198
|
+
2 * arr.length + 1
|
|
1199
|
+
)}{/each}
|
|
1157
1200
|
</div>
|
|
1158
1201
|
{:else}
|
|
1159
1202
|
<div
|
|
@@ -1162,6 +1205,11 @@
|
|
|
1162
1205
|
bind:this={rowsEl}
|
|
1163
1206
|
>
|
|
1164
1207
|
{#each rowIds as id, k (id)}
|
|
1208
|
+
{#each insertedAt(k) as { item, after }, n (`${item.id}:${n}`)}{@render addedRow(
|
|
1209
|
+
item,
|
|
1210
|
+
after,
|
|
1211
|
+
k
|
|
1212
|
+
)}{/each}
|
|
1165
1213
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
1166
1214
|
<div
|
|
1167
1215
|
class={['qm-array-row qm-wash', { standing: id === standingId, lifted: drag.lifted(k) }]}
|
|
@@ -1178,9 +1226,9 @@
|
|
|
1178
1226
|
content={() => readAt([k])}
|
|
1179
1227
|
value={arr[k]}
|
|
1180
1228
|
proposed={rowText(k)}
|
|
1181
|
-
plaintext={
|
|
1229
|
+
plaintext={leafFlags(items).plaintext}
|
|
1182
1230
|
block={multiline}
|
|
1183
|
-
paragraphs={
|
|
1231
|
+
paragraphs={leafFlags(items).paragraphs}
|
|
1184
1232
|
cap={textCap(items)}
|
|
1185
1233
|
label={rowName(k)}
|
|
1186
1234
|
placeholder={id === standingId ? t.strings.arrayStanding : undefined}
|
|
@@ -1247,7 +1295,11 @@
|
|
|
1247
1295
|
<ReviewRows entries={rowMarks(k)} member />
|
|
1248
1296
|
</div>
|
|
1249
1297
|
{/each}
|
|
1250
|
-
{#each added as { item }, n (item.id)}{@render addedRow(
|
|
1298
|
+
{#each added as { item }, n (item.id)}{@render addedRow(
|
|
1299
|
+
item,
|
|
1300
|
+
item.after,
|
|
1301
|
+
arr.length + n
|
|
1302
|
+
)}{/each}
|
|
1251
1303
|
</div>
|
|
1252
1304
|
{/if}
|
|
1253
1305
|
<DiagnosticList diagnostics={foot} />
|
|
@@ -1258,8 +1310,7 @@
|
|
|
1258
1310
|
the value, tinted and inert: a table's as a row of its cells under the same headers, a record
|
|
1259
1311
|
list's collapsed to its summary. The row, not the control, hears the pointer and carries the
|
|
1260
1312
|
item, so a press on it names the item and the answer card stands on it. -->
|
|
1261
|
-
{#snippet addedRow(item: FieldProposal, k: number)}
|
|
1262
|
-
{@const after = item.after}
|
|
1313
|
+
{#snippet addedRow(item: FieldProposal, after: unknown, k: number, order?: number)}
|
|
1263
1314
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
1264
1315
|
<div
|
|
1265
1316
|
class={[
|
|
@@ -1270,6 +1321,7 @@
|
|
|
1270
1321
|
'qm-review-lit': reviewing.lit === item.id
|
|
1271
1322
|
}
|
|
1272
1323
|
]}
|
|
1324
|
+
style:order
|
|
1273
1325
|
data-qm-review={item.id}
|
|
1274
1326
|
role="group"
|
|
1275
1327
|
aria-label={t.strings.reviewNewItem}
|
|
@@ -1302,9 +1354,9 @@
|
|
|
1302
1354
|
<ProseValue
|
|
1303
1355
|
content={() => asContent(after)}
|
|
1304
1356
|
value={after}
|
|
1305
|
-
plaintext={
|
|
1357
|
+
plaintext={leafFlags(items).plaintext}
|
|
1306
1358
|
block={multiline}
|
|
1307
|
-
paragraphs={
|
|
1359
|
+
paragraphs={leafFlags(items).paragraphs}
|
|
1308
1360
|
label={rowName(k)}
|
|
1309
1361
|
onChange={() => {}}
|
|
1310
1362
|
/>
|
package/dist/visual/Card.svelte
CHANGED
|
@@ -38,8 +38,9 @@
|
|
|
38
38
|
retype: (kind: string) => void;
|
|
39
39
|
rename: (title: string) => void;
|
|
40
40
|
diagFor: (field?: string) => Diagnostic[] | undefined;
|
|
41
|
-
/** Consumer enum-option policy for a field
|
|
42
|
-
|
|
41
|
+
/** Consumer enum-option policy for a field, or for an enum `steps` down inside it;
|
|
42
|
+
* true when no hook set. */
|
|
43
|
+
enumAllowed: (field: string, value: string, steps?: readonly PathStep[]) => boolean;
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
interface Props {
|
|
@@ -400,7 +401,7 @@
|
|
|
400
401
|
leafKey={ops.leafKey(f.name)}
|
|
401
402
|
domIds={ops.domIds(f.name)}
|
|
402
403
|
onCommitScalar={(v) => ops.commit(f.name, v)}
|
|
403
|
-
optionAllowed={(v) => ops.enumAllowed(f.name, v)}
|
|
404
|
+
optionAllowed={(v, steps) => ops.enumAllowed(f.name, v, steps)}
|
|
404
405
|
{enumDisallowed}
|
|
405
406
|
{onFocus}
|
|
406
407
|
{onCaretMove}
|
|
@@ -15,8 +15,9 @@ interface CardOps {
|
|
|
15
15
|
retype: (kind: string) => void;
|
|
16
16
|
rename: (title: string) => void;
|
|
17
17
|
diagFor: (field?: string) => Diagnostic[] | undefined;
|
|
18
|
-
/** Consumer enum-option policy for a field
|
|
19
|
-
|
|
18
|
+
/** Consumer enum-option policy for a field, or for an enum `steps` down inside it;
|
|
19
|
+
* true when no hook set. */
|
|
20
|
+
enumAllowed: (field: string, value: string, steps?: readonly PathStep[]) => boolean;
|
|
20
21
|
}
|
|
21
22
|
interface Props {
|
|
22
23
|
card: CardModel;
|
package/dist/visual/Field.svelte
CHANGED
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
import ReviewProposal from './ReviewProposal.svelte';
|
|
61
61
|
import ReviewRows from './ReviewRows.svelte';
|
|
62
62
|
import { review } from './review.svelte.js';
|
|
63
|
-
import { numberProposal, shownValue,
|
|
63
|
+
import { numberProposal, shownValue, textsOf } from './review.js';
|
|
64
64
|
|
|
65
65
|
interface Props {
|
|
66
66
|
field: FieldModel;
|
|
@@ -83,9 +83,9 @@
|
|
|
83
83
|
* the label and the control find each other. */
|
|
84
84
|
domIds: FieldDomIds;
|
|
85
85
|
onCommitScalar: (value: unknown) => void;
|
|
86
|
-
/** Enum-option policy: `false` marks that option unavailable
|
|
87
|
-
* control
|
|
88
|
-
optionAllowed?: (value: string) => boolean;
|
|
86
|
+
/** Enum-option policy: `false` marks that option unavailable, on the field's own
|
|
87
|
+
* enum control (`steps` absent) or on an enum `steps` down its object subform. */
|
|
88
|
+
optionAllowed?: (value: string, steps?: readonly PathStep[]) => boolean;
|
|
89
89
|
/** How a refused option draws: greyed (default) or left out. */
|
|
90
90
|
enumDisallowed?: 'hide' | 'disable';
|
|
91
91
|
/** A focus inside the field: its address, and the steps down to the cell holding
|
|
@@ -323,16 +323,16 @@
|
|
|
323
323
|
* rather than counted twice.
|
|
324
324
|
*/
|
|
325
325
|
// ── Review: this field's own items (`review.svelte.ts`) ──────────────────────
|
|
326
|
-
/** A
|
|
327
|
-
*
|
|
328
|
-
* and the proposed figures. */
|
|
326
|
+
/** A proposed value drawn as words over the control's own: a text field's as a word diff,
|
|
327
|
+
* whatever its kind, a whole value or each run of one answer, carried onto what the reader
|
|
328
|
+
* wrote since its writer read it; a number's as the struck and the proposed figures. */
|
|
329
329
|
const texted = $derived(
|
|
330
|
-
field.control === 'prose' &&
|
|
331
|
-
?
|
|
330
|
+
field.control === 'prose' && proposed
|
|
331
|
+
? textsOf([proposed, ...(reviewed.more ?? [])], printed ? (ghost as Content) : undefined)
|
|
332
332
|
: undefined
|
|
333
333
|
);
|
|
334
334
|
const numbered = $derived(field.control === 'number' ? numberProposal(proposed) : undefined);
|
|
335
|
-
const worded = $derived(texted ?? numbered);
|
|
335
|
+
const worded = $derived(texted?.[0] ?? numbered);
|
|
336
336
|
/** What a control that cannot draw a proposal as words shows while one stands: the value
|
|
337
337
|
* Accept would write, tinted (`ReviewProposal`), or its default or empty face where Accept
|
|
338
338
|
* clears it. */
|
|
@@ -495,6 +495,8 @@
|
|
|
495
495
|
bind:this={objectEl}
|
|
496
496
|
value={value as Record<string, unknown> | undefined}
|
|
497
497
|
properties={field.schema.properties}
|
|
498
|
+
{optionAllowed}
|
|
499
|
+
{enumDisallowed}
|
|
498
500
|
{flat}
|
|
499
501
|
placed
|
|
500
502
|
label={field.label}
|
|
@@ -24,9 +24,9 @@ interface Props {
|
|
|
24
24
|
* the label and the control find each other. */
|
|
25
25
|
domIds: FieldDomIds;
|
|
26
26
|
onCommitScalar: (value: unknown) => void;
|
|
27
|
-
/** Enum-option policy: `false` marks that option unavailable
|
|
28
|
-
* control
|
|
29
|
-
optionAllowed?: (value: string) => boolean;
|
|
27
|
+
/** Enum-option policy: `false` marks that option unavailable, on the field's own
|
|
28
|
+
* enum control (`steps` absent) or on an enum `steps` down its object subform. */
|
|
29
|
+
optionAllowed?: (value: string, steps?: readonly PathStep[]) => boolean;
|
|
30
30
|
/** How a refused option draws: greyed (default) or left out. */
|
|
31
31
|
enumDisallowed?: 'hide' | 'disable';
|
|
32
32
|
/** A focus inside the field: its address, and the steps down to the cell holding
|