payload-canvas 0.3.0-next.1 → 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 +1010 -55
- 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/LayoutDiff.js +3 -3
- package/dist/admin/diff/changes.js +13 -0
- package/dist/admin/diff/layoutDiff.scss +48 -48
- package/dist/admin/editor/Canvas.js +20 -5
- package/dist/admin/editor/DragLayer.js +1 -1
- package/dist/admin/editor/Editor.d.ts +3 -1
- package/dist/admin/editor/Editor.js +6 -3
- package/dist/admin/editor/InlineToolbar.js +1 -1
- package/dist/admin/editor/Inspector.js +115 -23
- package/dist/admin/editor/Library.js +40 -15
- package/dist/admin/editor/Outline.js +26 -19
- package/dist/admin/editor/Overlay.js +9 -4
- package/dist/admin/editor/actions.d.ts +18 -2
- package/dist/admin/editor/actions.js +53 -3
- package/dist/admin/editor/assistant/AssistantPanel.js +4 -2
- package/dist/admin/editor/assistant/ConnectAgents.js +1 -1
- package/dist/admin/editor/assistant/assistant.scss +65 -65
- 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 +45 -2
- 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 +138 -183
- package/dist/admin/editor/empty/EmptyStart.js +21 -43
- package/dist/admin/editor/empty/empty.scss +3 -3
- 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 +4 -3
- 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/GroupField.d.ts +5 -2
- package/dist/admin/editor/fields/GroupField.js +6 -2
- 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 +25 -0
- package/dist/admin/editor/fields/WhereField.js +47 -0
- package/dist/admin/editor/fields/access.d.ts +1 -1
- 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 +346 -34
- 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 +27 -0
- package/dist/admin/editor/fields/whereRows.js +167 -0
- package/dist/admin/editor/generate/GenerateImage.js +1 -1
- package/dist/admin/editor/generate/generate.scss +48 -48
- package/dist/admin/editor/icons.d.ts +17 -1
- package/dist/admin/editor/icons.js +33 -2
- package/dist/admin/editor/inline.js +9 -0
- package/dist/admin/editor/insert/InsertHandle.js +5 -2
- 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/FrameResize.js +1 -1
- package/dist/admin/editor/layout/LeftPanel.js +12 -7
- package/dist/admin/editor/layout/layout.scss +4 -4
- package/dist/admin/editor/live/PresenceUI.js +1 -1
- package/dist/admin/editor/live/presence.scss +1 -1
- package/dist/admin/editor/live/useMultiplayer.js +9 -1
- package/dist/admin/editor/locale/LocaleField.d.ts +2 -2
- package/dist/admin/editor/locale/LocaleField.js +4 -2
- package/dist/admin/editor/locale/locale.scss +12 -12
- package/dist/admin/editor/media/ImageEditor.js +1 -1
- package/dist/admin/editor/media/media.scss +23 -23
- package/dist/admin/editor/menu/Menu.js +1 -1
- package/dist/admin/editor/menu/blockMenu.js +32 -18
- package/dist/admin/editor/menu/menu.scss +16 -16
- package/dist/admin/editor/motion/MotionPanel.js +2 -2
- package/dist/admin/editor/motion/model.d.ts +2 -2
- package/dist/admin/editor/motion/model.js +2 -2
- package/dist/admin/editor/motion/motion.scss +2 -2
- package/dist/admin/editor/names.js +11 -3
- package/dist/admin/editor/regions/RegionOverlay.js +1 -1
- package/dist/admin/editor/regions/RegionPane.js +1 -1
- package/dist/admin/editor/renderField.d.ts +5 -1
- package/dist/admin/editor/renderField.js +73 -13
- package/dist/admin/editor/runtime.d.ts +14 -0
- package/dist/admin/editor/runtime.js +68 -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 +6 -3
- 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 -1
- package/dist/admin/editor/styles/StylesPanel.js +53 -11
- package/dist/admin/editor/styles/VariantBar.js +3 -3
- 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 +24 -4
- package/dist/admin/editor/styles/context.js +32 -9
- package/dist/admin/editor/styles/controls.d.ts +3 -1
- package/dist/admin/editor/styles/controls.js +31 -13
- package/dist/admin/editor/styles/popover.d.ts +6 -0
- package/dist/admin/editor/styles/popover.js +5 -5
- package/dist/admin/editor/styles/sections.js +2 -2
- package/dist/admin/editor/styles/styles.scss +115 -139
- 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.d.ts +14 -6
- package/dist/admin/editor/templates/Bindable.js +146 -61
- package/dist/admin/editor/templates/SamplePicker.js +2 -2
- 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 +11 -4
- package/dist/admin/editor/templates/binding.js +23 -3
- package/dist/admin/editor/templates/templates.scss +117 -90
- package/dist/admin/editor/templates/visibilityRows.d.ts +22 -0
- package/dist/admin/editor/templates/visibilityRows.js +83 -0
- package/dist/admin/editor/tooltip/tooltip.scss +4 -4
- 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 +6 -5
- package/dist/admin/editor/topbar/DocumentTitle.js +8 -3
- package/dist/admin/editor/topbar/TopBar.js +15 -3
- package/dist/admin/editor/topbar/contentMode.scss +35 -0
- package/dist/admin/editor/topbar/screens/DrawerRouter.d.ts +1 -1
- package/dist/admin/editor/topbar/screens/ScreenDrawer.js +1 -1
- package/dist/admin/editor/topbar/screens/drawerRouterSupport.d.ts +1 -1
- package/dist/admin/editor/topbar/screens/screens.scss +20 -20
- package/dist/admin/editor/topbar/settingsDrawer.js +3 -3
- package/dist/admin/editor/topbar/settingsDrawer.scss +7 -7
- package/dist/admin/editor/topbar/topbar.scss +50 -48
- package/dist/admin/editor/ui/Select.js +1 -1
- package/dist/admin/editor/ui/controls.scss +26 -26
- 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 +5 -4
- package/dist/admin/server/BuilderView.js +10 -3
- package/dist/admin/templateConditions.scss +24 -0
- package/dist/ai/adapters/anthropic.d.ts +2 -2
- 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 +24 -8
- package/dist/ai/loop.d.ts +5 -5
- 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 +30 -4
- 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 +83 -10
- 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 +5 -0
- package/dist/blocks/builtins/carousel.js +115 -0
- package/dist/blocks/builtins/disclosure.d.ts +14 -0
- package/dist/blocks/builtins/disclosure.js +97 -0
- package/dist/blocks/builtins/embed.d.ts +15 -0
- package/dist/blocks/builtins/embed.js +47 -0
- package/dist/blocks/builtins/faq.d.ts +17 -0
- package/dist/blocks/builtins/faq.js +88 -0
- package/dist/blocks/builtins/filterLink.d.ts +4 -0
- package/dist/blocks/builtins/filterLink.js +35 -0
- package/dist/blocks/builtins/icon.d.ts +10 -0
- package/dist/blocks/builtins/icon.js +45 -0
- package/dist/blocks/builtins/index.d.ts +40 -0
- package/dist/blocks/builtins/index.js +71 -0
- 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 +40 -0
- package/dist/blocks/builtins/sectionRef.js +100 -0
- package/dist/blocks/builtins/shared.d.ts +28 -0
- package/dist/blocks/builtins/shared.js +62 -0
- package/dist/blocks/builtins/tableOfContents.d.ts +7 -0
- package/dist/blocks/builtins/tableOfContents.js +38 -0
- 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 -34
- package/dist/blocks/defaults.js +339 -180
- package/dist/blocks/index.d.ts +4 -3
- package/dist/blocks/index.js +3 -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/attrs.d.ts +27 -0
- package/dist/core/attrs.js +132 -0
- package/dist/core/bindings.d.ts +171 -15
- package/dist/core/bindings.js +697 -27
- package/dist/core/blockNames.d.ts +9 -0
- package/dist/core/blockNames.js +11 -0
- package/dist/core/blocks.d.ts +62 -4
- package/dist/core/blocks.js +164 -7
- package/dist/core/classes.d.ts +18 -2
- package/dist/core/classes.js +37 -4
- 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/fieldAccess.js +1 -1
- package/dist/core/fieldHooks.d.ts +1 -1
- package/dist/core/fields.d.ts +5 -0
- package/dist/core/fields.js +11 -0
- package/dist/core/headings.d.ts +24 -0
- package/dist/core/headings.js +55 -0
- package/dist/core/index.d.ts +10 -3
- package/dist/core/index.js +10 -3
- package/dist/core/layers.d.ts +9 -0
- package/dist/core/layers.js +29 -0
- package/dist/core/motion.d.ts +24 -15
- package/dist/core/motion.js +20 -12
- package/dist/core/operations.d.ts +6 -0
- package/dist/core/operations.js +124 -6
- package/dist/core/payloadBlocks.js +7 -1
- package/dist/core/references.js +28 -0
- package/dist/core/schema.js +35 -1
- 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 +37 -2
- package/dist/core/types.d.ts +219 -2
- package/dist/core/validate.d.ts +4 -1
- package/dist/core/validate.js +48 -6
- 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 +14 -1
- package/dist/css/tokens.js +61 -2
- package/dist/index.d.ts +6 -3
- package/dist/index.js +7 -2
- package/dist/live/contentMode.d.ts +24 -0
- package/dist/live/contentMode.js +39 -0
- package/dist/live/draftAccess.js +1 -1
- package/dist/live/endpoints.js +3 -0
- package/dist/live/session.d.ts +6 -1
- package/dist/live/session.js +8 -0
- package/dist/live/storage.js +4 -2
- package/dist/live/types.d.ts +16 -1
- package/dist/mcp/index.d.ts +12 -1
- package/dist/mcp/index.js +177 -48
- package/dist/mcp/shared.d.ts +123 -30
- package/dist/mcp/shared.js +222 -11
- package/dist/plugin/hook.d.ts +7 -1
- package/dist/plugin/hook.js +30 -4
- package/dist/plugin/index.d.ts +27 -8
- package/dist/plugin/index.js +113 -26
- package/dist/plugin/links.d.ts +24 -0
- package/dist/plugin/links.js +27 -0
- package/dist/plugin/listCollections.d.ts +20 -3
- package/dist/plugin/listCollections.js +54 -8
- package/dist/plugin/references.d.ts +5 -0
- package/dist/plugin/references.js +1 -1
- 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.d.ts +4 -0
- package/dist/plugin/templates.js +42 -12
- package/dist/protocol/index.d.ts +19 -2
- package/dist/react/canvas/BuilderCanvas.js +149 -24
- 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 +17 -3
- package/dist/react/canvas/fetchDocs.js +51 -10
- package/dist/react/canvas/inline/rich/editor.js +1 -6
- package/dist/react/canvas/measure.d.ts +12 -1
- package/dist/react/canvas/measure.js +130 -7
- package/dist/react/canvas/resolveLayout.d.ts +1 -1
- package/dist/react/canvas/resolveLayout.js +19 -7
- package/dist/react/canvas/serverBlocks.d.ts +11 -0
- package/dist/react/canvas/serverBlocks.js +28 -1
- package/dist/react/canvas/thumbnail/ThumbnailCanvas.js +18 -5
- package/dist/react/classes/ClassesStyle.d.ts +27 -0
- package/dist/react/classes/ClassesStyle.js +27 -0
- package/dist/react/components/Button.d.ts +1 -1
- package/dist/react/components/Button.js +4 -2
- package/dist/react/components/CollectionList.d.ts +9 -3
- package/dist/react/components/CollectionList.js +28 -7
- package/dist/react/components/Container.d.ts +5 -2
- package/dist/react/components/Container.js +10 -4
- package/dist/react/components/Field.js +2 -2
- package/dist/react/components/Heading.js +9 -2
- package/dist/react/components/Image.d.ts +9 -0
- package/dist/react/components/Image.js +16 -1
- package/dist/react/components/Link.d.ts +1 -1
- package/dist/react/components/Link.js +5 -3
- package/dist/react/components/List.d.ts +2 -1
- package/dist/react/components/List.js +8 -2
- package/dist/react/components/Menu.d.ts +26 -1
- package/dist/react/components/Menu.js +116 -25
- package/dist/react/components/RichText.d.ts +6 -2
- package/dist/react/components/RichText.js +23 -2
- package/dist/react/components/builtins/Accordion.d.ts +10 -0
- package/dist/react/components/builtins/Accordion.js +38 -0
- 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 +24 -0
- package/dist/react/components/builtins/Carousel.js +209 -0
- package/dist/react/components/builtins/Disclosure.d.ts +8 -0
- package/dist/react/components/builtins/Disclosure.js +14 -0
- 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 +8 -0
- package/dist/react/components/builtins/FilterLink.js +30 -0
- package/dist/react/components/builtins/Icon.d.ts +14 -0
- package/dist/react/components/builtins/Icon.js +28 -0
- 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 +8 -0
- package/dist/react/components/builtins/SectionRef.js +21 -0
- 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 +21 -0
- package/dist/react/components/builtins/TableOfContents.js +36 -0
- package/dist/react/components/builtins/Tabs.d.ts +17 -0
- package/dist/react/components/builtins/Tabs.js +71 -0
- package/dist/react/components/builtins/glyphs.d.ts +8 -0
- package/dist/react/components/builtins/glyphs.js +7 -0
- package/dist/react/components/builtins/index.d.ts +49 -0
- package/dist/react/components/builtins/index.js +70 -0
- 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 +13 -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 +8 -3
- package/dist/react/index.js +7 -2
- package/dist/react/motion/runtime.js +10 -6
- package/dist/react/motion/style.js +1 -1
- package/dist/react/render/PayloadRoot.js +1 -1
- package/dist/react/render/RenderLayout.d.ts +9 -7
- package/dist/react/render/RenderLayout.js +145 -41
- 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 +139 -5
- package/dist/react/render/lists.js +401 -9
- 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 +26 -2
- package/dist/react/render/resolve.js +52 -25
- package/dist/react/render/reveal.d.ts +17 -0
- package/dist/react/render/reveal.js +39 -0
- package/dist/react/render/sections.d.ts +15 -0
- package/dist/react/render/sections.js +79 -0
- package/dist/react/render/templates.d.ts +47 -0
- package/dist/react/render/templates.js +139 -0
- package/dist/react/render/types.d.ts +66 -4
- package/dist/react/server.d.ts +3 -38
- package/dist/react/server.js +9 -86
- package/dist/react/theme/ThemeLiveLoader.d.ts +4 -0
- package/dist/react/theme/ThemeLiveLoader.js +5 -0
- package/dist/react/theme/ThemeStyle.d.ts +13 -2
- package/dist/react/theme/ThemeStyle.js +14 -4
- package/dist/theme/admin/ColorField.d.ts +2 -2
- package/dist/theme/admin/ColorField.js +2 -2
- package/dist/theme/admin/FontField.d.ts +2 -2
- package/dist/theme/admin/FontField.js +2 -2
- package/dist/theme/admin/SaveSignal.js +2 -2
- package/dist/theme/admin/Variables.d.ts +11 -0
- package/dist/theme/admin/Variables.js +115 -0
- package/dist/theme/admin/fields.scss +161 -48
- 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 +25 -28
- 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
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
// Comment mode on the canvas: a layer over the iframe that takes the pointer (a click places a
|
|
4
|
+
// pin on the block under it, the wheel still scrolls the page), the pins of the threads, and the
|
|
5
|
+
// popover with the composer or the open thread. Renders nothing outside comment mode, so the
|
|
6
|
+
// canvas does no comment work while people edit.
|
|
7
|
+
import { useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react';
|
|
8
|
+
import { createPortal } from 'react-dom';
|
|
9
|
+
import { deepestBlockAt } from '../../../core/index.js';
|
|
10
|
+
import { threadsOf } from '../../../comments/shared.js';
|
|
11
|
+
import { Icon } from '../icons.js';
|
|
12
|
+
import { cursorAt, cursorPoint } from '../live/presence.js';
|
|
13
|
+
import { toCanvasPoint, useRuntime } from '../runtime.js';
|
|
14
|
+
import { useEditor } from '../store.js';
|
|
15
|
+
import { useValue } from '../valueStore.js';
|
|
16
|
+
import { Avatar, CommentInput, Thread } from './Thread.js';
|
|
17
|
+
import './comments.scss';
|
|
18
|
+
const noSubscription = () => () => { };
|
|
19
|
+
const editorRoot = () => document.querySelector('.builder-editor');
|
|
20
|
+
const noRoot = () => null;
|
|
21
|
+
/** Space between the pin and its popover, and from the window edge, in screen pixels. */
|
|
22
|
+
const GAP = 10;
|
|
23
|
+
/** The pin's size on screen (`.builder-comment-pin`): the popover sits beside it, never over it. */
|
|
24
|
+
const PIN = 30;
|
|
25
|
+
const POPOVER_WIDTH = 300;
|
|
26
|
+
export function CommentLayer() {
|
|
27
|
+
const { comments } = useRuntime();
|
|
28
|
+
if (!comments)
|
|
29
|
+
return null;
|
|
30
|
+
return _jsx(ModeGate, { comments: comments });
|
|
31
|
+
}
|
|
32
|
+
function ModeGate({ comments }) {
|
|
33
|
+
const on = useValue(comments.mode);
|
|
34
|
+
return on ? _jsx(ModeLayer, { comments: comments }) : null;
|
|
35
|
+
}
|
|
36
|
+
function ModeLayer({ comments }) {
|
|
37
|
+
const runtime = useRuntime();
|
|
38
|
+
const measurement = useValue(runtime.measurement);
|
|
39
|
+
const list = useValue(comments.list);
|
|
40
|
+
const filter = useValue(comments.filter);
|
|
41
|
+
const draft = useValue(comments.draft);
|
|
42
|
+
const openId = useValue(comments.open);
|
|
43
|
+
const layout = useEditor(runtime.store, (s) => s.layout);
|
|
44
|
+
// The block under the pointer, by id: its outline follows the block when the page scrolls or changes.
|
|
45
|
+
const [hoveredId, setHoveredId] = useState(null);
|
|
46
|
+
const hovered = hoveredId ? (measurement?.blocks.find((b) => b.id === hoveredId)?.rect ?? null) : null;
|
|
47
|
+
const threads = useMemo(() => threadsOf(list, filter), [list, filter]);
|
|
48
|
+
const openThread = useMemo(() => (openId ? threadsOf(list).find((t) => t.root.id === openId) : undefined), [list, openId]);
|
|
49
|
+
const pointAt = (e) => {
|
|
50
|
+
const iframe = runtime.iframeRef.current;
|
|
51
|
+
return iframe ? toCanvasPoint(iframe, { x: e.clientX, y: e.clientY }) : null;
|
|
52
|
+
};
|
|
53
|
+
const onMove = (e) => {
|
|
54
|
+
const p = pointAt(e);
|
|
55
|
+
setHoveredId(p && measurement ? deepestBlockAt(layout, measurement, p) : null);
|
|
56
|
+
};
|
|
57
|
+
const onClick = (e) => {
|
|
58
|
+
const p = pointAt(e);
|
|
59
|
+
if (!p || !measurement)
|
|
60
|
+
return;
|
|
61
|
+
const cursor = cursorAt(layout, measurement, p);
|
|
62
|
+
// Over the page background, not a block: close what is open.
|
|
63
|
+
if (!cursor.blockId) {
|
|
64
|
+
comments.draft.set(null);
|
|
65
|
+
comments.open.set(null);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
// A click while a thread or the composer is open only closes it.
|
|
69
|
+
if (comments.draft.get() || comments.open.get()) {
|
|
70
|
+
comments.draft.set(null);
|
|
71
|
+
comments.open.set(null);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
comments.place(cursor);
|
|
75
|
+
};
|
|
76
|
+
const pinAt = (blockId, x, y) => (measurement && blockId ? cursorPoint(measurement, { blockId, x, y }) : null);
|
|
77
|
+
const draftPoint = draft ? pinAt(draft.blockId, draft.x, draft.y) : null;
|
|
78
|
+
const openPoint = openThread ? pinAt(openThread.root.blockId, openThread.root.x, openThread.root.y) : null;
|
|
79
|
+
return (_jsxs("div", { className: "builder-comments-layer", children: [_jsx("div", { className: "builder-comments-layer__capture", "aria-label": "Click a block to comment", onPointerMove: onMove, onPointerLeave: () => setHoveredId(null), onPointerDown: (e) => {
|
|
80
|
+
if (e.button !== 0)
|
|
81
|
+
return;
|
|
82
|
+
// The composer focuses its text box as it opens; the default mousedown would take focus back.
|
|
83
|
+
e.preventDefault();
|
|
84
|
+
onClick(e);
|
|
85
|
+
}, onWheel: (e) => runtime.postToCanvas({ type: 'scrollBy', dx: e.deltaX, dy: e.deltaY }) }), hovered && (_jsx("div", { className: "builder-comments-layer__hover", style: { left: hovered.x, top: hovered.y, width: hovered.width, height: hovered.height } })), threads.map((thread) => {
|
|
86
|
+
const point = pinAt(thread.root.blockId, thread.root.x, thread.root.y);
|
|
87
|
+
if (!point)
|
|
88
|
+
return null;
|
|
89
|
+
return _jsx(Pin, { thread: thread, point: point, open: thread.root.id === openId, comments: comments }, thread.root.id);
|
|
90
|
+
}), draftPoint && (_jsx("span", { className: "builder-comment-pin builder-comment-pin--draft", style: { left: draftPoint.x, top: draftPoint.y }, "aria-hidden": true, children: _jsx(Icon, { name: "plus", size: 12 }) })), draft && draftPoint && (_jsx(Popover, { runtime: runtime, point: draftPoint, label: "New comment", onClose: () => comments.draft.set(null), children: _jsx("div", { className: "builder-thread builder-thread--new", children: _jsx(CommentInput, { placeholder: "Add a comment", submitLabel: "Comment", focusOnMount: true, onCancel: () => comments.draft.set(null), onSubmit: (body) => comments.create(body) }) }) })), openThread && openPoint && (_jsx(Popover, { runtime: runtime, point: openPoint, label: "Comment thread", onClose: () => comments.open.set(null), children: _jsx(Thread, { thread: openThread, comments: comments, onClose: () => comments.open.set(null) }) }))] }));
|
|
91
|
+
}
|
|
92
|
+
function Pin({ thread, point, open, comments }) {
|
|
93
|
+
const { root, replies } = thread;
|
|
94
|
+
const classes = ['builder-comment-pin', open && 'builder-comment-pin--open', root.resolved && 'builder-comment-pin--resolved'].filter(Boolean).join(' ');
|
|
95
|
+
return (_jsx("button", { type: "button", className: classes, style: { left: point.x, top: point.y }, "aria-label": `Comment by ${root.authorName}${replies.length ? `, ${replies.length} ${replies.length === 1 ? 'reply' : 'replies'}` : ''}`, "aria-expanded": open, onClick: () => {
|
|
96
|
+
comments.draft.set(null);
|
|
97
|
+
comments.open.set(open ? null : root.id);
|
|
98
|
+
}, children: root.resolved ? _jsx(Icon, { name: "check", size: 12 }) : _jsx(Avatar, { name: root.authorName }) }));
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The composer or the thread next to its pin, in the editor root (outside the zoomed frame, so it
|
|
102
|
+
* keeps its size). Hidden while the pin is scrolled out of the canvas.
|
|
103
|
+
*/
|
|
104
|
+
function Popover({ runtime, point, label, onClose, children }) {
|
|
105
|
+
const host = useSyncExternalStore(noSubscription, editorRoot, noRoot);
|
|
106
|
+
const ref = useRef(null);
|
|
107
|
+
// Escape inside the popover closes it (a text box that cancels an edit handles it first).
|
|
108
|
+
useEffect(() => {
|
|
109
|
+
const el = ref.current;
|
|
110
|
+
if (!el)
|
|
111
|
+
return;
|
|
112
|
+
const onKey = (e) => {
|
|
113
|
+
if (e.key !== 'Escape' || e.defaultPrevented)
|
|
114
|
+
return;
|
|
115
|
+
e.preventDefault();
|
|
116
|
+
e.stopPropagation();
|
|
117
|
+
onClose();
|
|
118
|
+
};
|
|
119
|
+
el.addEventListener('keydown', onKey);
|
|
120
|
+
return () => el.removeEventListener('keydown', onKey);
|
|
121
|
+
}, [onClose]);
|
|
122
|
+
const iframe = runtime.iframeRef.current;
|
|
123
|
+
const box = iframe?.getBoundingClientRect();
|
|
124
|
+
const scale = iframe && box && iframe.offsetWidth ? box.width / iframe.offsetWidth : 1;
|
|
125
|
+
const screen = box ? { x: box.left + point.x * scale, y: box.top + point.y * scale } : null;
|
|
126
|
+
const visible = Boolean(box && screen && screen.y >= box.top && screen.y <= box.bottom && screen.x >= box.left && screen.x <= box.right);
|
|
127
|
+
// Right of the pin when it fits, else left. Kept inside the window vertically.
|
|
128
|
+
useLayoutEffect(() => {
|
|
129
|
+
const el = ref.current;
|
|
130
|
+
if (!el || !screen)
|
|
131
|
+
return;
|
|
132
|
+
const right = screen.x + PIN + GAP + POPOVER_WIDTH <= window.innerWidth - GAP;
|
|
133
|
+
const left = right ? screen.x + PIN + GAP : screen.x - GAP - POPOVER_WIDTH;
|
|
134
|
+
// The popover's top lines up with the pin's top.
|
|
135
|
+
const top = Math.min(Math.max(GAP, screen.y - PIN), window.innerHeight - el.offsetHeight - GAP);
|
|
136
|
+
el.style.left = `${Math.max(GAP, left)}px`;
|
|
137
|
+
el.style.top = `${Math.max(GAP, top)}px`;
|
|
138
|
+
});
|
|
139
|
+
if (!host || !visible)
|
|
140
|
+
return null;
|
|
141
|
+
const style = { width: POPOVER_WIDTH };
|
|
142
|
+
return createPortal(_jsx("dialog", { ref: ref, open: true, className: "builder-comments-popover", "aria-label": label, style: style, children: children }), host);
|
|
143
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import './comments.scss';
|
|
3
|
+
/** Top bar: comment mode on or off, with the number of open threads. */
|
|
4
|
+
export declare function CommentsButton(): import("react").JSX.Element | null;
|
|
5
|
+
/** In comment mode the panel takes the inspector's place. The inspector stays mounted. */
|
|
6
|
+
export declare function CommentsOrInspector({ children }: {
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
// The comments panel (the right sidebar in comment mode) and the top bar button with the count of
|
|
4
|
+
// open threads.
|
|
5
|
+
import { useMemo } from 'react';
|
|
6
|
+
import { findBlock } from '../../../core/index.js';
|
|
7
|
+
import { openCount, threadsOf } from '../../../comments/shared.js';
|
|
8
|
+
import { Icon } from '../icons.js';
|
|
9
|
+
import { blockName } from '../names.js';
|
|
10
|
+
import { useRuntime } from '../runtime.js';
|
|
11
|
+
import { useEditor } from '../store.js';
|
|
12
|
+
import { formatSaveTime } from '../topbar/saveTime.js';
|
|
13
|
+
import { useOptionalValue, useValue, useValueSelector } from '../valueStore.js';
|
|
14
|
+
import { Avatar, Thread } from './Thread.js';
|
|
15
|
+
import './comments.scss';
|
|
16
|
+
/** Top bar: comment mode on or off, with the number of open threads. */
|
|
17
|
+
export function CommentsButton() {
|
|
18
|
+
const { comments } = useRuntime();
|
|
19
|
+
if (!comments)
|
|
20
|
+
return null;
|
|
21
|
+
return _jsx(CommentsToggle, { comments: comments });
|
|
22
|
+
}
|
|
23
|
+
function CommentsToggle({ comments }) {
|
|
24
|
+
const on = useValue(comments.mode);
|
|
25
|
+
const count = useValueSelector(comments.list, openCount);
|
|
26
|
+
const label = count > 0 ? `Comments, ${count} open` : 'Comments';
|
|
27
|
+
return (_jsxs("button", { type: "button", className: "builder-editor__icon-button builder-comments-button", "aria-pressed": on, "aria-label": label, "aria-keyshortcuts": "C", "data-tooltip": `${on ? 'Leave comment mode' : 'Comments'} · C`, onClick: () => comments.toggle(), children: [_jsx(Icon, { name: "comment" }), count > 0 && _jsx("span", { className: "builder-comments-button__badge", children: count > 99 ? '99+' : count })] }));
|
|
28
|
+
}
|
|
29
|
+
/** In comment mode the panel takes the inspector's place. The inspector stays mounted. */
|
|
30
|
+
export function CommentsOrInspector({ children }) {
|
|
31
|
+
const { comments } = useRuntime();
|
|
32
|
+
const on = useOptionalValue(comments?.mode ?? null) === true;
|
|
33
|
+
return (_jsxs(_Fragment, { children: [on && comments && _jsx(CommentsPanel, { comments: comments }), _jsx("div", { className: "builder-comments-keep", hidden: on, children: children })] }));
|
|
34
|
+
}
|
|
35
|
+
const FILTERS = [
|
|
36
|
+
{ id: 'all', label: 'All' },
|
|
37
|
+
{ id: 'open', label: 'Open' },
|
|
38
|
+
{ id: 'resolved', label: 'Resolved' },
|
|
39
|
+
];
|
|
40
|
+
function CommentsPanel({ comments }) {
|
|
41
|
+
const runtime = useRuntime();
|
|
42
|
+
const list = useValue(comments.list);
|
|
43
|
+
const loaded = useValue(comments.loaded);
|
|
44
|
+
const filter = useValue(comments.filter);
|
|
45
|
+
const openId = useValue(comments.open);
|
|
46
|
+
const threads = useMemo(() => threadsOf(list, filter), [list, filter]);
|
|
47
|
+
const counts = useMemo(() => {
|
|
48
|
+
const all = threadsOf(list);
|
|
49
|
+
const open = all.filter((t) => !t.root.resolved).length;
|
|
50
|
+
return { all: all.length, open, resolved: all.length - open };
|
|
51
|
+
}, [list]);
|
|
52
|
+
return (_jsxs("section", { className: "builder-comments-panel", "aria-label": "Comments", children: [_jsxs("header", { className: "builder-comments-panel__head", children: [_jsx("h2", { className: "builder-comments-panel__title", children: "Comments" }), _jsx("button", { type: "button", className: "builder-editor__icon-button builder-editor__icon-button--small", "aria-label": "Close comments", "data-tooltip": "Close \u00B7 C", onClick: () => comments.toggle(false), children: _jsx(Icon, { name: "close", size: 14 }) })] }), _jsx("div", { className: "builder-comments-panel__filter", children: _jsx("div", { className: "builder-editor__segmented builder-editor__segmented--full builder-editor__segmented--small", role: "tablist", "aria-label": "Show", children: FILTERS.map((option) => (_jsxs("button", { type: "button", role: "tab", "aria-selected": filter === option.id, className: "builder-editor__segment", onClick: () => comments.filter.set(option.id), children: [option.label, counts[option.id] > 0 && _jsx("span", { className: "builder-editor__segment-count", children: counts[option.id] })] }, option.id))) }) }), _jsx("div", { className: "builder-comments-panel__list", children: threads.length === 0 ? (_jsxs("div", { className: "builder-editor__empty", children: [_jsx(Icon, { name: "comment", size: 20 }), _jsx("p", { children: !loaded ? 'Loading comments' : filter === 'resolved' ? 'No resolved comments' : filter === 'open' && counts.all > 0 ? 'All resolved' : 'No comments yet' }), loaded && filter !== 'resolved' && _jsx("p", { className: "builder-editor__hint", children: "Click a block on the canvas to comment on it." })] })) : (threads.map((thread) => _jsx(ThreadCard, { thread: thread, open: openId === thread.root.id, runtime: runtime, comments: comments }, thread.root.id))) })] }));
|
|
53
|
+
}
|
|
54
|
+
function ThreadCard({ thread, open, runtime, comments }) {
|
|
55
|
+
const { root, replies } = thread;
|
|
56
|
+
const block = useEditor(runtime.store, (s) => (root.blockId ? findBlock(s.view, root.blockId) : null));
|
|
57
|
+
const where = block ? blockName(block, runtime.blockLabel(block.type)) : null;
|
|
58
|
+
const last = replies.at(-1);
|
|
59
|
+
const show = () => {
|
|
60
|
+
comments.draft.set(null);
|
|
61
|
+
if (open) {
|
|
62
|
+
comments.open.set(null);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
comments.open.set(root.id);
|
|
66
|
+
if (!block)
|
|
67
|
+
return;
|
|
68
|
+
runtime.store.select(block.id);
|
|
69
|
+
runtime.postToCanvas({ type: 'scrollIntoView', id: block.id });
|
|
70
|
+
};
|
|
71
|
+
const classes = ['builder-comment-card', open && 'builder-comment-card--open', root.resolved && 'builder-comment-card--resolved'].filter(Boolean).join(' ');
|
|
72
|
+
return (_jsxs("div", { className: classes, children: [_jsxs("button", { type: "button", className: "builder-comment-card__summary", "aria-expanded": open, onClick: show, children: [_jsx(Avatar, { name: root.authorName }), _jsxs("span", { className: "builder-comment-card__main", children: [_jsxs("span", { className: "builder-comment__head", children: [_jsx("span", { className: "builder-comment__name", children: root.authorName }), _jsx("time", { className: "builder-comment__time", dateTime: root.createdAt, children: formatSaveTime(root.createdAt) }), root.resolved && (_jsx("span", { className: "builder-comment-card__resolved", "aria-label": "Resolved", children: _jsx(Icon, { name: "check", size: 12 }) }))] }), _jsx("span", { className: "builder-comment-card__body", children: root.body }), _jsxs("span", { className: "builder-comment-card__meta", children: [where ? (_jsx("span", { className: "builder-comment-card__where", children: where })) : (_jsx("span", { className: "builder-comment-card__deleted", children: "Block deleted" })), replies.length > 0 && (_jsxs("span", { children: [replies.length, " ", replies.length === 1 ? 'reply' : 'replies', last && ` · ${last.authorName}`] }))] })] })] }), open && !block && _jsx(Thread, { thread: thread, comments: comments })] }));
|
|
73
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type CommentThread } from '../../../comments/shared.js';
|
|
2
|
+
import type { CommentsController } from './controller.js';
|
|
3
|
+
/** The signed-in user's author key, to tell their own comments. */
|
|
4
|
+
export declare function useAuthorKey(): string | null;
|
|
5
|
+
export declare function Avatar({ name }: {
|
|
6
|
+
name: string;
|
|
7
|
+
}): import("react").JSX.Element;
|
|
8
|
+
type InputProps = {
|
|
9
|
+
placeholder: string;
|
|
10
|
+
submitLabel: string;
|
|
11
|
+
initial?: string;
|
|
12
|
+
focusOnMount?: boolean;
|
|
13
|
+
/** Shows Cancel, and Escape cancels. */
|
|
14
|
+
onCancel?: () => void;
|
|
15
|
+
/** True when the text was saved: the box empties. */
|
|
16
|
+
onSubmit: (body: string) => Promise<boolean>;
|
|
17
|
+
};
|
|
18
|
+
/** A text box that grows with its text. Enter sends, Shift+Enter adds a line, Escape cancels. */
|
|
19
|
+
export declare function CommentInput({ placeholder, submitLabel, initial, focusOnMount, onCancel, onSubmit }: InputProps): import("react").JSX.Element;
|
|
20
|
+
/** The thread: resolve and close in the head, the comments, and a reply box. */
|
|
21
|
+
export declare function Thread({ thread, comments, onClose }: {
|
|
22
|
+
thread: CommentThread;
|
|
23
|
+
comments: CommentsController;
|
|
24
|
+
onClose?: () => void;
|
|
25
|
+
}): import("react").JSX.Element;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
// A comment thread (the popover at a pin, and the panel for threads whose block is gone) and the
|
|
4
|
+
// text box that writes comments and replies.
|
|
5
|
+
import { useAuth, useConfig } from '@payloadcms/ui';
|
|
6
|
+
import { useEffect, useRef, useState } from 'react';
|
|
7
|
+
import { authorKeyOf, COMMENT_MAX } from '../../../comments/shared.js';
|
|
8
|
+
import { Icon } from '../icons.js';
|
|
9
|
+
import { initials } from '../live/presence.js';
|
|
10
|
+
import { formatSaveTime } from '../topbar/saveTime.js';
|
|
11
|
+
/** The signed-in user's author key, to tell their own comments. */
|
|
12
|
+
export function useAuthorKey() {
|
|
13
|
+
const { user } = useAuth();
|
|
14
|
+
const { config } = useConfig();
|
|
15
|
+
if (!user)
|
|
16
|
+
return null;
|
|
17
|
+
const u = user;
|
|
18
|
+
return authorKeyOf({ ...user, collection: typeof u.collection === 'string' ? u.collection : config.admin.user });
|
|
19
|
+
}
|
|
20
|
+
export function Avatar({ name }) {
|
|
21
|
+
return (_jsx("span", { className: "builder-comment__avatar", "aria-hidden": true, children: initials(name) }));
|
|
22
|
+
}
|
|
23
|
+
/** A text box that grows with its text. Enter sends, Shift+Enter adds a line, Escape cancels. */
|
|
24
|
+
export function CommentInput({ placeholder, submitLabel, initial = '', focusOnMount, onCancel, onSubmit }) {
|
|
25
|
+
const [text, setText] = useState(initial);
|
|
26
|
+
const [busy, setBusy] = useState(false);
|
|
27
|
+
const ref = useRef(null);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (!focusOnMount)
|
|
30
|
+
return;
|
|
31
|
+
const el = ref.current;
|
|
32
|
+
el?.focus();
|
|
33
|
+
el?.setSelectionRange(el.value.length, el.value.length);
|
|
34
|
+
}, [focusOnMount]);
|
|
35
|
+
const submit = async () => {
|
|
36
|
+
if (busy || !text.trim())
|
|
37
|
+
return;
|
|
38
|
+
setBusy(true);
|
|
39
|
+
const saved = await onSubmit(text);
|
|
40
|
+
setBusy(false);
|
|
41
|
+
if (saved)
|
|
42
|
+
setText('');
|
|
43
|
+
ref.current?.focus();
|
|
44
|
+
};
|
|
45
|
+
const onKeyDown = (e) => {
|
|
46
|
+
if (e.key === 'Enter' && !e.shiftKey && !e.nativeEvent.isComposing) {
|
|
47
|
+
e.preventDefault();
|
|
48
|
+
void submit();
|
|
49
|
+
}
|
|
50
|
+
if (e.key === 'Escape' && onCancel) {
|
|
51
|
+
e.preventDefault();
|
|
52
|
+
e.stopPropagation();
|
|
53
|
+
onCancel();
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
return (_jsxs("div", { className: "builder-comment-input", children: [_jsx("textarea", { ref: ref, rows: 1, value: text, maxLength: COMMENT_MAX, placeholder: placeholder, "aria-label": placeholder, onChange: (e) => setText(e.target.value), onKeyDown: onKeyDown }), _jsxs("div", { className: "builder-comment-input__actions", children: [onCancel && (_jsx("button", { type: "button", className: "builder-comment__text-button", onClick: onCancel, children: "Cancel" })), _jsx("button", { type: "button", className: "builder-comment__send", disabled: busy || !text.trim(), "aria-label": submitLabel, "data-tooltip": `${submitLabel} · Enter`, onClick: () => void submit(), children: _jsx(Icon, { name: "arrowUp", size: 14 }) })] })] }));
|
|
57
|
+
}
|
|
58
|
+
/** One comment: author, time, text, and Edit / Delete for its author. */
|
|
59
|
+
function CommentItem({ comment, own, comments, isRoot }) {
|
|
60
|
+
const [editing, setEditing] = useState(false);
|
|
61
|
+
const [confirming, setConfirming] = useState(false);
|
|
62
|
+
const time = formatSaveTime(comment.createdAt);
|
|
63
|
+
return (_jsxs("article", { className: "builder-comment", children: [_jsx(Avatar, { name: comment.authorName }), _jsxs("div", { className: "builder-comment__main", children: [_jsxs("header", { className: "builder-comment__head", children: [_jsx("span", { className: "builder-comment__name", children: comment.authorName }), _jsxs("time", { className: "builder-comment__time", dateTime: comment.createdAt, children: [time, comment.editedAt && ' · edited'] }), own && !editing && (_jsxs("span", { className: "builder-comment__tools", children: [_jsx("button", { type: "button", className: "builder-editor__icon-button builder-editor__icon-button--small", "aria-label": "Edit", "data-tooltip": "Edit", onClick: () => setEditing(true), children: _jsx(Icon, { name: "rename", size: 13 }) }), _jsx("button", { type: "button", className: "builder-editor__icon-button builder-editor__icon-button--small", "aria-label": "Delete", "data-tooltip": "Delete", onClick: () => setConfirming(true), children: _jsx(Icon, { name: "delete", size: 13 }) })] }))] }), editing ? (_jsx(CommentInput, { placeholder: "Edit comment", submitLabel: "Save", initial: comment.body, focusOnMount: true, onCancel: () => setEditing(false), onSubmit: async (body) => {
|
|
64
|
+
const saved = await comments.edit(comment.id, body);
|
|
65
|
+
if (saved)
|
|
66
|
+
setEditing(false);
|
|
67
|
+
return saved;
|
|
68
|
+
} })) : (_jsx("p", { className: "builder-comment__body", children: comment.body })), confirming && (_jsxs("div", { className: "builder-comment__confirm", role: "alert", children: [_jsx("span", { children: isRoot ? 'Delete this thread and its replies?' : 'Delete this reply?' }), _jsx("button", { type: "button", className: "builder-comment__text-button", onClick: () => setConfirming(false), children: "Cancel" }), _jsx("button", { type: "button", className: "builder-comment__text-button builder-comment__text-button--danger", onClick: () => void comments.remove(comment.id), children: "Delete" })] }))] })] }));
|
|
69
|
+
}
|
|
70
|
+
/** The thread: resolve and close in the head, the comments, and a reply box. */
|
|
71
|
+
export function Thread({ thread, comments, onClose }) {
|
|
72
|
+
const me = useAuthorKey();
|
|
73
|
+
const { root, replies } = thread;
|
|
74
|
+
const [busy, setBusy] = useState(false);
|
|
75
|
+
const toggleResolved = async () => {
|
|
76
|
+
setBusy(true);
|
|
77
|
+
const done = await comments.setResolved(root.id, !root.resolved);
|
|
78
|
+
setBusy(false);
|
|
79
|
+
// Resolving closes the thread, as in Figma: it leaves the open list.
|
|
80
|
+
if (done && !root.resolved)
|
|
81
|
+
onClose?.();
|
|
82
|
+
};
|
|
83
|
+
return (_jsxs("div", { className: "builder-thread", children: [_jsxs("div", { className: "builder-thread__head", children: [_jsx("span", { className: "builder-thread__status", children: root.resolved ? `Resolved${root.resolvedByName ? ` by ${root.resolvedByName}` : ''}` : replies.length > 0 ? `${replies.length + 1} comments` : 'Comment' }), _jsx("button", { type: "button", className: "builder-editor__icon-button builder-editor__icon-button--small", "aria-pressed": root.resolved, "aria-label": root.resolved ? 'Reopen' : 'Resolve', "data-tooltip": root.resolved ? 'Reopen' : 'Resolve', disabled: busy, onClick: () => void toggleResolved(), children: _jsx(Icon, { name: root.resolved ? 'undo' : 'check', size: 14 }) }), onClose && (_jsx("button", { type: "button", className: "builder-editor__icon-button builder-editor__icon-button--small", "aria-label": "Close", "data-tooltip": "Close \u00B7 Esc", onClick: onClose, children: _jsx(Icon, { name: "close", size: 14 }) }))] }), _jsx("div", { className: "builder-thread__items", children: [root, ...replies].map((comment) => (_jsx(CommentItem, { comment: comment, own: comment.authorKey === me, comments: comments, isRoot: comment === root }, comment.id))) }), _jsx("div", { className: "builder-thread__reply", children: _jsx(CommentInput, { placeholder: "Reply", submitLabel: "Reply", focusOnMount: Boolean(onClose), onSubmit: (body) => comments.reply(root.id, body) }, root.id) })] }));
|
|
84
|
+
}
|