@quillmark/svelte 0.30.0 → 0.32.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 +5 -5
- package/dist/core/address.d.ts +1 -1
- package/dist/core/address.js +1 -1
- package/dist/core/codec/atoms.js +1 -1
- package/dist/core/codec/breaks.js +3 -2
- package/dist/core/codec/decode.d.ts +4 -3
- package/dist/core/codec/decode.js +17 -13
- package/dist/core/codec/field.d.ts +5 -4
- package/dist/core/codec/field.js +139 -49
- package/dist/core/codec/index.d.ts +2 -0
- package/dist/core/codec/index.js +5 -1
- package/dist/core/codec/inputrules.js +3 -3
- package/dist/core/codec/islands.d.ts +1 -1
- package/dist/core/codec/islands.js +3 -3
- package/dist/core/codec/keymap.d.ts +1 -1
- package/dist/core/codec/keymap.js +3 -2
- package/dist/core/codec/list-move.js +2 -1
- package/dist/core/codec/list-paste.js +1 -1
- package/dist/core/codec/lists.d.ts +1 -1
- package/dist/core/codec/lists.js +7 -6
- package/dist/core/codec/markdown-paste.js +2 -2
- package/dist/core/codec/positions.d.ts +12 -1
- package/dist/core/codec/prose.css +3 -11
- package/dist/core/codec/schema.d.ts +3 -3
- package/dist/core/codec/schema.js +6 -6
- package/dist/core/codec/shortcuts.d.ts +91 -0
- package/dist/core/codec/shortcuts.js +135 -0
- package/dist/core/codec/slash.d.ts +4 -2
- package/dist/core/codec/slash.js +11 -1
- package/dist/core/codec/table-paste.js +1 -1
- package/dist/core/codec/table-view.d.ts +1 -1
- package/dist/core/codec/table-view.js +27 -37
- package/dist/core/codec/tasks.js +1 -1
- package/dist/core/index.d.ts +1 -0
- package/dist/core/theme.css +16 -8
- package/dist/preset/scale.css +1 -1
- package/dist/preview/Preview.svelte +2 -3
- package/dist/preview/bridge.js +2 -2
- package/dist/preview/geometry.d.ts +2 -2
- package/dist/preview/geometry.js +2 -2
- package/dist/preview/paint.js +1 -1
- package/dist/visual/ArrayField.svelte +172 -87
- package/dist/visual/BooleanField.svelte +3 -3
- package/dist/visual/Card.svelte +68 -47
- package/dist/visual/CardControls.svelte +1 -1
- package/dist/visual/DateField.svelte +17 -2
- package/dist/visual/DiagnosticList.svelte +35 -3
- package/dist/visual/EnumField.svelte +59 -45
- package/dist/visual/Field.svelte +16 -6
- package/dist/visual/Field.svelte.d.ts +3 -1
- package/dist/visual/FieldHint.svelte +10 -3
- package/dist/visual/FormatPopover.svelte +9 -3
- package/dist/visual/MatrixAdd.svelte +4 -19
- package/dist/visual/MatrixField.svelte +21 -13
- package/dist/visual/NumberField.svelte +2 -3
- package/dist/visual/ObjectField.svelte +166 -147
- package/dist/visual/ProseField.svelte +8 -3
- package/dist/visual/SlashMenu.svelte +24 -12
- package/dist/visual/SlashMenu.svelte.d.ts +2 -0
- package/dist/visual/TextField.svelte +1 -1
- package/dist/visual/VariantField.svelte +1 -1
- package/dist/visual/VisualEditor.svelte +1 -1
- package/dist/visual/VisualEditor.svelte.d.ts +1 -1
- package/dist/visual/VisualEditorInner.svelte +159 -24
- package/dist/visual/VisualEditorInner.svelte.d.ts +1 -1
- package/dist/visual/controls.css +43 -5
- package/dist/visual/diagnostics.d.ts +2 -2
- package/dist/visual/diagnostics.js +2 -2
- package/dist/visual/index.d.ts +2 -0
- package/dist/visual/index.js +3 -0
- package/dist/visual/leaves.js +1 -1
- package/dist/visual/props.d.ts +2 -2
- package/dist/visual/strings.d.ts +33 -15
- package/dist/visual/strings.js +42 -7
- package/dist/visual/structure.d.ts +27 -18
- package/dist/visual/structure.js +32 -28
- package/dist/visual/tips.js +1 -1
- package/dist/visual/undo.svelte.d.ts +36 -0
- package/dist/visual/undo.svelte.js +119 -0
- package/package.json +2 -2
- package/dist/visual/hold.d.ts +0 -17
- package/dist/visual/hold.js +0 -39
package/dist/visual/props.d.ts
CHANGED
|
@@ -61,7 +61,7 @@ export interface VisualEditorProps {
|
|
|
61
61
|
onError?: EditorErrorHandler;
|
|
62
62
|
/**
|
|
63
63
|
* External diagnostics, routed by `.path` and merged with `quill.validate`
|
|
64
|
-
* and local commit errors (
|
|
64
|
+
* and local commit errors (INVARIANTS §Diagnostics). Warnings do not draw.
|
|
65
65
|
*/
|
|
66
66
|
diagnostics?: Diagnostic[];
|
|
67
67
|
/**
|
|
@@ -78,7 +78,7 @@ export interface VisualEditorProps {
|
|
|
78
78
|
* it in place, `'hide'` leaves it out of the list. One policy for the surface, not
|
|
79
79
|
* a per-option verdict, and the selected value is drawn under either (disabled
|
|
80
80
|
* when refused), so the control always shows what the document says
|
|
81
|
-
* (
|
|
81
|
+
* (INVARIANTS §Enums).
|
|
82
82
|
*/
|
|
83
83
|
enumDisallowed?: 'hide' | 'disable';
|
|
84
84
|
/**
|
package/dist/visual/strings.d.ts
CHANGED
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
import type { Diagnostic } from '@quillmark/wasm';
|
|
2
|
-
import { type SlashStrings, type TableChromeStrings } from '../core/codec/index.js';
|
|
2
|
+
import { type ShortcutStrings, type SlashStrings, type TableChromeStrings } from '../core/codec/index.js';
|
|
3
3
|
import type { BodyPlaceholder } from './structure.js';
|
|
4
4
|
/**
|
|
5
|
-
* The island and the
|
|
6
|
-
* (a NodeView inside the leaf,
|
|
5
|
+
* The island, the insert menu and the shortcut list's keys come from the codec, which owns
|
|
6
|
+
* all three models (a NodeView inside the leaf, the trigger the leaf's keymap drives, and
|
|
7
|
+
* the keymaps' own tables). Extending
|
|
7
8
|
* rather than restating them is what keeps one English list: a consumer overrides an
|
|
8
9
|
* island handle's name beside the card controls' and the codec still has a default
|
|
9
10
|
* for a leaf mounted directly.
|
|
10
11
|
*/
|
|
11
|
-
export interface VisualStrings extends TableChromeStrings, SlashStrings {
|
|
12
|
+
export interface VisualStrings extends TableChromeStrings, SlashStrings, ShortcutStrings {
|
|
12
13
|
cardMoveUp: string;
|
|
13
14
|
cardMoveDown: string;
|
|
14
15
|
cardDelete: string;
|
|
15
16
|
/** The card-title input's accessible name. */
|
|
16
17
|
cardTitle: string;
|
|
18
|
+
/** A closed panel's header, spoken after its name (`Layout, has an issue`) when a field
|
|
19
|
+
* inside holds a diagnostic: the leading separator is part of the wording. */
|
|
20
|
+
groupFlagged: string;
|
|
21
|
+
/** The toast's notice, named for what went: `Authors 2 removed`. */
|
|
22
|
+
undoRemoved: (what: string) => string;
|
|
23
|
+
/** The toast's button, which puts it back. */
|
|
24
|
+
undoAction: string;
|
|
17
25
|
/** The trailing strip's visible words, drawn after a `+`, and every
|
|
18
26
|
* strip's accessible name. One string over
|
|
19
27
|
* one kind and many: the trigger seeds a card, and which kind is the menu's word
|
|
@@ -42,16 +50,25 @@ export interface VisualStrings extends TableChromeStrings, SlashStrings {
|
|
|
42
50
|
*/
|
|
43
51
|
textCount: (count: number, max: number) => string;
|
|
44
52
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
|
|
53
|
+
* An `object` array element's title, open or collapsed: the 1-based index, the label
|
|
54
|
+
* standing over the list already. Parametric, so word order stays the translator's.
|
|
55
|
+
*/
|
|
56
|
+
elementItem: (index: number) => string;
|
|
57
|
+
/**
|
|
58
|
+
* An `object` array element's accessible name: the label and {@link elementItem},
|
|
59
|
+
* so the words the row draws are inside the name it is spoken by.
|
|
48
60
|
*/
|
|
49
61
|
elementUntitled: (label: string, index: number) => string;
|
|
50
|
-
/**
|
|
51
|
-
|
|
62
|
+
/** `validation::type_mismatch`: the value is not the declared type (`args.expected`). */
|
|
63
|
+
diagTypeMismatch: (expected: string) => string;
|
|
64
|
+
/** `validation::format_violation`: the value misses a string format (`args.format`). */
|
|
65
|
+
diagFormatViolation: (format: string) => string;
|
|
66
|
+
/** The tag on the `default:` member's row ({@link EnumField}). */
|
|
52
67
|
enumUnsetTag: string;
|
|
53
|
-
/** The
|
|
54
|
-
|
|
68
|
+
/** The row under a stored value that clears it back to the `default:`. */
|
|
69
|
+
enumReset: string;
|
|
70
|
+
/** The same row where no `default:` prints: no `default:`, a blank one, or an `enum?`. */
|
|
71
|
+
enumClear: string;
|
|
55
72
|
/** The count in the matrix's label row: how many of its items are held. */
|
|
56
73
|
matrixHeld: (held: number, total: number) => string;
|
|
57
74
|
/** An open matrix's add box at rest, naming the list it adds to: `Add to Staff…`. The box
|
|
@@ -127,7 +144,7 @@ export interface VisualStrings extends TableChromeStrings, SlashStrings {
|
|
|
127
144
|
*
|
|
128
145
|
* A formatter reads the whole `Diagnostic`, including `args`: the facts `message`
|
|
129
146
|
* interpolates, keyed by name. What it can re-word tracks what that type carries per
|
|
130
|
-
* lane (
|
|
147
|
+
* lane (INVARIANTS §Diagnostics for why each lands where it does):
|
|
131
148
|
*
|
|
132
149
|
* - **`validation::enum_violation`, `type_mismatch`, `format_violation`**: the
|
|
133
150
|
* constraint re-words from the quill's schema at `path`, the offending value from
|
|
@@ -182,6 +199,7 @@ export declare function setWording(channel: Wording): void;
|
|
|
182
199
|
* composing one directly) still has every key.
|
|
183
200
|
*/
|
|
184
201
|
export declare function wording(): Wording;
|
|
185
|
-
/** A diagnostic's displayed text: the consumer's formatter,
|
|
186
|
-
*
|
|
187
|
-
|
|
202
|
+
/** A diagnostic's displayed text: the consumer's formatter, else the package's wording for
|
|
203
|
+
* a validation code whose `args` carry what it needs, else its message. The last arm is
|
|
204
|
+
* permanent, not a courtesy ({@link FormatDiagnostic}). */
|
|
205
|
+
export declare function diagnosticText(d: Diagnostic, format: FormatDiagnostic | undefined, strings?: VisualStrings): string;
|
package/dist/visual/strings.js
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
// would put a `strings` prop on every component between the root and each leaf,
|
|
19
19
|
// which is a prop that means nothing to any of them.
|
|
20
20
|
import { getContext, setContext } from 'svelte';
|
|
21
|
-
import { DEFAULT_SLASH_STRINGS, DEFAULT_TABLE_STRINGS } from '../core/codec/index.js';
|
|
21
|
+
import { DEFAULT_SHORTCUT_STRINGS, DEFAULT_SLASH_STRINGS, DEFAULT_TABLE_STRINGS } from '../core/codec/index.js';
|
|
22
22
|
/**
|
|
23
23
|
* A `Mod` chord as the writer's platform prints it: `⌘B` on Apple's, `Ctrl+B`
|
|
24
24
|
* elsewhere, and `Shift-7` as `⇧⌘7` or `Ctrl+Shift+7`. The platform test is the one
|
|
@@ -35,10 +35,14 @@ export function chord(key, platform = typeof navigator === 'undefined' ? '' : na
|
|
|
35
35
|
export const DEFAULT_VISUAL_STRINGS = {
|
|
36
36
|
...DEFAULT_TABLE_STRINGS,
|
|
37
37
|
...DEFAULT_SLASH_STRINGS,
|
|
38
|
+
...DEFAULT_SHORTCUT_STRINGS,
|
|
38
39
|
cardMoveUp: 'Move up',
|
|
39
40
|
cardMoveDown: 'Move down',
|
|
40
41
|
cardDelete: 'Delete card',
|
|
41
42
|
cardTitle: 'Card title',
|
|
43
|
+
groupFlagged: ', has an issue',
|
|
44
|
+
undoRemoved: (what) => `${what} removed`,
|
|
45
|
+
undoAction: 'Undo',
|
|
42
46
|
addCard: 'Add Card',
|
|
43
47
|
arrayAdd: '+ Add',
|
|
44
48
|
arrayRemove: 'Remove',
|
|
@@ -46,9 +50,23 @@ export const DEFAULT_VISUAL_STRINGS = {
|
|
|
46
50
|
arrayRowAction: (action, row) => `${action} ${row}`,
|
|
47
51
|
arrayCount: (count, max) => `${count} / ${max}`,
|
|
48
52
|
textCount: (count, max) => `${count} / ${max}`,
|
|
49
|
-
|
|
53
|
+
elementItem: (index) => `Item ${index}`,
|
|
54
|
+
elementUntitled: (label, index) => `${label}, item ${index}`,
|
|
55
|
+
diagTypeMismatch: (expected) => expected === 'boolean'
|
|
56
|
+
? 'Needs to be on or off.'
|
|
57
|
+
: expected === 'integer'
|
|
58
|
+
? 'Needs a whole number, like 12.'
|
|
59
|
+
: expected === 'number'
|
|
60
|
+
? 'Needs a number, like 12.'
|
|
61
|
+
: `Needs a ${expected} value.`,
|
|
62
|
+
diagFormatViolation: (format) => format === 'date'
|
|
63
|
+
? 'Not a real date. Type it as YYYY-MM-DD, or press Today.'
|
|
64
|
+
: format === 'datetime'
|
|
65
|
+
? 'Not a real date and time. Type it as YYYY-MM-DDTHH:MM.'
|
|
66
|
+
: `Doesn't match the ${format} format.`,
|
|
50
67
|
enumUnsetTag: 'Default',
|
|
51
|
-
|
|
68
|
+
enumReset: 'Reset to default',
|
|
69
|
+
enumClear: 'Clear',
|
|
52
70
|
matrixHeld: (held, total) => `${held} of ${total} held`,
|
|
53
71
|
matrixAdd: (list) => (list ? `Add to ${list}…` : 'Add…'),
|
|
54
72
|
matrixItemTitle: (list, index) => `${list ? `${list} item` : 'Item'} ${index}`,
|
|
@@ -102,8 +120,25 @@ export function setWording(channel) {
|
|
|
102
120
|
export function wording() {
|
|
103
121
|
return (getContext(KEY) ?? { strings: DEFAULT_VISUAL_STRINGS, formatDiagnostic: undefined });
|
|
104
122
|
}
|
|
105
|
-
/** A diagnostic's displayed text: the consumer's formatter,
|
|
106
|
-
*
|
|
107
|
-
|
|
108
|
-
|
|
123
|
+
/** A diagnostic's displayed text: the consumer's formatter, else the package's wording for
|
|
124
|
+
* a validation code whose `args` carry what it needs, else its message. The last arm is
|
|
125
|
+
* permanent, not a courtesy ({@link FormatDiagnostic}). */
|
|
126
|
+
export function diagnosticText(d, format, strings) {
|
|
127
|
+
return (format ? format(d) : undefined) ?? (strings && builtIn(d, strings)) ?? d.message;
|
|
128
|
+
}
|
|
129
|
+
function builtIn(d, strings) {
|
|
130
|
+
const args = (d.args ?? {});
|
|
131
|
+
const str = (k) => typeof args[k] === 'string' ? args[k] : undefined;
|
|
132
|
+
switch (d.code) {
|
|
133
|
+
case 'validation::type_mismatch': {
|
|
134
|
+
const expected = str('expected');
|
|
135
|
+
return expected ? strings.diagTypeMismatch(expected) : undefined;
|
|
136
|
+
}
|
|
137
|
+
case 'validation::format_violation': {
|
|
138
|
+
const format = str('format');
|
|
139
|
+
return format ? strings.diagFormatViolation(format) : undefined;
|
|
140
|
+
}
|
|
141
|
+
default:
|
|
142
|
+
return undefined;
|
|
143
|
+
}
|
|
109
144
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Content, type PathStep, type PayloadItem, type QuillCardSchema, type QuillFieldSchema, type QuillFieldType, type ResolvedField, type Resolved } from '@quillmark/wasm';
|
|
2
2
|
import type { TextCap } from '../core/codec/index.js';
|
|
3
|
-
/** The control a field type maps to (
|
|
3
|
+
/** The control a field type maps to (INVARIANTS §"Structure mirrors the schema"). */
|
|
4
4
|
export type ControlKind = 'prose' | 'text' | 'enum' | 'variant' | 'number' | 'boolean' | 'date' | 'array' | 'object' | 'matrix';
|
|
5
5
|
/** The container controls: the ones a nested address walks into and a deep
|
|
6
6
|
* diagnostic routes through. */
|
|
@@ -132,7 +132,8 @@ export type BodyPlaceholder = (ctx: BodyPlaceholderContext) => string | undefine
|
|
|
132
132
|
*/
|
|
133
133
|
export declare function resolveBodyGhost(resolvedDefault: string | undefined, custom: string | undefined, builtIn: string): string;
|
|
134
134
|
/** Whether a cell is optional: a `t?` type, which renders `none` unanswered and so
|
|
135
|
-
* never declares a `default:` (
|
|
135
|
+
* never declares a `default:` (quillmark `docs/quills/quill-yaml-reference.md`
|
|
136
|
+
* §"Optional fields"). */
|
|
136
137
|
export declare function optionalCell(f: QuillFieldSchema): boolean;
|
|
137
138
|
/**
|
|
138
139
|
* The declared type with an optional cell's `?` stripped; the `?` moves the render floor and
|
|
@@ -173,7 +174,7 @@ export declare function controlKind(f: QuillFieldSchema): ControlKind;
|
|
|
173
174
|
export declare const VARIANT_DISCRIMINANT: "value";
|
|
174
175
|
/** The label key of an open matrix's added item, the one cell a roster member never
|
|
175
176
|
* stores. The boundary exports no constant for it, so the package spells it once
|
|
176
|
-
* (
|
|
177
|
+
* (quillmark `docs/quills/quill-yaml-reference.md` §Matrix). */
|
|
177
178
|
export declare const MATRIX_TITLE = "title";
|
|
178
179
|
/** One item of a matrix: its id and its title. */
|
|
179
180
|
export interface MatrixMember {
|
|
@@ -244,15 +245,13 @@ export declare function matrixMemberSchema(matrix: QuillFieldSchema, id: string)
|
|
|
244
245
|
* under a `matrix` and a key under that member, a cell of any world (or the
|
|
245
246
|
* discriminant) under a variant-bearing `enum`. The editor's copy of the boundary's
|
|
246
247
|
* `schema_at`, held here because the landing lane checks an address against the schema
|
|
247
|
-
* before it asks the mounted tree for it (
|
|
248
|
+
* before it asks the mounted tree for it (INVARIANTS §Surface).
|
|
248
249
|
*/
|
|
249
250
|
export declare function schemaAt(field: QuillFieldSchema, steps: readonly PathStep[]): QuillFieldSchema | undefined;
|
|
250
251
|
/**
|
|
251
|
-
* Whether a cell is one line tall by declaration: what a table column
|
|
252
|
+
* Whether a cell is one line tall by declaration: what a table column can hold.
|
|
252
253
|
*/
|
|
253
254
|
export declare function shortCell(sub: QuillFieldSchema): boolean;
|
|
254
|
-
/** A collapsed row's own words ({@link firstShortText}). */
|
|
255
|
-
export declare function rowSummary(items: QuillFieldSchema | undefined, row: unknown): string | undefined;
|
|
256
255
|
/** How an `array` draws its elements. */
|
|
257
256
|
export type ArrayLayout = 'list' | 'table';
|
|
258
257
|
/**
|
|
@@ -260,7 +259,7 @@ export type ArrayLayout = 'list' | 'table';
|
|
|
260
259
|
* and every cell of the row is short (a block prose cell declines it, at load width and
|
|
261
260
|
* every width after), else `'list'`. That every column is a leaf is the loader's
|
|
262
261
|
* contract (`quill::table_column_not_leaf`); whether a leaf fits a cell is the surface's
|
|
263
|
-
* answer (
|
|
262
|
+
* answer (quillmark `docs/quills/quill-yaml-reference.md` §layout): a table composes by position, so a row that would stack
|
|
264
263
|
* inside a cell is not one.
|
|
265
264
|
*/
|
|
266
265
|
export declare function arrayLayout(field: QuillFieldSchema): ArrayLayout;
|
|
@@ -276,8 +275,8 @@ export declare function variantCells(schema: QuillFieldSchema, member: string |
|
|
|
276
275
|
/**
|
|
277
276
|
* The container a discriminant pick commits, and the discriminant cell alone the unset
|
|
278
277
|
* sentinel clears: sibling cells are **kept** either way, since the boundary carries an
|
|
279
|
-
* answer its world does not select rather than dropping it (
|
|
280
|
-
*
|
|
278
|
+
* answer its world does not select rather than dropping it (INVARIANTS
|
|
279
|
+
* §Enums). A container left holding nothing is an unset field, which commits
|
|
281
280
|
* `undefined`.
|
|
282
281
|
*/
|
|
283
282
|
export declare function commitDiscriminant(value: Record<string, unknown> | undefined, member: string | undefined): Record<string, unknown> | undefined;
|
|
@@ -289,7 +288,7 @@ export declare function fieldTitle(key: string, schema: QuillFieldSchema): strin
|
|
|
289
288
|
* card-level object's `properties` project the same way. */
|
|
290
289
|
export declare function fieldModels(cardSchema: Pick<QuillCardSchema, 'fields'>): FieldModel[];
|
|
291
290
|
/**
|
|
292
|
-
* Group-section order (
|
|
291
|
+
* Group-section order (INVARIANTS §"Structure mirrors the schema"): the `ui.groups` key order,
|
|
293
292
|
* else first appearance of each field's `ui.group`.
|
|
294
293
|
*/
|
|
295
294
|
export declare function groupOrder(cardSchema: QuillCardSchema): string[];
|
|
@@ -301,7 +300,7 @@ export declare function groupLabel(cardSchema: QuillCardSchema, group: string):
|
|
|
301
300
|
*/
|
|
302
301
|
export declare function groupSections(fields: FieldModel[], order: string[], labelFor: (group: string) => string): GroupSection[];
|
|
303
302
|
/**
|
|
304
|
-
* Object-panel sections (
|
|
303
|
+
* Object-panel sections (INVARIANTS §"Structure mirrors the schema"): every
|
|
305
304
|
* top-level `object` is a panel of its own, headed by the object, in declaration
|
|
306
305
|
* order; everything else stands in one unframed section above them. The section id
|
|
307
306
|
* is the field name, which a card's keys hold unique.
|
|
@@ -314,27 +313,37 @@ export declare function objectSections(fields: FieldModel[]): GroupSection[];
|
|
|
314
313
|
*/
|
|
315
314
|
export declare function cardSections(cardSchema: QuillCardSchema): GroupSection[];
|
|
316
315
|
/**
|
|
317
|
-
* The group section a card
|
|
316
|
+
* The group section a card opens on first mount, or `null` when the card declares none.
|
|
318
317
|
* All-collapsed would disclose nothing of what is behind the chevrons, and a rule keyed on document
|
|
319
318
|
* state would move the opening under a user as they fill.
|
|
320
319
|
*/
|
|
321
320
|
export declare function initialExpandedGroup(sections: GroupSection[]): string | null;
|
|
322
321
|
/** How wide a field sits in its section grid. */
|
|
323
322
|
export type FieldSpan = 'cell' | 'full';
|
|
323
|
+
/**
|
|
324
|
+
* Where a run's last cell would stand alone in its row, by capacity: `odd` at two tracks
|
|
325
|
+
* (an odd run), `lone` at two and four (a run one past a multiple of four). The grid
|
|
326
|
+
* reads it against the capacity it stands at (`--tail-odd`, `--tail-lone`, the ladder in
|
|
327
|
+
* controls.css), so the field takes the row only where it would be alone in it.
|
|
328
|
+
*/
|
|
329
|
+
export type RunTail = 'odd' | 'lone';
|
|
324
330
|
export interface PlacedField {
|
|
325
331
|
field: FieldModel;
|
|
326
332
|
span: FieldSpan;
|
|
333
|
+
tail?: RunTail;
|
|
327
334
|
}
|
|
328
335
|
/**
|
|
329
|
-
* Consecutive packable fields are `cell`s the grid auto-places
|
|
330
|
-
*
|
|
331
|
-
* empty.
|
|
336
|
+
* Consecutive packable fields are `cell`s the grid auto-places, and a run of one is `full`:
|
|
337
|
+
* alone, a field would stand in a narrow track that reads as truncated against the width it
|
|
338
|
+
* leaves empty. A longer run's last cell carries its `tail`, which the grid spends at the
|
|
339
|
+
* capacity it stands at, so the last of three spans the row at two tracks and shares it at
|
|
340
|
+
* four. Everything else is `full`. No width is measured.
|
|
332
341
|
*/
|
|
333
342
|
export declare function placeFields(fields: FieldModel[]): PlacedField[];
|
|
334
343
|
/** A card's field values by key, off its payload items. */
|
|
335
344
|
export declare function fieldValues(items: readonly PayloadItem[]): Record<string, unknown>;
|
|
336
|
-
/** A field value as title text. A
|
|
337
|
-
*
|
|
345
|
+
/** A field value as title text. A text field rests as the authored string or as
|
|
346
|
+
* `Content`, whose `text` is the same words; a scalar reads as
|
|
338
347
|
* itself; a variant container reads as its discriminant member, the one cell of it
|
|
339
348
|
* that names the world; any other container as nothing. */
|
|
340
349
|
export declare function titleText(v: unknown): string;
|
package/dist/visual/structure.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// The schema × payload join, as pure functions (
|
|
1
|
+
// The schema × payload join, as pure functions (INVARIANTS §"Structure mirrors the schema"). The reactive
|
|
2
2
|
// orchestration lives in VisualEditor.svelte.
|
|
3
3
|
import { VARIANT_DISCRIMINANT_KEY } from '@quillmark/wasm';
|
|
4
4
|
import { core } from '../core/lifecycle.js';
|
|
@@ -57,7 +57,8 @@ export function resolveBodyGhost(resolvedDefault, custom, builtIn) {
|
|
|
57
57
|
return resolvedDefault || custom || builtIn;
|
|
58
58
|
}
|
|
59
59
|
/** Whether a cell is optional: a `t?` type, which renders `none` unanswered and so
|
|
60
|
-
* never declares a `default:` (
|
|
60
|
+
* never declares a `default:` (quillmark `docs/quills/quill-yaml-reference.md`
|
|
61
|
+
* §"Optional fields"). */
|
|
61
62
|
export function optionalCell(f) {
|
|
62
63
|
return f.type.endsWith('?');
|
|
63
64
|
}
|
|
@@ -130,8 +131,8 @@ export function controlKind(f) {
|
|
|
130
131
|
case 'text':
|
|
131
132
|
return 'prose';
|
|
132
133
|
case 'enum':
|
|
133
|
-
// `variants:` is the one key that changes a field's resting shape (
|
|
134
|
-
// `
|
|
134
|
+
// `variants:` is the one key that changes a field's resting shape (quillmark
|
|
135
|
+
// `docs/quills/quill-yaml-reference.md` §Variants): with it the field rests as a container, without it a bare string.
|
|
135
136
|
return f.variants ? 'variant' : 'enum';
|
|
136
137
|
case 'number':
|
|
137
138
|
case 'integer':
|
|
@@ -157,7 +158,7 @@ export function controlKind(f) {
|
|
|
157
158
|
export const VARIANT_DISCRIMINANT = VARIANT_DISCRIMINANT_KEY;
|
|
158
159
|
/** The label key of an open matrix's added item, the one cell a roster member never
|
|
159
160
|
* stores. The boundary exports no constant for it, so the package spells it once
|
|
160
|
-
* (
|
|
161
|
+
* (quillmark `docs/quills/quill-yaml-reference.md` §Matrix). */
|
|
161
162
|
export const MATRIX_TITLE = 'title';
|
|
162
163
|
/** The roster's members, in declaration order. Own keys only: a schema map is indexed
|
|
163
164
|
* by a document-supplied id, and `'toString' in members` is true of every roster. */
|
|
@@ -275,7 +276,7 @@ export function addedItems(matrix, map) {
|
|
|
275
276
|
const title = stored[MATRIX_TITLE];
|
|
276
277
|
if (title == null)
|
|
277
278
|
continue;
|
|
278
|
-
out.push({ id, title:
|
|
279
|
+
out.push({ id, title: titleText(title) });
|
|
279
280
|
}
|
|
280
281
|
return out.sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
|
|
281
282
|
}
|
|
@@ -317,7 +318,7 @@ export function matrixMemberSchema(matrix, id) {
|
|
|
317
318
|
* under a `matrix` and a key under that member, a cell of any world (or the
|
|
318
319
|
* discriminant) under a variant-bearing `enum`. The editor's copy of the boundary's
|
|
319
320
|
* `schema_at`, held here because the landing lane checks an address against the schema
|
|
320
|
-
* before it asks the mounted tree for it (
|
|
321
|
+
* before it asks the mounted tree for it (INVARIANTS §Surface).
|
|
321
322
|
*/
|
|
322
323
|
export function schemaAt(field, steps) {
|
|
323
324
|
let cursor = field;
|
|
@@ -360,9 +361,9 @@ function stepInto(schema, step) {
|
|
|
360
361
|
return undefined;
|
|
361
362
|
}
|
|
362
363
|
}
|
|
363
|
-
// ──
|
|
364
|
+
// ── Short cells and layouts ──────────────────────────────────────────────────
|
|
364
365
|
/**
|
|
365
|
-
* Whether a cell is one line tall by declaration: what a table column
|
|
366
|
+
* Whether a cell is one line tall by declaration: what a table column can hold.
|
|
366
367
|
*/
|
|
367
368
|
export function shortCell(sub) {
|
|
368
369
|
const kind = controlKind(sub);
|
|
@@ -383,16 +384,12 @@ function firstShortText(cells, values) {
|
|
|
383
384
|
return undefined;
|
|
384
385
|
return titleText(own(values, named[0])).trim() || undefined;
|
|
385
386
|
}
|
|
386
|
-
/** A collapsed row's own words ({@link firstShortText}). */
|
|
387
|
-
export function rowSummary(items, row) {
|
|
388
|
-
return firstShortText(items?.properties, (row ?? {}));
|
|
389
|
-
}
|
|
390
387
|
/**
|
|
391
388
|
* The layout an array takes: `'table'` where the array's own `ui.layout` asks for it
|
|
392
389
|
* and every cell of the row is short (a block prose cell declines it, at load width and
|
|
393
390
|
* every width after), else `'list'`. That every column is a leaf is the loader's
|
|
394
391
|
* contract (`quill::table_column_not_leaf`); whether a leaf fits a cell is the surface's
|
|
395
|
-
* answer (
|
|
392
|
+
* answer (quillmark `docs/quills/quill-yaml-reference.md` §layout): a table composes by position, so a row that would stack
|
|
396
393
|
* inside a cell is not one.
|
|
397
394
|
*/
|
|
398
395
|
export function arrayLayout(field) {
|
|
@@ -421,8 +418,8 @@ export function variantCells(schema, member) {
|
|
|
421
418
|
/**
|
|
422
419
|
* The container a discriminant pick commits, and the discriminant cell alone the unset
|
|
423
420
|
* sentinel clears: sibling cells are **kept** either way, since the boundary carries an
|
|
424
|
-
* answer its world does not select rather than dropping it (
|
|
425
|
-
*
|
|
421
|
+
* answer its world does not select rather than dropping it (INVARIANTS
|
|
422
|
+
* §Enums). A container left holding nothing is an unset field, which commits
|
|
426
423
|
* `undefined`.
|
|
427
424
|
*/
|
|
428
425
|
export function commitDiscriminant(value, member) {
|
|
@@ -468,7 +465,7 @@ export function fieldModels(cardSchema) {
|
|
|
468
465
|
});
|
|
469
466
|
}
|
|
470
467
|
/**
|
|
471
|
-
* Group-section order (
|
|
468
|
+
* Group-section order (INVARIANTS §"Structure mirrors the schema"): the `ui.groups` key order,
|
|
472
469
|
* else first appearance of each field's `ui.group`.
|
|
473
470
|
*/
|
|
474
471
|
export function groupOrder(cardSchema) {
|
|
@@ -515,7 +512,7 @@ export function groupSections(fields, order, labelFor) {
|
|
|
515
512
|
return sections;
|
|
516
513
|
}
|
|
517
514
|
/**
|
|
518
|
-
* Object-panel sections (
|
|
515
|
+
* Object-panel sections (INVARIANTS §"Structure mirrors the schema"): every
|
|
519
516
|
* top-level `object` is a panel of its own, headed by the object, in declaration
|
|
520
517
|
* order; everything else stands in one unframed section above them. The section id
|
|
521
518
|
* is the field name, which a card's keys hold unique.
|
|
@@ -544,7 +541,7 @@ export function cardSections(cardSchema) {
|
|
|
544
541
|
return [...panels, ...groupSections(grouped, order, (g) => groupLabel(cardSchema, g))];
|
|
545
542
|
}
|
|
546
543
|
/**
|
|
547
|
-
* The group section a card
|
|
544
|
+
* The group section a card opens on first mount, or `null` when the card declares none.
|
|
548
545
|
* All-collapsed would disclose nothing of what is behind the chevrons, and a rule keyed on document
|
|
549
546
|
* state would move the opening under a user as they fill.
|
|
550
547
|
*/
|
|
@@ -580,18 +577,25 @@ function packable(f) {
|
|
|
580
577
|
return f.control !== 'prose' || f.inline;
|
|
581
578
|
}
|
|
582
579
|
/**
|
|
583
|
-
* Consecutive packable fields are `cell`s the grid auto-places
|
|
584
|
-
*
|
|
585
|
-
* empty.
|
|
580
|
+
* Consecutive packable fields are `cell`s the grid auto-places, and a run of one is `full`:
|
|
581
|
+
* alone, a field would stand in a narrow track that reads as truncated against the width it
|
|
582
|
+
* leaves empty. A longer run's last cell carries its `tail`, which the grid spends at the
|
|
583
|
+
* capacity it stands at, so the last of three spans the row at two tracks and shares it at
|
|
584
|
+
* four. Everything else is `full`. No width is measured.
|
|
586
585
|
*/
|
|
587
586
|
export function placeFields(fields) {
|
|
588
587
|
const out = [];
|
|
589
588
|
let run = 0;
|
|
590
|
-
// A run
|
|
591
|
-
// field already placed.
|
|
589
|
+
// A run's length is only knowable at its end, so the span or tail is patched back onto
|
|
590
|
+
// the field already placed.
|
|
592
591
|
const flush = () => {
|
|
592
|
+
const last = out[out.length - 1];
|
|
593
593
|
if (run === 1)
|
|
594
|
-
|
|
594
|
+
last.span = 'full';
|
|
595
|
+
else if (run % 4 === 1)
|
|
596
|
+
last.tail = 'lone';
|
|
597
|
+
else if (run % 2 === 1)
|
|
598
|
+
last.tail = 'odd';
|
|
595
599
|
run = 0;
|
|
596
600
|
};
|
|
597
601
|
for (const f of fields) {
|
|
@@ -615,8 +619,8 @@ export function fieldValues(items) {
|
|
|
615
619
|
values[p.key] = p.value;
|
|
616
620
|
return values;
|
|
617
621
|
}
|
|
618
|
-
/** A field value as title text. A
|
|
619
|
-
*
|
|
622
|
+
/** A field value as title text. A text field rests as the authored string or as
|
|
623
|
+
* `Content`, whose `text` is the same words; a scalar reads as
|
|
620
624
|
* itself; a variant container reads as its discriminant member, the one cell of it
|
|
621
625
|
* that names the world; any other container as nothing. */
|
|
622
626
|
export function titleText(v) {
|
|
@@ -653,7 +657,7 @@ export function cardTitle(cardSchema, kind, values, extTitle) {
|
|
|
653
657
|
export function bodyEnabled(cardSchema) {
|
|
654
658
|
return cardSchema?.body?.enabled !== false;
|
|
655
659
|
}
|
|
656
|
-
// ── Session identity (
|
|
660
|
+
// ── Session identity (INVARIANTS §"The address is the spine") ─────────────
|
|
657
661
|
// Cards are positional in the content and `doc.cards` re-allocates on each read,
|
|
658
662
|
// so a stable card-instance key cannot be the card object (a fresh object every
|
|
659
663
|
// derive): it is a session id held in a parallel array, reordered in lockstep
|
package/dist/visual/tips.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// The tips channel: `$ext.editor.tips`, a list of authoring hints a
|
|
2
2
|
// quill or consumer seeds, which the editor only ever renders and clears.
|
|
3
3
|
// Editor-only chrome; never reaches the render backend, never gates, absent when
|
|
4
|
-
// the channel is empty (
|
|
4
|
+
// the channel is empty (INVARIANTS §"Card operations").
|
|
5
5
|
//
|
|
6
6
|
// The channel narrowing the derive reads and the render the card paints. The write
|
|
7
7
|
// is `patchEditorExt` (ext.ts), the one door into the namespace.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** How long an offer stands, in ms. Long enough to read the toast and reach its button;
|
|
2
|
+
* short enough that the toast is gone before the user has moved on to something else. */
|
|
3
|
+
export declare const OFFER_MS = 6000;
|
|
4
|
+
export interface UndoOffer {
|
|
5
|
+
/** What the toast says, already worded: `Item 2 removed`. */
|
|
6
|
+
readonly notice: string;
|
|
7
|
+
/** Put back what the removal took. Runs at most once. */
|
|
8
|
+
readonly restore: () => void;
|
|
9
|
+
}
|
|
10
|
+
export interface StructuralUndo {
|
|
11
|
+
/** The offer on show, if any. */
|
|
12
|
+
readonly current: UndoOffer | undefined;
|
|
13
|
+
/** Offer `restore` as the undo of the removal just made, replacing any standing offer. */
|
|
14
|
+
offer(notice: string, restore: () => void): void;
|
|
15
|
+
/** Name the control the removal handed the focus to. ⌘Z there is the offer's until the
|
|
16
|
+
* control takes an edit or the focus leaves it: the key that removed is the key that
|
|
17
|
+
* asks for it back, and the control has nothing of its own to undo yet. */
|
|
18
|
+
hand(el: Element | null): void;
|
|
19
|
+
/** Whether ⌘Z pressed at `target` is the offer's: the page's body, where a removal under
|
|
20
|
+
* the pointer leaves the focus, when this offer is the page's latest; the handed control; or a control under `root` that keeps
|
|
21
|
+
* no history of its own. A text control that is not the handed one keeps its key. */
|
|
22
|
+
accepts(target: EventTarget | null, root: Element | undefined): boolean;
|
|
23
|
+
/** Hold the lapse while the toast is under the pointer or the focus, and let it run again. */
|
|
24
|
+
pause(): void;
|
|
25
|
+
resume(): void;
|
|
26
|
+
/** Run the standing offer and clear it. False when there was none to run. */
|
|
27
|
+
take(): boolean;
|
|
28
|
+
/** Drop the standing offer without running it. */
|
|
29
|
+
withdraw(): void;
|
|
30
|
+
}
|
|
31
|
+
export declare function createStructuralUndo(): StructuralUndo & {
|
|
32
|
+
dispose(): void;
|
|
33
|
+
};
|
|
34
|
+
export declare function setStructuralUndo(undo: StructuralUndo): void;
|
|
35
|
+
/** The editor's undo, or {@link NO_UNDO} off-tree. */
|
|
36
|
+
export declare function structuralUndo(): StructuralUndo;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// The structural undo: one step back for a removal, offered on a toast.
|
|
2
|
+
//
|
|
3
|
+
// A leaf's text has its own history (`core/codec/field.ts`), so a keystroke is undone where
|
|
4
|
+
// it was typed. A removal has no leaf left to hold one: the card or the row it took is gone
|
|
5
|
+
// from the tree, and with it every history that could have restored it. So the surface keeps
|
|
6
|
+
// the step itself, one deep, and offers it where the removal happened.
|
|
7
|
+
//
|
|
8
|
+
// One deep, and only the latest: a second removal replaces the first offer, and any other
|
|
9
|
+
// structural edit withdraws it, because the restore reinserts at the index the removal left
|
|
10
|
+
// and an edit between the two moves what that index names. The offer lapses on its own after
|
|
11
|
+
// a while, so an Undo pressed long after the removal is not a surprise; the while holds as
|
|
12
|
+
// long as the toast is under the pointer or the focus.
|
|
13
|
+
//
|
|
14
|
+
// The key listens on the document while an offer stands, not on the surface: a removal by
|
|
15
|
+
// the pointer takes the pressed button with it and leaves the focus on the page's body,
|
|
16
|
+
// which no keydown on the surface hears.
|
|
17
|
+
import { getContext, setContext } from 'svelte';
|
|
18
|
+
/** How long an offer stands, in ms. Long enough to read the toast and reach its button;
|
|
19
|
+
* short enough that the toast is gone before the user has moved on to something else. */
|
|
20
|
+
export const OFFER_MS = 6000;
|
|
21
|
+
const EDITABLE = 'input, textarea, select, [contenteditable="true"]';
|
|
22
|
+
/** The editor whose offer is the page's latest: the body belongs to no surface, so of two
|
|
23
|
+
* editors with an offer standing, the key at the body is the one that offered last's. */
|
|
24
|
+
let latest;
|
|
25
|
+
export function createStructuralUndo() {
|
|
26
|
+
let current = $state();
|
|
27
|
+
let handed;
|
|
28
|
+
let timer;
|
|
29
|
+
let paused = false;
|
|
30
|
+
const stop = () => {
|
|
31
|
+
if (timer !== undefined)
|
|
32
|
+
clearTimeout(timer);
|
|
33
|
+
timer = undefined;
|
|
34
|
+
};
|
|
35
|
+
const lapse = () => {
|
|
36
|
+
timer = setTimeout(clear, OFFER_MS);
|
|
37
|
+
};
|
|
38
|
+
const clear = () => {
|
|
39
|
+
stop();
|
|
40
|
+
paused = false;
|
|
41
|
+
handed = undefined;
|
|
42
|
+
current = undefined;
|
|
43
|
+
};
|
|
44
|
+
const self = {
|
|
45
|
+
get current() {
|
|
46
|
+
return current;
|
|
47
|
+
},
|
|
48
|
+
offer(notice, restore) {
|
|
49
|
+
clear();
|
|
50
|
+
current = { notice, restore };
|
|
51
|
+
latest = self;
|
|
52
|
+
lapse();
|
|
53
|
+
},
|
|
54
|
+
hand(el) {
|
|
55
|
+
if (!current || !el)
|
|
56
|
+
return;
|
|
57
|
+
handed = el;
|
|
58
|
+
const release = () => {
|
|
59
|
+
if (handed === el)
|
|
60
|
+
handed = undefined;
|
|
61
|
+
el.removeEventListener('input', release);
|
|
62
|
+
el.removeEventListener('focusout', release);
|
|
63
|
+
};
|
|
64
|
+
el.addEventListener('input', release);
|
|
65
|
+
el.addEventListener('focusout', release);
|
|
66
|
+
},
|
|
67
|
+
accepts(target, root) {
|
|
68
|
+
if (!current || !(target instanceof Element))
|
|
69
|
+
return false;
|
|
70
|
+
if (target === document.body)
|
|
71
|
+
return latest === self;
|
|
72
|
+
if (target === handed)
|
|
73
|
+
return true;
|
|
74
|
+
return !!root?.contains(target) && !target.closest(EDITABLE);
|
|
75
|
+
},
|
|
76
|
+
pause() {
|
|
77
|
+
if (!current || paused)
|
|
78
|
+
return;
|
|
79
|
+
paused = true;
|
|
80
|
+
stop();
|
|
81
|
+
},
|
|
82
|
+
resume() {
|
|
83
|
+
if (!current || !paused)
|
|
84
|
+
return;
|
|
85
|
+
paused = false;
|
|
86
|
+
lapse();
|
|
87
|
+
},
|
|
88
|
+
take() {
|
|
89
|
+
const offer = current;
|
|
90
|
+
clear();
|
|
91
|
+
if (!offer)
|
|
92
|
+
return false;
|
|
93
|
+
offer.restore();
|
|
94
|
+
return true;
|
|
95
|
+
},
|
|
96
|
+
withdraw: clear,
|
|
97
|
+
dispose: clear
|
|
98
|
+
};
|
|
99
|
+
return self;
|
|
100
|
+
}
|
|
101
|
+
const KEY = Symbol('qm.undo');
|
|
102
|
+
export function setStructuralUndo(undo) {
|
|
103
|
+
setContext(KEY, undo);
|
|
104
|
+
}
|
|
105
|
+
/** What a component rendered outside the editor gets: no offer, so it removes as it always did. */
|
|
106
|
+
const NO_UNDO = {
|
|
107
|
+
current: undefined,
|
|
108
|
+
offer() { },
|
|
109
|
+
hand() { },
|
|
110
|
+
accepts: () => false,
|
|
111
|
+
pause() { },
|
|
112
|
+
resume() { },
|
|
113
|
+
take: () => false,
|
|
114
|
+
withdraw() { }
|
|
115
|
+
};
|
|
116
|
+
/** The editor's undo, or {@link NO_UNDO} off-tree. */
|
|
117
|
+
export function structuralUndo() {
|
|
118
|
+
return getContext(KEY) ?? NO_UNDO;
|
|
119
|
+
}
|