@yuntijs/ui 1.0.0 → 1.1.0-beta.10

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 (41) hide show
  1. package/es/ChatItem/index.js +3 -2
  2. package/es/ChatItem/style.js +3 -2
  3. package/es/ChatItem/type.d.ts +4 -0
  4. package/es/Form/collapse-list/index.js +16 -9
  5. package/es/Form/collapse-list/utils.d.ts +1 -0
  6. package/es/Form/collapse-list/utils.js +2 -1
  7. package/es/Mentions/index.d.ts +13 -3
  8. package/es/Mentions/index.js +33 -19
  9. package/es/Mentions/plugins/editor-ref.d.ts +5 -0
  10. package/es/Mentions/plugins/editor-ref.js +13 -0
  11. package/es/Mentions/plugins/mention-converter.d.ts +32 -0
  12. package/es/Mentions/plugins/mention-converter.js +151 -0
  13. package/es/Mentions/plugins/mention-node/component.js +1 -1
  14. package/es/Mentions/plugins/mention-picker/hooks.js +1 -0
  15. package/es/Mentions/plugins/mention-picker/index.d.ts +4 -0
  16. package/es/Mentions/plugins/mention-picker/index.js +54 -13
  17. package/es/Mentions/plugins/mention-picker/menu-item.js +19 -3
  18. package/es/Mentions/plugins/mention-picker/style.js +1 -1
  19. package/es/Mentions/plugins/mention-picker/utils.d.ts +3 -1
  20. package/es/Mentions/plugins/mention-picker/utils.js +3 -0
  21. package/es/Mentions/plugins/shift-enter-key.d.ts +6 -0
  22. package/es/Mentions/plugins/shift-enter-key.js +48 -0
  23. package/es/Mentions/style.d.ts +1 -0
  24. package/es/Mentions/style.js +4 -4
  25. package/es/Mentions/types.d.ts +1 -0
  26. package/es/Mentions/utils.d.ts +1 -1
  27. package/es/Mentions/utils.js +11 -30
  28. package/es/MonacoEditor/base/helper.d.ts +4 -0
  29. package/es/MonacoEditor/base/helper.js +13 -4
  30. package/es/MonacoEditor/base/index.d.ts +2 -2
  31. package/es/MonacoEditor/base/index.js +33 -10
  32. package/es/MonacoEditor/base/style.js +1 -1
  33. package/es/MonacoEditor/index.js +1 -1
  34. package/es/SelectCard/index.js +1 -1
  35. package/es/hooks/useHighlight.d.ts +1 -3
  36. package/es/hooks/useHighlight.js +65 -67
  37. package/package.json +5 -5
  38. package/umd/index.min.js +1 -1
  39. package/umd/index.min.js.map +1 -1
  40. /package/es/Mentions/plugins/{OnBlurBlockPlugin.d.ts → on-blur-block.d.ts} +0 -0
  41. /package/es/Mentions/plugins/{OnBlurBlockPlugin.js → on-blur-block.js} +0 -0
@@ -1,82 +1,80 @@
1
1
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
2
2
  import _regeneratorRuntime from "@babel/runtime/regenerator";
3
3
  import { transformerNotationDiff, transformerNotationErrorLevel, transformerNotationFocus, transformerNotationHighlight, transformerNotationWordHighlight } from '@shikijs/transformers';
4
- import { createHighlighter } from 'shiki';
4
+ import { useTheme, useThemeMode } from 'antd-style';
5
+ import { useMemo } from 'react';
6
+ import { codeToHtml } from 'shiki';
5
7
  import useSWR from 'swr';
6
- import { themeConfig } from "../Highlighter/theme";
8
+ import { Md5 } from 'ts-md5';
7
9
  import { languageMap } from "./languageMap";
8
10
  export var FALLBACK_LANG = 'txt';
