@mdxeditor/editor 3.0.7 → 3.1.0

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.
Files changed (61) hide show
  1. package/dist/FormatConstants.js +6 -0
  2. package/dist/MDXEditor.js +1 -1
  3. package/dist/directive-editors/GenericDirectiveEditor.js +5 -7
  4. package/dist/exportMarkdownFromLexical.js +10 -7
  5. package/dist/icons/strikethrough_s.svg.js +5 -0
  6. package/dist/icons/subscript.svg.js +5 -0
  7. package/dist/icons/superscript.svg.js +5 -0
  8. package/dist/importMarkdownToLexical.js +3 -1
  9. package/dist/index.d.ts +133 -142
  10. package/dist/index.js +2 -1
  11. package/dist/jsx-editors/GenericJsxEditor.js +1 -1
  12. package/dist/mdastUtilHtmlComment.js +2 -2
  13. package/dist/node_modules/micromark-extension-gfm-strikethrough/lib/syntax.js +114 -0
  14. package/dist/node_modules/micromark-util-chunked/index.js +29 -0
  15. package/dist/node_modules/micromark-util-classify-character/index.js +12 -0
  16. package/dist/node_modules/micromark-util-resolve-all/index.js +15 -0
  17. package/dist/plugins/codeblock/index.js +2 -2
  18. package/dist/plugins/codemirror/index.js +4 -4
  19. package/dist/plugins/core/Icon.js +6 -0
  20. package/dist/plugins/core/LexicalTextVisitor.js +56 -10
  21. package/dist/plugins/core/MdastFormattingVisitor.js +66 -30
  22. package/dist/plugins/core/MdastHTMLNode.js +1 -2
  23. package/dist/plugins/core/NestedLexicalEditor.js +1 -1
  24. package/dist/plugins/core/PropertyPopover.js +28 -18
  25. package/dist/plugins/core/index.js +36 -39
  26. package/dist/plugins/core/ui/DownshiftAutoComplete.js +1 -1
  27. package/dist/plugins/directives/index.js +2 -2
  28. package/dist/plugins/frontmatter/FrontmatterEditor.js +48 -31
  29. package/dist/plugins/frontmatter/FrontmatterNode.js +5 -3
  30. package/dist/plugins/image/ImageDialog.js +1 -1
  31. package/dist/plugins/image/ImageEditor.js +8 -6
  32. package/dist/plugins/image/ImageNode.js +2 -2
  33. package/dist/plugins/image/MdastImageVisitor.js +3 -3
  34. package/dist/plugins/image/index.js +20 -20
  35. package/dist/plugins/jsx/index.js +1 -1
  36. package/dist/plugins/link-dialog/LinkDialog.js +13 -5
  37. package/dist/plugins/link-dialog/index.js +7 -8
  38. package/dist/plugins/lists/MdastListVisitor.js +1 -2
  39. package/dist/plugins/lists/index.js +1 -1
  40. package/dist/plugins/markdown-shortcut/index.js +4 -2
  41. package/dist/plugins/sandpack/SandpackEditor.js +1 -1
  42. package/dist/plugins/sandpack/index.js +2 -2
  43. package/dist/plugins/sandpack/useCodeMirrorRef.js +8 -8
  44. package/dist/plugins/table/TableEditor.js +67 -50
  45. package/dist/plugins/table/TableNode.js +2 -2
  46. package/dist/plugins/toolbar/components/BlockTypeSelect.js +3 -3
  47. package/dist/plugins/toolbar/components/BoldItalicUnderlineToggles.js +79 -24
  48. package/dist/plugins/toolbar/components/ChangeAdmonitionType.js +1 -1
  49. package/dist/plugins/toolbar/components/ChangeCodeMirrorLanguage.js +1 -1
  50. package/dist/plugins/toolbar/components/DiffSourceToggleWrapper.js +3 -1
  51. package/dist/plugins/toolbar/components/InsertFrontmatter.js +3 -1
  52. package/dist/plugins/toolbar/components/InsertImage.js +12 -1
  53. package/dist/plugins/toolbar/components/InsertThematicBreak.js +10 -1
  54. package/dist/plugins/toolbar/components/KitchenSinkToolbar.js +2 -2
  55. package/dist/plugins/toolbar/primitives/DialogButton.js +1 -1
  56. package/dist/plugins/toolbar/primitives/select.js +3 -1
  57. package/dist/plugins/toolbar/primitives/toolbar.js +17 -3
  58. package/dist/utils/detectMac.js +1 -1
  59. package/dist/utils/isPartOftheEditorUI.js +1 -1
  60. package/package.json +9 -8
  61. package/dist/plugins/core/MdastInlineCodeVisitor.js +0 -27
