@kedataindo/docflow-core 0.0.83 → 0.0.85

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.
@@ -1,71 +0,0 @@
1
- import { Awareness } from 'y-protocols/awareness';
2
- import { WebsocketProvider } from 'y-websocket';
3
- import * as Y from 'yjs';
4
- export { A as AwarenessState, C as CollaborationOptions, a as CollaborationSetup, c as collaborationExtensions, b as createCollaboration } from '../Collaboration-CGv9OZlB.cjs';
5
- import '@tiptap/core';
6
- import 'y-indexeddb';
7
- import 'y-webrtc';
8
-
9
- interface SubdocState {
10
- id: string;
11
- doc: Y.Doc;
12
- provider: WebsocketProvider | null;
13
- active: boolean;
14
- }
15
- interface SubdocumentProviderOptions {
16
- /** WebSocket URL for the collaboration server. */
17
- websocketUrl: string;
18
- /** Room prefix — subdocuments use `${roomPrefix}/${id}` as room name. */
19
- roomPrefix: string;
20
- /** User info for awareness. */
21
- user: {
22
- name: string;
23
- color: string;
24
- };
25
- /** Number of subdocuments to keep active (buffer around visible viewport). */
26
- maxActive?: number;
27
- /** Called when subdocument state changes (active/deactivated). */
28
- onStateChange?: (states: SubdocState[]) => void;
29
- }
30
- /**
31
- * Manages multiple Y.Doc subdocuments under a parent document.
32
- *
33
- * Use case: large documents (100+ pages) split into per-section subdocuments.
34
- * Only active (visible) subdocuments are connected to the network via
35
- * WebSocketProvider; inactive ones keep local state but stop syncing.
36
- *
37
- * Usage:
38
- * const provider = new SubdocumentProvider({ websocketUrl, roomPrefix, user })
39
- * provider.createSubdoc('section-1')
40
- * provider.activate('section-1') // starts syncing
41
- * provider.deactivate('section-1') // stops syncing
42
- * const frag = provider.getFragment('section-1') // Y.XmlFragment for editor
43
- */
44
- declare class SubdocumentProvider {
45
- readonly parentDoc: Y.Doc;
46
- readonly subdocs: Y.Map<Y.Doc>;
47
- readonly awareness: Awareness;
48
- private readonly options;
49
- private readonly states;
50
- private readonly activeQueue;
51
- private readonly parentProvider;
52
- constructor(options: SubdocumentProviderOptions);
53
- /** Create a new subdocument. Does NOT activate it. */
54
- createSubdoc(id: string, initialState?: Uint8Array): Y.Doc;
55
- /** Activate a subdocument — connects it to the network for live sync. */
56
- activate(id: string): void;
57
- /** Deactivate a subdocument — disconnects it from the network. */
58
- deactivate(id: string): void;
59
- /** Get the Y.XmlFragment for a subdocument. */
60
- getFragment(id: string): Y.XmlFragment | null;
61
- /** Check if a subdocument is currently active (syncing). */
62
- isActive(id: string): boolean;
63
- /** Get all subdocument states. */
64
- getAllStates(): SubdocState[];
65
- /** Get IDs of all active subdocuments. */
66
- getActiveIds(): string[];
67
- /** Destroy all subdocuments and providers. */
68
- destroy(): void;
69
- }
70
-
71
- export { type SubdocState, SubdocumentProvider, type SubdocumentProviderOptions };
@@ -1,71 +0,0 @@
1
- import { Awareness } from 'y-protocols/awareness';
2
- import { WebsocketProvider } from 'y-websocket';
3
- import * as Y from 'yjs';
4
- export { A as AwarenessState, C as CollaborationOptions, a as CollaborationSetup, c as collaborationExtensions, b as createCollaboration } from '../Collaboration-CGv9OZlB.js';
5
- import '@tiptap/core';
6
- import 'y-indexeddb';
7
- import 'y-webrtc';
8
-
9
- interface SubdocState {
10
- id: string;
11
- doc: Y.Doc;
12
- provider: WebsocketProvider | null;
13
- active: boolean;
14
- }
15
- interface SubdocumentProviderOptions {
16
- /** WebSocket URL for the collaboration server. */
17
- websocketUrl: string;
18
- /** Room prefix — subdocuments use `${roomPrefix}/${id}` as room name. */
19
- roomPrefix: string;
20
- /** User info for awareness. */
21
- user: {
22
- name: string;
23
- color: string;
24
- };
25
- /** Number of subdocuments to keep active (buffer around visible viewport). */
26
- maxActive?: number;
27
- /** Called when subdocument state changes (active/deactivated). */
28
- onStateChange?: (states: SubdocState[]) => void;
29
- }
30
- /**
31
- * Manages multiple Y.Doc subdocuments under a parent document.
32
- *
33
- * Use case: large documents (100+ pages) split into per-section subdocuments.
34
- * Only active (visible) subdocuments are connected to the network via
35
- * WebSocketProvider; inactive ones keep local state but stop syncing.
36
- *
37
- * Usage:
38
- * const provider = new SubdocumentProvider({ websocketUrl, roomPrefix, user })
39
- * provider.createSubdoc('section-1')
40
- * provider.activate('section-1') // starts syncing
41
- * provider.deactivate('section-1') // stops syncing
42
- * const frag = provider.getFragment('section-1') // Y.XmlFragment for editor
43
- */
44
- declare class SubdocumentProvider {
45
- readonly parentDoc: Y.Doc;
46
- readonly subdocs: Y.Map<Y.Doc>;
47
- readonly awareness: Awareness;
48
- private readonly options;
49
- private readonly states;
50
- private readonly activeQueue;
51
- private readonly parentProvider;
52
- constructor(options: SubdocumentProviderOptions);
53
- /** Create a new subdocument. Does NOT activate it. */
54
- createSubdoc(id: string, initialState?: Uint8Array): Y.Doc;
55
- /** Activate a subdocument — connects it to the network for live sync. */
56
- activate(id: string): void;
57
- /** Deactivate a subdocument — disconnects it from the network. */
58
- deactivate(id: string): void;
59
- /** Get the Y.XmlFragment for a subdocument. */
60
- getFragment(id: string): Y.XmlFragment | null;
61
- /** Check if a subdocument is currently active (syncing). */
62
- isActive(id: string): boolean;
63
- /** Get all subdocument states. */
64
- getAllStates(): SubdocState[];
65
- /** Get IDs of all active subdocuments. */
66
- getActiveIds(): string[];
67
- /** Destroy all subdocuments and providers. */
68
- destroy(): void;
69
- }
70
-
71
- export { type SubdocState, SubdocumentProvider, type SubdocumentProviderOptions };
@@ -1,116 +0,0 @@
1
- import {
2
- collaborationExtensions,
3
- createCollaboration
4
- } from "../chunk-XJG72F7M.js";
5
-
6
- // src/SubdocumentProvider.ts
7
- import { Awareness as AwarenessClass } from "y-protocols/awareness";
8
- import { WebsocketProvider } from "y-websocket";
9
- import * as Y from "yjs";
10
- var SubdocumentProvider = class {
11
- parentDoc;
12
- subdocs;
13
- awareness;
14
- options;
15
- states = /* @__PURE__ */ new Map();
16
- activeQueue = [];
17
- parentProvider = null;
18
- constructor(options) {
19
- this.options = {
20
- maxActive: options.maxActive ?? 5,
21
- onStateChange: options.onStateChange ?? (() => {
22
- }),
23
- ...options
24
- };
25
- this.parentDoc = new Y.Doc();
26
- this.subdocs = this.parentDoc.getMap("subdocs");
27
- this.awareness = new AwarenessClass(this.parentDoc);
28
- this.awareness.setLocalStateField("user", this.options.user);
29
- this.parentProvider = new WebsocketProvider(
30
- this.options.websocketUrl,
31
- `${this.options.roomPrefix}/_parent`,
32
- this.parentDoc
33
- );
34
- }
35
- /** Create a new subdocument. Does NOT activate it. */
36
- createSubdoc(id, initialState) {
37
- if (this.states.has(id)) return this.states.get(id).doc;
38
- const doc = new Y.Doc();
39
- if (initialState) Y.applyUpdate(doc, initialState);
40
- doc.getXmlFragment("default");
41
- this.subdocs.set(id, doc);
42
- this.states.set(id, {
43
- id,
44
- doc,
45
- provider: null,
46
- active: false
47
- });
48
- this.options.onStateChange(this.getAllStates());
49
- return doc;
50
- }
51
- /** Activate a subdocument — connects it to the network for live sync. */
52
- activate(id) {
53
- const state = this.states.get(id);
54
- if (!state || state.active) return;
55
- if (this.activeQueue.length >= this.options.maxActive) {
56
- const oldest = this.activeQueue.shift();
57
- if (oldest) this.deactivate(oldest);
58
- }
59
- const doc = state.doc;
60
- const roomName = `${this.options.roomPrefix}/${id}`;
61
- const provider = new WebsocketProvider(
62
- this.options.websocketUrl,
63
- roomName,
64
- doc
65
- );
66
- provider.awareness.setLocalStateField("user", this.options.user);
67
- state.provider = provider;
68
- state.active = true;
69
- this.activeQueue.push(id);
70
- this.options.onStateChange(this.getAllStates());
71
- }
72
- /** Deactivate a subdocument — disconnects it from the network. */
73
- deactivate(id) {
74
- const state = this.states.get(id);
75
- if (!state || !state.active) return;
76
- state.provider?.destroy();
77
- state.provider = null;
78
- state.active = false;
79
- const idx = this.activeQueue.indexOf(id);
80
- if (idx >= 0) this.activeQueue.splice(idx, 1);
81
- this.options.onStateChange(this.getAllStates());
82
- }
83
- /** Get the Y.XmlFragment for a subdocument. */
84
- getFragment(id) {
85
- const doc = this.states.get(id)?.doc ?? this.subdocs.get(id);
86
- if (!doc) return null;
87
- return doc.getXmlFragment("default");
88
- }
89
- /** Check if a subdocument is currently active (syncing). */
90
- isActive(id) {
91
- return this.states.get(id)?.active ?? false;
92
- }
93
- /** Get all subdocument states. */
94
- getAllStates() {
95
- return Array.from(this.states.values());
96
- }
97
- /** Get IDs of all active subdocuments. */
98
- getActiveIds() {
99
- return [...this.activeQueue];
100
- }
101
- /** Destroy all subdocuments and providers. */
102
- destroy() {
103
- for (const [id] of this.states) {
104
- this.deactivate(id);
105
- }
106
- this.parentProvider?.destroy();
107
- this.parentDoc.destroy();
108
- this.states.clear();
109
- this.activeQueue.length = 0;
110
- }
111
- };
112
- export {
113
- SubdocumentProvider,
114
- collaborationExtensions,
115
- createCollaboration
116
- };