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
package/dist/blocks/index.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
export { defaultBlocks, FIELD_CLASS_MAP, MENU_CLASS_MAP, type DefaultBlocksOptions } from './defaults.js';
|
|
1
|
+
export { defaultBlocks, FIELD_CLASS_MAP, MENU_CLASS_MAP, MENU_LABELS, type DefaultBlocksOptions } from './defaults.js';
|
|
2
2
|
export * from './builtins/index.js';
|
|
3
3
|
export { isLinkField, linkField, type BuilderCondition, type LinkFieldOptions } from './link.js';
|
|
4
4
|
export { fromPayloadBlocks, type FromPayloadBlocksOptions, type PayloadBlockOverride } from './payload.js';
|
|
5
5
|
export { defineBlock, defineSection, type SectionBlockInput, type SectionInput, sectionsWithVariants, withDefaultClassNames, withInlineBlocks } from '../core/blocks.js';
|
|
6
6
|
export { BUILDER_CSS_CLASS, withBuilderCssClass } from '../css/marker.js';
|
|
7
|
-
export { listCollectionsOf, prepareBlocks } from '../plugin/listCollections.js';
|
|
8
7
|
export type { Block, BlockDefinition, BlockProps, Layout, SectionDefinition, SectionVariant, SlotDefinition, } from '../core/types.js';
|
package/dist/blocks/index.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
// Client-safe entry: `payload-canvas/blocks`. Block definitions are plain data, so the
|
|
2
2
|
// site, the canvas iframe and payload.config.ts can all import the same blocks list.
|
|
3
3
|
// No `node:` imports and no Payload runtime imports here (type imports only). A test checks it.
|
|
4
|
-
export { defaultBlocks, FIELD_CLASS_MAP, MENU_CLASS_MAP } from './defaults.js';
|
|
4
|
+
export { defaultBlocks, FIELD_CLASS_MAP, MENU_CLASS_MAP, MENU_LABELS } from './defaults.js';
|
|
5
5
|
export * from './builtins/index.js';
|
|
6
6
|
export { isLinkField, linkField } from './link.js';
|
|
7
7
|
export { fromPayloadBlocks } from './payload.js';
|
|
8
8
|
export { defineBlock, defineSection, sectionsWithVariants, withDefaultClassNames, withInlineBlocks } from '../core/blocks.js';
|
|
9
9
|
export { BUILDER_CSS_CLASS, withBuilderCssClass } from '../css/marker.js';
|
|
10
|
-
export { listCollectionsOf, prepareBlocks } from '../plugin/listCollections.js';
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { type CollectionAfterChangeHook, type PayloadRequest } from 'payload';
|
|
2
|
+
import { type BuilderClass, type ClassUsage } from './shared.js';
|
|
3
|
+
import { type ReplaceResult } from './usage.js';
|
|
4
|
+
export type ActionResult<T> = ({
|
|
5
|
+
ok: true;
|
|
6
|
+
} & T) | {
|
|
7
|
+
ok: false;
|
|
8
|
+
status: number;
|
|
9
|
+
error: string;
|
|
10
|
+
usage?: ClassUsage;
|
|
11
|
+
};
|
|
12
|
+
/** A readable message of a Payload error: the field messages of a ValidationError, else the message. */
|
|
13
|
+
export declare function errorMessage(error: unknown): string;
|
|
14
|
+
/** The classes (their latest drafts) the request's user may read, by name. */
|
|
15
|
+
export declare function loadClasses(req: PayloadRequest): Promise<BuilderClass[]>;
|
|
16
|
+
/** One class by name (its latest draft), or null. Former names do not count. */
|
|
17
|
+
export declare function findClass(req: PayloadRequest, name: string): Promise<BuilderClass | null>;
|
|
18
|
+
/** Publishes the class's latest draft. */
|
|
19
|
+
export declare function publishClass(req: PayloadRequest, id: string | number): Promise<ActionResult<{
|
|
20
|
+
class: BuilderClass;
|
|
21
|
+
}>>;
|
|
22
|
+
export type ClassInput = {
|
|
23
|
+
label?: string | null;
|
|
24
|
+
group?: string | null;
|
|
25
|
+
styles?: string | null;
|
|
26
|
+
css?: string | null;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Creates the class `name`, or updates it when it exists (its latest draft). `publish`: publish it
|
|
30
|
+
* too. `newName`: rename it first (see `renameClass`).
|
|
31
|
+
*/
|
|
32
|
+
export declare function upsertClass(req: PayloadRequest, args: ClassInput & {
|
|
33
|
+
name: string;
|
|
34
|
+
newName?: string;
|
|
35
|
+
publish?: boolean;
|
|
36
|
+
}): Promise<ActionResult<{
|
|
37
|
+
class: BuilderClass;
|
|
38
|
+
created: boolean;
|
|
39
|
+
renamed?: ReplaceResult;
|
|
40
|
+
}>>;
|
|
41
|
+
/**
|
|
42
|
+
* Renames a class everywhere: the class (its published version and its latest draft; pending draft
|
|
43
|
+
* changes stay drafts), and every layout that uses the old name, through the live sessions. The
|
|
44
|
+
* old published name stays as a former name, so published pages keep their look until they are
|
|
45
|
+
* published again.
|
|
46
|
+
*/
|
|
47
|
+
export declare function renameClass(req: PayloadRequest, id: string | number, name: string): Promise<ActionResult<{
|
|
48
|
+
class: BuilderClass;
|
|
49
|
+
replaced: ReplaceResult;
|
|
50
|
+
}>>;
|
|
51
|
+
/**
|
|
52
|
+
* Deletes a class. While blocks use it, `removeFromBlocks` must be true: the class is removed from
|
|
53
|
+
* those blocks first (their drafts, through the live sessions). Published pages lose its styles
|
|
54
|
+
* at once.
|
|
55
|
+
*/
|
|
56
|
+
export declare function deleteClass(req: PayloadRequest, id: string | number, options?: {
|
|
57
|
+
removeFromBlocks?: boolean;
|
|
58
|
+
}): Promise<ActionResult<{
|
|
59
|
+
name: string;
|
|
60
|
+
replaced: ReplaceResult;
|
|
61
|
+
}>>;
|
|
62
|
+
/**
|
|
63
|
+
* Creates published classes from the site's code `@utility` classes (`/* @canvas Group: Label *\/`
|
|
64
|
+
* comments give label and group). Names that are classes already are skipped. One stylesheet
|
|
65
|
+
* compile at the end. After the import the classes are the source: the code rules can go.
|
|
66
|
+
*/
|
|
67
|
+
export declare function importSiteClasses(req: PayloadRequest, names?: readonly string[]): Promise<ActionResult<{
|
|
68
|
+
created: BuilderClass[];
|
|
69
|
+
skipped: Array<{
|
|
70
|
+
name: string;
|
|
71
|
+
reason: string;
|
|
72
|
+
}>;
|
|
73
|
+
}>>;
|
|
74
|
+
/**
|
|
75
|
+
* A builder collection's `afterChange` hook: publishing a page publishes the classes it uses that
|
|
76
|
+
* have unpublished changes (new classes, edited styles, a rename), as the same user. So the live
|
|
77
|
+
* page looks like the canvas. Classes the user may not update stay drafts (logged).
|
|
78
|
+
*/
|
|
79
|
+
export declare function publishClassesWithPage(field: string): CollectionAfterChangeHook;
|
|
80
|
+
/** Every name the classes answer to (names and former names), for usage counts. */
|
|
81
|
+
export declare function namesOf(classes: readonly BuilderClass[]): string[];
|
|
82
|
+
/**
|
|
83
|
+
* The classes no block uses: not in any layout's latest draft or open live session, and not in any
|
|
84
|
+
* published layout (every document, not only those the user may read), by name or former name.
|
|
85
|
+
*/
|
|
86
|
+
export declare function unusedClasses(req: PayloadRequest): Promise<BuilderClass[]>;
|
|
87
|
+
/**
|
|
88
|
+
* Deletes every class no block uses (see `unusedClasses`), as the request's user. Classes the user
|
|
89
|
+
* may not delete are reported in `failed`.
|
|
90
|
+
*/
|
|
91
|
+
export declare function removeUnusedClasses(req: PayloadRequest): Promise<ActionResult<{
|
|
92
|
+
deleted: string[];
|
|
93
|
+
failed: Array<{
|
|
94
|
+
name: string;
|
|
95
|
+
error: string;
|
|
96
|
+
}>;
|
|
97
|
+
}>>;
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
// What the class endpoints and MCP tools do: list, create or update, rename, delete, import from
|
|
2
|
+
// the site's CSS, publish, and the hook that publishes a page's classes with the page.
|
|
3
|
+
// Every write goes through the Local API as the request's user (`overrideAccess: false`), so the
|
|
4
|
+
// collection's access, hooks, validation and versions apply. Server-only.
|
|
5
|
+
import { APIError, ValidationError } from 'payload';
|
|
6
|
+
import { normalizeLayout, walkBlocks } from '../core/tree.js';
|
|
7
|
+
import { getSiteClassRules } from '../css/index.js';
|
|
8
|
+
import { classesConfigOf } from './config.js';
|
|
9
|
+
import { SKIP_CLASSES_SHEET_CONTEXT } from './collection.js';
|
|
10
|
+
import { storeClassesSheet } from './sheet.js';
|
|
11
|
+
import { bareClass, classNameProblem, classTokens, FORCE_DELETE_CLASS_CONTEXT, importSiteClass, toBuilderClass, withPreviousName, } from './shared.js';
|
|
12
|
+
import { classUsage, replaceClassInLayouts, usedClassNames } from './usage.js';
|
|
13
|
+
/** A readable message of a Payload error: the field messages of a ValidationError, else the message. */
|
|
14
|
+
export function errorMessage(error) {
|
|
15
|
+
if (error instanceof ValidationError) {
|
|
16
|
+
const list = error.data?.errors ?? [];
|
|
17
|
+
const text = list.map((e) => e.message).filter(Boolean).join(' ');
|
|
18
|
+
if (text)
|
|
19
|
+
return text;
|
|
20
|
+
}
|
|
21
|
+
return error instanceof Error ? error.message : String(error);
|
|
22
|
+
}
|
|
23
|
+
const statusOf = (error) => error instanceof ValidationError ? 400 : error instanceof APIError ? error.status : error?.status && typeof error.status === 'number' ? error.status : 500;
|
|
24
|
+
const fail = (error) => ({ ok: false, status: statusOf(error), error: errorMessage(error) });
|
|
25
|
+
function requireConfig(req) {
|
|
26
|
+
const config = classesConfigOf(req.payload);
|
|
27
|
+
if (!config)
|
|
28
|
+
throw new APIError('Editable classes are turned off (`classes: false`).', 404, null, true);
|
|
29
|
+
return config;
|
|
30
|
+
}
|
|
31
|
+
const asUser = (req) => ({ overrideAccess: false, user: req.user, req });
|
|
32
|
+
/** The fields of a class that a version holds. */
|
|
33
|
+
const pick = (source) => ({ label: source.label ?? null, group: source.group ?? null, styles: source.styles ?? null, css: source.css ?? null });
|
|
34
|
+
/** The classes (their latest drafts) the request's user may read, by name. */
|
|
35
|
+
export async function loadClasses(req) {
|
|
36
|
+
const config = requireConfig(req);
|
|
37
|
+
const result = await req.payload.find({ collection: config.slug, draft: true, depth: 0, pagination: false, sort: 'name', ...asUser(req) });
|
|
38
|
+
return result.docs.flatMap((doc) => toBuilderClass(doc) ?? []);
|
|
39
|
+
}
|
|
40
|
+
/** One class by name (its latest draft), or null. Former names do not count. */
|
|
41
|
+
export async function findClass(req, name) {
|
|
42
|
+
const config = requireConfig(req);
|
|
43
|
+
const result = await req.payload.find({ collection: config.slug, draft: true, depth: 0, limit: 1, pagination: false, where: { name: { equals: name } }, ...asUser(req) });
|
|
44
|
+
const doc = result.docs[0];
|
|
45
|
+
return doc ? toBuilderClass(doc) : null;
|
|
46
|
+
}
|
|
47
|
+
async function byId(req, id, draft) {
|
|
48
|
+
const config = requireConfig(req);
|
|
49
|
+
return (await req.payload.findByID({ collection: config.slug, id, depth: 0, draft, ...asUser(req) }).catch(() => null));
|
|
50
|
+
}
|
|
51
|
+
/** Publishes the class's latest draft. */
|
|
52
|
+
export async function publishClass(req, id) {
|
|
53
|
+
try {
|
|
54
|
+
const config = requireConfig(req);
|
|
55
|
+
const doc = await req.payload.update({ collection: config.slug, id, data: { _status: 'published' }, depth: 0, ...asUser(req) });
|
|
56
|
+
return { ok: true, class: toBuilderClass(doc) };
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
return fail(error);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Creates the class `name`, or updates it when it exists (its latest draft). `publish`: publish it
|
|
64
|
+
* too. `newName`: rename it first (see `renameClass`).
|
|
65
|
+
*/
|
|
66
|
+
export async function upsertClass(req, args) {
|
|
67
|
+
try {
|
|
68
|
+
const config = requireConfig(req);
|
|
69
|
+
const data = {};
|
|
70
|
+
for (const key of ['label', 'group', 'styles', 'css'])
|
|
71
|
+
if (args[key] !== undefined)
|
|
72
|
+
data[key] = args[key];
|
|
73
|
+
const existing = await findClass(req, args.name);
|
|
74
|
+
if (!existing) {
|
|
75
|
+
const problem = classNameProblem(args.newName ?? args.name);
|
|
76
|
+
if (problem)
|
|
77
|
+
return { ok: false, status: 400, error: problem };
|
|
78
|
+
const doc = await req.payload.create({
|
|
79
|
+
collection: config.slug,
|
|
80
|
+
data: { ...data, name: args.newName ?? args.name, _status: args.publish ? 'published' : 'draft' },
|
|
81
|
+
draft: !args.publish,
|
|
82
|
+
depth: 0,
|
|
83
|
+
...asUser(req),
|
|
84
|
+
});
|
|
85
|
+
return { ok: true, class: toBuilderClass(doc), created: true };
|
|
86
|
+
}
|
|
87
|
+
let renamed;
|
|
88
|
+
if (args.newName && args.newName !== existing.name) {
|
|
89
|
+
const result = await renameClass(req, existing.id, args.newName);
|
|
90
|
+
if (!result.ok)
|
|
91
|
+
return result;
|
|
92
|
+
renamed = result.replaced;
|
|
93
|
+
}
|
|
94
|
+
const doc = await req.payload.update({
|
|
95
|
+
collection: config.slug,
|
|
96
|
+
id: existing.id,
|
|
97
|
+
data: { ...data, ...(args.publish ? { _status: 'published' } : {}) },
|
|
98
|
+
draft: !args.publish,
|
|
99
|
+
depth: 0,
|
|
100
|
+
...asUser(req),
|
|
101
|
+
});
|
|
102
|
+
return { ok: true, class: toBuilderClass(doc), created: false, ...(renamed ? { renamed } : {}) };
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
return fail(error);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Renames a class everywhere: the class (its published version and its latest draft; pending draft
|
|
110
|
+
* changes stay drafts), and every layout that uses the old name, through the live sessions. The
|
|
111
|
+
* old published name stays as a former name, so published pages keep their look until they are
|
|
112
|
+
* published again.
|
|
113
|
+
*/
|
|
114
|
+
export async function renameClass(req, id, name) {
|
|
115
|
+
try {
|
|
116
|
+
const config = requireConfig(req);
|
|
117
|
+
const next = name.trim();
|
|
118
|
+
const problem = classNameProblem(next);
|
|
119
|
+
if (problem)
|
|
120
|
+
return { ok: false, status: 400, error: problem };
|
|
121
|
+
const draft = await byId(req, id, true);
|
|
122
|
+
if (!draft || typeof draft.name !== 'string')
|
|
123
|
+
return { ok: false, status: 404, error: 'The class does not exist, or you may not read it.' };
|
|
124
|
+
const old = draft.name;
|
|
125
|
+
if (old === next)
|
|
126
|
+
return { ok: true, class: toBuilderClass(draft), replaced: { documents: 0, blocks: 0, failed: [] } };
|
|
127
|
+
const main = await byId(req, id, false);
|
|
128
|
+
const published = main?._status === 'published' ? main : null;
|
|
129
|
+
const previous = published ? withPreviousName(withPreviousName(draft.previousNames, old, next), String(published.name), next) : (draft.previousNames ?? []).filter((n) => n !== next);
|
|
130
|
+
const write = (data, asDraft) => req.payload.update({ collection: config.slug, id, data: { ...data, name: next, previousNames: previous }, draft: asDraft, depth: 0, ...asUser(req) });
|
|
131
|
+
let doc;
|
|
132
|
+
if (!published)
|
|
133
|
+
doc = await write({}, true);
|
|
134
|
+
else if (draft._status === 'published')
|
|
135
|
+
doc = await write({ _status: 'published' }, false);
|
|
136
|
+
else {
|
|
137
|
+
// Publish the new name with the published styles, then put the pending draft back on top.
|
|
138
|
+
await write({ ...pick(published), _status: 'published' }, false);
|
|
139
|
+
doc = await write({ ...pick(draft), _status: 'draft' }, true);
|
|
140
|
+
}
|
|
141
|
+
const replaced = await replaceClassInLayouts(req, old, next);
|
|
142
|
+
return { ok: true, class: toBuilderClass(doc), replaced };
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
return fail(error);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Deletes a class. While blocks use it, `removeFromBlocks` must be true: the class is removed from
|
|
150
|
+
* those blocks first (their drafts, through the live sessions). Published pages lose its styles
|
|
151
|
+
* at once.
|
|
152
|
+
*/
|
|
153
|
+
export async function deleteClass(req, id, options = {}) {
|
|
154
|
+
try {
|
|
155
|
+
const config = requireConfig(req);
|
|
156
|
+
const draft = await byId(req, id, true);
|
|
157
|
+
if (!draft || typeof draft.name !== 'string')
|
|
158
|
+
return { ok: false, status: 404, error: 'The class does not exist, or you may not read it.' };
|
|
159
|
+
const name = draft.name;
|
|
160
|
+
const usage = (await classUsage(req, [name]))[name];
|
|
161
|
+
if (usage && usage.blocks > 0 && !options.removeFromBlocks) {
|
|
162
|
+
return { ok: false, status: 409, error: `.${name} is used on ${usage.blocks} block(s). Pass removeFromBlocks to remove it from them and delete it.`, usage };
|
|
163
|
+
}
|
|
164
|
+
const replaced = usage && usage.blocks > 0 ? await replaceClassInLayouts(req, name, null) : { documents: 0, blocks: 0, failed: [] };
|
|
165
|
+
if (replaced.failed.length > 0) {
|
|
166
|
+
return { ok: false, status: 403, error: `Not deleted: .${name} could not be removed from ${replaced.failed.map((f) => `“${f.title}” (${f.error})`).join(', ')}.` };
|
|
167
|
+
}
|
|
168
|
+
await req.payload.delete({ collection: config.slug, id, ...asUser(req), context: { [FORCE_DELETE_CLASS_CONTEXT]: true } });
|
|
169
|
+
return { ok: true, name, replaced };
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
return fail(error);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Creates published classes from the site's code `@utility` classes (`/* @canvas Group: Label *\/`
|
|
177
|
+
* comments give label and group). Names that are classes already are skipped. One stylesheet
|
|
178
|
+
* compile at the end. After the import the classes are the source: the code rules can go.
|
|
179
|
+
*/
|
|
180
|
+
export async function importSiteClasses(req, names) {
|
|
181
|
+
try {
|
|
182
|
+
const config = requireConfig(req);
|
|
183
|
+
const rules = (await getSiteClassRules(config.css)).filter((rule) => !names || names.includes(rule.name));
|
|
184
|
+
const existing = await req.payload.find({ collection: config.slug, draft: true, depth: 0, pagination: false, overrideAccess: true, req, select: { name: true } });
|
|
185
|
+
const taken = new Set(existing.docs.map((d) => d.name));
|
|
186
|
+
const created = [];
|
|
187
|
+
const skipped = [];
|
|
188
|
+
for (const rule of rules) {
|
|
189
|
+
if (taken.has(rule.name)) {
|
|
190
|
+
skipped.push({ name: rule.name, reason: 'already a class' });
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
try {
|
|
194
|
+
const doc = await req.payload.create({
|
|
195
|
+
collection: config.slug,
|
|
196
|
+
data: { ...importSiteClass(rule), _status: 'published' },
|
|
197
|
+
depth: 0,
|
|
198
|
+
...asUser(req),
|
|
199
|
+
context: { [SKIP_CLASSES_SHEET_CONTEXT]: true },
|
|
200
|
+
});
|
|
201
|
+
created.push(toBuilderClass(doc));
|
|
202
|
+
}
|
|
203
|
+
catch (error) {
|
|
204
|
+
skipped.push({ name: rule.name, reason: errorMessage(error) });
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if (created.length > 0)
|
|
208
|
+
await storeClassesSheet(req.payload, req);
|
|
209
|
+
return { ok: true, created, skipped };
|
|
210
|
+
}
|
|
211
|
+
catch (error) {
|
|
212
|
+
return fail(error);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
/** The bare class names a layout uses (blocks and their parts). */
|
|
216
|
+
function layoutClassNames(layout) {
|
|
217
|
+
const names = new Set();
|
|
218
|
+
walkBlocks(layout, (block) => {
|
|
219
|
+
for (const token of classTokens(block.className))
|
|
220
|
+
names.add(bareClass(token));
|
|
221
|
+
for (const value of Object.values(block.partClassName ?? {}))
|
|
222
|
+
if (typeof value === 'string')
|
|
223
|
+
for (const token of classTokens(value))
|
|
224
|
+
names.add(bareClass(token));
|
|
225
|
+
});
|
|
226
|
+
return names;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* A builder collection's `afterChange` hook: publishing a page publishes the classes it uses that
|
|
230
|
+
* have unpublished changes (new classes, edited styles, a rename), as the same user. So the live
|
|
231
|
+
* page looks like the canvas. Classes the user may not update stay drafts (logged).
|
|
232
|
+
*/
|
|
233
|
+
export function publishClassesWithPage(field) {
|
|
234
|
+
return async ({ doc, req }) => {
|
|
235
|
+
if (doc?._status !== 'published')
|
|
236
|
+
return doc;
|
|
237
|
+
const config = classesConfigOf(req.payload);
|
|
238
|
+
if (!config)
|
|
239
|
+
return doc;
|
|
240
|
+
const names = layoutClassNames(normalizeLayout(doc[field]));
|
|
241
|
+
if (names.size === 0)
|
|
242
|
+
return doc;
|
|
243
|
+
const pending = await req.payload
|
|
244
|
+
.find({ collection: config.slug, draft: true, depth: 0, pagination: false, where: { name: { in: [...names] } }, overrideAccess: true, req })
|
|
245
|
+
.catch(() => null);
|
|
246
|
+
for (const cls of (pending?.docs ?? [])) {
|
|
247
|
+
if (cls._status !== 'draft')
|
|
248
|
+
continue;
|
|
249
|
+
try {
|
|
250
|
+
// A save without a user (a seed script, a migration) publishes them as the system does.
|
|
251
|
+
await req.payload.update({ collection: config.slug, id: cls.id, data: { _status: 'published' }, depth: 0, ...(req.user ? asUser(req) : { overrideAccess: true, req }) });
|
|
252
|
+
}
|
|
253
|
+
catch (error) {
|
|
254
|
+
req.payload.logger.warn(`[websiteBuilder] Publishing the page did not publish the class "${String(cls.name)}": ${errorMessage(error)}`);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return doc;
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
/** Every name the classes answer to (names and former names), for usage counts. */
|
|
261
|
+
export function namesOf(classes) {
|
|
262
|
+
return [...new Set(classes.flatMap((c) => [c.name, ...(c.previousNames ?? [])]))];
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* The classes no block uses: not in any layout's latest draft or open live session, and not in any
|
|
266
|
+
* published layout (every document, not only those the user may read), by name or former name.
|
|
267
|
+
*/
|
|
268
|
+
export async function unusedClasses(req) {
|
|
269
|
+
const classes = await loadClasses(req);
|
|
270
|
+
const used = await usedClassNames(req, namesOf(classes));
|
|
271
|
+
return classes.filter((c) => [c.name, ...(c.previousNames ?? [])].every((name) => !used.has(name)));
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Deletes every class no block uses (see `unusedClasses`), as the request's user. Classes the user
|
|
275
|
+
* may not delete are reported in `failed`.
|
|
276
|
+
*/
|
|
277
|
+
export async function removeUnusedClasses(req) {
|
|
278
|
+
try {
|
|
279
|
+
const config = requireConfig(req);
|
|
280
|
+
const deleted = [];
|
|
281
|
+
const failed = [];
|
|
282
|
+
for (const item of await unusedClasses(req)) {
|
|
283
|
+
try {
|
|
284
|
+
await req.payload.delete({ collection: config.slug, id: item.id, ...asUser(req) });
|
|
285
|
+
deleted.push(item.name);
|
|
286
|
+
}
|
|
287
|
+
catch (error) {
|
|
288
|
+
failed.push({ name: item.name, error: errorMessage(error) });
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
return { ok: true, deleted, failed };
|
|
292
|
+
}
|
|
293
|
+
catch (error) {
|
|
294
|
+
return fail(error);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type CollectionConfig } from 'payload';
|
|
2
|
+
import { type ClassesOptions } from './config.js';
|
|
3
|
+
/** `context` flag: skip the stylesheet compile in this save (a batch compiles once at its end). */
|
|
4
|
+
export declare const SKIP_CLASSES_SHEET_CONTEXT = "builderSkipClassesSheet";
|
|
5
|
+
export declare function classesCollection(slug: string, options?: ClassesOptions): CollectionConfig;
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
// The classes collection: one document per editable class, with drafts and versions. Server-only
|
|
2
|
+
// (the revalidation imports next/cache).
|
|
3
|
+
import { revalidatePath } from 'next/cache';
|
|
4
|
+
import { APIError, } from 'payload';
|
|
5
|
+
import { isTailwindUtility } from '../css/index.js';
|
|
6
|
+
import { classesConfigOf } from './config.js';
|
|
7
|
+
import { storeClassesSheet } from './sheet.js';
|
|
8
|
+
import { classNameProblem, cssProblem, FORCE_DELETE_CLASS_CONTEXT, normalizeStyles, plural, withPreviousName } from './shared.js';
|
|
9
|
+
import { classUsage } from './usage.js';
|
|
10
|
+
/** `context` flag: skip the stylesheet compile in this save (a batch compiles once at its end). */
|
|
11
|
+
export const SKIP_CLASSES_SHEET_CONTEXT = 'builderSkipClassesSheet';
|
|
12
|
+
const signedIn = ({ req }) => Boolean(req.user);
|
|
13
|
+
/** Form, no Tailwind utility with the name, unique among the latest drafts too. */
|
|
14
|
+
const validateName = async (value, options) => {
|
|
15
|
+
const problem = classNameProblem(value);
|
|
16
|
+
if (problem)
|
|
17
|
+
return problem;
|
|
18
|
+
const name = String(value).trim();
|
|
19
|
+
const { req } = options;
|
|
20
|
+
const id = options.id;
|
|
21
|
+
const config = classesConfigOf(req.payload);
|
|
22
|
+
if (!config)
|
|
23
|
+
return true;
|
|
24
|
+
if (await isTailwindUtility(name, config.css).catch(() => false)) {
|
|
25
|
+
return `“${name}” is already a Tailwind class. Pick another name, for example “${name}-style”.`;
|
|
26
|
+
}
|
|
27
|
+
// The database's unique index covers the main documents; a draft rename must not clash either.
|
|
28
|
+
const clash = await req.payload.find({
|
|
29
|
+
collection: config.slug,
|
|
30
|
+
draft: true,
|
|
31
|
+
depth: 0,
|
|
32
|
+
limit: 1,
|
|
33
|
+
pagination: false,
|
|
34
|
+
where: { and: [{ name: { equals: name } }, ...(id !== undefined ? [{ id: { not_equals: id } }] : [])] },
|
|
35
|
+
overrideAccess: true,
|
|
36
|
+
req,
|
|
37
|
+
});
|
|
38
|
+
return clash.docs.length > 0 ? `A class named “${name}” already exists.` : true;
|
|
39
|
+
};
|
|
40
|
+
/** Custom CSS must compile when the class is published. Drafts may hold half-typed CSS. */
|
|
41
|
+
const validateCss = (value, { data }) => data?._status === 'published' ? (cssProblem(value) ?? true) : true;
|
|
42
|
+
/**
|
|
43
|
+
* On publish, a name that differs from the published one keeps the published name as a former
|
|
44
|
+
* name: published pages that still use it keep their look. Styles get one space between classes.
|
|
45
|
+
*/
|
|
46
|
+
const beforeChange = async ({ data, operation, originalDoc, req }) => {
|
|
47
|
+
if ('styles' in data)
|
|
48
|
+
data.styles = normalizeStyles(data.styles);
|
|
49
|
+
if (typeof data.name === 'string')
|
|
50
|
+
data.name = data.name.trim();
|
|
51
|
+
if (operation !== 'update' || data._status !== 'published' || originalDoc?.id === undefined)
|
|
52
|
+
return data;
|
|
53
|
+
const config = classesConfigOf(req.payload);
|
|
54
|
+
if (!config)
|
|
55
|
+
return data;
|
|
56
|
+
const published = (await req.payload
|
|
57
|
+
.findByID({ collection: config.slug, id: originalDoc.id, depth: 0, draft: false, overrideAccess: true, req })
|
|
58
|
+
.catch(() => null));
|
|
59
|
+
const name = typeof data.name === 'string' ? data.name : String(originalDoc.name ?? '');
|
|
60
|
+
const previous = Array.isArray(data.previousNames) ? data.previousNames : (originalDoc.previousNames ?? []);
|
|
61
|
+
if (published?._status === 'published' && typeof published.name === 'string' && published.name !== name) {
|
|
62
|
+
data.previousNames = withPreviousName(previous, published.name, name);
|
|
63
|
+
}
|
|
64
|
+
else if (previous.includes(name)) {
|
|
65
|
+
data.previousNames = previous.filter((n) => n !== name);
|
|
66
|
+
}
|
|
67
|
+
return data;
|
|
68
|
+
};
|
|
69
|
+
/** Clears Next's page cache: the stylesheet's hashed URL is in every page's `<head>`. */
|
|
70
|
+
function revalidate(req) {
|
|
71
|
+
if (req.context?.disableRevalidate)
|
|
72
|
+
return;
|
|
73
|
+
try {
|
|
74
|
+
revalidatePath('/', 'layout');
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
req.payload.logger.debug(`[websiteBuilder] Classes revalidation skipped: ${error instanceof Error ? error.message : String(error)}`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
async function recompile(req) {
|
|
81
|
+
if (req.context?.[SKIP_CLASSES_SHEET_CONTEXT])
|
|
82
|
+
return;
|
|
83
|
+
try {
|
|
84
|
+
const sheet = await storeClassesSheet(req.payload, req);
|
|
85
|
+
if (sheet?.changed)
|
|
86
|
+
revalidate(req);
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
req.payload.logger.error({ err: error, msg: '[websiteBuilder] The classes stylesheet failed to compile. The site keeps the last one.' });
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/** The published stylesheet changes with a publish, an unpublish (the main document was published) and a delete. */
|
|
93
|
+
const afterChange = async ({ doc, previousDoc, req }) => {
|
|
94
|
+
if (doc?._status === 'published' || previousDoc?._status === 'published')
|
|
95
|
+
await recompile(req);
|
|
96
|
+
return doc;
|
|
97
|
+
};
|
|
98
|
+
const afterDelete = async ({ doc, req }) => {
|
|
99
|
+
await recompile(req);
|
|
100
|
+
return doc;
|
|
101
|
+
};
|
|
102
|
+
/** A class still used by blocks is not deleted (the builder's delete removes it from them first). */
|
|
103
|
+
const beforeDelete = async ({ id, req }) => {
|
|
104
|
+
if (req.context?.[FORCE_DELETE_CLASS_CONTEXT])
|
|
105
|
+
return;
|
|
106
|
+
const config = classesConfigOf(req.payload);
|
|
107
|
+
if (!config)
|
|
108
|
+
return;
|
|
109
|
+
const doc = (await req.payload.findByID({ collection: config.slug, id, depth: 0, draft: true, overrideAccess: true, req }).catch(() => null));
|
|
110
|
+
if (!doc || typeof doc.name !== 'string')
|
|
111
|
+
return;
|
|
112
|
+
const usage = (await classUsage(req, [doc.name], { asUser: false }))[doc.name];
|
|
113
|
+
if (!usage || usage.blocks === 0)
|
|
114
|
+
return;
|
|
115
|
+
const where = usage.documents
|
|
116
|
+
.slice(0, 5)
|
|
117
|
+
.map((d) => `“${d.title}”`)
|
|
118
|
+
.join(', ');
|
|
119
|
+
throw new APIError(`The class .${doc.name} is used on ${plural(usage.blocks, 'block')} on ${plural(usage.documents.length, 'page')} (${where}${usage.documents.length > 5 ? ', …' : ''}). ` +
|
|
120
|
+
'Delete it in the builder’s Styles panel, which removes it from those blocks too.', 409, null, true);
|
|
121
|
+
};
|
|
122
|
+
export function classesCollection(slug, options = {}) {
|
|
123
|
+
return {
|
|
124
|
+
slug,
|
|
125
|
+
labels: { singular: 'Class', plural: 'Classes' },
|
|
126
|
+
access: { read: signedIn, create: signedIn, update: signedIn, delete: signedIn, ...options.access },
|
|
127
|
+
admin: {
|
|
128
|
+
useAsTitle: 'name',
|
|
129
|
+
defaultColumns: ['name', 'label', 'group', '_status', 'updatedAt'],
|
|
130
|
+
description: 'Shared styles for blocks. Edit a class once and every block that uses it changes. The builder’s Styles panel edits them on the canvas.',
|
|
131
|
+
...options.admin,
|
|
132
|
+
},
|
|
133
|
+
versions: { maxPerDoc: 50, drafts: { autosave: { interval: 800 }, validate: true } },
|
|
134
|
+
hooks: {
|
|
135
|
+
...options.hooks,
|
|
136
|
+
beforeChange: [beforeChange, ...(options.hooks?.beforeChange ?? [])],
|
|
137
|
+
afterChange: [afterChange, ...(options.hooks?.afterChange ?? [])],
|
|
138
|
+
beforeDelete: [beforeDelete, ...(options.hooks?.beforeDelete ?? [])],
|
|
139
|
+
afterDelete: [afterDelete, ...(options.hooks?.afterDelete ?? [])],
|
|
140
|
+
},
|
|
141
|
+
fields: [
|
|
142
|
+
{
|
|
143
|
+
name: 'name',
|
|
144
|
+
type: 'text',
|
|
145
|
+
required: true,
|
|
146
|
+
unique: true,
|
|
147
|
+
index: true,
|
|
148
|
+
validate: validateName,
|
|
149
|
+
admin: {
|
|
150
|
+
description: 'The class name blocks use, without the dot. Rename a class in the builder’s Styles panel (or with the MCP tools): that also updates every page that uses it.',
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
type: 'row',
|
|
155
|
+
fields: [
|
|
156
|
+
{ name: 'label', type: 'text', admin: { description: 'Shown next to the name in the Classes box.' } },
|
|
157
|
+
{ name: 'group', type: 'text', admin: { description: 'Groups classes in the Classes box, for example “Buttons”.' } },
|
|
158
|
+
],
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
name: 'styles',
|
|
162
|
+
type: 'textarea',
|
|
163
|
+
admin: {
|
|
164
|
+
description: 'Tailwind classes with variants, for example “rounded-xl p-6 md:p-8 hover:shadow-lg”. Another class’s name applies that class.',
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
name: 'css',
|
|
169
|
+
type: 'code',
|
|
170
|
+
label: 'Custom CSS',
|
|
171
|
+
validate: validateCss,
|
|
172
|
+
admin: {
|
|
173
|
+
language: 'css',
|
|
174
|
+
description: 'Declarations and nested rules for what Tailwind classes cannot express: layered gradients, “&::before { … }”, @keyframes.',
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
name: 'previousNames',
|
|
179
|
+
type: 'text',
|
|
180
|
+
hasMany: true,
|
|
181
|
+
admin: {
|
|
182
|
+
position: 'sidebar',
|
|
183
|
+
readOnly: true,
|
|
184
|
+
description: 'Former published names. Published pages that still use them keep their look until they are published again.',
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
],
|
|
188
|
+
};
|
|
189
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { CollectionConfig } from 'payload';
|
|
2
|
+
import type { BlockDefinition } from '../core/types.js';
|
|
3
|
+
import type { CssOptions } from '../css/index.js';
|
|
4
|
+
export type ClassesOptions = {
|
|
5
|
+
/** Slug of the classes collection. Default "builder-classes". */
|
|
6
|
+
slug?: string;
|
|
7
|
+
/** Slug of the hidden global that stores the compiled stylesheet. Default "builder-classes-sheet". */
|
|
8
|
+
sheetSlug?: string;
|
|
9
|
+
/** Access control. Default: signed-in users read, create, update and delete. The site never reads the collection: it loads the compiled stylesheet. */
|
|
10
|
+
access?: CollectionConfig['access'];
|
|
11
|
+
/** Merged into the collection's `admin` options (e.g. `group`). */
|
|
12
|
+
admin?: CollectionConfig['admin'];
|
|
13
|
+
/** Extra hooks. They run after the plugin's own hooks. */
|
|
14
|
+
hooks?: CollectionConfig['hooks'];
|
|
15
|
+
};
|
|
16
|
+
/** What the server helpers need. Stored under `CLASSES_CONFIG_KEY`. */
|
|
17
|
+
export type ClassesServerConfig = {
|
|
18
|
+
slug: string;
|
|
19
|
+
sheetSlug: string;
|
|
20
|
+
/** Full API path of the class endpoints, e.g. "/api/builder/classes". */
|
|
21
|
+
endpoint: string;
|
|
22
|
+
/** Full API path of the stylesheet route, e.g. "/api/builder/classes-sheet". */
|
|
23
|
+
sheetPath: string;
|
|
24
|
+
/** The site's CSS entry and Tailwind plugins: the classes compile against them. */
|
|
25
|
+
css: CssOptions;
|
|
26
|
+
/** The block definitions: renames and removals apply operations to layouts with them. */
|
|
27
|
+
blocks: BlockDefinition[];
|
|
28
|
+
};
|
|
29
|
+
/** The classes config the plugin stored on the Payload config. `null` without the plugin or with `classes: false`. */
|
|
30
|
+
export declare function classesConfigOf(payload: {
|
|
31
|
+
config: {
|
|
32
|
+
custom?: Record<string, unknown>;
|
|
33
|
+
};
|
|
34
|
+
}): ClassesServerConfig | null;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Options of the editable classes and the config the plugin stores for the server helpers.
|
|
2
|
+
// Type imports only from `payload`: the site helpers import this file.
|
|
3
|
+
import { CLASSES_CONFIG_KEY } from './shared.js';
|
|
4
|
+
/** The classes config the plugin stored on the Payload config. `null` without the plugin or with `classes: false`. */
|
|
5
|
+
export function classesConfigOf(payload) {
|
|
6
|
+
const value = payload.config.custom?.[CLASSES_CONFIG_KEY];
|
|
7
|
+
return typeof value?.slug === 'string' && typeof value.sheetSlug === 'string' ? value : null;
|
|
8
|
+
}
|