@pixerate/editor-react 0.192.0 → 0.193.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/{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 +3 -3
|
@@ -39,7 +39,11 @@ function useAutosave(options) {
|
|
|
39
39
|
interval: o.interval,
|
|
40
40
|
debounceMs: o.debounceMs,
|
|
41
41
|
retryBaseMs: o.retryBaseMs,
|
|
42
|
-
retryMaxMs: o.retryMaxMs
|
|
42
|
+
retryMaxMs: o.retryMaxMs,
|
|
43
|
+
baseVersion: () => {
|
|
44
|
+
const v = optionsRef.current.baseVersion;
|
|
45
|
+
return typeof v === "function" ? v() : v;
|
|
46
|
+
}
|
|
43
47
|
});
|
|
44
48
|
const unsubscribeStatus = instance.subscribe(setStatus);
|
|
45
49
|
const unsubscribeRevisions = revisions.subscribe(() => instance.notify());
|
|
@@ -201,8 +205,82 @@ var RecoveryPrompt = ({
|
|
|
201
205
|
);
|
|
202
206
|
};
|
|
203
207
|
|
|
208
|
+
// src/persistence/useEditorSync.ts
|
|
209
|
+
import { useCallback as useCallback3, useEffect as useEffect2, useMemo as useMemo2, useRef as useRef3, useState as useState2 } from "react";
|
|
210
|
+
import {
|
|
211
|
+
createEditorRemoteSync
|
|
212
|
+
} from "@pixerate/editor/persistence";
|
|
213
|
+
function useEditorSync(doc, options) {
|
|
214
|
+
const optionsRef = useRef3(options);
|
|
215
|
+
optionsRef.current = options;
|
|
216
|
+
const [controller, setController] = useState2(null);
|
|
217
|
+
const [status, setStatus] = useState2(() => ({
|
|
218
|
+
status: "idle",
|
|
219
|
+
version: options.initialVersion ?? 0,
|
|
220
|
+
savedVersion: options.initialVersion ?? 0,
|
|
221
|
+
dirty: false,
|
|
222
|
+
lastSavedAt: null
|
|
223
|
+
}));
|
|
224
|
+
useEffect2(() => {
|
|
225
|
+
const { flushOnHide: _flushOnHide, ...initial } = optionsRef.current;
|
|
226
|
+
const instance = createEditorRemoteSync(doc, {
|
|
227
|
+
...initial,
|
|
228
|
+
save: (context) => optionsRef.current.save(context),
|
|
229
|
+
diff: initial.diff ? (current, baseline) => optionsRef.current.diff(current, baseline) : void 0,
|
|
230
|
+
isEmptyDiff: initial.isEmptyDiff ? (diff, current, baseline) => optionsRef.current.isEmptyDiff(diff, current, baseline) : void 0,
|
|
231
|
+
onLocalChange: (event) => optionsRef.current.onLocalChange?.(event),
|
|
232
|
+
onSaved: (event) => optionsRef.current.onSaved?.(event),
|
|
233
|
+
onError: (error) => optionsRef.current.onError?.(error),
|
|
234
|
+
onConflict: initial.onConflict ? (context) => optionsRef.current.onConflict(context) : void 0,
|
|
235
|
+
autosave: { markClean: async () => optionsRef.current.autosave?.markClean() }
|
|
236
|
+
});
|
|
237
|
+
const unsubscribe = instance.subscribe(setStatus);
|
|
238
|
+
setController(instance);
|
|
239
|
+
return () => {
|
|
240
|
+
unsubscribe();
|
|
241
|
+
void instance.flush();
|
|
242
|
+
instance.destroy();
|
|
243
|
+
};
|
|
244
|
+
}, [doc]);
|
|
245
|
+
const flushOnHide = options.flushOnHide ?? true;
|
|
246
|
+
useEffect2(() => {
|
|
247
|
+
if (!controller || !flushOnHide || typeof window === "undefined") return;
|
|
248
|
+
const onVisibilityChange = () => {
|
|
249
|
+
if (document.visibilityState === "hidden") void controller.flush();
|
|
250
|
+
};
|
|
251
|
+
const onPageHide = () => void controller.flush();
|
|
252
|
+
document.addEventListener("visibilitychange", onVisibilityChange);
|
|
253
|
+
window.addEventListener("pagehide", onPageHide);
|
|
254
|
+
return () => {
|
|
255
|
+
document.removeEventListener("visibilitychange", onVisibilityChange);
|
|
256
|
+
window.removeEventListener("pagehide", onPageHide);
|
|
257
|
+
};
|
|
258
|
+
}, [controller, flushOnHide]);
|
|
259
|
+
const applyRemote = useCallback3(
|
|
260
|
+
(fn, remoteVersion) => controller ? controller.applyRemote(fn, remoteVersion) : fn(),
|
|
261
|
+
[controller]
|
|
262
|
+
);
|
|
263
|
+
return useMemo2(
|
|
264
|
+
() => ({
|
|
265
|
+
status,
|
|
266
|
+
version: status.version,
|
|
267
|
+
savedVersion: status.savedVersion,
|
|
268
|
+
dirty: status.dirty,
|
|
269
|
+
controller,
|
|
270
|
+
baseline: () => controller?.baseline(),
|
|
271
|
+
notify: () => controller?.notify() ?? false,
|
|
272
|
+
applyRemote,
|
|
273
|
+
resetBaseline: (remoteVersion) => controller?.resetBaseline(remoteVersion),
|
|
274
|
+
flush: () => controller?.flush() ?? Promise.resolve(true),
|
|
275
|
+
whenIdle: () => controller?.whenIdle() ?? Promise.resolve()
|
|
276
|
+
}),
|
|
277
|
+
[status, controller, applyRemote]
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
|
|
204
281
|
export {
|
|
205
282
|
useAutosave,
|
|
206
283
|
useEditorAutosave,
|
|
207
|
-
RecoveryPrompt
|
|
284
|
+
RecoveryPrompt,
|
|
285
|
+
useEditorSync
|
|
208
286
|
};
|
package/dist/index.cjs
CHANGED
|
@@ -121,6 +121,7 @@ __export(src_exports, {
|
|
|
121
121
|
useEditor: () => useEditor2,
|
|
122
122
|
useEditorAutosave: () => useEditorAutosave,
|
|
123
123
|
useEditorSlots: () => useEditorSlots,
|
|
124
|
+
useEditorSync: () => useEditorSync,
|
|
124
125
|
useElementPlaybackSurface: () => useElementPlaybackSurface,
|
|
125
126
|
useFileImport: () => useFileImport,
|
|
126
127
|
useFillHandle: () => useFillHandle,
|
|
@@ -12506,7 +12507,11 @@ function useAutosave(options) {
|
|
|
12506
12507
|
interval: o.interval,
|
|
12507
12508
|
debounceMs: o.debounceMs,
|
|
12508
12509
|
retryBaseMs: o.retryBaseMs,
|
|
12509
|
-
retryMaxMs: o.retryMaxMs
|
|
12510
|
+
retryMaxMs: o.retryMaxMs,
|
|
12511
|
+
baseVersion: () => {
|
|
12512
|
+
const v = optionsRef.current.baseVersion;
|
|
12513
|
+
return typeof v === "function" ? v() : v;
|
|
12514
|
+
}
|
|
12510
12515
|
});
|
|
12511
12516
|
const unsubscribeStatus = instance.subscribe(setStatus);
|
|
12512
12517
|
const unsubscribeRevisions = revisions.subscribe(() => instance.notify());
|
|
@@ -12663,18 +12668,89 @@ var RecoveryPrompt = ({
|
|
|
12663
12668
|
);
|
|
12664
12669
|
};
|
|
12665
12670
|
|
|
12666
|
-
// src/
|
|
12671
|
+
// src/persistence/useEditorSync.ts
|
|
12667
12672
|
var import_react90 = require("react");
|
|
12673
|
+
var import_persistence4 = require("@pixerate/editor/persistence");
|
|
12674
|
+
function useEditorSync(doc, options) {
|
|
12675
|
+
const optionsRef = (0, import_react90.useRef)(options);
|
|
12676
|
+
optionsRef.current = options;
|
|
12677
|
+
const [controller, setController] = (0, import_react90.useState)(null);
|
|
12678
|
+
const [status, setStatus] = (0, import_react90.useState)(() => ({
|
|
12679
|
+
status: "idle",
|
|
12680
|
+
version: options.initialVersion ?? 0,
|
|
12681
|
+
savedVersion: options.initialVersion ?? 0,
|
|
12682
|
+
dirty: false,
|
|
12683
|
+
lastSavedAt: null
|
|
12684
|
+
}));
|
|
12685
|
+
(0, import_react90.useEffect)(() => {
|
|
12686
|
+
const { flushOnHide: _flushOnHide, ...initial } = optionsRef.current;
|
|
12687
|
+
const instance = (0, import_persistence4.createEditorRemoteSync)(doc, {
|
|
12688
|
+
...initial,
|
|
12689
|
+
save: (context) => optionsRef.current.save(context),
|
|
12690
|
+
diff: initial.diff ? (current, baseline) => optionsRef.current.diff(current, baseline) : void 0,
|
|
12691
|
+
isEmptyDiff: initial.isEmptyDiff ? (diff, current, baseline) => optionsRef.current.isEmptyDiff(diff, current, baseline) : void 0,
|
|
12692
|
+
onLocalChange: (event) => optionsRef.current.onLocalChange?.(event),
|
|
12693
|
+
onSaved: (event) => optionsRef.current.onSaved?.(event),
|
|
12694
|
+
onError: (error) => optionsRef.current.onError?.(error),
|
|
12695
|
+
onConflict: initial.onConflict ? (context) => optionsRef.current.onConflict(context) : void 0,
|
|
12696
|
+
autosave: { markClean: async () => optionsRef.current.autosave?.markClean() }
|
|
12697
|
+
});
|
|
12698
|
+
const unsubscribe = instance.subscribe(setStatus);
|
|
12699
|
+
setController(instance);
|
|
12700
|
+
return () => {
|
|
12701
|
+
unsubscribe();
|
|
12702
|
+
void instance.flush();
|
|
12703
|
+
instance.destroy();
|
|
12704
|
+
};
|
|
12705
|
+
}, [doc]);
|
|
12706
|
+
const flushOnHide = options.flushOnHide ?? true;
|
|
12707
|
+
(0, import_react90.useEffect)(() => {
|
|
12708
|
+
if (!controller || !flushOnHide || typeof window === "undefined") return;
|
|
12709
|
+
const onVisibilityChange = () => {
|
|
12710
|
+
if (document.visibilityState === "hidden") void controller.flush();
|
|
12711
|
+
};
|
|
12712
|
+
const onPageHide = () => void controller.flush();
|
|
12713
|
+
document.addEventListener("visibilitychange", onVisibilityChange);
|
|
12714
|
+
window.addEventListener("pagehide", onPageHide);
|
|
12715
|
+
return () => {
|
|
12716
|
+
document.removeEventListener("visibilitychange", onVisibilityChange);
|
|
12717
|
+
window.removeEventListener("pagehide", onPageHide);
|
|
12718
|
+
};
|
|
12719
|
+
}, [controller, flushOnHide]);
|
|
12720
|
+
const applyRemote = (0, import_react90.useCallback)(
|
|
12721
|
+
(fn, remoteVersion) => controller ? controller.applyRemote(fn, remoteVersion) : fn(),
|
|
12722
|
+
[controller]
|
|
12723
|
+
);
|
|
12724
|
+
return (0, import_react90.useMemo)(
|
|
12725
|
+
() => ({
|
|
12726
|
+
status,
|
|
12727
|
+
version: status.version,
|
|
12728
|
+
savedVersion: status.savedVersion,
|
|
12729
|
+
dirty: status.dirty,
|
|
12730
|
+
controller,
|
|
12731
|
+
baseline: () => controller?.baseline(),
|
|
12732
|
+
notify: () => controller?.notify() ?? false,
|
|
12733
|
+
applyRemote,
|
|
12734
|
+
resetBaseline: (remoteVersion) => controller?.resetBaseline(remoteVersion),
|
|
12735
|
+
flush: () => controller?.flush() ?? Promise.resolve(true),
|
|
12736
|
+
whenIdle: () => controller?.whenIdle() ?? Promise.resolve()
|
|
12737
|
+
}),
|
|
12738
|
+
[status, controller, applyRemote]
|
|
12739
|
+
);
|
|
12740
|
+
}
|
|
12741
|
+
|
|
12742
|
+
// src/generation/useGenerationPlan.ts
|
|
12743
|
+
var import_react91 = require("react");
|
|
12668
12744
|
var import_generation = require("@pixerate/editor/generation");
|
|
12669
12745
|
function useGenerationPlan(request, capabilities, options = {}) {
|
|
12670
12746
|
const key = JSON.stringify([request, capabilities, options]);
|
|
12671
|
-
return (0,
|
|
12747
|
+
return (0, import_react91.useMemo)(() => (0, import_generation.planGenerationRequest)(request, capabilities, options), [key]);
|
|
12672
12748
|
}
|
|
12673
12749
|
function useJobProgress(options) {
|
|
12674
12750
|
const { startedAt, expectedMs, done, now, intervalMs = 1e3 } = options;
|
|
12675
|
-
const [tick, setTick] = (0,
|
|
12751
|
+
const [tick, setTick] = (0, import_react91.useState)(() => Date.now());
|
|
12676
12752
|
const ticking = !done && now === void 0;
|
|
12677
|
-
(0,
|
|
12753
|
+
(0, import_react91.useEffect)(() => {
|
|
12678
12754
|
if (!ticking) return;
|
|
12679
12755
|
setTick(Date.now());
|
|
12680
12756
|
const id = setInterval(() => setTick(Date.now()), Math.max(16, intervalMs));
|
|
@@ -12684,7 +12760,7 @@ function useJobProgress(options) {
|
|
|
12684
12760
|
}
|
|
12685
12761
|
|
|
12686
12762
|
// src/generation/GenerationSettings.tsx
|
|
12687
|
-
var
|
|
12763
|
+
var import_react92 = require("react");
|
|
12688
12764
|
var import_generation2 = require("@pixerate/editor/generation");
|
|
12689
12765
|
var import_jsx_runtime68 = require("react/jsx-runtime");
|
|
12690
12766
|
var inputClass2 = "w-full rounded-md border border-border bg-background px-2 py-1 text-sm outline-none focus:ring-1 focus:ring-ring";
|
|
@@ -12767,8 +12843,8 @@ var GenerationSettings = ({
|
|
|
12767
12843
|
renderReference,
|
|
12768
12844
|
className = ""
|
|
12769
12845
|
}) => {
|
|
12770
|
-
const baseId = (0,
|
|
12771
|
-
const controls = (0,
|
|
12846
|
+
const baseId = (0, import_react92.useId)();
|
|
12847
|
+
const controls = (0, import_react92.useMemo)(() => (0, import_generation2.getGenerationControls)(capabilities), [capabilities]);
|
|
12772
12848
|
const computed = useGenerationPlan(value, capabilities, { strategy });
|
|
12773
12849
|
const plan = planProp ?? computed;
|
|
12774
12850
|
const slots = (0, import_generation2.getReferenceSlots)(capabilities, value);
|
|
@@ -12863,7 +12939,7 @@ var JobProgress = ({ title, className = "", ...options }) => {
|
|
|
12863
12939
|
};
|
|
12864
12940
|
|
|
12865
12941
|
// src/generation/AssetMentionChips.tsx
|
|
12866
|
-
var
|
|
12942
|
+
var import_react93 = require("react");
|
|
12867
12943
|
var import_generation3 = require("@pixerate/editor/generation");
|
|
12868
12944
|
var import_jsx_runtime70 = require("react/jsx-runtime");
|
|
12869
12945
|
var AssetMentionChips = ({
|
|
@@ -12875,14 +12951,14 @@ var AssetMentionChips = ({
|
|
|
12875
12951
|
renderAsset,
|
|
12876
12952
|
className = ""
|
|
12877
12953
|
}) => {
|
|
12878
|
-
const [open, setOpen] = (0,
|
|
12879
|
-
const rootRef = (0,
|
|
12880
|
-
const chips = (0,
|
|
12954
|
+
const [open, setOpen] = (0, import_react93.useState)(null);
|
|
12955
|
+
const rootRef = (0, import_react93.useRef)(null);
|
|
12956
|
+
const chips = (0, import_react93.useMemo)(
|
|
12881
12957
|
() => (0, import_generation3.describeAssetMentions)((0, import_generation3.findTextMentions)(content), assets, capabilities),
|
|
12882
12958
|
[content, assets, capabilities]
|
|
12883
12959
|
);
|
|
12884
12960
|
const options = roles ?? (capabilities ? (0, import_generation3.getAssetRoleOptions)(capabilities) : (0, import_generation3.defaultAssetRoleOptions)());
|
|
12885
|
-
(0,
|
|
12961
|
+
(0, import_react93.useEffect)(() => {
|
|
12886
12962
|
if (open === null) return;
|
|
12887
12963
|
const onPointer = (event) => {
|
|
12888
12964
|
if (!rootRef.current?.contains(event.target)) setOpen(null);
|
|
@@ -12977,15 +13053,15 @@ var AssetMentionChips = ({
|
|
|
12977
13053
|
};
|
|
12978
13054
|
|
|
12979
13055
|
// src/generation/GenerationHistory.tsx
|
|
12980
|
-
var
|
|
13056
|
+
var import_react94 = require("react");
|
|
12981
13057
|
var import_generation4 = require("@pixerate/editor/generation");
|
|
12982
13058
|
var import_jsx_runtime71 = require("react/jsx-runtime");
|
|
12983
13059
|
function useGenerationRecords(store, filter) {
|
|
12984
|
-
const [records, setRecords] = (0,
|
|
12985
|
-
const [loading, setLoading] = (0,
|
|
12986
|
-
const [error, setError] = (0,
|
|
13060
|
+
const [records, setRecords] = (0, import_react94.useState)([]);
|
|
13061
|
+
const [loading, setLoading] = (0, import_react94.useState)(!!store);
|
|
13062
|
+
const [error, setError] = (0, import_react94.useState)(null);
|
|
12987
13063
|
const filterKey = (0, import_generation4.stableStringify)(filter ?? {});
|
|
12988
|
-
const refresh = (0,
|
|
13064
|
+
const refresh = (0, import_react94.useCallback)(async () => {
|
|
12989
13065
|
if (!store) {
|
|
12990
13066
|
setRecords([]);
|
|
12991
13067
|
setLoading(false);
|
|
@@ -13002,7 +13078,7 @@ function useGenerationRecords(store, filter) {
|
|
|
13002
13078
|
setLoading(false);
|
|
13003
13079
|
}
|
|
13004
13080
|
}, [store, filterKey]);
|
|
13005
|
-
(0,
|
|
13081
|
+
(0, import_react94.useEffect)(() => {
|
|
13006
13082
|
void refresh();
|
|
13007
13083
|
if (!store) return;
|
|
13008
13084
|
return store.subscribe(() => void refresh());
|
|
@@ -13028,15 +13104,15 @@ var GenerationHistory = ({
|
|
|
13028
13104
|
emptyText = "No generations yet.",
|
|
13029
13105
|
className = ""
|
|
13030
13106
|
}) => {
|
|
13031
|
-
const [innerMode, setInnerMode] = (0,
|
|
13107
|
+
const [innerMode, setInnerMode] = (0, import_react94.useState)("exact");
|
|
13032
13108
|
const mode = modeProp ?? innerMode;
|
|
13033
13109
|
const setMode = (next) => {
|
|
13034
13110
|
if (modeProp === void 0) setInnerMode(next);
|
|
13035
13111
|
onModeChange?.(next);
|
|
13036
13112
|
};
|
|
13037
|
-
const options = (0,
|
|
13038
|
-
const results = (0,
|
|
13039
|
-
const models = (0,
|
|
13113
|
+
const options = (0, import_react94.useMemo)(() => ({ templates, capabilities, assets, mode }), [templates, capabilities, assets, mode]);
|
|
13114
|
+
const results = (0, import_react94.useMemo)(() => records.map((record) => (0, import_generation4.recreateRequest)(record, options)), [records, options]);
|
|
13115
|
+
const models = (0, import_react94.useMemo)(
|
|
13040
13116
|
() => capabilities ? Array.isArray(capabilities) ? capabilities : [capabilities] : [],
|
|
13041
13117
|
[capabilities]
|
|
13042
13118
|
);
|
|
@@ -13147,19 +13223,19 @@ var GenerationHistory = ({
|
|
|
13147
13223
|
};
|
|
13148
13224
|
|
|
13149
13225
|
// src/find-replace/useFindReplace.ts
|
|
13150
|
-
var
|
|
13226
|
+
var import_react95 = require("react");
|
|
13151
13227
|
var import_editor17 = require("@pixerate/editor");
|
|
13152
13228
|
var noopUnsubscribe2 = () => {
|
|
13153
13229
|
};
|
|
13154
13230
|
function useFindReplace(editor) {
|
|
13155
13231
|
const store = (0, import_editor17.getFindReplaceStore)(editor ?? null);
|
|
13156
|
-
const subscribe = (0,
|
|
13232
|
+
const subscribe = (0, import_react95.useCallback)(
|
|
13157
13233
|
(onChange) => store ? store.subscribe(() => onChange()) : noopUnsubscribe2,
|
|
13158
13234
|
[store]
|
|
13159
13235
|
);
|
|
13160
13236
|
const getSnapshot2 = () => store?.getSnapshot() ?? import_editor17.EMPTY_FIND_REPLACE_SNAPSHOT;
|
|
13161
|
-
const snapshot = (0,
|
|
13162
|
-
return (0,
|
|
13237
|
+
const snapshot = (0, import_react95.useSyncExternalStore)(subscribe, getSnapshot2, getSnapshot2);
|
|
13238
|
+
return (0, import_react95.useMemo)(() => {
|
|
13163
13239
|
const run = (fn) => {
|
|
13164
13240
|
if (editor && !editor.isDestroyed && store) fn(editor);
|
|
13165
13241
|
};
|
|
@@ -13183,7 +13259,7 @@ function useFindReplace(editor) {
|
|
|
13183
13259
|
}
|
|
13184
13260
|
|
|
13185
13261
|
// src/find-replace/FindReplaceBar.tsx
|
|
13186
|
-
var
|
|
13262
|
+
var import_react96 = require("react");
|
|
13187
13263
|
var import_editor18 = require("@pixerate/editor");
|
|
13188
13264
|
var import_jsx_runtime72 = require("react/jsx-runtime");
|
|
13189
13265
|
var inputClass3 = "min-w-0 flex-1 rounded border border-input bg-background px-2 py-1 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-ring";
|
|
@@ -13198,10 +13274,10 @@ var FindReplaceBar = ({
|
|
|
13198
13274
|
onClose
|
|
13199
13275
|
}) => {
|
|
13200
13276
|
const find = useFindReplace(editor);
|
|
13201
|
-
const findInput = (0,
|
|
13202
|
-
const [moreOpen, setMoreOpen] = (0,
|
|
13277
|
+
const findInput = (0, import_react96.useRef)(null);
|
|
13278
|
+
const [moreOpen, setMoreOpen] = (0, import_react96.useState)(false);
|
|
13203
13279
|
const visible = find.available && (alwaysOpen || find.open);
|
|
13204
|
-
(0,
|
|
13280
|
+
(0, import_react96.useEffect)(() => {
|
|
13205
13281
|
if (!visible || find.focusRequest === 0) return;
|
|
13206
13282
|
findInput.current?.focus();
|
|
13207
13283
|
findInput.current?.select();
|
|
@@ -13345,12 +13421,12 @@ var FindReplaceBar = ({
|
|
|
13345
13421
|
};
|
|
13346
13422
|
|
|
13347
13423
|
// src/tables/useTableMenu.ts
|
|
13348
|
-
var
|
|
13424
|
+
var import_react97 = require("react");
|
|
13349
13425
|
var import_editor19 = require("@pixerate/editor");
|
|
13350
13426
|
function useTableMenu(editor) {
|
|
13351
|
-
const store = (0,
|
|
13352
|
-
const snapshot = (0,
|
|
13353
|
-
return (0,
|
|
13427
|
+
const store = (0, import_react97.useMemo)(() => (0, import_editor19.createTableStore)(editor), [editor]);
|
|
13428
|
+
const snapshot = (0, import_react97.useSyncExternalStore)(store.subscribe, store.getSnapshot, store.getSnapshot);
|
|
13429
|
+
return (0, import_react97.useMemo)(
|
|
13354
13430
|
() => ({
|
|
13355
13431
|
...snapshot,
|
|
13356
13432
|
run: (action, params) => (0, import_editor19.runTableAction)(editor, action, params, { focus: true }),
|
|
@@ -13361,7 +13437,7 @@ function useTableMenu(editor) {
|
|
|
13361
13437
|
}
|
|
13362
13438
|
|
|
13363
13439
|
// src/tables/TableToolbar.tsx
|
|
13364
|
-
var
|
|
13440
|
+
var import_react98 = __toESM(require("react"), 1);
|
|
13365
13441
|
var import_editor20 = require("@pixerate/editor");
|
|
13366
13442
|
var import_jsx_runtime73 = require("react/jsx-runtime");
|
|
13367
13443
|
var keepSelection2 = (event) => event.preventDefault();
|
|
@@ -13382,7 +13458,7 @@ var TableToolbar = ({
|
|
|
13382
13458
|
const enabled = status === true;
|
|
13383
13459
|
const active = item.active?.(table);
|
|
13384
13460
|
const separator = index > 0 && items[index - 1].group !== item.group;
|
|
13385
|
-
return /* @__PURE__ */ (0, import_jsx_runtime73.jsxs)(
|
|
13461
|
+
return /* @__PURE__ */ (0, import_jsx_runtime73.jsxs)(import_react98.default.Fragment, { children: [
|
|
13386
13462
|
separator && /* @__PURE__ */ (0, import_jsx_runtime73.jsx)("span", { className: separatorClassName, "aria-hidden": "true" }),
|
|
13387
13463
|
/* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
|
|
13388
13464
|
"button",
|
|
@@ -13406,7 +13482,7 @@ var TableToolbar = ({
|
|
|
13406
13482
|
};
|
|
13407
13483
|
|
|
13408
13484
|
// src/tables/InsertTableGrid.tsx
|
|
13409
|
-
var
|
|
13485
|
+
var import_react99 = require("react");
|
|
13410
13486
|
var import_jsx_runtime74 = require("react/jsx-runtime");
|
|
13411
13487
|
var keepSelection3 = (event) => event.preventDefault();
|
|
13412
13488
|
var InsertTableGrid = ({
|
|
@@ -13420,7 +13496,7 @@ var InsertTableGrid = ({
|
|
|
13420
13496
|
onInsert
|
|
13421
13497
|
}) => {
|
|
13422
13498
|
const table = useTableMenu(editor);
|
|
13423
|
-
const [hover, setHover] = (0,
|
|
13499
|
+
const [hover, setHover] = (0, import_react99.useState)(null);
|
|
13424
13500
|
const status = table.actions.insertTable;
|
|
13425
13501
|
const disabled = !editor || !status.enabled;
|
|
13426
13502
|
const insert = (size) => {
|
|
@@ -13487,14 +13563,14 @@ var TableBubbleMenu = ({
|
|
|
13487
13563
|
var import_client2 = require("react-dom/client");
|
|
13488
13564
|
|
|
13489
13565
|
// src/chart/ChartCanvas.tsx
|
|
13490
|
-
var
|
|
13566
|
+
var import_react101 = require("react");
|
|
13491
13567
|
var import_chart2 = require("@pixerate/editor/chart");
|
|
13492
13568
|
|
|
13493
13569
|
// src/chart/useChartEditor.ts
|
|
13494
|
-
var
|
|
13570
|
+
var import_react100 = require("react");
|
|
13495
13571
|
var import_chart = require("@pixerate/editor/chart");
|
|
13496
13572
|
function useChartState(controller) {
|
|
13497
|
-
return (0,
|
|
13573
|
+
return (0, import_react100.useSyncExternalStore)(controller.subscribe, controller.getState, controller.getState);
|
|
13498
13574
|
}
|
|
13499
13575
|
|
|
13500
13576
|
// src/chart/ChartCanvas.tsx
|
|
@@ -13546,7 +13622,7 @@ function renderChartMark(mark, fontFamily, interactive) {
|
|
|
13546
13622
|
}
|
|
13547
13623
|
}
|
|
13548
13624
|
function ChartPresenceLayer({ presence }) {
|
|
13549
|
-
const { actors } = (0,
|
|
13625
|
+
const { actors } = (0, import_react101.useSyncExternalStore)(presence.subscribe, presence.getState, presence.getState);
|
|
13550
13626
|
return /* @__PURE__ */ (0, import_jsx_runtime76.jsx)("g", { "data-chart-presence": "", pointerEvents: "none", children: actors.map((a) => /* @__PURE__ */ (0, import_jsx_runtime76.jsxs)("g", { transform: `translate(${a.x} ${a.y})`, "data-actor": a.id, children: [
|
|
13551
13627
|
/* @__PURE__ */ (0, import_jsx_runtime76.jsx)("path", { d: "M0,0 L0,14 L4,10.5 L7,17 L9.5,16 L6.5,9.5 L11.5,9.5 Z", style: { fill: a.color, stroke: "#ffffff", strokeWidth: 1 }, transform: a.pressed ? "scale(0.9)" : void 0 }),
|
|
13552
13628
|
/* @__PURE__ */ (0, import_jsx_runtime76.jsxs)("g", { transform: "translate(13 16)", children: [
|
|
@@ -13567,15 +13643,15 @@ function ChartTooltipContent({ tooltip }) {
|
|
|
13567
13643
|
}
|
|
13568
13644
|
function ChartCanvas({ controller, width = 640, height = 400, responsive = true, theme, editable = true, measureText, emptyMessage, className, presence, sceneRef, tooltip = false, renderTooltip }) {
|
|
13569
13645
|
const state = useChartState(controller);
|
|
13570
|
-
const wrapper = (0,
|
|
13571
|
-
const svg = (0,
|
|
13572
|
-
const drag = (0,
|
|
13573
|
-
const [measured, setMeasured] = (0,
|
|
13574
|
-
const [frozen, setFrozen] = (0,
|
|
13646
|
+
const wrapper = (0, import_react101.useRef)(null);
|
|
13647
|
+
const svg = (0, import_react101.useRef)(null);
|
|
13648
|
+
const drag = (0, import_react101.useRef)(null);
|
|
13649
|
+
const [measured, setMeasured] = (0, import_react101.useState)(null);
|
|
13650
|
+
const [frozen, setFrozen] = (0, import_react101.useState)(null);
|
|
13575
13651
|
const tooltipMode = tooltip === true ? "point" : tooltip || null;
|
|
13576
|
-
const [tip, setTip] = (0,
|
|
13577
|
-
const [tipAt, setTipAt] = (0,
|
|
13578
|
-
(0,
|
|
13652
|
+
const [tip, setTip] = (0, import_react101.useState)(null);
|
|
13653
|
+
const [tipAt, setTipAt] = (0, import_react101.useState)({ left: 0, top: 0, flip: false });
|
|
13654
|
+
(0, import_react101.useEffect)(() => {
|
|
13579
13655
|
const el = wrapper.current;
|
|
13580
13656
|
if (!responsive || !el || typeof ResizeObserver === "undefined") return;
|
|
13581
13657
|
const observer = new ResizeObserver(([entry]) => {
|
|
@@ -13586,8 +13662,8 @@ function ChartCanvas({ controller, width = 640, height = 400, responsive = true,
|
|
|
13586
13662
|
return () => observer.disconnect();
|
|
13587
13663
|
}, [responsive]);
|
|
13588
13664
|
const sceneWidth = responsive && measured || width;
|
|
13589
|
-
const fullTheme = (0,
|
|
13590
|
-
const scene = (0,
|
|
13665
|
+
const fullTheme = (0, import_react101.useMemo)(() => ({ ...import_chart2.CSS_VARIABLE_CHART_THEME, ...theme }), [theme]);
|
|
13666
|
+
const scene = (0, import_react101.useMemo)(
|
|
13591
13667
|
() => (0, import_chart2.layoutChart)(state.spec, {
|
|
13592
13668
|
width: sceneWidth,
|
|
13593
13669
|
height,
|
|
@@ -13604,8 +13680,8 @@ function ChartCanvas({ controller, width = 640, height = 400, responsive = true,
|
|
|
13604
13680
|
[state.spec, state.selection, state.raceFrame, sceneWidth, height, fullTheme, editable, measureText, emptyMessage, frozen]
|
|
13605
13681
|
);
|
|
13606
13682
|
if (sceneRef) sceneRef.current = scene;
|
|
13607
|
-
const byKey = (0,
|
|
13608
|
-
(0,
|
|
13683
|
+
const byKey = (0, import_react101.useMemo)(() => new Map(scene.marks.map((m) => [m.key, m])), [scene]);
|
|
13684
|
+
(0, import_react101.useEffect)(() => () => drag.current?.end(), []);
|
|
13609
13685
|
const scenePoint = (e) => (0, import_chart2.chartClientToScene)(scene, svg.current.getBoundingClientRect(), e.clientX, e.clientY);
|
|
13610
13686
|
const onPointerDown = (e) => {
|
|
13611
13687
|
if (!editable || e.button !== 0) return;
|
|
@@ -13698,7 +13774,7 @@ function ChartCanvas({ controller, width = 640, height = 400, responsive = true,
|
|
|
13698
13774
|
}
|
|
13699
13775
|
|
|
13700
13776
|
// src/chart/ChartDataGrid.tsx
|
|
13701
|
-
var
|
|
13777
|
+
var import_react102 = require("react");
|
|
13702
13778
|
var import_chart3 = require("@pixerate/editor/chart");
|
|
13703
13779
|
|
|
13704
13780
|
// src/chart/styles.ts
|
|
@@ -13713,9 +13789,9 @@ var chartCellClass = "h-7 w-full min-w-[4.5rem] bg-transparent px-2 text-right t
|
|
|
13713
13789
|
// src/chart/ChartDataGrid.tsx
|
|
13714
13790
|
var import_jsx_runtime77 = require("react/jsx-runtime");
|
|
13715
13791
|
function ChartCommitInput({ value, onCommit, onKeyDown, onBlur, ...rest }) {
|
|
13716
|
-
const [draft, setDraft] = (0,
|
|
13717
|
-
const typing = (0,
|
|
13718
|
-
(0,
|
|
13792
|
+
const [draft, setDraft] = (0, import_react102.useState)(value);
|
|
13793
|
+
const typing = (0, import_react102.useRef)(false);
|
|
13794
|
+
(0, import_react102.useEffect)(() => {
|
|
13719
13795
|
if (!typing.current) setDraft(value);
|
|
13720
13796
|
}, [value]);
|
|
13721
13797
|
const commit = () => {
|
|
@@ -13753,7 +13829,7 @@ function ChartCommitInput({ value, onCommit, onKeyDown, onBlur, ...rest }) {
|
|
|
13753
13829
|
}
|
|
13754
13830
|
function ChartTreeGrid({ controller, readOnly = false, className }) {
|
|
13755
13831
|
const { spec } = useChartState(controller);
|
|
13756
|
-
const [columns, setColumns] = (0,
|
|
13832
|
+
const [columns, setColumns] = (0, import_react102.useState)(1);
|
|
13757
13833
|
const rows = (0, import_chart3.chartTreeToRows)(spec.tree);
|
|
13758
13834
|
const depth = Math.max(columns, (0, import_chart3.chartTreeDepth)(spec.tree));
|
|
13759
13835
|
const labels = (0, import_chart3.chartTreeColumnLabels)(depth);
|
|
@@ -13941,7 +14017,7 @@ function ChartDataGrid({ controller, categoryHeader = "Category", readOnly = fal
|
|
|
13941
14017
|
}
|
|
13942
14018
|
|
|
13943
14019
|
// src/chart/ChartInspector.tsx
|
|
13944
|
-
var
|
|
14020
|
+
var import_react103 = require("react");
|
|
13945
14021
|
var import_chart4 = require("@pixerate/editor/chart");
|
|
13946
14022
|
var import_jsx_runtime78 = require("react/jsx-runtime");
|
|
13947
14023
|
var cap = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
@@ -14106,7 +14182,7 @@ function ErrorBarFields({ controller, series, which, idBase }) {
|
|
|
14106
14182
|
}
|
|
14107
14183
|
function ChartInspector({ controller, sections, className }) {
|
|
14108
14184
|
const { spec, selectedSeries, selection, raceFrame, racePlaying } = useChartState(controller);
|
|
14109
|
-
const idBase = (0,
|
|
14185
|
+
const idBase = (0, import_react103.useId)();
|
|
14110
14186
|
const show = (section) => !sections || sections.includes(section);
|
|
14111
14187
|
const cartesian = (0, import_chart4.isCartesianChart)(spec.type);
|
|
14112
14188
|
const family = (0, import_chart4.chartFamily)(spec);
|
|
@@ -14449,10 +14525,10 @@ function createReactChartNodeView(options = {}) {
|
|
|
14449
14525
|
}
|
|
14450
14526
|
|
|
14451
14527
|
// src/style/useStyle.ts
|
|
14452
|
-
var
|
|
14528
|
+
var import_react104 = require("react");
|
|
14453
14529
|
var message = (error) => error instanceof Error ? error.message : String(error);
|
|
14454
14530
|
function useResolverTask(styles, run, deliver, deps) {
|
|
14455
|
-
(0,
|
|
14531
|
+
(0, import_react104.useEffect)(() => {
|
|
14456
14532
|
if (!styles || !run) {
|
|
14457
14533
|
deliver({ value: null, error: null });
|
|
14458
14534
|
return;
|
|
@@ -14479,7 +14555,7 @@ function useResolverTask(styles, run, deliver, deps) {
|
|
|
14479
14555
|
}, [styles, ...deps]);
|
|
14480
14556
|
}
|
|
14481
14557
|
function useStyle(styles, domain) {
|
|
14482
|
-
const [result, setResult] = (0,
|
|
14558
|
+
const [result, setResult] = (0, import_react104.useState)({ style: null, error: null });
|
|
14483
14559
|
useResolverTask(
|
|
14484
14560
|
styles,
|
|
14485
14561
|
(s) => s.resolve(domain),
|
|
@@ -14489,7 +14565,7 @@ function useStyle(styles, domain) {
|
|
|
14489
14565
|
return result;
|
|
14490
14566
|
}
|
|
14491
14567
|
function useStyleFindings(styles, domain, state) {
|
|
14492
|
-
const [result, setResult] = (0,
|
|
14568
|
+
const [result, setResult] = (0, import_react104.useState)({ report: null, style: null, error: null });
|
|
14493
14569
|
useResolverTask(
|
|
14494
14570
|
styles,
|
|
14495
14571
|
(s) => s.check(domain, state),
|
|
@@ -14650,6 +14726,7 @@ function StyleFindings({ report, onSelect, title = "House style", className = ""
|
|
|
14650
14726
|
useEditor,
|
|
14651
14727
|
useEditorAutosave,
|
|
14652
14728
|
useEditorSlots,
|
|
14729
|
+
useEditorSync,
|
|
14653
14730
|
useElementPlaybackSurface,
|
|
14654
14731
|
useFileImport,
|
|
14655
14732
|
useFillHandle,
|
package/dist/index.js
CHANGED
|
@@ -93,8 +93,9 @@ import {
|
|
|
93
93
|
import {
|
|
94
94
|
RecoveryPrompt,
|
|
95
95
|
useAutosave,
|
|
96
|
-
useEditorAutosave
|
|
97
|
-
|
|
96
|
+
useEditorAutosave,
|
|
97
|
+
useEditorSync
|
|
98
|
+
} from "./chunk-QBU4WMBA.js";
|
|
98
99
|
|
|
99
100
|
// src/hooks/usePromptEditor.ts
|
|
100
101
|
import React, { useMemo, useEffect, useRef } from "react";
|
|
@@ -2463,6 +2464,7 @@ export {
|
|
|
2463
2464
|
useEditor2 as useEditor,
|
|
2464
2465
|
useEditorAutosave,
|
|
2465
2466
|
useEditorSlots,
|
|
2467
|
+
useEditorSync,
|
|
2466
2468
|
useElementPlaybackSurface,
|
|
2467
2469
|
useFileImport,
|
|
2468
2470
|
useFillHandle,
|
|
@@ -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.193.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.279.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",
|
|
@@ -334,7 +334,7 @@
|
|
|
334
334
|
"tsup": "^9.0.0",
|
|
335
335
|
"typescript": "^5.7.3",
|
|
336
336
|
"vitest": "^5.0.5",
|
|
337
|
-
"@pixerate/editor": "0.
|
|
337
|
+
"@pixerate/editor": "0.279.0"
|
|
338
338
|
},
|
|
339
339
|
"scripts": {
|
|
340
340
|
"build": "tsup && tsc -p tsconfig.build.json && node ../../scripts/finalize-declarations.mjs dist",
|