dishui 0.0.97 → 0.0.104

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.
Files changed (84) hide show
  1. package/dist/.release-verified.json +2 -2
  2. package/dist/ai.js +17 -15
  3. package/dist/components/Card/Ticket.d.ts +52 -0
  4. package/dist/components/Card/Ticket2.js +218 -0
  5. package/dist/components/Card/Ticket2.js.map +1 -0
  6. package/dist/components/Card/index.d.ts +12 -0
  7. package/dist/components/Card/index.js +142 -139
  8. package/dist/components/Card/index.js.map +1 -1
  9. package/dist/components/ai/AgentRunCard/index.d.ts +38 -0
  10. package/dist/components/ai/AgentRunCard/index.js +100 -0
  11. package/dist/components/ai/AgentRunCard/index.js.map +1 -0
  12. package/dist/components/ai/IssueCard/index.d.ts +39 -0
  13. package/dist/components/ai/IssueCard/index.js +78 -0
  14. package/dist/components/ai/IssueCard/index.js.map +1 -0
  15. package/dist/components/ai/index.d.ts +4 -0
  16. package/dist/components/pro/Flow/constants.js +3 -3
  17. package/dist/components/pro/Flow/constants.js.map +1 -1
  18. package/dist/components/pro/Flow/context/FlowAIContext.d.ts +2 -0
  19. package/dist/components/pro/Flow/context/FlowAIContext.js +9 -4
  20. package/dist/components/pro/Flow/context/FlowAIContext.js.map +1 -1
  21. package/dist/components/pro/Flow/nodes/MediaContent.d.ts +3 -2
  22. package/dist/components/pro/Flow/nodes/MediaContent.js +16 -16
  23. package/dist/components/pro/Flow/nodes/MediaContent.js.map +1 -1
  24. package/dist/components/pro/Flow/nodes/MediaOverlay.js +25 -23
  25. package/dist/components/pro/Flow/nodes/MediaOverlay.js.map +1 -1
  26. package/dist/components/pro/Flow/nodes/shapes.js +3 -3
  27. package/dist/components/pro/Flow/nodes/shapes.js.map +1 -1
  28. package/dist/components/pro/Flow/panels/InspectorPanel.js +396 -384
  29. package/dist/components/pro/Flow/panels/InspectorPanel.js.map +1 -1
  30. package/dist/components/pro/Flow/utils/themeColor.d.ts +2 -2
  31. package/dist/components/pro/Flow/utils/themeColor.js +2 -2
  32. package/dist/components/pro/Flow/utils/themeColor.js.map +1 -1
  33. package/dist/components/pro/Kanban/Kanban.d.ts +3 -0
  34. package/dist/components/pro/Kanban/Kanban.js +339 -0
  35. package/dist/components/pro/Kanban/Kanban.js.map +1 -0
  36. package/dist/components/pro/Kanban/Swimlanes.d.ts +3 -0
  37. package/dist/components/pro/Kanban/Swimlanes.js +60 -0
  38. package/dist/components/pro/Kanban/Swimlanes.js.map +1 -0
  39. package/dist/components/pro/Kanban/index.d.ts +5 -0
  40. package/dist/components/pro/Kanban/types.d.ts +103 -0
  41. package/dist/components/pro/Kanban/useKanbanDrag.d.ts +17 -0
  42. package/dist/components/pro/Kanban/useKanbanDrag.js +69 -0
  43. package/dist/components/pro/Kanban/useKanbanDrag.js.map +1 -0
  44. package/dist/components/pro/Kanban/utils.d.ts +13 -0
  45. package/dist/components/pro/Kanban/utils.js +48 -0
  46. package/dist/components/pro/Kanban/utils.js.map +1 -0
  47. package/dist/components/pro/RichTextEditor/AIRewrite.js +158 -127
  48. package/dist/components/pro/RichTextEditor/AIRewrite.js.map +1 -1
  49. package/dist/components/pro/RichTextEditor/BlockHandle.d.ts +2 -0
  50. package/dist/components/pro/RichTextEditor/BlockHandle.js +156 -115
  51. package/dist/components/pro/RichTextEditor/BlockHandle.js.map +1 -1
  52. package/dist/components/pro/RichTextEditor/RichTextEditor.js +136 -159
  53. package/dist/components/pro/RichTextEditor/RichTextEditor.js.map +1 -1
  54. package/dist/components/pro/RichTextEditor/Toolbar/ColorPicker.js +44 -41
  55. package/dist/components/pro/RichTextEditor/Toolbar/ColorPicker.js.map +1 -1
  56. package/dist/components/pro/RichTextEditor/Toolbar/FloatingDialogMenu.js +59 -53
  57. package/dist/components/pro/RichTextEditor/Toolbar/FloatingDialogMenu.js.map +1 -1
  58. package/dist/components/pro/RichTextEditor/Toolbar/MarkdownTemplates.js +48 -44
  59. package/dist/components/pro/RichTextEditor/Toolbar/MarkdownTemplates.js.map +1 -1
  60. package/dist/components/pro/RichTextEditor/Toolbar/TableOpsMenu.js +67 -63
  61. package/dist/components/pro/RichTextEditor/Toolbar/TableOpsMenu.js.map +1 -1
  62. package/dist/components/pro/RichTextEditor/Toolbar/Toolbar.d.ts +1 -0
  63. package/dist/components/pro/RichTextEditor/Toolbar/Toolbar.js +182 -129
  64. package/dist/components/pro/RichTextEditor/Toolbar/Toolbar.js.map +1 -1
  65. package/dist/components/pro/RichTextEditor/Toolbar/ToolbarButton.d.ts +1 -0
  66. package/dist/components/pro/RichTextEditor/Toolbar/ToolbarButton.js +3 -3
  67. package/dist/components/pro/RichTextEditor/Toolbar/ToolbarButton.js.map +1 -1
  68. package/dist/components/pro/RichTextEditor/Toolbar/useAnchoredDropdown.d.ts +3 -0
  69. package/dist/components/pro/RichTextEditor/Toolbar/useAnchoredDropdown.js +31 -0
  70. package/dist/components/pro/RichTextEditor/Toolbar/useAnchoredDropdown.js.map +1 -0
  71. package/dist/components/pro/RichTextEditor/index.d.ts +1 -1
  72. package/dist/components/pro/RichTextEditor/types.d.ts +78 -11
  73. package/dist/components/pro/RichTextEditor/types.js +11 -0
  74. package/dist/components/pro/RichTextEditor/types.js.map +1 -1
  75. package/dist/dishui.css +1 -1
  76. package/dist/index-nostyled.d.ts +1 -1
  77. package/dist/index.d.ts +4 -2
  78. package/dist/index.js +128 -122
  79. package/dist/kanban.js +5 -0
  80. package/dist/utils/i18n.js +20 -0
  81. package/dist/utils/i18n.js.map +1 -1
  82. package/dist/utils/menu.js +1 -1
  83. package/dist/utils/menu.js.map +1 -1
  84. package/package.json +5 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useKanbanDrag.js","names":[],"sources":["../../../../src/components/pro/Kanban/useKanbanDrag.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from \"react\";\nimport type React from \"react\";\nimport type { KanbanDragTarget, KanbanId } from \"./types\";\n\nexport interface UseKanbanDragOptions {\n threshold?: number;\n disabled?: boolean;\n onDrop: (cardId: KanbanId, target: KanbanDragTarget) => void;\n}\n\ntype PendingDrag = {\n cardId: KanbanId;\n pointerId: number;\n startX: number;\n startY: number;\n element: HTMLElement;\n};\n\nfunction targetFromPoint(x: number, y: number): KanbanDragTarget | null {\n const hit = document.elementFromPoint(x, y) as HTMLElement | null;\n const board = hit?.closest<HTMLElement>(\".dishui-kanban\");\n if (!board) return null;\n\n const direct = hit?.closest<HTMLElement>(\"[data-kanban-drop]\");\n let indicator = direct?.closest<HTMLElement>(\"[data-disabled='true']\") ? null : direct;\n if (!indicator) {\n let bestDistance = Number.POSITIVE_INFINITY;\n board.querySelectorAll<HTMLElement>(\"[data-kanban-drop]\").forEach(candidate => {\n if (candidate.closest(\"[data-disabled='true']\")) return;\n const rect = candidate.getBoundingClientRect();\n const dx = x < rect.left ? rect.left - x : x > rect.right ? x - rect.right : 0;\n const dy = Math.abs(y - (rect.top + rect.bottom) / 2);\n const distance = dx * dx + dy * dy;\n if (distance < bestDistance) {\n bestDistance = distance;\n indicator = candidate;\n }\n });\n }\n\n const columnId = indicator?.dataset.columnId;\n const laneId = indicator?.dataset.laneId;\n const index = Number(indicator?.dataset.index);\n if (columnId === undefined || !Number.isFinite(index)) return null;\n return { columnId, laneId: laneId || undefined, index };\n}\n\nexport function useKanbanDrag({ threshold = 5, disabled = false, onDrop }: UseKanbanDragOptions) {\n const [draggingId, setDraggingId] = useState<KanbanId | null>(null);\n const [target, setTarget] = useState<KanbanDragTarget | null>(null);\n const pendingRef = useRef<PendingDrag | null>(null);\n const activeRef = useRef(false);\n const targetRef = useRef<KanbanDragTarget | null>(null);\n\n const cleanup = useCallback(() => {\n const pending = pendingRef.current;\n pendingRef.current = null;\n activeRef.current = false;\n targetRef.current = null;\n setDraggingId(null);\n setTarget(null);\n if (pending?.element.hasPointerCapture(pending.pointerId)) {\n pending.element.releasePointerCapture(pending.pointerId);\n }\n }, []);\n\n const onPointerDown = useCallback((event: React.PointerEvent<HTMLElement>, cardId: KanbanId) => {\n if (disabled || event.button !== 0 || event.currentTarget.closest(\"[data-kanban-disabled='true']\")) return;\n const element = event.currentTarget;\n pendingRef.current = { cardId, pointerId: event.pointerId, startX: event.clientX, startY: event.clientY, element };\n element.setPointerCapture(event.pointerId);\n }, [disabled]);\n\n const onPointerMove = useCallback((event: React.PointerEvent<HTMLElement>) => {\n const pending = pendingRef.current;\n if (!pending || pending.pointerId !== event.pointerId) return;\n const distance = Math.hypot(event.clientX - pending.startX, event.clientY - pending.startY);\n if (!activeRef.current && distance < Math.max(4, Math.min(6, threshold))) return;\n event.preventDefault();\n if (!activeRef.current) {\n activeRef.current = true;\n setDraggingId(pending.cardId);\n }\n const next = targetFromPoint(event.clientX, event.clientY);\n targetRef.current = next;\n setTarget(next);\n }, [threshold]);\n\n const onPointerUp = useCallback((event: React.PointerEvent<HTMLElement>) => {\n const pending = pendingRef.current;\n if (!pending || pending.pointerId !== event.pointerId) return;\n if (activeRef.current && targetRef.current) onDrop(pending.cardId, targetRef.current);\n cleanup();\n }, [cleanup, onDrop]);\n\n useEffect(() => {\n const cancel = () => cleanup();\n const onKey = (event: KeyboardEvent) => { if (event.key === \"Escape\") cleanup(); };\n window.addEventListener(\"blur\", cancel);\n window.addEventListener(\"keydown\", onKey);\n return () => {\n window.removeEventListener(\"blur\", cancel);\n window.removeEventListener(\"keydown\", onKey);\n cleanup();\n };\n }, [cleanup]);\n\n return {\n draggingId,\n target,\n onPointerDown,\n onPointerMove,\n onPointerUp,\n onPointerCancel: cleanup,\n onLostPointerCapture: cleanup,\n cancelDrag: cleanup,\n };\n}\n"],"mappings":";;AAkBA,SAAS,EAAgB,GAAW,GAAoC;CACtE,IAAM,IAAM,SAAS,iBAAiB,GAAG,CAAC,GACpC,IAAQ,GAAK,QAAqB,gBAAgB;CACxD,IAAI,CAAC,GAAO,OAAO;CAEnB,IAAM,IAAS,GAAK,QAAqB,oBAAoB,GACzD,IAAY,GAAQ,QAAqB,wBAAwB,IAAI,OAAO;CAChF,IAAI,CAAC,GAAW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ardMove, KanbanId, KanbanLocation } from "./types";
