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