9
- var FALLBACK_LANGS = [FALLBACK_LANG];
10
- var cacheHighlighter;
11
- var initHighlighter = /*#__PURE__*/function () {
12
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(lang) {
13
- var highlighter, language;
11
+
12
+ // @Todo: use worker to improve performance
13
+ export var useHighlight = function useHighlight(text, lang, enableTransformer) {
14
+ var _useThemeMode = useThemeMode(),
15
+ isDarkMode = _useThemeMode.isDarkMode;
16
+ var language = lang.toLowerCase();
17
+ var matchedLanguage = useMemo(function () {
18
+ return languageMap.includes(language) ? language : FALLBACK_LANG;
19
+ }, [language]);
20
+ var theme = useTheme();
21
+ var transformers = useMemo(function () {
22
+ if (!enableTransformer) return;
23
+ return [transformerNotationDiff(), transformerNotationHighlight(), transformerNotationWordHighlight(), transformerNotationFocus(), transformerNotationErrorLevel()];
24
+ }, [enableTransformer]);
25
+ var key = useMemo(function () {
26
+ return Md5.hashStr(text);
27
+ }, [text]);
28
+ var shikiTheme = useMemo(function () {
29
+ if (language === 'md') {
30
+ return isDarkMode ? 'catppuccin-mocha' : 'catppuccin-latte';
31
+ }
32
+ return isDarkMode ? 'slack-dark' : 'slack-ochin';
33
+ }, [isDarkMode, language]);
34
+ return useSWR([matchedLanguage, isDarkMode ? 'd' : 'l', key].join('-'), /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
14
35
  return _regeneratorRuntime.wrap(function _callee$(_context) {
15
36
  while (1) switch (_context.prev = _context.next) {
16
37
  case 0:
17
- highlighter = cacheHighlighter;
18
- language = lang.toLowerCase();
19
- if (!(highlighter && FALLBACK_LANGS.includes(language))) {
20
- _context.next = 4;
21
- break;
22
- }
23
- return _context.abrupt("return", highlighter);
38
+ _context.prev = 0;
39
+ return _context.abrupt("return", codeToHtml(text, {
40
+ colorReplacements: {
41
+ 'slack-dark': {
42
+ '#4ec9b0': theme.yellow,
43
+ '#569cd6': theme.colorError,
44
+ '#6a9955': theme.gray,
45
+ '#9cdcfe': theme.colorText,
46
+ '#b5cea8': theme.purple10,
47
+ '#c586c0': theme.colorInfo,
48
+ '#ce9178': theme.colorSuccess,
49
+ '#dcdcaa': theme.colorWarning,
50
+ '#e6e6e6': theme.colorText
51
+ },
52
+ 'slack-ochin': {
53
+ '#002339': theme.colorText,
54
+ '#0991b6': theme.colorError,
55
+ '#174781': theme.purple10,
56
+ '#2f86d2': theme.colorText,
57
+ '#357b42': theme.gray,
58
+ '#7b30d0': theme.colorInfo,
59
+ '#7eb233': theme.colorWarningTextActive,
60
+ '#a44185': theme.colorSuccess,
61
+ '#dc3eb7': theme.yellow11
62
+ }
63
+ },
64
+ lang: matchedLanguage,
65
+ theme: shikiTheme,
66
+ transformers: transformers
67
+ }));
24
68
  case 4:
25
- if (languageMap.includes(language) && !FALLBACK_LANGS.includes(language)) {
26
- FALLBACK_LANGS.push(language);
27
- }
28
- _context.next = 7;
29
- return createHighlighter({
30
- langs: FALLBACK_LANGS,
31
- themes: [themeConfig(true), themeConfig(false), 'catppuccin-latte', 'catppuccin-mocha']
32
- });
33
- case 7:
34
- highlighter = _context.sent;
35
- cacheHighlighter = highlighter;
36
- return _context.abrupt("return", highlighter);
37
- case 10:
69
+ _context.prev = 4;
70
+ _context.t0 = _context["catch"](0);
71
+ console.warn('shiki Highlight error:', _context.t0);
72
+ return _context.abrupt("return", text);
73
+ case 8:
38
74
  case "end":
39
75
  return _context.stop();
40
76
  }
41
- }, _callee);
42
- }));
43
- return function initHighlighter(_x) {
44
- return _ref.apply(this, arguments);
45
- };
46
- }();
47
- export var useHighlight = function useHighlight(text, lang, isDarkMode) {
48
- return useSWR([lang === null || lang === void 0 ? void 0 : lang.toLowerCase(), isDarkMode ? 'dark' : 'light', text].join('-'), /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
49
- var language, theme, highlighter, html;
50
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
51
- while (1) switch (_context2.prev = _context2.next) {
52
- case 0:
53
- _context2.prev = 0;
54
- language = lang.toLowerCase();
55
- theme = isDarkMode ? 'dark' : 'light';
56
- if (language === 'md') {
57
- theme = isDarkMode ? 'catppuccin-mocha' : 'catppuccin-latte';
58
- }
59
- _context2.next = 6;
60
- return initHighlighter(language);
61
- case 6:
62
- highlighter = _context2.sent;
63
- html = highlighter === null || highlighter === void 0 ? void 0 : highlighter.codeToHtml(text, {
64
- lang: languageMap.includes(language) ? language : FALLBACK_LANG,
65
- theme: theme,
66
- transformers: [transformerNotationDiff(), transformerNotationHighlight(), transformerNotationWordHighlight(), transformerNotationFocus(), transformerNotationErrorLevel()]
67
- });
68
- return _context2.abrupt("return", html);
69
- case 11:
70
- _context2.prev = 11;
71
- _context2.t0 = _context2["catch"](0);
72
- return _context2.abrupt("return", '');
73
- case 14:
74
- case "end":
75
- return _context2.stop();
76
- }
77
- }, _callee2, null, [[0, 11]]);
78
- })), {
79
- revalidateOnFocus: false
80
- });
77
+ }, _callee, null, [[0, 4]]);
78
+ })));
81
79
  };
