@gravitee/ui-components 3.24.3 → 3.24.4-migrate-codemirror-999a116

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 (117) hide show
  1. package/CHANGELOG.md +1251 -0
  2. package/LICENSE.txt +202 -0
  3. package/README.md +195 -0
  4. package/assets/i18n/en.json +0 -3
  5. package/assets/i18n/fr.json +0 -3
  6. package/package.json +4 -7
  7. package/src/.eslintrc.js +19 -0
  8. package/src/atoms/gv-autocomplete.js +156 -132
  9. package/src/atoms/gv-button.js +248 -82
  10. package/src/atoms/gv-checkbox.js +103 -45
  11. package/src/atoms/gv-date-picker-calendar.js +393 -312
  12. package/src/atoms/gv-date-picker-cell.js +81 -57
  13. package/src/atoms/gv-date-picker.js +319 -180
  14. package/src/atoms/gv-file-upload.js +195 -85
  15. package/src/atoms/gv-icon.js +34 -13
  16. package/src/atoms/gv-image.js +66 -31
  17. package/src/atoms/gv-input-message.js +37 -12
  18. package/src/atoms/gv-input.js +169 -139
  19. package/src/atoms/gv-link.js +125 -47
  20. package/src/atoms/gv-message.js +69 -18
  21. package/src/atoms/gv-metric.js +68 -19
  22. package/src/atoms/gv-relative-time.js +38 -67
  23. package/src/atoms/gv-select-native.js +215 -96
  24. package/src/atoms/gv-select.js +230 -110
  25. package/src/atoms/gv-spinner.js +26 -5
  26. package/src/atoms/gv-state.js +66 -25
  27. package/src/atoms/gv-switch.js +160 -40
  28. package/src/atoms/gv-tag.js +78 -26
  29. package/src/atoms/gv-text.js +83 -22
  30. package/src/charts/gv-chart-bar.js +18 -22
  31. package/src/charts/gv-chart-gauge.js +31 -28
  32. package/src/charts/gv-chart-histogram.js +10 -18
  33. package/src/charts/gv-chart-line.js +59 -70
  34. package/src/charts/gv-chart-map.js +42 -44
  35. package/src/charts/gv-chart-pie.js +14 -18
  36. package/src/index.js +0 -2
  37. package/src/lib/asciidoc-lang.js +642 -0
  38. package/src/lib/cron-expression.js +35 -40
  39. package/src/lib/date.js +1 -10
  40. package/src/lib/events.js +1 -3
  41. package/src/lib/http-client-schema-form.js +12 -13
  42. package/src/lib/http.js +56 -57
  43. package/src/lib/i18n.js +22 -30
  44. package/src/lib/item.js +12 -13
  45. package/src/lib/properties.js +42 -77
  46. package/src/lib/schema-form.js +5 -4
  47. package/src/lib/studio.js +60 -13
  48. package/src/lib/style.js +8 -8
  49. package/src/lib/text-format.js +7 -14
  50. package/src/lib/theme.js +5 -8
  51. package/src/lib/utils.js +18 -17
  52. package/src/mixins/chart-element.js +54 -31
  53. package/src/mixins/input-element.js +49 -60
  54. package/src/mixins/item-resource.js +32 -34
  55. package/src/mixins/keyboard-element.js +5 -6
  56. package/src/mixins/update-after-browser.js +1 -4
  57. package/src/mixins/with-resize-observer.js +13 -23
  58. package/src/mixins/with-skeleton-attribute.js +48 -54
  59. package/src/molecules/gv-card-full.js +147 -26
  60. package/src/molecules/gv-card-list.js +42 -13
  61. package/src/molecules/gv-card.js +91 -17
  62. package/src/molecules/gv-category-list.js +17 -6
  63. package/src/molecules/gv-category.js +103 -23
  64. package/src/molecules/gv-code.js +243 -189
  65. package/src/molecules/gv-confirm.js +71 -41
  66. package/src/molecules/gv-cron-editor.js +389 -143
  67. package/src/molecules/gv-dropdown-menu.js +46 -14
  68. package/src/molecules/gv-expandable.js +59 -31
  69. package/src/molecules/gv-expression-language.js +208 -552
  70. package/src/molecules/gv-identity-picture.js +65 -42
  71. package/src/molecules/gv-list.js +134 -42
  72. package/src/molecules/gv-metrics.js +49 -37
  73. package/src/molecules/gv-modal.js +95 -28
  74. package/src/molecules/gv-nav.js +75 -49
  75. package/src/molecules/gv-option.js +130 -57
  76. package/src/molecules/gv-plans.js +209 -86
  77. package/src/molecules/gv-popover.js +177 -57
  78. package/src/molecules/gv-promote.js +146 -28
  79. package/src/molecules/gv-rating-list.js +195 -69
  80. package/src/molecules/gv-rating.js +105 -52
  81. package/src/molecules/gv-row-expandable.js +11 -5
  82. package/src/molecules/gv-row.js +147 -21
  83. package/src/molecules/gv-stats.js +48 -23
  84. package/src/molecules/gv-stepper.js +187 -43
  85. package/src/molecules/gv-table.js +309 -199
  86. package/src/molecules/gv-tree.js +156 -33
  87. package/src/organisms/gv-documentation.js +127 -44
  88. package/src/organisms/gv-header.js +195 -37
  89. package/src/organisms/gv-http-client.js +168 -32
  90. package/src/organisms/gv-menu.js +158 -37
  91. package/src/organisms/gv-newsletter-subscription.js +189 -48
  92. package/src/organisms/gv-pagination.js +77 -49
  93. package/src/organisms/gv-properties.js +492 -271
  94. package/src/organisms/gv-resizable-views.js +259 -41
  95. package/src/organisms/gv-resources.js +275 -168
  96. package/src/organisms/gv-schema-form-array.js +159 -49
  97. package/src/organisms/gv-schema-form-control-object.js +73 -59
  98. package/src/organisms/gv-schema-form-control.js +134 -107
  99. package/src/organisms/gv-schema-form.js +280 -195
  100. package/src/organisms/gv-tabs.js +98 -66
  101. package/src/organisms/gv-user-menu.js +201 -36
  102. package/src/organisms/gv-vertical-menu.js +61 -20
  103. package/src/policy-studio/gv-flow-step.js +245 -105
  104. package/src/policy-studio/gv-flow.js +304 -125
  105. package/src/policy-studio/gv-policy-studio-menu.js +471 -157
  106. package/src/policy-studio/gv-policy-studio.js +761 -692
  107. package/src/styles/empty.js +20 -3
  108. package/src/styles/input.js +247 -3
  109. package/src/styles/link.js +16 -3
  110. package/src/styles/shapes.js +0 -1
  111. package/src/styles/skeleton.js +37 -3
  112. package/src/styles/zoom.js +24 -3
  113. package/src/theme/definition.json +1762 -0
  114. package/src/theme/gv-theme.js +60 -21
  115. package/assets/css/codemirror/all.css +0 -476
  116. package/src/molecules/gv-code-hint.js +0 -49
  117. package/wc/gv-code-hint.js +0 -1
