@cozeloop/prompt-components 0.0.1

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 (149) hide show
  1. package/README.md +1 -0
  2. package/dist/es/basic-editor/custom-facet.js +9 -0
  3. package/dist/es/basic-editor/diff.js +138 -0
  4. package/dist/es/basic-editor/extensions/go-syntax.js +122 -0
  5. package/dist/es/basic-editor/extensions/go-template.js +16 -0
  6. package/dist/es/basic-editor/extensions/go-theme.js +1071 -0
  7. package/dist/es/basic-editor/extensions/jinja.js +80 -0
  8. package/dist/es/basic-editor/extensions/keymap.js +442 -0
  9. package/dist/es/basic-editor/extensions/language-support.js +12 -0
  10. package/dist/es/basic-editor/extensions/markdown.js +58 -0
  11. package/dist/es/basic-editor/extensions/search/dom/icon.js +250 -0
  12. package/dist/es/basic-editor/extensions/search/dom/match-count.js +33 -0
  13. package/dist/es/basic-editor/extensions/search/index.js +18 -0
  14. package/dist/es/basic-editor/extensions/search/panel.js +418 -0
  15. package/dist/es/basic-editor/extensions/search/theme.js +184 -0
  16. package/dist/es/basic-editor/extensions/validation.js +84 -0
  17. package/dist/es/basic-editor/extensions/validation.module.js +5 -0
  18. package/dist/es/basic-editor/extensions/validation_module.css +7 -0
  19. package/dist/es/basic-editor/extensions/variable.js +178 -0
  20. package/dist/es/basic-editor/index.js +171 -0
  21. package/dist/es/code-editor/code-editor.js +83 -0
  22. package/dist/es/code-editor/index.js +12 -0
  23. package/dist/es/code-editor/json-editor.js +157 -0
  24. package/dist/es/code-editor/raw-text-editor.js +46 -0
  25. package/dist/es/code-editor/text-editor.js +41 -0
  26. package/dist/es/code-editor/themes/coze-dark.js +112 -0
  27. package/dist/es/code-editor/themes/coze-light.js +118 -0
  28. package/dist/es/consts/index.js +12 -0
  29. package/dist/es/dev-layout/index.js +35 -0
  30. package/dist/es/index.js +66 -0
  31. package/dist/es/mermaid-diagram/index.js +148 -0
  32. package/dist/es/mermaid-diagram/index.module.js +5 -0
  33. package/dist/es/mermaid-diagram/index_module.css +4 -0
  34. package/dist/es/mermaid-diagram/use-svg-pan-zoom.js +49 -0
  35. package/dist/es/mermaid-diagram/utils.js +74 -0
  36. package/dist/es/model-config-editor/basic-type.js +73 -0
  37. package/dist/es/model-config-editor/index.module.js +5 -0
  38. package/dist/es/model-config-editor/index_module.css +8 -0
  39. package/dist/es/model-config-editor/model-config-form.js +130 -0
  40. package/dist/es/model-config-editor/popover-type.js +118 -0
  41. package/dist/es/model-select/index.js +136 -0
  42. package/dist/es/model-select/index.module.js +5 -0
  43. package/dist/es/model-select/index_module.css +14 -0
  44. package/dist/es/model-select/model-option/index.js +161 -0
  45. package/dist/es/model-select/model-option/index.module.js +5 -0
  46. package/dist/es/model-select/model-option/index_module.css +23 -0
  47. package/dist/es/model-select/model-option-group/index.js +44 -0
  48. package/dist/es/prompt-editor/index.js +188 -0
  49. package/dist/es/prompt-editor/index.module.js +5 -0
  50. package/dist/es/prompt-editor/index_module.css +71 -0
  51. package/dist/es/prompt-editor/message-type-select.js +74 -0
  52. package/dist/es/schema-editor/index.js +43 -0
  53. package/dist/es/utils/base.js +53 -0
  54. package/dist/es/utils/model-config.js +32 -0
  55. package/dist/lib/basic-editor/custom-facet.js +33 -0
  56. package/dist/lib/basic-editor/diff.js +167 -0
  57. package/dist/lib/basic-editor/extensions/go-syntax.js +146 -0
  58. package/dist/lib/basic-editor/extensions/go-template.js +50 -0
  59. package/dist/lib/basic-editor/extensions/go-theme.js +1091 -0
  60. package/dist/lib/basic-editor/extensions/jinja.js +100 -0
  61. package/dist/lib/basic-editor/extensions/keymap.js +465 -0
  62. package/dist/lib/basic-editor/extensions/language-support.js +32 -0
  63. package/dist/lib/basic-editor/extensions/markdown.js +78 -0
  64. package/dist/lib/basic-editor/extensions/search/dom/icon.js +291 -0
  65. package/dist/lib/basic-editor/extensions/search/dom/match-count.js +67 -0
  66. package/dist/lib/basic-editor/extensions/search/index.js +38 -0
  67. package/dist/lib/basic-editor/extensions/search/panel.js +429 -0
  68. package/dist/lib/basic-editor/extensions/search/theme.js +208 -0
  69. package/dist/lib/basic-editor/extensions/validation.js +118 -0
  70. package/dist/lib/basic-editor/extensions/validation.module.js +25 -0
  71. package/dist/lib/basic-editor/extensions/validation_module.css +7 -0
  72. package/dist/lib/basic-editor/extensions/variable.js +190 -0
  73. package/dist/lib/basic-editor/index.js +193 -0
  74. package/dist/lib/code-editor/code-editor.js +117 -0
  75. package/dist/lib/code-editor/index.js +40 -0
  76. package/dist/lib/code-editor/json-editor.js +184 -0
  77. package/dist/lib/code-editor/raw-text-editor.js +70 -0
  78. package/dist/lib/code-editor/text-editor.js +75 -0
  79. package/dist/lib/code-editor/themes/coze-dark.js +136 -0
  80. package/dist/lib/code-editor/themes/coze-light.js +142 -0
  81. package/dist/lib/consts/index.js +38 -0
  82. package/dist/lib/dev-layout/index.js +69 -0
  83. package/dist/lib/index.js +110 -0
  84. package/dist/lib/mermaid-diagram/index.js +174 -0
  85. package/dist/lib/mermaid-diagram/index.module.js +25 -0
  86. package/dist/lib/mermaid-diagram/index_module.css +4 -0
  87. package/dist/lib/mermaid-diagram/use-svg-pan-zoom.js +83 -0
  88. package/dist/lib/mermaid-diagram/utils.js +98 -0
  89. package/dist/lib/model-config-editor/basic-type.js +105 -0
  90. package/dist/lib/model-config-editor/index.module.js +25 -0
  91. package/dist/lib/model-config-editor/index_module.css +8 -0
  92. package/dist/lib/model-config-editor/model-config-form.js +149 -0
  93. package/dist/lib/model-config-editor/popover-type.js +145 -0
  94. package/dist/lib/model-select/index.js +170 -0
  95. package/dist/lib/model-select/index.module.js +25 -0
  96. package/dist/lib/model-select/index_module.css +14 -0
  97. package/dist/lib/model-select/model-option/index.js +188 -0
  98. package/dist/lib/model-select/model-option/index.module.js +25 -0
  99. package/dist/lib/model-select/model-option/index_module.css +23 -0
  100. package/dist/lib/model-select/model-option-group/index.js +75 -0
  101. package/dist/lib/prompt-editor/index.js +218 -0
  102. package/dist/lib/prompt-editor/index.module.js +25 -0
  103. package/dist/lib/prompt-editor/index_module.css +71 -0
  104. package/dist/lib/prompt-editor/message-type-select.js +108 -0
  105. package/dist/lib/schema-editor/index.js +77 -0
  106. package/dist/lib/utils/base.js +82 -0
  107. package/dist/lib/utils/model-config.js +57 -0
  108. package/dist/types/basic-editor/custom-facet.d.ts +2 -0
  109. package/dist/types/basic-editor/diff.d.ts +15 -0
  110. package/dist/types/basic-editor/extensions/go-syntax.d.ts +71 -0
  111. package/dist/types/basic-editor/extensions/go-template.d.ts +1 -0
  112. package/dist/types/basic-editor/extensions/go-theme.d.ts +2 -0
  113. package/dist/types/basic-editor/extensions/jinja.d.ts +6 -0
  114. package/dist/types/basic-editor/extensions/keymap.d.ts +4 -0
  115. package/dist/types/basic-editor/extensions/language-support.d.ts +2 -0
  116. package/dist/types/basic-editor/extensions/markdown.d.ts +2 -0
  117. package/dist/types/basic-editor/extensions/search/dom/icon.d.ts +59 -0
  118. package/dist/types/basic-editor/extensions/search/dom/match-count.d.ts +14 -0
  119. package/dist/types/basic-editor/extensions/search/index.d.ts +1 -0
  120. package/dist/types/basic-editor/extensions/search/panel.d.ts +32 -0
  121. package/dist/types/basic-editor/extensions/search/theme.d.ts +1 -0
  122. package/dist/types/basic-editor/extensions/validation.d.ts +10 -0
  123. package/dist/types/basic-editor/extensions/variable.d.ts +14 -0
  124. package/dist/types/basic-editor/index.d.ts +28 -0
  125. package/dist/types/code-editor/code-editor.d.ts +23 -0
  126. package/dist/types/code-editor/index.d.ts +5 -0
  127. package/dist/types/code-editor/json-editor.d.ts +17 -0
  128. package/dist/types/code-editor/raw-text-editor.d.ts +11 -0
  129. package/dist/types/code-editor/text-editor.d.ts +23 -0
  130. package/dist/types/code-editor/themes/coze-dark.d.ts +1 -0
  131. package/dist/types/code-editor/themes/coze-light.d.ts +1 -0
  132. package/dist/types/consts/index.d.ts +3 -0
  133. package/dist/types/dev-layout/index.d.ts +13 -0
  134. package/dist/types/index.d.ts +19 -0
  135. package/dist/types/mermaid-diagram/index.d.ts +12 -0
  136. package/dist/types/mermaid-diagram/use-svg-pan-zoom.d.ts +17 -0
  137. package/dist/types/mermaid-diagram/utils.d.ts +1 -0
  138. package/dist/types/model-config-editor/basic-type.d.ts +19 -0
  139. package/dist/types/model-config-editor/model-config-form.d.ts +14 -0
  140. package/dist/types/model-config-editor/popover-type.d.ts +25 -0
  141. package/dist/types/model-select/index.d.ts +38 -0
  142. package/dist/types/model-select/model-option/index.d.ts +30 -0
  143. package/dist/types/model-select/model-option-group/index.d.ts +15 -0
  144. package/dist/types/prompt-editor/index.d.ts +30 -0
  145. package/dist/types/prompt-editor/message-type-select.d.ts +16 -0
  146. package/dist/types/schema-editor/index.d.ts +18 -0
  147. package/dist/types/utils/base.d.ts +10 -0
  148. package/dist/types/utils/model-config.d.ts +4 -0
  149. package/package.json +75 -0
