@aleph-alpha/chat-kit 6.2.0 → 6.4.0

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 (83) hide show
  1. package/dist/{CkHistory.vue_vue_type_script_setup_true_lang-DPCpIxWc.js → CkHistory.vue_vue_type_script_setup_true_lang-B0WUzTHa.js} +351 -164
  2. package/dist/chat-kit.css +111 -28
  3. package/dist/code-palette-DH_G7mZ5.js +21599 -0
  4. package/dist/components/base/CkCodeEditor/CkCodeEditor.stories.d.ts +49 -0
  5. package/dist/components/base/CkCodeEditor/CkCodeEditor.stories.d.ts.map +1 -0
  6. package/dist/components/base/CkCodeEditor/CkCodeEditor.vue.d.ts +40 -0
  7. package/dist/components/base/CkCodeEditor/CkCodeEditor.vue.d.ts.map +1 -0
  8. package/dist/components/base/CkCodeEditor/badgeDecoration.d.ts +47 -0
  9. package/dist/components/base/CkCodeEditor/badgeDecoration.d.ts.map +1 -0
  10. package/dist/components/base/CkCodeEditor/createCodeMirror.d.ts +48 -0
  11. package/dist/components/base/CkCodeEditor/createCodeMirror.d.ts.map +1 -0
  12. package/dist/components/base/CkCodeEditor/index.d.ts +3 -0
  13. package/dist/components/base/CkCodeEditor/index.d.ts.map +1 -0
  14. package/dist/components/base/CkCodeEditor/types.d.ts +149 -0
  15. package/dist/components/base/CkCodeEditor/types.d.ts.map +1 -0
  16. package/dist/components/base/CkMilkdownEditor/CkMilkdownEditor.stories.d.ts +6 -0
  17. package/dist/components/base/CkMilkdownEditor/CkMilkdownEditor.stories.d.ts.map +1 -1
  18. package/dist/components/base/CkMilkdownEditor/CkMilkdownEditor.vue.d.ts +1 -0
  19. package/dist/components/base/CkMilkdownEditor/CkMilkdownEditor.vue.d.ts.map +1 -1
  20. package/dist/components/base/CkMilkdownEditor/createCrepeEditor.d.ts +1 -0
  21. package/dist/components/base/CkMilkdownEditor/createCrepeEditor.d.ts.map +1 -1
  22. package/dist/components/base/CkMilkdownEditor/types.d.ts +8 -0
  23. package/dist/components/base/CkMilkdownEditor/types.d.ts.map +1 -1
  24. package/dist/components/base/index.d.ts +2 -0
  25. package/dist/components/base/index.d.ts.map +1 -1
  26. package/dist/components/index.d.ts +2 -2
  27. package/dist/components/index.d.ts.map +1 -1
  28. package/dist/components/index.js +27 -26
  29. package/dist/createCodeMirror-5iswYetS.js +169 -0
  30. package/dist/{createCrepeEditor-C9seqnzm.js → createCrepeEditor-C-AQ1w_e.js} +1433 -24739
  31. package/dist/handlers/index.js +1 -1
  32. package/dist/handlers/useChatKitLabels.d.ts +6 -0
  33. package/dist/handlers/useChatKitLabels.d.ts.map +1 -1
  34. package/dist/{components/base/CkMilkdownEditor/codeMirrorTheme.d.ts → helpers/codemirror/theme.d.ts} +1 -1
  35. package/dist/helpers/codemirror/theme.d.ts.map +1 -0
  36. package/dist/{index-DO8xk00f.js → index-ABUMl7H3.js} +3 -3
  37. package/dist/{index-DfvAv_Y2.js → index-BlIc9r0r.js} +3 -2
  38. package/dist/{index-VbqLf82s.js → index-BqWO6mvz.js} +4 -4
  39. package/dist/{index-Bxg0Q_mk.js → index-CFGO7LRz.js} +2 -2
  40. package/dist/index-CG8e3146.js +1825 -0
  41. package/dist/{index-C90_LSx6.js → index-CIF4qQzR.js} +4 -4
  42. package/dist/{index-DXTRMb09.js → index-CR2kGrpY.js} +3 -3
  43. package/dist/{index-B0nlcqqF.js → index-CWp_t8Wl.js} +2 -2
  44. package/dist/{index-CHtY7ztn.js → index-D0IZW-Up.js} +2 -2
  45. package/dist/{index-By7WdPbk.js → index-DKwEe_Tu.js} +4 -4
  46. package/dist/{index-DINJn4Mn.js → index-DLjsqQHx.js} +3 -3
  47. package/dist/{index-eZunhxNH.js → index-DPgw0Cf_.js} +2 -2
  48. package/dist/{index-D85elIIr.js → index-Db5-PJG-.js} +2 -2
  49. package/dist/{index-CFdcEeXx.js → index-Dbi75pKH.js} +3 -2
  50. package/dist/{index-8mYiDHFC.js → index-DfLCrnVq.js} +2 -2
  51. package/dist/{index-6PiPEjJd.js → index-GpSpJ3ti.js} +3 -2
  52. package/dist/{index-reQfKGuJ.js → index-Mh3WUU-6.js} +1 -1
  53. package/dist/{index-DLZcs4H8.js → index-QAs789O5.js} +2 -2
  54. package/dist/{index-DzpUblMx.js → index-S4ylc8JK.js} +3 -3
  55. package/dist/{index-DbVRgXxM.js → index-XZeturb3.js} +3 -3
  56. package/dist/{index-U4LYutvz.js → index-g2X42srv.js} +3 -2
  57. package/dist/{index-DNxEOsDD.js → index-hEJ_Bavx.js} +2 -2
  58. package/dist/{index-C5UC1wP7.js → index-hbS5PDHj.js} +3 -2
  59. package/dist/index.d.ts +2 -2
  60. package/dist/index.d.ts.map +1 -1
  61. package/dist/index.js +29 -28
  62. package/dist/{useChatKitLabels-Bz58tas9.js → useChatKitLabels-CatQSpfL.js} +2 -0
  63. package/package.json +4 -2
  64. package/src/components/base/CkCodeEditor/CkCodeEditor.spec.ts +284 -0
  65. package/src/components/base/CkCodeEditor/CkCodeEditor.stories.ts +405 -0
  66. package/src/components/base/CkCodeEditor/CkCodeEditor.vue +244 -0
  67. package/src/components/base/CkCodeEditor/badgeDecoration.ts +173 -0
  68. package/src/components/base/CkCodeEditor/createCodeMirror.ts +197 -0
  69. package/src/components/base/CkCodeEditor/index.ts +2 -0
  70. package/src/components/base/CkCodeEditor/types.ts +154 -0
  71. package/src/components/base/CkMilkdownEditor/CkMilkdownEditor.spec.ts +13 -0
  72. package/src/components/base/CkMilkdownEditor/CkMilkdownEditor.stories.ts +34 -0
  73. package/src/components/base/CkMilkdownEditor/CkMilkdownEditor.vue +3 -1
  74. package/src/components/base/CkMilkdownEditor/createCrepeEditor.ts +2 -1
  75. package/src/components/base/CkMilkdownEditor/milkdown-theme.css +39 -26
  76. package/src/components/base/CkMilkdownEditor/types.ts +8 -0
  77. package/src/components/base/index.ts +6 -0
  78. package/src/components/index.ts +4 -0
  79. package/src/handlers/useChatKitLabels.ts +6 -0
  80. package/src/helpers/codemirror/code-palette.css +49 -0
  81. package/src/{components/base/CkMilkdownEditor/codeMirrorTheme.ts → helpers/codemirror/theme.ts} +23 -12
  82. package/src/index.ts +4 -0
  83. package/dist/components/base/CkMilkdownEditor/codeMirrorTheme.d.ts.map +0 -1
