@riebeckite/plugin-excalidraw 0.0.30 → 0.0.32
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/client.js +9 -6
- package/dist/index.js +4 -1
- package/dist/src/client_init.d.ts +6 -1
- package/package.json +2 -2
package/dist/client.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// src/client_init.ts
|
|
2
|
-
function initExcalidraw() {
|
|
2
|
+
function initExcalidraw(context = {}) {
|
|
3
|
+
const root = context.root ?? document;
|
|
3
4
|
const figures = Array.from(
|
|
4
|
-
|
|
5
|
+
root.querySelectorAll(
|
|
5
6
|
'.rr-excalidraw[data-excalidraw="pending"]'
|
|
6
7
|
)
|
|
7
8
|
);
|
|
@@ -9,13 +10,13 @@ function initExcalidraw() {
|
|
|
9
10
|
const immediate = figures.filter(
|
|
10
11
|
(figure) => figure.dataset.excalidrawLazy === "false"
|
|
11
12
|
);
|
|
12
|
-
for (const figure of immediate) void renderFigure(figure);
|
|
13
|
+
for (const figure of immediate) void renderFigure(figure, context.signal);
|
|
13
14
|
const lazy = figures.filter(
|
|
14
15
|
(figure) => figure.dataset.excalidrawLazy !== "false"
|
|
15
16
|
);
|
|
16
17
|
if (lazy.length === 0) return;
|
|
17
18
|
if (!("IntersectionObserver" in window)) {
|
|
18
|
-
for (const figure of lazy) void renderFigure(figure);
|
|
19
|
+
for (const figure of lazy) void renderFigure(figure, context.signal);
|
|
19
20
|
return;
|
|
20
21
|
}
|
|
21
22
|
const observer = new IntersectionObserver(
|
|
@@ -24,14 +25,15 @@ function initExcalidraw() {
|
|
|
24
25
|
if (!entry.isIntersecting) continue;
|
|
25
26
|
const figure = entry.target;
|
|
26
27
|
observer.unobserve(figure);
|
|
27
|
-
void renderFigure(figure);
|
|
28
|
+
void renderFigure(figure, context.signal);
|
|
28
29
|
}
|
|
29
30
|
},
|
|
30
31
|
{ rootMargin: "200px" }
|
|
31
32
|
);
|
|
32
33
|
for (const figure of lazy) observer.observe(figure);
|
|
34
|
+
return () => observer.disconnect();
|
|
33
35
|
}
|
|
34
|
-
async function renderFigure(figure) {
|
|
36
|
+
async function renderFigure(figure, signal) {
|
|
35
37
|
const canvas = figure.querySelector(".rr-excalidraw__canvas");
|
|
36
38
|
const payloadScript = figure.querySelector(
|
|
37
39
|
".rr-excalidraw__payload"
|
|
@@ -48,6 +50,7 @@ async function renderFigure(figure) {
|
|
|
48
50
|
},
|
|
49
51
|
files: payload.files
|
|
50
52
|
});
|
|
53
|
+
if (signal?.aborted || !figure.isConnected) return;
|
|
51
54
|
svg.removeAttribute("width");
|
|
52
55
|
svg.removeAttribute("height");
|
|
53
56
|
svg.setAttribute("role", "img");
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riebeckite/plugin-excalidraw",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.32",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"@excalidraw/excalidraw": "^0.18.0",
|
|
25
25
|
"lz-string": "^1.5.0",
|
|
26
26
|
"unist-util-visit": "^5.0.0",
|
|
27
|
-
"@riebeckite/core": "0.0.
|
|
27
|
+
"@riebeckite/core": "0.0.32"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/mdast": "^4.0.4",
|