@examplary/ui 1.56.0 → 1.58.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/components/ai/ai-icon.js +2 -25
- package/dist/components/ai/ai-prompt-suggestion.js +3 -26
- package/dist/components/brand/tick-icon.js +2 -25
- package/dist/components/chat/chat-input.js +8 -31
- package/dist/components/chat/chat-typing-indicator.js +2 -2
- package/dist/components/chat/chat-view.js +6 -34
- package/dist/components/loading/ai-spinner.js +2 -13
- package/dist/components/loading/tick-loader.js +39 -104
- package/dist/components/print/answer-box.js +2 -25
- package/dist/components/question-types/fetch-component.js +65 -106
- package/dist/components/question-types/format-question-type.d.ts +41 -41
- package/dist/components/question-types/format-question-type.js +36 -37
- package/dist/components/rich-text/minimal-rich-text-field.d.ts +2 -2
- package/dist/components/rich-text/minimal-rich-text-field.js +47 -85
- package/dist/components/rich-text/rich-text-display.js +15 -33
- package/dist/components/rich-text/rich-text-field.js +2 -25
- package/dist/components/rich-text/rich-text-toolbar.d.ts +3 -2
- package/dist/components/rich-text/rich-text-toolbar.js +5 -6
- package/dist/components/rich-text/tiptap/collaboration-caret.js +24 -34
- package/dist/components/rich-text/tiptap/comments/comment-bubble.d.ts +1 -1
- package/dist/components/rich-text/tiptap/comments/comment-bubble.js +36 -41
- package/dist/components/rich-text/tiptap/content-reference.js +6 -7
- package/dist/components/rich-text/tiptap/crop-page-clipping-modal.d.ts +3 -3
- package/dist/components/rich-text/tiptap/crop-page-clipping-modal.js +20 -25
- package/dist/components/rich-text/tiptap/extensions.d.ts +2 -2
- package/dist/components/rich-text/tiptap/extensions.js +6 -16
- package/dist/components/rich-text/tiptap/file-attachment.js +9 -11
- package/dist/components/rich-text/tiptap/file-handler.d.ts +2 -2
- package/dist/components/rich-text/tiptap/file-handler.js +110 -185
- package/dist/components/rich-text/tiptap/image.js +18 -23
- package/dist/components/rich-text/tiptap/mathematics-component.js +25 -30
- package/dist/components/rich-text/tiptap/mathematics.js +56 -82
- package/dist/components/rich-text/tiptap/page-clipping.js +3 -4
- package/dist/components/rich-text/tiptap/png-scanner.js +63 -108
- package/dist/components/rich-text/tiptap/rich-text-formatting-menu.d.ts +1 -1
- package/dist/components/rich-text/tiptap/rich-text-formatting-menu.js +31 -46
- package/dist/components/ui/alert.d.ts +3 -3
- package/dist/components/ui/alert.js +7 -32
- package/dist/components/ui/avatar.js +18 -14
- package/dist/components/ui/badge.d.ts +3 -3
- package/dist/components/ui/badge.js +4 -27
- package/dist/components/ui/button.d.ts +4 -4
- package/dist/components/ui/button.js +4 -27
- package/dist/components/ui/card.js +6 -46
- package/dist/components/ui/checkbox.js +1 -26
- package/dist/components/ui/color-picker.js +11 -22
- package/dist/components/ui/command-palette.d.ts +2 -2
- package/dist/components/ui/command-palette.js +38 -72
- package/dist/components/ui/command.js +18 -49
- package/dist/components/ui/comments.js +37 -107
- package/dist/components/ui/context-menu.js +30 -67
- package/dist/components/ui/dialog.js +15 -61
- package/dist/components/ui/dropdown.js +17 -64
- package/dist/components/ui/floating-menu.js +2 -25
- package/dist/components/ui/floating-resizable.d.ts +5 -0
- package/dist/components/ui/floating-resizable.js +24 -0
- package/dist/components/ui/help-icon.js +1 -2
- package/dist/components/ui/icon-picker.js +50 -130
- package/dist/components/ui/index.d.ts +1 -0
- package/dist/components/ui/index.js +1 -0
- package/dist/components/ui/input.js +2 -25
- package/dist/components/ui/label.d.ts +1 -1
- package/dist/components/ui/label.js +2 -27
- package/dist/components/ui/popover.d.ts +2 -2
- package/dist/components/ui/popover.js +4 -32
- package/dist/components/ui/progress-bar.js +2 -3
- package/dist/components/ui/radio-group.js +4 -28
- package/dist/components/ui/resizable.d.ts +6 -9
- package/dist/components/ui/resizable.js +13 -60
- package/dist/components/ui/select.js +12 -55
- package/dist/components/ui/separator.js +1 -26
- package/dist/components/ui/sheet.d.ts +3 -3
- package/dist/components/ui/sheet.js +11 -51
- package/dist/components/ui/skeleton.js +2 -25
- package/dist/components/ui/slider.js +7 -32
- package/dist/components/ui/sortable.d.ts +1 -1
- package/dist/components/ui/sortable.js +131 -155
- package/dist/components/ui/switch.d.ts +3 -3
- package/dist/components/ui/switch.js +3 -28
- package/dist/components/ui/table.js +8 -54
- package/dist/components/ui/tabs.js +8 -34
- package/dist/components/ui/text-selection-menu.d.ts +1 -1
- package/dist/components/ui/text-selection-menu.js +19 -25
- package/dist/components/ui/textarea.js +7 -30
- package/dist/components/ui/tooltip.js +4 -29
- package/dist/components/web-components/content-reference.js +81 -106
- package/dist/components/web-components/file-attachment.js +9 -30
- package/dist/components/web-components/index.js +1 -1
- package/dist/components/web-components/inline-comment-reply.js +3 -24
- package/dist/components/web-components/inline-comment.js +3 -24
- package/dist/components/web-components/inline-math.js +14 -36
- package/dist/components/web-components/page-clipping.js +13 -34
- package/dist/lib/compose-refs.js +10 -18
- package/dist/lib/use-spin-loop.js +19 -69
- package/dist/src/global.css +2 -2
- package/dist/utils.js +1 -5
- package/package.json +5 -4
- package/dist/components/rich-text/tiptap/comments/comment-reply.d.ts +0 -21
- package/dist/components/rich-text/tiptap/comments/comment-reply.js +0 -230
- package/dist/components/rich-text/tiptap/comments/comment.d.ts +0 -22
- package/dist/components/rich-text/tiptap/comments/comment.js +0 -198
- package/dist/components/rich-text/tiptap/comments/helpers.d.ts +0 -19
- package/dist/components/rich-text/tiptap/comments/helpers.js +0 -95
- package/dist/components/rich-text/tiptap/comments/types.d.ts +0 -29
- package/dist/components/rich-text/tiptap/comments/types.js +0 -1
|
@@ -1,199 +1,124 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
12
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
-
function step(op) {
|
|
15
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
-
switch (op[0]) {
|
|
20
|
-
case 0: case 1: t = op; break;
|
|
21
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
-
default:
|
|
25
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
-
if (t[2]) _.ops.pop();
|
|
30
|
-
_.trys.pop(); continue;
|
|
31
|
-
}
|
|
32
|
-
op = body.call(thisArg, _);
|
|
33
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
1
|
import toast from "react-hot-toast";
|
|
38
2
|
import FileHandler from "@tiptap/extension-file-handler";
|
|
39
3
|
import { getImageSize } from "./png-scanner";
|
|
40
|
-
export
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
var _a, url, name_1, isImage, attrs, width, _1, e_2;
|
|
50
|
-
return __generator(this, function (_b) {
|
|
51
|
-
switch (_b.label) {
|
|
52
|
-
case 0:
|
|
53
|
-
_b.trys.push([0, 6, , 7]);
|
|
54
|
-
return [4 /*yield*/, uploadFile(file)];
|
|
55
|
-
case 1:
|
|
56
|
-
_a = _b.sent(), url = _a.url, name_1 = _a.name;
|
|
57
|
-
console.log({ url: url, name: name_1 });
|
|
58
|
-
isImage = file.type.startsWith("image/");
|
|
59
|
-
attrs = {
|
|
60
|
-
src: url,
|
|
61
|
-
title: name_1,
|
|
62
|
-
type: file.type,
|
|
63
|
-
};
|
|
64
|
-
if (!isImage) return [3 /*break*/, 5];
|
|
65
|
-
_b.label = 2;
|
|
66
|
-
case 2:
|
|
67
|
-
_b.trys.push([2, 4, , 5]);
|
|
68
|
-
return [4 /*yield*/, getImageSize(file)];
|
|
69
|
-
case 3:
|
|
70
|
-
width = (_b.sent()).width;
|
|
71
|
-
if (width)
|
|
72
|
-
attrs.width = width;
|
|
73
|
-
return [3 /*break*/, 5];
|
|
74
|
-
case 4:
|
|
75
|
-
_1 = _b.sent();
|
|
76
|
-
return [3 /*break*/, 5];
|
|
77
|
-
case 5:
|
|
78
|
-
if (isImage) {
|
|
79
|
-
return [2 /*return*/, "<img src=\"".concat(url, "\" title=\"").concat(name_1, "\" width=\"").concat(attrs.width, "\" alt=\"").concat(name_1, "\"/>")];
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
return [2 /*return*/, "<file-attachment title=\"".concat(name_1, "\" type=\"").concat(file.type, "\" href=\"").concat(url, "\">").concat(name_1, "</file-attachment>")];
|
|
83
|
-
}
|
|
84
|
-
return [3 /*break*/, 7];
|
|
85
|
-
case 6:
|
|
86
|
-
e_2 = _b.sent();
|
|
87
|
-
console.log(e_2);
|
|
88
|
-
throw e_2;
|
|
89
|
-
case 7: return [2 /*return*/];
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
}); }))];
|
|
93
|
-
case 1:
|
|
94
|
-
items = _a.sent();
|
|
95
|
-
resolve(items.join(""));
|
|
96
|
-
return [3 /*break*/, 3];
|
|
97
|
-
case 2:
|
|
98
|
-
e_1 = _a.sent();
|
|
99
|
-
console.log(e_1);
|
|
100
|
-
throw e_1;
|
|
101
|
-
case 3: return [2 /*return*/];
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
}); }, {
|
|
105
|
-
loading: "Uploading file...",
|
|
106
|
-
success: "Uploaded successfully!",
|
|
107
|
-
error: "Failed to upload file",
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
};
|
|
111
|
-
export var processFiles = function (uploadFile, currentEditor, files, pos) {
|
|
112
|
-
toast.promise(Promise.all(files.map(function (file) { return __awaiter(void 0, void 0, void 0, function () {
|
|
113
|
-
var _a, url, name_2, isImage, attrs, width, _2, content, e_3;
|
|
114
|
-
return __generator(this, function (_b) {
|
|
115
|
-
switch (_b.label) {
|
|
116
|
-
case 0:
|
|
117
|
-
_b.trys.push([0, 6, , 7]);
|
|
118
|
-
return [4 /*yield*/, uploadFile(file)];
|
|
119
|
-
case 1:
|
|
120
|
-
_a = _b.sent(), url = _a.url, name_2 = _a.name;
|
|
121
|
-
isImage = file.type.startsWith("image/");
|
|
122
|
-
attrs = {
|
|
4
|
+
export const processFilesAsString = (uploadFile, files) => new Promise((resolve) => {
|
|
5
|
+
toast.promise(async () => {
|
|
6
|
+
try {
|
|
7
|
+
const items = await Promise.all(Array.from(files).map(async (file) => {
|
|
8
|
+
try {
|
|
9
|
+
const { url, name } = await uploadFile(file);
|
|
10
|
+
console.log({ url, name });
|
|
11
|
+
const isImage = file.type.startsWith("image/");
|
|
12
|
+
const attrs = {
|
|
123
13
|
src: url,
|
|
124
|
-
title:
|
|
14
|
+
title: name,
|
|
125
15
|
type: file.type,
|
|
126
16
|
};
|
|
127
|
-
if (
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
case 3:
|
|
133
|
-
width = (_b.sent()).width;
|
|
134
|
-
if (width)
|
|
135
|
-
attrs.width = width;
|
|
136
|
-
return [3 /*break*/, 5];
|
|
137
|
-
case 4:
|
|
138
|
-
_2 = _b.sent();
|
|
139
|
-
return [3 /*break*/, 5];
|
|
140
|
-
case 5:
|
|
141
|
-
content = isImage
|
|
142
|
-
? {
|
|
143
|
-
type: "image",
|
|
144
|
-
attrs: attrs,
|
|
17
|
+
if (isImage) {
|
|
18
|
+
try {
|
|
19
|
+
const { width } = await getImageSize(file);
|
|
20
|
+
if (width)
|
|
21
|
+
attrs.width = width;
|
|
145
22
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
23
|
+
catch (_) {
|
|
24
|
+
// do nothing
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (isImage) {
|
|
28
|
+
return `<img src="${url}" title="${name}" width="${attrs.width}" alt="${name}"/>`;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
return `<file-attachment title="${name}" type="${file.type}" href="${url}">${name}</file-attachment>`;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
console.log(e);
|
|
36
|
+
throw e;
|
|
37
|
+
}
|
|
38
|
+
}));
|
|
39
|
+
resolve(items.join(""));
|
|
40
|
+
}
|
|
41
|
+
catch (e) {
|
|
42
|
+
console.log(e);
|
|
43
|
+
throw e;
|
|
44
|
+
}
|
|
45
|
+
}, {
|
|
167
46
|
loading: "Uploading file...",
|
|
168
47
|
success: "Uploaded successfully!",
|
|
169
48
|
error: "Failed to upload file",
|
|
170
49
|
});
|
|
171
|
-
};
|
|
172
|
-
export
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
"image/
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
if (htmlContent) {
|
|
191
|
-
// if there is htmlContent, stop manual insertion & let other extensions handle insertion via inputRule
|
|
192
|
-
// you could extract the pasted file from this url string and upload it to a server for example
|
|
193
|
-
return false;
|
|
50
|
+
});
|
|
51
|
+
export const processFiles = (uploadFile, currentEditor, files, pos) => {
|
|
52
|
+
toast.promise(Promise.all(files.map(async (file) => {
|
|
53
|
+
try {
|
|
54
|
+
const { url, name } = await uploadFile(file);
|
|
55
|
+
const isImage = file.type.startsWith("image/");
|
|
56
|
+
const attrs = {
|
|
57
|
+
src: url,
|
|
58
|
+
title: name,
|
|
59
|
+
type: file.type,
|
|
60
|
+
};
|
|
61
|
+
if (isImage) {
|
|
62
|
+
try {
|
|
63
|
+
const { width } = await getImageSize(file);
|
|
64
|
+
if (width)
|
|
65
|
+
attrs.width = width;
|
|
66
|
+
}
|
|
67
|
+
catch (_) {
|
|
68
|
+
// do nothing
|
|
194
69
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
70
|
+
}
|
|
71
|
+
const content = isImage
|
|
72
|
+
? {
|
|
73
|
+
type: "image",
|
|
74
|
+
attrs,
|
|
75
|
+
}
|
|
76
|
+
: {
|
|
77
|
+
type: "file-attachment",
|
|
78
|
+
attrs,
|
|
79
|
+
content: [
|
|
80
|
+
{
|
|
81
|
+
type: "text",
|
|
82
|
+
href: url,
|
|
83
|
+
text: name,
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
};
|
|
87
|
+
currentEditor.chain().insertContentAt(pos, content).focus().run();
|
|
88
|
+
}
|
|
89
|
+
catch (e) {
|
|
90
|
+
console.log(e);
|
|
91
|
+
throw e;
|
|
92
|
+
}
|
|
93
|
+
})), {
|
|
94
|
+
loading: "Uploading file...",
|
|
95
|
+
success: "Uploaded successfully!",
|
|
96
|
+
error: "Failed to upload file",
|
|
198
97
|
});
|
|
199
98
|
};
|
|
99
|
+
export const fileHandler = (uploadFile) => FileHandler.configure({
|
|
100
|
+
allowedMimeTypes: [
|
|
101
|
+
"image/png",
|
|
102
|
+
"image/jpeg",
|
|
103
|
+
"image/gif",
|
|
104
|
+
"image/webp",
|
|
105
|
+
"application/pdf",
|
|
106
|
+
"text/html",
|
|
107
|
+
"text/plain",
|
|
108
|
+
"application/msword",
|
|
109
|
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
110
|
+
],
|
|
111
|
+
onDrop: (currentEditor, files, pos) => {
|
|
112
|
+
processFiles(uploadFile, currentEditor, files, pos);
|
|
113
|
+
},
|
|
114
|
+
onPaste: (currentEditor, files, htmlContent) => {
|
|
115
|
+
files.forEach((file) => {
|
|
116
|
+
if (htmlContent) {
|
|
117
|
+
// if there is htmlContent, stop manual insertion & let other extensions handle insertion via inputRule
|
|
118
|
+
// you could extract the pasted file from this url string and upload it to a server for example
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
processFiles(uploadFile, currentEditor, [file], currentEditor.state.selection.anchor);
|
|
122
|
+
});
|
|
123
|
+
},
|
|
124
|
+
});
|
|
@@ -2,28 +2,28 @@ import { mergeAttributes, Node, nodeInputRule } from "@tiptap/core";
|
|
|
2
2
|
/**
|
|
3
3
|
* Matches an image to a  on input.
|
|
4
4
|
*/
|
|
5
|
-
export
|
|
5
|
+
export const inputRegex = /(?:^|\s)(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/;
|
|
6
6
|
/**
|
|
7
7
|
* This extension allows you to insert images.
|
|
8
8
|
* @see https://www.tiptap.dev/api/nodes/image
|
|
9
9
|
*/
|
|
10
|
-
|
|
10
|
+
const Image = Node.create({
|
|
11
11
|
name: "image",
|
|
12
|
-
addOptions
|
|
12
|
+
addOptions() {
|
|
13
13
|
return {
|
|
14
14
|
inline: false,
|
|
15
15
|
allowBase64: false,
|
|
16
16
|
HTMLAttributes: {},
|
|
17
17
|
};
|
|
18
18
|
},
|
|
19
|
-
inline
|
|
19
|
+
inline() {
|
|
20
20
|
return this.options.inline;
|
|
21
21
|
},
|
|
22
|
-
group
|
|
22
|
+
group() {
|
|
23
23
|
return this.options.inline ? "inline" : "block";
|
|
24
24
|
},
|
|
25
25
|
draggable: true,
|
|
26
|
-
addAttributes
|
|
26
|
+
addAttributes() {
|
|
27
27
|
return {
|
|
28
28
|
src: {
|
|
29
29
|
default: null,
|
|
@@ -42,7 +42,7 @@ var Image = Node.create({
|
|
|
42
42
|
},
|
|
43
43
|
};
|
|
44
44
|
},
|
|
45
|
-
parseHTML
|
|
45
|
+
parseHTML() {
|
|
46
46
|
return [
|
|
47
47
|
{
|
|
48
48
|
tag: this.options.allowBase64
|
|
@@ -51,35 +51,30 @@ var Image = Node.create({
|
|
|
51
51
|
},
|
|
52
52
|
];
|
|
53
53
|
},
|
|
54
|
-
renderHTML
|
|
55
|
-
var HTMLAttributes = _a.HTMLAttributes;
|
|
54
|
+
renderHTML({ HTMLAttributes }) {
|
|
56
55
|
return [
|
|
57
56
|
"img",
|
|
58
57
|
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),
|
|
59
58
|
];
|
|
60
59
|
},
|
|
61
|
-
addCommands
|
|
62
|
-
var _this = this;
|
|
60
|
+
addCommands() {
|
|
63
61
|
return {
|
|
64
|
-
setImage:
|
|
65
|
-
return
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
attrs: options,
|
|
70
|
-
});
|
|
71
|
-
};
|
|
62
|
+
setImage: (options) => ({ commands }) => {
|
|
63
|
+
return commands.insertContent({
|
|
64
|
+
type: this.name,
|
|
65
|
+
attrs: options,
|
|
66
|
+
});
|
|
72
67
|
},
|
|
73
68
|
};
|
|
74
69
|
},
|
|
75
|
-
addInputRules
|
|
70
|
+
addInputRules() {
|
|
76
71
|
return [
|
|
77
72
|
nodeInputRule({
|
|
78
73
|
find: inputRegex,
|
|
79
74
|
type: this.type,
|
|
80
|
-
getAttributes:
|
|
81
|
-
|
|
82
|
-
return { src
|
|
75
|
+
getAttributes: (match) => {
|
|
76
|
+
const [, , alt, src, title] = match;
|
|
77
|
+
return { src, alt, title };
|
|
83
78
|
},
|
|
84
79
|
}),
|
|
85
80
|
];
|
|
@@ -6,63 +6,58 @@ import { convertLatexToMathMl } from "mathlive";
|
|
|
6
6
|
import { cn } from "../../../utils.js";
|
|
7
7
|
import { Popover, PopoverTrigger, PopoverContent } from "../../ui/popover.js";
|
|
8
8
|
import "mathlive";
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
return (_jsx(NodeViewWrapper, { as: "span", children: _jsx(InlineMathView, { children: node.attrs.latex, onEdit: function (newLatex) {
|
|
9
|
+
export const MathematicsEditComponent = ({ node, editor }) => {
|
|
10
|
+
return (_jsx(NodeViewWrapper, { as: "span", children: _jsx(InlineMathView, { children: node.attrs.latex, onEdit: (newLatex) => {
|
|
12
11
|
editor.commands.updateInlineMath({ latex: newLatex });
|
|
13
12
|
} }, node.attrs.latex) }));
|
|
14
13
|
};
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
var html = useMemo(function () {
|
|
14
|
+
export const InlineMathView = ({ children, onEdit, }) => {
|
|
15
|
+
const [menuOpen, setMenuOpen] = useState(false);
|
|
16
|
+
const [value, setValue] = useState(children || "");
|
|
17
|
+
const html = useMemo(() => {
|
|
20
18
|
try {
|
|
21
19
|
return convertLatexToMathMl(value);
|
|
22
20
|
}
|
|
23
|
-
catch
|
|
21
|
+
catch {
|
|
24
22
|
return value;
|
|
25
23
|
}
|
|
26
24
|
}, [value]);
|
|
27
|
-
return (_jsxs(Popover, { open: menuOpen, onOpenChange:
|
|
28
|
-
var _a;
|
|
25
|
+
return (_jsxs(Popover, { open: menuOpen, onOpenChange: (open) => {
|
|
29
26
|
setMenuOpen(open);
|
|
30
27
|
if (!open && value !== children) {
|
|
31
|
-
onEdit
|
|
32
|
-
|
|
28
|
+
onEdit?.(value);
|
|
29
|
+
const keyboard = document.querySelector(".ML__keyboard");
|
|
33
30
|
if (keyboard)
|
|
34
|
-
|
|
31
|
+
keyboard.parentNode?.removeChild(keyboard);
|
|
35
32
|
}
|
|
36
|
-
}, children: [_jsx(PopoverTrigger, { asChild: true, children: _jsxs("span", { className: cn("rounded-2xl bg-pink-50 min-h-6 px-1.5 py-0.25 inline-flex gap-2.5 items-center cursor-pointer hover:bg-pink-200 group transition-all", menuOpen && "bg-pink-200"), children: [_jsx("math", { dangerouslySetInnerHTML: { __html: html } }), _jsx(EditIcon, { className: cn("text-pink-500 size-3 hidden group-hover:block shrink-0", menuOpen && "block") })] }) }), _jsx(PopoverContent, { align: "center", side: "bottom", sideOffset: -30, collisionPadding: 12, className: "border border-black p-0 bg-white rounded-md shadow-md max-w-none", onPointerDownOutside:
|
|
37
|
-
|
|
38
|
-
if (mathKeyboard
|
|
33
|
+
}, children: [_jsx(PopoverTrigger, { asChild: true, children: _jsxs("span", { className: cn("rounded-2xl bg-pink-50 min-h-6 px-1.5 py-0.25 inline-flex gap-2.5 items-center cursor-pointer hover:bg-pink-200 group transition-all", menuOpen && "bg-pink-200"), children: [_jsx("math", { dangerouslySetInnerHTML: { __html: html } }), _jsx(EditIcon, { className: cn("text-pink-500 size-3 hidden group-hover:block shrink-0", menuOpen && "block") })] }) }), _jsx(PopoverContent, { align: "center", side: "bottom", sideOffset: -30, collisionPadding: 12, className: "border border-black p-0 bg-white rounded-md shadow-md max-w-none", onPointerDownOutside: (event) => {
|
|
34
|
+
const mathKeyboard = document.querySelector(".ML__keyboard");
|
|
35
|
+
if (mathKeyboard?.contains(event.target)) {
|
|
39
36
|
// Prevent closing when clicking on the math keyboard
|
|
40
37
|
event.preventDefault();
|
|
41
38
|
}
|
|
42
|
-
|
|
43
|
-
if (mathField
|
|
39
|
+
const mathField = document.querySelector("math-field");
|
|
40
|
+
if (mathField?.contains(event.target)) {
|
|
44
41
|
// Prevent closing when clicking on the math field
|
|
45
42
|
event.preventDefault();
|
|
46
43
|
}
|
|
47
|
-
}, children: _jsx("math-field", { className: "min-w-64 max-w-128 p-2 rounded-lg outline-none border-0 focus:ring-0", onInput:
|
|
44
|
+
}, children: _jsx("math-field", { className: "min-w-64 max-w-128 p-2 rounded-lg outline-none border-0 focus:ring-0", onInput: (event) => {
|
|
48
45
|
setValue(event.target.value);
|
|
49
|
-
|
|
46
|
+
const inputType = event.nativeEvent.inputType;
|
|
50
47
|
if (inputType === "insertLineBreak") {
|
|
51
48
|
// Close popover on Enter
|
|
52
49
|
setMenuOpen(false);
|
|
53
50
|
if (value !== children) {
|
|
54
|
-
onEdit
|
|
51
|
+
onEdit?.(value);
|
|
55
52
|
}
|
|
56
53
|
}
|
|
57
|
-
}, ref:
|
|
54
|
+
}, ref: (el) => {
|
|
58
55
|
if (!el)
|
|
59
56
|
return;
|
|
60
|
-
el.menuItems = el.menuItems.filter(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
item.id !== "background-color");
|
|
66
|
-
});
|
|
57
|
+
el.menuItems = el.menuItems.filter((item) => !item.id ||
|
|
58
|
+
(item.id !== "insert-matrix" &&
|
|
59
|
+
item.id !== "mode" &&
|
|
60
|
+
item.id !== "color" &&
|
|
61
|
+
item.id !== "background-color"));
|
|
67
62
|
}, children: value }) })] }));
|
|
68
63
|
};
|