@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,333 @@
|
|
|
1
|
+
import { HocuspocusProvider, HocuspocusProviderWebsocket } from "@hocuspocus/provider";
|
|
2
|
+
/**
|
|
3
|
+
* Hocuspocus sync provider for real-time collaboration
|
|
4
|
+
* Supports multiplexing - multiple documents can share the same WebSocket connection
|
|
5
|
+
*/
|
|
6
|
+
export class HocuspocusSyncProvider {
|
|
7
|
+
static type = 'network';
|
|
8
|
+
type = 'network';
|
|
9
|
+
provider;
|
|
10
|
+
isConnected = false;
|
|
11
|
+
isSynced = false;
|
|
12
|
+
usesSharedSocket = false;
|
|
13
|
+
isDestroyed = false;
|
|
14
|
+
connectTimeout = null;
|
|
15
|
+
pendingConnectReject = null;
|
|
16
|
+
connectionTimeoutMs;
|
|
17
|
+
_connectionStatus = 'disconnected';
|
|
18
|
+
visibilityHandler = null;
|
|
19
|
+
onlineHandler = null;
|
|
20
|
+
get awareness() {
|
|
21
|
+
return this.provider.awareness;
|
|
22
|
+
}
|
|
23
|
+
get rawProvider() {
|
|
24
|
+
return this.provider;
|
|
25
|
+
}
|
|
26
|
+
get connectionStatus() {
|
|
27
|
+
return this._connectionStatus;
|
|
28
|
+
}
|
|
29
|
+
// Static shared WebSocket instance for multiplexing
|
|
30
|
+
static sharedWebSocketProvider = null;
|
|
31
|
+
constructor(docName, doc, options) {
|
|
32
|
+
const name = options?.name || docName;
|
|
33
|
+
const url = options?.url || 'ws://localhost:1234';
|
|
34
|
+
this.connectionTimeoutMs = options?.connectionTimeout ?? 10000;
|
|
35
|
+
// Use provided websocketProvider or the static shared one
|
|
36
|
+
const websocketProvider = options?.websocketProvider || HocuspocusSyncProvider.sharedWebSocketProvider;
|
|
37
|
+
// Build reconnect config from options
|
|
38
|
+
const reconnectConfig = {};
|
|
39
|
+
if (options?.delay !== undefined)
|
|
40
|
+
reconnectConfig.delay = options.delay;
|
|
41
|
+
if (options?.factor !== undefined)
|
|
42
|
+
reconnectConfig.factor = options.factor;
|
|
43
|
+
if (options?.maxAttempts !== undefined)
|
|
44
|
+
reconnectConfig.maxAttempts = options.maxAttempts;
|
|
45
|
+
if (options?.minDelay !== undefined)
|
|
46
|
+
reconnectConfig.minDelay = options.minDelay;
|
|
47
|
+
if (options?.maxDelay !== undefined)
|
|
48
|
+
reconnectConfig.maxDelay = options.maxDelay;
|
|
49
|
+
const onConnect = () => {
|
|
50
|
+
if (this.isDestroyed) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
this.isConnected = true;
|
|
54
|
+
this._connectionStatus = 'connected';
|
|
55
|
+
if (!options?.quiet) {
|
|
56
|
+
console.info(`Hocuspocus connected: ${name}`);
|
|
57
|
+
}
|
|
58
|
+
if (options?.onConnect) {
|
|
59
|
+
options.onConnect();
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const onDisconnect = () => {
|
|
63
|
+
if (this.isDestroyed) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
this.isConnected = false;
|
|
67
|
+
this.isSynced = false;
|
|
68
|
+
this._connectionStatus = 'disconnected';
|
|
69
|
+
if (!options?.quiet) {
|
|
70
|
+
console.info(`Hocuspocus disconnected: ${name}`);
|
|
71
|
+
}
|
|
72
|
+
if (options?.onDisconnect) {
|
|
73
|
+
options.onDisconnect();
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const onSynced = () => {
|
|
77
|
+
if (this.isDestroyed) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
this.isSynced = true;
|
|
81
|
+
this._connectionStatus = 'synced';
|
|
82
|
+
if (!options?.quiet) {
|
|
83
|
+
console.info(`Hocuspocus synced: ${name}`);
|
|
84
|
+
}
|
|
85
|
+
if (options?.onSynced) {
|
|
86
|
+
options.onSynced();
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
const onStatus = (data) => {
|
|
90
|
+
if (this.isDestroyed) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (data.status === 'connecting') {
|
|
94
|
+
this._connectionStatus = 'connecting';
|
|
95
|
+
}
|
|
96
|
+
if (options?.onStatus) {
|
|
97
|
+
options.onStatus(data);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
if (websocketProvider) {
|
|
101
|
+
// Multiplexing mode - use shared WebSocket connection
|
|
102
|
+
this.usesSharedSocket = true;
|
|
103
|
+
const config = {
|
|
104
|
+
websocketProvider,
|
|
105
|
+
name,
|
|
106
|
+
document: doc,
|
|
107
|
+
token: options?.token || null,
|
|
108
|
+
onStatus,
|
|
109
|
+
onConnect,
|
|
110
|
+
onDisconnect,
|
|
111
|
+
onSynced,
|
|
112
|
+
...reconnectConfig,
|
|
113
|
+
};
|
|
114
|
+
// Add optional settings
|
|
115
|
+
if (options?.forceSyncInterval !== undefined) {
|
|
116
|
+
config.forceSyncInterval = options.forceSyncInterval;
|
|
117
|
+
}
|
|
118
|
+
if (options?.onAuthenticationFailed) {
|
|
119
|
+
config.onAuthenticationFailed = options.onAuthenticationFailed;
|
|
120
|
+
}
|
|
121
|
+
this.provider = new HocuspocusProvider(config);
|
|
122
|
+
// Must call attach() explicitly when using shared socket
|
|
123
|
+
this.provider.attach();
|
|
124
|
+
if (!options?.quiet) {
|
|
125
|
+
console.info(`Hocuspocus Provider initialized (multiplexed): ${name}`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
// Standalone mode - create own WebSocket connection
|
|
130
|
+
this.usesSharedSocket = false;
|
|
131
|
+
const config = {
|
|
132
|
+
url,
|
|
133
|
+
name,
|
|
134
|
+
document: doc,
|
|
135
|
+
token: options?.token || null,
|
|
136
|
+
autoConnect: false,
|
|
137
|
+
onStatus,
|
|
138
|
+
onConnect,
|
|
139
|
+
onDisconnect,
|
|
140
|
+
onSynced,
|
|
141
|
+
...reconnectConfig,
|
|
142
|
+
};
|
|
143
|
+
// Add optional settings
|
|
144
|
+
if (options?.forceSyncInterval !== undefined) {
|
|
145
|
+
config.forceSyncInterval = options.forceSyncInterval;
|
|
146
|
+
}
|
|
147
|
+
if (options?.onAuthenticationFailed) {
|
|
148
|
+
config.onAuthenticationFailed = options.onAuthenticationFailed;
|
|
149
|
+
}
|
|
150
|
+
if (options?.WebSocketPolyfill) {
|
|
151
|
+
config.WebSocketPolyfill = options.WebSocketPolyfill;
|
|
152
|
+
}
|
|
153
|
+
this.provider = new HocuspocusProvider(config);
|
|
154
|
+
if (!options?.quiet) {
|
|
155
|
+
console.info(`Hocuspocus Provider initialized: ${url}/${name}`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
this.setupBrowserEventListeners();
|
|
159
|
+
}
|
|
160
|
+
setupBrowserEventListeners() {
|
|
161
|
+
if (typeof document !== 'undefined') {
|
|
162
|
+
this.visibilityHandler = () => {
|
|
163
|
+
if (document.visibilityState === 'visible' && !this.isConnected && !this.isDestroyed) {
|
|
164
|
+
this.provider.connect();
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
document.addEventListener('visibilitychange', this.visibilityHandler);
|
|
168
|
+
}
|
|
169
|
+
if (typeof window !== 'undefined') {
|
|
170
|
+
this.onlineHandler = () => {
|
|
171
|
+
if (!this.isConnected && !this.isDestroyed) {
|
|
172
|
+
this.provider.connect();
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
window.addEventListener('online', this.onlineHandler);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
removeBrowserEventListeners() {
|
|
179
|
+
if (this.visibilityHandler && typeof document !== 'undefined') {
|
|
180
|
+
document.removeEventListener('visibilitychange', this.visibilityHandler);
|
|
181
|
+
this.visibilityHandler = null;
|
|
182
|
+
}
|
|
183
|
+
if (this.onlineHandler && typeof window !== 'undefined') {
|
|
184
|
+
window.removeEventListener('online', this.onlineHandler);
|
|
185
|
+
this.onlineHandler = null;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Create a shared WebSocket connection for multiplexing
|
|
190
|
+
* Call this once to create a shared connection that multiple providers can use
|
|
191
|
+
*/
|
|
192
|
+
static createSharedWebSocket(options) {
|
|
193
|
+
if (HocuspocusSyncProvider.sharedWebSocketProvider) {
|
|
194
|
+
console.warn('Shared WebSocket already exists. Returning existing instance.');
|
|
195
|
+
return HocuspocusSyncProvider.sharedWebSocketProvider;
|
|
196
|
+
}
|
|
197
|
+
const config = {
|
|
198
|
+
url: options.url,
|
|
199
|
+
};
|
|
200
|
+
if (options.WebSocketPolyfill) {
|
|
201
|
+
config.WebSocketPolyfill = options.WebSocketPolyfill;
|
|
202
|
+
}
|
|
203
|
+
if (options.onConnect) {
|
|
204
|
+
config.onConnect = options.onConnect;
|
|
205
|
+
}
|
|
206
|
+
if (options.onDisconnect) {
|
|
207
|
+
config.onDisconnect = options.onDisconnect;
|
|
208
|
+
}
|
|
209
|
+
if (options.onStatus) {
|
|
210
|
+
config.onStatus = options.onStatus;
|
|
211
|
+
}
|
|
212
|
+
HocuspocusSyncProvider.sharedWebSocketProvider = new HocuspocusProviderWebsocket(config);
|
|
213
|
+
console.info(`Shared Hocuspocus WebSocket created: ${options.url}`);
|
|
214
|
+
return HocuspocusSyncProvider.sharedWebSocketProvider;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Destroy the shared WebSocket connection
|
|
218
|
+
* Call this when you're done with all multiplexed providers
|
|
219
|
+
*/
|
|
220
|
+
static destroySharedWebSocket() {
|
|
221
|
+
if (HocuspocusSyncProvider.sharedWebSocketProvider) {
|
|
222
|
+
HocuspocusSyncProvider.sharedWebSocketProvider.destroy();
|
|
223
|
+
HocuspocusSyncProvider.sharedWebSocketProvider = null;
|
|
224
|
+
console.info('Shared Hocuspocus WebSocket destroyed');
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Get the shared WebSocket provider instance (if it exists)
|
|
229
|
+
*/
|
|
230
|
+
static getSharedWebSocket() {
|
|
231
|
+
return HocuspocusSyncProvider.sharedWebSocketProvider;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Static factory method for creating HocuspocusSyncProvider with configuration options
|
|
235
|
+
* Returns a ProviderFactory that can be used in sync configuration
|
|
236
|
+
*/
|
|
237
|
+
static with(options) {
|
|
238
|
+
return {
|
|
239
|
+
type: 'network',
|
|
240
|
+
create: (docName, doc, runtimeOptions) => {
|
|
241
|
+
const mergedOptions = runtimeOptions ? { ...options, ...runtimeOptions } : options;
|
|
242
|
+
return new HocuspocusSyncProvider(docName, doc, mergedOptions);
|
|
243
|
+
},
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
async connect() {
|
|
247
|
+
if (this.isSynced || this.isDestroyed) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
this._connectionStatus = 'connecting';
|
|
251
|
+
return new Promise((resolve, reject) => {
|
|
252
|
+
// Store reject function so we can cancel the connection if destroyed
|
|
253
|
+
this.pendingConnectReject = reject;
|
|
254
|
+
this.connectTimeout = setTimeout(() => {
|
|
255
|
+
this.pendingConnectReject = null;
|
|
256
|
+
this.connectTimeout = null;
|
|
257
|
+
reject(new Error('Hocuspocus connection timeout'));
|
|
258
|
+
}, this.connectionTimeoutMs);
|
|
259
|
+
const syncHandler = () => {
|
|
260
|
+
if (this.connectTimeout) {
|
|
261
|
+
clearTimeout(this.connectTimeout);
|
|
262
|
+
this.connectTimeout = null;
|
|
263
|
+
}
|
|
264
|
+
this.pendingConnectReject = null;
|
|
265
|
+
this.provider.off('synced', syncHandler);
|
|
266
|
+
if (!this.isDestroyed) {
|
|
267
|
+
resolve();
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
this.provider.on('synced', syncHandler);
|
|
271
|
+
// If already synced, resolve immediately
|
|
272
|
+
if (this.provider.isSynced) {
|
|
273
|
+
if (this.connectTimeout) {
|
|
274
|
+
clearTimeout(this.connectTimeout);
|
|
275
|
+
this.connectTimeout = null;
|
|
276
|
+
}
|
|
277
|
+
this.pendingConnectReject = null;
|
|
278
|
+
this.provider.off('synced', syncHandler);
|
|
279
|
+
resolve();
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
// Connect if not already connected (standalone mode only)
|
|
283
|
+
if (!this.isConnected && !this.usesSharedSocket) {
|
|
284
|
+
this.provider.connect();
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
async reconnect() {
|
|
289
|
+
this.disconnect();
|
|
290
|
+
return this.connect();
|
|
291
|
+
}
|
|
292
|
+
disconnect() {
|
|
293
|
+
// Cancel any pending connection attempt
|
|
294
|
+
if (this.connectTimeout) {
|
|
295
|
+
clearTimeout(this.connectTimeout);
|
|
296
|
+
this.connectTimeout = null;
|
|
297
|
+
}
|
|
298
|
+
if (this.pendingConnectReject) {
|
|
299
|
+
this.pendingConnectReject = null; // Don't reject, just abandon the promise
|
|
300
|
+
}
|
|
301
|
+
if (this.provider) {
|
|
302
|
+
if (this.usesSharedSocket) {
|
|
303
|
+
// Detach from shared socket instead of disconnecting
|
|
304
|
+
this.provider.detach();
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
this.provider.disconnect();
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
this.isConnected = false;
|
|
311
|
+
this.isSynced = false;
|
|
312
|
+
this._connectionStatus = 'disconnected';
|
|
313
|
+
}
|
|
314
|
+
destroy() {
|
|
315
|
+
// Mark as destroyed first to prevent any callbacks from doing work
|
|
316
|
+
this.isDestroyed = true;
|
|
317
|
+
// Cancel any pending connection attempt
|
|
318
|
+
if (this.connectTimeout) {
|
|
319
|
+
clearTimeout(this.connectTimeout);
|
|
320
|
+
this.connectTimeout = null;
|
|
321
|
+
}
|
|
322
|
+
if (this.pendingConnectReject) {
|
|
323
|
+
this.pendingConnectReject = null; // Don't reject, just abandon the promise
|
|
324
|
+
}
|
|
325
|
+
this.removeBrowserEventListeners();
|
|
326
|
+
if (this.provider) {
|
|
327
|
+
this.provider.destroy();
|
|
328
|
+
}
|
|
329
|
+
this.isConnected = false;
|
|
330
|
+
this.isSynced = false;
|
|
331
|
+
this._connectionStatus = 'disconnected';
|
|
332
|
+
}
|
|
333
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import * as Y from "yjs";
|
|
2
|
+
/**
|
|
3
|
+
* Module-scoped cache that survives component removal and remounting
|
|
4
|
+
* within the same JS runtime. Cleared on page reload.
|
|
5
|
+
*/
|
|
6
|
+
const sessionCache = new Map();
|
|
7
|
+
/**
|
|
8
|
+
* In-memory sync provider for session-scoped persistence.
|
|
9
|
+
*
|
|
10
|
+
* State survives the component being removed from the DOM and later
|
|
11
|
+
* re-added within the same page session, but is lost on page reload.
|
|
12
|
+
* Intended for documentation demos where durable IndexedDB persistence
|
|
13
|
+
* is not desired.
|
|
14
|
+
*/
|
|
15
|
+
export class InMemorySyncProvider {
|
|
16
|
+
static type = 'local';
|
|
17
|
+
type = 'local';
|
|
18
|
+
doc;
|
|
19
|
+
cacheKey;
|
|
20
|
+
isConnected = false;
|
|
21
|
+
constructor(docName, doc, options) {
|
|
22
|
+
this.doc = doc;
|
|
23
|
+
this.cacheKey = options?.name ?? docName;
|
|
24
|
+
}
|
|
25
|
+
handleUpdate = (_update, origin) => {
|
|
26
|
+
// Skip updates that originated from connect() rehydration to avoid a
|
|
27
|
+
// redundant re-encode of the state we just applied.
|
|
28
|
+
if (origin === this) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
sessionCache.set(this.cacheKey, Y.encodeStateAsUpdate(this.doc));
|
|
32
|
+
};
|
|
33
|
+
async connect() {
|
|
34
|
+
if (this.isConnected) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const cached = sessionCache.get(this.cacheKey);
|
|
38
|
+
if (cached) {
|
|
39
|
+
Y.applyUpdate(this.doc, cached, this);
|
|
40
|
+
}
|
|
41
|
+
this.doc.on('update', this.handleUpdate);
|
|
42
|
+
this.isConnected = true;
|
|
43
|
+
}
|
|
44
|
+
disconnect() {
|
|
45
|
+
this.isConnected = false;
|
|
46
|
+
}
|
|
47
|
+
async reconnect() {
|
|
48
|
+
this.disconnect();
|
|
49
|
+
return this.connect();
|
|
50
|
+
}
|
|
51
|
+
destroy() {
|
|
52
|
+
this.doc.off('update', this.handleUpdate);
|
|
53
|
+
this.isConnected = false;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Clears the in-memory cache.
|
|
57
|
+
*
|
|
58
|
+
* @param name - If provided, only the entry with this cache key is removed.
|
|
59
|
+
* If omitted, all entries are cleared.
|
|
60
|
+
*/
|
|
61
|
+
static clear(name) {
|
|
62
|
+
if (name !== undefined) {
|
|
63
|
+
sessionCache.delete(name);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
sessionCache.clear();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { IndexeddbPersistence } from "y-indexeddb";
|
|
2
|
+
/**
|
|
3
|
+
* IndexedDB sync provider for local persistence
|
|
4
|
+
*/
|
|
5
|
+
export class IndexedDBSyncProvider {
|
|
6
|
+
static type = 'local';
|
|
7
|
+
type = 'local';
|
|
8
|
+
provider;
|
|
9
|
+
isConnected = false;
|
|
10
|
+
constructor(docName, doc, options) {
|
|
11
|
+
const dbName = options?.name || docName;
|
|
12
|
+
this.provider = new IndexeddbPersistence(dbName, doc);
|
|
13
|
+
}
|
|
14
|
+
async connect() {
|
|
15
|
+
if (this.isConnected) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
return new Promise(resolve => {
|
|
19
|
+
this.provider.on('synced', () => {
|
|
20
|
+
this.isConnected = true;
|
|
21
|
+
resolve();
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
disconnect() {
|
|
26
|
+
// IndexedDB doesn't need explicit disconnect
|
|
27
|
+
this.isConnected = false;
|
|
28
|
+
}
|
|
29
|
+
async reconnect() {
|
|
30
|
+
this.disconnect();
|
|
31
|
+
return this.connect();
|
|
32
|
+
}
|
|
33
|
+
destroy() {
|
|
34
|
+
if (this.provider) {
|
|
35
|
+
this.provider.destroy();
|
|
36
|
+
}
|
|
37
|
+
this.isConnected = false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { WebsocketProvider } from "y-websocket";
|
|
2
|
+
/**
|
|
3
|
+
* WebSocket sync provider for real-time collaboration
|
|
4
|
+
*/
|
|
5
|
+
export class WebSocketSyncProvider {
|
|
6
|
+
static type = 'network';
|
|
7
|
+
type = 'network';
|
|
8
|
+
provider;
|
|
9
|
+
isConnected = false;
|
|
10
|
+
_quiet = false;
|
|
11
|
+
get awareness() {
|
|
12
|
+
return this.provider.awareness;
|
|
13
|
+
}
|
|
14
|
+
get rawProvider() {
|
|
15
|
+
return this.provider;
|
|
16
|
+
}
|
|
17
|
+
constructor(docName, doc, options) {
|
|
18
|
+
const url = options?.url || 'ws://localhost:1234';
|
|
19
|
+
const roomName = options?.roomName || docName;
|
|
20
|
+
this.provider = new WebsocketProvider(url, roomName, doc, {
|
|
21
|
+
params: options?.params,
|
|
22
|
+
protocols: options?.protocols,
|
|
23
|
+
WebSocketPolyfill: options?.WebSocketPolyfill,
|
|
24
|
+
awareness: options?.awareness,
|
|
25
|
+
maxBackoffTime: options?.maxBackoffTime,
|
|
26
|
+
disableBc: true,
|
|
27
|
+
});
|
|
28
|
+
this._quiet = options?.quiet ?? false;
|
|
29
|
+
this.setupEventListeners();
|
|
30
|
+
if (!this._quiet) {
|
|
31
|
+
console.info(`WebSocket Provider initialized: ${url}/${roomName}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Static factory method for creating WebSocketSyncProvider with configuration options
|
|
36
|
+
* Returns a ProviderFactory that can be used in sync configuration
|
|
37
|
+
*/
|
|
38
|
+
static with(options) {
|
|
39
|
+
return {
|
|
40
|
+
type: 'network',
|
|
41
|
+
create: (docName, doc, runtimeOptions) => {
|
|
42
|
+
const mergedOptions = runtimeOptions ? { ...options, ...runtimeOptions } : options;
|
|
43
|
+
return new WebSocketSyncProvider(docName, doc, mergedOptions);
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
setupEventListeners() {
|
|
48
|
+
this.provider.on('status', ({ status }) => {
|
|
49
|
+
if (status === 'connected') {
|
|
50
|
+
this.isConnected = true;
|
|
51
|
+
if (!this._quiet) {
|
|
52
|
+
console.info('WebSocket connected');
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else if (status === 'disconnected') {
|
|
56
|
+
this.isConnected = false;
|
|
57
|
+
if (!this._quiet) {
|
|
58
|
+
console.info('WebSocket disconnected');
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
this.provider.on('sync', (synced) => {
|
|
63
|
+
if (synced && !this._quiet) {
|
|
64
|
+
console.info('WebSocket synced');
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
async connect() {
|
|
69
|
+
if (this.isConnected) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
return new Promise((resolve, reject) => {
|
|
73
|
+
const timeout = setTimeout(() => {
|
|
74
|
+
reject(new Error('WebSocket connection timeout'));
|
|
75
|
+
}, 10000); // 10 second timeout
|
|
76
|
+
const statusHandler = ({ status }) => {
|
|
77
|
+
if (status === 'connected') {
|
|
78
|
+
clearTimeout(timeout);
|
|
79
|
+
this.provider.off('status', statusHandler);
|
|
80
|
+
this.isConnected = true;
|
|
81
|
+
resolve();
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
this.provider.on('status', statusHandler);
|
|
85
|
+
// If already connected, resolve immediately
|
|
86
|
+
if (this.provider.wsconnected) {
|
|
87
|
+
clearTimeout(timeout);
|
|
88
|
+
this.provider.off('status', statusHandler);
|
|
89
|
+
this.isConnected = true;
|
|
90
|
+
resolve();
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
disconnect() {
|
|
95
|
+
if (this.provider) {
|
|
96
|
+
this.provider.disconnect();
|
|
97
|
+
}
|
|
98
|
+
this.isConnected = false;
|
|
99
|
+
}
|
|
100
|
+
async reconnect() {
|
|
101
|
+
this.disconnect();
|
|
102
|
+
return this.connect();
|
|
103
|
+
}
|
|
104
|
+
destroy() {
|
|
105
|
+
if (this.provider) {
|
|
106
|
+
this.provider.destroy();
|
|
107
|
+
}
|
|
108
|
+
this.isConnected = false;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const KRITZEL_RENDERER_REGISTRY_KEY = '__kritzelDynamicObjectRendererRegistry__';
|
|
2
|
+
const getGlobalRegistryStore = () => {
|
|
3
|
+
const globalScope = globalThis;
|
|
4
|
+
const existing = globalScope[KRITZEL_RENDERER_REGISTRY_KEY];
|
|
5
|
+
if (existing) {
|
|
6
|
+
return existing;
|
|
7
|
+
}
|
|
8
|
+
const created = {
|
|
9
|
+
renderers: new Map(),
|
|
10
|
+
};
|
|
11
|
+
globalScope[KRITZEL_RENDERER_REGISTRY_KEY] = created;
|
|
12
|
+
return created;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Global registry for dynamic object renderers.
|
|
16
|
+
* Allows wrapper frameworks (Angular, React, Vue) to register renderer implementations
|
|
17
|
+
* without coupling to core, and enables deterministic rehydration across reloads and
|
|
18
|
+
* clipboard paste operations.
|
|
19
|
+
*
|
|
20
|
+
* Renderer keys are opaque strings that must be stable (e.g., 'angular-todo', 'react-editor').
|
|
21
|
+
* When a dynamic object is deserialized with a rendererKey, the registry is consulted to
|
|
22
|
+
* resolve the renderer and mount with the persisted rendererData.
|
|
23
|
+
*/
|
|
24
|
+
export class KritzelDynamicObjectRendererRegistry {
|
|
25
|
+
static get _renderers() {
|
|
26
|
+
return getGlobalRegistryStore().renderers;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Registers a renderer implementation for a given key.
|
|
30
|
+
* @param key - Stable identifier for this renderer (e.g., 'angular-my-component')
|
|
31
|
+
* @param renderer - Renderer implementation with mount/unmount/update handlers
|
|
32
|
+
*/
|
|
33
|
+
static register(key, renderer) {
|
|
34
|
+
this._renderers.set(key, renderer);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Retrieves a registered renderer by key.
|
|
38
|
+
* @param key - Renderer identifier
|
|
39
|
+
* @returns The registered renderer, or undefined if not found
|
|
40
|
+
*/
|
|
41
|
+
static get(key) {
|
|
42
|
+
return this._renderers.get(key);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Unregisters a renderer by key.
|
|
46
|
+
* @param key - Renderer identifier to remove
|
|
47
|
+
* @returns True if the renderer was found and removed; false otherwise
|
|
48
|
+
*/
|
|
49
|
+
static unregister(key) {
|
|
50
|
+
return this._renderers.delete(key);
|
|
51
|
+
}
|
|
52
|
+
}
|