@haklex/rich-editor 0.57.0 → 0.59.0
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/README.md +35 -0
- package/dist/{AlertQuoteEditNode-DQt5pIZ8.js → AlertQuoteEditNode-Ck4v29Wg.js} +9 -20
- package/dist/BlockIdPlugin-Cwv8aV9g.js +106 -0
- package/dist/{ColorSchemeContext-RLg0uDRt.js → ColorSchemeContext-Dc_HebHd.js} +5 -4
- package/dist/ContentEditable.css--lQ6ekTS.js +7 -0
- package/dist/EditorBlockContext-DytAx9Tg.js +9 -0
- package/dist/{ExtraNodesContext-DdU7MZwS.js → ExtraNodesContext-xQ2RNsqH.js} +1 -1
- package/dist/{MermaidPlugin-BpoGXa9D.js → MermaidPlugin-BCoGsdi3.js} +3 -3
- package/dist/NestedEditorPluginsContext-D78UZkmx.js +16 -0
- package/dist/{RubyRenderer-CnTFvt0b.js → RubyRenderer-8HMSMaZz.js} +1 -1
- package/dist/VirtualizationPlugin-C8TJ4HJN.js +178 -0
- package/dist/{SubmitShortcutPlugin-BuRxU6WD.js → VirtualizationPlugin-Crc0cLUx.js} +969 -532
- package/dist/VirtualizedEditor-CIGYcIfr.js +818 -0
- package/dist/command-registry-entry.d.ts +3 -0
- package/dist/command-registry-entry.d.ts.map +1 -0
- package/dist/command-registry-entry.mjs +343 -0
- package/dist/commands/registry.d.ts +24 -0
- package/dist/commands/registry.d.ts.map +1 -0
- package/dist/commands-entry.mjs +2 -2
- package/dist/components/EditorSurfaceHost.d.ts +3 -0
- package/dist/components/EditorSurfaceHost.d.ts.map +1 -0
- package/dist/components/RichEditor.d.ts.map +1 -1
- package/dist/components/RichEditorShell.d.ts +3 -1
- package/dist/components/RichEditorShell.d.ts.map +1 -1
- package/dist/components/VirtualizationFromProps.d.ts +6 -0
- package/dist/components/VirtualizationFromProps.d.ts.map +1 -0
- package/dist/components/decorators/GridEditDecorator.d.ts.map +1 -1
- package/dist/components/renderers/ImageRenderer.d.ts +1 -0
- package/dist/components/renderers/ImageRenderer.d.ts.map +1 -1
- package/dist/context/EditorBlockContext.d.ts +12 -0
- package/dist/context/EditorBlockContext.d.ts.map +1 -0
- package/dist/context/EditorSurfaceContext.d.ts +42 -0
- package/dist/context/EditorSurfaceContext.d.ts.map +1 -0
- package/dist/defineProperty-BYhxpJwd.js +39 -0
- package/dist/{grid.css-CUb_icKZ.js → grid.css-DJWKdYpz.js} +2 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +95 -43
- package/dist/{katex.css-9tq8FN8h.js → katex.css-9crOcnIa.js} +2 -1
- package/dist/{node-registry-CH2oHfO4.js → node-registry-jRE4LqH-.js} +37 -21
- package/dist/nodes/ImageNode.d.ts +7 -1
- package/dist/nodes/ImageNode.d.ts.map +1 -1
- package/dist/nodes/RichQuoteNode.d.ts +4 -1
- package/dist/nodes/RichQuoteNode.d.ts.map +1 -1
- package/dist/nodes-entry.mjs +4 -4
- package/dist/plugins/FileUploadPlugin.d.ts.map +1 -1
- package/dist/plugins/ImageDialog.d.ts +13 -0
- package/dist/plugins/ImageDialog.d.ts.map +1 -0
- package/dist/plugins/ImageDialogReview.d.ts +13 -0
- package/dist/plugins/ImageDialogReview.d.ts.map +1 -0
- package/dist/plugins/ImageDialogSource.d.ts +12 -0
- package/dist/plugins/ImageDialogSource.d.ts.map +1 -0
- package/dist/plugins/ImagePlugin.d.ts.map +1 -1
- package/dist/plugins/ImageUploadPlugin.d.ts +1 -1
- package/dist/plugins/ImageUploadPlugin.d.ts.map +1 -1
- package/dist/plugins/VideoUploadPlugin.d.ts +1 -1
- package/dist/plugins/VideoUploadPlugin.d.ts.map +1 -1
- package/dist/plugins/VirtualizationPlugin.d.ts +2 -0
- package/dist/plugins/VirtualizationPlugin.d.ts.map +1 -0
- package/dist/plugins/image-dialog-model.d.ts +65 -0
- package/dist/plugins/image-dialog-model.d.ts.map +1 -0
- package/dist/plugins/image-dialog.css.d.ts +30 -0
- package/dist/plugins/image-dialog.css.d.ts.map +1 -0
- package/dist/plugins/image-upload-toast.d.ts +2 -0
- package/dist/plugins/image-upload-toast.d.ts.map +1 -0
- package/dist/plugins/image-upload.css.d.ts +0 -23
- package/dist/plugins/image-upload.css.d.ts.map +1 -1
- package/dist/plugins/insertion-cursor.d.ts +20 -0
- package/dist/plugins/insertion-cursor.d.ts.map +1 -0
- package/dist/plugins/present-image-dialog.d.ts +14 -0
- package/dist/plugins/present-image-dialog.d.ts.map +1 -0
- package/dist/plugins-entry.d.ts +5 -0
- package/dist/plugins-entry.d.ts.map +1 -1
- package/dist/plugins-entry.mjs +7 -5
- package/dist/recycler-entry.d.ts +8 -0
- package/dist/recycler-entry.d.ts.map +1 -0
- package/dist/recycler-entry.mjs +3 -0
- package/dist/renderers-entry.mjs +4 -4
- package/dist/rich-editor.css +1 -1
- package/dist/static-entry.d.ts +1 -0
- package/dist/static-entry.d.ts.map +1 -1
- package/dist/static-entry.mjs +10 -9
- package/dist/styles/grid.css.d.ts.map +1 -1
- package/dist/styles/shared.css.d.ts.map +1 -1
- package/dist/styles-entry.mjs +3 -3
- package/dist/{theme-Blq1EG_t.js → theme-DH4xzxU-.js} +63 -48
- package/dist/{thumbhash-DHHqtr0c.js → thumbhash-GjK8OYAb.js} +1 -1
- package/dist/types.d.ts +3 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/{utils-CdxPji5z.js → utils-E6qVk-NR.js} +1 -0
- package/dist/viewport-BvO92tse.js +210 -0
- package/dist/virtualization/VirtualizationPlugin.d.ts +5 -0
- package/dist/virtualization/VirtualizationPlugin.d.ts.map +1 -0
- package/dist/virtualization/VirtualizedEditor.d.ts +6 -0
- package/dist/virtualization/VirtualizedEditor.d.ts.map +1 -0
- package/dist/virtualization/controller.d.ts +73 -0
- package/dist/virtualization/controller.d.ts.map +1 -0
- package/dist/virtualization/document.d.ts +26 -0
- package/dist/virtualization/document.d.ts.map +1 -0
- package/dist/virtualization/layout.d.ts +42 -0
- package/dist/virtualization/layout.d.ts.map +1 -0
- package/dist/virtualization/preserve.d.ts +21 -0
- package/dist/virtualization/preserve.d.ts.map +1 -0
- package/dist/virtualization/style.css.d.ts +4 -0
- package/dist/virtualization/style.css.d.ts.map +1 -0
- package/dist/virtualization/sync.d.ts +4 -0
- package/dist/virtualization/sync.d.ts.map +1 -0
- package/dist/virtualization/types.d.ts +13 -0
- package/dist/virtualization/types.d.ts.map +1 -0
- package/dist/virtualization/viewport.d.ts +3 -0
- package/dist/virtualization/viewport.d.ts.map +1 -0
- package/dist/virtualization-entry.d.ts +3 -0
- package/dist/virtualization-entry.d.ts.map +1 -0
- package/dist/virtualization-entry.mjs +1 -0
- package/package.json +17 -5
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { c as setCodeBlockCursorIntent, o as $createCodeBlockEditNode, s as $createBannerEditNode, t as getResolvedEditNodes } from "./node-registry-
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import { i as FootnoteDefinitionsProvider, t as computeImageMeta } from "./thumbhash-
|
|
5
|
-
import { C as fileExtFromName, D as $createCommentPlaceholderNode, E as $createCommentNode, F as BannerNode, T as DetailsNode, _ as $createFootnoteSectionNode, b as $createFileNode, c as $createRubyNode, h as $isGridContainerNode, j as CodeBlockNode, k as CommentNode, o as $createVideoNode, u as RubyNode, v as $isFootnoteSectionNode, w as $createDetailsNode, x as $isFileNode, y as FootnoteSectionNode } from "./ColorSchemeContext-
|
|
6
|
-
import { c as PasteLinkPlugin, t as $createAlertQuoteEditNode } from "./AlertQuoteEditNode-
|
|
1
|
+
import { c as setCodeBlockCursorIntent, o as $createCodeBlockEditNode, s as $createBannerEditNode, t as getResolvedEditNodes } from "./node-registry-jRE4LqH-.js";
|
|
2
|
+
/* empty css */
|
|
3
|
+
import { B as FootnoteNode, C as KaTeXBlockNode, G as AlertQuoteNode, K as extractTextContent, O as $withAdaptiveImageDisplayWidth, Q as INLINE_DRAG_MIME, V as OPEN_FILE_PICKER_COMMAND, Z as INLINE_DRAG_ATTR, _ as MentionNode, b as KaTeXInlineNode, c as SpoilerNode, h as $createMentionNode, k as OPEN_IMAGE_UPLOAD_DIALOG_COMMAND, o as $createSpoilerNode, v as $createKaTeXInlineNode, w as $createImageNode, x as $createKaTeXBlockNode, z as $createFootnoteNode } from "./theme-DH4xzxU-.js";
|
|
4
|
+
import { i as FootnoteDefinitionsProvider, t as computeImageMeta } from "./thumbhash-GjK8OYAb.js";
|
|
5
|
+
import { C as fileExtFromName, D as $createCommentPlaceholderNode, E as $createCommentNode, F as BannerNode, T as DetailsNode, _ as $createFootnoteSectionNode, b as $createFileNode, c as $createRubyNode, h as $isGridContainerNode, j as CodeBlockNode, k as CommentNode, o as $createVideoNode, u as RubyNode, v as $isFootnoteSectionNode, w as $createDetailsNode, x as $isFileNode, y as FootnoteSectionNode } from "./ColorSchemeContext-Dc_HebHd.js";
|
|
6
|
+
import { c as PasteLinkPlugin, t as $createAlertQuoteEditNode } from "./AlertQuoteEditNode-Ck4v29Wg.js";
|
|
7
7
|
import { n as getHostname, r as probeFavicon, t as normalizeSerializedEditorState } from "./normalizeSerializedEditorState-VaI73T09.js";
|
|
8
|
+
import "./VirtualizationPlugin-C8TJ4HJN.js";
|
|
9
|
+
import { n as blockIdState } from "./BlockIdPlugin-Cwv8aV9g.js";
|
|
10
|
+
import { n as useEditorBlock } from "./EditorBlockContext-DytAx9Tg.js";
|
|
8
11
|
import { CheckListPlugin } from "@lexical/react/LexicalCheckListPlugin";
|
|
9
12
|
import { LinkPlugin } from "@lexical/react/LexicalLinkPlugin";
|
|
10
13
|
import { ListPlugin } from "@lexical/react/LexicalListPlugin";
|
|
@@ -12,19 +15,19 @@ import { TabIndentationPlugin } from "@lexical/react/LexicalTabIndentationPlugin
|
|
|
12
15
|
import { TablePlugin } from "@lexical/react/LexicalTablePlugin";
|
|
13
16
|
import { AutoLinkNode, LinkNode, createLinkMatcherWithRegExp, registerAutoLink } from "@lexical/link";
|
|
14
17
|
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
15
|
-
import { createContext, use, useCallback, useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
18
|
+
import { createContext, use, useCallback, useEffect, useId, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
16
19
|
import { $createQuoteNode, $isQuoteNode, DRAG_DROP_PASTE, QuoteNode } from "@lexical/rich-text";
|
|
17
|
-
import { $addUpdateTag, $createLineBreakNode, $createNodeSelection, $createParagraphNode, $createRangeSelection, $createTextNode, $getNodeByKey, $getRoot, $getSelection, $getState, $insertNodes, $isDecoratorNode, $isElementNode, $isLineBreakNode, $isNodeSelection, $isParagraphNode, $isRangeSelection, $isRootNode, $isTextNode, $nodesOfType, $parseSerializedNode, $setSelection,
|
|
20
|
+
import { $addUpdateTag, $createLineBreakNode, $createNodeSelection, $createParagraphNode, $createRangeSelection, $createTextNode, $getNodeByKey, $getRoot, $getSelection, $getState, $insertNodes, $isDecoratorNode, $isElementNode, $isLineBreakNode, $isNodeSelection, $isParagraphNode, $isRangeSelection, $isRootNode, $isTextNode, $nodesOfType, $parseSerializedNode, $setSelection, BLUR_COMMAND, CLICK_COMMAND, COMMAND_PRIORITY_CRITICAL, COMMAND_PRIORITY_EDITOR, COMMAND_PRIORITY_HIGH, COMMAND_PRIORITY_LOW, HISTORY_MERGE_TAG, IS_CODE, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_RIGHT_COMMAND, KEY_ARROW_UP_COMMAND, KEY_BACKSPACE_COMMAND, KEY_DELETE_COMMAND, KEY_ENTER_COMMAND, KEY_SPACE_COMMAND, PASTE_COMMAND, SELECTION_CHANGE_COMMAND, SKIP_COLLAB_TAG, TextNode, createEditor } from "lexical";
|
|
18
21
|
import { $createHorizontalRuleNode, HorizontalRuleNode, INSERT_HORIZONTAL_RULE_COMMAND } from "@lexical/extension";
|
|
19
22
|
import { CODE_BLOCK_NODE_TRANSFORMER, COMMENT_TRANSFORMER, CONTAINER_TRANSFORMER, FOOTNOTE_SECTION_TRANSFORMER, FOOTNOTE_TRANSFORMER, GIT_ALERT_TRANSFORMER, HORIZONTAL_RULE_BLOCK_TRANSFORMER, IMAGE_BLOCK_TRANSFORMER, INSERT_TRANSFORMER, KATEX_BLOCK_TRANSFORMER, KATEX_INLINE_TRANSFORMER, LINK_CARD_BLOCK_TRANSFORMER, MENTION_TRANSFORMER, MERMAID_BLOCK_TRANSFORMER, RUBY_TRANSFORMER, SPOILER_TRANSFORMER, SUBSCRIPT_TRANSFORMER, SUPERSCRIPT_TRANSFORMER, TABLE_BLOCK_TRANSFORMER, VIDEO_BLOCK_TRANSFORMER } from "@haklex/rich-headless/transformers";
|
|
20
23
|
import { createPortal } from "react-dom";
|
|
21
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
24
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
22
25
|
import { $convertFromMarkdownString, CHECK_LIST, CODE, QUOTE, TRANSFORMERS } from "@lexical/markdown";
|
|
23
26
|
import { $createTableCellNode, $createTableNode, $createTableRowNode, TableCellHeaderStates } from "@lexical/table";
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
27
|
+
import { MapPin, Pencil, Plus, Upload, X } from "lucide-react";
|
|
28
|
+
import { ActionButton, AnimatedCheckbox, Field, Kbd, TextInput, confirmDiscardChanges, presentDialog, toast, updateToast } from "@haklex/rich-editor-ui";
|
|
26
29
|
import { MarkdownShortcutPlugin } from "@lexical/react/LexicalMarkdownShortcutPlugin";
|
|
27
|
-
import {
|
|
30
|
+
import { usePortalTheme } from "@haklex/rich-style-token";
|
|
28
31
|
//#region src/plugins/AutoLinkPlugin.tsx
|
|
29
32
|
var DEFAULT_MATCHERS = [createLinkMatcherWithRegExp(/https?:\/\/(?:www\.)?[\w#%+.:=@~-]{1,256}\.[A-Za-z]{2}[\w#%&()+./:=?@~-]*/), createLinkMatcherWithRegExp(/(?:[\w%+.-]+@[\d.a-z-]+\.[a-z]{2,})/i, (text) => `mailto:${text}`)];
|
|
30
33
|
function AutoLinkPlugin({ matchers }) {
|
|
@@ -1072,7 +1075,7 @@ function MarkdownShortcutsPlugin() {
|
|
|
1072
1075
|
//#endregion
|
|
1073
1076
|
//#region src/components/CorePlugins.tsx
|
|
1074
1077
|
function CorePlugins() {
|
|
1075
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1078
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
1076
1079
|
/* @__PURE__ */ jsx(ListPlugin, {}),
|
|
1077
1080
|
/* @__PURE__ */ jsx(LinkPlugin, {}),
|
|
1078
1081
|
/* @__PURE__ */ jsx(PasteLinkPlugin, {}),
|
|
@@ -1147,107 +1150,6 @@ function useVideoUpload() {
|
|
|
1147
1150
|
return use(VideoUploadContext);
|
|
1148
1151
|
}
|
|
1149
1152
|
//#endregion
|
|
1150
|
-
//#region src/plugins/BlockIdPlugin.tsx
|
|
1151
|
-
var blockIdState = createState("blockId", { parse: (v) => typeof v === "string" ? v : "" });
|
|
1152
|
-
var NORMALIZATION_TAG = "block-id-normalization";
|
|
1153
|
-
function buildPreviousIdIndex(editorState) {
|
|
1154
|
-
return editorState.read(() => {
|
|
1155
|
-
const map = /* @__PURE__ */ new Map();
|
|
1156
|
-
for (const child of $getRoot().getChildren()) {
|
|
1157
|
-
const id = $getState(child, blockIdState);
|
|
1158
|
-
if (!id) continue;
|
|
1159
|
-
const set = map.get(id) ?? /* @__PURE__ */ new Set();
|
|
1160
|
-
set.add(child.getKey());
|
|
1161
|
-
map.set(id, set);
|
|
1162
|
-
}
|
|
1163
|
-
return map;
|
|
1164
|
-
});
|
|
1165
|
-
}
|
|
1166
|
-
function collectRootChildren(editorState) {
|
|
1167
|
-
return editorState.read(() => $getRoot().getChildren().map((child) => $getState(child, blockIdState)));
|
|
1168
|
-
}
|
|
1169
|
-
function hasDuplicateOrMissingId(children) {
|
|
1170
|
-
const seen = /* @__PURE__ */ new Set();
|
|
1171
|
-
for (const id of children) {
|
|
1172
|
-
if (!id || seen.has(id)) return true;
|
|
1173
|
-
seen.add(id);
|
|
1174
|
-
}
|
|
1175
|
-
return false;
|
|
1176
|
-
}
|
|
1177
|
-
function generateBlockId(used) {
|
|
1178
|
-
while (true) {
|
|
1179
|
-
const id = nanoid(8);
|
|
1180
|
-
if (!used.has(id)) return id;
|
|
1181
|
-
}
|
|
1182
|
-
}
|
|
1183
|
-
function pickKeeperKey(nodes, previousKeys) {
|
|
1184
|
-
if (!nodes.length) return null;
|
|
1185
|
-
if (previousKeys?.size) {
|
|
1186
|
-
for (const node of nodes) if (previousKeys.has(node.getKey())) return node.getKey();
|
|
1187
|
-
}
|
|
1188
|
-
return nodes[0]?.getKey() ?? null;
|
|
1189
|
-
}
|
|
1190
|
-
function normalizeRootBlockIds(editor, previousIdIndex) {
|
|
1191
|
-
editor.update(() => {
|
|
1192
|
-
$addUpdateTag("history-merge");
|
|
1193
|
-
const children = $getRoot().getChildren();
|
|
1194
|
-
const groupedById = /* @__PURE__ */ new Map();
|
|
1195
|
-
for (const child of children) {
|
|
1196
|
-
const id = $getState(child, blockIdState);
|
|
1197
|
-
if (!id) continue;
|
|
1198
|
-
const bucket = groupedById.get(id) ?? [];
|
|
1199
|
-
bucket.push(child);
|
|
1200
|
-
groupedById.set(id, bucket);
|
|
1201
|
-
}
|
|
1202
|
-
const keeperById = /* @__PURE__ */ new Map();
|
|
1203
|
-
for (const [id, nodes] of groupedById) {
|
|
1204
|
-
if (nodes.length <= 1) continue;
|
|
1205
|
-
const keeperKey = pickKeeperKey(nodes, previousIdIndex.get(id));
|
|
1206
|
-
if (keeperKey) keeperById.set(id, keeperKey);
|
|
1207
|
-
}
|
|
1208
|
-
const used = /* @__PURE__ */ new Set();
|
|
1209
|
-
for (const child of children) {
|
|
1210
|
-
let id = $getState(child, blockIdState);
|
|
1211
|
-
const keeperKey = id ? keeperById.get(id) : null;
|
|
1212
|
-
if (!id || used.has(id) || keeperKey !== void 0 && child.getKey() !== keeperKey) {
|
|
1213
|
-
id = generateBlockId(used);
|
|
1214
|
-
$setState(child, blockIdState, id);
|
|
1215
|
-
}
|
|
1216
|
-
used.add(id);
|
|
1217
|
-
}
|
|
1218
|
-
}, { tag: NORMALIZATION_TAG });
|
|
1219
|
-
}
|
|
1220
|
-
function syncBlockIdAttributes(editor) {
|
|
1221
|
-
editor.getEditorState().read(() => {
|
|
1222
|
-
for (const child of $getRoot().getChildren()) {
|
|
1223
|
-
const id = $getState(child, blockIdState);
|
|
1224
|
-
if (!id) continue;
|
|
1225
|
-
const dom = editor.getElementByKey(child.getKey());
|
|
1226
|
-
if (dom && dom.getAttribute("data-block-id") !== id) dom.setAttribute("data-block-id", id);
|
|
1227
|
-
}
|
|
1228
|
-
});
|
|
1229
|
-
}
|
|
1230
|
-
function BlockIdPlugin() {
|
|
1231
|
-
const [editor] = useLexicalComposerContext();
|
|
1232
|
-
useEffect(() => {
|
|
1233
|
-
if (hasDuplicateOrMissingId(collectRootChildren(editor.getEditorState()))) normalizeRootBlockIds(editor, /* @__PURE__ */ new Map());
|
|
1234
|
-
syncBlockIdAttributes(editor);
|
|
1235
|
-
return editor.registerUpdateListener(({ tags, editorState, prevEditorState }) => {
|
|
1236
|
-
if (tags.has(NORMALIZATION_TAG)) {
|
|
1237
|
-
syncBlockIdAttributes(editor);
|
|
1238
|
-
return;
|
|
1239
|
-
}
|
|
1240
|
-
if (!hasDuplicateOrMissingId(collectRootChildren(editorState))) {
|
|
1241
|
-
syncBlockIdAttributes(editor);
|
|
1242
|
-
return;
|
|
1243
|
-
}
|
|
1244
|
-
const previousIdIndex = buildPreviousIdIndex(prevEditorState);
|
|
1245
|
-
normalizeRootBlockIds(editor, previousIdIndex);
|
|
1246
|
-
});
|
|
1247
|
-
}, [editor]);
|
|
1248
|
-
return null;
|
|
1249
|
-
}
|
|
1250
|
-
//#endregion
|
|
1251
1153
|
//#region src/plugins/file-upload-store.ts
|
|
1252
1154
|
var stores = /* @__PURE__ */ new WeakMap();
|
|
1253
1155
|
function getStore(editor) {
|
|
@@ -1280,6 +1182,9 @@ function isMediaFile(file) {
|
|
|
1280
1182
|
return file.type.startsWith("image/") || file.type.startsWith("video/");
|
|
1281
1183
|
}
|
|
1282
1184
|
function FileUploadPlugin({ onUpload }) {
|
|
1185
|
+
const block = useEditorBlock();
|
|
1186
|
+
const blockRef = useRef(block);
|
|
1187
|
+
blockRef.current = block;
|
|
1283
1188
|
const [editor] = useLexicalComposerContext();
|
|
1284
1189
|
const uploadRef = useRef(onUpload);
|
|
1285
1190
|
uploadRef.current = onUpload;
|
|
@@ -1306,6 +1211,7 @@ function FileUploadPlugin({ onUpload }) {
|
|
|
1306
1211
|
});
|
|
1307
1212
|
};
|
|
1308
1213
|
const run = async () => {
|
|
1214
|
+
const release = blockRef.current?.retain();
|
|
1309
1215
|
const base = {
|
|
1310
1216
|
percent: 0,
|
|
1311
1217
|
retry: () => void run(),
|
|
@@ -1335,6 +1241,8 @@ function FileUploadPlugin({ onUpload }) {
|
|
|
1335
1241
|
status: "error",
|
|
1336
1242
|
error: "Upload failed"
|
|
1337
1243
|
});
|
|
1244
|
+
} finally {
|
|
1245
|
+
queueMicrotask(() => release?.());
|
|
1338
1246
|
}
|
|
1339
1247
|
};
|
|
1340
1248
|
run();
|
|
@@ -1389,50 +1297,24 @@ async function resolvePreprocessTargets(files, source, preprocess) {
|
|
|
1389
1297
|
}
|
|
1390
1298
|
}
|
|
1391
1299
|
//#endregion
|
|
1392
|
-
//#region src/plugins/image-
|
|
1393
|
-
var
|
|
1394
|
-
var
|
|
1395
|
-
var
|
|
1396
|
-
info: "_1x58dbf3",
|
|
1397
|
-
success: "_1x58dbf4",
|
|
1398
|
-
error: "_1x58dbf5"
|
|
1399
|
-
};
|
|
1400
|
-
var spinner = "_1x58dbf7";
|
|
1401
|
-
var dialogPopup = "_1x58dbf8";
|
|
1402
|
-
var dialogHeader = "_1x58dbf9";
|
|
1403
|
-
var dialogTitle = "_1x58dbfa";
|
|
1404
|
-
var dialogBody = "_1x58dbfb";
|
|
1405
|
-
var tabWrap = "_1x58dbfc";
|
|
1406
|
-
var uploadDropzone = "_1x58dbfd";
|
|
1407
|
-
var uploadDropzoneState = {
|
|
1408
|
-
idle: "_1x58dbfe",
|
|
1409
|
-
active: "_1x58dbff",
|
|
1410
|
-
busy: "_1x58dbfg"
|
|
1411
|
-
};
|
|
1412
|
-
var uploadDropIcon = "_1x58dbfh";
|
|
1413
|
-
var uploadDropTitle = "_1x58dbfi";
|
|
1414
|
-
var uploadDropDesc = "_1x58dbfj";
|
|
1415
|
-
var hiddenInput = "_1x58dbfk";
|
|
1416
|
-
var uploadBusyWrap = "_1x58dbfl";
|
|
1417
|
-
var uploadProgress = "_1x58dbfm";
|
|
1418
|
-
var urlInputRow = "_1x58dbfn";
|
|
1419
|
-
var textInput = "_1x58dbfo";
|
|
1420
|
-
var helperText = "_1x58dbfr";
|
|
1421
|
-
var dialogFooter = "_1x58dbfs";
|
|
1422
|
-
//#endregion
|
|
1423
|
-
//#region src/plugins/ImageUploadPlugin.tsx
|
|
1300
|
+
//#region src/plugins/image-dialog-model.ts
|
|
1301
|
+
var IMAGE_FORMATS_HINT = "PNG, JPG, GIF, WebP, AVIF";
|
|
1302
|
+
var UNSAFE_URL_RE = /^(?:javascript\s*:|vbscript\s*:|data\s*:(?!image\/))/i;
|
|
1303
|
+
var FLATTENED_BY_CANVAS = /* @__PURE__ */ new Set(["image/gif", "image/svg+xml"]);
|
|
1424
1304
|
function isImageFile(file) {
|
|
1425
1305
|
return file.type.startsWith("image/");
|
|
1426
1306
|
}
|
|
1427
|
-
function hasImageData(dataTransfer) {
|
|
1428
|
-
if (!dataTransfer) return false;
|
|
1429
|
-
if ([...dataTransfer.files].some(isImageFile)) return true;
|
|
1430
|
-
return [...dataTransfer.items].some((item) => item.type.startsWith("image/"));
|
|
1431
|
-
}
|
|
1432
|
-
var UNSAFE_URL_RE = /^(?:javascript\s*:|vbscript\s*:|data\s*:(?!image\/))/i;
|
|
1433
1307
|
function isSafeImageUrl(url) {
|
|
1434
1308
|
return !UNSAFE_URL_RE.test(url);
|
|
1435
1309
|
}
|
|
1310
|
+
function isEditableImage(file) {
|
|
1311
|
+
return !FLATTENED_BY_CANVAS.has(file.type);
|
|
1312
|
+
}
|
|
1313
|
+
function formatBytes(bytes) {
|
|
1314
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
1315
|
+
if (bytes < 1048576) return `${Math.round(bytes / 1024)} KB`;
|
|
1316
|
+
return `${(bytes / 1024 / 1024).toFixed(1)} MB`;
|
|
1317
|
+
}
|
|
1436
1318
|
function loadImageByUrl(src) {
|
|
1437
1319
|
return new Promise((resolve, reject) => {
|
|
1438
1320
|
const image = new Image();
|
|
@@ -1446,6 +1328,802 @@ function loadImageByUrl(src) {
|
|
|
1446
1328
|
image.src = src;
|
|
1447
1329
|
});
|
|
1448
1330
|
}
|
|
1331
|
+
function urlFileName(src) {
|
|
1332
|
+
try {
|
|
1333
|
+
const { pathname } = new URL(src);
|
|
1334
|
+
return decodeURIComponent(pathname.split("/").pop() || "") || src;
|
|
1335
|
+
} catch {
|
|
1336
|
+
return src;
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
function imageDialogCopy(mode, count) {
|
|
1340
|
+
if (mode === "replace") return {
|
|
1341
|
+
action: "Replace",
|
|
1342
|
+
title: "Replace image"
|
|
1343
|
+
};
|
|
1344
|
+
const label = count > 1 ? `Insert ${count} images` : "Insert image";
|
|
1345
|
+
return {
|
|
1346
|
+
action: label,
|
|
1347
|
+
title: label
|
|
1348
|
+
};
|
|
1349
|
+
}
|
|
1350
|
+
async function finalizeRows(rows, stripGps) {
|
|
1351
|
+
const failedIds = [];
|
|
1352
|
+
return {
|
|
1353
|
+
entries: (await Promise.all(rows.map(async (row) => {
|
|
1354
|
+
if (row.kind === "url") return {
|
|
1355
|
+
height: row.height,
|
|
1356
|
+
kind: "url",
|
|
1357
|
+
src: row.src,
|
|
1358
|
+
width: row.width
|
|
1359
|
+
};
|
|
1360
|
+
if (row.current !== row.original || !row.removeGps || !row.gps) return {
|
|
1361
|
+
file: row.current,
|
|
1362
|
+
kind: "file"
|
|
1363
|
+
};
|
|
1364
|
+
try {
|
|
1365
|
+
if (!stripGps) throw new Error("No GPS stripper configured");
|
|
1366
|
+
return {
|
|
1367
|
+
file: await stripGps(row.original),
|
|
1368
|
+
kind: "file"
|
|
1369
|
+
};
|
|
1370
|
+
} catch {
|
|
1371
|
+
failedIds.push(row.id);
|
|
1372
|
+
return null;
|
|
1373
|
+
}
|
|
1374
|
+
}))).filter((entry) => entry !== null),
|
|
1375
|
+
failedIds
|
|
1376
|
+
};
|
|
1377
|
+
}
|
|
1378
|
+
var editors = /* @__PURE__ */ new WeakMap();
|
|
1379
|
+
function registerImageEditor(scope, capability) {
|
|
1380
|
+
editors.set(scope, capability);
|
|
1381
|
+
return () => {
|
|
1382
|
+
if (editors.get(scope) === capability) editors.delete(scope);
|
|
1383
|
+
};
|
|
1384
|
+
}
|
|
1385
|
+
function getImageEditor(scope) {
|
|
1386
|
+
return (scope && editors.get(scope)) ?? null;
|
|
1387
|
+
}
|
|
1388
|
+
//#endregion
|
|
1389
|
+
//#region src/plugins/image-upload.css.ts
|
|
1390
|
+
var draggingWrapperClass = "rich-image-upload-dragging";
|
|
1391
|
+
//#endregion
|
|
1392
|
+
//#region src/plugins/image-upload-toast.ts
|
|
1393
|
+
var ERROR_TOAST_DURATION$1 = 6e3;
|
|
1394
|
+
function plural(count, one, many) {
|
|
1395
|
+
return count > 1 ? many.replace("#", String(count)) : one;
|
|
1396
|
+
}
|
|
1397
|
+
async function reportImageUploads(files, run) {
|
|
1398
|
+
const attempt = async (batch) => {
|
|
1399
|
+
const id = toast({
|
|
1400
|
+
title: plural(batch.length, "Uploading image…", "Uploading # images…"),
|
|
1401
|
+
tone: "loading"
|
|
1402
|
+
});
|
|
1403
|
+
const failed = await run(batch);
|
|
1404
|
+
if (failed.length === 0) {
|
|
1405
|
+
updateToast(id, {
|
|
1406
|
+
title: plural(batch.length, "Image inserted", "Inserted # images"),
|
|
1407
|
+
tone: "success"
|
|
1408
|
+
});
|
|
1409
|
+
return;
|
|
1410
|
+
}
|
|
1411
|
+
updateToast(id, {
|
|
1412
|
+
action: {
|
|
1413
|
+
label: "Retry",
|
|
1414
|
+
onClick: () => void attempt(failed)
|
|
1415
|
+
},
|
|
1416
|
+
duration: ERROR_TOAST_DURATION$1,
|
|
1417
|
+
title: plural(failed.length, "Image upload failed", "# images failed to upload"),
|
|
1418
|
+
tone: "error"
|
|
1419
|
+
});
|
|
1420
|
+
};
|
|
1421
|
+
await attempt(files);
|
|
1422
|
+
}
|
|
1423
|
+
//#endregion
|
|
1424
|
+
//#region src/plugins/insertion-cursor.ts
|
|
1425
|
+
function $capturePoint(selection) {
|
|
1426
|
+
if ($isRangeSelection(selection)) {
|
|
1427
|
+
const end = selection.isBackward() ? selection.anchor : selection.focus;
|
|
1428
|
+
return {
|
|
1429
|
+
kind: "point",
|
|
1430
|
+
key: end.key,
|
|
1431
|
+
offset: end.offset,
|
|
1432
|
+
type: end.type
|
|
1433
|
+
};
|
|
1434
|
+
}
|
|
1435
|
+
if ($isNodeSelection(selection)) {
|
|
1436
|
+
const last = selection.getNodes().at(-1);
|
|
1437
|
+
if (last) return {
|
|
1438
|
+
kind: "after",
|
|
1439
|
+
key: last.getKey()
|
|
1440
|
+
};
|
|
1441
|
+
}
|
|
1442
|
+
return null;
|
|
1443
|
+
}
|
|
1444
|
+
function $createInsertionCursor() {
|
|
1445
|
+
const selection = $getSelection();
|
|
1446
|
+
return {
|
|
1447
|
+
callerMoved: false,
|
|
1448
|
+
expected: selection?.clone() ?? null,
|
|
1449
|
+
point: $capturePoint(selection)
|
|
1450
|
+
};
|
|
1451
|
+
}
|
|
1452
|
+
function readInsertionCursor(active, target) {
|
|
1453
|
+
return active === target ? $createInsertionCursor() : target.getEditorState().read($createInsertionCursor);
|
|
1454
|
+
}
|
|
1455
|
+
function $pointSize(key, type) {
|
|
1456
|
+
const node = $getNodeByKey(key);
|
|
1457
|
+
if (!node?.isAttached()) return null;
|
|
1458
|
+
if (type === "text") return $isTextNode(node) ? node.getTextContentSize() : null;
|
|
1459
|
+
return $isElementNode(node) ? node.getChildrenSize() : null;
|
|
1460
|
+
}
|
|
1461
|
+
function $resolvePoint(point) {
|
|
1462
|
+
if (!point) return null;
|
|
1463
|
+
let key = point.key;
|
|
1464
|
+
let offset;
|
|
1465
|
+
let type = "element";
|
|
1466
|
+
if (point.kind === "after") {
|
|
1467
|
+
const node = $getNodeByKey(point.key);
|
|
1468
|
+
const parent = node?.isAttached() ? node.getParent() : null;
|
|
1469
|
+
if (!node || !parent) return null;
|
|
1470
|
+
key = parent.getKey();
|
|
1471
|
+
offset = node.getIndexWithinParent() + 1;
|
|
1472
|
+
} else {
|
|
1473
|
+
const size = $pointSize(point.key, point.type);
|
|
1474
|
+
if (size === null) return null;
|
|
1475
|
+
offset = Math.min(point.offset, size);
|
|
1476
|
+
type = point.type;
|
|
1477
|
+
}
|
|
1478
|
+
const selection = $createRangeSelection();
|
|
1479
|
+
selection.anchor.set(key, offset, type);
|
|
1480
|
+
selection.focus.set(key, offset, type);
|
|
1481
|
+
return selection;
|
|
1482
|
+
}
|
|
1483
|
+
function $isPointUsable(point) {
|
|
1484
|
+
const size = $pointSize(point.key, point.type);
|
|
1485
|
+
return size !== null && point.offset <= size;
|
|
1486
|
+
}
|
|
1487
|
+
function $isSelectionUsable(selection) {
|
|
1488
|
+
if ($isRangeSelection(selection)) return $isPointUsable(selection.anchor) && $isPointUsable(selection.focus);
|
|
1489
|
+
return selection.getNodes().every((node) => node.isAttached());
|
|
1490
|
+
}
|
|
1491
|
+
function $insertAtCursor(cursor, nodes) {
|
|
1492
|
+
if (nodes.length === 0) return;
|
|
1493
|
+
const target = $resolvePoint(cursor.point);
|
|
1494
|
+
const current = $getSelection();
|
|
1495
|
+
const restore = (cursor.callerMoved || (current === null ? cursor.expected !== null : !current.is(cursor.expected))) && current ? current.clone() : null;
|
|
1496
|
+
if (target) $setSelection(target);
|
|
1497
|
+
$insertNodes(nodes);
|
|
1498
|
+
if (restore && $isSelectionUsable(restore)) {
|
|
1499
|
+
$setSelection(restore);
|
|
1500
|
+
cursor.callerMoved = true;
|
|
1501
|
+
}
|
|
1502
|
+
cursor.expected = $getSelection()?.clone() ?? null;
|
|
1503
|
+
cursor.point = {
|
|
1504
|
+
kind: "after",
|
|
1505
|
+
key: nodes.at(-1).getKey()
|
|
1506
|
+
};
|
|
1507
|
+
}
|
|
1508
|
+
//#endregion
|
|
1509
|
+
//#region src/plugins/image-dialog.css.ts
|
|
1510
|
+
var popup = "dtt1x70";
|
|
1511
|
+
var root = "dtt1x71";
|
|
1512
|
+
var body = "dtt1x72";
|
|
1513
|
+
var footer = "dtt1x73";
|
|
1514
|
+
var footerHint = "dtt1x75 dtt1x74";
|
|
1515
|
+
var errorHint = "dtt1x76 dtt1x75 dtt1x74";
|
|
1516
|
+
var hiddenInput = "dtt1x77";
|
|
1517
|
+
var dropzone = "dtt1x78";
|
|
1518
|
+
var dropIcon = "dtt1x79";
|
|
1519
|
+
var dropTitle = "dtt1x7a";
|
|
1520
|
+
var pasteHint = "dtt1x7b dtt1x74";
|
|
1521
|
+
var rows = "dtt1x7g";
|
|
1522
|
+
var row = "dtt1x7h";
|
|
1523
|
+
var rowFailed = "dtt1x7i";
|
|
1524
|
+
var thumb = "dtt1x7j";
|
|
1525
|
+
var rowBody = "dtt1x7k";
|
|
1526
|
+
var rowTitle = "dtt1x7l";
|
|
1527
|
+
var fileName = "dtt1x7m";
|
|
1528
|
+
var meta = "dtt1x7o dtt1x74";
|
|
1529
|
+
//#endregion
|
|
1530
|
+
//#region src/plugins/ImageDialogReview.tsx
|
|
1531
|
+
function useFileImageInfo(file) {
|
|
1532
|
+
const [info, setInfo] = useState(null);
|
|
1533
|
+
const [failed, setFailed] = useState(false);
|
|
1534
|
+
useEffect(() => {
|
|
1535
|
+
if (typeof URL.createObjectURL !== "function") return;
|
|
1536
|
+
const url = URL.createObjectURL(file);
|
|
1537
|
+
let active = true;
|
|
1538
|
+
setFailed(false);
|
|
1539
|
+
const image = new Image();
|
|
1540
|
+
image.onload = () => {
|
|
1541
|
+
if (active) setInfo({
|
|
1542
|
+
height: image.naturalHeight,
|
|
1543
|
+
url,
|
|
1544
|
+
width: image.naturalWidth
|
|
1545
|
+
});
|
|
1546
|
+
};
|
|
1547
|
+
image.onerror = () => {
|
|
1548
|
+
if (active) setFailed(true);
|
|
1549
|
+
};
|
|
1550
|
+
image.src = url;
|
|
1551
|
+
return () => {
|
|
1552
|
+
active = false;
|
|
1553
|
+
URL.revokeObjectURL(url);
|
|
1554
|
+
};
|
|
1555
|
+
}, [file]);
|
|
1556
|
+
return {
|
|
1557
|
+
failed,
|
|
1558
|
+
info
|
|
1559
|
+
};
|
|
1560
|
+
}
|
|
1561
|
+
function RowActions({ editLabel = "Edit", name, onEdit, onRemove }) {
|
|
1562
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [onEdit && /* @__PURE__ */ jsxs(ActionButton, {
|
|
1563
|
+
size: "sm",
|
|
1564
|
+
variant: "outline",
|
|
1565
|
+
onClick: onEdit,
|
|
1566
|
+
children: [/* @__PURE__ */ jsx(Pencil, {
|
|
1567
|
+
"aria-hidden": true,
|
|
1568
|
+
size: 14
|
|
1569
|
+
}), editLabel]
|
|
1570
|
+
}), /* @__PURE__ */ jsx(ActionButton, {
|
|
1571
|
+
icon: true,
|
|
1572
|
+
"aria-label": `Remove ${name}`,
|
|
1573
|
+
size: "sm",
|
|
1574
|
+
title: "Remove",
|
|
1575
|
+
onClick: onRemove,
|
|
1576
|
+
children: /* @__PURE__ */ jsx(X, {
|
|
1577
|
+
"aria-hidden": true,
|
|
1578
|
+
size: 16
|
|
1579
|
+
})
|
|
1580
|
+
})] });
|
|
1581
|
+
}
|
|
1582
|
+
function FileRowItem({ canEdit, failed, onEdit, onRemove, onToggleGps, row: row$1 }) {
|
|
1583
|
+
const { failed: decodeFailed, info } = useFileImageInfo(row$1.current);
|
|
1584
|
+
const edited = row$1.current !== row$1.original;
|
|
1585
|
+
const editable = canEdit && isEditableImage(row$1.current) && !decodeFailed;
|
|
1586
|
+
const type = row$1.current.type.replace("image/", "").toUpperCase();
|
|
1587
|
+
const meta$1 = [
|
|
1588
|
+
edited ? row$1.summary || null : null,
|
|
1589
|
+
info ? `${info.width} × ${info.height}` : null,
|
|
1590
|
+
formatBytes(row$1.current.size),
|
|
1591
|
+
edited ? null : type || null
|
|
1592
|
+
].filter(Boolean).join(" · ");
|
|
1593
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1594
|
+
className: failed ? `${row} ${rowFailed}` : row,
|
|
1595
|
+
"data-image-dialog-row": "",
|
|
1596
|
+
children: [
|
|
1597
|
+
info ? /* @__PURE__ */ jsx("img", {
|
|
1598
|
+
alt: "",
|
|
1599
|
+
className: thumb,
|
|
1600
|
+
src: info.url
|
|
1601
|
+
}) : /* @__PURE__ */ jsx("div", { className: thumb }),
|
|
1602
|
+
/* @__PURE__ */ jsxs("div", {
|
|
1603
|
+
className: rowBody,
|
|
1604
|
+
children: [
|
|
1605
|
+
/* @__PURE__ */ jsxs("div", {
|
|
1606
|
+
className: rowTitle,
|
|
1607
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
1608
|
+
className: fileName,
|
|
1609
|
+
title: row$1.original.name,
|
|
1610
|
+
children: row$1.original.name
|
|
1611
|
+
}), edited && /* @__PURE__ */ jsx("span", {
|
|
1612
|
+
className: "dtt1x7n",
|
|
1613
|
+
children: "Edited"
|
|
1614
|
+
})]
|
|
1615
|
+
}),
|
|
1616
|
+
/* @__PURE__ */ jsx("span", {
|
|
1617
|
+
className: meta,
|
|
1618
|
+
children: meta$1
|
|
1619
|
+
}),
|
|
1620
|
+
canEdit && !isEditableImage(row$1.current) && /* @__PURE__ */ jsx("span", {
|
|
1621
|
+
className: "dtt1x7o dtt1x74",
|
|
1622
|
+
children: "Animated or vector — editing would flatten it"
|
|
1623
|
+
}),
|
|
1624
|
+
!edited && row$1.gps && /* @__PURE__ */ jsxs("div", {
|
|
1625
|
+
className: "dtt1x7p",
|
|
1626
|
+
children: [/* @__PURE__ */ jsx(MapPin, {
|
|
1627
|
+
"aria-label": "Has location",
|
|
1628
|
+
className: "dtt1x7q",
|
|
1629
|
+
size: 13
|
|
1630
|
+
}), /* @__PURE__ */ jsx(AnimatedCheckbox, {
|
|
1631
|
+
checked: row$1.removeGps,
|
|
1632
|
+
label: "Remove before upload",
|
|
1633
|
+
onChange: onToggleGps
|
|
1634
|
+
})]
|
|
1635
|
+
}),
|
|
1636
|
+
failed && /* @__PURE__ */ jsx("span", {
|
|
1637
|
+
className: "dtt1x7r dtt1x74",
|
|
1638
|
+
children: "Could not remove location from this image"
|
|
1639
|
+
})
|
|
1640
|
+
]
|
|
1641
|
+
}),
|
|
1642
|
+
/* @__PURE__ */ jsx(RowActions, {
|
|
1643
|
+
editLabel: edited ? "Re-edit" : "Edit",
|
|
1644
|
+
name: row$1.original.name,
|
|
1645
|
+
onEdit: editable ? onEdit : void 0,
|
|
1646
|
+
onRemove
|
|
1647
|
+
})
|
|
1648
|
+
]
|
|
1649
|
+
});
|
|
1650
|
+
}
|
|
1651
|
+
function ImageDialogReview({ canAddMore, canEdit, failedIds, onAddMore, onEdit, onRemove, onToggleGps, rows: rows$1 }) {
|
|
1652
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("div", {
|
|
1653
|
+
className: rows,
|
|
1654
|
+
children: rows$1.map((row$2) => row$2.kind === "file" ? /* @__PURE__ */ jsx(FileRowItem, {
|
|
1655
|
+
canEdit,
|
|
1656
|
+
failed: row$2.removeGps && failedIds.includes(row$2.id),
|
|
1657
|
+
row: row$2,
|
|
1658
|
+
onEdit: () => onEdit(row$2),
|
|
1659
|
+
onRemove: () => onRemove(row$2.id),
|
|
1660
|
+
onToggleGps: (next) => onToggleGps(row$2.id, next)
|
|
1661
|
+
}, row$2.id) : /* @__PURE__ */ jsxs("div", {
|
|
1662
|
+
className: row,
|
|
1663
|
+
"data-image-dialog-row": "",
|
|
1664
|
+
children: [
|
|
1665
|
+
/* @__PURE__ */ jsx("img", {
|
|
1666
|
+
alt: "",
|
|
1667
|
+
className: thumb,
|
|
1668
|
+
src: row$2.src
|
|
1669
|
+
}),
|
|
1670
|
+
/* @__PURE__ */ jsxs("div", {
|
|
1671
|
+
className: rowBody,
|
|
1672
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
1673
|
+
className: fileName,
|
|
1674
|
+
title: row$2.src,
|
|
1675
|
+
children: urlFileName(row$2.src)
|
|
1676
|
+
}), /* @__PURE__ */ jsxs("span", {
|
|
1677
|
+
className: meta,
|
|
1678
|
+
children: [
|
|
1679
|
+
row$2.width,
|
|
1680
|
+
" × ",
|
|
1681
|
+
row$2.height,
|
|
1682
|
+
" · from link"
|
|
1683
|
+
]
|
|
1684
|
+
})]
|
|
1685
|
+
}),
|
|
1686
|
+
/* @__PURE__ */ jsx(RowActions, {
|
|
1687
|
+
name: urlFileName(row$2.src),
|
|
1688
|
+
onRemove: () => onRemove(row$2.id)
|
|
1689
|
+
})
|
|
1690
|
+
]
|
|
1691
|
+
}, row$2.id))
|
|
1692
|
+
}), canAddMore && /* @__PURE__ */ jsxs(ActionButton, {
|
|
1693
|
+
className: "dtt1x7s",
|
|
1694
|
+
size: "md",
|
|
1695
|
+
variant: "ghost",
|
|
1696
|
+
onClick: onAddMore,
|
|
1697
|
+
children: [/* @__PURE__ */ jsx(Plus, {
|
|
1698
|
+
"aria-hidden": true,
|
|
1699
|
+
size: 14
|
|
1700
|
+
}), "Add more"]
|
|
1701
|
+
})] });
|
|
1702
|
+
}
|
|
1703
|
+
//#endregion
|
|
1704
|
+
//#region src/plugins/ImageDialogSource.tsx
|
|
1705
|
+
var PREVIEW_DEBOUNCE_MS = 300;
|
|
1706
|
+
function hasImageData$1(dataTransfer) {
|
|
1707
|
+
if (!dataTransfer) return false;
|
|
1708
|
+
if ([...dataTransfer.files].some(isImageFile)) return true;
|
|
1709
|
+
return [...dataTransfer.items].some((item) => item.type.startsWith("image/"));
|
|
1710
|
+
}
|
|
1711
|
+
function useUrlPreview(url) {
|
|
1712
|
+
const [state, setState] = useState({ status: "idle" });
|
|
1713
|
+
useEffect(() => {
|
|
1714
|
+
const trimmed = url.trim();
|
|
1715
|
+
if (!trimmed) {
|
|
1716
|
+
setState({ status: "idle" });
|
|
1717
|
+
return;
|
|
1718
|
+
}
|
|
1719
|
+
if (!isSafeImageUrl(trimmed)) {
|
|
1720
|
+
setState({
|
|
1721
|
+
message: "Unsupported URL scheme",
|
|
1722
|
+
status: "error"
|
|
1723
|
+
});
|
|
1724
|
+
return;
|
|
1725
|
+
}
|
|
1726
|
+
setState({ status: "loading" });
|
|
1727
|
+
let active = true;
|
|
1728
|
+
const timer = setTimeout(() => {
|
|
1729
|
+
loadImageByUrl(trimmed).then(({ height, width }) => {
|
|
1730
|
+
if (active) setState({
|
|
1731
|
+
height,
|
|
1732
|
+
status: "loaded",
|
|
1733
|
+
width
|
|
1734
|
+
});
|
|
1735
|
+
}, () => {
|
|
1736
|
+
if (active) setState({
|
|
1737
|
+
message: "Could not load this image URL",
|
|
1738
|
+
status: "error"
|
|
1739
|
+
});
|
|
1740
|
+
});
|
|
1741
|
+
}, PREVIEW_DEBOUNCE_MS);
|
|
1742
|
+
return () => {
|
|
1743
|
+
active = false;
|
|
1744
|
+
clearTimeout(timer);
|
|
1745
|
+
};
|
|
1746
|
+
}, [url]);
|
|
1747
|
+
return state;
|
|
1748
|
+
}
|
|
1749
|
+
function ImageDialogSource({ allowUrl, onAddUrl, onPickFiles, onReceiveFiles }) {
|
|
1750
|
+
const urlId = useId();
|
|
1751
|
+
const [dragActive, setDragActive] = useState(false);
|
|
1752
|
+
const [url, setUrl] = useState("");
|
|
1753
|
+
const preview = useUrlPreview(url);
|
|
1754
|
+
const src = url.trim();
|
|
1755
|
+
const addUrl = () => {
|
|
1756
|
+
if (preview.status !== "loaded") return;
|
|
1757
|
+
onAddUrl({
|
|
1758
|
+
height: preview.height,
|
|
1759
|
+
src,
|
|
1760
|
+
width: preview.width
|
|
1761
|
+
});
|
|
1762
|
+
setUrl("");
|
|
1763
|
+
};
|
|
1764
|
+
const handleZoneKeyDown = (event) => {
|
|
1765
|
+
if (event.target !== event.currentTarget) return;
|
|
1766
|
+
if (event.key !== "Enter" && event.key !== " ") return;
|
|
1767
|
+
event.preventDefault();
|
|
1768
|
+
onPickFiles();
|
|
1769
|
+
};
|
|
1770
|
+
const handleDragOver = (event) => {
|
|
1771
|
+
if (!hasImageData$1(event.dataTransfer)) return;
|
|
1772
|
+
event.preventDefault();
|
|
1773
|
+
setDragActive(true);
|
|
1774
|
+
};
|
|
1775
|
+
const handleDrop = (event) => {
|
|
1776
|
+
event.preventDefault();
|
|
1777
|
+
setDragActive(false);
|
|
1778
|
+
const files = [...event.dataTransfer.files].filter(isImageFile);
|
|
1779
|
+
if (files.length > 0) onReceiveFiles(files);
|
|
1780
|
+
};
|
|
1781
|
+
const hint = preview.status === "loaded" ? `Loaded · ${preview.width} × ${preview.height}` : preview.status === "loading" ? "Loading preview…" : void 0;
|
|
1782
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs("div", {
|
|
1783
|
+
"aria-label": "Drop images here or choose files",
|
|
1784
|
+
className: dropzone,
|
|
1785
|
+
"data-drag-active": dragActive || void 0,
|
|
1786
|
+
role: "button",
|
|
1787
|
+
tabIndex: 0,
|
|
1788
|
+
onDragEnter: handleDragOver,
|
|
1789
|
+
onDragLeave: () => setDragActive(false),
|
|
1790
|
+
onDragOver: handleDragOver,
|
|
1791
|
+
onDrop: handleDrop,
|
|
1792
|
+
onKeyDown: handleZoneKeyDown,
|
|
1793
|
+
children: [
|
|
1794
|
+
/* @__PURE__ */ jsx("span", {
|
|
1795
|
+
"aria-hidden": true,
|
|
1796
|
+
className: dropIcon,
|
|
1797
|
+
children: /* @__PURE__ */ jsx(Upload, { size: 18 })
|
|
1798
|
+
}),
|
|
1799
|
+
/* @__PURE__ */ jsx("span", {
|
|
1800
|
+
className: dropTitle,
|
|
1801
|
+
children: "Drop images here"
|
|
1802
|
+
}),
|
|
1803
|
+
/* @__PURE__ */ jsx(ActionButton, {
|
|
1804
|
+
size: "md",
|
|
1805
|
+
tabIndex: -1,
|
|
1806
|
+
variant: "outline",
|
|
1807
|
+
onClick: onPickFiles,
|
|
1808
|
+
children: "Choose files"
|
|
1809
|
+
}),
|
|
1810
|
+
/* @__PURE__ */ jsxs("span", {
|
|
1811
|
+
className: pasteHint,
|
|
1812
|
+
children: [
|
|
1813
|
+
"or press ",
|
|
1814
|
+
/* @__PURE__ */ jsx(Kbd, {
|
|
1815
|
+
keys: ["mod", "v"],
|
|
1816
|
+
size: "sm"
|
|
1817
|
+
}),
|
|
1818
|
+
" to paste"
|
|
1819
|
+
]
|
|
1820
|
+
})
|
|
1821
|
+
]
|
|
1822
|
+
}), allowUrl && /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("div", {
|
|
1823
|
+
className: "dtt1x7c dtt1x74",
|
|
1824
|
+
children: "or from a link"
|
|
1825
|
+
}), /* @__PURE__ */ jsx(Field, {
|
|
1826
|
+
error: preview.status === "error" ? preview.message : void 0,
|
|
1827
|
+
hint,
|
|
1828
|
+
id: urlId,
|
|
1829
|
+
label: "Image URL",
|
|
1830
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
1831
|
+
className: "dtt1x7d",
|
|
1832
|
+
children: [
|
|
1833
|
+
/* @__PURE__ */ jsx(TextInput, {
|
|
1834
|
+
className: "dtt1x7e",
|
|
1835
|
+
id: urlId,
|
|
1836
|
+
invalid: preview.status === "error",
|
|
1837
|
+
placeholder: "https://example.com/image.jpg",
|
|
1838
|
+
type: "url",
|
|
1839
|
+
value: url,
|
|
1840
|
+
onChange: (event) => setUrl(event.target.value),
|
|
1841
|
+
onKeyDown: (event) => {
|
|
1842
|
+
if (event.key !== "Enter") return;
|
|
1843
|
+
event.preventDefault();
|
|
1844
|
+
addUrl();
|
|
1845
|
+
}
|
|
1846
|
+
}),
|
|
1847
|
+
preview.status === "loaded" && /* @__PURE__ */ jsx("img", {
|
|
1848
|
+
alt: "",
|
|
1849
|
+
className: "dtt1x7f",
|
|
1850
|
+
src
|
|
1851
|
+
}),
|
|
1852
|
+
/* @__PURE__ */ jsx(ActionButton, {
|
|
1853
|
+
disabled: preview.status !== "loaded",
|
|
1854
|
+
size: "md",
|
|
1855
|
+
variant: "solid",
|
|
1856
|
+
onClick: addUrl,
|
|
1857
|
+
children: "Add"
|
|
1858
|
+
})
|
|
1859
|
+
]
|
|
1860
|
+
})
|
|
1861
|
+
})] })] });
|
|
1862
|
+
}
|
|
1863
|
+
//#endregion
|
|
1864
|
+
//#region src/plugins/ImageDialog.tsx
|
|
1865
|
+
var rowCounter = 0;
|
|
1866
|
+
function toFileRow(file) {
|
|
1867
|
+
return {
|
|
1868
|
+
current: file,
|
|
1869
|
+
gps: null,
|
|
1870
|
+
id: `image-row-${++rowCounter}`,
|
|
1871
|
+
kind: "file",
|
|
1872
|
+
original: file,
|
|
1873
|
+
removeGps: true,
|
|
1874
|
+
summary: ""
|
|
1875
|
+
};
|
|
1876
|
+
}
|
|
1877
|
+
function initialRows(files, mode) {
|
|
1878
|
+
const images = (files ?? []).filter(isImageFile);
|
|
1879
|
+
return (mode === "replace" ? images.slice(0, 1) : images).map(toFileRow);
|
|
1880
|
+
}
|
|
1881
|
+
function withGps(rows, found) {
|
|
1882
|
+
return rows.map((row) => row.kind === "file" && found.has(row.id) ? {
|
|
1883
|
+
...row,
|
|
1884
|
+
gps: found.get(row.id) ?? null
|
|
1885
|
+
} : row);
|
|
1886
|
+
}
|
|
1887
|
+
function ImageDialog({ allowUrl = true, editor = null, initialFiles, mode = "insert", onCancel, onDirtyChange, onSubmit, onTitleChange }) {
|
|
1888
|
+
const startedWithFiles = Boolean(initialFiles?.some(isImageFile));
|
|
1889
|
+
const [rows, setRows] = useState(() => initialRows(initialFiles, mode));
|
|
1890
|
+
const [step, setStep] = useState(startedWithFiles ? "review" : "source");
|
|
1891
|
+
const [failedIds, setFailedIds] = useState([]);
|
|
1892
|
+
const [inserting, setInserting] = useState(false);
|
|
1893
|
+
const fileInputRef = useRef(null);
|
|
1894
|
+
const detections = useRef(/* @__PURE__ */ new Map());
|
|
1895
|
+
const privacy = editor?.privacy;
|
|
1896
|
+
const copy = imageDialogCopy(mode, step === "review" ? rows.length : 1);
|
|
1897
|
+
const dirty = rows.some((row) => row.kind === "file" && row.current !== row.original) || !startedWithFiles && rows.length > 0;
|
|
1898
|
+
useEffect(() => {
|
|
1899
|
+
onTitleChange?.(copy.title);
|
|
1900
|
+
}, [copy.title, onTitleChange]);
|
|
1901
|
+
useEffect(() => {
|
|
1902
|
+
onDirtyChange?.(dirty);
|
|
1903
|
+
}, [dirty, onDirtyChange]);
|
|
1904
|
+
useEffect(() => {
|
|
1905
|
+
if (!privacy) return;
|
|
1906
|
+
for (const row of rows) {
|
|
1907
|
+
if (row.kind !== "file" || detections.current.has(row.id)) continue;
|
|
1908
|
+
const detection = privacy.detectGps(row.original).catch(() => null);
|
|
1909
|
+
detections.current.set(row.id, detection);
|
|
1910
|
+
detection.then((gps) => {
|
|
1911
|
+
setRows((current) => withGps(current, /* @__PURE__ */ new Map([[row.id, gps]])));
|
|
1912
|
+
});
|
|
1913
|
+
}
|
|
1914
|
+
}, [privacy, rows]);
|
|
1915
|
+
const addFiles = (files) => {
|
|
1916
|
+
const images = files.filter(isImageFile);
|
|
1917
|
+
if (images.length === 0) return;
|
|
1918
|
+
setFailedIds([]);
|
|
1919
|
+
setRows((current) => mode === "replace" ? [toFileRow(images[0])] : [...current, ...images.map(toFileRow)]);
|
|
1920
|
+
setStep("review");
|
|
1921
|
+
};
|
|
1922
|
+
const addUrl = (entry) => {
|
|
1923
|
+
const row = {
|
|
1924
|
+
...entry,
|
|
1925
|
+
id: `image-row-${++rowCounter}`,
|
|
1926
|
+
kind: "url"
|
|
1927
|
+
};
|
|
1928
|
+
setRows((current) => mode === "replace" ? [row] : [...current, row]);
|
|
1929
|
+
setStep("review");
|
|
1930
|
+
};
|
|
1931
|
+
const removeRow = (id) => {
|
|
1932
|
+
const next = rows.filter((row) => row.id !== id);
|
|
1933
|
+
setRows(next);
|
|
1934
|
+
if (next.length > 0) return;
|
|
1935
|
+
if (startedWithFiles) onCancel();
|
|
1936
|
+
else setStep("source");
|
|
1937
|
+
};
|
|
1938
|
+
const editRow = async (target) => {
|
|
1939
|
+
if (!editor) return;
|
|
1940
|
+
const result = await editor.edit(target.current);
|
|
1941
|
+
if (!result || result.file === target.current) return;
|
|
1942
|
+
setRows((current) => current.map((row) => row.id === target.id && row.kind === "file" ? {
|
|
1943
|
+
...row,
|
|
1944
|
+
current: result.file,
|
|
1945
|
+
summary: [row.summary, result.summary].filter(Boolean).join(" · ")
|
|
1946
|
+
} : row));
|
|
1947
|
+
};
|
|
1948
|
+
const toggleGps = (id, removeGps) => {
|
|
1949
|
+
setRows((current) => current.map((row) => row.id === id && row.kind === "file" ? {
|
|
1950
|
+
...row,
|
|
1951
|
+
removeGps
|
|
1952
|
+
} : row));
|
|
1953
|
+
};
|
|
1954
|
+
const blocked = failedIds.some((id) => rows.some((row) => row.id === id && row.kind === "file" && row.removeGps && row.gps && row.current === row.original));
|
|
1955
|
+
const insert = async () => {
|
|
1956
|
+
if (inserting || blocked || rows.length === 0) return;
|
|
1957
|
+
setInserting(true);
|
|
1958
|
+
const ids = [...detections.current.keys()];
|
|
1959
|
+
const found = await Promise.all(ids.map((id) => detections.current.get(id)));
|
|
1960
|
+
const merged = withGps(rows, new Map(ids.map((id, index) => [id, found[index]])));
|
|
1961
|
+
const result = await finalizeRows(merged, privacy?.stripGps);
|
|
1962
|
+
setInserting(false);
|
|
1963
|
+
if (result.failedIds.length > 0) {
|
|
1964
|
+
setRows(merged);
|
|
1965
|
+
setFailedIds(result.failedIds);
|
|
1966
|
+
return;
|
|
1967
|
+
}
|
|
1968
|
+
onSubmit(result.entries);
|
|
1969
|
+
};
|
|
1970
|
+
const handleKeyDown = (event) => {
|
|
1971
|
+
if (step !== "review" || event.key !== "Enter" || !(event.metaKey || event.ctrlKey)) return;
|
|
1972
|
+
event.preventDefault();
|
|
1973
|
+
insert();
|
|
1974
|
+
};
|
|
1975
|
+
const handlePaste = (event) => {
|
|
1976
|
+
const files = [...event.clipboardData?.files ?? []].filter(isImageFile);
|
|
1977
|
+
if (files.length === 0) return;
|
|
1978
|
+
event.preventDefault();
|
|
1979
|
+
addFiles(files);
|
|
1980
|
+
};
|
|
1981
|
+
const pickFiles = () => fileInputRef.current?.click();
|
|
1982
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1983
|
+
className: root,
|
|
1984
|
+
onKeyDown: handleKeyDown,
|
|
1985
|
+
onPaste: handlePaste,
|
|
1986
|
+
children: [
|
|
1987
|
+
/* @__PURE__ */ jsx("input", {
|
|
1988
|
+
accept: "image/*",
|
|
1989
|
+
className: hiddenInput,
|
|
1990
|
+
multiple: mode !== "replace",
|
|
1991
|
+
ref: fileInputRef,
|
|
1992
|
+
type: "file",
|
|
1993
|
+
onChange: (event) => {
|
|
1994
|
+
addFiles([...event.currentTarget.files ?? []]);
|
|
1995
|
+
event.currentTarget.value = "";
|
|
1996
|
+
}
|
|
1997
|
+
}),
|
|
1998
|
+
/* @__PURE__ */ jsx("div", {
|
|
1999
|
+
className: body,
|
|
2000
|
+
children: step === "source" ? /* @__PURE__ */ jsx(ImageDialogSource, {
|
|
2001
|
+
allowUrl,
|
|
2002
|
+
onAddUrl: addUrl,
|
|
2003
|
+
onPickFiles: pickFiles,
|
|
2004
|
+
onReceiveFiles: addFiles
|
|
2005
|
+
}) : /* @__PURE__ */ jsx(ImageDialogReview, {
|
|
2006
|
+
canAddMore: mode !== "replace",
|
|
2007
|
+
canEdit: Boolean(editor),
|
|
2008
|
+
failedIds,
|
|
2009
|
+
rows,
|
|
2010
|
+
onAddMore: pickFiles,
|
|
2011
|
+
onEdit: (row) => void editRow(row),
|
|
2012
|
+
onRemove: removeRow,
|
|
2013
|
+
onToggleGps: toggleGps
|
|
2014
|
+
})
|
|
2015
|
+
}),
|
|
2016
|
+
/* @__PURE__ */ jsx("div", {
|
|
2017
|
+
className: footer,
|
|
2018
|
+
children: step === "source" ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("span", {
|
|
2019
|
+
className: footerHint,
|
|
2020
|
+
children: IMAGE_FORMATS_HINT
|
|
2021
|
+
}), rows.length > 0 && /* @__PURE__ */ jsx(ActionButton, {
|
|
2022
|
+
size: "md",
|
|
2023
|
+
variant: "outline",
|
|
2024
|
+
onClick: () => setStep("review"),
|
|
2025
|
+
children: "Continue"
|
|
2026
|
+
})] }) : /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
2027
|
+
/* @__PURE__ */ jsx("span", {
|
|
2028
|
+
className: blocked ? errorHint : footerHint,
|
|
2029
|
+
children: blocked ? "Keep the location or remove the flagged images to continue" : "Nothing is uploaded until you insert"
|
|
2030
|
+
}),
|
|
2031
|
+
startedWithFiles ? /* @__PURE__ */ jsx(ActionButton, {
|
|
2032
|
+
size: "md",
|
|
2033
|
+
variant: "outline",
|
|
2034
|
+
onClick: onCancel,
|
|
2035
|
+
children: "Cancel"
|
|
2036
|
+
}) : /* @__PURE__ */ jsx(ActionButton, {
|
|
2037
|
+
size: "md",
|
|
2038
|
+
variant: "outline",
|
|
2039
|
+
onClick: () => setStep("source"),
|
|
2040
|
+
children: "Back"
|
|
2041
|
+
}),
|
|
2042
|
+
/* @__PURE__ */ jsxs(ActionButton, {
|
|
2043
|
+
autoFocus: true,
|
|
2044
|
+
disabled: inserting || blocked,
|
|
2045
|
+
size: "md",
|
|
2046
|
+
variant: "solid",
|
|
2047
|
+
onClick: () => void insert(),
|
|
2048
|
+
children: [copy.action, /* @__PURE__ */ jsx(Kbd, {
|
|
2049
|
+
keys: ["mod", "enter"],
|
|
2050
|
+
size: "sm",
|
|
2051
|
+
tone: "inverted"
|
|
2052
|
+
})]
|
|
2053
|
+
})
|
|
2054
|
+
] })
|
|
2055
|
+
})
|
|
2056
|
+
]
|
|
2057
|
+
});
|
|
2058
|
+
}
|
|
2059
|
+
//#endregion
|
|
2060
|
+
//#region src/plugins/present-image-dialog.tsx
|
|
2061
|
+
function createTitleStore(initial) {
|
|
2062
|
+
let value = initial;
|
|
2063
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
2064
|
+
return {
|
|
2065
|
+
get: () => value,
|
|
2066
|
+
set: (next) => {
|
|
2067
|
+
if (next === value) return;
|
|
2068
|
+
value = next;
|
|
2069
|
+
for (const listener of listeners) listener();
|
|
2070
|
+
},
|
|
2071
|
+
subscribe: (listener) => {
|
|
2072
|
+
listeners.add(listener);
|
|
2073
|
+
return () => {
|
|
2074
|
+
listeners.delete(listener);
|
|
2075
|
+
};
|
|
2076
|
+
}
|
|
2077
|
+
};
|
|
2078
|
+
}
|
|
2079
|
+
function DialogTitleText({ store }) {
|
|
2080
|
+
return useSyncExternalStore(store.subscribe, store.get, store.get);
|
|
2081
|
+
}
|
|
2082
|
+
function presentImageDialog({ allowUrl = true, editor = null, files, mode = "insert", portalClassName, theme } = {}) {
|
|
2083
|
+
return new Promise((resolve) => {
|
|
2084
|
+
let settled = false;
|
|
2085
|
+
const settle = (result) => {
|
|
2086
|
+
if (settled) return;
|
|
2087
|
+
settled = true;
|
|
2088
|
+
resolve(result);
|
|
2089
|
+
};
|
|
2090
|
+
let dirty = false;
|
|
2091
|
+
const setDirty = (next) => {
|
|
2092
|
+
dirty = next;
|
|
2093
|
+
};
|
|
2094
|
+
const title = createTitleStore(imageDialogCopy(mode, files?.length ?? 1).title);
|
|
2095
|
+
presentDialog({
|
|
2096
|
+
className: popup,
|
|
2097
|
+
confirmDismiss: () => !dirty || confirmDiscardChanges(),
|
|
2098
|
+
onClose: () => settle(null),
|
|
2099
|
+
portalClassName,
|
|
2100
|
+
sheet: "auto",
|
|
2101
|
+
theme,
|
|
2102
|
+
title: /* @__PURE__ */ jsx(DialogTitleText, { store: title }),
|
|
2103
|
+
width: 520,
|
|
2104
|
+
content: ({ dismiss, requestDismiss }) => /* @__PURE__ */ jsx(ImageDialog, {
|
|
2105
|
+
allowUrl,
|
|
2106
|
+
editor,
|
|
2107
|
+
initialFiles: files,
|
|
2108
|
+
mode,
|
|
2109
|
+
onCancel: () => void requestDismiss(),
|
|
2110
|
+
onDirtyChange: setDirty,
|
|
2111
|
+
onTitleChange: title.set,
|
|
2112
|
+
onSubmit: (entries) => {
|
|
2113
|
+
settle(entries);
|
|
2114
|
+
dismiss();
|
|
2115
|
+
}
|
|
2116
|
+
})
|
|
2117
|
+
});
|
|
2118
|
+
});
|
|
2119
|
+
}
|
|
2120
|
+
//#endregion
|
|
2121
|
+
//#region src/plugins/ImageUploadPlugin.tsx
|
|
2122
|
+
function hasImageData(dataTransfer) {
|
|
2123
|
+
if (!dataTransfer) return false;
|
|
2124
|
+
if ([...dataTransfer.files].some(isImageFile)) return true;
|
|
2125
|
+
return [...dataTransfer.items].some((item) => item.type.startsWith("image/"));
|
|
2126
|
+
}
|
|
1449
2127
|
function readAsDataUrl(file) {
|
|
1450
2128
|
return new Promise((resolve, reject) => {
|
|
1451
2129
|
const reader = new FileReader();
|
|
@@ -1461,87 +2139,94 @@ async function defaultImageUpload(file) {
|
|
|
1461
2139
|
};
|
|
1462
2140
|
}
|
|
1463
2141
|
function ImageUploadPlugin({ onUpload }) {
|
|
2142
|
+
const block = useEditorBlock();
|
|
2143
|
+
const blockRef = useRef(block);
|
|
2144
|
+
blockRef.current = block;
|
|
1464
2145
|
const [editor] = useLexicalComposerContext();
|
|
1465
2146
|
const uploadRef = useRef(onUpload);
|
|
1466
2147
|
uploadRef.current = onUpload;
|
|
1467
|
-
const
|
|
1468
|
-
const
|
|
1469
|
-
|
|
1470
|
-
const
|
|
1471
|
-
const
|
|
1472
|
-
|
|
1473
|
-
const
|
|
1474
|
-
|
|
1475
|
-
const [dialogDragActive, setDialogDragActive] = useState(false);
|
|
1476
|
-
const [pendingUploads, setPendingUploads] = useState(0);
|
|
1477
|
-
const [dialogUploading, setDialogUploading] = useState(false);
|
|
1478
|
-
const [toast$2, setToast] = useState(null);
|
|
1479
|
-
const [urlInput, setUrlInput] = useState("");
|
|
1480
|
-
const [urlPreview$1, setUrlPreview] = useState(null);
|
|
1481
|
-
const [urlMeta, setUrlMeta] = useState(null);
|
|
1482
|
-
const [urlLoading, setUrlLoading] = useState(false);
|
|
1483
|
-
const [urlError, setUrlError] = useState(null);
|
|
1484
|
-
const tabItems = useMemo(() => [{
|
|
1485
|
-
value: "upload",
|
|
1486
|
-
label: "Upload"
|
|
1487
|
-
}, {
|
|
1488
|
-
value: "url",
|
|
1489
|
-
label: "URL"
|
|
1490
|
-
}], []);
|
|
1491
|
-
const pushToast = useCallback((kind, message) => {
|
|
1492
|
-
setToast({
|
|
1493
|
-
kind,
|
|
1494
|
-
message
|
|
1495
|
-
});
|
|
1496
|
-
if (toastTimerRef.current) window.clearTimeout(toastTimerRef.current);
|
|
1497
|
-
toastTimerRef.current = window.setTimeout(setToast, 2200, null);
|
|
1498
|
-
}, []);
|
|
1499
|
-
const insertByUpload = useCallback(async (file, target, options) => {
|
|
1500
|
-
if (!isImageFile(file)) return false;
|
|
1501
|
-
const closeDialog = Boolean(options?.closeDialog);
|
|
1502
|
-
setPendingUploads((value) => value + 1);
|
|
1503
|
-
if (closeDialog) setDialogUploading(true);
|
|
2148
|
+
const preprocessContext = useImagePreprocess();
|
|
2149
|
+
const preprocessContextRef = useRef(preprocessContext);
|
|
2150
|
+
preprocessContextRef.current = preprocessContext;
|
|
2151
|
+
const portalTheme = usePortalTheme();
|
|
2152
|
+
const portalThemeRef = useRef(portalTheme);
|
|
2153
|
+
portalThemeRef.current = portalTheme;
|
|
2154
|
+
const uploadAndInsert = useCallback(async (file, target, cursor, after) => {
|
|
2155
|
+
const release = blockRef.current?.retain();
|
|
1504
2156
|
try {
|
|
1505
2157
|
const [result, meta] = await Promise.all([uploadRef.current(file), computeImageMeta(file)]);
|
|
1506
|
-
await
|
|
2158
|
+
await after;
|
|
1507
2159
|
target.update(() => {
|
|
1508
|
-
|
|
2160
|
+
$insertAtCursor(cursor, [$createImageNode($withAdaptiveImageDisplayWidth({
|
|
1509
2161
|
src: result.src,
|
|
1510
2162
|
altText: result.altText ?? file.name,
|
|
1511
2163
|
width: result.width ?? meta.width,
|
|
1512
2164
|
height: result.height ?? meta.height,
|
|
1513
2165
|
thumbhash: result.thumbhash ?? meta.thumbhash
|
|
1514
|
-
}));
|
|
1515
|
-
$insertNodes([node]);
|
|
2166
|
+
}))]);
|
|
1516
2167
|
});
|
|
1517
|
-
if (closeDialog) {
|
|
1518
|
-
setDialogOpen(false);
|
|
1519
|
-
setUrlInput("");
|
|
1520
|
-
setUrlPreview(null);
|
|
1521
|
-
setUrlMeta(null);
|
|
1522
|
-
setUrlError(null);
|
|
1523
|
-
}
|
|
1524
|
-
pushToast("success", "Image uploaded");
|
|
1525
|
-
return true;
|
|
1526
|
-
} catch (err) {
|
|
1527
|
-
console.error("[ImageUploadPlugin]", err);
|
|
1528
|
-
pushToast("error", "Image upload failed");
|
|
1529
|
-
return false;
|
|
1530
2168
|
} finally {
|
|
1531
|
-
|
|
1532
|
-
setDialogUploading(false);
|
|
2169
|
+
queueMicrotask(() => release?.());
|
|
1533
2170
|
}
|
|
1534
|
-
}, [
|
|
2171
|
+
}, []);
|
|
2172
|
+
const uploadFiles = useCallback((files, target, cursor) => reportImageUploads(files, async (batch) => {
|
|
2173
|
+
let previous = Promise.resolve();
|
|
2174
|
+
const results = batch.map((file) => {
|
|
2175
|
+
const current = uploadAndInsert(file, target, cursor, previous.catch(() => {}));
|
|
2176
|
+
previous = current;
|
|
2177
|
+
return current;
|
|
2178
|
+
});
|
|
2179
|
+
const settled = await Promise.allSettled(results);
|
|
2180
|
+
return batch.filter((_, index) => {
|
|
2181
|
+
const outcome = settled[index];
|
|
2182
|
+
if (outcome.status === "fulfilled") return false;
|
|
2183
|
+
console.error("[ImageUploadPlugin]", outcome.reason);
|
|
2184
|
+
return true;
|
|
2185
|
+
});
|
|
2186
|
+
}), [uploadAndInsert]);
|
|
1535
2187
|
const handleFiles = useCallback((files, source, target) => {
|
|
1536
2188
|
const images = files.filter(isImageFile);
|
|
1537
2189
|
if (images.length === 0) return false;
|
|
2190
|
+
const cursor = readInsertionCursor(editor, target);
|
|
1538
2191
|
(async () => {
|
|
1539
|
-
const
|
|
1540
|
-
|
|
1541
|
-
|
|
2192
|
+
const release = blockRef.current?.retain();
|
|
2193
|
+
try {
|
|
2194
|
+
const preprocess = preprocessContextRef.current?.ref.current ?? null;
|
|
2195
|
+
const targets = await resolvePreprocessTargets(images, source, preprocess);
|
|
2196
|
+
if (targets.length > 0) await uploadFiles(targets, target, cursor);
|
|
2197
|
+
} finally {
|
|
2198
|
+
queueMicrotask(() => release?.());
|
|
2199
|
+
}
|
|
1542
2200
|
})();
|
|
1543
2201
|
return true;
|
|
1544
|
-
}, [
|
|
2202
|
+
}, [editor, uploadFiles]);
|
|
2203
|
+
const openDialog = useCallback(async (target, cursor) => {
|
|
2204
|
+
const release = blockRef.current?.retain();
|
|
2205
|
+
try {
|
|
2206
|
+
const scope = preprocessContextRef.current;
|
|
2207
|
+
const imageEditor = getImageEditor(scope);
|
|
2208
|
+
const entries = await presentImageDialog({
|
|
2209
|
+
editor: imageEditor,
|
|
2210
|
+
portalClassName: portalThemeRef.current.className,
|
|
2211
|
+
theme: portalThemeRef.current.theme
|
|
2212
|
+
});
|
|
2213
|
+
if (!entries) return;
|
|
2214
|
+
const urls = entries.flatMap((entry) => entry.kind === "url" ? [entry] : []);
|
|
2215
|
+
if (urls.length > 0) target.update(() => {
|
|
2216
|
+
$insertAtCursor(cursor, urls.map((entry) => $createImageNode($withAdaptiveImageDisplayWidth({
|
|
2217
|
+
src: entry.src,
|
|
2218
|
+
altText: "",
|
|
2219
|
+
width: entry.width,
|
|
2220
|
+
height: entry.height
|
|
2221
|
+
}))));
|
|
2222
|
+
});
|
|
2223
|
+
const picked = entries.flatMap((entry) => entry.kind === "file" ? [entry.file] : []);
|
|
2224
|
+
const files = imageEditor ? picked : await resolvePreprocessTargets(picked, "dialog", scope?.ref.current ?? null);
|
|
2225
|
+
if (files.length > 0) await uploadFiles(files, target, cursor);
|
|
2226
|
+
} finally {
|
|
2227
|
+
queueMicrotask(() => release?.());
|
|
2228
|
+
}
|
|
2229
|
+
}, [uploadFiles]);
|
|
1545
2230
|
useEffect(() => {
|
|
1546
2231
|
const unregisterDragDrop = editor.registerCommand(DRAG_DROP_PASTE, (files, fromEditor) => handleFiles(files, "drop", fromEditor), COMMAND_PRIORITY_HIGH);
|
|
1547
2232
|
const unregisterPaste = editor.registerCommand(PASTE_COMMAND, (event, fromEditor) => {
|
|
@@ -1552,26 +2237,21 @@ function ImageUploadPlugin({ onUpload }) {
|
|
|
1552
2237
|
return false;
|
|
1553
2238
|
}, COMMAND_PRIORITY_HIGH);
|
|
1554
2239
|
const unregisterOpenDialog = editor.registerCommand(OPEN_IMAGE_UPLOAD_DIALOG_COMMAND, (_payload, fromEditor) => {
|
|
1555
|
-
|
|
1556
|
-
setDialogOpen(true);
|
|
2240
|
+
openDialog(fromEditor, readInsertionCursor(editor, fromEditor));
|
|
1557
2241
|
return true;
|
|
1558
2242
|
}, COMMAND_PRIORITY_EDITOR);
|
|
1559
2243
|
const rootElement = editor.getRootElement();
|
|
1560
2244
|
const wrapper = rootElement?.parentElement ?? null;
|
|
1561
|
-
if (!wrapper) return () => {
|
|
2245
|
+
if (!rootElement || !wrapper) return () => {
|
|
1562
2246
|
unregisterDragDrop();
|
|
1563
2247
|
unregisterPaste();
|
|
1564
2248
|
unregisterOpenDialog();
|
|
1565
2249
|
};
|
|
1566
2250
|
let dragCounter = 0;
|
|
1567
|
-
const setWrapperDragging = (next) => {
|
|
1568
|
-
setRootDragActive(next);
|
|
1569
|
-
wrapper.classList.toggle(draggingWrapperClass, next);
|
|
1570
|
-
};
|
|
1571
2251
|
const onDragEnter = (event) => {
|
|
1572
2252
|
if (!hasImageData(event.dataTransfer)) return;
|
|
1573
2253
|
dragCounter += 1;
|
|
1574
|
-
|
|
2254
|
+
wrapper.classList.add(draggingWrapperClass);
|
|
1575
2255
|
};
|
|
1576
2256
|
const onDragOver = (event) => {
|
|
1577
2257
|
if (!hasImageData(event.dataTransfer)) return;
|
|
@@ -1579,253 +2259,32 @@ function ImageUploadPlugin({ onUpload }) {
|
|
|
1579
2259
|
};
|
|
1580
2260
|
const onDragLeave = () => {
|
|
1581
2261
|
dragCounter = Math.max(dragCounter - 1, 0);
|
|
1582
|
-
if (dragCounter === 0)
|
|
2262
|
+
if (dragCounter === 0) wrapper.classList.remove(draggingWrapperClass);
|
|
1583
2263
|
};
|
|
1584
2264
|
const onDrop = () => {
|
|
1585
2265
|
dragCounter = 0;
|
|
1586
|
-
|
|
2266
|
+
wrapper.classList.remove(draggingWrapperClass);
|
|
1587
2267
|
};
|
|
1588
|
-
rootElement
|
|
1589
|
-
rootElement
|
|
1590
|
-
rootElement
|
|
1591
|
-
rootElement
|
|
2268
|
+
rootElement.addEventListener("dragenter", onDragEnter);
|
|
2269
|
+
rootElement.addEventListener("dragover", onDragOver);
|
|
2270
|
+
rootElement.addEventListener("dragleave", onDragLeave);
|
|
2271
|
+
rootElement.addEventListener("drop", onDrop);
|
|
1592
2272
|
return () => {
|
|
1593
|
-
if (toastTimerRef.current) window.clearTimeout(toastTimerRef.current);
|
|
1594
2273
|
unregisterDragDrop();
|
|
1595
2274
|
unregisterPaste();
|
|
1596
2275
|
unregisterOpenDialog();
|
|
1597
|
-
|
|
1598
|
-
rootElement
|
|
1599
|
-
rootElement
|
|
1600
|
-
rootElement
|
|
1601
|
-
rootElement
|
|
2276
|
+
wrapper.classList.remove(draggingWrapperClass);
|
|
2277
|
+
rootElement.removeEventListener("dragenter", onDragEnter);
|
|
2278
|
+
rootElement.removeEventListener("dragover", onDragOver);
|
|
2279
|
+
rootElement.removeEventListener("dragleave", onDragLeave);
|
|
2280
|
+
rootElement.removeEventListener("drop", onDrop);
|
|
1602
2281
|
};
|
|
1603
|
-
}, [editor, handleFiles]);
|
|
1604
|
-
const resetUrlState = useCallback(() => {
|
|
1605
|
-
setUrlInput("");
|
|
1606
|
-
setUrlPreview(null);
|
|
1607
|
-
setUrlMeta(null);
|
|
1608
|
-
setUrlError(null);
|
|
1609
|
-
setUrlLoading(false);
|
|
1610
|
-
}, []);
|
|
1611
|
-
const handleDialogFile = useCallback(async (file) => {
|
|
1612
|
-
if (!file) return;
|
|
1613
|
-
let uploadFile = file;
|
|
1614
|
-
if (isImageFile(file)) [uploadFile] = await resolvePreprocessTargets([file], "dialog", getPreprocess());
|
|
1615
|
-
if (!uploadFile) return;
|
|
1616
|
-
await insertByUpload(uploadFile, targetEditorRef.current, { closeDialog: true });
|
|
1617
|
-
}, [insertByUpload, getPreprocess]);
|
|
1618
|
-
const handleUrlPreview = useCallback(async () => {
|
|
1619
|
-
const nextUrl = urlInput.trim();
|
|
1620
|
-
if (!nextUrl) return;
|
|
1621
|
-
if (!isSafeImageUrl(nextUrl)) {
|
|
1622
|
-
setUrlError("Unsupported URL scheme");
|
|
1623
|
-
return;
|
|
1624
|
-
}
|
|
1625
|
-
setUrlLoading(true);
|
|
1626
|
-
setUrlError(null);
|
|
1627
|
-
try {
|
|
1628
|
-
const meta = await loadImageByUrl(nextUrl);
|
|
1629
|
-
setUrlMeta(meta);
|
|
1630
|
-
setUrlPreview(nextUrl);
|
|
1631
|
-
} catch {
|
|
1632
|
-
setUrlPreview(null);
|
|
1633
|
-
setUrlMeta(null);
|
|
1634
|
-
setUrlError("Could not load this image URL");
|
|
1635
|
-
} finally {
|
|
1636
|
-
setUrlLoading(false);
|
|
1637
|
-
}
|
|
1638
|
-
}, [urlInput]);
|
|
1639
|
-
const handleInsertByUrl = useCallback(() => {
|
|
1640
|
-
if (!urlPreview$1 || !isSafeImageUrl(urlPreview$1)) return;
|
|
1641
|
-
targetEditorRef.current.update(() => {
|
|
1642
|
-
const node = $createImageNode($withAdaptiveImageDisplayWidth({
|
|
1643
|
-
src: urlPreview$1,
|
|
1644
|
-
altText: "",
|
|
1645
|
-
width: urlMeta?.width,
|
|
1646
|
-
height: urlMeta?.height
|
|
1647
|
-
}));
|
|
1648
|
-
$insertNodes([node]);
|
|
1649
|
-
});
|
|
1650
|
-
pushToast("success", "Image inserted");
|
|
1651
|
-
setDialogOpen(false);
|
|
1652
|
-
resetUrlState();
|
|
1653
2282
|
}, [
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
urlPreview$1
|
|
2283
|
+
editor,
|
|
2284
|
+
handleFiles,
|
|
2285
|
+
openDialog
|
|
1658
2286
|
]);
|
|
1659
|
-
|
|
1660
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [(helperMessage || toast$2) && /* @__PURE__ */ jsxs("div", {
|
|
1661
|
-
className: "_1x58dbf1",
|
|
1662
|
-
children: [helperMessage && /* @__PURE__ */ jsxs("div", {
|
|
1663
|
-
className: `_1x58dbf2 ${toastVariant.info}`,
|
|
1664
|
-
children: [/* @__PURE__ */ jsx("span", { className: "_1x58dbf7" }), helperMessage]
|
|
1665
|
-
}), toast$2 && /* @__PURE__ */ jsxs("div", {
|
|
1666
|
-
className: `_1x58dbf2 ${toastVariant[toast$2.kind]}`,
|
|
1667
|
-
children: [toast$2.kind === "success" ? /* @__PURE__ */ jsx(Check, { size: 12 }) : /* @__PURE__ */ jsx(Info, { size: 12 }), toast$2.message]
|
|
1668
|
-
})]
|
|
1669
|
-
}), /* @__PURE__ */ jsx(Dialog, {
|
|
1670
|
-
open: dialogOpen,
|
|
1671
|
-
onOpenChange: (nextOpen) => {
|
|
1672
|
-
if (!nextOpen && dialogUploading) return;
|
|
1673
|
-
setDialogOpen(nextOpen);
|
|
1674
|
-
if (!nextOpen) {
|
|
1675
|
-
resetUrlState();
|
|
1676
|
-
setDialogUploading(false);
|
|
1677
|
-
setDialogDragActive(false);
|
|
1678
|
-
targetEditorRef.current = editor;
|
|
1679
|
-
}
|
|
1680
|
-
},
|
|
1681
|
-
children: /* @__PURE__ */ jsxs(DialogPopup, {
|
|
1682
|
-
className: dialogPopup,
|
|
1683
|
-
showCloseButton: !dialogUploading,
|
|
1684
|
-
children: [
|
|
1685
|
-
/* @__PURE__ */ jsx("div", {
|
|
1686
|
-
className: dialogHeader,
|
|
1687
|
-
children: /* @__PURE__ */ jsx(DialogTitle, {
|
|
1688
|
-
className: dialogTitle,
|
|
1689
|
-
children: "Insert image"
|
|
1690
|
-
})
|
|
1691
|
-
}),
|
|
1692
|
-
/* @__PURE__ */ jsxs("div", {
|
|
1693
|
-
className: dialogBody,
|
|
1694
|
-
children: [/* @__PURE__ */ jsx("div", {
|
|
1695
|
-
className: tabWrap,
|
|
1696
|
-
children: /* @__PURE__ */ jsx(SegmentedControl, {
|
|
1697
|
-
fullWidth: true,
|
|
1698
|
-
items: tabItems,
|
|
1699
|
-
value: tab,
|
|
1700
|
-
onChange: setTab
|
|
1701
|
-
})
|
|
1702
|
-
}), tab === "upload" ? /* @__PURE__ */ jsxs("div", {
|
|
1703
|
-
className: `${uploadDropzone} ${uploadDropzoneState[dialogUploading ? "busy" : dialogDragActive ? "active" : "idle"]}`,
|
|
1704
|
-
role: "button",
|
|
1705
|
-
tabIndex: 0,
|
|
1706
|
-
onDragLeave: () => setDialogDragActive(false),
|
|
1707
|
-
onClick: () => {
|
|
1708
|
-
if (!dialogUploading) fileInputRef.current?.click();
|
|
1709
|
-
},
|
|
1710
|
-
onDragEnter: (event) => {
|
|
1711
|
-
if (hasImageData(event.dataTransfer)) {
|
|
1712
|
-
event.preventDefault();
|
|
1713
|
-
setDialogDragActive(true);
|
|
1714
|
-
}
|
|
1715
|
-
},
|
|
1716
|
-
onDragOver: (event) => {
|
|
1717
|
-
if (hasImageData(event.dataTransfer)) event.preventDefault();
|
|
1718
|
-
},
|
|
1719
|
-
onDrop: (event) => {
|
|
1720
|
-
event.preventDefault();
|
|
1721
|
-
setDialogDragActive(false);
|
|
1722
|
-
const file = [...event.dataTransfer.files].find(isImageFile);
|
|
1723
|
-
handleDialogFile(file ?? null);
|
|
1724
|
-
},
|
|
1725
|
-
onKeyDown: (event) => {
|
|
1726
|
-
if (event.key !== "Enter" && event.key !== " ") return;
|
|
1727
|
-
event.preventDefault();
|
|
1728
|
-
if (!dialogUploading) fileInputRef.current?.click();
|
|
1729
|
-
},
|
|
1730
|
-
children: [/* @__PURE__ */ jsx("input", {
|
|
1731
|
-
accept: "image/*",
|
|
1732
|
-
className: hiddenInput,
|
|
1733
|
-
ref: fileInputRef,
|
|
1734
|
-
type: "file",
|
|
1735
|
-
onChange: (event) => {
|
|
1736
|
-
const file = event.currentTarget.files?.[0] ?? null;
|
|
1737
|
-
handleDialogFile(file);
|
|
1738
|
-
event.currentTarget.value = "";
|
|
1739
|
-
}
|
|
1740
|
-
}), dialogUploading ? /* @__PURE__ */ jsx("div", {
|
|
1741
|
-
className: uploadBusyWrap,
|
|
1742
|
-
children: /* @__PURE__ */ jsxs("div", {
|
|
1743
|
-
className: uploadProgress,
|
|
1744
|
-
children: [/* @__PURE__ */ jsx("span", { className: spinner }), "Uploading image..."]
|
|
1745
|
-
})
|
|
1746
|
-
}) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1747
|
-
/* @__PURE__ */ jsx("span", {
|
|
1748
|
-
className: uploadDropIcon,
|
|
1749
|
-
children: /* @__PURE__ */ jsx(Upload, { size: 18 })
|
|
1750
|
-
}),
|
|
1751
|
-
/* @__PURE__ */ jsx("span", {
|
|
1752
|
-
className: uploadDropTitle,
|
|
1753
|
-
children: "Click to upload or drag and drop"
|
|
1754
|
-
}),
|
|
1755
|
-
/* @__PURE__ */ jsx("span", {
|
|
1756
|
-
className: uploadDropDesc,
|
|
1757
|
-
children: "PNG, JPG, GIF, WebP"
|
|
1758
|
-
})
|
|
1759
|
-
] })]
|
|
1760
|
-
}) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1761
|
-
/* @__PURE__ */ jsxs("div", {
|
|
1762
|
-
className: urlInputRow,
|
|
1763
|
-
children: [
|
|
1764
|
-
/* @__PURE__ */ jsx("input", {
|
|
1765
|
-
className: textInput,
|
|
1766
|
-
placeholder: "https://example.com/image.jpg",
|
|
1767
|
-
type: "url",
|
|
1768
|
-
value: urlInput,
|
|
1769
|
-
onChange: (event) => {
|
|
1770
|
-
setUrlInput(event.target.value);
|
|
1771
|
-
setUrlError(null);
|
|
1772
|
-
setUrlPreview(null);
|
|
1773
|
-
setUrlMeta(null);
|
|
1774
|
-
},
|
|
1775
|
-
onKeyDown: (event) => {
|
|
1776
|
-
if (event.key === "Enter") {
|
|
1777
|
-
event.preventDefault();
|
|
1778
|
-
if (urlPreview$1) handleInsertByUrl();
|
|
1779
|
-
else handleUrlPreview();
|
|
1780
|
-
}
|
|
1781
|
-
}
|
|
1782
|
-
}),
|
|
1783
|
-
/* @__PURE__ */ jsx(ActionButton, {
|
|
1784
|
-
disabled: urlLoading || !urlInput.trim(),
|
|
1785
|
-
size: "md",
|
|
1786
|
-
variant: "outline",
|
|
1787
|
-
onClick: () => void handleUrlPreview(),
|
|
1788
|
-
children: urlLoading ? "Loading" : "Preview"
|
|
1789
|
-
}),
|
|
1790
|
-
/* @__PURE__ */ jsx(ActionButton, {
|
|
1791
|
-
disabled: !urlPreview$1,
|
|
1792
|
-
size: "md",
|
|
1793
|
-
variant: "accent",
|
|
1794
|
-
onClick: handleInsertByUrl,
|
|
1795
|
-
children: "Insert"
|
|
1796
|
-
})
|
|
1797
|
-
]
|
|
1798
|
-
}),
|
|
1799
|
-
urlError && /* @__PURE__ */ jsxs("span", {
|
|
1800
|
-
className: `_1x58dbfr ${toastVariant.error}`,
|
|
1801
|
-
children: [/* @__PURE__ */ jsx(Info, { size: 12 }), urlError]
|
|
1802
|
-
}),
|
|
1803
|
-
urlPreview$1 && /* @__PURE__ */ jsx("div", {
|
|
1804
|
-
className: "_1x58dbfp",
|
|
1805
|
-
children: /* @__PURE__ */ jsx("img", {
|
|
1806
|
-
alt: "Preview",
|
|
1807
|
-
className: "_1x58dbfq",
|
|
1808
|
-
src: urlPreview$1
|
|
1809
|
-
})
|
|
1810
|
-
})
|
|
1811
|
-
] })]
|
|
1812
|
-
}),
|
|
1813
|
-
/* @__PURE__ */ jsxs("div", {
|
|
1814
|
-
className: dialogFooter,
|
|
1815
|
-
children: [/* @__PURE__ */ jsxs("span", {
|
|
1816
|
-
className: helperText,
|
|
1817
|
-
children: [/* @__PURE__ */ jsx(Link2, { size: 12 }), "You can also paste images or drag files directly into the editor."]
|
|
1818
|
-
}), /* @__PURE__ */ jsx(ActionBar, { children: /* @__PURE__ */ jsx(ActionButton, {
|
|
1819
|
-
disabled: dialogUploading,
|
|
1820
|
-
size: "md",
|
|
1821
|
-
variant: "outline",
|
|
1822
|
-
onClick: () => setDialogOpen(false),
|
|
1823
|
-
children: "Close"
|
|
1824
|
-
}) })]
|
|
1825
|
-
})
|
|
1826
|
-
]
|
|
1827
|
-
})
|
|
1828
|
-
})] });
|
|
2287
|
+
return null;
|
|
1829
2288
|
}
|
|
1830
2289
|
//#endregion
|
|
1831
2290
|
//#region src/plugins/LinkFaviconPlugin.tsx
|
|
@@ -2478,49 +2937,51 @@ function hasVideoData(dataTransfer) {
|
|
|
2478
2937
|
if ([...dataTransfer.files].some(isVideoFile)) return true;
|
|
2479
2938
|
return [...dataTransfer.items].some((item) => item.type.startsWith("video/"));
|
|
2480
2939
|
}
|
|
2940
|
+
var ERROR_TOAST_DURATION = 6e3;
|
|
2481
2941
|
function VideoUploadPlugin({ onUpload }) {
|
|
2942
|
+
const block = useEditorBlock();
|
|
2943
|
+
const blockRef = useRef(block);
|
|
2944
|
+
blockRef.current = block;
|
|
2482
2945
|
const [editor] = useLexicalComposerContext();
|
|
2483
2946
|
const uploadRef = useRef(onUpload);
|
|
2484
2947
|
uploadRef.current = onUpload;
|
|
2485
|
-
const
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
const pushToast = useCallback((kind, message) => {
|
|
2491
|
-
setToast({
|
|
2492
|
-
kind,
|
|
2493
|
-
message
|
|
2948
|
+
const uploadVideo = useCallback(async (file, cursor) => {
|
|
2949
|
+
const release = blockRef.current?.retain();
|
|
2950
|
+
const id = toast({
|
|
2951
|
+
title: "Uploading video…",
|
|
2952
|
+
tone: "loading"
|
|
2494
2953
|
});
|
|
2495
|
-
if (toastTimerRef.current) window.clearTimeout(toastTimerRef.current);
|
|
2496
|
-
toastTimerRef.current = window.setTimeout(setToast, 2200, null);
|
|
2497
|
-
}, []);
|
|
2498
|
-
const uploadVideo = useCallback(async (file) => {
|
|
2499
|
-
const id = nextUploadIdRef.current++;
|
|
2500
|
-
setUploads((prev) => new Map(prev).set(id, 0));
|
|
2501
2954
|
try {
|
|
2502
2955
|
const result = await uploadRef.current(file, { onProgress: (percent) => {
|
|
2503
|
-
|
|
2956
|
+
updateToast(id, { title: `Uploading video… ${Math.round(percent)}%` });
|
|
2504
2957
|
} });
|
|
2505
2958
|
editor.update(() => {
|
|
2506
|
-
$
|
|
2959
|
+
$insertAtCursor(cursor, [$createVideoNode({ src: result.src })]);
|
|
2960
|
+
});
|
|
2961
|
+
updateToast(id, {
|
|
2962
|
+
title: "Video uploaded",
|
|
2963
|
+
tone: "success"
|
|
2507
2964
|
});
|
|
2508
|
-
pushToast("success", "Video uploaded");
|
|
2509
2965
|
} catch (err) {
|
|
2510
2966
|
console.error("[VideoUploadPlugin]", err);
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2967
|
+
updateToast(id, {
|
|
2968
|
+
action: {
|
|
2969
|
+
label: "Retry",
|
|
2970
|
+
onClick: () => void uploadVideo(file, cursor)
|
|
2971
|
+
},
|
|
2972
|
+
duration: ERROR_TOAST_DURATION,
|
|
2973
|
+
title: "Video upload failed",
|
|
2974
|
+
tone: "error"
|
|
2517
2975
|
});
|
|
2976
|
+
} finally {
|
|
2977
|
+
queueMicrotask(() => release?.());
|
|
2518
2978
|
}
|
|
2519
|
-
}, [editor
|
|
2979
|
+
}, [editor]);
|
|
2520
2980
|
const handleFiles = useCallback((files) => {
|
|
2521
2981
|
const videos = files.filter(isVideoFile);
|
|
2522
2982
|
if (videos.length === 0) return false;
|
|
2523
|
-
|
|
2983
|
+
const cursor = $createInsertionCursor();
|
|
2984
|
+
for (const file of videos) uploadVideo(file, cursor);
|
|
2524
2985
|
return videos.length === files.length;
|
|
2525
2986
|
}, [uploadVideo]);
|
|
2526
2987
|
useEffect(() => {
|
|
@@ -2534,19 +2995,15 @@ function VideoUploadPlugin({ onUpload }) {
|
|
|
2534
2995
|
}, COMMAND_PRIORITY_CRITICAL);
|
|
2535
2996
|
const rootElement = editor.getRootElement();
|
|
2536
2997
|
const wrapper = rootElement?.parentElement ?? null;
|
|
2537
|
-
if (!wrapper) return () => {
|
|
2998
|
+
if (!rootElement || !wrapper) return () => {
|
|
2538
2999
|
unregisterDragDrop();
|
|
2539
3000
|
unregisterPaste();
|
|
2540
3001
|
};
|
|
2541
3002
|
let dragCounter = 0;
|
|
2542
|
-
const setWrapperDragging = (next) => {
|
|
2543
|
-
setRootDragActive(next);
|
|
2544
|
-
wrapper.classList.toggle(draggingWrapperClass, next);
|
|
2545
|
-
};
|
|
2546
3003
|
const onDragEnter = (event) => {
|
|
2547
3004
|
if (!hasVideoData(event.dataTransfer)) return;
|
|
2548
3005
|
dragCounter += 1;
|
|
2549
|
-
|
|
3006
|
+
wrapper.classList.add(draggingWrapperClass);
|
|
2550
3007
|
};
|
|
2551
3008
|
const onDragOver = (event) => {
|
|
2552
3009
|
if (!hasVideoData(event.dataTransfer)) return;
|
|
@@ -2554,57 +3011,26 @@ function VideoUploadPlugin({ onUpload }) {
|
|
|
2554
3011
|
};
|
|
2555
3012
|
const onDragLeave = () => {
|
|
2556
3013
|
dragCounter = Math.max(dragCounter - 1, 0);
|
|
2557
|
-
if (dragCounter === 0)
|
|
3014
|
+
if (dragCounter === 0) wrapper.classList.remove(draggingWrapperClass);
|
|
2558
3015
|
};
|
|
2559
3016
|
const onDrop = () => {
|
|
2560
3017
|
dragCounter = 0;
|
|
2561
|
-
|
|
3018
|
+
wrapper.classList.remove(draggingWrapperClass);
|
|
2562
3019
|
};
|
|
2563
|
-
rootElement
|
|
2564
|
-
rootElement
|
|
2565
|
-
rootElement
|
|
2566
|
-
rootElement
|
|
3020
|
+
rootElement.addEventListener("dragenter", onDragEnter);
|
|
3021
|
+
rootElement.addEventListener("dragover", onDragOver);
|
|
3022
|
+
rootElement.addEventListener("dragleave", onDragLeave);
|
|
3023
|
+
rootElement.addEventListener("drop", onDrop);
|
|
2567
3024
|
return () => {
|
|
2568
|
-
if (toastTimerRef.current) window.clearTimeout(toastTimerRef.current);
|
|
2569
3025
|
unregisterDragDrop();
|
|
2570
3026
|
unregisterPaste();
|
|
2571
|
-
|
|
2572
|
-
rootElement
|
|
2573
|
-
rootElement
|
|
2574
|
-
rootElement
|
|
2575
|
-
rootElement
|
|
3027
|
+
wrapper.classList.remove(draggingWrapperClass);
|
|
3028
|
+
rootElement.removeEventListener("dragenter", onDragEnter);
|
|
3029
|
+
rootElement.removeEventListener("dragover", onDragOver);
|
|
3030
|
+
rootElement.removeEventListener("dragleave", onDragLeave);
|
|
3031
|
+
rootElement.removeEventListener("drop", onDrop);
|
|
2576
3032
|
};
|
|
2577
3033
|
}, [editor, handleFiles]);
|
|
2578
|
-
const helperMessage = (() => {
|
|
2579
|
-
if (uploads.size === 1) {
|
|
2580
|
-
const percent = [...uploads.values()][0] ?? 0;
|
|
2581
|
-
return `Uploading video... ${Math.round(percent)}%`;
|
|
2582
|
-
}
|
|
2583
|
-
if (uploads.size > 1) return `Uploading ${uploads.size} videos...`;
|
|
2584
|
-
if (rootDragActive) return "Drop video files to upload";
|
|
2585
|
-
return null;
|
|
2586
|
-
})();
|
|
2587
|
-
if (!helperMessage && !toast$1) return null;
|
|
2588
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
2589
|
-
className: toastStack,
|
|
2590
|
-
children: [helperMessage && /* @__PURE__ */ jsxs("div", {
|
|
2591
|
-
className: `_1x58dbf2 ${toastVariant.info}`,
|
|
2592
|
-
children: [/* @__PURE__ */ jsx("span", { className: "_1x58dbf7" }), helperMessage]
|
|
2593
|
-
}), toast$1 && /* @__PURE__ */ jsxs("div", {
|
|
2594
|
-
className: `_1x58dbf2 ${toastVariant[toast$1.kind]}`,
|
|
2595
|
-
children: [toast$1.kind === "success" ? /* @__PURE__ */ jsx(Check, { size: 12 }) : /* @__PURE__ */ jsx(Info, { size: 12 }), toast$1.message]
|
|
2596
|
-
})]
|
|
2597
|
-
});
|
|
2598
|
-
}
|
|
2599
|
-
//#endregion
|
|
2600
|
-
//#region src/plugins/AutoFocusPlugin.tsx
|
|
2601
|
-
function AutoFocusPlugin() {
|
|
2602
|
-
const [editor] = useLexicalComposerContext();
|
|
2603
|
-
useEffect(() => {
|
|
2604
|
-
const root = editor.getRootElement();
|
|
2605
|
-
if (root) root.focus({ preventScroll: true });
|
|
2606
|
-
else editor.focus();
|
|
2607
|
-
}, [editor]);
|
|
2608
3034
|
return null;
|
|
2609
3035
|
}
|
|
2610
3036
|
//#endregion
|
|
@@ -2744,4 +3170,15 @@ function SubmitShortcutPlugin({ onSubmit }) {
|
|
|
2744
3170
|
return null;
|
|
2745
3171
|
}
|
|
2746
3172
|
//#endregion
|
|
2747
|
-
|
|
3173
|
+
//#region src/plugins/AutoFocusPlugin.tsx
|
|
3174
|
+
function AutoFocusPlugin() {
|
|
3175
|
+
const [editor] = useLexicalComposerContext();
|
|
3176
|
+
useEffect(() => {
|
|
3177
|
+
const root = editor.getRootElement();
|
|
3178
|
+
if (root) root.focus({ preventScroll: true });
|
|
3179
|
+
else editor.focus();
|
|
3180
|
+
}, [editor]);
|
|
3181
|
+
return null;
|
|
3182
|
+
}
|
|
3183
|
+
//#endregion
|
|
3184
|
+
export { BlockExitPlugin as $, ImageDialog as A, useImageUpload as B, createTextSelectionStore as C, ImageUploadPlugin as D, LinkFaviconPlugin as E, setFileUploadEntry as F, CorePlugins as G, useImagePreprocess as H, useFileUploadEntry as I, ALL_TRANSFORMERS as J, MarkdownShortcutsPlugin as K, VideoUploadProvider as L, registerImageEditor as M, resolvePreprocessTargets as N, defaultImageUpload as O, FileUploadPlugin as P, registerClickBelowCommand as Q, useVideoUpload as R, TextSelectionStoreProvider as S, useTextSelectionStore as T, FileUploadProvider as U, ImagePreprocessProvider as V, useFileUpload as W, HorizontalRulePlugin as X, InlineDndPlugin as Y, ClickBelowPlugin as Z, $getRootBlock as _, EditorRefPlugin as a, buildBlockAnchor as b, $captureTextSelection as c, createDOMRangeFromTextSelection as d, AutoLinkPlugin as et, findDOMPointByTextOffset as f, TEXT_SELECTION_HIGHLIGHT_NAME as g, getTextOffsetFromDOMPoint as h, FootnotePlugin as i, getImageEditor as j, presentImageDialog as k, $captureTextSelectionFromRangeSelection as l, getDOMRectFromTextSelection as m, SubmitShortcutPlugin as n, VideoUploadPlugin as o, getBlockElementById as p, MarkdownPastePlugin as q, OnChangePlugin as r, TextSelectionPlugin as s, AutoFocusPlugin as t, $restoreTextSelection as u, $getTextOffsetInBlock as v, useTextSelectionSnapshot as w, buildRangeAnchor as x, $resolveSelectionPoint as y, ImageUploadProvider as z };
|