@crowdstrike/glide-core 0.17.1 → 0.19.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/LICENSE +1 -1
- package/README.md +1 -1
- package/dist/accordion.d.ts +1 -1
- package/dist/accordion.js +1 -1
- package/dist/button-group.button.d.ts +2 -2
- package/dist/button-group.button.js +1 -1
- package/dist/button-group.d.ts +1 -1
- package/dist/button-group.js +1 -1
- package/dist/button.d.ts +1 -0
- package/dist/button.js +1 -1
- package/dist/checkbox-group.d.ts +6 -2
- package/dist/checkbox-group.js +13 -12
- package/dist/checkbox.d.ts +7 -4
- package/dist/checkbox.js +9 -8
- package/dist/drawer.d.ts +1 -0
- package/dist/drawer.js +1 -1
- package/dist/drawer.styles.js +2 -2
- package/dist/dropdown.d.ts +5 -3
- package/dist/dropdown.js +37 -36
- package/dist/dropdown.option.d.ts +3 -2
- package/dist/dropdown.option.js +1 -1
- package/dist/dropdown.styles.js +3 -15
- package/dist/form-controls-layout.d.ts +2 -5
- package/dist/form-controls-layout.js +1 -1
- package/dist/icon-button.d.ts +1 -1
- package/dist/icon-button.js +1 -1
- package/dist/inline-alert.d.ts +1 -0
- package/dist/inline-alert.js +1 -1
- package/dist/input.d.ts +5 -2
- package/dist/input.js +5 -5
- package/dist/label.d.ts +1 -2
- package/dist/label.js +1 -1
- package/dist/library/assert-slot.d.ts +19 -0
- package/dist/library/assert-slot.js +1 -0
- package/dist/library/assert-slot.test.d.ts +1 -0
- package/dist/library/assert-slot.test.js +296 -0
- package/dist/library/expect-unhandled-rejection.js +1 -0
- package/dist/library/expect-window-error.d.ts +1 -0
- package/dist/library/expect-window-error.js +1 -0
- package/dist/library/form-control.d.ts +22 -0
- package/dist/library/form-control.js +1 -0
- package/dist/library/localize.test.js +1 -3
- package/dist/library/shadow-root-mode.d.ts +2 -0
- package/dist/library/shadow-root-mode.js +1 -0
- package/dist/menu.button.d.ts +2 -1
- package/dist/menu.button.js +1 -1
- package/dist/menu.d.ts +1 -0
- package/dist/menu.js +1 -1
- package/dist/menu.link.d.ts +2 -1
- package/dist/menu.link.js +1 -1
- package/dist/menu.options.d.ts +1 -1
- package/dist/menu.options.js +1 -1
- package/dist/modal.d.ts +2 -2
- package/dist/modal.icon-button.d.ts +1 -2
- package/dist/modal.icon-button.js +1 -1
- package/dist/modal.js +1 -1
- package/dist/modal.styles.js +23 -19
- package/dist/popover.d.ts +1 -0
- package/dist/popover.js +1 -1
- package/dist/radio-group.d.ts +6 -2
- package/dist/radio-group.js +16 -17
- package/dist/radio-group.radio.d.ts +3 -2
- package/dist/radio-group.radio.js +1 -1
- package/dist/radio-group.radio.styles.js +4 -1
- package/dist/radio-group.styles.js +0 -2
- package/dist/split-button.d.ts +1 -1
- package/dist/split-button.js +1 -1
- package/dist/split-button.primary-button.d.ts +1 -0
- package/dist/split-button.primary-button.js +1 -1
- package/dist/split-button.primary-link.d.ts +1 -0
- package/dist/split-button.primary-link.js +1 -1
- package/dist/split-button.secondary-button.d.ts +1 -0
- package/dist/split-button.secondary-button.js +1 -1
- package/dist/tab.d.ts +1 -0
- package/dist/tab.group.d.ts +4 -4
- package/dist/tab.group.js +1 -1
- package/dist/tab.js +1 -1
- package/dist/tab.panel.d.ts +1 -0
- package/dist/tab.panel.js +1 -1
- package/dist/tag.d.ts +1 -0
- package/dist/tag.js +1 -1
- package/dist/textarea.d.ts +6 -3
- package/dist/textarea.js +9 -9
- package/dist/toasts.d.ts +1 -0
- package/dist/toasts.js +1 -1
- package/dist/toasts.toast.js +1 -1
- package/dist/toggle.d.ts +2 -1
- package/dist/toggle.js +1 -1
- package/dist/tooltip.container.d.ts +20 -0
- package/dist/tooltip.container.js +1 -0
- package/dist/tooltip.container.styles.d.ts +2 -0
- package/dist/tooltip.container.styles.js +51 -0
- package/dist/tooltip.d.ts +8 -2
- package/dist/tooltip.js +1 -1
- package/dist/tooltip.styles.js +0 -50
- package/dist/tree.d.ts +4 -4
- package/dist/tree.item.d.ts +1 -1
- package/dist/tree.item.icon-button.d.ts +1 -2
- package/dist/tree.item.icon-button.js +1 -1
- package/dist/tree.item.js +1 -1
- package/dist/tree.item.menu.d.ts +3 -5
- package/dist/tree.item.menu.js +1 -1
- package/dist/tree.js +1 -1
- package/package.json +17 -16
- package/dist/library/expect-argument-error.js +0 -1
- package/dist/library/ow.d.ts +0 -16
- package/dist/library/ow.js +0 -1
- package/dist/library/ow.test.d.ts +0 -5
- package/dist/library/ow.test.js +0 -59
- package/dist/modal.tertiary-icon.d.ts +0 -18
- package/dist/modal.tertiary-icon.js +0 -1
- /package/dist/library/{expect-argument-error.d.ts → expect-unhandled-rejection.d.ts} +0 -0
package/dist/input.js
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
var __decorate=this&&this.__decorate||function(t,e,i,s){var a,o=arguments.length,r=o<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,i,s);else for(var l=t.length-1;l>=0;l--)(a=t[l])&&(r=(o<3?a(r):o>3?a(e,i,r):a(e,i))||r);return o>3&&r&&Object.defineProperty(e,i,r),r};import"./icon-button.js";import"./label.js";import{LitElement,
|
1
|
+
var __decorate=this&&this.__decorate||function(t,e,i,s){var a,o=arguments.length,r=o<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,i,s);else for(var l=t.length-1;l>=0;l--)(a=t[l])&&(r=(o<3?a(r):o>3?a(e,i,r):a(e,i))||r);return o>3&&r&&Object.defineProperty(e,i,r),r};import"./icon-button.js";import"./label.js";import{html,LitElement,nothing}from"lit";import{classMap}from"lit/directives/class-map.js";import{createRef,ref}from"lit/directives/ref.js";import{customElement,property,state}from"lit/decorators.js";import{ifDefined}from"lit/directives/if-defined.js";import{styleMap}from"lit/directives/style-map.js";import{unsafeHTML}from"lit/directives/unsafe-html.js";import{when}from"lit/directives/when.js";import packageJson from"../package.json"with{type:"json"};import{LocalizeController}from"./library/localize.js";import magnifyingGlassIcon from"./icons/magnifying-glass.js";import styles from"./input.styles.js";import xIcon from"./icons/x.js";import shadowRootMode from"./library/shadow-root-mode.js";export const SUPPORTED_TYPES=["date","email","number","password","search","tel","text","url"];let GlideCoreInput=class GlideCoreInput extends LitElement{static{this.formAssociated=!0}static{this.shadowRootOptions={...LitElement.shadowRootOptions,mode:shadowRootMode,delegatesFocus:!0}}static{this.styles=styles}get form(){return this.#t.form}get validity(){return this.pattern?(this.#t.setValidity({customError:Boolean(this.validityMessage),patternMismatch:!new RegExp(this.pattern).test(this.value),valueMissing:Boolean(this.required&&!this.value)}," ",this.#e.value),this.#t.validity):!this.pattern&&this.#t.validity.patternMismatch?(this.#t.setValidity({}),this.#t.validity):!this.required||this.value||this.disabled?this.required&&this.#t.validity.valueMissing&&this.value?(this.#t.setValidity({}),this.#t.validity):(this.required||!this.#t.validity.valueMissing||this.value||this.#t.setValidity({}),this.#t.validity):(this.#t.setValidity({customError:Boolean(this.validityMessage),valueMissing:!0}," ",this.#e.value),this.#t.validity)}get willValidate(){return this.#t.willValidate}blur(){this.#e.value?.blur()}checkValidity(){this.isCheckingValidity=!0;const t=this.#t.checkValidity();return this.isCheckingValidity=!1,t}disconnectedCallback(){super.disconnectedCallback(),this.form?.removeEventListener("formdata",this.#i)}formAssociatedCallback(){this.form?.addEventListener("formdata",this.#i)}formResetCallback(){this.value=this.getAttribute("value")??""}render(){return html`
|
2
2
|
<glide-core-private-label
|
3
3
|
class=${classMap({left:"left"===this.privateSplit,middle:"middle"===this.privateSplit})}
|
4
4
|
orientation=${this.orientation}
|
5
5
|
split=${ifDefined(this.privateSplit??void 0)}
|
6
|
+
tooltip=${ifDefined(this.tooltip)}
|
6
7
|
?disabled=${this.disabled}
|
7
8
|
?error=${this.#s||this.#a}
|
8
9
|
?hide=${this.hideLabel}
|
9
10
|
?required=${this.required}
|
10
11
|
>
|
11
|
-
<slot name="tooltip" slot="tooltip"></slot>
|
12
12
|
<label for="input"> ${this.label} </label>
|
13
13
|
|
14
14
|
<div
|
@@ -39,10 +39,10 @@ var __decorate=this&&this.__decorate||function(t,e,i,s){var a,o=arguments.length
|
|
39
39
|
${ref(this.#e)}
|
40
40
|
/>
|
41
41
|
|
42
|
-
${this.#
|
42
|
+
${this.#p?html`
|
43
43
|
<glide-core-icon-button
|
44
44
|
variant="tertiary"
|
45
|
-
class=${classMap({"clear-icon-button":!0,"clear-icon-button--visible":this.#
|
45
|
+
class=${classMap({"clear-icon-button":!0,"clear-icon-button--visible":this.#h})}
|
46
46
|
data-test="clear-button"
|
47
47
|
label=${this.#c.term("clearEntry",this.label)}
|
48
48
|
@click=${this.#u}
|
@@ -99,7 +99,7 @@ var __decorate=this&&this.__decorate||function(t,e,i,s){var a,o=arguments.length
|
|
99
99
|
`:nothing}
|
100
100
|
</div>
|
101
101
|
</glide-core-private-label>
|
102
|
-
`}reportValidity(){this.isReportValidityOrSubmit=!0;const t=this.#t.reportValidity();return this.requestUpdate(),t}setCustomValidity(t){this.validityMessage=t,""===t?this.#t.setValidity({customError:!1},"",this.#e.value):this.#t.setValidity({customError:!0,patternMismatch:this.#t.validity.patternMismatch,valueMissing:this.#t.validity.valueMissing}," ",this.#e.value)}setValidity(t,e){this.validityMessage=e,this.#t.setValidity(t," ",this.#e.value)}constructor(){super(),this.type="text",this.name="",this.value="",this.hideLabel=!1,this.orientation="horizontal",this.clearable=!1,this.spellcheck=!1,this.autocapitalize="on",this.autocomplete="on",this.passwordToggle=!1,this.required=!1,this.readonly=!1,this.disabled=!1,this.hasFocus=!1,this.isBlurring=!1,this.isCheckingValidity=!1,this.isReportValidityOrSubmit=!1,this.passwordVisible=!1,this.#e=createRef(),this.#c=new LocalizeController(this),this.#i=({formData:t})=>{this.name&&this.value&&!this.disabled&&t.append(this.name,this.value)},this.#t=this.attachInternals(),this.addEventListener("invalid",(t=>{if(t?.preventDefault(),this.isCheckingValidity||this.isBlurring)return;this.isReportValidityOrSubmit=!0;this.form?.querySelector(":invalid")===this&&this.focus()}))}#e;#t;#c;get#
|
102
|
+
`}reportValidity(){this.isReportValidityOrSubmit=!0;const t=this.#t.reportValidity();return this.requestUpdate(),t}resetValidityFeedback(){this.isReportValidityOrSubmit=!1}setCustomValidity(t){this.validityMessage=t,""===t?this.#t.setValidity({customError:!1},"",this.#e.value):this.#t.setValidity({customError:!0,patternMismatch:this.#t.validity.patternMismatch,valueMissing:this.#t.validity.valueMissing}," ",this.#e.value)}setValidity(t,e){this.validityMessage=e,this.#t.setValidity(t," ",this.#e.value)}constructor(){super(),this.type="text",this.name="",this.value="",this.hideLabel=!1,this.orientation="horizontal",this.clearable=!1,this.spellcheck=!1,this.autocapitalize="on",this.autocomplete="on",this.passwordToggle=!1,this.required=!1,this.readonly=!1,this.disabled=!1,this.version=packageJson.version,this.hasFocus=!1,this.isBlurring=!1,this.isCheckingValidity=!1,this.isReportValidityOrSubmit=!1,this.passwordVisible=!1,this.#e=createRef(),this.#c=new LocalizeController(this),this.#i=({formData:t})=>{this.name&&this.value&&!this.disabled&&t.append(this.name,this.value)},this.#t=this.attachInternals(),this.addEventListener("invalid",(t=>{if(t?.preventDefault(),this.isCheckingValidity||this.isBlurring)return;this.isReportValidityOrSubmit=!0;this.form?.querySelector(":invalid")===this&&this.focus()}))}#e;#t;#c;get#p(){return this.clearable&&!this.disabled&&!this.readonly}get#h(){return this.#p&&this.value.length>0}get#m(){return this.value.length}#i;get#a(){return Boolean(!this.disabled&&!this.readonly&&this.maxlength&&this.#m>this.maxlength)}get#s(){return!this.disabled&&!this.validity?.valid&&this.isReportValidityOrSubmit}#u(t){this.value="",this.dispatchEvent(new Event("input",{bubbles:!0,composed:!0})),this.#e.value?.focus(),t.stopPropagation()}#r(){this.isBlurring=!0,this.reportValidity(),this.isBlurring=!1,this.hasFocus=!1}#l(t){this.#e.value?.value&&(this.value=this.#e.value?.value),this.dispatchEvent(new Event(t.type,{bubbles:!0,composed:!0}))}#o(){this.hasFocus=!0}#n(){this.#e.value&&(this.value=this.#e.value.value)}#d(t){"Enter"===t.key&&this.form?.requestSubmit()}#y(){this.passwordVisible=!this.passwordVisible}};__decorate([property()],GlideCoreInput.prototype,"type",void 0),__decorate([property({reflect:!0})],GlideCoreInput.prototype,"name",void 0),__decorate([property()],GlideCoreInput.prototype,"value",void 0),__decorate([property({reflect:!0})],GlideCoreInput.prototype,"label",void 0),__decorate([property({attribute:"hide-label",type:Boolean})],GlideCoreInput.prototype,"hideLabel",void 0),__decorate([property({reflect:!0})],GlideCoreInput.prototype,"orientation",void 0),__decorate([property({reflect:!0})],GlideCoreInput.prototype,"pattern",void 0),__decorate([property({reflect:!0})],GlideCoreInput.prototype,"placeholder",void 0),__decorate([property({type:Boolean})],GlideCoreInput.prototype,"clearable",void 0),__decorate([property({reflect:!0,type:Boolean})],GlideCoreInput.prototype,"spellcheck",void 0),__decorate([property({reflect:!0})],GlideCoreInput.prototype,"autocapitalize",void 0),__decorate([property({reflect:!0})],GlideCoreInput.prototype,"autocomplete",void 0),__decorate([property({attribute:"password-toggle",type:Boolean})],GlideCoreInput.prototype,"passwordToggle",void 0),__decorate([property({reflect:!0,type:Boolean})],GlideCoreInput.prototype,"required",void 0),__decorate([property({type:Boolean})],GlideCoreInput.prototype,"readonly",void 0),__decorate([property({reflect:!0,type:Boolean})],GlideCoreInput.prototype,"disabled",void 0),__decorate([property()],GlideCoreInput.prototype,"privateSplit",void 0),__decorate([property({type:Number,converter:t=>t&&Number.parseInt(t,10),reflect:!0})],GlideCoreInput.prototype,"maxlength",void 0),__decorate([property({reflect:!0})],GlideCoreInput.prototype,"version",void 0),__decorate([property({reflect:!0})],GlideCoreInput.prototype,"tooltip",void 0),__decorate([state()],GlideCoreInput.prototype,"hasFocus",void 0),__decorate([state()],GlideCoreInput.prototype,"isBlurring",void 0),__decorate([state()],GlideCoreInput.prototype,"isCheckingValidity",void 0),__decorate([state()],GlideCoreInput.prototype,"isReportValidityOrSubmit",void 0),__decorate([state()],GlideCoreInput.prototype,"passwordVisible",void 0),__decorate([state()],GlideCoreInput.prototype,"validityMessage",void 0),GlideCoreInput=__decorate([customElement("glide-core-input")],GlideCoreInput);export default GlideCoreInput;const icons={eye:html`<svg
|
103
103
|
aria-hidden="true"
|
104
104
|
style=${styleMap({height:"1rem",width:"1rem"})}
|
105
105
|
fill="none"
|
package/dist/label.d.ts
CHANGED
@@ -12,7 +12,6 @@ declare global {
|
|
12
12
|
* @slot control - The control with which the label is associated.
|
13
13
|
* @slot summary - Additional information or context.
|
14
14
|
* @slot description - Additional information or context.
|
15
|
-
* @slot tooltip - Content for the tooltip.
|
16
15
|
*/
|
17
16
|
export default class GlideCoreLabel extends LitElement {
|
18
17
|
#private;
|
@@ -24,11 +23,11 @@ export default class GlideCoreLabel extends LitElement {
|
|
24
23
|
orientation: 'horizontal' | 'vertical';
|
25
24
|
required: boolean;
|
26
25
|
split?: 'left' | 'middle';
|
26
|
+
tooltip?: string;
|
27
27
|
firstUpdated(): void;
|
28
28
|
render(): import("lit").TemplateResult<1>;
|
29
29
|
private hasDescription;
|
30
30
|
private hasSummarySlot;
|
31
|
-
private hasTooltipSlot;
|
32
31
|
private isLabelTooltip;
|
33
32
|
private label;
|
34
33
|
}
|
package/dist/label.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
var __decorate=this&&this.__decorate||function(e,t,o,l){var i,
|
1
|
+
var __decorate=this&&this.__decorate||function(e,t,o,l){var i,r=arguments.length,s=r<3?t:null===l?l=Object.getOwnPropertyDescriptor(t,o):l;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,o,l);else for(var a=e.length-1;a>=0;a--)(i=e[a])&&(s=(r<3?i(s):r>3?i(t,o,s):i(t,o))||s);return r>3&&s&&Object.defineProperty(t,o,s),s};import"./tooltip.js";import{html,LitElement}from"lit";import{classMap}from"lit/directives/class-map.js";import{createRef,ref}from"lit/directives/ref.js";import{customElement,property,state}from"lit/decorators.js";import{styleMap}from"lit/directives/style-map.js";import{ifDefined}from"lit/directives/if-defined.js";import styles from"./label.styles.js";import{LocalizeController}from"./library/localize.js";import assertSlot from"./library/assert-slot.js";import shadowRootMode from"./library/shadow-root-mode.js";let GlideCoreLabel=class GlideCoreLabel extends LitElement{constructor(){super(...arguments),this.disabled=!1,this.error=!1,this.hide=!1,this.orientation="horizontal",this.required=!1,this.hasDescription=!1,this.hasSummarySlot=!1,this.isLabelTooltip=!1,this.label="",this.#e=createRef(),this.#t=createRef(),this.#o=createRef(),this.#l=new LocalizeController(this),this.#i=createRef()}static{this.shadowRootOptions={...LitElement.shadowRootOptions,mode:shadowRootMode}}static{this.styles=styles}firstUpdated(){const e=new ResizeObserver((()=>{this.hasDescription=Boolean(this.#t.value&&this.#t.value.offsetHeight>0)}));this.#t.value&&e.observe(this.#t.value)}render(){return html`<div class="${classMap({component:!0,horizontal:"horizontal"===this.orientation,vertical:"vertical"===this.orientation,left:"left"===this.split,middle:"middle"===this.split,"hidden-label":this.hide})}"><div class="${classMap({tooltips:!0,hidden:this.hide,left:"left"===this.split,middle:"middle"===this.split})}" part="private-tooltips"><glide-core-tooltip class="${classMap({"optional-tooltip":!0,vertical:"vertical"===this.orientation,visible:!!this.tooltip})}" label="${ifDefined(this.tooltip)}" placement="${"vertical"===this.orientation?"right":"bottom"}"><button aria-label="${this.#l.term("tooltip")}" class="optional-tooltip-target" slot="target" type="button">${icons.information}</button></glide-core-tooltip><glide-core-tooltip class="label-tooltip" label="${ifDefined(this.tooltip)}" placement="right" ?disabled="${!this.isLabelTooltip}" screenreader-hidden><div class="${classMap({label:!0,disabled:this.disabled})}" data-test="label" slot="target" ${ref(this.#o)}><slot @slotchange="${this.#r}" ${assertSlot()} ${ref(this.#e)}></slot>${this.required?html`<span aria-hidden="true" class="required-symbol">*</span>`:""}</div></glide-core-tooltip></div><div class="control-and-summary" part="private-control-and-summary"><slot class="${classMap({control:!0,error:this.error,disabled:this.disabled,vertical:"vertical"===this.orientation,summaryless:!this.hasSummarySlot,"hidden-label":this.hide})}" name="control" ${assertSlot()}></slot><slot class="${classMap({summary:!0,error:this.error})}" name="summary" @slotchange="${this.#s}" ${ref(this.#i)}></slot></div><slot class="${classMap({description:!0,content:this.hasDescription,error:this.error,tooltip:!!this.tooltip})}" id="description" name="description" ${ref(this.#t)}></slot></div>`}#e;#t;#o;#l;#i;#r(){const e=this.#e.value?.assignedElements().at(0),t=this.#o.value;e?.textContent&&(this.label=e.textContent);const o=new ResizeObserver((()=>{e&&t&&(this.isLabelTooltip=e.getBoundingClientRect().width>t.getBoundingClientRect().width)}));t&&o.observe(t)}#s(){const e=this.#i.value?.assignedNodes({flatten:!0});this.hasSummarySlot=Boolean(e&&e.length>0)}};__decorate([property({reflect:!0,type:Boolean})],GlideCoreLabel.prototype,"disabled",void 0),__decorate([property({reflect:!0,type:Boolean})],GlideCoreLabel.prototype,"error",void 0),__decorate([property({reflect:!0,type:Boolean})],GlideCoreLabel.prototype,"hide",void 0),__decorate([property({reflect:!0})],GlideCoreLabel.prototype,"orientation",void 0),__decorate([property({reflect:!0,type:Boolean})],GlideCoreLabel.prototype,"required",void 0),__decorate([property()],GlideCoreLabel.prototype,"split",void 0),__decorate([property()],GlideCoreLabel.prototype,"tooltip",void 0),__decorate([state()],GlideCoreLabel.prototype,"hasDescription",void 0),__decorate([state()],GlideCoreLabel.prototype,"hasSummarySlot",void 0),__decorate([state()],GlideCoreLabel.prototype,"isLabelTooltip",void 0),__decorate([state()],GlideCoreLabel.prototype,"label",void 0),GlideCoreLabel=__decorate([customElement("glide-core-private-label")],GlideCoreLabel);export default GlideCoreLabel;const icons={information:html`<svg style="${styleMap({height:"1rem",width:"1rem"})}" viewBox="0 0 24 24" fill="none"><circle cx="12" cy="12" r="10" stroke="currentColor" stroke-width="2"/><path d="M12 16L12 12" stroke="currentColor" stroke-width="2" stroke-linecap="round"/><circle cx="12" cy="8" r="1" fill="currentColor"/></svg>`};
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { type ElementPart } from 'lit';
|
2
|
+
import { Directive, type PartInfo } from 'lit/directive.js';
|
3
|
+
declare class AssertSlot extends Directive {
|
4
|
+
#private;
|
5
|
+
render(slotted?: (typeof Element | typeof Text)[] | null, isOptional?: boolean): symbol;
|
6
|
+
update(part: ElementPart, [slotted, isOptional]: [
|
7
|
+
(typeof Element | typeof Text)[] | undefined | null,
|
8
|
+
boolean | undefined
|
9
|
+
]): symbol;
|
10
|
+
constructor(partInfo: PartInfo);
|
11
|
+
}
|
12
|
+
declare const assertSlot: (slotted?: ({
|
13
|
+
new (): Element;
|
14
|
+
prototype: Element;
|
15
|
+
} | {
|
16
|
+
new (data?: string): Text;
|
17
|
+
prototype: Text;
|
18
|
+
})[] | null | undefined, isOptional?: boolean | undefined) => import("lit/directive.js").DirectiveResult<typeof AssertSlot>;
|
19
|
+
export default assertSlot;
|
@@ -0,0 +1 @@
|
|
1
|
+
import{LitElement,noChange}from"lit";import{Directive,directive,PartType}from"lit/directive.js";const isThrow=["localhost","127.0.0.1"].some((e=>window.location.host.includes(e)));class AssertSlot extends Directive{render(e,t){return noChange}update(e,[t,n]){if(e.options?.host instanceof LitElement&&isThrow){const o=e.options.host;!this.#e&&e.element&&isThrow&&(e.options.host.updateComplete.then((()=>{if(!n&&e.element instanceof HTMLSlotElement&&0===e.element.assignedNodes().length&&t?.length){const n=e.element.name?`Expected the "${e.element.name}" slot of ${o.constructor.name} to have a slotted element that extends ${t.map((({name:e})=>e)).join(" or ")}.`:`Expected ${o.constructor.name} to have a slotted element that extends ${t.map((({name:e})=>e)).join(" or ")}.`;throw new TypeError(n)}if(!n&&e.element instanceof HTMLSlotElement&&0===e.element.assignedNodes().length){const t=e.element.name?`Expected ${o.constructor.name} to have a "${e.element.name}" slot.`:`Expected ${o.constructor.name} to have a default slot.`;throw new TypeError(t)}})),this.#e||e.element?.addEventListener("slotchange",(()=>{if(!(n&&e.element instanceof HTMLSlotElement&&0===e.element.assignedNodes().length)){if(e.element instanceof HTMLSlotElement&&0===e.element.assignedNodes().length){if(t&&t.length>0){const n=e.element.name?`Expected the "${e.element.name}" slot of ${o.constructor.name} to have a slotted element that extends ${t.map((({name:e})=>e)).join(" or ")}.`:`Expected ${o.constructor.name} to have a slotted element that extends ${t.map((({name:e})=>e)).join(" or ")}.`;throw new TypeError(n)}const n=e.element.name?`Expected a "${e.element.name}" slot.`:"Expected a default slot.";throw new TypeError(n)}if(t?.length&&e.element instanceof HTMLSlotElement){const n=e.element.assignedNodes({flatten:!0}).filter((e=>!!(e instanceof Text&&t.includes(Text))||!(e instanceof Text)));if(0===n.length){const e=`Expected ${o.constructor.name} to have a slotted element that extends ${t.map((({name:e})=>e)).join(" or ")}.`;throw new TypeError(e)}for(const s of n){if(!t.some((e=>s instanceof e))){const n=e.element.name?`Expected the "${e.element.name}" slot of ${o.constructor.name} to have a slotted element that extends ${t.map((({name:e})=>e)).join(" or ")}. Extends ${s.constructor.name} instead.`:`Expected ${o.constructor.name} to have a slotted element that extends ${t.map((({name:e})=>e)).join(" or ")}. Extends ${s.constructor.name} instead.`;throw new TypeError(n)}}}}})),this.#e=!0)}return this.render()}constructor(e){if(super(e),e.type!==PartType.ELEMENT)throw new TypeError("Directive must be inside the element's opening tag.");if("element"in e){if(!(e.element instanceof HTMLSlotElement))throw new TypeError("Directive can only be used on slots.")}}#e=!1}const assertSlot=directive(AssertSlot);export default assertSlot;
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,296 @@
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
6
|
+
};
|
7
|
+
import { LitElement } from 'lit';
|
8
|
+
import { customElement, property } from 'lit/decorators.js';
|
9
|
+
import { aTimeout, expect, fixture, html, waitUntil } from '@open-wc/testing';
|
10
|
+
import sinon from 'sinon';
|
11
|
+
import { ifDefined } from 'lit/directives/if-defined.js';
|
12
|
+
import assertSlot from './assert-slot.js';
|
13
|
+
let GlideCoreWithSlot = class GlideCoreWithSlot extends LitElement {
|
14
|
+
constructor() {
|
15
|
+
super(...arguments);
|
16
|
+
this.optional = false;
|
17
|
+
this.slotted = [];
|
18
|
+
}
|
19
|
+
static { this.shadowRootOptions = {
|
20
|
+
...LitElement.shadowRootOptions,
|
21
|
+
}; }
|
22
|
+
render() {
|
23
|
+
return html `<slot
|
24
|
+
name=${ifDefined(this.name)}
|
25
|
+
${assertSlot(this.slotted, this.optional)}
|
26
|
+
></slot>`;
|
27
|
+
}
|
28
|
+
};
|
29
|
+
__decorate([
|
30
|
+
property()
|
31
|
+
], GlideCoreWithSlot.prototype, "name", void 0);
|
32
|
+
__decorate([
|
33
|
+
property({ type: Boolean })
|
34
|
+
], GlideCoreWithSlot.prototype, "optional", void 0);
|
35
|
+
__decorate([
|
36
|
+
property({ type: Array })
|
37
|
+
], GlideCoreWithSlot.prototype, "slotted", void 0);
|
38
|
+
GlideCoreWithSlot = __decorate([
|
39
|
+
customElement('glide-core-with-slot')
|
40
|
+
], GlideCoreWithSlot);
|
41
|
+
let GlideCoreWhenNotUsedOnSlot = class GlideCoreWhenNotUsedOnSlot extends LitElement {
|
42
|
+
static { this.shadowRootOptions = {
|
43
|
+
...LitElement.shadowRootOptions,
|
44
|
+
}; }
|
45
|
+
render() {
|
46
|
+
return html `<div ${assertSlot()}></div>`;
|
47
|
+
}
|
48
|
+
};
|
49
|
+
GlideCoreWhenNotUsedOnSlot = __decorate([
|
50
|
+
customElement('glide-core-when-not-used-on-slot')
|
51
|
+
], GlideCoreWhenNotUsedOnSlot);
|
52
|
+
let GlideCorewhenNotUsedInsideTag = class GlideCorewhenNotUsedInsideTag extends LitElement {
|
53
|
+
static { this.shadowRootOptions = {
|
54
|
+
...LitElement.shadowRootOptions,
|
55
|
+
}; }
|
56
|
+
render() {
|
57
|
+
return html `<slot>${assertSlot()}</slot>`;
|
58
|
+
}
|
59
|
+
};
|
60
|
+
GlideCorewhenNotUsedInsideTag = __decorate([
|
61
|
+
customElement('glide-core-when-not-used-inside-tag')
|
62
|
+
], GlideCorewhenNotUsedInsideTag);
|
63
|
+
it('throws when a required default slot is empty', async () => {
|
64
|
+
const stub = sinon.stub(console, 'error');
|
65
|
+
const spy = sinon.spy();
|
66
|
+
window.addEventListener('unhandledrejection', spy, { once: true });
|
67
|
+
await fixture(html `<glide-core-with-slot></glide-core-with-slot>`);
|
68
|
+
await waitUntil(() => spy.callCount);
|
69
|
+
expect(spy.callCount).to.equal(1);
|
70
|
+
expect(spy.args.at(0)?.at(0) instanceof PromiseRejectionEvent).to.be.true;
|
71
|
+
expect(spy.args.at(0)?.at(0).reason.message).to.equal('Expected GlideCoreWithSlot to have a default slot.');
|
72
|
+
stub.restore();
|
73
|
+
});
|
74
|
+
it('throws when a required default slot is emptied', async () => {
|
75
|
+
const component = await fixture(html `<glide-core-with-slot>
|
76
|
+
<button>Button</button>
|
77
|
+
</glide-core-with-slot>`);
|
78
|
+
const stub = sinon.stub(console, 'error');
|
79
|
+
const spy = sinon.spy();
|
80
|
+
const onerror = window.onerror;
|
81
|
+
// eslint-disable-next-line unicorn/prefer-add-event-listener
|
82
|
+
window.onerror = spy;
|
83
|
+
component.innerHTML = '';
|
84
|
+
await waitUntil(() => spy.callCount);
|
85
|
+
expect(spy.callCount).to.equal(1);
|
86
|
+
expect(spy.args.at(0)?.at(0)).to.equal('Uncaught TypeError: Expected a default slot.');
|
87
|
+
// eslint-disable-next-line unicorn/prefer-add-event-listener
|
88
|
+
window.onerror = onerror;
|
89
|
+
stub.restore();
|
90
|
+
});
|
91
|
+
it('throws when a required named slot is empty', async () => {
|
92
|
+
const stub = sinon.stub(console, 'error');
|
93
|
+
const spy = sinon.spy();
|
94
|
+
window.addEventListener('unhandledrejection', spy, { once: true });
|
95
|
+
await fixture(html `<glide-core-with-slot name="test"></glide-core-with-slot>`);
|
96
|
+
await waitUntil(() => spy.callCount);
|
97
|
+
expect(spy.callCount).to.equal(1);
|
98
|
+
expect(spy.args.at(0)?.at(0) instanceof PromiseRejectionEvent).to.be.true;
|
99
|
+
expect(spy.args.at(0)?.at(0).reason.message).to.equal('Expected GlideCoreWithSlot to have a "test" slot.');
|
100
|
+
stub.restore();
|
101
|
+
});
|
102
|
+
it('throws when a required named slot is emptied', async () => {
|
103
|
+
const component = await fixture(html `<glide-core-with-slot name="test">
|
104
|
+
<button slot="test">Button</button>
|
105
|
+
</glide-core-with-slot>`);
|
106
|
+
const stub = sinon.stub(console, 'error');
|
107
|
+
const spy = sinon.spy();
|
108
|
+
const onerror = window.onerror;
|
109
|
+
// eslint-disable-next-line unicorn/prefer-add-event-listener
|
110
|
+
window.onerror = spy;
|
111
|
+
component.innerHTML = '';
|
112
|
+
await waitUntil(() => spy.callCount);
|
113
|
+
expect(spy.callCount).to.equal(1);
|
114
|
+
expect(spy.args.at(0)?.at(0)).to.equal('Uncaught TypeError: Expected a "test" slot.');
|
115
|
+
// eslint-disable-next-line unicorn/prefer-add-event-listener
|
116
|
+
window.onerror = onerror;
|
117
|
+
stub.restore();
|
118
|
+
});
|
119
|
+
it('throws when a typed and required default slot is empty', async () => {
|
120
|
+
const stub = sinon.stub(console, 'error');
|
121
|
+
const spy = sinon.spy();
|
122
|
+
window.addEventListener('unhandledrejection', spy, { once: true });
|
123
|
+
await fixture(html `<glide-core-with-slot
|
124
|
+
.slotted=${[HTMLButtonElement]}
|
125
|
+
></glide-core-with-slot>`);
|
126
|
+
await waitUntil(() => spy.callCount);
|
127
|
+
expect(spy.callCount).to.equal(1);
|
128
|
+
expect(spy.args.at(0)?.at(0) instanceof PromiseRejectionEvent).to.be.true;
|
129
|
+
expect(spy.args.at(0)?.at(0).reason.message).to.equal('Expected GlideCoreWithSlot to have a slotted element that extends HTMLButtonElement.');
|
130
|
+
stub.restore();
|
131
|
+
});
|
132
|
+
it('throws when a typed and required default slot is emptied', async () => {
|
133
|
+
const component = await fixture(html `<glide-core-with-slot .slotted=${[HTMLButtonElement]}>
|
134
|
+
<button>Button</button>
|
135
|
+
</glide-core-with-slot>`);
|
136
|
+
const stub = sinon.stub(console, 'error');
|
137
|
+
const spy = sinon.spy();
|
138
|
+
const onerror = window.onerror;
|
139
|
+
// eslint-disable-next-line unicorn/prefer-add-event-listener
|
140
|
+
window.onerror = spy;
|
141
|
+
component.innerHTML = '';
|
142
|
+
await waitUntil(() => spy.callCount);
|
143
|
+
expect(spy.callCount).to.equal(1);
|
144
|
+
expect(spy.args.at(0)?.at(0)).to.equal('Uncaught TypeError: Expected GlideCoreWithSlot to have a slotted element that extends HTMLButtonElement.');
|
145
|
+
// eslint-disable-next-line unicorn/prefer-add-event-listener
|
146
|
+
window.onerror = onerror;
|
147
|
+
stub.restore();
|
148
|
+
});
|
149
|
+
it('throws when a typed and required default slot has the wrong element', async () => {
|
150
|
+
const stub = sinon.stub(console, 'error');
|
151
|
+
const spy = sinon.spy();
|
152
|
+
const onerror = window.onerror;
|
153
|
+
// eslint-disable-next-line unicorn/prefer-add-event-listener
|
154
|
+
window.onerror = spy;
|
155
|
+
await fixture(html `<glide-core-with-slot
|
156
|
+
.slotted=${[HTMLButtonElement, HTMLDivElement, Text]}
|
157
|
+
>
|
158
|
+
<a href="/">Link</a>
|
159
|
+
</glide-core-with-slot>`);
|
160
|
+
expect(spy.callCount).to.equal(1);
|
161
|
+
expect(spy.args.at(0)?.at(0)).to.equal('Uncaught TypeError: Expected GlideCoreWithSlot to have a slotted element that extends HTMLButtonElement or HTMLDivElement or Text. Extends HTMLAnchorElement instead.');
|
162
|
+
// eslint-disable-next-line unicorn/prefer-add-event-listener
|
163
|
+
window.onerror = onerror;
|
164
|
+
stub.restore();
|
165
|
+
});
|
166
|
+
it('throws when a typed and required default slot only contains text', async () => {
|
167
|
+
const stub = sinon.stub(console, 'error');
|
168
|
+
const spy = sinon.spy();
|
169
|
+
const onerror = window.onerror;
|
170
|
+
// eslint-disable-next-line unicorn/prefer-add-event-listener
|
171
|
+
window.onerror = spy;
|
172
|
+
await fixture(html `<glide-core-with-slot .slotted=${[HTMLButtonElement]}>
|
173
|
+
Text
|
174
|
+
</glide-core-with-slot>`);
|
175
|
+
expect(spy.callCount).to.equal(1);
|
176
|
+
expect(spy.args.at(0)?.at(0)).to.equal('Uncaught TypeError: Expected GlideCoreWithSlot to have a slotted element that extends HTMLButtonElement.');
|
177
|
+
// eslint-disable-next-line unicorn/prefer-add-event-listener
|
178
|
+
window.onerror = onerror;
|
179
|
+
stub.restore();
|
180
|
+
});
|
181
|
+
it('throws when a typed and required named slot is empty', async () => {
|
182
|
+
const stub = sinon.stub(console, 'error');
|
183
|
+
const spy = sinon.spy();
|
184
|
+
window.addEventListener('unhandledrejection', spy, { once: true });
|
185
|
+
await fixture(html `<glide-core-with-slot
|
186
|
+
name="test"
|
187
|
+
.slotted=${[HTMLButtonElement]}
|
188
|
+
></glide-core-with-slot>`);
|
189
|
+
await waitUntil(() => spy.callCount);
|
190
|
+
expect(spy.callCount).to.equal(1);
|
191
|
+
expect(spy.args.at(0)?.at(0) instanceof PromiseRejectionEvent).to.be.true;
|
192
|
+
expect(spy.args.at(0)?.at(0).reason.message).to.equal('Expected the "test" slot of GlideCoreWithSlot to have a slotted element that extends HTMLButtonElement.');
|
193
|
+
stub.restore();
|
194
|
+
});
|
195
|
+
it('throws when a typed and required named slot is emptied', async () => {
|
196
|
+
const component = await fixture(html `<glide-core-with-slot name="test" .slotted=${[HTMLButtonElement]}>
|
197
|
+
<button slot="test">Button</button>
|
198
|
+
</glide-core-with-slot>`);
|
199
|
+
const stub = sinon.stub(console, 'error');
|
200
|
+
const spy = sinon.spy();
|
201
|
+
const onerror = window.onerror;
|
202
|
+
// eslint-disable-next-line unicorn/prefer-add-event-listener
|
203
|
+
window.onerror = spy;
|
204
|
+
component.innerHTML = '';
|
205
|
+
await waitUntil(() => spy.callCount);
|
206
|
+
expect(spy.callCount).to.equal(1);
|
207
|
+
expect(spy.args.at(0)?.at(0)).to.equal('Uncaught TypeError: Expected the "test" slot of GlideCoreWithSlot to have a slotted element that extends HTMLButtonElement.');
|
208
|
+
// eslint-disable-next-line unicorn/prefer-add-event-listener
|
209
|
+
window.onerror = onerror;
|
210
|
+
stub.restore();
|
211
|
+
});
|
212
|
+
it('throws when a typed and required named slot has the wrong element', async () => {
|
213
|
+
const stub = sinon.stub(console, 'error');
|
214
|
+
const spy = sinon.spy();
|
215
|
+
const onerror = window.onerror;
|
216
|
+
// eslint-disable-next-line unicorn/prefer-add-event-listener
|
217
|
+
window.onerror = spy;
|
218
|
+
await fixture(html `<glide-core-with-slot
|
219
|
+
name="test"
|
220
|
+
.slotted=${[HTMLButtonElement, HTMLDivElement, Text]}
|
221
|
+
>
|
222
|
+
<a slot="test" href="/">Link</a>
|
223
|
+
</glide-core-with-slot>`);
|
224
|
+
expect(spy.callCount).to.equal(1);
|
225
|
+
expect(spy.args.at(0)?.at(0)).to.equal('Uncaught TypeError: Expected the "test" slot of GlideCoreWithSlot to have a slotted element that extends HTMLButtonElement or HTMLDivElement or Text. Extends HTMLAnchorElement instead.');
|
226
|
+
// eslint-disable-next-line unicorn/prefer-add-event-listener
|
227
|
+
window.onerror = onerror;
|
228
|
+
stub.restore();
|
229
|
+
});
|
230
|
+
it('does not throw when an optional slot is empty', async () => {
|
231
|
+
const spy = sinon.spy();
|
232
|
+
window.addEventListener('unhandledrejection', spy, { once: true });
|
233
|
+
await fixture(html `<glide-core-with-slot optional></glide-core-with-slot>`);
|
234
|
+
// Wait for the event handler to be called.
|
235
|
+
await aTimeout(0);
|
236
|
+
expect(spy.callCount).to.equal(0);
|
237
|
+
});
|
238
|
+
it('does not throw when an optional slot is emptied', async () => {
|
239
|
+
const spy = sinon.spy();
|
240
|
+
window.addEventListener('error', spy);
|
241
|
+
const component = await fixture(html `<glide-core-with-slot optional>
|
242
|
+
<button>Button</button>
|
243
|
+
</glide-core-with-slot>`);
|
244
|
+
component.innerHTML = '';
|
245
|
+
// Wait for the event handler to be called.
|
246
|
+
await aTimeout(0);
|
247
|
+
expect(spy.callCount).to.equal(0);
|
248
|
+
});
|
249
|
+
it('does not throw when a typed and required default slot only contains text and text is allowed', async () => {
|
250
|
+
const spy = sinon.spy();
|
251
|
+
window.addEventListener('error', spy);
|
252
|
+
await fixture(html `<glide-core-with-slot .slotted=${[Text]}> </glide-core-with-slot>`);
|
253
|
+
expect(spy.callCount).to.equal(0);
|
254
|
+
});
|
255
|
+
it('throws when a typed optional slot has the wrong element', async () => {
|
256
|
+
const stub = sinon.stub(console, 'error');
|
257
|
+
const spy = sinon.spy();
|
258
|
+
const onerror = window.onerror;
|
259
|
+
// eslint-disable-next-line unicorn/prefer-add-event-listener
|
260
|
+
window.onerror = spy;
|
261
|
+
await fixture(html `<glide-core-with-slot
|
262
|
+
.slotted=${[HTMLButtonElement, HTMLDivElement, Text]}
|
263
|
+
optional
|
264
|
+
>
|
265
|
+
<a href="/">Link</a>
|
266
|
+
</glide-core-with-slot>`);
|
267
|
+
expect(spy.callCount).to.equal(1);
|
268
|
+
expect(spy.args.at(0)?.at(0)).to.equal('Uncaught TypeError: Expected GlideCoreWithSlot to have a slotted element that extends HTMLButtonElement or HTMLDivElement or Text. Extends HTMLAnchorElement instead.');
|
269
|
+
// eslint-disable-next-line unicorn/prefer-add-event-listener
|
270
|
+
window.onerror = onerror;
|
271
|
+
stub.restore();
|
272
|
+
});
|
273
|
+
it('throws when not used on a slot', async () => {
|
274
|
+
const spy = sinon.spy();
|
275
|
+
try {
|
276
|
+
await fixture(html `<glide-core-when-not-used-on-slot></glide-core-when-not-used-on-slot>`);
|
277
|
+
}
|
278
|
+
catch (error) {
|
279
|
+
if (error instanceof Error) {
|
280
|
+
spy(error);
|
281
|
+
}
|
282
|
+
}
|
283
|
+
expect(spy.args.at(0)?.at(0).message).to.equal('Directive can only be used on slots.');
|
284
|
+
});
|
285
|
+
it('throws when not used inside an opening tag', async () => {
|
286
|
+
const spy = sinon.spy();
|
287
|
+
try {
|
288
|
+
await fixture(html `<glide-core-when-not-used-inside-tag></glide-core-when-not-used-inside-tag>`);
|
289
|
+
}
|
290
|
+
catch (error) {
|
291
|
+
if (error instanceof Error) {
|
292
|
+
spy(error);
|
293
|
+
}
|
294
|
+
}
|
295
|
+
expect(spy.args.at(0)?.at(0).message).to.equal("Directive must be inside the element's opening tag.");
|
296
|
+
});
|
@@ -0,0 +1 @@
|
|
1
|
+
import{expect,waitUntil}from"@open-wc/testing";import sinon from"sinon";export default async function(e){const n=sinon.stub(console,"error"),t=sinon.spy();window.addEventListener("unhandledrejection",t,{once:!0}),await e.call(context),await waitUntil((()=>t.callCount)),expect(t.callCount).to.equal(1),expect(t.args.at(0)?.at(0)instanceof PromiseRejectionEvent).to.be.true,window.removeEventListener("unhandledrejection",t),n.restore()}
|
@@ -0,0 +1 @@
|
|
1
|
+
export default function (callback: () => unknown): Promise<void>;
|
@@ -0,0 +1 @@
|
|
1
|
+
import{expect,waitUntil}from"@open-wc/testing";import sinon from"sinon";export default async function(o){const t=sinon.stub(console,"error"),n=sinon.spy(),r=window.onerror;window.onerror=n,await o.call(context),await waitUntil((()=>n.callCount)),expect(n.callCount).to.be.greaterThan(0),expect(n.args.at(0)?.at(4)instanceof TypeError).to.be.true,window.onerror=r,t.restore()}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
export default interface FormControl {
|
2
|
+
disabled: boolean;
|
3
|
+
form: HTMLFormElement | null;
|
4
|
+
hideLabel: boolean;
|
5
|
+
label?: string;
|
6
|
+
name: string;
|
7
|
+
orientation: 'horizontal' | 'vertical';
|
8
|
+
privateSplit?: 'left' | 'middle';
|
9
|
+
required: boolean;
|
10
|
+
summary?: string;
|
11
|
+
tooltip?: string;
|
12
|
+
validity: ValidityState;
|
13
|
+
value: string | string[];
|
14
|
+
willValidate: boolean;
|
15
|
+
checkValidity: () => boolean;
|
16
|
+
formAssociatedCallback: () => void;
|
17
|
+
formResetCallback: () => void;
|
18
|
+
reportValidity: () => boolean;
|
19
|
+
resetValidityFeedback: () => void;
|
20
|
+
setCustomValidity: (message: string) => void;
|
21
|
+
setValidity: (flags?: ValidityStateFlags, message?: string) => void;
|
22
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export{};
|
@@ -1,4 +1,3 @@
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unused-expressions */
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
@@ -6,10 +5,10 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
6
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
7
6
|
};
|
8
7
|
import { LitElement } from 'lit';
|
9
|
-
import { LocalizeController } from './localize.js';
|
10
8
|
import { customElement } from 'lit/decorators.js';
|
11
9
|
import { expect, fixture, html } from '@open-wc/testing';
|
12
10
|
import en from '../translations/en.js';
|
11
|
+
import { LocalizeController } from './localize.js';
|
13
12
|
let GlideCoreMockComponent = class GlideCoreMockComponent extends LitElement {
|
14
13
|
constructor() {
|
15
14
|
super(...arguments);
|
@@ -17,7 +16,6 @@ let GlideCoreMockComponent = class GlideCoreMockComponent extends LitElement {
|
|
17
16
|
}
|
18
17
|
static { this.shadowRootOptions = {
|
19
18
|
...LitElement.shadowRootOptions,
|
20
|
-
mode: 'closed',
|
21
19
|
}; }
|
22
20
|
};
|
23
21
|
GlideCoreMockComponent = __decorate([
|
@@ -0,0 +1 @@
|
|
1
|
+
export default window.navigator.webdriver?"open":"closed";
|
package/dist/menu.button.d.ts
CHANGED
@@ -5,7 +5,7 @@ declare global {
|
|
5
5
|
}
|
6
6
|
}
|
7
7
|
/**
|
8
|
-
* @slot icon - An icon.
|
8
|
+
* @slot icon - An optional icon.
|
9
9
|
*/
|
10
10
|
export default class GlideCoreMenuButton extends LitElement {
|
11
11
|
#private;
|
@@ -15,6 +15,7 @@ export default class GlideCoreMenuButton extends LitElement {
|
|
15
15
|
set disabled(isDisabled: boolean);
|
16
16
|
label?: string;
|
17
17
|
privateActive: boolean;
|
18
|
+
readonly version: string;
|
18
19
|
click(): void;
|
19
20
|
connectedCallback(): void;
|
20
21
|
render(): import("lit").TemplateResult<1>;
|
package/dist/menu.button.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
var __decorate=this&&this.__decorate||function(e,t,o,i){var s
|
1
|
+
var __decorate=this&&this.__decorate||function(e,t,o,i){var r,s=arguments.length,n=s<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,o):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,i);else for(var l=e.length-1;l>=0;l--)(r=e[l])&&(n=(s<3?r(n):s>3?r(t,o,n):r(t,o))||n);return s>3&&n&&Object.defineProperty(t,o,n),n};import{html,LitElement}from"lit";import{classMap}from"lit/directives/class-map.js";import{createRef,ref}from"lit/directives/ref.js";import{customElement,property}from"lit/decorators.js";import{nanoid}from"nanoid";import packageJson from"../package.json"with{type:"json"};import styles from"./menu.button.styles.js";import shadowRootMode from"./library/shadow-root-mode.js";let GlideCoreMenuButton=class GlideCoreMenuButton extends LitElement{constructor(){super(...arguments),this.privateActive=!1,this.version=packageJson.version,this.#e=createRef(),this.#t=nanoid(),this.#o=!1}static{this.shadowRootOptions={...LitElement.shadowRootOptions,mode:shadowRootMode}}static{this.styles=styles}get disabled(){return this.#o}set disabled(e){this.#o=e,e&&this.privateActive&&this.dispatchEvent(new Event("private-disabled",{bubbles:!0}))}click(){this.#e.value?.click()}connectedCallback(){super.connectedCallback(),this.id=this.#t,this.role="menuitem",this.tabIndex=-1}render(){return html`<button class="${classMap({component:!0,active:this.privateActive,disabled:this.disabled})}" ?disabled="${this.disabled}" data-test="component" type="button" ${ref(this.#e)}><slot name="icon"></slot>${this.label}</button>`}#e;#t;#o};__decorate([property({reflect:!0,type:Boolean})],GlideCoreMenuButton.prototype,"disabled",null),__decorate([property({reflect:!0})],GlideCoreMenuButton.prototype,"label",void 0),__decorate([property({type:Boolean})],GlideCoreMenuButton.prototype,"privateActive",void 0),__decorate([property({reflect:!0})],GlideCoreMenuButton.prototype,"version",void 0),GlideCoreMenuButton=__decorate([customElement("glide-core-menu-button")],GlideCoreMenuButton);export default GlideCoreMenuButton;
|
package/dist/menu.d.ts
CHANGED
@@ -22,6 +22,7 @@ export default class GlideCoreMenu extends LitElement {
|
|
22
22
|
placement: Placement;
|
23
23
|
get size(): "small" | "large";
|
24
24
|
set size(size: 'small' | 'large');
|
25
|
+
readonly version: string;
|
25
26
|
connectedCallback(): void;
|
26
27
|
createRenderRoot(): ShadowRoot;
|
27
28
|
disconnectedCallback(): void;
|
package/dist/menu.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
var __decorate=this&&this.__decorate||function(e,t,i,o){var n,s=arguments.length,l=s<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,i):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)l=Reflect.decorate(e,t,i,o);else for(var a=e.length-1;a>=0;a--)(n=e[a])&&(l=(s<3?n(l):s>3?n(t,i,l):n(t,i))||l);return s>3&&l&&Object.defineProperty(t,i,l),l};import{LitElement
|
1
|
+
var __decorate=this&&this.__decorate||function(e,t,i,o){var n,s=arguments.length,l=s<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,i):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)l=Reflect.decorate(e,t,i,o);else for(var a=e.length-1;a>=0;a--)(n=e[a])&&(l=(s<3?n(l):s>3?n(t,i,l):n(t,i))||l);return s>3&&l&&Object.defineProperty(t,i,l),l};import{html,LitElement}from"lit";import{autoUpdate,computePosition,flip,offset}from"@floating-ui/dom";import{createRef,ref}from"lit/directives/ref.js";import{customElement,property}from"lit/decorators.js";import{nanoid}from"nanoid";import packageJson from"../package.json"with{type:"json"};import GlideCoreMenuButton from"./menu.button.js";import GlideCoreMenuLink from"./menu.link.js";import GlideCoreMenuOptions from"./menu.options.js";import assertSlot from"./library/assert-slot.js";import styles from"./menu.styles.js";import shadowRootMode from"./library/shadow-root-mode.js";let GlideCoreMenu=class GlideCoreMenu extends LitElement{constructor(){super(...arguments),this.placement="bottom-start",this.version=packageJson.version,this.#e=createRef(),this.#t=createRef(),this.#i=!1,this.#o=!1,this.#n=!1,this.#s=!1,this.#l=!1,this.#a="large",this.#r=createRef(),this.#d=e=>{e.target===this.#t.value&&e.preventDefault()},this.#c=e=>{if(e.target===this.#t.value&&(this.#o=!0),e.target instanceof Element){const t=e.target?.closest("glide-core-menu-link");t?.disabled&&(this.#n=!0)}},this.#h=()=>{this.#o?this.#o=!1:this.#n?this.#n=!1:this.#l?this.#l=!1:(this.open=!1,this.#p&&(this.#p.ariaActivedescendant=""))},this.#u=()=>{this.#l=!0}}static{this.shadowRootOptions={...LitElement.shadowRootOptions,mode:shadowRootMode}}static{this.styles=styles}get offset(){return this.#m??Number.parseFloat(window.getComputedStyle(document.body).getPropertyValue("--glide-core-spacing-xxs"))*Number.parseFloat(window.getComputedStyle(document.documentElement).fontSize)}set offset(e){this.#m=e}get open(){return this.#s}set open(e){const t=e!==this.#s;this.#s=e,e&&t&&!this.isTargetDisabled?(this.#f(),this.dispatchEvent(new Event("toggle",{bubbles:!0,composed:!0}))):t&&(this.#E(),this.dispatchEvent(new Event("toggle",{bubbles:!0,composed:!0})))}get size(){return this.#a}set size(e){this.#a=e,this.#p&&(this.#p.privateSize=e)}connectedCallback(){super.connectedCallback(),document.addEventListener("click",this.#h,{capture:!0})}createRenderRoot(){return this.#v=super.createRenderRoot(),this.#v}disconnectedCallback(){super.disconnectedCallback(),document.removeEventListener("click",this.#h,{capture:!0})}firstUpdated(){this.#t.value&&(this.#t.value.popover="manual",this.open&&!this.isTargetDisabled&&this.#f()),this.#r.value?.addEventListener("mouseup",this.#u),this.#t.value?.addEventListener("mousedown",this.#d),this.#t.value?.addEventListener("mouseup",this.#c)}get isTargetDisabled(){const e=this.#g&&"disabled"in this.#g&&this.#g.disabled,t=this.#g&&"true"===this.#g.ariaDisabled;return Boolean(e)||Boolean(t)}render(){return html`<div class="component" @focusout="${this.#S}" ${ref(this.#e)}><slot class="target-slot" name="target" @click="${this.#C}" @keydown="${this.#k}" @slotchange="${this.#b}" ${assertSlot([Element])} ${ref(this.#r)}></slot><slot class="default-slot" @click="${this.#y}" @focusin="${this.#D}" @keydown="${this.#k}" @mouseover="${this.#R}" @private-disabled="${this.#w}" @private-slot-change="${this.#M}" @slotchange="${this.#O}" ${assertSlot([GlideCoreMenuOptions])} ${ref(this.#t)}></slot></div>`}#A;#e;#t;#i;#o;#n;#s;#l;#m;#v;#a;#r;get#L(){return this.#T?.find((({privateActive:e})=>e))}#d;#c;#h;#u;#G(e){this.#g&&"focus"in this.#g&&this.#g?.focus(e)}#E(){this.#A?.(),this.#p&&(this.#p.ariaActivedescendant=""),this.#g&&(this.#g.ariaExpanded="false"),this.#t.value?.hidePopover()}#S(e){const t=e.relatedTarget instanceof HTMLElement&&this.#v?.contains(e.relatedTarget),i=e.relatedTarget instanceof GlideCoreMenuOptions,o=e.relatedTarget instanceof GlideCoreMenuButton||e.relatedTarget instanceof GlideCoreMenuLink;t||i||o||(this.open=!1)}#O(){this.#p&&(this.#p.privateSize=this.size)}#y(e){e.target!==this.#t.value&&(this.open=!1)}#D(e){(e.target instanceof GlideCoreMenuButton||e.target instanceof GlideCoreMenuLink)&&this.#L&&this.#p&&!e.target.disabled&&(this.#L.privateActive=!1,e.target.privateActive=!0,this.#p.ariaActivedescendant=e.target.id)}#R(e){if((e.target instanceof GlideCoreMenuLink||e.target instanceof GlideCoreMenuButton)&&!e.target.disabled){if(this.#T)for(const t of this.#T)t.privateActive=t===e.target;this.#p&&(this.#p.ariaActivedescendant=e.target.id)}}#w(){if(this.#T&&this.#L){const e=this.#T.indexOf(this.#L);this.#L.privateActive=!1;const t=this.#T?.find(((t,i)=>!t.disabled&&i>e));if(t)return void(t.privateActive=!0);const i=this.#T.findLast(((t,i)=>!t.disabled&&i<e));i&&(i.privateActive=!0)}}#M(){const e=this.#T?.find((e=>!e.disabled));!this.#L&&e&&(e.privateActive=!0)}#k(e){const t=this.#g instanceof HTMLSpanElement||this.#g instanceof HTMLDivElement;if([" ","Enter"].includes(e.key)&&this.open)return" "===e.key&&t&&e.preventDefault(),this.open=!1,this.#G(),this.#L?.click(),void(this.#i=!0);if([" ","Enter"].includes(e.key)&&t)return e.preventDefault(),void(this.open=!0);if(["Escape"].includes(e.key)&&this.open)return e.preventDefault(),this.open=!1,void this.#G();if(["ArrowUp","ArrowDown"].includes(e.key)&&!this.open&&this.#L&&this.#p)return e.preventDefault(),this.open=!0,void(this.#p.ariaActivedescendant=this.#L.id);if(this.open&&this.#L&&this.#T){const t=this.#T.indexOf(this.#L);if("ArrowUp"===e.key&&!e.metaKey){e.preventDefault();const i=this.#T.findLast(((e,i)=>!e.disabled&&i<t));return void(i&&this.#p&&(this.#L.privateActive=!1,this.#p.ariaActivedescendant=i.id,i.privateActive=!0))}if("ArrowDown"===e.key&&!e.metaKey){e.preventDefault();const i=this.#T.find(((e,i)=>!e.disabled&&i>t));return void(i&&this.#p&&(this.#L.privateActive=!1,this.#p.ariaActivedescendant=i.id,i.privateActive=!0))}if("ArrowUp"===e.key&&e.metaKey||"Home"===e.key||"PageUp"===e.key){e.preventDefault();const t=[...this.#T].reverse().findLast((e=>!e.disabled));return void(t&&this.#p&&(this.#L.privateActive=!1,this.#p.ariaActivedescendant=t.id,t.privateActive=!0))}if("ArrowDown"===e.key&&e.metaKey||"End"===e.key||"PageDown"===e.key){e.preventDefault();const t=[...this.#T].findLast((e=>!e.disabled));return void(t&&this.#p&&(this.#L.privateActive=!1,this.#p.ariaActivedescendant=t.id,t.privateActive=!0))}}}#b(){const e=new MutationObserver((()=>{this.open&&!this.isTargetDisabled?this.#f():this.#E()}));this.#g&&this.#p&&(e.observe(this.#g,{attributes:!0,attributeFilter:["aria-disabled","disabled"]}),this.#g.ariaHasPopup="true",this.#g.id=nanoid(),this.#g.setAttribute("aria-controls",this.#p.id),this.#p.ariaLabelledby=this.#g.id);(this.#g instanceof HTMLSpanElement||this.#g instanceof HTMLDivElement)&&this.#g instanceof HTMLElement&&(this.#g.tabIndex=0),this.open&&!this.isTargetDisabled?this.#f():this.#E()}#C(){this.isTargetDisabled?this.#E():this.#i?this.#i=!1:this.#T&&this.#T.length>0&&(this.open=!this.open)}get#p(){const e=this.#t.value?.assignedElements().at(0);return e instanceof GlideCoreMenuOptions?e:null}get#T(){let e=this.#t.value?.assignedElements()?.at(0)?.children;const t=e?.[0];if(t instanceof HTMLSlotElement&&(e=t.assignedElements()),e)return[...e].filter((e=>e instanceof GlideCoreMenuLink||e instanceof GlideCoreMenuButton))}#f(){this.#A?.(),this.#g&&this.#t.value&&(this.#A=autoUpdate(this.#g,this.#t.value,(()=>{(async()=>{if(this.#g&&this.#t.value){const{x:e,y:t,placement:i}=await computePosition(this.#g,this.#t.value,{placement:this.placement,middleware:[offset(this.offset),flip()]});this.#t.value.dataset.placement=i,Object.assign(this.#t.value.style,{left:`${e}px`,top:`${t}px`})}this.#t.value?.showPopover(),this.#p&&this.#L?.id&&(this.#p.ariaActivedescendant=this.#L.id),this.#g&&(this.#g.ariaExpanded="true")})()})))}get#g(){return this.#r.value?.assignedElements().at(0)}};__decorate([property({reflect:!0,type:Number})],GlideCoreMenu.prototype,"offset",null),__decorate([property({reflect:!0,type:Boolean})],GlideCoreMenu.prototype,"open",null),__decorate([property({reflect:!0})],GlideCoreMenu.prototype,"placement",void 0),__decorate([property({reflect:!0})],GlideCoreMenu.prototype,"size",null),__decorate([property({reflect:!0})],GlideCoreMenu.prototype,"version",void 0),GlideCoreMenu=__decorate([customElement("glide-core-menu")],GlideCoreMenu);export default GlideCoreMenu;
|