editium 1.0.1
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/LICENSE +21 -0
- package/README.md +424 -0
- package/dist/Editium.d.ts +4 -0
- package/dist/ResizableImage.d.ts +9 -0
- package/dist/TableElement.d.ts +21 -0
- package/dist/Toolbar.d.ts +31 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.esm.js +3128 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +3154 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +99 -0
- package/dist/utils.d.ts +55 -0
- package/package.json +105 -0
- package/vanilla/README.md +409 -0
- package/vanilla/build-bundle.js +41 -0
- package/vanilla/editium.bundle.js +3257 -0
- package/vanilla/editium.css +772 -0
- package/vanilla/editium.js +2453 -0
- package/vanilla/example/README.md +69 -0
- package/vanilla/example/demo.css +351 -0
- package/vanilla/example/demo.js +122 -0
- package/vanilla/example/index.html +202 -0
- package/vanilla/package.json +30 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,3154 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
var React = require('react');
|
|
5
|
+
var slate = require('slate');
|
|
6
|
+
var slateReact = require('slate-react');
|
|
7
|
+
var slateHistory = require('slate-history');
|
|
8
|
+
var outline = require('@heroicons/react/24/outline');
|
|
9
|
+
|
|
10
|
+
/******************************************************************************
|
|
11
|
+
Copyright (c) Microsoft Corporation.
|
|
12
|
+
|
|
13
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
14
|
+
purpose with or without fee is hereby granted.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
17
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
18
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
19
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
20
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
21
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
22
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
23
|
+
***************************************************************************** */
|
|
24
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
var __assign = function() {
|
|
28
|
+
__assign = Object.assign || function __assign(t) {
|
|
29
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
30
|
+
s = arguments[i];
|
|
31
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
32
|
+
}
|
|
33
|
+
return t;
|
|
34
|
+
};
|
|
35
|
+
return __assign.apply(this, arguments);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
39
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
40
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
41
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
42
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
43
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
44
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function __generator(thisArg, body) {
|
|
49
|
+
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);
|
|
50
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
51
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
52
|
+
function step(op) {
|
|
53
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
54
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
55
|
+
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;
|
|
56
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
57
|
+
switch (op[0]) {
|
|
58
|
+
case 0: case 1: t = op; break;
|
|
59
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
60
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
61
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
62
|
+
default:
|
|
63
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
64
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
65
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
66
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
67
|
+
if (t[2]) _.ops.pop();
|
|
68
|
+
_.trys.pop(); continue;
|
|
69
|
+
}
|
|
70
|
+
op = body.call(thisArg, _);
|
|
71
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
72
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function __spreadArray(to, from, pack) {
|
|
77
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
78
|
+
if (ar || !(i in from)) {
|
|
79
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
80
|
+
ar[i] = from[i];
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
87
|
+
var e = new Error(message);
|
|
88
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
var isAlignmentActive = function (editor, alignment) {
|
|
92
|
+
var selection = editor.selection;
|
|
93
|
+
if (!selection)
|
|
94
|
+
return false;
|
|
95
|
+
var match = Array.from(slate.Editor.nodes(editor, {
|
|
96
|
+
at: slate.Editor.unhangRange(editor, selection),
|
|
97
|
+
match: function (n) {
|
|
98
|
+
return !slate.Editor.isEditor(n) &&
|
|
99
|
+
slate.Element.isElement(n) &&
|
|
100
|
+
n.align === alignment;
|
|
101
|
+
},
|
|
102
|
+
}))[0];
|
|
103
|
+
return !!match;
|
|
104
|
+
};
|
|
105
|
+
var toggleAlignment = function (editor, alignment) {
|
|
106
|
+
var isActive = isAlignmentActive(editor, alignment);
|
|
107
|
+
slate.Transforms.setNodes(editor, { align: isActive ? undefined : alignment }, {
|
|
108
|
+
match: function (n) {
|
|
109
|
+
return !slate.Editor.isEditor(n) &&
|
|
110
|
+
slate.Element.isElement(n) &&
|
|
111
|
+
['paragraph', 'heading-one', 'heading-two', 'heading-three', 'heading-four', 'heading-five', 'heading-six', 'heading-seven', 'heading-eight'].includes(n.type);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
var indentListItem = function (editor) {
|
|
116
|
+
var selection = editor.selection;
|
|
117
|
+
if (!selection)
|
|
118
|
+
return;
|
|
119
|
+
var listItemMatch = Array.from(slate.Editor.nodes(editor, {
|
|
120
|
+
match: function (n) {
|
|
121
|
+
return !slate.Editor.isEditor(n) &&
|
|
122
|
+
slate.Element.isElement(n) &&
|
|
123
|
+
n.type === 'list-item';
|
|
124
|
+
},
|
|
125
|
+
}))[0];
|
|
126
|
+
if (!listItemMatch)
|
|
127
|
+
return;
|
|
128
|
+
var listMatch = Array.from(slate.Editor.nodes(editor, {
|
|
129
|
+
match: function (n) {
|
|
130
|
+
return !slate.Editor.isEditor(n) &&
|
|
131
|
+
slate.Element.isElement(n) &&
|
|
132
|
+
['bulleted-list', 'numbered-list'].includes(n.type);
|
|
133
|
+
},
|
|
134
|
+
}))[0];
|
|
135
|
+
if (listMatch) {
|
|
136
|
+
var parentList = listMatch[0];
|
|
137
|
+
var listType = parentList.type;
|
|
138
|
+
slate.Transforms.wrapNodes(editor, { type: listType, children: [] }, {
|
|
139
|
+
match: function (n) {
|
|
140
|
+
return !slate.Editor.isEditor(n) &&
|
|
141
|
+
slate.Element.isElement(n) &&
|
|
142
|
+
n.type === 'list-item';
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
var outdentListItem = function (editor) {
|
|
148
|
+
var selection = editor.selection;
|
|
149
|
+
if (!selection)
|
|
150
|
+
return;
|
|
151
|
+
var listNodes = Array.from(slate.Editor.nodes(editor, {
|
|
152
|
+
match: function (n) {
|
|
153
|
+
return !slate.Editor.isEditor(n) &&
|
|
154
|
+
slate.Element.isElement(n) &&
|
|
155
|
+
['bulleted-list', 'numbered-list'].includes(n.type);
|
|
156
|
+
},
|
|
157
|
+
}));
|
|
158
|
+
if (listNodes.length > 1) {
|
|
159
|
+
slate.Transforms.unwrapNodes(editor, {
|
|
160
|
+
match: function (n) {
|
|
161
|
+
return !slate.Editor.isEditor(n) &&
|
|
162
|
+
slate.Element.isElement(n) &&
|
|
163
|
+
['bulleted-list', 'numbered-list'].includes(n.type);
|
|
164
|
+
},
|
|
165
|
+
split: true,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
else if (listNodes.length === 1) {
|
|
169
|
+
slate.Transforms.unwrapNodes(editor, {
|
|
170
|
+
match: function (n) {
|
|
171
|
+
return !slate.Editor.isEditor(n) &&
|
|
172
|
+
slate.Element.isElement(n) &&
|
|
173
|
+
['bulleted-list', 'numbered-list'].includes(n.type);
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
slate.Transforms.setNodes(editor, { type: 'paragraph' }, {
|
|
177
|
+
match: function (n) {
|
|
178
|
+
return !slate.Editor.isEditor(n) &&
|
|
179
|
+
slate.Element.isElement(n) &&
|
|
180
|
+
n.type === 'list-item';
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
var isMarkActive = function (editor, format) {
|
|
186
|
+
var marks = slate.Editor.marks(editor);
|
|
187
|
+
return marks ? marks[format] === true : false;
|
|
188
|
+
};
|
|
189
|
+
var isBlockActive = function (editor, format) {
|
|
190
|
+
var selection = editor.selection;
|
|
191
|
+
if (!selection)
|
|
192
|
+
return false;
|
|
193
|
+
var match = Array.from(slate.Editor.nodes(editor, {
|
|
194
|
+
at: slate.Editor.unhangRange(editor, selection),
|
|
195
|
+
match: function (n) {
|
|
196
|
+
return !slate.Editor.isEditor(n) &&
|
|
197
|
+
slate.Element.isElement(n) &&
|
|
198
|
+
n.type === format;
|
|
199
|
+
},
|
|
200
|
+
}))[0];
|
|
201
|
+
return !!match;
|
|
202
|
+
};
|
|
203
|
+
var toggleMark = function (editor, format) {
|
|
204
|
+
var isActive = isMarkActive(editor, format);
|
|
205
|
+
if (isActive) {
|
|
206
|
+
slate.Editor.removeMark(editor, format);
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
slate.Editor.addMark(editor, format, true);
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
var applyColor = function (editor, color) {
|
|
213
|
+
if (color === null) {
|
|
214
|
+
slate.Editor.removeMark(editor, 'color');
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
slate.Editor.addMark(editor, 'color', color);
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
var applyBackgroundColor = function (editor, color) {
|
|
221
|
+
if (color === null) {
|
|
222
|
+
slate.Editor.removeMark(editor, 'backgroundColor');
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
slate.Editor.addMark(editor, 'backgroundColor', color);
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
var getActiveColor = function (editor) {
|
|
229
|
+
var marks = slate.Editor.marks(editor);
|
|
230
|
+
return (marks === null || marks === void 0 ? void 0 : marks.color) ? String(marks.color) : null;
|
|
231
|
+
};
|
|
232
|
+
var getActiveBackgroundColor = function (editor) {
|
|
233
|
+
var marks = slate.Editor.marks(editor);
|
|
234
|
+
return (marks === null || marks === void 0 ? void 0 : marks.backgroundColor) ? String(marks.backgroundColor) : null;
|
|
235
|
+
};
|
|
236
|
+
var toggleBlock = function (editor, format) {
|
|
237
|
+
var isActive = isBlockActive(editor, format);
|
|
238
|
+
var isList = ['bulleted-list', 'numbered-list'].includes(format);
|
|
239
|
+
slate.Transforms.unwrapNodes(editor, {
|
|
240
|
+
match: function (n) {
|
|
241
|
+
return !slate.Editor.isEditor(n) &&
|
|
242
|
+
slate.Element.isElement(n) &&
|
|
243
|
+
['bulleted-list', 'numbered-list'].includes(n.type);
|
|
244
|
+
},
|
|
245
|
+
split: true,
|
|
246
|
+
});
|
|
247
|
+
var newProperties;
|
|
248
|
+
if (format === 'list-item') {
|
|
249
|
+
newProperties = { type: isActive ? 'paragraph' : 'list-item' };
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
newProperties = { type: isActive ? 'paragraph' : isList ? 'list-item' : format };
|
|
253
|
+
}
|
|
254
|
+
slate.Transforms.setNodes(editor, newProperties);
|
|
255
|
+
if (!isActive && isList) {
|
|
256
|
+
var block = { type: format, children: [] };
|
|
257
|
+
slate.Transforms.wrapNodes(editor, block);
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
var insertHorizontalRule = function (editor) {
|
|
261
|
+
var hr = {
|
|
262
|
+
type: 'horizontal-rule',
|
|
263
|
+
children: [{ text: '' }],
|
|
264
|
+
};
|
|
265
|
+
slate.Transforms.insertNodes(editor, hr);
|
|
266
|
+
var paragraph = {
|
|
267
|
+
type: 'paragraph',
|
|
268
|
+
children: [{ text: '' }],
|
|
269
|
+
};
|
|
270
|
+
slate.Transforms.insertNodes(editor, paragraph);
|
|
271
|
+
};
|
|
272
|
+
var insertImage = function (editor, url, alt, width) {
|
|
273
|
+
var image = {
|
|
274
|
+
type: 'image',
|
|
275
|
+
url: url,
|
|
276
|
+
alt: alt || 'Image',
|
|
277
|
+
width: width,
|
|
278
|
+
children: [{ text: '' }],
|
|
279
|
+
};
|
|
280
|
+
slate.Transforms.insertNodes(editor, image);
|
|
281
|
+
var paragraph = {
|
|
282
|
+
type: 'paragraph',
|
|
283
|
+
children: [{ text: '' }],
|
|
284
|
+
};
|
|
285
|
+
slate.Transforms.insertNodes(editor, paragraph);
|
|
286
|
+
};
|
|
287
|
+
var isValidImageUrl = function (url) {
|
|
288
|
+
try {
|
|
289
|
+
var parsedUrl = new URL(url);
|
|
290
|
+
var imageExtensions = ['.jpg', '.jpeg', '.png', '.gif', '.svg', '.webp', '.bmp', '.ico'];
|
|
291
|
+
var pathname_1 = parsedUrl.pathname.toLowerCase();
|
|
292
|
+
return imageExtensions.some(function (ext) { return pathname_1.endsWith(ext); }) ||
|
|
293
|
+
parsedUrl.protocol === 'data:' ||
|
|
294
|
+
pathname_1.includes('/image') ||
|
|
295
|
+
parsedUrl.hostname.includes('cdn') ||
|
|
296
|
+
parsedUrl.hostname.includes('imgur') ||
|
|
297
|
+
parsedUrl.hostname.includes('unsplash');
|
|
298
|
+
}
|
|
299
|
+
catch (_a) {
|
|
300
|
+
return false;
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
var insertLink = function (editor, url, title, target) {
|
|
304
|
+
if (editor.selection) {
|
|
305
|
+
wrapLink(editor, url, title, target);
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
var isLinkActive = function (editor) {
|
|
309
|
+
var link = Array.from(slate.Editor.nodes(editor, {
|
|
310
|
+
match: function (n) {
|
|
311
|
+
return !slate.Editor.isEditor(n) &&
|
|
312
|
+
slate.Element.isElement(n) &&
|
|
313
|
+
n.type === 'link';
|
|
314
|
+
},
|
|
315
|
+
}))[0];
|
|
316
|
+
return !!link;
|
|
317
|
+
};
|
|
318
|
+
var unwrapLink = function (editor) {
|
|
319
|
+
slate.Transforms.unwrapNodes(editor, {
|
|
320
|
+
match: function (n) {
|
|
321
|
+
return !slate.Editor.isEditor(n) &&
|
|
322
|
+
slate.Element.isElement(n) &&
|
|
323
|
+
n.type === 'link';
|
|
324
|
+
},
|
|
325
|
+
});
|
|
326
|
+
};
|
|
327
|
+
var wrapLink = function (editor, url, title, target) {
|
|
328
|
+
if (isLinkActive(editor)) {
|
|
329
|
+
unwrapLink(editor);
|
|
330
|
+
}
|
|
331
|
+
var selection = editor.selection;
|
|
332
|
+
var isCollapsed = selection && slate.Range.isCollapsed(selection);
|
|
333
|
+
var link = __assign(__assign(__assign({ type: 'link', url: url }, (title && { title: title })), (target && { target: target })), { children: isCollapsed ? [{ text: url }] : [] });
|
|
334
|
+
if (isCollapsed) {
|
|
335
|
+
slate.Transforms.insertNodes(editor, link);
|
|
336
|
+
}
|
|
337
|
+
else {
|
|
338
|
+
slate.Transforms.wrapNodes(editor, link, { split: true });
|
|
339
|
+
slate.Transforms.collapse(editor, { edge: 'end' });
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
var insertTable = function (editor, rows, cols) {
|
|
343
|
+
if (rows === void 0) { rows = 3; }
|
|
344
|
+
if (cols === void 0) { cols = 3; }
|
|
345
|
+
var tableRows = [];
|
|
346
|
+
for (var i = 0; i < rows; i++) {
|
|
347
|
+
var cells = [];
|
|
348
|
+
for (var j = 0; j < cols; j++) {
|
|
349
|
+
cells.push({
|
|
350
|
+
type: 'table-cell',
|
|
351
|
+
children: [{ text: '' }],
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
tableRows.push({
|
|
355
|
+
type: 'table-row',
|
|
356
|
+
children: cells,
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
var table = {
|
|
360
|
+
type: 'table',
|
|
361
|
+
children: tableRows,
|
|
362
|
+
};
|
|
363
|
+
var paragraph = {
|
|
364
|
+
type: 'paragraph',
|
|
365
|
+
children: [{ text: '' }],
|
|
366
|
+
};
|
|
367
|
+
slate.Transforms.insertNodes(editor, [table, paragraph]);
|
|
368
|
+
};
|
|
369
|
+
var isInTable = function (editor) {
|
|
370
|
+
var selection = editor.selection;
|
|
371
|
+
if (!selection)
|
|
372
|
+
return false;
|
|
373
|
+
var tableMatch = Array.from(slate.Editor.nodes(editor, {
|
|
374
|
+
at: selection,
|
|
375
|
+
match: function (n) {
|
|
376
|
+
return !slate.Editor.isEditor(n) &&
|
|
377
|
+
slate.Element.isElement(n) &&
|
|
378
|
+
n.type === 'table';
|
|
379
|
+
},
|
|
380
|
+
}))[0];
|
|
381
|
+
return !!tableMatch;
|
|
382
|
+
};
|
|
383
|
+
var addTableRow = function (editor) {
|
|
384
|
+
var _a;
|
|
385
|
+
var selection = editor.selection;
|
|
386
|
+
if (!selection)
|
|
387
|
+
return;
|
|
388
|
+
var tableMatch = Array.from(slate.Editor.nodes(editor, {
|
|
389
|
+
at: selection,
|
|
390
|
+
match: function (n) {
|
|
391
|
+
return !slate.Editor.isEditor(n) &&
|
|
392
|
+
slate.Element.isElement(n) &&
|
|
393
|
+
n.type === 'table';
|
|
394
|
+
},
|
|
395
|
+
}))[0];
|
|
396
|
+
if (!tableMatch)
|
|
397
|
+
return;
|
|
398
|
+
var _b = tableMatch, table = _b[0], tablePath = _b[1];
|
|
399
|
+
var firstRow = table.children[0];
|
|
400
|
+
var colCount = ((_a = firstRow === null || firstRow === void 0 ? void 0 : firstRow.children) === null || _a === void 0 ? void 0 : _a.length) || 1;
|
|
401
|
+
var cells = [];
|
|
402
|
+
for (var i = 0; i < colCount; i++) {
|
|
403
|
+
cells.push({
|
|
404
|
+
type: 'table-cell',
|
|
405
|
+
children: [{ text: '' }],
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
var newRow = {
|
|
409
|
+
type: 'table-row',
|
|
410
|
+
children: cells,
|
|
411
|
+
};
|
|
412
|
+
slate.Transforms.insertNodes(editor, newRow, {
|
|
413
|
+
at: __spreadArray(__spreadArray([], tablePath, true), [table.children.length], false),
|
|
414
|
+
});
|
|
415
|
+
};
|
|
416
|
+
var removeTableRow = function (editor) {
|
|
417
|
+
var selection = editor.selection;
|
|
418
|
+
if (!selection)
|
|
419
|
+
return;
|
|
420
|
+
var rowMatch = Array.from(slate.Editor.nodes(editor, {
|
|
421
|
+
at: selection,
|
|
422
|
+
match: function (n) {
|
|
423
|
+
return !slate.Editor.isEditor(n) &&
|
|
424
|
+
slate.Element.isElement(n) &&
|
|
425
|
+
n.type === 'table-row';
|
|
426
|
+
},
|
|
427
|
+
}))[0];
|
|
428
|
+
if (!rowMatch)
|
|
429
|
+
return;
|
|
430
|
+
var _a = rowMatch, rowPath = _a[1];
|
|
431
|
+
var tableMatch = Array.from(slate.Editor.nodes(editor, {
|
|
432
|
+
at: selection,
|
|
433
|
+
match: function (n) {
|
|
434
|
+
return !slate.Editor.isEditor(n) &&
|
|
435
|
+
slate.Element.isElement(n) &&
|
|
436
|
+
n.type === 'table';
|
|
437
|
+
},
|
|
438
|
+
}))[0];
|
|
439
|
+
if (tableMatch) {
|
|
440
|
+
var table = tableMatch[0];
|
|
441
|
+
if (table.children.length <= 1) {
|
|
442
|
+
slate.Transforms.removeNodes(editor, {
|
|
443
|
+
match: function (n) {
|
|
444
|
+
return !slate.Editor.isEditor(n) &&
|
|
445
|
+
slate.Element.isElement(n) &&
|
|
446
|
+
n.type === 'table';
|
|
447
|
+
},
|
|
448
|
+
});
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
slate.Transforms.removeNodes(editor, { at: rowPath });
|
|
453
|
+
};
|
|
454
|
+
var addTableColumn = function (editor) {
|
|
455
|
+
var selection = editor.selection;
|
|
456
|
+
if (!selection)
|
|
457
|
+
return;
|
|
458
|
+
var tableMatch = Array.from(slate.Editor.nodes(editor, {
|
|
459
|
+
at: selection,
|
|
460
|
+
match: function (n) {
|
|
461
|
+
return !slate.Editor.isEditor(n) &&
|
|
462
|
+
slate.Element.isElement(n) &&
|
|
463
|
+
n.type === 'table';
|
|
464
|
+
},
|
|
465
|
+
}))[0];
|
|
466
|
+
if (!tableMatch)
|
|
467
|
+
return;
|
|
468
|
+
var _a = tableMatch, table = _a[0], tablePath = _a[1];
|
|
469
|
+
table.children.forEach(function (_row, rowIndex) {
|
|
470
|
+
var newCell = {
|
|
471
|
+
type: 'table-cell',
|
|
472
|
+
children: [{ text: '' }],
|
|
473
|
+
};
|
|
474
|
+
slate.Transforms.insertNodes(editor, newCell, {
|
|
475
|
+
at: __spreadArray(__spreadArray([], tablePath, true), [rowIndex, table.children[rowIndex].children.length], false),
|
|
476
|
+
});
|
|
477
|
+
});
|
|
478
|
+
};
|
|
479
|
+
var removeTableColumn = function (editor) {
|
|
480
|
+
var _a, _b;
|
|
481
|
+
var selection = editor.selection;
|
|
482
|
+
if (!selection)
|
|
483
|
+
return;
|
|
484
|
+
var cellMatch = Array.from(slate.Editor.nodes(editor, {
|
|
485
|
+
at: selection,
|
|
486
|
+
match: function (n) {
|
|
487
|
+
return !slate.Editor.isEditor(n) &&
|
|
488
|
+
slate.Element.isElement(n) &&
|
|
489
|
+
n.type === 'table-cell';
|
|
490
|
+
},
|
|
491
|
+
}))[0];
|
|
492
|
+
if (!cellMatch)
|
|
493
|
+
return;
|
|
494
|
+
var _c = cellMatch, cellPath = _c[1];
|
|
495
|
+
var cellIndex = cellPath[cellPath.length - 1];
|
|
496
|
+
var tableMatch = Array.from(slate.Editor.nodes(editor, {
|
|
497
|
+
at: selection,
|
|
498
|
+
match: function (n) {
|
|
499
|
+
return !slate.Editor.isEditor(n) &&
|
|
500
|
+
slate.Element.isElement(n) &&
|
|
501
|
+
n.type === 'table';
|
|
502
|
+
},
|
|
503
|
+
}))[0];
|
|
504
|
+
if (!tableMatch)
|
|
505
|
+
return;
|
|
506
|
+
var _d = tableMatch, table = _d[0], tablePath = _d[1];
|
|
507
|
+
if (((_b = (_a = table.children[0]) === null || _a === void 0 ? void 0 : _a.children) === null || _b === void 0 ? void 0 : _b.length) <= 1) {
|
|
508
|
+
slate.Transforms.removeNodes(editor, { at: tablePath });
|
|
509
|
+
return;
|
|
510
|
+
}
|
|
511
|
+
for (var rowIndex = table.children.length - 1; rowIndex >= 0; rowIndex--) {
|
|
512
|
+
slate.Transforms.removeNodes(editor, {
|
|
513
|
+
at: __spreadArray(__spreadArray([], tablePath, true), [rowIndex, cellIndex], false),
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
};
|
|
517
|
+
var setTableAlignment = function (editor, alignment) {
|
|
518
|
+
var selection = editor.selection;
|
|
519
|
+
if (!selection)
|
|
520
|
+
return;
|
|
521
|
+
var tableMatch = Array.from(slate.Editor.nodes(editor, {
|
|
522
|
+
at: selection,
|
|
523
|
+
match: function (n) {
|
|
524
|
+
return !slate.Editor.isEditor(n) &&
|
|
525
|
+
slate.Element.isElement(n) &&
|
|
526
|
+
n.type === 'table';
|
|
527
|
+
},
|
|
528
|
+
}))[0];
|
|
529
|
+
if (!tableMatch)
|
|
530
|
+
return;
|
|
531
|
+
var _a = tableMatch, tablePath = _a[1];
|
|
532
|
+
slate.Transforms.setNodes(editor, { align: alignment }, { at: tablePath });
|
|
533
|
+
};
|
|
534
|
+
var findAllMatches = function (editor, searchQuery) {
|
|
535
|
+
if (!searchQuery)
|
|
536
|
+
return [];
|
|
537
|
+
var matches = [];
|
|
538
|
+
var searchLower = searchQuery.toLowerCase();
|
|
539
|
+
var textNodes = Array.from(slate.Editor.nodes(editor, {
|
|
540
|
+
at: [],
|
|
541
|
+
match: function (n) { return slate.Text.isText(n); },
|
|
542
|
+
}));
|
|
543
|
+
textNodes.forEach(function (_a) {
|
|
544
|
+
var node = _a[0], path = _a[1];
|
|
545
|
+
var textNode = node;
|
|
546
|
+
var text = textNode.text;
|
|
547
|
+
var textLower = text.toLowerCase();
|
|
548
|
+
var index = 0;
|
|
549
|
+
while ((index = textLower.indexOf(searchLower, index)) !== -1) {
|
|
550
|
+
matches.push({
|
|
551
|
+
path: path,
|
|
552
|
+
offset: index,
|
|
553
|
+
text: text.substring(index, index + searchQuery.length),
|
|
554
|
+
});
|
|
555
|
+
index += searchQuery.length;
|
|
556
|
+
}
|
|
557
|
+
});
|
|
558
|
+
return matches;
|
|
559
|
+
};
|
|
560
|
+
var navigateToMatch = function (editor, match) {
|
|
561
|
+
var _a;
|
|
562
|
+
var start = { path: match.path, offset: match.offset };
|
|
563
|
+
var end = { path: match.path, offset: match.offset + match.text.length };
|
|
564
|
+
slate.Transforms.select(editor, { anchor: start, focus: end });
|
|
565
|
+
var domRange = slateReact.ReactEditor.toDOMRange(editor, editor.selection);
|
|
566
|
+
(_a = domRange.startContainer.parentElement) === null || _a === void 0 ? void 0 : _a.scrollIntoView({
|
|
567
|
+
behavior: 'smooth',
|
|
568
|
+
block: 'center',
|
|
569
|
+
});
|
|
570
|
+
};
|
|
571
|
+
var replaceMatch = function (editor, match, replaceText) {
|
|
572
|
+
var start = { path: match.path, offset: match.offset };
|
|
573
|
+
var end = { path: match.path, offset: match.offset + match.text.length };
|
|
574
|
+
slate.Transforms.select(editor, { anchor: start, focus: end });
|
|
575
|
+
slate.Transforms.insertText(editor, replaceText);
|
|
576
|
+
};
|
|
577
|
+
var replaceAllMatches = function (editor, matches, replaceText) {
|
|
578
|
+
var sortedMatches = __spreadArray([], matches, true).reverse();
|
|
579
|
+
slate.Editor.withoutNormalizing(editor, function () {
|
|
580
|
+
sortedMatches.forEach(function (match) {
|
|
581
|
+
var start = { path: match.path, offset: match.offset };
|
|
582
|
+
var end = { path: match.path, offset: match.offset + match.text.length };
|
|
583
|
+
slate.Transforms.select(editor, { anchor: start, focus: end });
|
|
584
|
+
slate.Transforms.delete(editor);
|
|
585
|
+
slate.Transforms.insertText(editor, replaceText, { at: start });
|
|
586
|
+
});
|
|
587
|
+
});
|
|
588
|
+
};
|
|
589
|
+
var serializeToHtml = function (nodes) {
|
|
590
|
+
return nodes.map(function (node) { return serializeNode(node); }).join('');
|
|
591
|
+
};
|
|
592
|
+
var serializeNode = function (node) {
|
|
593
|
+
if (slate.Text.isText(node)) {
|
|
594
|
+
var textNode = node;
|
|
595
|
+
var string = escapeHtml(textNode.text);
|
|
596
|
+
var styles = [];
|
|
597
|
+
if (textNode.color)
|
|
598
|
+
styles.push("color: ".concat(textNode.color));
|
|
599
|
+
if (textNode.backgroundColor)
|
|
600
|
+
styles.push("background-color: ".concat(textNode.backgroundColor));
|
|
601
|
+
var styleAttr = styles.length > 0 ? " style=\"".concat(styles.join('; '), "\"") : '';
|
|
602
|
+
if (textNode.bold)
|
|
603
|
+
string = "<strong>".concat(string, "</strong>");
|
|
604
|
+
if (textNode.italic)
|
|
605
|
+
string = "<em>".concat(string, "</em>");
|
|
606
|
+
if (textNode.underline)
|
|
607
|
+
string = "<u>".concat(string, "</u>");
|
|
608
|
+
if (textNode.code)
|
|
609
|
+
string = "<code>".concat(string, "</code>");
|
|
610
|
+
if (textNode.strikethrough)
|
|
611
|
+
string = "<s>".concat(string, "</s>");
|
|
612
|
+
if (textNode.superscript)
|
|
613
|
+
string = "<sup>".concat(string, "</sup>");
|
|
614
|
+
if (textNode.subscript)
|
|
615
|
+
string = "<sub>".concat(string, "</sub>");
|
|
616
|
+
if (styleAttr) {
|
|
617
|
+
string = "<span".concat(styleAttr, ">").concat(string, "</span>");
|
|
618
|
+
}
|
|
619
|
+
return string;
|
|
620
|
+
}
|
|
621
|
+
var elementNode = node;
|
|
622
|
+
var children = elementNode.children.map(function (n) { return serializeNode(n); }).join('');
|
|
623
|
+
var alignStyle = elementNode.align ? " style=\"text-align: ".concat(elementNode.align, "\"") : '';
|
|
624
|
+
switch (elementNode.type) {
|
|
625
|
+
case 'paragraph':
|
|
626
|
+
return "<p".concat(alignStyle, ">").concat(children, "</p>");
|
|
627
|
+
case 'heading-one':
|
|
628
|
+
return "<h1".concat(alignStyle, ">").concat(children, "</h1>");
|
|
629
|
+
case 'heading-two':
|
|
630
|
+
return "<h2".concat(alignStyle, ">").concat(children, "</h2>");
|
|
631
|
+
case 'heading-three':
|
|
632
|
+
return "<h3".concat(alignStyle, ">").concat(children, "</h3>");
|
|
633
|
+
case 'heading-four':
|
|
634
|
+
return "<h4".concat(alignStyle, ">").concat(children, "</h4>");
|
|
635
|
+
case 'heading-five':
|
|
636
|
+
return "<h5".concat(alignStyle, ">").concat(children, "</h5>");
|
|
637
|
+
case 'heading-six':
|
|
638
|
+
return "<h6".concat(alignStyle, ">").concat(children, "</h6>");
|
|
639
|
+
case 'heading-seven':
|
|
640
|
+
return "<h7".concat(alignStyle, ">").concat(children, "</h7>");
|
|
641
|
+
case 'heading-eight':
|
|
642
|
+
return "<h8".concat(alignStyle, ">").concat(children, "</h8>");
|
|
643
|
+
case 'bulleted-list':
|
|
644
|
+
return "<ul>".concat(children, "</ul>");
|
|
645
|
+
case 'numbered-list':
|
|
646
|
+
return "<ol>".concat(children, "</ol>");
|
|
647
|
+
case 'list-item':
|
|
648
|
+
return "<li>".concat(children, "</li>");
|
|
649
|
+
case 'blockquote':
|
|
650
|
+
return "<blockquote".concat(alignStyle, ">").concat(children, "</blockquote>");
|
|
651
|
+
case 'code-block':
|
|
652
|
+
return "<pre><code>".concat(children, "</code></pre>");
|
|
653
|
+
case 'horizontal-rule':
|
|
654
|
+
return "<hr />";
|
|
655
|
+
case 'table':
|
|
656
|
+
var tableNode = elementNode;
|
|
657
|
+
var tableAlignStyle = tableNode.align ? " margin-left: ".concat(tableNode.align === 'center' ? 'auto' :
|
|
658
|
+
tableNode.align === 'right' ? 'auto' : '0', "; margin-right: ").concat(tableNode.align === 'center' ? 'auto' :
|
|
659
|
+
tableNode.align === 'right' ? '0' : 'auto', ";") : '';
|
|
660
|
+
var tableWidthStyle = tableNode.width ? " width: ".concat(tableNode.width, "px; max-width: 100%;") : ' width: 100%;';
|
|
661
|
+
return "<table style=\"border-collapse: collapse;".concat(tableWidthStyle, " margin-top: 16px; margin-bottom: 16px;").concat(tableAlignStyle, "\">").concat(children, "</table>");
|
|
662
|
+
case 'table-row':
|
|
663
|
+
return "<tr>".concat(children, "</tr>");
|
|
664
|
+
case 'table-cell':
|
|
665
|
+
var cellNode = elementNode;
|
|
666
|
+
var cellAlignStyle = cellNode.align ? " text-align: ".concat(cellNode.align, ";") : '';
|
|
667
|
+
return "<td style=\"border: 1px solid #ddd; padding: 8px;".concat(cellAlignStyle, "\">").concat(children, "</td>");
|
|
668
|
+
case 'image':
|
|
669
|
+
var imageNode = elementNode;
|
|
670
|
+
var altAttr = imageNode.alt ? " alt=\"".concat(escapeHtml(imageNode.alt), "\"") : ' alt="Image"';
|
|
671
|
+
var widthAttr = imageNode.width ? " width=\"".concat(imageNode.width, "\"") : '';
|
|
672
|
+
var heightAttr = imageNode.height ? " height=\"".concat(imageNode.height, "\"") : '';
|
|
673
|
+
var imgAlignStyle = imageNode.align ? " style=\"display: block; margin: ".concat(imageNode.align === 'center' ? '0 auto' :
|
|
674
|
+
imageNode.align === 'right' ? '0 0 0 auto' : '0', ";\"") : '';
|
|
675
|
+
return "<img src=\"".concat(escapeHtml(imageNode.url), "\"").concat(altAttr).concat(widthAttr).concat(heightAttr).concat(imgAlignStyle, " />");
|
|
676
|
+
case 'link':
|
|
677
|
+
var linkNode = elementNode;
|
|
678
|
+
var titleAttr = linkNode.title ? " title=\"".concat(escapeHtml(linkNode.title), "\"") : '';
|
|
679
|
+
var targetAttr = linkNode.target ? " target=\"".concat(linkNode.target, "\"") : '';
|
|
680
|
+
var relAttr = linkNode.target === '_blank' ? ' rel="noopener noreferrer"' : '';
|
|
681
|
+
return "<a href=\"".concat(escapeHtml(linkNode.url), "\"").concat(titleAttr).concat(targetAttr).concat(relAttr, ">").concat(children, "</a>");
|
|
682
|
+
default:
|
|
683
|
+
return children;
|
|
684
|
+
}
|
|
685
|
+
};
|
|
686
|
+
var escapeHtml = function (text) {
|
|
687
|
+
var div = document.createElement('div');
|
|
688
|
+
div.textContent = text;
|
|
689
|
+
return div.innerHTML;
|
|
690
|
+
};
|
|
691
|
+
var defaultInitialValue = [
|
|
692
|
+
{
|
|
693
|
+
type: 'paragraph',
|
|
694
|
+
children: [{ text: '' }],
|
|
695
|
+
},
|
|
696
|
+
];
|
|
697
|
+
var getTextContent = function (nodes) {
|
|
698
|
+
return nodes
|
|
699
|
+
.map(function (node) {
|
|
700
|
+
if (node.text !== undefined) {
|
|
701
|
+
return node.text;
|
|
702
|
+
}
|
|
703
|
+
if (node.children) {
|
|
704
|
+
return getTextContent(node.children);
|
|
705
|
+
}
|
|
706
|
+
return '';
|
|
707
|
+
})
|
|
708
|
+
.join('');
|
|
709
|
+
};
|
|
710
|
+
var countWords = function (text) {
|
|
711
|
+
var trimmed = text.trim();
|
|
712
|
+
if (trimmed === '')
|
|
713
|
+
return 0;
|
|
714
|
+
return trimmed.split(/\s+/).filter(function (word) { return word.length > 0; }).length;
|
|
715
|
+
};
|
|
716
|
+
var countCharacters = function (text) {
|
|
717
|
+
return text.length;
|
|
718
|
+
};
|
|
719
|
+
var countCharactersNoSpaces = function (text) {
|
|
720
|
+
return text.replace(/\s/g, '').length;
|
|
721
|
+
};
|
|
722
|
+
|
|
723
|
+
var Dropdown = function (_a) {
|
|
724
|
+
var trigger = _a.trigger, children = _a.children, title = _a.title;
|
|
725
|
+
var _b = React.useState(false), isOpen = _b[0], setIsOpen = _b[1];
|
|
726
|
+
var dropdownRef = React.useRef(null);
|
|
727
|
+
React.useEffect(function () {
|
|
728
|
+
var handleClickOutside = function (event) {
|
|
729
|
+
if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
|
|
730
|
+
setIsOpen(false);
|
|
731
|
+
}
|
|
732
|
+
};
|
|
733
|
+
document.addEventListener('mousedown', handleClickOutside);
|
|
734
|
+
return function () { return document.removeEventListener('mousedown', handleClickOutside); };
|
|
735
|
+
}, []);
|
|
736
|
+
return (jsxRuntime.jsxs("div", { ref: dropdownRef, style: { position: 'relative', display: 'inline-block' }, children: [jsxRuntime.jsxs("button", { title: title, onMouseDown: function (e) {
|
|
737
|
+
e.preventDefault();
|
|
738
|
+
setIsOpen(!isOpen);
|
|
739
|
+
}, style: {
|
|
740
|
+
backgroundColor: isOpen ? '#dee2e6' : 'transparent',
|
|
741
|
+
border: 'none',
|
|
742
|
+
borderRadius: '3px',
|
|
743
|
+
padding: '5px 8px',
|
|
744
|
+
margin: '0',
|
|
745
|
+
cursor: 'pointer',
|
|
746
|
+
fontSize: '14px',
|
|
747
|
+
fontWeight: '400',
|
|
748
|
+
color: '#222f3e',
|
|
749
|
+
transition: 'background-color 0.1s ease',
|
|
750
|
+
display: 'inline-flex',
|
|
751
|
+
alignItems: 'center',
|
|
752
|
+
justifyContent: 'center',
|
|
753
|
+
minHeight: '28px',
|
|
754
|
+
boxShadow: 'none',
|
|
755
|
+
whiteSpace: 'nowrap',
|
|
756
|
+
}, onMouseEnter: function (e) {
|
|
757
|
+
if (!isOpen) {
|
|
758
|
+
e.currentTarget.style.backgroundColor = '#e9ecef';
|
|
759
|
+
}
|
|
760
|
+
}, onMouseLeave: function (e) {
|
|
761
|
+
if (!isOpen) {
|
|
762
|
+
e.currentTarget.style.backgroundColor = 'transparent';
|
|
763
|
+
}
|
|
764
|
+
}, children: [trigger, jsxRuntime.jsx(outline.ChevronDownIcon, { style: { marginLeft: '4px', width: '12px', height: '12px' } })] }), isOpen && (jsxRuntime.jsx("div", { style: {
|
|
765
|
+
position: 'absolute',
|
|
766
|
+
top: '100%',
|
|
767
|
+
left: '0',
|
|
768
|
+
zIndex: 9999,
|
|
769
|
+
backgroundColor: '#ffffff',
|
|
770
|
+
border: '1px solid #ccc',
|
|
771
|
+
borderRadius: '3px',
|
|
772
|
+
boxShadow: '0 2px 8px rgba(0, 0, 0, 0.15)',
|
|
773
|
+
minWidth: '180px',
|
|
774
|
+
marginTop: '4px',
|
|
775
|
+
overflow: 'hidden',
|
|
776
|
+
padding: '4px 0'
|
|
777
|
+
}, children: children }))] }));
|
|
778
|
+
};
|
|
779
|
+
var ToolbarButton = function (_a) {
|
|
780
|
+
var active = _a.active, onMouseDown = _a.onMouseDown, children = _a.children, title = _a.title;
|
|
781
|
+
return (jsxRuntime.jsx("button", { title: title, onMouseDown: onMouseDown, style: {
|
|
782
|
+
backgroundColor: active ? '#dee2e6' : 'transparent',
|
|
783
|
+
border: 'none',
|
|
784
|
+
borderRadius: '3px',
|
|
785
|
+
padding: '5px 8px',
|
|
786
|
+
margin: '0',
|
|
787
|
+
cursor: 'pointer',
|
|
788
|
+
fontSize: '14px',
|
|
789
|
+
fontWeight: '400',
|
|
790
|
+
color: '#222f3e',
|
|
791
|
+
transition: 'background-color 0.1s ease',
|
|
792
|
+
display: 'inline-flex',
|
|
793
|
+
alignItems: 'center',
|
|
794
|
+
justifyContent: 'center',
|
|
795
|
+
minHeight: '28px',
|
|
796
|
+
boxShadow: 'none',
|
|
797
|
+
whiteSpace: 'nowrap',
|
|
798
|
+
}, onMouseEnter: function (e) {
|
|
799
|
+
if (!active) {
|
|
800
|
+
e.currentTarget.style.backgroundColor = '#e9ecef';
|
|
801
|
+
}
|
|
802
|
+
}, onMouseLeave: function (e) {
|
|
803
|
+
if (!active) {
|
|
804
|
+
e.currentTarget.style.backgroundColor = 'transparent';
|
|
805
|
+
}
|
|
806
|
+
}, children: children }));
|
|
807
|
+
};
|
|
808
|
+
var DropdownItem = function (_a) {
|
|
809
|
+
var active = _a.active, onMouseDown = _a.onMouseDown, children = _a.children, icon = _a.icon;
|
|
810
|
+
return (jsxRuntime.jsxs("button", { onMouseDown: onMouseDown, style: {
|
|
811
|
+
width: '100%',
|
|
812
|
+
padding: '6px 16px',
|
|
813
|
+
border: 'none',
|
|
814
|
+
backgroundColor: active ? '#e7f4ff' : 'transparent',
|
|
815
|
+
color: '#222f3e',
|
|
816
|
+
fontSize: '14px',
|
|
817
|
+
fontWeight: '400',
|
|
818
|
+
cursor: 'pointer',
|
|
819
|
+
textAlign: 'left',
|
|
820
|
+
transition: 'background-color 0.1s ease',
|
|
821
|
+
borderRadius: '0',
|
|
822
|
+
display: 'flex',
|
|
823
|
+
alignItems: 'center',
|
|
824
|
+
gap: '10px',
|
|
825
|
+
}, onMouseEnter: function (e) {
|
|
826
|
+
e.currentTarget.style.backgroundColor = '#e7f4ff';
|
|
827
|
+
}, onMouseLeave: function (e) {
|
|
828
|
+
if (!active) {
|
|
829
|
+
e.currentTarget.style.backgroundColor = 'transparent';
|
|
830
|
+
}
|
|
831
|
+
}, children: [icon && jsxRuntime.jsx("span", { style: { width: '16px', height: '16px', display: 'flex', alignItems: 'center', justifyContent: 'center' }, children: icon }), children] }));
|
|
832
|
+
};
|
|
833
|
+
var ToolbarSeparator = function () { return (jsxRuntime.jsx("div", { style: {
|
|
834
|
+
width: '1px',
|
|
835
|
+
height: '24px',
|
|
836
|
+
backgroundColor: '#ccc',
|
|
837
|
+
margin: '0 4px',
|
|
838
|
+
alignSelf: 'center',
|
|
839
|
+
} })); };
|
|
840
|
+
var Toolbar = function (_a) {
|
|
841
|
+
var _b;
|
|
842
|
+
var items = _a.items, className = _a.className, onViewOutput = _a.onViewOutput; _a.onEditLink; var _c = _a.searchQuery, propSearchQuery = _c === void 0 ? '' : _c, _d = _a.searchMatches, propSearchMatches = _d === void 0 ? [] : _d, _e = _a.currentMatchIndex, propCurrentMatchIndex = _e === void 0 ? 0 : _e, onSearchQueryChange = _a.onSearchQueryChange, onSearchMatchesChange = _a.onSearchMatchesChange, onCurrentMatchIndexChange = _a.onCurrentMatchIndexChange, _f = _a.isFullscreen, isFullscreen = _f === void 0 ? false : _f, onFullscreenToggle = _a.onFullscreenToggle;
|
|
843
|
+
var editor = slateReact.useSlate();
|
|
844
|
+
var _g = React.useState(false), showLinkModal = _g[0], setShowLinkModal = _g[1];
|
|
845
|
+
var _h = React.useState(''), linkText = _h[0], setLinkText = _h[1];
|
|
846
|
+
var _j = React.useState(''), linkUrl = _j[0], setLinkUrl = _j[1];
|
|
847
|
+
var _k = React.useState(''), linkTitle = _k[0], setLinkTitle = _k[1];
|
|
848
|
+
var _l = React.useState('_self'), linkTarget = _l[0], setLinkTarget = _l[1];
|
|
849
|
+
var _m = React.useState(false), isEditingLink = _m[0], setIsEditingLink = _m[1];
|
|
850
|
+
var _o = React.useState(false); _o[0]; _o[1];
|
|
851
|
+
var _p = React.useState({ x: 0, y: 0 }); _p[0]; _p[1];
|
|
852
|
+
var _q = React.useState(false), showImageModal = _q[0], setShowImageModal = _q[1];
|
|
853
|
+
var _r = React.useState(''), imageUrl = _r[0], setImageUrl = _r[1];
|
|
854
|
+
var _s = React.useState(''), imageAlt = _s[0], setImageAlt = _s[1];
|
|
855
|
+
var _t = React.useState(null), imageFile = _t[0], setImageFile = _t[1];
|
|
856
|
+
var _u = React.useState(''), imageUploadError = _u[0], setImageUploadError = _u[1];
|
|
857
|
+
var _v = React.useState(false), isReplacingImage = _v[0], setIsReplacingImage = _v[1];
|
|
858
|
+
var _w = React.useState(null), replacingImagePath = _w[0], setReplacingImagePath = _w[1];
|
|
859
|
+
var _x = React.useState(false), showTableModal = _x[0], setShowTableModal = _x[1];
|
|
860
|
+
var _y = React.useState(3), tableRows = _y[0], setTableRows = _y[1];
|
|
861
|
+
var _z = React.useState(3), tableCols = _z[0], setTableCols = _z[1];
|
|
862
|
+
var _0 = React.useState(false), showFindReplace = _0[0], setShowFindReplace = _0[1];
|
|
863
|
+
var _1 = React.useState(''), replaceText = _1[0], setReplaceText = _1[1];
|
|
864
|
+
var _2 = React.useState(0), totalMatches = _2[0], setTotalMatches = _2[1];
|
|
865
|
+
var searchQuery = propSearchQuery;
|
|
866
|
+
var searchMatches = propSearchMatches;
|
|
867
|
+
var currentMatchIndex = propCurrentMatchIndex;
|
|
868
|
+
var handleMarkToggle = function (event, format) {
|
|
869
|
+
event.preventDefault();
|
|
870
|
+
toggleMark(editor, format);
|
|
871
|
+
};
|
|
872
|
+
var handleBlockToggle = function (event, format) {
|
|
873
|
+
event.preventDefault();
|
|
874
|
+
toggleBlock(editor, format);
|
|
875
|
+
};
|
|
876
|
+
var handleAlignmentToggle = function (event, alignment) {
|
|
877
|
+
event.preventDefault();
|
|
878
|
+
toggleAlignment(editor, alignment);
|
|
879
|
+
};
|
|
880
|
+
var handleIndent = function (event) {
|
|
881
|
+
event.preventDefault();
|
|
882
|
+
indentListItem(editor);
|
|
883
|
+
};
|
|
884
|
+
var handleOutdent = function (event) {
|
|
885
|
+
event.preventDefault();
|
|
886
|
+
outdentListItem(editor);
|
|
887
|
+
};
|
|
888
|
+
var handleUndo = function (event) {
|
|
889
|
+
event.preventDefault();
|
|
890
|
+
slateHistory.HistoryEditor.undo(editor);
|
|
891
|
+
};
|
|
892
|
+
var handleRedo = function (event) {
|
|
893
|
+
event.preventDefault();
|
|
894
|
+
slateHistory.HistoryEditor.redo(editor);
|
|
895
|
+
};
|
|
896
|
+
var handleLinkToggle = function (event) {
|
|
897
|
+
event.preventDefault();
|
|
898
|
+
var selection = editor.selection;
|
|
899
|
+
if (selection) {
|
|
900
|
+
var selectedText = slate.Editor.string(editor, selection);
|
|
901
|
+
setLinkText(selectedText);
|
|
902
|
+
}
|
|
903
|
+
else {
|
|
904
|
+
setLinkText('');
|
|
905
|
+
}
|
|
906
|
+
setLinkUrl('');
|
|
907
|
+
setLinkTitle('');
|
|
908
|
+
setLinkTarget('_self');
|
|
909
|
+
setIsEditingLink(false);
|
|
910
|
+
setShowLinkModal(true);
|
|
911
|
+
};
|
|
912
|
+
var handleInsertLink = function () {
|
|
913
|
+
if (!linkUrl.trim()) {
|
|
914
|
+
alert('URL is required');
|
|
915
|
+
return;
|
|
916
|
+
}
|
|
917
|
+
try {
|
|
918
|
+
new URL(linkUrl);
|
|
919
|
+
}
|
|
920
|
+
catch (_a) {
|
|
921
|
+
alert('Please enter a valid URL (e.g., https://example.com)');
|
|
922
|
+
return;
|
|
923
|
+
}
|
|
924
|
+
if (isEditingLink) {
|
|
925
|
+
slate.Transforms.setNodes(editor, {
|
|
926
|
+
url: linkUrl,
|
|
927
|
+
title: linkTitle || undefined,
|
|
928
|
+
target: linkTarget
|
|
929
|
+
}, {
|
|
930
|
+
match: function (n) { return n.type === 'link'; }
|
|
931
|
+
});
|
|
932
|
+
if (linkText.trim() && editor.selection) {
|
|
933
|
+
slate.Transforms.delete(editor, { at: editor.selection });
|
|
934
|
+
slate.Transforms.insertText(editor, linkText, { at: editor.selection });
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
else {
|
|
938
|
+
if (linkText.trim()) {
|
|
939
|
+
if (editor.selection) {
|
|
940
|
+
slate.Transforms.delete(editor);
|
|
941
|
+
}
|
|
942
|
+
slate.Transforms.insertNodes(editor, {
|
|
943
|
+
type: 'link',
|
|
944
|
+
url: linkUrl,
|
|
945
|
+
title: linkTitle || undefined,
|
|
946
|
+
target: linkTarget,
|
|
947
|
+
children: [{ text: linkText }],
|
|
948
|
+
});
|
|
949
|
+
slate.Transforms.move(editor);
|
|
950
|
+
}
|
|
951
|
+
else if (editor.selection && !slate.Range.isCollapsed(editor.selection)) {
|
|
952
|
+
insertLink(editor, linkUrl, linkTitle || undefined, linkTarget);
|
|
953
|
+
}
|
|
954
|
+
else {
|
|
955
|
+
slate.Transforms.insertNodes(editor, {
|
|
956
|
+
type: 'link',
|
|
957
|
+
url: linkUrl,
|
|
958
|
+
title: linkTitle || undefined,
|
|
959
|
+
target: linkTarget,
|
|
960
|
+
children: [{ text: linkUrl }],
|
|
961
|
+
});
|
|
962
|
+
slate.Transforms.move(editor);
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
setShowLinkModal(false);
|
|
966
|
+
setLinkText('');
|
|
967
|
+
setLinkUrl('');
|
|
968
|
+
setLinkTitle('');
|
|
969
|
+
setLinkTarget('_self');
|
|
970
|
+
setIsEditingLink(false);
|
|
971
|
+
};
|
|
972
|
+
var handleImageToggle = function (event) {
|
|
973
|
+
event.preventDefault();
|
|
974
|
+
setImageUrl('');
|
|
975
|
+
setImageAlt('');
|
|
976
|
+
setImageFile(null);
|
|
977
|
+
setImageUploadError('');
|
|
978
|
+
setIsReplacingImage(false);
|
|
979
|
+
setReplacingImagePath(null);
|
|
980
|
+
setShowImageModal(true);
|
|
981
|
+
};
|
|
982
|
+
var handleInsertImage = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
983
|
+
var editiumProps, uploadedUrl, error_1;
|
|
984
|
+
return __generator(this, function (_a) {
|
|
985
|
+
switch (_a.label) {
|
|
986
|
+
case 0:
|
|
987
|
+
setImageUploadError('');
|
|
988
|
+
if (!imageFile) return [3 /*break*/, 5];
|
|
989
|
+
editiumProps = window.__editiumProps;
|
|
990
|
+
if (!(editiumProps === null || editiumProps === void 0 ? void 0 : editiumProps.onImageUpload)) {
|
|
991
|
+
setImageUploadError('Upload not configured. Please define onImageUpload in your app.');
|
|
992
|
+
return [2 /*return*/];
|
|
993
|
+
}
|
|
994
|
+
_a.label = 1;
|
|
995
|
+
case 1:
|
|
996
|
+
_a.trys.push([1, 3, , 4]);
|
|
997
|
+
return [4 /*yield*/, editiumProps.onImageUpload(imageFile)];
|
|
998
|
+
case 2:
|
|
999
|
+
uploadedUrl = _a.sent();
|
|
1000
|
+
if (isReplacingImage && replacingImagePath) {
|
|
1001
|
+
slate.Transforms.setNodes(editor, {
|
|
1002
|
+
url: uploadedUrl,
|
|
1003
|
+
alt: imageAlt || imageFile.name
|
|
1004
|
+
}, { at: replacingImagePath });
|
|
1005
|
+
}
|
|
1006
|
+
else {
|
|
1007
|
+
insertImage(editor, uploadedUrl, imageAlt || imageFile.name);
|
|
1008
|
+
}
|
|
1009
|
+
setShowImageModal(false);
|
|
1010
|
+
setImageUrl('');
|
|
1011
|
+
setImageAlt('');
|
|
1012
|
+
setImageFile(null);
|
|
1013
|
+
setIsReplacingImage(false);
|
|
1014
|
+
setReplacingImagePath(null);
|
|
1015
|
+
return [3 /*break*/, 4];
|
|
1016
|
+
case 3:
|
|
1017
|
+
error_1 = _a.sent();
|
|
1018
|
+
setImageUploadError('Failed to upload image: ' + error_1.message);
|
|
1019
|
+
return [3 /*break*/, 4];
|
|
1020
|
+
case 4: return [2 /*return*/];
|
|
1021
|
+
case 5:
|
|
1022
|
+
if (!imageUrl.trim()) {
|
|
1023
|
+
setImageUploadError('Please enter an image URL or select a file');
|
|
1024
|
+
return [2 /*return*/];
|
|
1025
|
+
}
|
|
1026
|
+
if (!isValidImageUrl(imageUrl)) {
|
|
1027
|
+
setImageUploadError('Please enter a valid image URL');
|
|
1028
|
+
return [2 /*return*/];
|
|
1029
|
+
}
|
|
1030
|
+
if (isReplacingImage && replacingImagePath) {
|
|
1031
|
+
slate.Transforms.setNodes(editor, {
|
|
1032
|
+
url: imageUrl,
|
|
1033
|
+
alt: imageAlt || 'Image'
|
|
1034
|
+
}, { at: replacingImagePath });
|
|
1035
|
+
}
|
|
1036
|
+
else {
|
|
1037
|
+
insertImage(editor, imageUrl, imageAlt || 'Image');
|
|
1038
|
+
}
|
|
1039
|
+
setShowImageModal(false);
|
|
1040
|
+
setImageUrl('');
|
|
1041
|
+
setImageAlt('');
|
|
1042
|
+
setImageFile(null);
|
|
1043
|
+
setIsReplacingImage(false);
|
|
1044
|
+
setReplacingImagePath(null);
|
|
1045
|
+
return [2 /*return*/];
|
|
1046
|
+
}
|
|
1047
|
+
});
|
|
1048
|
+
}); };
|
|
1049
|
+
var handleFileChange = function (e) {
|
|
1050
|
+
var _a;
|
|
1051
|
+
var file = (_a = e.target.files) === null || _a === void 0 ? void 0 : _a[0];
|
|
1052
|
+
if (file) {
|
|
1053
|
+
if (!file.type.startsWith('image/')) {
|
|
1054
|
+
setImageUploadError('Please select an image file');
|
|
1055
|
+
return;
|
|
1056
|
+
}
|
|
1057
|
+
if (file.size > 5 * 1024 * 1024) {
|
|
1058
|
+
setImageUploadError('Image size should be less than 5MB');
|
|
1059
|
+
return;
|
|
1060
|
+
}
|
|
1061
|
+
setImageFile(file);
|
|
1062
|
+
setImageUploadError('');
|
|
1063
|
+
}
|
|
1064
|
+
};
|
|
1065
|
+
var handleTableToggle = function (event) {
|
|
1066
|
+
event.preventDefault();
|
|
1067
|
+
setShowTableModal(true);
|
|
1068
|
+
setTableRows(3);
|
|
1069
|
+
setTableCols(3);
|
|
1070
|
+
};
|
|
1071
|
+
var handleInsertTable = function () {
|
|
1072
|
+
insertTable(editor, tableRows, tableCols);
|
|
1073
|
+
setShowTableModal(false);
|
|
1074
|
+
};
|
|
1075
|
+
var handleFindReplaceToggle = function (event) {
|
|
1076
|
+
event.preventDefault();
|
|
1077
|
+
setShowFindReplace(!showFindReplace);
|
|
1078
|
+
if (!showFindReplace) {
|
|
1079
|
+
onSearchQueryChange === null || onSearchQueryChange === void 0 ? void 0 : onSearchQueryChange('');
|
|
1080
|
+
setReplaceText('');
|
|
1081
|
+
onCurrentMatchIndexChange === null || onCurrentMatchIndexChange === void 0 ? void 0 : onCurrentMatchIndexChange(0);
|
|
1082
|
+
onSearchMatchesChange === null || onSearchMatchesChange === void 0 ? void 0 : onSearchMatchesChange([]);
|
|
1083
|
+
setTotalMatches(0);
|
|
1084
|
+
}
|
|
1085
|
+
};
|
|
1086
|
+
React.useEffect(function () {
|
|
1087
|
+
if (!searchQuery || !showFindReplace) {
|
|
1088
|
+
onSearchMatchesChange === null || onSearchMatchesChange === void 0 ? void 0 : onSearchMatchesChange([]);
|
|
1089
|
+
setTotalMatches(0);
|
|
1090
|
+
onCurrentMatchIndexChange === null || onCurrentMatchIndexChange === void 0 ? void 0 : onCurrentMatchIndexChange(0);
|
|
1091
|
+
return;
|
|
1092
|
+
}
|
|
1093
|
+
var matches = findAllMatches(editor, searchQuery);
|
|
1094
|
+
onSearchMatchesChange === null || onSearchMatchesChange === void 0 ? void 0 : onSearchMatchesChange(matches);
|
|
1095
|
+
setTotalMatches(matches.length);
|
|
1096
|
+
if (matches.length > 0) {
|
|
1097
|
+
onCurrentMatchIndexChange === null || onCurrentMatchIndexChange === void 0 ? void 0 : onCurrentMatchIndexChange(0);
|
|
1098
|
+
navigateToMatch(editor, matches[0]);
|
|
1099
|
+
}
|
|
1100
|
+
else {
|
|
1101
|
+
onCurrentMatchIndexChange === null || onCurrentMatchIndexChange === void 0 ? void 0 : onCurrentMatchIndexChange(0);
|
|
1102
|
+
}
|
|
1103
|
+
}, [searchQuery, showFindReplace, editor, onSearchMatchesChange, onCurrentMatchIndexChange]);
|
|
1104
|
+
var handleNextMatch = function () {
|
|
1105
|
+
if (searchMatches.length === 0)
|
|
1106
|
+
return;
|
|
1107
|
+
var nextIndex = (currentMatchIndex + 1) % searchMatches.length;
|
|
1108
|
+
onCurrentMatchIndexChange === null || onCurrentMatchIndexChange === void 0 ? void 0 : onCurrentMatchIndexChange(nextIndex);
|
|
1109
|
+
navigateToMatch(editor, searchMatches[nextIndex]);
|
|
1110
|
+
};
|
|
1111
|
+
var handlePrevMatch = function () {
|
|
1112
|
+
if (searchMatches.length === 0)
|
|
1113
|
+
return;
|
|
1114
|
+
var prevIndex = currentMatchIndex === 0 ? searchMatches.length - 1 : currentMatchIndex - 1;
|
|
1115
|
+
onCurrentMatchIndexChange === null || onCurrentMatchIndexChange === void 0 ? void 0 : onCurrentMatchIndexChange(prevIndex);
|
|
1116
|
+
navigateToMatch(editor, searchMatches[prevIndex]);
|
|
1117
|
+
};
|
|
1118
|
+
var handleReplace = function () {
|
|
1119
|
+
if (searchMatches.length === 0 || currentMatchIndex >= searchMatches.length)
|
|
1120
|
+
return;
|
|
1121
|
+
replaceMatch(editor, searchMatches[currentMatchIndex], replaceText);
|
|
1122
|
+
var matches = findAllMatches(editor, searchQuery);
|
|
1123
|
+
onSearchMatchesChange === null || onSearchMatchesChange === void 0 ? void 0 : onSearchMatchesChange(matches);
|
|
1124
|
+
};
|
|
1125
|
+
var handleReplaceAll = function () {
|
|
1126
|
+
if (searchMatches.length === 0)
|
|
1127
|
+
return;
|
|
1128
|
+
replaceAllMatches(editor, searchMatches, replaceText);
|
|
1129
|
+
onSearchQueryChange === null || onSearchQueryChange === void 0 ? void 0 : onSearchQueryChange('');
|
|
1130
|
+
setTimeout(function () {
|
|
1131
|
+
onSearchQueryChange === null || onSearchQueryChange === void 0 ? void 0 : onSearchQueryChange('');
|
|
1132
|
+
setReplaceText('');
|
|
1133
|
+
onSearchMatchesChange === null || onSearchMatchesChange === void 0 ? void 0 : onSearchMatchesChange([]);
|
|
1134
|
+
setTotalMatches(0);
|
|
1135
|
+
onCurrentMatchIndexChange === null || onCurrentMatchIndexChange === void 0 ? void 0 : onCurrentMatchIndexChange(0);
|
|
1136
|
+
}, 50);
|
|
1137
|
+
};
|
|
1138
|
+
React.useEffect(function () {
|
|
1139
|
+
var handleExternalEdit = function (linkData) {
|
|
1140
|
+
setLinkText(linkData.text);
|
|
1141
|
+
setLinkUrl(linkData.url);
|
|
1142
|
+
setLinkTitle(linkData.title || '');
|
|
1143
|
+
setLinkTarget(linkData.target || '_self');
|
|
1144
|
+
setIsEditingLink(true);
|
|
1145
|
+
setShowLinkModal(true);
|
|
1146
|
+
if (linkData.path) {
|
|
1147
|
+
editor.selection = slate.Editor.range(editor, linkData.path);
|
|
1148
|
+
}
|
|
1149
|
+
};
|
|
1150
|
+
window.__editiumLinkEditHandler = handleExternalEdit;
|
|
1151
|
+
return function () {
|
|
1152
|
+
delete window.__editiumLinkEditHandler;
|
|
1153
|
+
};
|
|
1154
|
+
}, [editor]);
|
|
1155
|
+
React.useEffect(function () {
|
|
1156
|
+
var handleImageReplace = function (imageData) {
|
|
1157
|
+
setImageUrl(imageData.url);
|
|
1158
|
+
setImageAlt(imageData.alt || '');
|
|
1159
|
+
setImageFile(null);
|
|
1160
|
+
setImageUploadError('');
|
|
1161
|
+
setIsReplacingImage(true);
|
|
1162
|
+
setReplacingImagePath(imageData.path);
|
|
1163
|
+
setShowImageModal(true);
|
|
1164
|
+
};
|
|
1165
|
+
window.__editiumImageReplaceHandler = handleImageReplace;
|
|
1166
|
+
return function () {
|
|
1167
|
+
delete window.__editiumImageReplaceHandler;
|
|
1168
|
+
};
|
|
1169
|
+
}, []);
|
|
1170
|
+
var blockFormattingItems = ['paragraph', 'heading-one', 'heading-two', 'heading-three', 'heading-four', 'heading-five', 'heading-six', 'heading-seven', 'heading-eight'];
|
|
1171
|
+
var alignmentItems = ['left', 'center', 'right', 'justify'];
|
|
1172
|
+
var formatItems = ['bold', 'italic', 'underline', 'strikethrough', 'code', 'superscript', 'subscript'];
|
|
1173
|
+
var listItems = ['bulleted-list', 'numbered-list', 'indent', 'outdent'];
|
|
1174
|
+
var blockItems = ['blockquote', 'code-block'];
|
|
1175
|
+
var colorItems = ['text-color', 'bg-color'];
|
|
1176
|
+
var insertItems = ['link', 'horizontal-rule', 'image', 'table'];
|
|
1177
|
+
var editItems = ['undo', 'redo'];
|
|
1178
|
+
var colorPalette = [
|
|
1179
|
+
{ name: 'Black', value: '#000000' },
|
|
1180
|
+
{ name: 'Dark Gray', value: '#495057' },
|
|
1181
|
+
{ name: 'Gray', value: '#6c757d' },
|
|
1182
|
+
{ name: 'Light Gray', value: '#adb5bd' },
|
|
1183
|
+
{ name: 'Red', value: '#dc3545' },
|
|
1184
|
+
{ name: 'Orange', value: '#fd7e14' },
|
|
1185
|
+
{ name: 'Yellow', value: '#ffc107' },
|
|
1186
|
+
{ name: 'Green', value: '#28a745' },
|
|
1187
|
+
{ name: 'Teal', value: '#20c997' },
|
|
1188
|
+
{ name: 'Blue', value: '#007bff' },
|
|
1189
|
+
{ name: 'Indigo', value: '#6610f2' },
|
|
1190
|
+
{ name: 'Purple', value: '#6f42c1' },
|
|
1191
|
+
{ name: 'Pink', value: '#e83e8c' },
|
|
1192
|
+
{ name: 'White', value: '#ffffff' },
|
|
1193
|
+
];
|
|
1194
|
+
var renderToolbarItem = function (item, index) {
|
|
1195
|
+
if (item === 'separator') {
|
|
1196
|
+
var prevItem = index > 0 ? items[index - 1] : null;
|
|
1197
|
+
if (prevItem) {
|
|
1198
|
+
if (formatItems.includes(prevItem)) {
|
|
1199
|
+
var firstFormatIndex = items.findIndex(function (i) { return formatItems.includes(i); });
|
|
1200
|
+
if (firstFormatIndex !== index - 1)
|
|
1201
|
+
return null;
|
|
1202
|
+
}
|
|
1203
|
+
if (listItems.includes(prevItem)) {
|
|
1204
|
+
var firstListIndex = items.findIndex(function (i) { return listItems.includes(i); });
|
|
1205
|
+
if (firstListIndex !== index - 1)
|
|
1206
|
+
return null;
|
|
1207
|
+
}
|
|
1208
|
+
if (alignmentItems.includes(prevItem)) {
|
|
1209
|
+
var firstAlignIndex = items.findIndex(function (i) { return alignmentItems.includes(i); });
|
|
1210
|
+
if (firstAlignIndex !== index - 1)
|
|
1211
|
+
return null;
|
|
1212
|
+
}
|
|
1213
|
+
if (blockFormattingItems.includes(prevItem)) {
|
|
1214
|
+
var firstBlockIndex = items.findIndex(function (i) { return blockFormattingItems.includes(i); });
|
|
1215
|
+
if (firstBlockIndex !== index - 1)
|
|
1216
|
+
return null;
|
|
1217
|
+
}
|
|
1218
|
+
if (insertItems.includes(prevItem)) {
|
|
1219
|
+
var firstInsertIndex = items.findIndex(function (i) { return insertItems.includes(i); });
|
|
1220
|
+
if (firstInsertIndex !== index - 1)
|
|
1221
|
+
return null;
|
|
1222
|
+
}
|
|
1223
|
+
if (editItems.includes(prevItem)) {
|
|
1224
|
+
var firstEditIndex = items.findIndex(function (i) { return editItems.includes(i); });
|
|
1225
|
+
if (firstEditIndex !== index - 1)
|
|
1226
|
+
return null;
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
return jsxRuntime.jsx(ToolbarSeparator, {}, "separator-".concat(index));
|
|
1230
|
+
}
|
|
1231
|
+
if (blockFormattingItems.includes(item)) {
|
|
1232
|
+
var firstBlockIndex = items.findIndex(function (i) { return blockFormattingItems.includes(i); });
|
|
1233
|
+
var currentIndex = items.findIndex(function (i) { return i === item; });
|
|
1234
|
+
if (firstBlockIndex !== currentIndex) {
|
|
1235
|
+
return null; // Skip rendering individual block formatting buttons
|
|
1236
|
+
}
|
|
1237
|
+
var activeBlock = blockFormattingItems.find(function (block) {
|
|
1238
|
+
return items.includes(block) && isBlockActive(editor, block);
|
|
1239
|
+
});
|
|
1240
|
+
var getBlockLabel_1 = function (block) {
|
|
1241
|
+
switch (block) {
|
|
1242
|
+
case 'paragraph': return 'Paragraph';
|
|
1243
|
+
case 'heading-one': return 'Heading 1';
|
|
1244
|
+
case 'heading-two': return 'Heading 2';
|
|
1245
|
+
case 'heading-three': return 'Heading 3';
|
|
1246
|
+
case 'heading-four': return 'Heading 4';
|
|
1247
|
+
case 'heading-five': return 'Heading 5';
|
|
1248
|
+
case 'heading-six': return 'Heading 6';
|
|
1249
|
+
case 'heading-seven': return 'Heading 7';
|
|
1250
|
+
case 'heading-eight': return 'Heading 8';
|
|
1251
|
+
default: return 'Format';
|
|
1252
|
+
}
|
|
1253
|
+
};
|
|
1254
|
+
return (jsxRuntime.jsx(Dropdown, { trigger: jsxRuntime.jsx("span", { children: activeBlock ? getBlockLabel_1(activeBlock) : 'Paragraph' }), title: "Block format", children: items.filter(function (i) { return blockFormattingItems.includes(i); }).map(function (block) { return (jsxRuntime.jsx(DropdownItem, { active: isBlockActive(editor, block), onMouseDown: function (e) { return handleBlockToggle(e, block); }, children: getBlockLabel_1(block) }, block)); }) }, "block-formatting-dropdown"));
|
|
1255
|
+
}
|
|
1256
|
+
if (alignmentItems.includes(item)) {
|
|
1257
|
+
var firstAlignIndex = items.findIndex(function (i) { return alignmentItems.includes(i); });
|
|
1258
|
+
var currentIndex = items.findIndex(function (i) { return i === item; });
|
|
1259
|
+
if (firstAlignIndex !== currentIndex) {
|
|
1260
|
+
return null; // Skip rendering individual alignment buttons
|
|
1261
|
+
}
|
|
1262
|
+
alignmentItems.find(function (align) {
|
|
1263
|
+
return items.includes(align) && isAlignmentActive(editor, align);
|
|
1264
|
+
});
|
|
1265
|
+
var getAlignmentIcon_1 = function (align) {
|
|
1266
|
+
switch (align) {
|
|
1267
|
+
case 'left':
|
|
1268
|
+
return (jsxRuntime.jsxs("div", { style: { display: 'flex', flexDirection: 'column', gap: '1px', width: '16px', height: '16px' }, children: [jsxRuntime.jsx("div", { style: { width: '12px', height: '2px', backgroundColor: 'currentColor' } }), jsxRuntime.jsx("div", { style: { width: '8px', height: '2px', backgroundColor: 'currentColor' } }), jsxRuntime.jsx("div", { style: { width: '10px', height: '2px', backgroundColor: 'currentColor' } })] }));
|
|
1269
|
+
case 'center':
|
|
1270
|
+
return (jsxRuntime.jsxs("div", { style: { display: 'flex', flexDirection: 'column', gap: '1px', width: '16px', height: '16px', alignItems: 'center' }, children: [jsxRuntime.jsx("div", { style: { width: '10px', height: '2px', backgroundColor: 'currentColor' } }), jsxRuntime.jsx("div", { style: { width: '6px', height: '2px', backgroundColor: 'currentColor' } }), jsxRuntime.jsx("div", { style: { width: '8px', height: '2px', backgroundColor: 'currentColor' } })] }));
|
|
1271
|
+
case 'right':
|
|
1272
|
+
return (jsxRuntime.jsxs("div", { style: { display: 'flex', flexDirection: 'column', gap: '1px', width: '16px', height: '16px', alignItems: 'flex-end' }, children: [jsxRuntime.jsx("div", { style: { width: '12px', height: '2px', backgroundColor: 'currentColor' } }), jsxRuntime.jsx("div", { style: { width: '8px', height: '2px', backgroundColor: 'currentColor' } }), jsxRuntime.jsx("div", { style: { width: '10px', height: '2px', backgroundColor: 'currentColor' } })] }));
|
|
1273
|
+
case 'justify':
|
|
1274
|
+
return (jsxRuntime.jsxs("div", { style: { display: 'flex', flexDirection: 'column', gap: '1px', width: '16px', height: '16px' }, children: [jsxRuntime.jsx("div", { style: { width: '100%', height: '2px', backgroundColor: 'currentColor' } }), jsxRuntime.jsx("div", { style: { width: '100%', height: '2px', backgroundColor: 'currentColor' } }), jsxRuntime.jsx("div", { style: { width: '100%', height: '2px', backgroundColor: 'currentColor' } })] }));
|
|
1275
|
+
default:
|
|
1276
|
+
return (jsxRuntime.jsxs("div", { style: { display: 'flex', flexDirection: 'column', gap: '1px', width: '16px', height: '16px' }, children: [jsxRuntime.jsx("div", { style: { width: '12px', height: '2px', backgroundColor: 'currentColor' } }), jsxRuntime.jsx("div", { style: { width: '8px', height: '2px', backgroundColor: 'currentColor' } }), jsxRuntime.jsx("div", { style: { width: '10px', height: '2px', backgroundColor: 'currentColor' } })] }));
|
|
1277
|
+
}
|
|
1278
|
+
};
|
|
1279
|
+
var getAlignmentLabel_1 = function (align) {
|
|
1280
|
+
switch (align) {
|
|
1281
|
+
case 'left': return 'Align Left';
|
|
1282
|
+
case 'center': return 'Align Center';
|
|
1283
|
+
case 'right': return 'Align Right';
|
|
1284
|
+
case 'justify': return 'Justify';
|
|
1285
|
+
default: return 'Align';
|
|
1286
|
+
}
|
|
1287
|
+
};
|
|
1288
|
+
return (jsxRuntime.jsx(Dropdown, { trigger: jsxRuntime.jsx("span", { children: "Align" }), title: "Text alignment", children: items.filter(function (i) { return alignmentItems.includes(i); }).map(function (align) { return (jsxRuntime.jsx(DropdownItem, { active: isAlignmentActive(editor, align), onMouseDown: function (e) { return handleAlignmentToggle(e, align); }, icon: getAlignmentIcon_1(align), children: getAlignmentLabel_1(align) }, align)); }) }, "alignment-dropdown"));
|
|
1289
|
+
}
|
|
1290
|
+
switch (item) {
|
|
1291
|
+
case 'bold':
|
|
1292
|
+
case 'italic':
|
|
1293
|
+
case 'underline':
|
|
1294
|
+
case 'strikethrough':
|
|
1295
|
+
case 'code':
|
|
1296
|
+
case 'superscript':
|
|
1297
|
+
case 'subscript': {
|
|
1298
|
+
var formatItems_1 = ['bold', 'italic', 'underline', 'strikethrough', 'code', 'superscript', 'subscript'];
|
|
1299
|
+
var firstFormatIndex = items.findIndex(function (i) { return formatItems_1.includes(i); });
|
|
1300
|
+
var currentIndex = items.findIndex(function (i) { return i === item; });
|
|
1301
|
+
if (firstFormatIndex !== currentIndex)
|
|
1302
|
+
return null;
|
|
1303
|
+
return (jsxRuntime.jsxs(Dropdown, { trigger: jsxRuntime.jsx("span", { children: "Format" }), title: "Format", children: [items.includes('bold') && (jsxRuntime.jsx(DropdownItem, { active: isMarkActive(editor, 'bold'), onMouseDown: function (e) { return handleMarkToggle(e, 'bold'); }, icon: jsxRuntime.jsx("span", { style: { fontWeight: 'bold', fontSize: '16px' }, children: "B" }), children: "Bold" })), items.includes('italic') && (jsxRuntime.jsx(DropdownItem, { active: isMarkActive(editor, 'italic'), onMouseDown: function (e) { return handleMarkToggle(e, 'italic'); }, icon: jsxRuntime.jsx("span", { style: { fontStyle: 'italic', fontSize: '16px' }, children: "I" }), children: "Italic" })), items.includes('underline') && (jsxRuntime.jsx(DropdownItem, { active: isMarkActive(editor, 'underline'), onMouseDown: function (e) { return handleMarkToggle(e, 'underline'); }, icon: jsxRuntime.jsx("span", { style: { textDecoration: 'underline', fontSize: '16px' }, children: "U" }), children: "Underline" })), items.includes('strikethrough') && (jsxRuntime.jsx(DropdownItem, { active: isMarkActive(editor, 'strikethrough'), onMouseDown: function (e) { return handleMarkToggle(e, 'strikethrough'); }, icon: jsxRuntime.jsx("span", { style: { textDecoration: 'line-through', fontSize: '16px' }, children: "S" }), children: "Strikethrough" })), items.includes('code') && (jsxRuntime.jsx(DropdownItem, { active: isMarkActive(editor, 'code'), onMouseDown: function (e) { return handleMarkToggle(e, 'code'); }, icon: jsxRuntime.jsx(outline.CodeBracketIcon, { style: { width: '16px', height: '16px' } }), children: "Code" })), items.includes('superscript') && (jsxRuntime.jsx(DropdownItem, { active: isMarkActive(editor, 'superscript'), onMouseDown: function (e) { return handleMarkToggle(e, 'superscript'); }, icon: jsxRuntime.jsxs("span", { style: { fontSize: '12px' }, children: ["X", jsxRuntime.jsx("sup", { children: "2" })] }), children: "Superscript" })), items.includes('subscript') && (jsxRuntime.jsx(DropdownItem, { active: isMarkActive(editor, 'subscript'), onMouseDown: function (e) { return handleMarkToggle(e, 'subscript'); }, icon: jsxRuntime.jsxs("span", { style: { fontSize: '12px' }, children: ["X", jsxRuntime.jsx("sub", { children: "2" })] }), children: "Subscript" }))] }, "format-menu"));
|
|
1304
|
+
}
|
|
1305
|
+
case 'bulleted-list':
|
|
1306
|
+
case 'numbered-list':
|
|
1307
|
+
case 'indent':
|
|
1308
|
+
case 'outdent': {
|
|
1309
|
+
var listItems_1 = ['bulleted-list', 'numbered-list', 'indent', 'outdent'];
|
|
1310
|
+
var firstListIndex = items.findIndex(function (i) { return listItems_1.includes(i); });
|
|
1311
|
+
var currentIndex = items.findIndex(function (i) { return i === item; });
|
|
1312
|
+
if (firstListIndex !== currentIndex)
|
|
1313
|
+
return null;
|
|
1314
|
+
return (jsxRuntime.jsxs(Dropdown, { trigger: jsxRuntime.jsx("span", { children: "Lists" }), title: "Lists", children: [items.includes('bulleted-list') && (jsxRuntime.jsx(DropdownItem, { active: isBlockActive(editor, 'bulleted-list'), onMouseDown: function (e) { return handleBlockToggle(e, 'bulleted-list'); }, icon: jsxRuntime.jsx(outline.ListBulletIcon, { style: { width: '16px', height: '16px' } }), children: "Bullet list" })), items.includes('numbered-list') && (jsxRuntime.jsx(DropdownItem, { active: isBlockActive(editor, 'numbered-list'), onMouseDown: function (e) { return handleBlockToggle(e, 'numbered-list'); }, icon: jsxRuntime.jsx("span", { style: { fontSize: '14px', fontWeight: '600' }, children: "1." }), children: "Numbered list" })), items.includes('indent') && (jsxRuntime.jsx(DropdownItem, { active: false, onMouseDown: handleIndent, icon: jsxRuntime.jsx(outline.ArrowRightIcon, { style: { width: '16px', height: '16px' } }), children: "Increase indent" })), items.includes('outdent') && (jsxRuntime.jsx(DropdownItem, { active: false, onMouseDown: handleOutdent, icon: jsxRuntime.jsx(outline.ArrowLeftIcon, { style: { width: '16px', height: '16px' } }), children: "Decrease indent" }))] }, "lists-menu"));
|
|
1315
|
+
}
|
|
1316
|
+
case 'blockquote':
|
|
1317
|
+
case 'code-block': {
|
|
1318
|
+
var firstBlockItemIndex = items.findIndex(function (i) { return blockItems.includes(i); });
|
|
1319
|
+
var currentIndex = items.findIndex(function (i) { return i === item; });
|
|
1320
|
+
if (firstBlockItemIndex !== currentIndex)
|
|
1321
|
+
return null;
|
|
1322
|
+
return (jsxRuntime.jsxs(Dropdown, { trigger: jsxRuntime.jsx("span", { children: "Blocks" }), title: "Blocks", children: [items.includes('blockquote') && (jsxRuntime.jsx(DropdownItem, { active: isBlockActive(editor, 'blockquote'), onMouseDown: function (e) { return handleBlockToggle(e, 'blockquote'); }, icon: jsxRuntime.jsx("span", { style: { fontSize: '16px', fontWeight: 'bold' }, children: "\u275D" }), children: "Blockquote" })), items.includes('code-block') && (jsxRuntime.jsx(DropdownItem, { active: isBlockActive(editor, 'code-block'), onMouseDown: function (e) { return handleBlockToggle(e, 'code-block'); }, icon: jsxRuntime.jsx(outline.CodeBracketIcon, { style: { width: '16px', height: '16px' } }), children: "Code Block" }))] }, "blocks-menu"));
|
|
1323
|
+
}
|
|
1324
|
+
case 'text-color':
|
|
1325
|
+
case 'bg-color': {
|
|
1326
|
+
var firstColorIndex = items.findIndex(function (i) { return colorItems.includes(i); });
|
|
1327
|
+
var currentIndex = items.findIndex(function (i) { return i === item; });
|
|
1328
|
+
if (firstColorIndex !== currentIndex)
|
|
1329
|
+
return null;
|
|
1330
|
+
var activeTextColor_1 = getActiveColor(editor);
|
|
1331
|
+
var activeBgColor_1 = getActiveBackgroundColor(editor);
|
|
1332
|
+
return (jsxRuntime.jsxs(Dropdown, { trigger: jsxRuntime.jsx("span", { children: "Color" }), title: "Color", children: [items.includes('text-color') && (jsxRuntime.jsxs("div", { style: { padding: '8px 12px' }, children: [jsxRuntime.jsx("div", { style: {
|
|
1333
|
+
fontSize: '12px',
|
|
1334
|
+
fontWeight: '600',
|
|
1335
|
+
marginBottom: '8px',
|
|
1336
|
+
color: '#495057'
|
|
1337
|
+
}, children: "Text Color" }), jsxRuntime.jsx("div", { style: {
|
|
1338
|
+
display: 'grid',
|
|
1339
|
+
gridTemplateColumns: 'repeat(7, 1fr)',
|
|
1340
|
+
gap: '4px',
|
|
1341
|
+
marginBottom: '8px'
|
|
1342
|
+
}, children: colorPalette.map(function (color) { return (jsxRuntime.jsx("button", { onMouseDown: function (e) {
|
|
1343
|
+
e.preventDefault();
|
|
1344
|
+
applyColor(editor, color.value);
|
|
1345
|
+
}, title: color.name, style: {
|
|
1346
|
+
width: '24px',
|
|
1347
|
+
height: '24px',
|
|
1348
|
+
backgroundColor: color.value,
|
|
1349
|
+
border: activeTextColor_1 === color.value ? '2px solid #007bff' : '1px solid #dee2e6',
|
|
1350
|
+
borderRadius: '3px',
|
|
1351
|
+
cursor: 'pointer',
|
|
1352
|
+
padding: 0,
|
|
1353
|
+
boxShadow: color.value === '#ffffff' ? 'inset 0 0 0 1px #dee2e6' : 'none'
|
|
1354
|
+
} }, "text-".concat(color.value))); }) }), jsxRuntime.jsxs("div", { style: {
|
|
1355
|
+
display: 'flex',
|
|
1356
|
+
alignItems: 'center',
|
|
1357
|
+
gap: '6px',
|
|
1358
|
+
marginBottom: '8px',
|
|
1359
|
+
paddingTop: '4px'
|
|
1360
|
+
}, children: [jsxRuntime.jsx("input", { type: "color", value: activeTextColor_1 || '#000000', onChange: function (e) {
|
|
1361
|
+
applyColor(editor, e.target.value);
|
|
1362
|
+
}, title: "Pick custom color", style: {
|
|
1363
|
+
width: '24px',
|
|
1364
|
+
height: '24px',
|
|
1365
|
+
border: '1px solid #dee2e6',
|
|
1366
|
+
borderRadius: '3px',
|
|
1367
|
+
cursor: 'pointer',
|
|
1368
|
+
padding: '0',
|
|
1369
|
+
backgroundColor: 'transparent'
|
|
1370
|
+
} }), jsxRuntime.jsx("span", { style: {
|
|
1371
|
+
fontSize: '12px',
|
|
1372
|
+
color: '#6c757d'
|
|
1373
|
+
}, children: "Custom" })] }), jsxRuntime.jsx("button", { onMouseDown: function (e) {
|
|
1374
|
+
e.preventDefault();
|
|
1375
|
+
applyColor(editor, null);
|
|
1376
|
+
}, style: {
|
|
1377
|
+
width: '100%',
|
|
1378
|
+
padding: '4px 8px',
|
|
1379
|
+
fontSize: '12px',
|
|
1380
|
+
border: '1px solid #dee2e6',
|
|
1381
|
+
borderRadius: '3px',
|
|
1382
|
+
backgroundColor: 'transparent',
|
|
1383
|
+
cursor: 'pointer',
|
|
1384
|
+
color: '#495057'
|
|
1385
|
+
}, children: "Remove Color" })] })), items.includes('bg-color') && (jsxRuntime.jsxs("div", { style: { padding: '8px 12px', borderTop: '1px solid #dee2e6' }, children: [jsxRuntime.jsx("div", { style: {
|
|
1386
|
+
fontSize: '12px',
|
|
1387
|
+
fontWeight: '600',
|
|
1388
|
+
marginBottom: '8px',
|
|
1389
|
+
color: '#495057'
|
|
1390
|
+
}, children: "Background Highlight" }), jsxRuntime.jsx("div", { style: {
|
|
1391
|
+
display: 'grid',
|
|
1392
|
+
gridTemplateColumns: 'repeat(7, 1fr)',
|
|
1393
|
+
gap: '4px',
|
|
1394
|
+
marginBottom: '8px'
|
|
1395
|
+
}, children: colorPalette.map(function (color) { return (jsxRuntime.jsx("button", { onMouseDown: function (e) {
|
|
1396
|
+
e.preventDefault();
|
|
1397
|
+
applyBackgroundColor(editor, color.value);
|
|
1398
|
+
}, title: color.name, style: {
|
|
1399
|
+
width: '24px',
|
|
1400
|
+
height: '24px',
|
|
1401
|
+
backgroundColor: color.value,
|
|
1402
|
+
border: activeBgColor_1 === color.value ? '2px solid #007bff' : '1px solid #dee2e6',
|
|
1403
|
+
borderRadius: '3px',
|
|
1404
|
+
cursor: 'pointer',
|
|
1405
|
+
padding: 0,
|
|
1406
|
+
boxShadow: color.value === '#ffffff' ? 'inset 0 0 0 1px #dee2e6' : 'none'
|
|
1407
|
+
} }, "bg-".concat(color.value))); }) }), jsxRuntime.jsxs("div", { style: {
|
|
1408
|
+
display: 'flex',
|
|
1409
|
+
alignItems: 'center',
|
|
1410
|
+
gap: '6px',
|
|
1411
|
+
marginBottom: '8px',
|
|
1412
|
+
paddingTop: '4px'
|
|
1413
|
+
}, children: [jsxRuntime.jsx("input", { type: "color", value: activeBgColor_1 || '#ffffff', onChange: function (e) {
|
|
1414
|
+
applyBackgroundColor(editor, e.target.value);
|
|
1415
|
+
}, title: "Pick custom color", style: {
|
|
1416
|
+
width: '24px',
|
|
1417
|
+
height: '24px',
|
|
1418
|
+
border: '1px solid #dee2e6',
|
|
1419
|
+
borderRadius: '3px',
|
|
1420
|
+
cursor: 'pointer',
|
|
1421
|
+
padding: '0',
|
|
1422
|
+
backgroundColor: 'transparent'
|
|
1423
|
+
} }), jsxRuntime.jsx("span", { style: {
|
|
1424
|
+
fontSize: '12px',
|
|
1425
|
+
color: '#6c757d'
|
|
1426
|
+
}, children: "Custom" })] }), jsxRuntime.jsx("button", { onMouseDown: function (e) {
|
|
1427
|
+
e.preventDefault();
|
|
1428
|
+
applyBackgroundColor(editor, null);
|
|
1429
|
+
}, style: {
|
|
1430
|
+
width: '100%',
|
|
1431
|
+
padding: '4px 8px',
|
|
1432
|
+
fontSize: '12px',
|
|
1433
|
+
border: '1px solid #dee2e6',
|
|
1434
|
+
borderRadius: '3px',
|
|
1435
|
+
backgroundColor: 'transparent',
|
|
1436
|
+
cursor: 'pointer',
|
|
1437
|
+
color: '#495057'
|
|
1438
|
+
}, children: "Remove Highlight" })] }))] }, "color-menu"));
|
|
1439
|
+
}
|
|
1440
|
+
case 'link':
|
|
1441
|
+
case 'horizontal-rule':
|
|
1442
|
+
case 'image':
|
|
1443
|
+
case 'table': {
|
|
1444
|
+
var firstInsertIndex = items.findIndex(function (i) { return insertItems.includes(i); });
|
|
1445
|
+
var currentIndex = items.findIndex(function (i) { return i === item; });
|
|
1446
|
+
if (firstInsertIndex !== currentIndex)
|
|
1447
|
+
return null;
|
|
1448
|
+
return (jsxRuntime.jsxs(Dropdown, { trigger: jsxRuntime.jsx("span", { children: "Insert" }), title: "Insert", children: [items.includes('link') && (jsxRuntime.jsx(DropdownItem, { active: isLinkActive(editor), onMouseDown: handleLinkToggle, icon: jsxRuntime.jsx(outline.LinkIcon, { style: { width: '16px', height: '16px' } }), children: "Link" })), items.includes('image') && (jsxRuntime.jsx(DropdownItem, { active: false, onMouseDown: handleImageToggle, icon: jsxRuntime.jsx(outline.PhotoIcon, { style: { width: '16px', height: '16px' } }), children: "Image" })), items.includes('table') && (jsxRuntime.jsx(DropdownItem, { active: false, onMouseDown: handleTableToggle, icon: jsxRuntime.jsx(outline.TableCellsIcon, { style: { width: '16px', height: '16px' } }), children: "Table" })), items.includes('horizontal-rule') && (jsxRuntime.jsx(DropdownItem, { active: false, onMouseDown: function (e) {
|
|
1449
|
+
e.preventDefault();
|
|
1450
|
+
insertHorizontalRule(editor);
|
|
1451
|
+
}, icon: jsxRuntime.jsx("span", { style: { fontSize: '16px', fontWeight: 'bold' }, children: "\u2015" }), children: "Horizontal Rule" }))] }, "insert-menu"));
|
|
1452
|
+
}
|
|
1453
|
+
case 'undo':
|
|
1454
|
+
case 'redo': {
|
|
1455
|
+
var firstEditIndex = items.findIndex(function (i) { return editItems.includes(i); });
|
|
1456
|
+
var currentIndex = items.findIndex(function (i) { return i === item; });
|
|
1457
|
+
if (firstEditIndex !== currentIndex)
|
|
1458
|
+
return null;
|
|
1459
|
+
return (jsxRuntime.jsxs(Dropdown, { trigger: jsxRuntime.jsx("span", { children: "Edit" }), title: "Edit", children: [items.includes('undo') && (jsxRuntime.jsx(DropdownItem, { active: false, onMouseDown: handleUndo, icon: jsxRuntime.jsx(outline.ArrowUturnLeftIcon, { style: { width: '16px', height: '16px' } }), children: "Undo" })), items.includes('redo') && (jsxRuntime.jsx(DropdownItem, { active: false, onMouseDown: handleRedo, icon: jsxRuntime.jsx(outline.ArrowUturnRightIcon, { style: { width: '16px', height: '16px' } }), children: "Redo" }))] }, "edit-menu"));
|
|
1460
|
+
}
|
|
1461
|
+
case 'view-output':
|
|
1462
|
+
return (jsxRuntime.jsxs(Dropdown, { trigger: jsxRuntime.jsx("span", { children: "View" }), title: "View Output", children: [jsxRuntime.jsx(DropdownItem, { active: false, onMouseDown: function (event) {
|
|
1463
|
+
event.preventDefault();
|
|
1464
|
+
if (onViewOutput) {
|
|
1465
|
+
onViewOutput('preview');
|
|
1466
|
+
}
|
|
1467
|
+
}, icon: jsxRuntime.jsx(outline.ArrowTopRightOnSquareIcon, { style: { width: '16px', height: '16px' } }), children: "Preview" }), jsxRuntime.jsx(DropdownItem, { active: false, onMouseDown: function (event) {
|
|
1468
|
+
event.preventDefault();
|
|
1469
|
+
if (onViewOutput) {
|
|
1470
|
+
onViewOutput('html');
|
|
1471
|
+
}
|
|
1472
|
+
}, icon: jsxRuntime.jsx("span", { style: { fontFamily: 'monospace', fontSize: '14px' }, children: "</>" }), children: "View HTML" }), jsxRuntime.jsx(DropdownItem, { active: false, onMouseDown: function (event) {
|
|
1473
|
+
event.preventDefault();
|
|
1474
|
+
if (onViewOutput) {
|
|
1475
|
+
onViewOutput('json');
|
|
1476
|
+
}
|
|
1477
|
+
}, icon: jsxRuntime.jsx("span", { style: { fontFamily: 'monospace', fontSize: '14px' } }), children: "View JSON" })] }, item));
|
|
1478
|
+
case 'find-replace':
|
|
1479
|
+
return (jsxRuntime.jsx(ToolbarButton, { active: showFindReplace, onMouseDown: handleFindReplaceToggle, title: "Find & Replace", children: jsxRuntime.jsx(outline.MagnifyingGlassIcon, { style: { width: '18px', height: '18px' } }) }, item));
|
|
1480
|
+
case 'fullscreen':
|
|
1481
|
+
return (jsxRuntime.jsx(ToolbarButton, { active: isFullscreen, onMouseDown: function (e) {
|
|
1482
|
+
e.preventDefault();
|
|
1483
|
+
onFullscreenToggle === null || onFullscreenToggle === void 0 ? void 0 : onFullscreenToggle();
|
|
1484
|
+
}, title: isFullscreen ? "Exit Fullscreen (Esc)" : "Enter Fullscreen (F11)", children: isFullscreen ? (jsxRuntime.jsx(outline.ArrowsPointingInIcon, { style: { width: '18px', height: '18px' } })) : (jsxRuntime.jsx(outline.ArrowsPointingOutIcon, { style: { width: '18px', height: '18px' } })) }, item));
|
|
1485
|
+
default:
|
|
1486
|
+
return null;
|
|
1487
|
+
}
|
|
1488
|
+
};
|
|
1489
|
+
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [showLinkModal && (jsxRuntime.jsx("div", { style: {
|
|
1490
|
+
position: 'fixed',
|
|
1491
|
+
top: 0,
|
|
1492
|
+
left: 0,
|
|
1493
|
+
right: 0,
|
|
1494
|
+
bottom: 0,
|
|
1495
|
+
backgroundColor: 'rgba(0, 0, 0, 0.5)',
|
|
1496
|
+
display: 'flex',
|
|
1497
|
+
alignItems: 'center',
|
|
1498
|
+
justifyContent: 'center',
|
|
1499
|
+
zIndex: 10000,
|
|
1500
|
+
}, onClick: function () {
|
|
1501
|
+
setShowLinkModal(false);
|
|
1502
|
+
setLinkText('');
|
|
1503
|
+
setLinkUrl('');
|
|
1504
|
+
setLinkTitle('');
|
|
1505
|
+
setLinkTarget('_self');
|
|
1506
|
+
setIsEditingLink(false);
|
|
1507
|
+
}, children: jsxRuntime.jsxs("div", { style: {
|
|
1508
|
+
backgroundColor: '#ffffff',
|
|
1509
|
+
borderRadius: '8px',
|
|
1510
|
+
padding: '24px',
|
|
1511
|
+
width: '90%',
|
|
1512
|
+
maxWidth: '500px',
|
|
1513
|
+
boxShadow: '0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04)',
|
|
1514
|
+
}, onClick: function (e) { return e.stopPropagation(); }, children: [jsxRuntime.jsx("h3", { style: { margin: '0 0 20px 0', color: '#111827', fontSize: '20px', fontWeight: '600' }, children: isEditingLink ? 'Edit Link' : 'Insert Link' }), jsxRuntime.jsxs("div", { style: { marginBottom: '16px' }, children: [jsxRuntime.jsx("label", { style: { display: 'block', marginBottom: '8px', color: '#374151', fontSize: '14px', fontWeight: '500' }, children: "Text to display" }), jsxRuntime.jsx("input", { type: "text", value: linkText, onChange: function (e) { return setLinkText(e.target.value); }, placeholder: "Enter link text", style: {
|
|
1515
|
+
width: '100%',
|
|
1516
|
+
padding: '8px 12px',
|
|
1517
|
+
border: '1px solid #d1d5db',
|
|
1518
|
+
borderRadius: '6px',
|
|
1519
|
+
fontSize: '14px',
|
|
1520
|
+
outline: 'none',
|
|
1521
|
+
boxSizing: 'border-box',
|
|
1522
|
+
}, onFocus: function (e) { return e.target.style.borderColor = '#3b82f6'; }, onBlur: function (e) { return e.target.style.borderColor = '#d1d5db'; } }), jsxRuntime.jsx("small", { style: { display: 'block', marginTop: '4px', color: '#6b7280', fontSize: '12px' }, children: "If empty, will use URL or selected text as display text" })] }), jsxRuntime.jsxs("div", { style: { marginBottom: '16px' }, children: [jsxRuntime.jsxs("label", { style: { display: 'block', marginBottom: '8px', color: '#374151', fontSize: '14px', fontWeight: '500' }, children: ["URL ", jsxRuntime.jsx("span", { style: { color: '#ef4444' }, children: "*" })] }), jsxRuntime.jsx("input", { type: "url", value: linkUrl, onChange: function (e) { return setLinkUrl(e.target.value); }, placeholder: "https://example.com", style: {
|
|
1523
|
+
width: '100%',
|
|
1524
|
+
padding: '8px 12px',
|
|
1525
|
+
border: '1px solid #d1d5db',
|
|
1526
|
+
borderRadius: '6px',
|
|
1527
|
+
fontSize: '14px',
|
|
1528
|
+
outline: 'none',
|
|
1529
|
+
boxSizing: 'border-box',
|
|
1530
|
+
}, onFocus: function (e) { return e.target.style.borderColor = '#3b82f6'; }, onBlur: function (e) { return e.target.style.borderColor = '#d1d5db'; }, onKeyDown: function (e) {
|
|
1531
|
+
if (e.key === 'Enter') {
|
|
1532
|
+
e.preventDefault();
|
|
1533
|
+
handleInsertLink();
|
|
1534
|
+
}
|
|
1535
|
+
} })] }), jsxRuntime.jsxs("div", { style: { marginBottom: '16px' }, children: [jsxRuntime.jsx("label", { style: { display: 'block', marginBottom: '8px', color: '#374151', fontSize: '14px', fontWeight: '500' }, children: "Title" }), jsxRuntime.jsx("input", { type: "text", value: linkTitle, onChange: function (e) { return setLinkTitle(e.target.value); }, placeholder: "Link title (tooltip)", style: {
|
|
1536
|
+
width: '100%',
|
|
1537
|
+
padding: '8px 12px',
|
|
1538
|
+
border: '1px solid #d1d5db',
|
|
1539
|
+
borderRadius: '6px',
|
|
1540
|
+
fontSize: '14px',
|
|
1541
|
+
outline: 'none',
|
|
1542
|
+
boxSizing: 'border-box',
|
|
1543
|
+
}, onFocus: function (e) { return e.target.style.borderColor = '#3b82f6'; }, onBlur: function (e) { return e.target.style.borderColor = '#d1d5db'; } }), jsxRuntime.jsx("small", { style: { display: 'block', marginTop: '4px', color: '#6b7280', fontSize: '12px' }, children: "Appears as a tooltip when hovering over the link" })] }), jsxRuntime.jsxs("div", { style: { marginBottom: '24px' }, children: [jsxRuntime.jsx("label", { style: { display: 'block', marginBottom: '8px', color: '#374151', fontSize: '14px', fontWeight: '500' }, children: "Open link in" }), jsxRuntime.jsxs("div", { style: { display: 'flex', gap: '12px' }, children: [jsxRuntime.jsxs("label", { style: { display: 'flex', alignItems: 'center', cursor: 'pointer' }, children: [jsxRuntime.jsx("input", { type: "radio", name: "linkTarget", value: "_self", checked: linkTarget === '_self', onChange: function (e) { return setLinkTarget(e.target.value); }, style: { marginRight: '6px', cursor: 'pointer' } }), jsxRuntime.jsx("span", { style: { fontSize: '14px', color: '#374151' }, children: "Current tab" })] }), jsxRuntime.jsxs("label", { style: { display: 'flex', alignItems: 'center', cursor: 'pointer' }, children: [jsxRuntime.jsx("input", { type: "radio", name: "linkTarget", value: "_blank", checked: linkTarget === '_blank', onChange: function (e) { return setLinkTarget(e.target.value); }, style: { marginRight: '6px', cursor: 'pointer' } }), jsxRuntime.jsx("span", { style: { fontSize: '14px', color: '#374151' }, children: "New tab" })] })] })] }), jsxRuntime.jsxs("div", { style: { display: 'flex', gap: '12px', justifyContent: 'flex-end' }, children: [jsxRuntime.jsx("button", { onClick: function () {
|
|
1544
|
+
setShowLinkModal(false);
|
|
1545
|
+
setLinkText('');
|
|
1546
|
+
setLinkUrl('');
|
|
1547
|
+
setLinkTitle('');
|
|
1548
|
+
setLinkTarget('_self');
|
|
1549
|
+
setIsEditingLink(false);
|
|
1550
|
+
}, style: {
|
|
1551
|
+
padding: '8px 16px',
|
|
1552
|
+
border: '1px solid #d1d5db',
|
|
1553
|
+
borderRadius: '6px',
|
|
1554
|
+
backgroundColor: '#ffffff',
|
|
1555
|
+
color: '#374151',
|
|
1556
|
+
fontSize: '14px',
|
|
1557
|
+
fontWeight: '500',
|
|
1558
|
+
cursor: 'pointer',
|
|
1559
|
+
transition: 'all 0.15s ease',
|
|
1560
|
+
}, onMouseEnter: function (e) { return e.currentTarget.style.backgroundColor = '#f9fafb'; }, onMouseLeave: function (e) { return e.currentTarget.style.backgroundColor = '#ffffff'; }, children: "Cancel" }), jsxRuntime.jsx("button", { onClick: handleInsertLink, style: {
|
|
1561
|
+
padding: '8px 16px',
|
|
1562
|
+
border: 'none',
|
|
1563
|
+
borderRadius: '6px',
|
|
1564
|
+
backgroundColor: '#3b82f6',
|
|
1565
|
+
color: '#ffffff',
|
|
1566
|
+
fontSize: '14px',
|
|
1567
|
+
fontWeight: '500',
|
|
1568
|
+
cursor: 'pointer',
|
|
1569
|
+
transition: 'all 0.15s ease',
|
|
1570
|
+
}, onMouseEnter: function (e) { return e.currentTarget.style.backgroundColor = '#2563eb'; }, onMouseLeave: function (e) { return e.currentTarget.style.backgroundColor = '#3b82f6'; }, children: isEditingLink ? 'Update Link' : 'Insert Link' })] })] }) })), showImageModal && (jsxRuntime.jsx("div", { style: {
|
|
1571
|
+
position: 'fixed',
|
|
1572
|
+
top: 0,
|
|
1573
|
+
left: 0,
|
|
1574
|
+
right: 0,
|
|
1575
|
+
bottom: 0,
|
|
1576
|
+
backgroundColor: 'rgba(0, 0, 0, 0.5)',
|
|
1577
|
+
display: 'flex',
|
|
1578
|
+
alignItems: 'center',
|
|
1579
|
+
justifyContent: 'center',
|
|
1580
|
+
zIndex: 10000,
|
|
1581
|
+
}, onClick: function () {
|
|
1582
|
+
setShowImageModal(false);
|
|
1583
|
+
setImageUrl('');
|
|
1584
|
+
setImageAlt('');
|
|
1585
|
+
setImageFile(null);
|
|
1586
|
+
setImageUploadError('');
|
|
1587
|
+
}, children: jsxRuntime.jsxs("div", { style: {
|
|
1588
|
+
backgroundColor: '#ffffff',
|
|
1589
|
+
borderRadius: '8px',
|
|
1590
|
+
padding: '24px',
|
|
1591
|
+
width: '90%',
|
|
1592
|
+
maxWidth: '500px',
|
|
1593
|
+
boxShadow: '0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04)',
|
|
1594
|
+
}, onClick: function (e) { return e.stopPropagation(); }, children: [jsxRuntime.jsx("h3", { style: { margin: '0 0 20px 0', color: '#111827', fontSize: '20px', fontWeight: '600' }, children: isReplacingImage ? 'Replace Image' : 'Insert Image' }), jsxRuntime.jsxs("div", { style: { marginBottom: '16px' }, children: [jsxRuntime.jsx("label", { style: { display: 'block', marginBottom: '8px', color: '#374151', fontSize: '14px', fontWeight: '500' }, children: "Image URL" }), jsxRuntime.jsx("input", { type: "url", value: imageUrl, onChange: function (e) { return setImageUrl(e.target.value); }, placeholder: "https://example.com/image.jpg", disabled: !!imageFile, style: {
|
|
1595
|
+
width: '100%',
|
|
1596
|
+
padding: '8px 12px',
|
|
1597
|
+
border: '1px solid #d1d5db',
|
|
1598
|
+
borderRadius: '6px',
|
|
1599
|
+
fontSize: '14px',
|
|
1600
|
+
outline: 'none',
|
|
1601
|
+
boxSizing: 'border-box',
|
|
1602
|
+
backgroundColor: imageFile ? '#f9fafb' : '#ffffff',
|
|
1603
|
+
}, onFocus: function (e) { return !imageFile && (e.target.style.borderColor = '#3b82f6'); }, onBlur: function (e) { return e.target.style.borderColor = '#d1d5db'; } })] }), jsxRuntime.jsxs("div", { style: {
|
|
1604
|
+
marginBottom: '16px',
|
|
1605
|
+
padding: '12px',
|
|
1606
|
+
backgroundColor: '#f9fafb',
|
|
1607
|
+
borderRadius: '6px',
|
|
1608
|
+
textAlign: 'center'
|
|
1609
|
+
}, children: [jsxRuntime.jsx("p", { style: { margin: '0 0 12px 0', color: '#6b7280', fontSize: '14px' }, children: "Or upload from your computer" }), jsxRuntime.jsx("input", { type: "file", accept: "image/*", onChange: handleFileChange, style: { display: 'none' }, id: "image-upload" }), jsxRuntime.jsx("label", { htmlFor: "image-upload", style: {
|
|
1610
|
+
display: 'inline-block',
|
|
1611
|
+
padding: '8px 16px',
|
|
1612
|
+
border: '1px solid #d1d5db',
|
|
1613
|
+
borderRadius: '6px',
|
|
1614
|
+
backgroundColor: '#ffffff',
|
|
1615
|
+
color: '#374151',
|
|
1616
|
+
fontSize: '14px',
|
|
1617
|
+
fontWeight: '500',
|
|
1618
|
+
cursor: 'pointer',
|
|
1619
|
+
transition: 'all 0.15s ease',
|
|
1620
|
+
}, onMouseEnter: function (e) { return e.currentTarget.style.backgroundColor = '#f9fafb'; }, onMouseLeave: function (e) { return e.currentTarget.style.backgroundColor = '#ffffff'; }, children: "Choose File" }), imageFile && (jsxRuntime.jsxs("p", { style: { margin: '8px 0 0 0', color: '#374151', fontSize: '13px' }, children: ["Selected: ", imageFile.name] })), !((_b = window.__editiumProps) === null || _b === void 0 ? void 0 : _b.onImageUpload) && (jsxRuntime.jsx("p", { style: {
|
|
1621
|
+
margin: '8px 0 0 0',
|
|
1622
|
+
color: '#dc2626',
|
|
1623
|
+
fontSize: '12px',
|
|
1624
|
+
fontStyle: 'italic'
|
|
1625
|
+
}, children: "\u26A0 Upload not configured. Define onImageUpload in your app." }))] }), jsxRuntime.jsxs("div", { style: { marginBottom: '16px' }, children: [jsxRuntime.jsx("label", { style: { display: 'block', marginBottom: '8px', color: '#374151', fontSize: '14px', fontWeight: '500' }, children: "Alt Text (optional)" }), jsxRuntime.jsx("input", { type: "text", value: imageAlt, onChange: function (e) { return setImageAlt(e.target.value); }, placeholder: "Describe the image", style: {
|
|
1626
|
+
width: '100%',
|
|
1627
|
+
padding: '8px 12px',
|
|
1628
|
+
border: '1px solid #d1d5db',
|
|
1629
|
+
borderRadius: '6px',
|
|
1630
|
+
fontSize: '14px',
|
|
1631
|
+
outline: 'none',
|
|
1632
|
+
boxSizing: 'border-box',
|
|
1633
|
+
}, onFocus: function (e) { return e.target.style.borderColor = '#3b82f6'; }, onBlur: function (e) { return e.target.style.borderColor = '#d1d5db'; } }), jsxRuntime.jsx("small", { style: { display: 'block', marginTop: '4px', color: '#6b7280', fontSize: '12px' }, children: "For accessibility" })] }), imageUploadError && (jsxRuntime.jsx("div", { style: {
|
|
1634
|
+
marginBottom: '16px',
|
|
1635
|
+
padding: '12px',
|
|
1636
|
+
backgroundColor: '#fef2f2',
|
|
1637
|
+
border: '1px solid #fecaca',
|
|
1638
|
+
borderRadius: '6px',
|
|
1639
|
+
color: '#dc2626',
|
|
1640
|
+
fontSize: '14px'
|
|
1641
|
+
}, children: imageUploadError })), jsxRuntime.jsxs("div", { style: { display: 'flex', gap: '12px', justifyContent: 'flex-end' }, children: [jsxRuntime.jsx("button", { onClick: function () {
|
|
1642
|
+
setShowImageModal(false);
|
|
1643
|
+
setImageUrl('');
|
|
1644
|
+
setImageAlt('');
|
|
1645
|
+
setImageFile(null);
|
|
1646
|
+
setImageUploadError('');
|
|
1647
|
+
}, style: {
|
|
1648
|
+
padding: '8px 16px',
|
|
1649
|
+
border: '1px solid #d1d5db',
|
|
1650
|
+
borderRadius: '6px',
|
|
1651
|
+
backgroundColor: '#ffffff',
|
|
1652
|
+
color: '#374151',
|
|
1653
|
+
fontSize: '14px',
|
|
1654
|
+
fontWeight: '500',
|
|
1655
|
+
cursor: 'pointer',
|
|
1656
|
+
transition: 'all 0.15s ease',
|
|
1657
|
+
}, onMouseEnter: function (e) { return e.currentTarget.style.backgroundColor = '#f9fafb'; }, onMouseLeave: function (e) { return e.currentTarget.style.backgroundColor = '#ffffff'; }, children: "Cancel" }), jsxRuntime.jsx("button", { onClick: handleInsertImage, style: {
|
|
1658
|
+
padding: '8px 16px',
|
|
1659
|
+
border: 'none',
|
|
1660
|
+
borderRadius: '6px',
|
|
1661
|
+
backgroundColor: '#3b82f6',
|
|
1662
|
+
color: '#ffffff',
|
|
1663
|
+
fontSize: '14px',
|
|
1664
|
+
fontWeight: '500',
|
|
1665
|
+
cursor: 'pointer',
|
|
1666
|
+
transition: 'all 0.15s ease',
|
|
1667
|
+
}, onMouseEnter: function (e) { return e.currentTarget.style.backgroundColor = '#2563eb'; }, onMouseLeave: function (e) { return e.currentTarget.style.backgroundColor = '#3b82f6'; }, children: isReplacingImage ? 'Replace' : 'Insert Image' })] })] }) })), showTableModal && (jsxRuntime.jsx("div", { style: {
|
|
1668
|
+
position: 'fixed',
|
|
1669
|
+
top: 0,
|
|
1670
|
+
left: 0,
|
|
1671
|
+
right: 0,
|
|
1672
|
+
bottom: 0,
|
|
1673
|
+
backgroundColor: 'rgba(0, 0, 0, 0.5)',
|
|
1674
|
+
display: 'flex',
|
|
1675
|
+
alignItems: 'center',
|
|
1676
|
+
justifyContent: 'center',
|
|
1677
|
+
zIndex: 1000,
|
|
1678
|
+
}, children: jsxRuntime.jsxs("div", { style: {
|
|
1679
|
+
backgroundColor: 'white',
|
|
1680
|
+
borderRadius: '8px',
|
|
1681
|
+
padding: '24px',
|
|
1682
|
+
maxWidth: '400px',
|
|
1683
|
+
width: '90%',
|
|
1684
|
+
boxShadow: '0 4px 20px rgba(0, 0, 0, 0.15)',
|
|
1685
|
+
}, children: [jsxRuntime.jsx("h3", { style: { margin: '0 0 16px 0', fontSize: '18px', fontWeight: '600', color: '#1f2937' }, children: "Insert Table" }), jsxRuntime.jsxs("div", { style: { marginBottom: '16px' }, children: [jsxRuntime.jsx("div", { style: {
|
|
1686
|
+
display: 'grid',
|
|
1687
|
+
gridTemplateColumns: 'repeat(10, 30px)',
|
|
1688
|
+
gridTemplateRows: 'repeat(10, 30px)',
|
|
1689
|
+
gap: '2px',
|
|
1690
|
+
padding: '8px',
|
|
1691
|
+
backgroundColor: '#f9fafb',
|
|
1692
|
+
borderRadius: '4px',
|
|
1693
|
+
width: 'fit-content',
|
|
1694
|
+
}, children: Array.from({ length: 100 }, function (_, index) {
|
|
1695
|
+
var row = Math.floor(index / 10) + 1;
|
|
1696
|
+
var col = (index % 10) + 1;
|
|
1697
|
+
var isHighlighted = row <= tableRows && col <= tableCols;
|
|
1698
|
+
return (jsxRuntime.jsx("div", { onMouseEnter: function () {
|
|
1699
|
+
setTableRows(row);
|
|
1700
|
+
setTableCols(col);
|
|
1701
|
+
}, onClick: handleInsertTable, style: {
|
|
1702
|
+
width: '30px',
|
|
1703
|
+
height: '30px',
|
|
1704
|
+
border: '1px solid #d1d5db',
|
|
1705
|
+
backgroundColor: isHighlighted ? '#3b82f6' : 'white',
|
|
1706
|
+
cursor: 'pointer',
|
|
1707
|
+
transition: 'background-color 0.1s ease',
|
|
1708
|
+
borderRadius: '2px',
|
|
1709
|
+
} }, index));
|
|
1710
|
+
}) }), jsxRuntime.jsxs("div", { style: {
|
|
1711
|
+
marginTop: '12px',
|
|
1712
|
+
textAlign: 'center',
|
|
1713
|
+
fontSize: '14px',
|
|
1714
|
+
fontWeight: '500',
|
|
1715
|
+
color: '#374151',
|
|
1716
|
+
}, children: [tableRows, " \u00D7 ", tableCols, " Table"] })] }), jsxRuntime.jsxs("div", { style: { display: 'flex', gap: '8px', justifyContent: 'flex-end' }, children: [jsxRuntime.jsx("button", { onClick: function () { return setShowTableModal(false); }, style: {
|
|
1717
|
+
padding: '8px 16px',
|
|
1718
|
+
border: '1px solid #d1d5db',
|
|
1719
|
+
borderRadius: '4px',
|
|
1720
|
+
backgroundColor: 'white',
|
|
1721
|
+
color: '#374151',
|
|
1722
|
+
cursor: 'pointer',
|
|
1723
|
+
fontSize: '14px',
|
|
1724
|
+
fontWeight: '500',
|
|
1725
|
+
}, onMouseEnter: function (e) { return e.currentTarget.style.backgroundColor = '#f3f4f6'; }, onMouseLeave: function (e) { return e.currentTarget.style.backgroundColor = 'white'; }, children: "Cancel" }), jsxRuntime.jsx("button", { onClick: handleInsertTable, style: {
|
|
1726
|
+
padding: '8px 16px',
|
|
1727
|
+
border: 'none',
|
|
1728
|
+
borderRadius: '4px',
|
|
1729
|
+
backgroundColor: '#3b82f6',
|
|
1730
|
+
color: 'white',
|
|
1731
|
+
cursor: 'pointer',
|
|
1732
|
+
fontSize: '14px',
|
|
1733
|
+
fontWeight: '500',
|
|
1734
|
+
}, onMouseEnter: function (e) { return e.currentTarget.style.backgroundColor = '#2563eb'; }, onMouseLeave: function (e) { return e.currentTarget.style.backgroundColor = '#3b82f6'; }, children: "Insert Table" })] })] }) })), jsxRuntime.jsxs("div", { className: className, style: {
|
|
1735
|
+
border: '1px solid #ccc',
|
|
1736
|
+
borderBottom: showFindReplace ? 'none' : '1px solid #ccc',
|
|
1737
|
+
padding: '4px 8px',
|
|
1738
|
+
backgroundColor: '#fff',
|
|
1739
|
+
borderRadius: showFindReplace ? '4px 4px 0 0' : '4px',
|
|
1740
|
+
display: 'flex',
|
|
1741
|
+
flexWrap: 'wrap',
|
|
1742
|
+
gap: '2px',
|
|
1743
|
+
alignItems: 'center',
|
|
1744
|
+
justifyContent: 'space-between',
|
|
1745
|
+
boxShadow: 'none',
|
|
1746
|
+
minHeight: '42px',
|
|
1747
|
+
maxWidth: '100%',
|
|
1748
|
+
overflow: 'visible',
|
|
1749
|
+
position: 'relative',
|
|
1750
|
+
zIndex: 100
|
|
1751
|
+
}, children: [jsxRuntime.jsx("div", { style: { display: 'flex', flexWrap: 'wrap', gap: '2px', alignItems: 'center', flex: 1 }, children: items.filter(function (item) { return item !== 'fullscreen' && item !== 'find-replace'; }).map(function (item, index) { return renderToolbarItem(item, index); }) }), jsxRuntime.jsxs("div", { style: { display: 'flex', gap: '2px', marginLeft: '8px' }, children: [items.includes('find-replace') && renderToolbarItem('find-replace', items.length - 1), items.includes('fullscreen') && renderToolbarItem('fullscreen', items.length)] })] }), showFindReplace && (jsxRuntime.jsxs("div", { style: {
|
|
1752
|
+
backgroundColor: '#f9fafb',
|
|
1753
|
+
border: '1px solid #ccc',
|
|
1754
|
+
borderTop: 'none',
|
|
1755
|
+
borderRadius: '0 0 4px 4px',
|
|
1756
|
+
padding: '16px',
|
|
1757
|
+
display: 'flex',
|
|
1758
|
+
alignItems: 'flex-start',
|
|
1759
|
+
gap: '12px',
|
|
1760
|
+
boxShadow: '0 2px 4px rgba(0, 0, 0, 0.05)',
|
|
1761
|
+
}, children: [jsxRuntime.jsxs("div", { style: { flex: '1', minWidth: '200px' }, children: [jsxRuntime.jsxs("div", { style: { position: 'relative' }, children: [jsxRuntime.jsx("input", { type: "text", value: searchQuery, onChange: function (e) { return onSearchQueryChange === null || onSearchQueryChange === void 0 ? void 0 : onSearchQueryChange(e.target.value); }, placeholder: "Find...", autoFocus: true, style: {
|
|
1762
|
+
width: '100%',
|
|
1763
|
+
padding: '8px 10px 8px 32px',
|
|
1764
|
+
border: searchQuery && totalMatches === 0 ? '1px solid #ef4444' : '1px solid #d1d5db',
|
|
1765
|
+
borderRadius: '6px',
|
|
1766
|
+
fontSize: '13px',
|
|
1767
|
+
outline: 'none',
|
|
1768
|
+
transition: 'all 0.2s',
|
|
1769
|
+
backgroundColor: 'white',
|
|
1770
|
+
boxSizing: 'border-box',
|
|
1771
|
+
}, onFocus: function (e) {
|
|
1772
|
+
if (!searchQuery || totalMatches > 0) {
|
|
1773
|
+
e.currentTarget.style.borderColor = '#3b82f6';
|
|
1774
|
+
}
|
|
1775
|
+
}, onBlur: function (e) {
|
|
1776
|
+
if (searchQuery && totalMatches === 0) {
|
|
1777
|
+
e.currentTarget.style.borderColor = '#ef4444';
|
|
1778
|
+
}
|
|
1779
|
+
else {
|
|
1780
|
+
e.currentTarget.style.borderColor = '#d1d5db';
|
|
1781
|
+
}
|
|
1782
|
+
} }), jsxRuntime.jsx(outline.MagnifyingGlassIcon, { style: {
|
|
1783
|
+
width: '16px',
|
|
1784
|
+
height: '16px',
|
|
1785
|
+
position: 'absolute',
|
|
1786
|
+
left: '10px',
|
|
1787
|
+
top: '50%',
|
|
1788
|
+
transform: 'translateY(-50%)',
|
|
1789
|
+
color: '#9ca3af',
|
|
1790
|
+
pointerEvents: 'none',
|
|
1791
|
+
} })] }), searchQuery && (jsxRuntime.jsx("div", { style: {
|
|
1792
|
+
marginTop: '4px',
|
|
1793
|
+
fontSize: '11px',
|
|
1794
|
+
color: totalMatches === 0 ? '#ef4444' : '#6b7280',
|
|
1795
|
+
}, children: totalMatches === 0 ? 'No matches' : "".concat(currentMatchIndex + 1, " of ").concat(totalMatches) }))] }), searchQuery && (jsxRuntime.jsxs("div", { style: { display: 'flex', gap: '4px' }, children: [jsxRuntime.jsx("button", { onClick: handlePrevMatch, disabled: totalMatches === 0, title: "Previous match (Shift+Enter)", style: {
|
|
1796
|
+
padding: '8px',
|
|
1797
|
+
border: '1px solid #d1d5db',
|
|
1798
|
+
borderRadius: '6px',
|
|
1799
|
+
backgroundColor: totalMatches === 0 ? '#f3f4f6' : 'white',
|
|
1800
|
+
cursor: totalMatches === 0 ? 'not-allowed' : 'pointer',
|
|
1801
|
+
display: 'flex',
|
|
1802
|
+
alignItems: 'center',
|
|
1803
|
+
color: totalMatches === 0 ? '#d1d5db' : '#6b7280',
|
|
1804
|
+
transition: 'all 0.2s',
|
|
1805
|
+
}, onMouseEnter: function (e) {
|
|
1806
|
+
if (totalMatches > 0) {
|
|
1807
|
+
e.currentTarget.style.backgroundColor = '#f3f4f6';
|
|
1808
|
+
e.currentTarget.style.borderColor = '#9ca3af';
|
|
1809
|
+
}
|
|
1810
|
+
}, onMouseLeave: function (e) {
|
|
1811
|
+
if (totalMatches > 0) {
|
|
1812
|
+
e.currentTarget.style.backgroundColor = 'white';
|
|
1813
|
+
e.currentTarget.style.borderColor = '#d1d5db';
|
|
1814
|
+
}
|
|
1815
|
+
}, children: jsxRuntime.jsx(outline.ChevronLeftIcon, { style: { width: '14px', height: '14px' } }) }), jsxRuntime.jsx("button", { onClick: handleNextMatch, disabled: totalMatches === 0, title: "Next match (Enter)", style: {
|
|
1816
|
+
padding: '8px',
|
|
1817
|
+
border: '1px solid #d1d5db',
|
|
1818
|
+
borderRadius: '6px',
|
|
1819
|
+
backgroundColor: totalMatches === 0 ? '#f3f4f6' : 'white',
|
|
1820
|
+
cursor: totalMatches === 0 ? 'not-allowed' : 'pointer',
|
|
1821
|
+
display: 'flex',
|
|
1822
|
+
alignItems: 'center',
|
|
1823
|
+
color: totalMatches === 0 ? '#d1d5db' : '#6b7280',
|
|
1824
|
+
transition: 'all 0.2s',
|
|
1825
|
+
}, onMouseEnter: function (e) {
|
|
1826
|
+
if (totalMatches > 0) {
|
|
1827
|
+
e.currentTarget.style.backgroundColor = '#f3f4f6';
|
|
1828
|
+
e.currentTarget.style.borderColor = '#9ca3af';
|
|
1829
|
+
}
|
|
1830
|
+
}, onMouseLeave: function (e) {
|
|
1831
|
+
if (totalMatches > 0) {
|
|
1832
|
+
e.currentTarget.style.backgroundColor = 'white';
|
|
1833
|
+
e.currentTarget.style.borderColor = '#d1d5db';
|
|
1834
|
+
}
|
|
1835
|
+
}, children: jsxRuntime.jsx(outline.ChevronRightIcon, { style: { width: '14px', height: '14px' } }) })] })), jsxRuntime.jsx("div", { style: { flex: '1', minWidth: '200px' }, children: jsxRuntime.jsx("input", { type: "text", value: replaceText, onChange: function (e) { return setReplaceText(e.target.value); }, placeholder: "Replace...", style: {
|
|
1836
|
+
width: '100%',
|
|
1837
|
+
padding: '8px 10px',
|
|
1838
|
+
border: '1px solid #d1d5db',
|
|
1839
|
+
borderRadius: '6px',
|
|
1840
|
+
fontSize: '13px',
|
|
1841
|
+
outline: 'none',
|
|
1842
|
+
transition: 'all 0.2s',
|
|
1843
|
+
backgroundColor: 'white',
|
|
1844
|
+
boxSizing: 'border-box',
|
|
1845
|
+
}, onFocus: function (e) {
|
|
1846
|
+
e.currentTarget.style.borderColor = '#3b82f6';
|
|
1847
|
+
}, onBlur: function (e) {
|
|
1848
|
+
e.currentTarget.style.borderColor = '#d1d5db';
|
|
1849
|
+
} }) }), jsxRuntime.jsxs("div", { style: { display: 'flex', gap: '6px' }, children: [jsxRuntime.jsx("button", { onClick: handleReplace, disabled: searchMatches.length === 0, title: "Replace current match", style: {
|
|
1850
|
+
padding: '8px 12px',
|
|
1851
|
+
border: '1px solid #d1d5db',
|
|
1852
|
+
borderRadius: '6px',
|
|
1853
|
+
backgroundColor: searchMatches.length === 0 ? '#f3f4f6' : 'white',
|
|
1854
|
+
color: searchMatches.length === 0 ? '#9ca3af' : '#374151',
|
|
1855
|
+
cursor: searchMatches.length === 0 ? 'not-allowed' : 'pointer',
|
|
1856
|
+
fontSize: '13px',
|
|
1857
|
+
fontWeight: '500',
|
|
1858
|
+
whiteSpace: 'nowrap',
|
|
1859
|
+
transition: 'all 0.2s',
|
|
1860
|
+
}, onMouseEnter: function (e) {
|
|
1861
|
+
if (searchMatches.length > 0) {
|
|
1862
|
+
e.currentTarget.style.backgroundColor = '#f3f4f6';
|
|
1863
|
+
e.currentTarget.style.borderColor = '#9ca3af';
|
|
1864
|
+
}
|
|
1865
|
+
}, onMouseLeave: function (e) {
|
|
1866
|
+
if (searchMatches.length > 0) {
|
|
1867
|
+
e.currentTarget.style.backgroundColor = 'white';
|
|
1868
|
+
e.currentTarget.style.borderColor = '#d1d5db';
|
|
1869
|
+
}
|
|
1870
|
+
}, children: "Replace" }), jsxRuntime.jsx("button", { onClick: handleReplaceAll, disabled: searchMatches.length === 0, title: "Replace all matches", style: {
|
|
1871
|
+
padding: '8px 12px',
|
|
1872
|
+
border: 'none',
|
|
1873
|
+
borderRadius: '6px',
|
|
1874
|
+
backgroundColor: searchMatches.length === 0 ? '#cbd5e1' : '#3b82f6',
|
|
1875
|
+
color: 'white',
|
|
1876
|
+
cursor: searchMatches.length === 0 ? 'not-allowed' : 'pointer',
|
|
1877
|
+
fontSize: '13px',
|
|
1878
|
+
fontWeight: '500',
|
|
1879
|
+
whiteSpace: 'nowrap',
|
|
1880
|
+
transition: 'all 0.2s',
|
|
1881
|
+
}, onMouseEnter: function (e) {
|
|
1882
|
+
if (searchMatches.length > 0) {
|
|
1883
|
+
e.currentTarget.style.backgroundColor = '#2563eb';
|
|
1884
|
+
}
|
|
1885
|
+
}, onMouseLeave: function (e) {
|
|
1886
|
+
if (searchMatches.length > 0) {
|
|
1887
|
+
e.currentTarget.style.backgroundColor = '#3b82f6';
|
|
1888
|
+
}
|
|
1889
|
+
}, children: "Replace All" })] }), jsxRuntime.jsx("button", { onClick: function () { return setShowFindReplace(false); }, title: "Close (Esc)", style: {
|
|
1890
|
+
padding: '8px',
|
|
1891
|
+
border: '1px solid #d1d5db',
|
|
1892
|
+
borderRadius: '6px',
|
|
1893
|
+
backgroundColor: 'white',
|
|
1894
|
+
cursor: 'pointer',
|
|
1895
|
+
display: 'flex',
|
|
1896
|
+
alignItems: 'center',
|
|
1897
|
+
color: '#6b7280',
|
|
1898
|
+
transition: 'all 0.2s',
|
|
1899
|
+
}, onMouseEnter: function (e) {
|
|
1900
|
+
e.currentTarget.style.backgroundColor = '#fee2e2';
|
|
1901
|
+
e.currentTarget.style.borderColor = '#ef4444';
|
|
1902
|
+
e.currentTarget.style.color = '#dc2626';
|
|
1903
|
+
}, onMouseLeave: function (e) {
|
|
1904
|
+
e.currentTarget.style.backgroundColor = 'white';
|
|
1905
|
+
e.currentTarget.style.borderColor = '#d1d5db';
|
|
1906
|
+
e.currentTarget.style.color = '#6b7280';
|
|
1907
|
+
}, children: jsxRuntime.jsx(outline.XMarkIcon, { style: { width: '16px', height: '16px' } }) })] }))] }));
|
|
1908
|
+
};
|
|
1909
|
+
|
|
1910
|
+
var ResizableImage = function (_a) {
|
|
1911
|
+
var element = _a.element, attributes = _a.attributes, children = _a.children;
|
|
1912
|
+
var editor = slateReact.useSlateStatic();
|
|
1913
|
+
var selected = slateReact.useSelected();
|
|
1914
|
+
var focused = slateReact.useFocused();
|
|
1915
|
+
var _b = React.useState(false), isResizing = _b[0], setIsResizing = _b[1];
|
|
1916
|
+
var _c = React.useState({
|
|
1917
|
+
width: element.width || 0,
|
|
1918
|
+
height: element.height || 0,
|
|
1919
|
+
}), dimensions = _c[0], setDimensions = _c[1];
|
|
1920
|
+
var _d = React.useState(false), showActions = _d[0], setShowActions = _d[1];
|
|
1921
|
+
var imageRef = React.useRef(null);
|
|
1922
|
+
var startPos = React.useRef({ x: 0, y: 0, width: 0, height: 0 });
|
|
1923
|
+
var handleImageLoad = React.useCallback(function (e) {
|
|
1924
|
+
var img = e.currentTarget;
|
|
1925
|
+
if (!element.width && !element.height) {
|
|
1926
|
+
setDimensions({
|
|
1927
|
+
width: img.naturalWidth,
|
|
1928
|
+
height: img.naturalHeight,
|
|
1929
|
+
});
|
|
1930
|
+
}
|
|
1931
|
+
}, [element.width, element.height]);
|
|
1932
|
+
var handleMouseDown = React.useCallback(function (e, handle) {
|
|
1933
|
+
var _a, _b;
|
|
1934
|
+
e.preventDefault();
|
|
1935
|
+
e.stopPropagation();
|
|
1936
|
+
setIsResizing(true);
|
|
1937
|
+
var currentWidth = dimensions.width || ((_a = imageRef.current) === null || _a === void 0 ? void 0 : _a.offsetWidth) || 0;
|
|
1938
|
+
var currentHeight = dimensions.height || ((_b = imageRef.current) === null || _b === void 0 ? void 0 : _b.offsetHeight) || 0;
|
|
1939
|
+
startPos.current = {
|
|
1940
|
+
x: e.clientX,
|
|
1941
|
+
y: e.clientY,
|
|
1942
|
+
width: currentWidth,
|
|
1943
|
+
height: currentHeight,
|
|
1944
|
+
};
|
|
1945
|
+
var handleMouseMove = function (moveEvent) {
|
|
1946
|
+
var deltaX = moveEvent.clientX - startPos.current.x;
|
|
1947
|
+
var deltaY = moveEvent.clientY - startPos.current.y;
|
|
1948
|
+
var newWidth = startPos.current.width;
|
|
1949
|
+
var newHeight = startPos.current.height;
|
|
1950
|
+
switch (handle) {
|
|
1951
|
+
case 'se':
|
|
1952
|
+
newWidth = Math.max(100, startPos.current.width + deltaX);
|
|
1953
|
+
newHeight = Math.max(100, startPos.current.height + deltaY);
|
|
1954
|
+
break;
|
|
1955
|
+
case 'sw':
|
|
1956
|
+
newWidth = Math.max(100, startPos.current.width - deltaX);
|
|
1957
|
+
newHeight = Math.max(100, startPos.current.height + deltaY);
|
|
1958
|
+
break;
|
|
1959
|
+
case 'ne':
|
|
1960
|
+
newWidth = Math.max(100, startPos.current.width + deltaX);
|
|
1961
|
+
newHeight = Math.max(100, startPos.current.height - deltaY);
|
|
1962
|
+
break;
|
|
1963
|
+
case 'nw':
|
|
1964
|
+
newWidth = Math.max(100, startPos.current.width - deltaX);
|
|
1965
|
+
newHeight = Math.max(100, startPos.current.height - deltaY);
|
|
1966
|
+
break;
|
|
1967
|
+
case 'e':
|
|
1968
|
+
newWidth = Math.max(100, startPos.current.width + deltaX);
|
|
1969
|
+
newHeight = startPos.current.height;
|
|
1970
|
+
break;
|
|
1971
|
+
case 'w':
|
|
1972
|
+
newWidth = Math.max(100, startPos.current.width - deltaX);
|
|
1973
|
+
newHeight = startPos.current.height;
|
|
1974
|
+
break;
|
|
1975
|
+
case 'n':
|
|
1976
|
+
newWidth = startPos.current.width;
|
|
1977
|
+
newHeight = Math.max(100, startPos.current.height - deltaY);
|
|
1978
|
+
break;
|
|
1979
|
+
case 's':
|
|
1980
|
+
newWidth = startPos.current.width;
|
|
1981
|
+
newHeight = Math.max(100, startPos.current.height + deltaY);
|
|
1982
|
+
break;
|
|
1983
|
+
}
|
|
1984
|
+
setDimensions({ width: newWidth, height: newHeight });
|
|
1985
|
+
};
|
|
1986
|
+
var handleMouseUp = function () {
|
|
1987
|
+
setIsResizing(false);
|
|
1988
|
+
var path = slateReact.ReactEditor.findPath(editor, element);
|
|
1989
|
+
slate.Transforms.setNodes(editor, {
|
|
1990
|
+
width: dimensions.width,
|
|
1991
|
+
height: dimensions.height
|
|
1992
|
+
}, { at: path });
|
|
1993
|
+
document.removeEventListener('mousemove', handleMouseMove);
|
|
1994
|
+
document.removeEventListener('mouseup', handleMouseUp);
|
|
1995
|
+
};
|
|
1996
|
+
document.addEventListener('mousemove', handleMouseMove);
|
|
1997
|
+
document.addEventListener('mouseup', handleMouseUp);
|
|
1998
|
+
}, [dimensions, editor, element]);
|
|
1999
|
+
var handleRemoveImage = React.useCallback(function () {
|
|
2000
|
+
var path = slateReact.ReactEditor.findPath(editor, element);
|
|
2001
|
+
slate.Transforms.removeNodes(editor, { at: path });
|
|
2002
|
+
}, [editor, element]);
|
|
2003
|
+
var handleReplaceImage = React.useCallback(function () {
|
|
2004
|
+
if (window.__editiumImageReplaceHandler) {
|
|
2005
|
+
var path = slateReact.ReactEditor.findPath(editor, element);
|
|
2006
|
+
window.__editiumImageReplaceHandler({
|
|
2007
|
+
url: element.url,
|
|
2008
|
+
alt: element.alt,
|
|
2009
|
+
width: element.width,
|
|
2010
|
+
height: element.height,
|
|
2011
|
+
align: element.align,
|
|
2012
|
+
path: path,
|
|
2013
|
+
});
|
|
2014
|
+
}
|
|
2015
|
+
}, [editor, element]);
|
|
2016
|
+
var handleAlignmentChange = React.useCallback(function (alignment) {
|
|
2017
|
+
var path = slateReact.ReactEditor.findPath(editor, element);
|
|
2018
|
+
slate.Transforms.setNodes(editor, { align: alignment }, { at: path });
|
|
2019
|
+
}, [editor, element]);
|
|
2020
|
+
var containerStyle = {
|
|
2021
|
+
display: 'flex',
|
|
2022
|
+
justifyContent: element.align === 'center' ? 'center' :
|
|
2023
|
+
element.align === 'right' ? 'flex-end' : 'flex-start',
|
|
2024
|
+
margin: '16px 0',
|
|
2025
|
+
position: 'relative',
|
|
2026
|
+
};
|
|
2027
|
+
var wrapperStyle = {
|
|
2028
|
+
position: 'relative',
|
|
2029
|
+
display: 'inline-block',
|
|
2030
|
+
maxWidth: '100%',
|
|
2031
|
+
cursor: isResizing ? 'nwse-resize' : 'default',
|
|
2032
|
+
};
|
|
2033
|
+
var imageStyle = {
|
|
2034
|
+
maxWidth: '100%',
|
|
2035
|
+
width: dimensions.width ? "".concat(dimensions.width, "px") : 'auto',
|
|
2036
|
+
height: dimensions.height ? "".concat(dimensions.height, "px") : 'auto',
|
|
2037
|
+
borderRadius: '4px',
|
|
2038
|
+
boxShadow: (selected && focused) || showActions
|
|
2039
|
+
? '0 0 0 3px #3b82f6'
|
|
2040
|
+
: '0 1px 3px rgba(0, 0, 0, 0.1)',
|
|
2041
|
+
display: 'block',
|
|
2042
|
+
transition: showActions || (selected && focused) ? 'none' : 'box-shadow 0.2s ease',
|
|
2043
|
+
};
|
|
2044
|
+
var handleStyle = {
|
|
2045
|
+
position: 'absolute',
|
|
2046
|
+
width: '12px',
|
|
2047
|
+
height: '12px',
|
|
2048
|
+
backgroundColor: '#3b82f6',
|
|
2049
|
+
border: '2px solid #ffffff',
|
|
2050
|
+
borderRadius: '50%',
|
|
2051
|
+
opacity: showActions ? 1 : 0,
|
|
2052
|
+
transition: 'opacity 0.2s ease',
|
|
2053
|
+
pointerEvents: showActions ? 'auto' : 'none',
|
|
2054
|
+
zIndex: 10,
|
|
2055
|
+
};
|
|
2056
|
+
return (jsxRuntime.jsxs("div", __assign({}, attributes, { contentEditable: false, style: { userSelect: 'none' }, children: [jsxRuntime.jsx("div", { style: containerStyle, children: jsxRuntime.jsxs("div", { style: wrapperStyle, onMouseEnter: function () { return setShowActions(true); }, onMouseLeave: function () { return !isResizing && setShowActions(false); }, children: [jsxRuntime.jsx("img", { ref: imageRef, src: element.url, alt: element.alt || 'Image', style: imageStyle, onLoad: handleImageLoad, draggable: false }), ((selected && focused) || showActions) && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("div", { style: __assign(__assign({}, handleStyle), { top: '-6px', left: '-6px', cursor: 'nw-resize' }), onMouseDown: function (e) { return handleMouseDown(e, 'nw'); }, title: "Resize" }), jsxRuntime.jsx("div", { style: __assign(__assign({}, handleStyle), { top: '-6px', right: '-6px', cursor: 'ne-resize' }), onMouseDown: function (e) { return handleMouseDown(e, 'ne'); }, title: "Resize" }), jsxRuntime.jsx("div", { style: __assign(__assign({}, handleStyle), { bottom: '-6px', left: '-6px', cursor: 'sw-resize' }), onMouseDown: function (e) { return handleMouseDown(e, 'sw'); }, title: "Resize" }), jsxRuntime.jsx("div", { style: __assign(__assign({}, handleStyle), { bottom: '-6px', right: '-6px', cursor: 'se-resize' }), onMouseDown: function (e) { return handleMouseDown(e, 'se'); }, title: "Resize" }), jsxRuntime.jsx("div", { style: __assign(__assign({}, handleStyle), { top: '-6px', left: '50%', transform: 'translateX(-50%)', cursor: 'n-resize' }), onMouseDown: function (e) { return handleMouseDown(e, 'n'); }, title: "Resize Height" }), jsxRuntime.jsx("div", { style: __assign(__assign({}, handleStyle), { bottom: '-6px', left: '50%', transform: 'translateX(-50%)', cursor: 's-resize' }), onMouseDown: function (e) { return handleMouseDown(e, 's'); }, title: "Resize Height" }), jsxRuntime.jsx("div", { style: __assign(__assign({}, handleStyle), { left: '-6px', top: '50%', transform: 'translateY(-50%)', cursor: 'w-resize' }), onMouseDown: function (e) { return handleMouseDown(e, 'w'); }, title: "Resize Width" }), jsxRuntime.jsx("div", { style: __assign(__assign({}, handleStyle), { right: '-6px', top: '50%', transform: 'translateY(-50%)', cursor: 'e-resize' }), onMouseDown: function (e) { return handleMouseDown(e, 'e'); }, title: "Resize Width" })] })), ((selected && focused) || showActions) && (jsxRuntime.jsxs("div", { style: {
|
|
2057
|
+
position: 'absolute',
|
|
2058
|
+
top: '8px',
|
|
2059
|
+
right: '8px',
|
|
2060
|
+
display: 'flex',
|
|
2061
|
+
flexDirection: 'column',
|
|
2062
|
+
gap: '8px',
|
|
2063
|
+
zIndex: 11,
|
|
2064
|
+
}, children: [jsxRuntime.jsxs("div", { style: {
|
|
2065
|
+
display: 'flex',
|
|
2066
|
+
gap: '4px',
|
|
2067
|
+
backgroundColor: '#ffffff',
|
|
2068
|
+
border: '1px solid #d1d5db',
|
|
2069
|
+
borderRadius: '4px',
|
|
2070
|
+
padding: '4px',
|
|
2071
|
+
boxShadow: '0 1px 2px rgba(0, 0, 0, 0.05)',
|
|
2072
|
+
}, children: [jsxRuntime.jsx("button", { onClick: function () { return handleAlignmentChange('left'); }, onMouseDown: function (e) { return e.preventDefault(); }, style: {
|
|
2073
|
+
padding: '4px 8px',
|
|
2074
|
+
backgroundColor: element.align === 'left' ? '#e0f2fe' : 'transparent',
|
|
2075
|
+
border: 'none',
|
|
2076
|
+
borderRadius: '2px',
|
|
2077
|
+
color: '#374151',
|
|
2078
|
+
fontSize: '12px',
|
|
2079
|
+
fontWeight: '500',
|
|
2080
|
+
cursor: 'pointer',
|
|
2081
|
+
transition: 'all 0.15s ease',
|
|
2082
|
+
}, onMouseEnter: function (e) {
|
|
2083
|
+
if (element.align !== 'left') {
|
|
2084
|
+
e.currentTarget.style.backgroundColor = '#f9fafb';
|
|
2085
|
+
}
|
|
2086
|
+
}, onMouseLeave: function (e) {
|
|
2087
|
+
if (element.align !== 'left') {
|
|
2088
|
+
e.currentTarget.style.backgroundColor = 'transparent';
|
|
2089
|
+
}
|
|
2090
|
+
}, title: "Align left", children: "\u2B05" }), jsxRuntime.jsx("button", { onClick: function () { return handleAlignmentChange('center'); }, onMouseDown: function (e) { return e.preventDefault(); }, style: {
|
|
2091
|
+
padding: '4px 8px',
|
|
2092
|
+
backgroundColor: element.align === 'center' ? '#e0f2fe' : 'transparent',
|
|
2093
|
+
border: 'none',
|
|
2094
|
+
borderRadius: '2px',
|
|
2095
|
+
color: '#374151',
|
|
2096
|
+
fontSize: '12px',
|
|
2097
|
+
fontWeight: '500',
|
|
2098
|
+
cursor: 'pointer',
|
|
2099
|
+
transition: 'all 0.15s ease',
|
|
2100
|
+
}, onMouseEnter: function (e) {
|
|
2101
|
+
if (element.align !== 'center') {
|
|
2102
|
+
e.currentTarget.style.backgroundColor = '#f9fafb';
|
|
2103
|
+
}
|
|
2104
|
+
}, onMouseLeave: function (e) {
|
|
2105
|
+
if (element.align !== 'center') {
|
|
2106
|
+
e.currentTarget.style.backgroundColor = 'transparent';
|
|
2107
|
+
}
|
|
2108
|
+
}, title: "Align center", children: "\u2194" }), jsxRuntime.jsx("button", { onClick: function () { return handleAlignmentChange('right'); }, onMouseDown: function (e) { return e.preventDefault(); }, style: {
|
|
2109
|
+
padding: '4px 8px',
|
|
2110
|
+
backgroundColor: element.align === 'right' ? '#e0f2fe' : 'transparent',
|
|
2111
|
+
border: 'none',
|
|
2112
|
+
borderRadius: '2px',
|
|
2113
|
+
color: '#374151',
|
|
2114
|
+
fontSize: '12px',
|
|
2115
|
+
fontWeight: '500',
|
|
2116
|
+
cursor: 'pointer',
|
|
2117
|
+
transition: 'all 0.15s ease',
|
|
2118
|
+
}, onMouseEnter: function (e) {
|
|
2119
|
+
if (element.align !== 'right') {
|
|
2120
|
+
e.currentTarget.style.backgroundColor = '#f9fafb';
|
|
2121
|
+
}
|
|
2122
|
+
}, onMouseLeave: function (e) {
|
|
2123
|
+
if (element.align !== 'right') {
|
|
2124
|
+
e.currentTarget.style.backgroundColor = 'transparent';
|
|
2125
|
+
}
|
|
2126
|
+
}, title: "Align right", children: "\u27A1" })] }), jsxRuntime.jsxs("div", { style: {
|
|
2127
|
+
display: 'flex',
|
|
2128
|
+
gap: '4px',
|
|
2129
|
+
}, children: [jsxRuntime.jsx("button", { onClick: handleReplaceImage, onMouseDown: function (e) { return e.preventDefault(); }, style: {
|
|
2130
|
+
padding: '6px 12px',
|
|
2131
|
+
backgroundColor: '#ffffff',
|
|
2132
|
+
border: '1px solid #d1d5db',
|
|
2133
|
+
borderRadius: '4px',
|
|
2134
|
+
color: '#374151',
|
|
2135
|
+
fontSize: '12px',
|
|
2136
|
+
fontWeight: '500',
|
|
2137
|
+
cursor: 'pointer',
|
|
2138
|
+
boxShadow: '0 1px 2px rgba(0, 0, 0, 0.05)',
|
|
2139
|
+
transition: 'all 0.15s ease',
|
|
2140
|
+
}, onMouseEnter: function (e) {
|
|
2141
|
+
e.currentTarget.style.backgroundColor = '#f9fafb';
|
|
2142
|
+
e.currentTarget.style.borderColor = '#9ca3af';
|
|
2143
|
+
}, onMouseLeave: function (e) {
|
|
2144
|
+
e.currentTarget.style.backgroundColor = '#ffffff';
|
|
2145
|
+
e.currentTarget.style.borderColor = '#d1d5db';
|
|
2146
|
+
}, title: "Replace image", children: "Replace" }), jsxRuntime.jsx("button", { onClick: handleRemoveImage, onMouseDown: function (e) { return e.preventDefault(); }, style: {
|
|
2147
|
+
padding: '6px 12px',
|
|
2148
|
+
backgroundColor: '#ffffff',
|
|
2149
|
+
border: '1px solid #d1d5db',
|
|
2150
|
+
borderRadius: '4px',
|
|
2151
|
+
color: '#dc2626',
|
|
2152
|
+
fontSize: '12px',
|
|
2153
|
+
fontWeight: '500',
|
|
2154
|
+
cursor: 'pointer',
|
|
2155
|
+
boxShadow: '0 1px 2px rgba(0, 0, 0, 0.05)',
|
|
2156
|
+
transition: 'all 0.15s ease',
|
|
2157
|
+
}, onMouseEnter: function (e) {
|
|
2158
|
+
e.currentTarget.style.backgroundColor = '#fef2f2';
|
|
2159
|
+
e.currentTarget.style.borderColor = '#fca5a5';
|
|
2160
|
+
}, onMouseLeave: function (e) {
|
|
2161
|
+
e.currentTarget.style.backgroundColor = '#ffffff';
|
|
2162
|
+
e.currentTarget.style.borderColor = '#d1d5db';
|
|
2163
|
+
}, title: "Remove image", children: "Remove" })] })] }))] }) }), children] })));
|
|
2164
|
+
};
|
|
2165
|
+
|
|
2166
|
+
var TableComponent = function (_a) {
|
|
2167
|
+
var element = _a.element, attributes = _a.attributes, children = _a.children;
|
|
2168
|
+
var editor = slateReact.useSlateStatic();
|
|
2169
|
+
var selected = slateReact.useSelected();
|
|
2170
|
+
var focused = slateReact.useFocused();
|
|
2171
|
+
var _b = React.useState(false), showControls = _b[0], setShowControls = _b[1];
|
|
2172
|
+
var _c = React.useState(element.width || null), tableWidth = _c[0], setTableWidth = _c[1];
|
|
2173
|
+
var _d = React.useState(false), isResizing = _d[0], setIsResizing = _d[1];
|
|
2174
|
+
var tableRef = React.useRef(null);
|
|
2175
|
+
var handleAddRow = function () {
|
|
2176
|
+
addTableRow(editor);
|
|
2177
|
+
};
|
|
2178
|
+
var handleRemoveRow = function () {
|
|
2179
|
+
removeTableRow(editor);
|
|
2180
|
+
};
|
|
2181
|
+
var handleAddColumn = function () {
|
|
2182
|
+
addTableColumn(editor);
|
|
2183
|
+
};
|
|
2184
|
+
var handleRemoveColumn = function () {
|
|
2185
|
+
removeTableColumn(editor);
|
|
2186
|
+
};
|
|
2187
|
+
var handleDeleteTable = function () {
|
|
2188
|
+
slate.Transforms.removeNodes(editor, {
|
|
2189
|
+
match: function (n) {
|
|
2190
|
+
return !slate.Editor.isEditor(n) &&
|
|
2191
|
+
n.type === 'table';
|
|
2192
|
+
},
|
|
2193
|
+
});
|
|
2194
|
+
};
|
|
2195
|
+
var handleAlign = function (alignment) {
|
|
2196
|
+
setTableAlignment(editor, alignment);
|
|
2197
|
+
};
|
|
2198
|
+
var updateTableWidth = function (width) {
|
|
2199
|
+
setTableWidth(width);
|
|
2200
|
+
try {
|
|
2201
|
+
var path = slateReact.ReactEditor.findPath(editor, element);
|
|
2202
|
+
slate.Transforms.setNodes(editor, { width: width }, { at: path });
|
|
2203
|
+
}
|
|
2204
|
+
catch (error) {
|
|
2205
|
+
console.warn('Could not update table width:', error);
|
|
2206
|
+
}
|
|
2207
|
+
};
|
|
2208
|
+
return (jsxRuntime.jsx("div", { style: {
|
|
2209
|
+
position: 'relative',
|
|
2210
|
+
margin: '16px 0',
|
|
2211
|
+
display: 'flex',
|
|
2212
|
+
justifyContent: element.align === 'center' ? 'center' :
|
|
2213
|
+
element.align === 'right' ? 'flex-end' : 'flex-start',
|
|
2214
|
+
}, children: jsxRuntime.jsxs("div", __assign({}, attributes, { style: { position: 'relative', width: tableWidth ? "".concat(tableWidth, "px") : '100%', maxWidth: '100%' }, onMouseEnter: function () { return setShowControls(true); }, onMouseLeave: function () { return setShowControls(false); }, children: [jsxRuntime.jsx("table", { ref: tableRef, style: {
|
|
2215
|
+
borderCollapse: 'collapse',
|
|
2216
|
+
width: '100%',
|
|
2217
|
+
border: (selected && focused) || showControls ? '2px solid #3b82f6' : '1px solid #e5e7eb',
|
|
2218
|
+
transition: 'border 0.2s ease',
|
|
2219
|
+
}, children: jsxRuntime.jsx("tbody", { children: children }) }), ((selected && focused) || showControls) && (jsxRuntime.jsxs("div", { contentEditable: false, style: {
|
|
2220
|
+
position: 'absolute',
|
|
2221
|
+
top: '-40px',
|
|
2222
|
+
right: '0',
|
|
2223
|
+
display: 'flex',
|
|
2224
|
+
gap: '4px',
|
|
2225
|
+
backgroundColor: '#fff',
|
|
2226
|
+
padding: '4px',
|
|
2227
|
+
borderRadius: '6px',
|
|
2228
|
+
boxShadow: '0 2px 8px rgba(0, 0, 0, 0.15)',
|
|
2229
|
+
zIndex: 10,
|
|
2230
|
+
}, children: [jsxRuntime.jsxs("button", { onClick: handleAddRow, title: "Add Row", style: {
|
|
2231
|
+
display: 'flex',
|
|
2232
|
+
alignItems: 'center',
|
|
2233
|
+
gap: '4px',
|
|
2234
|
+
padding: '6px 10px',
|
|
2235
|
+
border: '1px solid #e5e7eb',
|
|
2236
|
+
borderRadius: '4px',
|
|
2237
|
+
backgroundColor: '#fff',
|
|
2238
|
+
cursor: 'pointer',
|
|
2239
|
+
fontSize: '13px',
|
|
2240
|
+
color: '#374151',
|
|
2241
|
+
}, onMouseOver: function (e) { return (e.currentTarget.style.backgroundColor = '#f3f4f6'); }, onMouseOut: function (e) { return (e.currentTarget.style.backgroundColor = '#fff'); }, children: [jsxRuntime.jsx(outline.PlusIcon, { style: { width: '16px', height: '16px' } }), "Row"] }), jsxRuntime.jsxs("button", { onClick: handleRemoveRow, title: "Remove Row", style: {
|
|
2242
|
+
display: 'flex',
|
|
2243
|
+
alignItems: 'center',
|
|
2244
|
+
gap: '4px',
|
|
2245
|
+
padding: '6px 10px',
|
|
2246
|
+
border: '1px solid #e5e7eb',
|
|
2247
|
+
borderRadius: '4px',
|
|
2248
|
+
backgroundColor: '#fff',
|
|
2249
|
+
cursor: 'pointer',
|
|
2250
|
+
fontSize: '13px',
|
|
2251
|
+
color: '#374151',
|
|
2252
|
+
}, onMouseOver: function (e) { return (e.currentTarget.style.backgroundColor = '#f3f4f6'); }, onMouseOut: function (e) { return (e.currentTarget.style.backgroundColor = '#fff'); }, children: [jsxRuntime.jsx(outline.MinusIcon, { style: { width: '16px', height: '16px' } }), "Row"] }), jsxRuntime.jsxs("button", { onClick: handleAddColumn, title: "Add Column", style: {
|
|
2253
|
+
display: 'flex',
|
|
2254
|
+
alignItems: 'center',
|
|
2255
|
+
gap: '4px',
|
|
2256
|
+
padding: '6px 10px',
|
|
2257
|
+
border: '1px solid #e5e7eb',
|
|
2258
|
+
borderRadius: '4px',
|
|
2259
|
+
backgroundColor: '#fff',
|
|
2260
|
+
cursor: 'pointer',
|
|
2261
|
+
fontSize: '13px',
|
|
2262
|
+
color: '#374151',
|
|
2263
|
+
}, onMouseOver: function (e) { return (e.currentTarget.style.backgroundColor = '#f3f4f6'); }, onMouseOut: function (e) { return (e.currentTarget.style.backgroundColor = '#fff'); }, children: [jsxRuntime.jsx(outline.PlusIcon, { style: { width: '16px', height: '16px' } }), "Col"] }), jsxRuntime.jsxs("button", { onClick: handleRemoveColumn, title: "Remove Column", style: {
|
|
2264
|
+
display: 'flex',
|
|
2265
|
+
alignItems: 'center',
|
|
2266
|
+
gap: '4px',
|
|
2267
|
+
padding: '6px 10px',
|
|
2268
|
+
border: '1px solid #e5e7eb',
|
|
2269
|
+
borderRadius: '4px',
|
|
2270
|
+
backgroundColor: '#fff',
|
|
2271
|
+
cursor: 'pointer',
|
|
2272
|
+
fontSize: '13px',
|
|
2273
|
+
color: '#374151',
|
|
2274
|
+
}, onMouseOver: function (e) { return (e.currentTarget.style.backgroundColor = '#f3f4f6'); }, onMouseOut: function (e) { return (e.currentTarget.style.backgroundColor = '#fff'); }, children: [jsxRuntime.jsx(outline.MinusIcon, { style: { width: '16px', height: '16px' } }), "Col"] }), jsxRuntime.jsx("div", { style: { width: '1px', height: '24px', backgroundColor: '#e5e7eb', margin: '0 4px' } }), jsxRuntime.jsx("button", { onClick: function () { return handleAlign('left'); }, title: "Align Left", style: {
|
|
2275
|
+
display: 'flex',
|
|
2276
|
+
alignItems: 'center',
|
|
2277
|
+
padding: '6px 8px',
|
|
2278
|
+
border: '1px solid #e5e7eb',
|
|
2279
|
+
borderRadius: '4px',
|
|
2280
|
+
backgroundColor: element.align === 'left' || !element.align ? '#e0e7ff' : '#fff',
|
|
2281
|
+
cursor: 'pointer',
|
|
2282
|
+
fontSize: '13px',
|
|
2283
|
+
color: '#374151',
|
|
2284
|
+
}, onMouseOver: function (e) {
|
|
2285
|
+
if (element.align !== 'left' && element.align)
|
|
2286
|
+
e.currentTarget.style.backgroundColor = '#f3f4f6';
|
|
2287
|
+
}, onMouseOut: function (e) {
|
|
2288
|
+
e.currentTarget.style.backgroundColor = element.align === 'left' || !element.align ? '#e0e7ff' : '#fff';
|
|
2289
|
+
}, children: jsxRuntime.jsx(outline.Bars3BottomLeftIcon, { style: { width: '16px', height: '16px' } }) }), jsxRuntime.jsx("button", { onClick: function () { return handleAlign('center'); }, title: "Align Center", style: {
|
|
2290
|
+
display: 'flex',
|
|
2291
|
+
alignItems: 'center',
|
|
2292
|
+
padding: '6px 8px',
|
|
2293
|
+
border: '1px solid #e5e7eb',
|
|
2294
|
+
borderRadius: '4px',
|
|
2295
|
+
backgroundColor: element.align === 'center' ? '#e0e7ff' : '#fff',
|
|
2296
|
+
cursor: 'pointer',
|
|
2297
|
+
fontSize: '13px',
|
|
2298
|
+
color: '#374151',
|
|
2299
|
+
}, onMouseOver: function (e) {
|
|
2300
|
+
if (element.align !== 'center')
|
|
2301
|
+
e.currentTarget.style.backgroundColor = '#f3f4f6';
|
|
2302
|
+
}, onMouseOut: function (e) {
|
|
2303
|
+
e.currentTarget.style.backgroundColor = element.align === 'center' ? '#e0e7ff' : '#fff';
|
|
2304
|
+
}, children: jsxRuntime.jsx(outline.Bars3Icon, { style: { width: '16px', height: '16px' } }) }), jsxRuntime.jsx("button", { onClick: function () { return handleAlign('right'); }, title: "Align Right", style: {
|
|
2305
|
+
display: 'flex',
|
|
2306
|
+
alignItems: 'center',
|
|
2307
|
+
padding: '6px 8px',
|
|
2308
|
+
border: '1px solid #e5e7eb',
|
|
2309
|
+
borderRadius: '4px',
|
|
2310
|
+
backgroundColor: element.align === 'right' ? '#e0e7ff' : '#fff',
|
|
2311
|
+
cursor: 'pointer',
|
|
2312
|
+
fontSize: '13px',
|
|
2313
|
+
color: '#374151',
|
|
2314
|
+
}, onMouseOver: function (e) {
|
|
2315
|
+
if (element.align !== 'right')
|
|
2316
|
+
e.currentTarget.style.backgroundColor = '#f3f4f6';
|
|
2317
|
+
}, onMouseOut: function (e) {
|
|
2318
|
+
e.currentTarget.style.backgroundColor = element.align === 'right' ? '#e0e7ff' : '#fff';
|
|
2319
|
+
}, children: jsxRuntime.jsx(outline.Bars3BottomRightIcon, { style: { width: '16px', height: '16px' } }) }), jsxRuntime.jsx("div", { style: { width: '1px', height: '24px', backgroundColor: '#e5e7eb', margin: '0 4px' } }), jsxRuntime.jsxs("button", { onClick: handleDeleteTable, title: "Delete Table", style: {
|
|
2320
|
+
display: 'flex',
|
|
2321
|
+
alignItems: 'center',
|
|
2322
|
+
gap: '4px',
|
|
2323
|
+
padding: '6px 10px',
|
|
2324
|
+
border: '1px solid #e5e7eb',
|
|
2325
|
+
borderRadius: '4px',
|
|
2326
|
+
backgroundColor: '#fff',
|
|
2327
|
+
cursor: 'pointer',
|
|
2328
|
+
fontSize: '13px',
|
|
2329
|
+
color: '#dc2626',
|
|
2330
|
+
}, onMouseOver: function (e) {
|
|
2331
|
+
e.currentTarget.style.backgroundColor = '#fee2e2';
|
|
2332
|
+
}, onMouseOut: function (e) {
|
|
2333
|
+
e.currentTarget.style.backgroundColor = '#fff';
|
|
2334
|
+
}, children: [jsxRuntime.jsx(outline.TrashIcon, { style: { width: '16px', height: '16px' } }), "Delete"] })] })), ((selected && focused) || showControls) && (jsxRuntime.jsx("div", { contentEditable: false, onMouseDown: function (e) {
|
|
2335
|
+
var _a;
|
|
2336
|
+
e.preventDefault();
|
|
2337
|
+
e.stopPropagation();
|
|
2338
|
+
setIsResizing(true);
|
|
2339
|
+
var startX = e.clientX;
|
|
2340
|
+
var startWidth = ((_a = tableRef.current) === null || _a === void 0 ? void 0 : _a.offsetWidth) || 0;
|
|
2341
|
+
var finalWidth = startWidth;
|
|
2342
|
+
var handleMouseMove = function (moveEvent) {
|
|
2343
|
+
var diff = moveEvent.clientX - startX;
|
|
2344
|
+
var newWidth = Math.max(200, startWidth + diff);
|
|
2345
|
+
finalWidth = newWidth;
|
|
2346
|
+
setTableWidth(newWidth);
|
|
2347
|
+
};
|
|
2348
|
+
var handleMouseUp = function () {
|
|
2349
|
+
setIsResizing(false);
|
|
2350
|
+
updateTableWidth(finalWidth);
|
|
2351
|
+
document.removeEventListener('mousemove', handleMouseMove);
|
|
2352
|
+
document.removeEventListener('mouseup', handleMouseUp);
|
|
2353
|
+
};
|
|
2354
|
+
document.addEventListener('mousemove', handleMouseMove);
|
|
2355
|
+
document.addEventListener('mouseup', handleMouseUp);
|
|
2356
|
+
}, style: {
|
|
2357
|
+
position: 'absolute',
|
|
2358
|
+
right: '-4px',
|
|
2359
|
+
top: '0',
|
|
2360
|
+
bottom: '0',
|
|
2361
|
+
width: '8px',
|
|
2362
|
+
cursor: 'col-resize',
|
|
2363
|
+
backgroundColor: isResizing ? '#3b82f6' : 'transparent',
|
|
2364
|
+
transition: 'background-color 0.2s',
|
|
2365
|
+
zIndex: 5,
|
|
2366
|
+
}, onMouseEnter: function (e) {
|
|
2367
|
+
if (!isResizing)
|
|
2368
|
+
e.currentTarget.style.backgroundColor = '#3b82f680';
|
|
2369
|
+
}, onMouseLeave: function (e) {
|
|
2370
|
+
if (!isResizing)
|
|
2371
|
+
e.currentTarget.style.backgroundColor = 'transparent';
|
|
2372
|
+
} }))] })) }));
|
|
2373
|
+
};
|
|
2374
|
+
var TableRowComponent = function (_a) {
|
|
2375
|
+
var attributes = _a.attributes, children = _a.children;
|
|
2376
|
+
return jsxRuntime.jsx("tr", __assign({}, attributes, { children: children }));
|
|
2377
|
+
};
|
|
2378
|
+
var TableCellComponent = function (_a) {
|
|
2379
|
+
var element = _a.element, attributes = _a.attributes, children = _a.children;
|
|
2380
|
+
var editor = slateReact.useSlateStatic();
|
|
2381
|
+
var selected = slateReact.useSelected();
|
|
2382
|
+
var focused = slateReact.useFocused();
|
|
2383
|
+
var _b = React.useState(false), showAlignMenu = _b[0], setShowAlignMenu = _b[1];
|
|
2384
|
+
var menuRef = React.useRef(null);
|
|
2385
|
+
React.useEffect(function () {
|
|
2386
|
+
var handleClickOutside = function (event) {
|
|
2387
|
+
if (menuRef.current && !menuRef.current.contains(event.target)) {
|
|
2388
|
+
setShowAlignMenu(false);
|
|
2389
|
+
}
|
|
2390
|
+
};
|
|
2391
|
+
if (showAlignMenu) {
|
|
2392
|
+
document.addEventListener('mousedown', handleClickOutside);
|
|
2393
|
+
return function () { return document.removeEventListener('mousedown', handleClickOutside); };
|
|
2394
|
+
}
|
|
2395
|
+
}, [showAlignMenu]);
|
|
2396
|
+
var handleCellAlign = function (alignment) {
|
|
2397
|
+
var path = slateReact.ReactEditor.findPath(editor, element);
|
|
2398
|
+
slate.Transforms.setNodes(editor, { align: alignment }, { at: path });
|
|
2399
|
+
setShowAlignMenu(false);
|
|
2400
|
+
};
|
|
2401
|
+
return (jsxRuntime.jsxs("td", __assign({}, attributes, { style: {
|
|
2402
|
+
border: '1px solid #e5e7eb',
|
|
2403
|
+
padding: '8px 12px',
|
|
2404
|
+
minWidth: '100px',
|
|
2405
|
+
position: 'relative',
|
|
2406
|
+
textAlign: element.align || 'left',
|
|
2407
|
+
}, children: [selected && focused && (jsxRuntime.jsxs("div", { ref: menuRef, contentEditable: false, style: {
|
|
2408
|
+
position: 'absolute',
|
|
2409
|
+
top: '4px',
|
|
2410
|
+
right: '4px',
|
|
2411
|
+
zIndex: 10,
|
|
2412
|
+
}, children: [jsxRuntime.jsx("button", { onClick: function () { return setShowAlignMenu(!showAlignMenu); }, style: {
|
|
2413
|
+
padding: '2px 6px',
|
|
2414
|
+
border: '1px solid #e5e7eb',
|
|
2415
|
+
borderRadius: '3px',
|
|
2416
|
+
backgroundColor: '#fff',
|
|
2417
|
+
cursor: 'pointer',
|
|
2418
|
+
fontSize: '11px',
|
|
2419
|
+
color: '#6b7280',
|
|
2420
|
+
display: 'flex',
|
|
2421
|
+
alignItems: 'center',
|
|
2422
|
+
gap: '4px',
|
|
2423
|
+
}, onMouseOver: function (e) { return (e.currentTarget.style.backgroundColor = '#f3f4f6'); }, onMouseOut: function (e) { return (e.currentTarget.style.backgroundColor = '#fff'); }, title: "Align cell content", children: jsxRuntime.jsx(outline.Bars3BottomLeftIcon, { style: { width: '12px', height: '12px' } }) }), showAlignMenu && (jsxRuntime.jsxs("div", { style: {
|
|
2424
|
+
position: 'absolute',
|
|
2425
|
+
top: '100%',
|
|
2426
|
+
right: '0',
|
|
2427
|
+
marginTop: '4px',
|
|
2428
|
+
backgroundColor: '#fff',
|
|
2429
|
+
border: '1px solid #e5e7eb',
|
|
2430
|
+
borderRadius: '6px',
|
|
2431
|
+
boxShadow: '0 4px 6px -1px rgba(0, 0, 0, 0.1)',
|
|
2432
|
+
padding: '4px',
|
|
2433
|
+
display: 'flex',
|
|
2434
|
+
gap: '2px',
|
|
2435
|
+
minWidth: '120px',
|
|
2436
|
+
}, children: [jsxRuntime.jsx("button", { onClick: function () { return handleCellAlign('left'); }, style: {
|
|
2437
|
+
padding: '4px 8px',
|
|
2438
|
+
border: 'none',
|
|
2439
|
+
borderRadius: '3px',
|
|
2440
|
+
backgroundColor: element.align === 'left' || !element.align ? '#e0e7ff' : 'transparent',
|
|
2441
|
+
cursor: 'pointer',
|
|
2442
|
+
display: 'flex',
|
|
2443
|
+
alignItems: 'center',
|
|
2444
|
+
justifyContent: 'center',
|
|
2445
|
+
}, onMouseOver: function (e) {
|
|
2446
|
+
if (element.align !== 'left' && element.align)
|
|
2447
|
+
e.currentTarget.style.backgroundColor = '#f3f4f6';
|
|
2448
|
+
}, onMouseOut: function (e) {
|
|
2449
|
+
e.currentTarget.style.backgroundColor = element.align === 'left' || !element.align ? '#e0e7ff' : 'transparent';
|
|
2450
|
+
}, title: "Align Left", children: jsxRuntime.jsx(outline.Bars3BottomLeftIcon, { style: { width: '16px', height: '16px' } }) }), jsxRuntime.jsx("button", { onClick: function () { return handleCellAlign('center'); }, style: {
|
|
2451
|
+
padding: '4px 8px',
|
|
2452
|
+
border: 'none',
|
|
2453
|
+
borderRadius: '3px',
|
|
2454
|
+
backgroundColor: element.align === 'center' ? '#e0e7ff' : 'transparent',
|
|
2455
|
+
cursor: 'pointer',
|
|
2456
|
+
display: 'flex',
|
|
2457
|
+
alignItems: 'center',
|
|
2458
|
+
justifyContent: 'center',
|
|
2459
|
+
}, onMouseOver: function (e) {
|
|
2460
|
+
if (element.align !== 'center')
|
|
2461
|
+
e.currentTarget.style.backgroundColor = '#f3f4f6';
|
|
2462
|
+
}, onMouseOut: function (e) {
|
|
2463
|
+
e.currentTarget.style.backgroundColor = element.align === 'center' ? '#e0e7ff' : 'transparent';
|
|
2464
|
+
}, title: "Align Center", children: jsxRuntime.jsx(outline.Bars3Icon, { style: { width: '16px', height: '16px' } }) }), jsxRuntime.jsx("button", { onClick: function () { return handleCellAlign('right'); }, style: {
|
|
2465
|
+
padding: '4px 8px',
|
|
2466
|
+
border: 'none',
|
|
2467
|
+
borderRadius: '3px',
|
|
2468
|
+
backgroundColor: element.align === 'right' ? '#e0e7ff' : 'transparent',
|
|
2469
|
+
cursor: 'pointer',
|
|
2470
|
+
display: 'flex',
|
|
2471
|
+
alignItems: 'center',
|
|
2472
|
+
justifyContent: 'center',
|
|
2473
|
+
}, onMouseOver: function (e) {
|
|
2474
|
+
if (element.align !== 'right')
|
|
2475
|
+
e.currentTarget.style.backgroundColor = '#f3f4f6';
|
|
2476
|
+
}, onMouseOut: function (e) {
|
|
2477
|
+
e.currentTarget.style.backgroundColor = element.align === 'right' ? '#e0e7ff' : 'transparent';
|
|
2478
|
+
}, title: "Align Right", children: jsxRuntime.jsx(outline.Bars3BottomRightIcon, { style: { width: '16px', height: '16px' } }) })] }))] })), children] })));
|
|
2479
|
+
};
|
|
2480
|
+
|
|
2481
|
+
// All available toolbar items in a logical grouped order
|
|
2482
|
+
var ALL_TOOLBAR_ITEMS = [
|
|
2483
|
+
'paragraph', 'heading-one', 'heading-two', 'heading-three', 'heading-four',
|
|
2484
|
+
'heading-five', 'heading-six', 'heading-seven', 'heading-eight',
|
|
2485
|
+
'separator',
|
|
2486
|
+
'bold', 'italic', 'underline', 'strikethrough',
|
|
2487
|
+
'separator',
|
|
2488
|
+
'superscript', 'subscript', 'code',
|
|
2489
|
+
'separator',
|
|
2490
|
+
'left', 'center', 'right', 'justify',
|
|
2491
|
+
'separator',
|
|
2492
|
+
'text-color', 'bg-color',
|
|
2493
|
+
'separator',
|
|
2494
|
+
'blockquote', 'code-block',
|
|
2495
|
+
'separator',
|
|
2496
|
+
'bulleted-list', 'numbered-list', 'indent', 'outdent',
|
|
2497
|
+
'separator',
|
|
2498
|
+
'link', 'image', 'table', 'horizontal-rule', 'undo', 'redo',
|
|
2499
|
+
'separator',
|
|
2500
|
+
'find-replace', 'fullscreen', 'view-output'
|
|
2501
|
+
];
|
|
2502
|
+
|
|
2503
|
+
var renderLeaf = function (_a) {
|
|
2504
|
+
var attributes = _a.attributes, children = _a.children, leaf = _a.leaf;
|
|
2505
|
+
var textLeaf = leaf;
|
|
2506
|
+
if (textLeaf.bold) {
|
|
2507
|
+
children = jsxRuntime.jsx("strong", { children: children });
|
|
2508
|
+
}
|
|
2509
|
+
if (textLeaf.italic) {
|
|
2510
|
+
children = jsxRuntime.jsx("em", { children: children });
|
|
2511
|
+
}
|
|
2512
|
+
if (textLeaf.underline) {
|
|
2513
|
+
children = jsxRuntime.jsx("u", { children: children });
|
|
2514
|
+
}
|
|
2515
|
+
if (textLeaf.strikethrough) {
|
|
2516
|
+
children = jsxRuntime.jsx("s", { children: children });
|
|
2517
|
+
}
|
|
2518
|
+
if (textLeaf.superscript) {
|
|
2519
|
+
children = jsxRuntime.jsx("sup", { children: children });
|
|
2520
|
+
}
|
|
2521
|
+
if (textLeaf.subscript) {
|
|
2522
|
+
children = jsxRuntime.jsx("sub", { children: children });
|
|
2523
|
+
}
|
|
2524
|
+
if (textLeaf.code) {
|
|
2525
|
+
children = jsxRuntime.jsx("code", { style: {
|
|
2526
|
+
backgroundColor: '#f4f4f4',
|
|
2527
|
+
padding: '2px 4px',
|
|
2528
|
+
borderRadius: '3px',
|
|
2529
|
+
fontFamily: 'monospace'
|
|
2530
|
+
}, children: children });
|
|
2531
|
+
}
|
|
2532
|
+
var style = {};
|
|
2533
|
+
if (textLeaf.color) {
|
|
2534
|
+
style.color = textLeaf.color;
|
|
2535
|
+
}
|
|
2536
|
+
if (textLeaf.backgroundColor) {
|
|
2537
|
+
style.backgroundColor = textLeaf.backgroundColor;
|
|
2538
|
+
}
|
|
2539
|
+
if (textLeaf.searchCurrent) {
|
|
2540
|
+
style.backgroundColor = '#ff9800';
|
|
2541
|
+
style.color = '#fff';
|
|
2542
|
+
}
|
|
2543
|
+
else if (textLeaf.search) {
|
|
2544
|
+
style.backgroundColor = '#ffeb3b';
|
|
2545
|
+
}
|
|
2546
|
+
return jsxRuntime.jsx("span", __assign({}, attributes, { style: Object.keys(style).length > 0 ? style : undefined, children: children }));
|
|
2547
|
+
};
|
|
2548
|
+
var parseInitialValue = function (initialValue) {
|
|
2549
|
+
if (!initialValue) {
|
|
2550
|
+
return defaultInitialValue;
|
|
2551
|
+
}
|
|
2552
|
+
if (typeof initialValue === 'string') {
|
|
2553
|
+
if (initialValue.trim() === '') {
|
|
2554
|
+
return defaultInitialValue;
|
|
2555
|
+
}
|
|
2556
|
+
return [
|
|
2557
|
+
{
|
|
2558
|
+
type: 'paragraph',
|
|
2559
|
+
children: [{ text: initialValue }],
|
|
2560
|
+
},
|
|
2561
|
+
];
|
|
2562
|
+
}
|
|
2563
|
+
return initialValue.length > 0 ? initialValue : defaultInitialValue;
|
|
2564
|
+
};
|
|
2565
|
+
var withTables = function (editor) {
|
|
2566
|
+
var normalizeNode = editor.normalizeNode;
|
|
2567
|
+
editor.normalizeNode = function (entry) {
|
|
2568
|
+
var node = entry[0], path = entry[1];
|
|
2569
|
+
if (slate.Element.isElement(node) && node.type === 'table') {
|
|
2570
|
+
for (var _i = 0, _a = Array.from(slate.Editor.nodes(editor, { at: path })); _i < _a.length; _i++) {
|
|
2571
|
+
var _b = _a[_i], child = _b[0], childPath = _b[1];
|
|
2572
|
+
if (childPath.length === path.length + 1 && slate.Element.isElement(child) && child.type !== 'table-row') {
|
|
2573
|
+
slate.Transforms.removeNodes(editor, { at: childPath });
|
|
2574
|
+
return;
|
|
2575
|
+
}
|
|
2576
|
+
}
|
|
2577
|
+
}
|
|
2578
|
+
if (slate.Element.isElement(node) && node.type === 'table-row') {
|
|
2579
|
+
for (var _c = 0, _d = Array.from(slate.Editor.nodes(editor, { at: path })); _c < _d.length; _c++) {
|
|
2580
|
+
var _e = _d[_c], child = _e[0], childPath = _e[1];
|
|
2581
|
+
if (childPath.length === path.length + 1 && slate.Element.isElement(child) && child.type !== 'table-cell') {
|
|
2582
|
+
slate.Transforms.removeNodes(editor, { at: childPath });
|
|
2583
|
+
return;
|
|
2584
|
+
}
|
|
2585
|
+
}
|
|
2586
|
+
}
|
|
2587
|
+
normalizeNode(entry);
|
|
2588
|
+
};
|
|
2589
|
+
return editor;
|
|
2590
|
+
};
|
|
2591
|
+
var Editium = function (_a) {
|
|
2592
|
+
var initialValue = _a.initialValue, onChange = _a.onChange, _b = _a.toolbar, toolbar = _b === void 0 ? ['bold', 'italic', 'underline', 'heading-one', 'heading-two', 'bulleted-list', 'numbered-list', 'link'] : _b, _c = _a.placeholder, placeholder = _c === void 0 ? 'Start typing...' : _c, _d = _a.className, className = _d === void 0 ? '' : _d, _e = _a.style, style = _e === void 0 ? {} : _e, _f = _a.readOnly, readOnly = _f === void 0 ? false : _f, onImageUpload = _a.onImageUpload, externalSearchQuery = _a.searchQuery, externalSearchMatches = _a.searchMatches, externalCurrentMatchIndex = _a.currentMatchIndex, _g = _a.showWordCount, showWordCount = _g === void 0 ? true : _g, _h = _a.height, height = _h === void 0 ? '200px' : _h, _j = _a.minHeight, minHeight = _j === void 0 ? '150px' : _j, _k = _a.maxHeight, maxHeight = _k === void 0 ? '250px' : _k;
|
|
2593
|
+
var toolbarItems = toolbar === 'all' ? ALL_TOOLBAR_ITEMS : toolbar;
|
|
2594
|
+
var editor = React.useMemo(function () { return withTables(slateHistory.withHistory(slateReact.withReact(slate.createEditor()))); }, []);
|
|
2595
|
+
var _l = React.useState(function () { return parseInitialValue(initialValue); }), value = _l[0], setValue = _l[1];
|
|
2596
|
+
var _m = React.useState(null), showOutputModal = _m[0], setShowOutputModal = _m[1];
|
|
2597
|
+
var _o = React.useState(false), copySuccess = _o[0], setCopySuccess = _o[1];
|
|
2598
|
+
var _p = React.useState(false), showLinkPopup = _p[0], setShowLinkPopup = _p[1];
|
|
2599
|
+
var _q = React.useState({ x: 0, y: 0 }), linkPopupPosition = _q[0], setLinkPopupPosition = _q[1];
|
|
2600
|
+
var _r = React.useState(null), selectedLink = _r[0], setSelectedLink = _r[1];
|
|
2601
|
+
var _s = React.useState(false), isFullscreen = _s[0], setIsFullscreen = _s[1];
|
|
2602
|
+
var _t = React.useState(''), internalSearchQuery = _t[0], setInternalSearchQuery = _t[1];
|
|
2603
|
+
var _u = React.useState([]), internalSearchMatches = _u[0], setInternalSearchMatches = _u[1];
|
|
2604
|
+
var _v = React.useState(0), internalCurrentMatchIndex = _v[0], setInternalCurrentMatchIndex = _v[1];
|
|
2605
|
+
var searchQuery = externalSearchQuery !== undefined ? externalSearchQuery : internalSearchQuery;
|
|
2606
|
+
var searchMatches = externalSearchMatches !== undefined ? externalSearchMatches : internalSearchMatches;
|
|
2607
|
+
var currentMatchIndex = externalCurrentMatchIndex !== undefined ? externalCurrentMatchIndex : internalCurrentMatchIndex;
|
|
2608
|
+
React.useEffect(function () {
|
|
2609
|
+
window.__editiumProps = { onImageUpload: onImageUpload };
|
|
2610
|
+
return function () {
|
|
2611
|
+
delete window.__editiumProps;
|
|
2612
|
+
};
|
|
2613
|
+
}, [onImageUpload]);
|
|
2614
|
+
var _w = React.useState(null), selectedLinkPath = _w[0], setSelectedLinkPath = _w[1];
|
|
2615
|
+
var handleFullscreenToggle = React.useCallback(function () {
|
|
2616
|
+
setIsFullscreen(!isFullscreen);
|
|
2617
|
+
}, [isFullscreen]);
|
|
2618
|
+
React.useEffect(function () {
|
|
2619
|
+
var handleKeyDown = function (event) {
|
|
2620
|
+
if (event.key === 'F11') {
|
|
2621
|
+
event.preventDefault();
|
|
2622
|
+
setIsFullscreen(!isFullscreen);
|
|
2623
|
+
}
|
|
2624
|
+
if (event.key === 'Escape' && isFullscreen) {
|
|
2625
|
+
event.preventDefault();
|
|
2626
|
+
setIsFullscreen(false);
|
|
2627
|
+
}
|
|
2628
|
+
};
|
|
2629
|
+
window.addEventListener('keydown', handleKeyDown);
|
|
2630
|
+
return function () { return window.removeEventListener('keydown', handleKeyDown); };
|
|
2631
|
+
}, [isFullscreen]);
|
|
2632
|
+
React.useEffect(function () {
|
|
2633
|
+
if (isFullscreen) {
|
|
2634
|
+
var originalOverflow_1 = document.body.style.overflow;
|
|
2635
|
+
document.body.style.overflow = 'hidden';
|
|
2636
|
+
return function () {
|
|
2637
|
+
document.body.style.overflow = originalOverflow_1;
|
|
2638
|
+
};
|
|
2639
|
+
}
|
|
2640
|
+
}, [isFullscreen]);
|
|
2641
|
+
// Handle keyboard shortcuts
|
|
2642
|
+
var handleKeyDown = React.useCallback(function (event) {
|
|
2643
|
+
if (event.key === 'Delete' || event.key === 'Backspace') {
|
|
2644
|
+
var selection = editor.selection;
|
|
2645
|
+
if (selection) {
|
|
2646
|
+
var imageNode = Array.from(slate.Editor.nodes(editor, {
|
|
2647
|
+
at: selection,
|
|
2648
|
+
match: function (n) {
|
|
2649
|
+
return !slate.Editor.isEditor(n) &&
|
|
2650
|
+
slate.Element.isElement(n) &&
|
|
2651
|
+
n.type === 'image';
|
|
2652
|
+
},
|
|
2653
|
+
}))[0];
|
|
2654
|
+
if (imageNode) {
|
|
2655
|
+
event.preventDefault();
|
|
2656
|
+
var imagePath = imageNode[1];
|
|
2657
|
+
slate.Transforms.removeNodes(editor, { at: imagePath });
|
|
2658
|
+
return;
|
|
2659
|
+
}
|
|
2660
|
+
if (event.key === 'Delete' && slate.Range.isCollapsed(selection)) {
|
|
2661
|
+
try {
|
|
2662
|
+
var after = slate.Editor.after(editor, selection);
|
|
2663
|
+
if (after) {
|
|
2664
|
+
var nextNode = Array.from(slate.Editor.nodes(editor, {
|
|
2665
|
+
at: after,
|
|
2666
|
+
match: function (n) {
|
|
2667
|
+
return !slate.Editor.isEditor(n) &&
|
|
2668
|
+
slate.Element.isElement(n) &&
|
|
2669
|
+
n.type === 'image';
|
|
2670
|
+
},
|
|
2671
|
+
}))[0];
|
|
2672
|
+
if (nextNode) {
|
|
2673
|
+
event.preventDefault();
|
|
2674
|
+
var nextPath = nextNode[1];
|
|
2675
|
+
slate.Transforms.removeNodes(editor, { at: nextPath });
|
|
2676
|
+
return;
|
|
2677
|
+
}
|
|
2678
|
+
}
|
|
2679
|
+
}
|
|
2680
|
+
catch (e) {
|
|
2681
|
+
// Ignore errors if we can't find next node
|
|
2682
|
+
}
|
|
2683
|
+
}
|
|
2684
|
+
}
|
|
2685
|
+
}
|
|
2686
|
+
if (!event.ctrlKey && !event.metaKey) {
|
|
2687
|
+
return;
|
|
2688
|
+
}
|
|
2689
|
+
switch (event.key) {
|
|
2690
|
+
case 'b':
|
|
2691
|
+
event.preventDefault();
|
|
2692
|
+
toggleMark(editor, 'bold');
|
|
2693
|
+
break;
|
|
2694
|
+
case 'i':
|
|
2695
|
+
event.preventDefault();
|
|
2696
|
+
toggleMark(editor, 'italic');
|
|
2697
|
+
break;
|
|
2698
|
+
case 'u':
|
|
2699
|
+
event.preventDefault();
|
|
2700
|
+
toggleMark(editor, 'underline');
|
|
2701
|
+
break;
|
|
2702
|
+
case '`':
|
|
2703
|
+
event.preventDefault();
|
|
2704
|
+
toggleMark(editor, 'code');
|
|
2705
|
+
break;
|
|
2706
|
+
case 'd':
|
|
2707
|
+
event.preventDefault();
|
|
2708
|
+
toggleMark(editor, 'strikethrough');
|
|
2709
|
+
break;
|
|
2710
|
+
case 'z':
|
|
2711
|
+
if (event.shiftKey) {
|
|
2712
|
+
event.preventDefault();
|
|
2713
|
+
slateHistory.HistoryEditor.redo(editor);
|
|
2714
|
+
}
|
|
2715
|
+
else {
|
|
2716
|
+
event.preventDefault();
|
|
2717
|
+
slateHistory.HistoryEditor.undo(editor);
|
|
2718
|
+
}
|
|
2719
|
+
break;
|
|
2720
|
+
case 'y':
|
|
2721
|
+
event.preventDefault();
|
|
2722
|
+
slateHistory.HistoryEditor.redo(editor);
|
|
2723
|
+
break;
|
|
2724
|
+
}
|
|
2725
|
+
}, [editor]);
|
|
2726
|
+
var handleChange = React.useCallback(function (newValue) {
|
|
2727
|
+
setValue(newValue);
|
|
2728
|
+
if (onChange) {
|
|
2729
|
+
var htmlValue = serializeToHtml(newValue);
|
|
2730
|
+
onChange(htmlValue, newValue);
|
|
2731
|
+
}
|
|
2732
|
+
}, [onChange]);
|
|
2733
|
+
var textContent = React.useMemo(function () { return getTextContent(editor.children); }, [editor.children]);
|
|
2734
|
+
var wordCount = React.useMemo(function () { return countWords(textContent); }, [textContent]);
|
|
2735
|
+
var charCount = React.useMemo(function () { return countCharacters(textContent); }, [textContent]);
|
|
2736
|
+
var charCountNoSpaces = React.useMemo(function () { return countCharactersNoSpaces(textContent); }, [textContent]);
|
|
2737
|
+
React.useEffect(function () {
|
|
2738
|
+
if (initialValue !== undefined) {
|
|
2739
|
+
var parsedValue = parseInitialValue(initialValue);
|
|
2740
|
+
setValue(parsedValue);
|
|
2741
|
+
}
|
|
2742
|
+
}, [initialValue]);
|
|
2743
|
+
var handleCopy = React.useCallback(function () {
|
|
2744
|
+
var currentValue = editor.children;
|
|
2745
|
+
var textToCopy = showOutputModal === 'html'
|
|
2746
|
+
? serializeToHtml(currentValue)
|
|
2747
|
+
: JSON.stringify(currentValue, null, 2);
|
|
2748
|
+
navigator.clipboard.writeText(textToCopy).then(function () {
|
|
2749
|
+
setCopySuccess(true);
|
|
2750
|
+
setTimeout(function () { return setCopySuccess(false); }, 2000);
|
|
2751
|
+
});
|
|
2752
|
+
}, [showOutputModal, editor]);
|
|
2753
|
+
var handleLinkClick = React.useCallback(function (event, linkElement) {
|
|
2754
|
+
event.preventDefault();
|
|
2755
|
+
var linkEntry = Array.from(slate.Editor.nodes(editor, {
|
|
2756
|
+
match: function (n) { return n.type === 'link' && n.url === linkElement.url; },
|
|
2757
|
+
}))[0];
|
|
2758
|
+
if (linkEntry) {
|
|
2759
|
+
linkEntry[0]; var path = linkEntry[1];
|
|
2760
|
+
setSelectedLinkPath(path);
|
|
2761
|
+
}
|
|
2762
|
+
var rect = event.target.getBoundingClientRect();
|
|
2763
|
+
setLinkPopupPosition({
|
|
2764
|
+
x: rect.left + window.scrollX,
|
|
2765
|
+
y: rect.bottom + window.scrollY + 5
|
|
2766
|
+
});
|
|
2767
|
+
setSelectedLink(linkElement);
|
|
2768
|
+
setShowLinkPopup(true);
|
|
2769
|
+
}, [editor]);
|
|
2770
|
+
var decorate = React.useCallback(function (_a) {
|
|
2771
|
+
var node = _a[0], path = _a[1];
|
|
2772
|
+
var ranges = [];
|
|
2773
|
+
if (searchQuery && searchMatches.length > 0 && slate.Text.isText(node)) {
|
|
2774
|
+
searchMatches.forEach(function (match, index) {
|
|
2775
|
+
if (JSON.stringify(match.path) === JSON.stringify(path)) {
|
|
2776
|
+
ranges.push({
|
|
2777
|
+
anchor: { path: path, offset: match.offset },
|
|
2778
|
+
focus: { path: path, offset: match.offset + match.text.length },
|
|
2779
|
+
search: true,
|
|
2780
|
+
searchCurrent: index === currentMatchIndex,
|
|
2781
|
+
});
|
|
2782
|
+
}
|
|
2783
|
+
});
|
|
2784
|
+
}
|
|
2785
|
+
return ranges;
|
|
2786
|
+
}, [searchQuery, searchMatches, currentMatchIndex]);
|
|
2787
|
+
var renderElementWithHandlers = React.useCallback(function (props) {
|
|
2788
|
+
var attributes = props.attributes, children = props.children, element = props.element;
|
|
2789
|
+
var style = { margin: '0', fontWeight: 'normal' };
|
|
2790
|
+
var alignStyle = element.align ? {
|
|
2791
|
+
textAlign: element.align
|
|
2792
|
+
} : {};
|
|
2793
|
+
var combinedStyle = __assign(__assign({}, style), alignStyle);
|
|
2794
|
+
switch (element.type) {
|
|
2795
|
+
case 'paragraph':
|
|
2796
|
+
return jsxRuntime.jsx("p", __assign({}, attributes, { style: combinedStyle, children: children }));
|
|
2797
|
+
case 'heading-one':
|
|
2798
|
+
return jsxRuntime.jsx("h1", __assign({}, attributes, { style: __assign(__assign({}, combinedStyle), { fontSize: '2em', margin: '0' }), children: children }));
|
|
2799
|
+
case 'heading-two':
|
|
2800
|
+
return jsxRuntime.jsx("h2", __assign({}, attributes, { style: __assign(__assign({}, combinedStyle), { fontSize: '1.5em', margin: '0' }), children: children }));
|
|
2801
|
+
case 'heading-three':
|
|
2802
|
+
return jsxRuntime.jsx("h3", __assign({}, attributes, { style: __assign(__assign({}, combinedStyle), { fontSize: '1.25em', margin: '0' }), children: children }));
|
|
2803
|
+
case 'heading-four':
|
|
2804
|
+
return jsxRuntime.jsx("h4", __assign({}, attributes, { style: __assign(__assign({}, combinedStyle), { fontSize: '1.1em', margin: '0' }), children: children }));
|
|
2805
|
+
case 'heading-five':
|
|
2806
|
+
return jsxRuntime.jsx("h5", __assign({}, attributes, { style: __assign(__assign({}, combinedStyle), { fontSize: '1em', margin: '0' }), children: children }));
|
|
2807
|
+
case 'heading-six':
|
|
2808
|
+
return jsxRuntime.jsx("h6", __assign({}, attributes, { style: __assign(__assign({}, combinedStyle), { fontSize: '0.9em', margin: '0' }), children: children }));
|
|
2809
|
+
case 'heading-seven':
|
|
2810
|
+
return jsxRuntime.jsx("h1", __assign({}, attributes, { style: __assign(__assign({}, combinedStyle), { fontSize: '0.85em', margin: '0' }), children: children }));
|
|
2811
|
+
case 'heading-eight':
|
|
2812
|
+
return jsxRuntime.jsx("h1", __assign({}, attributes, { style: __assign(__assign({}, combinedStyle), { fontSize: '0.8em', margin: '0' }), children: children }));
|
|
2813
|
+
case 'bulleted-list':
|
|
2814
|
+
return jsxRuntime.jsx("ul", __assign({}, attributes, { style: __assign(__assign({}, style), { margin: '0' }), children: children }));
|
|
2815
|
+
case 'numbered-list':
|
|
2816
|
+
return jsxRuntime.jsx("ol", __assign({}, attributes, { style: __assign(__assign({}, style), { margin: '0' }), children: children }));
|
|
2817
|
+
case 'list-item':
|
|
2818
|
+
return jsxRuntime.jsx("li", __assign({}, attributes, { children: children }));
|
|
2819
|
+
case 'blockquote':
|
|
2820
|
+
return (jsxRuntime.jsx("blockquote", __assign({}, attributes, { style: __assign(__assign({}, combinedStyle), { borderLeft: '4px solid #ddd', paddingLeft: '16px', marginLeft: '0', marginRight: '0', color: '#666', fontStyle: 'italic' }), children: children })));
|
|
2821
|
+
case 'code-block':
|
|
2822
|
+
return (jsxRuntime.jsx("pre", __assign({}, attributes, { style: {
|
|
2823
|
+
backgroundColor: '#f5f5f5',
|
|
2824
|
+
padding: '16px',
|
|
2825
|
+
borderRadius: '4px',
|
|
2826
|
+
overflow: 'auto',
|
|
2827
|
+
fontFamily: 'monospace',
|
|
2828
|
+
fontSize: '14px',
|
|
2829
|
+
lineHeight: '1.5',
|
|
2830
|
+
margin: '0'
|
|
2831
|
+
}, children: jsxRuntime.jsx("code", { children: children }) })));
|
|
2832
|
+
case 'horizontal-rule':
|
|
2833
|
+
return (jsxRuntime.jsxs("div", __assign({}, attributes, { contentEditable: false, style: { userSelect: 'none' }, children: [jsxRuntime.jsx("hr", { style: {
|
|
2834
|
+
border: 'none',
|
|
2835
|
+
borderTop: '2px solid #ddd',
|
|
2836
|
+
margin: '16px 0'
|
|
2837
|
+
} }), children] })));
|
|
2838
|
+
case 'image':
|
|
2839
|
+
var imageElement = element;
|
|
2840
|
+
return jsxRuntime.jsx(ResizableImage, { element: imageElement, attributes: attributes, children: children });
|
|
2841
|
+
case 'table':
|
|
2842
|
+
var tableElement = element;
|
|
2843
|
+
return jsxRuntime.jsx(TableComponent, { element: tableElement, attributes: attributes, children: children });
|
|
2844
|
+
case 'table-row':
|
|
2845
|
+
var tableRowElement = element;
|
|
2846
|
+
return jsxRuntime.jsx(TableRowComponent, { element: tableRowElement, attributes: attributes, children: children });
|
|
2847
|
+
case 'table-cell':
|
|
2848
|
+
var tableCellElement = element;
|
|
2849
|
+
return jsxRuntime.jsx(TableCellComponent, { element: tableCellElement, attributes: attributes, children: children });
|
|
2850
|
+
case 'link':
|
|
2851
|
+
var linkElement_1 = element;
|
|
2852
|
+
return (jsxRuntime.jsx("a", __assign({}, attributes, { href: linkElement_1.url, title: linkElement_1.title, onClick: function (e) { return handleLinkClick(e, linkElement_1); }, style: {
|
|
2853
|
+
color: '#0066cc',
|
|
2854
|
+
textDecoration: 'underline',
|
|
2855
|
+
cursor: 'pointer'
|
|
2856
|
+
}, children: children })));
|
|
2857
|
+
default:
|
|
2858
|
+
return jsxRuntime.jsx("p", __assign({}, attributes, { style: combinedStyle, children: children }));
|
|
2859
|
+
}
|
|
2860
|
+
}, [handleLinkClick]);
|
|
2861
|
+
var handleOpenLink = React.useCallback(function () {
|
|
2862
|
+
if (selectedLink) {
|
|
2863
|
+
window.open(selectedLink.url, selectedLink.target || '_self');
|
|
2864
|
+
setShowLinkPopup(false);
|
|
2865
|
+
}
|
|
2866
|
+
}, [selectedLink]);
|
|
2867
|
+
var handleRemoveLink = React.useCallback(function () {
|
|
2868
|
+
if (selectedLink) {
|
|
2869
|
+
var linkEntries = Array.from(slate.Editor.nodes(editor, {
|
|
2870
|
+
match: function (n) {
|
|
2871
|
+
return !slate.Editor.isEditor(n) &&
|
|
2872
|
+
slate.Element.isElement(n) &&
|
|
2873
|
+
n.type === 'link' &&
|
|
2874
|
+
n.url === selectedLink.url;
|
|
2875
|
+
},
|
|
2876
|
+
}));
|
|
2877
|
+
if (linkEntries.length > 0) {
|
|
2878
|
+
var _a = linkEntries[0], linkNode = _a[0], linkPath = _a[1];
|
|
2879
|
+
var link = linkNode;
|
|
2880
|
+
if (linkPath.length === 1) {
|
|
2881
|
+
var textChildren = link.children;
|
|
2882
|
+
slate.Transforms.removeNodes(editor, { at: linkPath });
|
|
2883
|
+
slate.Transforms.insertNodes(editor, {
|
|
2884
|
+
type: 'paragraph',
|
|
2885
|
+
children: textChildren,
|
|
2886
|
+
}, {
|
|
2887
|
+
at: linkPath,
|
|
2888
|
+
});
|
|
2889
|
+
}
|
|
2890
|
+
else {
|
|
2891
|
+
slate.Transforms.unwrapNodes(editor, {
|
|
2892
|
+
at: linkPath,
|
|
2893
|
+
});
|
|
2894
|
+
}
|
|
2895
|
+
}
|
|
2896
|
+
setShowLinkPopup(false);
|
|
2897
|
+
}
|
|
2898
|
+
}, [selectedLink, editor]);
|
|
2899
|
+
var handleEditLink = React.useCallback(function () {
|
|
2900
|
+
if (selectedLink && selectedLinkPath) {
|
|
2901
|
+
var linkText = slate.Editor.string(editor, selectedLinkPath);
|
|
2902
|
+
if (window.__editiumLinkEditHandler) {
|
|
2903
|
+
window.__editiumLinkEditHandler({
|
|
2904
|
+
url: selectedLink.url,
|
|
2905
|
+
title: selectedLink.title,
|
|
2906
|
+
target: selectedLink.target,
|
|
2907
|
+
text: linkText,
|
|
2908
|
+
path: selectedLinkPath
|
|
2909
|
+
});
|
|
2910
|
+
}
|
|
2911
|
+
}
|
|
2912
|
+
setShowLinkPopup(false);
|
|
2913
|
+
}, [selectedLink, selectedLinkPath, editor]);
|
|
2914
|
+
var formatHtml = React.useCallback(function (html) {
|
|
2915
|
+
var formatted = '';
|
|
2916
|
+
var indent = 0;
|
|
2917
|
+
var tab = ' ';
|
|
2918
|
+
html.split(/(<[^>]+>)/g).forEach(function (part) {
|
|
2919
|
+
if (part.trim() === '')
|
|
2920
|
+
return;
|
|
2921
|
+
if (part.startsWith('</')) {
|
|
2922
|
+
indent--;
|
|
2923
|
+
formatted += tab.repeat(Math.max(0, indent)) + part + '\n';
|
|
2924
|
+
}
|
|
2925
|
+
else if (part.startsWith('<')) {
|
|
2926
|
+
formatted += tab.repeat(indent) + part + '\n';
|
|
2927
|
+
if (!part.includes('</') && !part.endsWith('/>')) {
|
|
2928
|
+
indent++;
|
|
2929
|
+
}
|
|
2930
|
+
}
|
|
2931
|
+
else {
|
|
2932
|
+
formatted += tab.repeat(indent) + part.trim() + '\n';
|
|
2933
|
+
}
|
|
2934
|
+
});
|
|
2935
|
+
return formatted.trim();
|
|
2936
|
+
}, []);
|
|
2937
|
+
var editorStyle = __assign({ border: '1px solid #ccc', borderTop: 'none', borderRadius: toolbar.length > 0 ? '0' : '4px 4px 0 0', borderBottom: 'none', padding: '16px', height: typeof height === 'number' ? "".concat(height, "px") : height, minHeight: typeof minHeight === 'number' ? "".concat(minHeight, "px") : minHeight, maxHeight: typeof maxHeight === 'number' ? "".concat(maxHeight, "px") : maxHeight, fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif', fontSize: '14px', lineHeight: '1.6', outline: 'none', backgroundColor: '#fff', position: 'relative', overflow: 'auto' }, style);
|
|
2938
|
+
var containerStyle = isFullscreen ? {
|
|
2939
|
+
position: 'fixed',
|
|
2940
|
+
top: 0,
|
|
2941
|
+
left: 0,
|
|
2942
|
+
right: 0,
|
|
2943
|
+
bottom: 0,
|
|
2944
|
+
zIndex: 9999,
|
|
2945
|
+
backgroundColor: '#fff',
|
|
2946
|
+
display: 'flex',
|
|
2947
|
+
flexDirection: 'column',
|
|
2948
|
+
overflow: 'hidden',
|
|
2949
|
+
} : {};
|
|
2950
|
+
var editableStyle = isFullscreen ? __assign(__assign({}, editorStyle), { flex: 1, overflow: 'auto', border: 'none', borderRadius: 0,
|
|
2951
|
+
// Remove height constraints in fullscreen mode
|
|
2952
|
+
height: 'auto', minHeight: 'auto', maxHeight: 'none' }) : editorStyle;
|
|
2953
|
+
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("style", { children: "\n [data-slate-editor] {\n position: relative;\n min-height: inherit;\n height: 100%;\n }\n \n /* Custom scrollbar styling for better UX */\n [data-slate-editor]::-webkit-scrollbar {\n width: 8px;\n height: 8px;\n }\n \n [data-slate-editor]::-webkit-scrollbar-track {\n background: #f1f1f1;\n border-radius: 4px;\n }\n \n [data-slate-editor]::-webkit-scrollbar-thumb {\n background: #c1c1c1;\n border-radius: 4px;\n }\n \n [data-slate-editor]::-webkit-scrollbar-thumb:hover {\n background: #a8a8a8;\n }\n \n [data-slate-editor] [data-slate-placeholder] {\n opacity: 0.333;\n pointer-events: none;\n user-select: none;\n display: inline-block !important;\n width: 100%;\n max-width: 100%;\n white-space: nowrap;\n margin: 0 !important;\n vertical-align: text-top;\n }\n \n [data-slate-editor] p,\n [data-slate-editor] h1,\n [data-slate-editor] h2,\n [data-slate-editor] h3,\n [data-slate-editor] h4,\n [data-slate-editor] h5,\n [data-slate-editor] h6 {\n position: relative;\n }\n \n [data-slate-editor] [contenteditable=\"true\"] {\n outline: none;\n position: relative;\n z-index: 1;\n }\n \n [data-slate-editor] > * {\n margin: 0 !important;\n line-height: 1.6;\n }\n \n [data-slate-editor] p {\n margin: 0 !important;\n line-height: 1.6;\n }\n \n [data-slate-editor] h1,\n [data-slate-editor] h2,\n [data-slate-editor] h3,\n [data-slate-editor] h4,\n [data-slate-editor] h5,\n [data-slate-editor] h6 {\n margin: 0 !important;\n line-height: 1.6;\n }\n \n [data-slate-editor] ul,\n [data-slate-editor] ol {\n margin: 0 !important;\n padding-left: 24px;\n }\n " }), jsxRuntime.jsxs("div", { className: className, style: containerStyle, children: [showLinkPopup && (jsxRuntime.jsx("div", { style: {
|
|
2954
|
+
position: 'fixed',
|
|
2955
|
+
top: 0,
|
|
2956
|
+
left: 0,
|
|
2957
|
+
right: 0,
|
|
2958
|
+
bottom: 0,
|
|
2959
|
+
zIndex: 9998,
|
|
2960
|
+
}, onClick: function () { return setShowLinkPopup(false); }, children: jsxRuntime.jsxs("div", { style: {
|
|
2961
|
+
position: 'absolute',
|
|
2962
|
+
top: "".concat(linkPopupPosition.y, "px"),
|
|
2963
|
+
left: "".concat(linkPopupPosition.x, "px"),
|
|
2964
|
+
backgroundColor: '#ffffff',
|
|
2965
|
+
border: '1px solid #d1d5db',
|
|
2966
|
+
borderRadius: '8px',
|
|
2967
|
+
boxShadow: '0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)',
|
|
2968
|
+
minWidth: '200px',
|
|
2969
|
+
overflow: 'hidden',
|
|
2970
|
+
zIndex: 9999,
|
|
2971
|
+
}, onClick: function (e) { return e.stopPropagation(); }, children: [selectedLink && (jsxRuntime.jsxs("div", { style: { padding: '8px 12px', borderBottom: '1px solid #e5e7eb', backgroundColor: '#f9fafb' }, children: [jsxRuntime.jsx("div", { style: { fontSize: '12px', color: '#6b7280', marginBottom: '4px' }, children: "Link URL:" }), jsxRuntime.jsx("div", { style: {
|
|
2972
|
+
fontSize: '13px',
|
|
2973
|
+
color: '#111827',
|
|
2974
|
+
wordBreak: 'break-all',
|
|
2975
|
+
fontFamily: 'monospace'
|
|
2976
|
+
}, children: selectedLink.url })] })), jsxRuntime.jsxs("button", { onClick: handleOpenLink, style: {
|
|
2977
|
+
width: '100%',
|
|
2978
|
+
padding: '12px 16px',
|
|
2979
|
+
border: 'none',
|
|
2980
|
+
backgroundColor: 'transparent',
|
|
2981
|
+
color: '#374151',
|
|
2982
|
+
fontSize: '14px',
|
|
2983
|
+
textAlign: 'left',
|
|
2984
|
+
cursor: 'pointer',
|
|
2985
|
+
display: 'flex',
|
|
2986
|
+
alignItems: 'center',
|
|
2987
|
+
gap: '10px',
|
|
2988
|
+
fontWeight: '500',
|
|
2989
|
+
}, onMouseEnter: function (e) { return e.currentTarget.style.backgroundColor = '#f3f4f6'; }, onMouseLeave: function (e) { return e.currentTarget.style.backgroundColor = 'transparent'; }, children: [jsxRuntime.jsx("svg", { style: { width: '16px', height: '16px' }, fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: jsxRuntime.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14" }) }), "Open Link"] }), jsxRuntime.jsxs("button", { onClick: handleEditLink, style: {
|
|
2990
|
+
width: '100%',
|
|
2991
|
+
padding: '12px 16px',
|
|
2992
|
+
border: 'none',
|
|
2993
|
+
backgroundColor: 'transparent',
|
|
2994
|
+
color: '#374151',
|
|
2995
|
+
fontSize: '14px',
|
|
2996
|
+
textAlign: 'left',
|
|
2997
|
+
cursor: 'pointer',
|
|
2998
|
+
display: 'flex',
|
|
2999
|
+
alignItems: 'center',
|
|
3000
|
+
gap: '10px',
|
|
3001
|
+
fontWeight: '500',
|
|
3002
|
+
}, onMouseEnter: function (e) { return e.currentTarget.style.backgroundColor = '#f3f4f6'; }, onMouseLeave: function (e) { return e.currentTarget.style.backgroundColor = 'transparent'; }, children: [jsxRuntime.jsx("svg", { style: { width: '16px', height: '16px' }, fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: jsxRuntime.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z" }) }), "Edit Link"] }), jsxRuntime.jsxs("button", { onClick: handleRemoveLink, style: {
|
|
3003
|
+
width: '100%',
|
|
3004
|
+
padding: '12px 16px',
|
|
3005
|
+
border: 'none',
|
|
3006
|
+
borderTop: '1px solid #e5e7eb',
|
|
3007
|
+
backgroundColor: 'transparent',
|
|
3008
|
+
color: '#ef4444',
|
|
3009
|
+
fontSize: '14px',
|
|
3010
|
+
textAlign: 'left',
|
|
3011
|
+
cursor: 'pointer',
|
|
3012
|
+
display: 'flex',
|
|
3013
|
+
alignItems: 'center',
|
|
3014
|
+
gap: '10px',
|
|
3015
|
+
fontWeight: '500',
|
|
3016
|
+
}, onMouseEnter: function (e) { return e.currentTarget.style.backgroundColor = '#fef2f2'; }, onMouseLeave: function (e) { return e.currentTarget.style.backgroundColor = 'transparent'; }, children: [jsxRuntime.jsx("svg", { style: { width: '16px', height: '16px' }, fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: jsxRuntime.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" }) }), "Remove Link"] })] }) })), jsxRuntime.jsxs(slateReact.Slate, { editor: editor, initialValue: value, onValueChange: handleChange, children: [toolbarItems.length > 0 && (jsxRuntime.jsx(Toolbar, { items: toolbarItems, onViewOutput: function (type) { return setShowOutputModal(type); }, onEditLink: function () { }, searchQuery: searchQuery, searchMatches: searchMatches, currentMatchIndex: currentMatchIndex, onSearchQueryChange: setInternalSearchQuery, onSearchMatchesChange: setInternalSearchMatches, onCurrentMatchIndexChange: setInternalCurrentMatchIndex, isFullscreen: isFullscreen, onFullscreenToggle: handleFullscreenToggle })), jsxRuntime.jsx(slateReact.Editable, { renderElement: renderElementWithHandlers, renderLeaf: renderLeaf, decorate: decorate, placeholder: placeholder, onKeyDown: handleKeyDown, readOnly: readOnly, style: editableStyle })] }), jsxRuntime.jsxs("div", { style: {
|
|
3017
|
+
padding: '8px 12px',
|
|
3018
|
+
backgroundColor: '#f9fafb',
|
|
3019
|
+
borderTop: '1px solid #e5e7eb',
|
|
3020
|
+
borderLeft: isFullscreen ? 'none' : '1px solid #ccc',
|
|
3021
|
+
borderRight: isFullscreen ? 'none' : '1px solid #ccc',
|
|
3022
|
+
borderBottom: isFullscreen ? 'none' : '1px solid #ccc',
|
|
3023
|
+
borderRadius: isFullscreen ? '0' : '0 0 4px 4px',
|
|
3024
|
+
display: 'flex',
|
|
3025
|
+
justifyContent: showWordCount ? 'space-between' : 'flex-end',
|
|
3026
|
+
alignItems: 'center',
|
|
3027
|
+
gap: '20px',
|
|
3028
|
+
fontSize: '12px',
|
|
3029
|
+
color: '#6b7280',
|
|
3030
|
+
fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
|
|
3031
|
+
}, children: [showWordCount && (jsxRuntime.jsxs("div", { style: { display: 'flex', gap: '20px' }, children: [jsxRuntime.jsxs("div", { style: { display: 'flex', alignItems: 'center', gap: '6px' }, children: [jsxRuntime.jsx("span", { style: { fontWeight: '500', color: '#374151' }, children: "Words:" }), jsxRuntime.jsx("span", { style: { fontWeight: '600', color: '#111827' }, children: wordCount.toLocaleString() })] }), jsxRuntime.jsxs("div", { style: { display: 'flex', alignItems: 'center', gap: '6px' }, children: [jsxRuntime.jsx("span", { style: { fontWeight: '500', color: '#374151' }, children: "Characters:" }), jsxRuntime.jsx("span", { style: { fontWeight: '600', color: '#111827' }, children: charCount.toLocaleString() })] }), jsxRuntime.jsxs("div", { style: { display: 'flex', alignItems: 'center', gap: '6px' }, children: [jsxRuntime.jsx("span", { style: { fontWeight: '500', color: '#374151' }, children: "Characters (no spaces):" }), jsxRuntime.jsx("span", { style: { fontWeight: '600', color: '#111827' }, children: charCountNoSpaces.toLocaleString() })] })] })), jsxRuntime.jsxs("div", { style: {
|
|
3032
|
+
display: 'flex',
|
|
3033
|
+
alignItems: 'center',
|
|
3034
|
+
gap: '6px',
|
|
3035
|
+
color: '#9ca3af',
|
|
3036
|
+
fontSize: '11px',
|
|
3037
|
+
}, children: [jsxRuntime.jsx("span", { children: "Built with" }), jsxRuntime.jsx("span", { style: {
|
|
3038
|
+
fontWeight: '600',
|
|
3039
|
+
color: '#3b82f6',
|
|
3040
|
+
letterSpacing: '0.5px',
|
|
3041
|
+
cursor: 'pointer',
|
|
3042
|
+
}, onClick: function (e) {
|
|
3043
|
+
e.preventDefault();
|
|
3044
|
+
window.open('https://www.npmjs.com/package/editium', '_blank');
|
|
3045
|
+
}, children: "Editium" })] })] }), showOutputModal && (jsxRuntime.jsx("div", { style: {
|
|
3046
|
+
position: 'fixed',
|
|
3047
|
+
top: 0,
|
|
3048
|
+
left: 0,
|
|
3049
|
+
right: 0,
|
|
3050
|
+
bottom: 0,
|
|
3051
|
+
backgroundColor: 'rgba(0, 0, 0, 0.5)',
|
|
3052
|
+
display: 'flex',
|
|
3053
|
+
alignItems: 'center',
|
|
3054
|
+
justifyContent: 'center',
|
|
3055
|
+
zIndex: 10000,
|
|
3056
|
+
}, onClick: function () {
|
|
3057
|
+
setShowOutputModal(null);
|
|
3058
|
+
setCopySuccess(false);
|
|
3059
|
+
}, children: jsxRuntime.jsxs("div", { style: {
|
|
3060
|
+
backgroundColor: '#ffffff',
|
|
3061
|
+
borderRadius: '8px',
|
|
3062
|
+
padding: '24px',
|
|
3063
|
+
maxWidth: '900px',
|
|
3064
|
+
maxHeight: '85vh',
|
|
3065
|
+
width: '90%',
|
|
3066
|
+
overflow: 'hidden',
|
|
3067
|
+
boxShadow: '0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04)',
|
|
3068
|
+
display: 'flex',
|
|
3069
|
+
flexDirection: 'column',
|
|
3070
|
+
}, onClick: function (e) { return e.stopPropagation(); }, children: [jsxRuntime.jsxs("div", { style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: '16px' }, children: [jsxRuntime.jsx("h2", { style: { margin: 0, color: '#111827', fontSize: '24px', fontWeight: '600' }, children: showOutputModal === 'html' ? 'HTML Output' : showOutputModal === 'json' ? 'JSON Output' : 'Preview' }), jsxRuntime.jsxs("div", { style: { display: 'flex', gap: '8px', alignItems: 'center' }, children: [showOutputModal !== 'preview' && (jsxRuntime.jsx("button", { onClick: handleCopy, style: {
|
|
3071
|
+
backgroundColor: copySuccess ? '#10b981' : '#3b82f6',
|
|
3072
|
+
color: '#ffffff',
|
|
3073
|
+
border: 'none',
|
|
3074
|
+
borderRadius: '6px',
|
|
3075
|
+
padding: '8px 16px',
|
|
3076
|
+
fontSize: '14px',
|
|
3077
|
+
fontWeight: '500',
|
|
3078
|
+
cursor: 'pointer',
|
|
3079
|
+
transition: 'all 0.2s ease-in-out',
|
|
3080
|
+
display: 'flex',
|
|
3081
|
+
alignItems: 'center',
|
|
3082
|
+
gap: '6px',
|
|
3083
|
+
}, onMouseEnter: function (e) {
|
|
3084
|
+
if (!copySuccess) {
|
|
3085
|
+
e.currentTarget.style.backgroundColor = '#2563eb';
|
|
3086
|
+
}
|
|
3087
|
+
}, onMouseLeave: function (e) {
|
|
3088
|
+
if (!copySuccess) {
|
|
3089
|
+
e.currentTarget.style.backgroundColor = '#3b82f6';
|
|
3090
|
+
}
|
|
3091
|
+
}, title: "Copy to clipboard", children: copySuccess ? (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("svg", { style: { width: '16px', height: '16px' }, fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: jsxRuntime.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M5 13l4 4L19 7" }) }), "Copied!"] })) : (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("svg", { style: { width: '16px', height: '16px' }, fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: jsxRuntime.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z" }) }), "Copy"] })) })), jsxRuntime.jsx("button", { onClick: function () {
|
|
3092
|
+
setShowOutputModal(null);
|
|
3093
|
+
setCopySuccess(false);
|
|
3094
|
+
}, style: {
|
|
3095
|
+
background: 'none',
|
|
3096
|
+
border: 'none',
|
|
3097
|
+
fontSize: '24px',
|
|
3098
|
+
cursor: 'pointer',
|
|
3099
|
+
color: '#6b7280',
|
|
3100
|
+
padding: '4px',
|
|
3101
|
+
lineHeight: 1,
|
|
3102
|
+
}, title: "Close", children: "\u00D7" })] })] }), jsxRuntime.jsx("div", { style: {
|
|
3103
|
+
flex: 1,
|
|
3104
|
+
overflow: 'auto',
|
|
3105
|
+
backgroundColor: showOutputModal === 'preview' ? '#ffffff' : '#1e293b',
|
|
3106
|
+
borderRadius: '6px',
|
|
3107
|
+
border: showOutputModal === 'preview' ? '1px solid #e5e7eb' : '1px solid #334155',
|
|
3108
|
+
padding: showOutputModal === 'preview' ? '20px' : '0',
|
|
3109
|
+
}, children: showOutputModal === 'preview' ? (jsxRuntime.jsx("div", { dangerouslySetInnerHTML: { __html: serializeToHtml(editor.children) }, style: {
|
|
3110
|
+
fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
|
|
3111
|
+
fontSize: '16px',
|
|
3112
|
+
lineHeight: '1.6',
|
|
3113
|
+
color: '#111827',
|
|
3114
|
+
} })) : (jsxRuntime.jsx("pre", { style: {
|
|
3115
|
+
margin: 0,
|
|
3116
|
+
padding: '20px',
|
|
3117
|
+
fontSize: '13px',
|
|
3118
|
+
lineHeight: '1.6',
|
|
3119
|
+
fontFamily: 'Consolas, Monaco, "Courier New", monospace',
|
|
3120
|
+
color: '#e2e8f0',
|
|
3121
|
+
overflowX: 'auto',
|
|
3122
|
+
whiteSpace: 'pre-wrap',
|
|
3123
|
+
wordBreak: 'break-word',
|
|
3124
|
+
}, children: jsxRuntime.jsx("code", { children: showOutputModal === 'html'
|
|
3125
|
+
? formatHtml(serializeToHtml(editor.children))
|
|
3126
|
+
: JSON.stringify(editor.children, null, 2) }) })) })] }) }))] })] }));
|
|
3127
|
+
};
|
|
3128
|
+
|
|
3129
|
+
exports.ALL_TOOLBAR_ITEMS = ALL_TOOLBAR_ITEMS;
|
|
3130
|
+
exports.Editium = Editium;
|
|
3131
|
+
exports.ResizableImage = ResizableImage;
|
|
3132
|
+
exports.TableCellComponent = TableCellComponent;
|
|
3133
|
+
exports.TableComponent = TableComponent;
|
|
3134
|
+
exports.TableRowComponent = TableRowComponent;
|
|
3135
|
+
exports.addTableColumn = addTableColumn;
|
|
3136
|
+
exports.addTableRow = addTableRow;
|
|
3137
|
+
exports.defaultInitialValue = defaultInitialValue;
|
|
3138
|
+
exports.findAllMatches = findAllMatches;
|
|
3139
|
+
exports.insertLink = insertLink;
|
|
3140
|
+
exports.insertTable = insertTable;
|
|
3141
|
+
exports.isBlockActive = isBlockActive;
|
|
3142
|
+
exports.isInTable = isInTable;
|
|
3143
|
+
exports.isLinkActive = isLinkActive;
|
|
3144
|
+
exports.isMarkActive = isMarkActive;
|
|
3145
|
+
exports.navigateToMatch = navigateToMatch;
|
|
3146
|
+
exports.removeTableColumn = removeTableColumn;
|
|
3147
|
+
exports.removeTableRow = removeTableRow;
|
|
3148
|
+
exports.replaceAllMatches = replaceAllMatches;
|
|
3149
|
+
exports.replaceMatch = replaceMatch;
|
|
3150
|
+
exports.serializeToHtml = serializeToHtml;
|
|
3151
|
+
exports.setTableAlignment = setTableAlignment;
|
|
3152
|
+
exports.toggleBlock = toggleBlock;
|
|
3153
|
+
exports.toggleMark = toggleMark;
|
|
3154
|
+
//# sourceMappingURL=index.js.map
|