@eldrajs/theme-core 0.0.0 → 0.1.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 +301 -0
- package/LICENSE +21 -0
- package/README.md +68 -1
- package/dist/bridge-DfNINXLL.js +314 -0
- package/dist/bridge.d.ts +2 -0
- package/dist/bridge.js +2 -0
- package/dist/design-tokens.d.ts +68 -0
- package/dist/design-tokens.js +486 -0
- package/dist/dynamic-route.d.ts +2 -0
- package/dist/dynamic-route.js +3 -0
- package/dist/dynamicRoute-CxXY-Y_8.js +126 -0
- package/dist/dynamicRoute-pRTBoYT6.d.ts +55 -0
- package/dist/i18n.d.ts +107 -0
- package/dist/i18n.js +192 -0
- package/dist/image-framing.d.ts +2 -0
- package/dist/image-framing.js +109 -0
- package/dist/imageFraming-BUZ-yqho.d.ts +51 -0
- package/dist/index-DxrkKyG4.d.ts +488 -0
- package/dist/index.d.ts +407 -0
- package/dist/index.js +1136 -0
- package/dist/layout-CWq_v6ws.d.ts +244 -0
- package/dist/layout.d.ts +2 -0
- package/dist/layout.js +930 -0
- package/dist/links.d.ts +113 -0
- package/dist/links.js +184 -0
- package/dist/overlay-Bgi0tIbN.d.ts +201 -0
- package/dist/overlay-BvkEOiMB.js +2908 -0
- package/dist/overlay.d.ts +2 -0
- package/dist/overlay.js +6 -0
- package/dist/preview-router.d.ts +2 -0
- package/dist/preview-router.js +130 -0
- package/dist/reusable.d.ts +66 -0
- package/dist/reusable.js +92 -0
- package/dist/reusableExpansion-Bqm83nCJ.js +229 -0
- package/dist/reusableExpansion-CXvs_ckx.d.ts +42 -0
- package/dist/stega.d.ts +17 -0
- package/dist/stega.js +69 -0
- package/dist/template-layout.d.ts +3 -0
- package/dist/template-layout.js +328 -0
- package/dist/templateLayout-MjNs0gbF.d.ts +254 -0
- package/package.json +89 -2
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
import { ColorLiteral, ColorSelection, ContainerOverride, ContainerPreset, CssTokenLength, DesignTokenCatalog, DesignTokenId, DesignTokenValidationCode, DesignTokenValidationError, ResponsiveTokenValue, SiteDesignTokenOverrides, ThemeColorToken, ThemeDesignTokens, applyDesignTokenOverrides, designTokenRevisionHash, generateDesignTokenCss, generateTailwindThemeCss, normalizeColorSelection, normalizeSiteDesignTokenOverrides, normalizeThemeDesignTokens, resolveColorSelection, resolveDesignTokenCatalog, responsiveValue } from "./design-tokens.js";
|
|
2
|
+
import { a as buildDynamicRoutePath, c as parseDynamicRoutePattern, d as resolvePagePath, i as RouteTemplateLike, l as resolveRoute, n as MAX_DYNAMIC_ROUTE_PATTERN_BYTES, o as catalogRouteTarget, r as ParsedDynamicRoutePattern, s as matchDynamicRoutePattern, t as DynamicRouteResolution, u as PageLike } from "./dynamicRoute-pRTBoYT6.js";
|
|
3
|
+
import { a as ImageFraming, c as focalBand, d as imageFramingAttrs, f as imageFramingStyle, h as unscaledFrameRect, i as IMAGE_FRAMING_MIN_ZOOM, l as framingDrag, m as parseImageFramingValueAttr, n as FrameRect, o as clampFocal, p as normalizeImageFraming, r as IMAGE_FRAMING_MAX_ZOOM, s as clampImageFraming, t as DEFAULT_IMAGE_FRAMING, u as framingZoom } from "./imageFraming-BUZ-yqho.js";
|
|
4
|
+
import { StegaMeta, decodeStega, encodeStega, stripStega } from "./stega.js";
|
|
5
|
+
import { C as ResolveEntryListBody, S as PageMeta, _ as EldraClientOptions, a as TemplateLayoutDocument, b as EntryList, c as TemplateLayoutRenderNode, d as CatalogDoc, f as CatalogList, g as EldraClientError, h as EldraClient, i as TemplateLayoutContext, l as buildTemplateBlockRenames, m as EldraCatalogReader, n as TemplateBlockFieldDefinition, o as TemplateLayoutNode, p as CatalogQuery, r as TemplateBlockNode, s as TemplateLayoutRenderModel, t as TemplateBlockDefinition, u as createTemplateLayoutRenderModel, v as EldraRetryOptions, x as EntryQuery, y as EntryDoc } from "./templateLayout-MjNs0gbF.js";
|
|
6
|
+
import { A as generateLayoutCss, C as Responsive, D as WidthLength, E as Spacing, F as resolveLayoutBreakpoints, I as resolveLayoutDocument, L as validateLayoutDocument, M as layoutNodeClass, N as layoutRenderNodeId, O as activeLayoutBreakpoint, P as normalizeLayoutDocument, S as ResolvedLayoutStyle, T as SlotValidationContext, _ as LayoutValidationError, a as LAYOUT_BREAKPOINTS, b as ResolvedLayoutDocument, c as LayoutBreakpoints, d as LayoutNode, f as LayoutRenderBlockNode, g as LayoutValidationCode, h as LayoutStyle, i as EDIT_MODE_HIDDEN_OPACITY, j as hiddenLayoutBreakpoints, k as createLayoutRenderModel, l as LayoutContainerNode, m as LayoutRenderNode, n as CssLength, o as LayoutBlockNode, p as LayoutRenderModel, r as DEFAULT_LAYOUT_BREAKPOINTS, s as LayoutBreakpoint, t as BlockSlotDefinition, u as LayoutDocument, v as LayoutValidationIssue, w as SizingLength, x as ResolvedLayoutNode, y as NormalizedLayoutResult } from "./layout-CWq_v6ws.js";
|
|
7
|
+
import { a as RichTextRenderStateChange, c as NegotiatedEditorCapabilities, d as PreviewRouterMessageType, f as createPreviewMessageRouter, i as RichTextFieldIdentity, l as PREVIEW_ROUTER_MESSAGE_TYPES, n as OverlayRuntime, o as classifyBeforeInput, r as OverlayRuntimeOptions, s as createOverlayRuntime, t as BeforeInputClassification, u as PreviewMessageRouter } from "./overlay-Bgi0tIbN.js";
|
|
8
|
+
import { a as ReusableComponentRevision, i as ReusableComponentResolver, n as ReusableComponentPlacement, o as ReusableRenderIdentity, r as ReusableComponentProjection, s as createProjectionResolver, t as ReusableComponentBinding } from "./reusableExpansion-CXvs_ckx.js";
|
|
9
|
+
import { PageLayoutDocument, PageLayoutNode, ReusableComponentSnapshotCache, ReusableLayoutOptions, ReusableLayoutRenderModel, ReusableLayoutRenderNode, ReusablePerspective, createReusableLayoutRenderModel } from "./reusable.js";
|
|
10
|
+
//#region src/client.d.ts
|
|
11
|
+
export declare function createEldraClient(opts: EldraClientOptions): EldraClient;
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/stegaWalk.d.ts
|
|
14
|
+
/**
|
|
15
|
+
* Projects a complete localized CMS draft into the active-locale shape used
|
|
16
|
+
* by theme renderers. The input is never mutated, so Studio can keep sending
|
|
17
|
+
* and persisting the complete document.
|
|
18
|
+
*
|
|
19
|
+
* `apiId` (the entry's own `schemaApiId`, when known) gates the
|
|
20
|
+
* `{value,label}` select unwrap above on `isBlockFieldSelect`, tracking the
|
|
21
|
+
* dot-separated field path as the walk descends (the same convention
|
|
22
|
+
* `encodeEntryDataStega`'s `walk` uses), so it only fires for a field the
|
|
23
|
+
* theme's manifest actually registered as `type: "select"` — including one
|
|
24
|
+
* nested inside a `list`'s composite item, e.g. `"items.0.variant"`. When
|
|
25
|
+
* `apiId` is omitted, or the schema has no registered block fields at all
|
|
26
|
+
* (a non-block entry, such as a page, never appears in the block-fields
|
|
27
|
+
* registry), `isBlockFieldSelect` returns false for every path and nothing
|
|
28
|
+
* is unwrapped — safe by construction, never a guess.
|
|
29
|
+
*
|
|
30
|
+
* Entering a nested resolved entry doc (`{id, data, schemaApiId, ...}` —
|
|
31
|
+
* the shape a page's embedded `blocks[]` array carries, or any other
|
|
32
|
+
* resolved reference field) re-derives `apiId` from that doc's own
|
|
33
|
+
* `schemaApiId` and resets the path, mirroring `encodeEntryDataStega`'s
|
|
34
|
+
* `walkNode`: a page's own schema is never registered as a block, so
|
|
35
|
+
* threading the outer `apiId` straight through would make every nested
|
|
36
|
+
* block's own select fields silently fail to unwrap forever, exactly the
|
|
37
|
+
* "non-block entry" case above — but the nested doc has its own registered
|
|
38
|
+
* fields once its own `schemaApiId` is used.
|
|
39
|
+
*/
|
|
40
|
+
export declare function projectEntryDataLocale(data: Record<string, unknown>, locale: string | null, apiId?: string): Record<string, unknown>;
|
|
41
|
+
/** Deep-copies `data`, stega-encoding every string leaf with its dot path.
|
|
42
|
+
* Entering a nested resolved entry doc re-roots entryId and fieldPath.
|
|
43
|
+
*
|
|
44
|
+
* `apiId` (the entry's own `schemaApiId`, when known) is used only to skip
|
|
45
|
+
* encoding a registered `select` field's resolved value (e.g. `variant`,
|
|
46
|
+
* top-level or nested inside a `list`'s composite item — see
|
|
47
|
+
* `isBlockFieldSelect`): that string is never displayed as editable text,
|
|
48
|
+
* only compared with `===` inside a `Block.vue`, and stega's invisible
|
|
49
|
+
* tracking characters make that comparison silently fail forever. Entering
|
|
50
|
+
* a nested resolved entry doc (a page's embedded block) re-derives `apiId`
|
|
51
|
+
* from that doc's own `schemaApiId`, so a block's own select fields are
|
|
52
|
+
* protected the same way whether it is fetched directly or embedded inside
|
|
53
|
+
* a page. */
|
|
54
|
+
export declare function encodeEntryDataStega(entryId: string, data: Record<string, unknown>, locale: string | null, apiId?: string): Record<string, unknown>;
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region src/layoutIdentity.d.ts
|
|
57
|
+
/**
|
|
58
|
+
* The layout identity of a rendered element: the nearest
|
|
59
|
+
* `[data-eldra-layout-node]` ancestor's node id and, when the placement is a
|
|
60
|
+
* reusable one, its `data-eldra-reusable-placement` id.
|
|
61
|
+
*
|
|
62
|
+
* Both the overlay runtime (block/field clicks, framing) and the §18 in-theme
|
|
63
|
+
* rich-text editor (`theme:rich-text-edited`) must resolve this the same way,
|
|
64
|
+
* so the two share this one implementation rather than each closing over a
|
|
65
|
+
* private copy. Keys are omitted — never set to `undefined` — so a payload
|
|
66
|
+
* built by spreading the result matches the bridge's optional fields exactly.
|
|
67
|
+
*/
|
|
68
|
+
export declare function layoutIdentityOf(element: Element | null): {
|
|
69
|
+
layoutNodeId?: string;
|
|
70
|
+
reusablePlacementId?: string;
|
|
71
|
+
};
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/richText.d.ts
|
|
74
|
+
/**
|
|
75
|
+
* Ordered ids of every rich-text toolbar control a `block.json` may request
|
|
76
|
+
* in `metadata.toolbar`. §18 v3: the theme no longer renders a toolbar —
|
|
77
|
+
* Studio's overlay editor does — but the list stays here as the single
|
|
78
|
+
* source of truth for the vite-plugin-theme scanner's build-time
|
|
79
|
+
* `metadata.toolbar` validation and theme-vue's block field lookup, so Theme
|
|
80
|
+
* Kit never carries two copies of it.
|
|
81
|
+
*
|
|
82
|
+
* Must stay in sync with the `metadata.toolbar` control ids Core's
|
|
83
|
+
* `richtext.go` validator accepts; a theme whose manifest names an id Core
|
|
84
|
+
* rejects fails ingest.
|
|
85
|
+
*/
|
|
86
|
+
export declare const RICH_TEXT_TOOLBAR_CONTROLS: readonly ["heading", "bold", "italic", "strike", "underline", "link", "bulletList", "orderedList", "blockquote", "code", "codeBlock", "hardBreak", "horizontalRule", "image", "embed", "highlight", "textColor", "undo", "redo", "table"];
|
|
87
|
+
type RichTextToolbarControl = (typeof RICH_TEXT_TOOLBAR_CONTROLS)[number];
|
|
88
|
+
/**
|
|
89
|
+
* Allow ordinary site links while rejecting executable and opaque URL
|
|
90
|
+
* schemes. Framework-neutral so both the theme-vue rich-text renderer and
|
|
91
|
+
* hand-rolled theme code can share one link/asset-src allowlist. Values are
|
|
92
|
+
* stega-stripped before validation since a themed link target can carry the
|
|
93
|
+
* click-tracking payload from `encodeStega`.
|
|
94
|
+
*/
|
|
95
|
+
export declare function safeHref(value: unknown): string | null;
|
|
96
|
+
//#endregion
|
|
97
|
+
//#region src/richTextTree.d.ts
|
|
98
|
+
/**
|
|
99
|
+
* Framework-neutral read renderer for a §18 rich-text field's TipTap JSON
|
|
100
|
+
* document. Produces a plain element tree; each framework binding maps that
|
|
101
|
+
* tree onto its own vnode factory (`@eldrajs/theme-vue`'s `renderRichTextDoc`
|
|
102
|
+
* is ~20 lines of `h()`), so the node/mark rules, the URL gating and the
|
|
103
|
+
* attribute whitelist exist exactly once for every adapter.
|
|
104
|
+
*
|
|
105
|
+
* Read mode only — the theme renders rich text, Studio owns the document and
|
|
106
|
+
* the one headless editor that writes it.
|
|
107
|
+
*
|
|
108
|
+
* §18 v3: every **node** element carries `data-eldra-node="<type>"` and
|
|
109
|
+
* `data-eldra-pos="<open position>"` (see `richTextPositions.ts`), so the
|
|
110
|
+
* overlay can map a DOM selection to a ProseMirror document position without
|
|
111
|
+
* a schema. **Mark** elements (`strong`, `em`, `s`, `u`, `code`, `mark`,
|
|
112
|
+
* `span[style]`, `a`) carry no stamps, and neither do the wrappers that are
|
|
113
|
+
* not nodes: a `codeBlock` stamps its `pre`, not the `code` inside it, and a
|
|
114
|
+
* `table` stamps the `table`, not the `tbody`. The stamps are computed from
|
|
115
|
+
* the document, not from the tree, so a node the sanitiser drops (an unsafe
|
|
116
|
+
* image `src`) still consumes its position and everything after it stays
|
|
117
|
+
* numbered as the document numbers it.
|
|
118
|
+
*/
|
|
119
|
+
interface RichTextMark {
|
|
120
|
+
type?: string;
|
|
121
|
+
attrs?: Record<string, unknown>;
|
|
122
|
+
}
|
|
123
|
+
interface RichTextNode {
|
|
124
|
+
type?: string;
|
|
125
|
+
attrs?: Record<string, unknown>;
|
|
126
|
+
content?: RichTextNode[];
|
|
127
|
+
marks?: RichTextMark[];
|
|
128
|
+
text?: string;
|
|
129
|
+
}
|
|
130
|
+
/** One element in the render tree. Attribute values are always strings, so a
|
|
131
|
+
* mapper can hand them to any vnode factory (or to `setAttribute`) unchanged. */
|
|
132
|
+
interface RichTextRenderNode {
|
|
133
|
+
tag: string;
|
|
134
|
+
attrs: Record<string, string>;
|
|
135
|
+
children: RichTextRenderChild[];
|
|
136
|
+
}
|
|
137
|
+
/** Text leaves are plain strings; everything else is an element. */
|
|
138
|
+
type RichTextRenderChild = RichTextRenderNode | string;
|
|
139
|
+
interface BuildRichTextTreeOptions {
|
|
140
|
+
/** Validates and normalizes a link/image/embed/file-attachment target; unsafe values return null. */
|
|
141
|
+
safeHref: (value: unknown) => string | null;
|
|
142
|
+
/**
|
|
143
|
+
* Pad an empty textblock (a `paragraph`/`heading` with no content, or an
|
|
144
|
+
* empty `codeBlock`) with a single unstamped `<br data-eldra-pad="">`
|
|
145
|
+
* child, the way TipTap/ProseMirror pad an empty textblock with a trailing
|
|
146
|
+
* `<br>` — without it the browser collapses `<p></p>` to zero height, so a
|
|
147
|
+
* fresh paragraph (e.g. from pressing Enter at the end of one) is
|
|
148
|
+
* invisible and has nowhere for the caret to sit. Defaults to `false` so
|
|
149
|
+
* static/published output is unchanged; the theme-vue binding passes
|
|
150
|
+
* `true` only while the field is actually being edited.
|
|
151
|
+
*
|
|
152
|
+
* The pad is zero-width to `richTextPositions.ts`'s DOM walk (see
|
|
153
|
+
* `RICH_TEXT_PAD_ATTR`) — not a `hardBreak`, which is stamped and still
|
|
154
|
+
* counts one position — and `computeRichTextPositions`, which works from
|
|
155
|
+
* the document rather than the DOM, needs no changes at all.
|
|
156
|
+
*/
|
|
157
|
+
padEmptyBlocks?: boolean;
|
|
158
|
+
/**
|
|
159
|
+
* A floor for every `heading` node's level: the rendered tag is
|
|
160
|
+
* `h{max(minHeadingLevel, level)}`, still capped at 6. Defaults to 1 — the
|
|
161
|
+
* generic clamp, i.e. whatever level the document carries.
|
|
162
|
+
*
|
|
163
|
+
* A page owns its heading outline; a rich-text field does not. The same body
|
|
164
|
+
* document is legitimately an `h2`-and-down section in one block and an
|
|
165
|
+
* `h3`-and-down one in another (the starter's `article` body starts at h2,
|
|
166
|
+
* its `rich-text` block at h3), and nothing in the document or in a block's
|
|
167
|
+
* toolbar metadata can express that — the toolbar's `heading` control id is
|
|
168
|
+
* level-agnostic, so an editor can insert any level anywhere. Applying the
|
|
169
|
+
* floor at *render* time is what lets one stored document sit correctly under
|
|
170
|
+
* two different page outlines, and is why this is a render option rather than
|
|
171
|
+
* a document transform: the document is never rewritten, so an editor's own
|
|
172
|
+
* level survives a round trip through Studio untouched.
|
|
173
|
+
*
|
|
174
|
+
* A floor, never an offset: an author who already wrote h3 under
|
|
175
|
+
* `minHeadingLevel: 3` keeps h3, and one who wrote h4 keeps h4 — only the
|
|
176
|
+
* levels *above* the floor move. Out-of-range and non-integer values are
|
|
177
|
+
* clamped into 1-6 the same way a node's own level is, so this never produces
|
|
178
|
+
* an `<h0>`/`<h7>` whatever a caller passes.
|
|
179
|
+
*/
|
|
180
|
+
minHeadingLevel?: number;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Build a TipTap JSON document's content as a render tree. Non-doc input
|
|
184
|
+
* builds an empty tree.
|
|
185
|
+
*
|
|
186
|
+
* Every top-level child is an element: a well-formed document only holds
|
|
187
|
+
* block nodes there, and a malformed one (a text node, or an unknown node
|
|
188
|
+
* wrapping text, directly under `doc`) gets its bare text wrapped in a
|
|
189
|
+
* `span` rather than dropped — so the content survives and a mapper never
|
|
190
|
+
* has to place a text node next to the field root's element children.
|
|
191
|
+
*/
|
|
192
|
+
export declare function buildRichTextTree(doc: unknown, options: BuildRichTextTreeOptions): RichTextRenderNode[];
|
|
193
|
+
//#endregion
|
|
194
|
+
//#region src/richTextPositions.d.ts
|
|
195
|
+
/**
|
|
196
|
+
* ProseMirror-compatible document positions for a §18 rich-text field, with
|
|
197
|
+
* no dependency on ProseMirror (nor TipTap, nor any UI library — the theme
|
|
198
|
+
* SDK is a bridge only).
|
|
199
|
+
*
|
|
200
|
+
* §18 v3 makes the theme's own render the editing surface: the operator types
|
|
201
|
+
* in the theme's DOM and the theme reports what happened as positions, which
|
|
202
|
+
* Studio applies to the one headless TipTap editor that owns the document.
|
|
203
|
+
* That only works if both sides agree on the numbering to the character, so
|
|
204
|
+
* the rules below are ProseMirror's, restated:
|
|
205
|
+
*
|
|
206
|
+
* - the `doc`'s content starts at `0`, and the `doc` itself has no tokens;
|
|
207
|
+
* - every non-text node with content **opens** (+1), its children follow, and
|
|
208
|
+
* it **closes** (+1) after them;
|
|
209
|
+
* - a text node occupies `text.length` — UTF-16 code units, which is what
|
|
210
|
+
* ProseMirror counts, so an astral-plane character (an emoji) is 2;
|
|
211
|
+
* - a leaf node (`image`, `hardBreak`, `horizontalRule`, `embed`) occupies 1.
|
|
212
|
+
*
|
|
213
|
+
* `packages/theme-core/test/fixtures/rich-text-positions.fixture.json` pins
|
|
214
|
+
* the numbering for a set of documents and is copied byte-for-byte into
|
|
215
|
+
* Studio's tests, where it is asserted against a real TipTap instance —
|
|
216
|
+
* neither implementation can drift without the other suite failing.
|
|
217
|
+
*
|
|
218
|
+
* The DOM half of the module maps between a DOM point (what a `Selection`
|
|
219
|
+
* gives) and a position, using the `data-eldra-node`/`data-eldra-pos` stamps
|
|
220
|
+
* `buildRichTextTree` puts on **node** elements. Mark elements (`strong`,
|
|
221
|
+
* `em`, `a`, …) and the structural wrappers that are not nodes (`tbody`, the
|
|
222
|
+
* `code` inside a `codeBlock`'s `pre`) carry no stamp and are walked through
|
|
223
|
+
* transparently, which is exactly their status in the document.
|
|
224
|
+
*/
|
|
225
|
+
/** Nodes that occupy exactly one position and have no content. */
|
|
226
|
+
export declare const RICH_TEXT_LEAF_TYPES: readonly string[];
|
|
227
|
+
/**
|
|
228
|
+
* Ancestor element → mark name, for reading the active marks of a selection
|
|
229
|
+
* straight off the DOM. `span` counts only when it carries the inline style
|
|
230
|
+
* `textStyle` renders (a bare `span` is the wrapper `buildRichTextTree` puts
|
|
231
|
+
* around stray top-level text, not a mark), and `a` splits by the attribute
|
|
232
|
+
* the `fileAttachment` mark renders.
|
|
233
|
+
*/
|
|
234
|
+
export declare const RICH_TEXT_MARK_ELEMENTS: Readonly<Record<string, string>>;
|
|
235
|
+
interface RichTextPositionNode {
|
|
236
|
+
/** Indices into `content` from the `doc` down to this node. */
|
|
237
|
+
path: number[];
|
|
238
|
+
type: string;
|
|
239
|
+
/** The node's open position — the position immediately before it. */
|
|
240
|
+
pos: number;
|
|
241
|
+
/** The position immediately after it: `pos + nodeSize`. */
|
|
242
|
+
end: number;
|
|
243
|
+
}
|
|
244
|
+
interface RichTextPositions {
|
|
245
|
+
/** The `doc`'s content size. */
|
|
246
|
+
size: number;
|
|
247
|
+
/** Every node below the `doc`, in document order (the `doc` is not one). */
|
|
248
|
+
nodes: RichTextPositionNode[];
|
|
249
|
+
}
|
|
250
|
+
/** The DOM point a `Selection`/`Range` boundary is expressed as. */
|
|
251
|
+
interface RichTextDomPoint {
|
|
252
|
+
node: Node;
|
|
253
|
+
offset: number;
|
|
254
|
+
}
|
|
255
|
+
interface RichTextSelectionContext {
|
|
256
|
+
/** Mark names from the ancestor mark elements, innermost first — the same
|
|
257
|
+
* order `applyMarks` consumes a text node's `marks` array in. */
|
|
258
|
+
marks: string[];
|
|
259
|
+
/** The nearest stamped node element, which is the position's parent block. */
|
|
260
|
+
block: {
|
|
261
|
+
type: string;
|
|
262
|
+
attrs?: Record<string, unknown>;
|
|
263
|
+
} | null;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* A text node's rendered text, stega stripped. Edit mode stega-encodes every
|
|
267
|
+
* text leaf of a rich-text document (`encodeEntryDataStega`), so this is the
|
|
268
|
+
* one definition of "a text node's text" shared by the renderer
|
|
269
|
+
* (`richTextTree.ts`'s `buildNode`) and the position walk below — the DOM
|
|
270
|
+
* must never contain the invisible payload, and a position is a position in
|
|
271
|
+
* the *clean* document Studio holds either way. Non-text nodes have none.
|
|
272
|
+
*/
|
|
273
|
+
export declare function richTextText(node: unknown): string;
|
|
274
|
+
/**
|
|
275
|
+
* The number of positions a node occupies, including its own open and close
|
|
276
|
+
* tokens. The `doc` is the one node with no tokens, so it is not measured
|
|
277
|
+
* here — `computeRichTextPositions` sums its children instead.
|
|
278
|
+
*/
|
|
279
|
+
export declare function richTextNodeSize(node: unknown): number;
|
|
280
|
+
/**
|
|
281
|
+
* Walk a TipTap JSON document and return its content size plus every node's
|
|
282
|
+
* open/close position. Non-`doc` input (or a `doc` with no content) is an
|
|
283
|
+
* empty document: `{ size: 0, nodes: [] }`.
|
|
284
|
+
*
|
|
285
|
+
* Text nodes are included, so the fixture pins the whole numbering rather
|
|
286
|
+
* than only the elements the renderer stamps.
|
|
287
|
+
*/
|
|
288
|
+
export declare function computeRichTextPositions(doc: unknown): RichTextPositions;
|
|
289
|
+
/**
|
|
290
|
+
* `buildRichTextTree`'s `padEmptyBlocks` marker: a single unstamped
|
|
291
|
+
* `<br data-eldra-pad="">` child `buildRichTextTree` renders for an empty
|
|
292
|
+
* textblock (an empty paragraph, heading, or `codeBlock`'s `code`) so the
|
|
293
|
+
* browser does not collapse it to zero height and the caret has a line to
|
|
294
|
+
* sit on. Not a `hardBreak` — a real one is stamped (`data-eldra-node`) and
|
|
295
|
+
* still occupies one position via the leaf branch below; this occupies none.
|
|
296
|
+
*/
|
|
297
|
+
export declare const RICH_TEXT_PAD_ATTR = "data-eldra-pad";
|
|
298
|
+
/**
|
|
299
|
+
* The document position of a DOM point inside a rendered rich-text root — the
|
|
300
|
+
* shape `Selection.anchorNode`/`anchorOffset` and a `Range`'s boundaries come
|
|
301
|
+
* in. Returns null for a point outside `root`, or one the walk cannot reach
|
|
302
|
+
* (a detached node).
|
|
303
|
+
*/
|
|
304
|
+
export declare function resolveDomPosition(root: Element, node: Node, offset: number): number | null;
|
|
305
|
+
/**
|
|
306
|
+
* The DOM point for a document position inside a rendered rich-text root, so
|
|
307
|
+
* the theme can put the caret back where Studio says it belongs. Returns null
|
|
308
|
+
* for a position outside the rendered document.
|
|
309
|
+
*/
|
|
310
|
+
export declare function resolveDomPoint(root: Element, pos: number): RichTextDomPoint | null;
|
|
311
|
+
/**
|
|
312
|
+
* Both boundaries of a DOM range as document positions. A `Range` is always
|
|
313
|
+
* ordered, so `from <= to`; a boundary outside `root` returns null rather
|
|
314
|
+
* than a half-resolved range.
|
|
315
|
+
*/
|
|
316
|
+
export declare function domRangeToPositions(root: Element, range: {
|
|
317
|
+
startContainer: Node;
|
|
318
|
+
startOffset: number;
|
|
319
|
+
endContainer: Node;
|
|
320
|
+
endOffset: number;
|
|
321
|
+
}): {
|
|
322
|
+
from: number;
|
|
323
|
+
to: number;
|
|
324
|
+
} | null;
|
|
325
|
+
/**
|
|
326
|
+
* Refresh the `data-eldra-pos` stamps of an already-rendered root against a
|
|
327
|
+
* new document, without replacing any DOM.
|
|
328
|
+
*
|
|
329
|
+
* §18 v3 lets a field's re-render be **deferred** while a native text op is in
|
|
330
|
+
* flight: the browser owns that subtree, and replacing it would take the caret
|
|
331
|
+
* with it. The document underneath still moves — Studio applies the op and
|
|
332
|
+
* echoes the result — so every position after the edit shifts, and a stamp
|
|
333
|
+
* that still says what it said before the operator typed would send the next
|
|
334
|
+
* selection report to the wrong place in the document.
|
|
335
|
+
*
|
|
336
|
+
* Returns false, changing nothing, when the rendered tree and the document
|
|
337
|
+
* disagree on the number or the order of node elements — a node the sanitiser
|
|
338
|
+
* dropped, or a structural change that arrived while deferred. The caller must
|
|
339
|
+
* then fall back to a full re-render, which is the only honest answer: the
|
|
340
|
+
* stamps cannot describe a tree that is not the document's.
|
|
341
|
+
*/
|
|
342
|
+
export declare function restampRichTextPositions(root: Element, doc: unknown): boolean;
|
|
343
|
+
/**
|
|
344
|
+
* The marks and the block a DOM point sits in, read off the rendered tree —
|
|
345
|
+
* enough for the toolbar's active state, and it needs no schema on the theme
|
|
346
|
+
* side. Marks come from the ancestor mark elements innermost first (the order
|
|
347
|
+
* a text node's own `marks` array is applied in); the block is the nearest
|
|
348
|
+
* stamped node element.
|
|
349
|
+
*
|
|
350
|
+
* Pass the **caret's own node** — `Selection.focusNode`, which is the text
|
|
351
|
+
* node the caret sits in. Passing a block element instead answers for that
|
|
352
|
+
* element's own ancestry, so a caret inside `<strong>` reported as its parent
|
|
353
|
+
* `<p>` would come back with no marks at all and the toolbar would show bold
|
|
354
|
+
* as inactive while the operator is typing in bold.
|
|
355
|
+
*/
|
|
356
|
+
export declare function describeSelectionContext(root: Element, node: Node): RichTextSelectionContext;
|
|
357
|
+
/**
|
|
358
|
+
* The mark an ancestor element stands for, or null when it is not a mark.
|
|
359
|
+
* Exported because `RICH_TEXT_MARK_ELEMENTS` alone is misleading: three of its
|
|
360
|
+
* entries are conditional — a `span` is `textStyle` only with an inline
|
|
361
|
+
* `style`, an `a` splits by `data-file-attachment`, and a `code` directly
|
|
362
|
+
* inside a `codeBlock`'s `pre` is part of that node rather than an inline
|
|
363
|
+
* `code` mark. Anyone classifying an element must come through here.
|
|
364
|
+
*/
|
|
365
|
+
export declare function richTextMarkNameOf(element: Element): string | null;
|
|
366
|
+
//#endregion
|
|
367
|
+
//#region src/blockFields.d.ts
|
|
368
|
+
/**
|
|
369
|
+
* The theme's scanned `block.json` field metadata, as `virtual:eldra/block-fields`
|
|
370
|
+
* projects it. Framework-neutral: a binding's composable is a thin wrapper
|
|
371
|
+
* (`@eldrajs/theme-vue`'s `useEldraBlockField`), so the registry and the lookup
|
|
372
|
+
* are not re-implemented per framework.
|
|
373
|
+
*/
|
|
374
|
+
interface BlockFieldDefinition {
|
|
375
|
+
fieldId: string;
|
|
376
|
+
type: string;
|
|
377
|
+
/** Present (and true) only for localized fields; the virtual module omits it otherwise. */
|
|
378
|
+
localized?: boolean;
|
|
379
|
+
metadata?: Record<string, unknown>;
|
|
380
|
+
}
|
|
381
|
+
type BlockFieldsMap = Record<string, BlockFieldDefinition[]>;
|
|
382
|
+
/**
|
|
383
|
+
* Registers the theme's block field metadata so `isBlockFieldLocalized` can
|
|
384
|
+
* resolve it without importing a virtual module id — the SDK packages are
|
|
385
|
+
* published plain and cannot resolve `virtual:eldra/block-fields` at their
|
|
386
|
+
* own build time the way an app entry bundled by `@eldrajs/vite-plugin-theme`
|
|
387
|
+
* can. The themed app's bootstrap (theme-nuxt's runtime plugin, or an
|
|
388
|
+
* equivalent entry for another adapter) imports `virtual:eldra/block-fields`
|
|
389
|
+
* and calls this once at startup with the resolved map; call it again (e.g.
|
|
390
|
+
* on the plugin's HMR rescan) to replace the registered map.
|
|
391
|
+
*/
|
|
392
|
+
export declare function registerBlockFields(fields: BlockFieldsMap): void;
|
|
393
|
+
/**
|
|
394
|
+
* Whether the manifest marks this block field `localized`. A rich-text
|
|
395
|
+
* renderer uses it to default an omitted `locale` to the preview's active
|
|
396
|
+
* content locale — a localized field's draft is keyed per locale, so the
|
|
397
|
+
* marking attributes (and therefore every §18 v3 rich-text report) must carry
|
|
398
|
+
* the locale the render actually used. Returns false for an unknown
|
|
399
|
+
* block/field and outside a themed build.
|
|
400
|
+
*
|
|
401
|
+
* `metadata.toolbar` is deliberately not read here: §18 v3 keeps the toolbar
|
|
402
|
+
* to Studio, which gets the control list from Core's field definitions. The
|
|
403
|
+
* vite plugin still validates the ids at build time.
|
|
404
|
+
*/
|
|
405
|
+
export declare function isBlockFieldLocalized(apiId: string | undefined, fieldId: string): boolean;
|
|
406
|
+
//#endregion
|
|
407
|
+
export { type BeforeInputClassification, type BlockFieldDefinition, type BlockFieldsMap, BlockSlotDefinition, type BuildRichTextTreeOptions, CatalogDoc, CatalogList, CatalogQuery, ColorLiteral, ColorSelection, ContainerOverride, ContainerPreset, CssLength, CssTokenLength, DEFAULT_IMAGE_FRAMING, DEFAULT_LAYOUT_BREAKPOINTS, DesignTokenCatalog, DesignTokenId, DesignTokenValidationCode, DesignTokenValidationError, DynamicRouteResolution, EDIT_MODE_HIDDEN_OPACITY, EldraCatalogReader, EldraClient, EldraClientError, EldraClientOptions, EldraRetryOptions, EntryDoc, EntryList, EntryQuery, FrameRect, IMAGE_FRAMING_MAX_ZOOM, IMAGE_FRAMING_MIN_ZOOM, ImageFraming, LAYOUT_BREAKPOINTS, LayoutBlockNode, LayoutBreakpoint, LayoutBreakpoints, LayoutContainerNode, LayoutDocument, LayoutNode, LayoutRenderBlockNode, LayoutRenderModel, LayoutRenderNode, LayoutStyle, LayoutValidationCode, LayoutValidationError, LayoutValidationIssue, MAX_DYNAMIC_ROUTE_PATTERN_BYTES, type NegotiatedEditorCapabilities, NormalizedLayoutResult, type OverlayRuntime, type OverlayRuntimeOptions, PREVIEW_ROUTER_MESSAGE_TYPES, PageLayoutDocument, PageLayoutNode, type PageLike, PageMeta, ParsedDynamicRoutePattern, type PreviewMessageRouter, type PreviewRouterMessageType, ResolveEntryListBody, ResolvedLayoutDocument, ResolvedLayoutNode, ResolvedLayoutStyle, Responsive, ResponsiveTokenValue, type ReusableComponentBinding, type ReusableComponentPlacement, type ReusableComponentProjection, type ReusableComponentResolver, type ReusableComponentRevision, ReusableComponentSnapshotCache, ReusableLayoutOptions, ReusableLayoutRenderModel, ReusableLayoutRenderNode, ReusablePerspective, type ReusableRenderIdentity, type RichTextDomPoint, type RichTextFieldIdentity, type RichTextMark, type RichTextNode, type RichTextPositionNode, type RichTextPositions, type RichTextRenderChild, type RichTextRenderNode, type RichTextRenderStateChange, type RichTextSelectionContext, type RichTextToolbarControl, RouteTemplateLike, SiteDesignTokenOverrides, SizingLength, SlotValidationContext, Spacing, type StegaMeta, TemplateBlockDefinition, TemplateBlockFieldDefinition, TemplateBlockNode, TemplateLayoutContext, TemplateLayoutDocument, TemplateLayoutNode, TemplateLayoutRenderModel, TemplateLayoutRenderNode, ThemeColorToken, ThemeDesignTokens, WidthLength, activeLayoutBreakpoint, applyDesignTokenOverrides, buildDynamicRoutePath, buildTemplateBlockRenames, catalogRouteTarget, clampFocal, clampImageFraming, classifyBeforeInput, createLayoutRenderModel, createOverlayRuntime, createPreviewMessageRouter, createProjectionResolver, createReusableLayoutRenderModel, createTemplateLayoutRenderModel, decodeStega, designTokenRevisionHash, encodeStega, focalBand, framingDrag, framingZoom, generateDesignTokenCss, generateLayoutCss, generateTailwindThemeCss, hiddenLayoutBreakpoints, imageFramingAttrs, imageFramingStyle, layoutNodeClass, layoutRenderNodeId, matchDynamicRoutePattern, normalizeColorSelection, normalizeImageFraming, normalizeLayoutDocument, normalizeSiteDesignTokenOverrides, normalizeThemeDesignTokens, parseDynamicRoutePattern, parseImageFramingValueAttr, resolveColorSelection, resolveDesignTokenCatalog, resolveLayoutBreakpoints, resolveLayoutDocument, resolvePagePath, resolveRoute, responsiveValue, stripStega, unscaledFrameRect, validateLayoutDocument };
|