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,24 @@
|
|
|
1
|
+
// Saved sections (server only): `GET {api}/{slug}/:id/used-in` tells the editor how many builder
|
|
2
|
+
// documents use a saved section (a component's copies), for "Used on 3 pages" in the inspector.
|
|
3
|
+
import { findReferrers } from './references.js';
|
|
4
|
+
export const SECTION_USED_IN_PATH = '/:id/used-in';
|
|
5
|
+
/** The endpoint, for the saved sections collection `slug`. Needs a signed-in user. */
|
|
6
|
+
export function sectionUsedInEndpoint(slug) {
|
|
7
|
+
return {
|
|
8
|
+
path: SECTION_USED_IN_PATH,
|
|
9
|
+
method: 'get',
|
|
10
|
+
handler: async (req) => {
|
|
11
|
+
if (!req.user)
|
|
12
|
+
return Response.json({ error: 'Sign in first.' }, { status: 401 });
|
|
13
|
+
const id = req.routeParams?.id;
|
|
14
|
+
if (typeof id !== 'string' && typeof id !== 'number')
|
|
15
|
+
return Response.json({ error: 'No id.' }, { status: 400 });
|
|
16
|
+
const { docs, total } = await findReferrers(req.payload, { relationTo: slug, value: id }, { req, limit: 50 });
|
|
17
|
+
return Response.json({ total, docs: docs.slice(0, 10) });
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/** The saved sections collection with the endpoint added. */
|
|
22
|
+
export function withSectionUsedIn(collection) {
|
|
23
|
+
return { ...collection, endpoints: [...(collection.endpoints || []), sectionUsedInEndpoint(collection.slug)] };
|
|
24
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Endpoint } from 'payload';
|
|
2
|
+
import { type LiveEndpointOptions } from '../live/endpoints.js';
|
|
3
|
+
export declare function templateEndpoint(args: {
|
|
4
|
+
collections: LiveEndpointOptions['collections'];
|
|
5
|
+
/** Slug of the templates collection. */
|
|
6
|
+
templatesSlug: string;
|
|
7
|
+
/** The collections whose documents render through templates. */
|
|
8
|
+
targets: readonly string[];
|
|
9
|
+
}): Endpoint;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// GET {api}/builder/live/:collection/:id/template -> AppliedTemplateResponse
|
|
2
|
+
// The template the site renders a document through, for the editor's empty page. It runs the
|
|
3
|
+
// site's own rule (`findTemplate`, the code behind `loadTemplate`): published templates, with the
|
|
4
|
+
// conditions matched against the document's latest draft.
|
|
5
|
+
import { DOCUMENT_TEMPLATE_FIELD } from '../core/bindings.js';
|
|
6
|
+
import { APPLIED_TEMPLATE_PATH } from '../core/templateChoice.js';
|
|
7
|
+
import { LIVE_PATH, targetOf } from '../live/endpoints.js';
|
|
8
|
+
import { findTemplate } from '../react/render/templates.js';
|
|
9
|
+
const json = (body, status = 200) => Response.json(body, { status, headers: { 'Cache-Control': 'private, no-store' } });
|
|
10
|
+
export function templateEndpoint(args) {
|
|
11
|
+
return {
|
|
12
|
+
path: `${LIVE_PATH}/:collection/:id/${APPLIED_TEMPLATE_PATH}`,
|
|
13
|
+
method: 'get',
|
|
14
|
+
handler: async (req) => {
|
|
15
|
+
if (!req.user)
|
|
16
|
+
return json({ ok: false, error: 'Unauthorized' }, 401);
|
|
17
|
+
const target = targetOf(req, args.collections);
|
|
18
|
+
if (target instanceof Response)
|
|
19
|
+
return target;
|
|
20
|
+
if (!args.targets.includes(target.collection))
|
|
21
|
+
return json({ ok: true, template: null });
|
|
22
|
+
let doc;
|
|
23
|
+
try {
|
|
24
|
+
// The user's own access: only a document the user may read.
|
|
25
|
+
doc = (await req.payload.findByID({
|
|
26
|
+
collection: target.collection,
|
|
27
|
+
id: target.id,
|
|
28
|
+
draft: true,
|
|
29
|
+
depth: 0,
|
|
30
|
+
overrideAccess: false,
|
|
31
|
+
user: req.user,
|
|
32
|
+
select: { [DOCUMENT_TEMPLATE_FIELD]: true },
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return json({ ok: false, error: 'Document not found or not readable' }, 404);
|
|
37
|
+
}
|
|
38
|
+
const found = await findTemplate(req.payload, {
|
|
39
|
+
collection: target.collection,
|
|
40
|
+
doc,
|
|
41
|
+
templatesSlug: args.templatesSlug,
|
|
42
|
+
draft: false,
|
|
43
|
+
documentDraft: true,
|
|
44
|
+
});
|
|
45
|
+
const template = found ? { id: found.template.id, name: String(found.template.name ?? 'Untitled') } : null;
|
|
46
|
+
return json({ ok: true, template });
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
package/dist/plugin/templates.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// Templates for collection documents (docs/architecture.md section 11): the templates collection,
|
|
2
2
|
// the `template` relationship on each target collection, and the bindable field list per collection.
|
|
3
3
|
import { ValidationError, } from 'payload';
|
|
4
|
-
import { DOCUMENT_TEMPLATE_FIELD, TEMPLATE_CONDITIONS_FIELD, TEMPLATE_DEFAULT_FIELD, TEMPLATE_LAYOUT_FIELD, TEMPLATE_PREVIEW_FIELD, TEMPLATE_TARGET_FIELD, URL_PATH, } from '../core/bindings.js';
|
|
5
|
-
import { dataFields, textOf } from '../core/fields.js';
|
|
4
|
+
import { DOCUMENT_TEMPLATE_FIELD, TEMPLATE_CONDITIONS_FIELD, TEMPLATE_DEFAULT_FIELD, TEMPLATE_LAYOUT_FIELD, TEMPLATE_PREVIEW_FIELD, TEMPLATE_PRIORITY_FIELD, TEMPLATE_TARGET_FIELD, URL_PATH, } from '../core/bindings.js';
|
|
5
|
+
import { dataFields, optionList, textOf } from '../core/fields.js';
|
|
6
6
|
import { normalizeLayout } from '../core/tree.js';
|
|
7
7
|
/** Server-only key in `config.custom`: the templates data (`TemplatesClientConfig`) for the MCP tools. */
|
|
8
8
|
export const TEMPLATES_CONFIG_KEY = 'websiteBuilderTemplates';
|
|
@@ -50,6 +50,8 @@ function walk(fields, prefix, byslug, hops, skipFor) {
|
|
|
50
50
|
const out = { path, label: textOf(field.label) ?? humanize(field.name), type: field.type };
|
|
51
51
|
if (field.hasMany)
|
|
52
52
|
out.hasMany = true;
|
|
53
|
+
if ((field.type === 'select' || field.type === 'radio') && field.options)
|
|
54
|
+
out.options = optionList(field);
|
|
53
55
|
if (field.type === 'group' || field.type === 'array') {
|
|
54
56
|
const children = walk(dataFields(field.fields).filter((f) => !isHidden(f)), path, byslug, hops, skipFor);
|
|
55
57
|
if (children.length > 0)
|
|
@@ -212,7 +214,7 @@ export function validateConditions(value) {
|
|
|
212
214
|
if (value === null || value === undefined || value === '')
|
|
213
215
|
return true;
|
|
214
216
|
if (typeof value !== 'object' || Array.isArray(value)) {
|
|
215
|
-
return 'Conditions must be a where query: a JSON object such as {"
|
|
217
|
+
return 'Conditions must be a where query: a JSON object such as {"category": {"equals": "news"}}, or empty.';
|
|
216
218
|
}
|
|
217
219
|
return true;
|
|
218
220
|
}
|
|
@@ -225,7 +227,7 @@ export function templatesCollection(args) {
|
|
|
225
227
|
admin: {
|
|
226
228
|
useAsTitle: 'name',
|
|
227
229
|
defaultColumns: ['name', TEMPLATE_TARGET_FIELD, TEMPLATE_DEFAULT_FIELD, '_status', 'updatedAt'],
|
|
228
|
-
description: '
|
|
230
|
+
description: 'Page designs for the documents of a collection.',
|
|
229
231
|
...admin,
|
|
230
232
|
},
|
|
231
233
|
versions: { maxPerDoc: 20, drafts: { autosave: { interval: 300 } } },
|
|
@@ -252,7 +254,7 @@ export function templatesCollection(args) {
|
|
|
252
254
|
defaultValue: false,
|
|
253
255
|
admin: {
|
|
254
256
|
position: 'sidebar',
|
|
255
|
-
description: '
|
|
257
|
+
description: 'For documents that no other template matches.',
|
|
256
258
|
components: { Cell: 'payload-canvas/client#TemplateDefaultCell' },
|
|
257
259
|
},
|
|
258
260
|
},
|
|
@@ -262,7 +264,20 @@ export function templatesCollection(args) {
|
|
|
262
264
|
label: 'Conditions',
|
|
263
265
|
validate: validateConditions,
|
|
264
266
|
admin: {
|
|
265
|
-
description: '
|
|
267
|
+
description: 'Only for documents that match.',
|
|
268
|
+
// Condition rows (field, operator, value) over the target collection's fields; "Edit as JSON" for the rest.
|
|
269
|
+
components: { Field: 'payload-canvas/client#TemplateConditionsField' },
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
name: TEMPLATE_PRIORITY_FIELD,
|
|
274
|
+
type: 'number',
|
|
275
|
+
label: 'Priority',
|
|
276
|
+
defaultValue: 0,
|
|
277
|
+
admin: {
|
|
278
|
+
position: 'sidebar',
|
|
279
|
+
description: 'When several templates match, the highest number wins.',
|
|
280
|
+
condition: (data) => Boolean(data?.[TEMPLATE_CONDITIONS_FIELD] && Object.keys(data[TEMPLATE_CONDITIONS_FIELD]).length > 0),
|
|
266
281
|
},
|
|
267
282
|
},
|
|
268
283
|
{
|
|
@@ -271,7 +286,7 @@ export function templatesCollection(args) {
|
|
|
271
286
|
label: 'Preview document',
|
|
272
287
|
relationTo: targets,
|
|
273
288
|
filterOptions: ({ relationTo, data }) => relationTo === data?.[TEMPLATE_TARGET_FIELD],
|
|
274
|
-
admin: { position: 'sidebar', description: 'The editor shows
|
|
289
|
+
admin: { position: 'sidebar', description: 'The editor shows its data.' },
|
|
275
290
|
},
|
|
276
291
|
],
|
|
277
292
|
};
|
|
@@ -284,7 +299,7 @@ export function documentTemplateField(target, templatesSlug) {
|
|
|
284
299
|
label: 'Template',
|
|
285
300
|
relationTo: templatesSlug,
|
|
286
301
|
filterOptions: { [TEMPLATE_TARGET_FIELD]: { equals: target } },
|
|
287
|
-
admin: { position: 'sidebar', description: '
|
|
302
|
+
admin: { position: 'sidebar', description: 'Empty: the matching template.' },
|
|
288
303
|
};
|
|
289
304
|
}
|
|
290
305
|
export function hasFieldNamed(fields, name) {
|
package/dist/protocol/index.d.ts
CHANGED
|
@@ -24,6 +24,16 @@ export type CanvasInit = {
|
|
|
24
24
|
regions?: RegionConfig[];
|
|
25
25
|
/** Collection -> relationship field path -> related collection, for `<path>.$url` bindings. */
|
|
26
26
|
relations?: Record<string, Record<string, string>>;
|
|
27
|
+
/**
|
|
28
|
+
* Full API path that lists the editable classes (`GET {api}/builder/classes`). The canvas compiles
|
|
29
|
+
* their latest drafts, and follows the editor's edits on `CLASSES_CHANNEL`. Left out: no classes.
|
|
30
|
+
*/
|
|
31
|
+
classesEndpoint?: string;
|
|
32
|
+
/**
|
|
33
|
+
* The saved sections collection: the canvas loads the blocks of live saved sections (components'
|
|
34
|
+
* copies) from it. The app's own block list usually has no `sectionRef` definition to name it.
|
|
35
|
+
*/
|
|
36
|
+
savedSections?: string | null;
|
|
27
37
|
};
|
|
28
38
|
export type PointerKind = 'move' | 'leave' | 'click';
|
|
29
39
|
/** One section to picture. The iframe answers with a `thumbnail` message with the same `key`. */
|
|
@@ -109,12 +119,17 @@ export type CanvasToAdmin =
|
|
|
109
119
|
type: 'measure';
|
|
110
120
|
measurement: CanvasMeasurement;
|
|
111
121
|
}
|
|
112
|
-
/**
|
|
122
|
+
/**
|
|
123
|
+
* Pointer position in iframe viewport coordinates. `control`: the pointer is over a canvas
|
|
124
|
+
* control (`data-builder-control`, a carousel's arrow), which acts as on the site: the editor
|
|
125
|
+
* shows no hover outline and no "+" there. A click on a control sends no `click`.
|
|
126
|
+
*/
|
|
113
127
|
| {
|
|
114
128
|
type: 'pointer';
|
|
115
129
|
kind: PointerKind;
|
|
116
130
|
x: number;
|
|
117
131
|
y: number;
|
|
132
|
+
control?: boolean;
|
|
118
133
|
} | {
|
|
119
134
|
type: 'key';
|
|
120
135
|
key: KeyAction;
|
|
@@ -4,12 +4,18 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
|
|
|
4
4
|
// block and slot rectangles, the pointer and editor shortcuts back. It holds no selection or drop logic.
|
|
5
5
|
import { collectClasses, createId, findBlock, joinListItem, TEXT_LIST_ITEM_BLOCK, } from '../../core/index.js';
|
|
6
6
|
import { createCanvasCompiler } from '../../css/browser.js';
|
|
7
|
+
import { THEME_CHANNEL } from '../../theme/config.js';
|
|
8
|
+
import { classNamesOf, withoutClassNames } from '../../classes/shared.js';
|
|
9
|
+
import { useCanvasClasses, useClassSheet } from './classes.js';
|
|
7
10
|
import { keyAction, post, setPropPath, unwrap, } from '../../protocol/index.js';
|
|
8
11
|
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react';
|
|
9
12
|
import { flushSync } from 'react-dom';
|
|
10
13
|
import { defaultResolveLink, RenderLayout } from '../index.js';
|
|
14
|
+
import { CanvasModeContext } from '../render/canvasMode.js';
|
|
11
15
|
import { LayoutOutlet, LayoutOutletContext, LayoutOutletPresence } from '../render/LayoutOutlet.js';
|
|
12
16
|
import { LAYOUT_ROOT_ATTRIBUTE, REGION_ATTRIBUTE } from '../render/regions.js';
|
|
17
|
+
import { revealBlock } from '../render/reveal.js';
|
|
18
|
+
import { blockElement, controlAt, onBackdrop, revealInCanvas, summaryOwner } from './controls.js';
|
|
13
19
|
import { createCanvasDrag } from './drag.js';
|
|
14
20
|
import { forgetDoc } from './fetchDocs.js';
|
|
15
21
|
import { editableAt, firstEditable } from './inline/dom.js';
|
|
@@ -90,6 +96,11 @@ span[data-builder-passthrough] { display: inline-block; margin: 0 2px; padding:
|
|
|
90
96
|
`;
|
|
91
97
|
/** Room kept above and below a block scrolled into view (the toolbar sits above it). */
|
|
92
98
|
const SCROLL_MARGIN = 48;
|
|
99
|
+
/**
|
|
100
|
+
* A click on a summary that edits in place opens or closes its item this long after the click,
|
|
101
|
+
* unless a double-click (which edits the text) follows. Other summary clicks act at once.
|
|
102
|
+
*/
|
|
103
|
+
const SUMMARY_TOGGLE_DELAY_MS = 260;
|
|
93
104
|
function send(message) {
|
|
94
105
|
post(window.parent, message);
|
|
95
106
|
}
|
|
@@ -111,10 +122,13 @@ const canvasMode = () => (new URLSearchParams(window.location.search).get('mode'
|
|
|
111
122
|
export function BuilderCanvas(props) {
|
|
112
123
|
// Null on the server and in the hydration render: the page reads its URL in the browser only.
|
|
113
124
|
const mode = useSyncExternalStore(subscribeNothing, canvasMode, () => null);
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
125
|
+
// `useCanvasMode()` in block components (and client components inside server blocks) reads it.
|
|
126
|
+
if (mode === 'thumbnail') {
|
|
127
|
+
return (_jsx(CanvasModeContext.Provider, { value: "thumbnail", children: _jsx(ThumbnailCanvas, { ...props }) }));
|
|
128
|
+
}
|
|
129
|
+
if (mode === 'editor') {
|
|
130
|
+
return (_jsx(CanvasModeContext.Provider, { value: "canvas", children: _jsx(EditorCanvas, { ...props }) }));
|
|
131
|
+
}
|
|
118
132
|
return null;
|
|
119
133
|
}
|
|
120
134
|
/** The scope the canvas server action renders for. `locale`: the editor's locale. */
|
|
@@ -443,7 +457,10 @@ function EditorCanvas({ blocks, components, plugins, resolveLink, server }) {
|
|
|
443
457
|
let hasInit = false;
|
|
444
458
|
let hasLayout = false;
|
|
445
459
|
let lastPointer = null;
|
|
446
|
-
|
|
460
|
+
// `control`: the pointer is over a canvas control (a carousel arrow): no hover, no "+".
|
|
461
|
+
const sendPointer = (kind, x, y, control = false) => send({ type: 'pointer', kind, x, y, ...(control ? { control: true } : {}) });
|
|
462
|
+
// A canvas control, or the backdrop of an open popup: it acts as on the site.
|
|
463
|
+
const isControl = (target, x, y) => Boolean(controlAt(target)) || onBackdrop(target, x, y);
|
|
447
464
|
// Either side may load first, so repeat `ready` until the init data and a layout arrive.
|
|
448
465
|
const readyTimer = window.setInterval(() => send({ type: 'ready' }), 250);
|
|
449
466
|
const stopReady = () => {
|
|
@@ -453,7 +470,7 @@ function EditorCanvas({ blocks, components, plugins, resolveLink, server }) {
|
|
|
453
470
|
// Scrolls a block into view with room around it, so it never stops flush at the edge
|
|
454
471
|
// (under the editor's floating toolbar). A block taller than the view shows its top.
|
|
455
472
|
const scrollToBlock = (id) => {
|
|
456
|
-
const el =
|
|
473
|
+
const el = blockElement(id);
|
|
457
474
|
if (!el)
|
|
458
475
|
return;
|
|
459
476
|
const rect = el.getBoundingClientRect();
|
|
@@ -466,6 +483,27 @@ function EditorCanvas({ blocks, components, plugins, resolveLink, server }) {
|
|
|
466
483
|
if (delta !== 0)
|
|
467
484
|
window.scrollBy({ top: delta, behavior: 'smooth' });
|
|
468
485
|
};
|
|
486
|
+
// Brings a selected block out of a closed item, another slide or tab first (see
|
|
487
|
+
// `revealInCanvas`), then scrolls to it once the reveal has rendered (two frames: React's
|
|
488
|
+
// update, then its layout).
|
|
489
|
+
let revealFrame = 0;
|
|
490
|
+
// The item a summary click just toggled: the selection that the same click makes (the
|
|
491
|
+
// disclosure) must not open it again.
|
|
492
|
+
let toggled = null;
|
|
493
|
+
const justToggled = (details) => toggled?.details === details && Date.now() - toggled.at < 300;
|
|
494
|
+
const revealAndScroll = (id) => {
|
|
495
|
+
const el = blockElement(id);
|
|
496
|
+
if (!el)
|
|
497
|
+
return;
|
|
498
|
+
revealInCanvas(el, justToggled);
|
|
499
|
+
cancelAnimationFrame(revealFrame);
|
|
500
|
+
revealFrame = requestAnimationFrame(() => {
|
|
501
|
+
revealFrame = requestAnimationFrame(() => {
|
|
502
|
+
revealFrame = 0;
|
|
503
|
+
scrollToBlock(id);
|
|
504
|
+
});
|
|
505
|
+
});
|
|
506
|
+
};
|
|
469
507
|
const onMessage = (event) => {
|
|
470
508
|
const message = unwrap(event, window.parent);
|
|
471
509
|
if (!message)
|
|
@@ -492,14 +530,18 @@ function EditorCanvas({ blocks, components, plugins, resolveLink, server }) {
|
|
|
492
530
|
}
|
|
493
531
|
case 'selection':
|
|
494
532
|
if (message.selectedId && message.selectedId !== selectedRef.current)
|
|
495
|
-
|
|
533
|
+
revealAndScroll(message.selectedId);
|
|
534
|
+
// Nothing selected any more (Escape): the reveal event from <html>, outside every block,
|
|
535
|
+
// so open popups close.
|
|
536
|
+
if (!message.selectedId && selectedRef.current)
|
|
537
|
+
revealBlock(document.documentElement);
|
|
496
538
|
selectedRef.current = message.selectedId;
|
|
497
539
|
return;
|
|
498
540
|
case 'scrollBy':
|
|
499
541
|
window.scrollBy(message.dx, message.dy);
|
|
500
542
|
return;
|
|
501
543
|
case 'scrollIntoView':
|
|
502
|
-
|
|
544
|
+
revealAndScroll(message.id);
|
|
503
545
|
return;
|
|
504
546
|
case 'context':
|
|
505
547
|
setContext(message.context);
|
|
@@ -574,7 +616,8 @@ function EditorCanvas({ blocks, components, plugins, resolveLink, server }) {
|
|
|
574
616
|
// Images: the upload props under the pointer. Sent only when they change.
|
|
575
617
|
let lastImage = '';
|
|
576
618
|
let imageFrame = 0;
|
|
577
|
-
|
|
619
|
+
// No image under the backdrop of an open popup: the page behind it is out of reach.
|
|
620
|
+
const imageAt = (x, y) => activeRef.current || onBackdrop(document.elementFromPoint(x, y), x, y) ? null : mapper.imageTarget(x, y);
|
|
578
621
|
const sendImageHover = (target, dropping = false) => {
|
|
579
622
|
const key = target ? JSON.stringify([target, dropping]) : '';
|
|
580
623
|
if (key === lastImage)
|
|
@@ -650,19 +693,22 @@ function EditorCanvas({ blocks, components, plugins, resolveLink, server }) {
|
|
|
650
693
|
return;
|
|
651
694
|
if (!(e.target instanceof Element) || !e.target.closest('[data-block-id]'))
|
|
652
695
|
return;
|
|
696
|
+
if (onBackdrop(e.target, e.clientX, e.clientY))
|
|
697
|
+
return;
|
|
653
698
|
e.preventDefault();
|
|
654
699
|
send({ type: 'contextMenu', x: e.clientX, y: e.clientY });
|
|
655
700
|
};
|
|
701
|
+
// The page or an element in it scrolled (a carousel sends `scroll` from its viewport too).
|
|
656
702
|
const onScroll = () => {
|
|
657
703
|
scheduleMeasure();
|
|
658
704
|
// The block under a still pointer changes when the page scrolls.
|
|
659
705
|
if (lastPointer)
|
|
660
|
-
sendPointer('move', lastPointer.x, lastPointer.y);
|
|
706
|
+
sendPointer('move', lastPointer.x, lastPointer.y, isControl(document.elementFromPoint(lastPointer.x, lastPointer.y), lastPointer.x, lastPointer.y));
|
|
661
707
|
scheduleImageHover();
|
|
662
708
|
};
|
|
663
709
|
const onPointerMove = (e) => {
|
|
664
710
|
lastPointer = { x: e.clientX, y: e.clientY };
|
|
665
|
-
sendPointer('move', e.clientX, e.clientY);
|
|
711
|
+
sendPointer('move', e.clientX, e.clientY, isControl(e.target, e.clientX, e.clientY));
|
|
666
712
|
scheduleImageHover();
|
|
667
713
|
};
|
|
668
714
|
const onPointerLeave = () => {
|
|
@@ -670,15 +716,50 @@ function EditorCanvas({ blocks, components, plugins, resolveLink, server }) {
|
|
|
670
716
|
sendPointer('leave', 0, 0);
|
|
671
717
|
sendImageHover(null);
|
|
672
718
|
};
|
|
719
|
+
// A popup or a `<details>` opened or closed (`toggle` does not bubble: captured). An open popup
|
|
720
|
+
// changes no size on the page, so measure here, and watch the blocks that now show.
|
|
721
|
+
const onToggle = (e) => {
|
|
722
|
+
const ro = observer.current;
|
|
723
|
+
if (ro && e.target instanceof Element)
|
|
724
|
+
for (const el of e.target.querySelectorAll('[data-block-id], [data-slot-owner]'))
|
|
725
|
+
ro.observe(el);
|
|
726
|
+
scheduleMeasure();
|
|
727
|
+
};
|
|
673
728
|
// Another canvas width: other elements may show (responsive copies), so map again.
|
|
674
729
|
const onResize = () => {
|
|
675
730
|
scheduleMeasure();
|
|
676
731
|
mapper.invalidate();
|
|
677
732
|
};
|
|
678
|
-
//
|
|
733
|
+
// A click on a summary opens or closes its item, as on the site, and selects as usual. On text
|
|
734
|
+
// that a double-click edits, it waits: the double-click edits the text and toggles nothing.
|
|
735
|
+
let summaryTimer = 0;
|
|
736
|
+
const toggleSummary = (e) => {
|
|
737
|
+
const details = summaryOwner(e.target);
|
|
738
|
+
if (!details || isEditing(e.target))
|
|
739
|
+
return;
|
|
740
|
+
window.clearTimeout(summaryTimer);
|
|
741
|
+
if (e.detail > 1)
|
|
742
|
+
return;
|
|
743
|
+
const toggle = () => {
|
|
744
|
+
details.open = !details.open;
|
|
745
|
+
toggled = { details, at: Date.now() };
|
|
746
|
+
};
|
|
747
|
+
const ownerEl = e.target instanceof Element ? ownerOf(e.target)?.element : null;
|
|
748
|
+
if (ownerEl)
|
|
749
|
+
mapper.ensure(ownerEl);
|
|
750
|
+
if (e.target instanceof Element && editableAt(e.target))
|
|
751
|
+
summaryTimer = window.setTimeout(toggle, SUMMARY_TOGGLE_DELAY_MS);
|
|
752
|
+
else
|
|
753
|
+
toggle();
|
|
754
|
+
};
|
|
755
|
+
// Edit mode: links, buttons and forms inside blocks must not act. Canvas controls (a
|
|
756
|
+
// carousel's arrows, a popup's backdrop) act as on the site and select nothing.
|
|
679
757
|
const onClick = (e) => {
|
|
758
|
+
if (isControl(e.target, e.clientX, e.clientY) && !isEditing(e.target))
|
|
759
|
+
return;
|
|
680
760
|
e.preventDefault();
|
|
681
761
|
e.stopPropagation();
|
|
762
|
+
toggleSummary(e);
|
|
682
763
|
sendPointer('click', e.clientX, e.clientY);
|
|
683
764
|
};
|
|
684
765
|
const block = (e) => e.preventDefault();
|
|
@@ -707,8 +788,10 @@ function EditorCanvas({ blocks, components, plugins, resolveLink, server }) {
|
|
|
707
788
|
send({ type: 'key', key });
|
|
708
789
|
};
|
|
709
790
|
window.addEventListener('message', onMessage);
|
|
710
|
-
|
|
791
|
+
// Capture: element scrolls (a scrolling list, a carousel) do not bubble.
|
|
792
|
+
document.addEventListener('scroll', onScroll, { capture: true, passive: true });
|
|
711
793
|
window.addEventListener('resize', onResize);
|
|
794
|
+
document.addEventListener('toggle', onToggle, true);
|
|
712
795
|
document.addEventListener('pointermove', onPointerMove);
|
|
713
796
|
document.documentElement.addEventListener('pointerleave', onPointerLeave);
|
|
714
797
|
document.addEventListener('click', onClick, true);
|
|
@@ -727,10 +810,13 @@ function EditorCanvas({ blocks, components, plugins, resolveLink, server }) {
|
|
|
727
810
|
return () => {
|
|
728
811
|
window.clearInterval(readyTimer);
|
|
729
812
|
window.removeEventListener('message', onMessage);
|
|
730
|
-
|
|
813
|
+
document.removeEventListener('scroll', onScroll, { capture: true });
|
|
814
|
+
window.clearTimeout(summaryTimer);
|
|
815
|
+
cancelAnimationFrame(revealFrame);
|
|
731
816
|
window.removeEventListener('resize', onResize);
|
|
732
817
|
document.removeEventListener('pointermove', onPointerMove);
|
|
733
818
|
document.documentElement.removeEventListener('pointerleave', onPointerLeave);
|
|
819
|
+
document.removeEventListener('toggle', onToggle, true);
|
|
734
820
|
document.removeEventListener('click', onClick, true);
|
|
735
821
|
document.removeEventListener('auxclick', block, true);
|
|
736
822
|
document.removeEventListener('submit', block, true);
|
|
@@ -751,17 +837,52 @@ function EditorCanvas({ blocks, components, plugins, resolveLink, server }) {
|
|
|
751
837
|
}, [scheduleMeasure, startInline, stopInline, drag, motion, mapper, serverBlocks]);
|
|
752
838
|
// The CSS endpoint comes from the admin, or from `?cssEndpoint=` when the page is opened alone.
|
|
753
839
|
const cssEndpoint = init?.cssEndpoint ?? null;
|
|
840
|
+
const [cssInput, setCssInput] = useState(null);
|
|
841
|
+
// A theme save can add or rename design variables (`bg-brand`): load the CSS input again.
|
|
842
|
+
const [themeSaves, setThemeSaves] = useState(0);
|
|
843
|
+
useEffect(() => {
|
|
844
|
+
if (typeof BroadcastChannel === 'undefined')
|
|
845
|
+
return;
|
|
846
|
+
const channel = new BroadcastChannel(THEME_CHANNEL);
|
|
847
|
+
channel.addEventListener('message', () => setThemeSaves((n) => n + 1));
|
|
848
|
+
return () => channel.close();
|
|
849
|
+
}, []);
|
|
754
850
|
useEffect(() => {
|
|
755
851
|
const endpoint = cssEndpoint ?? new URLSearchParams(window.location.search).get('cssEndpoint');
|
|
756
852
|
if (!endpoint)
|
|
757
853
|
return;
|
|
758
854
|
let cancelled = false;
|
|
759
|
-
fetch(endpoint, { credentials: 'include' })
|
|
855
|
+
fetch(endpoint, { credentials: 'include', cache: 'no-store' })
|
|
760
856
|
.then(async (res) => {
|
|
761
857
|
if (!res.ok)
|
|
762
858
|
throw new Error(`${res.status} ${res.statusText}`);
|
|
763
|
-
|
|
859
|
+
const input = (await res.json());
|
|
860
|
+
if (!cancelled)
|
|
861
|
+
setCssInput(input);
|
|
764
862
|
})
|
|
863
|
+
.catch((error) => {
|
|
864
|
+
if (cancelled)
|
|
865
|
+
return;
|
|
866
|
+
setCompiler({ status: 'failed' });
|
|
867
|
+
send({ type: 'error', message: `Canvas CSS failed to load: ${String(error)}` });
|
|
868
|
+
});
|
|
869
|
+
return () => {
|
|
870
|
+
cancelled = true;
|
|
871
|
+
};
|
|
872
|
+
}, [cssEndpoint, themeSaves]);
|
|
873
|
+
// Editable classes: their own stylesheet, compiled from the latest drafts. The layout's CSS
|
|
874
|
+
// leaves their names out, as the site's page CSS does.
|
|
875
|
+
const dbClasses = useCanvasClasses(init ? (init.classesEndpoint ?? null) : null);
|
|
876
|
+
const classSheet = useClassSheet(cssInput, dbClasses, pluginsRef.current);
|
|
877
|
+
const classNames = useMemo(() => classNamesOf(dbClasses ?? []), [dbClasses]);
|
|
878
|
+
const namesKey = useMemo(() => [...classNames].toSorted().join(' '), [classNames]);
|
|
879
|
+
// A fresh compiler for every new set of class names: a compiler outputs every class it ever
|
|
880
|
+
// built, and a class name may have been built as a code `@utility` before.
|
|
881
|
+
useEffect(() => {
|
|
882
|
+
if (!cssInput)
|
|
883
|
+
return;
|
|
884
|
+
let cancelled = false;
|
|
885
|
+
createCanvasCompiler(cssInput, pluginsRef.current)
|
|
765
886
|
.then((next) => {
|
|
766
887
|
if (!cancelled)
|
|
767
888
|
setCompiler({ status: 'ready', compiler: next });
|
|
@@ -775,7 +896,7 @@ function EditorCanvas({ blocks, components, plugins, resolveLink, server }) {
|
|
|
775
896
|
return () => {
|
|
776
897
|
cancelled = true;
|
|
777
898
|
};
|
|
778
|
-
}, [
|
|
899
|
+
}, [cssInput, namesKey]);
|
|
779
900
|
// Bind the template to the sample document, load collection lists, then replace upload and
|
|
780
901
|
// relationship IDs with documents. The newest layout wins.
|
|
781
902
|
const resolveRun = useRef(0);
|
|
@@ -785,7 +906,7 @@ function EditorCanvas({ blocks, components, plugins, resolveLink, server }) {
|
|
|
785
906
|
if (!layout || !init || !definitions)
|
|
786
907
|
return;
|
|
787
908
|
const run = ++resolveRun.current;
|
|
788
|
-
resolveCanvasLayout(layout, context, init.api, definitions, linkResolver, locale, init.relations)
|
|
909
|
+
resolveCanvasLayout(layout, context, init.api, definitions, linkResolver, locale, init.relations, init.savedSections)
|
|
789
910
|
.then((next) => {
|
|
790
911
|
if (run !== resolveRun.current)
|
|
791
912
|
return;
|
|
@@ -861,7 +982,7 @@ function EditorCanvas({ blocks, components, plugins, resolveLink, server }) {
|
|
|
861
982
|
const canvasComponents = useMemo(() => withServerBlocks(components, definitions, Boolean(serverBlocks)), [components, definitions, serverBlocks]);
|
|
862
983
|
// One compile per distinct class set (about 4 ms). `null` until a layout is resolved.
|
|
863
984
|
// Block definitions add the classes their components use (`BlockDefinition.classes`).
|
|
864
|
-
const classKey = useMemo(() => (resolved ? collectClasses(resolved, definitions).join(' ') : null), [resolved, definitions]);
|
|
985
|
+
const classKey = useMemo(() => (resolved ? withoutClassNames(collectClasses(resolved, definitions), classNames).join(' ') : null), [resolved, definitions, classNames]);
|
|
865
986
|
const css = useMemo(() => {
|
|
866
987
|
if (compiler.status !== 'ready' || classKey === null)
|
|
867
988
|
return '';
|
|
@@ -910,7 +1031,9 @@ function EditorCanvas({ blocks, components, plugins, resolveLink, server }) {
|
|
|
910
1031
|
}, [freeze]);
|
|
911
1032
|
// With regions the first frame is awaited too (also in the render before its request starts), so nothing moves when it arrives.
|
|
912
1033
|
const frameLoading = Boolean(init?.regions?.length) && (frame.status === 'loading' || frame.status === 'off');
|
|
913
|
-
|
|
1034
|
+
// The classes' stylesheet first, so blocks never show without their classes.
|
|
1035
|
+
const classesReady = !init?.classesEndpoint || compiler.status === 'failed' || classSheet !== null;
|
|
1036
|
+
const visible = shown && compiler.status !== 'loading' && pageData !== undefined && !frameLoading && classesReady;
|
|
914
1037
|
// Observes the current block and slot elements and measures.
|
|
915
1038
|
const observeBlocks = useCallback(() => {
|
|
916
1039
|
const ro = observer.current;
|
|
@@ -960,5 +1083,5 @@ function EditorCanvas({ blocks, components, plugins, resolveLink, server }) {
|
|
|
960
1083
|
page = outlet;
|
|
961
1084
|
}
|
|
962
1085
|
}
|
|
963
|
-
return (_jsxs(_Fragment, { children: [_jsx("style", { "data-builder-editor-css": "", children: EDITOR_CSS }), _jsx("div", { ref: rootRef, "data-builder-root": "", children: page })] }));
|
|
1086
|
+
return (_jsxs(_Fragment, { children: [_jsx("style", { "data-builder-editor-css": "", children: EDITOR_CSS }), classSheet?.css ? _jsx("style", { "data-builder-classes": "", children: classSheet.css }) : null, _jsx("div", { ref: rootRef, "data-builder-root": "", children: page })] }));
|
|
964
1087
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type BuilderClass } from '../../classes/shared.js';
|
|
2
|
+
import type { CanvasCssInput, TailwindPlugins } from '../../css/index.js';
|
|
3
|
+
import { type ClassSheet } from '../../css/classes.js';
|
|
4
|
+
/** The classes from the endpoint. An empty list when it fails (the canvas then works without them). */
|
|
5
|
+
export declare function fetchCanvasClasses(endpoint: string): Promise<BuilderClass[]>;
|
|
6
|
+
/**
|
|
7
|
+
* The classes the canvas shows. Null while the first list loads; always an empty list without an
|
|
8
|
+
* endpoint. Follows the editor's edits (BroadcastChannel) and loads again when the page becomes
|
|
9
|
+
* visible.
|
|
10
|
+
*/
|
|
11
|
+
export declare function useCanvasClasses(endpoint: string | null): BuilderClass[] | null;
|
|
12
|
+
/**
|
|
13
|
+
* The stylesheet of `classes`, compiled against the canvas's CSS input. Null until the first
|
|
14
|
+
* compile is done (or while `classes` loads). A result shows unless a newer one already did, so a
|
|
15
|
+
* slider drag updates the canvas while it moves.
|
|
16
|
+
*/
|
|
17
|
+
export declare function useClassSheet(input: CanvasCssInput | null, classes: BuilderClass[] | null, plugins?: TailwindPlugins): ClassSheet | null;
|