@chengzhiyi/pi-excalidraw 0.1.3 → 0.1.5
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/frame.css +64 -0
- package/dist/frame.js +33 -7
- package/dist/resources.json +4 -4
- package/package.json +3 -3
package/dist/frame.css
CHANGED
|
@@ -164,6 +164,70 @@
|
|
|
164
164
|
width: 100%;
|
|
165
165
|
height: auto;
|
|
166
166
|
}
|
|
167
|
+
.diagrams_placeholder {
|
|
168
|
+
box-sizing: border-box;
|
|
169
|
+
display: flex;
|
|
170
|
+
flex-direction: column;
|
|
171
|
+
align-items: center;
|
|
172
|
+
justify-content: center;
|
|
173
|
+
gap: 8px;
|
|
174
|
+
height: 100%;
|
|
175
|
+
min-height: 180px;
|
|
176
|
+
padding: 24px;
|
|
177
|
+
text-align: center;
|
|
178
|
+
color: var(--diagram-muted, var(--text-secondary));
|
|
179
|
+
font-size: 12px;
|
|
180
|
+
}
|
|
181
|
+
.diagrams_placeholder p {
|
|
182
|
+
margin: 0;
|
|
183
|
+
max-width: 420px;
|
|
184
|
+
overflow-wrap: anywhere;
|
|
185
|
+
}
|
|
186
|
+
.diagrams_placeholderTitle {
|
|
187
|
+
color: var(--diagram-fg, var(--text-primary));
|
|
188
|
+
font-size: 13px;
|
|
189
|
+
font-weight: 500;
|
|
190
|
+
}
|
|
191
|
+
.diagrams_placeholder button {
|
|
192
|
+
margin-top: 4px;
|
|
193
|
+
padding: 6px 14px;
|
|
194
|
+
border: 1px solid var(--diagram-border, var(--border-default));
|
|
195
|
+
border-radius: 7px;
|
|
196
|
+
color: var(--diagram-fg, var(--text-primary));
|
|
197
|
+
background: transparent;
|
|
198
|
+
font-size: 12px;
|
|
199
|
+
}
|
|
200
|
+
.diagrams_placeholder button:hover {
|
|
201
|
+
background: var(--dsw-alias-interactive-bg-hover);
|
|
202
|
+
}
|
|
203
|
+
.diagrams_placeholder button:focus-visible {
|
|
204
|
+
outline: 2px solid #818cf8;
|
|
205
|
+
outline-offset: 2px;
|
|
206
|
+
}
|
|
207
|
+
.diagrams_spinner {
|
|
208
|
+
width: 18px;
|
|
209
|
+
height: 18px;
|
|
210
|
+
border: 2px solid var(--diagram-border, var(--border-default));
|
|
211
|
+
border-top-color: var(--diagram-muted, var(--text-secondary));
|
|
212
|
+
border-radius: 50%;
|
|
213
|
+
opacity: 0;
|
|
214
|
+
animation: diagrams_fadeIn .2s ease .6s forwards, diagrams_spin .8s linear infinite;
|
|
215
|
+
}
|
|
216
|
+
@keyframes diagrams_fadeIn {
|
|
217
|
+
to {
|
|
218
|
+
opacity: .8;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
@keyframes diagrams_spin {
|
|
222
|
+
to {
|
|
223
|
+
transform: rotate(360deg);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
@media (prefers-reduced-motion: reduce) {
|
|
227
|
+
.diagrams_spinner {
|
|
228
|
+
animation: diagrams_fadeIn .2s ease .6s forwards;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
167
231
|
.diagrams_previewPlaceholder {
|
|
168
232
|
display: grid;
|
|
169
233
|
place-items: center;
|
package/dist/frame.js
CHANGED
|
@@ -283,6 +283,11 @@ var diagrams_default = {
|
|
|
283
283
|
toolDetails: "diagrams_toolDetails",
|
|
284
284
|
previewViewport: "diagrams_previewViewport",
|
|
285
285
|
streamImage: "diagrams_streamImage",
|
|
286
|
+
placeholder: "diagrams_placeholder",
|
|
287
|
+
placeholderTitle: "diagrams_placeholderTitle",
|
|
288
|
+
spinner: "diagrams_spinner",
|
|
289
|
+
fadeIn: "diagrams_fadeIn",
|
|
290
|
+
spin: "diagrams_spin",
|
|
286
291
|
previewPlaceholder: "diagrams_previewPlaceholder",
|
|
287
292
|
editButton: "diagrams_editButton",
|
|
288
293
|
review: "diagrams_review",
|
|
@@ -301,15 +306,31 @@ function clearDownloads() {
|
|
|
301
306
|
}
|
|
302
307
|
var download = downloadDrawing;
|
|
303
308
|
var errorText = (error) => error instanceof Error ? error.message : String(error);
|
|
309
|
+
function Placeholder({ error, locale, retry }) {
|
|
310
|
+
const t = (zh, en) => locale === "zh" ? zh : en;
|
|
311
|
+
if (!error) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: diagrams_default.placeholder, role: "status", "aria-busy": "true", "aria-label": t("\u6B63\u5728\u52A0\u8F7D Excalidraw", "Loading Excalidraw"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: diagrams_default.spinner }) });
|
|
312
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: diagrams_default.placeholder, role: "alert", children: [
|
|
313
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: diagrams_default.placeholderTitle, children: t("Excalidraw \u6682\u65F6\u65E0\u6CD5\u52A0\u8F7D", "Excalidraw could not load") }),
|
|
314
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: diagrams_default.placeholderDetail, children: error }),
|
|
315
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", onClick: retry, children: t("\u91CD\u8BD5", "Retry") })
|
|
316
|
+
] });
|
|
317
|
+
}
|
|
304
318
|
function DiagramWorkspace(p) {
|
|
305
319
|
const pending = (0, import_react.useRef)(null);
|
|
306
320
|
const [draft, setDraft] = (0, import_react.useState)(null), [error, setError] = (0, import_react.useState)("");
|
|
321
|
+
const [attempt, setAttempt] = (0, import_react.useState)(0);
|
|
307
322
|
(0, import_react.useEffect)(() => {
|
|
308
323
|
if (!p.visible) return;
|
|
309
324
|
pending.current ??= diagramAction(p.session.sessionId, "new", {});
|
|
310
|
-
void pending.current.then(setDraft).catch((e) =>
|
|
311
|
-
|
|
312
|
-
|
|
325
|
+
void pending.current.then(setDraft).catch((e) => {
|
|
326
|
+
pending.current = null;
|
|
327
|
+
setError(errorText(e));
|
|
328
|
+
});
|
|
329
|
+
}, [p.visible, p.session.sessionId, attempt]);
|
|
330
|
+
return draft ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DiagramEditor, { ...p, contentId: draft.id }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Placeholder, { error, locale: p.locale, retry: () => {
|
|
331
|
+
setError("");
|
|
332
|
+
setAttempt((value) => value + 1);
|
|
333
|
+
} });
|
|
313
334
|
}
|
|
314
335
|
function DiagramEditor(p) {
|
|
315
336
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DiagramEditorRoute, { ...p }, JSON.stringify([p.session.sessionId, p.contentId]));
|
|
@@ -355,6 +376,7 @@ function NativeDiagramEditor(p) {
|
|
|
355
376
|
const state = (0, import_react.useSyncExternalStore)(model.subscribe, model.getSnapshot);
|
|
356
377
|
const [canvas, setCanvas] = (0, import_react.useState)(null), [error, setError] = (0, import_react.useState)("");
|
|
357
378
|
const [dialog, setDialog] = (0, import_react.useState)(null), [path, setPath] = (0, import_react.useState)("");
|
|
379
|
+
const [attempt, setAttempt] = (0, import_react.useState)(0);
|
|
358
380
|
const t = (zh, en) => p.locale === "zh" ? zh : en;
|
|
359
381
|
const run = async (operation) => {
|
|
360
382
|
setError("");
|
|
@@ -387,7 +409,7 @@ function NativeDiagramEditor(p) {
|
|
|
387
409
|
clearInterval(timer2);
|
|
388
410
|
model.suspend();
|
|
389
411
|
};
|
|
390
|
-
}, [model, p.visible, p.contentId, p.session.sessionId]);
|
|
412
|
+
}, [model, p.visible, p.contentId, p.session.sessionId, attempt]);
|
|
391
413
|
const candidateId = state.draft?.candidate?.id;
|
|
392
414
|
(0, import_react.useEffect)(() => {
|
|
393
415
|
if (canvas && candidateId) void model.initialize(canvas.materialize).catch((e) => setError(errorText(e)));
|
|
@@ -406,6 +428,7 @@ function NativeDiagramEditor(p) {
|
|
|
406
428
|
setPath(state.draft?.path ?? `diagrams/${p.contentId}.excalidraw`);
|
|
407
429
|
setDialog("save");
|
|
408
430
|
};
|
|
431
|
+
const ready = p.visible && canvas && state.scene;
|
|
409
432
|
const downloadSource = async () => {
|
|
410
433
|
const scene = model.getSnapshot().scene;
|
|
411
434
|
if (scene) await download(new Blob([JSON.stringify(scene)], { type: "application/json" }), `${state.draft?.title ?? "diagram"}.excalidraw`);
|
|
@@ -417,7 +440,10 @@ function NativeDiagramEditor(p) {
|
|
|
417
440
|
openDialog("save");
|
|
418
441
|
}
|
|
419
442
|
}, children: [
|
|
420
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: diagrams_default.canvas, "data-diagram-canvas": true, children:
|
|
443
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: diagrams_default.canvas, "data-diagram-canvas": true, children: ready ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(canvas.default, { scene: state.scene, readOnly: state.busy, locale: p.locale, onChange: (value) => model.change(value), onError: setError }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Placeholder, { error: error || state.error, locale: p.locale, retry: () => {
|
|
444
|
+
setError("");
|
|
445
|
+
setAttempt((value) => value + 1);
|
|
446
|
+
} }) }),
|
|
421
447
|
dialog && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: diagrams_default.modalBackdrop, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("form", { className: diagrams_default.dialog, role: "dialog", "aria-label": t("\u4FDD\u5B58\u56FE\u7A3F", "Save diagram"), onSubmit: (event) => {
|
|
422
448
|
event.preventDefault();
|
|
423
449
|
void run(async () => {
|
|
@@ -440,7 +466,7 @@ function NativeDiagramEditor(p) {
|
|
|
440
466
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { onClick: () => model.restore(), children: t("\u6062\u590D", "Restore") }),
|
|
441
467
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { onClick: () => model.dismissRecovery(), children: t("\u4FDD\u7559\u5F53\u524D\u56FE\u7A3F", "Keep current") })
|
|
442
468
|
] }),
|
|
443
|
-
!dialog && (error || state.error) && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: diagrams_default.error, role: "alert", children: [
|
|
469
|
+
ready && !dialog && (error || state.error) && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: diagrams_default.error, role: "alert", children: [
|
|
444
470
|
error || state.error,
|
|
445
471
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { onClick: () => void run(() => model.reload()), children: t("\u91CD\u65B0\u8F7D\u5165", "Reload") }),
|
|
446
472
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { onClick: () => void run(downloadSource), children: t("\u4E0B\u8F7D\u8349\u7A3F", "Download draft") })
|
|
@@ -665,7 +691,7 @@ function DiagramPreview({ sessionId, id, title, locale, open, header, collapsed,
|
|
|
665
691
|
header(state.unavailable),
|
|
666
692
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { id: bodyId, hidden: collapsed, children: [
|
|
667
693
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: diagrams_default.previewViewport, "data-diagram-preview": true, children: [
|
|
668
|
-
image && !state.unavailable ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("img", { src: image, alt: title, "data-scene-revision": renderedKey }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: diagrams_default.previewPlaceholder, children:
|
|
694
|
+
image && !state.unavailable ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("img", { src: image, alt: title, "data-scene-revision": renderedKey }) : state.unavailable ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: diagrams_default.previewPlaceholder, children: t("\u6B64\u5386\u53F2\u56FE\u7A3F\u6CA1\u6709\u53EF\u7528\u5185\u5BB9\u3002", "No content is available for this historical drawing.") }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: diagrams_default.previewPlaceholder, role: "status", "aria-busy": !(error || state.error), "aria-label": t("\u6B63\u5728\u52A0\u8F7D Excalidraw", "Loading Excalidraw"), children: !(error || state.error) && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: diagrams_default.spinner }) }),
|
|
669
695
|
state.unavailable ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { onClick: open, children: t("\u6062\u590D\u9009\u9879", "Recovery options") }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: diagrams_default.editButton, onClick: open, "aria-label": t("\u7F16\u8F91 Excalidraw", "Edit Excalidraw"), children: t("\u7F16\u8F91 \u2197", "Edit \u2197") })
|
|
670
696
|
] }),
|
|
671
697
|
candidate && !initial && !state.unavailable && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: diagrams_default.review, role: "status", children: [
|
package/dist/resources.json
CHANGED
|
@@ -2541,8 +2541,8 @@
|
|
|
2541
2541
|
},
|
|
2542
2542
|
{
|
|
2543
2543
|
"path": "./dist/frame.css",
|
|
2544
|
-
"bytes":
|
|
2545
|
-
"sha256": "
|
|
2544
|
+
"bytes": 174290,
|
|
2545
|
+
"sha256": "c6754a0961df1226ed93e3d1aada5a346cb2bb805e9f0d28554136393a406ec0",
|
|
2546
2546
|
"mime": "text/css"
|
|
2547
2547
|
},
|
|
2548
2548
|
{
|
|
@@ -2553,8 +2553,8 @@
|
|
|
2553
2553
|
},
|
|
2554
2554
|
{
|
|
2555
2555
|
"path": "./dist/frame.js",
|
|
2556
|
-
"bytes":
|
|
2557
|
-
"sha256": "
|
|
2556
|
+
"bytes": 43702,
|
|
2557
|
+
"sha256": "7a6fa3f0cd6fe70d1c4387ca413b0e8d12c2e03552be7dc12869da7542c79c4c",
|
|
2558
2558
|
"mime": "text/javascript"
|
|
2559
2559
|
},
|
|
2560
2560
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chengzhiyi/pi-excalidraw",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Self-contained hosted v2 Excalidraw plugin for pi-webapp",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -53,8 +53,8 @@
|
|
|
53
53
|
"directory": "packages/excalidraw"
|
|
54
54
|
},
|
|
55
55
|
"piRelease": {
|
|
56
|
-
"fingerprint": "
|
|
57
|
-
"source": "
|
|
56
|
+
"fingerprint": "262b3f40586c545eaedae03f66eaa847308ead688a3a0ec662ceef990886ea2c",
|
|
57
|
+
"source": "07799b0eeb863e11bbcc1e1e83630b9839e13864"
|
|
58
58
|
},
|
|
59
59
|
"scripts": {
|
|
60
60
|
"build": "node scripts/build.mjs",
|