@taprootio/espalier 3.9.0 → 4.0.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.
- package/CHANGELOG.md +17 -0
- package/custom-elements.json +9527 -10146
- package/dist/action-menu/esp-action-menu-item.d.ts +4 -4
- package/dist/action-menu/esp-action-menu-item.js +1 -1
- package/dist/action-menu/esp-action-menu.d.ts +2 -2
- package/dist/action-menu/esp-action-menu.js +6 -6
- package/dist/box/esp-box.d.ts +1 -1
- package/dist/burger/esp-burger.d.ts +4 -4
- package/dist/burger/esp-burger.js +4 -4
- package/dist/button/esp-button.d.ts +5 -5
- package/dist/button/esp-button.js +9 -9
- package/dist/checkbox/esp-checkbox-group.d.ts +4 -2
- package/dist/checkbox/esp-checkbox-group.js +1 -1
- package/dist/checkbox/esp-checkbox.d.ts +4 -2
- package/dist/color-picker/esp-color-picker.d.ts +2 -2
- package/dist/color-picker/esp-color-picker.js +4 -4
- package/dist/date-picker/esp-date-picker.d.ts +5 -3
- package/dist/date-picker/esp-date-picker.js +7 -7
- package/dist/details/esp-details-group.d.ts +1 -1
- package/dist/details/esp-details-group.js +3 -3
- package/dist/details/esp-details.d.ts +2 -2
- package/dist/details/esp-details.js +3 -3
- package/dist/dialog/esp-dialog.d.ts +7 -7
- package/dist/dialog/esp-dialog.js +7 -7
- package/dist/file-upload/esp-file-upload.d.ts +5 -2
- package/dist/file-upload/esp-file-upload.js +3 -3
- package/dist/flyout/esp-flyout.d.ts +10 -10
- package/dist/flyout/esp-flyout.js +14 -14
- package/dist/focus-picker/esp-focus-picker.d.ts +4 -4
- package/dist/focus-picker/esp-focus-picker.js +4 -4
- package/dist/font-picker/esp-font-picker.d.ts +1 -1
- package/dist/font-picker/esp-font-picker.js +2 -2
- package/dist/form/esp-form.d.ts +9 -9
- package/dist/form/esp-form.js +1 -1
- package/dist/grid/esp-grid.d.ts +10 -10
- package/dist/grid/esp-grid.js +13 -11
- package/dist/header/esp-header-button.d.ts +2 -2
- package/dist/header/esp-header-button.js +1 -1
- package/dist/header/esp-header.d.ts +5 -5
- package/dist/header/esp-header.js +4 -4
- package/dist/help/esp-help-provider.js +1 -1
- package/dist/help/help-document.js +1 -1
- package/dist/image-upload/esp-image-preview.js +8 -8
- package/dist/image-upload/esp-image-upload.d.ts +14 -14
- package/dist/image-upload/esp-image-upload.js +10 -10
- package/dist/image-upload/image-helpers.d.ts +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/info/esp-info.d.ts +2 -2
- package/dist/info/esp-info.js +6 -6
- package/dist/input/esp-input.d.ts +8 -7
- package/dist/input/esp-input.js +2 -2
- package/dist/lightbox/esp-lightbox.js +6 -6
- package/dist/menu/esp-menu-group.d.ts +1 -1
- package/dist/menu/esp-menu-group.js +1 -1
- package/dist/menu/esp-menu-item.d.ts +2 -2
- package/dist/menu/esp-menu-item.js +2 -2
- package/dist/menu/esp-menu.d.ts +2 -2
- package/dist/menu/esp-menu.js +9 -9
- package/dist/page/esp-page.d.ts +4 -4
- package/dist/page/esp-page.js +1 -1
- package/dist/pickers/esp-pick-one.d.ts +3 -1
- package/dist/pickers/esp-pick-one.js +2 -2
- package/dist/pickers/esp-pick-some.d.ts +3 -1
- package/dist/pickers/esp-pick-some.js +1 -1
- package/dist/pickers/esp-picker-base.d.ts +1 -1
- package/dist/pickers/esp-picker-menu.d.ts +4 -4
- package/dist/pickers/esp-picker-menu.js +7 -7
- package/dist/popover/esp-popover.d.ts +2 -2
- package/dist/popover/esp-popover.js +3 -3
- package/dist/progress/esp-progress.d.ts +4 -4
- package/dist/radio-button/esp-radio-button-group.d.ts +4 -2
- package/dist/radio-button/esp-radio-button-group.js +4 -4
- package/dist/radio-button/esp-radio-button.d.ts +1 -1
- package/dist/repeater/esp-repeater.d.ts +2 -12
- package/dist/search/esp-search.d.ts +4 -4
- package/dist/search/esp-search.js +3 -3
- package/dist/shared/esp-element-base.js +1 -1
- package/dist/shared/events.d.ts +151 -70
- package/dist/shared/events.js +1 -1
- package/dist/shared/flyout-events.d.ts +1 -1
- package/dist/shared/flyout-events.js +1 -1
- package/dist/shared/form-field-controller.d.ts +3 -3
- package/dist/shared/intent-values.d.ts +0 -12
- package/dist/shared/intent-values.js +1 -1
- package/dist/shared/utilities.d.ts +0 -31
- package/dist/shared/utilities.js +1 -1
- package/dist/shared/validation.d.ts +2 -2
- package/dist/shared/validation.js +1 -1
- package/dist/slider/esp-slider.d.ts +4 -2
- package/dist/status-indicator/esp-status-indicator.js +2 -2
- package/dist/switch/esp-switch.d.ts +4 -2
- package/dist/tabs/esp-tab-group.d.ts +2 -2
- package/dist/tabs/esp-tab-group.js +4 -4
- package/dist/tabs/esp-tab.d.ts +2 -1
- package/dist/tabs/esp-tab.js +2 -2
- package/dist/textarea/esp-textarea.d.ts +6 -5
- package/dist/textarea/esp-textarea.js +1 -1
- package/dist/toaster/esp-toaster.d.ts +4 -4
- package/dist/toaster/esp-toaster.js +1 -1
- package/dist/tree/esp-tree.d.ts +2 -1
- package/dist/tree/esp-tree.js +26 -26
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var b=function(i,t,a,e){var s=arguments.length,o=s<3?t:e===null?e=Object.getOwnPropertyDescriptor(t,a):e,r;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")o=Reflect.decorate(i,t,a,e);else for(var l=i.length-1;l>=0;l--)(r=i[l])&&(o=(s<3?r(o):s>3?r(t,a,o):r(t,a))||o);return s>3&&o&&Object.defineProperty(t,a,o),o};import{css as u,html as d,nothing as
|
|
1
|
+
var b=function(i,t,a,e){var s=arguments.length,o=s<3?t:e===null?e=Object.getOwnPropertyDescriptor(t,a):e,r;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")o=Reflect.decorate(i,t,a,e);else for(var l=i.length-1;l>=0;l--)(r=i[l])&&(o=(s<3?r(o):s>3?r(t,a,o):r(t,a))||o);return s>3&&o&&Object.defineProperty(t,a,o),o};import{css as u,html as d,nothing as f}from"lit";import{customElement as v,property as m,state as g}from"lit/decorators.js";import{createRef as y,ref as w}from"lit/directives/ref.js";import{EspalierElementBase as c}from"../shared/esp-element-base.js";import{ESP_EVENTS as T}from"../shared/events.js";import{EspalierTab as p}from"./esp-tab.js";import{disabledControl as k}from"../shared/style-fragments.js";let n=class extends c{constructor(){super(...arguments),this.panelsSlot=y(),this.disabled=!1,this.tabData=[]}getTabs(){const t=this.panelsSlot.value?Array.from(this.panelsSlot.value.assignedElements()).filter(a=>a instanceof p):[];return t.length>0?t:Array.from(this.children).filter(a=>a instanceof p)}syncTabData(){const t=this.getTabs();if(t.length===0){this.tabData=[];return}const a=t.find(e=>e.active&&!e.disabled);if(a)for(const e of t)e!==a&&(e.active=!1);else{const e=t.find(s=>!s.disabled);e?e.active=!0:t[0].active=!0}this.tabData=t.map((e,s)=>{const o=`esp-tab-btn-${this.correlationId}-${s}`,r=`esp-tab-panel-${this.correlationId}-${s}`;return e.panelId=r,e.ariaLabelledBy=o,{label:e.label,active:e.active,disabled:this.disabled||e.disabled,buttonId:o,panelId:r}})}activateTab(t){const a=this.getTabs(),e=a[t];if(!(!e||e.disabled||this.disabled)){for(const s of a)s.active=s===e;this.syncTabData(),this.dispatchEvent(new CustomEvent(T.TAB_GROUP_CHANGED,{detail:{index:t,label:e.label},bubbles:!0,composed:!0}))}}handleTabClick(t){this.activateTab(t),this.updateComplete.then(()=>{this.shadowRoot?.getElementById(this.tabData[t]?.buttonId)?.focus()})}handleKeyDown(t){if(!["ArrowLeft","ArrowRight","Home","End"].includes(t.key))return;t.preventDefault();const e=this.tabData.map((l,h)=>({td:l,i:h})).filter(({td:l})=>!l.disabled).map(({i:l})=>l);if(e.length===0)return;const s=this.tabData.findIndex(l=>l.active),o=e.indexOf(s);let r;switch(t.key){case"ArrowRight":o===-1?r=e[0]:r=e[(o+1)%e.length];break;case"ArrowLeft":o===-1?r=e[e.length-1]:r=e[(o-1+e.length)%e.length];break;case"Home":r=e[0];break;case"End":r=e[e.length-1];break;default:return}this.activateTab(r),this.updateComplete.then(()=>{this.shadowRoot?.getElementById(this.tabData[r]?.buttonId)?.focus()})}handleChildUpdated(){this.syncTabData()}handleSlotChange(){this.syncTabData()}connectedCallback(){super.connectedCallback(),this.syncTabData()}willUpdate(t){super.willUpdate(t),t.has("disabled")&&this.syncTabData()}render(){return d`
|
|
2
2
|
<div class="tab-container">
|
|
3
3
|
<div class="tab-list" role="tablist" part="tab-list" @keydown=${this.handleKeyDown}>
|
|
4
4
|
${this.tabData.map((t,a)=>d`
|
|
@@ -9,7 +9,7 @@ var b=function(i,t,a,e){var s=arguments.length,o=s<3?t:e===null?e=Object.getOwnP
|
|
|
9
9
|
part="tab-button"
|
|
10
10
|
aria-selected=${t.active?"true":"false"}
|
|
11
11
|
aria-controls=${t.panelId}
|
|
12
|
-
aria-disabled=${t.disabled?"true":
|
|
12
|
+
aria-disabled=${t.disabled?"true":f}
|
|
13
13
|
tabindex=${t.active?"0":"-1"}
|
|
14
14
|
?disabled=${t.disabled}
|
|
15
15
|
@click=${()=>this.handleTabClick(a)}
|
|
@@ -22,7 +22,7 @@ var b=function(i,t,a,e){var s=arguments.length,o=s<3?t:e===null?e=Object.getOwnP
|
|
|
22
22
|
<slot
|
|
23
23
|
${w(this.panelsSlot)}
|
|
24
24
|
@slotchange=${this.handleSlotChange}
|
|
25
|
-
@esp-tab-updated=${this.handleChildUpdated}
|
|
25
|
+
@esp-internal-tab-updated=${this.handleChildUpdated}
|
|
26
26
|
></slot>
|
|
27
27
|
</div>
|
|
28
28
|
</div>
|
|
@@ -106,4 +106,4 @@ var b=function(i,t,a,e){var s=arguments.length,o=s<3?t:e===null?e=Object.getOwnP
|
|
|
106
106
|
.panels {
|
|
107
107
|
|
|
108
108
|
}
|
|
109
|
-
`],b([
|
|
109
|
+
`],b([m({type:Boolean,reflect:!0})],n.prototype,"disabled",void 0),b([g()],n.prototype,"tabData",void 0),n=b([v("esp-tab-group")],n);export{n as EspalierTabGroup};
|
package/dist/tabs/esp-tab.d.ts
CHANGED
|
@@ -48,7 +48,8 @@ import { EspalierElementBase } from "../shared/esp-element-base.js";
|
|
|
48
48
|
* @customElement esp-tab
|
|
49
49
|
* @slot - The default slot holds the panel content displayed
|
|
50
50
|
* when this tab is active.
|
|
51
|
-
*
|
|
51
|
+
* Label, active-state, and disabled-state updates are reported through a
|
|
52
|
+
* private coordination event consumed by the parent tab group.
|
|
52
53
|
*
|
|
53
54
|
* @csspart panel - The panel wrapper element.
|
|
54
55
|
*
|
package/dist/tabs/esp-tab.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var l=function(
|
|
1
|
+
var l=function(s,e,o,r){var p=arguments.length,a=p<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,o):r,n;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")a=Reflect.decorate(s,e,o,r);else for(var d=s.length-1;d>=0;d--)(n=s[d])&&(a=(p<3?n(a):p>3?n(e,o,a):n(e,o))||a);return p>3&&a&&Object.defineProperty(e,o,a),a};import{css as f,html as u}from"lit";import{customElement as c,property as i}from"lit/decorators.js";import{EspalierElementBase as b}from"../shared/esp-element-base.js";let t=class extends b{constructor(){super(...arguments),this.label="",this.active=!1,this.disabled=!1,this.panelId="",this.ariaLabelledBy=""}updated(e){super.updated(e),(e.has("label")||e.has("active")||e.has("disabled"))&&this.dispatchEvent(new CustomEvent("esp-internal-tab-updated",{bubbles:!0,composed:!0}))}render(){return u`
|
|
2
2
|
<div
|
|
3
3
|
part="panel"
|
|
4
4
|
role="tabpanel"
|
|
@@ -24,4 +24,4 @@ var l=function(i,e,o,r){var p=arguments.length,a=p<3?e:r===null?r=Object.getOwnP
|
|
|
24
24
|
color: var(--esp-color-text);
|
|
25
25
|
outline: none;
|
|
26
26
|
}
|
|
27
|
-
`],l([
|
|
27
|
+
`],l([i({type:String})],t.prototype,"label",void 0),l([i({type:Boolean,reflect:!0})],t.prototype,"active",void 0),l([i({type:Boolean,reflect:!0})],t.prototype,"disabled",void 0),l([i({attribute:!1})],t.prototype,"panelId",void 0),l([i({attribute:!1})],t.prototype,"ariaLabelledBy",void 0),t=l([c("esp-tab")],t);export{t as EspalierTab};
|
|
@@ -14,7 +14,7 @@ import { EspalierElementBase } from "../shared/esp-element-base.js";
|
|
|
14
14
|
* <script>
|
|
15
15
|
* const theTextarea = findByTagName("esp-textarea")[0];
|
|
16
16
|
* const theP = findByTagName("p")[0];
|
|
17
|
-
* theTextarea.addEventListener("value-changed", (ev) => {
|
|
17
|
+
* theTextarea.addEventListener("esp-value-changed", (ev) => {
|
|
18
18
|
* theP.innerText = ev.detail.length
|
|
19
19
|
* ? ev.detail
|
|
20
20
|
* : "The textarea is empty...";
|
|
@@ -54,7 +54,8 @@ import { EspalierElementBase } from "../shared/esp-element-base.js";
|
|
|
54
54
|
* ```
|
|
55
55
|
*
|
|
56
56
|
* @customElement esp-textarea
|
|
57
|
-
* @event {CustomEvent<string>} value-changed - Emitted when the textarea value changes.
|
|
57
|
+
* @event {CustomEvent<string>} esp-value-changed - Emitted when the textarea value changes.
|
|
58
|
+
* @event {CustomEvent<{ valid: boolean; message: string }>} esp-validity-changed - Emitted whenever constraint validation runs.
|
|
58
59
|
*
|
|
59
60
|
* ```html
|
|
60
61
|
* <esp-box>
|
|
@@ -64,7 +65,7 @@ import { EspalierElementBase } from "../shared/esp-element-base.js";
|
|
|
64
65
|
* <script>
|
|
65
66
|
* const theTextarea = findByTagName("esp-textarea")[0];
|
|
66
67
|
* const theP = findByTagName("p")[0];
|
|
67
|
-
* theTextarea.addEventListener("value-changed", (ev) => {
|
|
68
|
+
* theTextarea.addEventListener("esp-value-changed", (ev) => {
|
|
68
69
|
* theP.innerText = ev.detail.length
|
|
69
70
|
* ? ev.detail
|
|
70
71
|
* : "The textarea is empty...";
|
|
@@ -213,7 +214,7 @@ export declare class EspalierTextarea extends EspalierElementBase implements Esp
|
|
|
213
214
|
* <script>
|
|
214
215
|
* const theTextarea = findByTagName("esp-textarea")[0];
|
|
215
216
|
* const theButton = findByTagName("esp-button")[0];
|
|
216
|
-
* theButton.addEventListener("clicked", () => {
|
|
217
|
+
* theButton.addEventListener("esp-clicked", () => {
|
|
217
218
|
* theTextarea.focus();
|
|
218
219
|
* });
|
|
219
220
|
* </script>
|
|
@@ -221,7 +222,7 @@ export declare class EspalierTextarea extends EspalierElementBase implements Esp
|
|
|
221
222
|
*
|
|
222
223
|
*/
|
|
223
224
|
focus(options?: FocusOptions): void;
|
|
224
|
-
/** Re-run constraint validation and dispatch `validity-changed`. */
|
|
225
|
+
/** Re-run constraint validation and dispatch `esp-validity-changed`. */
|
|
225
226
|
validate(): void;
|
|
226
227
|
/** Check whether the current state is valid (delegates to ElementInternals). */
|
|
227
228
|
checkValidity(): boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var r=function(n,e,i,l){var h=arguments.length,a=h<3?e:l===null?l=Object.getOwnPropertyDescriptor(e,i):l,d;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")a=Reflect.decorate(n,e,i,l);else for(var u=n.length-1;u>=0;u--)(d=n[u])&&(a=(h<3?d(a):h>3?d(e,i,a):d(e,i))||a);return h>3&&a&&Object.defineProperty(e,i,a),a};import{css as m,html as p}from"lit";import{customElement as f,property as s}from"lit/decorators.js";import{ifDefined as o}from"lit/directives/if-defined.js";import{createRef as v,ref as g}from"lit/directives/ref.js";import{EspalierElementBase as c}from"../shared/esp-element-base.js";import{FormFieldController as y}from"../shared/form-field-controller.js";import{FormFieldDescriptionController as b}from"../shared/form-field-description-controller.js";let t=class extends c{constructor(){super(...arguments),this.internals=this.attachInternals(),this.theTextarea=v(),this.formCtrl=new y({host:this,internals:this.internals,getFormValue:()=>this.value||null,getValidity:()=>this._getValidity(),getValidationAnchor:()=>this.theTextarea.value??this,onReset:()=>{this.value="",this._hasVisibleError=!1},onRestore:e=>{this.value=e},onDisabled:e=>{this.disabled=e}}),this.formItemDescription=new b({host:this,getTarget:()=>this.theTextarea.value}),this._hasVisibleError=!1,this.fieldName="",this.value="",this.name="",this.required=!1,this.requiredMessage="",this.validationMessage="",this.disabled=!1,this._trackVisibleError=e=>{const i=e.detail;this._hasVisibleError=!i.valid}}handleInput(e){const i=e.target;this.value=i.value,this._syncInput()}_syncInput(){this._hasVisibleError?this.formCtrl.syncValue():this.formCtrl.syncValueSilently(),this.emitValueChanged(this.value)}_handleBlur(){this.formCtrl.syncValue()}_getValidity(){const e=this.theTextarea.value;if(e&&!e.validity.valid){const i=e.validity,l={valueMissing:i.valueMissing,tooLong:i.tooLong,tooShort:i.tooShort};return{flags:l,message:this._getFriendlyMessage(l)}}return this.required&&!this.value?{flags:{valueMissing:!0},message:this.requiredMessage||"Please fill out this field."}:null}_getFriendlyMessage(e){return e.valueMissing?this.requiredMessage||"Please fill out this field.":e.tooShort?this.validationMessage||`Must be at least ${this.minlength} characters.`:e.tooLong?this.validationMessage||`Must be no more than ${this.maxlength} characters.`:"Please enter a valid value."}focus(e){this.focusResolvedElementAfterUpdate(()=>this.theTextarea.value,e)}setFormItemDescription(e){this.formItemDescription.setDescription(e)}setFormItemLabel(e){this.formItemDescription.setLabel(e)}validate(){this.formCtrl.validate()}checkValidity(){return this.formCtrl.checkValidity()}formResetCallback(){this.formCtrl.handleFormReset()}formStateRestoreCallback(e){this.formCtrl.handleFormStateRestore(e)}formDisabledCallback(e){this.formCtrl.handleFormDisabled(e)}connectedCallback(){super.connectedCallback(),this.addEventListener("validity-changed",this._trackVisibleError)}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener("validity-changed",this._trackVisibleError)}render(){return p`
|
|
1
|
+
var r=function(n,e,i,l){var h=arguments.length,a=h<3?e:l===null?l=Object.getOwnPropertyDescriptor(e,i):l,d;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")a=Reflect.decorate(n,e,i,l);else for(var u=n.length-1;u>=0;u--)(d=n[u])&&(a=(h<3?d(a):h>3?d(e,i,a):d(e,i))||a);return h>3&&a&&Object.defineProperty(e,i,a),a};import{css as m,html as p}from"lit";import{customElement as f,property as s}from"lit/decorators.js";import{ifDefined as o}from"lit/directives/if-defined.js";import{createRef as v,ref as g}from"lit/directives/ref.js";import{EspalierElementBase as c}from"../shared/esp-element-base.js";import{FormFieldController as y}from"../shared/form-field-controller.js";import{FormFieldDescriptionController as b}from"../shared/form-field-description-controller.js";let t=class extends c{constructor(){super(...arguments),this.internals=this.attachInternals(),this.theTextarea=v(),this.formCtrl=new y({host:this,internals:this.internals,getFormValue:()=>this.value||null,getValidity:()=>this._getValidity(),getValidationAnchor:()=>this.theTextarea.value??this,onReset:()=>{this.value="",this._hasVisibleError=!1},onRestore:e=>{this.value=e},onDisabled:e=>{this.disabled=e}}),this.formItemDescription=new b({host:this,getTarget:()=>this.theTextarea.value}),this._hasVisibleError=!1,this.fieldName="",this.value="",this.name="",this.required=!1,this.requiredMessage="",this.validationMessage="",this.disabled=!1,this._trackVisibleError=e=>{const i=e.detail;this._hasVisibleError=!i.valid}}handleInput(e){const i=e.target;this.value=i.value,this._syncInput()}_syncInput(){this._hasVisibleError?this.formCtrl.syncValue():this.formCtrl.syncValueSilently(),this.emitValueChanged(this.value)}_handleBlur(){this.formCtrl.syncValue()}_getValidity(){const e=this.theTextarea.value;if(e&&!e.validity.valid){const i=e.validity,l={valueMissing:i.valueMissing,tooLong:i.tooLong,tooShort:i.tooShort};return{flags:l,message:this._getFriendlyMessage(l)}}return this.required&&!this.value?{flags:{valueMissing:!0},message:this.requiredMessage||"Please fill out this field."}:null}_getFriendlyMessage(e){return e.valueMissing?this.requiredMessage||"Please fill out this field.":e.tooShort?this.validationMessage||`Must be at least ${this.minlength} characters.`:e.tooLong?this.validationMessage||`Must be no more than ${this.maxlength} characters.`:"Please enter a valid value."}focus(e){this.focusResolvedElementAfterUpdate(()=>this.theTextarea.value,e)}setFormItemDescription(e){this.formItemDescription.setDescription(e)}setFormItemLabel(e){this.formItemDescription.setLabel(e)}validate(){this.formCtrl.validate()}checkValidity(){return this.formCtrl.checkValidity()}formResetCallback(){this.formCtrl.handleFormReset()}formStateRestoreCallback(e){this.formCtrl.handleFormStateRestore(e)}formDisabledCallback(e){this.formCtrl.handleFormDisabled(e)}connectedCallback(){super.connectedCallback(),this.addEventListener("esp-validity-changed",this._trackVisibleError)}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener("esp-validity-changed",this._trackVisibleError)}render(){return p`
|
|
2
2
|
<div class="esp-field">
|
|
3
3
|
<textarea
|
|
4
4
|
id=${this.fieldName}
|
|
@@ -60,14 +60,14 @@ import { EspalierElementBase } from "../shared/esp-element-base.js";
|
|
|
60
60
|
* <script>
|
|
61
61
|
* const msgInput = findById("toast-msg");
|
|
62
62
|
* const durInput = findById("toast-dur");
|
|
63
|
-
* findById("fire-toast").addEventListener("clicked", () => {
|
|
63
|
+
* findById("fire-toast").addEventListener("esp-clicked", () => {
|
|
64
64
|
* showToast({
|
|
65
65
|
* message: msgInput.value,
|
|
66
66
|
* duration: Number(durInput.value) || 5,
|
|
67
67
|
* icon: "bread"
|
|
68
68
|
* });
|
|
69
69
|
* });
|
|
70
|
-
* findById("fire-persistent").addEventListener("clicked", () => {
|
|
70
|
+
* findById("fire-persistent").addEventListener("esp-clicked", () => {
|
|
71
71
|
* showToast({
|
|
72
72
|
* message: msgInput.value,
|
|
73
73
|
* duration: 0,
|
|
@@ -75,14 +75,14 @@ import { EspalierElementBase } from "../shared/esp-element-base.js";
|
|
|
75
75
|
* intent: "warning"
|
|
76
76
|
* });
|
|
77
77
|
* });
|
|
78
|
-
* findById("fire-success").addEventListener("clicked", () => {
|
|
78
|
+
* findById("fire-success").addEventListener("esp-clicked", () => {
|
|
79
79
|
* showToast({
|
|
80
80
|
* message: "Operation completed successfully!",
|
|
81
81
|
* intent: "success",
|
|
82
82
|
* icon: "bread"
|
|
83
83
|
* });
|
|
84
84
|
* });
|
|
85
|
-
* findById("fire-danger").addEventListener("clicked", () => {
|
|
85
|
+
* findById("fire-danger").addEventListener("esp-clicked", () => {
|
|
86
86
|
* showToast({
|
|
87
87
|
* message: "Something went wrong!",
|
|
88
88
|
* intent: "danger",
|
|
@@ -3,7 +3,7 @@ var u=function(o,e,s,n){var c=arguments.length,r=c<3?e:n===null?n=Object.getOwnP
|
|
|
3
3
|
${this.toasts.map(e=>{const s=this.getToastIconHref(e);return l`<esp-info
|
|
4
4
|
.destroyable=${(e.duration??5)===0}
|
|
5
5
|
.intent=${e.intent??"info"}
|
|
6
|
-
@destroy=${()=>this.removeToast(e)}
|
|
6
|
+
@esp-info-destroy=${()=>this.removeToast(e)}
|
|
7
7
|
>
|
|
8
8
|
${s?y(s,{"aria-hidden":null,class:null,slot:"icon-slot"}):l``}
|
|
9
9
|
${e.message}</esp-info
|
package/dist/tree/esp-tree.d.ts
CHANGED
|
@@ -361,6 +361,7 @@ export declare function buildWebTreePath({ parentPath, segment, rootPath, }: Esp
|
|
|
361
361
|
* @event {CustomEvent<EspTreeNodeActionDetail>} esp-tree-cut - Fired when a cuttable node's cut action is invoked.
|
|
362
362
|
* @event {CustomEvent<EspTreeNodeActionDetail>} esp-tree-paste-child - Fired when a paste child target node's paste-as-child action is invoked.
|
|
363
363
|
* @event {CustomEvent<EspTreeGraftInputDetail>} esp-tree-graft-input - Fired live as the graft input changes.
|
|
364
|
+
* @event {CustomEvent<{ valid: boolean; message: string }>} esp-validity-changed - Fired whenever constraint validation runs.
|
|
364
365
|
*
|
|
365
366
|
* @docPageTitle Tree
|
|
366
367
|
* @docUrl /components/tree
|
|
@@ -513,7 +514,7 @@ export declare class EspalierTree extends EspalierElementBase {
|
|
|
513
514
|
formStateRestoreCallback(state: string): void;
|
|
514
515
|
/** Called by the browser when a parent `<fieldset>` is en/disabled. */
|
|
515
516
|
formDisabledCallback(isDisabled: boolean): void;
|
|
516
|
-
/** Re-run constraint validation and dispatch `validity-changed`. */
|
|
517
|
+
/** Re-run constraint validation and dispatch `esp-validity-changed`. */
|
|
517
518
|
validate(): void;
|
|
518
519
|
/** Check whether the current state is valid. */
|
|
519
520
|
checkValidity(): boolean;
|
package/dist/tree/esp-tree.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var d=function(c,e,t,i){var s=arguments.length,o=s<3?e:i===null?i=Object.getOwnPropertyDescriptor(e,t):i,r;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")o=Reflect.decorate(c,e,t,i);else for(var a=c.length-1;a>=0;a--)(r=c[a])&&(o=(s<3?r(o):s>3?r(e,t,o):r(e,t))||o);return s>3&&o&&Object.defineProperty(e,t,o),o};import{css as
|
|
1
|
+
var d=function(c,e,t,i){var s=arguments.length,o=s<3?e:i===null?i=Object.getOwnPropertyDescriptor(e,t):i,r;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")o=Reflect.decorate(c,e,t,i);else for(var a=c.length-1;a>=0;a--)(r=c[a])&&(o=(s<3?r(o):s>3?r(e,t,o):r(e,t))||o);return s>3&&o&&Object.defineProperty(e,t,o),o};import{css as D,html as p,nothing as u}from"lit";import{customElement as L,property as h,state as x}from"lit/decorators.js";import{classMap as m}from"lit/directives/class-map.js";import{createRef as $,ref as S}from"lit/directives/ref.js";import{unsafeHTML as C}from"lit/directives/unsafe-html.js";import{EspalierElementBase as z}from"../shared/esp-element-base.js";import{ESP_EVENTS as _}from"../shared/events.js";import{FormFieldController as F}from"../shared/form-field-controller.js";import{getIconHrefForHost as M}from"../shared/intent-values.js";import{caretRight as U}from"../shared/svgs/caret-right.js";import{renderSpriteIcon as G}from"../shared/svgs/render-sprite-icon.js";import"../box/esp-box.js";import"../action-menu/esp-action-menu.js";import"../button/esp-button.js";import"../dialog/esp-dialog.js";import"../form-item/esp-form-item.js";import"../info/esp-info.js";import"../input/esp-input.js";import"./esp-tree-item.js";import{EspalierTreeItem as P}from"./esp-tree-item.js";const B="A branch with that name already exists here.",q="Enter a name for the new branch.",V=500,T={edit:_.TREE_EDIT,delete:_.TREE_DELETE,"move-up":_.TREE_MOVE_UP,"move-down":_.TREE_MOVE_DOWN,cut:_.TREE_CUT,"paste-child":_.TREE_PASTE_CHILD},N={edit:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
2
2
|
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
|
|
3
3
|
<path d="M7 7h-1a2 2 0 0 0 -2 2v9a2 2 0 0 0 2 2h9a2 2 0 0 0 2 -2v-1" />
|
|
4
4
|
<path d="M20.385 6.585a2.1 2.1 0 0 0 -2.97 -2.97l-8.415 8.385v3h3l8.385 -8.415z" />
|
|
@@ -38,14 +38,14 @@ var d=function(c,e,t,i){var s=arguments.length,o=s<3?e:i===null?i=Object.getOwnP
|
|
|
38
38
|
<path d="M5 10a2 2 0 1 1 0 4a2 2 0 0 1 0 -4z" />
|
|
39
39
|
<path d="M12 10a2 2 0 1 1 0 4a2 2 0 0 1 0 -4z" />
|
|
40
40
|
<path d="M19 10a2 2 0 1 1 0 4a2 2 0 0 1 0 -4z" />
|
|
41
|
-
</svg>`};function
|
|
41
|
+
</svg>`};function R(c,e){return p`<span
|
|
42
42
|
slot=${e??u}
|
|
43
43
|
class="tree-action-icon"
|
|
44
44
|
aria-hidden="true"
|
|
45
45
|
focusable="false"
|
|
46
46
|
>
|
|
47
|
-
${
|
|
48
|
-
</span>`}function N(c){return c.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function H({parentPath:c,segment:e,rootPath:t}){return e?!c||c===t?t.endsWith("/")?`${t}${e}`:`${t}/${e}`:c.endsWith("/")?`${c}${e}`:`${c}/${e}`:c||t}let n=class extends z{constructor(){super(...arguments),this.internals=this.attachInternals(),this.formCtrl=new F({host:this,internals:this.internals,getFormValue:()=>this.value?this.value:null,getValidity:()=>this.required&&!this.value?{flags:{valueMissing:!0},message:this.requiredMessage||"Please select an option."}:null,onReset:()=>{this.value=this._defaultValue},onRestore:e=>{this.value=e},onDisabled:e=>{this.disabled=e}}),this.nodes=[],this.value="",this.name="",this.required=!1,this.requiredMessage="",this.disabled=!1,this.allowGraft=!1,this.rootLabel="/",this.rootPath="/",this.rootSelectable=!0,this.label="",this.graftError=null,this.buildPath=H,this.normalizeGraftSegment=({raw:e})=>N(e),this.keepExpanded=!1,this.expandIcon="",this.collapseIcon="",this._itemsSlot=$(),this._graftInputRef=$(),this._graftDialogRef=$(),this._slottedIds=new WeakMap,this._nextSlottedId=0,this._model=[],this._rowIndex=new Map,this._pathIndex=new Map,this._slottedNodes=[],this._lazyLoaded=new Map,this._grafted=new Map,this._expanded=new Set,this._loading=new Set,this._generation=0,this._defaultValue="",this._pendingFocus=!1,this._pendingScrollId=null,this._pendingGraftFocus=!1,this._nextGraftId=0,this._typeBuffer="",this._typeTimer=null,this._activeId=null,this._selectedId=null,this._graftParentId=null,this._graftValue="",this._graftErrorInternal=null}willUpdate(e){super.willUpdate(e);const t=!this.hasUpdated||e.has("nodes")||e.has("rootLabel")||e.has("rootPath")||e.has("rootSelectable")||e.has("buildPath");t&&(this.hasUpdated&&this._generation++,this._rebuildModel(),this._reconcileState()),e.has("value")?this._reconcileSelectionFromValue():t&&this._reconcileSelectionFromModel(),e.has("value")&&this.hasUpdated&&this.formCtrl.syncValue(),(t||e.has("value"))&&this._revealSelectedValue()}firstUpdated(e){super.firstUpdated(e),this._defaultValue=this.value,this.childElementCount>0&&this._onSlotChange(),this.formCtrl.syncValueSilently()}updated(e){if(super.updated(e),this._pendingFocus&&this._activeId&&(this._pendingFocus=!1,this._rowEl(this._activeId)?.focus({preventScroll:!0})),this._pendingGraftFocus&&(this._pendingGraftFocus=!1,this._graftInputRef.value?.focus()),this._syncGuidePaths(),this._pendingScrollId){const t=this._pendingScrollId;this._pendingScrollId=null,this._scrollRowIntoView(t)}}formResetCallback(){this.formCtrl.handleFormReset()}formStateRestoreCallback(e){this.formCtrl.handleFormStateRestore(e)}formDisabledCallback(e){this.formCtrl.handleFormDisabled(e)}validate(){this.formCtrl.validate()}checkValidity(){return this.formCtrl.checkValidity()}focus(){if(this.disabled)return;const e=this._visibleRows(),t=this._currentActive(e);t&&this._rowEl(t)?.focus()}setGraftError(e){this.graftError=e&&e.length>0?e:null}_rebuildModel(){const e=this.nodes.length?this.nodes:this._slottedNodes,t=this.rootPath||"/",i={id:"__root",segment:"",label:this.rootLabel||t,selectable:this.rootSelectable,hasChildren:!0},s=new Set(e.map(l=>l.segment.toLowerCase())),o=(this._grafted.get(i.id)??[]).filter(l=>!s.has(l.segment.toLowerCase())),r=e===this._slottedNodes,a=[...this._buildChildren(e,t,2,!1,i,r),...this._buildChildren(o,t,2,!0,i,!0)];this._model=[{id:i.id,segment:i.segment,label:i.label??t,icon:"",selectable:this.rootSelectable,editable:!1,deletable:!1,movableUp:!1,movableDown:!1,cuttable:!1,pasteChildTarget:!1,path:t,parentPath:"",parentId:"",level:1,hasChildren:a.length>0,loaded:!0,ephemeral:!1,root:!0,actions:[],children:a}],this._expanded.add(i.id)}_build(e,t,i,s,o,r=!1){if(!this._isUsableNodeId(e.id,r))return null;const a=this._buildPath(t,e.segment,e,o),l=e.children??[],g=e.hasChildren??!1,b=this._lazyLoaded.has(e.id),_=b?this._lazyLoaded.get(e.id)??[]:[],m=new Set([...l,..._].map(f=>f.segment.toLowerCase())),w=(this._grafted.get(e.id)??[]).filter(f=>!m.has(f.segment.toLowerCase())),y=[...this._buildChildren(l,a,i+1,s,e,r),...this._buildChildren(_,a,i+1,s,e,!1),...this._buildChildren(w,a,i+1,!0,e,!0)],I=e.label||e.segment;return{id:e.id,segment:e.segment,data:e.data,label:I,icon:e.icon??"",selectable:e.selectable!==!1,editable:e.editable===!0,deletable:e.deletable===!0,movableUp:e.movableUp===!0,movableDown:e.movableDown===!0,cuttable:e.cuttable===!0,pasteChildTarget:e.pasteChildTarget===!0,path:a,parentPath:t,parentId:o?.id??"",level:i,hasChildren:g||y.length>0,loaded:!g||b,ephemeral:s,root:!1,actions:this._actionsFor(e,I),children:y}}_actionsFor(e,t){const i=[],s=(o,r,a)=>{o&&i.push({kind:r,label:a,accessibleLabel:`${a} ${t}`})};return s(e.editable===!0,"edit","Edit"),s(e.deletable===!0,"delete","Delete"),s(e.movableUp===!0,"move-up","Move up"),s(e.movableDown===!0,"move-down","Move down"),s(e.cuttable===!0,"cut","Cut"),e.pasteChildTarget===!0&&i.push({kind:"paste-child",label:"Paste as child",accessibleLabel:`Paste as child of ${t}`}),i}_buildChildren(e,t,i,s,o,r=!1){return e.flatMap(a=>{const l=this._build(a,t,i,s,o,r);return l?[l]:[]})}_isUsableNodeId(e,t){return e?!t&&this._isGeneratedId(e)?(console.warn(`esp-tree: reserved node id "${e}" ignored.`),!1):!0:(console.warn("esp-tree: node without a stable id ignored."),!1)}_isGeneratedId(e){return e==="__root"||e.startsWith("__slotted:")||e.startsWith("__graft:")}_reconcileState(){this._rowIndex.clear(),this._pathIndex.clear();const e=t=>{for(const i of t){if(this._rowIndex.has(i.id)){console.warn(`esp-tree: duplicate node id "${i.id}" ignored.`);continue}this._pathIndex.has(i.path)?console.warn(`esp-tree: duplicate path "${i.path}" for ids "${this._pathIndex.get(i.path).id}" and "${i.id}".`):this._pathIndex.set(i.path,i),this._rowIndex.set(i.id,i),e(i.children)}};e(this._model);for(const t of[...this._expanded])this._rowIndex.has(t)||this._expanded.delete(t);for(const t of[...this._lazyLoaded.keys()])this._rowIndex.has(t)||this._lazyLoaded.delete(t);for(const t of[...this._grafted.keys()])this._rowIndex.has(t)||this._grafted.delete(t);this._activeId&&!this._rowIndex.has(this._activeId)&&(this._activeId=null)}_revealSelectedValue(){if(!this.value&&!this._selectedId)return;let e=this._selectedId?this._rowIndex.get(this._selectedId):void 0;for(e??=this.value?this._pathIndex.get(this.value):void 0;e&&e.parentId;)this._expanded.add(e.parentId),e=this._rowIndex.get(e.parentId)}_reconcileSelectionFromValue(){if(this._selectedId){const e=this._findRowById(this._selectedId);if(e&&e.path===this.value)return}this._selectedId=this.value?this._findRow(this.value)?.id??null:null}_reconcileSelectionFromModel(){if(this._selectedId){const e=this._findRowById(this._selectedId);if(e){this.value!==e.path&&(this.value=e.path,this.hasUpdated&&this.formCtrl.syncValue(),this._emit("esp-tree-select",{path:e.path,node:this._toPublic(e)}));return}this._selectedId=null}this.value&&(this._selectedId=this._findRow(this.value)?.id??null)}_buildPath(e,t,i,s){return this.buildPath({parentPath:e,segment:t,node:i,parentNode:s,rootPath:this.rootPath||"/"})}_joinPath(e,t){const i=e?this._findRow(e):null;return this._buildPath(e,t,{id:t,segment:t,label:t},i?this._toPublic(i):null)}_findRow(e){return this._pathIndex.get(e)??null}_findRowById(e){return this._rowIndex.get(e)??null}_isIndexedRow(e){return this._rowIndex.get(e.id)===e}_visibleRows(){const e=[],t=i=>{for(const s of i)this._isIndexedRow(s)&&(e.push(s),s.children.length&&this._expanded.has(s.id)&&t(s.children))};return t(this._model),e}_currentActive(e){return this._activeId&&e.some(t=>t.id===this._activeId)?this._activeId:e[0]?.id??null}_rowEl(e){const t=globalThis.CSS?.escape?.(e)??e.replace(/\\/g,"\\\\").replace(/"/g,'\\"');return this.shadowRoot?.querySelector(`[data-id="${t}"]`)??null}_scrollRowIntoView(e){this._rowEl(e)?.scrollIntoView?.({block:"nearest",inline:"nearest"})}_toPublic(e){return{id:e.id,segment:e.segment,data:e.data,label:e.label,icon:e.icon||void 0,selectable:e.selectable,editable:e.editable,deletable:e.deletable,movableUp:e.movableUp,movableDown:e.movableDown,cuttable:e.cuttable,pasteChildTarget:e.pasteChildTarget,hasChildren:e.hasChildren}}_emit(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0,composed:!0}))}_setExpanded(e,t){t!==this._expanded.has(e.id)&&(t?(this._expanded.add(e.id),e.hasChildren&&!e.loaded&&this._ensureLoaded(e)):this._expanded.delete(e.id),this._emit("esp-tree-toggle",{path:e.path,node:this._toPublic(e),open:t}),this.requestUpdate())}_toggle(e){e.hasChildren&&this._setExpanded(e,!this._expanded.has(e.id))}async _ensureLoaded(e){if(e.loaded||!e.hasChildren||this._loading.has(e.id)||!this.loadChildren)return;const t=this._generation;this._loading.add(e.id),this.requestUpdate();try{const i=await this.loadChildren({id:e.id,segment:e.segment,data:e.data,label:e.label,path:e.path,level:e.level});if(t!==this._generation)return;this._lazyLoaded.set(e.id,i??[]),this._rebuildModel(),this._reconcileState(),this._reconcileSelectionFromModel(),this._pendingScrollId=e.id}catch{}finally{this._loading.delete(e.id),this.requestUpdate()}}_select(e){if(!e.selectable)return;e.hasChildren&&!this._expanded.has(e.id)&&this._setExpanded(e,!0);const t=this._isSelected(e)&&this.value===e.path;this._selectedId=e.id,!t&&(this.value=e.path,this._emit("esp-tree-select",{path:e.path,node:this._toPublic(e)}))}_containsRow(e,t){if(e.id===t.id)return!0;for(;t.parentId;){if(t.parentId===e.id)return!0;const i=this._findRowById(t.parentId);if(!i)break;t=i}return!1}_collapseSelectedBranchOutside(e){if(this.keepExpanded||!this.value&&!this._selectedId||this._isSelected(e))return;const t=this._selectedId?this._findRowById(this._selectedId):this.value?this._findRow(this.value):null;!t?.hasChildren||!this._expanded.has(t.id)||this._containsRow(t,e)||this._setExpanded(t,!1)}_isSelected(e){return this._selectedId===e.id}_setActiveId(e){this._activeId=e,this._pendingFocus=!0,this._pendingScrollId=e}_setActiveRow(e){this._setActiveId(e.id)}_activateAndSelect(e){this._setActiveRow(e),this._collapseSelectedBranchOutside(e),this._select(e),this.requestUpdate()}_onRowClick(e){if(this.disabled)return;if(this._isSelected(e)&&e.selectable&&e.hasChildren){this._setActiveRow(e),this._toggle(e),this.requestUpdate();return}this._activateAndSelect(e)}_onToggleClick(e,t){e.stopPropagation(),!(this.disabled||!t.hasChildren)&&(this._setActiveRow(t),this._toggle(t),this.requestUpdate())}_edit(e){e.editable&&this._emit(G.edit,{path:e.path,node:this._toPublic(e)})}_onActionEvent(e,t,i){e.stopPropagation(),!this.disabled&&(this._activeId=t.id,this._emit(G[i],{path:t.path,node:this._toPublic(t)}),this.requestUpdate())}_onActionMenuSelect(e,t){e.stopPropagation();const i=e.detail.value;t.actions.some(s=>s.kind===i)&&this._onActionEvent(e,t,i)}_stopRowActionEvent(e){e.stopPropagation()}_onRowActionsKeydown(e,t){e.stopPropagation(),!e.defaultPrevented&&(e.key!=="ArrowLeft"&&e.key!=="Escape"||(e.preventDefault(),this._closeRowActionMenus(),this._focusRow(t)))}_onKeydown(e){if(this.disabled)return;const t=e.target;if(t instanceof HTMLElement&&t.closest("button, input, textarea, select, a[href], esp-button, esp-action-menu, esp-action-menu-item, .node-actions"))return;const i=this._visibleRows();if(!i.length)return;const s=this._currentActive(i);let o=i.findIndex(a=>a.id===s);o<0&&(o=0);const r=i[o];if(r){if(e.key==="F10"&&e.shiftKey||e.key==="ContextMenu"){if(r.actions.length===0)return;e.preventDefault(),this._focusRowActions(r);return}switch(e.key){case"ArrowDown":e.preventDefault(),this._moveActive(i[Math.min(o+1,i.length-1)]);break;case"ArrowUp":e.preventDefault(),this._moveActive(i[Math.max(o-1,0)]);break;case"Home":e.preventDefault(),this._moveActive(i[0]);break;case"End":e.preventDefault(),this._moveActive(i[i.length-1]);break;case"ArrowRight":if(e.preventDefault(),r.hasChildren&&!this._expanded.has(r.id)){this._setActiveRow(r),this._setExpanded(r,!0);break}if(r.actions.length>0&&this._focusRowActionTrigger(r))break;if(r.hasChildren&&this._expanded.has(r.id)){const a=i[o+1];if(a&&a.parentId===r.id){this._moveActive(a);break}}break;case"ArrowLeft":if(e.preventDefault(),r.hasChildren&&this._expanded.has(r.id))this._setActiveRow(r),this._setExpanded(r,!1);else if(r.parentId){const a=i.find(l=>l.id===r.parentId);a&&this._moveActive(a)}break;case"Enter":case" ":e.preventDefault(),this._activateAndSelect(r);break;case"F2":if(!r.editable)break;e.preventDefault(),this._setActiveRow(r),this._edit(r),this.requestUpdate();break;case"Insert":if(!this.allowGraft)break;e.preventDefault(),this._openGraftForRow(r);break;default:e.key.length===1&&!e.ctrlKey&&!e.metaKey&&!e.altKey&&(e.preventDefault(),this._typeahead(e.key,i,o));break}}}_moveActive(e){e&&(this._closeRowActionMenus(),this._setActiveRow(e),this.requestUpdate())}_focusRow(e){this._closeRowActionMenus(),this._activeId=e.id,this._rowEl(e.id)?.focus({preventScroll:!0}),this.requestUpdate()}_closeRowActionMenus(){this.shadowRoot?.querySelectorAll("esp-action-menu.node-action-menu").forEach(e=>e.closeMenu?.({restoreFocus:!1}))}async _focusRowActions(e){const i=this._rowEl(e.id)?.querySelector(".node-actions");if(!i)return;if(e.actions.length===1){i.querySelector("esp-button")?.focus({preventScroll:!0});return}const s=i.querySelector("esp-action-menu");if(!s)return;s.openMenu(),await s.updateComplete;const o=s;if(typeof o.focusFirstItem=="function"){o.focusFirstItem();return}s.querySelector("esp-action-menu-item:not([disabled])")?.focus()}_focusRowActionTrigger(e){const i=this._rowEl(e.id)?.querySelector(".node-actions esp-button");return i?(i.focus({preventScroll:!0}),!0):!1}_typeahead(e,t,i){this._typeTimer&&clearTimeout(this._typeTimer),this._typeBuffer+=e.toLowerCase(),this._typeTimer=setTimeout(()=>{this._typeBuffer="",this._typeTimer=null},U);const s=t.length;for(let o=1;o<=s;o++){const r=t[(i+o)%s];if(r&&r.label.toLowerCase().startsWith(this._typeBuffer)){this._moveActive(r);return}}}_onSlotChange(){const e=Array.from(this.children).filter(t=>t instanceof P);this._slottedNodes=e.map(t=>this._parseItem(t)),this._generation++,this._rebuildModel(),this._reconcileState(),this.requestUpdate()}_parseItem(e){const t=this._idForSlottedItem(e),i=e.getAttribute("segment")??e.segment??"",s=e.getAttribute("label")??e.label,o=e.getAttribute("icon")??e.icon,r=e.getAttribute("selectable"),a=r===null?e.selectable:r!=="false",l=e.hasAttribute("editable")||e.editable,g=e.hasAttribute("deletable")||e.deletable,b=e.hasAttribute("movable-up")||e.movableUp,_=e.hasAttribute("movable-down")||e.movableDown,m=e.hasAttribute("cuttable")||e.cuttable,w=e.hasAttribute("paste-child-target")||e.pasteChildTarget,y=e.hasAttribute("has-children")||e.hasChildren,I=Array.from(e.children).filter(x=>x instanceof P),f={id:t,segment:i,data:e.data,selectable:a,hasChildren:y};s&&(f.label=s),o&&(f.icon=o),l&&(f.editable=!0),g&&(f.deletable=!0),b&&(f.movableUp=!0),_&&(f.movableDown=!0),m&&(f.cuttable=!0),w&&(f.pasteChildTarget=!0);const C=I.map(x=>this._parseItem(x));return C.length&&(f.children=C),f}_idForSlottedItem(e){const t=this._slottedIds.get(e);if(t)return t;if(e.id&&!this._isGeneratedId(e.id))return this._slottedIds.set(e,e.id),e.id;e.id&&console.warn(`esp-tree: reserved slotted item id "${e.id}" ignored.`);const i=`__slotted:${++this._nextSlottedId}`;return this._slottedIds.set(e,i),i}_onGraftAddClick(e,t){e.stopPropagation(),!this.disabled&&this._openGraftForRow(t)}_openGraftForRow(e){if(this.disabled)return;const t=e??this._model[0]??null,i=this._rowPath(t);this._requestGraft(t,i)&&(t&&(this._setActiveRow(t),this._expanded.add(t.id)),this._openGraft(t?.id??"__root"))}_requestGraft(e,t){return this.dispatchEvent(new CustomEvent("esp-tree-graft-request",{detail:{parentPath:t,parentNode:e?this._toPublic(e):null},bubbles:!0,composed:!0,cancelable:!0}))}_openGraft(e){this._graftParentId=e,this._graftValue="",this._graftErrorInternal=null,this.graftError=null,this._pendingGraftFocus=!0,this.requestUpdate(),this.updateComplete.then(()=>{if(this._graftParentId!==e)return;const t=this._graftDialogRef.value;t&&!t.hasAttribute("is-open")&&t.toggleOpen()})}_cancelGraft(){this._closeGraftDialog(),this._resetGraftState()}_closeGraftDialog(){const e=this._graftDialogRef.value;e?.hasAttribute("is-open")&&e.toggleOpen()}_resetGraftState(){this._graftParentId=null,this._graftValue="",this._graftErrorInternal=null,this.graftError=null}_onGraftDialogClosed(){this._resetGraftState()}_onGraftInput(e){const t=e.detail??e.target.value;this._graftValue=t;const i=this._graftParentPath(),s=this._normalizeGraft(t,i),{valid:o,reason:r}=this._validateSegment(i,s);this._graftErrorInternal=null,this._emit("esp-tree-graft-input",{parentPath:i,raw:t,segment:s,path:this._joinPath(i,s),valid:o,reason:r})}_onGraftKeydown(e){if(e.stopPropagation(),e.key==="Enter")e.preventDefault(),this._commitGraft();else if(e.key==="Escape"){e.preventDefault();const t=this._graftParentId;this._cancelGraft(),t&&this._moveActive(this._findRowById(t)??void 0)}}_commitGraft(){if(this.disabled)return;const e=this._graftParentRow(),t=e?.id??"__root",i=this._rowPath(e),s=this._normalizeGraft(this._graftValue,i),{valid:o,reason:r}=this._validateSegment(i,s);if(!o){this._graftErrorInternal=r==="duplicate"?B:q;return}if(this.graftError)return;const a=this._joinPath(i,s),l={id:`__graft:${++this._nextGraftId}`,segment:s,label:s,selectable:!0},g=this._grafted.get(t)??[];g.push(l),this._grafted.set(t,g),this._rebuildModel(),this._reconcileState(),e&&this._expanded.add(e.id),this._closeGraftDialog(),this._resetGraftState(),this.value=a,this._selectedId=l.id,this._setActiveId(l.id);const b=this._findRowById(l.id),_=b?this._toPublic(b):l;this._emit("esp-tree-graft",{parentPath:i,segment:s,path:a,node:_}),this._emit("esp-tree-select",{path:a,node:_}),this.requestUpdate()}_validateSegment(e,t){return t?this._siblingSegments(e).has(t.toLowerCase())?{valid:!1,reason:"duplicate"}:{valid:!0,reason:""}:{valid:!1,reason:"empty"}}_siblingSegments(e){const t=e?this._findRow(e)?.children??[]:this._model;return new Set(t.map(i=>i.segment.toLowerCase()))}_normalizeGraft(e,t){return this.normalizeGraftSegment({raw:e,parentPath:t})}_graftParentPath(){return this._rowPath(this._graftParentRow())}_graftParentRow(){return this._graftParentId?this._findRowById(this._graftParentId)??this._model[0]??null:this._model[0]??null}_rowPath(e){return e?.path??(this.rootPath||"/")}render(){const e=this._visibleRows(),t=this._currentActive(e);return p`
|
|
47
|
+
${C(N[c])}
|
|
48
|
+
</span>`}function H(c){return c.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function j({parentPath:c,segment:e,rootPath:t}){return e?!c||c===t?t.endsWith("/")?`${t}${e}`:`${t}/${e}`:c.endsWith("/")?`${c}${e}`:`${c}/${e}`:c||t}let n=class extends z{constructor(){super(...arguments),this.internals=this.attachInternals(),this.formCtrl=new F({host:this,internals:this.internals,getFormValue:()=>this.value?this.value:null,getValidity:()=>this.required&&!this.value?{flags:{valueMissing:!0},message:this.requiredMessage||"Please select an option."}:null,onReset:()=>{this.value=this._defaultValue},onRestore:e=>{this.value=e},onDisabled:e=>{this.disabled=e}}),this.nodes=[],this.value="",this.name="",this.required=!1,this.requiredMessage="",this.disabled=!1,this.allowGraft=!1,this.rootLabel="/",this.rootPath="/",this.rootSelectable=!0,this.label="",this.graftError=null,this.buildPath=j,this.normalizeGraftSegment=({raw:e})=>H(e),this.keepExpanded=!1,this.expandIcon="",this.collapseIcon="",this._itemsSlot=$(),this._graftInputRef=$(),this._graftDialogRef=$(),this._slottedIds=new WeakMap,this._nextSlottedId=0,this._model=[],this._rowIndex=new Map,this._pathIndex=new Map,this._slottedNodes=[],this._lazyLoaded=new Map,this._grafted=new Map,this._expanded=new Set,this._loading=new Set,this._generation=0,this._defaultValue="",this._pendingFocus=!1,this._pendingScrollId=null,this._pendingGraftFocus=!1,this._nextGraftId=0,this._typeBuffer="",this._typeTimer=null,this._activeId=null,this._selectedId=null,this._graftParentId=null,this._graftValue="",this._graftErrorInternal=null}willUpdate(e){super.willUpdate(e);const t=!this.hasUpdated||e.has("nodes")||e.has("rootLabel")||e.has("rootPath")||e.has("rootSelectable")||e.has("buildPath");t&&(this.hasUpdated&&this._generation++,this._rebuildModel(),this._reconcileState()),e.has("value")?this._reconcileSelectionFromValue():t&&this._reconcileSelectionFromModel(),e.has("value")&&this.hasUpdated&&this.formCtrl.syncValue(),(t||e.has("value"))&&this._revealSelectedValue()}firstUpdated(e){super.firstUpdated(e),this._defaultValue=this.value,this.childElementCount>0&&this._onSlotChange(),this.formCtrl.syncValueSilently()}updated(e){if(super.updated(e),this._pendingFocus&&this._activeId&&(this._pendingFocus=!1,this._rowEl(this._activeId)?.focus({preventScroll:!0})),this._pendingGraftFocus&&(this._pendingGraftFocus=!1,this._graftInputRef.value?.focus()),this._syncGuidePaths(),this._pendingScrollId){const t=this._pendingScrollId;this._pendingScrollId=null,this._scrollRowIntoView(t)}}formResetCallback(){this.formCtrl.handleFormReset()}formStateRestoreCallback(e){this.formCtrl.handleFormStateRestore(e)}formDisabledCallback(e){this.formCtrl.handleFormDisabled(e)}validate(){this.formCtrl.validate()}checkValidity(){return this.formCtrl.checkValidity()}focus(){if(this.disabled)return;const e=this._visibleRows(),t=this._currentActive(e);t&&this._rowEl(t)?.focus()}setGraftError(e){this.graftError=e&&e.length>0?e:null}_rebuildModel(){const e=this.nodes.length?this.nodes:this._slottedNodes,t=this.rootPath||"/",i={id:"__root",segment:"",label:this.rootLabel||t,selectable:this.rootSelectable,hasChildren:!0},s=new Set(e.map(l=>l.segment.toLowerCase())),o=(this._grafted.get(i.id)??[]).filter(l=>!s.has(l.segment.toLowerCase())),r=e===this._slottedNodes,a=[...this._buildChildren(e,t,2,!1,i,r),...this._buildChildren(o,t,2,!0,i,!0)];this._model=[{id:i.id,segment:i.segment,label:i.label??t,icon:"",selectable:this.rootSelectable,editable:!1,deletable:!1,movableUp:!1,movableDown:!1,cuttable:!1,pasteChildTarget:!1,path:t,parentPath:"",parentId:"",level:1,hasChildren:a.length>0,loaded:!0,ephemeral:!1,root:!0,actions:[],children:a}],this._expanded.add(i.id)}_build(e,t,i,s,o,r=!1){if(!this._isUsableNodeId(e.id,r))return null;const a=this._buildPath(t,e.segment,e,o),l=e.children??[],g=e.hasChildren??!1,v=this._lazyLoaded.has(e.id),b=v?this._lazyLoaded.get(e.id)??[]:[],w=new Set([...l,...b].map(f=>f.segment.toLowerCase())),y=(this._grafted.get(e.id)??[]).filter(f=>!w.has(f.segment.toLowerCase())),I=[...this._buildChildren(l,a,i+1,s,e,r),...this._buildChildren(b,a,i+1,s,e,!1),...this._buildChildren(y,a,i+1,!0,e,!0)],k=e.label||e.segment;return{id:e.id,segment:e.segment,data:e.data,label:k,icon:e.icon??"",selectable:e.selectable!==!1,editable:e.editable===!0,deletable:e.deletable===!0,movableUp:e.movableUp===!0,movableDown:e.movableDown===!0,cuttable:e.cuttable===!0,pasteChildTarget:e.pasteChildTarget===!0,path:a,parentPath:t,parentId:o?.id??"",level:i,hasChildren:g||I.length>0,loaded:!g||v,ephemeral:s,root:!1,actions:this._actionsFor(e,k),children:I}}_actionsFor(e,t){const i=[],s=(o,r,a)=>{o&&i.push({kind:r,label:a,accessibleLabel:`${a} ${t}`})};return s(e.editable===!0,"edit","Edit"),s(e.deletable===!0,"delete","Delete"),s(e.movableUp===!0,"move-up","Move up"),s(e.movableDown===!0,"move-down","Move down"),s(e.cuttable===!0,"cut","Cut"),e.pasteChildTarget===!0&&i.push({kind:"paste-child",label:"Paste as child",accessibleLabel:`Paste as child of ${t}`}),i}_buildChildren(e,t,i,s,o,r=!1){return e.flatMap(a=>{const l=this._build(a,t,i,s,o,r);return l?[l]:[]})}_isUsableNodeId(e,t){return e?!t&&this._isGeneratedId(e)?(console.warn(`esp-tree: reserved node id "${e}" ignored.`),!1):!0:(console.warn("esp-tree: node without a stable id ignored."),!1)}_isGeneratedId(e){return e==="__root"||e.startsWith("__slotted:")||e.startsWith("__graft:")}_reconcileState(){this._rowIndex.clear(),this._pathIndex.clear();const e=t=>{for(const i of t){if(this._rowIndex.has(i.id)){console.warn(`esp-tree: duplicate node id "${i.id}" ignored.`);continue}this._pathIndex.has(i.path)?console.warn(`esp-tree: duplicate path "${i.path}" for ids "${this._pathIndex.get(i.path).id}" and "${i.id}".`):this._pathIndex.set(i.path,i),this._rowIndex.set(i.id,i),e(i.children)}};e(this._model);for(const t of[...this._expanded])this._rowIndex.has(t)||this._expanded.delete(t);for(const t of[...this._lazyLoaded.keys()])this._rowIndex.has(t)||this._lazyLoaded.delete(t);for(const t of[...this._grafted.keys()])this._rowIndex.has(t)||this._grafted.delete(t);this._activeId&&!this._rowIndex.has(this._activeId)&&(this._activeId=null)}_revealSelectedValue(){if(!this.value&&!this._selectedId)return;let e=this._selectedId?this._rowIndex.get(this._selectedId):void 0;for(e??=this.value?this._pathIndex.get(this.value):void 0;e&&e.parentId;)this._expanded.add(e.parentId),e=this._rowIndex.get(e.parentId)}_reconcileSelectionFromValue(){if(this._selectedId){const e=this._findRowById(this._selectedId);if(e&&e.path===this.value)return}this._selectedId=this.value?this._findRow(this.value)?.id??null:null}_reconcileSelectionFromModel(){if(this._selectedId){const e=this._findRowById(this._selectedId);if(e){this.value!==e.path&&(this.value=e.path,this.hasUpdated&&this.formCtrl.syncValue(),this._emit(_.TREE_SELECT,{path:e.path,node:this._toPublic(e)}));return}this._selectedId=null}this.value&&(this._selectedId=this._findRow(this.value)?.id??null)}_buildPath(e,t,i,s){return this.buildPath({parentPath:e,segment:t,node:i,parentNode:s,rootPath:this.rootPath||"/"})}_joinPath(e,t){const i=e?this._findRow(e):null;return this._buildPath(e,t,{id:t,segment:t,label:t},i?this._toPublic(i):null)}_findRow(e){return this._pathIndex.get(e)??null}_findRowById(e){return this._rowIndex.get(e)??null}_isIndexedRow(e){return this._rowIndex.get(e.id)===e}_visibleRows(){const e=[],t=i=>{for(const s of i)this._isIndexedRow(s)&&(e.push(s),s.children.length&&this._expanded.has(s.id)&&t(s.children))};return t(this._model),e}_currentActive(e){return this._activeId&&e.some(t=>t.id===this._activeId)?this._activeId:e[0]?.id??null}_rowEl(e){const t=globalThis.CSS?.escape?.(e)??e.replace(/\\/g,"\\\\").replace(/"/g,'\\"');return this.shadowRoot?.querySelector(`[data-id="${t}"]`)??null}_scrollRowIntoView(e){this._rowEl(e)?.scrollIntoView?.({block:"nearest",inline:"nearest"})}_toPublic(e){return{id:e.id,segment:e.segment,data:e.data,label:e.label,icon:e.icon||void 0,selectable:e.selectable,editable:e.editable,deletable:e.deletable,movableUp:e.movableUp,movableDown:e.movableDown,cuttable:e.cuttable,pasteChildTarget:e.pasteChildTarget,hasChildren:e.hasChildren}}_emit(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0,composed:!0}))}_setExpanded(e,t){t!==this._expanded.has(e.id)&&(t?(this._expanded.add(e.id),e.hasChildren&&!e.loaded&&this._ensureLoaded(e)):this._expanded.delete(e.id),this._emit(_.TREE_TOGGLE,{path:e.path,node:this._toPublic(e),open:t}),this.requestUpdate())}_toggle(e){e.hasChildren&&this._setExpanded(e,!this._expanded.has(e.id))}async _ensureLoaded(e){if(e.loaded||!e.hasChildren||this._loading.has(e.id)||!this.loadChildren)return;const t=this._generation;this._loading.add(e.id),this.requestUpdate();try{const i=await this.loadChildren({id:e.id,segment:e.segment,data:e.data,label:e.label,path:e.path,level:e.level});if(t!==this._generation)return;this._lazyLoaded.set(e.id,i??[]),this._rebuildModel(),this._reconcileState(),this._reconcileSelectionFromModel(),this._pendingScrollId=e.id}catch{}finally{this._loading.delete(e.id),this.requestUpdate()}}_select(e){if(!e.selectable)return;e.hasChildren&&!this._expanded.has(e.id)&&this._setExpanded(e,!0);const t=this._isSelected(e)&&this.value===e.path;this._selectedId=e.id,!t&&(this.value=e.path,this._emit(_.TREE_SELECT,{path:e.path,node:this._toPublic(e)}))}_containsRow(e,t){if(e.id===t.id)return!0;for(;t.parentId;){if(t.parentId===e.id)return!0;const i=this._findRowById(t.parentId);if(!i)break;t=i}return!1}_collapseSelectedBranchOutside(e){if(this.keepExpanded||!this.value&&!this._selectedId||this._isSelected(e))return;const t=this._selectedId?this._findRowById(this._selectedId):this.value?this._findRow(this.value):null;!t?.hasChildren||!this._expanded.has(t.id)||this._containsRow(t,e)||this._setExpanded(t,!1)}_isSelected(e){return this._selectedId===e.id}_setActiveId(e){this._activeId=e,this._pendingFocus=!0,this._pendingScrollId=e}_setActiveRow(e){this._setActiveId(e.id)}_activateAndSelect(e){this._setActiveRow(e),this._collapseSelectedBranchOutside(e),this._select(e),this.requestUpdate()}_onRowClick(e){if(this.disabled)return;if(this._isSelected(e)&&e.selectable&&e.hasChildren){this._setActiveRow(e),this._toggle(e),this.requestUpdate();return}this._activateAndSelect(e)}_onToggleClick(e,t){e.stopPropagation(),!(this.disabled||!t.hasChildren)&&(this._setActiveRow(t),this._toggle(t),this.requestUpdate())}_edit(e){e.editable&&this._emit(T.edit,{path:e.path,node:this._toPublic(e)})}_onActionEvent(e,t,i){e.stopPropagation(),!this.disabled&&(this._activeId=t.id,this._emit(T[i],{path:t.path,node:this._toPublic(t)}),this.requestUpdate())}_onActionMenuSelect(e,t){e.stopPropagation();const i=e.detail.value;t.actions.some(s=>s.kind===i)&&this._onActionEvent(e,t,i)}_stopRowActionEvent(e){e.stopPropagation()}_onRowActionsKeydown(e,t){e.stopPropagation(),!e.defaultPrevented&&(e.key!=="ArrowLeft"&&e.key!=="Escape"||(e.preventDefault(),this._closeRowActionMenus(),this._focusRow(t)))}_onKeydown(e){if(this.disabled)return;const t=e.target;if(t instanceof HTMLElement&&t.closest("button, input, textarea, select, a[href], esp-button, esp-action-menu, esp-action-menu-item, .node-actions"))return;const i=this._visibleRows();if(!i.length)return;const s=this._currentActive(i);let o=i.findIndex(a=>a.id===s);o<0&&(o=0);const r=i[o];if(r){if(e.key==="F10"&&e.shiftKey||e.key==="ContextMenu"){if(r.actions.length===0)return;e.preventDefault(),this._focusRowActions(r);return}switch(e.key){case"ArrowDown":e.preventDefault(),this._moveActive(i[Math.min(o+1,i.length-1)]);break;case"ArrowUp":e.preventDefault(),this._moveActive(i[Math.max(o-1,0)]);break;case"Home":e.preventDefault(),this._moveActive(i[0]);break;case"End":e.preventDefault(),this._moveActive(i[i.length-1]);break;case"ArrowRight":if(e.preventDefault(),r.hasChildren&&!this._expanded.has(r.id)){this._setActiveRow(r),this._setExpanded(r,!0);break}if(r.actions.length>0&&this._focusRowActionTrigger(r))break;if(r.hasChildren&&this._expanded.has(r.id)){const a=i[o+1];if(a&&a.parentId===r.id){this._moveActive(a);break}}break;case"ArrowLeft":if(e.preventDefault(),r.hasChildren&&this._expanded.has(r.id))this._setActiveRow(r),this._setExpanded(r,!1);else if(r.parentId){const a=i.find(l=>l.id===r.parentId);a&&this._moveActive(a)}break;case"Enter":case" ":e.preventDefault(),this._activateAndSelect(r);break;case"F2":if(!r.editable)break;e.preventDefault(),this._setActiveRow(r),this._edit(r),this.requestUpdate();break;case"Insert":if(!this.allowGraft)break;e.preventDefault(),this._openGraftForRow(r);break;default:e.key.length===1&&!e.ctrlKey&&!e.metaKey&&!e.altKey&&(e.preventDefault(),this._typeahead(e.key,i,o));break}}}_moveActive(e){e&&(this._closeRowActionMenus(),this._setActiveRow(e),this.requestUpdate())}_focusRow(e){this._closeRowActionMenus(),this._activeId=e.id,this._rowEl(e.id)?.focus({preventScroll:!0}),this.requestUpdate()}_closeRowActionMenus(){this.shadowRoot?.querySelectorAll("esp-action-menu.node-action-menu").forEach(e=>e.closeMenu?.({restoreFocus:!1}))}async _focusRowActions(e){const i=this._rowEl(e.id)?.querySelector(".node-actions");if(!i)return;if(e.actions.length===1){i.querySelector("esp-button")?.focus({preventScroll:!0});return}const s=i.querySelector("esp-action-menu");if(!s)return;s.openMenu(),await s.updateComplete;const o=s;if(typeof o.focusFirstItem=="function"){o.focusFirstItem();return}s.querySelector("esp-action-menu-item:not([disabled])")?.focus()}_focusRowActionTrigger(e){const i=this._rowEl(e.id)?.querySelector(".node-actions esp-button");return i?(i.focus({preventScroll:!0}),!0):!1}_typeahead(e,t,i){this._typeTimer&&clearTimeout(this._typeTimer),this._typeBuffer+=e.toLowerCase(),this._typeTimer=setTimeout(()=>{this._typeBuffer="",this._typeTimer=null},V);const s=t.length;for(let o=1;o<=s;o++){const r=t[(i+o)%s];if(r&&r.label.toLowerCase().startsWith(this._typeBuffer)){this._moveActive(r);return}}}_onSlotChange(){const e=Array.from(this.children).filter(t=>t instanceof P);this._slottedNodes=e.map(t=>this._parseItem(t)),this._generation++,this._rebuildModel(),this._reconcileState(),this.requestUpdate()}_parseItem(e){const t=this._idForSlottedItem(e),i=e.getAttribute("segment")??e.segment??"",s=e.getAttribute("label")??e.label,o=e.getAttribute("icon")??e.icon,r=e.getAttribute("selectable"),a=r===null?e.selectable:r!=="false",l=e.hasAttribute("editable")||e.editable,g=e.hasAttribute("deletable")||e.deletable,v=e.hasAttribute("movable-up")||e.movableUp,b=e.hasAttribute("movable-down")||e.movableDown,w=e.hasAttribute("cuttable")||e.cuttable,y=e.hasAttribute("paste-child-target")||e.pasteChildTarget,I=e.hasAttribute("has-children")||e.hasChildren,k=Array.from(e.children).filter(E=>E instanceof P),f={id:t,segment:i,data:e.data,selectable:a,hasChildren:I};s&&(f.label=s),o&&(f.icon=o),l&&(f.editable=!0),g&&(f.deletable=!0),v&&(f.movableUp=!0),b&&(f.movableDown=!0),w&&(f.cuttable=!0),y&&(f.pasteChildTarget=!0);const A=k.map(E=>this._parseItem(E));return A.length&&(f.children=A),f}_idForSlottedItem(e){const t=this._slottedIds.get(e);if(t)return t;if(e.id&&!this._isGeneratedId(e.id))return this._slottedIds.set(e,e.id),e.id;e.id&&console.warn(`esp-tree: reserved slotted item id "${e.id}" ignored.`);const i=`__slotted:${++this._nextSlottedId}`;return this._slottedIds.set(e,i),i}_onGraftAddClick(e,t){e.stopPropagation(),!this.disabled&&this._openGraftForRow(t)}_openGraftForRow(e){if(this.disabled)return;const t=e??this._model[0]??null,i=this._rowPath(t);this._requestGraft(t,i)&&(t&&(this._setActiveRow(t),this._expanded.add(t.id)),this._openGraft(t?.id??"__root"))}_requestGraft(e,t){return this.dispatchEvent(new CustomEvent(_.TREE_GRAFT_REQUEST,{detail:{parentPath:t,parentNode:e?this._toPublic(e):null},bubbles:!0,composed:!0,cancelable:!0}))}_openGraft(e){this._graftParentId=e,this._graftValue="",this._graftErrorInternal=null,this.graftError=null,this._pendingGraftFocus=!0,this.requestUpdate(),this.updateComplete.then(()=>{if(this._graftParentId!==e)return;const t=this._graftDialogRef.value;t&&!t.hasAttribute("is-open")&&t.toggleOpen()})}_cancelGraft(){this._closeGraftDialog(),this._resetGraftState()}_closeGraftDialog(){const e=this._graftDialogRef.value;e?.hasAttribute("is-open")&&e.toggleOpen()}_resetGraftState(){this._graftParentId=null,this._graftValue="",this._graftErrorInternal=null,this.graftError=null}_onGraftDialogClosed(){this._resetGraftState()}_onGraftInput(e){const t=e.detail??e.target.value;this._graftValue=t;const i=this._graftParentPath(),s=this._normalizeGraft(t,i),{valid:o,reason:r}=this._validateSegment(i,s);this._graftErrorInternal=null,this._emit(_.TREE_GRAFT_INPUT,{parentPath:i,raw:t,segment:s,path:this._joinPath(i,s),valid:o,reason:r})}_onGraftKeydown(e){if(e.stopPropagation(),e.key==="Enter")e.preventDefault(),this._commitGraft();else if(e.key==="Escape"){e.preventDefault();const t=this._graftParentId;this._cancelGraft(),t&&this._moveActive(this._findRowById(t)??void 0)}}_commitGraft(){if(this.disabled)return;const e=this._graftParentRow(),t=e?.id??"__root",i=this._rowPath(e),s=this._normalizeGraft(this._graftValue,i),{valid:o,reason:r}=this._validateSegment(i,s);if(!o){this._graftErrorInternal=r==="duplicate"?B:q;return}if(this.graftError)return;const a=this._joinPath(i,s),l={id:`__graft:${++this._nextGraftId}`,segment:s,label:s,selectable:!0},g=this._grafted.get(t)??[];g.push(l),this._grafted.set(t,g),this._rebuildModel(),this._reconcileState(),e&&this._expanded.add(e.id),this._closeGraftDialog(),this._resetGraftState(),this.value=a,this._selectedId=l.id,this._setActiveId(l.id);const v=this._findRowById(l.id),b=v?this._toPublic(v):l;this._emit(_.TREE_GRAFT,{parentPath:i,segment:s,path:a,node:b}),this._emit(_.TREE_SELECT,{path:a,node:b}),this.requestUpdate()}_validateSegment(e,t){return t?this._siblingSegments(e).has(t.toLowerCase())?{valid:!1,reason:"duplicate"}:{valid:!0,reason:""}:{valid:!1,reason:"empty"}}_siblingSegments(e){const t=e?this._findRow(e)?.children??[]:this._model;return new Set(t.map(i=>i.segment.toLowerCase()))}_normalizeGraft(e,t){return this.normalizeGraftSegment({raw:e,parentPath:t})}_graftParentPath(){return this._rowPath(this._graftParentRow())}_graftParentRow(){return this._graftParentId?this._findRowById(this._graftParentId)??this._model[0]??null:this._model[0]??null}_rowPath(e){return e?.path??(this.rootPath||"/")}render(){const e=this._visibleRows(),t=this._currentActive(e);return p`
|
|
49
49
|
<div
|
|
50
50
|
class="tree"
|
|
51
51
|
role="tree"
|
|
@@ -57,7 +57,7 @@ var d=function(c,e,t,i){var s=arguments.length,o=s<3?e:i===null?i=Object.getOwnP
|
|
|
57
57
|
</div>
|
|
58
58
|
${this.allowGraft?this._renderGraftDialog():u}
|
|
59
59
|
<slot ${S(this._itemsSlot)} @slotchange=${this._onSlotChange} hidden></slot>
|
|
60
|
-
`}_renderGeneratedIcon(e,t){const i=M(e,this);return i?
|
|
60
|
+
`}_renderGeneratedIcon(e,t){const i=M(e,this);return i?G(i,{class:t}):u}_renderToggleIcon(e){return e?C(e):U}_renderBranchGuide(){return p`
|
|
61
61
|
<svg
|
|
62
62
|
class="branch-guide"
|
|
63
63
|
viewBox="0 0 24 1"
|
|
@@ -67,13 +67,13 @@ var d=function(c,e,t,i){var s=arguments.length,o=s<3?e:i===null?i=Object.getOwnP
|
|
|
67
67
|
>
|
|
68
68
|
<path></path>
|
|
69
69
|
</svg>
|
|
70
|
-
`}_syncGuidePaths(){const e=this.shadowRoot;if(e)for(const t of e.querySelectorAll(".children"))this._syncGuidePath(t)}_syncGuidePath(e){const t=Array.from(e.children).find(g=>g.classList.contains("branch-guide")),i=t?.querySelector("path");if(!t||!i)return;const s=e.getBoundingClientRect(),o=Number.parseFloat(getComputedStyle(e).paddingInlineStart)||24,r=[];let a=o;for(const g of Array.from(e.children)){if(g.classList.contains("branch-guide"))continue;const
|
|
71
|
-
class=${
|
|
70
|
+
`}_syncGuidePaths(){const e=this.shadowRoot;if(e)for(const t of e.querySelectorAll(".children"))this._syncGuidePath(t)}_syncGuidePath(e){const t=Array.from(e.children).find(g=>g.classList.contains("branch-guide")),i=t?.querySelector("path");if(!t||!i)return;const s=e.getBoundingClientRect(),o=Number.parseFloat(getComputedStyle(e).paddingInlineStart)||24,r=[];let a=o;for(const g of Array.from(e.children)){if(g.classList.contains("branch-guide"))continue;const v=this._guideTargetFor(g);if(!v)continue;const b=v.getBoundingClientRect(),w=b.left-s.left;Number.isFinite(w)&&w>0&&(a=w);const y=b.top-s.top+b.height/2;Number.isFinite(y)&&r.push(y)}const l=Math.max(s.height,r[r.length-1]??0,1);if(t.setAttribute("viewBox",`0 0 ${this._round(a)} ${this._round(l)}`),!r.length){i.removeAttribute("d");return}i.setAttribute("d",this._guidePath(r,a))}_guideTargetFor(e){return e.classList.contains("treeitem")?Array.from(e.children).find(i=>i.classList.contains("row-shell"))?.querySelector(".row")??null:e.classList.contains("graft-insert")?e.querySelector(".graft-add"):null}_guidePath(e,t){const i=this._round(Math.max(t,1)),s=this._round(e[e.length-1]??0),o=this._round(Math.max(0,Math.min(6,i/2,s))),r=["M 0 0"];for(const a of e.slice(0,-1)){const l=this._round(a);r.push(`V ${l}`,`H ${i}`,"H 0")}return o>0&&s>o?r.push(`V ${this._round(s-o)}`,`Q 0 ${s} ${o} ${s}`,`H ${i}`):r.push(`V ${s}`,`H ${i}`),r.join(" ")}_round(e){return Math.round(e*100)/100}_renderToggleAction(e,t){if(!e.hasChildren)return p`<span
|
|
71
|
+
class=${m({"icon-action":!0,"toggle-action":!0,placeholder:!0})}
|
|
72
72
|
aria-hidden="true"
|
|
73
73
|
></span>`;const i=t?`Collapse ${e.label}`:`Expand ${e.label}`,s=t&&this.collapseIcon?this.collapseIcon:this.expandIcon;return p`
|
|
74
74
|
<button
|
|
75
75
|
type="button"
|
|
76
|
-
class=${
|
|
76
|
+
class=${m({"icon-action":!0,"toggle-action":!0,open:t&&!this.collapseIcon})}
|
|
77
77
|
aria-label=${i}
|
|
78
78
|
title=${i}
|
|
79
79
|
aria-expanded=${String(t)}
|
|
@@ -85,24 +85,24 @@ var d=function(c,e,t,i){var s=arguments.length,o=s<3?e:i===null?i=Object.getOwnP
|
|
|
85
85
|
</button>
|
|
86
86
|
`}_renderNodeTools(e){const t=M(e.icon,this),i=t.length>0;return i?p`
|
|
87
87
|
<span
|
|
88
|
-
class=${
|
|
88
|
+
class=${m({"node-tools":!0,"has-icon":i})}
|
|
89
89
|
>
|
|
90
90
|
<span class="node-icon" aria-hidden="true">
|
|
91
|
-
${
|
|
91
|
+
${G(t,{"aria-hidden":null})}
|
|
92
92
|
</span>
|
|
93
93
|
</span>
|
|
94
94
|
`:u}_renderNodeActions(e){const t=e.actions;return t.length===0?u:p`
|
|
95
95
|
<span
|
|
96
96
|
class="node-actions"
|
|
97
97
|
@click=${this._stopRowActionEvent}
|
|
98
|
-
@clicked=${this._stopRowActionEvent}
|
|
98
|
+
@esp-clicked=${this._stopRowActionEvent}
|
|
99
99
|
@keydown=${i=>this._onRowActionsKeydown(i,e)}
|
|
100
100
|
>
|
|
101
101
|
${t.length===1?this._renderSingleNodeAction(e,t[0]):this._renderNodeActionMenu(e,t)}
|
|
102
102
|
</span>
|
|
103
103
|
`}_renderSingleNodeAction(e,t){return p`
|
|
104
104
|
<esp-button
|
|
105
|
-
class=${
|
|
105
|
+
class=${m({"node-action-button":!0,[`${t.kind}-action`]:!0})}
|
|
106
106
|
icon-only
|
|
107
107
|
collapsed
|
|
108
108
|
label=${t.accessibleLabel}
|
|
@@ -111,9 +111,9 @@ var d=function(c,e,t,i){var s=arguments.length,o=s<3?e:i===null?i=Object.getOwnP
|
|
|
111
111
|
tabindex="-1"
|
|
112
112
|
incognito
|
|
113
113
|
?disabled=${this.disabled}
|
|
114
|
-
@clicked=${i=>this._onActionEvent(i,e,t.kind)}
|
|
114
|
+
@esp-clicked=${i=>this._onActionEvent(i,e,t.kind)}
|
|
115
115
|
>
|
|
116
|
-
${
|
|
116
|
+
${R(t.kind)}
|
|
117
117
|
</esp-button>
|
|
118
118
|
`}_renderNodeActionMenu(e,t){const i=`Actions for ${e.label}`;return p`
|
|
119
119
|
<esp-action-menu
|
|
@@ -121,7 +121,7 @@ var d=function(c,e,t,i){var s=arguments.length,o=s<3?e:i===null?i=Object.getOwnP
|
|
|
121
121
|
placement="bottom-end"
|
|
122
122
|
icon-position="right"
|
|
123
123
|
?disabled=${this.disabled}
|
|
124
|
-
@select=${s=>this._onActionMenuSelect(s,e)}
|
|
124
|
+
@esp-action-menu-select=${s=>this._onActionMenuSelect(s,e)}
|
|
125
125
|
>
|
|
126
126
|
<esp-button
|
|
127
127
|
slot="trigger"
|
|
@@ -135,11 +135,11 @@ var d=function(c,e,t,i){var s=arguments.length,o=s<3?e:i===null?i=Object.getOwnP
|
|
|
135
135
|
tabindex="-1"
|
|
136
136
|
?disabled=${this.disabled}
|
|
137
137
|
>
|
|
138
|
-
${
|
|
138
|
+
${R("menu")}
|
|
139
139
|
</esp-button>
|
|
140
140
|
${t.map(s=>p`
|
|
141
141
|
<esp-action-menu-item value=${s.kind}>
|
|
142
|
-
${
|
|
142
|
+
${R(s.kind,"icon")} ${s.label}
|
|
143
143
|
</esp-action-menu-item>
|
|
144
144
|
`)}
|
|
145
145
|
</esp-action-menu>
|
|
@@ -157,7 +157,7 @@ var d=function(c,e,t,i){var s=arguments.length,o=s<3?e:i===null?i=Object.getOwnP
|
|
|
157
157
|
tabindex=${this.disabled?-1:o?0:-1}
|
|
158
158
|
>
|
|
159
159
|
<div class="row-shell">
|
|
160
|
-
<div class=${
|
|
160
|
+
<div class=${m(a)} @click=${()=>this._onRowClick(e)}>
|
|
161
161
|
${this._renderToggleAction(e,i)} ${this._renderNodeTools(e)}
|
|
162
162
|
<span class="node-label">${e.label}</span>
|
|
163
163
|
${r?p`<span class="loading" aria-hidden="true"></span>`:u}
|
|
@@ -168,7 +168,7 @@ var d=function(c,e,t,i){var s=arguments.length,o=s<3?e:i===null?i=Object.getOwnP
|
|
|
168
168
|
</div>
|
|
169
169
|
`}_renderChildGroup(e,t){const i=this._expanded.has(e.id),s=i&&e.children.length>0,o=this.allowGraft&&(i||!e.hasChildren);return!s&&!o?u:p`
|
|
170
170
|
<div
|
|
171
|
-
class=${
|
|
171
|
+
class=${m({children:!0,"add-only":!s})}
|
|
172
172
|
role=${s?"group":"presentation"}
|
|
173
173
|
>
|
|
174
174
|
${this._renderBranchGuide()}
|
|
@@ -177,12 +177,12 @@ var d=function(c,e,t,i){var s=arguments.length,o=s<3?e:i===null?i=Object.getOwnP
|
|
|
177
177
|
</div>
|
|
178
178
|
`}_renderGraftAdd(e,t,i){return p`
|
|
179
179
|
<div
|
|
180
|
-
class=${
|
|
180
|
+
class=${m({"graft-insert":!0,root:i})}
|
|
181
181
|
role="presentation"
|
|
182
182
|
>
|
|
183
183
|
<button
|
|
184
184
|
type="button"
|
|
185
|
-
class=${
|
|
185
|
+
class=${m({"icon-action":!0,"graft-add":!0,"graft-root":i})}
|
|
186
186
|
aria-label=${t}
|
|
187
187
|
title=${t}
|
|
188
188
|
?disabled=${this.disabled}
|
|
@@ -218,7 +218,7 @@ var d=function(c,e,t,i){var s=arguments.length,o=s<3?e:i===null?i=Object.getOwnP
|
|
|
218
218
|
class="graft-input"
|
|
219
219
|
.value=${this._graftValue}
|
|
220
220
|
placeholder="new-branch"
|
|
221
|
-
@value-changed=${this._onGraftInput}
|
|
221
|
+
@esp-value-changed=${this._onGraftInput}
|
|
222
222
|
@keydown=${this._onGraftKeydown}
|
|
223
223
|
></esp-input>
|
|
224
224
|
</esp-form-item>
|
|
@@ -232,7 +232,7 @@ var d=function(c,e,t,i){var s=arguments.length,o=s<3?e:i===null?i=Object.getOwnP
|
|
|
232
232
|
label="Cancel"
|
|
233
233
|
icon="circle-x"
|
|
234
234
|
?disabled=${this.disabled}
|
|
235
|
-
@clicked=${this._cancelGraft}
|
|
235
|
+
@esp-clicked=${this._cancelGraft}
|
|
236
236
|
></esp-button>
|
|
237
237
|
<esp-button
|
|
238
238
|
collapsed
|
|
@@ -240,13 +240,13 @@ var d=function(c,e,t,i){var s=arguments.length,o=s<3?e:i===null?i=Object.getOwnP
|
|
|
240
240
|
label="Add branch"
|
|
241
241
|
icon="plus"
|
|
242
242
|
?disabled=${this.disabled}
|
|
243
|
-
@clicked=${this._commitGraft}
|
|
243
|
+
@esp-clicked=${this._commitGraft}
|
|
244
244
|
></esp-button>
|
|
245
245
|
</div>
|
|
246
246
|
</section>
|
|
247
247
|
</esp-box>`:u}
|
|
248
248
|
</esp-dialog>
|
|
249
|
-
`}};n.formAssociated=!0,n.styles=[...z.styles,
|
|
249
|
+
`}};n.formAssociated=!0,n.styles=[...z.styles,D`
|
|
250
250
|
:host {
|
|
251
251
|
--_esp-tree-indent-step: var(--esp-tree-indent-step, 1.25rem);
|
|
252
252
|
--_esp-tree-action-size: var(--esp-tree-action-size, 1.75rem);
|
|
@@ -620,4 +620,4 @@ var d=function(c,e,t,i){var s=arguments.length,o=s<3?e:i===null?i=Object.getOwnP
|
|
|
620
620
|
gap: var(--esp-size-small);
|
|
621
621
|
justify-content: flex-end;
|
|
622
622
|
}
|
|
623
|
-
`],d([h({type:Array})],n.prototype,"nodes",void 0),d([h({type:String})],n.prototype,"value",void 0),d([h({type:String,reflect:!0})],n.prototype,"name",void 0),d([h({type:Boolean,reflect:!0})],n.prototype,"required",void 0),d([h({attribute:"required-message"})],n.prototype,"requiredMessage",void 0),d([h({type:Boolean,reflect:!0})],n.prototype,"disabled",void 0),d([h({type:Boolean,attribute:"allow-graft"})],n.prototype,"allowGraft",void 0),d([h({type:String,attribute:"root-label"})],n.prototype,"rootLabel",void 0),d([h({type:String,attribute:"root-path"})],n.prototype,"rootPath",void 0),d([h({attribute:"root-selectable",converter:{fromAttribute:c=>c!=="false",toAttribute:c=>String(c)}})],n.prototype,"rootSelectable",void 0),d([h({type:String})],n.prototype,"label",void 0),d([h({type:String,reflect:!0,attribute:"graft-error"})],n.prototype,"graftError",void 0),d([h({attribute:!1})],n.prototype,"loadChildren",void 0),d([h({attribute:!1})],n.prototype,"buildPath",void 0),d([h({attribute:!1})],n.prototype,"normalizeGraftSegment",void 0),d([h({type:Boolean,attribute:"keep-expanded"})],n.prototype,"keepExpanded",void 0),d([h({attribute:!1})],n.prototype,"expandIcon",void 0),d([h({attribute:!1})],n.prototype,"collapseIcon",void 0),d([
|
|
623
|
+
`],d([h({type:Array})],n.prototype,"nodes",void 0),d([h({type:String})],n.prototype,"value",void 0),d([h({type:String,reflect:!0})],n.prototype,"name",void 0),d([h({type:Boolean,reflect:!0})],n.prototype,"required",void 0),d([h({attribute:"required-message"})],n.prototype,"requiredMessage",void 0),d([h({type:Boolean,reflect:!0})],n.prototype,"disabled",void 0),d([h({type:Boolean,attribute:"allow-graft"})],n.prototype,"allowGraft",void 0),d([h({type:String,attribute:"root-label"})],n.prototype,"rootLabel",void 0),d([h({type:String,attribute:"root-path"})],n.prototype,"rootPath",void 0),d([h({attribute:"root-selectable",converter:{fromAttribute:c=>c!=="false",toAttribute:c=>String(c)}})],n.prototype,"rootSelectable",void 0),d([h({type:String})],n.prototype,"label",void 0),d([h({type:String,reflect:!0,attribute:"graft-error"})],n.prototype,"graftError",void 0),d([h({attribute:!1})],n.prototype,"loadChildren",void 0),d([h({attribute:!1})],n.prototype,"buildPath",void 0),d([h({attribute:!1})],n.prototype,"normalizeGraftSegment",void 0),d([h({type:Boolean,attribute:"keep-expanded"})],n.prototype,"keepExpanded",void 0),d([h({attribute:!1})],n.prototype,"expandIcon",void 0),d([h({attribute:!1})],n.prototype,"collapseIcon",void 0),d([x()],n.prototype,"_activeId",void 0),d([x()],n.prototype,"_graftParentId",void 0),d([x()],n.prototype,"_graftValue",void 0),d([x()],n.prototype,"_graftErrorInternal",void 0),n=d([L("esp-tree")],n);export{n as EspalierTree,j as buildWebTreePath,H as normalizeSegment};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@taprootio/espalier",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"packageManager": "bun@1.3.12",
|
|
5
5
|
"description": "Espalier — a themeable, accessible, framework-agnostic, enterprise-grade design system built on web standards and love.",
|
|
6
6
|
"customElements": "custom-elements.json",
|