@antdv-next/x 1.1.3-beta.3 → 1.1.3-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.
@@ -1,4 +1,5 @@
1
1
  import { default as CodeHighlighter } from './CodeHighlighter';
2
2
  export { setupCodeHighlighter } from './shiki';
3
+ export type { CodeHighlighterLanguageLoader, SetupCodeHighlighterOptions, } from './shiki';
3
4
  export type { CodeHighlighterHeaderSlotScope, CodeHighlighterProps, CodeHighlighterRef, CodeHighlighterSemanticType, CodeHighlighterSlots, } from './interface';
4
5
  export default CodeHighlighter;
@@ -0,0 +1,3 @@
1
+ import { createHighlighterCore } from 'shiki/core';
2
+ export type CodeHighlighterInstance = Awaited<ReturnType<typeof createHighlighterCore>>;
3
+ export declare function createHighlighter(): Promise<import('shiki').HighlighterCore>;
@@ -0,0 +1,14 @@
1
+ import { createHighlighterCore } from "shiki/core";
2
+ import darkTheme from "shiki/dist/themes/vitesse-dark.mjs";
3
+ import lightTheme from "shiki/dist/themes/vitesse-light.mjs";
4
+ import { createJavaScriptRegexEngine } from "shiki/engine/javascript";
5
+ //#region components/code-highlighter/shiki-runtime.ts
6
+ function createHighlighter() {
7
+ return createHighlighterCore({
8
+ themes: [lightTheme, darkTheme],
9
+ langs: [],
10
+ engine: createJavaScriptRegexEngine()
11
+ });
12
+ }
13
+ //#endregion
14
+ export { createHighlighter };
@@ -1,15 +1,20 @@
1
- type LanguageLoader = (lang: string) => Promise<any>;
1
+ import { LanguageInput } from 'shiki';
2
+ export type CodeHighlighterLanguageLoader = (lang: string) => Promise<LanguageInput | null>;
3
+ export interface SetupCodeHighlighterOptions {
4
+ loadLanguage?: CodeHighlighterLanguageLoader;
5
+ }
2
6
  /**
3
- * 注入自定义语言加载器,覆盖默认内置白名单。
7
+ * 注入自定义语言加载器。返回 `null` 时回退到默认内置白名单。
4
8
  * 建议按需 `import` 语言模块,避免引入全量语言包。
5
9
  *
6
10
  * @example 按需加载额外语言
7
11
  * ```ts
8
12
  * import { setupCodeHighlighter } from "@antdv-next/x";
13
+ * import type { LanguageInput } from "shiki";
9
14
  *
10
15
  * setupCodeHighlighter({
11
16
  * loadLanguage: async (lang) => {
12
- * const loaders: Record<string, () => Promise<{ default: any }>> = {
17
+ * const loaders: Record<string, () => Promise<{ default: LanguageInput }>> = {
13
18
  * go: () => import("shiki/dist/langs/go.mjs"),
14
19
  * rust: () => import("shiki/dist/langs/rust.mjs"),
15
20
  * };
@@ -19,11 +24,8 @@ type LanguageLoader = (lang: string) => Promise<any>;
19
24
  * });
20
25
  * ```
21
26
  */
22
- export declare function setupCodeHighlighter(options: {
23
- loadLanguage?: LanguageLoader;
24
- }): void;
27
+ export declare function setupCodeHighlighter(options?: SetupCodeHighlighterOptions): void;
25
28
  export declare function codeToHtml(code: string, options?: {
26
29
  lang?: string;
27
30
  theme?: string;
28
31
  }): Promise<string>;
29
- export {};
@@ -1,7 +1,3 @@
1
- import { createHighlighterCore } from "shiki/core";
2
- import darkTheme from "shiki/dist/themes/vitesse-dark.mjs";
3
- import lightTheme from "shiki/dist/themes/vitesse-light.mjs";
4
- import { createJavaScriptRegexEngine } from "shiki/engine/javascript";
5
1
  //#region components/code-highlighter/shiki.ts
