@kopexa/tiptap 17.0.17 → 17.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-2U5CQUZH.mjs +91 -0
- package/dist/chunk-2V6VOAPI.mjs +139 -0
- package/dist/chunk-32SUXCAQ.mjs +115 -0
- package/dist/chunk-3VRQUYYW.mjs +169 -0
- package/dist/chunk-4CDZ547I.mjs +185 -0
- package/dist/chunk-5GFFTVMZ.mjs +62 -0
- package/dist/{chunk-FJAGUXEO.mjs → chunk-7SRL3P4B.mjs} +32 -19
- package/dist/{chunk-WHJ4B43N.mjs → chunk-7VGROP26.mjs} +69 -25
- package/dist/chunk-7VW67NVL.mjs +80 -0
- package/dist/chunk-BXHPO3T7.mjs +152 -0
- package/dist/{chunk-QF3YHPWM.mjs → chunk-E5NW3MJZ.mjs} +4 -4
- package/dist/chunk-FRJX2F4T.mjs +55 -0
- package/dist/chunk-IFXRPGIJ.mjs +98 -0
- package/dist/chunk-JCV5SEKN.mjs +65 -0
- package/dist/chunk-LMCQMSW2.mjs +345 -0
- package/dist/chunk-N4CT5RNC.mjs +123 -0
- package/dist/{chunk-B2DHYFSH.mjs → chunk-NEHW62L7.mjs} +56 -3
- package/dist/chunk-NSYSECKW.mjs +53 -0
- package/dist/{chunk-3IKIIRV3.mjs → chunk-QAE2D4KV.mjs} +39 -16
- package/dist/chunk-TAM3VMJT.mjs +80 -0
- package/dist/chunk-UU6JK5HX.mjs +257 -0
- package/dist/chunk-UVHVCION.mjs +168 -0
- package/dist/chunk-VF3G2URZ.mjs +83 -0
- package/dist/chunk-VRQ6OSAZ.mjs +76 -0
- package/dist/chunk-WAAH3NLG.mjs +77 -0
- package/dist/chunk-XNDXYI2N.mjs +158 -0
- package/dist/context/editor-file-context.d.mts +70 -0
- package/dist/context/editor-file-context.d.ts +70 -0
- package/dist/context/editor-file-context.js +96 -0
- package/dist/context/editor-file-context.mjs +12 -0
- package/dist/extensions/callout/callout-settings.d.mts +13 -0
- package/dist/extensions/callout/callout-settings.d.ts +13 -0
- package/dist/extensions/callout/callout-settings.js +206 -0
- package/dist/extensions/callout/callout-settings.mjs +9 -0
- package/dist/extensions/callout/callout-view.d.mts +12 -0
- package/dist/extensions/callout/callout-view.d.ts +12 -0
- package/dist/extensions/callout/callout-view.js +273 -0
- package/dist/extensions/callout/callout-view.mjs +12 -0
- package/dist/extensions/callout/index.d.mts +44 -0
- package/dist/extensions/callout/index.d.ts +44 -0
- package/dist/extensions/callout/index.js +380 -0
- package/dist/extensions/callout/index.mjs +13 -0
- package/dist/extensions/callout/messages.d.mts +59 -0
- package/dist/extensions/callout/messages.d.ts +59 -0
- package/dist/extensions/callout/messages.js +88 -0
- package/dist/extensions/callout/messages.mjs +7 -0
- package/dist/extensions/image/image-view.d.mts +15 -0
- package/dist/extensions/image/image-view.d.ts +15 -0
- package/dist/extensions/image/image-view.js +423 -0
- package/dist/extensions/image/image-view.mjs +12 -0
- package/dist/extensions/image/index.d.mts +66 -0
- package/dist/extensions/image/index.d.ts +66 -0
- package/dist/extensions/image/index.js +495 -0
- package/dist/extensions/image/index.mjs +16 -0
- package/dist/extensions/image/messages.d.mts +56 -0
- package/dist/extensions/image/messages.d.ts +56 -0
- package/dist/extensions/image/messages.js +85 -0
- package/dist/extensions/image/messages.mjs +7 -0
- package/dist/extensions/math/index.d.mts +38 -0
- package/dist/extensions/math/index.d.ts +38 -0
- package/dist/extensions/math/index.js +544 -0
- package/dist/extensions/math/index.mjs +17 -0
- package/dist/extensions/math/inline-math-view.d.mts +12 -0
- package/dist/extensions/math/inline-math-view.d.ts +12 -0
- package/dist/extensions/math/inline-math-view.js +232 -0
- package/dist/extensions/math/inline-math-view.mjs +11 -0
- package/dist/extensions/math/inline-math.d.mts +32 -0
- package/dist/extensions/math/inline-math.d.ts +32 -0
- package/dist/extensions/math/inline-math.js +304 -0
- package/dist/extensions/math/inline-math.mjs +12 -0
- package/dist/extensions/math/math-block-view.d.mts +11 -0
- package/dist/extensions/math/math-block-view.d.ts +11 -0
- package/dist/extensions/math/math-block-view.js +248 -0
- package/dist/extensions/math/math-block-view.mjs +11 -0
- package/dist/extensions/math/messages.d.mts +49 -0
- package/dist/extensions/math/messages.d.ts +49 -0
- package/dist/extensions/math/messages.js +78 -0
- package/dist/extensions/math/messages.mjs +7 -0
- package/dist/extensions/toc/index.d.mts +53 -0
- package/dist/extensions/toc/index.d.ts +53 -0
- package/dist/extensions/toc/index.js +501 -0
- package/dist/extensions/toc/index.mjs +13 -0
- package/dist/extensions/toc/messages.d.mts +74 -0
- package/dist/extensions/toc/messages.d.ts +74 -0
- package/dist/extensions/toc/messages.js +103 -0
- package/dist/extensions/toc/messages.mjs +7 -0
- package/dist/extensions/toc/toc-settings.d.mts +13 -0
- package/dist/extensions/toc/toc-settings.d.ts +13 -0
- package/dist/extensions/toc/toc-settings.js +283 -0
- package/dist/extensions/toc/toc-settings.mjs +9 -0
- package/dist/extensions/toc/toc-view.d.mts +12 -0
- package/dist/extensions/toc/toc-view.d.ts +12 -0
- package/dist/extensions/toc/toc-view.js +411 -0
- package/dist/extensions/toc/toc-view.mjs +12 -0
- package/dist/hooks/use-create-editor.d.mts +20 -2
- package/dist/hooks/use-create-editor.d.ts +20 -2
- package/dist/hooks/use-create-editor.js +2020 -20
- package/dist/hooks/use-create-editor.mjs +20 -3
- package/dist/index.d.mts +11 -2
- package/dist/index.d.ts +11 -2
- package/dist/index.js +3948 -1563
- package/dist/index.mjs +64 -23
- package/dist/presets/basic/editor-header.d.mts +3 -2
- package/dist/presets/basic/editor-header.d.ts +3 -2
- package/dist/presets/basic/editor-header.js +91 -25
- package/dist/presets/basic/editor-header.mjs +14 -14
- package/dist/presets/basic/index.d.mts +3 -1
- package/dist/presets/basic/index.d.ts +3 -1
- package/dist/presets/basic/index.js +3833 -1517
- package/dist/presets/basic/index.mjs +41 -22
- package/dist/ui/bubble-menu/index.d.mts +13 -0
- package/dist/ui/bubble-menu/index.d.ts +13 -0
- package/dist/ui/bubble-menu/index.js +671 -0
- package/dist/ui/bubble-menu/index.mjs +16 -0
- package/dist/ui/color-highlight-popover/color-highlight-popover.mjs +2 -2
- package/dist/ui/color-highlight-popover/index.mjs +2 -2
- package/dist/ui/copy-anchor-link-button/use-scroll-to-hash.mjs +2 -2
- package/dist/ui/link-bubble/index.d.mts +13 -0
- package/dist/ui/link-bubble/index.d.ts +13 -0
- package/dist/ui/link-bubble/index.js +182 -0
- package/dist/ui/link-bubble/index.mjs +10 -0
- package/dist/ui/link-popover/index.js +66 -23
- package/dist/ui/link-popover/index.mjs +3 -3
- package/dist/ui/link-popover/link-popover.d.mts +7 -2
- package/dist/ui/link-popover/link-popover.d.ts +7 -2
- package/dist/ui/link-popover/link-popover.js +66 -23
- package/dist/ui/link-popover/link-popover.mjs +3 -3
- package/dist/ui/link-popover/use-link-popover.mjs +2 -2
- package/dist/ui/slash-dropdown-menu/index.js +53 -3
- package/dist/ui/slash-dropdown-menu/index.mjs +6 -6
- package/dist/ui/slash-dropdown-menu/slash-dropdown-menu.js +53 -3
- package/dist/ui/slash-dropdown-menu/slash-dropdown-menu.mjs +4 -4
- package/dist/ui/slash-dropdown-menu/use-slash-dropdown-menu.d.mts +28 -0
- package/dist/ui/slash-dropdown-menu/use-slash-dropdown-menu.d.ts +28 -0
- package/dist/ui/slash-dropdown-menu/use-slash-dropdown-menu.js +53 -3
- package/dist/ui/slash-dropdown-menu/use-slash-dropdown-menu.mjs +1 -1
- package/dist/ui/suggestion-menu/index.mjs +2 -2
- package/dist/ui/suggestion-menu/suggestion-menu.mjs +2 -2
- package/dist/utils/safe-parse.js +113 -4
- package/dist/utils/safe-parse.mjs +1 -1
- package/package.json +48 -39
- package/dist/chunk-7LHOYNVF.mjs +0 -60
- package/dist/chunk-LXOLVGLW.mjs +0 -131
- package/dist/{chunk-XL5FS7LN.mjs → chunk-C5RQWJKE.mjs} +3 -3
- package/dist/{chunk-JNL4KY45.mjs → chunk-DZLGLP7R.mjs} +3 -3
- package/dist/{chunk-LHXRE26G.mjs → chunk-VTKJPVNM.mjs} +3 -3
- package/dist/{chunk-XLSZK3WJ.mjs → chunk-ZYFCSR3E.mjs} +3 -3
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
"use client";
|
|
4
|
+
var __create = Object.create;
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __export = (target, all) => {
|
|
11
|
+
for (var name in all)
|
|
12
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
13
|
+
};
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from))
|
|
17
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
18
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
28
|
+
mod
|
|
29
|
+
));
|
|
30
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
31
|
+
|
|
32
|
+
// src/extensions/math/inline-math-view.tsx
|
|
33
|
+
var inline_math_view_exports = {};
|
|
34
|
+
__export(inline_math_view_exports, {
|
|
35
|
+
InlineMathView: () => InlineMathView,
|
|
36
|
+
default: () => inline_math_view_default
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(inline_math_view_exports);
|
|
39
|
+
var import_button = require("@kopexa/button");
|
|
40
|
+
var import_dialog = require("@kopexa/dialog");
|
|
41
|
+
var import_label = require("@kopexa/label");
|
|
42
|
+
var import_react = require("@tiptap/react");
|
|
43
|
+
var import_katex = __toESM(require("katex"));
|
|
44
|
+
var import_katex_min = require("katex/dist/katex.min.css");
|
|
45
|
+
var import_react2 = require("react");
|
|
46
|
+
var import_react_intl2 = require("react-intl");
|
|
47
|
+
|
|
48
|
+
// src/extensions/math/messages.ts
|
|
49
|
+
var import_react_intl = require("react-intl");
|
|
50
|
+
var messages = (0, import_react_intl.defineMessages)({
|
|
51
|
+
title: {
|
|
52
|
+
id: "editor.math.title",
|
|
53
|
+
defaultMessage: "Formula",
|
|
54
|
+
description: "Math block title"
|
|
55
|
+
},
|
|
56
|
+
edit: {
|
|
57
|
+
id: "editor.math.edit",
|
|
58
|
+
defaultMessage: "Edit",
|
|
59
|
+
description: "Edit button label"
|
|
60
|
+
},
|
|
61
|
+
preview: {
|
|
62
|
+
id: "editor.math.preview",
|
|
63
|
+
defaultMessage: "Preview",
|
|
64
|
+
description: "Preview section label"
|
|
65
|
+
},
|
|
66
|
+
latex_input: {
|
|
67
|
+
id: "editor.math.latex_input",
|
|
68
|
+
defaultMessage: "LaTeX",
|
|
69
|
+
description: "LaTeX input label"
|
|
70
|
+
},
|
|
71
|
+
latex_placeholder: {
|
|
72
|
+
id: "editor.math.latex_placeholder",
|
|
73
|
+
defaultMessage: "Enter LaTeX formula...",
|
|
74
|
+
description: "LaTeX input placeholder"
|
|
75
|
+
},
|
|
76
|
+
invalid_latex: {
|
|
77
|
+
id: "editor.math.invalid_latex",
|
|
78
|
+
defaultMessage: "Invalid LaTeX syntax",
|
|
79
|
+
description: "Error message for invalid LaTeX"
|
|
80
|
+
},
|
|
81
|
+
empty_formula: {
|
|
82
|
+
id: "editor.math.empty_formula",
|
|
83
|
+
defaultMessage: "Click to add formula",
|
|
84
|
+
description: "Placeholder for empty formula"
|
|
85
|
+
},
|
|
86
|
+
save: {
|
|
87
|
+
id: "editor.math.save",
|
|
88
|
+
defaultMessage: "Save",
|
|
89
|
+
description: "Save button label"
|
|
90
|
+
},
|
|
91
|
+
cancel: {
|
|
92
|
+
id: "editor.math.cancel",
|
|
93
|
+
defaultMessage: "Cancel",
|
|
94
|
+
description: "Cancel button label"
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// src/extensions/math/inline-math-view.tsx
|
|
99
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
100
|
+
function InlineMathView({ editor, node, getPos }) {
|
|
101
|
+
const intl = (0, import_react_intl2.useIntl)();
|
|
102
|
+
const attrs = node.attrs;
|
|
103
|
+
const { latex = "" } = attrs;
|
|
104
|
+
const isEditable = (0, import_react.useEditorState)({
|
|
105
|
+
editor,
|
|
106
|
+
selector: ({ editor: e }) => {
|
|
107
|
+
var _a;
|
|
108
|
+
return (_a = e == null ? void 0 : e.isEditable) != null ? _a : false;
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
const [isOpen, setIsOpen] = (0, import_react2.useState)(false);
|
|
112
|
+
const [localLatex, setLocalLatex] = (0, import_react2.useState)(latex);
|
|
113
|
+
const [error, setError] = (0, import_react2.useState)(null);
|
|
114
|
+
(0, import_react2.useEffect)(() => {
|
|
115
|
+
if (isOpen) {
|
|
116
|
+
setLocalLatex(latex);
|
|
117
|
+
setError(null);
|
|
118
|
+
}
|
|
119
|
+
}, [isOpen, latex]);
|
|
120
|
+
const renderedHtml = (0, import_react2.useMemo)(() => {
|
|
121
|
+
if (!latex) return null;
|
|
122
|
+
try {
|
|
123
|
+
return import_katex.default.renderToString(latex, {
|
|
124
|
+
throwOnError: false,
|
|
125
|
+
displayMode: false,
|
|
126
|
+
output: "html"
|
|
127
|
+
});
|
|
128
|
+
} catch {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
}, [latex]);
|
|
132
|
+
const previewHtml = (0, import_react2.useMemo)(() => {
|
|
133
|
+
if (!localLatex) return null;
|
|
134
|
+
try {
|
|
135
|
+
setError(null);
|
|
136
|
+
return import_katex.default.renderToString(localLatex, {
|
|
137
|
+
throwOnError: true,
|
|
138
|
+
displayMode: false,
|
|
139
|
+
output: "html"
|
|
140
|
+
});
|
|
141
|
+
} catch (_e) {
|
|
142
|
+
setError(intl.formatMessage(messages.invalid_latex));
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
}, [localLatex, intl]);
|
|
146
|
+
const handleSave = (0, import_react2.useCallback)(() => {
|
|
147
|
+
const pos = getPos();
|
|
148
|
+
if (pos === void 0) return;
|
|
149
|
+
editor.view.dispatch(
|
|
150
|
+
editor.state.tr.setNodeMarkup(pos, void 0, { latex: localLatex })
|
|
151
|
+
);
|
|
152
|
+
setIsOpen(false);
|
|
153
|
+
}, [editor, localLatex, getPos]);
|
|
154
|
+
const handleCancel = (0, import_react2.useCallback)(() => {
|
|
155
|
+
setLocalLatex(latex);
|
|
156
|
+
setError(null);
|
|
157
|
+
setIsOpen(false);
|
|
158
|
+
}, [latex]);
|
|
159
|
+
const handleClick = (0, import_react2.useCallback)(
|
|
160
|
+
(e) => {
|
|
161
|
+
e.stopPropagation();
|
|
162
|
+
e.preventDefault();
|
|
163
|
+
if (isEditable) {
|
|
164
|
+
setIsOpen(true);
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
[isEditable]
|
|
168
|
+
);
|
|
169
|
+
const isEmpty = !latex;
|
|
170
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
171
|
+
import_react.NodeViewWrapper,
|
|
172
|
+
{
|
|
173
|
+
as: "span",
|
|
174
|
+
className: "inline-math-wrapper",
|
|
175
|
+
"data-type": "inline-math",
|
|
176
|
+
"data-latex": latex,
|
|
177
|
+
children: [
|
|
178
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
179
|
+
"span",
|
|
180
|
+
{
|
|
181
|
+
className: `inline-math cursor-pointer rounded px-0.5 transition-colors ${isEditable ? "hover:bg-primary/10 hover:ring-1 hover:ring-primary/20" : ""} ${isEmpty ? "text-muted-foreground italic" : ""}`,
|
|
182
|
+
onClick: handleClick,
|
|
183
|
+
children: isEmpty ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "text-xs", children: "$?$" }) : renderedHtml ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
184
|
+
"span",
|
|
185
|
+
{
|
|
186
|
+
dangerouslySetInnerHTML: { __html: renderedHtml }
|
|
187
|
+
}
|
|
188
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "text-destructive text-xs", children: latex })
|
|
189
|
+
}
|
|
190
|
+
),
|
|
191
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.Dialog.Root, { open: isOpen, onOpenChange: setIsOpen, size: "sm", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_dialog.Dialog.Content, { children: [
|
|
192
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.Dialog.Header, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.Dialog.Title, { children: intl.formatMessage(messages.title) }) }),
|
|
193
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.Dialog.Body, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "space-y-4", children: [
|
|
194
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "space-y-1.5", children: [
|
|
195
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_label.Label, { className: "text-sm", children: intl.formatMessage(messages.latex_input) }),
|
|
196
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
197
|
+
"input",
|
|
198
|
+
{
|
|
199
|
+
type: "text",
|
|
200
|
+
className: "w-full p-2 rounded-md border border-input bg-background font-mono text-sm focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
|
|
201
|
+
value: localLatex,
|
|
202
|
+
onChange: (e) => setLocalLatex(e.target.value),
|
|
203
|
+
placeholder: intl.formatMessage(messages.latex_placeholder),
|
|
204
|
+
spellCheck: false
|
|
205
|
+
}
|
|
206
|
+
),
|
|
207
|
+
error && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "text-xs text-destructive", children: error })
|
|
208
|
+
] }),
|
|
209
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "space-y-1.5", children: [
|
|
210
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_label.Label, { className: "text-sm", children: intl.formatMessage(messages.preview) }),
|
|
211
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "min-h-10 p-3 rounded-md border border-border bg-muted/30 flex items-center justify-center", children: previewHtml ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
212
|
+
"span",
|
|
213
|
+
{
|
|
214
|
+
dangerouslySetInnerHTML: { __html: previewHtml }
|
|
215
|
+
}
|
|
216
|
+
) : localLatex ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "text-muted-foreground text-sm", children: intl.formatMessage(messages.invalid_latex) }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "text-muted-foreground text-sm", children: "$...$" }) })
|
|
217
|
+
] })
|
|
218
|
+
] }) }),
|
|
219
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_dialog.Dialog.Footer, { children: [
|
|
220
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_button.Button, { variant: "ghost", onClick: handleCancel, children: intl.formatMessage(messages.cancel) }),
|
|
221
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_button.Button, { onClick: handleSave, disabled: !!error && !!localLatex, children: intl.formatMessage(messages.save) })
|
|
222
|
+
] })
|
|
223
|
+
] }) })
|
|
224
|
+
]
|
|
225
|
+
}
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
var inline_math_view_default = InlineMathView;
|
|
229
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
230
|
+
0 && (module.exports = {
|
|
231
|
+
InlineMathView
|
|
232
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Node } from '@tiptap/core';
|
|
2
|
+
|
|
3
|
+
interface InlineMathAttrs {
|
|
4
|
+
/**
|
|
5
|
+
* The LaTeX formula content
|
|
6
|
+
*/
|
|
7
|
+
latex: string;
|
|
8
|
+
}
|
|
9
|
+
interface InlineMathOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Custom HTML attributes for the inline math wrapper element.
|
|
12
|
+
*/
|
|
13
|
+
HTMLAttributes: Record<string, unknown>;
|
|
14
|
+
}
|
|
15
|
+
declare module "@tiptap/core" {
|
|
16
|
+
interface Commands<ReturnType> {
|
|
17
|
+
inlineMath: {
|
|
18
|
+
/**
|
|
19
|
+
* Insert inline math
|
|
20
|
+
*/
|
|
21
|
+
insertInlineMath: (latex?: string) => ReturnType;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Inline Math Node Extension
|
|
27
|
+
*
|
|
28
|
+
* Renders inline LaTeX formulas using KaTeX.
|
|
29
|
+
*/
|
|
30
|
+
declare const InlineMath: Node<InlineMathOptions, any>;
|
|
31
|
+
|
|
32
|
+
export { InlineMath, type InlineMathAttrs, type InlineMathOptions, InlineMath as default };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Node } from '@tiptap/core';
|
|
2
|
+
|
|
3
|
+
interface InlineMathAttrs {
|
|
4
|
+
/**
|
|
5
|
+
* The LaTeX formula content
|
|
6
|
+
*/
|
|
7
|
+
latex: string;
|
|
8
|
+
}
|
|
9
|
+
interface InlineMathOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Custom HTML attributes for the inline math wrapper element.
|
|
12
|
+
*/
|
|
13
|
+
HTMLAttributes: Record<string, unknown>;
|
|
14
|
+
}
|
|
15
|
+
declare module "@tiptap/core" {
|
|
16
|
+
interface Commands<ReturnType> {
|
|
17
|
+
inlineMath: {
|
|
18
|
+
/**
|
|
19
|
+
* Insert inline math
|
|
20
|
+
*/
|
|
21
|
+
insertInlineMath: (latex?: string) => ReturnType;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Inline Math Node Extension
|
|
27
|
+
*
|
|
28
|
+
* Renders inline LaTeX formulas using KaTeX.
|
|
29
|
+
*/
|
|
30
|
+
declare const InlineMath: Node<InlineMathOptions, any>;
|
|
31
|
+
|
|
32
|
+
export { InlineMath, type InlineMathAttrs, type InlineMathOptions, InlineMath as default };
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
"use client";
|
|
4
|
+
var __create = Object.create;
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __export = (target, all) => {
|
|
11
|
+
for (var name in all)
|
|
12
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
13
|
+
};
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from))
|
|
17
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
18
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
28
|
+
mod
|
|
29
|
+
));
|
|
30
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
31
|
+
|
|
32
|
+
// src/extensions/math/inline-math.ts
|
|
33
|
+
var inline_math_exports = {};
|
|
34
|
+
__export(inline_math_exports, {
|
|
35
|
+
InlineMath: () => InlineMath,
|
|
36
|
+
default: () => inline_math_default
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(inline_math_exports);
|
|
39
|
+
var import_core = require("@tiptap/core");
|
|
40
|
+
var import_react3 = require("@tiptap/react");
|
|
41
|
+
|
|
42
|
+
// src/extensions/math/inline-math-view.tsx
|
|
43
|
+
var import_button = require("@kopexa/button");
|
|
44
|
+
var import_dialog = require("@kopexa/dialog");
|
|
45
|
+
var import_label = require("@kopexa/label");
|
|
46
|
+
var import_react = require("@tiptap/react");
|
|
47
|
+
var import_katex = __toESM(require("katex"));
|
|
48
|
+
var import_katex_min = require("katex/dist/katex.min.css");
|
|
49
|
+
var import_react2 = require("react");
|
|
50
|
+
var import_react_intl2 = require("react-intl");
|
|
51
|
+
|
|
52
|
+
// src/extensions/math/messages.ts
|
|
53
|
+
var import_react_intl = require("react-intl");
|
|
54
|
+
var messages = (0, import_react_intl.defineMessages)({
|
|
55
|
+
title: {
|
|
56
|
+
id: "editor.math.title",
|
|
57
|
+
defaultMessage: "Formula",
|
|
58
|
+
description: "Math block title"
|
|
59
|
+
},
|
|
60
|
+
edit: {
|
|
61
|
+
id: "editor.math.edit",
|
|
62
|
+
defaultMessage: "Edit",
|
|
63
|
+
description: "Edit button label"
|
|
64
|
+
},
|
|
65
|
+
preview: {
|
|
66
|
+
id: "editor.math.preview",
|
|
67
|
+
defaultMessage: "Preview",
|
|
68
|
+
description: "Preview section label"
|
|
69
|
+
},
|
|
70
|
+
latex_input: {
|
|
71
|
+
id: "editor.math.latex_input",
|
|
72
|
+
defaultMessage: "LaTeX",
|
|
73
|
+
description: "LaTeX input label"
|
|
74
|
+
},
|
|
75
|
+
latex_placeholder: {
|
|
76
|
+
id: "editor.math.latex_placeholder",
|
|
77
|
+
defaultMessage: "Enter LaTeX formula...",
|
|
78
|
+
description: "LaTeX input placeholder"
|
|
79
|
+
},
|
|
80
|
+
invalid_latex: {
|
|
81
|
+
id: "editor.math.invalid_latex",
|
|
82
|
+
defaultMessage: "Invalid LaTeX syntax",
|
|
83
|
+
description: "Error message for invalid LaTeX"
|
|
84
|
+
},
|
|
85
|
+
empty_formula: {
|
|
86
|
+
id: "editor.math.empty_formula",
|
|
87
|
+
defaultMessage: "Click to add formula",
|
|
88
|
+
description: "Placeholder for empty formula"
|
|
89
|
+
},
|
|
90
|
+
save: {
|
|
91
|
+
id: "editor.math.save",
|
|
92
|
+
defaultMessage: "Save",
|
|
93
|
+
description: "Save button label"
|
|
94
|
+
},
|
|
95
|
+
cancel: {
|
|
96
|
+
id: "editor.math.cancel",
|
|
97
|
+
defaultMessage: "Cancel",
|
|
98
|
+
description: "Cancel button label"
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// src/extensions/math/inline-math-view.tsx
|
|
103
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
104
|
+
function InlineMathView({ editor, node, getPos }) {
|
|
105
|
+
const intl = (0, import_react_intl2.useIntl)();
|
|
106
|
+
const attrs = node.attrs;
|
|
107
|
+
const { latex = "" } = attrs;
|
|
108
|
+
const isEditable = (0, import_react.useEditorState)({
|
|
109
|
+
editor,
|
|
110
|
+
selector: ({ editor: e }) => {
|
|
111
|
+
var _a;
|
|
112
|
+
return (_a = e == null ? void 0 : e.isEditable) != null ? _a : false;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
const [isOpen, setIsOpen] = (0, import_react2.useState)(false);
|
|
116
|
+
const [localLatex, setLocalLatex] = (0, import_react2.useState)(latex);
|
|
117
|
+
const [error, setError] = (0, import_react2.useState)(null);
|
|
118
|
+
(0, import_react2.useEffect)(() => {
|
|
119
|
+
if (isOpen) {
|
|
120
|
+
setLocalLatex(latex);
|
|
121
|
+
setError(null);
|
|
122
|
+
}
|
|
123
|
+
}, [isOpen, latex]);
|
|
124
|
+
const renderedHtml = (0, import_react2.useMemo)(() => {
|
|
125
|
+
if (!latex) return null;
|
|
126
|
+
try {
|
|
127
|
+
return import_katex.default.renderToString(latex, {
|
|
128
|
+
throwOnError: false,
|
|
129
|
+
displayMode: false,
|
|
130
|
+
output: "html"
|
|
131
|
+
});
|
|
132
|
+
} catch {
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
}, [latex]);
|
|
136
|
+
const previewHtml = (0, import_react2.useMemo)(() => {
|
|
137
|
+
if (!localLatex) return null;
|
|
138
|
+
try {
|
|
139
|
+
setError(null);
|
|
140
|
+
return import_katex.default.renderToString(localLatex, {
|
|
141
|
+
throwOnError: true,
|
|
142
|
+
displayMode: false,
|
|
143
|
+
output: "html"
|
|
144
|
+
});
|
|
145
|
+
} catch (_e) {
|
|
146
|
+
setError(intl.formatMessage(messages.invalid_latex));
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
}, [localLatex, intl]);
|
|
150
|
+
const handleSave = (0, import_react2.useCallback)(() => {
|
|
151
|
+
const pos = getPos();
|
|
152
|
+
if (pos === void 0) return;
|
|
153
|
+
editor.view.dispatch(
|
|
154
|
+
editor.state.tr.setNodeMarkup(pos, void 0, { latex: localLatex })
|
|
155
|
+
);
|
|
156
|
+
setIsOpen(false);
|
|
157
|
+
}, [editor, localLatex, getPos]);
|
|
158
|
+
const handleCancel = (0, import_react2.useCallback)(() => {
|
|
159
|
+
setLocalLatex(latex);
|
|
160
|
+
setError(null);
|
|
161
|
+
setIsOpen(false);
|
|
162
|
+
}, [latex]);
|
|
163
|
+
const handleClick = (0, import_react2.useCallback)(
|
|
164
|
+
(e) => {
|
|
165
|
+
e.stopPropagation();
|
|
166
|
+
e.preventDefault();
|
|
167
|
+
if (isEditable) {
|
|
168
|
+
setIsOpen(true);
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
[isEditable]
|
|
172
|
+
);
|
|
173
|
+
const isEmpty = !latex;
|
|
174
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
175
|
+
import_react.NodeViewWrapper,
|
|
176
|
+
{
|
|
177
|
+
as: "span",
|
|
178
|
+
className: "inline-math-wrapper",
|
|
179
|
+
"data-type": "inline-math",
|
|
180
|
+
"data-latex": latex,
|
|
181
|
+
children: [
|
|
182
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
183
|
+
"span",
|
|
184
|
+
{
|
|
185
|
+
className: `inline-math cursor-pointer rounded px-0.5 transition-colors ${isEditable ? "hover:bg-primary/10 hover:ring-1 hover:ring-primary/20" : ""} ${isEmpty ? "text-muted-foreground italic" : ""}`,
|
|
186
|
+
onClick: handleClick,
|
|
187
|
+
children: isEmpty ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "text-xs", children: "$?$" }) : renderedHtml ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
188
|
+
"span",
|
|
189
|
+
{
|
|
190
|
+
dangerouslySetInnerHTML: { __html: renderedHtml }
|
|
191
|
+
}
|
|
192
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "text-destructive text-xs", children: latex })
|
|
193
|
+
}
|
|
194
|
+
),
|
|
195
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.Dialog.Root, { open: isOpen, onOpenChange: setIsOpen, size: "sm", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_dialog.Dialog.Content, { children: [
|
|
196
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.Dialog.Header, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.Dialog.Title, { children: intl.formatMessage(messages.title) }) }),
|
|
197
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.Dialog.Body, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "space-y-4", children: [
|
|
198
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "space-y-1.5", children: [
|
|
199
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_label.Label, { className: "text-sm", children: intl.formatMessage(messages.latex_input) }),
|
|
200
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
201
|
+
"input",
|
|
202
|
+
{
|
|
203
|
+
type: "text",
|
|
204
|
+
className: "w-full p-2 rounded-md border border-input bg-background font-mono text-sm focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
|
|
205
|
+
value: localLatex,
|
|
206
|
+
onChange: (e) => setLocalLatex(e.target.value),
|
|
207
|
+
placeholder: intl.formatMessage(messages.latex_placeholder),
|
|
208
|
+
spellCheck: false
|
|
209
|
+
}
|
|
210
|
+
),
|
|
211
|
+
error && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "text-xs text-destructive", children: error })
|
|
212
|
+
] }),
|
|
213
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "space-y-1.5", children: [
|
|
214
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_label.Label, { className: "text-sm", children: intl.formatMessage(messages.preview) }),
|
|
215
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "min-h-10 p-3 rounded-md border border-border bg-muted/30 flex items-center justify-center", children: previewHtml ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
216
|
+
"span",
|
|
217
|
+
{
|
|
218
|
+
dangerouslySetInnerHTML: { __html: previewHtml }
|
|
219
|
+
}
|
|
220
|
+
) : localLatex ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "text-muted-foreground text-sm", children: intl.formatMessage(messages.invalid_latex) }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "text-muted-foreground text-sm", children: "$...$" }) })
|
|
221
|
+
] })
|
|
222
|
+
] }) }),
|
|
223
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_dialog.Dialog.Footer, { children: [
|
|
224
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_button.Button, { variant: "ghost", onClick: handleCancel, children: intl.formatMessage(messages.cancel) }),
|
|
225
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_button.Button, { onClick: handleSave, disabled: !!error && !!localLatex, children: intl.formatMessage(messages.save) })
|
|
226
|
+
] })
|
|
227
|
+
] }) })
|
|
228
|
+
]
|
|
229
|
+
}
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// src/extensions/math/inline-math.ts
|
|
234
|
+
var InlineMath = import_core.Node.create({
|
|
235
|
+
name: "inlineMath",
|
|
236
|
+
group: "inline",
|
|
237
|
+
inline: true,
|
|
238
|
+
atom: true,
|
|
239
|
+
addOptions() {
|
|
240
|
+
return {
|
|
241
|
+
HTMLAttributes: {}
|
|
242
|
+
};
|
|
243
|
+
},
|
|
244
|
+
addAttributes() {
|
|
245
|
+
return {
|
|
246
|
+
latex: {
|
|
247
|
+
default: "",
|
|
248
|
+
parseHTML: (element) => element.getAttribute("data-latex") || "",
|
|
249
|
+
renderHTML: (attributes) => ({
|
|
250
|
+
"data-latex": attributes.latex
|
|
251
|
+
})
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
},
|
|
255
|
+
parseHTML() {
|
|
256
|
+
return [
|
|
257
|
+
{
|
|
258
|
+
tag: 'span[data-type="inline-math"]'
|
|
259
|
+
}
|
|
260
|
+
];
|
|
261
|
+
},
|
|
262
|
+
renderHTML({ HTMLAttributes }) {
|
|
263
|
+
return [
|
|
264
|
+
"span",
|
|
265
|
+
(0, import_core.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes, {
|
|
266
|
+
"data-type": "inline-math"
|
|
267
|
+
})
|
|
268
|
+
];
|
|
269
|
+
},
|
|
270
|
+
addNodeView() {
|
|
271
|
+
return (0, import_react3.ReactNodeViewRenderer)(InlineMathView, {
|
|
272
|
+
as: "span"
|
|
273
|
+
});
|
|
274
|
+
},
|
|
275
|
+
addCommands() {
|
|
276
|
+
return {
|
|
277
|
+
insertInlineMath: (latex = "") => ({ commands }) => {
|
|
278
|
+
return commands.insertContent({
|
|
279
|
+
type: this.name,
|
|
280
|
+
attrs: { latex }
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
},
|
|
285
|
+
addInputRules() {
|
|
286
|
+
return [
|
|
287
|
+
// Inline math with $...$
|
|
288
|
+
new import_core.InputRule({
|
|
289
|
+
// Match $...$ but not $$...$$
|
|
290
|
+
find: /(?<!\$)\$([^$]+)\$(?!\$)/,
|
|
291
|
+
handler: ({ state, range, match }) => {
|
|
292
|
+
const latex = match[1];
|
|
293
|
+
const { tr } = state;
|
|
294
|
+
tr.replaceWith(range.from, range.to, this.type.create({ latex }));
|
|
295
|
+
}
|
|
296
|
+
})
|
|
297
|
+
];
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
var inline_math_default = InlineMath;
|
|
301
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
302
|
+
0 && (module.exports = {
|
|
303
|
+
InlineMath
|
|
304
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { NodeViewProps } from '@tiptap/react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Math Block NodeView Component
|
|
6
|
+
*
|
|
7
|
+
* Renders a LaTeX formula using KaTeX with an edit dialog.
|
|
8
|
+
*/
|
|
9
|
+
declare function MathBlockView({ editor, node, getPos }: NodeViewProps): react_jsx_runtime.JSX.Element;
|
|
10
|
+
|
|
11
|
+
export { MathBlockView, MathBlockView as default };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { NodeViewProps } from '@tiptap/react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Math Block NodeView Component
|
|
6
|
+
*
|
|
7
|
+
* Renders a LaTeX formula using KaTeX with an edit dialog.
|
|
8
|
+
*/
|
|
9
|
+
declare function MathBlockView({ editor, node, getPos }: NodeViewProps): react_jsx_runtime.JSX.Element;
|
|
10
|
+
|
|
11
|
+
export { MathBlockView, MathBlockView as default };
|