@phcdevworks/spectre-components 1.6.0 → 1.8.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/README.md +194 -1
- package/dist/alert.cjs.map +1 -1
- package/dist/alert.d.cts +2 -2
- package/dist/alert.d.ts +2 -2
- package/dist/alert.js.map +1 -1
- package/dist/avatar.cjs.map +1 -1
- package/dist/avatar.d.cts +2 -2
- package/dist/avatar.d.ts +2 -2
- package/dist/avatar.js.map +1 -1
- package/dist/badge.cjs.map +1 -1
- package/dist/badge.d.cts +2 -2
- package/dist/badge.d.ts +2 -2
- package/dist/badge.js.map +1 -1
- package/dist/button.cjs.map +1 -1
- package/dist/button.d.cts +2 -2
- package/dist/button.d.ts +2 -2
- package/dist/button.js.map +1 -1
- package/dist/card.cjs.map +1 -1
- package/dist/card.d.cts +2 -2
- package/dist/card.d.ts +2 -2
- package/dist/card.js.map +1 -1
- package/dist/container.cjs.map +1 -1
- package/dist/container.d.cts +2 -2
- package/dist/container.d.ts +2 -2
- package/dist/container.js.map +1 -1
- package/dist/dropdown.cjs +486 -0
- package/dist/dropdown.cjs.map +1 -0
- package/dist/dropdown.d.cts +69 -0
- package/dist/dropdown.d.ts +69 -0
- package/dist/dropdown.js +482 -0
- package/dist/dropdown.js.map +1 -0
- package/dist/footer.cjs +418 -0
- package/dist/footer.cjs.map +1 -0
- package/dist/footer.d.cts +39 -0
- package/dist/footer.d.ts +39 -0
- package/dist/footer.js +415 -0
- package/dist/footer.js.map +1 -0
- package/dist/{form-8KZeQRgr.d.cts → form-DgzRhNmg.d.cts} +7 -1
- package/dist/{form-8KZeQRgr.d.ts → form-DgzRhNmg.d.ts} +7 -1
- package/dist/grid.cjs.map +1 -1
- package/dist/grid.d.cts +2 -2
- package/dist/grid.d.ts +2 -2
- package/dist/grid.js.map +1 -1
- package/dist/icon-box.cjs.map +1 -1
- package/dist/icon-box.d.cts +2 -2
- package/dist/icon-box.d.ts +2 -2
- package/dist/icon-box.js.map +1 -1
- package/dist/index.cjs +993 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +978 -2
- package/dist/index.js.map +1 -1
- package/dist/input.cjs.map +1 -1
- package/dist/input.d.cts +2 -2
- package/dist/input.d.ts +2 -2
- package/dist/input.js.map +1 -1
- package/dist/modal.cjs +519 -0
- package/dist/modal.cjs.map +1 -0
- package/dist/modal.d.cts +52 -0
- package/dist/modal.d.ts +52 -0
- package/dist/modal.js +516 -0
- package/dist/modal.js.map +1 -0
- package/dist/nav.cjs +424 -0
- package/dist/nav.cjs.map +1 -0
- package/dist/nav.d.cts +45 -0
- package/dist/nav.d.ts +45 -0
- package/dist/nav.js +421 -0
- package/dist/nav.js.map +1 -0
- package/dist/rating.cjs.map +1 -1
- package/dist/rating.d.cts +2 -2
- package/dist/rating.d.ts +2 -2
- package/dist/rating.js.map +1 -1
- package/dist/select.cjs.map +1 -1
- package/dist/select.d.cts +1 -1
- package/dist/select.d.ts +1 -1
- package/dist/select.js.map +1 -1
- package/dist/sidebar.cjs +481 -0
- package/dist/sidebar.cjs.map +1 -0
- package/dist/sidebar.d.cts +50 -0
- package/dist/sidebar.d.ts +50 -0
- package/dist/sidebar.js +478 -0
- package/dist/sidebar.js.map +1 -0
- package/dist/spinner.cjs.map +1 -1
- package/dist/spinner.d.cts +2 -2
- package/dist/spinner.d.ts +2 -2
- package/dist/spinner.js.map +1 -1
- package/dist/stack.cjs.map +1 -1
- package/dist/stack.d.cts +2 -2
- package/dist/stack.d.ts +2 -2
- package/dist/stack.js.map +1 -1
- package/dist/tag.cjs.map +1 -1
- package/dist/tag.d.cts +2 -2
- package/dist/tag.d.ts +2 -2
- package/dist/tag.js.map +1 -1
- package/dist/testimonial.cjs.map +1 -1
- package/dist/testimonial.d.cts +2 -2
- package/dist/testimonial.d.ts +2 -2
- package/dist/testimonial.js.map +1 -1
- package/dist/textarea.cjs.map +1 -1
- package/dist/textarea.d.cts +1 -1
- package/dist/textarea.d.ts +1 -1
- package/dist/textarea.js.map +1 -1
- package/dist/toast.cjs +475 -0
- package/dist/toast.cjs.map +1 -0
- package/dist/toast.d.cts +68 -0
- package/dist/toast.d.ts +68 -0
- package/dist/toast.js +471 -0
- package/dist/toast.js.map +1 -0
- package/dist/tooltip.cjs +444 -0
- package/dist/tooltip.cjs.map +1 -0
- package/dist/tooltip.d.cts +50 -0
- package/dist/tooltip.d.ts +50 -0
- package/dist/tooltip.js +440 -0
- package/dist/tooltip.js.map +1 -0
- package/package.json +43 -8
package/dist/index.cjs
CHANGED
|
@@ -172,6 +172,37 @@ var spectreStackAligns = ["center", "stretch"];
|
|
|
172
172
|
function isStackAlign(value) {
|
|
173
173
|
return spectreStackAligns.includes(value);
|
|
174
174
|
}
|
|
175
|
+
var spectreDropdownPlacements = [
|
|
176
|
+
"bottom-start",
|
|
177
|
+
"bottom-end",
|
|
178
|
+
"top-start",
|
|
179
|
+
"top-end"
|
|
180
|
+
];
|
|
181
|
+
function isDropdownPlacement(value) {
|
|
182
|
+
return spectreDropdownPlacements.includes(
|
|
183
|
+
value
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
var spectreToastVariants = [
|
|
187
|
+
"info",
|
|
188
|
+
"success",
|
|
189
|
+
"warning",
|
|
190
|
+
"danger"
|
|
191
|
+
];
|
|
192
|
+
function isToastVariant(value) {
|
|
193
|
+
return spectreToastVariants.includes(value);
|
|
194
|
+
}
|
|
195
|
+
var spectreTooltipPlacements = [
|
|
196
|
+
"top",
|
|
197
|
+
"bottom",
|
|
198
|
+
"left",
|
|
199
|
+
"right"
|
|
200
|
+
];
|
|
201
|
+
function isTooltipPlacement(value) {
|
|
202
|
+
return spectreTooltipPlacements.includes(
|
|
203
|
+
value
|
|
204
|
+
);
|
|
205
|
+
}
|
|
175
206
|
function normalizeInt(value, fallback, min = 0) {
|
|
176
207
|
if (value == null || typeof value !== "number" || !Number.isInteger(value) || value < min) {
|
|
177
208
|
return fallback;
|
|
@@ -2886,6 +2917,944 @@ function defineSpectreStack(tagName = "sp-stack") {
|
|
|
2886
2917
|
customElements.define(tagName, SpectreStackElement);
|
|
2887
2918
|
return SpectreStackElement;
|
|
2888
2919
|
}
|
|
2920
|
+
var SpectreDropdownElement = class extends SpectreBaseElement {
|
|
2921
|
+
constructor() {
|
|
2922
|
+
super(...arguments);
|
|
2923
|
+
this.fullWidth = false;
|
|
2924
|
+
this.open = false;
|
|
2925
|
+
this.placement = "bottom-start";
|
|
2926
|
+
this.triggerLabel = "Toggle menu";
|
|
2927
|
+
this.triggerContent = [];
|
|
2928
|
+
this.menuContent = [];
|
|
2929
|
+
this.handleDocumentClick = (event) => {
|
|
2930
|
+
if (!this.open) {
|
|
2931
|
+
return;
|
|
2932
|
+
}
|
|
2933
|
+
if (!event.composedPath().includes(this)) {
|
|
2934
|
+
this.close();
|
|
2935
|
+
}
|
|
2936
|
+
};
|
|
2937
|
+
this.handleDocumentKeydown = (event) => {
|
|
2938
|
+
if (event.key === "Escape" && this.open) {
|
|
2939
|
+
this.close();
|
|
2940
|
+
this.triggerElement?.focus();
|
|
2941
|
+
}
|
|
2942
|
+
};
|
|
2943
|
+
}
|
|
2944
|
+
get id() {
|
|
2945
|
+
return super.id;
|
|
2946
|
+
}
|
|
2947
|
+
set id(value) {
|
|
2948
|
+
super.id = value;
|
|
2949
|
+
}
|
|
2950
|
+
get title() {
|
|
2951
|
+
return super.title;
|
|
2952
|
+
}
|
|
2953
|
+
set title(value) {
|
|
2954
|
+
super.title = value;
|
|
2955
|
+
}
|
|
2956
|
+
isInternalNode(node) {
|
|
2957
|
+
if (node.nodeType !== Node.ELEMENT_NODE) {
|
|
2958
|
+
return false;
|
|
2959
|
+
}
|
|
2960
|
+
const el = node;
|
|
2961
|
+
return el.hasAttribute("data-sp-dropdown-menu") || el.hasAttribute("data-sp-dropdown-trigger");
|
|
2962
|
+
}
|
|
2963
|
+
syncProjectedContent() {
|
|
2964
|
+
const nextTriggerContent = [];
|
|
2965
|
+
const nextMenuContent = [];
|
|
2966
|
+
this.childNodes.forEach((node) => {
|
|
2967
|
+
if (this.isInternalNode(node)) {
|
|
2968
|
+
return;
|
|
2969
|
+
}
|
|
2970
|
+
const isTriggerSlot = node.nodeType === Node.ELEMENT_NODE && node.getAttribute("slot") === "trigger";
|
|
2971
|
+
if (isTriggerSlot) {
|
|
2972
|
+
nextTriggerContent.push(node);
|
|
2973
|
+
} else {
|
|
2974
|
+
nextMenuContent.push(node);
|
|
2975
|
+
}
|
|
2976
|
+
});
|
|
2977
|
+
const changed = nextTriggerContent.length !== this.triggerContent.length || nextTriggerContent.some((n, i) => n !== this.triggerContent[i]) || nextMenuContent.length !== this.menuContent.length || nextMenuContent.some((n, i) => n !== this.menuContent[i]);
|
|
2978
|
+
if (changed) {
|
|
2979
|
+
this.triggerContent = nextTriggerContent;
|
|
2980
|
+
this.menuContent = nextMenuContent;
|
|
2981
|
+
}
|
|
2982
|
+
return changed;
|
|
2983
|
+
}
|
|
2984
|
+
get hasTriggerContent() {
|
|
2985
|
+
return hasMeaningfulContent(this.triggerContent);
|
|
2986
|
+
}
|
|
2987
|
+
get hasMenuContent() {
|
|
2988
|
+
return hasMeaningfulContent(this.menuContent);
|
|
2989
|
+
}
|
|
2990
|
+
connectedCallback() {
|
|
2991
|
+
super.connectedCallback();
|
|
2992
|
+
this.syncProjectedContent();
|
|
2993
|
+
this.startContentObserver();
|
|
2994
|
+
document.addEventListener("click", this.handleDocumentClick);
|
|
2995
|
+
document.addEventListener("keydown", this.handleDocumentKeydown);
|
|
2996
|
+
}
|
|
2997
|
+
disconnectedCallback() {
|
|
2998
|
+
this.stopContentObserver();
|
|
2999
|
+
document.removeEventListener("click", this.handleDocumentClick);
|
|
3000
|
+
document.removeEventListener("keydown", this.handleDocumentKeydown);
|
|
3001
|
+
super.disconnectedCallback();
|
|
3002
|
+
}
|
|
3003
|
+
update(changedProperties) {
|
|
3004
|
+
this.stopContentObserver();
|
|
3005
|
+
super.update(changedProperties);
|
|
3006
|
+
this.startContentObserver();
|
|
3007
|
+
}
|
|
3008
|
+
startContentObserver() {
|
|
3009
|
+
if (this.contentObserver) {
|
|
3010
|
+
return;
|
|
3011
|
+
}
|
|
3012
|
+
this.contentObserver = new MutationObserver(() => {
|
|
3013
|
+
if (this.syncProjectedContent()) {
|
|
3014
|
+
this.requestUpdate();
|
|
3015
|
+
}
|
|
3016
|
+
});
|
|
3017
|
+
this.contentObserver.observe(this, { childList: true });
|
|
3018
|
+
}
|
|
3019
|
+
stopContentObserver() {
|
|
3020
|
+
this.contentObserver?.disconnect();
|
|
3021
|
+
this.contentObserver = void 0;
|
|
3022
|
+
}
|
|
3023
|
+
willUpdate(changedProperties) {
|
|
3024
|
+
if (changedProperties.has("fullWidth") && this.fullWidth == null) {
|
|
3025
|
+
this.fullWidth = false;
|
|
3026
|
+
}
|
|
3027
|
+
if (changedProperties.has("open") && this.open == null) {
|
|
3028
|
+
this.open = false;
|
|
3029
|
+
}
|
|
3030
|
+
if (changedProperties.has("placement") && (this.placement == null || !isDropdownPlacement(this.placement))) {
|
|
3031
|
+
this.placement = "bottom-start";
|
|
3032
|
+
}
|
|
3033
|
+
if (changedProperties.has("triggerLabel") && !this.triggerLabel) {
|
|
3034
|
+
this.triggerLabel = "Toggle menu";
|
|
3035
|
+
}
|
|
3036
|
+
}
|
|
3037
|
+
get triggerElement() {
|
|
3038
|
+
return this.querySelector("[data-sp-dropdown-trigger]");
|
|
3039
|
+
}
|
|
3040
|
+
toggle() {
|
|
3041
|
+
if (this.open) {
|
|
3042
|
+
this.close();
|
|
3043
|
+
} else {
|
|
3044
|
+
this.openMenu();
|
|
3045
|
+
}
|
|
3046
|
+
}
|
|
3047
|
+
openMenu() {
|
|
3048
|
+
if (this.open) {
|
|
3049
|
+
return;
|
|
3050
|
+
}
|
|
3051
|
+
this.open = true;
|
|
3052
|
+
this.dispatchEvent(new CustomEvent("sp-open", { bubbles: true }));
|
|
3053
|
+
}
|
|
3054
|
+
close() {
|
|
3055
|
+
if (!this.open) {
|
|
3056
|
+
return;
|
|
3057
|
+
}
|
|
3058
|
+
this.open = false;
|
|
3059
|
+
this.dispatchEvent(new CustomEvent("sp-close", { bubbles: true }));
|
|
3060
|
+
}
|
|
3061
|
+
get dropdownClasses() {
|
|
3062
|
+
return spectreUi.getDropdownClasses({ fullWidth: this.fullWidth ?? false });
|
|
3063
|
+
}
|
|
3064
|
+
get menuClasses() {
|
|
3065
|
+
return spectreUi.getDropdownMenuClasses({
|
|
3066
|
+
open: this.open ?? false,
|
|
3067
|
+
placement: this.placement
|
|
3068
|
+
});
|
|
3069
|
+
}
|
|
3070
|
+
render() {
|
|
3071
|
+
return lit.html`<div
|
|
3072
|
+
class="${this.dropdownClasses}"
|
|
3073
|
+
id="${ifDefined_js.ifDefined(this.id || void 0)}"
|
|
3074
|
+
title="${ifDefined_js.ifDefined(this.title || void 0)}"
|
|
3075
|
+
>
|
|
3076
|
+
<button
|
|
3077
|
+
aria-expanded="${this.open ? "true" : "false"}"
|
|
3078
|
+
aria-haspopup="true"
|
|
3079
|
+
aria-label="${ifDefined_js.ifDefined(this.forwardedAriaLabel ?? this.triggerLabel)}"
|
|
3080
|
+
class="sp-dropdown__trigger"
|
|
3081
|
+
data-sp-dropdown-trigger
|
|
3082
|
+
type="button"
|
|
3083
|
+
@click="${() => this.toggle()}"
|
|
3084
|
+
>
|
|
3085
|
+
${this.hasTriggerContent ? this.triggerContent : this.triggerLabel}
|
|
3086
|
+
</button>
|
|
3087
|
+
<div class="${this.menuClasses}" data-sp-dropdown-menu>
|
|
3088
|
+
${this.hasMenuContent ? this.menuContent : lit.nothing}
|
|
3089
|
+
</div>
|
|
3090
|
+
</div>`;
|
|
3091
|
+
}
|
|
3092
|
+
};
|
|
3093
|
+
SpectreDropdownElement.properties = {
|
|
3094
|
+
fullWidth: { attribute: "full-width", type: Boolean, reflect: true },
|
|
3095
|
+
open: { type: Boolean, reflect: true },
|
|
3096
|
+
placement: { type: String, reflect: true },
|
|
3097
|
+
triggerLabel: { attribute: "trigger-label", type: String }
|
|
3098
|
+
};
|
|
3099
|
+
function defineSpectreDropdown(tagName = "sp-dropdown") {
|
|
3100
|
+
const existingElement = customElements.get(tagName);
|
|
3101
|
+
if (existingElement) {
|
|
3102
|
+
return existingElement;
|
|
3103
|
+
}
|
|
3104
|
+
customElements.define(tagName, SpectreDropdownElement);
|
|
3105
|
+
return SpectreDropdownElement;
|
|
3106
|
+
}
|
|
3107
|
+
var SpectreFooterElement = class extends SpectreProjectableElement {
|
|
3108
|
+
constructor() {
|
|
3109
|
+
super(...arguments);
|
|
3110
|
+
this.bordered = false;
|
|
3111
|
+
this.fullWidth = false;
|
|
3112
|
+
}
|
|
3113
|
+
get id() {
|
|
3114
|
+
return super.id;
|
|
3115
|
+
}
|
|
3116
|
+
set id(value) {
|
|
3117
|
+
super.id = value;
|
|
3118
|
+
}
|
|
3119
|
+
get title() {
|
|
3120
|
+
return super.title;
|
|
3121
|
+
}
|
|
3122
|
+
set title(value) {
|
|
3123
|
+
super.title = value;
|
|
3124
|
+
}
|
|
3125
|
+
getContentContainer() {
|
|
3126
|
+
return this.querySelector("[data-sp-footer-native]");
|
|
3127
|
+
}
|
|
3128
|
+
isInternalNode(node) {
|
|
3129
|
+
if (node.nodeType !== Node.ELEMENT_NODE) {
|
|
3130
|
+
return false;
|
|
3131
|
+
}
|
|
3132
|
+
const el = node;
|
|
3133
|
+
return el.hasAttribute("data-sp-footer-native");
|
|
3134
|
+
}
|
|
3135
|
+
willUpdate(changedProperties) {
|
|
3136
|
+
if (changedProperties.has("bordered") && this.bordered == null) {
|
|
3137
|
+
this.bordered = false;
|
|
3138
|
+
}
|
|
3139
|
+
if (changedProperties.has("fullWidth") && this.fullWidth == null) {
|
|
3140
|
+
this.fullWidth = false;
|
|
3141
|
+
}
|
|
3142
|
+
}
|
|
3143
|
+
get footerClasses() {
|
|
3144
|
+
return spectreUi.getFooterClasses({
|
|
3145
|
+
bordered: this.bordered ?? false,
|
|
3146
|
+
fullWidth: this.fullWidth ?? false
|
|
3147
|
+
});
|
|
3148
|
+
}
|
|
3149
|
+
render() {
|
|
3150
|
+
return lit.html`<footer
|
|
3151
|
+
aria-label="${ifDefined_js.ifDefined(this.forwardedAriaLabel)}"
|
|
3152
|
+
class="${this.footerClasses}"
|
|
3153
|
+
data-sp-footer-native
|
|
3154
|
+
id="${ifDefined_js.ifDefined(this.id || void 0)}"
|
|
3155
|
+
title="${ifDefined_js.ifDefined(this.title || void 0)}"
|
|
3156
|
+
>
|
|
3157
|
+
${this.hasProjectedContent ? this.projectedContent : lit.nothing}
|
|
3158
|
+
</footer>`;
|
|
3159
|
+
}
|
|
3160
|
+
};
|
|
3161
|
+
SpectreFooterElement.properties = {
|
|
3162
|
+
bordered: { type: Boolean, reflect: true },
|
|
3163
|
+
fullWidth: { attribute: "full-width", type: Boolean, reflect: true }
|
|
3164
|
+
};
|
|
3165
|
+
function defineSpectreFooter(tagName = "sp-footer") {
|
|
3166
|
+
const existingElement = customElements.get(tagName);
|
|
3167
|
+
if (existingElement) {
|
|
3168
|
+
return existingElement;
|
|
3169
|
+
}
|
|
3170
|
+
customElements.define(tagName, SpectreFooterElement);
|
|
3171
|
+
return SpectreFooterElement;
|
|
3172
|
+
}
|
|
3173
|
+
var FOCUSABLE_SELECTOR = [
|
|
3174
|
+
"a[href]",
|
|
3175
|
+
"button:not([disabled])",
|
|
3176
|
+
"input:not([disabled])",
|
|
3177
|
+
"select:not([disabled])",
|
|
3178
|
+
"textarea:not([disabled])",
|
|
3179
|
+
'[tabindex]:not([tabindex="-1"])'
|
|
3180
|
+
].join(",");
|
|
3181
|
+
var SpectreModalElement = class extends SpectreProjectableElement {
|
|
3182
|
+
constructor() {
|
|
3183
|
+
super(...arguments);
|
|
3184
|
+
this.fullWidth = false;
|
|
3185
|
+
this.open = false;
|
|
3186
|
+
this.previouslyFocusedElement = null;
|
|
3187
|
+
this.handleDocumentKeydown = (event) => {
|
|
3188
|
+
if (!this.open) {
|
|
3189
|
+
return;
|
|
3190
|
+
}
|
|
3191
|
+
if (event.key === "Escape") {
|
|
3192
|
+
this.close();
|
|
3193
|
+
return;
|
|
3194
|
+
}
|
|
3195
|
+
if (event.key === "Tab") {
|
|
3196
|
+
this.trapFocus(event);
|
|
3197
|
+
}
|
|
3198
|
+
};
|
|
3199
|
+
}
|
|
3200
|
+
get id() {
|
|
3201
|
+
return super.id;
|
|
3202
|
+
}
|
|
3203
|
+
set id(value) {
|
|
3204
|
+
super.id = value;
|
|
3205
|
+
}
|
|
3206
|
+
get title() {
|
|
3207
|
+
return super.title;
|
|
3208
|
+
}
|
|
3209
|
+
set title(value) {
|
|
3210
|
+
super.title = value;
|
|
3211
|
+
}
|
|
3212
|
+
getContentContainer() {
|
|
3213
|
+
return this.querySelector("[data-sp-modal-native]");
|
|
3214
|
+
}
|
|
3215
|
+
isInternalNode(node) {
|
|
3216
|
+
if (node.nodeType !== Node.ELEMENT_NODE) {
|
|
3217
|
+
return false;
|
|
3218
|
+
}
|
|
3219
|
+
const el = node;
|
|
3220
|
+
return el.hasAttribute("data-sp-modal-native") || el.hasAttribute("data-sp-modal-overlay");
|
|
3221
|
+
}
|
|
3222
|
+
willUpdate(changedProperties) {
|
|
3223
|
+
if (changedProperties.has("fullWidth") && this.fullWidth == null) {
|
|
3224
|
+
this.fullWidth = false;
|
|
3225
|
+
}
|
|
3226
|
+
if (changedProperties.has("open") && this.open == null) {
|
|
3227
|
+
this.open = false;
|
|
3228
|
+
}
|
|
3229
|
+
}
|
|
3230
|
+
updated(changedProperties) {
|
|
3231
|
+
super.updated(changedProperties);
|
|
3232
|
+
if (!changedProperties.has("open")) {
|
|
3233
|
+
return;
|
|
3234
|
+
}
|
|
3235
|
+
if (this.open) {
|
|
3236
|
+
this.previouslyFocusedElement = document.activeElement;
|
|
3237
|
+
this.focusFirstElement();
|
|
3238
|
+
} else if (this.previouslyFocusedElement) {
|
|
3239
|
+
this.previouslyFocusedElement.focus();
|
|
3240
|
+
this.previouslyFocusedElement = null;
|
|
3241
|
+
}
|
|
3242
|
+
}
|
|
3243
|
+
connectedCallback() {
|
|
3244
|
+
super.connectedCallback();
|
|
3245
|
+
document.addEventListener("keydown", this.handleDocumentKeydown);
|
|
3246
|
+
}
|
|
3247
|
+
disconnectedCallback() {
|
|
3248
|
+
document.removeEventListener("keydown", this.handleDocumentKeydown);
|
|
3249
|
+
super.disconnectedCallback();
|
|
3250
|
+
}
|
|
3251
|
+
get modalElement() {
|
|
3252
|
+
return this.querySelector("[data-sp-modal-native]");
|
|
3253
|
+
}
|
|
3254
|
+
get focusableElements() {
|
|
3255
|
+
const modal = this.modalElement;
|
|
3256
|
+
if (!modal) {
|
|
3257
|
+
return [];
|
|
3258
|
+
}
|
|
3259
|
+
return Array.from(modal.querySelectorAll(FOCUSABLE_SELECTOR));
|
|
3260
|
+
}
|
|
3261
|
+
focusFirstElement() {
|
|
3262
|
+
const [first] = this.focusableElements;
|
|
3263
|
+
(first ?? this.modalElement)?.focus();
|
|
3264
|
+
}
|
|
3265
|
+
trapFocus(event) {
|
|
3266
|
+
const focusable = this.focusableElements;
|
|
3267
|
+
if (focusable.length === 0) {
|
|
3268
|
+
event.preventDefault();
|
|
3269
|
+
return;
|
|
3270
|
+
}
|
|
3271
|
+
const first = focusable[0];
|
|
3272
|
+
const last = focusable[focusable.length - 1];
|
|
3273
|
+
const active = document.activeElement;
|
|
3274
|
+
if (event.shiftKey && active === first) {
|
|
3275
|
+
event.preventDefault();
|
|
3276
|
+
last?.focus();
|
|
3277
|
+
} else if (!event.shiftKey && active === last) {
|
|
3278
|
+
event.preventDefault();
|
|
3279
|
+
first?.focus();
|
|
3280
|
+
}
|
|
3281
|
+
}
|
|
3282
|
+
close() {
|
|
3283
|
+
if (!this.open) {
|
|
3284
|
+
return;
|
|
3285
|
+
}
|
|
3286
|
+
this.open = false;
|
|
3287
|
+
this.dispatchEvent(new CustomEvent("sp-close", { bubbles: true }));
|
|
3288
|
+
}
|
|
3289
|
+
get overlayClasses() {
|
|
3290
|
+
return spectreUi.getModalOverlayClasses({ open: this.open ?? false });
|
|
3291
|
+
}
|
|
3292
|
+
get modalClasses() {
|
|
3293
|
+
return spectreUi.getModalClasses({
|
|
3294
|
+
open: this.open ?? false,
|
|
3295
|
+
fullWidth: this.fullWidth ?? false
|
|
3296
|
+
});
|
|
3297
|
+
}
|
|
3298
|
+
render() {
|
|
3299
|
+
const isHidden = !this.open;
|
|
3300
|
+
return lit.html`<div
|
|
3301
|
+
aria-hidden="${ifDefined_js.ifDefined(isHidden ? "true" : void 0)}"
|
|
3302
|
+
class="${this.overlayClasses}"
|
|
3303
|
+
data-sp-modal-overlay
|
|
3304
|
+
@click="${(event) => {
|
|
3305
|
+
if (event.target === event.currentTarget) {
|
|
3306
|
+
this.close();
|
|
3307
|
+
}
|
|
3308
|
+
}}"
|
|
3309
|
+
>
|
|
3310
|
+
<div
|
|
3311
|
+
aria-describedby="${ifDefined_js.ifDefined(this.forwardedAriaDescribedBy)}"
|
|
3312
|
+
aria-hidden="${ifDefined_js.ifDefined(isHidden ? "true" : void 0)}"
|
|
3313
|
+
aria-label="${ifDefined_js.ifDefined(this.forwardedAriaLabel)}"
|
|
3314
|
+
aria-labelledby="${ifDefined_js.ifDefined(this.forwardedAriaLabelledBy)}"
|
|
3315
|
+
aria-modal="true"
|
|
3316
|
+
class="${this.modalClasses}"
|
|
3317
|
+
data-sp-modal-native
|
|
3318
|
+
id="${ifDefined_js.ifDefined(this.id || void 0)}"
|
|
3319
|
+
role="dialog"
|
|
3320
|
+
tabindex="-1"
|
|
3321
|
+
title="${ifDefined_js.ifDefined(this.title || void 0)}"
|
|
3322
|
+
>
|
|
3323
|
+
${this.hasProjectedContent ? this.projectedContent : lit.nothing}
|
|
3324
|
+
</div>
|
|
3325
|
+
</div>`;
|
|
3326
|
+
}
|
|
3327
|
+
};
|
|
3328
|
+
SpectreModalElement.properties = {
|
|
3329
|
+
fullWidth: { attribute: "full-width", type: Boolean, reflect: true },
|
|
3330
|
+
open: { type: Boolean, reflect: true }
|
|
3331
|
+
};
|
|
3332
|
+
function defineSpectreModal(tagName = "sp-modal") {
|
|
3333
|
+
const existingElement = customElements.get(tagName);
|
|
3334
|
+
if (existingElement) {
|
|
3335
|
+
return existingElement;
|
|
3336
|
+
}
|
|
3337
|
+
customElements.define(tagName, SpectreModalElement);
|
|
3338
|
+
return SpectreModalElement;
|
|
3339
|
+
}
|
|
3340
|
+
var SpectreNavElement = class extends SpectreProjectableElement {
|
|
3341
|
+
constructor() {
|
|
3342
|
+
super(...arguments);
|
|
3343
|
+
this.bordered = false;
|
|
3344
|
+
this.fullWidth = false;
|
|
3345
|
+
this.sticky = false;
|
|
3346
|
+
}
|
|
3347
|
+
get id() {
|
|
3348
|
+
return super.id;
|
|
3349
|
+
}
|
|
3350
|
+
set id(value) {
|
|
3351
|
+
super.id = value;
|
|
3352
|
+
}
|
|
3353
|
+
get title() {
|
|
3354
|
+
return super.title;
|
|
3355
|
+
}
|
|
3356
|
+
set title(value) {
|
|
3357
|
+
super.title = value;
|
|
3358
|
+
}
|
|
3359
|
+
getContentContainer() {
|
|
3360
|
+
return this.querySelector("[data-sp-nav-native]");
|
|
3361
|
+
}
|
|
3362
|
+
isInternalNode(node) {
|
|
3363
|
+
if (node.nodeType !== Node.ELEMENT_NODE) {
|
|
3364
|
+
return false;
|
|
3365
|
+
}
|
|
3366
|
+
const el = node;
|
|
3367
|
+
return el.hasAttribute("data-sp-nav-native");
|
|
3368
|
+
}
|
|
3369
|
+
willUpdate(changedProperties) {
|
|
3370
|
+
if (changedProperties.has("bordered") && this.bordered == null) {
|
|
3371
|
+
this.bordered = false;
|
|
3372
|
+
}
|
|
3373
|
+
if (changedProperties.has("fullWidth") && this.fullWidth == null) {
|
|
3374
|
+
this.fullWidth = false;
|
|
3375
|
+
}
|
|
3376
|
+
if (changedProperties.has("sticky") && this.sticky == null) {
|
|
3377
|
+
this.sticky = false;
|
|
3378
|
+
}
|
|
3379
|
+
}
|
|
3380
|
+
get navClasses() {
|
|
3381
|
+
return spectreUi.getNavClasses({
|
|
3382
|
+
bordered: this.bordered ?? false,
|
|
3383
|
+
fullWidth: this.fullWidth ?? false,
|
|
3384
|
+
sticky: this.sticky ?? false
|
|
3385
|
+
});
|
|
3386
|
+
}
|
|
3387
|
+
render() {
|
|
3388
|
+
return lit.html`<nav
|
|
3389
|
+
aria-label="${ifDefined_js.ifDefined(this.forwardedAriaLabel)}"
|
|
3390
|
+
class="${this.navClasses}"
|
|
3391
|
+
data-sp-nav-native
|
|
3392
|
+
id="${ifDefined_js.ifDefined(this.id || void 0)}"
|
|
3393
|
+
title="${ifDefined_js.ifDefined(this.title || void 0)}"
|
|
3394
|
+
>
|
|
3395
|
+
${this.hasProjectedContent ? this.projectedContent : lit.nothing}
|
|
3396
|
+
</nav>`;
|
|
3397
|
+
}
|
|
3398
|
+
};
|
|
3399
|
+
SpectreNavElement.properties = {
|
|
3400
|
+
bordered: { type: Boolean, reflect: true },
|
|
3401
|
+
fullWidth: { attribute: "full-width", type: Boolean, reflect: true },
|
|
3402
|
+
sticky: { type: Boolean, reflect: true }
|
|
3403
|
+
};
|
|
3404
|
+
function defineSpectreNav(tagName = "sp-nav") {
|
|
3405
|
+
const existingElement = customElements.get(tagName);
|
|
3406
|
+
if (existingElement) {
|
|
3407
|
+
return existingElement;
|
|
3408
|
+
}
|
|
3409
|
+
customElements.define(tagName, SpectreNavElement);
|
|
3410
|
+
return SpectreNavElement;
|
|
3411
|
+
}
|
|
3412
|
+
var SpectreSidebarElement = class extends SpectreProjectableElement {
|
|
3413
|
+
constructor() {
|
|
3414
|
+
super(...arguments);
|
|
3415
|
+
this.bordered = false;
|
|
3416
|
+
this.open = false;
|
|
3417
|
+
this.toggleLabel = "Toggle sidebar";
|
|
3418
|
+
this.handleDocumentKeydown = (event) => {
|
|
3419
|
+
if (event.key === "Escape" && this.open) {
|
|
3420
|
+
this.close();
|
|
3421
|
+
}
|
|
3422
|
+
};
|
|
3423
|
+
}
|
|
3424
|
+
get id() {
|
|
3425
|
+
return super.id;
|
|
3426
|
+
}
|
|
3427
|
+
set id(value) {
|
|
3428
|
+
super.id = value;
|
|
3429
|
+
}
|
|
3430
|
+
get title() {
|
|
3431
|
+
return super.title;
|
|
3432
|
+
}
|
|
3433
|
+
set title(value) {
|
|
3434
|
+
super.title = value;
|
|
3435
|
+
}
|
|
3436
|
+
getContentContainer() {
|
|
3437
|
+
return this.querySelector("[data-sp-sidebar-native]");
|
|
3438
|
+
}
|
|
3439
|
+
isInternalNode(node) {
|
|
3440
|
+
if (node.nodeType !== Node.ELEMENT_NODE) {
|
|
3441
|
+
return false;
|
|
3442
|
+
}
|
|
3443
|
+
const el = node;
|
|
3444
|
+
return el.hasAttribute("data-sp-sidebar-native") || el.hasAttribute("data-sp-sidebar-toggle") || el.hasAttribute("data-sp-sidebar-backdrop");
|
|
3445
|
+
}
|
|
3446
|
+
willUpdate(changedProperties) {
|
|
3447
|
+
if (changedProperties.has("bordered") && this.bordered == null) {
|
|
3448
|
+
this.bordered = false;
|
|
3449
|
+
}
|
|
3450
|
+
if (changedProperties.has("open") && this.open == null) {
|
|
3451
|
+
this.open = false;
|
|
3452
|
+
}
|
|
3453
|
+
if (changedProperties.has("toggleLabel") && !this.toggleLabel) {
|
|
3454
|
+
this.toggleLabel = "Toggle sidebar";
|
|
3455
|
+
}
|
|
3456
|
+
if (changedProperties.has("open")) {
|
|
3457
|
+
HTMLElement.prototype.setAttribute.call(
|
|
3458
|
+
this,
|
|
3459
|
+
"data-sidebar-open",
|
|
3460
|
+
this.open ? "true" : "false"
|
|
3461
|
+
);
|
|
3462
|
+
}
|
|
3463
|
+
}
|
|
3464
|
+
connectedCallback() {
|
|
3465
|
+
super.connectedCallback();
|
|
3466
|
+
HTMLElement.prototype.setAttribute.call(
|
|
3467
|
+
this,
|
|
3468
|
+
"data-sidebar-open",
|
|
3469
|
+
this.open ? "true" : "false"
|
|
3470
|
+
);
|
|
3471
|
+
document.addEventListener("keydown", this.handleDocumentKeydown);
|
|
3472
|
+
}
|
|
3473
|
+
disconnectedCallback() {
|
|
3474
|
+
document.removeEventListener("keydown", this.handleDocumentKeydown);
|
|
3475
|
+
super.disconnectedCallback();
|
|
3476
|
+
}
|
|
3477
|
+
toggle() {
|
|
3478
|
+
if (this.open) {
|
|
3479
|
+
this.close();
|
|
3480
|
+
} else {
|
|
3481
|
+
this.openSidebar();
|
|
3482
|
+
}
|
|
3483
|
+
}
|
|
3484
|
+
openSidebar() {
|
|
3485
|
+
if (this.open) {
|
|
3486
|
+
return;
|
|
3487
|
+
}
|
|
3488
|
+
this.open = true;
|
|
3489
|
+
this.dispatchEvent(new CustomEvent("sp-open", { bubbles: true }));
|
|
3490
|
+
}
|
|
3491
|
+
close() {
|
|
3492
|
+
if (!this.open) {
|
|
3493
|
+
return;
|
|
3494
|
+
}
|
|
3495
|
+
this.open = false;
|
|
3496
|
+
this.dispatchEvent(new CustomEvent("sp-close", { bubbles: true }));
|
|
3497
|
+
}
|
|
3498
|
+
get sidebarClasses() {
|
|
3499
|
+
return spectreUi.getSidebarClasses({ bordered: this.bordered ?? false });
|
|
3500
|
+
}
|
|
3501
|
+
render() {
|
|
3502
|
+
return lit.html`<button
|
|
3503
|
+
aria-expanded="${this.open ? "true" : "false"}"
|
|
3504
|
+
aria-label="${ifDefined_js.ifDefined(this.toggleLabel)}"
|
|
3505
|
+
class="${spectreUi.getSidebarToggleClasses()}"
|
|
3506
|
+
data-sp-sidebar-toggle
|
|
3507
|
+
type="button"
|
|
3508
|
+
@click="${() => this.toggle()}"
|
|
3509
|
+
>
|
|
3510
|
+
☰
|
|
3511
|
+
</button>
|
|
3512
|
+
<div
|
|
3513
|
+
class="${spectreUi.getSidebarBackdropClasses()}"
|
|
3514
|
+
data-sp-sidebar-backdrop
|
|
3515
|
+
@click="${() => this.close()}"
|
|
3516
|
+
></div>
|
|
3517
|
+
<aside
|
|
3518
|
+
aria-label="${ifDefined_js.ifDefined(this.forwardedAriaLabel)}"
|
|
3519
|
+
class="${this.sidebarClasses}"
|
|
3520
|
+
data-sp-sidebar-native
|
|
3521
|
+
id="${ifDefined_js.ifDefined(this.id || void 0)}"
|
|
3522
|
+
title="${ifDefined_js.ifDefined(this.title || void 0)}"
|
|
3523
|
+
>
|
|
3524
|
+
${this.hasProjectedContent ? this.projectedContent : lit.nothing}
|
|
3525
|
+
</aside>`;
|
|
3526
|
+
}
|
|
3527
|
+
};
|
|
3528
|
+
SpectreSidebarElement.properties = {
|
|
3529
|
+
bordered: { type: Boolean, reflect: true },
|
|
3530
|
+
open: { type: Boolean, reflect: false },
|
|
3531
|
+
toggleLabel: { attribute: "toggle-label", type: String }
|
|
3532
|
+
};
|
|
3533
|
+
function defineSpectreSidebar(tagName = "sp-sidebar") {
|
|
3534
|
+
const existingElement = customElements.get(tagName);
|
|
3535
|
+
if (existingElement) {
|
|
3536
|
+
return existingElement;
|
|
3537
|
+
}
|
|
3538
|
+
customElements.define(tagName, SpectreSidebarElement);
|
|
3539
|
+
return SpectreSidebarElement;
|
|
3540
|
+
}
|
|
3541
|
+
var SpectreToastElement = class extends SpectreBaseElement {
|
|
3542
|
+
constructor() {
|
|
3543
|
+
super(...arguments);
|
|
3544
|
+
this.dismissed = false;
|
|
3545
|
+
this.fullWidth = false;
|
|
3546
|
+
this.variant = "info";
|
|
3547
|
+
this.iconContent = [];
|
|
3548
|
+
this.bodyContent = [];
|
|
3549
|
+
}
|
|
3550
|
+
get id() {
|
|
3551
|
+
return super.id;
|
|
3552
|
+
}
|
|
3553
|
+
set id(value) {
|
|
3554
|
+
super.id = value;
|
|
3555
|
+
}
|
|
3556
|
+
get title() {
|
|
3557
|
+
return super.title;
|
|
3558
|
+
}
|
|
3559
|
+
set title(value) {
|
|
3560
|
+
super.title = value;
|
|
3561
|
+
}
|
|
3562
|
+
isInternalNode(node) {
|
|
3563
|
+
if (node.nodeType !== Node.ELEMENT_NODE) {
|
|
3564
|
+
return false;
|
|
3565
|
+
}
|
|
3566
|
+
const el = node;
|
|
3567
|
+
return el.hasAttribute("data-sp-toast-native") || el.hasAttribute("data-sp-toast-icon");
|
|
3568
|
+
}
|
|
3569
|
+
syncProjectedContent() {
|
|
3570
|
+
const nextIconContent = [];
|
|
3571
|
+
const nextBodyContent = [];
|
|
3572
|
+
this.childNodes.forEach((node) => {
|
|
3573
|
+
if (this.isInternalNode(node)) {
|
|
3574
|
+
return;
|
|
3575
|
+
}
|
|
3576
|
+
const isIconSlot = node.nodeType === Node.ELEMENT_NODE && node.getAttribute("slot") === "icon";
|
|
3577
|
+
if (isIconSlot) {
|
|
3578
|
+
nextIconContent.push(node);
|
|
3579
|
+
} else {
|
|
3580
|
+
nextBodyContent.push(node);
|
|
3581
|
+
}
|
|
3582
|
+
});
|
|
3583
|
+
const changed = nextIconContent.length !== this.iconContent.length || nextIconContent.some((n, i) => n !== this.iconContent[i]) || nextBodyContent.length !== this.bodyContent.length || nextBodyContent.some((n, i) => n !== this.bodyContent[i]);
|
|
3584
|
+
if (changed) {
|
|
3585
|
+
this.iconContent = nextIconContent;
|
|
3586
|
+
this.bodyContent = nextBodyContent;
|
|
3587
|
+
}
|
|
3588
|
+
return changed;
|
|
3589
|
+
}
|
|
3590
|
+
get hasIconContent() {
|
|
3591
|
+
return hasMeaningfulContent(this.iconContent);
|
|
3592
|
+
}
|
|
3593
|
+
get hasBodyContent() {
|
|
3594
|
+
return hasMeaningfulContent(this.bodyContent);
|
|
3595
|
+
}
|
|
3596
|
+
connectedCallback() {
|
|
3597
|
+
super.connectedCallback();
|
|
3598
|
+
this.syncProjectedContent();
|
|
3599
|
+
this.startContentObserver();
|
|
3600
|
+
}
|
|
3601
|
+
disconnectedCallback() {
|
|
3602
|
+
this.stopContentObserver();
|
|
3603
|
+
this.clearAutoDismissTimer();
|
|
3604
|
+
super.disconnectedCallback();
|
|
3605
|
+
}
|
|
3606
|
+
update(changedProperties) {
|
|
3607
|
+
this.stopContentObserver();
|
|
3608
|
+
super.update(changedProperties);
|
|
3609
|
+
this.startContentObserver();
|
|
3610
|
+
}
|
|
3611
|
+
startContentObserver() {
|
|
3612
|
+
if (this.contentObserver) {
|
|
3613
|
+
return;
|
|
3614
|
+
}
|
|
3615
|
+
this.contentObserver = new MutationObserver(() => {
|
|
3616
|
+
if (this.syncProjectedContent()) {
|
|
3617
|
+
this.requestUpdate();
|
|
3618
|
+
}
|
|
3619
|
+
});
|
|
3620
|
+
this.contentObserver.observe(this, { childList: true });
|
|
3621
|
+
}
|
|
3622
|
+
stopContentObserver() {
|
|
3623
|
+
this.contentObserver?.disconnect();
|
|
3624
|
+
this.contentObserver = void 0;
|
|
3625
|
+
}
|
|
3626
|
+
willUpdate(changedProperties) {
|
|
3627
|
+
if (changedProperties.has("dismissed") && this.dismissed == null) {
|
|
3628
|
+
this.dismissed = false;
|
|
3629
|
+
}
|
|
3630
|
+
if (changedProperties.has("fullWidth") && this.fullWidth == null) {
|
|
3631
|
+
this.fullWidth = false;
|
|
3632
|
+
}
|
|
3633
|
+
if (changedProperties.has("variant") && (this.variant == null || !isToastVariant(this.variant))) {
|
|
3634
|
+
this.variant = "info";
|
|
3635
|
+
}
|
|
3636
|
+
if (changedProperties.has("autoDismiss")) {
|
|
3637
|
+
this.autoDismiss = normalizeInt(this.autoDismiss, void 0, 0);
|
|
3638
|
+
}
|
|
3639
|
+
}
|
|
3640
|
+
updated(changedProperties) {
|
|
3641
|
+
super.updated(changedProperties);
|
|
3642
|
+
if (changedProperties.has("dismissed") || changedProperties.has("autoDismiss")) {
|
|
3643
|
+
this.clearAutoDismissTimer();
|
|
3644
|
+
if (!this.dismissed && this.autoDismiss) {
|
|
3645
|
+
this.autoDismissTimer = setTimeout(() => {
|
|
3646
|
+
this.dismiss();
|
|
3647
|
+
}, this.autoDismiss);
|
|
3648
|
+
}
|
|
3649
|
+
}
|
|
3650
|
+
}
|
|
3651
|
+
clearAutoDismissTimer() {
|
|
3652
|
+
if (this.autoDismissTimer) {
|
|
3653
|
+
clearTimeout(this.autoDismissTimer);
|
|
3654
|
+
this.autoDismissTimer = void 0;
|
|
3655
|
+
}
|
|
3656
|
+
}
|
|
3657
|
+
show() {
|
|
3658
|
+
if (!this.dismissed) {
|
|
3659
|
+
return;
|
|
3660
|
+
}
|
|
3661
|
+
this.dismissed = false;
|
|
3662
|
+
this.dispatchEvent(new CustomEvent("sp-show", { bubbles: true }));
|
|
3663
|
+
}
|
|
3664
|
+
dismiss() {
|
|
3665
|
+
if (this.dismissed) {
|
|
3666
|
+
return;
|
|
3667
|
+
}
|
|
3668
|
+
this.dismissed = true;
|
|
3669
|
+
this.dispatchEvent(new CustomEvent("sp-dismiss", { bubbles: true }));
|
|
3670
|
+
}
|
|
3671
|
+
get toastClasses() {
|
|
3672
|
+
return spectreUi.getToastClasses({
|
|
3673
|
+
variant: this.variant,
|
|
3674
|
+
dismissed: this.dismissed ?? false,
|
|
3675
|
+
fullWidth: this.fullWidth ?? false
|
|
3676
|
+
});
|
|
3677
|
+
}
|
|
3678
|
+
get iconClasses() {
|
|
3679
|
+
return spectreUi.getToastIconClasses({ variant: this.variant });
|
|
3680
|
+
}
|
|
3681
|
+
render() {
|
|
3682
|
+
return lit.html`<div
|
|
3683
|
+
aria-atomic="true"
|
|
3684
|
+
aria-label="${ifDefined_js.ifDefined(this.forwardedAriaLabel)}"
|
|
3685
|
+
aria-live="polite"
|
|
3686
|
+
class="${this.toastClasses}"
|
|
3687
|
+
data-sp-toast-native
|
|
3688
|
+
id="${ifDefined_js.ifDefined(this.id || void 0)}"
|
|
3689
|
+
role="status"
|
|
3690
|
+
title="${ifDefined_js.ifDefined(this.title || void 0)}"
|
|
3691
|
+
>
|
|
3692
|
+
${this.hasIconContent ? lit.html`<div class="${this.iconClasses}" data-sp-toast-icon>
|
|
3693
|
+
${this.iconContent}
|
|
3694
|
+
</div>` : lit.nothing}
|
|
3695
|
+
${this.hasBodyContent ? this.bodyContent : lit.nothing}
|
|
3696
|
+
</div>`;
|
|
3697
|
+
}
|
|
3698
|
+
};
|
|
3699
|
+
SpectreToastElement.properties = {
|
|
3700
|
+
autoDismiss: { attribute: "auto-dismiss", type: Number },
|
|
3701
|
+
dismissed: { type: Boolean, reflect: true },
|
|
3702
|
+
fullWidth: { attribute: "full-width", type: Boolean, reflect: true },
|
|
3703
|
+
variant: { type: String, reflect: true }
|
|
3704
|
+
};
|
|
3705
|
+
function defineSpectreToast(tagName = "sp-toast") {
|
|
3706
|
+
const existingElement = customElements.get(tagName);
|
|
3707
|
+
if (existingElement) {
|
|
3708
|
+
return existingElement;
|
|
3709
|
+
}
|
|
3710
|
+
customElements.define(tagName, SpectreToastElement);
|
|
3711
|
+
return SpectreToastElement;
|
|
3712
|
+
}
|
|
3713
|
+
var SpectreTooltipElement = class extends SpectreBaseElement {
|
|
3714
|
+
constructor() {
|
|
3715
|
+
super(...arguments);
|
|
3716
|
+
this.placement = "top";
|
|
3717
|
+
this.visible = false;
|
|
3718
|
+
this.triggerContent = [];
|
|
3719
|
+
this.tooltipContent = [];
|
|
3720
|
+
}
|
|
3721
|
+
get id() {
|
|
3722
|
+
return super.id;
|
|
3723
|
+
}
|
|
3724
|
+
set id(value) {
|
|
3725
|
+
super.id = value;
|
|
3726
|
+
}
|
|
3727
|
+
get title() {
|
|
3728
|
+
return super.title;
|
|
3729
|
+
}
|
|
3730
|
+
set title(value) {
|
|
3731
|
+
super.title = value;
|
|
3732
|
+
}
|
|
3733
|
+
isInternalNode(node) {
|
|
3734
|
+
if (node.nodeType !== Node.ELEMENT_NODE) {
|
|
3735
|
+
return false;
|
|
3736
|
+
}
|
|
3737
|
+
const el = node;
|
|
3738
|
+
return el.hasAttribute("data-sp-tooltip-native") || el.hasAttribute("data-sp-tooltip-trigger");
|
|
3739
|
+
}
|
|
3740
|
+
syncProjectedContent() {
|
|
3741
|
+
const nextTooltipContent = [];
|
|
3742
|
+
const nextTriggerContent = [];
|
|
3743
|
+
this.childNodes.forEach((node) => {
|
|
3744
|
+
if (this.isInternalNode(node)) {
|
|
3745
|
+
return;
|
|
3746
|
+
}
|
|
3747
|
+
const isTooltipSlot = node.nodeType === Node.ELEMENT_NODE && node.getAttribute("slot") === "tooltip";
|
|
3748
|
+
if (isTooltipSlot) {
|
|
3749
|
+
nextTooltipContent.push(node);
|
|
3750
|
+
} else {
|
|
3751
|
+
nextTriggerContent.push(node);
|
|
3752
|
+
}
|
|
3753
|
+
});
|
|
3754
|
+
const changed = nextTooltipContent.length !== this.tooltipContent.length || nextTooltipContent.some((n, i) => n !== this.tooltipContent[i]) || nextTriggerContent.length !== this.triggerContent.length || nextTriggerContent.some((n, i) => n !== this.triggerContent[i]);
|
|
3755
|
+
if (changed) {
|
|
3756
|
+
this.tooltipContent = nextTooltipContent;
|
|
3757
|
+
this.triggerContent = nextTriggerContent;
|
|
3758
|
+
}
|
|
3759
|
+
return changed;
|
|
3760
|
+
}
|
|
3761
|
+
get hasTooltipContent() {
|
|
3762
|
+
return hasMeaningfulContent(this.tooltipContent);
|
|
3763
|
+
}
|
|
3764
|
+
connectedCallback() {
|
|
3765
|
+
var _a, _b;
|
|
3766
|
+
super.connectedCallback();
|
|
3767
|
+
this.syncProjectedContent();
|
|
3768
|
+
this.startContentObserver();
|
|
3769
|
+
(_a = this.style).position || (_a.position = "relative");
|
|
3770
|
+
(_b = this.style).display || (_b.display = "inline-block");
|
|
3771
|
+
}
|
|
3772
|
+
disconnectedCallback() {
|
|
3773
|
+
this.stopContentObserver();
|
|
3774
|
+
super.disconnectedCallback();
|
|
3775
|
+
}
|
|
3776
|
+
update(changedProperties) {
|
|
3777
|
+
this.stopContentObserver();
|
|
3778
|
+
super.update(changedProperties);
|
|
3779
|
+
this.startContentObserver();
|
|
3780
|
+
}
|
|
3781
|
+
startContentObserver() {
|
|
3782
|
+
if (this.contentObserver) {
|
|
3783
|
+
return;
|
|
3784
|
+
}
|
|
3785
|
+
this.contentObserver = new MutationObserver(() => {
|
|
3786
|
+
if (this.syncProjectedContent()) {
|
|
3787
|
+
this.requestUpdate();
|
|
3788
|
+
}
|
|
3789
|
+
});
|
|
3790
|
+
this.contentObserver.observe(this, { childList: true });
|
|
3791
|
+
}
|
|
3792
|
+
stopContentObserver() {
|
|
3793
|
+
this.contentObserver?.disconnect();
|
|
3794
|
+
this.contentObserver = void 0;
|
|
3795
|
+
}
|
|
3796
|
+
willUpdate(changedProperties) {
|
|
3797
|
+
if (changedProperties.has("placement") && (this.placement == null || !isTooltipPlacement(this.placement))) {
|
|
3798
|
+
this.placement = "top";
|
|
3799
|
+
}
|
|
3800
|
+
if (changedProperties.has("visible") && this.visible == null) {
|
|
3801
|
+
this.visible = false;
|
|
3802
|
+
}
|
|
3803
|
+
}
|
|
3804
|
+
show() {
|
|
3805
|
+
if (this.visible) {
|
|
3806
|
+
return;
|
|
3807
|
+
}
|
|
3808
|
+
this.visible = true;
|
|
3809
|
+
this.dispatchEvent(new CustomEvent("sp-show", { bubbles: true }));
|
|
3810
|
+
}
|
|
3811
|
+
hide() {
|
|
3812
|
+
if (!this.visible) {
|
|
3813
|
+
return;
|
|
3814
|
+
}
|
|
3815
|
+
this.visible = false;
|
|
3816
|
+
this.dispatchEvent(new CustomEvent("sp-hide", { bubbles: true }));
|
|
3817
|
+
}
|
|
3818
|
+
get tooltipClasses() {
|
|
3819
|
+
return spectreUi.getTooltipClasses({
|
|
3820
|
+
placement: this.placement,
|
|
3821
|
+
visible: this.visible ?? false
|
|
3822
|
+
});
|
|
3823
|
+
}
|
|
3824
|
+
render() {
|
|
3825
|
+
return lit.html`<span
|
|
3826
|
+
data-sp-tooltip-trigger
|
|
3827
|
+
@focusin="${() => this.show()}"
|
|
3828
|
+
@focusout="${() => this.hide()}"
|
|
3829
|
+
@mouseenter="${() => this.show()}"
|
|
3830
|
+
@mouseleave="${() => this.hide()}"
|
|
3831
|
+
>
|
|
3832
|
+
${this.triggerContent}
|
|
3833
|
+
</span>
|
|
3834
|
+
<span
|
|
3835
|
+
aria-label="${ifDefined_js.ifDefined(this.forwardedAriaLabel)}"
|
|
3836
|
+
class="${this.tooltipClasses}"
|
|
3837
|
+
data-sp-tooltip-native
|
|
3838
|
+
id="${ifDefined_js.ifDefined(this.id || void 0)}"
|
|
3839
|
+
role="tooltip"
|
|
3840
|
+
title="${ifDefined_js.ifDefined(this.title || void 0)}"
|
|
3841
|
+
>
|
|
3842
|
+
${this.hasTooltipContent ? this.tooltipContent : lit.nothing}
|
|
3843
|
+
</span>`;
|
|
3844
|
+
}
|
|
3845
|
+
};
|
|
3846
|
+
SpectreTooltipElement.properties = {
|
|
3847
|
+
placement: { type: String, reflect: true },
|
|
3848
|
+
visible: { type: Boolean, reflect: true }
|
|
3849
|
+
};
|
|
3850
|
+
function defineSpectreTooltip(tagName = "sp-tooltip") {
|
|
3851
|
+
const existingElement = customElements.get(tagName);
|
|
3852
|
+
if (existingElement) {
|
|
3853
|
+
return existingElement;
|
|
3854
|
+
}
|
|
3855
|
+
customElements.define(tagName, SpectreTooltipElement);
|
|
3856
|
+
return SpectreTooltipElement;
|
|
3857
|
+
}
|
|
2889
3858
|
|
|
2890
3859
|
// src/index.ts
|
|
2891
3860
|
function defineSpectreComponents() {
|
|
@@ -2911,6 +3880,13 @@ function defineSpectreComponents() {
|
|
|
2911
3880
|
defineSpectreGrid();
|
|
2912
3881
|
defineSpectreSection();
|
|
2913
3882
|
defineSpectreStack();
|
|
3883
|
+
defineSpectreDropdown();
|
|
3884
|
+
defineSpectreFooter();
|
|
3885
|
+
defineSpectreModal();
|
|
3886
|
+
defineSpectreNav();
|
|
3887
|
+
defineSpectreSidebar();
|
|
3888
|
+
defineSpectreToast();
|
|
3889
|
+
defineSpectreTooltip();
|
|
2914
3890
|
}
|
|
2915
3891
|
|
|
2916
3892
|
exports.SpectreAlertElement = SpectreAlertElement;
|
|
@@ -2920,21 +3896,28 @@ exports.SpectreButtonElement = SpectreButtonElement;
|
|
|
2920
3896
|
exports.SpectreCardElement = SpectreCardElement;
|
|
2921
3897
|
exports.SpectreCheckboxElement = SpectreCheckboxElement;
|
|
2922
3898
|
exports.SpectreContainerElement = SpectreContainerElement;
|
|
3899
|
+
exports.SpectreDropdownElement = SpectreDropdownElement;
|
|
2923
3900
|
exports.SpectreFieldsetElement = SpectreFieldsetElement;
|
|
3901
|
+
exports.SpectreFooterElement = SpectreFooterElement;
|
|
2924
3902
|
exports.SpectreGridElement = SpectreGridElement;
|
|
2925
3903
|
exports.SpectreIconBoxElement = SpectreIconBoxElement;
|
|
2926
3904
|
exports.SpectreInputElement = SpectreInputElement;
|
|
2927
3905
|
exports.SpectreLabelElement = SpectreLabelElement;
|
|
3906
|
+
exports.SpectreModalElement = SpectreModalElement;
|
|
3907
|
+
exports.SpectreNavElement = SpectreNavElement;
|
|
2928
3908
|
exports.SpectrePricingCardElement = SpectrePricingCardElement;
|
|
2929
3909
|
exports.SpectreRadioElement = SpectreRadioElement;
|
|
2930
3910
|
exports.SpectreRatingElement = SpectreRatingElement;
|
|
2931
3911
|
exports.SpectreSectionElement = SpectreSectionElement;
|
|
2932
3912
|
exports.SpectreSelectElement = SpectreSelectElement;
|
|
3913
|
+
exports.SpectreSidebarElement = SpectreSidebarElement;
|
|
2933
3914
|
exports.SpectreSpinnerElement = SpectreSpinnerElement;
|
|
2934
3915
|
exports.SpectreStackElement = SpectreStackElement;
|
|
2935
3916
|
exports.SpectreTagElement = SpectreTagElement;
|
|
2936
3917
|
exports.SpectreTestimonialElement = SpectreTestimonialElement;
|
|
2937
3918
|
exports.SpectreTextareaElement = SpectreTextareaElement;
|
|
3919
|
+
exports.SpectreToastElement = SpectreToastElement;
|
|
3920
|
+
exports.SpectreTooltipElement = SpectreTooltipElement;
|
|
2938
3921
|
exports.defineSpectreAlert = defineSpectreAlert;
|
|
2939
3922
|
exports.defineSpectreAvatar = defineSpectreAvatar;
|
|
2940
3923
|
exports.defineSpectreBadge = defineSpectreBadge;
|
|
@@ -2943,21 +3926,28 @@ exports.defineSpectreCard = defineSpectreCard;
|
|
|
2943
3926
|
exports.defineSpectreCheckbox = defineSpectreCheckbox;
|
|
2944
3927
|
exports.defineSpectreComponents = defineSpectreComponents;
|
|
2945
3928
|
exports.defineSpectreContainer = defineSpectreContainer;
|
|
3929
|
+
exports.defineSpectreDropdown = defineSpectreDropdown;
|
|
2946
3930
|
exports.defineSpectreFieldset = defineSpectreFieldset;
|
|
3931
|
+
exports.defineSpectreFooter = defineSpectreFooter;
|
|
2947
3932
|
exports.defineSpectreGrid = defineSpectreGrid;
|
|
2948
3933
|
exports.defineSpectreIconBox = defineSpectreIconBox;
|
|
2949
3934
|
exports.defineSpectreInput = defineSpectreInput;
|
|
2950
3935
|
exports.defineSpectreLabel = defineSpectreLabel;
|
|
3936
|
+
exports.defineSpectreModal = defineSpectreModal;
|
|
3937
|
+
exports.defineSpectreNav = defineSpectreNav;
|
|
2951
3938
|
exports.defineSpectrePricingCard = defineSpectrePricingCard;
|
|
2952
3939
|
exports.defineSpectreRadio = defineSpectreRadio;
|
|
2953
3940
|
exports.defineSpectreRating = defineSpectreRating;
|
|
2954
3941
|
exports.defineSpectreSection = defineSpectreSection;
|
|
2955
3942
|
exports.defineSpectreSelect = defineSpectreSelect;
|
|
3943
|
+
exports.defineSpectreSidebar = defineSpectreSidebar;
|
|
2956
3944
|
exports.defineSpectreSpinner = defineSpectreSpinner;
|
|
2957
3945
|
exports.defineSpectreStack = defineSpectreStack;
|
|
2958
3946
|
exports.defineSpectreTag = defineSpectreTag;
|
|
2959
3947
|
exports.defineSpectreTestimonial = defineSpectreTestimonial;
|
|
2960
3948
|
exports.defineSpectreTextarea = defineSpectreTextarea;
|
|
3949
|
+
exports.defineSpectreToast = defineSpectreToast;
|
|
3950
|
+
exports.defineSpectreTooltip = defineSpectreTooltip;
|
|
2961
3951
|
exports.spectreAlertSizes = spectreInputSizes;
|
|
2962
3952
|
exports.spectreAlertVariants = spectreAlertVariants;
|
|
2963
3953
|
exports.spectreAvatarShapes = spectreAvatarShapes;
|
|
@@ -2969,6 +3959,7 @@ exports.spectreButtonTypes = spectreButtonTypes;
|
|
|
2969
3959
|
exports.spectreButtonVariants = spectreButtonVariants;
|
|
2970
3960
|
exports.spectreCardVariants = spectreCardVariants;
|
|
2971
3961
|
exports.spectreContainerMaxWidths = spectreContainerMaxWidths;
|
|
3962
|
+
exports.spectreDropdownPlacements = spectreDropdownPlacements;
|
|
2972
3963
|
exports.spectreGridColumns = spectreGridColumns;
|
|
2973
3964
|
exports.spectreGridGaps = spectreGridGaps;
|
|
2974
3965
|
exports.spectreIconBoxSizes = spectreInputSizes;
|
|
@@ -2984,5 +3975,7 @@ exports.spectreStackDirections = spectreStackDirections;
|
|
|
2984
3975
|
exports.spectreTagSizes = spectreInputSizes;
|
|
2985
3976
|
exports.spectreTagVariants = spectreTagVariants;
|
|
2986
3977
|
exports.spectreTestimonialVariants = spectreTestimonialVariants;
|
|
3978
|
+
exports.spectreToastVariants = spectreToastVariants;
|
|
3979
|
+
exports.spectreTooltipPlacements = spectreTooltipPlacements;
|
|
2987
3980
|
//# sourceMappingURL=index.cjs.map
|
|
2988
3981
|
//# sourceMappingURL=index.cjs.map
|