payload-canvas 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +625 -153
- package/dist/admin/AiKeyField.d.ts +8 -0
- package/dist/admin/AiKeyField.js +54 -0
- package/dist/admin/BuilderTab.js +4 -1
- package/dist/admin/DocumentEditView.d.ts +9 -0
- package/dist/admin/DocumentEditView.js +45 -0
- package/dist/admin/LayoutField.d.ts +2 -2
- package/dist/admin/LayoutField.js +10 -7
- package/dist/admin/TemplateConditionsField.d.ts +9 -0
- package/dist/admin/TemplateConditionsField.js +22 -0
- package/dist/admin/aiKeyField.scss +58 -0
- package/dist/admin/client.d.ts +3 -0
- package/dist/admin/client.js +6 -0
- package/dist/admin/diff/changes.js +5 -0
- package/dist/admin/editor/Canvas.js +20 -5
- package/dist/admin/editor/Editor.d.ts +3 -1
- package/dist/admin/editor/Editor.js +6 -3
- package/dist/admin/editor/Inspector.js +75 -28
- package/dist/admin/editor/Library.js +40 -15
- package/dist/admin/editor/Outline.js +21 -16
- package/dist/admin/editor/Overlay.js +8 -3
- package/dist/admin/editor/actions.d.ts +10 -2
- package/dist/admin/editor/actions.js +18 -3
- package/dist/admin/editor/assistant/AssistantPanel.js +3 -1
- package/dist/admin/editor/classes/ClassManager.d.ts +4 -0
- package/dist/admin/editor/classes/ClassManager.js +56 -0
- package/dist/admin/editor/classes/controller.d.ts +112 -0
- package/dist/admin/editor/classes/controller.js +326 -0
- package/dist/admin/editor/classes/manager.scss +262 -0
- package/dist/admin/editor/classes/managerModel.d.ts +5 -0
- package/dist/admin/editor/classes/managerModel.js +27 -0
- package/dist/admin/editor/comments/CommentLayer.d.ts +2 -0
- package/dist/admin/editor/comments/CommentLayer.js +143 -0
- package/dist/admin/editor/comments/CommentsPanel.d.ts +8 -0
- package/dist/admin/editor/comments/CommentsPanel.js +73 -0
- package/dist/admin/editor/comments/Thread.d.ts +26 -0
- package/dist/admin/editor/comments/Thread.js +84 -0
- package/dist/admin/editor/comments/comments.scss +539 -0
- package/dist/admin/editor/comments/controller.d.ts +48 -0
- package/dist/admin/editor/comments/controller.js +142 -0
- package/dist/admin/editor/contentMode.d.ts +17 -0
- package/dist/admin/editor/contentMode.js +37 -0
- package/dist/admin/editor/dnd/DropOutlines.d.ts +1 -0
- package/dist/admin/editor/dnd/DropOutlines.js +73 -0
- package/dist/admin/editor/dnd/dnd.scss +43 -0
- package/dist/admin/editor/dnd/mode.d.ts +4 -0
- package/dist/admin/editor/dnd/mode.js +39 -0
- package/dist/admin/editor/editor.scss +13 -58
- package/dist/admin/editor/empty/EmptyStart.js +18 -66
- package/dist/admin/editor/fields/AddButton.d.ts +15 -0
- package/dist/admin/editor/fields/AddButton.js +14 -0
- package/dist/admin/editor/fields/ArrayField.js +3 -2
- package/dist/admin/editor/fields/CheckedInputs.d.ts +1 -0
- package/dist/admin/editor/fields/ConditionRows.d.ts +19 -0
- package/dist/admin/editor/fields/ConditionRows.js +137 -0
- package/dist/admin/editor/fields/ListWhereField.d.ts +8 -0
- package/dist/admin/editor/fields/ListWhereField.js +20 -0
- package/dist/admin/editor/fields/QueryFiltersField.d.ts +18 -0
- package/dist/admin/editor/fields/QueryFiltersField.js +41 -0
- package/dist/admin/editor/fields/RelatedField.d.ts +19 -0
- package/dist/admin/editor/fields/RelatedField.js +44 -0
- package/dist/admin/editor/fields/SortField.d.ts +13 -0
- package/dist/admin/editor/fields/SortField.js +37 -0
- package/dist/admin/editor/fields/WhereField.d.ts +12 -4
- package/dist/admin/editor/fields/WhereField.js +33 -53
- package/dist/admin/editor/fields/collectionFields.d.ts +6 -0
- package/dist/admin/editor/fields/collectionFields.js +15 -0
- package/dist/admin/editor/fields/conditions.d.ts +99 -0
- package/dist/admin/editor/fields/conditions.js +339 -0
- package/dist/admin/editor/fields/fields.scss +232 -9
- package/dist/admin/editor/fields/listOptions.d.ts +44 -0
- package/dist/admin/editor/fields/listOptions.js +111 -0
- package/dist/admin/editor/fields/queryFilterRows.d.ts +8 -0
- package/dist/admin/editor/fields/queryFilterRows.js +29 -0
- package/dist/admin/editor/fields/whereRows.d.ts +11 -12
- package/dist/admin/editor/fields/whereRows.js +83 -34
- package/dist/admin/editor/icons.d.ts +16 -1
- package/dist/admin/editor/icons.js +30 -1
- package/dist/admin/editor/inline.js +9 -0
- package/dist/admin/editor/insert/InsertHandle.js +4 -1
- package/dist/admin/editor/insert/picker.d.ts +3 -1
- package/dist/admin/editor/insert/picker.js +17 -10
- package/dist/admin/editor/insert/spots.d.ts +12 -1
- package/dist/admin/editor/insert/spots.js +49 -10
- package/dist/admin/editor/layout/LeftPanel.js +11 -6
- package/dist/admin/editor/live/useMultiplayer.js +9 -1
- package/dist/admin/editor/menu/blockMenu.js +27 -17
- package/dist/admin/editor/names.js +11 -3
- package/dist/admin/editor/renderField.d.ts +3 -1
- package/dist/admin/editor/renderField.js +63 -12
- package/dist/admin/editor/runtime.d.ts +14 -0
- package/dist/admin/editor/runtime.js +67 -6
- package/dist/admin/editor/sections/ComponentFields.d.ts +8 -0
- package/dist/admin/editor/sections/ComponentFields.js +116 -0
- package/dist/admin/editor/sections/PropertyControls.d.ts +18 -0
- package/dist/admin/editor/sections/PropertyControls.js +65 -0
- package/dist/admin/editor/sections/components.d.ts +29 -0
- package/dist/admin/editor/sections/components.js +112 -0
- package/dist/admin/editor/sections/components.scss +238 -0
- package/dist/admin/editor/sections/variants.d.ts +32 -0
- package/dist/admin/editor/sections/variants.js +59 -0
- package/dist/admin/editor/sections/variants.scss +90 -0
- package/dist/admin/editor/shortcuts.d.ts +4 -1
- package/dist/admin/editor/shortcuts.js +19 -3
- package/dist/admin/editor/store.d.ts +18 -0
- package/dist/admin/editor/store.js +46 -0
- package/dist/admin/editor/styles/ClassBar.d.ts +14 -0
- package/dist/admin/editor/styles/ClassBar.js +90 -0
- package/dist/admin/editor/styles/ClassCss.d.ts +4 -0
- package/dist/admin/editor/styles/ClassCss.js +28 -0
- package/dist/admin/editor/styles/ClassDialog.d.ts +2 -0
- package/dist/admin/editor/styles/ClassDialog.js +151 -0
- package/dist/admin/editor/styles/ColorPicker.js +5 -2
- package/dist/admin/editor/styles/RawClasses.d.ts +26 -1
- package/dist/admin/editor/styles/RawClasses.js +184 -32
- package/dist/admin/editor/styles/StylesPanel.d.ts +3 -3
- package/dist/admin/editor/styles/StylesPanel.js +53 -14
- package/dist/admin/editor/styles/VariantBar.js +2 -2
- package/dist/admin/editor/styles/classEdit.d.ts +4 -0
- package/dist/admin/editor/styles/classEdit.js +20 -0
- package/dist/admin/editor/styles/classes.scss +381 -0
- package/dist/admin/editor/styles/context.d.ts +19 -6
- package/dist/admin/editor/styles/context.js +24 -6
- package/dist/admin/editor/styles/controls.d.ts +3 -1
- package/dist/admin/editor/styles/controls.js +30 -12
- package/dist/admin/editor/styles/popover.d.ts +6 -0
- package/dist/admin/editor/styles/popover.js +5 -5
- package/dist/admin/editor/styles/styles.scss +26 -104
- package/dist/admin/editor/styles/suggestions.d.ts +22 -0
- package/dist/admin/editor/styles/suggestions.js +77 -0
- package/dist/admin/editor/styles/tokens.js +14 -0
- package/dist/admin/editor/templates/Bindable.js +86 -57
- package/dist/admin/editor/templates/SamplePicker.js +1 -1
- package/dist/admin/editor/templates/Visibility.d.ts +9 -0
- package/dist/admin/editor/templates/Visibility.js +54 -0
- package/dist/admin/editor/templates/binding.d.ts +2 -2
- package/dist/admin/editor/templates/binding.js +2 -2
- package/dist/admin/editor/templates/templates.scss +27 -0
- package/dist/admin/editor/templates/visibilityRows.d.ts +22 -0
- package/dist/admin/editor/templates/visibilityRows.js +83 -0
- package/dist/admin/editor/topbar/ContentModeToggle.d.ts +5 -0
- package/dist/admin/editor/topbar/ContentModeToggle.js +26 -0
- package/dist/admin/editor/topbar/DocumentActions.d.ts +1 -1
- package/dist/admin/editor/topbar/DocumentActions.js +5 -4
- package/dist/admin/editor/topbar/DocumentTitle.js +7 -2
- package/dist/admin/editor/topbar/TopBar.js +15 -3
- package/dist/admin/editor/topbar/contentMode.scss +35 -0
- package/dist/admin/editor/topbar/topbar.scss +3 -1
- package/dist/admin/formChoice.d.ts +3 -0
- package/dist/admin/formChoice.js +10 -0
- package/dist/admin/layoutField.scss +69 -0
- package/dist/admin/screen/BuilderScreen.d.ts +6 -1
- package/dist/admin/screen/BuilderScreen.js +4 -3
- package/dist/admin/server/BuilderView.js +10 -3
- package/dist/admin/templateConditions.scss +24 -0
- package/dist/ai/adapters/anthropic.js +17 -4
- package/dist/ai/adapters/cloudflare-gateway.js +7 -1
- package/dist/ai/adapters/cloudflare-workers-ai.js +2 -0
- package/dist/ai/adapters/openai-compatible.js +1 -0
- package/dist/ai/adapters/openrouter.js +2 -0
- package/dist/ai/config.d.ts +24 -4
- package/dist/ai/config.js +27 -8
- package/dist/ai/endpoint.d.ts +5 -2
- package/dist/ai/endpoint.js +31 -26
- package/dist/ai/images/cloudflare-workers-ai.js +6 -2
- package/dist/ai/images/openai.js +8 -3
- package/dist/ai/images/openrouter.js +6 -2
- package/dist/ai/images/service.d.ts +10 -4
- package/dist/ai/images/service.js +23 -7
- package/dist/ai/openai-format.d.ts +7 -0
- package/dist/ai/openai-format.js +17 -5
- package/dist/ai/prompt.d.ts +8 -0
- package/dist/ai/prompt.js +25 -5
- package/dist/ai/settings/index.d.ts +62 -0
- package/dist/ai/settings/index.js +264 -0
- package/dist/ai/settings/secret.d.ts +11 -0
- package/dist/ai/settings/secret.js +46 -0
- package/dist/ai/settings/shared.d.ts +22 -0
- package/dist/ai/settings/shared.js +3 -0
- package/dist/ai/tools.d.ts +3 -0
- package/dist/ai/tools.js +79 -15
- package/dist/ai/types.d.ts +43 -0
- package/dist/blocks/builtins/adjacentLinks.d.ts +5 -0
- package/dist/blocks/builtins/adjacentLinks.js +76 -0
- package/dist/blocks/builtins/carousel.d.ts +2 -29
- package/dist/blocks/builtins/carousel.js +44 -51
- package/dist/blocks/builtins/disclosure.d.ts +2 -1
- package/dist/blocks/builtins/disclosure.js +22 -32
- package/dist/blocks/builtins/embed.d.ts +15 -0
- package/dist/blocks/builtins/embed.js +47 -0
- package/dist/blocks/builtins/faq.d.ts +1 -1
- package/dist/blocks/builtins/faq.js +2 -2
- package/dist/blocks/builtins/filterLink.d.ts +1 -19
- package/dist/blocks/builtins/filterLink.js +9 -50
- package/dist/blocks/builtins/icon.d.ts +2 -0
- package/dist/blocks/builtins/icon.js +8 -8
- package/dist/blocks/builtins/index.d.ts +18 -13
- package/dist/blocks/builtins/index.js +43 -22
- package/dist/blocks/builtins/marquee.d.ts +5 -0
- package/dist/blocks/builtins/marquee.js +68 -0
- package/dist/blocks/builtins/popup.d.ts +5 -0
- package/dist/blocks/builtins/popup.js +83 -0
- package/dist/blocks/builtins/sectionRef.d.ts +16 -2
- package/dist/blocks/builtins/sectionRef.js +34 -12
- package/dist/blocks/builtins/shared.d.ts +18 -23
- package/dist/blocks/builtins/shared.js +34 -42
- package/dist/blocks/builtins/tableOfContents.d.ts +4 -0
- package/dist/blocks/builtins/tableOfContents.js +12 -18
- package/dist/blocks/builtins/tabs.d.ts +6 -0
- package/dist/blocks/builtins/tabs.js +87 -0
- package/dist/blocks/client/adjacentLinks.d.ts +4 -0
- package/dist/blocks/client/adjacentLinks.js +4 -0
- package/dist/blocks/client/carousel.d.ts +45 -0
- package/dist/blocks/client/carousel.js +53 -0
- package/dist/blocks/client/embed.d.ts +21 -0
- package/dist/blocks/client/embed.js +23 -0
- package/dist/blocks/client/field.d.ts +7 -0
- package/dist/blocks/client/field.js +8 -0
- package/dist/blocks/client/filterLink.d.ts +19 -0
- package/dist/blocks/client/filterLink.js +30 -0
- package/dist/blocks/client/helpers.d.ts +21 -0
- package/dist/blocks/client/helpers.js +24 -0
- package/dist/blocks/client/marquee.d.ts +14 -0
- package/dist/blocks/client/marquee.js +25 -0
- package/dist/blocks/client/menu.d.ts +46 -0
- package/dist/blocks/client/menu.js +49 -0
- package/dist/blocks/client/popup.d.ts +15 -0
- package/dist/blocks/client/popup.js +16 -0
- package/dist/blocks/client/tabs.d.ts +10 -0
- package/dist/blocks/client/tabs.js +11 -0
- package/dist/blocks/defaults.d.ts +15 -52
- package/dist/blocks/defaults.js +203 -437
- package/dist/blocks/index.d.ts +1 -2
- package/dist/blocks/index.js +1 -2
- package/dist/classes/actions.d.ts +97 -0
- package/dist/classes/actions.js +296 -0
- package/dist/classes/collection.d.ts +5 -0
- package/dist/classes/collection.js +189 -0
- package/dist/classes/config.d.ts +34 -0
- package/dist/classes/config.js +8 -0
- package/dist/classes/endpoints.d.ts +2 -0
- package/dist/classes/endpoints.js +120 -0
- package/dist/classes/index.d.ts +36 -0
- package/dist/classes/index.js +42 -0
- package/dist/classes/mcp.d.ts +6 -0
- package/dist/classes/mcp.js +161 -0
- package/dist/classes/shared.d.ts +131 -0
- package/dist/classes/shared.js +300 -0
- package/dist/classes/sheet.d.ts +34 -0
- package/dist/classes/sheet.js +126 -0
- package/dist/classes/usage.d.ts +57 -0
- package/dist/classes/usage.js +208 -0
- package/dist/comments/collection.d.ts +38 -0
- package/dist/comments/collection.js +226 -0
- package/dist/comments/config.d.ts +15 -0
- package/dist/comments/config.js +2 -0
- package/dist/comments/index.d.ts +20 -0
- package/dist/comments/index.js +22 -0
- package/dist/comments/shared.d.ts +54 -0
- package/dist/comments/shared.js +104 -0
- package/dist/core/bindings.d.ts +77 -32
- package/dist/core/bindings.js +319 -134
- package/dist/core/blockNames.d.ts +9 -0
- package/dist/core/blockNames.js +11 -0
- package/dist/core/blocks.d.ts +21 -8
- package/dist/core/blocks.js +37 -16
- package/dist/core/classes.d.ts +16 -8
- package/dist/core/classes.js +31 -27
- package/dist/core/components.d.ts +72 -0
- package/dist/core/components.js +294 -0
- package/dist/core/contentMode.d.ts +27 -0
- package/dist/core/contentMode.js +0 -0
- package/dist/core/dropTarget.d.ts +11 -0
- package/dist/core/dropTarget.js +24 -1
- package/dist/core/fields.d.ts +5 -0
- package/dist/core/fields.js +11 -0
- package/dist/core/headings.d.ts +5 -2
- package/dist/core/headings.js +14 -6
- package/dist/core/index.d.ts +8 -3
- package/dist/core/index.js +8 -3
- package/dist/core/layers.d.ts +9 -0
- package/dist/core/layers.js +29 -0
- package/dist/core/operations.d.ts +6 -0
- package/dist/core/operations.js +85 -24
- package/dist/core/payloadBlocks.js +5 -1
- package/dist/core/references.js +28 -0
- package/dist/core/schema.js +20 -6
- package/dist/core/sectionOrigin.d.ts +6 -0
- package/dist/core/sectionOrigin.js +21 -0
- package/dist/core/sections.d.ts +72 -0
- package/dist/core/sections.js +331 -0
- package/dist/core/templateChoice.d.ts +24 -0
- package/dist/core/templateChoice.js +43 -0
- package/dist/core/tree.js +18 -6
- package/dist/core/types.d.ts +148 -18
- package/dist/core/validate.d.ts +4 -1
- package/dist/core/validate.js +28 -11
- package/dist/core/visibility.d.ts +63 -0
- package/dist/core/visibility.js +214 -0
- package/dist/core/whereValues.d.ts +22 -0
- package/dist/core/whereValues.js +43 -0
- package/dist/css/classes.d.ts +16 -0
- package/dist/css/classes.js +172 -0
- package/dist/css/index.d.ts +32 -1
- package/dist/css/index.js +64 -5
- package/dist/css/tokens.d.ts +10 -0
- package/dist/css/tokens.js +23 -10
- package/dist/index.d.ts +5 -2
- package/dist/index.js +6 -1
- package/dist/live/contentMode.d.ts +24 -0
- package/dist/live/contentMode.js +39 -0
- package/dist/live/endpoints.js +3 -0
- package/dist/live/session.d.ts +5 -0
- package/dist/live/session.js +8 -0
- package/dist/live/types.d.ts +16 -1
- package/dist/mcp/index.d.ts +10 -1
- package/dist/mcp/index.js +146 -54
- package/dist/mcp/shared.d.ts +93 -3
- package/dist/mcp/shared.js +211 -15
- package/dist/plugin/hook.d.ts +7 -1
- package/dist/plugin/hook.js +30 -4
- package/dist/plugin/index.d.ts +19 -8
- package/dist/plugin/index.js +89 -20
- package/dist/plugin/links.d.ts +24 -0
- package/dist/plugin/links.js +27 -0
- package/dist/plugin/listCollections.d.ts +9 -7
- package/dist/plugin/listCollections.js +30 -21
- package/dist/plugin/sections.d.ts +14 -7
- package/dist/plugin/sections.js +69 -23
- package/dist/plugin/sectionsUsedIn.d.ts +6 -0
- package/dist/plugin/sectionsUsedIn.js +24 -0
- package/dist/plugin/templateEndpoint.d.ts +9 -0
- package/dist/plugin/templateEndpoint.js +49 -0
- package/dist/plugin/templates.js +23 -8
- package/dist/protocol/index.d.ts +16 -1
- package/dist/react/canvas/BuilderCanvas.js +144 -21
- package/dist/react/canvas/classes.d.ts +17 -0
- package/dist/react/canvas/classes.js +102 -0
- package/dist/react/canvas/controls.d.ts +31 -0
- package/dist/react/canvas/controls.js +75 -0
- package/dist/react/canvas/fetchDocs.d.ts +2 -2
- package/dist/react/canvas/fetchDocs.js +16 -8
- package/dist/react/canvas/measure.d.ts +9 -0
- package/dist/react/canvas/measure.js +106 -7
- package/dist/react/canvas/resolveLayout.d.ts +1 -1
- package/dist/react/canvas/resolveLayout.js +4 -3
- package/dist/react/canvas/thumbnail/ThumbnailCanvas.js +17 -4
- package/dist/react/classes/ClassesStyle.d.ts +27 -0
- package/dist/react/classes/ClassesStyle.js +27 -0
- package/dist/react/components/Button.d.ts +2 -11
- package/dist/react/components/Button.js +8 -43
- package/dist/react/components/CollectionList.d.ts +4 -1
- package/dist/react/components/CollectionList.js +10 -3
- package/dist/react/components/Container.d.ts +5 -2
- package/dist/react/components/Container.js +7 -4
- package/dist/react/components/Field.js +3 -14
- package/dist/react/components/Link.d.ts +1 -1
- package/dist/react/components/Link.js +5 -3
- package/dist/react/components/List.d.ts +1 -1
- package/dist/react/components/List.js +2 -2
- package/dist/react/components/Menu.d.ts +10 -1
- package/dist/react/components/Menu.js +39 -12
- package/dist/react/components/RichText.d.ts +3 -4
- package/dist/react/components/RichText.js +5 -5
- package/dist/react/components/builtins/Accordion.d.ts +4 -3
- package/dist/react/components/builtins/Accordion.js +6 -5
- package/dist/react/components/builtins/AdjacentLinks.d.ts +11 -0
- package/dist/react/components/builtins/AdjacentLinks.js +20 -0
- package/dist/react/components/builtins/Carousel.d.ts +21 -10
- package/dist/react/components/builtins/Carousel.js +175 -100
- package/dist/react/components/builtins/Disclosure.d.ts +4 -3
- package/dist/react/components/builtins/Disclosure.js +6 -5
- package/dist/react/components/builtins/Embed.d.ts +11 -0
- package/dist/react/components/builtins/Embed.js +23 -0
- package/dist/react/components/builtins/EmbedHtml.d.ts +15 -0
- package/dist/react/components/builtins/EmbedHtml.js +51 -0
- package/dist/react/components/builtins/EmbedPreview.d.ts +34 -0
- package/dist/react/components/builtins/EmbedPreview.js +105 -0
- package/dist/react/components/builtins/FilterLink.d.ts +1 -1
- package/dist/react/components/builtins/FilterLink.js +4 -4
- package/dist/react/components/builtins/Marquee.d.ts +8 -0
- package/dist/react/components/builtins/Marquee.js +15 -0
- package/dist/react/components/builtins/Popup.d.ts +26 -0
- package/dist/react/components/builtins/Popup.js +146 -0
- package/dist/react/components/builtins/SectionRef.d.ts +4 -3
- package/dist/react/components/builtins/SectionRef.js +9 -5
- package/dist/react/components/builtins/Tab.d.ts +7 -0
- package/dist/react/components/builtins/Tab.js +21 -0
- package/dist/react/components/builtins/TableOfContents.d.ts +17 -3
- package/dist/react/components/builtins/TableOfContents.js +22 -7
- package/dist/react/components/builtins/Tabs.d.ts +17 -0
- package/dist/react/components/builtins/Tabs.js +71 -0
- package/dist/react/components/builtins/index.d.ts +37 -20
- package/dist/react/components/builtins/index.js +54 -20
- package/dist/react/components/builtins/tabsContext.d.ts +12 -0
- package/dist/react/components/builtins/tabsContext.js +6 -0
- package/dist/react/components/index.js +11 -8
- package/dist/react/components/lazy.d.ts +32 -0
- package/dist/react/components/lazy.js +20 -0
- package/dist/react/components/lazyBlock.d.ts +17 -0
- package/dist/react/components/lazyBlock.js +23 -0
- package/dist/react/index.d.ts +6 -3
- package/dist/react/index.js +5 -2
- package/dist/react/render/RenderLayout.d.ts +9 -7
- package/dist/react/render/RenderLayout.js +96 -45
- package/dist/react/render/canvasMode.d.ts +13 -0
- package/dist/react/render/canvasMode.js +13 -0
- package/dist/react/render/canvasServer.js +4 -3
- package/dist/react/render/canvasServerTypes.d.ts +5 -0
- package/dist/react/render/lists.d.ts +36 -4
- package/dist/react/render/lists.js +132 -15
- package/dist/react/render/marks.d.ts +15 -0
- package/dist/react/render/marks.js +23 -0
- package/dist/react/render/payload.d.ts +8 -1
- package/dist/react/render/payload.js +12 -3
- package/dist/react/render/preview.d.ts +11 -0
- package/dist/react/render/preview.js +13 -0
- package/dist/react/render/relations.d.ts +10 -0
- package/dist/react/render/relations.js +39 -0
- package/dist/react/render/resolve.d.ts +8 -4
- package/dist/react/render/resolve.js +11 -5
- package/dist/react/render/reveal.d.ts +17 -0
- package/dist/react/render/reveal.js +39 -0
- package/dist/react/render/sections.d.ts +11 -5
- package/dist/react/render/sections.js +52 -24
- package/dist/react/render/templates.d.ts +47 -0
- package/dist/react/render/templates.js +139 -0
- package/dist/react/render/types.d.ts +62 -5
- package/dist/react/server.d.ts +2 -37
- package/dist/react/server.js +8 -133
- package/dist/react/theme/ThemeLiveLoader.d.ts +4 -0
- package/dist/react/theme/ThemeLiveLoader.js +5 -0
- package/dist/react/theme/ThemeStyle.js +1 -1
- package/dist/theme/admin/Variables.d.ts +11 -0
- package/dist/theme/admin/Variables.js +115 -0
- package/dist/theme/admin/fields.scss +113 -0
- package/dist/theme/client.d.ts +1 -0
- package/dist/theme/client.js +2 -0
- package/dist/theme/css.d.ts +6 -1
- package/dist/theme/css.js +12 -4
- package/dist/theme/global.js +83 -0
- package/dist/theme/index.d.ts +1 -0
- package/dist/theme/index.js +1 -0
- package/dist/theme/server.d.ts +15 -0
- package/dist/theme/server.js +43 -0
- package/dist/theme/usage.d.ts +23 -0
- package/dist/theme/usage.js +68 -0
- package/dist/theme/variables.d.ts +72 -0
- package/dist/theme/variables.js +231 -0
- package/package.json +4 -2
- package/dist/admin/editor/styles/SiteClasses.d.ts +0 -9
- package/dist/admin/editor/styles/SiteClasses.js +0 -31
- package/dist/blocks/builtins/headingId.d.ts +0 -15
- package/dist/blocks/builtins/headingId.js +0 -36
- package/dist/blocks/builtins/lightbox.d.ts +0 -43
- package/dist/blocks/builtins/lightbox.js +0 -93
- package/dist/blocks/builtins/mediaBackdrop.d.ts +0 -11
- package/dist/blocks/builtins/mediaBackdrop.js +0 -79
- package/dist/react/components/Quote.d.ts +0 -3
- package/dist/react/components/Quote.js +0 -12
- package/dist/react/components/Spacer.d.ts +0 -3
- package/dist/react/components/Spacer.js +0 -6
- package/dist/react/components/builtins/BackdropVideo.d.ts +0 -13
- package/dist/react/components/builtins/BackdropVideo.js +0 -16
- package/dist/react/components/builtins/Lightbox.d.ts +0 -45
- package/dist/react/components/builtins/Lightbox.js +0 -252
- package/dist/react/components/builtins/MediaBackdrop.d.ts +0 -14
- package/dist/react/components/builtins/MediaBackdrop.js +0 -61
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
// Where editable classes are used, and renaming or removing a class in every layout that uses it.
|
|
2
|
+
// Server-only.
|
|
3
|
+
//
|
|
4
|
+
// Class names live inside layout strings (`className`, `partClassName`), not in relationship
|
|
5
|
+
// fields, and a page may use a name before the class exists (import from the site's CSS), so the
|
|
6
|
+
// usage comes from a scan of the layouts (one query per builder collection, latest drafts, open
|
|
7
|
+
// live sessions first) instead of the references index. Changes go through each document's live
|
|
8
|
+
// session, the same path as people's edits: open editors see them at once, and the session saves
|
|
9
|
+
// a draft with Payload's hooks, access and versions.
|
|
10
|
+
import { normalizeLayout, walkBlocks } from '../core/tree.js';
|
|
11
|
+
import { actorFromUser } from '../live/apply.js';
|
|
12
|
+
import { canEditDesign } from '../live/contentMode.js';
|
|
13
|
+
import { builderConfigOf } from '../live/document.js';
|
|
14
|
+
import { DRAFT_NOT_READABLE_MESSAGE, liveReadProblem, withLiveReadCheck } from '../live/draftAccess.js';
|
|
15
|
+
import { sessionTargetOf } from '../live/endpoints.js';
|
|
16
|
+
import { liveRuntimeOf } from '../live/runtime.js';
|
|
17
|
+
import { RAW_LAYOUT_CONTEXT } from '../plugin/hook.js';
|
|
18
|
+
import { savedSectionsConfigOf } from '../plugin/sections.js';
|
|
19
|
+
import { classesConfigOf } from './config.js';
|
|
20
|
+
import { bareClass, classTokens, replaceClass, usesClass } from './shared.js';
|
|
21
|
+
/** The class names a block uses (its own classes and its parts'), without variant prefixes. */
|
|
22
|
+
function blockClassNames(block) {
|
|
23
|
+
const names = new Set();
|
|
24
|
+
for (const token of classTokens(block.className))
|
|
25
|
+
names.add(bareClass(token));
|
|
26
|
+
for (const value of Object.values(block.partClassName ?? {})) {
|
|
27
|
+
if (typeof value === 'string')
|
|
28
|
+
for (const token of classTokens(value))
|
|
29
|
+
names.add(bareClass(token));
|
|
30
|
+
}
|
|
31
|
+
return names;
|
|
32
|
+
}
|
|
33
|
+
/** Blocks per class name in one layout, for the names asked for. */
|
|
34
|
+
export function countClassUses(layout, names) {
|
|
35
|
+
const counts = new Map();
|
|
36
|
+
walkBlocks(layout, (block) => {
|
|
37
|
+
for (const name of blockClassNames(block))
|
|
38
|
+
if (names.has(name))
|
|
39
|
+
counts.set(name, (counts.get(name) ?? 0) + 1);
|
|
40
|
+
});
|
|
41
|
+
return counts;
|
|
42
|
+
}
|
|
43
|
+
/** The operations that rename (or with `to: null` remove) class `from` in a layout. */
|
|
44
|
+
export function replaceClassOps(layout, from, to) {
|
|
45
|
+
const ops = [];
|
|
46
|
+
walkBlocks(layout, (block) => {
|
|
47
|
+
if (usesClass(block.className, from))
|
|
48
|
+
ops.push({ type: 'update', id: block.id, className: replaceClass(block.className, from, to) || null });
|
|
49
|
+
const parts = Object.entries(block.partClassName ?? {}).filter(([, value]) => typeof value === 'string' && usesClass(value, from));
|
|
50
|
+
if (parts.length > 0) {
|
|
51
|
+
ops.push({ type: 'update', id: block.id, partClassName: Object.fromEntries(parts.map(([part, value]) => [part, replaceClass(value, from, to) || null])) });
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
return ops;
|
|
55
|
+
}
|
|
56
|
+
const configOf = (req, collection) => req.payload.collections[collection]?.config;
|
|
57
|
+
/**
|
|
58
|
+
* Every layout of the builder collections (JSON layouts; a Payload blocks field holds no classes):
|
|
59
|
+
* the latest drafts, with the open live session's layout instead where one is open. `asUser`:
|
|
60
|
+
* only the documents the request's user may read. `published`: the published layouts instead (what
|
|
61
|
+
* the live site renders; a collection without drafts: every document), saved sections left out.
|
|
62
|
+
*/
|
|
63
|
+
export async function scanLayouts(req, asUser, published = false) {
|
|
64
|
+
const builder = builderConfigOf(req.payload);
|
|
65
|
+
if (!builder)
|
|
66
|
+
return [];
|
|
67
|
+
const sessions = liveRuntimeOf(req.payload).sessions;
|
|
68
|
+
const sectionsSlug = savedSectionsConfigOf(req.payload)?.slug ?? null;
|
|
69
|
+
const out = [];
|
|
70
|
+
for (const [collection, options] of Object.entries(builder.collections)) {
|
|
71
|
+
if (options.payloadBlocks)
|
|
72
|
+
continue;
|
|
73
|
+
const config = configOf(req, collection);
|
|
74
|
+
if (!config)
|
|
75
|
+
continue;
|
|
76
|
+
// The site never renders a saved section on its own.
|
|
77
|
+
if (published && collection === sectionsSlug)
|
|
78
|
+
continue;
|
|
79
|
+
// Saved sections keep their blocks in `blocks`; the builder's `layout` there is virtual.
|
|
80
|
+
const field = collection === sectionsSlug ? 'blocks' : options.field;
|
|
81
|
+
const drafts = Boolean(config.versions?.drafts);
|
|
82
|
+
const title = config.admin?.useAsTitle && config.admin.useAsTitle !== 'id' ? config.admin.useAsTitle : null;
|
|
83
|
+
const result = await req.payload.find({
|
|
84
|
+
collection: collection,
|
|
85
|
+
depth: 0,
|
|
86
|
+
pagination: false,
|
|
87
|
+
draft: drafts && !published,
|
|
88
|
+
...(published && drafts ? { where: { _status: { equals: 'published' } } } : {}),
|
|
89
|
+
select: { [field]: true, ...(title ? { [title]: true } : {}) },
|
|
90
|
+
context: { [RAW_LAYOUT_CONTEXT]: true },
|
|
91
|
+
overrideAccess: !asUser,
|
|
92
|
+
...(asUser ? { user: req.user } : {}),
|
|
93
|
+
req,
|
|
94
|
+
});
|
|
95
|
+
for (const doc of result.docs) {
|
|
96
|
+
const id = doc.id;
|
|
97
|
+
const open = published ? undefined : sessions.peek(collection, id);
|
|
98
|
+
const stored = collection === sectionsSlug ? { version: 1, blocks: doc.blocks } : doc[field];
|
|
99
|
+
const name = title ? doc[title] : null;
|
|
100
|
+
out.push({ collection, id, title: typeof name === 'string' && name.trim() ? name.trim() : String(id), layout: open?.layout ?? normalizeLayout(stored) });
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return out;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Where each of `names` is used: blocks and documents. `asUser` (default true): only documents the
|
|
107
|
+
* request's user may read; the delete check counts every document.
|
|
108
|
+
*/
|
|
109
|
+
export async function classUsage(req, names, options = {}) {
|
|
110
|
+
const wanted = new Set(names);
|
|
111
|
+
const usage = Object.fromEntries([...wanted].map((name) => [name, { blocks: 0, documents: [] }]));
|
|
112
|
+
if (wanted.size === 0)
|
|
113
|
+
return usage;
|
|
114
|
+
for (const { collection, id, title, layout } of await scanLayouts(req, options.asUser ?? true)) {
|
|
115
|
+
for (const [name, blocks] of countClassUses(layout, wanted)) {
|
|
116
|
+
const entry = usage[name];
|
|
117
|
+
entry.blocks += blocks;
|
|
118
|
+
entry.documents.push({ collection, id, title, blocks });
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return usage;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* The published documents whose published layout uses one of `names` (the live site renders those
|
|
125
|
+
* layouts), as the request's user may read them. Each document once, with the block count.
|
|
126
|
+
*/
|
|
127
|
+
export async function publishedClassUsage(req, names) {
|
|
128
|
+
const wanted = new Set(names);
|
|
129
|
+
if (wanted.size === 0)
|
|
130
|
+
return [];
|
|
131
|
+
const out = [];
|
|
132
|
+
for (const { collection, id, title, layout } of await scanLayouts(req, true, true)) {
|
|
133
|
+
let blocks = 0;
|
|
134
|
+
for (const count of countClassUses(layout, wanted).values())
|
|
135
|
+
blocks += count;
|
|
136
|
+
if (blocks > 0)
|
|
137
|
+
out.push({ collection, id, title, blocks });
|
|
138
|
+
}
|
|
139
|
+
return out;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* The names among `names` that any layout uses: the latest drafts, open live sessions and the
|
|
143
|
+
* published layouts of every document (no access check: deleting must not miss a page).
|
|
144
|
+
*/
|
|
145
|
+
export async function usedClassNames(req, names) {
|
|
146
|
+
const wanted = new Set(names);
|
|
147
|
+
const used = new Set();
|
|
148
|
+
if (wanted.size === 0)
|
|
149
|
+
return used;
|
|
150
|
+
const [drafts, published] = await Promise.all([scanLayouts(req, false), scanLayouts(req, false, true)]);
|
|
151
|
+
for (const { layout } of [...drafts, ...published])
|
|
152
|
+
for (const name of countClassUses(layout, wanted).keys())
|
|
153
|
+
used.add(name);
|
|
154
|
+
return used;
|
|
155
|
+
}
|
|
156
|
+
const NOTHING = '__nothing_to_change__';
|
|
157
|
+
/**
|
|
158
|
+
* Renames class `from` to `to` (or removes it, with `to: null`) in every layout that uses it, as
|
|
159
|
+
* the request's user, through each document's live session. Documents the user may not update are
|
|
160
|
+
* reported in `failed`.
|
|
161
|
+
*/
|
|
162
|
+
export async function replaceClassInLayouts(req, from, to) {
|
|
163
|
+
const result = { documents: 0, blocks: 0, failed: [] };
|
|
164
|
+
const builder = builderConfigOf(req.payload);
|
|
165
|
+
if (!builder)
|
|
166
|
+
return result;
|
|
167
|
+
const runtime = liveRuntimeOf(req.payload);
|
|
168
|
+
const usage = (await classUsage(req, [from]))[from];
|
|
169
|
+
for (const doc of usage?.documents ?? []) {
|
|
170
|
+
const fail = (error) => result.failed.push({ collection: doc.collection, id: doc.id, title: doc.title, error });
|
|
171
|
+
const target = sessionTargetOf(req.payload, builder.collections, doc.collection, String(doc.id));
|
|
172
|
+
if (!target)
|
|
173
|
+
continue;
|
|
174
|
+
if (!(await runtime.canUpdate(req, doc.collection, doc.id))) {
|
|
175
|
+
fail('You may not edit this document.');
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
const stale = await liveReadProblem(req, target).catch(() => DRAFT_NOT_READABLE_MESSAGE);
|
|
179
|
+
if (stale) {
|
|
180
|
+
fail(stale);
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
let changed = 0;
|
|
184
|
+
const commit = await runtime.sessions.commit({
|
|
185
|
+
target,
|
|
186
|
+
store: req.payload,
|
|
187
|
+
user: req.user,
|
|
188
|
+
actor: actorFromUser(req.user),
|
|
189
|
+
ops: (layout) => {
|
|
190
|
+
const ops = replaceClassOps(layout, from, to);
|
|
191
|
+
changed = ops.length;
|
|
192
|
+
return ops.length > 0 ? ops : NOTHING;
|
|
193
|
+
},
|
|
194
|
+
blocks: classesConfigOf(req.payload)?.blocks ?? [],
|
|
195
|
+
localization: builder.collections[doc.collection]?.localization ?? null,
|
|
196
|
+
contentOnly: !(await canEditDesign(req)),
|
|
197
|
+
access: withLiveReadCheck(req, target),
|
|
198
|
+
});
|
|
199
|
+
if (commit.ok) {
|
|
200
|
+
result.documents++;
|
|
201
|
+
result.blocks += changed;
|
|
202
|
+
}
|
|
203
|
+
else if (commit.error !== NOTHING) {
|
|
204
|
+
fail(commit.error);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return result;
|
|
208
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type CollectionConfig } from 'payload';
|
|
2
|
+
import type { CommentsOptions } from './config.js';
|
|
3
|
+
/** What a save does, decided from plain values. Pure, so the rules are tested without Payload. */
|
|
4
|
+
export type CommentWrite = {
|
|
5
|
+
operation: 'create' | 'update';
|
|
6
|
+
data: Record<string, unknown>;
|
|
7
|
+
/** The stored comment (updates). */
|
|
8
|
+
original?: Record<string, unknown> | null;
|
|
9
|
+
/** The thread a new reply answers. Undefined when `data.parent` is empty; null when it is not found. */
|
|
10
|
+
parent?: Record<string, unknown> | null;
|
|
11
|
+
user: unknown;
|
|
12
|
+
/** The builder collections. */
|
|
13
|
+
collections: readonly string[];
|
|
14
|
+
/** The author's auth collection is this one: `author` links to the user. */
|
|
15
|
+
userSlug: string | null;
|
|
16
|
+
now: string;
|
|
17
|
+
};
|
|
18
|
+
export type CommentWriteResult = {
|
|
19
|
+
ok: true;
|
|
20
|
+
data: Record<string, unknown>;
|
|
21
|
+
target: {
|
|
22
|
+
collection: string;
|
|
23
|
+
id: string;
|
|
24
|
+
};
|
|
25
|
+
} | {
|
|
26
|
+
ok: false;
|
|
27
|
+
status: 400 | 403;
|
|
28
|
+
error: string;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* The data to store, and the document whose update access the user needs. A new comment gets its
|
|
32
|
+
* author from the user; a reply takes its document from its thread. On updates, only the text
|
|
33
|
+
* (by its author) and the resolved state (of a thread) change.
|
|
34
|
+
*/
|
|
35
|
+
export declare function commentWrite(input: CommentWrite): CommentWriteResult;
|
|
36
|
+
export declare function commentsCollection(slug: string, options: CommentsOptions | undefined, args: {
|
|
37
|
+
userSlug: string | null;
|
|
38
|
+
}): CollectionConfig;
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
// The comments collection: one document per comment. A thread is a comment on a block; replies
|
|
2
|
+
// point to their thread. The editor reads and writes it over Payload's REST API, and every save or
|
|
3
|
+
// delete goes out on the document's live channel (`comments` events). Comments never touch the
|
|
4
|
+
// layout, its undo history, saves or publishing.
|
|
5
|
+
import { APIError, parseDocumentID, } from 'payload';
|
|
6
|
+
import { builderConfigOf } from '../live/document.js';
|
|
7
|
+
import { liveRuntimeOf } from '../live/runtime.js';
|
|
8
|
+
import { collaboratorName } from '../live/session.js';
|
|
9
|
+
import { authorKeyOf, COMMENT_MAX, toComment } from './shared.js';
|
|
10
|
+
/** Fields a save never changes after the comment exists: where it is and who wrote it. */
|
|
11
|
+
const FIXED_FIELDS = ['docCollection', 'docId', 'parent', 'blockId', 'x', 'y', 'author', 'authorKey', 'authorName'];
|
|
12
|
+
const signedIn = ({ req }) => Boolean(req.user);
|
|
13
|
+
/** Only the author deletes a comment (a thread's replies go with it). */
|
|
14
|
+
const ownComment = ({ req }) => {
|
|
15
|
+
const key = authorKeyOf(req.user);
|
|
16
|
+
return key ? { authorKey: { equals: key } } : false;
|
|
17
|
+
};
|
|
18
|
+
const str = (value) => (typeof value === 'string' || typeof value === 'number' ? String(value) : '');
|
|
19
|
+
/**
|
|
20
|
+
* The data to store, and the document whose update access the user needs. A new comment gets its
|
|
21
|
+
* author from the user; a reply takes its document from its thread. On updates, only the text
|
|
22
|
+
* (by its author) and the resolved state (of a thread) change.
|
|
23
|
+
*/
|
|
24
|
+
export function commentWrite(input) {
|
|
25
|
+
const { operation, user, now } = input;
|
|
26
|
+
const data = { ...input.data };
|
|
27
|
+
if (typeof data.body === 'string')
|
|
28
|
+
data.body = data.body.trim();
|
|
29
|
+
if (operation === 'create') {
|
|
30
|
+
const key = authorKeyOf(user);
|
|
31
|
+
if (!key)
|
|
32
|
+
return { ok: false, status: 403, error: 'Sign in to comment.' };
|
|
33
|
+
if (!data.body)
|
|
34
|
+
return { ok: false, status: 400, error: 'Write a comment.' };
|
|
35
|
+
data.authorKey = key;
|
|
36
|
+
data.authorName = collaboratorName(user);
|
|
37
|
+
const u = user;
|
|
38
|
+
if (input.userSlug)
|
|
39
|
+
data.author = u.collection === input.userSlug ? u.id : null;
|
|
40
|
+
data.resolved = false;
|
|
41
|
+
data.resolvedByName = null;
|
|
42
|
+
data.resolvedAt = null;
|
|
43
|
+
data.editedAt = null;
|
|
44
|
+
if (input.parent !== undefined) {
|
|
45
|
+
const parent = input.parent;
|
|
46
|
+
if (!parent || parent.parent)
|
|
47
|
+
return { ok: false, status: 400, error: 'Reply to a thread that exists.' };
|
|
48
|
+
data.docCollection = parent.docCollection;
|
|
49
|
+
data.docId = parent.docId;
|
|
50
|
+
data.blockId = null;
|
|
51
|
+
data.x = null;
|
|
52
|
+
data.y = null;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
data.parent = null;
|
|
56
|
+
if (!input.collections.includes(str(data.docCollection)))
|
|
57
|
+
return { ok: false, status: 400, error: 'Comment on a builder document.' };
|
|
58
|
+
if (!str(data.docId) || !str(data.blockId))
|
|
59
|
+
return { ok: false, status: 400, error: 'Comment on a block.' };
|
|
60
|
+
}
|
|
61
|
+
return { ok: true, data, target: { collection: str(data.docCollection), id: str(data.docId) } };
|
|
62
|
+
}
|
|
63
|
+
const original = input.original ?? {};
|
|
64
|
+
for (const field of FIXED_FIELDS) {
|
|
65
|
+
if (field in original)
|
|
66
|
+
data[field] = original[field];
|
|
67
|
+
else
|
|
68
|
+
delete data[field];
|
|
69
|
+
}
|
|
70
|
+
const key = authorKeyOf(user);
|
|
71
|
+
if (typeof data.body === 'string' && data.body !== original.body) {
|
|
72
|
+
if (!key || key !== original.authorKey)
|
|
73
|
+
return { ok: false, status: 403, error: 'Only the author can change a comment.' };
|
|
74
|
+
if (!data.body)
|
|
75
|
+
return { ok: false, status: 400, error: 'Write a comment.' };
|
|
76
|
+
data.editedAt = now;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
data.body = original.body;
|
|
80
|
+
data.editedAt = original.editedAt ?? null;
|
|
81
|
+
}
|
|
82
|
+
if (typeof data.resolved === 'boolean' && data.resolved !== (original.resolved === true)) {
|
|
83
|
+
if (original.parent)
|
|
84
|
+
return { ok: false, status: 400, error: 'Resolve the thread, not a reply.' };
|
|
85
|
+
data.resolvedByName = data.resolved ? collaboratorName(user) : null;
|
|
86
|
+
data.resolvedAt = data.resolved ? now : null;
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
data.resolved = original.resolved === true;
|
|
90
|
+
data.resolvedByName = original.resolvedByName ?? null;
|
|
91
|
+
data.resolvedAt = original.resolvedAt ?? null;
|
|
92
|
+
}
|
|
93
|
+
return { ok: true, data, target: { collection: str(original.docCollection), id: str(original.docId) } };
|
|
94
|
+
}
|
|
95
|
+
function fail(result) {
|
|
96
|
+
throw new APIError(result.error, result.status, null, true);
|
|
97
|
+
}
|
|
98
|
+
function broadcast(req, doc, event) {
|
|
99
|
+
const collection = str(doc.docCollection);
|
|
100
|
+
const id = str(doc.docId);
|
|
101
|
+
if (!collection || !id)
|
|
102
|
+
return;
|
|
103
|
+
// Only editors with the document open hear it. The stream checks their read access per event.
|
|
104
|
+
liveRuntimeOf(req.payload).sessions.broadcast(collection, id, event);
|
|
105
|
+
}
|
|
106
|
+
/** Editors with the document open see the saved comment at once. */
|
|
107
|
+
const afterChange = ({ doc, req }) => {
|
|
108
|
+
const comment = toComment(doc);
|
|
109
|
+
if (comment)
|
|
110
|
+
broadcast(req, doc, { type: 'comments', change: 'saved', comment });
|
|
111
|
+
return doc;
|
|
112
|
+
};
|
|
113
|
+
/** Editors with the document open drop the comment at once. */
|
|
114
|
+
const afterDelete = ({ doc, id, req }) => {
|
|
115
|
+
broadcast(req, doc, { type: 'comments', change: 'deleted', id: String(id) });
|
|
116
|
+
return doc;
|
|
117
|
+
};
|
|
118
|
+
export function commentsCollection(slug, options = {}, args) {
|
|
119
|
+
// REST bodies carry ids as text; the relationship check wants the database's id type.
|
|
120
|
+
const beforeValidate = ({ data, req }) => {
|
|
121
|
+
if (data && (typeof data.parent === 'string' || typeof data.parent === 'number')) {
|
|
122
|
+
data.parent = parseDocumentID({ collectionSlug: slug, id: data.parent, payload: req.payload }) ?? data.parent;
|
|
123
|
+
}
|
|
124
|
+
return data;
|
|
125
|
+
};
|
|
126
|
+
const beforeChange = async ({ data, operation, originalDoc, req }) => {
|
|
127
|
+
// Server code without a user (seeds, jobs) writes as it likes.
|
|
128
|
+
if (!req.user || (operation !== 'create' && operation !== 'update'))
|
|
129
|
+
return data;
|
|
130
|
+
const parentId = operation === 'create' ? data.parent : undefined;
|
|
131
|
+
const parent = parentId === undefined || parentId === null || parentId === ''
|
|
132
|
+
? undefined
|
|
133
|
+
: (await req.payload.findByID({ collection: slug, id: parentId, depth: 0, overrideAccess: true, req }).catch(() => null));
|
|
134
|
+
const result = commentWrite({
|
|
135
|
+
operation,
|
|
136
|
+
data,
|
|
137
|
+
original: originalDoc,
|
|
138
|
+
parent,
|
|
139
|
+
user: req.user,
|
|
140
|
+
collections: Object.keys(builderConfigOf(req.payload)?.collections ?? {}),
|
|
141
|
+
userSlug: args.userSlug,
|
|
142
|
+
now: new Date().toISOString(),
|
|
143
|
+
});
|
|
144
|
+
if (!result.ok)
|
|
145
|
+
fail(result);
|
|
146
|
+
// Users who may change the document may comment on it, resolve and reply.
|
|
147
|
+
const { collection, id } = result.target;
|
|
148
|
+
const docId = parseDocumentID({ collectionSlug: collection, id, payload: req.payload }) ?? id;
|
|
149
|
+
if (!(await liveRuntimeOf(req.payload).canUpdate(req, collection, docId))) {
|
|
150
|
+
fail({ status: 403, error: 'You cannot comment on this page: you are not allowed to change it.' });
|
|
151
|
+
}
|
|
152
|
+
return result.data;
|
|
153
|
+
};
|
|
154
|
+
// A thread takes its replies with it. Before the delete: the database clears the replies'
|
|
155
|
+
// `parent` link when the thread goes, so afterwards they could not be found.
|
|
156
|
+
const beforeDelete = async ({ id, req }) => {
|
|
157
|
+
await req.payload.delete({ collection: slug, where: { parent: { equals: id } }, overrideAccess: true, req });
|
|
158
|
+
};
|
|
159
|
+
return {
|
|
160
|
+
slug,
|
|
161
|
+
labels: { singular: 'Comment', plural: 'Comments' },
|
|
162
|
+
access: { read: signedIn, create: signedIn, update: signedIn, delete: ownComment, ...options.access },
|
|
163
|
+
admin: {
|
|
164
|
+
useAsTitle: 'body',
|
|
165
|
+
defaultColumns: ['body', 'authorName', 'docCollection', 'resolved', 'createdAt'],
|
|
166
|
+
description: 'Comments people leave on blocks in the builder. Open the page in the builder to discuss and resolve them.',
|
|
167
|
+
...options.admin,
|
|
168
|
+
},
|
|
169
|
+
indexes: [{ fields: ['docCollection', 'docId'] }],
|
|
170
|
+
hooks: {
|
|
171
|
+
...options.hooks,
|
|
172
|
+
beforeValidate: [beforeValidate, ...(options.hooks?.beforeValidate ?? [])],
|
|
173
|
+
beforeChange: [beforeChange, ...(options.hooks?.beforeChange ?? [])],
|
|
174
|
+
afterChange: [afterChange, ...(options.hooks?.afterChange ?? [])],
|
|
175
|
+
beforeDelete: [beforeDelete, ...(options.hooks?.beforeDelete ?? [])],
|
|
176
|
+
afterDelete: [afterDelete, ...(options.hooks?.afterDelete ?? [])],
|
|
177
|
+
},
|
|
178
|
+
fields: [
|
|
179
|
+
{ name: 'body', label: 'Comment', type: 'textarea', required: true, maxLength: COMMENT_MAX },
|
|
180
|
+
{
|
|
181
|
+
name: 'parent',
|
|
182
|
+
label: 'Reply to',
|
|
183
|
+
type: 'relationship',
|
|
184
|
+
relationTo: slug,
|
|
185
|
+
index: true,
|
|
186
|
+
admin: { position: 'sidebar', readOnly: true },
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
name: 'resolved',
|
|
190
|
+
type: 'checkbox',
|
|
191
|
+
defaultValue: false,
|
|
192
|
+
admin: { position: 'sidebar' },
|
|
193
|
+
},
|
|
194
|
+
{ name: 'resolvedByName', label: 'Resolved by', type: 'text', admin: { position: 'sidebar', readOnly: true } },
|
|
195
|
+
{ name: 'resolvedAt', label: 'Resolved at', type: 'date', admin: { position: 'sidebar', readOnly: true } },
|
|
196
|
+
{
|
|
197
|
+
type: 'collapsible',
|
|
198
|
+
label: 'Where',
|
|
199
|
+
admin: { initCollapsed: true },
|
|
200
|
+
fields: [
|
|
201
|
+
{
|
|
202
|
+
type: 'row',
|
|
203
|
+
fields: [
|
|
204
|
+
{ name: 'docCollection', label: 'Collection', type: 'text', required: true, index: true, admin: { readOnly: true } },
|
|
205
|
+
{ name: 'docId', label: 'Document', type: 'text', required: true, index: true, admin: { readOnly: true } },
|
|
206
|
+
{ name: 'blockId', label: 'Block', type: 'text', admin: { readOnly: true } },
|
|
207
|
+
],
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
type: 'row',
|
|
211
|
+
fields: [
|
|
212
|
+
{ name: 'x', type: 'number', min: 0, max: 1, admin: { readOnly: true } },
|
|
213
|
+
{ name: 'y', type: 'number', min: 0, max: 1, admin: { readOnly: true } },
|
|
214
|
+
],
|
|
215
|
+
},
|
|
216
|
+
],
|
|
217
|
+
},
|
|
218
|
+
...(args.userSlug
|
|
219
|
+
? [{ name: 'author', type: 'relationship', relationTo: args.userSlug, admin: { position: 'sidebar', readOnly: true } }]
|
|
220
|
+
: []),
|
|
221
|
+
{ name: 'authorName', label: 'Author', type: 'text', admin: { position: 'sidebar', readOnly: true } },
|
|
222
|
+
{ name: 'authorKey', type: 'text', index: true, admin: { hidden: true } },
|
|
223
|
+
{ name: 'editedAt', label: 'Edited at', type: 'date', admin: { position: 'sidebar', readOnly: true } },
|
|
224
|
+
],
|
|
225
|
+
};
|
|
226
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { CollectionConfig } from 'payload';
|
|
2
|
+
export type CommentsOptions = {
|
|
3
|
+
/** Slug of the comments collection. Default "builder-comments". */
|
|
4
|
+
slug?: string;
|
|
5
|
+
/**
|
|
6
|
+
* Access control. Default: signed-in users read; users who may change a page comment on it,
|
|
7
|
+
* reply and resolve; authors edit their own text and delete their own comments.
|
|
8
|
+
* The update-access check of the page always runs (in a hook), also with your own `access`.
|
|
9
|
+
*/
|
|
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
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { CollectionConfig } from 'payload';
|
|
2
|
+
import type { CommentsOptions } from './config.js';
|
|
3
|
+
import { type CommentsClientConfig } from './shared.js';
|
|
4
|
+
export * from './shared.js';
|
|
5
|
+
export type { CommentsOptions } from './config.js';
|
|
6
|
+
export { commentWrite, commentsCollection, type CommentWrite, type CommentWriteResult } from './collection.js';
|
|
7
|
+
export type ResolvedComments = {
|
|
8
|
+
client: CommentsClientConfig;
|
|
9
|
+
collection: CollectionConfig;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* The comments collection and the editor's config, from the plugin's `comments` option (on by
|
|
13
|
+
* default; `false` turns it off). Throws on a slug clash.
|
|
14
|
+
*/
|
|
15
|
+
export declare function resolveComments(option: CommentsOptions | boolean | undefined, args: {
|
|
16
|
+
collections: readonly {
|
|
17
|
+
slug: string;
|
|
18
|
+
}[];
|
|
19
|
+
userSlug: string | undefined;
|
|
20
|
+
}): ResolvedComments | null;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Comments on the canvas: a plugin collection of comment threads on blocks. Server entry.
|
|
2
|
+
// See the README section "Comments on the canvas".
|
|
3
|
+
import { commentsCollection } from './collection.js';
|
|
4
|
+
import { DEFAULT_COMMENTS_SLUG } from './shared.js';
|
|
5
|
+
export * from './shared.js';
|
|
6
|
+
export { commentWrite, commentsCollection } from './collection.js';
|
|
7
|
+
/**
|
|
8
|
+
* The comments collection and the editor's config, from the plugin's `comments` option (on by
|
|
9
|
+
* default; `false` turns it off). Throws on a slug clash.
|
|
10
|
+
*/
|
|
11
|
+
export function resolveComments(option, args) {
|
|
12
|
+
if (option === false)
|
|
13
|
+
return null;
|
|
14
|
+
const options = option === true || option === undefined ? {} : option;
|
|
15
|
+
const slug = options.slug ?? DEFAULT_COMMENTS_SLUG;
|
|
16
|
+
if (args.collections.some((c) => c.slug === slug)) {
|
|
17
|
+
throw new Error(`[websiteBuilder] A collection named "${slug}" already exists. Set \`comments.slug\` to another name, or \`comments: false\`.`);
|
|
18
|
+
}
|
|
19
|
+
// `author` links to the admin's user collection when it exists now.
|
|
20
|
+
const userSlug = args.userSlug && args.collections.some((c) => c.slug === args.userSlug) ? args.userSlug : null;
|
|
21
|
+
return { client: { collection: slug }, collection: commentsCollection(slug, options, { userSlug }) };
|
|
22
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/** Default slug of the comments collection. */
|
|
2
|
+
export declare const DEFAULT_COMMENTS_SLUG = "builder-comments";
|
|
3
|
+
/** Server-only key in `config.custom` that holds `CommentsServerConfig`. */
|
|
4
|
+
export declare const COMMENTS_CONFIG_KEY = "websiteBuilderComments";
|
|
5
|
+
/** Longest comment text, in characters. */
|
|
6
|
+
export declare const COMMENT_MAX = 5000;
|
|
7
|
+
/** What the editor needs: the collection it reads and writes over Payload's REST API. */
|
|
8
|
+
export type CommentsClientConfig = {
|
|
9
|
+
collection: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* One comment as the editor and the live channel see it. A thread is a comment without `parent`;
|
|
13
|
+
* its replies point to it. Only a thread has a block, a pin position and a resolved state.
|
|
14
|
+
*/
|
|
15
|
+
export type BuilderComment = {
|
|
16
|
+
id: string;
|
|
17
|
+
/** The thread this comment replies to. Null for the thread's first comment. */
|
|
18
|
+
parent: string | null;
|
|
19
|
+
/** The block the pin is on. Null for replies. */
|
|
20
|
+
blockId: string | null;
|
|
21
|
+
/** The pin, relative to the block's box: 0..1 from its left and top edges. */
|
|
22
|
+
x: number;
|
|
23
|
+
y: number;
|
|
24
|
+
body: string;
|
|
25
|
+
/** Who wrote it: `<auth collection>:<user id>`. The author may edit and delete it. */
|
|
26
|
+
authorKey: string;
|
|
27
|
+
authorName: string;
|
|
28
|
+
resolved: boolean;
|
|
29
|
+
resolvedByName: string | null;
|
|
30
|
+
resolvedAt: string | null;
|
|
31
|
+
createdAt: string;
|
|
32
|
+
/** Set when the author changed the text. */
|
|
33
|
+
editedAt: string | null;
|
|
34
|
+
};
|
|
35
|
+
/** A thread: its first comment and the replies, oldest first. */
|
|
36
|
+
export type CommentThread = {
|
|
37
|
+
root: BuilderComment;
|
|
38
|
+
replies: BuilderComment[];
|
|
39
|
+
};
|
|
40
|
+
export type CommentFilter = 'all' | 'open' | 'resolved';
|
|
41
|
+
/** A stored comment document (depth 0 or more) as a `BuilderComment`. Null when it is not one. */
|
|
42
|
+
export declare function toComment(doc: unknown): BuilderComment | null;
|
|
43
|
+
/** The user's author key, as the server stores it: `<auth collection>:<id>`. */
|
|
44
|
+
export declare function authorKeyOf(user: unknown): string | null;
|
|
45
|
+
/** Adds the comment, or replaces the one with its id. Keeps the list in creation order. */
|
|
46
|
+
export declare function upsertComment(list: readonly BuilderComment[], comment: BuilderComment): BuilderComment[];
|
|
47
|
+
/** Removes the comment and, for a thread, its replies. */
|
|
48
|
+
export declare function removeComment(list: readonly BuilderComment[], id: string): BuilderComment[];
|
|
49
|
+
/** Open threads first (newest first), then resolved ones (newest resolved first). */
|
|
50
|
+
export declare function threadsOf(list: readonly BuilderComment[], filter?: CommentFilter): CommentThread[];
|
|
51
|
+
/** Number of open threads: the top bar's badge. */
|
|
52
|
+
export declare function openCount(list: readonly BuilderComment[]): number;
|
|
53
|
+
/** The REST query that lists one document's comments, oldest first. */
|
|
54
|
+
export declare function commentsQuery(collection: string, docId: string | number): string;
|