2
+ export declare function idsEqual(a: KanbanId | undefined, b: KanbanId | undefined): boolean;
3
+ export declare function cardsAt(cards: readonly KanbanCard[], columnId: KanbanId, laneId?: KanbanId): KanbanCard[];
4
+ export declare function getCardLocation(cards: readonly KanbanCard[], cardId: KanbanId): KanbanLocation | null;
5
+ /**
6
+ * Pure immutable card move. `to.index` is the insertion index in the target
7
+ * cell after the moving card has been removed, which makes same-cell sorting
8
+ * and cross-column/lane moves follow one rule.
9
+ */
10
+ export declare function moveKanbanCard(cards: readonly KanbanCard[], cardId: KanbanId, to: KanbanLocation): KanbanCard[];
11
+ export declare function createCardMove(cards: readonly KanbanCard[], cardId: KanbanId, to: KanbanLocation): KanbanCardMove | null;
12
+ export declare function locationEquals(a: KanbanLocation | null, b: KanbanLocation | null): boolean;
13
+ export declare function idText(id: KanbanId | undefined): string;
@@ -0,0 +1,48 @@
1
+ //#region src/components/pro/Kanban/utils.ts
2
+ function e(e, t) {
3
+ return e === t;
4
+ }
5
+ function t(t, n, r) {
6
+ return t.filter((t) => e(t.columnId, n) && e(t.laneId, r));
7
+ }
8
+ function n(n, r) {
9
+ let i = n.find((t) => e(t.id, r));
10
+ return i ? {
11
+ columnId: i.columnId,
12
+ laneId: i.laneId,
13
+ index: t(n, i.columnId, i.laneId).findIndex((t) => e(t.id, r))
14
+ } : null;
15
+ }
16
+ function r(n, r, i) {
17
+ let a = n.find((t) => e(t.id, r));
18
+ if (!a) return [...n];
19
+ let o = n.filter((t) => !e(t.id, r)), s = t(o, i.columnId, i.laneId), c = Math.max(0, Math.min(i.index, s.length)), l = {
20
+ ...a,
21
+ columnId: i.columnId
22
+ }, u = n.findIndex((t) => e(t.id, r));
23
+ if (i.laneId === void 0 ? delete l.laneId : l.laneId = i.laneId, c === s.length) {
24
+ let t = s[s.length - 1], n = t ? o.findIndex((n) => e(n.id, t.id)) + 1 : Math.min(u, o.length), r = [...o];
25
+ return r.splice(n, 0, l), r;
26
+ }
27
+ let d = s[c].id, f = o.findIndex((t) => e(t.id, d)), p = [...o];
28
+ return p.splice(f, 0, l), p;
29
+ }
30
+ function i(t, i, a) {
31
+ let o = t.find((t) => e(t.id, i)), s = n(t, i);
32
+ return !o || !s ? null : {
33
+ card: o,
34
+ from: s,
35
+ to: a,
36
+ cards: r(t, i, a)
37
+ };
38
+ }
39
+ function a(t, n) {
40
+ return !!t && !!n && e(t.columnId, n.columnId) && e(t.laneId, n.laneId) && t.index === n.index;
41
+ }
42
+ function o(e) {
43
+ return e === void 0 ? "" : String(e);
44
+ }
45
+ //#endregion
46
+ export { t as cardsAt, i as createCardMove, n as getCardLocation, o as idText, e as idsEqual, a as locationEquals, r as moveKanbanCard };
47
+
48
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","names":[],"sources":["../../../../src/components/pro/Kanban/utils.ts"],"sourcesContent":["import type { KanbanCard, KanbanCardMove, KanbanId, KanbanLocation } from \"./types\";\n\nexport function idsEqual(a: KanbanId | undefined, b: KanbanId | undefined): boolean {\n return a === b;\n}\n\nexport function cardsAt(\n cards: readonly KanbanCard[],\n columnId: KanbanId,\n laneId?: KanbanId,\n): KanbanCard[] {\n return cards.filter(card => idsEqual(card.columnId, columnId) && idsEqual(card.laneId, laneId));\n}\n\nexport function getCardLocation(cards: readonly KanbanCard[], cardId: KanbanId): KanbanLocation | null {\n const card = cards.find(item => idsEqual(item.id, cardId));\n if (!card) return null;\n return {\n columnId: card.columnId,\n laneId: card.laneId,\n index: cardsAt(cards, card.columnId, card.laneId).findIndex(item => idsEqual(item.id, cardId)),\n };\n}\n\n/**\n * Pure immutable card move. `to.index` is the insertion index in the target\n * cell after the moving card has been removed, which makes same-cell sorting\n * and cross-column/lane moves follow one rule.\n */\nexport function moveKanbanCard(\n cards: readonly KanbanCard[],\n cardId: KanbanId,\n to: KanbanLocation,\n): KanbanCard[] {\n const moving = cards.find(card => idsEqual(card.id, cardId));\n if (!moving) return [...cards];\n\n const without = cards.filter(card => !idsEqual(card.id, cardId));\n const targetCards = cardsAt(without, to.columnId, to.laneId);\n const index = Math.max(0, Math.min(to.index, targetCards.length));\n const nextCard: KanbanCard = { ...moving, columnId: to.columnId };\n const originalGlobalIndex = cards.findIndex(card => idsEqual(card.id, cardId));\n if (to.laneId === undefined) delete nextCard.laneId;\n else nextCard.laneId = to.laneId;\n\n if (index === targetCards.length) {\n const lastTarget = targetCards[targetCards.length - 1];\n const globalIndex = lastTarget\n ? without.findIndex(card => idsEqual(card.id, lastTarget.id)) + 1\n : Math.min(originalGlobalIndex, without.length);\n const result = [...without];\n result.splice(globalIndex, 0, nextCard);\n return result;\n }\n\n const beforeId = targetCards[index].id;\n const globalIndex = without.findIndex(card => idsEqual(card.id, beforeId));\n const result = [...without];\n result.splice(globalIndex, 0, nextCard);\n return result;\n}\n\nexport function createCardMove(\n cards: readonly KanbanCard[],\n cardId: KanbanId,\n to: KanbanLocation,\n): KanbanCardMove | null {\n const card = cards.find(item => idsEqual(item.id, cardId));\n const from = getCardLocation(cards, cardId);\n if (!card || !from) return null;\n return { card, from, to, cards: moveKanbanCard(cards, cardId, to) };\n}\n\nexport function locationEquals(a: KanbanLocation | null, b: KanbanLocation | null): boolean {\n return !!a && !!b && idsEqual(a.columnId, b.columnId) && idsEqual(a.laneId, b.laneId) && a.index === b.index;\n}\n\nexport function idText(id: KanbanId | undefined): string {\n return id === undefined ? \"\" : String(id);\n}\n"],"mappings":";AAEA,SAAgB,EAAS,GAAyB,GAAkC;CAClF,OAAO,MAAM;AACf;AAEA,SAAgB,EACd,GACA,GACA,GACc;CACd,OAAO,EAAM,QAAO,MAAQ,EAAS,EAAK,UAAU,CAAQ,KAAK,EAAS,EAAK,QAAQ,CAAM,CAAC;AAChG;AAEA,SAAgB,EAAgB,GAA8B,GAAyC;CACrG,IAAM,IAAO,EAAM,MAAK,MAAQ,EAAS,EAAK,IAAI,CAAM,CAAC;CAEzD,OADK,IACE;EACL,UAAU,EAAK;EACf,Q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nD,IAAO,EAAgB,GAAO,CAAM;CAE1C,OADI,CAAC,KAAQ,CAAC,IAAa,OACpB;EAAE;EAAM;EAAM;EAAI,OAAO,EAAe,GAAO,GAAQ,CAAE;CAAE;AACpE;AAEA,SAAgB,EAAe,GAA0B,GAAmC;CAC1F,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAS,EAAE,UAAU,EAAE,QAAQ,KAAK,EAAS,EAAE,QAAQ,EAAE,MAAM,KAAK,EAAE,UAAU,EAAE;AACzG;AAEA,SAAgB,EAAO,GAAkC;CACvD,OAAO,MAAO,KAAA,IAAY,KAAK,OAAO,CAAE;AAC1C"}
@@ -1,8 +1,10 @@
1
1
  import { defaultLabels as e } from "./types.js";
