@po-ui/ng-code-editor 5.22.3 → 6.2.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 (55) hide show
  1. package/README.md +20 -20
  2. package/esm2020/lib/components/po-code-editor/interfaces/po-code-editor-registerable-options.interface.mjs +2 -0
  3. package/esm2020/lib/components/po-code-editor/interfaces/po-code-editor-registerable-suggestion.interface.mjs +2 -0
  4. package/esm2020/lib/components/po-code-editor/interfaces/po-code-editor-registerable-tokens.interface.mjs +2 -0
  5. package/esm2020/lib/components/po-code-editor/interfaces/po-code-editor-registerable.interface.mjs +2 -0
  6. package/esm2020/lib/components/po-code-editor/po-code-editor-base.component.mjs +261 -0
  7. package/esm2020/lib/components/po-code-editor/po-code-editor-register.service.mjs +66 -0
  8. package/esm2020/lib/components/po-code-editor/po-code-editor-suggestion.service.mjs +29 -0
  9. package/{esm2015/lib/components/po-code-editor/po-code-editor.component.js → esm2020/lib/components/po-code-editor/po-code-editor.component.mjs} +229 -225
  10. package/esm2020/lib/components/po-code-editor/po-code-editor.module.mjs +37 -0
  11. package/esm2020/lib/index.mjs +4 -0
  12. package/esm2020/po-ui-ng-code-editor.mjs +5 -0
  13. package/{esm2015/public-api.js → esm2020/public-api.mjs} +2 -2
  14. package/fesm2015/po-ui-ng-code-editor.mjs +632 -0
  15. package/fesm2015/po-ui-ng-code-editor.mjs.map +1 -0
  16. package/{fesm2015/po-ui-ng-code-editor.js → fesm2020/po-ui-ng-code-editor.mjs} +605 -582
  17. package/fesm2020/po-ui-ng-code-editor.mjs.map +1 -0
  18. package/lib/components/po-code-editor/interfaces/po-code-editor-registerable-options.interface.d.ts +22 -22
  19. package/lib/components/po-code-editor/interfaces/po-code-editor-registerable-suggestion.interface.d.ts +37 -37
  20. package/lib/components/po-code-editor/interfaces/po-code-editor-registerable-tokens.interface.d.ts +21 -21
  21. package/lib/components/po-code-editor/interfaces/po-code-editor-registerable.interface.d.ts +17 -17
  22. package/lib/components/po-code-editor/po-code-editor-base.component.d.ts +194 -191
  23. package/lib/components/po-code-editor/po-code-editor-register.service.d.ts +70 -67
  24. package/lib/components/po-code-editor/po-code-editor-suggestion.service.d.ts +10 -7
  25. package/lib/components/po-code-editor/po-code-editor.component.d.ts +61 -58
  26. package/lib/components/po-code-editor/po-code-editor.module.d.ts +16 -10
  27. package/lib/index.d.ts +7 -7
  28. package/package.json +31 -16
  29. package/po-ui-ng-code-editor-6.2.0.tgz +0 -0
  30. package/po-ui-ng-code-editor.d.ts +5 -6
  31. package/public-api.d.ts +1 -1
  32. package/schematics/README.md +98 -98
  33. package/schematics/collection.json +10 -10
  34. package/schematics/ng-add/index.d.ts +10 -10
  35. package/schematics/ng-add/index.js +38 -38
  36. package/schematics/ng-add/index.js.map +1 -1
  37. package/schematics/ng-add/index.spec.d.ts +1 -1
  38. package/schematics/ng-add/index.spec.js +113 -113
  39. package/schematics/ng-add/index.spec.js.map +1 -1
  40. package/schematics/ng-add/schema.json +7 -7
  41. package/bundles/po-ui-ng-code-editor.umd.js +0 -981
  42. package/bundles/po-ui-ng-code-editor.umd.js.map +0 -1
  43. package/esm2015/lib/components/po-code-editor/interfaces/po-code-editor-registerable-options.interface.js +0 -2
  44. package/esm2015/lib/components/po-code-editor/interfaces/po-code-editor-registerable-suggestion.interface.js +0 -2
  45. package/esm2015/lib/components/po-code-editor/interfaces/po-code-editor-registerable-tokens.interface.js +0 -2
  46. package/esm2015/lib/components/po-code-editor/interfaces/po-code-editor-registerable.interface.js +0 -2
  47. package/esm2015/lib/components/po-code-editor/po-code-editor-base.component.js +0 -248
  48. package/esm2015/lib/components/po-code-editor/po-code-editor-register.service.js +0 -63
  49. package/esm2015/lib/components/po-code-editor/po-code-editor-suggestion.service.js +0 -28
  50. package/esm2015/lib/components/po-code-editor/po-code-editor.module.js +0 -31
  51. package/esm2015/lib/index.js +0 -4
  52. package/esm2015/po-ui-ng-code-editor.js +0 -7
  53. package/fesm2015/po-ui-ng-code-editor.js.map +0 -1
  54. package/po-ui-ng-code-editor-5.22.3.tgz +0 -0
  55. package/po-ui-ng-code-editor.metadata.json +0 -1
