@dxos/react-ui-editor 0.3.11-main.474ad53 → 0.3.11-main.47fbf79
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/lib/browser/index.mjs +34 -66
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/formatting.d.ts +2 -3
- package/dist/types/src/extensions/markdown/formatting.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/formatting.test.d.ts.map +1 -1
- package/package.json +24 -24
- package/src/components/TextEditor/MarkdownEditor.stories.tsx +1 -1
- package/src/components/Toolbar/Toolbar.stories.tsx +1 -1
- package/src/components/Toolbar/Toolbar.tsx +7 -26
- package/src/extensions/markdown/formatting.test.ts +4 -5
- package/src/extensions/markdown/formatting.ts +34 -73
|
@@ -1836,7 +1836,7 @@ import { syntaxTree as syntaxTree2 } from "@codemirror/language";
|
|
|
1836
1836
|
import { RangeSetBuilder as RangeSetBuilder2, EditorSelection } from "@codemirror/state";
|
|
1837
1837
|
import { Decoration as Decoration4, EditorView as EditorView9, keymap as keymap5, ViewPlugin as ViewPlugin4 } from "@codemirror/view";
|
|
1838
1838
|
import { useState, useMemo } from "react";
|
|
1839
|
-
var compareFormatting = (a, b) => a.blockType === b.blockType && a.strong === b.strong && a.emphasis === b.emphasis && a.strikethrough === b.strikethrough && a.code === b.code && a.link === b.link && a.listStyle === b.listStyle && a.
|
|
1839
|
+
var compareFormatting = (a, b) => a.blockType === b.blockType && a.strong === b.strong && a.emphasis === b.emphasis && a.strikethrough === b.strikethrough && a.code === b.code && a.link === b.link && a.listStyle === b.listStyle && a.blockquote === b.blockquote;
|
|
1840
1840
|
var Inline;
|
|
1841
1841
|
(function(Inline2) {
|
|
1842
1842
|
Inline2[Inline2["Strong"] = 0] = "Strong";
|
|
@@ -2108,18 +2108,15 @@ var skipSpaces = (pos, doc, dir, limit) => {
|
|
|
2108
2108
|
};
|
|
2109
2109
|
var snippets = {
|
|
2110
2110
|
codeblock: snippet([
|
|
2111
|
-
|
|
2112
|
-
"```#{}",
|
|
2111
|
+
"```#{lang}",
|
|
2113
2112
|
"#{}",
|
|
2114
2113
|
"```"
|
|
2115
2114
|
].join("\n")),
|
|
2116
2115
|
table: snippet([
|
|
2117
|
-
//
|
|
2118
2116
|
"| #{col1} | #{col2} |",
|
|
2119
2117
|
"| ---- | ---- |",
|
|
2120
2118
|
"| #{val1} | #{val2} |",
|
|
2121
|
-
"| #{val3} | #{val4} |"
|
|
2122
|
-
""
|
|
2119
|
+
"| #{val3} | #{val4} |"
|
|
2123
2120
|
].join("\n"))
|
|
2124
2121
|
};
|
|
2125
2122
|
var insertTable = (view) => {
|
|
@@ -2313,20 +2310,6 @@ var addList = (type) => ({ state, dispatch }) => {
|
|
|
2313
2310
|
});
|
|
2314
2311
|
}
|
|
2315
2312
|
if (!blocks.length) {
|
|
2316
|
-
const { from, to } = state.doc.lineAt(state.selection.main.anchor);
|
|
2317
|
-
if (from === to) {
|
|
2318
|
-
dispatch(state.update({
|
|
2319
|
-
changes: [
|
|
2320
|
-
{
|
|
2321
|
-
from,
|
|
2322
|
-
insert: type === 1 ? "- " : type === 0 ? "1. " : "- [ ] "
|
|
2323
|
-
}
|
|
2324
|
-
],
|
|
2325
|
-
userEvent: "format.list.add",
|
|
2326
|
-
scrollIntoView: true
|
|
2327
|
-
}));
|
|
2328
|
-
return true;
|
|
2329
|
-
}
|
|
2330
2313
|
return false;
|
|
2331
2314
|
}
|
|
2332
2315
|
const changes = [];
|
|
@@ -2541,7 +2524,7 @@ var setBlockquote = (enable) => ({ state, dispatch }) => {
|
|
|
2541
2524
|
var addBlockquote = setBlockquote(true);
|
|
2542
2525
|
var removeBlockquote = setBlockquote(false);
|
|
2543
2526
|
var toggleBlockquote = (target) => {
|
|
2544
|
-
return (getFormatting(target.state).
|
|
2527
|
+
return (getFormatting(target.state).blockquote ? removeBlockquote : addBlockquote)(target);
|
|
2545
2528
|
};
|
|
2546
2529
|
var addCodeblock = (target) => {
|
|
2547
2530
|
const { state, dispatch } = target;
|
|
@@ -2723,37 +2706,37 @@ var InlineMarker = {
|
|
|
2723
2706
|
Strikethrough: 2
|
|
2724
2707
|
};
|
|
2725
2708
|
var IgnoreInline = /* @__PURE__ */ new Set([
|
|
2726
|
-
"Autolink",
|
|
2727
|
-
"CodeMark",
|
|
2728
|
-
"CodeText",
|
|
2729
|
-
"Comment",
|
|
2730
|
-
"EmphasisMark",
|
|
2731
2709
|
"Hardbreak",
|
|
2732
|
-
"HeaderMark",
|
|
2733
2710
|
"HTMLTag",
|
|
2734
|
-
"
|
|
2735
|
-
"ListMark",
|
|
2711
|
+
"Comment",
|
|
2736
2712
|
"ProcessingInstruction",
|
|
2713
|
+
"Autolink",
|
|
2714
|
+
"HeaderMark",
|
|
2737
2715
|
"QuoteMark",
|
|
2716
|
+
"ListMark",
|
|
2717
|
+
"LinkMark",
|
|
2718
|
+
"EmphasisMark",
|
|
2719
|
+
"CodeMark",
|
|
2720
|
+
"CodeText",
|
|
2738
2721
|
"StrikethroughMark",
|
|
2739
|
-
"
|
|
2722
|
+
"TaskMarker",
|
|
2740
2723
|
"SuperscriptMark",
|
|
2741
|
-
"
|
|
2724
|
+
"SubscriptMark"
|
|
2742
2725
|
]);
|
|
2743
2726
|
var Textblocks = {
|
|
2727
|
+
Paragraph: "paragraph",
|
|
2728
|
+
Task: "paragraph",
|
|
2729
|
+
CodeBlock: "codeblock",
|
|
2730
|
+
FencedCode: "codeblock",
|
|
2744
2731
|
ATXHeading1: "heading1",
|
|
2745
2732
|
ATXHeading2: "heading2",
|
|
2746
2733
|
ATXHeading3: "heading3",
|
|
2747
2734
|
ATXHeading4: "heading4",
|
|
2748
2735
|
ATXHeading5: "heading5",
|
|
2749
2736
|
ATXHeading6: "heading6",
|
|
2750
|
-
CodeBlock: "codeblock",
|
|
2751
|
-
FencedCode: "codeblock",
|
|
2752
|
-
Paragraph: "paragraph",
|
|
2753
2737
|
SetextHeading1: "heading1",
|
|
2754
2738
|
SetextHeading2: "heading2",
|
|
2755
|
-
TableCell: "tablecell"
|
|
2756
|
-
Task: "paragraph"
|
|
2739
|
+
TableCell: "tablecell"
|
|
2757
2740
|
};
|
|
2758
2741
|
var getFormatting = (state) => {
|
|
2759
2742
|
let blockType = null;
|
|
@@ -2764,7 +2747,7 @@ var getFormatting = (state) => {
|
|
|
2764
2747
|
null
|
|
2765
2748
|
];
|
|
2766
2749
|
let link2 = false;
|
|
2767
|
-
let
|
|
2750
|
+
let blockquote2 = null;
|
|
2768
2751
|
let listStyle = null;
|
|
2769
2752
|
const stack = [];
|
|
2770
2753
|
let currentBlock = null;
|
|
@@ -2873,10 +2856,10 @@ var getFormatting = (state) => {
|
|
|
2873
2856
|
hasList = stack[i] === "TaskList" ? "task" : stack[i] === "BulletList" ? "bullet" : "ordered";
|
|
2874
2857
|
}
|
|
2875
2858
|
}
|
|
2876
|
-
if (
|
|
2877
|
-
|
|
2878
|
-
} else if (!hasQuote &&
|
|
2879
|
-
|
|
2859
|
+
if (blockquote2 === null) {
|
|
2860
|
+
blockquote2 = hasQuote;
|
|
2861
|
+
} else if (!hasQuote && blockquote2) {
|
|
2862
|
+
blockquote2 = false;
|
|
2880
2863
|
}
|
|
2881
2864
|
if (listStyle === null) {
|
|
2882
2865
|
listStyle = hasList;
|
|
@@ -2890,17 +2873,14 @@ var getFormatting = (state) => {
|
|
|
2890
2873
|
}
|
|
2891
2874
|
});
|
|
2892
2875
|
}
|
|
2893
|
-
const { from, to } = state.doc.lineAt(selection.main.anchor);
|
|
2894
|
-
const blankLine = from === to;
|
|
2895
2876
|
return {
|
|
2896
|
-
blankLine,
|
|
2897
2877
|
blockType: blockType || null,
|
|
2898
|
-
blockQuote: blockQuote ?? false,
|
|
2899
|
-
code: inline[3] ?? false,
|
|
2900
|
-
emphasis: inline[1] ?? false,
|
|
2901
2878
|
strong: inline[0] ?? false,
|
|
2879
|
+
emphasis: inline[1] ?? false,
|
|
2880
|
+
code: inline[3] ?? false,
|
|
2902
2881
|
strikethrough: inline[2] ?? false,
|
|
2903
2882
|
link: link2,
|
|
2883
|
+
blockquote: blockquote2 ?? false,
|
|
2904
2884
|
listStyle: listStyle || null
|
|
2905
2885
|
};
|
|
2906
2886
|
};
|
|
@@ -3934,20 +3914,11 @@ var defaultMarkdownSlots = {
|
|
|
3934
3914
|
};
|
|
3935
3915
|
|
|
3936
3916
|
// packages/ui/react-ui-editor/src/components/Toolbar/Toolbar.tsx
|
|
3937
|
-
import { CaretRight, ChatText, Code,
|
|
3917
|
+
import { CaretRight, ChatText, Code, Link, ListBullets, ListChecks, ListNumbers, Paragraph, TextStrikethrough, Table as Table2, TextB, TextItalic } from "@phosphor-icons/react";
|
|
3938
3918
|
import { createContext } from "@radix-ui/react-context";
|
|
3939
3919
|
import React2 from "react";
|
|
3940
3920
|
import { Button, DensityProvider, Select } from "@dxos/react-ui";
|
|
3941
3921
|
import { getSize, mx as mx4 } from "@dxos/react-ui-theme";
|
|
3942
|
-
var HeadingIcons = {
|
|
3943
|
-
"0": Paragraph,
|
|
3944
|
-
"1": TextHOne,
|
|
3945
|
-
"2": TextHTwo,
|
|
3946
|
-
"3": TextHThree,
|
|
3947
|
-
"4": TextHFour,
|
|
3948
|
-
"5": TextHFive,
|
|
3949
|
-
"6": TextHSix
|
|
3950
|
-
};
|
|
3951
3922
|
var [ToolbarContextProvider, useToolbarContext] = createContext("Toolbar");
|
|
3952
3923
|
var ToolbarRoot = ({ children, onAction, state }) => {
|
|
3953
3924
|
return /* @__PURE__ */ React2.createElement(ToolbarContextProvider, {
|
|
@@ -3957,7 +3928,7 @@ var ToolbarRoot = ({ children, onAction, state }) => {
|
|
|
3957
3928
|
density: "fine"
|
|
3958
3929
|
}, /* @__PURE__ */ React2.createElement("div", {
|
|
3959
3930
|
role: "toolbar",
|
|
3960
|
-
className: "flex w-full shrink-0 p-1 gap-
|
|
3931
|
+
className: "flex w-full shrink-0 p-1 gap-2 items-center whitespace-nowrap overflow-hidden"
|
|
3961
3932
|
}, children)));
|
|
3962
3933
|
};
|
|
3963
3934
|
var ToolbarButton = ({ Icon, onClick, title, getState, disable }) => {
|
|
@@ -3988,8 +3959,7 @@ var MarkdownHeading = () => {
|
|
|
3988
3959
|
const { onAction, state } = useToolbarContext("MarkdownFormatting");
|
|
3989
3960
|
const blockType = state ? state.blockType : "paragraph";
|
|
3990
3961
|
const header = blockType && /heading(\d)/.exec(blockType);
|
|
3991
|
-
const value = header ? header[1] : blockType === "paragraph" || !blockType ? "0" :
|
|
3992
|
-
const HeadingIcon = HeadingIcons[value ?? "0"];
|
|
3962
|
+
const value = header ? header[1] : blockType === "paragraph" || !blockType ? "0" : null;
|
|
3993
3963
|
return /* @__PURE__ */ React2.createElement(Select.Root, {
|
|
3994
3964
|
disabled: value === null,
|
|
3995
3965
|
value: value ?? "0",
|
|
@@ -3997,7 +3967,7 @@ var MarkdownHeading = () => {
|
|
|
3997
3967
|
type: "heading",
|
|
3998
3968
|
data: parseInt(value2)
|
|
3999
3969
|
})
|
|
4000
|
-
}, /* @__PURE__ */ React2.createElement(Select.TriggerButton, null, /* @__PURE__ */ React2.createElement(
|
|
3970
|
+
}, /* @__PURE__ */ React2.createElement(Select.TriggerButton, null, /* @__PURE__ */ React2.createElement(Paragraph, {
|
|
4001
3971
|
className: getSize(5)
|
|
4002
3972
|
})), /* @__PURE__ */ React2.createElement(Select.Portal, null, /* @__PURE__ */ React2.createElement(Select.Content, null, /* @__PURE__ */ React2.createElement(Select.Viewport, null, /* @__PURE__ */ React2.createElement(Select.Option, {
|
|
4003
3973
|
value: "0"
|
|
@@ -4084,15 +4054,14 @@ var MarkdownBlocks = () => /* @__PURE__ */ React2.createElement("div", {
|
|
|
4084
4054
|
}, /* @__PURE__ */ React2.createElement(ToolbarButton, {
|
|
4085
4055
|
Icon: CaretRight,
|
|
4086
4056
|
title: "Block quote",
|
|
4087
|
-
getState: (s) => s.
|
|
4057
|
+
getState: (s) => s.blockquote,
|
|
4088
4058
|
onClick: (s) => ({
|
|
4089
4059
|
type: "blockquote",
|
|
4090
|
-
data: s ? !s.
|
|
4060
|
+
data: s ? !s.blockquote : null
|
|
4091
4061
|
})
|
|
4092
4062
|
}), /* @__PURE__ */ React2.createElement(ToolbarButton, {
|
|
4093
|
-
Icon:
|
|
4063
|
+
Icon: Code,
|
|
4094
4064
|
title: "Code block",
|
|
4095
|
-
disable: (s) => !s.blankLine,
|
|
4096
4065
|
getState: (s) => s.blockType === "codeblock",
|
|
4097
4066
|
onClick: (s) => ({
|
|
4098
4067
|
type: "codeblock",
|
|
@@ -4101,7 +4070,6 @@ var MarkdownBlocks = () => /* @__PURE__ */ React2.createElement("div", {
|
|
|
4101
4070
|
}), /* @__PURE__ */ React2.createElement(ToolbarButton, {
|
|
4102
4071
|
Icon: Table2,
|
|
4103
4072
|
title: "Table",
|
|
4104
|
-
disable: (s) => !s.blankLine,
|
|
4105
4073
|
onClick: () => ({
|
|
4106
4074
|
type: "table"
|
|
4107
4075
|
})
|