@cozeloop/prompt-components 0.0.1 → 0.0.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.
Files changed (186) hide show
  1. package/dist/edenx.config.d.ts +2 -0
  2. package/dist/{es/basic-editor/extensions/go-syntax.js → go-syntax-067c4f5d.mjs} +16 -9
  3. package/dist/go-syntax-4deb0289.js +8 -0
  4. package/dist/{es/basic-editor/extensions/go-theme.js → go-theme-062a6df6.mjs} +3 -4
  5. package/dist/go-theme-fbd8a4fa.js +1 -0
  6. package/dist/index.cjs +61 -0
  7. package/dist/index.d.ts +1 -0
  8. package/dist/index.js +2788 -0
  9. package/dist/{types → src}/basic-editor/custom-facet.d.ts +2 -1
  10. package/dist/src/basic-editor/diff.d.ts +16 -0
  11. package/dist/src/basic-editor/extensions/go-syntax.d.ts +71 -0
  12. package/dist/src/basic-editor/extensions/go-template.d.ts +1 -0
  13. package/dist/{types → src}/basic-editor/extensions/go-theme.d.ts +1 -1
  14. package/dist/src/basic-editor/extensions/jinja.d.ts +4 -0
  15. package/dist/{types → src}/basic-editor/extensions/keymap.d.ts +3 -2
  16. package/dist/src/basic-editor/extensions/language-support.d.ts +2 -0
  17. package/dist/src/basic-editor/extensions/markdown.d.ts +2 -0
  18. package/dist/src/basic-editor/extensions/search/dom/icon.d.ts +59 -0
  19. package/dist/src/basic-editor/extensions/search/dom/match-count.d.ts +14 -0
  20. package/dist/src/basic-editor/extensions/search/index.d.ts +1 -0
  21. package/dist/src/basic-editor/extensions/search/panel.d.ts +33 -0
  22. package/dist/src/basic-editor/extensions/search/theme.d.ts +1 -0
  23. package/dist/src/basic-editor/extensions/validation.d.ts +8 -0
  24. package/dist/src/basic-editor/extensions/variable.d.ts +11 -0
  25. package/dist/src/basic-editor/index.d.ts +29 -0
  26. package/dist/{types → src}/code-editor/index.d.ts +1 -1
  27. package/dist/src/code-editor/json-editor.d.ts +18 -0
  28. package/dist/src/code-editor/raw-text-editor.d.ts +11 -0
  29. package/dist/{types → src}/consts/index.d.ts +1 -1
  30. package/dist/src/dev-layout/index.d.ts +7 -0
  31. package/dist/{types → src}/index.d.ts +7 -7
  32. package/dist/src/mermaid-diagram/index.d.ts +12 -0
  33. package/dist/src/mermaid-diagram/use-svg-pan-zoom.d.ts +12 -0
  34. package/dist/{types → src}/mermaid-diagram/utils.d.ts +1 -1
  35. package/dist/src/model-config-editor/basic-type.d.ts +13 -0
  36. package/dist/src/model-config-editor/model-config-form.d.ts +13 -0
  37. package/dist/src/model-config-editor/popover-type.d.ts +19 -0
  38. package/dist/src/model-select/index.d.ts +27 -0
  39. package/dist/src/model-select/model-option/index.d.ts +25 -0
  40. package/dist/src/model-select/model-option-group/index.d.ts +16 -0
  41. package/dist/src/prompt-editor/index.d.ts +31 -0
  42. package/dist/src/prompt-editor/message-type-select.d.ts +11 -0
  43. package/dist/src/schema-editor/index.d.ts +11 -0
  44. package/dist/{types → src}/utils/base.d.ts +5 -4
  45. package/dist/src/utils/model-config.d.ts +5 -0
  46. package/dist/style.css +1 -0
  47. package/dist/test-build.d.ts +7 -0
  48. package/dist/vite.config.d.ts +2 -0
  49. package/package.json +15 -5
  50. package/dist/es/basic-editor/custom-facet.js +0 -9
  51. package/dist/es/basic-editor/diff.js +0 -138
  52. package/dist/es/basic-editor/extensions/go-template.js +0 -16
  53. package/dist/es/basic-editor/extensions/jinja.js +0 -80
  54. package/dist/es/basic-editor/extensions/keymap.js +0 -442
  55. package/dist/es/basic-editor/extensions/language-support.js +0 -12
  56. package/dist/es/basic-editor/extensions/markdown.js +0 -58
  57. package/dist/es/basic-editor/extensions/search/dom/icon.js +0 -250
  58. package/dist/es/basic-editor/extensions/search/dom/match-count.js +0 -33
  59. package/dist/es/basic-editor/extensions/search/index.js +0 -18
  60. package/dist/es/basic-editor/extensions/search/panel.js +0 -418
  61. package/dist/es/basic-editor/extensions/search/theme.js +0 -184
  62. package/dist/es/basic-editor/extensions/validation.js +0 -84
  63. package/dist/es/basic-editor/extensions/validation.module.js +0 -5
  64. package/dist/es/basic-editor/extensions/validation_module.css +0 -7
  65. package/dist/es/basic-editor/extensions/variable.js +0 -178
  66. package/dist/es/basic-editor/index.js +0 -171
  67. package/dist/es/code-editor/code-editor.js +0 -83
  68. package/dist/es/code-editor/index.js +0 -12
  69. package/dist/es/code-editor/json-editor.js +0 -157
  70. package/dist/es/code-editor/raw-text-editor.js +0 -46
  71. package/dist/es/code-editor/text-editor.js +0 -41
  72. package/dist/es/code-editor/themes/coze-dark.js +0 -112
  73. package/dist/es/code-editor/themes/coze-light.js +0 -118
  74. package/dist/es/consts/index.js +0 -12
  75. package/dist/es/dev-layout/index.js +0 -35
  76. package/dist/es/index.js +0 -66
  77. package/dist/es/mermaid-diagram/index.js +0 -148
  78. package/dist/es/mermaid-diagram/index.module.js +0 -5
  79. package/dist/es/mermaid-diagram/index_module.css +0 -4
  80. package/dist/es/mermaid-diagram/use-svg-pan-zoom.js +0 -49
  81. package/dist/es/mermaid-diagram/utils.js +0 -74
  82. package/dist/es/model-config-editor/basic-type.js +0 -73
  83. package/dist/es/model-config-editor/index.module.js +0 -5
  84. package/dist/es/model-config-editor/index_module.css +0 -8
  85. package/dist/es/model-config-editor/model-config-form.js +0 -130
  86. package/dist/es/model-config-editor/popover-type.js +0 -118
  87. package/dist/es/model-select/index.js +0 -136
  88. package/dist/es/model-select/index.module.js +0 -5
  89. package/dist/es/model-select/index_module.css +0 -14
  90. package/dist/es/model-select/model-option/index.js +0 -161
  91. package/dist/es/model-select/model-option/index.module.js +0 -5
  92. package/dist/es/model-select/model-option/index_module.css +0 -23
  93. package/dist/es/model-select/model-option-group/index.js +0 -44
  94. package/dist/es/prompt-editor/index.js +0 -188
  95. package/dist/es/prompt-editor/index.module.js +0 -5
  96. package/dist/es/prompt-editor/index_module.css +0 -71
  97. package/dist/es/prompt-editor/message-type-select.js +0 -74
  98. package/dist/es/schema-editor/index.js +0 -43
  99. package/dist/es/utils/base.js +0 -53
  100. package/dist/es/utils/model-config.js +0 -32
  101. package/dist/lib/basic-editor/custom-facet.js +0 -33
  102. package/dist/lib/basic-editor/diff.js +0 -167
  103. package/dist/lib/basic-editor/extensions/go-syntax.js +0 -146
  104. package/dist/lib/basic-editor/extensions/go-template.js +0 -50
  105. package/dist/lib/basic-editor/extensions/go-theme.js +0 -1091
  106. package/dist/lib/basic-editor/extensions/jinja.js +0 -100
  107. package/dist/lib/basic-editor/extensions/keymap.js +0 -465
  108. package/dist/lib/basic-editor/extensions/language-support.js +0 -32
  109. package/dist/lib/basic-editor/extensions/markdown.js +0 -78
  110. package/dist/lib/basic-editor/extensions/search/dom/icon.js +0 -291
  111. package/dist/lib/basic-editor/extensions/search/dom/match-count.js +0 -67
  112. package/dist/lib/basic-editor/extensions/search/index.js +0 -38
  113. package/dist/lib/basic-editor/extensions/search/panel.js +0 -429
  114. package/dist/lib/basic-editor/extensions/search/theme.js +0 -208
  115. package/dist/lib/basic-editor/extensions/validation.js +0 -118
  116. package/dist/lib/basic-editor/extensions/validation.module.js +0 -25
  117. package/dist/lib/basic-editor/extensions/validation_module.css +0 -7
  118. package/dist/lib/basic-editor/extensions/variable.js +0 -190
  119. package/dist/lib/basic-editor/index.js +0 -193
  120. package/dist/lib/code-editor/code-editor.js +0 -117
  121. package/dist/lib/code-editor/index.js +0 -40
  122. package/dist/lib/code-editor/json-editor.js +0 -184
  123. package/dist/lib/code-editor/raw-text-editor.js +0 -70
  124. package/dist/lib/code-editor/text-editor.js +0 -75
  125. package/dist/lib/code-editor/themes/coze-dark.js +0 -136
  126. package/dist/lib/code-editor/themes/coze-light.js +0 -142
  127. package/dist/lib/consts/index.js +0 -38
  128. package/dist/lib/dev-layout/index.js +0 -69
  129. package/dist/lib/index.js +0 -110
  130. package/dist/lib/mermaid-diagram/index.js +0 -174
  131. package/dist/lib/mermaid-diagram/index.module.js +0 -25
  132. package/dist/lib/mermaid-diagram/index_module.css +0 -4
  133. package/dist/lib/mermaid-diagram/use-svg-pan-zoom.js +0 -83
  134. package/dist/lib/mermaid-diagram/utils.js +0 -98
  135. package/dist/lib/model-config-editor/basic-type.js +0 -105
  136. package/dist/lib/model-config-editor/index.module.js +0 -25
  137. package/dist/lib/model-config-editor/index_module.css +0 -8
  138. package/dist/lib/model-config-editor/model-config-form.js +0 -149
  139. package/dist/lib/model-config-editor/popover-type.js +0 -145
  140. package/dist/lib/model-select/index.js +0 -170
  141. package/dist/lib/model-select/index.module.js +0 -25
  142. package/dist/lib/model-select/index_module.css +0 -14
  143. package/dist/lib/model-select/model-option/index.js +0 -188
  144. package/dist/lib/model-select/model-option/index.module.js +0 -25
  145. package/dist/lib/model-select/model-option/index_module.css +0 -23
  146. package/dist/lib/model-select/model-option-group/index.js +0 -75
  147. package/dist/lib/prompt-editor/index.js +0 -218
  148. package/dist/lib/prompt-editor/index.module.js +0 -25
  149. package/dist/lib/prompt-editor/index_module.css +0 -71
  150. package/dist/lib/prompt-editor/message-type-select.js +0 -108
  151. package/dist/lib/schema-editor/index.js +0 -77
  152. package/dist/lib/utils/base.js +0 -82
  153. package/dist/lib/utils/model-config.js +0 -57
  154. package/dist/types/basic-editor/diff.d.ts +0 -15
  155. package/dist/types/basic-editor/extensions/go-syntax.d.ts +0 -71
  156. package/dist/types/basic-editor/extensions/go-template.d.ts +0 -1
  157. package/dist/types/basic-editor/extensions/jinja.d.ts +0 -6
  158. package/dist/types/basic-editor/extensions/language-support.d.ts +0 -2
  159. package/dist/types/basic-editor/extensions/markdown.d.ts +0 -2
  160. package/dist/types/basic-editor/extensions/search/dom/icon.d.ts +0 -59
  161. package/dist/types/basic-editor/extensions/search/dom/match-count.d.ts +0 -14
  162. package/dist/types/basic-editor/extensions/search/index.d.ts +0 -1
  163. package/dist/types/basic-editor/extensions/search/panel.d.ts +0 -32
  164. package/dist/types/basic-editor/extensions/search/theme.d.ts +0 -1
  165. package/dist/types/basic-editor/extensions/validation.d.ts +0 -10
  166. package/dist/types/basic-editor/extensions/variable.d.ts +0 -14
  167. package/dist/types/basic-editor/index.d.ts +0 -28
  168. package/dist/types/code-editor/code-editor.d.ts +0 -23
  169. package/dist/types/code-editor/json-editor.d.ts +0 -17
  170. package/dist/types/code-editor/raw-text-editor.d.ts +0 -11
  171. package/dist/types/code-editor/text-editor.d.ts +0 -23
  172. package/dist/types/code-editor/themes/coze-dark.d.ts +0 -1
  173. package/dist/types/code-editor/themes/coze-light.d.ts +0 -1
  174. package/dist/types/dev-layout/index.d.ts +0 -13
  175. package/dist/types/mermaid-diagram/index.d.ts +0 -12
  176. package/dist/types/mermaid-diagram/use-svg-pan-zoom.d.ts +0 -17
  177. package/dist/types/model-config-editor/basic-type.d.ts +0 -19
  178. package/dist/types/model-config-editor/model-config-form.d.ts +0 -14
  179. package/dist/types/model-config-editor/popover-type.d.ts +0 -25
  180. package/dist/types/model-select/index.d.ts +0 -38
  181. package/dist/types/model-select/model-option/index.d.ts +0 -30
  182. package/dist/types/model-select/model-option-group/index.d.ts +0 -15
  183. package/dist/types/prompt-editor/index.d.ts +0 -30
  184. package/dist/types/prompt-editor/message-type-select.d.ts +0 -16
  185. package/dist/types/schema-editor/index.d.ts +0 -18
  186. package/dist/types/utils/model-config.d.ts +0 -4
@@ -1,418 +0,0 @@
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
- };
@@ -1,184 +0,0 @@
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
- };
@@ -1,84 +0,0 @@
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
- };
@@ -1,5 +0,0 @@
1
- import "./validation_module.css";
2
- var validation_default = { "valid": "valid_5e57b", "invalid": "invalid_5e57b" };
3
- export {
4
- validation_default as default
5
- };
@@ -1,7 +0,0 @@
1
- .valid_5e57b {
2
- color: var(--Green-COZColorGreen7, #00A136);
3
- }
4
-
5
- .invalid_5e57b {
6
- color: #0607094D;
7
- }