@formicoidea/labre-core 0.43.1 → 0.45.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-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/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 +3 -0
- 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/frame-manager.d.ts +5 -0
- package/dist/_pkgs/affine-block-frame/frame-manager.js +48 -17
- package/dist/_pkgs/affine-block-frame/frame-tool.js +3 -1
- 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/translations.d.ts +0 -1
- package/dist/_pkgs/affine-block-note/translations.js +0 -5
- package/dist/_pkgs/affine-block-root/configs/toolbar.js +17 -1
- 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-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 +80 -0
- package/dist/_pkgs/affine-block-surface/extensions/selection-pane/actions.js +248 -0
- package/dist/_pkgs/affine-block-surface/extensions/selection-pane/commands.d.ts +82 -0
- package/dist/_pkgs/affine-block-surface/extensions/selection-pane/commands.js +342 -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-fragment-adapter-panel/adapter-panel.d.ts +2 -2
- package/dist/_pkgs/affine-fragment-frame-panel/card/frame-card.js +2 -2
- 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 +1 -0
- package/dist/_pkgs/affine-fragment-frame-panel/index.js +1 -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-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 +27 -0
- 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/index.d.ts +3 -0
- package/dist/_pkgs/affine-shared/services/index.js +3 -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 +5 -0
- package/dist/_pkgs/affine-shared/services/translation-service/chrome.js +9 -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 +2 -0
- package/dist/_pkgs/affine-shared/utils/index.js +2 -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-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 +61 -0
- package/dist/_pkgs/affine-widget-edgeless-toolbar/selection-pane/drop.js +91 -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 +170 -0
- package/dist/_pkgs/affine-widget-edgeless-toolbar/selection-pane/selection-pane-widget.js +1381 -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/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 +4 -1
- package/dist/translations.js +10 -6
- package/package.json +9 -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-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
|
@@ -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
|
-
});
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { type EditorHost } from '../../std/index.js';
|
|
2
|
-
import type { Store } from '../../store/index.js';
|
|
3
|
-
/**
|
|
4
|
-
* Create a test host object
|
|
5
|
-
*
|
|
6
|
-
* This function creates a mock host object that includes doc and command properties,
|
|
7
|
-
* which can be used for testing command execution.
|
|
8
|
-
*
|
|
9
|
-
* Usage:
|
|
10
|
-
* ```typescript
|
|
11
|
-
* const doc = affine`<affine-page></affine-page>`;
|
|
12
|
-
* const host = createTestHost(doc);
|
|
13
|
-
*
|
|
14
|
-
* // Use host.command.exec to execute commands
|
|
15
|
-
* const [_, result] = host.command.exec(someCommand, {
|
|
16
|
-
* // command params
|
|
17
|
-
* });
|
|
18
|
-
* ```
|
|
19
|
-
*
|
|
20
|
-
* @param doc Document object
|
|
21
|
-
* @returns Host object containing doc and command
|
|
22
|
-
*/
|
|
23
|
-
export declare function createTestHost(doc: Store): EditorHost;
|
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
import { CommandManager } from '../../std/index.js';
|
|
2
|
-
import { Subject } from 'rxjs';
|
|
3
|
-
/**
|
|
4
|
-
* Mock selection class for testing
|
|
5
|
-
*/
|
|
6
|
-
class MockSelectionStore {
|
|
7
|
-
constructor() {
|
|
8
|
-
this._selections = [];
|
|
9
|
-
this.slots = {
|
|
10
|
-
changed: {
|
|
11
|
-
emit: () => { },
|
|
12
|
-
},
|
|
13
|
-
remoteChanged: {
|
|
14
|
-
emit: () => { },
|
|
15
|
-
},
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
get value() {
|
|
19
|
-
return this._selections;
|
|
20
|
-
}
|
|
21
|
-
create(selectionClass, ...args) {
|
|
22
|
-
return new selectionClass(...args);
|
|
23
|
-
}
|
|
24
|
-
setGroup(group, selections) {
|
|
25
|
-
this._selections = this._selections.filter(s => s.group !== group);
|
|
26
|
-
this._selections.push(...selections);
|
|
27
|
-
return this;
|
|
28
|
-
}
|
|
29
|
-
set(selections) {
|
|
30
|
-
this._selections = selections;
|
|
31
|
-
return this;
|
|
32
|
-
}
|
|
33
|
-
find(type) {
|
|
34
|
-
return this._selections.find(s => s instanceof type);
|
|
35
|
-
}
|
|
36
|
-
filter(type) {
|
|
37
|
-
return this._selections.filter(s => s instanceof type);
|
|
38
|
-
}
|
|
39
|
-
clear() {
|
|
40
|
-
this._selections = [];
|
|
41
|
-
return this;
|
|
42
|
-
}
|
|
43
|
-
dispose() {
|
|
44
|
-
this._selections = [];
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
class MockViewStore {
|
|
48
|
-
constructor(doc) {
|
|
49
|
-
this.doc = doc;
|
|
50
|
-
this._blockMap = new Map();
|
|
51
|
-
this.viewUpdated = new Subject();
|
|
52
|
-
}
|
|
53
|
-
get views() {
|
|
54
|
-
return Array.from(this._blockMap.values());
|
|
55
|
-
}
|
|
56
|
-
deleteBlock(node) {
|
|
57
|
-
this._blockMap.delete(node.model.id);
|
|
58
|
-
this.viewUpdated.next({
|
|
59
|
-
id: node.model.id,
|
|
60
|
-
method: 'delete',
|
|
61
|
-
type: 'block',
|
|
62
|
-
view: node,
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
getBlock(id) {
|
|
66
|
-
if (this._blockMap.has(id)) {
|
|
67
|
-
return this._blockMap.get(id) || null;
|
|
68
|
-
}
|
|
69
|
-
const block = this.doc.getBlock(id);
|
|
70
|
-
if (!block)
|
|
71
|
-
return null;
|
|
72
|
-
const mockComponent = this._createMockBlockComponent(block);
|
|
73
|
-
this._blockMap.set(id, mockComponent);
|
|
74
|
-
return mockComponent;
|
|
75
|
-
}
|
|
76
|
-
setBlock(node) {
|
|
77
|
-
if (this._blockMap.has(node.model.id)) {
|
|
78
|
-
this.deleteBlock(node);
|
|
79
|
-
}
|
|
80
|
-
this._blockMap.set(node.model.id, node);
|
|
81
|
-
this.viewUpdated.next({
|
|
82
|
-
id: node.model.id,
|
|
83
|
-
method: 'add',
|
|
84
|
-
type: 'block',
|
|
85
|
-
view: node,
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
_createMockBlockComponent(block) {
|
|
89
|
-
const role = this._determineBlockRole(block);
|
|
90
|
-
const mockComponent = {
|
|
91
|
-
id: block.id,
|
|
92
|
-
model: block,
|
|
93
|
-
flavour: block.flavour,
|
|
94
|
-
role,
|
|
95
|
-
parentElement: null,
|
|
96
|
-
children: [],
|
|
97
|
-
closest: () => null,
|
|
98
|
-
querySelector: () => null,
|
|
99
|
-
querySelectorAll: () => [],
|
|
100
|
-
};
|
|
101
|
-
this._setupParentChildRelationships(mockComponent);
|
|
102
|
-
return mockComponent;
|
|
103
|
-
}
|
|
104
|
-
_determineBlockRole(block) {
|
|
105
|
-
if (block.flavour.includes('paragraph') ||
|
|
106
|
-
block.flavour.includes('list') ||
|
|
107
|
-
block.flavour.includes('list-item') ||
|
|
108
|
-
block.flavour.includes('text')) {
|
|
109
|
-
return 'content';
|
|
110
|
-
}
|
|
111
|
-
return 'root';
|
|
112
|
-
}
|
|
113
|
-
_setupParentChildRelationships(component) {
|
|
114
|
-
const parentId = component.model.parentId;
|
|
115
|
-
if (parentId) {
|
|
116
|
-
const parentComponent = this.getBlock(parentId);
|
|
117
|
-
if (parentComponent) {
|
|
118
|
-
component.parentElement = parentComponent;
|
|
119
|
-
if (!parentComponent.children.find(child => child.id === component.id)) {
|
|
120
|
-
parentComponent.children.push(component);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
try {
|
|
125
|
-
const childIds = component.model.children?.map((child) => typeof child === 'string' ? child : child.id) || [];
|
|
126
|
-
for (const childId of childIds) {
|
|
127
|
-
const childBlock = this.doc.getBlock(childId);
|
|
128
|
-
if (childBlock) {
|
|
129
|
-
const childComponent = this.getBlock(childId) ||
|
|
130
|
-
this._createMockBlockComponent(childBlock);
|
|
131
|
-
if (!component.children.find(child => child.id === childComponent.id)) {
|
|
132
|
-
component.children.push(childComponent);
|
|
133
|
-
childComponent.parentElement = component;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
catch {
|
|
139
|
-
// ignore
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
dispose() {
|
|
143
|
-
this._blockMap.clear();
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Create a test host object
|
|
148
|
-
*
|
|
149
|
-
* This function creates a mock host object that includes doc and command properties,
|
|
150
|
-
* which can be used for testing command execution.
|
|
151
|
-
*
|
|
152
|
-
* Usage:
|
|
153
|
-
* ```typescript
|
|
154
|
-
* const doc = affine`<affine-page></affine-page>`;
|
|
155
|
-
* const host = createTestHost(doc);
|
|
156
|
-
*
|
|
157
|
-
* // Use host.command.exec to execute commands
|
|
158
|
-
* const [_, result] = host.command.exec(someCommand, {
|
|
159
|
-
* // command params
|
|
160
|
-
* });
|
|
161
|
-
* ```
|
|
162
|
-
*
|
|
163
|
-
* @param doc Document object
|
|
164
|
-
* @returns Host object containing doc and command
|
|
165
|
-
*/
|
|
166
|
-
export function createTestHost(doc) {
|
|
167
|
-
const std = {
|
|
168
|
-
host: undefined,
|
|
169
|
-
view: new MockViewStore(doc),
|
|
170
|
-
command: undefined,
|
|
171
|
-
selection: undefined,
|
|
172
|
-
};
|
|
173
|
-
const host = {
|
|
174
|
-
store: doc,
|
|
175
|
-
std: std,
|
|
176
|
-
selection: undefined,
|
|
177
|
-
};
|
|
178
|
-
host.store = doc;
|
|
179
|
-
host.std = std;
|
|
180
|
-
std.host = host;
|
|
181
|
-
std.selection = new MockSelectionStore();
|
|
182
|
-
std.command = new CommandManager(std);
|
|
183
|
-
// @ts-expect-error dev-only
|
|
184
|
-
host.command = std.command;
|
|
185
|
-
host.selection = std.selection;
|
|
186
|
-
return host;
|
|
187
|
-
}
|