@kritzel/engine 0.4.31
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/LICENSE.md +50 -0
- package/dist/cjs/app-globals-V2Kpy_OQ.js +5 -0
- package/dist/cjs/engine.constants-CakmdKMW.js +28206 -0
- package/dist/cjs/index-BbbWU2aN.js +1742 -0
- package/dist/cjs/index.cjs.js +4232 -0
- package/dist/cjs/kritzel-awareness-cursors_5.cjs.entry.js +28004 -0
- package/dist/cjs/loader.cjs.js +13 -0
- package/dist/cjs/stencil.cjs.js +25 -0
- package/dist/collection/classes/core/core.class.js +1389 -0
- package/dist/collection/classes/core/reviver.class.js +124 -0
- package/dist/collection/classes/core/store.class.js +337 -0
- package/dist/collection/classes/core/viewport.class.js +794 -0
- package/dist/collection/classes/core/workspace.class.js +112 -0
- package/dist/collection/classes/handlers/base.handler.js +20 -0
- package/dist/collection/classes/handlers/context-menu.handler.js +170 -0
- package/dist/collection/classes/handlers/hover.handler.js +35 -0
- package/dist/collection/classes/handlers/key.handler.js +162 -0
- package/dist/collection/classes/handlers/line-handle.handler.js +475 -0
- package/dist/collection/classes/handlers/move.handler.js +295 -0
- package/dist/collection/classes/handlers/resize.handler.js +327 -0
- package/dist/collection/classes/handlers/rotation.handler.js +174 -0
- package/dist/collection/classes/handlers/selection.handler.js +526 -0
- package/dist/collection/classes/managers/anchor.manager.js +1476 -0
- package/dist/collection/classes/managers/browser-permission.manager.js +64 -0
- package/dist/collection/classes/managers/clipboard.manager.js +346 -0
- package/dist/collection/classes/managers/clipboard.types.js +1 -0
- package/dist/collection/classes/managers/cursor.manager.js +139 -0
- package/dist/collection/classes/managers/license.manager.js +341 -0
- package/dist/collection/classes/managers/localization.manager.js +227 -0
- package/dist/collection/classes/managers/theme.manager.js +206 -0
- package/dist/collection/classes/objects/base-object.class.js +462 -0
- package/dist/collection/classes/objects/dynamic-object.class.js +437 -0
- package/dist/collection/classes/objects/group.class.js +590 -0
- package/dist/collection/classes/objects/image.class.js +500 -0
- package/dist/collection/classes/objects/line.class.js +789 -0
- package/dist/collection/classes/objects/path.class.js +578 -0
- package/dist/collection/classes/objects/selection-box.class.js +32 -0
- package/dist/collection/classes/objects/selection-group.class.js +752 -0
- package/dist/collection/classes/objects/shape.class.js +628 -0
- package/dist/collection/classes/objects/text.class.js +461 -0
- package/dist/collection/classes/providers/assets/asset-resolver.class.js +536 -0
- package/dist/collection/classes/providers/assets/http-asset-provider.class.js +111 -0
- package/dist/collection/classes/providers/assets/indexeddb-asset-provider.class.js +241 -0
- package/dist/collection/classes/providers/assets/presigned-asset-provider.class.js +86 -0
- package/dist/collection/classes/providers/paste-intent/event-paste-intent.provider.js +48 -0
- package/dist/collection/classes/providers/paste-intent/ios-paste-intent.provider.js +16 -0
- package/dist/collection/classes/providers/paste-intent/navigator-paste-intent.provider.js +86 -0
- package/dist/collection/classes/providers/sync/broadcast-sync-provider.class.js +100 -0
- package/dist/collection/classes/providers/sync/hocuspocus-sync-provider.class.js +333 -0
- package/dist/collection/classes/providers/sync/in-memory-sync-provider.class.js +69 -0
- package/dist/collection/classes/providers/sync/indexeddb-sync-provider.class.js +39 -0
- package/dist/collection/classes/providers/sync/websocket-sync-provider.class.js +110 -0
- package/dist/collection/classes/registries/dynamic-object-renderer.registry.js +52 -0
- package/dist/collection/classes/registries/font-registry.class.js +161 -0
- package/dist/collection/classes/registries/icon-registry.class.js +118 -0
- package/dist/collection/classes/registries/paste-intent-provider.registry.js +26 -0
- package/dist/collection/classes/registries/tool.registry.js +69 -0
- package/dist/collection/classes/structures/app-state-map.structure.js +461 -0
- package/dist/collection/classes/structures/object-map.structure.js +1103 -0
- package/dist/collection/classes/structures/quadtree.structure.js +251 -0
- package/dist/collection/classes/tools/base-tool.class.js +88 -0
- package/dist/collection/classes/tools/brush-tool.class.js +236 -0
- package/dist/collection/classes/tools/eraser-tool.class.js +133 -0
- package/dist/collection/classes/tools/image-tool.class.js +152 -0
- package/dist/collection/classes/tools/line-tool.class.js +249 -0
- package/dist/collection/classes/tools/selection-tool.class.js +611 -0
- package/dist/collection/classes/tools/shape-tool.class.js +251 -0
- package/dist/collection/classes/tools/text-tool.class.js +179 -0
- package/dist/collection/collection-manifest.json +17 -0
- package/dist/collection/components/kritzel-awareness-cursors/kritzel-awareness-cursors.css +115 -0
- package/dist/collection/components/kritzel-awareness-cursors/kritzel-awareness-cursors.js +380 -0
- package/dist/collection/components/kritzel-cursor-trail/kritzel-cursor-trail.css +10 -0
- package/dist/collection/components/kritzel-cursor-trail/kritzel-cursor-trail.js +153 -0
- package/dist/collection/components/kritzel-engine/kritzel-engine.css +81 -0
- package/dist/collection/components/kritzel-engine/kritzel-engine.js +6345 -0
- package/dist/collection/components/kritzel-icon/kritzel-icon.css +18 -0
- package/dist/collection/components/kritzel-icon/kritzel-icon.js +93 -0
- package/dist/collection/components/kritzel-watermark/kritzel-watermark.css +29 -0
- package/dist/collection/components/kritzel-watermark/kritzel-watermark.js +83 -0
- package/dist/collection/configs/default-asset-storage.config.js +9 -0
- package/dist/collection/configs/default-brush-tool.config.js +9 -0
- package/dist/collection/configs/default-engine-config.js +73 -0
- package/dist/collection/configs/default-line-tool.config.js +12 -0
- package/dist/collection/configs/default-shape-tool.config.js +15 -0
- package/dist/collection/configs/default-sync.config.js +6 -0
- package/dist/collection/configs/default-text-tool.config.js +12 -0
- package/dist/collection/constants/color-palette.constants.js +40 -0
- package/dist/collection/constants/core.constants.js +1 -0
- package/dist/collection/constants/engine.constants.js +4 -0
- package/dist/collection/constants/license.constants.js +25 -0
- package/dist/collection/constants/schema.constants.js +4 -0
- package/dist/collection/constants/storage.constants.js +1 -0
- package/dist/collection/constants/stroke-size.constants.js +2 -0
- package/dist/collection/constants/text-tool-fonts.constants.js +18 -0
- package/dist/collection/constants/version.js +6 -0
- package/dist/collection/enums/alignment.enum.js +9 -0
- package/dist/collection/enums/event-button.enum.js +6 -0
- package/dist/collection/enums/handle-type.enum.js +7 -0
- package/dist/collection/enums/shape-type.enum.js +6 -0
- package/dist/collection/events/active-workspace-change.event.js +1 -0
- package/dist/collection/events/editor-is-ready.event.js +1 -0
- package/dist/collection/events/login.event.js +1 -0
- package/dist/collection/helpers/alignment.helper.js +73 -0
- package/dist/collection/helpers/class.helper.js +5 -0
- package/dist/collection/helpers/color.helper.js +106 -0
- package/dist/collection/helpers/cursor.helper.js +57 -0
- package/dist/collection/helpers/devices.helper.js +28 -0
- package/dist/collection/helpers/event.helper.js +58 -0
- package/dist/collection/helpers/geometry.helper.js +149 -0
- package/dist/collection/helpers/html.helper.js +116 -0
- package/dist/collection/helpers/image-file.helper.js +6 -0
- package/dist/collection/helpers/keyboard.helper.js +55 -0
- package/dist/collection/helpers/localization.helper.js +25 -0
- package/dist/collection/helpers/math.helper.js +8 -0
- package/dist/collection/helpers/migration.helper.js +45 -0
- package/dist/collection/helpers/object.helper.js +29 -0
- package/dist/collection/helpers/svg-export.helper.js +655 -0
- package/dist/collection/helpers/theme.helper.js +77 -0
- package/dist/collection/helpers/tool-config.helper.js +63 -0
- package/dist/collection/helpers/wheel.helper.js +113 -0
- package/dist/collection/index.js +107 -0
- package/dist/collection/interfaces/anchor.interface.js +1 -0
- package/dist/collection/interfaces/arrow-head.interface.js +1 -0
- package/dist/collection/interfaces/asset-provider.interface.js +1 -0
- package/dist/collection/interfaces/asset-storage-config.interface.js +1 -0
- package/dist/collection/interfaces/asset.interface.js +1 -0
- package/dist/collection/interfaces/bounding-box.interface.js +1 -0
- package/dist/collection/interfaces/clonable.interface.js +1 -0
- package/dist/collection/interfaces/context-menu-item.interface.js +1 -0
- package/dist/collection/interfaces/context-menu-state.interface.js +1 -0
- package/dist/collection/interfaces/debug-info.interface.js +1 -0
- package/dist/collection/interfaces/dialog.interface.js +1 -0
- package/dist/collection/interfaces/document-metadata.interface.js +1 -0
- package/dist/collection/interfaces/dynamic-object-renderer.interface.js +1 -0
- package/dist/collection/interfaces/engine-state.interface.js +1 -0
- package/dist/collection/interfaces/font.interface.js +1 -0
- package/dist/collection/interfaces/localization.interface.js +1 -0
- package/dist/collection/interfaces/login-config.interface.js +1 -0
- package/dist/collection/interfaces/master-detail.interface.js +1 -0
- package/dist/collection/interfaces/menu-item.interface.js +1 -0
- package/dist/collection/interfaces/migration.interface.js +1 -0
- package/dist/collection/interfaces/notification.interface.js +1 -0
- package/dist/collection/interfaces/object-change-event.interface.js +1 -0
- package/dist/collection/interfaces/object-export.interface.js +1 -0
- package/dist/collection/interfaces/object.interface.js +1 -0
- package/dist/collection/interfaces/paste-intent-provider.interface.js +1 -0
- package/dist/collection/interfaces/point.interface.js +1 -0
- package/dist/collection/interfaces/polygon.interface.js +1 -0
- package/dist/collection/interfaces/remote-cursor.interface.js +1 -0
- package/dist/collection/interfaces/selection-state.interface.js +1 -0
- package/dist/collection/interfaces/serializable.interface.js +1 -0
- package/dist/collection/interfaces/settings.interface.js +1 -0
- package/dist/collection/interfaces/share.interface.js +1 -0
- package/dist/collection/interfaces/shortcut.interface.js +1 -0
- package/dist/collection/interfaces/sync-config.interface.js +21 -0
- package/dist/collection/interfaces/sync-provider.interface.js +1 -0
- package/dist/collection/interfaces/theme.interface.js +1 -0
- package/dist/collection/interfaces/tool-config.interface.js +1 -0
- package/dist/collection/interfaces/tool-type.interface.js +1 -0
- package/dist/collection/interfaces/tool.interface.js +1 -0
- package/dist/collection/interfaces/toolbar-item.interface.js +1 -0
- package/dist/collection/interfaces/undo-state.interface.js +1 -0
- package/dist/collection/interfaces/user.interface.js +1 -0
- package/dist/collection/interfaces/viewport-state.interface.js +1 -0
- package/dist/collection/locales/de-locale.js +119 -0
- package/dist/collection/locales/en-locale.js +120 -0
- package/dist/collection/locales/fr-locale.js +119 -0
- package/dist/collection/migrations/app-state.migrations.js +47 -0
- package/dist/collection/migrations/workspace.migrations.js +67 -0
- package/dist/collection/themes/dark-theme.js +340 -0
- package/dist/collection/themes/light-theme.js +346 -0
- package/dist/collection/types/deep-readonly.type.js +1 -0
- package/dist/collection/types/state.types.js +1 -0
- package/dist/components/index.d.ts +47 -0
- package/dist/components/index.js +4143 -0
- package/dist/components/kritzel-awareness-cursors.d.ts +11 -0
- package/dist/components/kritzel-awareness-cursors.js +6 -0
- package/dist/components/kritzel-cursor-trail.d.ts +11 -0
- package/dist/components/kritzel-cursor-trail.js +6 -0
- package/dist/components/kritzel-engine.d.ts +11 -0
- package/dist/components/kritzel-engine.js +52641 -0
- package/dist/components/kritzel-icon.d.ts +11 -0
- package/dist/components/kritzel-icon.js +6 -0
- package/dist/components/kritzel-watermark.d.ts +11 -0
- package/dist/components/kritzel-watermark.js +6 -0
- package/dist/components/p-B2Htv9ou.js +49 -0
- package/dist/components/p-BvRGQvVI.js +3456 -0
- package/dist/components/p-CfSx6HU_.js +1469 -0
- package/dist/components/p-YP8wAcF4.js +122 -0
- package/dist/components/p-fx6msYHJ.js +167 -0
- package/dist/esm/app-globals-DQuL1Twl.js +3 -0
- package/dist/esm/engine.constants-Bl5-pbq-.js +28143 -0
- package/dist/esm/index-BU9Mv7y0.js +1715 -0
- package/dist/esm/index.js +4134 -0
- package/dist/esm/kritzel-awareness-cursors_5.entry.js +27978 -0
- package/dist/esm/loader.js +11 -0
- package/dist/esm/stencil.js +21 -0
- package/dist/index.cjs.js +1 -0
- package/dist/index.js +1 -0
- package/dist/stencil/index.esm.js +4134 -0
- package/dist/stencil/p-BU9Mv7y0.js +1702 -0
- package/dist/stencil/p-Bl5-pbq-.js +28143 -0
- package/dist/stencil/p-DQuL1Twl.js +3 -0
- package/dist/stencil/p-f0a8b7af.entry.js +27978 -0
- package/dist/stencil/stencil.esm.js +21 -0
- package/dist/types/classes/core/core.class.d.ts +532 -0
- package/dist/types/classes/core/reviver.class.d.ts +32 -0
- package/dist/types/classes/core/store.class.d.ts +198 -0
- package/dist/types/classes/core/viewport.class.d.ts +256 -0
- package/dist/types/classes/core/workspace.class.d.ts +95 -0
- package/dist/types/classes/handlers/base.handler.d.ts +18 -0
- package/dist/types/classes/handlers/context-menu.handler.d.ts +67 -0
- package/dist/types/classes/handlers/hover.handler.d.ts +23 -0
- package/dist/types/classes/handlers/key.handler.d.ts +44 -0
- package/dist/types/classes/handlers/line-handle.handler.d.ts +115 -0
- package/dist/types/classes/handlers/move.handler.d.ts +94 -0
- package/dist/types/classes/handlers/resize.handler.d.ts +95 -0
- package/dist/types/classes/handlers/rotation.handler.d.ts +50 -0
- package/dist/types/classes/handlers/selection.handler.d.ts +153 -0
- package/dist/types/classes/managers/anchor.manager.d.ts +513 -0
- package/dist/types/classes/managers/browser-permission.manager.d.ts +41 -0
- package/dist/types/classes/managers/clipboard.manager.d.ts +71 -0
- package/dist/types/classes/managers/clipboard.types.d.ts +23 -0
- package/dist/types/classes/managers/cursor.manager.d.ts +66 -0
- package/dist/types/classes/managers/license.manager.d.ts +147 -0
- package/dist/types/classes/managers/localization.manager.d.ts +145 -0
- package/dist/types/classes/managers/theme.manager.d.ts +112 -0
- package/dist/types/classes/objects/base-object.class.d.ts +266 -0
- package/dist/types/classes/objects/dynamic-object.class.d.ts +148 -0
- package/dist/types/classes/objects/group.class.d.ts +231 -0
- package/dist/types/classes/objects/image.class.d.ts +246 -0
- package/dist/types/classes/objects/line.class.d.ts +285 -0
- package/dist/types/classes/objects/path.class.d.ts +220 -0
- package/dist/types/classes/objects/selection-box.class.d.ts +19 -0
- package/dist/types/classes/objects/selection-group.class.d.ts +267 -0
- package/dist/types/classes/objects/shape.class.d.ts +322 -0
- package/dist/types/classes/objects/text.class.d.ts +197 -0
- package/dist/types/classes/providers/assets/asset-resolver.class.d.ts +141 -0
- package/dist/types/classes/providers/assets/http-asset-provider.class.d.ts +79 -0
- package/dist/types/classes/providers/assets/indexeddb-asset-provider.class.d.ts +69 -0
- package/dist/types/classes/providers/assets/presigned-asset-provider.class.d.ts +69 -0
- package/dist/types/classes/providers/paste-intent/event-paste-intent.provider.d.ts +8 -0
- package/dist/types/classes/providers/paste-intent/ios-paste-intent.provider.d.ts +6 -0
- package/dist/types/classes/providers/paste-intent/navigator-paste-intent.provider.d.ts +9 -0
- package/dist/types/classes/providers/sync/broadcast-sync-provider.class.d.ts +23 -0
- package/dist/types/classes/providers/sync/hocuspocus-sync-provider.class.d.ts +163 -0
- package/dist/types/classes/providers/sync/in-memory-sync-provider.class.d.ts +39 -0
- package/dist/types/classes/providers/sync/indexeddb-sync-provider.class.d.ts +25 -0
- package/dist/types/classes/providers/sync/websocket-sync-provider.class.d.ts +63 -0
- package/dist/types/classes/registries/dynamic-object-renderer.registry.d.ts +32 -0
- package/dist/types/classes/registries/font-registry.class.d.ts +19 -0
- package/dist/types/classes/registries/icon-registry.class.d.ts +39 -0
- package/dist/types/classes/registries/paste-intent-provider.registry.d.ts +10 -0
- package/dist/types/classes/registries/tool.registry.d.ts +53 -0
- package/dist/types/classes/structures/app-state-map.structure.d.ts +171 -0
- package/dist/types/classes/structures/object-map.structure.d.ts +403 -0
- package/dist/types/classes/structures/quadtree.structure.d.ts +128 -0
- package/dist/types/classes/tools/base-tool.class.d.ts +72 -0
- package/dist/types/classes/tools/brush-tool.class.d.ts +68 -0
- package/dist/types/classes/tools/eraser-tool.class.d.ts +38 -0
- package/dist/types/classes/tools/image-tool.class.d.ts +74 -0
- package/dist/types/classes/tools/line-tool.class.d.ts +63 -0
- package/dist/types/classes/tools/selection-tool.class.d.ts +188 -0
- package/dist/types/classes/tools/shape-tool.class.d.ts +90 -0
- package/dist/types/classes/tools/text-tool.class.d.ts +66 -0
- package/dist/types/components/kritzel-awareness-cursors/kritzel-awareness-cursors.d.ts +29 -0
- package/dist/types/components/kritzel-cursor-trail/kritzel-cursor-trail.d.ts +19 -0
- package/dist/types/components/kritzel-engine/kritzel-engine.d.ts +695 -0
- package/dist/types/components/kritzel-icon/kritzel-icon.d.ts +6 -0
- package/dist/types/components/kritzel-watermark/kritzel-watermark.d.ts +20 -0
- package/dist/types/components.d.ts +981 -0
- package/dist/types/configs/default-asset-storage.config.d.ts +8 -0
- package/dist/types/configs/default-brush-tool.config.d.ts +2 -0
- package/dist/types/configs/default-engine-config.d.ts +2 -0
- package/dist/types/configs/default-line-tool.config.d.ts +2 -0
- package/dist/types/configs/default-shape-tool.config.d.ts +2 -0
- package/dist/types/configs/default-sync.config.d.ts +5 -0
- package/dist/types/configs/default-text-tool.config.d.ts +2 -0
- package/dist/types/constants/color-palette.constants.d.ts +31 -0
- package/dist/types/constants/core.constants.d.ts +0 -0
- package/dist/types/constants/engine.constants.d.ts +4 -0
- package/dist/types/constants/license.constants.d.ts +25 -0
- package/dist/types/constants/schema.constants.d.ts +4 -0
- package/dist/types/constants/storage.constants.d.ts +1 -0
- package/dist/types/constants/stroke-size.constants.d.ts +2 -0
- package/dist/types/constants/text-tool-fonts.constants.d.ts +3 -0
- package/dist/types/constants/version.d.ts +6 -0
- package/dist/types/enums/alignment.enum.d.ts +8 -0
- package/dist/types/enums/event-button.enum.d.ts +5 -0
- package/dist/types/enums/handle-type.enum.d.ts +6 -0
- package/dist/types/enums/shape-type.enum.d.ts +5 -0
- package/dist/types/events/active-workspace-change.event.d.ts +7 -0
- package/dist/types/events/editor-is-ready.event.d.ts +18 -0
- package/dist/types/events/login.event.d.ts +3 -0
- package/dist/types/helpers/alignment.helper.d.ts +21 -0
- package/dist/types/helpers/class.helper.d.ts +3 -0
- package/dist/types/helpers/color.helper.d.ts +34 -0
- package/dist/types/helpers/cursor.helper.d.ts +22 -0
- package/dist/types/helpers/devices.helper.d.ts +8 -0
- package/dist/types/helpers/event.helper.d.ts +6 -0
- package/dist/types/helpers/geometry.helper.d.ts +38 -0
- package/dist/types/helpers/html.helper.d.ts +8 -0
- package/dist/types/helpers/image-file.helper.d.ts +3 -0
- package/dist/types/helpers/keyboard.helper.d.ts +6 -0
- package/dist/types/helpers/localization.helper.d.ts +18 -0
- package/dist/types/helpers/math.helper.d.ts +4 -0
- package/dist/types/helpers/migration.helper.d.ts +30 -0
- package/dist/types/helpers/object.helper.d.ts +9 -0
- package/dist/types/helpers/svg-export.helper.d.ts +231 -0
- package/dist/types/helpers/theme.helper.d.ts +42 -0
- package/dist/types/helpers/tool-config.helper.d.ts +4 -0
- package/dist/types/helpers/wheel.helper.d.ts +9 -0
- package/dist/types/index.d.ts +109 -0
- package/dist/types/interfaces/anchor.interface.d.ts +147 -0
- package/dist/types/interfaces/arrow-head.interface.d.ts +27 -0
- package/dist/types/interfaces/asset-provider.interface.d.ts +88 -0
- package/dist/types/interfaces/asset-storage-config.interface.d.ts +40 -0
- package/dist/types/interfaces/asset.interface.d.ts +43 -0
- package/dist/types/interfaces/bounding-box.interface.d.ts +8 -0
- package/dist/types/interfaces/clonable.interface.d.ts +3 -0
- package/dist/types/interfaces/context-menu-item.interface.d.ts +25 -0
- package/dist/types/interfaces/context-menu-state.interface.d.ts +16 -0
- package/dist/types/interfaces/debug-info.interface.d.ts +7 -0
- package/dist/types/interfaces/dialog.interface.d.ts +4 -0
- package/dist/types/interfaces/document-metadata.interface.d.ts +6 -0
- package/dist/types/interfaces/dynamic-object-renderer.interface.d.ts +40 -0
- package/dist/types/interfaces/engine-state.interface.d.ts +82 -0
- package/dist/types/interfaces/font.interface.d.ts +15 -0
- package/dist/types/interfaces/localization.interface.d.ts +143 -0
- package/dist/types/interfaces/login-config.interface.d.ts +24 -0
- package/dist/types/interfaces/master-detail.interface.d.ts +14 -0
- package/dist/types/interfaces/menu-item.interface.d.ts +27 -0
- package/dist/types/interfaces/migration.interface.d.ts +16 -0
- package/dist/types/interfaces/notification.interface.d.ts +10 -0
- package/dist/types/interfaces/object-change-event.interface.d.ts +31 -0
- package/dist/types/interfaces/object-export.interface.d.ts +20 -0
- package/dist/types/interfaces/object.interface.d.ts +53 -0
- package/dist/types/interfaces/paste-intent-provider.interface.d.ts +10 -0
- package/dist/types/interfaces/point.interface.d.ts +4 -0
- package/dist/types/interfaces/polygon.interface.d.ts +7 -0
- package/dist/types/interfaces/remote-cursor.interface.d.ts +18 -0
- package/dist/types/interfaces/selection-state.interface.d.ts +7 -0
- package/dist/types/interfaces/serializable.interface.d.ts +5 -0
- package/dist/types/interfaces/settings.interface.d.ts +25 -0
- package/dist/types/interfaces/share.interface.d.ts +9 -0
- package/dist/types/interfaces/shortcut.interface.d.ts +10 -0
- package/dist/types/interfaces/sync-config.interface.d.ts +41 -0
- package/dist/types/interfaces/sync-provider.interface.d.ts +66 -0
- package/dist/types/interfaces/theme.interface.d.ts +553 -0
- package/dist/types/interfaces/tool-config.interface.d.ts +24 -0
- package/dist/types/interfaces/tool-type.interface.d.ts +1 -0
- package/dist/types/interfaces/tool.interface.d.ts +8 -0
- package/dist/types/interfaces/toolbar-item.interface.d.ts +66 -0
- package/dist/types/interfaces/undo-state.interface.d.ts +6 -0
- package/dist/types/interfaces/user.interface.d.ts +22 -0
- package/dist/types/interfaces/viewport-state.interface.d.ts +7 -0
- package/dist/types/locales/de-locale.d.ts +5 -0
- package/dist/types/locales/en-locale.d.ts +6 -0
- package/dist/types/locales/fr-locale.d.ts +5 -0
- package/dist/types/migrations/app-state.migrations.d.ts +11 -0
- package/dist/types/migrations/workspace.migrations.d.ts +11 -0
- package/dist/types/stencil-public-runtime.d.ts +1873 -0
- package/dist/types/themes/dark-theme.d.ts +5 -0
- package/dist/types/themes/light-theme.d.ts +5 -0
- package/dist/types/types/deep-readonly.type.d.ts +7 -0
- package/dist/types/types/state.types.d.ts +3 -0
- package/loader/cdn.js +1 -0
- package/loader/index.cjs.js +1 -0
- package/loader/index.d.ts +24 -0
- package/loader/index.es2017.js +1 -0
- package/loader/index.js +2 -0
- package/package.json +101 -0
- package/readme.md +11 -0
|
@@ -0,0 +1,461 @@
|
|
|
1
|
+
import * as Y from "yjs";
|
|
2
|
+
import { KritzelWorkspace } from "../core/workspace.class";
|
|
3
|
+
import { DEFAULT_SYNC_CONFIG } from "../../configs/default-sync.config";
|
|
4
|
+
import { APP_STATE_INSTANCE_ID_STORAGE_KEY } from "../../constants/storage.constants";
|
|
5
|
+
import { CURRENT_APP_STATE_SCHEMA_VERSION } from "../../constants/schema.constants";
|
|
6
|
+
import { ObjectHelper } from "../../helpers/object.helper";
|
|
7
|
+
import { runMigrations } from "../../helpers/migration.helper";
|
|
8
|
+
import { APP_STATE_MIGRATIONS } from "../../migrations/app-state.migrations";
|
|
9
|
+
/**
|
|
10
|
+
* Manages the application state for workspaces with Yjs-based synchronization support.
|
|
11
|
+
* This class provides a synchronized map of workspaces that can be shared across
|
|
12
|
+
* multiple clients using configurable sync providers (e.g., WebSocket, WebRTC).
|
|
13
|
+
*/
|
|
14
|
+
export class KritzelAppStateMap {
|
|
15
|
+
map;
|
|
16
|
+
_ydoc = null;
|
|
17
|
+
_workspacesMap = null;
|
|
18
|
+
_metadataMap = null;
|
|
19
|
+
_providers = [];
|
|
20
|
+
_core = null;
|
|
21
|
+
_isReady = false;
|
|
22
|
+
_onRemoteChangeCallback = null;
|
|
23
|
+
_workspacesObserver = null;
|
|
24
|
+
_networkSyncPromise = null;
|
|
25
|
+
/**
|
|
26
|
+
* Indicates whether the app state map has been initialized and is ready for use.
|
|
27
|
+
* @returns True if initialized and all providers are connected, false otherwise.
|
|
28
|
+
*/
|
|
29
|
+
get isReady() {
|
|
30
|
+
return this._isReady;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Settles when network providers finish their initial sync (or fail/time out).
|
|
34
|
+
* Resolves immediately when no network providers are configured.
|
|
35
|
+
*/
|
|
36
|
+
whenNetworkSynced() {
|
|
37
|
+
return this._networkSyncPromise ?? Promise.resolve();
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Indicates whether any configured sync provider replicates over the network.
|
|
41
|
+
* Used by the engine to warn when a matching remote asset storage
|
|
42
|
+
* provider is missing (images would otherwise only exist locally).
|
|
43
|
+
*/
|
|
44
|
+
get hasNetworkSyncProvider() {
|
|
45
|
+
return this._providers.some(p => p.type === 'network');
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Creates a new KritzelAppStateMap instance with an empty workspace map.
|
|
49
|
+
*/
|
|
50
|
+
constructor() {
|
|
51
|
+
this.map = new Map();
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Registers a callback function to be invoked when remote changes are received.
|
|
55
|
+
* This allows external code to react to workspace changes from other clients.
|
|
56
|
+
* @param callback - The function to call when remote changes occur.
|
|
57
|
+
*/
|
|
58
|
+
onRemoteChange(callback) {
|
|
59
|
+
this._onRemoteChangeCallback = callback;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Initializes the app state map with Yjs synchronization.
|
|
63
|
+
* Creates a dedicated Y.Doc for app state, sets up workspace observation,
|
|
64
|
+
* instantiates and connects all configured sync providers, and loads existing workspaces.
|
|
65
|
+
* @param core - The KritzelCore instance for triggering re-renders and accessing the store.
|
|
66
|
+
* @param config - Optional sync configuration specifying providers. Defaults to DEFAULT_SYNC_CONFIG.
|
|
67
|
+
* @returns A promise that resolves when all providers are connected and the state is loaded.
|
|
68
|
+
*/
|
|
69
|
+
async initialize(core, config) {
|
|
70
|
+
this._core = core;
|
|
71
|
+
// Create a dedicated Y.Doc for app state (workspaces)
|
|
72
|
+
this._ydoc = new Y.Doc();
|
|
73
|
+
this._workspacesMap = this._ydoc.getMap('workspaces');
|
|
74
|
+
this._metadataMap = this._ydoc.getMap('metadata');
|
|
75
|
+
const instanceId = config?.appStateId ?? this.getOrCreateAppStateInstanceId(core);
|
|
76
|
+
const docName = core.editorId ? `kritzel-app-state-${core.editorId}-${instanceId}` : `kritzel-app-state-${instanceId}`;
|
|
77
|
+
const finalConfig = config ?? DEFAULT_SYNC_CONFIG;
|
|
78
|
+
// Instantiate providers from configuration
|
|
79
|
+
const showSyncProviderInfo = !!core.store.state.debugInfo.showSyncProviderInfo;
|
|
80
|
+
const quiet = !showSyncProviderInfo;
|
|
81
|
+
for (const providerConfig of finalConfig.providers) {
|
|
82
|
+
let provider;
|
|
83
|
+
// Check if it's a class constructor or a factory
|
|
84
|
+
if (typeof providerConfig === 'function') {
|
|
85
|
+
// It's a class constructor
|
|
86
|
+
provider = new providerConfig(docName, this._ydoc, { quiet });
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
// It's a factory with a create method
|
|
90
|
+
provider = providerConfig.create(docName, this._ydoc, { quiet });
|
|
91
|
+
}
|
|
92
|
+
this._providers.push(provider);
|
|
93
|
+
}
|
|
94
|
+
if (showSyncProviderInfo) {
|
|
95
|
+
const providerList = this._providers.map(p => `${p.constructor.name} (${p.type})`).join(', ');
|
|
96
|
+
console.info(`[Kritzel] App-state sync providers initialized for ${docName}: ${providerList || 'none'}`);
|
|
97
|
+
}
|
|
98
|
+
// Observe changes to workspaces and sync with application state
|
|
99
|
+
this._workspacesObserver = event => {
|
|
100
|
+
this.handleWorkspacesChange(event);
|
|
101
|
+
};
|
|
102
|
+
this._workspacesMap.observe(this._workspacesObserver);
|
|
103
|
+
// Separate local providers (IndexedDB, BroadcastChannel) from network providers (Hocuspocus, WebSocket)
|
|
104
|
+
// Local providers are awaited so data is available immediately; network providers sync in the background
|
|
105
|
+
// via Yjs observers that are already registered above.
|
|
106
|
+
const localProviders = this._providers.filter(p => p.type === 'local');
|
|
107
|
+
const networkProviders = this._providers.filter(p => p.type === 'network');
|
|
108
|
+
// Await local providers for immediate data availability
|
|
109
|
+
const localResults = await Promise.allSettled(localProviders.map(p => p.connect()));
|
|
110
|
+
if (showSyncProviderInfo) {
|
|
111
|
+
const connectedLocalCount = localResults.filter(result => result.status === 'fulfilled').length;
|
|
112
|
+
console.info(`[Kritzel] App-state local providers connected: ${connectedLocalCount}/${localProviders.length}`);
|
|
113
|
+
}
|
|
114
|
+
localResults.forEach((result, i) => {
|
|
115
|
+
if (showSyncProviderInfo && result.status === 'rejected') {
|
|
116
|
+
console.error(`[Kritzel] Sync provider "${localProviders[i]?.constructor.name}" failed to connect:`, result.reason);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
// Connect network providers in the background (remote data arrives via Yjs observers)
|
|
120
|
+
if (showSyncProviderInfo && networkProviders.length > 0) {
|
|
121
|
+
console.info(`[Kritzel] App-state network providers connecting in background: ${networkProviders.length}`);
|
|
122
|
+
}
|
|
123
|
+
const networkConnectPromises = networkProviders.map(provider => provider.connect().catch(err => {
|
|
124
|
+
if (showSyncProviderInfo) {
|
|
125
|
+
console.error(`[Kritzel] Network sync provider "${provider.constructor.name}" failed to connect:`, err);
|
|
126
|
+
}
|
|
127
|
+
}));
|
|
128
|
+
if (networkConnectPromises.length > 0) {
|
|
129
|
+
this._networkSyncPromise = Promise.allSettled(networkConnectPromises).then(() => undefined);
|
|
130
|
+
}
|
|
131
|
+
this._isReady = true;
|
|
132
|
+
// Run any pending schema migrations before loading data
|
|
133
|
+
const quietMigrations = !core.store.state.debugInfo.showMigrationInfo;
|
|
134
|
+
runMigrations(this._ydoc, this._metadataMap, { workspaces: this._workspacesMap }, APP_STATE_MIGRATIONS, CURRENT_APP_STATE_SCHEMA_VERSION, { quiet: quietMigrations });
|
|
135
|
+
// Initialize document metadata (only if not already set by a previous client)
|
|
136
|
+
this.initializeMetadata('state');
|
|
137
|
+
// Load workspaces from Yjs
|
|
138
|
+
this.loadFromYjs();
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Resolves a stable instance identifier for the app-state document.
|
|
142
|
+
* The id is persisted in localStorage and reused across remounts/reloads.
|
|
143
|
+
* @param core - The core instance used to namespace the storage key by editorId.
|
|
144
|
+
* @returns A stable instance identifier.
|
|
145
|
+
* @throws Error when localStorage is unavailable or inaccessible.
|
|
146
|
+
*/
|
|
147
|
+
getOrCreateAppStateInstanceId(core) {
|
|
148
|
+
const storage = globalThis.localStorage;
|
|
149
|
+
if (!storage) {
|
|
150
|
+
throw new Error('[KritzelAppStateMap] localStorage is unavailable. Cannot persist app-state document identity.');
|
|
151
|
+
}
|
|
152
|
+
const storageKey = core.getStorageKey(APP_STATE_INSTANCE_ID_STORAGE_KEY);
|
|
153
|
+
let instanceId;
|
|
154
|
+
try {
|
|
155
|
+
instanceId = storage.getItem(storageKey);
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
throw new Error('[KritzelAppStateMap] Failed to read app-state instance id from localStorage.');
|
|
159
|
+
}
|
|
160
|
+
if (instanceId) {
|
|
161
|
+
return instanceId;
|
|
162
|
+
}
|
|
163
|
+
const generatedInstanceId = ObjectHelper.generateUUID();
|
|
164
|
+
try {
|
|
165
|
+
storage.setItem(storageKey, generatedInstanceId);
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
throw new Error('[KritzelAppStateMap] Failed to persist app-state instance id to localStorage.');
|
|
169
|
+
}
|
|
170
|
+
return generatedInstanceId;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Handles changes to the Yjs workspaces map.
|
|
174
|
+
* For local changes, only triggers a re-render. For remote changes, synchronizes
|
|
175
|
+
* the local map with the Yjs state by adding, updating, or deleting workspaces.
|
|
176
|
+
* @param event - The Yjs map event containing information about changed keys.
|
|
177
|
+
*/
|
|
178
|
+
handleWorkspacesChange(event) {
|
|
179
|
+
// Skip Map updates for local changes (already done), but still trigger re-render
|
|
180
|
+
if (event.transaction.origin === 'local') {
|
|
181
|
+
this._core?.rerender();
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
// Skip migration transactions — data will be loaded fresh via loadFromYjs()
|
|
185
|
+
if (event.transaction.origin === 'migration') {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
const changedKeys = Array.from(event.keysChanged);
|
|
189
|
+
const workspacesToUpdate = [];
|
|
190
|
+
const workspacesToDelete = [];
|
|
191
|
+
changedKeys.forEach(key => {
|
|
192
|
+
const change = event.changes.keys.get(key);
|
|
193
|
+
if (change && change.action === 'delete') {
|
|
194
|
+
workspacesToDelete.push(key);
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
const serialized = this._workspacesMap.get(key);
|
|
198
|
+
if (serialized) {
|
|
199
|
+
const workspace = this.reviveWorkspace(serialized);
|
|
200
|
+
workspacesToUpdate.push(workspace);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
// Delete workspaces from local map
|
|
205
|
+
workspacesToDelete.forEach(workspaceId => {
|
|
206
|
+
this.map.delete(workspaceId);
|
|
207
|
+
});
|
|
208
|
+
// Update or insert workspaces
|
|
209
|
+
workspacesToUpdate.forEach(workspace => {
|
|
210
|
+
this.map.set(workspace.id, workspace);
|
|
211
|
+
});
|
|
212
|
+
// Update the store's workspace list to reflect remote changes
|
|
213
|
+
if (this._core?.store) {
|
|
214
|
+
this._core.store.state.workspaces = this.allWorkspaces();
|
|
215
|
+
}
|
|
216
|
+
// Notify about remote changes
|
|
217
|
+
if (this._onRemoteChangeCallback) {
|
|
218
|
+
this._onRemoteChangeCallback();
|
|
219
|
+
}
|
|
220
|
+
this._core?.rerender();
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Reconstructs a KritzelWorkspace instance from its serialized form.
|
|
224
|
+
* Restores all properties including id, name, viewport, and timestamps.
|
|
225
|
+
* Handles both legacy { translateX, translateY } and new { centerWorldX, centerWorldY } viewport formats.
|
|
226
|
+
* @param serialized - The serialized workspace data object.
|
|
227
|
+
* @returns A fully reconstructed KritzelWorkspace instance.
|
|
228
|
+
*/
|
|
229
|
+
reviveWorkspace(serialized) {
|
|
230
|
+
let viewport = serialized.viewport;
|
|
231
|
+
// Backward compatibility: convert legacy translateX/translateY to centerWorldX/centerWorldY
|
|
232
|
+
if (viewport && 'translateX' in viewport && !('centerWorldX' in viewport)) {
|
|
233
|
+
const scale = viewport.scale ?? 1;
|
|
234
|
+
viewport = {
|
|
235
|
+
centerWorldX: -(viewport.translateX ?? 0) / scale,
|
|
236
|
+
centerWorldY: -(viewport.translateY ?? 0) / scale,
|
|
237
|
+
scale,
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
const workspace = new KritzelWorkspace({
|
|
241
|
+
id: serialized.id,
|
|
242
|
+
name: serialized.name,
|
|
243
|
+
viewport,
|
|
244
|
+
});
|
|
245
|
+
if (this._core) {
|
|
246
|
+
workspace._core = this._core;
|
|
247
|
+
}
|
|
248
|
+
workspace.createdAt = new Date(serialized.createdAt);
|
|
249
|
+
workspace.updatedAt = new Date(serialized.updatedAt);
|
|
250
|
+
workspace.isPublic = serialized.isPublic ?? false;
|
|
251
|
+
return workspace;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Initializes document metadata if not already set.
|
|
255
|
+
* Uses 'metadata' transaction origin to avoid triggering remote sync callbacks for local state.
|
|
256
|
+
*/
|
|
257
|
+
initializeMetadata(type) {
|
|
258
|
+
if (!this._metadataMap || !this._ydoc) {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
this._ydoc.transact(() => {
|
|
262
|
+
if (!this._metadataMap?.get('type')) {
|
|
263
|
+
this._metadataMap?.set('type', type);
|
|
264
|
+
}
|
|
265
|
+
if (this._metadataMap?.get('isPublic') === undefined) {
|
|
266
|
+
this._metadataMap?.set('isPublic', false);
|
|
267
|
+
}
|
|
268
|
+
if (this._metadataMap?.get('schemaVersion') === undefined) {
|
|
269
|
+
this._metadataMap?.set('schemaVersion', CURRENT_APP_STATE_SCHEMA_VERSION);
|
|
270
|
+
}
|
|
271
|
+
}, 'metadata');
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Returns whether the document is publicly accessible.
|
|
275
|
+
*/
|
|
276
|
+
getIsPublic() {
|
|
277
|
+
return this._metadataMap?.get('isPublic') ?? false;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Sets whether the document is publicly accessible.
|
|
281
|
+
* This change is synced to all connected clients and the server.
|
|
282
|
+
*/
|
|
283
|
+
setIsPublic(isPublic) {
|
|
284
|
+
if (!this._metadataMap || !this._ydoc) {
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
this._ydoc.transact(() => {
|
|
288
|
+
this._metadataMap?.set('isPublic', isPublic);
|
|
289
|
+
}, 'metadata');
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Returns the document type stored in metadata.
|
|
293
|
+
*/
|
|
294
|
+
getDocumentType() {
|
|
295
|
+
return this._metadataMap?.get('type') ?? 'state';
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Executes a callback within a Yjs transaction marked as 'local'.
|
|
299
|
+
* This allows batching multiple Yjs operations and identifying them as local changes.
|
|
300
|
+
* @param callback - The function containing Yjs operations to execute within the transaction.
|
|
301
|
+
*/
|
|
302
|
+
transaction(callback) {
|
|
303
|
+
if (this._ydoc) {
|
|
304
|
+
this._ydoc.transact(callback, 'local');
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Loads all workspaces from the Yjs map into the local map.
|
|
309
|
+
* Clears the existing local map and repopulates it by reviving each serialized workspace.
|
|
310
|
+
* This is typically called during initialization or when a full sync is needed.
|
|
311
|
+
*/
|
|
312
|
+
loadFromYjs() {
|
|
313
|
+
if (!this._workspacesMap) {
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
this.map.clear();
|
|
317
|
+
this._workspacesMap.forEach((serialized, key) => {
|
|
318
|
+
const workspace = this.reviveWorkspace(serialized);
|
|
319
|
+
this.map.set(key, workspace);
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Resets the app state by clearing both the local map and the Yjs workspaces map.
|
|
324
|
+
* This operation is performed within a local transaction to avoid triggering remote sync callbacks.
|
|
325
|
+
*/
|
|
326
|
+
reset() {
|
|
327
|
+
this.map.clear();
|
|
328
|
+
this._ydoc?.transact(() => {
|
|
329
|
+
this._workspacesMap?.clear();
|
|
330
|
+
}, 'local');
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Inserts a new workspace into both the local map and the Yjs map.
|
|
334
|
+
* The workspace is serialized before being stored in Yjs for synchronization.
|
|
335
|
+
* @param workspace - The workspace to insert.
|
|
336
|
+
* @returns True if the workspace was successfully inserted, false if it has no id.
|
|
337
|
+
*/
|
|
338
|
+
insert(workspace) {
|
|
339
|
+
if (!workspace.id) {
|
|
340
|
+
return false;
|
|
341
|
+
}
|
|
342
|
+
this.map.set(workspace.id, workspace);
|
|
343
|
+
if (this._workspacesMap) {
|
|
344
|
+
const serialized = workspace.serialize();
|
|
345
|
+
this._ydoc?.transact(() => {
|
|
346
|
+
this._workspacesMap?.set(workspace.id, serialized);
|
|
347
|
+
}, 'local');
|
|
348
|
+
}
|
|
349
|
+
return true;
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Updates an existing workspace in both the local map and the Yjs map.
|
|
353
|
+
* The workspace must already exist in the map to be updated.
|
|
354
|
+
* @param workspace - The workspace with updated data.
|
|
355
|
+
* @returns True if the workspace was successfully updated, false if it doesn't exist or has no id.
|
|
356
|
+
*/
|
|
357
|
+
update(workspace) {
|
|
358
|
+
if (!workspace.id || !this.map.has(workspace.id)) {
|
|
359
|
+
return false;
|
|
360
|
+
}
|
|
361
|
+
this.map.set(workspace.id, workspace);
|
|
362
|
+
if (this._workspacesMap) {
|
|
363
|
+
const serialized = workspace.serialize();
|
|
364
|
+
this._ydoc?.transact(() => {
|
|
365
|
+
this._workspacesMap?.set(workspace.id, serialized);
|
|
366
|
+
}, 'local');
|
|
367
|
+
}
|
|
368
|
+
return true;
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Removes a workspace matching the given predicate from both the local map and the Yjs map.
|
|
372
|
+
* Only the first matching workspace will be removed.
|
|
373
|
+
* @param predicate - A function that returns true for the workspace to remove.
|
|
374
|
+
* @returns True if a matching workspace was found and removed, false otherwise.
|
|
375
|
+
*/
|
|
376
|
+
remove(predicate) {
|
|
377
|
+
const workspaceToRemove = Array.from(this.map.values()).find(predicate);
|
|
378
|
+
if (!workspaceToRemove) {
|
|
379
|
+
return false;
|
|
380
|
+
}
|
|
381
|
+
this.map.delete(workspaceToRemove.id);
|
|
382
|
+
if (this._workspacesMap) {
|
|
383
|
+
this._ydoc?.transact(() => {
|
|
384
|
+
this._workspacesMap?.delete(workspaceToRemove.id);
|
|
385
|
+
}, 'local');
|
|
386
|
+
}
|
|
387
|
+
return true;
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Retrieves a workspace by its unique identifier.
|
|
391
|
+
* @param id - The unique identifier of the workspace to retrieve.
|
|
392
|
+
* @returns The workspace if found, undefined otherwise.
|
|
393
|
+
*/
|
|
394
|
+
get(id) {
|
|
395
|
+
return this.map.get(id);
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Returns all workspaces currently stored in the map.
|
|
399
|
+
* @returns An array containing all workspaces.
|
|
400
|
+
*/
|
|
401
|
+
allWorkspaces() {
|
|
402
|
+
return Array.from(this.map.values());
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Filters workspaces based on a predicate function.
|
|
406
|
+
* @param predicate - A function that returns true for workspaces to include.
|
|
407
|
+
* @returns An array of workspaces that match the predicate.
|
|
408
|
+
*/
|
|
409
|
+
filter(predicate) {
|
|
410
|
+
return Array.from(this.map.values()).filter(predicate);
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Finds the first workspace matching the given predicate.
|
|
414
|
+
* @param predicate - A function that returns true for the workspace to find.
|
|
415
|
+
* @returns The first matching workspace, or undefined if no match is found.
|
|
416
|
+
*/
|
|
417
|
+
find(predicate) {
|
|
418
|
+
return Array.from(this.map.values()).find(predicate);
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* Checks if a workspace with the given id exists in the map.
|
|
422
|
+
* @param id - The unique identifier of the workspace to check.
|
|
423
|
+
* @returns True if a workspace with the given id exists, false otherwise.
|
|
424
|
+
*/
|
|
425
|
+
has(id) {
|
|
426
|
+
return this.map.has(id);
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Destroys the app state map and releases all resources.
|
|
430
|
+
* Unobserves the Yjs workspaces map, disconnects and destroys all sync providers,
|
|
431
|
+
* clears all maps, destroys the Y.Doc, and resets all internal references.
|
|
432
|
+
* This should be called when the app state map is no longer needed.
|
|
433
|
+
*/
|
|
434
|
+
destroy() {
|
|
435
|
+
// Unobserve the workspaces map
|
|
436
|
+
if (this._workspacesMap && this._workspacesObserver) {
|
|
437
|
+
this._workspacesMap.unobserve(this._workspacesObserver);
|
|
438
|
+
this._workspacesObserver = null;
|
|
439
|
+
}
|
|
440
|
+
// Disconnect and destroy all providers
|
|
441
|
+
this._providers.forEach(p => {
|
|
442
|
+
p.disconnect();
|
|
443
|
+
p.destroy();
|
|
444
|
+
});
|
|
445
|
+
this._providers = [];
|
|
446
|
+
// Clear maps
|
|
447
|
+
this.map.clear();
|
|
448
|
+
this._workspacesMap = null;
|
|
449
|
+
this._metadataMap = null;
|
|
450
|
+
// Destroy Y.Doc
|
|
451
|
+
if (this._ydoc) {
|
|
452
|
+
this._ydoc.destroy();
|
|
453
|
+
this._ydoc = null;
|
|
454
|
+
}
|
|
455
|
+
// Clear remaining references
|
|
456
|
+
this._core = null;
|
|
457
|
+
this._onRemoteChangeCallback = null;
|
|
458
|
+
this._networkSyncPromise = null;
|
|
459
|
+
this._isReady = false;
|
|
460
|
+
}
|
|
461
|
+
}
|