@panneau/forms 5.0.0-alpha.17 → 5.0.0-alpha.19
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 +2 -1
- package/dist/Form.css +10 -2
- package/dist/Form.module.js +5 -3
- package/dist/Form.module.js.map +1 -1
- package/dist/FormBinding.d.ts.map +1 -1
- package/dist/FormBinding.js +5 -8
- package/dist/FormBinding.js.map +1 -1
- package/dist/FormSkeleton.d.ts.map +1 -1
- package/dist/FormSkeleton.js +0 -1
- package/dist/FormSkeleton.js.map +1 -1
- package/dist/FormView.d.ts +15 -2
- package/dist/FormView.d.ts.map +1 -1
- package/dist/FormView.js +221 -182
- package/dist/FormView.js.map +1 -1
- package/dist/context.d.ts +7 -0
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +8 -2
- package/dist/context.js.map +1 -1
- package/dist/formatError.d.ts.map +1 -1
- package/dist/formatError.js +2 -2
- package/dist/formatError.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/layout/Layout.d.ts +10 -0
- package/dist/layout/Layout.d.ts.map +1 -1
- package/dist/layout/Layout.js +126 -86
- package/dist/layout/Layout.js.map +1 -1
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +2 -1
- package/dist/paths.js.map +1 -1
- package/dist/publication/Publication.d.ts +33 -0
- package/dist/publication/Publication.d.ts.map +1 -0
- package/dist/publication/Publication.js +218 -0
- package/dist/publication/Publication.js.map +1 -0
- package/dist/publication/index.d.ts +3 -0
- package/dist/publication/index.d.ts.map +1 -0
- package/dist/publication/index.js +1 -0
- package/package.json +14 -7
package/dist/FormView.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormView.js","names":["ReactNode","useRef","useState","Form","SubmitResult","getLayoutFieldNames","getProblem","resolveFields","selectVisible","useLeaveGuard","usePanneau","usePlugins","FieldCheckSource","FieldEntry","FieldsProvider","RelationSource","UploadSource","builtInFields","Field","LayoutNode","Alert","Button","usePanneauIntl","useToast","ConflictDialog","ErrorSummary","styles","FormBinding","FormSkeleton","FormContext","RevealContext","createRevealRegistry","useFormState","cx","FieldFlow","LayoutNodes","messages","useBeforeUnloadGuard","useLeaveConfirmation","FormViewProps","form","fields","layout","locales","relationSource","uploadSource","checkSource","components","Readonly","Record","submitLabel","actions","onSubmitted","result","onReload","guardUnsavedChanges","showSavedToast","isLoading","id","className","layoutClassName","sidebarClassName","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","FormView","t0","$","_c","t1","t2","t3","t4","ariaLabel","intl","toasts","definition","plugins","state","registry","resolving","setResolving","guarded","dirty","leave","confirmLeave","formLocales","resolved","mode","main","filter","_temp","Set","flow","laidOut","t5","node_0","sidebar","order","flatMap","_temp2","t6","t7","t8","goTo","reveal","show","frames","closest","requestAnimationFrame","reduced","window","matchMedia","matches","scrollIntoView","block","behavior","target","focus","preventScroll","handle","status","first","keys","title","formatMessage","saved","tone","saveFailed","action","label","retry","onAction","submit","then","timeout","resolve","choice","conflict","resolveConflict","finally","t9","error","problem","errorDetail","detail","Error","message","showSummary","submitCount","_temp3","fieldsByName","t10","t11","t12","t13","t14","t15","withSidebar","t16","t17","footer","unsaved","save","t18","t19","t20","t21","t22","values","event","preventDefault","stack","map","node_3","children","dialog","node_2","node_1","_c","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 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 { 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 { FormSkeleton } from './FormSkeleton';\nimport { FormContext, RevealContext, createRevealRegistry, useFormState } from './context';\nimport { cx } from './cx';\nimport { FieldFlow, LayoutNodes } from './layout/Layout';\nimport { messages } from './messages';\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 /** 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 /** Shows a toast after a successful submit. Defaults to true. */\n showSavedToast?: 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 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/**\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 checkSource,\n components,\n submitLabel,\n actions,\n onSubmitted,\n onReload,\n guardUnsavedChanges = true,\n showSavedToast = true,\n isLoading = false,\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 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 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 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 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 await form\n .resolveConflict(choice)\n .then(handle)\n .finally(() => setResolving(false));\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 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={submitLabel !== null || actions !== undefined}\n className={className}\n layoutClassName={layoutClassName}\n sidebarClassName={sidebarClassName}\n footerClassName={footerClassName}\n />\n );\n }\n\n return (\n <FormContext value={form}>\n <RevealContext value={registry}>\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 >\n {showSummary ? (\n <ErrorSummary\n errors={orderErrors(order, state.errors, formLocales)}\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={laidOut} fields={resolved.fieldsByName} />\n {flow.length > 0 ? (\n <FieldFlow nodes={flow} fields={resolved.fieldsByName} />\n ) : null}\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 {leave.dialog}\n </FieldsProvider>\n </RevealContext>\n </FormContext>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA2FA,IAAMgE,YACF;;AAGJ,SAASC,iBAAiBC,MAAmBE,MAAkC;CAC3E,IAAIC,UAAUD;CACd,OAAOC,YAAY,IAAI;EACnB,MAAMC,UAAUJ,KAAKK,cACjB,uBAAuBC,IAAIC,OAAOJ,OAAO,EAAC,GAC9C;EACA,IAAIC,YAAY,MACZ,OAAOA;EAEXD,UAAUA,QAAQK,SAAS,GAAG,IAAIL,QAAQM,MAAM,GAAGN,QAAQO,YAAY,GAAG,CAAC,IAAI;CACnF;CACA,OAAO;AACX;;;;;;AAOA,SAASC,YACLC,OACAC,QACApC,UAA6B,CAAA,GACL;CACxB,MAAMqC,QAAQZ,SAAiB;EAC3B,MAAMa,QAAQH,MAAMI,QAAQd,KAAKe,MAAM,GAAG,CAAC,CAAC,MAAM,EAAE;EACpD,OAAOF,UAAU,KAAKH,MAAMM,SAASH;CACzC;CACA,MAAMI,cAAcjB,SAAiB;EACjC,MAAMa,QAAQtC,QAAQuC,QAAQd,KAAKe,MAAM,GAAG,CAAC,CAAC,MAAM,EAAE;EACtD,OAAOF,UAAU,KAAKtC,QAAQyC,SAASH;CAC3C;CACA,MAAMK,WAAWC,GAAWC,MACxBR,KAAKO,CAAC,IAAIP,KAAKQ,CAAC,KAChBH,WAAWE,CAAC,IAAIF,WAAWG,CAAC,KAC5BD,EAAEE,cAAcD,GAAGE,KAAAA,GAAW,EAAEC,SAAS,KAAK,CAAC;CACnD,OAAOC,OAAOC,YAAYD,OAAOE,QAAQf,MAAM,CAAC,CAACgB,MAAM,C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,WAAA3K,oBAAMwL;SAAtB,UAAA,CACI,oBAAC,aAAD;UAAoB9E,OAAAA;UAAiB,QAAAP,SAAQgE;SAAa,CAAA,GACzD1D,KAAI/C,SAAU,IACX,oBAAC,WAAD;UAAkB+C,OAAAA;UAAc,QAAAN,SAAQgE;SAAa,CAAA,IADxD,IAGC;QACLtD,CAAAA,GAAAA,QAAOnD,SAAU,IACd,oBAAA,SAAA;SAAkB,WAAAnD,GAAGP,oBAAM6G,SAAU1E,gBAAgB;SAChD0E,UAAAA,QAAO4E,KAAKC,QAAAnI,UACT,oBAAA,OAAA;UAA4B,WAAAvD,oBAAMwL;UAC9B,UAAA,oBAAC,aAAD;WACW,OAAAjH,OAAIoH,YAAJ,CAAA;WACC,QAAAxF,SAAQgE;UAAa,CAAA;SAE/B,GALI5G,KAKJ,CACT;QACG,CAAA,IAVX,IAYC;;OACLqH;MAmBE;;KACPQ;KASCpF,MAAK4F;IAlGK;;EADL,CAAA;CADN,CAAA;AAuGE;AA9Pf,SAAA1B,OAAA2B,QAAA;CAAA,OA2ImDtH,OAAIG,SAAU;AAAS;AA3I1E,SAAAsC,OAAA8E,QAAA;CAAA,OAwDkDvH,OAAIoH,YAAJ,CAAA;AAAmB;AAxDrE,SAAApF,MAAAhC,MAAA;CAAA,OA0C2CA,KAAIG,SAAU;AAAS"}
|
|
1
|
+
{"version":3,"file":"FormView.js","names":["CircleCheck","KeyboardEvent","ReactNode","useRef","useState","Form","SubmitResult","getLayoutFieldNames","getProblem","resolveFields","selectVisible","useLeaveGuard","usePanneau","usePlugins","FieldCheckSource","FieldEntry","FieldsProvider","RelationSource","UploadSource","builtInFields","Field","LayoutNode","Alert","Button","Icon","Tooltip","isApplePlatform","usePanneauIntl","useToast","useToastOffset","ConflictDialog","ErrorSummary","styles","FormBinding","FormSkeleton","ErrorSectionsContext","FormContext","RevealContext","createRevealRegistry","useFormState","cx","FieldFlow","LayoutNodes","messages","useBeforeUnloadGuard","useLeaveConfirmation","FormViewProps","form","fields","layout","locales","relationSource","uploadSource","checkSource","components","Readonly","Record","submitLabel","actions","onSubmitted","result","onReload","guardUnsavedChanges","showSavedToast","saved","isLoading","id","className","layoutClassName","sidebarClassName","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","t8","t9","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","t10","Symbol","for","t11","Node","currentTarget","contains","preventDefault","requestSubmit","onKeyDown","t12","error","problem","errorDetail","detail","Error","message","showSummary","submitCount","_temp3","fieldsByName","t13","t14","t15","t16","t17","saveFailed","retry","t18","withSidebar","t19","t20","statusError","unsaved","saveShortcut","modifier","save","t21","t22","t23","t24","t25","values","event_0","submit","stack","map","node_3","children","dialog","node_2","node_1","_c","createRevealRegistry","styles","_Fragment"],"sources":["../src/FormView.tsx"],"sourcesContent":["import { CircleCheck } from 'lucide-react';\nimport { 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 Button,\n Icon,\n Tooltip,\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 } from './layout/Layout';\nimport { messages } from './messages';\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 /** 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 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 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 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 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\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 <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={orderErrors(order, state.errors, formLocales)}\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={laidOut} fields={resolved.fieldsByName} />\n {flow.length > 0 ? (\n <FieldFlow nodes={flow} fields={resolved.fieldsByName} />\n ) : null}\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 {hasFooter ? (\n <div ref={footer} className={cx(styles.footer, footerClassName)}>\n <span\n className={cx(\n styles.status,\n state.status === 'error' && styles.statusError,\n )}\n role=\"status\"\n >\n {state.status === 'error' ? (\n intl.formatMessage(messages.saveFailed)\n ) : state.dirty ? (\n intl.formatMessage(messages.unsaved)\n ) : savedShown && state.status !== 'submitting' ? (\n <>\n <Icon icon={CircleCheck} />\n {intl.formatMessage(messages.saved)}\n </>\n ) : null}\n </span>\n {actions}\n {submitLabel !== null ? (\n <Tooltip\n content={intl.formatMessage(messages.saveShortcut, {\n modifier: apple ? '⌘' : 'Ctrl',\n })}\n >\n <Button\n type=\"submit\"\n variant=\"primary\"\n isPending={state.status === 'submitting'}\n aria-keyshortcuts={\n apple ? 'Meta+Enter' : 'Control+Enter'\n }\n >\n {submitLabel ?? intl.formatMessage(messages.save)}\n </Button>\n </Tooltip>\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 {leave.dialog}\n </FieldsProvider>\n </ErrorSectionsContext>\n </RevealContext>\n </FormContext>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAqHA,IAAMwE,YACF;;AAGJ,SAASC,iBAAiBC,MAAmBE,MAAkC;CAC3E,IAAIC,UAAUD;CACd,OAAOC,YAAY,IAAI;EACnB,MAAMC,UAAUJ,KAAKK,cACjB,uBAAuBC,IAAIC,OAAOJ,OAAO,EAAC,GAC9C;EACA,IAAIC,YAAY,MACZ,OAAOA;EAEXD,UAAUA,QAAQK,SAAS,GAAG,IAAIL,QAAQM,MAAM,GAAGN,QAAQO,YAAY,GAAG,CAAC,IAAI;CACnF;CACA,OAAO;AACX;;;;;;AAOA,SAASC,YACLC,OACAC,QACArC,UAA6B,CAAA,GACL;CACxB,MAAMsC,QAAQZ,SAAiB;EAC3B,MAAMa,QAAQH,MAAMI,QAAQd,KAAKe,MAAM,GAAG,CAAC,CAAC,MAAM,EAAE;EACpD,OAAOF,UAAU,KAAKH,MAAMM,SAASH;CACzC;CACA,MAAMI,cAAcjB,SAAiB;EACjC,MAAMa,QAAQvC,QAAQwC,QAAQd,KAAKe,MAAM,GAAG,CAAC,CAAC,MAAM,EAAE;EACtD,OAAOF,UAAU,KAAKvC,QAAQ0C,SAASH;CAC3C;CAC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AAU;AAAS;AAnK1E,SAAAuD,OAAAsF,QAAA;CAAA,OAoEkDhJ,OAAI6I,YAAJ,CAAA;AAAmB;AApErE,SAAA5F,MAAAjD,MAAA;CAAA,OAsD2CA,KAAIG,SAAU;AAAS"}
|
package/dist/context.d.ts
CHANGED
|
@@ -1,8 +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
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>;
|
|
8
15
|
//# sourceMappingURL=context.d.ts.map
|
package/dist/context.d.ts.map
CHANGED
|
@@ -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;
|
|
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,5 +1,5 @@
|
|
|
1
1
|
import { createContext, use, useSyncExternalStore } from "react";
|
|
2
|
-
import { RevealContext, createRevealRegistry } from "@panneau/fields";
|
|
2
|
+
import { RevealContext, createRevealRegistry, createRevealRegistry as createRevealRegistry$1 } from "@panneau/fields";
|
|
3
3
|
//#region src/context.ts
|
|
4
4
|
var FormContext = createContext(null);
|
|
5
5
|
/** The form of the closest `FormView`. */
|
|
@@ -12,7 +12,13 @@ function useFormContext() {
|
|
|
12
12
|
function useFormState(form) {
|
|
13
13
|
return useSyncExternalStore(form.subscribe, form.getState, form.getState);
|
|
14
14
|
}
|
|
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());
|
|
15
21
|
//#endregion
|
|
16
|
-
export { FormContext, RevealContext, createRevealRegistry, useFormContext, useFormState };
|
|
22
|
+
export { ErrorSectionsContext, FormContext, RevealContext, createRevealRegistry$1 as createRevealRegistry, useFormContext, useFormState };
|
|
17
23
|
|
|
18
24
|
//# sourceMappingURL=context.js.map
|
package/dist/context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","names":["createContext","use","useSyncExternalStore","Form","FormState","FormContext","useFormContext","form","Error","useFormState","subscribe","getState","RevealContext","
|
|
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"}
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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"}
|
package/dist/formatError.js
CHANGED
|
@@ -2,10 +2,10 @@ 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";
|
|
5
6
|
import { formatMoney } from "@panneau/fields/money";
|
|
6
7
|
//#region src/formatError.ts
|
|
7
8
|
var COUNTED = /* @__PURE__ */ new Set([
|
|
8
|
-
"repeater",
|
|
9
9
|
"relation",
|
|
10
10
|
"media",
|
|
11
11
|
"select",
|
|
@@ -36,7 +36,7 @@ function useFormatRuleFailure(fields) {
|
|
|
36
36
|
}
|
|
37
37
|
if (failure.rule === "daterange") return intl.formatMessage(failure.value === "start" ? messages.rule.daterangeStart : failure.value === "end" ? messages.rule.daterangeEnd : messages.rule.daterangeOrder);
|
|
38
38
|
if (failure.rule === "min" || failure.rule === "max") {
|
|
39
|
-
const list = field !== void 0 && step?.index === void 0 &&
|
|
39
|
+
const list = field !== void 0 && step?.index === void 0 && (getNestedShape(field) === "repeater" || COUNTED.has(field.type) && field.multiple === true);
|
|
40
40
|
const numeric = field?.type === "number";
|
|
41
41
|
const key = list ? failure.rule === "min" ? "minItems" : "maxItems" : numeric ? failure.rule : failure.rule === "min" ? "minLength" : "maxLength";
|
|
42
42
|
return intl.formatMessage(messages.rule[key], { value });
|
package/dist/formatError.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatError.js","names":["formatMoney","Field","RuleFailure","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 { usePanneauIntl } from '@panneau/ui';\n\nimport { messages } from './messages';\nimport { getPathSteps } from './paths';\n\nconst COUNTED = new Set(['
|
|
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'\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C,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
|
@@ -4,6 +4,7 @@ export { ErrorSummary, type ErrorSummaryProps } from './ErrorSummary.js';
|
|
|
4
4
|
export { Form, type FormProps } from './Form.js';
|
|
5
5
|
export { FormBinding } from './FormBinding.js';
|
|
6
6
|
export { FormView, type FormViewProps } from './FormView.js';
|
|
7
|
+
export type { LayoutComponentProps } from './layout/Layout.js';
|
|
7
8
|
export { useFormContext, useFormState } from './context.js';
|
|
8
9
|
export { useFormatRuleFailure } from './formatError.js';
|
|
9
10
|
export { type LeaveConfirmation, useBeforeUnloadGuard, useLeaveConfirmation } from './unsaved.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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,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"}
|
package/dist/layout/Layout.d.ts
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
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
|
+
/** What the component of a `component` node of a form layout gets, with the node's `props`. */
|
|
9
|
+
export interface LayoutComponentProps {
|
|
10
|
+
node: LayoutNode;
|
|
11
|
+
form: Form;
|
|
12
|
+
/** The fields of the form, by name. */
|
|
13
|
+
fields: ReadonlyMap<string, Field>;
|
|
14
|
+
/** The node's children, rendered: the fields a component frames (decision 0065). */
|
|
15
|
+
children: ReactNode;
|
|
16
|
+
}
|
|
7
17
|
/** Renders layout nodes in order. */
|
|
8
18
|
export declare function LayoutNodes({ nodes, fields }: LayoutProps): ReactNode;
|
|
9
19
|
/**
|
|
@@ -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;
|
|
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;AAQ3D,MAAM,WAAW,WAAW;IACxB,KAAK,EAAE,SAAS,UAAU,EAAE,CAAC;IAC7B,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;CACtC;AAgID,+FAA+F;AAC/F,MAAM,WAAW,oBAAoB;IACjC,IAAI,EAAE,UAAU,CAAC;IACjB,IAAI,EAAE,IAAI,CAAC;IACX,uCAAuC;IACvC,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACnC,oFAAoF;IACpF,QAAQ,EAAE,SAAS,CAAC;CACvB;AA2ED,qCAAqC;AACrC,wBAAgB,WAAW,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,WAAW,GAAG,SAAS,CAErE;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,WAAW,GAAG,SAAS,CAmBnE"}
|