@lobehub/ui 1.106.0 → 1.106.2

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.
@@ -7,6 +7,11 @@ export interface ActionIconGroupItems {
7
7
  key: string;
8
8
  label: string;
9
9
  }
10
+ export interface ActionEvent {
11
+ item: ActionIconGroupItems;
12
+ key: string;
13
+ keyPath: string[];
14
+ }
10
15
  export interface ActionIconGroupProps extends DivProps {
11
16
  /**
12
17
  * @description The direction of the icons
@@ -24,7 +29,7 @@ export interface ActionIconGroupProps extends DivProps {
24
29
  * @default []
25
30
  */
26
31
  items?: ActionIconGroupItems[];
27
- onActionClick?: (key: string) => void;
32
+ onActionClick?: (action: ActionEvent) => void;
28
33
  /**
29
34
  * @description The position of the tooltip relative to the target
30
35
  * @enum ["top","left","right","bottom","topLeft","topRight","bottomLeft","bottomRight","leftTop","leftBottom","rightTop","rightBottom"]
@@ -37,7 +37,11 @@ var ActionIconGroup = /*#__PURE__*/memo(function (_ref) {
37
37
  return /*#__PURE__*/_jsx(ActionIcon, {
38
38
  icon: item.icon,
39
39
  onClick: onActionClick ? function () {
40
- return onActionClick === null || onActionClick === void 0 ? void 0 : onActionClick(item.key);
40
+ return onActionClick === null || onActionClick === void 0 ? void 0 : onActionClick({
41
+ item: item,
42
+ key: item.key,
43
+ keyPath: [item.key]
44
+ });
41
45
  } : undefined,
42
46
  placement: tooltipsPlacement,
43
47
  size: "small",
@@ -52,8 +56,12 @@ var ActionIconGroup = /*#__PURE__*/memo(function (_ref) {
52
56
  icon: item.icon,
53
57
  size: "small"
54
58
  }),
55
- onClick: onActionClick ? function () {
56
- return onActionClick(item.key);
59
+ onClick: onActionClick ? function (info) {
60
+ return onActionClick({
61
+ item: item,
62
+ key: info.key,
63
+ keyPath: info.keyPath
64
+ });
57
65
  } : undefined
58
66
  });
59
67
  })
@@ -1,10 +1,11 @@
1
1
  import { FC, ReactNode } from 'react';
2
+ import { ActionEvent } from "../ActionIconGroup";
2
3
  import { type ChatItemProps } from "../ChatItem";
3
4
  import { ChatMessage } from "../types/chatMessage";
4
5
  import { LLMRoleType } from "../types/llm";
5
6
  import { type ActionsBarProps } from './ActionsBar';
6
7
  export type OnMessageChange = (id: string, content: string) => void;
7
- export type OnActionClick = (props: ChatMessage) => void;
8
+ export type OnActionClick = (action: ActionEvent, message: ChatMessage) => void;
8
9
  export type RenderRole = LLMRoleType | 'default' | string;
9
10
  export type RenderItem = FC<{
10
11
  key: string;
@@ -21,9 +22,7 @@ export interface ListItemProps {
21
22
  /**
22
23
  * @description 点击操作按钮的回调函数
23
24
  */
24
- onActionsClick?: {
25
- [actionKey: string]: OnActionClick;
26
- };
25
+ onActionsClick?: OnActionClick;
27
26
  /**
28
27
  * @description 消息变化的回调函数
29
28
  */
@@ -5,7 +5,7 @@ var _excluded = ["renderMessagesExtra", "showTitle", "onActionsClick", "onMessag
5
5
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
6
6
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
7
7
  import { App } from 'antd';
8
- import _copy from 'copy-to-clipboard';
8
+ import copy from 'copy-to-clipboard';
9
9
  import { memo, useCallback, useMemo, useState } from 'react';
10
10
  import ChatItem from "../ChatItem";
11
11
  import ActionsBar from "./ActionsBar";
@@ -77,20 +77,24 @@ var Item = /*#__PURE__*/memo(function (props) {
77
77
  if (renderActions !== null && renderActions !== void 0 && renderActions[item.role]) RenderFunction = renderActions[item.role];
78
78
  if (renderActions !== null && renderActions !== void 0 && renderActions['default']) RenderFunction = renderActions['default'];
79
79
  if (!RenderFunction) RenderFunction = ActionsBar;
80
- var handleActionClick = _objectSpread({
81
- copy: function copy(_ref5) {
82
- var content = _ref5.content;
83
- _copy(content);
84
- message.success((text === null || text === void 0 ? void 0 : text.copySuccess) || 'Copy Success');
85
- },
86
- edit: function edit() {
87
- return setEditing(true);
80
+ var handleActionClick = function handleActionClick(action, data) {
81
+ switch (action.key) {
82
+ case 'copy':
83
+ {
84
+ copy(data.content);
85
+ message.success((text === null || text === void 0 ? void 0 : text.copySuccess) || 'Copy Success');
86
+ break;
87
+ }
88
+ case 'edit':
89
+ {
90
+ setEditing(true);
91
+ }
88
92
  }
89
- }, onActionsClick);
93
+ onActionsClick === null || onActionsClick === void 0 ? void 0 : onActionsClick(action, data);
94
+ };
90
95
  return /*#__PURE__*/_jsx(RenderFunction, _objectSpread(_objectSpread({}, data), {}, {
91
96
  onActionClick: function onActionClick(actionKey) {
92
- var _handleActionClick$ac;
93
- return handleActionClick === null || handleActionClick === void 0 ? void 0 : (_handleActionClick$ac = handleActionClick[actionKey]) === null || _handleActionClick$ac === void 0 ? void 0 : _handleActionClick$ac.call(handleActionClick, data);
97
+ return handleActionClick === null || handleActionClick === void 0 ? void 0 : handleActionClick(actionKey, data);
94
98
  },
95
99
  text: text
96
100
  }));
@@ -4,9 +4,8 @@ var _excluded = ["children", "customStylish", "customToken", "enableWebfonts", "
4
4
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
5
5
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
6
6
  import { App } from 'antd';
7
- import { ThemeProvider as AntdThemeProvider, StyleProvider, setupStyled } from 'antd-style';
8
- import { memo, useCallback, useEffect } from 'react';
9
- import { ThemeContext } from 'styled-components';
7
+ import { ThemeProvider as AntdThemeProvider, StyleProvider } from 'antd-style';
8
+ import { memo, useCallback } from 'react';
10
9
  import { useCdnFn } from "../ConfigProvider";
11
10
  import FontLoader from "../FontLoader";
12
11
  import { lobeCustomStylish, lobeCustomToken } from "../styles";
@@ -43,11 +42,6 @@ var ThemeProvider = /*#__PURE__*/memo(function (_ref) {
43
42
  pkg: 'katex',
44
43
  version: '0.16.8'
45
44
  })];
46
- useEffect(function () {
47
- setupStyled({
48
- ThemeContext: ThemeContext
49
- });
50
- }, []);
51
45
  var stylish = useCallback(function (theme) {
52
46
  return _objectSpread(_objectSpread({}, lobeCustomStylish(theme)), customStylish === null || customStylish === void 0 ? void 0 : customStylish(theme));
53
47
  }, [customStylish]);
@@ -1,3 +1,3 @@
1
- export declare const FALLBACK_LANG = "markdown";
2
- export declare const useHighlight: (text: string, language: string, isDarkMode: boolean) => import("swr/_internal").SWRResponse<string, any, any>;
1
+ export declare const FALLBACK_LANG = "txt";
2
+ export declare const useHighlight: (text: string, lang: string, isDarkMode: boolean) => import("swr/_internal").SWRResponse<string, any, any>;
3
3
  export { default as languageMap } from './languageMap';
@@ -3,33 +3,37 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
3
3
  import { getHighlighter } from 'shikiji';
4
4
  import useSWR from 'swr';
5
5
  import { themeConfig } from "../Highlighter/theme";
6
- export var FALLBACK_LANG = 'markdown';
6
+ import languageMap from "./languageMap";
7
+ export var FALLBACK_LANG = 'txt';
7
8
  var FALLBACK_LANGS = [FALLBACK_LANG];
8
9
  var cacheHighlighter;
9
10
  var initHighlighter = /*#__PURE__*/function () {
10
11
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(lang) {
11
- var highlighter;
12
+ var highlighter, language;
12
13
  return _regeneratorRuntime.wrap(function _callee$(_context) {
13
14
  while (1) switch (_context.prev = _context.next) {
14
15
  case 0:
15
16
  highlighter = cacheHighlighter;
16
- if (!(highlighter && FALLBACK_LANGS.includes(lang))) {
17
- _context.next = 5;
17
+ language = lang.toLowerCase();
18
+ if (!(highlighter && FALLBACK_LANGS.includes(language))) {
19
+ _context.next = 4;
18
20
  break;
19
21
  }
20
22
  return _context.abrupt("return", highlighter);
21
- case 5:
22
- FALLBACK_LANGS.push(lang);
23
- _context.next = 8;
23
+ case 4:
24
+ if (languageMap.includes(language) && !FALLBACK_LANGS.includes(language)) {
25
+ FALLBACK_LANGS.push(language);
26
+ }
27
+ _context.next = 7;
24
28
  return getHighlighter({
25
29
  langs: FALLBACK_LANGS,
26
30
  themes: [themeConfig(true), themeConfig(false)]
27
31
  });
28
- case 8:
32
+ case 7:
29
33
  highlighter = _context.sent;
30
34
  cacheHighlighter = highlighter;
31
35
  return _context.abrupt("return", highlighter);
32
- case 11:
36
+ case 10:
33
37
  case "end":
34
38
  return _context.stop();
35
39
  }
@@ -39,31 +43,32 @@ var initHighlighter = /*#__PURE__*/function () {
39
43
  return _ref.apply(this, arguments);
40
44
  };
41
45
  }();
42
- export var useHighlight = function useHighlight(text, language, isDarkMode) {
43
- return useSWR([text, language, Number(isDarkMode)].join('-'), /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
44
- var highlighter, html;
46
+ export var useHighlight = function useHighlight(text, lang, isDarkMode) {
47
+ return useSWR([lang.toLowerCase(), isDarkMode ? 'dark' : 'light', text].join('-'), /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
48
+ var language, highlighter, html;
45
49
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
46
50
  while (1) switch (_context2.prev = _context2.next) {
47
51
  case 0:
48
52
  _context2.prev = 0;
49
- _context2.next = 3;
53
+ language = lang.toLowerCase();
54
+ _context2.next = 4;
50
55
  return initHighlighter(language);
51
- case 3:
56
+ case 4:
52
57
  highlighter = _context2.sent;
53
58
  html = highlighter === null || highlighter === void 0 ? void 0 : highlighter.codeToHtml(text, {
54
- lang: language,
59
+ lang: languageMap.includes(language) ? language : FALLBACK_LANG,
55
60
  theme: isDarkMode ? 'dark' : 'light'
56
61
  });
57
62
  return _context2.abrupt("return", html);
58
- case 8:
59
- _context2.prev = 8;
63
+ case 9:
64
+ _context2.prev = 9;
60
65
  _context2.t0 = _context2["catch"](0);
61
66
  return _context2.abrupt("return", "<pre><code>".concat(text, "</code></pre>"));
62
- case 11:
67
+ case 12:
63
68
  case "end":
64
69
  return _context2.stop();
65
70
  }
66
- }, _callee2, null, [[0, 8]]);
71
+ }, _callee2, null, [[0, 9]]);
67
72
  })));
68
73
  };
69
74
  export { default as languageMap } from "./languageMap";
@@ -1,5 +1,4 @@
1
1
  import 'antd-style';
2
- import { AntdToken } from 'antd-style/lib/types/theme';
3
2
 
4
3
  import { LobeCustomStylish } from './customStylish';
5
4
  import { LobeCustomToken } from './customToken';
@@ -10,7 +9,3 @@ declare module 'antd-style' {
10
9
  // eslint-disable-next-line @typescript-eslint/no-empty-interface
11
10
  export interface CustomStylish extends LobeCustomStylish {}
12
11
  }
13
-
14
- declare module 'styled-components' {
15
- export interface DefaultTheme extends AntdToken, LobeCustomToken {}
16
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/ui",
3
- "version": "1.106.0",
3
+ "version": "1.106.2",
4
4
  "description": "Lobe UI is an open-source UI component library for building AIGC web apps",
5
5
  "keywords": [
6
6
  "lobehub",
@@ -105,7 +105,6 @@
105
105
  "remark-gfm": "^3",
106
106
  "remark-math": "^5",
107
107
  "shikiji": "^0",
108
- "styled-components": "^6",
109
108
  "swr": "^2",
110
109
  "three": "^0.150",
111
110
  "ts-md5": "^1",
@@ -143,6 +142,7 @@
143
142
  "remark": "^14",
144
143
  "remark-cli": "^11",
145
144
  "semantic-release": "^21",
145
+ "styled-components": "^6",
146
146
  "stylelint": "^15",
147
147
  "typescript": "^5",
148
148
  "vitest": "latest"