@haklex/rich-ext-excalidraw 0.0.82 → 0.0.83

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.
@@ -1,205 +0,0 @@
1
- import { createContext, use, useEffect, useMemo, useState } from "react";
2
- import { jsx } from "react/jsx-runtime";
3
- //#region src/ExcalidrawConfigContext.tsx
4
- var ExcalidrawConfigContext = createContext({});
5
- function ExcalidrawConfigProvider({ apiUrl, saveSnapshot, children }) {
6
- const value = useMemo(() => ({
7
- apiUrl,
8
- saveSnapshot
9
- }), [apiUrl, saveSnapshot]);
10
- return /* @__PURE__ */ jsx(ExcalidrawConfigContext.Provider, {
11
- value,
12
- children
13
- });
14
- }
15
- function useExcalidrawConfig() {
16
- return use(ExcalidrawConfigContext);
17
- }
18
- //#endregion
19
- //#region src/constants.ts
20
- var readonlyUIOptions = { canvasActions: {
21
- toggleTheme: false,
22
- export: false,
23
- saveAsImage: false,
24
- loadScene: false,
25
- changeViewBackgroundColor: false
26
- } };
27
- //#endregion
28
- //#region src/styles.css.ts
29
- var excalidrawStaticContainer = "_1c3wdzl0";
30
- var excalidrawEditorContainer = "_1c3wdzl1";
31
- var excalidrawPlaceholder = "_1c3wdzl2";
32
- var excalidrawLoading = "_1c3wdzl3";
33
- var excalidrawError = "_1c3wdzl5";
34
- var excalidrawActionGroup = "_1c3wdzl6";
35
- var excalidrawActionButton = "_1c3wdzl7";
36
- var excalidrawFullscreenPopup = "_1c3wdzl8";
37
- var excalidrawDialogHeader = "_1c3wdzl9";
38
- var excalidrawDialogHeaderTitle = "_1c3wdzla";
39
- var excalidrawStatusDot = "_1c3wdzlb";
40
- var excalidrawDialogTitle = "_1c3wdzlc";
41
- var excalidrawDialogMeta = "_1c3wdzld";
42
- var excalidrawHeaderActions = "_1c3wdzle";
43
- var excalidrawHeaderClose = "_1c3wdzlf";
44
- var excalidrawActionBarBtn = "_1c3wdzlg";
45
- var excalidrawActionBarSep = "_1c3wdzlh";
46
- var excalidrawActionBarUrl = "_1c3wdzli";
47
- var excalidrawDialogCanvas = "_1c3wdzlj";
48
- var excalidrawConfirmActions = "_1c3wdzlk";
49
- var excalidrawConfirmBtn = "_1c3wdzll";
50
- var excalidrawConfirmBtnPrimary = "_1c3wdzlm";
51
- var excalidrawConfirmBtnDanger = "_1c3wdzln";
52
- var excalidrawEditOverlay = "_1c3wdzlo";
53
- var excalidrawEditLabel = "_1c3wdzlp";
54
- //#endregion
55
- //#region src/types.ts
56
- function parseSnapshot(raw) {
57
- if (!raw || !raw.trim()) return null;
58
- try {
59
- const json = JSON.parse(raw);
60
- if (json && typeof json === "object") return {
61
- type: "inline",
62
- data: json
63
- };
64
- } catch {}
65
- const lines = raw.split("\n");
66
- const firstLine = lines[0].trim();
67
- if (!firstLine.startsWith("http") && !firstLine.startsWith("blob:") && !firstLine.startsWith("ref:")) return null;
68
- const remaining = lines.slice(1).join("\n").trim();
69
- if (remaining) try {
70
- const delta = JSON.parse(remaining);
71
- if (delta && typeof delta === "object") return {
72
- type: "delta",
73
- baseUrl: firstLine,
74
- delta
75
- };
76
- } catch {}
77
- return {
78
- type: "remote",
79
- url: firstLine
80
- };
81
- }
82
- function serializeSnapshot(snapshot) {
83
- switch (snapshot.type) {
84
- case "inline": return JSON.stringify(snapshot.data);
85
- case "remote": return snapshot.url;
86
- case "delta": return [snapshot.baseUrl, JSON.stringify(snapshot.delta)].join("\n");
87
- }
88
- }
89
- //#endregion
90
- //#region src/useExcalidrawData.ts
91
- function resolveUrl(url, apiUrl) {
92
- const refLine = url;
93
- if (url.startsWith("http") || url.startsWith("blob:")) return {
94
- fetchUrl: url,
95
- refLine
96
- };
97
- if (url.startsWith("ref:") && apiUrl) return {
98
- fetchUrl: `${apiUrl}/objects/${url.slice(4)}`,
99
- refLine
100
- };
101
- return { error: url.startsWith("ref:") ? "Missing apiUrl for ref resolution" : "Unrecognized snapshot format" };
102
- }
103
- function typedToParsed(typed, apiUrl) {
104
- switch (typed.type) {
105
- case "inline": return {
106
- type: "inline",
107
- snapshot: typed.data
108
- };
109
- case "remote": {
110
- const result = resolveUrl(typed.url, apiUrl);
111
- if ("error" in result) return {
112
- type: "error",
113
- error: result.error
114
- };
115
- return {
116
- type: "remote",
117
- fetchUrl: result.fetchUrl,
118
- refLine: result.refLine
119
- };
120
- }
121
- case "delta": {
122
- const result = resolveUrl(typed.baseUrl, apiUrl);
123
- if ("error" in result) return {
124
- type: "error",
125
- error: result.error
126
- };
127
- return {
128
- type: "incremental",
129
- fetchUrl: result.fetchUrl,
130
- refLine: result.refLine,
131
- delta: typed.delta
132
- };
133
- }
134
- }
135
- }
136
- function stringToParsed(data, apiUrl) {
137
- const typed = parseSnapshot(data);
138
- if (!typed) return { type: "empty" };
139
- return typedToParsed(typed, apiUrl);
140
- }
141
- function useExcalidrawData(data) {
142
- const { apiUrl } = useExcalidrawConfig();
143
- const parsed = useMemo(() => {
144
- if (data === null || data === void 0) return { type: "empty" };
145
- if (typeof data === "string") return stringToParsed(data, apiUrl);
146
- return typedToParsed(data, apiUrl);
147
- }, [data, apiUrl]);
148
- const [remoteSnapshot, setRemoteSnapshot] = useState();
149
- const [baseData, setBaseData] = useState();
150
- const [loading, setLoading] = useState(parsed.type === "remote" || parsed.type === "incremental");
151
- const [error, setError] = useState("");
152
- useEffect(() => {
153
- if (parsed.type !== "remote" && parsed.type !== "incremental") return;
154
- const { fetchUrl } = parsed;
155
- const delta = parsed.type === "incremental" ? parsed.delta : void 0;
156
- let cancelled = false;
157
- setLoading(true);
158
- setError("");
159
- fetch(fetchUrl).then((res) => {
160
- if (!res.ok) throw new Error(`HTTP ${res.status}`);
161
- return res.json();
162
- }).then(async (json) => {
163
- if (cancelled) return;
164
- setBaseData(json);
165
- if ((delta ? Object.keys(delta) : []).length > 0) {
166
- const { patch } = await import("jsondiffpatch");
167
- if (cancelled) return;
168
- setRemoteSnapshot(patch(structuredClone(json), delta));
169
- } else setRemoteSnapshot(json);
170
- setLoading(false);
171
- }).catch((err) => {
172
- if (!cancelled) {
173
- setError(err instanceof Error ? err.message : "Failed to load");
174
- setLoading(false);
175
- }
176
- });
177
- return () => {
178
- cancelled = true;
179
- };
180
- }, [parsed]);
181
- if (parsed.type === "inline") return {
182
- snapshot: parsed.snapshot,
183
- loading: false,
184
- error: ""
185
- };
186
- if (parsed.type === "remote" || parsed.type === "incremental") return {
187
- snapshot: remoteSnapshot,
188
- loading,
189
- error,
190
- baseRef: parsed.refLine,
191
- baseData
192
- };
193
- if (parsed.type === "error") return {
194
- snapshot: void 0,
195
- loading: false,
196
- error: parsed.error
197
- };
198
- return {
199
- snapshot: void 0,
200
- loading: false,
201
- error: ""
202
- };
203
- }
204
- //#endregion
205
- export { ExcalidrawConfigProvider as A, excalidrawHeaderActions as C, excalidrawStaticContainer as D, excalidrawPlaceholder as E, excalidrawStatusDot as O, excalidrawFullscreenPopup as S, excalidrawLoading as T, excalidrawDialogTitle as _, excalidrawActionBarSep as a, excalidrawEditorContainer as b, excalidrawActionGroup as c, excalidrawConfirmBtnDanger as d, excalidrawConfirmBtnPrimary as f, excalidrawDialogMeta as g, excalidrawDialogHeaderTitle as h, excalidrawActionBarBtn as i, useExcalidrawConfig as j, readonlyUIOptions as k, excalidrawConfirmActions as l, excalidrawDialogHeader as m, parseSnapshot as n, excalidrawActionBarUrl as o, excalidrawDialogCanvas as p, serializeSnapshot as r, excalidrawActionButton as s, useExcalidrawData as t, excalidrawConfirmBtn as u, excalidrawEditLabel as v, excalidrawHeaderClose as w, excalidrawError as x, excalidrawEditOverlay as y };