@aquera/nile-elements 0.0.101 → 0.0.102

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/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Webcomponent nile-elements following open-wc recommendations",
4
4
  "license": "MIT",
5
5
  "author": "nile-elements",
6
- "version": "0.0.101",
6
+ "version": "0.0.102",
7
7
  "main": "dist/src/index.js",
8
8
  "type": "module",
9
9
  "module": "dist/src/index.js",
@@ -108,46 +108,12 @@ export class NileCodeEditor extends NileElement {
108
108
  }
109
109
 
110
110
  firstUpdated() {
111
- const lineNumbersExtension = this.lineNumbersComp.of(this.getLineNumbersExension());
112
- const readOnlyExtension = this.readOnlyComp.of(this.getReadOnlyExtension());
113
- const restrictSingleLineExtension = this.restrictSingleLineComp.of(this.getSingleLineExtension())
114
- const customAutoCompletions = this.customCompletionComp.of(javascriptLanguage.data.of({
115
- autocomplete: scopeCompletionSource(this.customAutoCompletions),
116
- }));
117
- const language = this.language == "sql" ? sql() : javascript()
118
- let startState = EditorState.create({
119
- doc: !this.multiline ? this.convertToSingleLine(this.value) : this.value,
120
- extensions: [
121
- basicSetup({
122
- lineNumbers: this.lineNumbers || this.multiline,
123
- highlightActiveLine: false,
124
- foldGutter: false,
125
- }),
126
- lineNumbersExtension,
127
- readOnlyExtension,
128
- restrictSingleLineExtension,
129
- customAutoCompletions,
130
- autocompletion(),
131
- language,
132
- EditorView.theme(Theme),
133
- EditorView.updateListener.of((v: ViewUpdate) => {
134
- if (v.docChanged) {
135
- this.emit('nile-change', { value: this.view.state.doc.toString() })
136
- }
137
- }),
138
- EditorView.domEventHandlers({
139
- focus: () => this.dispatchEvent(new Event('nile-focus')),
140
- blur: () => this.dispatchEvent(new Event('nile-blur')),
141
- }),
142
- ],
143
- });
144
-
145
- this.view = new EditorView({
146
- state: startState,
147
- parent: this.codeEditor
148
- });
149
-
150
- this.emit('nile-after-init',{ codeMirrorInstance: this.view, insertAtCursor: this.insertBetweenCode } )
111
+ this.createNewView()
112
+ this.emit('nile-after-init',{
113
+ codeMirrorInstance: this.view,
114
+ createNewView: this.createNewView,
115
+ insertAtCursor: this.insertBetweenCode
116
+ }, false )
151
117
  }
152
118
 
