@lattice-php/lattice 0.17.0 → 0.17.2

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 (70) hide show
  1. package/dist/chat/index.d.ts +1 -1
  2. package/dist/chat/index.js +3 -3
  3. package/dist/chat/index.js.map +1 -1
  4. package/dist/core/components/chart-view.d.ts +3 -0
  5. package/dist/core/components/chart-view.js +225 -0
  6. package/dist/core/components/chart-view.js.map +1 -0
  7. package/dist/core/components/chart.js +10 -220
  8. package/dist/core/components/chart.js.map +1 -1
  9. package/dist/core/components/index.js +3 -2
  10. package/dist/core/components/index.js.map +1 -1
  11. package/dist/core/renderer.js +42 -2
  12. package/dist/core/renderer.js.map +1 -1
  13. package/dist/create-app.js +3 -3
  14. package/dist/create-app.js.map +1 -1
  15. package/dist/form/components/fields/date-input.js +2 -2
  16. package/dist/form/components/fields/date-input.js.map +1 -1
  17. package/dist/form/components/fields/{date-picker-control.d.ts → date-picker-field.d.ts} +2 -2
  18. package/dist/form/components/fields/{date-picker-control.js → date-picker-field.js} +4 -4
  19. package/dist/form/components/fields/date-picker-field.js.map +1 -0
  20. package/dist/form/components/fields/date-picker.d.ts +2 -0
  21. package/dist/form/components/fields/date-picker.js +17 -0
  22. package/dist/form/components/fields/date-picker.js.map +1 -0
  23. package/dist/form/components/fields/date-time-input.js +2 -2
  24. package/dist/form/components/fields/date-time-input.js.map +1 -1
  25. package/dist/form/components/fields/rich-editor-field.d.ts +3 -0
  26. package/dist/form/components/fields/rich-editor-field.js +340 -0
  27. package/dist/form/components/fields/rich-editor-field.js.map +1 -0
  28. package/dist/form/components/fields/rich-editor.js +10 -335
  29. package/dist/form/components/fields/rich-editor.js.map +1 -1
  30. package/dist/form/components/fields/table-rows.js +2 -2
  31. package/dist/form/index.js +37 -29
  32. package/dist/form/index.js.map +1 -1
  33. package/dist/index.d.ts +2 -2
  34. package/dist/index.js +4 -4
  35. package/dist/notifications/index.d.ts +1 -1
  36. package/dist/notifications/index.js +2 -2
  37. package/dist/notifications/index.js.map +1 -1
  38. package/dist/provider.js +4 -4
  39. package/dist/provider.js.map +1 -1
  40. package/dist/registry.d.ts +1 -1
  41. package/dist/registry.js +15 -2
  42. package/dist/registry.js.map +1 -0
  43. package/dist/table/components/cells/money-cell.js +1 -1
  44. package/dist/table/components/cells/number-cell.js +1 -1
  45. package/dist/table/components/table.js +1 -1
  46. package/dist/table/index.js +3 -2
  47. package/dist/table/index.js.map +1 -1
  48. package/package.json +8 -11
  49. package/dist/core/components/eager.d.ts +0 -1
  50. package/dist/core/components/eager.js +0 -50
  51. package/dist/core/components/eager.js.map +0 -1
  52. package/dist/form/components/fields/date-picker-control.js.map +0 -1
  53. package/dist/form/components/fields/lazy-date-picker-control.d.ts +0 -2
  54. package/dist/form/components/fields/lazy-date-picker-control.js +0 -17
  55. package/dist/form/components/fields/lazy-date-picker-control.js.map +0 -1
  56. package/dist/form/eager.d.ts +0 -1
  57. package/dist/form/eager.js +0 -47
  58. package/dist/form/eager.js.map +0 -1
  59. package/dist/form/skeleton.d.ts +0 -2
  60. package/dist/form/skeleton.js +0 -22
  61. package/dist/form/skeleton.js.map +0 -1
  62. package/dist/registry/eager.d.ts +0 -1
  63. package/dist/registry/eager.js +0 -15
  64. package/dist/registry/eager.js.map +0 -1
  65. package/dist/registry/lazy.d.ts +0 -1
  66. package/dist/registry/lazy.js +0 -15
  67. package/dist/registry/lazy.js.map +0 -1
  68. package/dist/table/eager.d.ts +0 -1
  69. package/dist/table/eager.js +0 -11
  70. package/dist/table/eager.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"renderer.js","names":[],"sources":["../../resources/js/core/renderer.tsx"],"sourcesContent":["import { Suspense } from \"react\";\nimport type { ReactNode } from \"react\";\nimport type { Node } from \"./types\";\nimport { useCollapsed } from \"./collapsed-context\";\nimport { useComponentRegistry } from \"./registry-context\";\n\nfunction MissingComponent({ node }: { node: Node }) {\n if (!import.meta.env.DEV) {\n return null;\n }\n\n return <div data-lattice-missing-component={node.type}>Missing component: {node.type}</div>;\n}\n\nfunction nodeKey(node: Node, index: number): string {\n return node.key ?? node.id ?? `${node.type}-${index}`;\n}\n\nexport function Renderer({ nodes }: { nodes: Node[] }): ReactNode {\n return nodes.map((node, index) => <NodeRenderer key={nodeKey(node, index)} node={node} />);\n}\n\nexport function RenderNode({ node }: { node: Node }): ReactNode {\n return <NodeRenderer node={node} />;\n}\n\nfunction NodeRenderer({ node }: { node: Node }) {\n const collapsed = useCollapsed();\n const registry = useComponentRegistry();\n const registration = registry[node.type];\n\n if (collapsed && node.props?.hideWhenCollapsed === true) {\n return null;\n }\n\n if (!registration) {\n return <MissingComponent node={node} />;\n }\n\n const Component = registration.component;\n const children = node.schema?.length ? <Renderer nodes={node.schema} /> : null;\n const renderedComponent = <Component node={node}>{children}</Component>;\n\n if (registration.mode === \"lazy\") {\n const FallbackComponent = registration.fallback;\n const fallback = FallbackComponent ? (\n <FallbackComponent node={node}>{null}</FallbackComponent>\n ) : null;\n\n return <Suspense fallback={fallback}>{renderedComponent}</Suspense>;\n }\n\n return renderedComponent;\n}\n"],"mappings":";;;;;AAMA,SAAS,iBAAiB,EAAE,QAAwB;CAEhD,OAAO;AAIX;AAEA,SAAS,QAAQ,MAAY,OAAuB;CAClD,OAAO,KAAK,OAAO,KAAK,MAAM,GAAG,KAAK,KAAK,GAAG;AAChD;AAEA,SAAgB,SAAS,EAAE,SAAuC;CAChE,OAAO,MAAM,KAAK,MAAM,UAAU,oBAAC,cAAD,EAA+C,KAAO,GAAnC,QAAQ,MAAM,KAAK,CAAgB,CAAC;AAC3F;AAEA,SAAgB,WAAW,EAAE,QAAmC;CAC9D,OAAO,oBAAC,cAAD,EAAoB,KAAO,CAAA;AACpC;AAEA,SAAS,aAAa,EAAE,QAAwB;CAC9C,MAAM,YAAY,aAAa;CAE/B,MAAM,eADW,qBACI,EAAS,KAAK;CAEnC,IAAI,aAAa,KAAK,OAAO,sBAAsB,MACjD,OAAO;CAGT,IAAI,CAAC,cACH,OAAO,oBAAC,kBAAD,EAAwB,KAAO,CAAA;CAGxC,MAAM,YAAY,aAAa;CAE/B,MAAM,oBAAoB,oBAAC,WAAD;EAAiB;EAAO,UADjC,KAAK,QAAQ,SAAS,oBAAC,UAAD,EAAU,OAAO,KAAK,OAAS,CAAA,IAAI;CACJ,CAAA;CAEtE,IAAI,aAAa,SAAS,QAAQ;EAChC,MAAM,oBAAoB,aAAa;EAKvC,OAAO,oBAAC,UAAD;GAAoB,UAJV,oBACf,oBAAC,mBAAD;IAAyB;cAAO;GAAwB,CAAA,IACtD;aAEkC;EAA4B,CAAA;CACpE;CAEA,OAAO;AACT"}
