@bettercms-ai/kit 3.1.31 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/context.d.ts +11 -0
- package/dist/context.js.map +1 -1
- package/dist/controls/rich-text/blocks.js +1 -1
- package/dist/controls/rich-text/control.d.ts +2 -1
- package/dist/controls/rich-text/control.js +21 -8
- package/dist/controls/rich-text/control.js.map +1 -1
- package/dist/controls/rich-text/editor.js +1 -1
- package/dist/engine/frame.js +1 -1
- package/dist/engine/frame.js.map +1 -1
- package/dist/engine/held.d.ts +82 -0
- package/dist/engine/held.js +190 -0
- package/dist/engine/held.js.map +1 -0
- package/dist/engine/kit-field.d.ts +9 -3
- package/dist/engine/kit-field.js +38 -12
- package/dist/engine/kit-field.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/schema/types.d.ts +9 -0
- package/dist/schema/types.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +2 -2
package/dist/context.d.ts
CHANGED
|
@@ -163,6 +163,17 @@ export interface KitServices {
|
|
|
163
163
|
* owns the label row and the help; the box is tagged `data-kit-legacy`. Absent → the field says why in words.
|
|
164
164
|
*/
|
|
165
165
|
LegacyControl?: React.ComponentType<ControlProps>;
|
|
166
|
+
/**
|
|
167
|
+
* HELD fields (kit 3.2.0), for a hold that depends on the stored value (a value an adapter cannot map back unchanged):
|
|
168
|
+
* a reason → the field at `path` renders read-only in its shell with that reason (`data-kit-held`) and is never
|
|
169
|
+
* written; null/undefined → the field edits as usual. A schema-level hold is `FieldSchema.held`. Called on render, so
|
|
170
|
+
* keep it cheap and pure.
|
|
171
|
+
*/
|
|
172
|
+
heldReason?: (at: {
|
|
173
|
+
field: FieldSchema;
|
|
174
|
+
path: FieldPath;
|
|
175
|
+
value: unknown;
|
|
176
|
+
}) => string | null | undefined;
|
|
166
177
|
/**
|
|
167
178
|
* The host's own items for a field's ⋯ menu (the entry editor's Move up · Move down · Move to panel), drawn after
|
|
168
179
|
* History and before Rewrite with AI. It renders kit `MenuItem`s, with its own leading `MenuSeparator`, or null.
|
package/dist/context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","names":[],"sources":["../src/context.tsx"],"sourcesContent":["/**\n * Kit runtime contexts (V2 HEAD 9829bf1 kit/context.tsx).\n *\n * - KitServices — pluggable app services (media library picker, upload sink, toast, AI rewrite, comment threads).\n * Hosts register theirs once (`registerKitServices`) or provide them (`KitServicesProvider`); the kit\n * never imports a feature. A service that is absent hides the surface that needs it.\n * - KitEnv — the editing environment a control renders in: variant (panel | document), doc identity, site\n * palette, permissions, presence, comments. Has safe defaults so a control can render alone.\n * - FormApi — present only inside <SchemaForm>: value, writes, navigation, issues, baselines, history.\n */\nimport * as React from \"react\";\nimport type { Cap } from \"./schema/sources\";\nimport type { FieldAccess, FieldPath, FieldSchema, Fieldset, TypeSchema } from \"./schema/types\";\nimport type { KitIssue } from \"./lib/validate\";\nimport type { ControlProps } from \"./types\";\nimport type { LinkTarget } from \"./controls/link\";\n\n/* ── Services ─────────────────────────────────────────────────────────── */\n/** The media asset a picker hands back (the host's media library row, narrowed to what the kit reads). */\nexport interface KitMediaAsset {\n id: string;\n url: string;\n name?: string;\n alt?: string;\n kind?: \"image\" | \"video\" | \"file\" | \"svg\";\n width?: number;\n height?: number;\n size?: number;\n}\nexport interface KitMediaPickerProps {\n open: boolean;\n onOpenChange: (v: boolean) => void;\n onPick: (assets: KitMediaAsset[]) => void;\n multiple?: boolean;\n accept?: (\"image\" | \"video\" | \"file\" | \"svg\")[];\n /** What the dialog is for, in the author's words (\"Replace icon\"). Absent: the host's own title. */\n title?: string;\n /** An icon's Remove, in the dialog's footer (its row has no room for one). Absent: no Remove. */\n onRemove?: () => void;\n /**\n * An icon's first tab: the icons already on this site, each with the value it is stored as. The field's own icon\n * leads, marked `current`: picking it closes the dialog with no write. Absent: no such tab.\n */\n icons?: KitSiteIcon[];\n onPickIcon?: (value: unknown) => void;\n}\n/** One icon already on the site (KitServices.useSiteIcons), as the picker's first tab draws it. */\nexport interface KitSiteIcon {\n url: string;\n value: unknown;\n assetId?: string;\n current?: boolean;\n}\nexport interface KitToastOptions {\n /** the second line under the message (V2 sonner `description`) */\n description?: string;\n action?: { label: string; onClick: () => void };\n duration?: number;\n icon?: React.ReactNode;\n}\n/** The host's toaster. The kit has no toast dependency (V2 re-exported sonner's). */\nexport interface KitToast {\n (message: string, opts?: KitToastOptions): void;\n success: (message: string, opts?: KitToastOptions) => void;\n}\n/** Rewrite with AI presets (V2 lib/ai.ts). The host's `aiRewrite` service produces the text. */\nexport type AiPreset = \"improve\" | \"shorter\" | \"longer\" | \"simplify\" | \"grammar\" | \"translate\";\nexport const AI_PRESETS: { id: AiPreset; label: string }[] = [\n { id: \"improve\", label: \"Improve\" },\n { id: \"shorter\", label: \"Shorter\" },\n { id: \"longer\", label: \"Longer\" },\n { id: \"simplify\", label: \"Simplify\" },\n { id: \"grammar\", label: \"Fix spelling & grammar\" },\n { id: \"translate\", label: \"Translate to Spanish\" },\n];\n/**\n * GAP-004: words selected in a rich-text field, to comment on (W3C TextQuoteSelector). `prefix` / `suffix` are up to 32\n * characters of the field's text right before and after them, so the host can find the right occurrence again.\n */\nexport interface KitCommentSelection {\n quote: string;\n prefix?: string;\n suffix?: string;\n}\n/** The in-place field comments popover (V2 FieldThreads over the comments store), drawn by the host. */\nexport interface KitFieldCommentsProps {\n docId: string;\n /** pathKey of the field (\"items.1.answer\") */\n fieldKey: string;\n label: string;\n /** the field's text, first 80 characters */\n quote?: string;\n /** GAP-004: set when the popover opened from a rich-text selection's Comment: the new thread is about these words */\n selection?: KitCommentSelection;\n onClose: () => void;\n /** \"Open in panel\": set when the host has a comments panel (`env.onComment`) */\n onOpenPanel?: () => void;\n}\n/** One field's ⋯ menu, as the host's extra items see it (KitServices.FieldMenuExtras). */\nexport interface KitFieldMenuExtrasProps {\n field: FieldSchema;\n path: FieldPath;\n /** the field is read-only for the lens: a host offers nothing that edits */\n readOnly: boolean;\n}\n/* The popover around FieldComments keeps itself open on Escape while focus is on an element marked `data-esc-owner`\n (V2 guardEscape): the composer marks its input so Escape clears or blurs the draft instead of losing it. */\nexport interface KitServices {\n /** The media library picker. */\n MediaPicker?: React.ComponentType<KitMediaPickerProps>;\n /** Called after an upload so the host can file the assets into its media library. */\n onUploaded?: (assets: KitMediaAsset[]) => void;\n /**\n * Image placements keep their edits BESIDE the url (`${name}Alt` · `${name}Focal` · `${name}Crop` ·\n * `${name}Decorative`) instead of turning the value into an object — the Visuals block model.\n */\n imageSiblings?: boolean;\n /** Real metadata for an image url (the host's media library), so captions never show placeholders. */\n resolveImage?: (url: string) => { name?: string; width?: number; height?: number; size?: number } | undefined;\n /** The host's full image editor (crop, rotate, focal, alt…), opened in place. */\n editImage?: (req: { docId: string; path: FieldPath; title: string }) => void;\n /**\n * RP-047: whether a rich-text body image at this address can be cropped (the crop is drawn by the media library's\n * image URL, so a picture from elsewhere keeps its whole frame). False → the crop is disabled and says why; the focal\n * point still applies. Absent → the crop is offered.\n */\n canCrop?: (url: string) => boolean;\n /** The project's forms for `reference: { to: [\"form\"] }` (the host's Forms store). */\n forms?: () => { id: string; title: string; subtitle: string }[];\n /** Toasts for Copy / Paste / Reset / AI (each with Undo). Absent → the action still runs, silently. */\n toast?: KitToast;\n /**\n * A slug's \"Save new address\" with \"Redirect it to the new address\" ticked (V2 SlugControl): the host files the\n * redirect from the old slug to the new one. Absent → no checkbox is offered, and the toast says the old address\n * will return \"Not found\", which is what happens. A rejection is named in a toast (the new slug is already saved).\n */\n redirectSlug?: (from: string, to: string) => void | Promise<void>;\n /**\n * A slug's \"Save new address\": the host writes the new address before any redirect is filed. Absent → the form's\n * value is the save (V2). A rejection is named in a toast and the old-address box stays for another try.\n */\n saveSlug?: (to: string) => Promise<void>;\n /** Rewrite with AI. Absent → the ⋯ menu offers no rewrite. `attempt` counts \"Try again\" presses. */\n aiRewrite?: (text: string, preset: AiPreset, attempt: number) => string | Promise<string>;\n /** In-place field comments. Absent and no `env.onComment` → the field shows no add-comment control. */\n FieldComments?: React.ComponentType<KitFieldCommentsProps>;\n /**\n * A React hook: open (unresolved) threads on one field, read from the same store FieldComments draws (V2 counted\n * `useBlockThreads(docId, key)`). Used while the host has no `env.onComment`; absent → SchemaForm `comments` counts.\n */\n useFieldCommentCount?: (docId: string, fieldKey: string) => number;\n /**\n * The host's own control for a type (a FieldRenderer arm in the dashboard), drawn for a stored value a kit control\n * hands off because it cannot carry it unchanged (rich text, LegacyFallback). Bare inside the kit FieldShell, which\n * owns the label row and the help; the box is tagged `data-kit-legacy`. Absent → the field says why in words.\n */\n LegacyControl?: React.ComponentType<ControlProps>;\n /**\n * The host's own items for a field's ⋯ menu (the entry editor's Move up · Move down · Move to panel), drawn after\n * History and before Rewrite with AI. It renders kit `MenuItem`s, with its own leading `MenuSeparator`, or null.\n * Absent → the menu is exactly V2's.\n */\n FieldMenuExtras?: React.ComponentType<KitFieldMenuExtrasProps>;\n /**\n * A React HOOK: the project's pages and CMS items a link can point at (controls/link.tsx). The host passes the same\n * function for the life of the form (it is called on every render of a link control). Absent → the link picker says\n * page search isn't available and takes a typed path. `error` is a whole sentence naming what failed (\"Pages couldn't\n * be loaded: …\", \"Items from Blog couldn't be loaded: …\"); the picker shows it under whatever did load.\n */\n useLinkTargets?: () => { targets: LinkTarget[]; loading?: boolean; error?: string };\n /**\n * A React HOOK: every SVG the site already uses (its pages, header and footer, the library's SVGs), for an icon's\n * picker. The host passes the same function for the life of the form. Absent → the picker has no site tab.\n */\n useSiteIcons?: () => KitSiteIcon[];\n /**\n * The entries a rich text's related posts or author bio block shows (kit-richtext-blocks-plan.md RT8). `ids`: the\n * hand-picked entries (an author bio's one author, related posts in hand-picked mode), answered in that order with\n * any the host cannot find left out. `query`: related posts chosen for the reader (owner 2026-10-24: `topic` = same\n * tags or category, `newest` = the collection newest first; `count` of them, `excludeId` the entry being edited).\n * Absent → the blocks show their empty state; a rejection's message is shown as said.\n */\n resolveRichTextRefs?: (req: KitRichTextRefRequest) => Promise<KitRichTextRef[]>;\n}\n\n/** What a related posts or author bio block asks the host for (KitServices.resolveRichTextRefs). */\nexport interface KitRichTextRefRequest {\n kind: \"relatedPosts\" | \"authorBio\";\n ids?: string[];\n query?: { collection?: string; mode: \"topic\" | \"newest\"; count: number; excludeId?: string };\n}\n/**\n * One resolved entry, as the block draws it: a post card (title, cover, category) or an author (avatar, title as name, bio).\n * A post with no `href` has no public page (its collection has no detail route); Related posts names that under its cards.\n */\nexport interface KitRichTextRef {\n id: string;\n title: string;\n href?: string;\n cover?: string;\n category?: string;\n avatar?: string;\n bio?: string;\n}\n\n/**\n * A React HOOK over KitServices.resolveRichTextRefs: `unavailable` when the host offers no resolver (draw the empty\n * state), else `loading`, then `items` or `error` (a sentence). `req` null asks nothing (a block with nothing picked).\n */\nexport function useRichTextRefs(req: KitRichTextRefRequest | null): { items: KitRichTextRef[]; loading: boolean; error?: string; unavailable: boolean } {\n const { resolveRichTextRefs } = useKitServices();\n const key = req ? JSON.stringify(req) : \"\";\n const [state, setState] = React.useState<{ key: string; items: KitRichTextRef[]; error?: string } | null>(null);\n React.useEffect(() => {\n if (!resolveRichTextRefs || !key) return;\n let live = true;\n resolveRichTextRefs(JSON.parse(key) as KitRichTextRefRequest).then(\n (items) => live && setState({ key, items }),\n (e: unknown) => live && setState({ key, items: [], error: e instanceof Error ? e.message : String(e) }),\n );\n return () => void (live = false);\n }, [resolveRichTextRefs, key]);\n if (!resolveRichTextRefs) return { items: [], loading: false, unavailable: true };\n if (!key) return { items: [], loading: false, unavailable: false };\n const done = state?.key === key ? state : null;\n return { items: done?.items ?? [], loading: !done, error: done?.error, unavailable: false };\n}\nlet registry: KitServices = {};\nconst listeners = new Set<() => void>();\n/** Register app services once at module load (e.g. the Content feature registers its media library). */\nexport function registerKitServices(s: KitServices) {\n registry = { ...registry, ...s };\n listeners.forEach((l) => l());\n}\nconst ServicesCtx = React.createContext<KitServices | null>(null);\nexport function KitServicesProvider({ value, children }: { value: KitServices; children: React.ReactNode }) {\n return <ServicesCtx.Provider value={value}>{children}</ServicesCtx.Provider>;\n}\nexport function useKitServices(): KitServices {\n const local = React.useContext(ServicesCtx);\n const global = React.useSyncExternalStore(\n (cb) => {\n listeners.add(cb);\n return () => listeners.delete(cb);\n },\n () => registry,\n () => registry,\n );\n return local ? { ...global, ...local } : global;\n}\n\n/** A host header element a top-level field (by path key) renders its actions into, instead of a label row. */\nexport const FieldHeaderSlot = React.createContext<{ key: string; el: HTMLElement } | null>(null);\n\n/* ── Environment ──────────────────────────────────────────────────────── */\nexport type KitVariant = \"panel\" | \"document\";\nexport interface KitPeer {\n id?: string;\n name: string;\n avatar?: string;\n /** presence colour (avatar ring, field border, caret flag) */\n color?: string;\n /** \"editing\" (soft lock + border) or \"viewing\" */\n status?: \"editing\" | \"viewing\";\n}\nexport interface Swatch {\n name: string;\n value: string;\n token?: string;\n}\n\n/** V2's demo site palette (Caldera). Hosts pass the project's brand palette through `env.palette`. */\nexport const SITE_PALETTE: Swatch[] = [\n { name: \"Ember\", value: \"#E0663B\", token: \"brand.ember\" },\n { name: \"Ochre\", value: \"#D97706\", token: \"brand.ochre\" },\n { name: \"Moss\", value: \"#4F6B4A\", token: \"brand.moss\" },\n { name: \"Lake\", value: \"#2563EB\", token: \"accent.lake\" },\n { name: \"Dusk\", value: \"#7C3AED\", token: \"accent.dusk\" },\n { name: \"Berry\", value: \"#DB2777\", token: \"accent.berry\" },\n { name: \"Char\", value: \"#1E1B18\", token: \"neutral.900\" },\n { name: \"Slate\", value: \"#4B5563\", token: \"neutral.600\" },\n { name: \"Bone\", value: \"#E7E0D6\", token: \"neutral.200\" },\n { name: \"Paper\", value: \"#F6F1EA\", token: \"neutral.50\" },\n];\n\nexport interface KitEnv {\n variant: KitVariant;\n /** Identity of the document/block being edited (rich-text sync, comments, history). */\n docId: string;\n /** The document's title — slug generation. */\n docTitle?: string;\n /** Public URL prefix for slug previews, e.g. \"caldera.bettercms.site/journal/\". */\n urlPrefix?: string;\n /** The document has been published (slug changes warn about the old address). */\n isPublished?: boolean;\n /**\n * The form's slug is the document's ADDRESS (a page's or an entry's URL). Only then does a changed slug on a published\n * document say the old address will stop working and offer the redirect. A slug prop or a key is not an address, so\n * it gets no such box (V2 draws it on document hosts only: its component-prop forms pass no published state).\n */\n slugIsAddress?: boolean;\n palette: Swatch[];\n /** The whole form is read-only for the lens (the host's content.edit rule, a generated twin…). */\n readOnly: boolean;\n /**\n * D58: the host's access check for the lens (`useCan` at the host). The kit never imports the store; it asks this for\n * field-level `access` and for developer surfaces (field keys, IDs, API names: `schema.view` or `api.view`).\n * Hosts that omit it (staff tools, demos) get allow-all.\n */\n can: (cap: Cap) => boolean;\n /** pathKey → teammates in that field */\n presence: Record<string, KitPeer[]>;\n /** pathKey → open comment threads */\n comments: Record<string, number>;\n /** Host comment panel. When absent, field comments live in the in-place popover only. */\n /** `quote`: the words selected in a rich text field when the comment came from its toolbar */\n onComment?: (path: FieldPath, field: FieldSchema, quote?: string) => void;\n /** The whole form is a global block (\"Navigation\") — every field is synced. */\n syncedFrom?: string;\n /** \"Open {title}\" on a reference card: the host edits the referenced entry in place (stacked panel). */\n onOpenReference?: (ref: { collectionId: string; entryId: string; title: string }) => void;\n /** CPO D39: \"inline\" (default) shows help under the label; \"tooltip\" moves it behind the ⓘ — for dense hosts (grid cells, popovers). */\n helpDisplay?: \"inline\" | \"tooltip\";\n /** D61 Review changes: the host's change markers, present only while its History panel is open. */\n review?: KitReview;\n /** D61 field ⋯ › History: the host opens its one History panel on this field. Absent = no History item. */\n onFieldHistory?: (path: FieldPath, field: FieldSchema) => void;\n /**\n * \"quiet\": a meta-form, like the schema editor's field settings (founder call, 2026-10-05). No comment, ⋯ or per-field\n * undo on the fields, and an on/off field is a label-left row with its switch on the right (the inspector's PRow), not a\n * switch card. \"preview\": the same chrome-free fields, controls exactly as editors see them (a schema preview, where a\n * comment would land on a sample, never a real document). Default \"full\".\n */\n fieldChrome?: \"full\" | \"preview\" | \"quiet\";\n /**\n * A host's own control for one field, by its path key (\"type\", \"options\"), drawn inside the usual shell. The schema\n * editor's field settings plug their Type, Options, Key and Show this field controls in here. Absent = kit controls only.\n */\n controls?: Record<string, React.ComponentType<ControlProps>>;\n /**\n * A collapsed fieldset's summary as chips, from the host (the schema editor's field settings: \"Required\", \"3 options\").\n * `undefined` falls back to the kit's own one-line summary. Keep it stable (a new function re-renders the form).\n */\n sectionSummary?: (set: Fieldset, value: Record<string, unknown>) => string[] | undefined;\n}\n\n/**\n * D61 Review changes, as the kit sees it. The host owns the history model; the kit only asks, per field path, whether\n * it changed in the range, and renders the host's marker (a 2px bar in the author's colour at the field's left edge,\n * with its hover card) where the at-rest \"changed\" dot would be.\n */\nexport interface KitReview {\n /** changes at or inside this field in the range (0 = unchanged) */\n count: (path: FieldPath) => number;\n /** the presence colour of whoever changed it last (list rows draw their own bar) */\n color: (path: FieldPath) => string | undefined;\n /** the host's change bar and hover card for a changed field (null when unchanged) */\n bar: (path: FieldPath, field: FieldSchema) => React.ReactNode;\n /** Show only changes: unchanged fields fold into one quiet line each run */\n onlyChanges: boolean;\n}\n\n/** The title of the fieldset a field sits in (null outside one). A quiet meta-form drops a field label that only repeats\n * its section's title (\"Options\" › \"Options\"): the section heading names it. */\nexport const KitSectionTitle = React.createContext<string | null>(null);\n/**\n * D66: the host's address row under a slug field (production URL, who serves it, the preview, live state). The host\n * knows the site's hosting; the kit only asks it to render the row for the slug being typed. Absent = the kit's own row.\n */\nexport const KitAddressContext = React.createContext<((slug: string) => React.ReactNode) | null>(null);\nexport const DEFAULT_ENV: KitEnv = {\n variant: \"panel\",\n docId: \"kit\",\n palette: [],\n readOnly: false,\n can: () => true,\n presence: {},\n comments: {},\n};\nconst EnvCtx = React.createContext<KitEnv>(DEFAULT_ENV);\n\n/** D58 field access: fields in the `seo` group default to `{ edit: \"seo.edit\" }`. */\nexport const fieldAccessOf = (field: FieldSchema): FieldAccess | undefined => field.access ?? (field.group === \"seo\" ? { edit: \"seo.edit\" } : undefined);\n\n/**\n * One field for the lens: hidden (no `view`), read-only (plain text: no `edit`, the field is `readOnly`, or the whole form\n * is read-only and the field has no edit cap of its own), or editable. An explicit `edit` cap wins over the form's\n * read-only rule, so an SEO specialist edits SEO fields inside a form they can't otherwise change.\n */\nexport function resolveFieldAccess(field: FieldSchema, env: Pick<KitEnv, \"can\" | \"readOnly\">): { hidden: boolean; readOnly: boolean } {\n const a = fieldAccessOf(field);\n if (a?.view && !env.can(a.view)) return { hidden: true, readOnly: true };\n if (field.readOnly === true) return { hidden: false, readOnly: true };\n if (a?.edit) return { hidden: false, readOnly: !env.can(a.edit) };\n return { hidden: false, readOnly: env.readOnly };\n}\n/** Drop the fields the lens can't `view` (recursively), so they are neither rendered nor validated. Same object back when\n * nothing is hidden. Values of dropped fields stay in the document untouched. */\nexport function visibleFields(fields: FieldSchema[], can: KitEnv[\"can\"]): FieldSchema[] {\n let changed = false;\n const out: FieldSchema[] = [];\n for (const f of fields) {\n const a = fieldAccessOf(f);\n if (a?.view && !can(a.view)) {\n changed = true;\n continue;\n }\n let g = f;\n if (f.fields) {\n const n = visibleFields(f.fields, can);\n if (n !== f.fields) g = { ...g, fields: n };\n }\n if (Array.isArray(f.of)) {\n const n = visibleFields(f.of, can);\n if (n !== f.of) g = { ...g, of: n };\n }\n if (f.slotSettings) {\n const n = visibleFields(f.slotSettings, can);\n if (n !== f.slotSettings) g = { ...g, slotSettings: n };\n }\n if (g !== f) changed = true;\n out.push(g);\n }\n return changed ? out : fields;\n}\nexport function visibleSchema(schema: TypeSchema, can: KitEnv[\"can\"]): TypeSchema {\n const fields = visibleFields(schema.fields, can);\n return fields === schema.fields ? schema : { ...schema, fields };\n}\n\n/** Developer surfaces (field keys, API names, IDs): `schema.view` or `api.view`. */\nexport const seesDevSurfaces = (env: Pick<KitEnv, \"can\">) => env.can(\"schema.view\") || env.can(\"api.view\");\nexport const KitEnvProvider = EnvCtx.Provider;\nexport const useKitEnv = () => React.useContext(EnvCtx);\n\n/* ── Form runtime (inside <SchemaForm>) ──────────────────────────────── */\nexport interface HistoryEntry {\n value: unknown;\n at: number;\n by: string;\n label?: string;\n}\nexport interface FormApi {\n schema: TypeSchema;\n value: Record<string, unknown>;\n /** write a value; `record: false` skips the field undo/history stack (e.g. programmatic sync) */\n setAt: (path: FieldPath, v: unknown, opts?: { record?: boolean; label?: string }) => void;\n getAt: (path: FieldPath) => unknown;\n /** value when the form mounted (field undo baseline) */\n baselineAt: (path: FieldPath) => unknown;\n /** published value (changed dot, Reset to published); undefined when never published */\n publishedAt: (path: FieldPath) => unknown;\n hasPublished: boolean;\n /** component instances (CPO D28): top-level fields inherit from a component unless overridden */\n inherited?: { from: string; isOverridden: (key: string) => boolean; reset: (key: string) => void };\n /** the current navigation path (drill-in stack) */\n path: FieldPath;\n navigate: (path: FieldPath) => void;\n /** the form draws frames for a non-root path. False while SchemaForm renders only the root frame: History and\n * drill-in rows hide or go inert instead of navigating to a path nothing shows (no silent no-op). */\n canNavigate: boolean;\n resolveSchema?: (blockType: string) => TypeSchema | undefined;\n /** blocks offered by \"+ Add block\" in slots (filtered by each slot's allow list) */\n blockLibrary?: TypeSchema[];\n /** all issues by pathKey */\n issues: Map<string, KitIssue>;\n /** the issue shown for a key (rules on blur, required after blur or a publish attempt) */\n visibleIssue: (key: string) => KitIssue | undefined;\n /** visible issues under a path prefix (rollup dots on rows, crumbs and tabs) */\n rollup: (prefix: FieldPath) => { errors: number; warnings: number };\n touch: (key: string) => void;\n showAllErrors: boolean;\n /** per-field undo (Undo last change to {label}) */\n canUndo: (key: string) => boolean;\n undo: (key: string) => void;\n /** versions of a field this session (newest first) */\n history: (key: string) => HistoryEntry[];\n /** the last change to this field came from AI (⋯ shows \"Undo AI change\") */\n aiKeys: Set<string>;\n markAi: (key: string, on: boolean) => void;\n /** remembered UI state per frame (selected group tab, open fieldsets) */\n memory: Map<string, unknown>;\n}\nconst FormCtx = React.createContext<FormApi | null>(null);\nexport const FormProvider = FormCtx.Provider;\nexport const useForm = () => React.useContext(FormCtx);\n"],"mappings":";;;;;;;;;;;;;AAmEA,IAAa,aAAgD;CAC3D;EAAE,IAAI;EAAW,OAAO;CAAU;CAClC;EAAE,IAAI;EAAW,OAAO;CAAU;CAClC;EAAE,IAAI;EAAU,OAAO;CAAS;CAChC;EAAE,IAAI;EAAY,OAAO;CAAW;CACpC;EAAE,IAAI;EAAW,OAAO;CAAyB;CACjD;EAAE,IAAI;EAAa,OAAO;CAAuB;AACnD;;;;;AAuIA,SAAgB,gBAAgB,KAAwH;CACtJ,MAAM,EAAE,wBAAwB,eAAe;CAC/C,MAAM,MAAM,MAAM,KAAK,UAAU,GAAG,IAAI;CACxC,MAAM,CAAC,OAAO,YAAY,MAAM,SAA0E,IAAI;CAC9G,MAAM,gBAAgB;EACpB,IAAI,CAAC,uBAAuB,CAAC,KAAK;EAClC,IAAI,OAAO;EACX,oBAAoB,KAAK,MAAM,GAAG,CAA0B,CAAC,CAAC,MAC3D,UAAU,QAAQ,SAAS;GAAE;GAAK;EAAM,CAAC,IACzC,MAAe,QAAQ,SAAS;GAAE;GAAK,OAAO,CAAC;GAAG,OAAO,aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC;EAAE,CAAC,CACxG;EACA,aAAa,MAAM,OAAO;CAC5B,GAAG,CAAC,qBAAqB,GAAG,CAAC;CAC7B,IAAI,CAAC,qBAAqB,OAAO;EAAE,OAAO,CAAC;EAAG,SAAS;EAAO,aAAa;CAAK;CAChF,IAAI,CAAC,KAAK,OAAO;EAAE,OAAO,CAAC;EAAG,SAAS;EAAO,aAAa;CAAM;CACjE,MAAM,OAAO,OAAO,QAAQ,MAAM,QAAQ;CAC1C,OAAO;EAAE,OAAO,MAAM,SAAS,CAAC;EAAG,SAAS,CAAC;EAAM,OAAO,MAAM;EAAO,aAAa;CAAM;AAC5F;AACA,IAAI,WAAwB,CAAC;AAC7B,IAAM,4BAAY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;EACA,IAAI,MAAM,GAAG,UAAU;EACvB,IAAI,KAAK,CAAC;CACZ;CACA,OAAO,UAAU,MAAM;AACzB;AACA,SAAgB,cAAc,QAAoB,KAAgC;CAChF,MAAM,SAAS,cAAc,OAAO,QAAQ,GAAG;CAC/C,OAAO,WAAW,OAAO,SAAS,SAAS;EAAE,GAAG;EAAQ;CAAO;AACjE;;AAGA,IAAa,mBAAmB,QAA6B,IAAI,IAAI,aAAa,KAAK,IAAI,IAAI,UAAU;AACzG,IAAa,iBAAiB,OAAO;AACrC,IAAa,kBAAkB,MAAM,WAAW,MAAM;AAkDtD,IAAM,UAAU,MAAM,cAA8B,IAAI;AACxD,IAAa,eAAe,QAAQ;AACpC,IAAa,gBAAgB,MAAM,WAAW,OAAO"}
|
|
1
|
+
{"version":3,"file":"context.js","names":[],"sources":["../src/context.tsx"],"sourcesContent":["/**\n * Kit runtime contexts (V2 HEAD 9829bf1 kit/context.tsx).\n *\n * - KitServices — pluggable app services (media library picker, upload sink, toast, AI rewrite, comment threads).\n * Hosts register theirs once (`registerKitServices`) or provide them (`KitServicesProvider`); the kit\n * never imports a feature. A service that is absent hides the surface that needs it.\n * - KitEnv — the editing environment a control renders in: variant (panel | document), doc identity, site\n * palette, permissions, presence, comments. Has safe defaults so a control can render alone.\n * - FormApi — present only inside <SchemaForm>: value, writes, navigation, issues, baselines, history.\n */\nimport * as React from \"react\";\nimport type { Cap } from \"./schema/sources\";\nimport type { FieldAccess, FieldPath, FieldSchema, Fieldset, TypeSchema } from \"./schema/types\";\nimport type { KitIssue } from \"./lib/validate\";\nimport type { ControlProps } from \"./types\";\nimport type { LinkTarget } from \"./controls/link\";\n\n/* ── Services ─────────────────────────────────────────────────────────── */\n/** The media asset a picker hands back (the host's media library row, narrowed to what the kit reads). */\nexport interface KitMediaAsset {\n id: string;\n url: string;\n name?: string;\n alt?: string;\n kind?: \"image\" | \"video\" | \"file\" | \"svg\";\n width?: number;\n height?: number;\n size?: number;\n}\nexport interface KitMediaPickerProps {\n open: boolean;\n onOpenChange: (v: boolean) => void;\n onPick: (assets: KitMediaAsset[]) => void;\n multiple?: boolean;\n accept?: (\"image\" | \"video\" | \"file\" | \"svg\")[];\n /** What the dialog is for, in the author's words (\"Replace icon\"). Absent: the host's own title. */\n title?: string;\n /** An icon's Remove, in the dialog's footer (its row has no room for one). Absent: no Remove. */\n onRemove?: () => void;\n /**\n * An icon's first tab: the icons already on this site, each with the value it is stored as. The field's own icon\n * leads, marked `current`: picking it closes the dialog with no write. Absent: no such tab.\n */\n icons?: KitSiteIcon[];\n onPickIcon?: (value: unknown) => void;\n}\n/** One icon already on the site (KitServices.useSiteIcons), as the picker's first tab draws it. */\nexport interface KitSiteIcon {\n url: string;\n value: unknown;\n assetId?: string;\n current?: boolean;\n}\nexport interface KitToastOptions {\n /** the second line under the message (V2 sonner `description`) */\n description?: string;\n action?: { label: string; onClick: () => void };\n duration?: number;\n icon?: React.ReactNode;\n}\n/** The host's toaster. The kit has no toast dependency (V2 re-exported sonner's). */\nexport interface KitToast {\n (message: string, opts?: KitToastOptions): void;\n success: (message: string, opts?: KitToastOptions) => void;\n}\n/** Rewrite with AI presets (V2 lib/ai.ts). The host's `aiRewrite` service produces the text. */\nexport type AiPreset = \"improve\" | \"shorter\" | \"longer\" | \"simplify\" | \"grammar\" | \"translate\";\nexport const AI_PRESETS: { id: AiPreset; label: string }[] = [\n { id: \"improve\", label: \"Improve\" },\n { id: \"shorter\", label: \"Shorter\" },\n { id: \"longer\", label: \"Longer\" },\n { id: \"simplify\", label: \"Simplify\" },\n { id: \"grammar\", label: \"Fix spelling & grammar\" },\n { id: \"translate\", label: \"Translate to Spanish\" },\n];\n/**\n * GAP-004: words selected in a rich-text field, to comment on (W3C TextQuoteSelector). `prefix` / `suffix` are up to 32\n * characters of the field's text right before and after them, so the host can find the right occurrence again.\n */\nexport interface KitCommentSelection {\n quote: string;\n prefix?: string;\n suffix?: string;\n}\n/** The in-place field comments popover (V2 FieldThreads over the comments store), drawn by the host. */\nexport interface KitFieldCommentsProps {\n docId: string;\n /** pathKey of the field (\"items.1.answer\") */\n fieldKey: string;\n label: string;\n /** the field's text, first 80 characters */\n quote?: string;\n /** GAP-004: set when the popover opened from a rich-text selection's Comment: the new thread is about these words */\n selection?: KitCommentSelection;\n onClose: () => void;\n /** \"Open in panel\": set when the host has a comments panel (`env.onComment`) */\n onOpenPanel?: () => void;\n}\n/** One field's ⋯ menu, as the host's extra items see it (KitServices.FieldMenuExtras). */\nexport interface KitFieldMenuExtrasProps {\n field: FieldSchema;\n path: FieldPath;\n /** the field is read-only for the lens: a host offers nothing that edits */\n readOnly: boolean;\n}\n/* The popover around FieldComments keeps itself open on Escape while focus is on an element marked `data-esc-owner`\n (V2 guardEscape): the composer marks its input so Escape clears or blurs the draft instead of losing it. */\nexport interface KitServices {\n /** The media library picker. */\n MediaPicker?: React.ComponentType<KitMediaPickerProps>;\n /** Called after an upload so the host can file the assets into its media library. */\n onUploaded?: (assets: KitMediaAsset[]) => void;\n /**\n * Image placements keep their edits BESIDE the url (`${name}Alt` · `${name}Focal` · `${name}Crop` ·\n * `${name}Decorative`) instead of turning the value into an object — the Visuals block model.\n */\n imageSiblings?: boolean;\n /** Real metadata for an image url (the host's media library), so captions never show placeholders. */\n resolveImage?: (url: string) => { name?: string; width?: number; height?: number; size?: number } | undefined;\n /** The host's full image editor (crop, rotate, focal, alt…), opened in place. */\n editImage?: (req: { docId: string; path: FieldPath; title: string }) => void;\n /**\n * RP-047: whether a rich-text body image at this address can be cropped (the crop is drawn by the media library's\n * image URL, so a picture from elsewhere keeps its whole frame). False → the crop is disabled and says why; the focal\n * point still applies. Absent → the crop is offered.\n */\n canCrop?: (url: string) => boolean;\n /** The project's forms for `reference: { to: [\"form\"] }` (the host's Forms store). */\n forms?: () => { id: string; title: string; subtitle: string }[];\n /** Toasts for Copy / Paste / Reset / AI (each with Undo). Absent → the action still runs, silently. */\n toast?: KitToast;\n /**\n * A slug's \"Save new address\" with \"Redirect it to the new address\" ticked (V2 SlugControl): the host files the\n * redirect from the old slug to the new one. Absent → no checkbox is offered, and the toast says the old address\n * will return \"Not found\", which is what happens. A rejection is named in a toast (the new slug is already saved).\n */\n redirectSlug?: (from: string, to: string) => void | Promise<void>;\n /**\n * A slug's \"Save new address\": the host writes the new address before any redirect is filed. Absent → the form's\n * value is the save (V2). A rejection is named in a toast and the old-address box stays for another try.\n */\n saveSlug?: (to: string) => Promise<void>;\n /** Rewrite with AI. Absent → the ⋯ menu offers no rewrite. `attempt` counts \"Try again\" presses. */\n aiRewrite?: (text: string, preset: AiPreset, attempt: number) => string | Promise<string>;\n /** In-place field comments. Absent and no `env.onComment` → the field shows no add-comment control. */\n FieldComments?: React.ComponentType<KitFieldCommentsProps>;\n /**\n * A React hook: open (unresolved) threads on one field, read from the same store FieldComments draws (V2 counted\n * `useBlockThreads(docId, key)`). Used while the host has no `env.onComment`; absent → SchemaForm `comments` counts.\n */\n useFieldCommentCount?: (docId: string, fieldKey: string) => number;\n /**\n * The host's own control for a type (a FieldRenderer arm in the dashboard), drawn for a stored value a kit control\n * hands off because it cannot carry it unchanged (rich text, LegacyFallback). Bare inside the kit FieldShell, which\n * owns the label row and the help; the box is tagged `data-kit-legacy`. Absent → the field says why in words.\n */\n LegacyControl?: React.ComponentType<ControlProps>;\n /**\n * HELD fields (kit 3.2.0), for a hold that depends on the stored value (a value an adapter cannot map back unchanged):\n * a reason → the field at `path` renders read-only in its shell with that reason (`data-kit-held`) and is never\n * written; null/undefined → the field edits as usual. A schema-level hold is `FieldSchema.held`. Called on render, so\n * keep it cheap and pure.\n */\n heldReason?: (at: { field: FieldSchema; path: FieldPath; value: unknown }) => string | null | undefined;\n /**\n * The host's own items for a field's ⋯ menu (the entry editor's Move up · Move down · Move to panel), drawn after\n * History and before Rewrite with AI. It renders kit `MenuItem`s, with its own leading `MenuSeparator`, or null.\n * Absent → the menu is exactly V2's.\n */\n FieldMenuExtras?: React.ComponentType<KitFieldMenuExtrasProps>;\n /**\n * A React HOOK: the project's pages and CMS items a link can point at (controls/link.tsx). The host passes the same\n * function for the life of the form (it is called on every render of a link control). Absent → the link picker says\n * page search isn't available and takes a typed path. `error` is a whole sentence naming what failed (\"Pages couldn't\n * be loaded: …\", \"Items from Blog couldn't be loaded: …\"); the picker shows it under whatever did load.\n */\n useLinkTargets?: () => { targets: LinkTarget[]; loading?: boolean; error?: string };\n /**\n * A React HOOK: every SVG the site already uses (its pages, header and footer, the library's SVGs), for an icon's\n * picker. The host passes the same function for the life of the form. Absent → the picker has no site tab.\n */\n useSiteIcons?: () => KitSiteIcon[];\n /**\n * The entries a rich text's related posts or author bio block shows (kit-richtext-blocks-plan.md RT8). `ids`: the\n * hand-picked entries (an author bio's one author, related posts in hand-picked mode), answered in that order with\n * any the host cannot find left out. `query`: related posts chosen for the reader (owner 2026-10-24: `topic` = same\n * tags or category, `newest` = the collection newest first; `count` of them, `excludeId` the entry being edited).\n * Absent → the blocks show their empty state; a rejection's message is shown as said.\n */\n resolveRichTextRefs?: (req: KitRichTextRefRequest) => Promise<KitRichTextRef[]>;\n}\n\n/** What a related posts or author bio block asks the host for (KitServices.resolveRichTextRefs). */\nexport interface KitRichTextRefRequest {\n kind: \"relatedPosts\" | \"authorBio\";\n ids?: string[];\n query?: { collection?: string; mode: \"topic\" | \"newest\"; count: number; excludeId?: string };\n}\n/**\n * One resolved entry, as the block draws it: a post card (title, cover, category) or an author (avatar, title as name, bio).\n * A post with no `href` has no public page (its collection has no detail route); Related posts names that under its cards.\n */\nexport interface KitRichTextRef {\n id: string;\n title: string;\n href?: string;\n cover?: string;\n category?: string;\n avatar?: string;\n bio?: string;\n}\n\n/**\n * A React HOOK over KitServices.resolveRichTextRefs: `unavailable` when the host offers no resolver (draw the empty\n * state), else `loading`, then `items` or `error` (a sentence). `req` null asks nothing (a block with nothing picked).\n */\nexport function useRichTextRefs(req: KitRichTextRefRequest | null): { items: KitRichTextRef[]; loading: boolean; error?: string; unavailable: boolean } {\n const { resolveRichTextRefs } = useKitServices();\n const key = req ? JSON.stringify(req) : \"\";\n const [state, setState] = React.useState<{ key: string; items: KitRichTextRef[]; error?: string } | null>(null);\n React.useEffect(() => {\n if (!resolveRichTextRefs || !key) return;\n let live = true;\n resolveRichTextRefs(JSON.parse(key) as KitRichTextRefRequest).then(\n (items) => live && setState({ key, items }),\n (e: unknown) => live && setState({ key, items: [], error: e instanceof Error ? e.message : String(e) }),\n );\n return () => void (live = false);\n }, [resolveRichTextRefs, key]);\n if (!resolveRichTextRefs) return { items: [], loading: false, unavailable: true };\n if (!key) return { items: [], loading: false, unavailable: false };\n const done = state?.key === key ? state : null;\n return { items: done?.items ?? [], loading: !done, error: done?.error, unavailable: false };\n}\nlet registry: KitServices = {};\nconst listeners = new Set<() => void>();\n/** Register app services once at module load (e.g. the Content feature registers its media library). */\nexport function registerKitServices(s: KitServices) {\n registry = { ...registry, ...s };\n listeners.forEach((l) => l());\n}\nconst ServicesCtx = React.createContext<KitServices | null>(null);\nexport function KitServicesProvider({ value, children }: { value: KitServices; children: React.ReactNode }) {\n return <ServicesCtx.Provider value={value}>{children}</ServicesCtx.Provider>;\n}\nexport function useKitServices(): KitServices {\n const local = React.useContext(ServicesCtx);\n const global = React.useSyncExternalStore(\n (cb) => {\n listeners.add(cb);\n return () => listeners.delete(cb);\n },\n () => registry,\n () => registry,\n );\n return local ? { ...global, ...local } : global;\n}\n\n/** A host header element a top-level field (by path key) renders its actions into, instead of a label row. */\nexport const FieldHeaderSlot = React.createContext<{ key: string; el: HTMLElement } | null>(null);\n\n/* ── Environment ──────────────────────────────────────────────────────── */\nexport type KitVariant = \"panel\" | \"document\";\nexport interface KitPeer {\n id?: string;\n name: string;\n avatar?: string;\n /** presence colour (avatar ring, field border, caret flag) */\n color?: string;\n /** \"editing\" (soft lock + border) or \"viewing\" */\n status?: \"editing\" | \"viewing\";\n}\nexport interface Swatch {\n name: string;\n value: string;\n token?: string;\n}\n\n/** V2's demo site palette (Caldera). Hosts pass the project's brand palette through `env.palette`. */\nexport const SITE_PALETTE: Swatch[] = [\n { name: \"Ember\", value: \"#E0663B\", token: \"brand.ember\" },\n { name: \"Ochre\", value: \"#D97706\", token: \"brand.ochre\" },\n { name: \"Moss\", value: \"#4F6B4A\", token: \"brand.moss\" },\n { name: \"Lake\", value: \"#2563EB\", token: \"accent.lake\" },\n { name: \"Dusk\", value: \"#7C3AED\", token: \"accent.dusk\" },\n { name: \"Berry\", value: \"#DB2777\", token: \"accent.berry\" },\n { name: \"Char\", value: \"#1E1B18\", token: \"neutral.900\" },\n { name: \"Slate\", value: \"#4B5563\", token: \"neutral.600\" },\n { name: \"Bone\", value: \"#E7E0D6\", token: \"neutral.200\" },\n { name: \"Paper\", value: \"#F6F1EA\", token: \"neutral.50\" },\n];\n\nexport interface KitEnv {\n variant: KitVariant;\n /** Identity of the document/block being edited (rich-text sync, comments, history). */\n docId: string;\n /** The document's title — slug generation. */\n docTitle?: string;\n /** Public URL prefix for slug previews, e.g. \"caldera.bettercms.site/journal/\". */\n urlPrefix?: string;\n /** The document has been published (slug changes warn about the old address). */\n isPublished?: boolean;\n /**\n * The form's slug is the document's ADDRESS (a page's or an entry's URL). Only then does a changed slug on a published\n * document say the old address will stop working and offer the redirect. A slug prop or a key is not an address, so\n * it gets no such box (V2 draws it on document hosts only: its component-prop forms pass no published state).\n */\n slugIsAddress?: boolean;\n palette: Swatch[];\n /** The whole form is read-only for the lens (the host's content.edit rule, a generated twin…). */\n readOnly: boolean;\n /**\n * D58: the host's access check for the lens (`useCan` at the host). The kit never imports the store; it asks this for\n * field-level `access` and for developer surfaces (field keys, IDs, API names: `schema.view` or `api.view`).\n * Hosts that omit it (staff tools, demos) get allow-all.\n */\n can: (cap: Cap) => boolean;\n /** pathKey → teammates in that field */\n presence: Record<string, KitPeer[]>;\n /** pathKey → open comment threads */\n comments: Record<string, number>;\n /** Host comment panel. When absent, field comments live in the in-place popover only. */\n /** `quote`: the words selected in a rich text field when the comment came from its toolbar */\n onComment?: (path: FieldPath, field: FieldSchema, quote?: string) => void;\n /** The whole form is a global block (\"Navigation\") — every field is synced. */\n syncedFrom?: string;\n /** \"Open {title}\" on a reference card: the host edits the referenced entry in place (stacked panel). */\n onOpenReference?: (ref: { collectionId: string; entryId: string; title: string }) => void;\n /** CPO D39: \"inline\" (default) shows help under the label; \"tooltip\" moves it behind the ⓘ — for dense hosts (grid cells, popovers). */\n helpDisplay?: \"inline\" | \"tooltip\";\n /** D61 Review changes: the host's change markers, present only while its History panel is open. */\n review?: KitReview;\n /** D61 field ⋯ › History: the host opens its one History panel on this field. Absent = no History item. */\n onFieldHistory?: (path: FieldPath, field: FieldSchema) => void;\n /**\n * \"quiet\": a meta-form, like the schema editor's field settings (founder call, 2026-10-05). No comment, ⋯ or per-field\n * undo on the fields, and an on/off field is a label-left row with its switch on the right (the inspector's PRow), not a\n * switch card. \"preview\": the same chrome-free fields, controls exactly as editors see them (a schema preview, where a\n * comment would land on a sample, never a real document). Default \"full\".\n */\n fieldChrome?: \"full\" | \"preview\" | \"quiet\";\n /**\n * A host's own control for one field, by its path key (\"type\", \"options\"), drawn inside the usual shell. The schema\n * editor's field settings plug their Type, Options, Key and Show this field controls in here. Absent = kit controls only.\n */\n controls?: Record<string, React.ComponentType<ControlProps>>;\n /**\n * A collapsed fieldset's summary as chips, from the host (the schema editor's field settings: \"Required\", \"3 options\").\n * `undefined` falls back to the kit's own one-line summary. Keep it stable (a new function re-renders the form).\n */\n sectionSummary?: (set: Fieldset, value: Record<string, unknown>) => string[] | undefined;\n}\n\n/**\n * D61 Review changes, as the kit sees it. The host owns the history model; the kit only asks, per field path, whether\n * it changed in the range, and renders the host's marker (a 2px bar in the author's colour at the field's left edge,\n * with its hover card) where the at-rest \"changed\" dot would be.\n */\nexport interface KitReview {\n /** changes at or inside this field in the range (0 = unchanged) */\n count: (path: FieldPath) => number;\n /** the presence colour of whoever changed it last (list rows draw their own bar) */\n color: (path: FieldPath) => string | undefined;\n /** the host's change bar and hover card for a changed field (null when unchanged) */\n bar: (path: FieldPath, field: FieldSchema) => React.ReactNode;\n /** Show only changes: unchanged fields fold into one quiet line each run */\n onlyChanges: boolean;\n}\n\n/** The title of the fieldset a field sits in (null outside one). A quiet meta-form drops a field label that only repeats\n * its section's title (\"Options\" › \"Options\"): the section heading names it. */\nexport const KitSectionTitle = React.createContext<string | null>(null);\n/**\n * D66: the host's address row under a slug field (production URL, who serves it, the preview, live state). The host\n * knows the site's hosting; the kit only asks it to render the row for the slug being typed. Absent = the kit's own row.\n */\nexport const KitAddressContext = React.createContext<((slug: string) => React.ReactNode) | null>(null);\nexport const DEFAULT_ENV: KitEnv = {\n variant: \"panel\",\n docId: \"kit\",\n palette: [],\n readOnly: false,\n can: () => true,\n presence: {},\n comments: {},\n};\nconst EnvCtx = React.createContext<KitEnv>(DEFAULT_ENV);\n\n/** D58 field access: fields in the `seo` group default to `{ edit: \"seo.edit\" }`. */\nexport const fieldAccessOf = (field: FieldSchema): FieldAccess | undefined => field.access ?? (field.group === \"seo\" ? { edit: \"seo.edit\" } : undefined);\n\n/**\n * One field for the lens: hidden (no `view`), read-only (plain text: no `edit`, the field is `readOnly`, or the whole form\n * is read-only and the field has no edit cap of its own), or editable. An explicit `edit` cap wins over the form's\n * read-only rule, so an SEO specialist edits SEO fields inside a form they can't otherwise change.\n */\nexport function resolveFieldAccess(field: FieldSchema, env: Pick<KitEnv, \"can\" | \"readOnly\">): { hidden: boolean; readOnly: boolean } {\n const a = fieldAccessOf(field);\n if (a?.view && !env.can(a.view)) return { hidden: true, readOnly: true };\n if (field.readOnly === true) return { hidden: false, readOnly: true };\n if (a?.edit) return { hidden: false, readOnly: !env.can(a.edit) };\n return { hidden: false, readOnly: env.readOnly };\n}\n/** Drop the fields the lens can't `view` (recursively), so they are neither rendered nor validated. Same object back when\n * nothing is hidden. Values of dropped fields stay in the document untouched. */\nexport function visibleFields(fields: FieldSchema[], can: KitEnv[\"can\"]): FieldSchema[] {\n let changed = false;\n const out: FieldSchema[] = [];\n for (const f of fields) {\n const a = fieldAccessOf(f);\n if (a?.view && !can(a.view)) {\n changed = true;\n continue;\n }\n let g = f;\n if (f.fields) {\n const n = visibleFields(f.fields, can);\n if (n !== f.fields) g = { ...g, fields: n };\n }\n if (Array.isArray(f.of)) {\n const n = visibleFields(f.of, can);\n if (n !== f.of) g = { ...g, of: n };\n }\n if (f.slotSettings) {\n const n = visibleFields(f.slotSettings, can);\n if (n !== f.slotSettings) g = { ...g, slotSettings: n };\n }\n if (g !== f) changed = true;\n out.push(g);\n }\n return changed ? out : fields;\n}\nexport function visibleSchema(schema: TypeSchema, can: KitEnv[\"can\"]): TypeSchema {\n const fields = visibleFields(schema.fields, can);\n return fields === schema.fields ? schema : { ...schema, fields };\n}\n\n/** Developer surfaces (field keys, API names, IDs): `schema.view` or `api.view`. */\nexport const seesDevSurfaces = (env: Pick<KitEnv, \"can\">) => env.can(\"schema.view\") || env.can(\"api.view\");\nexport const KitEnvProvider = EnvCtx.Provider;\nexport const useKitEnv = () => React.useContext(EnvCtx);\n\n/* ── Form runtime (inside <SchemaForm>) ──────────────────────────────── */\nexport interface HistoryEntry {\n value: unknown;\n at: number;\n by: string;\n label?: string;\n}\nexport interface FormApi {\n schema: TypeSchema;\n value: Record<string, unknown>;\n /** write a value; `record: false` skips the field undo/history stack (e.g. programmatic sync) */\n setAt: (path: FieldPath, v: unknown, opts?: { record?: boolean; label?: string }) => void;\n getAt: (path: FieldPath) => unknown;\n /** value when the form mounted (field undo baseline) */\n baselineAt: (path: FieldPath) => unknown;\n /** published value (changed dot, Reset to published); undefined when never published */\n publishedAt: (path: FieldPath) => unknown;\n hasPublished: boolean;\n /** component instances (CPO D28): top-level fields inherit from a component unless overridden */\n inherited?: { from: string; isOverridden: (key: string) => boolean; reset: (key: string) => void };\n /** the current navigation path (drill-in stack) */\n path: FieldPath;\n navigate: (path: FieldPath) => void;\n /** the form draws frames for a non-root path. False while SchemaForm renders only the root frame: History and\n * drill-in rows hide or go inert instead of navigating to a path nothing shows (no silent no-op). */\n canNavigate: boolean;\n resolveSchema?: (blockType: string) => TypeSchema | undefined;\n /** blocks offered by \"+ Add block\" in slots (filtered by each slot's allow list) */\n blockLibrary?: TypeSchema[];\n /** all issues by pathKey */\n issues: Map<string, KitIssue>;\n /** the issue shown for a key (rules on blur, required after blur or a publish attempt) */\n visibleIssue: (key: string) => KitIssue | undefined;\n /** visible issues under a path prefix (rollup dots on rows, crumbs and tabs) */\n rollup: (prefix: FieldPath) => { errors: number; warnings: number };\n touch: (key: string) => void;\n showAllErrors: boolean;\n /** per-field undo (Undo last change to {label}) */\n canUndo: (key: string) => boolean;\n undo: (key: string) => void;\n /** versions of a field this session (newest first) */\n history: (key: string) => HistoryEntry[];\n /** the last change to this field came from AI (⋯ shows \"Undo AI change\") */\n aiKeys: Set<string>;\n markAi: (key: string, on: boolean) => void;\n /** remembered UI state per frame (selected group tab, open fieldsets) */\n memory: Map<string, unknown>;\n}\nconst FormCtx = React.createContext<FormApi | null>(null);\nexport const FormProvider = FormCtx.Provider;\nexport const useForm = () => React.useContext(FormCtx);\n"],"mappings":";;;;;;;;;;;;;AAmEA,IAAa,aAAgD;CAC3D;EAAE,IAAI;EAAW,OAAO;CAAU;CAClC;EAAE,IAAI;EAAW,OAAO;CAAU;CAClC;EAAE,IAAI;EAAU,OAAO;CAAS;CAChC;EAAE,IAAI;EAAY,OAAO;CAAW;CACpC;EAAE,IAAI;EAAW,OAAO;CAAyB;CACjD;EAAE,IAAI;EAAa,OAAO;CAAuB;AACnD;;;;;AA8IA,SAAgB,gBAAgB,KAAwH;CACtJ,MAAM,EAAE,wBAAwB,eAAe;CAC/C,MAAM,MAAM,MAAM,KAAK,UAAU,GAAG,IAAI;CACxC,MAAM,CAAC,OAAO,YAAY,MAAM,SAA0E,IAAI;CAC9G,MAAM,gBAAgB;EACpB,IAAI,CAAC,uBAAuB,CAAC,KAAK;EAClC,IAAI,OAAO;EACX,oBAAoB,KAAK,MAAM,GAAG,CAA0B,CAAC,CAAC,MAC3D,UAAU,QA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AQ;EACtB,MAAM,IAAI,cAAc,CAAC;EACzB,IAAI,GAAG,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG;GAC3B,UAAU;GACV;EACF;EACA,IAAI,IAAI;EACR,IAAI,EAAE,QAAQ;GACZ,MAAM,IAAI,cAAc,EAAE,QAAQ,GAAG;GACrC,IAAI,MAAM,EAAE,QAAQ,IAAI;IAAE,GAAG;IAAG,QAAQ;GAAE;EAC5C;EACA,IAAI,MAAM,QAAQ,EAAE,EAAE,GAAG;GACvB,MAAM,IAAI,cAAc,EAAE,IAAI,GAAG;GACjC,IAAI,MAAM,EAAE,IAAI,IAAI;IAAE,GAAG;IAAG,IAAI;GAAE;EACpC;EACA,IAAI,EAAE,cAAc;GAClB,MAAM,IAAI,cAAc,EAAE,cAAc,GAAG;GAC3C,IAAI,MAAM,EAAE,cAAc,IAAI;IAAE,GAAG;IAAG,cAAc;GAAE;EACxD;EACA,IAAI,MAAM,GAAG,UAAU;EACvB,IAAI,KAAK,CAAC;CACZ;CACA,OAAO,UAAU,MAAM;AACzB;AACA,SAAgB,cAAc,QAAoB,KAAgC;CAChF,MAAM,SAAS,cAAc,OAAO,QAAQ,GAAG;CAC/C,OAAO,WAAW,OAAO,SAAS,SAAS;EAAE,GAAG;EAAQ;CAAO;AACjE;;AAGA,IAAa,mBAAmB,QAA6B,IAAI,IAAI,aAAa,KAAK,IAAI,IAAI,UAAU;AACzG,IAAa,iBAAiB,OAAO;AACrC,IAAa,kBAAkB,MAAM,WAAW,MAAM;AAkDtD,IAAM,UAAU,MAAM,cAA8B,IAAI;AACxD,IAAa,eAAe,QAAQ;AACpC,IAAa,gBAAgB,MAAM,WAAW,OAAO"}
|
|
@@ -6,8 +6,8 @@ import { Menu, MenuContent, MenuItem, MenuTrigger, Popover, PopoverContent, Popo
|
|
|
6
6
|
import { Input, Textarea } from "../../ui/input.js";
|
|
7
7
|
import { LinkPopoverBody } from "../link.js";
|
|
8
8
|
import { TableEditor } from "../table/table-editor.js";
|
|
9
|
-
import { ImageDetails, VideoPreview } from "../media.js";
|
|
10
9
|
import { CALLOUT_TONES, placeCaret } from "./dom.js";
|
|
10
|
+
import { ImageDetails, VideoPreview } from "../media.js";
|
|
11
11
|
import { ArticleActions, ArticleCard, ArticleForm, ArticlePanel, articleCardKeyDown, useArticleOpen } from "./article-shell.js";
|
|
12
12
|
import { EmbedBlock } from "./embed.js";
|
|
13
13
|
import { GalleryBlock } from "./gallery.js";
|
|
@@ -8,7 +8,8 @@ type Opened = {
|
|
|
8
8
|
html: string;
|
|
9
9
|
} | {
|
|
10
10
|
ok: false;
|
|
11
|
-
reason: string;
|
|
11
|
+
reason: string; /** the HTML the codec read, when it could: what a held field shows */
|
|
12
|
+
html?: string;
|
|
12
13
|
};
|
|
13
14
|
/**
|
|
14
15
|
* Open a stored value: read it, then prove the editor carries it unchanged (load → serialize → write === stored).
|
|
@@ -5,10 +5,11 @@ import { Tooltip } from "../../ui/overlay.js";
|
|
|
5
5
|
import { FieldCommentRequest } from "../../engine/field-shell.js";
|
|
6
6
|
import { Textarea } from "../../ui/input.js";
|
|
7
7
|
import { resolveFrames } from "../../lib/frames.js";
|
|
8
|
+
import { editorRoundTrip } from "./dom.js";
|
|
9
|
+
import { HeldValue } from "../../engine/held.js";
|
|
8
10
|
import { LegacyFallback } from "../../engine/kit-field.js";
|
|
9
11
|
import { TEXT_FOCUS } from "../text.js";
|
|
10
12
|
import { UnknownValueNote } from "../unknown-value.js";
|
|
11
|
-
import { editorRoundTrip } from "./dom.js";
|
|
12
13
|
import { RichTextEditor } from "./editor.js";
|
|
13
14
|
import { paragraphsHtml, plainParagraphs, usePlainRichText } from "./plain.js";
|
|
14
15
|
import * as React from "react";
|
|
@@ -27,8 +28,9 @@ import { IconArrowsMaximize } from "@tabler/icons-react";
|
|
|
27
28
|
* - read: stored value → the HTML the editor opens on (+ what the field accepts)
|
|
28
29
|
* - write: edited HTML → the stored value, in the surface's own shape; a write that would drop something is refused,
|
|
29
30
|
* named, and nothing is stored
|
|
30
|
-
* - probe: a value the editor cannot carry unchanged (open → no edit → write ≠ stored) is not opened here at all:
|
|
31
|
-
*
|
|
31
|
+
* - probe: a value the editor cannot carry unchanged (open → no edit → write ≠ stored) is not opened here at all: it
|
|
32
|
+
* is HELD (read-only, its HTML shown, the reason above it; kit 3.2.0), or, while the host still provides
|
|
33
|
+
* KitServices.LegacyControl (removed in 4.0.0), the host's own control edits it. Opening never writes.
|
|
32
34
|
*/
|
|
33
35
|
var openKey = null;
|
|
34
36
|
var subs = /* @__PURE__ */ new Set();
|
|
@@ -81,23 +83,27 @@ function openValue(codec, value, at) {
|
|
|
81
83
|
}
|
|
82
84
|
if (holdsPullQuote(read.seed) && (!/data-rt="pullquote"/.test(read.html) || !read.features.includes("pullquote"))) return {
|
|
83
85
|
ok: false,
|
|
84
|
-
reason: "it holds a pull quote, which the standard editor edits"
|
|
86
|
+
reason: "it holds a pull quote, which the standard editor edits",
|
|
87
|
+
html: read.html
|
|
85
88
|
};
|
|
86
89
|
const html = editorRoundTrip(read.html);
|
|
87
90
|
try {
|
|
88
91
|
const back = codec.write(html, at, value);
|
|
89
92
|
if (back.losses.length) return {
|
|
90
93
|
ok: false,
|
|
91
|
-
reason: `this editor would drop ${back.losses.join(", ")}
|
|
94
|
+
reason: `this editor would drop ${back.losses.join(", ")}`,
|
|
95
|
+
html: read.html
|
|
92
96
|
};
|
|
93
97
|
if (!codec.same(back.value, read.seed)) return {
|
|
94
98
|
ok: false,
|
|
95
|
-
reason: "it holds formatting this editor cannot keep"
|
|
99
|
+
reason: "it holds formatting this editor cannot keep",
|
|
100
|
+
html: read.html
|
|
96
101
|
};
|
|
97
102
|
} catch (err) {
|
|
98
103
|
return {
|
|
99
104
|
ok: false,
|
|
100
|
-
reason: `the text could not be checked (${err instanceof Error ? err.message : String(err)})
|
|
105
|
+
reason: `the text could not be checked (${err instanceof Error ? err.message : String(err)})`,
|
|
106
|
+
html: read.html
|
|
101
107
|
};
|
|
102
108
|
}
|
|
103
109
|
return {
|
|
@@ -125,7 +131,7 @@ function CodecRichText({ codec, field, value, onChange, readOnly, path, id, inva
|
|
|
125
131
|
field,
|
|
126
132
|
path
|
|
127
133
|
}), [field, path]);
|
|
128
|
-
const { useInsertableComponents } = useKitServices();
|
|
134
|
+
const { useInsertableComponents, LegacyControl } = useKitServices();
|
|
129
135
|
const insertable = useInsertableComponents?.(at);
|
|
130
136
|
const mine = React.useRef(null);
|
|
131
137
|
const [refusal, setRefusal] = React.useState(null);
|
|
@@ -152,6 +158,13 @@ function CodecRichText({ codec, field, value, onChange, readOnly, path, id, inva
|
|
|
152
158
|
setHandedOff(docKey, !opened.ok);
|
|
153
159
|
if (!opened.ok && openKey === docKey) setFullEditor(null);
|
|
154
160
|
}, [docKey, opened.ok]);
|
|
161
|
+
if (!opened.ok && !LegacyControl) return /* @__PURE__ */ jsx(HeldValue, {
|
|
162
|
+
field,
|
|
163
|
+
value,
|
|
164
|
+
id,
|
|
165
|
+
reason: opened.reason,
|
|
166
|
+
html: opened.html
|
|
167
|
+
});
|
|
155
168
|
if (!opened.ok) return /* @__PURE__ */ jsxs("div", {
|
|
156
169
|
className: "flex min-w-0 flex-col gap-1.5",
|
|
157
170
|
children: [/* @__PURE__ */ jsxs("p", {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"control.js","names":[],"sources":["../../../src/controls/rich-text/control.tsx"],"sourcesContent":["/**\n * Rich text field (V2 HEAD controls/richtext.tsx, CPO D49).\n * - The editor stays in place: the document variant is the full editor in the column, the panel variant (inspector)\n * the same editor height-capped.\n * - Expanding (the toolbar's expand button, ⌘↵, or the expand icon in the field's label row at rest) opens the shared\n * ExpandedEditorModal: breadcrumb \"Section › Item › Field\", word count, Done. Esc closes and focus returns.\n *\n * STORAGE. The editor edits HTML; the stored value stays what production stores for the field, through the host's\n * codec (KitServices.richText, see ./codec.ts):\n * - read: stored value → the HTML the editor opens on (+ what the field accepts)\n * - write: edited HTML → the stored value, in the surface's own shape; a write that would drop something is refused,\n * named, and nothing is stored\n * - probe: a value the editor cannot carry unchanged (open → no edit → write ≠ stored) is not opened here at all: the\n * host's own control edits it (LegacyFallback), with the reason above it. Opening never writes.\n */\nimport * as React from \"react\";\nimport { IconArrowsMaximize } from \"@tabler/icons-react\";\nimport { cn } from \"../../lib/cn\";\nimport { useForm, useKitEnv, useKitServices } from \"../../context\";\nimport { resolveFrames } from \"../../lib/frames\";\nimport { pathKey } from \"../../lib/path\";\nimport type { ControlProps } from \"../../types\";\nimport { Tooltip } from \"../../ui/overlay\";\nimport { LegacyFallback } from \"../../engine/kit-field\";\nimport { FieldCommentRequest } from \"../../engine/field-shell\";\nimport type { KitRichTextCodec, RichTextRead } from \"./codec\";\nimport { editorRoundTrip } from \"./dom\";\nimport { RichTextEditor } from \"./editor\";\nimport { paragraphsHtml, plainParagraphs, usePlainRichText } from \"./plain\";\nimport { Textarea } from \"../../ui/input\";\nimport { TEXT_FOCUS } from \"../text\";\nimport { UnknownValueNote } from \"../unknown-value\";\n\n/* ── which rich-text field (docKey) has its full editor open — shared with the label-row action ── */\nlet openKey: string | null = null;\nconst subs = new Set<() => void>();\nexport function setFullEditor(key: string | null) {\n openKey = key;\n subs.forEach((s) => s());\n}\nfunction useFullEditorKey() {\n return React.useSyncExternalStore(\n (cb) => {\n subs.add(cb);\n return () => subs.delete(cb);\n },\n () => openKey,\n () => openKey,\n );\n}\n\n/* ── fields whose value went to the host's own control: the label-row expand button is not theirs to draw ── */\nconst handedOff = new Set<string>();\nfunction setHandedOff(key: string, on: boolean) {\n if (handedOff.has(key) === on) return;\n if (on) handedOff.add(key);\n else handedOff.delete(key);\n subs.forEach((s) => s());\n}\nfunction useHandedOff(key: string) {\n return React.useSyncExternalStore(\n (cb) => {\n subs.add(cb);\n return () => subs.delete(cb);\n },\n () => handedOff.has(key),\n () => handedOff.has(key),\n );\n}\n\n/** The expanded editor's breadcrumb: the form's frames (root › drilled items) and this field. */\nfunction useExpandCrumbs(fieldTitle: string): string[] {\n const form = useForm();\n const env = useKitEnv();\n if (!form) return [env.docTitle, fieldTitle].filter(Boolean) as string[];\n const { frames } = resolveFrames(form.schema, form.value, form.path, form.resolveSchema);\n const titles = frames.filter((f) => f.kind !== \"history\").map((f, i) => (i === 0 ? env.docTitle || f.title : f.title));\n return [...titles, fieldTitle];\n}\n\n/** A stored block array, or the `{ content }` / `{ format, value }` envelope around one, holding a pull quote block. */\nconst holdsPullQuote = (seed: unknown): boolean =>\n Array.isArray(seed)\n ? seed.some((b) => !!b && typeof b === \"object\" && (b as { _type?: unknown })._type === \"pullQuote\")\n : !!seed && typeof seed === \"object\" && holdsPullQuote((seed as { content?: unknown; value?: unknown }).content ?? (seed as { value?: unknown }).value);\n\n/** What the control decided for one stored value. */\ntype Opened =\n | { ok: true; read: RichTextRead; html: string }\n | { ok: false; reason: string };\n\n/**\n * Open a stored value: read it, then prove the editor carries it unchanged (load → serialize → write === stored).\n * A codec that throws, or a value that does not survive, is handed to the host's own control with the reason.\n */\nexport function openValue(codec: KitRichTextCodec, value: unknown, at: Parameters<KitRichTextCodec[\"read\"]>[1]): Opened {\n let read: RichTextRead;\n try {\n read = codec.read(value, at);\n } catch (err) {\n return { ok: false, reason: `the stored text could not be read (${err instanceof Error ? err.message : String(err)})` };\n }\n // a pull quote (V2 D55 article block) opens as the editor's pull-quote island, but only when the codec renders the\n // stored block as its markup in a field that offers it: a codec that renders nothing for it, or a field with no place\n // for one (a single paragraph), would lose it, so the standard editor edits it\n if (holdsPullQuote(read.seed) && (!/data-rt=\"pullquote\"/.test(read.html) || !read.features.includes(\"pullquote\")))\n return { ok: false, reason: \"it holds a pull quote, which the standard editor edits\" };\n // tables and pull quotes are islands (V2 TableBlock, PullQuote); the probe below proves they survive unchanged\n const html = editorRoundTrip(read.html);\n try {\n const back = codec.write(html, at, value);\n if (back.losses.length) return { ok: false, reason: `this editor would drop ${back.losses.join(\", \")}` };\n if (!codec.same(back.value, read.seed)) return { ok: false, reason: \"it holds formatting this editor cannot keep\" };\n } catch (err) {\n return { ok: false, reason: `the text could not be checked (${err instanceof Error ? err.message : String(err)})` };\n }\n return { ok: true, read, html };\n}\n\nexport function RichTextControl(props: ControlProps) {\n const { richText } = useKitServices();\n if (!richText) return <LegacyFallback {...props} />;\n return <CodecRichText codec={richText} {...props} />;\n}\n\nfunction CodecRichText({ codec, field, value, onChange, readOnly, path, id, invalid }: ControlProps & { codec: KitRichTextCodec }) {\n const env = useKitEnv();\n /* GAP-004: with no comments panel (env.onComment), the field's own comments popover takes the selected words */\n const requestComment = React.useContext(FieldCommentRequest);\n const docKey = `${env.docId}:${pathKey(path)}`;\n const open = useFullEditorKey() === docKey;\n const crumbs = useExpandCrumbs(field.title);\n const plainScope = usePlainRichText();\n const at = React.useMemo(() => ({ field, path }), [field, path]);\n // the components this field may embed (More components): a hook with one identity for the form's life, so calling it\n // only when the host provides it keeps the hook order fixed\n const { useInsertableComponents } = useKitServices();\n const insertable = useInsertableComponents?.(at);\n /* our own last write: its value comes back as `value`, and the editor keeps the HTML it emitted (no reload, no probe).\n Compared by content (NEW-RT5): a host hands it back as a new object (the dock re-reads its stored values), and the\n reload that followed replaced the body under an open footnote popover or block form after its first keystroke */\n const mine = React.useRef<{ value: unknown; html: string } | null>(null);\n const [refusal, setRefusal] = React.useState<string | null>(null);\n const opened = React.useMemo<Opened>(() => {\n if (mine.current && (mine.current.value === value || codec.same(mine.current.value, value))) {\n try {\n return { ok: true, read: codec.read(value, at), html: mine.current.html };\n } catch {\n /* judged afresh below, which names the failure */\n }\n }\n return openValue(codec, value, at);\n // `at` changes identity with the field object; the field's content is what matters\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [codec, value, JSON.stringify(field), pathKey(path)]);\n\n // close when this field goes away (block deselected, drilled elsewhere)\n React.useEffect(\n () => () => {\n if (openKey === docKey) setFullEditor(null);\n setHandedOff(docKey, false);\n },\n [docKey],\n );\n React.useLayoutEffect(() => {\n setHandedOff(docKey, !opened.ok);\n if (!opened.ok && openKey === docKey) setFullEditor(null);\n }, [docKey, opened.ok]);\n\n if (!opened.ok)\n return (\n <div className=\"flex min-w-0 flex-col gap-1.5\">\n <p role=\"note\" data-slot=\"kit-richtext-handoff\" className=\"rounded-kit-md bg-kit-subtle px-2.5 py-1.5 text-kit-xs text-kit-fg-2\">\n Edited with the standard editor: {opened.reason}.\n </p>\n <LegacyFallback field={field} value={value} onChange={onChange} readOnly={readOnly} path={path} id={id} invalid={invalid} />\n </div>\n );\n\n const { read, html } = opened;\n const write = (next: string) => {\n let res;\n try {\n res = codec.write(next, at, value);\n } catch (err) {\n setRefusal(`Not saved: the text could not be stored (${err instanceof Error ? err.message : String(err)}). Undo the last change with ⌘Z; leaving the field puts back the saved text.`);\n return;\n }\n if (res.losses.length) {\n setRefusal(`Not saved: this field cannot keep ${res.losses.join(\", \")}. Undo the last change with ⌘Z; leaving the field puts back the saved text.`);\n return;\n }\n setRefusal(null);\n if (codec.same(res.value, value)) return;\n mine.current = { value: res.value, html: next };\n onChange(res.value);\n };\n\n // The Values popover (PlainRichTextScope): plain paragraphs are V2's growing textarea (its `text` control), written\n // back through the same codec, one `<p>` per line. Anything richer keeps the editor below.\n const plain = plainScope && !read.losses.length ? plainParagraphs(html) : null;\n if (plain !== null)\n return (\n <div className=\"flex min-w-0 flex-col gap-1.5\">\n <Textarea\n id={id}\n rows={3}\n value={plain}\n readOnly={readOnly}\n aria-invalid={invalid || !!refusal}\n placeholder={field.placeholder}\n onChange={(e) => write(paragraphsHtml(e.target.value))}\n className={cn(TEXT_FOCUS, \"leading-5\")}\n />\n {refusal ? (\n <p role=\"alert\" className=\"text-kit-xs text-kit-danger-fg\">\n {refusal}\n </p>\n ) : null}\n </div>\n );\n\n /* V2 richtext.tsx:57: the editor sits in a plain <div>; the dash-only notes keep the 6px gap as their own margin */\n return (\n <div>\n {read.losses.length ? (\n <p role=\"status\" className=\"mb-1.5 rounded-kit-md bg-kit-warning-soft px-2.5 py-1.5 text-kit-xs text-kit-warning-fg\">\n Saved by an earlier editor. Editing here would drop {read.losses.join(\", \")}. Nothing changes until you edit.\n </p>\n ) : null}\n {read.undeclared?.length && codec.remap ? (\n <div className=\"mb-1.5\">\n <UnknownValueNote\n items={read.undeclared}\n onRemap={(key, to) => onChange(codec.remap!(value, at, key, to))}\n onRemove={(key) => onChange(codec.remap!(value, at, key, null))}\n readOnly={readOnly}\n />\n </div>\n ) : null}\n <RichTextEditor\n value={html}\n onChange={write}\n readOnly={readOnly}\n placeholder={field.placeholder}\n docKey={docKey}\n id={id}\n invalid={invalid || !!refusal}\n features={read.features}\n references={read.references}\n single={read.single}\n allowNewTab={read.newTab}\n components={insertable && !read.single && !readOnly ? insertable : undefined}\n variant={env.variant === \"document\" ? \"document\" : \"panel\"}\n maxHeight={env.variant === \"document\" ? undefined : 320}\n expandCrumbs={crumbs}\n expandedOpen={open}\n onExpandedOpenChange={(o) => setFullEditor(o ? docKey : null)}\n // select words → Comment in the toolbar: the host's comment popover opens on this field, quoting them\n onComment={\n env.onComment ? (quote) => env.onComment?.(path, field, quote) : requestComment ? (quote, around) => requestComment({ quote, ...around }) : undefined\n }\n // the field's popover sits under the field, behind the expanded editor's focus trap: no Comment in there\n commentInPlace={!env.onComment && !!requestComment}\n />\n {refusal ? (\n <p role=\"alert\" className=\"mt-1.5 text-kit-xs text-kit-danger-fg\">\n {refusal}\n </p>\n ) : null}\n </div>\n );\n}\n\n/** Label-row action (at rest): the field's toolbar holds the same button while it's open. */\nfunction readsPlain(codec: KitRichTextCodec, value: unknown, field: ControlProps[\"field\"], path: ControlProps[\"path\"]) {\n try {\n const read = codec.read(value, { field, path });\n return !read.losses.length && plainParagraphs(editorRoundTrip(read.html)) !== null;\n } catch {\n return false; // the control names the failure itself\n }\n}\n\nexport function RichTextExpandAction({ path, field, value }: ControlProps) {\n const env = useKitEnv();\n const { richText } = useKitServices();\n const handed = useHandedOff(`${env.docId}:${pathKey(path)}`);\n const plainScope = usePlainRichText();\n // the host's own control (no codec, or a value handed to it) has its own full-screen button\n if (env.variant === \"document\" || !richText || handed) return null;\n // drawn as a plain textarea (V2's `text` control has no ⤢)\n if (plainScope && readsPlain(richText, value, field, path)) return null;\n return (\n <Tooltip content=\"Expand editor\" shortcut=\"⌘↵\">\n <button\n type=\"button\"\n aria-label={`Expand ${field.title}`}\n onClick={() => setFullEditor(`${env.docId}:${pathKey(path)}`)}\n className={cn(\n \"-my-0.5 hidden size-6 items-center justify-center rounded-kit-md text-kit-fg-3 hover:bg-kit-hover hover:text-kit-fg\",\n \"group-hover/field:inline-flex group-focus-within/field:!hidden [@media(pointer:coarse)]:inline-flex\",\n )}\n >\n <IconArrowsMaximize className=\"size-3.5\" stroke={1.5} aria-hidden />\n </button>\n </Tooltip>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,IAAI,UAAyB;AAC7B,IAAM,uBAAO,IAAI,IAAgB;AACjC,SAAgB,cAAc,KAAoB;CAChD,UAAU;CACV,KAAK,SAAS,MAAM,EAAE,CAAC;AACzB;AACA,SAAS,mBAAmB;CAC1B,OAAO,MAAM,sBACV,OAAO;EACN,KAAK,IAAI,EAAE;EACX,aAAa,KAAK,OAAO,EAAE;CAC7B,SACM,eACA,OACR;AACF;AAGA,IAAM,4BAAY,IAAI,IAAY;AAClC,SAAS,aAAa,KAAa,IAAa;CAC9C,IAAI,UAAU,IAAI,GAAG,MAAM,IAAI;CAC/B,IAAI,IAAI,UAAU,IAAI,GAAG;MACpB,UAAU,OAAO,GAAG;CACzB,KAAK,SAAS,MAAM,EAAE,CAAC;AACzB;AACA,SAAS,aAAa,KAAa;CACjC,OAAO,MAAM,sBACV,OAAO;EACN,KAAK,IAAI,EAAE;EACX,aAAa,KAAK,OAAO,EAAE;CAC7B,SACM,UAAU,IAAI,GAAG,SACjB,UAAU,IAAI,GAAG,CACzB;AACF;;AAGA,SAAS,gBAAgB,YAA8B;CACrD,MAAM,OAAO,QAAQ;CACrB,MAAM,MAAM,UAAU;CACtB,IAAI,CAA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WAAU;GACvB,UAAA;EACA,CAAA,IACD;CACD,EAAA,CAAA;AAET;;AAGA,SAAS,WAAW,OAAyB,OAAgB,OAA8B,MAA4B;CACrH,IAAI;EACF,MAAM,OAAO,MAAM,KAAK,OAAO;GAAE;GAAO;EAAK,CAAC;EAC9C,OAAO,CAAC,KAAK,OAAO,UAAU,gBAAgB,gBAAgB,KAAK,IAAI,CAAC,MAAM;CAChF,QAAQ;EACN,OAAO;CACT;AACF;AAEA,SAAgB,qBAAqB,EAAE,MAAM,OAAO,SAAuB;CACzE,MAAM,MAAM,UAAU;CACtB,MAAM,EAAE,aAAa,eAAe;CACpC,MAAM,SAAS,aAAa,GAAG,IAAI,MAAM,GAAG,QAAQ,IAAI,GAAG;CAC3D,MAAM,aAAa,iBAAiB;CAEpC,IAAI,IAAI,YAAY,cAAc,CAAC,YAAY,QAAQ,OAAO;CAE9D,IAAI,cAAc,WAAW,UAAU,OAAO,OAAO,IAAI,GAAG,OAAO;CACnE,OACE,oBAAC,SAAD;EAAS,SAAQ;EAAgB,UAAS;EACxC,UAAA,oBAAC,UAAD;GACE,MAAK;GACL,cAAY,UAAU,MAAM;GAC5B,eAAe,cAAc,GAAG,IAAI,MAAM,GAAG,QAAQ,IAAI,GAAG;GAC5D,WAAW,GACT,uHACA,qGACF;GAEA,UAAA,oBAAC,oBAAD;IAAoB,WAAU;IAAW,QAAQ;IAAK,eAAA;GAAa,CAAA;EAC7D,CAAA;CACD,CAAA;AAEb"}
|
|
1
|
+
{"version":3,"file":"control.js","names":[],"sources":["../../../src/controls/rich-text/control.tsx"],"sourcesContent":["/**\n * Rich text field (V2 HEAD controls/richtext.tsx, CPO D49).\n * - The editor stays in place: the document variant is the full editor in the column, the panel variant (inspector)\n * the same editor height-capped.\n * - Expanding (the toolbar's expand button, ⌘↵, or the expand icon in the field's label row at rest) opens the shared\n * ExpandedEditorModal: breadcrumb \"Section › Item › Field\", word count, Done. Esc closes and focus returns.\n *\n * STORAGE. The editor edits HTML; the stored value stays what production stores for the field, through the host's\n * codec (KitServices.richText, see ./codec.ts):\n * - read: stored value → the HTML the editor opens on (+ what the field accepts)\n * - write: edited HTML → the stored value, in the surface's own shape; a write that would drop something is refused,\n * named, and nothing is stored\n * - probe: a value the editor cannot carry unchanged (open → no edit → write ≠ stored) is not opened here at all: it\n * is HELD (read-only, its HTML shown, the reason above it; kit 3.2.0), or, while the host still provides\n * KitServices.LegacyControl (removed in 4.0.0), the host's own control edits it. Opening never writes.\n */\nimport * as React from \"react\";\nimport { IconArrowsMaximize } from \"@tabler/icons-react\";\nimport { cn } from \"../../lib/cn\";\nimport { useForm, useKitEnv, useKitServices } from \"../../context\";\nimport { resolveFrames } from \"../../lib/frames\";\nimport { pathKey } from \"../../lib/path\";\nimport type { ControlProps } from \"../../types\";\nimport { Tooltip } from \"../../ui/overlay\";\nimport { LegacyFallback } from \"../../engine/kit-field\";\nimport { HeldValue } from \"../../engine/held\";\nimport { FieldCommentRequest } from \"../../engine/field-shell\";\nimport type { KitRichTextCodec, RichTextRead } from \"./codec\";\nimport { editorRoundTrip } from \"./dom\";\nimport { RichTextEditor } from \"./editor\";\nimport { paragraphsHtml, plainParagraphs, usePlainRichText } from \"./plain\";\nimport { Textarea } from \"../../ui/input\";\nimport { TEXT_FOCUS } from \"../text\";\nimport { UnknownValueNote } from \"../unknown-value\";\n\n/* ── which rich-text field (docKey) has its full editor open — shared with the label-row action ── */\nlet openKey: string | null = null;\nconst subs = new Set<() => void>();\nexport function setFullEditor(key: string | null) {\n openKey = key;\n subs.forEach((s) => s());\n}\nfunction useFullEditorKey() {\n return React.useSyncExternalStore(\n (cb) => {\n subs.add(cb);\n return () => subs.delete(cb);\n },\n () => openKey,\n () => openKey,\n );\n}\n\n/* ── fields whose value went to the host's own control: the label-row expand button is not theirs to draw ── */\nconst handedOff = new Set<string>();\nfunction setHandedOff(key: string, on: boolean) {\n if (handedOff.has(key) === on) return;\n if (on) handedOff.add(key);\n else handedOff.delete(key);\n subs.forEach((s) => s());\n}\nfunction useHandedOff(key: string) {\n return React.useSyncExternalStore(\n (cb) => {\n subs.add(cb);\n return () => subs.delete(cb);\n },\n () => handedOff.has(key),\n () => handedOff.has(key),\n );\n}\n\n/** The expanded editor's breadcrumb: the form's frames (root › drilled items) and this field. */\nfunction useExpandCrumbs(fieldTitle: string): string[] {\n const form = useForm();\n const env = useKitEnv();\n if (!form) return [env.docTitle, fieldTitle].filter(Boolean) as string[];\n const { frames } = resolveFrames(form.schema, form.value, form.path, form.resolveSchema);\n const titles = frames.filter((f) => f.kind !== \"history\").map((f, i) => (i === 0 ? env.docTitle || f.title : f.title));\n return [...titles, fieldTitle];\n}\n\n/** A stored block array, or the `{ content }` / `{ format, value }` envelope around one, holding a pull quote block. */\nconst holdsPullQuote = (seed: unknown): boolean =>\n Array.isArray(seed)\n ? seed.some((b) => !!b && typeof b === \"object\" && (b as { _type?: unknown })._type === \"pullQuote\")\n : !!seed && typeof seed === \"object\" && holdsPullQuote((seed as { content?: unknown; value?: unknown }).content ?? (seed as { value?: unknown }).value);\n\n/** What the control decided for one stored value. */\ntype Opened =\n | { ok: true; read: RichTextRead; html: string }\n | { ok: false; reason: string; /** the HTML the codec read, when it could: what a held field shows */ html?: string };\n\n/**\n * Open a stored value: read it, then prove the editor carries it unchanged (load → serialize → write === stored).\n * A codec that throws, or a value that does not survive, is handed to the host's own control with the reason.\n */\nexport function openValue(codec: KitRichTextCodec, value: unknown, at: Parameters<KitRichTextCodec[\"read\"]>[1]): Opened {\n let read: RichTextRead;\n try {\n read = codec.read(value, at);\n } catch (err) {\n return { ok: false, reason: `the stored text could not be read (${err instanceof Error ? err.message : String(err)})` };\n }\n // a pull quote (V2 D55 article block) opens as the editor's pull-quote island, but only when the codec renders the\n // stored block as its markup in a field that offers it: a codec that renders nothing for it, or a field with no place\n // for one (a single paragraph), would lose it, so the standard editor edits it\n if (holdsPullQuote(read.seed) && (!/data-rt=\"pullquote\"/.test(read.html) || !read.features.includes(\"pullquote\")))\n return { ok: false, reason: \"it holds a pull quote, which the standard editor edits\", html: read.html };\n // tables and pull quotes are islands (V2 TableBlock, PullQuote); the probe below proves they survive unchanged\n const html = editorRoundTrip(read.html);\n try {\n const back = codec.write(html, at, value);\n if (back.losses.length) return { ok: false, reason: `this editor would drop ${back.losses.join(\", \")}`, html: read.html };\n if (!codec.same(back.value, read.seed)) return { ok: false, reason: \"it holds formatting this editor cannot keep\", html: read.html };\n } catch (err) {\n return { ok: false, reason: `the text could not be checked (${err instanceof Error ? err.message : String(err)})`, html: read.html };\n }\n return { ok: true, read, html };\n}\n\nexport function RichTextControl(props: ControlProps) {\n const { richText } = useKitServices();\n if (!richText) return <LegacyFallback {...props} />;\n return <CodecRichText codec={richText} {...props} />;\n}\n\nfunction CodecRichText({ codec, field, value, onChange, readOnly, path, id, invalid }: ControlProps & { codec: KitRichTextCodec }) {\n const env = useKitEnv();\n /* GAP-004: with no comments panel (env.onComment), the field's own comments popover takes the selected words */\n const requestComment = React.useContext(FieldCommentRequest);\n const docKey = `${env.docId}:${pathKey(path)}`;\n const open = useFullEditorKey() === docKey;\n const crumbs = useExpandCrumbs(field.title);\n const plainScope = usePlainRichText();\n const at = React.useMemo(() => ({ field, path }), [field, path]);\n // the components this field may embed (More components): a hook with one identity for the form's life, so calling it\n // only when the host provides it keeps the hook order fixed\n const { useInsertableComponents, LegacyControl } = useKitServices();\n const insertable = useInsertableComponents?.(at);\n /* our own last write: its value comes back as `value`, and the editor keeps the HTML it emitted (no reload, no probe).\n Compared by content (NEW-RT5): a host hands it back as a new object (the dock re-reads its stored values), and the\n reload that followed replaced the body under an open footnote popover or block form after its first keystroke */\n const mine = React.useRef<{ value: unknown; html: string } | null>(null);\n const [refusal, setRefusal] = React.useState<string | null>(null);\n const opened = React.useMemo<Opened>(() => {\n if (mine.current && (mine.current.value === value || codec.same(mine.current.value, value))) {\n try {\n return { ok: true, read: codec.read(value, at), html: mine.current.html };\n } catch {\n /* judged afresh below, which names the failure */\n }\n }\n return openValue(codec, value, at);\n // `at` changes identity with the field object; the field's content is what matters\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [codec, value, JSON.stringify(field), pathKey(path)]);\n\n // close when this field goes away (block deselected, drilled elsewhere)\n React.useEffect(\n () => () => {\n if (openKey === docKey) setFullEditor(null);\n setHandedOff(docKey, false);\n },\n [docKey],\n );\n React.useLayoutEffect(() => {\n setHandedOff(docKey, !opened.ok);\n if (!opened.ok && openKey === docKey) setFullEditor(null);\n }, [docKey, opened.ok]);\n\n // kit 3.2.0: with no host control to hand it to, the value is held (shown read-only with the reason, never written)\n if (!opened.ok && !LegacyControl) return <HeldValue field={field} value={value} id={id} reason={opened.reason} html={opened.html} />;\n if (!opened.ok)\n return (\n <div className=\"flex min-w-0 flex-col gap-1.5\">\n <p role=\"note\" data-slot=\"kit-richtext-handoff\" className=\"rounded-kit-md bg-kit-subtle px-2.5 py-1.5 text-kit-xs text-kit-fg-2\">\n Edited with the standard editor: {opened.reason}.\n </p>\n <LegacyFallback field={field} value={value} onChange={onChange} readOnly={readOnly} path={path} id={id} invalid={invalid} />\n </div>\n );\n\n const { read, html } = opened;\n const write = (next: string) => {\n let res;\n try {\n res = codec.write(next, at, value);\n } catch (err) {\n setRefusal(`Not saved: the text could not be stored (${err instanceof Error ? err.message : String(err)}). Undo the last change with ⌘Z; leaving the field puts back the saved text.`);\n return;\n }\n if (res.losses.length) {\n setRefusal(`Not saved: this field cannot keep ${res.losses.join(\", \")}. Undo the last change with ⌘Z; leaving the field puts back the saved text.`);\n return;\n }\n setRefusal(null);\n if (codec.same(res.value, value)) return;\n mine.current = { value: res.value, html: next };\n onChange(res.value);\n };\n\n // The Values popover (PlainRichTextScope): plain paragraphs are V2's growing textarea (its `text` control), written\n // back through the same codec, one `<p>` per line. Anything richer keeps the editor below.\n const plain = plainScope && !read.losses.length ? plainParagraphs(html) : null;\n if (plain !== null)\n return (\n <div className=\"flex min-w-0 flex-col gap-1.5\">\n <Textarea\n id={id}\n rows={3}\n value={plain}\n readOnly={readOnly}\n aria-invalid={invalid || !!refusal}\n placeholder={field.placeholder}\n onChange={(e) => write(paragraphsHtml(e.target.value))}\n className={cn(TEXT_FOCUS, \"leading-5\")}\n />\n {refusal ? (\n <p role=\"alert\" className=\"text-kit-xs text-kit-danger-fg\">\n {refusal}\n </p>\n ) : null}\n </div>\n );\n\n /* V2 richtext.tsx:57: the editor sits in a plain <div>; the dash-only notes keep the 6px gap as their own margin */\n return (\n <div>\n {read.losses.length ? (\n <p role=\"status\" className=\"mb-1.5 rounded-kit-md bg-kit-warning-soft px-2.5 py-1.5 text-kit-xs text-kit-warning-fg\">\n Saved by an earlier editor. Editing here would drop {read.losses.join(\", \")}. Nothing changes until you edit.\n </p>\n ) : null}\n {read.undeclared?.length && codec.remap ? (\n <div className=\"mb-1.5\">\n <UnknownValueNote\n items={read.undeclared}\n onRemap={(key, to) => onChange(codec.remap!(value, at, key, to))}\n onRemove={(key) => onChange(codec.remap!(value, at, key, null))}\n readOnly={readOnly}\n />\n </div>\n ) : null}\n <RichTextEditor\n value={html}\n onChange={write}\n readOnly={readOnly}\n placeholder={field.placeholder}\n docKey={docKey}\n id={id}\n invalid={invalid || !!refusal}\n features={read.features}\n references={read.references}\n single={read.single}\n allowNewTab={read.newTab}\n components={insertable && !read.single && !readOnly ? insertable : undefined}\n variant={env.variant === \"document\" ? \"document\" : \"panel\"}\n maxHeight={env.variant === \"document\" ? undefined : 320}\n expandCrumbs={crumbs}\n expandedOpen={open}\n onExpandedOpenChange={(o) => setFullEditor(o ? docKey : null)}\n // select words → Comment in the toolbar: the host's comment popover opens on this field, quoting them\n onComment={\n env.onComment ? (quote) => env.onComment?.(path, field, quote) : requestComment ? (quote, around) => requestComment({ quote, ...around }) : undefined\n }\n // the field's popover sits under the field, behind the expanded editor's focus trap: no Comment in there\n commentInPlace={!env.onComment && !!requestComment}\n />\n {refusal ? (\n <p role=\"alert\" className=\"mt-1.5 text-kit-xs text-kit-danger-fg\">\n {refusal}\n </p>\n ) : null}\n </div>\n );\n}\n\n/** Label-row action (at rest): the field's toolbar holds the same button while it's open. */\nfunction readsPlain(codec: KitRichTextCodec, value: unknown, field: ControlProps[\"field\"], path: ControlProps[\"path\"]) {\n try {\n const read = codec.read(value, { field, path });\n return !read.losses.length && plainParagraphs(editorRoundTrip(read.html)) !== null;\n } catch {\n return false; // the control names the failure itself\n }\n}\n\nexport function RichTextExpandAction({ path, field, value }: ControlProps) {\n const env = useKitEnv();\n const { richText } = useKitServices();\n const handed = useHandedOff(`${env.docId}:${pathKey(path)}`);\n const plainScope = usePlainRichText();\n // the host's own control (no codec, or a value handed to it) has its own full-screen button\n if (env.variant === \"document\" || !richText || handed) return null;\n // drawn as a plain textarea (V2's `text` control has no ⤢)\n if (plainScope && readsPlain(richText, value, field, path)) return null;\n return (\n <Tooltip content=\"Expand editor\" shortcut=\"⌘↵\">\n <button\n type=\"button\"\n aria-label={`Expand ${field.title}`}\n onClick={() => setFullEditor(`${env.docId}:${pathKey(path)}`)}\n className={cn(\n \"-my-0.5 hidden size-6 items-center justify-center rounded-kit-md text-kit-fg-3 hover:bg-kit-hover hover:text-kit-fg\",\n \"group-hover/field:inline-flex group-focus-within/field:!hidden [@media(pointer:coarse)]:inline-flex\",\n )}\n >\n <IconArrowsMaximize className=\"size-3.5\" stroke={1.5} aria-hidden />\n </button>\n </Tooltip>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,IAAI,UAAyB;AAC7B,IAAM,uBAAO,IAAI,IAAgB;AACjC,SAAgB,cAAc,KAAoB;CAChD,UAAU;CACV,KAAK,SAAS,MAAM,EAAE,CAAC;AACzB;AACA,SAAS,mBAAmB;CAC1B,OAAO,MAAM,sBACV,OAAO;EACN,KAAK,IAAI,EAAE;EACX,aAAa,KAAK,OAAO,EAAE;CAC7B,SACM,eACA,OACR;AACF;AAGA,IAAM,4BAAY,IAAI,IAAY;AAClC,SAAS,aAAa,KAAa,IAAa;CAC9C,IAAI,UAAU,IA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AQ;EAAgB,UAAS;EACxC,UAAA,oBAAC,UAAD;GACE,MAAK;GACL,cAAY,UAAU,MAAM;GAC5B,eAAe,cAAc,GAAG,IAAI,MAAM,GAAG,QAAQ,IAAI,GAAG;GAC5D,WAAW,GACT,uHACA,qGACF;GAEA,UAAA,oBAAC,oBAAD;IAAoB,WAAU;IAAW,QAAQ;IAAK,eAAA;GAAa,CAAA;EAC7D,CAAA;CACD,CAAA;AAEb"}
|
|
@@ -6,8 +6,8 @@ import { Menu, MenuContent, MenuItem, MenuRadioGroup, MenuRadioItem, MenuSeparat
|
|
|
6
6
|
import { Input, Textarea } from "../../ui/input.js";
|
|
7
7
|
import { LinkPopoverBody } from "../link.js";
|
|
8
8
|
import { ExpandedEditorModal } from "../../ui/expanded-editor-modal.js";
|
|
9
|
-
import { COMPONENT_INSERT_TOAST } from "../component-services.js";
|
|
10
9
|
import { closestBlock, createIsland, defaultModel, editingHost, esc, hydrate, isEmptyHtml, ownsMenu, placeCaret, rangeRect, rid, sanitize, serialize, textBeforeCaret, topBlock } from "./dom.js";
|
|
10
|
+
import { COMPONENT_INSERT_TOAST } from "../component-services.js";
|
|
11
11
|
import { eventKey } from "../../lib/key-event.js";
|
|
12
12
|
import { ALL_FEATURES } from "./codec.js";
|
|
13
13
|
import { createOutlineStore, outlineOf } from "./toc.js";
|
package/dist/engine/frame.js
CHANGED
|
@@ -112,7 +112,7 @@ function FrameView({ frame, parentTitle }) {
|
|
|
112
112
|
title: frame.title
|
|
113
113
|
}), TableFrame ? /* @__PURE__ */ jsx(TableFrame, { frame }) : /* @__PURE__ */ jsx("p", {
|
|
114
114
|
role: "note",
|
|
115
|
-
"data-kit-
|
|
115
|
+
"data-kit-note": "table",
|
|
116
116
|
className: "text-kit-sm text-kit-fg-3",
|
|
117
117
|
children: "This table's rows and columns are edited in the table itself."
|
|
118
118
|
})]
|
package/dist/engine/frame.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frame.js","names":[],"sources":["../../src/engine/frame.tsx"],"sourcesContent":["/**\n * FrameView — what the panel shows for the current breadcrumb: the root fields, a drilled object / array item /\n * slot block (with \"2 of 4\" stepper, variant switcher and per-slot layout settings), the one button screen,\n * or a field's history as a stacked panel. Port of V2 engine/frame.tsx.\n *\n * FrameStage + useFrameNavigation — V2 schema-form's drill-in stage (direction-aware slide, scroll memory per frame,\n * focus on the entering frame, Esc / ⌥↑↓). Exported here so SchemaForm wires them without re-deriving the motion.\n *\n * FrameSlots — the frame draws other lanes' pieces (FieldList / FieldSection from grouping, ButtonScreen from link,\n * TableFrame from table). They arrive through context so this file never imports a module that does not exist yet;\n * a missing slot falls back to a plain field list (FieldList), the raw value (ButtonScreen, through\n * FallbackControl), a named note (TableFrame) or nothing (FieldSection). SchemaForm always hands ButtonScreen and TableFrame.\n */\nimport * as React from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"framer-motion\";\nimport { IconArrowDown, IconArrowUp, IconCopy, IconDots, IconTrash } from \"@tabler/icons-react\";\nimport { IconButton } from \"../ui/button\";\nimport { Menu, MenuContent, MenuItem, MenuSeparator, MenuTrigger, Tooltip } from \"../ui/overlay\";\nimport { Segmented } from \"../ui/controls\";\nimport { fitsSegmented } from \"../ui/choice-switch\";\nimport { Select } from \"../ui/select\";\nimport { resolveFieldAccess, useForm, useKitEnv, useKitServices } from \"../context\";\nimport { cn } from \"../lib/cn\";\nimport { HISTORY_SEGMENT, type FieldGroup, type FieldPath, type FieldSchema, type Fieldset } from \"../schema/types\";\nimport type { Frame } from \"../lib/frames\";\nimport { frameKeyOf, isObj, newKey } from \"../lib/path\";\nimport { condCtx, isHidden, itemSchemaFor, previewOf } from \"../lib/schema\";\nimport { Thumb } from \"./bits\";\nimport { FallbackControl, KitField } from \"./kit-field\";\n\n/* ── Slots (other lanes) ───────────────────────────────────────────── */\nexport interface FrameFieldListProps {\n fields: FieldSchema[];\n fieldsets?: Fieldset[];\n groups?: FieldGroup[];\n basePath: FieldPath;\n memoryKey: string;\n}\nexport interface FrameSlots {\n /** grouping lane: engine/field-list.tsx `FieldList` */\n FieldList?: React.ComponentType<FrameFieldListProps>;\n /** grouping lane: engine/grouping.tsx `FieldSection` (the slot-settings section of a slot block) */\n FieldSection?: React.ComponentType<{ title: string; description?: string; collapsible?: boolean; children: React.ReactNode }>;\n /** link lane: controls/link.tsx `ButtonScreen` + `normLink` (the \"button\" frame) */\n ButtonScreen?: React.ComponentType<{ value: unknown; onChange: (v: unknown) => void; title: string; readOnly?: boolean }>;\n normLink?: (v: unknown) => { label?: string };\n /** table lane: controls/table.tsx `TableFrame` (tableRow / tableColumn frames) */\n TableFrame?: React.ComponentType<{ frame: Frame }>;\n}\nconst SlotsCtx = React.createContext<FrameSlots>({});\nexport const FrameSlotsProvider = SlotsCtx.Provider;\nexport const useFrameSlots = () => React.useContext(SlotsCtx);\n\n/** Stand-in until the grouping lane's FieldList lands: the frame's visible fields in schema order. */\nfunction PlainFieldList({ fields, basePath }: FrameFieldListProps) {\n const form = useForm()!;\n const raw = basePath.length ? form.getAt(basePath) : form.value;\n const parent = isObj(raw) ? raw : {};\n const cc = condCtx(form, basePath);\n const shown = fields.filter((f) => !isHidden(f, parent, cc));\n return (\n <div className=\"flex flex-col gap-5\">\n {shown.map((f) => (\n <div key={f.name} className=\"min-w-0\">\n <KitField field={f} path={[...basePath, f.name]} parent={parent} />\n </div>\n ))}\n {shown.length === 0 ? <p className=\"py-6 text-center text-kit-sm text-kit-fg-3\">No fields here yet.</p> : null}\n </div>\n );\n}\n\n/** A button frame outside SchemaForm (no ButtonScreen slot) edits the button's raw value (FallbackControl), never an empty body. */\nfunction RawButtonScreen({ frame }: { frame: Frame }) {\n const form = useForm()!;\n const id = React.useId();\n const field = frame.field ?? { name: String(frame.path.at(-1) ?? \"button\"), title: frame.title, type: \"button\" as const };\n return <FallbackControl field={field} value={form.getAt(frame.path)} onChange={(n) => form.setAt(frame.path, n)} id={id} path={frame.path} />;\n}\n\n/** The button frame: header (the button's label) + the kit ButtonScreen, read-only when the lens can't edit the field. */\nfunction ButtonFrame({ frame, parentTitle }: { frame: Frame; parentTitle?: string }) {\n const form = useForm()!;\n const env = useKitEnv();\n const slots = useFrameSlots();\n const v = form.getAt(frame.path);\n const ButtonScreen = slots.ButtonScreen;\n const readOnly = frame.field ? resolveFieldAccess(frame.field, env).readOnly : !!env.readOnly;\n return (\n <div className=\"flex flex-col gap-5\">\n <FrameHeader frame={frame} context={parentTitle ? `${frame.title} in ${parentTitle}` : frame.title} title={slots.normLink?.(v).label || frame.title} />\n {ButtonScreen ? <ButtonScreen value={v} onChange={(n) => form.setAt(frame.path, n)} title={frame.title} readOnly={readOnly} /> : <RawButtonScreen frame={frame} />}\n </div>\n );\n}\n\n/* ── FrameView ─────────────────────────────────────────────────────── */\nexport function FrameView({ frame, parentTitle }: { frame: Frame; parentTitle?: string }) {\n const form = useForm()!;\n const slots = useFrameSlots();\n const FieldList = slots.FieldList ?? PlainFieldList;\n if (frame.kind === \"history\") return null; // D61: a field's history is the host's one History panel (onFieldHistory)\n if (frame.kind === \"button\") return <ButtonFrame frame={frame} parentTitle={parentTitle} />;\n // D50: a table row or column drills exactly like an array item: the same header (title, n of N, ↑ ↓ ⋯), its cells below\n if (frame.kind === \"tableRow\" || frame.kind === \"tableColumn\") {\n const it = frame.item!;\n const TableFrame = slots.TableFrame;\n return (\n <div className=\"flex flex-col gap-5\">\n <FrameHeader frame={frame} context={`${it.itemSchema?.title} ${it.index + 1} of ${it.count} in ${frame.field?.title ?? \"the table\"}`} title={frame.title} />\n {TableFrame ? (\n <TableFrame frame={frame} />\n ) : (\n /* Only the kit table control opens a row or column frame; until it is ported the table is the host's control,\n which edits rows in place. A path restored into one says so instead of drawing an empty body. */\n <p role=\"note\" data-kit-legacy=\"table\" className=\"text-kit-sm text-kit-fg-3\">\n This table's rows and columns are edited in the table itself.\n </p>\n )}\n </div>\n );\n }\n if (frame.kind === \"root\") return <FieldList fields={frame.fields} fieldsets={frame.fieldsets} groups={frame.groups} basePath={[]} memoryKey=\"root\" />;\n const it = frame.item;\n const block = it?.block;\n const variants = block?.variants ?? [];\n const raw = form.getAt(frame.path);\n const cur = isObj(raw) ? raw : {};\n const FieldSection = slots.FieldSection;\n return (\n <div className=\"flex flex-col gap-5\">\n <FrameHeader frame={frame} context={frameContext(frame, parentTitle)} title={frame.title} />\n {block && variants.length > 1 ? (\n <div className=\"flex flex-col gap-1.5\">\n <span className=\"text-kit-sm font-medium text-kit-fg-2\">Layout</span>\n {fitsSegmented(variants.map((v) => v.name)) ? (\n <Segmented\n aria-label=\"Layout\"\n value={String(cur._variant ?? variants[0].id)}\n onChange={(v) => form.setAt([...frame.path, \"_variant\"], v)}\n items={variants.map((v) => ({ value: v.id, label: v.name }))}\n className=\"w-full [&>button]:flex-1\"\n />\n ) : (\n <Select\n aria-label=\"Variant\"\n value={String(cur._variant ?? variants[0].id)}\n onValueChange={(v) => form.setAt([...frame.path, \"_variant\"], v)}\n options={variants.map((v) => ({ value: v.id, label: v.name, description: v.description }))}\n />\n )}\n </div>\n ) : null}\n <FieldList fields={frame.fields} fieldsets={frame.fieldsets} groups={frame.groups} basePath={frame.path} memoryKey={`f:${frame.kind}:${it?.block?.name ?? it?.itemSchema?.name ?? frame.field?.name ?? \"\"}`} />\n {it?.slotField?.slotSettings?.length && FieldSection ? (\n <FieldSection title={`Layout in ${it.slotField.title.toLowerCase()}`} description=\"How this block sits in its parent. The block's own content is above.\" collapsible={false}>\n <FieldList fields={it.slotField.slotSettings} basePath={[...frame.path, \"_settings\"]} memoryKey={`slotset:${it.slotField.name}`} />\n </FieldSection>\n ) : null}\n </div>\n );\n}\n\n/**\n * The context line under a drilled frame's title: \"Tier 1 of 3 in Tiers\" for an item (the item noun is the item\n * schema's title, which the adapter reads back from prod `ui.itemLabel`), \"Address in Author\" for an object.\n */\nexport function frameContext(frame: Frame, parentTitle?: string): string {\n const it = frame.item;\n if (it) {\n const noun = (frame.kind === \"block\" ? it.block?.title : it.itemSchema?.title) ?? \"Item\";\n const owner = (frame.kind === \"block\" ? it.slotField?.title : frame.field?.title) ?? \"the list\";\n return `${noun} ${it.index + 1} of ${it.count} in ${owner}`;\n }\n return parentTitle ? `${frame.field?.title ?? \"Group\"} in ${parentTitle}` : \"Group\";\n}\n\n/**\n * CPO D43 — the drilled frame's header answers \"what am I editing, and where does it live?\":\n * [media?] Starter [↑] [↓] [⋯]\n * Tier 1 of 3 in Tiers\n * The big title lives HERE only; the breadcrumb above is the path (its current crumb is small, D38). Prev / next are\n * labelled icon buttons whose tooltips name the sibling (\"Previous tier: Starter\"). No eyebrow, no duplicate counter.\n * Title 14/24 semibold (owner call). The native title= on the truncating h2 is V2 parity (kit-engine deviation from\n * the dashboard's no-title rule, see run ledger #32).\n */\nexport function FrameHeader({ frame, context, title }: { frame: Frame; context: string; title: string }) {\n const form = useForm()!;\n const { toast } = useKitServices();\n const it = frame.item;\n const media = it ? previewOf(it.block ?? it.itemSchema, form.getAt(frame.path), it.index).media : undefined;\n const step = (d: -1 | 1) => {\n if (!it) return;\n const n = it.index + d;\n if (n < 0 || n >= it.count) return;\n form.navigate([...it.arrayPath, n]);\n };\n const listRaw = it ? form.getAt(it.arrayPath) : undefined;\n const list = Array.isArray(listRaw) ? listRaw : [];\n const noun = (it?.block?.title ?? it?.itemSchema?.title ?? \"item\").toLowerCase();\n /* NEW-Q49-POLYSIBLING: in a mixed list a neighbour is named and previewed by its OWN type, not the current item's\n (a photo post's URL read as \"Next store review: https://…\") */\n const schemaAt = (i: number) => {\n const v = list[i];\n if (frame.kind === \"item\" && frame.field) return itemSchemaFor(frame.field, v) ?? it?.itemSchema;\n if (frame.kind === \"block\") return (isObj(v) && typeof v._type === \"string\" ? form.resolveSchema?.(v._type) : undefined) ?? it?.block;\n return it?.block ?? it?.itemSchema;\n };\n const nounAt = (i: number) => (it?.titleAt ? noun : (schemaAt(i)?.title ?? \"item\").toLowerCase());\n const sibling = (i: number) =>\n it && i >= 0 && i < it.count ? (it.titleAt ? it.titleAt(i) : previewOf(schemaAt(i), list[i], i, schemaAt(i)?.title).title) : \"\";\n const prev = it ? sibling(it.index - 1) : \"\";\n const next = it ? sibling(it.index + 1) : \"\";\n const prevNoun = it ? nounAt(it.index - 1) : noun;\n const nextNoun = it ? nounAt(it.index + 1) : noun;\n /* NEW-Q22-ROWLIMIT: the list's own bounds hold here as on its row menu (array.tsx): a duplicate past the maximum or a\n remove below the minimum only left a held, unsavable list */\n const bounds = frame.kind === \"item\" || frame.kind === \"block\" ? frame.field?.validation : undefined;\n const atMax = bounds?.max != null && list.length >= bounds.max;\n const atMin = bounds?.min != null && list.length <= bounds.min;\n /* NEW-Q48-ITEMACTIONS: a read-only list (a locked section, a viewer) offers no Duplicate / Remove: the host drops the\n write, so the menu only announced a change that never happened */\n const env = useKitEnv();\n const readOnly = frame.field ? resolveFieldAccess(frame.field, env).readOnly : !!env.readOnly;\n /* Duplicate / Remove move to another frame: the menu must not hand focus back to its trigger in the exiting frame\n (it unmounts, focus would drop to <body>); the stage focuses the entering frame instead */\n const moved = React.useRef(false);\n return (\n <div className=\"flex items-start gap-2.5 outline-none\" data-frame-header tabIndex={-1}>\n {media ? <Thumb media={media} size={36} /> : null}\n <div className=\"min-w-0 flex-1\">\n <h2 className=\"truncate text-kit-base font-semibold leading-6 text-kit-fg\" title={title}>\n {title}\n </h2>\n <p className=\"truncate text-kit-xs leading-4 text-kit-fg-3\">{context}</p>\n </div>\n {it ? (\n <div className=\"-mr-1 flex shrink-0 items-center gap-0.5 pt-0.5\">\n <IconButton\n label={prev ? `Previous ${prevNoun}: ${prev}` : `No previous ${noun}`}\n tooltip={prev ? `Previous ${prevNoun}: ${prev}` : `First ${noun}`}\n size=\"sm\"\n disabled={it.index === 0}\n onClick={() => step(-1)}\n >\n <IconArrowUp stroke={1.5} />\n </IconButton>\n <IconButton\n label={next ? `Next ${nextNoun}: ${next}` : `No next ${noun}`}\n tooltip={next ? `Next ${nextNoun}: ${next}` : `Last ${noun}`}\n size=\"sm\"\n disabled={it.index >= it.count - 1}\n onClick={() => step(1)}\n >\n <IconArrowDown stroke={1.5} />\n </IconButton>\n {readOnly ? null : (\n <Menu>\n <Tooltip content={`${title} actions`}>\n <MenuTrigger\n render={\n <IconButton label={`${title} actions`} tooltip={false} size=\"sm\">\n <IconDots stroke={1.5} />\n </IconButton>\n }\n />\n </Tooltip>\n <MenuContent align=\"end\" className=\"w-48\" finalFocus={() => !moved.current}>\n <MenuItem\n icon={<IconCopy stroke={1.5} />}\n disabled={atMax}\n onClick={() => {\n moved.current = true;\n const copy = isObj(list[it.index]) ? { ...(structuredClone(list[it.index]) as object), _key: newKey() } : list[it.index];\n form.setAt(it.arrayPath, [...list.slice(0, it.index + 1), copy, ...list.slice(it.index + 1)]);\n form.navigate([...it.arrayPath, it.index + 1]);\n toast?.success(\"Duplicated\", { description: \"You're now editing the copy.\" });\n }}\n >\n {atMax ? \"Duplicate · limit reached\" : \"Duplicate\"}\n </MenuItem>\n <MenuSeparator />\n <MenuItem\n danger\n icon={<IconTrash stroke={1.5} />}\n disabled={atMin}\n onClick={() => {\n moved.current = true;\n const prevList = list;\n form.navigate(parentFramePath(it.arrayPath));\n form.setAt(it.arrayPath, list.filter((_, j) => j !== it.index));\n toast?.(`“${title}” removed`, { action: { label: \"Undo\", onClick: () => form.setAt(it.arrayPath, prevList) }, duration: 10_000 });\n }}\n >\n {atMin ? `Remove · at least ${bounds?.min} required` : \"Remove\"}\n </MenuItem>\n </MenuContent>\n </Menu>\n )}\n </div>\n ) : null}\n </div>\n );\n}\n/** The frame that owns an array: drop the array field name (and the item index above it, if any). */\nconst parentFramePath = (arrayPath: FieldPath): FieldPath => arrayPath.slice(0, -1);\n\n/* ── Stage: direction-aware slide, scroll memory, focus, keys (V2 schema-form) ───────────────── */\n/** The title shown as `parentTitle` for the current frame (the root crumb's label for depth 1). */\nexport function parentTitleOf(frames: Frame[], rootLabel: string): string | undefined {\n if (frames.length < 2) return undefined;\n return frames.length === 2 ? rootLabel : frames[frames.length - 2].title;\n}\n\n/** Floating layers (Base UI popups carry these roles); keys and focus coming from one belong to that layer. */\nconst LAYER = \"[role=dialog],[role=menu],[role=listbox]\";\n\n/** Slide direction for a frame change: deeper → 1, shallower → −1, a sibling step → by index. */\nexport function frameDirection(prev: { depth: number; index: number; key: string }, frames: Frame[], key: string): 0 | 1 | -1 {\n if (prev.key === key) return 0;\n const cur = frames[frames.length - 1];\n if (frames.length > prev.depth) return 1;\n if (frames.length < prev.depth) return -1;\n return (cur.item?.index ?? 0) >= prev.index ? 1 : -1;\n}\n\n/**\n * The drill-in stack's behaviour. `root` wraps the form (keys bubble to it), `scroller` is the scrolling element (or\n * null when the host scrolls). Returns the current frame, its key, the slide direction and the form's onKeyDown.\n */\nexport function useFrameNavigation({\n frames,\n navigate,\n root,\n scroller,\n}: {\n frames: Frame[];\n navigate: (path: FieldPath) => void;\n root: React.RefObject<HTMLElement | null>;\n scroller: React.RefObject<HTMLElement | null>;\n}) {\n const current = frames[frames.length - 1];\n const frameKey = frameKeyOf(current.path);\n const prev = React.useRef({ depth: frames.length, index: current.item?.index ?? 0, key: frameKey });\n const dir = frameDirection(prev.current, frames, frameKey);\n const dirRef = React.useRef<number>(1);\n if (dir) dirRef.current = dir;\n\n const scrollMem = React.useRef(new Map<string, number>());\n React.useLayoutEffect(() => {\n const was = prev.current.key;\n if (was === frameKey) return;\n if (scroller.current) scrollMem.current.set(was, scroller.current.scrollTop);\n prev.current = { depth: frames.length, index: current.item?.index ?? 0, key: frameKey };\n const el = scroller.current;\n if (el) el.scrollTop = scrollMem.current.get(frameKey) ?? 0;\n const active = document.activeElement;\n /* a move started from a portalled menu (FrameHeader ⋯ → Duplicate / Remove) leaves focus in that layer, outside root */\n const layer = active && active !== document.body ? active.closest(LAYER) : null;\n const fromLayer = !!layer && !layer.contains(root.current);\n if (root.current && (active === document.body || root.current.contains(active) || fromLayer)) {\n // the exiting frame is still mounted during its exit animation — focus the ENTERING one\n const target = root.current.querySelector<HTMLElement>(`[data-frame-body=\"${CSS.escape(frameKey)}\"]`);\n target?.focus({ preventScroll: true });\n }\n });\n\n const onKeyDown = (e: React.KeyboardEvent) => {\n if (e.defaultPrevented) return;\n const t = e.target as HTMLElement;\n // ignore keys from floating layers opened by this form; a form INSIDE a dialog still handles its own keys\n // (V2 also listed Radix's popper wrapper; Base UI popups carry these roles themselves)\n const layer = t.closest(LAYER);\n if (layer && root.current && !layer.contains(root.current)) return;\n if (e.key === \"Escape\" && frames.length > 1 && !t.isContentEditable) {\n e.preventDefault();\n e.stopPropagation();\n navigate(frames[frames.length - 2].path);\n return;\n }\n const it = current.item;\n if (it && (e.key === \"ArrowUp\" || e.key === \"ArrowDown\")) {\n const typing = t.matches(\"input,textarea,select\") || t.isContentEditable;\n if (e.altKey || (!typing && t.matches(\"[data-frame-body],[data-frame-header]\"))) {\n const n = it.index + (e.key === \"ArrowUp\" ? -1 : 1);\n if (n >= 0 && n < it.count) {\n e.preventDefault();\n navigate([...it.arrayPath, n]);\n }\n }\n }\n };\n\n return { current, frameKey, dir: dirRef.current, onKeyDown };\n}\n\nconst EASE: [number, number, number, number] = [0.22, 1, 0.36, 1];\n\n/**\n * The frame body with V2's slide: 24px along the travel direction + fade, 220ms, ease [0.22, 1, 0.36, 1]; reduced\n * motion keeps only the fade. `before` renders inside the root frame above its fields (the synced-from note).\n */\nexport function FrameStage({\n frames,\n frameKey,\n dir,\n rootLabel,\n variant,\n before,\n review,\n}: {\n frames: Frame[];\n frameKey: string;\n dir: number;\n rootLabel: string;\n variant: \"panel\" | \"document\";\n before?: React.ReactNode;\n /** D61 Review changes is on: the clip leaves 16px on the left for the change bars */\n review?: boolean;\n}) {\n const reduce = useReducedMotion();\n const current = frames[frames.length - 1];\n return (\n // the drill slide is clipped sideways; with Review changes on (D61) the clip leaves 16px on the left for the change bars\n <div className=\"relative\" style={review ? { clipPath: \"inset(-100vh 0 -100vh -16px)\" } : { overflowX: \"clip\" }}>\n <AnimatePresence mode=\"popLayout\" initial={false} custom={dir}>\n <motion.div\n key={frameKey}\n custom={dir}\n variants={{\n enter: (d: number) => ({ x: reduce ? 0 : d * 24, opacity: 0 }),\n center: { x: 0, opacity: 1 },\n exit: (d: number) => ({ x: reduce ? 0 : d * -24, opacity: 0 }),\n }}\n initial=\"enter\"\n animate=\"center\"\n exit=\"exit\"\n transition={{ duration: 0.22, ease: EASE }}\n data-frame-body={frameKey}\n tabIndex={-1}\n className={cn(\"outline-none focus-visible:shadow-none\", variant === \"document\" ? \"py-1\" : \"px-4 py-4\")}\n >\n {current.kind === \"root\" ? before : null}\n <FrameView frame={current} parentTitle={parentTitleOf(frames, rootLabel)} />\n </motion.div>\n </AnimatePresence>\n </div>\n );\n}\n\nexport { HISTORY_SEGMENT };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDA,IAAM,WAAW,MAAM,cAA0B,CAAC,CAAC;AACnD,IAAa,qBAAqB,SAAS;AAC3C,IAAa,sBAAsB,MAAM,WAAW,QAAQ;;AAG5D,SAAS,eAAe,EAAE,QAAQ,YAAiC;CACjE,MAAM,OAAO,QAAQ;CACrB,MAAM,MAAM,SAAS,SAAS,KAAK,MAAM,QAAQ,IAAI,KAAK;CAC1D,MAAM,SAAS,MAAM,GAAG,IAAI,MAAM,CAAC;CACnC,MAAM,KAAK,QAAQ,MAAM,QAAQ;CACjC,MAAM,QAAQ,OAAO,QAAQ,MAAM,CAAC,SAAS,GAAG,QAAQ,EAAE,CAAC;CAC3D,OACE,qBAAC,OAAD;EAAK,WAAU;EAAf,UAAA,CACG,MAAM,KAAK,MACV,oBAAC,OAAD;GAAkB,WAAU;GAC1B,UAAA,oBAAC,UAAD;IAAU,OAAO;IAAG,MAAM,CAAC,GAAG,UAAU,EAAE,IAAI;IAAW;GAAS,CAAA;EAC/D,GAFK,EAAE,IAEP,CACN,GACA,MAAM,WAAW,IAAI,oBAAC,KAAD;GAAG,WAAU;GAA6C,UAAA;EAAsB,CAAA,IAAI,IACvG;;AAET;;AAGA,SAAS,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ACjE;GAjBL,GAAA,QAiBK;EACG,CAAA;CACd,CAAA;AAET"}
|
|
1
|
+
{"version":3,"file":"frame.js","names":[],"sources":["../../src/engine/frame.tsx"],"sourcesContent":["/**\n * FrameView — what the panel shows for the current breadcrumb: the root fields, a drilled object / array item /\n * slot block (with \"2 of 4\" stepper, variant switcher and per-slot layout settings), the one button screen,\n * or a field's history as a stacked panel. Port of V2 engine/frame.tsx.\n *\n * FrameStage + useFrameNavigation — V2 schema-form's drill-in stage (direction-aware slide, scroll memory per frame,\n * focus on the entering frame, Esc / ⌥↑↓). Exported here so SchemaForm wires them without re-deriving the motion.\n *\n * FrameSlots — the frame draws other lanes' pieces (FieldList / FieldSection from grouping, ButtonScreen from link,\n * TableFrame from table). They arrive through context so this file never imports a module that does not exist yet;\n * a missing slot falls back to a plain field list (FieldList), the raw value (ButtonScreen, through\n * FallbackControl), a named note (TableFrame) or nothing (FieldSection). SchemaForm always hands ButtonScreen and TableFrame.\n */\nimport * as React from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"framer-motion\";\nimport { IconArrowDown, IconArrowUp, IconCopy, IconDots, IconTrash } from \"@tabler/icons-react\";\nimport { IconButton } from \"../ui/button\";\nimport { Menu, MenuContent, MenuItem, MenuSeparator, MenuTrigger, Tooltip } from \"../ui/overlay\";\nimport { Segmented } from \"../ui/controls\";\nimport { fitsSegmented } from \"../ui/choice-switch\";\nimport { Select } from \"../ui/select\";\nimport { resolveFieldAccess, useForm, useKitEnv, useKitServices } from \"../context\";\nimport { cn } from \"../lib/cn\";\nimport { HISTORY_SEGMENT, type FieldGroup, type FieldPath, type FieldSchema, type Fieldset } from \"../schema/types\";\nimport type { Frame } from \"../lib/frames\";\nimport { frameKeyOf, isObj, newKey } from \"../lib/path\";\nimport { condCtx, isHidden, itemSchemaFor, previewOf } from \"../lib/schema\";\nimport { Thumb } from \"./bits\";\nimport { FallbackControl, KitField } from \"./kit-field\";\n\n/* ── Slots (other lanes) ───────────────────────────────────────────── */\nexport interface FrameFieldListProps {\n fields: FieldSchema[];\n fieldsets?: Fieldset[];\n groups?: FieldGroup[];\n basePath: FieldPath;\n memoryKey: string;\n}\nexport interface FrameSlots {\n /** grouping lane: engine/field-list.tsx `FieldList` */\n FieldList?: React.ComponentType<FrameFieldListProps>;\n /** grouping lane: engine/grouping.tsx `FieldSection` (the slot-settings section of a slot block) */\n FieldSection?: React.ComponentType<{ title: string; description?: string; collapsible?: boolean; children: React.ReactNode }>;\n /** link lane: controls/link.tsx `ButtonScreen` + `normLink` (the \"button\" frame) */\n ButtonScreen?: React.ComponentType<{ value: unknown; onChange: (v: unknown) => void; title: string; readOnly?: boolean }>;\n normLink?: (v: unknown) => { label?: string };\n /** table lane: controls/table.tsx `TableFrame` (tableRow / tableColumn frames) */\n TableFrame?: React.ComponentType<{ frame: Frame }>;\n}\nconst SlotsCtx = React.createContext<FrameSlots>({});\nexport const FrameSlotsProvider = SlotsCtx.Provider;\nexport const useFrameSlots = () => React.useContext(SlotsCtx);\n\n/** Stand-in until the grouping lane's FieldList lands: the frame's visible fields in schema order. */\nfunction PlainFieldList({ fields, basePath }: FrameFieldListProps) {\n const form = useForm()!;\n const raw = basePath.length ? form.getAt(basePath) : form.value;\n const parent = isObj(raw) ? raw : {};\n const cc = condCtx(form, basePath);\n const shown = fields.filter((f) => !isHidden(f, parent, cc));\n return (\n <div className=\"flex flex-col gap-5\">\n {shown.map((f) => (\n <div key={f.name} className=\"min-w-0\">\n <KitField field={f} path={[...basePath, f.name]} parent={parent} />\n </div>\n ))}\n {shown.length === 0 ? <p className=\"py-6 text-center text-kit-sm text-kit-fg-3\">No fields here yet.</p> : null}\n </div>\n );\n}\n\n/** A button frame outside SchemaForm (no ButtonScreen slot) edits the button's raw value (FallbackControl), never an empty body. */\nfunction RawButtonScreen({ frame }: { frame: Frame }) {\n const form = useForm()!;\n const id = React.useId();\n const field = frame.field ?? { name: String(frame.path.at(-1) ?? \"button\"), title: frame.title, type: \"button\" as const };\n return <FallbackControl field={field} value={form.getAt(frame.path)} onChange={(n) => form.setAt(frame.path, n)} id={id} path={frame.path} />;\n}\n\n/** The button frame: header (the button's label) + the kit ButtonScreen, read-only when the lens can't edit the field. */\nfunction ButtonFrame({ frame, parentTitle }: { frame: Frame; parentTitle?: string }) {\n const form = useForm()!;\n const env = useKitEnv();\n const slots = useFrameSlots();\n const v = form.getAt(frame.path);\n const ButtonScreen = slots.ButtonScreen;\n const readOnly = frame.field ? resolveFieldAccess(frame.field, env).readOnly : !!env.readOnly;\n return (\n <div className=\"flex flex-col gap-5\">\n <FrameHeader frame={frame} context={parentTitle ? `${frame.title} in ${parentTitle}` : frame.title} title={slots.normLink?.(v).label || frame.title} />\n {ButtonScreen ? <ButtonScreen value={v} onChange={(n) => form.setAt(frame.path, n)} title={frame.title} readOnly={readOnly} /> : <RawButtonScreen frame={frame} />}\n </div>\n );\n}\n\n/* ── FrameView ─────────────────────────────────────────────────────── */\nexport function FrameView({ frame, parentTitle }: { frame: Frame; parentTitle?: string }) {\n const form = useForm()!;\n const slots = useFrameSlots();\n const FieldList = slots.FieldList ?? PlainFieldList;\n if (frame.kind === \"history\") return null; // D61: a field's history is the host's one History panel (onFieldHistory)\n if (frame.kind === \"button\") return <ButtonFrame frame={frame} parentTitle={parentTitle} />;\n // D50: a table row or column drills exactly like an array item: the same header (title, n of N, ↑ ↓ ⋯), its cells below\n if (frame.kind === \"tableRow\" || frame.kind === \"tableColumn\") {\n const it = frame.item!;\n const TableFrame = slots.TableFrame;\n return (\n <div className=\"flex flex-col gap-5\">\n <FrameHeader frame={frame} context={`${it.itemSchema?.title} ${it.index + 1} of ${it.count} in ${frame.field?.title ?? \"the table\"}`} title={frame.title} />\n {TableFrame ? (\n <TableFrame frame={frame} />\n ) : (\n /* Only the kit table control opens a row or column frame; until it is ported the table is the host's control,\n which edits rows in place. A path restored into one says so instead of drawing an empty body. */\n <p role=\"note\" data-kit-note=\"table\" className=\"text-kit-sm text-kit-fg-3\">\n This table's rows and columns are edited in the table itself.\n </p>\n )}\n </div>\n );\n }\n if (frame.kind === \"root\") return <FieldList fields={frame.fields} fieldsets={frame.fieldsets} groups={frame.groups} basePath={[]} memoryKey=\"root\" />;\n const it = frame.item;\n const block = it?.block;\n const variants = block?.variants ?? [];\n const raw = form.getAt(frame.path);\n const cur = isObj(raw) ? raw : {};\n const FieldSection = slots.FieldSection;\n return (\n <div className=\"flex flex-col gap-5\">\n <FrameHeader frame={frame} context={frameContext(frame, parentTitle)} title={frame.title} />\n {block && variants.length > 1 ? (\n <div className=\"flex flex-col gap-1.5\">\n <span className=\"text-kit-sm font-medium text-kit-fg-2\">Layout</span>\n {fitsSegmented(variants.map((v) => v.name)) ? (\n <Segmented\n aria-label=\"Layout\"\n value={String(cur._variant ?? variants[0].id)}\n onChange={(v) => form.setAt([...frame.path, \"_variant\"], v)}\n items={variants.map((v) => ({ value: v.id, label: v.name }))}\n className=\"w-full [&>button]:flex-1\"\n />\n ) : (\n <Select\n aria-label=\"Variant\"\n value={String(cur._variant ?? variants[0].id)}\n onValueChange={(v) => form.setAt([...frame.path, \"_variant\"], v)}\n options={variants.map((v) => ({ value: v.id, label: v.name, description: v.description }))}\n />\n )}\n </div>\n ) : null}\n <FieldList fields={frame.fields} fieldsets={frame.fieldsets} groups={frame.groups} basePath={frame.path} memoryKey={`f:${frame.kind}:${it?.block?.name ?? it?.itemSchema?.name ?? frame.field?.name ?? \"\"}`} />\n {it?.slotField?.slotSettings?.length && FieldSection ? (\n <FieldSection title={`Layout in ${it.slotField.title.toLowerCase()}`} description=\"How this block sits in its parent. The block's own content is above.\" collapsible={false}>\n <FieldList fields={it.slotField.slotSettings} basePath={[...frame.path, \"_settings\"]} memoryKey={`slotset:${it.slotField.name}`} />\n </FieldSection>\n ) : null}\n </div>\n );\n}\n\n/**\n * The context line under a drilled frame's title: \"Tier 1 of 3 in Tiers\" for an item (the item noun is the item\n * schema's title, which the adapter reads back from prod `ui.itemLabel`), \"Address in Author\" for an object.\n */\nexport function frameContext(frame: Frame, parentTitle?: string): string {\n const it = frame.item;\n if (it) {\n const noun = (frame.kind === \"block\" ? it.block?.title : it.itemSchema?.title) ?? \"Item\";\n const owner = (frame.kind === \"block\" ? it.slotField?.title : frame.field?.title) ?? \"the list\";\n return `${noun} ${it.index + 1} of ${it.count} in ${owner}`;\n }\n return parentTitle ? `${frame.field?.title ?? \"Group\"} in ${parentTitle}` : \"Group\";\n}\n\n/**\n * CPO D43 — the drilled frame's header answers \"what am I editing, and where does it live?\":\n * [media?] Starter [↑] [↓] [⋯]\n * Tier 1 of 3 in Tiers\n * The big title lives HERE only; the breadcrumb above is the path (its current crumb is small, D38). Prev / next are\n * labelled icon buttons whose tooltips name the sibling (\"Previous tier: Starter\"). No eyebrow, no duplicate counter.\n * Title 14/24 semibold (owner call). The native title= on the truncating h2 is V2 parity (kit-engine deviation from\n * the dashboard's no-title rule, see run ledger #32).\n */\nexport function FrameHeader({ frame, context, title }: { frame: Frame; context: string; title: string }) {\n const form = useForm()!;\n const { toast } = useKitServices();\n const it = frame.item;\n const media = it ? previewOf(it.block ?? it.itemSchema, form.getAt(frame.path), it.index).media : undefined;\n const step = (d: -1 | 1) => {\n if (!it) return;\n const n = it.index + d;\n if (n < 0 || n >= it.count) return;\n form.navigate([...it.arrayPath, n]);\n };\n const listRaw = it ? form.getAt(it.arrayPath) : undefined;\n const list = Array.isArray(listRaw) ? listRaw : [];\n const noun = (it?.block?.title ?? it?.itemSchema?.title ?? \"item\").toLowerCase();\n /* NEW-Q49-POLYSIBLING: in a mixed list a neighbour is named and previewed by its OWN type, not the current item's\n (a photo post's URL read as \"Next store review: https://…\") */\n const schemaAt = (i: number) => {\n const v = list[i];\n if (frame.kind === \"item\" && frame.field) return itemSchemaFor(frame.field, v) ?? it?.itemSchema;\n if (frame.kind === \"block\") return (isObj(v) && typeof v._type === \"string\" ? form.resolveSchema?.(v._type) : undefined) ?? it?.block;\n return it?.block ?? it?.itemSchema;\n };\n const nounAt = (i: number) => (it?.titleAt ? noun : (schemaAt(i)?.title ?? \"item\").toLowerCase());\n const sibling = (i: number) =>\n it && i >= 0 && i < it.count ? (it.titleAt ? it.titleAt(i) : previewOf(schemaAt(i), list[i], i, schemaAt(i)?.title).title) : \"\";\n const prev = it ? sibling(it.index - 1) : \"\";\n const next = it ? sibling(it.index + 1) : \"\";\n const prevNoun = it ? nounAt(it.index - 1) : noun;\n const nextNoun = it ? nounAt(it.index + 1) : noun;\n /* NEW-Q22-ROWLIMIT: the list's own bounds hold here as on its row menu (array.tsx): a duplicate past the maximum or a\n remove below the minimum only left a held, unsavable list */\n const bounds = frame.kind === \"item\" || frame.kind === \"block\" ? frame.field?.validation : undefined;\n const atMax = bounds?.max != null && list.length >= bounds.max;\n const atMin = bounds?.min != null && list.length <= bounds.min;\n /* NEW-Q48-ITEMACTIONS: a read-only list (a locked section, a viewer) offers no Duplicate / Remove: the host drops the\n write, so the menu only announced a change that never happened */\n const env = useKitEnv();\n const readOnly = frame.field ? resolveFieldAccess(frame.field, env).readOnly : !!env.readOnly;\n /* Duplicate / Remove move to another frame: the menu must not hand focus back to its trigger in the exiting frame\n (it unmounts, focus would drop to <body>); the stage focuses the entering frame instead */\n const moved = React.useRef(false);\n return (\n <div className=\"flex items-start gap-2.5 outline-none\" data-frame-header tabIndex={-1}>\n {media ? <Thumb media={media} size={36} /> : null}\n <div className=\"min-w-0 flex-1\">\n <h2 className=\"truncate text-kit-base font-semibold leading-6 text-kit-fg\" title={title}>\n {title}\n </h2>\n <p className=\"truncate text-kit-xs leading-4 text-kit-fg-3\">{context}</p>\n </div>\n {it ? (\n <div className=\"-mr-1 flex shrink-0 items-center gap-0.5 pt-0.5\">\n <IconButton\n label={prev ? `Previous ${prevNoun}: ${prev}` : `No previous ${noun}`}\n tooltip={prev ? `Previous ${prevNoun}: ${prev}` : `First ${noun}`}\n size=\"sm\"\n disabled={it.index === 0}\n onClick={() => step(-1)}\n >\n <IconArrowUp stroke={1.5} />\n </IconButton>\n <IconButton\n label={next ? `Next ${nextNoun}: ${next}` : `No next ${noun}`}\n tooltip={next ? `Next ${nextNoun}: ${next}` : `Last ${noun}`}\n size=\"sm\"\n disabled={it.index >= it.count - 1}\n onClick={() => step(1)}\n >\n <IconArrowDown stroke={1.5} />\n </IconButton>\n {readOnly ? null : (\n <Menu>\n <Tooltip content={`${title} actions`}>\n <MenuTrigger\n render={\n <IconButton label={`${title} actions`} tooltip={false} size=\"sm\">\n <IconDots stroke={1.5} />\n </IconButton>\n }\n />\n </Tooltip>\n <MenuContent align=\"end\" className=\"w-48\" finalFocus={() => !moved.current}>\n <MenuItem\n icon={<IconCopy stroke={1.5} />}\n disabled={atMax}\n onClick={() => {\n moved.current = true;\n const copy = isObj(list[it.index]) ? { ...(structuredClone(list[it.index]) as object), _key: newKey() } : list[it.index];\n form.setAt(it.arrayPath, [...list.slice(0, it.index + 1), copy, ...list.slice(it.index + 1)]);\n form.navigate([...it.arrayPath, it.index + 1]);\n toast?.success(\"Duplicated\", { description: \"You're now editing the copy.\" });\n }}\n >\n {atMax ? \"Duplicate · limit reached\" : \"Duplicate\"}\n </MenuItem>\n <MenuSeparator />\n <MenuItem\n danger\n icon={<IconTrash stroke={1.5} />}\n disabled={atMin}\n onClick={() => {\n moved.current = true;\n const prevList = list;\n form.navigate(parentFramePath(it.arrayPath));\n form.setAt(it.arrayPath, list.filter((_, j) => j !== it.index));\n toast?.(`“${title}” removed`, { action: { label: \"Undo\", onClick: () => form.setAt(it.arrayPath, prevList) }, duration: 10_000 });\n }}\n >\n {atMin ? `Remove · at least ${bounds?.min} required` : \"Remove\"}\n </MenuItem>\n </MenuContent>\n </Menu>\n )}\n </div>\n ) : null}\n </div>\n );\n}\n/** The frame that owns an array: drop the array field name (and the item index above it, if any). */\nconst parentFramePath = (arrayPath: FieldPath): FieldPath => arrayPath.slice(0, -1);\n\n/* ── Stage: direction-aware slide, scroll memory, focus, keys (V2 schema-form) ───────────────── */\n/** The title shown as `parentTitle` for the current frame (the root crumb's label for depth 1). */\nexport function parentTitleOf(frames: Frame[], rootLabel: string): string | undefined {\n if (frames.length < 2) return undefined;\n return frames.length === 2 ? rootLabel : frames[frames.length - 2].title;\n}\n\n/** Floating layers (Base UI popups carry these roles); keys and focus coming from one belong to that layer. */\nconst LAYER = \"[role=dialog],[role=menu],[role=listbox]\";\n\n/** Slide direction for a frame change: deeper → 1, shallower → −1, a sibling step → by index. */\nexport function frameDirection(prev: { depth: number; index: number; key: string }, frames: Frame[], key: string): 0 | 1 | -1 {\n if (prev.key === key) return 0;\n const cur = frames[frames.length - 1];\n if (frames.length > prev.depth) return 1;\n if (frames.length < prev.depth) return -1;\n return (cur.item?.index ?? 0) >= prev.index ? 1 : -1;\n}\n\n/**\n * The drill-in stack's behaviour. `root` wraps the form (keys bubble to it), `scroller` is the scrolling element (or\n * null when the host scrolls). Returns the current frame, its key, the slide direction and the form's onKeyDown.\n */\nexport function useFrameNavigation({\n frames,\n navigate,\n root,\n scroller,\n}: {\n frames: Frame[];\n navigate: (path: FieldPath) => void;\n root: React.RefObject<HTMLElement | null>;\n scroller: React.RefObject<HTMLElement | null>;\n}) {\n const current = frames[frames.length - 1];\n const frameKey = frameKeyOf(current.path);\n const prev = React.useRef({ depth: frames.length, index: current.item?.index ?? 0, key: frameKey });\n const dir = frameDirection(prev.current, frames, frameKey);\n const dirRef = React.useRef<number>(1);\n if (dir) dirRef.current = dir;\n\n const scrollMem = React.useRef(new Map<string, number>());\n React.useLayoutEffect(() => {\n const was = prev.current.key;\n if (was === frameKey) return;\n if (scroller.current) scrollMem.current.set(was, scroller.current.scrollTop);\n prev.current = { depth: frames.length, index: current.item?.index ?? 0, key: frameKey };\n const el = scroller.current;\n if (el) el.scrollTop = scrollMem.current.get(frameKey) ?? 0;\n const active = document.activeElement;\n /* a move started from a portalled menu (FrameHeader ⋯ → Duplicate / Remove) leaves focus in that layer, outside root */\n const layer = active && active !== document.body ? active.closest(LAYER) : null;\n const fromLayer = !!layer && !layer.contains(root.current);\n if (root.current && (active === document.body || root.current.contains(active) || fromLayer)) {\n // the exiting frame is still mounted during its exit animation — focus the ENTERING one\n const target = root.current.querySelector<HTMLElement>(`[data-frame-body=\"${CSS.escape(frameKey)}\"]`);\n target?.focus({ preventScroll: true });\n }\n });\n\n const onKeyDown = (e: React.KeyboardEvent) => {\n if (e.defaultPrevented) return;\n const t = e.target as HTMLElement;\n // ignore keys from floating layers opened by this form; a form INSIDE a dialog still handles its own keys\n // (V2 also listed Radix's popper wrapper; Base UI popups carry these roles themselves)\n const layer = t.closest(LAYER);\n if (layer && root.current && !layer.contains(root.current)) return;\n if (e.key === \"Escape\" && frames.length > 1 && !t.isContentEditable) {\n e.preventDefault();\n e.stopPropagation();\n navigate(frames[frames.length - 2].path);\n return;\n }\n const it = current.item;\n if (it && (e.key === \"ArrowUp\" || e.key === \"ArrowDown\")) {\n const typing = t.matches(\"input,textarea,select\") || t.isContentEditable;\n if (e.altKey || (!typing && t.matches(\"[data-frame-body],[data-frame-header]\"))) {\n const n = it.index + (e.key === \"ArrowUp\" ? -1 : 1);\n if (n >= 0 && n < it.count) {\n e.preventDefault();\n navigate([...it.arrayPath, n]);\n }\n }\n }\n };\n\n return { current, frameKey, dir: dirRef.current, onKeyDown };\n}\n\nconst EASE: [number, number, number, number] = [0.22, 1, 0.36, 1];\n\n/**\n * The frame body with V2's slide: 24px along the travel direction + fade, 220ms, ease [0.22, 1, 0.36, 1]; reduced\n * motion keeps only the fade. `before` renders inside the root frame above its fields (the synced-from note).\n */\nexport function FrameStage({\n frames,\n frameKey,\n dir,\n rootLabel,\n variant,\n before,\n review,\n}: {\n frames: Frame[];\n frameKey: string;\n dir: number;\n rootLabel: string;\n variant: \"panel\" | \"document\";\n before?: React.ReactNode;\n /** D61 Review changes is on: the clip leaves 16px on the left for the change bars */\n review?: boolean;\n}) {\n const reduce = useReducedMotion();\n const current = frames[frames.length - 1];\n return (\n // the drill slide is clipped sideways; with Review changes on (D61) the clip leaves 16px on the left for the change bars\n <div className=\"relative\" style={review ? { clipPath: \"inset(-100vh 0 -100vh -16px)\" } : { overflowX: \"clip\" }}>\n <AnimatePresence mode=\"popLayout\" initial={false} custom={dir}>\n <motion.div\n key={frameKey}\n custom={dir}\n variants={{\n enter: (d: number) => ({ x: reduce ? 0 : d * 24, opacity: 0 }),\n center: { x: 0, opacity: 1 },\n exit: (d: number) => ({ x: reduce ? 0 : d * -24, opacity: 0 }),\n }}\n initial=\"enter\"\n animate=\"center\"\n exit=\"exit\"\n transition={{ duration: 0.22, ease: EASE }}\n data-frame-body={frameKey}\n tabIndex={-1}\n className={cn(\"outline-none focus-visible:shadow-none\", variant === \"document\" ? \"py-1\" : \"px-4 py-4\")}\n >\n {current.kind === \"root\" ? before : null}\n <FrameView frame={current} parentTitle={parentTitleOf(frames, rootLabel)} />\n </motion.div>\n </AnimatePresence>\n </div>\n );\n}\n\nexport { HISTORY_SEGMENT };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDA,IAAM,WAAW,MAAM,cAA0B,CAAC,CAAC;AACnD,IAAa,qBAAqB,SAAS;AAC3C,IAAa,sBAAsB,MAAM,WAAW,QAAQ;;AAG5D,SAAS,eAAe,EAAE,QAAQ,YAAiC;CACjE,MAAM,OAAO,QAAQ;CACrB,MAAM,MAAM,SAAS,SAAS,KAAK,MAAM,QAAQ,IAAI,KAAK;CAC1D,MAAM,SAAS,MAAM,GAAG,IAAI,MAAM,CAAC;CACnC,MAAM,KAAK,QAAQ,MAAM,QAAQ;CACjC,MAAM,QAAQ,OAAO,QAAQ,MAAM,CAAC,SAAS,GAAG,QAAQ,EAAE,CAAC;CAC3D,OACE,qBAAC,OAAD;EAAK,WAAU;EAAf,UAAA,CACG,MAAM,KAAK,MACV,oBAAC,OAAD;GAAkB,WAAU;GAC1B,UAAA,oBAAC,UAAD;IAAU,OAAO;IAAG,MAAM,CAAC,GAAG,UAAU,EAAE,IAAI;IAAW;GAAS,CAAA;EAC/D,GAFK,EAAE,IAEP,CACN,GACA,MAAM,WAAW,IA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