@panneau/forms 5.0.0-alpha.4 → 5.0.0-alpha.42

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.
Files changed (60) hide show
  1. package/README.md +12 -10
  2. package/dist/ConflictDialog.js +200 -63
  3. package/dist/ConflictDialog.js.map +1 -1
  4. package/dist/ErrorSummary.js.map +1 -1
  5. package/dist/FieldErrorBoundary.js.map +1 -1
  6. package/dist/Form.css +98 -23
  7. package/dist/Form.d.ts +3 -2
  8. package/dist/Form.d.ts.map +1 -1
  9. package/dist/Form.js +122 -21
  10. package/dist/Form.js.map +1 -1
  11. package/dist/Form.module.js +29 -10
  12. package/dist/Form.module.js.map +1 -1
  13. package/dist/FormBinding.d.ts.map +1 -1
  14. package/dist/FormBinding.js +78 -67
  15. package/dist/FormBinding.js.map +1 -1
  16. package/dist/FormSkeleton.d.ts +23 -0
  17. package/dist/FormSkeleton.d.ts.map +1 -0
  18. package/dist/FormSkeleton.js +435 -0
  19. package/dist/FormSkeleton.js.map +1 -0
  20. package/dist/FormView.d.ts +43 -4
  21. package/dist/FormView.d.ts.map +1 -1
  22. package/dist/FormView.js +335 -121
  23. package/dist/FormView.js.map +1 -1
  24. package/dist/context.d.ts +8 -8
  25. package/dist/context.d.ts.map +1 -1
  26. package/dist/context.js +8 -16
  27. package/dist/context.js.map +1 -1
  28. package/dist/cx.js.map +1 -1
  29. package/dist/describe.js.map +1 -1
  30. package/dist/formatError.d.ts +2 -2
  31. package/dist/formatError.d.ts.map +1 -1
  32. package/dist/formatError.js +31 -5
  33. package/dist/formatError.js.map +1 -1
  34. package/dist/index.d.ts +11 -9
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/layout/Layout.d.ts +28 -0
  37. package/dist/layout/Layout.d.ts.map +1 -1
  38. package/dist/layout/Layout.js +331 -89
  39. package/dist/layout/Layout.js.map +1 -1
  40. package/dist/locales/index.js.map +1 -1
  41. package/dist/panels/SaveControls.d.ts +27 -0
  42. package/dist/panels/SaveControls.d.ts.map +1 -0
  43. package/dist/panels/SaveControls.js +90 -0
  44. package/dist/panels/SaveControls.js.map +1 -0
  45. package/dist/panels/panels.d.ts +34 -0
  46. package/dist/panels/panels.d.ts.map +1 -0
  47. package/dist/panels/panels.js +61 -0
  48. package/dist/panels/panels.js.map +1 -0
  49. package/dist/paths.d.ts.map +1 -1
  50. package/dist/paths.js +2 -1
  51. package/dist/paths.js.map +1 -1
  52. package/dist/publication/Publication.d.ts +57 -0
  53. package/dist/publication/Publication.d.ts.map +1 -0
  54. package/dist/publication/Publication.js +427 -0
  55. package/dist/publication/Publication.js.map +1 -0
  56. package/dist/publication/index.d.ts +4 -0
  57. package/dist/publication/index.d.ts.map +1 -0
  58. package/dist/publication/index.js +1 -0
  59. package/dist/unsaved.js.map +1 -1
  60. package/package.json +16 -9
