@haklex/rich-ext-tldraw 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/TldrawDisplayRenderer.d.ts +6 -0
- package/dist/TldrawDisplayRenderer.d.ts.map +1 -0
- package/dist/TldrawEditNode.d.ts +14 -0
- package/dist/TldrawEditNode.d.ts.map +1 -0
- package/dist/TldrawNode.d.ts +1 -3
- package/dist/TldrawNode.d.ts.map +1 -1
- package/dist/TldrawRenderer.d.ts +2 -2
- package/dist/TldrawRenderer.d.ts.map +1 -1
- package/dist/TldrawSSRRenderer.d.ts +6 -0
- package/dist/TldrawSSRRenderer.d.ts.map +1 -0
- package/dist/index.d.ts +9 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +445 -382
- package/package.json +5 -5
- package/dist/TldrawStaticRenderer.d.ts +0 -6
- package/dist/TldrawStaticRenderer.d.ts.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TldrawDisplayRenderer.d.ts","sourceRoot":"","sources":["../src/TldrawDisplayRenderer.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAa,KAAK,EAAE,EAAkB,MAAM,OAAO,CAAA;AAM1D,MAAM,WAAW,yBAAyB;IACxC,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,eAAO,MAAM,qBAAqB,EAAE,EAAE,CAAC,yBAAyB,CAsC/D,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SlashMenuItemConfig } from '@haklex/rich-editor';
|
|
2
|
+
import { EditorConfig, LexicalEditor, LexicalNode, NodeKey } from 'lexical';
|
|
3
|
+
import { ReactElement } from 'react';
|
|
4
|
+
import { SerializedTldrawNode, TldrawNode } from './TldrawNode';
|
|
5
|
+
export declare class TldrawEditNode extends TldrawNode {
|
|
6
|
+
static slashMenuItems: SlashMenuItemConfig[];
|
|
7
|
+
static clone(node: TldrawEditNode): TldrawEditNode;
|
|
8
|
+
constructor(snapshot: string, key?: NodeKey);
|
|
9
|
+
static importJSON(serializedNode: SerializedTldrawNode): TldrawEditNode;
|
|
10
|
+
decorate(editor: LexicalEditor, _config: EditorConfig): ReactElement;
|
|
11
|
+
}
|
|
12
|
+
export declare function $createTldrawEditNode(snapshot: string): TldrawEditNode;
|
|
13
|
+
export declare function $isTldrawEditNode(node: LexicalNode | null | undefined): node is TldrawEditNode;
|
|
14
|
+
//# sourceMappingURL=TldrawEditNode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TldrawEditNode.d.ts","sourceRoot":"","sources":["../src/TldrawEditNode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAGhF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AAGzC,OAAO,EAAE,KAAK,oBAAoB,EAAC,UAAU,EAAE,MAAM,cAAc,CAAA;AAanE,qBAAa,cAAe,SAAQ,UAAU;IAC5C,MAAM,CAAC,cAAc,EAAE,mBAAmB,EAAE,CAa3C;IAED,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,cAAc,GAAG,cAAc;gBAItC,QAAQ,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,OAAO;IAI3C,MAAM,CAAC,UAAU,CAAC,cAAc,EAAE,oBAAoB,GAAG,cAAc;IAIvE,QAAQ,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,YAAY,GAAG,YAAY;CAsCrE;AAED,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc,CAEtE;AAED,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,WAAW,GAAG,IAAI,GAAG,SAAS,GACnC,IAAI,IAAI,cAAc,CAExB"}
|
package/dist/TldrawNode.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { SlashMenuItemConfig } from '@haklex/rich-editor';
|
|
2
1
|
import { EditorConfig, LexicalEditor, LexicalNode, NodeKey, SerializedLexicalNode, Spread, DecoratorNode } from 'lexical';
|
|
3
2
|
import { ReactElement } from 'react';
|
|
4
3
|
export type SerializedTldrawNode = Spread<{
|
|
@@ -6,7 +5,6 @@ export type SerializedTldrawNode = Spread<{
|
|
|
6
5
|
}, SerializedLexicalNode>;
|
|
7
6
|
export declare class TldrawNode extends DecoratorNode<ReactElement> {
|
|
8
7
|
__snapshot: string;
|
|
9
|
-
static slashMenuItems: SlashMenuItemConfig[];
|
|
10
8
|
static getType(): string;
|
|
11
9
|
static clone(node: TldrawNode): TldrawNode;
|
|
12
10
|
constructor(snapshot: string, key?: NodeKey);
|
|
@@ -17,7 +15,7 @@ export declare class TldrawNode extends DecoratorNode<ReactElement> {
|
|
|
17
15
|
exportJSON(): SerializedTldrawNode;
|
|
18
16
|
getSnapshot(): string;
|
|
19
17
|
setSnapshot(snapshot: string): void;
|
|
20
|
-
decorate(
|
|
18
|
+
decorate(_editor: LexicalEditor, _config: EditorConfig): ReactElement;
|
|
21
19
|
}
|
|
22
20
|
export declare function $createTldrawNode(snapshot: string): TldrawNode;
|
|
23
21
|
export declare function $isTldrawNode(node: LexicalNode | null | undefined): node is TldrawNode;
|
package/dist/TldrawNode.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TldrawNode.d.ts","sourceRoot":"","sources":["../src/TldrawNode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"TldrawNode.d.ts","sourceRoot":"","sources":["../src/TldrawNode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EACb,WAAW,EACX,OAAO,EACP,qBAAqB,EACrB,MAAM,EACP,MAAM,SAAS,CAAA;AAChB,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AACvC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AAKzC,MAAM,MAAM,oBAAoB,GAAG,MAAM,CACvC;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,EACpB,qBAAqB,CACtB,CAAA;AAED,qBAAa,UAAW,SAAQ,aAAa,CAAC,YAAY,CAAC;IACzD,UAAU,EAAE,MAAM,CAAA;IAElB,MAAM,CAAC,OAAO,IAAI,MAAM;IAIxB,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU;gBAI9B,QAAQ,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,OAAO;IAK3C,SAAS,CAAC,OAAO,EAAE,YAAY,GAAG,WAAW;IAM7C,SAAS,IAAI,OAAO;IAIpB,QAAQ,IAAI,OAAO;IAInB,MAAM,CAAC,UAAU,CAAC,cAAc,EAAE,oBAAoB,GAAG,UAAU;IAInE,UAAU,IAAI,oBAAoB;IASlC,WAAW,IAAI,MAAM;IAIrB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAKnC,QAAQ,CAAC,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,YAAY,GAAG,YAAY;CAKtE;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,CAE9D;AAED,wBAAgB,aAAa,CAC3B,IAAI,EAAE,WAAW,GAAG,IAAI,GAAG,SAAS,GACnC,IAAI,IAAI,UAAU,CAEpB"}
|
package/dist/TldrawRenderer.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export type { TldrawStaticRendererProps as TldrawRendererProps } from './
|
|
2
|
-
export {
|
|
1
|
+
export type { TldrawStaticRendererProps as TldrawRendererProps } from './TldrawDisplayRenderer';
|
|
2
|
+
export { TldrawDisplayRenderer as TldrawRenderer } from './TldrawDisplayRenderer';
|
|
3
3
|
//# sourceMappingURL=TldrawRenderer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TldrawRenderer.d.ts","sourceRoot":"","sources":["../src/TldrawRenderer.tsx"],"names":[],"mappings":"AAAA,YAAY,EAAE,yBAAyB,IAAI,mBAAmB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"TldrawRenderer.d.ts","sourceRoot":"","sources":["../src/TldrawRenderer.tsx"],"names":[],"mappings":"AAAA,YAAY,EAAE,yBAAyB,IAAI,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAC/F,OAAO,EAAE,qBAAqB,IAAI,cAAc,EAAE,MAAM,yBAAyB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TldrawSSRRenderer.d.ts","sourceRoot":"","sources":["../src/TldrawSSRRenderer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAA;AAE/B,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,eAAO,MAAM,iBAAiB,EAAE,EAAE,CAAC,sBAAsB,CAqCxD,CAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
export type { TldrawConfig } from './TldrawConfigContext';
|
|
2
2
|
export { TldrawConfigProvider, useTldrawConfig } from './TldrawConfigContext';
|
|
3
|
+
export type { TldrawStaticRendererProps as TldrawDisplayRendererProps } from './TldrawDisplayRenderer';
|
|
4
|
+
export { TldrawDisplayRenderer } from './TldrawDisplayRenderer';
|
|
5
|
+
export { $createTldrawEditNode, $isTldrawEditNode, TldrawEditNode, } from './TldrawEditNode';
|
|
3
6
|
export type { TldrawEditRendererProps } from './TldrawEditRenderer';
|
|
4
7
|
export { TldrawEditRenderer } from './TldrawEditRenderer';
|
|
5
8
|
export type { SerializedTldrawNode } from './TldrawNode';
|
|
6
9
|
export { $createTldrawNode, $isTldrawNode, TldrawNode } from './TldrawNode';
|
|
7
10
|
export { INSERT_TLDRAW_COMMAND, TldrawPlugin } from './TldrawPlugin';
|
|
8
|
-
export type {
|
|
9
|
-
export {
|
|
11
|
+
export type { TldrawSSRRendererProps } from './TldrawSSRRenderer';
|
|
12
|
+
export { TldrawSSRRenderer } from './TldrawSSRRenderer';
|
|
10
13
|
export { TLDRAW_BLOCK_TRANSFORMER } from './transformer';
|
|
11
|
-
export type { TldrawStaticRendererProps
|
|
12
|
-
export {
|
|
14
|
+
export type { TldrawStaticRendererProps } from './TldrawDisplayRenderer';
|
|
15
|
+
export type { TldrawStaticRendererProps as TldrawRendererProps } from './TldrawDisplayRenderer';
|
|
16
|
+
export { TldrawDisplayRenderer as TldrawStaticRenderer } from './TldrawDisplayRenderer';
|
|
17
|
+
export { TldrawDisplayRenderer as TldrawRenderer } from './TldrawDisplayRenderer';
|
|
13
18
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AACzD,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAC7E,YAAY,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAA;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AACzD,YAAY,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACxD,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAC3E,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AACpE,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AACzD,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAC7E,YAAY,EAAE,yBAAyB,IAAI,0BAA0B,EAAE,MAAM,yBAAyB,CAAA;AACtG,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AAC/D,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,cAAc,GACf,MAAM,kBAAkB,CAAA;AACzB,YAAY,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAA;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AACzD,YAAY,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACxD,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAC3E,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AACpE,YAAY,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAA;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAA;AAGxD,YAAY,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAA;AACxE,YAAY,EAAE,yBAAyB,IAAI,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAC/F,OAAO,EAAE,qBAAqB,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AACvF,OAAO,EAAE,qBAAqB,IAAI,cAAc,EAAE,MAAM,yBAAyB,CAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -2,11 +2,11 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
4
|
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
5
|
-
import { createContext, use, useMemo, useState, useEffect, useRef, useCallback,
|
|
5
|
+
import { createContext, use, useMemo, useState, useEffect, useRef, useCallback, Component, createElement, lazy, Suspense } from "react";
|
|
6
6
|
import { useColorScheme } from "@haklex/rich-editor";
|
|
7
7
|
import { presentDialog, SegmentedControl } from "@haklex/rich-editor-ui";
|
|
8
8
|
import { usePortalTheme } from "@haklex/rich-style-token";
|
|
9
|
-
import {
|
|
9
|
+
import { ZoomIn, ZoomOut, ScanSearch, Maximize2, X, PenTool, Pencil, Upload, Download, Clipboard } from "lucide-react";
|
|
10
10
|
import { DecoratorNode, $insertNodes, $getNodeByKey, createCommand, COMMAND_PRIORITY_EDITOR } from "lexical";
|
|
11
11
|
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
12
12
|
import { TLDRAW_BLOCK_TRANSFORMER } from "@haklex/rich-headless/transformers";
|
|
@@ -115,6 +115,356 @@ function useTldrawData(data) {
|
|
|
115
115
|
}
|
|
116
116
|
return { snapshot: void 0, loading: false, error: "" };
|
|
117
117
|
}
|
|
118
|
+
const TldrawDisplayRenderer = ({
|
|
119
|
+
snapshot
|
|
120
|
+
}) => {
|
|
121
|
+
const theme = useColorScheme();
|
|
122
|
+
const containerRef = useRef(null);
|
|
123
|
+
const [hasEnteredView, setHasEnteredView] = useState(false);
|
|
124
|
+
useEffect(() => {
|
|
125
|
+
if (hasEnteredView) return;
|
|
126
|
+
const target = containerRef.current;
|
|
127
|
+
if (!target) return;
|
|
128
|
+
const observer = new IntersectionObserver(
|
|
129
|
+
(entries) => {
|
|
130
|
+
if (entries.some((e) => e.isIntersecting)) {
|
|
131
|
+
setHasEnteredView(true);
|
|
132
|
+
observer.disconnect();
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
{ rootMargin: "200px 0px", threshold: 0.1 }
|
|
136
|
+
);
|
|
137
|
+
observer.observe(target);
|
|
138
|
+
return () => observer.disconnect();
|
|
139
|
+
}, [hasEnteredView]);
|
|
140
|
+
if (!hasEnteredView) {
|
|
141
|
+
return /* @__PURE__ */ jsx("div", { ref: containerRef, className: tldrawStaticContainer, children: /* @__PURE__ */ jsx("div", { className: tldrawLoading, children: "Loading tldraw..." }) });
|
|
142
|
+
}
|
|
143
|
+
return /* @__PURE__ */ jsx("div", { ref: containerRef, children: /* @__PURE__ */ jsx(TldrawStaticCanvas, { snapshot, theme }) });
|
|
144
|
+
};
|
|
145
|
+
const TldrawExpandContent = ({ dismiss, TldrawComponent, data, theme }) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
146
|
+
/* @__PURE__ */ jsxs("div", { className: tldrawDialogHeader, children: [
|
|
147
|
+
/* @__PURE__ */ jsx("span", { className: tldrawDialogTitle, children: "Whiteboard" }),
|
|
148
|
+
/* @__PURE__ */ jsx("span", { className: tldrawDialogMeta, children: "tldraw" }),
|
|
149
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: tldrawHeaderClose, onClick: dismiss, children: /* @__PURE__ */ jsx(X, { size: 18 }) })
|
|
150
|
+
] }),
|
|
151
|
+
/* @__PURE__ */ jsx("div", { className: tldrawDialogCanvas, children: /* @__PURE__ */ jsx(
|
|
152
|
+
TldrawComponent,
|
|
153
|
+
{
|
|
154
|
+
snapshot: data,
|
|
155
|
+
hideUi: true,
|
|
156
|
+
onMount: (editor) => {
|
|
157
|
+
editor.updateInstanceState({ isReadonly: true });
|
|
158
|
+
editor.setCurrentTool("hand");
|
|
159
|
+
editor.user.updateUserPreferences({ colorScheme: theme });
|
|
160
|
+
setTimeout(() => editor.zoomToFit({ animate: false }), 100);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
) })
|
|
164
|
+
] });
|
|
165
|
+
const TldrawStaticCanvas = ({ snapshot, theme }) => {
|
|
166
|
+
const {
|
|
167
|
+
snapshot: data,
|
|
168
|
+
loading: dataLoading,
|
|
169
|
+
error: dataError
|
|
170
|
+
} = useTldrawData(snapshot);
|
|
171
|
+
const [TldrawComponent, setTldrawComponent] = useState(null);
|
|
172
|
+
const [libLoading, setLibLoading] = useState(true);
|
|
173
|
+
const editorRef = useRef(null);
|
|
174
|
+
const { className: portalClassName } = usePortalTheme();
|
|
175
|
+
useEffect(() => {
|
|
176
|
+
import("tldraw").then((mod) => {
|
|
177
|
+
setTldrawComponent(() => mod.Tldraw);
|
|
178
|
+
setLibLoading(false);
|
|
179
|
+
}).catch(() => setLibLoading(false));
|
|
180
|
+
}, []);
|
|
181
|
+
useEffect(() => {
|
|
182
|
+
if (editorRef.current?.user?.updateUserPreferences) {
|
|
183
|
+
editorRef.current.user.updateUserPreferences({ colorScheme: theme });
|
|
184
|
+
}
|
|
185
|
+
}, [theme]);
|
|
186
|
+
const handleMount = useCallback(
|
|
187
|
+
(editor) => {
|
|
188
|
+
editorRef.current = editor;
|
|
189
|
+
editor.updateInstanceState({ isReadonly: true });
|
|
190
|
+
editor.setCurrentTool("hand");
|
|
191
|
+
editor.user.updateUserPreferences({ colorScheme: theme });
|
|
192
|
+
setTimeout(() => {
|
|
193
|
+
editor.zoomToFit({ animate: false });
|
|
194
|
+
}, 100);
|
|
195
|
+
},
|
|
196
|
+
[theme]
|
|
197
|
+
);
|
|
198
|
+
const handleExpand = useCallback(() => {
|
|
199
|
+
if (!TldrawComponent || !data) return;
|
|
200
|
+
presentDialog({
|
|
201
|
+
content: ({ dismiss }) => /* @__PURE__ */ jsx(
|
|
202
|
+
TldrawExpandContent,
|
|
203
|
+
{
|
|
204
|
+
dismiss,
|
|
205
|
+
TldrawComponent,
|
|
206
|
+
data,
|
|
207
|
+
theme
|
|
208
|
+
}
|
|
209
|
+
),
|
|
210
|
+
className: tldrawFullscreenPopup,
|
|
211
|
+
portalClassName,
|
|
212
|
+
showCloseButton: false,
|
|
213
|
+
clickOutsideToDismiss: true
|
|
214
|
+
});
|
|
215
|
+
}, [TldrawComponent, data, theme, portalClassName]);
|
|
216
|
+
const loading = dataLoading || libLoading;
|
|
217
|
+
if (loading) {
|
|
218
|
+
return /* @__PURE__ */ jsx("div", { className: tldrawStaticContainer, children: /* @__PURE__ */ jsx("div", { className: tldrawLoading, children: "Loading tldraw..." }) });
|
|
219
|
+
}
|
|
220
|
+
if (dataError || !data) {
|
|
221
|
+
return /* @__PURE__ */ jsx("div", { className: tldrawStaticContainer, children: /* @__PURE__ */ jsx("div", { className: tldrawError, children: dataError || "No data" }) });
|
|
222
|
+
}
|
|
223
|
+
if (!TldrawComponent) {
|
|
224
|
+
return /* @__PURE__ */ jsx("div", { className: tldrawStaticContainer, children: /* @__PURE__ */ jsx("div", { className: tldrawError, children: "Failed to load tldraw" }) });
|
|
225
|
+
}
|
|
226
|
+
return /* @__PURE__ */ jsxs(
|
|
227
|
+
"div",
|
|
228
|
+
{
|
|
229
|
+
className: tldrawStaticContainer,
|
|
230
|
+
"data-theme": theme,
|
|
231
|
+
"data-color-scheme": theme,
|
|
232
|
+
children: [
|
|
233
|
+
/* @__PURE__ */ jsx(
|
|
234
|
+
TldrawErrorBoundary,
|
|
235
|
+
{
|
|
236
|
+
fallback: /* @__PURE__ */ jsx("div", { className: tldrawError, children: "Failed to render tldraw" }),
|
|
237
|
+
children: /* @__PURE__ */ jsx(TldrawComponent, { snapshot: data, hideUi: true, onMount: handleMount })
|
|
238
|
+
}
|
|
239
|
+
),
|
|
240
|
+
/* @__PURE__ */ jsxs("div", { className: tldrawActionGroup, children: [
|
|
241
|
+
/* @__PURE__ */ jsx(
|
|
242
|
+
"button",
|
|
243
|
+
{
|
|
244
|
+
type: "button",
|
|
245
|
+
className: tldrawActionButton,
|
|
246
|
+
title: "Zoom In",
|
|
247
|
+
onClick: () => editorRef.current?.zoomIn(),
|
|
248
|
+
children: /* @__PURE__ */ jsx(ZoomIn, { size: 20 })
|
|
249
|
+
}
|
|
250
|
+
),
|
|
251
|
+
/* @__PURE__ */ jsx(
|
|
252
|
+
"button",
|
|
253
|
+
{
|
|
254
|
+
type: "button",
|
|
255
|
+
className: tldrawActionButton,
|
|
256
|
+
title: "Zoom Out",
|
|
257
|
+
onClick: () => editorRef.current?.zoomOut(),
|
|
258
|
+
children: /* @__PURE__ */ jsx(ZoomOut, { size: 20 })
|
|
259
|
+
}
|
|
260
|
+
),
|
|
261
|
+
/* @__PURE__ */ jsx(
|
|
262
|
+
"button",
|
|
263
|
+
{
|
|
264
|
+
type: "button",
|
|
265
|
+
className: tldrawActionButton,
|
|
266
|
+
title: "Fit to Content",
|
|
267
|
+
onClick: () => editorRef.current?.zoomToFit(),
|
|
268
|
+
children: /* @__PURE__ */ jsx(ScanSearch, { size: 20 })
|
|
269
|
+
}
|
|
270
|
+
),
|
|
271
|
+
/* @__PURE__ */ jsx(
|
|
272
|
+
"button",
|
|
273
|
+
{
|
|
274
|
+
type: "button",
|
|
275
|
+
className: tldrawActionButton,
|
|
276
|
+
title: "Expand",
|
|
277
|
+
onClick: handleExpand,
|
|
278
|
+
children: /* @__PURE__ */ jsx(Maximize2, { size: 20 })
|
|
279
|
+
}
|
|
280
|
+
)
|
|
281
|
+
] })
|
|
282
|
+
]
|
|
283
|
+
}
|
|
284
|
+
);
|
|
285
|
+
};
|
|
286
|
+
class TldrawErrorBoundary extends Component {
|
|
287
|
+
constructor() {
|
|
288
|
+
super(...arguments);
|
|
289
|
+
__publicField(this, "state", { hasError: false });
|
|
290
|
+
}
|
|
291
|
+
static getDerivedStateFromError() {
|
|
292
|
+
return { hasError: true };
|
|
293
|
+
}
|
|
294
|
+
render() {
|
|
295
|
+
return this.state.hasError ? this.props.fallback : this.props.children;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
const TldrawDisplayRenderer$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
299
|
+
__proto__: null,
|
|
300
|
+
TldrawDisplayRenderer
|
|
301
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
302
|
+
const TldrawSSRRenderer = ({ snapshot }) => {
|
|
303
|
+
let label = "Tldraw Whiteboard";
|
|
304
|
+
try {
|
|
305
|
+
const data = JSON.parse(snapshot);
|
|
306
|
+
if (data && typeof data === "object") {
|
|
307
|
+
const shapeCount = Object.keys(data).filter(
|
|
308
|
+
(k) => k.startsWith("shape:")
|
|
309
|
+
).length;
|
|
310
|
+
if (shapeCount > 0) {
|
|
311
|
+
label = `Tldraw Whiteboard (${shapeCount} shapes)`;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
} catch {
|
|
315
|
+
}
|
|
316
|
+
return /* @__PURE__ */ jsx(
|
|
317
|
+
"div",
|
|
318
|
+
{
|
|
319
|
+
className: "rich-tldraw-ssr-placeholder",
|
|
320
|
+
style: {
|
|
321
|
+
position: "relative",
|
|
322
|
+
width: "100%",
|
|
323
|
+
aspectRatio: "16 / 10",
|
|
324
|
+
display: "flex",
|
|
325
|
+
alignItems: "center",
|
|
326
|
+
justifyContent: "center",
|
|
327
|
+
backgroundColor: "var(--rich-tldraw-bg, #f5f5f5)",
|
|
328
|
+
borderRadius: "8px",
|
|
329
|
+
border: "1px solid var(--rich-tldraw-border, #e5e5e5)",
|
|
330
|
+
color: "var(--rich-tldraw-fg, #737373)",
|
|
331
|
+
fontSize: "14px"
|
|
332
|
+
},
|
|
333
|
+
"aria-label": label,
|
|
334
|
+
children: /* @__PURE__ */ jsx("span", { children: label })
|
|
335
|
+
}
|
|
336
|
+
);
|
|
337
|
+
};
|
|
338
|
+
class TldrawNode extends DecoratorNode {
|
|
339
|
+
constructor(snapshot, key) {
|
|
340
|
+
super(key);
|
|
341
|
+
__publicField(this, "__snapshot");
|
|
342
|
+
this.__snapshot = snapshot;
|
|
343
|
+
}
|
|
344
|
+
static getType() {
|
|
345
|
+
return "tldraw";
|
|
346
|
+
}
|
|
347
|
+
static clone(node) {
|
|
348
|
+
return new TldrawNode(node.__snapshot, node.__key);
|
|
349
|
+
}
|
|
350
|
+
createDOM(_config) {
|
|
351
|
+
const div = document.createElement("div");
|
|
352
|
+
div.className = "rich-tldraw-wrapper";
|
|
353
|
+
return div;
|
|
354
|
+
}
|
|
355
|
+
updateDOM() {
|
|
356
|
+
return false;
|
|
357
|
+
}
|
|
358
|
+
isInline() {
|
|
359
|
+
return false;
|
|
360
|
+
}
|
|
361
|
+
static importJSON(serializedNode) {
|
|
362
|
+
return $createTldrawNode(serializedNode.snapshot);
|
|
363
|
+
}
|
|
364
|
+
exportJSON() {
|
|
365
|
+
return {
|
|
366
|
+
...super.exportJSON(),
|
|
367
|
+
type: "tldraw",
|
|
368
|
+
snapshot: this.__snapshot,
|
|
369
|
+
version: 1
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
getSnapshot() {
|
|
373
|
+
return this.__snapshot;
|
|
374
|
+
}
|
|
375
|
+
setSnapshot(snapshot) {
|
|
376
|
+
const writable = this.getWritable();
|
|
377
|
+
writable.__snapshot = snapshot;
|
|
378
|
+
}
|
|
379
|
+
decorate(_editor, _config) {
|
|
380
|
+
return createElement(TldrawSSRRenderer, {
|
|
381
|
+
snapshot: this.__snapshot
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
function $createTldrawNode(snapshot) {
|
|
386
|
+
return new TldrawNode(snapshot);
|
|
387
|
+
}
|
|
388
|
+
function $isTldrawNode(node) {
|
|
389
|
+
return node instanceof TldrawNode;
|
|
390
|
+
}
|
|
391
|
+
const LazyDisplayRenderer = lazy(
|
|
392
|
+
() => Promise.resolve().then(() => TldrawDisplayRenderer$1).then((m) => ({
|
|
393
|
+
default: m.TldrawDisplayRenderer
|
|
394
|
+
}))
|
|
395
|
+
);
|
|
396
|
+
const LazyEditRenderer = lazy(
|
|
397
|
+
() => Promise.resolve().then(() => TldrawEditRenderer$1).then((m) => ({
|
|
398
|
+
default: m.TldrawEditRenderer
|
|
399
|
+
}))
|
|
400
|
+
);
|
|
401
|
+
const _TldrawEditNode = class _TldrawEditNode extends TldrawNode {
|
|
402
|
+
static clone(node) {
|
|
403
|
+
return new _TldrawEditNode(node.__snapshot, node.__key);
|
|
404
|
+
}
|
|
405
|
+
constructor(snapshot, key) {
|
|
406
|
+
super(snapshot, key);
|
|
407
|
+
}
|
|
408
|
+
static importJSON(serializedNode) {
|
|
409
|
+
return new _TldrawEditNode(serializedNode.snapshot);
|
|
410
|
+
}
|
|
411
|
+
decorate(editor, _config) {
|
|
412
|
+
const nodeKey = this.__key;
|
|
413
|
+
const isEditable = editor.isEditable();
|
|
414
|
+
const fallback = createElement("div", {
|
|
415
|
+
className: "rich-tldraw-loading",
|
|
416
|
+
style: {
|
|
417
|
+
position: "relative",
|
|
418
|
+
width: "100%",
|
|
419
|
+
aspectRatio: "16 / 10",
|
|
420
|
+
margin: "1rem 0"
|
|
421
|
+
}
|
|
422
|
+
});
|
|
423
|
+
if (isEditable) {
|
|
424
|
+
return createElement(
|
|
425
|
+
Suspense,
|
|
426
|
+
{ fallback },
|
|
427
|
+
createElement(LazyEditRenderer, {
|
|
428
|
+
snapshot: this.__snapshot,
|
|
429
|
+
onSnapshotChange: (newSnapshot) => {
|
|
430
|
+
editor.update(() => {
|
|
431
|
+
const node = $getNodeByKey(nodeKey);
|
|
432
|
+
if (node) {
|
|
433
|
+
node.setSnapshot(newSnapshot);
|
|
434
|
+
}
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
})
|
|
438
|
+
);
|
|
439
|
+
}
|
|
440
|
+
return createElement(
|
|
441
|
+
Suspense,
|
|
442
|
+
{ fallback },
|
|
443
|
+
createElement(LazyDisplayRenderer, { snapshot: this.__snapshot })
|
|
444
|
+
);
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
__publicField(_TldrawEditNode, "slashMenuItems", [
|
|
448
|
+
{
|
|
449
|
+
title: "Whiteboard",
|
|
450
|
+
icon: createElement(PenTool, { size: 20 }),
|
|
451
|
+
description: "Tldraw whiteboard canvas",
|
|
452
|
+
keywords: ["tldraw", "whiteboard", "draw", "canvas"],
|
|
453
|
+
section: "MEDIA",
|
|
454
|
+
onSelect: (editor) => {
|
|
455
|
+
editor.update(() => {
|
|
456
|
+
$insertNodes([$createTldrawEditNode("{}")]);
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
]);
|
|
461
|
+
let TldrawEditNode = _TldrawEditNode;
|
|
462
|
+
function $createTldrawEditNode(snapshot) {
|
|
463
|
+
return new TldrawEditNode(snapshot);
|
|
464
|
+
}
|
|
465
|
+
function $isTldrawEditNode(node) {
|
|
466
|
+
return node instanceof TldrawEditNode;
|
|
467
|
+
}
|
|
118
468
|
const SAVE_DEBOUNCE_MS = 2e3;
|
|
119
469
|
const TldrawEditorDialogContent = ({
|
|
120
470
|
dismiss,
|
|
@@ -402,301 +752,39 @@ const TldrawEditorDialogContent = ({
|
|
|
402
752
|
className: tldrawHeaderClose,
|
|
403
753
|
onClick: attemptClose,
|
|
404
754
|
children: /* @__PURE__ */ jsx(X, { size: 18 })
|
|
405
|
-
}
|
|
406
|
-
)
|
|
407
|
-
] }),
|
|
408
|
-
/* @__PURE__ */ jsx("div", { className: tldrawDialogCanvas, children: /* @__PURE__ */ jsx(TldrawComponent, { snapshot: initialData, onMount: handleMount }) })
|
|
409
|
-
] });
|
|
410
|
-
};
|
|
411
|
-
const TldrawEditRenderer = ({
|
|
412
|
-
snapshot,
|
|
413
|
-
onSnapshotChange
|
|
414
|
-
}) => {
|
|
415
|
-
const theme = useColorScheme();
|
|
416
|
-
const { saveSnapshot } = useTldrawConfig();
|
|
417
|
-
const {
|
|
418
|
-
snapshot: initialData,
|
|
419
|
-
loading: dataLoading,
|
|
420
|
-
error: dataError
|
|
421
|
-
} = useTldrawData(snapshot);
|
|
422
|
-
const [TldrawComponent, setTldrawComponent] = useState(null);
|
|
423
|
-
const [libLoading, setLibLoading] = useState(true);
|
|
424
|
-
const previewEditorRef = useRef(null);
|
|
425
|
-
const initialDataRef = useRef(void 0);
|
|
426
|
-
const onSnapshotChangeRef = useRef(onSnapshotChange);
|
|
427
|
-
onSnapshotChangeRef.current = onSnapshotChange;
|
|
428
|
-
const saveSnapshotRef = useRef(saveSnapshot);
|
|
429
|
-
saveSnapshotRef.current = saveSnapshot;
|
|
430
|
-
const snapshotRef = useRef(snapshot);
|
|
431
|
-
snapshotRef.current = snapshot;
|
|
432
|
-
const { className: portalClassName } = usePortalTheme();
|
|
433
|
-
useEffect(() => {
|
|
434
|
-
if (initialData && !initialDataRef.current) {
|
|
435
|
-
initialDataRef.current = initialData;
|
|
436
|
-
}
|
|
437
|
-
}, [initialData]);
|
|
438
|
-
useEffect(() => {
|
|
439
|
-
import("tldraw").then((mod) => {
|
|
440
|
-
setTldrawComponent(() => mod.Tldraw);
|
|
441
|
-
setLibLoading(false);
|
|
442
|
-
}).catch(() => setLibLoading(false));
|
|
443
|
-
}, []);
|
|
444
|
-
useEffect(() => {
|
|
445
|
-
if (previewEditorRef.current?.user?.updateUserPreferences) {
|
|
446
|
-
previewEditorRef.current.user.updateUserPreferences({
|
|
447
|
-
colorScheme: theme
|
|
448
|
-
});
|
|
449
|
-
}
|
|
450
|
-
}, [theme]);
|
|
451
|
-
const handlePreviewMount = useCallback(
|
|
452
|
-
(editor) => {
|
|
453
|
-
previewEditorRef.current = editor;
|
|
454
|
-
editor.updateInstanceState({ isReadonly: true });
|
|
455
|
-
editor.setCurrentTool("hand");
|
|
456
|
-
editor.user.updateUserPreferences({ colorScheme: theme });
|
|
457
|
-
setTimeout(() => editor.zoomToFit({ animate: false }), 100);
|
|
458
|
-
},
|
|
459
|
-
[theme]
|
|
460
|
-
);
|
|
461
|
-
const handleOpenEditor = useCallback(() => {
|
|
462
|
-
if (!TldrawComponent) return;
|
|
463
|
-
presentDialog({
|
|
464
|
-
content: ({ dismiss }) => /* @__PURE__ */ jsx(
|
|
465
|
-
TldrawEditorDialogContent,
|
|
466
|
-
{
|
|
467
|
-
dismiss,
|
|
468
|
-
TldrawComponent,
|
|
469
|
-
initialData: initialDataRef.current,
|
|
470
|
-
initialSnapshot: snapshotRef.current,
|
|
471
|
-
theme,
|
|
472
|
-
onSave: (ref) => onSnapshotChangeRef.current(ref),
|
|
473
|
-
saveSnapshot: saveSnapshotRef.current,
|
|
474
|
-
onClose: (doc) => {
|
|
475
|
-
if (doc) initialDataRef.current = doc;
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
),
|
|
479
|
-
className: tldrawFullscreenPopup,
|
|
480
|
-
portalClassName,
|
|
481
|
-
showCloseButton: false,
|
|
482
|
-
clickOutsideToDismiss: false
|
|
483
|
-
});
|
|
484
|
-
}, [TldrawComponent, theme, portalClassName]);
|
|
485
|
-
const loading = dataLoading || libLoading;
|
|
486
|
-
if (loading || !TldrawComponent) {
|
|
487
|
-
return /* @__PURE__ */ jsx("div", { className: tldrawEditorContainer, children: /* @__PURE__ */ jsx("div", { className: tldrawLoading, children: "Loading tldraw editor..." }) });
|
|
488
|
-
}
|
|
489
|
-
if (dataError) {
|
|
490
|
-
return /* @__PURE__ */ jsx("div", { className: tldrawEditorContainer, children: /* @__PURE__ */ jsx("div", { className: tldrawError, children: dataError }) });
|
|
491
|
-
}
|
|
492
|
-
return /* @__PURE__ */ jsxs("div", { className: tldrawEditorContainer, children: [
|
|
493
|
-
/* @__PURE__ */ jsx(
|
|
494
|
-
TldrawComponent,
|
|
495
|
-
{
|
|
496
|
-
snapshot: initialDataRef.current,
|
|
497
|
-
hideUi: true,
|
|
498
|
-
onMount: handlePreviewMount
|
|
499
|
-
}
|
|
500
|
-
),
|
|
501
|
-
/* @__PURE__ */ jsx(
|
|
502
|
-
"button",
|
|
503
|
-
{
|
|
504
|
-
type: "button",
|
|
505
|
-
className: tldrawEditOverlay,
|
|
506
|
-
onClick: handleOpenEditor,
|
|
507
|
-
children: /* @__PURE__ */ jsxs("span", { className: tldrawEditLabel, children: [
|
|
508
|
-
/* @__PURE__ */ jsx(Pencil, { size: 16 }),
|
|
509
|
-
"Edit Whiteboard"
|
|
510
|
-
] })
|
|
511
|
-
}
|
|
512
|
-
)
|
|
513
|
-
] });
|
|
514
|
-
};
|
|
515
|
-
const TldrawEditRenderer$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
516
|
-
__proto__: null,
|
|
517
|
-
TldrawEditRenderer
|
|
518
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
519
|
-
const LazyStaticRenderer = lazy(
|
|
520
|
-
() => Promise.resolve().then(() => TldrawStaticRenderer$1).then((m) => ({
|
|
521
|
-
default: m.TldrawStaticRenderer
|
|
522
|
-
}))
|
|
523
|
-
);
|
|
524
|
-
const LazyEditRenderer = lazy(
|
|
525
|
-
() => Promise.resolve().then(() => TldrawEditRenderer$1).then((m) => ({
|
|
526
|
-
default: m.TldrawEditRenderer
|
|
527
|
-
}))
|
|
528
|
-
);
|
|
529
|
-
const _TldrawNode = class _TldrawNode extends DecoratorNode {
|
|
530
|
-
constructor(snapshot, key) {
|
|
531
|
-
super(key);
|
|
532
|
-
__publicField(this, "__snapshot");
|
|
533
|
-
this.__snapshot = snapshot;
|
|
534
|
-
}
|
|
535
|
-
static getType() {
|
|
536
|
-
return "tldraw";
|
|
537
|
-
}
|
|
538
|
-
static clone(node) {
|
|
539
|
-
return new _TldrawNode(node.__snapshot, node.__key);
|
|
540
|
-
}
|
|
541
|
-
createDOM(_config) {
|
|
542
|
-
const div = document.createElement("div");
|
|
543
|
-
div.className = "rich-tldraw-wrapper";
|
|
544
|
-
return div;
|
|
545
|
-
}
|
|
546
|
-
updateDOM() {
|
|
547
|
-
return false;
|
|
548
|
-
}
|
|
549
|
-
isInline() {
|
|
550
|
-
return false;
|
|
551
|
-
}
|
|
552
|
-
static importJSON(serializedNode) {
|
|
553
|
-
return $createTldrawNode(serializedNode.snapshot);
|
|
554
|
-
}
|
|
555
|
-
exportJSON() {
|
|
556
|
-
return {
|
|
557
|
-
...super.exportJSON(),
|
|
558
|
-
type: "tldraw",
|
|
559
|
-
snapshot: this.__snapshot,
|
|
560
|
-
version: 1
|
|
561
|
-
};
|
|
562
|
-
}
|
|
563
|
-
getSnapshot() {
|
|
564
|
-
return this.__snapshot;
|
|
565
|
-
}
|
|
566
|
-
setSnapshot(snapshot) {
|
|
567
|
-
const writable = this.getWritable();
|
|
568
|
-
writable.__snapshot = snapshot;
|
|
569
|
-
}
|
|
570
|
-
decorate(editor, _config) {
|
|
571
|
-
const nodeKey = this.__key;
|
|
572
|
-
const isEditable = editor.isEditable();
|
|
573
|
-
const fallback = createElement("div", {
|
|
574
|
-
className: "rich-tldraw-loading",
|
|
575
|
-
style: {
|
|
576
|
-
position: "relative",
|
|
577
|
-
width: "100%",
|
|
578
|
-
aspectRatio: "16 / 10",
|
|
579
|
-
margin: "1rem 0"
|
|
580
|
-
}
|
|
581
|
-
});
|
|
582
|
-
if (isEditable) {
|
|
583
|
-
return createElement(
|
|
584
|
-
Suspense,
|
|
585
|
-
{ fallback },
|
|
586
|
-
createElement(LazyEditRenderer, {
|
|
587
|
-
snapshot: this.__snapshot,
|
|
588
|
-
onSnapshotChange: (newSnapshot) => {
|
|
589
|
-
editor.update(() => {
|
|
590
|
-
const node = $getNodeByKey(nodeKey);
|
|
591
|
-
if (node) {
|
|
592
|
-
node.setSnapshot(newSnapshot);
|
|
593
|
-
}
|
|
594
|
-
});
|
|
595
|
-
}
|
|
596
|
-
})
|
|
597
|
-
);
|
|
598
|
-
}
|
|
599
|
-
return createElement(
|
|
600
|
-
Suspense,
|
|
601
|
-
{ fallback },
|
|
602
|
-
createElement(LazyStaticRenderer, { snapshot: this.__snapshot })
|
|
603
|
-
);
|
|
604
|
-
}
|
|
755
|
+
}
|
|
756
|
+
)
|
|
757
|
+
] }),
|
|
758
|
+
/* @__PURE__ */ jsx("div", { className: tldrawDialogCanvas, children: /* @__PURE__ */ jsx(TldrawComponent, { snapshot: initialData, onMount: handleMount }) })
|
|
759
|
+
] });
|
|
605
760
|
};
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
icon: createElement(PenTool, { size: 20 }),
|
|
610
|
-
description: "Tldraw whiteboard canvas",
|
|
611
|
-
keywords: ["tldraw", "whiteboard", "draw", "canvas"],
|
|
612
|
-
section: "MEDIA",
|
|
613
|
-
onSelect: (editor) => {
|
|
614
|
-
editor.update(() => {
|
|
615
|
-
$insertNodes([$createTldrawNode("{}")]);
|
|
616
|
-
});
|
|
617
|
-
}
|
|
618
|
-
}
|
|
619
|
-
]);
|
|
620
|
-
let TldrawNode = _TldrawNode;
|
|
621
|
-
function $createTldrawNode(snapshot) {
|
|
622
|
-
return new TldrawNode(snapshot);
|
|
623
|
-
}
|
|
624
|
-
function $isTldrawNode(node) {
|
|
625
|
-
return node instanceof TldrawNode;
|
|
626
|
-
}
|
|
627
|
-
const INSERT_TLDRAW_COMMAND = createCommand("INSERT_TLDRAW");
|
|
628
|
-
function TldrawPlugin() {
|
|
629
|
-
const [editor] = useLexicalComposerContext();
|
|
630
|
-
useEffect(() => {
|
|
631
|
-
return editor.registerCommand(
|
|
632
|
-
INSERT_TLDRAW_COMMAND,
|
|
633
|
-
(snapshot) => {
|
|
634
|
-
const node = $createTldrawNode(snapshot);
|
|
635
|
-
$insertNodes([node]);
|
|
636
|
-
return true;
|
|
637
|
-
},
|
|
638
|
-
COMMAND_PRIORITY_EDITOR
|
|
639
|
-
);
|
|
640
|
-
}, [editor]);
|
|
641
|
-
return null;
|
|
642
|
-
}
|
|
643
|
-
const TldrawStaticRenderer = ({
|
|
644
|
-
snapshot
|
|
761
|
+
const TldrawEditRenderer = ({
|
|
762
|
+
snapshot,
|
|
763
|
+
onSnapshotChange
|
|
645
764
|
}) => {
|
|
646
765
|
const theme = useColorScheme();
|
|
647
|
-
const
|
|
648
|
-
const [hasEnteredView, setHasEnteredView] = useState(false);
|
|
649
|
-
useEffect(() => {
|
|
650
|
-
if (hasEnteredView) return;
|
|
651
|
-
const target = containerRef.current;
|
|
652
|
-
if (!target) return;
|
|
653
|
-
const observer = new IntersectionObserver(
|
|
654
|
-
(entries) => {
|
|
655
|
-
if (entries.some((e) => e.isIntersecting)) {
|
|
656
|
-
setHasEnteredView(true);
|
|
657
|
-
observer.disconnect();
|
|
658
|
-
}
|
|
659
|
-
},
|
|
660
|
-
{ rootMargin: "200px 0px", threshold: 0.1 }
|
|
661
|
-
);
|
|
662
|
-
observer.observe(target);
|
|
663
|
-
return () => observer.disconnect();
|
|
664
|
-
}, [hasEnteredView]);
|
|
665
|
-
if (!hasEnteredView) {
|
|
666
|
-
return /* @__PURE__ */ jsx("div", { ref: containerRef, className: tldrawStaticContainer, children: /* @__PURE__ */ jsx("div", { className: tldrawLoading, children: "Loading tldraw..." }) });
|
|
667
|
-
}
|
|
668
|
-
return /* @__PURE__ */ jsx("div", { ref: containerRef, children: /* @__PURE__ */ jsx(TldrawStaticCanvas, { snapshot, theme }) });
|
|
669
|
-
};
|
|
670
|
-
const TldrawExpandContent = ({ dismiss, TldrawComponent, data, theme }) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
671
|
-
/* @__PURE__ */ jsxs("div", { className: tldrawDialogHeader, children: [
|
|
672
|
-
/* @__PURE__ */ jsx("span", { className: tldrawDialogTitle, children: "Whiteboard" }),
|
|
673
|
-
/* @__PURE__ */ jsx("span", { className: tldrawDialogMeta, children: "tldraw" }),
|
|
674
|
-
/* @__PURE__ */ jsx("button", { type: "button", className: tldrawHeaderClose, onClick: dismiss, children: /* @__PURE__ */ jsx(X, { size: 18 }) })
|
|
675
|
-
] }),
|
|
676
|
-
/* @__PURE__ */ jsx("div", { className: tldrawDialogCanvas, children: /* @__PURE__ */ jsx(
|
|
677
|
-
TldrawComponent,
|
|
678
|
-
{
|
|
679
|
-
snapshot: data,
|
|
680
|
-
hideUi: true,
|
|
681
|
-
onMount: (editor) => {
|
|
682
|
-
editor.updateInstanceState({ isReadonly: true });
|
|
683
|
-
editor.setCurrentTool("hand");
|
|
684
|
-
editor.user.updateUserPreferences({ colorScheme: theme });
|
|
685
|
-
setTimeout(() => editor.zoomToFit({ animate: false }), 100);
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
) })
|
|
689
|
-
] });
|
|
690
|
-
const TldrawStaticCanvas = ({ snapshot, theme }) => {
|
|
766
|
+
const { saveSnapshot } = useTldrawConfig();
|
|
691
767
|
const {
|
|
692
|
-
snapshot:
|
|
768
|
+
snapshot: initialData,
|
|
693
769
|
loading: dataLoading,
|
|
694
770
|
error: dataError
|
|
695
771
|
} = useTldrawData(snapshot);
|
|
696
772
|
const [TldrawComponent, setTldrawComponent] = useState(null);
|
|
697
773
|
const [libLoading, setLibLoading] = useState(true);
|
|
698
|
-
const
|
|
774
|
+
const previewEditorRef = useRef(null);
|
|
775
|
+
const initialDataRef = useRef(void 0);
|
|
776
|
+
const onSnapshotChangeRef = useRef(onSnapshotChange);
|
|
777
|
+
onSnapshotChangeRef.current = onSnapshotChange;
|
|
778
|
+
const saveSnapshotRef = useRef(saveSnapshot);
|
|
779
|
+
saveSnapshotRef.current = saveSnapshot;
|
|
780
|
+
const snapshotRef = useRef(snapshot);
|
|
781
|
+
snapshotRef.current = snapshot;
|
|
699
782
|
const { className: portalClassName } = usePortalTheme();
|
|
783
|
+
useEffect(() => {
|
|
784
|
+
if (initialData && !initialDataRef.current) {
|
|
785
|
+
initialDataRef.current = initialData;
|
|
786
|
+
}
|
|
787
|
+
}, [initialData]);
|
|
700
788
|
useEffect(() => {
|
|
701
789
|
import("tldraw").then((mod) => {
|
|
702
790
|
setTldrawComponent(() => mod.Tldraw);
|
|
@@ -704,136 +792,111 @@ const TldrawStaticCanvas = ({ snapshot, theme }) => {
|
|
|
704
792
|
}).catch(() => setLibLoading(false));
|
|
705
793
|
}, []);
|
|
706
794
|
useEffect(() => {
|
|
707
|
-
if (
|
|
708
|
-
|
|
795
|
+
if (previewEditorRef.current?.user?.updateUserPreferences) {
|
|
796
|
+
previewEditorRef.current.user.updateUserPreferences({
|
|
797
|
+
colorScheme: theme
|
|
798
|
+
});
|
|
709
799
|
}
|
|
710
800
|
}, [theme]);
|
|
711
|
-
const
|
|
801
|
+
const handlePreviewMount = useCallback(
|
|
712
802
|
(editor) => {
|
|
713
|
-
|
|
803
|
+
previewEditorRef.current = editor;
|
|
714
804
|
editor.updateInstanceState({ isReadonly: true });
|
|
715
805
|
editor.setCurrentTool("hand");
|
|
716
806
|
editor.user.updateUserPreferences({ colorScheme: theme });
|
|
717
|
-
setTimeout(() => {
|
|
718
|
-
editor.zoomToFit({ animate: false });
|
|
719
|
-
}, 100);
|
|
807
|
+
setTimeout(() => editor.zoomToFit({ animate: false }), 100);
|
|
720
808
|
},
|
|
721
809
|
[theme]
|
|
722
810
|
);
|
|
723
|
-
const
|
|
724
|
-
if (!TldrawComponent
|
|
811
|
+
const handleOpenEditor = useCallback(() => {
|
|
812
|
+
if (!TldrawComponent) return;
|
|
725
813
|
presentDialog({
|
|
726
814
|
content: ({ dismiss }) => /* @__PURE__ */ jsx(
|
|
727
|
-
|
|
815
|
+
TldrawEditorDialogContent,
|
|
728
816
|
{
|
|
729
817
|
dismiss,
|
|
730
818
|
TldrawComponent,
|
|
731
|
-
|
|
732
|
-
|
|
819
|
+
initialData: initialDataRef.current,
|
|
820
|
+
initialSnapshot: snapshotRef.current,
|
|
821
|
+
theme,
|
|
822
|
+
onSave: (ref) => onSnapshotChangeRef.current(ref),
|
|
823
|
+
saveSnapshot: saveSnapshotRef.current,
|
|
824
|
+
onClose: (doc) => {
|
|
825
|
+
if (doc) initialDataRef.current = doc;
|
|
826
|
+
}
|
|
733
827
|
}
|
|
734
828
|
),
|
|
735
829
|
className: tldrawFullscreenPopup,
|
|
736
830
|
portalClassName,
|
|
737
831
|
showCloseButton: false,
|
|
738
|
-
clickOutsideToDismiss:
|
|
832
|
+
clickOutsideToDismiss: false
|
|
739
833
|
});
|
|
740
|
-
}, [TldrawComponent,
|
|
834
|
+
}, [TldrawComponent, theme, portalClassName]);
|
|
741
835
|
const loading = dataLoading || libLoading;
|
|
742
|
-
if (loading) {
|
|
743
|
-
return /* @__PURE__ */ jsx("div", { className:
|
|
744
|
-
}
|
|
745
|
-
if (dataError || !data) {
|
|
746
|
-
return /* @__PURE__ */ jsx("div", { className: tldrawStaticContainer, children: /* @__PURE__ */ jsx("div", { className: tldrawError, children: dataError || "No data" }) });
|
|
836
|
+
if (loading || !TldrawComponent) {
|
|
837
|
+
return /* @__PURE__ */ jsx("div", { className: tldrawEditorContainer, children: /* @__PURE__ */ jsx("div", { className: tldrawLoading, children: "Loading tldraw editor..." }) });
|
|
747
838
|
}
|
|
748
|
-
if (
|
|
749
|
-
return /* @__PURE__ */ jsx("div", { className:
|
|
839
|
+
if (dataError) {
|
|
840
|
+
return /* @__PURE__ */ jsx("div", { className: tldrawEditorContainer, children: /* @__PURE__ */ jsx("div", { className: tldrawError, children: dataError }) });
|
|
750
841
|
}
|
|
751
|
-
return /* @__PURE__ */ jsxs(
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
type: "button",
|
|
770
|
-
className: tldrawActionButton,
|
|
771
|
-
title: "Zoom In",
|
|
772
|
-
onClick: () => editorRef.current?.zoomIn(),
|
|
773
|
-
children: /* @__PURE__ */ jsx(ZoomIn, { size: 20 })
|
|
774
|
-
}
|
|
775
|
-
),
|
|
776
|
-
/* @__PURE__ */ jsx(
|
|
777
|
-
"button",
|
|
778
|
-
{
|
|
779
|
-
type: "button",
|
|
780
|
-
className: tldrawActionButton,
|
|
781
|
-
title: "Zoom Out",
|
|
782
|
-
onClick: () => editorRef.current?.zoomOut(),
|
|
783
|
-
children: /* @__PURE__ */ jsx(ZoomOut, { size: 20 })
|
|
784
|
-
}
|
|
785
|
-
),
|
|
786
|
-
/* @__PURE__ */ jsx(
|
|
787
|
-
"button",
|
|
788
|
-
{
|
|
789
|
-
type: "button",
|
|
790
|
-
className: tldrawActionButton,
|
|
791
|
-
title: "Fit to Content",
|
|
792
|
-
onClick: () => editorRef.current?.zoomToFit(),
|
|
793
|
-
children: /* @__PURE__ */ jsx(ScanSearch, { size: 20 })
|
|
794
|
-
}
|
|
795
|
-
),
|
|
796
|
-
/* @__PURE__ */ jsx(
|
|
797
|
-
"button",
|
|
798
|
-
{
|
|
799
|
-
type: "button",
|
|
800
|
-
className: tldrawActionButton,
|
|
801
|
-
title: "Expand",
|
|
802
|
-
onClick: handleExpand,
|
|
803
|
-
children: /* @__PURE__ */ jsx(Maximize2, { size: 20 })
|
|
804
|
-
}
|
|
805
|
-
)
|
|
842
|
+
return /* @__PURE__ */ jsxs("div", { className: tldrawEditorContainer, children: [
|
|
843
|
+
/* @__PURE__ */ jsx(
|
|
844
|
+
TldrawComponent,
|
|
845
|
+
{
|
|
846
|
+
snapshot: initialDataRef.current,
|
|
847
|
+
hideUi: true,
|
|
848
|
+
onMount: handlePreviewMount
|
|
849
|
+
}
|
|
850
|
+
),
|
|
851
|
+
/* @__PURE__ */ jsx(
|
|
852
|
+
"button",
|
|
853
|
+
{
|
|
854
|
+
type: "button",
|
|
855
|
+
className: tldrawEditOverlay,
|
|
856
|
+
onClick: handleOpenEditor,
|
|
857
|
+
children: /* @__PURE__ */ jsxs("span", { className: tldrawEditLabel, children: [
|
|
858
|
+
/* @__PURE__ */ jsx(Pencil, { size: 16 }),
|
|
859
|
+
"Edit Whiteboard"
|
|
806
860
|
] })
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
);
|
|
861
|
+
}
|
|
862
|
+
)
|
|
863
|
+
] });
|
|
810
864
|
};
|
|
811
|
-
|
|
812
|
-
constructor() {
|
|
813
|
-
super(...arguments);
|
|
814
|
-
__publicField(this, "state", { hasError: false });
|
|
815
|
-
}
|
|
816
|
-
static getDerivedStateFromError() {
|
|
817
|
-
return { hasError: true };
|
|
818
|
-
}
|
|
819
|
-
render() {
|
|
820
|
-
return this.state.hasError ? this.props.fallback : this.props.children;
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
const TldrawStaticRenderer$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
865
|
+
const TldrawEditRenderer$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
824
866
|
__proto__: null,
|
|
825
|
-
|
|
867
|
+
TldrawEditRenderer
|
|
826
868
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
869
|
+
const INSERT_TLDRAW_COMMAND = createCommand("INSERT_TLDRAW");
|
|
870
|
+
function TldrawPlugin() {
|
|
871
|
+
const [editor] = useLexicalComposerContext();
|
|
872
|
+
useEffect(() => {
|
|
873
|
+
return editor.registerCommand(
|
|
874
|
+
INSERT_TLDRAW_COMMAND,
|
|
875
|
+
(snapshot) => {
|
|
876
|
+
const node = $createTldrawEditNode(snapshot);
|
|
877
|
+
$insertNodes([node]);
|
|
878
|
+
return true;
|
|
879
|
+
},
|
|
880
|
+
COMMAND_PRIORITY_EDITOR
|
|
881
|
+
);
|
|
882
|
+
}, [editor]);
|
|
883
|
+
return null;
|
|
884
|
+
}
|
|
827
885
|
export {
|
|
886
|
+
$createTldrawEditNode,
|
|
828
887
|
$createTldrawNode,
|
|
888
|
+
$isTldrawEditNode,
|
|
829
889
|
$isTldrawNode,
|
|
830
890
|
INSERT_TLDRAW_COMMAND,
|
|
831
891
|
TLDRAW_BLOCK_TRANSFORMER,
|
|
832
892
|
TldrawConfigProvider,
|
|
893
|
+
TldrawDisplayRenderer,
|
|
894
|
+
TldrawEditNode,
|
|
833
895
|
TldrawEditRenderer,
|
|
834
896
|
TldrawNode,
|
|
835
897
|
TldrawPlugin,
|
|
836
|
-
|
|
837
|
-
|
|
898
|
+
TldrawDisplayRenderer as TldrawRenderer,
|
|
899
|
+
TldrawSSRRenderer,
|
|
900
|
+
TldrawDisplayRenderer as TldrawStaticRenderer,
|
|
838
901
|
useTldrawConfig
|
|
839
902
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@haklex/rich-ext-tldraw",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.32",
|
|
4
4
|
"description": "Tldraw whiteboard extension",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"tldraw": "^3.15.6",
|
|
20
|
-
"@haklex/rich-editor": "0.0.
|
|
21
|
-
"@haklex/rich-editor-ui": "0.0.
|
|
22
|
-
"@haklex/rich-
|
|
23
|
-
"@haklex/rich-
|
|
20
|
+
"@haklex/rich-editor": "0.0.32",
|
|
21
|
+
"@haklex/rich-editor-ui": "0.0.32",
|
|
22
|
+
"@haklex/rich-style-token": "0.0.32",
|
|
23
|
+
"@haklex/rich-headless": "0.0.32"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@lexical/react": "^0.40.0",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TldrawStaticRenderer.d.ts","sourceRoot":"","sources":["../src/TldrawStaticRenderer.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAa,KAAK,EAAE,EAAkB,MAAM,OAAO,CAAA;AAM1D,MAAM,WAAW,yBAAyB;IACxC,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,eAAO,MAAM,oBAAoB,EAAE,EAAE,CAAC,yBAAyB,CAsC9D,CAAA"}
|