@pixerate/editor-react 0.192.0 → 0.194.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/canvas/AnimatedEdge.d.cts +57 -0
- package/dist/canvas/AnimatedEdge.d.ts +57 -0
- package/dist/canvas/index.cjs +727 -591
- package/dist/canvas/index.d.cts +2 -0
- package/dist/canvas/index.d.ts +2 -0
- package/dist/canvas/index.js +308 -169
- package/dist/{chunk-2JNRWM6S.js → chunk-QBU4WMBA.js} +80 -2
- package/dist/index.cjs +143 -66
- package/dist/index.js +4 -2
- package/dist/persistence/index.cjs +80 -3
- package/dist/persistence/index.d.cts +1 -0
- package/dist/persistence/index.d.ts +1 -0
- package/dist/persistence/index.js +5 -3
- package/dist/persistence/useAutosave.d.cts +6 -0
- package/dist/persistence/useAutosave.d.ts +6 -0
- package/dist/persistence/useEditorSync.d.cts +30 -0
- package/dist/persistence/useEditorSync.d.ts +30 -0
- package/package.json +4 -4
|
@@ -22,7 +22,8 @@ var persistence_exports = {};
|
|
|
22
22
|
__export(persistence_exports, {
|
|
23
23
|
RecoveryPrompt: () => RecoveryPrompt,
|
|
24
24
|
useAutosave: () => useAutosave,
|
|
25
|
-
useEditorAutosave: () => useEditorAutosave
|
|
25
|
+
useEditorAutosave: () => useEditorAutosave,
|
|
26
|
+
useEditorSync: () => useEditorSync
|
|
26
27
|
});
|
|
27
28
|
module.exports = __toCommonJS(persistence_exports);
|
|
28
29
|
|
|
@@ -64,7 +65,11 @@ function useAutosave(options) {
|
|
|
64
65
|
interval: o.interval,
|
|
65
66
|
debounceMs: o.debounceMs,
|
|
66
67
|
retryBaseMs: o.retryBaseMs,
|
|
67
|
-
retryMaxMs: o.retryMaxMs
|
|
68
|
+
retryMaxMs: o.retryMaxMs,
|
|
69
|
+
baseVersion: () => {
|
|
70
|
+
const v = optionsRef.current.baseVersion;
|
|
71
|
+
return typeof v === "function" ? v() : v;
|
|
72
|
+
}
|
|
68
73
|
});
|
|
69
74
|
const unsubscribeStatus = instance.subscribe(setStatus);
|
|
70
75
|
const unsubscribeRevisions = revisions.subscribe(() => instance.notify());
|
|
@@ -220,9 +225,81 @@ var RecoveryPrompt = ({
|
|
|
220
225
|
}
|
|
221
226
|
);
|
|
222
227
|
};
|
|
228
|
+
|
|
229
|
+
// src/persistence/useEditorSync.ts
|
|
230
|
+
var import_react3 = require("react");
|
|
231
|
+
var import_persistence4 = require("@pixerate/editor/persistence");
|
|
232
|
+
function useEditorSync(doc, options) {
|
|
233
|
+
const optionsRef = (0, import_react3.useRef)(options);
|
|
234
|
+
optionsRef.current = options;
|
|
235
|
+
const [controller, setController] = (0, import_react3.useState)(null);
|
|
236
|
+
const [status, setStatus] = (0, import_react3.useState)(() => ({
|
|
237
|
+
status: "idle",
|
|
238
|
+
version: options.initialVersion ?? 0,
|
|
239
|
+
savedVersion: options.initialVersion ?? 0,
|
|
240
|
+
dirty: false,
|
|
241
|
+
lastSavedAt: null
|
|
242
|
+
}));
|
|
243
|
+
(0, import_react3.useEffect)(() => {
|
|
244
|
+
const { flushOnHide: _flushOnHide, ...initial } = optionsRef.current;
|
|
245
|
+
const instance = (0, import_persistence4.createEditorRemoteSync)(doc, {
|
|
246
|
+
...initial,
|
|
247
|
+
save: (context) => optionsRef.current.save(context),
|
|
248
|
+
diff: initial.diff ? (current, baseline) => optionsRef.current.diff(current, baseline) : void 0,
|
|
249
|
+
isEmptyDiff: initial.isEmptyDiff ? (diff, current, baseline) => optionsRef.current.isEmptyDiff(diff, current, baseline) : void 0,
|
|
250
|
+
onLocalChange: (event) => optionsRef.current.onLocalChange?.(event),
|
|
251
|
+
onSaved: (event) => optionsRef.current.onSaved?.(event),
|
|
252
|
+
onError: (error) => optionsRef.current.onError?.(error),
|
|
253
|
+
onConflict: initial.onConflict ? (context) => optionsRef.current.onConflict(context) : void 0,
|
|
254
|
+
autosave: { markClean: async () => optionsRef.current.autosave?.markClean() }
|
|
255
|
+
});
|
|
256
|
+
const unsubscribe = instance.subscribe(setStatus);
|
|
257
|
+
setController(instance);
|
|
258
|
+
return () => {
|
|
259
|
+
unsubscribe();
|
|
260
|
+
void instance.flush();
|
|
261
|
+
instance.destroy();
|
|
262
|
+
};
|
|
263
|
+
}, [doc]);
|
|
264
|
+
const flushOnHide = options.flushOnHide ?? true;
|
|
265
|
+
(0, import_react3.useEffect)(() => {
|
|
266
|
+
if (!controller || !flushOnHide || typeof window === "undefined") return;
|
|
267
|
+
const onVisibilityChange = () => {
|
|
268
|
+
if (document.visibilityState === "hidden") void controller.flush();
|
|
269
|
+
};
|
|
270
|
+
const onPageHide = () => void controller.flush();
|
|
271
|
+
document.addEventListener("visibilitychange", onVisibilityChange);
|
|
272
|
+
window.addEventListener("pagehide", onPageHide);
|
|
273
|
+
return () => {
|
|
274
|
+
document.removeEventListener("visibilitychange", onVisibilityChange);
|
|
275
|
+
window.removeEventListener("pagehide", onPageHide);
|
|
276
|
+
};
|
|
277
|
+
}, [controller, flushOnHide]);
|
|
278
|
+
const applyRemote = (0, import_react3.useCallback)(
|
|
279
|
+
(fn, remoteVersion) => controller ? controller.applyRemote(fn, remoteVersion) : fn(),
|
|
280
|
+
[controller]
|
|
281
|
+
);
|
|
282
|
+
return (0, import_react3.useMemo)(
|
|
283
|
+
() => ({
|
|
284
|
+
status,
|
|
285
|
+
version: status.version,
|
|
286
|
+
savedVersion: status.savedVersion,
|
|
287
|
+
dirty: status.dirty,
|
|
288
|
+
controller,
|
|
289
|
+
baseline: () => controller?.baseline(),
|
|
290
|
+
notify: () => controller?.notify() ?? false,
|
|
291
|
+
applyRemote,
|
|
292
|
+
resetBaseline: (remoteVersion) => controller?.resetBaseline(remoteVersion),
|
|
293
|
+
flush: () => controller?.flush() ?? Promise.resolve(true),
|
|
294
|
+
whenIdle: () => controller?.whenIdle() ?? Promise.resolve()
|
|
295
|
+
}),
|
|
296
|
+
[status, controller, applyRemote]
|
|
297
|
+
);
|
|
298
|
+
}
|
|
223
299
|
// Annotate the CommonJS export names for ESM import in node:
|
|
224
300
|
0 && (module.exports = {
|
|
225
301
|
RecoveryPrompt,
|
|
226
302
|
useAutosave,
|
|
227
|
-
useEditorAutosave
|
|
303
|
+
useEditorAutosave,
|
|
304
|
+
useEditorSync
|
|
228
305
|
});
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
RecoveryPrompt,
|
|
3
3
|
useAutosave,
|
|
4
|
-
useEditorAutosave
|
|
5
|
-
|
|
4
|
+
useEditorAutosave,
|
|
5
|
+
useEditorSync
|
|
6
|
+
} from "../chunk-QBU4WMBA.js";
|
|
6
7
|
export {
|
|
7
8
|
RecoveryPrompt,
|
|
8
9
|
useAutosave,
|
|
9
|
-
useEditorAutosave
|
|
10
|
+
useEditorAutosave,
|
|
11
|
+
useEditorSync
|
|
10
12
|
};
|
|
@@ -26,6 +26,12 @@ export interface UseAutosaveOptions<T> {
|
|
|
26
26
|
recover?: boolean;
|
|
27
27
|
/** Write pending changes on `pagehide` and when the tab is hidden (default `true`). */
|
|
28
28
|
flushOnHide?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* The server / host version of the loaded document, stored with each snapshot. The recovery
|
|
31
|
+
* check retires snapshots made on an older version instead of offering them, so they never
|
|
32
|
+
* overwrite newer server state.
|
|
33
|
+
*/
|
|
34
|
+
baseVersion?: number | (() => number | undefined);
|
|
29
35
|
}
|
|
30
36
|
export interface UseAutosaveResult<T> {
|
|
31
37
|
status: AutosaveStatusInfo;
|
|
@@ -26,6 +26,12 @@ export interface UseAutosaveOptions<T> {
|
|
|
26
26
|
recover?: boolean;
|
|
27
27
|
/** Write pending changes on `pagehide` and when the tab is hidden (default `true`). */
|
|
28
28
|
flushOnHide?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* The server / host version of the loaded document, stored with each snapshot. The recovery
|
|
31
|
+
* check retires snapshots made on an older version instead of offering them, so they never
|
|
32
|
+
* overwrite newer server state.
|
|
33
|
+
*/
|
|
34
|
+
baseVersion?: number | (() => number | undefined);
|
|
29
35
|
}
|
|
30
36
|
export interface UseAutosaveResult<T> {
|
|
31
37
|
status: AutosaveStatusInfo;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type EditorDocument, type EditorRemoteSync, type EditorRemoteSyncOptions, type EditorRemoteSyncStatus } from '@pixerate/editor/persistence';
|
|
2
|
+
export interface UseEditorSyncOptions<TDocument = unknown, TDiff = unknown> extends EditorRemoteSyncOptions<TDocument, TDiff> {
|
|
3
|
+
/**
|
|
4
|
+
* Flush pending debounced changes when the tab hides or unloads (`visibilitychange` to
|
|
5
|
+
* `"hidden"`, `pagehide`; default `true`).
|
|
6
|
+
*/
|
|
7
|
+
flushOnHide?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface UseEditorSyncResult<TDocument = unknown, TDiff = unknown> {
|
|
10
|
+
status: EditorRemoteSyncStatus;
|
|
11
|
+
version: number;
|
|
12
|
+
savedVersion: number;
|
|
13
|
+
dirty: boolean;
|
|
14
|
+
/** The controller, once mounted (`null` during the first render). */
|
|
15
|
+
controller: EditorRemoteSync<TDocument, TDiff> | null;
|
|
16
|
+
baseline(): TDocument | undefined;
|
|
17
|
+
notify(): boolean;
|
|
18
|
+
/** Runs `fn` without saving or reporting it as a local change (before mount, just runs `fn`). */
|
|
19
|
+
applyRemote<TResult>(fn: () => TResult, remoteVersion?: number): TResult;
|
|
20
|
+
resetBaseline(remoteVersion?: number): void;
|
|
21
|
+
flush(): Promise<boolean>;
|
|
22
|
+
whenIdle(): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* React hook wrapping `createEditorRemoteSync`: saves `doc` to a remote backend after each change
|
|
26
|
+
* (debounced, one save at a time, monotonic versions) and re-renders on status changes. Callbacks
|
|
27
|
+
* in `options` may change between renders; `initialVersion` and `debounceMs` are read when `doc`
|
|
28
|
+
* is first synced. Pending changes are flushed on unmount. Pass a stable `doc`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function useEditorSync<TDocument = unknown, TDiff = unknown>(doc: EditorDocument<TDocument>, options: UseEditorSyncOptions<TDocument, TDiff>): UseEditorSyncResult<TDocument, TDiff>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type EditorDocument, type EditorRemoteSync, type EditorRemoteSyncOptions, type EditorRemoteSyncStatus } from '@pixerate/editor/persistence';
|
|
2
|
+
export interface UseEditorSyncOptions<TDocument = unknown, TDiff = unknown> extends EditorRemoteSyncOptions<TDocument, TDiff> {
|
|
3
|
+
/**
|
|
4
|
+
* Flush pending debounced changes when the tab hides or unloads (`visibilitychange` to
|
|
5
|
+
* `"hidden"`, `pagehide`; default `true`).
|
|
6
|
+
*/
|
|
7
|
+
flushOnHide?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface UseEditorSyncResult<TDocument = unknown, TDiff = unknown> {
|
|
10
|
+
status: EditorRemoteSyncStatus;
|
|
11
|
+
version: number;
|
|
12
|
+
savedVersion: number;
|
|
13
|
+
dirty: boolean;
|
|
14
|
+
/** The controller, once mounted (`null` during the first render). */
|
|
15
|
+
controller: EditorRemoteSync<TDocument, TDiff> | null;
|
|
16
|
+
baseline(): TDocument | undefined;
|
|
17
|
+
notify(): boolean;
|
|
18
|
+
/** Runs `fn` without saving or reporting it as a local change (before mount, just runs `fn`). */
|
|
19
|
+
applyRemote<TResult>(fn: () => TResult, remoteVersion?: number): TResult;
|
|
20
|
+
resetBaseline(remoteVersion?: number): void;
|
|
21
|
+
flush(): Promise<boolean>;
|
|
22
|
+
whenIdle(): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* React hook wrapping `createEditorRemoteSync`: saves `doc` to a remote backend after each change
|
|
26
|
+
* (debounced, one save at a time, monotonic versions) and re-renders on status changes. Callbacks
|
|
27
|
+
* in `options` may change between renders; `initialVersion` and `debounceMs` are read when `doc`
|
|
28
|
+
* is first synced. Pending changes are flushed on unmount. Pass a stable `doc`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function useEditorSync<TDocument = unknown, TDiff = unknown>(doc: EditorDocument<TDocument>, options: UseEditorSyncOptions<TDocument, TDiff>): UseEditorSyncResult<TDocument, TDiff>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pixerate/editor-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.194.0",
|
|
4
4
|
"description": "React bindings and prompt/rich-text components for @pixerate/editor",
|
|
5
5
|
"author": "Pixerate",
|
|
6
6
|
"license": "MIT",
|
|
@@ -283,7 +283,7 @@
|
|
|
283
283
|
"dependencies": {},
|
|
284
284
|
"peerDependencies": {
|
|
285
285
|
"@dagrejs/dagre": "^1.1.8",
|
|
286
|
-
"@pixerate/editor": ">=0.
|
|
286
|
+
"@pixerate/editor": ">=0.281.0 <1.0.0-0",
|
|
287
287
|
"@tiptap/core": "^2.27.3",
|
|
288
288
|
"@tiptap/extension-bubble-menu": "^2.27.3",
|
|
289
289
|
"@tiptap/extension-placeholder": "^2.27.3",
|
|
@@ -333,8 +333,8 @@
|
|
|
333
333
|
"react-dom": "^19.3.1",
|
|
334
334
|
"tsup": "^9.0.0",
|
|
335
335
|
"typescript": "^5.7.3",
|
|
336
|
-
"vitest": "^5.0
|
|
337
|
-
"@pixerate/editor": "0.
|
|
336
|
+
"vitest": "^5.1.0",
|
|
337
|
+
"@pixerate/editor": "0.281.0"
|
|
338
338
|
},
|
|
339
339
|
"scripts": {
|
|
340
340
|
"build": "tsup && tsc -p tsconfig.build.json && node ../../scripts/finalize-declarations.mjs dist",
|