@idds/js 1.2.0 → 1.2.2
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/dist/index.iife.js +98 -37
- package/dist/index.js +98 -37
- package/package.json +1 -1
package/dist/index.iife.js
CHANGED
|
@@ -2991,23 +2991,29 @@ var InaUI = (() => {
|
|
|
2991
2991
|
const isSelected = normSelected.includes(itemValue) || showCustomization && item.textContent.trim() === customizationLabel && normSelected.some(
|
|
2992
2992
|
(val) => !Array.from(items).filter((i) => i.textContent.trim() !== customizationLabel).map((i) => i.getAttribute("data-value")).includes(val) && val !== ""
|
|
2993
2993
|
);
|
|
2994
|
+
const isDisabled = item.hasAttribute("disabled");
|
|
2994
2995
|
if (isSelected) {
|
|
2995
2996
|
item.classList.add(`${PREFIX4}-chip__item--selected`);
|
|
2996
2997
|
} else {
|
|
2997
2998
|
item.classList.remove(`${PREFIX4}-chip__item--selected`);
|
|
2998
2999
|
}
|
|
2999
|
-
|
|
3000
|
+
if (isDisabled) {
|
|
3001
|
+
item.classList.add(`${PREFIX4}-chip__item--disabled`);
|
|
3002
|
+
}
|
|
3003
|
+
item.setAttribute(
|
|
3004
|
+
"tabindex",
|
|
3005
|
+
index2 === focusedIndex && !isDisabled ? "0" : "-1"
|
|
3006
|
+
);
|
|
3000
3007
|
});
|
|
3001
3008
|
if (showCustomization) {
|
|
3002
|
-
const
|
|
3009
|
+
const isToggleBtn2 = (i) => i.hasAttribute("data-customization-toggle") || i.textContent.trim() === customizationLabel;
|
|
3010
|
+
const standardValues = Array.from(items).filter((item) => !isToggleBtn2(item)).map((item) => item.getAttribute("data-value"));
|
|
3003
3011
|
const customValues = normSelected.filter(
|
|
3004
3012
|
(val) => !standardValues.includes(val) && val !== ""
|
|
3005
3013
|
);
|
|
3006
3014
|
const isStandard = customValues.length === 0;
|
|
3007
3015
|
const primaryCustomValue = customValues[customValues.length - 1] || "";
|
|
3008
|
-
const toggleBtn = Array.from(items).find(
|
|
3009
|
-
(i) => i.textContent.trim() === customizationLabel
|
|
3010
|
-
);
|
|
3016
|
+
const toggleBtn = Array.from(items).find(isToggleBtn2);
|
|
3011
3017
|
const showInput = toggleBtn && normSelected.includes(toggleBtn.getAttribute("data-value")) || !isStandard && normSelected.length > 0;
|
|
3012
3018
|
if (showInput) {
|
|
3013
3019
|
if (!customFieldContainer) {
|
|
@@ -3028,16 +3034,11 @@ var InaUI = (() => {
|
|
|
3028
3034
|
`;
|
|
3029
3035
|
input = customFieldContainer.querySelector("input");
|
|
3030
3036
|
input.addEventListener("blur", (e) => {
|
|
3031
|
-
|
|
3032
|
-
if (val.trim()) {
|
|
3033
|
-
handleSelect(val.trim());
|
|
3034
|
-
}
|
|
3037
|
+
commitCustomValue(e.target);
|
|
3035
3038
|
});
|
|
3036
3039
|
input.addEventListener("keydown", (e) => {
|
|
3037
3040
|
if (e.key === "Enter") {
|
|
3038
|
-
|
|
3039
|
-
handleSelect(e.target.value.trim());
|
|
3040
|
-
}
|
|
3041
|
+
commitCustomValue(e.target);
|
|
3041
3042
|
e.target.blur();
|
|
3042
3043
|
}
|
|
3043
3044
|
});
|
|
@@ -3069,7 +3070,13 @@ var InaUI = (() => {
|
|
|
3069
3070
|
finalVal = newSelected;
|
|
3070
3071
|
selectedValue = newSelected.join(",");
|
|
3071
3072
|
} else {
|
|
3072
|
-
|
|
3073
|
+
const normSelected = getNormalizedSelected();
|
|
3074
|
+
if (normSelected.includes(val)) {
|
|
3075
|
+
selectedValue = "";
|
|
3076
|
+
finalVal = "";
|
|
3077
|
+
} else {
|
|
3078
|
+
selectedValue = val;
|
|
3079
|
+
}
|
|
3073
3080
|
}
|
|
3074
3081
|
container.setAttribute("data-selected", selectedValue);
|
|
3075
3082
|
updateUI();
|
|
@@ -3090,47 +3097,101 @@ var InaUI = (() => {
|
|
|
3090
3097
|
currentFocusedIndex = index2;
|
|
3091
3098
|
}
|
|
3092
3099
|
};
|
|
3100
|
+
const commitCustomValue = (inputEl) => {
|
|
3101
|
+
const finalValue = inputEl.value.trim();
|
|
3102
|
+
let normSelected = getNormalizedSelected();
|
|
3103
|
+
const toggleBtn = Array.from(items).find(isToggleBtn);
|
|
3104
|
+
const toggleVal = toggleBtn ? toggleBtn.getAttribute("data-value") : null;
|
|
3105
|
+
const standardValues = Array.from(items).filter((i) => !isToggleBtn(i)).map((i) => i.getAttribute("data-value"));
|
|
3106
|
+
const customValues = normSelected.filter(
|
|
3107
|
+
(val) => !standardValues.includes(val) && val !== "" && val !== toggleVal
|
|
3108
|
+
);
|
|
3109
|
+
const primaryCustomValue = customValues[customValues.length - 1];
|
|
3110
|
+
if (primaryCustomValue) {
|
|
3111
|
+
normSelected = normSelected.filter((v) => v !== primaryCustomValue);
|
|
3112
|
+
}
|
|
3113
|
+
if (finalValue !== "") {
|
|
3114
|
+
if (!normSelected.includes(finalValue)) {
|
|
3115
|
+
normSelected.push(finalValue);
|
|
3116
|
+
}
|
|
3117
|
+
}
|
|
3118
|
+
if (isMultiple) {
|
|
3119
|
+
selectedValue = normSelected.join(",");
|
|
3120
|
+
} else {
|
|
3121
|
+
selectedValue = finalValue;
|
|
3122
|
+
}
|
|
3123
|
+
updateUI();
|
|
3124
|
+
const changeEvent = new CustomEvent(`${PREFIX4}-chip:change`, {
|
|
3125
|
+
detail: { value: isMultiple ? getNormalizedSelected() : selectedValue },
|
|
3126
|
+
bubbles: true
|
|
3127
|
+
});
|
|
3128
|
+
container.dispatchEvent(changeEvent);
|
|
3129
|
+
};
|
|
3093
3130
|
items.forEach((item, index2) => {
|
|
3094
3131
|
item.addEventListener("click", (e) => {
|
|
3132
|
+
if (item.hasAttribute("disabled")) return;
|
|
3133
|
+
currentFocusedIndex = index2;
|
|
3095
3134
|
const val = item.getAttribute("data-value");
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3135
|
+
if (showCustomization && isToggleBtn(item)) {
|
|
3136
|
+
const normSelected = getNormalizedSelected();
|
|
3137
|
+
let newSelected = [...normSelected];
|
|
3138
|
+
const standardValues = Array.from(items).filter((i) => !isToggleBtn(i)).map((i) => i.getAttribute("data-value"));
|
|
3139
|
+
const customValues = normSelected.filter(
|
|
3140
|
+
(v) => !standardValues.includes(v) && v !== "" && v !== val
|
|
3141
|
+
);
|
|
3142
|
+
const primaryCustomValue = customValues[customValues.length - 1];
|
|
3143
|
+
const isInputVisible = normSelected.includes(val) || customValues.length > 0;
|
|
3144
|
+
if (isInputVisible) {
|
|
3145
|
+
newSelected = newSelected.filter((v) => v !== val);
|
|
3146
|
+
if (primaryCustomValue) {
|
|
3147
|
+
if (isMultiple) {
|
|
3148
|
+
newSelected = newSelected.filter(
|
|
3149
|
+
(v) => v !== primaryCustomValue
|
|
3150
|
+
);
|
|
3151
|
+
} else {
|
|
3152
|
+
newSelected = [];
|
|
3153
|
+
}
|
|
3154
|
+
}
|
|
3155
|
+
if (isMultiple) {
|
|
3156
|
+
selectedValue = newSelected.join(",");
|
|
3157
|
+
} else {
|
|
3158
|
+
selectedValue = newSelected.length ? newSelected[0] : "";
|
|
3159
|
+
}
|
|
3160
|
+
updateUI();
|
|
3161
|
+
const changeEvent = new CustomEvent(`${PREFIX4}-chip:change`, {
|
|
3162
|
+
detail: {
|
|
3163
|
+
value: isMultiple ? getNormalizedSelected() : selectedValue
|
|
3164
|
+
},
|
|
3165
|
+
bubbles: true
|
|
3166
|
+
});
|
|
3167
|
+
container.dispatchEvent(changeEvent);
|
|
3168
|
+
} else {
|
|
3169
|
+
handleSelect(val);
|
|
3170
|
+
}
|
|
3099
3171
|
} else {
|
|
3100
3172
|
handleSelect(val);
|
|
3101
3173
|
}
|
|
3102
3174
|
});
|
|
3103
|
-
item.addEventListener("focus", () => {
|
|
3104
|
-
currentFocusedIndex = index2;
|
|
3105
|
-
});
|
|
3106
3175
|
item.addEventListener("keydown", (e) => {
|
|
3176
|
+
if (item.hasAttribute("disabled")) return;
|
|
3107
3177
|
if (e.key === "ArrowRight" || e.key === "ArrowDown") {
|
|
3108
3178
|
e.preventDefault();
|
|
3109
|
-
|
|
3179
|
+
let nextIndex = (index2 + 1) % items.length;
|
|
3180
|
+
while (items[nextIndex].hasAttribute("disabled") && nextIndex !== index2) {
|
|
3181
|
+
nextIndex = (nextIndex + 1) % items.length;
|
|
3182
|
+
}
|
|
3110
3183
|
setItemFocus(nextIndex);
|
|
3111
3184
|
} else if (e.key === "ArrowLeft" || e.key === "ArrowUp") {
|
|
3112
3185
|
e.preventDefault();
|
|
3113
|
-
|
|
3186
|
+
let prevIndex = (index2 - 1 + items.length) % items.length;
|
|
3187
|
+
while (items[prevIndex].hasAttribute("disabled") && prevIndex !== index2) {
|
|
3188
|
+
prevIndex = (prevIndex - 1 + items.length) % items.length;
|
|
3189
|
+
}
|
|
3114
3190
|
setItemFocus(prevIndex);
|
|
3115
3191
|
}
|
|
3116
3192
|
if (e.key === " " || e.key === "Enter") {
|
|
3117
3193
|
e.preventDefault();
|
|
3118
|
-
|
|
3119
|
-
const label = item.textContent.trim();
|
|
3120
|
-
if (showCustomization && label === customizationLabel) {
|
|
3121
|
-
handleSelect(val);
|
|
3122
|
-
setTimeout(() => {
|
|
3123
|
-
const customFieldContainer2 = container.querySelector(
|
|
3124
|
-
`.${PREFIX4}-chip__custom-field`
|
|
3125
|
-
);
|
|
3126
|
-
if (customFieldContainer2) {
|
|
3127
|
-
const inputEl = customFieldContainer2.querySelector("input");
|
|
3128
|
-
if (inputEl) inputEl.focus();
|
|
3129
|
-
}
|
|
3130
|
-
}, 50);
|
|
3131
|
-
} else {
|
|
3132
|
-
handleSelect(val);
|
|
3133
|
-
}
|
|
3194
|
+
item.click();
|
|
3134
3195
|
}
|
|
3135
3196
|
});
|
|
3136
3197
|
});
|
package/dist/index.js
CHANGED
|
@@ -3071,23 +3071,29 @@ function initChip(rootSelector = `.${PREFIX5}-chip`) {
|
|
|
3071
3071
|
const isSelected = normSelected.includes(itemValue) || showCustomization && item.textContent.trim() === customizationLabel && normSelected.some(
|
|
3072
3072
|
(val) => !Array.from(items).filter((i) => i.textContent.trim() !== customizationLabel).map((i) => i.getAttribute("data-value")).includes(val) && val !== ""
|
|
3073
3073
|
);
|
|
3074
|
+
const isDisabled = item.hasAttribute("disabled");
|
|
3074
3075
|
if (isSelected) {
|
|
3075
3076
|
item.classList.add(`${PREFIX5}-chip__item--selected`);
|
|
3076
3077
|
} else {
|
|
3077
3078
|
item.classList.remove(`${PREFIX5}-chip__item--selected`);
|
|
3078
3079
|
}
|
|
3079
|
-
|
|
3080
|
+
if (isDisabled) {
|
|
3081
|
+
item.classList.add(`${PREFIX5}-chip__item--disabled`);
|
|
3082
|
+
}
|
|
3083
|
+
item.setAttribute(
|
|
3084
|
+
"tabindex",
|
|
3085
|
+
index2 === focusedIndex && !isDisabled ? "0" : "-1"
|
|
3086
|
+
);
|
|
3080
3087
|
});
|
|
3081
3088
|
if (showCustomization) {
|
|
3082
|
-
const
|
|
3089
|
+
const isToggleBtn2 = (i) => i.hasAttribute("data-customization-toggle") || i.textContent.trim() === customizationLabel;
|
|
3090
|
+
const standardValues = Array.from(items).filter((item) => !isToggleBtn2(item)).map((item) => item.getAttribute("data-value"));
|
|
3083
3091
|
const customValues = normSelected.filter(
|
|
3084
3092
|
(val) => !standardValues.includes(val) && val !== ""
|
|
3085
3093
|
);
|
|
3086
3094
|
const isStandard = customValues.length === 0;
|
|
3087
3095
|
const primaryCustomValue = customValues[customValues.length - 1] || "";
|
|
3088
|
-
const toggleBtn = Array.from(items).find(
|
|
3089
|
-
(i) => i.textContent.trim() === customizationLabel
|
|
3090
|
-
);
|
|
3096
|
+
const toggleBtn = Array.from(items).find(isToggleBtn2);
|
|
3091
3097
|
const showInput = toggleBtn && normSelected.includes(toggleBtn.getAttribute("data-value")) || !isStandard && normSelected.length > 0;
|
|
3092
3098
|
if (showInput) {
|
|
3093
3099
|
if (!customFieldContainer) {
|
|
@@ -3108,16 +3114,11 @@ function initChip(rootSelector = `.${PREFIX5}-chip`) {
|
|
|
3108
3114
|
`;
|
|
3109
3115
|
input = customFieldContainer.querySelector("input");
|
|
3110
3116
|
input.addEventListener("blur", (e) => {
|
|
3111
|
-
|
|
3112
|
-
if (val.trim()) {
|
|
3113
|
-
handleSelect(val.trim());
|
|
3114
|
-
}
|
|
3117
|
+
commitCustomValue(e.target);
|
|
3115
3118
|
});
|
|
3116
3119
|
input.addEventListener("keydown", (e) => {
|
|
3117
3120
|
if (e.key === "Enter") {
|
|
3118
|
-
|
|
3119
|
-
handleSelect(e.target.value.trim());
|
|
3120
|
-
}
|
|
3121
|
+
commitCustomValue(e.target);
|
|
3121
3122
|
e.target.blur();
|
|
3122
3123
|
}
|
|
3123
3124
|
});
|
|
@@ -3149,7 +3150,13 @@ function initChip(rootSelector = `.${PREFIX5}-chip`) {
|
|
|
3149
3150
|
finalVal = newSelected;
|
|
3150
3151
|
selectedValue = newSelected.join(",");
|
|
3151
3152
|
} else {
|
|
3152
|
-
|
|
3153
|
+
const normSelected = getNormalizedSelected();
|
|
3154
|
+
if (normSelected.includes(val)) {
|
|
3155
|
+
selectedValue = "";
|
|
3156
|
+
finalVal = "";
|
|
3157
|
+
} else {
|
|
3158
|
+
selectedValue = val;
|
|
3159
|
+
}
|
|
3153
3160
|
}
|
|
3154
3161
|
container.setAttribute("data-selected", selectedValue);
|
|
3155
3162
|
updateUI();
|
|
@@ -3170,47 +3177,101 @@ function initChip(rootSelector = `.${PREFIX5}-chip`) {
|
|
|
3170
3177
|
currentFocusedIndex = index2;
|
|
3171
3178
|
}
|
|
3172
3179
|
};
|
|
3180
|
+
const commitCustomValue = (inputEl) => {
|
|
3181
|
+
const finalValue = inputEl.value.trim();
|
|
3182
|
+
let normSelected = getNormalizedSelected();
|
|
3183
|
+
const toggleBtn = Array.from(items).find(isToggleBtn);
|
|
3184
|
+
const toggleVal = toggleBtn ? toggleBtn.getAttribute("data-value") : null;
|
|
3185
|
+
const standardValues = Array.from(items).filter((i) => !isToggleBtn(i)).map((i) => i.getAttribute("data-value"));
|
|
3186
|
+
const customValues = normSelected.filter(
|
|
3187
|
+
(val) => !standardValues.includes(val) && val !== "" && val !== toggleVal
|
|
3188
|
+
);
|
|
3189
|
+
const primaryCustomValue = customValues[customValues.length - 1];
|
|
3190
|
+
if (primaryCustomValue) {
|
|
3191
|
+
normSelected = normSelected.filter((v) => v !== primaryCustomValue);
|
|
3192
|
+
}
|
|
3193
|
+
if (finalValue !== "") {
|
|
3194
|
+
if (!normSelected.includes(finalValue)) {
|
|
3195
|
+
normSelected.push(finalValue);
|
|
3196
|
+
}
|
|
3197
|
+
}
|
|
3198
|
+
if (isMultiple) {
|
|
3199
|
+
selectedValue = normSelected.join(",");
|
|
3200
|
+
} else {
|
|
3201
|
+
selectedValue = finalValue;
|
|
3202
|
+
}
|
|
3203
|
+
updateUI();
|
|
3204
|
+
const changeEvent = new CustomEvent(`${PREFIX5}-chip:change`, {
|
|
3205
|
+
detail: { value: isMultiple ? getNormalizedSelected() : selectedValue },
|
|
3206
|
+
bubbles: true
|
|
3207
|
+
});
|
|
3208
|
+
container.dispatchEvent(changeEvent);
|
|
3209
|
+
};
|
|
3173
3210
|
items.forEach((item, index2) => {
|
|
3174
3211
|
item.addEventListener("click", (e) => {
|
|
3212
|
+
if (item.hasAttribute("disabled")) return;
|
|
3213
|
+
currentFocusedIndex = index2;
|
|
3175
3214
|
const val = item.getAttribute("data-value");
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3215
|
+
if (showCustomization && isToggleBtn(item)) {
|
|
3216
|
+
const normSelected = getNormalizedSelected();
|
|
3217
|
+
let newSelected = [...normSelected];
|
|
3218
|
+
const standardValues = Array.from(items).filter((i) => !isToggleBtn(i)).map((i) => i.getAttribute("data-value"));
|
|
3219
|
+
const customValues = normSelected.filter(
|
|
3220
|
+
(v) => !standardValues.includes(v) && v !== "" && v !== val
|
|
3221
|
+
);
|
|
3222
|
+
const primaryCustomValue = customValues[customValues.length - 1];
|
|
3223
|
+
const isInputVisible = normSelected.includes(val) || customValues.length > 0;
|
|
3224
|
+
if (isInputVisible) {
|
|
3225
|
+
newSelected = newSelected.filter((v) => v !== val);
|
|
3226
|
+
if (primaryCustomValue) {
|
|
3227
|
+
if (isMultiple) {
|
|
3228
|
+
newSelected = newSelected.filter(
|
|
3229
|
+
(v) => v !== primaryCustomValue
|
|
3230
|
+
);
|
|
3231
|
+
} else {
|
|
3232
|
+
newSelected = [];
|
|
3233
|
+
}
|
|
3234
|
+
}
|
|
3235
|
+
if (isMultiple) {
|
|
3236
|
+
selectedValue = newSelected.join(",");
|
|
3237
|
+
} else {
|
|
3238
|
+
selectedValue = newSelected.length ? newSelected[0] : "";
|
|
3239
|
+
}
|
|
3240
|
+
updateUI();
|
|
3241
|
+
const changeEvent = new CustomEvent(`${PREFIX5}-chip:change`, {
|
|
3242
|
+
detail: {
|
|
3243
|
+
value: isMultiple ? getNormalizedSelected() : selectedValue
|
|
3244
|
+
},
|
|
3245
|
+
bubbles: true
|
|
3246
|
+
});
|
|
3247
|
+
container.dispatchEvent(changeEvent);
|
|
3248
|
+
} else {
|
|
3249
|
+
handleSelect(val);
|
|
3250
|
+
}
|
|
3179
3251
|
} else {
|
|
3180
3252
|
handleSelect(val);
|
|
3181
3253
|
}
|
|
3182
3254
|
});
|
|
3183
|
-
item.addEventListener("focus", () => {
|
|
3184
|
-
currentFocusedIndex = index2;
|
|
3185
|
-
});
|
|
3186
3255
|
item.addEventListener("keydown", (e) => {
|
|
3256
|
+
if (item.hasAttribute("disabled")) return;
|
|
3187
3257
|
if (e.key === "ArrowRight" || e.key === "ArrowDown") {
|
|
3188
3258
|
e.preventDefault();
|
|
3189
|
-
|
|
3259
|
+
let nextIndex = (index2 + 1) % items.length;
|
|
3260
|
+
while (items[nextIndex].hasAttribute("disabled") && nextIndex !== index2) {
|
|
3261
|
+
nextIndex = (nextIndex + 1) % items.length;
|
|
3262
|
+
}
|
|
3190
3263
|
setItemFocus(nextIndex);
|
|
3191
3264
|
} else if (e.key === "ArrowLeft" || e.key === "ArrowUp") {
|
|
3192
3265
|
e.preventDefault();
|
|
3193
|
-
|
|
3266
|
+
let prevIndex = (index2 - 1 + items.length) % items.length;
|
|
3267
|
+
while (items[prevIndex].hasAttribute("disabled") && prevIndex !== index2) {
|
|
3268
|
+
prevIndex = (prevIndex - 1 + items.length) % items.length;
|
|
3269
|
+
}
|
|
3194
3270
|
setItemFocus(prevIndex);
|
|
3195
3271
|
}
|
|
3196
3272
|
if (e.key === " " || e.key === "Enter") {
|
|
3197
3273
|
e.preventDefault();
|
|
3198
|
-
|
|
3199
|
-
const label = item.textContent.trim();
|
|
3200
|
-
if (showCustomization && label === customizationLabel) {
|
|
3201
|
-
handleSelect(val);
|
|
3202
|
-
setTimeout(() => {
|
|
3203
|
-
const customFieldContainer2 = container.querySelector(
|
|
3204
|
-
`.${PREFIX5}-chip__custom-field`
|
|
3205
|
-
);
|
|
3206
|
-
if (customFieldContainer2) {
|
|
3207
|
-
const inputEl = customFieldContainer2.querySelector("input");
|
|
3208
|
-
if (inputEl) inputEl.focus();
|
|
3209
|
-
}
|
|
3210
|
-
}, 50);
|
|
3211
|
-
} else {
|
|
3212
|
-
handleSelect(val);
|
|
3213
|
-
}
|
|
3274
|
+
item.click();
|
|
3214
3275
|
}
|
|
3215
3276
|
});
|
|
3216
3277
|
});
|