@gravitee/ui-particles-angular 12.0.2 → 12.1.0-apim-3970-schematics-3dc6ff4

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.
@@ -2872,6 +2872,341 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.2.3", ngImpor
2872
2872
  }]
2873
2873
  }], ctorParameters: () => [{ type: GioMonacoEditorService }] });
2874
2874
 
2875
+ const SCHEMA_REF_BASE = '#/$defs/';
2876
+ function getKeywords(schema, keywords = new Set()) {
2877
+ const properties = schema.properties || {};
2878
+ const defs = schema.$defs || {};
2879
+ for (const property of Object.values(defs)) {
2880
+ if (property.properties) {
2881
+ getKeywords(property, keywords);
2882
+ }
2883
+ }
2884
+ for (const [name, property] of Object.entries(properties)) {
2885
+ keywords.add(name);
2886
+ if (property.properties) {
2887
+ getKeywords(property, keywords);
2888
+ }
2889
+ }
2890
+ return Array.from(keywords);
2891
+ }
2892
+ /**
2893
+ * Build suggestions for autocompletion based on a JSON schema definition and a property path
2894
+ *
2895
+ * @param schema an object model defined as a JSON schema following the 2020-12 specification
2896
+ * @param path the property path to inspect. If the property path contains '.', then root properties will be returned
2897
+ */
2898
+ function getSuggestions(schema, path) {
2899
+ const propertyNames = [...path];
2900
+ const propertyName = propertyNames.shift();
2901
+ if (propertyName === '.') {
2902
+ return buildSuggestions(schema, schema);
2903
+ }
2904
+ const property = getProperty(schema, propertyName);
2905
+ if (!property) {
2906
+ return {
2907
+ properties: [],
2908
+ additionalProperties: {},
2909
+ items: {},
2910
+ };
2911
+ }
2912
+ const newSchema = mergeSchemaWithProperties(schema, property);
2913
+ if (propertyNames.length > 0) {
2914
+ return getSuggestions(newSchema, propertyNames);
2915
+ }
2916
+ return buildSuggestions(newSchema, property);
2917
+ }
2918
+ function resolveReference(ref, defs = {}) {
2919
+ const refName = ref.substring(SCHEMA_REF_BASE.length);
2920
+ const resolved = defs[refName];
2921
+ if (resolved && resolved.$ref) {
2922
+ return resolveReference(resolved.$ref, defs);
2923
+ }
2924
+ return resolved || {};
2925
+ }
2926
+ function resolveType(property, defs) {
2927
+ if (property.$ref) {
2928
+ const resolved = resolveReference(property.$ref, defs);
2929
+ return resolveType(resolved, defs);
2930
+ }
2931
+ if (property.additionalProperties || property.items) {
2932
+ const stringMap = 'map<string, ';
2933
+ const array = 'array<';
2934
+ let type = property.additionalProperties ? stringMap : array;
2935
+ let copy = property.additionalProperties || property.items;
2936
+ while (copy.additionalProperties || copy.items) {
2937
+ type += copy.additionalProperties ? stringMap : array;
2938
+ copy = copy.additionalProperties || copy.items;
2939
+ }
2940
+ return `${type}${copy.type}>`;
2941
+ }
2942
+ return property.type;
2943
+ }
2944
+ function getProperty(schema, propertyName = String()) {
2945
+ if (schema.properties && schema.properties[propertyName]) {
2946
+ return schema.properties[propertyName];
2947
+ }
2948
+ if (schema.$ref && schema.$defs) {
2949
+ const property = resolveReference(schema.$ref, schema.$defs);
2950
+ if (property && property.properties) {
2951
+ return property.properties[propertyName];
2952
+ }
2953
+ }
2954
+ return {};
2955
+ }
2956
+ function buildIndexableSuggestion(property) {
2957
+ return {
2958
+ properties: [],
2959
+ additionalProperties: property.additionalProperties || {},
2960
+ items: property.items || {},
2961
+ };
2962
+ }
2963
+ function buildSuggestions(schema, property) {
2964
+ if (property.$ref && schema.$defs) {
2965
+ const ref = resolveReference(property.$ref, schema.$defs);
2966
+ return buildSuggestions(schema, ref);
2967
+ }
2968
+ if (property.additionalProperties || property.items) {
2969
+ return buildIndexableSuggestion(property);
2970
+ }
2971
+ const properties = property.properties || {};
2972
+ return {
2973
+ properties: mapSuggestions(properties, schema.$defs),
2974
+ additionalProperties: {},
2975
+ items: {},
2976
+ };
2977
+ }
2978
+ function mapSuggestions(properties, defs) {
2979
+ return Object.entries(properties).map(([name, property]) => {
2980
+ return {
2981
+ name,
2982
+ type: resolveType(property, defs),
2983
+ };
2984
+ });
2985
+ }
2986
+ function mergeSchemaWithProperties(schema, property) {
2987
+ return { ...schema, ...property };
2988
+ }
2989
+
2990
+ /*
2991
+ * Copyright (C) 2024 The Gravitee team (http://gravitee.io)
2992
+ *
2993
+ * Licensed under the Apache License, Version 2.0 (the "License");
2994
+ * you may not use this file except in compliance with the License.
2995
+ * You may obtain a copy of the License at
2996
+ *
2997
+ * http://www.apache.org/licenses/LICENSE-2.0
2998
+ *
2999
+ * Unless required by applicable law or agreed to in writing, software
3000
+ * distributed under the License is distributed on an "AS IS" BASIS,
3001
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3002
+ * See the License for the specific language governing permissions and
3003
+ * limitations under the License.
3004
+ */
3005
+ const SPEL_LANG_ID = 'spel';
3006
+ function getPropertyPath(model, position) {
3007
+ const line = model.getValueInRange({
3008
+ startLineNumber: position.lineNumber,
3009
+ startColumn: 0,
3010
+ endLineNumber: position.lineNumber,
3011
+ endColumn: position.column,
3012
+ });
3013
+ // get last valid el expression (most right hand side of the current line)
3014
+ const lastExpression = line.split('#').filter(Boolean).pop();
3015
+ if (!lastExpression) {
3016
+ return [];
3017
+ }
3018
+ // get expression left hand side
3019
+ const lastExpressionLHS = lastExpression.split(/\s+/).filter(Boolean).shift();
3020
+ if (!lastExpressionLHS) {
3021
+ return [];
3022
+ }
3023
+ return (lastExpressionLHS
3024
+ // remove special characters
3025
+ .replace(/\W/g, ' ')
3026
+ // normalize spaces
3027
+ .replace(/\s+/g, ' ')
3028
+ .trim()
3029
+ .split(/\s/));
3030
+ }
3031
+ class GioLanguageElService {
3032
+ ngOnDestroy() {
3033
+ this.unsubscribe$.next();
3034
+ this.unsubscribe$.complete();
3035
+ }
3036
+ constructor(codeEditorService) {
3037
+ this.unsubscribe$ = new Subject();
3038
+ this.context = {
3039
+ schema: {},
3040
+ keywords: [],
3041
+ };
3042
+ this.schema = {};
3043
+ this.keywords = [];
3044
+ codeEditorService.loaded$.pipe(takeUntil(this.unsubscribe$)).subscribe(event => {
3045
+ this.setup(event.monaco);
3046
+ });
3047
+ }
3048
+ setup(monaco) {
3049
+ if (!monaco) {
3050
+ throw new Error('Monaco is not loaded');
3051
+ }
3052
+ monaco.languages.register({ id: SPEL_LANG_ID });
3053
+ monaco.languages.setLanguageConfiguration(SPEL_LANG_ID, {
3054
+ brackets: [
3055
+ ['{', '}'],
3056
+ ['(', ')'],
3057
+ ['[', ']'],
3058
+ ],
3059
+ autoClosingPairs: [
3060
+ {
3061
+ open: "'",
3062
+ close: "'",
3063
+ },
3064
+ {
3065
+ open: '"',
3066
+ close: '"',
3067
+ },
3068
+ {
3069
+ open: '(',
3070
+ close: ')',
3071
+ },
3072
+ {
3073
+ open: '{',
3074
+ close: '}',
3075
+ },
3076
+ {
3077
+ open: '[',
3078
+ close: ']',
3079
+ },
3080
+ ],
3081
+ surroundingPairs: [
3082
+ {
3083
+ open: "'",
3084
+ close: "'",
3085
+ },
3086
+ {
3087
+ open: '"',
3088
+ close: '"',
3089
+ },
3090
+ {
3091
+ open: '(',
3092
+ close: ')',
3093
+ },
3094
+ {
3095
+ open: '{',
3096
+ close: '}',
3097
+ },
3098
+ ],
3099
+ });
3100
+ const schema = this.schema;
3101
+ const keywords = this.keywords;
3102
+ monaco.languages.setMonarchTokensProvider(SPEL_LANG_ID, {
3103
+ keywords,
3104
+ operators: ['=', '>', '<', '!', '?', ':', '==', '<=', '>=', '!=', '&&', '||', '++', '--', '+', '-', '*', '/', '^', '%'],
3105
+ tokenizer: {
3106
+ root: [
3107
+ [
3108
+ /@?[a-zA-Z][\w$]*/,
3109
+ {
3110
+ cases: {
3111
+ '@keywords': 'keyword',
3112
+ '@operators': 'operator',
3113
+ '@default': 'variable',
3114
+ },
3115
+ },
3116
+ ],
3117
+ [/["'].*?["']/, 'string'],
3118
+ [/"([^"\\]|\\.)*$/, 'string.invalid'],
3119
+ [/#/, 'number'],
3120
+ // eslint-disable-next-line no-useless-escape
3121
+ [/\d*\.\d+([eE][\-+]?\d+)?/, 'number.float'],
3122
+ [/0[xX][0-9a-fA-F]+/, 'number.hex'],
3123
+ [/\d+/, 'number'],
3124
+ ],
3125
+ },
3126
+ });
3127
+ monaco.languages.registerCompletionItemProvider(SPEL_LANG_ID, {
3128
+ provideCompletionItems(model, position, context) {
3129
+ const word = model.getWordUntilPosition(position);
3130
+ const mapPropertyKind = (propertySuggestion) => {
3131
+ switch (propertySuggestion.type) {
3132
+ case 'object':
3133
+ return monaco.languages.CompletionItemKind.Struct;
3134
+ case 'string':
3135
+ return monaco.languages.CompletionItemKind.Text;
3136
+ default:
3137
+ return monaco.languages.CompletionItemKind.Field;
3138
+ }
3139
+ };
3140
+ const mapPropertySuggestion = (propertySuggestion) => {
3141
+ return {
3142
+ label: propertySuggestion.name,
3143
+ kind: mapPropertyKind(propertySuggestion),
3144
+ insertText: propertySuggestion.name,
3145
+ detail: propertySuggestion.type,
3146
+ range: {
3147
+ startLineNumber: position.lineNumber,
3148
+ endLineNumber: position.lineNumber,
3149
+ startColumn: word.startColumn,
3150
+ endColumn: word.endColumn,
3151
+ },
3152
+ };
3153
+ };
3154
+ const mapIndexableSuggestions = (suggestion) => {
3155
+ return (suggestion.enum?.map(name => {
3156
+ return {
3157
+ label: name,
3158
+ kind: monaco.languages.CompletionItemKind.Enum,
3159
+ insertText: `"${name}"`,
3160
+ detail: 'enum',
3161
+ range: {
3162
+ startLineNumber: position.lineNumber,
3163
+ endLineNumber: position.lineNumber,
3164
+ startColumn: word.startColumn,
3165
+ endColumn: word.endColumn,
3166
+ },
3167
+ };
3168
+ }) || []);
3169
+ };
3170
+ if (context.triggerCharacter === '#') {
3171
+ return {
3172
+ suggestions: getSuggestions(schema, ['.']).properties.map(mapPropertySuggestion).sort(),
3173
+ };
3174
+ }
3175
+ if (context.triggerCharacter === '[') {
3176
+ const path = getPropertyPath(model, position);
3177
+ const suggestions = getSuggestions(schema, path);
3178
+ if (suggestions.additionalProperties && suggestions.additionalProperties.enum) {
3179
+ return {
3180
+ suggestions: mapIndexableSuggestions(suggestions.additionalProperties),
3181
+ };
3182
+ }
3183
+ }
3184
+ if (context.triggerCharacter === '.') {
3185
+ const path = getPropertyPath(model, position);
3186
+ const suggestions = getSuggestions(schema, path).properties.map(mapPropertySuggestion).sort();
3187
+ return {
3188
+ suggestions,
3189
+ };
3190
+ }
3191
+ return { suggestions: [] };
3192
+ },
3193
+ triggerCharacters: ['#', '.', '['],
3194
+ });
3195
+ }
3196
+ setSchema(schema) {
3197
+ Object.assign(this.schema, schema);
3198
+ this.keywords.push(...getKeywords(schema));
3199
+ }
3200
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.2.3", ngImport: i0, type: GioLanguageElService, deps: [{ token: GioMonacoEditorService }], target: i0.ɵɵFactoryTarget.Injectable }); }
3201
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.2.3", ngImport: i0, type: GioLanguageElService, providedIn: 'root' }); }
3202
+ }
3203
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.2.3", ngImport: i0, type: GioLanguageElService, decorators: [{
3204
+ type: Injectable,
3205
+ args: [{
3206
+ providedIn: 'root',
3207
+ }]
3208
+ }], ctorParameters: () => [{ type: GioMonacoEditorService }] });
3209
+
2875
3210
  /*
2876
3211
  * Copyright (C) 2023 The Gravitee team (http://gravitee.io)
2877
3212
  *
@@ -2888,11 +3223,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.2.3", ngImpor
2888
3223
  * limitations under the License.
2889
3224
  */