153
119
  protected updated(changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>): void{
@@ -225,6 +191,50 @@ export class NileCodeEditor extends NileElement {
225
191
  : ``}`;
226
192
  }
227
193
 
194
+ createNewView(){
195
+ if(this.view) this.view.destroy();
196
+ const lineNumbersExtension = this.lineNumbersComp.of(this.getLineNumbersExension());
197
+ const readOnlyExtension = this.readOnlyComp.of(this.getReadOnlyExtension());
198
+ const restrictSingleLineExtension = this.restrictSingleLineComp.of(this.getSingleLineExtension())
199
+ const customAutoCompletions = this.customCompletionComp.of(javascriptLanguage.data.of({
200
+ autocomplete: scopeCompletionSource(this.customAutoCompletions),
201
+ }));
202
+ const language = this.language == "sql" ? sql() : javascript()
203
+ let startState = EditorState.create({
204
+ doc: !this.multiline ? this.convertToSingleLine(this.value) : this.value,
205
+ extensions: [
206
+ basicSetup({
207
+ lineNumbers: this.lineNumbers || this.multiline,
208
+ highlightActiveLine: false,
209
+ foldGutter: false,
210
+ }),
211
+ lineNumbersExtension,
212
+ readOnlyExtension,
213
+ restrictSingleLineExtension,
214
+ customAutoCompletions,
215
+ autocompletion(),
216
+ language,
217
+ EditorView.theme(Theme),
218
+ EditorView.updateListener.of((v: ViewUpdate) => {
219
+ if (v.docChanged) {
220
+ this.emit('nile-change', { value: this.view.state.doc.toString() })
221
+ }
222
+ }),
223
+ EditorView.domEventHandlers({
224
+ focus: () => this.dispatchEvent(new Event('nile-focus')),
225
+ blur: () => this.dispatchEvent(new Event('nile-blur')),
226
+ }),
227
+ ],
228
+ });
229
+
230
+ this.view = new EditorView({
231
+ state: startState,
232
+ parent: this.codeEditor
233
+ });
234
+
235
+ this.emit('nile-after-update',{ codeMirrorInstance: this.view }, false )
236
+ }
237
+
228
238
  singleLineMultiLineToggle() {
229
239
  this.view.dispatch({
230
240
  changes: {
@@ -274,6 +284,7 @@ export class NileCodeEditor extends NileElement {
274
284
 
275
285
  emitNileExpand() {
276
286
  this.emit('nile-expand', { expand: true });
287
+ this.createNewView()
277
288
  }
278
289
 
279
290
  /* #endregion */
@@ -14,7 +14,7 @@ import { classMap } from 'lit/directives/class-map.js';
14
14
  import { query } from 'lit/decorators.js';
15
15
  import { watch } from '../internal/watch';
16
16
  import NileElement from '../internal/nile-element';
17
- import type { CSSResultGroup } from 'lit';
17
+ import type { CSSResultGroup, PropertyValueMap } from 'lit';
18
18
 
19
19
  let id = 0;
20
20
 
@@ -69,6 +69,7 @@ export class NileTab extends NileElement {
69
69
 
70
70
  @watch('active')
71
71
  handleActiveChange() {
72
+ if(this.active) this.emit('nile-toggle-change',{ value: this.panel })
72
73
  this.setAttribute('aria-selected', this.active ? 'true' : 'false');
73
74
  }
74
75
 
@@ -135,6 +135,10 @@ export class NileTabGroup extends NileElement {
135
135
  this.mutationObserver.disconnect();
136
136
  this.resizeObserver.unobserve(this.nav);
137
137
  }
138
+
139
+ protected firstUpdated(_changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>): void {
140
+ this.addEventListener('nile-toggle-change', this.handleToggleFromTab);
141
+ }
138
142
 
139
143
  protected updated(_changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>): void {
140
144
  if(_changedProperties.has('activeTabName')){
@@ -144,6 +148,96 @@ export class NileTabGroup extends NileElement {
144
148
  }
145
149
  }
146
150
 
151
+ @watch('noScrollControls', { waitUntilFirstUpdate: true })
152
+ updateScrollControls() {
153
+ if (this.noScrollControls) {
154
+ this.hasScrollControls = false;
155
+ } else {
156
+ this.hasScrollControls =
157
+ ['top', 'bottom'].includes(this.placement) && this.nav.scrollWidth > this.nav.clientWidth;
158
+ this.hasScrollControls = false;
159
+ }
160
+ }
161
+
162
+ @watch('placement', { waitUntilFirstUpdate: true })
163
+ syncIndicator() {
164
+ if(!this.indicator) return;
165
+ const tab = this.getActiveTab();
166
+
167
+ if (tab) {
168
+ this.indicator.style.display = 'block';
169
+ this.repositionIndicator();
170
+ } else {
171
+ this.indicator.style.display = 'none';
172
+ }
173
+ }
174
+
175
+ render() {
176
+ const isRtl = true;
177
+
178
+ return html`
179
+ <div
180
+ part="base"
181
+ class=${classMap({
182
+ 'tab-group': true,
183
+ 'tab-group--top': this.placement === 'top',
184
+ 'tab-group--bottom': this.placement === 'bottom',
185
+ 'tab-group--start': this.placement === 'start',
186
+ 'tab-group--end': this.placement === 'end',
187
+ 'tab-group--rtl': true,
188
+ 'tab-group--has-scroll-controls': this.hasScrollControls,
189
+ 'hide__track':this.noTrack
190
+ })}
191
+ @click=${this.handleClick}
192
+ @keydown=${this.handleKeyDown}
193
+ >
194
+ <div class="tab-group__nav-container" part="nav">
195
+ ${this.hasScrollControls
196
+ ? html`
197
+ <nile-icon-button
198
+ part="scroll-button scroll-button--start"
199
+ exportparts="base:scroll-button__base"
200
+ class="tab-group__scroll-button tab-group__scroll-button--start"
201
+ name='arrowright'
202
+ library="system"
203
+ label="scrollToStart"
204
+ @click=${this.handleScrollToStart}
205
+ ></nile-icon-button>
206
+ `
207
+ : ''}
208
+
209
+ <div class="tab-group__nav">
210
+ <div part="tabs" class="tab-group__tabs" role="tablist">
211
+ <div
212
+ part="active-tab-indicator"
213
+ class=${classMap({
214
+ 'tab-group__indicator': !this.noTrack,
215
+ })}
216
+ ></div>
217
+ <slot name="nav" @slotchange=${this.syncTabsAndPanels}></slot>
218
+ </div>
219
+ </div>
220
+
221
+ ${this.hasScrollControls
222
+ ? html`
223
+ <nile-icon-button
224
+ part="scroll-button scroll-button--end"
225
+ exportparts="base:scroll-button__base"
226
+ class="tab-group__scroll-button tab-group__scroll-button--end"
227
+ name='arrowleft'
228
+ library="system"
229
+ label="scrollToEnd"
230
+ @click=${this.handleScrollToEnd}
231
+ ></nile-icon-button>
232
+ `
233
+ : ''}
234
+ </div>
235
+
236
+ <slot part="body" class="tab-group__body" @slotchange=${this.syncTabsAndPanels}></slot>
237
+ </div>
238
+ `;
239
+ }
240
+
147
241
  private getAllTabs(options: { includeDisabled: boolean } = { includeDisabled: true }) {
148
242
  const slot = this.shadowRoot!.querySelector<HTMLSlotElement>('slot[name="nav"]')!;
149
243
 
@@ -358,105 +452,12 @@ export class NileTabGroup extends NileElement {
358
452
  // After updating, show or hide scroll controls as needed
359
453
  this.updateComplete.then(() => this.updateScrollControls());
360
454
  }
361
-
362
- @watch('noScrollControls', { waitUntilFirstUpdate: true })
363
- updateScrollControls() {
364
- if (this.noScrollControls) {
365
- this.hasScrollControls = false;
366
- } else {
367
- this.hasScrollControls =
368
- ['top', 'bottom'].includes(this.placement) && this.nav.scrollWidth > this.nav.clientWidth;
369
- this.hasScrollControls = false;
370
- }
371
- }
372
-
373
- @watch('placement', { waitUntilFirstUpdate: true })
374
- syncIndicator() {
375
- if(!this.indicator) return;
376
- const tab = this.getActiveTab();
377
-
378
- if (tab) {
379
- this.indicator.style.display = 'block';
380
- this.repositionIndicator();
381
- } else {
382
- this.indicator.style.display = 'none';
383
- }
384
- }
385
-
386
- /** Shows the specified tab panel. */
387
- show(panel: string) {
388
- const tab = this.tabs.find(el => el.panel === panel);
389
-
390
- if (tab) {
391
- this.activeTabName=tab.panel;
392
- }
455
+
456
+ private handleToggleFromTab(e:CustomEvent){
457
+ e.stopPropagation();
458
+ this.activeTabName=e.detail.value;
393
459
  }
394
460
 
395
- render() {
396
- const isRtl = true;
397
-
398
- return html`
399
- <div
400
- part="base"
401
- class=${classMap({
402
- 'tab-group': true,
403
- 'tab-group--top': this.placement === 'top',
404
- 'tab-group--bottom': this.placement === 'bottom',
405
- 'tab-group--start': this.placement === 'start',
406
- 'tab-group--end': this.placement === 'end',
407
- 'tab-group--rtl': true,
408
- 'tab-group--has-scroll-controls': this.hasScrollControls,
409
- 'hide__track':this.noTrack
410
- })}
411
- @click=${this.handleClick}
412
- @keydown=${this.handleKeyDown}
413
- >
414
- <div class="tab-group__nav-container" part="nav">
415
- ${this.hasScrollControls
416
- ? html`
417
- <nile-icon-button
418
- part="scroll-button scroll-button--start"
419
- exportparts="base:scroll-button__base"
420
- class="tab-group__scroll-button tab-group__scroll-button--start"
421
- name='arrowright'
422
- library="system"
423
- label="scrollToStart"
424
- @click=${this.handleScrollToStart}
425
- ></nile-icon-button>
426
- `
427
- : ''}
428
-
429
- <div class="tab-group__nav">
430
- <div part="tabs" class="tab-group__tabs" role="tablist">
431
- <div
432
- part="active-tab-indicator"
433
- class=${classMap({
434
- 'tab-group__indicator': !this.noTrack,
435
- })}
436
- ></div>
437
- <slot name="nav" @slotchange=${this.syncTabsAndPanels}></slot>
438
- </div>
439
- </div>
440
-
441
- ${this.hasScrollControls
442
- ? html`
443
- <nile-icon-button
444
- part="scroll-button scroll-button--end"
445
- exportparts="base:scroll-button__base"
446
- class="tab-group__scroll-button tab-group__scroll-button--end"
447
- name='arrowleft'
448
- library="system"
449
- label="scrollToEnd"
450
- @click=${this.handleScrollToEnd}
451
- ></nile-icon-button>
452
- `
453
- : ''}
454
- </div>
455
-
456
- <slot part="body" class="tab-group__body" @slotchange=${this.syncTabsAndPanels}></slot>
457
- </div>
458
- `;
459
- }
460
461
  }
461
462
 
462
463
  export default NileTabGroup;