@elice/material-exercise 1.220919.0 → 1.220920.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 (21) hide show
  1. package/cjs/components/shared/monaco-editor/utils/emmet/abbreviationActions.d.ts +6 -0
  2. package/cjs/components/shared/monaco-editor/utils/emmet/abbreviationActions.js +65 -0
  3. package/cjs/components/shared/monaco-editor/utils/emmet/emmet.d.ts +4 -4
  4. package/cjs/components/shared/monaco-editor/utils/emmet/emmet.js +6 -6
  5. package/cjs/components/shared/monaco-editor/utils/emmet/registerProvider.d.ts +2 -2
  6. package/cjs/components/shared/monaco-editor/utils/emmet/registerProvider.js +5 -4
  7. package/cjs/components/shared/monaco-editor/vendors/vscode-emmet-helper/emmetHelper.d.ts +7 -11
  8. package/cjs/components/shared/monaco-editor/vendors/vscode-emmet-helper/emmetHelper.js +13 -17
  9. package/cjs/components/shared/monaco-editor/vendors/vscode-emmet-helper/utils.d.ts +9 -4
  10. package/cjs/components/shared/monaco-editor/vendors/vscode-emmet-helper/utils.js +13 -7
  11. package/es/components/shared/monaco-editor/utils/emmet/abbreviationActions.d.ts +6 -0
  12. package/es/components/shared/monaco-editor/utils/emmet/abbreviationActions.js +61 -0
  13. package/es/components/shared/monaco-editor/utils/emmet/emmet.d.ts +4 -4
  14. package/es/components/shared/monaco-editor/utils/emmet/emmet.js +6 -6
  15. package/es/components/shared/monaco-editor/utils/emmet/registerProvider.d.ts +2 -2
  16. package/es/components/shared/monaco-editor/utils/emmet/registerProvider.js +5 -4
  17. package/es/components/shared/monaco-editor/vendors/vscode-emmet-helper/emmetHelper.d.ts +7 -11
  18. package/es/components/shared/monaco-editor/vendors/vscode-emmet-helper/emmetHelper.js +13 -17
  19. package/es/components/shared/monaco-editor/vendors/vscode-emmet-helper/utils.d.ts +9 -4
  20. package/es/components/shared/monaco-editor/vendors/vscode-emmet-helper/utils.js +13 -7
  21. package/package.json +4 -4
@@ -0,0 +1,6 @@
1
+ import type * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
2
+ /**
3
+ * VSCode did a complex node analysis, just use monaco's built-in tokenizer here.
4
+ * @see https://github.com/microsoft/vscode/blob/50140a53cc2088f478a5560683ccd354f2d5f431/extensions/emmet/src/abbreviationActions.ts#L438
5
+ */
6
+ export declare function isValidLocationForEmmetAbbreviation(model: monaco.editor.ITextModel, position: monaco.Position, syntax: string, language: string): boolean;
@@ -0,0 +1,65 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ /**
6
+ * Validate if the given position is valid for emmet abbreviation.
7
+ */
8
+ function isValidEmmetToken(tokens, index, syntax, language) {
9
+ const currentTokenType = tokens[index].type;
10
+
11
+ switch (syntax) {
12
+ case 'html':
13
+ return currentTokenType === 'text.html.basic';
14
+
15
+ case 'css':
16
+ return true;
17
+
18
+ case 'jsx':
19
+ return !currentTokenType.endsWith('.type.tsx');
20
+
21
+ default:
22
+ return false;
23
+ }
24
+ }
25
+ /**
26
+ * VSCode did a complex node analysis, just use monaco's built-in tokenizer here.
27
+ * @see https://github.com/microsoft/vscode/blob/50140a53cc2088f478a5560683ccd354f2d5f431/extensions/emmet/src/abbreviationActions.ts#L438
28
+ */
29
+
30
+
31
+ function isValidLocationForEmmetAbbreviation(model, position, syntax, language) {
32
+ const {
33
+ column,
34
+ lineNumber
35
+ } = position; // get current line's tokens
36
+
37
+ const _tokenization = // monaco-editor < 0.34.0
38
+ model._tokenization || // monaco-editor >= 0.34.0
39
+ model.tokenization._tokenization;
40
+
41
+ const _tokenizationStateStore = _tokenization._tokenizationStateStore;
42
+
43
+ const _tokenizationSupport = // monaco-editor >= 0.32.0
44
+ _tokenizationStateStore.tokenizationSupport || // monaco-editor < 0.32.0
45
+ _tokenization._tokenizationSupport;
46
+
47
+ const state = _tokenizationStateStore.getBeginState(lineNumber - 1).clone();
48
+
49
+ const tokenizationResult = _tokenizationSupport.tokenize(model.getLineContent(lineNumber), true, state, 0);
50
+
51
+ const tokens = tokenizationResult.tokens; // get token type at current column
52
+
53
+ for (let i = tokens.length - 1; i >= 0; i--) {
54
+ if (column - 1 > tokens[i].offset) {
55
+ // return true if current token is valid for emmet
56
+ if (isValidEmmetToken(tokens, i, syntax)) {
57
+ return true;
58
+ }
59
+ }
60
+ }
61
+
62
+ return false;
63
+ }
64
+
65
+ exports.isValidLocationForEmmetAbbreviation = isValidLocationForEmmetAbbreviation;
@@ -1,13 +1,13 @@
1
- import type * as Monaco from 'monaco-editor';
1
+ import type * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
2
2
  /**
3
3
  * Enable emmet feature for HTML.
4
4
  */
5
- export declare function emmetHTML(monaco: typeof Monaco, languages: string[]): (() => void) | undefined;
5
+ export declare function emmetHTML(_monaco: typeof monaco, languages: string[]): (() => void) | undefined;
6
6
  /**
7
7
  * Enable emmet feature for CSS.
8
8
  */
