@yuntijs/ui 1.1.0-beta.3 → 1.1.0-beta.5
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/es/Mentions/index.js +0 -12
- package/es/hooks/useHighlight.d.ts +1 -3
- package/es/hooks/useHighlight.js +65 -67
- package/package.json +2 -1
- package/umd/index.min.js +1 -1
- package/umd/index.min.js.map +1 -1
package/es/Mentions/index.js
CHANGED
|
@@ -120,18 +120,6 @@ export var Mentions = function Mentions(_ref) {
|
|
|
120
120
|
return document.fullscreenElement;
|
|
121
121
|
}
|
|
122
122
|
}, [getPopContainer]);
|
|
123
|
-
if (!isBrowser) {
|
|
124
|
-
return /*#__PURE__*/_jsxs("div", {
|
|
125
|
-
className: cx(styles.wrapper, classNames === null || classNames === void 0 ? void 0 : classNames.wrapper),
|
|
126
|
-
children: [/*#__PURE__*/_jsx("div", {
|
|
127
|
-
className: cx(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, styles.root, true), styles.filled, variant === 'filled'), styles.borderless, variant === 'borderless'), styles.disabled, disabled), className),
|
|
128
|
-
style: style || {}
|
|
129
|
-
}), /*#__PURE__*/_jsx("div", {
|
|
130
|
-
className: styles.placeholder,
|
|
131
|
-
children: placeholder || "\u8F93\u5165 ".concat(triggers.join(' 或 '), " \u63D2\u5165\u5F15\u7528")
|
|
132
|
-
})]
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
123
|
return /*#__PURE__*/_jsx(LexicalComposer, {
|
|
136
124
|
initialConfig: _objectSpread(_objectSpread({}, initialConfig), {}, {
|
|
137
125
|
editable: editable
|
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
export declare const FALLBACK_LANG = "txt";
|
|
2
|
-
export declare const useHighlight: (text: string, lang: string,
|
|
3
|
-
revalidateOnFocus: false;
|
|
4
|
-
}>;
|
|
2
|
+
export declare const useHighlight: (text: string, lang: string, enableTransformer?: boolean) => import("swr/dist/_internal").SWRResponse<string, any, any>;
|
|
5
3
|
export { languageMap } from './languageMap';
|
package/es/hooks/useHighlight.js
CHANGED
|
@@ -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 {
|
|
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 {
|
|
8
|
+
import { Md5 } from 'ts-md5';
|
|
7
9
|
import { languageMap } from "./languageMap";
|
|
8
10
|
export var FALLBACK_LANG = 'txt';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
_context.
|
|
29
|
-
|
|
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.1.0-beta.
|
|
3
|
+
"version": "1.1.0-beta.5",
|
|
4
4
|
"description": "☁️ Yunti UI - an open-source UI component library for building Cloud Native web apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"yuntijs",
|
|
@@ -104,6 +104,7 @@
|
|
|
104
104
|
"react18-json-view": "^0.2.8",
|
|
105
105
|
"shiki": "^3.2.1",
|
|
106
106
|
"swr": "^2.2.5",
|
|
107
|
+
"ts-md5": "^1.3.1",
|
|
107
108
|
"url-join": "^5.0.0",
|
|
108
109
|
"use-merge-value": "^1.2.0"
|
|
109
110
|
},
|