2890
3225
  class GioMonacoEditorComponent {
2891
- constructor(hostElement, config, monacoEditorService, languageJsonService, changeDetectorRef, ngZone, ngControl) {
3226
+ constructor(hostElement, config, monacoEditorService, languageJsonService, languageSpelService, changeDetectorRef, ngZone, ngControl) {
2892
3227
  this.hostElement = hostElement;
2893
3228
  this.config = config;
2894
3229
  this.monacoEditorService = monacoEditorService;
2895
3230
  this.languageJsonService = languageJsonService;
3231
+ this.languageSpelService = languageSpelService;
2896
3232
  this.changeDetectorRef = changeDetectorRef;
2897
3233
  this.ngZone = ngZone;
2898
3234
  this.ngControl = ngControl;
@@ -3022,11 +3358,16 @@ class GioMonacoEditorComponent {
3022
3358
  this.languageJsonService.addSchemas(uri, languageConfig.schemas);
3023
3359
  }
3024
3360
  break;
3361
+ case 'spel':
3362
+ if (languageConfig.schema) {
3363
+ this.languageSpelService.setSchema(languageConfig.schema);
3364
+ }
3365
+ break;
3025
3366
  default:
3026
3367
  break;
3027
3368
  }
3028
3369
  }
3029
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.2.3", ngImport: i0, type: GioMonacoEditorComponent, deps: [{ token: i0.ElementRef }, { token: GIO_MONACO_EDITOR_CONFIG }, { token: GioMonacoEditorService }, { token: GioLanguageJsonService }, { token: i0.ChangeDetectorRef }, { token: i0.NgZone }, { token: i1$1.NgControl, optional: true, self: true }], target: i0.ɵɵFactoryTarget.Component }); }
3370
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.2.3", ngImport: i0, type: GioMonacoEditorComponent, deps: [{ token: i0.ElementRef }, { token: GIO_MONACO_EDITOR_CONFIG }, { token: GioMonacoEditorService }, { token: GioLanguageJsonService }, { token: GioLanguageElService }, { token: i0.ChangeDetectorRef }, { token: i0.NgZone }, { token: i1$1.NgControl, optional: true, self: true }], target: i0.ɵɵFactoryTarget.Component }); }
3030
3371
  static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.2.3", type: GioMonacoEditorComponent, selector: "gio-monaco-editor", inputs: { languageConfig: "languageConfig", options: "options", disableMiniMap: "disableMiniMap" }, ngImport: i0, template: ` <div *ngIf="loaded$ | async">Loading...</div>`, isInline: true, styles: [":host{display:block;height:100%;min-height:150px;pointer-events:auto;transition:opacity .2s ease-out}:host-context(.hidden){opacity:0}\n"], dependencies: [{ kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "pipe", type: i1.AsyncPipe, name: "async" }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
3031
3372
  }
3032
3373
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.2.3", ngImport: i0, type: GioMonacoEditorComponent, decorators: [{
@@ -3035,7 +3376,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.2.3", ngImpor
3035
3376
  }], ctorParameters: () => [{ type: i0.ElementRef }, { type: undefined, decorators: [{
3036
3377
  type: Inject,
3037
3378
  args: [GIO_MONACO_EDITOR_CONFIG]
3038
- }] }, { type: GioMonacoEditorService }, { type: GioLanguageJsonService }, { type: i0.ChangeDetectorRef }, { type: i0.NgZone }, { type: i1$1.NgControl, decorators: [{
3379
+ }] }, { type: GioMonacoEditorService }, { type: GioLanguageJsonService }, { type: GioLanguageElService }, { type: i0.ChangeDetectorRef }, { type: i0.NgZone }, { type: i1$1.NgControl, decorators: [{
3039
3380
  type: Optional
3040
3381
  }, {
3041
3382
  type: Self