@adecore/editor-react 0.41.1 → 0.43.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 (124) hide show
  1. package/dist/CallHierarchyPanel.js +177 -181
  2. package/dist/EditorContextMenu.js +118 -105
  3. package/dist/EditorView.js +7 -1
  4. package/dist/LanguagePopups.js +7 -0
  5. package/dist/PickPopup.js +190 -70
  6. package/dist/WrapCard.d.ts +8 -0
  7. package/dist/WrapCard.js +172 -0
  8. package/dist/call-hierarchy-model.d.ts +4 -2
  9. package/dist/call-hierarchy-model.js +20 -0
  10. package/dist/call-hierarchy.d.ts +3 -0
  11. package/dist/call-hierarchy.js +54 -22
  12. package/dist/clipboard-history.d.ts +31 -0
  13. package/dist/clipboard-history.js +70 -0
  14. package/dist/code-actions.d.ts +3 -1
  15. package/dist/code-actions.js +50 -10
  16. package/dist/code-vision.js +2 -3
  17. package/dist/completion.js +10 -15
  18. package/dist/context-menu-rows.d.ts +1 -1
  19. package/dist/context-menu-rows.js +4 -0
  20. package/dist/definition-link.js +15 -5
  21. package/dist/document-colors.d.ts +24 -0
  22. package/dist/document-colors.js +194 -0
  23. package/dist/document-links.d.ts +22 -0
  24. package/dist/document-links.js +133 -0
  25. package/dist/document-query.d.ts +15 -0
  26. package/dist/document-query.js +54 -0
  27. package/dist/edit-locations.d.ts +20 -0
  28. package/dist/edit-locations.js +136 -0
  29. package/dist/editor-language.d.ts +19 -1
  30. package/dist/editor-language.js +77 -2
  31. package/dist/emmet.d.ts +13 -0
  32. package/dist/emmet.js +62 -0
  33. package/dist/folding.js +2 -3
  34. package/dist/format-on-type.js +3 -5
  35. package/dist/highlights.js +2 -3
  36. package/dist/history.d.ts +7 -0
  37. package/dist/history.js +79 -1
  38. package/dist/host-types.d.ts +6 -0
  39. package/dist/index.d.ts +11 -2
  40. package/dist/index.js +8 -0
  41. package/dist/inlay-hints.js +2 -2
  42. package/dist/inline-completion.d.ts +39 -0
  43. package/dist/inline-completion.js +221 -0
  44. package/dist/key-priority.d.ts +8 -5
  45. package/dist/key-priority.js +9 -6
  46. package/dist/linked-editing.d.ts +26 -0
  47. package/dist/linked-editing.js +215 -0
  48. package/dist/locales/en.json +31 -2
  49. package/dist/locales/nl.json +31 -2
  50. package/dist/markup-context.d.ts +37 -0
  51. package/dist/markup-context.js +291 -0
  52. package/dist/markup.d.ts +36 -0
  53. package/dist/markup.js +453 -0
  54. package/dist/navigation.js +4 -6
  55. package/dist/paste-history.d.ts +7 -0
  56. package/dist/paste-history.js +104 -0
  57. package/dist/peek.js +3 -4
  58. package/dist/pick.d.ts +20 -2
  59. package/dist/pick.js +141 -18
  60. package/dist/popups.d.ts +9 -0
  61. package/dist/popups.js +2 -1
  62. package/dist/project-language.d.ts +18 -1
  63. package/dist/project-language.js +129 -18
  64. package/dist/rename.js +8 -11
  65. package/dist/rendered-docs.js +1 -2
  66. package/dist/selection-ranges.js +2 -3
  67. package/dist/shortcut-keys.d.ts +27 -0
  68. package/dist/signature.js +3 -6
  69. package/dist/snippet-session.d.ts +2 -2
  70. package/dist/snippet-session.js +3 -3
  71. package/dist/symbol-picker.js +4 -6
  72. package/dist/symbols.js +22 -3
  73. package/dist/testing.d.ts +23 -1
  74. package/dist/testing.js +114 -0
  75. package/package.json +7 -6
  76. package/src/CallHierarchyPanel.tsx +26 -11
  77. package/src/EditorContextMenu.tsx +7 -0
  78. package/src/EditorView.tsx +9 -0
  79. package/src/LanguagePopups.tsx +4 -0
  80. package/src/PickPopup.tsx +40 -5
  81. package/src/WrapCard.tsx +64 -0
  82. package/src/call-hierarchy-model.ts +25 -3
  83. package/src/call-hierarchy.ts +62 -20
  84. package/src/clipboard-history.ts +102 -0
  85. package/src/code-actions.ts +48 -11
  86. package/src/code-vision.ts +3 -3
  87. package/src/completion.ts +15 -15
  88. package/src/context-menu-rows.ts +3 -2
  89. package/src/definition-link.ts +17 -5
  90. package/src/document-colors.ts +189 -0
  91. package/src/document-links.ts +129 -0
  92. package/src/document-query.ts +71 -0
  93. package/src/edit-locations.ts +162 -0
  94. package/src/editor-language.ts +80 -3
  95. package/src/emmet-module.d.ts +44 -0
  96. package/src/emmet.ts +73 -0
  97. package/src/folding.ts +3 -3
  98. package/src/format-on-type.ts +5 -5
  99. package/src/highlights.ts +3 -3
  100. package/src/history.ts +81 -1
  101. package/src/host-types.ts +10 -0
  102. package/src/index.ts +12 -3
  103. package/src/inlay-hints.ts +2 -2
  104. package/src/inline-completion.ts +221 -0
  105. package/src/key-priority.ts +9 -6
  106. package/src/linked-editing.ts +199 -0
  107. package/src/locales/en.json +31 -2
  108. package/src/locales/nl.json +31 -2
  109. package/src/markup-context.ts +262 -0
  110. package/src/markup.ts +367 -0
  111. package/src/navigation.ts +6 -6
  112. package/src/paste-history.ts +111 -0
  113. package/src/peek.ts +4 -4
  114. package/src/pick.ts +201 -19
  115. package/src/popups.ts +19 -1
  116. package/src/project-language.ts +136 -19
  117. package/src/rename.ts +11 -11
  118. package/src/rendered-docs.ts +2 -2
  119. package/src/selection-ranges.ts +3 -3
  120. package/src/signature.ts +6 -6
  121. package/src/snippet-session.ts +9 -4
  122. package/src/symbol-picker.ts +6 -6
  123. package/src/symbols.ts +30 -4
  124. package/src/testing.ts +126 -1
