@windoc/react 0.3.23 → 0.3.24
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.js +127 -43
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +128 -44
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -2430,6 +2430,49 @@ function EditorFooter() {
|
|
|
2430
2430
|
|
|
2431
2431
|
// src/Editor.tsx
|
|
2432
2432
|
var import_jsx_runtime43 = require("react/jsx-runtime");
|
|
2433
|
+
var CONTENT_SYNC_TIMEOUT = 300;
|
|
2434
|
+
function scheduleDeferredTask(callback) {
|
|
2435
|
+
const deferredWindow = window;
|
|
2436
|
+
if (deferredWindow.requestIdleCallback) {
|
|
2437
|
+
return deferredWindow.requestIdleCallback(
|
|
2438
|
+
() => {
|
|
2439
|
+
callback();
|
|
2440
|
+
},
|
|
2441
|
+
{ timeout: CONTENT_SYNC_TIMEOUT }
|
|
2442
|
+
);
|
|
2443
|
+
}
|
|
2444
|
+
return window.setTimeout(callback, 0);
|
|
2445
|
+
}
|
|
2446
|
+
function cancelDeferredTask(handle) {
|
|
2447
|
+
if (handle === null) return;
|
|
2448
|
+
const deferredWindow = window;
|
|
2449
|
+
if (deferredWindow.cancelIdleCallback) {
|
|
2450
|
+
deferredWindow.cancelIdleCallback(handle);
|
|
2451
|
+
return;
|
|
2452
|
+
}
|
|
2453
|
+
window.clearTimeout(handle);
|
|
2454
|
+
}
|
|
2455
|
+
function isSameNumberArray(left, right) {
|
|
2456
|
+
if (left === right) return true;
|
|
2457
|
+
if (!left || !right || left.length !== right.length) return false;
|
|
2458
|
+
for (let i = 0; i < left.length; i++) {
|
|
2459
|
+
if (left[i] !== right[i]) return false;
|
|
2460
|
+
}
|
|
2461
|
+
return true;
|
|
2462
|
+
}
|
|
2463
|
+
function isSameStringArray(left, right) {
|
|
2464
|
+
if (left === right) return true;
|
|
2465
|
+
if (!left || !right || left.length !== right.length) return false;
|
|
2466
|
+
for (let i = 0; i < left.length; i++) {
|
|
2467
|
+
if (left[i] !== right[i]) return false;
|
|
2468
|
+
}
|
|
2469
|
+
return true;
|
|
2470
|
+
}
|
|
2471
|
+
function isSameRangeStyle(left, right) {
|
|
2472
|
+
if (left === right) return true;
|
|
2473
|
+
if (!left || !right) return false;
|
|
2474
|
+
return left.type === right.type && left.font === right.font && left.size === right.size && left.bold === right.bold && left.italic === right.italic && left.underline === right.underline && left.strikeout === right.strikeout && left.color === right.color && left.highlight === right.highlight && left.rowFlex === right.rowFlex && left.rowMargin === right.rowMargin && left.undo === right.undo && left.redo === right.redo && left.painter === right.painter && left.level === right.level && left.listType === right.listType && isSameNumberArray(left.dashArray, right.dashArray) && isSameStringArray(left.groupIds, right.groupIds);
|
|
2475
|
+
}
|
|
2433
2476
|
function Editor({
|
|
2434
2477
|
defaultValue,
|
|
2435
2478
|
options: userOptions,
|
|
@@ -2483,6 +2526,9 @@ function EditorInner({
|
|
|
2483
2526
|
const editorRef = (0, import_react24.useRef)(null);
|
|
2484
2527
|
const [rangeStyle, setRangeStyle] = (0, import_react24.useState)(null);
|
|
2485
2528
|
const [isInTable, setIsInTable] = (0, import_react24.useState)(false);
|
|
2529
|
+
const lastRangeStyleRef = (0, import_react24.useRef)(null);
|
|
2530
|
+
const deferredContentSyncRef = (0, import_react24.useRef)(null);
|
|
2531
|
+
const contentSyncVersionRef = (0, import_react24.useRef)(0);
|
|
2486
2532
|
const {
|
|
2487
2533
|
setPageNoList,
|
|
2488
2534
|
setPageNo,
|
|
@@ -2512,11 +2558,10 @@ function EditorInner({
|
|
|
2512
2558
|
} = await import("@windoc/core");
|
|
2513
2559
|
if (cancelled) return;
|
|
2514
2560
|
const data = defaultValue ?? { main: [] };
|
|
2515
|
-
instance = new EditorClass(
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
);
|
|
2561
|
+
instance = new EditorClass(containerRef.current, data, {
|
|
2562
|
+
maskMargin: [24, 0, 24, 0],
|
|
2563
|
+
...userOptions
|
|
2564
|
+
});
|
|
2520
2565
|
editorRef.current = instance;
|
|
2521
2566
|
const opts = instance.command.getOptions();
|
|
2522
2567
|
setPageScale(Math.round(opts.scale * 100));
|
|
@@ -2524,40 +2569,67 @@ function EditorInner({
|
|
|
2524
2569
|
setPaperWidth(opts.width);
|
|
2525
2570
|
setPaperHeight(opts.height);
|
|
2526
2571
|
instance.listener.rangeStyleChange = (payload) => {
|
|
2527
|
-
|
|
2572
|
+
if (!isSameRangeStyle(lastRangeStyleRef.current, payload)) {
|
|
2573
|
+
lastRangeStyleRef.current = payload;
|
|
2574
|
+
(0, import_react24.startTransition)(() => {
|
|
2575
|
+
setRangeStyle(payload);
|
|
2576
|
+
});
|
|
2577
|
+
}
|
|
2528
2578
|
onRangeStyleChange?.(payload);
|
|
2529
2579
|
const rangeContext = instance?.command.getRangeContext();
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2580
|
+
(0, import_react24.startTransition)(() => {
|
|
2581
|
+
setIsInTable(rangeContext?.isTable === true);
|
|
2582
|
+
if (rangeContext) {
|
|
2583
|
+
setRowNo(rangeContext.startRowNo + 1);
|
|
2584
|
+
setColNo(rangeContext.startColNo + 1);
|
|
2585
|
+
}
|
|
2586
|
+
});
|
|
2535
2587
|
};
|
|
2536
2588
|
instance.listener.visiblePageNoListChange = (payload) => {
|
|
2537
|
-
|
|
2589
|
+
(0, import_react24.startTransition)(() => {
|
|
2590
|
+
setPageNoList(payload.map((i) => i + 1).join(", "));
|
|
2591
|
+
});
|
|
2538
2592
|
};
|
|
2539
2593
|
instance.listener.pageSizeChange = (payload) => {
|
|
2540
|
-
|
|
2594
|
+
(0, import_react24.startTransition)(() => {
|
|
2595
|
+
setPageSize(payload);
|
|
2596
|
+
});
|
|
2541
2597
|
};
|
|
2542
2598
|
instance.listener.intersectionPageNoChange = (payload) => {
|
|
2543
|
-
|
|
2599
|
+
(0, import_react24.startTransition)(() => {
|
|
2600
|
+
setPageNo(payload + 1);
|
|
2601
|
+
});
|
|
2544
2602
|
};
|
|
2545
2603
|
instance.listener.pageScaleChange = (payload) => {
|
|
2546
|
-
|
|
2604
|
+
(0, import_react24.startTransition)(() => {
|
|
2605
|
+
setPageScale(Math.floor(payload * 10 * 10));
|
|
2606
|
+
});
|
|
2547
2607
|
};
|
|
2548
2608
|
instance.listener.optionsChange = (payload) => {
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2609
|
+
(0, import_react24.startTransition)(() => {
|
|
2610
|
+
setPageScale(Math.round(payload.scale * 100));
|
|
2611
|
+
setPaperDirection(payload.paperDirection);
|
|
2612
|
+
setPaperWidth(payload.width);
|
|
2613
|
+
setPaperHeight(payload.height);
|
|
2614
|
+
});
|
|
2553
2615
|
};
|
|
2554
|
-
instance.listener.contentChange =
|
|
2555
|
-
const
|
|
2556
|
-
|
|
2557
|
-
if (onChange) {
|
|
2558
|
-
|
|
2559
|
-
if (value) onChange(value);
|
|
2616
|
+
instance.listener.contentChange = () => {
|
|
2617
|
+
const currentVersion = ++contentSyncVersionRef.current;
|
|
2618
|
+
cancelDeferredTask(deferredContentSyncRef.current);
|
|
2619
|
+
if (onChange && instance) {
|
|
2620
|
+
onChange(instance.command.getValue());
|
|
2560
2621
|
}
|
|
2622
|
+
deferredContentSyncRef.current = scheduleDeferredTask(async () => {
|
|
2623
|
+
if (cancelled || !instance) return;
|
|
2624
|
+
const count2 = await instance.command.getWordCount();
|
|
2625
|
+
if (cancelled || contentSyncVersionRef.current !== currentVersion) {
|
|
2626
|
+
return;
|
|
2627
|
+
}
|
|
2628
|
+
(0, import_react24.startTransition)(() => {
|
|
2629
|
+
setWordCount(count2 || 0);
|
|
2630
|
+
});
|
|
2631
|
+
deferredContentSyncRef.current = null;
|
|
2632
|
+
});
|
|
2561
2633
|
};
|
|
2562
2634
|
instance.register.shortcutList([
|
|
2563
2635
|
{
|
|
@@ -2631,12 +2703,16 @@ function EditorInner({
|
|
|
2631
2703
|
};
|
|
2632
2704
|
window.addEventListener("click", closeDropdowns, { capture: true });
|
|
2633
2705
|
const count = await instance.command.getWordCount();
|
|
2634
|
-
|
|
2706
|
+
(0, import_react24.startTransition)(() => {
|
|
2707
|
+
setWordCount(count || 0);
|
|
2708
|
+
});
|
|
2635
2709
|
onReady?.(instance);
|
|
2636
2710
|
};
|
|
2637
2711
|
initEditor();
|
|
2638
2712
|
return () => {
|
|
2639
2713
|
cancelled = true;
|
|
2714
|
+
cancelDeferredTask(deferredContentSyncRef.current);
|
|
2715
|
+
deferredContentSyncRef.current = null;
|
|
2640
2716
|
instance?.destroy();
|
|
2641
2717
|
editorRef.current = null;
|
|
2642
2718
|
if (closeDropdowns) {
|
|
@@ -2655,23 +2731,31 @@ function EditorInner({
|
|
|
2655
2731
|
e.preventDefault();
|
|
2656
2732
|
e.dataTransfer.dropEffect = "copy";
|
|
2657
2733
|
};
|
|
2658
|
-
return /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2734
|
+
return /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(
|
|
2735
|
+
EditorProvider,
|
|
2736
|
+
{
|
|
2737
|
+
editorRef,
|
|
2738
|
+
rangeStyle,
|
|
2739
|
+
isInTable,
|
|
2740
|
+
children: [
|
|
2741
|
+
toolbar && !renderToolbar && /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(EditorToolbar, {}),
|
|
2742
|
+
renderToolbar,
|
|
2743
|
+
children,
|
|
2744
|
+
/* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
|
|
2745
|
+
"div",
|
|
2746
|
+
{
|
|
2747
|
+
className: className ?? "editor",
|
|
2748
|
+
style: style ?? { flex: 1, minHeight: 0, overflow: "auto" },
|
|
2749
|
+
ref: containerRef,
|
|
2750
|
+
onDrop: handleDrop,
|
|
2751
|
+
onDragOver: handleDragOver
|
|
2752
|
+
}
|
|
2753
|
+
),
|
|
2754
|
+
footer && !renderFooter && /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(EditorFooter, {}),
|
|
2755
|
+
renderFooter
|
|
2756
|
+
]
|
|
2757
|
+
}
|
|
2758
|
+
);
|
|
2675
2759
|
}
|
|
2676
2760
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2677
2761
|
0 && (module.exports = {
|