payload-canvas 0.4.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +626 -154
- package/dist/admin/AiKeyField.d.ts +8 -0
- package/dist/admin/AiKeyField.js +54 -0
- package/dist/admin/BuilderTab.js +4 -1
- package/dist/admin/DocumentEditView.d.ts +9 -0
- package/dist/admin/DocumentEditView.js +45 -0
- package/dist/admin/LayoutField.d.ts +2 -2
- package/dist/admin/LayoutField.js +10 -7
- package/dist/admin/TemplateConditionsField.d.ts +9 -0
- package/dist/admin/TemplateConditionsField.js +22 -0
- package/dist/admin/aiKeyField.scss +58 -0
- package/dist/admin/client.d.ts +3 -0
- package/dist/admin/client.js +6 -0
- package/dist/admin/diff/changes.js +5 -0
- package/dist/admin/editor/Canvas.js +20 -5
- package/dist/admin/editor/Editor.d.ts +3 -1
- package/dist/admin/editor/Editor.js +6 -3
- package/dist/admin/editor/Inspector.js +75 -28
- package/dist/admin/editor/Library.js +40 -15
- package/dist/admin/editor/Outline.js +21 -16
- package/dist/admin/editor/Overlay.js +8 -3
- package/dist/admin/editor/actions.d.ts +10 -2
- package/dist/admin/editor/actions.js +18 -3
- package/dist/admin/editor/assistant/AssistantPanel.js +3 -1
- package/dist/admin/editor/classes/ClassManager.d.ts +4 -0
- package/dist/admin/editor/classes/ClassManager.js +56 -0
- package/dist/admin/editor/classes/controller.d.ts +112 -0
- package/dist/admin/editor/classes/controller.js +326 -0
- package/dist/admin/editor/classes/manager.scss +262 -0
- package/dist/admin/editor/classes/managerModel.d.ts +5 -0
- package/dist/admin/editor/classes/managerModel.js +27 -0
- package/dist/admin/editor/comments/CommentLayer.d.ts +2 -0
- package/dist/admin/editor/comments/CommentLayer.js +143 -0
- package/dist/admin/editor/comments/CommentsPanel.d.ts +8 -0
- package/dist/admin/editor/comments/CommentsPanel.js +73 -0
- package/dist/admin/editor/comments/Thread.d.ts +26 -0
- package/dist/admin/editor/comments/Thread.js +84 -0
- package/dist/admin/editor/comments/comments.scss +539 -0
- package/dist/admin/editor/comments/controller.d.ts +48 -0
- package/dist/admin/editor/comments/controller.js +142 -0
- package/dist/admin/editor/contentMode.d.ts +17 -0
- package/dist/admin/editor/contentMode.js +37 -0
- package/dist/admin/editor/dnd/DropOutlines.d.ts +1 -0
- package/dist/admin/editor/dnd/DropOutlines.js +73 -0
- package/dist/admin/editor/dnd/dnd.scss +43 -0
- package/dist/admin/editor/dnd/mode.d.ts +4 -0
- package/dist/admin/editor/dnd/mode.js +39 -0
- package/dist/admin/editor/editor.scss +13 -58
- package/dist/admin/editor/empty/EmptyStart.js +18 -66
- package/dist/admin/editor/fields/AddButton.d.ts +15 -0
- package/dist/admin/editor/fields/AddButton.js +14 -0
- package/dist/admin/editor/fields/ArrayField.js +3 -2
- package/dist/admin/editor/fields/CheckedInputs.d.ts +1 -0
- package/dist/admin/editor/fields/ConditionRows.d.ts +19 -0
- package/dist/admin/editor/fields/ConditionRows.js +137 -0
- package/dist/admin/editor/fields/ListWhereField.d.ts +8 -0
- package/dist/admin/editor/fields/ListWhereField.js +20 -0
- package/dist/admin/editor/fields/QueryFiltersField.d.ts +18 -0
- package/dist/admin/editor/fields/QueryFiltersField.js +41 -0
- package/dist/admin/editor/fields/RelatedField.d.ts +19 -0
- package/dist/admin/editor/fields/RelatedField.js +44 -0
- package/dist/admin/editor/fields/SortField.d.ts +13 -0
- package/dist/admin/editor/fields/SortField.js +37 -0
- package/dist/admin/editor/fields/WhereField.d.ts +12 -4
- package/dist/admin/editor/fields/WhereField.js +33 -53
- package/dist/admin/editor/fields/collectionFields.d.ts +6 -0
- package/dist/admin/editor/fields/collectionFields.js +15 -0
- package/dist/admin/editor/fields/conditions.d.ts +99 -0
- package/dist/admin/editor/fields/conditions.js +339 -0
- package/dist/admin/editor/fields/fields.scss +232 -9
- package/dist/admin/editor/fields/listOptions.d.ts +44 -0
- package/dist/admin/editor/fields/listOptions.js +111 -0
- package/dist/admin/editor/fields/queryFilterRows.d.ts +8 -0
- package/dist/admin/editor/fields/queryFilterRows.js +29 -0
- package/dist/admin/editor/fields/whereRows.d.ts +11 -12
- package/dist/admin/editor/fields/whereRows.js +83 -34
- package/dist/admin/editor/icons.d.ts +16 -1
- package/dist/admin/editor/icons.js +30 -1
- package/dist/admin/editor/inline.js +9 -0
- package/dist/admin/editor/insert/InsertHandle.js +4 -1
- package/dist/admin/editor/insert/picker.d.ts +3 -1
- package/dist/admin/editor/insert/picker.js +17 -10
- package/dist/admin/editor/insert/spots.d.ts +12 -1
- package/dist/admin/editor/insert/spots.js +49 -10
- package/dist/admin/editor/layout/LeftPanel.js +11 -6
- package/dist/admin/editor/live/useMultiplayer.js +9 -1
- package/dist/admin/editor/menu/blockMenu.js +27 -17
- package/dist/admin/editor/names.js +11 -3
- package/dist/admin/editor/renderField.d.ts +3 -1
- package/dist/admin/editor/renderField.js +63 -12
- package/dist/admin/editor/runtime.d.ts +14 -0
- package/dist/admin/editor/runtime.js +67 -6
- package/dist/admin/editor/sections/ComponentFields.d.ts +8 -0
- package/dist/admin/editor/sections/ComponentFields.js +116 -0
- package/dist/admin/editor/sections/PropertyControls.d.ts +18 -0
- package/dist/admin/editor/sections/PropertyControls.js +65 -0
- package/dist/admin/editor/sections/components.d.ts +29 -0
- package/dist/admin/editor/sections/components.js +112 -0
- package/dist/admin/editor/sections/components.scss +238 -0
- package/dist/admin/editor/sections/variants.d.ts +32 -0
- package/dist/admin/editor/sections/variants.js +59 -0
- package/dist/admin/editor/sections/variants.scss +90 -0
- package/dist/admin/editor/shortcuts.d.ts +4 -1
- package/dist/admin/editor/shortcuts.js +19 -3
- package/dist/admin/editor/store.d.ts +18 -0
- package/dist/admin/editor/store.js +46 -0
- package/dist/admin/editor/styles/ClassBar.d.ts +14 -0
- package/dist/admin/editor/styles/ClassBar.js +90 -0
- package/dist/admin/editor/styles/ClassCss.d.ts +4 -0
- package/dist/admin/editor/styles/ClassCss.js +28 -0
- package/dist/admin/editor/styles/ClassDialog.d.ts +2 -0
- package/dist/admin/editor/styles/ClassDialog.js +151 -0
- package/dist/admin/editor/styles/ColorPicker.js +5 -2
- package/dist/admin/editor/styles/RawClasses.d.ts +26 -1
- package/dist/admin/editor/styles/RawClasses.js +184 -32
- package/dist/admin/editor/styles/StylesPanel.d.ts +3 -3
- package/dist/admin/editor/styles/StylesPanel.js +53 -14
- package/dist/admin/editor/styles/VariantBar.js +2 -2
- package/dist/admin/editor/styles/classEdit.d.ts +4 -0
- package/dist/admin/editor/styles/classEdit.js +20 -0
- package/dist/admin/editor/styles/classes.scss +381 -0
- package/dist/admin/editor/styles/context.d.ts +19 -6
- package/dist/admin/editor/styles/context.js +24 -6
- package/dist/admin/editor/styles/controls.d.ts +3 -1
- package/dist/admin/editor/styles/controls.js +30 -12
- package/dist/admin/editor/styles/popover.d.ts +6 -0
- package/dist/admin/editor/styles/popover.js +5 -5
- package/dist/admin/editor/styles/styles.scss +26 -104
- package/dist/admin/editor/styles/suggestions.d.ts +22 -0
- package/dist/admin/editor/styles/suggestions.js +77 -0
- package/dist/admin/editor/styles/tokens.js +14 -0
- package/dist/admin/editor/templates/Bindable.js +86 -57
- package/dist/admin/editor/templates/SamplePicker.js +1 -1
- package/dist/admin/editor/templates/Visibility.d.ts +9 -0
- package/dist/admin/editor/templates/Visibility.js +54 -0
- package/dist/admin/editor/templates/binding.d.ts +2 -2
- package/dist/admin/editor/templates/binding.js +2 -2
- package/dist/admin/editor/templates/templates.scss +27 -0
- package/dist/admin/editor/templates/visibilityRows.d.ts +22 -0
- package/dist/admin/editor/templates/visibilityRows.js +83 -0
- package/dist/admin/editor/topbar/ContentModeToggle.d.ts +5 -0
- package/dist/admin/editor/topbar/ContentModeToggle.js +26 -0
- package/dist/admin/editor/topbar/DocumentActions.d.ts +1 -1
- package/dist/admin/editor/topbar/DocumentActions.js +5 -4
- package/dist/admin/editor/topbar/DocumentTitle.js +7 -2
- package/dist/admin/editor/topbar/TopBar.js +15 -3
- package/dist/admin/editor/topbar/contentMode.scss +35 -0
- package/dist/admin/editor/topbar/topbar.scss +3 -1
- package/dist/admin/formChoice.d.ts +3 -0
- package/dist/admin/formChoice.js +10 -0
- package/dist/admin/layoutField.scss +69 -0
- package/dist/admin/screen/BuilderScreen.d.ts +6 -1
- package/dist/admin/screen/BuilderScreen.js +4 -3
- package/dist/admin/server/BuilderView.js +10 -3
- package/dist/admin/templateConditions.scss +24 -0
- package/dist/ai/adapters/anthropic.js +17 -4
- package/dist/ai/adapters/cloudflare-gateway.js +7 -1
- package/dist/ai/adapters/cloudflare-workers-ai.js +2 -0
- package/dist/ai/adapters/openai-compatible.js +1 -0
- package/dist/ai/adapters/openrouter.js +2 -0
- package/dist/ai/config.d.ts +24 -4
- package/dist/ai/config.js +27 -8
- package/dist/ai/endpoint.d.ts +5 -2
- package/dist/ai/endpoint.js +31 -26
- package/dist/ai/images/cloudflare-workers-ai.js +6 -2
- package/dist/ai/images/openai.js +8 -3
- package/dist/ai/images/openrouter.js +6 -2
- package/dist/ai/images/service.d.ts +10 -4
- package/dist/ai/images/service.js +23 -7
- package/dist/ai/openai-format.d.ts +7 -0
- package/dist/ai/openai-format.js +17 -5
- package/dist/ai/prompt.d.ts +8 -0
- package/dist/ai/prompt.js +25 -5
- package/dist/ai/settings/index.d.ts +62 -0
- package/dist/ai/settings/index.js +264 -0
- package/dist/ai/settings/secret.d.ts +11 -0
- package/dist/ai/settings/secret.js +46 -0
- package/dist/ai/settings/shared.d.ts +22 -0
- package/dist/ai/settings/shared.js +3 -0
- package/dist/ai/tools.d.ts +3 -0
- package/dist/ai/tools.js +79 -15
- package/dist/ai/types.d.ts +43 -0
- package/dist/blocks/builtins/adjacentLinks.d.ts +5 -0
- package/dist/blocks/builtins/adjacentLinks.js +76 -0
- package/dist/blocks/builtins/carousel.d.ts +2 -29
- package/dist/blocks/builtins/carousel.js +44 -51
- package/dist/blocks/builtins/disclosure.d.ts +2 -1
- package/dist/blocks/builtins/disclosure.js +22 -32
- package/dist/blocks/builtins/embed.d.ts +15 -0
- package/dist/blocks/builtins/embed.js +47 -0
- package/dist/blocks/builtins/faq.d.ts +1 -1
- package/dist/blocks/builtins/faq.js +2 -2
- package/dist/blocks/builtins/filterLink.d.ts +1 -19
- package/dist/blocks/builtins/filterLink.js +9 -50
- package/dist/blocks/builtins/icon.d.ts +2 -0
- package/dist/blocks/builtins/icon.js +8 -8
- package/dist/blocks/builtins/index.d.ts +18 -13
- package/dist/blocks/builtins/index.js +43 -22
- package/dist/blocks/builtins/marquee.d.ts +5 -0
- package/dist/blocks/builtins/marquee.js +68 -0
- package/dist/blocks/builtins/popup.d.ts +5 -0
- package/dist/blocks/builtins/popup.js +83 -0
- package/dist/blocks/builtins/sectionRef.d.ts +16 -2
- package/dist/blocks/builtins/sectionRef.js +34 -12
- package/dist/blocks/builtins/shared.d.ts +18 -23
- package/dist/blocks/builtins/shared.js +34 -42
- package/dist/blocks/builtins/tableOfContents.d.ts +4 -0
- package/dist/blocks/builtins/tableOfContents.js +12 -18
- package/dist/blocks/builtins/tabs.d.ts +6 -0
- package/dist/blocks/builtins/tabs.js +87 -0
- package/dist/blocks/client/adjacentLinks.d.ts +4 -0
- package/dist/blocks/client/adjacentLinks.js +4 -0
- package/dist/blocks/client/carousel.d.ts +45 -0
- package/dist/blocks/client/carousel.js +53 -0
- package/dist/blocks/client/embed.d.ts +21 -0
- package/dist/blocks/client/embed.js +23 -0
- package/dist/blocks/client/field.d.ts +7 -0
- package/dist/blocks/client/field.js +8 -0
- package/dist/blocks/client/filterLink.d.ts +19 -0
- package/dist/blocks/client/filterLink.js +30 -0
- package/dist/blocks/client/helpers.d.ts +21 -0
- package/dist/blocks/client/helpers.js +24 -0
- package/dist/blocks/client/marquee.d.ts +14 -0
- package/dist/blocks/client/marquee.js +25 -0
- package/dist/blocks/client/menu.d.ts +46 -0
- package/dist/blocks/client/menu.js +49 -0
- package/dist/blocks/client/popup.d.ts +15 -0
- package/dist/blocks/client/popup.js +16 -0
- package/dist/blocks/client/tabs.d.ts +10 -0
- package/dist/blocks/client/tabs.js +11 -0
- package/dist/blocks/defaults.d.ts +15 -52
- package/dist/blocks/defaults.js +203 -437
- package/dist/blocks/index.d.ts +1 -1
- package/dist/blocks/index.js +2 -1
- package/dist/classes/actions.d.ts +97 -0
- package/dist/classes/actions.js +296 -0
- package/dist/classes/collection.d.ts +5 -0
- package/dist/classes/collection.js +189 -0
- package/dist/classes/config.d.ts +34 -0
- package/dist/classes/config.js +8 -0
- package/dist/classes/endpoints.d.ts +2 -0
- package/dist/classes/endpoints.js +120 -0
- package/dist/classes/index.d.ts +36 -0
- package/dist/classes/index.js +42 -0
- package/dist/classes/mcp.d.ts +6 -0
- package/dist/classes/mcp.js +161 -0
- package/dist/classes/shared.d.ts +131 -0
- package/dist/classes/shared.js +300 -0
- package/dist/classes/sheet.d.ts +34 -0
- package/dist/classes/sheet.js +126 -0
- package/dist/classes/usage.d.ts +57 -0
- package/dist/classes/usage.js +208 -0
- package/dist/comments/collection.d.ts +38 -0
- package/dist/comments/collection.js +226 -0
- package/dist/comments/config.d.ts +15 -0
- package/dist/comments/config.js +2 -0
- package/dist/comments/index.d.ts +20 -0
- package/dist/comments/index.js +22 -0
- package/dist/comments/shared.d.ts +54 -0
- package/dist/comments/shared.js +104 -0
- package/dist/core/bindings.d.ts +77 -32
- package/dist/core/bindings.js +319 -134
- package/dist/core/blockNames.d.ts +9 -0
- package/dist/core/blockNames.js +11 -0
- package/dist/core/blocks.d.ts +21 -8
- package/dist/core/blocks.js +37 -16
- package/dist/core/classes.d.ts +16 -8
- package/dist/core/classes.js +31 -27
- package/dist/core/components.d.ts +72 -0
- package/dist/core/components.js +294 -0
- package/dist/core/contentMode.d.ts +27 -0
- package/dist/core/contentMode.js +0 -0
- package/dist/core/dropTarget.d.ts +11 -0
- package/dist/core/dropTarget.js +24 -1
- package/dist/core/fields.d.ts +5 -0
- package/dist/core/fields.js +11 -0
- package/dist/core/headings.d.ts +5 -2
- package/dist/core/headings.js +14 -6
- package/dist/core/index.d.ts +8 -3
- package/dist/core/index.js +8 -3
- package/dist/core/layers.d.ts +9 -0
- package/dist/core/layers.js +29 -0
- package/dist/core/operations.d.ts +6 -0
- package/dist/core/operations.js +85 -24
- package/dist/core/payloadBlocks.js +5 -1
- package/dist/core/references.js +28 -0
- package/dist/core/schema.js +20 -6
- package/dist/core/sectionOrigin.d.ts +6 -0
- package/dist/core/sectionOrigin.js +21 -0
- package/dist/core/sections.d.ts +72 -0
- package/dist/core/sections.js +331 -0
- package/dist/core/templateChoice.d.ts +24 -0
- package/dist/core/templateChoice.js +43 -0
- package/dist/core/tree.js +18 -6
- package/dist/core/types.d.ts +148 -18
- package/dist/core/validate.d.ts +4 -1
- package/dist/core/validate.js +28 -11
- package/dist/core/visibility.d.ts +63 -0
- package/dist/core/visibility.js +214 -0
- package/dist/core/whereValues.d.ts +22 -0
- package/dist/core/whereValues.js +43 -0
- package/dist/css/classes.d.ts +16 -0
- package/dist/css/classes.js +172 -0
- package/dist/css/index.d.ts +32 -1
- package/dist/css/index.js +64 -5
- package/dist/css/tokens.d.ts +10 -0
- package/dist/css/tokens.js +23 -10
- package/dist/index.d.ts +5 -2
- package/dist/index.js +6 -1
- package/dist/live/contentMode.d.ts +24 -0
- package/dist/live/contentMode.js +39 -0
- package/dist/live/endpoints.js +3 -0
- package/dist/live/session.d.ts +5 -0
- package/dist/live/session.js +8 -0
- package/dist/live/types.d.ts +16 -1
- package/dist/mcp/index.d.ts +10 -1
- package/dist/mcp/index.js +146 -54
- package/dist/mcp/shared.d.ts +93 -3
- package/dist/mcp/shared.js +211 -15
- package/dist/plugin/hook.d.ts +7 -1
- package/dist/plugin/hook.js +30 -4
- package/dist/plugin/index.d.ts +19 -8
- package/dist/plugin/index.js +89 -20
- package/dist/plugin/links.d.ts +24 -0
- package/dist/plugin/links.js +27 -0
- package/dist/plugin/listCollections.d.ts +9 -7
- package/dist/plugin/listCollections.js +30 -21
- package/dist/plugin/sections.d.ts +14 -7
- package/dist/plugin/sections.js +69 -23
- package/dist/plugin/sectionsUsedIn.d.ts +6 -0
- package/dist/plugin/sectionsUsedIn.js +24 -0
- package/dist/plugin/templateEndpoint.d.ts +9 -0
- package/dist/plugin/templateEndpoint.js +49 -0
- package/dist/plugin/templates.js +23 -8
- package/dist/protocol/index.d.ts +16 -1
- package/dist/react/canvas/BuilderCanvas.js +144 -21
- package/dist/react/canvas/classes.d.ts +17 -0
- package/dist/react/canvas/classes.js +102 -0
- package/dist/react/canvas/controls.d.ts +31 -0
- package/dist/react/canvas/controls.js +75 -0
- package/dist/react/canvas/fetchDocs.d.ts +2 -2
- package/dist/react/canvas/fetchDocs.js +16 -8
- package/dist/react/canvas/measure.d.ts +9 -0
- package/dist/react/canvas/measure.js +106 -7
- package/dist/react/canvas/resolveLayout.d.ts +1 -1
- package/dist/react/canvas/resolveLayout.js +4 -3
- package/dist/react/canvas/thumbnail/ThumbnailCanvas.js +17 -4
- package/dist/react/classes/ClassesStyle.d.ts +27 -0
- package/dist/react/classes/ClassesStyle.js +27 -0
- package/dist/react/components/Button.d.ts +2 -11
- package/dist/react/components/Button.js +8 -43
- package/dist/react/components/CollectionList.d.ts +4 -1
- package/dist/react/components/CollectionList.js +10 -3
- package/dist/react/components/Container.d.ts +5 -2
- package/dist/react/components/Container.js +7 -4
- package/dist/react/components/Field.js +3 -14
- package/dist/react/components/Link.d.ts +1 -1
- package/dist/react/components/Link.js +5 -3
- package/dist/react/components/List.d.ts +1 -1
- package/dist/react/components/List.js +2 -2
- package/dist/react/components/Menu.d.ts +10 -1
- package/dist/react/components/Menu.js +39 -12
- package/dist/react/components/RichText.d.ts +3 -4
- package/dist/react/components/RichText.js +5 -5
- package/dist/react/components/builtins/Accordion.d.ts +4 -3
- package/dist/react/components/builtins/Accordion.js +6 -5
- package/dist/react/components/builtins/AdjacentLinks.d.ts +11 -0
- package/dist/react/components/builtins/AdjacentLinks.js +20 -0
- package/dist/react/components/builtins/Carousel.d.ts +21 -10
- package/dist/react/components/builtins/Carousel.js +175 -100
- package/dist/react/components/builtins/Disclosure.d.ts +4 -3
- package/dist/react/components/builtins/Disclosure.js +6 -5
- package/dist/react/components/builtins/Embed.d.ts +11 -0
- package/dist/react/components/builtins/Embed.js +23 -0
- package/dist/react/components/builtins/EmbedHtml.d.ts +15 -0
- package/dist/react/components/builtins/EmbedHtml.js +51 -0
- package/dist/react/components/builtins/EmbedPreview.d.ts +34 -0
- package/dist/react/components/builtins/EmbedPreview.js +105 -0
- package/dist/react/components/builtins/FilterLink.d.ts +1 -1
- package/dist/react/components/builtins/FilterLink.js +4 -4
- package/dist/react/components/builtins/Marquee.d.ts +8 -0
- package/dist/react/components/builtins/Marquee.js +15 -0
- package/dist/react/components/builtins/Popup.d.ts +26 -0
- package/dist/react/components/builtins/Popup.js +146 -0
- package/dist/react/components/builtins/SectionRef.d.ts +4 -3
- package/dist/react/components/builtins/SectionRef.js +9 -5
- package/dist/react/components/builtins/Tab.d.ts +7 -0
- package/dist/react/components/builtins/Tab.js +21 -0
- package/dist/react/components/builtins/TableOfContents.d.ts +17 -3
- package/dist/react/components/builtins/TableOfContents.js +22 -7
- package/dist/react/components/builtins/Tabs.d.ts +17 -0
- package/dist/react/components/builtins/Tabs.js +71 -0
- package/dist/react/components/builtins/index.d.ts +37 -20
- package/dist/react/components/builtins/index.js +54 -20
- package/dist/react/components/builtins/tabsContext.d.ts +12 -0
- package/dist/react/components/builtins/tabsContext.js +6 -0
- package/dist/react/components/index.js +11 -8
- package/dist/react/components/lazy.d.ts +32 -0
- package/dist/react/components/lazy.js +20 -0
- package/dist/react/components/lazyBlock.d.ts +17 -0
- package/dist/react/components/lazyBlock.js +23 -0
- package/dist/react/index.d.ts +6 -3
- package/dist/react/index.js +5 -2
- package/dist/react/render/RenderLayout.d.ts +9 -7
- package/dist/react/render/RenderLayout.js +96 -45
- package/dist/react/render/canvasMode.d.ts +13 -0
- package/dist/react/render/canvasMode.js +13 -0
- package/dist/react/render/canvasServer.js +4 -3
- package/dist/react/render/canvasServerTypes.d.ts +5 -0
- package/dist/react/render/lists.d.ts +36 -4
- package/dist/react/render/lists.js +132 -15
- package/dist/react/render/marks.d.ts +15 -0
- package/dist/react/render/marks.js +23 -0
- package/dist/react/render/payload.d.ts +8 -1
- package/dist/react/render/payload.js +12 -3
- package/dist/react/render/preview.d.ts +11 -0
- package/dist/react/render/preview.js +13 -0
- package/dist/react/render/relations.d.ts +10 -0
- package/dist/react/render/relations.js +39 -0
- package/dist/react/render/resolve.d.ts +8 -4
- package/dist/react/render/resolve.js +11 -5
- package/dist/react/render/reveal.d.ts +17 -0
- package/dist/react/render/reveal.js +39 -0
- package/dist/react/render/sections.d.ts +11 -5
- package/dist/react/render/sections.js +52 -24
- package/dist/react/render/templates.d.ts +47 -0
- package/dist/react/render/templates.js +139 -0
- package/dist/react/render/types.d.ts +62 -5
- package/dist/react/server.d.ts +2 -37
- package/dist/react/server.js +8 -133
- package/dist/react/theme/ThemeLiveLoader.d.ts +4 -0
- package/dist/react/theme/ThemeLiveLoader.js +5 -0
- package/dist/react/theme/ThemeStyle.js +1 -1
- package/dist/theme/admin/Variables.d.ts +11 -0
- package/dist/theme/admin/Variables.js +115 -0
- package/dist/theme/admin/fields.scss +113 -0
- package/dist/theme/client.d.ts +1 -0
- package/dist/theme/client.js +2 -0
- package/dist/theme/css.d.ts +6 -1
- package/dist/theme/css.js +12 -4
- package/dist/theme/global.js +83 -0
- package/dist/theme/index.d.ts +1 -0
- package/dist/theme/index.js +1 -0
- package/dist/theme/server.d.ts +15 -0
- package/dist/theme/server.js +43 -0
- package/dist/theme/usage.d.ts +23 -0
- package/dist/theme/usage.js +68 -0
- package/dist/theme/variables.d.ts +72 -0
- package/dist/theme/variables.js +231 -0
- package/package.json +4 -2
- package/dist/admin/editor/styles/SiteClasses.d.ts +0 -9
- package/dist/admin/editor/styles/SiteClasses.js +0 -31
- package/dist/blocks/builtins/headingId.d.ts +0 -15
- package/dist/blocks/builtins/headingId.js +0 -36
- package/dist/blocks/builtins/lightbox.d.ts +0 -43
- package/dist/blocks/builtins/lightbox.js +0 -93
- package/dist/blocks/builtins/mediaBackdrop.d.ts +0 -11
- package/dist/blocks/builtins/mediaBackdrop.js +0 -79
- package/dist/react/components/Quote.d.ts +0 -3
- package/dist/react/components/Quote.js +0 -12
- package/dist/react/components/Spacer.d.ts +0 -3
- package/dist/react/components/Spacer.js +0 -6
- package/dist/react/components/builtins/BackdropVideo.d.ts +0 -13
- package/dist/react/components/builtins/BackdropVideo.js +0 -16
- package/dist/react/components/builtins/Lightbox.d.ts +0 -45
- package/dist/react/components/builtins/Lightbox.js +0 -252
- package/dist/react/components/builtins/MediaBackdrop.d.ts +0 -14
- package/dist/react/components/builtins/MediaBackdrop.js +0 -61
|
@@ -59,11 +59,30 @@ export declare function pageWindow(current: number, totalPages: number): number[
|
|
|
59
59
|
* `searchParams` object of a Next.js page.
|
|
60
60
|
*/
|
|
61
61
|
export type ListQueryParams = URLSearchParams | Record<string, string | string[] | undefined>;
|
|
62
|
+
/**
|
|
63
|
+
* The `queryFilters` of a list for the URL query. Each param has one of two forms:
|
|
64
|
+
* - a field path (`{ category: "category" }`): the field equals the URL value (`?category=news`);
|
|
65
|
+
* - values to `Where` queries (`{ sort: { recent: Where, popular: Where } }`): each present
|
|
66
|
+
* `param=value` adds its `Where`; unknown values are ignored.
|
|
67
|
+
* Values of one param are OR-ed, params are AND-ed.
|
|
68
|
+
*/
|
|
69
|
+
export declare function queryFiltersOf(filters: unknown, query: ListQueryParams | null | undefined): Where[];
|
|
62
70
|
/**
|
|
63
71
|
* Date tokens in where values: `$now`, `$now-30d`, `$now+12h` become ISO dates. `now` is rounded
|
|
64
72
|
* down to the minute, so the canvas cache keeps one key per minute.
|
|
65
73
|
*/
|
|
66
74
|
export declare function withDateTokens<T>(value: T, now?: number): T;
|
|
75
|
+
/** What the `$page.` and `$query.` values of a where read. */
|
|
76
|
+
type WhereTokenSources = {
|
|
77
|
+
context?: TemplateContext | null;
|
|
78
|
+
query?: ListQueryParams | null;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* A where with its `$page.<path>` and `$query.<param>` values read (`core/whereValues.ts`).
|
|
82
|
+
* `none`: it matches nothing. `undefined`: nothing is left to filter by. In an `or`, a part with
|
|
83
|
+
* nothing left does not apply and is left out. Other values and keys stay as they are.
|
|
84
|
+
*/
|
|
85
|
+
export declare function resolveWhereTokens(where: Where, sources: WhereTokenSources): Where | 'none' | undefined;
|
|
67
86
|
/** How `filterField` relates the listed documents to the current document. */
|
|
68
87
|
export type ListFilterBy = 'current' | 'shared' | 'linked';
|
|
69
88
|
type Id = string | number;
|
|
@@ -87,12 +106,21 @@ export declare function listRequest(query: ListQuery): {
|
|
|
87
106
|
* `$random` (the seed and the block id pick the order), else after `offset`, at most `limit`.
|
|
88
107
|
*/
|
|
89
108
|
export declare function arrangeListDocs(docs: Doc[], query: ListQuery, seed?: number): Doc[];
|
|
109
|
+
export type ListQueriesOptions = {
|
|
110
|
+
/**
|
|
111
|
+
* Also query lists in hidden blocks (hidden by hand or by visibility conditions). The canvas
|
|
112
|
+
* does: it shows hidden blocks dimmed. The site does not, so hidden lists cost no query.
|
|
113
|
+
*/
|
|
114
|
+
includeHidden?: boolean;
|
|
115
|
+
};
|
|
90
116
|
/**
|
|
91
|
-
* The query of every collection list block in the layout (also inside other lists' items)
|
|
92
|
-
* `filterField` needs the current document (`context`);
|
|
93
|
-
* `queryFilters` need the URL query (`query`); without one
|
|
117
|
+
* The query of every collection list block in the layout (also inside other lists' items), except
|
|
118
|
+
* in hidden blocks (see `includeHidden`). `filterField` needs the current document (`context`);
|
|
119
|
+
* without one the list shows nothing. `queryFilters` need the URL query (`query`); without one
|
|
120
|
+
* they are off (the canvas). In `where`, `$page.<path>` values read `context` and `$query.<param>`
|
|
121
|
+
* values read `query` (`resolveWhereTokens`), then date tokens become dates.
|
|
94
122
|
*/
|
|
95
|
-
export declare function listQueries(layout: Layout, context?: TemplateContext | null, query?: ListQueryParams | null): ListQuery[];
|
|
123
|
+
export declare function listQueries(layout: Layout, context?: TemplateContext | null, query?: ListQueryParams | null, options?: ListQueriesOptions): ListQuery[];
|
|
96
124
|
/**
|
|
97
125
|
* Puts the loaded documents on each list block as the runtime-only `$items` prop, and a paginated
|
|
98
126
|
* list's page links as `$pages` (`pages`). Never mutates.
|
|
@@ -102,6 +130,10 @@ export declare function attachListItems(layout: Layout, items: ReadonlyMap<strin
|
|
|
102
130
|
* Gives every filter link the page parameters of the layout's paginated lists that do not use
|
|
103
131
|
* `page` (`$pageParams`), so a new filter starts those lists at page 1 too. `page` is always
|
|
104
132
|
* dropped. Returns the same layout when no list has its own parameter.
|
|
133
|
+
*
|
|
134
|
+
* It names the built-in filter link on purpose: the block contract has no hook for "data a block
|
|
135
|
+
* needs from the whole layout", and one built-in user does not justify adding one. A custom block
|
|
136
|
+
* that needs the parameters can read `listQueries(layout)` itself.
|
|
105
137
|
*/
|
|
106
138
|
export declare function withPageParams(layout: Layout, queries: readonly ListQuery[]): Layout;
|
|
107
139
|
/** One collection list of a loaded layout (`loadedLists`). */
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// Shared by `loadLayoutData` (Local API) and the canvas (REST).
|
|
3
3
|
import { COLLECTION_LIST_BLOCK, getByPath, LIST_ITEMS_PROP, PAGE_PARAM, walkBlocks, } from '../../core/index.js';
|
|
4
4
|
import { FILTER_LINK_BLOCK } from '../../blocks/builtins/filterLink.js';
|
|
5
|
+
import { DATE_TOKEN, pageTokenPath, queryTokenParam } from '../../core/whereValues.js';
|
|
5
6
|
import { isRecord } from './fields.js';
|
|
6
7
|
/** The runtime prop that carries a paginated list's page links (`ListPages`). Never stored. */
|
|
7
8
|
export const LIST_PAGES_PROP = '$pages';
|
|
@@ -37,18 +38,29 @@ function paramValues(query, param) {
|
|
|
37
38
|
return raw.flatMap((value) => value.split(',')).map((value) => value.trim()).filter(Boolean);
|
|
38
39
|
}
|
|
39
40
|
/**
|
|
40
|
-
* The `queryFilters` of a list for the URL query
|
|
41
|
-
*
|
|
42
|
-
*
|
|
41
|
+
* The `queryFilters` of a list for the URL query. Each param has one of two forms:
|
|
42
|
+
* - a field path (`{ category: "category" }`): the field equals the URL value (`?category=news`);
|
|
43
|
+
* - values to `Where` queries (`{ sort: { recent: Where, popular: Where } }`): each present
|
|
44
|
+
* `param=value` adds its `Where`; unknown values are ignored.
|
|
45
|
+
* Values of one param are OR-ed, params are AND-ed.
|
|
43
46
|
*/
|
|
44
|
-
function queryFiltersOf(filters, query) {
|
|
47
|
+
export function queryFiltersOf(filters, query) {
|
|
45
48
|
if (!query || !isRecord(filters))
|
|
46
49
|
return [];
|
|
47
50
|
const out = [];
|
|
48
51
|
for (const [param, byValue] of Object.entries(filters)) {
|
|
52
|
+
const values = paramValues(query, param);
|
|
53
|
+
if (values.length === 0)
|
|
54
|
+
continue;
|
|
55
|
+
if (typeof byValue === 'string') {
|
|
56
|
+
const field = byValue.trim();
|
|
57
|
+
if (field)
|
|
58
|
+
out.push({ [field]: values.length === 1 ? { equals: values[0] } : { in: values } });
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
49
61
|
if (!isRecord(byValue))
|
|
50
62
|
continue;
|
|
51
|
-
const matched =
|
|
63
|
+
const matched = values
|
|
52
64
|
.map((value) => (Object.hasOwn(byValue, value) ? byValue[value] : undefined))
|
|
53
65
|
.filter((where) => isRecord(where) && Object.keys(where).length > 0);
|
|
54
66
|
if (matched.length > 0)
|
|
@@ -56,7 +68,6 @@ function queryFiltersOf(filters, query) {
|
|
|
56
68
|
}
|
|
57
69
|
return out;
|
|
58
70
|
}
|
|
59
|
-
const DATE_TOKEN = /^\$now(?:([+-])(\d+)([dh]))?$/;
|
|
60
71
|
const UNIT_MS = { d: 86_400_000, h: 3_600_000 };
|
|
61
72
|
/**
|
|
62
73
|
* Date tokens in where values: `$now`, `$now-30d`, `$now+12h` become ISO dates. `now` is rounded
|
|
@@ -81,6 +92,98 @@ export function withDateTokens(value, now = Date.now()) {
|
|
|
81
92
|
};
|
|
82
93
|
return visit(value);
|
|
83
94
|
}
|
|
95
|
+
/** The plain values of a page field: list items, document ids and plain values. No empty values. */
|
|
96
|
+
function tokenValues(value) {
|
|
97
|
+
if (Array.isArray(value))
|
|
98
|
+
return value.flatMap(tokenValues);
|
|
99
|
+
if (isRecord(value) && 'relationTo' in value && 'value' in value)
|
|
100
|
+
return tokenValues(value.value);
|
|
101
|
+
if (isRecord(value))
|
|
102
|
+
return isId(value.id) ? [value.id] : [];
|
|
103
|
+
if (typeof value === 'boolean' || isId(value))
|
|
104
|
+
return [value];
|
|
105
|
+
return [];
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* One operator of a condition with its `$page.` or `$query.` value read. Several values turn
|
|
109
|
+
* `equals` into `in` and `not_equals` into `not_in`. No value: a URL value drops the condition
|
|
110
|
+
* (as URL filters do); a page field matches nothing, except `not_equals` and `not_in`, which drop.
|
|
111
|
+
*/
|
|
112
|
+
function readToken(operator, value, sources) {
|
|
113
|
+
const path = pageTokenPath(value);
|
|
114
|
+
const param = queryTokenParam(value);
|
|
115
|
+
if (path === null && param === null)
|
|
116
|
+
return { operator, value };
|
|
117
|
+
let values;
|
|
118
|
+
if (path !== null) {
|
|
119
|
+
const context = sources.context;
|
|
120
|
+
values = context && path ? tokenValues(getByPath(context.page ?? context.doc, path)) : [];
|
|
121
|
+
if (values.length === 0)
|
|
122
|
+
return operator === 'not_equals' || operator === 'not_in' ? 'drop' : 'none';
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
values = sources.query && param ? paramValues(sources.query, param) : [];
|
|
126
|
+
if (values.length === 0)
|
|
127
|
+
return 'drop';
|
|
128
|
+
}
|
|
129
|
+
if (operator === 'in' || operator === 'not_in')
|
|
130
|
+
return { operator, value: values };
|
|
131
|
+
if (values.length > 1 && operator === 'equals')
|
|
132
|
+
return { operator: 'in', value: values };
|
|
133
|
+
if (values.length > 1 && operator === 'not_equals')
|
|
134
|
+
return { operator: 'not_in', value: values };
|
|
135
|
+
return { operator, value: values[0] };
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* A where with its `$page.<path>` and `$query.<param>` values read (`core/whereValues.ts`).
|
|
139
|
+
* `none`: it matches nothing. `undefined`: nothing is left to filter by. In an `or`, a part with
|
|
140
|
+
* nothing left does not apply and is left out. Other values and keys stay as they are.
|
|
141
|
+
*/
|
|
142
|
+
export function resolveWhereTokens(where, sources) {
|
|
143
|
+
const out = {};
|
|
144
|
+
const extra = [];
|
|
145
|
+
for (const [key, inner] of Object.entries(where)) {
|
|
146
|
+
if ((key === 'and' || key === 'or') && Array.isArray(inner)) {
|
|
147
|
+
const parts = inner.map((part) => (isRecord(part) ? resolveWhereTokens(part, sources) : part));
|
|
148
|
+
if (key === 'and') {
|
|
149
|
+
if (parts.includes('none'))
|
|
150
|
+
return 'none';
|
|
151
|
+
const kept = parts.filter((part) => part !== undefined);
|
|
152
|
+
if (kept.length > 0)
|
|
153
|
+
out.and = kept;
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
const kept = parts.filter((part) => part !== undefined && part !== 'none');
|
|
157
|
+
if (kept.length > 0)
|
|
158
|
+
out.or = kept;
|
|
159
|
+
else if (parts.includes('none'))
|
|
160
|
+
return 'none';
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
if (!isRecord(inner)) {
|
|
164
|
+
out[key] = inner;
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
const condition = {};
|
|
168
|
+
for (const [operator, value] of Object.entries(inner)) {
|
|
169
|
+
const read = readToken(operator, value, sources);
|
|
170
|
+
if (read === 'none')
|
|
171
|
+
return 'none';
|
|
172
|
+
if (read === 'drop')
|
|
173
|
+
continue;
|
|
174
|
+
// `equals` became `in`, and the condition has an `in` already: AND the two.
|
|
175
|
+
if (read.operator in condition)
|
|
176
|
+
extra.push({ [key]: { [read.operator]: read.value } });
|
|
177
|
+
else
|
|
178
|
+
condition[read.operator] = read.value;
|
|
179
|
+
}
|
|
180
|
+
if (Object.keys(condition).length > 0)
|
|
181
|
+
out[key] = condition;
|
|
182
|
+
}
|
|
183
|
+
if (extra.length > 0)
|
|
184
|
+
out.and = [...(Array.isArray(out.and) ? out.and : []), ...extra];
|
|
185
|
+
return Object.keys(out).length > 0 ? out : undefined;
|
|
186
|
+
}
|
|
84
187
|
const isId = (value) => (typeof value === 'string' && value !== '') || (typeof value === 'number' && Number.isFinite(value));
|
|
85
188
|
/** The ids or values in a field value: populated documents, `{ relationTo, value }` pairs, primitives, single or many. */
|
|
86
189
|
function valuesOf(value) {
|
|
@@ -95,15 +198,18 @@ function valuesOf(value) {
|
|
|
95
198
|
}
|
|
96
199
|
/**
|
|
97
200
|
* The `filterField` filter of a list on the current document's page, or `none` when it matches
|
|
98
|
-
* nothing
|
|
201
|
+
* nothing: without a current document (a normal page, or a template without a sample document on
|
|
202
|
+
* the canvas) or when the current document has no values. Undefined without a filter.
|
|
99
203
|
*/
|
|
100
204
|
function filterOf(props, context) {
|
|
101
205
|
const field = typeof props.filterField === 'string' ? props.filterField.trim() : '';
|
|
102
|
-
if (!field
|
|
206
|
+
if (!field)
|
|
103
207
|
return undefined;
|
|
208
|
+
if (!context)
|
|
209
|
+
return 'none';
|
|
104
210
|
const by = props.filterBy === 'shared' || props.filterBy === 'linked' ? props.filterBy : 'current';
|
|
105
211
|
if (by === 'current')
|
|
106
|
-
return isId(context.doc.id) ? { [field]: { in: [context.doc.id] } } :
|
|
212
|
+
return isId(context.doc.id) ? { [field]: { in: [context.doc.id] } } : 'none';
|
|
107
213
|
const values = valuesOf(getByPath(context.doc, field));
|
|
108
214
|
if (values.length === 0)
|
|
109
215
|
return 'none';
|
|
@@ -213,13 +319,17 @@ const MAX_LIMIT = 100;
|
|
|
213
319
|
const MAX_OFFSET = 100;
|
|
214
320
|
const DEFAULT_SORT = '-createdAt';
|
|
215
321
|
/**
|
|
216
|
-
* The query of every collection list block in the layout (also inside other lists' items)
|
|
217
|
-
* `filterField` needs the current document (`context`);
|
|
218
|
-
* `queryFilters` need the URL query (`query`); without one
|
|
322
|
+
* The query of every collection list block in the layout (also inside other lists' items), except
|
|
323
|
+
* in hidden blocks (see `includeHidden`). `filterField` needs the current document (`context`);
|
|
324
|
+
* without one the list shows nothing. `queryFilters` need the URL query (`query`); without one
|
|
325
|
+
* they are off (the canvas). In `where`, `$page.<path>` values read `context` and `$query.<param>`
|
|
326
|
+
* values read `query` (`resolveWhereTokens`), then date tokens become dates.
|
|
219
327
|
*/
|
|
220
|
-
export function listQueries(layout, context, query) {
|
|
328
|
+
export function listQueries(layout, context, query, options = {}) {
|
|
221
329
|
const queries = [];
|
|
222
330
|
walkBlocks(layout, (block) => {
|
|
331
|
+
if (block.hidden && !options.includeHidden)
|
|
332
|
+
return false;
|
|
223
333
|
if (block.type !== COLLECTION_LIST_BLOCK)
|
|
224
334
|
return;
|
|
225
335
|
const props = block.props ?? {};
|
|
@@ -253,8 +363,11 @@ export function listQueries(layout, context, query) {
|
|
|
253
363
|
if (filter === 'none')
|
|
254
364
|
list.none = true;
|
|
255
365
|
const where = [filter, props.where, ...queryFiltersOf(props.queryFilters, query)].filter((w) => isRecord(w) && Object.keys(w).length > 0);
|
|
256
|
-
|
|
257
|
-
|
|
366
|
+
const resolved = !list.none && where.length > 0 ? resolveWhereTokens(where.length === 1 ? where[0] : { and: where }, { context, query }) : undefined;
|
|
367
|
+
if (resolved === 'none')
|
|
368
|
+
list.none = true;
|
|
369
|
+
else if (resolved)
|
|
370
|
+
list.where = withDateTokens(resolved);
|
|
258
371
|
queries.push(list);
|
|
259
372
|
});
|
|
260
373
|
return queries;
|
|
@@ -285,6 +398,10 @@ export function attachListItems(layout, items, pages) {
|
|
|
285
398
|
* Gives every filter link the page parameters of the layout's paginated lists that do not use
|
|
286
399
|
* `page` (`$pageParams`), so a new filter starts those lists at page 1 too. `page` is always
|
|
287
400
|
* dropped. Returns the same layout when no list has its own parameter.
|
|
401
|
+
*
|
|
402
|
+
* It names the built-in filter link on purpose: the block contract has no hook for "data a block
|
|
403
|
+
* needs from the whole layout", and one built-in user does not justify adding one. A custom block
|
|
404
|
+
* that needs the parameters can read `listQueries(layout)` itself.
|
|
288
405
|
*/
|
|
289
406
|
export function withPageParams(layout, queries) {
|
|
290
407
|
const params = [...new Set(queries.flatMap((query) => (query.pageParam ? [query.pageParam] : [])))];
|
|
@@ -8,6 +8,21 @@ import type { BlockComponentProps } from './types.js';
|
|
|
8
8
|
*/
|
|
9
9
|
export declare function withPageData<C extends ComponentType<BlockComponentProps>>(component: C): C;
|
|
10
10
|
export declare const readsPageData: (component: unknown) => boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Marks a block component that renders links with the site's link component
|
|
13
|
+
* (`BlockComponentProps.linkComponent`, the `linkComponent` of `RenderLayout`, for example
|
|
14
|
+
* `next/link`). Other components never get it. The built-in button, link and menu are marked.
|
|
15
|
+
*/
|
|
16
|
+
export declare function withLinkComponent<C extends ComponentType<BlockComponentProps>>(component: C): C;
|
|
17
|
+
export declare const readsLinkComponent: (component: unknown) => boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Marks a client block component that renders links. A function cannot pass from the server to a
|
|
20
|
+
* client component (and Next's server `next/link` is a function), so it gets
|
|
21
|
+
* `BlockComponentProps.clientLinks: true` instead when the site sets `linkComponent`, and renders
|
|
22
|
+
* `next/link` itself. The built-in menu is marked.
|
|
23
|
+
*/
|
|
24
|
+
export declare function withClientLinks<C extends ComponentType<BlockComponentProps>>(component: C): C;
|
|
25
|
+
export declare const readsClientLinks: (component: unknown) => boolean;
|
|
11
26
|
/** Marks a block component that must render on the server in the canvas, even if the canvas can import it. */
|
|
12
27
|
export declare function renderOnServer<C extends ComponentType<BlockComponentProps>>(component: C): C;
|
|
13
28
|
/** An async function component (a server component that loads data). */
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// so a client reference (a 'use client' component seen from the server) is safe to test.
|
|
3
3
|
const pageDataComponents = new WeakSet();
|
|
4
4
|
const serverComponents = new WeakSet();
|
|
5
|
+
const linkComponents = new WeakSet();
|
|
5
6
|
/**
|
|
6
7
|
* Marks a block component that reads the page data (`BlockComponentProps.pageData`, the
|
|
7
8
|
* `pageData` of `RenderLayout` and of the canvas). Other components never get it, so a client
|
|
@@ -13,6 +14,28 @@ export function withPageData(component) {
|
|
|
13
14
|
return component;
|
|
14
15
|
}
|
|
15
16
|
export const readsPageData = (component) => typeof component === 'function' && pageDataComponents.has(component);
|
|
17
|
+
/**
|
|
18
|
+
* Marks a block component that renders links with the site's link component
|
|
19
|
+
* (`BlockComponentProps.linkComponent`, the `linkComponent` of `RenderLayout`, for example
|
|
20
|
+
* `next/link`). Other components never get it. The built-in button, link and menu are marked.
|
|
21
|
+
*/
|
|
22
|
+
export function withLinkComponent(component) {
|
|
23
|
+
linkComponents.add(component);
|
|
24
|
+
return component;
|
|
25
|
+
}
|
|
26
|
+
export const readsLinkComponent = (component) => typeof component === 'function' && linkComponents.has(component);
|
|
27
|
+
const clientLinkComponents = new WeakSet();
|
|
28
|
+
/**
|
|
29
|
+
* Marks a client block component that renders links. A function cannot pass from the server to a
|
|
30
|
+
* client component (and Next's server `next/link` is a function), so it gets
|
|
31
|
+
* `BlockComponentProps.clientLinks: true` instead when the site sets `linkComponent`, and renders
|
|
32
|
+
* `next/link` itself. The built-in menu is marked.
|
|
33
|
+
*/
|
|
34
|
+
export function withClientLinks(component) {
|
|
35
|
+
clientLinkComponents.add(component);
|
|
36
|
+
return component;
|
|
37
|
+
}
|
|
38
|
+
export const readsClientLinks = (component) => typeof component === 'function' && clientLinkComponents.has(component);
|
|
16
39
|
/** Marks a block component that must render on the server in the canvas, even if the canvas can import it. */
|
|
17
40
|
export function renderOnServer(component) {
|
|
18
41
|
serverComponents.add(component);
|
|
@@ -4,13 +4,20 @@ import type { BlockComponentProps, BlockComponents, PageData, RenderMode } from
|
|
|
4
4
|
/** What the builder adds to a Payload-shaped component's props, under `builder`. */
|
|
5
5
|
export type PayloadBuilderProps = {
|
|
6
6
|
mode: RenderMode;
|
|
7
|
+
/** Server renders for the editor only: `'canvas'` or `'thumbnail'` (see `BlockComponentProps`). */
|
|
8
|
+
canvasMode?: 'canvas' | 'thumbnail';
|
|
7
9
|
/** The block's Tailwind classes (only for blocks with `styles: true`). */
|
|
8
10
|
className?: string;
|
|
9
11
|
/** The editor attributes for the root element. The adapter applies them itself. */
|
|
10
12
|
attributes: Record<string, string>;
|
|
11
13
|
/** Each slot rendered by the builder: every child carries its editor attributes. */
|
|
12
14
|
slots: Record<string, ReactNode>;
|
|
13
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* By slot or part name. Spread a slot's entry on the element that holds the slot's children, so
|
|
17
|
+
* the canvas can drop into it. A styled slot's or part's entry also carries its `className`.
|
|
18
|
+
*/
|
|
19
|
+
partAttributes: Record<string, Record<string, string>>;
|
|
20
|
+
/** @deprecated The same object as `partAttributes` (its name before 0.4). */
|
|
14
21
|
slotAttributes: Record<string, Record<string, string>>;
|
|
15
22
|
};
|
|
16
23
|
/**
|
|
@@ -25,13 +25,21 @@ const EMPTY_PAGE_DATA = Object.freeze({});
|
|
|
25
25
|
export function fromPayloadComponent(Component, options = {}) {
|
|
26
26
|
const blocks = options.blocks ?? [];
|
|
27
27
|
const mapProps = options.props;
|
|
28
|
-
function PayloadBlock({ block, props, className, slots, attributes,
|
|
28
|
+
function PayloadBlock({ block, props, className, slots, attributes, partAttributes, mode, pageData, canvasMode }) {
|
|
29
29
|
const def = getBlockDefinition(blocks, block.type);
|
|
30
30
|
const data = { ...withFieldDefaults(props, def?.fields ?? []) };
|
|
31
31
|
for (const name of new Set([...Object.keys(def?.slots ?? {}), ...Object.keys(slots)])) {
|
|
32
32
|
data[name] = (block.slots?.[name] ?? []).filter((child) => !child.hidden).map((child) => toPayloadBlock(child, blocks));
|
|
33
33
|
}
|
|
34
|
-
const builder = {
|
|
34
|
+
const builder = {
|
|
35
|
+
mode,
|
|
36
|
+
attributes,
|
|
37
|
+
slots,
|
|
38
|
+
partAttributes,
|
|
39
|
+
slotAttributes: partAttributes,
|
|
40
|
+
...(className ? { className } : {}),
|
|
41
|
+
...(canvasMode ? { canvasMode } : {}),
|
|
42
|
+
};
|
|
35
43
|
const payloadBlock = {
|
|
36
44
|
...data,
|
|
37
45
|
id: block.id,
|
|
@@ -87,5 +95,6 @@ export function fromPayloadComponents(components, blocks, options = {}) {
|
|
|
87
95
|
export function PayloadSlot({ builder, name, as: As = 'div', className, children }) {
|
|
88
96
|
if (!builder)
|
|
89
97
|
return children ?? null;
|
|
90
|
-
|
|
98
|
+
const { className: own, ...attributes } = builder.partAttributes[name] ?? {};
|
|
99
|
+
return (_jsx(As, { className: [className, own].filter(Boolean).join(' ') || undefined, ...attributes, children: builder.slots[name] }));
|
|
91
100
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { Block } from '../../core/index.js';
|
|
3
|
+
import { type PreviewBlockOptions } from './RenderLayout.js';
|
|
4
|
+
export type { PreviewBlockOptions };
|
|
5
|
+
/**
|
|
6
|
+
* Server preview for the canvas (`createCanvasServer`): renders one block (its data already
|
|
7
|
+
* loaded) as the canvas would, with the given components. It gets no editor attributes, and each
|
|
8
|
+
* slot is a `SlotOutlet`: the canvas fills it with the children it renders itself, so they stay
|
|
9
|
+
* editable. Its slot containers get the editor's slot attributes, as on the canvas.
|
|
10
|
+
*/
|
|
11
|
+
export declare function renderPreviewBlock(block: Block, options?: PreviewBlockOptions): ReactNode;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { renderBlockPreview } from './RenderLayout.js';
|
|
3
|
+
import { SlotOutlet } from './SlotOutlet.js';
|
|
4
|
+
const outlet = (slot) => _jsx(SlotOutlet, { name: slot });
|
|
5
|
+
/**
|
|
6
|
+
* Server preview for the canvas (`createCanvasServer`): renders one block (its data already
|
|
7
|
+
* loaded) as the canvas would, with the given components. It gets no editor attributes, and each
|
|
8
|
+
* slot is a `SlotOutlet`: the canvas fills it with the children it renders itself, so they stay
|
|
9
|
+
* editable. Its slot containers get the editor's slot attributes, as on the canvas.
|
|
10
|
+
*/
|
|
11
|
+
export function renderPreviewBlock(block, options = {}) {
|
|
12
|
+
return renderBlockPreview(block, options, outlet);
|
|
13
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Payload } from 'payload';
|
|
2
|
+
import { type BindingRelations, type Layout } from '../../core/index.js';
|
|
3
|
+
/** Runtime-only prop of collection lists and repeats: the `bindingRelations` their items use. Never stored. */
|
|
4
|
+
export declare const RELATIONS_PROP = "$relations";
|
|
5
|
+
/** The `bindingRelations` of the Payload config's collections, computed once per config. */
|
|
6
|
+
export declare function relationsOf(payload: Payload): BindingRelations;
|
|
7
|
+
/** Puts `relations` on every collection list and repeat (`$relations`). Same layout when there are none. Never mutates. */
|
|
8
|
+
export declare function withRelations(layout: Layout, relations: BindingRelations): Layout;
|
|
9
|
+
/** The `$relations` a list block carries, if any. */
|
|
10
|
+
export declare function relationsIn(props: Record<string, unknown> | undefined): BindingRelations | undefined;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// `<path>.$url` bindings need to know which collection a relationship field points to
|
|
2
|
+
// (`bindingRelations`). `loadLayoutData` reads that from the Payload config and puts it on every
|
|
3
|
+
// collection list and repeat as the runtime-only `$relations` prop, because their items resolve
|
|
4
|
+
// their bindings later, in `RenderLayout`. So a site passes it nowhere.
|
|
5
|
+
import { bindingRelations, COLLECTION_LIST_BLOCK, REPEAT_BLOCK } from '../../core/index.js';
|
|
6
|
+
import { isRecord } from './fields.js';
|
|
7
|
+
/** Runtime-only prop of collection lists and repeats: the `bindingRelations` their items use. Never stored. */
|
|
8
|
+
export const RELATIONS_PROP = '$relations';
|
|
9
|
+
const byConfig = new WeakMap();
|
|
10
|
+
/** The `bindingRelations` of the Payload config's collections, computed once per config. */
|
|
11
|
+
export function relationsOf(payload) {
|
|
12
|
+
const config = payload.config;
|
|
13
|
+
if (!config)
|
|
14
|
+
return {};
|
|
15
|
+
let relations = byConfig.get(config);
|
|
16
|
+
if (!relations) {
|
|
17
|
+
relations = bindingRelations(config.collections ?? []);
|
|
18
|
+
byConfig.set(config, relations);
|
|
19
|
+
}
|
|
20
|
+
return relations;
|
|
21
|
+
}
|
|
22
|
+
/** Puts `relations` on every collection list and repeat (`$relations`). Same layout when there are none. Never mutates. */
|
|
23
|
+
export function withRelations(layout, relations) {
|
|
24
|
+
if (Object.keys(relations).length === 0)
|
|
25
|
+
return layout;
|
|
26
|
+
const visit = (blocks) => blocks.map((block) => {
|
|
27
|
+
const repeats = block.type === COLLECTION_LIST_BLOCK || block.type === REPEAT_BLOCK;
|
|
28
|
+
const next = repeats ? { ...block, props: { ...block.props, [RELATIONS_PROP]: relations } } : block;
|
|
29
|
+
if (!next.slots)
|
|
30
|
+
return next;
|
|
31
|
+
return { ...next, slots: Object.fromEntries(Object.entries(next.slots).map(([name, children]) => [name, visit(children)])) };
|
|
32
|
+
});
|
|
33
|
+
return { ...layout, blocks: visit(layout.blocks) };
|
|
34
|
+
}
|
|
35
|
+
/** The `$relations` a list block carries, if any. */
|
|
36
|
+
export function relationsIn(props) {
|
|
37
|
+
const value = props?.[RELATIONS_PROP];
|
|
38
|
+
return isRecord(value) ? value : undefined;
|
|
39
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Payload } from 'payload';
|
|
2
|
-
import { type
|
|
2
|
+
import { type BlockDefinition, type Layout, type TemplateContext } from '../../core/index.js';
|
|
3
3
|
import { type ListQueryParams } from './lists.js';
|
|
4
4
|
import type { FetchDocs, ResolveLink } from './types.js';
|
|
5
5
|
import { type RenderLocale } from './locale.js';
|
|
@@ -18,8 +18,6 @@ export type LoadLayoutOptions = RenderLocale & {
|
|
|
18
18
|
context?: TemplateContext | null;
|
|
19
19
|
/** The site's link resolver, for the `$url` binding path. `RenderLayout` resolves it otherwise. */
|
|
20
20
|
resolveLink?: ResolveLink;
|
|
21
|
-
/** Which collection each relationship field points to (`bindingRelations`), for `<path>.$url` bindings. */
|
|
22
|
-
relations?: BindingRelations | null;
|
|
23
21
|
/**
|
|
24
22
|
* The visitor (the signed-in user, or none). Collection lists load their documents with this
|
|
25
23
|
* user's access (`overrideAccess: false`), so a list never shows documents or populated fields
|
|
@@ -42,11 +40,17 @@ export type LoadLayoutOptions = RenderLocale & {
|
|
|
42
40
|
* per call, so a cached page shuffles once per cache build.
|
|
43
41
|
*/
|
|
44
42
|
randomSeed?: number;
|
|
43
|
+
/**
|
|
44
|
+
* Also load the collection lists inside hidden blocks. Off by default: the site never renders
|
|
45
|
+
* them. The canvas server turns it on, because the editor shows hidden blocks dimmed.
|
|
46
|
+
*/
|
|
47
|
+
includeHidden?: boolean;
|
|
45
48
|
};
|
|
46
49
|
/**
|
|
47
50
|
* Server helper: prepares a layout for `RenderLayout` with Payload's Local API.
|
|
48
51
|
* 0. Puts the current blocks of each live saved section (`sectionRef`) into the layout.
|
|
49
|
-
* 1. Resolves bindings and Field blocks against `options.context` (when given).
|
|
52
|
+
* 1. Resolves bindings, visibility conditions and Field blocks against `options.context` (when given).
|
|
53
|
+
* `<path>.$url` bindings read the relationship fields' collections from the Payload config.
|
|
50
54
|
* 2. Loads every collection list's documents (`depth: 1` or the list's `depth`; published only unless `draft`), with the
|
|
51
55
|
* access of `options.user` (anonymous without it).
|
|
52
56
|
* 3. Replaces upload/relationship IDs in block props with documents (one batched `find` per collection).
|
|
@@ -3,6 +3,8 @@ import { resolveBindings } from '../../core/index.js';
|
|
|
3
3
|
import { isRecord, mapFieldValues } from './fields.js';
|
|
4
4
|
import { arrangeListDocs, attachListItems, listQueries, listRequest, pageLinks, withPageParams } from './lists.js';
|
|
5
5
|
import { localeArgs, localizeLayout } from './locale.js';
|
|
6
|
+
import { relationsOf, withRelations } from './relations.js';
|
|
7
|
+
import { savedSectionsSlugOf } from '../../blocks/builtins/sectionRef.js';
|
|
6
8
|
import { attachSections } from './sections.js';
|
|
7
9
|
const isId = (value) => typeof value === 'string' || typeof value === 'number';
|
|
8
10
|
/** Maps one relationship/upload value (single or hasMany, plain or polymorphic). */
|
|
@@ -116,7 +118,8 @@ export function urlResolver(resolveLink) {
|
|
|
116
118
|
/**
|
|
117
119
|
* Server helper: prepares a layout for `RenderLayout` with Payload's Local API.
|
|
118
120
|
* 0. Puts the current blocks of each live saved section (`sectionRef`) into the layout.
|
|
119
|
-
* 1. Resolves bindings and Field blocks against `options.context` (when given).
|
|
121
|
+
* 1. Resolves bindings, visibility conditions and Field blocks against `options.context` (when given).
|
|
122
|
+
* `<path>.$url` bindings read the relationship fields' collections from the Payload config.
|
|
120
123
|
* 2. Loads every collection list's documents (`depth: 1` or the list's `depth`; published only unless `draft`), with the
|
|
121
124
|
* access of `options.user` (anonymous without it).
|
|
122
125
|
* 3. Replaces upload/relationship IDs in block props with documents (one batched `find` per collection).
|
|
@@ -142,15 +145,17 @@ export async function loadLayoutData(layout, blocks, payload, options) {
|
|
|
142
145
|
return new Map(result.docs.map((doc) => [doc.id, doc]));
|
|
143
146
|
};
|
|
144
147
|
// Live saved sections first, so their blocks get the same bindings, lists and documents.
|
|
145
|
-
const withSections = await attachSections(layout, blocks, fetchDocs);
|
|
148
|
+
const withSections = await attachSections(layout, blocks, fetchDocs, savedSectionsSlugOf(payload.config) ?? undefined);
|
|
146
149
|
const localized = localizeLayout(withSections, blocks, payload, options);
|
|
150
|
+
// Which collection each relationship field points to, for `<path>.$url` bindings.
|
|
151
|
+
const relations = relationsOf(payload);
|
|
147
152
|
const bound = context
|
|
148
153
|
? resolveBindings(localized, context, blocks, {
|
|
149
154
|
...(options?.resolveLink ? { url: urlResolver(options.resolveLink) } : {}),
|
|
150
|
-
|
|
155
|
+
relations,
|
|
151
156
|
})
|
|
152
157
|
: localized;
|
|
153
|
-
const queries = listQueries(bound, context, options?.query);
|
|
158
|
+
const queries = listQueries(bound, context, options?.query, { includeHidden: options?.includeHidden === true });
|
|
154
159
|
const items = new Map();
|
|
155
160
|
const pages = new Map();
|
|
156
161
|
const seed = options?.randomSeed ?? Math.floor(Math.random() * 4_294_967_296);
|
|
@@ -161,7 +166,8 @@ export async function loadLayoutData(layout, blocks, payload, options) {
|
|
|
161
166
|
pages.set(query.blockId, pageLinks(options?.query, query.page, result.totalPages, query.pageParam, options?.path));
|
|
162
167
|
}));
|
|
163
168
|
const withItems = withPageParams(attachListItems(bound, items, pages), queries);
|
|
164
|
-
|
|
169
|
+
// List items and repeat rows resolve their bindings in `RenderLayout`: they take the relations along.
|
|
170
|
+
return resolveLayoutData(withRelations(withItems, relations), blocks, fetchDocs);
|
|
165
171
|
}
|
|
166
172
|
/**
|
|
167
173
|
* One collection list's documents. An unknown collection, a filter that matches nothing (`none`) or
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type RefObject } from 'react';
|
|
2
|
+
/** The DOM event the canvas sends from a selected block's element. It bubbles. */
|
|
3
|
+
export declare const REVEAL_EVENT = "builder:reveal";
|
|
4
|
+
/**
|
|
5
|
+
* Put this attribute on the controls of an interactive block (arrows, dots, tab buttons, a popup's
|
|
6
|
+
* close button). In the canvas, a click on such an element works as on the site (it does not select
|
|
7
|
+
* the block), and the "+" insert button does not show over it.
|
|
8
|
+
*/
|
|
9
|
+
export declare const CANVAS_CONTROL_ATTRIBUTE = "data-builder-control";
|
|
10
|
+
/** Sends the reveal event from a block's element. The canvas calls it when a block is selected. */
|
|
11
|
+
export declare function revealBlock(element: Element): void;
|
|
12
|
+
/**
|
|
13
|
+
* Calls `onReveal` with the selected block's element when the editor selects a block inside the
|
|
14
|
+
* element of `ref`. Only the canvas sends the event, so on the site it never fires. For client
|
|
15
|
+
* components. Example: scroll a carousel to the slide that holds the target.
|
|
16
|
+
*/
|
|
17
|
+
export declare function useCanvasReveal(ref: RefObject<HTMLElement | null>, onReveal: (target: HTMLElement) => void): void;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
// Interactive blocks (a carousel, an accordion, a popup, tabs) keep part of their content out of
|
|
3
|
+
// view. In the editor's canvas, a block inside them must come into view when the editor selects it
|
|
4
|
+
// (in the canvas or in Layers). The canvas sends a "reveal" DOM event from the selected block's
|
|
5
|
+
// element; it bubbles, so every interactive block around it can show it: scroll to the slide, open
|
|
6
|
+
// the item, open the popup, pick the tab.
|
|
7
|
+
import { useEffect, useEffectEvent } from 'react';
|
|
8
|
+
/** The DOM event the canvas sends from a selected block's element. It bubbles. */
|
|
9
|
+
export const REVEAL_EVENT = 'builder:reveal';
|
|
10
|
+
/**
|
|
11
|
+
* Put this attribute on the controls of an interactive block (arrows, dots, tab buttons, a popup's
|
|
12
|
+
* close button). In the canvas, a click on such an element works as on the site (it does not select
|
|
13
|
+
* the block), and the "+" insert button does not show over it.
|
|
14
|
+
*/
|
|
15
|
+
export const CANVAS_CONTROL_ATTRIBUTE = 'data-builder-control';
|
|
16
|
+
/** Sends the reveal event from a block's element. The canvas calls it when a block is selected. */
|
|
17
|
+
export function revealBlock(element) {
|
|
18
|
+
element.dispatchEvent(new CustomEvent(REVEAL_EVENT, { bubbles: true }));
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Calls `onReveal` with the selected block's element when the editor selects a block inside the
|
|
22
|
+
* element of `ref`. Only the canvas sends the event, so on the site it never fires. For client
|
|
23
|
+
* components. Example: scroll a carousel to the slide that holds the target.
|
|
24
|
+
*/
|
|
25
|
+
export function useCanvasReveal(ref, onReveal) {
|
|
26
|
+
// The latest `onReveal`, without adding the listener again on every render.
|
|
27
|
+
const reveal = useEffectEvent(onReveal);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
const element = ref.current;
|
|
30
|
+
if (!element)
|
|
31
|
+
return;
|
|
32
|
+
const listener = (event) => {
|
|
33
|
+
if (event.target instanceof HTMLElement)
|
|
34
|
+
reveal(event.target);
|
|
35
|
+
};
|
|
36
|
+
element.addEventListener(REVEAL_EVENT, listener);
|
|
37
|
+
return () => element.removeEventListener(REVEAL_EVENT, listener);
|
|
38
|
+
}, [ref]);
|
|
39
|
+
}
|