payload-canvas 0.4.0 → 0.5.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/README.md +625 -153
- 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 -2
- package/dist/blocks/index.js +1 -2
- 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,21 @@
|
|
|
1
|
+
// `Block.section`: the ready-made section a root block came from (see sections.ts). Its own file,
|
|
2
|
+
// so tree.ts, validate.ts and operations.ts can check it without importing the section helpers.
|
|
3
|
+
/**
|
|
4
|
+
* `value` as a canonical `SectionOrigin` (trimmed, no empty `variant`). Undefined when it is left
|
|
5
|
+
* out (undefined or null), an error message when its shape is wrong.
|
|
6
|
+
*/
|
|
7
|
+
export function checkSectionOrigin(value) {
|
|
8
|
+
if (value === undefined || value === null)
|
|
9
|
+
return undefined;
|
|
10
|
+
if (typeof value !== 'object' || Array.isArray(value))
|
|
11
|
+
return 'section must be an object { id, variant? }';
|
|
12
|
+
const { id, variant, ...rest } = value;
|
|
13
|
+
if (Object.keys(rest).length > 0)
|
|
14
|
+
return `section has unknown keys: ${Object.keys(rest).join(', ')}`;
|
|
15
|
+
if (typeof id !== 'string' || !id.trim())
|
|
16
|
+
return 'section.id must be a non-empty string';
|
|
17
|
+
if (variant !== undefined && variant !== null && typeof variant !== 'string')
|
|
18
|
+
return 'section.variant must be a string';
|
|
19
|
+
const name = typeof variant === 'string' ? variant.trim() : '';
|
|
20
|
+
return name ? { id: id.trim(), variant: name } : { id: id.trim() };
|
|
21
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { Block, Layout, Operation, SectionDefinition, SectionOrigin } from './types.js';
|
|
2
|
+
/** The name of a section's own version when it sets no `variantLabel`. */
|
|
3
|
+
export declare const DEFAULT_VARIANT_LABEL = "Default";
|
|
4
|
+
/** One version of a section: the section itself (`variant` undefined) or one of its variants. */
|
|
5
|
+
export type SectionVersion = {
|
|
6
|
+
variant: string | undefined;
|
|
7
|
+
label: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
blocks: Block[];
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* The versions of a section: the section itself first, then its variants. Saved sections have no
|
|
13
|
+
* variants.
|
|
14
|
+
*/
|
|
15
|
+
export declare function sectionVersions(section: SectionDefinition): SectionVersion[];
|
|
16
|
+
/** The index of a version in `sectionVersions`: 0 for the section itself, -1 for an unknown variant. */
|
|
17
|
+
export declare function versionIndex(section: SectionDefinition, variant?: string | null): number;
|
|
18
|
+
/** True when the section has variants to switch between. */
|
|
19
|
+
export declare function hasVariants(section: SectionDefinition): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* The blocks with `section` set on the root block. Only a list with one root block gets it: a
|
|
22
|
+
* section of several top-level blocks has no single block to switch.
|
|
23
|
+
*/
|
|
24
|
+
export declare function withSectionOrigin(blocks: readonly Block[], origin: SectionOrigin): Block[];
|
|
25
|
+
/** The block without `section`, at the root of the tree only (where it is set). */
|
|
26
|
+
export declare function withoutSectionOrigin(block: Block): Block;
|
|
27
|
+
/**
|
|
28
|
+
* One version of a section as a section of its own, ready to insert: the version's blocks (an app
|
|
29
|
+
* section's root block gets `section`), the label `<label> (<variant label>)` for a variant, and no
|
|
30
|
+
* `variants`. Null when the section has no such variant.
|
|
31
|
+
*/
|
|
32
|
+
export declare function sectionVersion(section: SectionDefinition, variant?: string | null): SectionDefinition | null;
|
|
33
|
+
/**
|
|
34
|
+
* Finds a section by its id (`hero`, `saved:12`), by a saved section's document id (`12`) or by
|
|
35
|
+
* its name (case-insensitive, the first match). Ids win over names.
|
|
36
|
+
*/
|
|
37
|
+
export declare function findSection(sections: readonly SectionDefinition[], ref: string): SectionDefinition | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* The version to insert for `ref` (see `findSection`) and `variant` (see `sectionVersion`). The old
|
|
40
|
+
* variant ids `<section id>/<variant id>` still work. Undefined when no section matches; an error
|
|
41
|
+
* message when the section has no such variant.
|
|
42
|
+
*/
|
|
43
|
+
export declare function findSectionVersion(sections: readonly SectionDefinition[], ref: string, variant?: string | null): SectionDefinition | string | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* The variants of a section for a listing (MCP and assistant `listSections`): id, label,
|
|
46
|
+
* description and what `show` returns for the blocks (an outline or the full JSON). Undefined
|
|
47
|
+
* when the section has none.
|
|
48
|
+
*/
|
|
49
|
+
export declare function listedVariants(section: SectionDefinition, show: (blocks: Block[]) => Record<string, unknown>): Record<string, unknown>[] | undefined;
|
|
50
|
+
/** The operations that switch a section in place, and the new root block. */
|
|
51
|
+
export type VariantSwitch = {
|
|
52
|
+
ops: Operation[];
|
|
53
|
+
block: Block;
|
|
54
|
+
label: string;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Replaces the section whose root block is `blockId` with another version of it (`variant`
|
|
58
|
+
* undefined: the section itself): a `remove` and an `insert` at the same place, so applied as one
|
|
59
|
+
* batch they are one undo step. Content the user changed carries over (see `carryContent`). The
|
|
60
|
+
* new blocks get new ids; HTML ids that other blocks use are left out. An error message when the
|
|
61
|
+
* block is no inserted app section, or the version does not exist.
|
|
62
|
+
*/
|
|
63
|
+
export declare function switchSectionVariant(layout: Layout, blockId: string, sections: readonly SectionDefinition[], variant: string | undefined, newId?: () => string): VariantSwitch | string;
|
|
64
|
+
/**
|
|
65
|
+
* `target` with the content the user changed in `current` since it was inserted from `source`:
|
|
66
|
+
* per matching block (see `matchVersions` and `pairWithSource`), every prop whose value differs
|
|
67
|
+
* from the source version (a cleared or removed prop too), and the name, hidden flag, HTML
|
|
68
|
+
* attributes and bindings when they differ. Classes, animations and the structure come from the
|
|
69
|
+
* new version. A translation stays when the new block's default-locale value is the one it
|
|
70
|
+
* translates. Blocks the user added inside the section are not carried over.
|
|
71
|
+
*/
|
|
72
|
+
export declare function carryContent(current: Block, source: Block, target: Block): Block;
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
// Section versions: a ready-made section and its variants (`SectionDefinition.variants`).
|
|
2
|
+
// Pure: the editor's library and variant switch, the MCP tools and the assistant use it.
|
|
3
|
+
//
|
|
4
|
+
// - The section itself is the first version, its variants follow.
|
|
5
|
+
// - An inserted app section with one root block remembers where it came from in `block.section`.
|
|
6
|
+
// - Switching an inserted section to another version replaces its blocks in place (one remove and
|
|
7
|
+
// one insert, so one undo step) and carries over the content the user changed.
|
|
8
|
+
import { htmlIdsOf, withoutTakenHtmlIds } from './attrs.js';
|
|
9
|
+
import { createId } from './ids.js';
|
|
10
|
+
import { findBlock, findLocation, walkBlocks } from './tree.js';
|
|
11
|
+
/** The name of a section's own version when it sets no `variantLabel`. */
|
|
12
|
+
export const DEFAULT_VARIANT_LABEL = 'Default';
|
|
13
|
+
/**
|
|
14
|
+
* The versions of a section: the section itself first, then its variants. Saved sections have no
|
|
15
|
+
* variants.
|
|
16
|
+
*/
|
|
17
|
+
export function sectionVersions(section) {
|
|
18
|
+
const own = { variant: undefined, label: section.variantLabel?.trim() || DEFAULT_VARIANT_LABEL, blocks: section.blocks };
|
|
19
|
+
if (section.description)
|
|
20
|
+
own.description = section.description;
|
|
21
|
+
const variants = section.savedId === undefined ? (section.variants ?? []) : [];
|
|
22
|
+
return [
|
|
23
|
+
own,
|
|
24
|
+
...variants.map((v) => {
|
|
25
|
+
const version = { variant: v.id, label: v.label, blocks: v.blocks };
|
|
26
|
+
const description = v.description ?? section.description;
|
|
27
|
+
if (description)
|
|
28
|
+
version.description = description;
|
|
29
|
+
return version;
|
|
30
|
+
}),
|
|
31
|
+
];
|
|
32
|
+
}
|
|
33
|
+
/** The index of a version in `sectionVersions`: 0 for the section itself, -1 for an unknown variant. */
|
|
34
|
+
export function versionIndex(section, variant) {
|
|
35
|
+
const name = variant?.trim();
|
|
36
|
+
if (!name)
|
|
37
|
+
return 0;
|
|
38
|
+
if (section.savedId !== undefined)
|
|
39
|
+
return -1;
|
|
40
|
+
const i = (section.variants ?? []).findIndex((v) => v.id === name);
|
|
41
|
+
return i < 0 ? -1 : i + 1;
|
|
42
|
+
}
|
|
43
|
+
/** True when the section has variants to switch between. */
|
|
44
|
+
export function hasVariants(section) {
|
|
45
|
+
return section.savedId === undefined && (section.variants?.length ?? 0) > 0;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The blocks with `section` set on the root block. Only a list with one root block gets it: a
|
|
49
|
+
* section of several top-level blocks has no single block to switch.
|
|
50
|
+
*/
|
|
51
|
+
export function withSectionOrigin(blocks, origin) {
|
|
52
|
+
if (blocks.length !== 1)
|
|
53
|
+
return [...blocks];
|
|
54
|
+
return [{ ...blocks[0], section: origin.variant ? { id: origin.id, variant: origin.variant } : { id: origin.id } }];
|
|
55
|
+
}
|
|
56
|
+
/** The block without `section`, at the root of the tree only (where it is set). */
|
|
57
|
+
export function withoutSectionOrigin(block) {
|
|
58
|
+
if (!block.section)
|
|
59
|
+
return block;
|
|
60
|
+
const { section: _section, ...rest } = block;
|
|
61
|
+
return rest;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* One version of a section as a section of its own, ready to insert: the version's blocks (an app
|
|
65
|
+
* section's root block gets `section`), the label `<label> (<variant label>)` for a variant, and no
|
|
66
|
+
* `variants`. Null when the section has no such variant.
|
|
67
|
+
*/
|
|
68
|
+
export function sectionVersion(section, variant) {
|
|
69
|
+
const index = versionIndex(section, variant);
|
|
70
|
+
if (index < 0)
|
|
71
|
+
return null;
|
|
72
|
+
const version = sectionVersions(section)[index];
|
|
73
|
+
const { variants: _variants, variantLabel: _variantLabel, description: _description, ...rest } = section;
|
|
74
|
+
const out = {
|
|
75
|
+
...rest,
|
|
76
|
+
label: version.variant ? `${section.label} (${version.label})` : section.label,
|
|
77
|
+
blocks: section.savedId === undefined ? withSectionOrigin(version.blocks, { id: section.id, variant: version.variant }) : version.blocks,
|
|
78
|
+
};
|
|
79
|
+
if (version.description)
|
|
80
|
+
out.description = version.description;
|
|
81
|
+
return out;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Finds a section by its id (`hero`, `saved:12`), by a saved section's document id (`12`) or by
|
|
85
|
+
* its name (case-insensitive, the first match). Ids win over names.
|
|
86
|
+
*/
|
|
87
|
+
export function findSection(sections, ref) {
|
|
88
|
+
const value = ref.trim();
|
|
89
|
+
if (!value)
|
|
90
|
+
return undefined;
|
|
91
|
+
const byId = sections.find((s) => s.id === value);
|
|
92
|
+
if (byId)
|
|
93
|
+
return byId;
|
|
94
|
+
const bySavedId = sections.find((s) => s.savedId !== undefined && String(s.savedId) === value);
|
|
95
|
+
if (bySavedId)
|
|
96
|
+
return bySavedId;
|
|
97
|
+
const name = value.toLowerCase();
|
|
98
|
+
return sections.find((s) => s.label.trim().toLowerCase() === name);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The version to insert for `ref` (see `findSection`) and `variant` (see `sectionVersion`). The old
|
|
102
|
+
* variant ids `<section id>/<variant id>` still work. Undefined when no section matches; an error
|
|
103
|
+
* message when the section has no such variant.
|
|
104
|
+
*/
|
|
105
|
+
export function findSectionVersion(sections, ref, variant) {
|
|
106
|
+
let section = findSection(sections, ref);
|
|
107
|
+
let name = variant?.trim() || undefined;
|
|
108
|
+
if (!section) {
|
|
109
|
+
const slash = ref.lastIndexOf('/');
|
|
110
|
+
const base = slash > 0 ? findSection(sections, ref.slice(0, slash)) : undefined;
|
|
111
|
+
const old = ref.slice(slash + 1).trim();
|
|
112
|
+
if (!base || (name && name !== old) || versionIndex(base, old) <= 0)
|
|
113
|
+
return undefined;
|
|
114
|
+
section = base;
|
|
115
|
+
name = old;
|
|
116
|
+
}
|
|
117
|
+
const version = sectionVersion(section, name);
|
|
118
|
+
if (version)
|
|
119
|
+
return version;
|
|
120
|
+
if (section.savedId !== undefined)
|
|
121
|
+
return `Saved sections have no variants. Leave out variant to insert "${section.label}".`;
|
|
122
|
+
const known = (section.variants ?? []).map((v) => v.id);
|
|
123
|
+
return `The section "${section.id}" has no variant "${name}". ${known.length > 0 ? `Its variants: ${known.join(', ')}.` : 'It has no variants.'}`;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* The variants of a section for a listing (MCP and assistant `listSections`): id, label,
|
|
127
|
+
* description and what `show` returns for the blocks (an outline or the full JSON). Undefined
|
|
128
|
+
* when the section has none.
|
|
129
|
+
*/
|
|
130
|
+
export function listedVariants(section, show) {
|
|
131
|
+
if (!hasVariants(section))
|
|
132
|
+
return undefined;
|
|
133
|
+
return sectionVersions(section)
|
|
134
|
+
.slice(1)
|
|
135
|
+
.map((v) => ({ id: v.variant, label: v.label, ...(v.description && v.description !== section.description ? { description: v.description } : {}), ...show(v.blocks) }));
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Replaces the section whose root block is `blockId` with another version of it (`variant`
|
|
139
|
+
* undefined: the section itself): a `remove` and an `insert` at the same place, so applied as one
|
|
140
|
+
* batch they are one undo step. Content the user changed carries over (see `carryContent`). The
|
|
141
|
+
* new blocks get new ids; HTML ids that other blocks use are left out. An error message when the
|
|
142
|
+
* block is no inserted app section, or the version does not exist.
|
|
143
|
+
*/
|
|
144
|
+
export function switchSectionVariant(layout, blockId, sections, variant, newId = createId) {
|
|
145
|
+
const block = findBlock(layout, blockId);
|
|
146
|
+
const location = findLocation(layout, blockId);
|
|
147
|
+
if (!block || !location)
|
|
148
|
+
return 'The section is no longer on the page.';
|
|
149
|
+
const origin = block.section;
|
|
150
|
+
if (!origin)
|
|
151
|
+
return 'This block is not a ready-made section.';
|
|
152
|
+
const section = sections.find((s) => s.id === origin.id && s.savedId === undefined);
|
|
153
|
+
if (!section)
|
|
154
|
+
return `The section "${origin.id}" is no longer available.`;
|
|
155
|
+
const versions = sectionVersions(section);
|
|
156
|
+
const target = versions[versionIndex(section, variant)];
|
|
157
|
+
if (!target)
|
|
158
|
+
return `The section "${section.label}" has no variant "${variant}".`;
|
|
159
|
+
const [targetRoot] = target.blocks;
|
|
160
|
+
if (!targetRoot || target.blocks.length !== 1)
|
|
161
|
+
return `"${section.label} (${target.label})" does not have one root block, so it cannot replace this one.`;
|
|
162
|
+
const from = versions[versionIndex(section, origin.variant)]?.blocks;
|
|
163
|
+
const source = from?.length === 1 ? from[0] : undefined;
|
|
164
|
+
const carried = source ? carryContent(block, source, targetRoot) : targetRoot;
|
|
165
|
+
const used = new Set();
|
|
166
|
+
walkBlocks(layout, (b) => void used.add(b.id));
|
|
167
|
+
let fresh = withFreshIds(carried, used, newId);
|
|
168
|
+
fresh.section = target.variant ? { id: section.id, variant: target.variant } : { id: section.id };
|
|
169
|
+
// HTML ids of other blocks stay theirs; the replaced blocks give theirs up.
|
|
170
|
+
const own = new Set(htmlIdsOf([block]).keys());
|
|
171
|
+
const taken = new Set([...htmlIdsOf(layout.blocks).keys()].filter((id) => !own.has(id)));
|
|
172
|
+
fresh = withoutTakenHtmlIds(fresh, taken);
|
|
173
|
+
const to = location.parentId === null ? { parentId: null, index: location.index } : { parentId: location.parentId, slot: location.slot, index: location.index };
|
|
174
|
+
return {
|
|
175
|
+
ops: [
|
|
176
|
+
{ type: 'remove', id: blockId },
|
|
177
|
+
{ type: 'insert', block: fresh, to },
|
|
178
|
+
],
|
|
179
|
+
block: fresh,
|
|
180
|
+
label: target.label,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
/** The block and its children, depth first (each block before its slots, slots in their order). */
|
|
184
|
+
function walkTree(block, out = []) {
|
|
185
|
+
out.push(block);
|
|
186
|
+
for (const children of Object.values(block.slots ?? {}))
|
|
187
|
+
for (const child of children)
|
|
188
|
+
walkTree(child, out);
|
|
189
|
+
return out;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* The blocks of `current` paired with the blocks of `source` (the version it was inserted from):
|
|
193
|
+
* both trees walked side by side, by slot name and index, while the types match. Blocks the user
|
|
194
|
+
* added, removed or moved break the pairing from there on in that list. Source id -> current block.
|
|
195
|
+
*/
|
|
196
|
+
function pairWithSource(current, source, out = new Map()) {
|
|
197
|
+
if (current.type !== source.type)
|
|
198
|
+
return out;
|
|
199
|
+
out.set(source.id, current);
|
|
200
|
+
for (const [name, children] of Object.entries(source.slots ?? {})) {
|
|
201
|
+
const mine = current.slots?.[name] ?? [];
|
|
202
|
+
children.forEach((child, i) => {
|
|
203
|
+
if (mine[i])
|
|
204
|
+
pairWithSource(mine[i], child, out);
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
return out;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Target id -> source block: the root blocks (the section's name and anchor live there, whatever
|
|
211
|
+
* their types), then blocks with the same `id` and type in both versions (authors give a block
|
|
212
|
+
* one id in each version to pair it exactly), then the remaining blocks of each type in order (the
|
|
213
|
+
* first heading with the first heading, and so on).
|
|
214
|
+
*/
|
|
215
|
+
function matchVersions(source, target) {
|
|
216
|
+
const sourceList = walkTree(source);
|
|
217
|
+
const targetList = walkTree(target);
|
|
218
|
+
const matched = new Map([[target.id, source]]);
|
|
219
|
+
const taken = new Set([source.id]);
|
|
220
|
+
for (const t of targetList) {
|
|
221
|
+
if (matched.has(t.id))
|
|
222
|
+
continue;
|
|
223
|
+
const s = sourceList.find((b) => b.id === t.id && b.type === t.type);
|
|
224
|
+
if (s && !taken.has(s.id)) {
|
|
225
|
+
matched.set(t.id, s);
|
|
226
|
+
taken.add(s.id);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
const queues = new Map();
|
|
230
|
+
for (const s of sourceList)
|
|
231
|
+
if (!taken.has(s.id))
|
|
232
|
+
queues.set(s.type, [...(queues.get(s.type) ?? []), s]);
|
|
233
|
+
for (const t of targetList) {
|
|
234
|
+
if (matched.has(t.id))
|
|
235
|
+
continue;
|
|
236
|
+
const s = queues.get(t.type)?.shift();
|
|
237
|
+
if (s)
|
|
238
|
+
matched.set(t.id, s);
|
|
239
|
+
}
|
|
240
|
+
return matched;
|
|
241
|
+
}
|
|
242
|
+
const same = (a, b) => JSON.stringify(sorted(a)) === JSON.stringify(sorted(b));
|
|
243
|
+
function sorted(value) {
|
|
244
|
+
if (Array.isArray(value))
|
|
245
|
+
return value.map(sorted);
|
|
246
|
+
if (value && typeof value === 'object') {
|
|
247
|
+
return Object.fromEntries(Object.keys(value).toSorted().map((k) => [k, sorted(value[k])]));
|
|
248
|
+
}
|
|
249
|
+
return value;
|
|
250
|
+
}
|
|
251
|
+
/** Block keys whose edits carry over to the matching block of the new version. */
|
|
252
|
+
const CARRIED_KEYS = ['label', 'hidden', 'attrs', 'bindings'];
|
|
253
|
+
/**
|
|
254
|
+
* `target` with the content the user changed in `current` since it was inserted from `source`:
|
|
255
|
+
* per matching block (see `matchVersions` and `pairWithSource`), every prop whose value differs
|
|
256
|
+
* from the source version (a cleared or removed prop too), and the name, hidden flag, HTML
|
|
257
|
+
* attributes and bindings when they differ. Classes, animations and the structure come from the
|
|
258
|
+
* new version. A translation stays when the new block's default-locale value is the one it
|
|
259
|
+
* translates. Blocks the user added inside the section are not carried over.
|
|
260
|
+
*/
|
|
261
|
+
export function carryContent(current, source, target) {
|
|
262
|
+
const paired = pairWithSource(current, source);
|
|
263
|
+
const matched = matchVersions(source, target);
|
|
264
|
+
const visit = (block) => {
|
|
265
|
+
const s = matched.get(block.id);
|
|
266
|
+
const c = s ? paired.get(s.id) : undefined;
|
|
267
|
+
let next = c && s ? applyChanges(block, s, c) : { ...block };
|
|
268
|
+
if (block.slots) {
|
|
269
|
+
next = { ...next, slots: Object.fromEntries(Object.entries(block.slots).map(([name, children]) => [name, children.map(visit)])) };
|
|
270
|
+
}
|
|
271
|
+
return next;
|
|
272
|
+
};
|
|
273
|
+
return visit(target);
|
|
274
|
+
}
|
|
275
|
+
function applyChanges(target, source, current) {
|
|
276
|
+
const next = { ...target };
|
|
277
|
+
// Root blocks of other types share only the name, the hidden flag and the HTML attributes.
|
|
278
|
+
if (target.type !== source.type)
|
|
279
|
+
return carryKeys(next, source, current, ['label', 'hidden', 'attrs']);
|
|
280
|
+
const props = { ...target.props };
|
|
281
|
+
const keys = new Set([...Object.keys(source.props ?? {}), ...Object.keys(current.props ?? {})]);
|
|
282
|
+
for (const key of keys) {
|
|
283
|
+
const mine = current.props?.[key];
|
|
284
|
+
if (same(mine, source.props?.[key]))
|
|
285
|
+
continue;
|
|
286
|
+
if (current.props && Object.hasOwn(current.props, key))
|
|
287
|
+
props[key] = structuredClone(mine);
|
|
288
|
+
else
|
|
289
|
+
delete props[key];
|
|
290
|
+
}
|
|
291
|
+
if (Object.keys(props).length > 0)
|
|
292
|
+
next.props = props;
|
|
293
|
+
else
|
|
294
|
+
delete next.props;
|
|
295
|
+
// A translation is right only while the default-locale value it translates stays the same.
|
|
296
|
+
const locales = {};
|
|
297
|
+
for (const [code, values] of Object.entries(current.locales ?? {})) {
|
|
298
|
+
const kept = Object.fromEntries(Object.entries(values).filter(([key]) => same(props[key], current.props?.[key])));
|
|
299
|
+
if (Object.keys(kept).length > 0)
|
|
300
|
+
locales[code] = structuredClone(kept);
|
|
301
|
+
}
|
|
302
|
+
if (Object.keys(locales).length > 0)
|
|
303
|
+
next.locales = locales;
|
|
304
|
+
else
|
|
305
|
+
delete next.locales;
|
|
306
|
+
return carryKeys(next, source, current, CARRIED_KEYS);
|
|
307
|
+
}
|
|
308
|
+
/** `next` with each of `keys` that the user changed (current differs from source) taken from current. */
|
|
309
|
+
function carryKeys(next, source, current, keys) {
|
|
310
|
+
for (const key of keys) {
|
|
311
|
+
if (same(current[key], source[key]))
|
|
312
|
+
continue;
|
|
313
|
+
if (current[key] === undefined)
|
|
314
|
+
delete next[key];
|
|
315
|
+
else
|
|
316
|
+
next[key] = structuredClone(current[key]);
|
|
317
|
+
}
|
|
318
|
+
return next;
|
|
319
|
+
}
|
|
320
|
+
/** A deep copy with new ids that are not in `used` (each new id joins it). */
|
|
321
|
+
function withFreshIds(block, used, newId) {
|
|
322
|
+
let id = newId();
|
|
323
|
+
while (used.has(id))
|
|
324
|
+
id = newId();
|
|
325
|
+
used.add(id);
|
|
326
|
+
const copy = { ...structuredClone(block), id };
|
|
327
|
+
if (block.slots) {
|
|
328
|
+
copy.slots = Object.fromEntries(Object.entries(block.slots).map(([name, list]) => [name, list.map((child) => withFreshIds(child, used, newId))]));
|
|
329
|
+
}
|
|
330
|
+
return copy;
|
|
331
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
type Doc = Record<string, unknown>;
|
|
2
|
+
/** A template's priority: its number, or 0 (also for templates saved before the field existed). */
|
|
3
|
+
export declare function templatePriority(template: Doc): number;
|
|
4
|
+
/** The templates that have conditions, in the order they are tried, each with its `where`. */
|
|
5
|
+
export declare function conditionedTemplates(candidates: readonly Doc[]): Array<{
|
|
6
|
+
template: Doc;
|
|
7
|
+
where: Record<string, unknown>;
|
|
8
|
+
}>;
|
|
9
|
+
/** The default templates, the most recently updated first. */
|
|
10
|
+
export declare function defaultTemplates(candidates: readonly Doc[]): Doc[];
|
|
11
|
+
/** The editor's endpoint for the template a document renders through: `{liveEndpoint}/:collection/:id/template`. */
|
|
12
|
+
export declare const APPLIED_TEMPLATE_PATH = "template";
|
|
13
|
+
/** The answer of that endpoint: the published template `loadTemplate` picks for the latest draft, or null. */
|
|
14
|
+
export type AppliedTemplateResponse = {
|
|
15
|
+
ok: true;
|
|
16
|
+
template: {
|
|
17
|
+
id: string | number;
|
|
18
|
+
name: string;
|
|
19
|
+
} | null;
|
|
20
|
+
} | {
|
|
21
|
+
ok: false;
|
|
22
|
+
error: string;
|
|
23
|
+
};
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// The order in which a document's template is chosen (docs/architecture.md section 11). Pure, so
|
|
2
|
+
// the site (`loadTemplate`), the editor's endpoint and the tests share one rule:
|
|
3
|
+
//
|
|
4
|
+
// 1. the document's own template (its `template` field);
|
|
5
|
+
// 2. else the template with conditions that match the document, highest `priority` first; on
|
|
6
|
+
// equal priority the older template (`createdAt`), then the lower id;
|
|
7
|
+
// 3. else the collection's default template, the most recently updated first.
|
|
8
|
+
//
|
|
9
|
+
// Templates with an empty layout are skipped at every step.
|
|
10
|
+
import { TEMPLATE_DEFAULT_FIELD, TEMPLATE_PRIORITY_FIELD, templateConditions } from './bindings.js';
|
|
11
|
+
/** A template's priority: its number, or 0 (also for templates saved before the field existed). */
|
|
12
|
+
export function templatePriority(template) {
|
|
13
|
+
const value = template[TEMPLATE_PRIORITY_FIELD];
|
|
14
|
+
return typeof value === 'number' && Number.isFinite(value) ? value : 0;
|
|
15
|
+
}
|
|
16
|
+
const timeOf = (value) => {
|
|
17
|
+
const time = typeof value === 'string' ? Date.parse(value) : Number.NaN;
|
|
18
|
+
return Number.isNaN(time) ? 0 : time;
|
|
19
|
+
};
|
|
20
|
+
/** Equal priority: the older template first, then the lower id. */
|
|
21
|
+
function byAge(a, b) {
|
|
22
|
+
const age = timeOf(a.createdAt) - timeOf(b.createdAt);
|
|
23
|
+
if (age !== 0)
|
|
24
|
+
return age;
|
|
25
|
+
return String(a.id).localeCompare(String(b.id), 'en', { numeric: true });
|
|
26
|
+
}
|
|
27
|
+
/** The templates that have conditions, in the order they are tried, each with its `where`. */
|
|
28
|
+
export function conditionedTemplates(candidates) {
|
|
29
|
+
return candidates
|
|
30
|
+
.flatMap((template) => {
|
|
31
|
+
const where = templateConditions(template);
|
|
32
|
+
return where ? [{ template, where }] : [];
|
|
33
|
+
})
|
|
34
|
+
.toSorted((a, b) => templatePriority(b.template) - templatePriority(a.template) || byAge(a.template, b.template));
|
|
35
|
+
}
|
|
36
|
+
/** The default templates, the most recently updated first. */
|
|
37
|
+
export function defaultTemplates(candidates) {
|
|
38
|
+
return candidates
|
|
39
|
+
.filter((template) => template[TEMPLATE_DEFAULT_FIELD] === true)
|
|
40
|
+
.toSorted((a, b) => timeOf(b.updatedAt) - timeOf(a.updatedAt));
|
|
41
|
+
}
|
|
42
|
+
/** The editor's endpoint for the template a document renders through: `{liveEndpoint}/:collection/:id/template`. */
|
|
43
|
+
export const APPLIED_TEMPLATE_PATH = 'template';
|
package/dist/core/tree.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { checkAttrs } from './attrs.js';
|
|
2
2
|
import { createId } from './ids.js';
|
|
3
3
|
import { normalizeMotion } from './motion.js';
|
|
4
|
+
import { checkSectionOrigin } from './sectionOrigin.js';
|
|
5
|
+
import { normalizeVisibility } from './visibility.js';
|
|
4
6
|
import { migrateTextList } from './textList.js';
|
|
5
7
|
/** Slot name used when a position or a location does not name one. The root list uses it too. */
|
|
6
8
|
export const DEFAULT_SLOT = 'children';
|
|
@@ -69,15 +71,17 @@ export function subtreeIds(block, out = []) {
|
|
|
69
71
|
// ---------------------------------------------------------------------------
|
|
70
72
|
// Canonical form (produced here and kept by every operation):
|
|
71
73
|
// - no empty `props`, `bindings` or `slots` objects, and no empty slot lists
|
|
72
|
-
// - `hidden`
|
|
74
|
+
// - `hidden` and `editableItems` are stored only when true, `label` only when non-empty (trimmed)
|
|
73
75
|
// - `locales` holds no empty locale objects, and is left out when empty
|
|
74
76
|
// - `motion` holds only valid kinds and values (motion.ts), and is left out when empty
|
|
75
77
|
// - `attrs` holds only valid, non-empty values (attrs.ts), and is left out when empty
|
|
76
|
-
// - `
|
|
78
|
+
// - `visibility` holds only valid conditions (visibility.ts), and is left out without one
|
|
79
|
+
// - `partClassName` holds only non-blank class strings (by part name), and is left out when empty
|
|
80
|
+
// - `section` (sectionOrigin.ts) is `{ id, variant? }` with non-empty strings, or left out
|
|
77
81
|
// - every id is a non-empty string, unique in the layout
|
|
78
82
|
// - old list blocks (`props.items` rows) hold `listItem` blocks in their `items` slot (textList.ts)
|
|
79
83
|
// The operations module relies on this form for exact undo.
|
|
80
|
-
const BLOCK_KEYS = new Set(['id', 'type', 'blockType', 'blockName', 'props', 'className', 'slots', 'children', 'bindings', 'hidden', 'label', 'locales', 'motion', 'attrs', '
|
|
84
|
+
const BLOCK_KEYS = new Set(['id', 'type', 'blockType', 'blockName', 'props', 'className', 'slots', 'children', 'bindings', 'hidden', 'label', 'locales', 'motion', 'attrs', 'visibility', 'partClassName', 'section', 'editableItems']);
|
|
81
85
|
export function isPlainObject(value) {
|
|
82
86
|
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
83
87
|
return false;
|
|
@@ -158,6 +162,8 @@ function normalizeBlock(value, seen) {
|
|
|
158
162
|
}
|
|
159
163
|
if (value.hidden === true)
|
|
160
164
|
block.hidden = true;
|
|
165
|
+
if (value.editableItems === true)
|
|
166
|
+
block.editableItems = true;
|
|
161
167
|
if (typeof value.label === 'string' && value.label.trim() !== '')
|
|
162
168
|
block.label = value.label.trim();
|
|
163
169
|
// Translations of localized props (locale.ts): no empty locale objects.
|
|
@@ -180,11 +186,17 @@ function normalizeBlock(value, seen) {
|
|
|
180
186
|
const attrs = normalizeAttrs(value.attrs);
|
|
181
187
|
if (attrs)
|
|
182
188
|
block.attrs = attrs;
|
|
183
|
-
|
|
184
|
-
|
|
189
|
+
const visibility = normalizeVisibility(value.visibility);
|
|
190
|
+
if (visibility)
|
|
191
|
+
block.visibility = visibility;
|
|
192
|
+
if (isPlainObject(value.partClassName)) {
|
|
193
|
+
const kept = Object.fromEntries(Object.entries(value.partClassName).filter(([, v]) => typeof v === 'string' && v.trim() !== ''));
|
|
185
194
|
if (Object.keys(kept).length > 0)
|
|
186
|
-
block.
|
|
195
|
+
block.partClassName = kept;
|
|
187
196
|
}
|
|
197
|
+
const origin = checkSectionOrigin(value.section);
|
|
198
|
+
if (origin && typeof origin !== 'string')
|
|
199
|
+
block.section = origin;
|
|
188
200
|
// Old shapes of built-in blocks (see textList.ts).
|
|
189
201
|
migrateTextList(block, (raw) => uniqueId(raw, seen));
|
|
190
202
|
return block;
|