@4399ywkf/editor 0.10.2 → 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.
@@ -5,9 +5,9 @@ import * as React from 'react';
5
5
  import { createContext, memo, forwardRef, useState, useCallback, useRef, useEffect, useMemo, lazy, useLayoutEffect, Suspense, useContext, useReducer, Children, isValidElement, cloneElement } from 'react';
6
6
  import { jsxs, jsx, Fragment as Fragment$1 } from 'react/jsx-runtime';
7
7
  import { createPortal } from 'react-dom';
8
- import { Extension, Node as Node$2, mergeAttributes as mergeAttributes$1, textblockTypeInputRule, InputRule, getChangedRanges, getTextSerializersFromSchema, generateJSON, generateHTML } from '@tiptap/core';
8
+ import { Extension, Node as Node$2, mergeAttributes as mergeAttributes$1, textblockTypeInputRule, InputRule, PasteRule, getChangedRanges, combineTransactionSteps, getTextSerializersFromSchema, getTextBetween, generateJSON, generateHTML } from '@tiptap/core';
9
9
  import { isChangeOrigin, Collaboration } from '@tiptap/extension-collaboration';
10
- import { Fragment, Slice, Mark } from '@tiptap/pm/model';
10
+ import { Fragment, Slice, Mark, DOMSerializer } from '@tiptap/pm/model';
11
11
  import { PluginKey, Plugin, TextSelection, Selection, NodeSelection, SelectionRange } from '@tiptap/pm/state';
12
12
  import { createGlobalStyle, useTheme } from 'antd-style';
13
13
  import { serialize, compile, stringify } from 'stylis';
@@ -50,9 +50,11 @@ import '@base-ui/react/use-render';
50
50
  import { cva } from 'class-variance-authority';
51
51
  import { exitSuggestion, SuggestionPluginKey, Suggestion } from '@tiptap/suggestion';
52
52
  import { DragHandle } from '@tiptap/extension-drag-handle-react';
53
+ import { Paragraph } from '@tiptap/extension-paragraph';
53
54
  import { Blockquote } from '@tiptap/extension-blockquote';
54
55
  import { Code } from '@tiptap/extension-code';
55
56
  import { Highlight } from '@tiptap/extension-highlight';
57
+ import { Link } from '@tiptap/extension-link';
56
58
  import { Strike } from '@tiptap/extension-strike';
57
59
 