9
- export declare function emmetCSS(monaco: typeof Monaco, languages: string[]): (() => void) | undefined;
9
+ export declare function emmetCSS(_monaco: typeof monaco, languages: string[]): (() => void) | undefined;
10
10
  /**
11
11
  * Enable emmet feature for JSX.
12
12
  */
13
- export declare function emmetJSX(monaco: typeof Monaco, languages: string[]): (() => void) | undefined;
13
+ export declare function emmetJSX(_monaco: typeof monaco, languages: string[]): (() => void) | undefined;
@@ -8,22 +8,22 @@ var registerProvider = require('./registerProvider.js');
8
8
  * Enable emmet feature for HTML.
9
9
  */
10
10
 
11
- function emmetHTML(monaco, languages) {
12
- return registerProvider.registerProvider(monaco, languages, 'html');
11
+ function emmetHTML(_monaco, languages) {
12
+ return registerProvider.registerProvider(_monaco, languages, 'html');
13
13
  }
14
14
  /**
15
15
  * Enable emmet feature for CSS.
16
16
  */
17
17
 
18
- function emmetCSS(monaco, languages) {
19
- return registerProvider.registerProvider(monaco, languages, 'css');
18
+ function emmetCSS(_monaco, languages) {
19
+ return registerProvider.registerProvider(_monaco, languages, 'css');
20
20
  }
21
21
  /**
22
22
  * Enable emmet feature for JSX.
23
23
  */
24
24
 
25
- function emmetJSX(monaco, languages) {
26
- return registerProvider.registerProvider(monaco, languages, 'jsx');
25
+ function emmetJSX(_monaco, languages) {
26
+ return registerProvider.registerProvider(_monaco, languages, 'jsx');
27
27
  }
28
28
 
29
29
  exports.emmetCSS = emmetCSS;
@@ -1,5 +1,5 @@
1
- import type * as Monaco from 'monaco-editor';
1
+ import type * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
2
2
  /**
3
3
  * Register completion provider of emmet.
4
4
  */
5
- export declare function registerProvider(monaco: typeof Monaco, languages: string[], syntax: string): (() => void) | undefined;
5
+ export declare function registerProvider(_monaco: typeof monaco, languages: string[], syntax: string): (() => void) | undefined;
@@ -4,19 +4,20 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var emmetHelper = require('../../vendors/vscode-emmet-helper/emmetHelper.js');
6
6
  var utils = require('../../vendors/vscode-emmet-helper/utils.js');
7
+ var abbreviationActions = require('./abbreviationActions.js');
7
8
 
8
9
  /**
9
10
  * Register completion provider of emmet.
10
11
  */
11
12
 
12
- function registerProvider(monaco, languages, syntax) {
13
- if (!monaco) {
13
+ function registerProvider(_monaco, languages, syntax) {
14
+ if (!_monaco) {
14
15
  return;
15
16
  }
16
17
 
17
- const providers = languages.map(language => monaco.languages.registerCompletionItemProvider(language, {
18
+ const providers = languages.map(language => _monaco.languages.registerCompletionItemProvider(language, {
18
19
  triggerCharacters: utils.LANGUAGE_MODES[utils.MAPPED_MODES[language] || language],
19
- provideCompletionItems: (model, position) => emmetHelper.doComplete(monaco, model, position, syntax, utils.DEFAULT_CONFIG)
20
+ provideCompletionItems: (model, position) => abbreviationActions.isValidLocationForEmmetAbbreviation(model, position, syntax) ? emmetHelper.doComplete(_monaco, model, position, syntax, utils.DEFAULT_CONFIG) : undefined
20
21
  }));
21
22
  return () => {
22
23
  providers.forEach(provider => provider.dispose());
@@ -1,10 +1,10 @@
1
- import type * as Monaco from 'monaco-editor';
1
+ import type * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
2
2
  import type { ExtractOptions, MarkupAbbreviation, Options, StylesheetAbbreviation, SyntaxType, UserConfig } from 'emmet';
3
3
  import type { SnippetsMap } from './configCompat';
4
- declare type TextModel = Monaco.editor.ITextModel;
5
- declare type CompletionList = Monaco.languages.CompletionList;
6
- declare type Position = Monaco.IPosition;
7
- declare type Range = Monaco.IRange;
4
+ declare type TextModel = monaco.editor.ITextModel;
5
+ declare type CompletionList = monaco.languages.CompletionList;
6
+ declare type Position = monaco.IPosition;
7
+ declare type Range = monaco.IRange;
8
8
  /**
9
9
  * Emmet configuration as derived from the Emmet related VS Code settings
10
10
  */
@@ -19,12 +19,8 @@ export interface VSCodeEmmetConfig {
19
19
  }
20
20
  /**
21
21
  * Returns all applicable emmet expansions for abbreviation at given position in a CompletionList
22
- * @param document TextDocument in which completions are requested
23
- * @param position Position in the document at which completions are requested
24
- * @param syntax Emmet supported language
25
- * @param emmetConfig Emmet Configurations as derived from VS Code
26
22
  */
27
- export declare function doComplete(monaco: typeof Monaco, model: TextModel, position: Position, syntax: string, emmetConfig: VSCodeEmmetConfig): CompletionList | undefined;
23
+ export declare function doComplete(_monaco: typeof monaco, model: TextModel, position: Position, syntax: string, emmetConfig: VSCodeEmmetConfig): CompletionList | undefined;
28
24
  export declare const emmetSnippetField: (index: number, placeholder: string) => string;
29
25
  /** Returns whether or not syntax is a supported stylesheet syntax, like CSS */
30
26
  export declare function isStyleSheet(syntax: string): boolean;
@@ -37,7 +33,7 @@ export declare function getDefaultSnippets(syntax: string): SnippetsMap;
37
33
  /**
38
34
  * Extracts abbreviation from the given position in the given document
39
35
  */
40
- export declare function extractAbbreviation(monaco: typeof Monaco, model: TextModel, position: Position, options?: Partial<ExtractOptions>): {
36
+ export declare function extractAbbreviation(_monaco: typeof monaco, model: TextModel, position: Position, options?: Partial<ExtractOptions>): {
41
37
  abbreviation: string;
42
38
  abbreviationRange: Range;
43
39
  filter: string | undefined;
@@ -37,13 +37,9 @@ const commentFilterSuffix = 'c';
37
37
  const maxFilters = 3;
38
38
  /**
39
39
  * Returns all applicable emmet expansions for abbreviation at given position in a CompletionList
40
- * @param document TextDocument in which completions are requested
41
- * @param position Position in the document at which completions are requested
42
- * @param syntax Emmet supported language
43
- * @param emmetConfig Emmet Configurations as derived from VS Code
44
40
  */
45
41
 
46
- function doComplete(monaco, model, position, syntax, emmetConfig) {
42
+ function doComplete(_monaco, model, position, syntax, emmetConfig) {
47
43
  var _a, _b;
48
44
 
49
45
  if (emmetConfig.showExpandedAbbreviation === 'never' || !getEmmetMode(syntax, emmetConfig.excludeLanguages)) {
@@ -66,7 +62,7 @@ function doComplete(monaco, model, position, syntax, emmetConfig) {
66
62
  lookAhead: !isStyleSheetRes,
67
63
  type: isStyleSheetRes ? 'stylesheet' : 'markup'
68
64
  };
69
- const extractedValue = extractAbbreviation(monaco, model, position, extractOptions);
65
+ const extractedValue = extractAbbreviation(_monaco, model, position, extractOptions);
70
66
 
71
67
  if (!extractedValue) {
72
68
  return;
@@ -108,11 +104,11 @@ function doComplete(monaco, model, position, syntax, emmetConfig) {
108
104
  }
109
105
 
110
106
  expandedAbbr = {
111
- kind: monaco.languages.CompletionItemKind.Property,
107
+ kind: _monaco.languages.CompletionItemKind.Property,
112
108
  label: abbreviation + (filter ? '|' + filter.replace(',', '|') : ''),
113
109
  documentation: replaceTabStopsWithCursors(expandedText),
114
110
  detail: 'Emmet abbreviation',
115
- insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
111
+ insertTextRules: _monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
116
112
  range: abbreviationRange,
117
113
  insertText: escapeNonTabStopDollar(addFinalTabStop(expandedText))
118
114
  };
@@ -137,7 +133,7 @@ function doComplete(monaco, model, position, syntax, emmetConfig) {
137
133
  expandedAbbr.filterText = abbreviation; // Custom snippets should show up in completions if abbreviation is a prefix
138
134
 
139
135
  const stylesheetCustomSnippetsKeys = stylesheetCustomSnippetsKeyCache.has(syntax) ? stylesheetCustomSnippetsKeyCache.get(syntax) : stylesheetCustomSnippetsKeyCache.get('css');
140
- completionItems = makeSnippetSuggestion(monaco, stylesheetCustomSnippetsKeys !== null && stylesheetCustomSnippetsKeys !== void 0 ? stylesheetCustomSnippetsKeys : [], abbreviation, abbreviation, abbreviationRange, expandOptions, 'Emmet Custom Snippet', false);
136
+ completionItems = makeSnippetSuggestion(_monaco, stylesheetCustomSnippetsKeys !== null && stylesheetCustomSnippetsKeys !== void 0 ? stylesheetCustomSnippetsKeys : [], abbreviation, abbreviation, abbreviationRange, expandOptions, 'Emmet Custom Snippet', false);
141
137
 
142
138
  if (!completionItems.find(x => x.insertText === (expandedAbbr === null || expandedAbbr === void 0 ? void 0 : expandedAbbr.insertText))) {
143
139
  // Fix for https://github.com/Microsoft/vscode/issues/28933#issuecomment-309236902
@@ -160,12 +156,12 @@ function doComplete(monaco, model, position, syntax, emmetConfig) {
160
156
  }
161
157
 
162
158
  if (syntax !== 'xml') {
163
- const commonlyUsedTagSuggestions = makeSnippetSuggestion(monaco, commonlyUsedTags, tagToFindMoreSuggestionsFor, abbreviation, abbreviationRange, expandOptions, 'Emmet Abbreviation');
159
+ const commonlyUsedTagSuggestions = makeSnippetSuggestion(_monaco, commonlyUsedTags, tagToFindMoreSuggestionsFor, abbreviation, abbreviationRange, expandOptions, 'Emmet Abbreviation');
164
160
  completionItems = completionItems.concat(commonlyUsedTagSuggestions);
165
161
  }
166
162
 
167
163
  if (emmetConfig.showAbbreviationSuggestions === true) {
168
- const abbreviationSuggestions = makeSnippetSuggestion(monaco, markupSnippetKeys.filter(x => !commonlyUsedTags.includes(x)), tagToFindMoreSuggestionsFor, abbreviation, abbreviationRange, expandOptions, 'Emmet Abbreviation'); // Workaround for the main expanded abbr not appearing before the snippet suggestions
164
+ const abbreviationSuggestions = makeSnippetSuggestion(_monaco, markupSnippetKeys.filter(x => !commonlyUsedTags.includes(x)), tagToFindMoreSuggestionsFor, abbreviation, abbreviationRange, expandOptions, 'Emmet Abbreviation'); // Workaround for the main expanded abbr not appearing before the snippet suggestions
169
165
 
170
166
  if (expandedAbbr && abbreviationSuggestions.length > 0 && tagToFindMoreSuggestionsFor !== abbreviation) {
171
167
  expandedAbbr.sortText = '0' + expandedAbbr.label;
@@ -187,7 +183,7 @@ function doComplete(monaco, model, position, syntax, emmetConfig) {
187
183
  }
188
184
 
189
185
  if (emmetConfig.showSuggestionsAsSnippets === true) {
190
- completionItems.forEach(x => x.kind = monaco.languages.CompletionItemKind.Snippet);
186
+ completionItems.forEach(x => x.kind = _monaco.languages.CompletionItemKind.Snippet);
191
187
  }
192
188
 
193
189
  return completionItems.length ? {
@@ -199,7 +195,7 @@ function doComplete(monaco, model, position, syntax, emmetConfig) {
199
195
  * Create & return snippets for snippet keys that start with given prefix
200
196
  */
201
197
 
202
- function makeSnippetSuggestion(monaco, snippetKeys, prefix, abbreviation, abbreviationRange, expandOptions, snippetDetail, skipFullMatch = true) {
198
+ function makeSnippetSuggestion(_monaco, snippetKeys, prefix, abbreviation, abbreviationRange, expandOptions, snippetDetail, skipFullMatch = true) {
203
199
  if (!prefix || !snippetKeys) {
204
200
  return [];
205
201
  }
@@ -222,11 +218,11 @@ function makeSnippetSuggestion(monaco, snippetKeys, prefix, abbreviation, abbrev
222
218
  }
223
219
 
224
220
  const item = {
225
- kind: monaco.languages.CompletionItemKind.Property,
221
+ kind: _monaco.languages.CompletionItemKind.Property,
226
222
  label: prefix + snippetKey.substr(prefix.length),
227
223
  documentation: replaceTabStopsWithCursors(expandedAbbr),
228
224
  detail: snippetDetail,
229
- insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
225
+ insertTextRules: _monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
230
226
  range: abbreviationRange,
231
227
  insertText: escapeNonTabStopDollar(addFinalTabStop(expandedAbbr))
232
228
  };
@@ -407,7 +403,7 @@ function getFilters(text, pos) {
407
403
  */
408
404
 
409
405
 
410
- function extractAbbreviation(monaco, model, position, options) {
406
+ function extractAbbreviation(_monaco, model, position, options) {
411
407
  const currentLine = model.getLineContent(position.lineNumber);
412
408
  const currentLineTillPosition = currentLine.substr(0, position.column - 1);
413
409
  const {
@@ -421,7 +417,7 @@ function extractAbbreviation(monaco, model, position, options) {
421
417
  return;
422
418
  }
423
419
 
424
- const rangeToReplace = new monaco.Range(position.lineNumber, result.location + 1, position.lineNumber, result.location + result.abbreviation.length + lengthOccupiedByFilter + 1);
420
+ const rangeToReplace = new _monaco.Range(position.lineNumber, result.location + 1, position.lineNumber, result.location + result.abbreviation.length + lengthOccupiedByFilter + 1);
425
421
  return {
426
422
  abbreviationRange: rangeToReplace,
427
423
  abbreviation: result.abbreviation,
@@ -1,12 +1,17 @@
1
- import { VSCodeEmmetConfig } from "./emmetHelper";
1
+ import type { VSCodeEmmetConfig } from './emmetHelper';
2
2
  /**
3
- * -ref: https://github.com/microsoft/vscode/blob/main/extensions/emmet/src/util.ts#L86
3
+ * Default emmet configuration.
4
+ */
5
+ export declare const DEFAULT_CONFIG: VSCodeEmmetConfig;
6
+ /**
7
+ * Mapping between languages that support Emmet and completion trigger characters.
8
+ * - ref: https://github.com/microsoft/vscode/blob/50140a53cc2088f478a5560683ccd354f2d5f431/extensions/emmet/src/util.ts#L86
4
9
  */
5
10
  export declare const LANGUAGE_MODES: {
6
11
  [id: string]: string[];
7
12
  };
8
13
  /**
9
- * https://github.com/microsoft/vscode/blob/main/extensions/emmet/src/util.ts#L124
14
+ * Language specific extensions can provide emmet completion support.
15
+ * - ref: https://github.com/microsoft/vscode/blob/50140a53cc2088f478a5560683ccd354f2d5f431/extensions/emmet/src/util.ts#L124
10
16
  */
11
17
  export declare const MAPPED_MODES: Record<string, string>;
12
- export declare const DEFAULT_CONFIG: VSCodeEmmetConfig;
@@ -5,8 +5,18 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  /* eslint-disable */
6
6
 
7
7
  /**
8
- * -ref: https://github.com/microsoft/vscode/blob/main/extensions/emmet/src/util.ts#L86
8
+ * Default emmet configuration.
9
9
  */
10
+ const DEFAULT_CONFIG = {
11
+ showExpandedAbbreviation: 'always',
12
+ showAbbreviationSuggestions: true,
13
+ showSuggestionsAsSnippets: false
14
+ };
15
+ /**
16
+ * Mapping between languages that support Emmet and completion trigger characters.
17
+ * - ref: https://github.com/microsoft/vscode/blob/50140a53cc2088f478a5560683ccd354f2d5f431/extensions/emmet/src/util.ts#L86
18
+ */
19
+
10
20
  const LANGUAGE_MODES = {
11
21
  html: ['!', '.', '}', ':', '*', '$', ']', '/', '>', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'],
12
22
  jade: ['!', '.', '}', ':', '*', '$', ']', '/', '>', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'],
@@ -23,7 +33,8 @@ const LANGUAGE_MODES = {
23
33
  typescript: ['!', '.', '}', '*', '$', ']', '/', '>', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
24
34
  };
25
35
  /**
26
- * https://github.com/microsoft/vscode/blob/main/extensions/emmet/src/util.ts#L124
36
+ * Language specific extensions can provide emmet completion support.
37
+ * - ref: https://github.com/microsoft/vscode/blob/50140a53cc2088f478a5560683ccd354f2d5f431/extensions/emmet/src/util.ts#L124
27
38
  */
28
39
 
29
40
  const MAPPED_MODES = {
@@ -31,11 +42,6 @@ const MAPPED_MODES = {
31
42
  php: 'html',
32
43
  twig: 'html'
33
44
  };
34
- const DEFAULT_CONFIG = {
35
- showExpandedAbbreviation: 'always',
36
- showAbbreviationSuggestions: true,
37
- showSuggestionsAsSnippets: false
38
- };
39
45
 
40
46
  exports.DEFAULT_CONFIG = DEFAULT_CONFIG;
41
47
  exports.LANGUAGE_MODES = LANGUAGE_MODES;
@@ -0,0 +1,6 @@
1
+ import type * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
2
+ /**
3
+ * VSCode did a complex node analysis, just use monaco's built-in tokenizer here.
4
+ * @see https://github.com/microsoft/vscode/blob/50140a53cc2088f478a5560683ccd354f2d5f431/extensions/emmet/src/abbreviationActions.ts#L438
5
+ */
6
+ export declare function isValidLocationForEmmetAbbreviation(model: monaco.editor.ITextModel, position: monaco.Position, syntax: string, language: string): boolean;
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Validate if the given position is valid for emmet abbreviation.
3
+ */
4
+ function isValidEmmetToken(tokens, index, syntax, language) {
5
+ const currentTokenType = tokens[index].type;
6
+
7
+ switch (syntax) {
8
+ case 'html':
9
+ return currentTokenType === 'text.html.basic';
10
+
11
+ case 'css':
12
+ return true;
13
+
14
+ case 'jsx':
15
+ return !currentTokenType.endsWith('.type.tsx');
16
+
17
+ default:
18
+ return false;
19
+ }
20
+ }
21
+ /**
22
+ * VSCode did a complex node analysis, just use monaco's built-in tokenizer here.
23
+ * @see https://github.com/microsoft/vscode/blob/50140a53cc2088f478a5560683ccd354f2d5f431/extensions/emmet/src/abbreviationActions.ts#L438
24
+ */
25
+
26
+
27
+ function isValidLocationForEmmetAbbreviation(model, position, syntax, language) {
28
+ const {
29
+ column,
30
+ lineNumber
31
+ } = position; // get current line's tokens
32
+
33
+ const _tokenization = // monaco-editor < 0.34.0
34
+ model._tokenization || // monaco-editor >= 0.34.0
35
+ model.tokenization._tokenization;
36
+
37
+ const _tokenizationStateStore = _tokenization._tokenizationStateStore;
38
+
39
+ const _tokenizationSupport = // monaco-editor >= 0.32.0
40
+ _tokenizationStateStore.tokenizationSupport || // monaco-editor < 0.32.0
41
+ _tokenization._tokenizationSupport;
42
+
43
+ const state = _tokenizationStateStore.getBeginState(lineNumber - 1).clone();
44
+
45
+ const tokenizationResult = _tokenizationSupport.tokenize(model.getLineContent(lineNumber), true, state, 0);
46
+
47
+ const tokens = tokenizationResult.tokens; // get token type at current column
48
+
49
+ for (let i = tokens.length - 1; i >= 0; i--) {
50
+ if (column - 1 > tokens[i].offset) {
51
+ // return true if current token is valid for emmet
52
+ if (isValidEmmetToken(tokens, i, syntax)) {
53
+ return true;
54
+ }
55
+ }
56
+ }
57
+
58
+ return false;
59
+ }
60
+
61
+ export { isValidLocationForEmmetAbbreviation };
@@ -1,13 +1,13 @@
1
- import type * as Monaco from 'monaco-editor';
1
+ import type * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
2
2
  /**
3
3
  * Enable emmet feature for HTML.
4
4
  */
5
- export declare function emmetHTML(monaco: typeof Monaco, languages: string[]): (() => void) | undefined;
5
+ export declare function emmetHTML(_monaco: typeof monaco, languages: string[]): (() => void) | undefined;
6
6
  /**
7
7
  * Enable emmet feature for CSS.
8
8
  */
9
- export declare function emmetCSS(monaco: typeof Monaco, languages: string[]): (() => void) | undefined;
9
+ export declare function emmetCSS(_monaco: typeof monaco, languages: string[]): (() => void) | undefined;
10
10
  /**
11
11
  * Enable emmet feature for JSX.
12
12
  */
13
- export declare function emmetJSX(monaco: typeof Monaco, languages: string[]): (() => void) | undefined;
13
+ export declare function emmetJSX(_monaco: typeof monaco, languages: string[]): (() => void) | undefined;
@@ -4,22 +4,22 @@ import { registerProvider } from './registerProvider.js';
4
4
  * Enable emmet feature for HTML.
5
5
  */
6
6
 
7
- function emmetHTML(monaco, languages) {
8
- return registerProvider(monaco, languages, 'html');
7
+ function emmetHTML(_monaco, languages) {
8
+ return registerProvider(_monaco, languages, 'html');
9
9
  }
10
10
  /**
11
11
  * Enable emmet feature for CSS.
12
12
  */
13
13
 
14
- function emmetCSS(monaco, languages) {
15
- return registerProvider(monaco, languages, 'css');
14
+ function emmetCSS(_monaco, languages) {
15
+ return registerProvider(_monaco, languages, 'css');
16
16
  }
17
17
  /**
18
18
  * Enable emmet feature for JSX.
19
19
  */
20
20
 
21
- function emmetJSX(monaco, languages) {
22
- return registerProvider(monaco, languages, 'jsx');
21
+ function emmetJSX(_monaco, languages) {
22
+ return registerProvider(_monaco, languages, 'jsx');
23
23
  }
24
24
 
25
25
  export { emmetCSS, emmetHTML, emmetJSX };
@@ -1,5 +1,5 @@
1
- import type * as Monaco from 'monaco-editor';
1
+ import type * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
2
2
  /**
3
3
  * Register completion provider of emmet.
4
4
  */
5
- export declare function registerProvider(monaco: typeof Monaco, languages: string[], syntax: string): (() => void) | undefined;
5
+ export declare function registerProvider(_monaco: typeof monaco, languages: string[], syntax: string): (() => void) | undefined;
@@ -1,18 +1,19 @@
1
1
  import { doComplete } from '../../vendors/vscode-emmet-helper/emmetHelper.js';
2
2
  import { LANGUAGE_MODES, MAPPED_MODES, DEFAULT_CONFIG } from '../../vendors/vscode-emmet-helper/utils.js';
3
+ import { isValidLocationForEmmetAbbreviation } from './abbreviationActions.js';
3
4
 
4
5
  /**
5
6
  * Register completion provider of emmet.
6
7
  */
7
8
 
8
- function registerProvider(monaco, languages, syntax) {
9
- if (!monaco) {
9
+ function registerProvider(_monaco, languages, syntax) {
10
+ if (!_monaco) {
10
11
  return;
11
12
  }
12
13
 
13
- const providers = languages.map(language => monaco.languages.registerCompletionItemProvider(language, {
14
+ const providers = languages.map(language => _monaco.languages.registerCompletionItemProvider(language, {
14
15
  triggerCharacters: LANGUAGE_MODES[MAPPED_MODES[language] || language],
15
- provideCompletionItems: (model, position) => doComplete(monaco, model, position, syntax, DEFAULT_CONFIG)
16
+ provideCompletionItems: (model, position) => isValidLocationForEmmetAbbreviation(model, position, syntax) ? doComplete(_monaco, model, position, syntax, DEFAULT_CONFIG) : undefined
16
17
  }));
17
18
  return () => {
18
19
  providers.forEach(provider => provider.dispose());
@@ -1,10 +1,10 @@
1
- import type * as Monaco from 'monaco-editor';
1
+ import type * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
2
2
  import type { ExtractOptions, MarkupAbbreviation, Options, StylesheetAbbreviation, SyntaxType, UserConfig } from 'emmet';
3
3
  import type { SnippetsMap } from './configCompat';
4
- declare type TextModel = Monaco.editor.ITextModel;
5
- declare type CompletionList = Monaco.languages.CompletionList;
6
- declare type Position = Monaco.IPosition;
7
- declare type Range = Monaco.IRange;
4
+ declare type TextModel = monaco.editor.ITextModel;
5
+ declare type CompletionList = monaco.languages.CompletionList;
6
+ declare type Position = monaco.IPosition;
7
+ declare type Range = monaco.IRange;
8
8
  /**
9
9
  * Emmet configuration as derived from the Emmet related VS Code settings
10
10
  */
@@ -19,12 +19,8 @@ export interface VSCodeEmmetConfig {
19
19
  }
20
20
  /**
21
21
  * Returns all applicable emmet expansions for abbreviation at given position in a CompletionList
22
- * @param document TextDocument in which completions are requested
23
- * @param position Position in the document at which completions are requested
24
- * @param syntax Emmet supported language
25
- * @param emmetConfig Emmet Configurations as derived from VS Code
26
22
  */
27
- export declare function doComplete(monaco: typeof Monaco, model: TextModel, position: Position, syntax: string, emmetConfig: VSCodeEmmetConfig): CompletionList | undefined;
23
+ export declare function doComplete(_monaco: typeof monaco, model: TextModel, position: Position, syntax: string, emmetConfig: VSCodeEmmetConfig): CompletionList | undefined;
28
24
  export declare const emmetSnippetField: (index: number, placeholder: string) => string;
29
25
  /** Returns whether or not syntax is a supported stylesheet syntax, like CSS */
30
26
  export declare function isStyleSheet(syntax: string): boolean;
@@ -37,7 +33,7 @@ export declare function getDefaultSnippets(syntax: string): SnippetsMap;
37
33
  /**
38
34
  * Extracts abbreviation from the given position in the given document
39
35
  */
40
- export declare function extractAbbreviation(monaco: typeof Monaco, model: TextModel, position: Position, options?: Partial<ExtractOptions>): {
36
+ export declare function extractAbbreviation(_monaco: typeof monaco, model: TextModel, position: Position, options?: Partial<ExtractOptions>): {
41
37
  abbreviation: string;
42
38
  abbreviationRange: Range;
43
39
  filter: string | undefined;
@@ -29,13 +29,9 @@ const commentFilterSuffix = 'c';
29
29
  const maxFilters = 3;
30
30
  /**
31
31
  * Returns all applicable emmet expansions for abbreviation at given position in a CompletionList
32
- * @param document TextDocument in which completions are requested
33
- * @param position Position in the document at which completions are requested
34
- * @param syntax Emmet supported language
35
- * @param emmetConfig Emmet Configurations as derived from VS Code
36
32
  */
37
33
 
38
- function doComplete(monaco, model, position, syntax, emmetConfig) {
34
+ function doComplete(_monaco, model, position, syntax, emmetConfig) {
39
35
  var _a, _b;
40
36
 
41
37
  if (emmetConfig.showExpandedAbbreviation === 'never' || !getEmmetMode(syntax, emmetConfig.excludeLanguages)) {
@@ -58,7 +54,7 @@ function doComplete(monaco, model, position, syntax, emmetConfig) {
58
54
  lookAhead: !isStyleSheetRes,
59
55
  type: isStyleSheetRes ? 'stylesheet' : 'markup'
60
56
  };
61
- const extractedValue = extractAbbreviation(monaco, model, position, extractOptions);
57
+ const extractedValue = extractAbbreviation(_monaco, model, position, extractOptions);
62
58
 
63
59
  if (!extractedValue) {
64
60
  return;
@@ -100,11 +96,11 @@ function doComplete(monaco, model, position, syntax, emmetConfig) {
100
96
  }
101
97
 
102
98
  expandedAbbr = {
103
- kind: monaco.languages.CompletionItemKind.Property,
99
+ kind: _monaco.languages.CompletionItemKind.Property,
104
100
  label: abbreviation + (filter ? '|' + filter.replace(',', '|') : ''),
105
101
  documentation: replaceTabStopsWithCursors(expandedText),
106
102
  detail: 'Emmet abbreviation',
107
- insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
103
+ insertTextRules: _monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
108
104
  range: abbreviationRange,
109
105
  insertText: escapeNonTabStopDollar(addFinalTabStop(expandedText))
110
106
  };
@@ -129,7 +125,7 @@ function doComplete(monaco, model, position, syntax, emmetConfig) {
129
125
  expandedAbbr.filterText = abbreviation; // Custom snippets should show up in completions if abbreviation is a prefix
130
126
 
131
127
  const stylesheetCustomSnippetsKeys = stylesheetCustomSnippetsKeyCache.has(syntax) ? stylesheetCustomSnippetsKeyCache.get(syntax) : stylesheetCustomSnippetsKeyCache.get('css');
132
- completionItems = makeSnippetSuggestion(monaco, stylesheetCustomSnippetsKeys !== null && stylesheetCustomSnippetsKeys !== void 0 ? stylesheetCustomSnippetsKeys : [], abbreviation, abbreviation, abbreviationRange, expandOptions, 'Emmet Custom Snippet', false);
128
+ completionItems = makeSnippetSuggestion(_monaco, stylesheetCustomSnippetsKeys !== null && stylesheetCustomSnippetsKeys !== void 0 ? stylesheetCustomSnippetsKeys : [], abbreviation, abbreviation, abbreviationRange, expandOptions, 'Emmet Custom Snippet', false);
133
129
 
134
130
  if (!completionItems.find(x => x.insertText === (expandedAbbr === null || expandedAbbr === void 0 ? void 0 : expandedAbbr.insertText))) {
135
131
  // Fix for https://github.com/Microsoft/vscode/issues/28933#issuecomment-309236902
@@ -152,12 +148,12 @@ function doComplete(monaco, model, position, syntax, emmetConfig) {
152
148
  }
153
149
 
154
150
  if (syntax !== 'xml') {
155
- const commonlyUsedTagSuggestions = makeSnippetSuggestion(monaco, commonlyUsedTags, tagToFindMoreSuggestionsFor, abbreviation, abbreviationRange, expandOptions, 'Emmet Abbreviation');
151
+ const commonlyUsedTagSuggestions = makeSnippetSuggestion(_monaco, commonlyUsedTags, tagToFindMoreSuggestionsFor, abbreviation, abbreviationRange, expandOptions, 'Emmet Abbreviation');
156
152
  completionItems = completionItems.concat(commonlyUsedTagSuggestions);
157
153
  }
158
154
 
159
155
  if (emmetConfig.showAbbreviationSuggestions === true) {
160
- const abbreviationSuggestions = makeSnippetSuggestion(monaco, markupSnippetKeys.filter(x => !commonlyUsedTags.includes(x)), tagToFindMoreSuggestionsFor, abbreviation, abbreviationRange, expandOptions, 'Emmet Abbreviation'); // Workaround for the main expanded abbr not appearing before the snippet suggestions
156
+ const abbreviationSuggestions = makeSnippetSuggestion(_monaco, markupSnippetKeys.filter(x => !commonlyUsedTags.includes(x)), tagToFindMoreSuggestionsFor, abbreviation, abbreviationRange, expandOptions, 'Emmet Abbreviation'); // Workaround for the main expanded abbr not appearing before the snippet suggestions
161
157
 
162
158
  if (expandedAbbr && abbreviationSuggestions.length > 0 && tagToFindMoreSuggestionsFor !== abbreviation) {
163
159
  expandedAbbr.sortText = '0' + expandedAbbr.label;
@@ -179,7 +175,7 @@ function doComplete(monaco, model, position, syntax, emmetConfig) {
179
175
  }
180
176
 
181
177
  if (emmetConfig.showSuggestionsAsSnippets === true) {
182
- completionItems.forEach(x => x.kind = monaco.languages.CompletionItemKind.Snippet);
178
+ completionItems.forEach(x => x.kind = _monaco.languages.CompletionItemKind.Snippet);
183
179
  }
184
180
 
185
181
  return completionItems.length ? {
@@ -191,7 +187,7 @@ function doComplete(monaco, model, position, syntax, emmetConfig) {
191
187
  * Create & return snippets for snippet keys that start with given prefix
192
188
  */
193
189
 
194
- function makeSnippetSuggestion(monaco, snippetKeys, prefix, abbreviation, abbreviationRange, expandOptions, snippetDetail, skipFullMatch = true) {
190
+ function makeSnippetSuggestion(_monaco, snippetKeys, prefix, abbreviation, abbreviationRange, expandOptions, snippetDetail, skipFullMatch = true) {
195
191
  if (!prefix || !snippetKeys) {
196
192
  return [];
197
193
  }
@@ -214,11 +210,11 @@ function makeSnippetSuggestion(monaco, snippetKeys, prefix, abbreviation, abbrev
214
210
  }
215
211
 
216
212
  const item = {
217
- kind: monaco.languages.CompletionItemKind.Property,
213
+ kind: _monaco.languages.CompletionItemKind.Property,
218
214
  label: prefix + snippetKey.substr(prefix.length),
219
215
  documentation: replaceTabStopsWithCursors(expandedAbbr),
220
216
  detail: snippetDetail,
221
- insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
217
+ insertTextRules: _monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
222
218
  range: abbreviationRange,
223
219
  insertText: escapeNonTabStopDollar(addFinalTabStop(expandedAbbr))
224
220
  };
@@ -399,7 +395,7 @@ function getFilters(text, pos) {
399
395
  */
400
396
 
401
397
 
402
- function extractAbbreviation(monaco, model, position, options) {
398
+ function extractAbbreviation(_monaco, model, position, options) {
403
399
  const currentLine = model.getLineContent(position.lineNumber);
404
400
  const currentLineTillPosition = currentLine.substr(0, position.column - 1);
405
401
  const {
@@ -413,7 +409,7 @@ function extractAbbreviation(monaco, model, position, options) {
413
409
  return;
414
410
  }
415
411
 
416
- const rangeToReplace = new monaco.Range(position.lineNumber, result.location + 1, position.lineNumber, result.location + result.abbreviation.length + lengthOccupiedByFilter + 1);
412
+ const rangeToReplace = new _monaco.Range(position.lineNumber, result.location + 1, position.lineNumber, result.location + result.abbreviation.length + lengthOccupiedByFilter + 1);
417
413
  return {
418
414
  abbreviationRange: rangeToReplace,
419
415
  abbreviation: result.abbreviation,
@@ -1,12 +1,17 @@
1
- import { VSCodeEmmetConfig } from "./emmetHelper";
1
+ import type { VSCodeEmmetConfig } from './emmetHelper';
2
2
  /**
3
- * -ref: https://github.com/microsoft/vscode/blob/main/extensions/emmet/src/util.ts#L86
3
+ * Default emmet configuration.
4
+ */
5
+ export declare const DEFAULT_CONFIG: VSCodeEmmetConfig;
6
+ /**
7
+ * Mapping between languages that support Emmet and completion trigger characters.
8
+ * - ref: https://github.com/microsoft/vscode/blob/50140a53cc2088f478a5560683ccd354f2d5f431/extensions/emmet/src/util.ts#L86
4
9
  */
5
10
  export declare const LANGUAGE_MODES: {
6
11
  [id: string]: string[];
7
12
  };
8
13
  /**
9
- * https://github.com/microsoft/vscode/blob/main/extensions/emmet/src/util.ts#L124
14
+ * Language specific extensions can provide emmet completion support.
15
+ * - ref: https://github.com/microsoft/vscode/blob/50140a53cc2088f478a5560683ccd354f2d5f431/extensions/emmet/src/util.ts#L124
10
16
  */
11
17
  export declare const MAPPED_MODES: Record<string, string>;
12
- export declare const DEFAULT_CONFIG: VSCodeEmmetConfig;
@@ -1,8 +1,18 @@
1
1
  /* eslint-disable */
2
2
 
3
3
  /**
4
- * -ref: https://github.com/microsoft/vscode/blob/main/extensions/emmet/src/util.ts#L86
4
+ * Default emmet configuration.
5
5
  */
6
+ const DEFAULT_CONFIG = {
7
+ showExpandedAbbreviation: 'always',
8
+ showAbbreviationSuggestions: true,
9
+ showSuggestionsAsSnippets: false
10
+ };
11
+ /**
12
+ * Mapping between languages that support Emmet and completion trigger characters.
13
+ * - ref: https://github.com/microsoft/vscode/blob/50140a53cc2088f478a5560683ccd354f2d5f431/extensions/emmet/src/util.ts#L86
14
+ */
15
+
6
16
  const LANGUAGE_MODES = {
7
17
  html: ['!', '.', '}', ':', '*', '$', ']', '/', '>', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'],
8
18
  jade: ['!', '.', '}', ':', '*', '$', ']', '/', '>', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'],
@@ -19,7 +29,8 @@ const LANGUAGE_MODES = {
19
29
  typescript: ['!', '.', '}', '*', '$', ']', '/', '>', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
20
30
  };
21
31
  /**
22
- * https://github.com/microsoft/vscode/blob/main/extensions/emmet/src/util.ts#L124
32
+ * Language specific extensions can provide emmet completion support.
33
+ * - ref: https://github.com/microsoft/vscode/blob/50140a53cc2088f478a5560683ccd354f2d5f431/extensions/emmet/src/util.ts#L124
23
34
  */
24
35
 
25
36
  const MAPPED_MODES = {
@@ -27,10 +38,5 @@ const MAPPED_MODES = {
27
38
  php: 'html',
28
39
  twig: 'html'
29
40
  };
30
- const DEFAULT_CONFIG = {
31
- showExpandedAbbreviation: 'always',
32
- showAbbreviationSuggestions: true,
33
- showSuggestionsAsSnippets: false
34
- };
35
41
 
36
42
  export { DEFAULT_CONFIG, LANGUAGE_MODES, MAPPED_MODES };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elice/material-exercise",
3
- "version": "1.220919.0",
3
+ "version": "1.220920.0",
4
4
  "description": "User view and editing components of Elice material exercise",
5
5
  "repository": "https://git.elicer.io/elice/frontend/library/elice-material",
6
6
  "license": "UNLICENSED",
@@ -116,8 +116,8 @@
116
116
  "@elice/design-tokens": "^1.220803.0",
117
117
  "@elice/icons": "^1.220803.0",
118
118
  "@elice/markdown": "^1.220803.0",
119
- "@elice/material-shared-types": "1.220919.0",
120
- "@elice/material-shared-utils": "1.220919.0",
119
+ "@elice/material-shared-types": "1.220920.0",
120
+ "@elice/material-shared-utils": "1.220920.0",
121
121
  "@elice/types": "^1.220914.0",
122
122
  "@elice/websocket": "^1.220803.0",
123
123
  "@types/classnames": "^2.3.1",
@@ -139,5 +139,5 @@
139
139
  "recoil": "^0.6.1",
140
140
  "styled-components": "^5.2.0"
141
141
  },
142
- "gitHead": "bddb3a6f9165572b2ba351356d5443f85d0ff519"
142
+ "gitHead": "446a4074e18958b473a8cb8973ee7073a7b9e2e4"
143
143
  }