@@ -1 +1 @@
1
- {"version":3,"file":"FormView.js","names":["node","styles"],"sources":["../src/FormView.tsx"],"sourcesContent":["import { type ReactNode, useRef, useState } from 'react';\n\nimport {\n type Form,\n type SubmitResult,\n getLayoutFieldNames,\n getProblem,\n resolveFields,\n selectVisible,\n usePanneau,\n usePlugins,\n} from '@panneau/core';\nimport {\n type FieldEntry,\n FieldsProvider,\n type RelationSource,\n type UploadSource,\n builtInFields,\n} from '@panneau/fields';\nimport type { Field, LayoutNode } from '@panneau/protocol';\nimport { Alert, Button, usePanneauIntl, useToast } from '@panneau/ui';\n\nimport { ConflictDialog } from './ConflictDialog';\nimport { ErrorSummary } from './ErrorSummary';\nimport styles from './Form.module.css';\nimport { FormBinding } from './FormBinding';\nimport { FormContext, RevealContext, createRevealRegistry, useFormState } from './context';\nimport { cx } from './cx';\nimport { LayoutNodes } from './layout/Layout';\nimport { messages } from './messages';\nimport { useBeforeUnloadGuard } from './unsaved';\n\nexport interface FormViewProps {\n /** The form state, from `useForm()` or `createForm()` of `@panneau/core`. */\n form: Form;\n /** The fields of the form. */\n fields: readonly Field[];\n /** The layout tree. Fields that no node references are added at the end. */\n layout?: readonly LayoutNode[];\n /** Locales of localized fields. Defaults to the definition's, from `PanneauProvider`. */\n locales?: readonly string[];\n /** Where relation fields search. Defaults to the one of a parent `FieldsProvider`. */\n relationSource?: RelationSource | null;\n /**\n * Where fields that take files upload them directly to storage. Defaults to the one of a\n * parent `FieldsProvider`. Without one, values hold the files themselves.\n */\n uploadSource?: UploadSource | null;\n /** Field entries by type, over the built-in ones and those of the plugins. */\n components?: Readonly<Record<string, FieldEntry>>;\n /** Label of the submit button. Defaults to \"Save\". `null` hides the button. */\n submitLabel?: ReactNode;\n /** Other buttons, next to the submit button. */\n actions?: ReactNode;\n /** Called after a successful submit, with what `onSubmit` returned. */\n onSubmitted?: (result: unknown) => void;\n /**\n * Called by \"Load the current version\" in the conflict dialog when the backend didn't send the\n * current item: fetch it, and `form.reset()` with it.\n */\n onReload?: () => void;\n /** Asks for confirmation before the page is left with unsaved changes. Defaults to true. */\n guardUnsavedChanges?: boolean;\n /** Shows a toast after a successful submit. Defaults to true. */\n showSavedToast?: boolean;\n id?: string;\n 'aria-label'?: string;\n className?: string;\n layoutClassName?: string;\n sidebarClassName?: string;\n footerClassName?: string;\n summaryClassName?: string;\n}\n\nconst FOCUSABLE =\n 'input:not([type=\"hidden\"]):not([disabled]), textarea:not([disabled]), select:not([disabled]), button:not([disabled]), [tabindex]:not([tabindex=\"-1\"])';\n\n/** The element of the field at a path, or of the closest field that holds it. */\nfunction findFieldElement(root: HTMLElement, path: string): HTMLElement | null {\n let current = path;\n while (current !== '') {\n const element = root.querySelector<HTMLElement>(\n `[data-panneau-path=\"${CSS.escape(current)}\"]`,\n );\n if (element !== null) {\n return element;\n }\n current = current.includes('.') ? current.slice(0, current.lastIndexOf('.')) : '';\n }\n return null;\n}\n\n/**\n * Error paths in the order of their fields: the order of the layout for top-level fields, then\n * the order of the paths inside them (`blocks.2.body` before `blocks.10.body`).\n */\nfunction orderErrors(\n names: readonly string[],\n errors: Record<string, string[]>,\n): Record<string, string[]> {\n const rank = (path: string) => {\n const index = names.indexOf(path.split('.')[0] ?? '');\n return index === -1 ? names.length : index;\n };\n const compare = (a: string, b: string) =>\n rank(a) - rank(b) || a.localeCompare(b, undefined, { numeric: true });\n return Object.fromEntries(Object.entries(errors).sort(([a], [b]) => compare(a, b)));\n}\n\n/**\n * Renders a form: its fields in their layout, bound to the form state of `@panneau/core`, with\n * an error summary, a scroll to the first error, error counts on tabs and sections, a guard for\n * unsaved changes and the dialog of version conflicts. Saving is the job of the form's\n * `onSubmit`.\n */\nexport function FormView({\n form,\n fields,\n layout = [],\n locales,\n relationSource,\n uploadSource,\n components,\n submitLabel,\n actions,\n onSubmitted,\n onReload,\n guardUnsavedChanges = true,\n showSavedToast = true,\n id,\n 'aria-label': ariaLabel,\n className,\n layoutClassName,\n sidebarClassName,\n footerClassName,\n summaryClassName,\n}: FormViewProps) {\n const intl = usePanneauIntl();\n const toasts = useToast();\n const { definition } = usePanneau();\n const plugins = usePlugins();\n const state = useFormState(form);\n const [registry] = useState(createRevealRegistry);\n const [resolving, setResolving] = useState(false);\n const root = useRef<HTMLFormElement>(null);\n useBeforeUnloadGuard(guardUnsavedChanges && state.dirty);\n\n const resolved = resolveFields(fields, layout);\n const main = resolved.layout.filter((node) => node.type !== 'sidebar');\n const sidebar = resolved.layout.filter(\n (node) => node.type === 'sidebar' && selectVisible(state, node),\n );\n const order = [\n ...getLayoutFieldNames(main),\n ...getLayoutFieldNames(sidebar.flatMap((node) => node.children ?? [])),\n ];\n const entries: Record<string, FieldEntry> = {\n ...builtInFields,\n ...(Object.fromEntries(plugins.fields) as Record<string, FieldEntry>),\n ...components,\n };\n\n /** Opens the tab or section of a path, then scrolls to its field and focuses it. */\n const goTo = (path: string) => {\n registry.reveal(path);\n // Wait for the tab or section to open before scrolling.\n requestAnimationFrame(() => {\n const element = root.current !== null ? findFieldElement(root.current, path) : null;\n if (element === null) {\n return;\n }\n const reduced = window.matchMedia?.('(prefers-reduced-motion: reduce)').matches;\n element.scrollIntoView?.({ block: 'center', behavior: reduced ? 'auto' : 'smooth' });\n const target =\n element.querySelector<HTMLElement>('[aria-invalid=\"true\"]') ??\n element.querySelector<HTMLElement>(FOCUSABLE);\n target?.focus({ preventScroll: true });\n });\n };\n\n const handle = (result: SubmitResult | null) => {\n if (result === null) {\n return;\n }\n if (result.status === 'invalid') {\n const first = Object.keys(orderErrors(order, result.errors))[0];\n if (first !== undefined) {\n goTo(first);\n }\n } else if (result.status === 'submitted') {\n if (showSavedToast) {\n toasts.show({ title: intl.formatMessage(messages.saved), tone: 'success' });\n }\n onSubmitted?.(result.result);\n } else if (result.status === 'error') {\n toasts.show(\n {\n title: intl.formatMessage(messages.saveFailed),\n tone: 'danger',\n action: {\n label: intl.formatMessage(messages.retry),\n onAction: () => void form.submit().then(handle),\n },\n },\n { timeout: 8000 },\n );\n }\n };\n\n const resolve = async (choice: 'reload' | 'overwrite') => {\n if (choice === 'reload' && state.conflict?.current === null && onReload !== undefined) {\n onReload();\n return;\n }\n setResolving(true);\n try {\n handle(await form.resolveConflict(choice));\n } finally {\n setResolving(false);\n }\n };\n\n const problem = state.status === 'error' ? getProblem(state.error) : null;\n const errorDetail =\n problem?.detail ??\n (problem === null && state.error instanceof Error ? state.error.message : undefined);\n const showSummary = state.status === 'invalid' && state.submitCount > 0;\n\n return (\n <FormContext value={form}>\n <RevealContext value={registry}>\n <FieldsProvider\n components={entries}\n locales={locales ?? definition?.locales ?? []}\n {...(relationSource !== undefined ? { relationSource } : {})}\n {...(uploadSource !== undefined ? { uploadSource } : {})}\n binding={FormBinding}\n >\n <form\n ref={root}\n id={id}\n aria-label={ariaLabel}\n noValidate\n className={cx(styles.form, className)}\n onSubmit={(event) => {\n event.preventDefault();\n void form.submit().then(handle);\n }}\n >\n {showSummary ? (\n <ErrorSummary\n errors={orderErrors(order, state.errors)}\n fields={resolved.fields}\n onSelect={goTo}\n {...(summaryClassName !== undefined\n ? { className: summaryClassName }\n : {})}\n />\n ) : null}\n {state.status === 'error' ? (\n <Alert\n tone=\"danger\"\n role=\"alert\"\n title={intl.formatMessage(messages.saveFailed)}\n actions={\n <Button size=\"sm\" type=\"submit\">\n {intl.formatMessage(messages.retry)}\n </Button>\n }\n >\n {errorDetail}\n </Alert>\n ) : null}\n <div\n className={cx(\n styles.layout,\n sidebar.length > 0 && styles.withSidebar,\n layoutClassName,\n )}\n >\n <div className={styles.stack}>\n <LayoutNodes nodes={main} fields={resolved.fieldsByName} />\n </div>\n {sidebar.length > 0 ? (\n <aside className={cx(styles.sidebar, sidebarClassName)}>\n {sidebar.map((node, index) => (\n <div key={index} className={styles.stack}>\n <LayoutNodes\n nodes={node.children ?? []}\n fields={resolved.fieldsByName}\n />\n </div>\n ))}\n </aside>\n ) : null}\n </div>\n {submitLabel !== null || actions !== undefined ? (\n <div className={cx(styles.footer, footerClassName)}>\n {state.dirty ? (\n <span className={styles.dirty} role=\"status\">\n {intl.formatMessage(messages.unsaved)}\n </span>\n ) : null}\n {actions}\n {submitLabel !== null ? (\n <Button\n type=\"submit\"\n variant=\"primary\"\n isPending={state.status === 'submitting'}\n >\n {submitLabel ?? intl.formatMessage(messages.save)}\n </Button>\n ) : null}\n </div>\n ) : null}\n </form>\n <ConflictDialog\n isOpen={state.status === 'conflict' || resolving}\n fields={resolved.fields}\n values={state.values}\n current={state.conflict?.current ?? null}\n isPending={resolving}\n onReload={() => void resolve('reload')}\n onOverwrite={() => void resolve('overwrite')}\n />\n </FieldsProvider>\n </RevealContext>\n </FormContext>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AA0EA,IAAM,YACF;;AAGJ,SAAS,iBAAiB,MAAmB,MAAkC;CAC3E,IAAI,UAAU;CACd,OAAO,YAAY,IAAI;EACnB,MAAM,UAAU,KAAK,cACjB,uBAAuB,IAAI,OAAO,OAAO,EAAC,GAC9C;EACA,IAAI,YAAY,MACZ,OAAO;EAEX,UAAU,QAAQ,SAAS,GAAG,IAAI,QAAQ,MAAM,GAAG,QAAQ,YAAY,GAAG,CAAC,IAAI;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A,CAOI,oBAAC,OAAD;QAAK,WAAWA,oBAAO;QACnB,UAAA,oBAAC,aAAD;SAAa,OAAO;SAAM,QAAQ,SAAS;QAAa,CAAA;OACvD,CAAA,GACJ,QAAQ,SAAS,IACd,oBAAC,SAAD;QAAO,WAAW,GAAGA,oBAAO,SAAS,gBAAgB;QAChD,UAAA,QAAQ,KAAKD,QAAM,UAChB,oBAAC,OAAD;SAAiB,WAAWC,oBAAO;SAC/B,UAAA,oBAAC,aAAD;UACI,OAAOD,OAAK,YAAY,CAAA;UACxB,QAAQ,SAAS;SAAa,CAAA;QAEjC,GALK,KAKL,CACR;OACE,CAAA,IACP,IACH;;MACJ,gBAAgB,QAAQ,YAAY,KAAA,IACjC,qBAAC,OAAD;OAAK,WAAW,GAAGC,oBAAO,QAAQ,eAAe;OAAjD,UAAA;QACK,MAAM,QACH,oBAAC,QAAD;SAAM,WAAWA,oBAAO;SAAO,MAAK;SAC/B,UAAA,KAAK,cAAc,SAAS,OAAO;QAClC,CAAA,IACN;QACH;QACA,gBAAgB,OACb,oBAAC,QAAD;SACI,MAAK;SACL,SAAQ;SACR,WAAW,MAAM,WAAW;SAE3B,UAAA,eAAe,KAAK,cAAc,SAAS,IAAI;QAC5C,CAAA,IACR;OACH;MACL,CAAA,IAAA;KACF;IACN,CAAA,GAAA,oBAAC,gBAAD;KACI,QAAQ,MAAM,WAAW,cAAc;KACvC,QAAQ,SAAS;KACjB,QAAQ,MAAM;KACd,SAAS,MAAM,UAAU,WAAW;KACpC,WAAW;KACX,gBAAgB,KAAK,QAAQ,QAAQ;KACrC,mBAAmB,KAAK,QAAQ,WAAW;IAAE,CAAA,CAErC;;EACL,CAAA;CACN,CAAA;AAErB"}
1
+ {"version":3,"file":"FormView.js","names":["KeyboardEvent","ReactNode","useRef","useState","Form","SubmitResult","getLayoutFieldNames","getProblem","resolveFields","selectVisible","useLeaveGuard","usePanneau","usePlugins","FieldCheckSource","FieldEntry","FieldsProvider","RelationSource","UploadSource","builtInFields","Field","LayoutNode","Alert","Aside","AsideLayout","Button","isApplePlatform","usePanneauIntl","useToast","useToastOffset","ConflictDialog","ErrorSummary","styles","FormBinding","FormSkeleton","ErrorSectionsContext","FormContext","RevealContext","createRevealRegistry","useFormState","cx","FieldFlow","LayoutNodes","SidebarNode","messages","SaveContext","SaveControls","SaveState","SummaryContext","FormPanelComponent","PanelsContext","builtInPanels","useBeforeUnloadGuard","useLeaveConfirmation","FormViewProps","form","fields","layout","locales","relationSource","uploadSource","checkSource","components","Readonly","Record","panels","submitLabel","actions","onSubmitted","result","onReload","guardUnsavedChanges","showSavedToast","saved","isLoading","id","className","layoutClassName","sidebarClassName","sidebarStorageKey","footerClassName","summaryClassName","FOCUSABLE","findFieldElement","root","HTMLElement","path","current","element","querySelector","CSS","escape","includes","slice","lastIndexOf","orderErrors","names","errors","rank","index","indexOf","split","length","localeRank","compare","a","b","localeCompare","undefined","numeric","Object","fromEntries","entries","sort","isUnplacedField","node","placed","ReadonlySet","type","name","has","isSaveShortcut","event","apple","key","metaKey","ctrlKey","altKey","shiftKey","repeat","nativeEvent","isComposing","FormView","t0","$","_c","t1","t2","t3","t4","t5","ariaLabel","intl","toasts","definition","plugins","state","registry","errorSections","resolving","setResolving","footer","hasFooter","savedShown","setSavedShown","dirty","guarded","leave","confirmLeave","formLocales","resolved","mode","main","filter","_temp","Set","flow","laidOut","t6","node_0","sidebar","order","flatMap","_temp2","t7","Symbol","for","t8","ReadonlyMap","t9","t10","Map","panelEntries","hasPanel","some","node_2","panel","t11","t12","t13","goTo","reveal","show","frames","closest","requestAnimationFrame","reduced","window","matchMedia","matches","scrollIntoView","block","behavior","target","focus","preventScroll","handle","status","keys","forEach","path_0","first","title","formatMessage","tone","resolve","choice","conflict","resolveConflict","then","finally","t14","Node","currentTarget","contains","preventDefault","requestSubmit","onKeyDown","t15","error","problem","errorDetail","detail","Error","message","showSummary","submitCount","orderedErrors","t16","t17","t18","save","t19","isSubmitting","_temp3","fieldsByName","t20","t21","t22","t23","t24","saveFailed","retry","t25","t26","t27","t28","t29","values","onSelect","event_0","submit","summary","besideAsideHidden","stack","map","node_4","dialog","node_3","node_1","children","_c","createRevealRegistry","styles"],"sources":["../src/FormView.tsx"],"sourcesContent":["import { type KeyboardEvent, type ReactNode, useRef, useState } from 'react';\n\nimport {\n type Form,\n type SubmitResult,\n getLayoutFieldNames,\n getProblem,\n resolveFields,\n selectVisible,\n useLeaveGuard,\n usePanneau,\n usePlugins,\n} from '@panneau/core';\nimport {\n type FieldCheckSource,\n type FieldEntry,\n FieldsProvider,\n type RelationSource,\n type UploadSource,\n builtInFields,\n} from '@panneau/fields';\nimport type { Field, LayoutNode } from '@panneau/protocol';\nimport {\n Alert,\n Aside,\n AsideLayout,\n Button,\n isApplePlatform,\n usePanneauIntl,\n useToast,\n useToastOffset,\n} from '@panneau/ui';\n\nimport { ConflictDialog } from './ConflictDialog';\nimport { ErrorSummary } from './ErrorSummary';\nimport styles from './Form.module.css';\nimport { FormBinding } from './FormBinding';\nimport { FormSkeleton } from './FormSkeleton';\nimport {\n ErrorSectionsContext,\n FormContext,\n RevealContext,\n createRevealRegistry,\n useFormState,\n} from './context';\nimport { cx } from './cx';\nimport { FieldFlow, LayoutNodes, SidebarNode } from './layout/Layout';\nimport { messages } from './messages';\nimport { SaveContext, SaveControls, type SaveState, SummaryContext } from './panels/SaveControls';\nimport { type FormPanelComponent, PanelsContext, builtInPanels } from './panels/panels';\nimport { useBeforeUnloadGuard, useLeaveConfirmation } from './unsaved';\n\nexport interface FormViewProps {\n /** The form state, from `useForm()` or `createForm()` of `@panneau/core`. */\n form: Form;\n /** The fields of the form. */\n fields: readonly Field[];\n /** The layout tree. Fields that no node references are added at the end. */\n layout?: readonly LayoutNode[];\n /** Locales of localized fields. Defaults to the definition's, from `PanneauProvider`. */\n locales?: readonly string[];\n /** Where relation fields search. Defaults to the one of a parent `FieldsProvider`. */\n relationSource?: RelationSource | null;\n /**\n * Where fields that take files upload them directly to storage. Defaults to the one of a\n * parent `FieldsProvider`. Without one, values hold the files themselves.\n */\n uploadSource?: UploadSource | null;\n /**\n * Where fields with `check` check their value, such as a slug's availability:\n * `createFieldCheckSource(adapter, resource, id)`. Defaults to the one of a parent\n * `FieldsProvider`.\n */\n checkSource?: FieldCheckSource | null;\n /** Field entries by type, over the built-in ones and those of the plugins. */\n components?: Readonly<Record<string, FieldEntry>>;\n /**\n * Panels of the sidebar, by name, over the built-in ones and those of plugins: the app gives\n * its own (decision 0075).\n */\n panels?: Readonly<Record<string, FormPanelComponent>>;\n /** Label of the submit button. Defaults to \"Save\". `null` hides the button. */\n submitLabel?: ReactNode;\n /** Other buttons, next to the submit button. */\n actions?: ReactNode;\n /** Called after a successful submit, with what `onSubmit` returned. */\n onSubmitted?: (result: unknown) => void;\n /**\n * Called by \"Load the current version\" in the conflict dialog when the backend didn't send the\n * current item: fetch it, and `form.reset()` with it.\n */\n onReload?: () => void;\n /**\n * Asks for confirmation before the page is left with unsaved changes: closed or reloaded, or,\n * under a `LeaveGuardsProvider`, left through the app's router. Defaults to true.\n */\n guardUnsavedChanges?: boolean;\n /**\n * Shows \"Saved\" in a toast after a successful submit, when the form has no footer to say it\n * (no submit button and no `actions`). Defaults to true. A form with a footer says \"Saved\" in\n * it, next to its button, where \"Unsaved changes\" was: the page already shows it (decision\n * 0062).\n */\n showSavedToast?: boolean;\n /**\n * The item was saved just before the form started over from it (a new `key` after a save):\n * the footer says \"Saved\" until the values change.\n */\n saved?: boolean;\n /**\n * The values load, such as the item to edit: the form draws a skeleton of its layout and\n * fields instead (decision 0034).\n */\n isLoading?: boolean;\n id?: string;\n 'aria-label'?: string;\n className?: string;\n layoutClassName?: string;\n sidebarClassName?: string;\n /**\n * The key under which the browser remembers the collapsed panels of the sidebar\n * (`panneau:<key>-panel-<label>`), such as `form-articles`. Without one, they last as long as\n * the form.\n */\n sidebarStorageKey?: string;\n footerClassName?: string;\n summaryClassName?: string;\n}\n\nconst FOCUSABLE =\n 'input:not([type=\"hidden\"]):not([disabled]), textarea:not([disabled]), select:not([disabled]), button:not([disabled]), [tabindex]:not([tabindex=\"-1\"])';\n\n/** The element of the field at a path, or of the closest field that holds it. */\nfunction findFieldElement(root: HTMLElement, path: string): HTMLElement | null {\n let current = path;\n while (current !== '') {\n const element = root.querySelector<HTMLElement>(\n `[data-panneau-path=\"${CSS.escape(current)}\"]`,\n );\n if (element !== null) {\n return element;\n }\n current = current.includes('.') ? current.slice(0, current.lastIndexOf('.')) : '';\n }\n return null;\n}\n\n/**\n * Error paths in the order of their fields: the order of the layout for top-level fields, then\n * the order of the paths inside them: locales in their order (`title.fr` before `title.en`), and\n * items by number (`blocks.2.body` before `blocks.10.body`).\n */\nfunction orderErrors(\n names: readonly string[],\n errors: Record<string, string[]>,\n locales: readonly string[] = [],\n): Record<string, string[]> {\n const rank = (path: string) => {\n const index = names.indexOf(path.split('.')[0] ?? '');\n return index === -1 ? names.length : index;\n };\n const localeRank = (path: string) => {\n const index = locales.indexOf(path.split('.')[1] ?? '');\n return index === -1 ? locales.length : index;\n };\n const compare = (a: string, b: string) =>\n rank(a) - rank(b) ||\n localeRank(a) - localeRank(b) ||\n a.localeCompare(b, undefined, { numeric: true });\n return Object.fromEntries(Object.entries(errors).sort(([a], [b]) => compare(a, b)));\n}\n\n/** Whether a node is a field that the layout as given doesn't place. */\nfunction isUnplacedField(node: LayoutNode | undefined, placed: ReadonlySet<string>): boolean {\n return node?.type === 'field' && node.name !== undefined && !placed.has(node.name);\n}\n\n/** Whether a key press saves: ⌘ Enter on Apple platforms, Ctrl Enter elsewhere. */\nfunction isSaveShortcut(event: KeyboardEvent, apple: boolean): boolean {\n return (\n event.key === 'Enter' &&\n (apple ? event.metaKey : event.ctrlKey) &&\n !event.altKey &&\n !event.shiftKey &&\n !event.repeat &&\n !event.nativeEvent.isComposing\n );\n}\n\n/**\n * Renders a form: its fields in their layout, bound to the form state of `@panneau/core`, with\n * an error summary, a scroll to the first error, error counts on tabs and sections, a guard for\n * unsaved changes and the dialog of version conflicts. Saving is the job of the form's\n * `onSubmit`.\n *\n * ⌘ Enter (Ctrl Enter elsewhere) saves from any of its fields. After a failed save, every\n * collapsed section that holds an error opens, and the first error is focused.\n */\nexport function FormView({\n form,\n fields,\n layout = [],\n locales,\n relationSource,\n uploadSource,\n checkSource,\n components,\n panels,\n submitLabel,\n actions,\n onSubmitted,\n onReload,\n guardUnsavedChanges = true,\n showSavedToast = true,\n saved = false,\n isLoading = false,\n id,\n 'aria-label': ariaLabel,\n className,\n layoutClassName,\n sidebarClassName,\n sidebarStorageKey,\n footerClassName,\n summaryClassName,\n}: FormViewProps) {\n const intl = usePanneauIntl();\n const toasts = useToast();\n const { definition } = usePanneau();\n const plugins = usePlugins();\n const state = useFormState(form);\n const [registry] = useState(createRevealRegistry);\n const [errorSections] = useState(createRevealRegistry);\n const [resolving, setResolving] = useState(false);\n const root = useRef<HTMLFormElement>(null);\n const footer = useRef<HTMLDivElement>(null);\n const hasFooter = submitLabel !== null || actions !== undefined;\n // Toasts rise above the footer, which sticks to the bottom of the page.\n useToastOffset(footer, hasFooter && !isLoading);\n // \"Saved\" in the footer, from the last submit or from before the form started over, until the\n // values change.\n const [savedShown, setSavedShown] = useState(saved);\n if (savedShown && state.dirty) {\n setSavedShown(false);\n }\n const guarded = guardUnsavedChanges && state.dirty;\n useBeforeUnloadGuard(guarded);\n // Leaving through the app's router asks first, in a dialog\n const leave = useLeaveConfirmation(guarded);\n useLeaveGuard(guarded, leave.confirmLeave);\n\n // In the mode of the form, as its rules are checked: the required mark of a password\n // required on create shows on create only\n const formLocales = locales ?? definition?.locales ?? [];\n const resolved = resolveFields(fields, layout, { mode: form.mode });\n const main = resolved.layout.filter((node) => node.type !== 'sidebar');\n // The fields that the layout doesn't place come last: they flow in columns\n const placed = new Set(getLayoutFieldNames(layout));\n let split = main.length;\n while (split > 0 && isUnplacedField(main[split - 1], placed)) {\n split -= 1;\n }\n const flow = main.slice(split);\n const laidOut = main.slice(0, split);\n const sidebar = resolved.layout.filter(\n (node) => node.type === 'sidebar' && selectVisible(state, node),\n );\n const order = [\n ...getLayoutFieldNames(main),\n ...getLayoutFieldNames(sidebar.flatMap((node) => node.children ?? [])),\n ];\n const panelEntries = new Map<string, FormPanelComponent>([\n ...Object.entries(builtInPanels),\n ...(plugins.panels as ReadonlyMap<string, FormPanelComponent>),\n ...Object.entries(panels ?? {}),\n ]);\n // Beside the form, the `save` and `errors` panels take the place of the footer and of the\n // summary at the top (decision 0075)\n const hasPanel = (name: string) => sidebar.some((node) => node.panel === name);\n const entries: Record<string, FieldEntry> = {\n ...builtInFields,\n ...(Object.fromEntries(plugins.fields) as Record<string, FieldEntry>),\n ...components,\n };\n\n /** Opens the tab, section or locale of a path, then scrolls to its field and focuses it. */\n const goTo = (path: string) => {\n registry.reveal(path);\n // Wait for the tab, section or locale to open before scrolling: a few frames at most.\n const show = (frames: number) => {\n const element = root.current !== null ? findFieldElement(root.current, path) : null;\n if (element === null) {\n return;\n }\n if (element.closest('[hidden]') !== null && frames > 0) {\n requestAnimationFrame(() => show(frames - 1));\n return;\n }\n const reduced = window.matchMedia?.('(prefers-reduced-motion: reduce)').matches;\n element.scrollIntoView?.({ block: 'center', behavior: reduced ? 'auto' : 'smooth' });\n const target =\n element.querySelector<HTMLElement>('[aria-invalid=\"true\"]') ??\n element.querySelector<HTMLElement>(FOCUSABLE);\n target?.focus({ preventScroll: true });\n };\n requestAnimationFrame(() => show(3));\n };\n\n const handle = (result: SubmitResult | null) => {\n if (result === null) {\n return;\n }\n if (result.status === 'invalid') {\n // Every collapsed section with an error opens: what is left to fix shows while\n // scrolling down\n Object.keys(result.errors).forEach((path) => errorSections.reveal(path));\n const first = Object.keys(orderErrors(order, result.errors, formLocales))[0];\n if (first !== undefined) {\n goTo(first);\n }\n } else if (result.status === 'submitted') {\n setSavedShown(true);\n if (showSavedToast && !hasFooter) {\n toasts.show(\n { title: intl.formatMessage(messages.saved), tone: 'success' },\n { key: 'panneau-form-saved' },\n );\n }\n onSubmitted?.(result.result);\n }\n // An error shows in the page: its alert, and the footer next to the button.\n };\n\n const resolve = async (choice: 'reload' | 'overwrite') => {\n if (choice === 'reload' && state.conflict?.current === null && onReload !== undefined) {\n onReload();\n return;\n }\n setResolving(true);\n await form\n .resolveConflict(choice)\n .then(handle)\n .finally(() => setResolving(false));\n };\n\n const apple = isApplePlatform();\n const onKeyDown = (event: KeyboardEvent<HTMLFormElement>) => {\n // Not `defaultPrevented`: rich text editors prevent the default of every Enter. Keys of\n // what a field opens in a portal, such as a dialog, reach the form through React: they\n // are that dialog's own.\n if (\n !isSaveShortcut(event, apple) ||\n !(event.target instanceof Node) ||\n !event.currentTarget.contains(event.target)\n ) {\n return;\n }\n event.preventDefault();\n event.currentTarget.requestSubmit();\n };\n\n const problem = state.status === 'error' ? getProblem(state.error) : null;\n const errorDetail =\n problem?.detail ??\n (problem === null && state.error instanceof Error ? state.error.message : undefined);\n const showSummary = state.status === 'invalid' && state.submitCount > 0;\n const orderedErrors = showSummary ? orderErrors(order, state.errors, formLocales) : {};\n const save: SaveState = {\n status:\n state.status === 'error'\n ? 'error'\n : state.dirty\n ? 'unsaved'\n : savedShown && state.status !== 'submitting'\n ? 'saved'\n : null,\n isSubmitting: state.status === 'submitting',\n actions,\n submitLabel: submitLabel === undefined ? intl.formatMessage(messages.save) : submitLabel,\n };\n\n if (isLoading) {\n return (\n <FormSkeleton\n main={laidOut}\n flow={flow}\n sidebar={resolved.layout.filter((node) => node.type === 'sidebar')}\n fields={resolved.fieldsByName}\n footer={hasFooter}\n className={className}\n layoutClassName={layoutClassName}\n sidebarClassName={sidebarClassName}\n footerClassName={footerClassName}\n />\n );\n }\n\n return (\n <FormContext value={form}>\n <PanelsContext value={panelEntries}>\n <SaveContext value={save}>\n <SummaryContext\n value={{ errors: orderedErrors, fields: resolved.fields, onSelect: goTo }}\n >\n <RevealContext value={registry}>\n <ErrorSectionsContext value={errorSections}>\n <FieldsProvider\n components={entries}\n locales={formLocales}\n {...(relationSource !== undefined ? { relationSource } : {})}\n {...(uploadSource !== undefined ? { uploadSource } : {})}\n {...(checkSource !== undefined ? { checkSource } : {})}\n binding={FormBinding}\n >\n <form\n ref={root}\n id={id}\n aria-label={ariaLabel}\n noValidate\n className={cx(styles.form, className)}\n onSubmit={(event) => {\n event.preventDefault();\n void form.submit().then(handle);\n }}\n onKeyDown={onKeyDown}\n >\n {showSummary ? (\n <ErrorSummary\n errors={orderedErrors}\n fields={resolved.fields}\n onSelect={goTo}\n className={cx(\n summaryClassName ?? styles.summary,\n hasPanel('errors') && styles.besideAsideHidden,\n )}\n />\n ) : null}\n {state.status === 'error' ? (\n <Alert\n tone=\"danger\"\n role=\"alert\"\n title={intl.formatMessage(messages.saveFailed)}\n actions={\n <Button size=\"sm\" type=\"submit\">\n {intl.formatMessage(messages.retry)}\n </Button>\n }\n >\n {errorDetail}\n </Alert>\n ) : null}\n <AsideLayout\n className={layoutClassName}\n mainClassName={styles.stack}\n aside={\n sidebar.length > 0 ? (\n <Aside\n label={intl.formatMessage(messages.sidebar)}\n className={sidebarClassName}\n >\n {sidebar.map((node, index) => (\n <SidebarNode\n key={index}\n node={node}\n fields={resolved.fieldsByName}\n storageKey={sidebarStorageKey}\n />\n ))}\n </Aside>\n ) : null\n }\n >\n <LayoutNodes\n nodes={laidOut}\n fields={resolved.fieldsByName}\n />\n {flow.length > 0 ? (\n <FieldFlow\n nodes={flow}\n fields={resolved.fieldsByName}\n />\n ) : null}\n </AsideLayout>\n {hasFooter ? (\n <div\n ref={footer}\n className={cx(\n styles.footer,\n hasPanel('save') && styles.besideAsideHidden,\n footerClassName,\n )}\n >\n <SaveControls {...save} />\n </div>\n ) : null}\n </form>\n <ConflictDialog\n isOpen={state.status === 'conflict' || resolving}\n fields={resolved.fields}\n values={state.values}\n current={state.conflict?.current ?? null}\n isPending={resolving}\n onReload={() => void resolve('reload')}\n onOverwrite={() => void resolve('overwrite')}\n />\n {leave.dialog}\n </FieldsProvider>\n </ErrorSectionsContext>\n </RevealContext>\n </Summary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b;WAcD,qBAAC,aAAD;YACe7K,WAAAA;YACI,eAAA7C,oBAAMwO;YAEjB,OAAA9F,QAAOpE,SAAU,IACb,oBAAC,OAAD;aACW,OAAAwC,KAAIuE,cAAezK,SAAQ8H,OAAQ;aAC/B5F,WAAAA;aAEV4F,UAAAA,QAAO+F,KAAKC,QAAAvK,UACT,oBAAC,aAAD;cAEUgB,MAAAA;cACE,QAAA6C,SAAQqF;cACJtK,YAAAA;aAAiB,GAHxBoB,KAGwB,CAEpC;YAXC,CAAA,IADV;YAJR,UAAA,CAqBI,oBAAC,aAAD;aACWoE,OAAAA;aACC,QAAAP,SAAQqF;YAAa,CAAA,GAEhC/E,KAAIhE,SAAU,IACX,oBAAC,WAAD;aACWgE,OAAAA;aACC,QAAAN,SAAQqF;YAAa,CAAA,IAHpC,IAzBO;;WAgCX7F,YACG,oBAAA,OAAA;YACSD,KAAAA;YACM,WAAA/G,GACPR,oBAAMuH,QACNgC,SAAS,MAAkC,KAAvBvJ,oBAAMuO,mBAC1BvL,eACJ;YAEA,UAAA,oBAAC,cAAD,EAAa,GAAKiK,KAAI,CAAA;WACpB,CAAA,IAVT;UAYE;;SACPgB;SASCpG,MAAK8G;QAnGK;;MADE,CAAA;KADX,CAAA;IAHH,CAAA;GADP,CAAA;EADF,CAAA;CADN,CAAA;AAkHE;AAzTf,SAAAvB,OAAAwB,QAAA;CAAA,OA2LmDzJ,OAAIG,SAAU;AAAS;AA3L1E,SAAAuD,OAAAgG,QAAA;CAAA,OAsEkD1J,OAAI2J,YAAJ,CAAA;AAAmB;AAtErE,SAAA1G,MAAAjD,MAAA;CAAA,OAwD2CA,KAAIG,SAAU;AAAS"}
package/dist/context.d.ts CHANGED
@@ -1,15 +1,15 @@
1
1
  import type { Form, FormState } from '@panneau/core';
2
+ import { type RevealRegistry } from '@panneau/fields';
2
3
  export declare const FormContext: import("react").Context<Form | null>;
3
4
  /** The form of the closest `FormView`. */
4
5
  export declare function useFormContext(): Form;
5
6
  /** The state of a form, updated on every change. */
6
7
  export declare function useFormState(form: Form): FormState;
7
- /** Opens the containers (tabs, sections) that hold a path, so that its field can be reached. */
8
- export type Revealer = (path: string) => void;
9
- export interface RevealRegistry {
10
- add(revealer: Revealer): () => void;
11
- reveal(path: string): void;
12
- }
13
- export declare function createRevealRegistry(): RevealRegistry;
14
- export declare const RevealContext: import("react").Context<RevealRegistry>;
8
+ export { RevealContext, createRevealRegistry } from '@panneau/fields';
9
+ /**
10
+ * Where a form asks its sections to open on the paths of its errors after a failed save: every
11
+ * collapsed section that holds one opens. Unlike `RevealContext`, tabs don't follow: one only
12
+ * can show, and each keeps its error count.
13
+ */
14
+ export declare const ErrorSectionsContext: import("react").Context<RevealRegistry>;
15
15
  //# sourceMappingURL=context.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAErD,eAAO,MAAM,WAAW,sCAAmC,CAAC;AAE5D,0CAA0C;AAC1C,wBAAgB,cAAc,IAAI,IAAI,CAMrC;AAED,oDAAoD;AACpD,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,CAElD;AAED,gGAAgG;AAChG,MAAM,MAAM,QAAQ,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;AAE9C,MAAM,WAAW,cAAc;IAC3B,GAAG,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,IAAI,CAAC;IACpC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B;AAED,wBAAgB,oBAAoB,IAAI,cAAc,CAarD;AAED,eAAO,MAAM,aAAa,yCAAwD,CAAC"}
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,KAAK,cAAc,EAAwB,MAAM,iBAAiB,CAAC;AAE5E,eAAO,MAAM,WAAW,sCAAmC,CAAC;AAE5D,0CAA0C;AAC1C,wBAAgB,cAAc,IAAI,IAAI,CAMrC;AAED,oDAAoD;AACpD,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,CAElD;AAID,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAEtE;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,yCAAwD,CAAC"}
package/dist/context.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { createContext, use, useSyncExternalStore } from "react";
2
+ import { RevealContext, createRevealRegistry, createRevealRegistry as createRevealRegistry$1 } from "@panneau/fields";
2
3
  //#region src/context.ts
3
4
  var FormContext = createContext(null);
4
5
  /** The form of the closest `FormView`. */
@@ -11,22 +12,13 @@ function useFormContext() {
11
12
  function useFormState(form) {
12
13
  return useSyncExternalStore(form.subscribe, form.getState, form.getState);
13
14
  }
14
- function createRevealRegistry() {
15
- const revealers = /* @__PURE__ */ new Set();
16
- return {
17
- add(revealer) {
18
- revealers.add(revealer);
19
- return () => {
20
- revealers.delete(revealer);
21
- };
22
- },
23
- reveal(path) {
24
- revealers.forEach((revealer) => revealer(path));
25
- }
26
- };
27
- }
28
- var RevealContext = createContext(createRevealRegistry());
15
+ /**
16
+ * Where a form asks its sections to open on the paths of its errors after a failed save: every
17
+ * collapsed section that holds one opens. Unlike `RevealContext`, tabs don't follow: one only
18
+ * can show, and each keeps its error count.
19
+ */
20
+ var ErrorSectionsContext = createContext(createRevealRegistry());
29
21
  //#endregion
30
- export { FormContext, RevealContext, createRevealRegistry, useFormContext, useFormState };
22
+ export { ErrorSectionsContext, FormContext, RevealContext, createRevealRegistry$1 as createRevealRegistry, useFormContext, useFormState };
31
23
 
32
24
  //# sourceMappingURL=context.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","names":[],"sources":["../src/context.ts"],"sourcesContent":["import { createContext, use, useSyncExternalStore } from 'react';\n\nimport type { Form, FormState } from '@panneau/core';\n\nexport const FormContext = createContext<Form | null>(null);\n\n/** The form of the closest `FormView`. */\nexport function useFormContext(): Form {\n const form = use(FormContext);\n if (form === null) {\n throw new Error('This component must be rendered inside a <Form> or a <FormView>.');\n }\n return form;\n}\n\n/** The state of a form, updated on every change. */\nexport function useFormState(form: Form): FormState {\n return useSyncExternalStore(form.subscribe, form.getState, form.getState);\n}\n\n/** Opens the containers (tabs, sections) that hold a path, so that its field can be reached. */\nexport type Revealer = (path: string) => void;\n\nexport interface RevealRegistry {\n add(revealer: Revealer): () => void;\n reveal(path: string): void;\n}\n\nexport function createRevealRegistry(): RevealRegistry {\n const revealers = new Set<Revealer>();\n return {\n add(revealer) {\n revealers.add(revealer);\n return () => {\n revealers.delete(revealer);\n };\n },\n reveal(path) {\n revealers.forEach((revealer) => revealer(path));\n },\n };\n}\n\nexport const RevealContext = createContext<RevealRegistry>(createRevealRegistry());\n"],"mappings":";;AAIA,IAAa,cAAc,cAA2B,IAAI;;AAG1D,SAAgB,iBAAuB;CACnC,MAAM,OAAO,IAAI,WAAW;CAC5B,IAAI,SAAS,MACT,MAAM,IAAI,MAAM,kEAAkE;CAEtF,OAAO;AACX;;AAGA,SAAO,aAAA,MAAA;CAAA,OACI,qBAAqB,KAAI,WAAY,KAAI,UAAW,KAAI,QAAS;AAAC;AAW7E,SAAgB,uBAAuC;CACnD,MAAM,4BAAY,IAAI,IAAc;CACpC,OAAO;EACH,IAAI,UAAU;GACV,UAAU,IAAI,QAAQ;GACtB,aAAa;IACT,UAAU,OAAO,QAAQ;GAC7B;EACJ;EACA,OAAO,MAAM;GACT,UAAU,SAAS,aAAa,SAAS,IAAI,CAAC;EAClD;CACJ;AACJ;AAEA,IAAa,gBAAgB,cAA8B,qBAAqB,CAAC"}
1
+ {"version":3,"file":"context.js","names":["createContext","use","useSyncExternalStore","Form","FormState","RevealRegistry","createRevealRegistry","FormContext","useFormContext","form","Error","useFormState","subscribe","getState","RevealContext","ErrorSectionsContext"],"sources":["../src/context.ts"],"sourcesContent":["import { createContext, use, useSyncExternalStore } from 'react';\n\nimport type { Form, FormState } from '@panneau/core';\nimport { type RevealRegistry, createRevealRegistry } from '@panneau/fields';\n\nexport const FormContext = createContext<Form | null>(null);\n\n/** The form of the closest `FormView`. */\nexport function useFormContext(): Form {\n const form = use(FormContext);\n if (form === null) {\n throw new Error('This component must be rendered inside a <Form> or a <FormView>.');\n }\n return form;\n}\n\n/** The state of a form, updated on every change. */\nexport function useFormState(form: Form): FormState {\n return useSyncExternalStore(form.subscribe, form.getState, form.getState);\n}\n\n// The reveal registry is in `@panneau/fields`, for the fields that hide some of their own (the\n// locales of a localized field).\nexport { RevealContext, createRevealRegistry } from '@panneau/fields';\n\n/**\n * Where a form asks its sections to open on the paths of its errors after a failed save: every\n * collapsed section that holds one opens. Unlike `RevealContext`, tabs don't follow: one only\n * can show, and each keeps its error count.\n */\nexport const ErrorSectionsContext = createContext<RevealRegistry>(createRevealRegistry());\n"],"mappings":";;;AAKA,IAAaO,cAAcP,cAA2B,IAAI;;AAG1D,SAAgBQ,iBAAuB;CACnC,MAAMC,OAAOR,IAAIM,WAAW;CAC5B,IAAIE,SAAS,MACT,MAAM,IAAIC,MAAM,kEAAkE;CAEtF,OAAOD;AACX;;AAGA,SAAOE,aAAAF,MAAA;CAAA,OACIP,qBAAqBO,KAAIG,WAAYH,KAAII,UAAWJ,KAAII,QAAS;AAAC;;;;;;AAY7E,IAAaE,uBAAuBf,cAA8BM,qBAAqB,CAAC"}
package/dist/cx.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cx.js","names":[],"sources":["../src/cx.ts"],"sourcesContent":["/** Joins class names, skipping empty ones. */\nexport function cx(...classNames: (string | false | null | undefined)[]): string {\n return classNames.filter(Boolean).join(' ');\n}\n"],"mappings":";;AACA,SAAgB,GAAG,GAAG,YAA2D;CAC7E,OAAO,WAAW,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG;AAC9C"}
1
+ {"version":3,"file":"cx.js","names":["cx","classNames","filter","Boolean","join"],"sources":["../src/cx.ts"],"sourcesContent":["/** Joins class names, skipping empty ones. */\nexport function cx(...classNames: (string | false | null | undefined)[]): string {\n return classNames.filter(Boolean).join(' ');\n}\n"],"mappings":";;AACA,SAAgBA,GAAG,GAAGC,YAA2D;CAC7E,OAAOA,WAAWC,OAAOC,OAAO,CAAC,CAACC,KAAK,GAAG;AAC9C"}
@@ -1 +1 @@
1
- {"version":3,"file":"describe.js","names":[],"sources":["../src/describe.ts"],"sourcesContent":["import type { Field } from '@panneau/protocol';\n\nimport { getPathSteps } from './paths';\n\n/**\n * A readable name for the value at a path, from the labels of its fields: `Blocks › 3 › Body`,\n * `Title (fr)`. Unknown paths are returned as is.\n */\nexport function describePath(fields: readonly Field[], path: string): string {\n const steps = getPathSteps(fields, path);\n if (steps.length === 0) {\n return path;\n }\n return steps\n .map((step) => {\n const label = step.field.label ?? step.field.name;\n const locale = step.locale !== undefined ? ` (${step.locale})` : '';\n const index = step.index !== undefined ? ` › ${step.index + 1}` : '';\n return `${label}${locale}${index}`;\n })\n .join(' › ');\n}\n"],"mappings":";;;;;;AAQA,SAAgB,aAAa,QAA0B,MAAsB;CACzE,MAAM,QAAQ,aAAa,QAAQ,IAAI;CACvC,IAAI,MAAM,WAAW,GACjB,OAAO;CAEX,OAAO,MACF,KAAK,SAAS;EAIX,OAAO,GAHO,KAAK,MAAM,SAAS,KAAK,MAAM,OAC9B,KAAK,WAAW,KAAA,IAAY,KAAK,KAAK,OAAM,KAAM,KACnD,KAAK,UAAU,KAAA,IAAY,MAAM,KAAK,QAAQ,MAAM;CAEtE,CAAC,CAAC,CACD,KAAK,KAAK;AACnB"}
1
+ {"version":3,"file":"describe.js","names":["Field","getPathSteps","describePath","fields","path","steps","length","map","step","label","field","name","locale","undefined","index","join"],"sources":["../src/describe.ts"],"sourcesContent":["import type { Field } from '@panneau/protocol';\n\nimport { getPathSteps } from './paths';\n\n/**\n * A readable name for the value at a path, from the labels of its fields: `Blocks › 3 › Body`,\n * `Title (fr)`. Unknown paths are returned as is.\n */\nexport function describePath(fields: readonly Field[], path: string): string {\n const steps = getPathSteps(fields, path);\n if (steps.length === 0) {\n return path;\n }\n return steps\n .map((step) => {\n const label = step.field.label ?? step.field.name;\n const locale = step.locale !== undefined ? ` (${step.locale})` : '';\n const index = step.index !== undefined ? ` › ${step.index + 1}` : '';\n return `${label}${locale}${index}`;\n })\n .join(' › ');\n}\n"],"mappings":";;;;;;AAQA,SAAgBE,aAAaC,QAA0BC,MAAsB;CACzE,MAAMC,QAAQJ,aAAaE,QAAQC,IAAI;CACvC,IAAIC,MAAMC,WAAW,GACjB,OAAOF;CAEX,OAAOC,MACFE,KAAKC,SAAS;EAIX,OAAO,GAHOA,KAAKE,MAAMD,SAASD,KAAKE,MAAMC,OAC9BH,KAAKI,WAAWC,KAAAA,IAAY,KAAKL,KAAKI,OAAM,KAAM,KACnDJ,KAAKM,UAAUD,KAAAA,IAAY,MAAML,KAAKM,QAAQ,MAAM;CAEtE,CAAC,CAAC,CACDC,KAAK,KAAK;AACnB"}
@@ -1,8 +1,8 @@
1
1
  import type { Field, RuleFailure } from '@panneau/protocol';
2
2
  /**
3
3
  * Translates the failures of the portable rules with react-intl, for `formatError`. `min` and
4
- * `max` say "characters" for texts and "items" for lists, from the field at the path. A rule's own
5
- * `message` wins.
4
+ * `max` say "characters" for texts and "items" for lists, from the field at the path, and `crop`
5
+ * names its ratios. A rule's own `message` wins.
6
6
  */
7
7
  export declare function useFormatRuleFailure(fields: readonly Field[]): (failure: RuleFailure, path: string) => string;
8
8
  //# sourceMappingURL=formatError.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"formatError.d.ts","sourceRoot":"","sources":["../src/formatError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAQ5D;;;;GAIG;AACH,wBAAgB,oBAAoB,CAChC,MAAM,EAAE,SAAS,KAAK,EAAE,GACzB,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAwChD"}
1
+ {"version":3,"file":"formatError.d.ts","sourceRoot":"","sources":["../src/formatError.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAS5D;;;;GAIG;AACH,wBAAgB,oBAAoB,CAChC,MAAM,EAAE,SAAS,KAAK,EAAE,GACzB,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CA6FhD"}
@@ -2,17 +2,19 @@ import { messages } from "./messages.js";
2
2
  import { getPathSteps } from "./paths.js";
3
3
  import { c } from "react/compiler-runtime";
4
4
  import { usePanneauIntl } from "@panneau/ui";
5
+ import { getNestedShape } from "@panneau/protocol/runtime";
6
+ import { formatMoney } from "@panneau/fields/money";
5
7
  //#region src/formatError.ts
6
8
  var COUNTED = /* @__PURE__ */ new Set([
7
- "repeater",
8
9
  "relation",
9
10
  "media",
10
- "select"
11
+ "select",
12
+ "country"
11
13
  ]);
12
14
  /**
13
15
  * Translates the failures of the portable rules with react-intl, for `formatError`. `min` and
14
- * `max` say "characters" for texts and "items" for lists, from the field at the path. A rule's own
15
- * `message` wins.
16
+ * `max` say "characters" for texts and "items" for lists, from the field at the path, and `crop`
17
+ * names its ratios. A rule's own `message` wins.
16
18
  */
17
19
  function useFormatRuleFailure(fields) {
18
20
  const $ = c(3);
@@ -24,12 +26,30 @@ function useFormatRuleFailure(fields) {
24
26
  const step = getPathSteps(fields, path).at(-1);
25
27
  const field = step?.field;
26
28
  const value = typeof failure.value === "number" ? failure.value : 0;
29
+ if ((failure.rule === "min" || failure.rule === "max") && field?.type === "money") {
30
+ const currency = field.settings?.currency;
31
+ const amount = formatMoney({
32
+ amount: value,
33
+ currency: typeof currency === "string" ? currency : null
34
+ }, intl.locale) ?? String(value);
35
+ return intl.formatMessage(failure.rule === "min" ? messages.rule.minAmount : messages.rule.maxAmount, { value: amount });
36
+ }
37
+ if (failure.rule === "daterange") return intl.formatMessage(failure.value === "start" ? messages.rule.daterangeStart : failure.value === "end" ? messages.rule.daterangeEnd : messages.rule.daterangeOrder);
27
38
  if (failure.rule === "min" || failure.rule === "max") {
28
- const list = field !== void 0 && step?.index === void 0 && COUNTED.has(field.type) && (field.type === "repeater" || field.multiple === true);
39
+ const list = field !== void 0 && step?.index === void 0 && (getNestedShape(field) === "repeater" || COUNTED.has(field.type) && field.multiple === true);
29
40
  const numeric = field?.type === "number";
30
41
  const key = list ? failure.rule === "min" ? "minItems" : "maxItems" : numeric ? failure.rule : failure.rule === "min" ? "minLength" : "maxLength";
31
42
  return intl.formatMessage(messages.rule[key], { value });
32
43
  }
44
+ if (failure.rule === "crop") {
45
+ const given = typeof failure.value === "object" && failure.value !== null ? failure.value.ratios : void 0;
46
+ const ratios = Array.isArray(given) ? given.filter(_temp) : [];
47
+ return ratios.length > 0 ? intl.formatMessage(messages.rule.cropRatios, { ratios: intl.formatList(ratios, { type: "disjunction" }) }) : intl.formatMessage(messages.rule.crop);
48
+ }
49
+ if (failure.rule === "providers") {
50
+ const providers = Array.isArray(failure.value) ? failure.value.filter(_temp2) : [];
51
+ return intl.formatMessage(messages.rule.providers, { providers: intl.formatList(providers, { type: "disjunction" }) });
52
+ }
33
53
  const rule = failure.rule;
34
54
  if (rule in messages.rule && rule !== "min" && rule !== "max") return intl.formatMessage(messages.rule[rule]);
35
55
  return intl.formatMessage(messages.rule.invalid);
@@ -40,6 +60,12 @@ function useFormatRuleFailure(fields) {
40
60
  } else t0 = $[2];
41
61
  return t0;
42
62
  }
63
+ function _temp2(name) {
64
+ return typeof name === "string";
65
+ }
66
+ function _temp(ratio) {
67
+ return typeof ratio === "string";
68
+ }
43
69
  //#endregion
44
70
  export { useFormatRuleFailure };
45
71
 
@@ -1 +1 @@
1
- {"version":3,"file":"formatError.js","names":["_c"],"sources":["../src/formatError.ts"],"sourcesContent":["import type { Field, RuleFailure } from '@panneau/protocol';\nimport { usePanneauIntl } from '@panneau/ui';\n\nimport { messages } from './messages';\nimport { getPathSteps } from './paths';\n\nconst COUNTED = new Set(['repeater', 'relation', 'media', 'select']);\n\n/**\n * Translates the failures of the portable rules with react-intl, for `formatError`. `min` and\n * `max` say \"characters\" for texts and \"items\" for lists, from the field at the path. A rule's own\n * `message` wins.\n */\nexport function useFormatRuleFailure(\n fields: readonly Field[],\n): (failure: RuleFailure, path: string) => string {\n const intl = usePanneauIntl();\n return (failure, path) => {\n if (failure.message !== undefined) {\n return failure.message;\n }\n const step = getPathSteps(fields, path).at(-1);\n const field = step?.field;\n const value = typeof failure.value === 'number' ? failure.value : 0;\n if (failure.rule === 'min' || failure.rule === 'max') {\n const list =\n field !== undefined &&\n step?.index === undefined &&\n COUNTED.has(field.type) &&\n (field.type === 'repeater' || field.multiple === true);\n const numeric = field?.type === 'number';\n const key = list\n ? failure.rule === 'min'\n ? 'minItems'\n : 'maxItems'\n : numeric\n ? failure.rule\n : failure.rule === 'min'\n ? 'minLength'\n : 'maxLength';\n return intl.formatMessage(messages.rule[key], { value });\n }\n const rule = failure.rule as keyof typeof messages.rule;\n if (rule in messages.rule && rule !== 'min' && rule !== 'max') {\n return intl.formatMessage(\n messages.rule[\n rule as Exclude<\n typeof rule,\n 'min' | 'max' | 'minLength' | 'maxLength' | 'minItems' | 'maxItems'\n >\n ],\n );\n }\n return intl.formatMessage(messages.rule.invalid);\n };\n}\n"],"mappings":";;;;;AAMA,IAAM,0BAAU,IAAI,IAAI;CAAC;CAAY;CAAY;CAAS;AAAQ,CAAC;;;;;;AAOnE,SAAO,qBAAA,QAAA;CAAA,MAAA,IAAAA,EAAA,CAAA;CAGH,MAAA,OAAa,eAAe;CAAE,IAAA;CAAA,IAAA,EAAA,OAAA,UAAA,EAAA,OAAA,MAAA;EACvB,MAAA,SAAA,SAAA;GACH,IAAI,QAAO,YAAa,KAAA,GAAS,OACtB,QAAO;GAElB,MAAA,OAAa,aAAa,QAAQ,IAAI,CAAC,CAAA,GAAI,EAAE;GAC7C,MAAA,QAAc,MAAI;GAClB,MAAA,QAAc,OAAO,QAAO,UAAW,WAAW,QAAO,QAA3C;GACd,IAAI,QAAO,SAAU,SAAS,QAAO,SAAU,OAAK;IAChD,MAAA,OACI,UAAU,KAAA,KACV,MAAI,UAAY,KAAA,KAChB,QAAO,IAAK,MAAK,IAAK,MACrB,MAAK,SAAU,cAAc,MAAK,aAAc;IACrD,MAAA,UAAgB,OAAK,SAAW;IAChC,MAAA,MAAY,OACN,QAAO,SAAU,QAAjB,aAAA,aAGA,UACE,QAAO,OACP,QAAO,SAAU,QAAjB,cAAA;IAEc,OACf,KAAI,cAAe,SAAQ,KAAM,MAAM,EAAA,MAAQ,CAAC;GAAC;GAE5D,MAAA,OAAa,QAAO;GACpB,IAAI,QAAQ,SAAQ,QAAS,SAAS,SAAS,SAAS,OAAK,OAClD,KAAI,cACP,SAAQ,KACJ,KAKR;GACH,OACM,KAAI,cAAe,SAAQ,KAAK,OAAQ;EAAC;EACnD,EAAA,KAAA;EAAA,EAAA,KAAA;EAAA,EAAA,KAAA;CAAA,OAAA,KAAA,EAAA;CAAA,OArCM;AAqCN"}
1
+ {"version":3,"file":"formatError.js","names":["formatMoney","Field","RuleFailure","getNestedShape","usePanneauIntl","messages","getPathSteps","COUNTED","Set","useFormatRuleFailure","fields","$","_c","intl","t0","failure","path","message","undefined","step","at","field","value","rule","type","currency","settings","amount","locale","String","formatMessage","minAmount","maxAmount","daterangeStart","daterangeEnd","daterangeOrder","list","index","has","multiple","numeric","key","given","ratios","Array","isArray","filter","_temp","length","cropRatios","formatList","crop","providers","_temp2","Exclude","invalid","name","ratio","_c"],"sources":["../src/formatError.ts"],"sourcesContent":["import { formatMoney } from '@panneau/fields/money';\nimport type { Field, RuleFailure } from '@panneau/protocol';\nimport { getNestedShape } from '@panneau/protocol/runtime';\nimport { usePanneauIntl } from '@panneau/ui';\n\nimport { messages } from './messages';\nimport { getPathSteps } from './paths';\n\nconst COUNTED = new Set(['relation', 'media', 'select', 'country']);\n\n/**\n * Translates the failures of the portable rules with react-intl, for `formatError`. `min` and\n * `max` say \"characters\" for texts and \"items\" for lists, from the field at the path, and `crop`\n * names its ratios. A rule's own `message` wins.\n */\nexport function useFormatRuleFailure(\n fields: readonly Field[],\n): (failure: RuleFailure, path: string) => string {\n const intl = usePanneauIntl();\n return (failure, path) => {\n if (failure.message !== undefined) {\n return failure.message;\n }\n const step = getPathSteps(fields, path).at(-1);\n const field = step?.field;\n const value = typeof failure.value === 'number' ? failure.value : 0;\n if ((failure.rule === 'min' || failure.rule === 'max') && field?.type === 'money') {\n // An amount in minor units, in the currency of the field (decision 0053).\n const currency = field.settings?.currency;\n const amount =\n formatMoney(\n { amount: value, currency: typeof currency === 'string' ? currency : null },\n intl.locale,\n ) ?? String(value);\n return intl.formatMessage(\n failure.rule === 'min' ? messages.rule.minAmount : messages.rule.maxAmount,\n { value: amount },\n );\n }\n if (failure.rule === 'daterange') {\n return intl.formatMessage(\n failure.value === 'start'\n ? messages.rule.daterangeStart\n : failure.value === 'end'\n ? messages.rule.daterangeEnd\n : messages.rule.daterangeOrder,\n );\n }\n if (failure.rule === 'min' || failure.rule === 'max') {\n const list =\n field !== undefined &&\n step?.index === undefined &&\n (getNestedShape(field) === 'repeater' ||\n (COUNTED.has(field.type) && field.multiple === true));\n const numeric = field?.type === 'number';\n const key = list\n ? failure.rule === 'min'\n ? 'minItems'\n : 'maxItems'\n : numeric\n ? failure.rule\n : failure.rule === 'min'\n ? 'minLength'\n : 'maxLength';\n return intl.formatMessage(messages.rule[key], { value });\n }\n if (failure.rule === 'crop') {\n const given =\n typeof failure.value === 'object' && failure.value !== null\n ? (failure.value as { ratios?: unknown }).ratios\n : undefined;\n const ratios = Array.isArray(given)\n ? given.filter((ratio): ratio is string => typeof ratio === 'string')\n : [];\n return ratios.length > 0\n ? intl.formatMessage(messages.rule.cropRatios, {\n ratios: intl.formatList(ratios, { type: 'disjunction' }),\n })\n : intl.formatMessage(messages.rule.crop);\n }\n if (failure.rule === 'providers') {\n const providers = Array.isArray(failure.value)\n ? failure.value.filter((name): name is string => typeof name === 'string')\n : [];\n return intl.formatMessage(messages.rule.providers, {\n providers: intl.formatList(providers, { type: 'disjunction' }),\n });\n }\n const rule = failure.rule as keyof typeof messages.rule;\n if (rule in messages.rule && rule !== 'min' && rule !== 'max') {\n return intl.formatMessage(\n messages.rule[\n rule as Exclude<\n typeof rule,\n | 'min'\n | 'max'\n | 'minLength'\n | 'maxLength'\n | 'minItems'\n | 'maxItems'\n | 'cropRatios'\n | 'providers'\n | 'minAmount'\n | 'maxAmount'\n >\n ],\n );\n }\n return intl.formatMessage(messages.rule.invalid);\n };\n}\n"],"mappings":";;;;;;;AAQA,IAAMO,0BAAU,IAAIC,IAAI;CAAC;CAAY;CAAS;CAAU;AAAS,CAAC;;;;;;AAOlE,SAAOC,qBAAAC,QAAA;CAAA,MAAAC,IAAAC,EAAA,CAAA;CAGH,MAAAC,OAAaT,eAAe;CAAE,IAAAU;CAAA,IAAAH,EAAA,OAAAD,UAAAC,EAAA,OAAAE,MAAA;EACvBC,MAAAC,SAAAC,SAAA;GACH,IAAID,QAAOE,YAAaC,KAAAA,GAAS,OACtBH,QAAOE;GAElB,MAAAE,OAAab,aAAaI,QAAQM,IAAI,CAAC,CAAAI,GAAI,EAAE;GAC7C,MAAAC,QAAcF,MAAIE;GAClB,MAAAC,QAAc,OAAOP,QAAOO,UAAW,WAAWP,QAAOO,QAA3C;GACd,KAAKP,QAAOQ,SAAU,SAASR,QAAOQ,SAAU,UAAUF,OAAKG,SAAW,SAAO;IAE7E,MAAAC,WAAiBJ,MAAKK,UAAmBD;IACzC,MAAAE,SACI3B,YACI;KAAA2B,QAAUL;KAAKG,UAAY,OAAOA,aAAa,WAApBA,WAAA;IAA+C,GAC1EZ,KAAIe,MACS,KAAZC,OAAOP,KA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,QAAOO,KAEhC,IADDP,QAAOO,MAAMwB,OAAQO,MACpB,IAFW,CAAA;IAET,OACFxC,KAAIiB,cAAezB,SAAQkB,KAAK6B,WAAY,EAAAA,WACpCvC,KAAIqC,WAAYE,WAAW,EAAA5B,MAAQ,cAAc,CAAC,EACjE,CAAC;GAAC;GAEN,MAAAD,OAAaR,QAAOQ;GACpB,IAAIA,QAAQlB,SAAQkB,QAASA,SAAS,SAASA,SAAS,OAAK,OAClDV,KAAIiB,cACPzB,SAAQkB,KACJA,KAcR;GACH,OACMV,KAAIiB,cAAezB,SAAQkB,KAAKgC,OAAQ;EAAC;EACnD5C,EAAA,KAAAD;EAAAC,EAAA,KAAAE;EAAAF,EAAA,KAAAG;CAAA,OAAAA,KAAAH,EAAA;CAAA,OA1FMG;AA0FN;AA9FE,SAAAuC,OAAAG,MAAA;CAAA,OAmE0D,OAAOA,SAAS;AAAQ;AAnElF,SAAAT,MAAAU,OAAA;CAAA,OAyDoD,OAAOA,UAAU;AAAQ"}
package/dist/index.d.ts CHANGED
@@ -1,10 +1,12 @@
1
- export { ConflictDialog, type ConflictDialogProps } from './ConflictDialog';
2
- export { describePath } from './describe';
3
- export { ErrorSummary, type ErrorSummaryProps } from './ErrorSummary';
4
- export { Form, type FormProps } from './Form';
5
- export { FormBinding } from './FormBinding';
6
- export { FormView, type FormViewProps } from './FormView';
7
- export { useFormContext, useFormState } from './context';
8
- export { useFormatRuleFailure } from './formatError';
9
- export { type LeaveConfirmation, useBeforeUnloadGuard, useLeaveConfirmation } from './unsaved';
1
+ export { ConflictDialog, type ConflictDialogProps } from './ConflictDialog.js';
2
+ export { describePath } from './describe.js';
3
+ export { ErrorSummary, type ErrorSummaryProps } from './ErrorSummary.js';
4
+ export { Form, type FormProps } from './Form.js';
5
+ export { FormBinding } from './FormBinding.js';
6
+ export { FormView, type FormViewProps } from './FormView.js';
7
+ export type { LayoutComponentProps } from './layout/Layout.js';
8
+ export type { FormPanelComponent, FormPanelProps } from './panels/panels.js';
9
+ export { useFormContext, useFormState } from './context.js';
10
+ export { useFormatRuleFailure } from './formatError.js';
11
+ export { type LeaveConfirmation, useBeforeUnloadGuard, useLeaveConfirmation } from './unsaved.js';
10
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,KAAK,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC5E,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,EAAE,IAAI,EAAE,KAAK,SAAS,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,KAAK,iBAAiB,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,KAAK,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC5E,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,EAAE,IAAI,EAAE,KAAK,SAAS,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAC1D,YAAY,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAC5D,YAAY,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,KAAK,iBAAiB,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC"}
@@ -1,9 +1,37 @@
1
1
  import { type ReactNode } from 'react';
2
+ import { type Form } from '@panneau/core';
2
3
  import type { Field, LayoutNode } from '@panneau/protocol';
3
4
  export interface LayoutProps {
4
5
  nodes: readonly LayoutNode[];
5
6
  fields: ReadonlyMap<string, Field>;
6
7
  }
8
+ export interface SidebarNodeProps {
9
+ node: LayoutNode;
10
+ fields: ReadonlyMap<string, Field>;
11
+ /** Where the browser remembers whether the panel is collapsed (`Form`'s `sidebarStorageKey`). */
12
+ storageKey?: string | undefined;
13
+ }
14
+ /**
15
+ * A `sidebar` node of a form layout: a panel of the form's aside (decision 0074). With a `label`,
16
+ * the user can collapse it, unless `collapsible: false`, and the browser remembers it. It opens to
17
+ * reveal a field, and after a failed save when it holds an error, as a section does. With a
18
+ * `panel`, its component renders it, with its children (decision 0075).
19
+ */
20
+ export declare function SidebarNode({ node, fields, storageKey }: SidebarNodeProps): import("react").JSX.Element;
21
+ /** What the component of a `component` node of a form layout gets, with the node's `props`. */
22
+ export interface LayoutComponentProps {
23
+ node: LayoutNode;
24
+ form: Form;
25
+ /** The fields of the form, by name. */
26
+ fields: ReadonlyMap<string, Field>;
27
+ /** The node's children, rendered: the fields a component frames (decision 0065). */
28
+ children: ReactNode;
29
+ }
7
30
  /** Renders layout nodes in order. */
8
31
  export declare function LayoutNodes({ nodes, fields }: LayoutProps): ReactNode;
32
+ /**
33
+ * Fields that the layout doesn't place, in columns: short fields side by side, wide ones
34
+ * (`isWideField()`) on their own row.
35
+ */
36
+ export declare function FieldFlow({ nodes, fields }: LayoutProps): ReactNode;
9
37
  //# sourceMappingURL=Layout.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Layout.d.ts","sourceRoot":"","sources":["../../src/layout/Layout.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEH,KAAK,SAAS,EAMjB,MAAM,OAAO,CAAC;AAUf,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAO3D,MAAM,WAAW,WAAW;IACxB,KAAK,EAAE,SAAS,UAAU,EAAE,CAAC;IAC7B,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;CACtC;AAwLD,qCAAqC;AACrC,wBAAgB,WAAW,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,WAAW,GAAG,SAAS,CAErE"}
1
+ {"version":3,"file":"Layout.d.ts","sourceRoot":"","sources":["../../src/layout/Layout.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEH,KAAK,SAAS,EAMjB,MAAM,OAAO,CAAC;AAEf,OAAO,EACH,KAAK,IAAI,EAKZ,MAAM,eAAe,CAAC;AAEvB,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAmB3D,MAAM,WAAW,WAAW;IACxB,KAAK,EAAE,SAAS,UAAU,EAAE,CAAC;IAC7B,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;CACtC;AAkID,MAAM,WAAW,gBAAgB;IAC7B,IAAI,EAAE,UAAU,CAAC;IACjB,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACnC,iGAAiG;IACjG,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACnC;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE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