@codingame/monaco-editor-wrapper 3.2.1 → 3.4.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.
@@ -1 +1,6 @@
1
1
  import 'monaco-editor/esm/vs/language/json/monaco.contribution';
2
+ import * as monaco from 'monaco-editor';
3
+ import { Disposable } from 'vscode';
4
+ declare type Unpacked<T> = T extends (infer U)[] ? U : T;
5
+ export declare function addJsonSchema(schema: Unpacked<NonNullable<monaco.languages.json.DiagnosticsOptions['schemas']>>): Disposable;
6
+ export {};
@@ -1,16 +1,23 @@
1
1
  import 'monaco-editor/esm/vs/language/json/monaco.contribution';
2
2
  import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
3
3
  import { onDidChangeJsonSchema, getJsonSchemas } from 'vscode/monaco';
4
+ import { Disposable } from 'vscode';
4
5
  import { r as registerWorkerLoader } from '../worker.js';
5
6
 
7
+ const customSchemas = [];
8
+
6
9
  function updateDiagnosticsOptions() {
7
10
  monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
8
11
  comments: 'ignore',
9
12
  validate: true,
10
- schemas: getJsonSchemas({
13
+ enableSchemaRequest: true,
14
+ schemas: [...getJsonSchemas({
11
15
  keybindings: ['file:///keybindings.json'],
12
16
  'settings/user': ['file:///settings.json']
13
- })
17
+ }), {
18
+ uri: 'https://json-schema.org/draft/2019-09/schema',
19
+ fileMatch: ['*.schema.json']
20
+ }, ...customSchemas]
14
21
  });
15
22
  }
16
23
 
@@ -22,3 +29,17 @@ const workerLoader = async () => (await import(
22
29
  '../json.worker.js').then(module => module)).default;
23
30
 
24
31
  registerWorkerLoader('json', workerLoader);
32
+ function addJsonSchema(schema) {
33
+ customSchemas.push(schema);
34
+ updateDiagnosticsOptions();
35
+ return new Disposable(() => {
36
+ const index = customSchemas.indexOf(schema);
37
+
38
+ if (index >= 0) {
39
+ customSchemas.splice(index, 1);
40
+ updateDiagnosticsOptions();
41
+ }
42
+ });
43
+ }
44
+
45
+ export { addJsonSchema };
package/dist/main.js CHANGED
@@ -4393,5 +4393,69 @@ function hideCodeWithoutDecoration(editor, decorations) {
4393
4393
  editor.setHiddenAreas(otherHiddenAreas);
4394
4394
  };
4395
4395
  }
4396
+ /**
4397
+ * Collapse everything between startToken and endToken
4398
+ */
4399
+
4400
+ async function collapseCodeSections(editor, startToken, endToken) {
4401
+ let isRegex = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
4402
+ const editorModel = editor.getModel();
4403
+ const ranges = [];
4404
+
4405
+ if (editorModel != null) {
4406
+ let currentPosition = editorModel.getFullModelRange().getStartPosition();
4407
+ let match;
4408
+
4409
+ while ((match = editorModel.findNextMatch(startToken,
4410
+ /* searchStart */
4411
+ currentPosition,
4412
+ /* isRegex */
4413
+ isRegex,
4414
+ /* matchCase */
4415
+ true,
4416
+ /* wordSeparators */
4417
+ null,
4418
+ /* captureMatches */
4419
+ false)) != null) {
4420
+ var _matchEnd$range$getEn;
4421
+
4422
+ if (match.range.getStartPosition().isBefore(currentPosition)) {
4423
+ break;
4424
+ }
4425
+
4426
+ const matchEnd = editorModel.findNextMatch(endToken,
4427
+ /* searchStart */
4428
+ match.range.getEndPosition(),
4429
+ /* isRegex */
4430
+ isRegex,
4431
+ /* matchCase */
4432
+ true,
4433
+ /* wordSeparators */
4434
+ null,
4435
+ /* captureMatches */
4436
+ false);
4437
+
4438
+ if (matchEnd != null && matchEnd.range.getStartPosition().isBefore(match.range.getStartPosition())) {
4439
+ break;
4440
+ }
4441
+
4442
+ currentPosition = (_matchEnd$range$getEn = matchEnd === null || matchEnd === void 0 ? void 0 : matchEnd.range.getEndPosition()) !== null && _matchEnd$range$getEn !== void 0 ? _matchEnd$range$getEn : editorModel.getFullModelRange().getEndPosition();
4443
+ ranges.push(monaco.Range.fromPositions(match.range.getStartPosition(), currentPosition));
4444
+ }
4445
+
4446
+ const selections = editor.getSelections();
4447
+ editor.setSelections(ranges.map(r => ({
4448
+ selectionStartLineNumber: r.startLineNumber,
4449
+ selectionStartColumn: r.startColumn,
4450
+ positionLineNumber: r.endLineNumber,
4451
+ positionColumn: r.endColumn
4452
+ })));
4453
+ await editor.getAction('editor.createFoldingRangeFromSelection').run();
4454
+
4455
+ if (selections != null) {
4456
+ editor.setSelections(selections);
4457
+ }
4458
+ }
4459
+ }
4396
4460
 
4397
- export { createEditor, defineVSCodeTheme, getMonacoLanguage, hideCodeWithoutDecoration, loadLanguage, lockCodeWithoutDecoration, registerEditorOpenHandler, registerTextModelContentProvider, updateEditorKeybindingsMode, updateKeybindings };
4461
+ export { collapseCodeSections, createEditor, defineVSCodeTheme, getMonacoLanguage, hideCodeWithoutDecoration, loadLanguage, lockCodeWithoutDecoration, registerEditorOpenHandler, registerTextModelContentProvider, updateEditorKeybindingsMode, updateKeybindings };
package/dist/tools.d.ts CHANGED
@@ -1,3 +1,7 @@
1
1
  import * as monaco from 'monaco-editor';
2
2
  export declare function lockCodeWithoutDecoration(editor: monaco.editor.IStandaloneCodeEditor, decorations: string[], allowChangeFromSources: string[], errorMessage?: string): () => void;
3
3
  export declare function hideCodeWithoutDecoration(editor: monaco.editor.IStandaloneCodeEditor, decorations: string[]): () => void;
4
+ /**
5
+ * Collapse everything between startToken and endToken
6
+ */
7
+ export declare function collapseCodeSections(editor: monaco.editor.IStandaloneCodeEditor, startToken: string, endToken: string, isRegex?: boolean): Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codingame/monaco-editor-wrapper",
3
- "version": "3.2.1",
3
+ "version": "3.4.0",
4
4
  "private": false,
5
5
  "description": "Enhanced Monaco editor with TextMate grammars and more",
6
6
  "scripts": {