@lobehub/editor 3.2.0 → 3.2.1

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 (131) hide show
  1. package/es/plugins/auto-complete/react/ReactAutoCompletePlugin.js +2 -4
  2. package/es/plugins/auto-complete/react/style.d.ts +4 -4
  3. package/es/plugins/auto-complete/react/style.js +2 -2
  4. package/es/plugins/code/react/CodeReactPlugin.js +2 -4
  5. package/es/plugins/code/react/style.d.ts +3 -3
  6. package/es/plugins/code/react/style.js +4 -4
  7. package/es/plugins/codeblock/command/index.d.ts +2 -11
  8. package/es/plugins/codeblock/command/index.js +1 -37
  9. package/es/plugins/codeblock/plugin/CodeHighlighterShiki.d.ts +0 -6
  10. package/es/plugins/codeblock/plugin/CodeHighlighterShiki.js +4 -5
  11. package/es/plugins/codeblock/plugin/FacadeShiki.d.ts +2 -7
  12. package/es/plugins/codeblock/plugin/FacadeShiki.js +46 -103
  13. package/es/plugins/codeblock/plugin/index.d.ts +0 -5
  14. package/es/plugins/codeblock/plugin/index.js +3 -7
  15. package/es/plugins/codeblock/react/ReactCodeblockPlugin.js +9 -26
  16. package/es/plugins/codeblock/react/style.d.ts +4 -6
  17. package/es/plugins/codeblock/react/style.js +5 -32
  18. package/es/plugins/common/react/Placeholder/index.js +1 -3
  19. package/es/plugins/common/react/Placeholder/style.d.ts +4 -4
  20. package/es/plugins/common/react/Placeholder/style.js +4 -4
  21. package/es/plugins/common/react/ReactPlainText.js +33 -21
  22. package/es/plugins/common/react/style.d.ts +22 -32
  23. package/es/plugins/common/react/style.js +27 -30
  24. package/es/plugins/file/react/ReactFilePlugin.js +1 -3
  25. package/es/plugins/file/react/style.d.ts +3 -3
  26. package/es/plugins/file/react/style.js +4 -4
  27. package/es/plugins/hr/react/components/HRNode.d.ts +2 -2
  28. package/es/plugins/hr/react/components/HRNode.js +5 -7
  29. package/es/plugins/hr/react/style.d.ts +1 -1
  30. package/es/plugins/hr/react/style.js +4 -4
  31. package/es/plugins/image/react/ReactImagePlugin.js +1 -3
  32. package/es/plugins/image/react/components/BrokenImage.js +3 -5
  33. package/es/plugins/image/react/components/Image.js +2 -4
  34. package/es/plugins/image/react/components/LazyImage.d.ts +9 -8
  35. package/es/plugins/image/react/components/LazyImage.js +6 -7
  36. package/es/plugins/image/react/components/ResizeHandle.d.ts +2 -2
  37. package/es/plugins/image/react/components/ResizeHandle.js +5 -7
  38. package/es/plugins/image/react/components/style.d.ts +9 -7
  39. package/es/plugins/image/react/components/style.js +11 -10
  40. package/es/plugins/image/react/style.d.ts +4 -4
  41. package/es/plugins/image/react/style.js +5 -5
  42. package/es/plugins/link/react/ReactLinkPlugin.js +1 -3
  43. package/es/plugins/link/react/components/LinkEdit.d.ts +2 -2
  44. package/es/plugins/link/react/components/LinkEdit.js +7 -9
  45. package/es/plugins/link/react/components/LinkToolbar.js +1 -3
  46. package/es/plugins/link/react/style.d.ts +4 -4
  47. package/es/plugins/link/react/style.js +7 -8
  48. package/es/plugins/link-highlight/react/ReactLinkHighlightPlugin.js +2 -4
  49. package/es/plugins/link-highlight/react/style.d.ts +3 -3
  50. package/es/plugins/link-highlight/react/style.js +2 -2
  51. package/es/plugins/list/react/ReactListPlugin.js +1 -3
  52. package/es/plugins/list/react/style.d.ts +1 -1
  53. package/es/plugins/list/react/style.js +4 -5
  54. package/es/plugins/litexml/react/DiffNodeToolbar/index.js +5 -4
  55. package/es/plugins/litexml/react/DiffNodeToolbar/style.d.ts +6 -5
  56. package/es/plugins/litexml/react/DiffNodeToolbar/style.js +7 -7
  57. package/es/plugins/litexml/react/index.js +1 -3
  58. package/es/plugins/litexml/react/style.d.ts +1 -1
  59. package/es/plugins/litexml/react/style.js +4 -4
  60. package/es/plugins/math/react/components/MathEditorContainer.js +1 -3
  61. package/es/plugins/math/react/components/MathEditorContent.js +3 -7
  62. package/es/plugins/math/react/components/MathInline.d.ts +2 -2
  63. package/es/plugins/math/react/components/MathInline.js +3 -3
  64. package/es/plugins/math/react/components/Placeholder.js +4 -6
  65. package/es/plugins/math/react/index.js +1 -3
  66. package/es/plugins/math/react/style.d.ts +6 -4
  67. package/es/plugins/math/react/style.js +10 -9
  68. package/es/plugins/mention/react/ReactMentionPlugin.js +1 -3
  69. package/es/plugins/mention/react/style.d.ts +3 -3
  70. package/es/plugins/mention/react/style.js +4 -4
  71. package/es/plugins/slash/react/components/DefaultSlashMenu.d.ts +2 -2
  72. package/es/plugins/slash/react/components/DefaultSlashMenu.js +24 -17
  73. package/es/plugins/slash/react/components/SlashMenu.d.ts +2 -2
  74. package/es/plugins/slash/react/components/SlashMenu.js +3 -4
  75. package/es/plugins/slash/react/style.d.ts +1 -1
  76. package/es/plugins/slash/react/style.js +4 -4
  77. package/es/plugins/table/react/TableActionMenu/index.js +3 -7
  78. package/es/plugins/table/react/TableActionMenu/style.d.ts +4 -1
  79. package/es/plugins/table/react/TableActionMenu/style.js +7 -4
  80. package/es/plugins/table/react/TableHoverActions/index.js +2 -4
  81. package/es/plugins/table/react/TableHoverActions/style.d.ts +4 -4
  82. package/es/plugins/table/react/TableHoverActions/style.js +2 -2
  83. package/es/plugins/table/react/TableResize/index.js +4 -7
  84. package/es/plugins/table/react/TableResize/style.d.ts +1 -1
  85. package/es/plugins/table/react/TableResize/style.js +4 -4
  86. package/es/plugins/table/react/index.js +2 -4
  87. package/es/plugins/table/react/style.d.ts +1 -1
  88. package/es/plugins/table/react/style.js +4 -4
  89. package/es/plugins/toolbar/react/index.js +6 -8
  90. package/es/plugins/toolbar/react/style.d.ts +5 -1
  91. package/es/plugins/toolbar/react/style.js +9 -6
  92. package/es/react/ChatInput/ChatInput.d.ts +2 -2
  93. package/es/react/ChatInput/ChatInput.js +16 -27
  94. package/es/react/ChatInput/style.d.ts +11 -6
  95. package/es/react/ChatInput/style.js +13 -9
  96. package/es/react/ChatInputActionBar/ChatInputActionBar.js +2 -4
  97. package/es/react/ChatInputActionBar/style.d.ts +3 -3
  98. package/es/react/ChatInputActionBar/style.js +2 -2
  99. package/es/react/ChatInputActions/ChatInputActions.js +25 -25
  100. package/es/react/ChatInputActions/components/ActionItem.d.ts +2 -2
  101. package/es/react/ChatInputActions/components/ActionItem.js +2 -4
  102. package/es/react/ChatInputActions/components/ActionRender.d.ts +2 -2
  103. package/es/react/ChatInputActions/components/ActionRender.js +5 -11
  104. package/es/react/ChatInputActions/components/CollapsedActions.d.ts +2 -2
  105. package/es/react/ChatInputActions/components/CollapsedActions.js +5 -8
  106. package/es/react/ChatInputActions/style.d.ts +5 -4
  107. package/es/react/ChatInputActions/style.js +6 -5
  108. package/es/react/CodeLanguageSelect/CodeLanguageSelect.d.ts +2 -2
  109. package/es/react/CodeLanguageSelect/CodeLanguageSelect.js +6 -9
  110. package/es/react/CodeLanguageSelect/style.d.ts +3 -3
  111. package/es/react/CodeLanguageSelect/style.js +2 -2
  112. package/es/react/FloatActions/FloatActions.d.ts +2 -2
  113. package/es/react/FloatActions/FloatActions.js +4 -8
  114. package/es/react/FloatActions/components/ActionItem.d.ts +2 -2
  115. package/es/react/FloatActions/components/ActionItem.js +2 -4
  116. package/es/react/FloatActions/components/ActionRender.d.ts +2 -2
  117. package/es/react/FloatActions/components/ActionRender.js +5 -11
  118. package/es/react/FloatActions/components/CollapsedActions.d.ts +2 -2
  119. package/es/react/FloatActions/components/CollapsedActions.js +5 -8
  120. package/es/react/FloatActions/style.d.ts +5 -4
  121. package/es/react/FloatActions/style.js +6 -5
  122. package/es/react/FloatMenu/FloatMenu.js +2 -4
  123. package/es/react/FloatMenu/style.d.ts +5 -4
  124. package/es/react/FloatMenu/style.js +7 -6
  125. package/es/react/SendButton/SendButton.d.ts +2 -2
  126. package/es/react/SendButton/SendButton.js +17 -15
  127. package/es/react/SendButton/components/SendIcon.js +15 -15
  128. package/es/react/SendButton/components/StopIcon.js +16 -18
  129. package/es/react/SendButton/style.d.ts +7 -7
  130. package/es/react/SendButton/style.js +9 -10
  131. package/package.json +3 -3