58
60
  var DEFAULT_MAX_FILE_SIZES = {
@@ -9925,7 +9927,7 @@ var paragraphNodeStyles = ({ isDark }) => `
9925
9927
  .is-empty.with-slash[data-placeholder]:has(
9926
9928
  > .ProseMirror-trailingBreak:only-child
9927
9929
  )::before {
9928
- content: "Write, type '/' for commands…";
9930
+ content: attr(data-placeholder);
9929
9931
  font-style: italic;
9930
9932
  }
9931
9933
 
@@ -13684,7 +13686,7 @@ function getAnchorNodeAndPos(editor, allowEmptySelection = true) {
13684
13686
  return { node, pos };
13685
13687
  }
13686
13688
  function getEditorExtension(editor, extensionName) {
13687
- if (!editor) return null;
13689
+ if (!editor || editor.isDestroyed || !editor.extensionManager) return null;
13688
13690
  const extension = editor.extensionManager.extensions.find(
13689
13691
  (ext) => ext.name === extensionName
13690
13692
  );
@@ -21173,7 +21175,7 @@ function useScrollToHash(config = {}) {
21173
21175
  onTargetNotFoundRef.current = onTargetNotFound;
21174
21176
  const scrollToNode = useCallback(
21175
21177
  (hash) => {
21176
- if (!editor) return false;
21178
+ if (!editor || editor.isDestroyed) return false;
21177
21179
  const attributeName = getEditorExtension(editor, "uniqueID")?.options?.attributeName ?? "data-id";
21178
21180
  const anchor2 = parseAnchorHash(hash);
21179
21181
  if (!anchor2) return false;
@@ -22420,67 +22422,74 @@ var NodeAlignment = Extension.create({
22420
22422
  types: ["paragraph", "heading", "blockquote", "tableCell", "tableHeader"],
22421
22423
  useStyle: true,
22422
22424
  textAlignValues: ["left", "center", "right", "justify"],
22423
- verticalAlignValues: ["top", "middle", "bottom"]
22425
+ verticalAlignValues: ["top", "middle", "bottom"],
22426
+ textAlignHandledTypes: []
22424
22427
  };
22425
22428
  },
22426
22429
  addGlobalAttributes() {
22430
+ const attributes = {
22431
+ nodeTextAlign: {
22432
+ default: null,
22433
+ parseHTML: (element) => {
22434
+ const styleAlign = element.style?.textAlign;
22435
+ if (styleAlign && this.options.textAlignValues.includes(styleAlign)) {
22436
+ return styleAlign;
22437
+ }
22438
+ const dataAlign = element.getAttribute("data-node-text-align");
22439
+ if (dataAlign && this.options.textAlignValues.includes(dataAlign)) {
22440
+ return dataAlign;
22441
+ }
22442
+ return null;
22443
+ },
22444
+ renderHTML: (attributes2) => {
22445
+ const align = attributes2.nodeTextAlign;
22446
+ if (!align || !this.options.textAlignValues.includes(align))
22447
+ return {};
22448
+ if (this.options.useStyle) {
22449
+ return { style: `text-align: ${align}` };
22450
+ } else {
22451
+ return { "data-node-text-align": align };
22452
+ }
22453
+ }
22454
+ },
22455
+ nodeVerticalAlign: {
22456
+ default: null,
22457
+ parseHTML: (element) => {
22458
+ const styleVAlign = element.style?.verticalAlign;
22459
+ if (styleVAlign && this.options.verticalAlignValues.includes(styleVAlign)) {
22460
+ return styleVAlign;
22461
+ }
22462
+ const dataVAlign = element.getAttribute(
22463
+ "data-node-vertical-align"
22464
+ );
22465
+ if (dataVAlign && this.options.verticalAlignValues.includes(dataVAlign)) {
22466
+ return dataVAlign;
22467
+ }
22468
+ return null;
22469
+ },
22470
+ renderHTML: (attributes2) => {
22471
+ const vAlign = attributes2.nodeVerticalAlign;
22472
+ if (!vAlign || !this.options.verticalAlignValues.includes(vAlign))
22473
+ return {};
22474
+ if (this.options.useStyle) {
22475
+ return { style: `vertical-align: ${vAlign}` };
22476
+ } else {
22477
+ return { "data-node-vertical-align": vAlign };
22478
+ }
22479
+ }
22480
+ }
22481
+ };
22482
+ const handled = new Set(this.options.textAlignHandledTypes);
22427
22483
  return [
22484
+ { types: this.options.types.filter((type) => !handled.has(type)), attributes },
22428
22485
  {
22429
- types: this.options.types,
22486
+ types: this.options.types.filter((type) => handled.has(type)),
22430
22487
  attributes: {
22431
- nodeTextAlign: {
22432
- default: null,
22433
- parseHTML: (element) => {
22434
- const styleAlign = element.style?.textAlign;
22435
- if (styleAlign && this.options.textAlignValues.includes(styleAlign)) {
22436
- return styleAlign;
22437
- }
22438
- const dataAlign = element.getAttribute("data-node-text-align");
22439
- if (dataAlign && this.options.textAlignValues.includes(dataAlign)) {
22440
- return dataAlign;
22441
- }
22442
- return null;
22443
- },
22444
- renderHTML: (attributes) => {
22445
- const align = attributes.nodeTextAlign;
22446
- if (!align || !this.options.textAlignValues.includes(align))
22447
- return {};
22448
- if (this.options.useStyle) {
22449
- return { style: `text-align: ${align}` };
22450
- } else {
22451
- return { "data-node-text-align": align };
22452
- }
22453
- }
22454
- },
22455
- nodeVerticalAlign: {
22456
- default: null,
22457
- parseHTML: (element) => {
22458
- const styleVAlign = element.style?.verticalAlign;
22459
- if (styleVAlign && this.options.verticalAlignValues.includes(styleVAlign)) {
22460
- return styleVAlign;
22461
- }
22462
- const dataVAlign = element.getAttribute(
22463
- "data-node-vertical-align"
22464
- );
22465
- if (dataVAlign && this.options.verticalAlignValues.includes(dataVAlign)) {
22466
- return dataVAlign;
22467
- }
22468
- return null;
22469
- },
22470
- renderHTML: (attributes) => {
22471
- const vAlign = attributes.nodeVerticalAlign;
22472
- if (!vAlign || !this.options.verticalAlignValues.includes(vAlign))
22473
- return {};
22474
- if (this.options.useStyle) {
22475
- return { style: `vertical-align: ${vAlign}` };
22476
- } else {
22477
- return { "data-node-vertical-align": vAlign };
22478
- }
22479
- }
22480
- }
22488
+ ...attributes,
22489
+ nodeTextAlign: { default: null, parseHTML: () => null, renderHTML: () => ({}) }
22481
22490
  }
22482
22491
  }
22483
- ];
22492
+ ].filter((group) => group.types.length > 0);
22484
22493
  },
22485
22494
  addCommands() {
22486
22495
  const executeAlignmentCommand = (attributeName, getTargetValue) => {
@@ -26564,6 +26573,43 @@ function convertCodeGroupDraft(view, draft) {
26564
26573
  dispatchAsOwnUndoStep(view, tr.scrollIntoView());
26565
26574
  return true;
26566
26575
  }
26576
+ function isPlainLineSlice(slice) {
26577
+ if (slice.content.childCount === 0) return false;
26578
+ let plain = true;
26579
+ slice.content.descendants((node) => {
26580
+ if (!plain) return false;
26581
+ if (node.isInline || node.type.name === "paragraph") return true;
26582
+ plain = false;
26583
+ return false;
26584
+ });
26585
+ return plain;
26586
+ }
26587
+ function sliceLines(slice, schema) {
26588
+ const container = schema.topNodeType.create(null, slice.content);
26589
+ return getTextBetween(
26590
+ container,
26591
+ { from: 0, to: container.content.size },
26592
+ { blockSeparator: "\n", textSerializers: getTextSerializersFromSchema(schema) }
26593
+ );
26594
+ }
26595
+ function containerPasteText(data, slice, schema) {
26596
+ const text = data.getData("text/plain");
26597
+ const html = data.getData("text/html");
26598
+ if (!html) return text || null;
26599
+ if (!isPlainLineSlice(slice)) return null;
26600
+ if (/\sdata-pm-slice=/.test(html)) return sliceLines(slice, schema);
26601
+ return text || null;
26602
+ }
26603
+ function resolveMarkConflicts(nodes, schema) {
26604
+ return nodes.map((node) => {
26605
+ const out = { ...node };
26606
+ if (node.marks?.length) {
26607
+ out.marks = node.marks.reduce((set, json) => schema.markFromJSON(json).addToSet(set), Mark.none).map((mark) => mark.toJSON());
26608
+ }
26609
+ if (node.content) out.content = resolveMarkConflicts(node.content, schema);
26610
+ return out;
26611
+ });
26612
+ }
26567
26613
  function isComposing(view, event) {
26568
26614
  if (event?.isComposing) return true;
26569
26615
  return Boolean(view.composing);
@@ -26590,31 +26636,36 @@ function createCodeGroupInputPlugin(editor) {
26590
26636
  }
26591
26637
  return editor.commands.splitBlock();
26592
26638
  },
26593
- handlePaste(view, event) {
26639
+ handlePaste(view, event, slice) {
26594
26640
  const { state } = view;
26595
26641
  if (state.selection.$from.parent.type.name === "codeBlock") return false;
26596
26642
  const data = event.clipboardData;
26597
26643
  if (!data) return false;
26598
26644
  if (view.input?.shiftKey) return false;
26599
- if (data.getData("text/html")) return false;
26600
- const text = data.getData("text/plain");
26645
+ const text = containerPasteText(data, slice, state.schema);
26601
26646
  if (!text || !containsCompleteContainer(text)) return false;
26602
26647
  const manager = editor.markdown;
26603
26648
  if (!manager) return false;
26604
- let json;
26649
+ let content;
26605
26650
  try {
26606
- json = manager.parse(text.replace(/\r\n?/g, "\n"));
26651
+ const json = manager.parse(text.replace(/\r\n?/g, "\n"));
26652
+ if (!json.content?.length) return false;
26653
+ content = resolveMarkConflicts(json.content, state.schema);
26607
26654
  } catch {
26608
26655
  return false;
26609
26656
  }
26610
- if (!json.content?.length) return false;
26611
26657
  stopYjsCapturing(view.state);
26612
26658
  view.dispatch(closeHistory(view.state.tr));
26613
- const inserted = editor.commands.insertContentAt(
26614
- { from: state.selection.from, to: state.selection.to },
26615
- json.content,
26616
- { updateSelection: true }
26617
- );
26659
+ let inserted = false;
26660
+ try {
26661
+ inserted = editor.commands.insertContentAt(
26662
+ { from: state.selection.from, to: state.selection.to },
26663
+ content,
26664
+ { updateSelection: true }
26665
+ );
26666
+ } catch (error) {
26667
+ console.warn("Markdown 粘贴转换失败,按普通粘贴处理", error);
26668
+ }
26618
26669
  stopYjsCapturing(view.state);
26619
26670
  view.dispatch(closeHistory(view.state.tr));
26620
26671
  return inserted;
@@ -33675,6 +33726,12 @@ function normalizeEditorContent(content, contentFormat, extensions, options = {}
33675
33726
  }
33676
33727
  return result.json;
33677
33728
  }
33729
+ function resolveEditorContentUpdate(content, contentFormat, extensions, options = {}) {
33730
+ if (content === void 0) return { kind: "ignore" };
33731
+ if (content === null || content === "") return { kind: "clear" };
33732
+ const json = normalizeEditorContent(content, contentFormat, extensions, options);
33733
+ return json ? { kind: "set", json } : { kind: "ignore" };
33734
+ }
33678
33735
  function defaultOnError(message) {
33679
33736
  console.error(`[editor] 内容未载入:${message}`);
33680
33737
  }
@@ -50624,15 +50681,233 @@ var Indent = Extension.create({
50624
50681
  };
50625
50682
  }
50626
50683
  });
50684
+ var SAFE_COLOR = /^(#[0-9a-f]{3,8}|rgba?\([\d\s.,%]+\)|hsla?\([\d\s.,%deg]+\)|[a-z]{3,20})$/i;
50685
+ var HTML_ONLY_MARKS = /* @__PURE__ */ new Set(["textStyle", "highlight", "underline", "superscript", "subscript"]);
50686
+ function markdownColor(value) {
50687
+ if (typeof value !== "string") return null;
50688
+ const resolved = resolveColorToHex(value);
50689
+ if (resolved) return resolved;
50690
+ const trimmed = value.trim();
50691
+ return SAFE_COLOR.test(trimmed) ? trimmed : null;
50692
+ }
50693
+ function escapeMarkdownAttribute(value) {
50694
+ return value.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
50695
+ }
50696
+ function blockStyles(attrs) {
50697
+ const align = ["center", "right"].includes(String(attrs?.textAlign)) ? String(attrs?.textAlign) : null;
50698
+ const indent = Math.max(0, Math.min(30, Math.trunc(Number(attrs?.indent) || 0)));
50699
+ const background = markdownColor(attrs?.backgroundColor);
50700
+ return [
50701
+ align ? `text-align: ${align}` : null,
50702
+ indent ? `margin-left: ${indent * 24}px` : null,
50703
+ background ? `background-color: ${background}` : null
50704
+ ].filter((style) => Boolean(style));
50705
+ }
50706
+ function hasHtmlOnlyMark(content) {
50707
+ return (content ?? []).some(
50708
+ (child) => child.marks?.some((mark) => HTML_ONLY_MARKS.has(mark.type)) || hasHtmlOnlyMark(child.content)
50709
+ );
50710
+ }
50711
+ function hasSignificantWhitespace(content) {
50712
+ const text = (content ?? []).map((child) => child.text ?? "").join("");
50713
+ return /\s{2}|^\s|\s$|\t/.test(text);
50714
+ }
50715
+ function needsHtmlBlock(node) {
50716
+ return blockStyles(node.attrs).length > 0 || hasHtmlOnlyMark(node.content);
50717
+ }
50718
+ function serializeInlineHTML(node, schema) {
50719
+ if (!schema || typeof document === "undefined") return null;
50720
+ try {
50721
+ const pmNode = schema.nodeFromJSON(node);
50722
+ const container = document.createElement("div");
50723
+ container.appendChild(
50724
+ DOMSerializer.fromSchema(schema).serializeFragment(pmNode.content, { document })
50725
+ );
50726
+ return container.innerHTML.replace(/\n/g, "&#10;");
50727
+ } catch {
50728
+ return null;
50729
+ }
50730
+ }
50731
+ function htmlBlock(node, tag, inner, extraAttrs = {}) {
50732
+ const styles = blockStyles(node.attrs);
50733
+ if (hasSignificantWhitespace(node.content)) styles.push("white-space: pre-wrap");
50734
+ const attrs = Object.entries(extraAttrs).map(
50735
+ ([key, value]) => ` ${key}="${escapeMarkdownAttribute(value)}"`
50736
+ );
50737
+ if (styles.length) attrs.push(` style="${escapeMarkdownAttribute(styles.join("; "))}"`);
50738
+ return `<${tag}${attrs.join("")}>${inner}</${tag}>`;
50739
+ }
50740
+ function createRichMarkdownExtensions() {
50741
+ const ref = { schema: null };
50742
+ const MarkdownParagraph = Paragraph.extend({
50743
+ onBeforeCreate() {
50744
+ ref.schema = this.editor.schema;
50745
+ },
50746
+ renderMarkdown(node, helpers, context) {
50747
+ const renderBase = Paragraph.config.renderMarkdown;
50748
+ if (!needsHtmlBlock(node)) return renderBase(node, helpers, context);
50749
+ const inner = serializeInlineHTML(node, ref.schema);
50750
+ return inner === null ? renderBase(node, helpers, context) : htmlBlock(node, "p", inner);
50751
+ }
50752
+ });
50753
+ const MarkdownHeading = Heading.extend({
50754
+ // extend() 会把 Heading 的 config 拷进来:不覆写的话,拷过来的函数里 `...this.parent()` 又调一遍
50755
+ // Heading 自己的同一个函数,数组被加两份(headingNumbering 是带 key 的插件,直接抛错)
50756
+ addExtensions() {
50757
+ return this.parent?.() ?? [];
50758
+ },
50759
+ addInputRules() {
50760
+ return this.parent?.() ?? [];
50761
+ },
50762
+ addProseMirrorPlugins() {
50763
+ return this.parent?.() ?? [];
50764
+ },
50765
+ renderMarkdown(node, helpers, context) {
50766
+ const renderBase = Heading.config.renderMarkdown;
50767
+ const level = Math.min(9, Math.max(1, Math.trunc(Number(node.attrs?.level) || 1)));
50768
+ if (level <= 6 && !needsHtmlBlock(node)) return renderBase(node, helpers, context);
50769
+ const inner = serializeInlineHTML(node, ref.schema);
50770
+ if (inner === null) return renderBase(node, helpers, context);
50771
+ return level <= 6 ? htmlBlock(node, `h${level}`, inner) : htmlBlock(node, "div", inner, { "data-heading-level": String(level) });
50772
+ }
50773
+ });
50774
+ return { MarkdownParagraph, MarkdownHeading };
50775
+ }
50776
+
50777
+ // src/lib/im-input.ts
50778
+ function createMessageInputKeyHandler({
50779
+ getEditor,
50780
+ getSendKey,
50781
+ onSend
50782
+ }) {
50783
+ return (view, event) => {
50784
+ if (!onSend || event.defaultPrevented || event.isComposing || event.keyCode === 229 || view.composing) {
50785
+ return false;
50786
+ }
50787
+ const editor = getEditor();
50788
+ if (!editor || editor.isDestroyed || !editor.isEditable) return false;
50789
+ if (event.key !== "Enter" || event.shiftKey || event.altKey) return false;
50790
+ const modifier = event.metaKey || event.ctrlKey;
50791
+ const sendKey = getSendKey();
50792
+ const shouldSend = sendKey === "enter" ? !modifier : sendKey === "mod-enter" ? modifier : false;
50793
+ if (!shouldSend) return false;
50794
+ event.preventDefault();
50795
+ onSend(editor);
50796
+ return true;
50797
+ };
50798
+ }
50627
50799
  var isMac3 = () => typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.platform);
50628
50800
  var FeishuStrike = Strike.extend({
50629
50801
  addKeyboardShortcuts() {
50630
50802
  return { "Mod-Shift-x": () => this.editor.commands.toggleStrike() };
50631
50803
  }
50632
50804
  });
50805
+ function partialLinkRuns(block, start, code, link) {
50806
+ const out = [];
50807
+ let from = -1;
50808
+ let to = -1;
50809
+ let links = [];
50810
+ const flush = () => {
50811
+ const first = links[0];
50812
+ if (from >= 0 && links.some(Boolean) && !links.every((m) => m && first && m.eq(first))) {
50813
+ out.push([from, to]);
50814
+ }
50815
+ from = -1;
50816
+ links = [];
50817
+ };
50818
+ block.forEach((child, offset6) => {
50819
+ if (!child.isText || !code.isInSet(child.marks)) {
50820
+ flush();
50821
+ return;
50822
+ }
50823
+ if (from < 0) from = start + offset6;
50824
+ to = start + offset6 + child.nodeSize;
50825
+ links.push(link.isInSet(child.marks));
50826
+ });
50827
+ flush();
50828
+ return out;
50829
+ }
50830
+ function inlineCodeLinkPlugin() {
50831
+ return new Plugin({
50832
+ key: new PluginKey("inlineCodeLink"),
50833
+ appendTransaction(transactions, oldState, newState) {
50834
+ const { code, link } = newState.schema.marks;
50835
+ if (!code || !link || !transactions.some((tr2) => tr2.docChanged)) return null;
50836
+ const changed = getChangedRanges(combineTransactionSteps(oldState.doc, [...transactions]));
50837
+ const seen = /* @__PURE__ */ new Set();
50838
+ const ranges = [];
50839
+ for (const { newRange } of changed) {
50840
+ newState.doc.nodesBetween(newRange.from, newRange.to, (node, pos) => {
50841
+ if (!node.isTextblock) return true;
50842
+ if (!seen.has(pos)) {
50843
+ seen.add(pos);
50844
+ ranges.push(...partialLinkRuns(node, pos + 1, code, link));
50845
+ }
50846
+ return false;
50847
+ });
50848
+ }
50849
+ if (!ranges.length) return null;
50850
+ const tr = newState.tr;
50851
+ for (const [from, to] of ranges) tr.removeMark(from, to, link);
50852
+ return tr;
50853
+ }
50854
+ });
50855
+ }
50633
50856
  var FeishuCode = Code.extend({
50857
+ excludes: "bold italic underline strike textStyle highlight superscript subscript code",
50634
50858
  addKeyboardShortcuts() {
50635
50859
  return { [isMac3() ? "Mod-Ctrl-c" : "Ctrl-Shift-c"]: () => this.editor.commands.toggleCode() };
50860
+ },
50861
+ addProseMirrorPlugins() {
50862
+ return [...this.parent?.() ?? [], inlineCodeLinkPlugin()];
50863
+ }
50864
+ });
50865
+ function selectionIsAllCode(state) {
50866
+ const { code } = state.schema.marks;
50867
+ const { from, to, empty } = state.selection;
50868
+ if (!code || empty) return false;
50869
+ let hasText = false;
50870
+ let allCode = true;
50871
+ state.doc.nodesBetween(from, to, (node) => {
50872
+ if (!node.isText) return true;
50873
+ hasText = true;
50874
+ if (!code.isInSet(node.marks)) allCode = false;
50875
+ return false;
50876
+ });
50877
+ return hasText && allCode;
50878
+ }
50879
+ var FeishuLink = Link.extend({
50880
+ addPasteRules() {
50881
+ return (this.parent?.() ?? []).map(
50882
+ (rule) => new PasteRule({
50883
+ find: rule.find,
50884
+ handler: (props) => {
50885
+ const { code } = props.state.schema.marks;
50886
+ if (code && props.state.doc.rangeHasMark(props.range.from, props.range.to, code)) {
50887
+ return null;
50888
+ }
50889
+ return rule.handler(props);
50890
+ }
50891
+ })
50892
+ );
50893
+ },
50894
+ // Link 的插件里只有「选中文字后粘贴网址 → 给选区加链接」这一个有 handlePaste。选中的全是行内代码时
50895
+ // 跳过它,按普通粘贴替换文字(放开链接之前就是这样),不给代码挂一个看不出来的链接
50896
+ addProseMirrorPlugins() {
50897
+ return (this.parent?.() ?? []).map((plugin) => {
50898
+ const handlePaste = plugin.props.handlePaste;
50899
+ if (!handlePaste) return plugin;
50900
+ return new Plugin({
50901
+ ...plugin.spec,
50902
+ props: {
50903
+ ...plugin.spec.props,
50904
+ handlePaste(view, event, slice) {
50905
+ if (selectionIsAllCode(view.state)) return false;
50906
+ return handlePaste.call(this, view, event, slice);
50907
+ }
50908
+ }
50909
+ });
50910
+ });
50636
50911
  }
50637
50912
  });
50638
50913
  var FeishuBlockquote = Blockquote.extend({
@@ -51030,6 +51305,7 @@ var CopyLink = Extension.create({
51030
51305
  };
51031
51306
  }
51032
51307
  });
51308
+ var TEXT_ALIGN_TYPES = ["heading", "paragraph"];
51033
51309
  function LoadingSpinner({ text = "Connecting..." }) {
51034
51310
  return /* @__PURE__ */ jsx("div", { className: "spinner-container", children: /* @__PURE__ */ jsxs("div", { className: "spinner-content", children: [
51035
51311
  /* @__PURE__ */ jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", children: [
@@ -51039,7 +51315,7 @@ function LoadingSpinner({ text = "Connecting..." }) {
51039
51315
  /* @__PURE__ */ jsx("div", { className: "spinner-loading-text", children: text })
51040
51316
  ] }) });
51041
51317
  }
51042
- function EditorContentArea() {
51318
+ function EditorContentArea({ hideFloatingToolbar = false }) {
51043
51319
  const { editor } = useContext(EditorContext);
51044
51320
  useScrollToHash();
51045
51321
  if (!editor) {
@@ -51069,7 +51345,7 @@ function EditorContentArea() {
51069
51345
  /* @__PURE__ */ jsx(EmojiDropdownMenu, {}),
51070
51346
  /* @__PURE__ */ jsx(MentionDropdownMenu, {}),
51071
51347
  /* @__PURE__ */ jsx(SlashDropdownMenu, {}),
51072
- /* @__PURE__ */ jsx(NotionToolbarFloating, {}),
51348
+ !hideFloatingToolbar && /* @__PURE__ */ jsx(NotionToolbarFloating, {}),
51073
51349
  /* @__PURE__ */ jsx(MathEditorPopover, { editor }),
51074
51350
  /* @__PURE__ */ jsx(LinkPastePanel, { editor }),
51075
51351
  /* @__PURE__ */ jsx(LinkEditPanel, { editor }),
@@ -51095,7 +51371,14 @@ function EditorProvider(props) {
51095
51371
  readOnly = false,
51096
51372
  permissions,
51097
51373
  hideHeader = false,
51374
+ hideFloatingToolbar = false,
51098
51375
  embedded = false,
51376
+ richMarkdown = false,
51377
+ sendKey,
51378
+ onSend,
51379
+ onUpdate,
51380
+ onSelectionUpdate,
51381
+ onEditorDestroy,
51099
51382
  onEditorReady,
51100
51383
  extensions: extraExtensions,
51101
51384
  pageHeader = false,
@@ -51122,6 +51405,16 @@ function EditorProvider(props) {
51122
51405
  return found;
51123
51406
  }, []);
51124
51407
  const editorConfig = useEditorConfig();
51408
+ const onSendRef = useRef(onSend);
51409
+ onSendRef.current = onSend;
51410
+ const sendKeyRef = useRef(sendKey);
51411
+ sendKeyRef.current = sendKey;
51412
+ const onUpdateRef = useRef(onUpdate);
51413
+ onUpdateRef.current = onUpdate;
51414
+ const onSelectionUpdateRef = useRef(onSelectionUpdate);
51415
+ onSelectionUpdateRef.current = onSelectionUpdate;
51416
+ const onEditorDestroyRef = useRef(onEditorDestroy);
51417
+ onEditorDestroyRef.current = onEditorDestroy;
51125
51418
  const [mathBus] = useState(createMathEditBus);
51126
51419
  const onUpload = editorConfig?.upload?.onUpload ?? handleImageUpload;
51127
51420
  const onUploadError = editorConfig?.upload?.onError ?? // 宿主没给 onError 时按飞书弹提示(「上传图片大小不能超过 20 MB」「图片格式仅支持 …」等)
@@ -51131,9 +51424,14 @@ function EditorProvider(props) {
51131
51424
  const videoMaxSize = resolveMaxSize("video", editorConfig?.upload);
51132
51425
  const audioMaxSize = resolveMaxSize("audio", editorConfig?.upload);
51133
51426
  const fileMaxSize = resolveMaxSize("file", editorConfig?.upload);
51427
+ const richMarkdownExtensions = useMemo(
51428
+ () => richMarkdown ? createRichMarkdownExtensions() : null,
51429
+ [richMarkdown]
51430
+ );
51134
51431
  const extensions = [
51135
51432
  StarterKit.configure({
51136
51433
  undoRedo: false,
51434
+ paragraph: richMarkdownExtensions ? false : void 0,
51137
51435
  horizontalRule: false,
51138
51436
  // 换成 1–9 级 + 折叠的版本(heading-node-extension)
51139
51437
  heading: false,
@@ -51146,8 +51444,10 @@ function EditorProvider(props) {
51146
51444
  dropcursor: {
51147
51445
  width: 2
51148
51446
  },
51149
- link: { openOnClick: false }
51447
+ // 换成粘贴规则跳过行内代码的版本(feishu-keymap 的 FeishuLink)
51448
+ link: false
51150
51449
  }),
51450
+ ...richMarkdownExtensions ? [richMarkdownExtensions.MarkdownParagraph] : [],
51151
51451
  // 代码块 / 分组 / 高亮 / Markdown / 直接输入:顺序固定,且在协同与 UniqueID 之前
51152
51452
  CodeBlockExtension,
51153
51453
  CodeGroupExtension,
@@ -51161,9 +51461,10 @@ function EditorProvider(props) {
51161
51461
  ApiParamExtension,
51162
51462
  ContainerInput,
51163
51463
  HorizontalRule,
51164
- Heading,
51464
+ richMarkdownExtensions ? richMarkdownExtensions.MarkdownHeading : Heading,
51165
51465
  FeishuStrike,
51166
51466
  FeishuCode,
51467
+ FeishuLink.configure({ openOnClick: false }),
51167
51468
  FeishuBlockquote,
51168
51469
  // ⌘⌥S 分割线、⌘⌥H 套用上次颜色、Alt+C 切换待办(规格 §33)
51169
51470
  FeishuKeymap,
@@ -51174,7 +51475,7 @@ function EditorProvider(props) {
51174
51475
  // 文档页头:节点始终注册(协同各端 schema 要一致),是否自动补由 pageHeader 决定
51175
51476
  PageHeader.configure({ autoInsert: pageHeader }),
51176
51477
  // 飞书只有左 / 中 / 右(对齐枚举里没有两端对齐),也就没有 ⌘⇧J
51177
- TextAlign.configure({ types: ["heading", "paragraph"], alignments: ["left", "center", "right"] }),
51478
+ TextAlign.configure({ types: TEXT_ALIGN_TYPES, alignments: ["left", "center", "right"] }),
51178
51479
  // Collaboration 可以无 provider 运行(仅操作本地 yjs doc),CollaborationCaret
51179
51480
  // 强依赖 provider.awareness,没 provider 时不挂以避免 runtime 崩。
51180
51481
  Collaboration.configure({ document: ydoc }),
@@ -51236,7 +51537,8 @@ function EditorProvider(props) {
51236
51537
  "tocNode"
51237
51538
  ]
51238
51539
  }),
51239
- NodeAlignment,
51540
+ // 段落 / 标题的 text-align 归 TextAlign,NodeAlignment 不再抢(见 textAlignHandledTypes)
51541
+ NodeAlignment.configure({ textAlignHandledTypes: TEXT_ALIGN_TYPES }),
51240
51542
  // 行距 / 段前段后距:Word 把它们挂在每个段落上,导入时没有对应属性就会
51241
51543
  // 整篇塌回编辑器的统一边距,原文的疏密节奏全丢。
51242
51544
  BlockSpacing.configure({
@@ -51379,6 +51681,14 @@ function EditorProvider(props) {
51379
51681
  const [initialContent] = useState(
51380
51682
  () => provider ? void 0 : normalizeEditorContent(content, contentFormat, extensions) ?? void 0
51381
51683
  );
51684
+ const messageInputKeyHandler = useMemo(
51685
+ () => createMessageInputKeyHandler({
51686
+ getEditor: () => editorRef.current,
51687
+ getSendKey: () => sendKeyRef.current,
51688
+ onSend: (current) => onSendRef.current?.(current)
51689
+ }),
51690
+ []
51691
+ );
51382
51692
  const editor = useEditor({
51383
51693
  immediatelyRender: false,
51384
51694
  // 只读模式:禁用编辑。扩展集保持不变,自定义节点仍走各自 NodeView 渲染
@@ -51388,10 +51698,18 @@ function EditorProvider(props) {
51388
51698
  editorProps: {
51389
51699
  attributes: {
51390
51700
  class: "notion-like-editor"
51391
- }
51701
+ },
51702
+ handleKeyDown: messageInputKeyHandler
51703
+ },
51704
+ onUpdate: ({ editor: current }) => onUpdateRef.current?.(current),
51705
+ onSelectionUpdate: ({ editor: current }) => onSelectionUpdateRef.current?.(current),
51706
+ onDestroy: () => {
51707
+ const current = editorRef.current;
51708
+ if (current) onEditorDestroyRef.current?.(current);
51392
51709
  },
51393
51710
  extensions
51394
51711
  });
51712
+ editorRef.current = editor;
51395
51713
  useEffect(() => {
51396
51714
  if (!editor) return;
51397
51715
  editorRef.current = editor;
@@ -51425,9 +51743,20 @@ function EditorProvider(props) {
51425
51743
  useEffect(() => {
51426
51744
  if (provider) return;
51427
51745
  if (!editor) return;
51428
- if (content === void 0 || content === null || content === "") return;
51429
- const next = normalizeEditorContent(content, contentFormat, editor.extensionManager.extensions);
51430
- if (!next) return;
51746
+ const update = resolveEditorContentUpdate(content, contentFormat, editor.extensionManager.extensions);
51747
+ if (update.kind === "ignore") return;
51748
+ if (update.kind === "clear") {
51749
+ if (editor.isEmpty) return;
51750
+ let cancelled2 = false;
51751
+ queueMicrotask(() => {
51752
+ if (cancelled2 || editor.isDestroyed) return;
51753
+ editor.commands.clearContent(false);
51754
+ });
51755
+ return () => {
51756
+ cancelled2 = true;
51757
+ };
51758
+ }
51759
+ const next = update.json;
51431
51760
  if (isSameDocument(editor.getJSON(), next)) return;
51432
51761
  let cancelled = false;
51433
51762
  queueMicrotask(() => {
@@ -51510,7 +51839,7 @@ function EditorProvider(props) {
51510
51839
  /* @__PURE__ */ jsx(ReadModeSelectionBar, { editor }),
51511
51840
  !readOnly && !hideHeader && /* @__PURE__ */ jsx(NotionEditorHeader, {}),
51512
51841
  /* @__PURE__ */ jsxs("div", { className: "notion-like-editor-layout", "data-width-mode": widthModeValue, children: [
51513
- /* @__PURE__ */ jsx(EditorContentArea, {}),
51842
+ /* @__PURE__ */ jsx(EditorContentArea, { hideFloatingToolbar }),
51514
51843
  !embedded && /* @__PURE__ */ jsx(TocSidebar, { topOffset: 48 })
51515
51844
  ] }),
51516
51845
  isEditable && /* @__PURE__ */ jsxs(Fragment$1, { children: [
@@ -51540,6 +51869,14 @@ function NotionEditor({
51540
51869
  codeBlock,
51541
51870
  readOnly = false,
51542
51871
  hideHeader = false,
51872
+ hideFloatingToolbar = false,
51873
+ embedded = false,
51874
+ richMarkdown = false,
51875
+ sendKey,
51876
+ onSend,
51877
+ onUpdate,
51878
+ onSelectionUpdate,
51879
+ onEditorDestroy,
51543
51880
  onEditorReady,
51544
51881
  extensions,
51545
51882
  pageHeader,
@@ -51564,6 +51901,14 @@ function NotionEditor({
51564
51901
  readOnly,
51565
51902
  permissions,
51566
51903
  hideHeader,
51904
+ hideFloatingToolbar,
51905
+ embedded,
51906
+ richMarkdown,
51907
+ sendKey,
51908
+ onSend,
51909
+ onUpdate,
51910
+ onSelectionUpdate,
51911
+ onEditorDestroy,
51567
51912
  onEditorReady,
51568
51913
  extensions,
51569
51914
  pageHeader,
@@ -51585,6 +51930,14 @@ function NotionEditorContent({
51585
51930
  readOnly = false,
51586
51931
  permissions,
51587
51932
  hideHeader = false,
51933
+ hideFloatingToolbar = false,
51934
+ embedded = false,
51935
+ richMarkdown = false,
51936
+ sendKey,
51937
+ onSend,
51938
+ onUpdate,
51939
+ onSelectionUpdate,
51940
+ onEditorDestroy,
51588
51941
  onEditorReady,
51589
51942
  extensions,
51590
51943
  pageHeader,
@@ -51614,6 +51967,14 @@ function NotionEditorContent({
51614
51967
  readOnly,
51615
51968
  permissions,
51616
51969
  hideHeader,
51970
+ hideFloatingToolbar,
51971
+ embedded,
51972
+ richMarkdown,
51973
+ sendKey,
51974
+ onSend,
51975
+ onUpdate,
51976
+ onSelectionUpdate,
51977
+ onEditorDestroy,
51617
51978
  onEditorReady,
51618
51979
  extensions,
51619
51980
  pageHeader,
@@ -51655,5 +52016,5 @@ function ArticleViewer({
51655
52016
  }
51656
52017
 
51657
52018
  export { ApiParamExtension, ArticleViewer, Audio, CalloutExtension, CodeBlockExtension, CodeGroupExtension, CollabContext, CollabProvider, Column, Columns, DEFAULT_DOC_PERMISSIONS, DEFAULT_MAX_FILE_SIZES, DOC_WIDTHS, DetailsExtension, DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, EditorConfigProvider, EditorContentArea, EditorProvider, EditorThemeStyle, FileAttachment, FileInline, FloatingElement, HIDE_FLOATING_META, LoadingSpinner, MediaUploadButton, MediaUploadPlaceholder, NotionEditor, NotionEditorContent, PasteDropMedia, Separator, Spacer, Toolbar, ToolbarGroup, ToolbarSeparator, UiState, UserContext, UserProvider, VIEW_MODE_TOAST, Video, ViewModeSwitch, WidthModeMenu, countDocument, countRange, countText, defaultUiState, detectMediaKind, findSelectionPosition, getDocPermissions, getEditorMarkdown, hasContentAbove, markHideFloatingOnNext, parseEditorContent, pickFile, printDocument, renderHighlightedHTML, resolveEditorTheme, resolveMaxSize, runMediaUpload, selectNodeAndHideFloating, serializeEditorMarkdown, useCollab, useCollaboration, useComposedRef, useCursorVisibility, useEditorConfig, useElementRect, useFloatingElement, useFloatingToolbarVisibility, useIsBreakpoint, useIsomorphicLayoutEffect, useMenuNavigation, useOnClickOutside, useThrottledCallback, useUiEditorState, useUnmount, useUser, useViewMode, useWidthMode, useWindowSize, use_ui_editor_state_default };
51658
- //# sourceMappingURL=chunk-PCM4FATZ.js.map
51659
- //# sourceMappingURL=chunk-PCM4FATZ.js.map
52019
+ //# sourceMappingURL=chunk-SV3LH2TC.js.map
52020
+ //# sourceMappingURL=chunk-SV3LH2TC.js.map