2
- import { useCallback as t, useEffect as n, useRef as r, useState as i } from "react";
3
- import { Fragment as a, jsx as o, jsxs as s } from "react/jsx-runtime";
2
+ import t from "../../ai/StreamingText/index.js";
3
+ import n from "../../ai/LoadingState/index.js";
4
+ import { useCallback as r, useEffect as i, useId as a, useRef as o, useState as s } from "react";
5
+ import { jsx as c, jsxs as l } from "react/jsx-runtime";
4
6
  //#region src/components/pro/RichTextEditor/AIRewrite.tsx
5
- var c = [
7
+ var u = [
6
8
  {
7
9
  key: "rewrite",
8
10
  labelKey: "aiRewrite",
@@ -44,7 +46,7 @@ var c = [
44
46
  icon: "💬"
45
47
  }
46
48
  ];
47
- function l(e, t) {
49
+ function d(e, t) {
48
50
  return e === "custom" ? t || "Follow the user instructions." : t || {
49
51
  rewrite: "Rewrite the following text to improve clarity and readability. Keep the same meaning and tone. Return only the rewritten text.",
50
52
  shorten: "Shorten the following text while preserving its key meaning. Be concise. Return only the shortened text.",
@@ -56,7 +58,7 @@ function l(e, t) {
56
58
  casual: "Rewrite the following text in a casual, friendly tone. Return only the rewritten text."
57
59
  }[e];
58
60
  }
59
- async function* u(e) {
61
+ async function* f(e) {
60
62
  let t = e.body?.getReader();
61
63
  if (!t) throw Error("No response body");
62
64
  let n = new TextDecoder(), r = "", i = [];
@@ -81,7 +83,8 @@ async function* u(e) {
81
83
  t.releaseLock();
82
84
  }
83
85
  }
84
- async function* d(e, t, n, r) {
86
+ async function* p(e, t, n, r) {
87
+ if (!e.gateway || !e.model) throw Error("OpenAI protocol requires gateway and model");
85
88
  let i = JSON.stringify({
86
89
  model: e.model,
87
90
  messages: [{
@@ -103,7 +106,7 @@ async function* d(e, t, n, r) {
103
106
  signal: r
104
107
  });
105
108
  if (!a.ok) throw Error(`AI API error: ${a.status} ${a.statusText}`);
106
- for await (let e of u(a)) {
109
+ for await (let e of f(a)) {
107
110
  if (e.trim() === "[DONE]") return;
108
111
  let t;
109
112
  try {
@@ -116,7 +119,8 @@ async function* d(e, t, n, r) {
116
119
  typeof n == "string" && (yield n);
117
120
  }
118
121
  }
119
- async function* f(e, t, n, r) {
122
+ async function* m(e, t, n, r) {
123
+ if (!e.gateway || !e.model) throw Error("Anthropic protocol requires gateway and model");
120
124
  let i = JSON.stringify({
121
125
  model: e.model,
122
126
  max_tokens: 4096,
@@ -138,7 +142,7 @@ async function* f(e, t, n, r) {
138
142
  signal: r
139
143
  });
140
144
  if (!a.ok) throw Error(`AI API error: ${a.status} ${a.statusText}`);
141
- for await (let e of u(a)) {
145
+ for await (let e of f(a)) {
142
146
  let t;
143
147
  try {
144
148
  t = JSON.parse(e);
@@ -150,103 +154,112 @@ async function* f(e, t, n, r) {
150
154
  t?.type === "content_block_delta" && typeof t.delta?.text == "string" && (yield t.delta.text);
151
155
  }
152
156
  }
153
- function p(e, t, n, r, i) {
157
+ function h(e, t, n, r, i, a) {
154
158
  if (e.protocol === "custom") {
155
159
  if (!e.customHandler) throw Error("Custom AI protocol requires customHandler");
156
160
  return e.customHandler({
157
161
  text: t,
158
162
  action: r === "custom" ? "rewrite" : r,
159
- signal: i
163
+ systemPrompt: n,
164
+ signal: i,
165
+ prompt: a?.prompt ?? "",
166
+ selectedText: a?.selectedText ?? t,
167
+ mode: a?.mode ?? "replace"
160
168
  });
161
169
  }
162
- return e.protocol === "anthropic" ? f(e, t, n, i) : d(e, t, n, i);
170
+ return e.protocol === "anthropic" ? m(e, t, n, i) : p(e, t, n, i);
163
171
  }
164
- var m = ({ editor: u, aiConfig: d, labels: f, initialSelection: m, selectionRange: h, onClose: g }) => {
165
- let _ = {
172
+ var g = ({ editor: f, aiConfig: p, labels: m, initialSelection: g, selectionRange: _, onClose: v }) => {
173
+ let y = {
166
174
  ...e,
167
- ...f
168
- }, [v, y] = i(""), [b, x] = i(!1), [S, C] = i(""), [w, T] = i(null), E = r(null), D = r(null), [O, k] = i(() => !u.isDestroyed && u.isEditable), [A, j] = i(!1), M = r(u.state.doc), N = r(!1), P = t(() => {
169
- let e = E.current;
170
- E.current = null, e?.abort();
175
+ ...m
176
+ }, b = a(), [x, S] = s(""), [C, w] = s(!1), [T, E] = s(""), [D, O] = s(null), k = o(null), A = o(null), [j, M] = s(() => !f.isDestroyed && f.isEditable), [N, P] = s(!1), F = o(f.state.doc), I = o(!1), L = r(() => {
177
+ let e = k.current;
178
+ k.current = null, e?.abort();
171
179
  }, []);
172
- n(() => {
173
- M.current = u.state.doc, N.current = !1, j(!1), C(""), x(!1), T(null);
180
+ i(() => {
181
+ F.current = f.state.doc, I.current = !1, P(!1), E(""), w(!1), O(null);
174
182
  let e = () => {
175
- k(!u.isDestroyed && u.isEditable), (u.isDestroyed || !u.isEditable || u.state.doc !== M.current) && (N.current = !0, j(!0), P(), x(!1), C(""), T("The document or editing permissions changed. Close and reopen AI Assistant."));
183
+ M(!f.isDestroyed && f.isEditable), (f.isDestroyed || !f.isEditable || f.state.doc !== F.current) && (I.current = !0, P(!0), L(), w(!1), E(""), O("The document or editing permissions changed. Close and reopen AI Assistant."));
176
184
  };
177
- return e(), u.on("update", e), u.on("transaction", e), u.on("destroy", e), () => {
178
- P(), u.off("update", e), u.off("transaction", e), u.off("destroy", e);
185
+ return e(), f.on("update", e), f.on("transaction", e), f.on("destroy", e), () => {
186
+ L(), f.off("update", e), f.off("transaction", e), f.off("destroy", e);
179
187
  };
180
188
  }, [
181
- u,
182
- m,
183
- h.from,
184
- h.to,
185
- P
189
+ f,
190
+ g,
191
+ _.from,
192
+ _.to,
193
+ L
186
194
  ]);
187
- let F = m;
188
- n(() => {
189
- D.current && D.current.focus();
195
+ let R = g;
196
+ i(() => {
197
+ A.current && A.current.focus();
190
198
  }, []);
191
- let I = t(async (e = "custom", t) => {
192
- if (u.isDestroyed || !u.isEditable || N.current || E.current) return;
193
- let n = F || u.state.doc.textContent;
194
- if (!n.trim() && !v.trim()) return;
195
- let r = e === "custom" ? v || "Improve the following text. Return only the improved text." : l(e, t), i = e === "custom" && v ? `Instructions: ${v}\n\nText:\n${n}` : n;
196
- x(!0), C(""), T(null);
197
- let a = new AbortController();
198
- E.current = a;
199
+ let z = r(async (e = "custom", t) => {
200
+ if (f.isDestroyed || !f.isEditable || I.current || k.current) return;
201
+ let n = R ? "replace" : "insert";
202
+ if (n === "insert" && !x.trim()) return;
203
+ let r = e === "custom" ? n === "replace" ? "Edit the selected text according to the user instruction. Return only the replacement text." : "Generate text according to the user instruction. Return only the text to insert." : d(e, t), i = [p.systemPrompt, r].filter(Boolean).join("\n\n"), a = n === "replace" ? x.trim() ? `Instruction:\n${x.trim()}\n\nSelected text:\n${R}` : R : x.trim();
204
+ w(!0), E(""), O(null);
205
+ let o = new AbortController();
206
+ k.current = o;
199
207
  try {
200
208
  let t = "";
201
- for await (let n of p(d, i, r, e, a.signal)) {
202
- if (a.signal.aborted || E.current !== a) break;
203
- t += n, C(t);
209
+ for await (let r of h(p, a, i, e, o.signal, {
210
+ prompt: x.trim(),
211
+ selectedText: R,
212
+ mode: n
213
+ })) {
214
+ if (o.signal.aborted || k.current !== o) break;
215
+ t += r, E(t);
204
216
  }
205
217
  } catch (e) {
206
- if (a.signal.aborted || E.current !== a) return;
207
- C(""), T(String(e instanceof Error ? e.message : e));
218
+ if (o.signal.aborted || k.current !== o) return;
219
+ E(""), O(String(e instanceof Error ? e.message : e));
208
220
  } finally {
209
- E.current === a && (E.current = null, x(!1));
221
+ k.current === o && (k.current = null, w(!1));
210
222
  }
211
223
  }, [
212
- u,
213
- d,
214
- F,
215
- v
216
- ]), L = t(() => {
217
- if (!S || E.current || u.isDestroyed || !u.isEditable || N.current) return;
218
- let { from: e, to: t } = h;
219
- if (u.state.doc !== M.current || !Number.isInteger(e) || !Number.isInteger(t) || e < 0 || t < e || t > u.state.doc.content.size) {
220
- T("The original selection is no longer valid. Close and reopen AI Assistant.");
224
+ f,
225
+ p,
226
+ R,
227
+ x
228
+ ]), B = r(() => {
229
+ if (!T || k.current || f.isDestroyed || !f.isEditable || I.current) return;
230
+ let { from: e, to: t } = _;
231
+ if (f.state.doc !== F.current || !Number.isInteger(e) || !Number.isInteger(t) || e < 0 || t < e || t > f.state.doc.content.size) {
232
+ O("The original selection is no longer valid. Close and reopen AI Assistant.");
221
233
  return;
222
234
  }
223
- u.view.dispatch(u.state.tr.insertText(S, e, t)), C(""), y(""), g();
235
+ f.view.dispatch(f.state.tr.insertText(T, e, t)), E(""), S(""), v();
224
236
  }, [
225
- u,
226
- S,
227
- h,
228
- g
229
- ]), R = t(() => {
230
- P(), C(""), x(!1), T(null);
231
- }, [P]), z = t((e) => {
232
- e.key === "Enter" && (e.metaKey || e.ctrlKey) && (e.preventDefault(), I());
233
- }, [I]);
234
- return /* @__PURE__ */ s("div", {
237
+ f,
238
+ T,
239
+ _,
240
+ v
241
+ ]), V = r(() => {
242
+ L(), E(""), w(!1), O(null);
243
+ }, [L]), H = r((e) => {
244
+ e.key === "Enter" && (e.metaKey || e.ctrlKey) && (e.preventDefault(), z());
245
+ }, [z]);
246
+ return /* @__PURE__ */ l("div", {
235
247
  className: "rte-ai-panel-v2",
236
248
  children: [
237
- /* @__PURE__ */ s("div", {
249
+ /* @__PURE__ */ l("div", {
238
250
  className: "rte-ai-panel-v2__header",
239
- children: [/* @__PURE__ */ s("span", {
251
+ children: [/* @__PURE__ */ l("span", {
240
252
  className: "rte-ai-panel-v2__title",
241
- children: ["✨ ", _.ai || "AI Assistant"]
242
- }), /* @__PURE__ */ o("button", {
253
+ children: ["✨ ", y.ai || "AI Assistant"]
254
+ }), /* @__PURE__ */ c("button", {
243
255
  type: "button",
244
256
  className: "rte-ai-panel-v2__close-btn",
245
257
  onClick: () => {
246
- P(), g();
258
+ L(), v();
247
259
  },
248
- title: "Close",
249
- children: /* @__PURE__ */ s("svg", {
260
+ title: y.aiClose,
261
+ "aria-label": y.aiClose,
262
+ children: /* @__PURE__ */ l("svg", {
250
263
  width: "14",
251
264
  height: "14",
252
265
  viewBox: "0 0 24 24",
@@ -255,12 +268,12 @@ var m = ({ editor: u, aiConfig: d, labels: f, initialSelection: m, selectionRang
255
268
  strokeWidth: "2",
256
269
  strokeLinecap: "round",
257
270
  strokeLinejoin: "round",
258
- children: [/* @__PURE__ */ o("line", {
271
+ children: [/* @__PURE__ */ c("line", {
259
272
  x1: "18",
260
273
  y1: "6",
261
274
  x2: "6",
262
275
  y2: "18"
263
- }), /* @__PURE__ */ o("line", {
276
+ }), /* @__PURE__ */ c("line", {
264
277
  x1: "6",
265
278
  y1: "6",
266
279
  x2: "18",
@@ -269,105 +282,123 @@ var m = ({ editor: u, aiConfig: d, labels: f, initialSelection: m, selectionRang
269
282
  })
270
283
  })]
271
284
  }),
272
- /* @__PURE__ */ s("div", {
285
+ /* @__PURE__ */ l("div", {
273
286
  className: "rte-ai-panel-v2__prompt-section",
274
- children: [/* @__PURE__ */ o("label", {
287
+ children: [/* @__PURE__ */ c("label", {
275
288
  className: "rte-ai-panel-v2__label",
276
- children: "Prompt"
277
- }), /* @__PURE__ */ o("textarea", {
278
- ref: D,
289
+ htmlFor: b,
290
+ children: y.aiPromptLabel
291
+ }), /* @__PURE__ */ c("textarea", {
292
+ id: b,
293
+ ref: A,
279
294
  className: "rte-ai-panel-v2__prompt-input",
280
- value: v,
281
- onChange: (e) => y(e.target.value),
282
- onKeyDown: z,
283
- placeholder: "Describe what AI should do... (Ctrl+Enter to generate)",
295
+ value: x,
296
+ onChange: (e) => S(e.target.value),
297
+ onKeyDown: H,
298
+ placeholder: y.aiPromptPlaceholder,
284
299
  rows: 3,
285
- disabled: b || !O || A
300
+ disabled: C || !j || N
286
301
  })]
287
302
  }),
288
- /* @__PURE__ */ s("div", {
303
+ /* @__PURE__ */ l("div", {
289
304
  className: "rte-ai-panel-v2__selection-section",
290
- children: [/* @__PURE__ */ o("label", {
305
+ children: [/* @__PURE__ */ c("span", {
291
306
  className: "rte-ai-panel-v2__label",
292
- children: "Selected Text"
293
- }), /* @__PURE__ */ o("div", {
307
+ children: y.aiSelectedText
308
+ }), /* @__PURE__ */ c("div", {
294
309
  className: "rte-ai-panel-v2__selection-box",
295
- children: F ? /* @__PURE__ */ o("span", { children: F.length > 300 ? F.slice(0, 300) + "..." : F }) : /* @__PURE__ */ o("span", {
310
+ children: R ? /* @__PURE__ */ c("span", { children: R.length > 300 ? R.slice(0, 300) + "..." : R }) : /* @__PURE__ */ c("span", {
296
311
  className: "rte-ai-panel-v2__empty",
297
- children: "No text selected (will use all content)"
312
+ children: y.aiInsertHint
298
313
  })
299
314
  })]
300
315
  }),
301
- /* @__PURE__ */ o("div", {
316
+ /* @__PURE__ */ c("div", {
302
317
  className: "rte-ai-panel-v2__quick-actions",
303
- children: c.map(({ key: e, labelKey: t, icon: n }) => /* @__PURE__ */ s("button", {
318
+ children: u.map(({ key: e, labelKey: t, icon: n }) => /* @__PURE__ */ l("button", {
304
319
  type: "button",
305
320
  className: "rte-ai-panel-v2__quick-btn",
306
- onClick: () => I(e),
307
- disabled: b || !O || A,
308
- title: _[t],
309
- children: [/* @__PURE__ */ o("span", { children: n }), /* @__PURE__ */ o("span", { children: _[t] })]
321
+ onClick: () => z(e),
322
+ disabled: C || !j || N || !R.trim(),
323
+ title: R ? y[t] : y.aiInsertHint,
324
+ children: [/* @__PURE__ */ c("span", { children: n }), /* @__PURE__ */ c("span", { children: y[t] })]
310
325
  }, e))
311
326
  }),
312
- /* @__PURE__ */ s("div", {
327
+ /* @__PURE__ */ l("div", {
313
328
  className: "rte-ai-panel-v2__actions",
314
- children: [/* @__PURE__ */ o("button", {
329
+ children: [/* @__PURE__ */ c("button", {
315
330
  type: "button",
316
331
  className: "rte-ai-panel-v2__generate-btn",
317
- onClick: () => I(),
318
- disabled: b || !O || A || !v.trim() && !F.trim(),
319
- children: b ? /* @__PURE__ */ s(a, { children: [
320
- /* @__PURE__ */ o("div", { className: "rte-ai-panel__spinner" }),
321
- " ",
322
- _.aiProcessing
323
- ] }) : "✨ Generate"
324
- }), b && /* @__PURE__ */ o("button", {
332
+ onClick: () => z(),
333
+ disabled: C || !j || N || !x.trim() && !R.trim(),
334
+ children: C ? y.aiProcessing : `✨ ${y.aiGenerate}`
335
+ }), C && /* @__PURE__ */ c("button", {
325
336
  type: "button",
326
337
  className: "rte-ai-panel-v2__cancel-btn",
327
- onClick: R,
328
- children: "Cancel"
338
+ onClick: V,
339
+ children: y.aiCancel
329
340
  })]
330
341
  }),
331
- S && /* @__PURE__ */ s("div", {
342
+ C && !T && /* @__PURE__ */ c(n, {
343
+ className: "rte-ai-panel-v2__loading",
344
+ label: y.aiProcessing,
345
+ variant: "dots",
346
+ layout: "block",
347
+ size: "sm"
348
+ }),
349
+ T && /* @__PURE__ */ l("div", {
332
350
  className: "rte-ai-panel-v2__result",
333
351
  children: [
334
- /* @__PURE__ */ o("label", {
335
- className: "rte-ai-panel-v2__label",
336
- children: "Result"
352
+ /* @__PURE__ */ l("div", {
353
+ className: "rte-ai-panel-v2__result-header",
354
+ children: [/* @__PURE__ */ c("span", {
355
+ className: "rte-ai-panel-v2__label",
356
+ children: y.aiResult
357
+ }), /* @__PURE__ */ l("span", {
358
+ className: `rte-ai-panel-v2__stream-status ${C ? "rte-ai-panel-v2__stream-status--live" : ""}`,
359
+ role: "status",
360
+ children: [/* @__PURE__ */ c("span", {
361
+ className: "rte-ai-panel-v2__stream-dot",
362
+ "aria-hidden": "true"
363
+ }), C ? y.aiProcessing : `${T.length} chars`]
364
+ })]
337
365
  }),
338
- /* @__PURE__ */ o("div", {
366
+ /* @__PURE__ */ c("div", {
339
367
  className: "rte-ai-panel-v2__result-text",
340
- children: S
368
+ children: /* @__PURE__ */ c(t, {
369
+ text: T,
370
+ streaming: C
371
+ })
341
372
  }),
342
- /* @__PURE__ */ s("div", {
373
+ /* @__PURE__ */ l("div", {
343
374
  className: "rte-ai-panel-v2__result-actions",
344
- children: [/* @__PURE__ */ o("button", {
375
+ children: [/* @__PURE__ */ c("button", {
345
376
  type: "button",
346
377
  className: "rte-ai-panel-v2__accept-btn",
347
- disabled: b || !O || A,
348
- onClick: L,
349
- children: _.aiAccept
350
- }), /* @__PURE__ */ o("button", {
378
+ disabled: C || !j || N,
379
+ onClick: B,
380
+ children: y.aiAccept
381
+ }), /* @__PURE__ */ c("button", {
351
382
  type: "button",
352
383
  className: "rte-ai-panel-v2__reject-btn",
353
- onClick: R,
354
- children: _.aiReject
384
+ onClick: V,
385
+ children: y.aiReject
355
386
  })]
356
387
  })
357
388
  ]
358
389
  }),
359
- w && /* @__PURE__ */ s("div", {
390
+ D && /* @__PURE__ */ l("div", {
360
391
  className: "rte-ai-panel-v2__error",
361
- children: [/* @__PURE__ */ o("span", { children: w }), /* @__PURE__ */ o("button", {
392
+ children: [/* @__PURE__ */ c("span", { children: D }), /* @__PURE__ */ c("button", {
362
393
  type: "button",
363
- onClick: () => T(null),
364
- children: "Dismiss"
394
+ onClick: () => O(null),
395
+ children: y.aiDismiss
365
396
  })]
366
397
  })
367
398
  ]
368
399
  });
369
400
  };
370
401
  //#endregion
371
- export { m as default };
402
+ export { g as default };
372
403
 
373
404
  //# sourceMappingURL=AIRewrite.js.map