82
80
  export { languageMap } from "./languageMap";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuntijs/ui",
3
- "version": "1.0.0",
3
+ "version": "1.1.0-beta.10",
4
4
  "description": "☁️ Yunti UI - an open-source UI component library for building Cloud Native web apps",
5
5
  "keywords": [
6
6
  "yuntijs",
@@ -80,7 +80,6 @@
80
80
  ]
81
81
  },
82
82
  "dependencies": {
83
- "@alilc/lowcode-plugin-base-monaco-editor": "^1.1.2",
84
83
  "@ant-design/icons": "^5",
85
84
  "@babel/runtime": "^7",
86
85
  "@lexical/react": "^0.23.1",
@@ -91,7 +90,7 @@
91
90
  "@lobehub/ui": "^1.164.2",
92
91
  "@melloware/react-logviewer": "^5.2.0",
93
92
  "@monaco-editor/loader": "^1.4.0",
94
- "@shikijs/transformers": "^1.10.3",
93
+ "@shikijs/transformers": "^3.2.1",
95
94
  "leva": "^0",
96
95
  "lexical": "^0.23.1",
97
96
  "lodash-es": "^4",
@@ -102,8 +101,9 @@
102
101
  "react-error-boundary": "^4",
103
102
  "react-layout-kit": "^1",
104
103
  "react18-json-view": "^0.2.8",
105
- "shiki": "^1.10.3",
104
+ "shiki": "^3.2.1",
106
105
  "swr": "^2.2.5",
106
+ "ts-md5": "^1.3.1",
107
107
  "url-join": "^5.0.0",
108
108
  "use-merge-value": "^1.2.0"
109
109
  },
@@ -130,7 +130,7 @@
130
130
  "jsdom": "^22",
131
131
  "lint-staged": "^15",
132
132
  "mdast-util-to-markdown": "^2.1.2",
133
- "monaco-editor": "^0.45.0",
133
+ "monaco-editor": "^0.52.2",
134
134
  "prettier": "^3",
135
135
  "react": "^18",
136
136
  "react-dom": "^18",