@4399ywkf/editor 0.9.1 → 0.9.3
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-R4E7QINT.js → DocView-YBRD4V4E.js} +6 -5
- package/dist/DocView-YBRD4V4E.js.map +1 -0
- package/dist/chunk-4MQS76M2.js +51666 -0
- package/dist/chunk-4MQS76M2.js.map +1 -0
- package/dist/chunk-ABMZOL26.js +116 -0
- package/dist/chunk-ABMZOL26.js.map +1 -0
- package/dist/{chunk-QMYT5WXO.js → chunk-MGSVKKK7.js} +2 -2
- package/dist/{chunk-QMYT5WXO.js.map → chunk-MGSVKKK7.js.map} +1 -1
- package/dist/chunk-UD6MDBTN.js +1192 -0
- package/dist/chunk-UD6MDBTN.js.map +1 -0
- package/dist/{code-types-Dqmit3xx.d.ts → code-types-BTrUO25D.d.ts} +9 -1
- package/dist/diagram-canvas-22ANCGUV.js +261 -0
- package/dist/diagram-canvas-22ANCGUV.js.map +1 -0
- package/dist/doc-runtime.js +45 -7
- package/dist/doc-runtime.js.map +1 -1
- package/dist/doc.d.ts +526 -54
- package/dist/doc.js +4 -3
- package/dist/doc.js.map +1 -1
- package/dist/docx.js +115 -13
- package/dist/docx.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/pdf.d.ts +2 -2
- package/dist/plugins/ai.js +1 -1
- package/dist/pptx.d.ts +2 -2
- package/dist/{registry-BQ5T1Yko.d.ts → registry-ByvNr_Fa.d.ts} +1 -1
- package/dist/sheet.d.ts +3 -3
- package/dist/style.css +1049 -6047
- package/package.json +21 -5
- package/dist/DocView-R4E7QINT.js.map +0 -1
- package/dist/chunk-OGRGQQ3D.js +0 -23747
- package/dist/chunk-OGRGQQ3D.js.map +0 -1
- package/dist/chunk-ZY5KLA7T.js +0 -258
- package/dist/chunk-ZY5KLA7T.js.map +0 -1
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// src/components/tiptap-node/diagram-node/diagram-model.ts
|
|
2
|
+
var DIAGRAM_SHAPES = [
|
|
3
|
+
{ shape: "terminator", label: "开始 / 结束", sample: "开始" },
|
|
4
|
+
{ shape: "process", label: "处理", sample: "处理" },
|
|
5
|
+
{ shape: "decision", label: "判断", sample: "条件?" },
|
|
6
|
+
{ shape: "data", label: "输入 / 输出", sample: "输入" }
|
|
7
|
+
];
|
|
8
|
+
var SHAPE_SIZE = {
|
|
9
|
+
terminator: { width: 120, height: 44 },
|
|
10
|
+
process: { width: 140, height: 56 },
|
|
11
|
+
decision: { width: 140, height: 80 },
|
|
12
|
+
data: { width: 140, height: 56 }
|
|
13
|
+
};
|
|
14
|
+
var MAX_DIAGRAM_NODES = 500;
|
|
15
|
+
var DEFAULT_DIAGRAM_HEIGHT = 420;
|
|
16
|
+
var MIN_DIAGRAM_HEIGHT = 200;
|
|
17
|
+
var MAX_DIAGRAM_HEIGHT = 1600;
|
|
18
|
+
var SHAPES = new Set(DIAGRAM_SHAPES.map((s) => s.shape));
|
|
19
|
+
var HANDLES = /* @__PURE__ */ new Set(["top", "right", "bottom", "left"]);
|
|
20
|
+
function defaultDiagram() {
|
|
21
|
+
return {
|
|
22
|
+
nodes: [
|
|
23
|
+
{ id: "n1", shape: "terminator", label: "开始", x: 10, y: 0 },
|
|
24
|
+
{ id: "n2", shape: "process", label: "处理", x: 0, y: 110 },
|
|
25
|
+
{ id: "n3", shape: "terminator", label: "结束", x: 10, y: 230 }
|
|
26
|
+
],
|
|
27
|
+
edges: [
|
|
28
|
+
{ id: "e1", source: "n1", target: "n2", sourceHandle: "bottom", targetHandle: "top" },
|
|
29
|
+
{ id: "e2", source: "n2", target: "n3", sourceHandle: "bottom", targetHandle: "top" }
|
|
30
|
+
]
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
var num = (v) => typeof v === "number" && Number.isFinite(v) ? Math.round(v) : 0;
|
|
34
|
+
var str = (v, max = 500) => typeof v === "string" ? v.slice(0, max) : "";
|
|
35
|
+
function normalizeDiagram(raw) {
|
|
36
|
+
const input = raw && typeof raw === "object" ? raw : {};
|
|
37
|
+
const nodes = [];
|
|
38
|
+
const ids = /* @__PURE__ */ new Set();
|
|
39
|
+
for (const n of Array.isArray(input.nodes) ? input.nodes : []) {
|
|
40
|
+
if (!n || typeof n !== "object") continue;
|
|
41
|
+
const id = str(n.id, 64);
|
|
42
|
+
if (!id || ids.has(id) || nodes.length >= MAX_DIAGRAM_NODES) continue;
|
|
43
|
+
const shape = SHAPES.has(n.shape) ? n.shape : "process";
|
|
44
|
+
ids.add(id);
|
|
45
|
+
nodes.push({ id, shape, label: str(n.label), x: num(n.x), y: num(n.y) });
|
|
46
|
+
}
|
|
47
|
+
const edges = [];
|
|
48
|
+
const edgeIds = /* @__PURE__ */ new Set();
|
|
49
|
+
for (const e of Array.isArray(input.edges) ? input.edges : []) {
|
|
50
|
+
if (!e || typeof e !== "object") continue;
|
|
51
|
+
const id = str(e.id, 64);
|
|
52
|
+
if (!id || edgeIds.has(id) || !ids.has(e.source) || !ids.has(e.target)) continue;
|
|
53
|
+
edgeIds.add(id);
|
|
54
|
+
const edge = { id, source: e.source, target: e.target };
|
|
55
|
+
if (e.sourceHandle && HANDLES.has(e.sourceHandle)) edge.sourceHandle = e.sourceHandle;
|
|
56
|
+
if (e.targetHandle && HANDLES.has(e.targetHandle)) edge.targetHandle = e.targetHandle;
|
|
57
|
+
const label = str(e.label, 200);
|
|
58
|
+
if (label) edge.label = label;
|
|
59
|
+
edges.push(edge);
|
|
60
|
+
}
|
|
61
|
+
return { nodes, edges };
|
|
62
|
+
}
|
|
63
|
+
function clampDiagramHeight(h) {
|
|
64
|
+
const n = Math.round(Number(h));
|
|
65
|
+
if (!Number.isFinite(n)) return DEFAULT_DIAGRAM_HEIGHT;
|
|
66
|
+
return Math.min(MAX_DIAGRAM_HEIGHT, Math.max(MIN_DIAGRAM_HEIGHT, n));
|
|
67
|
+
}
|
|
68
|
+
function nextId(prefix, used) {
|
|
69
|
+
const set = new Set(used);
|
|
70
|
+
let i = set.size + 1;
|
|
71
|
+
while (set.has(`${prefix}${i}`)) i++;
|
|
72
|
+
return `${prefix}${i}`;
|
|
73
|
+
}
|
|
74
|
+
var mermaidText = (s) => `"${s.replace(/"/g, "#quot;").replace(/\n/g, "<br/>")}"`;
|
|
75
|
+
var mermaidId = (id) => `n_${id.replace(/[^A-Za-z0-9_]/g, "_")}`;
|
|
76
|
+
function toMermaid(data) {
|
|
77
|
+
const { nodes, edges } = data;
|
|
78
|
+
const xs = nodes.map((n) => n.x);
|
|
79
|
+
const ys = nodes.map((n) => n.y);
|
|
80
|
+
const spanX = xs.length ? Math.max(...xs) - Math.min(...xs) : 0;
|
|
81
|
+
const spanY = ys.length ? Math.max(...ys) - Math.min(...ys) : 0;
|
|
82
|
+
const lines = [`flowchart ${spanY >= spanX ? "TD" : "LR"}`];
|
|
83
|
+
for (const n of nodes) {
|
|
84
|
+
const t = mermaidText(n.label);
|
|
85
|
+
const id = mermaidId(n.id);
|
|
86
|
+
const shape = n.shape === "terminator" ? `${id}([${t}])` : n.shape === "decision" ? `${id}{${t}}` : n.shape === "data" ? `${id}[/${t}/]` : `${id}[${t}]`;
|
|
87
|
+
lines.push(` ${shape}`);
|
|
88
|
+
}
|
|
89
|
+
for (const e of edges) {
|
|
90
|
+
const label = e.label ? `|${mermaidText(e.label)}|` : "";
|
|
91
|
+
lines.push(` ${mermaidId(e.source)} -->${label} ${mermaidId(e.target)}`);
|
|
92
|
+
}
|
|
93
|
+
return lines.join("\n");
|
|
94
|
+
}
|
|
95
|
+
function toOutline(data) {
|
|
96
|
+
const byId = new Map(data.nodes.map((n) => [n.id, n]));
|
|
97
|
+
const name = (id) => byId.get(id)?.label || "(未命名)";
|
|
98
|
+
const lines = data.edges.map(
|
|
99
|
+
(e) => `${name(e.source)} → ${name(e.target)}${e.label ? `(${e.label})` : ""}`
|
|
100
|
+
);
|
|
101
|
+
const connected = new Set(data.edges.flatMap((e) => [e.source, e.target]));
|
|
102
|
+
for (const n of data.nodes) if (!connected.has(n.id)) lines.push(name(n.id));
|
|
103
|
+
return lines;
|
|
104
|
+
}
|
|
105
|
+
function freeSpot(nodes, at, size, gap = 40) {
|
|
106
|
+
const hit = (x2, y2) => nodes.some(
|
|
107
|
+
(n) => x2 < n.x + n.width + gap / 2 && x2 + size.width + gap / 2 > n.x && y2 < n.y + n.height + gap / 2 && y2 + size.height + gap / 2 > n.y
|
|
108
|
+
);
|
|
109
|
+
let { x, y } = at;
|
|
110
|
+
for (let i = 0; i < 20 && hit(x, y); i++) x += size.width + gap;
|
|
111
|
+
return { x: Math.round(x), y: Math.round(y) };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export { DEFAULT_DIAGRAM_HEIGHT, DIAGRAM_SHAPES, MAX_DIAGRAM_NODES, SHAPE_SIZE, clampDiagramHeight, defaultDiagram, freeSpot, nextId, normalizeDiagram, toMermaid, toOutline };
|
|
115
|
+
//# sourceMappingURL=chunk-ABMZOL26.js.map
|
|
116
|
+
//# sourceMappingURL=chunk-ABMZOL26.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/tiptap-node/diagram-node/diagram-model.ts"],"names":["x","y"],"mappings":";AAgCO,IAAM,cAAA,GAA2E;AAAA,EACtF,EAAE,KAAA,EAAO,YAAA,EAAc,KAAA,EAAO,SAAA,EAAW,QAAQ,IAAA,EAAK;AAAA,EACtD,EAAE,KAAA,EAAO,SAAA,EAAW,KAAA,EAAO,IAAA,EAAM,QAAQ,IAAA,EAAK;AAAA,EAC9C,EAAE,KAAA,EAAO,UAAA,EAAY,KAAA,EAAO,IAAA,EAAM,QAAQ,KAAA,EAAM;AAAA,EAChD,EAAE,KAAA,EAAO,MAAA,EAAQ,KAAA,EAAO,SAAA,EAAW,QAAQ,IAAA;AAC7C;AAEO,IAAM,UAAA,GAAsE;AAAA,EACjF,UAAA,EAAY,EAAE,KAAA,EAAO,GAAA,EAAK,QAAQ,EAAA,EAAG;A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AA,EACA,MAAM,EAAA,EACoB;AAC1B,EAAA,MAAM,GAAA,GAAM,CAACA,EAAAA,EAAWC,EAAAA,KACtB,KAAA,CAAM,IAAA;AAAA,IACJ,CAAC,CAAA,KACCD,EAAAA,GAAI,CAAA,CAAE,CAAA,GAAI,CAAA,CAAE,KAAA,GAAQ,GAAA,GAAM,CAAA,IAC1BA,EAAAA,GAAI,IAAA,CAAK,KAAA,GAAQ,GAAA,GAAM,CAAA,GAAI,CAAA,CAAE,CAAA,IAC7BC,EAAAA,GAAI,CAAA,CAAE,CAAA,GAAI,CAAA,CAAE,MAAA,GAAS,GAAA,GAAM,CAAA,IAC3BA,EAAAA,GAAI,IAAA,CAAK,MAAA,GAAS,GAAA,GAAM,CAAA,GAAI,CAAA,CAAE;AAAA,GAClC;AACF,EAAA,IAAI,EAAE,CAAA,EAAG,CAAA,EAAE,GAAI,EAAA;AACf,EAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,EAAA,IAAM,GAAA,CAAI,CAAA,EAAG,CAAC,CAAA,EAAG,CAAA,EAAA,EAAK,CAAA,IAAK,IAAA,CAAK,KAAA,GAAQ,GAAA;AAC5D,EAAA,OAAO,EAAE,CAAA,EAAG,IAAA,CAAK,KAAA,CAAM,CAAC,GAAG,CAAA,EAAG,IAAA,CAAK,KAAA,CAAM,CAAC,CAAA,EAAE;AAC9C","file":"chunk-ABMZOL26.js","sourcesContent":["/**\n * 流程图的数据模型,不依赖 React 和 React Flow:文档里只存这份精简结构,\n * 画布(React Flow)打开时再转换。这样 AI 读写、导出、协同都只面对一份简单的 JSON,\n * 以后换渲染库也不用迁移文档。\n *\n * 形状取 draw.io 流程图最常用的四种(飞书流程图块基于 draw.io,见 feishu-component-specs §12)。\n */\nexport type DiagramShape = \"terminator\" | \"process\" | \"decision\" | \"data\"\n\nexport interface DiagramNodeData {\n id: string\n shape: DiagramShape\n label: string\n x: number\n y: number\n}\n\nexport interface DiagramEdgeData {\n id: string\n source: string\n target: string\n /** 连在节点哪一侧:top / right / bottom / left */\n sourceHandle?: string | null\n targetHandle?: string | null\n label?: string\n}\n\nexport interface DiagramData {\n nodes: DiagramNodeData[]\n edges: DiagramEdgeData[]\n}\n\nexport const DIAGRAM_SHAPES: { shape: DiagramShape; label: string; sample: string }[] = [\n { shape: \"terminator\", label: \"开始 / 结束\", sample: \"开始\" },\n { shape: \"process\", label: \"处理\", sample: \"处理\" },\n { shape: \"decision\", label: \"判断\", sample: \"条件?\" },\n { shape: \"data\", label: \"输入 / 输出\", sample: \"输入\" },\n]\n\nexport const SHAPE_SIZE: Record<DiagramShape, { width: number; height: number }> = {\n terminator: { width: 120, height: 44 },\n process: { width: 140, height: 56 },\n decision: { width: 140, height: 80 },\n data: { width: 140, height: 56 },\n}\n\nexport const MAX_DIAGRAM_NODES = 500\nexport const DEFAULT_DIAGRAM_HEIGHT = 420\nexport const MIN_DIAGRAM_HEIGHT = 200\nexport const MAX_DIAGRAM_HEIGHT = 1600\n\nconst SHAPES = new Set<string>(DIAGRAM_SHAPES.map((s) => s.shape))\nconst HANDLES = new Set([\"top\", \"right\", \"bottom\", \"left\"])\n\n/** 新建流程图的初始内容:开始 → 处理 → 结束 */\nexport function defaultDiagram(): DiagramData {\n return {\n nodes: [\n { id: \"n1\", shape: \"terminator\", label: \"开始\", x: 10, y: 0 },\n { id: \"n2\", shape: \"process\", label: \"处理\", x: 0, y: 110 },\n { id: \"n3\", shape: \"terminator\", label: \"结束\", x: 10, y: 230 },\n ],\n edges: [\n { id: \"e1\", source: \"n1\", target: \"n2\", sourceHandle: \"bottom\", targetHandle: \"top\" },\n { id: \"e2\", source: \"n2\", target: \"n3\", sourceHandle: \"bottom\", targetHandle: \"top\" },\n ],\n }\n}\n\nconst num = (v: unknown) => (typeof v === \"number\" && Number.isFinite(v) ? Math.round(v) : 0)\nconst str = (v: unknown, max = 500) => (typeof v === \"string\" ? v.slice(0, max) : \"\")\n\n/** 外来数据(HTML、AI、旧版本)一律过一遍:丢掉不认识的形状、悬空的连线、重复 id */\nexport function normalizeDiagram(raw: unknown): DiagramData {\n const input = (raw && typeof raw === \"object\" ? raw : {}) as Partial<DiagramData>\n const nodes: DiagramNodeData[] = []\n const ids = new Set<string>()\n for (const n of Array.isArray(input.nodes) ? input.nodes : []) {\n if (!n || typeof n !== \"object\") continue\n const id = str((n as DiagramNodeData).id, 64)\n if (!id || ids.has(id) || nodes.length >= MAX_DIAGRAM_NODES) continue\n const shape = SHAPES.has((n as DiagramNodeData).shape)\n ? (n as DiagramNodeData).shape\n : \"process\"\n ids.add(id)\n nodes.push({ id, shape, label: str(n.label), x: num(n.x), y: num(n.y) })\n }\n const edges: DiagramEdgeData[] = []\n const edgeIds = new Set<string>()\n for (const e of Array.isArray(input.edges) ? input.edges : []) {\n if (!e || typeof e !== \"object\") continue\n const id = str(e.id, 64)\n if (!id || edgeIds.has(id) || !ids.has(e.source) || !ids.has(e.target)) continue\n edgeIds.add(id)\n const edge: DiagramEdgeData = { id, source: e.source, target: e.target }\n if (e.sourceHandle && HANDLES.has(e.sourceHandle)) edge.sourceHandle = e.sourceHandle\n if (e.targetHandle && HANDLES.has(e.targetHandle)) edge.targetHandle = e.targetHandle\n const label = str(e.label, 200)\n if (label) edge.label = label\n edges.push(edge)\n }\n return { nodes, edges }\n}\n\nexport function clampDiagramHeight(h: unknown): number {\n const n = Math.round(Number(h))\n if (!Number.isFinite(n)) return DEFAULT_DIAGRAM_HEIGHT\n return Math.min(MAX_DIAGRAM_HEIGHT, Math.max(MIN_DIAGRAM_HEIGHT, n))\n}\n\n/** 下一个不重复的 id(n1、n2…) */\nexport function nextId(prefix: string, used: Iterable<string>): string {\n const set = new Set(used)\n let i = set.size + 1\n while (set.has(`${prefix}${i}`)) i++\n return `${prefix}${i}`\n}\n\nconst mermaidText = (s: string) => `\"${s.replace(/\"/g, \"#quot;\").replace(/\\n/g, \"<br/>\")}\"`\nconst mermaidId = (id: string) => `n_${id.replace(/[^A-Za-z0-9_]/g, \"_\")}`\n\n/**\n * 转成 Mermaid flowchart 文本:Markdown 导出用,AI 和别的工具都能读。\n * 方向按节点布局猜:纵向跨度大于横向就 TD,否则 LR。\n */\nexport function toMermaid(data: DiagramData): string {\n const { nodes, edges } = data\n const xs = nodes.map((n) => n.x)\n const ys = nodes.map((n) => n.y)\n const spanX = xs.length ? Math.max(...xs) - Math.min(...xs) : 0\n const spanY = ys.length ? Math.max(...ys) - Math.min(...ys) : 0\n const lines = [`flowchart ${spanY >= spanX ? \"TD\" : \"LR\"}`]\n for (const n of nodes) {\n const t = mermaidText(n.label)\n const id = mermaidId(n.id)\n const shape =\n n.shape === \"terminator\"\n ? `${id}([${t}])`\n : n.shape === \"decision\"\n ? `${id}{${t}}`\n : n.shape === \"data\"\n ? `${id}[/${t}/]`\n : `${id}[${t}]`\n lines.push(` ${shape}`)\n }\n for (const e of edges) {\n const label = e.label ? `|${mermaidText(e.label)}|` : \"\"\n lines.push(` ${mermaidId(e.source)} -->${label} ${mermaidId(e.target)}`)\n }\n return lines.join(\"\\n\")\n}\n\n/** 纯文字描述:Word 导出、无脚本环境的兜底。「开始 → 处理(是)」一条连线一行 */\nexport function toOutline(data: DiagramData): string[] {\n const byId = new Map(data.nodes.map((n) => [n.id, n]))\n const name = (id: string) => byId.get(id)?.label || \"(未命名)\"\n const lines = data.edges.map(\n (e) => `${name(e.source)} → ${name(e.target)}${e.label ? `(${e.label})` : \"\"}`,\n )\n const connected = new Set(data.edges.flatMap((e) => [e.source, e.target]))\n for (const n of data.nodes) if (!connected.has(n.id)) lines.push(name(n.id))\n return lines\n}\n\n/**\n * 新节点放在哪:从画布中心开始,和已有节点重叠就往右挪一格,最多挪 20 次。\n * `at` 是期望的左上角坐标。\n */\nexport function freeSpot(\n nodes: { x: number; y: number; width: number; height: number }[],\n at: { x: number; y: number },\n size: { width: number; height: number },\n gap = 40,\n): { x: number; y: number } {\n const hit = (x: number, y: number) =>\n nodes.some(\n (n) =>\n x < n.x + n.width + gap / 2 &&\n x + size.width + gap / 2 > n.x &&\n y < n.y + n.height + gap / 2 &&\n y + size.height + gap / 2 > n.y,\n )\n let { x, y } = at\n for (let i = 0; i < 20 && hit(x, y); i++) x += size.width + gap\n return { x: Math.round(x), y: Math.round(y) }\n}\n"]}
|
|
@@ -1011,5 +1011,5 @@ var AIButton = forwardRef(
|
|
|
1011
1011
|
AIButton.displayName = "AIButton";
|
|
1012
1012
|
|
|
1013
1013
|
export { AIButton, AIConfigContext, AIDialog, Button, MAC_SYMBOLS, MAX_FILE_SIZE, Popover, PopoverContent, PopoverTrigger, SR_ONLY, clamp, cn, findNodeAtPosition, findNodePosition, focusNextNode, formatShortcutKey, getAvatar, getElementOverflowPosition, getNodeDisplayName, getSelectedBlockNodes, getSelectedNodesOfType, getSelectionBoundingRect, getUrlParam, handleImageUpload, isAllowedUri, isExtensionAvailable, isMac, isMarkInSchema, isNodeInSchema, isNodeTypeSelected, isSelectionValid, isTextSelectionValid, isValidPosition, parseShortcutKeys, removeEmptyParagraphs, sanitizeUrl, selectCurrentBlockContent, selectionWithinConvertibleTypes, updateNodesAttr, useAIConfig, useAIContext, useTiptapEditor };
|
|
1014
|
-
//# sourceMappingURL=chunk-
|
|
1015
|
-
//# sourceMappingURL=chunk-
|
|
1014
|
+
//# sourceMappingURL=chunk-MGSVKKK7.js.map
|
|
1015
|
+
//# sourceMappingURL=chunk-MGSVKKK7.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/use-tiptap-editor.ts","../src/plugins/ai/use-ai-context.ts","../src/plugins/ai/ai-context.ts","../src/plugins/ai/ai-button-visibility.ts","../src/components/tiptap-icons/sparkles-icon.tsx","../src/components/tiptap-ui-primitive/tooltip/tooltip.tsx","../src/lib/tiptap-utils.ts","../src/components/tiptap-ui-primitive/button/button.tsx","../src/components/tiptap-ui-primitive/popover/popover.tsx","../src/components/tiptap-icons/send-icon.tsx","../src/plugins/ai/ai-dialog.tsx","../src/lib/tiptap-collab-utils.ts","../src/plugins/ai/ai-button.tsx"],"names":["useState","createContext","useContext","jsx","TooltipTrigger","TooltipContent","isMac","jsxs","forwardRef","useMemo","memo","useEffect","NodeSelection","nodeType","CellSelection","useCallback"],"mappings":";;;;;;;;;AAIA,SAAS,oBAAoB,MAAA,EAA+B;AAC1D,EAAA,MAAM,UAAU,MAAA,CAAO,OAAA;AACvB,EAAA,MAAM,QAAQ,OAAA,CAAQ,KAAA;AACtB,EAAA,IAAI,CAAC,KAAA,IAAS,EAAE,cAAA,IAAkB,QAAQ,OAAO,IAAA;AACjD,EAAA,OAAO,MAAM,YAAA,IAAgB,IAAA;AAC/B;AAEO,SAAS,gBAAgB,cAAA,EAI9B;AACA,EAAA,MAAM,EAAE,MAAA,EAAQ,UAAA,EAAW,GAAI,gBAAA,EAAiB;AAChD,EAAA,MAAM,aAAa,cAAA,IAAkB,UAAA;AAErC,EAAA,MAAM,CAAC,aAAA,EAAe,gBAAgB,CAAA,GAAI,SAAwB,IAAI,CAAA;AAEtE,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,IAAI,CAAC,UAAA,EAAY;AACf,MAAA,gBAAA,CAAiB,IAAI,CAAA;AACrB,MAAA;AAAA,IACF;AAEA,IAAA,MAAM,aAAA,GAAgB,MACpB,gBAAA,CAAiB,mBAAA,CAAoB,UAAU,CAAC,CAAA;AAElD,IAAA,aAAA,EAAc;AAEd,IAAA,UAAA,CAAW,EAAA,CAAG,UAAU,aAAa,CAAA;AACrC,IAAA,UAAA,CAAW,EAAA,CAAG,mBAAmB,aAAa,CAAA;AAE9C,IAAA,OAAO,MAAM;AACX,MAAA,UAAA,CAAW,GAAA,CAAI,UAAU,aAAa,CAAA;AACtC,MAAA,UAAA,CAAW,GAAA,CAAI,mBAAmB,aAAa,CAAA;AAAA,IACjD,CAAA;AAAA,EACF,CAAA,EAAG,CAAC,UAAU,CAAC,CAAA;AAEf,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,IAAI,CAAC,aAAA,EAAe;AAEpB,IAAA,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AA,EAAK,QAAA;AAAA,UACL,QAAA,EAAU,EAAA;AAAA,UACV,YAAA,EAAW,cAAA;AAAA,UACX,OAAA,EAAQ,cAAA;AAAA,UACR,OAAA,EAAS,WAAA;AAAA,UACR,GAAG,WAAA;AAAA,UAEJ,QAAA,kBAAAA,GAAAA,CAAC,YAAA,EAAA,EAAa,SAAA,EAAU,oBAAA,EAAqB;AAAA;AAAA,OAC/C,EACF,CAAA;AAAA,sBAGAA,IAAC,cAAA,EAAA,EAAe,IAAA,EAAK,OAAM,KAAA,EAAM,OAAA,EAAQ,UAAA,EAAY,CAAA,EACnD,QAAA,kBAAAA,GAAAA;AAAA,QAAC,QAAA;AAAA,QAAA;AAAA,UACC,MAAA;AAAA,UACA,MAAA;AAAA,UACA,YAAA;AAAA,UACA,OAAA,EAAS,MAAM,gBAAA,CAAiB,KAAK;AAAA;AAAA,OACvC,EACF;AAAA,KAAA,EACF,CAAA;AAAA,EAEJ;AACF;AAEA,QAAA,CAAS,WAAA,GAAc,UAAA","file":"chunk-QMYT5WXO.js","sourcesContent":["import type { Editor } from \"@tiptap/react\"\nimport { useCurrentEditor, useEditorState } from \"@tiptap/react\"\nimport { useEffect, useState } from \"react\"\n\nfunction getActivePageEditor(editor: Editor): Editor | null {\n const storage = editor.storage as unknown as Record<string, unknown>\n const pages = storage.pages as { activeEditor?: Editor | null } | undefined\n if (!pages || !(\"activeEditor\" in pages)) return null\n return pages.activeEditor ?? null\n}\n\nexport function useTiptapEditor(providedEditor?: Editor | null): {\n editor: Editor | null\n editorState?: Editor[\"state\"]\n canCommand?: Editor[\"can\"]\n} {\n const { editor: coreEditor } = useCurrentEditor()\n const mainEditor = providedEditor ?? coreEditor\n\n const [storageEditor, setStorageEditor] = useState<Editor | null>(null)\n\n useEffect(() => {\n if (!mainEditor) {\n setStorageEditor(null)\n return\n }\n\n const updateHandler = () =>\n setStorageEditor(getActivePageEditor(mainEditor))\n\n updateHandler()\n\n mainEditor.on(\"update\", updateHandler)\n mainEditor.on(\"selectionUpdate\", updateHandler)\n\n return () => {\n mainEditor.off(\"update\", updateHandler)\n mainEditor.off(\"selectionUpdate\", updateHandler)\n }\n }, [mainEditor])\n\n useEffect(() => {\n if (!storageEditor) return\n\n const handleDestroy = () => setStorageEditor(null)\n\n storageEditor.on(\"destroy\", handleDestroy)\n return () => {\n storageEditor.off(\"destroy\", handleDestroy)\n }\n }, [storageEditor])\n\n const editorState = useEditorState({\n editor: storageEditor ?? mainEditor,\n selector(context) {\n if (!context.editor) {\n return { editor: null, editorState: undefined, canCommand: undefined }\n }\n\n return {\n editor: context.editor,\n editorState: context.editor.state,\n canCommand: context.editor.can,\n }\n },\n })\n\n return editorState ?? { editor: null }\n}\n","import { useCallback } from \"react\"\nimport type { Editor } from \"@tiptap/react\"\nimport type { AIContextData } from \"./types\"\n\nconst CONTEXT_WINDOW_SIZE = 300\n\n/**\n * Extract text content from a Tiptap node recursively\n */\nfunction extractTextFromNode(node: any): string {\n if (node.isText) {\n return node.text || \"\"\n }\n if (node.content) {\n return node.content.map(extractTextFromNode).join(\"\")\n }\n return \"\"\n}\n\n/**\n * Get text at a specific position in the document\n */\nfunction getTextAtPosition(editor: Editor, pos: number, length: number): string {\n try {\n const { from, to } = editor.state.selection\n const $from = editor.state.doc.resolve(Math.max(1, pos - length))\n const $to = editor.state.doc.resolve(Math.min(editor.state.doc.content.size, pos + length))\n return editor.state.doc.textBetween($from.pos, $to.pos, \"\\n\", \" \")\n } catch {\n return \"\"\n }\n}\n\n/**\n * Get the node type at the current selection\n */\nfunction getNodeTypeAtSelection(editor: Editor): string | undefined {\n const { from } = editor.state.selection\n const $from = editor.state.doc.resolve(from)\n return $from.parent.type.name\n}\n\n/**\n * Get the heading level if the selection is inside a heading\n */\nfunction getHeadingLevel(editor: Editor): number | undefined {\n const { from } = editor.state.selection\n const $from = editor.state.doc.resolve(from)\n\n for (let d = $from.depth; d > 0; d--) {\n const node = $from.node(d)\n const match = node.type.name.match(/heading(\\d)/)\n if (match) {\n return parseInt(match[1], 10)\n }\n }\n\n return undefined\n}\n\n/**\n * Get the full document as text\n */\nfunction getFullDocument(editor: Editor): string {\n return editor.state.doc.textContent\n}\n\nexport function useAIContext(editor: Editor | null) {\n const buildContext = useCallback(\n (prompt: string): AIContextData | null => {\n if (!editor) {\n return null\n }\n\n const { from, to } = editor.state.selection\n const selectedText = editor.state.doc.textBetween(from, to)\n\n if (!selectedText) {\n return null\n }\n\n // Get the line and column number (simplified: count newlines before selection)\n const textBefore = editor.state.doc.textBetween(0, from)\n const lines = textBefore.split(\"\\n\")\n const line = lines.length\n const column = lines[lines.length - 1].length\n\n // Get surrounding context\n const precedingPos = Math.max(1, from - CONTEXT_WINDOW_SIZE)\n const followingPos = Math.min(editor.state.doc.content.size, to + CONTEXT_WINDOW_SIZE)\n\n const precedingText = editor.state.doc.textBetween(precedingPos, from)\n const followingText = editor.state.doc.textBetween(to, followingPos)\n\n return {\n prompt,\n selectedText,\n position: {\n line,\n column,\n },\n precedingText,\n followingText,\n nodeType: getNodeTypeAtSelection(editor),\n currentHeadingLevel: getHeadingLevel(editor),\n fullDocument: getFullDocument(editor),\n documentFormat: \"markdown\",\n }\n },\n [editor]\n )\n\n return { buildContext }\n}\n","import { createContext, useContext } from \"react\"\nimport type { AIPluginConfig } from \"./types\"\n\nexport const AIConfigContext = createContext<AIPluginConfig | null>(null)\n\nexport function useAIConfig(): AIPluginConfig | null {\n return useContext(AIConfigContext)\n}\n","export interface AIButtonVisibilityInput {\n /** 插件配置里的开关(`enabled !== false`)。 */\n enabled: boolean\n /** 「没得用就藏起来」。 */\n hideWhenUnavailable: boolean\n /** 编辑器是否可编辑。 */\n isEditable: boolean\n /** 当前选区是否可以拿去问 AI。 */\n hasValidSelection: boolean\n}\n\n/**\n * AI 按钮该不该渲染。\n *\n * 抽成纯函数不是为了复用,是为了能测 —— 这个判断写在组件里时曾经把\n * `hideWhenUnavailable` 取反用(`!hideWhenUnavailable && hasValidSelection`),\n * 于是工具栏传 `true` 的那条路上按钮**永远**渲染不出来,而构建、类型、\n * 导出检查全是绿的。一个布尔取反,静态手段一个都拦不住。\n */\nexport const shouldShowAIButton = ({\n enabled,\n hideWhenUnavailable,\n isEditable,\n hasValidSelection,\n}: AIButtonVisibilityInput): boolean =>\n enabled && (hideWhenUnavailable ? hasValidSelection : isEditable)\n","import { memo } from \"react\"\n\ntype SvgProps = React.ComponentPropsWithoutRef<\"svg\">\n\nexport const SparklesIcon = memo(({ className, ...props }: SvgProps) => {\n return (\n <svg\n width=\"24\"\n height=\"24\"\n className={className}\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <path\n d=\"M12 3L13.6392 8.20749C13.8353 8.83063 13.9333 9.14219 14.0982 9.40653C14.2442 9.64066 14.4276 9.84607 14.6402 10.0143C14.8802 10.2042 15.1679 10.3345 15.7434 10.5952L20.5 12L15.7434 13.4048C15.1679 13.6655 14.8802 13.7958 14.6402 13.9857C14.4276 14.1539 14.2442 14.3593 14.0982 14.5935C13.9333 14.8578 13.8353 15.1694 13.6392 15.7925L12 21L10.3608 15.7925C10.1647 15.1694 10.0667 14.8578 9.90182 14.5935C9.75583 14.3593 9.57241 14.1539 9.35983 13.9857C9.11985 13.7958 8.83209 13.6655 8.25659 13.4048L3.5 12L8.25659 10.5952C8.83209 10.3345 9.11985 10.2042 9.35983 10.0143C9.57241 9.84607 9.75583 9.64066 9.90182 9.40653C10.0667 9.14219 10.1647 8.83063 10.3608 8.20749L12 3Z\"\n stroke=\"currentColor\"\n strokeWidth=\"1.6\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n />\n <path\n d=\"M18.5 3.5L18.9 4.85C19 5.15 19.05 5.3 19.14 5.42C19.21 5.53 19.31 5.63 19.42 5.7C19.54 5.79 19.69 5.84 19.99 5.94L21.34 6.34L19.99 6.74C19.69 6.84 19.54 6.89 19.42 6.98C19.31 7.05 19.21 7.15 19.14 7.26C19.05 7.38 19 7.53 18.9 7.83L18.5 9.18L18.1 7.83C18 7.53 17.95 7.38 17.86 7.26C17.79 7.15 17.69 7.05 17.58 6.98C17.46 6.89 17.31 6.84 17.01 6.74L15.66 6.34L17.01 5.94C17.31 5.84 17.46 5.79 17.58 5.7C17.69 5.63 17.79 5.53 17.86 5.42C17.95 5.3 18 5.15 18.1 4.85L18.5 3.5Z\"\n stroke=\"currentColor\"\n strokeWidth=\"1.4\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n />\n </svg>\n )\n})\n\nSparklesIcon.displayName = \"SparklesIcon\"\n","import {\n cloneElement,\n createContext,\n forwardRef,\n isValidElement,\n useContext,\n useMemo,\n useState,\n version,\n} from \"react\"\nimport {\n useFloating,\n autoUpdate,\n offset,\n flip,\n shift,\n useHover,\n useFocus,\n useDismiss,\n useRole,\n useInteractions,\n useMergeRefs,\n FloatingPortal,\n type Placement,\n type UseFloatingReturn,\n type ReferenceType,\n FloatingDelayGroup,\n} from \"@floating-ui/react\"\nimport \"./tooltip.scss\"\n\ninterface TooltipProviderProps {\n children: React.ReactNode\n initialOpen?: boolean\n placement?: Placement\n open?: boolean\n onOpenChange?: (open: boolean) => void\n delay?: number\n closeDelay?: number\n timeout?: number\n useDelayGroup?: boolean\n}\n\ninterface TooltipTriggerProps extends Omit<\n React.HTMLProps<HTMLElement>,\n \"ref\"\n> {\n asChild?: boolean\n children: React.ReactNode\n}\n\ninterface TooltipContentProps extends Omit<\n React.HTMLProps<HTMLDivElement>,\n \"ref\"\n> {\n children?: React.ReactNode\n portal?: boolean\n portalProps?: Omit<React.ComponentProps<typeof FloatingPortal>, \"children\">\n}\n\ninterface TooltipContextValue extends UseFloatingReturn<ReferenceType> {\n open: boolean\n setOpen: (open: boolean) => void\n getReferenceProps: (\n userProps?: React.HTMLProps<HTMLElement>\n ) => Record<string, unknown>\n getFloatingProps: (\n userProps?: React.HTMLProps<HTMLDivElement>\n ) => Record<string, unknown>\n}\n\nfunction useTooltip({\n initialOpen = false,\n placement = \"top\",\n open: controlledOpen,\n onOpenChange: setControlledOpen,\n delay = 600,\n closeDelay = 0,\n}: Omit<TooltipProviderProps, \"children\"> = {}) {\n const [uncontrolledOpen, setUncontrolledOpen] = useState<boolean>(initialOpen)\n\n const open = controlledOpen ?? uncontrolledOpen\n const setOpen = setControlledOpen ?? setUncontrolledOpen\n\n const data = useFloating({\n placement,\n open,\n onOpenChange: setOpen,\n whileElementsMounted: autoUpdate,\n middleware: [\n offset(4),\n flip({\n crossAxis: placement.includes(\"-\"),\n fallbackAxisSideDirection: \"start\",\n padding: 4,\n }),\n shift({ padding: 4 }),\n ],\n })\n\n const context = data.context\n\n const hover = useHover(context, {\n mouseOnly: true,\n move: false,\n restMs: delay,\n enabled: controlledOpen == null,\n delay: {\n close: closeDelay,\n },\n })\n const focus = useFocus(context, {\n enabled: controlledOpen == null,\n })\n const dismiss = useDismiss(context)\n const role = useRole(context, { role: \"tooltip\" })\n\n const interactions = useInteractions([hover, focus, dismiss, role])\n\n return useMemo(\n () => ({\n open,\n setOpen,\n ...interactions,\n ...data,\n }),\n [open, setOpen, interactions, data]\n )\n}\n\nconst TooltipContext = createContext<TooltipContextValue | null>(null)\n\nfunction useTooltipContext() {\n const context = useContext(TooltipContext)\n\n if (context == null) {\n throw new Error(\"Tooltip components must be wrapped in <TooltipProvider />\")\n }\n\n return context\n}\n\nexport function Tooltip({ children, ...props }: TooltipProviderProps) {\n const tooltip = useTooltip(props)\n\n if (!props.useDelayGroup) {\n return (\n <TooltipContext.Provider value={tooltip}>\n {children}\n </TooltipContext.Provider>\n )\n }\n\n return (\n <FloatingDelayGroup\n delay={{ open: props.delay ?? 0, close: props.closeDelay ?? 0 }}\n timeoutMs={props.timeout}\n >\n <TooltipContext.Provider value={tooltip}>\n {children}\n </TooltipContext.Provider>\n </FloatingDelayGroup>\n )\n}\n\nexport const TooltipTrigger = forwardRef<HTMLElement, TooltipTriggerProps>(\n function TooltipTrigger({ children, asChild = false, ...props }, propRef) {\n const context = useTooltipContext()\n const childrenRef = isValidElement(children)\n ? parseInt(version, 10) >= 19\n ? // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (children as { props: { ref?: React.Ref<any> } }).props.ref\n : // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (children as any).ref\n : undefined\n const ref = useMergeRefs([context.refs.setReference, propRef, childrenRef])\n\n if (asChild && isValidElement(children)) {\n const dataAttributes = {\n \"data-tooltip-state\": context.open ? \"open\" : \"closed\",\n }\n\n return cloneElement(\n children,\n context.getReferenceProps({\n ref,\n ...props,\n ...(typeof children.props === \"object\" ? children.props : {}),\n ...dataAttributes,\n })\n )\n }\n\n return (\n <button\n ref={ref}\n data-tooltip-state={context.open ? \"open\" : \"closed\"}\n {...context.getReferenceProps(props)}\n >\n {children}\n </button>\n )\n }\n)\n\nexport const TooltipContent = forwardRef<HTMLDivElement, TooltipContentProps>(\n function TooltipContent(\n { style, children, portal = true, portalProps = {}, ...props },\n propRef\n ) {\n const context = useTooltipContext()\n const ref = useMergeRefs([context.refs.setFloating, propRef])\n\n if (!context.open) return null\n\n const content = (\n <div\n ref={ref}\n style={{\n ...context.floatingStyles,\n ...style,\n }}\n {...context.getFloatingProps(props)}\n className=\"tiptap-tooltip\"\n >\n {children}\n </div>\n )\n\n if (portal) {\n return <FloatingPortal {...portalProps}>{content}</FloatingPortal>\n }\n\n return content\n }\n)\n\nTooltip.displayName = \"Tooltip\"\nTooltipTrigger.displayName = \"TooltipTrigger\"\nTooltipContent.displayName = \"TooltipContent\"\n","import type { Node as PMNode } from \"@tiptap/pm/model\"\nimport type { Transaction } from \"@tiptap/pm/state\"\nimport {\n AllSelection,\n NodeSelection,\n Selection,\n TextSelection,\n} from \"@tiptap/pm/state\"\nimport { cellAround, CellSelection } from \"@tiptap/pm/tables\"\nimport {\n findParentNodeClosestToPos,\n type Editor,\n type NodeWithPos,\n} from \"@tiptap/react\"\n\nexport const MAX_FILE_SIZE = 5 * 1024 * 1024 // 5MB\n\nexport const MAC_SYMBOLS: Record<string, string> = {\n mod: \"⌘\",\n command: \"⌘\",\n meta: \"⌘\",\n ctrl: \"⌃\",\n control: \"⌃\",\n alt: \"⌥\",\n option: \"⌥\",\n shift: \"⇧\",\n backspace: \"Del\",\n delete: \"⌦\",\n enter: \"⏎\",\n escape: \"⎋\",\n capslock: \"⇪\",\n} as const\n\nexport const SR_ONLY = {\n position: \"absolute\",\n width: \"1px\",\n height: \"1px\",\n padding: 0,\n margin: \"-1px\",\n overflow: \"hidden\",\n clip: \"rect(0, 0, 0, 0)\",\n whiteSpace: \"nowrap\",\n borderWidth: 0,\n} as const\n\nexport function cn(\n ...classes: (string | boolean | undefined | null)[]\n): string {\n return classes.filter(Boolean).join(\" \")\n}\n\n/**\n * Determines if the current platform is macOS\n * @returns boolean indicating if the current platform is Mac\n */\nexport function isMac(): boolean {\n return (\n typeof navigator !== \"undefined\" &&\n navigator.platform.toLowerCase().includes(\"mac\")\n )\n}\n\n/**\n * Formats a shortcut key based on the platform (Mac or non-Mac)\n * @param key - The key to format (e.g., \"ctrl\", \"alt\", \"shift\")\n * @param isMac - Boolean indicating if the platform is Mac\n * @param capitalize - Whether to capitalize the key (default: true)\n * @returns Formatted shortcut key symbol\n */\nexport const formatShortcutKey = (\n key: string,\n isMac: boolean,\n capitalize: boolean = true\n) => {\n if (isMac) {\n const lowerKey = key.toLowerCase()\n return MAC_SYMBOLS[lowerKey] || (capitalize ? key.toUpperCase() : key)\n }\n\n return capitalize ? key.charAt(0).toUpperCase() + key.slice(1) : key\n}\n\n/**\n * Parses a shortcut key string into an array of formatted key symbols\n * @param shortcutKeys - The string of shortcut keys (e.g., \"ctrl-alt-shift\")\n * @param delimiter - The delimiter used to split the keys (default: \"-\")\n * @param capitalize - Whether to capitalize the keys (default: true)\n * @returns Array of formatted shortcut key symbols\n */\nexport const parseShortcutKeys = (props: {\n shortcutKeys: string | undefined\n delimiter?: string\n capitalize?: boolean\n}) => {\n const { shortcutKeys, delimiter = \"+\", capitalize = true } = props\n\n if (!shortcutKeys) return []\n\n return shortcutKeys\n .split(delimiter)\n .map((key) => key.trim())\n .map((key) => formatShortcutKey(key, isMac(), capitalize))\n}\n\n/**\n * Checks if a mark exists in the editor schema\n * @param markName - The name of the mark to check\n * @param editor - The editor instance\n * @returns boolean indicating if the mark exists in the schema\n */\nexport const isMarkInSchema = (\n markName: string,\n editor: Editor | null\n): boolean => {\n if (!editor?.schema) return false\n return editor.schema.spec.marks.get(markName) !== undefined\n}\n\n/**\n * Checks if a node exists in the editor schema\n * @param nodeName - The name of the node to check\n * @param editor - The editor instance\n * @returns boolean indicating if the node exists in the schema\n */\nexport const isNodeInSchema = (\n nodeName: string,\n editor: Editor | null\n): boolean => {\n if (!editor?.schema) return false\n return editor.schema.spec.nodes.get(nodeName) !== undefined\n}\n\n/**\n * Moves the focus to the next node in the editor\n * @param editor - The editor instance\n * @returns boolean indicating if the focus was moved\n */\nexport function focusNextNode(editor: Editor) {\n const { state, view } = editor\n const { doc, selection } = state\n\n const nextSel = Selection.findFrom(selection.$to, 1, true)\n if (nextSel) {\n view.dispatch(state.tr.setSelection(nextSel).scrollIntoView())\n return true\n }\n\n const paragraphType = state.schema.nodes.paragraph\n if (!paragraphType) {\n console.warn(\"No paragraph node type found in schema.\")\n return false\n }\n\n const end = doc.content.size\n const para = paragraphType.create()\n let tr = state.tr.insert(end, para)\n\n // Place the selection inside the new paragraph\n const $inside = tr.doc.resolve(end + 1)\n tr = tr.setSelection(TextSelection.near($inside)).scrollIntoView()\n view.dispatch(tr)\n return true\n}\n\n/**\n * Checks if a value is a valid number (not null, undefined, or NaN)\n * @param value - The value to check\n * @returns boolean indicating if the value is a valid number\n */\nexport function isValidPosition(pos: number | null | undefined): pos is number {\n return typeof pos === \"number\" && pos >= 0\n}\n\n/**\n * Checks if one or more extensions are registered in the Tiptap editor.\n * @param editor - The Tiptap editor instance\n * @param extensionNames - A single extension name or an array of names to check\n * @returns True if at least one of the extensions is available, false otherwise\n */\nexport function isExtensionAvailable(\n editor: Editor | null,\n extensionNames: string | string[]\n): boolean {\n if (!editor) return false\n\n const names = Array.isArray(extensionNames)\n ? extensionNames\n : [extensionNames]\n\n const found = names.some((name) =>\n editor.extensionManager.extensions.some((ext) => ext.name === name)\n )\n\n if (!found) {\n console.warn(\n `None of the extensions [${names.join(\", \")}] were found in the editor schema. Ensure they are included in the editor configuration.`\n )\n }\n\n return found\n}\n\n/**\n * Finds a node at the specified position with error handling\n * @param editor The Tiptap editor instance\n * @param position The position in the document to find the node\n * @returns The node at the specified position, or null if not found\n */\nexport function findNodeAtPosition(editor: Editor, position: number) {\n try {\n const node = editor.state.doc.nodeAt(position)\n if (!node) {\n console.warn(`No node found at position ${position}`)\n return null\n }\n return node\n } catch (error) {\n console.error(`Error getting node at position ${position}:`, error)\n return null\n }\n}\n\n/**\n * Finds the position and instance of a node in the document\n * @param props Object containing editor, node (optional), and nodePos (optional)\n * @param props.editor The Tiptap editor instance\n * @param props.node The node to find (optional if nodePos is provided)\n * @param props.nodePos The position of the node to find (optional if node is provided)\n * @returns An object with the position and node, or null if not found\n */\nexport function findNodePosition(props: {\n editor: Editor | null\n node?: PMNode | null\n nodePos?: number | null\n}): { pos: number; node: PMNode } | null {\n const { editor, node, nodePos } = props\n\n if (!editor || !editor.state?.doc) return null\n\n // Zero is valid position\n const hasValidNode = node !== undefined && node !== null\n const hasValidPos = isValidPosition(nodePos)\n\n if (!hasValidNode && !hasValidPos) {\n return null\n }\n\n // First search for the node in the document if we have a node\n if (hasValidNode) {\n let foundPos = -1\n let foundNode: PMNode | null = null\n\n editor.state.doc.descendants((currentNode, pos) => {\n // TODO: Needed?\n // if (currentNode.type && currentNode.type.name === node!.type.name) {\n if (currentNode === node) {\n foundPos = pos\n foundNode = currentNode\n return false\n }\n return true\n })\n\n if (foundPos !== -1 && foundNode !== null) {\n return { pos: foundPos, node: foundNode }\n }\n }\n\n // If we have a valid position, use findNodeAtPosition\n if (hasValidPos) {\n const nodeAtPos = findNodeAtPosition(editor, nodePos!)\n if (nodeAtPos) {\n return { pos: nodePos!, node: nodeAtPos }\n }\n }\n\n return null\n}\n\n/**\n * Determines whether the current selection contains a node whose type matches\n * any of the provided node type names.\n * @param editor Tiptap editor instance\n * @param nodeTypeNames List of node type names to match against\n * @param checkAncestorNodes Whether to check ancestor node types up the depth chain\n */\nexport function isNodeTypeSelected(\n editor: Editor | null,\n nodeTypeNames: string[] = [],\n checkAncestorNodes: boolean = false\n): boolean {\n if (!editor || !editor.state.selection) return false\n\n const { selection } = editor.state\n if (selection.empty) return false\n\n // Direct node selection check\n if (selection instanceof NodeSelection) {\n const selectedNode = selection.node\n return selectedNode ? nodeTypeNames.includes(selectedNode.type.name) : false\n }\n\n // Depth-based ancestor node check\n if (checkAncestorNodes) {\n const { $from } = selection\n for (let depth = $from.depth; depth > 0; depth--) {\n const ancestorNode = $from.node(depth)\n if (nodeTypeNames.includes(ancestorNode.type.name)) {\n return true\n }\n }\n }\n\n return false\n}\n\n/**\n * Check whether the current selection is fully within nodes\n * whose type names are in the provided `types` list.\n *\n * - NodeSelection → checks the selected node.\n * - Text/AllSelection → ensures all textblocks within [from, to) are allowed.\n */\nexport function selectionWithinConvertibleTypes(\n editor: Editor,\n types: string[] = []\n): boolean {\n if (!editor || types.length === 0) return false\n\n const { state } = editor\n const { selection } = state\n const allowed = new Set(types)\n\n if (selection instanceof NodeSelection) {\n const nodeType = selection.node?.type?.name\n return !!nodeType && allowed.has(nodeType)\n }\n\n if (selection instanceof TextSelection || selection instanceof AllSelection) {\n let valid = true\n state.doc.nodesBetween(selection.from, selection.to, (node) => {\n if (node.isTextblock && !allowed.has(node.type.name)) {\n valid = false\n return false // stop early\n }\n return valid\n })\n return valid\n }\n\n return false\n}\n\n/**\n * Handles image upload with progress tracking and abort capability\n * @param file The file to upload\n * @param onProgress Optional callback for tracking upload progress\n * @param abortSignal Optional AbortSignal for cancelling the upload\n * @returns Promise resolving to the URL of the uploaded image\n */\nexport const handleImageUpload = async (\n file: File,\n onProgress?: (event: { progress: number }) => void,\n abortSignal?: AbortSignal\n): Promise<string> => {\n // Validate file\n if (!file) {\n throw new Error(\"No file provided\")\n }\n\n if (file.size > MAX_FILE_SIZE) {\n throw new Error(\n `File size exceeds maximum allowed (${MAX_FILE_SIZE / (1024 * 1024)}MB)`\n )\n }\n\n // For demo/testing: Simulate upload progress. In production, replace the following code\n // with your own upload implementation.\n for (let progress = 0; progress <= 100; progress += 10) {\n if (abortSignal?.aborted) {\n throw new Error(\"Upload cancelled\")\n }\n await new Promise((resolve) => setTimeout(resolve, 500))\n onProgress?.({ progress })\n }\n\n return \"/images/tiptap-ui-placeholder-image.jpg\"\n}\n\ntype ProtocolOptions = {\n /**\n * The protocol scheme to be registered.\n * @default '''\n * @example 'ftp'\n * @example 'git'\n */\n scheme: string\n\n /**\n * If enabled, it allows optional slashes after the protocol.\n * @default false\n * @example true\n */\n optionalSlashes?: boolean\n}\n\ntype ProtocolConfig = Array<ProtocolOptions | string>\n\nconst ATTR_WHITESPACE =\n // eslint-disable-next-line no-control-regex\n /[\\u0000-\\u0020\\u00A0\\u1680\\u180E\\u2000-\\u2029\\u205F\\u3000]/g\n\nexport function isAllowedUri(\n uri: string | undefined,\n protocols?: ProtocolConfig\n) {\n const allowedProtocols: string[] = [\n \"http\",\n \"https\",\n \"ftp\",\n \"ftps\",\n \"mailto\",\n \"tel\",\n \"callto\",\n \"sms\",\n \"cid\",\n \"xmpp\",\n ]\n\n if (protocols) {\n protocols.forEach((protocol) => {\n const nextProtocol =\n typeof protocol === \"string\" ? protocol : protocol.scheme\n\n if (nextProtocol) {\n allowedProtocols.push(nextProtocol)\n }\n })\n }\n\n return (\n !uri ||\n uri.replace(ATTR_WHITESPACE, \"\").match(\n new RegExp(\n // eslint-disable-next-line no-useless-escape\n `^(?:(?:${allowedProtocols.join(\"|\")}):|[^a-z]|[a-z0-9+.\\-]+(?:[^a-z+.\\-:]|$))`,\n \"i\"\n )\n )\n )\n}\n\nexport function sanitizeUrl(\n inputUrl: string,\n baseUrl: string,\n protocols?: ProtocolConfig\n): string {\n try {\n const url = new URL(inputUrl, baseUrl)\n\n if (isAllowedUri(url.href, protocols)) {\n return url.href\n }\n } catch {\n // If URL creation fails, it's considered invalid\n }\n return \"#\"\n}\n\n/**\n * Update a single attribute on multiple nodes.\n *\n * @param tr - The transaction to mutate\n * @param targets - Array of { node, pos }\n * @param attrName - Attribute key to update\n * @param next - New value OR updater function receiving previous value\n * Pass `undefined` to remove the attribute.\n * @returns true if at least one node was updated, false otherwise\n */\nexport function updateNodesAttr<A extends string = string, V = unknown>(\n tr: Transaction,\n targets: readonly NodeWithPos[],\n attrName: A,\n next: V | ((prev: V | undefined) => V | undefined)\n): boolean {\n if (!targets.length) return false\n\n let changed = false\n\n for (const { pos } of targets) {\n // Always re-read from the transaction's current doc\n const currentNode = tr.doc.nodeAt(pos)\n if (!currentNode) continue\n\n const prevValue = (currentNode.attrs as Record<string, unknown>)[\n attrName\n ] as V | undefined\n const resolvedNext =\n typeof next === \"function\"\n ? (next as (p: V | undefined) => V | undefined)(prevValue)\n : next\n\n if (prevValue === resolvedNext) continue\n\n const nextAttrs: Record<string, unknown> = { ...currentNode.attrs }\n if (resolvedNext === undefined) {\n // Remove the key entirely instead of setting null\n delete nextAttrs[attrName]\n } else {\n nextAttrs[attrName] = resolvedNext\n }\n\n tr.setNodeMarkup(pos, undefined, nextAttrs)\n changed = true\n }\n\n return changed\n}\n\n/**\n * Selects the entire content of the current block node if the selection is empty.\n * If the selection is not empty, it does nothing.\n * @param editor The Tiptap editor instance\n */\nexport function selectCurrentBlockContent(editor: Editor) {\n const { selection, doc } = editor.state\n\n if (!selection.empty) return\n\n const $pos = selection.$from\n let blockNode: PMNode | null = null\n let blockPos = -1\n\n for (let depth = $pos.depth; depth >= 0; depth--) {\n const node = $pos.node(depth)\n const pos = $pos.start(depth)\n\n if (node.isBlock && node.textContent.trim()) {\n blockNode = node\n blockPos = pos\n break\n }\n }\n\n if (blockNode && blockPos >= 0) {\n const from = blockPos\n const to = blockPos + blockNode.nodeSize - 2 // -2 to exclude the closing tag\n\n if (from < to) {\n const $from = doc.resolve(from)\n const $to = doc.resolve(to)\n const newSelection = TextSelection.between($from, $to, 1)\n\n if (newSelection && !selection.eq(newSelection)) {\n editor.view.dispatch(editor.state.tr.setSelection(newSelection))\n }\n }\n }\n}\n\n/**\n * Retrieves all nodes of specified types from the current selection.\n * @param selection The current editor selection\n * @param allowedNodeTypes An array of node type names to look for (e.g., [\"image\", \"table\"])\n * @returns An array of objects containing the node and its position\n */\nexport function getSelectedNodesOfType(\n selection: Selection,\n allowedNodeTypes: string[]\n): NodeWithPos[] {\n const results: NodeWithPos[] = []\n const allowed = new Set(allowedNodeTypes)\n\n if (selection instanceof CellSelection) {\n selection.forEachCell((node: PMNode, pos: number) => {\n if (allowed.has(node.type.name)) {\n results.push({ node, pos })\n }\n })\n return results\n }\n\n if (selection instanceof NodeSelection) {\n const { node, from: pos } = selection\n if (node && allowed.has(node.type.name)) {\n results.push({ node, pos })\n }\n return results\n }\n\n const { $anchor } = selection\n const cell = cellAround($anchor)\n\n if (cell) {\n const cellNode = selection.$anchor.doc.nodeAt(cell.pos)\n if (cellNode && allowed.has(cellNode.type.name)) {\n results.push({ node: cellNode, pos: cell.pos })\n return results\n }\n }\n\n // Fallback: find parent nodes of allowed types\n const parentNode = findParentNodeClosestToPos($anchor, (node) =>\n allowed.has(node.type.name)\n )\n\n if (parentNode) {\n results.push({ node: parentNode.node, pos: parentNode.pos })\n }\n\n return results\n}\n\n/**\n * Clamps a value between min and max bounds\n */\nexport function clamp(value: number, min: number, max: number): number {\n return Math.max(min, Math.min(value, max))\n}\n\nexport function getSelectedBlockNodes(editor: Editor): PMNode[] {\n const { doc } = editor.state\n const { from, to } = editor.state.selection\n\n const blocks: PMNode[] = []\n const seen = new Set<number>()\n\n doc.nodesBetween(from, to, (node, pos) => {\n if (!node.isBlock) return\n\n if (!seen.has(pos)) {\n seen.add(pos)\n blocks.push(node)\n }\n\n return false\n })\n\n return blocks\n}\n","import { forwardRef, Fragment, useMemo } from \"react\"\n\n// --- Tiptap UI Primitive ---\nimport {\n Tooltip,\n TooltipContent,\n TooltipTrigger,\n} from \"../tooltip\"\n\n// --- Lib ---\nimport { cn, parseShortcutKeys } from \"../../../lib/tiptap-utils\"\n\nimport \"./button-colors.scss\"\nimport \"./button.scss\"\n\nexport type ButtonVariant = \"ghost\" | \"primary\"\nexport type ButtonSize = \"small\" | \"default\" | \"large\"\n\nexport interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {\n showTooltip?: boolean\n tooltip?: React.ReactNode\n shortcutKeys?: string\n variant?: ButtonVariant\n size?: ButtonSize\n}\n\nexport const ShortcutDisplay: React.FC<{ shortcuts: string[] }> = ({\n shortcuts,\n}) => {\n if (shortcuts.length === 0) return null\n\n return (\n <div>\n {shortcuts.map((key, index) => (\n <Fragment key={index}>\n {index > 0 && <kbd>+</kbd>}\n <kbd>{key}</kbd>\n </Fragment>\n ))}\n </div>\n )\n}\n\nexport const Button = forwardRef<HTMLButtonElement, ButtonProps>(\n (\n {\n className,\n children,\n tooltip,\n showTooltip = true,\n shortcutKeys,\n variant,\n size,\n ...props\n },\n ref\n ) => {\n const shortcuts = useMemo<string[]>(\n () => parseShortcutKeys({ shortcutKeys }),\n [shortcutKeys]\n )\n\n if (!tooltip || !showTooltip) {\n return (\n <button\n data-slot=\"tiptap-button\"\n className={cn(\"tiptap-button\", className)}\n ref={ref}\n data-style={variant}\n data-size={size}\n {...props}\n >\n {children}\n </button>\n )\n }\n\n return (\n <Tooltip delay={200}>\n <TooltipTrigger\n data-slot=\"tiptap-button\"\n className={cn(\"tiptap-button\", className)}\n ref={ref}\n data-style={variant}\n data-size={size}\n {...props}\n >\n {children}\n </TooltipTrigger>\n <TooltipContent>\n {tooltip}\n <ShortcutDisplay shortcuts={shortcuts} />\n </TooltipContent>\n </Tooltip>\n )\n }\n)\n\nButton.displayName = \"Button\"\n\nexport default Button\n","\"use client\"\n\nimport * as PopoverPrimitive from \"@radix-ui/react-popover\"\nimport { cn } from \"../../../lib/tiptap-utils\"\nimport \"./popover.scss\"\n\nfunction Popover({\n ...props\n}: React.ComponentProps<typeof PopoverPrimitive.Root>) {\n return <PopoverPrimitive.Root {...props} />\n}\n\nfunction PopoverTrigger({\n ...props\n}: React.ComponentProps<typeof PopoverPrimitive.Trigger>) {\n return <PopoverPrimitive.Trigger {...props} />\n}\n\nfunction PopoverContent({\n className,\n align = \"center\",\n sideOffset = 4,\n ...props\n}: React.ComponentProps<typeof PopoverPrimitive.Content>) {\n return (\n <PopoverPrimitive.Portal>\n <PopoverPrimitive.Content\n align={align}\n sideOffset={sideOffset}\n className={cn(\"tiptap-popover\", className)}\n {...props}\n />\n </PopoverPrimitive.Portal>\n )\n}\n\nexport { Popover, PopoverTrigger, PopoverContent }\n","import { memo } from \"react\"\n\ntype SvgProps = React.ComponentPropsWithoutRef<\"svg\">\n\n/** 向上的箭头 —— 提交态用,和聊天输入框那颗圆形发送键同义。 */\nexport const SendIcon = memo(({ className, ...props }: SvgProps) => {\n return (\n <svg\n width=\"24\"\n height=\"24\"\n className={className}\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <path\n d=\"M12 19V5M12 5L6 11M12 5L18 11\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n />\n </svg>\n )\n})\n\nSendIcon.displayName = \"SendIcon\"\n","\"use client\"\n\nimport { useEffect, useRef, useState } from \"react\"\nimport type { Editor } from \"@tiptap/react\"\n\n// --- Types ---\nimport type { AIContextData, AIPluginConfig } from \"./types\"\n\n// --- Icons ---\nimport { SendIcon } from \"../../components/tiptap-icons/send-icon\"\n\nimport \"./ai-dialog.scss\"\n\nexport interface AIDialogProps {\n editor: Editor\n config: AIPluginConfig\n buildContext: (prompt: string) => AIContextData | null\n onClose: () => void\n}\n\n/**\n * 一行输入 + 一颗提交键。\n *\n * 刻意不做成带标题栏和按钮行的卡片:它浮在正文上方紧贴选区,任何一行多余的\n * 装饰都会把用户正在读的那段文字挡掉。同类产品(ChatGPT canvas / Notion AI)\n * 也都收敛成单行胶囊。\n */\nexport function AIDialog({\n editor,\n config,\n buildContext,\n onClose,\n}: AIDialogProps) {\n const [prompt, setPrompt] = useState(\"\")\n const [isLoading, setIsLoading] = useState(false)\n const [error, setError] = useState<string | null>(null)\n const inputRef = useRef<HTMLInputElement>(null)\n\n useEffect(() => {\n inputRef.current?.focus()\n }, [])\n\n const canSubmit = Boolean(prompt.trim()) && !isLoading\n\n const handleSubmit = async () => {\n if (!canSubmit) return\n\n setError(null)\n setIsLoading(true)\n\n try {\n const context = buildContext(prompt)\n\n if (!context) {\n setError(\"没有选中内容\")\n return\n }\n\n const result = await config.plugin.process(context)\n\n if (result.error) {\n setError(result.error)\n return\n }\n\n // 插件自己落盘时不返回文本 —— 这里再替换一次会把它的改动冲掉。\n if (result.result) {\n const { from, to } = editor.state.selection\n editor.view.dispatch(\n editor.state.tr.replaceWith(from, to, [\n editor.state.schema.text(result.result),\n ])\n )\n }\n\n setPrompt(\"\")\n onClose()\n } catch (err) {\n setError(err instanceof Error ? err.message : \"出错了\")\n } finally {\n setIsLoading(false)\n }\n }\n\n const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {\n if (e.key === \"Enter\" && !e.shiftKey) {\n e.preventDefault()\n void handleSubmit()\n }\n if (e.key === \"Escape\") {\n e.preventDefault()\n onClose()\n }\n }\n\n return (\n <div className=\"tiptap-ai-dialog\">\n <div className=\"tiptap-ai-dialog-field\" data-loading={isLoading}>\n <input\n ref={inputRef}\n type=\"text\"\n className=\"tiptap-ai-dialog-input\"\n placeholder=\"描述你想要的修改\"\n value={prompt}\n disabled={isLoading}\n onChange={(e) => {\n setPrompt(e.target.value)\n setError(null)\n }}\n onKeyDown={handleKeyDown}\n />\n\n <button\n type=\"button\"\n className=\"tiptap-ai-dialog-submit\"\n aria-label=\"发送\"\n disabled={!canSubmit}\n onClick={() => void handleSubmit()}\n >\n <SendIcon />\n </button>\n </div>\n\n {error && <div className=\"tiptap-ai-dialog-error\">{error}</div>}\n </div>\n )\n}\n","import { NodeSelection, type Selection } from \"@tiptap/pm/state\"\nimport { CellSelection } from \"@tiptap/pm/tables\"\nimport type { JSONContent, Editor } from \"@tiptap/react\"\nimport { isTextSelection, isNodeSelection, posToDOMRect } from \"@tiptap/react\"\n\n\nconst NODE_TYPE_LABELS: Record<string, string> = {\n paragraph: \"Text\",\n heading: \"Heading\",\n blockquote: \"Blockquote\",\n listItem: \"List Item\",\n codeBlock: \"Code Block\",\n table: \"Table\",\n tocNode: \"Table of contents\",\n}\nexport type OverflowPosition = \"none\" | \"top\" | \"bottom\" | \"both\"\n\n/**\n * Utility function to get URL parameters\n */\nexport const getUrlParam = (param: string): string | null => {\n if (typeof window === \"undefined\") return null\n const params = new URLSearchParams(window.location.search)\n return params.get(param)\n}\n\n/**\n * Returns a display name for the current node in the editor\n * @param editor The Tiptap editor instance\n * @returns The display name of the current node\n */\nexport const getNodeDisplayName = (editor: Editor | null): string => {\n if (!editor) return \"Node\"\n\n const { selection } = editor.state\n\n if (selection instanceof NodeSelection) {\n const nodeType = selection.node.type.name\n return NODE_TYPE_LABELS[nodeType] || nodeType.toLowerCase()\n }\n\n if (selection instanceof CellSelection) {\n return \"Table\"\n }\n\n const { $anchor } = selection\n const nodeType = $anchor.parent.type.name\n return NODE_TYPE_LABELS[nodeType] || nodeType.toLowerCase()\n}\n\n/**\n * Removes empty paragraph nodes from content\n */\nexport const removeEmptyParagraphs = (content: JSONContent) => ({\n ...content,\n content: content.content?.filter(\n (node) =>\n node.type !== \"paragraph\" ||\n node.content?.some((child) => child.text?.trim() || child.type !== \"text\")\n ),\n})\n\n/**\n * Determines how a target element overflows relative to a container element\n */\nexport function getElementOverflowPosition(\n targetElement: Element,\n containerElement: HTMLElement\n): OverflowPosition {\n const targetBounds = targetElement.getBoundingClientRect()\n const containerBounds = containerElement.getBoundingClientRect()\n\n const isOverflowingTop = targetBounds.top < containerBounds.top\n const isOverflowingBottom = targetBounds.bottom > containerBounds.bottom\n\n if (isOverflowingTop && isOverflowingBottom) return \"both\"\n if (isOverflowingTop) return \"top\"\n if (isOverflowingBottom) return \"bottom\"\n return \"none\"\n}\n\n/**\n * Checks if the current selection is valid for a given editor\n */\nexport const isSelectionValid = (\n editor: Editor | null,\n selection?: Selection,\n excludedNodeTypes: string[] = [\"imageUpload\", \"horizontalRule\"]\n): boolean => {\n if (!editor) return false\n if (!selection) selection = editor.state.selection\n\n const { state } = editor\n const { doc } = state\n const { empty, from, to } = selection\n\n const isEmptyTextBlock =\n !doc.textBetween(from, to).length && isTextSelection(selection)\n const isCodeBlock =\n selection.$from.parent.type.spec.code ||\n (isNodeSelection(selection) && selection.node.type.spec.code)\n const isExcludedNode =\n isNodeSelection(selection) &&\n excludedNodeTypes.includes(selection.node.type.name)\n const isTableCell = selection instanceof CellSelection\n\n return (\n !empty &&\n !isEmptyTextBlock &&\n !isCodeBlock &&\n !isExcludedNode &&\n !isTableCell\n )\n}\n\n/**\n * Checks if the current text selection is valid for editing\n * - Not empty\n * - Not a code block\n * - Not a node selection\n */\nexport const isTextSelectionValid = (editor: Editor | null): boolean => {\n if (!editor) return false\n const { state } = editor\n const { selection } = state\n const isValid =\n isTextSelection(selection) &&\n !selection.empty &&\n !selection.$from.parent.type.spec.code &&\n !isNodeSelection(selection)\n\n return isValid\n}\n\n/**\n * Gets the bounding rect of the current selection in the editor.\n */\nexport const getSelectionBoundingRect = (editor: Editor): DOMRect | null => {\n const { state } = editor.view\n const { selection } = state\n const { ranges } = selection\n\n const from = Math.min(...ranges.map((range) => range.$from.pos))\n const to = Math.max(...ranges.map((range) => range.$to.pos))\n\n if (isNodeSelection(selection)) {\n const node = editor.view.nodeDOM(from) as HTMLElement\n if (node) {\n return node.getBoundingClientRect()\n }\n }\n\n return posToDOMRect(editor.view, from, to)\n}\n\n/**\n * Generates a deterministic avatar URL from a user name\n */\nexport const getAvatar = (name: string) => {\n if (!name) {\n return \"/avatars/memoji_01.png\"\n }\n\n let hash = 0\n for (let i = 0; i < name.length; i++) {\n hash = name.charCodeAt(i) + ((hash << 5) - hash)\n hash = hash & hash\n }\n\n const randomFraction = (Math.abs(hash) % 1000000) / 1000000\n const id = 1 + Math.floor(randomFraction * 20)\n const idString = id.toString().padStart(2, \"0\")\n return `/avatars/memoji_${idString}.png`\n}\n\n\n","\"use client\"\n\nimport { forwardRef, useCallback, useEffect, useState } from \"react\"\nimport type { Editor } from \"@tiptap/react\"\n\n// --- Hooks ---\nimport { useTiptapEditor } from \"../../hooks/use-tiptap-editor\"\nimport { useAIContext } from \"./use-ai-context\"\nimport { useAIConfig } from \"./ai-context\"\nimport { shouldShowAIButton } from \"./ai-button-visibility\"\n\n// --- Types ---\nimport type { AIPluginConfig } from \"./types\"\n\n// --- Icons ---\nimport { SparklesIcon } from \"../../components/tiptap-icons/sparkles-icon\"\n\n// --- UI Primitives ---\nimport type { ButtonProps } from \"../../components/tiptap-ui-primitive/button\"\nimport { Button } from \"../../components/tiptap-ui-primitive/button\"\nimport {\n Popover,\n PopoverContent,\n PopoverTrigger,\n} from \"../../components/tiptap-ui-primitive/popover\"\n\n// --- AI Dialog ---\nimport { AIDialog } from \"./ai-dialog\"\nimport { isSelectionValid } from \"../../lib/tiptap-collab-utils\"\n\nexport interface AIButtonProps extends Omit<ButtonProps, \"type\"> {\n /**\n * The Tiptap editor instance\n */\n editor?: Editor | null\n\n /**\n * AI plugin configuration (optional, will use context if not provided)\n */\n config?: AIPluginConfig\n\n /**\n * Whether to hide the button when no valid selection\n * @default true\n */\n hideWhenUnavailable?: boolean\n}\n\n/**\n * AI Button component for triggering the AI processing dialog\n *\n * Usage:\n * ```tsx\n * <AIButton\n * config={{ plugin: new MyAIPlugin() }}\n * hideWhenUnavailable\n * />\n * ```\n */\nexport const AIButton = forwardRef<HTMLButtonElement, AIButtonProps>(\n (\n {\n editor: providedEditor,\n config: providedConfig,\n hideWhenUnavailable = true,\n onClick,\n ...buttonProps\n },\n ref\n ) => {\n const { editor } = useTiptapEditor(providedEditor)\n const { buildContext } = useAIContext(editor)\n const contextConfig = useAIConfig()\n const [isOpen, setIsOpen] = useState(false)\n const [shouldShow, setShouldShow] = useState(false)\n\n const config = providedConfig || contextConfig\n const isEnabled = config?.enabled !== false\n\n useEffect(() => {\n if (!editor) {\n setShouldShow(false)\n return\n }\n\n const updateVisibility = () => {\n setShouldShow(\n shouldShowAIButton({\n enabled: isEnabled,\n hasValidSelection: isSelectionValid(editor),\n hideWhenUnavailable,\n isEditable: editor.isEditable,\n })\n )\n }\n\n updateVisibility()\n editor.on(\"selectionUpdate\", updateVisibility)\n\n return () => {\n editor.off(\"selectionUpdate\", updateVisibility)\n }\n }, [editor, hideWhenUnavailable, isEnabled])\n\n const handleOpenChange = useCallback(\n (open: boolean) => {\n setIsOpen(open)\n },\n []\n )\n\n const handleClick = useCallback(\n (event: React.MouseEvent<HTMLButtonElement>) => {\n onClick?.(event)\n if (!event.defaultPrevented) {\n setIsOpen(true)\n }\n },\n [onClick]\n )\n\n if (!shouldShow || !editor || !config) {\n return null\n }\n\n return (\n <Popover open={isOpen} onOpenChange={handleOpenChange}>\n <PopoverTrigger asChild>\n <Button\n ref={ref}\n type=\"button\"\n variant=\"ghost\"\n role=\"button\"\n tabIndex={-1}\n aria-label=\"AI Assistant\"\n tooltip=\"AI Assistant\"\n onClick={handleClick}\n {...buttonProps}\n >\n <SparklesIcon className=\"tiptap-button-icon\" />\n </Button>\n </PopoverTrigger>\n\n {/* 不用 asChild:AIDialog 不转发 ref,Radix 量不到尺寸会定位错位 */}\n <PopoverContent side=\"top\" align=\"start\" sideOffset={4}>\n <AIDialog\n editor={editor}\n config={config}\n buildContext={buildContext}\n onClose={() => handleOpenChange(false)}\n />\n </PopoverContent>\n </Popover>\n )\n }\n)\n\nAIButton.displayName = \"AIButton\"\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/hooks/use-tiptap-editor.ts","../src/plugins/ai/use-ai-context.ts","../src/plugins/ai/ai-context.ts","../src/plugins/ai/ai-button-visibility.ts","../src/components/tiptap-icons/sparkles-icon.tsx","../src/components/tiptap-ui-primitive/tooltip/tooltip.tsx","../src/lib/tiptap-utils.ts","../src/components/tiptap-ui-primitive/button/button.tsx","../src/components/tiptap-ui-primitive/popover/popover.tsx","../src/components/tiptap-icons/send-icon.tsx","../src/plugins/ai/ai-dialog.tsx","../src/lib/tiptap-collab-utils.ts","../src/plugins/ai/ai-button.tsx"],"names":["useState","createContext","useContext","jsx","TooltipTrigger","TooltipContent","isMac","jsxs","forwardRef","useMemo","memo","useEffect","NodeSelection","nodeType","CellSelection","useCallback"],"mappings":";;;;;;;;;AAIA,SAAS,oBAAoB,MAAA,EAA+B;AAC1D,EAAA,MAAM,UAAU,MAAA,CAAO,OAAA;AACvB,EAAA,MAAM,QAAQ,OAAA,CAAQ,KAAA;AACtB,EAAA,IAAI,CAAC,KAAA,IAAS,EAAE,cAAA,IAAkB,QAAQ,OAAO,IAAA;AACjD,EAAA,OAAO,MAAM,YAAA,IAAgB,IAAA;AAC/B;AAEO,SAAS,gBAAgB,cAAA,EAI9B;AACA,EAAA,MAAM,EAAE,MAAA,EAAQ,UAAA,EAAW,GAAI,gBAAA,EAAiB;AAChD,EAAA,MAAM,aAAa,cAAA,IAAkB,UAAA;AAErC,EAAA,MAAM,CAAC,aAAA,EAAe,gBAAgB,CAAA,GAAI,SAAwB,IAAI,CAAA;AAEtE,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,IAAI,CAAC,UAAA,EAAY;AACf,MAAA,gBAAA,CAAiB,IAAI,CAAA;AACrB,MAAA;AAAA,IACF;AAEA,IAAA,MAAM,aAAA,GAAgB,MACpB,gBAAA,CAAiB,mBAAA,CAAoB,UAAU,CAAC,CAAA;AAElD,IAAA,aAAA,EAAc;AAEd,IAAA,UAAA,CAAW,EAAA,CAAG,UAAU,aAAa,CAAA;AACrC,I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AA,IACT;AAEA,IAAA,uBACER,IAAAA,CAAC,OAAA,EAAA,EAAQ,IAAA,EAAM,MAAA,EAAQ,cAAc,gBAAA,EACnC,QAAA,EAAA;AAAA,sBAAAJ,GAAAA,CAAC,cAAA,EAAA,EAAe,OAAA,EAAO,IAAA,EACrB,QAAA,kBAAAA,GAAAA;AAAA,QAAC,MAAA;AAAA,QAAA;AAAA,UACC,GAAA;AAAA,UACA,IAAA,EAAK,QAAA;AAAA,UACL,OAAA,EAAQ,OAAA;AAAA,UACR,IAAA,EAAK,QAAA;AAAA,UACL,QAAA,EAAU,EAAA;AAAA,UACV,YAAA,EAAW,cAAA;AAAA,UACX,OAAA,EAAQ,cAAA;AAAA,UACR,OAAA,EAAS,WAAA;AAAA,UACR,GAAG,WAAA;AAAA,UAEJ,QAAA,kBAAAA,GAAAA,CAAC,YAAA,EAAA,EAAa,SAAA,EAAU,oBAAA,EAAqB;AAAA;AAAA,OAC/C,EACF,CAAA;AAAA,sBAGAA,IAAC,cAAA,EAAA,EAAe,IAAA,EAAK,OAAM,KAAA,EAAM,OAAA,EAAQ,UAAA,EAAY,CAAA,EACnD,QAAA,kBAAAA,GAAAA;AAAA,QAAC,QAAA;AAAA,QAAA;AAAA,UACC,MAAA;AAAA,UACA,MAAA;AAAA,UACA,YAAA;AAAA,UACA,OAAA,EAAS,MAAM,gBAAA,CAAiB,KAAK;AAAA;AAAA,OACvC,EACF;AAAA,KAAA,EACF,CAAA;AAAA,EAEJ;AACF;AAEA,QAAA,CAAS,WAAA,GAAc,UAAA","file":"chunk-MGSVKKK7.js","sourcesContent":["import type { Editor } from \"@tiptap/react\"\nimport { useCurrentEditor, useEditorState } from \"@tiptap/react\"\nimport { useEffect, useState } from \"react\"\n\nfunction getActivePageEditor(editor: Editor): Editor | null {\n const storage = editor.storage as unknown as Record<string, unknown>\n const pages = storage.pages as { activeEditor?: Editor | null } | undefined\n if (!pages || !(\"activeEditor\" in pages)) return null\n return pages.activeEditor ?? null\n}\n\nexport function useTiptapEditor(providedEditor?: Editor | null): {\n editor: Editor | null\n editorState?: Editor[\"state\"]\n canCommand?: Editor[\"can\"]\n} {\n const { editor: coreEditor } = useCurrentEditor()\n const mainEditor = providedEditor ?? coreEditor\n\n const [storageEditor, setStorageEditor] = useState<Editor | null>(null)\n\n useEffect(() => {\n if (!mainEditor) {\n setStorageEditor(null)\n return\n }\n\n const updateHandler = () =>\n setStorageEditor(getActivePageEditor(mainEditor))\n\n updateHandler()\n\n mainEditor.on(\"update\", updateHandler)\n mainEditor.on(\"selectionUpdate\", updateHandler)\n\n return () => {\n mainEditor.off(\"update\", updateHandler)\n mainEditor.off(\"selectionUpdate\", updateHandler)\n }\n }, [mainEditor])\n\n useEffect(() => {\n if (!storageEditor) return\n\n const handleDestroy = () => setStorageEditor(null)\n\n storageEditor.on(\"destroy\", handleDestroy)\n return () => {\n storageEditor.off(\"destroy\", handleDestroy)\n }\n }, [storageEditor])\n\n const editorState = useEditorState({\n editor: storageEditor ?? mainEditor,\n selector(context) {\n if (!context.editor) {\n return { editor: null, editorState: undefined, canCommand: undefined }\n }\n\n return {\n editor: context.editor,\n editorState: context.editor.state,\n canCommand: context.editor.can,\n }\n },\n })\n\n return editorState ?? { editor: null }\n}\n","import { useCallback } from \"react\"\nimport type { Editor } from \"@tiptap/react\"\nimport type { AIContextData } from \"./types\"\n\nconst CONTEXT_WINDOW_SIZE = 300\n\n/**\n * Extract text content from a Tiptap node recursively\n */\nfunction extractTextFromNode(node: any): string {\n if (node.isText) {\n return node.text || \"\"\n }\n if (node.content) {\n return node.content.map(extractTextFromNode).join(\"\")\n }\n return \"\"\n}\n\n/**\n * Get text at a specific position in the document\n */\nfunction getTextAtPosition(editor: Editor, pos: number, length: number): string {\n try {\n const { from, to } = editor.state.selection\n const $from = editor.state.doc.resolve(Math.max(1, pos - length))\n const $to = editor.state.doc.resolve(Math.min(editor.state.doc.content.size, pos + length))\n return editor.state.doc.textBetween($from.pos, $to.pos, \"\\n\", \" \")\n } catch {\n return \"\"\n }\n}\n\n/**\n * Get the node type at the current selection\n */\nfunction getNodeTypeAtSelection(editor: Editor): string | undefined {\n const { from } = editor.state.selection\n const $from = editor.state.doc.resolve(from)\n return $from.parent.type.name\n}\n\n/**\n * Get the heading level if the selection is inside a heading\n */\nfunction getHeadingLevel(editor: Editor): number | undefined {\n const { from } = editor.state.selection\n const $from = editor.state.doc.resolve(from)\n\n for (let d = $from.depth; d > 0; d--) {\n const node = $from.node(d)\n const match = node.type.name.match(/heading(\\d)/)\n if (match) {\n return parseInt(match[1], 10)\n }\n }\n\n return undefined\n}\n\n/**\n * Get the full document as text\n */\nfunction getFullDocument(editor: Editor): string {\n return editor.state.doc.textContent\n}\n\nexport function useAIContext(editor: Editor | null) {\n const buildContext = useCallback(\n (prompt: string): AIContextData | null => {\n if (!editor) {\n return null\n }\n\n const { from, to } = editor.state.selection\n const selectedText = editor.state.doc.textBetween(from, to)\n\n if (!selectedText) {\n return null\n }\n\n // Get the line and column number (simplified: count newlines before selection)\n const textBefore = editor.state.doc.textBetween(0, from)\n const lines = textBefore.split(\"\\n\")\n const line = lines.length\n const column = lines[lines.length - 1].length\n\n // Get surrounding context\n const precedingPos = Math.max(1, from - CONTEXT_WINDOW_SIZE)\n const followingPos = Math.min(editor.state.doc.content.size, to + CONTEXT_WINDOW_SIZE)\n\n const precedingText = editor.state.doc.textBetween(precedingPos, from)\n const followingText = editor.state.doc.textBetween(to, followingPos)\n\n return {\n prompt,\n selectedText,\n position: {\n line,\n column,\n },\n precedingText,\n followingText,\n nodeType: getNodeTypeAtSelection(editor),\n currentHeadingLevel: getHeadingLevel(editor),\n fullDocument: getFullDocument(editor),\n documentFormat: \"markdown\",\n }\n },\n [editor]\n )\n\n return { buildContext }\n}\n","import { createContext, useContext } from \"react\"\nimport type { AIPluginConfig } from \"./types\"\n\nexport const AIConfigContext = createContext<AIPluginConfig | null>(null)\n\nexport function useAIConfig(): AIPluginConfig | null {\n return useContext(AIConfigContext)\n}\n","export interface AIButtonVisibilityInput {\n /** 插件配置里的开关(`enabled !== false`)。 */\n enabled: boolean\n /** 「没得用就藏起来」。 */\n hideWhenUnavailable: boolean\n /** 编辑器是否可编辑。 */\n isEditable: boolean\n /** 当前选区是否可以拿去问 AI。 */\n hasValidSelection: boolean\n}\n\n/**\n * AI 按钮该不该渲染。\n *\n * 抽成纯函数不是为了复用,是为了能测 —— 这个判断写在组件里时曾经把\n * `hideWhenUnavailable` 取反用(`!hideWhenUnavailable && hasValidSelection`),\n * 于是工具栏传 `true` 的那条路上按钮**永远**渲染不出来,而构建、类型、\n * 导出检查全是绿的。一个布尔取反,静态手段一个都拦不住。\n */\nexport const shouldShowAIButton = ({\n enabled,\n hideWhenUnavailable,\n isEditable,\n hasValidSelection,\n}: AIButtonVisibilityInput): boolean =>\n enabled && (hideWhenUnavailable ? hasValidSelection : isEditable)\n","import { memo } from \"react\"\n\ntype SvgProps = React.ComponentPropsWithoutRef<\"svg\">\n\nexport const SparklesIcon = memo(({ className, ...props }: SvgProps) => {\n return (\n <svg\n width=\"24\"\n height=\"24\"\n className={className}\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <path\n d=\"M12 3L13.6392 8.20749C13.8353 8.83063 13.9333 9.14219 14.0982 9.40653C14.2442 9.64066 14.4276 9.84607 14.6402 10.0143C14.8802 10.2042 15.1679 10.3345 15.7434 10.5952L20.5 12L15.7434 13.4048C15.1679 13.6655 14.8802 13.7958 14.6402 13.9857C14.4276 14.1539 14.2442 14.3593 14.0982 14.5935C13.9333 14.8578 13.8353 15.1694 13.6392 15.7925L12 21L10.3608 15.7925C10.1647 15.1694 10.0667 14.8578 9.90182 14.5935C9.75583 14.3593 9.57241 14.1539 9.35983 13.9857C9.11985 13.7958 8.83209 13.6655 8.25659 13.4048L3.5 12L8.25659 10.5952C8.83209 10.3345 9.11985 10.2042 9.35983 10.0143C9.57241 9.84607 9.75583 9.64066 9.90182 9.40653C10.0667 9.14219 10.1647 8.83063 10.3608 8.20749L12 3Z\"\n stroke=\"currentColor\"\n strokeWidth=\"1.6\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n />\n <path\n d=\"M18.5 3.5L18.9 4.85C19 5.15 19.05 5.3 19.14 5.42C19.21 5.53 19.31 5.63 19.42 5.7C19.54 5.79 19.69 5.84 19.99 5.94L21.34 6.34L19.99 6.74C19.69 6.84 19.54 6.89 19.42 6.98C19.31 7.05 19.21 7.15 19.14 7.26C19.05 7.38 19 7.53 18.9 7.83L18.5 9.18L18.1 7.83C18 7.53 17.95 7.38 17.86 7.26C17.79 7.15 17.69 7.05 17.58 6.98C17.46 6.89 17.31 6.84 17.01 6.74L15.66 6.34L17.01 5.94C17.31 5.84 17.46 5.79 17.58 5.7C17.69 5.63 17.79 5.53 17.86 5.42C17.95 5.3 18 5.15 18.1 4.85L18.5 3.5Z\"\n stroke=\"currentColor\"\n strokeWidth=\"1.4\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n />\n </svg>\n )\n})\n\nSparklesIcon.displayName = \"SparklesIcon\"\n","import {\n cloneElement,\n createContext,\n forwardRef,\n isValidElement,\n useContext,\n useMemo,\n useState,\n version,\n} from \"react\"\nimport {\n useFloating,\n autoUpdate,\n offset,\n flip,\n shift,\n useHover,\n useFocus,\n useDismiss,\n useRole,\n useInteractions,\n useMergeRefs,\n FloatingPortal,\n type Placement,\n type UseFloatingReturn,\n type ReferenceType,\n FloatingDelayGroup,\n} from \"@floating-ui/react\"\n\ninterface TooltipProviderProps {\n children: React.ReactNode\n initialOpen?: boolean\n placement?: Placement\n open?: boolean\n onOpenChange?: (open: boolean) => void\n delay?: number\n closeDelay?: number\n timeout?: number\n useDelayGroup?: boolean\n}\n\ninterface TooltipTriggerProps extends Omit<\n React.HTMLProps<HTMLElement>,\n \"ref\"\n> {\n asChild?: boolean\n children: React.ReactNode\n}\n\ninterface TooltipContentProps extends Omit<\n React.HTMLProps<HTMLDivElement>,\n \"ref\"\n> {\n children?: React.ReactNode\n portal?: boolean\n portalProps?: Omit<React.ComponentProps<typeof FloatingPortal>, \"children\">\n}\n\ninterface TooltipContextValue extends UseFloatingReturn<ReferenceType> {\n open: boolean\n setOpen: (open: boolean) => void\n getReferenceProps: (\n userProps?: React.HTMLProps<HTMLElement>\n ) => Record<string, unknown>\n getFloatingProps: (\n userProps?: React.HTMLProps<HTMLDivElement>\n ) => Record<string, unknown>\n}\n\nfunction useTooltip({\n initialOpen = false,\n placement = \"top\",\n open: controlledOpen,\n onOpenChange: setControlledOpen,\n delay = 600,\n closeDelay = 0,\n}: Omit<TooltipProviderProps, \"children\"> = {}) {\n const [uncontrolledOpen, setUncontrolledOpen] = useState<boolean>(initialOpen)\n\n const open = controlledOpen ?? uncontrolledOpen\n const setOpen = setControlledOpen ?? setUncontrolledOpen\n\n const data = useFloating({\n placement,\n open,\n onOpenChange: setOpen,\n whileElementsMounted: autoUpdate,\n middleware: [\n offset(4),\n flip({\n crossAxis: placement.includes(\"-\"),\n fallbackAxisSideDirection: \"start\",\n padding: 4,\n }),\n shift({ padding: 4 }),\n ],\n })\n\n const context = data.context\n\n const hover = useHover(context, {\n mouseOnly: true,\n move: false,\n restMs: delay,\n enabled: controlledOpen == null,\n delay: {\n close: closeDelay,\n },\n })\n const focus = useFocus(context, {\n enabled: controlledOpen == null,\n })\n const dismiss = useDismiss(context)\n const role = useRole(context, { role: \"tooltip\" })\n\n const interactions = useInteractions([hover, focus, dismiss, role])\n\n return useMemo(\n () => ({\n open,\n setOpen,\n ...interactions,\n ...data,\n }),\n [open, setOpen, interactions, data]\n )\n}\n\nconst TooltipContext = createContext<TooltipContextValue | null>(null)\n\nfunction useTooltipContext() {\n const context = useContext(TooltipContext)\n\n if (context == null) {\n throw new Error(\"Tooltip components must be wrapped in <TooltipProvider />\")\n }\n\n return context\n}\n\nexport function Tooltip({ children, ...props }: TooltipProviderProps) {\n const tooltip = useTooltip(props)\n\n if (!props.useDelayGroup) {\n return (\n <TooltipContext.Provider value={tooltip}>\n {children}\n </TooltipContext.Provider>\n )\n }\n\n return (\n <FloatingDelayGroup\n delay={{ open: props.delay ?? 0, close: props.closeDelay ?? 0 }}\n timeoutMs={props.timeout}\n >\n <TooltipContext.Provider value={tooltip}>\n {children}\n </TooltipContext.Provider>\n </FloatingDelayGroup>\n )\n}\n\nexport const TooltipTrigger = forwardRef<HTMLElement, TooltipTriggerProps>(\n function TooltipTrigger({ children, asChild = false, ...props }, propRef) {\n const context = useTooltipContext()\n const childrenRef = isValidElement(children)\n ? parseInt(version, 10) >= 19\n ? // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (children as { props: { ref?: React.Ref<any> } }).props.ref\n : // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (children as any).ref\n : undefined\n const ref = useMergeRefs([context.refs.setReference, propRef, childrenRef])\n\n if (asChild && isValidElement(children)) {\n const dataAttributes = {\n \"data-tooltip-state\": context.open ? \"open\" : \"closed\",\n }\n\n return cloneElement(\n children,\n context.getReferenceProps({\n ref,\n ...props,\n ...(typeof children.props === \"object\" ? children.props : {}),\n ...dataAttributes,\n })\n )\n }\n\n return (\n <button\n ref={ref}\n data-tooltip-state={context.open ? \"open\" : \"closed\"}\n {...context.getReferenceProps(props)}\n >\n {children}\n </button>\n )\n }\n)\n\nexport const TooltipContent = forwardRef<HTMLDivElement, TooltipContentProps>(\n function TooltipContent(\n { style, children, portal = true, portalProps = {}, ...props },\n propRef\n ) {\n const context = useTooltipContext()\n const ref = useMergeRefs([context.refs.setFloating, propRef])\n\n if (!context.open) return null\n\n const content = (\n <div\n ref={ref}\n style={{\n ...context.floatingStyles,\n ...style,\n }}\n {...context.getFloatingProps(props)}\n className=\"tiptap-tooltip\"\n >\n {children}\n </div>\n )\n\n if (portal) {\n return <FloatingPortal {...portalProps}>{content}</FloatingPortal>\n }\n\n return content\n }\n)\n\nTooltip.displayName = \"Tooltip\"\nTooltipTrigger.displayName = \"TooltipTrigger\"\nTooltipContent.displayName = \"TooltipContent\"\n","import type { Node as PMNode } from \"@tiptap/pm/model\"\nimport type { Transaction } from \"@tiptap/pm/state\"\nimport {\n AllSelection,\n NodeSelection,\n Selection,\n TextSelection,\n} from \"@tiptap/pm/state\"\nimport { cellAround, CellSelection } from \"@tiptap/pm/tables\"\nimport {\n findParentNodeClosestToPos,\n type Editor,\n type NodeWithPos,\n} from \"@tiptap/react\"\n\nexport const MAX_FILE_SIZE = 5 * 1024 * 1024 // 5MB\n\nexport const MAC_SYMBOLS: Record<string, string> = {\n mod: \"⌘\",\n command: \"⌘\",\n meta: \"⌘\",\n ctrl: \"⌃\",\n control: \"⌃\",\n alt: \"⌥\",\n option: \"⌥\",\n shift: \"⇧\",\n backspace: \"Del\",\n delete: \"⌦\",\n enter: \"⏎\",\n escape: \"⎋\",\n capslock: \"⇪\",\n} as const\n\nexport const SR_ONLY = {\n position: \"absolute\",\n width: \"1px\",\n height: \"1px\",\n padding: 0,\n margin: \"-1px\",\n overflow: \"hidden\",\n clip: \"rect(0, 0, 0, 0)\",\n whiteSpace: \"nowrap\",\n borderWidth: 0,\n} as const\n\nexport function cn(\n ...classes: (string | boolean | undefined | null)[]\n): string {\n return classes.filter(Boolean).join(\" \")\n}\n\n/**\n * Determines if the current platform is macOS\n * @returns boolean indicating if the current platform is Mac\n */\nexport function isMac(): boolean {\n return (\n typeof navigator !== \"undefined\" &&\n navigator.platform.toLowerCase().includes(\"mac\")\n )\n}\n\n/**\n * Formats a shortcut key based on the platform (Mac or non-Mac)\n * @param key - The key to format (e.g., \"ctrl\", \"alt\", \"shift\")\n * @param isMac - Boolean indicating if the platform is Mac\n * @param capitalize - Whether to capitalize the key (default: true)\n * @returns Formatted shortcut key symbol\n */\nexport const formatShortcutKey = (\n key: string,\n isMac: boolean,\n capitalize: boolean = true\n) => {\n if (isMac) {\n const lowerKey = key.toLowerCase()\n return MAC_SYMBOLS[lowerKey] || (capitalize ? key.toUpperCase() : key)\n }\n\n return capitalize ? key.charAt(0).toUpperCase() + key.slice(1) : key\n}\n\n/**\n * Parses a shortcut key string into an array of formatted key symbols\n * @param shortcutKeys - The string of shortcut keys (e.g., \"ctrl-alt-shift\")\n * @param delimiter - The delimiter used to split the keys (default: \"-\")\n * @param capitalize - Whether to capitalize the keys (default: true)\n * @returns Array of formatted shortcut key symbols\n */\nexport const parseShortcutKeys = (props: {\n shortcutKeys: string | undefined\n delimiter?: string\n capitalize?: boolean\n}) => {\n const { shortcutKeys, delimiter = \"+\", capitalize = true } = props\n\n if (!shortcutKeys) return []\n\n return shortcutKeys\n .split(delimiter)\n .map((key) => key.trim())\n .map((key) => formatShortcutKey(key, isMac(), capitalize))\n}\n\n/**\n * Checks if a mark exists in the editor schema\n * @param markName - The name of the mark to check\n * @param editor - The editor instance\n * @returns boolean indicating if the mark exists in the schema\n */\nexport const isMarkInSchema = (\n markName: string,\n editor: Editor | null\n): boolean => {\n if (!editor?.schema) return false\n return editor.schema.spec.marks.get(markName) !== undefined\n}\n\n/**\n * Checks if a node exists in the editor schema\n * @param nodeName - The name of the node to check\n * @param editor - The editor instance\n * @returns boolean indicating if the node exists in the schema\n */\nexport const isNodeInSchema = (\n nodeName: string,\n editor: Editor | null\n): boolean => {\n if (!editor?.schema) return false\n return editor.schema.spec.nodes.get(nodeName) !== undefined\n}\n\n/**\n * Moves the focus to the next node in the editor\n * @param editor - The editor instance\n * @returns boolean indicating if the focus was moved\n */\nexport function focusNextNode(editor: Editor) {\n const { state, view } = editor\n const { doc, selection } = state\n\n const nextSel = Selection.findFrom(selection.$to, 1, true)\n if (nextSel) {\n view.dispatch(state.tr.setSelection(nextSel).scrollIntoView())\n return true\n }\n\n const paragraphType = state.schema.nodes.paragraph\n if (!paragraphType) {\n console.warn(\"No paragraph node type found in schema.\")\n return false\n }\n\n const end = doc.content.size\n const para = paragraphType.create()\n let tr = state.tr.insert(end, para)\n\n // Place the selection inside the new paragraph\n const $inside = tr.doc.resolve(end + 1)\n tr = tr.setSelection(TextSelection.near($inside)).scrollIntoView()\n view.dispatch(tr)\n return true\n}\n\n/**\n * Checks if a value is a valid number (not null, undefined, or NaN)\n * @param value - The value to check\n * @returns boolean indicating if the value is a valid number\n */\nexport function isValidPosition(pos: number | null | undefined): pos is number {\n return typeof pos === \"number\" && pos >= 0\n}\n\n/**\n * Checks if one or more extensions are registered in the Tiptap editor.\n * @param editor - The Tiptap editor instance\n * @param extensionNames - A single extension name or an array of names to check\n * @returns True if at least one of the extensions is available, false otherwise\n */\nexport function isExtensionAvailable(\n editor: Editor | null,\n extensionNames: string | string[]\n): boolean {\n if (!editor) return false\n\n const names = Array.isArray(extensionNames)\n ? extensionNames\n : [extensionNames]\n\n const found = names.some((name) =>\n editor.extensionManager.extensions.some((ext) => ext.name === name)\n )\n\n if (!found) {\n console.warn(\n `None of the extensions [${names.join(\", \")}] were found in the editor schema. Ensure they are included in the editor configuration.`\n )\n }\n\n return found\n}\n\n/**\n * Finds a node at the specified position with error handling\n * @param editor The Tiptap editor instance\n * @param position The position in the document to find the node\n * @returns The node at the specified position, or null if not found\n */\nexport function findNodeAtPosition(editor: Editor, position: number) {\n try {\n const node = editor.state.doc.nodeAt(position)\n if (!node) {\n console.warn(`No node found at position ${position}`)\n return null\n }\n return node\n } catch (error) {\n console.error(`Error getting node at position ${position}:`, error)\n return null\n }\n}\n\n/**\n * Finds the position and instance of a node in the document\n * @param props Object containing editor, node (optional), and nodePos (optional)\n * @param props.editor The Tiptap editor instance\n * @param props.node The node to find (optional if nodePos is provided)\n * @param props.nodePos The position of the node to find (optional if node is provided)\n * @returns An object with the position and node, or null if not found\n */\nexport function findNodePosition(props: {\n editor: Editor | null\n node?: PMNode | null\n nodePos?: number | null\n}): { pos: number; node: PMNode } | null {\n const { editor, node, nodePos } = props\n\n if (!editor || !editor.state?.doc) return null\n\n // Zero is valid position\n const hasValidNode = node !== undefined && node !== null\n const hasValidPos = isValidPosition(nodePos)\n\n if (!hasValidNode && !hasValidPos) {\n return null\n }\n\n // First search for the node in the document if we have a node\n if (hasValidNode) {\n let foundPos = -1\n let foundNode: PMNode | null = null\n\n editor.state.doc.descendants((currentNode, pos) => {\n // TODO: Needed?\n // if (currentNode.type && currentNode.type.name === node!.type.name) {\n if (currentNode === node) {\n foundPos = pos\n foundNode = currentNode\n return false\n }\n return true\n })\n\n if (foundPos !== -1 && foundNode !== null) {\n return { pos: foundPos, node: foundNode }\n }\n }\n\n // If we have a valid position, use findNodeAtPosition\n if (hasValidPos) {\n const nodeAtPos = findNodeAtPosition(editor, nodePos!)\n if (nodeAtPos) {\n return { pos: nodePos!, node: nodeAtPos }\n }\n }\n\n return null\n}\n\n/**\n * Determines whether the current selection contains a node whose type matches\n * any of the provided node type names.\n * @param editor Tiptap editor instance\n * @param nodeTypeNames List of node type names to match against\n * @param checkAncestorNodes Whether to check ancestor node types up the depth chain\n */\nexport function isNodeTypeSelected(\n editor: Editor | null,\n nodeTypeNames: string[] = [],\n checkAncestorNodes: boolean = false\n): boolean {\n if (!editor || !editor.state.selection) return false\n\n const { selection } = editor.state\n if (selection.empty) return false\n\n // Direct node selection check\n if (selection instanceof NodeSelection) {\n const selectedNode = selection.node\n return selectedNode ? nodeTypeNames.includes(selectedNode.type.name) : false\n }\n\n // Depth-based ancestor node check\n if (checkAncestorNodes) {\n const { $from } = selection\n for (let depth = $from.depth; depth > 0; depth--) {\n const ancestorNode = $from.node(depth)\n if (nodeTypeNames.includes(ancestorNode.type.name)) {\n return true\n }\n }\n }\n\n return false\n}\n\n/**\n * Check whether the current selection is fully within nodes\n * whose type names are in the provided `types` list.\n *\n * - NodeSelection → checks the selected node.\n * - Text/AllSelection → ensures all textblocks within [from, to) are allowed.\n */\nexport function selectionWithinConvertibleTypes(\n editor: Editor,\n types: string[] = []\n): boolean {\n if (!editor || types.length === 0) return false\n\n const { state } = editor\n const { selection } = state\n const allowed = new Set(types)\n\n if (selection instanceof NodeSelection) {\n const nodeType = selection.node?.type?.name\n return !!nodeType && allowed.has(nodeType)\n }\n\n if (selection instanceof TextSelection || selection instanceof AllSelection) {\n let valid = true\n state.doc.nodesBetween(selection.from, selection.to, (node) => {\n if (node.isTextblock && !allowed.has(node.type.name)) {\n valid = false\n return false // stop early\n }\n return valid\n })\n return valid\n }\n\n return false\n}\n\n/**\n * Handles image upload with progress tracking and abort capability\n * @param file The file to upload\n * @param onProgress Optional callback for tracking upload progress\n * @param abortSignal Optional AbortSignal for cancelling the upload\n * @returns Promise resolving to the URL of the uploaded image\n */\nexport const handleImageUpload = async (\n file: File,\n onProgress?: (event: { progress: number }) => void,\n abortSignal?: AbortSignal\n): Promise<string> => {\n // Validate file\n if (!file) {\n throw new Error(\"No file provided\")\n }\n\n if (file.size > MAX_FILE_SIZE) {\n throw new Error(\n `File size exceeds maximum allowed (${MAX_FILE_SIZE / (1024 * 1024)}MB)`\n )\n }\n\n // For demo/testing: Simulate upload progress. In production, replace the following code\n // with your own upload implementation.\n for (let progress = 0; progress <= 100; progress += 10) {\n if (abortSignal?.aborted) {\n throw new Error(\"Upload cancelled\")\n }\n await new Promise((resolve) => setTimeout(resolve, 500))\n onProgress?.({ progress })\n }\n\n return \"/images/tiptap-ui-placeholder-image.jpg\"\n}\n\ntype ProtocolOptions = {\n /**\n * The protocol scheme to be registered.\n * @default '''\n * @example 'ftp'\n * @example 'git'\n */\n scheme: string\n\n /**\n * If enabled, it allows optional slashes after the protocol.\n * @default false\n * @example true\n */\n optionalSlashes?: boolean\n}\n\ntype ProtocolConfig = Array<ProtocolOptions | string>\n\nconst ATTR_WHITESPACE =\n // eslint-disable-next-line no-control-regex\n /[\\u0000-\\u0020\\u00A0\\u1680\\u180E\\u2000-\\u2029\\u205F\\u3000]/g\n\nexport function isAllowedUri(\n uri: string | undefined,\n protocols?: ProtocolConfig\n) {\n const allowedProtocols: string[] = [\n \"http\",\n \"https\",\n \"ftp\",\n \"ftps\",\n \"mailto\",\n \"tel\",\n \"callto\",\n \"sms\",\n \"cid\",\n \"xmpp\",\n ]\n\n if (protocols) {\n protocols.forEach((protocol) => {\n const nextProtocol =\n typeof protocol === \"string\" ? protocol : protocol.scheme\n\n if (nextProtocol) {\n allowedProtocols.push(nextProtocol)\n }\n })\n }\n\n return (\n !uri ||\n uri.replace(ATTR_WHITESPACE, \"\").match(\n new RegExp(\n // eslint-disable-next-line no-useless-escape\n `^(?:(?:${allowedProtocols.join(\"|\")}):|[^a-z]|[a-z0-9+.\\-]+(?:[^a-z+.\\-:]|$))`,\n \"i\"\n )\n )\n )\n}\n\nexport function sanitizeUrl(\n inputUrl: string,\n baseUrl: string,\n protocols?: ProtocolConfig\n): string {\n try {\n const url = new URL(inputUrl, baseUrl)\n\n if (isAllowedUri(url.href, protocols)) {\n return url.href\n }\n } catch {\n // If URL creation fails, it's considered invalid\n }\n return \"#\"\n}\n\n/**\n * Update a single attribute on multiple nodes.\n *\n * @param tr - The transaction to mutate\n * @param targets - Array of { node, pos }\n * @param attrName - Attribute key to update\n * @param next - New value OR updater function receiving previous value\n * Pass `undefined` to remove the attribute.\n * @returns true if at least one node was updated, false otherwise\n */\nexport function updateNodesAttr<A extends string = string, V = unknown>(\n tr: Transaction,\n targets: readonly NodeWithPos[],\n attrName: A,\n next: V | ((prev: V | undefined) => V | undefined)\n): boolean {\n if (!targets.length) return false\n\n let changed = false\n\n for (const { pos } of targets) {\n // Always re-read from the transaction's current doc\n const currentNode = tr.doc.nodeAt(pos)\n if (!currentNode) continue\n\n const prevValue = (currentNode.attrs as Record<string, unknown>)[\n attrName\n ] as V | undefined\n const resolvedNext =\n typeof next === \"function\"\n ? (next as (p: V | undefined) => V | undefined)(prevValue)\n : next\n\n if (prevValue === resolvedNext) continue\n\n const nextAttrs: Record<string, unknown> = { ...currentNode.attrs }\n if (resolvedNext === undefined) {\n // Remove the key entirely instead of setting null\n delete nextAttrs[attrName]\n } else {\n nextAttrs[attrName] = resolvedNext\n }\n\n tr.setNodeMarkup(pos, undefined, nextAttrs)\n changed = true\n }\n\n return changed\n}\n\n/**\n * Selects the entire content of the current block node if the selection is empty.\n * If the selection is not empty, it does nothing.\n * @param editor The Tiptap editor instance\n */\nexport function selectCurrentBlockContent(editor: Editor) {\n const { selection, doc } = editor.state\n\n if (!selection.empty) return\n\n const $pos = selection.$from\n let blockNode: PMNode | null = null\n let blockPos = -1\n\n for (let depth = $pos.depth; depth >= 0; depth--) {\n const node = $pos.node(depth)\n const pos = $pos.start(depth)\n\n if (node.isBlock && node.textContent.trim()) {\n blockNode = node\n blockPos = pos\n break\n }\n }\n\n if (blockNode && blockPos >= 0) {\n const from = blockPos\n const to = blockPos + blockNode.nodeSize - 2 // -2 to exclude the closing tag\n\n if (from < to) {\n const $from = doc.resolve(from)\n const $to = doc.resolve(to)\n const newSelection = TextSelection.between($from, $to, 1)\n\n if (newSelection && !selection.eq(newSelection)) {\n editor.view.dispatch(editor.state.tr.setSelection(newSelection))\n }\n }\n }\n}\n\n/**\n * Retrieves all nodes of specified types from the current selection.\n * @param selection The current editor selection\n * @param allowedNodeTypes An array of node type names to look for (e.g., [\"image\", \"table\"])\n * @returns An array of objects containing the node and its position\n */\nexport function getSelectedNodesOfType(\n selection: Selection,\n allowedNodeTypes: string[]\n): NodeWithPos[] {\n const results: NodeWithPos[] = []\n const allowed = new Set(allowedNodeTypes)\n\n if (selection instanceof CellSelection) {\n selection.forEachCell((node: PMNode, pos: number) => {\n if (allowed.has(node.type.name)) {\n results.push({ node, pos })\n }\n })\n return results\n }\n\n if (selection instanceof NodeSelection) {\n const { node, from: pos } = selection\n if (node && allowed.has(node.type.name)) {\n results.push({ node, pos })\n }\n return results\n }\n\n const { $anchor } = selection\n const cell = cellAround($anchor)\n\n if (cell) {\n const cellNode = selection.$anchor.doc.nodeAt(cell.pos)\n if (cellNode && allowed.has(cellNode.type.name)) {\n results.push({ node: cellNode, pos: cell.pos })\n return results\n }\n }\n\n // Fallback: find parent nodes of allowed types\n const parentNode = findParentNodeClosestToPos($anchor, (node) =>\n allowed.has(node.type.name)\n )\n\n if (parentNode) {\n results.push({ node: parentNode.node, pos: parentNode.pos })\n }\n\n return results\n}\n\n/**\n * Clamps a value between min and max bounds\n */\nexport function clamp(value: number, min: number, max: number): number {\n return Math.max(min, Math.min(value, max))\n}\n\nexport function getSelectedBlockNodes(editor: Editor): PMNode[] {\n const { doc } = editor.state\n const { from, to } = editor.state.selection\n\n const blocks: PMNode[] = []\n const seen = new Set<number>()\n\n doc.nodesBetween(from, to, (node, pos) => {\n if (!node.isBlock) return\n\n if (!seen.has(pos)) {\n seen.add(pos)\n blocks.push(node)\n }\n\n return false\n })\n\n return blocks\n}\n","import { forwardRef, Fragment, useMemo } from \"react\"\n\n// --- Tiptap UI Primitive ---\nimport {\n Tooltip,\n TooltipContent,\n TooltipTrigger,\n} from \"../tooltip\"\n\n// --- Lib ---\nimport { cn, parseShortcutKeys } from \"../../../lib/tiptap-utils\"\n\n\nexport type ButtonVariant = \"ghost\" | \"primary\"\nexport type ButtonSize = \"small\" | \"default\" | \"large\"\n\nexport interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {\n showTooltip?: boolean\n tooltip?: React.ReactNode\n shortcutKeys?: string\n variant?: ButtonVariant\n size?: ButtonSize\n}\n\nexport const ShortcutDisplay: React.FC<{ shortcuts: string[] }> = ({\n shortcuts,\n}) => {\n if (shortcuts.length === 0) return null\n\n return (\n <div>\n {shortcuts.map((key, index) => (\n <Fragment key={index}>\n {index > 0 && <kbd>+</kbd>}\n <kbd>{key}</kbd>\n </Fragment>\n ))}\n </div>\n )\n}\n\nexport const Button = forwardRef<HTMLButtonElement, ButtonProps>(\n (\n {\n className,\n children,\n tooltip,\n showTooltip = true,\n shortcutKeys,\n variant,\n size,\n ...props\n },\n ref\n ) => {\n const shortcuts = useMemo<string[]>(\n () => parseShortcutKeys({ shortcutKeys }),\n [shortcutKeys]\n )\n\n if (!tooltip || !showTooltip) {\n return (\n <button\n data-slot=\"tiptap-button\"\n className={cn(\"tiptap-button\", className)}\n ref={ref}\n data-style={variant}\n data-size={size}\n {...props}\n >\n {children}\n </button>\n )\n }\n\n return (\n <Tooltip delay={200}>\n <TooltipTrigger\n data-slot=\"tiptap-button\"\n className={cn(\"tiptap-button\", className)}\n ref={ref}\n data-style={variant}\n data-size={size}\n {...props}\n >\n {children}\n </TooltipTrigger>\n <TooltipContent>\n {tooltip}\n <ShortcutDisplay shortcuts={shortcuts} />\n </TooltipContent>\n </Tooltip>\n )\n }\n)\n\nButton.displayName = \"Button\"\n\nexport default Button\n","\"use client\"\n\nimport * as PopoverPrimitive from \"@radix-ui/react-popover\"\nimport { cn } from \"../../../lib/tiptap-utils\"\n\nfunction Popover({\n ...props\n}: React.ComponentProps<typeof PopoverPrimitive.Root>) {\n return <PopoverPrimitive.Root {...props} />\n}\n\nfunction PopoverTrigger({\n ...props\n}: React.ComponentProps<typeof PopoverPrimitive.Trigger>) {\n return <PopoverPrimitive.Trigger {...props} />\n}\n\nfunction PopoverContent({\n className,\n align = \"center\",\n sideOffset = 4,\n ...props\n}: React.ComponentProps<typeof PopoverPrimitive.Content>) {\n return (\n <PopoverPrimitive.Portal>\n <PopoverPrimitive.Content\n align={align}\n sideOffset={sideOffset}\n className={cn(\"tiptap-popover\", className)}\n {...props}\n />\n </PopoverPrimitive.Portal>\n )\n}\n\nexport { Popover, PopoverTrigger, PopoverContent }\n","import { memo } from \"react\"\n\ntype SvgProps = React.ComponentPropsWithoutRef<\"svg\">\n\n/** 向上的箭头 —— 提交态用,和聊天输入框那颗圆形发送键同义。 */\nexport const SendIcon = memo(({ className, ...props }: SvgProps) => {\n return (\n <svg\n width=\"24\"\n height=\"24\"\n className={className}\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <path\n d=\"M12 19V5M12 5L6 11M12 5L18 11\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n />\n </svg>\n )\n})\n\nSendIcon.displayName = \"SendIcon\"\n","\"use client\"\n\nimport { useEffect, useRef, useState } from \"react\"\nimport type { Editor } from \"@tiptap/react\"\n\n// --- Types ---\nimport type { AIContextData, AIPluginConfig } from \"./types\"\n\n// --- Icons ---\nimport { SendIcon } from \"../../components/tiptap-icons/send-icon\"\n\n\nexport interface AIDialogProps {\n editor: Editor\n config: AIPluginConfig\n buildContext: (prompt: string) => AIContextData | null\n onClose: () => void\n}\n\n/**\n * 一行输入 + 一颗提交键。\n *\n * 刻意不做成带标题栏和按钮行的卡片:它浮在正文上方紧贴选区,任何一行多余的\n * 装饰都会把用户正在读的那段文字挡掉。同类产品(ChatGPT canvas / Notion AI)\n * 也都收敛成单行胶囊。\n */\nexport function AIDialog({\n editor,\n config,\n buildContext,\n onClose,\n}: AIDialogProps) {\n const [prompt, setPrompt] = useState(\"\")\n const [isLoading, setIsLoading] = useState(false)\n const [error, setError] = useState<string | null>(null)\n const inputRef = useRef<HTMLInputElement>(null)\n\n useEffect(() => {\n inputRef.current?.focus()\n }, [])\n\n const canSubmit = Boolean(prompt.trim()) && !isLoading\n\n const handleSubmit = async () => {\n if (!canSubmit) return\n\n setError(null)\n setIsLoading(true)\n\n try {\n const context = buildContext(prompt)\n\n if (!context) {\n setError(\"没有选中内容\")\n return\n }\n\n const result = await config.plugin.process(context)\n\n if (result.error) {\n setError(result.error)\n return\n }\n\n // 插件自己落盘时不返回文本 —— 这里再替换一次会把它的改动冲掉。\n if (result.result) {\n const { from, to } = editor.state.selection\n editor.view.dispatch(\n editor.state.tr.replaceWith(from, to, [\n editor.state.schema.text(result.result),\n ])\n )\n }\n\n setPrompt(\"\")\n onClose()\n } catch (err) {\n setError(err instanceof Error ? err.message : \"出错了\")\n } finally {\n setIsLoading(false)\n }\n }\n\n const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {\n if (e.key === \"Enter\" && !e.shiftKey) {\n e.preventDefault()\n void handleSubmit()\n }\n if (e.key === \"Escape\") {\n e.preventDefault()\n onClose()\n }\n }\n\n return (\n <div className=\"tiptap-ai-dialog\">\n <div className=\"tiptap-ai-dialog-field\" data-loading={isLoading}>\n <input\n ref={inputRef}\n type=\"text\"\n className=\"tiptap-ai-dialog-input\"\n placeholder=\"描述你想要的修改\"\n value={prompt}\n disabled={isLoading}\n onChange={(e) => {\n setPrompt(e.target.value)\n setError(null)\n }}\n onKeyDown={handleKeyDown}\n />\n\n <button\n type=\"button\"\n className=\"tiptap-ai-dialog-submit\"\n aria-label=\"发送\"\n disabled={!canSubmit}\n onClick={() => void handleSubmit()}\n >\n <SendIcon />\n </button>\n </div>\n\n {error && <div className=\"tiptap-ai-dialog-error\">{error}</div>}\n </div>\n )\n}\n","import { NodeSelection, type Selection } from \"@tiptap/pm/state\"\nimport { CellSelection } from \"@tiptap/pm/tables\"\nimport type { JSONContent, Editor } from \"@tiptap/react\"\nimport { isTextSelection, isNodeSelection, posToDOMRect } from \"@tiptap/react\"\n\n\nconst NODE_TYPE_LABELS: Record<string, string> = {\n paragraph: \"Text\",\n heading: \"Heading\",\n blockquote: \"Blockquote\",\n listItem: \"List Item\",\n codeBlock: \"Code Block\",\n table: \"Table\",\n tocNode: \"Table of contents\",\n}\nexport type OverflowPosition = \"none\" | \"top\" | \"bottom\" | \"both\"\n\n/**\n * Utility function to get URL parameters\n */\nexport const getUrlParam = (param: string): string | null => {\n if (typeof window === \"undefined\") return null\n const params = new URLSearchParams(window.location.search)\n return params.get(param)\n}\n\n/**\n * Returns a display name for the current node in the editor\n * @param editor The Tiptap editor instance\n * @returns The display name of the current node\n */\nexport const getNodeDisplayName = (editor: Editor | null): string => {\n if (!editor) return \"Node\"\n\n const { selection } = editor.state\n\n if (selection instanceof NodeSelection) {\n const nodeType = selection.node.type.name\n return NODE_TYPE_LABELS[nodeType] || nodeType.toLowerCase()\n }\n\n if (selection instanceof CellSelection) {\n return \"Table\"\n }\n\n const { $anchor } = selection\n const nodeType = $anchor.parent.type.name\n return NODE_TYPE_LABELS[nodeType] || nodeType.toLowerCase()\n}\n\n/**\n * Removes empty paragraph nodes from content\n */\nexport const removeEmptyParagraphs = (content: JSONContent) => ({\n ...content,\n content: content.content?.filter(\n (node) =>\n node.type !== \"paragraph\" ||\n node.content?.some((child) => child.text?.trim() || child.type !== \"text\")\n ),\n})\n\n/**\n * Determines how a target element overflows relative to a container element\n */\nexport function getElementOverflowPosition(\n targetElement: Element,\n containerElement: HTMLElement\n): OverflowPosition {\n const targetBounds = targetElement.getBoundingClientRect()\n const containerBounds = containerElement.getBoundingClientRect()\n\n const isOverflowingTop = targetBounds.top < containerBounds.top\n const isOverflowingBottom = targetBounds.bottom > containerBounds.bottom\n\n if (isOverflowingTop && isOverflowingBottom) return \"both\"\n if (isOverflowingTop) return \"top\"\n if (isOverflowingBottom) return \"bottom\"\n return \"none\"\n}\n\n/**\n * Checks if the current selection is valid for a given editor\n */\nexport const isSelectionValid = (\n editor: Editor | null,\n selection?: Selection,\n excludedNodeTypes: string[] = [\"imageUpload\", \"horizontalRule\"]\n): boolean => {\n if (!editor) return false\n if (!selection) selection = editor.state.selection\n\n const { state } = editor\n const { doc } = state\n const { empty, from, to } = selection\n\n const isEmptyTextBlock =\n !doc.textBetween(from, to).length && isTextSelection(selection)\n const isCodeBlock =\n selection.$from.parent.type.spec.code ||\n (isNodeSelection(selection) && selection.node.type.spec.code)\n const isExcludedNode =\n isNodeSelection(selection) &&\n excludedNodeTypes.includes(selection.node.type.name)\n const isTableCell = selection instanceof CellSelection\n\n return (\n !empty &&\n !isEmptyTextBlock &&\n !isCodeBlock &&\n !isExcludedNode &&\n !isTableCell\n )\n}\n\n/**\n * Checks if the current text selection is valid for editing\n * - Not empty\n * - Not a code block\n * - Not a node selection\n */\nexport const isTextSelectionValid = (editor: Editor | null): boolean => {\n if (!editor) return false\n const { state } = editor\n const { selection } = state\n const isValid =\n isTextSelection(selection) &&\n !selection.empty &&\n !selection.$from.parent.type.spec.code &&\n !isNodeSelection(selection)\n\n return isValid\n}\n\n/**\n * Gets the bounding rect of the current selection in the editor.\n */\nexport const getSelectionBoundingRect = (editor: Editor): DOMRect | null => {\n const { state } = editor.view\n const { selection } = state\n const { ranges } = selection\n\n const from = Math.min(...ranges.map((range) => range.$from.pos))\n const to = Math.max(...ranges.map((range) => range.$to.pos))\n\n if (isNodeSelection(selection)) {\n const node = editor.view.nodeDOM(from) as HTMLElement\n if (node) {\n return node.getBoundingClientRect()\n }\n }\n\n return posToDOMRect(editor.view, from, to)\n}\n\n/**\n * Generates a deterministic avatar URL from a user name\n */\nexport const getAvatar = (name: string) => {\n if (!name) {\n return \"/avatars/memoji_01.png\"\n }\n\n let hash = 0\n for (let i = 0; i < name.length; i++) {\n hash = name.charCodeAt(i) + ((hash << 5) - hash)\n hash = hash & hash\n }\n\n const randomFraction = (Math.abs(hash) % 1000000) / 1000000\n const id = 1 + Math.floor(randomFraction * 20)\n const idString = id.toString().padStart(2, \"0\")\n return `/avatars/memoji_${idString}.png`\n}\n\n\n","\"use client\"\n\nimport { forwardRef, useCallback, useEffect, useState } from \"react\"\nimport type { Editor } from \"@tiptap/react\"\n\n// --- Hooks ---\nimport { useTiptapEditor } from \"../../hooks/use-tiptap-editor\"\nimport { useAIContext } from \"./use-ai-context\"\nimport { useAIConfig } from \"./ai-context\"\nimport { shouldShowAIButton } from \"./ai-button-visibility\"\n\n// --- Types ---\nimport type { AIPluginConfig } from \"./types\"\n\n// --- Icons ---\nimport { SparklesIcon } from \"../../components/tiptap-icons/sparkles-icon\"\n\n// --- UI Primitives ---\nimport type { ButtonProps } from \"../../components/tiptap-ui-primitive/button\"\nimport { Button } from \"../../components/tiptap-ui-primitive/button\"\nimport {\n Popover,\n PopoverContent,\n PopoverTrigger,\n} from \"../../components/tiptap-ui-primitive/popover\"\n\n// --- AI Dialog ---\nimport { AIDialog } from \"./ai-dialog\"\nimport { isSelectionValid } from \"../../lib/tiptap-collab-utils\"\n\nexport interface AIButtonProps extends Omit<ButtonProps, \"type\"> {\n /**\n * The Tiptap editor instance\n */\n editor?: Editor | null\n\n /**\n * AI plugin configuration (optional, will use context if not provided)\n */\n config?: AIPluginConfig\n\n /**\n * Whether to hide the button when no valid selection\n * @default true\n */\n hideWhenUnavailable?: boolean\n}\n\n/**\n * AI Button component for triggering the AI processing dialog\n *\n * Usage:\n * ```tsx\n * <AIButton\n * config={{ plugin: new MyAIPlugin() }}\n * hideWhenUnavailable\n * />\n * ```\n */\nexport const AIButton = forwardRef<HTMLButtonElement, AIButtonProps>(\n (\n {\n editor: providedEditor,\n config: providedConfig,\n hideWhenUnavailable = true,\n onClick,\n ...buttonProps\n },\n ref\n ) => {\n const { editor } = useTiptapEditor(providedEditor)\n const { buildContext } = useAIContext(editor)\n const contextConfig = useAIConfig()\n const [isOpen, setIsOpen] = useState(false)\n const [shouldShow, setShouldShow] = useState(false)\n\n const config = providedConfig || contextConfig\n const isEnabled = config?.enabled !== false\n\n useEffect(() => {\n if (!editor) {\n setShouldShow(false)\n return\n }\n\n const updateVisibility = () => {\n setShouldShow(\n shouldShowAIButton({\n enabled: isEnabled,\n hasValidSelection: isSelectionValid(editor),\n hideWhenUnavailable,\n isEditable: editor.isEditable,\n })\n )\n }\n\n updateVisibility()\n editor.on(\"selectionUpdate\", updateVisibility)\n\n return () => {\n editor.off(\"selectionUpdate\", updateVisibility)\n }\n }, [editor, hideWhenUnavailable, isEnabled])\n\n const handleOpenChange = useCallback(\n (open: boolean) => {\n setIsOpen(open)\n },\n []\n )\n\n const handleClick = useCallback(\n (event: React.MouseEvent<HTMLButtonElement>) => {\n onClick?.(event)\n if (!event.defaultPrevented) {\n setIsOpen(true)\n }\n },\n [onClick]\n )\n\n if (!shouldShow || !editor || !config) {\n return null\n }\n\n return (\n <Popover open={isOpen} onOpenChange={handleOpenChange}>\n <PopoverTrigger asChild>\n <Button\n ref={ref}\n type=\"button\"\n variant=\"ghost\"\n role=\"button\"\n tabIndex={-1}\n aria-label=\"AI Assistant\"\n tooltip=\"AI Assistant\"\n onClick={handleClick}\n {...buttonProps}\n >\n <SparklesIcon className=\"tiptap-button-icon\" />\n </Button>\n </PopoverTrigger>\n\n {/* 不用 asChild:AIDialog 不转发 ref,Radix 量不到尺寸会定位错位 */}\n <PopoverContent side=\"top\" align=\"start\" sideOffset={4}>\n <AIDialog\n editor={editor}\n config={config}\n buildContext={buildContext}\n onClose={() => handleOpenChange(false)}\n />\n </PopoverContent>\n </Popover>\n )\n }\n)\n\nAIButton.displayName = \"AIButton\"\n"]}
|