@quillmark/wasm 0.104.0 → 0.106.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/CHANGELOG.md +244 -27
- package/README.md +72 -206
- package/backends/pdfform/wasm.d.ts +465 -713
- package/backends/pdfform/wasm.js +365 -491
- package/backends/pdfform/wasm_bg.wasm +0 -0
- package/backends/pdfform/wasm_bg.wasm.d.ts +1 -0
- package/backends/typst/wasm.d.ts +465 -713
- package/backends/typst/wasm.js +365 -491
- package/backends/typst/wasm_bg.wasm +0 -0
- package/backends/typst/wasm_bg.wasm.d.ts +1 -0
- package/core/wasm.d.ts +337 -492
- package/core/wasm.js +310 -411
- package/core/wasm_bg.wasm +0 -0
- package/core/wasm_bg.wasm.d.ts +1 -0
- package/package.json +1 -1
- package/runtime/runtime.d.ts +181 -255
- package/runtime/runtime.js +190 -353
package/core/wasm.js
CHANGED
|
@@ -24,16 +24,12 @@ export class Document {
|
|
|
24
24
|
/**
|
|
25
25
|
* Build a composable card of `kind`, typed-commit `fields` onto it, set its
|
|
26
26
|
* body from optional markdown, and place it: the ABI under `writer.addCard`.
|
|
27
|
-
* `at`
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* same per-field diagnostic bundle as [`commitFields`](Self::commit_fields),
|
|
34
|
-
* including an `edit::unknown_field` per undeclared name; an invalid
|
|
35
|
-
* kind or body, or an out-of-range position, throws a single-entry bundle
|
|
36
|
-
* keyed `$kind` / `$body`.
|
|
27
|
+
* `at` absent appends, a number inserts at that index (`0..=cards.length`).
|
|
28
|
+
* Transactional: the card is committed in full before it joins the document,
|
|
29
|
+
* so a rejected field (or an invalid kind, body, or out-of-range `at`)
|
|
30
|
+
* leaves the document untouched. Field errors throw the same per-field
|
|
31
|
+
* bundle as [`commitFields`](Self::commit_fields); an invalid kind or body,
|
|
32
|
+
* or a bad position, throws a single-entry bundle keyed `$kind` / `$body`.
|
|
37
33
|
* @param {Quill} quill
|
|
38
34
|
* @param {string} kind
|
|
39
35
|
* @param {Record<string, unknown>} [fields]
|
|
@@ -60,26 +56,22 @@ export class Document {
|
|
|
60
56
|
}
|
|
61
57
|
/**
|
|
62
58
|
* Typed field write at `addr`, resolving the field's schema `type` from
|
|
63
|
-
* `quill`: the stable ABI under the runtime `writer.set
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* use the encoding the seam already speaks: a content object or markdown
|
|
70
|
-
* string for richtext, a scalar/array/object otherwise.
|
|
59
|
+
* `quill`: the stable ABI under the runtime `writer.set`. One verb for every
|
|
60
|
+
* field type; the schema carries the `inline` constraint, so no type token
|
|
61
|
+
* is passed. A richtext-typed field stores canonical content, so identity
|
|
62
|
+
* marks (anchors, island ids) and content-only marks survive compiles and
|
|
63
|
+
* the storage DTO. Values use the encoding the seam already speaks: content
|
|
64
|
+
* object or markdown string for richtext, scalar/array/object otherwise.
|
|
71
65
|
*
|
|
72
|
-
* A bare string is `Addr` shorthand for `{ field }
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* `edit::
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
* `edit::
|
|
81
|
-
* on a typed mismatch, `edit::invalid_field_name` on a malformed name,
|
|
82
|
-
* and `edit::index_out_of_range` on an out-of-range card.
|
|
66
|
+
* A bare string is `Addr` shorthand for `{ field }`. A body address throws,
|
|
67
|
+
* having no field schema. A declared field is strict-committed, so a
|
|
68
|
+
* mismatch throws now rather than at render, and an undeclared name throws
|
|
69
|
+
* `edit::unknown_field` rather than falling to the opaque store — use
|
|
70
|
+
* [`storeField`](Document::store_field) for that. Also throws
|
|
71
|
+
* `edit::field_coercion_failed` / `edit::field_decode` /
|
|
72
|
+
* `edit::field_not_inline` on a typed mismatch,
|
|
73
|
+
* `edit::invalid_field_name` on a malformed name, and
|
|
74
|
+
* `edit::index_out_of_range` on an out-of-range card.
|
|
83
75
|
*
|
|
84
76
|
* The `quill` handle is passed per call because a `Document` carries only a
|
|
85
77
|
* `$quill` reference, not the resolved schema.
|
|
@@ -103,15 +95,12 @@ export class Document {
|
|
|
103
95
|
}
|
|
104
96
|
/**
|
|
105
97
|
* Batched twin of [`commitField`](Document::commit_field): typed-commit
|
|
106
|
-
* several fields on the card `addr` targets atomically
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
* including an `edit::unknown_field` for any name the schema does not
|
|
113
|
-
* declare, so a whole-form submit sees every typo in one pass. Throws on an
|
|
114
|
-
* out-of-range card.
|
|
98
|
+
* several fields on the card `addr` targets atomically. `addr` is a **card
|
|
99
|
+
* address** (absent = main; a present `field` throws). Same per-field
|
|
100
|
+
* diagnostic contract as [`storeFields`](Document::store_fields) — nothing
|
|
101
|
+
* applied on error, one `diagnostics` entry per offending field, including
|
|
102
|
+
* `edit::unknown_field` for undeclared names. Throws on an out-of-range
|
|
103
|
+
* card.
|
|
115
104
|
* @param {Quill} quill
|
|
116
105
|
* @param {CardAddr} addr
|
|
117
106
|
* @param {Record<string, unknown>} fields
|
|
@@ -132,21 +121,17 @@ export class Document {
|
|
|
132
121
|
}
|
|
133
122
|
/**
|
|
134
123
|
* Interpreted read at `addr`, resolving the field's declared `type` from
|
|
135
|
-
* `quill`: the stable ABI under the runtime `reader.get
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
* meaning rather than by wire shape.
|
|
124
|
+
* `quill`: the stable ABI under the runtime `reader.get`. The schema-plane
|
|
125
|
+
* twin of [`getStored`](Self::get_stored) — a `richtext` field returns its
|
|
126
|
+
* markdown projection, every other declared type its canonical value
|
|
127
|
+
* verbatim.
|
|
140
128
|
*
|
|
141
129
|
* A bare string is `Addr` shorthand for `{ field }`; `{ card, field }`
|
|
142
|
-
* targets a composable card
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
* lacks: there an unknown name reads back `undefined`); a `richtext` field
|
|
148
|
-
* holding a value that does not decode throws `edit::field_decode`;
|
|
149
|
-
* an out-of-range `addr.card` throws.
|
|
130
|
+
* targets a composable card. An **absent** field returns `undefined`, and an
|
|
131
|
+
* absent `addr.field` reads the body markdown. An undeclared name throws
|
|
132
|
+
* `edit::unknown_field` (the authority `bodyMarkdown` lacks), a `richtext`
|
|
133
|
+
* value that does not decode throws `edit::field_decode`, and an
|
|
134
|
+
* out-of-range `addr.card` throws.
|
|
150
135
|
*
|
|
151
136
|
* The `quill` handle is passed per call because a `Document` carries only a
|
|
152
137
|
* `$quill` reference, not the resolved schema.
|
|
@@ -172,25 +157,19 @@ export class Document {
|
|
|
172
157
|
}
|
|
173
158
|
/**
|
|
174
159
|
* Interpreted **`Content`** read at `addr`: the stable ABI under the runtime
|
|
175
|
-
* `reader.getContent
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
160
|
+
* `reader.getContent`. Where [`reader.get`](Self::reader_get) projects, this
|
|
161
|
+
* decodes the stored value through the codec the field's declared type names
|
|
162
|
+
* and returns canonical `Content`. Total over the storage form: a committed
|
|
163
|
+
* field and a parsed one both read back as a `Content`, so a content editor
|
|
164
|
+
* stops branching on how the document was built.
|
|
179
165
|
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
* absent `addr.field` reads the **body** `Content`, quill-free, mirroring
|
|
188
|
-
* [`getStored`](Self::get_stored). Throws `edit::unknown_field` for a name
|
|
189
|
-
* the schema does not declare, `edit::field_not_content` for a declared type
|
|
190
|
-
* that is not a content leaf (`array<richtext>` carries content and still has
|
|
191
|
-
* no one `Content`), `edit::field_decode` for a stored value
|
|
192
|
-
* that decodes under neither encoding, and `edit::index_out_of_range` for a
|
|
193
|
-
* bad `addr.card`.
|
|
166
|
+
* A bare string is `Addr` shorthand for `{ field }`. An **absent** field
|
|
167
|
+
* returns `undefined`, and an absent `addr.field` reads the body `Content`.
|
|
168
|
+
* Throws `edit::unknown_field` for an undeclared name,
|
|
169
|
+
* `edit::field_not_content` for a declared type that is not a content leaf
|
|
170
|
+
* (`array<richtext>` carries content and still has no one `Content`),
|
|
171
|
+
* `edit::field_decode` for a value that decodes under neither encoding, and
|
|
172
|
+
* `edit::index_out_of_range` for a bad `addr.card`.
|
|
194
173
|
* @param {Quill} quill
|
|
195
174
|
* @param {Addr | string} addr
|
|
196
175
|
* @returns {Content | undefined}
|
|
@@ -212,23 +191,59 @@ export class Document {
|
|
|
212
191
|
}
|
|
213
192
|
}
|
|
214
193
|
/**
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
*
|
|
220
|
-
*
|
|
221
|
-
* multi-block result with `edit::field_not_inline`. Returns the
|
|
222
|
-
* text `Delta`.
|
|
194
|
+
* Interpreted **`Content`** read of a value nested inside the composite
|
|
195
|
+
* field at `addr`: the stable ABI under the runtime `reader.getContentAt`,
|
|
196
|
+
* and [`reader.getContent`](Self::reader_get_content) with the path spelled
|
|
197
|
+
* out. `path` is a `PathStep[]` from the field to the leaf — `[0]` an
|
|
198
|
+
* element of an `array<richtext>`, `["motto"]` an `object`'s content
|
|
199
|
+
* property, `[1, "notes"]` a leaf under both.
|
|
223
200
|
*
|
|
224
|
-
* The codec is the declared type's
|
|
225
|
-
* the
|
|
201
|
+
* The codec is the leaf's declared type's, so the caller stops deciding
|
|
202
|
+
* what an element's stored bytes mean. Total over the storage form, as the
|
|
203
|
+
* whole-field read is.
|
|
226
204
|
*
|
|
227
|
-
* `
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
* `
|
|
205
|
+
* `undefined` when the field is absent **and when `path` names nothing in
|
|
206
|
+
* the stored value**: a repeater's row index goes stale between derive and
|
|
207
|
+
* read, and absence there is a read, not a fault. Throws
|
|
208
|
+
* `edit::unknown_field` for an undeclared name at any depth,
|
|
209
|
+
* `edit::field_not_content` when `path` resolves to no content leaf,
|
|
210
|
+
* `edit::field_decode` for a value that decodes under neither encoding
|
|
211
|
+
* (anchored at the addressed path), and `edit::index_out_of_range` for a
|
|
212
|
+
* bad `addr.card`. A body address throws: a body has no nested content
|
|
213
|
+
* address.
|
|
214
|
+
* @param {Quill} quill
|
|
215
|
+
* @param {Addr | string} addr
|
|
216
|
+
* @param {PathStep[]} path
|
|
217
|
+
* @returns {Content | undefined}
|
|
218
|
+
*/
|
|
219
|
+
_readerGetContentAt(quill, addr, path) {
|
|
220
|
+
try {
|
|
221
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
222
|
+
_assertClass(quill, Quill);
|
|
223
|
+
wasm.document__readerGetContentAt(retptr, this.__wbg_ptr, quill.__wbg_ptr, addHeapObject(addr), addHeapObject(path));
|
|
224
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
225
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
226
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
227
|
+
if (r2) {
|
|
228
|
+
throw takeObject(r1);
|
|
229
|
+
}
|
|
230
|
+
return takeObject(r0);
|
|
231
|
+
} finally {
|
|
232
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Revise the content field at `addr` from authored text, typed *and*
|
|
237
|
+
* anchor-preserving: the ABI under `writer.reviseField`. Surviving anchors
|
|
238
|
+
* rebase as in [`revise`](Self::revise), then the diffed result is
|
|
239
|
+
* schema-conformed, so a `richtext(inline)` field rejects a multi-block
|
|
240
|
+
* result with `edit::field_not_inline`. Returns the text `Delta`. The codec
|
|
241
|
+
* is the declared type's: `richtext` diffs markdown, `plaintext` literal
|
|
242
|
+
* text.
|
|
243
|
+
*
|
|
244
|
+
* `addr` must name a field; a body address throws, since a body carries no
|
|
245
|
+
* field schema (use [`revise`](Self::revise)). An undeclared name throws
|
|
246
|
+
* `edit::unknown_field`, an out-of-range card throws.
|
|
232
247
|
* @param {Quill} quill
|
|
233
248
|
* @param {Addr | string} addr
|
|
234
249
|
* @param {string} text
|
|
@@ -253,19 +268,16 @@ export class Document {
|
|
|
253
268
|
}
|
|
254
269
|
}
|
|
255
270
|
/**
|
|
256
|
-
* **Apply** a committed content edit `bundle`
|
|
257
|
-
*
|
|
258
|
-
*
|
|
259
|
-
*
|
|
260
|
-
*
|
|
261
|
-
*
|
|
262
|
-
* The island channel keeps a table or image edit on the op path: it moves
|
|
263
|
-
* the island alone, so the anchors elsewhere in the field survive an edit
|
|
271
|
+
* **Apply** a committed content edit `bundle` at `addr`, the editor splice:
|
|
272
|
+
* text delta first, then island ops, then line ops, then mark ops (mark
|
|
273
|
+
* ranges in final-text coordinates), all-or-nothing. An absent `addr.field`
|
|
274
|
+
* targets the body, an absent `addr.card` the main card. The island channel
|
|
275
|
+
* moves an island alone, so anchors elsewhere in the field survive an edit
|
|
264
276
|
* `overwrite` would clear.
|
|
265
277
|
*
|
|
266
278
|
* Throws on an out-of-range card, a field that is not richtext, a malformed
|
|
267
|
-
* bundle, or an op that applies out of bounds
|
|
268
|
-
* failed apply
|
|
279
|
+
* bundle, or an op that applies out of bounds; the value is unchanged on a
|
|
280
|
+
* failed apply.
|
|
269
281
|
* @param {Addr | string} addr
|
|
270
282
|
* @param {ChangeBundle} bundle
|
|
271
283
|
*/
|
|
@@ -283,10 +295,8 @@ export class Document {
|
|
|
283
295
|
}
|
|
284
296
|
}
|
|
285
297
|
/**
|
|
286
|
-
* Authoring-ergonomics header introducing a blueprint to an LLM/MCP
|
|
287
|
-
*
|
|
288
|
-
* JS consumers; any surface that draws from the same core source stays
|
|
289
|
-
* uniform.
|
|
298
|
+
* Authoring-ergonomics header introducing a blueprint to an LLM/MCP consumer
|
|
299
|
+
* for the given `quillName`, re-exposed from core.
|
|
290
300
|
* @param {string} quill_name
|
|
291
301
|
* @returns {string}
|
|
292
302
|
*/
|
|
@@ -309,15 +319,13 @@ export class Document {
|
|
|
309
319
|
}
|
|
310
320
|
}
|
|
311
321
|
/**
|
|
312
|
-
* The **body** markdown projection
|
|
313
|
-
*
|
|
314
|
-
*
|
|
315
|
-
* this read stays quill-free; a body is never absent.
|
|
322
|
+
* The **body** markdown projection: an on-demand, lossy export (content-only
|
|
323
|
+
* marks do not survive markdown). A body's type is a format fact, not a
|
|
324
|
+
* schema fact, so this read stays quill-free, and a body is never absent.
|
|
316
325
|
*
|
|
317
|
-
* `addr` is an optional
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
* type. An out-of-range `addr.card` throws.
|
|
326
|
+
* `addr` is an optional card address (absent = main). A present `field`
|
|
327
|
+
* throws: read a field's markdown through `quill.reader(doc).get(field)`,
|
|
328
|
+
* which interprets by declared type. An out-of-range `addr.card` throws.
|
|
321
329
|
* @param {CardAddr} [addr]
|
|
322
330
|
* @returns {string}
|
|
323
331
|
*/
|
|
@@ -337,11 +345,9 @@ export class Document {
|
|
|
337
345
|
}
|
|
338
346
|
}
|
|
339
347
|
/**
|
|
340
|
-
* A single composable card by index
|
|
341
|
-
*
|
|
342
|
-
*
|
|
343
|
-
* `index` throws `edit::index_out_of_range`, matching the card write
|
|
344
|
-
* verbs.
|
|
348
|
+
* A single composable card by index, so reading one need not materialize
|
|
349
|
+
* every card via [`cards`](Self::cards). An out-of-range `index` throws
|
|
350
|
+
* `edit::index_out_of_range`.
|
|
345
351
|
* @param {number} index
|
|
346
352
|
* @returns {Card}
|
|
347
353
|
*/
|
|
@@ -361,7 +367,7 @@ export class Document {
|
|
|
361
367
|
}
|
|
362
368
|
}
|
|
363
369
|
/**
|
|
364
|
-
* Number of composable cards
|
|
370
|
+
* Number of composable cards, excluding the main card.
|
|
365
371
|
* @returns {number}
|
|
366
372
|
*/
|
|
367
373
|
get cardCount() {
|
|
@@ -369,10 +375,10 @@ export class Document {
|
|
|
369
375
|
return ret >>> 0;
|
|
370
376
|
}
|
|
371
377
|
/**
|
|
372
|
-
* The composable card's own path, `cards.<kind>[index]`: the
|
|
373
|
-
*
|
|
374
|
-
*
|
|
375
|
-
*
|
|
378
|
+
* The composable card's own path, `cards.<kind>[index]`: the root
|
|
379
|
+
* [`pathFor`](Self::path_for) extends, for anchoring the card rather than
|
|
380
|
+
* one of its fields. Total on the index axis; out of range renders
|
|
381
|
+
* `cards[index]`.
|
|
376
382
|
* @param {number} index
|
|
377
383
|
* @returns {string}
|
|
378
384
|
*/
|
|
@@ -418,9 +424,8 @@ export class Document {
|
|
|
418
424
|
return Document.__wrap(ret);
|
|
419
425
|
}
|
|
420
426
|
/**
|
|
421
|
-
* Storage version this build writes via [`toJson`](Document::to_json).
|
|
422
|
-
*
|
|
423
|
-
* the tag advances only when the wire format changes, not on every release.
|
|
427
|
+
* Storage version this build writes via [`toJson`](Document::to_json). The
|
|
428
|
+
* tag advances only when the wire format changes, not on every release.
|
|
424
429
|
* @returns {string}
|
|
425
430
|
*/
|
|
426
431
|
static currentStorageVersion() {
|
|
@@ -440,8 +445,7 @@ export class Document {
|
|
|
440
445
|
}
|
|
441
446
|
}
|
|
442
447
|
/**
|
|
443
|
-
* Structural equality
|
|
444
|
-
* upstream prop updates instead of re-parsing on every keystroke.
|
|
448
|
+
* Structural equality, excluding parse-time `warnings`.
|
|
445
449
|
* @param {Document} other
|
|
446
450
|
* @returns {boolean}
|
|
447
451
|
*/
|
|
@@ -451,9 +455,8 @@ export class Document {
|
|
|
451
455
|
return ret !== 0;
|
|
452
456
|
}
|
|
453
457
|
/**
|
|
454
|
-
* Render a Diagnostic as the canonical pretty-printed text
|
|
455
|
-
*
|
|
456
|
-
* identical no matter which consumer surfaces it.
|
|
458
|
+
* Render a Diagnostic as the canonical pretty-printed text, so it looks
|
|
459
|
+
* identical whichever consumer surfaces it.
|
|
457
460
|
* @param {Diagnostic} diag
|
|
458
461
|
* @returns {string}
|
|
459
462
|
*/
|
|
@@ -474,11 +477,8 @@ export class Document {
|
|
|
474
477
|
}
|
|
475
478
|
}
|
|
476
479
|
/**
|
|
477
|
-
* Authoring-format rules for the card-yaml markdown surface
|
|
478
|
-
*
|
|
479
|
-
* here for JS consumers so it matches any other surface that draws from the
|
|
480
|
-
* same source. Read once at startup and cache; the value never changes
|
|
481
|
-
* between calls.
|
|
480
|
+
* Authoring-format rules for the card-yaml markdown surface, re-exposed from
|
|
481
|
+
* core. Constant across calls; read once and cache.
|
|
482
482
|
* @returns {string}
|
|
483
483
|
*/
|
|
484
484
|
static formatRules() {
|
|
@@ -498,10 +498,8 @@ export class Document {
|
|
|
498
498
|
}
|
|
499
499
|
}
|
|
500
500
|
/**
|
|
501
|
-
* Reconstruct a `Document` from a versioned storage DTO string produced
|
|
502
|
-
*
|
|
503
|
-
* The result carries no parse-time warnings (`.warnings` is always empty).
|
|
504
|
-
*
|
|
501
|
+
* Reconstruct a `Document` from a versioned storage DTO string produced by
|
|
502
|
+
* [`toJson`](Document::to_json). The result carries no parse-time warnings.
|
|
505
503
|
* Throws if `json` is not a valid storage DTO (malformed JSON, unknown
|
|
506
504
|
* `schema`, missing fields, or unparseable quill reference).
|
|
507
505
|
* @param {string} json
|
|
@@ -548,9 +546,9 @@ export class Document {
|
|
|
548
546
|
}
|
|
549
547
|
/**
|
|
550
548
|
* The whole `$ext` map at `addr` (a card address, absent `card` = main), or
|
|
551
|
-
* `undefined` when the card carries none
|
|
552
|
-
*
|
|
553
|
-
*
|
|
549
|
+
* `undefined` when the card carries none: the `$ext` read that avoids
|
|
550
|
+
* serializing the whole card. Throws on a present `field` or an
|
|
551
|
+
* out-of-range card.
|
|
554
552
|
* @param {CardAddr} [addr]
|
|
555
553
|
* @returns {Record<string, unknown> | undefined}
|
|
556
554
|
*/
|
|
@@ -571,9 +569,8 @@ export class Document {
|
|
|
571
569
|
}
|
|
572
570
|
/**
|
|
573
571
|
* The value stored under `$ext[ns]` at `addr` (a card address, absent `card`
|
|
574
|
-
* = main), or `undefined`.
|
|
575
|
-
*
|
|
576
|
-
* `removeExtNamespace`). Throws on a present `field` or an out-of-range card.
|
|
572
|
+
* = main), or `undefined`. Throws on a present `field` or an out-of-range
|
|
573
|
+
* card.
|
|
577
574
|
* @param {CardAddr} addr
|
|
578
575
|
* @param {string} ns
|
|
579
576
|
* @returns {unknown}
|
|
@@ -596,25 +593,20 @@ export class Document {
|
|
|
596
593
|
}
|
|
597
594
|
}
|
|
598
595
|
/**
|
|
599
|
-
* Read the **verbatim stored value** at `addr`:
|
|
600
|
-
*
|
|
601
|
-
*
|
|
602
|
-
*
|
|
603
|
-
*
|
|
604
|
-
*
|
|
605
|
-
*
|
|
606
|
-
* markdown projection use [`bodyMarkdown`](Self::get_markdown) (body) or
|
|
607
|
-
* `reader.get` (a field's declared type).
|
|
596
|
+
* Read the **verbatim stored value** at `addr`: a field's raw payload value,
|
|
597
|
+
* or the body content when `addr.field` is absent. A bare string is `Addr`
|
|
598
|
+
* shorthand for `{ field }`. Needs no schema: the read echo of the verbatim
|
|
599
|
+
* `store*` write, distinct from the interpreted
|
|
600
|
+
* [`reader.get`](Self::reader_get). Reads are total over the field axis — an
|
|
601
|
+
* absent field is `undefined` — and only an out-of-range `addr.card` throws
|
|
602
|
+
* `edit::index_out_of_range`.
|
|
608
603
|
*
|
|
609
|
-
*
|
|
610
|
-
*
|
|
611
|
-
* string. A document
|
|
612
|
-
*
|
|
613
|
-
*
|
|
614
|
-
*
|
|
615
|
-
* it is conformed, and this read reports what is there. For the `Content`
|
|
616
|
-
* either way, use the schema-plane `reader.getContent`, which decodes
|
|
617
|
-
* through the codec the field's declared type names.
|
|
604
|
+
* A content field at rest has one stored form per codec: a `richtext` field
|
|
605
|
+
* holds the canonical content object, a `plaintext` field its literal
|
|
606
|
+
* string. A document from the bound door (`quill.parse` / `quill.conform`)
|
|
607
|
+
* is at rest; one from the transport door may rest as authored until it is
|
|
608
|
+
* conformed, and this read reports what is there. For the `Content` either
|
|
609
|
+
* way use `reader.getContent`.
|
|
618
610
|
* @param {Addr | string} addr
|
|
619
611
|
* @returns {unknown}
|
|
620
612
|
*/
|
|
@@ -634,12 +626,10 @@ export class Document {
|
|
|
634
626
|
}
|
|
635
627
|
}
|
|
636
628
|
/**
|
|
637
|
-
* Insert a card
|
|
638
|
-
*
|
|
639
|
-
*
|
|
640
|
-
*
|
|
641
|
-
* (every returned `Card` is a valid `CardInput`). Throws if `card.kind` is
|
|
642
|
-
* not a valid kind name, or if `at` is out of range.
|
|
629
|
+
* Insert a card: `at` absent appends, a number inserts at that index (in
|
|
630
|
+
* `0..=cards.length`). Accepts any `CardInput`, including a card read back
|
|
631
|
+
* out of a document. Throws if `card.kind` is not a valid kind name, or if
|
|
632
|
+
* `at` is out of range.
|
|
643
633
|
* @param {CardInput} card
|
|
644
634
|
* @param {number} [at]
|
|
645
635
|
*/
|
|
@@ -658,9 +648,8 @@ export class Document {
|
|
|
658
648
|
}
|
|
659
649
|
/**
|
|
660
650
|
* Whether the field at `addr` is marked `!must_fill`. A bare string is `Addr`
|
|
661
|
-
* shorthand for `{ field }`. `false` for an absent field
|
|
662
|
-
*
|
|
663
|
-
* out-of-range `addr.card` throws.
|
|
651
|
+
* shorthand for `{ field }`. `false` for an absent field and for a body
|
|
652
|
+
* address; only an out-of-range `addr.card` throws.
|
|
664
653
|
* @param {Addr | string} addr
|
|
665
654
|
* @returns {boolean}
|
|
666
655
|
*/
|
|
@@ -680,15 +669,14 @@ export class Document {
|
|
|
680
669
|
}
|
|
681
670
|
}
|
|
682
671
|
/**
|
|
683
|
-
* Replace this document's contents **in place** from a versioned storage
|
|
684
|
-
*
|
|
685
|
-
*
|
|
686
|
-
*
|
|
672
|
+
* Replace this document's contents **in place** from a versioned storage DTO
|
|
673
|
+
* string: the mutating twin of [`fromJson`](Document::from_json). Parse-time
|
|
674
|
+
* `warnings` are cleared. Throws on an invalid DTO, leaving the document
|
|
675
|
+
* unchanged.
|
|
687
676
|
*
|
|
688
677
|
* The cross-WASM-memory `Document` bridge: mutate a document on a
|
|
689
|
-
* backend-memory clone, then write the
|
|
690
|
-
* canonical document
|
|
691
|
-
* the linear-memory seam without the caller re-binding its variable.
|
|
678
|
+
* backend-memory clone, then write the state back into the caller's
|
|
679
|
+
* canonical document, without the caller re-binding its variable.
|
|
692
680
|
* @param {string} json
|
|
693
681
|
*/
|
|
694
682
|
loadJson(json) {
|
|
@@ -707,8 +695,7 @@ export class Document {
|
|
|
707
695
|
}
|
|
708
696
|
}
|
|
709
697
|
/**
|
|
710
|
-
* The document's main (entry) card. Allocates and serializes on each
|
|
711
|
-
* call: cache locally if read in a hot loop.
|
|
698
|
+
* The document's main (entry) card. Allocates and serializes on each call.
|
|
712
699
|
* @returns {Card}
|
|
713
700
|
*/
|
|
714
701
|
get main() {
|
|
@@ -728,17 +715,12 @@ export class Document {
|
|
|
728
715
|
}
|
|
729
716
|
/**
|
|
730
717
|
* Build a fresh `Card` from a kind and a flat field map: the ergonomic
|
|
731
|
-
* constructor for `insertCard
|
|
732
|
-
*
|
|
733
|
-
*
|
|
734
|
-
*
|
|
735
|
-
* Sugar, not a required step: `insertCard` takes any `Card` object, and
|
|
736
|
-
* `removeCard` returns one, so a card round-trips without passing through
|
|
737
|
-
* here.
|
|
718
|
+
* constructor for `insertCard`, which also takes any `Card` object
|
|
719
|
+
* directly. Each `fields` entry becomes a card field in insertion order;
|
|
720
|
+
* `body` defaults to `""`.
|
|
738
721
|
*
|
|
739
|
-
* Checks only what a detached card can decide alone: field-name grammar
|
|
740
|
-
*
|
|
741
|
-
* root, reserved for a composable card) so `insertCard` is its gate, and
|
|
722
|
+
* Checks only what a detached card can decide alone: field-name grammar and
|
|
723
|
+
* value depth. Kind validity is positional, so `insertCard` is its gate and
|
|
742
724
|
* any kind string is accepted here.
|
|
743
725
|
* @param {string} kind
|
|
744
726
|
* @param {Record<string, unknown>} [fields]
|
|
@@ -783,12 +765,11 @@ export class Document {
|
|
|
783
765
|
}
|
|
784
766
|
}
|
|
785
767
|
/**
|
|
786
|
-
*
|
|
787
|
-
*
|
|
788
|
-
* blank
|
|
789
|
-
*
|
|
790
|
-
*
|
|
791
|
-
* Throws on an invalid quill reference. Mirrors Python `Document(quill_ref)`.
|
|
768
|
+
* A blank document: a main card carrying only `$quill`, an empty body, and
|
|
769
|
+
* no composable cards. Absent fields resolve at render time (`default`, else
|
|
770
|
+
* the field's blank), so nothing the caller did not set reaches the output.
|
|
771
|
+
* For an example-filled starter use `Quill.seedDocument()`. Throws on an
|
|
772
|
+
* invalid quill reference.
|
|
792
773
|
* @param {string} quill_ref
|
|
793
774
|
*/
|
|
794
775
|
constructor(quill_ref) {
|
|
@@ -811,15 +792,11 @@ export class Document {
|
|
|
811
792
|
}
|
|
812
793
|
}
|
|
813
794
|
/**
|
|
814
|
-
* **Overwrite** the content value at `addr`:
|
|
815
|
-
*
|
|
816
|
-
*
|
|
817
|
-
*
|
|
818
|
-
*
|
|
819
|
-
* [`applyChange`](Document::apply_change) preserves. An absent `addr.field`
|
|
820
|
-
* targets the body, an absent `addr.card` the main card. Cold-importing
|
|
821
|
-
* markdown is spelled `overwrite(addr, importMarkdown(md))` at the call
|
|
822
|
-
* site, where the anchor loss is visible.
|
|
795
|
+
* **Overwrite** the content value at `addr` with exactly `rt`: value
|
|
796
|
+
* semantics, so the identity anchors of any previous value are gone. By
|
|
797
|
+
* anchor fate `overwrite` destroys, [`revise`](Document::revise) rebases,
|
|
798
|
+
* and [`applyChange`](Document::apply_change) preserves. An absent
|
|
799
|
+
* `addr.field` targets the body, an absent `addr.card` the main card.
|
|
823
800
|
*
|
|
824
801
|
* Throws on an out-of-range card, a malformed field name, or an `rt` that is
|
|
825
802
|
* not a canonical content object.
|
|
@@ -840,26 +817,19 @@ export class Document {
|
|
|
840
817
|
}
|
|
841
818
|
}
|
|
842
819
|
/**
|
|
843
|
-
* `addr`'s canonical `DocPath` string, the anchor `Diagnostic.path`
|
|
844
|
-
*
|
|
845
|
-
* `pathFor({card: 2})` `cards.<kind>[2].body`.
|
|
846
|
-
* `Addr` mints one without restating the kind lookup, the `Addr` defaults
|
|
847
|
-
* or the range guard.
|
|
820
|
+
* `addr`'s canonical `DocPath` string, the anchor `Diagnostic.path` carries:
|
|
821
|
+
* `pathFor()` is `main.body`, `pathFor("intro")` `main.intro`,
|
|
822
|
+
* `pathFor({card: 2})` `cards.<kind>[2].body`.
|
|
848
823
|
*
|
|
849
|
-
* The kind is the card's stored `$kind` verbatim,
|
|
850
|
-
*
|
|
851
|
-
*
|
|
852
|
-
*
|
|
853
|
-
* `validate` diagnostic path differ for the same card.
|
|
824
|
+
* The kind is the card's stored `$kind` verbatim, not `validate`'s
|
|
825
|
+
* declared-kind filter, since a `Document` holds a `$quill` reference and no
|
|
826
|
+
* schema. That is the one edge where this path and a `validate` diagnostic
|
|
827
|
+
* path differ for the same card.
|
|
854
828
|
*
|
|
855
|
-
* **Total on the index axis**, unlike the `Addr` reads
|
|
856
|
-
* `
|
|
857
|
-
*
|
|
858
|
-
*
|
|
859
|
-
* `cards[7].from`, which parses back and resolves to nothing rather than
|
|
860
|
-
* mis-targeting. So a per-keystroke call needs no `try`; a caller wanting
|
|
861
|
-
* a drop-it guard has [`cardCount`](Self::card_count). Only a malformed
|
|
862
|
-
* address throws.
|
|
829
|
+
* **Total on the index axis**, unlike the `Addr` reads, which throw there:
|
|
830
|
+
* an out-of-range `{card: 7, field: "from"}` renders `cards[7].from`, which
|
|
831
|
+
* parses back and resolves to nothing rather than mis-targeting. Only a
|
|
832
|
+
* malformed address throws.
|
|
863
833
|
* @param {Addr | string} addr
|
|
864
834
|
* @returns {string}
|
|
865
835
|
*/
|
|
@@ -907,11 +877,9 @@ export class Document {
|
|
|
907
877
|
}
|
|
908
878
|
}
|
|
909
879
|
/**
|
|
910
|
-
* The canonical `$quill` reference grammar as author-facing text
|
|
911
|
-
* the
|
|
912
|
-
* messages from this instead of re-stating the rule
|
|
913
|
-
* `hint` on `parse::invalid_quill_reference`. Cache it; the value never
|
|
914
|
-
* changes.
|
|
880
|
+
* The canonical `$quill` reference grammar as author-facing text: the same
|
|
881
|
+
* text the `parse::invalid_quill_reference` hint carries. Drive validation
|
|
882
|
+
* messages from this instead of re-stating the rule.
|
|
915
883
|
* @returns {string}
|
|
916
884
|
*/
|
|
917
885
|
static quillRefHint() {
|
|
@@ -950,10 +918,9 @@ export class Document {
|
|
|
950
918
|
}
|
|
951
919
|
}
|
|
952
920
|
/**
|
|
953
|
-
* Remove the `$ext` map on the card `addr` targets
|
|
954
|
-
* previous map or `undefined
|
|
955
|
-
*
|
|
956
|
-
* (absent = main). Throws on a present `field` or an out-of-range card.
|
|
921
|
+
* Remove the `$ext` map on the card `addr` targets entirely, returning the
|
|
922
|
+
* previous map or `undefined`. Discards every namespace at once; prefer
|
|
923
|
+
* `removeExtNamespace`. Throws on a present `field` or an out-of-range card.
|
|
957
924
|
* @param {CardAddr} [addr]
|
|
958
925
|
* @returns {Record<string, unknown> | undefined}
|
|
959
926
|
*/
|
|
@@ -1000,9 +967,8 @@ export class Document {
|
|
|
1000
967
|
}
|
|
1001
968
|
/**
|
|
1002
969
|
* Remove a field at `addr`, returning the removed value or `undefined`. A
|
|
1003
|
-
* bare string is `Addr` shorthand for `{ field }`.
|
|
1004
|
-
*
|
|
1005
|
-
* a malformed name.
|
|
970
|
+
* bare string is `Addr` shorthand for `{ field }`. A body address throws, as
|
|
971
|
+
* does an out-of-range card or a malformed name.
|
|
1006
972
|
* @param {Addr | string} addr
|
|
1007
973
|
* @returns {any}
|
|
1008
974
|
*/
|
|
@@ -1022,9 +988,8 @@ export class Document {
|
|
|
1022
988
|
}
|
|
1023
989
|
}
|
|
1024
990
|
/**
|
|
1025
|
-
* Remove `cardKind` from the main card's `$seed` map, returning its
|
|
1026
|
-
*
|
|
1027
|
-
* survive. `$seed` is main-only, so this takes no address.
|
|
991
|
+
* Remove `cardKind` from the main card's `$seed` map, returning its overlay
|
|
992
|
+
* or `undefined`; drops `$seed` entirely once empty. Sibling kinds survive.
|
|
1028
993
|
* @param {string} card_kind
|
|
1029
994
|
* @returns {any}
|
|
1030
995
|
*/
|
|
@@ -1046,12 +1011,12 @@ export class Document {
|
|
|
1046
1011
|
}
|
|
1047
1012
|
}
|
|
1048
1013
|
/**
|
|
1049
|
-
* **Revise** the richtext value at `addr` from a markdown string:
|
|
1050
|
-
*
|
|
1051
|
-
*
|
|
1052
|
-
*
|
|
1053
|
-
*
|
|
1054
|
-
* absent
|
|
1014
|
+
* **Revise** the richtext value at `addr` from a markdown string: the
|
|
1015
|
+
* default write path. Imports the markdown, diffs it against the current
|
|
1016
|
+
* value, rebases surviving identity anchors, and returns the text `Delta` an
|
|
1017
|
+
* editor bridge maps its own positions through (`mapPos`). An absent
|
|
1018
|
+
* `addr.field` targets the body, an absent `addr.card` the main card; an
|
|
1019
|
+
* absent field cold-imports from empty.
|
|
1055
1020
|
*
|
|
1056
1021
|
* Throws on an out-of-range card, a malformed field name, a present
|
|
1057
1022
|
* non-content field value, or an over-nested markdown input.
|
|
@@ -1077,11 +1042,9 @@ export class Document {
|
|
|
1077
1042
|
}
|
|
1078
1043
|
}
|
|
1079
1044
|
/**
|
|
1080
|
-
* The main card's `$seed` overlay object
|
|
1081
|
-
*
|
|
1082
|
-
* `
|
|
1083
|
-
* via [`main`](Self::main) to fish out one key, and it keeps `seedCard`
|
|
1084
|
-
* pure: the quill still never reads the document.
|
|
1045
|
+
* The main card's `$seed[kind]` overlay object, or `undefined`. Feeds
|
|
1046
|
+
* `quill.seedCard(kind, overlay)` without serializing the whole main card,
|
|
1047
|
+
* and keeps `seedCard` pure: the quill never reads the document.
|
|
1085
1048
|
* @param {string} kind
|
|
1086
1049
|
* @returns {Record<string, unknown> | undefined}
|
|
1087
1050
|
*/
|
|
@@ -1144,15 +1107,11 @@ export class Document {
|
|
|
1144
1107
|
}
|
|
1145
1108
|
}
|
|
1146
1109
|
/**
|
|
1147
|
-
* Read the storage version tag from a raw storage DTO string without a
|
|
1148
|
-
*
|
|
1149
|
-
*
|
|
1150
|
-
*
|
|
1151
|
-
*
|
|
1152
|
-
* The storage version, not a field schema ([`schema`](Quill::schema) is the
|
|
1153
|
-
* quill's field declarations). The JSON key is spelled `"schema"`: it is
|
|
1154
|
-
* the DTO's serde tag, and retagging it would break the version dispatch
|
|
1155
|
-
* it drives.
|
|
1110
|
+
* Read the storage version tag from a raw storage DTO string without a full
|
|
1111
|
+
* parse, or `undefined`. Unknown future versions come back as-is, which
|
|
1112
|
+
* distinguishes "build too old" from "payload corrupt" when `fromJson`
|
|
1113
|
+
* throws. This is the storage version, not a field schema, though the JSON
|
|
1114
|
+
* key is spelled `"schema"`: that is the DTO's serde tag.
|
|
1156
1115
|
* @param {string} json
|
|
1157
1116
|
* @returns {string | undefined}
|
|
1158
1117
|
*/
|
|
@@ -1175,11 +1134,10 @@ export class Document {
|
|
|
1175
1134
|
}
|
|
1176
1135
|
}
|
|
1177
1136
|
/**
|
|
1178
|
-
* Replace the opaque `$ext` map on the card `addr` targets (
|
|
1179
|
-
*
|
|
1180
|
-
*
|
|
1181
|
-
*
|
|
1182
|
-
* `store` verb. Throws on a present `field` or an out-of-range card.
|
|
1137
|
+
* Replace the opaque `$ext` map on the card `addr` targets (absent `card` =
|
|
1138
|
+
* main). `value` must be a plain object. `$ext` carries out-of-band consumer
|
|
1139
|
+
* state and never reaches the rendered output. Throws on a present `field`
|
|
1140
|
+
* or an out-of-range card.
|
|
1183
1141
|
* @param {CardAddr} addr
|
|
1184
1142
|
* @param {any} value
|
|
1185
1143
|
*/
|
|
@@ -1198,9 +1156,8 @@ export class Document {
|
|
|
1198
1156
|
}
|
|
1199
1157
|
/**
|
|
1200
1158
|
* Merge `value` into `$ext[ns]` on the card `addr` targets, preserving
|
|
1201
|
-
* sibling namespaces: the recommended `$ext` write.
|
|
1202
|
-
*
|
|
1203
|
-
* Throws on a present `field` or an out-of-range card.
|
|
1159
|
+
* sibling namespaces: the recommended `$ext` write. Throws on a present
|
|
1160
|
+
* `field` or an out-of-range card.
|
|
1204
1161
|
* @param {CardAddr} addr
|
|
1205
1162
|
* @param {string} ns
|
|
1206
1163
|
* @param {any} value
|
|
@@ -1221,14 +1178,12 @@ export class Document {
|
|
|
1221
1178
|
}
|
|
1222
1179
|
}
|
|
1223
1180
|
/**
|
|
1224
|
-
* Store a field verbatim at `addr
|
|
1225
|
-
*
|
|
1226
|
-
*
|
|
1227
|
-
*
|
|
1228
|
-
*
|
|
1229
|
-
*
|
|
1230
|
-
* opaque; write it with `revise` / `overwrite` / `writer.reviseBody`. Throws on
|
|
1231
|
-
* an out-of-range card or a malformed name.
|
|
1181
|
+
* Store a field verbatim at `addr`, deferring coercion to render; the typed
|
|
1182
|
+
* write is [`commitField`](Document::commit_field). A bare string is `Addr`
|
|
1183
|
+
* shorthand for `{ field }`; `{ card: 2, field: "qty" }` targets a
|
|
1184
|
+
* composable card. Clears any `!must_fill` marker. A body address throws:
|
|
1185
|
+
* write a body with `revise` / `overwrite`. Throws on an out-of-range card
|
|
1186
|
+
* or a malformed name.
|
|
1232
1187
|
* @param {Addr | string} addr
|
|
1233
1188
|
* @param {any} value
|
|
1234
1189
|
*/
|
|
@@ -1246,14 +1201,11 @@ export class Document {
|
|
|
1246
1201
|
}
|
|
1247
1202
|
}
|
|
1248
1203
|
/**
|
|
1249
|
-
* Store several fields verbatim and atomically on the card `addr` targets
|
|
1250
|
-
*
|
|
1251
|
-
*
|
|
1252
|
-
*
|
|
1253
|
-
*
|
|
1254
|
-
* fields)` a composable one, never ambiguous with "set field `card`".
|
|
1255
|
-
* Nothing is applied on error; the thrown error's `diagnostics` carry one
|
|
1256
|
-
* entry per offending field. Throws on an out-of-range card.
|
|
1204
|
+
* Store several fields verbatim and atomically on the card `addr` targets.
|
|
1205
|
+
* `addr` is a **card address** (`{ card }`, absent = main) and comes first
|
|
1206
|
+
* because `card` is itself a legal field name; a present `field` throws.
|
|
1207
|
+
* Nothing is applied on error, and the thrown error's `diagnostics` carry
|
|
1208
|
+
* one entry per offending field. Throws on an out-of-range card.
|
|
1257
1209
|
* @param {CardAddr} addr
|
|
1258
1210
|
* @param {Record<string, unknown>} fields
|
|
1259
1211
|
*/
|
|
@@ -1271,10 +1223,8 @@ export class Document {
|
|
|
1271
1223
|
}
|
|
1272
1224
|
}
|
|
1273
1225
|
/**
|
|
1274
|
-
* Store a field verbatim at `addr` and mark it `!must_fill
|
|
1275
|
-
*
|
|
1276
|
-
* `{ card, field }` for a composable card). A body address throws. Same
|
|
1277
|
-
* validation as [`storeField`](Document::store_field).
|
|
1226
|
+
* Store a field verbatim at `addr` and mark it `!must_fill`. A body address
|
|
1227
|
+
* throws; same validation as [`storeField`](Document::store_field).
|
|
1278
1228
|
* @param {Addr | string} addr
|
|
1279
1229
|
* @param {any} value
|
|
1280
1230
|
*/
|
|
@@ -1293,10 +1243,9 @@ export class Document {
|
|
|
1293
1243
|
}
|
|
1294
1244
|
/**
|
|
1295
1245
|
* Merge a card-kind's seed `overlay` into the **main** card's `$seed` map
|
|
1296
|
-
* under `cardKind`, preserving sibling kinds
|
|
1297
|
-
*
|
|
1298
|
-
*
|
|
1299
|
-
* verb. Throws if `overlay` cannot be serialized or nests too deep.
|
|
1246
|
+
* under `cardKind`, preserving sibling kinds; `$seed` is main-only, so this
|
|
1247
|
+
* takes no address. Sets the starting values new cards of that kind spawn
|
|
1248
|
+
* with. Throws if `overlay` cannot be serialized or nests too deep.
|
|
1300
1249
|
* @param {string} card_kind
|
|
1301
1250
|
* @param {any} overlay
|
|
1302
1251
|
*/
|
|
@@ -1316,14 +1265,10 @@ export class Document {
|
|
|
1316
1265
|
}
|
|
1317
1266
|
}
|
|
1318
1267
|
/**
|
|
1319
|
-
* Serialize this document to a versioned storage DTO string.
|
|
1320
|
-
*
|
|
1321
|
-
*
|
|
1322
|
-
*
|
|
1323
|
-
* `warnings` are excluded from the DTO.
|
|
1324
|
-
*
|
|
1325
|
-
* Output is **byte-deterministic** within a `schema` version: equal
|
|
1326
|
-
* documents produce byte-equal output, safe for content-hash use cases.
|
|
1268
|
+
* Serialize this document to a versioned storage DTO string. Prefer it over
|
|
1269
|
+
* `toMarkdown` for persistence: the wire format is frozen per `schema`
|
|
1270
|
+
* version and the output is byte-deterministic within one, so equal
|
|
1271
|
+
* documents hash equal. Parse-time `warnings` are excluded.
|
|
1327
1272
|
* @returns {string}
|
|
1328
1273
|
*/
|
|
1329
1274
|
toJson() {
|
|
@@ -1364,11 +1309,9 @@ export class Document {
|
|
|
1364
1309
|
}
|
|
1365
1310
|
}
|
|
1366
1311
|
/**
|
|
1367
|
-
* Like [`fromJson`](Document::from_json) but returns `undefined` instead
|
|
1368
|
-
*
|
|
1369
|
-
*
|
|
1370
|
-
* `undefined` means "not a storage DTO"; `fromMarkdown` still throws on
|
|
1371
|
-
* genuinely malformed markdown.
|
|
1312
|
+
* Like [`fromJson`](Document::from_json) but returns `undefined` instead of
|
|
1313
|
+
* throwing when `json` is not a valid storage DTO, to discriminate format
|
|
1314
|
+
* without exceptions as control flow.
|
|
1372
1315
|
* @param {string} json
|
|
1373
1316
|
* @returns {Document | undefined}
|
|
1374
1317
|
*/
|
|
@@ -1380,9 +1323,9 @@ export class Document {
|
|
|
1380
1323
|
}
|
|
1381
1324
|
/**
|
|
1382
1325
|
* The non-fatal diagnostics of the load that produced this document: parse
|
|
1383
|
-
* warnings, plus
|
|
1384
|
-
*
|
|
1385
|
-
*
|
|
1326
|
+
* warnings, plus `conform::*` warnings when it came through `quill.parse`.
|
|
1327
|
+
* Session state, not document value: `equals` and the storage DTO exclude
|
|
1328
|
+
* it, and `fromJson` / `loadJson` clear it.
|
|
1386
1329
|
* @returns {Diagnostic[]}
|
|
1387
1330
|
*/
|
|
1388
1331
|
get warnings() {
|
|
@@ -1422,9 +1365,8 @@ export class Quill {
|
|
|
1422
1365
|
wasm.__wbg_quill_free(ptr, 0);
|
|
1423
1366
|
}
|
|
1424
1367
|
/**
|
|
1425
|
-
* The *declared* backend identifier (
|
|
1426
|
-
*
|
|
1427
|
-
* `supportsCanvas`) is read from the engine.
|
|
1368
|
+
* The *declared* backend identifier (e.g. `"typst"`): intent, not a
|
|
1369
|
+
* resolved capability. Capability is read from the engine.
|
|
1428
1370
|
* @returns {string}
|
|
1429
1371
|
*/
|
|
1430
1372
|
get backendId() {
|
|
@@ -1464,19 +1406,15 @@ export class Quill {
|
|
|
1464
1406
|
}
|
|
1465
1407
|
/**
|
|
1466
1408
|
* Land `doc`'s declared content fields at their canonical rest **in
|
|
1467
|
-
* place**, returning the `conform::*` diagnostics for
|
|
1468
|
-
*
|
|
1469
|
-
*
|
|
1470
|
-
* The read-repair verb: a document that arrived through the transport door
|
|
1471
|
-
* (`fromMarkdown`, `fromJson`, a stored row) converges here, and is then
|
|
1472
|
-
* eligible for rewrite under its current schema tag. Idempotent, and a
|
|
1473
|
-
* no-op on an already-canonical document: an equal value is not rewritten,
|
|
1474
|
-
* so YAML comments and stored bytes survive.
|
|
1409
|
+
* place**, returning the `conform::*` diagnostics for values that would not
|
|
1410
|
+
* commit. The read-repair verb for a document that arrived through the
|
|
1411
|
+
* transport door (`fromMarkdown`, `fromJson`, a stored row).
|
|
1475
1412
|
*
|
|
1476
|
-
*
|
|
1477
|
-
*
|
|
1478
|
-
*
|
|
1479
|
-
* `$quill`, before any
|
|
1413
|
+
* Idempotent: an equal value is not rewritten, so YAML comments and stored
|
|
1414
|
+
* bytes survive. A `!must_fill` marker anywhere in a field's value skips
|
|
1415
|
+
* that field, and a value the strict write refuses stays as authored with a
|
|
1416
|
+
* diagnostic. Throws when `doc` declares a different `$quill`, before any
|
|
1417
|
+
* mutation.
|
|
1480
1418
|
* @param {Document} doc
|
|
1481
1419
|
* @returns {Diagnostic[]}
|
|
1482
1420
|
*/
|
|
@@ -1497,13 +1435,9 @@ export class Quill {
|
|
|
1497
1435
|
}
|
|
1498
1436
|
}
|
|
1499
1437
|
/**
|
|
1500
|
-
* Build a quill from a file tree. Pure:
|
|
1501
|
-
*
|
|
1502
|
-
*
|
|
1503
|
-
* Accepts either a `Map<string, Uint8Array>` or a plain object
|
|
1504
|
-
* (`Record<string, Uint8Array>`). Plain objects are walked via
|
|
1505
|
-
* `Object.entries` at the boundary; the Rust side sees a single
|
|
1506
|
-
* canonical shape.
|
|
1438
|
+
* Build a quill from a file tree. Pure: the declared backend is resolved
|
|
1439
|
+
* later, at render time. Accepts a `Map<string, Uint8Array>` or a plain
|
|
1440
|
+
* object.
|
|
1507
1441
|
* @param {Map<string, Uint8Array>} tree
|
|
1508
1442
|
* @returns {Quill}
|
|
1509
1443
|
*/
|
|
@@ -1524,9 +1458,8 @@ export class Quill {
|
|
|
1524
1458
|
}
|
|
1525
1459
|
/**
|
|
1526
1460
|
* Identity snapshot of the `quill:` section of `Quill.yaml` plus any extra
|
|
1527
|
-
* `quill:` keys. Pure config:
|
|
1528
|
-
*
|
|
1529
|
-
* (`Quillmark.supportedFormats`), not part of this snapshot.
|
|
1461
|
+
* `quill:` keys. Pure config: output formats are a resolved-backend
|
|
1462
|
+
* capability read from `Quillmark.supportedFormats`, not part of this.
|
|
1530
1463
|
* @returns {QuillMetadata}
|
|
1531
1464
|
*/
|
|
1532
1465
|
get metadata() {
|
|
@@ -1545,18 +1478,16 @@ export class Quill {
|
|
|
1545
1478
|
}
|
|
1546
1479
|
}
|
|
1547
1480
|
/**
|
|
1548
|
-
* Parse `markdown` and conform it against this quill: the
|
|
1549
|
-
*
|
|
1550
|
-
*
|
|
1551
|
-
*
|
|
1552
|
-
*
|
|
1553
|
-
* field's declared codec rather than by how the document was built.
|
|
1481
|
+
* Parse `markdown` and conform it against this quill: the primary ingestion
|
|
1482
|
+
* path, and the bound twin of the schema-free `Document.fromMarkdown`. The
|
|
1483
|
+
* returned document rests at its canonical form (a `richtext` field as a
|
|
1484
|
+
* content object, a `plaintext` field as its literal string), so `getStored`
|
|
1485
|
+
* answers by the field's declared codec, not by how the document was built.
|
|
1554
1486
|
*
|
|
1555
1487
|
* Parse warnings and the `conform::*` diagnostics both land on
|
|
1556
1488
|
* `doc.warnings`. Throws on a parse failure, or when `markdown` declares a
|
|
1557
|
-
* `$quill` this quill does not answer to
|
|
1558
|
-
*
|
|
1559
|
-
* door (`Document.fromMarkdown`, `setQuillRef`, then `quill.conform`).
|
|
1489
|
+
* `$quill` this quill does not answer to. To open a document whose `$quill`
|
|
1490
|
+
* is stale, use `Document.fromMarkdown`, `setQuillRef`, then `quill.conform`.
|
|
1560
1491
|
* @param {string} markdown
|
|
1561
1492
|
* @returns {Document}
|
|
1562
1493
|
*/
|
|
@@ -1578,15 +1509,11 @@ export class Quill {
|
|
|
1578
1509
|
}
|
|
1579
1510
|
}
|
|
1580
1511
|
/**
|
|
1581
|
-
* The resolved-value view of `doc
|
|
1582
|
-
*
|
|
1583
|
-
*
|
|
1584
|
-
*
|
|
1585
|
-
*
|
|
1586
|
-
*
|
|
1587
|
-
* Value and provenance only: completeness and errors stay `validate`'s
|
|
1588
|
-
* (a consumer merges it with its own diagnostic producers regardless), and
|
|
1589
|
-
* schema guidance reads from `Quill.schema`.
|
|
1512
|
+
* The resolved-value view of `doc`: for every declared field, the value the
|
|
1513
|
+
* render projection would use and the `FieldSource` rung it came from
|
|
1514
|
+
* (`"authored" | "default" | "blank"`). The card body is a `body` sibling on
|
|
1515
|
+
* its card, never a row in `fields`, and `null` when the kind enables no
|
|
1516
|
+
* body. Value and provenance only; completeness stays `validate`'s.
|
|
1590
1517
|
* @param {Document} doc
|
|
1591
1518
|
* @returns {Resolved}
|
|
1592
1519
|
*/
|
|
@@ -1607,11 +1534,9 @@ export class Quill {
|
|
|
1607
1534
|
}
|
|
1608
1535
|
}
|
|
1609
1536
|
/**
|
|
1610
|
-
* Document schema for the quill: the user-fillable fields plus their
|
|
1611
|
-
*
|
|
1612
|
-
*
|
|
1613
|
-
* alike. Key order in `fields`/`properties` is declaration order: the
|
|
1614
|
-
* ordering contract. Returns the `QuillSchema` shape.
|
|
1537
|
+
* Document schema for the quill: the user-fillable fields plus their `ui`
|
|
1538
|
+
* hints. Key order in `fields`/`properties` is declaration order, the
|
|
1539
|
+
* ordering contract.
|
|
1615
1540
|
* @returns {QuillSchema}
|
|
1616
1541
|
*/
|
|
1617
1542
|
get schema() {
|
|
@@ -1631,15 +1556,13 @@ export class Quill {
|
|
|
1631
1556
|
}
|
|
1632
1557
|
/**
|
|
1633
1558
|
* Seed a starter composable `Card` of the given kind (carries `$kind`),
|
|
1634
|
-
* layering an optional per-kind seed `overlay` over the schema-example
|
|
1635
|
-
*
|
|
1636
|
-
*
|
|
1637
|
-
* straight into `Document.insertCard`.
|
|
1559
|
+
* layering an optional per-kind seed `overlay` over the schema-example base
|
|
1560
|
+
* (`overlay › example › absent`). `undefined` when `cardKind` is not
|
|
1561
|
+
* declared in this quill's schema.
|
|
1638
1562
|
*
|
|
1639
1563
|
* Pass `document.seedOverlay(cardKind)` as `overlay` so a card added to a
|
|
1640
1564
|
* template-derived document inherits its curated starting values; omit it
|
|
1641
|
-
*
|
|
1642
|
-
* plain object: this reads the document, it does not mutate it.
|
|
1565
|
+
* for the bare schema seed.
|
|
1643
1566
|
* @param {string} card_kind
|
|
1644
1567
|
* @param {Record<string, unknown> | undefined} overlay
|
|
1645
1568
|
* @returns {Card | undefined}
|
|
@@ -1662,12 +1585,10 @@ export class Quill {
|
|
|
1662
1585
|
}
|
|
1663
1586
|
}
|
|
1664
1587
|
/**
|
|
1665
|
-
* Seed a starter `Document` from the schema
|
|
1666
|
-
*
|
|
1667
|
-
*
|
|
1668
|
-
*
|
|
1669
|
-
* with both an `example` and a `default` renders its example. See
|
|
1670
|
-
* `prose/canon/SCHEMAS.md` § "Document seeding".
|
|
1588
|
+
* Seed a starter `Document` from the schema: the main card plus one instance
|
|
1589
|
+
* of each composable card kind, each committing its fields' `example:`
|
|
1590
|
+
* values and leaving every other field absent (interpolated at render as
|
|
1591
|
+
* `default:`, else the field's blank). A field with both renders its example.
|
|
1671
1592
|
* @returns {Document}
|
|
1672
1593
|
*/
|
|
1673
1594
|
seedDocument() {
|
|
@@ -1676,9 +1597,7 @@ export class Quill {
|
|
|
1676
1597
|
}
|
|
1677
1598
|
/**
|
|
1678
1599
|
* Seed a starter main `Card` (carries `$quill`) from the schema: the
|
|
1679
|
-
* `$kind: main` card of [`seedDocument`](Self::seed_document)
|
|
1680
|
-
* isolation, committing each field's `example:` value. Returns the same
|
|
1681
|
-
* `Card` shape as the `Document.main` getter.
|
|
1600
|
+
* `$kind: main` card of [`seedDocument`](Self::seed_document) alone.
|
|
1682
1601
|
* @returns {Card}
|
|
1683
1602
|
*/
|
|
1684
1603
|
seedMain() {
|
|
@@ -1697,16 +1616,13 @@ export class Quill {
|
|
|
1697
1616
|
}
|
|
1698
1617
|
}
|
|
1699
1618
|
/**
|
|
1700
|
-
* Flatten this quill back into its canonical file tree
|
|
1701
|
-
* [`fromTree`](Self::from_tree).
|
|
1702
|
-
* reproduces an equivalent quill.
|
|
1619
|
+
* Flatten this quill back into its canonical file tree, the inverse of
|
|
1620
|
+
* [`fromTree`](Self::from_tree). Keys are `"/"`-joined relative paths.
|
|
1703
1621
|
*
|
|
1704
1622
|
* This is how a quill crosses a WASM linear-memory boundary as data: a
|
|
1705
|
-
* `Quill` built in one build
|
|
1706
|
-
* cannot be passed to an engine in another (separate linear memories), so
|
|
1623
|
+
* `Quill` built in one build cannot be passed to an engine in another, so
|
|
1707
1624
|
* `@quillmark/wasm/runtime` re-feeds this tree to the backend build's
|
|
1708
|
-
* `Quill.fromTree` on demand.
|
|
1709
|
-
* matching what `fromTree` accepts.
|
|
1625
|
+
* `Quill.fromTree` on demand.
|
|
1710
1626
|
* @returns {Map<string, Uint8Array>}
|
|
1711
1627
|
*/
|
|
1712
1628
|
toTree() {
|
|
@@ -1715,14 +1631,9 @@ export class Quill {
|
|
|
1715
1631
|
}
|
|
1716
1632
|
/**
|
|
1717
1633
|
* Validate `doc` against this quill's schema, returning every diagnostic
|
|
1718
|
-
* (
|
|
1719
|
-
*
|
|
1720
|
-
*
|
|
1721
|
-
* `path`, and `hint` the engine emits) including the non-fatal
|
|
1722
|
-
* `validation::must_fill` warning for each `!must_fill` marker left in
|
|
1723
|
-
* the document. Field values, defaults, and order are not part of this
|
|
1724
|
-
* surface: read them from the `Document` payload and `Quill.schema`
|
|
1725
|
-
* (schema key order is display order).
|
|
1634
|
+
* (empty when the document is valid). Forwards the canonical
|
|
1635
|
+
* `validation::*` diagnostics the engine emits, including the non-fatal
|
|
1636
|
+
* `validation::must_fill` warning per `!must_fill` marker left behind.
|
|
1726
1637
|
* @param {Document} doc
|
|
1727
1638
|
* @returns {Diagnostic[]}
|
|
1728
1639
|
*/
|
|
@@ -1746,8 +1657,7 @@ export class Quill {
|
|
|
1746
1657
|
if (Symbol.dispose) Quill.prototype[Symbol.dispose] = Quill.prototype.free;
|
|
1747
1658
|
|
|
1748
1659
|
/**
|
|
1749
|
-
* Export
|
|
1750
|
-
* on-demand codec behind `exportMarkdown(card.body)`. Throws if `rt` is not a
|
|
1660
|
+
* Export canonical `Content` to its markdown projection. Throws if `rt` is not
|
|
1751
1661
|
* canonical content.
|
|
1752
1662
|
* @param {Content} rt
|
|
1753
1663
|
* @returns {string}
|
|
@@ -1779,10 +1689,8 @@ export function exportMarkdown(rt) {
|
|
|
1779
1689
|
|
|
1780
1690
|
/**
|
|
1781
1691
|
* Serialize structured [`DocPathSeg`] segments back to the canonical path
|
|
1782
|
-
* string: the inverse of `parseDocPath
|
|
1783
|
-
*
|
|
1784
|
-
* and on an empty segment array (symmetric with `parseDocPath("")`, which
|
|
1785
|
-
* throws "empty path").
|
|
1692
|
+
* string: the inverse of `parseDocPath`. Throws on a segment array the
|
|
1693
|
+
* deserializer rejects, and on an empty one.
|
|
1786
1694
|
* @param {DocPathSeg[]} segs
|
|
1787
1695
|
* @returns {string}
|
|
1788
1696
|
*/
|
|
@@ -1812,10 +1720,9 @@ export function formatDocPath(segs) {
|
|
|
1812
1720
|
}
|
|
1813
1721
|
|
|
1814
1722
|
/**
|
|
1815
|
-
* Import a markdown string to
|
|
1816
|
-
*
|
|
1817
|
-
*
|
|
1818
|
-
* semantics. Throws on an over-nested input.
|
|
1723
|
+
* Import a markdown string to canonical `Content`: the pure, document-free
|
|
1724
|
+
* codec. `overwrite(addr, importMarkdown(md))` spells the cold, anchor-losing
|
|
1725
|
+
* write; prefer `revise` for edit semantics. Throws on an over-nested input.
|
|
1819
1726
|
* @param {string} markdown
|
|
1820
1727
|
* @returns {Content}
|
|
1821
1728
|
*/
|
|
@@ -1839,10 +1746,9 @@ export function importMarkdown(markdown) {
|
|
|
1839
1746
|
|
|
1840
1747
|
/**
|
|
1841
1748
|
* Map a base content position (a USV index into `Content.text`, not a UTF-16
|
|
1842
|
-
* offset) through a `delta` to its new
|
|
1843
|
-
*
|
|
1844
|
-
*
|
|
1845
|
-
* it). Throws on a malformed `delta`.
|
|
1749
|
+
* offset) through a `delta` to its new position, holding a caret stable across
|
|
1750
|
+
* a `revise`. `assoc` decides the side of a same-position insertion (`"after"`
|
|
1751
|
+
* moves past it). Throws on a malformed `delta`.
|
|
1846
1752
|
* @param {Delta} delta
|
|
1847
1753
|
* @param {number} pos
|
|
1848
1754
|
* @param {Assoc} assoc
|
|
@@ -1865,11 +1771,10 @@ export function mapPos(delta, pos, assoc) {
|
|
|
1865
1771
|
}
|
|
1866
1772
|
|
|
1867
1773
|
/**
|
|
1868
|
-
* Parse a canonical document-model `Diagnostic.path`
|
|
1869
|
-
*
|
|
1870
|
-
*
|
|
1871
|
-
*
|
|
1872
|
-
* the string. Throws on a malformed path.
|
|
1774
|
+
* Parse a canonical document-model `Diagnostic.path` (`cards.<kind>[<i>].<field>`,
|
|
1775
|
+
* `main.body`, `recipients[0].name`) into structured [`DocPathSeg`] segments, so
|
|
1776
|
+
* a consumer routes on segments instead of regexing the string. Throws on a
|
|
1777
|
+
* malformed path.
|
|
1873
1778
|
* @param {string} path
|
|
1874
1779
|
* @returns {DocPathSeg[]}
|
|
1875
1780
|
*/
|
|
@@ -1892,12 +1797,10 @@ export function parseDocPath(path) {
|
|
|
1892
1797
|
}
|
|
1893
1798
|
|
|
1894
1799
|
/**
|
|
1895
|
-
* Rebase `markdown` onto a `base` content
|
|
1896
|
-
*
|
|
1897
|
-
* text
|
|
1898
|
-
*
|
|
1899
|
-
* md)` fuses this with the store for atomicity. Throws on an over-nested
|
|
1900
|
-
* markdown input or a non-content `base`.
|
|
1800
|
+
* Rebase `markdown` onto a `base` content: the document-free twin of `revise`,
|
|
1801
|
+
* returning the new `content` and the text `delta` (offsets are USV indices into
|
|
1802
|
+
* `Content.text`, surviving anchors rebased). Throws on an over-nested markdown
|
|
1803
|
+
* input or a non-content `base`.
|
|
1901
1804
|
* @param {Content} base
|
|
1902
1805
|
* @param {string} markdown
|
|
1903
1806
|
* @returns {{ content: Content; delta: Delta }}
|
|
@@ -1921,13 +1824,9 @@ export function rebase(base, markdown) {
|
|
|
1921
1824
|
}
|
|
1922
1825
|
|
|
1923
1826
|
/**
|
|
1924
|
-
* Runs at instantiation
|
|
1925
|
-
*
|
|
1926
|
-
*
|
|
1927
|
-
*
|
|
1928
|
-
* Not the package's `init`. That name belongs to the hand-written runtime,
|
|
1929
|
-
* which owns instantiation itself (`runtime/runtime.js`); this runs as part of
|
|
1930
|
-
* the instantiation it awaits.
|
|
1827
|
+
* Runs at instantiation, so a Rust panic reaches the console as a stack trace
|
|
1828
|
+
* rather than `unreachable`. Not the package's `init` — that name belongs to
|
|
1829
|
+
* the hand-written runtime, which owns instantiation itself.
|
|
1931
1830
|
*/
|
|
1932
1831
|
export function start() {
|
|
1933
1832
|
wasm.start();
|