@@ -0,0 +1,418 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ import createEle from "crelt";
21
+ import {
22
+ runScopeHandlers
23
+ } from "@codemirror/view";
24
+ import {
25
+ closeSearchPanel,
26
+ findNext,
27
+ findPrevious,
28
+ getSearchQuery,
29
+ replaceAll,
30
+ replaceNext,
31
+ SearchQuery,
32
+ setSearchQuery
33
+ } from "@codemirror/search";
34
+ import { MatchCount } from "./dom/match-count";
35
+ import {
36
+ IconCaseSensitive,
37
+ IconRegExp,
38
+ IconWholeWord,
39
+ IconArrowUp,
40
+ IconArrowDown,
41
+ IconReplace,
42
+ IconReplaceAll,
43
+ IconClose,
44
+ IconChevronRight
45
+ } from "./dom/icon";
46
+ class SearchPanel {
47
+ constructor(view) {
48
+ this.view = view;
49
+ this.commit = this.commit.bind(this);
50
+ this.query = getSearchQuery(view.state);
51
+ this.matchCount = new MatchCount();
52
+ const searchLine = this.initSearchLine(view);
53
+ const replaceLine = this.initReplaceLine(view);
54
+ const replaceLineStatus = () => {
55
+ var _a;
56
+ if (view.state.readOnly) {
57
+ replaceLine.style.display = "none";
58
+ return;
59
+ }
60
+ if (!((_a = this.expand) == null ? void 0 : _a.checked)) {
61
+ replaceLine.style.display = "none";
62
+ return;
63
+ }
64
+ replaceLine.style.display = "flex";
65
+ };
66
+ replaceLineStatus();
67
+ const expand = this.initExpandButton(view, () => replaceLineStatus());
68
+ const onMouseDown = useDragSearchPanel(this);
69
+ this.dom = createEle(
70
+ "div",
71
+ {
72
+ onkeydown: (e) => this.keydown(e),
73
+ class: "cm-custom-search"
74
+ },
75
+ [
76
+ createEle("div", {
77
+ class: "cm-custom-search-drag",
78
+ onmousedown: onMouseDown
79
+ }),
80
+ ...expand,
81
+ createEle(
82
+ "div",
83
+ {
84
+ class: "cm-custom-search-panel-content"
85
+ },
86
+ [searchLine, replaceLine]
87
+ )
88
+ ]
89
+ );
90
+ this.updateMatchCount(view.state, this.query);
91
+ }
92
+ initExpandButton(view, onExpandChange) {
93
+ this.expand = new IconChevronRight({
94
+ name: "expand",
95
+ title: phrase(view, "展开"),
96
+ onchange: onExpandChange
97
+ });
98
+ return view.state.readOnly ? [] : [
99
+ createEle(
100
+ "div",
101
+ {
102
+ class: "cm-custom-search-panel-expand"
103
+ },
104
+ [this.expand.dom]
105
+ )
106
+ ];
107
+ }
108
+ initSearchLine(view) {
109
+ const inputWrapperRef = {
110
+ current: null
111
+ };
112
+ const handleInputFocus = () => {
113
+ var _a;
114
+ (_a = inputWrapperRef.current) == null ? void 0 : _a.focus();
115
+ if (inputWrapperRef.current && !inputWrapperRef.current.classList.contains(
116
+ "cm-custom-search-panel-content-input-wrapper-focus"
117
+ )) {
118
+ inputWrapperRef.current.classList.add(
119
+ "cm-custom-search-panel-content-input-wrapper-focus"
120
+ );
121
+ }
122
+ };
123
+ const handleInputBlur = () => {
124
+ var _a;
125
+ (_a = inputWrapperRef.current) == null ? void 0 : _a.blur();
126
+ if (inputWrapperRef.current) {
127
+ inputWrapperRef.current.classList.remove(
128
+ "cm-custom-search-panel-content-input-wrapper-focus"
129
+ );
130
+ }
131
+ };
132
+ this.searchField = createEle("input", {
133
+ value: this.query.search,
134
+ placeholder: phrase(view, "查找"),
135
+ title: phrase(view, "查找"),
136
+ class: "cm-custom-text-field",
137
+ name: "search",
138
+ form: "",
139
+ "main-field": "true",
140
+ onchange: this.commit,
141
+ onkeyup: this.commit,
142
+ onfocus: handleInputFocus,
143
+ onblur: handleInputBlur
144
+ });
145
+ this.caseField = new IconCaseSensitive({
146
+ checked: this.query.caseSensitive,
147
+ onchange: () => {
148
+ this.searchField.focus();
149
+ this.commit();
150
+ },
151
+ name: "case",
152
+ title: phrase(view, "区分大小写")
153
+ });
154
+ this.reField = new IconRegExp({
155
+ name: "re",
156
+ checked: this.query.regexp,
157
+ onchange: () => {
158
+ this.searchField.focus();
159
+ this.commit();
160
+ },
161
+ title: phrase(view, "正则表达式")
162
+ });
163
+ this.wordField = new IconWholeWord({
164
+ name: "word",
165
+ checked: this.query.wholeWord,
166
+ onchange: () => {
167
+ this.searchField.focus();
168
+ this.commit();
169
+ },
170
+ title: phrase(view, "全词匹配")
171
+ });
172
+ this.arrowUp = new IconArrowUp({
173
+ name: "previous",
174
+ onclick: () => {
175
+ findPrevious(view);
176
+ this.updateMatchCount(view.state, this.query);
177
+ },
178
+ title: phrase(view, "上一个匹配")
179
+ });
180
+ this.arrowDown = new IconArrowDown({
181
+ name: "next",
182
+ onclick: () => {
183
+ findNext(view);
184
+ this.updateMatchCount(view.state, this.query);
185
+ },
186
+ title: phrase(view, "下一个匹配")
187
+ });
188
+ inputWrapperRef.current = createEle(
189
+ "div",
190
+ {
191
+ class: "cm-custom-search-panel-content-input-wrapper"
192
+ },
193
+ [
194
+ this.searchField,
195
+ // enter.dom,
196
+ this.caseField.dom,
197
+ this.reField.dom,
198
+ this.wordField.dom
199
+ ]
200
+ );
201
+ return createEle(
202
+ "div",
203
+ {
204
+ class: "cm-custom-search-panel-content-top"
205
+ },
206
+ [
207
+ inputWrapperRef.current,
208
+ this.matchCount.dom,
209
+ createEle(
210
+ "div",
211
+ {
212
+ class: "cm-custom-search-action-wrapper"
213
+ },
214
+ [
215
+ this.arrowUp.dom,
216
+ this.arrowDown.dom,
217
+ new IconClose({
218
+ name: "close-icon",
219
+ onclick: () => closeSearchPanel(view),
220
+ title: phrase(view, "关闭")
221
+ }).dom
222
+ ]
223
+ )
224
+ ]
225
+ );
226
+ }
227
+ initReplaceLine(view) {
228
+ const inputWrapperRef = {
229
+ current: null
230
+ };
231
+ const handleInputFocus = () => {
232
+ var _a;
233
+ (_a = inputWrapperRef.current) == null ? void 0 : _a.focus();
234
+ if (inputWrapperRef.current && !inputWrapperRef.current.classList.contains(
235
+ "cm-custom-search-panel-content-input-wrapper-focus"
236
+ )) {
237
+ inputWrapperRef.current.classList.add(
238
+ "cm-custom-search-panel-content-input-wrapper-focus"
239
+ );
240
+ }
241
+ };
242
+ const handleInputBlur = () => {
243
+ var _a;
244
+ (_a = inputWrapperRef.current) == null ? void 0 : _a.blur();
245
+ if (inputWrapperRef.current) {
246
+ inputWrapperRef.current.classList.remove(
247
+ "cm-custom-search-panel-content-input-wrapper-focus"
248
+ );
249
+ }
250
+ };
251
+ this.replaceField = createEle("input", {
252
+ value: this.query.replace,
253
+ placeholder: phrase(view, "替换"),
254
+ title: phrase(view, "替换"),
255
+ class: "cm-custom-text-field",
256
+ name: "replace",
257
+ form: "",
258
+ onchange: this.commit,
259
+ onkeyup: this.commit,
260
+ onfocus: handleInputFocus,
261
+ onblur: handleInputBlur
262
+ });
263
+ this.replace = new IconReplace({
264
+ name: "replace",
265
+ onclick: () => {
266
+ replaceNext(view);
267
+ this.updateMatchCount(view.state, this.query);
268
+ },
269
+ title: phrase(view, "替换")
270
+ });
271
+ this.replaceAll = new IconReplaceAll({
272
+ name: "replaceAll",
273
+ onclick: () => {
274
+ replaceAll(view);
275
+ this.updateMatchCount(view.state, this.query);
276
+ },
277
+ title: phrase(view, "替换所有")
278
+ });
279
+ inputWrapperRef.current = createEle(
280
+ "div",
281
+ {
282
+ class: "cm-custom-search-panel-content-input-wrapper"
283
+ },
284
+ [this.replaceField]
285
+ );
286
+ return createEle(
287
+ "div",
288
+ {
289
+ class: "cm-custom-search-panel-content-bottom"
290
+ },
291
+ [inputWrapperRef.current, this.replace.dom, this.replaceAll.dom]
292
+ );
293
+ }
294
+ commit() {
295
+ const query = new SearchQuery({
296
+ search: this.searchField.value,
297
+ caseSensitive: this.caseField.checked,
298
+ regexp: this.reField.checked,
299
+ wholeWord: this.wordField.checked,
300
+ replace: this.replaceField.value
301
+ });
302
+ if (!query.eq(this.query)) {
303
+ this.query = query;
304
+ this.view.dispatch({ effects: setSearchQuery.of(query) });
305
+ }
306
+ this.updateMatchCount(this.view.state, this.query);
307
+ }
308
+ keydown(e) {
309
+ if (runScopeHandlers(this.view, e, "search-panel")) {
310
+ e.preventDefault();
311
+ } else if ((e.keyCode === 13 || e.key === "Enter") && e.target === this.searchField) {
312
+ e.preventDefault();
313
+ (e.shiftKey ? findPrevious : findNext)(this.view);
314
+ } else if ((e.keyCode === 13 || e.key === "Enter") && e.target === this.replaceField) {
315
+ e.preventDefault();
316
+ replaceNext(this.view);
317
+ }
318
+ }
319
+ updateMatchCount(state, query) {
320
+ this.matchCount.data = __spreadProps(__spreadValues({}, findMatchIndex(state, query)), {
321
+ searching: !!query.search
322
+ });
323
+ if (this.matchCount.data.matchCount > 0) {
324
+ this.replace.disabled = false;
325
+ this.replaceAll.disabled = false;
326
+ this.arrowUp.disabled = false;
327
+ this.arrowDown.disabled = false;
328
+ } else {
329
+ this.replace.disabled = true;
330
+ this.replaceAll.disabled = true;
331
+ this.arrowUp.disabled = true;
332
+ this.arrowDown.disabled = true;
333
+ }
334
+ }
335
+ update(update) {
336
+ for (const tr of update.transactions) {
337
+ for (const effect of tr.effects) {
338
+ if (effect.is(setSearchQuery) && !effect.value.eq(this.query)) {
339
+ this.setQuery(effect.value);
340
+ this.updateMatchCount(update.state, effect.value);
341
+ }
342
+ }
343
+ }
344
+ }
345
+ setQuery(query) {
346
+ this.query = query;
347
+ this.searchField.value = query.search;
348
+ this.replaceField.value = query.replace;
349
+ this.caseField.checked = query.caseSensitive;
350
+ this.reField.checked = query.regexp;
351
+ this.wordField.checked = query.wholeWord;
352
+ }
353
+ mount() {
354
+ this.searchField.select();
355
+ }
356
+ get top() {
357
+ return true;
358
+ }
359
+ }
360
+ function phrase(view, p) {
361
+ return view.state.phrase(p);
362
+ }
363
+ function findMatchIndex(state, query) {
364
+ try {
365
+ const { from, to } = state.selection.main;
366
+ let index = 0;
367
+ let matchIndex = -1;
368
+ const cursor = query.getCursor(state);
369
+ let data = cursor.next();
370
+ while (!data.done) {
371
+ if (data.value.from === from && data.value.to === to) {
372
+ matchIndex = index;
373
+ }
374
+ data = cursor.next();
375
+ index++;
376
+ }
377
+ return { matchIndex, matchCount: index };
378
+ } catch (e) {
379
+ return { matchIndex: -1, matchCount: 0 };
380
+ }
381
+ }
382
+ function useDragSearchPanel(panel) {
383
+ let isResizing = false;
384
+ let startX = 0;
385
+ let startWidth = 0;
386
+ const onMouseMove = (e) => {
387
+ e.preventDefault();
388
+ e.stopPropagation();
389
+ if (!isResizing || !(panel == null ? void 0 : panel.dom)) {
390
+ return;
391
+ }
392
+ const newWidth = startX - e.clientX + startWidth;
393
+ panel.dom.style.width = `${newWidth}px`;
394
+ };
395
+ const onMouseUp = (e) => {
396
+ e.preventDefault();
397
+ e.stopPropagation();
398
+ isResizing = false;
399
+ startX = 0;
400
+ startWidth = 0;
401
+ document.removeEventListener("mousemove", onMouseMove);
402
+ document.removeEventListener("mouseup", onMouseUp);
403
+ };
404
+ const onMouseDown = (e) => {
405
+ var _a;
406
+ e.preventDefault();
407
+ e.stopPropagation();
408
+ isResizing = true;
409
+ startX = e.clientX;
410
+ startWidth = (_a = panel == null ? void 0 : panel.dom.clientWidth) != null ? _a : 0;
411
+ document.addEventListener("mousemove", onMouseMove);
412
+ document.addEventListener("mouseup", onMouseUp);
413
+ };
414
+ return onMouseDown;
415
+ }
416
+ export {
417
+ SearchPanel
418
+ };
@@ -0,0 +1,184 @@
1
+ import { EditorView } from "@codemirror/view";
2
+ import { Prec } from "@codemirror/state";
3
+ const theme = Prec.high(
4
+ EditorView.theme({
5
+ "& .cm-panels.cm-panels-top": {
6
+ borderBottom: "none",
7
+ backgroundColor: "transparent"
8
+ },
9
+ "& .cm-panels.cm-panels-bottom": {
10
+ borderTop: "none",
11
+ backgroundColor: "transparent",
12
+ border: "1px solid rgba(28, 31, 35, .08)"
13
+ },
14
+ "& .cm-searchMatch": {
15
+ outline: "none"
16
+ },
17
+ "& .cm-custom-search": {
18
+ position: "absolute",
19
+ top: 0,
20
+ right: "10px",
21
+ backgroundColor: "#f3f3f3",
22
+ display: "flex",
23
+ padding: "4px",
24
+ boxSizing: "border-box",
25
+ minWidth: "360px",
26
+ maxWidth: "calc(100% - 30px)",
27
+ borderRadius: "4px",
28
+ boxShadow: "0 2px 8px 2px rgba(0, 0, 0, 0.16)",
29
+ overflow: "hidden"
30
+ },
31
+ "& .cm-custom-search button": {
32
+ borderWidth: 0
33
+ },
34
+ "& .cm-custom-search input": {
35
+ outline: "none"
36
+ },
37
+ "& .cm-custom-search .cm-custom-search-drag": {
38
+ width: "3px",
39
+ height: "100%",
40
+ position: "absolute",
41
+ top: "0px",
42
+ left: "0px",
43
+ backgroundColor: "#c8c8c8"
44
+ },
45
+ "& .cm-custom-search .cm-custom-search-drag:hover": {
46
+ backgroundColor: "#0090f1",
47
+ cursor: "col-resize"
48
+ },
49
+ "& .cm-custom-text-field": {
50
+ backgroundColor: "inherit",
51
+ padding: 0,
52
+ border: "none",
53
+ color: "#444d56",
54
+ fontSize: "12px",
55
+ lineHeight: "16px",
56
+ verticalAlign: "middle",
57
+ width: "calc(100% - 58px)"
58
+ },
59
+ "& .cm-custom-search-panel-icon": {
60
+ display: "inline-flex",
61
+ "align-items": "center",
62
+ "justify-content": "center",
63
+ padding: "4px",
64
+ "border-radius": "2px",
65
+ "background-color": "transparent",
66
+ "box-sizing": "border-box",
67
+ width: "20px",
68
+ height: "20px",
69
+ cursor: "pointer"
70
+ },
71
+ "& .cm-custom-search-panel-icon:hover": {
72
+ color: "rgba(0, 100, 250, 1)",
73
+ backgroundColor: "rgba(46, 60, 56, .09)"
74
+ },
75
+ "& .cm-custom-search-panel-icon:active": {
76
+ backgroundColor: "rgba(46, 50, 56, .13)"
77
+ },
78
+ "& .cm-custom-search-panel-icon span": {
79
+ display: "inline-flex",
80
+ lineHeight: "12px",
81
+ fontSize: "12px"
82
+ },
83
+ "& .cm-custom-search-panel-icon-active": {
84
+ color: "rgba(0, 100, 250, 1)",
85
+ backgroundColor: "rgba(46, 50, 56, .05)"
86
+ },
87
+ "& .cm-custom-search-panel-icon-disabled": {
88
+ color: "rgba(28, 31, 35, .35)",
89
+ backgroundColor: "transparent"
90
+ },
91
+ "& .cm-custom-search-panel-icon-disabled:hover": {
92
+ color: "rgba(28, 31, 35, .35)",
93
+ backgroundColor: "transparent"
94
+ },
95
+ "& .cm-custom-search-panel-icon-disabled:active": {
96
+ color: "rgba(28, 31, 35, .35)",
97
+ backgroundColor: "transparent"
98
+ },
99
+ "& .cm-custom-search-panel-expand": {
100
+ display: "flex",
101
+ padding: "4px"
102
+ },
103
+ "& .cm-custom-search-panel-content": {
104
+ display: "flex",
105
+ flexDirection: "column",
106
+ flex: 1
107
+ },
108
+ "& .cm-custom-search-panel-content-top": {
109
+ display: "flex",
110
+ alignItems: "center"
111
+ },
112
+ "& .cm-custom-search-action-wrapper": {
113
+ display: "flex",
114
+ alignItems: "center",
115
+ justifyContent: "end"
116
+ },
117
+ "& .cm-custom-search-panel-content-input-wrapper": {
118
+ display: "flex",
119
+ alignItems: "center",
120
+ flex: 1,
121
+ position: "relative",
122
+ border: "1px solid #555",
123
+ padding: "4px",
124
+ minWidth: "170px",
125
+ marginLeft: "4px",
126
+ marginRight: "6px",
127
+ borderRadius: "2px"
128
+ },
129
+ "& .cm-custom-search-panel-content-input-wrapper-focus": {
130
+ borderColor: "rgba(0, 100, 250, 1)"
131
+ },
132
+ "& .cm-custom-search-panel-content-input-wrapper .cm-custom-search-panel-icon": {
133
+ position: "absolute",
134
+ top: "4px",
135
+ right: "4px",
136
+ padding: "2px",
137
+ width: "16px",
138
+ height: "16px !important"
139
+ },
140
+ "& .cm-panel.cm-custom-search [name=word]": {
141
+ right: "22px"
142
+ },
143
+ "& .cm-panel.cm-custom-search [name=case]": {
144
+ right: "40px"
145
+ },
146
+ "& .cm-panel.cm-custom-search [name=enter]": {
147
+ right: "58px"
148
+ },
149
+ "& .cm-panel.cm-custom-search [name=previous]": {
150
+ marginRight: "2px"
151
+ },
152
+ "& .cm-panel.cm-custom-search [name=next]": {
153
+ marginRight: "2px"
154
+ },
155
+ "& .cm-panel.cm-custom-search [name=close-icon]": {
156
+ marginRight: "2px"
157
+ },
158
+ "& .cm-panel.cm-custom-search [name=replace]": {
159
+ marginRight: "2px"
160
+ },
161
+ "& .cm-panel.cm-custom-search [name=expand]": {
162
+ transform: "rotate(0deg)"
163
+ },
164
+ "& .cm-panel.cm-custom-search [name=expand].cm-custom-search-panel-icon-active": {
165
+ transform: "rotate(90deg)"
166
+ },
167
+ "& .cm-custom-search-match-count": {
168
+ fontSize: "12px",
169
+ width: "80px",
170
+ overflow: "hidden"
171
+ },
172
+ "& .cm-custom-search-panel-content-bottom": {
173
+ marginRight: "104px",
174
+ display: "flex",
175
+ alignItems: "center"
176
+ },
177
+ "& .cm-custom-search-panel-content-bottom .cm-custom-search-panel-content-input-wrapper": {
178
+ marginTop: "6px"
179
+ }
180
+ })
181
+ );
182
+ export {
183
+ theme
184
+ };
@@ -0,0 +1,84 @@
1
+ import { useLayoutEffect } from "react";
2
+ import { useInjector } from "@coze-editor/editor/react";
3
+ import { astDecorator } from "@coze-editor/editor";
4
+ import { VARIABLE_MAX_LEN } from "../../consts";
5
+ import styles from "./validation.module";
6
+ function validate(text) {
7
+ const regex = new RegExp(`^[a-zA-Z][\\w]{0,${VARIABLE_MAX_LEN - 1}}$`, "gm");
8
+ if (regex.test(text)) {
9
+ return true;
10
+ }
11
+ return false;
12
+ }
13
+ function Validation({
14
+ variables,
15
+ isNormalTemplate
16
+ }) {
17
+ const injector = useInjector();
18
+ useLayoutEffect(
19
+ () => injector.inject([
20
+ astDecorator.whole.of((cursor, state) => {
21
+ var _a, _b, _c, _d;
22
+ if (cursor.name === "JinjaExpression" && ((_a = cursor.node.firstChild) == null ? void 0 : _a.name) === "JinjaExpressionStart" && ((_b = cursor.node.lastChild) == null ? void 0 : _b.name) === "JinjaExpressionEnd") {
23
+ const from = cursor.node.firstChild.to;
24
+ const to = cursor.node.lastChild.from;
25
+ const text = state.sliceDoc(from, to);
26
+ if (validate(text) && isNormalTemplate) {
27
+ return {
28
+ type: "className",
29
+ className: styles.valid,
30
+ from,
31
+ to
32
+ };
33
+ }
34
+ if (!isNormalTemplate) {
35
+ const item = variables == null ? void 0 : variables.find((variable) => variable.key === text);
36
+ if (item) {
37
+ return {
38
+ type: "className",
39
+ className: styles.valid,
40
+ from,
41
+ to
42
+ };
43
+ }
44
+ }
45
+ return {
46
+ type: "className",
47
+ className: styles.invalid,
48
+ from,
49
+ to
50
+ };
51
+ }
52
+ if (cursor.name === "JinjaStatement" && ((_c = cursor.node.firstChild) == null ? void 0 : _c.name) === "JinjaStatementStart" && ((_d = cursor.node.lastChild) == null ? void 0 : _d.name) === "JinjaStatementEnd" && !isNormalTemplate) {
53
+ const from = cursor.node.firstChild.to;
54
+ const to = cursor.node.lastChild.from;
55
+ const text = state.sliceDoc(from, to);
56
+ return (variables || []).map((variable) => {
57
+ if (variable.key) {
58
+ const index = text.indexOf(variable.key);
59
+ if (index !== -1) {
60
+ return {
61
+ type: "className",
62
+ className: styles.valid,
63
+ from: from + index,
64
+ to: from + index + variable.key.length + 1
65
+ };
66
+ }
67
+ }
68
+ return void 0;
69
+ }).filter(
70
+ (item) => item !== void 0
71
+ );
72
+ }
73
+ return void 0;
74
+ })
75
+ ]),
76
+ [injector, variables]
77
+ );
78
+ return null;
79
+ }
80
+ var validation_default = Validation;
81
+ export {
82
+ Validation,
83
+ validation_default as default
84
+ };
@@ -0,0 +1,5 @@
1
+ import "./validation_module.css";
2
+ var validation_default = { "valid": "valid_5e57b", "invalid": "invalid_5e57b" };
3
+ export {
4
+ validation_default as default
5
+ };
@@ -0,0 +1,7 @@
1
+ .valid_5e57b {
2
+ color: var(--Green-COZColorGreen7, #00A136);
3
+ }
4
+
5
+ .invalid_5e57b {
6
+ color: #0607094D;
7
+ }