@bettercms-ai/kit 4.1.1 → 4.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/adapters/lossy.d.ts +1 -1
- package/dist/adapters/lossy.js +1 -1
- package/dist/adapters/lossy.js.map +1 -1
- package/dist/adapters/schema.js +1 -1
- package/dist/adapters/schema.js.map +1 -1
- package/dist/context.d.ts +8 -0
- package/dist/context.js.map +1 -1
- package/dist/controls/index.js +2 -2
- package/dist/controls/media-v16.d.ts +3 -1
- package/dist/controls/media-v16.js +3 -1
- package/dist/controls/media-v16.js.map +1 -1
- package/dist/controls/media.d.ts +5 -1
- package/dist/controls/media.js +25 -7
- package/dist/controls/media.js.map +1 -1
- package/dist/controls/rich-text/block-tool.d.ts +1 -1
- package/dist/controls/rich-text/block-tool.js +1 -1
- package/dist/controls/rich-text/block-tool.js.map +1 -1
- package/dist/controls/rich-text/blocks.js +3 -1
- package/dist/controls/rich-text/blocks.js.map +1 -1
- package/dist/controls/rich-text/catalog.d.ts +26 -3
- package/dist/controls/rich-text/catalog.js +239 -58
- package/dist/controls/rich-text/catalog.js.map +1 -1
- package/dist/controls/rich-text/codec.d.ts +7 -1
- package/dist/controls/rich-text/codec.js +2 -1
- package/dist/controls/rich-text/codec.js.map +1 -1
- package/dist/controls/rich-text/control.js +2 -1
- package/dist/controls/rich-text/control.js.map +1 -1
- package/dist/controls/rich-text/dom.js +8 -3
- package/dist/controls/rich-text/dom.js.map +1 -1
- package/dist/controls/rich-text/editor.d.ts +3 -1
- package/dist/controls/rich-text/editor.js +160 -44
- package/dist/controls/rich-text/editor.js.map +1 -1
- package/dist/controls/rich-text/rewriteSelection.d.ts +25 -0
- package/dist/controls/rich-text/rewriteSelection.js +28 -0
- package/dist/controls/rich-text/rewriteSelection.js.map +1 -0
- package/dist/controls/rich-text/slash-preview.js +18 -5
- package/dist/controls/rich-text/slash-preview.js.map +1 -1
- package/dist/controls/rich-text/table-grid.js +28 -21
- package/dist/controls/rich-text/table-grid.js.map +1 -1
- package/dist/controls/rich-text/toolbar.d.ts +6 -2
- package/dist/controls/rich-text/toolbar.js +205 -4
- package/dist/controls/rich-text/toolbar.js.map +1 -1
- package/dist/controls/text.d.ts +1 -1
- package/dist/controls/text.js +10 -7
- package/dist/controls/text.js.map +1 -1
- package/dist/engine/field-shell.js +8 -4
- package/dist/engine/field-shell.js.map +1 -1
- package/dist/engine/frame.js +9 -2
- package/dist/engine/frame.js.map +1 -1
- package/dist/engine/grouping.js +4 -3
- package/dist/engine/grouping.js.map +1 -1
- package/dist/engine/item-list.js +2 -2
- package/dist/engine/item-list.js.map +1 -1
- package/dist/engine/schema-form.d.ts +2 -0
- package/dist/engine/schema-form.js +2 -0
- package/dist/engine/schema-form.js.map +1 -1
- package/dist/index.js +3 -3
- package/dist/kit.css +6 -32
- package/dist/lib/reduced-motion.d.ts +1 -0
- package/dist/lib/reduced-motion.js +19 -0
- package/dist/lib/reduced-motion.js.map +1 -0
- package/dist/styles.css +1 -1
- package/dist/theme.css +101 -0
- package/dist/tokens.css +9 -0
- package/dist/ui/content-fields.js +3 -2
- package/dist/ui/content-fields.js.map +1 -1
- package/dist/ui/controls.js +3 -2
- package/dist/ui/controls.js.map +1 -1
- package/dist/ui/floating-panel.js +3 -2
- package/dist/ui/floating-panel.js.map +1 -1
- package/dist/ui/foundations.js +3 -2
- package/dist/ui/foundations.js.map +1 -1
- package/dist/ui/index.js +2 -2
- package/dist/ui/inspector.d.ts +23 -5
- package/dist/ui/inspector.js +75 -30
- package/dist/ui/inspector.js.map +1 -1
- package/dist/ui/overlay.js +2 -2
- package/dist/ui/overlay.js.map +1 -1
- package/dist/ui/tab.js +3 -2
- package/dist/ui/tab.js.map +1 -1
- package/package.json +1 -1
package/dist/context.d.ts
CHANGED
|
@@ -192,6 +192,12 @@ export interface KitServices {
|
|
|
192
192
|
* written. A rejection is named in a toast.
|
|
193
193
|
*/
|
|
194
194
|
aiCommand?: (kind: AiCommandKind, context: AiCommandContext) => string | void | Promise<string | void>;
|
|
195
|
+
/**
|
|
196
|
+
* The AI commands this host can back (look "v16"), e.g. without "translate" when it has no target-language picker.
|
|
197
|
+
* Present → the "BetterCMS AI" view lists only these, in AI_COMMANDS order, and an empty list removes the AI row.
|
|
198
|
+
* Absent → all seven.
|
|
199
|
+
*/
|
|
200
|
+
aiCommandKinds?: readonly AiCommandKind[];
|
|
195
201
|
/** In-place field comments. Absent and no `env.onComment` → the field shows no add-comment control. */
|
|
196
202
|
FieldComments?: React.ComponentType<KitFieldCommentsProps>;
|
|
197
203
|
/**
|
|
@@ -363,6 +369,8 @@ export interface KitEnv {
|
|
|
363
369
|
}) => void;
|
|
364
370
|
/** CPO D39: "inline" (default) shows help under the label; "tooltip" moves it behind the ⓘ — for dense hosts (grid cells, popovers). */
|
|
365
371
|
helpDisplay?: "inline" | "tooltip";
|
|
372
|
+
/** Look "v16" field counter type size: 11 (11/14, the inspector; default) or 12 (12/16, the content editor, editor.css:425). */
|
|
373
|
+
counterSize?: 11 | 12;
|
|
366
374
|
/** D61 Review changes: the host's change markers, present only while its History panel is open. */
|
|
367
375
|
review?: KitReview;
|
|
368
376
|
/** D61 field ⋯ › History: the host opens its one History panel on this field. Absent = no History item. */
|
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 /** several actions (prototype `notify` takes one or more); the kit toaster draws them all under look \"v16\",\n * the first one otherwise. Wins over `action`. */\n actions?: { 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/**\n * The slash menu's \"BetterCMS AI\" commands (look \"v16\", prototype content.jsx:1210). The host's `aiCommand` service\n * produces the text; without it the menu offers no AI row.\n */\nexport type AiCommandKind = \"prompt\" | \"continue\" | \"improve\" | \"shorter\" | \"summarize\" | \"translate\" | \"spelling\";\nexport const AI_COMMANDS: { id: AiCommandKind; label: string; description: string }[] = [\n { id: \"prompt\", label: \"Write a prompt\", description: \"Generate text from a prompt\" },\n { id: \"continue\", label: \"Continue writing\", description: \"Pick up where you stopped\" },\n { id: \"improve\", label: \"Improve writing\", description: \"Smooth tone and clarity\" },\n { id: \"shorter\", label: \"Make shorter\", description: \"Same point, fewer words\" },\n { id: \"summarize\", label: \"Summarize\", description: \"Pull out the key points\" },\n { id: \"translate\", label: \"Translate\", description: \"Into another language\" },\n { id: \"spelling\", label: \"Fix spelling\", description: \"Spelling and grammar\" },\n];\n/** The commands that rewrite the block above the caret; the others write new text at the caret. */\nexport const AI_REWRITE_COMMANDS: readonly AiCommandKind[] = [\"improve\", \"shorter\", \"translate\", \"spelling\"];\n/** What the body hands the host with a command. All plain text. */\nexport interface AiCommandContext {\n /** the whole body */\n text: string;\n /** everything above the caret's line (what Continue writing picks up and Summarize reads) */\n before: string;\n /** the block a rewrite command replaces: the text block right above the caret's line (\"\" for the writing commands) */\n target: string;\n /** what stands on the caret's line once \"/…\" is removed (a prompt typed inline) */\n line: string;\n /** a rewrite's target cut at its formatting (bold, italic, links, code…): its text runs in order, which joined\n * give `target`. An answer that keeps these runs (joined by AI_RUN_SEPARATOR, or keeping every formatted run's\n * words unchanged) keeps their formatting; any other answer replaces the target as plain text. [] otherwise. */\n runs: string[];\n}\n/** Join the rewritten `AiCommandContext.runs` with this (U+241E) to keep each run's formatting in a rewrite. */\nexport const AI_RUN_SEPARATOR = \"␞\";\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 /**\n * The slash menu's \"BetterCMS AI\" view (look \"v16\"). Absent → the slash menu has no AI row. The answer is plain text\n * (paragraphs split by a blank line): a rewrite command (AI_REWRITE_COMMANDS) replaces `context.target` with it, any\n * other command writes it at the caret's line. No answer (void) means the host showed its own UI and nothing is\n * written. A rejection is named in a toast.\n */\n aiCommand?: (kind: AiCommandKind, context: AiCommandContext) => string | void | Promise<string | void>;\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 * How the popover around `FieldComments` is drawn (REQ-3-7): its distance from the field, its side shift and its\n * class (width, and `!border-0 !bg-transparent !shadow-none` when the host's composer is the surface). `selection` is\n * true when it opens on selected words (the quote popover). Absent → 8 under the field, 280 to 420 wide.\n */\n fieldCommentsPopover?: (p: { selection: boolean }) => { sideOffset?: number; alignOffset?: number; className?: string };\n /**\n * A field WITH open threads: its count button opens the host's Comments panel on that field instead of the in-place\n * popover (REQ-3-7). Absent → the popover opens with the threads.\n */\n onOpenFieldThreads?: (docId: string, fieldKey: string) => void;\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\n/* ── Look: which design the engine draws ────────────────────────────── */\n/**\n * \"v2\" (default) is the kit's own look, on every dashboard route. \"v16\" is the Visual Editor inspector of prototype\n * editor-v16 (INSPECTOR-FRAMEWORK §3): FieldSection draws the Section header (16 icon, 14/20 medium, rule UNDER the\n * group), an array's rows sit in the grey item list card with Add inside and the \"n of max\" note, and an item screen\n * ends with the red Delete. A host opts in by wrapping its inspector in <KitLookProvider>; nothing else changes.\n */\nexport type KitLook = \"v2\" | \"v16\";\nconst LookCtx = React.createContext<KitLook>(\"v2\");\nexport function KitLookProvider({ look = \"v16\", children }: { look?: KitLook; children: React.ReactNode }) {\n return <LookCtx.Provider value={look}>{children}</LookCtx.Provider>;\n}\nexport const useKitLook = () => React.useContext(LookCtx);\n\n/**\n * P-FDOT (prototype inspector.jsx:1220-1226, kit.css:506-515): the field a canvas click opened. The host sets it to\n * the field's path key (pathKey(path), e.g. \"title\" or \"cta.label\"); that field's label gets the 6px violet dot, and\n * `flash` (any value that changes per click, e.g. a counter) runs the violet sweep across it once. The host clears it\n * (null) when the author clicks or types in the field. Null everywhere else: nothing is drawn.\n */\nexport interface KitFocusField {\n key: string;\n flash?: number | string;\n}\nconst FocusFieldCtx = React.createContext<KitFocusField | null>(null);\nexport const KitFocusFieldProvider = FocusFieldCtx.Provider;\nexport const useKitFocusField = () => React.useContext(FocusFieldCtx);\n"],"mappings":";;;;;;;;;;;;;AAyEA,IAAa,cAA2E;CACtF;EAAE,IAAI;EAAU,OAAO;EAAkB,aAAa;CAA8B;CACpF;EAAE,IAAI;EAAY,OAAO;EAAoB,aAAa;CAA4B;CACtF;EAAE,IAAI;EAAW,OAAO;EAAmB,aAAa;CAA0B;CAClF;EAAE,IAAI;EAAW,OAAO;EAAgB,aAAa;CAA0B;CAC/E;EAAE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c;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;AAUrD,IAAM,UAAU,MAAM,cAAuB,IAAI;AACjD,SAAgB,gBAAgB,EAAE,OAAO,OAAO,YAA2D;CACzG,OAAO,oBAAC,QAAQ,UAAT;EAAkB,OAAO;EAAO;CAA2B,CAAA;AACpE;AACA,IAAa,mBAAmB,MAAM,WAAW,OAAO;AAYxD,IAAM,gBAAgB,MAAM,cAAoC,IAAI;AACpE,IAAa,wBAAwB,cAAc;AACnD,IAAa,yBAAyB,MAAM,WAAW,aAAa"}
|
|
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 /** several actions (prototype `notify` takes one or more); the kit toaster draws them all under look \"v16\",\n * the first one otherwise. Wins over `action`. */\n actions?: { 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/**\n * The slash menu's \"BetterCMS AI\" commands (look \"v16\", prototype content.jsx:1210). The host's `aiCommand` service\n * produces the text; without it the menu offers no AI row.\n */\nexport type AiCommandKind = \"prompt\" | \"continue\" | \"improve\" | \"shorter\" | \"summarize\" | \"translate\" | \"spelling\";\nexport const AI_COMMANDS: { id: AiCommandKind; label: string; description: string }[] = [\n { id: \"prompt\", label: \"Write a prompt\", description: \"Generate text from a prompt\" },\n { id: \"continue\", label: \"Continue writing\", description: \"Pick up where you stopped\" },\n { id: \"improve\", label: \"Improve writing\", description: \"Smooth tone and clarity\" },\n { id: \"shorter\", label: \"Make shorter\", description: \"Same point, fewer words\" },\n { id: \"summarize\", label: \"Summarize\", description: \"Pull out the key points\" },\n { id: \"translate\", label: \"Translate\", description: \"Into another language\" },\n { id: \"spelling\", label: \"Fix spelling\", description: \"Spelling and grammar\" },\n];\n/** The commands that rewrite the block above the caret; the others write new text at the caret. */\nexport const AI_REWRITE_COMMANDS: readonly AiCommandKind[] = [\"improve\", \"shorter\", \"translate\", \"spelling\"];\n/** What the body hands the host with a command. All plain text. */\nexport interface AiCommandContext {\n /** the whole body */\n text: string;\n /** everything above the caret's line (what Continue writing picks up and Summarize reads) */\n before: string;\n /** the block a rewrite command replaces: the text block right above the caret's line (\"\" for the writing commands) */\n target: string;\n /** what stands on the caret's line once \"/…\" is removed (a prompt typed inline) */\n line: string;\n /** a rewrite's target cut at its formatting (bold, italic, links, code…): its text runs in order, which joined\n * give `target`. An answer that keeps these runs (joined by AI_RUN_SEPARATOR, or keeping every formatted run's\n * words unchanged) keeps their formatting; any other answer replaces the target as plain text. [] otherwise. */\n runs: string[];\n}\n/** Join the rewritten `AiCommandContext.runs` with this (U+241E) to keep each run's formatting in a rewrite. */\nexport const AI_RUN_SEPARATOR = \"␞\";\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 /**\n * The slash menu's \"BetterCMS AI\" view (look \"v16\"). Absent → the slash menu has no AI row. The answer is plain text\n * (paragraphs split by a blank line): a rewrite command (AI_REWRITE_COMMANDS) replaces `context.target` with it, any\n * other command writes it at the caret's line. No answer (void) means the host showed its own UI and nothing is\n * written. A rejection is named in a toast.\n */\n aiCommand?: (kind: AiCommandKind, context: AiCommandContext) => string | void | Promise<string | void>;\n /**\n * The AI commands this host can back (look \"v16\"), e.g. without \"translate\" when it has no target-language picker.\n * Present → the \"BetterCMS AI\" view lists only these, in AI_COMMANDS order, and an empty list removes the AI row.\n * Absent → all seven.\n */\n aiCommandKinds?: readonly AiCommandKind[];\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 * How the popover around `FieldComments` is drawn (REQ-3-7): its distance from the field, its side shift and its\n * class (width, and `!border-0 !bg-transparent !shadow-none` when the host's composer is the surface). `selection` is\n * true when it opens on selected words (the quote popover). Absent → 8 under the field, 280 to 420 wide.\n */\n fieldCommentsPopover?: (p: { selection: boolean }) => { sideOffset?: number; alignOffset?: number; className?: string };\n /**\n * A field WITH open threads: its count button opens the host's Comments panel on that field instead of the in-place\n * popover (REQ-3-7). Absent → the popover opens with the threads.\n */\n onOpenFieldThreads?: (docId: string, fieldKey: string) => void;\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 /** Look \"v16\" field counter type size: 11 (11/14, the inspector; default) or 12 (12/16, the content editor, editor.css:425). */\n counterSize?: 11 | 12;\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\n/* ── Look: which design the engine draws ────────────────────────────── */\n/**\n * \"v2\" (default) is the kit's own look, on every dashboard route. \"v16\" is the Visual Editor inspector of prototype\n * editor-v16 (INSPECTOR-FRAMEWORK §3): FieldSection draws the Section header (16 icon, 14/20 medium, rule UNDER the\n * group), an array's rows sit in the grey item list card with Add inside and the \"n of max\" note, and an item screen\n * ends with the red Delete. A host opts in by wrapping its inspector in <KitLookProvider>; nothing else changes.\n */\nexport type KitLook = \"v2\" | \"v16\";\nconst LookCtx = React.createContext<KitLook>(\"v2\");\nexport function KitLookProvider({ look = \"v16\", children }: { look?: KitLook; children: React.ReactNode }) {\n return <LookCtx.Provider value={look}>{children}</LookCtx.Provider>;\n}\nexport const useKitLook = () => React.useContext(LookCtx);\n\n/**\n * P-FDOT (prototype inspector.jsx:1220-1226, kit.css:506-515): the field a canvas click opened. The host sets it to\n * the field's path key (pathKey(path), e.g. \"title\" or \"cta.label\"); that field's label gets the 6px violet dot, and\n * `flash` (any value that changes per click, e.g. a counter) runs the violet sweep across it once. The host clears it\n * (null) when the author clicks or types in the field. Null everywhere else: nothing is drawn.\n */\nexport interface KitFocusField {\n key: string;\n flash?: number | string;\n}\nconst FocusFieldCtx = React.createContext<KitFocusField | null>(null);\nexport const KitFocusFie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ANGED
|
@@ -18,7 +18,7 @@ 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
20
|
import { V16ImageField, V16_IMAGE_ACCEPT } from "./media-v16.js";
|
|
21
|
-
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
|
+
import { FileControl, GalleryControl, ImageControl, ImageDetails, MediaPicker, NO_CROP_OUTSIDE_LIBRARY, NO_CROP_SIZELESS, VideoControl, VideoPreview, acceptsFile, cropChoice, fileNameFromUrl, formatBytes, fromAsset, isVideoUrl, normImage, useUpload, videoProvider, withCrop, youTubeId } from "./media.js";
|
|
22
22
|
import { ComponentSlotControl, SlotDepthContext, SlotPicker } from "./slot.js";
|
|
23
23
|
import { RT_PROSE, RichTextEditor } from "./rich-text/editor.js";
|
|
24
24
|
import { RichTextControl, RichTextExpandAction } from "./rich-text/control.js";
|
|
@@ -35,6 +35,6 @@ function registerKitControls() {
|
|
|
35
35
|
CONTROLS.button = ButtonControl;
|
|
36
36
|
}
|
|
37
37
|
//#endregion
|
|
38
|
-
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, PrefixedInput, 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, V16ImageField, V16_IMAGE_ACCEPT, V16_TEXT_SURFACE, 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
|
+
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, NO_CROP_SIZELESS, NUMBER_SCALE, NumberControl, PlainNumber, PrefixedInput, 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, V16ImageField, V16_IMAGE_ACCEPT, V16_TEXT_SURFACE, 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 };
|
|
39
39
|
|
|
40
40
|
//# sourceMappingURL=index.js.map
|
|
@@ -23,5 +23,7 @@ export interface V16ImageFieldProps {
|
|
|
23
23
|
onRemove: () => void;
|
|
24
24
|
/** the media library, where the host has one (offered beside the upload when there is no upload service) */
|
|
25
25
|
onLibrary?: () => void;
|
|
26
|
+
/** the preview's own size as it loads (`loaded`: its load event fired), so the crop can be cut or say why not */
|
|
27
|
+
onNatural?: (img: HTMLImageElement | null, loaded: boolean) => void;
|
|
26
28
|
}
|
|
27
|
-
export declare function V16ImageField({ id, label, readOnly, image, upload, alt, onAlt, onCrop, onRemove, onLibrary }: V16ImageFieldProps): import("react/jsx-runtime").JSX.Element;
|
|
29
|
+
export declare function V16ImageField({ id, label, readOnly, image, upload, alt, onAlt, onCrop, onRemove, onLibrary, onNatural }: V16ImageFieldProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -21,7 +21,7 @@ var V16_IMAGE_ACCEPT = "image/png,image/jpeg,image/webp";
|
|
|
21
21
|
var OK_TYPE = /^image\/(png|jpe?g|webp)$/;
|
|
22
22
|
var MAX_BYTES = 10485760;
|
|
23
23
|
var BTN = "grid size-7 shrink-0 place-items-center rounded-[6px] text-kit-insp-label outline-none transition-colors hover:bg-kit-insp-card hover:text-kit-insp-tip-title data-[popup-open]:bg-kit-insp-card data-[popup-open]:text-kit-insp-tip-title focus-visible:shadow-[0_0_0_2px_var(--kit-insp-accent)] [&_svg]:size-3.5";
|
|
24
|
-
function V16ImageField({ id, label, readOnly, image, upload, alt, onAlt, onCrop, onRemove, onLibrary }) {
|
|
24
|
+
function V16ImageField({ id, label, readOnly, image, upload, alt, onAlt, onCrop, onRemove, onLibrary, onNatural }) {
|
|
25
25
|
const { toast } = useKitServices();
|
|
26
26
|
const file = React.useRef(null);
|
|
27
27
|
const [over, setOver] = React.useState(false);
|
|
@@ -73,6 +73,8 @@ function V16ImageField({ id, label, readOnly, image, upload, alt, onAlt, onCrop,
|
|
|
73
73
|
children: /* @__PURE__ */ jsx("img", {
|
|
74
74
|
src: image.src,
|
|
75
75
|
alt: alt ?? "",
|
|
76
|
+
ref: (n) => onNatural?.(n, false),
|
|
77
|
+
onLoad: (e) => onNatural?.(e.currentTarget, true),
|
|
76
78
|
className: "size-full object-cover"
|
|
77
79
|
})
|
|
78
80
|
}), /* @__PURE__ */ jsxs("div", {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"media-v16.js","names":[],"sources":["../../src/controls/media-v16.tsx"],"sourcesContent":["/**\n * Look \"v16\": the image control as prototype editor-v16 `MediaField` (inspector.jsx:1080-1136, media.css; REQ-5-6\n * group C, F1369-F1385). The image control (media.tsx ImageControl) draws this inside `KitLookProvider look=\"v16\"`:\n * no image → a 164 high dashed zone (\"Drag and drop to upload or select\", \"PNG, JPG or WEBP · up to 10 MB\"),\n * drag-over \"Drop to upload\", a type / size refusal for 2.6s, the upload's progress round the zone with\n * a % pill, then \"Uploaded successfully!\" for 0.8s;\n * an image → a card (168 thumb, name, \"W × H · size\", Replace, ⋯ Replace image / Crop and focal point / Copy image\n * URL / Remove from section);\n * then the \"Alternative text\" field (where the placement stores alt text).\n * Every action is the real one: the upload goes through `KitServices.uploadMedia`, the crop through the control's own\n * details popover. A service the host does not provide is not offered, in words.\n */\nimport * as React from \"react\";\nimport { IconDots, IconLink, IconScan, IconTrash, IconUpload } from \"@tabler/icons-react\";\nimport { cn } from \"../lib/cn\";\nimport { useKitServices } from \"../context\";\nimport { Menu, MenuContent, MenuItem, MenuSeparator, MenuTrigger, Tooltip } from \"../ui/overlay\";\n\nexport const V16_IMAGE_ACCEPT = \"image/png,image/jpeg,image/webp\";\nconst OK_TYPE = /^image\\/(png|jpe?g|webp)$/;\nconst MAX_BYTES = 10 * 1024 * 1024;\n\nexport interface V16ImageFieldProps {\n id: string;\n label: string;\n readOnly?: boolean;\n /** the image, or none */\n image: { src: string; url: string; name: string; meta?: string } | null;\n /** media.tsx useUpload: `run` absent = no upload service */\n upload: { run?: (files: File[]) => void; progress: number | null; error: string | null };\n /** the stored alt text; undefined = this placement keeps no alt text (no field is drawn) */\n alt?: string;\n onAlt?: (alt: string) => void;\n onCrop?: () => void;\n onRemove: () => void;\n /** the media library, where the host has one (offered beside the upload when there is no upload service) */\n onLibrary?: () => void;\n}\n\nconst BTN =\n \"grid size-7 shrink-0 place-items-center rounded-[6px] text-kit-insp-label outline-none transition-colors hover:bg-kit-insp-card hover:text-kit-insp-tip-title data-[popup-open]:bg-kit-insp-card data-[popup-open]:text-kit-insp-tip-title focus-visible:shadow-[0_0_0_2px_var(--kit-insp-accent)] [&_svg]:size-3.5\";\n\nexport function V16ImageField({ id, label, readOnly, image, upload, alt, onAlt, onCrop, onRemove, onLibrary }: V16ImageFieldProps) {\n const { toast } = useKitServices();\n const file = React.useRef<HTMLInputElement>(null);\n const [over, setOver] = React.useState(false);\n const [refusal, setRefusal] = React.useState<string | null>(null);\n const [done, setDone] = React.useState(false);\n const busy = upload.progress != null;\n const wasBusy = React.useRef(false);\n React.useEffect(() => {\n // F1377: the finished upload says so for 800ms before the card replaces the zone\n if (wasBusy.current && !busy && !upload.error) {\n setDone(true);\n const t = window.setTimeout(() => setDone(false), 800);\n wasBusy.current = busy;\n return () => window.clearTimeout(t);\n }\n wasBusy.current = busy;\n }, [busy, upload.error]);\n React.useEffect(() => {\n if (!refusal) return;\n const t = window.setTimeout(() => setRefusal(null), 2600);\n return () => window.clearTimeout(t);\n }, [refusal]);\n\n const take = (f: File | undefined) => {\n if (!f || !upload.run || busy) return;\n if (!OK_TYPE.test(f.type)) return setRefusal(\"Only PNG, JPG or WEBP files are supported\");\n if (f.size > MAX_BYTES) return setRefusal(\"That image is over 10 MB\");\n setRefusal(null);\n upload.run([f]);\n };\n const pick = () => (upload.run ? file.current?.click() : onLibrary?.());\n const input = (\n <input\n ref={file}\n type=\"file\"\n hidden\n accept={V16_IMAGE_ACCEPT}\n onChange={(e) => {\n take(e.target.files?.[0]);\n e.target.value = \"\";\n }}\n />\n );\n\n const showCard = image && !done && !busy;\n const pct = upload.progress ?? 0;\n return (\n <div className=\"flex flex-col gap-4\">\n {showCard ? (\n <div className=\"flex flex-col gap-2 rounded-[10px] border border-kit-insp-line bg-kit-insp-tip-bg p-2\">\n <div className=\"h-[168px] w-full overflow-hidden rounded-[6px] bg-kit-insp-card\">\n <img src={image.src} alt={alt ?? \"\"} className=\"size-full object-cover\" />\n </div>\n <div className=\"flex items-center gap-1\">\n <div className=\"flex min-w-0 flex-1 flex-col gap-0.5\">\n <span className=\"truncate text-[13px] font-medium leading-4 text-kit-insp-tip-title\">{image.name || \"image\"}</span>\n {image.meta ? <span className=\"truncate text-[12px] leading-[15px] text-kit-fg-3 tabular-nums\">{image.meta}</span> : null}\n </div>\n {readOnly ? null : (\n <>\n {upload.run || onLibrary ? (\n <Tooltip content=\"Replace image\">\n <button type=\"button\" aria-label=\"Replace image\" className={BTN} onClick={pick}>\n <IconUpload stroke={1.2} aria-hidden />\n </button>\n </Tooltip>\n ) : null}\n <Menu>\n <MenuTrigger aria-label=\"Image actions\" className={BTN}>\n <IconDots stroke={1.5} aria-hidden />\n </MenuTrigger>\n <MenuContent align=\"end\" className=\"w-[240px] min-w-[240px]\">\n {upload.run || onLibrary ? (\n <MenuItem icon={<IconUpload stroke={1.5} />} onClick={pick}>\n Replace image\n </MenuItem>\n ) : null}\n {onCrop ? (\n <MenuItem icon={<IconScan stroke={1.5} />} onClick={onCrop}>\n Crop and focal point\n </MenuItem>\n ) : null}\n <MenuItem\n icon={<IconLink stroke={1.5} />}\n onClick={() => {\n const w = navigator.clipboard?.writeText(image.url);\n if (!w) return toast?.(\"Copy is not available in this browser\");\n w.then(() => toast?.(\"Image URL copied\"), () => toast?.(\"The browser refused to copy the address\"));\n }}\n >\n Copy image URL\n </MenuItem>\n <MenuSeparator />\n <MenuItem danger icon={<IconTrash stroke={1.5} />} onClick={onRemove}>\n Remove from section\n </MenuItem>\n </MenuContent>\n </Menu>\n </>\n )}\n </div>\n </div>\n ) : (\n <div\n id={id}\n role=\"button\"\n tabIndex={readOnly ? -1 : 0}\n aria-busy={busy || undefined}\n aria-disabled={readOnly || (!upload.run && !onLibrary) || undefined}\n aria-label={`${label}: drag and drop to upload or select`}\n onKeyDown={(e) => {\n if (e.target !== e.currentTarget || busy || readOnly) return;\n if (e.key === \"Enter\" || e.key === \" \") {\n e.preventDefault();\n pick();\n }\n }}\n onDragOver={(e) => {\n if (readOnly || busy || !upload.run || !e.dataTransfer.types.includes(\"Files\")) return;\n e.preventDefault();\n setOver(true);\n }}\n onDragLeave={() => setOver(false)}\n onDrop={(e) => {\n if (readOnly || !upload.run) return;\n e.preventDefault();\n setOver(false);\n take(e.dataTransfer.files[0]);\n }}\n className={cn(\n \"relative flex h-[164px] w-full flex-col items-center justify-center rounded-[16px] border-2 border-dashed border-kit-insp-line-strong bg-kit-insp-card text-center outline-none transition-[background-color,border-color] duration-150 ease-out focus-visible:border-kit-insp-accent\",\n over && \"border-kit-insp-accent bg-kit-insp-zone-over\",\n refusal && \"border-kit-insp-error\",\n busy && \"border-transparent bg-kit-insp-tip-bg\",\n )}\n >\n {busy ? (\n <>\n <svg aria-hidden className=\"pointer-events-none absolute -inset-0.5 h-[calc(100%+4px)] w-[calc(100%+4px)] overflow-visible\">\n <rect x=\"1\" y=\"1\" rx=\"16\" style={{ width: \"calc(100% - 2px)\", height: \"calc(100% - 2px)\" }} fill=\"none\" stroke=\"var(--kit-insp-line)\" strokeWidth=\"1.5\" />\n <rect x=\"1\" y=\"1\" rx=\"16\" style={{ width: \"calc(100% - 2px)\", height: \"calc(100% - 2px)\" }} fill=\"none\" stroke=\"var(--kit-insp-accent)\" strokeWidth=\"1.5\" pathLength={100} strokeDasharray={`${pct} 100`} className=\"transition-[stroke-dasharray] duration-[60ms] ease-linear\" />\n </svg>\n <span className=\"absolute -top-[11px] left-1/2 h-[18px] min-w-[38px] -translate-x-1/2 rounded-full bg-kit-insp-accent px-1.5 text-[11px] font-semibold leading-[18px] text-white tabular-nums\">{pct}%</span>\n </>\n ) : null}\n <span className={cn(\"mb-3.5 grid size-10 place-items-center rounded-full bg-kit-insp-zone-over text-kit-insp-accent-fg\", busy && \"border border-kit-insp-line bg-kit-insp-tip-bg\")}>\n <IconUpload className=\"size-5\" stroke={1.5} aria-hidden />\n </span>\n <span className={cn(\"text-[13px] font-medium leading-4 text-kit-insp-tip-body\", refusal && \"text-kit-insp-count-over\")}>\n {refusal ?? (over ? \"Drop to upload\" : busy ? \"Uploading…\" : (\n <>\n Drag and drop to upload or{\" \"}\n <button\n type=\"button\"\n tabIndex={-1}\n disabled={readOnly || (!upload.run && !onLibrary)}\n onClick={(e) => {\n e.stopPropagation();\n pick();\n }}\n className=\"font-medium text-kit-insp-zone-link hover:underline disabled:no-underline\"\n >\n select\n </button>\n </>\n ))}\n </span>\n <span className={cn(\"mt-1.5 text-[12px] leading-[15px] text-kit-fg-3\", done && \"text-kit-insp-zone-done\")}>\n {done ? \"Uploaded successfully!\" : upload.run ? \"PNG, JPG or WEBP · up to 10 MB\" : onLibrary ? \"Pick one from the media library\" : \"Uploading is not available here\"}\n </span>\n </div>\n )}\n {upload.error ? (\n <p role=\"alert\" className=\"-mt-2 text-[12px] leading-4 text-kit-insp-error\">\n {upload.error}\n </p>\n ) : null}\n {input}\n {alt !== undefined && onAlt ? (\n <div className=\"flex flex-col gap-2\">\n <label htmlFor={`${id}-alt`} className=\"text-[13px] font-medium leading-4 text-kit-insp-tip-body\">\n Alternative text\n </label>\n <input\n id={`${id}-alt`}\n value={alt}\n readOnly={readOnly}\n placeholder=\"Describe the image for screen readers\"\n onChange={(e) => onAlt(e.target.value)}\n className=\"h-[34px] w-full rounded-[6px] border border-transparent bg-kit-insp-card px-2.5 text-[13px] leading-[18px] tracking-[-0.1625px] text-kit-insp-tip-title outline-none transition-[background-color,border-color] duration-[120ms] ease-out placeholder:text-kit-fg-3 focus:border-kit-insp-accent focus:bg-kit-insp-card-focus\"\n />\n </div>\n ) : null}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAkBA,IAAa,mBAAmB;AAChC,IAAM,UAAU;AAChB,IAAM,YAAY;AAmBlB,IAAM,MACJ;AAEF,SAAgB,cAAc,EAAE,IAAI,OAAO,UAAU,OAAO,QAAQ,KAAK,OAAO,QAAQ,UAAU,aAAiC;CACjI,MAAM,EAAE,UAAU,eAAe;CACjC,MAAM,OAAO,MAAM,OAAyB,IAAI;CAChD,MAAM,CAAC,MAAM,WAAW,MAAM,SAAS,KAAK;CAC5C,MAAM,CAAC,SAAS,cAAc,MAAM,SAAwB,IAAI;CAChE,MAAM,CAAC,MAAM,WAAW,MAAM,SAAS,KAAK;CAC5C,MAAM,OAAO,OAAO,YAAY;CAChC,MAAM,UAAU,MAAM,OAAO,KAAK;CAClC,MAAM,gBAAgB;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ACH,CAAA,IAAA;EACD;;AAET"}
|
|
1
|
+
{"version":3,"file":"media-v16.js","names":[],"sources":["../../src/controls/media-v16.tsx"],"sourcesContent":["/**\n * Look \"v16\": the image control as prototype editor-v16 `MediaField` (inspector.jsx:1080-1136, media.css; REQ-5-6\n * group C, F1369-F1385). The image control (media.tsx ImageControl) draws this inside `KitLookProvider look=\"v16\"`:\n * no image → a 164 high dashed zone (\"Drag and drop to upload or select\", \"PNG, JPG or WEBP · up to 10 MB\"),\n * drag-over \"Drop to upload\", a type / size refusal for 2.6s, the upload's progress round the zone with\n * a % pill, then \"Uploaded successfully!\" for 0.8s;\n * an image → a card (168 thumb, name, \"W × H · size\", Replace, ⋯ Replace image / Crop and focal point / Copy image\n * URL / Remove from section);\n * then the \"Alternative text\" field (where the placement stores alt text).\n * Every action is the real one: the upload goes through `KitServices.uploadMedia`, the crop through the control's own\n * details popover. A service the host does not provide is not offered, in words.\n */\nimport * as React from \"react\";\nimport { IconDots, IconLink, IconScan, IconTrash, IconUpload } from \"@tabler/icons-react\";\nimport { cn } from \"../lib/cn\";\nimport { useKitServices } from \"../context\";\nimport { Menu, MenuContent, MenuItem, MenuSeparator, MenuTrigger, Tooltip } from \"../ui/overlay\";\n\nexport const V16_IMAGE_ACCEPT = \"image/png,image/jpeg,image/webp\";\nconst OK_TYPE = /^image\\/(png|jpe?g|webp)$/;\nconst MAX_BYTES = 10 * 1024 * 1024;\n\nexport interface V16ImageFieldProps {\n id: string;\n label: string;\n readOnly?: boolean;\n /** the image, or none */\n image: { src: string; url: string; name: string; meta?: string } | null;\n /** media.tsx useUpload: `run` absent = no upload service */\n upload: { run?: (files: File[]) => void; progress: number | null; error: string | null };\n /** the stored alt text; undefined = this placement keeps no alt text (no field is drawn) */\n alt?: string;\n onAlt?: (alt: string) => void;\n onCrop?: () => void;\n onRemove: () => void;\n /** the media library, where the host has one (offered beside the upload when there is no upload service) */\n onLibrary?: () => void;\n /** the preview's own size as it loads (`loaded`: its load event fired), so the crop can be cut or say why not */\n onNatural?: (img: HTMLImageElement | null, loaded: boolean) => void;\n}\n\nconst BTN =\n \"grid size-7 shrink-0 place-items-center rounded-[6px] text-kit-insp-label outline-none transition-colors hover:bg-kit-insp-card hover:text-kit-insp-tip-title data-[popup-open]:bg-kit-insp-card data-[popup-open]:text-kit-insp-tip-title focus-visible:shadow-[0_0_0_2px_var(--kit-insp-accent)] [&_svg]:size-3.5\";\n\nexport function V16ImageField({ id, label, readOnly, image, upload, alt, onAlt, onCrop, onRemove, onLibrary, onNatural }: V16ImageFieldProps) {\n const { toast } = useKitServices();\n const file = React.useRef<HTMLInputElement>(null);\n const [over, setOver] = React.useState(false);\n const [refusal, setRefusal] = React.useState<string | null>(null);\n const [done, setDone] = React.useState(false);\n const busy = upload.progress != null;\n const wasBusy = React.useRef(false);\n React.useEffect(() => {\n // F1377: the finished upload says so for 800ms before the card replaces the zone\n if (wasBusy.current && !busy && !upload.error) {\n setDone(true);\n const t = window.setTimeout(() => setDone(false), 800);\n wasBusy.current = busy;\n return () => window.clearTimeout(t);\n }\n wasBusy.current = busy;\n }, [busy, upload.error]);\n React.useEffect(() => {\n if (!refusal) return;\n const t = window.setTimeout(() => setRefusal(null), 2600);\n return () => window.clearTimeout(t);\n }, [refusal]);\n\n const take = (f: File | undefined) => {\n if (!f || !upload.run || busy) return;\n if (!OK_TYPE.test(f.type)) return setRefusal(\"Only PNG, JPG or WEBP files are supported\");\n if (f.size > MAX_BYTES) return setRefusal(\"That image is over 10 MB\");\n setRefusal(null);\n upload.run([f]);\n };\n const pick = () => (upload.run ? file.current?.click() : onLibrary?.());\n const input = (\n <input\n ref={file}\n type=\"file\"\n hidden\n accept={V16_IMAGE_ACCEPT}\n onChange={(e) => {\n take(e.target.files?.[0]);\n e.target.value = \"\";\n }}\n />\n );\n\n const showCard = image && !done && !busy;\n const pct = upload.progress ?? 0;\n return (\n <div className=\"flex flex-col gap-4\">\n {showCard ? (\n <div className=\"flex flex-col gap-2 rounded-[10px] border border-kit-insp-line bg-kit-insp-tip-bg p-2\">\n <div className=\"h-[168px] w-full overflow-hidden rounded-[6px] bg-kit-insp-card\">\n <img src={image.src} alt={alt ?? \"\"} ref={(n) => onNatural?.(n, false)} onLoad={(e) => onNatural?.(e.currentTarget, true)} className=\"size-full object-cover\" />\n </div>\n <div className=\"flex items-center gap-1\">\n <div className=\"flex min-w-0 flex-1 flex-col gap-0.5\">\n <span className=\"truncate text-[13px] font-medium leading-4 text-kit-insp-tip-title\">{image.name || \"image\"}</span>\n {image.meta ? <span className=\"truncate text-[12px] leading-[15px] text-kit-fg-3 tabular-nums\">{image.meta}</span> : null}\n </div>\n {readOnly ? null : (\n <>\n {upload.run || onLibrary ? (\n <Tooltip content=\"Replace image\">\n <button type=\"button\" aria-label=\"Replace image\" className={BTN} onClick={pick}>\n <IconUpload stroke={1.2} aria-hidden />\n </button>\n </Tooltip>\n ) : null}\n <Menu>\n <MenuTrigger aria-label=\"Image actions\" className={BTN}>\n <IconDots stroke={1.5} aria-hidden />\n </MenuTrigger>\n <MenuContent align=\"end\" className=\"w-[240px] min-w-[240px]\">\n {upload.run || onLibrary ? (\n <MenuItem icon={<IconUpload stroke={1.5} />} onClick={pick}>\n Replace image\n </MenuItem>\n ) : null}\n {onCrop ? (\n <MenuItem icon={<IconScan stroke={1.5} />} onClick={onCrop}>\n Crop and focal point\n </MenuItem>\n ) : null}\n <MenuItem\n icon={<IconLink stroke={1.5} />}\n onClick={() => {\n const w = navigator.clipboard?.writeText(image.url);\n if (!w) return toast?.(\"Copy is not available in this browser\");\n w.then(() => toast?.(\"Image URL copied\"), () => toast?.(\"The browser refused to copy the address\"));\n }}\n >\n Copy image URL\n </MenuItem>\n <MenuSeparator />\n <MenuItem danger icon={<IconTrash stroke={1.5} />} onClick={onRemove}>\n Remove from section\n </MenuItem>\n </MenuContent>\n </Menu>\n </>\n )}\n </div>\n </div>\n ) : (\n <div\n id={id}\n role=\"button\"\n tabIndex={readOnly ? -1 : 0}\n aria-busy={busy || undefined}\n aria-disabled={readOnly || (!upload.run && !onLibrary) || undefined}\n aria-label={`${label}: drag and drop to upload or select`}\n onKeyDown={(e) => {\n if (e.target !== e.currentTarget || busy || readOnly) return;\n if (e.key === \"Enter\" || e.key === \" \") {\n e.preventDefault();\n pick();\n }\n }}\n onDragOver={(e) => {\n if (readOnly || busy || !upload.run || !e.dataTransfer.types.includes(\"Files\")) return;\n e.preventDefault();\n setOver(true);\n }}\n onDragLeave={() => setOver(false)}\n onDrop={(e) => {\n if (readOnly || !upload.run) return;\n e.preventDefault();\n setOver(false);\n take(e.dataTransfer.files[0]);\n }}\n className={cn(\n \"relative flex h-[164px] w-full flex-col items-center justify-center rounded-[16px] border-2 border-dashed border-kit-insp-line-strong bg-kit-insp-card text-center outline-none transition-[background-color,border-color] duration-150 ease-out focus-visible:border-kit-insp-accent\",\n over && \"border-kit-insp-accent bg-kit-insp-zone-over\",\n refusal && \"border-kit-insp-error\",\n busy && \"border-transparent bg-kit-insp-tip-bg\",\n )}\n >\n {busy ? (\n <>\n <svg aria-hidden className=\"pointer-events-none absolute -inset-0.5 h-[calc(100%+4px)] w-[calc(100%+4px)] overflow-visible\">\n <rect x=\"1\" y=\"1\" rx=\"16\" style={{ width: \"calc(100% - 2px)\", height: \"calc(100% - 2px)\" }} fill=\"none\" stroke=\"var(--kit-insp-line)\" strokeWidth=\"1.5\" />\n <rect x=\"1\" y=\"1\" rx=\"16\" style={{ width: \"calc(100% - 2px)\", height: \"calc(100% - 2px)\" }} fill=\"none\" stroke=\"var(--kit-insp-accent)\" strokeWidth=\"1.5\" pathLength={100} strokeDasharray={`${pct} 100`} className=\"transition-[stroke-dasharray] duration-[60ms] ease-linear\" />\n </svg>\n <span className=\"absolute -top-[11px] left-1/2 h-[18px] min-w-[38px] -translate-x-1/2 rounded-full bg-kit-insp-accent px-1.5 text-[11px] font-semibold leading-[18px] text-white tabular-nums\">{pct}%</span>\n </>\n ) : null}\n <span className={cn(\"mb-3.5 grid size-10 place-items-center rounded-full bg-kit-insp-zone-over text-kit-insp-accent-fg\", busy && \"border border-kit-insp-line bg-kit-insp-tip-bg\")}>\n <IconUpload className=\"size-5\" stroke={1.5} aria-hidden />\n </span>\n <span className={cn(\"text-[13px] font-medium leading-4 text-kit-insp-tip-body\", refusal && \"text-kit-insp-count-over\")}>\n {refusal ?? (over ? \"Drop to upload\" : busy ? \"Uploading…\" : (\n <>\n Drag and drop to upload or{\" \"}\n <button\n type=\"button\"\n tabIndex={-1}\n disabled={readOnly || (!upload.run && !onLibrary)}\n onClick={(e) => {\n e.stopPropagation();\n pick();\n }}\n className=\"font-medium text-kit-insp-zone-link hover:underline disabled:no-underline\"\n >\n select\n </button>\n </>\n ))}\n </span>\n <span className={cn(\"mt-1.5 text-[12px] leading-[15px] text-kit-fg-3\", done && \"text-kit-insp-zone-done\")}>\n {done ? \"Uploaded successfully!\" : upload.run ? \"PNG, JPG or WEBP · up to 10 MB\" : onLibrary ? \"Pick one from the media library\" : \"Uploading is not available here\"}\n </span>\n </div>\n )}\n {upload.error ? (\n <p role=\"alert\" className=\"-mt-2 text-[12px] leading-4 text-kit-insp-error\">\n {upload.error}\n </p>\n ) : null}\n {input}\n {alt !== undefined && onAlt ? (\n <div className=\"flex flex-col gap-2\">\n <label htmlFor={`${id}-alt`} className=\"text-[13px] font-medium leading-4 text-kit-insp-tip-body\">\n Alternative text\n </label>\n <input\n id={`${id}-alt`}\n value={alt}\n readOnly={readOnly}\n placeholder=\"Describe the image for screen readers\"\n onChange={(e) => onAlt(e.target.value)}\n className=\"h-[34px] w-full rounded-[6px] border border-transparent bg-kit-insp-card px-2.5 text-[13px] leading-[18px] tracking-[-0.1625px] text-kit-insp-tip-title outline-none transition-[background-color,border-color] duration-[120ms] ease-out placeholder:text-kit-fg-3 focus:border-kit-insp-accent focus:bg-kit-insp-card-focus\"\n />\n </div>\n ) : null}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAkBA,IAAa,mBAAmB;AAChC,IAAM,UA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ACN,oBAAC,QAAD;MAAM,WAAW,GAAG,mDAAmD,QAAQ,yBAAyB;MACrG,UAAA,OAAO,2BAA2B,OAAO,MAAM,mCAAmC,YAAY,oCAAoC;KAC/H,CAAA;IACH;;GAEN,OAAO,QACN,oBAAC,KAAD;IAAG,MAAK;IAAQ,WAAU;IACvB,UAAA,OAAO;GACP,CAAA,IACD;GACH;GACA,QAAQ,KAAA,KAAa,QACpB,qBAAC,OAAD;IAAK,WAAU;IAAf,UAAA,CACE,oBAAC,SAAD;KAAO,SAAS,GAAG,GAAG;KAAO,WAAU;KAA2D,UAAA;IAE3F,CAAA,GACP,oBAAC,SAAD;KACE,IAAI,GAAG,GAAG;KACV,OAAO;KACG;KACV,aAAY;KACZ,WAAW,MAAM,MAAM,EAAE,OAAO,KAAK;KACrC,WAAU;IACX,CAAA,CACE;GACH,CAAA,IAAA;EACD;;AAET"}
|
package/dist/controls/media.d.ts
CHANGED
|
@@ -72,7 +72,9 @@ export declare function withCrop(v: ImageValue, choice: V2ImageCrop, size: {
|
|
|
72
72
|
}): ImageValue;
|
|
73
73
|
/** RP-047: why a picture from outside the media library offers no crop (its URL cannot carry one). */
|
|
74
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
|
-
|
|
75
|
+
/** A picture that loaded with no size of its own (an SVG with no width and height): a crop is cut from a size. */
|
|
76
|
+
export declare const NO_CROP_SIZELESS = "SVGs can't be cropped: this one has no size of its own. The focal point still applies.";
|
|
77
|
+
export declare function ImageDetails({ v, onChange, readOnly, label, urlOnly, altOnly, framingOnly, canCrop, size, sizeless, asset, fit, }: {
|
|
76
78
|
v: ImageValue;
|
|
77
79
|
onChange: (n: ImageValue) => void;
|
|
78
80
|
readOnly?: boolean;
|
|
@@ -88,6 +90,8 @@ export declare function ImageDetails({ v, onChange, readOnly, label, urlOnly, al
|
|
|
88
90
|
w: number;
|
|
89
91
|
h: number;
|
|
90
92
|
};
|
|
93
|
+
/** the picture finished loading with no size of its own (an SVG): the crop is off and says why, never "still loading" */
|
|
94
|
+
sizeless?: boolean;
|
|
91
95
|
asset?: KitMediaAsset;
|
|
92
96
|
/** fitOf's answer for this picture: a logo or an icon field sits whole in the pad, on the checker */
|
|
93
97
|
fit?: "contain" | "cover";
|
package/dist/controls/media.js
CHANGED
|
@@ -355,7 +355,9 @@ function withCrop(v, choice, size) {
|
|
|
355
355
|
}
|
|
356
356
|
/** RP-047: why a picture from outside the media library offers no crop (its URL cannot carry one). */
|
|
357
357
|
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.";
|
|
358
|
-
|
|
358
|
+
/** A picture that loaded with no size of its own (an SVG with no width and height): a crop is cut from a size. */
|
|
359
|
+
var NO_CROP_SIZELESS = "SVGs can't be cropped: this one has no size of its own. The focal point still applies.";
|
|
360
|
+
function ImageDetails({ v, onChange, readOnly, label, urlOnly, altOnly = false, framingOnly = false, canCrop = true, size, sizeless = false, asset, fit = "cover" }) {
|
|
359
361
|
const { src } = useMedia();
|
|
360
362
|
const focal = v.focal ?? {
|
|
361
363
|
x: 50,
|
|
@@ -485,6 +487,9 @@ function ImageDetails({ v, onChange, readOnly, label, urlOnly, altOnly = false,
|
|
|
485
487
|
!canCrop ? /* @__PURE__ */ jsx(Reason, {
|
|
486
488
|
tone: "muted",
|
|
487
489
|
children: NO_CROP_OUTSIDE_LIBRARY
|
|
490
|
+
}) : !size && sizeless ? /* @__PURE__ */ jsx(Reason, {
|
|
491
|
+
tone: "muted",
|
|
492
|
+
children: NO_CROP_SIZELESS
|
|
488
493
|
}) : !size && !readOnly ? /* @__PURE__ */ jsx("span", {
|
|
489
494
|
className: "text-kit-2xs text-kit-fg-3",
|
|
490
495
|
children: "The crop is cut from the picture's size, which is still loading."
|
|
@@ -661,12 +666,21 @@ function ImageControl({ field, value, onChange: write, readOnly, id, path }) {
|
|
|
661
666
|
const accept = field.svgOnly ? "image/svg+xml" : "image/*";
|
|
662
667
|
const kinds = field.svgOnly ? ["svg"] : ["image", "svg"];
|
|
663
668
|
const [loaded, setLoaded] = React.useState();
|
|
664
|
-
const natural = loaded && v && loaded.url === v.url ? {
|
|
669
|
+
const natural = loaded && v && loaded.url === v.url && loaded.w > 0 ? {
|
|
665
670
|
w: loaded.w,
|
|
666
671
|
h: loaded.h
|
|
667
672
|
} : void 0;
|
|
668
|
-
|
|
669
|
-
|
|
673
|
+
/** `onLoad`: the load event fired, so a missing size is the picture's own (an SVG with none), not a load in progress */
|
|
674
|
+
const readNatural = (img, onLoad = false) => {
|
|
675
|
+
if (!img || !v || !img.complete && !onLoad) return;
|
|
676
|
+
if (!img.naturalWidth || !img.naturalHeight) {
|
|
677
|
+
if (onLoad) setLoaded((prev) => prev && prev.url === v.url && prev.w === 0 ? prev : {
|
|
678
|
+
url: v.url,
|
|
679
|
+
w: 0,
|
|
680
|
+
h: 0
|
|
681
|
+
});
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
670
684
|
const next = {
|
|
671
685
|
url: v.url,
|
|
672
686
|
w: img.naturalWidth,
|
|
@@ -679,6 +693,7 @@ function ImageControl({ field, value, onChange: write, readOnly, id, path }) {
|
|
|
679
693
|
w: asset.width,
|
|
680
694
|
h: asset.height
|
|
681
695
|
} : stored ?? natural;
|
|
696
|
+
const sizeless = !size && !!v && loaded?.url === v.url && loaded.w === 0;
|
|
682
697
|
const fit = fitOf(value, field);
|
|
683
698
|
const onChange = (n) => {
|
|
684
699
|
if (!n) return write(urlOnly ? "" : null);
|
|
@@ -773,7 +788,8 @@ function ImageControl({ field, value, onChange: write, readOnly, id, path }) {
|
|
|
773
788
|
}) : void 0,
|
|
774
789
|
onCrop: v && !urlOnly && !altOnly ? () => window.setTimeout(() => setDetails(true), 0) : void 0,
|
|
775
790
|
onRemove: () => onChange(null),
|
|
776
|
-
onLibrary: library
|
|
791
|
+
onLibrary: library,
|
|
792
|
+
onNatural: readNatural
|
|
777
793
|
})
|
|
778
794
|
}),
|
|
779
795
|
v ? /* @__PURE__ */ jsx(PopoverContent, {
|
|
@@ -788,6 +804,7 @@ function ImageControl({ field, value, onChange: write, readOnly, id, path }) {
|
|
|
788
804
|
urlOnly,
|
|
789
805
|
altOnly,
|
|
790
806
|
size,
|
|
807
|
+
sizeless,
|
|
791
808
|
asset,
|
|
792
809
|
fit
|
|
793
810
|
})
|
|
@@ -897,7 +914,7 @@ function ImageControl({ field, value, onChange: write, readOnly, id, path }) {
|
|
|
897
914
|
src: src(v.url),
|
|
898
915
|
alt: alt ?? "",
|
|
899
916
|
ref: readNatural,
|
|
900
|
-
onLoad: (e) => readNatural(e.currentTarget),
|
|
917
|
+
onLoad: (e) => readNatural(e.currentTarget, true),
|
|
901
918
|
className: fit === "contain" ? "size-full object-contain" : "size-full object-cover",
|
|
902
919
|
style: fit === "contain" ? void 0 : { objectPosition: `${focal.x}% ${focal.y}%` }
|
|
903
920
|
})
|
|
@@ -1021,6 +1038,7 @@ function ImageControl({ field, value, onChange: write, readOnly, id, path }) {
|
|
|
1021
1038
|
urlOnly,
|
|
1022
1039
|
altOnly,
|
|
1023
1040
|
size,
|
|
1041
|
+
sizeless,
|
|
1024
1042
|
asset,
|
|
1025
1043
|
fit
|
|
1026
1044
|
})
|
|
@@ -1521,6 +1539,6 @@ function VideoControl({ field, value, onChange, readOnly, id, onBlur }) {
|
|
|
1521
1539
|
});
|
|
1522
1540
|
}
|
|
1523
1541
|
//#endregion
|
|
1524
|
-
export { FileControl, GalleryControl, ImageControl, ImageDetails, MediaPicker, NO_CROP_OUTSIDE_LIBRARY, VideoControl, VideoPreview, acceptsFile, cropChoice, fileNameFromUrl, formatBytes, fromAsset, isVideoUrl, normImage, useUpload, videoProvider, withCrop, youTubeId };
|
|
1542
|
+
export { FileControl, GalleryControl, ImageControl, ImageDetails, MediaPicker, NO_CROP_OUTSIDE_LIBRARY, NO_CROP_SIZELESS, VideoControl, VideoPreview, acceptsFile, cropChoice, fileNameFromUrl, formatBytes, fromAsset, isVideoUrl, normImage, useUpload, videoProvider, withCrop, youTubeId };
|
|
1525
1543
|
|
|
1526
1544
|
//# sourceMappingURL=media.js.map
|