@@ -0,0 +1,291 @@
1
+ /* Above this a document is not read on a keystroke; the features then do nothing in it. */
2
+ export const MAX_MARKUP_SCAN = 1_000_000;
3
+ const VOID_ELEMENTS = new Set(['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr']);
4
+ const RAW_ELEMENTS = new Set(['script', 'style', 'textarea', 'title']);
5
+ const NAME_START = /[A-Za-z]/;
6
+ const NAME = /[\w:.-]/;
7
+ export function markupSyntaxOf(languageId) {
8
+ switch (languageId.toLowerCase()) {
9
+ case 'html':
10
+ case 'xhtml':
11
+ return 'html';
12
+ case 'xml':
13
+ case 'svg':
14
+ case 'xsl':
15
+ return 'xml';
16
+ case 'vue':
17
+ return 'vue';
18
+ case 'php':
19
+ return 'php';
20
+ default:
21
+ return null;
22
+ }
23
+ }
24
+ /* Whether an element of this name has no end tag, which only HTML has. */
25
+ export function isVoidElement(name, syntax) {
26
+ return syntax !== 'xml' && VOID_ELEMENTS.has(name.toLowerCase());
27
+ }
28
+ class Stop {
29
+ place;
30
+ constructor(place) {
31
+ this.place = place;
32
+ }
33
+ }
34
+ /*
35
+ * A reader of markup that is no parser: it follows tags, comments, raw elements and the code blocks of
36
+ * PHP and Vue far enough to tell what an offset is in, and pairs a start tag with the end tag that closes it.
37
+ */
38
+ class MarkupScanner {
39
+ pairs = [];
40
+ text;
41
+ syntax;
42
+ until;
43
+ open = [];
44
+ constructor(text, syntax, until) {
45
+ this.text = text;
46
+ this.syntax = syntax;
47
+ this.until = until;
48
+ }
49
+ run() {
50
+ try {
51
+ this.content();
52
+ return this.textPlace();
53
+ } catch (error) {
54
+ if (error instanceof Stop) {
55
+ return error.place;
56
+ }
57
+ throw error;
58
+ }
59
+ }
60
+ textPlace() {
61
+ return {
62
+ kind: 'text',
63
+ open: this.open.map(({
64
+ name,
65
+ nameFrom
66
+ }) => ({
67
+ name,
68
+ nameFrom
69
+ }))
70
+ };
71
+ }
72
+ /* Leaves the scan with what the offset is in when it lies in `from` to `to`, `to` included where the construct owns its last character. */
73
+ reached(from, to, place) {
74
+ if (from < this.until && this.until <= to) {
75
+ throw new Stop(place());
76
+ }
77
+ }
78
+ content() {
79
+ const {
80
+ text
81
+ } = this;
82
+ let at = 0;
83
+ while (at < text.length) {
84
+ if (at >= this.until) {
85
+ throw new Stop(this.textPlace());
86
+ }
87
+ const char = text[at];
88
+ if (char === '<') {
89
+ at = this.markup(at);
90
+ } else if (this.syntax === 'vue' && char === '{' && text[at + 1] === '{') {
91
+ at = this.skipTo(at, '}}');
92
+ } else {
93
+ at++;
94
+ }
95
+ }
96
+ }
97
+ /* Skips from `from` past `close`, the whole construct counting as something other than text. */
98
+ skipTo(from, close) {
99
+ const end = this.text.indexOf(close, from + 1);
100
+ const after = end === -1 ? this.text.length : end + close.length;
101
+ this.reached(from, end === -1 ? after : after - 1, () => ({
102
+ kind: 'other'
103
+ }));
104
+ return after;
105
+ }
106
+ markup(at) {
107
+ const {
108
+ text
109
+ } = this;
110
+ if (text.startsWith('<!--', at)) {
111
+ return this.skipTo(at, '-->');
112
+ }
113
+ if (text.startsWith('<![CDATA[', at)) {
114
+ return this.skipTo(at, ']]>');
115
+ }
116
+ if (text[at + 1] === '?') {
117
+ return this.skipTo(at, this.syntax === 'php' ? '?>' : '>');
118
+ }
119
+ if (text[at + 1] === '!') {
120
+ return this.skipTo(at, '>');
121
+ }
122
+ const closing = text[at + 1] === '/';
123
+ const nameFrom = at + (closing ? 2 : 1);
124
+ if (!NAME_START.test(text[nameFrom] ?? '')) {
125
+ return at + 1;
126
+ }
127
+ let nameTo = nameFrom;
128
+ while (nameTo < text.length && NAME.test(text[nameTo])) {
129
+ nameTo++;
130
+ }
131
+ const name = text.slice(nameFrom, nameTo);
132
+ const end = this.tagEnd(at, closing, name, nameFrom, nameTo);
133
+ if (closing) {
134
+ this.close(name, nameFrom, nameTo);
135
+ return end;
136
+ }
137
+ const selfClosing = text[end - 2] === '/' && text[end - 1] === '>';
138
+ if (selfClosing || isVoidElement(name, this.syntax)) {
139
+ return end;
140
+ }
141
+ if (this.syntax !== 'xml' && RAW_ELEMENTS.has(name.toLowerCase())) {
142
+ return this.rawContent(end, name, nameFrom, nameTo);
143
+ }
144
+ this.open.push({
145
+ name,
146
+ nameFrom,
147
+ nameTo
148
+ });
149
+ return end;
150
+ }
151
+ /* Reads the attributes of a tag up to the offset after its `>`, quotes and PHP blocks included. */
152
+ tagEnd(start, closing, name, nameFrom, nameTo) {
153
+ const {
154
+ text
155
+ } = this;
156
+ let at = nameTo;
157
+ let quote = null;
158
+ let valueFrom = -1;
159
+ while (at < text.length) {
160
+ const char = text[at];
161
+ if (this.syntax === 'php' && char === '<' && text[at + 1] === '?') {
162
+ at = this.skipTo(at, '?>');
163
+ continue;
164
+ }
165
+ if (quote !== null) {
166
+ if (char === quote) {
167
+ this.reached(valueFrom, at, () => ({
168
+ kind: 'tag',
169
+ tag: {
170
+ start,
171
+ closing,
172
+ name,
173
+ nameFrom,
174
+ nameTo,
175
+ inValue: true
176
+ }
177
+ }));
178
+ quote = null;
179
+ }
180
+ } else if (char === '"' || char === "'") {
181
+ quote = char;
182
+ valueFrom = at;
183
+ } else if (char === '>') {
184
+ this.reached(start, at, () => ({
185
+ kind: 'tag',
186
+ tag: {
187
+ start,
188
+ closing,
189
+ name,
190
+ nameFrom,
191
+ nameTo,
192
+ inValue: false
193
+ }
194
+ }));
195
+ return at + 1;
196
+ } else if (char === '<') {
197
+ // A tag that never closed ends where the next one starts.
198
+ this.reached(start, at, () => ({
199
+ kind: 'tag',
200
+ tag: {
201
+ start,
202
+ closing,
203
+ name,
204
+ nameFrom,
205
+ nameTo,
206
+ inValue: false
207
+ }
208
+ }));
209
+ return at;
210
+ }
211
+ at++;
212
+ }
213
+ this.reached(start, text.length, () => ({
214
+ kind: 'tag',
215
+ tag: {
216
+ start,
217
+ closing,
218
+ name,
219
+ nameFrom,
220
+ nameTo,
221
+ inValue: quote !== null && this.until > valueFrom
222
+ }
223
+ }));
224
+ return text.length;
225
+ }
226
+ /* The content of `script`, `style` and the like is not markup, up to the end tag of the element. */
227
+ rawContent(from, name, nameFrom, nameTo) {
228
+ const pattern = new RegExp(`</${name}(?=[\\s/>]|$)`, 'gi');
229
+ pattern.lastIndex = from;
230
+ const match = pattern.exec(this.text);
231
+ const end = match === null ? this.text.length : match.index;
232
+ this.reached(from - 1, end, () => ({
233
+ kind: 'other'
234
+ }));
235
+ if (match === null) {
236
+ return end;
237
+ }
238
+ const closeFrom = end + 2;
239
+ const closeTo = closeFrom + name.length;
240
+ const after = this.tagEnd(end, true, this.text.slice(closeFrom, closeTo), closeFrom, closeTo);
241
+ this.pairs.push({
242
+ open: {
243
+ from: nameFrom,
244
+ to: nameTo
245
+ },
246
+ close: {
247
+ from: closeFrom,
248
+ to: closeTo
249
+ }
250
+ });
251
+ return after;
252
+ }
253
+ /* An end tag closes the nearest open element of its name and every element left open inside it. */
254
+ close(name, nameFrom, nameTo) {
255
+ const caseless = this.syntax !== 'xml';
256
+ for (let index = this.open.length - 1; index >= 0; index--) {
257
+ const element = this.open[index];
258
+ if (element.name === name || caseless && element.name.toLowerCase() === name.toLowerCase()) {
259
+ this.pairs.push({
260
+ open: {
261
+ from: element.nameFrom,
262
+ to: element.nameTo
263
+ },
264
+ close: {
265
+ from: nameFrom,
266
+ to: nameTo
267
+ }
268
+ });
269
+ this.open.length = index;
270
+ return;
271
+ }
272
+ }
273
+ }
274
+ }
275
+ /* What `offset` is in; null for a document too large to read on a keystroke. */
276
+ export function markupPlaceAt(text, offset, syntax) {
277
+ if (text.length > MAX_MARKUP_SCAN) {
278
+ return null;
279
+ }
280
+ return new MarkupScanner(text, syntax, offset).run();
281
+ }
282
+ /* The start and end tag names of the element whose name holds `offset`, either one, its edges included. */
283
+ export function tagPairAt(text, offset, syntax) {
284
+ if (text.length > MAX_MARKUP_SCAN) {
285
+ return null;
286
+ }
287
+ const scanner = new MarkupScanner(text, syntax, Infinity);
288
+ scanner.run();
289
+ const holds = range => range.from <= offset && offset <= range.to;
290
+ return scanner.pairs.find(pair => holds(pair.open) || holds(pair.close)) ?? null;
291
+ }
@@ -0,0 +1,36 @@
1
+ import type { EditorLanguage } from './editor-language.ts';
2
+ export interface MarkupSettings {
3
+ readonly emmet?: boolean;
4
+ readonly closeTags?: boolean;
5
+ readonly linkedTags?: boolean;
6
+ }
7
+ export declare class MarkupFeature {
8
+ private readonly language;
9
+ private readonly syntax;
10
+ private settings;
11
+ private link;
12
+ private wrapping;
13
+ private revision;
14
+ private mirroring;
15
+ constructor(language: EditorLanguage);
16
+ get supported(): boolean;
17
+ configure(settings: MarkupSettings): void;
18
+ expand(): boolean;
19
+ startWrap(): boolean;
20
+ submitWrap(abbreviation: string): boolean;
21
+ cancelWrap(): void;
22
+ private key;
23
+ private editable;
24
+ private indent;
25
+ private wrapTarget;
26
+ private wrapLines;
27
+ private insert;
28
+ private apply;
29
+ private edited;
30
+ private follow;
31
+ private mirror;
32
+ private closeTag;
33
+ private completeEndTag;
34
+ private moved;
35
+ private linkAtCaret;
36
+ }