payload-canvas 0.4.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +626 -154
- package/dist/admin/AiKeyField.d.ts +8 -0
- package/dist/admin/AiKeyField.js +54 -0
- package/dist/admin/BuilderTab.js +4 -1
- package/dist/admin/DocumentEditView.d.ts +9 -0
- package/dist/admin/DocumentEditView.js +45 -0
- package/dist/admin/LayoutField.d.ts +2 -2
- package/dist/admin/LayoutField.js +10 -7
- package/dist/admin/TemplateConditionsField.d.ts +9 -0
- package/dist/admin/TemplateConditionsField.js +22 -0
- package/dist/admin/aiKeyField.scss +58 -0
- package/dist/admin/client.d.ts +3 -0
- package/dist/admin/client.js +6 -0
- package/dist/admin/diff/changes.js +5 -0
- package/dist/admin/editor/Canvas.js +20 -5
- package/dist/admin/editor/Editor.d.ts +3 -1
- package/dist/admin/editor/Editor.js +6 -3
- package/dist/admin/editor/Inspector.js +75 -28
- package/dist/admin/editor/Library.js +40 -15
- package/dist/admin/editor/Outline.js +21 -16
- package/dist/admin/editor/Overlay.js +8 -3
- package/dist/admin/editor/actions.d.ts +10 -2
- package/dist/admin/editor/actions.js +18 -3
- package/dist/admin/editor/assistant/AssistantPanel.js +3 -1
- package/dist/admin/editor/classes/ClassManager.d.ts +4 -0
- package/dist/admin/editor/classes/ClassManager.js +56 -0
- package/dist/admin/editor/classes/controller.d.ts +112 -0
- package/dist/admin/editor/classes/controller.js +326 -0
- package/dist/admin/editor/classes/manager.scss +262 -0
- package/dist/admin/editor/classes/managerModel.d.ts +5 -0
- package/dist/admin/editor/classes/managerModel.js +27 -0
- package/dist/admin/editor/comments/CommentLayer.d.ts +2 -0
- package/dist/admin/editor/comments/CommentLayer.js +143 -0
- package/dist/admin/editor/comments/CommentsPanel.d.ts +8 -0
- package/dist/admin/editor/comments/CommentsPanel.js +73 -0
- package/dist/admin/editor/comments/Thread.d.ts +26 -0
- package/dist/admin/editor/comments/Thread.js +84 -0
- package/dist/admin/editor/comments/comments.scss +539 -0
- package/dist/admin/editor/comments/controller.d.ts +48 -0
- package/dist/admin/editor/comments/controller.js +142 -0
- package/dist/admin/editor/contentMode.d.ts +17 -0
- package/dist/admin/editor/contentMode.js +37 -0
- package/dist/admin/editor/dnd/DropOutlines.d.ts +1 -0
- package/dist/admin/editor/dnd/DropOutlines.js +73 -0
- package/dist/admin/editor/dnd/dnd.scss +43 -0
- package/dist/admin/editor/dnd/mode.d.ts +4 -0
- package/dist/admin/editor/dnd/mode.js +39 -0
- package/dist/admin/editor/editor.scss +13 -58
- package/dist/admin/editor/empty/EmptyStart.js +18 -66
- package/dist/admin/editor/fields/AddButton.d.ts +15 -0
- package/dist/admin/editor/fields/AddButton.js +14 -0
- package/dist/admin/editor/fields/ArrayField.js +3 -2
- package/dist/admin/editor/fields/CheckedInputs.d.ts +1 -0
- package/dist/admin/editor/fields/ConditionRows.d.ts +19 -0
- package/dist/admin/editor/fields/ConditionRows.js +137 -0
- package/dist/admin/editor/fields/ListWhereField.d.ts +8 -0
- package/dist/admin/editor/fields/ListWhereField.js +20 -0
- package/dist/admin/editor/fields/QueryFiltersField.d.ts +18 -0
- package/dist/admin/editor/fields/QueryFiltersField.js +41 -0
- package/dist/admin/editor/fields/RelatedField.d.ts +19 -0
- package/dist/admin/editor/fields/RelatedField.js +44 -0
- package/dist/admin/editor/fields/SortField.d.ts +13 -0
- package/dist/admin/editor/fields/SortField.js +37 -0
- package/dist/admin/editor/fields/WhereField.d.ts +12 -4
- package/dist/admin/editor/fields/WhereField.js +33 -53
- package/dist/admin/editor/fields/collectionFields.d.ts +6 -0
- package/dist/admin/editor/fields/collectionFields.js +15 -0
- package/dist/admin/editor/fields/conditions.d.ts +99 -0
- package/dist/admin/editor/fields/conditions.js +339 -0
- package/dist/admin/editor/fields/fields.scss +232 -9
- package/dist/admin/editor/fields/listOptions.d.ts +44 -0
- package/dist/admin/editor/fields/listOptions.js +111 -0
- package/dist/admin/editor/fields/queryFilterRows.d.ts +8 -0
- package/dist/admin/editor/fields/queryFilterRows.js +29 -0
- package/dist/admin/editor/fields/whereRows.d.ts +11 -12
- package/dist/admin/editor/fields/whereRows.js +83 -34
- package/dist/admin/editor/icons.d.ts +16 -1
- package/dist/admin/editor/icons.js +30 -1
- package/dist/admin/editor/inline.js +9 -0
- package/dist/admin/editor/insert/InsertHandle.js +4 -1
- package/dist/admin/editor/insert/picker.d.ts +3 -1
- package/dist/admin/editor/insert/picker.js +17 -10
- package/dist/admin/editor/insert/spots.d.ts +12 -1
- package/dist/admin/editor/insert/spots.js +49 -10
- package/dist/admin/editor/layout/LeftPanel.js +11 -6
- package/dist/admin/editor/live/useMultiplayer.js +9 -1
- package/dist/admin/editor/menu/blockMenu.js +27 -17
- package/dist/admin/editor/names.js +11 -3
- package/dist/admin/editor/renderField.d.ts +3 -1
- package/dist/admin/editor/renderField.js +63 -12
- package/dist/admin/editor/runtime.d.ts +14 -0
- package/dist/admin/editor/runtime.js +67 -6
- package/dist/admin/editor/sections/ComponentFields.d.ts +8 -0
- package/dist/admin/editor/sections/ComponentFields.js +116 -0
- package/dist/admin/editor/sections/PropertyControls.d.ts +18 -0
- package/dist/admin/editor/sections/PropertyControls.js +65 -0
- package/dist/admin/editor/sections/components.d.ts +29 -0
- package/dist/admin/editor/sections/components.js +112 -0
- package/dist/admin/editor/sections/components.scss +238 -0
- package/dist/admin/editor/sections/variants.d.ts +32 -0
- package/dist/admin/editor/sections/variants.js +59 -0
- package/dist/admin/editor/sections/variants.scss +90 -0
- package/dist/admin/editor/shortcuts.d.ts +4 -1
- package/dist/admin/editor/shortcuts.js +19 -3
- package/dist/admin/editor/store.d.ts +18 -0
- package/dist/admin/editor/store.js +46 -0
- package/dist/admin/editor/styles/ClassBar.d.ts +14 -0
- package/dist/admin/editor/styles/ClassBar.js +90 -0
- package/dist/admin/editor/styles/ClassCss.d.ts +4 -0
- package/dist/admin/editor/styles/ClassCss.js +28 -0
- package/dist/admin/editor/styles/ClassDialog.d.ts +2 -0
- package/dist/admin/editor/styles/ClassDialog.js +151 -0
- package/dist/admin/editor/styles/ColorPicker.js +5 -2
- package/dist/admin/editor/styles/RawClasses.d.ts +26 -1
- package/dist/admin/editor/styles/RawClasses.js +184 -32
- package/dist/admin/editor/styles/StylesPanel.d.ts +3 -3
- package/dist/admin/editor/styles/StylesPanel.js +53 -14
- package/dist/admin/editor/styles/VariantBar.js +2 -2
- package/dist/admin/editor/styles/classEdit.d.ts +4 -0
- package/dist/admin/editor/styles/classEdit.js +20 -0
- package/dist/admin/editor/styles/classes.scss +381 -0
- package/dist/admin/editor/styles/context.d.ts +19 -6
- package/dist/admin/editor/styles/context.js +24 -6
- package/dist/admin/editor/styles/controls.d.ts +3 -1
- package/dist/admin/editor/styles/controls.js +30 -12
- package/dist/admin/editor/styles/popover.d.ts +6 -0
- package/dist/admin/editor/styles/popover.js +5 -5
- package/dist/admin/editor/styles/styles.scss +26 -104
- package/dist/admin/editor/styles/suggestions.d.ts +22 -0
- package/dist/admin/editor/styles/suggestions.js +77 -0
- package/dist/admin/editor/styles/tokens.js +14 -0
- package/dist/admin/editor/templates/Bindable.js +86 -57
- package/dist/admin/editor/templates/SamplePicker.js +1 -1
- package/dist/admin/editor/templates/Visibility.d.ts +9 -0
- package/dist/admin/editor/templates/Visibility.js +54 -0
- package/dist/admin/editor/templates/binding.d.ts +2 -2
- package/dist/admin/editor/templates/binding.js +2 -2
- package/dist/admin/editor/templates/templates.scss +27 -0
- package/dist/admin/editor/templates/visibilityRows.d.ts +22 -0
- package/dist/admin/editor/templates/visibilityRows.js +83 -0
- package/dist/admin/editor/topbar/ContentModeToggle.d.ts +5 -0
- package/dist/admin/editor/topbar/ContentModeToggle.js +26 -0
- package/dist/admin/editor/topbar/DocumentActions.d.ts +1 -1
- package/dist/admin/editor/topbar/DocumentActions.js +5 -4
- package/dist/admin/editor/topbar/DocumentTitle.js +7 -2
- package/dist/admin/editor/topbar/TopBar.js +15 -3
- package/dist/admin/editor/topbar/contentMode.scss +35 -0
- package/dist/admin/editor/topbar/topbar.scss +3 -1
- package/dist/admin/formChoice.d.ts +3 -0
- package/dist/admin/formChoice.js +10 -0
- package/dist/admin/layoutField.scss +69 -0
- package/dist/admin/screen/BuilderScreen.d.ts +6 -1
- package/dist/admin/screen/BuilderScreen.js +4 -3
- package/dist/admin/server/BuilderView.js +10 -3
- package/dist/admin/templateConditions.scss +24 -0
- package/dist/ai/adapters/anthropic.js +17 -4
- package/dist/ai/adapters/cloudflare-gateway.js +7 -1
- package/dist/ai/adapters/cloudflare-workers-ai.js +2 -0
- package/dist/ai/adapters/openai-compatible.js +1 -0
- package/dist/ai/adapters/openrouter.js +2 -0
- package/dist/ai/config.d.ts +24 -4
- package/dist/ai/config.js +27 -8
- package/dist/ai/endpoint.d.ts +5 -2
- package/dist/ai/endpoint.js +31 -26
- package/dist/ai/images/cloudflare-workers-ai.js +6 -2
- package/dist/ai/images/openai.js +8 -3
- package/dist/ai/images/openrouter.js +6 -2
- package/dist/ai/images/service.d.ts +10 -4
- package/dist/ai/images/service.js +23 -7
- package/dist/ai/openai-format.d.ts +7 -0
- package/dist/ai/openai-format.js +17 -5
- package/dist/ai/prompt.d.ts +8 -0
- package/dist/ai/prompt.js +25 -5
- package/dist/ai/settings/index.d.ts +62 -0
- package/dist/ai/settings/index.js +264 -0
- package/dist/ai/settings/secret.d.ts +11 -0
- package/dist/ai/settings/secret.js +46 -0
- package/dist/ai/settings/shared.d.ts +22 -0
- package/dist/ai/settings/shared.js +3 -0
- package/dist/ai/tools.d.ts +3 -0
- package/dist/ai/tools.js +79 -15
- package/dist/ai/types.d.ts +43 -0
- package/dist/blocks/builtins/adjacentLinks.d.ts +5 -0
- package/dist/blocks/builtins/adjacentLinks.js +76 -0
- package/dist/blocks/builtins/carousel.d.ts +2 -29
- package/dist/blocks/builtins/carousel.js +44 -51
- package/dist/blocks/builtins/disclosure.d.ts +2 -1
- package/dist/blocks/builtins/disclosure.js +22 -32
- package/dist/blocks/builtins/embed.d.ts +15 -0
- package/dist/blocks/builtins/embed.js +47 -0
- package/dist/blocks/builtins/faq.d.ts +1 -1
- package/dist/blocks/builtins/faq.js +2 -2
- package/dist/blocks/builtins/filterLink.d.ts +1 -19
- package/dist/blocks/builtins/filterLink.js +9 -50
- package/dist/blocks/builtins/icon.d.ts +2 -0
- package/dist/blocks/builtins/icon.js +8 -8
- package/dist/blocks/builtins/index.d.ts +18 -13
- package/dist/blocks/builtins/index.js +43 -22
- package/dist/blocks/builtins/marquee.d.ts +5 -0
- package/dist/blocks/builtins/marquee.js +68 -0
- package/dist/blocks/builtins/popup.d.ts +5 -0
- package/dist/blocks/builtins/popup.js +83 -0
- package/dist/blocks/builtins/sectionRef.d.ts +16 -2
- package/dist/blocks/builtins/sectionRef.js +34 -12
- package/dist/blocks/builtins/shared.d.ts +18 -23
- package/dist/blocks/builtins/shared.js +34 -42
- package/dist/blocks/builtins/tableOfContents.d.ts +4 -0
- package/dist/blocks/builtins/tableOfContents.js +12 -18
- package/dist/blocks/builtins/tabs.d.ts +6 -0
- package/dist/blocks/builtins/tabs.js +87 -0
- package/dist/blocks/client/adjacentLinks.d.ts +4 -0
- package/dist/blocks/client/adjacentLinks.js +4 -0
- package/dist/blocks/client/carousel.d.ts +45 -0
- package/dist/blocks/client/carousel.js +53 -0
- package/dist/blocks/client/embed.d.ts +21 -0
- package/dist/blocks/client/embed.js +23 -0
- package/dist/blocks/client/field.d.ts +7 -0
- package/dist/blocks/client/field.js +8 -0
- package/dist/blocks/client/filterLink.d.ts +19 -0
- package/dist/blocks/client/filterLink.js +30 -0
- package/dist/blocks/client/helpers.d.ts +21 -0
- package/dist/blocks/client/helpers.js +24 -0
- package/dist/blocks/client/marquee.d.ts +14 -0
- package/dist/blocks/client/marquee.js +25 -0
- package/dist/blocks/client/menu.d.ts +46 -0
- package/dist/blocks/client/menu.js +49 -0
- package/dist/blocks/client/popup.d.ts +15 -0
- package/dist/blocks/client/popup.js +16 -0
- package/dist/blocks/client/tabs.d.ts +10 -0
- package/dist/blocks/client/tabs.js +11 -0
- package/dist/blocks/defaults.d.ts +15 -52
- package/dist/blocks/defaults.js +203 -437
- package/dist/blocks/index.d.ts +1 -1
- package/dist/blocks/index.js +2 -1
- package/dist/classes/actions.d.ts +97 -0
- package/dist/classes/actions.js +296 -0
- package/dist/classes/collection.d.ts +5 -0
- package/dist/classes/collection.js +189 -0
- package/dist/classes/config.d.ts +34 -0
- package/dist/classes/config.js +8 -0
- package/dist/classes/endpoints.d.ts +2 -0
- package/dist/classes/endpoints.js +120 -0
- package/dist/classes/index.d.ts +36 -0
- package/dist/classes/index.js +42 -0
- package/dist/classes/mcp.d.ts +6 -0
- package/dist/classes/mcp.js +161 -0
- package/dist/classes/shared.d.ts +131 -0
- package/dist/classes/shared.js +300 -0
- package/dist/classes/sheet.d.ts +34 -0
- package/dist/classes/sheet.js +126 -0
- package/dist/classes/usage.d.ts +57 -0
- package/dist/classes/usage.js +208 -0
- package/dist/comments/collection.d.ts +38 -0
- package/dist/comments/collection.js +226 -0
- package/dist/comments/config.d.ts +15 -0
- package/dist/comments/config.js +2 -0
- package/dist/comments/index.d.ts +20 -0
- package/dist/comments/index.js +22 -0
- package/dist/comments/shared.d.ts +54 -0
- package/dist/comments/shared.js +104 -0
- package/dist/core/bindings.d.ts +77 -32
- package/dist/core/bindings.js +319 -134
- package/dist/core/blockNames.d.ts +9 -0
- package/dist/core/blockNames.js +11 -0
- package/dist/core/blocks.d.ts +21 -8
- package/dist/core/blocks.js +37 -16
- package/dist/core/classes.d.ts +16 -8
- package/dist/core/classes.js +31 -27
- package/dist/core/components.d.ts +72 -0
- package/dist/core/components.js +294 -0
- package/dist/core/contentMode.d.ts +27 -0
- package/dist/core/contentMode.js +0 -0
- package/dist/core/dropTarget.d.ts +11 -0
- package/dist/core/dropTarget.js +24 -1
- package/dist/core/fields.d.ts +5 -0
- package/dist/core/fields.js +11 -0
- package/dist/core/headings.d.ts +5 -2
- package/dist/core/headings.js +14 -6
- package/dist/core/index.d.ts +8 -3
- package/dist/core/index.js +8 -3
- package/dist/core/layers.d.ts +9 -0
- package/dist/core/layers.js +29 -0
- package/dist/core/operations.d.ts +6 -0
- package/dist/core/operations.js +85 -24
- package/dist/core/payloadBlocks.js +5 -1
- package/dist/core/references.js +28 -0
- package/dist/core/schema.js +20 -6
- package/dist/core/sectionOrigin.d.ts +6 -0
- package/dist/core/sectionOrigin.js +21 -0
- package/dist/core/sections.d.ts +72 -0
- package/dist/core/sections.js +331 -0
- package/dist/core/templateChoice.d.ts +24 -0
- package/dist/core/templateChoice.js +43 -0
- package/dist/core/tree.js +18 -6
- package/dist/core/types.d.ts +148 -18
- package/dist/core/validate.d.ts +4 -1
- package/dist/core/validate.js +28 -11
- package/dist/core/visibility.d.ts +63 -0
- package/dist/core/visibility.js +214 -0
- package/dist/core/whereValues.d.ts +22 -0
- package/dist/core/whereValues.js +43 -0
- package/dist/css/classes.d.ts +16 -0
- package/dist/css/classes.js +172 -0
- package/dist/css/index.d.ts +32 -1
- package/dist/css/index.js +64 -5
- package/dist/css/tokens.d.ts +10 -0
- package/dist/css/tokens.js +23 -10
- package/dist/index.d.ts +5 -2
- package/dist/index.js +6 -1
- package/dist/live/contentMode.d.ts +24 -0
- package/dist/live/contentMode.js +39 -0
- package/dist/live/endpoints.js +3 -0
- package/dist/live/session.d.ts +5 -0
- package/dist/live/session.js +8 -0
- package/dist/live/types.d.ts +16 -1
- package/dist/mcp/index.d.ts +10 -1
- package/dist/mcp/index.js +146 -54
- package/dist/mcp/shared.d.ts +93 -3
- package/dist/mcp/shared.js +211 -15
- package/dist/plugin/hook.d.ts +7 -1
- package/dist/plugin/hook.js +30 -4
- package/dist/plugin/index.d.ts +19 -8
- package/dist/plugin/index.js +89 -20
- package/dist/plugin/links.d.ts +24 -0
- package/dist/plugin/links.js +27 -0
- package/dist/plugin/listCollections.d.ts +9 -7
- package/dist/plugin/listCollections.js +30 -21
- package/dist/plugin/sections.d.ts +14 -7
- package/dist/plugin/sections.js +69 -23
- package/dist/plugin/sectionsUsedIn.d.ts +6 -0
- package/dist/plugin/sectionsUsedIn.js +24 -0
- package/dist/plugin/templateEndpoint.d.ts +9 -0
- package/dist/plugin/templateEndpoint.js +49 -0
- package/dist/plugin/templates.js +23 -8
- package/dist/protocol/index.d.ts +16 -1
- package/dist/react/canvas/BuilderCanvas.js +144 -21
- package/dist/react/canvas/classes.d.ts +17 -0
- package/dist/react/canvas/classes.js +102 -0
- package/dist/react/canvas/controls.d.ts +31 -0
- package/dist/react/canvas/controls.js +75 -0
- package/dist/react/canvas/fetchDocs.d.ts +2 -2
- package/dist/react/canvas/fetchDocs.js +16 -8
- package/dist/react/canvas/measure.d.ts +9 -0
- package/dist/react/canvas/measure.js +106 -7
- package/dist/react/canvas/resolveLayout.d.ts +1 -1
- package/dist/react/canvas/resolveLayout.js +4 -3
- package/dist/react/canvas/thumbnail/ThumbnailCanvas.js +17 -4
- package/dist/react/classes/ClassesStyle.d.ts +27 -0
- package/dist/react/classes/ClassesStyle.js +27 -0
- package/dist/react/components/Button.d.ts +2 -11
- package/dist/react/components/Button.js +8 -43
- package/dist/react/components/CollectionList.d.ts +4 -1
- package/dist/react/components/CollectionList.js +10 -3
- package/dist/react/components/Container.d.ts +5 -2
- package/dist/react/components/Container.js +7 -4
- package/dist/react/components/Field.js +3 -14
- package/dist/react/components/Link.d.ts +1 -1
- package/dist/react/components/Link.js +5 -3
- package/dist/react/components/List.d.ts +1 -1
- package/dist/react/components/List.js +2 -2
- package/dist/react/components/Menu.d.ts +10 -1
- package/dist/react/components/Menu.js +39 -12
- package/dist/react/components/RichText.d.ts +3 -4
- package/dist/react/components/RichText.js +5 -5
- package/dist/react/components/builtins/Accordion.d.ts +4 -3
- package/dist/react/components/builtins/Accordion.js +6 -5
- package/dist/react/components/builtins/AdjacentLinks.d.ts +11 -0
- package/dist/react/components/builtins/AdjacentLinks.js +20 -0
- package/dist/react/components/builtins/Carousel.d.ts +21 -10
- package/dist/react/components/builtins/Carousel.js +175 -100
- package/dist/react/components/builtins/Disclosure.d.ts +4 -3
- package/dist/react/components/builtins/Disclosure.js +6 -5
- package/dist/react/components/builtins/Embed.d.ts +11 -0
- package/dist/react/components/builtins/Embed.js +23 -0
- package/dist/react/components/builtins/EmbedHtml.d.ts +15 -0
- package/dist/react/components/builtins/EmbedHtml.js +51 -0
- package/dist/react/components/builtins/EmbedPreview.d.ts +34 -0
- package/dist/react/components/builtins/EmbedPreview.js +105 -0
- package/dist/react/components/builtins/FilterLink.d.ts +1 -1
- package/dist/react/components/builtins/FilterLink.js +4 -4
- package/dist/react/components/builtins/Marquee.d.ts +8 -0
- package/dist/react/components/builtins/Marquee.js +15 -0
- package/dist/react/components/builtins/Popup.d.ts +26 -0
- package/dist/react/components/builtins/Popup.js +146 -0
- package/dist/react/components/builtins/SectionRef.d.ts +4 -3
- package/dist/react/components/builtins/SectionRef.js +9 -5
- package/dist/react/components/builtins/Tab.d.ts +7 -0
- package/dist/react/components/builtins/Tab.js +21 -0
- package/dist/react/components/builtins/TableOfContents.d.ts +17 -3
- package/dist/react/components/builtins/TableOfContents.js +22 -7
- package/dist/react/components/builtins/Tabs.d.ts +17 -0
- package/dist/react/components/builtins/Tabs.js +71 -0
- package/dist/react/components/builtins/index.d.ts +37 -20
- package/dist/react/components/builtins/index.js +54 -20
- package/dist/react/components/builtins/tabsContext.d.ts +12 -0
- package/dist/react/components/builtins/tabsContext.js +6 -0
- package/dist/react/components/index.js +11 -8
- package/dist/react/components/lazy.d.ts +32 -0
- package/dist/react/components/lazy.js +20 -0
- package/dist/react/components/lazyBlock.d.ts +17 -0
- package/dist/react/components/lazyBlock.js +23 -0
- package/dist/react/index.d.ts +6 -3
- package/dist/react/index.js +5 -2
- package/dist/react/render/RenderLayout.d.ts +9 -7
- package/dist/react/render/RenderLayout.js +96 -45
- package/dist/react/render/canvasMode.d.ts +13 -0
- package/dist/react/render/canvasMode.js +13 -0
- package/dist/react/render/canvasServer.js +4 -3
- package/dist/react/render/canvasServerTypes.d.ts +5 -0
- package/dist/react/render/lists.d.ts +36 -4
- package/dist/react/render/lists.js +132 -15
- package/dist/react/render/marks.d.ts +15 -0
- package/dist/react/render/marks.js +23 -0
- package/dist/react/render/payload.d.ts +8 -1
- package/dist/react/render/payload.js +12 -3
- package/dist/react/render/preview.d.ts +11 -0
- package/dist/react/render/preview.js +13 -0
- package/dist/react/render/relations.d.ts +10 -0
- package/dist/react/render/relations.js +39 -0
- package/dist/react/render/resolve.d.ts +8 -4
- package/dist/react/render/resolve.js +11 -5
- package/dist/react/render/reveal.d.ts +17 -0
- package/dist/react/render/reveal.js +39 -0
- package/dist/react/render/sections.d.ts +11 -5
- package/dist/react/render/sections.js +52 -24
- package/dist/react/render/templates.d.ts +47 -0
- package/dist/react/render/templates.js +139 -0
- package/dist/react/render/types.d.ts +62 -5
- package/dist/react/server.d.ts +2 -37
- package/dist/react/server.js +8 -133
- package/dist/react/theme/ThemeLiveLoader.d.ts +4 -0
- package/dist/react/theme/ThemeLiveLoader.js +5 -0
- package/dist/react/theme/ThemeStyle.js +1 -1
- package/dist/theme/admin/Variables.d.ts +11 -0
- package/dist/theme/admin/Variables.js +115 -0
- package/dist/theme/admin/fields.scss +113 -0
- package/dist/theme/client.d.ts +1 -0
- package/dist/theme/client.js +2 -0
- package/dist/theme/css.d.ts +6 -1
- package/dist/theme/css.js +12 -4
- package/dist/theme/global.js +83 -0
- package/dist/theme/index.d.ts +1 -0
- package/dist/theme/index.js +1 -0
- package/dist/theme/server.d.ts +15 -0
- package/dist/theme/server.js +43 -0
- package/dist/theme/usage.d.ts +23 -0
- package/dist/theme/usage.js +68 -0
- package/dist/theme/variables.d.ts +72 -0
- package/dist/theme/variables.js +231 -0
- package/package.json +4 -2
- package/dist/admin/editor/styles/SiteClasses.d.ts +0 -9
- package/dist/admin/editor/styles/SiteClasses.js +0 -31
- package/dist/blocks/builtins/headingId.d.ts +0 -15
- package/dist/blocks/builtins/headingId.js +0 -36
- package/dist/blocks/builtins/lightbox.d.ts +0 -43
- package/dist/blocks/builtins/lightbox.js +0 -93
- package/dist/blocks/builtins/mediaBackdrop.d.ts +0 -11
- package/dist/blocks/builtins/mediaBackdrop.js +0 -79
- package/dist/react/components/Quote.d.ts +0 -3
- package/dist/react/components/Quote.js +0 -12
- package/dist/react/components/Spacer.d.ts +0 -3
- package/dist/react/components/Spacer.js +0 -6
- package/dist/react/components/builtins/BackdropVideo.d.ts +0 -13
- package/dist/react/components/builtins/BackdropVideo.js +0 -16
- package/dist/react/components/builtins/Lightbox.d.ts +0 -45
- package/dist/react/components/builtins/Lightbox.js +0 -252
- package/dist/react/components/builtins/MediaBackdrop.d.ts +0 -14
- package/dist/react/components/builtins/MediaBackdrop.js +0 -61
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Names that client block components need. No imports: a component that reads them does not
|
|
2
|
+
// pull the binding code into the page's JavaScript. `bindings.ts` re-exports them.
|
|
3
|
+
/** The collection list block: renders its `item` slot once per loaded document. */
|
|
4
|
+
export const COLLECTION_LIST_BLOCK = 'collectionList';
|
|
5
|
+
/**
|
|
6
|
+
* The repeat block: renders its `item` slot once per row of an array or hasMany field of the
|
|
7
|
+
* current document (`props.path`). The rows are its runtime-only `$items` prop.
|
|
8
|
+
*/
|
|
9
|
+
export const REPEAT_BLOCK = 'repeat';
|
|
10
|
+
/** The URL query parameter of a paginated list's page (`?page=3`). Filter links drop it. */
|
|
11
|
+
export const PAGE_PARAM = 'page';
|
package/dist/core/blocks.d.ts
CHANGED
|
@@ -12,11 +12,17 @@ export declare function slotAccepts(slot: SlotDefinition, type: string): boolean
|
|
|
12
12
|
*/
|
|
13
13
|
export declare function fitsParent(blocks: readonly BlockDefinition[], type: string, parentType: string | null): boolean;
|
|
14
14
|
/**
|
|
15
|
-
* The children a new block of `type` starts with:
|
|
16
|
-
*
|
|
17
|
-
*
|
|
15
|
+
* The children a new block of `type` starts with: in each slot that accepts exactly one type made
|
|
16
|
+
* for this block (its `parents` names `type`), the slot's `min` children of it, at least one. A new
|
|
17
|
+
* list starts with one list item; new tabs (`min: 2`) start with two tabs. Null when there are
|
|
18
|
+
* none. The children get the child type's default classes (`withDefaultClasses`).
|
|
18
19
|
*/
|
|
19
20
|
export declare function starterSlots(blocks: readonly BlockDefinition[], type: string, makeId: () => string): Record<string, Block[]> | null;
|
|
21
|
+
/**
|
|
22
|
+
* The new block with the definition's default classes: `defaultClassName` where it has no
|
|
23
|
+
* `className` key, and each part's `defaultClassName` where `partClassName` has no key for it.
|
|
24
|
+
*/
|
|
25
|
+
export declare function withDefaultClasses(block: Block, def: BlockDefinition | undefined): Block;
|
|
20
26
|
export declare function defineBlock<T extends BlockDefinition>(def: T): T;
|
|
21
27
|
/** A block in `defineSection` input: like `Block`, but `id` may be left out (here and in every slot). */
|
|
22
28
|
export type SectionBlockInput = Omit<Block, 'id' | 'slots'> & {
|
|
@@ -39,17 +45,24 @@ export type SectionInput = Omit<SectionDefinition, 'blocks' | 'variants'> & {
|
|
|
39
45
|
*/
|
|
40
46
|
export declare function defineSection(input: SectionInput): SectionDefinition;
|
|
41
47
|
/**
|
|
42
|
-
*
|
|
48
|
+
* Throws on a variant without id or label, or two variants of one section with one id. The plugin
|
|
49
|
+
* and `builderMcpTools` run it on the app's `sections`.
|
|
50
|
+
*/
|
|
51
|
+
export declare function checkSectionVariants(sections: readonly SectionDefinition[]): void;
|
|
52
|
+
/**
|
|
53
|
+
* The old flat list: each variant as a section of its own, right after its section: id
|
|
43
54
|
* `<section id>/<variant id>`, label `<section label> (<variant label>)`, the section's category,
|
|
44
55
|
* its description unless the variant has one, and `variantOf` set to the section id. The section
|
|
45
|
-
* itself stays the first version and loses its `variants` key. The plugin
|
|
46
|
-
*
|
|
47
|
-
*
|
|
56
|
+
* itself stays the first version and loses its `variants` key. The plugin no longer uses it: the
|
|
57
|
+
* editor, MCP and the assistant keep variants under their section (`core/sections.ts`), and
|
|
58
|
+
* `insertSection` still accepts the `<section id>/<variant id>` ids. Throws like
|
|
59
|
+
* `checkSectionVariants`.
|
|
48
60
|
*/
|
|
49
61
|
export declare function sectionsWithVariants(sections: readonly SectionDefinition[]): SectionDefinition[];
|
|
50
62
|
/**
|
|
51
63
|
* The blocks with each block's `defaultClassName` filled where the block has no `className` key, at
|
|
52
|
-
* any depth
|
|
64
|
+
* any depth, and each part's default classes where `partClassName` has no key for the part
|
|
65
|
+
* (`withDefaultClasses`). A `className` of `''` stays empty. Blocks of unknown types stay as they are. The
|
|
53
66
|
* plugin and `builderMcpTools` run it on the app's `sections`, so a section tree may leave out a
|
|
54
67
|
* block's default classes. Seeds that build layouts by hand can run it too.
|
|
55
68
|
*/
|
package/dist/core/blocks.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { defaultPartClassNames } from './classes.js';
|
|
1
2
|
import { indexLayout, subtreeIds } from './tree.js';
|
|
2
3
|
/**
|
|
3
4
|
* True when the slot accepts the block type as a direct child: `allow` undefined or containing "*"
|
|
@@ -24,9 +25,10 @@ function parentsMessage(blocks, type) {
|
|
|
24
25
|
return `${label(type)} can only go inside ${parents.map(label).join(' or ')}`;
|
|
25
26
|
}
|
|
26
27
|
/**
|
|
27
|
-
* The children a new block of `type` starts with:
|
|
28
|
-
*
|
|
29
|
-
*
|
|
28
|
+
* The children a new block of `type` starts with: in each slot that accepts exactly one type made
|
|
29
|
+
* for this block (its `parents` names `type`), the slot's `min` children of it, at least one. A new
|
|
30
|
+
* list starts with one list item; new tabs (`min: 2`) start with two tabs. Null when there are
|
|
31
|
+
* none. The children get the child type's default classes (`withDefaultClasses`).
|
|
30
32
|
*/
|
|
31
33
|
export function starterSlots(blocks, type, makeId) {
|
|
32
34
|
const slots = {};
|
|
@@ -36,13 +38,24 @@ export function starterSlots(blocks, type, makeId) {
|
|
|
36
38
|
const child = getBlockDefinition(blocks, slot.allow[0]);
|
|
37
39
|
if (!child?.parents?.includes(type))
|
|
38
40
|
continue;
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
block.className = child.defaultClassName;
|
|
42
|
-
slots[name] = [block];
|
|
41
|
+
const count = Math.max(1, Math.min(slot.min ?? 1, slot.max ?? Infinity));
|
|
42
|
+
slots[name] = Array.from({ length: count }, () => withDefaultClasses({ id: makeId(), type: child.type }, child));
|
|
43
43
|
}
|
|
44
44
|
return Object.keys(slots).length > 0 ? slots : null;
|
|
45
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* The new block with the definition's default classes: `defaultClassName` where it has no
|
|
48
|
+
* `className` key, and each part's `defaultClassName` where `partClassName` has no key for it.
|
|
49
|
+
*/
|
|
50
|
+
export function withDefaultClasses(block, def) {
|
|
51
|
+
const next = { ...block };
|
|
52
|
+
if (next.className === undefined && def?.defaultClassName)
|
|
53
|
+
next.className = def.defaultClassName;
|
|
54
|
+
const parts = defaultPartClassNames(def);
|
|
55
|
+
if (parts)
|
|
56
|
+
next.partClassName = { ...parts, ...next.partClassName };
|
|
57
|
+
return next;
|
|
58
|
+
}
|
|
46
59
|
export function defineBlock(def) {
|
|
47
60
|
return def;
|
|
48
61
|
}
|
|
@@ -110,12 +123,22 @@ function checkVariants(section, variants) {
|
|
|
110
123
|
}
|
|
111
124
|
}
|
|
112
125
|
/**
|
|
113
|
-
*
|
|
126
|
+
* Throws on a variant without id or label, or two variants of one section with one id. The plugin
|
|
127
|
+
* and `builderMcpTools` run it on the app's `sections`.
|
|
128
|
+
*/
|
|
129
|
+
export function checkSectionVariants(sections) {
|
|
130
|
+
for (const section of sections)
|
|
131
|
+
if (section.variants?.length)
|
|
132
|
+
checkVariants(section.id, section.variants);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* The old flat list: each variant as a section of its own, right after its section: id
|
|
114
136
|
* `<section id>/<variant id>`, label `<section label> (<variant label>)`, the section's category,
|
|
115
137
|
* its description unless the variant has one, and `variantOf` set to the section id. The section
|
|
116
|
-
* itself stays the first version and loses its `variants` key. The plugin
|
|
117
|
-
*
|
|
118
|
-
*
|
|
138
|
+
* itself stays the first version and loses its `variants` key. The plugin no longer uses it: the
|
|
139
|
+
* editor, MCP and the assistant keep variants under their section (`core/sections.ts`), and
|
|
140
|
+
* `insertSection` still accepts the `<section id>/<variant id>` ids. Throws like
|
|
141
|
+
* `checkSectionVariants`.
|
|
119
142
|
*/
|
|
120
143
|
export function sectionsWithVariants(sections) {
|
|
121
144
|
return sections.flatMap(({ variants, ...section }) => {
|
|
@@ -137,16 +160,14 @@ export function sectionsWithVariants(sections) {
|
|
|
137
160
|
}
|
|
138
161
|
/**
|
|
139
162
|
* The blocks with each block's `defaultClassName` filled where the block has no `className` key, at
|
|
140
|
-
* any depth
|
|
163
|
+
* any depth, and each part's default classes where `partClassName` has no key for the part
|
|
164
|
+
* (`withDefaultClasses`). A `className` of `''` stays empty. Blocks of unknown types stay as they are. The
|
|
141
165
|
* plugin and `builderMcpTools` run it on the app's `sections`, so a section tree may leave out a
|
|
142
166
|
* block's default classes. Seeds that build layouts by hand can run it too.
|
|
143
167
|
*/
|
|
144
168
|
export function withDefaultClassNames(list, definitions) {
|
|
145
169
|
return list.map((block) => {
|
|
146
|
-
const next =
|
|
147
|
-
const fallback = block.className === undefined ? getBlockDefinition(definitions, block.type)?.defaultClassName : undefined;
|
|
148
|
-
if (fallback)
|
|
149
|
-
next.className = fallback;
|
|
170
|
+
const next = withDefaultClasses(block, getBlockDefinition(definitions, block.type));
|
|
150
171
|
if (block.slots) {
|
|
151
172
|
next.slots = Object.fromEntries(Object.entries(block.slots).map(([name, children]) => [name, withDefaultClassNames(children, definitions)]));
|
|
152
173
|
}
|
package/dist/core/classes.d.ts
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
|
-
import { type DataField } from './fields.js';
|
|
2
1
|
import type { BlockDefinition, Layout } from './types.js';
|
|
2
|
+
/** One inner element of a block that takes classes of its own (`block.partClassName[name]`). */
|
|
3
|
+
export type BlockPart = {
|
|
4
|
+
name: string;
|
|
5
|
+
label: string;
|
|
6
|
+
/** True for a slot with `styles: true`, false for an entry of `BlockDefinition.parts`. */
|
|
7
|
+
slot: boolean;
|
|
8
|
+
defaultClassName?: string;
|
|
9
|
+
};
|
|
3
10
|
/**
|
|
4
|
-
* The block's
|
|
5
|
-
*
|
|
6
|
-
* The save hook and the canvas compile their values (and their `defaultValue`) like `className`.
|
|
11
|
+
* The block's parts: its slots with `styles: true` (in slot order), then its `parts`. A part name
|
|
12
|
+
* that is also a slot name is left out of `parts`.
|
|
7
13
|
*/
|
|
8
|
-
export declare function
|
|
14
|
+
export declare function blockParts(def: Pick<BlockDefinition, 'slots' | 'parts'> | undefined): BlockPart[];
|
|
15
|
+
/** The `partClassName` a newly inserted block starts with: each part's `defaultClassName`. Null without one. */
|
|
16
|
+
export declare function defaultPartClassNames(def: Pick<BlockDefinition, 'slots' | 'parts'> | undefined): Record<string, string> | null;
|
|
9
17
|
/**
|
|
10
|
-
* Every distinct class the layout needs, sorted: each block's `className` and `
|
|
11
|
-
* plus, when `blocks` is given, `BlockDefinition.classes` of every block type
|
|
12
|
-
*
|
|
18
|
+
* Every distinct class the layout needs, sorted: each block's `className` and `partClassName`
|
|
19
|
+
* (hidden blocks too), plus, when `blocks` is given, `BlockDefinition.classes` of every block type
|
|
20
|
+
* in the layout.
|
|
13
21
|
*/
|
|
14
22
|
export declare function collectClasses(layout: Layout, blocks?: readonly BlockDefinition[]): string[];
|
package/dist/core/classes.js
CHANGED
|
@@ -1,15 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { isPlainObject, walkBlocks } from './tree.js';
|
|
1
|
+
import { walkBlocks } from './tree.js';
|
|
3
2
|
/**
|
|
4
|
-
* The block's
|
|
5
|
-
*
|
|
6
|
-
* The save hook and the canvas compile their values (and their `defaultValue`) like `className`.
|
|
3
|
+
* The block's parts: its slots with `styles: true` (in slot order), then its `parts`. A part name
|
|
4
|
+
* that is also a slot name is left out of `parts`.
|
|
7
5
|
*/
|
|
8
|
-
export function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
export function blockParts(def) {
|
|
7
|
+
const slots = Object.entries(def?.slots ?? {});
|
|
8
|
+
const fromSlots = slots
|
|
9
|
+
.filter(([, slot]) => slot.styles)
|
|
10
|
+
.map(([name, slot]) => ({
|
|
11
|
+
name,
|
|
12
|
+
label: slot.label?.trim() || name,
|
|
13
|
+
slot: true,
|
|
14
|
+
...(slot.defaultClassName ? { defaultClassName: slot.defaultClassName } : {}),
|
|
15
|
+
}));
|
|
16
|
+
const fromParts = Object.entries(def?.parts ?? {})
|
|
17
|
+
.filter(([name]) => !def?.slots?.[name])
|
|
18
|
+
.map(([name, part]) => ({
|
|
19
|
+
name,
|
|
20
|
+
label: part.label.trim() || name,
|
|
21
|
+
slot: false,
|
|
22
|
+
...(part.defaultClassName ? { defaultClassName: part.defaultClassName } : {}),
|
|
23
|
+
}));
|
|
24
|
+
return [...fromSlots, ...fromParts];
|
|
25
|
+
}
|
|
26
|
+
/** The `partClassName` a newly inserted block starts with: each part's `defaultClassName`. Null without one. */
|
|
27
|
+
export function defaultPartClassNames(def) {
|
|
28
|
+
const entries = blockParts(def).flatMap((part) => (part.defaultClassName ? [[part.name, part.defaultClassName]] : []));
|
|
29
|
+
return entries.length > 0 ? Object.fromEntries(entries) : null;
|
|
13
30
|
}
|
|
14
31
|
function addClasses(target, value) {
|
|
15
32
|
for (const name of value.split(/\s+/)) {
|
|
@@ -18,28 +35,20 @@ function addClasses(target, value) {
|
|
|
18
35
|
}
|
|
19
36
|
}
|
|
20
37
|
/**
|
|
21
|
-
* Every distinct class the layout needs, sorted: each block's `className` and `
|
|
22
|
-
* plus, when `blocks` is given, `BlockDefinition.classes` of every block type
|
|
23
|
-
*
|
|
38
|
+
* Every distinct class the layout needs, sorted: each block's `className` and `partClassName`
|
|
39
|
+
* (hidden blocks too), plus, when `blocks` is given, `BlockDefinition.classes` of every block type
|
|
40
|
+
* in the layout.
|
|
24
41
|
*/
|
|
25
42
|
export function collectClasses(layout, blocks) {
|
|
26
43
|
const classes = new Set();
|
|
27
44
|
const types = new Set();
|
|
28
|
-
const propsOf = new Map((blocks ?? []).map((def) => [def.type, classFields(def)]));
|
|
29
45
|
walkBlocks(layout, (block) => {
|
|
30
46
|
types.add(block.type);
|
|
31
47
|
if (typeof block.className === 'string')
|
|
32
48
|
addClasses(classes, block.className);
|
|
33
|
-
for (const value of Object.values(block.
|
|
49
|
+
for (const value of Object.values(block.partClassName ?? {}))
|
|
34
50
|
if (typeof value === 'string')
|
|
35
51
|
addClasses(classes, value);
|
|
36
|
-
for (const field of propsOf.get(block.type) ?? []) {
|
|
37
|
-
for (const values of [block.props, ...Object.values(block.locales ?? {})]) {
|
|
38
|
-
const value = values?.[field.name];
|
|
39
|
-
if (typeof value === 'string')
|
|
40
|
-
addClasses(classes, value);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
52
|
});
|
|
44
53
|
for (const definition of blocks ?? []) {
|
|
45
54
|
if (!types.has(definition.type))
|
|
@@ -48,11 +57,6 @@ export function collectClasses(layout, blocks) {
|
|
|
48
57
|
if (typeof value === 'string')
|
|
49
58
|
addClasses(classes, value);
|
|
50
59
|
}
|
|
51
|
-
for (const field of propsOf.get(definition.type) ?? []) {
|
|
52
|
-
const fallback = field.defaultValue;
|
|
53
|
-
if (typeof fallback === 'string')
|
|
54
|
-
addClasses(classes, fallback);
|
|
55
|
-
}
|
|
56
60
|
}
|
|
57
61
|
return [...classes].toSorted();
|
|
58
62
|
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { DataField } from './fields.js';
|
|
2
|
+
import type { Block, BlockDefinition, BlockProps } from './types.js';
|
|
3
|
+
/** Binding root of a component's properties: `$component.title`. */
|
|
4
|
+
export declare const COMPONENT_PATH = "$component";
|
|
5
|
+
/** Binding key for a "visible" property: `bindings: { $visible: '$component.showButton' }` shows or hides the block. */
|
|
6
|
+
export declare const VISIBLE_BINDING = "$visible";
|
|
7
|
+
export type ComponentPropertyType = 'text' | 'richText' | 'image' | 'link' | 'visible' | 'other';
|
|
8
|
+
export type ComponentProperty = {
|
|
9
|
+
/** Key in a copy's values and in the binding (`$component.<name>`). */
|
|
10
|
+
name: string;
|
|
11
|
+
label: string;
|
|
12
|
+
type: ComponentPropertyType;
|
|
13
|
+
/** The first block that uses the property, and its prop path (`$visible` for a visible property). */
|
|
14
|
+
blockId: string;
|
|
15
|
+
propPath: string;
|
|
16
|
+
/** The master's value: what a copy shows until it sets its own. */
|
|
17
|
+
default: unknown;
|
|
18
|
+
/** The bound prop's field config (not for visible properties). */
|
|
19
|
+
field?: DataField;
|
|
20
|
+
};
|
|
21
|
+
/** Values of a copy, by property name. */
|
|
22
|
+
export type ComponentValues = Record<string, unknown>;
|
|
23
|
+
/** A property name from the label someone typed: "Button text" -> "buttonText". Empty when nothing is left. */
|
|
24
|
+
export declare function propertyName(label: string): string;
|
|
25
|
+
/** The label of a property name: "buttonText" -> "Button text". */
|
|
26
|
+
export declare function propertyLabel(name: string): string;
|
|
27
|
+
/** The binding of a property: "$component.title". */
|
|
28
|
+
export declare function propertyBinding(name: string): string;
|
|
29
|
+
/** The property a binding is, when it is exactly `$component.<name>`. Else null. */
|
|
30
|
+
export declare function propertyOf(binding: string): string | null;
|
|
31
|
+
/** True when a binding reads at least one property. */
|
|
32
|
+
export declare function readsComponent(binding: string): boolean;
|
|
33
|
+
/** The property type of a prop's field, or null when such a prop cannot be a property. */
|
|
34
|
+
export declare function propertyType(field: DataField | undefined): Exclude<ComponentPropertyType, 'visible' | 'other'> | null;
|
|
35
|
+
type Definitions = ReadonlyMap<string, BlockDefinition>;
|
|
36
|
+
/**
|
|
37
|
+
* The properties of a saved section's blocks, in layout order. A name used by several blocks is
|
|
38
|
+
* one property: the first block gives its type and default.
|
|
39
|
+
*/
|
|
40
|
+
export declare function componentProperties(blocks: readonly Block[], definitions: readonly BlockDefinition[] | Definitions): ComponentProperty[];
|
|
41
|
+
/** True when the blocks have at least one property: the saved section is a component. */
|
|
42
|
+
export declare function isComponent(blocks: readonly Block[]): boolean;
|
|
43
|
+
/** The names a block's bindings use as properties, by prop path. */
|
|
44
|
+
export declare function blockProperties(block: Block): Record<string, string>;
|
|
45
|
+
/** A copy's stored values: `props.values` when it is an object. */
|
|
46
|
+
export declare function componentValuesOf(props: BlockProps | undefined): ComponentValues;
|
|
47
|
+
/**
|
|
48
|
+
* The section's blocks with a copy's values put in: each `$component.<name>` binding takes the
|
|
49
|
+
* copy's value, or keeps the master's value when the copy has none (empty counts as none). The
|
|
50
|
+
* property bindings are removed; other bindings stay. A visible property set to false hides the
|
|
51
|
+
* block. `{}` gives the master's own content without the property bindings (a plain copy).
|
|
52
|
+
* Never mutates.
|
|
53
|
+
*/
|
|
54
|
+
export declare function applyComponentValues(blocks: readonly Block[], values: ComponentValues, definitions: readonly BlockDefinition[] | Definitions): Block[];
|
|
55
|
+
/**
|
|
56
|
+
* One value as a copy stores it. Images are stored as `{ relationTo, value }`, so the references
|
|
57
|
+
* of a page find them without loading the component. Undefined: no value (the default shows).
|
|
58
|
+
*/
|
|
59
|
+
export declare function storedValue(property: ComponentProperty, value: unknown): unknown;
|
|
60
|
+
/** A stored value as the property's field input takes it: an image's ID. */
|
|
61
|
+
export declare function fieldValue(property: ComponentProperty, value: unknown): unknown;
|
|
62
|
+
/**
|
|
63
|
+
* Checks values for a copy (MCP, the assistant): unknown names and values of the wrong kind are
|
|
64
|
+
* problems. Returns the values as a copy stores them (`storedValue`), without empty ones.
|
|
65
|
+
*/
|
|
66
|
+
export declare function checkComponentValues(properties: readonly ComponentProperty[], values: unknown): {
|
|
67
|
+
values: ComponentValues;
|
|
68
|
+
problems: string[];
|
|
69
|
+
};
|
|
70
|
+
/** The values without names the component no longer has. Same object when nothing is dropped. */
|
|
71
|
+
export declare function knownValues(properties: readonly ComponentProperty[], values: ComponentValues): ComponentValues;
|
|
72
|
+
export {};
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
// Components: saved sections with properties. A property is a binding inside the saved section
|
|
2
|
+
// that reads `$component.<name>`, e.g. `{ text: '$component.title' }` on a heading. The bindings
|
|
3
|
+
// are the only record of the properties: their type comes from the bound field, their default is
|
|
4
|
+
// the bound prop's own value (the literal value every binding keeps as its fallback). A live copy
|
|
5
|
+
// (`sectionRef`) stores its own values in `props.values`; `applyComponentValues` puts them into
|
|
6
|
+
// the section's blocks before the rest of the data loading. Pure: no React, no Payload.
|
|
7
|
+
import { isLinkField } from '../blocks/link.js';
|
|
8
|
+
import { bindingPaths, bindProps, getByPath, isMissing, isRichText, plainToRichText, propField, toPlainText } from './bindings.js';
|
|
9
|
+
import { isPlainObject } from './tree.js';
|
|
10
|
+
/** Binding root of a component's properties: `$component.title`. */
|
|
11
|
+
export const COMPONENT_PATH = '$component';
|
|
12
|
+
/** Binding key for a "visible" property: `bindings: { $visible: '$component.showButton' }` shows or hides the block. */
|
|
13
|
+
export const VISIBLE_BINDING = '$visible';
|
|
14
|
+
const NAME = /^[A-Za-z][A-Za-z0-9_]*$/;
|
|
15
|
+
const PREFIX = `${COMPONENT_PATH}.`;
|
|
16
|
+
/** A property name from the label someone typed: "Button text" -> "buttonText". Empty when nothing is left. */
|
|
17
|
+
export function propertyName(label) {
|
|
18
|
+
const words = label
|
|
19
|
+
.normalize('NFKD')
|
|
20
|
+
.replace(/[^A-Za-z0-9]+/g, ' ')
|
|
21
|
+
.trim()
|
|
22
|
+
.split(' ')
|
|
23
|
+
.filter(Boolean);
|
|
24
|
+
const name = words.map((word, i) => (i === 0 ? word.charAt(0).toLowerCase() + word.slice(1) : word.charAt(0).toUpperCase() + word.slice(1))).join('');
|
|
25
|
+
return name.replace(/^[0-9_]+/, '');
|
|
26
|
+
}
|
|
27
|
+
/** The label of a property name: "buttonText" -> "Button text". */
|
|
28
|
+
export function propertyLabel(name) {
|
|
29
|
+
const words = name.replace(/_/g, ' ').replace(/([a-z0-9])([A-Z])/g, '$1 $2').trim().toLowerCase();
|
|
30
|
+
return words.charAt(0).toUpperCase() + words.slice(1);
|
|
31
|
+
}
|
|
32
|
+
/** The binding of a property: "$component.title". */
|
|
33
|
+
export function propertyBinding(name) {
|
|
34
|
+
return `${PREFIX}${name}`;
|
|
35
|
+
}
|
|
36
|
+
/** The property a binding is, when it is exactly `$component.<name>`. Else null. */
|
|
37
|
+
export function propertyOf(binding) {
|
|
38
|
+
if (!binding.startsWith(PREFIX))
|
|
39
|
+
return null;
|
|
40
|
+
const name = binding.slice(PREFIX.length);
|
|
41
|
+
return NAME.test(name) ? name : null;
|
|
42
|
+
}
|
|
43
|
+
/** True when a binding reads at least one property. */
|
|
44
|
+
export function readsComponent(binding) {
|
|
45
|
+
return binding.includes(PREFIX);
|
|
46
|
+
}
|
|
47
|
+
/** The property type of a prop's field, or null when such a prop cannot be a property. */
|
|
48
|
+
export function propertyType(field) {
|
|
49
|
+
if (!field)
|
|
50
|
+
return null;
|
|
51
|
+
if (isLinkField(field))
|
|
52
|
+
return 'link';
|
|
53
|
+
switch (field.type) {
|
|
54
|
+
case 'text':
|
|
55
|
+
case 'textarea':
|
|
56
|
+
case 'email':
|
|
57
|
+
return field.hasMany ? null : 'text';
|
|
58
|
+
case 'richText':
|
|
59
|
+
return 'richText';
|
|
60
|
+
case 'upload':
|
|
61
|
+
return field.hasMany || typeof field.relationTo !== 'string' ? null : 'image';
|
|
62
|
+
default:
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const definitionMap = (blocks) => blocks instanceof Map ? blocks : new Map(blocks.map((d) => [d.type, d]));
|
|
67
|
+
function eachBlock(blocks, fn) {
|
|
68
|
+
for (const block of blocks) {
|
|
69
|
+
fn(block);
|
|
70
|
+
for (const list of Object.values(block.slots ?? {}))
|
|
71
|
+
eachBlock(list, fn);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* The properties of a saved section's blocks, in layout order. A name used by several blocks is
|
|
76
|
+
* one property: the first block gives its type and default.
|
|
77
|
+
*/
|
|
78
|
+
export function componentProperties(blocks, definitions) {
|
|
79
|
+
const defs = definitionMap(definitions);
|
|
80
|
+
const found = new Map();
|
|
81
|
+
eachBlock(blocks, (block) => {
|
|
82
|
+
for (const [propPath, binding] of Object.entries(block.bindings ?? {})) {
|
|
83
|
+
const name = propertyOf(binding);
|
|
84
|
+
if (!name || found.has(name))
|
|
85
|
+
continue;
|
|
86
|
+
if (propPath === VISIBLE_BINDING) {
|
|
87
|
+
found.set(name, { name, label: propertyLabel(name), type: 'visible', blockId: block.id, propPath, default: !block.hidden });
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
const definition = defs.get(block.type);
|
|
91
|
+
const field = definition ? propField(definition.fields, propPath) : undefined;
|
|
92
|
+
found.set(name, {
|
|
93
|
+
name,
|
|
94
|
+
label: propertyLabel(name),
|
|
95
|
+
type: propertyType(field) ?? 'other',
|
|
96
|
+
blockId: block.id,
|
|
97
|
+
propPath,
|
|
98
|
+
default: getByPath(block.props, propPath),
|
|
99
|
+
...(field ? { field } : {}),
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
return [...found.values()];
|
|
104
|
+
}
|
|
105
|
+
/** True when the blocks have at least one property: the saved section is a component. */
|
|
106
|
+
export function isComponent(blocks) {
|
|
107
|
+
let found = false;
|
|
108
|
+
eachBlock(blocks, (block) => {
|
|
109
|
+
if (!found)
|
|
110
|
+
found = Object.values(block.bindings ?? {}).some((binding) => propertyOf(binding) !== null);
|
|
111
|
+
});
|
|
112
|
+
return found;
|
|
113
|
+
}
|
|
114
|
+
/** The names a block's bindings use as properties, by prop path. */
|
|
115
|
+
export function blockProperties(block) {
|
|
116
|
+
const out = {};
|
|
117
|
+
for (const [propPath, binding] of Object.entries(block.bindings ?? {})) {
|
|
118
|
+
const name = propertyOf(binding);
|
|
119
|
+
if (name)
|
|
120
|
+
out[propPath] = name;
|
|
121
|
+
}
|
|
122
|
+
return out;
|
|
123
|
+
}
|
|
124
|
+
/** A copy's stored values: `props.values` when it is an object. */
|
|
125
|
+
export function componentValuesOf(props) {
|
|
126
|
+
const values = props?.values;
|
|
127
|
+
return isPlainObject(values) ? values : {};
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Puts the `{{$component.x}}` parts of a template string in as text. Other parts stay for the
|
|
131
|
+
* page's own binding step. `found`: at least one part had a value.
|
|
132
|
+
*/
|
|
133
|
+
function fillTemplate(binding, values) {
|
|
134
|
+
let found = false;
|
|
135
|
+
const text = binding.replace(/\{\{([^{}]+)\}\}/g, (whole, expression) => {
|
|
136
|
+
const paths = bindingPaths(expression);
|
|
137
|
+
if (paths.length === 0 || !paths.every((p) => p.startsWith(PREFIX)))
|
|
138
|
+
return whole;
|
|
139
|
+
const name = propertyOf(paths[0]);
|
|
140
|
+
const part = name ? toPlainText(values[name]) : undefined;
|
|
141
|
+
if (part === undefined)
|
|
142
|
+
return '';
|
|
143
|
+
found = true;
|
|
144
|
+
return part.replace(/[{}]/g, '');
|
|
145
|
+
});
|
|
146
|
+
return { text, found };
|
|
147
|
+
}
|
|
148
|
+
function applyToBlock(block, values, defs) {
|
|
149
|
+
let next = block;
|
|
150
|
+
if (block.bindings && Object.values(block.bindings).some(readsComponent)) {
|
|
151
|
+
const own = {};
|
|
152
|
+
const rest = {};
|
|
153
|
+
const texts = {};
|
|
154
|
+
let visible;
|
|
155
|
+
for (const [propPath, binding] of Object.entries(block.bindings)) {
|
|
156
|
+
if (!readsComponent(binding)) {
|
|
157
|
+
rest[propPath] = binding;
|
|
158
|
+
}
|
|
159
|
+
else if (propPath === VISIBLE_BINDING) {
|
|
160
|
+
const name = propertyOf(binding);
|
|
161
|
+
const value = name ? values[name] : undefined;
|
|
162
|
+
if (typeof value === 'boolean')
|
|
163
|
+
visible = value;
|
|
164
|
+
}
|
|
165
|
+
else if (binding.includes('{{')) {
|
|
166
|
+
const { text, found } = fillTemplate(binding, values);
|
|
167
|
+
// Parts that read the page's data stay a binding; else the text replaces the prop.
|
|
168
|
+
if (text.includes('{{'))
|
|
169
|
+
rest[propPath] = text;
|
|
170
|
+
else if (found)
|
|
171
|
+
texts[propPath] = text;
|
|
172
|
+
}
|
|
173
|
+
else if (bindingPaths(binding).every((p) => p.startsWith(PREFIX))) {
|
|
174
|
+
own[propPath] = binding.split(PREFIX).join('');
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
// A fallback chain that also reads the page's data stays for the page's own binding step.
|
|
178
|
+
rest[propPath] = binding;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
const definition = defs.get(block.type);
|
|
182
|
+
const bound = bindProps(block.props ?? {}, own, { collection: '', doc: values }, definition);
|
|
183
|
+
// Filled template strings go in through the same coercion (a rich text prop gets rich text).
|
|
184
|
+
const entries = Object.entries(texts);
|
|
185
|
+
const filled = bindProps(bound.props, Object.fromEntries(entries.map(([propPath], i) => [propPath, `t${i}`])), { collection: '', doc: Object.fromEntries(entries.map(([, text], i) => [`t${i}`, text])) }, definition);
|
|
186
|
+
next = { ...block, props: filled.props };
|
|
187
|
+
if (Object.keys(next.props ?? {}).length === 0)
|
|
188
|
+
delete next.props;
|
|
189
|
+
if (Object.keys(rest).length > 0)
|
|
190
|
+
next.bindings = rest;
|
|
191
|
+
else
|
|
192
|
+
delete next.bindings;
|
|
193
|
+
if (visible === false)
|
|
194
|
+
next.hidden = true;
|
|
195
|
+
else if (visible === true)
|
|
196
|
+
delete next.hidden;
|
|
197
|
+
}
|
|
198
|
+
if (!next.slots)
|
|
199
|
+
return next;
|
|
200
|
+
return {
|
|
201
|
+
...next,
|
|
202
|
+
slots: Object.fromEntries(Object.entries(next.slots).map(([name, list]) => [name, list.map((child) => applyToBlock(child, values, defs))])),
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* The section's blocks with a copy's values put in: each `$component.<name>` binding takes the
|
|
207
|
+
* copy's value, or keeps the master's value when the copy has none (empty counts as none). The
|
|
208
|
+
* property bindings are removed; other bindings stay. A visible property set to false hides the
|
|
209
|
+
* block. `{}` gives the master's own content without the property bindings (a plain copy).
|
|
210
|
+
* Never mutates.
|
|
211
|
+
*/
|
|
212
|
+
export function applyComponentValues(blocks, values, definitions) {
|
|
213
|
+
const defs = definitionMap(definitions);
|
|
214
|
+
return blocks.map((block) => applyToBlock(block, values, defs));
|
|
215
|
+
}
|
|
216
|
+
/** A relationship value as an ID: a `{ relationTo, value }` pair or a loaded document give theirs. */
|
|
217
|
+
function idOf(value) {
|
|
218
|
+
if (isPlainObject(value) && 'relationTo' in value)
|
|
219
|
+
return idOf(value.value);
|
|
220
|
+
if (isPlainObject(value) && 'id' in value)
|
|
221
|
+
return value.id;
|
|
222
|
+
return value;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* One value as a copy stores it. Images are stored as `{ relationTo, value }`, so the references
|
|
226
|
+
* of a page find them without loading the component. Undefined: no value (the default shows).
|
|
227
|
+
*/
|
|
228
|
+
export function storedValue(property, value) {
|
|
229
|
+
if (isMissing(value))
|
|
230
|
+
return undefined;
|
|
231
|
+
switch (property.type) {
|
|
232
|
+
case 'image': {
|
|
233
|
+
const id = idOf(value);
|
|
234
|
+
const relationTo = property.field?.relationTo;
|
|
235
|
+
if ((typeof id !== 'string' && typeof id !== 'number') || id === '' || typeof relationTo !== 'string')
|
|
236
|
+
return undefined;
|
|
237
|
+
return { relationTo, value: id };
|
|
238
|
+
}
|
|
239
|
+
case 'visible':
|
|
240
|
+
return typeof value === 'boolean' ? value : undefined;
|
|
241
|
+
case 'text':
|
|
242
|
+
return toPlainText(value);
|
|
243
|
+
case 'richText':
|
|
244
|
+
if (isRichText(value))
|
|
245
|
+
return value;
|
|
246
|
+
return typeof value === 'string' ? plainToRichText(value) : undefined;
|
|
247
|
+
case 'link':
|
|
248
|
+
if (typeof value === 'string')
|
|
249
|
+
return { type: 'url', url: value };
|
|
250
|
+
return isPlainObject(value) ? value : undefined;
|
|
251
|
+
default:
|
|
252
|
+
return value;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
/** A stored value as the property's field input takes it: an image's ID. */
|
|
256
|
+
export function fieldValue(property, value) {
|
|
257
|
+
return property.type === 'image' ? idOf(value) : value;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Checks values for a copy (MCP, the assistant): unknown names and values of the wrong kind are
|
|
261
|
+
* problems. Returns the values as a copy stores them (`storedValue`), without empty ones.
|
|
262
|
+
*/
|
|
263
|
+
export function checkComponentValues(properties, values) {
|
|
264
|
+
const problems = [];
|
|
265
|
+
const out = {};
|
|
266
|
+
if (values === undefined || values === null)
|
|
267
|
+
return { values: out, problems };
|
|
268
|
+
if (!isPlainObject(values))
|
|
269
|
+
return { values: out, problems: ['values must be an object of property name -> value.'] };
|
|
270
|
+
const byName = new Map(properties.map((p) => [p.name, p]));
|
|
271
|
+
for (const [name, value] of Object.entries(values)) {
|
|
272
|
+
const property = byName.get(name);
|
|
273
|
+
if (!property) {
|
|
274
|
+
const known = properties.map((p) => p.name).join(', ') || 'none';
|
|
275
|
+
problems.push(`Unknown property "${name}". Properties: ${known}.`);
|
|
276
|
+
continue;
|
|
277
|
+
}
|
|
278
|
+
if (isMissing(value))
|
|
279
|
+
continue;
|
|
280
|
+
const stored = storedValue(property, value);
|
|
281
|
+
if (stored === undefined) {
|
|
282
|
+
problems.push(`Property "${name}" (${property.type}) cannot take ${JSON.stringify(value).slice(0, 60)}.`);
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
out[name] = stored;
|
|
286
|
+
}
|
|
287
|
+
return { values: out, problems };
|
|
288
|
+
}
|
|
289
|
+
/** The values without names the component no longer has. Same object when nothing is dropped. */
|
|
290
|
+
export function knownValues(properties, values) {
|
|
291
|
+
const names = new Set(properties.map((p) => p.name));
|
|
292
|
+
const keys = Object.keys(values);
|
|
293
|
+
return keys.every((key) => names.has(key)) ? values : Object.fromEntries(keys.filter((key) => names.has(key)).map((key) => [key, values[key]]));
|
|
294
|
+
}
|