@8btc/xcanvas 0.0.14-beta.2 → 0.0.14-beta.3

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 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.2";
5
+ const version = "0.0.14-beta.3";
6
6
  const packageJson = {
7
7
  version
8
8
  };
@@ -118,15 +118,18 @@ function ApiFactory() {
118
118
  };
119
119
  })
120
120
  );
121
+ const files = excalidrawAPI.getFiles();
121
122
  rets.forEach((it) => {
122
- excalidrawAPI.addFiles([
123
- {
124
- mimeType: "image/png",
125
- id: it.url,
126
- dataURL: it.dataUrl,
127
- created: Date.now()
128
- }
129
- ]);
123
+ if (!files[it.url]) {
124
+ excalidrawAPI.addFiles([
125
+ {
126
+ mimeType: "image/png",
127
+ id: it.url,
128
+ dataURL: it.dataUrl,
129
+ created: Date.now()
130
+ }
131
+ ]);
132
+ }
130
133
  });
131
134
  const places = findPlaceForNewElements(
132
135
  excalidrawAPI.getAppState(),
@@ -172,8 +175,13 @@ function ApiFactory() {
172
175
  },
173
176
  insertImgs,
174
177
  appendImgs: async (urls) => {
175
- const files = excalidrawAPI.getFiles();
176
- const newUrls = urls.filter((it) => !files[it]);
178
+ const els = excalidrawAPI.getSceneElements();
179
+ const imgEls = els.filter((el) => el.type === "image");
180
+ const idSet = /* @__PURE__ */ new Set();
181
+ imgEls.forEach((it) => {
182
+ idSet.add(it.fileId);
183
+ });
184
+ const newUrls = urls.filter((url) => !idSet.has(url));
177
185
  await insertImgs(newUrls);
178
186
  },
179
187
  save: () => {
@@ -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.2";
5
+ const version = "0.0.14-beta.3";
6
6
  const packageJson = {
7
7
  version
8
8
  };
@@ -118,15 +118,18 @@
118
118
  };
119
119
  })
120
120
  );
121
+ const files = excalidrawAPI.getFiles();
121
122
  rets.forEach((it) => {
122
- excalidrawAPI.addFiles([
123
- {
124
- mimeType: "image/png",
125
- id: it.url,
126
- dataURL: it.dataUrl,
127
- created: Date.now()
128
- }
129
- ]);
123
+ if (!files[it.url]) {
124
+ excalidrawAPI.addFiles([
125
+ {
126
+ mimeType: "image/png",
127
+ id: it.url,
128
+ dataURL: it.dataUrl,
129
+ created: Date.now()
130
+ }
131
+ ]);
132
+ }
130
133
  });
131
134
  const places = findPlaceForNewElements(
132
135
  excalidrawAPI.getAppState(),
@@ -172,8 +175,13 @@
172
175
  },
173
176
  insertImgs,
174
177
  appendImgs: async (urls) => {
175
- const files = excalidrawAPI.getFiles();
176
- const newUrls = urls.filter((it) => !files[it]);
178
+ const els = excalidrawAPI.getSceneElements();
179
+ const imgEls = els.filter((el) => el.type === "image");
180
+ const idSet = /* @__PURE__ */ new Set();
181
+ imgEls.forEach((it) => {
182
+ idSet.add(it.fileId);
183
+ });
184
+ const newUrls = urls.filter((url) => !idSet.has(url));
177
185
  await insertImgs(newUrls);
178
186
  },
179
187
  save: () => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@8btc/xcanvas",
3
3
  "private": false,
4
- "version": "0.0.14-beta.2",
4
+ "version": "0.0.14-beta.3",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
7
7
  "exports": {