@8btc/xcanvas 0.0.14-beta.4 → 0.0.14-beta.6
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 +13 -4
- package/dist/index.umd.cjs +13 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { atom, useAtom, useAtomValue, useSetAtom } from "jotai";
|
|
3
3
|
import { Excalidraw, convertToExcalidrawElements, exportToCanvas } from "@8btc/excalidraw";
|
|
4
4
|
import { useEffect } from "react";
|
|
5
|
-
const version = "0.0.14-beta.
|
|
5
|
+
const version = "0.0.14-beta.6";
|
|
6
6
|
const packageJson = {
|
|
7
7
|
version
|
|
8
8
|
};
|
|
@@ -40,7 +40,7 @@ function CustomExcalidraw(props) {
|
|
|
40
40
|
function fetchImageAsDataUrl(src) {
|
|
41
41
|
return new Promise((resolve, reject) => {
|
|
42
42
|
const img = new Image();
|
|
43
|
-
img.crossOrigin = "
|
|
43
|
+
img.crossOrigin = "anonymous";
|
|
44
44
|
img.onload = () => {
|
|
45
45
|
const canvas = document.createElement("canvas");
|
|
46
46
|
canvas.width = img.naturalWidth;
|
|
@@ -178,11 +178,21 @@ function ApiFactory() {
|
|
|
178
178
|
const els = excalidrawAPI.getSceneElements();
|
|
179
179
|
const imgEls = els.filter((el) => el.type === "image");
|
|
180
180
|
const idSet = /* @__PURE__ */ new Set();
|
|
181
|
+
const intersecitonEls = [];
|
|
181
182
|
imgEls.forEach((it) => {
|
|
182
183
|
idSet.add(it.fileId);
|
|
184
|
+
if (urls.includes(it.fileId)) {
|
|
185
|
+
intersecitonEls.push(it);
|
|
186
|
+
}
|
|
183
187
|
});
|
|
184
188
|
const newUrls = urls.filter((url) => !idSet.has(url));
|
|
185
|
-
|
|
189
|
+
if (newUrls.length !== 0) {
|
|
190
|
+
await insertImgs(newUrls);
|
|
191
|
+
} else {
|
|
192
|
+
excalidrawAPI.scrollToContent(intersecitonEls, {
|
|
193
|
+
animate: els.length === 0 ? false : true
|
|
194
|
+
});
|
|
195
|
+
}
|
|
186
196
|
},
|
|
187
197
|
save: () => {
|
|
188
198
|
const appState = excalidrawAPI.getAppState();
|
|
@@ -306,7 +316,6 @@ function ApiFactory() {
|
|
|
306
316
|
}
|
|
307
317
|
const files = excalidrawAPI.getFiles();
|
|
308
318
|
if (selectedElements.length === 1 && selectedElements[0].type === "image" && selectedElements[0].fileId) {
|
|
309
|
-
console.log(files[selectedElements[0].fileId].dataURL);
|
|
310
319
|
if (selectedElements[0].fileId.startsWith("http") || selectedElements[0].fileId.startsWith("/files")) {
|
|
311
320
|
return selectedElements[0].fileId;
|
|
312
321
|
}
|
package/dist/index.umd.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("react/jsx-runtime"), require("jotai"), require("@8btc/excalidraw"), require("react")) : typeof define === "function" && define.amd ? define(["exports", "react/jsx-runtime", "jotai", "@8btc/excalidraw", "react"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.XCanvas = {}, global.jsxRuntime, global.Jotai, global.Excalidraw, global.React));
|
|
3
3
|
})(this, (function(exports2, jsxRuntime, jotai, excalidraw, react) {
|
|
4
4
|
"use strict";
|
|
5
|
-
const version = "0.0.14-beta.
|
|
5
|
+
const version = "0.0.14-beta.6";
|
|
6
6
|
const packageJson = {
|
|
7
7
|
version
|
|
8
8
|
};
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
function fetchImageAsDataUrl(src) {
|
|
41
41
|
return new Promise((resolve, reject) => {
|
|
42
42
|
const img = new Image();
|
|
43
|
-
img.crossOrigin = "
|
|
43
|
+
img.crossOrigin = "anonymous";
|
|
44
44
|
img.onload = () => {
|
|
45
45
|
const canvas = document.createElement("canvas");
|
|
46
46
|
canvas.width = img.naturalWidth;
|
|
@@ -178,11 +178,21 @@
|
|
|
178
178
|
const els = excalidrawAPI.getSceneElements();
|
|
179
179
|
const imgEls = els.filter((el) => el.type === "image");
|
|
180
180
|
const idSet = /* @__PURE__ */ new Set();
|
|
181
|
+
const intersecitonEls = [];
|
|
181
182
|
imgEls.forEach((it) => {
|
|
182
183
|
idSet.add(it.fileId);
|
|
184
|
+
if (urls.includes(it.fileId)) {
|
|
185
|
+
intersecitonEls.push(it);
|
|
186
|
+
}
|
|
183
187
|
});
|
|
184
188
|
const newUrls = urls.filter((url) => !idSet.has(url));
|
|
185
|
-
|
|
189
|
+
if (newUrls.length !== 0) {
|
|
190
|
+
await insertImgs(newUrls);
|
|
191
|
+
} else {
|
|
192
|
+
excalidrawAPI.scrollToContent(intersecitonEls, {
|
|
193
|
+
animate: els.length === 0 ? false : true
|
|
194
|
+
});
|
|
195
|
+
}
|
|
186
196
|
},
|
|
187
197
|
save: () => {
|
|
188
198
|
const appState = excalidrawAPI.getAppState();
|
|
@@ -306,7 +316,6 @@
|
|
|
306
316
|
}
|
|
307
317
|
const files = excalidrawAPI.getFiles();
|
|
308
318
|
if (selectedElements.length === 1 && selectedElements[0].type === "image" && selectedElements[0].fileId) {
|
|
309
|
-
console.log(files[selectedElements[0].fileId].dataURL);
|
|
310
319
|
if (selectedElements[0].fileId.startsWith("http") || selectedElements[0].fileId.startsWith("/files")) {
|
|
311
320
|
return selectedElements[0].fileId;
|
|
312
321
|
}
|