efficient-easel 0.0.0 → 0.97.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/LICENSE +10 -0
- package/README.md +818 -4
- package/dist/autosave/index.d.ts +101 -0
- package/dist/autosave/index.js +1 -0
- package/dist/blocks/index.d.ts +306 -0
- package/dist/blocks/index.js +0 -0
- package/dist/buckets-1vRlQceY.d.ts +13 -0
- package/dist/canvas/index.d.ts +194 -0
- package/dist/canvas/index.js +1 -0
- package/dist/chrome/chrome.css +570 -0
- package/dist/chrome/index.d.ts +219 -0
- package/dist/chrome/index.js +21 -0
- package/dist/chunk-2LUSK32B.js +1 -0
- package/dist/chunk-2OAZYSWJ.js +1 -0
- package/dist/chunk-67VZRQLG.js +13 -0
- package/dist/chunk-6OPSJGAI.js +1 -0
- package/dist/chunk-6PS6STGA.js +1 -0
- package/dist/chunk-6WY6ZXJG.js +1 -0
- package/dist/chunk-7A7O2JWQ.js +1 -0
- package/dist/chunk-BZ5ASXOL.js +1 -0
- package/dist/chunk-CERTFXCV.js +13 -0
- package/dist/chunk-D2BCHTQR.js +1 -0
- package/dist/chunk-FI23ALVJ.js +1 -0
- package/dist/chunk-GGTPNGFJ.js +1 -0
- package/dist/chunk-H4B72XCJ.js +1 -0
- package/dist/chunk-H6DDIBQ4.js +1 -0
- package/dist/chunk-KDIVA6WD.js +1 -0
- package/dist/chunk-KRXQM65X.js +1 -0
- package/dist/chunk-MCLBHENY.js +1 -0
- package/dist/chunk-MFIRYGHW.js +1 -0
- package/dist/chunk-NKB3KVAB.js +1 -0
- package/dist/chunk-O2NLQBFX.js +1 -0
- package/dist/chunk-OGZFDJ6G.js +1 -0
- package/dist/chunk-OWBO4WKA.js +0 -0
- package/dist/chunk-QB3BZIRA.js +5 -0
- package/dist/chunk-RE4LP46F.js +1 -0
- package/dist/chunk-STFMZJKU.js +14 -0
- package/dist/chunk-SUO5627P.js +1 -0
- package/dist/chunk-TDA4HH54.js +1 -0
- package/dist/chunk-WK3AFPXY.js +1 -0
- package/dist/chunk-YIMRTIBN.js +3 -0
- package/dist/chunk-YNZZYHA4.js +450 -0
- package/dist/chunk-YRLPFZW3.js +1 -0
- package/dist/chunk-ZAOM6PFH.js +1 -0
- package/dist/chunk-ZNCEOSXO.js +1 -0
- package/dist/copy/copy.css +282 -0
- package/dist/copy/index.d.ts +336 -0
- package/dist/copy/index.js +10 -0
- package/dist/data/index.d.ts +375 -0
- package/dist/data/index.js +1 -0
- package/dist/drag/drag.css +360 -0
- package/dist/drag/index.d.ts +379 -0
- package/dist/drag/index.js +18 -0
- package/dist/edit-lock/index.d.ts +354 -0
- package/dist/edit-lock/index.js +1 -0
- package/dist/editor/editor.css +58 -0
- package/dist/editor/index.d.ts +361 -0
- package/dist/editor/index.js +9 -0
- package/dist/fields/fields.css +207 -0
- package/dist/fields/index.d.ts +273 -0
- package/dist/fields/index.js +46 -0
- package/dist/gold/gold.css +196 -0
- package/dist/gold/index.d.ts +280 -0
- package/dist/gold/index.js +1 -0
- package/dist/icons/index.d.ts +474 -0
- package/dist/icons/index.js +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +1 -0
- package/dist/markup/index.d.ts +452 -0
- package/dist/markup/index.js +1 -0
- package/dist/menu/index.d.ts +49 -0
- package/dist/menu/index.js +15 -0
- package/dist/menu/menu.css +254 -0
- package/dist/node-ops/index.d.ts +91 -0
- package/dist/node-ops/index.js +1 -0
- package/dist/panel/index.d.ts +1088 -0
- package/dist/panel/index.js +16 -0
- package/dist/panel/panel.css +1460 -0
- package/dist/pick/index.d.ts +153 -0
- package/dist/pick/index.js +14 -0
- package/dist/pick/pick.css +235 -0
- package/dist/plan-DChbUXdS.d.ts +88 -0
- package/dist/rail/index.d.ts +145 -0
- package/dist/rail/index.js +1 -0
- package/dist/rail/rail.css +175 -0
- package/dist/render/index.d.ts +117 -0
- package/dist/render/index.js +5 -0
- package/dist/resolve-D68pb3Bx.d.ts +57 -0
- package/dist/shell/index.d.ts +159 -0
- package/dist/shell/index.js +1 -0
- package/dist/shell/shell.css +122 -0
- package/dist/strings/catalogue.d.ts +141 -0
- package/dist/strings/catalogue.js +1 -0
- package/dist/strings/index.d.ts +56 -0
- package/dist/strings/index.js +2 -0
- package/dist/style-clipboard/index.d.ts +184 -0
- package/dist/style-clipboard/index.js +1 -0
- package/dist/tree/index.d.ts +173 -0
- package/dist/tree/index.js +1 -0
- package/dist/tree/tree.css +618 -0
- package/dist/types-41704JE4.d.ts +112 -0
- package/dist/types-CEqUFH2j.d.ts +129 -0
- package/dist/types-CuNiSnX6.d.ts +204 -0
- package/dist/types-DNrn_w4V.d.ts +88 -0
- package/dist/types-Dy6oR6Z2.d.ts +153 -0
- package/dist/types-pGBXevBU.d.ts +131 -0
- package/dist/useNodeOps-BF0fQsif.d.ts +68 -0
- package/dist/watch-DmasQA61.d.ts +60 -0
- package/dist/wordFit-9B9nqyf3.d.ts +35 -0
- package/dist/words-B2YLaKEr.d.ts +30 -0
- package/dist/words-B87GIFWH.d.ts +86 -0
- package/dist/words-BK-npta-.d.ts +27 -0
- package/dist/words-CD3WADyb.d.ts +51 -0
- package/dist/words-CsRWXkY4.d.ts +129 -0
- package/dist/words-D9ChvbNC.d.ts +52 -0
- package/dist/words-DOhF-4D4.d.ts +35 -0
- package/dist/words-DagJdwIA.d.ts +78 -0
- package/dist/words-DfxEp_RH.d.ts +142 -0
- package/package.json +202 -3
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
import { D as Data, a as DataConfig, N as Node, S as SlotAddress, F as Found, P as Place, b as SlotEntry, W as WalkInfo } from '../types-41704JE4.js';
|
|
2
|
+
export { B as BlockShape, c as FieldShape, d as FieldsShape, e as NodeProps, R as RootData } from '../types-41704JE4.js';
|
|
3
|
+
export { R as ResolvableItem, a as ResolveCache, b as ResolveOptions, c as ResolveTrigger, d as changedProps, e as createResolveCache, f as deepEqual, r as resolveNodeData } from '../resolve-D68pb3Bx.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Finding a node's slots, and reading or writing a value at a prop path.
|
|
7
|
+
*
|
|
8
|
+
* A slot is found the way Puck finds one: by the FIELDS, not by the value. A
|
|
9
|
+
* prop is a slot when its field says `type: 'slot'`; a slot can also sit inside
|
|
10
|
+
* an `object` field or inside each item of an `array` field, and its name is
|
|
11
|
+
* then the prop path Puck gives it — `items[0].content`, `box.content`.
|
|
12
|
+
*
|
|
13
|
+
* One deliberate difference from Puck: Puck also walks an object whose field is
|
|
14
|
+
* NOT an `object` field using the PARENT's field map, so a key there that
|
|
15
|
+
* happens to share a slot's name is treated as a slot. No document relies on
|
|
16
|
+
* that (a non-array value there crashes Puck's own walk), and a rule that
|
|
17
|
+
* depends on a coincidence of names is not one to copy.
|
|
18
|
+
*
|
|
19
|
+
* Order is DECLARATION order — the order the fields are written in the config,
|
|
20
|
+
* which is the order a person reads the block in (`col1` before `col2`). Puck
|
|
21
|
+
* visits slots in reverse, as a side effect of how it fills empty ones; nothing
|
|
22
|
+
* in either app depends on that.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/** One step of a prop path: a key, or an index into an array. */
|
|
26
|
+
type Segment = string | number;
|
|
27
|
+
declare function getIn(value: unknown, segments: readonly Segment[]): unknown;
|
|
28
|
+
|
|
29
|
+
/** One translated value, and the fingerprint of the base value it was made from. */
|
|
30
|
+
interface TranslatedValue {
|
|
31
|
+
v: unknown;
|
|
32
|
+
src: string;
|
|
33
|
+
}
|
|
34
|
+
/** One node's translated values, by prop path. */
|
|
35
|
+
type TranslationEntries = Record<string, TranslatedValue>;
|
|
36
|
+
/** One language's values, beside the document — never inside it. Keyed by node id, or `"root"`. */
|
|
37
|
+
type TranslationOverlay = Record<string, TranslationEntries>;
|
|
38
|
+
/** One translatable value in a document: whose it is, and where in its props. */
|
|
39
|
+
interface TranslationRef {
|
|
40
|
+
id: string;
|
|
41
|
+
path: string;
|
|
42
|
+
}
|
|
43
|
+
interface TranslationStatus {
|
|
44
|
+
/** Values that want a translation (the base is not blank) or have one. */
|
|
45
|
+
total: number;
|
|
46
|
+
/** Values with words in the base and no translation: drawn in the base language. */
|
|
47
|
+
missing: TranslationRef[];
|
|
48
|
+
/** Values whose translation was made from a base value that has since changed. */
|
|
49
|
+
stale: TranslationRef[];
|
|
50
|
+
}
|
|
51
|
+
interface TranslatablePath {
|
|
52
|
+
path: string;
|
|
53
|
+
/** The value there now; `undefined` when the props hold none. */
|
|
54
|
+
value: unknown;
|
|
55
|
+
}
|
|
56
|
+
/** A node, or the root (`{ props }`, no type) — what `resolveNodeData` takes too. */
|
|
57
|
+
interface TranslatableItem {
|
|
58
|
+
type?: string;
|
|
59
|
+
props: Record<string, unknown>;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* A short, stable mark of a base value, kept beside its translation as `src`.
|
|
63
|
+
*
|
|
64
|
+
* a string `s<length>.<hash>` the string itself is hashed
|
|
65
|
+
* anything else `j<length>.<hash>` its JSON is hashed, keys sorted at
|
|
66
|
+
* every level, because a document's key
|
|
67
|
+
* order is not kept by the database
|
|
68
|
+
* no value `u`
|
|
69
|
+
*
|
|
70
|
+
* `<length>` is in UTF-16 code units and `<hash>` is FNV-1a (32 bits) over
|
|
71
|
+
* those units, both written in base 36. It is not a secret and not a proof:
|
|
72
|
+
* two values of the same length and the same 32-bit hash read as one, which is
|
|
73
|
+
* enough to notice that words were edited.
|
|
74
|
+
*
|
|
75
|
+
* The first letter names the scheme. These marks are STORED, so the function
|
|
76
|
+
* must go on giving the same answer for the same value; a better scheme takes
|
|
77
|
+
* a new letter rather than changing what `s` and `j` mean.
|
|
78
|
+
*/
|
|
79
|
+
declare function translationFingerprint(value: unknown): string;
|
|
80
|
+
/**
|
|
81
|
+
* The props of a node (or of the root) that may be translated, in the order
|
|
82
|
+
* the fields declare them, each with the value it holds now.
|
|
83
|
+
*
|
|
84
|
+
* A top-level value, and one inside an `object` field, is listed whether or
|
|
85
|
+
* not the props hold it (`value: undefined`). One inside an `array` field is
|
|
86
|
+
* listed per item that is there.
|
|
87
|
+
*/
|
|
88
|
+
declare function translatablePaths(item: TranslatableItem, config: DataConfig): TranslatablePath[];
|
|
89
|
+
/**
|
|
90
|
+
* The document in one language: every translated value laid over the base,
|
|
91
|
+
* every other value the base's.
|
|
92
|
+
*
|
|
93
|
+
* With no overlay, or an empty one, it is `data` ITSELF. Otherwise only the
|
|
94
|
+
* nodes that took a value are copied, along with what holds them; a block
|
|
95
|
+
* nothing was translated in is the same object before and after, and so is a
|
|
96
|
+
* document no entry lands in.
|
|
97
|
+
*
|
|
98
|
+
* An entry for a node that is not in the document (deleted, or not on this
|
|
99
|
+
* page), for a path the fields no longer declare, or for a block type the
|
|
100
|
+
* config does not know, is passed over — never an error.
|
|
101
|
+
*/
|
|
102
|
+
declare function applyTranslation(data: Data, config: DataConfig, overlay?: TranslationOverlay | null): Data;
|
|
103
|
+
/**
|
|
104
|
+
* How far a language has got: how many values want a translation, which have
|
|
105
|
+
* none (`missing`) and which were translated from words that have since
|
|
106
|
+
* changed (`stale`). Both lists are in document order — the root, then the
|
|
107
|
+
* nodes as `walk` visits them — and name the place in the BASE document.
|
|
108
|
+
*
|
|
109
|
+
* A value the base leaves blank wants nothing and is not counted, unless the
|
|
110
|
+
* language has an entry for it. A stale entry under an array that was not
|
|
111
|
+
* found again is reported at the index it is stored under.
|
|
112
|
+
*/
|
|
113
|
+
declare function translationStatus(data: Data, config: DataConfig, overlay?: TranslationOverlay | null): TranslationStatus;
|
|
114
|
+
/**
|
|
115
|
+
* The overlay a language's edit comes to. `edited` is the page as it was
|
|
116
|
+
* changed while it was shown in that language — `applyTranslation(base,
|
|
117
|
+
* previous)`, then words typed over it — and the answer holds an entry for
|
|
118
|
+
* every translatable value that differs from the base, with `src` the base
|
|
119
|
+
* value's fingerprint as it is now.
|
|
120
|
+
*
|
|
121
|
+
* - A value equal to the base's makes NO entry: falling back is the absence
|
|
122
|
+
* of one. So does a value that is not there (`undefined`).
|
|
123
|
+
* - Only translatable values are read. A block added, removed or moved in
|
|
124
|
+
* `edited`, an array of another length, a changed number or colour — the
|
|
125
|
+
* structure is the base's alone while a language is being written, and a
|
|
126
|
+
* difference there is passed over, never an error.
|
|
127
|
+
* - `previous` is the overlay the edit started from. An entry the edit did
|
|
128
|
+
* not touch is kept AS IT WAS, old `src` and all, so a save does not
|
|
129
|
+
* quietly turn a stale translation into a current one; and what `previous`
|
|
130
|
+
* holds for nodes that are not on the page is carried over (only
|
|
131
|
+
* `pruneTranslation` drops). Where nothing changed, the answer is
|
|
132
|
+
* `previous` itself.
|
|
133
|
+
*/
|
|
134
|
+
declare function extractTranslation(base: Data, edited: Data, config: DataConfig, previous?: TranslationOverlay | null): TranslationOverlay;
|
|
135
|
+
/**
|
|
136
|
+
* Drop what no longer has a place: the entries of a node that is not in the
|
|
137
|
+
* document, and — in a node whose type the config knows — an entry at a path
|
|
138
|
+
* its fields no longer declare or its props no longer reach. An entry whose
|
|
139
|
+
* array item moved is written at the index it is drawn at.
|
|
140
|
+
*
|
|
141
|
+
* A node whose type the config does NOT know keeps its entries untouched for
|
|
142
|
+
* as long as the node is there, and so does any node found inside it: with no
|
|
143
|
+
* fields there is no telling which of its paths are gone, and a block's
|
|
144
|
+
* content is allowed to land before its code.
|
|
145
|
+
*
|
|
146
|
+
* Until a host calls this, the entries of a deleted node stay in the overlay —
|
|
147
|
+
* which is what lets undoing the delete bring its translations back. An
|
|
148
|
+
* overlay with nothing to drop comes back as itself.
|
|
149
|
+
*/
|
|
150
|
+
declare function pruneTranslation(data: Data, config: DataConfig, overlay: TranslationOverlay): TranslationOverlay;
|
|
151
|
+
/**
|
|
152
|
+
* Carry an overlay across an edit of the BASE. `previousBase` is the document
|
|
153
|
+
* the overlay was in step with, `nextBase` the document after the edit.
|
|
154
|
+
*
|
|
155
|
+
* Only arrays need it. A node keeps its id wherever it goes, so moving one
|
|
156
|
+
* changes nothing here, and a node that was deleted keeps its entries (see
|
|
157
|
+
* `pruneTranslation`). An array item has no id, so its entries are stored
|
|
158
|
+
* under its INDEX, and this moves them to where the item went:
|
|
159
|
+
*
|
|
160
|
+
* - an item that reads the same before and after keeps its entries, at its
|
|
161
|
+
* new index (in place first; then the lowest unclaimed index before to the
|
|
162
|
+
* lowest after, so identical items keep their order);
|
|
163
|
+
* - an item that is at the same index on both sides but reads differently
|
|
164
|
+
* was edited where it stands: its entries stay, and are stale wherever a
|
|
165
|
+
* base value changed;
|
|
166
|
+
* - an item that is new but reads the same as one that was there (a
|
|
167
|
+
* duplicate) takes a COPY of that item's entries;
|
|
168
|
+
* - an item that is gone takes its entries with it. An item cannot be
|
|
169
|
+
* recognised again once it is out of the array, so a host that must bring
|
|
170
|
+
* them back on undo keeps the overlay in the same history step as the base.
|
|
171
|
+
*
|
|
172
|
+
* Stale entries travel with their item, which reading the overlay later, with
|
|
173
|
+
* `nextBase` alone, could not do: it finds a moved item by its base
|
|
174
|
+
* fingerprint, and a stale entry no longer has one that matches.
|
|
175
|
+
*
|
|
176
|
+
* An overlay the edit does not disturb comes back as itself.
|
|
177
|
+
*/
|
|
178
|
+
declare function rebaseTranslation(previousBase: Data, nextBase: Data, config: DataConfig, overlay: TranslationOverlay): TranslationOverlay;
|
|
179
|
+
/**
|
|
180
|
+
* Old id → new id, for a node and its copy: `duplicate` and `copyNode` give
|
|
181
|
+
* every copied node a fresh id, and an overlay is keyed by id. The two are
|
|
182
|
+
* walked side by side, slot by slot and child by child, for as far as they
|
|
183
|
+
* keep the same shape (a `strip` that drops a child ends the pairing there).
|
|
184
|
+
*/
|
|
185
|
+
declare function mapIds(source: Node, copy: Node, config: DataConfig): Record<string, string>;
|
|
186
|
+
/**
|
|
187
|
+
* The entries a copied subtree starts with: for every old id in `ids` that the
|
|
188
|
+
* overlay has entries for, the same entries under the new id. ONLY those — lay
|
|
189
|
+
* them over the language's overlay (`{ ...overlay, ...copyTranslation(overlay,
|
|
190
|
+
* ids) }`), or carry them to another page with the clipboard. An entry whose
|
|
191
|
+
* base value the copy changed (`strip`) is stale there, as it should be.
|
|
192
|
+
*/
|
|
193
|
+
declare function copyTranslation(overlay: TranslationOverlay | null | undefined, ids: Record<string, string>): TranslationOverlay;
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* efficient-easel/data — the document, as pure functions.
|
|
197
|
+
*
|
|
198
|
+
* The bottom layer of the engine that replaces Puck (the blueprint "Puck From
|
|
199
|
+
* The Ground Up For Efficient Editor", 2026-09-29, step 1.1). Every function
|
|
200
|
+
* takes a document and returns a new one; nothing here holds state, knows
|
|
201
|
+
* about React, or touches a browser global, so a server component, a Node
|
|
202
|
+
* script, a test and the editor's store all call the same code.
|
|
203
|
+
*
|
|
204
|
+
* find · walk · slotsOf read
|
|
205
|
+
* insert · move · remove · duplicate change the tree
|
|
206
|
+
* setProps · setRoot change one node's props, or the root's
|
|
207
|
+
* normalizeData what the editor does to a document it opens
|
|
208
|
+
* createNode · newId make a block the way the Add panel does
|
|
209
|
+
* applyTranslation · … a page's other languages, kept beside it (./translate)
|
|
210
|
+
*
|
|
211
|
+
* THE FORMAT DOES NOT CHANGE. A document goes in and comes out in exactly the
|
|
212
|
+
* shape Puck 0.20 saves (see ./types). Four rules keep it that way, and the
|
|
213
|
+
* round-trip spec pins each one:
|
|
214
|
+
*
|
|
215
|
+
* 1. An empty slot is written as `[]`, and `zones` is written as `{}`.
|
|
216
|
+
* 2. Default props follow Puck: a new block is created WITH its
|
|
217
|
+
* `defaultProps`; the root's `defaultProps` are filled in on open; an
|
|
218
|
+
* existing block is never back-filled.
|
|
219
|
+
* 3. A root prop that no field declares (a site's `theme`, `fonts`, `scales`)
|
|
220
|
+
* is kept exactly as it is. Nothing here drops a key it doesn't know.
|
|
221
|
+
* 4. The two older formats are READ — root props written directly on `root`,
|
|
222
|
+
* and children parked in `zones` — and converted on open, the way Puck's
|
|
223
|
+
* `migrate()` converts them. They are never written back.
|
|
224
|
+
*
|
|
225
|
+
* KEY ORDER. The backend stores these documents in Postgres `jsonb`, which does
|
|
226
|
+
* not keep key order, so "the same document as Puck" means the same keys and
|
|
227
|
+
* values. What this layer does promise is stronger for its own round trip: a
|
|
228
|
+
* document that is already in shape comes back as THE SAME OBJECT (so
|
|
229
|
+
* `normalizeData(doc) === doc`), and every edit copies only the nodes on the
|
|
230
|
+
* path to the change — an untouched block is the same object before and after.
|
|
231
|
+
*
|
|
232
|
+
* ERRORS. An edit that names a node or slot that is not there, an index off the
|
|
233
|
+
* end of a list, a move into the node's own subtree, or an insert that would
|
|
234
|
+
* put a second copy of an id into the document throws a `DataError`. The
|
|
235
|
+
* editor's store decides what an operator sees; this layer never guesses.
|
|
236
|
+
*
|
|
237
|
+
* LEAF DISCIPLINE: no imports outside this folder, no dependency at all.
|
|
238
|
+
* `crypto` is read inside `newId`, never at module evaluation.
|
|
239
|
+
*/
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* What `normalizeData` accepts: any saved document, as loosely as Puck's own
|
|
243
|
+
* `Data` type describes one (`root.props` optional). Converting the older
|
|
244
|
+
* shapes is its job, so it must take them without a cast. Every OTHER function
|
|
245
|
+
* here takes the normalised `Data` it returns.
|
|
246
|
+
*/
|
|
247
|
+
interface DataInput {
|
|
248
|
+
root?: {
|
|
249
|
+
props?: Record<string, unknown>;
|
|
250
|
+
[key: string]: unknown;
|
|
251
|
+
};
|
|
252
|
+
content?: unknown[];
|
|
253
|
+
zones?: Record<string, unknown[]>;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/** The root's id in a zone key, and the parent of the top-level list. */
|
|
257
|
+
declare const ROOT_ID = "root";
|
|
258
|
+
/** The top-level list's slot name. */
|
|
259
|
+
declare const ROOT_SLOT = "default-zone";
|
|
260
|
+
/** The top-level list, as an address. */
|
|
261
|
+
declare const ROOT_LIST: SlotAddress;
|
|
262
|
+
/** `{ parentId, slot }` → Puck's zone key `"<parentId>:<slot>"`. */
|
|
263
|
+
declare const zoneKey: ({ parentId, slot }: SlotAddress) => string;
|
|
264
|
+
/** Puck's zone key → `{ parentId, slot }`. Ids and prop paths hold no colon. */
|
|
265
|
+
declare function parseZoneKey(key: string): SlotAddress;
|
|
266
|
+
type DataErrorCode = 'not-found' | 'no-slot' | 'bad-index' | 'duplicate-id' | 'cycle' | 'id-change' | 'unknown-type';
|
|
267
|
+
declare class DataError extends Error {
|
|
268
|
+
readonly code: DataErrorCode;
|
|
269
|
+
constructor(code: DataErrorCode, message: string);
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* `<Type>-<uuid>` — the id every saved block already carries, in both apps.
|
|
273
|
+
* Where `crypto.randomUUID` is unavailable (a non-secure origin, an old test
|
|
274
|
+
* runtime) it falls back to time plus randomness: ids are persisted, so they
|
|
275
|
+
* must stay unique across page loads, which a counter would not.
|
|
276
|
+
*/
|
|
277
|
+
declare function newId(type: string): string;
|
|
278
|
+
/** A node's slots in declaration order. A missing top-level slot reads as `[]`. */
|
|
279
|
+
declare function slotsOf(node: Node, config: DataConfig): SlotEntry[];
|
|
280
|
+
/**
|
|
281
|
+
* Visit every node once, depth first, parent before children: the top-level
|
|
282
|
+
* list, then any slots on the root, then anything still parked in a legacy
|
|
283
|
+
* `zones` entry. Entries in a list that are not nodes are skipped, and indexes
|
|
284
|
+
* are always positions in the stored list.
|
|
285
|
+
*
|
|
286
|
+
* `visit` may return a node to put in this one's place (its id must not
|
|
287
|
+
* change); its children are then walked from the replacement. Returning
|
|
288
|
+
* nothing keeps the node. The result is `data` itself when nothing was
|
|
289
|
+
* replaced.
|
|
290
|
+
*/
|
|
291
|
+
declare function walk(data: Data, config: DataConfig, visit: (node: Node, info: WalkInfo) => Node | void): Data;
|
|
292
|
+
/** Where the node with this id is, or `null`. The first match in walk order. */
|
|
293
|
+
declare function find(data: Data, config: DataConfig, id: string): Found | null;
|
|
294
|
+
/** The list at an address, or `null` when no such slot exists. */
|
|
295
|
+
declare function getList(data: Data, config: DataConfig, address: SlotAddress): Node[] | null;
|
|
296
|
+
/**
|
|
297
|
+
* What the editor does to a document when it opens it — the same result Puck
|
|
298
|
+
* reaches on load, with the older formats converted (rule 4):
|
|
299
|
+
*
|
|
300
|
+
* - `root` holding its props directly becomes `{ props: { …those keys } }`;
|
|
301
|
+
* - the root's `defaultProps` fill any root prop that is missing (rule 2);
|
|
302
|
+
* - every declared top-level slot exists, `[]` when empty (rule 1);
|
|
303
|
+
* - `content` is a list and `zones` exists, `{}` when there is nothing in it;
|
|
304
|
+
* - children parked in `zones["<id>:<slot>"]` move into that slot when the
|
|
305
|
+
* node declares it and the slot is empty. Anything else in `zones` stays
|
|
306
|
+
* where it is — never dropped, never merged over content.
|
|
307
|
+
*
|
|
308
|
+
* A document already in shape is returned as the same object.
|
|
309
|
+
*/
|
|
310
|
+
declare function normalizeData(data: DataInput | Data, config: DataConfig): Data;
|
|
311
|
+
/**
|
|
312
|
+
* A new block, the way the Add panel makes one — Puck's `insert` recipe:
|
|
313
|
+
* `{ ...defaultProps, id }`, plus any `props` the caller starts it with. The
|
|
314
|
+
* defaults are copied, so two blocks never share an array or object, and every
|
|
315
|
+
* child a default slot seeds gets its own id.
|
|
316
|
+
*/
|
|
317
|
+
declare function createNode(config: DataConfig, type: string, props?: Record<string, unknown>, options?: {
|
|
318
|
+
id?: string;
|
|
319
|
+
}): Node;
|
|
320
|
+
/**
|
|
321
|
+
* Put `node` into the list at `place`. The node is brought into shape (default
|
|
322
|
+
* slots, ids for children that have none) and must not bring an id the
|
|
323
|
+
* document already holds — that is the bug where two blocks select, hide and
|
|
324
|
+
* delete together.
|
|
325
|
+
*/
|
|
326
|
+
declare function insert(data: Data, config: DataConfig, place: Place, node: Node): Data;
|
|
327
|
+
/** Take the node, and everything under it, out of the document. */
|
|
328
|
+
declare function remove(data: Data, config: DataConfig, id: string): Data;
|
|
329
|
+
/**
|
|
330
|
+
* Move a node to `to`. Within one list, `to.index` is the node's index AFTER
|
|
331
|
+
* the move (Puck's rule), so `0 … length-1`; into another list it is the index
|
|
332
|
+
* to insert at, `0 … length`. A move into the node's own subtree is refused.
|
|
333
|
+
*/
|
|
334
|
+
declare function move(data: Data, config: DataConfig, id: string, to: Place): Data;
|
|
335
|
+
/**
|
|
336
|
+
* Copy a node, and everything under it, to the place just after it. Every
|
|
337
|
+
* copied node gets a fresh id. `strip` sees each copied node (with its new id)
|
|
338
|
+
* and returns what to keep — the hook for "a copy must not claim the
|
|
339
|
+
* original's baked image" (`bakedId`), which Puck's own duplicate copied
|
|
340
|
+
* verbatim.
|
|
341
|
+
*/
|
|
342
|
+
declare function duplicate(data: Data, config: DataConfig, id: string, options?: {
|
|
343
|
+
id?: string;
|
|
344
|
+
strip?: (node: Node) => Node;
|
|
345
|
+
}): Data;
|
|
346
|
+
/**
|
|
347
|
+
* A copy of `node` and everything under it, every copied node with a FRESH id —
|
|
348
|
+
* what a paste inserts, so a clipboard can be pasted twice without two blocks
|
|
349
|
+
* sharing an id. `strip` sees each copied node, as in `duplicate`. The input is
|
|
350
|
+
* not touched.
|
|
351
|
+
*/
|
|
352
|
+
declare function copyNode(node: Node, config: DataConfig, options?: {
|
|
353
|
+
id?: string;
|
|
354
|
+
strip?: (node: Node) => Node;
|
|
355
|
+
}): Node;
|
|
356
|
+
/**
|
|
357
|
+
* Merge `patch` into a node's props — Puck's `replace`, for the common case of
|
|
358
|
+
* changing some props. A key keeps its place; a new key goes on the end;
|
|
359
|
+
* `undefined` clears a key (JSON drops it on save). New children in a patched
|
|
360
|
+
* slot are brought into shape. Changing `id` is refused. A patch that changes
|
|
361
|
+
* nothing returns `data` itself.
|
|
362
|
+
*/
|
|
363
|
+
declare function setProps(data: Data, config: DataConfig, id: string, patch: Record<string, unknown>): Data;
|
|
364
|
+
/**
|
|
365
|
+
* Replace a node wholesale — Puck's `replace` action: the node keeps its place
|
|
366
|
+
* and its id, and every prop is the new node's (a key it does not carry is
|
|
367
|
+
* gone, which `setProps` cannot do). Children in its slots that arrive without
|
|
368
|
+
* an id get one, and an id another node already holds is refused, as `insert`
|
|
369
|
+
* refuses it.
|
|
370
|
+
*/
|
|
371
|
+
declare function replaceNode(data: Data, config: DataConfig, id: string, node: Node): Data;
|
|
372
|
+
/** Merge `patch` into the root's props, the same way `setProps` does. */
|
|
373
|
+
declare function setRoot(data: Data, config: DataConfig, patch: Record<string, unknown>): Data;
|
|
374
|
+
|
|
375
|
+
export { Data, DataConfig, DataError, type DataErrorCode, type DataInput, Found, Node, Place, ROOT_ID, ROOT_LIST, ROOT_SLOT, type Segment, SlotAddress, SlotEntry, type TranslatableItem, type TranslatablePath, type TranslatedValue, type TranslationEntries, type TranslationOverlay, type TranslationRef, type TranslationStatus, WalkInfo, applyTranslation, copyNode, copyTranslation, createNode, duplicate, extractTranslation, find, getIn, getList, insert, mapIds, move, newId, normalizeData, parseZoneKey, pruneTranslation, rebaseTranslation, remove, replaceNode, setProps, setRoot, slotsOf, translatablePaths, translationFingerprint, translationStatus, walk, zoneKey };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{DataError,ROOT_ID,ROOT_LIST,ROOT_SLOT,applyTranslation,changedProps,copyNode,copyTranslation,createNode,createResolveCache,deepEqual,duplicate,extractTranslation,find,getList,insert,mapIds,move,newId,normalizeData,parseZoneKey,pruneTranslation,rebaseTranslation,remove,replaceNode,resolveNodeData,setProps,setRoot,slotsOf,translatablePaths,translationFingerprint,translationStatus,walk,zoneKey}from"../chunk-KRXQM65X.js";export{getIn}from"../chunk-NKB3KVAB.js";
|