@bettercms-ai/next 0.38.0 → 0.40.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/README.md +33 -4
- package/dist/blocks.js +139 -23
- package/dist/blocks.js.map +1 -1
- package/dist/draft-bridge.js +139 -23
- package/dist/draft-bridge.js.map +1 -1
- package/dist/elements.d.ts +8 -1
- package/dist/elements.js +21 -0
- package/dist/elements.js.map +1 -1
- package/dist/form.d.ts +33 -1
- package/dist/form.js +142 -24
- package/dist/form.js.map +1 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +23 -2
- package/dist/index.js.map +1 -1
- package/dist/search.js +1 -1
- package/dist/search.js.map +1 -1
- package/package.json +4 -4
package/dist/elements.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/field.tsx","../src/image.tsx","../src/button.tsx","../src/field-attrs.ts","../src/section-root.ts"],"sourcesContent":["/**\n * <BcmsField> — tag an entry field's rendered value with its identity so the\n * BetterCMS visual editor can bind click-to-edit deterministically (mirrors\n * Sanity's `data-sanity` / BaseHub's `data-basehub`). Entry-backed templates\n * hand-render field values (`f.title`, `f.body.html`), so the field `path` is\n * declared here by the author — the delivery payload carries no source-map.\n *\n * Server-safe (no hooks): renders in a Next Server Component. When the child is ONE\n * DOM element (`<h1>`, `<p>`), the attributes go on that element and nothing is added to\n * the page: `.hero > h1` and every animation target stay what the author wrote. Text,\n * several children, or a component (which may not pass unknown props on) are wrapped in a\n * `display:contents` span as before; pass `as` to carry the attributes on a real wrapper.\n * Twin: BcmsField.astro in @bettercms-ai/astro.\n *\n * `path` follows the editor grammar: `title` · `hero.title` · `columns[0].links[2].href`\n * (dotted keys and any number of `[n]` indices). For images, put the attributes on the\n * `<img>` itself (`kind=\"image\"` reflection patches `.src`), not on a wrapper:\n * <img src={imageValueUrl(f.cover, { w: 1200 })} data-bcms-field=\"cover\" data-bcms-kind=\"image\" />\n * `imageValueUrl` (re-exported from this package) applies the value's per-placement `crop` and\n * `focal`; `.url` alone would drop them. For a cover-fit box add\n * `style={{ objectPosition: imageValueObjectPosition(f.cover) ?? undefined }}`.\n */\nimport { Children, cloneElement, isValidElement, type ElementType, type ReactElement, type ReactNode } from \"react\";\n\nexport interface BcmsFieldProps {\n /** Field path in the editor grammar, e.g. `title` or `facts[2].label`. */\n path: string;\n /** Kind hint the editor's reflection branches on. Omit for plain text/number. */\n kind?: \"richtext\" | \"image\";\n /** Wrapper element. Without it: no wrapper around a single DOM element, a `display:contents` span around anything else. */\n as?: ElementType;\n children: ReactNode;\n}\n\nexport function BcmsField({ path, kind, as, children }: BcmsFieldProps) {\n const Tag = as ?? \"span\";\n const only = as ? [] : Children.toArray(children);\n const sole = only.length === 1 && isValidElement(only[0]) && typeof only[0].type === \"string\" ? (only[0] as ReactElement<Record<string, unknown>>) : null;\n // An element that already declares a field keeps its own address: wrapped, as before.\n if (sole && sole.props[\"data-bcms-field\"] === undefined && sole.props[\"data-bcms-layout-field\"] === undefined) {\n return cloneElement(sole, { \"data-bcms-field\": path, \"data-bcms-kind\": kind });\n }\n return (\n <Tag\n data-bcms-field={path}\n data-bcms-kind={kind}\n style={as ? undefined : { display: \"contents\" }}\n >\n {children}\n </Tag>\n );\n}\n","/**\n * <BcmsImage> — render an image field as one responsive `<img>` on the BetterCMS media transform\n * endpoint, declared so the visual editor binds it and a publish writes the new picture into it.\n * The same markup as the Astro SDK's <BcmsImage>.\n *\n * <BcmsImage path=\"hero.image\" src={page.hero.image} sizes=\"(min-width: 800px) 50vw, 100vw\" />\n *\n * `src` is an image VALUE (`{ url, altText, width?, focal?, crop? }`), a media url or an asset id.\n * The value's per-placement crop and focal point ride every url, and the focal point is also the\n * `object-position` (inert without `object-fit`). With `sizes` and no `width` the srcset is a WIDTH\n * ladder, never wider than the picture; with a pixel `width` it is 1x/2x. The value's `altText` is\n * the alt unless `alt` says otherwise. Any other prop reaches the `<img>` as written.\n *\n * A plain `<img>`, deliberately: `next/image` refuses a remote host the app has not allow-listed,\n * so an editor's replacement would break the build. Server-safe (no hooks).\n */\nimport type { ImageFit, ImageFormat, ImageSource } from \"@bettercms-ai/image-url\";\nimport { imageCore } from \"@bettercms-ai/sdk/bindings\";\nimport type { CSSProperties, ImgHTMLAttributes } from \"react\";\n\n/** What delivery adds to an image value beside its url: the facts this component reads. */\ntype ImageFacts = { altText?: string | null; alt?: string | null; width?: number | null; height?: number | null; focalX?: number | null; focalY?: number | null };\n\nexport interface BcmsImageProps extends Omit<ImgHTMLAttributes<HTMLImageElement>, \"src\" | \"srcSet\" | \"width\" | \"height\"> {\n src: ImageSource | (Exclude<ImageSource, string> & ImageFacts);\n /** The field this image renders, in the editor grammar (`cover`, `hero.image`). */\n path?: string;\n width?: number;\n height?: number;\n format?: ImageFormat;\n quality?: number;\n fit?: ImageFit;\n /** Focal point override, 0–1. Normally omitted: the value and the asset carry their own. */\n focalX?: number | null;\n focalY?: number | null;\n /** Media host for a `src` that is only an asset id. Defaults to the platform's. */\n baseUrl?: string;\n}\n\n/** The widths a `sizes` image offers: phone to desktop, and never an upscale of the picture. */\nexport function BcmsImage({\n src,\n path,\n alt,\n width,\n height,\n format = \"webp\",\n quality,\n fit,\n sizes,\n loading = \"lazy\",\n focalX,\n focalY,\n baseUrl,\n style,\n ...rest\n}: BcmsImageProps) {\n const { src: src1x, srcset: srcSet, alt: resolvedAlt, css } = imageCore(src, { alt, width, height, format, quality, fit, sizes, focalX, focalY, baseUrl });\n const merged: CSSProperties = { ...css, ...style };\n\n return (\n <img\n src={src1x}\n srcSet={srcSet}\n alt={resolvedAlt}\n data-bcms-field={path}\n data-bcms-kind={path ? \"image\" : undefined}\n width={width}\n height={height}\n sizes={sizes}\n loading={loading}\n style={Object.keys(merged).length > 0 ? merged : undefined}\n {...rest}\n />\n );\n}\n","/**\n * <BcmsButton> — render a `button` field ({ label, href, variant?, size?, arrow?, icon?,\n * newTab?, fullWidth? }) as one editable button, with the hooks the BetterCMS visual editor repaints and\n * in-place publishing writes. The same markup as the Astro SDK's <BcmsButton>:\n *\n * <a data-bcms-button=\"<path>\" data-variant data-size [data-full-width] href [target rel] data-bcms-props=\"<path>.href|url|href\">\n * [<svg class=\"bcms-btn-icon\">]<span data-bcms-field=\"<path>.label\">Label</span>[<svg class=\"bcms-btn-arrow\">]\n * </a>\n *\n * A value with `action: \"code\"` (no href: the site's script handles the click) renders the same\n * children in `<button type=\"button\" data-bcms-button=\"<path>\" data-variant data-size>`.\n *\n * Style it by `data-variant` and `data-size` in your own CSS. A full-width button also carries\n * `display:flex;width:100%;justify-content:center` inline, so it stretches with no rule of yours.\n * Server-safe (no hooks).\n *\n * <BcmsButton path=\"hero.cta\" value={page.hero.cta} className=\"btn\" />\n */\nimport { formatPropsAttribute, readButtonValue } from \"@bettercms-ai/types\";\nimport { ICON_MARKUP, ICON_VIEWBOX } from \"@bettercms-ai/icons/markup\";\n\n/**\n * One icon as an `<svg>` drawn from the markup table the block renderer already ships, so a button\n * costs no per-icon module: the icon map pulled every icon into a client bundle.\n */\nconst ButtonIcon = ({ name, className }: { name: keyof typeof ICON_MARKUP; className: string }) => (\n <svg data-bcms-icon={name} className={className} viewBox={ICON_VIEWBOX} width=\"1em\" height=\"1em\" fill=\"none\" aria-hidden focusable=\"false\" dangerouslySetInnerHTML={{ __html: ICON_MARKUP[name] }} />\n);\n\n/** A full-width button stretches across its column, label centred: the hosted renderer's `bcms-btn-full`. */\nconst FULL_WIDTH_STYLE = { display: \"flex\", width: \"100%\", justifyContent: \"center\" } as const;\n\nexport interface BcmsButtonProps {\n /** The field path in the editor grammar, e.g. `cta` or `hero.cta`. */\n path: string;\n /** The stored value. Missing keys render as the defaults (Primary, medium, no arrow, no icon). */\n value: unknown;\n className?: string;\n}\n\nexport function BcmsButton({ path, value, className }: BcmsButtonProps) {\n const b = readButtonValue(value);\n if (!b.label) return null;\n const content = (\n <>\n {/* Direct children of the root, as the editor and in-place publishing find them. */}\n {b.icon && <ButtonIcon name={b.icon} className=\"bcms-btn-icon\" />}\n <span data-bcms-field={`${path}.label`} data-bcms-kind=\"text\">\n {b.label}\n </span>\n {b.arrow && <ButtonIcon name=\"arrow-right\" className=\"bcms-btn-arrow\" />}\n </>\n );\n // `action: \"code\"`: your own handler owns the click (delegate on `[data-bcms-button]`), so no href.\n if (b.action === \"code\") {\n return (\n <button type=\"button\" className={className} data-bcms-button={path} data-variant={b.variant} data-size={b.size} {...(b.fullWidth ? { \"data-full-width\": \"\", style: FULL_WIDTH_STYLE } : {})}>\n {content}\n </button>\n );\n }\n return (\n <a\n className={className}\n href={b.href || \"#\"}\n data-bcms-button={path}\n data-variant={b.variant}\n data-size={b.size}\n {...(b.fullWidth ? { \"data-full-width\": \"\", style: FULL_WIDTH_STYLE } : {})}\n data-bcms-props={formatPropsAttribute([{ address: `${path}.href`, kind: \"url\", attr: \"href\" }])}\n {...(b.newTab ? { target: \"_blank\", rel: \"noopener noreferrer\" } : {})}\n >\n {content}\n </a>\n );\n}\n","/**\n * C3 — `fieldAttrs(path, fieldStyles)`: the props a site's OWN element spreads to bind a PAGE FIELD\n * and apply that field's stored style, so the BetterCMS editor offers its width and spacing handles\n * and its Align / Size / Weight controls.\n *\n * const page = await client.getPage(\"home\");\n * <h1 className=\"title\" {...fieldAttrs(\"hero-title\", page?.fieldStyles)}>{entry.data[\"hero-title\"]}</h1>\n *\n * `data-bcms-style` is the site's promise that \"this element's inline style is\n * `fieldStyleToCss(fieldStyles[path])`\"; the editor offers a field's handles only where it is\n * present. Present even when the field has no style (then there is no `style` prop at all).\n * Twin: `fieldAttrs` in @bettercms-ai/astro (a CSS string there).\n */\nimport type { CSSProperties } from \"react\";\nimport { fieldStyleToCss, type FieldStyle, type FieldStyles } from \"@bettercms-ai/types\";\n\nexport interface FieldAttrs {\n \"data-bcms-field\": string;\n /** The marker's revision: \"2\" promises `size` (zoom) too. Section roots keep \"\". */\n \"data-bcms-style\": \"2\";\n /** `fieldStyleToCss(fieldStyles[path])`; absent when the field has no style. */\n style?: CSSProperties;\n}\n\n/** The stored style for `path`, by OWN key only — a path like `constructor` never reads the prototype. */\nexport function fieldStyleOf(path: string, fieldStyles: FieldStyles | Record<string, unknown> | null | undefined): FieldStyle | undefined {\n if (!fieldStyles || typeof fieldStyles !== \"object\" || !Object.prototype.hasOwnProperty.call(fieldStyles, path)) return undefined;\n const style = (fieldStyles as Record<string, unknown>)[path];\n return style && typeof style === \"object\" ? (style as FieldStyle) : undefined;\n}\n\nexport function fieldAttrs(path: string, fieldStyles?: FieldStyles | Record<string, unknown> | null): FieldAttrs {\n const css = fieldStyleToCss(fieldStyleOf(path, fieldStyles));\n return { \"data-bcms-field\": path, \"data-bcms-style\": \"2\", ...(css ? { style: css as CSSProperties } : {}) };\n}\n\n/**\n * P7 — `entryAttrs(entry)` and `entryField(entry, path)`: the attributes a site's OWN card spreads to\n * declare a collection ENTRY, so the editor binds it without guessing from the rendered text.\n *\n * <article {...entryAttrs(post)}><h3 {...entryField(post, \"title\")}>{post.fields.title}</h3></article>\n *\n * The field address is ABSOLUTE (`entry:<id>:<path>`). With a `transform` the value is shown\n * changed (a date formatted, text truncated), so it is declared as `data-bcms-entry-from`: the\n * editor knows where it is but cannot re-render it. Twin: same helpers in @bettercms-ai/astro.\n */\nexport type EntryRef = { id?: string } | string;\nexport type EntryTransform = \"format\" | \"truncate\" | \"rendition\" | \"route\";\n/** One key is present: `data-bcms-entry-field`, or `data-bcms-entry-from` when transformed; none without an id. */\nexport interface EntryFieldAttrs {\n \"data-bcms-entry-field\"?: string;\n \"data-bcms-entry-from\"?: string;\n}\n\nfunction entryIdOf(entry: EntryRef): string | null {\n const id = typeof entry === \"string\" ? entry : entry?.id;\n return typeof id === \"string\" && id.trim() !== \"\" ? id : null;\n}\n\n/** An entry with no id (a snapshot written before ids were kept) renders unbound, never fails the build. */\nexport function entryAttrs(entry: EntryRef): { \"data-bcms-entry\"?: string } {\n const id = entryIdOf(entry);\n return id ? { \"data-bcms-entry\": id } : {};\n}\n\nexport function entryField(entry: EntryRef, path: string, opts?: { transform?: EntryTransform }): EntryFieldAttrs {\n const id = entryIdOf(entry);\n if (typeof path !== \"string\" || path.trim() === \"\") throw new Error(`entryField: no field path given for entry ${id ?? \"(no id)\"}`);\n if (!id) return {};\n const address = `entry:${id}:${path}`;\n return opts?.transform ? { \"data-bcms-entry-from\": `${address}|${opts.transform}` } : { \"data-bcms-entry-field\": address };\n}\n","/**\n * C3/C4 — `sectionRootAttrs(block)`: the props a site's OWN section root spreads so the\n * BetterCMS editor offers that section's spacing and style handles.\n *\n * <section className=\"hero\" {...sectionRootAttrs(block)}>…</section>\n *\n * The editor shows those handles on a site-rendered page only when EVERY root the site stamps\n * with `data-bcms-block` also carries `data-bcms-style`, which is the site's promise that \"this\n * root's inline style is `blockStyleToCss(block.style)`\" — the same declarations `<BcmsBlocks>`\n * puts on its own wrapper. The marker is present even when the style is EMPTY (then there is no\n * `style` prop at all): an unstyled section is the one an author is about to give its first\n * spacing edit. Twin: `sectionRootAttrs` in @bettercms-ai/astro (style as a string there).\n */\nimport type { CSSProperties } from \"react\";\nimport { blockStyleToColumnCss, blockStyleToCss, hideOnAttr, type BlockStyle } from \"@bettercms-ai/types\";\n\nexport interface SectionRootBlock {\n id?: string | null;\n style?: BlockStyle | Record<string, unknown> | null;\n}\n\nexport interface SectionRootAttrs {\n \"data-bcms-block\"?: string;\n \"data-bcms-style\": \"\";\n /** `\"mobile tablet\"` when `style.hideOn` hides it there; the site ships `RESPONSIVE_CSS` for it. */\n \"data-bcms-hide\"?: string;\n /** `blockStyleToCss(block.style)`; absent when the block has no style. */\n style?: CSSProperties;\n}\n\nexport function sectionRootAttrs(block: SectionRootBlock | null | undefined): SectionRootAttrs {\n const css = blockStyleToCss((block?.style ?? undefined) as BlockStyle | undefined);\n const id = typeof block?.id === \"string\" && block.id !== \"\" ? block.id : undefined;\n const hide = hideOnAttr(block?.style);\n return {\n ...(id !== undefined ? { \"data-bcms-block\": id } : {}),\n \"data-bcms-style\": \"\",\n ...(hide ? { \"data-bcms-hide\": hide } : {}),\n ...(css ? { style: css as CSSProperties } : {}),\n };\n}\n\nexport interface SectionColumnAttrs {\n \"data-bcms-column\": \"\";\n /** `blockStyleToColumnCss(block.style)`; absent when the section has no column. */\n style?: CSSProperties;\n}\n\n/**\n * C3 — `sectionColumnAttrs(block)`: the props a site's own INNER container spreads so the section's\n * content WIDTH ships (`style.contentWidth`, placed by `contentAlign`). The column BetterCMS draws as\n * `.bcms-block-inner`, never on the root (its background stays full-bleed); `data-bcms-column` is the\n * site's promise that this box's inline style is that column. Twin: @bettercms-ai/astro.\n */\nexport function sectionColumnAttrs(block: SectionRootBlock | null | undefined): SectionColumnAttrs {\n const css = blockStyleToColumnCss((block?.style ?? undefined) as BlockStyle | undefined);\n return { \"data-bcms-column\": \"\", ...(css ? { style: css as CSSProperties } : {}) };\n}\n"],"mappings":";AAsBA,SAAS,UAAU,cAAc,sBAA2E;AAqBxG;AATG,SAAS,UAAU,EAAE,MAAM,MAAM,IAAI,SAAS,GAAmB;AACtE,QAAM,MAAM,MAAM;AAClB,QAAM,OAAO,KAAK,CAAC,IAAI,SAAS,QAAQ,QAAQ;AAChD,QAAM,OAAO,KAAK,WAAW,KAAK,eAAe,KAAK,CAAC,CAAC,KAAK,OAAO,KAAK,CAAC,EAAE,SAAS,WAAY,KAAK,CAAC,IAA8C;AAErJ,MAAI,QAAQ,KAAK,MAAM,iBAAiB,MAAM,UAAa,KAAK,MAAM,wBAAwB,MAAM,QAAW;AAC7G,WAAO,aAAa,MAAM,EAAE,mBAAmB,MAAM,kBAAkB,KAAK,CAAC;AAAA,EAC/E;AACA,SACE;AAAA,IAAC;AAAA;AAAA,MACC,mBAAiB;AAAA,MACjB,kBAAgB;AAAA,MAChB,OAAO,KAAK,SAAY,EAAE,SAAS,WAAW;AAAA,MAE7C;AAAA;AAAA,EACH;AAEJ;;;AClCA,SAAS,iBAAiB;AA4CtB,gBAAAA,YAAA;AArBG,SAAS,UAAU;AAAA,EACxB;AAAA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AM,EAAE,OAAO,IAAqB,IAAI,CAAC,EAAG;AACnF;","names":["jsx","jsx"]}
|
|
1
|
+
{"version":3,"sources":["../src/field.tsx","../src/image.tsx","../src/button.tsx","../src/icon.tsx","../src/field-attrs.ts","../src/section-root.ts"],"sourcesContent":["/**\n * <BcmsField> — tag an entry field's rendered value with its identity so the\n * BetterCMS visual editor can bind click-to-edit deterministically (mirrors\n * Sanity's `data-sanity` / BaseHub's `data-basehub`). Entry-backed templates\n * hand-render field values (`f.title`, `f.body.html`), so the field `path` is\n * declared here by the author — the delivery payload carries no source-map.\n *\n * Server-safe (no hooks): renders in a Next Server Component. When the child is ONE\n * DOM element (`<h1>`, `<p>`), the attributes go on that element and nothing is added to\n * the page: `.hero > h1` and every animation target stay what the author wrote. Text,\n * several children, or a component (which may not pass unknown props on) are wrapped in a\n * `display:contents` span as before; pass `as` to carry the attributes on a real wrapper.\n * Twin: BcmsField.astro in @bettercms-ai/astro.\n *\n * `path` follows the editor grammar: `title` · `hero.title` · `columns[0].links[2].href`\n * (dotted keys and any number of `[n]` indices). For images, put the attributes on the\n * `<img>` itself (`kind=\"image\"` reflection patches `.src`), not on a wrapper:\n * <img src={imageValueUrl(f.cover, { w: 1200 })} data-bcms-field=\"cover\" data-bcms-kind=\"image\" />\n * `imageValueUrl` (re-exported from this package) applies the value's per-placement `crop` and\n * `focal`; `.url` alone would drop them. For a cover-fit box add\n * `style={{ objectPosition: imageValueObjectPosition(f.cover) ?? undefined }}`.\n */\nimport { Children, cloneElement, isValidElement, type ElementType, type ReactElement, type ReactNode } from \"react\";\n\nexport interface BcmsFieldProps {\n /** Field path in the editor grammar, e.g. `title` or `facts[2].label`. */\n path: string;\n /** Kind hint the editor's reflection branches on. Omit for plain text/number. */\n kind?: \"richtext\" | \"image\";\n /** Wrapper element. Without it: no wrapper around a single DOM element, a `display:contents` span around anything else. */\n as?: ElementType;\n children: ReactNode;\n}\n\nexport function BcmsField({ path, kind, as, children }: BcmsFieldProps) {\n const Tag = as ?? \"span\";\n const only = as ? [] : Children.toArray(children);\n const sole = only.length === 1 && isValidElement(only[0]) && typeof only[0].type === \"string\" ? (only[0] as ReactElement<Record<string, unknown>>) : null;\n // An element that already declares a field keeps its own address: wrapped, as before.\n if (sole && sole.props[\"data-bcms-field\"] === undefined && sole.props[\"data-bcms-layout-field\"] === undefined) {\n return cloneElement(sole, { \"data-bcms-field\": path, \"data-bcms-kind\": kind });\n }\n return (\n <Tag\n data-bcms-field={path}\n data-bcms-kind={kind}\n style={as ? undefined : { display: \"contents\" }}\n >\n {children}\n </Tag>\n );\n}\n","/**\n * <BcmsImage> — render an image field as one responsive `<img>` on the BetterCMS media transform\n * endpoint, declared so the visual editor binds it and a publish writes the new picture into it.\n * The same markup as the Astro SDK's <BcmsImage>.\n *\n * <BcmsImage path=\"hero.image\" src={page.hero.image} sizes=\"(min-width: 800px) 50vw, 100vw\" />\n *\n * `src` is an image VALUE (`{ url, altText, width?, focal?, crop? }`), a media url or an asset id.\n * The value's per-placement crop and focal point ride every url, and the focal point is also the\n * `object-position` (inert without `object-fit`). With `sizes` and no `width` the srcset is a WIDTH\n * ladder, never wider than the picture; with a pixel `width` it is 1x/2x. The value's `altText` is\n * the alt unless `alt` says otherwise. Any other prop reaches the `<img>` as written.\n *\n * A plain `<img>`, deliberately: `next/image` refuses a remote host the app has not allow-listed,\n * so an editor's replacement would break the build. Server-safe (no hooks).\n */\nimport type { ImageFit, ImageFormat, ImageSource } from \"@bettercms-ai/image-url\";\nimport { imageCore } from \"@bettercms-ai/sdk/bindings\";\nimport type { CSSProperties, ImgHTMLAttributes } from \"react\";\n\n/** What delivery adds to an image value beside its url: the facts this component reads. */\ntype ImageFacts = { altText?: string | null; alt?: string | null; width?: number | null; height?: number | null; focalX?: number | null; focalY?: number | null };\n\nexport interface BcmsImageProps extends Omit<ImgHTMLAttributes<HTMLImageElement>, \"src\" | \"srcSet\" | \"width\" | \"height\"> {\n src: ImageSource | (Exclude<ImageSource, string> & ImageFacts);\n /** The field this image renders, in the editor grammar (`cover`, `hero.image`). */\n path?: string;\n width?: number;\n height?: number;\n format?: ImageFormat;\n quality?: number;\n fit?: ImageFit;\n /** Focal point override, 0–1. Normally omitted: the value and the asset carry their own. */\n focalX?: number | null;\n focalY?: number | null;\n /** Media host for a `src` that is only an asset id. Defaults to the platform's. */\n baseUrl?: string;\n}\n\n/** The widths a `sizes` image offers: phone to desktop, and never an upscale of the picture. */\nexport function BcmsImage({\n src,\n path,\n alt,\n width,\n height,\n format = \"webp\",\n quality,\n fit,\n sizes,\n loading = \"lazy\",\n focalX,\n focalY,\n baseUrl,\n style,\n ...rest\n}: BcmsImageProps) {\n const { src: src1x, srcset: srcSet, alt: resolvedAlt, css } = imageCore(src, { alt, width, height, format, quality, fit, sizes, focalX, focalY, baseUrl });\n const merged: CSSProperties = { ...css, ...style };\n\n return (\n <img\n src={src1x}\n srcSet={srcSet}\n alt={resolvedAlt}\n data-bcms-field={path}\n data-bcms-kind={path ? \"image\" : undefined}\n width={width}\n height={height}\n sizes={sizes}\n loading={loading}\n style={Object.keys(merged).length > 0 ? merged : undefined}\n {...rest}\n />\n );\n}\n","/**\n * <BcmsButton> — render a `button` field ({ label, href, variant?, size?, arrow?, icon?,\n * newTab?, fullWidth? }) as one editable button, with the hooks the BetterCMS visual editor repaints and\n * in-place publishing writes. The same markup as the Astro SDK's <BcmsButton>:\n *\n * <a data-bcms-button=\"<path>\" data-variant data-size [data-full-width] href [target rel] data-bcms-props=\"<path>.href|url|href\">\n * [<svg class=\"bcms-btn-icon\">]<span data-bcms-field=\"<path>.label\">Label</span>[<svg class=\"bcms-btn-arrow\">]\n * </a>\n *\n * A value with `action: \"code\"` (no href: the site's script handles the click) renders the same\n * children in `<button type=\"button\" data-bcms-button=\"<path>\" data-variant data-size>`.\n *\n * Style it by `data-variant` and `data-size` in your own CSS. A full-width button also carries\n * `display:flex;width:100%;justify-content:center` inline, so it stretches with no rule of yours.\n * Server-safe (no hooks).\n *\n * <BcmsButton path=\"hero.cta\" value={page.hero.cta} className=\"btn\" />\n */\nimport { formatPropsAttribute, readButtonValue } from \"@bettercms-ai/types\";\nimport { ICON_MARKUP, ICON_VIEWBOX } from \"@bettercms-ai/icons/markup\";\n\n/**\n * One icon as an `<svg>` drawn from the markup table the block renderer already ships, so a button\n * costs no per-icon module: the icon map pulled every icon into a client bundle.\n */\nconst ButtonIcon = ({ name, className }: { name: keyof typeof ICON_MARKUP; className: string }) => (\n <svg data-bcms-icon={name} className={className} viewBox={ICON_VIEWBOX} width=\"1em\" height=\"1em\" fill=\"none\" aria-hidden focusable=\"false\" dangerouslySetInnerHTML={{ __html: ICON_MARKUP[name] }} />\n);\n\n/** A full-width button stretches across its column, label centred: the hosted renderer's `bcms-btn-full`. */\nconst FULL_WIDTH_STYLE = { display: \"flex\", width: \"100%\", justifyContent: \"center\" } as const;\n\nexport interface BcmsButtonProps {\n /** The field path in the editor grammar, e.g. `cta` or `hero.cta`. */\n path: string;\n /** The stored value. Missing keys render as the defaults (Primary, medium, no arrow, no icon). */\n value: unknown;\n className?: string;\n}\n\nexport function BcmsButton({ path, value, className }: BcmsButtonProps) {\n const b = readButtonValue(value);\n if (!b.label) return null;\n const content = (\n <>\n {/* Direct children of the root, as the editor and in-place publishing find them. */}\n {b.icon && <ButtonIcon name={b.icon} className=\"bcms-btn-icon\" />}\n <span data-bcms-field={`${path}.label`} data-bcms-kind=\"text\">\n {b.label}\n </span>\n {b.arrow && <ButtonIcon name=\"arrow-right\" className=\"bcms-btn-arrow\" />}\n </>\n );\n // `action: \"code\"`: your own handler owns the click (delegate on `[data-bcms-button]`), so no href.\n if (b.action === \"code\") {\n return (\n <button type=\"button\" className={className} data-bcms-button={path} data-variant={b.variant} data-size={b.size} {...(b.fullWidth ? { \"data-full-width\": \"\", style: FULL_WIDTH_STYLE } : {})}>\n {content}\n </button>\n );\n }\n return (\n <a\n className={className}\n href={b.href || \"#\"}\n data-bcms-button={path}\n data-variant={b.variant}\n data-size={b.size}\n {...(b.fullWidth ? { \"data-full-width\": \"\", style: FULL_WIDTH_STYLE } : {})}\n data-bcms-props={formatPropsAttribute([{ address: `${path}.href`, kind: \"url\", attr: \"href\" }])}\n {...(b.newTab ? { target: \"_blank\", rel: \"noopener noreferrer\" } : {})}\n >\n {content}\n </a>\n );\n}\n","/**\n * <BcmsIcon> — render an `icon` field's value (V2 D65), every stored form:\n *\n * a set name → <svg data-bcms-icon=\"name\">, from the markup table the block renderer ships\n * a library icon that → <span data-bcms-icon-url> masked in the text colour (it recolours with the text)\n * follows the text\n * any other url → <img> (a multicolour SVG or an image keeps its colours)\n *\n * A `label` makes the icon an image with that name; without one it is decorative (aria-hidden). Server-safe (no hooks).\n *\n * <BcmsIcon value={card.icon} className=\"size-5\" />\n */\nimport { iconSrc } from \"@bettercms-ai/types\";\nimport { ICON_MARKUP, ICON_VIEWBOX } from \"@bettercms-ai/icons/markup\";\n\nexport interface BcmsIconProps {\n /** The stored icon value: a set name, an image URL or an icon object. */\n value: unknown;\n className?: string;\n}\n\nexport function BcmsIcon({ value, className }: BcmsIconProps) {\n const src = iconSrc(value);\n if (!src) return null;\n const a11y = src.label ? { role: \"img\", \"aria-label\": src.label } : { \"aria-hidden\": true as const };\n if (\"name\" in src) {\n const markup = (ICON_MARKUP as Record<string, string>)[src.name];\n if (!markup) return null;\n return <svg data-bcms-icon={src.name} className={className} viewBox={ICON_VIEWBOX} width=\"1em\" height=\"1em\" fill=\"none\" focusable=\"false\" {...a11y} dangerouslySetInnerHTML={{ __html: markup }} />;\n }\n if (src.followsText) {\n const mask = `url(${JSON.stringify(src.url)}) center / contain no-repeat`;\n return <span data-bcms-icon-url={src.url} className={className} style={{ display: \"inline-block\", width: \"1em\", height: \"1em\", backgroundColor: \"currentColor\", mask, WebkitMask: mask }} {...a11y} />;\n }\n return <img src={src.url} alt={src.label ?? \"\"} className={className} width={16} height={16} style={{ width: \"1em\", height: \"1em\", objectFit: \"contain\" }} />;\n}\n","/**\n * C3 — `fieldAttrs(path, fieldStyles)`: the props a site's OWN element spreads to bind a PAGE FIELD\n * and apply that field's stored style, so the BetterCMS editor offers its width and spacing handles\n * and its Align / Size / Weight controls.\n *\n * const page = await client.getPage(\"home\");\n * <h1 className=\"title\" {...fieldAttrs(\"hero-title\", page?.fieldStyles)}>{entry.data[\"hero-title\"]}</h1>\n *\n * `data-bcms-style` is the site's promise that \"this element's inline style is\n * `fieldStyleToCss(fieldStyles[path])`\"; the editor offers a field's handles only where it is\n * present. Present even when the field has no style (then there is no `style` prop at all).\n * Twin: `fieldAttrs` in @bettercms-ai/astro (a CSS string there).\n */\nimport type { CSSProperties } from \"react\";\nimport { fieldStyleToCss, type FieldStyle, type FieldStyles } from \"@bettercms-ai/types\";\n\nexport interface FieldAttrs {\n \"data-bcms-field\": string;\n /** The marker's revision: \"2\" promises `size` (zoom) too. Section roots keep \"\". */\n \"data-bcms-style\": \"2\";\n /** `fieldStyleToCss(fieldStyles[path])`; absent when the field has no style. */\n style?: CSSProperties;\n}\n\n/** The stored style for `path`, by OWN key only — a path like `constructor` never reads the prototype. */\nexport function fieldStyleOf(path: string, fieldStyles: FieldStyles | Record<string, unknown> | null | undefined): FieldStyle | undefined {\n if (!fieldStyles || typeof fieldStyles !== \"object\" || !Object.prototype.hasOwnProperty.call(fieldStyles, path)) return undefined;\n const style = (fieldStyles as Record<string, unknown>)[path];\n return style && typeof style === \"object\" ? (style as FieldStyle) : undefined;\n}\n\nexport function fieldAttrs(path: string, fieldStyles?: FieldStyles | Record<string, unknown> | null): FieldAttrs {\n const css = fieldStyleToCss(fieldStyleOf(path, fieldStyles));\n return { \"data-bcms-field\": path, \"data-bcms-style\": \"2\", ...(css ? { style: css as CSSProperties } : {}) };\n}\n\n/**\n * P7 — `entryAttrs(entry)` and `entryField(entry, path)`: the attributes a site's OWN card spreads to\n * declare a collection ENTRY, so the editor binds it without guessing from the rendered text.\n *\n * <article {...entryAttrs(post)}><h3 {...entryField(post, \"title\")}>{post.fields.title}</h3></article>\n *\n * The field address is ABSOLUTE (`entry:<id>:<path>`). With a `transform` the value is shown\n * changed (a date formatted, text truncated), so it is declared as `data-bcms-entry-from`: the\n * editor knows where it is but cannot re-render it. Twin: same helpers in @bettercms-ai/astro.\n */\nexport type EntryRef = { id?: string } | string;\nexport type EntryTransform = \"format\" | \"truncate\" | \"rendition\" | \"route\";\n/** One key is present: `data-bcms-entry-field`, or `data-bcms-entry-from` when transformed; none without an id. */\nexport interface EntryFieldAttrs {\n \"data-bcms-entry-field\"?: string;\n \"data-bcms-entry-from\"?: string;\n}\n\nfunction entryIdOf(entry: EntryRef): string | null {\n const id = typeof entry === \"string\" ? entry : entry?.id;\n return typeof id === \"string\" && id.trim() !== \"\" ? id : null;\n}\n\n/** An entry with no id (a snapshot written before ids were kept) renders unbound, never fails the build. */\nexport function entryAttrs(entry: EntryRef): { \"data-bcms-entry\"?: string } {\n const id = entryIdOf(entry);\n return id ? { \"data-bcms-entry\": id } : {};\n}\n\nexport function entryField(entry: EntryRef, path: string, opts?: { transform?: EntryTransform }): EntryFieldAttrs {\n const id = entryIdOf(entry);\n if (typeof path !== \"string\" || path.trim() === \"\") throw new Error(`entryField: no field path given for entry ${id ?? \"(no id)\"}`);\n if (!id) return {};\n const address = `entry:${id}:${path}`;\n return opts?.transform ? { \"data-bcms-entry-from\": `${address}|${opts.transform}` } : { \"data-bcms-entry-field\": address };\n}\n","/**\n * C3/C4 — `sectionRootAttrs(block)`: the props a site's OWN section root spreads so the\n * BetterCMS editor offers that section's spacing and style handles.\n *\n * <section className=\"hero\" {...sectionRootAttrs(block)}>…</section>\n *\n * The editor shows those handles on a site-rendered page only when EVERY root the site stamps\n * with `data-bcms-block` also carries `data-bcms-style`, which is the site's promise that \"this\n * root's inline style is `blockStyleToCss(block.style)`\" — the same declarations `<BcmsBlocks>`\n * puts on its own wrapper. The marker is present even when the style is EMPTY (then there is no\n * `style` prop at all): an unstyled section is the one an author is about to give its first\n * spacing edit. Twin: `sectionRootAttrs` in @bettercms-ai/astro (style as a string there).\n */\nimport type { CSSProperties } from \"react\";\nimport { blockStyleToColumnCss, blockStyleToCss, hideOnAttr, type BlockStyle } from \"@bettercms-ai/types\";\n\nexport interface SectionRootBlock {\n id?: string | null;\n style?: BlockStyle | Record<string, unknown> | null;\n}\n\nexport interface SectionRootAttrs {\n \"data-bcms-block\"?: string;\n \"data-bcms-style\": \"\";\n /** `\"mobile tablet\"` when `style.hideOn` hides it there; the site ships `RESPONSIVE_CSS` for it. */\n \"data-bcms-hide\"?: string;\n /** `blockStyleToCss(block.style)`; absent when the block has no style. */\n style?: CSSProperties;\n}\n\nexport function sectionRootAttrs(block: SectionRootBlock | null | undefined): SectionRootAttrs {\n const css = blockStyleToCss((block?.style ?? undefined) as BlockStyle | undefined);\n const id = typeof block?.id === \"string\" && block.id !== \"\" ? block.id : undefined;\n const hide = hideOnAttr(block?.style);\n return {\n ...(id !== undefined ? { \"data-bcms-block\": id } : {}),\n \"data-bcms-style\": \"\",\n ...(hide ? { \"data-bcms-hide\": hide } : {}),\n ...(css ? { style: css as CSSProperties } : {}),\n };\n}\n\nexport interface SectionColumnAttrs {\n \"data-bcms-column\": \"\";\n /** `blockStyleToColumnCss(block.style)`; absent when the section has no column. */\n style?: CSSProperties;\n}\n\n/**\n * C3 — `sectionColumnAttrs(block)`: the props a site's own INNER container spreads so the section's\n * content WIDTH ships (`style.contentWidth`, placed by `contentAlign`). The column BetterCMS draws as\n * `.bcms-block-inner`, never on the root (its background stays full-bleed); `data-bcms-column` is the\n * site's promise that this box's inline style is that column. Twin: @bettercms-ai/astro.\n */\nexport function sectionColumnAttrs(block: SectionRootBlock | null | undefined): SectionColumnAttrs {\n const css = blockStyleToColumnCss((block?.style ?? undefined) as BlockStyle | undefined);\n return { \"data-bcms-column\": \"\", ...(css ? { style: css as CSSProperties } : {}) };\n}\n"],"mappings":";AAsBA,SAAS,UAAU,cAAc,sBAA2E;AAqBxG;AATG,SAAS,UAAU,EAAE,MAAM,MAAM,IAAI,SAAS,GAAmB;AACtE,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AAK;AACpC,SAAO;AAAA,IACL,GAAI,OAAO,SAAY,EAAE,mBAAmB,GAAG,IAAI,CAAC;AAAA,IACpD,mBAAmB;AAAA,IACnB,GAAI,OAAO,EAAE,kBAAkB,KAAK,IAAI,CAAC;AAAA,IACzC,GAAI,MAAM,EAAE,OAAO,IAAqB,IAAI,CAAC;AAAA,EAC/C;AACF;AAcO,SAAS,mBAAmB,OAAgE;AACjG,QAAM,MAAM,sBAAuB,OAAO,SAAS,MAAoC;AACvF,SAAO,EAAE,oBAAoB,IAAI,GAAI,MAAM,EAAE,OAAO,IAAqB,IAAI,CAAC,EAAG;AACnF;","names":["jsx","jsx","ICON_MARKUP","ICON_VIEWBOX","jsx"]}
|
package/dist/form.d.ts
CHANGED
|
@@ -11,6 +11,38 @@ import { DeliveryForm } from '@bettercms-ai/sdk/read';
|
|
|
11
11
|
* unstyled and class-driven, so the host site owns the look.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
+
/** A file a visitor attached and the upload route stored: what the submission names it by. */
|
|
15
|
+
interface StoredFile {
|
|
16
|
+
id: string;
|
|
17
|
+
name: string;
|
|
18
|
+
size: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* What to do with the files a visitor just picked for a `file` field, before any byte is sent:
|
|
22
|
+
* upload `take` (with `replace`, the file that lands replaces what is stored), or show `refusal`. `stored` counts stored, in-flight and queued files.
|
|
23
|
+
* - a field that takes one file: the new pick replaces the old one;
|
|
24
|
+
* - otherwise a pick that would go past the field's count is refused whole;
|
|
25
|
+
* - each file is pre-checked for type and size (@see fileFieldLimits; the server holds the rest).
|
|
26
|
+
*/
|
|
27
|
+
declare function planFilePick<F extends {
|
|
28
|
+
name: string;
|
|
29
|
+
size: number;
|
|
30
|
+
}>(limits: {
|
|
31
|
+
accept: string[];
|
|
32
|
+
maxFiles: number;
|
|
33
|
+
maxSizeMb: number;
|
|
34
|
+
}, stored: number, picked: readonly F[]): {
|
|
35
|
+
take: F[];
|
|
36
|
+
replace: boolean;
|
|
37
|
+
} | {
|
|
38
|
+
refusal: string;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Why a file field cannot be submitted yet, or "" when it can: the control's custom validity.
|
|
42
|
+
* A step's Next button and the browser's own checks read it; the field is never `required`,
|
|
43
|
+
* because what it holds is the list of stored files, not the picker's value.
|
|
44
|
+
*/
|
|
45
|
+
declare function fileFieldValidity(required: boolean | undefined, stored: number, uploading: boolean): string;
|
|
14
46
|
interface BcmsFormProps {
|
|
15
47
|
/** A form from your content snapshot or the delivery API. */
|
|
16
48
|
form: DeliveryForm;
|
|
@@ -25,4 +57,4 @@ interface BcmsFormProps {
|
|
|
25
57
|
}
|
|
26
58
|
declare function BcmsForm({ form, apiBase, turnstileSiteKey, onSubmitted, className, }: BcmsFormProps): ReactElement;
|
|
27
59
|
|
|
28
|
-
export { BcmsForm, type BcmsFormProps };
|
|
60
|
+
export { BcmsForm, type BcmsFormProps, type StoredFile, fileFieldValidity, planFilePick };
|
package/dist/form.js
CHANGED
|
@@ -8,10 +8,29 @@ import {
|
|
|
8
8
|
shouldShowField,
|
|
9
9
|
formInitialValues,
|
|
10
10
|
asStringArray,
|
|
11
|
-
toggleOption
|
|
11
|
+
toggleOption,
|
|
12
|
+
uploadFormFile,
|
|
13
|
+
fileFieldLimits,
|
|
14
|
+
fileFieldRefusal
|
|
12
15
|
} from "@bettercms-ai/sdk/read";
|
|
13
16
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
14
17
|
var TURNSTILE_SRC = "https://challenges.cloudflare.com/turnstile/v0/api.js";
|
|
18
|
+
function planFilePick(limits, stored, picked) {
|
|
19
|
+
const take = limits.maxFiles === 1 ? picked.slice(0, 1) : [...picked];
|
|
20
|
+
if (limits.maxFiles > 1 && stored + take.length > limits.maxFiles) {
|
|
21
|
+
return { refusal: `You can attach at most ${limits.maxFiles} files.` };
|
|
22
|
+
}
|
|
23
|
+
for (const file of take) {
|
|
24
|
+
const refusal = fileFieldRefusal(limits, file);
|
|
25
|
+
if (refusal) return { refusal };
|
|
26
|
+
}
|
|
27
|
+
return { take, replace: limits.maxFiles === 1 };
|
|
28
|
+
}
|
|
29
|
+
function fileFieldValidity(required, stored, uploading) {
|
|
30
|
+
if (uploading) return "Please wait: a file is still uploading.";
|
|
31
|
+
if (required && stored === 0) return "Please attach a file.";
|
|
32
|
+
return "";
|
|
33
|
+
}
|
|
15
34
|
var HONEYPOT_STYLE = {
|
|
16
35
|
position: "absolute",
|
|
17
36
|
width: "1px",
|
|
@@ -76,6 +95,80 @@ function BcmsForm({
|
|
|
76
95
|
});
|
|
77
96
|
const [status, setStatus] = useState({ state: "idle" });
|
|
78
97
|
const [fieldErrors, setFieldErrors] = useState({});
|
|
98
|
+
const [files, setFiles] = useState({});
|
|
99
|
+
const [uploading, setUploading] = useState({});
|
|
100
|
+
const [fileNotes, setFileNotes] = useState({});
|
|
101
|
+
const fileInputs = useRef({});
|
|
102
|
+
const uploadQueue = useRef(Promise.resolve());
|
|
103
|
+
const pickTurn = useRef({});
|
|
104
|
+
const anyUploading = Object.values(uploading).some((n) => n > 0);
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
for (const field of form.fields) {
|
|
107
|
+
if (field.type !== "file") continue;
|
|
108
|
+
fileInputs.current[field.key]?.setCustomValidity(
|
|
109
|
+
fileFieldValidity(field.required, files[field.key]?.length ?? 0, (uploading[field.key] ?? 0) > 0)
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
function pickFiles(field, picked) {
|
|
114
|
+
const key = field.key;
|
|
115
|
+
const plan = planFilePick(fileFieldLimits(field), (files[key]?.length ?? 0) + (uploading[key] ?? 0), picked);
|
|
116
|
+
if ("refusal" in plan) {
|
|
117
|
+
setFileNotes((n) => ({ ...n, [key]: plan.refusal }));
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (plan.take.length === 0) return;
|
|
121
|
+
setFileNotes((n) => ({ ...n, [key]: "" }));
|
|
122
|
+
const turn = pickTurn.current[key] = (pickTurn.current[key] ?? 0) + 1;
|
|
123
|
+
setUploading((u) => ({ ...u, [key]: (u[key] ?? 0) + plan.take.length }));
|
|
124
|
+
for (const file of plan.take) {
|
|
125
|
+
uploadQueue.current = uploadQueue.current.then(async () => {
|
|
126
|
+
try {
|
|
127
|
+
if (plan.replace && pickTurn.current[key] !== turn) return;
|
|
128
|
+
const stored = await uploadFormFile({ formId: form.id, fieldKey: key, file, baseUrl: apiBase });
|
|
129
|
+
setFiles((f) => ({ ...f, [key]: plan.replace ? [stored] : [...f[key] ?? [], stored] }));
|
|
130
|
+
} catch (err) {
|
|
131
|
+
const message = err instanceof Error && err.message ? err.message : "This file could not be uploaded. Please try again.";
|
|
132
|
+
setFileNotes((n) => ({ ...n, [key]: message }));
|
|
133
|
+
} finally {
|
|
134
|
+
setUploading((u) => ({ ...u, [key]: Math.max(0, (u[key] ?? 1) - 1) }));
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function removeFile(key, id) {
|
|
140
|
+
setFiles((f) => ({ ...f, [key]: (f[key] ?? []).filter((x) => x.id !== id) }));
|
|
141
|
+
}
|
|
142
|
+
function renderField(field) {
|
|
143
|
+
if (field.type === "file") {
|
|
144
|
+
return /* @__PURE__ */ jsx(
|
|
145
|
+
FileField,
|
|
146
|
+
{
|
|
147
|
+
field,
|
|
148
|
+
stored: files[field.key] ?? [],
|
|
149
|
+
uploading: (uploading[field.key] ?? 0) > 0,
|
|
150
|
+
note: fileNotes[field.key],
|
|
151
|
+
error: fieldErrors[field.key],
|
|
152
|
+
inputRef: (el) => {
|
|
153
|
+
fileInputs.current[field.key] = el;
|
|
154
|
+
},
|
|
155
|
+
onPick: (picked) => pickFiles(field, picked),
|
|
156
|
+
onRemove: (id) => removeFile(field.key, id)
|
|
157
|
+
},
|
|
158
|
+
field.key
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
return /* @__PURE__ */ jsx(
|
|
162
|
+
Field,
|
|
163
|
+
{
|
|
164
|
+
field,
|
|
165
|
+
value: values[field.key],
|
|
166
|
+
error: fieldErrors[field.key],
|
|
167
|
+
onChange: (v) => setValue(field.key, v)
|
|
168
|
+
},
|
|
169
|
+
field.key
|
|
170
|
+
);
|
|
171
|
+
}
|
|
79
172
|
const pages = useMemo(() => splitSteps(form.fields), [form.fields]);
|
|
80
173
|
const [enhanced, setEnhanced] = useState(false);
|
|
81
174
|
const [step, setStep] = useState(0);
|
|
@@ -127,6 +220,10 @@ function BcmsForm({
|
|
|
127
220
|
async function handleSubmit(e) {
|
|
128
221
|
e.preventDefault();
|
|
129
222
|
if (paged && step < last) return next();
|
|
223
|
+
if (anyUploading) {
|
|
224
|
+
setStatus({ state: "error", message: "Please wait: a file is still uploading." });
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
130
227
|
setStatus({ state: "submitting" });
|
|
131
228
|
setFieldErrors({});
|
|
132
229
|
const tokenEl = e.currentTarget.querySelector(
|
|
@@ -137,7 +234,7 @@ function BcmsForm({
|
|
|
137
234
|
for (const field of form.fields) {
|
|
138
235
|
if (field.type === "step") continue;
|
|
139
236
|
if (field.type === "hidden" || shouldShowField(field, values)) {
|
|
140
|
-
data[field.key] = values[field.key];
|
|
237
|
+
data[field.key] = field.type === "file" ? (files[field.key] ?? []).map((f) => f.id) : values[field.key];
|
|
141
238
|
}
|
|
142
239
|
}
|
|
143
240
|
if (form.honeypotField) data[form.honeypotField] = values[form.honeypotField] ?? "";
|
|
@@ -153,6 +250,8 @@ function BcmsForm({
|
|
|
153
250
|
const reset = formInitialValues(form);
|
|
154
251
|
if (form.honeypotField) reset[form.honeypotField] = "";
|
|
155
252
|
setValues(reset);
|
|
253
|
+
setFiles({});
|
|
254
|
+
setFileNotes({});
|
|
156
255
|
setStep(0);
|
|
157
256
|
setStatus({
|
|
158
257
|
state: "success",
|
|
@@ -210,16 +309,7 @@ function BcmsForm({
|
|
|
210
309
|
]
|
|
211
310
|
}
|
|
212
311
|
),
|
|
213
|
-
visibleFields.filter((f) => page.fields.includes(f)).map(
|
|
214
|
-
Field,
|
|
215
|
-
{
|
|
216
|
-
field,
|
|
217
|
-
value: values[field.key],
|
|
218
|
-
error: fieldErrors[field.key],
|
|
219
|
-
onChange: (v) => setValue(field.key, v)
|
|
220
|
-
},
|
|
221
|
-
field.key
|
|
222
|
-
)),
|
|
312
|
+
visibleFields.filter((f) => page.fields.includes(f)).map(renderField),
|
|
223
313
|
paged ? /* @__PURE__ */ jsxs("div", { className: "bcms-step-nav", children: [
|
|
224
314
|
i > 0 ? /* @__PURE__ */ jsx("button", { type: "button", "data-bcms-step-back": true, onClick: () => goTo(i - 1), children: "Back" }) : null,
|
|
225
315
|
i < last ? /* @__PURE__ */ jsx("button", { type: "button", "data-bcms-step-next": true, onClick: next, children: "Next" }) : null
|
|
@@ -227,16 +317,7 @@ function BcmsForm({
|
|
|
227
317
|
]
|
|
228
318
|
},
|
|
229
319
|
page.key ?? "first"
|
|
230
|
-
)) : visibleFields.map(
|
|
231
|
-
Field,
|
|
232
|
-
{
|
|
233
|
-
field,
|
|
234
|
-
value: values[field.key],
|
|
235
|
-
error: fieldErrors[field.key],
|
|
236
|
-
onChange: (v) => setValue(field.key, v)
|
|
237
|
-
},
|
|
238
|
-
field.key
|
|
239
|
-
)),
|
|
320
|
+
)) : visibleFields.map(renderField),
|
|
240
321
|
form.honeypotField ? /* @__PURE__ */ jsx("span", { "aria-hidden": "true", style: { position: "absolute", left: "-9999px" }, children: /* @__PURE__ */ jsx(
|
|
241
322
|
"input",
|
|
242
323
|
{
|
|
@@ -255,7 +336,7 @@ function BcmsForm({
|
|
|
255
336
|
{
|
|
256
337
|
type: "submit",
|
|
257
338
|
hidden: paged && step < last,
|
|
258
|
-
disabled: status.state === "submitting",
|
|
339
|
+
disabled: status.state === "submitting" || anyUploading,
|
|
259
340
|
"data-bcms-form-part": "submit",
|
|
260
341
|
children: status.state === "submitting" ? "Submitting\u2026" : form.submitLabel ?? "Submit"
|
|
261
342
|
}
|
|
@@ -272,6 +353,41 @@ function BcmsForm({
|
|
|
272
353
|
] })
|
|
273
354
|
);
|
|
274
355
|
}
|
|
356
|
+
function FileField({ field, stored, uploading, note, error, inputRef, onPick, onRemove }) {
|
|
357
|
+
const limits = fileFieldLimits(field);
|
|
358
|
+
const id = `bcms-f-${field.key}`;
|
|
359
|
+
return /* @__PURE__ */ jsxs("p", { className: "bcms-field bcms-field--file", "data-field": field.key, "data-bcms-form-field": field.key, children: [
|
|
360
|
+
/* @__PURE__ */ jsxs("label", { htmlFor: id, "data-bcms-form-part": "label", children: [
|
|
361
|
+
field.label,
|
|
362
|
+
field.required ? " *" : ""
|
|
363
|
+
] }),
|
|
364
|
+
/* @__PURE__ */ jsx("br", {}),
|
|
365
|
+
/* @__PURE__ */ jsx(
|
|
366
|
+
"input",
|
|
367
|
+
{
|
|
368
|
+
type: "file",
|
|
369
|
+
id,
|
|
370
|
+
ref: inputRef,
|
|
371
|
+
accept: limits.accept.map((e) => `.${e}`).join(","),
|
|
372
|
+
multiple: limits.maxFiles > 1,
|
|
373
|
+
onChange: (e) => {
|
|
374
|
+
const picked = Array.from(e.target.files ?? []);
|
|
375
|
+
e.target.value = "";
|
|
376
|
+
onPick(picked);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
),
|
|
380
|
+
stored.length > 0 ? /* @__PURE__ */ jsx("ul", { className: "bcms-file-list", children: stored.map((file) => /* @__PURE__ */ jsxs("li", { children: [
|
|
381
|
+
/* @__PURE__ */ jsx("span", { className: "bcms-file-name", children: file.name }),
|
|
382
|
+
" ",
|
|
383
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "bcms-file-remove", "aria-label": `Remove ${file.name}`, onClick: () => onRemove(file.id), children: "Remove" })
|
|
384
|
+
] }, file.id)) }) : null,
|
|
385
|
+
uploading ? /* @__PURE__ */ jsx("span", { className: "bcms-file-pending", "aria-live": "polite", children: "Uploading\u2026" }) : null,
|
|
386
|
+
note ? /* @__PURE__ */ jsx("span", { className: "bcms-field-error", "aria-live": "polite", children: note }) : null,
|
|
387
|
+
field.helpText ? /* @__PURE__ */ jsx("span", { className: "bcms-field-help", "data-bcms-form-part": "help", children: field.helpText }) : null,
|
|
388
|
+
error ? /* @__PURE__ */ jsx("span", { className: "bcms-field-error", role: "alert", children: error }) : null
|
|
389
|
+
] });
|
|
390
|
+
}
|
|
275
391
|
function Field({ field, value, error, onChange }) {
|
|
276
392
|
const required = field.required;
|
|
277
393
|
const errorNode = error ? /* @__PURE__ */ jsx("span", { className: "bcms-field-error", role: "alert", children: error }) : null;
|
|
@@ -401,6 +517,8 @@ function Field({ field, value, error, onChange }) {
|
|
|
401
517
|
] });
|
|
402
518
|
}
|
|
403
519
|
export {
|
|
404
|
-
BcmsForm
|
|
520
|
+
BcmsForm,
|
|
521
|
+
fileFieldValidity,
|
|
522
|
+
planFilePick
|
|
405
523
|
};
|
|
406
524
|
//# sourceMappingURL=form.js.map
|
package/dist/form.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/form.tsx"],"sourcesContent":["\"use client\";\n\n/**\n * <BcmsForm> — render a BetterCMS form natively in React, the headless way.\n *\n * Pass a form straight from your content snapshot (`readSnapshot().forms[n]`) or\n * the delivery API. It renders real inputs (no iframe), handles conditional\n * `showIf` fields, URL-query prefill, the honeypot, an optional Turnstile widget,\n * and submits via `@bettercms-ai/sdk`'s `submitForm`. All visible markup is\n * unstyled and class-driven, so the host site owns the look.\n */\n\nimport { lazy, Suspense, useEffect, useMemo, useRef, useState, type FormEvent, type ReactElement } from \"react\";\nimport {\n submitForm,\n shouldShowField,\n formInitialValues,\n asStringArray,\n toggleOption,\n type DeliveryForm,\n type DeliveryFormField,\n type FormValue,\n type FormValues,\n type FormSubmitError,\n} from \"@bettercms-ai/sdk/read\";\n\nconst TURNSTILE_SRC = \"https://challenges.cloudflare.com/turnstile/v0/api.js\";\n\n/**\n * The platform honeypot's clipped wrapper (the forms contract's `_bcms_hp`): out of flow, so nothing\n * moves; clipped, not off-screen, so a right-to-left page cannot scroll to it; never `display:none`,\n * which some bots skip. Any value in it is a bot's. The renderer's FORM_HONEYPOT, pinned by\n * src/__tests__/content/form-script-pin.test.ts.\n */\nconst HONEYPOT_STYLE = {\n position: \"absolute\",\n width: \"1px\",\n height: \"1px\",\n overflow: \"hidden\",\n clipPath: \"inset(50%)\",\n whiteSpace: \"nowrap\",\n} as const;\n\n/**\n * The country-picker phone control, loaded only when a form actually has one.\n *\n * It carries libphonenumber's metadata (~80KB), which no form without a picker should pay\n * for. The import specifier must survive into `dist/form.js` rather than being inlined —\n * see the `external` entry in tsup.config.ts and the dist greps in the tests.\n */\nconst PhoneField = lazy(() => import(\"./phone-field.js\"));\n\n// Field type → native <input type>. Other types render their own element.\nconst INPUT_TYPES: Partial<Record<DeliveryFormField[\"type\"], string>> = {\n text: \"text\",\n email: \"email\",\n phone: \"tel\",\n url: \"url\",\n number: \"number\",\n date: \"date\",\n};\n\nexport interface BcmsFormProps {\n /** A form from your content snapshot or the delivery API. */\n form: DeliveryForm;\n /** API origin. Defaults to the SDK default (https://api.bettercms.ai). */\n apiBase?: string;\n /** Turnstile site key — needed to render the widget when `form.turnstileEnabled`. */\n turnstileSiteKey?: string;\n /** Called with the new submission id after a successful submit (before any redirect). */\n onSubmitted?: (submissionId: string) => void;\n /** Class for the <form> element; field wrappers/status use `bcms-*` classes. */\n className?: string;\n}\n\ntype Status = { state: \"idle\" | \"submitting\" | \"error\" | \"success\"; message?: string };\n\nfunction readPrefill(): Record<string, string> {\n if (typeof window === \"undefined\") return {};\n const out: Record<string, string> = {};\n new URLSearchParams(window.location.search).forEach((v, k) => {\n out[k] = v;\n });\n return out;\n}\n\ntype Page = { label: string | null; key: string | null; fields: DeliveryFormField[] };\n\n/**\n * Cut the flat field list into pages at its `step` dividers, or null when it has none. Fields\n * before the first divider are page 1; an empty page is dropped. The hosted renderer and\n * BcmsForm.astro carry the same rule: each package publishes on its own, so none of them can\n * count on a newer shared helper arriving with it.\n */\nfunction splitSteps(fields: DeliveryFormField[]): Page[] | null {\n if (!fields.some((f) => f.type === \"step\")) return null;\n const pages: Page[] = [];\n let cur: Page = { label: null, key: null, fields: [] };\n for (const f of fields) {\n if (f.type !== \"step\") {\n cur.fields.push(f);\n continue;\n }\n if (cur.fields.length) pages.push(cur);\n cur = { label: f.label, key: f.key, fields: [] };\n }\n if (cur.fields.length) pages.push(cur);\n return pages;\n}\n\nfunction resetTurnstile(): void {\n const t = (globalThis as { turnstile?: { reset: () => void } }).turnstile;\n if (t) {\n try {\n t.reset();\n } catch {\n /* widget not mounted yet */\n }\n }\n}\n\nexport function BcmsForm({\n form,\n apiBase,\n turnstileSiteKey,\n onSubmitted,\n className,\n}: BcmsFormProps): ReactElement {\n const showTurnstile = Boolean(form.turnstileEnabled && turnstileSiteKey);\n const [values, setValues] = useState<FormValues>(() => {\n const init = formInitialValues(form, readPrefill());\n if (form.honeypotField) init[form.honeypotField] = \"\";\n return init;\n });\n const [status, setStatus] = useState<Status>({ state: \"idle\" });\n const [fieldErrors, setFieldErrors] = useState<Record<string, string>>({});\n\n // Steps. Until the component has mounted every page is shown, so server-rendered output (and a\n // visitor without JavaScript) gets one long form; `enhanced` then turns it into pages.\n const pages = useMemo(() => splitSteps(form.fields), [form.fields]);\n const [enhanced, setEnhanced] = useState(false);\n const [step, setStep] = useState(0);\n const pageRefs = useRef<(HTMLFieldSetElement | null)[]>([]);\n const headingRefs = useRef<(HTMLHeadingElement | null)[]>([]);\n const moveFocus = useRef(false);\n const last = pages ? pages.length - 1 : 0;\n const paged = Boolean(pages && enhanced);\n // When the form went live: `_bcms_t` is the whole ms from here to the submit.\n const shownAt = useRef(0);\n useEffect(() => {\n setEnhanced(true);\n shownAt.current = Date.now();\n }, []);\n // Focus follows the visitor to the new page's heading, never on first paint.\n useEffect(() => {\n if (!moveFocus.current) return;\n moveFocus.current = false;\n headingRefs.current[step]?.focus();\n }, [step]);\n\n // The browser's own validity, for ONE page: the first control that fails reports its message.\n function pageInvalid(i: number): boolean {\n const controls = pageRefs.current[i]?.querySelectorAll<HTMLInputElement>(\"input,select,textarea\") ?? [];\n for (const c of controls) {\n if (!c.checkValidity()) {\n c.reportValidity();\n return true;\n }\n }\n return false;\n }\n function goTo(i: number): void {\n moveFocus.current = true;\n setStep(i);\n }\n function next(): void {\n if (!pageInvalid(step)) goTo(step + 1);\n }\n\n // Cloudflare auto-renders any `.cf-turnstile` element once its script is present.\n useEffect(() => {\n if (!showTurnstile || document.querySelector(`script[src=\"${TURNSTILE_SRC}\"]`)) return;\n const script = document.createElement(\"script\");\n script.src = TURNSTILE_SRC;\n script.async = true;\n script.defer = true;\n document.head.appendChild(script);\n }, [showTurnstile]);\n\n const visibleFields = useMemo(\n () => form.fields.filter((f) => f.type !== \"hidden\" && f.type !== \"step\" && shouldShowField(f, values)),\n [form.fields, values],\n );\n\n const setValue = (key: string, value: FormValue) =>\n setValues((prev) => ({ ...prev, [key]: value }));\n\n async function handleSubmit(e: FormEvent<HTMLFormElement>): Promise<void> {\n e.preventDefault();\n // Enter inside a field before the last page moves on rather than submitting half a form.\n if (paged && step < last) return next();\n setStatus({ state: \"submitting\" });\n setFieldErrors({});\n\n const tokenEl = e.currentTarget.querySelector<HTMLInputElement>(\n '[name=\"cf-turnstile-response\"]',\n );\n const turnstileToken = tokenEl?.value || undefined;\n\n // Drop conditionally-hidden fields so a hidden required field can't block submit;\n // keep hidden-type fields and the honeypot (the API classifies bots on it).\n const data: FormValues = {};\n for (const field of form.fields) {\n if (field.type === \"step\") continue; // a divider is never an answer\n if (field.type === \"hidden\" || shouldShowField(field, values)) {\n data[field.key] = values[field.key];\n }\n }\n if (form.honeypotField) data[form.honeypotField] = values[form.honeypotField] ?? \"\";\n // The platform's checks: the honeypot's value (a person leaves it empty) and the time taken.\n data._bcms_hp = (e.currentTarget.elements.namedItem(\"_bcms_hp\") as HTMLInputElement | null)?.value ?? \"\";\n data._bcms_t = String(Date.now() - shownAt.current);\n\n try {\n const { id } = await submitForm({ formId: form.id, data, turnstileToken, baseUrl: apiBase });\n onSubmitted?.(id);\n // A web address only: a stored `javascript:` URL would run on the site's own origin.\n if (form.redirectUrl && /^https?:/i.test(form.redirectUrl)) {\n window.location.href = form.redirectUrl;\n return;\n }\n const reset = formInitialValues(form);\n if (form.honeypotField) reset[form.honeypotField] = \"\";\n setValues(reset);\n setStep(0);\n setStatus({\n state: \"success\",\n message: form.successMessage ?? \"Thanks! Your submission was received.\",\n });\n resetTurnstile();\n } catch (err) {\n const e2 = err as FormSubmitError;\n if (e2.fieldErrors) {\n setFieldErrors(e2.fieldErrors);\n // The server found a problem on a page the visitor has left: take them back to it.\n const bad = pages?.findIndex((p) => p.fields.some((f) => e2.fieldErrors?.[f.key]));\n if (bad !== undefined && bad >= 0) goTo(bad);\n }\n setStatus({ state: \"error\", message: e2.message || \"Something went wrong. Please try again.\" });\n resetTurnstile();\n }\n }\n\n return (\n // `data-bcms-form` carries the id so the Visual Editor can find THIS form in the\n // preview frame and patch its copy live. Valued rather than bare: the runtime\n // selectors are `form[data-bcms-form]`, which a valued attribute still matches.\n <form className={className} onSubmit={handleSubmit} noValidate data-bcms-form={form.id}>\n {pages\n ? pages.map((page, i) => (\n <fieldset\n key={page.key ?? \"first\"}\n ref={(el) => {\n pageRefs.current[i] = el;\n }}\n className=\"bcms-step\"\n data-bcms-step={i + 1}\n hidden={paged && i !== step}\n aria-labelledby={`bcms-step-${form.id}-${i + 1}`}\n >\n <h3\n id={`bcms-step-${form.id}-${i + 1}`}\n className=\"bcms-step-title\"\n tabIndex={-1}\n ref={(el) => {\n headingRefs.current[i] = el;\n }}\n data-bcms-form-field={page.key ?? undefined}\n >\n <span className=\"bcms-step-count\">\n Step {i + 1} of {pages.length}\n </span>\n {page.label ? (\n <>\n {\" \"}\n <span data-bcms-form-part=\"label\">{page.label}</span>\n </>\n ) : null}\n </h3>\n {visibleFields\n .filter((f) => page.fields.includes(f))\n .map((field) => (\n <Field\n key={field.key}\n field={field}\n value={values[field.key]}\n error={fieldErrors[field.key]}\n onChange={(v) => setValue(field.key, v)}\n />\n ))}\n {paged ? (\n <div className=\"bcms-step-nav\">\n {i > 0 ? (\n <button type=\"button\" data-bcms-step-back onClick={() => goTo(i - 1)}>\n Back\n </button>\n ) : null}\n {i < last ? (\n <button type=\"button\" data-bcms-step-next onClick={next}>\n Next\n </button>\n ) : null}\n </div>\n ) : null}\n </fieldset>\n ))\n : visibleFields.map((field) => (\n <Field\n key={field.key}\n field={field}\n value={values[field.key]}\n error={fieldErrors[field.key]}\n onChange={(v) => setValue(field.key, v)}\n />\n ))}\n\n {form.honeypotField ? (\n <span aria-hidden=\"true\" style={{ position: \"absolute\", left: \"-9999px\" }}>\n <input\n type=\"text\"\n name={form.honeypotField}\n tabIndex={-1}\n autoComplete=\"off\"\n value={String(values[form.honeypotField] ?? \"\")}\n onChange={(e) => setValue(form.honeypotField as string, e.target.value)}\n />\n </span>\n ) : null}\n\n {showTurnstile ? <div className=\"cf-turnstile\" data-sitekey={turnstileSiteKey} /> : null}\n\n <div style={HONEYPOT_STYLE}>\n <input type=\"text\" name=\"_bcms_hp\" tabIndex={-1} autoComplete=\"off\" aria-hidden=\"true\" />\n </div>\n\n <button\n type=\"submit\"\n hidden={paged && step < last}\n disabled={status.state === \"submitting\"}\n data-bcms-form-part=\"submit\"\n >\n {status.state === \"submitting\" ? \"Submitting…\" : form.submitLabel ?? \"Submit\"}\n </button>\n\n {status.message ? (\n <p\n className={`bcms-form-status bcms-form-status--${status.state}`}\n role=\"status\"\n aria-live=\"polite\"\n >\n {status.message}\n </p>\n ) : null}\n </form>\n );\n}\n\ninterface FieldProps {\n field: DeliveryFormField;\n value: FormValue;\n error?: string;\n onChange: (value: FormValue) => void;\n}\n\nfunction Field({ field, value, error, onChange }: FieldProps): ReactElement {\n const required = field.required;\n const errorNode = error ? (\n <span className=\"bcms-field-error\" role=\"alert\">\n {error}\n </span>\n ) : null;\n // Every author-editable string carries a `data-bcms-form-part` so the Visual Editor can\n // repaint it live. A string the dock can edit but cannot mark shows stale on the canvas.\n const helpNode = field.helpText ? (\n <span className=\"bcms-field-help\" data-bcms-form-part=\"help\">\n {field.helpText}\n </span>\n ) : null;\n\n if (field.type === \"checkbox\" || field.type === \"consent\") {\n return (\n <label\n className=\"bcms-field bcms-field--checkbox\"\n data-field={field.key}\n data-bcms-form-field={field.key}\n >\n <input\n type=\"checkbox\"\n name={field.key}\n required={required}\n checked={Boolean(value)}\n onChange={(e) => onChange(e.target.checked)}\n />{\" \"}\n <span data-bcms-form-part=\"label\">\n {field.label}\n {required ? \" *\" : \"\"}\n </span>\n {helpNode}\n {errorNode}\n </label>\n );\n }\n\n // Pick-one and pick-many are groups of controls, not a single element, so they\n // return their own <fieldset> rather than flowing into the label+control shape\n // below. Without these two branches both fell through to `<input type=\"text\">`.\n if (field.type === \"radio\" || field.type === \"checkboxes\") {\n const multi = field.type === \"checkboxes\";\n const selected = asStringArray(value);\n return (\n <fieldset\n className={`bcms-field bcms-field--${multi ? \"checkboxes\" : \"radio\"}`}\n data-field={field.key}\n data-bcms-form-field={field.key}\n >\n <legend data-bcms-form-part=\"label\">\n {field.label}\n {required ? \" *\" : \"\"}\n </legend>\n {(field.options ?? []).map((opt) => (\n <label key={opt} className=\"bcms-option\">\n <input\n type={multi ? \"checkbox\" : \"radio\"}\n name={field.key}\n value={opt}\n // `required` on every radio in a group is the native way to demand one\n // choice. On checkboxes it would demand ALL of them, so it is omitted —\n // the API enforces non-empty instead.\n required={!multi && required}\n checked={multi ? selected.includes(opt) : value === opt}\n onChange={(e) =>\n onChange(multi ? toggleOption(value, opt, e.target.checked) : opt)\n }\n />{\" \"}\n <span data-bcms-form-part=\"option\">{opt}</span>\n </label>\n ))}\n {helpNode}\n {errorNode}\n </fieldset>\n );\n }\n\n const str = String(value ?? \"\");\n let control: ReactElement;\n if (field.type === \"textarea\") {\n control = (\n <textarea\n name={field.key}\n placeholder={field.placeholder}\n required={required}\n value={str}\n onChange={(e) => onChange(e.target.value)}\n />\n );\n } else if (field.type === \"select\") {\n control = (\n <select name={field.key} required={required} value={str} onChange={(e) => onChange(e.target.value)}>\n <option value=\"\" disabled>\n Choose…\n </option>\n {(field.options ?? []).map((opt) => (\n <option key={opt} value={opt} data-bcms-form-part=\"option\">\n {opt}\n </option>\n ))}\n </select>\n );\n } else if (field.type === \"phone\" && field.ui?.countryPicker) {\n // The fallback is a usable tel input inside the SAME wrapper, so the host's `.bcms-phone`\n // rules apply before and after the chunk lands and the swap is not a layout surprise.\n control = (\n <Suspense\n fallback={\n <span className=\"bcms-phone\">\n <input type=\"tel\" name={field.key} placeholder={field.placeholder} required={required} value={str} onChange={(e) => onChange(e.target.value)} autoComplete=\"tel\" dir=\"ltr\" />\n </span>\n }\n >\n <PhoneField\n name={field.key}\n value={str}\n onChange={onChange}\n placeholder={field.placeholder}\n required={required}\n defaultCountry={field.ui.defaultCountry}\n />\n </Suspense>\n );\n } else {\n control = (\n <input\n type={INPUT_TYPES[field.type] ?? \"text\"}\n name={field.key}\n placeholder={field.placeholder}\n required={required}\n value={str}\n onChange={(e) => onChange(e.target.value)}\n />\n );\n }\n\n return (\n <p className=\"bcms-field\" data-field={field.key} data-bcms-form-field={field.key}>\n <label data-bcms-form-part=\"label\">\n {field.label}\n {required ? \" *\" : \"\"}\n </label>\n <br />\n {control}\n {helpNode}\n {errorNode}\n </p>\n );\n}\n"],"mappings":";;;;AAYA,SAAS,MAAM,UAAU,WAAW,SAAS,QAAQ,gBAAmD;AACxG;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAMK;AA+PS,SAIE,UAEE,KANJ;AA7PhB,IAAM,gBAAgB;AAQtB,IAAM,iBAAiB;AAAA,EACrB,UAAU;AAAA,EACV,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,UAAU;AAAA,EACV,YAAY;AACd;AASA,IAAM,aAAa,KAAK,MAAM,OA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;AAAA;AAAA,IAC1C;AAAA,EAEJ;AAEA,SACE,qBAAC,OAAE,WAAU,cAAa,cAAY,MAAM,KAAK,wBAAsB,MAAM,KAC3E;AAAA,yBAAC,WAAM,uBAAoB,SACxB;AAAA,YAAM;AAAA,MACN,WAAW,OAAO;AAAA,OACrB;AAAA,IACA,oBAAC,QAAG;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,KACH;AAEJ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/form.tsx"],"sourcesContent":["\"use client\";\n\n/**\n * <BcmsForm> — render a BetterCMS form natively in React, the headless way.\n *\n * Pass a form straight from your content snapshot (`readSnapshot().forms[n]`) or\n * the delivery API. It renders real inputs (no iframe), handles conditional\n * `showIf` fields, URL-query prefill, the honeypot, an optional Turnstile widget,\n * and submits via `@bettercms-ai/sdk`'s `submitForm`. All visible markup is\n * unstyled and class-driven, so the host site owns the look.\n */\n\nimport { lazy, Suspense, useEffect, useMemo, useRef, useState, type FormEvent, type ReactElement } from \"react\";\nimport {\n submitForm,\n shouldShowField,\n formInitialValues,\n asStringArray,\n toggleOption,\n type DeliveryForm,\n type DeliveryFormField,\n type FormValue,\n type FormValues,\n type FormSubmitError,\n uploadFormFile,\n fileFieldLimits,\n fileFieldRefusal,\n} from \"@bettercms-ai/sdk/read\";\n\nconst TURNSTILE_SRC = \"https://challenges.cloudflare.com/turnstile/v0/api.js\";\n\n/** A file a visitor attached and the upload route stored: what the submission names it by. */\nexport interface StoredFile {\n id: string;\n name: string;\n size: number;\n}\n\n/**\n * What to do with the files a visitor just picked for a `file` field, before any byte is sent:\n * upload `take` (with `replace`, the file that lands replaces what is stored), or show `refusal`. `stored` counts stored, in-flight and queued files.\n * - a field that takes one file: the new pick replaces the old one;\n * - otherwise a pick that would go past the field's count is refused whole;\n * - each file is pre-checked for type and size (@see fileFieldLimits; the server holds the rest).\n */\nexport function planFilePick<F extends { name: string; size: number }>(\n limits: { accept: string[]; maxFiles: number; maxSizeMb: number },\n stored: number,\n picked: readonly F[],\n): { take: F[]; replace: boolean } | { refusal: string } {\n const take = limits.maxFiles === 1 ? picked.slice(0, 1) : [...picked];\n if (limits.maxFiles > 1 && stored + take.length > limits.maxFiles) {\n return { refusal: `You can attach at most ${limits.maxFiles} files.` };\n }\n for (const file of take) {\n const refusal = fileFieldRefusal(limits, file);\n if (refusal) return { refusal };\n }\n return { take, replace: limits.maxFiles === 1 };\n}\n\n/**\n * Why a file field cannot be submitted yet, or \"\" when it can: the control's custom validity.\n * A step's Next button and the browser's own checks read it; the field is never `required`,\n * because what it holds is the list of stored files, not the picker's value.\n */\nexport function fileFieldValidity(required: boolean | undefined, stored: number, uploading: boolean): string {\n if (uploading) return \"Please wait: a file is still uploading.\";\n if (required && stored === 0) return \"Please attach a file.\";\n return \"\";\n}\n\n/**\n * The platform honeypot's clipped wrapper (the forms contract's `_bcms_hp`): out of flow, so nothing\n * moves; clipped, not off-screen, so a right-to-left page cannot scroll to it; never `display:none`,\n * which some bots skip. Any value in it is a bot's. The renderer's FORM_HONEYPOT, pinned by\n * src/__tests__/content/form-script-pin.test.ts.\n */\nconst HONEYPOT_STYLE = {\n position: \"absolute\",\n width: \"1px\",\n height: \"1px\",\n overflow: \"hidden\",\n clipPath: \"inset(50%)\",\n whiteSpace: \"nowrap\",\n} as const;\n\n/**\n * The country-picker phone control, loaded only when a form actually has one.\n *\n * It carries libphonenumber's metadata (~80KB), which no form without a picker should pay\n * for. The import specifier must survive into `dist/form.js` rather than being inlined —\n * see the `external` entry in tsup.config.ts and the dist greps in the tests.\n */\nconst PhoneField = lazy(() => import(\"./phone-field.js\"));\n\n// Field type → native <input type>. Other types render their own element.\nconst INPUT_TYPES: Partial<Record<DeliveryFormField[\"type\"], string>> = {\n text: \"text\",\n email: \"email\",\n phone: \"tel\",\n url: \"url\",\n number: \"number\",\n date: \"date\",\n};\n\nexport interface BcmsFormProps {\n /** A form from your content snapshot or the delivery API. */\n form: DeliveryForm;\n /** API origin. Defaults to the SDK default (https://api.bettercms.ai). */\n apiBase?: string;\n /** Turnstile site key — needed to render the widget when `form.turnstileEnabled`. */\n turnstileSiteKey?: string;\n /** Called with the new submission id after a successful submit (before any redirect). */\n onSubmitted?: (submissionId: string) => void;\n /** Class for the <form> element; field wrappers/status use `bcms-*` classes. */\n className?: string;\n}\n\ntype Status = { state: \"idle\" | \"submitting\" | \"error\" | \"success\"; message?: string };\n\nfunction readPrefill(): Record<string, string> {\n if (typeof window === \"undefined\") return {};\n const out: Record<string, string> = {};\n new URLSearchParams(window.location.search).forEach((v, k) => {\n out[k] = v;\n });\n return out;\n}\n\ntype Page = { label: string | null; key: string | null; fields: DeliveryFormField[] };\n\n/**\n * Cut the flat field list into pages at its `step` dividers, or null when it has none. Fields\n * before the first divider are page 1; an empty page is dropped. The hosted renderer and\n * BcmsForm.astro carry the same rule: each package publishes on its own, so none of them can\n * count on a newer shared helper arriving with it.\n */\nfunction splitSteps(fields: DeliveryFormField[]): Page[] | null {\n if (!fields.some((f) => f.type === \"step\")) return null;\n const pages: Page[] = [];\n let cur: Page = { label: null, key: null, fields: [] };\n for (const f of fields) {\n if (f.type !== \"step\") {\n cur.fields.push(f);\n continue;\n }\n if (cur.fields.length) pages.push(cur);\n cur = { label: f.label, key: f.key, fields: [] };\n }\n if (cur.fields.length) pages.push(cur);\n return pages;\n}\n\nfunction resetTurnstile(): void {\n const t = (globalThis as { turnstile?: { reset: () => void } }).turnstile;\n if (t) {\n try {\n t.reset();\n } catch {\n /* widget not mounted yet */\n }\n }\n}\n\nexport function BcmsForm({\n form,\n apiBase,\n turnstileSiteKey,\n onSubmitted,\n className,\n}: BcmsFormProps): ReactElement {\n const showTurnstile = Boolean(form.turnstileEnabled && turnstileSiteKey);\n const [values, setValues] = useState<FormValues>(() => {\n const init = formInitialValues(form, readPrefill());\n if (form.honeypotField) init[form.honeypotField] = \"\";\n return init;\n });\n const [status, setStatus] = useState<Status>({ state: \"idle\" });\n const [fieldErrors, setFieldErrors] = useState<Record<string, string>>({});\n\n // File fields. The files live HERE, not in the field: a field hidden by its condition is\n // unmounted, and what it held must not be lost, nor posted while it is hidden (handleSubmit\n // reads only shown fields). One upload in flight per form: picks queue behind each other.\n const [files, setFiles] = useState<Record<string, StoredFile[]>>({});\n const [uploading, setUploading] = useState<Record<string, number>>({});\n const [fileNotes, setFileNotes] = useState<Record<string, string>>({});\n const fileInputs = useRef<Record<string, HTMLInputElement | null>>({});\n const uploadQueue = useRef<Promise<void>>(Promise.resolve());\n // Bumped by each pick on a one-file field: a queued upload from an older pick is dropped.\n const pickTurn = useRef<Record<string, number>>({});\n const anyUploading = Object.values(uploading).some((n) => n > 0);\n // Each file control's validity, so a step's Next button and the browser stop on it.\n useEffect(() => {\n for (const field of form.fields) {\n if (field.type !== \"file\") continue;\n fileInputs.current[field.key]?.setCustomValidity(\n fileFieldValidity(field.required, files[field.key]?.length ?? 0, (uploading[field.key] ?? 0) > 0),\n );\n }\n });\n\n function pickFiles(field: DeliveryFormField, picked: File[]): void {\n const key = field.key;\n // What the field holds or will hold: stored, in flight and queued.\n const plan = planFilePick(fileFieldLimits(field), (files[key]?.length ?? 0) + (uploading[key] ?? 0), picked);\n if (\"refusal\" in plan) {\n setFileNotes((n) => ({ ...n, [key]: plan.refusal }));\n return;\n }\n if (plan.take.length === 0) return;\n setFileNotes((n) => ({ ...n, [key]: \"\" }));\n const turn = (pickTurn.current[key] = (pickTurn.current[key] ?? 0) + 1);\n setUploading((u) => ({ ...u, [key]: (u[key] ?? 0) + plan.take.length }));\n for (const file of plan.take) {\n uploadQueue.current = uploadQueue.current.then(async () => {\n try {\n // A one-file field picked again while this waited: the newer pick wins, this one is never sent.\n if (plan.replace && pickTurn.current[key] !== turn) return;\n const stored = await uploadFormFile({ formId: form.id, fieldKey: key, file, baseUrl: apiBase });\n // A one-file field: the file that lands replaces what is there.\n setFiles((f) => ({ ...f, [key]: plan.replace ? [stored] : [...(f[key] ?? []), stored] }));\n } catch (err) {\n // The server's own sentence (\"This file is larger than 10 MB.\"). No retry.\n const message = err instanceof Error && err.message ? err.message : \"This file could not be uploaded. Please try again.\";\n setFileNotes((n) => ({ ...n, [key]: message }));\n } finally {\n setUploading((u) => ({ ...u, [key]: Math.max(0, (u[key] ?? 1) - 1) }));\n }\n });\n }\n }\n\n function removeFile(key: string, id: string): void {\n setFiles((f) => ({ ...f, [key]: (f[key] ?? []).filter((x) => x.id !== id) }));\n }\n\n /** One field, as the page draws it. */\n function renderField(field: DeliveryFormField): ReactElement {\n if (field.type === \"file\") {\n return (\n <FileField\n key={field.key}\n field={field}\n stored={files[field.key] ?? []}\n uploading={(uploading[field.key] ?? 0) > 0}\n note={fileNotes[field.key]}\n error={fieldErrors[field.key]}\n inputRef={(el) => {\n fileInputs.current[field.key] = el;\n }}\n onPick={(picked) => pickFiles(field, picked)}\n onRemove={(id) => removeFile(field.key, id)}\n />\n );\n }\n return (\n <Field\n key={field.key}\n field={field}\n value={values[field.key]}\n error={fieldErrors[field.key]}\n onChange={(v) => setValue(field.key, v)}\n />\n );\n }\n\n // Steps. Until the component has mounted every page is shown, so server-rendered output (and a\n // visitor without JavaScript) gets one long form; `enhanced` then turns it into pages.\n const pages = useMemo(() => splitSteps(form.fields), [form.fields]);\n const [enhanced, setEnhanced] = useState(false);\n const [step, setStep] = useState(0);\n const pageRefs = useRef<(HTMLFieldSetElement | null)[]>([]);\n const headingRefs = useRef<(HTMLHeadingElement | null)[]>([]);\n const moveFocus = useRef(false);\n const last = pages ? pages.length - 1 : 0;\n const paged = Boolean(pages && enhanced);\n // When the form went live: `_bcms_t` is the whole ms from here to the submit.\n const shownAt = useRef(0);\n useEffect(() => {\n setEnhanced(true);\n shownAt.current = Date.now();\n }, []);\n // Focus follows the visitor to the new page's heading, never on first paint.\n useEffect(() => {\n if (!moveFocus.current) return;\n moveFocus.current = false;\n headingRefs.current[step]?.focus();\n }, [step]);\n\n // The browser's own validity, for ONE page: the first control that fails reports its message.\n function pageInvalid(i: number): boolean {\n const controls = pageRefs.current[i]?.querySelectorAll<HTMLInputElement>(\"input,select,textarea\") ?? [];\n for (const c of controls) {\n if (!c.checkValidity()) {\n c.reportValidity();\n return true;\n }\n }\n return false;\n }\n function goTo(i: number): void {\n moveFocus.current = true;\n setStep(i);\n }\n function next(): void {\n if (!pageInvalid(step)) goTo(step + 1);\n }\n\n // Cloudflare auto-renders any `.cf-turnstile` element once its script is present.\n useEffect(() => {\n if (!showTurnstile || document.querySelector(`script[src=\"${TURNSTILE_SRC}\"]`)) return;\n const script = document.createElement(\"script\");\n script.src = TURNSTILE_SRC;\n script.async = true;\n script.defer = true;\n document.head.appendChild(script);\n }, [showTurnstile]);\n\n const visibleFields = useMemo(\n () => form.fields.filter((f) => f.type !== \"hidden\" && f.type !== \"step\" && shouldShowField(f, values)),\n [form.fields, values],\n );\n\n const setValue = (key: string, value: FormValue) =>\n setValues((prev) => ({ ...prev, [key]: value }));\n\n async function handleSubmit(e: FormEvent<HTMLFormElement>): Promise<void> {\n e.preventDefault();\n // Enter inside a field before the last page moves on rather than submitting half a form.\n if (paged && step < last) return next();\n // The form is noValidate, so nothing else stops a submit while a file is still on its way:\n // without this an optional file would be left out of the submission without a word.\n if (anyUploading) {\n setStatus({ state: \"error\", message: \"Please wait: a file is still uploading.\" });\n return;\n }\n setStatus({ state: \"submitting\" });\n setFieldErrors({});\n\n const tokenEl = e.currentTarget.querySelector<HTMLInputElement>(\n '[name=\"cf-turnstile-response\"]',\n );\n const turnstileToken = tokenEl?.value || undefined;\n\n // Drop conditionally-hidden fields so a hidden required field can't block submit;\n // keep hidden-type fields and the honeypot (the API classifies bots on it).\n const data: FormValues = {};\n for (const field of form.fields) {\n if (field.type === \"step\") continue; // a divider is never an answer\n if (field.type === \"hidden\" || shouldShowField(field, values)) {\n // A file field's answer is the ids of the files stored for it.\n data[field.key] = field.type === \"file\" ? (files[field.key] ?? []).map((f) => f.id) : values[field.key];\n }\n }\n if (form.honeypotField) data[form.honeypotField] = values[form.honeypotField] ?? \"\";\n // The platform's checks: the honeypot's value (a person leaves it empty) and the time taken.\n data._bcms_hp = (e.currentTarget.elements.namedItem(\"_bcms_hp\") as HTMLInputElement | null)?.value ?? \"\";\n data._bcms_t = String(Date.now() - shownAt.current);\n\n try {\n const { id } = await submitForm({ formId: form.id, data, turnstileToken, baseUrl: apiBase });\n onSubmitted?.(id);\n // A web address only: a stored `javascript:` URL would run on the site's own origin.\n if (form.redirectUrl && /^https?:/i.test(form.redirectUrl)) {\n window.location.href = form.redirectUrl;\n return;\n }\n const reset = formInitialValues(form);\n if (form.honeypotField) reset[form.honeypotField] = \"\";\n setValues(reset);\n // The files now belong to that submission: a second one must attach its own.\n setFiles({});\n setFileNotes({});\n setStep(0);\n setStatus({\n state: \"success\",\n message: form.successMessage ?? \"Thanks! Your submission was received.\",\n });\n resetTurnstile();\n } catch (err) {\n const e2 = err as FormSubmitError;\n if (e2.fieldErrors) {\n setFieldErrors(e2.fieldErrors);\n // The server found a problem on a page the visitor has left: take them back to it.\n const bad = pages?.findIndex((p) => p.fields.some((f) => e2.fieldErrors?.[f.key]));\n if (bad !== undefined && bad >= 0) goTo(bad);\n }\n setStatus({ state: \"error\", message: e2.message || \"Something went wrong. Please try again.\" });\n resetTurnstile();\n }\n }\n\n return (\n // `data-bcms-form` carries the id so the Visual Editor can find THIS form in the\n // preview frame and patch its copy live. Valued rather than bare: the runtime\n // selectors are `form[data-bcms-form]`, which a valued attribute still matches.\n <form className={className} onSubmit={handleSubmit} noValidate data-bcms-form={form.id}>\n {pages\n ? pages.map((page, i) => (\n <fieldset\n key={page.key ?? \"first\"}\n ref={(el) => {\n pageRefs.current[i] = el;\n }}\n className=\"bcms-step\"\n data-bcms-step={i + 1}\n hidden={paged && i !== step}\n aria-labelledby={`bcms-step-${form.id}-${i + 1}`}\n >\n <h3\n id={`bcms-step-${form.id}-${i + 1}`}\n className=\"bcms-step-title\"\n tabIndex={-1}\n ref={(el) => {\n headingRefs.current[i] = el;\n }}\n data-bcms-form-field={page.key ?? undefined}\n >\n <span className=\"bcms-step-count\">\n Step {i + 1} of {pages.length}\n </span>\n {page.label ? (\n <>\n {\" \"}\n <span data-bcms-form-part=\"label\">{page.label}</span>\n </>\n ) : null}\n </h3>\n {visibleFields.filter((f) => page.fields.includes(f)).map(renderField)}\n {paged ? (\n <div className=\"bcms-step-nav\">\n {i > 0 ? (\n <button type=\"button\" data-bcms-step-back onClick={() => goTo(i - 1)}>\n Back\n </button>\n ) : null}\n {i < last ? (\n <button type=\"button\" data-bcms-step-next onClick={next}>\n Next\n </button>\n ) : null}\n </div>\n ) : null}\n </fieldset>\n ))\n : visibleFields.map(renderField)}\n\n {form.honeypotField ? (\n <span aria-hidden=\"true\" style={{ position: \"absolute\", left: \"-9999px\" }}>\n <input\n type=\"text\"\n name={form.honeypotField}\n tabIndex={-1}\n autoComplete=\"off\"\n value={String(values[form.honeypotField] ?? \"\")}\n onChange={(e) => setValue(form.honeypotField as string, e.target.value)}\n />\n </span>\n ) : null}\n\n {showTurnstile ? <div className=\"cf-turnstile\" data-sitekey={turnstileSiteKey} /> : null}\n\n <div style={HONEYPOT_STYLE}>\n <input type=\"text\" name=\"_bcms_hp\" tabIndex={-1} autoComplete=\"off\" aria-hidden=\"true\" />\n </div>\n\n <button\n type=\"submit\"\n hidden={paged && step < last}\n disabled={status.state === \"submitting\" || anyUploading}\n data-bcms-form-part=\"submit\"\n >\n {status.state === \"submitting\" ? \"Submitting…\" : form.submitLabel ?? \"Submit\"}\n </button>\n\n {status.message ? (\n <p\n className={`bcms-form-status bcms-form-status--${status.state}`}\n role=\"status\"\n aria-live=\"polite\"\n >\n {status.message}\n </p>\n ) : null}\n </form>\n );\n}\n\ninterface FileFieldProps {\n field: DeliveryFormField;\n stored: StoredFile[];\n uploading: boolean;\n note?: string;\n error?: string;\n inputRef: (el: HTMLInputElement | null) => void;\n onPick: (picked: File[]) => void;\n onRemove: (id: string) => void;\n}\n\n/**\n * A `file` field: a native file picker and the list of files stored for it. Each pick uploads at\n * once (BcmsForm.pickFiles); the picker is cleared after each, and the list is what is submitted.\n * Unstyled and class-driven, like every other field.\n */\nfunction FileField({ field, stored, uploading, note, error, inputRef, onPick, onRemove }: FileFieldProps): ReactElement {\n const limits = fileFieldLimits(field);\n const id = `bcms-f-${field.key}`;\n return (\n <p className=\"bcms-field bcms-field--file\" data-field={field.key} data-bcms-form-field={field.key}>\n <label htmlFor={id} data-bcms-form-part=\"label\">\n {field.label}\n {field.required ? \" *\" : \"\"}\n </label>\n <br />\n <input\n type=\"file\"\n id={id}\n ref={inputRef}\n accept={limits.accept.map((e) => `.${e}`).join(\",\")}\n multiple={limits.maxFiles > 1}\n onChange={(e) => {\n const picked = Array.from(e.target.files ?? []);\n e.target.value = \"\";\n onPick(picked);\n }}\n />\n {stored.length > 0 ? (\n <ul className=\"bcms-file-list\">\n {stored.map((file) => (\n <li key={file.id}>\n <span className=\"bcms-file-name\">{file.name}</span>{\" \"}\n <button type=\"button\" className=\"bcms-file-remove\" aria-label={`Remove ${file.name}`} onClick={() => onRemove(file.id)}>\n Remove\n </button>\n </li>\n ))}\n </ul>\n ) : null}\n {uploading ? (\n <span className=\"bcms-file-pending\" aria-live=\"polite\">\n Uploading…\n </span>\n ) : null}\n {note ? (\n <span className=\"bcms-field-error\" aria-live=\"polite\">\n {note}\n </span>\n ) : null}\n {field.helpText ? (\n <span className=\"bcms-field-help\" data-bcms-form-part=\"help\">\n {field.helpText}\n </span>\n ) : null}\n {error ? (\n <span className=\"bcms-field-error\" role=\"alert\">\n {error}\n </span>\n ) : null}\n </p>\n );\n}\n\ninterface FieldProps {\n field: DeliveryFormField;\n value: FormValue;\n error?: string;\n onChange: (value: FormValue) => void;\n}\n\nfunction Field({ field, value, error, onChange }: FieldProps): ReactElement {\n const required = field.required;\n const errorNode = error ? (\n <span className=\"bcms-field-error\" role=\"alert\">\n {error}\n </span>\n ) : null;\n // Every author-editable string carries a `data-bcms-form-part` so the Visual Editor can\n // repaint it live. A string the dock can edit but cannot mark shows stale on the canvas.\n const helpNode = field.helpText ? (\n <span className=\"bcms-field-help\" data-bcms-form-part=\"help\">\n {field.helpText}\n </span>\n ) : null;\n\n if (field.type === \"checkbox\" || field.type === \"consent\") {\n return (\n <label\n className=\"bcms-field bcms-field--checkbox\"\n data-field={field.key}\n data-bcms-form-field={field.key}\n >\n <input\n type=\"checkbox\"\n name={field.key}\n required={required}\n checked={Boolean(value)}\n onChange={(e) => onChange(e.target.checked)}\n />{\" \"}\n <span data-bcms-form-part=\"label\">\n {field.label}\n {required ? \" *\" : \"\"}\n </span>\n {helpNode}\n {errorNode}\n </label>\n );\n }\n\n // Pick-one and pick-many are groups of controls, not a single element, so they\n // return their own <fieldset> rather than flowing into the label+control shape\n // below. Without these two branches both fell through to `<input type=\"text\">`.\n if (field.type === \"radio\" || field.type === \"checkboxes\") {\n const multi = field.type === \"checkboxes\";\n const selected = asStringArray(value);\n return (\n <fieldset\n className={`bcms-field bcms-field--${multi ? \"checkboxes\" : \"radio\"}`}\n data-field={field.key}\n data-bcms-form-field={field.key}\n >\n <legend data-bcms-form-part=\"label\">\n {field.label}\n {required ? \" *\" : \"\"}\n </legend>\n {(field.options ?? []).map((opt) => (\n <label key={opt} className=\"bcms-option\">\n <input\n type={multi ? \"checkbox\" : \"radio\"}\n name={field.key}\n value={opt}\n // `required` on every radio in a group is the native way to demand one\n // choice. On checkboxes it would demand ALL of them, so it is omitted —\n // the API enforces non-empty instead.\n required={!multi && required}\n checked={multi ? selected.includes(opt) : value === opt}\n onChange={(e) =>\n onChange(multi ? toggleOption(value, opt, e.target.checked) : opt)\n }\n />{\" \"}\n <span data-bcms-form-part=\"option\">{opt}</span>\n </label>\n ))}\n {helpNode}\n {errorNode}\n </fieldset>\n );\n }\n\n const str = String(value ?? \"\");\n let control: ReactElement;\n if (field.type === \"textarea\") {\n control = (\n <textarea\n name={field.key}\n placeholder={field.placeholder}\n required={required}\n value={str}\n onChange={(e) => onChange(e.target.value)}\n />\n );\n } else if (field.type === \"select\") {\n control = (\n <select name={field.key} required={required} value={str} onChange={(e) => onChange(e.target.value)}>\n <option value=\"\" disabled>\n Choose…\n </option>\n {(field.options ?? []).map((opt) => (\n <option key={opt} value={opt} data-bcms-form-part=\"option\">\n {opt}\n </option>\n ))}\n </select>\n );\n } else if (field.type === \"phone\" && field.ui?.countryPicker) {\n // The fallback is a usable tel input inside the SAME wrapper, so the host's `.bcms-phone`\n // rules apply before and after the chunk lands and the swap is not a layout surprise.\n control = (\n <Suspense\n fallback={\n <span className=\"bcms-phone\">\n <input type=\"tel\" name={field.key} placeholder={field.placeholder} required={required} value={str} onChange={(e) => onChange(e.target.value)} autoComplete=\"tel\" dir=\"ltr\" />\n </span>\n }\n >\n <PhoneField\n name={field.key}\n value={str}\n onChange={onChange}\n placeholder={field.placeholder}\n required={required}\n defaultCountry={field.ui.defaultCountry}\n />\n </Suspense>\n );\n } else {\n control = (\n <input\n type={INPUT_TYPES[field.type] ?? \"text\"}\n name={field.key}\n placeholder={field.placeholder}\n required={required}\n value={str}\n onChange={(e) => onChange(e.target.value)}\n />\n );\n }\n\n return (\n <p className=\"bcms-field\" data-field={field.key} data-bcms-form-field={field.key}>\n <label data-bcms-form-part=\"label\">\n {field.label}\n {required ? \" *\" : \"\"}\n </label>\n <br />\n {control}\n {helpNode}\n {errorNode}\n </p>\n );\n}\n"],"mappings":";;;;AAYA,SAAS,MAAM,UAAU,WAAW,SAAS,QAAQ,gBAAmD;AACxG;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAMA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAsNC,SAsLU,UAtLV,KAkLQ,YAlLR;AApNR,IAAM,gBAAgB;AAgBf,SAAS,aACd,QACA,QACA,QACuD;AACvD,QAAM,OAAO,OAAO,aAAa,IAAI,OAAO,MAAM,GAAG,CAAC,IAAI,CAAC,GAAG,MAAM;AACpE,MAAI,OAAO,WAAW,KAAK,SAAS,KAAK,SAAS,OAAO,UAAU;AACjE,WAAO,EAAE,SAAS,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GAAG,IAAI,CAAC,QAC1B,oBAAC,YAAiB,OAAO,KAAK,uBAAoB,UAC/C,iBADU,GAEb,CACD;AAAA,OACH;AAAA,EAEJ,WAAW,MAAM,SAAS,WAAW,MAAM,IAAI,eAAe;AAG5D,cACE;AAAA,MAAC;AAAA;AAAA,QACC,UACE,oBAAC,UAAK,WAAU,cACd,8BAAC,WAAM,MAAK,OAAM,MAAM,MAAM,KAAK,aAAa,MAAM,aAAa,UAAoB,OAAO,KAAK,UAAU,CAAC,MAAM,SAAS,EAAE,OAAO,KAAK,GAAG,cAAa,OAAM,KAAI,OAAM,GAC7K;AAAA,QAGF;AAAA,UAAC;AAAA;AAAA,YACC,MAAM,MAAM;AAAA,YACZ,OAAO;AAAA,YACP;AAAA,YACA,aAAa,MAAM;AAAA,YACnB;AAAA,YACA,gBAAgB,MAAM,GAAG;AAAA;AAAA,QAC3B;AAAA;AAAA,IACF;AAAA,EAEJ,OAAO;AACL,cACE;AAAA,MAAC;AAAA;AAAA,QACC,MAAM,YAAY,MAAM,IAAI,KAAK;AAAA,QACjC,MAAM,MAAM;AAAA,QACZ,aAAa,MAAM;AAAA,QACnB;AAAA,QACA,OAAO;AAAA,QACP,UAAU,CAAC,MAAM,SAAS,EAAE,OAAO,KAAK;AAAA;AAAA,IAC1C;AAAA,EAEJ;AAEA,SACE,qBAAC,OAAE,WAAU,cAAa,cAAY,MAAM,KAAK,wBAAsB,MAAM,KAC3E;AAAA,yBAAC,WAAM,uBAAoB,SACxB;AAAA,YAAM;AAAA,MACN,WAAW,OAAO;AAAA,OACrB;AAAA,IACA,oBAAC,QAAG;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,KACH;AAEJ;","names":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -804,6 +804,13 @@ interface BcmsButtonProps {
|
|
|
804
804
|
}
|
|
805
805
|
declare function BcmsButton({ path, value, className }: BcmsButtonProps): react_jsx_runtime.JSX.Element | null;
|
|
806
806
|
|
|
807
|
+
interface BcmsIconProps {
|
|
808
|
+
/** The stored icon value: a set name, an image URL or an icon object. */
|
|
809
|
+
value: unknown;
|
|
810
|
+
className?: string;
|
|
811
|
+
}
|
|
812
|
+
declare function BcmsIcon({ value, className }: BcmsIconProps): react_jsx_runtime.JSX.Element | null;
|
|
813
|
+
|
|
807
814
|
/** What delivery adds to an image value beside its url: the facts this component reads. */
|
|
808
815
|
type ImageFacts = {
|
|
809
816
|
altText?: string | null;
|
|
@@ -905,4 +912,4 @@ interface VisualEditingProps {
|
|
|
905
912
|
studioUrl?: string;
|
|
906
913
|
}
|
|
907
914
|
|
|
908
|
-
export { type BcmsBlocksProps, BcmsButton, type BcmsButtonProps, BcmsDraftMarker, BcmsEmbedScripts, BcmsField, type BcmsFieldProps, type BcmsFormProps, BcmsImage, type BcmsImageProps, type BcmsLiveProps, type BcmsPageOptions, type BcmsSectionProps, type BcmsSectionsProps, type BetterCMSConfig, type BetterCMSEntry, BetterCMSError, type BetterCMSLiveConfig, type BetterCMSNext, type BetterCMSPage, type ContentSnapshot, type ContentSource, DEFAULT_SNAPSHOT_FILE, type DraftModeRouteConfig, type EntryFieldAttrs, type EntryList, type EntryRef, type EntryTransform, type FieldAttrs, type GetEntryOptions, type ListEntriesOptions, type LlmsModel, type LlmsModelField, type LlmsTxtOptions, type LlmsTxtRouteConfig, PREVIEW_TOKEN_COOKIE, type PageSnapshot, type ReadOptions, type RevalidateRouteConfig, SNAPSHOT_VERSION, type SectionColumnAttrs, type SectionRootAttrs, type SectionRootBlock, type SectionRootProps, type SectionsData, type SectionsRead, type SnapshotForms, type SnapshotPage, type VisualEditingProps, bcmsPage, buildMetadata, buildSnapshot, createBetterCMS, createDisableDraftRoute, createDraftModeRoute, createRevalidateRoute, defineBetterCMSLive, entryAttrs, entryField, fetchModels, fieldAttrs, fieldStyleOf, generateLlmsTxt, getBranchPreview, getComponent, getContent, getForm, getPage, getPreviewBranch, getPreviewToken, isDraftEnabled, llmsTxtRoute, parseSnapshot, readComponents, readForms, readPages, readSnapshot, sectionColumnAttrs, sectionRootAttrs, sectionsFor, sectionsServerSideProps, sectionsStaticProps, serializeSnapshot, writeSnapshot };
|
|
915
|
+
export { type BcmsBlocksProps, BcmsButton, type BcmsButtonProps, BcmsDraftMarker, BcmsEmbedScripts, BcmsField, type BcmsFieldProps, type BcmsFormProps, BcmsIcon, type BcmsIconProps, BcmsImage, type BcmsImageProps, type BcmsLiveProps, type BcmsPageOptions, type BcmsSectionProps, type BcmsSectionsProps, type BetterCMSConfig, type BetterCMSEntry, BetterCMSError, type BetterCMSLiveConfig, type BetterCMSNext, type BetterCMSPage, type ContentSnapshot, type ContentSource, DEFAULT_SNAPSHOT_FILE, type DraftModeRouteConfig, type EntryFieldAttrs, type EntryList, type EntryRef, type EntryTransform, type FieldAttrs, type GetEntryOptions, type ListEntriesOptions, type LlmsModel, type LlmsModelField, type LlmsTxtOptions, type LlmsTxtRouteConfig, PREVIEW_TOKEN_COOKIE, type PageSnapshot, type ReadOptions, type RevalidateRouteConfig, SNAPSHOT_VERSION, type SectionColumnAttrs, type SectionRootAttrs, type SectionRootBlock, type SectionRootProps, type SectionsData, type SectionsRead, type SnapshotForms, type SnapshotPage, type VisualEditingProps, bcmsPage, buildMetadata, buildSnapshot, createBetterCMS, createDisableDraftRoute, createDraftModeRoute, createRevalidateRoute, defineBetterCMSLive, entryAttrs, entryField, fetchModels, fieldAttrs, fieldStyleOf, generateLlmsTxt, getBranchPreview, getComponent, getContent, getForm, getPage, getPreviewBranch, getPreviewToken, isDraftEnabled, llmsTxtRoute, parseSnapshot, readComponents, readForms, readPages, readSnapshot, sectionColumnAttrs, sectionRootAttrs, sectionsFor, sectionsServerSideProps, sectionsStaticProps, serializeSnapshot, writeSnapshot };
|