@@ -6,19 +6,17 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
6
6
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
7
7
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
8
8
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
9
+ import { cx } from 'antd-style';
9
10
  import { useLayoutEffect } from 'react';
10
11
  import { useLexicalComposerContext } from "../../../editor-kernel/react/react-context";
11
12
  import { AutoCompletePlugin } from "../plugin";
12
- import { useStyles } from "./style";
13
+ import { styles } from "./style";
13
14
  var ReactAutoCompletePlugin = function ReactAutoCompletePlugin(_ref) {
14
15
  var onAutoComplete = _ref.onAutoComplete,
15
16
  delay = _ref.delay;
16
17
  var _useLexicalComposerCo = useLexicalComposerContext(),
17
18
  _useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
18
19
  editor = _useLexicalComposerCo2[0];
19
- var _useStyles = useStyles(),
20
- cx = _useStyles.cx,
21
- styles = _useStyles.styles;
22
20
  useLayoutEffect(function () {
23
21
  editor.registerPlugin(AutoCompletePlugin, {
24
22
  delay: delay,
@@ -1,4 +1,4 @@
1
- export declare const useStyles: (props?: unknown) => import("antd-style").ReturnStyles<{
2
- placeholderBlock: import("antd-style").SerializedStyles;
3
- placeholderInline: import("antd-style").SerializedStyles;
4
- }>;
1
+ export declare const styles: {
2
+ placeholderBlock: string;
3
+ placeholderInline: string;
4
+ };
@@ -1,7 +1,7 @@
1
1
  var _templateObject, _templateObject2;
2
2
  function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
3
- import { createStyles } from 'antd-style';
4
- export var useStyles = createStyles(function (_ref) {
3
+ import { createStaticStyles } from 'antd-style';
4
+ export var styles = createStaticStyles(function (_ref) {
5
5
  var css = _ref.css;
6
6
  return {
7
7
  placeholderBlock: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n opacity: 0.4;\n "]))),
@@ -6,11 +6,12 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
6
6
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
7
7
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
8
8
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
9
+ import { cx } from 'antd-style';
9
10
  import { useLayoutEffect } from 'react';
10
11
  import { useLexicalComposerContext } from "../../../editor-kernel/react/react-context";
11
12
  import { MarkdownPlugin } from "../../markdown/plugin";
12
13
  import { CodePlugin } from "../plugin";
13
- import { useStyles } from "./style";
14
+ import { styles } from "./style";
14
15
  var ReactCodePlugin = function ReactCodePlugin(_ref) {
15
16
  var className = _ref.className,
16
17
  _ref$enableHotkey = _ref.enableHotkey,
@@ -18,9 +19,6 @@ var ReactCodePlugin = function ReactCodePlugin(_ref) {
18
19
  var _useLexicalComposerCo = useLexicalComposerContext(),
19
20
  _useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
20
21
  editor = _useLexicalComposerCo2[0];
21
- var _useStyles = useStyles(),
22
- cx = _useStyles.cx,
23
- styles = _useStyles.styles;
24
22
  useLayoutEffect(function () {
25
23
  editor.registerPlugin(MarkdownPlugin);
26
24
  editor.registerPlugin(CodePlugin, {
@@ -1,3 +1,3 @@
1
- export declare const useStyles: (props?: unknown) => import("antd-style").ReturnStyles<{
2
- codeInline: import("antd-style").SerializedStyles;
3
- }>;
1
+ export declare const styles: {
2
+ codeInline: string;
3
+ };
@@ -1,10 +1,10 @@
1
1
  var _templateObject;
2
2
  function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
3
- import { createStyles } from 'antd-style';
4
- export var useStyles = createStyles(function (_ref) {
3
+ import { createStaticStyles } from 'antd-style';
4
+ export var styles = createStaticStyles(function (_ref) {
5
5
  var css = _ref.css,
6
- token = _ref.token;
6
+ cssVar = _ref.cssVar;
7
7
  return {
8
- codeInline: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: inline;\n\n margin-inline: 0.25em;\n padding-block: 0.2em;\n padding-inline: 0.4em;\n border: 1px solid var(--lobe-markdown-border-color);\n border-radius: 0.25em;\n\n font-family: ", ";\n font-size: 0.875em;\n line-height: 1;\n word-break: break-word;\n white-space: break-spaces;\n\n background: ", ";\n "])), token.fontFamilyCode, token.colorFillSecondary)
8
+ codeInline: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: inline;\n\n margin-inline: 0.25em;\n padding-block: 0.2em;\n padding-inline: 0.4em;\n border: 1px solid var(--lobe-markdown-border-color);\n border-radius: 0.25em;\n\n font-family: ", ";\n font-size: 0.875em;\n line-height: 1;\n word-break: break-word;\n white-space: break-spaces;\n\n background: ", ";\n "])), cssVar.fontFamilyCode, cssVar.colorFillSecondary)
9
9
  };
10
10
  });
@@ -1,16 +1,10 @@
1
- import { CodeNode } from '@lexical/code';
2
- import { LexicalEditor, LexicalNode } from 'lexical';
1
+ import { LexicalEditor } from 'lexical';
3
2
  export declare const CustomShikiTokenizer: {
4
- $tokenize: (codeNode: CodeNode, language?: string | undefined) => LexicalNode[];
3
+ $tokenize: (codeNode: import("@lexical/code").CodeNode, language?: string | undefined) => import("lexical").LexicalNode[];
5
4
  $tokenizeSerialized: (code: string, language?: string | undefined, theme?: string | {
6
5
  dark: string;
7
6
  light: string;
8
- } | undefined, defaultColorReplacements?: {
9
- current?: import("../plugin/FacadeShiki").AllColorReplacements | undefined;
10
7
  } | undefined) => import("lexical").SerializedLexicalNode[];
11
- defaultColorReplacements: {
12
- current?: import("../plugin/FacadeShiki").AllColorReplacements | undefined;
13
- } | undefined;
14
8
  defaultLanguage: string;
15
9
  defaultTheme: string | {
16
10
  dark: string;
@@ -20,7 +14,4 @@ export declare const CustomShikiTokenizer: {
20
14
  export declare const UPDATE_CODEBLOCK_LANG: import("lexical").LexicalCommand<{
21
15
  lang: string;
22
16
  }>;
23
- export declare const UPDATE_CODEBLOCK_COLOR_REPLACEMENTS: import("lexical").LexicalCommand<{
24
- colorReplacements?: import("../plugin/FacadeShiki").AllColorReplacements | undefined;
25
- }>;
26
17
  export declare function registerCodeCommand(editor: LexicalEditor): () => void;
@@ -1,37 +1,14 @@
1
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
5
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
6
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
7
1
  import { $isCodeNode } from '@lexical/code';
8
2
  import { $findMatchingParent } from '@lexical/utils';
9
- import { $getRoot, $getSelection, $isElementNode, $isRangeSelection, COMMAND_PRIORITY_EDITOR, createCommand } from 'lexical';
3
+ import { $getSelection, $isRangeSelection, COMMAND_PRIORITY_EDITOR, createCommand } from 'lexical';
10
4
  import { ShikiTokenizer } from "../plugin/CodeHighlighterShiki";
11
5
  export var CustomShikiTokenizer = {
12
6
  $tokenize: ShikiTokenizer.$tokenize,
13
7
  $tokenizeSerialized: ShikiTokenizer.$tokenizeSerialized,
14
- defaultColorReplacements: ShikiTokenizer.defaultColorReplacements,
15
8
  defaultLanguage: ShikiTokenizer.defaultLanguage,
16
9
  defaultTheme: ShikiTokenizer.defaultTheme
17
10
  };
18
11
  export var UPDATE_CODEBLOCK_LANG = createCommand('UPDATE_CODEBLOCK_LANG');
19
- export var UPDATE_CODEBLOCK_COLOR_REPLACEMENTS = createCommand('UPDATE_CODEBLOCK_COLOR_REPLACEMENTS');
20
- function getAllCodeNode(rootNode) {
21
- var codeNodes = [];
22
- var child = rootNode.getFirstChild();
23
- while (child !== null) {
24
- if ($isCodeNode(child)) {
25
- codeNodes.push(child);
26
- }
27
- if ($isElementNode(child)) {
28
- var subChildrenNodes = getAllCodeNode(child);
29
- codeNodes.push.apply(codeNodes, _toConsumableArray(subChildrenNodes));
30
- }
31
- child = child.getNextSibling();
32
- }
33
- return codeNodes;
34
- }
35
12
  export function registerCodeCommand(editor) {
36
13
  var unregisterLangCommand = editor.registerCommand(UPDATE_CODEBLOCK_LANG, function (payload) {
37
14
  CustomShikiTokenizer.defaultLanguage = payload.lang;
@@ -66,20 +43,7 @@ export function registerCodeCommand(editor) {
66
43
  return true;
67
44
  }, COMMAND_PRIORITY_EDITOR // Priority
68
45
  );
69
- var unregisterColorReplacementsCommand = editor.registerCommand(UPDATE_CODEBLOCK_COLOR_REPLACEMENTS, function (payload) {
70
- CustomShikiTokenizer.defaultColorReplacements = payload.colorReplacements;
71
- editor.update(function () {
72
- var codes = getAllCodeNode($getRoot());
73
- codes.forEach(function (code) {
74
- // Mark the code node as dirty to trigger re-highlighting with new color replacements
75
- code.markDirty();
76
- });
77
- });
78
- return true;
79
- }, COMMAND_PRIORITY_EDITOR // Priority
80
- );
81
46
  return function () {
82
47
  unregisterLangCommand();
83
- unregisterColorReplacementsCommand();
84
48
  };
85
49
  }
@@ -8,18 +8,12 @@
8
8
  import { CodeNode } from '@lexical/code';
9
9
  import type { LexicalEditor, LexicalNode } from 'lexical';
10
10
  import { INode } from "../../../editor-kernel/inode";
11
- import { AllColorReplacements } from './FacadeShiki';
12
11
  export interface Tokenizer {
13
12
  $tokenize(codeNode: CodeNode, language?: string): LexicalNode[];
14
13
  $tokenizeSerialized(code: string, language?: string, theme?: string | {
15
14
  dark: string;
16
15
  light: string;
17
- }, defaultColorReplacements?: {
18
- current?: AllColorReplacements;
19
16
  }): INode[];
20
- defaultColorReplacements?: {
21
- current?: AllColorReplacements;
22
- };
23
17
  defaultLanguage: string;
24
18
  defaultTheme: string | {
25
19
  dark: string;
@@ -17,19 +17,18 @@ import { mergeRegister } from '@lexical/utils';
17
17
  import { $createLineBreakNode, $createPoint, $createTabNode, $createTextNode, $getCaretRange, $getCaretRangeInDirection, $getNodeByKey, $getSelection, $getSiblingCaret, $getTextPointCaret, $insertNodes, $isLineBreakNode, $isRangeSelection, $isTabNode, $isTextNode, $normalizeCaret, $setSelectionFromCaretRange, COMMAND_PRIORITY_LOW, INDENT_CONTENT_COMMAND, INSERT_TAB_COMMAND, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_UP_COMMAND, KEY_TAB_COMMAND, MOVE_TO_END, MOVE_TO_START, OUTDENT_CONTENT_COMMAND, TextNode } from 'lexical';
18
18
  import { $getHighlightNodes, getHighlightSerializeNode, isCodeLanguageLoaded, isCodeThemeLoaded, loadCodeLanguage, loadCodeTheme } from "./FacadeShiki";
19
19
  import invariant from "./invariant";
20
- var DEFAULT_CODE_THEME = 'slack-ochin';
20
+ var DEFAULT_CODE_THEME = 'lobe-theme';
21
21
  export var ShikiTokenizer = {
22
22
  $tokenize: function $tokenize(codeNode, language) {
23
- return $getHighlightNodes(codeNode, language || this.defaultLanguage, this.defaultColorReplacements);
23
+ return $getHighlightNodes(codeNode, language || this.defaultLanguage);
24
24
  },
25
- $tokenizeSerialized: function $tokenizeSerialized(code, language, theme, defaultColorReplacements) {
25
+ $tokenizeSerialized: function $tokenizeSerialized(code, language, theme) {
26
26
  return getHighlightSerializeNode(code, language || this.defaultLanguage,
27
27
  // eslint-disable-next-line @typescript-eslint/no-use-before-define
28
28
  toCodeTheme({
29
29
  defaultTheme: theme || this.defaultTheme
30
- }), defaultColorReplacements || ShikiTokenizer.defaultColorReplacements);
30
+ }));
31
31
  },
32
- defaultColorReplacements: undefined,
33
32
  defaultLanguage: DEFAULT_CODE_LANGUAGE,
34
33
  defaultTheme: DEFAULT_CODE_THEME
35
34
  };
@@ -39,12 +39,8 @@ export declare function loadCodeTheme(theme: string, editor?: LexicalEditor, cod
39
39
  export declare function getCodeLanguageOptions(): [string, string][];
40
40
  export declare function getCodeThemeOptions(): [string, string][];
41
41
  export declare function normalizeCodeLanguage(language: string): string;
42
- export declare function getHighlightSerializeNode(code: string, language: string, theme?: string, colorReplacements?: {
43
- current?: AllColorReplacements;
44
- }): INode[];
45
- export declare function $getHighlightNodes(codeNode: CodeNode, language: string, colorReplacements?: {
46
- current?: AllColorReplacements;
47
- }): LexicalNode[];
42
+ export declare function getHighlightSerializeNode(code: string, language: string, theme?: string): INode[];
43
+ export declare function $getHighlightNodes(codeNode: CodeNode, language: string): LexicalNode[];
48
44
  /**
49
45
  * Extended version of $getHighlightNodes with additional options
50
46
  * @param codeNode - The CodeNode to highlight
@@ -52,7 +48,6 @@ export declare function $getHighlightNodes(codeNode: CodeNode, language: string,
52
48
  * @param options - Additional highlighting options
53
49
  */
54
50
  export interface HighlightOptions {
55
- colorReplacements?: AllColorReplacements;
56
51
  theme?: string;
57
52
  }
58
53
  export declare function $getHighlightNodesWithOptions(codeNode: CodeNode, language: string, options?: HighlightOptions): LexicalNode[];
@@ -1,7 +1,7 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
1
2
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
2
3
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
3
4
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
4
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
5
5
  /**
6
6
  * Copyright (c) Meta Platforms, Inc. and affiliates.
7
7
  *
@@ -11,6 +11,7 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
11
11
  */
12
12
 
13
13
  import { $createCodeHighlightNode, $isCodeNode } from '@lexical/code';
14
+ import { ShikiLobeTheme } from '@lobehub/ui';
14
15
  import { createHighlighterCoreSync, isSpecialLang, isSpecialTheme, stringifyTokenStyle } from '@shikijs/core';
15
16
  import { createJavaScriptRegexEngine } from '@shikijs/engine-javascript';
16
17
  import { $createLineBreakNode, $createTabNode, $getNodeByKey } from 'lexical';
@@ -24,39 +25,15 @@ var shiki = createHighlighterCoreSync({
24
25
  langs: [],
25
26
  themes: []
26
27
  });
28
+
29
+ // Load ShikiLobeTheme immediately after initialization
30
+ shiki.loadTheme(ShikiLobeTheme);
27
31
  function getDiffedLanguage(language) {
28
32
  var DIFF_LANGUAGE_REGEX = /^diff-([\w-]+)/i;
29
33
  var diffLanguageMatch = DIFF_LANGUAGE_REGEX.exec(language);
30
34
  return diffLanguageMatch ? diffLanguageMatch[1] : null;
31
35
  }
32
36
 
33
- /**
34
- * Type guard to check if color replacements are scoped by theme
35
- */
36
- function isScopedColorReplacements(colorReplacements) {
37
- // Check if any of the keys correspond to known theme names
38
- // or if the values are objects rather than strings
39
- var firstValue = Object.values(colorReplacements)[0];
40
- return _typeof(firstValue) === 'object' && firstValue !== null;
41
- }
42
-
43
- /**
44
- * Resolves color replacements for a specific theme
45
- * @param colorReplacements - The color replacements configuration
46
- * @param theme - The current theme name
47
- * @returns The resolved color replacements for the current theme
48
- */
49
- function resolveColorReplacements(colorReplacements, theme) {
50
- // Check if this is a scoped color replacements object
51
- if (isScopedColorReplacements(colorReplacements)) {
52
- // Return the color replacements for the specific theme, or empty object if not found
53
- return colorReplacements[theme] || {};
54
- }
55
-
56
- // Return the simple color replacements object as-is
57
- return colorReplacements;
58
- }
59
-
60
37
  /**
61
38
  * Creates a simple color replacement map
62
39
  * @param replacements - Object mapping from old color to new color
@@ -151,24 +128,41 @@ function _loadCodeTheme2() {
151
128
  return _regeneratorRuntime().wrap(function _callee$(_context) {
152
129
  while (1) switch (_context.prev = _context.next) {
153
130
  case 0:
154
- if (!isCodeThemeLoaded(theme)) {
155
- themeInfo = bundledThemesInfo.find(function (info) {
156
- return info.id === theme;
131
+ if (isCodeThemeLoaded(theme)) {
132
+ _context.next = 6;
133
+ break;
134
+ }
135
+ if (!(theme === 'lobe-theme')) {
136
+ _context.next = 4;
137
+ break;
138
+ }
139
+ // ShikiLobeTheme is already loaded in shiki instance initialization
140
+ if (editor && codeNodeKey) {
141
+ editor.update(function () {
142
+ var codeNode = $getNodeByKey(codeNodeKey);
143
+ if ($isCodeNode(codeNode)) {
144
+ codeNode.markDirty();
145
+ }
146
+ });
147
+ }
148
+ return _context.abrupt("return");
149
+ case 4:
150
+ themeInfo = bundledThemesInfo.find(function (info) {
151
+ return info.id === theme;
152
+ });
153
+ if (themeInfo) {
154
+ shiki.loadTheme(themeInfo.import()).then(function () {
155
+ if (editor && codeNodeKey) {
156
+ editor.update(function () {
157
+ var codeNode = $getNodeByKey(codeNodeKey);
158
+ if ($isCodeNode(codeNode)) {
159
+ codeNode.markDirty();
160
+ }
161
+ });
162
+ }
157
163
  });
158
- if (themeInfo) {
159
- shiki.loadTheme(themeInfo.import()).then(function () {
160
- if (editor && codeNodeKey) {
161
- editor.update(function () {
162
- var codeNode = $getNodeByKey(codeNodeKey);
163
- if ($isCodeNode(codeNode)) {
164
- codeNode.markDirty();
165
- }
166
- });
167
- }
168
- });
169
- }
170
164
  }
171
- case 1:
165
+ case 6:
172
166
  case "end":
173
167
  return _context.stop();
174
168
  }
@@ -228,7 +222,7 @@ function getTokenStyleObject(token) {
228
222
  }
229
223
  return style;
230
224
  }
231
- function mapTokensToLexicalSerialized(tokens, diff, colorReplacements) {
225
+ function mapTokensToLexicalSerialized(tokens, diff) {
232
226
  var nodes = [];
233
227
  tokens.forEach(function (line, idx) {
234
228
  if (idx) {
@@ -258,20 +252,7 @@ function mapTokensToLexicalSerialized(tokens, diff, colorReplacements) {
258
252
  nodes.push(INodeHelper.createLikeTextNode('tab', '\t'));
259
253
  }
260
254
  if (part !== '') {
261
- var _token$htmlStyle, _token$htmlStyle2;
262
255
  var node = INodeHelper.createLikeTextNode('code-highlight', part);
263
- if ((_token$htmlStyle = token.htmlStyle) !== null && _token$htmlStyle !== void 0 && _token$htmlStyle['--shiki-light'] && colorReplacements !== null && colorReplacements !== void 0 && colorReplacements['light']) {
264
- var newColor = colorReplacements['light'][token.htmlStyle['--shiki-light'].toLowerCase()];
265
- if (newColor) {
266
- token.htmlStyle['--shiki-light'] = newColor;
267
- }
268
- }
269
- if ((_token$htmlStyle2 = token.htmlStyle) !== null && _token$htmlStyle2 !== void 0 && _token$htmlStyle2['--shiki-dark'] && colorReplacements !== null && colorReplacements !== void 0 && colorReplacements['dark']) {
270
- var _newColor = colorReplacements['dark'][token.htmlStyle['--shiki-dark'].toLowerCase()];
271
- if (_newColor) {
272
- token.htmlStyle['--shiki-dark'] = _newColor;
273
- }
274
- }
275
256
  var style = stringifyTokenStyle(token.htmlStyle || getTokenStyleObject(token));
276
257
  node.style = style;
277
258
  nodes.push(node);
@@ -281,7 +262,7 @@ function mapTokensToLexicalSerialized(tokens, diff, colorReplacements) {
281
262
  });
282
263
  return nodes;
283
264
  }
284
- function mapTokensToLexicalStructure(tokens, diff, colorReplacements) {
265
+ function mapTokensToLexicalStructure(tokens, diff) {
285
266
  var nodes = [];
286
267
  tokens.forEach(function (line, idx) {
287
268
  if (idx) {
@@ -306,20 +287,7 @@ function mapTokensToLexicalStructure(tokens, diff, colorReplacements) {
306
287
  nodes.push($createTabNode());
307
288
  }
308
289
  if (part !== '') {
309
- var _token$htmlStyle3, _token$htmlStyle4;
310
290
  var node = $createCodeHighlightNode(part);
311
- if ((_token$htmlStyle3 = token.htmlStyle) !== null && _token$htmlStyle3 !== void 0 && _token$htmlStyle3['--shiki-light'] && colorReplacements !== null && colorReplacements !== void 0 && colorReplacements['light']) {
312
- var newColor = colorReplacements['light'][token.htmlStyle['--shiki-light'].toLowerCase()];
313
- if (newColor) {
314
- token.htmlStyle['--shiki-light'] = newColor;
315
- }
316
- }
317
- if ((_token$htmlStyle4 = token.htmlStyle) !== null && _token$htmlStyle4 !== void 0 && _token$htmlStyle4['--shiki-dark'] && colorReplacements !== null && colorReplacements !== void 0 && colorReplacements['dark']) {
318
- var _newColor2 = colorReplacements['dark'][token.htmlStyle['--shiki-dark'].toLowerCase()];
319
- if (_newColor2) {
320
- token.htmlStyle['--shiki-dark'] = _newColor2;
321
- }
322
- }
323
291
  var style = stringifyTokenStyle(token.htmlStyle || getTokenStyleObject(token));
324
292
  node.setStyle(style);
325
293
  nodes.push(node);
@@ -331,8 +299,7 @@ function mapTokensToLexicalStructure(tokens, diff, colorReplacements) {
331
299
  }
332
300
  var DIFF_LANGUAGE_REGEX = /^diff-([\w-]+)/i;
333
301
  export function getHighlightSerializeNode(code, language) {
334
- var theme = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'poimandres';
335
- var colorReplacements = arguments.length > 3 ? arguments[3] : undefined;
302
+ var theme = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'lobe-theme';
336
303
  // Implementation goes here
337
304
 
338
305
  var diffLanguageMatch = DIFF_LANGUAGE_REGEX.exec(language);
@@ -350,25 +317,14 @@ export function getHighlightSerializeNode(code, language) {
350
317
  lang: language,
351
318
  theme: themes[0]
352
319
  };
353
- var newColorReplacements = {};
354
- if (colorReplacements !== null && colorReplacements !== void 0 && colorReplacements.current && themes.length > 1) {
355
- if (colorReplacements.current[themes[0]]) {
356
- newColorReplacements['light'] = colorReplacements.current[themes[0]];
357
- }
358
- if (colorReplacements.current[themes[1]]) {
359
- newColorReplacements['dark'] = colorReplacements.current[themes[1]];
360
- }
361
- } else if (colorReplacements !== null && colorReplacements !== void 0 && colorReplacements.current) {
362
- options.colorReplacements = resolveColorReplacements(colorReplacements.current, themes[0]);
363
- }
364
320
  var tokensResult = shiki.codeToTokens(code, options);
365
321
  var tokens = tokensResult.tokens;
366
- return mapTokensToLexicalSerialized(tokens, !!diffLanguageMatch, newColorReplacements);
322
+ return mapTokensToLexicalSerialized(tokens, !!diffLanguageMatch);
367
323
  }
368
- export function $getHighlightNodes(codeNode, language, colorReplacements) {
324
+ export function $getHighlightNodes(codeNode, language) {
369
325
  var diffLanguageMatch = DIFF_LANGUAGE_REGEX.exec(language);
370
326
  var code = codeNode.getTextContent();
371
- var theme = codeNode.getTheme() || 'poimandres';
327
+ var theme = codeNode.getTheme() || 'lobe-theme';
372
328
  var themes = theme.split(' ');
373
329
 
374
330
  // Build the options for codeToTokens
@@ -383,17 +339,6 @@ export function $getHighlightNodes(codeNode, language, colorReplacements) {
383
339
  lang: language,
384
340
  theme: themes[0]
385
341
  };
386
- var newColorReplacements = {};
387
- if (colorReplacements !== null && colorReplacements !== void 0 && colorReplacements.current && themes.length > 1) {
388
- if (colorReplacements.current[themes[0]]) {
389
- newColorReplacements['light'] = colorReplacements.current[themes[0]];
390
- }
391
- if (colorReplacements.current[themes[1]]) {
392
- newColorReplacements['dark'] = colorReplacements.current[themes[1]];
393
- }
394
- } else if (colorReplacements !== null && colorReplacements !== void 0 && colorReplacements.current) {
395
- options.colorReplacements = resolveColorReplacements(colorReplacements.current, themes[0]);
396
- }
397
342
  var tokensResult = shiki.codeToTokens(code, options);
398
343
  var tokens = tokensResult.tokens;
399
344
  // let style = '';
@@ -406,7 +351,7 @@ export function $getHighlightNodes(codeNode, language, colorReplacements) {
406
351
  // if (codeNode.getStyle() !== style) {
407
352
  // codeNode.setStyle(style);
408
353
  // }
409
- return mapTokensToLexicalStructure(tokens, !!diffLanguageMatch, newColorReplacements);
354
+ return mapTokensToLexicalStructure(tokens, !!diffLanguageMatch);
410
355
  }
411
356
 
412
357
  /**
@@ -425,9 +370,7 @@ export function $getHighlightNodesWithOptions(codeNode, language, options) {
425
370
  };
426
371
  }
427
372
  try {
428
- return $getHighlightNodes(codeNode, language, {
429
- current: options === null || options === void 0 ? void 0 : options.colorReplacements
430
- });
373
+ return $getHighlightNodes(codeNode, language);
431
374
  } finally {
432
375
  // Restore original getTheme method
433
376
  if (options !== null && options !== void 0 && options.theme) {
@@ -1,10 +1,5 @@
1
1
  import { IEditorPluginConstructor } from "../../../types";
2
- import { AllColorReplacements } from './FacadeShiki';
3
2
  export interface CodeblockPluginOptions {
4
- /** Color replacements configuration for customizing theme colors */
5
- colorReplacements?: {
6
- current?: AllColorReplacements;
7
- };
8
3
  /** Shiki theme name to use for syntax highlighting */
9
4
  shikiTheme?: string | {
10
5
  dark: string;
@@ -62,7 +62,7 @@ export var CodeblockPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
62
62
  _inherits(CodeblockPlugin, _KernelPlugin);
63
63
  var _super = _createSuper(CodeblockPlugin);
64
64
  function CodeblockPlugin(kernel) {
65
- var _config$theme, _this$config, _this$config3;
65
+ var _config$theme, _this$config;
66
66
  var _this;
67
67
  var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
68
68
  _classCallCheck(this, CodeblockPlugin);
@@ -78,17 +78,13 @@ export var CodeblockPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
78
78
  var _this$config2;
79
79
  CustomShikiTokenizer.defaultTheme = (_this$config2 = _this.config) === null || _this$config2 === void 0 ? void 0 : _this$config2.shikiTheme;
80
80
  }
81
- if ((_this$config3 = _this.config) !== null && _this$config3 !== void 0 && _this$config3.colorReplacements) {
82
- var _this$config4;
83
- CustomShikiTokenizer.defaultColorReplacements = (_this$config4 = _this.config) === null || _this$config4 === void 0 ? void 0 : _this$config4.colorReplacements;
84
- }
85
81
  return _this;
86
82
  }
87
83
  _createClass(CodeblockPlugin, [{
88
84
  key: "onInit",
89
85
  value: function onInit(editor) {
90
- var _this$config5;
91
- if ((_this$config5 = this.config) !== null && _this$config5 !== void 0 && _this$config5.shikiTheme) {
86
+ var _this$config3;
87
+ if ((_this$config3 = this.config) !== null && _this$config3 !== void 0 && _this$config3.shikiTheme) {
92
88
  this.register(registerCodeHighlighting(editor, CustomShikiTokenizer));
93
89
  } else {
94
90
  this.register(registerCodeHighlighting(editor));
@@ -6,45 +6,28 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
6
6
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
7
7
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
8
8
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
9
- import { usePrevious } from 'ahooks';
10
- import { useEffect, useLayoutEffect, useRef } from 'react';
9
+ import { cx } from 'antd-style';
10
+ import { useLayoutEffect } from 'react';
11
11
  import { useLexicalComposerContext } from "../../../editor-kernel/react/react-context";
12
12
  import { MarkdownPlugin } from "../../markdown/plugin";
13
13
  import { CodeblockPlugin } from "../plugin";
14
- import { colorReplacements, useStyles } from "./style";
14
+ import { styles } from "./style";
15
15
  export var ReactCodeblockPlugin = function ReactCodeblockPlugin(_ref) {
16
16
  var theme = _ref.theme,
17
17
  shikiTheme = _ref.shikiTheme;
18
18
  var _useLexicalComposerCo = useLexicalComposerContext(),
19
19
  _useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
20
20
  editor = _useLexicalComposerCo2[0];
21
- var _useStyles = useStyles(),
22
- styles = _useStyles.styles,
23
- token = _useStyles.theme;
24
- var isDarkMode = token.isDarkMode;
25
- var prevStyles = usePrevious(styles);
26
- var colorReplacementsRef = useRef(colorReplacements);
21
+ var codeStyle = cx(styles.code);
27
22
  useLayoutEffect(function () {
28
23
  editor.registerPlugin(MarkdownPlugin);
29
24
  editor.registerPlugin(CodeblockPlugin, {
30
- colorReplacements: colorReplacementsRef,
31
- shikiTheme: shikiTheme || {
32
- dark: 'slack-dark',
33
- light: 'slack-ochin'
34
- },
35
- theme: theme || styles
25
+ shikiTheme: shikiTheme || 'lobe-theme',
26
+ theme: theme || {
27
+ code: styles.code
28
+ }
36
29
  });
37
- }, []);
38
- useEffect(function () {
39
- if (prevStyles !== null && prevStyles !== void 0 && prevStyles.code) {
40
- var _editor$getRootElemen;
41
- (_editor$getRootElemen = editor.getRootElement()) === null || _editor$getRootElemen === void 0 || _editor$getRootElemen.querySelectorAll('.' + (prevStyles === null || prevStyles === void 0 ? void 0 : prevStyles.code)).forEach(function (node) {
42
- node.classList.remove(prevStyles.code);
43
- node.classList.add(styles.code);
44
- });
45
- }
46
- editor.updateTheme('code', styles.code);
47
- }, [styles, isDarkMode, prevStyles]);
30
+ }, [codeStyle, editor, shikiTheme, theme]);
48
31
  return null;
49
32
  };
50
33
  ReactCodeblockPlugin.displayName = 'ReactCodeblockPlugin';
@@ -1,6 +1,4 @@
1
- import { AllColorReplacements } from "../plugin/FacadeShiki";
2
- export declare const useStyles: (props?: unknown) => import("antd-style").ReturnStyles<{
3
- code: import("antd-style").SerializedStyles;
4
- noBackground: import("antd-style").SerializedStyles;
5
- }>;
6
- export declare const colorReplacements: AllColorReplacements;
1
+ export declare const styles: {
2
+ code: string;
3
+ noBackground: string;
4
+ };