@@ -0,0 +1,632 @@
1
+ import * as i0 from '@angular/core';
2
+ import { Directive, Input, Injectable, forwardRef, Component, ViewChild, NgModule } from '@angular/core';
3
+ import { NG_VALUE_ACCESSOR } from '@angular/forms';
4
+ import { CommonModule } from '@angular/common';
5
+
6
+ const PO_CODE_EDITOR_THEMES = ['vs-dark', 'vs', 'hc-black'];
7
+ const PO_CODE_EDITOR_THEME_DEFAULT = 'vs';
8
+ /**
9
+ * @description
10
+ *
11
+ * O `po-code-editor` é um componente para edição de código fonte baseado no Monaco Editor da Microsoft.
12
+ *
13
+ * Sendo assim, algumas configurações presentes no Monaco podem ser utilizadas aqui, como a escolha da linguagem
14
+ * (utilizando o highlight syntax específico), escolha do tema e opção de diff, além de ser muito similar ao Visual
15
+ * Studio Code, com autocomplete e fechamento automático de brackets.
16
+ *
17
+ * Este componente pode ser usado em qualquer situação que necessite de adição de códigos, como por exemplo, criar
18
+ * receitas utilizando Terraform para gerenciar topologias.
19
+ * É importante ressaltar que este não é um componente para edição de textos comuns.
20
+ *
21
+ * O [(ngModel)] deve ser usado para manipular o conteúdo do po-code-editor, ou seja, tanto para incluir um conteúdo quanto
22
+ * para recuperar o conteúdo do po-code-editor, utiliza-se uma variável passada por [(ngModel)].
23
+ *
24
+ * #### Adicionando o pacote @po-ui/ng-code-editor
25
+ *
26
+ * Para instalar o pacote `po-code-editor` em sua aplicação execute:
27
+ *
28
+ * ```shell
29
+ * ng add @po-ui/ng-code-editor
30
+ * ```
31
+ *
32
+ * O comando `ng add` do `Angular CLI`:
33
+ * - inclui o `po-code-editor` no seu projeto;
34
+ * - adiciona o módulo `PoCodeEditorModule`:;
35
+ *
36
+ * ```
37
+ * // app.module.ts
38
+ * ...
39
+ * import { PoModule } from '@po-ui/ng-components';
40
+ * import { PoCodeEditorModule } from '@po-ui/ng-code-editor';
41
+ * ...
42
+ * @NgModule({
43
+ * imports: [
44
+ * ...
45
+ * PoModule,
46
+ * PoCodeEditorModule
47
+ * ],
48
+ * ...
49
+ * })
50
+ * export class AppModule { }
51
+ * ```
52
+ *
53
+ * - adiciona o tema PO UI e também o *asset* do Monaco no arquivo `angular.json`, conforme abaixo:
54
+ *
55
+ * <pre ngNonBindable>
56
+ * ...
57
+ * "assets": [
58
+ * { "glob": "&#42;&#42;/&#42;", "input": "node_modules/monaco-editor/min", "output": "/assets/monaco/" }
59
+ * ],
60
+ * "styles": [
61
+ * "./node_modules/@po-ui/style/css/po-theme-default.min.css"
62
+ * ]
63
+ * ...
64
+ * </pre>
65
+ */
66
+ class PoCodeEditorBaseComponent {
67
+ constructor() {
68
+ this.modifiedValue = '';
69
+ this.value = '';
70
+ this._height = 150;
71
+ this._language = 'plainText';
72
+ this._readonly = false;
73
+ this._showDiff = false;
74
+ this._theme = PO_CODE_EDITOR_THEME_DEFAULT;
75
+ /* istanbul ignore next */
76
+ this.onTouched = (value) => { };
77
+ /* istanbul ignore next */
78
+ this.onChangePropagate = (value) => { };
79
+ }
80
+ /**
81
+ * @optional
82
+ *
83
+ * @description
84
+ *
85
+ * Linguagem na qual será apresentado o código fonte.
86
+ * Para saber quais são as linguagens compatíveis, consulte a documentação oficial do
87
+ * [**Monaco Editor**](https://microsoft.github.io/monaco-editor/).
88
+ *
89
+ * Também é possível adicionar uma nova linguagem personalizada utilizando o serviço:
90
+ * [**po-code-editor-register**](https://po-ui.io/documentation/po-code-editor-register?view=doc).
91
+ *
92
+ * @default `plainText`
93
+ */
94
+ set language(language) {
95
+ this._language = language && language.length ? language.trim() : 'plainText';
96
+ if (this.editor && this._language) {
97
+ this.setLanguage(this._language);
98
+ }
99
+ }
100
+ get language() {
101
+ return this._language;
102
+ }
103
+ /**
104
+ * @optional
105
+ *
106
+ * @description
107
+ *
108
+ * Indica se o editor será aberto em modo de leitura.
109
+ *
110
+ * Neste caso, não é possível editar o código inserido.
111
+ *
112
+ * Obs: Esta propriedade não refletirá efeito se alterada após o carregamento do componente.
113
+ *
114
+ * @default `false`
115
+ */
116
+ set readonly(readonly) {
117
+ this._readonly = readonly === '' ? true : this.convertToBoolean(readonly);
118
+ if (this.editor) {
119
+ this.setReadOnly(readonly);
120
+ }
121
+ }
122
+ get readonly() {
123
+ return this._readonly;
124
+ }
125
+ /**
126
+ * @optional
127
+ *
128
+ * @description
129
+ *
130
+ * Indica se o editor será aberto em modo de comparação.
131
+ *
132
+ * Caso esteja habilitada esta opção, então o [(ngModel)] deverá ser passado como um array, cuja primeira opção deve
133
+ * conter uma string com o código original e na segunda posição uma string código modificado para efeito de
134
+ * comparação. Neste caso, o usuário conseguirá editar apenas o código modificado e isso refletirá na segunda posição
135
+ * do array consequentemente.
136
+ *
137
+ * Obs: Esta propriedade não refletirá efeito se alterada após o carregamento do componente.
138
+ *
139
+ * @default `false`
140
+ */
141
+ set showDiff(showDiff) {
142
+ this._showDiff = showDiff === '' ? true : this.convertToBoolean(showDiff);
143
+ }
144
+ get showDiff() {
145
+ return this._showDiff;
146
+ }
147
+ /**
148
+ * @optional
149
+ *
150
+ * @description
151
+ *
152
+ * Lista de sugestões usadas pelo autocomplete dentro do editor.
153
+ *
154
+ * Para visualizar a lista de sugestões use o comando `CTRL + SPACE`.
155
+ *
156
+ * Caso o editor esteja usando uma linguagem que já tenha uma lista de sugestões predefinida, o valor passado será adicionado
157
+ * a lista preexistente, aumentando as opções para o usuário.
158
+ *
159
+ * Caso tenha mais de um editor da mesma linguagem na aplicação, as sugestões serão adicionadas para que todos os editores da mesma linguagem
160
+ * tenham as mesmas sugestões.
161
+ *
162
+ * ```
163
+ * <po-code-editor
164
+ * [p-suggestions]="[{ label: 'po', insertText: 'Portinari UI' }, { label: 'ng', insertText: 'Angular' }]">
165
+ * </po-code-editor>
166
+ * ```
167
+ *
168
+ * Ao fornecer uma lista de sugestões é possível acelerar a escrita de scripts pelos usuários.
169
+ */
170
+ set suggestions(values) {
171
+ this._suggestions = values;
172
+ if (this.editor && this._suggestions) {
173
+ this.setSuggestions(this._suggestions);
174
+ }
175
+ }
176
+ get suggestions() {
177
+ return this._suggestions;
178
+ }
179
+ /**
180
+ * @optional
181
+ *
182
+ * @description
183
+ *
184
+ * Define um tema para o editor.
185
+ *
186
+ * Temas válidos:
187
+ * - `vs-dark`
188
+ * - `vs`
189
+ * - `hc-black`
190
+ *
191
+ * É importante salientar que o tema será aplicados a todos os componentes po-code-editor existentes na tela,
192
+ * ou seja, todas as instâncias do componente receberão o último tema atribuído ou o tema da última instância
193
+ * criada.
194
+ *
195
+ * @default `vs`
196
+ */
197
+ set theme(theme) {
198
+ this._theme = PO_CODE_EDITOR_THEMES.includes(theme) ? theme : PO_CODE_EDITOR_THEME_DEFAULT;
199
+ if (this.editor) {
200
+ this.setTheme(theme);
201
+ }
202
+ }
203
+ get theme() {
204
+ return this._theme;
205
+ }
206
+ /**
207
+ * @optional
208
+ *
209
+ * @description
210
+ *
211
+ * Define a altura do componente em pixels do po-code-editor.
212
+ * Esta propriedade não poderá ser alterada após o componente ter sido iniciado.
213
+ * A altura mínima é 150 pixels.
214
+ */
215
+ set height(height) {
216
+ this._height = parseFloat(height) >= 150 ? parseFloat(height) : 150;
217
+ }
218
+ get height() {
219
+ return `${this._height}px`;
220
+ }
221
+ getOptions() {
222
+ return { language: this.language, theme: this.theme, readOnly: this.readonly };
223
+ }
224
+ registerOnChange(fn) {
225
+ this.onChangePropagate = fn;
226
+ }
227
+ registerOnTouched(fn) {
228
+ this.onTouched = fn;
229
+ }
230
+ convertToBoolean(val) {
231
+ if (typeof val === 'string') {
232
+ val = val.toLowerCase().trim();
233
+ return val === 'true' || val === 'on' || val === '';
234
+ }
235
+ if (typeof val === 'number') {
236
+ return val === 1;
237
+ }
238
+ return !!val;
239
+ }
240
+ }
241
+ PoCodeEditorBaseComponent.ɵfac = function PoCodeEditorBaseComponent_Factory(t) { return new (t || PoCodeEditorBaseComponent)(); };
242
+ PoCodeEditorBaseComponent.ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: PoCodeEditorBaseComponent, inputs: { language: ["p-language", "language"], readonly: ["p-readonly", "readonly"], showDiff: ["p-show-diff", "showDiff"], suggestions: ["p-suggestions", "suggestions"], theme: ["p-theme", "theme"], height: ["p-height", "height"] } });
243
+ (function () {
244
+ (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(PoCodeEditorBaseComponent, [{
245
+ type: Directive
246
+ }], null, { language: [{
247
+ type: Input,
248
+ args: ['p-language']
249
+ }], readonly: [{
250
+ type: Input,
251
+ args: ['p-readonly']
252
+ }], showDiff: [{
253
+ type: Input,
254
+ args: ['p-show-diff']
255
+ }], suggestions: [{
256
+ type: Input,
257
+ args: ['p-suggestions']
258
+ }], theme: [{
259
+ type: Input,
260
+ args: ['p-theme']
261
+ }], height: [{
262
+ type: Input,
263
+ args: ['p-height']
264
+ }] });
265
+ })();
266
+
267
+ class PoCodeEditorSuggestionService {
268
+ constructor() {
269
+ this.suggestions = {};
270
+ }
271
+ getSuggestion(language, newSuggestion) {
272
+ if (this.suggestions[language]) {
273
+ const deduplicateSuggestions = this.deduplicateSuggestions(this.suggestions[language], newSuggestion);
274
+ this.suggestions[language] = [...this.suggestions[language], ...deduplicateSuggestions];
275
+ return deduplicateSuggestions;
276
+ }
277
+ else {
278
+ return (this.suggestions[language] = [...newSuggestion]);
279
+ }
280
+ }
281
+ deduplicateSuggestions(originalSuggestions, newSuggestions) {
282
+ return newSuggestions.filter(newItem => !originalSuggestions.find(originalItem => originalItem['label'] === newItem['label']));
283
+ }
284
+ }
285
+ PoCodeEditorSuggestionService.ɵfac = function PoCodeEditorSuggestionService_Factory(t) { return new (t || PoCodeEditorSuggestionService)(); };
286
+ PoCodeEditorSuggestionService.ɵprov = /*@__PURE__*/ i0.ɵɵdefineInjectable({ token: PoCodeEditorSuggestionService, factory: PoCodeEditorSuggestionService.ɵfac, providedIn: 'root' });
287
+ (function () {
288
+ (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(PoCodeEditorSuggestionService, [{
289
+ type: Injectable,
290
+ args: [{
291
+ providedIn: 'root'
292
+ }]
293
+ }], function () { return []; }, null);
294
+ })();
295
+
296
+ /**
297
+ * @description
298
+ *
299
+ * Wrapper para registro de sintaxes customizadas para o po-code-editor.
300
+ *
301
+ * Para utilização do serviço de idiomas **PoCodeEditorRegister**,
302
+ * deve-se importar o módulo PoCodeEditorModule mesmo já tendo importado
303
+ * o módulo PoModule.
304
+ * Na importação opcionalmente pode ser invocado o método **forRegister** informando um objeto para configuração.
305
+ *
306
+ * Exemplo de configuração:
307
+ * ```
308
+ * import { PoCodeEditorModule, PoCodeEditorRegisterable } from '@po-ui/ng-code-editor';
309
+ *
310
+ * declare const monaco: any; // Importante para usar configurações com tipos definidos pelo Monaco
311
+ *
312
+ * // A função `provideCompletionItems` precisa ser exportada para ser compatível com AOT.
313
+ * export function provideCompletionItems() {
314
+ * const suggestions = [{
315
+ * label: 'terraform',
316
+ * insertText: '#terraform language'
317
+ * }, {
318
+ * label: 'server',
319
+ * insertText: 'server ${1:ip}'
320
+ * }];
321
+ *
322
+ * return { suggestions: suggestions };
323
+ * }
324
+ *
325
+ * const customEditor: PoCodeEditorRegisterable = {
326
+ * language: 'terraform',
327
+ * options: {
328
+ * keywords: ['resource', 'provider', 'variable', 'output', 'module', 'true', 'false'],
329
+ * operators: ['{', '}', '(', ')', '[', ']', '?', ':'],
330
+ * symbols: /[=><!~?:&|+\-*\/\^%]+/,
331
+ * escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
332
+ * tokenizer: {
333
+ * ...
334
+ * }
335
+ * },
336
+ * suggestions: { provideCompletionItems: provideCompletionItems }
337
+ * };
338
+ *
339
+ * @NgModule({
340
+ * declarations: [],
341
+ * imports: [
342
+ * PoModule,
343
+ * PoCodeEditorModule.forRegister(customEditor)
344
+ * ],
345
+ * bootstrap: [AppComponent]
346
+ * })
347
+ * ```
348
+ *
349
+ * > As configurações para o registro de uma nova sintaxe no Monaco code editor podem ser encontradas em
350
+ * > [**Monaco Editor**](https://microsoft.github.io/monaco-editor/playground.html#extending-language-services-custom-languages).
351
+ */
352
+ class PoCodeEditorRegister {
353
+ }
354
+ PoCodeEditorRegister.ɵfac = function PoCodeEditorRegister_Factory(t) { return new (t || PoCodeEditorRegister)(); };
355
+ PoCodeEditorRegister.ɵprov = /*@__PURE__*/ i0.ɵɵdefineInjectable({ token: PoCodeEditorRegister, factory: PoCodeEditorRegister.ɵfac });
356
+ (function () {
357
+ (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(PoCodeEditorRegister, [{
358
+ type: Injectable
359
+ }], null, null);
360
+ })();
361
+
362
+ const _c0 = ["editorContainer"];
363
+ // variáveis relacionadas ao Monaco
364
+ let loadedMonaco = false;
365
+ let loadPromise;
366
+ /* istanbul ignore next */
367
+ const providers = [
368
+ {
369
+ provide: NG_VALUE_ACCESSOR,
370
+ // eslint-disable-next-line
371
+ useExisting: forwardRef(() => PoCodeEditorComponent),
372
+ multi: true
373
+ }
374
+ ];
375
+ /**
376
+ * @docsExtends PoCodeEditorBaseComponent
377
+ *
378
+ * @example
379
+ *
380
+ * <example name="po-code-editor-basic" title="PO Code Editor Basic">
381
+ * <file name="sample-po-code-editor-basic/sample-po-code-editor-basic.component.html"> </file>
382
+ * <file name="sample-po-code-editor-basic/sample-po-code-editor-basic.component.ts"> </file>
383
+ * </example>
384
+ *
385
+ * <example name="po-code-editor-labs" title="PO Code Editor Labs">
386
+ * <file name="sample-po-code-editor-labs/sample-po-code-editor-labs.component.html"> </file>
387
+ * <file name="sample-po-code-editor-labs/sample-po-code-editor-labs.component.ts"> </file>
388
+ * </example>
389
+ *
390
+ * <example name="po-code-editor-diff" title="PO Code Editor - Diff">
391
+ * <file name="sample-po-code-editor-diff/sample-po-code-editor-diff.component.html"> </file>
392
+ * <file name="sample-po-code-editor-diff/sample-po-code-editor-diff.component.ts"> </file>
393
+ * </example>
394
+ *
395
+ * <example name="po-code-editor-terraform" title="PO Code Editor - Terraform">
396
+ * <file name="sample-po-code-editor-terraform/sample-po-code-editor-terraform.component.html"> </file>
397
+ * <file name="sample-po-code-editor-terraform/sample-po-code-editor-terraform.component.ts"> </file>
398
+ * <file name="sample-po-code-editor-terraform/sample-po-code-editor-terraform.constant.ts"> </file>
399
+ * <file name="sample-po-code-editor-terraform/sample-po-code-editor-terraform.module.ts"> </file>
400
+ * </example>
401
+ *
402
+ * <example name="po-code-editor-suggestion" title="PO Code Editor Suggestion">
403
+ * <file name="sample-po-code-editor-suggestion/sample-po-code-editor-suggestion.component.html"> </file>
404
+ * <file name="sample-po-code-editor-suggestion/sample-po-code-editor-suggestion.component.ts"> </file>
405
+ * </example>
406
+ */
407
+ class PoCodeEditorComponent extends PoCodeEditorBaseComponent {
408
+ constructor(zone, el, poCodeEditorSuggestionService, codeEditorRegister) {
409
+ super();
410
+ this.zone = zone;
411
+ this.el = el;
412
+ this.poCodeEditorSuggestionService = poCodeEditorSuggestionService;
413
+ this.codeEditorRegister = codeEditorRegister;
414
+ this.canLoad = false;
415
+ }
416
+ /* istanbul ignore next */
417
+ ngAfterViewInit() {
418
+ if (loadedMonaco) {
419
+ /* istanbul ignore next */
420
+ loadPromise.then(() => {
421
+ setTimeout(() => {
422
+ if (this.el.nativeElement.offsetWidth) {
423
+ this.registerCustomLanguage();
424
+ this.initMonaco(this.getOptions());
425
+ }
426
+ else {
427
+ this.canLoad = true;
428
+ }
429
+ });
430
+ });
431
+ }
432
+ else {
433
+ loadedMonaco = true;
434
+ loadPromise = new Promise((resolve) => {
435
+ /* istanbul ignore next */
436
+ const onGotAmdLoader = () => {
437
+ window.require.config({ paths: { 'vs': './assets/monaco/vs' } });
438
+ window.require(['vs/editor/editor.main'], () => {
439
+ setTimeout(() => {
440
+ if (this.el.nativeElement.offsetWidth) {
441
+ this.registerCustomLanguage();
442
+ this.initMonaco(this.getOptions());
443
+ }
444
+ else {
445
+ this.canLoad = true;
446
+ }
447
+ resolve();
448
+ });
449
+ });
450
+ };
451
+ if (!window.require) {
452
+ const loaderScript = document.createElement('script');
453
+ loaderScript.type = 'text/javascript';
454
+ loaderScript.src = './assets/monaco/vs/loader.js';
455
+ loaderScript.addEventListener('load', onGotAmdLoader);
456
+ document.body.appendChild(loaderScript);
457
+ }
458
+ });
459
+ }
460
+ }
461
+ ngDoCheck() {
462
+ if (this.canLoad && this.el.nativeElement.offsetWidth) {
463
+ this.registerCustomLanguage();
464
+ this.initMonaco(this.getOptions());
465
+ this.canLoad = false;
466
+ }
467
+ }
468
+ /* istanbul ignore next */
469
+ monacoCreateModel(value) {
470
+ return monaco.editor.createModel(value);
471
+ }
472
+ setValueInEditor() {
473
+ if (this.showDiff) {
474
+ setTimeout(() => {
475
+ if (this.editor) {
476
+ this.editor.setModel({
477
+ original: this.monacoCreateModel(this.value),
478
+ modified: this.monacoCreateModel(this.modifiedValue)
479
+ });
480
+ }
481
+ });
482
+ }
483
+ else {
484
+ setTimeout(() => {
485
+ if (this.editor) {
486
+ this.editor.setValue(this.value);
487
+ }
488
+ });
489
+ }
490
+ }
491
+ setLanguage(language) {
492
+ if (this.showDiff) {
493
+ this.setMonacoLanguage(this.editor.getModel().original, language);
494
+ this.setMonacoLanguage(this.editor.getModel().modified, language);
495
+ }
496
+ else {
497
+ this.setMonacoLanguage(this.editor.getModel(), language);
498
+ }
499
+ }
500
+ /* istanbul ignore next */
501
+ setTheme(theme) {
502
+ monaco.editor.setTheme(theme);
503
+ }
504
+ setReadOnly(readOnly) {
505
+ this.editor.updateOptions({ readOnly: readOnly });
506
+ }
507
+ /* istanbul ignore next */
508
+ setSuggestions(newSuggestions, language = this.language) {
509
+ if (!newSuggestions) {
510
+ return;
511
+ }
512
+ const suggestions = this.poCodeEditorSuggestionService.getSuggestion(language, newSuggestions);
513
+ monaco.languages.registerCompletionItemProvider(language, {
514
+ provideCompletionItems: () => ({ suggestions })
515
+ });
516
+ }
517
+ writeValue(value) {
518
+ this.value = value && value instanceof Array ? value[0] : value;
519
+ this.modifiedValue = value && value instanceof Array && value.length > 0 ? value[1] : '';
520
+ this.setValueInEditor();
521
+ }
522
+ /* istanbul ignore next */
523
+ initMonaco(options) {
524
+ if (this.showDiff) {
525
+ this.editor = monaco.editor.createDiffEditor(this.editorContainer.nativeElement, options);
526
+ this.editor.setModel({
527
+ original: monaco.editor.createModel(this.value),
528
+ modified: monaco.editor.createModel(this.modifiedValue)
529
+ });
530
+ this.editor.onDidUpdateDiff((e) => {
531
+ const original = this.editor.getModel().original.getValue();
532
+ const modified = this.editor.getModel().modified.getValue();
533
+ this.onChangePropagate([original, modified]);
534
+ });
535
+ }
536
+ else {
537
+ this.editor = monaco.editor.create(this.editorContainer.nativeElement, options);
538
+ this.editor.setValue(this.value);
539
+ this.editor.onDidChangeModelContent((e) => {
540
+ const value = this.editor.getValue();
541
+ this.onChangePropagate(value);
542
+ this.zone.run(() => (this.value = value));
543
+ });
544
+ }
545
+ setTimeout(() => {
546
+ this.setLanguage(this.language);
547
+ this.setSuggestions(this.suggestions);
548
+ }, 500);
549
+ }
550
+ /* istanbul ignore next */
551
+ setMonacoLanguage(model, language) {
552
+ monaco.editor.setModelLanguage(model, language);
553
+ }
554
+ registerCustomLanguage() {
555
+ if (this.codeEditorRegister.language) {
556
+ monaco.languages.register({ id: this.codeEditorRegister.language });
557
+ if (this.codeEditorRegister.options) {
558
+ monaco.languages.setMonarchTokensProvider(this.codeEditorRegister.language, this.codeEditorRegister.options);
559
+ }
560
+ if (this.codeEditorRegister.suggestions) {
561
+ this.setSuggestions(this.codeEditorRegister.suggestions.provideCompletionItems().suggestions, this.codeEditorRegister.language);
562
+ }
563
+ }
564
+ }
565
+ }
566
+ PoCodeEditorComponent.ɵfac = function PoCodeEditorComponent_Factory(t) { return new (t || PoCodeEditorComponent)(i0.ɵɵdirectiveInject(i0.NgZone), i0.ɵɵdirectiveInject(i0.ElementRef), i0.ɵɵdirectiveInject(PoCodeEditorSuggestionService), i0.ɵɵdirectiveInject(PoCodeEditorRegister)); };
567
+ PoCodeEditorComponent.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: PoCodeEditorComponent, selectors: [["po-code-editor"]], viewQuery: function PoCodeEditorComponent_Query(rf, ctx) {
568
+ if (rf & 1) {
569
+ i0.ɵɵviewQuery(_c0, 7);
570
+ }
571
+ if (rf & 2) {
572
+ let _t;
573
+ i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.editorContainer = _t.first);
574
+ }
575
+ }, features: [i0.ɵɵProvidersFeature(providers), i0.ɵɵInheritDefinitionFeature], decls: 2, vars: 2, consts: [["editorContainer", ""]], template: function PoCodeEditorComponent_Template(rf, ctx) {
576
+ if (rf & 1) {
577
+ i0.ɵɵelement(0, "div", null, 0);
578
+ }
579
+ if (rf & 2) {
580
+ i0.ɵɵstyleProp("height", ctx.height);
581
+ }
582
+ }, encapsulation: 2 });
583
+ (function () {
584
+ (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(PoCodeEditorComponent, [{
585
+ type: Component,
586
+ args: [{ selector: 'po-code-editor', providers: providers, template: "<div #editorContainer [style.height]=\"height\"></div>\n" }]
587
+ }], function () { return [{ type: i0.NgZone }, { type: i0.ElementRef }, { type: PoCodeEditorSuggestionService }, { type: PoCodeEditorRegister }]; }, { editorContainer: [{
588
+ type: ViewChild,
589
+ args: ['editorContainer', { static: true }]
590
+ }] });
591
+ })();
592
+
593
+ /**
594
+ * @description
595
+ *
596
+ * Módulo do componente po-code-editor.
597
+ */
598
+ class PoCodeEditorModule {
599
+ static forRegister(props) {
600
+ return {
601
+ ngModule: PoCodeEditorModule,
602
+ providers: [
603
+ {
604
+ provide: PoCodeEditorRegister,
605
+ useValue: props
606
+ }
607
+ ]
608
+ };
609
+ }
610
+ }
611
+ PoCodeEditorModule.ɵfac = function PoCodeEditorModule_Factory(t) { return new (t || PoCodeEditorModule)(); };
612
+ PoCodeEditorModule.ɵmod = /*@__PURE__*/ i0.ɵɵdefineNgModule({ type: PoCodeEditorModule });
613
+ PoCodeEditorModule.ɵinj = /*@__PURE__*/ i0.ɵɵdefineInjector({ providers: [PoCodeEditorRegister], imports: [[CommonModule]] });
614
+ (function () {
615
+ (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(PoCodeEditorModule, [{
616
+ type: NgModule,
617
+ args: [{
618
+ imports: [CommonModule],
619
+ declarations: [PoCodeEditorComponent],
620
+ exports: [PoCodeEditorComponent],
621
+ providers: [PoCodeEditorRegister]
622
+ }]
623
+ }], null, null);
624
+ })();
625
+ (function () { (typeof ngJitMode === "undefined" || ngJitMode) && i0.ɵɵsetNgModuleScope(PoCodeEditorModule, { declarations: [PoCodeEditorComponent], imports: [CommonModule], exports: [PoCodeEditorComponent] }); })();
626
+
627
+ /**
628
+ * Generated bundle index. Do not edit.
629
+ */
630
+
631
+ export { PoCodeEditorComponent, PoCodeEditorModule, PoCodeEditorRegister };
632
+ //# sourceMappingURL=po-ui-ng-code-editor.mjs.map