6
2
  var PLAIN_TEXT_LANGUAGES = new Set([
7
3
  "text",
@@ -31,18 +27,19 @@ var defaultLoader = async (lang) => {
31
27
  const loader = BUILTIN_LANGUAGES[BUILTIN_ALIASES[lang] ?? lang];
32
28
  return loader ? (await loader()).default : null;
33
29
  };
34
- var activeLoader = defaultLoader;
30
+ var customLoader = null;
35
31
  /**
36
- * 注入自定义语言加载器,覆盖默认内置白名单。
32
+ * 注入自定义语言加载器。返回 `null` 时回退到默认内置白名单。
37
33
  * 建议按需 `import` 语言模块,避免引入全量语言包。
38
34
  *
39
35
  * @example 按需加载额外语言
40
36
  * ```ts
41
37
  * import { setupCodeHighlighter } from "@antdv-next/x";
38
+ * import type { LanguageInput } from "shiki";
42
39
  *
43
40
  * setupCodeHighlighter({
44
41
  * loadLanguage: async (lang) => {
45
- * const loaders: Record<string, () => Promise<{ default: any }>> = {
42
+ * const loaders: Record<string, () => Promise<{ default: LanguageInput }>> = {
46
43
  * go: () => import("shiki/dist/langs/go.mjs"),
47
44
  * rust: () => import("shiki/dist/langs/rust.mjs"),
48
45
  * };
@@ -52,8 +49,9 @@ var activeLoader = defaultLoader;
52
49
  * });
53
50
  * ```
54
51
  */
55
- function setupCodeHighlighter(options) {
56
- if (options?.loadLanguage) activeLoader = options.loadLanguage;
52
+ function setupCodeHighlighter(options = {}) {
53
+ customLoader = options.loadLanguage ?? null;
54
+ failedLangs.clear();
57
55
  }
58
56
  var highlighter = null;
59
57
  var highlighterPromise = null;
@@ -68,11 +66,7 @@ function escapeHtml(str) {
68
66
  }
69
67
  async function getHighlighter() {
70
68
  if (highlighter) return highlighter;
71
- if (!highlighterPromise) highlighterPromise = createHighlighterCore({
72
- themes: [lightTheme, darkTheme],
73
- langs: [],
74
- engine: createJavaScriptRegexEngine()
75
- });
69
+ if (!highlighterPromise) highlighterPromise = import("./shiki-runtime.js").then(({ createHighlighter }) => createHighlighter());
76
70
  highlighter = await highlighterPromise;
77
71
  return highlighter;
78
72
  }
@@ -83,7 +77,7 @@ async function loadLang(lang) {
83
77
  if (pendingLoad) return pendingLoad;
84
78
  const loadPromise = (async () => {
85
79
  try {
86
- const registration = await activeLoader(lang);
80
+ const registration = await customLoader?.(lang) ?? await defaultLoader(lang);
87
81
  if (!registration) {
88
82
  failedLangs.add(lang);
89
83
  return false;
package/dist/index.d.ts CHANGED
@@ -34,7 +34,7 @@ export type { ThoughtChainItemProps, ThoughtChainItemStatus, ThoughtChainItemTyp
34
34
  export type { ConversationItemType, ConversationsProps, ConversationsRef, CreationProps, DividerItemType, GroupableProps, } from './conversations';
35
35
  export type { SourcesProps } from './sources';
36
36
  export type { WelcomeProps, WelcomeRef } from './welcome';
37
- export type { CodeHighlighterProps, CodeHighlighterRef, CodeHighlighterSemanticType, } from './code-highlighter';
37
+ export type { CodeHighlighterLanguageLoader, CodeHighlighterProps, CodeHighlighterRef, CodeHighlighterSemanticType, SetupCodeHighlighterOptions, } from './code-highlighter';
38
38
  export { setupCodeHighlighter } from './code-highlighter';
39
39
  export type { SenderProps, SenderRef } from './sender';
40
40
  export type { RenderChildrenProps, SuggestionItem, SuggestionProps, } from './suggestion';
package/dist/index.umd.js CHANGED
@@ -29,6 +29,16 @@
29
29
  var __getOwnPropNames = Object.getOwnPropertyNames;
30
30
  var __getProtoOf = Object.getPrototypeOf;
31
31
  var __hasOwnProp = Object.prototype.hasOwnProperty;
32
+ var __esmMin = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
33
+ var __exportAll = (all, no_symbols) => {
34
+ let target = {};
35
+ for (var name in all) __defProp(target, name, {
36
+ get: all[name],
37
+ enumerable: true
38
+ });
39
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
40
+ return target;
41
+ };
32
42
  var __copyProps = (to, from, except, desc) => {
33
43
  if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
34
44
  key = keys[i];
@@ -49,7 +59,7 @@
49
59
  shiki_dist_themes_vitesse_dark_mjs = __toESM(shiki_dist_themes_vitesse_dark_mjs);
50
60
  shiki_dist_themes_vitesse_light_mjs = __toESM(shiki_dist_themes_vitesse_light_mjs);
51
61
  //#region package.json
52
- var version = "1.1.3-beta.3";
62
+ var version = "1.1.3-beta.5";
53
63
  //#endregion
54
64
  //#region components/x-provider/context.ts
55
65
  var XProviderContextKey = Symbol("antdv-next-x-provider-context");
@@ -4754,6 +4764,17 @@
4754
4764
  BubbleWithSub.System = XBubbleSystem;
4755
4765
  BubbleWithSub.Divider = XBubbleDivider;
4756
4766
  //#endregion
4767
+ //#region components/code-highlighter/shiki-runtime.ts
4768
+ var shiki_runtime_exports = /* @__PURE__ */ __exportAll({ createHighlighter: () => createHighlighter });
4769
+ function createHighlighter() {
4770
+ return (0, shiki_core.createHighlighterCore)({
4771
+ themes: [shiki_dist_themes_vitesse_light_mjs.default, shiki_dist_themes_vitesse_dark_mjs.default],
4772
+ langs: [],
4773
+ engine: (0, shiki_engine_javascript.createJavaScriptRegexEngine)()
4774
+ });
4775
+ }
4776
+ var init_shiki_runtime = __esmMin((() => {}));
4777
+ //#endregion
4757
4778
  //#region components/code-highlighter/shiki.ts
4758
4779
  var PLAIN_TEXT_LANGUAGES = new Set([
4759
4780
  "text",
@@ -4783,18 +4804,19 @@
4783
4804
  const loader = BUILTIN_LANGUAGES[BUILTIN_ALIASES[lang] ?? lang];
4784
4805
  return loader ? (await loader()).default : null;
4785
4806
  };
4786
- var activeLoader = defaultLoader;
4807
+ var customLoader = null;
4787
4808
  /**
4788
- * 注入自定义语言加载器,覆盖默认内置白名单。
4809
+ * 注入自定义语言加载器。返回 `null` 时回退到默认内置白名单。
4789
4810
  * 建议按需 `import` 语言模块,避免引入全量语言包。
4790
4811
  *
4791
4812
  * @example 按需加载额外语言
4792
4813
  * ```ts
4793
4814
  * import { setupCodeHighlighter } from "@antdv-next/x";
4815
+ * import type { LanguageInput } from "shiki";
4794
4816
  *
4795
4817
  * setupCodeHighlighter({
4796
4818
  * loadLanguage: async (lang) => {
4797
- * const loaders: Record<string, () => Promise<{ default: any }>> = {
4819
+ * const loaders: Record<string, () => Promise<{ default: LanguageInput }>> = {
4798
4820
  * go: () => import("shiki/dist/langs/go.mjs"),
4799
4821
  * rust: () => import("shiki/dist/langs/rust.mjs"),
4800
4822
  * };
@@ -4804,8 +4826,9 @@
4804
4826
  * });
4805
4827
  * ```
4806
4828
  */
4807
- function setupCodeHighlighter(options) {
4808
- if (options?.loadLanguage) activeLoader = options.loadLanguage;
4829
+ function setupCodeHighlighter(options = {}) {
4830
+ customLoader = options.loadLanguage ?? null;
4831
+ failedLangs.clear();
4809
4832
  }
4810
4833
  var highlighter = null;
4811
4834
  var highlighterPromise = null;
@@ -4820,11 +4843,7 @@
4820
4843
  }
4821
4844
  async function getHighlighter() {
4822
4845
  if (highlighter) return highlighter;
4823
- if (!highlighterPromise) highlighterPromise = (0, shiki_core.createHighlighterCore)({
4824
- themes: [shiki_dist_themes_vitesse_light_mjs.default, shiki_dist_themes_vitesse_dark_mjs.default],
4825
- langs: [],
4826
- engine: (0, shiki_engine_javascript.createJavaScriptRegexEngine)()
4827
- });
4846
+ if (!highlighterPromise) highlighterPromise = Promise.resolve().then(() => (init_shiki_runtime(), shiki_runtime_exports)).then(({ createHighlighter }) => createHighlighter());
4828
4847
  highlighter = await highlighterPromise;
4829
4848
  return highlighter;
4830
4849
  }
@@ -4835,7 +4854,7 @@
4835
4854
  if (pendingLoad) return pendingLoad;
4836
4855
  const loadPromise = (async () => {
4837
4856
  try {
4838
- const registration = await activeLoader(lang);
4857
+ const registration = await customLoader?.(lang) ?? await defaultLoader(lang);
4839
4858
  if (!registration) {
4840
4859
  failedLangs.add(lang);
4841
4860
  return false;
@@ -11352,6 +11371,7 @@
11352
11371
  top: (0, _antdv_next_cssinjs.unit)(calc(iconSize).mul(token.lineHeight).equal())
11353
11372
  }
11354
11373
  },
11374
+ [`${componentCls}-node-icon-none`]: { "&:after": { display: "none" } },
11355
11375
  [`${componentCls}-node-icon-dashed`]: { "&:after": { borderInlineStart: `${(0, _antdv_next_cssinjs.unit)(token.lineWidth)} dashed ${token.colorFillContent}` } },
11356
11376
  [`${componentCls}-node-icon-dotted`]: { "&:after": { borderInlineStart: `${(0, _antdv_next_cssinjs.unit)(token.lineWidth)} dotted ${token.colorFillContent}` } },
11357
11377
  [`${componentCls}-node-index-icon`]: {
@@ -11571,17 +11591,13 @@
11571
11591
  type: Number,
11572
11592
  required: true
11573
11593
  },
11574
- isLast: {
11575
- type: Boolean,
11576
- default: false
11577
- },
11578
11594
  prefixCls: {
11579
11595
  type: String,
11580
11596
  required: true
11581
11597
  },
11582
11598
  lineStyle: {
11583
11599
  type: [Boolean, String],
11584
- default: "solid"
11600
+ default: true
11585
11601
  },
11586
11602
  expanded: {
11587
11603
  type: Boolean,
@@ -11621,11 +11637,6 @@
11621
11637
  const configCtx = (0, antdv_next_config_provider_context.useConfig)();
11622
11638
  const isRtl = (0, vue.computed)(() => configCtx.value.direction === "rtl");
11623
11639
  const nodePrefixCls = (0, vue.computed)(() => `${props.prefixCls}-node`);
11624
- const resolvedLineStyle = (0, vue.computed)(() => {
11625
- if (props.lineStyle === false || props.isLast) return "none";
11626
- if (props.lineStyle === true) return "solid";
11627
- return props.lineStyle;
11628
- });
11629
11640
  const statusCls = (0, vue.computed)(() => `${props.prefixCls}-status`);
11630
11641
  const createSharedSlotInfo = (collapsible) => ({
11631
11642
  item: props.item,
@@ -11651,7 +11662,8 @@
11651
11662
  props.classes?.itemIcon,
11652
11663
  {
11653
11664
  [`${statusCls.value}-${item.status}`]: item.status,
11654
- [`${nodePrefixCls.value}-icon-${resolvedLineStyle.value}`]: typeof props.lineStyle !== "boolean" && resolvedLineStyle.value !== "none"
11665
+ [`${nodePrefixCls.value}-icon-${props.lineStyle}`]: typeof props.lineStyle === "string",
11666
+ [`${nodePrefixCls.value}-icon-none`]: props.lineStyle === false
11655
11667
  }
11656
11668
  ],
11657
11669
  "style": props.styles?.itemIcon
@@ -11805,7 +11817,7 @@
11805
11817
  },
11806
11818
  line: {
11807
11819
  type: [Boolean, String],
11808
- default: "solid"
11820
+ default: true
11809
11821
  }
11810
11822
  },
11811
11823
  emits: ["update:expandedKeys", "expand"],
@@ -11887,7 +11899,6 @@
11887
11899
  "key": key,
11888
11900
  "item": item,
11889
11901
  "index": index,
11890
- "isLast": index === items.length - 1,
11891
11902
  "prefixCls": prefixCls.value,
11892
11903
  "lineStyle": props.line,
11893
11904
  "expanded": mergedExpandedKeys.value.includes(key),
package/dist/package.js CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var version = "1.1.3-beta.3";
2
+ var version = "1.1.3-beta.5";
3
3
  //#endregion
4
4
  export { version };
@@ -9,17 +9,13 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
9
9
  type: NumberConstructor;
10
10
  required: true;
11
11
  };
12
- isLast: {
13
- type: BooleanConstructor;
14
- default: boolean;
15
- };
16
12
  prefixCls: {
17
13
  type: StringConstructor;
18
14
  required: true;
19
15
  };
20
16
  lineStyle: {
21
17
  type: PropType<boolean | "solid" | "dashed" | "dotted">;
22
- default: string;
18
+ default: boolean;
23
19
  };
24
20
  expanded: {
25
21
  type: BooleanConstructor;
@@ -62,17 +58,13 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
62
58
  type: NumberConstructor;
63
59
  required: true;
64
60
  };
65
- isLast: {
66
- type: BooleanConstructor;
67
- default: boolean;
68
- };
69
61
  prefixCls: {
70
62
  type: StringConstructor;
71
63
  required: true;
72
64
  };
73
65
  lineStyle: {
74
66
  type: PropType<boolean | "solid" | "dashed" | "dotted">;
75
- default: string;
67
+ default: boolean;
76
68
  };
77
69
  expanded: {
78
70
  type: BooleanConstructor;
@@ -115,7 +107,6 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
115
107
  descriptionRenderSlot: ((info: ThoughtChainDescriptionSlotInfo) => VNodeChild) | undefined;
116
108
  iconRenderSlot: ((info: ThoughtChainIconSlotInfo) => VNodeChild) | undefined;
117
109
  titleRenderSlot: ((info: ThoughtChainTitleSlotInfo) => VNodeChild) | undefined;
118
- isLast: boolean;
119
110
  lineStyle: boolean | "dashed" | "dotted" | "solid";
120
111
  contentRenderSlot: ((info: ThoughtChainContentSlotInfo) => VNodeChild) | undefined;
121
112
  footerRenderSlot: ((info: ThoughtChainFooterSlotInfo) => VNodeChild) | undefined;
@@ -15,17 +15,13 @@ var Node_default = /* @__PURE__ */ defineComponent({
15
15
  type: Number,
16
16
  required: true
17
17
  },
18
- isLast: {
19
- type: Boolean,
20
- default: false
21
- },
22
18
  prefixCls: {
23
19
  type: String,
24
20
  required: true
25
21
  },
26
22
  lineStyle: {
27
23
  type: [Boolean, String],
28
- default: "solid"
24
+ default: true
29
25
  },
30
26
  expanded: {
31
27
  type: Boolean,
@@ -65,11 +61,6 @@ var Node_default = /* @__PURE__ */ defineComponent({
65
61
  const configCtx = useConfig();
66
62
  const isRtl = computed(() => configCtx.value.direction === "rtl");
67
63
  const nodePrefixCls = computed(() => `${props.prefixCls}-node`);
68
- const resolvedLineStyle = computed(() => {
69
- if (props.lineStyle === false || props.isLast) return "none";
70
- if (props.lineStyle === true) return "solid";
71
- return props.lineStyle;
72
- });
73
64
  const statusCls = computed(() => `${props.prefixCls}-status`);
74
65
  const createSharedSlotInfo = (collapsible) => ({
75
66
  item: props.item,
@@ -95,7 +86,8 @@ var Node_default = /* @__PURE__ */ defineComponent({
95
86
  props.classes?.itemIcon,
96
87
  {
97
88
  [`${statusCls.value}-${item.status}`]: item.status,
98
- [`${nodePrefixCls.value}-icon-${resolvedLineStyle.value}`]: typeof props.lineStyle !== "boolean" && resolvedLineStyle.value !== "none"
89
+ [`${nodePrefixCls.value}-icon-${props.lineStyle}`]: typeof props.lineStyle === "string",
90
+ [`${nodePrefixCls.value}-icon-none`]: props.lineStyle === false
99
91
  }
100
92
  ],
101
93
  "style": props.styles?.itemIcon
@@ -39,7 +39,7 @@ export declare const XThoughtChain: import('vue').DefineComponent<import('vue').
39
39
  };
40
40
  line: {
41
41
  type: PropType<boolean | "solid" | "dashed" | "dotted">;
42
- default: string;
42
+ default: boolean;
43
43
  };
44
44
  }>, () => import("vue/jsx-runtime").JSX.Element, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, ("expand" | "update:expandedKeys")[], "expand" | "update:expandedKeys", import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
45
45
  prefixCls: {
@@ -80,7 +80,7 @@ export declare const XThoughtChain: import('vue').DefineComponent<import('vue').
80
80
  };
81
81
  line: {
82
82
  type: PropType<boolean | "solid" | "dashed" | "dotted">;
83
- default: string;
83
+ default: boolean;
84
84
  };
85
85
  }>> & Readonly<{
86
86
  onExpand?: ((...args: any[]) => any) | undefined;
@@ -54,7 +54,7 @@ var XThoughtChain = /* @__PURE__ */ defineComponent({
54
54
  },
55
55
  line: {
56
56
  type: [Boolean, String],
57
- default: "solid"
57
+ default: true
58
58
  }
59
59
  },
60
60
  emits: ["update:expandedKeys", "expand"],
@@ -136,7 +136,6 @@ var XThoughtChain = /* @__PURE__ */ defineComponent({
136
136
  "key": key,
137
137
  "item": item,
138
138
  "index": index,
139
- "isLast": index === items.length - 1,
140
139
  "prefixCls": prefixCls.value,
141
140
  "lineStyle": props.line,
142
141
  "expanded": mergedExpandedKeys.value.includes(key),
@@ -52,6 +52,7 @@ var genThoughtChainStyle = (token) => {
52
52
  top: unit(calc(iconSize).mul(token.lineHeight).equal())
53
53
  }
54
54
  },
55
+ [`${componentCls}-node-icon-none`]: { "&:after": { display: "none" } },
55
56
  [`${componentCls}-node-icon-dashed`]: { "&:after": { borderInlineStart: `${unit(token.lineWidth)} dashed ${token.colorFillContent}` } },
56
57
  [`${componentCls}-node-icon-dotted`]: { "&:after": { borderInlineStart: `${unit(token.lineWidth)} dotted ${token.colorFillContent}` } },
57
58
  [`${componentCls}-node-index-icon`]: {