@xom11/whiteboard 0.10.1 → 0.11.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/index.d.mts +17 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.js +28 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +28 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1519,7 +1519,9 @@ function Whiteboard({
|
|
|
1519
1519
|
onFilesChange,
|
|
1520
1520
|
onApi,
|
|
1521
1521
|
langCode = "vi-VN",
|
|
1522
|
-
stamps = DEFAULT_STAMPS
|
|
1522
|
+
stamps = DEFAULT_STAMPS,
|
|
1523
|
+
initialScene,
|
|
1524
|
+
initialFiles
|
|
1523
1525
|
}) {
|
|
1524
1526
|
const [api, setApi] = useState(null);
|
|
1525
1527
|
const apiRef = useRef(null);
|
|
@@ -1548,7 +1550,7 @@ function Whiteboard({
|
|
|
1548
1550
|
() => persistEnabled ? readScene(storageKey) : null,
|
|
1549
1551
|
[persistEnabled, storageKey]
|
|
1550
1552
|
);
|
|
1551
|
-
const effectiveInitialScene = persistedInitial ? {
|
|
1553
|
+
const effectiveInitialScene = initialScene !== void 0 ? initialScene : persistedInitial ? {
|
|
1552
1554
|
elements: persistedInitial.elements,
|
|
1553
1555
|
appState: persistedInitial.appState
|
|
1554
1556
|
} : null;
|
|
@@ -1723,6 +1725,30 @@ function Whiteboard({
|
|
|
1723
1725
|
console.warn("[whiteboard] flushPrune th\u1EA5t b\u1EA1i:", err);
|
|
1724
1726
|
}
|
|
1725
1727
|
};
|
|
1728
|
+
const initialFilesAddedRef = useRef(false);
|
|
1729
|
+
useEffect(() => {
|
|
1730
|
+
if (!api || initialFilesAddedRef.current) return;
|
|
1731
|
+
initialFilesAddedRef.current = true;
|
|
1732
|
+
if (!initialFiles) return;
|
|
1733
|
+
const entries = Object.entries(initialFiles);
|
|
1734
|
+
if (entries.length === 0) return;
|
|
1735
|
+
try {
|
|
1736
|
+
api.addFiles(
|
|
1737
|
+
entries.map(([id, f]) => ({
|
|
1738
|
+
id,
|
|
1739
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1740
|
+
dataURL: f.dataURL,
|
|
1741
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1742
|
+
mimeType: f.mimeType,
|
|
1743
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1744
|
+
created: f.created ?? Date.now()
|
|
1745
|
+
}))
|
|
1746
|
+
);
|
|
1747
|
+
entries.forEach(([id]) => knownFileIdsRef.current.add(id));
|
|
1748
|
+
} catch (err) {
|
|
1749
|
+
console.warn("[whiteboard] addFiles initialFiles th\u1EA5t b\u1EA1i:", err);
|
|
1750
|
+
}
|
|
1751
|
+
}, [api]);
|
|
1726
1752
|
useEffect(() => {
|
|
1727
1753
|
if (!api || !persistEnabled) return;
|
|
1728
1754
|
let cancelled = false;
|