@@ -0,0 +1,642 @@
1
+ /*
2
+ * Copyright (C) 2021 The Gravitee team (http://gravitee.io)
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ // Ace highlight rules function imported below.
17
+ const HighlightRules = function () {
18
+ const identifierRe = '[a-zA-Z\u00a1-\uffff]+\\b';
19
+ /* eslint no-useless-escape: "off" */
20
+ this.$rules = {
21
+ start: [
22
+ { token: 'empty', regex: /$/ },
23
+ { token: 'literal', regex: /^\.{4,}\s*$/, next: 'listingBlock' },
24
+ { token: 'literal', regex: /^-{4,}\s*$/, next: 'literalBlock' },
25
+ { token: 'literal', regex: /^\+{4,}\s*$/, next: 'passthroughBlock' },
26
+ { token: 'keyword', regex: /^={4,}\s*$/ },
27
+ { token: 'text', regex: /^\s*$/ },
28
+ // immediately return to the start mode without matching anything
29
+ { token: 'empty', regex: '', next: 'dissallowDelimitedBlock' },
30
+ ],
31
+
32
+ dissallowDelimitedBlock: [
33
+ { include: 'paragraphEnd' },
34
+ { token: 'comment', regex: '^//.+$' },
35
+ { token: 'keyword', regex: '^(?:NOTE|TIP|IMPORTANT|WARNING|CAUTION):\\s' },
36
+
37
+ { include: 'listStart' },
38
+ { token: 'literal', regex: /^\s+.+$/, next: 'indentedBlock' },
39
+ { token: 'empty', regex: '', next: 'text' },
40
+ ],
41
+
42
+ paragraphEnd: [
43
+ { token: 'doc.comment', regex: /^\/{4,}\s*$/, next: 'commentBlock' },
44
+ { token: 'tableBlock', regex: /^\s*[|!]=+\s*$/, next: 'tableBlock' },
45
+ // open block, ruler
46
+ { token: 'keyword', regex: /^(?:--|''')\s*$/, next: 'start' },
47
+ { token: 'option', regex: /^\[.*\]\s*$/, next: 'start' },
48
+ { token: 'pageBreak', regex: /^>{3,}$/, next: 'start' },
49
+ { token: 'literal', regex: /^\.{4,}\s*$/, next: 'listingBlock' },
50
+ { token: 'titleUnderline', regex: /^(?:={2,}|-{2,}|~{2,}|\^{2,}|\+{2,})\s*$/, next: 'start' },
51
+ { token: 'singleLineTitle', regex: /^={1,6}\s+\S.*$/, next: 'start' },
52
+
53
+ { token: 'otherBlock', regex: /^(?:\*{2,}|_{2,})\s*$/, next: 'start' },
54
+ // .optional title
55
+ { token: 'optionalTitle', regex: /^\.[^.\s].+$/, next: 'start' },
56
+ ],
57
+
58
+ listStart: [
59
+ {
60
+ token: 'keyword',
61
+ regex: /^\s*(?:\d+\.|[a-zA-Z]\.|[ixvmIXVM]+\)|\*{1,5}|-|\.{1,5})\s/,
62
+ next: 'listText',
63
+ },
64
+ { token: 'meta.tag', regex: /^.+(?::{2,4}|;;)(?: |$)/, next: 'listText' },
65
+ // continuation
66
+ { token: 'keyword', regex: /^\+\s*$/, next: 'start' },
67
+ ],
68
+
69
+ text: [
70
+ {
71
+ token: ['link', 'link'],
72
+ regex: /((?:https?:\/\/|ftp:\/\/|file:\/\/|mailto:|callto:)[^\s\[]+)(\[.*?\])/,
73
+ },
74
+ { token: ['link', 'link'], regex: /(?:https?:\/\/|ftp:\/\/|file:\/\/|mailto:|callto:)[^\s\[]+/ },
75
+ { token: 'link', regex: /\b[\w\.\/\-]+@[\w\.\/\-]+\b/ },
76
+ { include: 'macros' },
77
+ { include: 'paragraphEnd' },
78
+ { token: 'literal', regex: /\+{3,}/, next: 'smallPassthrough' },
79
+ {
80
+ token: 'escape',
81
+ regex: /\((?:C|TM|R)\)|\.{3}|->|<-|=>|<=|&#(?:\d+|x[a-fA-F\d]+);|(?: |^)--(?=\s+\S)/,
82
+ },
83
+ { token: 'escape', regex: /\\[_*'`+#]|\\{2}[_*'`+#]{2}/ },
84
+ { token: 'keyword', regex: /\s\+$/ },
85
+ // any word
86
+ { token: 'text', regex: identifierRe },
87
+ {
88
+ token: ['keyword', 'string', 'keyword'],
89
+ regex: /(<<[\w\d\-$]+,)(.*?)(>>|$)/,
90
+ },
91
+ { token: 'keyword', regex: /<<[\w\d\-$]+,?|>>/ },
92
+ { token: 'constant.character', regex: /\({2,3}.*?\){2,3}/ },
93
+ // List of callouts
94
+ { token: 'support.function.list.callout', regex: /^(?:<\d+>|\d+>|>) /, next: 'text' },
95
+ // Anchor
96
+ { token: 'keyword', regex: /\[\[.+?\]\]/ },
97
+ // bibliography
98
+ { token: 'support', regex: /^\[{3}[\w\d =\-]+\]{3}/ },
99
+
100
+ { include: 'quotes' },
101
+ // text block end
102
+ { token: 'empty', regex: /^\s*$/, next: 'start' },
103
+ ],
104
+
105
+ listText: [{ include: 'listStart' }, { include: 'text' }],
106
+
107
+ indentedBlock: [
108
+ { token: 'literal', regex: /^[\s\w].+$/, next: 'indentedBlock' },
109
+ { token: 'literal', regex: '', next: 'start' },
110
+ ],
111
+
112
+ listingBlock: [
113
+ { token: 'literal', regex: /^\.{4,}\s*$/, next: 'dissallowDelimitedBlock' },
114
+ { token: 'constant.numeric', regex: '<\\d+>' },
115
+ { token: 'literal', regex: '[^<]+' },
116
+ { token: 'literal', regex: '<' },
117
+ ],
118
+ literalBlock: [
119
+ { token: 'literal', regex: /^-{4,}\s*$/, next: 'dissallowDelimitedBlock' },
120
+ { token: 'constant.numeric', regex: '<\\d+>' },
121
+ { token: 'literal', regex: '[^<]+' },
122
+ { token: 'literal', regex: '<' },
123
+ ],
124
+ passthroughBlock: [
125
+ { token: 'literal', regex: /^\+{4,}\s*$/, next: 'dissallowDelimitedBlock' },
126
+ { token: 'literal', regex: identifierRe + '|\\d+' },
127
+ { include: 'macros' },
128
+ { token: 'literal', regex: '.' },
129
+ ],
130
+
131
+ smallPassthrough: [
132
+ { token: 'literal', regex: /[+]{3,}/, next: 'dissallowDelimitedBlock' },
133
+ { token: 'literal', regex: /^\s*$/, next: 'dissallowDelimitedBlock' },
134
+ { token: 'literal', regex: identifierRe + '|\\d+' },
135
+ { include: 'macros' },
136
+ ],
137
+
138
+ commentBlock: [
139
+ { token: 'doc.comment', regex: /^\/{4,}\s*$/, next: 'dissallowDelimitedBlock' },
140
+ { token: 'doc.comment', regex: '^.*$' },
141
+ ],
142
+ tableBlock: [
143
+ { token: 'tableBlock', regex: /^\s*\|={3,}\s*$/, next: 'dissallowDelimitedBlock' },
144
+ { token: 'tableBlock', regex: /^\s*!={3,}\s*$/, next: 'innerTableBlock' },
145
+ { token: 'tableBlock', regex: /\|/ },
146
+ { include: 'text', noEscape: true },
147
+ ],
148
+ innerTableBlock: [
149
+ { token: 'tableBlock', regex: /^\s*!={3,}\s*$/, next: 'tableBlock' },
150
+ { token: 'tableBlock', regex: /^\s*|={3,}\s*$/, next: 'dissallowDelimitedBlock' },
151
+ { token: 'tableBlock', regex: /\!/ },
152
+ ],
153
+ macros: [
154
+ { token: 'macro', regex: /{[\w\-$]+}/ },
155
+ {
156
+ token: ['text', 'string', 'text', 'constant.character', 'text'],
157
+ regex: /({)([\w\-$]+)(:)?(.+)?(})/,
158
+ },
159
+ {
160
+ token: ['text', 'markup.list.macro', 'keyword', 'string'],
161
+ regex: /(\w+)(footnote(?:ref)?::?)([^\s\[]+)?(\[.*?\])?/,
162
+ },
163
+ {
164
+ token: ['markup.list.macro', 'keyword', 'string'],
165
+ regex: /([a-zA-Z\-][\w\.\/\-]*::?)([^\s\[]+)(\[.*?\])?/,
166
+ },
167
+ { token: ['markup.list.macro', 'keyword'], regex: /([a-zA-Z\-][\w\.\/\-]+::?)(\[.*?\])/ },
168
+ { token: 'keyword', regex: /^:.+?:(?= |$)/ },
169
+ ],
170
+
171
+ quotes: [
172
+ { token: 'string.italic', regex: /__[^_\s].*?__/ },
173
+ { token: 'string.italic', regex: quoteRule('_') },
174
+
175
+ { token: 'keyword.bold', regex: /\*\*[^*\s].*?\*\*/ },
176
+ { token: 'keyword.bold', regex: quoteRule('\\*') },
177
+
178
+ { token: 'literal', regex: /\+\+[^+\s].*?\+\+/ },
179
+ { token: 'literal', regex: quoteRule('\\+') },
180
+
181
+ { token: 'literal', regex: /\$\$.+?\$\$/ },
182
+ { token: 'literal', regex: quoteRule('\\$') },
183
+
184
+ { token: 'literal', regex: /``[^`\s].*?``/ },
185
+ { token: 'literal', regex: quoteRule('`') },
186
+
187
+ { token: 'keyword', regex: /\^[^\^].*?\^/ },
188
+ { token: 'keyword', regex: quoteRule('\\^') },
189
+ { token: 'keyword', regex: /~[^~].*?~/ },
190
+ { token: 'keyword', regex: quoteRule('~') },
191
+
192
+ { token: 'keyword', regex: /##?/ },
193
+ { token: 'keyword', regex: /(?:\B|^)``|\b''/ },
194
+ ],
195
+ };
196
+
197
+ function quoteRule(ch) {
198
+ const prefix = /\w/.test(ch) ? '\\b' : '(?:\\B|^)';
199
+ return prefix + ch + '[^' + ch + '].*?' + ch + '(?![\\w*])';
200
+ }
201
+
202
+ // addQuoteBlock("text")
203
+
204
+ const tokenMap = {
205
+ macro: 'constant.character',
206
+ tableBlock: 'doc.comment',
207
+ titleUnderline: 'markup.heading',
208
+ singleLineTitle: 'markup.heading',
209
+ pageBreak: 'string',
210
+ option: 'string.regexp',
211
+ otherBlock: 'markup.list',
212
+ literal: 'support.function',
213
+ optionalTitle: 'constant.numeric',
214
+ escape: 'constant.language.escape',
215
+ link: 'markup.underline.list',
216
+ };
217
+
218
+ for (const state in this.$rules) {
219
+ const stateRules = this.$rules[state];
220
+ for (let i = stateRules.length; i--; ) {
221
+ const rule = stateRules[i];
222
+ if (rule.include || typeof rule === 'string') {
223
+ let args = [i, 1].concat(this.$rules[rule.include || rule]);
224
+ if (rule.noEscape) {
225
+ args = args.filter(function (x) {
226
+ return !x.next;
227
+ });
228
+ }
229
+ stateRules.splice.apply(stateRules, args);
230
+ } else if (rule.token in tokenMap) {
231
+ rule.token = tokenMap[rule.token];
232
+ }
233
+ }
234
+ }
235
+ };
236
+
237
+ // Ace's Syntax Tokenizer.
238
+
239
+ // tokenizing lines longer than this makes editor very slow
240
+ let MAX_TOKEN_COUNT = 1000;
241
+ const Tokenizer = function (rules) {
242
+ this.states = rules;
243
+
244
+ this.regExps = {};
245
+ this.matchMappings = {};
246
+ for (const key in this.states) {
247
+ const state = this.states[key];
248
+ const ruleRegExps = [];
249
+ let matchTotal = 0;
250
+ const mapping = (this.matchMappings[key] = { defaultToken: 'text' });
251
+ let flag = 'g';
252
+
253
+ const splitterRurles = [];
254
+ for (let i = 0; i < state.length; i++) {
255
+ const rule = state[i];
256
+ if (rule.defaultToken) mapping.defaultToken = rule.defaultToken;
257
+ if (rule.caseInsensitive) flag = 'gi';
258
+ if (rule.regex == null) continue;
259
+
260
+ if (rule.regex instanceof RegExp) rule.regex = rule.regex.toString().slice(1, -1);
261
+
262
+ // Count number of matching groups. 2 extra groups from the full match
263
+ // And the catch-all on the end (used to force a match);
264
+ let adjustedregex = rule.regex;
265
+ let matchcount = new RegExp('(?:(' + adjustedregex + ')|(.))').exec('a').length - 2;
266
+ if (Array.isArray(rule.token)) {
267
+ if (rule.token.length === 1 || matchcount === 1) {
268
+ rule.token = rule.token[0];
269
+ } else if (matchcount - 1 !== rule.token.length) {
270
+ throw new Error(
271
+ "number of classes and regexp groups in '" +
272
+ rule.token +
273
+ "'\n'" +
274
+ rule.regex +
275
+ "' doesn't match\n" +
276
+ (matchcount - 1) +
277
+ '!=' +
278
+ rule.token.length,
279
+ );
280
+ } else {
281
+ rule.tokenArray = rule.token;
282
+ rule.token = null;
283
+ rule.onMatch = this.$arrayTokens;
284
+ }
285
+ } else if (typeof rule.token === 'function' && !rule.onMatch) {
286
+ if (matchcount > 1) rule.onMatch = this.$applyToken;
287
+ else rule.onMatch = rule.token;
288
+ }
289
+
290
+ if (matchcount > 1) {
291
+ if (/\\\d/.test(rule.regex)) {
292
+ // Replace any backreferences and offset appropriately.
293
+ adjustedregex = rule.regex.replace(/\\([0-9]+)/g, function (match, digit) {
294
+ return '\\' + (parseInt(digit, 10) + matchTotal + 1);
295
+ });
296
+ } else {
297
+ matchcount = 1;
298
+ adjustedregex = this.removeCapturingGroups(rule.regex);
299
+ }
300
+ if (!rule.splitRegex && typeof rule.token !== 'string')
301
+ // flag will be known only at the very end
302
+ splitterRurles.push(rule);
303
+ }
304
+
305
+ mapping[matchTotal] = i;
306
+ matchTotal += matchcount;
307
+
308
+ ruleRegExps.push(adjustedregex);
309
+
310
+ // makes property access faster
311
+ if (!rule.onMatch) rule.onMatch = null;
312
+ }
313
+
314
+ splitterRurles.forEach(function (rule) {
315
+ rule.splitRegex = this.createSplitterRegexp(rule.regex, flag);
316
+ }, this);
317
+
318
+ this.regExps[key] = new RegExp('(' + ruleRegExps.join(')|(') + ')|($)', flag);
319
+ }
320
+ };
321
+
322
+ (function () {
323
+ this.$setMaxTokenCount = function (m) {
324
+ MAX_TOKEN_COUNT = m | 0;
325
+ };
326
+
327
+ this.$applyToken = function (str) {
328
+ const values = this.splitRegex.exec(str).slice(1);
329
+ const types = this.token.apply(this, values);
330
+
331
+ // required for compatibility with old modes
332
+ if (typeof types === 'string') return [{ type: types, value: str }];
333
+
334
+ const tokens = [];
335
+ for (let i = 0, l = types.length; i < l; i++) {
336
+ if (values[i])
337
+ tokens[tokens.length] = {
338
+ type: types[i],
339
+ value: values[i],
340
+ };
341
+ }
342
+ return tokens;
343
+ };
344
+
345
+ this.$arrayTokens = function (str) {
346
+ if (!str) return [];
347
+ const values = this.splitRegex.exec(str);
348
+ if (!values) return 'text';
349
+ const tokens = [];
350
+ const types = this.tokenArray;
351
+ for (let i = 0, l = types.length; i < l; i++) {
352
+ if (values[i + 1])
353
+ tokens[tokens.length] = {
354
+ type: types[i],
355
+ value: values[i + 1],
356
+ };
357
+ }
358
+ return tokens;
359
+ };
360
+
361
+ this.removeCapturingGroups = function (src) {
362
+ const r = src.replace(/\[(?:\\.|[^\]])*?\]|\\.|\(\?[:=!]|(\()/g, function (x, y) {
363
+ return y ? '(?:' : x;
364
+ });
365
+ return r;
366
+ };
367
+
368
+ this.createSplitterRegexp = function (src, flag) {
369
+ if (src.indexOf('(?=') !== -1) {
370
+ let stack = 0;
371
+ let inChClass = false;
372
+ const lastCapture = {};
373
+ src.replace(/(\\.)|(\((?:\?[=!])?)|(\))|([\[\]])/g, function (m, esc, parenOpen, parenClose, square, index) {
374
+ if (inChClass) {
375
+ inChClass = square !== ']';
376
+ } else if (square) {
377
+ inChClass = true;
378
+ } else if (parenClose) {
379
+ if (stack === lastCapture.stack) {
380
+ lastCapture.end = index + 1;
381
+ lastCapture.stack = -1;
382
+ }
383
+ stack--;
384
+ } else if (parenOpen) {
385
+ stack++;
386
+ if (parenOpen.length !== 1) {
387
+ lastCapture.stack = stack;
388
+ lastCapture.start = index;
389
+ }
390
+ }
391
+ return m;
392
+ });
393
+
394
+ if (lastCapture.end != null && /^\)*$/.test(src.substr(lastCapture.end)))
395
+ src = src.substring(0, lastCapture.start) + src.substr(lastCapture.end);
396
+ }
397
+ return new RegExp(src, (flag || '').replace('g', ''));
398
+ };
399
+
400
+ /**
401
+ * Returns an object containing two properties: `tokens`, which contains all the tokens; and `state`, the current state.
402
+ * @returns {Object}
403
+ **/
404
+ this.getLineTokens = function (line, startState) {
405
+ let stack = [];
406
+ if (startState && typeof startState !== 'string') {
407
+ stack = startState.slice(0);
408
+ startState = stack[0];
409
+ }
410
+
411
+ let currentState = startState || 'start';
412
+ let state = this.states[currentState];
413
+ if (!state) {
414
+ currentState = 'start';
415
+ state = this.states[currentState];
416
+ }
417
+ let mapping = this.matchMappings[currentState];
418
+ let re = this.regExps[currentState];
419
+ re.lastIndex = 0;
420
+
421
+ let match;
422
+ const tokens = [];
423
+ let lastIndex = 0;
424
+
425
+ let token = { type: null, value: '' };
426
+
427
+ /* eslint no-cond-assign: "off" */
428
+ while ((match = re.exec(line))) {
429
+ let type = mapping.defaultToken;
430
+ let rule = null;
431
+ const value = match[0];
432
+ const index = re.lastIndex;
433
+
434
+ if (index - value.length > lastIndex) {
435
+ const skipped = line.substring(lastIndex, index - value.length);
436
+ if (token.type === type) {
437
+ token.value += skipped;
438
+ } else {
439
+ if (token.type) tokens.push(token);
440
+ token = { type: type, value: skipped };
441
+ }
442
+ }
443
+
444
+ for (let i = 0; i < match.length - 2; i++) {
445
+ if (match[i + 1] === undefined) continue;
446
+
447
+ rule = state[mapping[i]];
448
+
449
+ if (rule.onMatch) type = rule.onMatch(value, currentState, stack);
450
+ else type = rule.token;
451
+
452
+ if (rule.next) {
453
+ if (typeof rule.next === 'string') currentState = rule.next;
454
+ else currentState = rule.next(currentState, stack);
455
+
456
+ state = this.states[currentState];
457
+ if (!state) {
458
+ window.console && console.error && console.error(currentState, "doesn't exist");
459
+ currentState = 'start';
460
+ state = this.states[currentState];
461
+ }
462
+ mapping = this.matchMappings[currentState];
463
+ lastIndex = index;
464
+ re = this.regExps[currentState];
465
+ re.lastIndex = index;
466
+ }
467
+ break;
468
+ }
469
+
470
+ if (value) {
471
+ if (typeof type === 'string') {
472
+ if ((!rule || rule.merge !== false) && token.type === type) {
473
+ token.value += value;
474
+ } else {
475
+ if (token.type) tokens.push(token);
476
+ token = { type: type, value: value };
477
+ }
478
+ } else if (type) {
479
+ if (token.type) tokens.push(token);
480
+ token = { type: null, value: '' };
481
+ for (let i = 0; i < type.length; i++) tokens.push(type[i]);
482
+ }
483
+ }
484
+
485
+ if (lastIndex === line.length) break;
486
+
487
+ lastIndex = index;
488
+
489
+ if (tokens.length > MAX_TOKEN_COUNT) {
490
+ // chrome doens't show contents of text nodes with very long text
491
+ while (lastIndex < line.length) {
492
+ if (token.type) tokens.push(token);
493
+ token = {
494
+ value: line.substring(lastIndex, (lastIndex += 2000)),
495
+ type: 'overflow',
496
+ };
497
+ }
498
+ currentState = 'start';
499
+ stack = [];
500
+ break;
501
+ }
502
+ }
503
+
504
+ if (token.type) tokens.push(token);
505
+
506
+ if (stack.length > 1) {
507
+ if (stack[0] !== currentState) stack.unshift(currentState);
508
+ }
509
+ return {
510
+ tokens: tokens,
511
+ state: stack.length ? stack : currentState,
512
+ };
513
+ };
514
+ }.call(Tokenizer.prototype));
515
+
516
+ // Token conversion.
517
+ // See <https://github.com/ajaxorg/ace/wiki/Creating-or-Extending-an-Edit-Mode#common-tokens>
518
+ // This is not an exact match nor the best match that can be made.
519
+ const tokenFromAceToken = {
520
+ empty: null,
521
+ text: null,
522
+
523
+ // Keyword
524
+ keyword: 'keyword',
525
+ control: 'keyword',
526
+ operator: 'operator',
527
+
528
+ // Constants
529
+ constant: 'atom',
530
+ numeric: 'number',
531
+ character: 'atom',
532
+ escape: 'atom',
533
+
534
+ // Variables
535
+ variable: 'variable',
536
+ parameter: 'variable-3',
537
+ // Python's `self` uses that.
538
+ language: 'variable-2',
539
+
540
+ // Comments
541
+ comment: 'comment',
542
+ line: 'comment',
543
+ 'double-slash': 'comment',
544
+ 'double-dash': 'comment',
545
+ 'number-sign': 'comment',
546
+ percentage: 'comment',
547
+ block: 'comment',
548
+ doc: 'comment',
549
+
550
+ // String
551
+ string: 'string',
552
+ quoted: 'string',
553
+ single: 'string',
554
+ double: 'string',
555
+ triple: 'string',
556
+ unquoted: 'string',
557
+ interpolated: 'string',
558
+ regexp: 'string-2',
559
+
560
+ meta: 'keyword',
561
+ literal: 'qualifier',
562
+ support: 'builtin',
563
+
564
+ // Markup
565
+ markup: 'tag',
566
+ underline: 'link',
567
+ link: 'link',
568
+ strong: 'strong',
569
+ heading: 'header',
570
+ em: 'em',
571
+ list: 'variable-2',
572
+ numbered: 'variable-2',
573
+ unnumbered: 'variable-2',
574
+ quote: 'quote',
575
+ // Markdown's raw block uses that.
576
+ raw: 'variable-2',
577
+
578
+ // Invalid
579
+ invalid: 'error',
580
+ illegal: 'invalidchar',
581
+ deprecated: 'error',
582
+ };
583
+
584
+ // Takes a list of Ace tokens, returns a (string) CodeMirror token.
585
+ const cmTokenFromAceTokens = function (tokens) {
586
+ let token = null;
587
+ for (let i = 0; i < tokens.length; i++) {
588
+ // Find the most specific token.
589
+ if (tokenFromAceToken[tokens[i]] !== undefined) {
590
+ token = tokenFromAceToken[tokens[i]];
591
+ }
592
+ }
593
+ return token;
594
+ };
595
+
596
+ // Consume a token from plannedTokens.
597
+ const consumeToken = function (stream, state) {
598
+ const plannedToken = state.plannedTokens.shift();
599
+ if (plannedToken === undefined) {
600
+ return null;
601
+ }
602
+ stream.match(plannedToken.value);
603
+ const tokens = plannedToken.type.split('.');
604
+ return cmTokenFromAceTokens(tokens);
605
+ };
606
+
607
+ const matchToken = function (stream, state) {
608
+ // Anormal start: we already have planned tokens to consume.
609
+ if (state.plannedTokens.length > 0) {
610
+ return consumeToken(stream, state);
611
+ }
612
+
613
+ // Normal start.
614
+ const currentState = state.current;
615
+ const currentLine = stream.match(/.*$/, false)[0];
616
+ const tokenized = tokenizer.getLineTokens(currentLine, currentState);
617
+ // We got a {tokens, state} object.
618
+ // Each token is a {value, type} object.
619
+ state.plannedTokens = tokenized.tokens;
620
+ state.current = tokenized.state;
621
+
622
+ // Consume a token.
623
+ return consumeToken(stream, state);
624
+ };
625
+
626
+ // Initialize all state.
627
+ const aceHighlightRules = new HighlightRules();
628
+ const tokenizer = new Tokenizer(aceHighlightRules.$rules);
629
+
630
+ export const asciidoc = {
631
+ startState: function () {
632
+ return {
633
+ current: 'start',
634
+ // List of {value, type}, with type being an Ace token string.
635
+ plannedTokens: [],
636
+ };
637
+ },
638
+ blankLine: function (state) {
639
+ matchToken('', state);
640
+ },
641
+ token: matchToken,
642
+ };