@4399ywkf/editor 0.11.0 → 0.12.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/dist/{DocView-KUVYBQ66.js → DocView-5LI4KWEZ.js} +3 -3
- package/dist/{DocView-KUVYBQ66.js.map → DocView-5LI4KWEZ.js.map} +1 -1
- package/dist/{chunk-6MZAYCF6.js → chunk-SV3LH2TC.js} +229 -16
- package/dist/chunk-SV3LH2TC.js.map +1 -0
- package/dist/doc-standalone.js +225 -13
- package/dist/doc-standalone.js.map +1 -1
- package/dist/doc.d.ts +28 -6
- package/dist/doc.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +2 -1
- package/dist/chunk-6MZAYCF6.js.map +0 -1
package/dist/doc-standalone.js
CHANGED
|
@@ -82522,6 +82522,16 @@ function containerPasteText(data, slice2, schema) {
|
|
|
82522
82522
|
if (/\sdata-pm-slice=/.test(html)) return sliceLines(slice2, schema);
|
|
82523
82523
|
return text || null;
|
|
82524
82524
|
}
|
|
82525
|
+
function resolveMarkConflicts(nodes, schema) {
|
|
82526
|
+
return nodes.map((node) => {
|
|
82527
|
+
const out = { ...node };
|
|
82528
|
+
if (node.marks?.length) {
|
|
82529
|
+
out.marks = node.marks.reduce((set, json) => schema.markFromJSON(json).addToSet(set), Mark.none).map((mark) => mark.toJSON());
|
|
82530
|
+
}
|
|
82531
|
+
if (node.content) out.content = resolveMarkConflicts(node.content, schema);
|
|
82532
|
+
return out;
|
|
82533
|
+
});
|
|
82534
|
+
}
|
|
82525
82535
|
function isComposing(view, event) {
|
|
82526
82536
|
if (event?.isComposing) return true;
|
|
82527
82537
|
return Boolean(view.composing);
|
|
@@ -82558,20 +82568,26 @@ function createCodeGroupInputPlugin(editor) {
|
|
|
82558
82568
|
if (!text || !containsCompleteContainer(text)) return false;
|
|
82559
82569
|
const manager = editor.markdown;
|
|
82560
82570
|
if (!manager) return false;
|
|
82561
|
-
let
|
|
82571
|
+
let content;
|
|
82562
82572
|
try {
|
|
82563
|
-
json = manager.parse(text.replace(/\r\n?/g, "\n"));
|
|
82573
|
+
const json = manager.parse(text.replace(/\r\n?/g, "\n"));
|
|
82574
|
+
if (!json.content?.length) return false;
|
|
82575
|
+
content = resolveMarkConflicts(json.content, state.schema);
|
|
82564
82576
|
} catch {
|
|
82565
82577
|
return false;
|
|
82566
82578
|
}
|
|
82567
|
-
if (!json.content?.length) return false;
|
|
82568
82579
|
stopYjsCapturing(view.state);
|
|
82569
82580
|
view.dispatch(closeHistory(view.state.tr));
|
|
82570
|
-
|
|
82571
|
-
|
|
82572
|
-
|
|
82573
|
-
|
|
82574
|
-
|
|
82581
|
+
let inserted = false;
|
|
82582
|
+
try {
|
|
82583
|
+
inserted = editor.commands.insertContentAt(
|
|
82584
|
+
{ from: state.selection.from, to: state.selection.to },
|
|
82585
|
+
content,
|
|
82586
|
+
{ updateSelection: true }
|
|
82587
|
+
);
|
|
82588
|
+
} catch (error) {
|
|
82589
|
+
console.warn("Markdown 粘贴转换失败,按普通粘贴处理", error);
|
|
82590
|
+
}
|
|
82575
82591
|
stopYjsCapturing(view.state);
|
|
82576
82592
|
view.dispatch(closeHistory(view.state.tr));
|
|
82577
82593
|
return inserted;
|
|
@@ -96723,6 +96739,12 @@ function normalizeEditorContent(content, contentFormat, extensions, options = {}
|
|
|
96723
96739
|
}
|
|
96724
96740
|
return result.json;
|
|
96725
96741
|
}
|
|
96742
|
+
function resolveEditorContentUpdate(content, contentFormat, extensions, options = {}) {
|
|
96743
|
+
if (content === void 0) return { kind: "ignore" };
|
|
96744
|
+
if (content === null || content === "") return { kind: "clear" };
|
|
96745
|
+
const json = normalizeEditorContent(content, contentFormat, extensions, options);
|
|
96746
|
+
return json ? { kind: "set", json } : { kind: "ignore" };
|
|
96747
|
+
}
|
|
96726
96748
|
function defaultOnError(message) {
|
|
96727
96749
|
console.error(`[editor] 内容未载入:${message}`);
|
|
96728
96750
|
}
|
|
@@ -118174,6 +118196,29 @@ function createRichMarkdownExtensions() {
|
|
|
118174
118196
|
return { MarkdownParagraph, MarkdownHeading };
|
|
118175
118197
|
}
|
|
118176
118198
|
|
|
118199
|
+
// src/lib/im-input.ts
|
|
118200
|
+
function createMessageInputKeyHandler({
|
|
118201
|
+
getEditor,
|
|
118202
|
+
getSendKey,
|
|
118203
|
+
onSend
|
|
118204
|
+
}) {
|
|
118205
|
+
return (view, event) => {
|
|
118206
|
+
if (!onSend || event.defaultPrevented || event.isComposing || event.keyCode === 229 || view.composing) {
|
|
118207
|
+
return false;
|
|
118208
|
+
}
|
|
118209
|
+
const editor = getEditor();
|
|
118210
|
+
if (!editor || editor.isDestroyed || !editor.isEditable) return false;
|
|
118211
|
+
if (event.key !== "Enter" || event.shiftKey || event.altKey) return false;
|
|
118212
|
+
const modifier = event.metaKey || event.ctrlKey;
|
|
118213
|
+
const sendKey = getSendKey();
|
|
118214
|
+
const shouldSend = sendKey === "enter" ? !modifier : sendKey === "mod-enter" ? modifier : false;
|
|
118215
|
+
if (!shouldSend) return false;
|
|
118216
|
+
event.preventDefault();
|
|
118217
|
+
onSend(editor);
|
|
118218
|
+
return true;
|
|
118219
|
+
};
|
|
118220
|
+
}
|
|
118221
|
+
|
|
118177
118222
|
// ../../node_modules/.pnpm/@tiptap+extension-highlight@3.30.0_@tiptap+core@3.30.0_@tiptap+pm@3.30.0_/node_modules/@tiptap/extension-highlight/dist/index.js
|
|
118178
118223
|
var inputRegex6 = /(?:^|\s)(==(?!\s+==)((?:[^=]+))==(?!\s+==))$/;
|
|
118179
118224
|
var pasteRegex3 = /(?:^|\s)(==(?!\s+==)((?:[^=]+))==(?!\s+==))/g;
|
|
@@ -118287,9 +118332,112 @@ var FeishuStrike = Strike.extend({
|
|
|
118287
118332
|
return { "Mod-Shift-x": () => this.editor.commands.toggleStrike() };
|
|
118288
118333
|
}
|
|
118289
118334
|
});
|
|
118335
|
+
function partialLinkRuns(block, start, code, link) {
|
|
118336
|
+
const out = [];
|
|
118337
|
+
let from2 = -1;
|
|
118338
|
+
let to = -1;
|
|
118339
|
+
let links = [];
|
|
118340
|
+
const flush = () => {
|
|
118341
|
+
const first2 = links[0];
|
|
118342
|
+
if (from2 >= 0 && links.some(Boolean) && !links.every((m) => m && first2 && m.eq(first2))) {
|
|
118343
|
+
out.push([from2, to]);
|
|
118344
|
+
}
|
|
118345
|
+
from2 = -1;
|
|
118346
|
+
links = [];
|
|
118347
|
+
};
|
|
118348
|
+
block.forEach((child, offset9) => {
|
|
118349
|
+
if (!child.isText || !code.isInSet(child.marks)) {
|
|
118350
|
+
flush();
|
|
118351
|
+
return;
|
|
118352
|
+
}
|
|
118353
|
+
if (from2 < 0) from2 = start + offset9;
|
|
118354
|
+
to = start + offset9 + child.nodeSize;
|
|
118355
|
+
links.push(link.isInSet(child.marks));
|
|
118356
|
+
});
|
|
118357
|
+
flush();
|
|
118358
|
+
return out;
|
|
118359
|
+
}
|
|
118360
|
+
function inlineCodeLinkPlugin() {
|
|
118361
|
+
return new Plugin({
|
|
118362
|
+
key: new PluginKey("inlineCodeLink"),
|
|
118363
|
+
appendTransaction(transactions, oldState, newState) {
|
|
118364
|
+
const { code, link } = newState.schema.marks;
|
|
118365
|
+
if (!code || !link || !transactions.some((tr3) => tr3.docChanged)) return null;
|
|
118366
|
+
const changed = getChangedRanges(combineTransactionSteps(oldState.doc, [...transactions]));
|
|
118367
|
+
const seen = /* @__PURE__ */ new Set();
|
|
118368
|
+
const ranges = [];
|
|
118369
|
+
for (const { newRange } of changed) {
|
|
118370
|
+
newState.doc.nodesBetween(newRange.from, newRange.to, (node, pos) => {
|
|
118371
|
+
if (!node.isTextblock) return true;
|
|
118372
|
+
if (!seen.has(pos)) {
|
|
118373
|
+
seen.add(pos);
|
|
118374
|
+
ranges.push(...partialLinkRuns(node, pos + 1, code, link));
|
|
118375
|
+
}
|
|
118376
|
+
return false;
|
|
118377
|
+
});
|
|
118378
|
+
}
|
|
118379
|
+
if (!ranges.length) return null;
|
|
118380
|
+
const tr2 = newState.tr;
|
|
118381
|
+
for (const [from2, to] of ranges) tr2.removeMark(from2, to, link);
|
|
118382
|
+
return tr2;
|
|
118383
|
+
}
|
|
118384
|
+
});
|
|
118385
|
+
}
|
|
118290
118386
|
var FeishuCode = Code.extend({
|
|
118387
|
+
excludes: "bold italic underline strike textStyle highlight superscript subscript code",
|
|
118291
118388
|
addKeyboardShortcuts() {
|
|
118292
118389
|
return { [isMac5() ? "Mod-Ctrl-c" : "Ctrl-Shift-c"]: () => this.editor.commands.toggleCode() };
|
|
118390
|
+
},
|
|
118391
|
+
addProseMirrorPlugins() {
|
|
118392
|
+
return [...this.parent?.() ?? [], inlineCodeLinkPlugin()];
|
|
118393
|
+
}
|
|
118394
|
+
});
|
|
118395
|
+
function selectionIsAllCode(state) {
|
|
118396
|
+
const { code } = state.schema.marks;
|
|
118397
|
+
const { from: from2, to, empty: empty2 } = state.selection;
|
|
118398
|
+
if (!code || empty2) return false;
|
|
118399
|
+
let hasText = false;
|
|
118400
|
+
let allCode = true;
|
|
118401
|
+
state.doc.nodesBetween(from2, to, (node) => {
|
|
118402
|
+
if (!node.isText) return true;
|
|
118403
|
+
hasText = true;
|
|
118404
|
+
if (!code.isInSet(node.marks)) allCode = false;
|
|
118405
|
+
return false;
|
|
118406
|
+
});
|
|
118407
|
+
return hasText && allCode;
|
|
118408
|
+
}
|
|
118409
|
+
var FeishuLink = Link.extend({
|
|
118410
|
+
addPasteRules() {
|
|
118411
|
+
return (this.parent?.() ?? []).map(
|
|
118412
|
+
(rule) => new PasteRule({
|
|
118413
|
+
find: rule.find,
|
|
118414
|
+
handler: (props) => {
|
|
118415
|
+
const { code } = props.state.schema.marks;
|
|
118416
|
+
if (code && props.state.doc.rangeHasMark(props.range.from, props.range.to, code)) {
|
|
118417
|
+
return null;
|
|
118418
|
+
}
|
|
118419
|
+
return rule.handler(props);
|
|
118420
|
+
}
|
|
118421
|
+
})
|
|
118422
|
+
);
|
|
118423
|
+
},
|
|
118424
|
+
// Link 的插件里只有「选中文字后粘贴网址 → 给选区加链接」这一个有 handlePaste。选中的全是行内代码时
|
|
118425
|
+
// 跳过它,按普通粘贴替换文字(放开链接之前就是这样),不给代码挂一个看不出来的链接
|
|
118426
|
+
addProseMirrorPlugins() {
|
|
118427
|
+
return (this.parent?.() ?? []).map((plugin) => {
|
|
118428
|
+
const handlePaste2 = plugin.props.handlePaste;
|
|
118429
|
+
if (!handlePaste2) return plugin;
|
|
118430
|
+
return new Plugin({
|
|
118431
|
+
...plugin.spec,
|
|
118432
|
+
props: {
|
|
118433
|
+
...plugin.spec.props,
|
|
118434
|
+
handlePaste(view, event, slice2) {
|
|
118435
|
+
if (selectionIsAllCode(view.state)) return false;
|
|
118436
|
+
return handlePaste2.call(this, view, event, slice2);
|
|
118437
|
+
}
|
|
118438
|
+
}
|
|
118439
|
+
});
|
|
118440
|
+
});
|
|
118293
118441
|
}
|
|
118294
118442
|
});
|
|
118295
118443
|
var FeishuBlockquote = Blockquote.extend({
|
|
@@ -118760,6 +118908,11 @@ function EditorProvider(props) {
|
|
|
118760
118908
|
hideFloatingToolbar = false,
|
|
118761
118909
|
embedded = false,
|
|
118762
118910
|
richMarkdown = false,
|
|
118911
|
+
sendKey,
|
|
118912
|
+
onSend,
|
|
118913
|
+
onUpdate,
|
|
118914
|
+
onSelectionUpdate,
|
|
118915
|
+
onEditorDestroy,
|
|
118763
118916
|
onEditorReady,
|
|
118764
118917
|
extensions: extraExtensions,
|
|
118765
118918
|
pageHeader = false,
|
|
@@ -118786,6 +118939,16 @@ function EditorProvider(props) {
|
|
|
118786
118939
|
return found2;
|
|
118787
118940
|
}, []);
|
|
118788
118941
|
const editorConfig = useEditorConfig();
|
|
118942
|
+
const onSendRef = useRef(onSend);
|
|
118943
|
+
onSendRef.current = onSend;
|
|
118944
|
+
const sendKeyRef = useRef(sendKey);
|
|
118945
|
+
sendKeyRef.current = sendKey;
|
|
118946
|
+
const onUpdateRef = useRef(onUpdate);
|
|
118947
|
+
onUpdateRef.current = onUpdate;
|
|
118948
|
+
const onSelectionUpdateRef = useRef(onSelectionUpdate);
|
|
118949
|
+
onSelectionUpdateRef.current = onSelectionUpdate;
|
|
118950
|
+
const onEditorDestroyRef = useRef(onEditorDestroy);
|
|
118951
|
+
onEditorDestroyRef.current = onEditorDestroy;
|
|
118789
118952
|
const [mathBus] = useState(createMathEditBus);
|
|
118790
118953
|
const onUpload = editorConfig?.upload?.onUpload ?? handleImageUpload;
|
|
118791
118954
|
const onUploadError = editorConfig?.upload?.onError ?? // 宿主没给 onError 时按飞书弹提示(「上传图片大小不能超过 20 MB」「图片格式仅支持 …」等)
|
|
@@ -118815,7 +118978,8 @@ function EditorProvider(props) {
|
|
|
118815
118978
|
dropcursor: {
|
|
118816
118979
|
width: 2
|
|
118817
118980
|
},
|
|
118818
|
-
|
|
118981
|
+
// 换成粘贴规则跳过行内代码的版本(feishu-keymap 的 FeishuLink)
|
|
118982
|
+
link: false
|
|
118819
118983
|
}),
|
|
118820
118984
|
...richMarkdownExtensions ? [richMarkdownExtensions.MarkdownParagraph] : [],
|
|
118821
118985
|
// 代码块 / 分组 / 高亮 / Markdown / 直接输入:顺序固定,且在协同与 UniqueID 之前
|
|
@@ -118834,6 +118998,7 @@ function EditorProvider(props) {
|
|
|
118834
118998
|
richMarkdownExtensions ? richMarkdownExtensions.MarkdownHeading : Heading2,
|
|
118835
118999
|
FeishuStrike,
|
|
118836
119000
|
FeishuCode,
|
|
119001
|
+
FeishuLink.configure({ openOnClick: false }),
|
|
118837
119002
|
FeishuBlockquote,
|
|
118838
119003
|
// ⌘⌥S 分割线、⌘⌥H 套用上次颜色、Alt+C 切换待办(规格 §33)
|
|
118839
119004
|
FeishuKeymap,
|
|
@@ -119050,6 +119215,14 @@ function EditorProvider(props) {
|
|
|
119050
119215
|
const [initialContent] = useState(
|
|
119051
119216
|
() => provider ? void 0 : normalizeEditorContent(content, contentFormat, extensions) ?? void 0
|
|
119052
119217
|
);
|
|
119218
|
+
const messageInputKeyHandler = useMemo(
|
|
119219
|
+
() => createMessageInputKeyHandler({
|
|
119220
|
+
getEditor: () => editorRef.current,
|
|
119221
|
+
getSendKey: () => sendKeyRef.current,
|
|
119222
|
+
onSend: (current) => onSendRef.current?.(current)
|
|
119223
|
+
}),
|
|
119224
|
+
[]
|
|
119225
|
+
);
|
|
119053
119226
|
const editor = useEditor({
|
|
119054
119227
|
immediatelyRender: false,
|
|
119055
119228
|
// 只读模式:禁用编辑。扩展集保持不变,自定义节点仍走各自 NodeView 渲染
|
|
@@ -119059,10 +119232,18 @@ function EditorProvider(props) {
|
|
|
119059
119232
|
editorProps: {
|
|
119060
119233
|
attributes: {
|
|
119061
119234
|
class: "notion-like-editor"
|
|
119062
|
-
}
|
|
119235
|
+
},
|
|
119236
|
+
handleKeyDown: messageInputKeyHandler
|
|
119237
|
+
},
|
|
119238
|
+
onUpdate: ({ editor: current }) => onUpdateRef.current?.(current),
|
|
119239
|
+
onSelectionUpdate: ({ editor: current }) => onSelectionUpdateRef.current?.(current),
|
|
119240
|
+
onDestroy: () => {
|
|
119241
|
+
const current = editorRef.current;
|
|
119242
|
+
if (current) onEditorDestroyRef.current?.(current);
|
|
119063
119243
|
},
|
|
119064
119244
|
extensions
|
|
119065
119245
|
});
|
|
119246
|
+
editorRef.current = editor;
|
|
119066
119247
|
useEffect(() => {
|
|
119067
119248
|
if (!editor) return;
|
|
119068
119249
|
editorRef.current = editor;
|
|
@@ -119096,9 +119277,20 @@ function EditorProvider(props) {
|
|
|
119096
119277
|
useEffect(() => {
|
|
119097
119278
|
if (provider) return;
|
|
119098
119279
|
if (!editor) return;
|
|
119099
|
-
|
|
119100
|
-
|
|
119101
|
-
if (
|
|
119280
|
+
const update = resolveEditorContentUpdate(content, contentFormat, editor.extensionManager.extensions);
|
|
119281
|
+
if (update.kind === "ignore") return;
|
|
119282
|
+
if (update.kind === "clear") {
|
|
119283
|
+
if (editor.isEmpty) return;
|
|
119284
|
+
let cancelled2 = false;
|
|
119285
|
+
queueMicrotask(() => {
|
|
119286
|
+
if (cancelled2 || editor.isDestroyed) return;
|
|
119287
|
+
editor.commands.clearContent(false);
|
|
119288
|
+
});
|
|
119289
|
+
return () => {
|
|
119290
|
+
cancelled2 = true;
|
|
119291
|
+
};
|
|
119292
|
+
}
|
|
119293
|
+
const next = update.json;
|
|
119102
119294
|
if (isSameDocument(editor.getJSON(), next)) return;
|
|
119103
119295
|
let cancelled = false;
|
|
119104
119296
|
queueMicrotask(() => {
|
|
@@ -119214,6 +119406,11 @@ function NotionEditor({
|
|
|
119214
119406
|
hideFloatingToolbar = false,
|
|
119215
119407
|
embedded = false,
|
|
119216
119408
|
richMarkdown = false,
|
|
119409
|
+
sendKey,
|
|
119410
|
+
onSend,
|
|
119411
|
+
onUpdate,
|
|
119412
|
+
onSelectionUpdate,
|
|
119413
|
+
onEditorDestroy,
|
|
119217
119414
|
onEditorReady,
|
|
119218
119415
|
extensions,
|
|
119219
119416
|
pageHeader,
|
|
@@ -119241,6 +119438,11 @@ function NotionEditor({
|
|
|
119241
119438
|
hideFloatingToolbar,
|
|
119242
119439
|
embedded,
|
|
119243
119440
|
richMarkdown,
|
|
119441
|
+
sendKey,
|
|
119442
|
+
onSend,
|
|
119443
|
+
onUpdate,
|
|
119444
|
+
onSelectionUpdate,
|
|
119445
|
+
onEditorDestroy,
|
|
119244
119446
|
onEditorReady,
|
|
119245
119447
|
extensions,
|
|
119246
119448
|
pageHeader,
|
|
@@ -119265,6 +119467,11 @@ function NotionEditorContent({
|
|
|
119265
119467
|
hideFloatingToolbar = false,
|
|
119266
119468
|
embedded = false,
|
|
119267
119469
|
richMarkdown = false,
|
|
119470
|
+
sendKey,
|
|
119471
|
+
onSend,
|
|
119472
|
+
onUpdate,
|
|
119473
|
+
onSelectionUpdate,
|
|
119474
|
+
onEditorDestroy,
|
|
119268
119475
|
onEditorReady,
|
|
119269
119476
|
extensions,
|
|
119270
119477
|
pageHeader,
|
|
@@ -119297,6 +119504,11 @@ function NotionEditorContent({
|
|
|
119297
119504
|
hideFloatingToolbar,
|
|
119298
119505
|
embedded,
|
|
119299
119506
|
richMarkdown,
|
|
119507
|
+
sendKey,
|
|
119508
|
+
onSend,
|
|
119509
|
+
onUpdate,
|
|
119510
|
+
onSelectionUpdate,
|
|
119511
|
+
onEditorDestroy,
|
|
119300
119512
|
onEditorReady,
|
|
119301
119513
|
extensions,
|
|
119302
119514
|
pageHeader,
|