@underverse-ui/underverse 0.2.78 → 0.2.80
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +3765 -282
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3750 -266
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -13305,14 +13305,14 @@ function useStickyColumns(columns, visibleKeys) {
|
|
|
13305
13305
|
// ../../components/ui/DataTable/utils/validation.ts
|
|
13306
13306
|
function validateColumns(columns) {
|
|
13307
13307
|
const warnings = [];
|
|
13308
|
-
const
|
|
13308
|
+
const keys2 = /* @__PURE__ */ new Set();
|
|
13309
13309
|
function validate(cols, path = "") {
|
|
13310
13310
|
for (const col of cols) {
|
|
13311
13311
|
const fullPath = path ? `${path}.${col.key}` : col.key;
|
|
13312
|
-
if (
|
|
13312
|
+
if (keys2.has(col.key)) {
|
|
13313
13313
|
warnings.push(`Duplicate key "${col.key}" at ${fullPath}`);
|
|
13314
13314
|
}
|
|
13315
|
-
|
|
13315
|
+
keys2.add(col.key);
|
|
13316
13316
|
const isGroup = col.children && col.children.length > 0;
|
|
13317
13317
|
if (isGroup) {
|
|
13318
13318
|
if (col.dataIndex) {
|
|
@@ -15132,7 +15132,7 @@ function useSmartLocale() {
|
|
|
15132
15132
|
}
|
|
15133
15133
|
|
|
15134
15134
|
// ../../components/ui/UEditor/UEditor.tsx
|
|
15135
|
-
import { useEffect as
|
|
15135
|
+
import { useEffect as useEffect28, useMemo as useMemo16 } from "react";
|
|
15136
15136
|
import { useTranslations as useTranslations7 } from "next-intl";
|
|
15137
15137
|
import { useEditor, EditorContent } from "@tiptap/react";
|
|
15138
15138
|
|
|
@@ -15156,7 +15156,6 @@ import CodeBlockLowlight from "@tiptap/extension-code-block-lowlight";
|
|
|
15156
15156
|
import History2 from "@tiptap/extension-history";
|
|
15157
15157
|
import Placeholder from "@tiptap/extension-placeholder";
|
|
15158
15158
|
import Link3 from "@tiptap/extension-link";
|
|
15159
|
-
import Image3 from "@tiptap/extension-image";
|
|
15160
15159
|
import { TextStyle } from "@tiptap/extension-text-style";
|
|
15161
15160
|
import Color from "@tiptap/extension-color";
|
|
15162
15161
|
import Highlight from "@tiptap/extension-highlight";
|
|
@@ -15349,71 +15348,3433 @@ var getSuggestionItems = ({ query }) => {
|
|
|
15349
15348
|
editor.chain().focus().deleteRange(range).insertTable({ rows: 3, cols: 3, withHeaderRow: true }).run();
|
|
15350
15349
|
}
|
|
15351
15350
|
}
|
|
15352
|
-
].filter((item) => item.title.toLowerCase().includes(query.toLowerCase()));
|
|
15351
|
+
].filter((item) => item.title.toLowerCase().includes(query.toLowerCase()));
|
|
15352
|
+
};
|
|
15353
|
+
var SlashCommand = Extension.create({
|
|
15354
|
+
name: "slashCommand",
|
|
15355
|
+
addProseMirrorPlugins() {
|
|
15356
|
+
return [
|
|
15357
|
+
Suggestion({
|
|
15358
|
+
editor: this.editor,
|
|
15359
|
+
char: "/",
|
|
15360
|
+
command: ({ editor, range, props }) => {
|
|
15361
|
+
props.command({ editor, range });
|
|
15362
|
+
},
|
|
15363
|
+
items: getSuggestionItems,
|
|
15364
|
+
render: () => {
|
|
15365
|
+
let component;
|
|
15366
|
+
let popup;
|
|
15367
|
+
return {
|
|
15368
|
+
onStart: (props) => {
|
|
15369
|
+
component = new ReactRenderer(CommandList, {
|
|
15370
|
+
props,
|
|
15371
|
+
editor: props.editor
|
|
15372
|
+
});
|
|
15373
|
+
if (!props.clientRect) {
|
|
15374
|
+
return;
|
|
15375
|
+
}
|
|
15376
|
+
popup = tippy("body", {
|
|
15377
|
+
getReferenceClientRect: props.clientRect,
|
|
15378
|
+
appendTo: () => document.body,
|
|
15379
|
+
content: component.element,
|
|
15380
|
+
showOnCreate: true,
|
|
15381
|
+
interactive: true,
|
|
15382
|
+
trigger: "manual",
|
|
15383
|
+
placement: "bottom-start"
|
|
15384
|
+
});
|
|
15385
|
+
},
|
|
15386
|
+
onUpdate(props) {
|
|
15387
|
+
component?.updateProps(props);
|
|
15388
|
+
if (!props.clientRect) {
|
|
15389
|
+
return;
|
|
15390
|
+
}
|
|
15391
|
+
popup?.[0]?.setProps({
|
|
15392
|
+
getReferenceClientRect: props.clientRect
|
|
15393
|
+
});
|
|
15394
|
+
},
|
|
15395
|
+
onKeyDown(props) {
|
|
15396
|
+
if (props.event.key === "Escape") {
|
|
15397
|
+
popup?.[0]?.hide();
|
|
15398
|
+
return true;
|
|
15399
|
+
}
|
|
15400
|
+
return component?.ref?.onKeyDown(props) ?? false;
|
|
15401
|
+
},
|
|
15402
|
+
onExit() {
|
|
15403
|
+
popup?.[0]?.destroy();
|
|
15404
|
+
component?.destroy();
|
|
15405
|
+
}
|
|
15406
|
+
};
|
|
15407
|
+
}
|
|
15408
|
+
})
|
|
15409
|
+
];
|
|
15410
|
+
}
|
|
15411
|
+
});
|
|
15412
|
+
|
|
15413
|
+
// ../../components/ui/UEditor/clipboard-images.ts
|
|
15414
|
+
import { Extension as Extension2 } from "@tiptap/core";
|
|
15415
|
+
|
|
15416
|
+
// ../../node_modules/prosemirror-model/dist/index.js
|
|
15417
|
+
function findDiffStart(a, b, pos) {
|
|
15418
|
+
for (let i = 0; ; i++) {
|
|
15419
|
+
if (i == a.childCount || i == b.childCount)
|
|
15420
|
+
return a.childCount == b.childCount ? null : pos;
|
|
15421
|
+
let childA = a.child(i), childB = b.child(i);
|
|
15422
|
+
if (childA == childB) {
|
|
15423
|
+
pos += childA.nodeSize;
|
|
15424
|
+
continue;
|
|
15425
|
+
}
|
|
15426
|
+
if (!childA.sameMarkup(childB))
|
|
15427
|
+
return pos;
|
|
15428
|
+
if (childA.isText && childA.text != childB.text) {
|
|
15429
|
+
for (let j = 0; childA.text[j] == childB.text[j]; j++)
|
|
15430
|
+
pos++;
|
|
15431
|
+
return pos;
|
|
15432
|
+
}
|
|
15433
|
+
if (childA.content.size || childB.content.size) {
|
|
15434
|
+
let inner = findDiffStart(childA.content, childB.content, pos + 1);
|
|
15435
|
+
if (inner != null)
|
|
15436
|
+
return inner;
|
|
15437
|
+
}
|
|
15438
|
+
pos += childA.nodeSize;
|
|
15439
|
+
}
|
|
15440
|
+
}
|
|
15441
|
+
function findDiffEnd(a, b, posA, posB) {
|
|
15442
|
+
for (let iA = a.childCount, iB = b.childCount; ; ) {
|
|
15443
|
+
if (iA == 0 || iB == 0)
|
|
15444
|
+
return iA == iB ? null : { a: posA, b: posB };
|
|
15445
|
+
let childA = a.child(--iA), childB = b.child(--iB), size = childA.nodeSize;
|
|
15446
|
+
if (childA == childB) {
|
|
15447
|
+
posA -= size;
|
|
15448
|
+
posB -= size;
|
|
15449
|
+
continue;
|
|
15450
|
+
}
|
|
15451
|
+
if (!childA.sameMarkup(childB))
|
|
15452
|
+
return { a: posA, b: posB };
|
|
15453
|
+
if (childA.isText && childA.text != childB.text) {
|
|
15454
|
+
let same = 0, minSize = Math.min(childA.text.length, childB.text.length);
|
|
15455
|
+
while (same < minSize && childA.text[childA.text.length - same - 1] == childB.text[childB.text.length - same - 1]) {
|
|
15456
|
+
same++;
|
|
15457
|
+
posA--;
|
|
15458
|
+
posB--;
|
|
15459
|
+
}
|
|
15460
|
+
return { a: posA, b: posB };
|
|
15461
|
+
}
|
|
15462
|
+
if (childA.content.size || childB.content.size) {
|
|
15463
|
+
let inner = findDiffEnd(childA.content, childB.content, posA - 1, posB - 1);
|
|
15464
|
+
if (inner)
|
|
15465
|
+
return inner;
|
|
15466
|
+
}
|
|
15467
|
+
posA -= size;
|
|
15468
|
+
posB -= size;
|
|
15469
|
+
}
|
|
15470
|
+
}
|
|
15471
|
+
var Fragment25 = class _Fragment {
|
|
15472
|
+
/**
|
|
15473
|
+
@internal
|
|
15474
|
+
*/
|
|
15475
|
+
constructor(content, size) {
|
|
15476
|
+
this.content = content;
|
|
15477
|
+
this.size = size || 0;
|
|
15478
|
+
if (size == null)
|
|
15479
|
+
for (let i = 0; i < content.length; i++)
|
|
15480
|
+
this.size += content[i].nodeSize;
|
|
15481
|
+
}
|
|
15482
|
+
/**
|
|
15483
|
+
Invoke a callback for all descendant nodes between the given two
|
|
15484
|
+
positions (relative to start of this fragment). Doesn't descend
|
|
15485
|
+
into a node when the callback returns `false`.
|
|
15486
|
+
*/
|
|
15487
|
+
nodesBetween(from, to, f, nodeStart = 0, parent) {
|
|
15488
|
+
for (let i = 0, pos = 0; pos < to; i++) {
|
|
15489
|
+
let child = this.content[i], end = pos + child.nodeSize;
|
|
15490
|
+
if (end > from && f(child, nodeStart + pos, parent || null, i) !== false && child.content.size) {
|
|
15491
|
+
let start = pos + 1;
|
|
15492
|
+
child.nodesBetween(Math.max(0, from - start), Math.min(child.content.size, to - start), f, nodeStart + start);
|
|
15493
|
+
}
|
|
15494
|
+
pos = end;
|
|
15495
|
+
}
|
|
15496
|
+
}
|
|
15497
|
+
/**
|
|
15498
|
+
Call the given callback for every descendant node. `pos` will be
|
|
15499
|
+
relative to the start of the fragment. The callback may return
|
|
15500
|
+
`false` to prevent traversal of a given node's children.
|
|
15501
|
+
*/
|
|
15502
|
+
descendants(f) {
|
|
15503
|
+
this.nodesBetween(0, this.size, f);
|
|
15504
|
+
}
|
|
15505
|
+
/**
|
|
15506
|
+
Extract the text between `from` and `to`. See the same method on
|
|
15507
|
+
[`Node`](https://prosemirror.net/docs/ref/#model.Node.textBetween).
|
|
15508
|
+
*/
|
|
15509
|
+
textBetween(from, to, blockSeparator, leafText) {
|
|
15510
|
+
let text = "", first = true;
|
|
15511
|
+
this.nodesBetween(from, to, (node, pos) => {
|
|
15512
|
+
let nodeText = node.isText ? node.text.slice(Math.max(from, pos) - pos, to - pos) : !node.isLeaf ? "" : leafText ? typeof leafText === "function" ? leafText(node) : leafText : node.type.spec.leafText ? node.type.spec.leafText(node) : "";
|
|
15513
|
+
if (node.isBlock && (node.isLeaf && nodeText || node.isTextblock) && blockSeparator) {
|
|
15514
|
+
if (first)
|
|
15515
|
+
first = false;
|
|
15516
|
+
else
|
|
15517
|
+
text += blockSeparator;
|
|
15518
|
+
}
|
|
15519
|
+
text += nodeText;
|
|
15520
|
+
}, 0);
|
|
15521
|
+
return text;
|
|
15522
|
+
}
|
|
15523
|
+
/**
|
|
15524
|
+
Create a new fragment containing the combined content of this
|
|
15525
|
+
fragment and the other.
|
|
15526
|
+
*/
|
|
15527
|
+
append(other) {
|
|
15528
|
+
if (!other.size)
|
|
15529
|
+
return this;
|
|
15530
|
+
if (!this.size)
|
|
15531
|
+
return other;
|
|
15532
|
+
let last = this.lastChild, first = other.firstChild, content = this.content.slice(), i = 0;
|
|
15533
|
+
if (last.isText && last.sameMarkup(first)) {
|
|
15534
|
+
content[content.length - 1] = last.withText(last.text + first.text);
|
|
15535
|
+
i = 1;
|
|
15536
|
+
}
|
|
15537
|
+
for (; i < other.content.length; i++)
|
|
15538
|
+
content.push(other.content[i]);
|
|
15539
|
+
return new _Fragment(content, this.size + other.size);
|
|
15540
|
+
}
|
|
15541
|
+
/**
|
|
15542
|
+
Cut out the sub-fragment between the two given positions.
|
|
15543
|
+
*/
|
|
15544
|
+
cut(from, to = this.size) {
|
|
15545
|
+
if (from == 0 && to == this.size)
|
|
15546
|
+
return this;
|
|
15547
|
+
let result = [], size = 0;
|
|
15548
|
+
if (to > from)
|
|
15549
|
+
for (let i = 0, pos = 0; pos < to; i++) {
|
|
15550
|
+
let child = this.content[i], end = pos + child.nodeSize;
|
|
15551
|
+
if (end > from) {
|
|
15552
|
+
if (pos < from || end > to) {
|
|
15553
|
+
if (child.isText)
|
|
15554
|
+
child = child.cut(Math.max(0, from - pos), Math.min(child.text.length, to - pos));
|
|
15555
|
+
else
|
|
15556
|
+
child = child.cut(Math.max(0, from - pos - 1), Math.min(child.content.size, to - pos - 1));
|
|
15557
|
+
}
|
|
15558
|
+
result.push(child);
|
|
15559
|
+
size += child.nodeSize;
|
|
15560
|
+
}
|
|
15561
|
+
pos = end;
|
|
15562
|
+
}
|
|
15563
|
+
return new _Fragment(result, size);
|
|
15564
|
+
}
|
|
15565
|
+
/**
|
|
15566
|
+
@internal
|
|
15567
|
+
*/
|
|
15568
|
+
cutByIndex(from, to) {
|
|
15569
|
+
if (from == to)
|
|
15570
|
+
return _Fragment.empty;
|
|
15571
|
+
if (from == 0 && to == this.content.length)
|
|
15572
|
+
return this;
|
|
15573
|
+
return new _Fragment(this.content.slice(from, to));
|
|
15574
|
+
}
|
|
15575
|
+
/**
|
|
15576
|
+
Create a new fragment in which the node at the given index is
|
|
15577
|
+
replaced by the given node.
|
|
15578
|
+
*/
|
|
15579
|
+
replaceChild(index, node) {
|
|
15580
|
+
let current = this.content[index];
|
|
15581
|
+
if (current == node)
|
|
15582
|
+
return this;
|
|
15583
|
+
let copy = this.content.slice();
|
|
15584
|
+
let size = this.size + node.nodeSize - current.nodeSize;
|
|
15585
|
+
copy[index] = node;
|
|
15586
|
+
return new _Fragment(copy, size);
|
|
15587
|
+
}
|
|
15588
|
+
/**
|
|
15589
|
+
Create a new fragment by prepending the given node to this
|
|
15590
|
+
fragment.
|
|
15591
|
+
*/
|
|
15592
|
+
addToStart(node) {
|
|
15593
|
+
return new _Fragment([node].concat(this.content), this.size + node.nodeSize);
|
|
15594
|
+
}
|
|
15595
|
+
/**
|
|
15596
|
+
Create a new fragment by appending the given node to this
|
|
15597
|
+
fragment.
|
|
15598
|
+
*/
|
|
15599
|
+
addToEnd(node) {
|
|
15600
|
+
return new _Fragment(this.content.concat(node), this.size + node.nodeSize);
|
|
15601
|
+
}
|
|
15602
|
+
/**
|
|
15603
|
+
Compare this fragment to another one.
|
|
15604
|
+
*/
|
|
15605
|
+
eq(other) {
|
|
15606
|
+
if (this.content.length != other.content.length)
|
|
15607
|
+
return false;
|
|
15608
|
+
for (let i = 0; i < this.content.length; i++)
|
|
15609
|
+
if (!this.content[i].eq(other.content[i]))
|
|
15610
|
+
return false;
|
|
15611
|
+
return true;
|
|
15612
|
+
}
|
|
15613
|
+
/**
|
|
15614
|
+
The first child of the fragment, or `null` if it is empty.
|
|
15615
|
+
*/
|
|
15616
|
+
get firstChild() {
|
|
15617
|
+
return this.content.length ? this.content[0] : null;
|
|
15618
|
+
}
|
|
15619
|
+
/**
|
|
15620
|
+
The last child of the fragment, or `null` if it is empty.
|
|
15621
|
+
*/
|
|
15622
|
+
get lastChild() {
|
|
15623
|
+
return this.content.length ? this.content[this.content.length - 1] : null;
|
|
15624
|
+
}
|
|
15625
|
+
/**
|
|
15626
|
+
The number of child nodes in this fragment.
|
|
15627
|
+
*/
|
|
15628
|
+
get childCount() {
|
|
15629
|
+
return this.content.length;
|
|
15630
|
+
}
|
|
15631
|
+
/**
|
|
15632
|
+
Get the child node at the given index. Raise an error when the
|
|
15633
|
+
index is out of range.
|
|
15634
|
+
*/
|
|
15635
|
+
child(index) {
|
|
15636
|
+
let found2 = this.content[index];
|
|
15637
|
+
if (!found2)
|
|
15638
|
+
throw new RangeError("Index " + index + " out of range for " + this);
|
|
15639
|
+
return found2;
|
|
15640
|
+
}
|
|
15641
|
+
/**
|
|
15642
|
+
Get the child node at the given index, if it exists.
|
|
15643
|
+
*/
|
|
15644
|
+
maybeChild(index) {
|
|
15645
|
+
return this.content[index] || null;
|
|
15646
|
+
}
|
|
15647
|
+
/**
|
|
15648
|
+
Call `f` for every child node, passing the node, its offset
|
|
15649
|
+
into this parent node, and its index.
|
|
15650
|
+
*/
|
|
15651
|
+
forEach(f) {
|
|
15652
|
+
for (let i = 0, p = 0; i < this.content.length; i++) {
|
|
15653
|
+
let child = this.content[i];
|
|
15654
|
+
f(child, p, i);
|
|
15655
|
+
p += child.nodeSize;
|
|
15656
|
+
}
|
|
15657
|
+
}
|
|
15658
|
+
/**
|
|
15659
|
+
Find the first position at which this fragment and another
|
|
15660
|
+
fragment differ, or `null` if they are the same.
|
|
15661
|
+
*/
|
|
15662
|
+
findDiffStart(other, pos = 0) {
|
|
15663
|
+
return findDiffStart(this, other, pos);
|
|
15664
|
+
}
|
|
15665
|
+
/**
|
|
15666
|
+
Find the first position, searching from the end, at which this
|
|
15667
|
+
fragment and the given fragment differ, or `null` if they are
|
|
15668
|
+
the same. Since this position will not be the same in both
|
|
15669
|
+
nodes, an object with two separate positions is returned.
|
|
15670
|
+
*/
|
|
15671
|
+
findDiffEnd(other, pos = this.size, otherPos = other.size) {
|
|
15672
|
+
return findDiffEnd(this, other, pos, otherPos);
|
|
15673
|
+
}
|
|
15674
|
+
/**
|
|
15675
|
+
Find the index and inner offset corresponding to a given relative
|
|
15676
|
+
position in this fragment. The result object will be reused
|
|
15677
|
+
(overwritten) the next time the function is called. @internal
|
|
15678
|
+
*/
|
|
15679
|
+
findIndex(pos) {
|
|
15680
|
+
if (pos == 0)
|
|
15681
|
+
return retIndex(0, pos);
|
|
15682
|
+
if (pos == this.size)
|
|
15683
|
+
return retIndex(this.content.length, pos);
|
|
15684
|
+
if (pos > this.size || pos < 0)
|
|
15685
|
+
throw new RangeError(`Position ${pos} outside of fragment (${this})`);
|
|
15686
|
+
for (let i = 0, curPos = 0; ; i++) {
|
|
15687
|
+
let cur = this.child(i), end = curPos + cur.nodeSize;
|
|
15688
|
+
if (end >= pos) {
|
|
15689
|
+
if (end == pos)
|
|
15690
|
+
return retIndex(i + 1, end);
|
|
15691
|
+
return retIndex(i, curPos);
|
|
15692
|
+
}
|
|
15693
|
+
curPos = end;
|
|
15694
|
+
}
|
|
15695
|
+
}
|
|
15696
|
+
/**
|
|
15697
|
+
Return a debugging string that describes this fragment.
|
|
15698
|
+
*/
|
|
15699
|
+
toString() {
|
|
15700
|
+
return "<" + this.toStringInner() + ">";
|
|
15701
|
+
}
|
|
15702
|
+
/**
|
|
15703
|
+
@internal
|
|
15704
|
+
*/
|
|
15705
|
+
toStringInner() {
|
|
15706
|
+
return this.content.join(", ");
|
|
15707
|
+
}
|
|
15708
|
+
/**
|
|
15709
|
+
Create a JSON-serializeable representation of this fragment.
|
|
15710
|
+
*/
|
|
15711
|
+
toJSON() {
|
|
15712
|
+
return this.content.length ? this.content.map((n) => n.toJSON()) : null;
|
|
15713
|
+
}
|
|
15714
|
+
/**
|
|
15715
|
+
Deserialize a fragment from its JSON representation.
|
|
15716
|
+
*/
|
|
15717
|
+
static fromJSON(schema, value) {
|
|
15718
|
+
if (!value)
|
|
15719
|
+
return _Fragment.empty;
|
|
15720
|
+
if (!Array.isArray(value))
|
|
15721
|
+
throw new RangeError("Invalid input for Fragment.fromJSON");
|
|
15722
|
+
return new _Fragment(value.map(schema.nodeFromJSON));
|
|
15723
|
+
}
|
|
15724
|
+
/**
|
|
15725
|
+
Build a fragment from an array of nodes. Ensures that adjacent
|
|
15726
|
+
text nodes with the same marks are joined together.
|
|
15727
|
+
*/
|
|
15728
|
+
static fromArray(array) {
|
|
15729
|
+
if (!array.length)
|
|
15730
|
+
return _Fragment.empty;
|
|
15731
|
+
let joined, size = 0;
|
|
15732
|
+
for (let i = 0; i < array.length; i++) {
|
|
15733
|
+
let node = array[i];
|
|
15734
|
+
size += node.nodeSize;
|
|
15735
|
+
if (i && node.isText && array[i - 1].sameMarkup(node)) {
|
|
15736
|
+
if (!joined)
|
|
15737
|
+
joined = array.slice(0, i);
|
|
15738
|
+
joined[joined.length - 1] = node.withText(joined[joined.length - 1].text + node.text);
|
|
15739
|
+
} else if (joined) {
|
|
15740
|
+
joined.push(node);
|
|
15741
|
+
}
|
|
15742
|
+
}
|
|
15743
|
+
return new _Fragment(joined || array, size);
|
|
15744
|
+
}
|
|
15745
|
+
/**
|
|
15746
|
+
Create a fragment from something that can be interpreted as a
|
|
15747
|
+
set of nodes. For `null`, it returns the empty fragment. For a
|
|
15748
|
+
fragment, the fragment itself. For a node or array of nodes, a
|
|
15749
|
+
fragment containing those nodes.
|
|
15750
|
+
*/
|
|
15751
|
+
static from(nodes) {
|
|
15752
|
+
if (!nodes)
|
|
15753
|
+
return _Fragment.empty;
|
|
15754
|
+
if (nodes instanceof _Fragment)
|
|
15755
|
+
return nodes;
|
|
15756
|
+
if (Array.isArray(nodes))
|
|
15757
|
+
return this.fromArray(nodes);
|
|
15758
|
+
if (nodes.attrs)
|
|
15759
|
+
return new _Fragment([nodes], nodes.nodeSize);
|
|
15760
|
+
throw new RangeError("Can not convert " + nodes + " to a Fragment" + (nodes.nodesBetween ? " (looks like multiple versions of prosemirror-model were loaded)" : ""));
|
|
15761
|
+
}
|
|
15762
|
+
};
|
|
15763
|
+
Fragment25.empty = new Fragment25([], 0);
|
|
15764
|
+
var found = { index: 0, offset: 0 };
|
|
15765
|
+
function retIndex(index, offset) {
|
|
15766
|
+
found.index = index;
|
|
15767
|
+
found.offset = offset;
|
|
15768
|
+
return found;
|
|
15769
|
+
}
|
|
15770
|
+
function compareDeep(a, b) {
|
|
15771
|
+
if (a === b)
|
|
15772
|
+
return true;
|
|
15773
|
+
if (!(a && typeof a == "object") || !(b && typeof b == "object"))
|
|
15774
|
+
return false;
|
|
15775
|
+
let array = Array.isArray(a);
|
|
15776
|
+
if (Array.isArray(b) != array)
|
|
15777
|
+
return false;
|
|
15778
|
+
if (array) {
|
|
15779
|
+
if (a.length != b.length)
|
|
15780
|
+
return false;
|
|
15781
|
+
for (let i = 0; i < a.length; i++)
|
|
15782
|
+
if (!compareDeep(a[i], b[i]))
|
|
15783
|
+
return false;
|
|
15784
|
+
} else {
|
|
15785
|
+
for (let p in a)
|
|
15786
|
+
if (!(p in b) || !compareDeep(a[p], b[p]))
|
|
15787
|
+
return false;
|
|
15788
|
+
for (let p in b)
|
|
15789
|
+
if (!(p in a))
|
|
15790
|
+
return false;
|
|
15791
|
+
}
|
|
15792
|
+
return true;
|
|
15793
|
+
}
|
|
15794
|
+
var Mark = class _Mark {
|
|
15795
|
+
/**
|
|
15796
|
+
@internal
|
|
15797
|
+
*/
|
|
15798
|
+
constructor(type, attrs) {
|
|
15799
|
+
this.type = type;
|
|
15800
|
+
this.attrs = attrs;
|
|
15801
|
+
}
|
|
15802
|
+
/**
|
|
15803
|
+
Given a set of marks, create a new set which contains this one as
|
|
15804
|
+
well, in the right position. If this mark is already in the set,
|
|
15805
|
+
the set itself is returned. If any marks that are set to be
|
|
15806
|
+
[exclusive](https://prosemirror.net/docs/ref/#model.MarkSpec.excludes) with this mark are present,
|
|
15807
|
+
those are replaced by this one.
|
|
15808
|
+
*/
|
|
15809
|
+
addToSet(set) {
|
|
15810
|
+
let copy, placed = false;
|
|
15811
|
+
for (let i = 0; i < set.length; i++) {
|
|
15812
|
+
let other = set[i];
|
|
15813
|
+
if (this.eq(other))
|
|
15814
|
+
return set;
|
|
15815
|
+
if (this.type.excludes(other.type)) {
|
|
15816
|
+
if (!copy)
|
|
15817
|
+
copy = set.slice(0, i);
|
|
15818
|
+
} else if (other.type.excludes(this.type)) {
|
|
15819
|
+
return set;
|
|
15820
|
+
} else {
|
|
15821
|
+
if (!placed && other.type.rank > this.type.rank) {
|
|
15822
|
+
if (!copy)
|
|
15823
|
+
copy = set.slice(0, i);
|
|
15824
|
+
copy.push(this);
|
|
15825
|
+
placed = true;
|
|
15826
|
+
}
|
|
15827
|
+
if (copy)
|
|
15828
|
+
copy.push(other);
|
|
15829
|
+
}
|
|
15830
|
+
}
|
|
15831
|
+
if (!copy)
|
|
15832
|
+
copy = set.slice();
|
|
15833
|
+
if (!placed)
|
|
15834
|
+
copy.push(this);
|
|
15835
|
+
return copy;
|
|
15836
|
+
}
|
|
15837
|
+
/**
|
|
15838
|
+
Remove this mark from the given set, returning a new set. If this
|
|
15839
|
+
mark is not in the set, the set itself is returned.
|
|
15840
|
+
*/
|
|
15841
|
+
removeFromSet(set) {
|
|
15842
|
+
for (let i = 0; i < set.length; i++)
|
|
15843
|
+
if (this.eq(set[i]))
|
|
15844
|
+
return set.slice(0, i).concat(set.slice(i + 1));
|
|
15845
|
+
return set;
|
|
15846
|
+
}
|
|
15847
|
+
/**
|
|
15848
|
+
Test whether this mark is in the given set of marks.
|
|
15849
|
+
*/
|
|
15850
|
+
isInSet(set) {
|
|
15851
|
+
for (let i = 0; i < set.length; i++)
|
|
15852
|
+
if (this.eq(set[i]))
|
|
15853
|
+
return true;
|
|
15854
|
+
return false;
|
|
15855
|
+
}
|
|
15856
|
+
/**
|
|
15857
|
+
Test whether this mark has the same type and attributes as
|
|
15858
|
+
another mark.
|
|
15859
|
+
*/
|
|
15860
|
+
eq(other) {
|
|
15861
|
+
return this == other || this.type == other.type && compareDeep(this.attrs, other.attrs);
|
|
15862
|
+
}
|
|
15863
|
+
/**
|
|
15864
|
+
Convert this mark to a JSON-serializeable representation.
|
|
15865
|
+
*/
|
|
15866
|
+
toJSON() {
|
|
15867
|
+
let obj = { type: this.type.name };
|
|
15868
|
+
for (let _ in this.attrs) {
|
|
15869
|
+
obj.attrs = this.attrs;
|
|
15870
|
+
break;
|
|
15871
|
+
}
|
|
15872
|
+
return obj;
|
|
15873
|
+
}
|
|
15874
|
+
/**
|
|
15875
|
+
Deserialize a mark from JSON.
|
|
15876
|
+
*/
|
|
15877
|
+
static fromJSON(schema, json) {
|
|
15878
|
+
if (!json)
|
|
15879
|
+
throw new RangeError("Invalid input for Mark.fromJSON");
|
|
15880
|
+
let type = schema.marks[json.type];
|
|
15881
|
+
if (!type)
|
|
15882
|
+
throw new RangeError(`There is no mark type ${json.type} in this schema`);
|
|
15883
|
+
let mark = type.create(json.attrs);
|
|
15884
|
+
type.checkAttrs(mark.attrs);
|
|
15885
|
+
return mark;
|
|
15886
|
+
}
|
|
15887
|
+
/**
|
|
15888
|
+
Test whether two sets of marks are identical.
|
|
15889
|
+
*/
|
|
15890
|
+
static sameSet(a, b) {
|
|
15891
|
+
if (a == b)
|
|
15892
|
+
return true;
|
|
15893
|
+
if (a.length != b.length)
|
|
15894
|
+
return false;
|
|
15895
|
+
for (let i = 0; i < a.length; i++)
|
|
15896
|
+
if (!a[i].eq(b[i]))
|
|
15897
|
+
return false;
|
|
15898
|
+
return true;
|
|
15899
|
+
}
|
|
15900
|
+
/**
|
|
15901
|
+
Create a properly sorted mark set from null, a single mark, or an
|
|
15902
|
+
unsorted array of marks.
|
|
15903
|
+
*/
|
|
15904
|
+
static setFrom(marks) {
|
|
15905
|
+
if (!marks || Array.isArray(marks) && marks.length == 0)
|
|
15906
|
+
return _Mark.none;
|
|
15907
|
+
if (marks instanceof _Mark)
|
|
15908
|
+
return [marks];
|
|
15909
|
+
let copy = marks.slice();
|
|
15910
|
+
copy.sort((a, b) => a.type.rank - b.type.rank);
|
|
15911
|
+
return copy;
|
|
15912
|
+
}
|
|
15913
|
+
};
|
|
15914
|
+
Mark.none = [];
|
|
15915
|
+
var ReplaceError = class extends Error {
|
|
15916
|
+
};
|
|
15917
|
+
var Slice = class _Slice {
|
|
15918
|
+
/**
|
|
15919
|
+
Create a slice. When specifying a non-zero open depth, you must
|
|
15920
|
+
make sure that there are nodes of at least that depth at the
|
|
15921
|
+
appropriate side of the fragment—i.e. if the fragment is an
|
|
15922
|
+
empty paragraph node, `openStart` and `openEnd` can't be greater
|
|
15923
|
+
than 1.
|
|
15924
|
+
|
|
15925
|
+
It is not necessary for the content of open nodes to conform to
|
|
15926
|
+
the schema's content constraints, though it should be a valid
|
|
15927
|
+
start/end/middle for such a node, depending on which sides are
|
|
15928
|
+
open.
|
|
15929
|
+
*/
|
|
15930
|
+
constructor(content, openStart, openEnd) {
|
|
15931
|
+
this.content = content;
|
|
15932
|
+
this.openStart = openStart;
|
|
15933
|
+
this.openEnd = openEnd;
|
|
15934
|
+
}
|
|
15935
|
+
/**
|
|
15936
|
+
The size this slice would add when inserted into a document.
|
|
15937
|
+
*/
|
|
15938
|
+
get size() {
|
|
15939
|
+
return this.content.size - this.openStart - this.openEnd;
|
|
15940
|
+
}
|
|
15941
|
+
/**
|
|
15942
|
+
@internal
|
|
15943
|
+
*/
|
|
15944
|
+
insertAt(pos, fragment) {
|
|
15945
|
+
let content = insertInto(this.content, pos + this.openStart, fragment);
|
|
15946
|
+
return content && new _Slice(content, this.openStart, this.openEnd);
|
|
15947
|
+
}
|
|
15948
|
+
/**
|
|
15949
|
+
@internal
|
|
15950
|
+
*/
|
|
15951
|
+
removeBetween(from, to) {
|
|
15952
|
+
return new _Slice(removeRange(this.content, from + this.openStart, to + this.openStart), this.openStart, this.openEnd);
|
|
15953
|
+
}
|
|
15954
|
+
/**
|
|
15955
|
+
Tests whether this slice is equal to another slice.
|
|
15956
|
+
*/
|
|
15957
|
+
eq(other) {
|
|
15958
|
+
return this.content.eq(other.content) && this.openStart == other.openStart && this.openEnd == other.openEnd;
|
|
15959
|
+
}
|
|
15960
|
+
/**
|
|
15961
|
+
@internal
|
|
15962
|
+
*/
|
|
15963
|
+
toString() {
|
|
15964
|
+
return this.content + "(" + this.openStart + "," + this.openEnd + ")";
|
|
15965
|
+
}
|
|
15966
|
+
/**
|
|
15967
|
+
Convert a slice to a JSON-serializable representation.
|
|
15968
|
+
*/
|
|
15969
|
+
toJSON() {
|
|
15970
|
+
if (!this.content.size)
|
|
15971
|
+
return null;
|
|
15972
|
+
let json = { content: this.content.toJSON() };
|
|
15973
|
+
if (this.openStart > 0)
|
|
15974
|
+
json.openStart = this.openStart;
|
|
15975
|
+
if (this.openEnd > 0)
|
|
15976
|
+
json.openEnd = this.openEnd;
|
|
15977
|
+
return json;
|
|
15978
|
+
}
|
|
15979
|
+
/**
|
|
15980
|
+
Deserialize a slice from its JSON representation.
|
|
15981
|
+
*/
|
|
15982
|
+
static fromJSON(schema, json) {
|
|
15983
|
+
if (!json)
|
|
15984
|
+
return _Slice.empty;
|
|
15985
|
+
let openStart = json.openStart || 0, openEnd = json.openEnd || 0;
|
|
15986
|
+
if (typeof openStart != "number" || typeof openEnd != "number")
|
|
15987
|
+
throw new RangeError("Invalid input for Slice.fromJSON");
|
|
15988
|
+
return new _Slice(Fragment25.fromJSON(schema, json.content), openStart, openEnd);
|
|
15989
|
+
}
|
|
15990
|
+
/**
|
|
15991
|
+
Create a slice from a fragment by taking the maximum possible
|
|
15992
|
+
open value on both side of the fragment.
|
|
15993
|
+
*/
|
|
15994
|
+
static maxOpen(fragment, openIsolating = true) {
|
|
15995
|
+
let openStart = 0, openEnd = 0;
|
|
15996
|
+
for (let n = fragment.firstChild; n && !n.isLeaf && (openIsolating || !n.type.spec.isolating); n = n.firstChild)
|
|
15997
|
+
openStart++;
|
|
15998
|
+
for (let n = fragment.lastChild; n && !n.isLeaf && (openIsolating || !n.type.spec.isolating); n = n.lastChild)
|
|
15999
|
+
openEnd++;
|
|
16000
|
+
return new _Slice(fragment, openStart, openEnd);
|
|
16001
|
+
}
|
|
16002
|
+
};
|
|
16003
|
+
Slice.empty = new Slice(Fragment25.empty, 0, 0);
|
|
16004
|
+
function removeRange(content, from, to) {
|
|
16005
|
+
let { index, offset } = content.findIndex(from), child = content.maybeChild(index);
|
|
16006
|
+
let { index: indexTo, offset: offsetTo } = content.findIndex(to);
|
|
16007
|
+
if (offset == from || child.isText) {
|
|
16008
|
+
if (offsetTo != to && !content.child(indexTo).isText)
|
|
16009
|
+
throw new RangeError("Removing non-flat range");
|
|
16010
|
+
return content.cut(0, from).append(content.cut(to));
|
|
16011
|
+
}
|
|
16012
|
+
if (index != indexTo)
|
|
16013
|
+
throw new RangeError("Removing non-flat range");
|
|
16014
|
+
return content.replaceChild(index, child.copy(removeRange(child.content, from - offset - 1, to - offset - 1)));
|
|
16015
|
+
}
|
|
16016
|
+
function insertInto(content, dist, insert, parent) {
|
|
16017
|
+
let { index, offset } = content.findIndex(dist), child = content.maybeChild(index);
|
|
16018
|
+
if (offset == dist || child.isText) {
|
|
16019
|
+
if (parent && !parent.canReplace(index, index, insert))
|
|
16020
|
+
return null;
|
|
16021
|
+
return content.cut(0, dist).append(insert).append(content.cut(dist));
|
|
16022
|
+
}
|
|
16023
|
+
let inner = insertInto(child.content, dist - offset - 1, insert, child);
|
|
16024
|
+
return inner && content.replaceChild(index, child.copy(inner));
|
|
16025
|
+
}
|
|
16026
|
+
function replace($from, $to, slice) {
|
|
16027
|
+
if (slice.openStart > $from.depth)
|
|
16028
|
+
throw new ReplaceError("Inserted content deeper than insertion position");
|
|
16029
|
+
if ($from.depth - slice.openStart != $to.depth - slice.openEnd)
|
|
16030
|
+
throw new ReplaceError("Inconsistent open depths");
|
|
16031
|
+
return replaceOuter($from, $to, slice, 0);
|
|
16032
|
+
}
|
|
16033
|
+
function replaceOuter($from, $to, slice, depth) {
|
|
16034
|
+
let index = $from.index(depth), node = $from.node(depth);
|
|
16035
|
+
if (index == $to.index(depth) && depth < $from.depth - slice.openStart) {
|
|
16036
|
+
let inner = replaceOuter($from, $to, slice, depth + 1);
|
|
16037
|
+
return node.copy(node.content.replaceChild(index, inner));
|
|
16038
|
+
} else if (!slice.content.size) {
|
|
16039
|
+
return close(node, replaceTwoWay($from, $to, depth));
|
|
16040
|
+
} else if (!slice.openStart && !slice.openEnd && $from.depth == depth && $to.depth == depth) {
|
|
16041
|
+
let parent = $from.parent, content = parent.content;
|
|
16042
|
+
return close(parent, content.cut(0, $from.parentOffset).append(slice.content).append(content.cut($to.parentOffset)));
|
|
16043
|
+
} else {
|
|
16044
|
+
let { start, end } = prepareSliceForReplace(slice, $from);
|
|
16045
|
+
return close(node, replaceThreeWay($from, start, end, $to, depth));
|
|
16046
|
+
}
|
|
16047
|
+
}
|
|
16048
|
+
function checkJoin(main, sub) {
|
|
16049
|
+
if (!sub.type.compatibleContent(main.type))
|
|
16050
|
+
throw new ReplaceError("Cannot join " + sub.type.name + " onto " + main.type.name);
|
|
16051
|
+
}
|
|
16052
|
+
function joinable($before, $after, depth) {
|
|
16053
|
+
let node = $before.node(depth);
|
|
16054
|
+
checkJoin(node, $after.node(depth));
|
|
16055
|
+
return node;
|
|
16056
|
+
}
|
|
16057
|
+
function addNode(child, target) {
|
|
16058
|
+
let last = target.length - 1;
|
|
16059
|
+
if (last >= 0 && child.isText && child.sameMarkup(target[last]))
|
|
16060
|
+
target[last] = child.withText(target[last].text + child.text);
|
|
16061
|
+
else
|
|
16062
|
+
target.push(child);
|
|
16063
|
+
}
|
|
16064
|
+
function addRange($start, $end, depth, target) {
|
|
16065
|
+
let node = ($end || $start).node(depth);
|
|
16066
|
+
let startIndex = 0, endIndex = $end ? $end.index(depth) : node.childCount;
|
|
16067
|
+
if ($start) {
|
|
16068
|
+
startIndex = $start.index(depth);
|
|
16069
|
+
if ($start.depth > depth) {
|
|
16070
|
+
startIndex++;
|
|
16071
|
+
} else if ($start.textOffset) {
|
|
16072
|
+
addNode($start.nodeAfter, target);
|
|
16073
|
+
startIndex++;
|
|
16074
|
+
}
|
|
16075
|
+
}
|
|
16076
|
+
for (let i = startIndex; i < endIndex; i++)
|
|
16077
|
+
addNode(node.child(i), target);
|
|
16078
|
+
if ($end && $end.depth == depth && $end.textOffset)
|
|
16079
|
+
addNode($end.nodeBefore, target);
|
|
16080
|
+
}
|
|
16081
|
+
function close(node, content) {
|
|
16082
|
+
node.type.checkContent(content);
|
|
16083
|
+
return node.copy(content);
|
|
16084
|
+
}
|
|
16085
|
+
function replaceThreeWay($from, $start, $end, $to, depth) {
|
|
16086
|
+
let openStart = $from.depth > depth && joinable($from, $start, depth + 1);
|
|
16087
|
+
let openEnd = $to.depth > depth && joinable($end, $to, depth + 1);
|
|
16088
|
+
let content = [];
|
|
16089
|
+
addRange(null, $from, depth, content);
|
|
16090
|
+
if (openStart && openEnd && $start.index(depth) == $end.index(depth)) {
|
|
16091
|
+
checkJoin(openStart, openEnd);
|
|
16092
|
+
addNode(close(openStart, replaceThreeWay($from, $start, $end, $to, depth + 1)), content);
|
|
16093
|
+
} else {
|
|
16094
|
+
if (openStart)
|
|
16095
|
+
addNode(close(openStart, replaceTwoWay($from, $start, depth + 1)), content);
|
|
16096
|
+
addRange($start, $end, depth, content);
|
|
16097
|
+
if (openEnd)
|
|
16098
|
+
addNode(close(openEnd, replaceTwoWay($end, $to, depth + 1)), content);
|
|
16099
|
+
}
|
|
16100
|
+
addRange($to, null, depth, content);
|
|
16101
|
+
return new Fragment25(content);
|
|
16102
|
+
}
|
|
16103
|
+
function replaceTwoWay($from, $to, depth) {
|
|
16104
|
+
let content = [];
|
|
16105
|
+
addRange(null, $from, depth, content);
|
|
16106
|
+
if ($from.depth > depth) {
|
|
16107
|
+
let type = joinable($from, $to, depth + 1);
|
|
16108
|
+
addNode(close(type, replaceTwoWay($from, $to, depth + 1)), content);
|
|
16109
|
+
}
|
|
16110
|
+
addRange($to, null, depth, content);
|
|
16111
|
+
return new Fragment25(content);
|
|
16112
|
+
}
|
|
16113
|
+
function prepareSliceForReplace(slice, $along) {
|
|
16114
|
+
let extra = $along.depth - slice.openStart, parent = $along.node(extra);
|
|
16115
|
+
let node = parent.copy(slice.content);
|
|
16116
|
+
for (let i = extra - 1; i >= 0; i--)
|
|
16117
|
+
node = $along.node(i).copy(Fragment25.from(node));
|
|
16118
|
+
return {
|
|
16119
|
+
start: node.resolveNoCache(slice.openStart + extra),
|
|
16120
|
+
end: node.resolveNoCache(node.content.size - slice.openEnd - extra)
|
|
16121
|
+
};
|
|
16122
|
+
}
|
|
16123
|
+
var ResolvedPos = class _ResolvedPos {
|
|
16124
|
+
/**
|
|
16125
|
+
@internal
|
|
16126
|
+
*/
|
|
16127
|
+
constructor(pos, path, parentOffset) {
|
|
16128
|
+
this.pos = pos;
|
|
16129
|
+
this.path = path;
|
|
16130
|
+
this.parentOffset = parentOffset;
|
|
16131
|
+
this.depth = path.length / 3 - 1;
|
|
16132
|
+
}
|
|
16133
|
+
/**
|
|
16134
|
+
@internal
|
|
16135
|
+
*/
|
|
16136
|
+
resolveDepth(val) {
|
|
16137
|
+
if (val == null)
|
|
16138
|
+
return this.depth;
|
|
16139
|
+
if (val < 0)
|
|
16140
|
+
return this.depth + val;
|
|
16141
|
+
return val;
|
|
16142
|
+
}
|
|
16143
|
+
/**
|
|
16144
|
+
The parent node that the position points into. Note that even if
|
|
16145
|
+
a position points into a text node, that node is not considered
|
|
16146
|
+
the parent—text nodes are ‘flat’ in this model, and have no content.
|
|
16147
|
+
*/
|
|
16148
|
+
get parent() {
|
|
16149
|
+
return this.node(this.depth);
|
|
16150
|
+
}
|
|
16151
|
+
/**
|
|
16152
|
+
The root node in which the position was resolved.
|
|
16153
|
+
*/
|
|
16154
|
+
get doc() {
|
|
16155
|
+
return this.node(0);
|
|
16156
|
+
}
|
|
16157
|
+
/**
|
|
16158
|
+
The ancestor node at the given level. `p.node(p.depth)` is the
|
|
16159
|
+
same as `p.parent`.
|
|
16160
|
+
*/
|
|
16161
|
+
node(depth) {
|
|
16162
|
+
return this.path[this.resolveDepth(depth) * 3];
|
|
16163
|
+
}
|
|
16164
|
+
/**
|
|
16165
|
+
The index into the ancestor at the given level. If this points
|
|
16166
|
+
at the 3rd node in the 2nd paragraph on the top level, for
|
|
16167
|
+
example, `p.index(0)` is 1 and `p.index(1)` is 2.
|
|
16168
|
+
*/
|
|
16169
|
+
index(depth) {
|
|
16170
|
+
return this.path[this.resolveDepth(depth) * 3 + 1];
|
|
16171
|
+
}
|
|
16172
|
+
/**
|
|
16173
|
+
The index pointing after this position into the ancestor at the
|
|
16174
|
+
given level.
|
|
16175
|
+
*/
|
|
16176
|
+
indexAfter(depth) {
|
|
16177
|
+
depth = this.resolveDepth(depth);
|
|
16178
|
+
return this.index(depth) + (depth == this.depth && !this.textOffset ? 0 : 1);
|
|
16179
|
+
}
|
|
16180
|
+
/**
|
|
16181
|
+
The (absolute) position at the start of the node at the given
|
|
16182
|
+
level.
|
|
16183
|
+
*/
|
|
16184
|
+
start(depth) {
|
|
16185
|
+
depth = this.resolveDepth(depth);
|
|
16186
|
+
return depth == 0 ? 0 : this.path[depth * 3 - 1] + 1;
|
|
16187
|
+
}
|
|
16188
|
+
/**
|
|
16189
|
+
The (absolute) position at the end of the node at the given
|
|
16190
|
+
level.
|
|
16191
|
+
*/
|
|
16192
|
+
end(depth) {
|
|
16193
|
+
depth = this.resolveDepth(depth);
|
|
16194
|
+
return this.start(depth) + this.node(depth).content.size;
|
|
16195
|
+
}
|
|
16196
|
+
/**
|
|
16197
|
+
The (absolute) position directly before the wrapping node at the
|
|
16198
|
+
given level, or, when `depth` is `this.depth + 1`, the original
|
|
16199
|
+
position.
|
|
16200
|
+
*/
|
|
16201
|
+
before(depth) {
|
|
16202
|
+
depth = this.resolveDepth(depth);
|
|
16203
|
+
if (!depth)
|
|
16204
|
+
throw new RangeError("There is no position before the top-level node");
|
|
16205
|
+
return depth == this.depth + 1 ? this.pos : this.path[depth * 3 - 1];
|
|
16206
|
+
}
|
|
16207
|
+
/**
|
|
16208
|
+
The (absolute) position directly after the wrapping node at the
|
|
16209
|
+
given level, or the original position when `depth` is `this.depth + 1`.
|
|
16210
|
+
*/
|
|
16211
|
+
after(depth) {
|
|
16212
|
+
depth = this.resolveDepth(depth);
|
|
16213
|
+
if (!depth)
|
|
16214
|
+
throw new RangeError("There is no position after the top-level node");
|
|
16215
|
+
return depth == this.depth + 1 ? this.pos : this.path[depth * 3 - 1] + this.path[depth * 3].nodeSize;
|
|
16216
|
+
}
|
|
16217
|
+
/**
|
|
16218
|
+
When this position points into a text node, this returns the
|
|
16219
|
+
distance between the position and the start of the text node.
|
|
16220
|
+
Will be zero for positions that point between nodes.
|
|
16221
|
+
*/
|
|
16222
|
+
get textOffset() {
|
|
16223
|
+
return this.pos - this.path[this.path.length - 1];
|
|
16224
|
+
}
|
|
16225
|
+
/**
|
|
16226
|
+
Get the node directly after the position, if any. If the position
|
|
16227
|
+
points into a text node, only the part of that node after the
|
|
16228
|
+
position is returned.
|
|
16229
|
+
*/
|
|
16230
|
+
get nodeAfter() {
|
|
16231
|
+
let parent = this.parent, index = this.index(this.depth);
|
|
16232
|
+
if (index == parent.childCount)
|
|
16233
|
+
return null;
|
|
16234
|
+
let dOff = this.pos - this.path[this.path.length - 1], child = parent.child(index);
|
|
16235
|
+
return dOff ? parent.child(index).cut(dOff) : child;
|
|
16236
|
+
}
|
|
16237
|
+
/**
|
|
16238
|
+
Get the node directly before the position, if any. If the
|
|
16239
|
+
position points into a text node, only the part of that node
|
|
16240
|
+
before the position is returned.
|
|
16241
|
+
*/
|
|
16242
|
+
get nodeBefore() {
|
|
16243
|
+
let index = this.index(this.depth);
|
|
16244
|
+
let dOff = this.pos - this.path[this.path.length - 1];
|
|
16245
|
+
if (dOff)
|
|
16246
|
+
return this.parent.child(index).cut(0, dOff);
|
|
16247
|
+
return index == 0 ? null : this.parent.child(index - 1);
|
|
16248
|
+
}
|
|
16249
|
+
/**
|
|
16250
|
+
Get the position at the given index in the parent node at the
|
|
16251
|
+
given depth (which defaults to `this.depth`).
|
|
16252
|
+
*/
|
|
16253
|
+
posAtIndex(index, depth) {
|
|
16254
|
+
depth = this.resolveDepth(depth);
|
|
16255
|
+
let node = this.path[depth * 3], pos = depth == 0 ? 0 : this.path[depth * 3 - 1] + 1;
|
|
16256
|
+
for (let i = 0; i < index; i++)
|
|
16257
|
+
pos += node.child(i).nodeSize;
|
|
16258
|
+
return pos;
|
|
16259
|
+
}
|
|
16260
|
+
/**
|
|
16261
|
+
Get the marks at this position, factoring in the surrounding
|
|
16262
|
+
marks' [`inclusive`](https://prosemirror.net/docs/ref/#model.MarkSpec.inclusive) property. If the
|
|
16263
|
+
position is at the start of a non-empty node, the marks of the
|
|
16264
|
+
node after it (if any) are returned.
|
|
16265
|
+
*/
|
|
16266
|
+
marks() {
|
|
16267
|
+
let parent = this.parent, index = this.index();
|
|
16268
|
+
if (parent.content.size == 0)
|
|
16269
|
+
return Mark.none;
|
|
16270
|
+
if (this.textOffset)
|
|
16271
|
+
return parent.child(index).marks;
|
|
16272
|
+
let main = parent.maybeChild(index - 1), other = parent.maybeChild(index);
|
|
16273
|
+
if (!main) {
|
|
16274
|
+
let tmp = main;
|
|
16275
|
+
main = other;
|
|
16276
|
+
other = tmp;
|
|
16277
|
+
}
|
|
16278
|
+
let marks = main.marks;
|
|
16279
|
+
for (var i = 0; i < marks.length; i++)
|
|
16280
|
+
if (marks[i].type.spec.inclusive === false && (!other || !marks[i].isInSet(other.marks)))
|
|
16281
|
+
marks = marks[i--].removeFromSet(marks);
|
|
16282
|
+
return marks;
|
|
16283
|
+
}
|
|
16284
|
+
/**
|
|
16285
|
+
Get the marks after the current position, if any, except those
|
|
16286
|
+
that are non-inclusive and not present at position `$end`. This
|
|
16287
|
+
is mostly useful for getting the set of marks to preserve after a
|
|
16288
|
+
deletion. Will return `null` if this position is at the end of
|
|
16289
|
+
its parent node or its parent node isn't a textblock (in which
|
|
16290
|
+
case no marks should be preserved).
|
|
16291
|
+
*/
|
|
16292
|
+
marksAcross($end) {
|
|
16293
|
+
let after = this.parent.maybeChild(this.index());
|
|
16294
|
+
if (!after || !after.isInline)
|
|
16295
|
+
return null;
|
|
16296
|
+
let marks = after.marks, next = $end.parent.maybeChild($end.index());
|
|
16297
|
+
for (var i = 0; i < marks.length; i++)
|
|
16298
|
+
if (marks[i].type.spec.inclusive === false && (!next || !marks[i].isInSet(next.marks)))
|
|
16299
|
+
marks = marks[i--].removeFromSet(marks);
|
|
16300
|
+
return marks;
|
|
16301
|
+
}
|
|
16302
|
+
/**
|
|
16303
|
+
The depth up to which this position and the given (non-resolved)
|
|
16304
|
+
position share the same parent nodes.
|
|
16305
|
+
*/
|
|
16306
|
+
sharedDepth(pos) {
|
|
16307
|
+
for (let depth = this.depth; depth > 0; depth--)
|
|
16308
|
+
if (this.start(depth) <= pos && this.end(depth) >= pos)
|
|
16309
|
+
return depth;
|
|
16310
|
+
return 0;
|
|
16311
|
+
}
|
|
16312
|
+
/**
|
|
16313
|
+
Returns a range based on the place where this position and the
|
|
16314
|
+
given position diverge around block content. If both point into
|
|
16315
|
+
the same textblock, for example, a range around that textblock
|
|
16316
|
+
will be returned. If they point into different blocks, the range
|
|
16317
|
+
around those blocks in their shared ancestor is returned. You can
|
|
16318
|
+
pass in an optional predicate that will be called with a parent
|
|
16319
|
+
node to see if a range into that parent is acceptable.
|
|
16320
|
+
*/
|
|
16321
|
+
blockRange(other = this, pred) {
|
|
16322
|
+
if (other.pos < this.pos)
|
|
16323
|
+
return other.blockRange(this);
|
|
16324
|
+
for (let d = this.depth - (this.parent.inlineContent || this.pos == other.pos ? 1 : 0); d >= 0; d--)
|
|
16325
|
+
if (other.pos <= this.end(d) && (!pred || pred(this.node(d))))
|
|
16326
|
+
return new NodeRange(this, other, d);
|
|
16327
|
+
return null;
|
|
16328
|
+
}
|
|
16329
|
+
/**
|
|
16330
|
+
Query whether the given position shares the same parent node.
|
|
16331
|
+
*/
|
|
16332
|
+
sameParent(other) {
|
|
16333
|
+
return this.pos - this.parentOffset == other.pos - other.parentOffset;
|
|
16334
|
+
}
|
|
16335
|
+
/**
|
|
16336
|
+
Return the greater of this and the given position.
|
|
16337
|
+
*/
|
|
16338
|
+
max(other) {
|
|
16339
|
+
return other.pos > this.pos ? other : this;
|
|
16340
|
+
}
|
|
16341
|
+
/**
|
|
16342
|
+
Return the smaller of this and the given position.
|
|
16343
|
+
*/
|
|
16344
|
+
min(other) {
|
|
16345
|
+
return other.pos < this.pos ? other : this;
|
|
16346
|
+
}
|
|
16347
|
+
/**
|
|
16348
|
+
@internal
|
|
16349
|
+
*/
|
|
16350
|
+
toString() {
|
|
16351
|
+
let str = "";
|
|
16352
|
+
for (let i = 1; i <= this.depth; i++)
|
|
16353
|
+
str += (str ? "/" : "") + this.node(i).type.name + "_" + this.index(i - 1);
|
|
16354
|
+
return str + ":" + this.parentOffset;
|
|
16355
|
+
}
|
|
16356
|
+
/**
|
|
16357
|
+
@internal
|
|
16358
|
+
*/
|
|
16359
|
+
static resolve(doc, pos) {
|
|
16360
|
+
if (!(pos >= 0 && pos <= doc.content.size))
|
|
16361
|
+
throw new RangeError("Position " + pos + " out of range");
|
|
16362
|
+
let path = [];
|
|
16363
|
+
let start = 0, parentOffset = pos;
|
|
16364
|
+
for (let node = doc; ; ) {
|
|
16365
|
+
let { index, offset } = node.content.findIndex(parentOffset);
|
|
16366
|
+
let rem = parentOffset - offset;
|
|
16367
|
+
path.push(node, index, start + offset);
|
|
16368
|
+
if (!rem)
|
|
16369
|
+
break;
|
|
16370
|
+
node = node.child(index);
|
|
16371
|
+
if (node.isText)
|
|
16372
|
+
break;
|
|
16373
|
+
parentOffset = rem - 1;
|
|
16374
|
+
start += offset + 1;
|
|
16375
|
+
}
|
|
16376
|
+
return new _ResolvedPos(pos, path, parentOffset);
|
|
16377
|
+
}
|
|
16378
|
+
/**
|
|
16379
|
+
@internal
|
|
16380
|
+
*/
|
|
16381
|
+
static resolveCached(doc, pos) {
|
|
16382
|
+
let cache = resolveCache.get(doc);
|
|
16383
|
+
if (cache) {
|
|
16384
|
+
for (let i = 0; i < cache.elts.length; i++) {
|
|
16385
|
+
let elt = cache.elts[i];
|
|
16386
|
+
if (elt.pos == pos)
|
|
16387
|
+
return elt;
|
|
16388
|
+
}
|
|
16389
|
+
} else {
|
|
16390
|
+
resolveCache.set(doc, cache = new ResolveCache());
|
|
16391
|
+
}
|
|
16392
|
+
let result = cache.elts[cache.i] = _ResolvedPos.resolve(doc, pos);
|
|
16393
|
+
cache.i = (cache.i + 1) % resolveCacheSize;
|
|
16394
|
+
return result;
|
|
16395
|
+
}
|
|
16396
|
+
};
|
|
16397
|
+
var ResolveCache = class {
|
|
16398
|
+
constructor() {
|
|
16399
|
+
this.elts = [];
|
|
16400
|
+
this.i = 0;
|
|
16401
|
+
}
|
|
16402
|
+
};
|
|
16403
|
+
var resolveCacheSize = 12;
|
|
16404
|
+
var resolveCache = /* @__PURE__ */ new WeakMap();
|
|
16405
|
+
var NodeRange = class {
|
|
16406
|
+
/**
|
|
16407
|
+
Construct a node range. `$from` and `$to` should point into the
|
|
16408
|
+
same node until at least the given `depth`, since a node range
|
|
16409
|
+
denotes an adjacent set of nodes in a single parent node.
|
|
16410
|
+
*/
|
|
16411
|
+
constructor($from, $to, depth) {
|
|
16412
|
+
this.$from = $from;
|
|
16413
|
+
this.$to = $to;
|
|
16414
|
+
this.depth = depth;
|
|
16415
|
+
}
|
|
16416
|
+
/**
|
|
16417
|
+
The position at the start of the range.
|
|
16418
|
+
*/
|
|
16419
|
+
get start() {
|
|
16420
|
+
return this.$from.before(this.depth + 1);
|
|
16421
|
+
}
|
|
16422
|
+
/**
|
|
16423
|
+
The position at the end of the range.
|
|
16424
|
+
*/
|
|
16425
|
+
get end() {
|
|
16426
|
+
return this.$to.after(this.depth + 1);
|
|
16427
|
+
}
|
|
16428
|
+
/**
|
|
16429
|
+
The parent node that the range points into.
|
|
16430
|
+
*/
|
|
16431
|
+
get parent() {
|
|
16432
|
+
return this.$from.node(this.depth);
|
|
16433
|
+
}
|
|
16434
|
+
/**
|
|
16435
|
+
The start index of the range in the parent node.
|
|
16436
|
+
*/
|
|
16437
|
+
get startIndex() {
|
|
16438
|
+
return this.$from.index(this.depth);
|
|
16439
|
+
}
|
|
16440
|
+
/**
|
|
16441
|
+
The end index of the range in the parent node.
|
|
16442
|
+
*/
|
|
16443
|
+
get endIndex() {
|
|
16444
|
+
return this.$to.indexAfter(this.depth);
|
|
16445
|
+
}
|
|
16446
|
+
};
|
|
16447
|
+
var emptyAttrs = /* @__PURE__ */ Object.create(null);
|
|
16448
|
+
var Node = class _Node {
|
|
16449
|
+
/**
|
|
16450
|
+
@internal
|
|
16451
|
+
*/
|
|
16452
|
+
constructor(type, attrs, content, marks = Mark.none) {
|
|
16453
|
+
this.type = type;
|
|
16454
|
+
this.attrs = attrs;
|
|
16455
|
+
this.marks = marks;
|
|
16456
|
+
this.content = content || Fragment25.empty;
|
|
16457
|
+
}
|
|
16458
|
+
/**
|
|
16459
|
+
The array of this node's child nodes.
|
|
16460
|
+
*/
|
|
16461
|
+
get children() {
|
|
16462
|
+
return this.content.content;
|
|
16463
|
+
}
|
|
16464
|
+
/**
|
|
16465
|
+
The size of this node, as defined by the integer-based [indexing
|
|
16466
|
+
scheme](https://prosemirror.net/docs/guide/#doc.indexing). For text nodes, this is the
|
|
16467
|
+
amount of characters. For other leaf nodes, it is one. For
|
|
16468
|
+
non-leaf nodes, it is the size of the content plus two (the
|
|
16469
|
+
start and end token).
|
|
16470
|
+
*/
|
|
16471
|
+
get nodeSize() {
|
|
16472
|
+
return this.isLeaf ? 1 : 2 + this.content.size;
|
|
16473
|
+
}
|
|
16474
|
+
/**
|
|
16475
|
+
The number of children that the node has.
|
|
16476
|
+
*/
|
|
16477
|
+
get childCount() {
|
|
16478
|
+
return this.content.childCount;
|
|
16479
|
+
}
|
|
16480
|
+
/**
|
|
16481
|
+
Get the child node at the given index. Raises an error when the
|
|
16482
|
+
index is out of range.
|
|
16483
|
+
*/
|
|
16484
|
+
child(index) {
|
|
16485
|
+
return this.content.child(index);
|
|
16486
|
+
}
|
|
16487
|
+
/**
|
|
16488
|
+
Get the child node at the given index, if it exists.
|
|
16489
|
+
*/
|
|
16490
|
+
maybeChild(index) {
|
|
16491
|
+
return this.content.maybeChild(index);
|
|
16492
|
+
}
|
|
16493
|
+
/**
|
|
16494
|
+
Call `f` for every child node, passing the node, its offset
|
|
16495
|
+
into this parent node, and its index.
|
|
16496
|
+
*/
|
|
16497
|
+
forEach(f) {
|
|
16498
|
+
this.content.forEach(f);
|
|
16499
|
+
}
|
|
16500
|
+
/**
|
|
16501
|
+
Invoke a callback for all descendant nodes recursively between
|
|
16502
|
+
the given two positions that are relative to start of this
|
|
16503
|
+
node's content. The callback is invoked with the node, its
|
|
16504
|
+
position relative to the original node (method receiver),
|
|
16505
|
+
its parent node, and its child index. When the callback returns
|
|
16506
|
+
false for a given node, that node's children will not be
|
|
16507
|
+
recursed over. The last parameter can be used to specify a
|
|
16508
|
+
starting position to count from.
|
|
16509
|
+
*/
|
|
16510
|
+
nodesBetween(from, to, f, startPos = 0) {
|
|
16511
|
+
this.content.nodesBetween(from, to, f, startPos, this);
|
|
16512
|
+
}
|
|
16513
|
+
/**
|
|
16514
|
+
Call the given callback for every descendant node. Doesn't
|
|
16515
|
+
descend into a node when the callback returns `false`.
|
|
16516
|
+
*/
|
|
16517
|
+
descendants(f) {
|
|
16518
|
+
this.nodesBetween(0, this.content.size, f);
|
|
16519
|
+
}
|
|
16520
|
+
/**
|
|
16521
|
+
Concatenates all the text nodes found in this fragment and its
|
|
16522
|
+
children.
|
|
16523
|
+
*/
|
|
16524
|
+
get textContent() {
|
|
16525
|
+
return this.isLeaf && this.type.spec.leafText ? this.type.spec.leafText(this) : this.textBetween(0, this.content.size, "");
|
|
16526
|
+
}
|
|
16527
|
+
/**
|
|
16528
|
+
Get all text between positions `from` and `to`. When
|
|
16529
|
+
`blockSeparator` is given, it will be inserted to separate text
|
|
16530
|
+
from different block nodes. If `leafText` is given, it'll be
|
|
16531
|
+
inserted for every non-text leaf node encountered, otherwise
|
|
16532
|
+
[`leafText`](https://prosemirror.net/docs/ref/#model.NodeSpec.leafText) will be used.
|
|
16533
|
+
*/
|
|
16534
|
+
textBetween(from, to, blockSeparator, leafText) {
|
|
16535
|
+
return this.content.textBetween(from, to, blockSeparator, leafText);
|
|
16536
|
+
}
|
|
16537
|
+
/**
|
|
16538
|
+
Returns this node's first child, or `null` if there are no
|
|
16539
|
+
children.
|
|
16540
|
+
*/
|
|
16541
|
+
get firstChild() {
|
|
16542
|
+
return this.content.firstChild;
|
|
16543
|
+
}
|
|
16544
|
+
/**
|
|
16545
|
+
Returns this node's last child, or `null` if there are no
|
|
16546
|
+
children.
|
|
16547
|
+
*/
|
|
16548
|
+
get lastChild() {
|
|
16549
|
+
return this.content.lastChild;
|
|
16550
|
+
}
|
|
16551
|
+
/**
|
|
16552
|
+
Test whether two nodes represent the same piece of document.
|
|
16553
|
+
*/
|
|
16554
|
+
eq(other) {
|
|
16555
|
+
return this == other || this.sameMarkup(other) && this.content.eq(other.content);
|
|
16556
|
+
}
|
|
16557
|
+
/**
|
|
16558
|
+
Compare the markup (type, attributes, and marks) of this node to
|
|
16559
|
+
those of another. Returns `true` if both have the same markup.
|
|
16560
|
+
*/
|
|
16561
|
+
sameMarkup(other) {
|
|
16562
|
+
return this.hasMarkup(other.type, other.attrs, other.marks);
|
|
16563
|
+
}
|
|
16564
|
+
/**
|
|
16565
|
+
Check whether this node's markup correspond to the given type,
|
|
16566
|
+
attributes, and marks.
|
|
16567
|
+
*/
|
|
16568
|
+
hasMarkup(type, attrs, marks) {
|
|
16569
|
+
return this.type == type && compareDeep(this.attrs, attrs || type.defaultAttrs || emptyAttrs) && Mark.sameSet(this.marks, marks || Mark.none);
|
|
16570
|
+
}
|
|
16571
|
+
/**
|
|
16572
|
+
Create a new node with the same markup as this node, containing
|
|
16573
|
+
the given content (or empty, if no content is given).
|
|
16574
|
+
*/
|
|
16575
|
+
copy(content = null) {
|
|
16576
|
+
if (content == this.content)
|
|
16577
|
+
return this;
|
|
16578
|
+
return new _Node(this.type, this.attrs, content, this.marks);
|
|
16579
|
+
}
|
|
16580
|
+
/**
|
|
16581
|
+
Create a copy of this node, with the given set of marks instead
|
|
16582
|
+
of the node's own marks.
|
|
16583
|
+
*/
|
|
16584
|
+
mark(marks) {
|
|
16585
|
+
return marks == this.marks ? this : new _Node(this.type, this.attrs, this.content, marks);
|
|
16586
|
+
}
|
|
16587
|
+
/**
|
|
16588
|
+
Create a copy of this node with only the content between the
|
|
16589
|
+
given positions. If `to` is not given, it defaults to the end of
|
|
16590
|
+
the node.
|
|
16591
|
+
*/
|
|
16592
|
+
cut(from, to = this.content.size) {
|
|
16593
|
+
if (from == 0 && to == this.content.size)
|
|
16594
|
+
return this;
|
|
16595
|
+
return this.copy(this.content.cut(from, to));
|
|
16596
|
+
}
|
|
16597
|
+
/**
|
|
16598
|
+
Cut out the part of the document between the given positions, and
|
|
16599
|
+
return it as a `Slice` object.
|
|
16600
|
+
*/
|
|
16601
|
+
slice(from, to = this.content.size, includeParents = false) {
|
|
16602
|
+
if (from == to)
|
|
16603
|
+
return Slice.empty;
|
|
16604
|
+
let $from = this.resolve(from), $to = this.resolve(to);
|
|
16605
|
+
let depth = includeParents ? 0 : $from.sharedDepth(to);
|
|
16606
|
+
let start = $from.start(depth), node = $from.node(depth);
|
|
16607
|
+
let content = node.content.cut($from.pos - start, $to.pos - start);
|
|
16608
|
+
return new Slice(content, $from.depth - depth, $to.depth - depth);
|
|
16609
|
+
}
|
|
16610
|
+
/**
|
|
16611
|
+
Replace the part of the document between the given positions with
|
|
16612
|
+
the given slice. The slice must 'fit', meaning its open sides
|
|
16613
|
+
must be able to connect to the surrounding content, and its
|
|
16614
|
+
content nodes must be valid children for the node they are placed
|
|
16615
|
+
into. If any of this is violated, an error of type
|
|
16616
|
+
[`ReplaceError`](https://prosemirror.net/docs/ref/#model.ReplaceError) is thrown.
|
|
16617
|
+
*/
|
|
16618
|
+
replace(from, to, slice) {
|
|
16619
|
+
return replace(this.resolve(from), this.resolve(to), slice);
|
|
16620
|
+
}
|
|
16621
|
+
/**
|
|
16622
|
+
Find the node directly after the given position.
|
|
16623
|
+
*/
|
|
16624
|
+
nodeAt(pos) {
|
|
16625
|
+
for (let node = this; ; ) {
|
|
16626
|
+
let { index, offset } = node.content.findIndex(pos);
|
|
16627
|
+
node = node.maybeChild(index);
|
|
16628
|
+
if (!node)
|
|
16629
|
+
return null;
|
|
16630
|
+
if (offset == pos || node.isText)
|
|
16631
|
+
return node;
|
|
16632
|
+
pos -= offset + 1;
|
|
16633
|
+
}
|
|
16634
|
+
}
|
|
16635
|
+
/**
|
|
16636
|
+
Find the (direct) child node after the given offset, if any,
|
|
16637
|
+
and return it along with its index and offset relative to this
|
|
16638
|
+
node.
|
|
16639
|
+
*/
|
|
16640
|
+
childAfter(pos) {
|
|
16641
|
+
let { index, offset } = this.content.findIndex(pos);
|
|
16642
|
+
return { node: this.content.maybeChild(index), index, offset };
|
|
16643
|
+
}
|
|
16644
|
+
/**
|
|
16645
|
+
Find the (direct) child node before the given offset, if any,
|
|
16646
|
+
and return it along with its index and offset relative to this
|
|
16647
|
+
node.
|
|
16648
|
+
*/
|
|
16649
|
+
childBefore(pos) {
|
|
16650
|
+
if (pos == 0)
|
|
16651
|
+
return { node: null, index: 0, offset: 0 };
|
|
16652
|
+
let { index, offset } = this.content.findIndex(pos);
|
|
16653
|
+
if (offset < pos)
|
|
16654
|
+
return { node: this.content.child(index), index, offset };
|
|
16655
|
+
let node = this.content.child(index - 1);
|
|
16656
|
+
return { node, index: index - 1, offset: offset - node.nodeSize };
|
|
16657
|
+
}
|
|
16658
|
+
/**
|
|
16659
|
+
Resolve the given position in the document, returning an
|
|
16660
|
+
[object](https://prosemirror.net/docs/ref/#model.ResolvedPos) with information about its context.
|
|
16661
|
+
*/
|
|
16662
|
+
resolve(pos) {
|
|
16663
|
+
return ResolvedPos.resolveCached(this, pos);
|
|
16664
|
+
}
|
|
16665
|
+
/**
|
|
16666
|
+
@internal
|
|
16667
|
+
*/
|
|
16668
|
+
resolveNoCache(pos) {
|
|
16669
|
+
return ResolvedPos.resolve(this, pos);
|
|
16670
|
+
}
|
|
16671
|
+
/**
|
|
16672
|
+
Test whether a given mark or mark type occurs in this document
|
|
16673
|
+
between the two given positions.
|
|
16674
|
+
*/
|
|
16675
|
+
rangeHasMark(from, to, type) {
|
|
16676
|
+
let found2 = false;
|
|
16677
|
+
if (to > from)
|
|
16678
|
+
this.nodesBetween(from, to, (node) => {
|
|
16679
|
+
if (type.isInSet(node.marks))
|
|
16680
|
+
found2 = true;
|
|
16681
|
+
return !found2;
|
|
16682
|
+
});
|
|
16683
|
+
return found2;
|
|
16684
|
+
}
|
|
16685
|
+
/**
|
|
16686
|
+
True when this is a block (non-inline node)
|
|
16687
|
+
*/
|
|
16688
|
+
get isBlock() {
|
|
16689
|
+
return this.type.isBlock;
|
|
16690
|
+
}
|
|
16691
|
+
/**
|
|
16692
|
+
True when this is a textblock node, a block node with inline
|
|
16693
|
+
content.
|
|
16694
|
+
*/
|
|
16695
|
+
get isTextblock() {
|
|
16696
|
+
return this.type.isTextblock;
|
|
16697
|
+
}
|
|
16698
|
+
/**
|
|
16699
|
+
True when this node allows inline content.
|
|
16700
|
+
*/
|
|
16701
|
+
get inlineContent() {
|
|
16702
|
+
return this.type.inlineContent;
|
|
16703
|
+
}
|
|
16704
|
+
/**
|
|
16705
|
+
True when this is an inline node (a text node or a node that can
|
|
16706
|
+
appear among text).
|
|
16707
|
+
*/
|
|
16708
|
+
get isInline() {
|
|
16709
|
+
return this.type.isInline;
|
|
16710
|
+
}
|
|
16711
|
+
/**
|
|
16712
|
+
True when this is a text node.
|
|
16713
|
+
*/
|
|
16714
|
+
get isText() {
|
|
16715
|
+
return this.type.isText;
|
|
16716
|
+
}
|
|
16717
|
+
/**
|
|
16718
|
+
True when this is a leaf node.
|
|
16719
|
+
*/
|
|
16720
|
+
get isLeaf() {
|
|
16721
|
+
return this.type.isLeaf;
|
|
16722
|
+
}
|
|
16723
|
+
/**
|
|
16724
|
+
True when this is an atom, i.e. when it does not have directly
|
|
16725
|
+
editable content. This is usually the same as `isLeaf`, but can
|
|
16726
|
+
be configured with the [`atom` property](https://prosemirror.net/docs/ref/#model.NodeSpec.atom)
|
|
16727
|
+
on a node's spec (typically used when the node is displayed as
|
|
16728
|
+
an uneditable [node view](https://prosemirror.net/docs/ref/#view.NodeView)).
|
|
16729
|
+
*/
|
|
16730
|
+
get isAtom() {
|
|
16731
|
+
return this.type.isAtom;
|
|
16732
|
+
}
|
|
16733
|
+
/**
|
|
16734
|
+
Return a string representation of this node for debugging
|
|
16735
|
+
purposes.
|
|
16736
|
+
*/
|
|
16737
|
+
toString() {
|
|
16738
|
+
if (this.type.spec.toDebugString)
|
|
16739
|
+
return this.type.spec.toDebugString(this);
|
|
16740
|
+
let name = this.type.name;
|
|
16741
|
+
if (this.content.size)
|
|
16742
|
+
name += "(" + this.content.toStringInner() + ")";
|
|
16743
|
+
return wrapMarks(this.marks, name);
|
|
16744
|
+
}
|
|
16745
|
+
/**
|
|
16746
|
+
Get the content match in this node at the given index.
|
|
16747
|
+
*/
|
|
16748
|
+
contentMatchAt(index) {
|
|
16749
|
+
let match = this.type.contentMatch.matchFragment(this.content, 0, index);
|
|
16750
|
+
if (!match)
|
|
16751
|
+
throw new Error("Called contentMatchAt on a node with invalid content");
|
|
16752
|
+
return match;
|
|
16753
|
+
}
|
|
16754
|
+
/**
|
|
16755
|
+
Test whether replacing the range between `from` and `to` (by
|
|
16756
|
+
child index) with the given replacement fragment (which defaults
|
|
16757
|
+
to the empty fragment) would leave the node's content valid. You
|
|
16758
|
+
can optionally pass `start` and `end` indices into the
|
|
16759
|
+
replacement fragment.
|
|
16760
|
+
*/
|
|
16761
|
+
canReplace(from, to, replacement = Fragment25.empty, start = 0, end = replacement.childCount) {
|
|
16762
|
+
let one = this.contentMatchAt(from).matchFragment(replacement, start, end);
|
|
16763
|
+
let two = one && one.matchFragment(this.content, to);
|
|
16764
|
+
if (!two || !two.validEnd)
|
|
16765
|
+
return false;
|
|
16766
|
+
for (let i = start; i < end; i++)
|
|
16767
|
+
if (!this.type.allowsMarks(replacement.child(i).marks))
|
|
16768
|
+
return false;
|
|
16769
|
+
return true;
|
|
16770
|
+
}
|
|
16771
|
+
/**
|
|
16772
|
+
Test whether replacing the range `from` to `to` (by index) with
|
|
16773
|
+
a node of the given type would leave the node's content valid.
|
|
16774
|
+
*/
|
|
16775
|
+
canReplaceWith(from, to, type, marks) {
|
|
16776
|
+
if (marks && !this.type.allowsMarks(marks))
|
|
16777
|
+
return false;
|
|
16778
|
+
let start = this.contentMatchAt(from).matchType(type);
|
|
16779
|
+
let end = start && start.matchFragment(this.content, to);
|
|
16780
|
+
return end ? end.validEnd : false;
|
|
16781
|
+
}
|
|
16782
|
+
/**
|
|
16783
|
+
Test whether the given node's content could be appended to this
|
|
16784
|
+
node. If that node is empty, this will only return true if there
|
|
16785
|
+
is at least one node type that can appear in both nodes (to avoid
|
|
16786
|
+
merging completely incompatible nodes).
|
|
16787
|
+
*/
|
|
16788
|
+
canAppend(other) {
|
|
16789
|
+
if (other.content.size)
|
|
16790
|
+
return this.canReplace(this.childCount, this.childCount, other.content);
|
|
16791
|
+
else
|
|
16792
|
+
return this.type.compatibleContent(other.type);
|
|
16793
|
+
}
|
|
16794
|
+
/**
|
|
16795
|
+
Check whether this node and its descendants conform to the
|
|
16796
|
+
schema, and raise an exception when they do not.
|
|
16797
|
+
*/
|
|
16798
|
+
check() {
|
|
16799
|
+
this.type.checkContent(this.content);
|
|
16800
|
+
this.type.checkAttrs(this.attrs);
|
|
16801
|
+
let copy = Mark.none;
|
|
16802
|
+
for (let i = 0; i < this.marks.length; i++) {
|
|
16803
|
+
let mark = this.marks[i];
|
|
16804
|
+
mark.type.checkAttrs(mark.attrs);
|
|
16805
|
+
copy = mark.addToSet(copy);
|
|
16806
|
+
}
|
|
16807
|
+
if (!Mark.sameSet(copy, this.marks))
|
|
16808
|
+
throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map((m) => m.type.name)}`);
|
|
16809
|
+
this.content.forEach((node) => node.check());
|
|
16810
|
+
}
|
|
16811
|
+
/**
|
|
16812
|
+
Return a JSON-serializeable representation of this node.
|
|
16813
|
+
*/
|
|
16814
|
+
toJSON() {
|
|
16815
|
+
let obj = { type: this.type.name };
|
|
16816
|
+
for (let _ in this.attrs) {
|
|
16817
|
+
obj.attrs = this.attrs;
|
|
16818
|
+
break;
|
|
16819
|
+
}
|
|
16820
|
+
if (this.content.size)
|
|
16821
|
+
obj.content = this.content.toJSON();
|
|
16822
|
+
if (this.marks.length)
|
|
16823
|
+
obj.marks = this.marks.map((n) => n.toJSON());
|
|
16824
|
+
return obj;
|
|
16825
|
+
}
|
|
16826
|
+
/**
|
|
16827
|
+
Deserialize a node from its JSON representation.
|
|
16828
|
+
*/
|
|
16829
|
+
static fromJSON(schema, json) {
|
|
16830
|
+
if (!json)
|
|
16831
|
+
throw new RangeError("Invalid input for Node.fromJSON");
|
|
16832
|
+
let marks = void 0;
|
|
16833
|
+
if (json.marks) {
|
|
16834
|
+
if (!Array.isArray(json.marks))
|
|
16835
|
+
throw new RangeError("Invalid mark data for Node.fromJSON");
|
|
16836
|
+
marks = json.marks.map(schema.markFromJSON);
|
|
16837
|
+
}
|
|
16838
|
+
if (json.type == "text") {
|
|
16839
|
+
if (typeof json.text != "string")
|
|
16840
|
+
throw new RangeError("Invalid text node in JSON");
|
|
16841
|
+
return schema.text(json.text, marks);
|
|
16842
|
+
}
|
|
16843
|
+
let content = Fragment25.fromJSON(schema, json.content);
|
|
16844
|
+
let node = schema.nodeType(json.type).create(json.attrs, content, marks);
|
|
16845
|
+
node.type.checkAttrs(node.attrs);
|
|
16846
|
+
return node;
|
|
16847
|
+
}
|
|
16848
|
+
};
|
|
16849
|
+
Node.prototype.text = void 0;
|
|
16850
|
+
function wrapMarks(marks, str) {
|
|
16851
|
+
for (let i = marks.length - 1; i >= 0; i--)
|
|
16852
|
+
str = marks[i].type.name + "(" + str + ")";
|
|
16853
|
+
return str;
|
|
16854
|
+
}
|
|
16855
|
+
var ContentMatch = class _ContentMatch {
|
|
16856
|
+
/**
|
|
16857
|
+
@internal
|
|
16858
|
+
*/
|
|
16859
|
+
constructor(validEnd) {
|
|
16860
|
+
this.validEnd = validEnd;
|
|
16861
|
+
this.next = [];
|
|
16862
|
+
this.wrapCache = [];
|
|
16863
|
+
}
|
|
16864
|
+
/**
|
|
16865
|
+
@internal
|
|
16866
|
+
*/
|
|
16867
|
+
static parse(string, nodeTypes) {
|
|
16868
|
+
let stream = new TokenStream(string, nodeTypes);
|
|
16869
|
+
if (stream.next == null)
|
|
16870
|
+
return _ContentMatch.empty;
|
|
16871
|
+
let expr = parseExpr(stream);
|
|
16872
|
+
if (stream.next)
|
|
16873
|
+
stream.err("Unexpected trailing text");
|
|
16874
|
+
let match = dfa(nfa(expr));
|
|
16875
|
+
checkForDeadEnds(match, stream);
|
|
16876
|
+
return match;
|
|
16877
|
+
}
|
|
16878
|
+
/**
|
|
16879
|
+
Match a node type, returning a match after that node if
|
|
16880
|
+
successful.
|
|
16881
|
+
*/
|
|
16882
|
+
matchType(type) {
|
|
16883
|
+
for (let i = 0; i < this.next.length; i++)
|
|
16884
|
+
if (this.next[i].type == type)
|
|
16885
|
+
return this.next[i].next;
|
|
16886
|
+
return null;
|
|
16887
|
+
}
|
|
16888
|
+
/**
|
|
16889
|
+
Try to match a fragment. Returns the resulting match when
|
|
16890
|
+
successful.
|
|
16891
|
+
*/
|
|
16892
|
+
matchFragment(frag, start = 0, end = frag.childCount) {
|
|
16893
|
+
let cur = this;
|
|
16894
|
+
for (let i = start; cur && i < end; i++)
|
|
16895
|
+
cur = cur.matchType(frag.child(i).type);
|
|
16896
|
+
return cur;
|
|
16897
|
+
}
|
|
16898
|
+
/**
|
|
16899
|
+
@internal
|
|
16900
|
+
*/
|
|
16901
|
+
get inlineContent() {
|
|
16902
|
+
return this.next.length != 0 && this.next[0].type.isInline;
|
|
16903
|
+
}
|
|
16904
|
+
/**
|
|
16905
|
+
Get the first matching node type at this match position that can
|
|
16906
|
+
be generated.
|
|
16907
|
+
*/
|
|
16908
|
+
get defaultType() {
|
|
16909
|
+
for (let i = 0; i < this.next.length; i++) {
|
|
16910
|
+
let { type } = this.next[i];
|
|
16911
|
+
if (!(type.isText || type.hasRequiredAttrs()))
|
|
16912
|
+
return type;
|
|
16913
|
+
}
|
|
16914
|
+
return null;
|
|
16915
|
+
}
|
|
16916
|
+
/**
|
|
16917
|
+
@internal
|
|
16918
|
+
*/
|
|
16919
|
+
compatible(other) {
|
|
16920
|
+
for (let i = 0; i < this.next.length; i++)
|
|
16921
|
+
for (let j = 0; j < other.next.length; j++)
|
|
16922
|
+
if (this.next[i].type == other.next[j].type)
|
|
16923
|
+
return true;
|
|
16924
|
+
return false;
|
|
16925
|
+
}
|
|
16926
|
+
/**
|
|
16927
|
+
Try to match the given fragment, and if that fails, see if it can
|
|
16928
|
+
be made to match by inserting nodes in front of it. When
|
|
16929
|
+
successful, return a fragment of inserted nodes (which may be
|
|
16930
|
+
empty if nothing had to be inserted). When `toEnd` is true, only
|
|
16931
|
+
return a fragment if the resulting match goes to the end of the
|
|
16932
|
+
content expression.
|
|
16933
|
+
*/
|
|
16934
|
+
fillBefore(after, toEnd = false, startIndex = 0) {
|
|
16935
|
+
let seen = [this];
|
|
16936
|
+
function search(match, types) {
|
|
16937
|
+
let finished = match.matchFragment(after, startIndex);
|
|
16938
|
+
if (finished && (!toEnd || finished.validEnd))
|
|
16939
|
+
return Fragment25.from(types.map((tp) => tp.createAndFill()));
|
|
16940
|
+
for (let i = 0; i < match.next.length; i++) {
|
|
16941
|
+
let { type, next } = match.next[i];
|
|
16942
|
+
if (!(type.isText || type.hasRequiredAttrs()) && seen.indexOf(next) == -1) {
|
|
16943
|
+
seen.push(next);
|
|
16944
|
+
let found2 = search(next, types.concat(type));
|
|
16945
|
+
if (found2)
|
|
16946
|
+
return found2;
|
|
16947
|
+
}
|
|
16948
|
+
}
|
|
16949
|
+
return null;
|
|
16950
|
+
}
|
|
16951
|
+
return search(this, []);
|
|
16952
|
+
}
|
|
16953
|
+
/**
|
|
16954
|
+
Find a set of wrapping node types that would allow a node of the
|
|
16955
|
+
given type to appear at this position. The result may be empty
|
|
16956
|
+
(when it fits directly) and will be null when no such wrapping
|
|
16957
|
+
exists.
|
|
16958
|
+
*/
|
|
16959
|
+
findWrapping(target) {
|
|
16960
|
+
for (let i = 0; i < this.wrapCache.length; i += 2)
|
|
16961
|
+
if (this.wrapCache[i] == target)
|
|
16962
|
+
return this.wrapCache[i + 1];
|
|
16963
|
+
let computed = this.computeWrapping(target);
|
|
16964
|
+
this.wrapCache.push(target, computed);
|
|
16965
|
+
return computed;
|
|
16966
|
+
}
|
|
16967
|
+
/**
|
|
16968
|
+
@internal
|
|
16969
|
+
*/
|
|
16970
|
+
computeWrapping(target) {
|
|
16971
|
+
let seen = /* @__PURE__ */ Object.create(null), active = [{ match: this, type: null, via: null }];
|
|
16972
|
+
while (active.length) {
|
|
16973
|
+
let current = active.shift(), match = current.match;
|
|
16974
|
+
if (match.matchType(target)) {
|
|
16975
|
+
let result = [];
|
|
16976
|
+
for (let obj = current; obj.type; obj = obj.via)
|
|
16977
|
+
result.push(obj.type);
|
|
16978
|
+
return result.reverse();
|
|
16979
|
+
}
|
|
16980
|
+
for (let i = 0; i < match.next.length; i++) {
|
|
16981
|
+
let { type, next } = match.next[i];
|
|
16982
|
+
if (!type.isLeaf && !type.hasRequiredAttrs() && !(type.name in seen) && (!current.type || next.validEnd)) {
|
|
16983
|
+
active.push({ match: type.contentMatch, type, via: current });
|
|
16984
|
+
seen[type.name] = true;
|
|
16985
|
+
}
|
|
16986
|
+
}
|
|
16987
|
+
}
|
|
16988
|
+
return null;
|
|
16989
|
+
}
|
|
16990
|
+
/**
|
|
16991
|
+
The number of outgoing edges this node has in the finite
|
|
16992
|
+
automaton that describes the content expression.
|
|
16993
|
+
*/
|
|
16994
|
+
get edgeCount() {
|
|
16995
|
+
return this.next.length;
|
|
16996
|
+
}
|
|
16997
|
+
/**
|
|
16998
|
+
Get the _n_th outgoing edge from this node in the finite
|
|
16999
|
+
automaton that describes the content expression.
|
|
17000
|
+
*/
|
|
17001
|
+
edge(n) {
|
|
17002
|
+
if (n >= this.next.length)
|
|
17003
|
+
throw new RangeError(`There's no ${n}th edge in this content match`);
|
|
17004
|
+
return this.next[n];
|
|
17005
|
+
}
|
|
17006
|
+
/**
|
|
17007
|
+
@internal
|
|
17008
|
+
*/
|
|
17009
|
+
toString() {
|
|
17010
|
+
let seen = [];
|
|
17011
|
+
function scan(m) {
|
|
17012
|
+
seen.push(m);
|
|
17013
|
+
for (let i = 0; i < m.next.length; i++)
|
|
17014
|
+
if (seen.indexOf(m.next[i].next) == -1)
|
|
17015
|
+
scan(m.next[i].next);
|
|
17016
|
+
}
|
|
17017
|
+
scan(this);
|
|
17018
|
+
return seen.map((m, i) => {
|
|
17019
|
+
let out = i + (m.validEnd ? "*" : " ") + " ";
|
|
17020
|
+
for (let i2 = 0; i2 < m.next.length; i2++)
|
|
17021
|
+
out += (i2 ? ", " : "") + m.next[i2].type.name + "->" + seen.indexOf(m.next[i2].next);
|
|
17022
|
+
return out;
|
|
17023
|
+
}).join("\n");
|
|
17024
|
+
}
|
|
17025
|
+
};
|
|
17026
|
+
ContentMatch.empty = new ContentMatch(true);
|
|
17027
|
+
var TokenStream = class {
|
|
17028
|
+
constructor(string, nodeTypes) {
|
|
17029
|
+
this.string = string;
|
|
17030
|
+
this.nodeTypes = nodeTypes;
|
|
17031
|
+
this.inline = null;
|
|
17032
|
+
this.pos = 0;
|
|
17033
|
+
this.tokens = string.split(/\s*(?=\b|\W|$)/);
|
|
17034
|
+
if (this.tokens[this.tokens.length - 1] == "")
|
|
17035
|
+
this.tokens.pop();
|
|
17036
|
+
if (this.tokens[0] == "")
|
|
17037
|
+
this.tokens.shift();
|
|
17038
|
+
}
|
|
17039
|
+
get next() {
|
|
17040
|
+
return this.tokens[this.pos];
|
|
17041
|
+
}
|
|
17042
|
+
eat(tok) {
|
|
17043
|
+
return this.next == tok && (this.pos++ || true);
|
|
17044
|
+
}
|
|
17045
|
+
err(str) {
|
|
17046
|
+
throw new SyntaxError(str + " (in content expression '" + this.string + "')");
|
|
17047
|
+
}
|
|
17048
|
+
};
|
|
17049
|
+
function parseExpr(stream) {
|
|
17050
|
+
let exprs = [];
|
|
17051
|
+
do {
|
|
17052
|
+
exprs.push(parseExprSeq(stream));
|
|
17053
|
+
} while (stream.eat("|"));
|
|
17054
|
+
return exprs.length == 1 ? exprs[0] : { type: "choice", exprs };
|
|
17055
|
+
}
|
|
17056
|
+
function parseExprSeq(stream) {
|
|
17057
|
+
let exprs = [];
|
|
17058
|
+
do {
|
|
17059
|
+
exprs.push(parseExprSubscript(stream));
|
|
17060
|
+
} while (stream.next && stream.next != ")" && stream.next != "|");
|
|
17061
|
+
return exprs.length == 1 ? exprs[0] : { type: "seq", exprs };
|
|
17062
|
+
}
|
|
17063
|
+
function parseExprSubscript(stream) {
|
|
17064
|
+
let expr = parseExprAtom(stream);
|
|
17065
|
+
for (; ; ) {
|
|
17066
|
+
if (stream.eat("+"))
|
|
17067
|
+
expr = { type: "plus", expr };
|
|
17068
|
+
else if (stream.eat("*"))
|
|
17069
|
+
expr = { type: "star", expr };
|
|
17070
|
+
else if (stream.eat("?"))
|
|
17071
|
+
expr = { type: "opt", expr };
|
|
17072
|
+
else if (stream.eat("{"))
|
|
17073
|
+
expr = parseExprRange(stream, expr);
|
|
17074
|
+
else
|
|
17075
|
+
break;
|
|
17076
|
+
}
|
|
17077
|
+
return expr;
|
|
17078
|
+
}
|
|
17079
|
+
function parseNum(stream) {
|
|
17080
|
+
if (/\D/.test(stream.next))
|
|
17081
|
+
stream.err("Expected number, got '" + stream.next + "'");
|
|
17082
|
+
let result = Number(stream.next);
|
|
17083
|
+
stream.pos++;
|
|
17084
|
+
return result;
|
|
17085
|
+
}
|
|
17086
|
+
function parseExprRange(stream, expr) {
|
|
17087
|
+
let min = parseNum(stream), max = min;
|
|
17088
|
+
if (stream.eat(",")) {
|
|
17089
|
+
if (stream.next != "}")
|
|
17090
|
+
max = parseNum(stream);
|
|
17091
|
+
else
|
|
17092
|
+
max = -1;
|
|
17093
|
+
}
|
|
17094
|
+
if (!stream.eat("}"))
|
|
17095
|
+
stream.err("Unclosed braced range");
|
|
17096
|
+
return { type: "range", min, max, expr };
|
|
17097
|
+
}
|
|
17098
|
+
function resolveName(stream, name) {
|
|
17099
|
+
let types = stream.nodeTypes, type = types[name];
|
|
17100
|
+
if (type)
|
|
17101
|
+
return [type];
|
|
17102
|
+
let result = [];
|
|
17103
|
+
for (let typeName in types) {
|
|
17104
|
+
let type2 = types[typeName];
|
|
17105
|
+
if (type2.isInGroup(name))
|
|
17106
|
+
result.push(type2);
|
|
17107
|
+
}
|
|
17108
|
+
if (result.length == 0)
|
|
17109
|
+
stream.err("No node type or group '" + name + "' found");
|
|
17110
|
+
return result;
|
|
17111
|
+
}
|
|
17112
|
+
function parseExprAtom(stream) {
|
|
17113
|
+
if (stream.eat("(")) {
|
|
17114
|
+
let expr = parseExpr(stream);
|
|
17115
|
+
if (!stream.eat(")"))
|
|
17116
|
+
stream.err("Missing closing paren");
|
|
17117
|
+
return expr;
|
|
17118
|
+
} else if (!/\W/.test(stream.next)) {
|
|
17119
|
+
let exprs = resolveName(stream, stream.next).map((type) => {
|
|
17120
|
+
if (stream.inline == null)
|
|
17121
|
+
stream.inline = type.isInline;
|
|
17122
|
+
else if (stream.inline != type.isInline)
|
|
17123
|
+
stream.err("Mixing inline and block content");
|
|
17124
|
+
return { type: "name", value: type };
|
|
17125
|
+
});
|
|
17126
|
+
stream.pos++;
|
|
17127
|
+
return exprs.length == 1 ? exprs[0] : { type: "choice", exprs };
|
|
17128
|
+
} else {
|
|
17129
|
+
stream.err("Unexpected token '" + stream.next + "'");
|
|
17130
|
+
}
|
|
17131
|
+
}
|
|
17132
|
+
function nfa(expr) {
|
|
17133
|
+
let nfa2 = [[]];
|
|
17134
|
+
connect(compile(expr, 0), node());
|
|
17135
|
+
return nfa2;
|
|
17136
|
+
function node() {
|
|
17137
|
+
return nfa2.push([]) - 1;
|
|
17138
|
+
}
|
|
17139
|
+
function edge(from, to, term) {
|
|
17140
|
+
let edge2 = { term, to };
|
|
17141
|
+
nfa2[from].push(edge2);
|
|
17142
|
+
return edge2;
|
|
17143
|
+
}
|
|
17144
|
+
function connect(edges, to) {
|
|
17145
|
+
edges.forEach((edge2) => edge2.to = to);
|
|
17146
|
+
}
|
|
17147
|
+
function compile(expr2, from) {
|
|
17148
|
+
if (expr2.type == "choice") {
|
|
17149
|
+
return expr2.exprs.reduce((out, expr3) => out.concat(compile(expr3, from)), []);
|
|
17150
|
+
} else if (expr2.type == "seq") {
|
|
17151
|
+
for (let i = 0; ; i++) {
|
|
17152
|
+
let next = compile(expr2.exprs[i], from);
|
|
17153
|
+
if (i == expr2.exprs.length - 1)
|
|
17154
|
+
return next;
|
|
17155
|
+
connect(next, from = node());
|
|
17156
|
+
}
|
|
17157
|
+
} else if (expr2.type == "star") {
|
|
17158
|
+
let loop = node();
|
|
17159
|
+
edge(from, loop);
|
|
17160
|
+
connect(compile(expr2.expr, loop), loop);
|
|
17161
|
+
return [edge(loop)];
|
|
17162
|
+
} else if (expr2.type == "plus") {
|
|
17163
|
+
let loop = node();
|
|
17164
|
+
connect(compile(expr2.expr, from), loop);
|
|
17165
|
+
connect(compile(expr2.expr, loop), loop);
|
|
17166
|
+
return [edge(loop)];
|
|
17167
|
+
} else if (expr2.type == "opt") {
|
|
17168
|
+
return [edge(from)].concat(compile(expr2.expr, from));
|
|
17169
|
+
} else if (expr2.type == "range") {
|
|
17170
|
+
let cur = from;
|
|
17171
|
+
for (let i = 0; i < expr2.min; i++) {
|
|
17172
|
+
let next = node();
|
|
17173
|
+
connect(compile(expr2.expr, cur), next);
|
|
17174
|
+
cur = next;
|
|
17175
|
+
}
|
|
17176
|
+
if (expr2.max == -1) {
|
|
17177
|
+
connect(compile(expr2.expr, cur), cur);
|
|
17178
|
+
} else {
|
|
17179
|
+
for (let i = expr2.min; i < expr2.max; i++) {
|
|
17180
|
+
let next = node();
|
|
17181
|
+
edge(cur, next);
|
|
17182
|
+
connect(compile(expr2.expr, cur), next);
|
|
17183
|
+
cur = next;
|
|
17184
|
+
}
|
|
17185
|
+
}
|
|
17186
|
+
return [edge(cur)];
|
|
17187
|
+
} else if (expr2.type == "name") {
|
|
17188
|
+
return [edge(from, void 0, expr2.value)];
|
|
17189
|
+
} else {
|
|
17190
|
+
throw new Error("Unknown expr type");
|
|
17191
|
+
}
|
|
17192
|
+
}
|
|
17193
|
+
}
|
|
17194
|
+
function cmp(a, b) {
|
|
17195
|
+
return b - a;
|
|
17196
|
+
}
|
|
17197
|
+
function nullFrom(nfa2, node) {
|
|
17198
|
+
let result = [];
|
|
17199
|
+
scan(node);
|
|
17200
|
+
return result.sort(cmp);
|
|
17201
|
+
function scan(node2) {
|
|
17202
|
+
let edges = nfa2[node2];
|
|
17203
|
+
if (edges.length == 1 && !edges[0].term)
|
|
17204
|
+
return scan(edges[0].to);
|
|
17205
|
+
result.push(node2);
|
|
17206
|
+
for (let i = 0; i < edges.length; i++) {
|
|
17207
|
+
let { term, to } = edges[i];
|
|
17208
|
+
if (!term && result.indexOf(to) == -1)
|
|
17209
|
+
scan(to);
|
|
17210
|
+
}
|
|
17211
|
+
}
|
|
17212
|
+
}
|
|
17213
|
+
function dfa(nfa2) {
|
|
17214
|
+
let labeled = /* @__PURE__ */ Object.create(null);
|
|
17215
|
+
return explore(nullFrom(nfa2, 0));
|
|
17216
|
+
function explore(states) {
|
|
17217
|
+
let out = [];
|
|
17218
|
+
states.forEach((node) => {
|
|
17219
|
+
nfa2[node].forEach(({ term, to }) => {
|
|
17220
|
+
if (!term)
|
|
17221
|
+
return;
|
|
17222
|
+
let set;
|
|
17223
|
+
for (let i = 0; i < out.length; i++)
|
|
17224
|
+
if (out[i][0] == term)
|
|
17225
|
+
set = out[i][1];
|
|
17226
|
+
nullFrom(nfa2, to).forEach((node2) => {
|
|
17227
|
+
if (!set)
|
|
17228
|
+
out.push([term, set = []]);
|
|
17229
|
+
if (set.indexOf(node2) == -1)
|
|
17230
|
+
set.push(node2);
|
|
17231
|
+
});
|
|
17232
|
+
});
|
|
17233
|
+
});
|
|
17234
|
+
let state = labeled[states.join(",")] = new ContentMatch(states.indexOf(nfa2.length - 1) > -1);
|
|
17235
|
+
for (let i = 0; i < out.length; i++) {
|
|
17236
|
+
let states2 = out[i][1].sort(cmp);
|
|
17237
|
+
state.next.push({ type: out[i][0], next: labeled[states2.join(",")] || explore(states2) });
|
|
17238
|
+
}
|
|
17239
|
+
return state;
|
|
17240
|
+
}
|
|
17241
|
+
}
|
|
17242
|
+
function checkForDeadEnds(match, stream) {
|
|
17243
|
+
for (let i = 0, work = [match]; i < work.length; i++) {
|
|
17244
|
+
let state = work[i], dead = !state.validEnd, nodes = [];
|
|
17245
|
+
for (let j = 0; j < state.next.length; j++) {
|
|
17246
|
+
let { type, next } = state.next[j];
|
|
17247
|
+
nodes.push(type.name);
|
|
17248
|
+
if (dead && !(type.isText || type.hasRequiredAttrs()))
|
|
17249
|
+
dead = false;
|
|
17250
|
+
if (work.indexOf(next) == -1)
|
|
17251
|
+
work.push(next);
|
|
17252
|
+
}
|
|
17253
|
+
if (dead)
|
|
17254
|
+
stream.err("Only non-generatable nodes (" + nodes.join(", ") + ") in a required position (see https://prosemirror.net/docs/guide/#generatable)");
|
|
17255
|
+
}
|
|
17256
|
+
}
|
|
17257
|
+
|
|
17258
|
+
// ../../node_modules/prosemirror-transform/dist/index.js
|
|
17259
|
+
var lower16 = 65535;
|
|
17260
|
+
var factor16 = Math.pow(2, 16);
|
|
17261
|
+
function makeRecover(index, offset) {
|
|
17262
|
+
return index + offset * factor16;
|
|
17263
|
+
}
|
|
17264
|
+
function recoverIndex(value) {
|
|
17265
|
+
return value & lower16;
|
|
17266
|
+
}
|
|
17267
|
+
function recoverOffset(value) {
|
|
17268
|
+
return (value - (value & lower16)) / factor16;
|
|
17269
|
+
}
|
|
17270
|
+
var DEL_BEFORE = 1;
|
|
17271
|
+
var DEL_AFTER = 2;
|
|
17272
|
+
var DEL_ACROSS = 4;
|
|
17273
|
+
var DEL_SIDE = 8;
|
|
17274
|
+
var MapResult = class {
|
|
17275
|
+
/**
|
|
17276
|
+
@internal
|
|
17277
|
+
*/
|
|
17278
|
+
constructor(pos, delInfo, recover) {
|
|
17279
|
+
this.pos = pos;
|
|
17280
|
+
this.delInfo = delInfo;
|
|
17281
|
+
this.recover = recover;
|
|
17282
|
+
}
|
|
17283
|
+
/**
|
|
17284
|
+
Tells you whether the position was deleted, that is, whether the
|
|
17285
|
+
step removed the token on the side queried (via the `assoc`)
|
|
17286
|
+
argument from the document.
|
|
17287
|
+
*/
|
|
17288
|
+
get deleted() {
|
|
17289
|
+
return (this.delInfo & DEL_SIDE) > 0;
|
|
17290
|
+
}
|
|
17291
|
+
/**
|
|
17292
|
+
Tells you whether the token before the mapped position was deleted.
|
|
17293
|
+
*/
|
|
17294
|
+
get deletedBefore() {
|
|
17295
|
+
return (this.delInfo & (DEL_BEFORE | DEL_ACROSS)) > 0;
|
|
17296
|
+
}
|
|
17297
|
+
/**
|
|
17298
|
+
True when the token after the mapped position was deleted.
|
|
17299
|
+
*/
|
|
17300
|
+
get deletedAfter() {
|
|
17301
|
+
return (this.delInfo & (DEL_AFTER | DEL_ACROSS)) > 0;
|
|
17302
|
+
}
|
|
17303
|
+
/**
|
|
17304
|
+
Tells whether any of the steps mapped through deletes across the
|
|
17305
|
+
position (including both the token before and after the
|
|
17306
|
+
position).
|
|
17307
|
+
*/
|
|
17308
|
+
get deletedAcross() {
|
|
17309
|
+
return (this.delInfo & DEL_ACROSS) > 0;
|
|
17310
|
+
}
|
|
17311
|
+
};
|
|
17312
|
+
var StepMap = class _StepMap {
|
|
17313
|
+
/**
|
|
17314
|
+
Create a position map. The modifications to the document are
|
|
17315
|
+
represented as an array of numbers, in which each group of three
|
|
17316
|
+
represents a modified chunk as `[start, oldSize, newSize]`.
|
|
17317
|
+
*/
|
|
17318
|
+
constructor(ranges, inverted = false) {
|
|
17319
|
+
this.ranges = ranges;
|
|
17320
|
+
this.inverted = inverted;
|
|
17321
|
+
if (!ranges.length && _StepMap.empty)
|
|
17322
|
+
return _StepMap.empty;
|
|
17323
|
+
}
|
|
17324
|
+
/**
|
|
17325
|
+
@internal
|
|
17326
|
+
*/
|
|
17327
|
+
recover(value) {
|
|
17328
|
+
let diff = 0, index = recoverIndex(value);
|
|
17329
|
+
if (!this.inverted)
|
|
17330
|
+
for (let i = 0; i < index; i++)
|
|
17331
|
+
diff += this.ranges[i * 3 + 2] - this.ranges[i * 3 + 1];
|
|
17332
|
+
return this.ranges[index * 3] + diff + recoverOffset(value);
|
|
17333
|
+
}
|
|
17334
|
+
mapResult(pos, assoc = 1) {
|
|
17335
|
+
return this._map(pos, assoc, false);
|
|
17336
|
+
}
|
|
17337
|
+
map(pos, assoc = 1) {
|
|
17338
|
+
return this._map(pos, assoc, true);
|
|
17339
|
+
}
|
|
17340
|
+
/**
|
|
17341
|
+
@internal
|
|
17342
|
+
*/
|
|
17343
|
+
_map(pos, assoc, simple) {
|
|
17344
|
+
let diff = 0, oldIndex = this.inverted ? 2 : 1, newIndex = this.inverted ? 1 : 2;
|
|
17345
|
+
for (let i = 0; i < this.ranges.length; i += 3) {
|
|
17346
|
+
let start = this.ranges[i] - (this.inverted ? diff : 0);
|
|
17347
|
+
if (start > pos)
|
|
17348
|
+
break;
|
|
17349
|
+
let oldSize = this.ranges[i + oldIndex], newSize = this.ranges[i + newIndex], end = start + oldSize;
|
|
17350
|
+
if (pos <= end) {
|
|
17351
|
+
let side = !oldSize ? assoc : pos == start ? -1 : pos == end ? 1 : assoc;
|
|
17352
|
+
let result = start + diff + (side < 0 ? 0 : newSize);
|
|
17353
|
+
if (simple)
|
|
17354
|
+
return result;
|
|
17355
|
+
let recover = pos == (assoc < 0 ? start : end) ? null : makeRecover(i / 3, pos - start);
|
|
17356
|
+
let del = pos == start ? DEL_AFTER : pos == end ? DEL_BEFORE : DEL_ACROSS;
|
|
17357
|
+
if (assoc < 0 ? pos != start : pos != end)
|
|
17358
|
+
del |= DEL_SIDE;
|
|
17359
|
+
return new MapResult(result, del, recover);
|
|
17360
|
+
}
|
|
17361
|
+
diff += newSize - oldSize;
|
|
17362
|
+
}
|
|
17363
|
+
return simple ? pos + diff : new MapResult(pos + diff, 0, null);
|
|
17364
|
+
}
|
|
17365
|
+
/**
|
|
17366
|
+
@internal
|
|
17367
|
+
*/
|
|
17368
|
+
touches(pos, recover) {
|
|
17369
|
+
let diff = 0, index = recoverIndex(recover);
|
|
17370
|
+
let oldIndex = this.inverted ? 2 : 1, newIndex = this.inverted ? 1 : 2;
|
|
17371
|
+
for (let i = 0; i < this.ranges.length; i += 3) {
|
|
17372
|
+
let start = this.ranges[i] - (this.inverted ? diff : 0);
|
|
17373
|
+
if (start > pos)
|
|
17374
|
+
break;
|
|
17375
|
+
let oldSize = this.ranges[i + oldIndex], end = start + oldSize;
|
|
17376
|
+
if (pos <= end && i == index * 3)
|
|
17377
|
+
return true;
|
|
17378
|
+
diff += this.ranges[i + newIndex] - oldSize;
|
|
17379
|
+
}
|
|
17380
|
+
return false;
|
|
17381
|
+
}
|
|
17382
|
+
/**
|
|
17383
|
+
Calls the given function on each of the changed ranges included in
|
|
17384
|
+
this map.
|
|
17385
|
+
*/
|
|
17386
|
+
forEach(f) {
|
|
17387
|
+
let oldIndex = this.inverted ? 2 : 1, newIndex = this.inverted ? 1 : 2;
|
|
17388
|
+
for (let i = 0, diff = 0; i < this.ranges.length; i += 3) {
|
|
17389
|
+
let start = this.ranges[i], oldStart = start - (this.inverted ? diff : 0), newStart = start + (this.inverted ? 0 : diff);
|
|
17390
|
+
let oldSize = this.ranges[i + oldIndex], newSize = this.ranges[i + newIndex];
|
|
17391
|
+
f(oldStart, oldStart + oldSize, newStart, newStart + newSize);
|
|
17392
|
+
diff += newSize - oldSize;
|
|
17393
|
+
}
|
|
17394
|
+
}
|
|
17395
|
+
/**
|
|
17396
|
+
Create an inverted version of this map. The result can be used to
|
|
17397
|
+
map positions in the post-step document to the pre-step document.
|
|
17398
|
+
*/
|
|
17399
|
+
invert() {
|
|
17400
|
+
return new _StepMap(this.ranges, !this.inverted);
|
|
17401
|
+
}
|
|
17402
|
+
/**
|
|
17403
|
+
@internal
|
|
17404
|
+
*/
|
|
17405
|
+
toString() {
|
|
17406
|
+
return (this.inverted ? "-" : "") + JSON.stringify(this.ranges);
|
|
17407
|
+
}
|
|
17408
|
+
/**
|
|
17409
|
+
Create a map that moves all positions by offset `n` (which may be
|
|
17410
|
+
negative). This can be useful when applying steps meant for a
|
|
17411
|
+
sub-document to a larger document, or vice-versa.
|
|
17412
|
+
*/
|
|
17413
|
+
static offset(n) {
|
|
17414
|
+
return n == 0 ? _StepMap.empty : new _StepMap(n < 0 ? [0, -n, 0] : [0, 0, n]);
|
|
17415
|
+
}
|
|
17416
|
+
};
|
|
17417
|
+
StepMap.empty = new StepMap([]);
|
|
17418
|
+
var stepsByID = /* @__PURE__ */ Object.create(null);
|
|
17419
|
+
var Step = class {
|
|
17420
|
+
/**
|
|
17421
|
+
Get the step map that represents the changes made by this step,
|
|
17422
|
+
and which can be used to transform between positions in the old
|
|
17423
|
+
and the new document.
|
|
17424
|
+
*/
|
|
17425
|
+
getMap() {
|
|
17426
|
+
return StepMap.empty;
|
|
17427
|
+
}
|
|
17428
|
+
/**
|
|
17429
|
+
Try to merge this step with another one, to be applied directly
|
|
17430
|
+
after it. Returns the merged step when possible, null if the
|
|
17431
|
+
steps can't be merged.
|
|
17432
|
+
*/
|
|
17433
|
+
merge(other) {
|
|
17434
|
+
return null;
|
|
17435
|
+
}
|
|
17436
|
+
/**
|
|
17437
|
+
Deserialize a step from its JSON representation. Will call
|
|
17438
|
+
through to the step class' own implementation of this method.
|
|
17439
|
+
*/
|
|
17440
|
+
static fromJSON(schema, json) {
|
|
17441
|
+
if (!json || !json.stepType)
|
|
17442
|
+
throw new RangeError("Invalid input for Step.fromJSON");
|
|
17443
|
+
let type = stepsByID[json.stepType];
|
|
17444
|
+
if (!type)
|
|
17445
|
+
throw new RangeError(`No step type ${json.stepType} defined`);
|
|
17446
|
+
return type.fromJSON(schema, json);
|
|
17447
|
+
}
|
|
17448
|
+
/**
|
|
17449
|
+
To be able to serialize steps to JSON, each step needs a string
|
|
17450
|
+
ID to attach to its JSON representation. Use this method to
|
|
17451
|
+
register an ID for your step classes. Try to pick something
|
|
17452
|
+
that's unlikely to clash with steps from other modules.
|
|
17453
|
+
*/
|
|
17454
|
+
static jsonID(id, stepClass) {
|
|
17455
|
+
if (id in stepsByID)
|
|
17456
|
+
throw new RangeError("Duplicate use of step JSON ID " + id);
|
|
17457
|
+
stepsByID[id] = stepClass;
|
|
17458
|
+
stepClass.prototype.jsonID = id;
|
|
17459
|
+
return stepClass;
|
|
17460
|
+
}
|
|
17461
|
+
};
|
|
17462
|
+
var StepResult = class _StepResult {
|
|
17463
|
+
/**
|
|
17464
|
+
@internal
|
|
17465
|
+
*/
|
|
17466
|
+
constructor(doc, failed) {
|
|
17467
|
+
this.doc = doc;
|
|
17468
|
+
this.failed = failed;
|
|
17469
|
+
}
|
|
17470
|
+
/**
|
|
17471
|
+
Create a successful step result.
|
|
17472
|
+
*/
|
|
17473
|
+
static ok(doc) {
|
|
17474
|
+
return new _StepResult(doc, null);
|
|
17475
|
+
}
|
|
17476
|
+
/**
|
|
17477
|
+
Create a failed step result.
|
|
17478
|
+
*/
|
|
17479
|
+
static fail(message) {
|
|
17480
|
+
return new _StepResult(null, message);
|
|
17481
|
+
}
|
|
17482
|
+
/**
|
|
17483
|
+
Call [`Node.replace`](https://prosemirror.net/docs/ref/#model.Node.replace) with the given
|
|
17484
|
+
arguments. Create a successful result if it succeeds, and a
|
|
17485
|
+
failed one if it throws a `ReplaceError`.
|
|
17486
|
+
*/
|
|
17487
|
+
static fromReplace(doc, from, to, slice) {
|
|
17488
|
+
try {
|
|
17489
|
+
return _StepResult.ok(doc.replace(from, to, slice));
|
|
17490
|
+
} catch (e) {
|
|
17491
|
+
if (e instanceof ReplaceError)
|
|
17492
|
+
return _StepResult.fail(e.message);
|
|
17493
|
+
throw e;
|
|
17494
|
+
}
|
|
17495
|
+
}
|
|
17496
|
+
};
|
|
17497
|
+
function mapFragment(fragment, f, parent) {
|
|
17498
|
+
let mapped = [];
|
|
17499
|
+
for (let i = 0; i < fragment.childCount; i++) {
|
|
17500
|
+
let child = fragment.child(i);
|
|
17501
|
+
if (child.content.size)
|
|
17502
|
+
child = child.copy(mapFragment(child.content, f, child));
|
|
17503
|
+
if (child.isInline)
|
|
17504
|
+
child = f(child, parent, i);
|
|
17505
|
+
mapped.push(child);
|
|
17506
|
+
}
|
|
17507
|
+
return Fragment25.fromArray(mapped);
|
|
17508
|
+
}
|
|
17509
|
+
var AddMarkStep = class _AddMarkStep extends Step {
|
|
17510
|
+
/**
|
|
17511
|
+
Create a mark step.
|
|
17512
|
+
*/
|
|
17513
|
+
constructor(from, to, mark) {
|
|
17514
|
+
super();
|
|
17515
|
+
this.from = from;
|
|
17516
|
+
this.to = to;
|
|
17517
|
+
this.mark = mark;
|
|
17518
|
+
}
|
|
17519
|
+
apply(doc) {
|
|
17520
|
+
let oldSlice = doc.slice(this.from, this.to), $from = doc.resolve(this.from);
|
|
17521
|
+
let parent = $from.node($from.sharedDepth(this.to));
|
|
17522
|
+
let slice = new Slice(mapFragment(oldSlice.content, (node, parent2) => {
|
|
17523
|
+
if (!node.isAtom || !parent2.type.allowsMarkType(this.mark.type))
|
|
17524
|
+
return node;
|
|
17525
|
+
return node.mark(this.mark.addToSet(node.marks));
|
|
17526
|
+
}, parent), oldSlice.openStart, oldSlice.openEnd);
|
|
17527
|
+
return StepResult.fromReplace(doc, this.from, this.to, slice);
|
|
17528
|
+
}
|
|
17529
|
+
invert() {
|
|
17530
|
+
return new RemoveMarkStep(this.from, this.to, this.mark);
|
|
17531
|
+
}
|
|
17532
|
+
map(mapping) {
|
|
17533
|
+
let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);
|
|
17534
|
+
if (from.deleted && to.deleted || from.pos >= to.pos)
|
|
17535
|
+
return null;
|
|
17536
|
+
return new _AddMarkStep(from.pos, to.pos, this.mark);
|
|
17537
|
+
}
|
|
17538
|
+
merge(other) {
|
|
17539
|
+
if (other instanceof _AddMarkStep && other.mark.eq(this.mark) && this.from <= other.to && this.to >= other.from)
|
|
17540
|
+
return new _AddMarkStep(Math.min(this.from, other.from), Math.max(this.to, other.to), this.mark);
|
|
17541
|
+
return null;
|
|
17542
|
+
}
|
|
17543
|
+
toJSON() {
|
|
17544
|
+
return {
|
|
17545
|
+
stepType: "addMark",
|
|
17546
|
+
mark: this.mark.toJSON(),
|
|
17547
|
+
from: this.from,
|
|
17548
|
+
to: this.to
|
|
17549
|
+
};
|
|
17550
|
+
}
|
|
17551
|
+
/**
|
|
17552
|
+
@internal
|
|
17553
|
+
*/
|
|
17554
|
+
static fromJSON(schema, json) {
|
|
17555
|
+
if (typeof json.from != "number" || typeof json.to != "number")
|
|
17556
|
+
throw new RangeError("Invalid input for AddMarkStep.fromJSON");
|
|
17557
|
+
return new _AddMarkStep(json.from, json.to, schema.markFromJSON(json.mark));
|
|
17558
|
+
}
|
|
17559
|
+
};
|
|
17560
|
+
Step.jsonID("addMark", AddMarkStep);
|
|
17561
|
+
var RemoveMarkStep = class _RemoveMarkStep extends Step {
|
|
17562
|
+
/**
|
|
17563
|
+
Create a mark-removing step.
|
|
17564
|
+
*/
|
|
17565
|
+
constructor(from, to, mark) {
|
|
17566
|
+
super();
|
|
17567
|
+
this.from = from;
|
|
17568
|
+
this.to = to;
|
|
17569
|
+
this.mark = mark;
|
|
17570
|
+
}
|
|
17571
|
+
apply(doc) {
|
|
17572
|
+
let oldSlice = doc.slice(this.from, this.to);
|
|
17573
|
+
let slice = new Slice(mapFragment(oldSlice.content, (node) => {
|
|
17574
|
+
return node.mark(this.mark.removeFromSet(node.marks));
|
|
17575
|
+
}, doc), oldSlice.openStart, oldSlice.openEnd);
|
|
17576
|
+
return StepResult.fromReplace(doc, this.from, this.to, slice);
|
|
17577
|
+
}
|
|
17578
|
+
invert() {
|
|
17579
|
+
return new AddMarkStep(this.from, this.to, this.mark);
|
|
17580
|
+
}
|
|
17581
|
+
map(mapping) {
|
|
17582
|
+
let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);
|
|
17583
|
+
if (from.deleted && to.deleted || from.pos >= to.pos)
|
|
17584
|
+
return null;
|
|
17585
|
+
return new _RemoveMarkStep(from.pos, to.pos, this.mark);
|
|
17586
|
+
}
|
|
17587
|
+
merge(other) {
|
|
17588
|
+
if (other instanceof _RemoveMarkStep && other.mark.eq(this.mark) && this.from <= other.to && this.to >= other.from)
|
|
17589
|
+
return new _RemoveMarkStep(Math.min(this.from, other.from), Math.max(this.to, other.to), this.mark);
|
|
17590
|
+
return null;
|
|
17591
|
+
}
|
|
17592
|
+
toJSON() {
|
|
17593
|
+
return {
|
|
17594
|
+
stepType: "removeMark",
|
|
17595
|
+
mark: this.mark.toJSON(),
|
|
17596
|
+
from: this.from,
|
|
17597
|
+
to: this.to
|
|
17598
|
+
};
|
|
17599
|
+
}
|
|
17600
|
+
/**
|
|
17601
|
+
@internal
|
|
17602
|
+
*/
|
|
17603
|
+
static fromJSON(schema, json) {
|
|
17604
|
+
if (typeof json.from != "number" || typeof json.to != "number")
|
|
17605
|
+
throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");
|
|
17606
|
+
return new _RemoveMarkStep(json.from, json.to, schema.markFromJSON(json.mark));
|
|
17607
|
+
}
|
|
17608
|
+
};
|
|
17609
|
+
Step.jsonID("removeMark", RemoveMarkStep);
|
|
17610
|
+
var AddNodeMarkStep = class _AddNodeMarkStep extends Step {
|
|
17611
|
+
/**
|
|
17612
|
+
Create a node mark step.
|
|
17613
|
+
*/
|
|
17614
|
+
constructor(pos, mark) {
|
|
17615
|
+
super();
|
|
17616
|
+
this.pos = pos;
|
|
17617
|
+
this.mark = mark;
|
|
17618
|
+
}
|
|
17619
|
+
apply(doc) {
|
|
17620
|
+
let node = doc.nodeAt(this.pos);
|
|
17621
|
+
if (!node)
|
|
17622
|
+
return StepResult.fail("No node at mark step's position");
|
|
17623
|
+
let updated = node.type.create(node.attrs, null, this.mark.addToSet(node.marks));
|
|
17624
|
+
return StepResult.fromReplace(doc, this.pos, this.pos + 1, new Slice(Fragment25.from(updated), 0, node.isLeaf ? 0 : 1));
|
|
17625
|
+
}
|
|
17626
|
+
invert(doc) {
|
|
17627
|
+
let node = doc.nodeAt(this.pos);
|
|
17628
|
+
if (node) {
|
|
17629
|
+
let newSet = this.mark.addToSet(node.marks);
|
|
17630
|
+
if (newSet.length == node.marks.length) {
|
|
17631
|
+
for (let i = 0; i < node.marks.length; i++)
|
|
17632
|
+
if (!node.marks[i].isInSet(newSet))
|
|
17633
|
+
return new _AddNodeMarkStep(this.pos, node.marks[i]);
|
|
17634
|
+
return new _AddNodeMarkStep(this.pos, this.mark);
|
|
17635
|
+
}
|
|
17636
|
+
}
|
|
17637
|
+
return new RemoveNodeMarkStep(this.pos, this.mark);
|
|
17638
|
+
}
|
|
17639
|
+
map(mapping) {
|
|
17640
|
+
let pos = mapping.mapResult(this.pos, 1);
|
|
17641
|
+
return pos.deletedAfter ? null : new _AddNodeMarkStep(pos.pos, this.mark);
|
|
17642
|
+
}
|
|
17643
|
+
toJSON() {
|
|
17644
|
+
return { stepType: "addNodeMark", pos: this.pos, mark: this.mark.toJSON() };
|
|
17645
|
+
}
|
|
17646
|
+
/**
|
|
17647
|
+
@internal
|
|
17648
|
+
*/
|
|
17649
|
+
static fromJSON(schema, json) {
|
|
17650
|
+
if (typeof json.pos != "number")
|
|
17651
|
+
throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");
|
|
17652
|
+
return new _AddNodeMarkStep(json.pos, schema.markFromJSON(json.mark));
|
|
17653
|
+
}
|
|
17654
|
+
};
|
|
17655
|
+
Step.jsonID("addNodeMark", AddNodeMarkStep);
|
|
17656
|
+
var RemoveNodeMarkStep = class _RemoveNodeMarkStep extends Step {
|
|
17657
|
+
/**
|
|
17658
|
+
Create a mark-removing step.
|
|
17659
|
+
*/
|
|
17660
|
+
constructor(pos, mark) {
|
|
17661
|
+
super();
|
|
17662
|
+
this.pos = pos;
|
|
17663
|
+
this.mark = mark;
|
|
17664
|
+
}
|
|
17665
|
+
apply(doc) {
|
|
17666
|
+
let node = doc.nodeAt(this.pos);
|
|
17667
|
+
if (!node)
|
|
17668
|
+
return StepResult.fail("No node at mark step's position");
|
|
17669
|
+
let updated = node.type.create(node.attrs, null, this.mark.removeFromSet(node.marks));
|
|
17670
|
+
return StepResult.fromReplace(doc, this.pos, this.pos + 1, new Slice(Fragment25.from(updated), 0, node.isLeaf ? 0 : 1));
|
|
17671
|
+
}
|
|
17672
|
+
invert(doc) {
|
|
17673
|
+
let node = doc.nodeAt(this.pos);
|
|
17674
|
+
if (!node || !this.mark.isInSet(node.marks))
|
|
17675
|
+
return this;
|
|
17676
|
+
return new AddNodeMarkStep(this.pos, this.mark);
|
|
17677
|
+
}
|
|
17678
|
+
map(mapping) {
|
|
17679
|
+
let pos = mapping.mapResult(this.pos, 1);
|
|
17680
|
+
return pos.deletedAfter ? null : new _RemoveNodeMarkStep(pos.pos, this.mark);
|
|
17681
|
+
}
|
|
17682
|
+
toJSON() {
|
|
17683
|
+
return { stepType: "removeNodeMark", pos: this.pos, mark: this.mark.toJSON() };
|
|
17684
|
+
}
|
|
17685
|
+
/**
|
|
17686
|
+
@internal
|
|
17687
|
+
*/
|
|
17688
|
+
static fromJSON(schema, json) {
|
|
17689
|
+
if (typeof json.pos != "number")
|
|
17690
|
+
throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");
|
|
17691
|
+
return new _RemoveNodeMarkStep(json.pos, schema.markFromJSON(json.mark));
|
|
17692
|
+
}
|
|
17693
|
+
};
|
|
17694
|
+
Step.jsonID("removeNodeMark", RemoveNodeMarkStep);
|
|
17695
|
+
var ReplaceStep = class _ReplaceStep extends Step {
|
|
17696
|
+
/**
|
|
17697
|
+
The given `slice` should fit the 'gap' between `from` and
|
|
17698
|
+
`to`—the depths must line up, and the surrounding nodes must be
|
|
17699
|
+
able to be joined with the open sides of the slice. When
|
|
17700
|
+
`structure` is true, the step will fail if the content between
|
|
17701
|
+
from and to is not just a sequence of closing and then opening
|
|
17702
|
+
tokens (this is to guard against rebased replace steps
|
|
17703
|
+
overwriting something they weren't supposed to).
|
|
17704
|
+
*/
|
|
17705
|
+
constructor(from, to, slice, structure = false) {
|
|
17706
|
+
super();
|
|
17707
|
+
this.from = from;
|
|
17708
|
+
this.to = to;
|
|
17709
|
+
this.slice = slice;
|
|
17710
|
+
this.structure = structure;
|
|
17711
|
+
}
|
|
17712
|
+
apply(doc) {
|
|
17713
|
+
if (this.structure && contentBetween(doc, this.from, this.to))
|
|
17714
|
+
return StepResult.fail("Structure replace would overwrite content");
|
|
17715
|
+
return StepResult.fromReplace(doc, this.from, this.to, this.slice);
|
|
17716
|
+
}
|
|
17717
|
+
getMap() {
|
|
17718
|
+
return new StepMap([this.from, this.to - this.from, this.slice.size]);
|
|
17719
|
+
}
|
|
17720
|
+
invert(doc) {
|
|
17721
|
+
return new _ReplaceStep(this.from, this.from + this.slice.size, doc.slice(this.from, this.to));
|
|
17722
|
+
}
|
|
17723
|
+
map(mapping) {
|
|
17724
|
+
let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);
|
|
17725
|
+
if (from.deletedAcross && to.deletedAcross)
|
|
17726
|
+
return null;
|
|
17727
|
+
return new _ReplaceStep(from.pos, Math.max(from.pos, to.pos), this.slice, this.structure);
|
|
17728
|
+
}
|
|
17729
|
+
merge(other) {
|
|
17730
|
+
if (!(other instanceof _ReplaceStep) || other.structure || this.structure)
|
|
17731
|
+
return null;
|
|
17732
|
+
if (this.from + this.slice.size == other.from && !this.slice.openEnd && !other.slice.openStart) {
|
|
17733
|
+
let slice = this.slice.size + other.slice.size == 0 ? Slice.empty : new Slice(this.slice.content.append(other.slice.content), this.slice.openStart, other.slice.openEnd);
|
|
17734
|
+
return new _ReplaceStep(this.from, this.to + (other.to - other.from), slice, this.structure);
|
|
17735
|
+
} else if (other.to == this.from && !this.slice.openStart && !other.slice.openEnd) {
|
|
17736
|
+
let slice = this.slice.size + other.slice.size == 0 ? Slice.empty : new Slice(other.slice.content.append(this.slice.content), other.slice.openStart, this.slice.openEnd);
|
|
17737
|
+
return new _ReplaceStep(other.from, this.to, slice, this.structure);
|
|
17738
|
+
} else {
|
|
17739
|
+
return null;
|
|
17740
|
+
}
|
|
17741
|
+
}
|
|
17742
|
+
toJSON() {
|
|
17743
|
+
let json = { stepType: "replace", from: this.from, to: this.to };
|
|
17744
|
+
if (this.slice.size)
|
|
17745
|
+
json.slice = this.slice.toJSON();
|
|
17746
|
+
if (this.structure)
|
|
17747
|
+
json.structure = true;
|
|
17748
|
+
return json;
|
|
17749
|
+
}
|
|
17750
|
+
/**
|
|
17751
|
+
@internal
|
|
17752
|
+
*/
|
|
17753
|
+
static fromJSON(schema, json) {
|
|
17754
|
+
if (typeof json.from != "number" || typeof json.to != "number")
|
|
17755
|
+
throw new RangeError("Invalid input for ReplaceStep.fromJSON");
|
|
17756
|
+
return new _ReplaceStep(json.from, json.to, Slice.fromJSON(schema, json.slice), !!json.structure);
|
|
17757
|
+
}
|
|
17758
|
+
};
|
|
17759
|
+
Step.jsonID("replace", ReplaceStep);
|
|
17760
|
+
var ReplaceAroundStep = class _ReplaceAroundStep extends Step {
|
|
17761
|
+
/**
|
|
17762
|
+
Create a replace-around step with the given range and gap.
|
|
17763
|
+
`insert` should be the point in the slice into which the content
|
|
17764
|
+
of the gap should be moved. `structure` has the same meaning as
|
|
17765
|
+
it has in the [`ReplaceStep`](https://prosemirror.net/docs/ref/#transform.ReplaceStep) class.
|
|
17766
|
+
*/
|
|
17767
|
+
constructor(from, to, gapFrom, gapTo, slice, insert, structure = false) {
|
|
17768
|
+
super();
|
|
17769
|
+
this.from = from;
|
|
17770
|
+
this.to = to;
|
|
17771
|
+
this.gapFrom = gapFrom;
|
|
17772
|
+
this.gapTo = gapTo;
|
|
17773
|
+
this.slice = slice;
|
|
17774
|
+
this.insert = insert;
|
|
17775
|
+
this.structure = structure;
|
|
17776
|
+
}
|
|
17777
|
+
apply(doc) {
|
|
17778
|
+
if (this.structure && (contentBetween(doc, this.from, this.gapFrom) || contentBetween(doc, this.gapTo, this.to)))
|
|
17779
|
+
return StepResult.fail("Structure gap-replace would overwrite content");
|
|
17780
|
+
let gap = doc.slice(this.gapFrom, this.gapTo);
|
|
17781
|
+
if (gap.openStart || gap.openEnd)
|
|
17782
|
+
return StepResult.fail("Gap is not a flat range");
|
|
17783
|
+
let inserted = this.slice.insertAt(this.insert, gap.content);
|
|
17784
|
+
if (!inserted)
|
|
17785
|
+
return StepResult.fail("Content does not fit in gap");
|
|
17786
|
+
return StepResult.fromReplace(doc, this.from, this.to, inserted);
|
|
17787
|
+
}
|
|
17788
|
+
getMap() {
|
|
17789
|
+
return new StepMap([
|
|
17790
|
+
this.from,
|
|
17791
|
+
this.gapFrom - this.from,
|
|
17792
|
+
this.insert,
|
|
17793
|
+
this.gapTo,
|
|
17794
|
+
this.to - this.gapTo,
|
|
17795
|
+
this.slice.size - this.insert
|
|
17796
|
+
]);
|
|
17797
|
+
}
|
|
17798
|
+
invert(doc) {
|
|
17799
|
+
let gap = this.gapTo - this.gapFrom;
|
|
17800
|
+
return new _ReplaceAroundStep(this.from, this.from + this.slice.size + gap, this.from + this.insert, this.from + this.insert + gap, doc.slice(this.from, this.to).removeBetween(this.gapFrom - this.from, this.gapTo - this.from), this.gapFrom - this.from, this.structure);
|
|
17801
|
+
}
|
|
17802
|
+
map(mapping) {
|
|
17803
|
+
let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);
|
|
17804
|
+
let gapFrom = this.from == this.gapFrom ? from.pos : mapping.map(this.gapFrom, -1);
|
|
17805
|
+
let gapTo = this.to == this.gapTo ? to.pos : mapping.map(this.gapTo, 1);
|
|
17806
|
+
if (from.deletedAcross && to.deletedAcross || gapFrom < from.pos || gapTo > to.pos)
|
|
17807
|
+
return null;
|
|
17808
|
+
return new _ReplaceAroundStep(from.pos, to.pos, gapFrom, gapTo, this.slice, this.insert, this.structure);
|
|
17809
|
+
}
|
|
17810
|
+
toJSON() {
|
|
17811
|
+
let json = {
|
|
17812
|
+
stepType: "replaceAround",
|
|
17813
|
+
from: this.from,
|
|
17814
|
+
to: this.to,
|
|
17815
|
+
gapFrom: this.gapFrom,
|
|
17816
|
+
gapTo: this.gapTo,
|
|
17817
|
+
insert: this.insert
|
|
17818
|
+
};
|
|
17819
|
+
if (this.slice.size)
|
|
17820
|
+
json.slice = this.slice.toJSON();
|
|
17821
|
+
if (this.structure)
|
|
17822
|
+
json.structure = true;
|
|
17823
|
+
return json;
|
|
17824
|
+
}
|
|
17825
|
+
/**
|
|
17826
|
+
@internal
|
|
17827
|
+
*/
|
|
17828
|
+
static fromJSON(schema, json) {
|
|
17829
|
+
if (typeof json.from != "number" || typeof json.to != "number" || typeof json.gapFrom != "number" || typeof json.gapTo != "number" || typeof json.insert != "number")
|
|
17830
|
+
throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");
|
|
17831
|
+
return new _ReplaceAroundStep(json.from, json.to, json.gapFrom, json.gapTo, Slice.fromJSON(schema, json.slice), json.insert, !!json.structure);
|
|
17832
|
+
}
|
|
17833
|
+
};
|
|
17834
|
+
Step.jsonID("replaceAround", ReplaceAroundStep);
|
|
17835
|
+
function contentBetween(doc, from, to) {
|
|
17836
|
+
let $from = doc.resolve(from), dist = to - from, depth = $from.depth;
|
|
17837
|
+
while (dist > 0 && depth > 0 && $from.indexAfter(depth) == $from.node(depth).childCount) {
|
|
17838
|
+
depth--;
|
|
17839
|
+
dist--;
|
|
17840
|
+
}
|
|
17841
|
+
if (dist > 0) {
|
|
17842
|
+
let next = $from.node(depth).maybeChild($from.indexAfter(depth));
|
|
17843
|
+
while (dist > 0) {
|
|
17844
|
+
if (!next || next.isLeaf)
|
|
17845
|
+
return true;
|
|
17846
|
+
next = next.firstChild;
|
|
17847
|
+
dist--;
|
|
17848
|
+
}
|
|
17849
|
+
}
|
|
17850
|
+
return false;
|
|
17851
|
+
}
|
|
17852
|
+
var AttrStep = class _AttrStep extends Step {
|
|
17853
|
+
/**
|
|
17854
|
+
Construct an attribute step.
|
|
17855
|
+
*/
|
|
17856
|
+
constructor(pos, attr, value) {
|
|
17857
|
+
super();
|
|
17858
|
+
this.pos = pos;
|
|
17859
|
+
this.attr = attr;
|
|
17860
|
+
this.value = value;
|
|
17861
|
+
}
|
|
17862
|
+
apply(doc) {
|
|
17863
|
+
let node = doc.nodeAt(this.pos);
|
|
17864
|
+
if (!node)
|
|
17865
|
+
return StepResult.fail("No node at attribute step's position");
|
|
17866
|
+
let attrs = /* @__PURE__ */ Object.create(null);
|
|
17867
|
+
for (let name in node.attrs)
|
|
17868
|
+
attrs[name] = node.attrs[name];
|
|
17869
|
+
attrs[this.attr] = this.value;
|
|
17870
|
+
let updated = node.type.create(attrs, null, node.marks);
|
|
17871
|
+
return StepResult.fromReplace(doc, this.pos, this.pos + 1, new Slice(Fragment25.from(updated), 0, node.isLeaf ? 0 : 1));
|
|
17872
|
+
}
|
|
17873
|
+
getMap() {
|
|
17874
|
+
return StepMap.empty;
|
|
17875
|
+
}
|
|
17876
|
+
invert(doc) {
|
|
17877
|
+
return new _AttrStep(this.pos, this.attr, doc.nodeAt(this.pos).attrs[this.attr]);
|
|
17878
|
+
}
|
|
17879
|
+
map(mapping) {
|
|
17880
|
+
let pos = mapping.mapResult(this.pos, 1);
|
|
17881
|
+
return pos.deletedAfter ? null : new _AttrStep(pos.pos, this.attr, this.value);
|
|
17882
|
+
}
|
|
17883
|
+
toJSON() {
|
|
17884
|
+
return { stepType: "attr", pos: this.pos, attr: this.attr, value: this.value };
|
|
17885
|
+
}
|
|
17886
|
+
static fromJSON(schema, json) {
|
|
17887
|
+
if (typeof json.pos != "number" || typeof json.attr != "string")
|
|
17888
|
+
throw new RangeError("Invalid input for AttrStep.fromJSON");
|
|
17889
|
+
return new _AttrStep(json.pos, json.attr, json.value);
|
|
17890
|
+
}
|
|
17891
|
+
};
|
|
17892
|
+
Step.jsonID("attr", AttrStep);
|
|
17893
|
+
var DocAttrStep = class _DocAttrStep extends Step {
|
|
17894
|
+
/**
|
|
17895
|
+
Construct an attribute step.
|
|
17896
|
+
*/
|
|
17897
|
+
constructor(attr, value) {
|
|
17898
|
+
super();
|
|
17899
|
+
this.attr = attr;
|
|
17900
|
+
this.value = value;
|
|
17901
|
+
}
|
|
17902
|
+
apply(doc) {
|
|
17903
|
+
let attrs = /* @__PURE__ */ Object.create(null);
|
|
17904
|
+
for (let name in doc.attrs)
|
|
17905
|
+
attrs[name] = doc.attrs[name];
|
|
17906
|
+
attrs[this.attr] = this.value;
|
|
17907
|
+
let updated = doc.type.create(attrs, doc.content, doc.marks);
|
|
17908
|
+
return StepResult.ok(updated);
|
|
17909
|
+
}
|
|
17910
|
+
getMap() {
|
|
17911
|
+
return StepMap.empty;
|
|
17912
|
+
}
|
|
17913
|
+
invert(doc) {
|
|
17914
|
+
return new _DocAttrStep(this.attr, doc.attrs[this.attr]);
|
|
17915
|
+
}
|
|
17916
|
+
map(mapping) {
|
|
17917
|
+
return this;
|
|
17918
|
+
}
|
|
17919
|
+
toJSON() {
|
|
17920
|
+
return { stepType: "docAttr", attr: this.attr, value: this.value };
|
|
17921
|
+
}
|
|
17922
|
+
static fromJSON(schema, json) {
|
|
17923
|
+
if (typeof json.attr != "string")
|
|
17924
|
+
throw new RangeError("Invalid input for DocAttrStep.fromJSON");
|
|
17925
|
+
return new _DocAttrStep(json.attr, json.value);
|
|
17926
|
+
}
|
|
17927
|
+
};
|
|
17928
|
+
Step.jsonID("docAttr", DocAttrStep);
|
|
17929
|
+
var TransformError = class extends Error {
|
|
17930
|
+
};
|
|
17931
|
+
TransformError = function TransformError2(message) {
|
|
17932
|
+
let err = Error.call(this, message);
|
|
17933
|
+
err.__proto__ = TransformError2.prototype;
|
|
17934
|
+
return err;
|
|
17935
|
+
};
|
|
17936
|
+
TransformError.prototype = Object.create(Error.prototype);
|
|
17937
|
+
TransformError.prototype.constructor = TransformError;
|
|
17938
|
+
TransformError.prototype.name = "TransformError";
|
|
17939
|
+
|
|
17940
|
+
// ../../node_modules/prosemirror-state/dist/index.js
|
|
17941
|
+
var classesById = /* @__PURE__ */ Object.create(null);
|
|
17942
|
+
var Selection = class {
|
|
17943
|
+
/**
|
|
17944
|
+
Initialize a selection with the head and anchor and ranges. If no
|
|
17945
|
+
ranges are given, constructs a single range across `$anchor` and
|
|
17946
|
+
`$head`.
|
|
17947
|
+
*/
|
|
17948
|
+
constructor($anchor, $head, ranges) {
|
|
17949
|
+
this.$anchor = $anchor;
|
|
17950
|
+
this.$head = $head;
|
|
17951
|
+
this.ranges = ranges || [new SelectionRange($anchor.min($head), $anchor.max($head))];
|
|
17952
|
+
}
|
|
17953
|
+
/**
|
|
17954
|
+
The selection's anchor, as an unresolved position.
|
|
17955
|
+
*/
|
|
17956
|
+
get anchor() {
|
|
17957
|
+
return this.$anchor.pos;
|
|
17958
|
+
}
|
|
17959
|
+
/**
|
|
17960
|
+
The selection's head.
|
|
17961
|
+
*/
|
|
17962
|
+
get head() {
|
|
17963
|
+
return this.$head.pos;
|
|
17964
|
+
}
|
|
17965
|
+
/**
|
|
17966
|
+
The lower bound of the selection's main range.
|
|
17967
|
+
*/
|
|
17968
|
+
get from() {
|
|
17969
|
+
return this.$from.pos;
|
|
17970
|
+
}
|
|
17971
|
+
/**
|
|
17972
|
+
The upper bound of the selection's main range.
|
|
17973
|
+
*/
|
|
17974
|
+
get to() {
|
|
17975
|
+
return this.$to.pos;
|
|
17976
|
+
}
|
|
17977
|
+
/**
|
|
17978
|
+
The resolved lower bound of the selection's main range.
|
|
17979
|
+
*/
|
|
17980
|
+
get $from() {
|
|
17981
|
+
return this.ranges[0].$from;
|
|
17982
|
+
}
|
|
17983
|
+
/**
|
|
17984
|
+
The resolved upper bound of the selection's main range.
|
|
17985
|
+
*/
|
|
17986
|
+
get $to() {
|
|
17987
|
+
return this.ranges[0].$to;
|
|
17988
|
+
}
|
|
17989
|
+
/**
|
|
17990
|
+
Indicates whether the selection contains any content.
|
|
17991
|
+
*/
|
|
17992
|
+
get empty() {
|
|
17993
|
+
let ranges = this.ranges;
|
|
17994
|
+
for (let i = 0; i < ranges.length; i++)
|
|
17995
|
+
if (ranges[i].$from.pos != ranges[i].$to.pos)
|
|
17996
|
+
return false;
|
|
17997
|
+
return true;
|
|
17998
|
+
}
|
|
17999
|
+
/**
|
|
18000
|
+
Get the content of this selection as a slice.
|
|
18001
|
+
*/
|
|
18002
|
+
content() {
|
|
18003
|
+
return this.$from.doc.slice(this.from, this.to, true);
|
|
18004
|
+
}
|
|
18005
|
+
/**
|
|
18006
|
+
Replace the selection with a slice or, if no slice is given,
|
|
18007
|
+
delete the selection. Will append to the given transaction.
|
|
18008
|
+
*/
|
|
18009
|
+
replace(tr, content = Slice.empty) {
|
|
18010
|
+
let lastNode = content.content.lastChild, lastParent = null;
|
|
18011
|
+
for (let i = 0; i < content.openEnd; i++) {
|
|
18012
|
+
lastParent = lastNode;
|
|
18013
|
+
lastNode = lastNode.lastChild;
|
|
18014
|
+
}
|
|
18015
|
+
let mapFrom = tr.steps.length, ranges = this.ranges;
|
|
18016
|
+
for (let i = 0; i < ranges.length; i++) {
|
|
18017
|
+
let { $from, $to } = ranges[i], mapping = tr.mapping.slice(mapFrom);
|
|
18018
|
+
tr.replaceRange(mapping.map($from.pos), mapping.map($to.pos), i ? Slice.empty : content);
|
|
18019
|
+
if (i == 0)
|
|
18020
|
+
selectionToInsertionEnd(tr, mapFrom, (lastNode ? lastNode.isInline : lastParent && lastParent.isTextblock) ? -1 : 1);
|
|
18021
|
+
}
|
|
18022
|
+
}
|
|
18023
|
+
/**
|
|
18024
|
+
Replace the selection with the given node, appending the changes
|
|
18025
|
+
to the given transaction.
|
|
18026
|
+
*/
|
|
18027
|
+
replaceWith(tr, node) {
|
|
18028
|
+
let mapFrom = tr.steps.length, ranges = this.ranges;
|
|
18029
|
+
for (let i = 0; i < ranges.length; i++) {
|
|
18030
|
+
let { $from, $to } = ranges[i], mapping = tr.mapping.slice(mapFrom);
|
|
18031
|
+
let from = mapping.map($from.pos), to = mapping.map($to.pos);
|
|
18032
|
+
if (i) {
|
|
18033
|
+
tr.deleteRange(from, to);
|
|
18034
|
+
} else {
|
|
18035
|
+
tr.replaceRangeWith(from, to, node);
|
|
18036
|
+
selectionToInsertionEnd(tr, mapFrom, node.isInline ? -1 : 1);
|
|
18037
|
+
}
|
|
18038
|
+
}
|
|
18039
|
+
}
|
|
18040
|
+
/**
|
|
18041
|
+
Find a valid cursor or leaf node selection starting at the given
|
|
18042
|
+
position and searching back if `dir` is negative, and forward if
|
|
18043
|
+
positive. When `textOnly` is true, only consider cursor
|
|
18044
|
+
selections. Will return null when no valid selection position is
|
|
18045
|
+
found.
|
|
18046
|
+
*/
|
|
18047
|
+
static findFrom($pos, dir, textOnly = false) {
|
|
18048
|
+
let inner = $pos.parent.inlineContent ? new TextSelection($pos) : findSelectionIn($pos.node(0), $pos.parent, $pos.pos, $pos.index(), dir, textOnly);
|
|
18049
|
+
if (inner)
|
|
18050
|
+
return inner;
|
|
18051
|
+
for (let depth = $pos.depth - 1; depth >= 0; depth--) {
|
|
18052
|
+
let found2 = dir < 0 ? findSelectionIn($pos.node(0), $pos.node(depth), $pos.before(depth + 1), $pos.index(depth), dir, textOnly) : findSelectionIn($pos.node(0), $pos.node(depth), $pos.after(depth + 1), $pos.index(depth) + 1, dir, textOnly);
|
|
18053
|
+
if (found2)
|
|
18054
|
+
return found2;
|
|
18055
|
+
}
|
|
18056
|
+
return null;
|
|
18057
|
+
}
|
|
18058
|
+
/**
|
|
18059
|
+
Find a valid cursor or leaf node selection near the given
|
|
18060
|
+
position. Searches forward first by default, but if `bias` is
|
|
18061
|
+
negative, it will search backwards first.
|
|
18062
|
+
*/
|
|
18063
|
+
static near($pos, bias = 1) {
|
|
18064
|
+
return this.findFrom($pos, bias) || this.findFrom($pos, -bias) || new AllSelection($pos.node(0));
|
|
18065
|
+
}
|
|
18066
|
+
/**
|
|
18067
|
+
Find the cursor or leaf node selection closest to the start of
|
|
18068
|
+
the given document. Will return an
|
|
18069
|
+
[`AllSelection`](https://prosemirror.net/docs/ref/#state.AllSelection) if no valid position
|
|
18070
|
+
exists.
|
|
18071
|
+
*/
|
|
18072
|
+
static atStart(doc) {
|
|
18073
|
+
return findSelectionIn(doc, doc, 0, 0, 1) || new AllSelection(doc);
|
|
18074
|
+
}
|
|
18075
|
+
/**
|
|
18076
|
+
Find the cursor or leaf node selection closest to the end of the
|
|
18077
|
+
given document.
|
|
18078
|
+
*/
|
|
18079
|
+
static atEnd(doc) {
|
|
18080
|
+
return findSelectionIn(doc, doc, doc.content.size, doc.childCount, -1) || new AllSelection(doc);
|
|
18081
|
+
}
|
|
18082
|
+
/**
|
|
18083
|
+
Deserialize the JSON representation of a selection. Must be
|
|
18084
|
+
implemented for custom classes (as a static class method).
|
|
18085
|
+
*/
|
|
18086
|
+
static fromJSON(doc, json) {
|
|
18087
|
+
if (!json || !json.type)
|
|
18088
|
+
throw new RangeError("Invalid input for Selection.fromJSON");
|
|
18089
|
+
let cls = classesById[json.type];
|
|
18090
|
+
if (!cls)
|
|
18091
|
+
throw new RangeError(`No selection type ${json.type} defined`);
|
|
18092
|
+
return cls.fromJSON(doc, json);
|
|
18093
|
+
}
|
|
18094
|
+
/**
|
|
18095
|
+
To be able to deserialize selections from JSON, custom selection
|
|
18096
|
+
classes must register themselves with an ID string, so that they
|
|
18097
|
+
can be disambiguated. Try to pick something that's unlikely to
|
|
18098
|
+
clash with classes from other modules.
|
|
18099
|
+
*/
|
|
18100
|
+
static jsonID(id, selectionClass) {
|
|
18101
|
+
if (id in classesById)
|
|
18102
|
+
throw new RangeError("Duplicate use of selection JSON ID " + id);
|
|
18103
|
+
classesById[id] = selectionClass;
|
|
18104
|
+
selectionClass.prototype.jsonID = id;
|
|
18105
|
+
return selectionClass;
|
|
18106
|
+
}
|
|
18107
|
+
/**
|
|
18108
|
+
Get a [bookmark](https://prosemirror.net/docs/ref/#state.SelectionBookmark) for this selection,
|
|
18109
|
+
which is a value that can be mapped without having access to a
|
|
18110
|
+
current document, and later resolved to a real selection for a
|
|
18111
|
+
given document again. (This is used mostly by the history to
|
|
18112
|
+
track and restore old selections.) The default implementation of
|
|
18113
|
+
this method just converts the selection to a text selection and
|
|
18114
|
+
returns the bookmark for that.
|
|
18115
|
+
*/
|
|
18116
|
+
getBookmark() {
|
|
18117
|
+
return TextSelection.between(this.$anchor, this.$head).getBookmark();
|
|
18118
|
+
}
|
|
18119
|
+
};
|
|
18120
|
+
Selection.prototype.visible = true;
|
|
18121
|
+
var SelectionRange = class {
|
|
18122
|
+
/**
|
|
18123
|
+
Create a range.
|
|
18124
|
+
*/
|
|
18125
|
+
constructor($from, $to) {
|
|
18126
|
+
this.$from = $from;
|
|
18127
|
+
this.$to = $to;
|
|
18128
|
+
}
|
|
18129
|
+
};
|
|
18130
|
+
var warnedAboutTextSelection = false;
|
|
18131
|
+
function checkTextSelection($pos) {
|
|
18132
|
+
if (!warnedAboutTextSelection && !$pos.parent.inlineContent) {
|
|
18133
|
+
warnedAboutTextSelection = true;
|
|
18134
|
+
console["warn"]("TextSelection endpoint not pointing into a node with inline content (" + $pos.parent.type.name + ")");
|
|
18135
|
+
}
|
|
18136
|
+
}
|
|
18137
|
+
var TextSelection = class _TextSelection extends Selection {
|
|
18138
|
+
/**
|
|
18139
|
+
Construct a text selection between the given points.
|
|
18140
|
+
*/
|
|
18141
|
+
constructor($anchor, $head = $anchor) {
|
|
18142
|
+
checkTextSelection($anchor);
|
|
18143
|
+
checkTextSelection($head);
|
|
18144
|
+
super($anchor, $head);
|
|
18145
|
+
}
|
|
18146
|
+
/**
|
|
18147
|
+
Returns a resolved position if this is a cursor selection (an
|
|
18148
|
+
empty text selection), and null otherwise.
|
|
18149
|
+
*/
|
|
18150
|
+
get $cursor() {
|
|
18151
|
+
return this.$anchor.pos == this.$head.pos ? this.$head : null;
|
|
18152
|
+
}
|
|
18153
|
+
map(doc, mapping) {
|
|
18154
|
+
let $head = doc.resolve(mapping.map(this.head));
|
|
18155
|
+
if (!$head.parent.inlineContent)
|
|
18156
|
+
return Selection.near($head);
|
|
18157
|
+
let $anchor = doc.resolve(mapping.map(this.anchor));
|
|
18158
|
+
return new _TextSelection($anchor.parent.inlineContent ? $anchor : $head, $head);
|
|
18159
|
+
}
|
|
18160
|
+
replace(tr, content = Slice.empty) {
|
|
18161
|
+
super.replace(tr, content);
|
|
18162
|
+
if (content == Slice.empty) {
|
|
18163
|
+
let marks = this.$from.marksAcross(this.$to);
|
|
18164
|
+
if (marks)
|
|
18165
|
+
tr.ensureMarks(marks);
|
|
18166
|
+
}
|
|
18167
|
+
}
|
|
18168
|
+
eq(other) {
|
|
18169
|
+
return other instanceof _TextSelection && other.anchor == this.anchor && other.head == this.head;
|
|
18170
|
+
}
|
|
18171
|
+
getBookmark() {
|
|
18172
|
+
return new TextBookmark(this.anchor, this.head);
|
|
18173
|
+
}
|
|
18174
|
+
toJSON() {
|
|
18175
|
+
return { type: "text", anchor: this.anchor, head: this.head };
|
|
18176
|
+
}
|
|
18177
|
+
/**
|
|
18178
|
+
@internal
|
|
18179
|
+
*/
|
|
18180
|
+
static fromJSON(doc, json) {
|
|
18181
|
+
if (typeof json.anchor != "number" || typeof json.head != "number")
|
|
18182
|
+
throw new RangeError("Invalid input for TextSelection.fromJSON");
|
|
18183
|
+
return new _TextSelection(doc.resolve(json.anchor), doc.resolve(json.head));
|
|
18184
|
+
}
|
|
18185
|
+
/**
|
|
18186
|
+
Create a text selection from non-resolved positions.
|
|
18187
|
+
*/
|
|
18188
|
+
static create(doc, anchor, head = anchor) {
|
|
18189
|
+
let $anchor = doc.resolve(anchor);
|
|
18190
|
+
return new this($anchor, head == anchor ? $anchor : doc.resolve(head));
|
|
18191
|
+
}
|
|
18192
|
+
/**
|
|
18193
|
+
Return a text selection that spans the given positions or, if
|
|
18194
|
+
they aren't text positions, find a text selection near them.
|
|
18195
|
+
`bias` determines whether the method searches forward (default)
|
|
18196
|
+
or backwards (negative number) first. Will fall back to calling
|
|
18197
|
+
[`Selection.near`](https://prosemirror.net/docs/ref/#state.Selection^near) when the document
|
|
18198
|
+
doesn't contain a valid text position.
|
|
18199
|
+
*/
|
|
18200
|
+
static between($anchor, $head, bias) {
|
|
18201
|
+
let dPos = $anchor.pos - $head.pos;
|
|
18202
|
+
if (!bias || dPos)
|
|
18203
|
+
bias = dPos >= 0 ? 1 : -1;
|
|
18204
|
+
if (!$head.parent.inlineContent) {
|
|
18205
|
+
let found2 = Selection.findFrom($head, bias, true) || Selection.findFrom($head, -bias, true);
|
|
18206
|
+
if (found2)
|
|
18207
|
+
$head = found2.$head;
|
|
18208
|
+
else
|
|
18209
|
+
return Selection.near($head, bias);
|
|
18210
|
+
}
|
|
18211
|
+
if (!$anchor.parent.inlineContent) {
|
|
18212
|
+
if (dPos == 0) {
|
|
18213
|
+
$anchor = $head;
|
|
18214
|
+
} else {
|
|
18215
|
+
$anchor = (Selection.findFrom($anchor, -bias, true) || Selection.findFrom($anchor, bias, true)).$anchor;
|
|
18216
|
+
if ($anchor.pos < $head.pos != dPos < 0)
|
|
18217
|
+
$anchor = $head;
|
|
18218
|
+
}
|
|
18219
|
+
}
|
|
18220
|
+
return new _TextSelection($anchor, $head);
|
|
18221
|
+
}
|
|
18222
|
+
};
|
|
18223
|
+
Selection.jsonID("text", TextSelection);
|
|
18224
|
+
var TextBookmark = class _TextBookmark {
|
|
18225
|
+
constructor(anchor, head) {
|
|
18226
|
+
this.anchor = anchor;
|
|
18227
|
+
this.head = head;
|
|
18228
|
+
}
|
|
18229
|
+
map(mapping) {
|
|
18230
|
+
return new _TextBookmark(mapping.map(this.anchor), mapping.map(this.head));
|
|
18231
|
+
}
|
|
18232
|
+
resolve(doc) {
|
|
18233
|
+
return TextSelection.between(doc.resolve(this.anchor), doc.resolve(this.head));
|
|
18234
|
+
}
|
|
18235
|
+
};
|
|
18236
|
+
var NodeSelection = class _NodeSelection extends Selection {
|
|
18237
|
+
/**
|
|
18238
|
+
Create a node selection. Does not verify the validity of its
|
|
18239
|
+
argument.
|
|
18240
|
+
*/
|
|
18241
|
+
constructor($pos) {
|
|
18242
|
+
let node = $pos.nodeAfter;
|
|
18243
|
+
let $end = $pos.node(0).resolve($pos.pos + node.nodeSize);
|
|
18244
|
+
super($pos, $end);
|
|
18245
|
+
this.node = node;
|
|
18246
|
+
}
|
|
18247
|
+
map(doc, mapping) {
|
|
18248
|
+
let { deleted, pos } = mapping.mapResult(this.anchor);
|
|
18249
|
+
let $pos = doc.resolve(pos);
|
|
18250
|
+
if (deleted)
|
|
18251
|
+
return Selection.near($pos);
|
|
18252
|
+
return new _NodeSelection($pos);
|
|
18253
|
+
}
|
|
18254
|
+
content() {
|
|
18255
|
+
return new Slice(Fragment25.from(this.node), 0, 0);
|
|
18256
|
+
}
|
|
18257
|
+
eq(other) {
|
|
18258
|
+
return other instanceof _NodeSelection && other.anchor == this.anchor;
|
|
18259
|
+
}
|
|
18260
|
+
toJSON() {
|
|
18261
|
+
return { type: "node", anchor: this.anchor };
|
|
18262
|
+
}
|
|
18263
|
+
getBookmark() {
|
|
18264
|
+
return new NodeBookmark(this.anchor);
|
|
18265
|
+
}
|
|
18266
|
+
/**
|
|
18267
|
+
@internal
|
|
18268
|
+
*/
|
|
18269
|
+
static fromJSON(doc, json) {
|
|
18270
|
+
if (typeof json.anchor != "number")
|
|
18271
|
+
throw new RangeError("Invalid input for NodeSelection.fromJSON");
|
|
18272
|
+
return new _NodeSelection(doc.resolve(json.anchor));
|
|
18273
|
+
}
|
|
18274
|
+
/**
|
|
18275
|
+
Create a node selection from non-resolved positions.
|
|
18276
|
+
*/
|
|
18277
|
+
static create(doc, from) {
|
|
18278
|
+
return new _NodeSelection(doc.resolve(from));
|
|
18279
|
+
}
|
|
18280
|
+
/**
|
|
18281
|
+
Determines whether the given node may be selected as a node
|
|
18282
|
+
selection.
|
|
18283
|
+
*/
|
|
18284
|
+
static isSelectable(node) {
|
|
18285
|
+
return !node.isText && node.type.spec.selectable !== false;
|
|
18286
|
+
}
|
|
18287
|
+
};
|
|
18288
|
+
NodeSelection.prototype.visible = false;
|
|
18289
|
+
Selection.jsonID("node", NodeSelection);
|
|
18290
|
+
var NodeBookmark = class _NodeBookmark {
|
|
18291
|
+
constructor(anchor) {
|
|
18292
|
+
this.anchor = anchor;
|
|
18293
|
+
}
|
|
18294
|
+
map(mapping) {
|
|
18295
|
+
let { deleted, pos } = mapping.mapResult(this.anchor);
|
|
18296
|
+
return deleted ? new TextBookmark(pos, pos) : new _NodeBookmark(pos);
|
|
18297
|
+
}
|
|
18298
|
+
resolve(doc) {
|
|
18299
|
+
let $pos = doc.resolve(this.anchor), node = $pos.nodeAfter;
|
|
18300
|
+
if (node && NodeSelection.isSelectable(node))
|
|
18301
|
+
return new NodeSelection($pos);
|
|
18302
|
+
return Selection.near($pos);
|
|
18303
|
+
}
|
|
18304
|
+
};
|
|
18305
|
+
var AllSelection = class _AllSelection extends Selection {
|
|
18306
|
+
/**
|
|
18307
|
+
Create an all-selection over the given document.
|
|
18308
|
+
*/
|
|
18309
|
+
constructor(doc) {
|
|
18310
|
+
super(doc.resolve(0), doc.resolve(doc.content.size));
|
|
18311
|
+
}
|
|
18312
|
+
replace(tr, content = Slice.empty) {
|
|
18313
|
+
if (content == Slice.empty) {
|
|
18314
|
+
tr.delete(0, tr.doc.content.size);
|
|
18315
|
+
let sel = Selection.atStart(tr.doc);
|
|
18316
|
+
if (!sel.eq(tr.selection))
|
|
18317
|
+
tr.setSelection(sel);
|
|
18318
|
+
} else {
|
|
18319
|
+
super.replace(tr, content);
|
|
18320
|
+
}
|
|
18321
|
+
}
|
|
18322
|
+
toJSON() {
|
|
18323
|
+
return { type: "all" };
|
|
18324
|
+
}
|
|
18325
|
+
/**
|
|
18326
|
+
@internal
|
|
18327
|
+
*/
|
|
18328
|
+
static fromJSON(doc) {
|
|
18329
|
+
return new _AllSelection(doc);
|
|
18330
|
+
}
|
|
18331
|
+
map(doc) {
|
|
18332
|
+
return new _AllSelection(doc);
|
|
18333
|
+
}
|
|
18334
|
+
eq(other) {
|
|
18335
|
+
return other instanceof _AllSelection;
|
|
18336
|
+
}
|
|
18337
|
+
getBookmark() {
|
|
18338
|
+
return AllBookmark;
|
|
18339
|
+
}
|
|
18340
|
+
};
|
|
18341
|
+
Selection.jsonID("all", AllSelection);
|
|
18342
|
+
var AllBookmark = {
|
|
18343
|
+
map() {
|
|
18344
|
+
return this;
|
|
18345
|
+
},
|
|
18346
|
+
resolve(doc) {
|
|
18347
|
+
return new AllSelection(doc);
|
|
18348
|
+
}
|
|
18349
|
+
};
|
|
18350
|
+
function findSelectionIn(doc, node, pos, index, dir, text = false) {
|
|
18351
|
+
if (node.inlineContent)
|
|
18352
|
+
return TextSelection.create(doc, pos);
|
|
18353
|
+
for (let i = index - (dir > 0 ? 0 : 1); dir > 0 ? i < node.childCount : i >= 0; i += dir) {
|
|
18354
|
+
let child = node.child(i);
|
|
18355
|
+
if (!child.isAtom) {
|
|
18356
|
+
let inner = findSelectionIn(doc, child, pos + dir, dir < 0 ? child.childCount : 0, dir, text);
|
|
18357
|
+
if (inner)
|
|
18358
|
+
return inner;
|
|
18359
|
+
} else if (!text && NodeSelection.isSelectable(child)) {
|
|
18360
|
+
return NodeSelection.create(doc, pos - (dir < 0 ? child.nodeSize : 0));
|
|
18361
|
+
}
|
|
18362
|
+
pos += child.nodeSize * dir;
|
|
18363
|
+
}
|
|
18364
|
+
return null;
|
|
18365
|
+
}
|
|
18366
|
+
function selectionToInsertionEnd(tr, startLen, bias) {
|
|
18367
|
+
let last = tr.steps.length - 1;
|
|
18368
|
+
if (last < startLen)
|
|
18369
|
+
return;
|
|
18370
|
+
let step = tr.steps[last];
|
|
18371
|
+
if (!(step instanceof ReplaceStep || step instanceof ReplaceAroundStep))
|
|
18372
|
+
return;
|
|
18373
|
+
let map = tr.mapping.maps[last], end;
|
|
18374
|
+
map.forEach((_from, _to, _newFrom, newTo) => {
|
|
18375
|
+
if (end == null)
|
|
18376
|
+
end = newTo;
|
|
18377
|
+
});
|
|
18378
|
+
tr.setSelection(Selection.near(tr.doc.resolve(end), bias));
|
|
18379
|
+
}
|
|
18380
|
+
function bind(f, self) {
|
|
18381
|
+
return !self || !f ? f : f.bind(self);
|
|
18382
|
+
}
|
|
18383
|
+
var FieldDesc = class {
|
|
18384
|
+
constructor(name, desc, self) {
|
|
18385
|
+
this.name = name;
|
|
18386
|
+
this.init = bind(desc.init, self);
|
|
18387
|
+
this.apply = bind(desc.apply, self);
|
|
18388
|
+
}
|
|
18389
|
+
};
|
|
18390
|
+
var baseFields = [
|
|
18391
|
+
new FieldDesc("doc", {
|
|
18392
|
+
init(config) {
|
|
18393
|
+
return config.doc || config.schema.topNodeType.createAndFill();
|
|
18394
|
+
},
|
|
18395
|
+
apply(tr) {
|
|
18396
|
+
return tr.doc;
|
|
18397
|
+
}
|
|
18398
|
+
}),
|
|
18399
|
+
new FieldDesc("selection", {
|
|
18400
|
+
init(config, instance) {
|
|
18401
|
+
return config.selection || Selection.atStart(instance.doc);
|
|
18402
|
+
},
|
|
18403
|
+
apply(tr) {
|
|
18404
|
+
return tr.selection;
|
|
18405
|
+
}
|
|
18406
|
+
}),
|
|
18407
|
+
new FieldDesc("storedMarks", {
|
|
18408
|
+
init(config) {
|
|
18409
|
+
return config.storedMarks || null;
|
|
18410
|
+
},
|
|
18411
|
+
apply(tr, _marks, _old, state) {
|
|
18412
|
+
return state.selection.$cursor ? tr.storedMarks : null;
|
|
18413
|
+
}
|
|
18414
|
+
}),
|
|
18415
|
+
new FieldDesc("scrollToSelection", {
|
|
18416
|
+
init() {
|
|
18417
|
+
return 0;
|
|
18418
|
+
},
|
|
18419
|
+
apply(tr, prev) {
|
|
18420
|
+
return tr.scrolledIntoView ? prev + 1 : prev;
|
|
18421
|
+
}
|
|
18422
|
+
})
|
|
18423
|
+
];
|
|
18424
|
+
function bindProps(obj, self, target) {
|
|
18425
|
+
for (let prop in obj) {
|
|
18426
|
+
let val = obj[prop];
|
|
18427
|
+
if (val instanceof Function)
|
|
18428
|
+
val = val.bind(self);
|
|
18429
|
+
else if (prop == "handleDOMEvents")
|
|
18430
|
+
val = bindProps(val, self, {});
|
|
18431
|
+
target[prop] = val;
|
|
18432
|
+
}
|
|
18433
|
+
return target;
|
|
18434
|
+
}
|
|
18435
|
+
var Plugin = class {
|
|
18436
|
+
/**
|
|
18437
|
+
Create a plugin.
|
|
18438
|
+
*/
|
|
18439
|
+
constructor(spec) {
|
|
18440
|
+
this.spec = spec;
|
|
18441
|
+
this.props = {};
|
|
18442
|
+
if (spec.props)
|
|
18443
|
+
bindProps(spec.props, this, this.props);
|
|
18444
|
+
this.key = spec.key ? spec.key.key : createKey("plugin");
|
|
18445
|
+
}
|
|
18446
|
+
/**
|
|
18447
|
+
Extract the plugin's state field from an editor state.
|
|
18448
|
+
*/
|
|
18449
|
+
getState(state) {
|
|
18450
|
+
return state[this.key];
|
|
18451
|
+
}
|
|
15353
18452
|
};
|
|
15354
|
-
var
|
|
15355
|
-
|
|
18453
|
+
var keys = /* @__PURE__ */ Object.create(null);
|
|
18454
|
+
function createKey(name) {
|
|
18455
|
+
if (name in keys)
|
|
18456
|
+
return name + "$" + ++keys[name];
|
|
18457
|
+
keys[name] = 0;
|
|
18458
|
+
return name + "$";
|
|
18459
|
+
}
|
|
18460
|
+
|
|
18461
|
+
// ../../components/ui/UEditor/clipboard-images.ts
|
|
18462
|
+
function getImageFiles(dataTransfer) {
|
|
18463
|
+
if (!dataTransfer) return [];
|
|
18464
|
+
const itemFiles = [];
|
|
18465
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
18466
|
+
for (const item of Array.from(dataTransfer.items ?? [])) {
|
|
18467
|
+
if (item.kind !== "file") continue;
|
|
18468
|
+
if (!item.type.startsWith("image/")) continue;
|
|
18469
|
+
const file = item.getAsFile();
|
|
18470
|
+
if (!file) continue;
|
|
18471
|
+
byKey.set(`${file.name}:${file.size}:${file.lastModified}`, file);
|
|
18472
|
+
}
|
|
18473
|
+
itemFiles.push(...Array.from(byKey.values()));
|
|
18474
|
+
if (itemFiles.length > 0) return itemFiles;
|
|
18475
|
+
for (const file of Array.from(dataTransfer.files ?? [])) {
|
|
18476
|
+
if (!file.type.startsWith("image/")) continue;
|
|
18477
|
+
byKey.set(`${file.name}:${file.size}:${file.lastModified}`, file);
|
|
18478
|
+
}
|
|
18479
|
+
return Array.from(byKey.values());
|
|
18480
|
+
}
|
|
18481
|
+
function fileToDataUrl(file) {
|
|
18482
|
+
return new Promise((resolve, reject) => {
|
|
18483
|
+
const reader = new FileReader();
|
|
18484
|
+
reader.onload = () => resolve(String(reader.result ?? ""));
|
|
18485
|
+
reader.onerror = () => reject(reader.error ?? new Error("Failed to read image file"));
|
|
18486
|
+
reader.readAsDataURL(file);
|
|
18487
|
+
});
|
|
18488
|
+
}
|
|
18489
|
+
async function resolveImageSrc(file, options) {
|
|
18490
|
+
if (options.insertMode === "upload" && options.upload) {
|
|
18491
|
+
try {
|
|
18492
|
+
const result = await options.upload(file);
|
|
18493
|
+
const src = typeof result === "string" ? result : "";
|
|
18494
|
+
if (src) return src;
|
|
18495
|
+
} catch (err) {
|
|
18496
|
+
if (!options.fallbackToDataUrl) throw err;
|
|
18497
|
+
}
|
|
18498
|
+
}
|
|
18499
|
+
return fileToDataUrl(file);
|
|
18500
|
+
}
|
|
18501
|
+
var ClipboardImages = Extension2.create({
|
|
18502
|
+
name: "clipboardImages",
|
|
18503
|
+
addOptions() {
|
|
18504
|
+
return {
|
|
18505
|
+
maxFileSize: 10 * 1024 * 1024,
|
|
18506
|
+
allowedMimeTypes: ["image/png", "image/jpeg", "image/webp", "image/gif", "image/svg+xml"],
|
|
18507
|
+
upload: void 0,
|
|
18508
|
+
fallbackToDataUrl: true,
|
|
18509
|
+
insertMode: "base64"
|
|
18510
|
+
};
|
|
18511
|
+
},
|
|
15356
18512
|
addProseMirrorPlugins() {
|
|
18513
|
+
const editor = this.editor;
|
|
18514
|
+
const options = this.options;
|
|
18515
|
+
const insertFiles = async (files, selectionPos) => {
|
|
18516
|
+
if (selectionPos !== void 0) {
|
|
18517
|
+
editor.commands.setTextSelection(selectionPos);
|
|
18518
|
+
}
|
|
18519
|
+
for (const file of files) {
|
|
18520
|
+
if (file.size > options.maxFileSize) continue;
|
|
18521
|
+
if (options.allowedMimeTypes.length > 0 && !options.allowedMimeTypes.includes(file.type)) continue;
|
|
18522
|
+
const src = await resolveImageSrc(file, options);
|
|
18523
|
+
editor.chain().focus().setImage({ src, alt: file.name }).run();
|
|
18524
|
+
editor.commands.createParagraphNear();
|
|
18525
|
+
}
|
|
18526
|
+
};
|
|
15357
18527
|
return [
|
|
15358
|
-
|
|
15359
|
-
|
|
15360
|
-
|
|
15361
|
-
|
|
15362
|
-
|
|
15363
|
-
|
|
15364
|
-
|
|
15365
|
-
|
|
15366
|
-
|
|
15367
|
-
|
|
15368
|
-
|
|
15369
|
-
|
|
15370
|
-
|
|
15371
|
-
|
|
15372
|
-
|
|
15373
|
-
|
|
15374
|
-
|
|
15375
|
-
|
|
15376
|
-
|
|
15377
|
-
|
|
15378
|
-
getReferenceClientRect: props.clientRect,
|
|
15379
|
-
appendTo: () => document.body,
|
|
15380
|
-
content: component.element,
|
|
15381
|
-
showOnCreate: true,
|
|
15382
|
-
interactive: true,
|
|
15383
|
-
trigger: "manual",
|
|
15384
|
-
placement: "bottom-start"
|
|
15385
|
-
});
|
|
15386
|
-
},
|
|
15387
|
-
onUpdate(props) {
|
|
15388
|
-
component?.updateProps(props);
|
|
15389
|
-
if (!props.clientRect) {
|
|
15390
|
-
return;
|
|
15391
|
-
}
|
|
15392
|
-
popup?.[0]?.setProps({
|
|
15393
|
-
getReferenceClientRect: props.clientRect
|
|
15394
|
-
});
|
|
15395
|
-
},
|
|
15396
|
-
onKeyDown(props) {
|
|
15397
|
-
if (props.event.key === "Escape") {
|
|
15398
|
-
popup?.[0]?.hide();
|
|
15399
|
-
return true;
|
|
15400
|
-
}
|
|
15401
|
-
return component?.ref?.onKeyDown(props) ?? false;
|
|
15402
|
-
},
|
|
15403
|
-
onExit() {
|
|
15404
|
-
popup?.[0]?.destroy();
|
|
15405
|
-
component?.destroy();
|
|
15406
|
-
}
|
|
15407
|
-
};
|
|
18528
|
+
new Plugin({
|
|
18529
|
+
props: {
|
|
18530
|
+
handlePaste: (_view, event) => {
|
|
18531
|
+
if (!(event instanceof ClipboardEvent)) return false;
|
|
18532
|
+
const files = getImageFiles(event.clipboardData);
|
|
18533
|
+
if (files.length === 0) return false;
|
|
18534
|
+
event.preventDefault();
|
|
18535
|
+
void insertFiles(files);
|
|
18536
|
+
return true;
|
|
18537
|
+
},
|
|
18538
|
+
handleDrop: (view, event, _slice, moved) => {
|
|
18539
|
+
if (moved) return false;
|
|
18540
|
+
if (!(event instanceof DragEvent)) return false;
|
|
18541
|
+
const files = getImageFiles(event.dataTransfer);
|
|
18542
|
+
if (files.length === 0) return false;
|
|
18543
|
+
const pos = view.posAtCoords({ left: event.clientX, top: event.clientY })?.pos;
|
|
18544
|
+
event.preventDefault();
|
|
18545
|
+
void insertFiles(files, pos);
|
|
18546
|
+
return true;
|
|
18547
|
+
}
|
|
15408
18548
|
}
|
|
15409
18549
|
})
|
|
15410
18550
|
];
|
|
15411
18551
|
}
|
|
15412
18552
|
});
|
|
15413
18553
|
|
|
18554
|
+
// ../../components/ui/UEditor/resizable-image.tsx
|
|
18555
|
+
import { useEffect as useEffect25, useRef as useRef22, useState as useState43 } from "react";
|
|
18556
|
+
import Image3 from "@tiptap/extension-image";
|
|
18557
|
+
import { mergeAttributes } from "@tiptap/core";
|
|
18558
|
+
import { NodeViewWrapper, ReactNodeViewRenderer } from "@tiptap/react";
|
|
18559
|
+
import { jsx as jsx69, jsxs as jsxs61 } from "react/jsx-runtime";
|
|
18560
|
+
var MIN_IMAGE_SIZE_PX = 40;
|
|
18561
|
+
var AXIS_LOCK_THRESHOLD_PX = 4;
|
|
18562
|
+
function toNullableNumber(value) {
|
|
18563
|
+
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
18564
|
+
if (typeof value === "string") {
|
|
18565
|
+
const parsed = Number.parseInt(value, 10);
|
|
18566
|
+
return Number.isFinite(parsed) ? parsed : null;
|
|
18567
|
+
}
|
|
18568
|
+
return null;
|
|
18569
|
+
}
|
|
18570
|
+
function clamp4(value, min, max) {
|
|
18571
|
+
return Math.min(max, Math.max(min, value));
|
|
18572
|
+
}
|
|
18573
|
+
function ResizableImageNodeView(props) {
|
|
18574
|
+
const { node, selected, updateAttributes, editor, getPos } = props;
|
|
18575
|
+
const wrapperRef = useRef22(null);
|
|
18576
|
+
const imgRef = useRef22(null);
|
|
18577
|
+
const [isHovered, setIsHovered] = useState43(false);
|
|
18578
|
+
const [isResizing, setIsResizing] = useState43(false);
|
|
18579
|
+
const widthAttr = toNullableNumber(node.attrs["width"]);
|
|
18580
|
+
const heightAttr = toNullableNumber(node.attrs["height"]);
|
|
18581
|
+
const textAlign = String(node.attrs["textAlign"] ?? "");
|
|
18582
|
+
const dragStateRef = useRef22(null);
|
|
18583
|
+
useEffect25(() => {
|
|
18584
|
+
const img = imgRef.current;
|
|
18585
|
+
if (!img) return;
|
|
18586
|
+
img.style.width = widthAttr ? `${widthAttr}px` : "";
|
|
18587
|
+
img.style.height = heightAttr ? `${heightAttr}px` : "";
|
|
18588
|
+
}, [widthAttr, heightAttr]);
|
|
18589
|
+
const selectNode = () => {
|
|
18590
|
+
const pos = typeof getPos === "function" ? getPos() : null;
|
|
18591
|
+
if (typeof pos === "number") editor.commands.setNodeSelection(pos);
|
|
18592
|
+
};
|
|
18593
|
+
const onResizePointerDown = (event) => {
|
|
18594
|
+
event.preventDefault();
|
|
18595
|
+
event.stopPropagation();
|
|
18596
|
+
const img = imgRef.current;
|
|
18597
|
+
const wrapper = wrapperRef.current;
|
|
18598
|
+
if (!img || !wrapper) return;
|
|
18599
|
+
selectNode();
|
|
18600
|
+
const rect = img.getBoundingClientRect();
|
|
18601
|
+
const editorEl = wrapper.closest(".ProseMirror");
|
|
18602
|
+
const maxW = editorEl ? editorEl.getBoundingClientRect().width : Number.POSITIVE_INFINITY;
|
|
18603
|
+
const startW = Math.max(MIN_IMAGE_SIZE_PX, rect.width);
|
|
18604
|
+
const startH = Math.max(MIN_IMAGE_SIZE_PX, rect.height);
|
|
18605
|
+
const aspect = startH > 0 ? startW / startH : 1;
|
|
18606
|
+
dragStateRef.current = {
|
|
18607
|
+
pointerId: event.pointerId,
|
|
18608
|
+
startX: event.clientX,
|
|
18609
|
+
startY: event.clientY,
|
|
18610
|
+
startW,
|
|
18611
|
+
startH,
|
|
18612
|
+
lastW: startW,
|
|
18613
|
+
lastH: startH,
|
|
18614
|
+
axis: null,
|
|
18615
|
+
aspect,
|
|
18616
|
+
maxW: Math.max(MIN_IMAGE_SIZE_PX, maxW)
|
|
18617
|
+
};
|
|
18618
|
+
setIsResizing(true);
|
|
18619
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
18620
|
+
};
|
|
18621
|
+
const onResizePointerMove = (event) => {
|
|
18622
|
+
const drag = dragStateRef.current;
|
|
18623
|
+
const img = imgRef.current;
|
|
18624
|
+
if (!drag || !img) return;
|
|
18625
|
+
if (event.pointerId !== drag.pointerId) return;
|
|
18626
|
+
const dx = event.clientX - drag.startX;
|
|
18627
|
+
const dy = event.clientY - drag.startY;
|
|
18628
|
+
let nextW = drag.startW;
|
|
18629
|
+
let nextH = drag.startH;
|
|
18630
|
+
if (event.ctrlKey) {
|
|
18631
|
+
if (Math.abs(dx) >= Math.abs(dy)) {
|
|
18632
|
+
nextW = clamp4(drag.startW + dx, MIN_IMAGE_SIZE_PX, drag.maxW);
|
|
18633
|
+
nextH = clamp4(nextW / drag.aspect, MIN_IMAGE_SIZE_PX, Number.POSITIVE_INFINITY);
|
|
18634
|
+
} else {
|
|
18635
|
+
nextH = clamp4(drag.startH + dy, MIN_IMAGE_SIZE_PX, Number.POSITIVE_INFINITY);
|
|
18636
|
+
nextW = clamp4(nextH * drag.aspect, MIN_IMAGE_SIZE_PX, drag.maxW);
|
|
18637
|
+
}
|
|
18638
|
+
} else {
|
|
18639
|
+
if (!drag.axis && (Math.abs(dx) > AXIS_LOCK_THRESHOLD_PX || Math.abs(dy) > AXIS_LOCK_THRESHOLD_PX)) {
|
|
18640
|
+
drag.axis = Math.abs(dx) >= Math.abs(dy) ? "x" : "y";
|
|
18641
|
+
}
|
|
18642
|
+
if (drag.axis === "x") nextW = clamp4(drag.startW + dx, MIN_IMAGE_SIZE_PX, drag.maxW);
|
|
18643
|
+
if (drag.axis === "y") nextH = clamp4(drag.startH + dy, MIN_IMAGE_SIZE_PX, Number.POSITIVE_INFINITY);
|
|
18644
|
+
}
|
|
18645
|
+
drag.lastW = nextW;
|
|
18646
|
+
drag.lastH = nextH;
|
|
18647
|
+
img.style.width = `${Math.round(nextW)}px`;
|
|
18648
|
+
img.style.height = `${Math.round(nextH)}px`;
|
|
18649
|
+
};
|
|
18650
|
+
const finishResize = () => {
|
|
18651
|
+
const drag = dragStateRef.current;
|
|
18652
|
+
dragStateRef.current = null;
|
|
18653
|
+
setIsResizing(false);
|
|
18654
|
+
if (!drag) return;
|
|
18655
|
+
updateAttributes({
|
|
18656
|
+
width: Math.round(drag.lastW),
|
|
18657
|
+
height: Math.round(drag.lastH)
|
|
18658
|
+
});
|
|
18659
|
+
};
|
|
18660
|
+
const onResizePointerUp = (event) => {
|
|
18661
|
+
const drag = dragStateRef.current;
|
|
18662
|
+
if (!drag || event.pointerId !== drag.pointerId) return;
|
|
18663
|
+
event.preventDefault();
|
|
18664
|
+
event.stopPropagation();
|
|
18665
|
+
finishResize();
|
|
18666
|
+
};
|
|
18667
|
+
const onResizePointerCancel = (event) => {
|
|
18668
|
+
const drag = dragStateRef.current;
|
|
18669
|
+
if (!drag || event.pointerId !== drag.pointerId) return;
|
|
18670
|
+
event.preventDefault();
|
|
18671
|
+
event.stopPropagation();
|
|
18672
|
+
finishResize();
|
|
18673
|
+
};
|
|
18674
|
+
const showHandle = selected || isHovered || isResizing;
|
|
18675
|
+
const wrapperAlignClass = textAlign === "center" ? "mx-auto" : textAlign === "right" ? "ml-auto" : textAlign === "justify" ? "mx-auto" : "";
|
|
18676
|
+
const wrapperWidthClass = "w-fit";
|
|
18677
|
+
return /* @__PURE__ */ jsxs61(
|
|
18678
|
+
NodeViewWrapper,
|
|
18679
|
+
{
|
|
18680
|
+
as: "div",
|
|
18681
|
+
ref: wrapperRef,
|
|
18682
|
+
className: ["relative block align-middle max-w-full my-4", wrapperWidthClass, wrapperAlignClass].filter(Boolean).join(" "),
|
|
18683
|
+
onMouseEnter: () => setIsHovered(true),
|
|
18684
|
+
onMouseLeave: () => setIsHovered(false),
|
|
18685
|
+
onClick: (e) => {
|
|
18686
|
+
e.stopPropagation();
|
|
18687
|
+
selectNode();
|
|
18688
|
+
},
|
|
18689
|
+
contentEditable: false,
|
|
18690
|
+
children: [
|
|
18691
|
+
/* @__PURE__ */ jsx69(
|
|
18692
|
+
"img",
|
|
18693
|
+
{
|
|
18694
|
+
ref: imgRef,
|
|
18695
|
+
src: String(node.attrs["src"] ?? ""),
|
|
18696
|
+
alt: String(node.attrs["alt"] ?? ""),
|
|
18697
|
+
title: String(node.attrs["title"] ?? ""),
|
|
18698
|
+
draggable: "true",
|
|
18699
|
+
className: [
|
|
18700
|
+
"block rounded-lg max-w-full",
|
|
18701
|
+
selected ? "ring-2 ring-primary/60 ring-offset-2 ring-offset-background" : "",
|
|
18702
|
+
isResizing ? "select-none" : ""
|
|
18703
|
+
].join(" "),
|
|
18704
|
+
style: {
|
|
18705
|
+
width: widthAttr ? `${widthAttr}px` : void 0,
|
|
18706
|
+
height: heightAttr ? `${heightAttr}px` : void 0
|
|
18707
|
+
}
|
|
18708
|
+
}
|
|
18709
|
+
),
|
|
18710
|
+
showHandle && /* @__PURE__ */ jsx69(
|
|
18711
|
+
"div",
|
|
18712
|
+
{
|
|
18713
|
+
"aria-hidden": "true",
|
|
18714
|
+
onPointerDown: onResizePointerDown,
|
|
18715
|
+
onPointerMove: onResizePointerMove,
|
|
18716
|
+
onPointerUp: onResizePointerUp,
|
|
18717
|
+
onPointerCancel: onResizePointerCancel,
|
|
18718
|
+
className: [
|
|
18719
|
+
"absolute -right-1 -bottom-1 h-3 w-3 rounded-sm",
|
|
18720
|
+
"bg-primary border border-background shadow-sm",
|
|
18721
|
+
"cursor-nwse-resize",
|
|
18722
|
+
"opacity-90 hover:opacity-100"
|
|
18723
|
+
].join(" ")
|
|
18724
|
+
}
|
|
18725
|
+
)
|
|
18726
|
+
]
|
|
18727
|
+
}
|
|
18728
|
+
);
|
|
18729
|
+
}
|
|
18730
|
+
var ResizableImage = Image3.extend({
|
|
18731
|
+
addAttributes() {
|
|
18732
|
+
const parentAttrs = this.parent?.() ?? {};
|
|
18733
|
+
return {
|
|
18734
|
+
...parentAttrs,
|
|
18735
|
+
width: {
|
|
18736
|
+
default: null,
|
|
18737
|
+
parseHTML: (element) => {
|
|
18738
|
+
const raw = element.getAttribute("width") || element.style.width || "";
|
|
18739
|
+
const parsed = Number.parseInt(raw, 10);
|
|
18740
|
+
return Number.isFinite(parsed) ? parsed : null;
|
|
18741
|
+
},
|
|
18742
|
+
renderHTML: (attrs) => typeof attrs.width === "number" ? { width: attrs.width } : {}
|
|
18743
|
+
},
|
|
18744
|
+
height: {
|
|
18745
|
+
default: null,
|
|
18746
|
+
parseHTML: (element) => {
|
|
18747
|
+
const raw = element.getAttribute("height") || element.style.height || "";
|
|
18748
|
+
const parsed = Number.parseInt(raw, 10);
|
|
18749
|
+
return Number.isFinite(parsed) ? parsed : null;
|
|
18750
|
+
},
|
|
18751
|
+
renderHTML: (attrs) => typeof attrs.height === "number" ? { height: attrs.height } : {}
|
|
18752
|
+
}
|
|
18753
|
+
};
|
|
18754
|
+
},
|
|
18755
|
+
renderHTML({ HTMLAttributes: HTMLAttributes2 }) {
|
|
18756
|
+
return ["img", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes2)];
|
|
18757
|
+
},
|
|
18758
|
+
addNodeView() {
|
|
18759
|
+
return ReactNodeViewRenderer(ResizableImageNodeView);
|
|
18760
|
+
}
|
|
18761
|
+
}).configure({
|
|
18762
|
+
allowBase64: true,
|
|
18763
|
+
HTMLAttributes: {
|
|
18764
|
+
class: "rounded-lg max-w-full my-4"
|
|
18765
|
+
}
|
|
18766
|
+
});
|
|
18767
|
+
var resizable_image_default = ResizableImage;
|
|
18768
|
+
|
|
15414
18769
|
// ../../components/ui/UEditor/extensions.ts
|
|
15415
18770
|
var lowlight = createLowlight(common);
|
|
15416
|
-
function buildUEditorExtensions({
|
|
18771
|
+
function buildUEditorExtensions({
|
|
18772
|
+
placeholder,
|
|
18773
|
+
maxCharacters,
|
|
18774
|
+
uploadImage,
|
|
18775
|
+
imageInsertMode = "base64",
|
|
18776
|
+
editable = true
|
|
18777
|
+
}) {
|
|
15417
18778
|
return [
|
|
15418
18779
|
Document,
|
|
15419
18780
|
Paragraph,
|
|
@@ -15469,18 +18830,15 @@ function buildUEditorExtensions({ placeholder, maxCharacters }) {
|
|
|
15469
18830
|
class: "text-primary underline underline-offset-2 hover:text-primary/80 cursor-pointer"
|
|
15470
18831
|
}
|
|
15471
18832
|
}),
|
|
15472
|
-
|
|
15473
|
-
|
|
15474
|
-
class: "rounded-lg max-w-full h-auto my-4"
|
|
15475
|
-
}
|
|
15476
|
-
}),
|
|
18833
|
+
resizable_image_default,
|
|
18834
|
+
ClipboardImages.configure({ upload: uploadImage, insertMode: imageInsertMode }),
|
|
15477
18835
|
TextStyle,
|
|
15478
18836
|
Color,
|
|
15479
18837
|
Highlight.configure({
|
|
15480
18838
|
multicolor: true
|
|
15481
18839
|
}),
|
|
15482
18840
|
TextAlign.configure({
|
|
15483
|
-
types: ["heading", "paragraph"]
|
|
18841
|
+
types: ["heading", "paragraph", "image"]
|
|
15484
18842
|
}),
|
|
15485
18843
|
Table3.configure({
|
|
15486
18844
|
resizable: true,
|
|
@@ -15514,7 +18872,7 @@ function buildUEditorExtensions({ placeholder, maxCharacters }) {
|
|
|
15514
18872
|
}
|
|
15515
18873
|
|
|
15516
18874
|
// ../../components/ui/UEditor/toolbar.tsx
|
|
15517
|
-
import
|
|
18875
|
+
import React60, { useRef as useRef24, useState as useState45 } from "react";
|
|
15518
18876
|
import { useTranslations as useTranslations4 } from "next-intl";
|
|
15519
18877
|
import {
|
|
15520
18878
|
AlignCenter,
|
|
@@ -15547,14 +18905,15 @@ import {
|
|
|
15547
18905
|
Trash2,
|
|
15548
18906
|
Type as Type2,
|
|
15549
18907
|
Underline as UnderlineIcon,
|
|
15550
|
-
Undo as UndoIcon
|
|
18908
|
+
Undo as UndoIcon,
|
|
18909
|
+
Upload as Upload2
|
|
15551
18910
|
} from "lucide-react";
|
|
15552
18911
|
|
|
15553
18912
|
// ../../components/ui/UEditor/colors.tsx
|
|
15554
18913
|
import { useMemo as useMemo14 } from "react";
|
|
15555
18914
|
import { useTranslations as useTranslations2 } from "next-intl";
|
|
15556
18915
|
import { X as X14 } from "lucide-react";
|
|
15557
|
-
import { jsx as
|
|
18916
|
+
import { jsx as jsx70, jsxs as jsxs62 } from "react/jsx-runtime";
|
|
15558
18917
|
var useEditorColors = () => {
|
|
15559
18918
|
const t = useTranslations2("UEditor");
|
|
15560
18919
|
const textColors = useMemo14(
|
|
@@ -15591,9 +18950,9 @@ var EditorColorPalette = ({
|
|
|
15591
18950
|
currentColor,
|
|
15592
18951
|
onSelect,
|
|
15593
18952
|
label
|
|
15594
|
-
}) => /* @__PURE__ */
|
|
15595
|
-
/* @__PURE__ */
|
|
15596
|
-
/* @__PURE__ */
|
|
18953
|
+
}) => /* @__PURE__ */ jsxs62("div", { className: "p-2", children: [
|
|
18954
|
+
/* @__PURE__ */ jsx70("span", { className: "text-xs font-medium text-muted-foreground uppercase tracking-wider px-2", children: label }),
|
|
18955
|
+
/* @__PURE__ */ jsx70("div", { className: "grid grid-cols-4 gap-1.5 mt-2", children: colors.map((c) => /* @__PURE__ */ jsxs62(
|
|
15597
18956
|
"button",
|
|
15598
18957
|
{
|
|
15599
18958
|
type: "button",
|
|
@@ -15606,8 +18965,8 @@ var EditorColorPalette = ({
|
|
|
15606
18965
|
style: { backgroundColor: c.color || "transparent" },
|
|
15607
18966
|
title: c.name,
|
|
15608
18967
|
children: [
|
|
15609
|
-
c.color === "" && /* @__PURE__ */
|
|
15610
|
-
c.color === "inherit" && /* @__PURE__ */
|
|
18968
|
+
c.color === "" && /* @__PURE__ */ jsx70(X14, { className: "w-4 h-4 text-muted-foreground" }),
|
|
18969
|
+
c.color === "inherit" && /* @__PURE__ */ jsx70("span", { className: "text-xs font-medium", children: "A" })
|
|
15611
18970
|
]
|
|
15612
18971
|
},
|
|
15613
18972
|
c.name
|
|
@@ -15615,30 +18974,36 @@ var EditorColorPalette = ({
|
|
|
15615
18974
|
] });
|
|
15616
18975
|
|
|
15617
18976
|
// ../../components/ui/UEditor/inputs.tsx
|
|
15618
|
-
import { useEffect as
|
|
18977
|
+
import { useEffect as useEffect26, useRef as useRef23, useState as useState44 } from "react";
|
|
15619
18978
|
import { useTranslations as useTranslations3 } from "next-intl";
|
|
15620
18979
|
import { Check as Check9, X as X15 } from "lucide-react";
|
|
15621
|
-
import { jsx as
|
|
18980
|
+
import { jsx as jsx71, jsxs as jsxs63 } from "react/jsx-runtime";
|
|
18981
|
+
function normalizeUrl(raw) {
|
|
18982
|
+
const url = raw.trim();
|
|
18983
|
+
if (!url) return "";
|
|
18984
|
+
if (url.startsWith("#") || url.startsWith("/")) return url;
|
|
18985
|
+
if (/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(url)) return url;
|
|
18986
|
+
return `https://${url}`;
|
|
18987
|
+
}
|
|
15622
18988
|
var LinkInput = ({
|
|
15623
18989
|
onSubmit,
|
|
15624
18990
|
onCancel,
|
|
15625
18991
|
initialUrl = ""
|
|
15626
18992
|
}) => {
|
|
15627
18993
|
const t = useTranslations3("UEditor");
|
|
15628
|
-
const [url, setUrl] =
|
|
15629
|
-
const inputRef =
|
|
15630
|
-
|
|
18994
|
+
const [url, setUrl] = useState44(initialUrl);
|
|
18995
|
+
const inputRef = useRef23(null);
|
|
18996
|
+
useEffect26(() => {
|
|
15631
18997
|
inputRef.current?.focus();
|
|
15632
18998
|
inputRef.current?.select();
|
|
15633
18999
|
}, []);
|
|
15634
19000
|
const handleSubmit = (e) => {
|
|
15635
19001
|
e.preventDefault();
|
|
15636
|
-
|
|
15637
|
-
|
|
15638
|
-
}
|
|
19002
|
+
const normalized = normalizeUrl(url);
|
|
19003
|
+
if (normalized) onSubmit(normalized);
|
|
15639
19004
|
};
|
|
15640
|
-
return /* @__PURE__ */
|
|
15641
|
-
/* @__PURE__ */
|
|
19005
|
+
return /* @__PURE__ */ jsxs63("form", { onSubmit: handleSubmit, className: "flex items-center gap-2 p-2", children: [
|
|
19006
|
+
/* @__PURE__ */ jsx71(
|
|
15642
19007
|
"input",
|
|
15643
19008
|
{
|
|
15644
19009
|
ref: inputRef,
|
|
@@ -15649,16 +19014,16 @@ var LinkInput = ({
|
|
|
15649
19014
|
className: "flex-1 px-3 py-2 text-sm bg-muted/50 border-0 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary/20"
|
|
15650
19015
|
}
|
|
15651
19016
|
),
|
|
15652
|
-
/* @__PURE__ */
|
|
15653
|
-
/* @__PURE__ */
|
|
19017
|
+
/* @__PURE__ */ jsx71("button", { type: "submit", className: "p-2 rounded-lg bg-primary text-primary-foreground hover:bg-primary/90 transition-colors", children: /* @__PURE__ */ jsx71(Check9, { className: "w-4 h-4" }) }),
|
|
19018
|
+
/* @__PURE__ */ jsx71("button", { type: "button", onClick: onCancel, className: "p-2 rounded-lg hover:bg-muted transition-colors text-muted-foreground", children: /* @__PURE__ */ jsx71(X15, { className: "w-4 h-4" }) })
|
|
15654
19019
|
] });
|
|
15655
19020
|
};
|
|
15656
19021
|
var ImageInput = ({ onSubmit, onCancel }) => {
|
|
15657
19022
|
const t = useTranslations3("UEditor");
|
|
15658
|
-
const [url, setUrl] =
|
|
15659
|
-
const [alt, setAlt] =
|
|
15660
|
-
const inputRef =
|
|
15661
|
-
|
|
19023
|
+
const [url, setUrl] = useState44("");
|
|
19024
|
+
const [alt, setAlt] = useState44("");
|
|
19025
|
+
const inputRef = useRef23(null);
|
|
19026
|
+
useEffect26(() => {
|
|
15662
19027
|
inputRef.current?.focus();
|
|
15663
19028
|
}, []);
|
|
15664
19029
|
const handleSubmit = (e) => {
|
|
@@ -15667,10 +19032,10 @@ var ImageInput = ({ onSubmit, onCancel }) => {
|
|
|
15667
19032
|
onSubmit(url, alt);
|
|
15668
19033
|
}
|
|
15669
19034
|
};
|
|
15670
|
-
return /* @__PURE__ */
|
|
15671
|
-
/* @__PURE__ */
|
|
15672
|
-
/* @__PURE__ */
|
|
15673
|
-
/* @__PURE__ */
|
|
19035
|
+
return /* @__PURE__ */ jsxs63("form", { onSubmit: handleSubmit, className: "p-3 space-y-3", children: [
|
|
19036
|
+
/* @__PURE__ */ jsxs63("div", { children: [
|
|
19037
|
+
/* @__PURE__ */ jsx71("label", { className: "text-xs font-medium text-muted-foreground", children: t("imageInput.urlLabel") }),
|
|
19038
|
+
/* @__PURE__ */ jsx71(
|
|
15674
19039
|
"input",
|
|
15675
19040
|
{
|
|
15676
19041
|
ref: inputRef,
|
|
@@ -15682,9 +19047,9 @@ var ImageInput = ({ onSubmit, onCancel }) => {
|
|
|
15682
19047
|
}
|
|
15683
19048
|
)
|
|
15684
19049
|
] }),
|
|
15685
|
-
/* @__PURE__ */
|
|
15686
|
-
/* @__PURE__ */
|
|
15687
|
-
/* @__PURE__ */
|
|
19050
|
+
/* @__PURE__ */ jsxs63("div", { children: [
|
|
19051
|
+
/* @__PURE__ */ jsx71("label", { className: "text-xs font-medium text-muted-foreground", children: t("imageInput.altLabel") }),
|
|
19052
|
+
/* @__PURE__ */ jsx71(
|
|
15688
19053
|
"input",
|
|
15689
19054
|
{
|
|
15690
19055
|
type: "text",
|
|
@@ -15695,8 +19060,8 @@ var ImageInput = ({ onSubmit, onCancel }) => {
|
|
|
15695
19060
|
}
|
|
15696
19061
|
)
|
|
15697
19062
|
] }),
|
|
15698
|
-
/* @__PURE__ */
|
|
15699
|
-
/* @__PURE__ */
|
|
19063
|
+
/* @__PURE__ */ jsxs63("div", { className: "flex gap-2", children: [
|
|
19064
|
+
/* @__PURE__ */ jsx71(
|
|
15700
19065
|
"button",
|
|
15701
19066
|
{
|
|
15702
19067
|
type: "submit",
|
|
@@ -15705,20 +19070,31 @@ var ImageInput = ({ onSubmit, onCancel }) => {
|
|
|
15705
19070
|
children: t("imageInput.addBtn")
|
|
15706
19071
|
}
|
|
15707
19072
|
),
|
|
15708
|
-
/* @__PURE__ */
|
|
19073
|
+
/* @__PURE__ */ jsx71("button", { type: "button", onClick: onCancel, className: "px-4 py-2 rounded-lg hover:bg-muted transition-colors text-muted-foreground", children: t("imageInput.cancelBtn") })
|
|
15709
19074
|
] })
|
|
15710
19075
|
] });
|
|
15711
19076
|
};
|
|
15712
19077
|
|
|
15713
19078
|
// ../../components/ui/UEditor/toolbar.tsx
|
|
15714
|
-
import { jsx as
|
|
15715
|
-
|
|
15716
|
-
|
|
19079
|
+
import { Fragment as Fragment26, jsx as jsx72, jsxs as jsxs64 } from "react/jsx-runtime";
|
|
19080
|
+
function fileToDataUrl2(file) {
|
|
19081
|
+
return new Promise((resolve, reject) => {
|
|
19082
|
+
const reader = new FileReader();
|
|
19083
|
+
reader.onload = () => resolve(String(reader.result ?? ""));
|
|
19084
|
+
reader.onerror = () => reject(reader.error ?? new Error("Failed to read image file"));
|
|
19085
|
+
reader.readAsDataURL(file);
|
|
19086
|
+
});
|
|
19087
|
+
}
|
|
19088
|
+
var ToolbarButton = React60.forwardRef(({ onClick, onMouseDown, active, disabled, children, title, className }, ref) => {
|
|
19089
|
+
const button = /* @__PURE__ */ jsx72(
|
|
15717
19090
|
"button",
|
|
15718
19091
|
{
|
|
15719
19092
|
ref,
|
|
15720
19093
|
type: "button",
|
|
15721
|
-
onMouseDown: (e) =>
|
|
19094
|
+
onMouseDown: (e) => {
|
|
19095
|
+
onMouseDown?.(e);
|
|
19096
|
+
e.preventDefault();
|
|
19097
|
+
},
|
|
15722
19098
|
onClick,
|
|
15723
19099
|
disabled,
|
|
15724
19100
|
className: cn(
|
|
@@ -15733,51 +19109,76 @@ var ToolbarButton = React59.forwardRef(({ onClick, active, disabled, children, t
|
|
|
15733
19109
|
}
|
|
15734
19110
|
);
|
|
15735
19111
|
if (title) {
|
|
15736
|
-
return /* @__PURE__ */
|
|
19112
|
+
return /* @__PURE__ */ jsx72(Tooltip, { content: title, placement: "top", delay: { open: 500, close: 0 }, children: button });
|
|
15737
19113
|
}
|
|
15738
19114
|
return button;
|
|
15739
19115
|
});
|
|
15740
19116
|
ToolbarButton.displayName = "ToolbarButton";
|
|
15741
|
-
var ToolbarDivider = () => /* @__PURE__ */
|
|
15742
|
-
var EditorToolbar = ({
|
|
19117
|
+
var ToolbarDivider = () => /* @__PURE__ */ jsx72("div", { className: "w-px h-6 bg-border/50 mx-1" });
|
|
19118
|
+
var EditorToolbar = ({
|
|
19119
|
+
editor,
|
|
19120
|
+
variant,
|
|
19121
|
+
uploadImage,
|
|
19122
|
+
imageInsertMode = "base64"
|
|
19123
|
+
}) => {
|
|
15743
19124
|
const t = useTranslations4("UEditor");
|
|
15744
19125
|
const { textColors, highlightColors } = useEditorColors();
|
|
15745
|
-
const [showImageInput, setShowImageInput] =
|
|
19126
|
+
const [showImageInput, setShowImageInput] = useState45(false);
|
|
19127
|
+
const fileInputRef = useRef24(null);
|
|
19128
|
+
const [isUploadingImage, setIsUploadingImage] = useState45(false);
|
|
19129
|
+
const [imageUploadError, setImageUploadError] = useState45(null);
|
|
19130
|
+
const insertImageFiles = async (files) => {
|
|
19131
|
+
if (files.length === 0) return;
|
|
19132
|
+
setIsUploadingImage(true);
|
|
19133
|
+
setImageUploadError(null);
|
|
19134
|
+
for (const file of files) {
|
|
19135
|
+
if (!file.type.startsWith("image/")) continue;
|
|
19136
|
+
try {
|
|
19137
|
+
const src = imageInsertMode === "upload" && uploadImage ? await uploadImage(file) : await fileToDataUrl2(file);
|
|
19138
|
+
if (!src) continue;
|
|
19139
|
+
editor.chain().focus().setImage({ src, alt: file.name }).run();
|
|
19140
|
+
editor.commands.createParagraphNear();
|
|
19141
|
+
} catch {
|
|
19142
|
+
setImageUploadError(t("imageInput.uploadError"));
|
|
19143
|
+
}
|
|
19144
|
+
}
|
|
19145
|
+
setIsUploadingImage(false);
|
|
19146
|
+
};
|
|
15746
19147
|
if (variant === "minimal") {
|
|
15747
|
-
return /* @__PURE__ */
|
|
15748
|
-
/* @__PURE__ */
|
|
15749
|
-
/* @__PURE__ */
|
|
19148
|
+
return /* @__PURE__ */ jsxs64("div", { className: "flex items-center gap-1 p-2 border-b bg-muted/30", children: [
|
|
19149
|
+
/* @__PURE__ */ jsx72(ToolbarButton, { onClick: () => editor.chain().focus().toggleBold().run(), active: editor.isActive("bold"), title: t("toolbar.bold"), children: /* @__PURE__ */ jsx72(BoldIcon, { className: "w-4 h-4" }) }),
|
|
19150
|
+
/* @__PURE__ */ jsx72(
|
|
15750
19151
|
ToolbarButton,
|
|
15751
19152
|
{
|
|
15752
19153
|
onClick: () => editor.chain().focus().toggleItalic().run(),
|
|
15753
19154
|
active: editor.isActive("italic"),
|
|
15754
19155
|
title: t("toolbar.italic"),
|
|
15755
|
-
children: /* @__PURE__ */
|
|
19156
|
+
children: /* @__PURE__ */ jsx72(ItalicIcon, { className: "w-4 h-4" })
|
|
15756
19157
|
}
|
|
15757
19158
|
),
|
|
15758
|
-
/* @__PURE__ */
|
|
19159
|
+
/* @__PURE__ */ jsx72(
|
|
15759
19160
|
ToolbarButton,
|
|
15760
19161
|
{
|
|
15761
19162
|
onClick: () => editor.chain().focus().toggleBulletList().run(),
|
|
15762
19163
|
active: editor.isActive("bulletList"),
|
|
15763
19164
|
title: t("toolbar.bulletList"),
|
|
15764
|
-
children: /* @__PURE__ */
|
|
19165
|
+
children: /* @__PURE__ */ jsx72(ListIcon, { className: "w-4 h-4" })
|
|
15765
19166
|
}
|
|
15766
19167
|
)
|
|
15767
19168
|
] });
|
|
15768
19169
|
}
|
|
15769
|
-
return /* @__PURE__ */
|
|
15770
|
-
/* @__PURE__ */
|
|
19170
|
+
return /* @__PURE__ */ jsxs64("div", { className: "flex flex-wrap items-center gap-1 p-2 border-b bg-linear-to-r from-muted/30 to-transparent", children: [
|
|
19171
|
+
/* @__PURE__ */ jsxs64(
|
|
15771
19172
|
DropdownMenu,
|
|
15772
19173
|
{
|
|
15773
|
-
trigger: /* @__PURE__ */
|
|
19174
|
+
trigger: /* @__PURE__ */ jsxs64(ToolbarButton, { onClick: () => {
|
|
15774
19175
|
}, title: t("toolbar.textStyle"), className: "px-2 w-auto gap-1", children: [
|
|
15775
|
-
/* @__PURE__ */
|
|
15776
|
-
/* @__PURE__ */
|
|
19176
|
+
/* @__PURE__ */ jsx72(Type2, { className: "w-4 h-4" }),
|
|
19177
|
+
/* @__PURE__ */ jsx72(ChevronDown5, { className: "w-3 h-3" })
|
|
15777
19178
|
] }),
|
|
15778
19179
|
children: [
|
|
15779
|
-
/* @__PURE__ */
|
|
15780
|
-
/* @__PURE__ */
|
|
19180
|
+
/* @__PURE__ */ jsx72(DropdownMenuItem, { icon: Type2, label: t("toolbar.normal"), onClick: () => editor.chain().focus().setParagraph().run(), active: editor.isActive("paragraph") }),
|
|
19181
|
+
/* @__PURE__ */ jsx72(
|
|
15781
19182
|
DropdownMenuItem,
|
|
15782
19183
|
{
|
|
15783
19184
|
icon: Heading1Icon,
|
|
@@ -15787,7 +19188,7 @@ var EditorToolbar = ({ editor, variant }) => {
|
|
|
15787
19188
|
shortcut: "Ctrl+Alt+1"
|
|
15788
19189
|
}
|
|
15789
19190
|
),
|
|
15790
|
-
/* @__PURE__ */
|
|
19191
|
+
/* @__PURE__ */ jsx72(
|
|
15791
19192
|
DropdownMenuItem,
|
|
15792
19193
|
{
|
|
15793
19194
|
icon: Heading2Icon,
|
|
@@ -15797,7 +19198,7 @@ var EditorToolbar = ({ editor, variant }) => {
|
|
|
15797
19198
|
shortcut: "Ctrl+Alt+2"
|
|
15798
19199
|
}
|
|
15799
19200
|
),
|
|
15800
|
-
/* @__PURE__ */
|
|
19201
|
+
/* @__PURE__ */ jsx72(
|
|
15801
19202
|
DropdownMenuItem,
|
|
15802
19203
|
{
|
|
15803
19204
|
icon: Heading3Icon,
|
|
@@ -15810,46 +19211,46 @@ var EditorToolbar = ({ editor, variant }) => {
|
|
|
15810
19211
|
]
|
|
15811
19212
|
}
|
|
15812
19213
|
),
|
|
15813
|
-
/* @__PURE__ */
|
|
15814
|
-
/* @__PURE__ */
|
|
15815
|
-
/* @__PURE__ */
|
|
19214
|
+
/* @__PURE__ */ jsx72(ToolbarDivider, {}),
|
|
19215
|
+
/* @__PURE__ */ jsx72(ToolbarButton, { onClick: () => editor.chain().focus().toggleBold().run(), active: editor.isActive("bold"), title: t("toolbar.bold"), children: /* @__PURE__ */ jsx72(BoldIcon, { className: "w-4 h-4" }) }),
|
|
19216
|
+
/* @__PURE__ */ jsx72(
|
|
15816
19217
|
ToolbarButton,
|
|
15817
19218
|
{
|
|
15818
19219
|
onClick: () => editor.chain().focus().toggleItalic().run(),
|
|
15819
19220
|
active: editor.isActive("italic"),
|
|
15820
19221
|
title: t("toolbar.italic"),
|
|
15821
|
-
children: /* @__PURE__ */
|
|
19222
|
+
children: /* @__PURE__ */ jsx72(ItalicIcon, { className: "w-4 h-4" })
|
|
15822
19223
|
}
|
|
15823
19224
|
),
|
|
15824
|
-
/* @__PURE__ */
|
|
19225
|
+
/* @__PURE__ */ jsx72(
|
|
15825
19226
|
ToolbarButton,
|
|
15826
19227
|
{
|
|
15827
19228
|
onClick: () => editor.chain().focus().toggleUnderline().run(),
|
|
15828
19229
|
active: editor.isActive("underline"),
|
|
15829
19230
|
title: t("toolbar.underline"),
|
|
15830
|
-
children: /* @__PURE__ */
|
|
19231
|
+
children: /* @__PURE__ */ jsx72(UnderlineIcon, { className: "w-4 h-4" })
|
|
15831
19232
|
}
|
|
15832
19233
|
),
|
|
15833
|
-
/* @__PURE__ */
|
|
19234
|
+
/* @__PURE__ */ jsx72(
|
|
15834
19235
|
ToolbarButton,
|
|
15835
19236
|
{
|
|
15836
19237
|
onClick: () => editor.chain().focus().toggleStrike().run(),
|
|
15837
19238
|
active: editor.isActive("strike"),
|
|
15838
19239
|
title: t("toolbar.strike"),
|
|
15839
|
-
children: /* @__PURE__ */
|
|
19240
|
+
children: /* @__PURE__ */ jsx72(StrikethroughIcon, { className: "w-4 h-4" })
|
|
15840
19241
|
}
|
|
15841
19242
|
),
|
|
15842
|
-
/* @__PURE__ */
|
|
15843
|
-
/* @__PURE__ */
|
|
15844
|
-
/* @__PURE__ */
|
|
19243
|
+
/* @__PURE__ */ jsx72(ToolbarButton, { onClick: () => editor.chain().focus().toggleCode().run(), active: editor.isActive("code"), title: t("toolbar.code"), children: /* @__PURE__ */ jsx72(CodeIcon, { className: "w-4 h-4" }) }),
|
|
19244
|
+
/* @__PURE__ */ jsx72(ToolbarDivider, {}),
|
|
19245
|
+
/* @__PURE__ */ jsx72(
|
|
15845
19246
|
DropdownMenu,
|
|
15846
19247
|
{
|
|
15847
|
-
trigger: /* @__PURE__ */
|
|
19248
|
+
trigger: /* @__PURE__ */ jsxs64(ToolbarButton, { onClick: () => {
|
|
15848
19249
|
}, title: t("colors.textColor"), children: [
|
|
15849
|
-
/* @__PURE__ */
|
|
15850
|
-
/* @__PURE__ */
|
|
19250
|
+
/* @__PURE__ */ jsx72(Palette2, { className: "w-4 h-4" }),
|
|
19251
|
+
/* @__PURE__ */ jsx72(ChevronDown5, { className: "w-3 h-3" })
|
|
15851
19252
|
] }),
|
|
15852
|
-
children: /* @__PURE__ */
|
|
19253
|
+
children: /* @__PURE__ */ jsx72(
|
|
15853
19254
|
EditorColorPalette,
|
|
15854
19255
|
{
|
|
15855
19256
|
colors: textColors,
|
|
@@ -15866,15 +19267,15 @@ var EditorToolbar = ({ editor, variant }) => {
|
|
|
15866
19267
|
)
|
|
15867
19268
|
}
|
|
15868
19269
|
),
|
|
15869
|
-
/* @__PURE__ */
|
|
19270
|
+
/* @__PURE__ */ jsx72(
|
|
15870
19271
|
DropdownMenu,
|
|
15871
19272
|
{
|
|
15872
|
-
trigger: /* @__PURE__ */
|
|
19273
|
+
trigger: /* @__PURE__ */ jsxs64(ToolbarButton, { onClick: () => {
|
|
15873
19274
|
}, active: editor.isActive("highlight"), title: t("colors.highlight"), children: [
|
|
15874
|
-
/* @__PURE__ */
|
|
15875
|
-
/* @__PURE__ */
|
|
19275
|
+
/* @__PURE__ */ jsx72(Highlighter, { className: "w-4 h-4" }),
|
|
19276
|
+
/* @__PURE__ */ jsx72(ChevronDown5, { className: "w-3 h-3" })
|
|
15876
19277
|
] }),
|
|
15877
|
-
children: /* @__PURE__ */
|
|
19278
|
+
children: /* @__PURE__ */ jsx72(
|
|
15878
19279
|
EditorColorPalette,
|
|
15879
19280
|
{
|
|
15880
19281
|
colors: highlightColors,
|
|
@@ -15891,17 +19292,17 @@ var EditorToolbar = ({ editor, variant }) => {
|
|
|
15891
19292
|
)
|
|
15892
19293
|
}
|
|
15893
19294
|
),
|
|
15894
|
-
/* @__PURE__ */
|
|
15895
|
-
/* @__PURE__ */
|
|
19295
|
+
/* @__PURE__ */ jsx72(ToolbarDivider, {}),
|
|
19296
|
+
/* @__PURE__ */ jsxs64(
|
|
15896
19297
|
DropdownMenu,
|
|
15897
19298
|
{
|
|
15898
|
-
trigger: /* @__PURE__ */
|
|
19299
|
+
trigger: /* @__PURE__ */ jsxs64(ToolbarButton, { onClick: () => {
|
|
15899
19300
|
}, title: t("toolbar.alignment"), children: [
|
|
15900
|
-
/* @__PURE__ */
|
|
15901
|
-
/* @__PURE__ */
|
|
19301
|
+
/* @__PURE__ */ jsx72(AlignLeft, { className: "w-4 h-4" }),
|
|
19302
|
+
/* @__PURE__ */ jsx72(ChevronDown5, { className: "w-3 h-3" })
|
|
15902
19303
|
] }),
|
|
15903
19304
|
children: [
|
|
15904
|
-
/* @__PURE__ */
|
|
19305
|
+
/* @__PURE__ */ jsx72(
|
|
15905
19306
|
DropdownMenuItem,
|
|
15906
19307
|
{
|
|
15907
19308
|
icon: AlignLeft,
|
|
@@ -15910,7 +19311,7 @@ var EditorToolbar = ({ editor, variant }) => {
|
|
|
15910
19311
|
active: editor.isActive({ textAlign: "left" })
|
|
15911
19312
|
}
|
|
15912
19313
|
),
|
|
15913
|
-
/* @__PURE__ */
|
|
19314
|
+
/* @__PURE__ */ jsx72(
|
|
15914
19315
|
DropdownMenuItem,
|
|
15915
19316
|
{
|
|
15916
19317
|
icon: AlignCenter,
|
|
@@ -15919,7 +19320,7 @@ var EditorToolbar = ({ editor, variant }) => {
|
|
|
15919
19320
|
active: editor.isActive({ textAlign: "center" })
|
|
15920
19321
|
}
|
|
15921
19322
|
),
|
|
15922
|
-
/* @__PURE__ */
|
|
19323
|
+
/* @__PURE__ */ jsx72(
|
|
15923
19324
|
DropdownMenuItem,
|
|
15924
19325
|
{
|
|
15925
19326
|
icon: AlignRight,
|
|
@@ -15928,7 +19329,7 @@ var EditorToolbar = ({ editor, variant }) => {
|
|
|
15928
19329
|
active: editor.isActive({ textAlign: "right" })
|
|
15929
19330
|
}
|
|
15930
19331
|
),
|
|
15931
|
-
/* @__PURE__ */
|
|
19332
|
+
/* @__PURE__ */ jsx72(
|
|
15932
19333
|
DropdownMenuItem,
|
|
15933
19334
|
{
|
|
15934
19335
|
icon: AlignJustify,
|
|
@@ -15940,17 +19341,17 @@ var EditorToolbar = ({ editor, variant }) => {
|
|
|
15940
19341
|
]
|
|
15941
19342
|
}
|
|
15942
19343
|
),
|
|
15943
|
-
/* @__PURE__ */
|
|
15944
|
-
/* @__PURE__ */
|
|
19344
|
+
/* @__PURE__ */ jsx72(ToolbarDivider, {}),
|
|
19345
|
+
/* @__PURE__ */ jsxs64(
|
|
15945
19346
|
DropdownMenu,
|
|
15946
19347
|
{
|
|
15947
|
-
trigger: /* @__PURE__ */
|
|
19348
|
+
trigger: /* @__PURE__ */ jsxs64(ToolbarButton, { onClick: () => {
|
|
15948
19349
|
}, title: t("toolbar.bulletList"), children: [
|
|
15949
|
-
/* @__PURE__ */
|
|
15950
|
-
/* @__PURE__ */
|
|
19350
|
+
/* @__PURE__ */ jsx72(ListIcon, { className: "w-4 h-4" }),
|
|
19351
|
+
/* @__PURE__ */ jsx72(ChevronDown5, { className: "w-3 h-3" })
|
|
15951
19352
|
] }),
|
|
15952
19353
|
children: [
|
|
15953
|
-
/* @__PURE__ */
|
|
19354
|
+
/* @__PURE__ */ jsx72(
|
|
15954
19355
|
DropdownMenuItem,
|
|
15955
19356
|
{
|
|
15956
19357
|
icon: ListIcon,
|
|
@@ -15960,7 +19361,7 @@ var EditorToolbar = ({ editor, variant }) => {
|
|
|
15960
19361
|
shortcut: "Ctrl+Shift+8"
|
|
15961
19362
|
}
|
|
15962
19363
|
),
|
|
15963
|
-
/* @__PURE__ */
|
|
19364
|
+
/* @__PURE__ */ jsx72(
|
|
15964
19365
|
DropdownMenuItem,
|
|
15965
19366
|
{
|
|
15966
19367
|
icon: ListOrderedIcon,
|
|
@@ -15970,7 +19371,7 @@ var EditorToolbar = ({ editor, variant }) => {
|
|
|
15970
19371
|
shortcut: "Ctrl+Shift+7"
|
|
15971
19372
|
}
|
|
15972
19373
|
),
|
|
15973
|
-
/* @__PURE__ */
|
|
19374
|
+
/* @__PURE__ */ jsx72(
|
|
15974
19375
|
DropdownMenuItem,
|
|
15975
19376
|
{
|
|
15976
19377
|
icon: ListTodo2,
|
|
@@ -15983,16 +19384,16 @@ var EditorToolbar = ({ editor, variant }) => {
|
|
|
15983
19384
|
]
|
|
15984
19385
|
}
|
|
15985
19386
|
),
|
|
15986
|
-
/* @__PURE__ */
|
|
19387
|
+
/* @__PURE__ */ jsxs64(
|
|
15987
19388
|
DropdownMenu,
|
|
15988
19389
|
{
|
|
15989
|
-
trigger: /* @__PURE__ */
|
|
19390
|
+
trigger: /* @__PURE__ */ jsxs64(ToolbarButton, { onClick: () => {
|
|
15990
19391
|
}, title: t("toolbar.quote"), children: [
|
|
15991
|
-
/* @__PURE__ */
|
|
15992
|
-
/* @__PURE__ */
|
|
19392
|
+
/* @__PURE__ */ jsx72(QuoteIcon, { className: "w-4 h-4" }),
|
|
19393
|
+
/* @__PURE__ */ jsx72(ChevronDown5, { className: "w-3 h-3" })
|
|
15993
19394
|
] }),
|
|
15994
19395
|
children: [
|
|
15995
|
-
/* @__PURE__ */
|
|
19396
|
+
/* @__PURE__ */ jsx72(
|
|
15996
19397
|
DropdownMenuItem,
|
|
15997
19398
|
{
|
|
15998
19399
|
icon: QuoteIcon,
|
|
@@ -16002,7 +19403,7 @@ var EditorToolbar = ({ editor, variant }) => {
|
|
|
16002
19403
|
shortcut: "Ctrl+Shift+B"
|
|
16003
19404
|
}
|
|
16004
19405
|
),
|
|
16005
|
-
/* @__PURE__ */
|
|
19406
|
+
/* @__PURE__ */ jsx72(
|
|
16006
19407
|
DropdownMenuItem,
|
|
16007
19408
|
{
|
|
16008
19409
|
icon: FileCode2,
|
|
@@ -16015,15 +19416,15 @@ var EditorToolbar = ({ editor, variant }) => {
|
|
|
16015
19416
|
]
|
|
16016
19417
|
}
|
|
16017
19418
|
),
|
|
16018
|
-
/* @__PURE__ */
|
|
19419
|
+
/* @__PURE__ */ jsx72(
|
|
16019
19420
|
DropdownMenu,
|
|
16020
19421
|
{
|
|
16021
|
-
trigger: /* @__PURE__ */
|
|
19422
|
+
trigger: /* @__PURE__ */ jsxs64(ToolbarButton, { onClick: () => {
|
|
16022
19423
|
}, title: t("toolbar.image"), children: [
|
|
16023
|
-
/* @__PURE__ */
|
|
16024
|
-
/* @__PURE__ */
|
|
19424
|
+
/* @__PURE__ */ jsx72(ImageIcon2, { className: "w-4 h-4" }),
|
|
19425
|
+
/* @__PURE__ */ jsx72(ChevronDown5, { className: "w-3 h-3" })
|
|
16025
19426
|
] }),
|
|
16026
|
-
children: showImageInput ? /* @__PURE__ */
|
|
19427
|
+
children: showImageInput ? /* @__PURE__ */ jsx72(
|
|
16027
19428
|
ImageInput,
|
|
16028
19429
|
{
|
|
16029
19430
|
onSubmit: (url, alt) => {
|
|
@@ -16032,21 +19433,48 @@ var EditorToolbar = ({ editor, variant }) => {
|
|
|
16032
19433
|
},
|
|
16033
19434
|
onCancel: () => setShowImageInput(false)
|
|
16034
19435
|
}
|
|
16035
|
-
) : /* @__PURE__ */
|
|
19436
|
+
) : /* @__PURE__ */ jsxs64(Fragment26, { children: [
|
|
19437
|
+
/* @__PURE__ */ jsx72(DropdownMenuItem, { icon: LinkIcon, label: t("imageInput.addFromUrl"), onClick: () => setShowImageInput(true) }),
|
|
19438
|
+
/* @__PURE__ */ jsx72(
|
|
19439
|
+
DropdownMenuItem,
|
|
19440
|
+
{
|
|
19441
|
+
icon: Upload2,
|
|
19442
|
+
label: isUploadingImage ? t("imageInput.uploading") : t("imageInput.uploadTab"),
|
|
19443
|
+
disabled: isUploadingImage,
|
|
19444
|
+
onClick: () => fileInputRef.current?.click()
|
|
19445
|
+
}
|
|
19446
|
+
),
|
|
19447
|
+
imageUploadError && /* @__PURE__ */ jsx72(DropdownMenuItem, { label: imageUploadError, disabled: true, destructive: true }),
|
|
19448
|
+
/* @__PURE__ */ jsx72(
|
|
19449
|
+
"input",
|
|
19450
|
+
{
|
|
19451
|
+
ref: fileInputRef,
|
|
19452
|
+
type: "file",
|
|
19453
|
+
accept: "image/*",
|
|
19454
|
+
multiple: true,
|
|
19455
|
+
className: "hidden",
|
|
19456
|
+
onChange: (e) => {
|
|
19457
|
+
const files = Array.from(e.target.files ?? []);
|
|
19458
|
+
e.target.value = "";
|
|
19459
|
+
void insertImageFiles(files);
|
|
19460
|
+
}
|
|
19461
|
+
}
|
|
19462
|
+
)
|
|
19463
|
+
] })
|
|
16036
19464
|
}
|
|
16037
19465
|
),
|
|
16038
|
-
/* @__PURE__ */
|
|
19466
|
+
/* @__PURE__ */ jsxs64(
|
|
16039
19467
|
DropdownMenu,
|
|
16040
19468
|
{
|
|
16041
|
-
trigger: /* @__PURE__ */
|
|
19469
|
+
trigger: /* @__PURE__ */ jsxs64(ToolbarButton, { onClick: () => {
|
|
16042
19470
|
}, title: t("toolbar.table"), children: [
|
|
16043
|
-
/* @__PURE__ */
|
|
16044
|
-
/* @__PURE__ */
|
|
19471
|
+
/* @__PURE__ */ jsx72(TableIcon, { className: "w-4 h-4" }),
|
|
19472
|
+
/* @__PURE__ */ jsx72(ChevronDown5, { className: "w-3 h-3" })
|
|
16045
19473
|
] }),
|
|
16046
19474
|
children: [
|
|
16047
|
-
/* @__PURE__ */
|
|
16048
|
-
/* @__PURE__ */
|
|
16049
|
-
/* @__PURE__ */
|
|
19475
|
+
/* @__PURE__ */ jsx72(DropdownMenuItem, { icon: TableIcon, label: t("tableMenu.insert3x3"), onClick: () => editor.chain().focus().insertTable({ rows: 3, cols: 3, withHeaderRow: true }).run() }),
|
|
19476
|
+
/* @__PURE__ */ jsx72("div", { className: "my-1 border-t" }),
|
|
19477
|
+
/* @__PURE__ */ jsx72(
|
|
16050
19478
|
DropdownMenuItem,
|
|
16051
19479
|
{
|
|
16052
19480
|
icon: ArrowDown,
|
|
@@ -16055,7 +19483,7 @@ var EditorToolbar = ({ editor, variant }) => {
|
|
|
16055
19483
|
disabled: !editor.can().addColumnBefore()
|
|
16056
19484
|
}
|
|
16057
19485
|
),
|
|
16058
|
-
/* @__PURE__ */
|
|
19486
|
+
/* @__PURE__ */ jsx72(
|
|
16059
19487
|
DropdownMenuItem,
|
|
16060
19488
|
{
|
|
16061
19489
|
icon: ArrowDown,
|
|
@@ -16064,7 +19492,7 @@ var EditorToolbar = ({ editor, variant }) => {
|
|
|
16064
19492
|
disabled: !editor.can().addColumnAfter()
|
|
16065
19493
|
}
|
|
16066
19494
|
),
|
|
16067
|
-
/* @__PURE__ */
|
|
19495
|
+
/* @__PURE__ */ jsx72(
|
|
16068
19496
|
DropdownMenuItem,
|
|
16069
19497
|
{
|
|
16070
19498
|
icon: ArrowRight,
|
|
@@ -16073,7 +19501,7 @@ var EditorToolbar = ({ editor, variant }) => {
|
|
|
16073
19501
|
disabled: !editor.can().addRowBefore()
|
|
16074
19502
|
}
|
|
16075
19503
|
),
|
|
16076
|
-
/* @__PURE__ */
|
|
19504
|
+
/* @__PURE__ */ jsx72(
|
|
16077
19505
|
DropdownMenuItem,
|
|
16078
19506
|
{
|
|
16079
19507
|
icon: ArrowRight,
|
|
@@ -16082,8 +19510,8 @@ var EditorToolbar = ({ editor, variant }) => {
|
|
|
16082
19510
|
disabled: !editor.can().addRowAfter()
|
|
16083
19511
|
}
|
|
16084
19512
|
),
|
|
16085
|
-
/* @__PURE__ */
|
|
16086
|
-
/* @__PURE__ */
|
|
19513
|
+
/* @__PURE__ */ jsx72("div", { className: "my-1 border-t" }),
|
|
19514
|
+
/* @__PURE__ */ jsx72(
|
|
16087
19515
|
DropdownMenuItem,
|
|
16088
19516
|
{
|
|
16089
19517
|
icon: Trash2,
|
|
@@ -16092,8 +19520,8 @@ var EditorToolbar = ({ editor, variant }) => {
|
|
|
16092
19520
|
disabled: !editor.can().deleteColumn()
|
|
16093
19521
|
}
|
|
16094
19522
|
),
|
|
16095
|
-
/* @__PURE__ */
|
|
16096
|
-
/* @__PURE__ */
|
|
19523
|
+
/* @__PURE__ */ jsx72(DropdownMenuItem, { icon: Trash2, label: t("tableMenu.deleteRow"), onClick: () => editor.chain().focus().deleteRow().run(), disabled: !editor.can().deleteRow() }),
|
|
19524
|
+
/* @__PURE__ */ jsx72(
|
|
16097
19525
|
DropdownMenuItem,
|
|
16098
19526
|
{
|
|
16099
19527
|
icon: Trash2,
|
|
@@ -16105,17 +19533,17 @@ var EditorToolbar = ({ editor, variant }) => {
|
|
|
16105
19533
|
]
|
|
16106
19534
|
}
|
|
16107
19535
|
),
|
|
16108
|
-
/* @__PURE__ */
|
|
16109
|
-
/* @__PURE__ */
|
|
16110
|
-
/* @__PURE__ */
|
|
16111
|
-
/* @__PURE__ */
|
|
16112
|
-
/* @__PURE__ */
|
|
16113
|
-
/* @__PURE__ */
|
|
19536
|
+
/* @__PURE__ */ jsx72(ToolbarDivider, {}),
|
|
19537
|
+
/* @__PURE__ */ jsx72(ToolbarButton, { onClick: () => editor.chain().focus().toggleSubscript().run(), active: editor.isActive("subscript"), title: t("toolbar.subscript"), children: /* @__PURE__ */ jsx72(SubscriptIcon, { className: "w-4 h-4" }) }),
|
|
19538
|
+
/* @__PURE__ */ jsx72(ToolbarButton, { onClick: () => editor.chain().focus().toggleSuperscript().run(), active: editor.isActive("superscript"), title: t("toolbar.superscript"), children: /* @__PURE__ */ jsx72(SuperscriptIcon, { className: "w-4 h-4" }) }),
|
|
19539
|
+
/* @__PURE__ */ jsx72(ToolbarDivider, {}),
|
|
19540
|
+
/* @__PURE__ */ jsx72(ToolbarButton, { onClick: () => editor.chain().focus().undo().run(), disabled: !editor.can().undo(), title: t("toolbar.undo"), children: /* @__PURE__ */ jsx72(UndoIcon, { className: "w-4 h-4" }) }),
|
|
19541
|
+
/* @__PURE__ */ jsx72(ToolbarButton, { onClick: () => editor.chain().focus().redo().run(), disabled: !editor.can().redo(), title: t("toolbar.redo"), children: /* @__PURE__ */ jsx72(RedoIcon, { className: "w-4 h-4" }) })
|
|
16114
19542
|
] });
|
|
16115
19543
|
};
|
|
16116
19544
|
|
|
16117
19545
|
// ../../components/ui/UEditor/menus.tsx
|
|
16118
|
-
import { useCallback as useCallback12, useEffect as
|
|
19546
|
+
import { useCallback as useCallback12, useEffect as useEffect27, useMemo as useMemo15, useRef as useRef25, useState as useState46 } from "react";
|
|
16119
19547
|
import { createPortal as createPortal9 } from "react-dom";
|
|
16120
19548
|
import { useTranslations as useTranslations5 } from "next-intl";
|
|
16121
19549
|
import {
|
|
@@ -16141,11 +19569,11 @@ import {
|
|
|
16141
19569
|
Underline as UnderlineIcon2,
|
|
16142
19570
|
Strikethrough as StrikethroughIcon2
|
|
16143
19571
|
} from "lucide-react";
|
|
16144
|
-
import { jsx as
|
|
19572
|
+
import { jsx as jsx73, jsxs as jsxs65 } from "react/jsx-runtime";
|
|
16145
19573
|
var SlashCommandMenu = ({ editor, onClose, filterText = "" }) => {
|
|
16146
19574
|
const t = useTranslations5("UEditor");
|
|
16147
|
-
const [selectedIndex, setSelectedIndex] =
|
|
16148
|
-
const menuRef =
|
|
19575
|
+
const [selectedIndex, setSelectedIndex] = useState46(0);
|
|
19576
|
+
const menuRef = useRef25(null);
|
|
16149
19577
|
const allCommands = useMemo15(
|
|
16150
19578
|
() => [
|
|
16151
19579
|
{
|
|
@@ -16222,10 +19650,10 @@ var SlashCommandMenu = ({ editor, onClose, filterText = "" }) => {
|
|
|
16222
19650
|
const lowerFilter = filterText.toLowerCase();
|
|
16223
19651
|
return allCommands.filter((cmd) => cmd.label.toLowerCase().includes(lowerFilter) || cmd.description.toLowerCase().includes(lowerFilter));
|
|
16224
19652
|
}, [allCommands, filterText]);
|
|
16225
|
-
|
|
19653
|
+
useEffect27(() => {
|
|
16226
19654
|
setSelectedIndex(0);
|
|
16227
19655
|
}, [filterText]);
|
|
16228
|
-
|
|
19656
|
+
useEffect27(() => {
|
|
16229
19657
|
const selectedElement = menuRef.current?.querySelector(`[data-index="${selectedIndex}"]`);
|
|
16230
19658
|
selectedElement?.scrollIntoView({ block: "nearest" });
|
|
16231
19659
|
}, [selectedIndex]);
|
|
@@ -16239,7 +19667,7 @@ var SlashCommandMenu = ({ editor, onClose, filterText = "" }) => {
|
|
|
16239
19667
|
},
|
|
16240
19668
|
[commands, onClose]
|
|
16241
19669
|
);
|
|
16242
|
-
|
|
19670
|
+
useEffect27(() => {
|
|
16243
19671
|
const handleKeyDown = (e) => {
|
|
16244
19672
|
if (commands.length === 0) return;
|
|
16245
19673
|
if (e.key === "ArrowDown") {
|
|
@@ -16260,11 +19688,11 @@ var SlashCommandMenu = ({ editor, onClose, filterText = "" }) => {
|
|
|
16260
19688
|
return () => document.removeEventListener("keydown", handleKeyDown);
|
|
16261
19689
|
}, [commands, selectedIndex, selectCommand, onClose]);
|
|
16262
19690
|
if (commands.length === 0) {
|
|
16263
|
-
return /* @__PURE__ */
|
|
19691
|
+
return /* @__PURE__ */ jsx73("div", { className: "w-72 p-4 text-center text-muted-foreground text-sm", children: t("slashCommand.noResults") });
|
|
16264
19692
|
}
|
|
16265
|
-
return /* @__PURE__ */
|
|
16266
|
-
/* @__PURE__ */
|
|
16267
|
-
/* @__PURE__ */
|
|
19693
|
+
return /* @__PURE__ */ jsxs65("div", { ref: menuRef, className: "w-72 max-h-80 overflow-y-auto", children: [
|
|
19694
|
+
/* @__PURE__ */ jsx73("div", { className: "px-3 py-2 border-b", children: /* @__PURE__ */ jsx73("span", { className: "text-xs font-semibold text-muted-foreground uppercase tracking-wider", children: t("slashCommand.basicBlocks") }) }),
|
|
19695
|
+
/* @__PURE__ */ jsx73("div", { className: "p-1", children: commands.map((cmd, index) => /* @__PURE__ */ jsxs65(
|
|
16268
19696
|
"button",
|
|
16269
19697
|
{
|
|
16270
19698
|
type: "button",
|
|
@@ -16277,19 +19705,19 @@ var SlashCommandMenu = ({ editor, onClose, filterText = "" }) => {
|
|
|
16277
19705
|
selectedIndex === index ? "bg-accent" : "hover:bg-accent/50"
|
|
16278
19706
|
),
|
|
16279
19707
|
children: [
|
|
16280
|
-
/* @__PURE__ */
|
|
19708
|
+
/* @__PURE__ */ jsx73(
|
|
16281
19709
|
"div",
|
|
16282
19710
|
{
|
|
16283
19711
|
className: cn(
|
|
16284
19712
|
"flex items-center justify-center w-10 h-10 rounded-lg mr-3 transition-colors",
|
|
16285
19713
|
selectedIndex === index ? "bg-primary/10" : "bg-muted/50 group-hover:bg-muted"
|
|
16286
19714
|
),
|
|
16287
|
-
children: /* @__PURE__ */
|
|
19715
|
+
children: /* @__PURE__ */ jsx73(cmd.icon, { className: cn("w-5 h-5", selectedIndex === index ? "text-primary" : "text-muted-foreground") })
|
|
16288
19716
|
}
|
|
16289
19717
|
),
|
|
16290
|
-
/* @__PURE__ */
|
|
16291
|
-
/* @__PURE__ */
|
|
16292
|
-
/* @__PURE__ */
|
|
19718
|
+
/* @__PURE__ */ jsxs65("div", { className: "text-left", children: [
|
|
19719
|
+
/* @__PURE__ */ jsx73("div", { className: cn("text-sm font-medium", selectedIndex === index && "text-primary"), children: cmd.label }),
|
|
19720
|
+
/* @__PURE__ */ jsx73("div", { className: "text-xs text-muted-foreground", children: cmd.description })
|
|
16293
19721
|
] })
|
|
16294
19722
|
]
|
|
16295
19723
|
},
|
|
@@ -16299,43 +19727,54 @@ var SlashCommandMenu = ({ editor, onClose, filterText = "" }) => {
|
|
|
16299
19727
|
};
|
|
16300
19728
|
var FloatingMenuContent = ({ editor }) => {
|
|
16301
19729
|
const t = useTranslations5("UEditor");
|
|
16302
|
-
const [showCommands, setShowCommands] =
|
|
19730
|
+
const [showCommands, setShowCommands] = useState46(false);
|
|
16303
19731
|
if (showCommands) {
|
|
16304
|
-
return /* @__PURE__ */
|
|
19732
|
+
return /* @__PURE__ */ jsx73(SlashCommandMenu, { editor, onClose: () => setShowCommands(false) });
|
|
16305
19733
|
}
|
|
16306
|
-
return /* @__PURE__ */
|
|
19734
|
+
return /* @__PURE__ */ jsxs65(
|
|
16307
19735
|
"button",
|
|
16308
19736
|
{
|
|
16309
19737
|
type: "button",
|
|
16310
19738
|
onClick: () => setShowCommands(true),
|
|
16311
19739
|
className: "flex items-center gap-1 px-2 py-1.5 rounded-lg hover:bg-accent transition-all group",
|
|
16312
19740
|
children: [
|
|
16313
|
-
/* @__PURE__ */
|
|
16314
|
-
/* @__PURE__ */
|
|
19741
|
+
/* @__PURE__ */ jsx73(Plus, { className: "w-4 h-4 text-muted-foreground group-hover:text-foreground" }),
|
|
19742
|
+
/* @__PURE__ */ jsx73("span", { className: "text-sm text-muted-foreground group-hover:text-foreground", children: t("floatingMenu.addBlock") })
|
|
16315
19743
|
]
|
|
16316
19744
|
}
|
|
16317
19745
|
);
|
|
16318
19746
|
};
|
|
16319
|
-
var BubbleMenuContent = ({
|
|
19747
|
+
var BubbleMenuContent = ({
|
|
19748
|
+
editor,
|
|
19749
|
+
onKeepOpenChange
|
|
19750
|
+
}) => {
|
|
16320
19751
|
const t = useTranslations5("UEditor");
|
|
16321
19752
|
const { textColors, highlightColors } = useEditorColors();
|
|
16322
|
-
const [showLinkInput, setShowLinkInput] =
|
|
16323
|
-
const [showEditorColorPalette, setShowEditorColorPalette] =
|
|
19753
|
+
const [showLinkInput, setShowLinkInput] = useState46(false);
|
|
19754
|
+
const [showEditorColorPalette, setShowEditorColorPalette] = useState46(false);
|
|
19755
|
+
useEffect27(() => {
|
|
19756
|
+
onKeepOpenChange?.(showLinkInput);
|
|
19757
|
+
}, [onKeepOpenChange, showLinkInput]);
|
|
16324
19758
|
if (showLinkInput) {
|
|
16325
|
-
return /* @__PURE__ */
|
|
19759
|
+
return /* @__PURE__ */ jsx73(
|
|
16326
19760
|
LinkInput,
|
|
16327
19761
|
{
|
|
16328
19762
|
initialUrl: editor.getAttributes("link").href || "",
|
|
16329
19763
|
onSubmit: (url) => {
|
|
16330
19764
|
editor.chain().focus().extendMarkRange("link").setLink({ href: url }).run();
|
|
19765
|
+
setShowLinkInput(false);
|
|
19766
|
+
requestAnimationFrame(() => editor.commands.focus());
|
|
16331
19767
|
},
|
|
16332
|
-
onCancel: () =>
|
|
19768
|
+
onCancel: () => {
|
|
19769
|
+
setShowLinkInput(false);
|
|
19770
|
+
requestAnimationFrame(() => editor.commands.focus());
|
|
19771
|
+
}
|
|
16333
19772
|
}
|
|
16334
19773
|
);
|
|
16335
19774
|
}
|
|
16336
19775
|
if (showEditorColorPalette) {
|
|
16337
|
-
return /* @__PURE__ */
|
|
16338
|
-
/* @__PURE__ */
|
|
19776
|
+
return /* @__PURE__ */ jsxs65("div", { className: "w-48", children: [
|
|
19777
|
+
/* @__PURE__ */ jsx73(
|
|
16339
19778
|
EditorColorPalette,
|
|
16340
19779
|
{
|
|
16341
19780
|
colors: textColors,
|
|
@@ -16350,8 +19789,8 @@ var BubbleMenuContent = ({ editor }) => {
|
|
|
16350
19789
|
label: t("colors.textColor")
|
|
16351
19790
|
}
|
|
16352
19791
|
),
|
|
16353
|
-
/* @__PURE__ */
|
|
16354
|
-
/* @__PURE__ */
|
|
19792
|
+
/* @__PURE__ */ jsx73("div", { className: "border-t my-1" }),
|
|
19793
|
+
/* @__PURE__ */ jsx73(
|
|
16355
19794
|
EditorColorPalette,
|
|
16356
19795
|
{
|
|
16357
19796
|
colors: highlightColors,
|
|
@@ -16366,7 +19805,7 @@ var BubbleMenuContent = ({ editor }) => {
|
|
|
16366
19805
|
label: t("colors.highlight")
|
|
16367
19806
|
}
|
|
16368
19807
|
),
|
|
16369
|
-
/* @__PURE__ */
|
|
19808
|
+
/* @__PURE__ */ jsx73("div", { className: "p-2 border-t", children: /* @__PURE__ */ jsx73(
|
|
16370
19809
|
"button",
|
|
16371
19810
|
{
|
|
16372
19811
|
type: "button",
|
|
@@ -16377,53 +19816,71 @@ var BubbleMenuContent = ({ editor }) => {
|
|
|
16377
19816
|
) })
|
|
16378
19817
|
] });
|
|
16379
19818
|
}
|
|
16380
|
-
return /* @__PURE__ */
|
|
16381
|
-
/* @__PURE__ */
|
|
16382
|
-
/* @__PURE__ */
|
|
16383
|
-
/* @__PURE__ */
|
|
19819
|
+
return /* @__PURE__ */ jsxs65("div", { className: "flex items-center gap-0.5 p-1", children: [
|
|
19820
|
+
/* @__PURE__ */ jsx73(ToolbarButton, { onClick: () => editor.chain().focus().toggleBold().run(), active: editor.isActive("bold"), title: t("toolbar.bold"), children: /* @__PURE__ */ jsx73(BoldIcon2, { className: "w-4 h-4" }) }),
|
|
19821
|
+
/* @__PURE__ */ jsx73(ToolbarButton, { onClick: () => editor.chain().focus().toggleItalic().run(), active: editor.isActive("italic"), title: t("toolbar.italic"), children: /* @__PURE__ */ jsx73(ItalicIcon2, { className: "w-4 h-4" }) }),
|
|
19822
|
+
/* @__PURE__ */ jsx73(
|
|
16384
19823
|
ToolbarButton,
|
|
16385
19824
|
{
|
|
16386
19825
|
onClick: () => editor.chain().focus().toggleUnderline().run(),
|
|
16387
19826
|
active: editor.isActive("underline"),
|
|
16388
19827
|
title: t("toolbar.underline"),
|
|
16389
|
-
children: /* @__PURE__ */
|
|
19828
|
+
children: /* @__PURE__ */ jsx73(UnderlineIcon2, { className: "w-4 h-4" })
|
|
16390
19829
|
}
|
|
16391
19830
|
),
|
|
16392
|
-
/* @__PURE__ */
|
|
16393
|
-
/* @__PURE__ */
|
|
16394
|
-
/* @__PURE__ */
|
|
16395
|
-
/* @__PURE__ */
|
|
16396
|
-
|
|
16397
|
-
|
|
16398
|
-
|
|
19831
|
+
/* @__PURE__ */ jsx73(ToolbarButton, { onClick: () => editor.chain().focus().toggleStrike().run(), active: editor.isActive("strike"), title: t("toolbar.strike"), children: /* @__PURE__ */ jsx73(StrikethroughIcon2, { className: "w-4 h-4" }) }),
|
|
19832
|
+
/* @__PURE__ */ jsx73(ToolbarButton, { onClick: () => editor.chain().focus().toggleCode().run(), active: editor.isActive("code"), title: t("toolbar.code"), children: /* @__PURE__ */ jsx73(CodeIcon2, { className: "w-4 h-4" }) }),
|
|
19833
|
+
/* @__PURE__ */ jsx73("div", { className: "w-px h-6 bg-border/50 mx-1" }),
|
|
19834
|
+
/* @__PURE__ */ jsx73(
|
|
19835
|
+
ToolbarButton,
|
|
19836
|
+
{
|
|
19837
|
+
onMouseDown: () => {
|
|
19838
|
+
onKeepOpenChange?.(true);
|
|
19839
|
+
},
|
|
19840
|
+
onClick: () => {
|
|
19841
|
+
setShowLinkInput(true);
|
|
19842
|
+
},
|
|
19843
|
+
active: editor.isActive("link"),
|
|
19844
|
+
title: t("toolbar.link"),
|
|
19845
|
+
children: /* @__PURE__ */ jsx73(LinkIcon2, { className: "w-4 h-4" })
|
|
19846
|
+
}
|
|
19847
|
+
),
|
|
19848
|
+
/* @__PURE__ */ jsx73(ToolbarButton, { onClick: () => setShowEditorColorPalette(true), title: t("colors.textColor"), children: /* @__PURE__ */ jsx73(Palette3, { className: "w-4 h-4" }) }),
|
|
19849
|
+
/* @__PURE__ */ jsx73("div", { className: "w-px h-6 bg-border/50 mx-1" }),
|
|
19850
|
+
/* @__PURE__ */ jsx73(
|
|
16399
19851
|
ToolbarButton,
|
|
16400
19852
|
{
|
|
16401
19853
|
onClick: () => editor.chain().focus().toggleSubscript().run(),
|
|
16402
19854
|
active: editor.isActive("subscript"),
|
|
16403
19855
|
title: t("toolbar.subscript"),
|
|
16404
|
-
children: /* @__PURE__ */
|
|
19856
|
+
children: /* @__PURE__ */ jsx73(SubscriptIcon2, { className: "w-4 h-4" })
|
|
16405
19857
|
}
|
|
16406
19858
|
),
|
|
16407
|
-
/* @__PURE__ */
|
|
19859
|
+
/* @__PURE__ */ jsx73(
|
|
16408
19860
|
ToolbarButton,
|
|
16409
19861
|
{
|
|
16410
19862
|
onClick: () => editor.chain().focus().toggleSuperscript().run(),
|
|
16411
19863
|
active: editor.isActive("superscript"),
|
|
16412
19864
|
title: t("toolbar.superscript"),
|
|
16413
|
-
children: /* @__PURE__ */
|
|
19865
|
+
children: /* @__PURE__ */ jsx73(SuperscriptIcon2, { className: "w-4 h-4" })
|
|
16414
19866
|
}
|
|
16415
19867
|
)
|
|
16416
19868
|
] });
|
|
16417
19869
|
};
|
|
16418
19870
|
var CustomBubbleMenu = ({ editor }) => {
|
|
16419
|
-
const [isVisible, setIsVisible] =
|
|
16420
|
-
const [position, setPosition] =
|
|
16421
|
-
const menuRef =
|
|
16422
|
-
|
|
19871
|
+
const [isVisible, setIsVisible] = useState46(false);
|
|
19872
|
+
const [position, setPosition] = useState46({ top: 0, left: 0 });
|
|
19873
|
+
const menuRef = useRef25(null);
|
|
19874
|
+
const keepOpenRef = useRef25(false);
|
|
19875
|
+
const setKeepOpen = useCallback12((next) => {
|
|
19876
|
+
keepOpenRef.current = next;
|
|
19877
|
+
if (next) setIsVisible(true);
|
|
19878
|
+
}, []);
|
|
19879
|
+
useEffect27(() => {
|
|
16423
19880
|
const updatePosition = () => {
|
|
16424
19881
|
const { state, view } = editor;
|
|
16425
19882
|
const { from, to, empty } = state.selection;
|
|
16426
|
-
if (empty || !view.hasFocus()) {
|
|
19883
|
+
if (!keepOpenRef.current && (empty || !view.hasFocus())) {
|
|
16427
19884
|
setIsVisible(false);
|
|
16428
19885
|
return;
|
|
16429
19886
|
}
|
|
@@ -16434,7 +19891,9 @@ var CustomBubbleMenu = ({ editor }) => {
|
|
|
16434
19891
|
setPosition({ top, left });
|
|
16435
19892
|
setIsVisible(true);
|
|
16436
19893
|
};
|
|
16437
|
-
const handleBlur = () =>
|
|
19894
|
+
const handleBlur = () => {
|
|
19895
|
+
if (!keepOpenRef.current) setIsVisible(false);
|
|
19896
|
+
};
|
|
16438
19897
|
editor.on("selectionUpdate", updatePosition);
|
|
16439
19898
|
editor.on("focus", updatePosition);
|
|
16440
19899
|
editor.on("blur", handleBlur);
|
|
@@ -16446,7 +19905,7 @@ var CustomBubbleMenu = ({ editor }) => {
|
|
|
16446
19905
|
}, [editor]);
|
|
16447
19906
|
if (!isVisible) return null;
|
|
16448
19907
|
return createPortal9(
|
|
16449
|
-
/* @__PURE__ */
|
|
19908
|
+
/* @__PURE__ */ jsx73(
|
|
16450
19909
|
"div",
|
|
16451
19910
|
{
|
|
16452
19911
|
ref: menuRef,
|
|
@@ -16457,16 +19916,22 @@ var CustomBubbleMenu = ({ editor }) => {
|
|
|
16457
19916
|
transform: "translate(-50%, -100%)"
|
|
16458
19917
|
},
|
|
16459
19918
|
onMouseDown: (e) => e.preventDefault(),
|
|
16460
|
-
children: /* @__PURE__ */
|
|
19919
|
+
children: /* @__PURE__ */ jsx73(
|
|
19920
|
+
BubbleMenuContent,
|
|
19921
|
+
{
|
|
19922
|
+
editor,
|
|
19923
|
+
onKeepOpenChange: setKeepOpen
|
|
19924
|
+
}
|
|
19925
|
+
)
|
|
16461
19926
|
}
|
|
16462
19927
|
),
|
|
16463
19928
|
document.body
|
|
16464
19929
|
);
|
|
16465
19930
|
};
|
|
16466
19931
|
var CustomFloatingMenu = ({ editor }) => {
|
|
16467
|
-
const [isVisible, setIsVisible] =
|
|
16468
|
-
const [position, setPosition] =
|
|
16469
|
-
|
|
19932
|
+
const [isVisible, setIsVisible] = useState46(false);
|
|
19933
|
+
const [position, setPosition] = useState46({ top: 0, left: 0 });
|
|
19934
|
+
useEffect27(() => {
|
|
16470
19935
|
const updatePosition = () => {
|
|
16471
19936
|
const { state, view } = editor;
|
|
16472
19937
|
const { $from, empty } = state.selection;
|
|
@@ -16493,7 +19958,7 @@ var CustomFloatingMenu = ({ editor }) => {
|
|
|
16493
19958
|
}, [editor]);
|
|
16494
19959
|
if (!isVisible) return null;
|
|
16495
19960
|
return createPortal9(
|
|
16496
|
-
/* @__PURE__ */
|
|
19961
|
+
/* @__PURE__ */ jsx73(
|
|
16497
19962
|
"div",
|
|
16498
19963
|
{
|
|
16499
19964
|
className: "fixed z-50 rounded-2xl border border-border bg-card text-card-foreground shadow-lg backdrop-blur-sm overflow-hidden animate-in fade-in-0 slide-in-from-bottom-2",
|
|
@@ -16503,7 +19968,7 @@ var CustomFloatingMenu = ({ editor }) => {
|
|
|
16503
19968
|
transform: "translate(-50%, -100%)"
|
|
16504
19969
|
},
|
|
16505
19970
|
onMouseDown: (e) => e.preventDefault(),
|
|
16506
|
-
children: /* @__PURE__ */
|
|
19971
|
+
children: /* @__PURE__ */ jsx73(FloatingMenuContent, { editor })
|
|
16507
19972
|
}
|
|
16508
19973
|
),
|
|
16509
19974
|
document.body
|
|
@@ -16512,25 +19977,25 @@ var CustomFloatingMenu = ({ editor }) => {
|
|
|
16512
19977
|
|
|
16513
19978
|
// ../../components/ui/UEditor/CharacterCount.tsx
|
|
16514
19979
|
import { useTranslations as useTranslations6 } from "next-intl";
|
|
16515
|
-
import { jsxs as
|
|
19980
|
+
import { jsxs as jsxs66 } from "react/jsx-runtime";
|
|
16516
19981
|
var CharacterCountDisplay = ({ editor, maxCharacters }) => {
|
|
16517
19982
|
const t = useTranslations6("UEditor");
|
|
16518
19983
|
const storage = editor.storage;
|
|
16519
19984
|
const characterCount = storage.characterCount?.characters?.() ?? 0;
|
|
16520
19985
|
const wordCount = storage.characterCount?.words?.() ?? 0;
|
|
16521
19986
|
const percentage = maxCharacters ? Math.round(characterCount / maxCharacters * 100) : 0;
|
|
16522
|
-
return /* @__PURE__ */
|
|
16523
|
-
/* @__PURE__ */
|
|
19987
|
+
return /* @__PURE__ */ jsxs66("div", { className: "flex items-center gap-3 px-3 py-2 text-xs text-muted-foreground border-t bg-muted/20", children: [
|
|
19988
|
+
/* @__PURE__ */ jsxs66("span", { children: [
|
|
16524
19989
|
wordCount,
|
|
16525
19990
|
" ",
|
|
16526
19991
|
t("words")
|
|
16527
19992
|
] }),
|
|
16528
|
-
/* @__PURE__ */
|
|
19993
|
+
/* @__PURE__ */ jsxs66("span", { children: [
|
|
16529
19994
|
characterCount,
|
|
16530
19995
|
" ",
|
|
16531
19996
|
t("characters")
|
|
16532
19997
|
] }),
|
|
16533
|
-
maxCharacters && /* @__PURE__ */
|
|
19998
|
+
maxCharacters && /* @__PURE__ */ jsxs66("span", { className: cn(percentage > 90 && "text-destructive", percentage > 100 && "font-bold"), children: [
|
|
16534
19999
|
characterCount,
|
|
16535
20000
|
"/",
|
|
16536
20001
|
maxCharacters
|
|
@@ -16539,12 +20004,14 @@ var CharacterCountDisplay = ({ editor, maxCharacters }) => {
|
|
|
16539
20004
|
};
|
|
16540
20005
|
|
|
16541
20006
|
// ../../components/ui/UEditor/UEditor.tsx
|
|
16542
|
-
import { jsx as
|
|
20007
|
+
import { jsx as jsx74, jsxs as jsxs67 } from "react/jsx-runtime";
|
|
16543
20008
|
var UEditor = ({
|
|
16544
20009
|
content = "",
|
|
16545
20010
|
onChange,
|
|
16546
20011
|
onHtmlChange,
|
|
16547
20012
|
onJsonChange,
|
|
20013
|
+
uploadImage,
|
|
20014
|
+
imageInsertMode = "base64",
|
|
16548
20015
|
placeholder,
|
|
16549
20016
|
className,
|
|
16550
20017
|
editable = true,
|
|
@@ -16561,8 +20028,8 @@ var UEditor = ({
|
|
|
16561
20028
|
const t = useTranslations7("UEditor");
|
|
16562
20029
|
const effectivePlaceholder = placeholder ?? t("placeholder");
|
|
16563
20030
|
const extensions = useMemo16(
|
|
16564
|
-
() => buildUEditorExtensions({ placeholder: effectivePlaceholder, maxCharacters }),
|
|
16565
|
-
[effectivePlaceholder, maxCharacters]
|
|
20031
|
+
() => buildUEditorExtensions({ placeholder: effectivePlaceholder, maxCharacters, uploadImage, imageInsertMode, editable }),
|
|
20032
|
+
[effectivePlaceholder, maxCharacters, uploadImage, imageInsertMode, editable]
|
|
16566
20033
|
);
|
|
16567
20034
|
const editor = useEditor({
|
|
16568
20035
|
immediatelyRender: false,
|
|
@@ -16578,6 +20045,19 @@ var UEditor = ({
|
|
|
16578
20045
|
event.stopPropagation();
|
|
16579
20046
|
}
|
|
16580
20047
|
return false;
|
|
20048
|
+
},
|
|
20049
|
+
click: (view, event) => {
|
|
20050
|
+
if (!(event instanceof MouseEvent)) return false;
|
|
20051
|
+
if (event.button !== 0) return false;
|
|
20052
|
+
const target = event.target;
|
|
20053
|
+
const anchor = target?.closest?.("a[href]");
|
|
20054
|
+
const href = anchor?.getAttribute("href") ?? "";
|
|
20055
|
+
if (!href) return false;
|
|
20056
|
+
if (!view.state.selection.empty) return false;
|
|
20057
|
+
event.preventDefault();
|
|
20058
|
+
event.stopPropagation();
|
|
20059
|
+
window.open(href, "_blank", "noopener,noreferrer");
|
|
20060
|
+
return true;
|
|
16581
20061
|
}
|
|
16582
20062
|
},
|
|
16583
20063
|
attributes: {
|
|
@@ -16605,6 +20085,10 @@ var UEditor = ({
|
|
|
16605
20085
|
"[&_pre]:!bg-[#1e1e1e]",
|
|
16606
20086
|
"[&_pre]:!text-[#d4d4d4]",
|
|
16607
20087
|
"[&_pre_code]:!bg-transparent",
|
|
20088
|
+
"[&_img.ProseMirror-selectednode]:ring-2",
|
|
20089
|
+
"[&_img.ProseMirror-selectednode]:ring-primary/60",
|
|
20090
|
+
"[&_img.ProseMirror-selectednode]:ring-offset-2",
|
|
20091
|
+
"[&_img.ProseMirror-selectednode]:ring-offset-background",
|
|
16608
20092
|
"[&_hr]:border-t-2",
|
|
16609
20093
|
"[&_hr]:border-primary/30",
|
|
16610
20094
|
"[&_hr]:my-8",
|
|
@@ -16652,7 +20136,7 @@ var UEditor = ({
|
|
|
16652
20136
|
onJsonChange?.(editor2.getJSON());
|
|
16653
20137
|
}
|
|
16654
20138
|
});
|
|
16655
|
-
|
|
20139
|
+
useEffect28(() => {
|
|
16656
20140
|
if (editor && content !== editor.getHTML()) {
|
|
16657
20141
|
if (editor.isEmpty && content) {
|
|
16658
20142
|
editor.commands.setContent(content);
|
|
@@ -16660,7 +20144,7 @@ var UEditor = ({
|
|
|
16660
20144
|
}
|
|
16661
20145
|
}, [content, editor]);
|
|
16662
20146
|
if (!editor) {
|
|
16663
|
-
return /* @__PURE__ */
|
|
20147
|
+
return /* @__PURE__ */ jsx74(
|
|
16664
20148
|
"div",
|
|
16665
20149
|
{
|
|
16666
20150
|
className: cn("w-full rounded-lg border bg-background flex items-center justify-center text-muted-foreground", className),
|
|
@@ -16669,7 +20153,7 @@ var UEditor = ({
|
|
|
16669
20153
|
}
|
|
16670
20154
|
);
|
|
16671
20155
|
}
|
|
16672
|
-
return /* @__PURE__ */
|
|
20156
|
+
return /* @__PURE__ */ jsxs67(
|
|
16673
20157
|
"div",
|
|
16674
20158
|
{
|
|
16675
20159
|
className: cn(
|
|
@@ -16681,10 +20165,10 @@ var UEditor = ({
|
|
|
16681
20165
|
className
|
|
16682
20166
|
),
|
|
16683
20167
|
children: [
|
|
16684
|
-
editable && showToolbar && /* @__PURE__ */
|
|
16685
|
-
editable && showBubbleMenu && /* @__PURE__ */
|
|
16686
|
-
editable && showFloatingMenu && /* @__PURE__ */
|
|
16687
|
-
/* @__PURE__ */
|
|
20168
|
+
editable && showToolbar && /* @__PURE__ */ jsx74(EditorToolbar, { editor, variant, uploadImage, imageInsertMode }),
|
|
20169
|
+
editable && showBubbleMenu && /* @__PURE__ */ jsx74(CustomBubbleMenu, { editor }),
|
|
20170
|
+
editable && showFloatingMenu && /* @__PURE__ */ jsx74(CustomFloatingMenu, { editor }),
|
|
20171
|
+
/* @__PURE__ */ jsx74(
|
|
16688
20172
|
EditorContent,
|
|
16689
20173
|
{
|
|
16690
20174
|
editor,
|
|
@@ -16695,7 +20179,7 @@ var UEditor = ({
|
|
|
16695
20179
|
}
|
|
16696
20180
|
}
|
|
16697
20181
|
),
|
|
16698
|
-
showCharacterCount && /* @__PURE__ */
|
|
20182
|
+
showCharacterCount && /* @__PURE__ */ jsx74(CharacterCountDisplay, { editor, maxCharacters })
|
|
16699
20183
|
]
|
|
16700
20184
|
}
|
|
16701
20185
|
);
|