@bettercms-ai/kit 3.1.22 → 3.1.24
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 +17 -0
- package/dist/context.js.map +1 -1
- package/dist/controls/index.js +2 -2
- package/dist/controls/media-services.d.ts +13 -0
- package/dist/controls/media.d.ts +24 -1
- package/dist/controls/media.js +137 -59
- package/dist/controls/media.js.map +1 -1
- package/dist/controls/rich-text/blocks.d.ts +1 -1
- package/dist/controls/rich-text/blocks.js +62 -4
- package/dist/controls/rich-text/blocks.js.map +1 -1
- package/dist/controls/rich-text/control.js +7 -1
- package/dist/controls/rich-text/control.js.map +1 -1
- package/dist/controls/rich-text/editor.d.ts +8 -3
- package/dist/controls/rich-text/editor.js +193 -9
- package/dist/controls/rich-text/editor.js.map +1 -1
- package/dist/controls/rich-text/ops.d.ts +11 -2
- package/dist/controls/rich-text/ops.js +70 -3
- package/dist/controls/rich-text/ops.js.map +1 -1
- package/dist/engine/field-shell.d.ts +7 -1
- package/dist/engine/field-shell.js +73 -46
- package/dist/engine/field-shell.js.map +1 -1
- package/dist/index.js +3 -3
- package/dist/library/entries/data.entries.js +8 -0
- package/dist/library/entries/data.entries.js.map +1 -1
- package/dist/library/kit-catalog.json +1 -1
- package/dist/styles.css +1 -1
- package/dist/theme.css +27 -0
- package/dist/tokens.css +71 -0
- package/package.json +1 -1
package/dist/context.d.ts
CHANGED
|
@@ -70,6 +70,15 @@ export declare const AI_PRESETS: {
|
|
|
70
70
|
id: AiPreset;
|
|
71
71
|
label: string;
|
|
72
72
|
}[];
|
|
73
|
+
/**
|
|
74
|
+
* GAP-004: words selected in a rich-text field, to comment on (W3C TextQuoteSelector). `prefix` / `suffix` are up to 32
|
|
75
|
+
* characters of the field's text right before and after them, so the host can find the right occurrence again.
|
|
76
|
+
*/
|
|
77
|
+
export interface KitCommentSelection {
|
|
78
|
+
quote: string;
|
|
79
|
+
prefix?: string;
|
|
80
|
+
suffix?: string;
|
|
81
|
+
}
|
|
73
82
|
/** The in-place field comments popover (V2 FieldThreads over the comments store), drawn by the host. */
|
|
74
83
|
export interface KitFieldCommentsProps {
|
|
75
84
|
docId: string;
|
|
@@ -78,6 +87,8 @@ export interface KitFieldCommentsProps {
|
|
|
78
87
|
label: string;
|
|
79
88
|
/** the field's text, first 80 characters */
|
|
80
89
|
quote?: string;
|
|
90
|
+
/** GAP-004: set when the popover opened from a rich-text selection's Comment: the new thread is about these words */
|
|
91
|
+
selection?: KitCommentSelection;
|
|
81
92
|
onClose: () => void;
|
|
82
93
|
/** "Open in panel": set when the host has a comments panel (`env.onComment`) */
|
|
83
94
|
onOpenPanel?: () => void;
|
|
@@ -112,6 +123,12 @@ export interface KitServices {
|
|
|
112
123
|
path: FieldPath;
|
|
113
124
|
title: string;
|
|
114
125
|
}) => void;
|
|
126
|
+
/**
|
|
127
|
+
* RP-047: whether a rich-text body image at this address can be cropped (the crop is drawn by the media library's
|
|
128
|
+
* image URL, so a picture from elsewhere keeps its whole frame). False → the crop is disabled and says why; the focal
|
|
129
|
+
* point still applies. Absent → the crop is offered.
|
|
130
|
+
*/
|
|
131
|
+
canCrop?: (url: string) => boolean;
|
|
115
132
|
/** The project's forms for `reference: { to: ["form"] }` (the host's Forms store). */
|
|
116
133
|
forms?: () => {
|
|
117
134
|
id: string;
|
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/** 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 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 /** 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;;;;;AAsHA,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,CA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AAM,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"}
|
|
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;E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encesControl, referenceNoun, useRefere
|
|
|
17
17
|
import { FormPickerControl, isFormOnly } from "./form-picker.js";
|
|
18
18
|
import { IconControl, IconPicker, IconValueGlyph } from "./icon.js";
|
|
19
19
|
import { LocationControl, locationFromDraft } from "./location.js";
|
|
20
|
-
import { FileControl, GalleryControl, ImageControl, MediaPicker, VideoControl, VideoPreview, acceptsFile, cropChoice, fileNameFromUrl, formatBytes, fromAsset, isVideoUrl, normImage, useUpload, videoProvider, withCrop, youTubeId } from "./media.js";
|
|
20
|
+
import { FileControl, GalleryControl, ImageControl, ImageDetails, MediaPicker, NO_CROP_OUTSIDE_LIBRARY, VideoControl, VideoPreview, acceptsFile, cropChoice, fileNameFromUrl, formatBytes, fromAsset, isVideoUrl, normImage, useUpload, videoProvider, withCrop, youTubeId } from "./media.js";
|
|
21
21
|
import { ComponentSlotControl, SlotDepthContext, SlotPicker } from "./slot.js";
|
|
22
22
|
import { RT_PROSE, RichTextEditor } from "./rich-text/editor.js";
|
|
23
23
|
import { RichTextControl, RichTextExpandAction } from "./rich-text/control.js";
|
|
@@ -34,6 +34,6 @@ function registerKitControls() {
|
|
|
34
34
|
CONTROLS.button = ButtonControl;
|
|
35
35
|
}
|
|
36
36
|
//#endregion
|
|
37
|
-
export { BUTTON_ICONS, BooleanControl, ButtonControl, ButtonIconPicker, ButtonLinkEditor, ButtonPreview, ButtonScreen, ButtonStyleGrid, C1_ACTIONS, C1_CONTROLS, C2_CONTROLS, CodeControl, CodeDialogField, CodeSurface, ColorControl, ComponentSlotControl, DateControl, EmailControl, FileControl, FormPickerControl, GalleryControl, HEX_COLOR, IconControl, IconPicker, IconValueGlyph, ImageControl, JsonControl, LINK_TYPES, LinkControl, LinkField, LinkForm, LinkLine, LinkOptions, LinkPicker, LinkPopoverBody, LinkQuickEdit, LocationControl, MediaPicker, MiniCalendar, MultiSelectControl, NUMBER_SCALE, NumberControl, PlainNumber, REL_ITEMS, RT_PROSE, RatingControl, RefThumb, ReferenceControl, ReferencesControl, RichTextControl, RichTextEditor, RichTextExpandAction, STYLE_ITEMS, ScaleControl, ScaleSlider, SectionAnchorsProvider, SelectControl, SlotDepthContext, SlotPicker, SlugControl, SlugGenerate, StringControl, StyleGlyph, TARGET_KEYS, TEXT_FOCUS, TableControl, TableFrame, TableFullScreenAction, TagsControl, TextControl, UnknownValueNote, UnreadableValue, UrlControl, VideoControl, VideoPreview, acceptsFile, cropChoice, describeLink, detectType, fileNameFromUrl, fileTarget, finalizeLink, findTarget, formatBytes, fromAsset, hasLink, hrefOf, isFormOnly, isVideoUrl, jsonProblem, linkIcon, linkProblem, linkShapeOf, linkText, locationFromDraft, lookLabel, lookOf, nextButton, normImage, normLink, optionIcons, pickerHex, ratingScale, referenceNoun, registerC1Controls, registerC2Controls, registerKitControls, slugSource, slugTidy, slugTyping, snapRating, storedLink, str, tagRefusal, toNum, ungroupNumber, useLinkTargets, useOwnDescription, useReferenceRecords, useUpload, videoProvider, withCrop, withTarget, withText, youTubeId };
|
|
37
|
+
export { BUTTON_ICONS, BooleanControl, ButtonControl, ButtonIconPicker, ButtonLinkEditor, ButtonPreview, ButtonScreen, ButtonStyleGrid, C1_ACTIONS, C1_CONTROLS, C2_CONTROLS, CodeControl, CodeDialogField, CodeSurface, ColorControl, ComponentSlotControl, DateControl, EmailControl, FileControl, FormPickerControl, GalleryControl, HEX_COLOR, IconControl, IconPicker, IconValueGlyph, ImageControl, ImageDetails, JsonControl, LINK_TYPES, LinkControl, LinkField, LinkForm, LinkLine, LinkOptions, LinkPicker, LinkPopoverBody, LinkQuickEdit, LocationControl, MediaPicker, MiniCalendar, MultiSelectControl, NO_CROP_OUTSIDE_LIBRARY, NUMBER_SCALE, NumberControl, PlainNumber, REL_ITEMS, RT_PROSE, RatingControl, RefThumb, ReferenceControl, ReferencesControl, RichTextControl, RichTextEditor, RichTextExpandAction, STYLE_ITEMS, ScaleControl, ScaleSlider, SectionAnchorsProvider, SelectControl, SlotDepthContext, SlotPicker, SlugControl, SlugGenerate, StringControl, StyleGlyph, TARGET_KEYS, TEXT_FOCUS, TableControl, TableFrame, TableFullScreenAction, TagsControl, TextControl, UnknownValueNote, UnreadableValue, UrlControl, VideoControl, VideoPreview, acceptsFile, cropChoice, describeLink, detectType, fileNameFromUrl, fileTarget, finalizeLink, findTarget, formatBytes, fromAsset, hasLink, hrefOf, isFormOnly, isVideoUrl, jsonProblem, linkIcon, linkProblem, linkShapeOf, linkText, locationFromDraft, lookLabel, lookOf, nextButton, normImage, normLink, optionIcons, pickerHex, ratingScale, referenceNoun, registerC1Controls, registerC2Controls, registerKitControls, slugSource, slugTidy, slugTyping, snapRating, storedLink, str, tagRefusal, toNum, ungroupNumber, useLinkTargets, useOwnDescription, useReferenceRecords, useUpload, videoProvider, withCrop, withTarget, withText, youTubeId };
|
|
38
38
|
|
|
39
39
|
//# sourceMappingURL=index.js.map
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* Existing members the media controls also read: `MediaPicker` (the media library dialog), `onUploaded`, `toast`.
|
|
8
8
|
*/
|
|
9
|
+
import type { ComponentType } from "react";
|
|
9
10
|
import type { FieldPath } from "../schema/types";
|
|
10
11
|
export interface KitUploadOptions {
|
|
11
12
|
/** 0–1 across all files */
|
|
@@ -41,6 +42,18 @@ declare module "../context" {
|
|
|
41
42
|
}) => KitMediaAsset | undefined;
|
|
42
43
|
/** The URL to draw a stored address with (a site-relative path on a code-built project needs the site origin). */
|
|
43
44
|
mediaSrc?: (url: string) => string;
|
|
45
|
+
/**
|
|
46
|
+
* The host's note under a chosen file: what its media library holds about the asset that the field does not store
|
|
47
|
+
* (the dashboard's read-only transcript of a video or audio file, with a link to where it is edited). It draws
|
|
48
|
+
* nothing for a file it has nothing to say about. Absent → no note.
|
|
49
|
+
*/
|
|
50
|
+
FileNote?: ComponentType<{
|
|
51
|
+
value: {
|
|
52
|
+
url: string;
|
|
53
|
+
id?: string;
|
|
54
|
+
name?: string;
|
|
55
|
+
};
|
|
56
|
+
}>;
|
|
44
57
|
}
|
|
45
58
|
}
|
|
46
59
|
export {};
|
package/dist/controls/media.d.ts
CHANGED
|
@@ -70,6 +70,28 @@ export declare function withCrop(v: ImageValue, choice: V2ImageCrop, size: {
|
|
|
70
70
|
w: number;
|
|
71
71
|
h: number;
|
|
72
72
|
}): ImageValue;
|
|
73
|
+
/** RP-047: why a picture from outside the media library offers no crop (its URL cannot carry one). */
|
|
74
|
+
export declare const NO_CROP_OUTSIDE_LIBRARY = "This picture isn't in your media library, so it can't be cropped here. The focal point still applies.";
|
|
75
|
+
export declare function ImageDetails({ v, onChange, readOnly, label, urlOnly, altOnly, framingOnly, canCrop, size, asset, fit, }: {
|
|
76
|
+
v: ImageValue;
|
|
77
|
+
onChange: (n: ImageValue) => void;
|
|
78
|
+
readOnly?: boolean;
|
|
79
|
+
label: string;
|
|
80
|
+
urlOnly: boolean;
|
|
81
|
+
/** Only the alt text is kept with this image (`imageAltOnly`). */
|
|
82
|
+
altOnly?: boolean;
|
|
83
|
+
/** RP-047: the crop and focal point only (a rich-text body image edits its alt text and file in its own toolbar) */
|
|
84
|
+
framingOnly?: boolean;
|
|
85
|
+
/** RP-047: false → the crop is disabled and says why (a picture from outside the media library) */
|
|
86
|
+
canCrop?: boolean;
|
|
87
|
+
size?: {
|
|
88
|
+
w: number;
|
|
89
|
+
h: number;
|
|
90
|
+
};
|
|
91
|
+
asset?: KitMediaAsset;
|
|
92
|
+
/** fitOf's answer for this picture: a logo or an icon field sits whole in the pad, on the checker */
|
|
93
|
+
fit?: "contain" | "cover";
|
|
94
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
73
95
|
export declare function ImageControl({ field, value, onChange: write, readOnly, id, path }: ControlProps): import("react/jsx-runtime").JSX.Element;
|
|
74
96
|
/** An array of images: a sortable grid of tiles with a dashed "Add images" tile last (hidden at `max`). */
|
|
75
97
|
export declare function GalleryControl({ value, onChange, readOnly, field, id, path }: ControlProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -84,7 +106,8 @@ export declare function VideoPreview({ url, poster, title }: {
|
|
|
84
106
|
/**
|
|
85
107
|
* A URL input with a live preview. The value keeps its stored shape: a URL string stays a string, a `{ url, poster… }`
|
|
86
108
|
* object keeps its other keys. What is typed is a draft until it is an address prod stores (http(s) or a site path);
|
|
87
|
-
* until then the field keeps the saved value and says why under the input.
|
|
109
|
+
* until then the field keeps the saved value and says why under the input. DK-014: an MP4 or WebM file can be
|
|
110
|
+
* uploaded or picked from the media library, each offered only when the host has that service.
|
|
88
111
|
*/
|
|
89
112
|
export declare function VideoControl({ field, value, onChange, readOnly, id, onBlur }: ControlProps): import("react/jsx-runtime").JSX.Element;
|
|
90
113
|
export {};
|
package/dist/controls/media.js
CHANGED
|
@@ -352,7 +352,9 @@ function withCrop(v, choice, size) {
|
|
|
352
352
|
if (rect) next.crop = rect;
|
|
353
353
|
return next;
|
|
354
354
|
}
|
|
355
|
-
|
|
355
|
+
/** RP-047: why a picture from outside the media library offers no crop (its URL cannot carry one). */
|
|
356
|
+
var NO_CROP_OUTSIDE_LIBRARY = "This picture isn't in your media library, so it can't be cropped here. The focal point still applies.";
|
|
357
|
+
function ImageDetails({ v, onChange, readOnly, label, urlOnly, altOnly = false, framingOnly = false, canCrop = true, size, asset, fit = "cover" }) {
|
|
356
358
|
const { src } = useMedia();
|
|
357
359
|
const focal = v.focal ?? {
|
|
358
360
|
x: 50,
|
|
@@ -388,7 +390,7 @@ function ImageDetails({ v, onChange, readOnly, label, urlOnly, altOnly = false,
|
|
|
388
390
|
className: "flex items-center justify-between",
|
|
389
391
|
children: [/* @__PURE__ */ jsx("span", {
|
|
390
392
|
className: "text-kit-sm font-medium text-kit-fg",
|
|
391
|
-
children: "Alt text and details"
|
|
393
|
+
children: framingOnly ? "Crop and focal point" : "Alt text and details"
|
|
392
394
|
}), size ? /* @__PURE__ */ jsxs("span", {
|
|
393
395
|
className: "tabular-nums text-kit-2xs text-kit-fg-3",
|
|
394
396
|
children: [
|
|
@@ -410,7 +412,7 @@ function ImageDetails({ v, onChange, readOnly, label, urlOnly, altOnly = false,
|
|
|
410
412
|
className: "text-kit-sm text-kit-fg",
|
|
411
413
|
children: asset.alt
|
|
412
414
|
})]
|
|
413
|
-
}) : null] }) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("label", {
|
|
415
|
+
}) : null] }) : /* @__PURE__ */ jsxs(Fragment, { children: [framingOnly ? null : /* @__PURE__ */ jsxs("label", {
|
|
414
416
|
className: "flex flex-col gap-1.5",
|
|
415
417
|
children: [/* @__PURE__ */ jsx("span", {
|
|
416
418
|
className: "text-kit-xs text-kit-fg-3",
|
|
@@ -464,7 +466,7 @@ function ImageDetails({ v, onChange, readOnly, label, urlOnly, altOnly = false,
|
|
|
464
466
|
/* @__PURE__ */ jsx(Select, {
|
|
465
467
|
size: "sm",
|
|
466
468
|
"aria-label": `${label} crop`,
|
|
467
|
-
disabled: readOnly || !size,
|
|
469
|
+
disabled: readOnly || !size || !canCrop,
|
|
468
470
|
triggerClassName: "w-full",
|
|
469
471
|
value: choice,
|
|
470
472
|
onValueChange: (c) => size && c !== CUSTOM_CROP && onChange(withCrop(v, c, size)),
|
|
@@ -479,7 +481,10 @@ function ImageDetails({ v, onChange, readOnly, label, urlOnly, altOnly = false,
|
|
|
479
481
|
disabled: true
|
|
480
482
|
}] : []]
|
|
481
483
|
}),
|
|
482
|
-
!
|
|
484
|
+
!canCrop ? /* @__PURE__ */ jsx(Reason, {
|
|
485
|
+
tone: "muted",
|
|
486
|
+
children: NO_CROP_OUTSIDE_LIBRARY
|
|
487
|
+
}) : !size && !readOnly ? /* @__PURE__ */ jsx("span", {
|
|
483
488
|
className: "text-kit-2xs text-kit-fg-3",
|
|
484
489
|
children: "The crop is cut from the picture's size, which is still loading."
|
|
485
490
|
}) : null,
|
|
@@ -535,7 +540,7 @@ function ImageDetails({ v, onChange, readOnly, label, urlOnly, altOnly = false,
|
|
|
535
540
|
})
|
|
536
541
|
]
|
|
537
542
|
})] }),
|
|
538
|
-
urlOnly || altOnly ? /* @__PURE__ */ jsxs("div", {
|
|
543
|
+
framingOnly ? null : urlOnly || altOnly ? /* @__PURE__ */ jsxs("div", {
|
|
539
544
|
className: "flex flex-col gap-1.5",
|
|
540
545
|
children: [/* @__PURE__ */ jsx("span", {
|
|
541
546
|
className: "text-kit-xs text-kit-fg-3",
|
|
@@ -1191,60 +1196,64 @@ function FileControl({ value, onChange, readOnly, id }) {
|
|
|
1191
1196
|
const name = asset?.name ?? v.name ?? fileNameFromUrl(v.url);
|
|
1192
1197
|
const ext = (name.includes(".") ? name.split(".").pop() : "")?.toUpperCase() || "FILE";
|
|
1193
1198
|
const meta = [ext.toLowerCase(), asset?.size ? formatBytes(asset.size) : null].filter(Boolean).join(" · ");
|
|
1199
|
+
const Note = s.FileNote;
|
|
1194
1200
|
return /* @__PURE__ */ jsxs("div", {
|
|
1195
|
-
className: "flex
|
|
1196
|
-
children: [
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
className: "min-w-0 flex-1",
|
|
1204
|
-
children: [/* @__PURE__ */ jsx("a", {
|
|
1205
|
-
id,
|
|
1206
|
-
href: src(v.url),
|
|
1207
|
-
target: "_blank",
|
|
1208
|
-
rel: "noreferrer",
|
|
1209
|
-
className: "block truncate text-kit-sm font-medium text-kit-accent-fg hover:underline",
|
|
1210
|
-
children: name
|
|
1211
|
-
}), /* @__PURE__ */ jsx("div", {
|
|
1212
|
-
className: "text-kit-xs text-kit-fg-3",
|
|
1213
|
-
children: meta
|
|
1214
|
-
})]
|
|
1215
|
-
}),
|
|
1216
|
-
library ? /* @__PURE__ */ jsx(Button, {
|
|
1217
|
-
size: "sm",
|
|
1218
|
-
variant: "ghost",
|
|
1219
|
-
onClick: library,
|
|
1220
|
-
children: "Replace"
|
|
1221
|
-
}) : null,
|
|
1222
|
-
/* @__PURE__ */ jsxs(Menu, { children: [/* @__PURE__ */ jsx(MenuTrigger, {
|
|
1223
|
-
render: /* @__PURE__ */ jsx(IconButton, {
|
|
1224
|
-
label: "File actions",
|
|
1225
|
-
size: "sm"
|
|
1201
|
+
className: "flex flex-col gap-1.5",
|
|
1202
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
1203
|
+
className: "flex items-center gap-3 rounded-kit-lg border border-kit-line-strong bg-kit-control-bg p-2",
|
|
1204
|
+
children: [
|
|
1205
|
+
/* @__PURE__ */ jsx("span", {
|
|
1206
|
+
"aria-hidden": true,
|
|
1207
|
+
className: "flex size-14 shrink-0 items-center justify-center rounded-kit-md border border-kit-line bg-kit-subtle font-kit-mono text-kit-2xs font-medium text-kit-fg-2",
|
|
1208
|
+
children: ext
|
|
1226
1209
|
}),
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1210
|
+
/* @__PURE__ */ jsxs("div", {
|
|
1211
|
+
className: "min-w-0 flex-1",
|
|
1212
|
+
children: [/* @__PURE__ */ jsx("a", {
|
|
1213
|
+
id,
|
|
1214
|
+
href: src(v.url),
|
|
1215
|
+
target: "_blank",
|
|
1216
|
+
rel: "noreferrer",
|
|
1217
|
+
className: "block truncate text-kit-sm font-medium text-kit-accent-fg hover:underline",
|
|
1218
|
+
children: name
|
|
1219
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
1220
|
+
className: "text-kit-xs text-kit-fg-3",
|
|
1221
|
+
children: meta
|
|
1222
|
+
})]
|
|
1223
|
+
}),
|
|
1224
|
+
library ? /* @__PURE__ */ jsx(Button, {
|
|
1225
|
+
size: "sm",
|
|
1226
|
+
variant: "ghost",
|
|
1227
|
+
onClick: library,
|
|
1228
|
+
children: "Replace"
|
|
1229
|
+
}) : null,
|
|
1230
|
+
/* @__PURE__ */ jsxs(Menu, { children: [/* @__PURE__ */ jsx(MenuTrigger, {
|
|
1231
|
+
render: /* @__PURE__ */ jsx(IconButton, {
|
|
1232
|
+
label: "File actions",
|
|
1233
|
+
size: "sm"
|
|
1235
1234
|
}),
|
|
1236
|
-
/* @__PURE__ */ jsx(
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1235
|
+
children: /* @__PURE__ */ jsx(IconDots, { stroke: 1.5 })
|
|
1236
|
+
}), /* @__PURE__ */ jsxs(MenuContent, {
|
|
1237
|
+
align: "end",
|
|
1238
|
+
children: [
|
|
1239
|
+
/* @__PURE__ */ jsx(MenuItem, {
|
|
1240
|
+
icon: /* @__PURE__ */ jsx(IconDownload, { stroke: 1.5 }),
|
|
1241
|
+
onClick: () => window.open(src(v.url), "_blank", "noopener"),
|
|
1242
|
+
children: "Open"
|
|
1243
|
+
}),
|
|
1244
|
+
/* @__PURE__ */ jsx(MenuSeparator, {}),
|
|
1245
|
+
/* @__PURE__ */ jsx(MenuItem, {
|
|
1246
|
+
danger: true,
|
|
1247
|
+
icon: /* @__PURE__ */ jsx(IconTrash, { stroke: 1.5 }),
|
|
1248
|
+
disabled: readOnly,
|
|
1249
|
+
onClick: () => !readOnly && onChange(null),
|
|
1250
|
+
children: "Remove"
|
|
1251
|
+
})
|
|
1252
|
+
]
|
|
1253
|
+
})] }),
|
|
1254
|
+
pickerEl
|
|
1255
|
+
]
|
|
1256
|
+
}), Note ? /* @__PURE__ */ jsx(Note, { value: v }) : null]
|
|
1248
1257
|
});
|
|
1249
1258
|
}
|
|
1250
1259
|
var videoProvider = (url) => /youtu/.test(url) ? "YouTube" : /vimeo/.test(url) ? "Vimeo" : /loom/.test(url) ? "Loom" : /\.(mp4|webm|mov)(\?|$)/i.test(url) ? "MP4" : url ? "Link" : "";
|
|
@@ -1304,16 +1313,22 @@ function VideoPreview({ url, poster, title }) {
|
|
|
1304
1313
|
]
|
|
1305
1314
|
});
|
|
1306
1315
|
}
|
|
1316
|
+
/** The video files the media library stores (the backend's upload allowlist: mp4 and webm, no QuickTime). */
|
|
1317
|
+
var VIDEO_ACCEPT = "video/mp4,video/webm";
|
|
1307
1318
|
/**
|
|
1308
1319
|
* A URL input with a live preview. The value keeps its stored shape: a URL string stays a string, a `{ url, poster… }`
|
|
1309
1320
|
* object keeps its other keys. What is typed is a draft until it is an address prod stores (http(s) or a site path);
|
|
1310
|
-
* until then the field keeps the saved value and says why under the input.
|
|
1321
|
+
* until then the field keeps the saved value and says why under the input. DK-014: an MP4 or WebM file can be
|
|
1322
|
+
* uploaded or picked from the media library, each offered only when the host has that service.
|
|
1311
1323
|
*/
|
|
1312
1324
|
function VideoControl({ field, value, onChange, readOnly, id, onBlur }) {
|
|
1325
|
+
const s = useKitServices();
|
|
1313
1326
|
const obj = isObj(value) && typeof value.url === "string" ? value : null;
|
|
1314
1327
|
const stored = typeof value === "string" ? value : obj?.url ?? "";
|
|
1315
1328
|
const [draft, setDraft] = React.useState(stored);
|
|
1316
1329
|
const [touched, setTouched] = React.useState(false);
|
|
1330
|
+
const [picker, setPicker] = React.useState(false);
|
|
1331
|
+
const fileInput = React.useRef(null);
|
|
1317
1332
|
React.useEffect(() => setDraft(stored), [stored]);
|
|
1318
1333
|
const commit = (raw) => {
|
|
1319
1334
|
const url = raw.trim();
|
|
@@ -1324,6 +1339,10 @@ function VideoControl({ field, value, onChange, readOnly, id, onBlur }) {
|
|
|
1324
1339
|
url
|
|
1325
1340
|
} : url);
|
|
1326
1341
|
};
|
|
1342
|
+
const up = useUpload(VIDEO_ACCEPT, "MP4 or WebM video", (a) => a[0] && commit(a[0].url));
|
|
1343
|
+
const upload = !readOnly ? up.run : void 0;
|
|
1344
|
+
const library = s.MediaPicker && !readOnly ? () => setPicker(true) : void 0;
|
|
1345
|
+
const busy = up.progress != null;
|
|
1327
1346
|
const bad = draft.trim() !== "" && !isVideoUrl(draft);
|
|
1328
1347
|
const errorId = `${id}-error`;
|
|
1329
1348
|
return /* @__PURE__ */ jsxs("div", {
|
|
@@ -1358,6 +1377,65 @@ function VideoControl({ field, value, onChange, readOnly, id, onBlur }) {
|
|
|
1358
1377
|
className: "text-kit-xs text-kit-danger-fg",
|
|
1359
1378
|
children: "Not saved: use a full link starting with https://, or a site path starting with /."
|
|
1360
1379
|
}) : null,
|
|
1380
|
+
library || upload ? /* @__PURE__ */ jsxs("div", {
|
|
1381
|
+
className: "flex flex-wrap items-center gap-1.5",
|
|
1382
|
+
children: [
|
|
1383
|
+
library ? /* @__PURE__ */ jsx(Button, {
|
|
1384
|
+
size: "sm",
|
|
1385
|
+
variant: "secondary",
|
|
1386
|
+
onClick: library,
|
|
1387
|
+
disabled: busy,
|
|
1388
|
+
children: "Media library"
|
|
1389
|
+
}) : null,
|
|
1390
|
+
upload ? /* @__PURE__ */ jsx(Button, {
|
|
1391
|
+
size: "sm",
|
|
1392
|
+
variant: "ghost",
|
|
1393
|
+
leftIcon: /* @__PURE__ */ jsx(IconUpload, { stroke: 1.5 }),
|
|
1394
|
+
onClick: () => fileInput.current?.click(),
|
|
1395
|
+
disabled: busy,
|
|
1396
|
+
children: "Upload"
|
|
1397
|
+
}) : null,
|
|
1398
|
+
upload ? /* @__PURE__ */ jsx("input", {
|
|
1399
|
+
ref: fileInput,
|
|
1400
|
+
type: "file",
|
|
1401
|
+
hidden: true,
|
|
1402
|
+
tabIndex: -1,
|
|
1403
|
+
"aria-hidden": true,
|
|
1404
|
+
accept: VIDEO_ACCEPT,
|
|
1405
|
+
onChange: (e) => {
|
|
1406
|
+
upload(Array.from(e.target.files ?? []));
|
|
1407
|
+
e.target.value = "";
|
|
1408
|
+
}
|
|
1409
|
+
}) : null
|
|
1410
|
+
]
|
|
1411
|
+
}) : null,
|
|
1412
|
+
busy ? /* @__PURE__ */ jsxs("div", {
|
|
1413
|
+
className: "flex items-center gap-2 text-kit-xs text-kit-fg-2",
|
|
1414
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
1415
|
+
className: "shrink-0",
|
|
1416
|
+
children: [
|
|
1417
|
+
/* @__PURE__ */ jsx("span", {
|
|
1418
|
+
role: "status",
|
|
1419
|
+
children: "Uploading…"
|
|
1420
|
+
}),
|
|
1421
|
+
" ",
|
|
1422
|
+
up.progress,
|
|
1423
|
+
"%"
|
|
1424
|
+
]
|
|
1425
|
+
}), /* @__PURE__ */ jsx(Progress, {
|
|
1426
|
+
value: up.progress,
|
|
1427
|
+
tone: "ink",
|
|
1428
|
+
label: "Upload progress",
|
|
1429
|
+
className: "max-w-56"
|
|
1430
|
+
})]
|
|
1431
|
+
}) : null,
|
|
1432
|
+
up.error ? /* @__PURE__ */ jsx(Reason, { children: up.error }) : null,
|
|
1433
|
+
library ? /* @__PURE__ */ jsx(MediaPicker, {
|
|
1434
|
+
open: picker,
|
|
1435
|
+
onOpenChange: setPicker,
|
|
1436
|
+
accept: ["video"],
|
|
1437
|
+
onPick: (a) => a[0] && commit(a[0].url)
|
|
1438
|
+
}) : null,
|
|
1361
1439
|
stored ? /* @__PURE__ */ jsx(VideoPreview, {
|
|
1362
1440
|
url: stored,
|
|
1363
1441
|
poster: obj?.poster,
|
|
@@ -1370,6 +1448,6 @@ function VideoControl({ field, value, onChange, readOnly, id, onBlur }) {
|
|
|
1370
1448
|
});
|
|
1371
1449
|
}
|
|
1372
1450
|
//#endregion
|
|
1373
|
-
export { FileControl, GalleryControl, ImageControl, MediaPicker, VideoControl, VideoPreview, acceptsFile, cropChoice, fileNameFromUrl, formatBytes, fromAsset, isVideoUrl, normImage, useUpload, videoProvider, withCrop, youTubeId };
|
|
1451
|
+
export { FileControl, GalleryControl, ImageControl, ImageDetails, MediaPicker, NO_CROP_OUTSIDE_LIBRARY, VideoControl, VideoPreview, acceptsFile, cropChoice, fileNameFromUrl, formatBytes, fromAsset, isVideoUrl, normImage, useUpload, videoProvider, withCrop, youTubeId };
|
|
1374
1452
|
|
|
1375
1453
|
//# sourceMappingURL=media.js.map
|