wysimark-lite 0.18.0 → 0.21.2
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/README.md +40 -0
- package/dist/index.d.ts +20 -2
- package/dist/index.js +124 -241
- package/dist/index.mjs +578 -240
- package/dist/index.mjs.map +1 -1
- package/dist/metafile-esm.json +1 -1
- package/package.json +5 -7
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
1
3
|
// src/index.tsx
|
|
2
4
|
import {
|
|
3
5
|
createRef,
|
|
@@ -11,8 +13,8 @@ import { createRoot } from "react-dom/client";
|
|
|
11
13
|
// src/entry/index.tsx
|
|
12
14
|
import throttle3 from "lodash.throttle";
|
|
13
15
|
import { useCallback as useCallback16, useRef as useRef13, useState as useState12 } from "react";
|
|
14
|
-
import { Editor as
|
|
15
|
-
import { ReactEditor as
|
|
16
|
+
import { Editor as Editor64, Transforms as Transforms47 } from "slate";
|
|
17
|
+
import { ReactEditor as ReactEditor18, Slate as Slate2 } from "slate-react";
|
|
16
18
|
|
|
17
19
|
// src/convert/parse/index.ts
|
|
18
20
|
import remarkParse from "remark-parse";
|
|
@@ -1588,7 +1590,12 @@ var translations = {
|
|
|
1588
1590
|
switchToVisualEditor: "\u30D3\u30B8\u30E5\u30A2\u30EB\u30A8\u30C7\u30A3\u30BF\u306B\u5207\u308A\u66FF\u3048",
|
|
1589
1591
|
switchToRawMarkdown: "\u30DE\u30FC\u30AF\u30C0\u30A6\u30F3\u8868\u793A\u306B\u5207\u308A\u66FF\u3048",
|
|
1590
1592
|
codeBlock: "\u30B3\u30FC\u30C9\u30D6\u30ED\u30C3\u30AF",
|
|
1591
|
-
increaseQuoteDepth: "\u5F15\u7528\u3092\u91CD\u306D\u308B"
|
|
1593
|
+
increaseQuoteDepth: "\u5F15\u7528\u3092\u91CD\u306D\u308B",
|
|
1594
|
+
register: "\u767B\u9332",
|
|
1595
|
+
imageSourceUrl: "URL",
|
|
1596
|
+
imageSourceFile: "\u30D5\u30A1\u30A4\u30EB",
|
|
1597
|
+
selectFile: "\u30D5\u30A1\u30A4\u30EB\u3092\u9078\u629E",
|
|
1598
|
+
uploading: "\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u4E2D..."
|
|
1592
1599
|
},
|
|
1593
1600
|
en: {
|
|
1594
1601
|
bold: "Bold",
|
|
@@ -1628,7 +1635,12 @@ var translations = {
|
|
|
1628
1635
|
switchToVisualEditor: "Switch to visual editor",
|
|
1629
1636
|
switchToRawMarkdown: "Switch to raw markdown",
|
|
1630
1637
|
codeBlock: "Code Block",
|
|
1631
|
-
increaseQuoteDepth: "Increase Quote Depth"
|
|
1638
|
+
increaseQuoteDepth: "Increase Quote Depth",
|
|
1639
|
+
register: "Register",
|
|
1640
|
+
imageSourceUrl: "URL",
|
|
1641
|
+
imageSourceFile: "File",
|
|
1642
|
+
selectFile: "Select File",
|
|
1643
|
+
uploading: "Uploading..."
|
|
1632
1644
|
}
|
|
1633
1645
|
};
|
|
1634
1646
|
var getLanguage = () => {
|
|
@@ -1956,13 +1968,17 @@ function curryTwo(fn, arg1, arg2) {
|
|
|
1956
1968
|
}
|
|
1957
1969
|
|
|
1958
1970
|
// src/sink/utils/core-utils/is-mac.ts
|
|
1959
|
-
var IS_MAC_REGEX = /mac os x/i;
|
|
1971
|
+
var IS_MAC_REGEX = /mac os x|macintosh/i;
|
|
1960
1972
|
var isMacValue = void 0;
|
|
1961
1973
|
function isMac() {
|
|
1962
1974
|
if (isMacValue !== void 0)
|
|
1963
1975
|
return isMacValue;
|
|
1964
|
-
|
|
1965
|
-
|
|
1976
|
+
try {
|
|
1977
|
+
const { userAgent } = window.navigator;
|
|
1978
|
+
isMacValue = IS_MAC_REGEX.test(userAgent);
|
|
1979
|
+
} catch {
|
|
1980
|
+
isMacValue = false;
|
|
1981
|
+
}
|
|
1966
1982
|
return isMacValue;
|
|
1967
1983
|
}
|
|
1968
1984
|
|
|
@@ -3613,6 +3629,10 @@ var AtomicDeletePlugin = createPlugin(
|
|
|
3613
3629
|
}
|
|
3614
3630
|
);
|
|
3615
3631
|
|
|
3632
|
+
// src/image-plugin/index.tsx
|
|
3633
|
+
import { Transforms as Transforms17 } from "slate";
|
|
3634
|
+
import { ReactEditor as ReactEditor9 } from "slate-react";
|
|
3635
|
+
|
|
3616
3636
|
// src/image-plugin/methods/index.ts
|
|
3617
3637
|
import { Editor as Editor20, Transforms as Transforms12 } from "slate";
|
|
3618
3638
|
import { ReactEditor as ReactEditor3 } from "slate-react";
|
|
@@ -4565,6 +4585,47 @@ function renderElement({
|
|
|
4565
4585
|
}
|
|
4566
4586
|
|
|
4567
4587
|
// src/image-plugin/index.tsx
|
|
4588
|
+
function createOnDrop2(editor) {
|
|
4589
|
+
return (event) => {
|
|
4590
|
+
const { dataTransfer } = event;
|
|
4591
|
+
if (!dataTransfer.files || dataTransfer.files.length === 0) {
|
|
4592
|
+
return false;
|
|
4593
|
+
}
|
|
4594
|
+
const imageFiles = Array.from(dataTransfer.files).filter(
|
|
4595
|
+
(file) => file.type.startsWith("image/")
|
|
4596
|
+
);
|
|
4597
|
+
if (imageFiles.length === 0) {
|
|
4598
|
+
return false;
|
|
4599
|
+
}
|
|
4600
|
+
event.preventDefault();
|
|
4601
|
+
event.stopPropagation();
|
|
4602
|
+
const range = ReactEditor9.findEventRange(editor, event);
|
|
4603
|
+
if (range) {
|
|
4604
|
+
Transforms17.select(editor, range);
|
|
4605
|
+
}
|
|
4606
|
+
const onImageChange = editor.wysimark?.onImageChange;
|
|
4607
|
+
imageFiles.forEach(async (file) => {
|
|
4608
|
+
if (onImageChange) {
|
|
4609
|
+
try {
|
|
4610
|
+
const url = await onImageChange(file);
|
|
4611
|
+
if (url) {
|
|
4612
|
+
editor.image.insertImageFromUrl(url, file.name, "");
|
|
4613
|
+
}
|
|
4614
|
+
} catch (error) {
|
|
4615
|
+
console.error("Failed to upload image:", error);
|
|
4616
|
+
}
|
|
4617
|
+
} else {
|
|
4618
|
+
const reader = new FileReader();
|
|
4619
|
+
reader.onload = () => {
|
|
4620
|
+
const dataUrl = reader.result;
|
|
4621
|
+
editor.image.insertImageFromUrl(dataUrl, file.name, "");
|
|
4622
|
+
};
|
|
4623
|
+
reader.readAsDataURL(file);
|
|
4624
|
+
}
|
|
4625
|
+
});
|
|
4626
|
+
return true;
|
|
4627
|
+
};
|
|
4628
|
+
}
|
|
4568
4629
|
var DEFAULT_OPTIONS = {
|
|
4569
4630
|
maxInitialInlineImageSize: { width: 64, height: 64 },
|
|
4570
4631
|
maxInitialImageSize: { width: 320, height: 320 },
|
|
@@ -4647,7 +4708,8 @@ var ImagePlugin = (
|
|
|
4647
4708
|
normalizeNode: curryOne(normalizeNode2, editor)
|
|
4648
4709
|
},
|
|
4649
4710
|
editableProps: {
|
|
4650
|
-
renderElement
|
|
4711
|
+
renderElement,
|
|
4712
|
+
onDrop: createOnDrop2(editor)
|
|
4651
4713
|
}
|
|
4652
4714
|
});
|
|
4653
4715
|
}
|
|
@@ -4655,7 +4717,7 @@ var ImagePlugin = (
|
|
|
4655
4717
|
);
|
|
4656
4718
|
|
|
4657
4719
|
// src/block-quote-plugin/index.tsx
|
|
4658
|
-
import { Editor as
|
|
4720
|
+
import { Editor as Editor25, Element as Element11, Transforms as Transforms18 } from "slate";
|
|
4659
4721
|
|
|
4660
4722
|
// src/block-quote-plugin/styles.tsx
|
|
4661
4723
|
import styled22 from "@emotion/styled";
|
|
@@ -4686,25 +4748,25 @@ var BlockQuotePlugin = createPlugin(
|
|
|
4686
4748
|
editor.supportsBlockQuote = true;
|
|
4687
4749
|
editor.blockQuotePlugin = {
|
|
4688
4750
|
indent: () => {
|
|
4689
|
-
|
|
4751
|
+
Transforms18.wrapNodes(
|
|
4690
4752
|
editor,
|
|
4691
4753
|
{ type: "block-quote", children: [] },
|
|
4692
4754
|
{ match: matchBlockQuoteSafe }
|
|
4693
4755
|
);
|
|
4694
4756
|
},
|
|
4695
4757
|
outdent: () => {
|
|
4696
|
-
|
|
4758
|
+
Transforms18.liftNodes(editor, {
|
|
4697
4759
|
match: (node, path) => matchBlockQuoteSafe(node) && path.length > 1
|
|
4698
4760
|
});
|
|
4699
4761
|
},
|
|
4700
4762
|
isActive: () => {
|
|
4701
|
-
const [match] =
|
|
4763
|
+
const [match] = Editor25.nodes(editor, {
|
|
4702
4764
|
match: (n) => Element11.isElement(n) && n.type === "block-quote"
|
|
4703
4765
|
});
|
|
4704
4766
|
return !!match;
|
|
4705
4767
|
},
|
|
4706
4768
|
increaseDepth: () => {
|
|
4707
|
-
const [match] =
|
|
4769
|
+
const [match] = Editor25.nodes(editor, {
|
|
4708
4770
|
match: (n) => Element11.isElement(n) && n.type === "block-quote"
|
|
4709
4771
|
});
|
|
4710
4772
|
if (!match)
|
|
@@ -4712,15 +4774,15 @@ var BlockQuotePlugin = createPlugin(
|
|
|
4712
4774
|
if (!editor.blockQuotePlugin.canIncreaseDepth())
|
|
4713
4775
|
return;
|
|
4714
4776
|
const [, path] = match;
|
|
4715
|
-
|
|
4716
|
-
|
|
4777
|
+
Transforms18.select(editor, path);
|
|
4778
|
+
Transforms18.wrapNodes(
|
|
4717
4779
|
editor,
|
|
4718
4780
|
{ type: "block-quote", children: [] },
|
|
4719
4781
|
{ at: path, split: false }
|
|
4720
4782
|
);
|
|
4721
4783
|
},
|
|
4722
4784
|
decreaseDepth: () => {
|
|
4723
|
-
const [match] =
|
|
4785
|
+
const [match] = Editor25.nodes(editor, {
|
|
4724
4786
|
match: (n) => Element11.isElement(n) && n.type === "block-quote"
|
|
4725
4787
|
});
|
|
4726
4788
|
if (!match)
|
|
@@ -4730,7 +4792,7 @@ var BlockQuotePlugin = createPlugin(
|
|
|
4730
4792
|
const [node, path] = match;
|
|
4731
4793
|
const children = node.children;
|
|
4732
4794
|
if (children.length === 1 && Element11.isElement(children[0]) && children[0].type === "block-quote") {
|
|
4733
|
-
|
|
4795
|
+
Transforms18.unwrapNodes(editor, {
|
|
4734
4796
|
at: [...path, 0],
|
|
4735
4797
|
// Path to the nested block-quote
|
|
4736
4798
|
match: (n) => Element11.isElement(n) && n.type === "block-quote"
|
|
@@ -4738,7 +4800,7 @@ var BlockQuotePlugin = createPlugin(
|
|
|
4738
4800
|
}
|
|
4739
4801
|
},
|
|
4740
4802
|
canIncreaseDepth: () => {
|
|
4741
|
-
const [match] =
|
|
4803
|
+
const [match] = Editor25.nodes(editor, {
|
|
4742
4804
|
match: (n) => Element11.isElement(n) && n.type === "block-quote"
|
|
4743
4805
|
});
|
|
4744
4806
|
if (!match)
|
|
@@ -4753,7 +4815,7 @@ var BlockQuotePlugin = createPlugin(
|
|
|
4753
4815
|
return depth < MAX_DEPTH;
|
|
4754
4816
|
},
|
|
4755
4817
|
canDecreaseDepth: () => {
|
|
4756
|
-
const [match] =
|
|
4818
|
+
const [match] = Editor25.nodes(editor, {
|
|
4757
4819
|
match: (n) => Element11.isElement(n) && n.type === "block-quote"
|
|
4758
4820
|
});
|
|
4759
4821
|
if (!match)
|
|
@@ -4773,7 +4835,7 @@ var BlockQuotePlugin = createPlugin(
|
|
|
4773
4835
|
return false;
|
|
4774
4836
|
return normalizeSiblings(editor, [node, path], (a, b) => {
|
|
4775
4837
|
if (Element11.isElement(a[0]) && Element11.isElement(b[0]) && a[0].type === "block-quote" && b[0].type === "block-quote") {
|
|
4776
|
-
|
|
4838
|
+
Transforms18.mergeNodes(editor, { at: b[1] });
|
|
4777
4839
|
}
|
|
4778
4840
|
return true;
|
|
4779
4841
|
});
|
|
@@ -4795,7 +4857,7 @@ var BlockQuotePlugin = createPlugin(
|
|
|
4795
4857
|
);
|
|
4796
4858
|
|
|
4797
4859
|
// src/code-block-plugin/index.tsx
|
|
4798
|
-
import { Editor as
|
|
4860
|
+
import { Editor as Editor28, Element as Element15, Transforms as Transforms21 } from "slate";
|
|
4799
4861
|
|
|
4800
4862
|
// src/code-block-plugin/decorate.tsx
|
|
4801
4863
|
import Prism from "prismjs";
|
|
@@ -4866,7 +4928,7 @@ function createCodeBlock(editor, { language }) {
|
|
|
4866
4928
|
}
|
|
4867
4929
|
|
|
4868
4930
|
// src/code-block-plugin/methods/setCodeBlockLanguage.ts
|
|
4869
|
-
import { Element as Element13, Transforms as
|
|
4931
|
+
import { Element as Element13, Transforms as Transforms19 } from "slate";
|
|
4870
4932
|
function setCodeBlockLanguage(editor, language, options = {}) {
|
|
4871
4933
|
const entry = findElementUp(
|
|
4872
4934
|
editor,
|
|
@@ -4875,7 +4937,7 @@ function setCodeBlockLanguage(editor, language, options = {}) {
|
|
|
4875
4937
|
);
|
|
4876
4938
|
if (!entry)
|
|
4877
4939
|
return false;
|
|
4878
|
-
|
|
4940
|
+
Transforms19.setNodes(editor, { language }, { at: entry[1] });
|
|
4879
4941
|
return true;
|
|
4880
4942
|
}
|
|
4881
4943
|
|
|
@@ -4942,7 +5004,7 @@ var LanguageList = [
|
|
|
4942
5004
|
];
|
|
4943
5005
|
|
|
4944
5006
|
// src/code-block-plugin/normalizeNode.tsx
|
|
4945
|
-
import { Element as Element14, Node as Node7, Transforms as
|
|
5007
|
+
import { Element as Element14, Node as Node7, Transforms as Transforms20 } from "slate";
|
|
4946
5008
|
function normalizeNode3(editor, entry) {
|
|
4947
5009
|
if (!Element14.isElement(entry[0]))
|
|
4948
5010
|
return false;
|
|
@@ -4951,10 +5013,10 @@ function normalizeNode3(editor, entry) {
|
|
|
4951
5013
|
if (!Element14.isElement(child))
|
|
4952
5014
|
continue;
|
|
4953
5015
|
if (editor.isVoid(child)) {
|
|
4954
|
-
|
|
5016
|
+
Transforms20.removeNodes(editor, { at: path });
|
|
4955
5017
|
return true;
|
|
4956
5018
|
} else {
|
|
4957
|
-
|
|
5019
|
+
Transforms20.unwrapNodes(editor, { at: path });
|
|
4958
5020
|
return true;
|
|
4959
5021
|
}
|
|
4960
5022
|
}
|
|
@@ -4966,14 +5028,14 @@ function normalizeNode3(editor, entry) {
|
|
|
4966
5028
|
if (child.type === "code-block-line")
|
|
4967
5029
|
continue;
|
|
4968
5030
|
if (child.type === "code-block") {
|
|
4969
|
-
|
|
5031
|
+
Transforms20.unwrapNodes(editor, { at: path });
|
|
4970
5032
|
return true;
|
|
4971
5033
|
} else if (editor.isVoid(child)) {
|
|
4972
|
-
|
|
5034
|
+
Transforms20.removeNodes(editor, { at: path });
|
|
4973
5035
|
return true;
|
|
4974
5036
|
} else {
|
|
4975
|
-
|
|
4976
|
-
|
|
5037
|
+
Transforms20.removeNodes(editor, { at: path });
|
|
5038
|
+
Transforms20.insertNodes(editor, {
|
|
4977
5039
|
type: "code-block-line",
|
|
4978
5040
|
children: [{ text: Node7.string(child) }]
|
|
4979
5041
|
});
|
|
@@ -5152,9 +5214,9 @@ var CodeBlockPlugin = createPlugin(
|
|
|
5152
5214
|
const codeBlockEntry = findElementUp(editor, "code-block");
|
|
5153
5215
|
if (codeBlockEntry == null)
|
|
5154
5216
|
return false;
|
|
5155
|
-
const codeBlockText =
|
|
5217
|
+
const codeBlockText = Editor28.string(editor, codeBlockEntry[1]);
|
|
5156
5218
|
if (codeBlockText === "") {
|
|
5157
|
-
|
|
5219
|
+
Transforms21.removeNodes(editor, { at: codeBlockEntry[1] });
|
|
5158
5220
|
return true;
|
|
5159
5221
|
}
|
|
5160
5222
|
return false;
|
|
@@ -5189,7 +5251,7 @@ var CodeBlockPlugin = createPlugin(
|
|
|
5189
5251
|
);
|
|
5190
5252
|
if (!entry)
|
|
5191
5253
|
return false;
|
|
5192
|
-
|
|
5254
|
+
Transforms21.select(editor, entry[1]);
|
|
5193
5255
|
return true;
|
|
5194
5256
|
}
|
|
5195
5257
|
}),
|
|
@@ -5208,13 +5270,13 @@ var CodeBlockPlugin = createPlugin(
|
|
|
5208
5270
|
);
|
|
5209
5271
|
|
|
5210
5272
|
// src/collapsible-paragraph-plugin/index.tsx
|
|
5211
|
-
import { Editor as
|
|
5273
|
+
import { Editor as Editor32 } from "slate";
|
|
5212
5274
|
|
|
5213
5275
|
// src/collapsible-paragraph-plugin/normalize-node/index.ts
|
|
5214
5276
|
import { Element as Element18 } from "slate";
|
|
5215
5277
|
|
|
5216
5278
|
// src/collapsible-paragraph-plugin/normalize-node/normalize-sibling-paragraphs.ts
|
|
5217
|
-
import { Element as Element16, Transforms as
|
|
5279
|
+
import { Element as Element16, Transforms as Transforms22 } from "slate";
|
|
5218
5280
|
function isParagraph(node) {
|
|
5219
5281
|
return Element16.isElement(node) && node.type === "paragraph";
|
|
5220
5282
|
}
|
|
@@ -5223,7 +5285,7 @@ function normalizeSiblingParagraphs(editor, entry) {
|
|
|
5223
5285
|
if (!isParagraph(a[0]) || !isParagraph(b[0]))
|
|
5224
5286
|
return false;
|
|
5225
5287
|
if (a[0].__collapsible && b[0].__collapsible) {
|
|
5226
|
-
|
|
5288
|
+
Transforms22.removeNodes(editor, { at: a[1] });
|
|
5227
5289
|
return true;
|
|
5228
5290
|
}
|
|
5229
5291
|
return false;
|
|
@@ -5231,7 +5293,7 @@ function normalizeSiblingParagraphs(editor, entry) {
|
|
|
5231
5293
|
}
|
|
5232
5294
|
|
|
5233
5295
|
// src/collapsible-paragraph-plugin/normalize-node/normalize-sibling-walls.ts
|
|
5234
|
-
import { Element as Element17, Transforms as
|
|
5296
|
+
import { Element as Element17, Transforms as Transforms23 } from "slate";
|
|
5235
5297
|
function isWall(editor, node) {
|
|
5236
5298
|
if (!Element17.isElement(node))
|
|
5237
5299
|
return false;
|
|
@@ -5243,7 +5305,7 @@ function normalizeSiblingWalls(editor, entry) {
|
|
|
5243
5305
|
return normalizeSiblings(editor, entry, (a, b) => {
|
|
5244
5306
|
if (!isWall(editor, a[0]) || !isWall(editor, b[0]))
|
|
5245
5307
|
return false;
|
|
5246
|
-
|
|
5308
|
+
Transforms23.insertNodes(
|
|
5247
5309
|
editor,
|
|
5248
5310
|
{
|
|
5249
5311
|
type: "paragraph",
|
|
@@ -5342,7 +5404,7 @@ var CollapsibleParagraphPlugin = createPlugin((editor) => {
|
|
|
5342
5404
|
editor.insertBreak = () => {
|
|
5343
5405
|
const { selection } = editor;
|
|
5344
5406
|
if (selection && selection.anchor.path[0] === selection.focus.path[0]) {
|
|
5345
|
-
const text =
|
|
5407
|
+
const text = Editor32.string(editor, [selection.anchor.path[0]]);
|
|
5346
5408
|
if (text.match(/\n$/) || text.match(/\n\n/)) {
|
|
5347
5409
|
insertBreak3();
|
|
5348
5410
|
} else {
|
|
@@ -5399,25 +5461,160 @@ function addConvertElementType(editor, type) {
|
|
|
5399
5461
|
}
|
|
5400
5462
|
|
|
5401
5463
|
// src/convert-element-plugin/methods/convert-elements.ts
|
|
5402
|
-
import { Editor as
|
|
5464
|
+
import { Editor as Editor33, Element as Element20, Node as Node11, Point, Transforms as Transforms24 } from "slate";
|
|
5465
|
+
function elementContainsNewlines(element) {
|
|
5466
|
+
const text = Node11.string(element);
|
|
5467
|
+
return text.includes("\n");
|
|
5468
|
+
}
|
|
5469
|
+
function getSelectedLineIndices(editor, element, elementPath, selection) {
|
|
5470
|
+
const text = Node11.string(element);
|
|
5471
|
+
const lines = text.split("\n");
|
|
5472
|
+
const elementStart = Editor33.start(editor, elementPath);
|
|
5473
|
+
const elementEnd = Editor33.end(editor, elementPath);
|
|
5474
|
+
const start = Point.isBefore(selection.anchor, elementStart) ? elementStart : Point.isAfter(selection.anchor, elementEnd) ? elementEnd : selection.anchor;
|
|
5475
|
+
const end = Point.isBefore(selection.focus, elementStart) ? elementStart : Point.isAfter(selection.focus, elementEnd) ? elementEnd : selection.focus;
|
|
5476
|
+
const startOffset = Math.min(
|
|
5477
|
+
Editor33.string(editor, { anchor: elementStart, focus: start }).length,
|
|
5478
|
+
text.length
|
|
5479
|
+
);
|
|
5480
|
+
const endOffset = Math.min(
|
|
5481
|
+
Editor33.string(editor, { anchor: elementStart, focus: end }).length,
|
|
5482
|
+
text.length
|
|
5483
|
+
);
|
|
5484
|
+
const minOffset = Math.min(startOffset, endOffset);
|
|
5485
|
+
const maxOffset = Math.max(startOffset, endOffset);
|
|
5486
|
+
let currentOffset = 0;
|
|
5487
|
+
let startLineIndex = 0;
|
|
5488
|
+
let endLineIndex = lines.length - 1;
|
|
5489
|
+
for (let i = 0; i < lines.length; i++) {
|
|
5490
|
+
const lineEnd = currentOffset + lines[i].length;
|
|
5491
|
+
if (currentOffset <= minOffset && minOffset <= lineEnd) {
|
|
5492
|
+
startLineIndex = i;
|
|
5493
|
+
}
|
|
5494
|
+
if (currentOffset <= maxOffset && maxOffset <= lineEnd) {
|
|
5495
|
+
endLineIndex = i;
|
|
5496
|
+
break;
|
|
5497
|
+
}
|
|
5498
|
+
currentOffset = lineEnd + 1;
|
|
5499
|
+
}
|
|
5500
|
+
return { startLineIndex, endLineIndex };
|
|
5501
|
+
}
|
|
5502
|
+
function splitElementAtSelectedLines(editor, element, path, selection) {
|
|
5503
|
+
const text = Node11.string(element);
|
|
5504
|
+
if (!text.includes("\n")) {
|
|
5505
|
+
return path;
|
|
5506
|
+
}
|
|
5507
|
+
const lines = text.split("\n");
|
|
5508
|
+
if (lines.length <= 1) {
|
|
5509
|
+
return path;
|
|
5510
|
+
}
|
|
5511
|
+
const { startLineIndex, endLineIndex } = getSelectedLineIndices(
|
|
5512
|
+
editor,
|
|
5513
|
+
element,
|
|
5514
|
+
path,
|
|
5515
|
+
selection
|
|
5516
|
+
);
|
|
5517
|
+
const beforeLines = lines.slice(0, startLineIndex);
|
|
5518
|
+
const selectedLines = lines.slice(startLineIndex, endLineIndex + 1);
|
|
5519
|
+
const afterLines = lines.slice(endLineIndex + 1);
|
|
5520
|
+
if (beforeLines.length === 0 && afterLines.length === 0) {
|
|
5521
|
+
return path;
|
|
5522
|
+
}
|
|
5523
|
+
Editor33.withoutNormalizing(editor, () => {
|
|
5524
|
+
const basePath = path.slice(0, -1);
|
|
5525
|
+
const baseIndex = path[path.length - 1];
|
|
5526
|
+
if (afterLines.length > 0) {
|
|
5527
|
+
const afterText = afterLines.join("\n");
|
|
5528
|
+
const afterElement = {
|
|
5529
|
+
...element,
|
|
5530
|
+
children: [{ text: afterText }]
|
|
5531
|
+
};
|
|
5532
|
+
Transforms24.insertNodes(editor, afterElement, {
|
|
5533
|
+
at: [...basePath, baseIndex + 1]
|
|
5534
|
+
});
|
|
5535
|
+
}
|
|
5536
|
+
const childrenCount = element.children.length;
|
|
5537
|
+
for (let j = childrenCount - 1; j >= 0; j--) {
|
|
5538
|
+
Transforms24.removeNodes(editor, { at: [...path, j] });
|
|
5539
|
+
}
|
|
5540
|
+
if (beforeLines.length > 0) {
|
|
5541
|
+
Transforms24.insertNodes(
|
|
5542
|
+
editor,
|
|
5543
|
+
{ text: beforeLines.join("\n") },
|
|
5544
|
+
{ at: [...path, 0] }
|
|
5545
|
+
);
|
|
5546
|
+
const selectedText = selectedLines.join("\n");
|
|
5547
|
+
const selectedElement = {
|
|
5548
|
+
type: "paragraph",
|
|
5549
|
+
children: [{ text: selectedText }]
|
|
5550
|
+
};
|
|
5551
|
+
Transforms24.insertNodes(editor, selectedElement, {
|
|
5552
|
+
at: [...basePath, baseIndex + 1]
|
|
5553
|
+
});
|
|
5554
|
+
} else {
|
|
5555
|
+
Transforms24.insertNodes(
|
|
5556
|
+
editor,
|
|
5557
|
+
{ text: selectedLines.join("\n") },
|
|
5558
|
+
{ at: [...path, 0] }
|
|
5559
|
+
);
|
|
5560
|
+
}
|
|
5561
|
+
});
|
|
5562
|
+
if (beforeLines.length > 0) {
|
|
5563
|
+
return [...path.slice(0, -1), path[path.length - 1] + 1];
|
|
5564
|
+
}
|
|
5565
|
+
return path;
|
|
5566
|
+
}
|
|
5403
5567
|
function convertElements(editor, matchForToggle, targetElement, allowToggle) {
|
|
5568
|
+
const { selection } = editor;
|
|
5569
|
+
if (!selection)
|
|
5570
|
+
return false;
|
|
5404
5571
|
const entries = Array.from(
|
|
5405
|
-
|
|
5572
|
+
Editor33.nodes(editor, {
|
|
5406
5573
|
match: (node) => Element20.isElement(node) && editor.convertElement.isConvertibleElement(node)
|
|
5407
5574
|
})
|
|
5408
5575
|
);
|
|
5409
5576
|
if (entries.length === 0)
|
|
5410
5577
|
return false;
|
|
5411
|
-
const
|
|
5578
|
+
const allPaths = [];
|
|
5579
|
+
Editor33.withoutNormalizing(editor, () => {
|
|
5580
|
+
for (let i = entries.length - 1; i >= 0; i--) {
|
|
5581
|
+
const [element, path] = entries[i];
|
|
5582
|
+
if (elementContainsNewlines(element)) {
|
|
5583
|
+
const splitPath = splitElementAtSelectedLines(
|
|
5584
|
+
editor,
|
|
5585
|
+
element,
|
|
5586
|
+
path,
|
|
5587
|
+
selection
|
|
5588
|
+
);
|
|
5589
|
+
allPaths.unshift(splitPath);
|
|
5590
|
+
} else {
|
|
5591
|
+
allPaths.unshift(path);
|
|
5592
|
+
}
|
|
5593
|
+
}
|
|
5594
|
+
});
|
|
5595
|
+
const updatedEntries = allPaths.map((path) => {
|
|
5596
|
+
try {
|
|
5597
|
+
const node = Node11.get(editor, path);
|
|
5598
|
+
if (Element20.isElement(node)) {
|
|
5599
|
+
return [node, path];
|
|
5600
|
+
}
|
|
5601
|
+
return null;
|
|
5602
|
+
} catch {
|
|
5603
|
+
return null;
|
|
5604
|
+
}
|
|
5605
|
+
}).filter((entry) => entry !== null);
|
|
5606
|
+
if (updatedEntries.length === 0)
|
|
5607
|
+
return false;
|
|
5608
|
+
const shouldToggle = allowToggle && updatedEntries.every((entry) => matchForToggle(entry[0]));
|
|
5412
5609
|
if (shouldToggle) {
|
|
5413
|
-
|
|
5414
|
-
for (const entry of
|
|
5610
|
+
Editor33.withoutNormalizing(editor, () => {
|
|
5611
|
+
for (const entry of updatedEntries) {
|
|
5415
5612
|
rewrapElement(editor, { type: "paragraph" }, entry[1]);
|
|
5416
5613
|
}
|
|
5417
5614
|
});
|
|
5418
5615
|
} else {
|
|
5419
|
-
|
|
5420
|
-
for (const entry of
|
|
5616
|
+
Editor33.withoutNormalizing(editor, () => {
|
|
5617
|
+
for (const entry of updatedEntries) {
|
|
5421
5618
|
rewrapElement(editor, targetElement, entry[1]);
|
|
5422
5619
|
}
|
|
5423
5620
|
});
|
|
@@ -5452,32 +5649,32 @@ var ConvertElementPlugin = createPlugin((editor) => {
|
|
|
5452
5649
|
});
|
|
5453
5650
|
|
|
5454
5651
|
// src/heading-plugin/insert-break.ts
|
|
5455
|
-
import { Editor as
|
|
5652
|
+
import { Editor as Editor34, Path as Path9, Range as Range6, Transforms as Transforms25 } from "slate";
|
|
5456
5653
|
function insertBreak(editor) {
|
|
5457
5654
|
const entry = findElementUp(editor, "heading");
|
|
5458
5655
|
if (!entry)
|
|
5459
5656
|
return false;
|
|
5460
5657
|
if (!editor.selection)
|
|
5461
5658
|
return false;
|
|
5462
|
-
if (
|
|
5659
|
+
if (Range6.isExpanded(editor.selection))
|
|
5463
5660
|
return false;
|
|
5464
|
-
if (!
|
|
5661
|
+
if (!Editor34.isEnd(editor, editor.selection.anchor, entry[1]))
|
|
5465
5662
|
return false;
|
|
5466
|
-
const nextPath =
|
|
5467
|
-
|
|
5663
|
+
const nextPath = Path9.next(entry[1]);
|
|
5664
|
+
Transforms25.insertNodes(
|
|
5468
5665
|
editor,
|
|
5469
5666
|
{ type: "paragraph", children: [{ text: "" }] },
|
|
5470
5667
|
{ at: nextPath }
|
|
5471
5668
|
);
|
|
5472
|
-
|
|
5473
|
-
anchor:
|
|
5474
|
-
focus:
|
|
5669
|
+
Transforms25.select(editor, {
|
|
5670
|
+
anchor: Editor34.start(editor, nextPath),
|
|
5671
|
+
focus: Editor34.start(editor, nextPath)
|
|
5475
5672
|
});
|
|
5476
5673
|
return true;
|
|
5477
5674
|
}
|
|
5478
5675
|
|
|
5479
5676
|
// src/heading-plugin/methods/index.ts
|
|
5480
|
-
import { Editor as
|
|
5677
|
+
import { Editor as Editor35 } from "slate";
|
|
5481
5678
|
function convertHeading(editor, level, allowToggle) {
|
|
5482
5679
|
editor.convertElement.convertElements(
|
|
5483
5680
|
(element) => element.type === "heading" && element.level == level,
|
|
@@ -5486,7 +5683,7 @@ function convertHeading(editor, level, allowToggle) {
|
|
|
5486
5683
|
);
|
|
5487
5684
|
}
|
|
5488
5685
|
function isHeadingActive(editor, level) {
|
|
5489
|
-
const [match] =
|
|
5686
|
+
const [match] = Editor35.nodes(editor, {
|
|
5490
5687
|
match: (n) => {
|
|
5491
5688
|
return "type" in n && "level" in n && n.type === "heading" && n.level === level;
|
|
5492
5689
|
}
|
|
@@ -5758,7 +5955,7 @@ var InlineCodePlugin = createPlugin(
|
|
|
5758
5955
|
);
|
|
5759
5956
|
|
|
5760
5957
|
// src/list-plugin/index.tsx
|
|
5761
|
-
import { Editor as
|
|
5958
|
+
import { Editor as Editor40, Path as Path10 } from "slate";
|
|
5762
5959
|
|
|
5763
5960
|
// src/list-plugin/methods/convert-list-item.ts
|
|
5764
5961
|
function convertOrderedList(editor, allowToggle) {
|
|
@@ -5842,36 +6039,36 @@ function indent(editor) {
|
|
|
5842
6039
|
}
|
|
5843
6040
|
|
|
5844
6041
|
// src/list-plugin/methods/insert-break.ts
|
|
5845
|
-
import { Editor as
|
|
6042
|
+
import { Editor as Editor36, Transforms as Transforms26 } from "slate";
|
|
5846
6043
|
function insertBreak2(editor) {
|
|
5847
6044
|
const entry = findElementUp(editor, isListItem);
|
|
5848
6045
|
if (!entry)
|
|
5849
6046
|
return false;
|
|
5850
6047
|
const [element, path] = entry;
|
|
5851
|
-
if (
|
|
6048
|
+
if (Editor36.isEmpty(editor, element)) {
|
|
5852
6049
|
if (element.depth > 0) {
|
|
5853
|
-
|
|
6050
|
+
Transforms26.setNodes(editor, { depth: element.depth - 1 }, { at: path });
|
|
5854
6051
|
return true;
|
|
5855
6052
|
} else {
|
|
5856
6053
|
rewrapElement(editor, { type: "paragraph" }, path);
|
|
5857
6054
|
return true;
|
|
5858
6055
|
}
|
|
5859
6056
|
}
|
|
5860
|
-
|
|
6057
|
+
Transforms26.splitNodes(editor, { always: true });
|
|
5861
6058
|
const nextEntry = findElementUp(editor, isListItem);
|
|
5862
6059
|
if (!nextEntry)
|
|
5863
6060
|
return true;
|
|
5864
6061
|
if (nextEntry[0].type === "task-list-item" && nextEntry[0].checked === true) {
|
|
5865
|
-
|
|
6062
|
+
Transforms26.setNodes(editor, { checked: false }, { at: nextEntry[1] });
|
|
5866
6063
|
}
|
|
5867
6064
|
return true;
|
|
5868
6065
|
}
|
|
5869
6066
|
|
|
5870
6067
|
// src/list-plugin/methods/outdent.ts
|
|
5871
|
-
import { Editor as
|
|
6068
|
+
import { Editor as Editor37 } from "slate";
|
|
5872
6069
|
function outdent(editor) {
|
|
5873
6070
|
const entries = Array.from(
|
|
5874
|
-
|
|
6071
|
+
Editor37.nodes(editor, {
|
|
5875
6072
|
match: isListItem
|
|
5876
6073
|
})
|
|
5877
6074
|
);
|
|
@@ -5889,7 +6086,7 @@ function outdent(editor) {
|
|
|
5889
6086
|
}
|
|
5890
6087
|
|
|
5891
6088
|
// src/list-plugin/methods/toggleTaskListItem.ts
|
|
5892
|
-
import { Transforms as
|
|
6089
|
+
import { Transforms as Transforms27 } from "slate";
|
|
5893
6090
|
function toggleTaskListItem(editor, { at = editor.selection } = {}) {
|
|
5894
6091
|
const taskListItem = findElementUp(
|
|
5895
6092
|
editor,
|
|
@@ -5899,7 +6096,7 @@ function toggleTaskListItem(editor, { at = editor.selection } = {}) {
|
|
|
5899
6096
|
if (!taskListItem)
|
|
5900
6097
|
return false;
|
|
5901
6098
|
const nextChecked = !taskListItem[0].checked;
|
|
5902
|
-
|
|
6099
|
+
Transforms27.setNodes(
|
|
5903
6100
|
editor,
|
|
5904
6101
|
{ checked: nextChecked },
|
|
5905
6102
|
{ at: taskListItem[1] }
|
|
@@ -5925,7 +6122,7 @@ function createListMethods(editor) {
|
|
|
5925
6122
|
}
|
|
5926
6123
|
|
|
5927
6124
|
// src/list-plugin/normalize-node/normalize-ordered-first-at-depth.ts
|
|
5928
|
-
import { Element as Element21, Transforms as
|
|
6125
|
+
import { Element as Element21, Transforms as Transforms28 } from "slate";
|
|
5929
6126
|
var isOrderedListItem = createIsElementType([
|
|
5930
6127
|
"ordered-list-item"
|
|
5931
6128
|
]);
|
|
@@ -5938,7 +6135,7 @@ function normalizeOrderedFirstAtDepth(editor, entry) {
|
|
|
5938
6135
|
return false;
|
|
5939
6136
|
const __firstAtDepth = isOrderedListItem(a[0]) ? b[0].depth > a[0].depth : isListItem(a[0]) ? b[0].depth > a[0].depth : true;
|
|
5940
6137
|
if (b[0].__firstAtDepth !== __firstAtDepth) {
|
|
5941
|
-
|
|
6138
|
+
Transforms28.setNodes(editor, { __firstAtDepth }, { at: b[1] });
|
|
5942
6139
|
return true;
|
|
5943
6140
|
}
|
|
5944
6141
|
return false;
|
|
@@ -5956,7 +6153,7 @@ function normalizeNode5(editor, entry) {
|
|
|
5956
6153
|
// src/list-plugin/render-element/ordered-list-item.tsx
|
|
5957
6154
|
import { clsx as clsx6 } from "clsx";
|
|
5958
6155
|
import { useEffect as useEffect5 } from "react";
|
|
5959
|
-
import { ReactEditor as
|
|
6156
|
+
import { ReactEditor as ReactEditor10, useSlateStatic as useSlateStatic11 } from "slate-react";
|
|
5960
6157
|
|
|
5961
6158
|
// src/list-plugin/render-element/styles.ts
|
|
5962
6159
|
import styled28 from "@emotion/styled";
|
|
@@ -6028,7 +6225,7 @@ function OrderedListItem({
|
|
|
6028
6225
|
}) {
|
|
6029
6226
|
const editor = useSlateStatic11();
|
|
6030
6227
|
useEffect5(() => {
|
|
6031
|
-
const path =
|
|
6228
|
+
const path = ReactEditor10.findPath(editor, element);
|
|
6032
6229
|
normalizeOrderedFirstAtDepth(editor, [element, path]);
|
|
6033
6230
|
}, []);
|
|
6034
6231
|
const style = {
|
|
@@ -6179,12 +6376,12 @@ var ListPlugin = createPlugin(
|
|
|
6179
6376
|
if (!listItem)
|
|
6180
6377
|
return false;
|
|
6181
6378
|
const listItemPath = listItem[1];
|
|
6182
|
-
if (!
|
|
6379
|
+
if (!Path10.hasPrevious(listItemPath)) {
|
|
6183
6380
|
editor.collapsibleParagraph.convertParagraph();
|
|
6184
6381
|
return true;
|
|
6185
6382
|
}
|
|
6186
|
-
const prevElementPath =
|
|
6187
|
-
const prevElementEntry =
|
|
6383
|
+
const prevElementPath = Path10.previous(listItemPath);
|
|
6384
|
+
const prevElementEntry = Editor40.node(editor, prevElementPath);
|
|
6188
6385
|
if (isListItem(prevElementEntry[0]))
|
|
6189
6386
|
return false;
|
|
6190
6387
|
editor.collapsibleParagraph.convertParagraph();
|
|
@@ -6194,7 +6391,7 @@ var ListPlugin = createPlugin(
|
|
|
6194
6391
|
editableProps: {
|
|
6195
6392
|
renderElement: renderElement3,
|
|
6196
6393
|
onKeyDown(e) {
|
|
6197
|
-
if (!
|
|
6394
|
+
if (!Editor40.nodes(editor, { match: isListItem }))
|
|
6198
6395
|
return false;
|
|
6199
6396
|
return hotkeyHandler(e);
|
|
6200
6397
|
}
|
|
@@ -6205,15 +6402,15 @@ var ListPlugin = createPlugin(
|
|
|
6205
6402
|
|
|
6206
6403
|
// src/marks-plugin/index.tsx
|
|
6207
6404
|
import { clsx as clsx7 } from "clsx";
|
|
6208
|
-
import { Editor as
|
|
6405
|
+
import { Editor as Editor43, Point as Point3, Range as Range8 } from "slate";
|
|
6209
6406
|
|
|
6210
6407
|
// src/marks-plugin/methods/removeMarks.ts
|
|
6211
|
-
import { Editor as
|
|
6408
|
+
import { Editor as Editor41, Text as Text4, Transforms as Transforms29 } from "slate";
|
|
6212
6409
|
function removeMarks(editor, { at = editor.selection } = {}) {
|
|
6213
6410
|
if (at == null)
|
|
6214
6411
|
return;
|
|
6215
6412
|
const nodeEntries = [
|
|
6216
|
-
...
|
|
6413
|
+
...Editor41.nodes(editor, {
|
|
6217
6414
|
match: (n) => Text4.isText(n),
|
|
6218
6415
|
at
|
|
6219
6416
|
})
|
|
@@ -6226,7 +6423,7 @@ function removeMarks(editor, { at = editor.selection } = {}) {
|
|
|
6226
6423
|
setter[key2] = null;
|
|
6227
6424
|
}
|
|
6228
6425
|
}
|
|
6229
|
-
|
|
6426
|
+
Transforms29.setNodes(editor, setter, {
|
|
6230
6427
|
match: (n) => Text4.isText(n),
|
|
6231
6428
|
split: true,
|
|
6232
6429
|
at
|
|
@@ -6234,14 +6431,14 @@ function removeMarks(editor, { at = editor.selection } = {}) {
|
|
|
6234
6431
|
}
|
|
6235
6432
|
|
|
6236
6433
|
// src/marks-plugin/methods/toggle-mark.ts
|
|
6237
|
-
import { Editor as
|
|
6434
|
+
import { Editor as Editor42, Point as Point2, Range as Range7 } from "slate";
|
|
6238
6435
|
function toggleMark(editor, markKey, unsetKey, { at = editor.selection } = {}) {
|
|
6239
6436
|
if (at == null)
|
|
6240
6437
|
return;
|
|
6241
|
-
const point =
|
|
6242
|
-
const isAtLineEnd =
|
|
6438
|
+
const point = Range7.isRange(at) ? at.focus : at;
|
|
6439
|
+
const isAtLineEnd = Point2.isPoint(point) && (Editor42.after(editor, point) === null || Editor42.isEnd(editor, point, Editor42.end(editor, [])));
|
|
6243
6440
|
const validMarkKey = markKey;
|
|
6244
|
-
const marks =
|
|
6441
|
+
const marks = Editor42.marks(editor) || {};
|
|
6245
6442
|
const isActive = marks[validMarkKey] === true;
|
|
6246
6443
|
if (isAtLineEnd) {
|
|
6247
6444
|
if (!isActive) {
|
|
@@ -6255,12 +6452,12 @@ function toggleMark(editor, markKey, unsetKey, { at = editor.selection } = {}) {
|
|
|
6255
6452
|
}
|
|
6256
6453
|
}
|
|
6257
6454
|
if (isActive) {
|
|
6258
|
-
|
|
6455
|
+
Editor42.removeMark(editor, validMarkKey);
|
|
6259
6456
|
} else {
|
|
6260
|
-
|
|
6457
|
+
Editor42.addMark(editor, validMarkKey, true);
|
|
6261
6458
|
}
|
|
6262
6459
|
if (typeof unsetKey === "string") {
|
|
6263
|
-
|
|
6460
|
+
Editor42.removeMark(editor, unsetKey);
|
|
6264
6461
|
}
|
|
6265
6462
|
}
|
|
6266
6463
|
|
|
@@ -6328,9 +6525,9 @@ var MarksPlugin = createPlugin((editor) => {
|
|
|
6328
6525
|
editor.marksPlugin.removeMarks = () => {
|
|
6329
6526
|
removeMarks2();
|
|
6330
6527
|
if (editor.selection) {
|
|
6331
|
-
const point =
|
|
6332
|
-
if (
|
|
6333
|
-
const isAtLineEnd =
|
|
6528
|
+
const point = Range8.isRange(editor.selection) ? editor.selection.focus : editor.selection;
|
|
6529
|
+
if (Point3.isPoint(point)) {
|
|
6530
|
+
const isAtLineEnd = Editor43.after(editor, point) === null || Editor43.isEnd(editor, point, Editor43.end(editor, []));
|
|
6334
6531
|
if (isAtLineEnd) {
|
|
6335
6532
|
editor.activeMarks = {};
|
|
6336
6533
|
}
|
|
@@ -6364,11 +6561,11 @@ var MarksPlugin = createPlugin((editor) => {
|
|
|
6364
6561
|
});
|
|
6365
6562
|
|
|
6366
6563
|
// src/normalize-after-delete-plugin/index.tsx
|
|
6367
|
-
import { Editor as
|
|
6564
|
+
import { Editor as Editor44, Point as Point4 } from "slate";
|
|
6368
6565
|
function forceNormalizeNearestElement(editor) {
|
|
6369
6566
|
if (!editor.selection)
|
|
6370
6567
|
return;
|
|
6371
|
-
const entry =
|
|
6568
|
+
const entry = Editor44.parent(editor, editor.selection);
|
|
6372
6569
|
forceNormalizePath(editor, entry[1]);
|
|
6373
6570
|
}
|
|
6374
6571
|
var NormalizeAfterDeletePlugin = createPlugin((editor) => {
|
|
@@ -6379,9 +6576,9 @@ var NormalizeAfterDeletePlugin = createPlugin((editor) => {
|
|
|
6379
6576
|
deleteBackward() {
|
|
6380
6577
|
if (!editor.selection)
|
|
6381
6578
|
return false;
|
|
6382
|
-
const entry =
|
|
6383
|
-
const isStart =
|
|
6384
|
-
|
|
6579
|
+
const entry = Editor44.parent(editor, editor.selection);
|
|
6580
|
+
const isStart = Point4.equals(
|
|
6581
|
+
Editor44.start(editor, entry[1]),
|
|
6385
6582
|
editor.selection.anchor
|
|
6386
6583
|
);
|
|
6387
6584
|
if (!isStart)
|
|
@@ -6393,9 +6590,9 @@ var NormalizeAfterDeletePlugin = createPlugin((editor) => {
|
|
|
6393
6590
|
deleteForward() {
|
|
6394
6591
|
if (!editor.selection)
|
|
6395
6592
|
return false;
|
|
6396
|
-
const entry =
|
|
6397
|
-
const isEnd =
|
|
6398
|
-
|
|
6593
|
+
const entry = Editor44.parent(editor, editor.selection);
|
|
6594
|
+
const isEnd = Point4.equals(
|
|
6595
|
+
Editor44.end(editor, entry[1]),
|
|
6399
6596
|
editor.selection.anchor
|
|
6400
6597
|
);
|
|
6401
6598
|
if (!isEnd)
|
|
@@ -6413,12 +6610,12 @@ var NormalizeAfterDeletePlugin = createPlugin((editor) => {
|
|
|
6413
6610
|
import { Element as Element23 } from "slate";
|
|
6414
6611
|
|
|
6415
6612
|
// src/table-plugin/delete-fragment/index.ts
|
|
6416
|
-
import { Editor as
|
|
6613
|
+
import { Editor as Editor46, Path as Path12, Transforms as Transforms31 } from "slate";
|
|
6417
6614
|
|
|
6418
6615
|
// src/table-plugin/delete-fragment/get-reversed-delete-safe-ranges.ts
|
|
6419
|
-
import { Editor as
|
|
6616
|
+
import { Editor as Editor45, Path as Path11 } from "slate";
|
|
6420
6617
|
function getReversedDeleteSafeRanges(editor, deleteRange, protectedTypes) {
|
|
6421
|
-
const positions = [...
|
|
6618
|
+
const positions = [...Editor45.positions(editor, { at: deleteRange })];
|
|
6422
6619
|
const deleteSafeRanges = [];
|
|
6423
6620
|
let startPos, prevPos, startTdPath;
|
|
6424
6621
|
startPos = prevPos = positions[0];
|
|
@@ -6429,7 +6626,7 @@ function getReversedDeleteSafeRanges(editor, deleteRange, protectedTypes) {
|
|
|
6429
6626
|
const tdPath = findElementUpPath(editor, protectedTypes, {
|
|
6430
6627
|
at: pos
|
|
6431
6628
|
});
|
|
6432
|
-
if (startTdPath && tdPath &&
|
|
6629
|
+
if (startTdPath && tdPath && Path11.equals(startTdPath, tdPath) || startTdPath == void 0 && tdPath == void 0) {
|
|
6433
6630
|
prevPos = pos;
|
|
6434
6631
|
} else {
|
|
6435
6632
|
const range2 = { anchor: startPos, focus: prevPos };
|
|
@@ -6448,7 +6645,7 @@ function getReversedDeleteSafeRanges(editor, deleteRange, protectedTypes) {
|
|
|
6448
6645
|
function deleteFragmentWithProtectedTypes(editor, protectedTypes) {
|
|
6449
6646
|
if (editor.selection == null)
|
|
6450
6647
|
return false;
|
|
6451
|
-
const [start, end] =
|
|
6648
|
+
const [start, end] = Editor46.edges(editor, editor.selection);
|
|
6452
6649
|
const startProtectedPath = findElementUpPath(editor, protectedTypes, {
|
|
6453
6650
|
at: start
|
|
6454
6651
|
});
|
|
@@ -6458,7 +6655,7 @@ function deleteFragmentWithProtectedTypes(editor, protectedTypes) {
|
|
|
6458
6655
|
if (!startProtectedPath && !endProtectedPath) {
|
|
6459
6656
|
return false;
|
|
6460
6657
|
}
|
|
6461
|
-
if (startProtectedPath && endProtectedPath &&
|
|
6658
|
+
if (startProtectedPath && endProtectedPath && Path12.equals(startProtectedPath, endProtectedPath)) {
|
|
6462
6659
|
return false;
|
|
6463
6660
|
}
|
|
6464
6661
|
const reversedRanges = getReversedDeleteSafeRanges(
|
|
@@ -6466,17 +6663,17 @@ function deleteFragmentWithProtectedTypes(editor, protectedTypes) {
|
|
|
6466
6663
|
editor.selection,
|
|
6467
6664
|
protectedTypes
|
|
6468
6665
|
);
|
|
6469
|
-
|
|
6666
|
+
Editor46.withoutNormalizing(editor, () => {
|
|
6470
6667
|
for (const range of reversedRanges) {
|
|
6471
|
-
|
|
6668
|
+
Transforms31.delete(editor, { at: range });
|
|
6472
6669
|
}
|
|
6473
|
-
|
|
6670
|
+
Transforms31.collapse(editor, { edge: "start" });
|
|
6474
6671
|
});
|
|
6475
6672
|
return true;
|
|
6476
6673
|
}
|
|
6477
6674
|
|
|
6478
6675
|
// src/table-plugin/methods/index.ts
|
|
6479
|
-
import { Transforms as
|
|
6676
|
+
import { Transforms as Transforms39 } from "slate";
|
|
6480
6677
|
|
|
6481
6678
|
// src/table-plugin/methods/get-table-info.ts
|
|
6482
6679
|
function getTableInfo(editor, { at = editor.selection } = {}) {
|
|
@@ -6514,7 +6711,7 @@ function getTableInfo(editor, { at = editor.selection } = {}) {
|
|
|
6514
6711
|
}
|
|
6515
6712
|
|
|
6516
6713
|
// src/table-plugin/methods/insert-column.ts
|
|
6517
|
-
import { Editor as
|
|
6714
|
+
import { Editor as Editor47, Transforms as Transforms32 } from "slate";
|
|
6518
6715
|
|
|
6519
6716
|
// src/table-plugin/methods/utils.ts
|
|
6520
6717
|
function createCell(index, children = [
|
|
@@ -6536,13 +6733,13 @@ function insertColumn(editor, { offset = 0, at = editor.selection } = {}) {
|
|
|
6536
6733
|
return false;
|
|
6537
6734
|
const { tableElement, tablePath, cellIndex } = t2;
|
|
6538
6735
|
const nextCellIndex = cellIndex + offset;
|
|
6539
|
-
|
|
6736
|
+
Editor47.withoutNormalizing(editor, () => {
|
|
6540
6737
|
const { columns } = tableElement;
|
|
6541
6738
|
const nextColumns = [...columns];
|
|
6542
6739
|
nextColumns.splice(nextCellIndex, 0, columns[nextCellIndex]);
|
|
6543
|
-
|
|
6740
|
+
Transforms32.setNodes(editor, { columns: nextColumns }, { at: tablePath });
|
|
6544
6741
|
tableElement.children.forEach((rowElement, i) => {
|
|
6545
|
-
|
|
6742
|
+
Transforms32.insertNodes(editor, createCell(nextCellIndex), {
|
|
6546
6743
|
at: [...tablePath, i, nextCellIndex]
|
|
6547
6744
|
});
|
|
6548
6745
|
});
|
|
@@ -6551,7 +6748,7 @@ function insertColumn(editor, { offset = 0, at = editor.selection } = {}) {
|
|
|
6551
6748
|
}
|
|
6552
6749
|
|
|
6553
6750
|
// src/table-plugin/methods/insert-row.ts
|
|
6554
|
-
import { Transforms as
|
|
6751
|
+
import { Transforms as Transforms33 } from "slate";
|
|
6555
6752
|
function createRow(columnCount) {
|
|
6556
6753
|
return {
|
|
6557
6754
|
type: "table-row",
|
|
@@ -6563,7 +6760,7 @@ function insertRow(editor, { at = editor.selection, offset = 0 } = {}) {
|
|
|
6563
6760
|
if (!t2)
|
|
6564
6761
|
return false;
|
|
6565
6762
|
const nextRowElement = createRow(t2.tableElement.columns.length);
|
|
6566
|
-
|
|
6763
|
+
Transforms33.insertNodes(editor, nextRowElement, {
|
|
6567
6764
|
at: [...t2.tablePath, t2.rowIndex + offset]
|
|
6568
6765
|
});
|
|
6569
6766
|
return true;
|
|
@@ -6573,7 +6770,7 @@ function insertRowBelow(editor, { at } = {}) {
|
|
|
6573
6770
|
}
|
|
6574
6771
|
|
|
6575
6772
|
// src/table-plugin/methods/insert-table.ts
|
|
6576
|
-
import { Editor as
|
|
6773
|
+
import { Editor as Editor49, Element as Element22, Path as Path13, Transforms as Transforms34 } from "slate";
|
|
6577
6774
|
function createRange(size) {
|
|
6578
6775
|
return [...Array(size).keys()];
|
|
6579
6776
|
}
|
|
@@ -6606,25 +6803,25 @@ function insertRootElement2(editor, element, { at = editor.selection } = {}) {
|
|
|
6606
6803
|
);
|
|
6607
6804
|
if (entry == null) {
|
|
6608
6805
|
const selection = editor.selection;
|
|
6609
|
-
|
|
6610
|
-
|
|
6806
|
+
Editor49.withoutNormalizing(editor, () => {
|
|
6807
|
+
Transforms34.insertNodes(editor, element, { at });
|
|
6611
6808
|
if (selection) {
|
|
6612
|
-
|
|
6613
|
-
|
|
6809
|
+
Transforms34.select(editor, selection);
|
|
6810
|
+
Transforms34.move(editor);
|
|
6614
6811
|
}
|
|
6615
6812
|
});
|
|
6616
6813
|
} else {
|
|
6617
|
-
const nextPath =
|
|
6618
|
-
|
|
6619
|
-
|
|
6620
|
-
|
|
6814
|
+
const nextPath = Path13.next(entry[1]);
|
|
6815
|
+
Editor49.withoutNormalizing(editor, () => {
|
|
6816
|
+
Transforms34.insertNodes(editor, element, { at: nextPath });
|
|
6817
|
+
Transforms34.select(editor, Editor49.start(editor, nextPath));
|
|
6621
6818
|
});
|
|
6622
6819
|
}
|
|
6623
6820
|
return true;
|
|
6624
6821
|
}
|
|
6625
6822
|
|
|
6626
6823
|
// src/table-plugin/methods/navigation/select-element.ts
|
|
6627
|
-
import { Path as
|
|
6824
|
+
import { Path as Path14 } from "slate";
|
|
6628
6825
|
function selectElementBelow(editor, t2) {
|
|
6629
6826
|
const { cellIndex, rowIndex, rowCount, tablePath } = t2;
|
|
6630
6827
|
if (rowIndex < rowCount - 1) {
|
|
@@ -6632,7 +6829,7 @@ function selectElementBelow(editor, t2) {
|
|
|
6632
6829
|
return true;
|
|
6633
6830
|
}
|
|
6634
6831
|
try {
|
|
6635
|
-
selectStartOfElement(editor,
|
|
6832
|
+
selectStartOfElement(editor, Path14.next(tablePath));
|
|
6636
6833
|
return true;
|
|
6637
6834
|
} catch (e) {
|
|
6638
6835
|
return false;
|
|
@@ -6645,7 +6842,7 @@ function selectElementAbove(editor, t2) {
|
|
|
6645
6842
|
return true;
|
|
6646
6843
|
}
|
|
6647
6844
|
try {
|
|
6648
|
-
selectEndOfElement(editor,
|
|
6845
|
+
selectEndOfElement(editor, Path14.previous(tablePath));
|
|
6649
6846
|
return true;
|
|
6650
6847
|
} catch (e) {
|
|
6651
6848
|
return false;
|
|
@@ -6653,7 +6850,7 @@ function selectElementAbove(editor, t2) {
|
|
|
6653
6850
|
}
|
|
6654
6851
|
|
|
6655
6852
|
// src/table-plugin/methods/navigation/utils.ts
|
|
6656
|
-
import { ReactEditor as
|
|
6853
|
+
import { ReactEditor as ReactEditor11 } from "slate-react";
|
|
6657
6854
|
function getUnreliableSelectionRect() {
|
|
6658
6855
|
const s = window.getSelection();
|
|
6659
6856
|
if (!s)
|
|
@@ -6662,7 +6859,7 @@ function getUnreliableSelectionRect() {
|
|
|
6662
6859
|
return range.getBoundingClientRect();
|
|
6663
6860
|
}
|
|
6664
6861
|
function getElementRect(editor, element) {
|
|
6665
|
-
return
|
|
6862
|
+
return ReactEditor11.toDOMNode(editor, element).getBoundingClientRect();
|
|
6666
6863
|
}
|
|
6667
6864
|
function checkIsInElement(editor, element) {
|
|
6668
6865
|
const selectionRect = getUnreliableSelectionRect();
|
|
@@ -6697,15 +6894,15 @@ function up(editor) {
|
|
|
6697
6894
|
}
|
|
6698
6895
|
|
|
6699
6896
|
// src/table-plugin/methods/remove-column.ts
|
|
6700
|
-
import { Editor as
|
|
6897
|
+
import { Editor as Editor52, Transforms as Transforms36 } from "slate";
|
|
6701
6898
|
|
|
6702
6899
|
// src/table-plugin/methods/remove-table.ts
|
|
6703
|
-
import { Transforms as
|
|
6900
|
+
import { Transforms as Transforms35 } from "slate";
|
|
6704
6901
|
function removeTable(editor) {
|
|
6705
6902
|
const t2 = editor.tablePlugin.getTableInfo();
|
|
6706
6903
|
if (t2 === void 0)
|
|
6707
6904
|
return false;
|
|
6708
|
-
|
|
6905
|
+
Transforms35.removeNodes(editor, { at: t2.tablePath });
|
|
6709
6906
|
return true;
|
|
6710
6907
|
}
|
|
6711
6908
|
|
|
@@ -6718,26 +6915,26 @@ function removeColumn(editor, { at = editor.selection } = {}) {
|
|
|
6718
6915
|
if (cellCount === 1) {
|
|
6719
6916
|
return removeTable(editor);
|
|
6720
6917
|
}
|
|
6721
|
-
|
|
6918
|
+
Editor52.withoutNormalizing(editor, () => {
|
|
6722
6919
|
const columns = [...tableElement.columns];
|
|
6723
6920
|
columns.splice(cellIndex, 1);
|
|
6724
|
-
|
|
6921
|
+
Transforms36.setNodes(editor, { columns }, { at: tablePath });
|
|
6725
6922
|
tableElement.children.forEach((rowElement, rowIndex2) => {
|
|
6726
|
-
|
|
6923
|
+
Transforms36.removeNodes(editor, {
|
|
6727
6924
|
at: [...tablePath, rowIndex2, cellIndex]
|
|
6728
6925
|
});
|
|
6729
6926
|
});
|
|
6730
|
-
const selection =
|
|
6927
|
+
const selection = Editor52.start(editor, [
|
|
6731
6928
|
...tablePath,
|
|
6732
6929
|
rowIndex,
|
|
6733
6930
|
Math.min(cellIndex, cellCount - 2)
|
|
6734
6931
|
]);
|
|
6735
|
-
|
|
6932
|
+
Transforms36.select(editor, selection);
|
|
6736
6933
|
});
|
|
6737
6934
|
}
|
|
6738
6935
|
|
|
6739
6936
|
// src/table-plugin/methods/remove-row.ts
|
|
6740
|
-
import { Editor as
|
|
6937
|
+
import { Editor as Editor53, Transforms as Transforms37 } from "slate";
|
|
6741
6938
|
function removeRow(editor, { at = editor.selection } = {}) {
|
|
6742
6939
|
const t2 = getTableInfo(editor, { at });
|
|
6743
6940
|
if (t2 === void 0)
|
|
@@ -6746,11 +6943,11 @@ function removeRow(editor, { at = editor.selection } = {}) {
|
|
|
6746
6943
|
removeTable(editor);
|
|
6747
6944
|
return true;
|
|
6748
6945
|
}
|
|
6749
|
-
|
|
6750
|
-
|
|
6751
|
-
|
|
6946
|
+
Editor53.withoutNormalizing(editor, () => {
|
|
6947
|
+
Transforms37.removeNodes(editor, { at: t2.rowPath });
|
|
6948
|
+
Transforms37.select(
|
|
6752
6949
|
editor,
|
|
6753
|
-
|
|
6950
|
+
Editor53.start(editor, [
|
|
6754
6951
|
...t2.tablePath,
|
|
6755
6952
|
Math.min(t2.rowIndex, t2.rowCount - 2),
|
|
6756
6953
|
t2.cellIndex
|
|
@@ -6761,7 +6958,7 @@ function removeRow(editor, { at = editor.selection } = {}) {
|
|
|
6761
6958
|
}
|
|
6762
6959
|
|
|
6763
6960
|
// src/table-plugin/methods/setTableColumnAlign.ts
|
|
6764
|
-
import { Transforms as
|
|
6961
|
+
import { Transforms as Transforms38 } from "slate";
|
|
6765
6962
|
function setTableColumnAlign(editor, options) {
|
|
6766
6963
|
const t2 = getTableInfo(editor);
|
|
6767
6964
|
if (t2 === void 0)
|
|
@@ -6769,7 +6966,7 @@ function setTableColumnAlign(editor, options) {
|
|
|
6769
6966
|
const { tableElement, tablePath, cellIndex } = t2;
|
|
6770
6967
|
const nextColumns = tableElement.columns.slice();
|
|
6771
6968
|
nextColumns.splice(cellIndex, 1, { align: options.align });
|
|
6772
|
-
|
|
6969
|
+
Transforms38.setNodes(editor, { columns: nextColumns }, { at: tablePath });
|
|
6773
6970
|
return true;
|
|
6774
6971
|
}
|
|
6775
6972
|
|
|
@@ -6829,12 +7026,12 @@ function selectCell(editor, { at = editor.selection } = {}) {
|
|
|
6829
7026
|
if (t2 === void 0)
|
|
6830
7027
|
return false;
|
|
6831
7028
|
const { cellPath } = t2;
|
|
6832
|
-
|
|
7029
|
+
Transforms39.select(editor, cellPath);
|
|
6833
7030
|
return true;
|
|
6834
7031
|
}
|
|
6835
7032
|
|
|
6836
7033
|
// src/table-plugin/normalize/normalize-table.ts
|
|
6837
|
-
import { Transforms as
|
|
7034
|
+
import { Transforms as Transforms40 } from "slate";
|
|
6838
7035
|
function normalizeTableIndexes(editor, entry) {
|
|
6839
7036
|
let isTransformed = false;
|
|
6840
7037
|
const rowElements = entry[0].children;
|
|
@@ -6842,7 +7039,7 @@ function normalizeTableIndexes(editor, entry) {
|
|
|
6842
7039
|
const cellElements = rowElement.children;
|
|
6843
7040
|
cellElements.forEach((cellElement, x) => {
|
|
6844
7041
|
if (cellElement.x !== x || cellElement.y !== y) {
|
|
6845
|
-
|
|
7042
|
+
Transforms40.setNodes(editor, { x, y }, { at: [...entry[1], y, x] });
|
|
6846
7043
|
isTransformed = true;
|
|
6847
7044
|
}
|
|
6848
7045
|
});
|
|
@@ -6851,14 +7048,14 @@ function normalizeTableIndexes(editor, entry) {
|
|
|
6851
7048
|
}
|
|
6852
7049
|
|
|
6853
7050
|
// src/table-plugin/normalize/normalize-table-cell.ts
|
|
6854
|
-
import { Editor as
|
|
7051
|
+
import { Editor as Editor57, Transforms as Transforms41 } from "slate";
|
|
6855
7052
|
function normalizeTableCell(editor, entry) {
|
|
6856
7053
|
const [node, path] = entry;
|
|
6857
7054
|
if (node.children.length === 1 && node.children[0].type === "table-content") {
|
|
6858
7055
|
return false;
|
|
6859
7056
|
}
|
|
6860
|
-
|
|
6861
|
-
|
|
7057
|
+
Editor57.withoutNormalizing(editor, () => {
|
|
7058
|
+
Transforms41.insertNodes(
|
|
6862
7059
|
editor,
|
|
6863
7060
|
{
|
|
6864
7061
|
type: "table-content",
|
|
@@ -6867,9 +7064,9 @@ function normalizeTableCell(editor, entry) {
|
|
|
6867
7064
|
{ at: [...entry[1], 0] }
|
|
6868
7065
|
);
|
|
6869
7066
|
for (let i = node.children.length; i >= 0; i--) {
|
|
6870
|
-
|
|
7067
|
+
Transforms41.mergeNodes(editor, { at: [...path, i] });
|
|
6871
7068
|
}
|
|
6872
|
-
|
|
7069
|
+
Transforms41.delete(editor, {
|
|
6873
7070
|
at: { path: [...path, 0, 0], offset: 0 },
|
|
6874
7071
|
unit: "character"
|
|
6875
7072
|
});
|
|
@@ -6879,7 +7076,7 @@ function normalizeTableCell(editor, entry) {
|
|
|
6879
7076
|
|
|
6880
7077
|
// src/table-plugin/render-element/table.tsx
|
|
6881
7078
|
import { useEffect as useEffect6 } from "react";
|
|
6882
|
-
import { ReactEditor as
|
|
7079
|
+
import { ReactEditor as ReactEditor12, useSelected as useSelected7, useSlateStatic as useSlateStatic13 } from "slate-react";
|
|
6883
7080
|
|
|
6884
7081
|
// src/table-plugin/render-element/styles/index.ts
|
|
6885
7082
|
import styled31 from "@emotion/styled";
|
|
@@ -7086,7 +7283,7 @@ function Table({
|
|
|
7086
7283
|
const editor = useSlateStatic13();
|
|
7087
7284
|
const isSelected = useSelected7();
|
|
7088
7285
|
useEffect6(() => {
|
|
7089
|
-
const path =
|
|
7286
|
+
const path = ReactEditor12.findPath(editor, element);
|
|
7090
7287
|
normalizeTableIndexes(editor, [element, path]);
|
|
7091
7288
|
}, []);
|
|
7092
7289
|
return /* @__PURE__ */ jsx46(TableContext.Provider, { value: { isSelected }, children: /* @__PURE__ */ jsx46($Table, { ...attributes, columns: element.columns, children: /* @__PURE__ */ jsx46("tbody", { children }) }) });
|
|
@@ -7555,13 +7752,13 @@ var ThemePlugin = createPlugin((editor) => {
|
|
|
7555
7752
|
// src/toolbar-plugin/render-editable/index.tsx
|
|
7556
7753
|
import { clsx as clsx10 } from "clsx";
|
|
7557
7754
|
import { useCallback as useCallback15, useRef as useRef12 } from "react";
|
|
7558
|
-
import { Editor as
|
|
7559
|
-
import { ReactEditor as
|
|
7755
|
+
import { Editor as Editor60, Transforms as Transforms43 } from "slate";
|
|
7756
|
+
import { ReactEditor as ReactEditor16, useFocused, useSlateStatic as useSlateStatic21 } from "slate-react";
|
|
7560
7757
|
|
|
7561
7758
|
// src/toolbar-plugin/components/dialog/table-dialog.tsx
|
|
7562
7759
|
import { clsx as clsx8 } from "clsx";
|
|
7563
7760
|
import { useCallback as useCallback12, useRef as useRef7, useState as useState7 } from "react";
|
|
7564
|
-
import { ReactEditor as
|
|
7761
|
+
import { ReactEditor as ReactEditor13, useSlateStatic as useSlateStatic16 } from "slate-react";
|
|
7565
7762
|
|
|
7566
7763
|
// src/toolbar-plugin/styles/table-styles.ts
|
|
7567
7764
|
import styled33 from "@emotion/styled";
|
|
@@ -7612,7 +7809,7 @@ function TableDialog({
|
|
|
7612
7809
|
const createTable2 = useCallback12(
|
|
7613
7810
|
(x, y) => {
|
|
7614
7811
|
editor.tablePlugin.insertTable(x, y);
|
|
7615
|
-
|
|
7812
|
+
ReactEditor13.focus(editor);
|
|
7616
7813
|
close();
|
|
7617
7814
|
},
|
|
7618
7815
|
[editor]
|
|
@@ -7638,7 +7835,7 @@ function TableDialog({
|
|
|
7638
7835
|
|
|
7639
7836
|
// src/toolbar-plugin/components/toolbar/toolbar.tsx
|
|
7640
7837
|
import throttle2 from "lodash.throttle";
|
|
7641
|
-
import { useEffect as
|
|
7838
|
+
import { useEffect as useEffect8, useRef as useRef11, useState as useState10 } from "react";
|
|
7642
7839
|
import { useSlateStatic as useSlateStatic20 } from "slate-react";
|
|
7643
7840
|
|
|
7644
7841
|
// src/toolbar-plugin/icons.tsx
|
|
@@ -7674,12 +7871,6 @@ var Image = () => /* @__PURE__ */ jsxs27(TablerIcon, { children: [
|
|
|
7674
7871
|
/* @__PURE__ */ jsx57("path", { d: "m4 15 4-4a3 5 0 0 1 3 0l5 5" }),
|
|
7675
7872
|
/* @__PURE__ */ jsx57("path", { d: "m14 14 1-1a3 5 0 0 1 3 0l2 2" })
|
|
7676
7873
|
] });
|
|
7677
|
-
var PhotoUp = () => /* @__PURE__ */ jsxs27(TablerIcon, { children: [
|
|
7678
|
-
/* @__PURE__ */ jsx57("path", { stroke: "none", d: "M0 0h24v24H0z" }),
|
|
7679
|
-
/* @__PURE__ */ jsx57("path", { d: "M15 8h.01M12.5 21H6a3 3 0 0 1-3-3V6a3 3 0 0 1 3-3h12a3 3 0 0 1 3 3v6.5" }),
|
|
7680
|
-
/* @__PURE__ */ jsx57("path", { d: "m3 16 5-5c.928-.893 2.072-.893 3 0l3.5 3.5" }),
|
|
7681
|
-
/* @__PURE__ */ jsx57("path", { d: "m14 14 1-1c.679-.653 1.473-.829 2.214-.526M19 22v-6M22 19l-3-3-3 3" })
|
|
7682
|
-
] });
|
|
7683
7874
|
var Plus = () => /* @__PURE__ */ jsx57(TablerIcon, { children: /* @__PURE__ */ jsx57("path", { d: "M12 5v14M5 12h14" }) });
|
|
7684
7875
|
var Strikethrough = () => /* @__PURE__ */ jsx57(TablerIcon, { children: /* @__PURE__ */ jsx57("path", { d: "M5 12h14M16 6.5A4 2 0 0 0 12 5h-1a3.5 3.5 0 0 0 0 7h2a3.5 3.5 0 0 1 0 7h-1.5a4 2 0 0 1-4-1.5" }) });
|
|
7685
7876
|
var Underline = () => /* @__PURE__ */ jsx57(TablerIcon, { children: /* @__PURE__ */ jsx57("path", { d: "M7 5v5a5 5 0 0 0 10 0V5M5 19h14" }) });
|
|
@@ -7759,7 +7950,7 @@ var compactBlockItems = [
|
|
|
7759
7950
|
];
|
|
7760
7951
|
|
|
7761
7952
|
// src/toolbar-plugin/components/dialog/image-url-dialog.tsx
|
|
7762
|
-
import { useState as useState8, useRef as useRef8 } from "react";
|
|
7953
|
+
import { useState as useState8, useRef as useRef8, useEffect as useEffect7 } from "react";
|
|
7763
7954
|
import { useSlateStatic as useSlateStatic17 } from "slate-react";
|
|
7764
7955
|
|
|
7765
7956
|
// src/toolbar-plugin/styles/file-dialog-styles.ts
|
|
@@ -7777,9 +7968,25 @@ function ImageUrlDialog({
|
|
|
7777
7968
|
}) {
|
|
7778
7969
|
const editor = useSlateStatic17();
|
|
7779
7970
|
const ref = useRef8(void 0);
|
|
7780
|
-
const
|
|
7781
|
-
const
|
|
7782
|
-
const
|
|
7971
|
+
const fileInputRef = useRef8(null);
|
|
7972
|
+
const savedState = editor.wysimark?.imageDialogState;
|
|
7973
|
+
const hasOnImageChange = !!editor.wysimark?.onImageChange;
|
|
7974
|
+
const [url, setUrl] = useState8(savedState?.url ?? "");
|
|
7975
|
+
const [alt, setAlt] = useState8(savedState?.alt ?? "");
|
|
7976
|
+
const [title, setTitle] = useState8(savedState?.title ?? "");
|
|
7977
|
+
const [imageSource, setImageSource] = useState8(savedState?.imageSource ?? (hasOnImageChange ? "file" : "url"));
|
|
7978
|
+
const [isUploading, setIsUploading] = useState8(false);
|
|
7979
|
+
const [uploadedUrl, setUploadedUrl] = useState8(savedState?.uploadedUrl ?? "");
|
|
7980
|
+
useEffect7(() => {
|
|
7981
|
+
if (editor.wysimark) {
|
|
7982
|
+
editor.wysimark.imageDialogState = { url, alt, title, imageSource, uploadedUrl };
|
|
7983
|
+
}
|
|
7984
|
+
}, [url, alt, title, imageSource, uploadedUrl]);
|
|
7985
|
+
const clearState = () => {
|
|
7986
|
+
if (editor.wysimark) {
|
|
7987
|
+
editor.wysimark.imageDialogState = void 0;
|
|
7988
|
+
}
|
|
7989
|
+
};
|
|
7783
7990
|
const style = useAbsoluteReposition(
|
|
7784
7991
|
{ src: ref, dest },
|
|
7785
7992
|
({ src, dest: dest2 }) => {
|
|
@@ -7796,15 +8003,69 @@ function ImageUrlDialog({
|
|
|
7796
8003
|
);
|
|
7797
8004
|
function handleSubmit(e) {
|
|
7798
8005
|
e.preventDefault();
|
|
7799
|
-
|
|
8006
|
+
const finalUrl = imageSource === "file" ? uploadedUrl : url;
|
|
8007
|
+
if (finalUrl.trim() === "")
|
|
7800
8008
|
return;
|
|
7801
|
-
editor.image.insertImageFromUrl(
|
|
8009
|
+
editor.image.insertImageFromUrl(finalUrl, alt, title);
|
|
8010
|
+
clearState();
|
|
8011
|
+
close();
|
|
8012
|
+
}
|
|
8013
|
+
function handleCancel() {
|
|
8014
|
+
clearState();
|
|
7802
8015
|
close();
|
|
7803
8016
|
}
|
|
8017
|
+
async function handleFileSelect(e) {
|
|
8018
|
+
const file = e.target.files?.[0];
|
|
8019
|
+
if (!file || !editor.wysimark?.onImageChange)
|
|
8020
|
+
return;
|
|
8021
|
+
setIsUploading(true);
|
|
8022
|
+
try {
|
|
8023
|
+
const resultUrl = await editor.wysimark.onImageChange(file);
|
|
8024
|
+
setUploadedUrl(resultUrl);
|
|
8025
|
+
} catch (error) {
|
|
8026
|
+
console.error("Failed to upload image:", error);
|
|
8027
|
+
} finally {
|
|
8028
|
+
setIsUploading(false);
|
|
8029
|
+
}
|
|
8030
|
+
}
|
|
8031
|
+
function handleSelectFileClick() {
|
|
8032
|
+
fileInputRef.current?.click();
|
|
8033
|
+
}
|
|
8034
|
+
const isSubmitDisabled = imageSource === "file" ? uploadedUrl.trim() === "" || isUploading : url.trim() === "";
|
|
7804
8035
|
return /* @__PURE__ */ jsxs28(Fragment8, { children: [
|
|
7805
8036
|
/* @__PURE__ */ jsx58(CloseMask, { close }),
|
|
7806
8037
|
/* @__PURE__ */ jsx58($FileDialog, { ref, style, children: /* @__PURE__ */ jsxs28("form", { onSubmit: handleSubmit, style: { padding: "8px" }, children: [
|
|
7807
|
-
/* @__PURE__ */ jsxs28("div", { style: { marginBottom: "
|
|
8038
|
+
hasOnImageChange && /* @__PURE__ */ jsxs28("div", { style: { marginBottom: "12px" }, children: [
|
|
8039
|
+
/* @__PURE__ */ jsxs28("label", { style: { display: "inline-flex", alignItems: "center", marginRight: "16px", cursor: "pointer" }, children: [
|
|
8040
|
+
/* @__PURE__ */ jsx58(
|
|
8041
|
+
"input",
|
|
8042
|
+
{
|
|
8043
|
+
type: "radio",
|
|
8044
|
+
name: "imageSource",
|
|
8045
|
+
value: "file",
|
|
8046
|
+
checked: imageSource === "file",
|
|
8047
|
+
onChange: () => setImageSource("file"),
|
|
8048
|
+
style: { marginRight: "4px" }
|
|
8049
|
+
}
|
|
8050
|
+
),
|
|
8051
|
+
t("imageSourceFile")
|
|
8052
|
+
] }),
|
|
8053
|
+
/* @__PURE__ */ jsxs28("label", { style: { display: "inline-flex", alignItems: "center", cursor: "pointer" }, children: [
|
|
8054
|
+
/* @__PURE__ */ jsx58(
|
|
8055
|
+
"input",
|
|
8056
|
+
{
|
|
8057
|
+
type: "radio",
|
|
8058
|
+
name: "imageSource",
|
|
8059
|
+
value: "url",
|
|
8060
|
+
checked: imageSource === "url",
|
|
8061
|
+
onChange: () => setImageSource("url"),
|
|
8062
|
+
style: { marginRight: "4px" }
|
|
8063
|
+
}
|
|
8064
|
+
),
|
|
8065
|
+
t("imageSourceUrl")
|
|
8066
|
+
] })
|
|
8067
|
+
] }),
|
|
8068
|
+
imageSource === "url" ? /* @__PURE__ */ jsxs28("div", { style: { marginBottom: "8px" }, children: [
|
|
7808
8069
|
/* @__PURE__ */ jsx58("label", { style: { display: "block", marginBottom: "4px" }, children: t("imageUrlRequired") }),
|
|
7809
8070
|
/* @__PURE__ */ jsx58(
|
|
7810
8071
|
"input",
|
|
@@ -7819,10 +8080,57 @@ function ImageUrlDialog({
|
|
|
7819
8080
|
border: "1px solid #ccc",
|
|
7820
8081
|
borderRadius: "4px"
|
|
7821
8082
|
},
|
|
7822
|
-
placeholder: "https://example.com/image.jpg"
|
|
7823
|
-
required: true
|
|
8083
|
+
placeholder: "https://example.com/image.jpg"
|
|
7824
8084
|
}
|
|
7825
8085
|
)
|
|
8086
|
+
] }) : /* @__PURE__ */ jsxs28("div", { style: { marginBottom: "8px" }, children: [
|
|
8087
|
+
/* @__PURE__ */ jsx58(
|
|
8088
|
+
"input",
|
|
8089
|
+
{
|
|
8090
|
+
ref: fileInputRef,
|
|
8091
|
+
type: "file",
|
|
8092
|
+
accept: "image/*",
|
|
8093
|
+
onChange: handleFileSelect,
|
|
8094
|
+
style: { display: "none" }
|
|
8095
|
+
}
|
|
8096
|
+
),
|
|
8097
|
+
/* @__PURE__ */ jsx58(
|
|
8098
|
+
"button",
|
|
8099
|
+
{
|
|
8100
|
+
type: "button",
|
|
8101
|
+
onClick: handleSelectFileClick,
|
|
8102
|
+
disabled: isUploading,
|
|
8103
|
+
style: {
|
|
8104
|
+
padding: "8px 16px",
|
|
8105
|
+
backgroundColor: isUploading ? "#ccc" : "#f0f0f0",
|
|
8106
|
+
border: "1px solid #ccc",
|
|
8107
|
+
borderRadius: "4px",
|
|
8108
|
+
cursor: isUploading ? "not-allowed" : "pointer",
|
|
8109
|
+
marginBottom: "8px"
|
|
8110
|
+
},
|
|
8111
|
+
children: isUploading ? t("uploading") : t("selectFile")
|
|
8112
|
+
}
|
|
8113
|
+
),
|
|
8114
|
+
uploadedUrl && /* @__PURE__ */ jsxs28("div", { style: { marginTop: "8px" }, children: [
|
|
8115
|
+
/* @__PURE__ */ jsx58("label", { style: { display: "block", marginBottom: "4px" }, children: t("imageUrlRequired") }),
|
|
8116
|
+
/* @__PURE__ */ jsx58(
|
|
8117
|
+
"input",
|
|
8118
|
+
{
|
|
8119
|
+
type: "text",
|
|
8120
|
+
value: uploadedUrl,
|
|
8121
|
+
disabled: true,
|
|
8122
|
+
style: {
|
|
8123
|
+
width: "100%",
|
|
8124
|
+
padding: "6px",
|
|
8125
|
+
boxSizing: "border-box",
|
|
8126
|
+
border: "1px solid #ccc",
|
|
8127
|
+
borderRadius: "4px",
|
|
8128
|
+
backgroundColor: "#f5f5f5",
|
|
8129
|
+
color: "#666"
|
|
8130
|
+
}
|
|
8131
|
+
}
|
|
8132
|
+
)
|
|
8133
|
+
] })
|
|
7826
8134
|
] }),
|
|
7827
8135
|
/* @__PURE__ */ jsxs28("div", { style: { marginBottom: "8px" }, children: [
|
|
7828
8136
|
/* @__PURE__ */ jsx58("label", { style: { display: "block", marginBottom: "4px" }, children: t("altText") }),
|
|
@@ -7862,27 +8170,43 @@ function ImageUrlDialog({
|
|
|
7862
8170
|
}
|
|
7863
8171
|
)
|
|
7864
8172
|
] }),
|
|
7865
|
-
/* @__PURE__ */ jsxs28(
|
|
7866
|
-
|
|
7867
|
-
|
|
7868
|
-
|
|
7869
|
-
|
|
7870
|
-
|
|
7871
|
-
|
|
7872
|
-
|
|
7873
|
-
|
|
7874
|
-
|
|
7875
|
-
|
|
7876
|
-
|
|
7877
|
-
|
|
7878
|
-
|
|
7879
|
-
|
|
7880
|
-
|
|
7881
|
-
|
|
7882
|
-
t("
|
|
7883
|
-
|
|
7884
|
-
|
|
7885
|
-
|
|
8173
|
+
/* @__PURE__ */ jsxs28("div", { style: { display: "flex", gap: "8px" }, children: [
|
|
8174
|
+
/* @__PURE__ */ jsx58(
|
|
8175
|
+
"button",
|
|
8176
|
+
{
|
|
8177
|
+
type: "submit",
|
|
8178
|
+
disabled: isSubmitDisabled,
|
|
8179
|
+
style: {
|
|
8180
|
+
display: "flex",
|
|
8181
|
+
alignItems: "center",
|
|
8182
|
+
padding: "8px 16px",
|
|
8183
|
+
backgroundColor: isSubmitDisabled ? "#ccc" : "#0078d4",
|
|
8184
|
+
color: "white",
|
|
8185
|
+
border: "none",
|
|
8186
|
+
borderRadius: "4px",
|
|
8187
|
+
cursor: isSubmitDisabled ? "not-allowed" : "pointer",
|
|
8188
|
+
fontWeight: "bold"
|
|
8189
|
+
},
|
|
8190
|
+
children: t("register")
|
|
8191
|
+
}
|
|
8192
|
+
),
|
|
8193
|
+
/* @__PURE__ */ jsx58(
|
|
8194
|
+
"button",
|
|
8195
|
+
{
|
|
8196
|
+
type: "button",
|
|
8197
|
+
onClick: handleCancel,
|
|
8198
|
+
style: {
|
|
8199
|
+
padding: "8px 16px",
|
|
8200
|
+
backgroundColor: "#f0f0f0",
|
|
8201
|
+
color: "#333",
|
|
8202
|
+
border: "1px solid #ccc",
|
|
8203
|
+
borderRadius: "4px",
|
|
8204
|
+
cursor: "pointer"
|
|
8205
|
+
},
|
|
8206
|
+
children: t("cancel")
|
|
8207
|
+
}
|
|
8208
|
+
)
|
|
8209
|
+
] })
|
|
7886
8210
|
] }) })
|
|
7887
8211
|
] });
|
|
7888
8212
|
}
|
|
@@ -7894,7 +8218,7 @@ import {
|
|
|
7894
8218
|
useRef as useRef9,
|
|
7895
8219
|
useState as useState9
|
|
7896
8220
|
} from "react";
|
|
7897
|
-
import { ReactEditor as
|
|
8221
|
+
import { ReactEditor as ReactEditor14, useSlateStatic as useSlateStatic18 } from "slate-react";
|
|
7898
8222
|
|
|
7899
8223
|
// src/toolbar-plugin/styles/dialog-shared-styles.ts
|
|
7900
8224
|
import styled35 from "@emotion/styled";
|
|
@@ -7956,7 +8280,7 @@ function AnchorDialog2({
|
|
|
7956
8280
|
const [url, setUrl] = useState9("");
|
|
7957
8281
|
const insertLink2 = () => {
|
|
7958
8282
|
editor.anchor.insertLink(url, url, { select: true });
|
|
7959
|
-
|
|
8283
|
+
ReactEditor14.focus(editor);
|
|
7960
8284
|
close();
|
|
7961
8285
|
};
|
|
7962
8286
|
const onChangeInput = useCallback13(
|
|
@@ -8019,7 +8343,8 @@ var dialogItems = [
|
|
|
8019
8343
|
}
|
|
8020
8344
|
];
|
|
8021
8345
|
var expandedDialogItems = dialogItems;
|
|
8022
|
-
var compactDialogItems =
|
|
8346
|
+
var compactDialogItems = dialogItems;
|
|
8347
|
+
var smallDialogItems = [
|
|
8023
8348
|
{
|
|
8024
8349
|
icon: Plus,
|
|
8025
8350
|
title: t("insert"),
|
|
@@ -8029,9 +8354,9 @@ var compactDialogItems = [
|
|
|
8029
8354
|
];
|
|
8030
8355
|
|
|
8031
8356
|
// src/toolbar-plugin/items/mark-items.tsx
|
|
8032
|
-
import { Editor as
|
|
8357
|
+
import { Editor as Editor58 } from "slate";
|
|
8033
8358
|
function getMarks(editor) {
|
|
8034
|
-
const marks =
|
|
8359
|
+
const marks = Editor58.marks(editor);
|
|
8035
8360
|
return {
|
|
8036
8361
|
bold: marks?.bold || false,
|
|
8037
8362
|
italic: marks?.italic || false,
|
|
@@ -8119,7 +8444,7 @@ var compactListItems = [
|
|
|
8119
8444
|
];
|
|
8120
8445
|
|
|
8121
8446
|
// src/toolbar-plugin/items/quote-items.tsx
|
|
8122
|
-
import { Editor as
|
|
8447
|
+
import { Editor as Editor59, Transforms as Transforms42 } from "slate";
|
|
8123
8448
|
var quoteItemsList = [
|
|
8124
8449
|
{
|
|
8125
8450
|
icon: Quote,
|
|
@@ -8148,9 +8473,9 @@ var quoteItemsList = [
|
|
|
8148
8473
|
const codeBlockEntry = findElementUp(editor, "code-block");
|
|
8149
8474
|
if (codeBlockEntry) {
|
|
8150
8475
|
const [codeBlock, path] = codeBlockEntry;
|
|
8151
|
-
const textContent =
|
|
8152
|
-
|
|
8153
|
-
|
|
8476
|
+
const textContent = Editor59.string(editor, path);
|
|
8477
|
+
Transforms42.removeNodes(editor, { at: path });
|
|
8478
|
+
Transforms42.insertNodes(
|
|
8154
8479
|
editor,
|
|
8155
8480
|
{
|
|
8156
8481
|
type: "paragraph",
|
|
@@ -8165,9 +8490,9 @@ var quoteItemsList = [
|
|
|
8165
8490
|
return;
|
|
8166
8491
|
}
|
|
8167
8492
|
if (selection && (selection.anchor.offset !== selection.focus.offset || JSON.stringify(selection.anchor.path) !== JSON.stringify(selection.focus.path))) {
|
|
8168
|
-
const selectedText =
|
|
8169
|
-
|
|
8170
|
-
|
|
8493
|
+
const selectedText = Editor59.string(editor, selection);
|
|
8494
|
+
Transforms42.delete(editor);
|
|
8495
|
+
Transforms42.insertNodes(
|
|
8171
8496
|
editor,
|
|
8172
8497
|
{
|
|
8173
8498
|
type: "code-block",
|
|
@@ -8237,10 +8562,10 @@ var largeItems = [
|
|
|
8237
8562
|
"divider",
|
|
8238
8563
|
...expandedMarkItems,
|
|
8239
8564
|
"divider",
|
|
8240
|
-
...expandedQuoteItems,
|
|
8241
|
-
"divider",
|
|
8242
8565
|
...expandedDialogItems,
|
|
8243
8566
|
"divider",
|
|
8567
|
+
...expandedQuoteItems,
|
|
8568
|
+
"divider",
|
|
8244
8569
|
rawModeItem,
|
|
8245
8570
|
visualModeItem
|
|
8246
8571
|
];
|
|
@@ -8251,10 +8576,10 @@ var mediumItems = [
|
|
|
8251
8576
|
"divider",
|
|
8252
8577
|
...expandedMarkItems,
|
|
8253
8578
|
"divider",
|
|
8254
|
-
...expandedQuoteItems,
|
|
8255
|
-
"divider",
|
|
8256
8579
|
...compactDialogItems,
|
|
8257
8580
|
"divider",
|
|
8581
|
+
...expandedQuoteItems,
|
|
8582
|
+
"divider",
|
|
8258
8583
|
rawModeItem,
|
|
8259
8584
|
visualModeItem
|
|
8260
8585
|
];
|
|
@@ -8265,20 +8590,20 @@ var smallItems = [
|
|
|
8265
8590
|
"divider",
|
|
8266
8591
|
...compactMarkItems,
|
|
8267
8592
|
"divider",
|
|
8268
|
-
...
|
|
8593
|
+
...smallDialogItems,
|
|
8269
8594
|
"divider",
|
|
8270
|
-
...
|
|
8595
|
+
...compactQuoteItems,
|
|
8271
8596
|
"divider",
|
|
8272
8597
|
rawModeItem,
|
|
8273
8598
|
visualModeItem
|
|
8274
8599
|
];
|
|
8275
|
-
var initialItems =
|
|
8600
|
+
var initialItems = smallItems;
|
|
8276
8601
|
var itemSets = [largeItems, mediumItems, smallItems];
|
|
8277
8602
|
|
|
8278
8603
|
// src/toolbar-plugin/components/toolbar/toolbar-button.tsx
|
|
8279
8604
|
import { clsx as clsx9 } from "clsx";
|
|
8280
8605
|
import { useCallback as useCallback14, useRef as useRef10 } from "react";
|
|
8281
|
-
import { ReactEditor as
|
|
8606
|
+
import { ReactEditor as ReactEditor15, useSlate as useSlate2, useSlateStatic as useSlateStatic19 } from "slate-react";
|
|
8282
8607
|
import { jsx as jsx60, jsxs as jsxs30 } from "react/jsx-runtime";
|
|
8283
8608
|
function ToolbarButton({
|
|
8284
8609
|
item
|
|
@@ -8307,7 +8632,7 @@ function ToolbarButton({
|
|
|
8307
8632
|
const onClick = useCallback14(() => {
|
|
8308
8633
|
if (item.action) {
|
|
8309
8634
|
item.action(staticEditor);
|
|
8310
|
-
|
|
8635
|
+
ReactEditor15.focus(staticEditor);
|
|
8311
8636
|
return;
|
|
8312
8637
|
}
|
|
8313
8638
|
if (menuLayer.layer) {
|
|
@@ -8379,10 +8704,11 @@ function measureItemSetWidth(items, buttonWidth, dividerWidth) {
|
|
|
8379
8704
|
}
|
|
8380
8705
|
return width;
|
|
8381
8706
|
}
|
|
8707
|
+
var WIDTH_BUFFER_PX = 48;
|
|
8382
8708
|
function Toolbar() {
|
|
8383
8709
|
const ref = useRef11(null);
|
|
8384
8710
|
const [items, setItems] = useState10(initialItems);
|
|
8385
|
-
|
|
8711
|
+
useEffect8(() => {
|
|
8386
8712
|
const refresh = throttle2(
|
|
8387
8713
|
() => {
|
|
8388
8714
|
const toolbar = ref.current;
|
|
@@ -8395,7 +8721,7 @@ function Toolbar() {
|
|
|
8395
8721
|
widths.button,
|
|
8396
8722
|
widths.divider
|
|
8397
8723
|
);
|
|
8398
|
-
if (itemSetWidth < widths.toolbar) {
|
|
8724
|
+
if (itemSetWidth < widths.toolbar - WIDTH_BUFFER_PX) {
|
|
8399
8725
|
setItems(itemSets[i]);
|
|
8400
8726
|
return;
|
|
8401
8727
|
}
|
|
@@ -8405,9 +8731,10 @@ function Toolbar() {
|
|
|
8405
8731
|
100,
|
|
8406
8732
|
{ trailing: true }
|
|
8407
8733
|
);
|
|
8408
|
-
refresh
|
|
8734
|
+
const timeoutId = setTimeout(refresh, 0);
|
|
8409
8735
|
window.addEventListener("resize", refresh);
|
|
8410
8736
|
return () => {
|
|
8737
|
+
clearTimeout(timeoutId);
|
|
8411
8738
|
window.removeEventListener("resize", refresh);
|
|
8412
8739
|
};
|
|
8413
8740
|
}, []);
|
|
@@ -8430,8 +8757,8 @@ function renderEditable({ attributes, Editable: Editable3 }) {
|
|
|
8430
8757
|
(e) => {
|
|
8431
8758
|
if (e.target !== e.currentTarget)
|
|
8432
8759
|
return;
|
|
8433
|
-
|
|
8434
|
-
|
|
8760
|
+
Transforms43.select(editor, Editor60.end(editor, []));
|
|
8761
|
+
ReactEditor16.focus(editor);
|
|
8435
8762
|
},
|
|
8436
8763
|
[editor]
|
|
8437
8764
|
);
|
|
@@ -8480,7 +8807,7 @@ var ToolbarPlugin = createPlugin(
|
|
|
8480
8807
|
);
|
|
8481
8808
|
|
|
8482
8809
|
// src/trailing-block-plugin/index.tsx
|
|
8483
|
-
import { Editor as
|
|
8810
|
+
import { Editor as Editor61, Node as Node13, Path as Path15, Transforms as Transforms44 } from "slate";
|
|
8484
8811
|
var TrailingBlockPlugin = createPlugin(
|
|
8485
8812
|
(editor) => {
|
|
8486
8813
|
editor.allowTrailingBlock = true;
|
|
@@ -8488,19 +8815,19 @@ var TrailingBlockPlugin = createPlugin(
|
|
|
8488
8815
|
name: "trailing-block",
|
|
8489
8816
|
editor: {
|
|
8490
8817
|
normalizeNode: (entry) => {
|
|
8491
|
-
if (!
|
|
8818
|
+
if (!Editor61.isEditor(entry[0]))
|
|
8492
8819
|
return false;
|
|
8493
8820
|
const lastPath = [editor.children.length - 1];
|
|
8494
|
-
const lastElement =
|
|
8821
|
+
const lastElement = Node13.child(
|
|
8495
8822
|
editor,
|
|
8496
8823
|
editor.children.length - 1
|
|
8497
8824
|
);
|
|
8498
|
-
if (
|
|
8499
|
-
|
|
8825
|
+
if (Editor61.hasBlocks(editor, lastElement) || Editor61.isVoid(editor, lastElement)) {
|
|
8826
|
+
Transforms44.insertNodes(
|
|
8500
8827
|
editor,
|
|
8501
8828
|
{ type: "paragraph", children: [{ text: "" }] },
|
|
8502
8829
|
{
|
|
8503
|
-
at:
|
|
8830
|
+
at: Path15.next(lastPath)
|
|
8504
8831
|
}
|
|
8505
8832
|
);
|
|
8506
8833
|
}
|
|
@@ -8512,11 +8839,11 @@ var TrailingBlockPlugin = createPlugin(
|
|
|
8512
8839
|
);
|
|
8513
8840
|
|
|
8514
8841
|
// src/paste-markdown-plugin/methods/index.ts
|
|
8515
|
-
import { Transforms as
|
|
8842
|
+
import { Transforms as Transforms45 } from "slate";
|
|
8516
8843
|
function pasteMarkdown(editor, markdown) {
|
|
8517
8844
|
const escapedMarkdown = escapeUrlSlashes(markdown);
|
|
8518
8845
|
const fragment = parse(escapedMarkdown);
|
|
8519
|
-
|
|
8846
|
+
Transforms45.insertNodes(editor, fragment);
|
|
8520
8847
|
}
|
|
8521
8848
|
function createPasteMarkdownMethods(editor) {
|
|
8522
8849
|
return {
|
|
@@ -8601,7 +8928,7 @@ var { withSink, SinkEditable: SinkEditable2 } = Sink;
|
|
|
8601
8928
|
|
|
8602
8929
|
// src/entry/useEditor.tsx
|
|
8603
8930
|
import { useState as useState11 } from "react";
|
|
8604
|
-
import { createEditor, Editor as
|
|
8931
|
+
import { createEditor, Editor as Editor63, Transforms as Transforms46 } from "slate";
|
|
8605
8932
|
import { withHistory } from "slate-history";
|
|
8606
8933
|
import { withReact } from "slate-react";
|
|
8607
8934
|
function useEditor({
|
|
@@ -8637,7 +8964,7 @@ function useEditor({
|
|
|
8637
8964
|
const documentValue = parse(escapedMarkdown);
|
|
8638
8965
|
editor2.children = documentValue;
|
|
8639
8966
|
editor2.selection = null;
|
|
8640
|
-
|
|
8967
|
+
Transforms46.select(editor2, Editor63.start(editor2, [0]));
|
|
8641
8968
|
};
|
|
8642
8969
|
return nextEditor;
|
|
8643
8970
|
});
|
|
@@ -8656,7 +8983,8 @@ function Editable2({
|
|
|
8656
8983
|
throttleInMs = 1e3,
|
|
8657
8984
|
placeholder,
|
|
8658
8985
|
className,
|
|
8659
|
-
style
|
|
8986
|
+
style,
|
|
8987
|
+
onImageChange
|
|
8660
8988
|
}) {
|
|
8661
8989
|
const [isRawMode, setIsRawMode] = useState12(false);
|
|
8662
8990
|
const [rawText, setRawText] = useState12(value);
|
|
@@ -8680,17 +9008,26 @@ function Editable2({
|
|
|
8680
9008
|
),
|
|
8681
9009
|
[editor, onChange, throttleInMs]
|
|
8682
9010
|
);
|
|
8683
|
-
const onSlateChange = useCallback16(
|
|
8684
|
-
|
|
8685
|
-
|
|
8686
|
-
|
|
8687
|
-
|
|
8688
|
-
|
|
8689
|
-
|
|
9011
|
+
const onSlateChange = useCallback16(
|
|
9012
|
+
(nextValue) => {
|
|
9013
|
+
if (ignoreNextChangeRef.current) {
|
|
9014
|
+
ignoreNextChangeRef.current = false;
|
|
9015
|
+
prevValueRef.current = nextValue;
|
|
9016
|
+
return;
|
|
9017
|
+
}
|
|
9018
|
+
if (prevValueRef.current === nextValue) {
|
|
9019
|
+
return;
|
|
9020
|
+
}
|
|
9021
|
+
prevValueRef.current = nextValue;
|
|
9022
|
+
onThrottledSlateChange();
|
|
9023
|
+
},
|
|
9024
|
+
[onThrottledSlateChange]
|
|
9025
|
+
);
|
|
8690
9026
|
if (editor.wysimark.prevValue == null || initialValueRef.current == null) {
|
|
8691
9027
|
ignoreNextChangeRef.current = true;
|
|
8692
9028
|
const valueToProcess = isRawMode ? value : escapeUrlSlashes(value);
|
|
8693
9029
|
const children = parse(valueToProcess);
|
|
9030
|
+
editor.children = children;
|
|
8694
9031
|
prevValueRef.current = initialValueRef.current = children;
|
|
8695
9032
|
editor.wysimark.prevValue = {
|
|
8696
9033
|
markdown: value,
|
|
@@ -8711,13 +9048,13 @@ function Editable2({
|
|
|
8711
9048
|
const documentValue = parse(valueToProcess);
|
|
8712
9049
|
editor.children = documentValue;
|
|
8713
9050
|
editor.selection = null;
|
|
8714
|
-
|
|
9051
|
+
Transforms47.select(editor, Editor64.start(editor, [0]));
|
|
8715
9052
|
}
|
|
8716
9053
|
}
|
|
8717
9054
|
}
|
|
8718
9055
|
const onSinkeEditableMouseDown = useCallback16(() => {
|
|
8719
9056
|
if (navigator.userAgent.toLowerCase().includes("firefox")) {
|
|
8720
|
-
|
|
9057
|
+
ReactEditor18.focus(editor);
|
|
8721
9058
|
}
|
|
8722
9059
|
}, [editor]);
|
|
8723
9060
|
const onBlur = useCallback16(() => {
|
|
@@ -8746,6 +9083,7 @@ function Editable2({
|
|
|
8746
9083
|
}, [isRawMode, applyRawTextToEditor, updateRawTextFromEditor]);
|
|
8747
9084
|
editor.wysimark.isRawMode = isRawMode;
|
|
8748
9085
|
editor.wysimark.toggleRawMode = handleRawModeToggle;
|
|
9086
|
+
editor.wysimark.onImageChange = onImageChange;
|
|
8749
9087
|
return /* @__PURE__ */ jsxs32("div", { style: { position: "relative" }, children: [
|
|
8750
9088
|
isRawMode && /* @__PURE__ */ jsx64("div", { style: { position: "absolute", top: "5px", right: "25px", zIndex: 10 }, children: /* @__PURE__ */ jsx64(
|
|
8751
9089
|
"div",
|
|
@@ -8805,8 +9143,8 @@ function Editable2({
|
|
|
8805
9143
|
Slate2,
|
|
8806
9144
|
{
|
|
8807
9145
|
editor,
|
|
8808
|
-
initialValue: initialValueRef.current,
|
|
8809
|
-
|
|
9146
|
+
initialValue: initialValueRef.current ?? editor.children,
|
|
9147
|
+
onChange: onSlateChange,
|
|
8810
9148
|
children: /* @__PURE__ */ jsx64(
|
|
8811
9149
|
SinkEditable2,
|
|
8812
9150
|
{
|