@pilotiq/pilotiq 0.7.1 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +2 -2
- package/CHANGELOG.md +154 -0
- package/CLAUDE.md +59 -3
- package/dist/Pilotiq.d.ts +83 -0
- package/dist/Pilotiq.d.ts.map +1 -1
- package/dist/Pilotiq.js +39 -0
- package/dist/Pilotiq.js.map +1 -1
- package/dist/actions/Action.d.ts +27 -99
- package/dist/actions/Action.d.ts.map +1 -1
- package/dist/actions/Action.js +52 -754
- package/dist/actions/Action.js.map +1 -1
- package/dist/actions/bulkFactories.d.ts +46 -0
- package/dist/actions/bulkFactories.d.ts.map +1 -0
- package/dist/actions/bulkFactories.js +144 -0
- package/dist/actions/bulkFactories.js.map +1 -0
- package/dist/actions/crudFactories.d.ts +94 -0
- package/dist/actions/crudFactories.d.ts.map +1 -0
- package/dist/actions/crudFactories.js +209 -0
- package/dist/actions/crudFactories.js.map +1 -0
- package/dist/actions/factoryHelpers.d.ts +108 -0
- package/dist/actions/factoryHelpers.d.ts.map +1 -0
- package/dist/actions/factoryHelpers.js +138 -0
- package/dist/actions/factoryHelpers.js.map +1 -0
- package/dist/actions/m2mFactories.d.ts +47 -0
- package/dist/actions/m2mFactories.d.ts.map +1 -0
- package/dist/actions/m2mFactories.js +173 -0
- package/dist/actions/m2mFactories.js.map +1 -0
- package/dist/actions/relationFactories.d.ts +93 -0
- package/dist/actions/relationFactories.d.ts.map +1 -0
- package/dist/actions/relationFactories.js +321 -0
- package/dist/actions/relationFactories.js.map +1 -0
- package/dist/elements/dispatchForm.js +1 -1
- package/dist/elements/dispatchForm.js.map +1 -1
- package/dist/elements/dispatchTable.js +1 -1
- package/dist/elements/dispatchTable.js.map +1 -1
- package/dist/fields/Field.d.ts +31 -0
- package/dist/fields/Field.d.ts.map +1 -1
- package/dist/fields/Field.js +25 -0
- package/dist/fields/Field.js.map +1 -1
- package/dist/pageData/breadcrumbs.d.ts +42 -0
- package/dist/pageData/breadcrumbs.d.ts.map +1 -0
- package/dist/pageData/breadcrumbs.js +172 -0
- package/dist/pageData/breadcrumbs.js.map +1 -0
- package/dist/pageData/forms.d.ts +137 -0
- package/dist/pageData/forms.d.ts.map +1 -0
- package/dist/pageData/forms.js +427 -0
- package/dist/pageData/forms.js.map +1 -0
- package/dist/pageData/helpers.d.ts +239 -0
- package/dist/pageData/helpers.d.ts.map +1 -0
- package/dist/pageData/helpers.js +703 -0
- package/dist/pageData/helpers.js.map +1 -0
- package/dist/pageData/misc.d.ts +76 -0
- package/dist/pageData/misc.d.ts.map +1 -0
- package/dist/pageData/misc.js +263 -0
- package/dist/pageData/misc.js.map +1 -0
- package/dist/pageData/navigation.d.ts +292 -0
- package/dist/pageData/navigation.d.ts.map +1 -0
- package/dist/pageData/navigation.js +591 -0
- package/dist/pageData/navigation.js.map +1 -0
- package/dist/pageData/relationPages.d.ts +172 -0
- package/dist/pageData/relationPages.d.ts.map +1 -0
- package/dist/pageData/relationPages.js +867 -0
- package/dist/pageData/relationPages.js.map +1 -0
- package/dist/pageData/relationTabs.d.ts +65 -0
- package/dist/pageData/relationTabs.d.ts.map +1 -0
- package/dist/pageData/relationTabs.js +258 -0
- package/dist/pageData/relationTabs.js.map +1 -0
- package/dist/pageData/resourcePages.d.ts +48 -0
- package/dist/pageData/resourcePages.d.ts.map +1 -0
- package/dist/pageData/resourcePages.js +504 -0
- package/dist/pageData/resourcePages.js.map +1 -0
- package/dist/pageData.d.ts +12 -792
- package/dist/pageData.d.ts.map +1 -1
- package/dist/pageData.js +24 -3797
- package/dist/pageData.js.map +1 -1
- package/dist/react/AppShell.d.ts +8 -0
- package/dist/react/AppShell.d.ts.map +1 -1
- package/dist/react/AppShell.js +11 -1
- package/dist/react/AppShell.js.map +1 -1
- package/dist/react/CollabExtensionFactoryRegistry.d.ts +47 -0
- package/dist/react/CollabExtensionFactoryRegistry.d.ts.map +1 -0
- package/dist/react/CollabExtensionFactoryRegistry.js +14 -0
- package/dist/react/CollabExtensionFactoryRegistry.js.map +1 -0
- package/dist/react/CollabRoomContext.d.ts +37 -0
- package/dist/react/CollabRoomContext.d.ts.map +1 -0
- package/dist/react/CollabRoomContext.js +12 -0
- package/dist/react/CollabRoomContext.js.map +1 -0
- package/dist/react/FormCollabBindingRegistry.d.ts +62 -0
- package/dist/react/FormCollabBindingRegistry.d.ts.map +1 -0
- package/dist/react/FormCollabBindingRegistry.js +14 -0
- package/dist/react/FormCollabBindingRegistry.js.map +1 -0
- package/dist/react/RecordWrapperGate.d.ts +25 -0
- package/dist/react/RecordWrapperGate.d.ts.map +1 -0
- package/dist/react/RecordWrapperGate.js +30 -0
- package/dist/react/RecordWrapperGate.js.map +1 -0
- package/dist/react/RecordWrapperRegistry.d.ts +31 -0
- package/dist/react/RecordWrapperRegistry.d.ts.map +1 -0
- package/dist/react/RecordWrapperRegistry.js +15 -0
- package/dist/react/RecordWrapperRegistry.js.map +1 -0
- package/dist/react/SchemaRenderer.d.ts +17 -23
- package/dist/react/SchemaRenderer.d.ts.map +1 -1
- package/dist/react/SchemaRenderer.js +71 -3647
- package/dist/react/SchemaRenderer.js.map +1 -1
- package/dist/react/component-slots.d.ts +103 -0
- package/dist/react/component-slots.d.ts.map +1 -0
- package/dist/react/component-slots.js +18 -0
- package/dist/react/component-slots.js.map +1 -0
- package/dist/react/fields/BuilderInput.d.ts.map +1 -1
- package/dist/react/fields/BuilderInput.js +21 -117
- package/dist/react/fields/BuilderInput.js.map +1 -1
- package/dist/react/fields/MarkdownInput.d.ts.map +1 -1
- package/dist/react/fields/MarkdownInput.js +1 -3
- package/dist/react/fields/MarkdownInput.js.map +1 -1
- package/dist/react/fields/RepeaterInput.d.ts.map +1 -1
- package/dist/react/fields/RepeaterInput.js +22 -127
- package/dist/react/fields/RepeaterInput.js.map +1 -1
- package/dist/react/fields/rowState.d.ts +40 -0
- package/dist/react/fields/rowState.d.ts.map +1 -0
- package/dist/react/fields/rowState.js +60 -0
- package/dist/react/fields/rowState.js.map +1 -0
- package/dist/react/fields/useRowReorderDnd.d.ts +28 -0
- package/dist/react/fields/useRowReorderDnd.d.ts.map +1 -0
- package/dist/react/fields/useRowReorderDnd.js +51 -0
- package/dist/react/fields/useRowReorderDnd.js.map +1 -0
- package/dist/react/index.d.ts +9 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +8 -0
- package/dist/react/index.js.map +1 -1
- package/dist/react/layouts/SidebarLayout.d.ts +1 -1
- package/dist/react/layouts/SidebarLayout.d.ts.map +1 -1
- package/dist/react/layouts/SidebarLayout.js +10 -2
- package/dist/react/layouts/SidebarLayout.js.map +1 -1
- package/dist/react/layouts/TopbarLayout.d.ts +1 -1
- package/dist/react/layouts/TopbarLayout.d.ts.map +1 -1
- package/dist/react/layouts/TopbarLayout.js +19 -11
- package/dist/react/layouts/TopbarLayout.js.map +1 -1
- package/dist/react/parseRecordEditUrl.d.ts +29 -0
- package/dist/react/parseRecordEditUrl.d.ts.map +1 -0
- package/dist/react/parseRecordEditUrl.js +25 -0
- package/dist/react/parseRecordEditUrl.js.map +1 -0
- package/dist/react/persistedState.d.ts +19 -0
- package/dist/react/persistedState.d.ts.map +1 -0
- package/dist/react/persistedState.js +51 -0
- package/dist/react/persistedState.js.map +1 -0
- package/dist/react/schemaRenderer/AlertRenderer.d.ts +12 -0
- package/dist/react/schemaRenderer/AlertRenderer.d.ts.map +1 -0
- package/dist/react/schemaRenderer/AlertRenderer.js +61 -0
- package/dist/react/schemaRenderer/AlertRenderer.js.map +1 -0
- package/dist/react/schemaRenderer/EntryRenderer.d.ts +13 -0
- package/dist/react/schemaRenderer/EntryRenderer.d.ts.map +1 -0
- package/dist/react/schemaRenderer/EntryRenderer.js +277 -0
- package/dist/react/schemaRenderer/EntryRenderer.js.map +1 -0
- package/dist/react/schemaRenderer/SectionRenderer.d.ts +16 -0
- package/dist/react/schemaRenderer/SectionRenderer.d.ts.map +1 -0
- package/dist/react/schemaRenderer/SectionRenderer.js +62 -0
- package/dist/react/schemaRenderer/SectionRenderer.js.map +1 -0
- package/dist/react/schemaRenderer/SimpleElements.d.ts +25 -0
- package/dist/react/schemaRenderer/SimpleElements.d.ts.map +1 -0
- package/dist/react/schemaRenderer/SimpleElements.js +147 -0
- package/dist/react/schemaRenderer/SimpleElements.js.map +1 -0
- package/dist/react/schemaRenderer/TabsRenderer.d.ts +17 -0
- package/dist/react/schemaRenderer/TabsRenderer.d.ts.map +1 -0
- package/dist/react/schemaRenderer/TabsRenderer.js +31 -0
- package/dist/react/schemaRenderer/TabsRenderer.js.map +1 -0
- package/dist/react/schemaRenderer/WizardRenderer.d.ts +34 -0
- package/dist/react/schemaRenderer/WizardRenderer.d.ts.map +1 -0
- package/dist/react/schemaRenderer/WizardRenderer.js +208 -0
- package/dist/react/schemaRenderer/WizardRenderer.js.map +1 -0
- package/dist/react/schemaRenderer/action/ActionGroupTrigger.d.ts +21 -0
- package/dist/react/schemaRenderer/action/ActionGroupTrigger.d.ts.map +1 -0
- package/dist/react/schemaRenderer/action/ActionGroupTrigger.js +82 -0
- package/dist/react/schemaRenderer/action/ActionGroupTrigger.js.map +1 -0
- package/dist/react/schemaRenderer/action/ActionModalDialog.d.ts +30 -0
- package/dist/react/schemaRenderer/action/ActionModalDialog.d.ts.map +1 -0
- package/dist/react/schemaRenderer/action/ActionModalDialog.js +182 -0
- package/dist/react/schemaRenderer/action/ActionModalDialog.js.map +1 -0
- package/dist/react/schemaRenderer/action/ConfirmActionDialog.d.ts +17 -0
- package/dist/react/schemaRenderer/action/ConfirmActionDialog.d.ts.map +1 -0
- package/dist/react/schemaRenderer/action/ConfirmActionDialog.js +19 -0
- package/dist/react/schemaRenderer/action/ConfirmActionDialog.js.map +1 -0
- package/dist/react/schemaRenderer/action/HandlerActionButton.d.ts +16 -0
- package/dist/react/schemaRenderer/action/HandlerActionButton.d.ts.map +1 -0
- package/dist/react/schemaRenderer/action/HandlerActionButton.js +16 -0
- package/dist/react/schemaRenderer/action/HandlerActionButton.js.map +1 -0
- package/dist/react/schemaRenderer/action/MethodActionButton.d.ts +22 -0
- package/dist/react/schemaRenderer/action/MethodActionButton.d.ts.map +1 -0
- package/dist/react/schemaRenderer/action/MethodActionButton.js +26 -0
- package/dist/react/schemaRenderer/action/MethodActionButton.js.map +1 -0
- package/dist/react/schemaRenderer/action/buttons.d.ts +18 -0
- package/dist/react/schemaRenderer/action/buttons.d.ts.map +1 -0
- package/dist/react/schemaRenderer/action/buttons.js +74 -0
- package/dist/react/schemaRenderer/action/buttons.js.map +1 -0
- package/dist/react/schemaRenderer/action/helpers.d.ts +26 -0
- package/dist/react/schemaRenderer/action/helpers.d.ts.map +1 -0
- package/dist/react/schemaRenderer/action/helpers.js +126 -0
- package/dist/react/schemaRenderer/action/helpers.js.map +1 -0
- package/dist/react/schemaRenderer/action/renderAction.d.ts +21 -0
- package/dist/react/schemaRenderer/action/renderAction.d.ts.map +1 -0
- package/dist/react/schemaRenderer/action/renderAction.js +102 -0
- package/dist/react/schemaRenderer/action/renderAction.js.map +1 -0
- package/dist/react/schemaRenderer/columnFormat.d.ts +10 -0
- package/dist/react/schemaRenderer/columnFormat.d.ts.map +1 -0
- package/dist/react/schemaRenderer/columnFormat.js +76 -0
- package/dist/react/schemaRenderer/columnFormat.js.map +1 -0
- package/dist/react/schemaRenderer/constants.d.ts +8 -0
- package/dist/react/schemaRenderer/constants.d.ts.map +1 -0
- package/dist/react/schemaRenderer/constants.js +45 -0
- package/dist/react/schemaRenderer/constants.js.map +1 -0
- package/dist/react/schemaRenderer/form/FormRenderer.d.ts +29 -0
- package/dist/react/schemaRenderer/form/FormRenderer.d.ts.map +1 -0
- package/dist/react/schemaRenderer/form/FormRenderer.js +152 -0
- package/dist/react/schemaRenderer/form/FormRenderer.js.map +1 -0
- package/dist/react/schemaRenderer/form/renderField.d.ts +6 -0
- package/dist/react/schemaRenderer/form/renderField.d.ts.map +1 -0
- package/dist/react/schemaRenderer/form/renderField.js +239 -0
- package/dist/react/schemaRenderer/form/renderField.js.map +1 -0
- package/dist/react/schemaRenderer/helpers.d.ts +32 -0
- package/dist/react/schemaRenderer/helpers.d.ts.map +1 -0
- package/dist/react/schemaRenderer/helpers.js +52 -0
- package/dist/react/schemaRenderer/helpers.js.map +1 -0
- package/dist/react/schemaRenderer/table/CardsLayoutBody.d.ts +60 -0
- package/dist/react/schemaRenderer/table/CardsLayoutBody.d.ts.map +1 -0
- package/dist/react/schemaRenderer/table/CardsLayoutBody.js +189 -0
- package/dist/react/schemaRenderer/table/CardsLayoutBody.js.map +1 -0
- package/dist/react/schemaRenderer/table/TableRenderer.d.ts +29 -0
- package/dist/react/schemaRenderer/table/TableRenderer.d.ts.map +1 -0
- package/dist/react/schemaRenderer/table/TableRenderer.js +85 -0
- package/dist/react/schemaRenderer/table/TableRenderer.js.map +1 -0
- package/dist/react/schemaRenderer/table/TableRendererBody.d.ts +18 -0
- package/dist/react/schemaRenderer/table/TableRendererBody.d.ts.map +1 -0
- package/dist/react/schemaRenderer/table/TableRendererBody.js +555 -0
- package/dist/react/schemaRenderer/table/TableRendererBody.js.map +1 -0
- package/dist/react/schemaRenderer/table/filters.d.ts +263 -0
- package/dist/react/schemaRenderer/table/filters.d.ts.map +1 -0
- package/dist/react/schemaRenderer/table/filters.js +497 -0
- package/dist/react/schemaRenderer/table/filters.js.map +1 -0
- package/dist/react/schemaRenderer/table/formatCell.d.ts +11 -0
- package/dist/react/schemaRenderer/table/formatCell.d.ts.map +1 -0
- package/dist/react/schemaRenderer/table/formatCell.js +172 -0
- package/dist/react/schemaRenderer/table/formatCell.js.map +1 -0
- package/dist/react/schemaRenderer/table/links.d.ts +42 -0
- package/dist/react/schemaRenderer/table/links.d.ts.map +1 -0
- package/dist/react/schemaRenderer/table/links.js +55 -0
- package/dist/react/schemaRenderer/table/links.js.map +1 -0
- package/dist/react/schemaRenderer/table/renderRowActions.d.ts +13 -0
- package/dist/react/schemaRenderer/table/renderRowActions.d.ts.map +1 -0
- package/dist/react/schemaRenderer/table/renderRowActions.js +25 -0
- package/dist/react/schemaRenderer/table/renderRowActions.js.map +1 -0
- package/dist/react/schemaRenderer/table/url.d.ts +41 -0
- package/dist/react/schemaRenderer/table/url.d.ts.map +1 -0
- package/dist/react/schemaRenderer/table/url.js +114 -0
- package/dist/react/schemaRenderer/table/url.js.map +1 -0
- package/dist/routes/globals.d.ts +13 -0
- package/dist/routes/globals.d.ts.map +1 -0
- package/dist/routes/globals.js +131 -0
- package/dist/routes/globals.js.map +1 -0
- package/dist/routes/helpers.d.ts +217 -0
- package/dist/routes/helpers.d.ts.map +1 -0
- package/dist/routes/helpers.js +498 -0
- package/dist/routes/helpers.js.map +1 -0
- package/dist/routes/pages.d.ts +15 -0
- package/dist/routes/pages.d.ts.map +1 -0
- package/dist/routes/pages.js +145 -0
- package/dist/routes/pages.js.map +1 -0
- package/dist/routes/panel.d.ts +19 -0
- package/dist/routes/panel.d.ts.map +1 -0
- package/dist/routes/panel.js +191 -0
- package/dist/routes/panel.js.map +1 -0
- package/dist/routes/relations.d.ts +21 -0
- package/dist/routes/relations.d.ts.map +1 -0
- package/dist/routes/relations.js +1239 -0
- package/dist/routes/relations.js.map +1 -0
- package/dist/routes/resources.d.ts +28 -0
- package/dist/routes/resources.d.ts.map +1 -0
- package/dist/routes/resources.js +741 -0
- package/dist/routes/resources.js.map +1 -0
- package/dist/routes/theme.d.ts +12 -0
- package/dist/routes/theme.d.ts.map +1 -0
- package/dist/routes/theme.js +82 -0
- package/dist/routes/theme.js.map +1 -0
- package/dist/routes.d.ts.map +1 -1
- package/dist/routes.js +64 -3078
- package/dist/routes.js.map +1 -1
- package/dist/vite.d.ts +1 -0
- package/dist/vite.d.ts.map +1 -1
- package/dist/vite.js +31 -10
- package/dist/vite.js.map +1 -1
- package/package.json +2 -1
- package/src/Pilotiq.ts +95 -0
- package/src/actions/Action.ts +79 -723
- package/src/actions/bulkFactories.ts +168 -0
- package/src/actions/crudFactories.ts +220 -0
- package/src/actions/factoryHelpers.ts +177 -0
- package/src/actions/m2mFactories.ts +193 -0
- package/src/actions/relationFactories.ts +372 -0
- package/src/elements/dispatchForm.ts +1 -1
- package/src/elements/dispatchTable.ts +1 -1
- package/src/fields/Field.ts +39 -0
- package/src/pageData/breadcrumbs.ts +288 -0
- package/src/pageData/forms.ts +578 -0
- package/src/pageData/helpers.ts +764 -0
- package/src/pageData/misc.ts +347 -0
- package/src/pageData/navigation.ts +779 -0
- package/src/pageData/relationPages.ts +1246 -0
- package/src/pageData/relationTabs.ts +286 -0
- package/src/pageData/resourcePages.ts +593 -0
- package/src/pageData.ts +122 -4731
- package/src/react/AppShell.tsx +27 -1
- package/src/react/CollabExtensionFactoryRegistry.ts +55 -0
- package/src/react/CollabRoomContext.ts +42 -0
- package/src/react/FormCollabBindingRegistry.ts +72 -0
- package/src/react/RecordWrapperGate.tsx +40 -0
- package/src/react/RecordWrapperRegistry.ts +39 -0
- package/src/react/SchemaRenderer.tsx +230 -6479
- package/src/react/component-slots.test.ts +103 -0
- package/src/react/component-slots.ts +116 -0
- package/src/react/fields/BuilderInput.tsx +29 -117
- package/src/react/fields/MarkdownInput.tsx +0 -1
- package/src/react/fields/RepeaterInput.tsx +29 -130
- package/src/react/fields/rowState.ts +106 -0
- package/src/react/fields/useRowReorderDnd.ts +78 -0
- package/src/react/index.ts +38 -0
- package/src/react/layouts/SidebarLayout.tsx +39 -28
- package/src/react/layouts/TopbarLayout.tsx +70 -57
- package/src/react/parseRecordEditUrl.test.ts +75 -0
- package/src/react/parseRecordEditUrl.ts +55 -0
- package/src/react/persistedState.ts +40 -0
- package/src/react/schemaRenderer/AlertRenderer.tsx +112 -0
- package/src/react/schemaRenderer/EntryRenderer.tsx +501 -0
- package/src/react/schemaRenderer/SectionRenderer.tsx +120 -0
- package/src/react/schemaRenderer/SimpleElements.tsx +306 -0
- package/src/react/schemaRenderer/TabsRenderer.tsx +62 -0
- package/src/react/schemaRenderer/WizardRenderer.tsx +338 -0
- package/src/react/schemaRenderer/action/ActionGroupTrigger.tsx +177 -0
- package/src/react/schemaRenderer/action/ActionModalDialog.tsx +273 -0
- package/src/react/schemaRenderer/action/ConfirmActionDialog.tsx +61 -0
- package/src/react/schemaRenderer/action/HandlerActionButton.tsx +43 -0
- package/src/react/schemaRenderer/action/MethodActionButton.tsx +64 -0
- package/src/react/schemaRenderer/action/buttons.tsx +99 -0
- package/src/react/schemaRenderer/action/helpers.ts +140 -0
- package/src/react/schemaRenderer/action/renderAction.tsx +245 -0
- package/src/react/schemaRenderer/columnFormat.ts +65 -0
- package/src/react/schemaRenderer/constants.ts +50 -0
- package/src/react/schemaRenderer/form/FormRenderer.tsx +233 -0
- package/src/react/schemaRenderer/form/renderField.tsx +511 -0
- package/src/react/schemaRenderer/helpers.tsx +81 -0
- package/src/react/schemaRenderer/table/CardsLayoutBody.tsx +308 -0
- package/src/react/schemaRenderer/table/TableRenderer.tsx +123 -0
- package/src/react/schemaRenderer/table/TableRendererBody.tsx +974 -0
- package/src/react/schemaRenderer/table/filters.tsx +1233 -0
- package/src/react/schemaRenderer/table/formatCell.tsx +264 -0
- package/src/react/schemaRenderer/table/links.tsx +112 -0
- package/src/react/schemaRenderer/table/renderRowActions.tsx +52 -0
- package/src/react/schemaRenderer/table/url.tsx +143 -0
- package/src/routes/globals.ts +154 -0
- package/src/routes/helpers.ts +668 -0
- package/src/routes/pages.ts +173 -0
- package/src/routes/panel.ts +204 -0
- package/src/routes/relations.ts +1219 -0
- package/src/routes/resources.ts +786 -0
- package/src/routes/theme.ts +109 -0
- package/src/routes.test.ts +1 -1
- package/src/routes.ts +64 -3176
- package/src/schema/TableWidget.test.ts +2 -2
- package/src/theme/migrate.test.ts +178 -0
- package/src/vite.test.ts +184 -0
- package/src/vite.ts +31 -9
|
@@ -0,0 +1,703 @@
|
|
|
1
|
+
import { Field } from '../fields/Field.js';
|
|
2
|
+
import { Column } from '../Column.js';
|
|
3
|
+
import { SelectField } from '../fields/SelectField.js';
|
|
4
|
+
import { isRepeaterField, RepeaterField } from '../fields/RepeaterField.js';
|
|
5
|
+
import { isBuilderField, BuilderField } from '../fields/BuilderField.js';
|
|
6
|
+
import { isServerDataElement } from '../schema/ServerDataElement.js';
|
|
7
|
+
import { findActions, findRowExtraActions } from '../elements/dispatchAction.js';
|
|
8
|
+
import { findForms, loadRelationRows } from '../elements/dispatchForm.js';
|
|
9
|
+
import { findTables } from '../elements/dispatchTable.js';
|
|
10
|
+
import { getMorphRelationDescriptor, getPrimaryKey, } from '../orm/modelDefaults.js';
|
|
11
|
+
// ─── pageData shared helpers ────────────────────────────────
|
|
12
|
+
//
|
|
13
|
+
// URL-tag helpers (stamp dispatch URLs / cell-edit endpoints / wizard
|
|
14
|
+
// endpoints / mention-resolve endpoints), the load-record fill pipeline
|
|
15
|
+
// (`applyFillPipeline` + relationship Repeater/Builder fills),
|
|
16
|
+
// server-data widget resolution, and the two `*Ctx` helpers that the
|
|
17
|
+
// per-role builders use to construct the `SchemaContext` they pass into
|
|
18
|
+
// `resolveSchema`. Pure (mostly stateless) helpers — no per-page-role
|
|
19
|
+
// orchestration.
|
|
20
|
+
export function userCtx(ctx, user) {
|
|
21
|
+
if (user === null || user === undefined)
|
|
22
|
+
return ctx;
|
|
23
|
+
return { ...ctx, user: user };
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Run a (possibly async) boolean predicate; fail closed when it throws.
|
|
27
|
+
*
|
|
28
|
+
* Every page-builder pre-flight that consults `canX(user, …)` needs this
|
|
29
|
+
* shape — predicates may be sync booleans, Promises, or throw at the
|
|
30
|
+
* remote-auth layer; a throw must never propagate to the wire as an
|
|
31
|
+
* unhandled 500.
|
|
32
|
+
*/
|
|
33
|
+
export async function safeBool(fn) {
|
|
34
|
+
try {
|
|
35
|
+
return Boolean(await fn());
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/** Plan #6 — stamp the panel-wide upload URL so `FileUpload` fields
|
|
42
|
+
* emit it on their meta. Single URL for the whole panel; no per-field
|
|
43
|
+
* variation. The route is always registered (see `_uploads` in
|
|
44
|
+
* `routes.ts`) — meta is stamped regardless of whether an adapter is
|
|
45
|
+
* configured so the renderer can show a clear error rather than
|
|
46
|
+
* silently breaking. The companion `hasUploadAdapter` flag distinguishes
|
|
47
|
+
* "URL exists but adapter missing" so fields with optional upload
|
|
48
|
+
* affordances (e.g. `MarkdownField`'s `attachFiles` button) can hide
|
|
49
|
+
* themselves rather than render a broken control. */
|
|
50
|
+
export function uploadCtx(ctx, cfg) {
|
|
51
|
+
return {
|
|
52
|
+
...ctx,
|
|
53
|
+
uploadUrl: `${cfg.path}/_uploads`,
|
|
54
|
+
...(cfg.uploads ? { hasUploadAdapter: true } : {}),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export async function callPageSchema(PageClass, ctx) {
|
|
58
|
+
return Promise.resolve(PageClass.schema(ctx));
|
|
59
|
+
}
|
|
60
|
+
/** Mark every Form on the page with its action URL so the rendered <form> posts to itself. */
|
|
61
|
+
export function tagFormActions(elements, action) {
|
|
62
|
+
for (const form of findForms(elements)) {
|
|
63
|
+
if (!form.getAction())
|
|
64
|
+
form.action(action);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Plan #5 — stamp the partial-resolve endpoint URL on every form whose
|
|
69
|
+
* descendants include at least one `live()` field. The client uses
|
|
70
|
+
* `FormMeta.stateUrl` to flip into controlled-state mode; forms without
|
|
71
|
+
* any live fields stay uncontrolled (zero-cost legacy path).
|
|
72
|
+
*
|
|
73
|
+
* `urlBuilder(formId)` lets the caller compose a per-form URL — the
|
|
74
|
+
* endpoint shape is `${base}/${slug}/_form/${formId}/state` so each
|
|
75
|
+
* form on a multi-form page gets its own route segment.
|
|
76
|
+
*/
|
|
77
|
+
export function tagFormStateUrls(elements, urlBuilder) {
|
|
78
|
+
for (const form of findForms(elements)) {
|
|
79
|
+
if (formHasLiveField(form)) {
|
|
80
|
+
form.withStateUrl(urlBuilder(form.getFormId()));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Reorderable rows — stamp the POST-reorder URL on every `Table` that
|
|
86
|
+
* has `Table.reorderable()` set. The renderer reads `TableMeta.reorderUrl`
|
|
87
|
+
* to wire the drop handler; tables that aren't reorderable skip wiring
|
|
88
|
+
* entirely. Same shape as `tagFormStateUrls` so the call site stays
|
|
89
|
+
* consistent.
|
|
90
|
+
*/
|
|
91
|
+
export function tagTableReorderUrls(elements, url) {
|
|
92
|
+
for (const table of findTables(elements)) {
|
|
93
|
+
if (table.isReorderable() && !table.getReorderUrl()) {
|
|
94
|
+
table.withReorderUrl(url);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
// Marks every Table on the page deferred and stamps the URL the
|
|
99
|
+
// renderer will fetch from after mount. Must run BEFORE `loadTableRecords`
|
|
100
|
+
// so the records handler short-circuits.
|
|
101
|
+
export function tagTableDeferred(elements, url) {
|
|
102
|
+
for (const table of findTables(elements)) {
|
|
103
|
+
table.withDeferred(true);
|
|
104
|
+
table.withTableUrl(url);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Editable cell columns — walk every table on the page and stamp
|
|
109
|
+
* `_cellEditUrls[colName]` per row, but only on rows that already
|
|
110
|
+
* carry a `_cellEditable[colName]` marker (set by `loadTableRecords`
|
|
111
|
+
* after `R.canEdit(user, row)` passed). The dispatcher stays
|
|
112
|
+
* URL-shape-agnostic; URL building lives here parallel to
|
|
113
|
+
* `tagFormStateUrls / tagTableReorderUrls`.
|
|
114
|
+
*
|
|
115
|
+
* `idOf` extracts the per-row primary key. Defaults to reading `id` —
|
|
116
|
+
* works for the rudder ORM convention. Resources with a different
|
|
117
|
+
* primary-key column should pass an override (none in v1).
|
|
118
|
+
*/
|
|
119
|
+
export function tagCellEditUrls(elements, resourceUrl, idOf = row => row['id']) {
|
|
120
|
+
for (const table of findTables(elements)) {
|
|
121
|
+
const rows = table.getRows();
|
|
122
|
+
if (!rows || rows.length === 0)
|
|
123
|
+
continue;
|
|
124
|
+
// Optimisation: skip the table when none of its columns are editable.
|
|
125
|
+
const editable = (table.getChildren() ?? []).some(c => c instanceof Column && c.isEditable());
|
|
126
|
+
if (!editable)
|
|
127
|
+
continue;
|
|
128
|
+
for (const row of rows) {
|
|
129
|
+
const editableMap = row['_cellEditable'];
|
|
130
|
+
if (!editableMap)
|
|
131
|
+
continue;
|
|
132
|
+
const id = idOf(row);
|
|
133
|
+
if (id === undefined || id === null || id === '')
|
|
134
|
+
continue;
|
|
135
|
+
const urls = {};
|
|
136
|
+
for (const colName of Object.keys(editableMap)) {
|
|
137
|
+
urls[colName] = `${resourceUrl}/${encodeURIComponent(String(id))}/_cell/${encodeURIComponent(colName)}`;
|
|
138
|
+
}
|
|
139
|
+
;
|
|
140
|
+
row['_cellEditUrls'] = urls;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Plan #8 — stamp the wizard step-validate endpoint URL on every form
|
|
146
|
+
* whose descendants include a `Wizard` element. `FormMeta.wizardUrl` is
|
|
147
|
+
* what the client posts to on Next-button clicks; forms without a wizard
|
|
148
|
+
* descendant skip wiring.
|
|
149
|
+
*/
|
|
150
|
+
export function tagFormWizardUrls(elements, urlBuilder) {
|
|
151
|
+
for (const form of findForms(elements)) {
|
|
152
|
+
if (formHasWizard(form)) {
|
|
153
|
+
form.withWizardUrl(urlBuilder(form.getFormId()));
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Stamp `_agentRunBase` on every field element in the resolved
|
|
159
|
+
* `ElementMeta[]` tree that carries `aiActions`. Operates on the
|
|
160
|
+
* post-`resolveSchema` wire shape (plain objects) rather than on
|
|
161
|
+
* `Element` instances — `aiActions` is added by the `field-ai.ts`
|
|
162
|
+
* wrapper during `toMeta()`, so it isn't visible to pre-resolve walkers.
|
|
163
|
+
*
|
|
164
|
+
* Only called on edit pages where a `recordId` is known. Create pages
|
|
165
|
+
* deliberately skip it — field AI actions target existing content.
|
|
166
|
+
*/
|
|
167
|
+
export function tagFieldAiUrls(elements, agentBase) {
|
|
168
|
+
for (const el of elements) {
|
|
169
|
+
if (Array.isArray(el['aiActions']) && el['aiActions'].length > 0) {
|
|
170
|
+
;
|
|
171
|
+
el['_agentRunBase'] = agentBase;
|
|
172
|
+
}
|
|
173
|
+
const children = el['children'];
|
|
174
|
+
if (Array.isArray(children))
|
|
175
|
+
tagFieldAiUrls(children, agentBase);
|
|
176
|
+
// Repeater rows
|
|
177
|
+
const rows = el['rows'];
|
|
178
|
+
if (Array.isArray(rows)) {
|
|
179
|
+
for (const row of rows) {
|
|
180
|
+
const rowChildren = row['children'];
|
|
181
|
+
if (Array.isArray(rowChildren))
|
|
182
|
+
tagFieldAiUrls(rowChildren, agentBase);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Audit row 2026-05-07 cont'd⁸ — stamp the inline-create-option endpoint
|
|
189
|
+
* URL on every `SelectField` that has called `createOptionForm()`. Walks
|
|
190
|
+
* every form on the page so the URL carries the parent form's id; URL
|
|
191
|
+
* shape `${formScopeUrl}/_form/${formId}/create-option/${fieldName}` so
|
|
192
|
+
* the route handler can pick the form by id and the field by name.
|
|
193
|
+
*
|
|
194
|
+
* Mirrors `tagFormStateUrls / tagFormWizardUrls` — operates on the
|
|
195
|
+
* un-resolved Element tree, mutates field-instance state via
|
|
196
|
+
* `field.withCreateOptionUrl(url)`, and the field's `toMeta()` reads it
|
|
197
|
+
* back to emit `createOption.url`.
|
|
198
|
+
*
|
|
199
|
+
* Stops at Repeater / Builder boundaries (parallel to the form-state /
|
|
200
|
+
* wizard walkers): inside-row schemas are dispatched per-row and the
|
|
201
|
+
* createOption shape doesn't compose with row body coercion in v1.
|
|
202
|
+
*/
|
|
203
|
+
export function tagSelectCreateOptionUrls(elements, urlBuilder) {
|
|
204
|
+
for (const form of findForms(elements)) {
|
|
205
|
+
const formId = form.getFormId();
|
|
206
|
+
walkSelectFields(form.getChildren() ?? [], (field) => {
|
|
207
|
+
if (field.hasCreateOption() && !field.getCreateOptionUrl()) {
|
|
208
|
+
field.withCreateOptionUrl(urlBuilder(formId, field.name));
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
export function walkSelectFields(elements, visit) {
|
|
214
|
+
for (const el of elements) {
|
|
215
|
+
if (el instanceof SelectField) {
|
|
216
|
+
visit(el);
|
|
217
|
+
// SelectField has no children of its own — no recursion needed.
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
// Stop at row-array boundaries — see comment on `tagSelectCreateOptionUrls`.
|
|
221
|
+
if (el instanceof RepeaterField)
|
|
222
|
+
continue;
|
|
223
|
+
if (el instanceof BuilderField)
|
|
224
|
+
continue;
|
|
225
|
+
const children = el.getChildren();
|
|
226
|
+
if (children && children.length > 0)
|
|
227
|
+
walkSelectFields(children, visit);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
export function isAsyncMentionField(el) {
|
|
231
|
+
if (el.getType() !== 'richtext')
|
|
232
|
+
return false;
|
|
233
|
+
const candidate = el;
|
|
234
|
+
return typeof candidate.hasAsyncMentions === 'function'
|
|
235
|
+
&& typeof candidate.withMentionsUrl === 'function';
|
|
236
|
+
}
|
|
237
|
+
export function tagRichTextMentionUrls(elements, urlBuilder) {
|
|
238
|
+
for (const form of findForms(elements)) {
|
|
239
|
+
const url = urlBuilder(form.getFormId());
|
|
240
|
+
const visit = (els) => {
|
|
241
|
+
for (const el of els) {
|
|
242
|
+
// Don't cross into nested forms — each form gets its own URL.
|
|
243
|
+
if (el !== form && el.getType() === 'form')
|
|
244
|
+
continue;
|
|
245
|
+
if (isAsyncMentionField(el) && el.hasAsyncMentions()) {
|
|
246
|
+
el.withMentionsUrl(url);
|
|
247
|
+
}
|
|
248
|
+
// Builder.getChildren() returns undefined to keep the field-level
|
|
249
|
+
// walkers from treating heterogeneous rows as flat children. Manual
|
|
250
|
+
// descent into each block's schema covers the URL-stamping path
|
|
251
|
+
// without changing the no-cross posture for save/coerce.
|
|
252
|
+
if (isBuilderField(el)) {
|
|
253
|
+
for (const block of el.getBlocks())
|
|
254
|
+
visit(block.getSchema());
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
const children = el.getChildren();
|
|
258
|
+
if (children)
|
|
259
|
+
visit(children);
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
const children = form.getChildren();
|
|
263
|
+
if (children)
|
|
264
|
+
visit(children);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
export function formHasLiveField(form) {
|
|
268
|
+
let found = false;
|
|
269
|
+
const visit = (els) => {
|
|
270
|
+
for (const el of els) {
|
|
271
|
+
if (found)
|
|
272
|
+
return;
|
|
273
|
+
// Either a server-side `live()` (drives a roundtrip) OR a
|
|
274
|
+
// client-side `afterStateUpdatedJs(body)` (JS-only) is enough to
|
|
275
|
+
// mount the controlled-form path: the FormStateProvider holds the
|
|
276
|
+
// values map either path needs, and the client gates the actual
|
|
277
|
+
// network POST on `live` separately. Cost of the over-stamp for
|
|
278
|
+
// JS-only forms is one unused endpoint URL per form — endpoint
|
|
279
|
+
// never gets hit because the client only POSTs on `live`.
|
|
280
|
+
if (el instanceof Field && (el.isLive() || el.getAfterStateUpdatedJs() !== undefined)) {
|
|
281
|
+
found = true;
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
const children = el.getChildren();
|
|
285
|
+
if (children)
|
|
286
|
+
visit(children);
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
const children = form.getChildren();
|
|
290
|
+
if (children)
|
|
291
|
+
visit(children);
|
|
292
|
+
return found;
|
|
293
|
+
}
|
|
294
|
+
export function formHasWizard(form) {
|
|
295
|
+
let found = false;
|
|
296
|
+
const visit = (els) => {
|
|
297
|
+
for (const el of els) {
|
|
298
|
+
if (found)
|
|
299
|
+
return;
|
|
300
|
+
if (el.getType() === 'wizard') {
|
|
301
|
+
found = true;
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
const children = el.getChildren();
|
|
305
|
+
if (children)
|
|
306
|
+
visit(children);
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
const children = form.getChildren();
|
|
310
|
+
if (children)
|
|
311
|
+
visit(children);
|
|
312
|
+
return found;
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Run the edit-mode fill pipeline on a loaded record:
|
|
316
|
+
* mutateFormDataBeforeFill → fillFromRecord → mutateFormDataAfterFill
|
|
317
|
+
*
|
|
318
|
+
* `fillFromRecord` defaults to `{ ...record }` when not configured. Both
|
|
319
|
+
* mutators are optional and may be async. `ctx.record` is the loaded
|
|
320
|
+
* record so mutators can read from fields the form doesn't surface.
|
|
321
|
+
*/
|
|
322
|
+
export async function applyFillPipeline(form, record) {
|
|
323
|
+
const recordObj = record;
|
|
324
|
+
let values = { ...recordObj };
|
|
325
|
+
const before = form.getMutateFormDataBeforeFill();
|
|
326
|
+
if (before)
|
|
327
|
+
values = await before(values, { values, record });
|
|
328
|
+
const fill = form.getFillFromRecord();
|
|
329
|
+
if (fill)
|
|
330
|
+
values = fill(record);
|
|
331
|
+
const after = form.getMutateFormDataAfterFill();
|
|
332
|
+
if (after)
|
|
333
|
+
values = await after(values, { values, record });
|
|
334
|
+
return values;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Walk the form's top-level Repeaters and replace `values[fieldName]`
|
|
338
|
+
* with rows fetched from `parent.related(name)` for any
|
|
339
|
+
* relationship-backed Repeater. Each loaded row stamps `__id` to the
|
|
340
|
+
* child's primary key so the renderer can round-trip identity through
|
|
341
|
+
* a hidden input and the save-side diff can match submitted rows back
|
|
342
|
+
* to existing records.
|
|
343
|
+
*
|
|
344
|
+
* No-op when the parent record is null (create mode), when no
|
|
345
|
+
* relationship-backed Repeaters exist on the form, or when the
|
|
346
|
+
* resource has no `R.model` (relation queries need it).
|
|
347
|
+
*
|
|
348
|
+
* Mutates and returns a fresh values object — never the input.
|
|
349
|
+
*/
|
|
350
|
+
export async function applyRelationshipRepeaterFill(form, values, record, parentModel) {
|
|
351
|
+
if (record == null)
|
|
352
|
+
return values;
|
|
353
|
+
if (!parentModel)
|
|
354
|
+
return values;
|
|
355
|
+
const repeaters = findRelationshipRepeaters(form.getChildren() ?? []);
|
|
356
|
+
if (repeaters.length === 0)
|
|
357
|
+
return values;
|
|
358
|
+
const out = { ...values };
|
|
359
|
+
for (const repeater of repeaters) {
|
|
360
|
+
const cfg = repeater.getRelationship();
|
|
361
|
+
const pivotColumns = cfg.pivotColumns;
|
|
362
|
+
let rows;
|
|
363
|
+
try {
|
|
364
|
+
rows = await loadRelationRows(parentModel, record, cfg.name, pivotColumns);
|
|
365
|
+
}
|
|
366
|
+
catch {
|
|
367
|
+
// Failed lookup (e.g. missing `relations` map on a test stub)
|
|
368
|
+
// — fall back to whatever value applyFillPipeline produced
|
|
369
|
+
// rather than wiping the field. Better to render stale data
|
|
370
|
+
// than to silently empty the row list.
|
|
371
|
+
continue;
|
|
372
|
+
}
|
|
373
|
+
// The child model is opaque here — we don't have the full
|
|
374
|
+
// descriptor at this seam, so use the configured override or
|
|
375
|
+
// peek the parent's relations map for the FK column. Strip it
|
|
376
|
+
// (and the PK) from each row's payload so the inner schema
|
|
377
|
+
// doesn't surface them as form values. For morphMany the
|
|
378
|
+
// attachment is two columns instead of one — strip both.
|
|
379
|
+
const pkColumn = pickChildPrimaryKey(parentModel, cfg.name) ?? 'id';
|
|
380
|
+
const fkColumn = cfg.foreignKey ?? pickChildForeignKey(parentModel, cfg.name);
|
|
381
|
+
const morph = getMorphRelationDescriptor(parentModel, cfg.name);
|
|
382
|
+
const morphIdCol = morph ? `${morph.morphName}Id` : undefined;
|
|
383
|
+
const morphTyCol = morph ? `${morph.morphName}Type` : undefined;
|
|
384
|
+
out[repeater.name] = rows.map(row => {
|
|
385
|
+
const r = (row && typeof row === 'object') ? { ...row } : {};
|
|
386
|
+
const pkValue = r[pkColumn];
|
|
387
|
+
delete r[pkColumn];
|
|
388
|
+
if (fkColumn)
|
|
389
|
+
delete r[fkColumn];
|
|
390
|
+
if (morphIdCol)
|
|
391
|
+
delete r[morphIdCol];
|
|
392
|
+
if (morphTyCol)
|
|
393
|
+
delete r[morphTyCol];
|
|
394
|
+
// M2M pivot extras — flatten `row.pivot[col]` onto the row's data
|
|
395
|
+
// so each pivot column round-trips through the inner schema as a
|
|
396
|
+
// regular form field. The pivot envelope itself is dropped from
|
|
397
|
+
// the values shape — the persist side splits pivot vs child
|
|
398
|
+
// columns by name lookup against `cfg.pivotColumns`.
|
|
399
|
+
const pivotEnvelope = r['pivot'];
|
|
400
|
+
delete r['pivot'];
|
|
401
|
+
const stamped = { ...r };
|
|
402
|
+
if (pivotColumns && pivotColumns.length > 0
|
|
403
|
+
&& pivotEnvelope && typeof pivotEnvelope === 'object') {
|
|
404
|
+
const pe = pivotEnvelope;
|
|
405
|
+
for (const col of pivotColumns) {
|
|
406
|
+
if (col in pe)
|
|
407
|
+
stamped[col] = pe[col];
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
if (pkValue !== undefined && pkValue !== null) {
|
|
411
|
+
stamped['__id'] = String(pkValue);
|
|
412
|
+
}
|
|
413
|
+
return stamped;
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
return out;
|
|
417
|
+
}
|
|
418
|
+
/** Walk the form's children for top-level relationship-backed Repeaters. */
|
|
419
|
+
export function findRelationshipRepeaters(elements) {
|
|
420
|
+
const out = [];
|
|
421
|
+
const walk = (els) => {
|
|
422
|
+
for (const el of els) {
|
|
423
|
+
if (isRepeaterField(el)) {
|
|
424
|
+
const r = el;
|
|
425
|
+
if (r.getRelationship())
|
|
426
|
+
out.push(r);
|
|
427
|
+
// Don't dive into Repeater children — relationship-on-relationship
|
|
428
|
+
// isn't supported in v1.
|
|
429
|
+
continue;
|
|
430
|
+
}
|
|
431
|
+
// Don't dive into Builder children either — relationship-backed
|
|
432
|
+
// Builders are resolved separately by `findRelationshipBuilders`.
|
|
433
|
+
if (isBuilderField(el))
|
|
434
|
+
continue;
|
|
435
|
+
const children = el.getChildren();
|
|
436
|
+
if (children && children.length > 0)
|
|
437
|
+
walk(children);
|
|
438
|
+
}
|
|
439
|
+
};
|
|
440
|
+
walk(elements);
|
|
441
|
+
return out;
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* Walk the form's top-level Builders and replace `values[fieldName]` with
|
|
445
|
+
* rows fetched from `parent.related(name)` for any relationship-backed
|
|
446
|
+
* Builder. Each loaded row stamps `__id` (child PK) + `type` (block
|
|
447
|
+
* discriminator) + `data` (per-block JSON payload) so the renderer can
|
|
448
|
+
* round-trip the heterogeneous envelope.
|
|
449
|
+
*
|
|
450
|
+
* Mirrors `applyRelationshipRepeaterFill`. No-op when the parent record
|
|
451
|
+
* is null (create mode), the resource has no `R.model`, or no
|
|
452
|
+
* relationship-backed Builders exist on the form.
|
|
453
|
+
*/
|
|
454
|
+
export async function applyRelationshipBuilderFill(form, values, record, parentModel) {
|
|
455
|
+
if (record == null)
|
|
456
|
+
return values;
|
|
457
|
+
if (!parentModel)
|
|
458
|
+
return values;
|
|
459
|
+
const builders = findRelationshipBuilders(form.getChildren() ?? []);
|
|
460
|
+
if (builders.length === 0)
|
|
461
|
+
return values;
|
|
462
|
+
const out = { ...values };
|
|
463
|
+
for (const builder of builders) {
|
|
464
|
+
const cfg = builder.getRelationship();
|
|
465
|
+
let rows;
|
|
466
|
+
try {
|
|
467
|
+
rows = await loadRelationRows(parentModel, record, cfg.name);
|
|
468
|
+
}
|
|
469
|
+
catch {
|
|
470
|
+
// Failed lookup (e.g. missing `relations` map on a test stub) —
|
|
471
|
+
// fall back to whatever value applyFillPipeline produced rather
|
|
472
|
+
// than wiping the field. Better stale than silently empty.
|
|
473
|
+
continue;
|
|
474
|
+
}
|
|
475
|
+
const pkColumn = pickChildPrimaryKey(parentModel, cfg.name) ?? 'id';
|
|
476
|
+
const fkColumn = cfg.foreignKey ?? pickChildForeignKey(parentModel, cfg.name);
|
|
477
|
+
const typeColumn = cfg.typeColumn ?? 'type';
|
|
478
|
+
const dataColumn = cfg.dataColumn ?? 'data';
|
|
479
|
+
out[builder.name] = rows.map(row => {
|
|
480
|
+
const r = (row && typeof row === 'object') ? { ...row } : {};
|
|
481
|
+
const pkValue = r[pkColumn];
|
|
482
|
+
const blockType = typeof r[typeColumn] === 'string' ? r[typeColumn] : '';
|
|
483
|
+
const dataRaw = r[dataColumn];
|
|
484
|
+
const blockData = parseBuilderDataPayload(dataRaw);
|
|
485
|
+
const stamped = {
|
|
486
|
+
type: blockType,
|
|
487
|
+
data: blockData,
|
|
488
|
+
};
|
|
489
|
+
if (pkValue !== undefined && pkValue !== null) {
|
|
490
|
+
stamped['__id'] = String(pkValue);
|
|
491
|
+
}
|
|
492
|
+
// Non-`type` / `data` / FK / PK columns aren't surfaced — the
|
|
493
|
+
// JSON envelope is the source of truth for per-block fields. If
|
|
494
|
+
// a user denormalizes a column, they handle it via per-block
|
|
495
|
+
// mutate hooks, not by leaking the column into row values.
|
|
496
|
+
void fkColumn;
|
|
497
|
+
return stamped;
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
return out;
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* Normalize the JSON payload column into a plain object. Prisma
|
|
504
|
+
* hydrates `Json` columns to objects; some adapters return strings.
|
|
505
|
+
* Anything that isn't a parseable object falls back to `{}` so the
|
|
506
|
+
* inner schema renders fresh defaults.
|
|
507
|
+
*/
|
|
508
|
+
export function parseBuilderDataPayload(raw) {
|
|
509
|
+
if (raw && typeof raw === 'object' && !Array.isArray(raw)) {
|
|
510
|
+
return raw;
|
|
511
|
+
}
|
|
512
|
+
if (typeof raw === 'string') {
|
|
513
|
+
try {
|
|
514
|
+
const parsed = JSON.parse(raw);
|
|
515
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
516
|
+
return parsed;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
catch {
|
|
520
|
+
// fall through to {}
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
return {};
|
|
524
|
+
}
|
|
525
|
+
/** Walk the form's children for top-level relationship-backed Builders. */
|
|
526
|
+
export function findRelationshipBuilders(elements) {
|
|
527
|
+
const out = [];
|
|
528
|
+
const walk = (els) => {
|
|
529
|
+
for (const el of els) {
|
|
530
|
+
if (isBuilderField(el)) {
|
|
531
|
+
const b = el;
|
|
532
|
+
if (b.getRelationship())
|
|
533
|
+
out.push(b);
|
|
534
|
+
continue;
|
|
535
|
+
}
|
|
536
|
+
// Don't dive into Repeater children either — both array-row
|
|
537
|
+
// boundaries are walker stops here.
|
|
538
|
+
if (isRepeaterField(el))
|
|
539
|
+
continue;
|
|
540
|
+
const children = el.getChildren();
|
|
541
|
+
if (children && children.length > 0)
|
|
542
|
+
walk(children);
|
|
543
|
+
}
|
|
544
|
+
};
|
|
545
|
+
walk(elements);
|
|
546
|
+
return out;
|
|
547
|
+
}
|
|
548
|
+
/** Read the child model's PK column from the parent's relations map, when present. */
|
|
549
|
+
export function pickChildPrimaryKey(parentModel, name) {
|
|
550
|
+
const relations = parentModel['relations'];
|
|
551
|
+
if (!relations || typeof relations !== 'object')
|
|
552
|
+
return undefined;
|
|
553
|
+
const entry = relations[name];
|
|
554
|
+
if (!entry || typeof entry !== 'object')
|
|
555
|
+
return undefined;
|
|
556
|
+
const e = entry;
|
|
557
|
+
if (typeof e['model'] !== 'function')
|
|
558
|
+
return undefined;
|
|
559
|
+
try {
|
|
560
|
+
const child = e['model']();
|
|
561
|
+
return getPrimaryKey(child);
|
|
562
|
+
}
|
|
563
|
+
catch {
|
|
564
|
+
return undefined;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
/** Read the FK column from the parent's relations map, when present. */
|
|
568
|
+
export function pickChildForeignKey(parentModel, name) {
|
|
569
|
+
const relations = parentModel['relations'];
|
|
570
|
+
if (!relations || typeof relations !== 'object')
|
|
571
|
+
return undefined;
|
|
572
|
+
const entry = relations[name];
|
|
573
|
+
if (!entry || typeof entry !== 'object')
|
|
574
|
+
return undefined;
|
|
575
|
+
const e = entry;
|
|
576
|
+
return typeof e['foreignKey'] === 'string' ? e['foreignKey'] : undefined;
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* Plan #15 — collect every `ServerDataElement` in the schema tree and
|
|
580
|
+
* resolve their `getServerData(ctx)` payloads in parallel. Returns a
|
|
581
|
+
* map keyed by element id, ready to ship as `viewProps._widgetData`.
|
|
582
|
+
*
|
|
583
|
+
* Lazy elements (default — `lazy(false)` opts out) skip the hook and
|
|
584
|
+
* stamp `null` so the renderer paints a skeleton and fetches the
|
|
585
|
+
* payload via `POST {base}/_widget/:id` on mount. Eager elements
|
|
586
|
+
* resolve synchronously and ship the data with the page.
|
|
587
|
+
*
|
|
588
|
+
* Per-widget errors are caught and surfaced as `{ error: '...' }` —
|
|
589
|
+
* one flaky `getStats()` shouldn't 500 the entire dashboard.
|
|
590
|
+
*
|
|
591
|
+
* Visibility is **not** re-evaluated here. The schema resolver
|
|
592
|
+
* (`resolveSchema → evaluateVisibility`) drops hidden layout elements
|
|
593
|
+
* before any widget code runs. Widgets inside still-rendered branches
|
|
594
|
+
* always resolve (or stamp lazy null).
|
|
595
|
+
*/
|
|
596
|
+
export async function resolveServerDataElements(elements, ctx) {
|
|
597
|
+
const widgets = collectServerDataElements(elements);
|
|
598
|
+
if (widgets.length === 0)
|
|
599
|
+
return {};
|
|
600
|
+
const out = {};
|
|
601
|
+
await Promise.all(widgets.map(async (el) => {
|
|
602
|
+
const id = el.getId();
|
|
603
|
+
if (el.isLazy()) {
|
|
604
|
+
out[id] = null; // sentinel — renderer paints skeleton, fetches on mount
|
|
605
|
+
return;
|
|
606
|
+
}
|
|
607
|
+
try {
|
|
608
|
+
out[id] = await el.resolveServerData(ctx);
|
|
609
|
+
}
|
|
610
|
+
catch (err) {
|
|
611
|
+
out[id] = { error: err instanceof Error ? err.message : 'Widget failed to load' };
|
|
612
|
+
}
|
|
613
|
+
}));
|
|
614
|
+
return out;
|
|
615
|
+
}
|
|
616
|
+
/** Walk the tree collecting every `ServerDataElement`. Walks into
|
|
617
|
+
* containers but stops at Form/Repeater/Builder boundaries — widgets
|
|
618
|
+
* inside an editable form don't make sense in v1. */
|
|
619
|
+
export function collectServerDataElements(elements) {
|
|
620
|
+
const out = [];
|
|
621
|
+
const walk = (els) => {
|
|
622
|
+
for (const el of els) {
|
|
623
|
+
if (isServerDataElement(el)) {
|
|
624
|
+
out.push(el);
|
|
625
|
+
// Don't recurse into a widget's children — `View` etc. are leaves
|
|
626
|
+
// for v1 (no nested widgets inside widgets).
|
|
627
|
+
continue;
|
|
628
|
+
}
|
|
629
|
+
// Skip walkers that imply per-row resolution — widgets inside
|
|
630
|
+
// Repeater/Builder rows don't have a stable id space.
|
|
631
|
+
const type = el.getType();
|
|
632
|
+
if (type === 'form' || type === 'repeater' || type === 'builder' || type === 'table' || type === 'tableWidget')
|
|
633
|
+
continue;
|
|
634
|
+
const children = el.getChildren();
|
|
635
|
+
if (children)
|
|
636
|
+
walk(children);
|
|
637
|
+
}
|
|
638
|
+
};
|
|
639
|
+
walk(elements);
|
|
640
|
+
return out;
|
|
641
|
+
}
|
|
642
|
+
/**
|
|
643
|
+
* Plan #15 — stamp the polling-endpoint URL on every `ServerDataElement`
|
|
644
|
+
* in the tree. Mirrors `tagFormStateUrls / tagTableReorderUrls`. Walks
|
|
645
|
+
* with the same boundaries as `collectServerDataElements` so the wire
|
|
646
|
+
* stays in sync (no orphan widgets without URLs and vice versa).
|
|
647
|
+
*
|
|
648
|
+
* `urlBuilder(id)` typically produces `${base}/_widget/${id}` for
|
|
649
|
+
* dashboard widgets and `${base}/${pageSlug}/_widget/${id}` for
|
|
650
|
+
* custom-page widgets — the route handlers for both shapes are wired up
|
|
651
|
+
* in `routes.ts` (see Phase A.4).
|
|
652
|
+
*/
|
|
653
|
+
export function tagWidgetUrls(elements, urlBuilder) {
|
|
654
|
+
for (const widget of collectServerDataElements(elements)) {
|
|
655
|
+
if (widget.getWidgetUrl())
|
|
656
|
+
continue; // user-set wins
|
|
657
|
+
widget.withWidgetUrl(urlBuilder(widget.getId()));
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
/**
|
|
661
|
+
* Stamp every form-subresource URL the page might need in one pass:
|
|
662
|
+
* - `_form/${formId}/state` (Plan #5 partial-resolve)
|
|
663
|
+
* - `_form/${formId}/wizard` (Plan #8 step-validate)
|
|
664
|
+
* - `_form/${formId}/mentions` (async-mention typeahead)
|
|
665
|
+
* - `_form/${formId}/create-option/${fieldName}` (SelectField inline-create)
|
|
666
|
+
*
|
|
667
|
+
* Every page-builder that mounts a form (dashboard / resource create+edit /
|
|
668
|
+
* global edit / custom page) needs all four — the underlying taggers skip
|
|
669
|
+
* forms that don't carry the matching feature, so this is always safe to
|
|
670
|
+
* call. `base` is the route prefix (e.g. `${cfg.path}` / `${resourceBase}` /
|
|
671
|
+
* `${resourceBase}/${recordId}` / `${pageUrl}`).
|
|
672
|
+
*/
|
|
673
|
+
export function tagFormSubresourceUrls(elements, base) {
|
|
674
|
+
tagFormStateUrls(elements, formId => `${base}/_form/${formId}/state`);
|
|
675
|
+
tagFormWizardUrls(elements, formId => `${base}/_form/${formId}/wizard`);
|
|
676
|
+
tagRichTextMentionUrls(elements, formId => `${base}/_form/${formId}/mentions`);
|
|
677
|
+
tagSelectCreateOptionUrls(elements, (formId, fieldName) => `${base}/_form/${formId}/create-option/${fieldName}`);
|
|
678
|
+
}
|
|
679
|
+
/** Stamp dispatchUrl on every handler-style Action so the client knows where to POST. */
|
|
680
|
+
export function tagActionDispatch(elements, baseUrl) {
|
|
681
|
+
for (const action of findActions(elements)) {
|
|
682
|
+
if (!action.getHandler())
|
|
683
|
+
continue;
|
|
684
|
+
if (action.getHref() || action.getMethod())
|
|
685
|
+
continue;
|
|
686
|
+
if (action.getDispatchUrl())
|
|
687
|
+
continue;
|
|
688
|
+
action.dispatchUrl(`${baseUrl}/_action/${action.name}`);
|
|
689
|
+
}
|
|
690
|
+
// Row-scoped extraItemActions (Repeater/Builder). Stamped here too so
|
|
691
|
+
// the client can POST to the same `_action/:name` route — the renderer
|
|
692
|
+
// attaches `_rowPath=<fieldName>.<index>` per click; the server's
|
|
693
|
+
// dispatcher uses that to walk into the right row when building
|
|
694
|
+
// `ctx.row`. See `findRowExtraActions` in `dispatchAction.ts`.
|
|
695
|
+
for (const { action } of findRowExtraActions(elements)) {
|
|
696
|
+
if (!action.getHandler())
|
|
697
|
+
continue;
|
|
698
|
+
if (action.getDispatchUrl())
|
|
699
|
+
continue;
|
|
700
|
+
action.dispatchUrl(`${baseUrl}/_action/${action.name}`);
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
//# sourceMappingURL=helpers.js.map
|