1
+ {"version":3,"file":"renderer.js","names":[],"sources":["../../resources/js/core/renderer.tsx"],"sourcesContent":["import { Suspense } from \"react\";\nimport type { ReactNode } from \"react\";\nimport type { Node } from \"./types\";\nimport { useCollapsed } from \"./collapsed-context\";\nimport { useComponentRegistry } from \"./registry-context\";\n\nconst warnedMissingTypes = new Set<string>();\n\nfunction warnMissingComponent(type: string): void {\n if (!import.meta.env.DEV || warnedMissingTypes.has(type)) {\n return;\n }\n\n warnedMissingTypes.add(type);\n console.warn(\n `[lattice] No component registered for node type \"${type}\" — Lattice rendered a fallback ` +\n \"placeholder. Likely causes: your app registry was not passed to \" +\n \"createLatticeApp({ registry }), or the registry key does not match the PHP \" +\n \"#[AsComponent]/AsField type.\",\n );\n}\n\nfunction MissingComponentIcon() {\n return (\n <svg\n aria-hidden=\"true\"\n className=\"size-lt-icon-md shrink-0\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n strokeWidth=\"2\"\n viewBox=\"0 0 24 24\"\n >\n <rect height=\"18\" rx=\"2\" strokeDasharray=\"4 3\" width=\"18\" x=\"3\" y=\"3\" />\n <path d=\"M12 8v4\" />\n <path d=\"M12 16h.01\" />\n </svg>\n );\n}\n\n/**\n * Fallback for a node whose type has no registered renderer. Always renders a\n * visible, muted marker — icon-only survives tight spots like table cells — so\n * the gap is never invisible. Shows the type inline in development; keeps it\n * screen-reader-only (plus a hover tooltip) in production.\n */\nfunction MissingComponent({ node }: { node: Node }) {\n warnMissingComponent(node.type);\n\n const label = `Missing component: ${node.type}`;\n\n return (\n <span\n className=\"inline-flex items-center gap-1.5 align-middle text-lt-muted-fg\"\n data-lattice-missing-component={node.type}\n title={label}\n >\n <MissingComponentIcon />\n <span className={import.meta.env.DEV ? \"text-sm\" : \"sr-only\"}>{label}</span>\n </span>\n );\n}\n\nfunction nodeKey(node: Node, index: number): string {\n return node.key ?? node.id ?? `${node.type}-${index}`;\n}\n\nexport function Renderer({ nodes }: { nodes: Node[] }): ReactNode {\n return nodes.map((node, index) => <NodeRenderer key={nodeKey(node, index)} node={node} />);\n}\n\nexport function RenderNode({ node }: { node: Node }): ReactNode {\n return <NodeRenderer node={node} />;\n}\n\nfunction NodeRenderer({ node }: { node: Node }) {\n const collapsed = useCollapsed();\n const registry = useComponentRegistry();\n const registration = registry[node.type];\n\n if (collapsed && node.props?.hideWhenCollapsed === true) {\n return null;\n }\n\n if (!registration) {\n return <MissingComponent node={node} />;\n }\n\n const Component = registration.component;\n const children = node.schema?.length ? <Renderer nodes={node.schema} /> : null;\n const renderedComponent = <Component node={node}>{children}</Component>;\n\n if (registration.mode === \"lazy\") {\n const FallbackComponent = registration.fallback;\n const fallback = FallbackComponent ? (\n <FallbackComponent node={node}>{null}</FallbackComponent>\n ) : null;\n\n return <Suspense fallback={fallback}>{renderedComponent}</Suspense>;\n }\n\n return renderedComponent;\n}\n"],"mappings":";;;;;AAsBA,SAAS,uBAAuB;CAC9B,OACE,qBAAC,OAAD;EACE,eAAY;EACZ,WAAU;EACV,MAAK;EACL,QAAO;EACP,eAAc;EACd,gBAAe;EACf,aAAY;EACZ,SAAQ;YARV;GAUE,oBAAC,QAAD;IAAM,QAAO;IAAK,IAAG;IAAI,iBAAgB;IAAM,OAAM;IAAK,GAAE;IAAI,GAAE;GAAK,CA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CAEA,OAAO;AACT"}
@@ -3,7 +3,7 @@ import { extendRegistry } from "./core/registry.js";
3
3
  import { setDefaultRegistry } from "./core/registry-context.js";
4
4
  import { createLayoutResolver, createPageResolver } from "./inertia.js";
5
5
  import { ProviderBase } from "./provider-base.js";
6
- import { lazyRegistry } from "./registry/lazy.js";
6
+ import { registry } from "./registry.js";
7
7
  import { createInertiaApp } from "@inertiajs/react";
8
8
  import { jsx } from "react/jsx-runtime";
9
9
  //#region resources/js/create-app.tsx
@@ -13,8 +13,8 @@ import { jsx } from "react/jsx-runtime";
13
13
  * registry, sprite, flash toasts via Lattice's own Toaster — and theme
14
14
  * initialization. Forwards any other createInertiaApp option.
15
15
  */
