@haklex/rich-ext-code-snippet 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.
- package/dist/CodeSnippetNode-BmRM_Ma7.js +400 -0
- package/dist/index.mjs +454 -394
- package/dist/rich-ext-code-snippet.css +1 -2
- package/dist/static.mjs +12 -5
- package/package.json +7 -7
- package/dist/transformer-CCg3Ky-e.js +0 -443
package/dist/index.mjs
CHANGED
|
@@ -1,416 +1,476 @@
|
|
|
1
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
import { g as getLanguageFromFilename, m as modal, s as semanticClassNames, a as modalTitlebar, b as modalTitle, c as modalIconButton, d as modalBody, e as modalSidebar, f as sidebarHeader, h as sidebarAddButton, i as fileList, j as dragOverlay, k as fileIcon, l as fileName, n as fileItem, o as modalEditor, p as breadcrumb, q as breadcrumbLeft, r as breadcrumbName, t as breadcrumbLang, u as editorContainer, v as fileDragHandle, w as renameInput, x as fileDelete, y as codeSnippetDialogPopup, z as editContainer, C as CodeSnippetRenderer, A as editOverlay, B as editLabel, $ as $isCodeSnippetNode, D as CodeSnippetNode } from "./CodeSnippetNode-BmRM_Ma7.js";
|
|
5
|
+
import { E } from "./CodeSnippetNode-BmRM_Ma7.js";
|
|
6
|
+
import { jsxs, jsx, Fragment } from "react/jsx-runtime";
|
|
2
7
|
import { useColorScheme } from "@haklex/rich-editor";
|
|
3
8
|
import { presentDialog } from "@haklex/rich-editor-ui";
|
|
4
9
|
import { usePortalTheme } from "@haklex/rich-style-token";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
10
|
+
import { X, Plus, GripVertical, Trash2, Pencil, FileCode } from "lucide-react";
|
|
11
|
+
import { useState, useRef, useEffect, useCallback, useMemo, useContext, createContext, createElement } from "react";
|
|
12
|
+
import { history, defaultKeymap, historyKeymap, indentWithTab } from "@codemirror/commands";
|
|
8
13
|
import { Compartment, EditorState } from "@codemirror/state";
|
|
9
14
|
import { EditorView, keymap, lineNumbers } from "@codemirror/view";
|
|
10
|
-
import {
|
|
11
|
-
import { SortableContext,
|
|
15
|
+
import { useSensors, useSensor, PointerSensor, DndContext, closestCenter, DragOverlay } from "@dnd-kit/core";
|
|
16
|
+
import { arrayMove, SortableContext, verticalListSortingStrategy, useSortable } from "@dnd-kit/sortable";
|
|
12
17
|
import { CSS } from "@dnd-kit/utilities";
|
|
13
18
|
import { getThemeExtensions, loadLanguageExtension } from "@haklex/cm-editor";
|
|
14
19
|
import { normalizeLanguage } from "@haklex/rich-renderer-codeblock/constants";
|
|
15
20
|
import { FileIcon } from "@haklex/rich-renderer-codeblock/icons";
|
|
16
21
|
import { createPortal } from "react-dom";
|
|
17
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
18
22
|
import { $getNodeByKey, $insertNodes } from "lexical";
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
23
|
+
import { CODE_SNIPPET_BLOCK_TRANSFORMER } from "@haklex/rich-headless/transformers";
|
|
24
|
+
const SortableFileItem = ({
|
|
25
|
+
file,
|
|
26
|
+
isActive,
|
|
27
|
+
isEditing,
|
|
28
|
+
editValue,
|
|
29
|
+
canDelete,
|
|
30
|
+
onSelect,
|
|
31
|
+
onStartRename,
|
|
32
|
+
onEditChange,
|
|
33
|
+
onCommitRename,
|
|
34
|
+
onCancelRename,
|
|
35
|
+
onDelete
|
|
36
|
+
}) => {
|
|
37
|
+
const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({
|
|
38
|
+
id: file.filename
|
|
39
|
+
});
|
|
40
|
+
const style = {
|
|
41
|
+
transform: CSS.Transform.toString(transform),
|
|
42
|
+
transition
|
|
43
|
+
};
|
|
44
|
+
return /* @__PURE__ */ jsxs(
|
|
45
|
+
"div",
|
|
46
|
+
{
|
|
47
|
+
className: `${fileItem({ active: isActive, dragging: isDragging })} ${semanticClassNames.fileItem} ${isActive ? semanticClassNames.fileItemActive : ""} ${isDragging ? semanticClassNames.fileItemDragging : ""}`.trim(),
|
|
48
|
+
ref: setNodeRef,
|
|
49
|
+
style,
|
|
50
|
+
onClick: onSelect,
|
|
51
|
+
onDoubleClick: onStartRename,
|
|
52
|
+
children: [
|
|
53
|
+
/* @__PURE__ */ jsx(
|
|
54
|
+
"span",
|
|
55
|
+
{
|
|
56
|
+
className: `${fileDragHandle} ${semanticClassNames.fileDragHandle}`,
|
|
57
|
+
...attributes,
|
|
58
|
+
...listeners,
|
|
59
|
+
onClick: (e) => e.stopPropagation(),
|
|
60
|
+
children: /* @__PURE__ */ jsx(GripVertical, { size: 12 })
|
|
61
|
+
}
|
|
62
|
+
),
|
|
63
|
+
/* @__PURE__ */ jsx(
|
|
64
|
+
FileIcon,
|
|
65
|
+
{
|
|
66
|
+
className: `${fileIcon} ${semanticClassNames.fileIcon}`,
|
|
67
|
+
filename: file.filename,
|
|
68
|
+
size: 14
|
|
69
|
+
}
|
|
70
|
+
),
|
|
71
|
+
isEditing ? /* @__PURE__ */ jsx(
|
|
72
|
+
"input",
|
|
73
|
+
{
|
|
74
|
+
autoFocus: true,
|
|
75
|
+
className: `${renameInput} ${semanticClassNames.renameInput}`,
|
|
76
|
+
value: editValue,
|
|
77
|
+
onBlur: onCommitRename,
|
|
78
|
+
onChange: (e) => onEditChange(e.target.value),
|
|
79
|
+
onClick: (e) => e.stopPropagation(),
|
|
80
|
+
onKeyDown: (e) => {
|
|
81
|
+
if (e.key === "Enter") onCommitRename();
|
|
82
|
+
if (e.key === "Escape") onCancelRename();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
) : /* @__PURE__ */ jsx("span", { className: `${fileName} ${semanticClassNames.fileName}`, children: file.filename }),
|
|
86
|
+
canDelete && /* @__PURE__ */ jsx(
|
|
87
|
+
"button",
|
|
88
|
+
{
|
|
89
|
+
"aria-label": `Delete ${file.filename}`,
|
|
90
|
+
className: `${fileDelete} ${semanticClassNames.fileDelete}`,
|
|
91
|
+
type: "button",
|
|
92
|
+
onClick: (e) => {
|
|
93
|
+
e.stopPropagation();
|
|
94
|
+
onDelete();
|
|
95
|
+
},
|
|
96
|
+
children: /* @__PURE__ */ jsx(Trash2, { size: 12 })
|
|
97
|
+
}
|
|
98
|
+
)
|
|
99
|
+
]
|
|
100
|
+
}
|
|
101
|
+
);
|
|
75
102
|
};
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
103
|
+
const CodeEditorModal = ({
|
|
104
|
+
files: initialFiles,
|
|
105
|
+
onFilesChange,
|
|
106
|
+
dismiss,
|
|
107
|
+
colorScheme
|
|
108
|
+
}) => {
|
|
109
|
+
const [editFiles, setEditFiles] = useState(() => initialFiles.map((f) => ({ ...f })));
|
|
110
|
+
const [activeFilename, setActiveFilename] = useState(initialFiles[0]?.filename ?? "");
|
|
111
|
+
const [editingFilename, setEditingFilename] = useState(null);
|
|
112
|
+
const [newFilenameInput, setNewFilenameInput] = useState("");
|
|
113
|
+
const [dragActiveId, setDragActiveId] = useState(null);
|
|
114
|
+
const containerRef = useRef(null);
|
|
115
|
+
const editorRef = useRef(null);
|
|
116
|
+
const languageCompartmentRef = useRef(null);
|
|
117
|
+
const themeCompartmentRef = useRef(null);
|
|
118
|
+
if (!languageCompartmentRef.current) languageCompartmentRef.current = new Compartment();
|
|
119
|
+
if (!themeCompartmentRef.current) themeCompartmentRef.current = new Compartment();
|
|
120
|
+
const onCodeChangeRef = useRef(void 0);
|
|
121
|
+
const editFilesRef = useRef(editFiles);
|
|
122
|
+
editFilesRef.current = editFiles;
|
|
123
|
+
const activeFile = editFiles.find((f) => f.filename === activeFilename) ?? editFiles[0];
|
|
124
|
+
onCodeChangeRef.current = (code) => {
|
|
125
|
+
setEditFiles((prev) => prev.map((f) => f.filename === activeFilename ? { ...f, code } : f));
|
|
126
|
+
};
|
|
127
|
+
useEffect(() => {
|
|
128
|
+
const container = containerRef.current;
|
|
129
|
+
if (!container) return;
|
|
130
|
+
const file = editFilesRef.current.find((f) => f.filename === activeFilename);
|
|
131
|
+
if (!file) return;
|
|
132
|
+
let cancelled = false;
|
|
133
|
+
const lang = normalizeLanguage(file.language ?? getLanguageFromFilename(file.filename));
|
|
134
|
+
const editor = new EditorView({
|
|
135
|
+
parent: container,
|
|
136
|
+
state: EditorState.create({
|
|
137
|
+
doc: file.code,
|
|
138
|
+
extensions: [
|
|
139
|
+
history(),
|
|
140
|
+
keymap.of([...defaultKeymap, ...historyKeymap, indentWithTab]),
|
|
141
|
+
EditorView.updateListener.of((update) => {
|
|
142
|
+
if (!update.docChanged) return;
|
|
143
|
+
onCodeChangeRef.current?.(update.state.doc.toString());
|
|
144
|
+
}),
|
|
145
|
+
lineNumbers(),
|
|
146
|
+
themeCompartmentRef.current.of(getThemeExtensions(colorScheme)),
|
|
147
|
+
languageCompartmentRef.current.of([])
|
|
148
|
+
]
|
|
149
|
+
})
|
|
150
|
+
});
|
|
151
|
+
editorRef.current = editor;
|
|
152
|
+
(async () => {
|
|
153
|
+
const extension = await loadLanguageExtension(lang);
|
|
154
|
+
if (cancelled) return;
|
|
155
|
+
editor.dispatch({
|
|
156
|
+
effects: languageCompartmentRef.current.reconfigure(extension)
|
|
157
|
+
});
|
|
158
|
+
})();
|
|
159
|
+
return () => {
|
|
160
|
+
cancelled = true;
|
|
161
|
+
editor.destroy();
|
|
162
|
+
editorRef.current = null;
|
|
163
|
+
};
|
|
164
|
+
}, [activeFilename]);
|
|
165
|
+
useEffect(() => {
|
|
166
|
+
const editor = editorRef.current;
|
|
167
|
+
if (!editor) return;
|
|
168
|
+
editor.dispatch({
|
|
169
|
+
effects: themeCompartmentRef.current.reconfigure(getThemeExtensions(colorScheme))
|
|
170
|
+
});
|
|
171
|
+
}, [colorScheme]);
|
|
172
|
+
const handleDismiss = useCallback(() => {
|
|
173
|
+
onFilesChange?.(editFiles);
|
|
174
|
+
dismiss();
|
|
175
|
+
}, [editFiles, onFilesChange, dismiss]);
|
|
176
|
+
const handleAddFile = useCallback(() => {
|
|
177
|
+
const name = `untitled-${editFiles.length + 1}.ts`;
|
|
178
|
+
const newFile = {
|
|
179
|
+
filename: name,
|
|
180
|
+
code: "",
|
|
181
|
+
language: "typescript"
|
|
182
|
+
};
|
|
183
|
+
setEditFiles((prev) => [...prev, newFile]);
|
|
184
|
+
setActiveFilename(name);
|
|
185
|
+
}, [editFiles.length]);
|
|
186
|
+
const handleDeleteFile = useCallback(
|
|
187
|
+
(filename) => {
|
|
188
|
+
if (editFiles.length <= 1) return;
|
|
189
|
+
const newFiles = editFiles.filter((f) => f.filename !== filename);
|
|
190
|
+
setEditFiles(newFiles);
|
|
191
|
+
if (activeFilename === filename) {
|
|
192
|
+
setActiveFilename(newFiles[0]?.filename ?? "");
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
[editFiles, activeFilename]
|
|
196
|
+
);
|
|
197
|
+
const handleRenameFile = useCallback(
|
|
198
|
+
(oldName, newName) => {
|
|
199
|
+
if (!newName.trim() || editFiles.some((f) => f.filename === newName && f.filename !== oldName)) {
|
|
200
|
+
setEditingFilename(null);
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
setEditFiles(
|
|
204
|
+
(prev) => prev.map(
|
|
205
|
+
(f) => f.filename === oldName ? { ...f, filename: newName, language: void 0 } : f
|
|
206
|
+
)
|
|
207
|
+
);
|
|
208
|
+
if (activeFilename === oldName) {
|
|
209
|
+
setActiveFilename(newName);
|
|
210
|
+
}
|
|
211
|
+
setEditingFilename(null);
|
|
212
|
+
},
|
|
213
|
+
[editFiles, activeFilename]
|
|
214
|
+
);
|
|
215
|
+
const sensors = useSensors(useSensor(PointerSensor, { activationConstraint: { distance: 5 } }));
|
|
216
|
+
const fileIds = useMemo(() => editFiles.map((f) => f.filename), [editFiles]);
|
|
217
|
+
const handleDragEnd = useCallback(
|
|
218
|
+
(event) => {
|
|
219
|
+
const { active, over } = event;
|
|
220
|
+
setDragActiveId(null);
|
|
221
|
+
if (!over || active.id === over.id) return;
|
|
222
|
+
const oldIndex = editFiles.findIndex((f) => f.filename === active.id);
|
|
223
|
+
const newIndex = editFiles.findIndex((f) => f.filename === over.id);
|
|
224
|
+
if (oldIndex === -1 || newIndex === -1) return;
|
|
225
|
+
setEditFiles(arrayMove(editFiles, oldIndex, newIndex));
|
|
226
|
+
},
|
|
227
|
+
[editFiles]
|
|
228
|
+
);
|
|
229
|
+
const dragActiveFile = dragActiveId ? editFiles.find((f) => f.filename === dragActiveId) : null;
|
|
230
|
+
const { className: portalThemeClassName } = usePortalTheme();
|
|
231
|
+
const language = activeFile ? activeFile.language ?? getLanguageFromFilename(activeFile.filename) : "";
|
|
232
|
+
return /* @__PURE__ */ jsxs("div", { className: `${modal} ${semanticClassNames.modal}`, children: [
|
|
233
|
+
/* @__PURE__ */ jsxs("div", { className: `${modalTitlebar} ${semanticClassNames.modalTitlebar}`, children: [
|
|
234
|
+
/* @__PURE__ */ jsx("span", { className: `${modalTitle} ${semanticClassNames.modalTitle}`, children: "Code Snippet" }),
|
|
235
|
+
/* @__PURE__ */ jsx(
|
|
236
|
+
"button",
|
|
237
|
+
{
|
|
238
|
+
className: `${modalIconButton} ${semanticClassNames.modalIconButton}`,
|
|
239
|
+
type: "button",
|
|
240
|
+
onClick: handleDismiss,
|
|
241
|
+
children: /* @__PURE__ */ jsx(X, { size: 14 })
|
|
242
|
+
}
|
|
243
|
+
)
|
|
244
|
+
] }),
|
|
245
|
+
/* @__PURE__ */ jsxs("div", { className: `${modalBody} ${semanticClassNames.modalBody}`, children: [
|
|
246
|
+
/* @__PURE__ */ jsxs("div", { className: `${modalSidebar} ${semanticClassNames.modalSidebar}`, children: [
|
|
247
|
+
/* @__PURE__ */ jsxs("div", { className: `${sidebarHeader} ${semanticClassNames.sidebarHeader}`, children: [
|
|
248
|
+
/* @__PURE__ */ jsx("span", { children: "Files" }),
|
|
249
|
+
/* @__PURE__ */ jsx(
|
|
250
|
+
"button",
|
|
251
|
+
{
|
|
252
|
+
"aria-label": "Add file",
|
|
253
|
+
className: `${sidebarAddButton} ${semanticClassNames.sidebarAddButton}`,
|
|
254
|
+
type: "button",
|
|
255
|
+
onClick: handleAddFile,
|
|
256
|
+
children: /* @__PURE__ */ jsx(Plus, { size: 14 })
|
|
257
|
+
}
|
|
258
|
+
)
|
|
259
|
+
] }),
|
|
260
|
+
/* @__PURE__ */ jsx("div", { className: `${fileList} ${semanticClassNames.fileList}`, children: /* @__PURE__ */ jsxs(
|
|
261
|
+
DndContext,
|
|
262
|
+
{
|
|
263
|
+
collisionDetection: closestCenter,
|
|
264
|
+
sensors,
|
|
265
|
+
onDragCancel: () => setDragActiveId(null),
|
|
266
|
+
onDragEnd: handleDragEnd,
|
|
267
|
+
onDragStart: (event) => setDragActiveId(event.active.id),
|
|
268
|
+
children: [
|
|
269
|
+
/* @__PURE__ */ jsx(SortableContext, { items: fileIds, strategy: verticalListSortingStrategy, children: editFiles.map((file) => /* @__PURE__ */ jsx(
|
|
270
|
+
SortableFileItem,
|
|
271
|
+
{
|
|
272
|
+
canDelete: editFiles.length > 1,
|
|
273
|
+
editValue: newFilenameInput,
|
|
274
|
+
file,
|
|
275
|
+
isActive: file.filename === activeFilename,
|
|
276
|
+
isEditing: editingFilename === file.filename,
|
|
277
|
+
onCancelRename: () => setEditingFilename(null),
|
|
278
|
+
onCommitRename: () => handleRenameFile(file.filename, newFilenameInput),
|
|
279
|
+
onDelete: () => handleDeleteFile(file.filename),
|
|
280
|
+
onEditChange: setNewFilenameInput,
|
|
281
|
+
onSelect: () => setActiveFilename(file.filename),
|
|
282
|
+
onStartRename: () => {
|
|
283
|
+
setEditingFilename(file.filename);
|
|
284
|
+
setNewFilenameInput(file.filename);
|
|
285
|
+
}
|
|
286
|
+
},
|
|
287
|
+
file.filename
|
|
288
|
+
)) }),
|
|
289
|
+
typeof document !== "undefined" ? createPortal(
|
|
290
|
+
/* @__PURE__ */ jsx(DragOverlay, { children: /* @__PURE__ */ jsx("div", { className: portalThemeClassName, style: { display: "contents" }, children: dragActiveFile ? /* @__PURE__ */ jsxs(
|
|
291
|
+
"div",
|
|
292
|
+
{
|
|
293
|
+
className: `${fileItem()} ${semanticClassNames.fileItem} ${dragOverlay} ${semanticClassNames.dragOverlay}`,
|
|
294
|
+
children: [
|
|
295
|
+
/* @__PURE__ */ jsx(
|
|
296
|
+
FileIcon,
|
|
297
|
+
{
|
|
298
|
+
className: `${fileIcon} ${semanticClassNames.fileIcon}`,
|
|
299
|
+
filename: dragActiveFile.filename,
|
|
300
|
+
size: 14
|
|
301
|
+
}
|
|
302
|
+
),
|
|
303
|
+
/* @__PURE__ */ jsx(
|
|
304
|
+
"span",
|
|
305
|
+
{
|
|
306
|
+
className: `${fileName} ${semanticClassNames.fileName}`,
|
|
307
|
+
children: dragActiveFile.filename
|
|
308
|
+
}
|
|
309
|
+
)
|
|
310
|
+
]
|
|
311
|
+
}
|
|
312
|
+
) : null }) }),
|
|
313
|
+
document.body
|
|
314
|
+
) : null
|
|
315
|
+
]
|
|
316
|
+
}
|
|
317
|
+
) })
|
|
318
|
+
] }),
|
|
319
|
+
/* @__PURE__ */ jsxs("div", { className: `${modalEditor} ${semanticClassNames.modalEditor}`, children: [
|
|
320
|
+
/* @__PURE__ */ jsx("div", { className: `${breadcrumb} ${semanticClassNames.breadcrumb}`, children: /* @__PURE__ */ jsx("div", { className: `${breadcrumbLeft} ${semanticClassNames.breadcrumbLeft}`, children: activeFile && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
321
|
+
/* @__PURE__ */ jsx(
|
|
322
|
+
FileIcon,
|
|
323
|
+
{
|
|
324
|
+
className: `${fileIcon} ${semanticClassNames.fileIcon}`,
|
|
325
|
+
filename: activeFile.filename,
|
|
326
|
+
size: 14
|
|
327
|
+
}
|
|
328
|
+
),
|
|
329
|
+
/* @__PURE__ */ jsx(
|
|
330
|
+
"span",
|
|
331
|
+
{
|
|
332
|
+
className: `${breadcrumbName} ${semanticClassNames.breadcrumbName}`,
|
|
333
|
+
children: activeFile.filename
|
|
334
|
+
}
|
|
335
|
+
),
|
|
336
|
+
language && /* @__PURE__ */ jsx(
|
|
337
|
+
"span",
|
|
338
|
+
{
|
|
339
|
+
className: `${breadcrumbLang} ${semanticClassNames.breadcrumbLang}`,
|
|
340
|
+
children: language
|
|
341
|
+
}
|
|
342
|
+
)
|
|
343
|
+
] }) }) }),
|
|
344
|
+
/* @__PURE__ */ jsx(
|
|
345
|
+
"div",
|
|
346
|
+
{
|
|
347
|
+
className: `${editorContainer} ${semanticClassNames.editorContainer}`,
|
|
348
|
+
ref: containerRef
|
|
349
|
+
}
|
|
350
|
+
)
|
|
351
|
+
] })
|
|
352
|
+
] })
|
|
353
|
+
] });
|
|
293
354
|
};
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
355
|
+
const CodeSnippetEditRenderer = ({
|
|
356
|
+
files,
|
|
357
|
+
onFilesChange
|
|
358
|
+
}) => {
|
|
359
|
+
const { className: portalClassName } = usePortalTheme();
|
|
360
|
+
const colorScheme = useColorScheme();
|
|
361
|
+
const handleEdit = useCallback(() => {
|
|
362
|
+
presentDialog({
|
|
363
|
+
content: ({ dismiss }) => /* @__PURE__ */ jsx(
|
|
364
|
+
CodeEditorModal,
|
|
365
|
+
{
|
|
366
|
+
colorScheme,
|
|
367
|
+
dismiss,
|
|
368
|
+
files,
|
|
369
|
+
onFilesChange
|
|
370
|
+
}
|
|
371
|
+
),
|
|
372
|
+
className: codeSnippetDialogPopup,
|
|
373
|
+
portalClassName,
|
|
374
|
+
theme: colorScheme,
|
|
375
|
+
showCloseButton: false,
|
|
376
|
+
clickOutsideToDismiss: false
|
|
377
|
+
});
|
|
378
|
+
}, [files, onFilesChange, portalClassName, colorScheme]);
|
|
379
|
+
return /* @__PURE__ */ jsxs("div", { className: `${editContainer} ${semanticClassNames.editContainer}`, children: [
|
|
380
|
+
/* @__PURE__ */ jsx(CodeSnippetRenderer, { files }),
|
|
381
|
+
/* @__PURE__ */ jsx(
|
|
382
|
+
"button",
|
|
383
|
+
{
|
|
384
|
+
"aria-label": "Edit code snippet",
|
|
385
|
+
className: `${editOverlay} ${semanticClassNames.editOverlay}`,
|
|
386
|
+
type: "button",
|
|
387
|
+
onClick: handleEdit,
|
|
388
|
+
children: /* @__PURE__ */ jsxs("span", { className: `${editLabel} ${semanticClassNames.editLabel}`, children: [
|
|
389
|
+
/* @__PURE__ */ jsx(Pencil, { size: 14 }),
|
|
390
|
+
"Edit"
|
|
391
|
+
] })
|
|
392
|
+
}
|
|
393
|
+
)
|
|
394
|
+
] });
|
|
332
395
|
};
|
|
333
|
-
|
|
334
|
-
//#region ../../node_modules/.pnpm/@lexical+react@0.41.0_react-dom@19.2.4_react@19.2.4__react@19.2.4_yjs@13.6.29/node_modules/@lexical/react/LexicalComposerContext.prod.mjs
|
|
335
|
-
/**
|
|
336
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
337
|
-
*
|
|
338
|
-
* This source code is licensed under the MIT license found in the
|
|
339
|
-
* LICENSE file in the root directory of this source tree.
|
|
340
|
-
*
|
|
341
|
-
*/
|
|
342
|
-
var r = createContext(null);
|
|
396
|
+
const r = createContext(null);
|
|
343
397
|
function o() {
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
398
|
+
const n = useContext(r);
|
|
399
|
+
return null == n && (function(n2, ...e) {
|
|
400
|
+
const r2 = new URL("https://lexical.dev/docs/error"), t = new URLSearchParams();
|
|
401
|
+
t.append("code", n2);
|
|
402
|
+
for (const n3 of e) t.append("v", n3);
|
|
403
|
+
throw r2.search = t.toString(), Error(`Minified Lexical error #${n2}; visit ${r2.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`);
|
|
404
|
+
})(8), n;
|
|
351
405
|
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
406
|
+
const CodeSnippetEditDecorator = ({ nodeKey, files }) => {
|
|
407
|
+
const [editor] = o();
|
|
408
|
+
const onFilesChange = useCallback(
|
|
409
|
+
(newFiles) => {
|
|
410
|
+
editor.update(() => {
|
|
411
|
+
const node = $getNodeByKey(nodeKey);
|
|
412
|
+
if ($isCodeSnippetNode(node)) {
|
|
413
|
+
node.setFiles(newFiles);
|
|
414
|
+
}
|
|
415
|
+
});
|
|
416
|
+
},
|
|
417
|
+
[editor, nodeKey]
|
|
418
|
+
);
|
|
419
|
+
return /* @__PURE__ */ jsx(CodeSnippetEditRenderer, { files, onFilesChange });
|
|
365
420
|
};
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
});
|
|
380
|
-
}
|
|
421
|
+
const _CodeSnippetEditNode = class _CodeSnippetEditNode extends CodeSnippetNode {
|
|
422
|
+
static clone(node) {
|
|
423
|
+
return new _CodeSnippetEditNode(node.__files, node.__key);
|
|
424
|
+
}
|
|
425
|
+
static importJSON(serializedNode) {
|
|
426
|
+
return new _CodeSnippetEditNode(serializedNode.files);
|
|
427
|
+
}
|
|
428
|
+
decorate(_editor, _config) {
|
|
429
|
+
return createElement(CodeSnippetEditDecorator, {
|
|
430
|
+
nodeKey: this.__key,
|
|
431
|
+
files: this.__files
|
|
432
|
+
});
|
|
433
|
+
}
|
|
381
434
|
};
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
}
|
|
404
|
-
}]);
|
|
435
|
+
__publicField(_CodeSnippetEditNode, "commandItems", [
|
|
436
|
+
{
|
|
437
|
+
title: "Code Snippet",
|
|
438
|
+
icon: createElement(FileCode, { size: 20 }),
|
|
439
|
+
description: "Multi-file code snippet with tabs",
|
|
440
|
+
keywords: ["code", "snippet", "files", "tabs"],
|
|
441
|
+
section: "MEDIA",
|
|
442
|
+
placement: ["slash", "toolbar"],
|
|
443
|
+
group: "insert",
|
|
444
|
+
onSelect: (editor) => {
|
|
445
|
+
editor.update(() => {
|
|
446
|
+
$insertNodes([
|
|
447
|
+
$createCodeSnippetEditNode([
|
|
448
|
+
{ filename: "index.ts", code: "", language: "typescript" }
|
|
449
|
+
])
|
|
450
|
+
]);
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
]);
|
|
455
|
+
let CodeSnippetEditNode = _CodeSnippetEditNode;
|
|
405
456
|
function $createCodeSnippetEditNode(files) {
|
|
406
|
-
|
|
457
|
+
return new CodeSnippetEditNode(files);
|
|
407
458
|
}
|
|
408
459
|
function $isCodeSnippetEditNode(node) {
|
|
409
|
-
|
|
460
|
+
return node instanceof CodeSnippetEditNode;
|
|
410
461
|
}
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
462
|
+
const codeSnippetNodes = [CodeSnippetNode];
|
|
463
|
+
const codeSnippetEditNodes = [CodeSnippetEditNode];
|
|
464
|
+
export {
|
|
465
|
+
$createCodeSnippetEditNode,
|
|
466
|
+
E as $createCodeSnippetNode,
|
|
467
|
+
$isCodeSnippetEditNode,
|
|
468
|
+
$isCodeSnippetNode,
|
|
469
|
+
CODE_SNIPPET_BLOCK_TRANSFORMER,
|
|
470
|
+
CodeSnippetEditNode,
|
|
471
|
+
CodeSnippetEditRenderer,
|
|
472
|
+
CodeSnippetNode,
|
|
473
|
+
CodeSnippetRenderer,
|
|
474
|
+
codeSnippetEditNodes,
|
|
475
|
+
codeSnippetNodes
|
|
476
|
+
};
|