@gravitee/ui-components 3.24.2-migrate-codemirror-4150e72 → 3.24.3-fix-lit2-button-623e8b3

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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [3.24.3](https://github.com/gravitee-io/gravitee-ui-components/compare/v3.24.2...v3.24.3) (2021-12-15)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * resolve will update implementation ([e4a8076](https://github.com/gravitee-io/gravitee-ui-components/commit/e4a8076358a0715734cc03fa9023fc0fb7d9029f))
7
+
1
8
  ## [3.24.2](https://github.com/gravitee-io/gravitee-ui-components/compare/v3.24.1...v3.24.2) (2021-12-14)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravitee/ui-components",
3
- "version": "3.24.2-migrate-codemirror-4150e72",
3
+ "version": "3.24.3-fix-lit2-button-623e8b3",
4
4
  "description": "Gravitee.io UI Components library, based on Web Components",
5
5
  "repository": {
6
6
  "type": "git",
@@ -49,20 +49,6 @@
49
49
  "package.json": "npm run lint:package"
50
50
  },
51
51
  "dependencies": {
52
- "@codemirror/autocomplete": "^0.19.5",
53
- "@codemirror/basic-setup": "^0.19.0",
54
- "@codemirror/closebrackets": "^0.19.0",
55
- "@codemirror/fold": "^0.19.1",
56
- "@codemirror/gutter": "^0.19.4",
57
- "@codemirror/highlight": "^0.19.6",
58
- "@codemirror/history": "^0.19.0",
59
- "@codemirror/lang-java": "^0.19.1",
60
- "@codemirror/lang-javascript": "^0.19.2",
61
- "@codemirror/language": "^0.19.3",
62
- "@codemirror/language-data": "^0.19.1",
63
- "@codemirror/matchbrackets": "^0.19.3",
64
- "@codemirror/state": "^0.19.5",
65
- "@codemirror/view": "^0.19.16",
66
52
  "@formatjs/intl-locale": "^2.4.40",
67
53
  "@formatjs/intl-relativetimeformat": "^9.3.2",
68
54
  "clipboard-copy": "^4.0.0",
@@ -81,8 +67,6 @@
81
67
  "@babel/core": "7.16.0",
82
68
  "@babel/plugin-syntax-dynamic-import": "7.8.3",
83
69
  "@babel/preset-env": "7.16.4",
84
- "@codemirror/commands": "^0.19.5",
85
- "@codemirror/lang-html": "^0.19.3",
86
70
  "@commitlint/cli": "15.0.0",
87
71
  "@commitlint/config-conventional": "15.0.0",
88
72
  "@highcharts/map-collection": "1.1.3",
@@ -322,14 +322,6 @@ export class GvButton extends LitElement {
322
322
  }
323
323
  }
324
324
 
325
- async performUpdate() {
326
- super.performUpdate();
327
- const icon = this.shadowRoot.querySelector('gv-icon');
328
- if (icon) {
329
- icon.performUpdate();
330
- }
331
- }
332
-
333
325
  render() {
334
326
  const classes = {
335
327
  button: true,
@@ -202,7 +202,7 @@ export class GvSelectNative extends InputElement(LitElement) {
202
202
 
203
203
  willUpdate(changedProperties) {
204
204
  if (changedProperties.has('value')) {
205
- this.updateState(changedProperties.get('value'));
205
+ this.updateState(this.value);
206
206
  }
207
207
  }
208
208
 
@@ -239,7 +239,7 @@ export class GvSelect extends withResizeObserver(InputElement(LitElement)) {
239
239
 
240
240
  willUpdate(changedProperties) {
241
241
  if (changedProperties.has('value')) {
242
- this.updateState(changedProperties.get('value'));
242
+ this.updateState(this.value);
243
243
  }
244
244
  }
245
245
 
package/src/index.js CHANGED
@@ -31,7 +31,6 @@ export { GvCardList } from './molecules/gv-card-list';
31
31
  export { GvCard } from './molecules/gv-card';
32
32
  export { GvCategoryList } from './molecules/gv-category-list';
33
33
  export { GvCategory } from './molecules/gv-category';
34
- export { GvCodeEditor } from './molecules/gv-code-editor';
35
34
  export { GvCodeHint } from './molecules/gv-code-hint';
36
35
  export { GvCode } from './molecules/gv-code';
37
36
  export { GvConfirm } from './molecules/gv-confirm';
@@ -1,407 +0,0 @@
1
- /*
2
- * Copyright (C) 2015 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
- import { LitElement, html, css } from 'lit-element';
17
-
18
- import { shapeClipboard } from '../styles/shapes';
19
- import { dispatchCustomEvent } from '../lib/events';
20
- import { uuid } from '../lib/utils';
21
- import { classMap } from 'lit-html/directives/class-map';
22
-
23
- import { EditorView, basicSetup } from '@codemirror/basic-setup';
24
- import { EditorState, Compartment, Prec, EditorSelection } from '@codemirror/state';
25
- import { autocompletion, startCompletion, pickedCompletion } from '@codemirror/autocomplete';
26
- import { json } from '@codemirror/lang-json';
27
- import { languages } from '@codemirror/language-data';
28
- import { placeholder, keymap } from '@codemirror/view';
29
- import { get } from 'object-path';
30
-
31
- const languageCompartment = new Compartment();
32
- const readonlyCompartment = new Compartment();
33
- const placeholderCompartment = new Compartment();
34
-
35
- /**
36
- * Code editor component
37
- *
38
- * ## Details
39
- * * has @theme facet
40
- *
41
- * @fires gv-code:input - input events with the `value` on `detail`
42
- * @fires gv-code:ready - event dispatch when component is ready
43
- * @fires gv-code:clipboard-copy - event dispatch when component the `value` has been copied to clipboard
44
- *
45
- * @attr {String} label - code language
46
- * @attr {String} value - code content to be highlighted
47
- * @attr {options} Object - options based on codemirror https://codemirror.net/doc/manual.html#config
48
- * @attr {Object} grammar - The grammar for Expression Language support
49
- * @attr {String} placeholder - an example value to display in the input when empty
50
- * @attr {Number} rows - number of rows of the text element
51
- * @attr {Boolean} large - for a large input (only if the field has one row)
52
- * @attr {Boolean} medium - for a medium input (only if the field has one row) (Default)
53
- * @attr {Boolean} small - for a small input (only if the field has one row)
54
- *
55
- * @attr {Boolean} [clipboard=false]- true if field has clipboard button
56
- * @attr {Boolean} [autofocus=false] - true to put the focus on the input
57
- * @attr {Boolean} [readonly=false] - true if field is readonly mode
58
- */
59
- export class GvCodeEditor extends LitElement {
60
- static get properties() {
61
- return {
62
- value: { type: String },
63
- readonly: { type: Boolean },
64
- placeholder: { type: String },
65
- options: { type: Object },
66
- rows: { type: Number },
67
- clipboard: { type: Boolean },
68
- grammar: { type: Object },
69
- _clipboardIcon: { type: String },
70
- _codeMirror: { type: Object },
71
- _error: { type: String, attribute: false },
72
- };
73
- }
74
-
75
- constructor() {
76
- super();
77
- this._id = `gv-code-${uuid()}`;
78
- this.value = '';
79
- this.readonly = false;
80
- this.autofocus = false;
81
- this.clipboard = false;
82
- this._clipboardIcon = shapeClipboard;
83
- }
84
-
85
- render() {
86
- const classes = {
87
- singleLine: this.singleLine,
88
- };
89
- return html` <div id="${this._id}" class="${classMap(classes)}"></div> `;
90
- }
91
-
92
- _onChange() {
93
- dispatchCustomEvent(this, 'input', this.value);
94
- }
95
-
96
- get singleLine() {
97
- return this.rows === 1;
98
- }
99
-
100
- _getModelType(typeId) {
101
- if (this.grammar != null) {
102
- return get(this.grammar, `_types.${typeId}`);
103
- }
104
- return null;
105
- }
106
-
107
- _isMap(typeId) {
108
- return ['Map', 'HttpHeaders', 'MultiValueMap'].includes(typeId);
109
- }
110
-
111
- _getEnum(typeId) {
112
- if (this.grammar != null) {
113
- return get(this.grammar, `_enums.${typeId}`);
114
- }
115
- return [''];
116
- }
117
-
118
- _convertType(type) {
119
- if (type) {
120
- const lowerType = type.toLowerCase();
121
- if (lowerType === 'string') {
122
- // class, constant, enum, function, interface, keyword, method, namespace, property, text, type, and variable.
123
- return 'text';
124
- } else if (lowerType === 'httpheaders' || lowerType === 'multivaluemap') {
125
- return 'type';
126
- } else if (lowerType === 'int' || lowerType === 'long') {
127
- return 'variable';
128
- } else if (lowerType.includes('[]')) {
129
- return 'enum';
130
- }
131
- }
132
- return 'variable';
133
- }
134
-
135
- _autocomplete(ctx) {
136
- const { handler, match } = this._completionHandlers
137
- .filter((handler) => (this.grammar != null && handler.supportEL === true) || handler.supportEL !== true)
138
- .map((handler) => ({ handler, match: handler.expr ? ctx.matchBefore(handler.expr) : true }))
139
- .find(({ match, expr }) => match);
140
- return handler.run.call(this, ctx, match);
141
- }
142
-
143
- _buildMethods(type) {
144
- const modelType = this._getModelType(type);
145
- return modelType.methods.map(({ name, params = [], returnType }) => {
146
- const command = `${name}()`;
147
- const displayParams = params.map((p) => `${p.type} ${p.name}`);
148
- const label = `${name}(${displayParams.join(', ')})`;
149
- const detail = `return ${returnType}`;
150
- return {
151
- type: 'method',
152
- command,
153
- apply: (view, completion, from, to) => {
154
- const anchor = from + name.length + 1;
155
- view.dispatch({
156
- changes: { from, to, insert: completion.command },
157
- selection: { anchor },
158
- userEvent: 'input.complete',
159
- annotations: pickedCompletion.of(view),
160
- });
161
- },
162
- label,
163
- detail,
164
- };
165
- });
166
- }
167
-
168
- get _completionHandlers() {
169
- return [
170
- {
171
- expr: /{#[a-z]*/,
172
- supportEL: true,
173
- run(ctx, match) {
174
- const prefix = match.text.replaceAll('{#', '');
175
- const from = ctx.pos - prefix.length;
176
- const options = Object.keys(this.grammar)
177
- .filter((command) => !command.startsWith('_') && command.startsWith(prefix))
178
- .map((command) => {
179
- return {
180
- // class, constant, enum, function, interface, keyword, method, namespace, property, text, type, and variable.
181
- type: 'variable',
182
- command,
183
- apply: command,
184
- label: command,
185
- };
186
- });
187
- return { from, options };
188
- },
189
- },
190
- {
191
- expr: /{#[a-z]*.[a-zA-Z]*/,
192
- run(ctx, match) {
193
- const tokens = match.text.split('.');
194
- const key = tokens[0].replaceAll('{#', '');
195
- const prefix = tokens[1];
196
- const candidate = this.grammar[key][prefix];
197
- let options = [];
198
- let from = ctx.pos;
199
- if (candidate) {
200
- // const modelType = this._getModelType(candidate._type);
201
- if (this._isMap(candidate._type)) {
202
- options = this._getEnum(candidate._type).map((value) => {
203
- const type = this._convertType(candidate._type);
204
- const command = `['${value}'][0]`;
205
- return {
206
- type,
207
- command,
208
- apply: command,
209
- label: value,
210
- };
211
- });
212
- }
213
- } else {
214
- from -= prefix.length;
215
- const candidate = this.grammar[key];
216
- if (candidate._type) {
217
- options = this._buildMethods(candidate._type);
218
- } else {
219
- options = Object.keys(candidate)
220
- .filter((command) => !command.startsWith('_') && command.startsWith(prefix))
221
- .map((command) => ({
222
- type: this._convertType(candidate[command]._type),
223
- command,
224
- apply: command,
225
- label: command,
226
- }));
227
- }
228
- }
229
- return { from, options };
230
- },
231
- },
232
- {
233
- expr: /{#[a-z]*.[a-zA-Z]*.[a-zA-Z]*/,
234
- run(ctx, match) {
235
- const tokens = match.text.split('.');
236
- const key = tokens[0].replaceAll('{#', '');
237
- const word = tokens[1];
238
- const prefix = tokens[2];
239
- const candidate = this.grammar[key][word];
240
- let options = [];
241
- let from = ctx.pos;
242
- if (candidate) {
243
- if (this._isMap(candidate._type)) {
244
- options = this._getEnum(candidate._type)
245
- .filter((command) => !command.startsWith('_') && command.startsWith(prefix))
246
- .map((label) => {
247
- const type = this._convertType(candidate._type);
248
- return {
249
- type,
250
- command: `['${label}'][0]`,
251
- apply(view, completion, _from, to) {
252
- const from = _from - prefix.length - 1;
253
- view.dispatch({
254
- changes: { from, to, insert: completion.command },
255
- selection: { anchor: from + completion.command.length },
256
- userEvent: 'input.complete',
257
- annotations: pickedCompletion.of(view),
258
- });
259
- },
260
- label,
261
- };
262
- });
263
- } else {
264
- if (candidate._type) {
265
- options = this._buildMethods(candidate._type);
266
- } else {
267
- from -= prefix.length;
268
- options = Object.keys(candidate)
269
- .filter((command) => command.startsWith(prefix))
270
- .map((command) => {
271
- return {
272
- type: this._convertType(candidate[command]._type),
273
- command,
274
- apply: command,
275
- label: command,
276
- };
277
- });
278
- }
279
- }
280
- }
281
- return { from, options };
282
- },
283
- },
284
- {
285
- run(ctx) {
286
- const autocompleteLanguage = ctx.state.languageDataAt('autocomplete', ctx.pos);
287
- if (autocompleteLanguage.length > 0) {
288
- return autocompleteLanguage[0](ctx);
289
- }
290
- return { from: ctx.pos, options: [] };
291
- },
292
- },
293
- ];
294
- }
295
-
296
- getExtensions() {
297
- return [
298
- basicSetup,
299
- languageCompartment.of(json()),
300
- placeholderCompartment.of(placeholder(this.placeholder || '')),
301
- EditorState.transactionFilter.of((tr) => (this.singleLine && tr.newDoc.lines > 1 ? [] : tr)),
302
- readonlyCompartment.of(EditorView.editable.of(!this.readonly)),
303
- EditorView.updateListener.of((update) => {
304
- this.value = update.view.contentDOM.innerText;
305
- }),
306
- autocompletion({
307
- activateOnTyping: true,
308
- override: [this._autocomplete.bind(this)],
309
- }),
310
- Prec.high(this.insertELKeymap()),
311
- ];
312
- }
313
-
314
- insertELKeymap() {
315
- return keymap.of([
316
- {
317
- key: 'Ctrl-Shift-e',
318
- mac: 'Cmd-Shift-e',
319
- run(view) {
320
- view.dispatch(
321
- view.state.changeByRange((range) => ({
322
- changes: [{ from: range.from, to: range.to, insert: '{#}' }],
323
- range: EditorSelection.range(range.from + 2, range.to + 2),
324
- })),
325
- );
326
- startCompletion(view);
327
- return true;
328
- },
329
- },
330
- ]);
331
- }
332
-
333
- firstUpdated() {
334
- super.firstUpdated();
335
- const parent = this.shadowRoot.querySelector(`[id=${this._id}]`);
336
- this._editorState = EditorState.create({
337
- doc: this.value,
338
- extensions: this.getExtensions(),
339
- });
340
- this._editorView = new EditorView({
341
- root: this.shadowRoot,
342
- parent,
343
- state: this._editorState,
344
- });
345
- parent.appendChild(this._editorView.dom);
346
- }
347
-
348
- async updated(properties) {
349
- if (properties.has('placeholder')) {
350
- this._editorView.dispatch({
351
- effects: placeholderCompartment.reconfigure(placeholder(this.placeholder)),
352
- });
353
- }
354
- if (properties.has('value')) {
355
- this._editorState.update({ changes: { from: 0, to: this._editorState.doc.length, insert: this.value } });
356
- }
357
- if (properties.has('readonly')) {
358
- this._editorView.dispatch({
359
- effects: readonlyCompartment.reconfigure(EditorView.editable.of(!this.readonly)),
360
- });
361
- }
362
-
363
- if (properties.has('options') && this.options) {
364
- if (this.options.mode) {
365
- const language = languages.find((language) => {
366
- return language.name.toUpperCase() === this.options.mode.toUpperCase() || language.alias.includes(this.options.mode);
367
- });
368
- if (language != null) {
369
- if (language.support == null) {
370
- await language.load();
371
- }
372
- this._editorView.dispatch({
373
- effects: languageCompartment.reconfigure(language.support.extension),
374
- });
375
- } else {
376
- console.warn(
377
- `Cannot find language ${this.options.mode}, please use language supported by CodeMirror 6`,
378
- languages.map((l) => l.name),
379
- );
380
- }
381
- }
382
- }
383
- }
384
-
385
- static get styles() {
386
- return [
387
- // language=CSS
388
- css`
389
- :host {
390
- box-sizing: border-box;
391
- display: block;
392
- margin: 0 0.2rem 0.2rem 0.2rem;
393
- }
394
-
395
- .singleLine .cm-gutters {
396
- display: none;
397
- }
398
-
399
- .singleLine .cm-scroller {
400
- overflow: hidden;
401
- }
402
- `,
403
- ];
404
- }
405
- }
406
-
407
- window.customElements.define('gv-code-editor', GvCodeEditor);
@@ -1 +0,0 @@
1
- import '../src/molecules/gv-code-editor';