package/dist/index.js CHANGED
@@ -27,7 +27,7 @@ import { toolbarContents$, toolbarPlugin } from "./plugins/toolbar/index.js";
27
27
  import { cmExtensions$, diffMarkdown$, diffSourcePlugin, readOnlyDiff$ } from "./plugins/diff-source/index.js";
28
28
  import { markdownShortcutPlugin } from "./plugins/markdown-shortcut/index.js";
29
29
  import { BlockTypeSelect } from "./plugins/toolbar/components/BlockTypeSelect.js";
30
- import { BoldItalicUnderlineToggles } from "./plugins/toolbar/components/BoldItalicUnderlineToggles.js";
30
+ import { BoldItalicUnderlineToggles, StrikeThroughSupSubToggles } from "./plugins/toolbar/components/BoldItalicUnderlineToggles.js";
31
31
  import { ChangeAdmonitionType, admonitionLabelsMap } from "./plugins/toolbar/components/ChangeAdmonitionType.js";
32
32
  import { ChangeCodeMirrorLanguage } from "./plugins/toolbar/components/ChangeCodeMirrorLanguage.js";
33
33
  import { CodeToggle } from "./plugins/toolbar/components/CodeToggle.js";
@@ -129,6 +129,7 @@ export {
129
129
  ShowSandpackInfo,
130
130
  SingleChoiceToggleGroup,
131
131
  SingleToggleGroup,
132
+ StrikeThroughSupSubToggles,
132
133
  TYPE_NAME,
133
134
  TableNode,
134
135
  ToggleSingleGroupWithItem,
@@ -3,7 +3,7 @@ import { useMdastNodeUpdater, NestedLexicalEditor } from "../plugins/core/Nested
3
3
  import { PropertyPopover } from "../plugins/core/PropertyPopover.js";
4
4
  import styles from "../styles/ui.module.css.js";
5
5
  const isExpressionValue = (value) => {
6
- if (typeof value === "object" && value !== null && "type" in value && value.type === "mdxJsxAttributeValueExpression" && "value" in value && typeof value.value === "string") {
6
+ if (value !== null && typeof value === "object" && "type" in value && "value" in value && typeof value.value === "string") {
7
7
  return true;
8
8
  }
9
9
  return false;
@@ -12,10 +12,10 @@ function commentFromMarkdown(_options) {
12
12
  exit: {
13
13
  comment(token) {
14
14
  const text = this.resume();
15
- if (_options == null ? void 0 : _options.ast) {
15
+ if (_options.ast) {
16
16
  this.enter(
17
17
  {
18
- // @ts-expect-error: hush.
18
+ // @ts-expect-error: not typing this
19
19
  type: "comment",
20
20
  value: "",
21
21
  commentValue: text.slice(0, -2)
@@ -0,0 +1,114 @@
1
+ import { splice } from "../../micromark-util-chunked/index.js";
2
+ import { classifyCharacter } from "../../micromark-util-classify-character/index.js";
3
+ import { resolveAll } from "../../micromark-util-resolve-all/index.js";
4
+ function gfmStrikethrough(options) {
5
+ const options_ = options || {};
6
+ let single = options_.singleTilde;
7
+ const tokenizer = {
8
+ tokenize: tokenizeStrikethrough,
9
+ resolveAll: resolveAllStrikethrough
10
+ };
11
+ if (single === null || single === void 0) {
12
+ single = true;
13
+ }
14
+ return {
15
+ text: {
16
+ [126]: tokenizer
17
+ },
18
+ insideSpan: {
19
+ null: [tokenizer]
20
+ },
21
+ attentionMarkers: {
22
+ null: [126]
23
+ }
24
+ };
25
+ function resolveAllStrikethrough(events, context) {
26
+ let index = -1;
27
+ while (++index < events.length) {
28
+ if (events[index][0] === "enter" && events[index][1].type === "strikethroughSequenceTemporary" && events[index][1]._close) {
29
+ let open = index;
30
+ while (open--) {
31
+ if (events[open][0] === "exit" && events[open][1].type === "strikethroughSequenceTemporary" && events[open][1]._open && // If the sizes are the same:
32
+ events[index][1].end.offset - events[index][1].start.offset === events[open][1].end.offset - events[open][1].start.offset) {
33
+ events[index][1].type = "strikethroughSequence";
34
+ events[open][1].type = "strikethroughSequence";
35
+ const strikethrough = {
36
+ type: "strikethrough",
37
+ start: Object.assign({}, events[open][1].start),
38
+ end: Object.assign({}, events[index][1].end)
39
+ };
40
+ const text = {
41
+ type: "strikethroughText",
42
+ start: Object.assign({}, events[open][1].end),
43
+ end: Object.assign({}, events[index][1].start)
44
+ };
45
+ const nextEvents = [
46
+ ["enter", strikethrough, context],
47
+ ["enter", events[open][1], context],
48
+ ["exit", events[open][1], context],
49
+ ["enter", text, context]
50
+ ];
51
+ const insideSpan = context.parser.constructs.insideSpan.null;
52
+ if (insideSpan) {
53
+ splice(
54
+ nextEvents,
55
+ nextEvents.length,
56
+ 0,
57
+ resolveAll(insideSpan, events.slice(open + 1, index), context)
58
+ );
59
+ }
60
+ splice(nextEvents, nextEvents.length, 0, [
61
+ ["exit", text, context],
62
+ ["enter", events[index][1], context],
63
+ ["exit", events[index][1], context],
64
+ ["exit", strikethrough, context]
65
+ ]);
66
+ splice(events, open - 1, index - open + 3, nextEvents);
67
+ index = open + nextEvents.length - 2;
68
+ break;
69
+ }
70
+ }
71
+ }
72
+ }
73
+ index = -1;
74
+ while (++index < events.length) {
75
+ if (events[index][1].type === "strikethroughSequenceTemporary") {
76
+ events[index][1].type = "data";
77
+ }
78
+ }
79
+ return events;
80
+ }
81
+ function tokenizeStrikethrough(effects, ok, nok) {
82
+ const previous = this.previous;
83
+ const events = this.events;
84
+ let size = 0;
85
+ return start;
86
+ function start(code) {
87
+ if (previous === 126 && events[events.length - 1][1].type !== "characterEscape") {
88
+ return nok(code);
89
+ }
90
+ effects.enter("strikethroughSequenceTemporary");
91
+ return more(code);
92
+ }
93
+ function more(code) {
94
+ const before = classifyCharacter(previous);
95
+ if (code === 126) {
96
+ if (size > 1)
97
+ return nok(code);
98
+ effects.consume(code);
99
+ size++;
100
+ return more;
101
+ }
102
+ if (size < 2 && !single)
103
+ return nok(code);
104
+ const token = effects.exit("strikethroughSequenceTemporary");
105
+ const after = classifyCharacter(code);
106
+ token._open = !after || after === 2 && Boolean(before);
107
+ token._close = !before || before === 2 && Boolean(after);
108
+ return ok(code);
109
+ }
110
+ }
111
+ }
112
+ export {
113
+ gfmStrikethrough
114
+ };
@@ -0,0 +1,29 @@
1
+ function splice(list, start, remove, items) {
2
+ const end = list.length;
3
+ let chunkStart = 0;
4
+ let parameters;
5
+ if (start < 0) {
6
+ start = -start > end ? 0 : end + start;
7
+ } else {
8
+ start = start > end ? end : start;
9
+ }
10
+ remove = remove > 0 ? remove : 0;
11
+ if (items.length < 1e4) {
12
+ parameters = Array.from(items);
13
+ parameters.unshift(start, remove);
14
+ list.splice(...parameters);
15
+ } else {
16
+ if (remove)
17
+ list.splice(start, remove);
18
+ while (chunkStart < items.length) {
19
+ parameters = items.slice(chunkStart, chunkStart + 1e4);
20
+ parameters.unshift(start, 0);
21
+ list.splice(...parameters);
22
+ chunkStart += 1e4;
23
+ start += 1e4;
24
+ }
25
+ }
26
+ }
27
+ export {
28
+ splice
29
+ };
@@ -0,0 +1,12 @@
1
+ import { markdownLineEndingOrSpace, unicodeWhitespace, unicodePunctuation } from "micromark-util-character";
2
+ function classifyCharacter(code) {
3
+ if (code === null || markdownLineEndingOrSpace(code) || unicodeWhitespace(code)) {
4
+ return 1;
5
+ }
6
+ if (unicodePunctuation(code)) {
7
+ return 2;
8
+ }
9
+ }
10
+ export {
11
+ classifyCharacter
12
+ };
@@ -0,0 +1,15 @@
1
+ function resolveAll(constructs, events, context) {
2
+ const called = [];
3
+ let index = -1;
4
+ while (++index < constructs.length) {
5
+ const resolve = constructs[index].resolveAll;
6
+ if (resolve && !called.includes(resolve)) {
7
+ events = resolve(events, context);
8
+ called.push(resolve);
9
+ }
10
+ }
11
+ return events;
12
+ }
13
+ export {
14
+ resolveAll
15
+ };
@@ -21,12 +21,12 @@ const insertCodeBlock$ = Signal((r) => {
21
21
  const appendCodeBlockEditorDescriptor$ = Appender(codeBlockEditorDescriptors$);
22
22
  const codeBlockPlugin = realmPlugin({
23
23
  update(realm, params) {
24
- realm.pub(defaultCodeBlockLanguage$, (params == null ? void 0 : params.defaultCodeBlockLanguage) || "");
24
+ realm.pub(defaultCodeBlockLanguage$, (params == null ? void 0 : params.defaultCodeBlockLanguage) ?? "");
25
25
  },
26
26
  init(realm, params) {
27
27
  realm.pubIn({
28
28
  [addActivePlugin$]: "codeblock",
29
- [codeBlockEditorDescriptors$]: (params == null ? void 0 : params.codeBlockEditorDescriptors) || [],
29
+ [codeBlockEditorDescriptors$]: (params == null ? void 0 : params.codeBlockEditorDescriptors) ?? [],
30
30
  [addImportVisitor$]: MdastCodeVisitor,
31
31
  [addLexicalNode$]: CodeBlockNode,
32
32
  [addExportVisitor$]: CodeBlockVisitor
@@ -30,15 +30,15 @@ const codeMirrorPlugin = realmPlugin({
30
30
  update(r, params) {
31
31
  r.pubIn({
32
32
  [codeBlockLanguages$]: params == null ? void 0 : params.codeBlockLanguages,
33
- [codeMirrorExtensions$]: (params == null ? void 0 : params.codeMirrorExtensions) || [],
33
+ [codeMirrorExtensions$]: (params == null ? void 0 : params.codeMirrorExtensions) ?? [],
34
34
  [codeMirrorAutoLoadLanguageSupport$]: (params == null ? void 0 : params.autoLoadLanguageSupport) ?? true
35
35
  });
36
36
  },
37
37
  init(r, params) {
38
38
  r.pubIn({
39
39
  [codeBlockLanguages$]: params == null ? void 0 : params.codeBlockLanguages,
40
- [codeMirrorExtensions$]: (params == null ? void 0 : params.codeMirrorExtensions) || [],
41
- [appendCodeBlockEditorDescriptor$]: buildCodeBlockDescriptor((params == null ? void 0 : params.codeBlockLanguages) || {}),
40
+ [codeMirrorExtensions$]: (params == null ? void 0 : params.codeMirrorExtensions) ?? [],
41
+ [appendCodeBlockEditorDescriptor$]: buildCodeBlockDescriptor((params == null ? void 0 : params.codeBlockLanguages) ?? {}),
42
42
  [codeMirrorAutoLoadLanguageSupport$]: (params == null ? void 0 : params.autoLoadLanguageSupport) ?? true
43
43
  });
44
44
  }
@@ -46,7 +46,7 @@ const codeMirrorPlugin = realmPlugin({
46
46
  function buildCodeBlockDescriptor(codeBlockLanguages) {
47
47
  return {
48
48
  match(language, meta) {
49
- return Boolean(codeBlockLanguages.hasOwnProperty(language || "")) && !Boolean(meta);
49
+ return Boolean(Object.hasOwn(codeBlockLanguages, language ?? "")) && !meta;
50
50
  },
51
51
  priority: 1,
52
52
  Editor: CodeMirrorEditor
@@ -42,6 +42,9 @@ import SvgRichText from "../../icons/rich_text.svg.js";
42
42
  import SvgSettings from "../../icons/settings.svg.js";
43
43
  import SvgTable from "../../icons/table.svg.js";
44
44
  import SvgUndo from "../../icons/undo.svg.js";
45
+ import SvgStrikethroughS from "../../icons/strikethrough_s.svg.js";
46
+ import SvgSuperscript from "../../icons/superscript.svg.js";
47
+ import SvgSubscript from "../../icons/subscript.svg.js";
45
48
  const IconMap = {
46
49
  add_column: SvgAddColumn,
47
50
  add_photo: SvgAddPhoto,
@@ -84,6 +87,9 @@ const IconMap = {
84
87
  redo: SvgRedo,
85
88
  rich_text: SvgRichText,
86
89
  settings: SvgSettings,
90
+ strikeThrough: SvgStrikethroughS,
91
+ subscript: SvgSubscript,
92
+ superscript: SvgSuperscript,
87
93
  table: SvgTable,
88
94
  undo: SvgUndo
89
95
  };
@@ -1,15 +1,16 @@
1
1
  import { $isTextNode } from "lexical";
2
- import { IS_CODE, IS_ITALIC, IS_BOLD, IS_UNDERLINE } from "../../FormatConstants.js";
2
+ import { IS_ITALIC, IS_BOLD, IS_UNDERLINE, IS_STRIKETHROUGH, IS_SUPERSCRIPT, IS_SUBSCRIPT, IS_CODE } from "../../FormatConstants.js";
3
3
  function isMdastText(mdastNode) {
4
4
  return mdastNode.type === "text";
5
5
  }
6
- const JOINABLE_TAGS = ["u", "span"];
6
+ const JOINABLE_TAGS = ["u", "span", "sub", "sup"];
7
7
  const LexicalTextVisitor = {
8
8
  shouldJoin: (prevNode, currentNode) => {
9
9
  if (["text", "emphasis", "strong"].includes(prevNode.type)) {
10
10
  return prevNode.type === currentNode.type;
11
11
  }
12
- if (prevNode.type === "mdxJsxTextElement" && currentNode.type === "mdxJsxTextElement" && JOINABLE_TAGS.includes(currentNode.name)) {
12
+ if (prevNode.type === "mdxJsxTextElement" && // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
13
+ currentNode.type === "mdxJsxTextElement" && JOINABLE_TAGS.includes(currentNode.name)) {
13
14
  const currentMdxNode = currentNode;
14
15
  return prevNode.name === currentMdxNode.name && JSON.stringify(prevNode.attributes) === JSON.stringify(currentMdxNode.attributes);
15
16
  }
@@ -33,14 +34,8 @@ const LexicalTextVisitor = {
33
34
  const previousSibling = lexicalNode.getPreviousSibling();
34
35
  const prevFormat = $isTextNode(previousSibling) ? previousSibling.getFormat() : 0;
35
36
  const textContent = lexicalNode.getTextContent();
36
- const format = lexicalNode.getFormat() ?? 0;
37
+ const format = lexicalNode.getFormat();
37
38
  const style = lexicalNode.getStyle();
38
- if (format & IS_CODE) {
39
- actions.addAndStepInto("inlineCode", {
40
- value: textContent
41
- });
42
- return;
43
- }
44
39
  let localParentNode = mdastParent;
45
40
  if (style) {
46
41
  localParentNode = actions.appendToParent(localParentNode, {
@@ -70,6 +65,28 @@ const LexicalTextVisitor = {
70
65
  attributes: []
71
66
  });
72
67
  }
68
+ if (prevFormat & format & IS_STRIKETHROUGH) {
69
+ localParentNode = actions.appendToParent(localParentNode, {
70
+ type: "delete",
71
+ children: []
72
+ });
73
+ }
74
+ if (prevFormat & format & IS_SUPERSCRIPT) {
75
+ localParentNode = actions.appendToParent(localParentNode, {
76
+ type: "mdxJsxTextElement",
77
+ name: "sup",
78
+ children: [],
79
+ attributes: []
80
+ });
81
+ }
82
+ if (prevFormat & format & IS_SUBSCRIPT) {
83
+ localParentNode = actions.appendToParent(localParentNode, {
84
+ type: "mdxJsxTextElement",
85
+ name: "sub",
86
+ children: [],
87
+ attributes: []
88
+ });
89
+ }
73
90
  if (format & IS_ITALIC && !(prevFormat & IS_ITALIC)) {
74
91
  localParentNode = actions.appendToParent(localParentNode, {
75
92
  type: "emphasis",
@@ -90,6 +107,35 @@ const LexicalTextVisitor = {
90
107
  attributes: []
91
108
  });
92
109
  }
110
+ if (format & IS_STRIKETHROUGH && !(prevFormat & IS_STRIKETHROUGH)) {
111
+ localParentNode = actions.appendToParent(localParentNode, {
112
+ type: "delete",
113
+ children: []
114
+ });
115
+ }
116
+ if (format & IS_SUPERSCRIPT && !(prevFormat & IS_SUPERSCRIPT)) {
117
+ localParentNode = actions.appendToParent(localParentNode, {
118
+ type: "mdxJsxTextElement",
119
+ name: "sup",
120
+ children: [],
121
+ attributes: []
122
+ });
123
+ }
124
+ if (format & IS_SUBSCRIPT && !(prevFormat & IS_SUBSCRIPT)) {
125
+ localParentNode = actions.appendToParent(localParentNode, {
126
+ type: "mdxJsxTextElement",
127
+ name: "sub",
128
+ children: [],
129
+ attributes: []
130
+ });
131
+ }
132
+ if (format & IS_CODE) {
133
+ actions.appendToParent(localParentNode, {
134
+ type: "inlineCode",
135
+ value: textContent
136
+ });
137
+ return;
138
+ }
93
139
  actions.appendToParent(localParentNode, {
94
140
  type: "text",
95
141
  value: textContent
@@ -1,36 +1,72 @@
1
- import { IS_UNDERLINE, IS_ITALIC, IS_BOLD } from "../../FormatConstants.js";
2
- function isOpeningUnderlineNode(node) {
3
- return node.type === "html" && node.value === "<u>";
4
- }
5
- function isClosingUnderlineNode(node) {
6
- return node.type === "html" && node.value === "</u>";
7
- }
8
- function isJsxUnderlineNode(node) {
9
- return node.type === "mdxJsxTextElement" && node.name === "u";
10
- }
11
- const MdastFormattingVisitor = {
12
- testNode(mdastNode) {
13
- return mdastNode.type === "emphasis" || mdastNode.type === "strong" || isJsxUnderlineNode(mdastNode) || isOpeningUnderlineNode(mdastNode) || isClosingUnderlineNode(mdastNode);
14
- },
15
- visitNode({ mdastNode, lexicalParent, actions, mdastParent }) {
16
- if (isOpeningUnderlineNode(mdastNode)) {
17
- actions.removeFormatting(IS_UNDERLINE, mdastParent);
18
- return;
19
- }
20
- if (isClosingUnderlineNode(mdastNode)) {
21
- actions.removeFormatting(IS_UNDERLINE, mdastParent);
22
- return;
23
- }
24
- if (mdastNode.type === "emphasis") {
25
- actions.addFormatting(IS_ITALIC);
26
- } else if (mdastNode.type === "strong") {
27
- actions.addFormatting(IS_BOLD);
28
- } else if (isJsxUnderlineNode(mdastNode)) {
29
- actions.addFormatting(IS_UNDERLINE);
1
+ import { IS_STRIKETHROUGH, IS_CODE, IS_ITALIC, IS_BOLD, IS_UNDERLINE, IS_SUPERSCRIPT, IS_SUBSCRIPT } from "../../FormatConstants.js";
2
+ import { $createTextNode } from "lexical";
3
+ function buildFormattingVisitors(tag, format) {
4
+ return [
5
+ {
6
+ testNode: (node) => node.type === "mdxJsxTextElement" && node.name === tag,
7
+ visitNode({ actions, mdastNode, lexicalParent }) {
8
+ actions.addFormatting(format);
9
+ actions.visitChildren(mdastNode, lexicalParent);
10
+ }
11
+ },
12
+ {
13
+ testNode: (node) => node.type === "html" && node.value === `<${tag}>`,
14
+ visitNode({ actions, mdastParent }) {
15
+ actions.addFormatting(format, mdastParent);
16
+ }
17
+ },
18
+ {
19
+ testNode: (node) => node.type === "html" && node.value === `</${tag}>`,
20
+ visitNode({ actions, mdastParent }) {
21
+ actions.removeFormatting(format, mdastParent);
22
+ }
30
23
  }
24
+ ];
25
+ }
26
+ const StrikeThroughVisitor = {
27
+ testNode: "delete",
28
+ visitNode({ mdastNode, actions, lexicalParent }) {
29
+ actions.addFormatting(IS_STRIKETHROUGH);
30
+ actions.visitChildren(mdastNode, lexicalParent);
31
+ }
32
+ };
33
+ const MdCodeVisitor = {
34
+ testNode: "inlineCode",
35
+ visitNode({ mdastNode, actions }) {
36
+ actions.addAndStepInto($createTextNode(mdastNode.value).setFormat(actions.getParentFormatting() | IS_CODE));
37
+ }
38
+ };
39
+ const MdEmphasisVisitor = {
40
+ testNode: "emphasis",
41
+ visitNode({ mdastNode, actions, lexicalParent }) {
42
+ actions.addFormatting(IS_ITALIC);
43
+ actions.visitChildren(mdastNode, lexicalParent);
44
+ }
45
+ };
46
+ const MdStrongVisitor = {
47
+ testNode: "strong",
48
+ visitNode({ mdastNode, actions, lexicalParent }) {
49
+ actions.addFormatting(IS_BOLD);
31
50
  actions.visitChildren(mdastNode, lexicalParent);
32
51
  }
33
52
  };
53
+ const formattingVisitors = [
54
+ // emphasis
55
+ MdEmphasisVisitor,
56
+ // strong
57
+ MdStrongVisitor,
58
+ // underline
59
+ ...buildFormattingVisitors("u", IS_UNDERLINE),
60
+ // code
61
+ ...buildFormattingVisitors("code", IS_CODE),
62
+ MdCodeVisitor,
63
+ // strikethrough
64
+ StrikeThroughVisitor,
65
+ // superscript
66
+ ...buildFormattingVisitors("sup", IS_SUPERSCRIPT),
67
+ // subscript
68
+ ...buildFormattingVisitors("sub", IS_SUBSCRIPT)
69
+ ];
34
70
  export {
35
- MdastFormattingVisitor
71
+ formattingVisitors
36
72
  };
@@ -1,7 +1,6 @@
1
1
  const MDX_NODE_TYPES = ["mdxJsxTextElement", "mdxJsxFlowElement"];
2
2
  function isMdastHTMLNode(node) {
3
- var _a;
4
- return MDX_NODE_TYPES.includes(node.type) && htmlTags.includes(((_a = node.name) == null ? void 0 : _a.toLowerCase()) ?? "");
3
+ return MDX_NODE_TYPES.includes(node.type) && htmlTags.includes(node.name.toLowerCase());
5
4
  }
6
5
  const htmlTags = [
7
6
  "a",
@@ -84,7 +84,7 @@ const NestedLexicalEditor = function(props) {
84
84
  return editor2;
85
85
  });
86
86
  React__default.useEffect(() => {
87
- focusEmitter == null ? void 0 : focusEmitter.subscribe(() => {
87
+ focusEmitter.subscribe(() => {
88
88
  editor.focus();
89
89
  });
90
90
  }, [editor, focusEmitter]);
@@ -9,31 +9,41 @@ const PropertyPopover = ({ title, properties, onChange }) => {
9
9
  const [open, setOpen] = React__default.useState(false);
10
10
  const iconComponentFor = useCellValue(iconComponentFor$);
11
11
  const { register, handleSubmit, reset } = useForm({ defaultValues: properties });
12
- return /* @__PURE__ */ React__default.createElement(RadixPopover.Root, { open, onOpenChange: (v) => setOpen(v) }, /* @__PURE__ */ React__default.createElement(RadixPopover.Trigger, { className: styles.iconButton }, /* @__PURE__ */ React__default.createElement("div", null, iconComponentFor("settings"))), /* @__PURE__ */ React__default.createElement(PopoverPortal, null, /* @__PURE__ */ React__default.createElement(PopoverContent, null, /* @__PURE__ */ React__default.createElement(
13
- "form",
12
+ return /* @__PURE__ */ React__default.createElement(
13
+ RadixPopover.Root,
14
14
  {
15
- onSubmit: (e) => {
16
- void handleSubmit(onChange)(e);
17
- setOpen(false);
18
- e.preventDefault();
19
- e.stopPropagation();
15
+ open,
16
+ onOpenChange: (v) => {
17
+ setOpen(v);
20
18
  }
21
19
  },
22
- /* @__PURE__ */ React__default.createElement("h3", { className: styles.propertyPanelTitle }, title, " Attributes"),
23
- /* @__PURE__ */ React__default.createElement("table", { className: styles.propertyEditorTable }, /* @__PURE__ */ React__default.createElement("thead", null, /* @__PURE__ */ React__default.createElement("tr", null, /* @__PURE__ */ React__default.createElement("th", { className: styles.readOnlyColumnCell }, "Attribute"), /* @__PURE__ */ React__default.createElement("th", null, "Value"))), /* @__PURE__ */ React__default.createElement("tbody", null, Object.keys(properties).map((propName) => /* @__PURE__ */ React__default.createElement("tr", { key: propName }, /* @__PURE__ */ React__default.createElement("th", { className: styles.readOnlyColumnCell }, " ", propName, " "), /* @__PURE__ */ React__default.createElement("td", null, /* @__PURE__ */ React__default.createElement("input", { ...register(propName), className: styles.propertyEditorInput }))))), /* @__PURE__ */ React__default.createElement("tfoot", null, /* @__PURE__ */ React__default.createElement("tr", null, /* @__PURE__ */ React__default.createElement("td", { colSpan: 2 }, /* @__PURE__ */ React__default.createElement("div", { className: styles.buttonsFooter }, /* @__PURE__ */ React__default.createElement("button", { type: "submit", className: styles.primaryButton }, "Save"), /* @__PURE__ */ React__default.createElement(
24
- "button",
20
+ /* @__PURE__ */ React__default.createElement(RadixPopover.Trigger, { className: styles.iconButton }, /* @__PURE__ */ React__default.createElement("div", null, iconComponentFor("settings"))),
21
+ /* @__PURE__ */ React__default.createElement(PopoverPortal, null, /* @__PURE__ */ React__default.createElement(PopoverContent, null, /* @__PURE__ */ React__default.createElement(
22
+ "form",
25
23
  {
26
- type: "reset",
27
- className: styles.secondaryButton,
28
- onClick: (e) => {
29
- e.preventDefault();
30
- reset(properties);
24
+ onSubmit: (e) => {
25
+ void handleSubmit(onChange)(e);
31
26
  setOpen(false);
27
+ e.preventDefault();
28
+ e.stopPropagation();
32
29
  }
33
30
  },
34
- "Cancel"
35
- ))))))
36
- ))));
31
+ /* @__PURE__ */ React__default.createElement("h3", { className: styles.propertyPanelTitle }, title, " Attributes"),
32
+ /* @__PURE__ */ React__default.createElement("table", { className: styles.propertyEditorTable }, /* @__PURE__ */ React__default.createElement("thead", null, /* @__PURE__ */ React__default.createElement("tr", null, /* @__PURE__ */ React__default.createElement("th", { className: styles.readOnlyColumnCell }, "Attribute"), /* @__PURE__ */ React__default.createElement("th", null, "Value"))), /* @__PURE__ */ React__default.createElement("tbody", null, Object.keys(properties).map((propName) => /* @__PURE__ */ React__default.createElement("tr", { key: propName }, /* @__PURE__ */ React__default.createElement("th", { className: styles.readOnlyColumnCell }, " ", propName, " "), /* @__PURE__ */ React__default.createElement("td", null, /* @__PURE__ */ React__default.createElement("input", { ...register(propName), className: styles.propertyEditorInput }))))), /* @__PURE__ */ React__default.createElement("tfoot", null, /* @__PURE__ */ React__default.createElement("tr", null, /* @__PURE__ */ React__default.createElement("td", { colSpan: 2 }, /* @__PURE__ */ React__default.createElement("div", { className: styles.buttonsFooter }, /* @__PURE__ */ React__default.createElement("button", { type: "submit", className: styles.primaryButton }, "Save"), /* @__PURE__ */ React__default.createElement(
33
+ "button",
34
+ {
35
+ type: "reset",
36
+ className: styles.secondaryButton,
37
+ onClick: (e) => {
38
+ e.preventDefault();
39
+ reset(properties);
40
+ setOpen(false);
41
+ }
42
+ },
43
+ "Cancel"
44
+ ))))))
45
+ )))
46
+ );
37
47
  };
38
48
  export {
39
49
  PropertyPopover