@@ -0,0 +1,169 @@
1
+ import { J as MatchDecorator, D as Decoration, V as ViewPlugin, E as EditorView, W as WidgetType, K as EditorState, O as Compartment, Q as lineNumbers, U as languages, X as ckCodeMirrorTheme, Y as history, Z as drawSelection, _ as highlightSpecialChars, $ as highlightActiveLine, a0 as bracketMatching, a1 as indentOnInput, k as indentUnit, m as keymap, a2 as defaultKeymap, a3 as historyKeymap, a4 as indentWithTab, a5 as placeholder } from "./code-palette-DH_G7mZ5.js";
2
+ import { p as purify } from "./katex.min-md74IFlY.js";
3
+ const DEFAULT_BADGE_CLASS = "ck-code-badge inline-flex w-fit shrink-0 select-none items-center justify-center gap-1 overflow-hidden whitespace-nowrap rounded-md border border-border-surface-default bg-background-button-secondary-button text-content-on-surface-primary px-2 py-0.5 label-12-regular align-middle";
4
+ class BadgeWidget extends WidgetType {
5
+ constructor(content) {
6
+ super();
7
+ this.content = content;
8
+ }
9
+ // Decorations are rebuilt on every document and viewport change. Without a
10
+ // real comparison here every pill would be torn down and recreated on each
11
+ // keystroke, which flickers and drops any focus inside the widget.
12
+ eq(other) {
13
+ return other.content.label === this.content.label && other.content.icon === this.content.icon && other.content.title === this.content.title && other.content.class === this.content.class;
14
+ }
15
+ toDOM() {
16
+ const el = document.createElement("span");
17
+ el.className = this.content.class ?? DEFAULT_BADGE_CLASS;
18
+ if (this.content.title) el.title = this.content.title;
19
+ if (this.content.icon) {
20
+ const icon = document.createElement("span");
21
+ icon.className = "ck-code-badge__icon inline-flex shrink-0";
22
+ icon.innerHTML = purify.sanitize(this.content.icon, {
23
+ USE_PROFILES: { svg: true, svgFilters: true }
24
+ });
25
+ el.append(icon);
26
+ }
27
+ el.append(document.createTextNode(this.content.label));
28
+ return el;
29
+ }
30
+ /** The pill is decorative; let the editor handle every event over it. */
31
+ ignoreEvent() {
32
+ return false;
33
+ }
34
+ }
35
+ function toGlobal(pattern) {
36
+ const flags = pattern.flags.includes("g") ? pattern.flags : `${pattern.flags}g`;
37
+ return new RegExp(pattern.source, flags);
38
+ }
39
+ function badgeExtension(rule) {
40
+ const matcher = new MatchDecorator({
41
+ regexp: toGlobal(rule.pattern),
42
+ decoration: (match) => {
43
+ const content = rule.render(match);
44
+ return content ? Decoration.replace({ widget: new BadgeWidget(content) }) : null;
45
+ }
46
+ });
47
+ return ViewPlugin.fromClass(
48
+ class {
49
+ badges;
50
+ constructor(view) {
51
+ this.badges = matcher.createDeco(view);
52
+ }
53
+ update(update) {
54
+ this.badges = matcher.updateDeco(update, this.badges);
55
+ }
56
+ },
57
+ {
58
+ decorations: (plugin) => plugin.badges,
59
+ provide: (plugin) => EditorView.atomicRanges.of(
60
+ (view) => view.plugin(plugin)?.badges ?? Decoration.none
61
+ )
62
+ }
63
+ );
64
+ }
65
+ const PLAIN_ALIASES = /* @__PURE__ */ new Set(["text", "txt", "plain", "plaintext", ""]);
66
+ async function resolveLanguage(language) {
67
+ const id = language.trim().toLowerCase();
68
+ if (PLAIN_ALIASES.has(id)) return null;
69
+ const description = languages.find(
70
+ (candidate) => candidate.name.toLowerCase() === id || candidate.alias.includes(id) || candidate.extensions.includes(id)
71
+ );
72
+ if (!description) return null;
73
+ try {
74
+ return await description.load();
75
+ } catch {
76
+ return null;
77
+ }
78
+ }
79
+ function readonlyState(readonly) {
80
+ return [EditorState.readOnly.of(readonly), EditorView.editable.of(!readonly)];
81
+ }
82
+ function baseExtensions(options) {
83
+ return [
84
+ // Deliberately not CodeMirror's `basicSetup`: it also brings autocomplete,
85
+ // search, folding and bracket closing, none of which suit a snippet field,
86
+ // and its fold gutter would sit next to the line numbers.
87
+ history(),
88
+ drawSelection(),
89
+ highlightSpecialChars(),
90
+ highlightActiveLine(),
91
+ bracketMatching(),
92
+ indentOnInput(),
93
+ indentUnit.of(" "),
94
+ keymap.of([...defaultKeymap, ...historyKeymap, indentWithTab]),
95
+ ckCodeMirrorTheme,
96
+ EditorView.contentAttributes.of({
97
+ role: "textbox",
98
+ "aria-multiline": "true",
99
+ ...options.ariaLabel ? { "aria-label": options.ariaLabel } : {}
100
+ }),
101
+ EditorView.updateListener.of((update) => {
102
+ if (update.docChanged) options.onChange(update.state.doc.toString());
103
+ if (update.focusChanged) {
104
+ if (update.view.hasFocus) options.onFocus();
105
+ else options.onBlur();
106
+ }
107
+ }),
108
+ ...options.placeholder ? [placeholder(options.placeholder)] : []
109
+ ];
110
+ }
111
+ async function createCodeMirror(options) {
112
+ const languageSlot = new Compartment();
113
+ const readonlySlot = new Compartment();
114
+ const lineNumbersSlot = new Compartment();
115
+ const wrappingSlot = new Compartment();
116
+ const badgeSlot = new Compartment();
117
+ const support = await resolveLanguage(options.language);
118
+ const view = new EditorView({
119
+ parent: options.parent,
120
+ state: EditorState.create({
121
+ doc: options.doc,
122
+ extensions: [
123
+ ...baseExtensions(options),
124
+ languageSlot.of(support ? [support] : []),
125
+ readonlySlot.of(readonlyState(options.readonly)),
126
+ lineNumbersSlot.of(options.showLineNumbers ? lineNumbers() : []),
127
+ wrappingSlot.of(options.lineWrapping ? EditorView.lineWrapping : []),
128
+ badgeSlot.of(options.badge ? badgeExtension(options.badge) : [])
129
+ ]
130
+ })
131
+ });
132
+ function reconfigure(slot, extension) {
133
+ view.dispatch({ effects: slot.reconfigure(extension) });
134
+ }
135
+ return {
136
+ view,
137
+ getCode: () => view.state.doc.toString(),
138
+ setCode: (value) => {
139
+ if (value === view.state.doc.toString()) return;
140
+ const cursor = Math.min(view.state.selection.main.head, value.length);
141
+ view.dispatch({
142
+ changes: { from: 0, to: view.state.doc.length, insert: value },
143
+ selection: { anchor: cursor }
144
+ });
145
+ },
146
+ setLanguage: async (language) => {
147
+ const next = await resolveLanguage(language);
148
+ reconfigure(languageSlot, next ? [next] : []);
149
+ },
150
+ setReadonly: (readonly) => {
151
+ reconfigure(readonlySlot, readonlyState(readonly));
152
+ },
153
+ setShowLineNumbers: (show) => {
154
+ reconfigure(lineNumbersSlot, show ? lineNumbers() : []);
155
+ },
156
+ setLineWrapping: (wrap) => {
157
+ reconfigure(wrappingSlot, wrap ? EditorView.lineWrapping : []);
158
+ },
159
+ setBadge: (rule) => {
160
+ reconfigure(badgeSlot, rule ? badgeExtension(rule) : []);
161
+ },
162
+ focus: () => view.focus(),
163
+ destroy: () => view.destroy()
164
+ };
165
+ }
166
+ export {
167
+ createCodeMirror,
168
+ resolveLanguage
169
+ };