@kedataindo/docflow-core 0.0.34 → 0.0.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -201,6 +201,24 @@ function createCollaboration(options) {
201
201
  awareness.on("change", notify);
202
202
  notify();
203
203
  }
204
+ const readyParts = [];
205
+ if (persistence) {
206
+ readyParts.push(
207
+ persistence.whenSynced.then(
208
+ () => void 0,
209
+ () => void 0
210
+ )
211
+ );
212
+ }
213
+ if (provider && options.provider === "websocket") {
214
+ const ws = provider;
215
+ readyParts.push(
216
+ new Promise((resolve) => {
217
+ ws.once("sync", () => resolve());
218
+ })
219
+ );
220
+ }
221
+ const whenReady = readyParts.length === 0 ? Promise.resolve() : Promise.all(readyParts).then(() => void 0);
204
222
  const destroy = () => {
205
223
  if (awarenessHandler) {
206
224
  awareness.off("change", awarenessHandler);
@@ -211,7 +229,7 @@ function createCollaboration(options) {
211
229
  void persistence?.destroy();
212
230
  ydoc.destroy();
213
231
  };
214
- return { ydoc, provider, awareness, persistence, destroy, setLocalCursorEnabled };
232
+ return { ydoc, provider, awareness, persistence, whenReady, destroy, setLocalCursorEnabled };
215
233
  }
216
234
  function collaborationExtensions(options) {
217
235
  const setup = "ydoc" in options ? options : createCollaboration(options);
@@ -1523,7 +1541,7 @@ function createEditor(options = {}) {
1523
1541
  content: options.content ? migrateContent(options.content) : options.content
1524
1542
  };
1525
1543
  const plugins = migratedOptions.plugins ?? [];
1526
- const collaborationSetup = migratedOptions.collaboration ? createCollaboration(migratedOptions.collaboration) : void 0;
1544
+ const collaborationSetup = !migratedOptions.collaboration ? void 0 : "ydoc" in migratedOptions.collaboration ? migratedOptions.collaboration : createCollaboration(migratedOptions.collaboration);
1527
1545
  const performanceMonitor = migratedOptions.debug ? createPerformanceMonitor() : void 0;
1528
1546
  let tiptapEditor = createTiptapEditor(migratedOptions, plugins, collaborationSetup);
1529
1547
  let pluginActions = createActionMap(tiptapEditor, plugins);
package/dist/index.d.cts CHANGED
@@ -99,6 +99,16 @@ interface CollaborationSetup {
99
99
  * use it as a seed source.
100
100
  */
101
101
  persistence?: IndexeddbPersistence;
102
+ /**
103
+ * Issue #117 — resolves after BOTH the offline mirror (if `offline`) AND
104
+ * the provider's first sync (if `websocket`) have completed. Hosts MUST
105
+ * `await setup.whenReady` before binding the editor, otherwise the
106
+ * TipTap view can render against the IndexedDB cache before the
107
+ * authoritative server state arrives, briefly showing — and on a
108
+ * disconnected peer potentially re-broadcasting — nodes the server has
109
+ * since deleted. Resolves immediately when neither side applies.
110
+ */
111
+ whenReady: Promise<void>;
102
112
  destroy: () => void;
103
113
  /**
104
114
  * Phase 9 PR2 — toggle the local cursor emission + present flag.
@@ -191,7 +201,7 @@ interface EditorOptions {
191
201
  plugins?: DocsEditorPlugin[];
192
202
  editable?: boolean;
193
203
  onUpdate?: (json: object) => void;
194
- collaboration?: CollaborationOptions;
204
+ collaboration?: CollaborationOptions | CollaborationSetup;
195
205
  getPageMap?: () => Map<number, {
196
206
  page: number;
197
207
  blockIndex: number;
package/dist/index.d.ts CHANGED
@@ -99,6 +99,16 @@ interface CollaborationSetup {
99
99
  * use it as a seed source.
100
100
  */
101
101
  persistence?: IndexeddbPersistence;
102
+ /**
103
+ * Issue #117 — resolves after BOTH the offline mirror (if `offline`) AND
104
+ * the provider's first sync (if `websocket`) have completed. Hosts MUST
105
+ * `await setup.whenReady` before binding the editor, otherwise the
106
+ * TipTap view can render against the IndexedDB cache before the
107
+ * authoritative server state arrives, briefly showing — and on a
108
+ * disconnected peer potentially re-broadcasting — nodes the server has
109
+ * since deleted. Resolves immediately when neither side applies.
110
+ */
111
+ whenReady: Promise<void>;
102
112
  destroy: () => void;
103
113
  /**
104
114
  * Phase 9 PR2 — toggle the local cursor emission + present flag.
@@ -191,7 +201,7 @@ interface EditorOptions {
191
201
  plugins?: DocsEditorPlugin[];
192
202
  editable?: boolean;
193
203
  onUpdate?: (json: object) => void;
194
- collaboration?: CollaborationOptions;
204
+ collaboration?: CollaborationOptions | CollaborationSetup;
195
205
  getPageMap?: () => Map<number, {
196
206
  page: number;
197
207
  blockIndex: number;
package/dist/index.js CHANGED
@@ -143,6 +143,24 @@ function createCollaboration(options) {
143
143
  awareness.on("change", notify);
144
144
  notify();
145
145
  }
146
+ const readyParts = [];
147
+ if (persistence) {
148
+ readyParts.push(
149
+ persistence.whenSynced.then(
150
+ () => void 0,
151
+ () => void 0
152
+ )
153
+ );
154
+ }
155
+ if (provider && options.provider === "websocket") {
156
+ const ws = provider;
157
+ readyParts.push(
158
+ new Promise((resolve) => {
159
+ ws.once("sync", () => resolve());
160
+ })
161
+ );
162
+ }
163
+ const whenReady = readyParts.length === 0 ? Promise.resolve() : Promise.all(readyParts).then(() => void 0);
146
164
  const destroy = () => {
147
165
  if (awarenessHandler) {
148
166
  awareness.off("change", awarenessHandler);
@@ -153,7 +171,7 @@ function createCollaboration(options) {
153
171
  void persistence?.destroy();
154
172
  ydoc.destroy();
155
173
  };
156
- return { ydoc, provider, awareness, persistence, destroy, setLocalCursorEnabled };
174
+ return { ydoc, provider, awareness, persistence, whenReady, destroy, setLocalCursorEnabled };
157
175
  }
158
176
  function collaborationExtensions(options) {
159
177
  const setup = "ydoc" in options ? options : createCollaboration(options);
@@ -1465,7 +1483,7 @@ function createEditor(options = {}) {
1465
1483
  content: options.content ? migrateContent(options.content) : options.content
1466
1484
  };
1467
1485
  const plugins = migratedOptions.plugins ?? [];
1468
- const collaborationSetup = migratedOptions.collaboration ? createCollaboration(migratedOptions.collaboration) : void 0;
1486
+ const collaborationSetup = !migratedOptions.collaboration ? void 0 : "ydoc" in migratedOptions.collaboration ? migratedOptions.collaboration : createCollaboration(migratedOptions.collaboration);
1469
1487
  const performanceMonitor = migratedOptions.debug ? createPerformanceMonitor() : void 0;
1470
1488
  let tiptapEditor = createTiptapEditor(migratedOptions, plugins, collaborationSetup);
1471
1489
  let pluginActions = createActionMap(tiptapEditor, plugins);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kedataindo/docflow-core",
3
3
  "license": "UNLICENSED",
4
- "version": "0.0.34",
4
+ "version": "0.0.36",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.js",