16
- function createLatticeApp({ registry, plugins, sprite, pages = {}, defaultLayout, strictMode = true, ...inertiaOptions } = {}) {
17
- const baseRegistry = registry ?? lazyRegistry;
16
+ function createLatticeApp({ registry: registry$1, plugins, sprite, pages = {}, defaultLayout, strictMode = true, ...inertiaOptions } = {}) {
17
+ const baseRegistry = registry$1 ?? registry;
18
18
  const activeRegistry = plugins && plugins.length > 0 ? extendRegistry(baseRegistry, ...plugins) : baseRegistry;
19
19
  setDefaultRegistry(activeRegistry);
20
20
  const app = createInertiaApp({
@@ -1 +1 @@
1
- {"version":3,"file":"create-app.js","names":[],"sources":["../resources/js/create-app.tsx"],"sourcesContent":["import { createInertiaApp } from \"@inertiajs/react\";\nimport type { ReactElement } from \"react\";\nimport { initializeTheme } from \"./appearance\";\nimport { extendRegistry, type Plugin, type Registry } from \"./core/registry\";\nimport { setDefaultRegistry } from \"./core/registry-context\";\nimport type { SpriteValue } from \"./icons/sprite\";\nimport {\n createLayoutResolver,\n createPageResolver,\n type CreateLayoutResolverOptions,\n type PageModules,\n} from \"./inertia\";\nimport { ProviderBase } from \"./provider-base\";\nimport { registry as defaultRegistry } from \"./registry\";\n\ntype InertiaAppOptions = NonNullable<Parameters<typeof createInertiaApp>[0]>;\n\nexport type CreateLatticeAppOptions = Omit<\n InertiaAppOptions,\n \"resolve\" | \"layout\" | \"setup\" | \"withApp\" | \"pages\"\n> & {\n registry?: Registry;\n /**\n * Component-package plugins to merge onto the registry — pass the\n * Composer-discovered `virtual:lattice/plugins` here to register vendor\n * components with no manual `extendRegistry` call.\n */\n plugins?: Plugin[];\n sprite?: SpriteValue;\n /** Normal Inertia page modules, e.g. `import.meta.glob('./pages/**\\/*.tsx')`. */\n pages?: PageModules;\n defaultLayout?: CreateLayoutResolverOptions[\"defaultLayout\"];\n};\n\n/**\n * Bootstrap an Inertia app with the Lattice shell: the page/layout resolvers\n * (server-driven Lattice pages and normal Inertia pages alike), the Provider —\n * registry, sprite, flash toasts via Lattice's own Toaster — and theme\n * initialization. Forwards any other createInertiaApp option.\n */\nexport function createLatticeApp({\n registry,\n plugins,\n sprite,\n pages = {},\n defaultLayout,\n strictMode = true,\n ...inertiaOptions\n}: CreateLatticeAppOptions = {}) {\n const baseRegistry = registry ?? defaultRegistry;\n const activeRegistry =\n plugins && plugins.length > 0 ? extendRegistry(baseRegistry, ...plugins) : baseRegistry;\n\n setDefaultRegistry(activeRegistry);\n\n const app = createInertiaApp({\n ...inertiaOptions,\n strictMode,\n resolve: createPageResolver(pages),\n layout: createLayoutResolver({ defaultLayout }),\n withApp: (node: ReactElement): ReactElement => (\n <ProviderBase registry={activeRegistry} sprite={sprite}>\n {node}\n </ProviderBase>\n ),\n });\n\n initializeTheme();\n\n return app;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAwCA,SAAgB,iBAAiB,EAC/B,UACA,SACA,QACA,QAAQ,CAAC,GACT,eACA,aAAa,MACb,GAAG,mBACwB,CAAC,GAAG;CAC/B,MAAM,eAAe,YAAY;CACjC,MAAM,iBACJ,WAAW,QAAQ,SAAS,IAAI,eAAe,cAAc,GAAG,OAAO,IAAI;CAE7E,mBAAmB,cAAc;CAEjC,MAAM,MAAM,iBAAiB;EAC3B,GAAG;EACH;EACA,SAAS,mBAAmB,KAAK;EACjC,QAAQ,qBAAqB,EAAE,cAAc,CAAC;EAC9C,UAAU,SACR,oBAAC,cAAD;GAAc,UAAU;GAAwB;aAC7C;EACW,CAAA;CAElB,CAAC;CAED,gBAAgB;CAEhB,OAAO;AACT"}
1
+ {"version":3,"file":"create-app.js","names":[],"sources":["../resources/js/create-app.tsx"],"sourcesContent":["import { createInertiaApp } from \"@inertiajs/react\";\nimport type { ReactElement } from \"react\";\nimport { initializeTheme } from \"./appearance\";\nimport { extendRegistry, type Plugin, type Registry } from \"./core/registry\";\nimport { setDefaultRegistry } from \"./core/registry-context\";\nimport type { SpriteValue } from \"./icons/sprite\";\nimport {\n createLayoutResolver,\n createPageResolver,\n type CreateLayoutResolverOptions,\n type PageModules,\n} from \"./inertia\";\nimport { ProviderBase } from \"./provider-base\";\nimport { registry as defaultRegistry } from \"./registry\";\n\ntype InertiaAppOptions = NonNullable<Parameters<typeof createInertiaApp>[0]>;\n\nexport type CreateLatticeAppOptions = Omit<\n InertiaAppOptions,\n \"resolve\" | \"layout\" | \"setup\" | \"withApp\" | \"pages\"\n> & {\n registry?: Registry;\n /**\n * Component-package plugins to merge onto the registry — pass the\n * Composer-discovered `virtual:lattice/plugins` here to register vendor\n * components with no manual `extendRegistry` call.\n */\n plugins?: Plugin[];\n sprite?: SpriteValue;\n /** Normal Inertia page modules, e.g. `import.meta.glob('./pages/**\\/*.tsx')`. */\n pages?: PageModules;\n defaultLayout?: CreateLayoutResolverOptions[\"defaultLayout\"];\n};\n\n/**\n * Bootstrap an Inertia app with the Lattice shell: the page/layout resolvers\n * (server-driven Lattice pages and normal Inertia pages alike), the Provider —\n * registry, sprite, flash toasts via Lattice's own Toaster — and theme\n * initialization. Forwards any other createInertiaApp option.\n */\nexport function createLatticeApp({\n registry,\n plugins,\n sprite,\n pages = {},\n defaultLayout,\n strictMode = true,\n ...inertiaOptions\n}: CreateLatticeAppOptions = {}) {\n const baseRegistry = registry ?? defaultRegistry;\n const activeRegistry =\n plugins && plugins.length > 0 ? extendRegistry(baseRegistry, ...plugins) : baseRegistry;\n\n setDefaultRegistry(activeRegistry);\n\n const app = createInertiaApp({\n ...inertiaOptions,\n strictMode,\n resolve: createPageResolver(pages),\n layout: createLayoutResolver({ defaultLayout }),\n withApp: (node: ReactElement): ReactElement => (\n <ProviderBase registry={activeRegistry} sprite={sprite}>\n {node}\n </ProviderBase>\n ),\n });\n\n initializeTheme();\n\n return app;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAwCA,SAAgB,iBAAiB,EAC/B,UAAA,YACA,SACA,QACA,QAAQ,CAAC,GACT,eACA,aAAa,MACb,GAAG,mBACwB,CAAC,GAAG;CAC/B,MAAM,eAAe,cAAY;CACjC,MAAM,iBACJ,WAAW,QAAQ,SAAS,IAAI,eAAe,cAAc,GAAG,OAAO,IAAI;CAE7E,mBAAmB,cAAc;CAEjC,MAAM,MAAM,iBAAiB;EAC3B,GAAG;EACH;EACA,SAAS,mBAAmB,KAAK;EACjC,QAAQ,qBAAqB,EAAE,cAAc,CAAC;EAC9C,UAAU,SACR,oBAAC,cAAD;GAAc,UAAU;GAAwB;aAC7C;EACW,CAAA;CAElB,CAAC;CAED,gBAAgB;CAEhB,OAAO;AACT"}
@@ -1,4 +1,4 @@
1
- import { LazyDatePickerControl } from "./lazy-date-picker-control.js";
1
+ import { DatePicker } from "./date-picker.js";
2
2
  import { SimpleField } from "./simple-field.js";
3
3
  import { jsx } from "react/jsx-runtime";
4
4
  //#region resources/js/form/components/fields/date-input.tsx
@@ -7,7 +7,7 @@ var DateInputComponent = ({ node }) => {
7
7
  return /* @__PURE__ */ jsx(SimpleField, {
8
8
  node,
9
9
  label: props.label ?? "",
10
- children: ({ name, testId, value, readOnly, disabled, change, blur }) => /* @__PURE__ */ jsx(LazyDatePickerControl, {
10
+ children: ({ name, testId, value, readOnly, disabled, change, blur }) => /* @__PURE__ */ jsx(DatePicker, {
11
11
  autoFocus: props.autoFocus ?? false,
12
12
  disabled,
13
13
  label: props.label ?? props.name,
@@ -1 +1 @@
1
- {"version":3,"file":"date-input.js","names":[],"sources":["../../../../resources/js/form/components/fields/date-input.tsx"],"sourcesContent":["import type { RendererComponent } from \"@lattice-php/lattice/core/types\";\nimport { LazyDatePickerControl } from \"./lazy-date-picker-control\";\nimport { SimpleField } from \"./simple-field\";\n\nexport const DateInputComponent: RendererComponent<\"field.date-input\"> = ({ node }) => {\n const props = node.props;\n\n return (\n <SimpleField node={node} label={props.label ?? \"\"}>\n {({ name, testId, value, readOnly, disabled, change, blur }) => (\n <LazyDatePickerControl\n autoFocus={props.autoFocus ?? false}\n disabled={disabled}\n label={props.label ?? props.name}\n max={props.max || undefined}\n min={props.min || undefined}\n mode=\"date\"\n name={name}\n onBlur={blur}\n onChange={change}\n readOnly={readOnly}\n tabIndex={props.tabIndex ?? undefined}\n testId={testId ?? props.name}\n value={value}\n />\n )}\n </SimpleField>\n );\n};\n"],"mappings":";;;;AAIA,IAAa,sBAA6D,EAAE,WAAW;CACrF,MAAM,QAAQ,KAAK;CAEnB,OACE,oBAAC,aAAD;EAAmB;EAAM,OAAO,MAAM,SAAS;aAC3C,EAAE,MAAM,QAAQ,OAAO,UAAU,UAAU,QAAQ,WACnD,oBAAC,uBAAD;GACE,WAAW,MAAM,aAAa;GACpB;GACV,OAAO,MAAM,SAAS,MAAM;GAC5B,KAAK,MAAM,OAAO,KAAA;GAClB,KAAK,MAAM,OAAO,KAAA;GAClB,MAAK;GACC;GACN,QAAQ;GACR,UAAU;GACA;GACV,UAAU,MAAM,YAAY,KAAA;GAC5B,QAAQ,UAAU,MAAM;GACjB;EACR,CAAA;CAEQ,CAAA;AAEjB"}
1
+ {"version":3,"file":"date-input.js","names":[],"sources":["../../../../resources/js/form/components/fields/date-input.tsx"],"sourcesContent":["import type { RendererComponent } from \"@lattice-php/lattice/core/types\";\nimport { DatePicker } from \"./date-picker\";\nimport { SimpleField } from \"./simple-field\";\n\nexport const DateInputComponent: RendererComponent<\"field.date-input\"> = ({ node }) => {\n const props = node.props;\n\n return (\n <SimpleField node={node} label={props.label ?? \"\"}>\n {({ name, testId, value, readOnly, disabled, change, blur }) => (\n <DatePicker\n autoFocus={props.autoFocus ?? false}\n disabled={disabled}\n label={props.label ?? props.name}\n max={props.max || undefined}\n min={props.min || undefined}\n mode=\"date\"\n name={name}\n onBlur={blur}\n onChange={change}\n readOnly={readOnly}\n tabIndex={props.tabIndex ?? undefined}\n testId={testId ?? props.name}\n value={value}\n />\n )}\n </SimpleField>\n );\n};\n"],"mappings":";;;;AAIA,IAAa,sBAA6D,EAAE,WAAW;CACrF,MAAM,QAAQ,KAAK;CAEnB,OACE,oBAAC,aAAD;EAAmB;EAAM,OAAO,MAAM,SAAS;aAC3C,EAAE,MAAM,QAAQ,OAAO,UAAU,UAAU,QAAQ,WACnD,oBAAC,YAAD;GACE,WAAW,MAAM,aAAa;GACpB;GACV,OAAO,MAAM,SAAS,MAAM;GAC5B,KAAK,MAAM,OAAO,KAAA;GAClB,KAAK,MAAM,OAAO,KAAA;GAClB,MAAK;GACC;GACN,QAAQ;GACR,UAAU;GACA;GACV,UAAU,MAAM,YAAY,KAAA;GAC5B,QAAQ,UAAU,MAAM;GACjB;EACR,CAAA;CAEQ,CAAA;AAEjB"}
@@ -1,4 +1,4 @@
1
- export type DatePickerControlProps = {
1
+ export type DatePickerFieldProps = {
2
2
  mode: "date" | "date-time";
3
3
  label: string;
4
4
  name: string;
@@ -15,4 +15,4 @@ export type DatePickerControlProps = {
15
15
  onChange: (value: string) => void;
16
16
  onBlur?: () => void;
17
17
  };
18
- export declare function DatePickerControl({ mode, label, name, testId, value, min, max, step, disabled, readOnly, autoFocus, tabIndex, timezone, onChange, onBlur, }: DatePickerControlProps): import("react").JSX.Element;
18
+ export declare function DatePickerField({ mode, label, name, testId, value, min, max, step, disabled, readOnly, autoFocus, tabIndex, timezone, onChange, onBlur, }: DatePickerFieldProps): import("react").JSX.Element;
@@ -10,8 +10,8 @@ import { createElement, useId, useMemo } from "react";
10
10
  import { jsx, jsxs } from "react/jsx-runtime";
11
11
  import * as datePicker from "@zag-js/date-picker";
12
12
  import { normalizeProps, useMachine } from "@zag-js/react";
13
- //#region resources/js/form/components/fields/date-picker-control.tsx
14
- function DatePickerControl({ mode, label, name, testId, value, min, max, step, disabled, readOnly, autoFocus = false, tabIndex, timezone = "UTC", onChange, onBlur }) {
13
+ //#region resources/js/form/components/fields/date-picker-field.tsx
14
+ function DatePickerField({ mode, label, name, testId, value, min, max, step, disabled, readOnly, autoFocus = false, tabIndex, timezone = "UTC", onChange, onBlur }) {
15
15
  const id = useId();
16
16
  const { locale } = useLocale();
17
17
  const selected = useMemo(() => [mode === "date" ? parseDateValue(value) : parseDateTimeValue(value, timezone)].filter(Boolean), [
@@ -192,6 +192,6 @@ function normalizeDateInputValue(value) {
192
192
  return `${compact.slice(0, 4)}-${compact.slice(4, 6)}-${compact.slice(6, 8)}`;
193
193
  }
194
194
  //#endregion
195
- export { DatePickerControl };
195
+ export { DatePickerField };
196
196
 
197
- //# sourceMappingURL=date-picker-control.js.map
197
+ //# sourceMappingURL=date-picker-field.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"date-picker-field.js","names":[],"sources":["../../../../resources/js/form/components/fields/date-picker-field.tsx"],"sourcesContent":["import type { DateValue } from \"@internationalized/date\";\nimport * as datePicker from \"@zag-js/date-picker\";\nimport { normalizeProps, useMachine } from \"@zag-js/react\";\nimport { useId, useMemo } from \"react\";\nimport { Button } from \"@lattice-php/lattice/core/components/button\";\nimport { Icon } from \"@lattice-php/lattice/icons\";\nimport { useLocale } from \"@lattice-php/lattice/i18n\";\nimport { cn } from \"@lattice-php/lattice/lib/utils\";\nimport { Input } from \"../base/input\";\nimport {\n formatDateDisplayValue,\n formatDateTimeDisplayValue,\n formatDateTimeValue,\n formatDateValue,\n formatTimeInputValue,\n parseDateDisplayValue,\n parseDateTimeDisplayValue,\n parseDateTimeValue,\n parseDateValue,\n} from \"./date-picker-value\";\nimport { TimePicker } from \"./time-picker\";\nimport { parseTimeString } from \"./time-picker-columns\";\n\nexport type DatePickerFieldProps = {\n mode: \"date\" | \"date-time\";\n label: string;\n name: string;\n testId: string;\n value: unknown;\n min?: string | null;\n max?: string | null;\n step?: number | null;\n disabled: boolean;\n readOnly: boolean;\n autoFocus?: boolean;\n tabIndex?: number | null;\n timezone?: string;\n onChange: (value: string) => void;\n onBlur?: () => void;\n};\n\nexport function DatePickerField({\n mode,\n label,\n name,\n testId,\n value,\n min,\n max,\n step,\n disabled,\n readOnly,\n autoFocus = false,\n tabIndex,\n timezone = \"UTC\",\n onChange,\n onBlur,\n}: DatePickerFieldProps) {\n const id = useId();\n const { locale } = useLocale();\n const selected = useMemo(\n () =>\n [mode === \"date\" ? parseDateValue(value) : parseDateTimeValue(value, timezone)].filter(\n Boolean,\n ) as DateValue[],\n [mode, timezone, value],\n );\n const service = useMachine(datePicker.machine, {\n id,\n name,\n value: selected.length > 0 ? selected : undefined,\n min: min ? parseDateValue(min) : undefined,\n max: max ? parseDateValue(max) : undefined,\n disabled,\n readOnly,\n locale,\n selectionMode: \"single\",\n timeZone: timezone,\n closeOnSelect: mode === \"date\",\n format(date) {\n return mode === \"date\"\n ? formatDateDisplayValue(date, locale)\n : formatDateTimeDisplayValue(date, locale, timezone);\n },\n parse(text) {\n return mode === \"date\"\n ? parseDateDisplayValue(text, locale)\n : parseDateTimeDisplayValue(text, locale, timezone);\n },\n onValueChange(details) {\n const next = details.value[0];\n\n onChange(mode === \"date\" ? formatDateValue(next) : formatDateTimeValue(next, timezone));\n },\n onOpenChange(details) {\n if (!details.open) {\n onBlur?.();\n }\n },\n });\n const api = datePicker.connect(service, normalizeProps);\n const { name: _inputName, onInput, ...inputProps } = api.getInputProps();\n const submittedValue =\n mode === \"date\" ? formatDateValue(selected[0]) : formatDateTimeValue(selected[0], timezone);\n\n return (\n <div {...api.getRootProps()} className={cn(\"relative\", api.open && \"z-lt-popover\")}>\n <input type=\"hidden\" name={name} value={submittedValue} data-test={`${testId}-value`} />\n <div {...api.getControlProps()} className=\"flex gap-2\">\n <Input\n {...inputProps}\n aria-label={label}\n autoFocus={autoFocus}\n data-test={testId}\n disabled={disabled}\n id={name}\n onInput={(event) => {\n onInput?.(event);\n\n if (mode !== \"date\") {\n return;\n }\n\n const normalized = normalizeDateInputValue(event.currentTarget.value);\n\n if (!normalized) {\n return;\n }\n\n const next = parseDateValue(normalized);\n\n if (!next) {\n return;\n }\n\n event.currentTarget.value = normalized;\n api.setValue([next]);\n event.currentTarget.value = formatDateDisplayValue(next, locale);\n onChange(formatDateValue(next));\n }}\n readOnly={readOnly}\n tabIndex={tabIndex ?? undefined}\n />\n <Button\n {...api.getTriggerProps()}\n aria-label={`Open ${label || name} calendar`}\n disabled={disabled || readOnly}\n size=\"icon\"\n type=\"button\"\n variant=\"secondary\"\n >\n <Icon name=\"calendar\" className=\"size-lt-icon-md\" aria-hidden=\"true\" />\n </Button>\n </div>\n {api.open ? (\n <div\n {...api.getPositionerProps()}\n className=\"absolute z-lt-popover mt-2 rounded-lt-sm border border-lt-border bg-lt-popover p-3 text-lt-popover-fg shadow-lt-md\"\n >\n <div {...api.getContentProps()} className=\"grid gap-3\">\n <div className=\"flex items-center justify-between gap-2\">\n <Button {...api.getPrevTriggerProps()} size=\"icon\" type=\"button\" variant=\"ghost\">\n <Icon name=\"chevron-left\" className=\"size-lt-icon-md\" aria-hidden=\"true\" />\n </Button>\n <div {...api.getRangeTextProps()} className=\"text-sm font-medium text-lt-fg\" />\n <Button {...api.getNextTriggerProps()} size=\"icon\" type=\"button\" variant=\"ghost\">\n <Icon name=\"chevron-right\" className=\"size-lt-icon-md\" aria-hidden=\"true\" />\n </Button>\n </div>\n <table {...api.getTableProps()} className=\"w-full border-collapse text-sm\">\n <thead {...api.getTableHeadProps()}>\n <tr {...api.getTableRowProps()}>\n {api.weekDays.map((day) => (\n <th\n {...api.getTableHeaderProps()}\n aria-label={day.long}\n key={day.value.toString()}\n className=\"size-8 text-center text-xs font-medium text-lt-muted-fg\"\n >\n {day.narrow}\n </th>\n ))}\n </tr>\n </thead>\n <tbody {...api.getTableBodyProps()}>\n {api.weeks.map((week, weekIndex) => (\n <tr {...api.getTableRowProps()} key={weekIndex}>\n {week.map((day) => {\n const state = api.getDayTableCellState({ value: day });\n\n return (\n <td\n {...api.getDayTableCellProps({ value: day })}\n key={day.toString()}\n className=\"p-0 text-center\"\n >\n <button\n {...api.getDayTableCellTriggerProps({ value: day })}\n type=\"button\"\n className={cn(\n \"size-8 rounded-lt-sm text-sm text-lt-fg hover:bg-lt-muted\",\n state.selected && \"bg-lt-primary text-lt-primary-fg\",\n state.outsideRange && \"text-lt-muted-fg\",\n state.disabled && \"cursor-not-allowed opacity-40\",\n )}\n >\n {day.day}\n </button>\n </td>\n );\n })}\n </tr>\n ))}\n </tbody>\n </table>\n {mode === \"date-time\" ? (\n <TimePicker\n value={parseTimeString(formatTimeInputValue(selected[0], timezone))}\n onChange={(next) =>\n api.setTime({ hour: next.hour, minute: next.minute, second: next.second })\n }\n step={step}\n disabled={disabled}\n readOnly={readOnly}\n testId={`${testId}-time`}\n />\n ) : null}\n </div>\n </div>\n ) : null}\n </div>\n );\n}\n\nfunction normalizeDateInputValue(value: string): string | undefined {\n const compact = value.replace(/\\D/g, \"\");\n\n if (compact.length !== 8) {\n return undefined;\n }\n\n return `${compact.slice(0, 4)}-${compact.slice(4, 6)}-${compact.slice(6, 8)}`;\n}\n"],"mappings":";;;;;;;;;;;;;AAyCA,SAAgB,gBAAgB,EAC9B,MACA,OACA,MACA,QACA,OACA,KACA,KACA,MACA,UACA,UACA,YAAY,OACZ,UACA,WAAW,OACX,UACA,UACuB;CACvB,MAAM,KAAK,MAAM;CACjB,MAAM,EAAE,WAAW,UAAU;CAC7B,MAAM,WAAW,cAEb,CAAC,SAAS,SAAS,eAAe,KAAK,IAAI,mBAAmB,OAAO,QAAQ,CAAC,EAAE,OAC9E,OACF,GACF;EAAC;EAAM;EAAU;CAAK,CACxB;CACA,MAAM,UAAU,WAAW,WAAW,SAAS;EAC7C;EACA;EACA,OAAO,S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date-picker-field';
2
+ export declare function DatePicker(props: DatePickerFieldProps): import("react").JSX.Element;
@@ -0,0 +1,17 @@
1
+ import { Suspense, lazy } from "react";
2
+ import { jsx } from "react/jsx-runtime";
3
+ //#region resources/js/form/components/fields/date-picker.tsx
4
+ var DatePickerField = lazy(async () => {
5
+ const { DatePickerField } = await import("./date-picker-field.js");
6
+ return { default: DatePickerField };
7
+ });
8
+ function DatePicker(props) {
9
+ return /* @__PURE__ */ jsx(Suspense, {
10
+ fallback: null,
11
+ children: /* @__PURE__ */ jsx(DatePickerField, { ...props })
12
+ });
13
+ }
14
+ //#endregion
15
+ export { DatePicker };
16
+
17
+ //# sourceMappingURL=date-picker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"date-picker.js","names":[],"sources":["../../../../resources/js/form/components/fields/date-picker.tsx"],"sourcesContent":["import { lazy, Suspense } from \"react\";\nimport type { DatePickerFieldProps } from \"./date-picker-field\";\n\nconst DatePickerField = lazy(async () => {\n const { DatePickerField } = await import(\"./date-picker-field\");\n\n return { default: DatePickerField };\n});\n\nexport function DatePicker(props: DatePickerFieldProps) {\n return (\n <Suspense fallback={null}>\n <DatePickerField {...props} />\n </Suspense>\n );\n}\n"],"mappings":";;;AAGA,IAAM,kBAAkB,KAAK,YAAY;CACvC,MAAM,EAAE,oBAAoB,MAAM,OAAO;CAEzC,OAAO,EAAE,SAAS,gBAAgB;AACpC,CAAC;AAED,SAAgB,WAAW,OAA6B;CACtD,OACE,oBAAC,UAAD;EAAU,UAAU;YAClB,oBAAC,iBAAD,EAAiB,GAAI,MAAQ,CAAA;CACrB,CAAA;AAEd"}
@@ -1,5 +1,5 @@
1
1
  import { useTimezone } from "../../../i18n/timezone.js";
2
- import { LazyDatePickerControl } from "./lazy-date-picker-control.js";
2
+ import { DatePicker } from "./date-picker.js";
3
3
  import { SimpleField } from "./simple-field.js";
4
4
  import { jsx } from "react/jsx-runtime";
5
5
  //#region resources/js/form/components/fields/date-time-input.tsx
@@ -9,7 +9,7 @@ var DateTimeInputComponent = ({ node }) => {
9
9
  return /* @__PURE__ */ jsx(SimpleField, {
10
10
  node,
11
11
  label: props.label ?? "",
12
- children: ({ name, testId, value, readOnly, disabled, change, blur }) => /* @__PURE__ */ jsx(LazyDatePickerControl, {
12
+ children: ({ name, testId, value, readOnly, disabled, change, blur }) => /* @__PURE__ */ jsx(DatePicker, {
13
13
  autoFocus: props.autoFocus ?? false,
14
14
  disabled,
15
15
  label: props.label ?? props.name,
@@ -1 +1 @@
1
- {"version":3,"file":"date-time-input.js","names":[],"sources":["../../../../resources/js/form/components/fields/date-time-input.tsx"],"sourcesContent":["import type { RendererComponent } from \"@lattice-php/lattice/core/types\";\nimport { useTimezone } from \"@lattice-php/lattice/i18n\";\nimport { LazyDatePickerControl } from \"./lazy-date-picker-control\";\nimport { SimpleField } from \"./simple-field\";\n\nexport const DateTimeInputComponent: RendererComponent<\"field.date-time-input\"> = ({ node }) => {\n const props = node.props;\n const { timezone } = useTimezone();\n\n return (\n <SimpleField node={node} label={props.label ?? \"\"}>\n {({ name, testId, value, readOnly, disabled, change, blur }) => (\n <LazyDatePickerControl\n autoFocus={props.autoFocus ?? false}\n disabled={disabled}\n label={props.label ?? props.name}\n max={props.max}\n min={props.min}\n mode=\"date-time\"\n name={name}\n onBlur={blur}\n onChange={change}\n readOnly={readOnly}\n step={props.step}\n tabIndex={props.tabIndex ?? undefined}\n testId={testId ?? props.name}\n timezone={timezone}\n value={value}\n />\n )}\n </SimpleField>\n );\n};\n"],"mappings":";;;;;AAKA,IAAa,0BAAsE,EAAE,WAAW;CAC9F,MAAM,QAAQ,KAAK;CACnB,MAAM,EAAE,aAAa,YAAY;CAEjC,OACE,oBAAC,aAAD;EAAmB;EAAM,OAAO,MAAM,SAAS;aAC3C,EAAE,MAAM,QAAQ,OAAO,UAAU,UAAU,QAAQ,WACnD,oBAAC,uBAAD;GACE,WAAW,MAAM,aAAa;GACpB;GACV,OAAO,MAAM,SAAS,MAAM;GAC5B,KAAK,MAAM;GACX,KAAK,MAAM;GACX,MAAK;GACC;GACN,QAAQ;GACR,UAAU;GACA;GACV,MAAM,MAAM;GACZ,UAAU,MAAM,YAAY,KAAA;GAC5B,QAAQ,UAAU,MAAM;GACd;GACH;EACR,CAAA;CAEQ,CAAA;AAEjB"}
1
+ {"version":3,"file":"date-time-input.js","names":[],"sources":["../../../../resources/js/form/components/fields/date-time-input.tsx"],"sourcesContent":["import type { RendererComponent } from \"@lattice-php/lattice/core/types\";\nimport { useTimezone } from \"@lattice-php/lattice/i18n\";\nimport { DatePicker } from \"./date-picker\";\nimport { SimpleField } from \"./simple-field\";\n\nexport const DateTimeInputComponent: RendererComponent<\"field.date-time-input\"> = ({ node }) => {\n const props = node.props;\n const { timezone } = useTimezone();\n\n return (\n <SimpleField node={node} label={props.label ?? \"\"}>\n {({ name, testId, value, readOnly, disabled, change, blur }) => (\n <DatePicker\n autoFocus={props.autoFocus ?? false}\n disabled={disabled}\n label={props.label ?? props.name}\n max={props.max}\n min={props.min}\n mode=\"date-time\"\n name={name}\n onBlur={blur}\n onChange={change}\n readOnly={readOnly}\n step={props.step}\n tabIndex={props.tabIndex ?? undefined}\n testId={testId ?? props.name}\n timezone={timezone}\n value={value}\n />\n )}\n </SimpleField>\n );\n};\n"],"mappings":";;;;;AAKA,IAAa,0BAAsE,EAAE,WAAW;CAC9F,MAAM,QAAQ,KAAK;CACnB,MAAM,EAAE,aAAa,YAAY;CAEjC,OACE,oBAAC,aAAD;EAAmB;EAAM,OAAO,MAAM,SAAS;aAC3C,EAAE,MAAM,QAAQ,OAAO,UAAU,UAAU,QAAQ,WACnD,oBAAC,YAAD;GACE,WAAW,MAAM,aAAa;GACpB;GACV,OAAO,MAAM,SAAS,MAAM;GAC5B,KAAK,MAAM;GACX,KAAK,MAAM;GACX,MAAK;GACC;GACN,QAAQ;GACR,UAAU;GACA;GACV,MAAM,MAAM;GACZ,UAAU,MAAM,YAAY,KAAA;GAC5B,QAAQ,UAAU,MAAM;GACd;GACH;EACR,CAAA;CAEQ,CAAA;AAEjB"}
@@ -0,0 +1,3 @@
1
+ import { RendererComponent } from '../../../core/types';
2
+ declare const RichEditorField: RendererComponent<"field.rich-editor">;
3
+ export default RichEditorField;
@@ -0,0 +1,340 @@
1
+ import { cn } from "../../../lib/utils.js";
2
+ import { Icon } from "../../../icons/sprite.js";
3
+ import { useT } from "../../../i18n/instance.js";
4
+ import { useFormContext } from "../context.js";
5
+ import { useFieldScope } from "../field-scope.js";
6
+ import { useFormValue } from "../values.js";
7
+ import { FormFieldFrame } from "../base/field.js";
8
+ import { useDependentField } from "../use-dependent-field.js";
9
+ import { useFieldCommit } from "../use-field-commit.js";
10
+ import { useEffect, useState } from "react";
11
+ import { jsx, jsxs } from "react/jsx-runtime";
12
+ import { Details, DetailsContent, DetailsSummary } from "@tiptap/extension-details";
13
+ import { Highlight } from "@tiptap/extension-highlight";
14
+ import { Link } from "@tiptap/extension-link";
15
+ import { TableKit } from "@tiptap/extension-table";
16
+ import { TextAlign } from "@tiptap/extension-text-align";
17
+ import { EditorContent, useEditor } from "@tiptap/react";
18
+ import { StarterKit } from "@tiptap/starter-kit";
19
+ //#region resources/js/form/components/fields/rich-editor-field.tsx
20
+ var toolbar = [
21
+ {
22
+ icon: "bold",
23
+ key: "bold",
24
+ label: "Bold",
25
+ isActive: (e) => e.isActive("bold"),
26
+ run: (e) => e.chain().focus().toggleBold().run()
27
+ },
28
+ {
29
+ icon: "italic",
30
+ key: "italic",
31
+ label: "Italic",
32
+ isActive: (e) => e.isActive("italic"),
33
+ run: (e) => e.chain().focus().toggleItalic().run()
34
+ },
35
+ {
36
+ icon: "strikethrough",
37
+ key: "strikethrough",
38
+ label: "Strikethrough",
39
+ isActive: (e) => e.isActive("strike"),
40
+ run: (e) => e.chain().focus().toggleStrike().run()
41
+ },
42
+ {
43
+ icon: "underline",
44
+ key: "underline",
45
+ label: "Underline",
46
+ isActive: (e) => e.isActive("underline"),
47
+ run: (e) => e.chain().focus().toggleUnderline().run()
48
+ },
49
+ {
50
+ icon: "highlighter",
51
+ key: "highlight",
52
+ label: "Highlight",
53
+ isActive: (e) => e.isActive("highlight"),
54
+ run: (e) => e.chain().focus().toggleHighlight().run()
55
+ },
56
+ "separator",
57
+ {
58
+ icon: "heading-1",
59
+ key: "heading-1",
60
+ label: "Heading 1",
61
+ isActive: (e) => e.isActive("heading", { level: 1 }),
62
+ run: (e) => e.chain().focus().toggleHeading({ level: 1 }).run()
63
+ },
64
+ {
65
+ icon: "heading-2",
66
+ key: "heading-2",
67
+ label: "Heading 2",
68
+ isActive: (e) => e.isActive("heading", { level: 2 }),
69
+ run: (e) => e.chain().focus().toggleHeading({ level: 2 }).run()
70
+ },
71
+ {
72
+ icon: "heading-3",
73
+ key: "heading-3",
74
+ label: "Heading 3",
75
+ isActive: (e) => e.isActive("heading", { level: 3 }),
76
+ run: (e) => e.chain().focus().toggleHeading({ level: 3 }).run()
77
+ },
78
+ "separator",
79
+ {
80
+ icon: "list",
81
+ key: "bullet-list",
82
+ label: "Bullet list",
83
+ isActive: (e) => e.isActive("bulletList"),
84
+ run: (e) => e.chain().focus().toggleBulletList().run()
85
+ },
86
+ {
87
+ icon: "list-ordered",
88
+ key: "ordered-list",
89
+ label: "Ordered list",
90
+ isActive: (e) => e.isActive("orderedList"),
91
+ run: (e) => e.chain().focus().toggleOrderedList().run()
92
+ },
93
+ {
94
+ icon: "quote",
95
+ key: "blockquote",
96
+ label: "Blockquote",
97
+ isActive: (e) => e.isActive("blockquote"),
98
+ run: (e) => e.chain().focus().toggleBlockquote().run()
99
+ },
100
+ {
101
+ icon: "code",
102
+ key: "code-block",
103
+ label: "Code block",
104
+ isActive: (e) => e.isActive("codeBlock"),
105
+ run: (e) => e.chain().focus().toggleCodeBlock().run()
106
+ },
107
+ {
108
+ icon: "minus",
109
+ key: "horizontal-rule",
110
+ label: "Horizontal rule",
111
+ isActive: () => false,
112
+ run: (e) => e.chain().focus().setHorizontalRule().run()
113
+ },
114
+ "separator",
115
+ {
116
+ icon: "align-left",
117
+ key: "align-left",
118
+ label: "Align left",
119
+ isActive: (e) => e.isActive({ textAlign: "left" }),
120
+ run: (e) => e.chain().focus().setTextAlign("left").run()
121
+ },
122
+ {
123
+ icon: "align-center",
124
+ key: "align-center",
125
+ label: "Align center",
126
+ isActive: (e) => e.isActive({ textAlign: "center" }),
127
+ run: (e) => e.chain().focus().setTextAlign("center").run()
128
+ },
129
+ {
130
+ icon: "align-right",
131
+ key: "align-right",
132
+ label: "Align right",
133
+ isActive: (e) => e.isActive({ textAlign: "right" }),
134
+ run: (e) => e.chain().focus().setTextAlign("right").run()
135
+ },
136
+ {
137
+ icon: "align-justify",
138
+ key: "justify",
139
+ label: "Justify",
140
+ isActive: (e) => e.isActive({ textAlign: "justify" }),
141
+ run: (e) => e.chain().focus().setTextAlign("justify").run()
142
+ },
143
+ "separator",
144
+ {
145
+ icon: "link",
146
+ key: "link",
147
+ label: "Link",
148
+ isActive: (e) => e.isActive("link"),
149
+ run: (e) => {
150
+ if (e.isActive("link")) {
151
+ e.chain().focus().unsetLink().run();
152
+ return;
153
+ }
154
+ const url = window.prompt("Link URL");
155
+ if (url) e.chain().focus().extendMarkRange("link").setLink({ href: url }).run();
156
+ }
157
+ },
158
+ "separator",
159
+ {
160
+ icon: "table",
161
+ key: "insert-table",
162
+ label: "Insert table",
163
+ isActive: (e) => e.isActive("table"),
164
+ run: (e) => e.chain().focus().insertTable({
165
+ rows: 3,
166
+ cols: 3,
167
+ withHeaderRow: true
168
+ }).run()
169
+ },
170
+ {
171
+ icon: "columns-3",
172
+ key: "add-column",
173
+ label: "Add column",
174
+ isActive: () => false,
175
+ isDisabled: (e) => !e.can().addColumnAfter(),
176
+ run: (e) => e.chain().focus().addColumnAfter().run()
177
+ },
178
+ {
179
+ icon: "rows-3",
180
+ key: "add-row",
181
+ label: "Add row",
182
+ isActive: () => false,
183
+ isDisabled: (e) => !e.can().addRowAfter(),
184
+ run: (e) => e.chain().focus().addRowAfter().run()
185
+ },
186
+ {
187
+ icon: "trash-2",
188
+ key: "delete-table",
189
+ label: "Delete table",
190
+ isActive: () => false,
191
+ isDisabled: (e) => !e.can().deleteTable(),
192
+ run: (e) => e.chain().focus().deleteTable().run()
193
+ },
194
+ {
195
+ icon: "chevron-right",
196
+ key: "details",
197
+ label: "Details",
198
+ isActive: (e) => e.isActive("details"),
199
+ run: (e) => {
200
+ if (e.isActive("details")) {
201
+ e.chain().focus().unsetDetails().run();
202
+ return;
203
+ }
204
+ e.chain().focus().setDetails().run();
205
+ }
206
+ }
207
+ ];
208
+ var emojis = [
209
+ "😀",
210
+ "😅",
211
+ "😂",
212
+ "🥳",
213
+ "😎",
214
+ "🤔",
215
+ "👍",
216
+ "🙏",
217
+ "🔥",
218
+ "🎉",
219
+ "🚀",
220
+ "💡",
221
+ "✅",
222
+ "❌",
223
+ "⭐",
224
+ "❤️"
225
+ ];
226
+ function EmojiPicker({ editor }) {
227
+ const { t } = useT("lattice");
228
+ const [open, setOpen] = useState(false);
229
+ return /* @__PURE__ */ jsxs("div", {
230
+ className: "relative",
231
+ children: [/* @__PURE__ */ jsx("button", {
232
+ "aria-label": t("form.editor.insert-emoji", "Insert emoji"),
233
+ "data-test": "editor-emoji",
234
+ className: "inline-flex size-7 items-center justify-center rounded-lt-sm text-lt-muted-fg transition-colors hover:bg-lt-accent hover:text-lt-accent-fg [&_svg]:size-lt-icon-md",
235
+ onClick: () => setOpen((value) => !value),
236
+ onMouseDown: (event) => event.preventDefault(),
237
+ title: t("form.editor.insert-emoji", "Insert emoji"),
238
+ type: "button",
239
+ children: /* @__PURE__ */ jsx(Icon, { name: "smile" })
240
+ }), open && /* @__PURE__ */ jsx("div", {
241
+ className: "absolute z-lt-dropdown mt-1 grid grid-cols-8 gap-0.5 rounded-lt-sm border border-lt-border bg-lt-bg p-1 shadow-lt-md",
242
+ children: emojis.map((emoji) => /* @__PURE__ */ jsx("button", {
243
+ className: "inline-flex size-7 items-center justify-center rounded-lt-sm text-base hover:bg-lt-accent",
244
+ onClick: () => {
245
+ editor.chain().focus().insertContent(emoji).run();
246
+ setOpen(false);
247
+ },
248
+ onMouseDown: (event) => event.preventDefault(),
249
+ type: "button",
250
+ children: emoji
251
+ }, emoji))
252
+ })]
253
+ });
254
+ }
255
+ function Toolbar({ editor }) {
256
+ const { t } = useT("lattice");
257
+ return /* @__PURE__ */ jsxs("div", {
258
+ className: "flex flex-wrap items-center gap-0.5 border-b border-lt-border p-1",
259
+ children: [
260
+ toolbar.map((item, index) => {
261
+ if (item === "separator") return /* @__PURE__ */ jsx("span", { className: "mx-1 h-5 w-px bg-lt-border" }, `sep-${index}`);
262
+ const label = t(`form.editor.${item.key}`, item.label);
263
+ return /* @__PURE__ */ jsx("button", {
264
+ "aria-label": label,
265
+ "aria-pressed": item.isActive(editor),
266
+ "data-test": `editor-${item.key}`,
267
+ className: cn("inline-flex size-7 items-center justify-center rounded-lt-sm text-lt-muted-fg transition-colors hover:bg-lt-accent hover:text-lt-accent-fg disabled:pointer-events-none disabled:opacity-40 [&_svg]:size-lt-icon-md", item.isActive(editor) && "bg-lt-accent text-lt-accent-fg"),
268
+ disabled: item.isDisabled?.(editor) ?? false,
269
+ onClick: () => item.run(editor),
270
+ onMouseDown: (event) => event.preventDefault(),
271
+ title: label,
272
+ type: "button",
273
+ children: /* @__PURE__ */ jsx(Icon, { name: item.icon })
274
+ }, item.key);
275
+ }),
276
+ /* @__PURE__ */ jsx("span", { className: "mx-1 h-5 w-px bg-lt-border" }),
277
+ /* @__PURE__ */ jsx(EmojiPicker, { editor })
278
+ ]
279
+ });
280
+ }
281
+ var RichEditorField = ({ node }) => {
282
+ const { errors } = useFormContext();
283
+ const { hidden, required, readOnly, disabled } = useDependentField(node);
284
+ const { change, blur } = useFieldCommit();
285
+ const name = node.props.name;
286
+ const scope = useFieldScope();
287
+ const globalValue = useFormValue(name);
288
+ const storedValue = scope ? scope.getValue(name) : globalValue;
289
+ const domName = scope ? scope.scopedName(name) : name;
290
+ const errorKey = scope ? scope.errorKey(name) : name;
291
+ const locked = readOnly || disabled;
292
+ const initialContent = typeof storedValue === "object" && storedValue !== null ? storedValue : node.props.value ?? "";
293
+ const editor = useEditor({
294
+ extensions: [
295
+ StarterKit,
296
+ Highlight,
297
+ TextAlign.configure({ types: ["heading", "paragraph"] }),
298
+ Link.configure({ openOnClick: false }),
299
+ TableKit.configure({ table: { resizable: false } }),
300
+ Details,
301
+ DetailsSummary,
302
+ DetailsContent
303
+ ],
304
+ content: initialContent,
305
+ editable: !locked,
306
+ immediatelyRender: false,
307
+ editorProps: { attributes: { class: "lattice-prose min-h-32 px-3 py-2 outline-none" } },
308
+ onUpdate: ({ editor: instance }) => {
309
+ change(name, instance.isEmpty ? null : instance.getJSON());
310
+ },
311
+ onBlur: () => {
312
+ blur(name);
313
+ }
314
+ });
315
+ useEffect(() => {
316
+ editor?.setEditable(!locked);
317
+ }, [editor, locked]);
318
+ if (hidden) return null;
319
+ const submittedValue = storedValue ? JSON.stringify(storedValue) : "";
320
+ return /* @__PURE__ */ jsxs(FormFieldFrame, {
321
+ error: errors[errorKey],
322
+ helperText: node.props.helperText ?? void 0,
323
+ tooltip: node.props.tooltip ?? void 0,
324
+ label: node.props.label ?? "",
325
+ name: domName,
326
+ required,
327
+ children: [/* @__PURE__ */ jsxs("div", {
328
+ className: cn("overflow-hidden rounded-lt-sm border border-lt-input bg-transparent shadow-lt-xs focus-within:border-lt-ring focus-within:ring-[3px] focus-within:ring-lt-ring/50", locked && "opacity-60"),
329
+ children: [editor && !locked && /* @__PURE__ */ jsx(Toolbar, { editor }), /* @__PURE__ */ jsx(EditorContent, { editor })]
330
+ }), /* @__PURE__ */ jsx("input", {
331
+ name: domName,
332
+ type: "hidden",
333
+ value: submittedValue
334
+ })]
335
+ });
336
+ };
337
+ //#endregion
338
+ export { RichEditorField as default };
339
+
340
+ //# sourceMappingURL=rich-editor-field.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rich-editor-field.js","names":[],"sources":["../../../../resources/js/form/components/fields/rich-editor-field.tsx"],"sourcesContent":["import { Icon } from \"@lattice-php/lattice/icons\";\nimport { Details, DetailsContent, DetailsSummary } from \"@tiptap/extension-details\";\nimport { Highlight } from \"@tiptap/extension-highlight\";\nimport { Link } from \"@tiptap/extension-link\";\nimport { TableKit } from \"@tiptap/extension-table\";\nimport { TextAlign } from \"@tiptap/extension-text-align\";\nimport { type Editor, EditorContent, useEditor } from \"@tiptap/react\";\nimport { StarterKit } from \"@tiptap/starter-kit\";\nimport { useEffect, useState } from \"react\";\nimport { cn } from \"@lattice-php/lattice/lib/utils\";\nimport { useT } from \"@lattice-php/lattice/i18n\";\nimport type { RendererComponent } from \"@lattice-php/lattice/core/types\";\nimport { FormFieldFrame } from \"../base/field\";\nimport { useFormContext } from \"../context\";\nimport { useFieldScope } from \"../field-scope\";\nimport { useDependentField } from \"../use-dependent-field\";\nimport { useFieldCommit } from \"../use-field-commit\";\nimport { useFormValue } from \"../values\";\n\ntype ToolbarItem =\n | \"separator\"\n | {\n icon: string;\n key: string;\n label: string;\n isActive: (editor: Editor) => boolean;\n isDisabled?: (editor: Editor) => boolean;\n run: (editor: Editor) => void;\n };\n\nconst toolbar: ToolbarItem[] = [\n {\n icon: \"bold\",\n key: \"bold\",\n label: \"Bold\",\n isActive: (e) => e.isActive(\"bold\"),\n run: (e) => e.chain().focus().toggleBold().run(),\n },\n {\n icon: \"italic\",\n key: \"italic\",\n label: \"Italic\",\n isActive: (e) => e.isActive(\"italic\"),\n run: (e) => e.chain().focus().toggleItalic().run(),\n },\n {\n icon: \"strikethrough\",\n key: \"strikethrough\",\n label: \"Strikethrough\",\n isActive: (e) => e.isActive(\"strike\"),\n run: (e) => e.chain().focus().toggleStrike().run(),\n },\n {\n icon: \"underline\",\n key: \"underline\",\n label: \"Underline\",\n isActive: (e) => e.isActive(\"underline\"),\n run: (e) => e.chain().focus().toggleUnderline().run(),\n },\n {\n icon: \"highlighter\",\n key: \"highlight\",\n label: \"Highlight\",\n isActive: (e) => e.isActive(\"highlight\"),\n run: (e) => e.chain().focus().toggleHighlight().run(),\n },\n \"separator\",\n {\n icon: \"heading-1\",\n key: \"heading-1\",\n label: \"Heading 1\",\n isActive: (e) => e.isActive(\"heading\", { level: 1 }),\n run: (e) => e.chain().focus().toggleHeading({ level: 1 }).run(),\n },\n {\n icon: \"heading-2\",\n key: \"heading-2\",\n label: \"Heading 2\",\n isActive: (e) => e.isActive(\"heading\", { level: 2 }),\n run: (e) => e.chain().focus().toggleHeading({ level: 2 }).run(),\n },\n {\n icon: \"heading-3\",\n key: \"heading-3\",\n label: \"Heading 3\",\n isActive: (e) => e.isActive(\"heading\", { level: 3 }),\n run: (e) => e.chain().focus().toggleHeading({ level: 3 }).run(),\n },\n \"separator\",\n {\n icon: \"list\",\n key: \"bullet-list\",\n label: \"Bullet list\",\n isActive: (e) => e.isActive(\"bulletList\"),\n run: (e) => e.chain().focus().toggleBulletList().run(),\n },\n {\n icon: \"list-ordered\",\n key: \"ordered-list\",\n label: \"Ordered list\",\n isActive: (e) => e.isActive(\"orderedList\"),\n run: (e) => e.chain().focus().toggleOrderedList().run(),\n },\n {\n icon: \"quote\",\n key: \"blockquote\",\n label: \"Blockquote\",\n isActive: (e) => e.isActive(\"blockquote\"),\n run: (e) => e.chain().focus().toggleBlockquote().run(),\n },\n {\n icon: \"code\",\n key: \"code-block\",\n label: \"Code block\",\n isActive: (e) => e.isActive(\"codeBlock\"),\n run: (e) => e.chain().focus().toggleCodeBlock().run(),\n },\n {\n icon: \"minus\",\n key: \"horizontal-rule\",\n label: \"Horizontal rule\",\n isActive: () => false,\n run: (e) => e.chain().focus().setHorizontalRule().run(),\n },\n \"separator\",\n {\n icon: \"align-left\",\n key: \"align-left\",\n label: \"Align left\",\n isActive: (e) => e.isActive({ textAlign: \"left\" }),\n run: (e) => e.chain().focus().setTextAlign(\"left\").run(),\n },\n {\n icon: \"align-center\",\n key: \"align-center\",\n label: \"Align center\",\n isActive: (e) => e.isActive({ textAlign: \"center\" }),\n run: (e) => e.chain().focus().setTextAlign(\"center\").run(),\n },\n {\n icon: \"align-right\",\n key: \"align-right\",\n label: \"Align right\",\n isActive: (e) => e.isActive({ textAlign: \"right\" }),\n run: (e) => e.chain().focus().setTextAlign(\"right\").run(),\n },\n {\n icon: \"align-justify\",\n key: \"justify\",\n label: \"Justify\",\n isActive: (e) => e.isActive({ textAlign: \"justify\" }),\n run: (e) => e.chain().focus().setTextAlign(\"justify\").run(),\n },\n \"separator\",\n {\n icon: \"link\",\n key: \"link\",\n label: \"Link\",\n isActive: (e) => e.isActive(\"link\"),\n run: (e) => {\n if (e.isActive(\"link\")) {\n e.chain().focus().unsetLink().run();\n return;\n }\n const url = window.prompt(\"Link URL\");\n if (url) {\n e.chain().focus().extendMarkRange(\"link\").setLink({ href: url }).run();\n }\n },\n },\n \"separator\",\n {\n icon: \"table\",\n key: \"insert-table\",\n label: \"Insert table\",\n isActive: (e) => e.isActive(\"table\"),\n run: (e) => e.chain().focus().insertTable({ rows: 3, cols: 3, withHeaderRow: true }).run(),\n },\n {\n icon: \"columns-3\",\n key: \"add-column\",\n label: \"Add column\",\n isActive: () => false,\n isDisabled: (e) => !e.can().addColumnAfter(),\n run: (e) => e.chain().focus().addColumnAfter().run(),\n },\n {\n icon: \"rows-3\",\n key: \"add-row\",\n label: \"Add row\",\n isActive: () => false,\n isDisabled: (e) => !e.can().addRowAfter(),\n run: (e) => e.chain().focus().addRowAfter().run(),\n },\n {\n icon: \"trash-2\",\n key: \"delete-table\",\n label: \"Delete table\",\n isActive: () => false,\n isDisabled: (e) => !e.can().deleteTable(),\n run: (e) => e.chain().focus().deleteTable().run(),\n },\n {\n icon: \"chevron-right\",\n key: \"details\",\n label: \"Details\",\n isActive: (e) => e.isActive(\"details\"),\n run: (e) => {\n if (e.isActive(\"details\")) {\n e.chain().focus().unsetDetails().run();\n return;\n }\n e.chain().focus().setDetails().run();\n },\n },\n];\n\nconst emojis = [\n \"😀\",\n \"😅\",\n \"😂\",\n \"🥳\",\n \"😎\",\n \"🤔\",\n \"👍\",\n \"🙏\",\n \"🔥\",\n \"🎉\",\n \"🚀\",\n \"💡\",\n \"✅\",\n \"❌\",\n \"⭐\",\n \"❤️\",\n];\n\nfunction EmojiPicker({ editor }: { editor: Editor }) {\n const { t } = useT(\"lattice\");\n const [open, setOpen] = useState(false);\n\n return (\n <div className=\"relative\">\n <button\n aria-label={t(\"form.editor.insert-emoji\", \"Insert emoji\")}\n data-test=\"editor-emoji\"\n className=\"inline-flex size-7 items-center justify-center rounded-lt-sm text-lt-muted-fg transition-colors hover:bg-lt-accent hover:text-lt-accent-fg [&_svg]:size-lt-icon-md\"\n onClick={() => setOpen((value) => !value)}\n onMouseDown={(event) => event.preventDefault()}\n title={t(\"form.editor.insert-emoji\", \"Insert emoji\")}\n type=\"button\"\n >\n <Icon name=\"smile\" />\n </button>\n {open && (\n <div className=\"absolute z-lt-dropdown mt-1 grid grid-cols-8 gap-0.5 rounded-lt-sm border border-lt-border bg-lt-bg p-1 shadow-lt-md\">\n {emojis.map((emoji) => (\n <button\n className=\"inline-flex size-7 items-center justify-center rounded-lt-sm text-base hover:bg-lt-accent\"\n key={emoji}\n onClick={() => {\n editor.chain().focus().insertContent(emoji).run();\n setOpen(false);\n }}\n onMouseDown={(event) => event.preventDefault()}\n type=\"button\"\n >\n {emoji}\n </button>\n ))}\n </div>\n )}\n </div>\n );\n}\n\nfunction Toolbar({ editor }: { editor: Editor }) {\n const { t } = useT(\"lattice\");\n\n return (\n <div className=\"flex flex-wrap items-center gap-0.5 border-b border-lt-border p-1\">\n {toolbar.map((item, index) => {\n if (item === \"separator\") {\n // eslint-disable-next-line react/no-array-index-key\n return <span key={`sep-${index}`} className=\"mx-1 h-5 w-px bg-lt-border\" />;\n }\n\n const label = t(`form.editor.${item.key}`, item.label);\n\n return (\n <button\n aria-label={label}\n aria-pressed={item.isActive(editor)}\n data-test={`editor-${item.key}`}\n className={cn(\n \"inline-flex size-7 items-center justify-center rounded-lt-sm text-lt-muted-fg transition-colors hover:bg-lt-accent hover:text-lt-accent-fg disabled:pointer-events-none disabled:opacity-40 [&_svg]:size-lt-icon-md\",\n item.isActive(editor) && \"bg-lt-accent text-lt-accent-fg\",\n )}\n disabled={item.isDisabled?.(editor) ?? false}\n key={item.key}\n // Keep focus in the editor so toolbar clicks don't blur it (which would\n // otherwise trigger a precognition request).\n onClick={() => item.run(editor)}\n onMouseDown={(event) => event.preventDefault()}\n title={label}\n type=\"button\"\n >\n <Icon name={item.icon} />\n </button>\n );\n })}\n <span className=\"mx-1 h-5 w-px bg-lt-border\" />\n <EmojiPicker editor={editor} />\n </div>\n );\n}\n\nconst RichEditorField: RendererComponent<\"field.rich-editor\"> = ({ node }) => {\n const { errors } = useFormContext();\n const { hidden, required, readOnly, disabled } = useDependentField(node);\n const { change, blur } = useFieldCommit();\n const name = node.props.name;\n const scope = useFieldScope();\n const globalValue = useFormValue(name);\n const storedValue = scope ? scope.getValue(name) : globalValue;\n const domName = scope ? scope.scopedName(name) : name;\n const errorKey = scope ? scope.errorKey(name) : name;\n const locked = readOnly || disabled;\n const initialContent =\n typeof storedValue === \"object\" && storedValue !== null\n ? (storedValue as object)\n : ((node.props.value as object | undefined) ?? \"\");\n\n const editor = useEditor({\n extensions: [\n StarterKit,\n Highlight,\n TextAlign.configure({ types: [\"heading\", \"paragraph\"] }),\n Link.configure({ openOnClick: false }),\n TableKit.configure({ table: { resizable: false } }),\n Details,\n DetailsSummary,\n DetailsContent,\n ],\n content: initialContent,\n editable: !locked,\n immediatelyRender: false,\n editorProps: {\n attributes: {\n class: \"lattice-prose min-h-32 px-3 py-2 outline-none\",\n },\n },\n onUpdate: ({ editor: instance }) => {\n change(name, instance.isEmpty ? null : instance.getJSON());\n },\n onBlur: () => {\n blur(name);\n },\n });\n\n useEffect(() => {\n editor?.setEditable(!locked);\n }, [editor, locked]);\n\n if (hidden) {\n return null;\n }\n\n const submittedValue = storedValue ? JSON.stringify(storedValue) : \"\";\n\n return (\n <FormFieldFrame\n error={errors[errorKey]}\n helperText={node.props.helperText ?? undefined}\n tooltip={node.props.tooltip ?? undefined}\n label={node.props.label ?? \"\"}\n name={domName}\n required={required}\n >\n <div\n className={cn(\n \"overflow-hidden rounded-lt-sm border border-lt-input bg-transparent shadow-lt-xs focus-within:border-lt-ring focus-within:ring-[3px] focus-within:ring-lt-ring/50\",\n locked && \"opacity-60\",\n )}\n >\n {editor && !locked && <Toolbar editor={editor} />}\n <EditorContent editor={editor} />\n </div>\n <input name={domName} type=\"hidden\" value={submittedValue} />\n </FormFieldFrame>\n );\n};\n\nexport default RichEditorField;\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA8BA,IAAM,UAAyB;CAC7B;EACE,MAAM;EACN,KAAK;EACL,OAAO;EACP,WAAW,MAAM,EAAE,SAAS,MAAM;EAClC,MAAM,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI;CACjD;CACA;EACE,MAAM;EACN,KAAK;EACL,OAAO;EACP,WAAW,MAAM,EAAE,SAAS,QAAQ;EACpC,MAAM,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,IAAI;CACnD;CACA;EACE,MAAM;EACN,KAAK;EACL,OAAO;EACP,WAAW,MAAM,EAAE,SAAS,QAAQ;EACpC,MAAM,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,IAAI;CACnD;CACA;EACE,MAAM;EACN,KAAK;EACL,OAAO;EACP,WAAW,MAAM,EAAE,SAAS,WAAW;EACvC,MAAM,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,IAAI;CACtD;CACA;EACE,MAAM;EACN,KAAK;EACL,OAAO;EACP,WAAW,MAAM,EAAE,SAAS,WAAW;EACvC,MAAM,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,IAAI;CACtD;CACA;CACA;EACE,MAAM;EACN,KAAK;EACL,OAAO;EACP,WAAW,MAAM,EAAE,SAAS,WAAW,E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