@formicoidea/labre-core 0.43.1 → 0.46.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/dist/_pkgs/affine-block-attachment/utils.js +4 -0
- package/dist/_pkgs/affine-block-bookmark/configs/toolbar.js +17 -4
- package/dist/_pkgs/affine-block-callout/commands/turn-callout-into.d.ts +43 -0
- package/dist/_pkgs/affine-block-callout/commands/turn-callout-into.js +109 -0
- package/dist/_pkgs/affine-block-callout/commands/turn-into-callout.d.ts +29 -0
- package/dist/_pkgs/affine-block-callout/commands/turn-into-callout.js +81 -0
- package/dist/_pkgs/affine-block-callout/configs/slash-menu.js +6 -4
- package/dist/_pkgs/affine-block-callout/configs/toolbar.d.ts +65 -0
- package/dist/_pkgs/affine-block-callout/configs/toolbar.js +178 -0
- package/dist/_pkgs/affine-block-callout/configs/turn-into.d.ts +8 -0
- package/dist/_pkgs/affine-block-callout/configs/turn-into.js +19 -0
- package/dist/_pkgs/affine-block-callout/translations.d.ts +4 -2
- package/dist/_pkgs/affine-block-callout/translations.js +4 -2
- package/dist/_pkgs/affine-block-callout/view.js +10 -1
- package/dist/_pkgs/affine-block-code/code-block-service.d.ts +13 -0
- package/dist/_pkgs/affine-block-code/code-block-service.js +26 -0
- package/dist/_pkgs/affine-block-code/code-block.d.ts +6 -0
- package/dist/_pkgs/affine-block-code/code-block.js +11 -2
- package/dist/_pkgs/affine-block-code/code-toolbar/components/lang-button.js +31 -8
- package/dist/_pkgs/affine-block-edgeless-text/edgeless-toolbar/config.d.ts +11 -0
- package/dist/_pkgs/affine-block-edgeless-text/svg-painter.d.ts +20 -0
- package/dist/_pkgs/affine-block-edgeless-text/svg-painter.js +76 -0
- package/dist/_pkgs/affine-block-edgeless-text/view.js +2 -0
- package/dist/_pkgs/affine-block-embed/configs/toolbar.js +11 -2
- package/dist/_pkgs/affine-block-embed/embed-iframe-block/configs/toolbar.js +11 -2
- package/dist/_pkgs/affine-block-embed-doc/embed-linked-doc-block/embed-edgeless-linked-doc-block.js +3 -1
- package/dist/_pkgs/affine-block-embed-doc/embed-synced-doc-block/configs/toolbar.js +7 -2
- package/dist/_pkgs/affine-block-embed-doc/embed-synced-doc-block/embed-edgeless-synced-doc-block.js +3 -1
- package/dist/_pkgs/affine-block-frame/commands.d.ts +27 -0
- package/dist/_pkgs/affine-block-frame/commands.js +49 -0
- package/dist/_pkgs/affine-block-frame/frame-manager.d.ts +16 -6
- package/dist/_pkgs/affine-block-frame/frame-manager.js +58 -22
- package/dist/_pkgs/affine-block-frame/frame-order.d.ts +43 -0
- package/dist/_pkgs/affine-block-frame/frame-order.js +93 -0
- package/dist/_pkgs/affine-block-frame/frame-tool.js +3 -1
- package/dist/_pkgs/affine-block-frame/index.d.ts +2 -0
- package/dist/_pkgs/affine-block-frame/index.js +2 -0
- package/dist/_pkgs/affine-block-frame/present/frame-order-menu.d.ts +10 -2
- package/dist/_pkgs/affine-block-frame/present/frame-order-menu.js +32 -18
- package/dist/_pkgs/affine-block-frame/view.js +6 -0
- package/dist/_pkgs/affine-block-image/utils.js +4 -1
- package/dist/_pkgs/affine-block-latex/adapters/markdown/preprocessor.d.ts +8 -0
- package/dist/_pkgs/affine-block-latex/adapters/markdown/preprocessor.js +9 -5
- package/dist/_pkgs/affine-block-note/configs/toolbar.d.ts +19 -0
- package/dist/_pkgs/affine-block-note/configs/toolbar.js +38 -23
- package/dist/_pkgs/affine-block-note/translations.d.ts +2 -1
- package/dist/_pkgs/affine-block-note/translations.js +14 -6
- package/dist/_pkgs/affine-block-root/configs/toolbar.js +48 -3
- package/dist/_pkgs/affine-block-root/edgeless/clipboard/clipboard.js +2 -1
- package/dist/_pkgs/affine-block-root/edgeless/clipboard/command.js +161 -83
- package/dist/_pkgs/affine-block-root/edgeless/clipboard/paste-order.d.ts +21 -0
- package/dist/_pkgs/affine-block-root/edgeless/clipboard/paste-order.js +85 -0
- package/dist/_pkgs/affine-block-root/edgeless/edgeless-root-block.d.ts +6 -0
- package/dist/_pkgs/affine-block-root/edgeless/edgeless-root-block.js +18 -1
- package/dist/_pkgs/affine-block-root/edgeless/utils/clone-utils.d.ts +9 -0
- package/dist/_pkgs/affine-block-root/edgeless/utils/clone-utils.js +28 -0
- package/dist/_pkgs/affine-block-root/keyboard/commands.js +9 -6
- package/dist/_pkgs/affine-block-root/preview/edgeless-root-preview-block.js +15 -2
- package/dist/_pkgs/affine-block-root/translations.d.ts +7 -2
- package/dist/_pkgs/affine-block-root/translations.js +10 -13
- package/dist/_pkgs/affine-block-surface/adapters/markdown/element-adapter/type.d.ts +1 -1
- package/dist/_pkgs/affine-block-surface/element-model/index.d.ts +1 -1
- package/dist/_pkgs/affine-block-surface/element-model/index.js +1 -1
- package/dist/_pkgs/affine-block-surface/extensions/audit.js +13 -61
- package/dist/_pkgs/affine-block-surface/extensions/canvas-grid/commands.d.ts +2 -0
- package/dist/_pkgs/affine-block-surface/extensions/canvas-grid/commands.js +71 -0
- package/dist/_pkgs/affine-block-surface/extensions/canvas-grid/index.d.ts +1 -0
- package/dist/_pkgs/affine-block-surface/extensions/canvas-grid/index.js +1 -0
- package/dist/_pkgs/affine-block-surface/extensions/clipboard-config.js +4 -0
- package/dist/_pkgs/affine-block-surface/extensions/crud-extension.js +4 -0
- package/dist/_pkgs/affine-block-surface/extensions/export-manager/export-manager.d.ts +12 -0
- package/dist/_pkgs/affine-block-surface/extensions/export-manager/export-manager.js +27 -7
- package/dist/_pkgs/affine-block-surface/extensions/export-svg/command.d.ts +2 -1
- package/dist/_pkgs/affine-block-surface/extensions/export-svg/command.js +22 -3
- package/dist/_pkgs/affine-block-surface/extensions/export-svg/index.d.ts +6 -3
- package/dist/_pkgs/affine-block-surface/extensions/export-svg/index.js +4 -2
- package/dist/_pkgs/affine-block-surface/extensions/export-svg/parts.d.ts +63 -0
- package/dist/_pkgs/affine-block-surface/extensions/export-svg/parts.js +67 -0
- package/dist/_pkgs/affine-block-surface/extensions/export-svg/render.d.ts +62 -5
- package/dist/_pkgs/affine-block-surface/extensions/export-svg/render.js +98 -18
- package/dist/_pkgs/affine-block-surface/extensions/export-svg/svg-context.d.ts +14 -0
- package/dist/_pkgs/affine-block-surface/extensions/export-svg/svg-context.js +82 -1
- package/dist/_pkgs/affine-block-surface/extensions/export-svg/toolbar.d.ts +2 -2
- package/dist/_pkgs/affine-block-surface/extensions/export-svg/toolbar.js +112 -10
- package/dist/_pkgs/affine-block-surface/extensions/export-svg/translations.d.ts +13 -0
- package/dist/_pkgs/affine-block-surface/extensions/export-svg/translations.js +33 -0
- package/dist/_pkgs/affine-block-surface/extensions/index.d.ts +3 -0
- package/dist/_pkgs/affine-block-surface/extensions/index.js +3 -0
- package/dist/_pkgs/affine-block-surface/extensions/reading-widget.d.ts +13 -6
- package/dist/_pkgs/affine-block-surface/extensions/reading-widget.js +26 -10
- package/dist/_pkgs/affine-block-surface/extensions/reading.d.ts +82 -6
- package/dist/_pkgs/affine-block-surface/extensions/reading.js +99 -21
- package/dist/_pkgs/affine-block-surface/extensions/selection-pane/actions.d.ts +91 -0
- package/dist/_pkgs/affine-block-surface/extensions/selection-pane/actions.js +285 -0
- package/dist/_pkgs/affine-block-surface/extensions/selection-pane/commands.d.ts +80 -0
- package/dist/_pkgs/affine-block-surface/extensions/selection-pane/commands.js +355 -0
- package/dist/_pkgs/affine-block-surface/extensions/selection-pane/index.d.ts +3 -0
- package/dist/_pkgs/affine-block-surface/extensions/selection-pane/index.js +3 -0
- package/dist/_pkgs/affine-block-surface/extensions/selection-pane/tree.d.ts +137 -0
- package/dist/_pkgs/affine-block-surface/extensions/selection-pane/tree.js +323 -0
- package/dist/_pkgs/affine-block-surface/extensions/svg-sketch.d.ts +112 -4
- package/dist/_pkgs/affine-block-surface/extensions/svg-sketch.js +86 -15
- package/dist/_pkgs/affine-block-surface/extensions/user-layers/actions.d.ts +76 -0
- package/dist/_pkgs/affine-block-surface/extensions/user-layers/actions.js +299 -0
- package/dist/_pkgs/affine-block-surface/extensions/user-layers/active-layer.d.ts +20 -0
- package/dist/_pkgs/affine-block-surface/extensions/user-layers/active-layer.js +34 -0
- package/dist/_pkgs/affine-block-surface/extensions/user-layers/commands.d.ts +67 -0
- package/dist/_pkgs/affine-block-surface/extensions/user-layers/commands.js +172 -0
- package/dist/_pkgs/affine-block-surface/extensions/user-layers/creation.d.ts +40 -0
- package/dist/_pkgs/affine-block-surface/extensions/user-layers/creation.js +69 -0
- package/dist/_pkgs/affine-block-surface/extensions/user-layers/index.d.ts +5 -0
- package/dist/_pkgs/affine-block-surface/extensions/user-layers/index.js +5 -0
- package/dist/_pkgs/affine-block-surface/extensions/user-layers/translations.d.ts +10 -0
- package/dist/_pkgs/affine-block-surface/extensions/user-layers/translations.js +14 -0
- package/dist/_pkgs/affine-block-surface/framework-background/facts.d.ts +55 -2
- package/dist/_pkgs/affine-block-surface/framework-background/facts.js +63 -1
- package/dist/_pkgs/affine-block-surface/framework-background/stacking.d.ts +16 -8
- package/dist/_pkgs/affine-block-surface/framework-background/stacking.js +26 -14
- package/dist/_pkgs/affine-block-surface/renderer/canvas-renderer.js +17 -3
- package/dist/_pkgs/affine-block-surface/renderer/dom-renderer.d.ts +3 -1
- package/dist/_pkgs/affine-block-surface/renderer/dom-renderer.js +22 -2
- package/dist/_pkgs/affine-block-surface/renderer/paint-predicate.d.ts +30 -0
- package/dist/_pkgs/affine-block-surface/renderer/paint-predicate.js +29 -0
- package/dist/_pkgs/affine-block-surface/surface-block.js +6 -0
- package/dist/_pkgs/affine-block-surface/surface-model.js +5 -0
- package/dist/_pkgs/affine-block-surface/surface-transformer.js +5 -0
- package/dist/_pkgs/affine-block-surface/tool/default-tool.js +28 -5
- package/dist/_pkgs/affine-block-surface/view.js +23 -1
- package/dist/_pkgs/affine-block-surface-ref/surface-ref-block.js +12 -2
- package/dist/_pkgs/affine-components/context-menu/button.js +14 -0
- package/dist/_pkgs/affine-components/filterable-list/index.js +30 -9
- package/dist/_pkgs/affine-components/icons/index.d.ts +0 -1
- package/dist/_pkgs/affine-components/icons/index.js +0 -1
- package/dist/_pkgs/affine-components/icons/text.d.ts +1 -0
- package/dist/_pkgs/affine-components/icons/text.js +11 -0
- package/dist/_pkgs/affine-components/portal/portal.d.ts +1 -1
- package/dist/_pkgs/affine-foundation/view.d.ts +8 -8
- package/dist/_pkgs/affine-fragment-adapter-panel/adapter-panel.d.ts +2 -2
- package/dist/_pkgs/affine-fragment-frame-panel/body/frame-panel-body.d.ts +34 -2
- package/dist/_pkgs/affine-fragment-frame-panel/body/frame-panel-body.js +194 -81
- package/dist/_pkgs/affine-fragment-frame-panel/card/frame-card.d.ts +7 -4
- package/dist/_pkgs/affine-fragment-frame-panel/card/frame-card.js +9 -24
- package/dist/_pkgs/affine-fragment-frame-panel/header/frame-panel-header.d.ts +1 -1
- package/dist/_pkgs/affine-fragment-frame-panel/header/frame-panel-header.js +8 -27
- package/dist/_pkgs/affine-fragment-frame-panel/index.d.ts +2 -0
- package/dist/_pkgs/affine-fragment-frame-panel/index.js +2 -0
- package/dist/_pkgs/affine-gfx-connector/element-renderer/connector-dom/index.js +3 -1
- package/dist/_pkgs/affine-gfx-connector/element-renderer/index.js +21 -4
- package/dist/_pkgs/affine-gfx-connector/text/edgeless-connector-label-editor.js +3 -2
- package/dist/_pkgs/affine-gfx-connector/toolbar/config.js +1 -1
- package/dist/_pkgs/affine-gfx-group/command/group-api.js +52 -1
- package/dist/_pkgs/affine-gfx-shape/element-renderer/shape/index.js +21 -3
- package/dist/_pkgs/affine-gfx-shape/text/edgeless-shape-text-editor.js +2 -0
- package/dist/_pkgs/affine-gfx-shape/toolbar/config.js +1 -1
- package/dist/_pkgs/affine-gfx-template/services/template-middlewares.d.ts +9 -0
- package/dist/_pkgs/affine-gfx-template/services/template-middlewares.js +23 -1
- package/dist/_pkgs/affine-gfx-template/services/template.js +2 -1
- package/dist/_pkgs/affine-gfx-text/edgeless-text-editor.js +2 -1
- package/dist/_pkgs/affine-gfx-text/element-renderer/index.js +20 -3
- package/dist/_pkgs/affine-gfx-text/element-renderer/utils.d.ts +67 -1
- package/dist/_pkgs/affine-gfx-text/element-renderer/utils.js +101 -0
- package/dist/_pkgs/affine-gfx-text/toolbar/actions.d.ts +11 -0
- package/dist/_pkgs/affine-gfx-text/toolbar/actions.js +53 -2
- package/dist/_pkgs/affine-gfx-text/toolbar/config.d.ts +11 -0
- package/dist/_pkgs/affine-gfx-text/toolbar/config.js +1 -1
- package/dist/_pkgs/affine-inline-preset/adapters/html/html-inline.d.ts +3 -0
- package/dist/_pkgs/affine-inline-preset/adapters/html/html-inline.js +31 -0
- package/dist/_pkgs/affine-inline-preset/adapters/html/inline-delta.d.ts +4 -0
- package/dist/_pkgs/affine-inline-preset/adapters/html/inline-delta.js +14 -0
- package/dist/_pkgs/affine-inline-preset/command/config.js +21 -3
- package/dist/_pkgs/affine-inline-preset/command/index.d.ts +1 -1
- package/dist/_pkgs/affine-inline-preset/command/index.js +1 -1
- package/dist/_pkgs/affine-inline-preset/command/text-style.d.ts +2 -1
- package/dist/_pkgs/affine-inline-preset/command/text-style.js +1 -0
- package/dist/_pkgs/affine-inline-preset/default-inline-manager.js +2 -1
- package/dist/_pkgs/affine-inline-preset/inline-spec.d.ts +4 -0
- package/dist/_pkgs/affine-inline-preset/inline-spec.js +14 -0
- package/dist/_pkgs/affine-inline-preset/translations.d.ts +2 -2
- package/dist/_pkgs/affine-inline-preset/translations.js +2 -2
- package/dist/_pkgs/affine-model/blocks/attachment/attachment-model.js +2 -0
- package/dist/_pkgs/affine-model/blocks/bookmark/bookmark-model.js +2 -0
- package/dist/_pkgs/affine-model/blocks/edgeless-text/edgeless-text-model.d.ts +1 -1
- package/dist/_pkgs/affine-model/blocks/edgeless-text/edgeless-text-model.js +2 -0
- package/dist/_pkgs/affine-model/blocks/embed/iframe/iframe-model.js +2 -0
- package/dist/_pkgs/affine-model/blocks/frame/frame-model.js +2 -0
- package/dist/_pkgs/affine-model/blocks/image/image-model.js +2 -0
- package/dist/_pkgs/affine-model/blocks/latex/latex-model.js +2 -0
- package/dist/_pkgs/affine-model/blocks/note/note-model.js +2 -0
- package/dist/_pkgs/affine-model/consts/text.d.ts +26 -0
- package/dist/_pkgs/affine-model/consts/text.js +25 -0
- package/dist/_pkgs/affine-model/elements/shape/shape.d.ts +6 -1
- package/dist/_pkgs/affine-model/elements/shape/shape.js +14 -1
- package/dist/_pkgs/affine-model/elements/text/text.d.ts +6 -1
- package/dist/_pkgs/affine-model/elements/text/text.js +13 -1
- package/dist/_pkgs/affine-model/utils/helper.js +2 -0
- package/dist/_pkgs/affine-model/utils/types.d.ts +2 -2
- package/dist/_pkgs/affine-rich-text/conversion.d.ts +25 -0
- package/dist/_pkgs/affine-rich-text/conversion.js +9 -0
- package/dist/_pkgs/affine-rich-text/index.d.ts +1 -1
- package/dist/_pkgs/affine-rich-text/index.js +1 -1
- package/dist/_pkgs/affine-shared/commands/model-crud/replace-selected-text-with-blocks.d.ts +1 -1
- package/dist/_pkgs/affine-shared/services/canvas-grid.d.ts +63 -0
- package/dist/_pkgs/affine-shared/services/canvas-grid.js +109 -0
- package/dist/_pkgs/affine-shared/services/canvas-local-visibility.d.ts +64 -0
- package/dist/_pkgs/affine-shared/services/canvas-local-visibility.js +192 -0
- package/dist/_pkgs/affine-shared/services/edit-props-store.d.ts +31 -4
- package/dist/_pkgs/affine-shared/services/edit-props-store.js +34 -0
- package/dist/_pkgs/affine-shared/services/editor-setting-service.d.ts +3 -0
- package/dist/_pkgs/affine-shared/services/editor-setting-service.js +7 -0
- package/dist/_pkgs/affine-shared/services/feature-flag-service.d.ts +4 -0
- package/dist/_pkgs/affine-shared/services/font-loader/config.d.ts +2 -2
- package/dist/_pkgs/affine-shared/services/font-loader/font-loader-service.d.ts +3 -3
- package/dist/_pkgs/affine-shared/services/index.d.ts +4 -1
- package/dist/_pkgs/affine-shared/services/index.js +4 -1
- package/dist/_pkgs/affine-shared/services/link-preview-service/link-preview-storage.d.ts +4 -4
- package/dist/_pkgs/affine-shared/services/outline-panel-service.d.ts +31 -0
- package/dist/_pkgs/affine-shared/services/outline-panel-service.js +17 -0
- package/dist/_pkgs/affine-shared/services/selection-pane-service.d.ts +44 -0
- package/dist/_pkgs/affine-shared/services/selection-pane-service.js +28 -0
- package/dist/_pkgs/affine-shared/services/telemetry-service/lifecycle.d.ts +69 -0
- package/dist/_pkgs/affine-shared/services/telemetry-service/telemetry-service.d.ts +2 -2
- package/dist/_pkgs/affine-shared/services/translation-service/chrome.d.ts +16 -0
- package/dist/_pkgs/affine-shared/services/translation-service/chrome.js +28 -0
- package/dist/_pkgs/affine-shared/styles/index.d.ts +1 -0
- package/dist/_pkgs/affine-shared/styles/index.js +1 -0
- package/dist/_pkgs/affine-shared/styles/panel-header.d.ts +31 -0
- package/dist/_pkgs/affine-shared/styles/panel-header.js +61 -0
- package/dist/_pkgs/affine-shared/styles/text.js +7 -7
- package/dist/_pkgs/affine-shared/types/index.d.ts +6 -0
- package/dist/_pkgs/affine-shared/utils/canvas-export-colors.d.ts +26 -0
- package/dist/_pkgs/affine-shared/utils/canvas-export-colors.js +127 -0
- package/dist/_pkgs/affine-shared/utils/file/filesys.d.ts +8 -11
- package/dist/_pkgs/affine-shared/utils/file/filesys.js +8 -11
- package/dist/_pkgs/affine-shared/utils/index.d.ts +3 -0
- package/dist/_pkgs/affine-shared/utils/index.js +3 -0
- package/dist/_pkgs/affine-shared/utils/label-mode.d.ts +47 -0
- package/dist/_pkgs/affine-shared/utils/label-mode.js +55 -0
- package/dist/_pkgs/affine-shared/utils/model/merge-to-code-model.js +7 -1
- package/dist/_pkgs/affine-shared/utils/model/transform-model.js +5 -0
- package/dist/_pkgs/affine-shared/utils/panel-reorder-drag.d.ts +85 -0
- package/dist/_pkgs/affine-shared/utils/panel-reorder-drag.js +162 -0
- package/dist/_pkgs/affine-widget-edgeless-selected-rect/utils.js +10 -3
- package/dist/_pkgs/affine-widget-edgeless-toolbar/catalogue/artefact-catalogue-widget.js +25 -49
- package/dist/_pkgs/affine-widget-edgeless-toolbar/effects.d.ts +4 -0
- package/dist/_pkgs/affine-widget-edgeless-toolbar/effects.js +4 -0
- package/dist/_pkgs/affine-widget-edgeless-toolbar/index.d.ts +4 -0
- package/dist/_pkgs/affine-widget-edgeless-toolbar/index.js +4 -0
- package/dist/_pkgs/affine-widget-edgeless-toolbar/selection-pane/drop.d.ts +62 -0
- package/dist/_pkgs/affine-widget-edgeless-toolbar/selection-pane/drop.js +94 -0
- package/dist/_pkgs/affine-widget-edgeless-toolbar/selection-pane/labels.d.ts +17 -0
- package/dist/_pkgs/affine-widget-edgeless-toolbar/selection-pane/labels.js +95 -0
- package/dist/_pkgs/affine-widget-edgeless-toolbar/selection-pane/selection-pane-default.d.ts +10 -0
- package/dist/_pkgs/affine-widget-edgeless-toolbar/selection-pane/selection-pane-default.js +31 -0
- package/dist/_pkgs/affine-widget-edgeless-toolbar/selection-pane/selection-pane-tool.d.ts +26 -0
- package/dist/_pkgs/affine-widget-edgeless-toolbar/selection-pane/selection-pane-tool.js +82 -0
- package/dist/_pkgs/affine-widget-edgeless-toolbar/selection-pane/selection-pane-widget.d.ts +186 -0
- package/dist/_pkgs/affine-widget-edgeless-toolbar/selection-pane/selection-pane-widget.js +1417 -0
- package/dist/_pkgs/affine-widget-edgeless-toolbar/translations.d.ts +52 -0
- package/dist/_pkgs/affine-widget-edgeless-toolbar/translations.js +161 -1
- package/dist/_pkgs/affine-widget-edgeless-toolbar/view.js +10 -0
- package/dist/_pkgs/affine-widget-note-slicer/note-slicer.js +7 -3
- package/dist/_pkgs/std/gfx/controller.d.ts +13 -0
- package/dist/_pkgs/std/gfx/controller.js +22 -2
- package/dist/_pkgs/std/gfx/grid.d.ts +31 -2
- package/dist/_pkgs/std/gfx/index.d.ts +3 -1
- package/dist/_pkgs/std/gfx/index.js +3 -1
- package/dist/_pkgs/std/gfx/interactivity/manager.js +7 -0
- package/dist/_pkgs/std/gfx/layer.js +73 -5
- package/dist/_pkgs/std/gfx/local-visibility.d.ts +88 -0
- package/dist/_pkgs/std/gfx/local-visibility.js +217 -0
- package/dist/_pkgs/std/gfx/model/gfx-block-model.d.ts +13 -0
- package/dist/_pkgs/std/gfx/model/surface/element-model.d.ts +34 -0
- package/dist/_pkgs/std/gfx/model/surface/element-model.js +65 -1
- package/dist/_pkgs/std/gfx/model/surface/surface-model.d.ts +27 -0
- package/dist/_pkgs/std/gfx/model/surface/surface-model.js +43 -0
- package/dist/_pkgs/std/gfx/model/surface/user-layers.d.ts +68 -0
- package/dist/_pkgs/std/gfx/model/surface/user-layers.js +127 -0
- package/dist/_pkgs/std/scope/std-scope.d.ts +1 -1
- package/dist/_pkgs/std/utils/layer.d.ts +10 -0
- package/dist/_pkgs/std/utils/layer.js +64 -13
- package/dist/_pkgs/std/view/element/gfx-block-component.js +10 -2
- package/dist/commands.js +6 -1
- package/dist/host-panels.d.ts +90 -0
- package/dist/host-panels.js +111 -0
- package/dist/translations.js +10 -6
- package/package.json +13 -2
- package/dist/_pkgs/affine-components/icons/file-icons-rc.d.ts +0 -1
- package/dist/_pkgs/affine-components/icons/file-icons-rc.js +0 -130
- package/dist/_pkgs/affine-fragment-frame-panel/utils/drag.d.ts +0 -27
- package/dist/_pkgs/affine-fragment-frame-panel/utils/drag.js +0 -96
- package/dist/_pkgs/affine-shared/services/sidebar-service.d.ts +0 -8
- package/dist/_pkgs/affine-shared/services/sidebar-service.js +0 -7
- package/dist/_pkgs/affine-shared/test-utils/affine-template.d.ts +0 -6
- package/dist/_pkgs/affine-shared/test-utils/affine-template.js +0 -258
- package/dist/_pkgs/affine-shared/test-utils/affine-test-utils.d.ts +0 -8
- package/dist/_pkgs/affine-shared/test-utils/affine-test-utils.js +0 -81
- package/dist/_pkgs/affine-shared/test-utils/create-test-host.d.ts +0 -23
- package/dist/_pkgs/affine-shared/test-utils/create-test-host.js +0 -187
- package/dist/_pkgs/affine-shared/test-utils/index.d.ts +0 -3
- package/dist/_pkgs/affine-shared/test-utils/index.js +0 -3
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formicoidea/labre-core",
|
|
3
3
|
"description": "Labre editor — the full BlockSuite-derived editor as one package.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.46.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"author": "lajola",
|
|
@@ -818,6 +818,10 @@
|
|
|
818
818
|
"types": "./dist/commands.d.ts",
|
|
819
819
|
"import": "./dist/commands.js"
|
|
820
820
|
},
|
|
821
|
+
"./host-panels": {
|
|
822
|
+
"types": "./dist/host-panels.d.ts",
|
|
823
|
+
"import": "./dist/host-panels.js"
|
|
824
|
+
},
|
|
821
825
|
"./frameworks": {
|
|
822
826
|
"types": "./dist/frameworks.d.ts",
|
|
823
827
|
"import": "./dist/frameworks.js"
|
|
@@ -873,6 +877,14 @@
|
|
|
873
877
|
"./_pkgs/global/utils": {
|
|
874
878
|
"types": "./dist/_pkgs/global/utils/index.d.ts",
|
|
875
879
|
"import": "./dist/_pkgs/global/utils/index.js"
|
|
880
|
+
},
|
|
881
|
+
"./_pkgs/store": {
|
|
882
|
+
"types": "./dist/_pkgs/store/index.d.ts",
|
|
883
|
+
"import": "./dist/_pkgs/store/index.js"
|
|
884
|
+
},
|
|
885
|
+
"./_pkgs/store/index.js": {
|
|
886
|
+
"types": "./dist/_pkgs/store/index.d.ts",
|
|
887
|
+
"import": "./dist/_pkgs/store/index.js"
|
|
876
888
|
}
|
|
877
889
|
},
|
|
878
890
|
"files": [
|
|
@@ -946,7 +958,6 @@
|
|
|
946
958
|
"ts-pattern": "^5.1.0",
|
|
947
959
|
"unified": "^11.0.5",
|
|
948
960
|
"unist-util-visit": "^5.0.0",
|
|
949
|
-
"vitest": "^3.2.3",
|
|
950
961
|
"w3c-keyname": "^2.2.8",
|
|
951
962
|
"y-protocols": "^1.0.6",
|
|
952
963
|
"yjs": "^13.6.21",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function getAttachmentFileIconRC(filetype: string): (props: import("react").SVGProps<SVGSVGElement>) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { FileIconAepIcon, FileIconAiIcon, FileIconAviIcon, FileIconCssIcon, FileIconCsvIcon, FileIconDmgIcon, FileIconDocIcon, FileIconDocxIcon, FileIconEpsIcon, FileIconExeIcon, FileIconFigIcon, FileIconGifIcon, FileIconHtmlIcon, FileIconInddIcon, FileIconJavaIcon, FileIconJpegIcon, FileIconJsIcon, FileIconJsonIcon, FileIconMkvIcon, FileIconMp3Icon, FileIconMp4Icon, FileIconMpegIcon, FileIconNoneIcon, FileIconPdfIcon, FileIconPngIcon, FileIconPptIcon, FileIconPptxIcon, FileIconPsdIcon, FileIconRarIcon, FileIconRssIcon, FileIconSqlIcon, FileIconSvgIcon, FileIconTiffIcon, FileIconTxtIcon, FileIconWavIcon, FileIconWebpIcon, FileIconXlsIcon, FileIconXlsxIcon, FileIconXmlIcon, FileIconZipIcon, ImageIcon, } from '@blocksuite/icons/rc';
|
|
2
|
-
export function getAttachmentFileIconRC(filetype) {
|
|
3
|
-
switch (filetype) {
|
|
4
|
-
case 'img':
|
|
5
|
-
return ImageIcon;
|
|
6
|
-
case 'image/jpeg':
|
|
7
|
-
case 'jpg':
|
|
8
|
-
case 'jpeg':
|
|
9
|
-
return FileIconJpegIcon;
|
|
10
|
-
case 'image/png':
|
|
11
|
-
case 'png':
|
|
12
|
-
return FileIconPngIcon;
|
|
13
|
-
case 'image/webp':
|
|
14
|
-
case 'webp':
|
|
15
|
-
return FileIconWebpIcon;
|
|
16
|
-
case 'image/tiff':
|
|
17
|
-
case 'tiff':
|
|
18
|
-
return FileIconTiffIcon;
|
|
19
|
-
case 'image/gif':
|
|
20
|
-
case 'gif':
|
|
21
|
-
return FileIconGifIcon;
|
|
22
|
-
case 'image/svg':
|
|
23
|
-
case 'svg':
|
|
24
|
-
return FileIconSvgIcon;
|
|
25
|
-
case 'image/eps':
|
|
26
|
-
case 'eps':
|
|
27
|
-
return FileIconEpsIcon;
|
|
28
|
-
case 'application/pdf':
|
|
29
|
-
case 'pdf':
|
|
30
|
-
return FileIconPdfIcon;
|
|
31
|
-
case 'application/msword':
|
|
32
|
-
case 'application/x-iwork-pages-sffpages':
|
|
33
|
-
case 'doc':
|
|
34
|
-
return FileIconDocIcon;
|
|
35
|
-
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
|
|
36
|
-
case 'docx':
|
|
37
|
-
return FileIconDocxIcon;
|
|
38
|
-
case 'text/plain':
|
|
39
|
-
case 'txt':
|
|
40
|
-
return FileIconTxtIcon;
|
|
41
|
-
case 'csv':
|
|
42
|
-
return FileIconCsvIcon;
|
|
43
|
-
case 'application/vnd.ms-excel':
|
|
44
|
-
case 'xls':
|
|
45
|
-
return FileIconXlsIcon;
|
|
46
|
-
case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
|
|
47
|
-
case 'application/x-iwork-numbers-sffnumbers':
|
|
48
|
-
case 'xlsx':
|
|
49
|
-
return FileIconXlsxIcon;
|
|
50
|
-
case 'application/vnd.ms-powerpoint':
|
|
51
|
-
case 'application/x-iwork-keynote-sffkeynote':
|
|
52
|
-
case 'ppt':
|
|
53
|
-
return FileIconPptIcon;
|
|
54
|
-
case 'application/vnd.openxmlformats-officedocument.presentationml.presentation':
|
|
55
|
-
case 'pptx':
|
|
56
|
-
return FileIconPptxIcon;
|
|
57
|
-
case 'application/illustrator':
|
|
58
|
-
case 'fig':
|
|
59
|
-
return FileIconFigIcon;
|
|
60
|
-
case 'application/postscript':
|
|
61
|
-
case 'ai':
|
|
62
|
-
return FileIconAiIcon;
|
|
63
|
-
case 'application/vnd.adobe.photoshop':
|
|
64
|
-
case 'psd':
|
|
65
|
-
return FileIconPsdIcon;
|
|
66
|
-
case 'application/vnd.adobe.indesign':
|
|
67
|
-
case 'indd':
|
|
68
|
-
return FileIconInddIcon;
|
|
69
|
-
case 'application/vnd.adobe.afterfx':
|
|
70
|
-
case 'aep':
|
|
71
|
-
return FileIconAepIcon;
|
|
72
|
-
case 'audio/mpeg':
|
|
73
|
-
case 'audio/mp3':
|
|
74
|
-
case 'mp3':
|
|
75
|
-
return FileIconMp3Icon;
|
|
76
|
-
case 'audio/wav':
|
|
77
|
-
case 'wav':
|
|
78
|
-
return FileIconWavIcon;
|
|
79
|
-
case 'video/mpeg':
|
|
80
|
-
case 'mpeg':
|
|
81
|
-
return FileIconMpegIcon;
|
|
82
|
-
case 'video/mp4':
|
|
83
|
-
case 'mp4':
|
|
84
|
-
return FileIconMp4Icon;
|
|
85
|
-
case 'video/avi':
|
|
86
|
-
case 'avi':
|
|
87
|
-
return FileIconAviIcon;
|
|
88
|
-
case 'video/mkv':
|
|
89
|
-
case 'mkv':
|
|
90
|
-
return FileIconMkvIcon;
|
|
91
|
-
case 'text/html':
|
|
92
|
-
case 'html':
|
|
93
|
-
return FileIconHtmlIcon;
|
|
94
|
-
case 'text/css':
|
|
95
|
-
case 'css':
|
|
96
|
-
return FileIconCssIcon;
|
|
97
|
-
case 'application/rss+xml':
|
|
98
|
-
case 'rss':
|
|
99
|
-
return FileIconRssIcon;
|
|
100
|
-
case 'application/sql':
|
|
101
|
-
case 'sql':
|
|
102
|
-
return FileIconSqlIcon;
|
|
103
|
-
case 'application/javascript':
|
|
104
|
-
case 'js':
|
|
105
|
-
return FileIconJsIcon;
|
|
106
|
-
case 'application/json':
|
|
107
|
-
case 'json':
|
|
108
|
-
return FileIconJsonIcon;
|
|
109
|
-
case 'application/java':
|
|
110
|
-
case 'java':
|
|
111
|
-
return FileIconJavaIcon;
|
|
112
|
-
case 'application/xml':
|
|
113
|
-
case 'xml':
|
|
114
|
-
return FileIconXmlIcon;
|
|
115
|
-
case 'application/x-msdos-program':
|
|
116
|
-
case 'exe':
|
|
117
|
-
return FileIconExeIcon;
|
|
118
|
-
case 'application/x-apple-diskimage':
|
|
119
|
-
case 'dmg':
|
|
120
|
-
return FileIconDmgIcon;
|
|
121
|
-
case 'application/zip':
|
|
122
|
-
case 'zip':
|
|
123
|
-
return FileIconZipIcon;
|
|
124
|
-
case 'application/x-rar-compressed':
|
|
125
|
-
case 'rar':
|
|
126
|
-
return FileIconRarIcon;
|
|
127
|
-
default:
|
|
128
|
-
return FileIconNoneIcon;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { FrameBlockModel } from '../../affine-model/index.js';
|
|
2
|
-
import type { FramePanelBody } from '../body/frame-panel-body.js';
|
|
3
|
-
import { FrameCard } from '../card/frame-card.js';
|
|
4
|
-
/**
|
|
5
|
-
* start drag frame cards
|
|
6
|
-
* @param frames frames to drag
|
|
7
|
-
*/
|
|
8
|
-
export declare function startDragging(frames: {
|
|
9
|
-
frame: FrameBlockModel;
|
|
10
|
-
element: FrameCard;
|
|
11
|
-
cardIndex: number;
|
|
12
|
-
frameIndex: string;
|
|
13
|
-
}[], options: {
|
|
14
|
-
width: number;
|
|
15
|
-
onDragEnd?: (insertIndex?: number) => void;
|
|
16
|
-
onDragMove?: (insertIdx?: number, indicatorTranslateY?: number) => void;
|
|
17
|
-
framePanelBody: HTMLElement;
|
|
18
|
-
frameListContainer: HTMLElement;
|
|
19
|
-
frameElementHeight: number;
|
|
20
|
-
document: Document;
|
|
21
|
-
domHost: Document | HTMLElement;
|
|
22
|
-
container: FramePanelBody;
|
|
23
|
-
start: {
|
|
24
|
-
x: number;
|
|
25
|
-
y: number;
|
|
26
|
-
};
|
|
27
|
-
}): void;
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { on, once } from '../../affine-shared/utils/index.js';
|
|
2
|
-
import { FrameCard } from '../card/frame-card.js';
|
|
3
|
-
/**
|
|
4
|
-
* start drag frame cards
|
|
5
|
-
* @param frames frames to drag
|
|
6
|
-
*/
|
|
7
|
-
export function startDragging(frames, options) {
|
|
8
|
-
const { document, domHost, container, onDragMove, onDragEnd, frameElementHeight, framePanelBody, frameListContainer, start, } = options;
|
|
9
|
-
const cardElements = frames
|
|
10
|
-
.slice(frames.length - 2, frames.length)
|
|
11
|
-
.map((frame, idx, arr) => {
|
|
12
|
-
const el = new FrameCard();
|
|
13
|
-
el.frame = frame.frame;
|
|
14
|
-
el.cardIndex = frame.cardIndex;
|
|
15
|
-
el.frameIndex = frame.frameIndex;
|
|
16
|
-
el.status = 'dragging';
|
|
17
|
-
el.stackOrder = arr.length - 1 - idx;
|
|
18
|
-
el.pos = start;
|
|
19
|
-
el.width = options.width;
|
|
20
|
-
el.std = container.editorHost.std;
|
|
21
|
-
if (frames.length > 1 && el.stackOrder === 0)
|
|
22
|
-
el.draggingCardNumber = frames.length;
|
|
23
|
-
return el;
|
|
24
|
-
});
|
|
25
|
-
const maskElement = createMaskElement(document);
|
|
26
|
-
const listContainerRect = framePanelBody.getBoundingClientRect();
|
|
27
|
-
const children = Array.from(frameListContainer.children);
|
|
28
|
-
const computedStyle = getComputedStyle(frameListContainer);
|
|
29
|
-
const frameListContainerGap = parseInt(computedStyle.getPropertyValue('gap')) ?? 16;
|
|
30
|
-
let idx;
|
|
31
|
-
let indicatorTranslateY;
|
|
32
|
-
container.renderRoot.append(maskElement);
|
|
33
|
-
container.renderRoot.append(...cardElements);
|
|
34
|
-
const insideListContainer = (e) => {
|
|
35
|
-
return (e.clientX >= listContainerRect.left &&
|
|
36
|
-
e.clientX <= listContainerRect.right &&
|
|
37
|
-
e.clientY >= listContainerRect.top &&
|
|
38
|
-
e.clientY <= listContainerRect.bottom);
|
|
39
|
-
};
|
|
40
|
-
const disposeMove = on(container, 'mousemove', e => {
|
|
41
|
-
cardElements.forEach(el => {
|
|
42
|
-
el.pos = {
|
|
43
|
-
x: e.clientX,
|
|
44
|
-
y: e.clientY,
|
|
45
|
-
};
|
|
46
|
-
});
|
|
47
|
-
if (!insideListContainer(e)) {
|
|
48
|
-
idx = undefined;
|
|
49
|
-
onDragMove?.(idx, 0);
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
idx = 0;
|
|
53
|
-
for (const card of children) {
|
|
54
|
-
if (!card.frame)
|
|
55
|
-
break;
|
|
56
|
-
const topBoundary = listContainerRect.top +
|
|
57
|
-
card.offsetTop -
|
|
58
|
-
framePanelBody.scrollTop -
|
|
59
|
-
frameListContainerGap / 2;
|
|
60
|
-
const midBoundary = topBoundary + card.offsetHeight / 2;
|
|
61
|
-
const bottomBoundary = topBoundary + card.offsetHeight + frameListContainerGap;
|
|
62
|
-
if (e.clientY >= topBoundary && e.clientY <= bottomBoundary) {
|
|
63
|
-
idx = e.clientY > midBoundary ? idx + 1 : idx;
|
|
64
|
-
indicatorTranslateY =
|
|
65
|
-
idx * (frameElementHeight + frameListContainerGap) -
|
|
66
|
-
frameListContainerGap / 2;
|
|
67
|
-
onDragMove?.(idx, indicatorTranslateY);
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
++idx;
|
|
71
|
-
}
|
|
72
|
-
onDragMove?.(idx);
|
|
73
|
-
});
|
|
74
|
-
let ended = false;
|
|
75
|
-
const dragEnd = () => {
|
|
76
|
-
if (ended)
|
|
77
|
-
return;
|
|
78
|
-
ended = true;
|
|
79
|
-
cardElements.forEach(child => child.remove());
|
|
80
|
-
maskElement.remove();
|
|
81
|
-
disposeMove();
|
|
82
|
-
onDragEnd?.(idx);
|
|
83
|
-
};
|
|
84
|
-
once(domHost, 'mouseup', dragEnd);
|
|
85
|
-
}
|
|
86
|
-
function createMaskElement(doc) {
|
|
87
|
-
const mask = doc.createElement('div');
|
|
88
|
-
mask.style.height = '100vh';
|
|
89
|
-
mask.style.width = '100vw';
|
|
90
|
-
mask.style.position = 'fixed';
|
|
91
|
-
mask.style.left = '0';
|
|
92
|
-
mask.style.top = '0';
|
|
93
|
-
mask.style.zIndex = 'calc(var(--affine-z-index-popover, 0) + 3)';
|
|
94
|
-
mask.style.cursor = 'grabbing';
|
|
95
|
-
return mask;
|
|
96
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { ExtensionType } from '../../store/index.js';
|
|
2
|
-
export interface SidebarService {
|
|
3
|
-
open: (tabId?: string) => void;
|
|
4
|
-
close: () => void;
|
|
5
|
-
getTabIds: () => string[];
|
|
6
|
-
}
|
|
7
|
-
export declare const SidebarExtensionIdentifier: import("../../global/di/types.js").ServiceIdentifier<SidebarService> & (<U extends SidebarService = SidebarService>(variant: import("../../global/di/types.js").ServiceVariant) => import("../../global/di/types.js").ServiceIdentifier<U>);
|
|
8
|
-
export declare const SidebarExtension: (service: SidebarService) => ExtensionType;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { createIdentifier } from '../../global/di/index.js';
|
|
2
|
-
export const SidebarExtensionIdentifier = createIdentifier('AffineSidebarExtension');
|
|
3
|
-
export const SidebarExtension = (service) => ({
|
|
4
|
-
setup: di => {
|
|
5
|
-
di.addImpl(SidebarExtensionIdentifier, () => service);
|
|
6
|
-
},
|
|
7
|
-
});
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { type Block, type ExtensionType } from '../../store/index.js';
|
|
2
|
-
export declare function createAffineTemplate(extensions?: ExtensionType[]): {
|
|
3
|
-
affine: (strings: TemplateStringsArray, ...values: any[]) => import("../../std/index.js").EditorHost;
|
|
4
|
-
block: (strings: TemplateStringsArray, ...values: any[]) => Block | null;
|
|
5
|
-
};
|
|
6
|
-
export declare const affine: (strings: TemplateStringsArray, ...values: any[]) => import("../../std/index.js").EditorHost, block: (strings: TemplateStringsArray, ...values: any[]) => Block | null;
|
|
@@ -1,258 +0,0 @@
|
|
|
1
|
-
import { CodeBlockSchemaExtension, DatabaseBlockSchemaExtension, ImageBlockSchemaExtension, ListBlockSchemaExtension, NoteBlockSchemaExtension, ParagraphBlockSchemaExtension, RootBlockSchemaExtension, } from '../../affine-model/index.js';
|
|
2
|
-
import { Container } from '../../global/di/index.js';
|
|
3
|
-
import { TextSelection } from '../../std/index.js';
|
|
4
|
-
import { Text } from '../../store/index.js';
|
|
5
|
-
import { TestWorkspace } from '../../store/test/index.js';
|
|
6
|
-
import { createTestHost } from './create-test-host.js';
|
|
7
|
-
const DEFAULT_EXTENSIONS = [
|
|
8
|
-
RootBlockSchemaExtension,
|
|
9
|
-
NoteBlockSchemaExtension,
|
|
10
|
-
ParagraphBlockSchemaExtension,
|
|
11
|
-
ListBlockSchemaExtension,
|
|
12
|
-
ImageBlockSchemaExtension,
|
|
13
|
-
DatabaseBlockSchemaExtension,
|
|
14
|
-
CodeBlockSchemaExtension,
|
|
15
|
-
];
|
|
16
|
-
// Mapping from tag names to flavours
|
|
17
|
-
const tagToFlavour = {
|
|
18
|
-
'affine-page': 'affine:page',
|
|
19
|
-
'affine-note': 'affine:note',
|
|
20
|
-
'affine-paragraph': 'affine:paragraph',
|
|
21
|
-
'affine-list': 'affine:list',
|
|
22
|
-
'affine-image': 'affine:image',
|
|
23
|
-
'affine-database': 'affine:database',
|
|
24
|
-
'affine-code': 'affine:code',
|
|
25
|
-
};
|
|
26
|
-
export function createAffineTemplate(extensions = DEFAULT_EXTENSIONS) {
|
|
27
|
-
/**
|
|
28
|
-
* Parse template strings and build BlockSuite document structure,
|
|
29
|
-
* then create a host object with the document
|
|
30
|
-
*
|
|
31
|
-
* Example:
|
|
32
|
-
* ```
|
|
33
|
-
* const host = affine`
|
|
34
|
-
* <affine-page id="page">
|
|
35
|
-
* <affine-note id="note">
|
|
36
|
-
* <affine-paragraph id="paragraph-1">Hello, world<anchor /></affine-paragraph>
|
|
37
|
-
* <affine-paragraph id="paragraph-2">Hello, world<focus /></affine-paragraph>
|
|
38
|
-
* </affine-note>
|
|
39
|
-
* </affine-page>
|
|
40
|
-
* `;
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
function affine(strings, ...values) {
|
|
44
|
-
// Merge template strings and values
|
|
45
|
-
let htmlString = '';
|
|
46
|
-
strings.forEach((str, i) => {
|
|
47
|
-
htmlString += str;
|
|
48
|
-
if (i < values.length) {
|
|
49
|
-
htmlString += values[i];
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
// Create a new doc
|
|
53
|
-
const workspace = new TestWorkspace({});
|
|
54
|
-
workspace.meta.initialize();
|
|
55
|
-
const doc = workspace.createDoc('test-doc');
|
|
56
|
-
const container = new Container();
|
|
57
|
-
extensions.forEach(extension => {
|
|
58
|
-
extension.setup(container);
|
|
59
|
-
});
|
|
60
|
-
const store = doc.getStore({ extensions, provider: container.provider() });
|
|
61
|
-
let selectionInfo = {};
|
|
62
|
-
// Use DOMParser to parse HTML string
|
|
63
|
-
doc.load(() => {
|
|
64
|
-
const parser = new DOMParser();
|
|
65
|
-
const dom = parser.parseFromString(htmlString.trim(), 'text/html');
|
|
66
|
-
const root = dom.body.firstElementChild;
|
|
67
|
-
if (!root) {
|
|
68
|
-
throw new Error('Template must contain a root element');
|
|
69
|
-
}
|
|
70
|
-
buildDocFromElement(store, root, null, selectionInfo);
|
|
71
|
-
});
|
|
72
|
-
// Create host object
|
|
73
|
-
const host = createTestHost(store);
|
|
74
|
-
// Set selection if needed
|
|
75
|
-
if (selectionInfo.anchorBlockId && selectionInfo.focusBlockId) {
|
|
76
|
-
const anchorBlock = store.getBlock(selectionInfo.anchorBlockId);
|
|
77
|
-
const anchorTextLength = anchorBlock?.model?.text?.length ?? 0;
|
|
78
|
-
const focusOffset = selectionInfo.focusOffset ?? 0;
|
|
79
|
-
const anchorOffset = selectionInfo.anchorOffset ?? 0;
|
|
80
|
-
if (selectionInfo.anchorBlockId === selectionInfo.focusBlockId) {
|
|
81
|
-
const selection = host.selection.create(TextSelection, {
|
|
82
|
-
from: {
|
|
83
|
-
blockId: selectionInfo.anchorBlockId,
|
|
84
|
-
index: anchorOffset,
|
|
85
|
-
length: focusOffset,
|
|
86
|
-
},
|
|
87
|
-
to: null,
|
|
88
|
-
});
|
|
89
|
-
host.selection.setGroup('note', [selection]);
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
const selection = host.selection.create(TextSelection, {
|
|
93
|
-
from: {
|
|
94
|
-
blockId: selectionInfo.anchorBlockId,
|
|
95
|
-
index: anchorOffset,
|
|
96
|
-
length: anchorTextLength - anchorOffset,
|
|
97
|
-
},
|
|
98
|
-
to: {
|
|
99
|
-
blockId: selectionInfo.focusBlockId,
|
|
100
|
-
index: 0,
|
|
101
|
-
length: focusOffset,
|
|
102
|
-
},
|
|
103
|
-
});
|
|
104
|
-
host.selection.setGroup('note', [selection]);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
else if (selectionInfo.cursorBlockId) {
|
|
108
|
-
const selection = host.selection.create(TextSelection, {
|
|
109
|
-
from: {
|
|
110
|
-
blockId: selectionInfo.cursorBlockId,
|
|
111
|
-
index: selectionInfo.cursorOffset ?? 0,
|
|
112
|
-
length: 0,
|
|
113
|
-
},
|
|
114
|
-
to: null,
|
|
115
|
-
});
|
|
116
|
-
host.selection.setGroup('note', [selection]);
|
|
117
|
-
}
|
|
118
|
-
return host;
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Create a single block from template string
|
|
122
|
-
*
|
|
123
|
-
* Example:
|
|
124
|
-
* ```
|
|
125
|
-
* const block = block`<affine-note />`
|
|
126
|
-
* ```
|
|
127
|
-
*/
|
|
128
|
-
function block(strings, ...values) {
|
|
129
|
-
// Merge template strings and values
|
|
130
|
-
let htmlString = '';
|
|
131
|
-
strings.forEach((str, i) => {
|
|
132
|
-
htmlString += str;
|
|
133
|
-
if (i < values.length) {
|
|
134
|
-
htmlString += values[i];
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
// Create a temporary doc to hold the block
|
|
138
|
-
const workspace = new TestWorkspace({});
|
|
139
|
-
workspace.meta.initialize();
|
|
140
|
-
const doc = workspace.createDoc('temp-doc');
|
|
141
|
-
const store = doc.getStore({ extensions });
|
|
142
|
-
let blockId = null;
|
|
143
|
-
const selectionInfo = {};
|
|
144
|
-
// Use DOMParser to parse HTML string
|
|
145
|
-
doc.load(() => {
|
|
146
|
-
const parser = new DOMParser();
|
|
147
|
-
const dom = parser.parseFromString(htmlString.trim(), 'text/html');
|
|
148
|
-
const root = dom.body.firstElementChild;
|
|
149
|
-
if (!root) {
|
|
150
|
-
throw new Error('Template must contain a root element');
|
|
151
|
-
}
|
|
152
|
-
// Create a root block if needed
|
|
153
|
-
const flavour = tagToFlavour[root.tagName.toLowerCase()];
|
|
154
|
-
if (flavour === 'affine:paragraph' ||
|
|
155
|
-
flavour === 'affine:list' ||
|
|
156
|
-
flavour === 'affine:code') {
|
|
157
|
-
const pageId = store.addBlock('affine:page', {});
|
|
158
|
-
const noteId = store.addBlock('affine:note', {}, pageId);
|
|
159
|
-
blockId = buildDocFromElement(store, root, noteId, selectionInfo);
|
|
160
|
-
}
|
|
161
|
-
else {
|
|
162
|
-
blockId = buildDocFromElement(store, root, null, selectionInfo);
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
// Return the created block
|
|
166
|
-
return blockId ? (store.getBlock(blockId) ?? null) : null;
|
|
167
|
-
}
|
|
168
|
-
return {
|
|
169
|
-
affine,
|
|
170
|
-
block,
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
export const { affine, block } = createAffineTemplate();
|
|
174
|
-
/**
|
|
175
|
-
* Recursively build document structure
|
|
176
|
-
* @param doc
|
|
177
|
-
* @param element
|
|
178
|
-
* @param parentId
|
|
179
|
-
* @param selectionInfo
|
|
180
|
-
* @returns
|
|
181
|
-
*/
|
|
182
|
-
function buildDocFromElement(doc, element, parentId, selectionInfo) {
|
|
183
|
-
const tagName = element.tagName.toLowerCase();
|
|
184
|
-
// Handle selection tags
|
|
185
|
-
if (tagName === 'anchor') {
|
|
186
|
-
if (!parentId)
|
|
187
|
-
return '';
|
|
188
|
-
const parentBlock = doc.getBlock(parentId);
|
|
189
|
-
if (parentBlock) {
|
|
190
|
-
const textBeforeCursor = element.previousSibling?.textContent ?? '';
|
|
191
|
-
selectionInfo.anchorBlockId = parentId;
|
|
192
|
-
selectionInfo.anchorOffset = textBeforeCursor.length;
|
|
193
|
-
}
|
|
194
|
-
return parentId;
|
|
195
|
-
}
|
|
196
|
-
else if (tagName === 'focus') {
|
|
197
|
-
if (!parentId)
|
|
198
|
-
return '';
|
|
199
|
-
const parentBlock = doc.getBlock(parentId);
|
|
200
|
-
if (parentBlock) {
|
|
201
|
-
const textBeforeCursor = element.previousSibling?.textContent ?? '';
|
|
202
|
-
selectionInfo.focusBlockId = parentId;
|
|
203
|
-
selectionInfo.focusOffset = textBeforeCursor.length;
|
|
204
|
-
}
|
|
205
|
-
return parentId;
|
|
206
|
-
}
|
|
207
|
-
else if (tagName === 'cursor') {
|
|
208
|
-
if (!parentId)
|
|
209
|
-
return '';
|
|
210
|
-
const parentBlock = doc.getBlock(parentId);
|
|
211
|
-
if (parentBlock) {
|
|
212
|
-
const textBeforeCursor = element.previousSibling?.textContent ?? '';
|
|
213
|
-
selectionInfo.cursorBlockId = parentId;
|
|
214
|
-
selectionInfo.cursorOffset = textBeforeCursor.length;
|
|
215
|
-
}
|
|
216
|
-
return parentId;
|
|
217
|
-
}
|
|
218
|
-
const flavour = tagToFlavour[tagName];
|
|
219
|
-
if (!flavour) {
|
|
220
|
-
throw new Error(`Unknown tag name: ${tagName}`);
|
|
221
|
-
}
|
|
222
|
-
const props = {};
|
|
223
|
-
const customId = element.getAttribute('id');
|
|
224
|
-
// If ID is specified, add it to props
|
|
225
|
-
if (customId) {
|
|
226
|
-
props.id = customId;
|
|
227
|
-
}
|
|
228
|
-
// Process element attributes
|
|
229
|
-
Array.from(element.attributes).forEach(attr => {
|
|
230
|
-
if (attr.name !== 'id') {
|
|
231
|
-
// Skip id attribute, we already handled it
|
|
232
|
-
props[attr.name] = attr.value;
|
|
233
|
-
}
|
|
234
|
-
});
|
|
235
|
-
// Special handling for different block types based on their flavours
|
|
236
|
-
switch (flavour) {
|
|
237
|
-
case 'affine:paragraph':
|
|
238
|
-
case 'affine:list':
|
|
239
|
-
if (element.textContent) {
|
|
240
|
-
props.text = new Text(element.textContent);
|
|
241
|
-
}
|
|
242
|
-
break;
|
|
243
|
-
}
|
|
244
|
-
// Create block
|
|
245
|
-
const blockId = doc.addBlock(flavour, props, parentId);
|
|
246
|
-
// Process all child nodes, including text nodes
|
|
247
|
-
Array.from(element.children).forEach(child => {
|
|
248
|
-
if (child.nodeType === Node.ELEMENT_NODE) {
|
|
249
|
-
// Handle element nodes
|
|
250
|
-
buildDocFromElement(doc, child, blockId, selectionInfo);
|
|
251
|
-
}
|
|
252
|
-
else if (child.nodeType === Node.TEXT_NODE) {
|
|
253
|
-
// Handle text nodes
|
|
254
|
-
console.log('buildDocFromElement text node:', child.textContent);
|
|
255
|
-
}
|
|
256
|
-
});
|
|
257
|
-
return blockId;
|
|
258
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { expect } from 'vitest';
|
|
2
|
-
const COMPARE_PROPERTIES = new Set(['id']);
|
|
3
|
-
function blockToTemplate(block, indent = '') {
|
|
4
|
-
const props = Object.entries(block.props)
|
|
5
|
-
.filter(([key]) => COMPARE_PROPERTIES.has(key))
|
|
6
|
-
.map(([key, value]) => `${key}="${value}"`)
|
|
7
|
-
.join(' ');
|
|
8
|
-
const text = block.text ? block.text.toString() : '';
|
|
9
|
-
const children = block.children
|
|
10
|
-
.map(child => blockToTemplate(child, indent + ' '))
|
|
11
|
-
.join('\n');
|
|
12
|
-
const tagName = `affine-${block.flavour}`;
|
|
13
|
-
const propsStr = props ? ` ${props}` : '';
|
|
14
|
-
const content = text
|
|
15
|
-
? `>${text}</${tagName}>`
|
|
16
|
-
: children
|
|
17
|
-
? `>\n${children}\n${indent}</${tagName}>`
|
|
18
|
-
: `></${tagName}>`;
|
|
19
|
-
return `${indent}<${tagName}${propsStr}${content}`;
|
|
20
|
-
}
|
|
21
|
-
function docToTemplate(doc) {
|
|
22
|
-
if (!doc.root)
|
|
23
|
-
return 'null';
|
|
24
|
-
const rootBlock = doc.getBlock(doc.root.id);
|
|
25
|
-
if (!rootBlock)
|
|
26
|
-
return 'null';
|
|
27
|
-
return blockToTemplate(rootBlock.model);
|
|
28
|
-
}
|
|
29
|
-
function compareBlocks(actual, expected, compareId = false) {
|
|
30
|
-
if (actual.flavour !== expected.flavour)
|
|
31
|
-
return false;
|
|
32
|
-
if (compareId && actual.id !== expected.id)
|
|
33
|
-
return false;
|
|
34
|
-
if (actual.children.length !== expected.children.length)
|
|
35
|
-
return false;
|
|
36
|
-
const actualText = actual.text;
|
|
37
|
-
const expectedText = expected.text;
|
|
38
|
-
if (actualText &&
|
|
39
|
-
expectedText &&
|
|
40
|
-
actualText.toString() !== expectedText.toString()) {
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
const actualProps = { ...actual.props };
|
|
44
|
-
const expectedProps = { ...expected.props };
|
|
45
|
-
if (JSON.stringify(actualProps) !== JSON.stringify(expectedProps))
|
|
46
|
-
return false;
|
|
47
|
-
for (const [i, child] of actual.children.entries()) {
|
|
48
|
-
if (!compareBlocks(child, expected.children[i], compareId))
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
return true;
|
|
52
|
-
}
|
|
53
|
-
function compareDocs(actual, expected, compareId = false) {
|
|
54
|
-
if (!actual.root || !expected.root)
|
|
55
|
-
return false;
|
|
56
|
-
const actualRoot = actual.getBlock(actual.root.id);
|
|
57
|
-
const expectedRoot = expected.getBlock(expected.root.id);
|
|
58
|
-
if (!actualRoot || !expectedRoot)
|
|
59
|
-
return false;
|
|
60
|
-
return compareBlocks(actualRoot.model, expectedRoot.model, compareId);
|
|
61
|
-
}
|
|
62
|
-
expect.extend({
|
|
63
|
-
toEqualDoc(received, expected, options = { compareId: false }) {
|
|
64
|
-
const compareId = options.compareId;
|
|
65
|
-
const pass = compareDocs(received, expected, compareId);
|
|
66
|
-
if (pass) {
|
|
67
|
-
return {
|
|
68
|
-
message: () => 'expected documents to be different',
|
|
69
|
-
pass: true,
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
const actualTemplate = docToTemplate(received);
|
|
74
|
-
const expectedTemplate = docToTemplate(expected);
|
|
75
|
-
return {
|
|
76
|
-
message: () => `Documents are not equal.\n\nActual:\n${actualTemplate}\n\nExpected:\n${expectedTemplate}`,
|
|
77
|
-
pass: false,
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
});
|