slim-select 4.1.0 → 4.2.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/dist/vue/index.js CHANGED
@@ -52,7 +52,7 @@ var s = class {
52
52
  constructor(e) {
53
53
  e ||= {};
54
54
  let t = (e = "", t = "") => `${e} ${t}`.trim();
55
- this.main = t("ss-main", e.main), this.placeholder = t("ss-placeholder", e.placeholder), this.values = t("ss-values", e.values), this.single = t("ss-single", e.single), this.multiString = t("ss-multi-string", e.multiString), this.max = t("ss-max", e.max), this.value = t("ss-value", e.value), this.valueText = t("ss-value-text", e.valueText), this.valueDelete = t("ss-value-delete", e.valueDelete), this.valueOut = t("ss-value-out", e.valueOut), this.deselect = t("ss-deselect", e.deselect), this.deselectPath = e.deselectPath || "M10,10 L90,90 M10,90 L90,10", this.arrow = t("ss-arrow", e.arrow), this.arrowClose = e.arrowClose || "M10,30 L50,70 L90,30", this.arrowOpen = e.arrowOpen || "M10,70 L50,30 L90,70", this.content = t("ss-content", e.content), this.contentOpen = t("ss-open", e.contentOpen), this.dirAbove = t("ss-dir-above", e.dirAbove), this.dirBelow = t("ss-dir-below", e.dirBelow), this.search = t("ss-search", e.search), this.searchHighlighter = t("ss-search-highlight", e.searchHighlighter), this.searching = t("ss-searching", e.searching), this.status = t("ss-status", e.status), this.addable = t("ss-addable", e.addable), this.addablePath = e.addablePath || "M50,10 L50,90 M10,50 L90,50", this.list = t("ss-list", e.list), this.optgroup = t("ss-optgroup", e.optgroup), this.optgroupLabel = t("ss-optgroup-label", e.optgroupLabel), this.optgroupLabelText = t("ss-optgroup-label-text", e.optgroupLabelText), this.optgroupActions = t("ss-optgroup-actions", e.optgroupActions), this.optgroupSelectAll = t("ss-selectall", e.optgroupSelectAll), this.optgroupSelectAllBox = e.optgroupSelectAllBox || "M60,10 L10,10 L10,90 L90,90 L90,50", this.optgroupSelectAllCheck = e.optgroupSelectAllCheck || "M30,45 L50,70 L90,10", this.optgroupClosable = t("ss-closable", e.optgroupClosable), this.option = t("ss-option", e.option), this.optionDelete = e.optionDelete || "M10,10 L90,90 M10,90 L90,10", this.highlighted = t("ss-highlighted", e.highlighted), this.modalOverlay = t("ss-modal-overlay", e.modalOverlay), this.modalDialog = t("ss-modal-dialog", e.modalDialog), this.modalTitle = t("ss-modal-title", e.modalTitle), this.modalClose = t("ss-modal-close", e.modalClose), this.modalContent = t("ss-modal-content", e.modalContent), this.mainOpen = t("ss-open", e.mainOpen), this.close = t("ss-close", e.close), this.selected = t("ss-selected", e.selected), this.error = t("ss-error", e.error), this.disabled = t("ss-disabled", e.disabled), this.hide = t("ss-hide", e.hide);
55
+ this.main = t("ss-main", e.main), this.placeholder = t("ss-placeholder", e.placeholder), this.values = t("ss-values", e.values), this.single = t("ss-single", e.single), this.multiString = t("ss-multi-string", e.multiString), this.max = t("ss-max", e.max), this.value = t("ss-value", e.value), this.valueText = t("ss-value-text", e.valueText), this.valueDelete = t("ss-value-delete", e.valueDelete), this.valueOut = t("ss-value-out", e.valueOut), this.deselect = t("ss-deselect", e.deselect), this.deselectPath = e.deselectPath || "M10,10 L90,90 M10,90 L90,10", this.arrow = t("ss-arrow", e.arrow), this.arrowClose = e.arrowClose || "M10,30 L50,70 L90,30", this.arrowOpen = e.arrowOpen || "M10,70 L50,30 L90,70", this.content = t("ss-content", e.content), this.contentOpen = t("ss-open", e.contentOpen), this.dirAbove = t("ss-dir-above", e.dirAbove), this.dirBelow = t("ss-dir-below", e.dirBelow), this.search = t("ss-search", e.search), this.searchHighlighter = t("ss-search-highlight", e.searchHighlighter), this.searching = t("ss-searching", e.searching), this.status = t("ss-status", e.status), this.addable = t("ss-addable", e.addable), this.addablePath = e.addablePath || "M50,10 L50,90 M10,50 L90,50", this.list = t("ss-list", e.list), this.optgroup = t("ss-optgroup", e.optgroup), this.optgroupLabel = t("ss-optgroup-label", e.optgroupLabel), this.optgroupLabelText = t("ss-optgroup-label-text", e.optgroupLabelText), this.optgroupActions = t("ss-optgroup-actions", e.optgroupActions), this.optgroupSelectAll = t("ss-selectall", e.optgroupSelectAll), this.optgroupSelectAllBox = e.optgroupSelectAllBox || "M15,15 L85,15 L85,85 L15,85 Z", this.optgroupSelectAllCheck = e.optgroupSelectAllCheck || "M25,50 L42,68 L75,32", this.optgroupClosable = t("ss-closable", e.optgroupClosable), this.option = t("ss-option", e.option), this.optionDelete = e.optionDelete || "M10,10 L90,90 M10,90 L90,10", this.highlighted = t("ss-highlighted", e.highlighted), this.modalOverlay = t("ss-modal-overlay", e.modalOverlay), this.modalDialog = t("ss-modal-dialog", e.modalDialog), this.modalTitle = t("ss-modal-title", e.modalTitle), this.modalClose = t("ss-modal-close", e.modalClose), this.modalContent = t("ss-modal-content", e.modalContent), this.mainOpen = t("ss-open", e.mainOpen), this.close = t("ss-close", e.close), this.selected = t("ss-selected", e.selected), this.error = t("ss-error", e.error), this.disabled = t("ss-disabled", e.disabled), this.hide = t("ss-hide", e.hide);
56
56
  }
57
57
  getFirst(e) {
58
58
  return this[e].split(" ")[0];
@@ -146,10 +146,13 @@ var _ = class {
146
146
  maxValuesShown;
147
147
  maxValuesMessage;
148
148
  addableText;
149
+ selectAll;
150
+ selectAllText;
151
+ unselectAllText;
149
152
  modal;
150
153
  modalTitle;
151
154
  constructor(e) {
152
- e ||= {}, this.id = "ss-" + x(), this.style = e.style || "", this.class = e.class || [], this.disabled = e.disabled !== void 0 && e.disabled, this.alwaysOpen = e.alwaysOpen !== void 0 && e.alwaysOpen, this.showSearch = e.showSearch === void 0 || e.showSearch, this.focusSearch = e.focusSearch === void 0 || e.focusSearch, this.keepSearch = e.keepSearch !== void 0 && e.keepSearch, this.ariaLabel = e.ariaLabel || "Combobox", this.searchPlaceholder = e.searchPlaceholder || "Search...", this.searchText = e.searchText || "No Results", this.searchingText = e.searchingText || "Searching...", this.resultsText = e.resultsText || "{count} results available", this.deselectText = e.deselectText || "Clear", this.removeText = e.removeText || "Remove", this.searchHighlight = e.searchHighlight !== void 0 && e.searchHighlight, this.closeOnSelect = e.closeOnSelect === void 0 || e.closeOnSelect, this.contentLocation = e.contentLocation || document.body, this.contentPosition = e.contentPosition || "absolute", this.contentWidth = e.contentWidth || "", this.openPosition = e.openPosition || "auto", this.placeholderText = e.placeholderText === void 0 ? "Select Value" : e.placeholderText, this.allowDeselect = e.allowDeselect !== void 0 && e.allowDeselect, this.hideSelected = e.hideSelected !== void 0 && e.hideSelected, this.multiString = e.multiString !== void 0 && e.multiString, this.keepOrder = e.keepOrder !== void 0 && e.keepOrder, this.showOptionTooltips = e.showOptionTooltips !== void 0 && e.showOptionTooltips, this.minSelected = e.minSelected || 0, this.maxSelected = e.maxSelected || 1e3, this.timeoutDelay = e.timeoutDelay || 200, this.maxValuesShown = e.maxValuesShown || 20, this.maxValuesMessage = e.maxValuesMessage || "{number} selected", this.addableText = e.addableText || "Press \"Enter\" to add {value}", this.modal = e.modal || "mobile", this.modalTitle = e.modalTitle || "";
155
+ e ||= {}, this.id = "ss-" + x(), this.style = e.style || "", this.class = e.class || [], this.disabled = e.disabled !== void 0 && e.disabled, this.alwaysOpen = e.alwaysOpen !== void 0 && e.alwaysOpen, this.showSearch = e.showSearch === void 0 || e.showSearch, this.focusSearch = e.focusSearch === void 0 || e.focusSearch, this.keepSearch = e.keepSearch !== void 0 && e.keepSearch, this.ariaLabel = e.ariaLabel || "Combobox", this.searchPlaceholder = e.searchPlaceholder || "Search...", this.searchText = e.searchText || "No Results", this.searchingText = e.searchingText || "Searching...", this.resultsText = e.resultsText || "{count} results available", this.deselectText = e.deselectText || "Clear", this.removeText = e.removeText || "Remove", this.searchHighlight = e.searchHighlight !== void 0 && e.searchHighlight, this.closeOnSelect = e.closeOnSelect === void 0 || e.closeOnSelect, this.contentLocation = e.contentLocation || document.body, this.contentPosition = e.contentPosition || "absolute", this.contentWidth = e.contentWidth || "", this.openPosition = e.openPosition || "auto", this.placeholderText = e.placeholderText === void 0 ? "Select Value" : e.placeholderText, this.allowDeselect = e.allowDeselect !== void 0 && e.allowDeselect, this.hideSelected = e.hideSelected !== void 0 && e.hideSelected, this.multiString = e.multiString !== void 0 && e.multiString, this.keepOrder = e.keepOrder !== void 0 && e.keepOrder, this.showOptionTooltips = e.showOptionTooltips !== void 0 && e.showOptionTooltips, this.minSelected = e.minSelected || 0, this.maxSelected = e.maxSelected || 1e3, this.timeoutDelay = e.timeoutDelay || 200, this.maxValuesShown = e.maxValuesShown || 20, this.maxValuesMessage = e.maxValuesMessage || "{number} selected", this.addableText = e.addableText || "Press \"Enter\" to add {value}", this.selectAll = e.selectAll !== void 0 && e.selectAll, this.selectAllText = e.selectAllText || "Select All", this.unselectAllText = e.unselectAllText || "Unselect All", this.modal = e.modal || "mobile", this.modalTitle = e.modalTitle || "";
153
156
  }
154
157
  };
155
158
  //#endregion
@@ -982,13 +985,13 @@ var P = class {
982
985
  let r = {
983
986
  main: e,
984
987
  input: t
985
- };
986
- this.settings.showSearch || (this.addClasses(e, this.classes.hide), t.readOnly = !0), t.type = "search", t.placeholder = this.settings.searchPlaceholder, t.tabIndex = -1, t.setAttribute("aria-label", this.settings.searchPlaceholder), t.setAttribute("aria-autocomplete", "list"), t.setAttribute("autocapitalize", "off"), t.setAttribute("autocomplete", "off"), t.setAttribute("autocorrect", "off"), t.setAttribute("aria-hidden", "true");
987
- let i = C(() => {
988
+ }, i = this.settings.selectAll && this.settings.isMultiple;
989
+ this.settings.showSearch || (t.readOnly = !0, i ? this.addClasses(t, this.classes.hide) : this.addClasses(e, this.classes.hide)), t.type = "search", t.id = `${this.settings.id}-search`, t.placeholder = this.settings.searchPlaceholder, t.tabIndex = -1, t.setAttribute("aria-label", this.settings.searchPlaceholder), t.setAttribute("aria-autocomplete", "list"), t.setAttribute("autocapitalize", "off"), t.setAttribute("autocomplete", "off"), t.setAttribute("autocorrect", "off"), t.setAttribute("aria-hidden", "true");
990
+ let a = C(() => {
988
991
  this.callbacks.search(t.value);
989
992
  }, 100);
990
993
  if (t.oninput = (e) => {
991
- e.target.value !== "" && this.clearValueChipHighlight(), i();
994
+ e.target.value !== "" && this.clearValueChipHighlight(), a();
992
995
  }, t.onkeydown = (e) => {
993
996
  switch (e.key) {
994
997
  case "ArrowUp":
@@ -1004,7 +1007,11 @@ var P = class {
1004
1007
  return r ? (r.click(), !1) : !this.callbacks.addable || (n.click(), !1);
1005
1008
  }
1006
1009
  return e.key.length === 1 && this.clearValueChipHighlight(), !0;
1007
- }, e.appendChild(t), this.callbacks.addable) {
1010
+ }, e.appendChild(t), i) {
1011
+ let t = this.createSelectAllControl(() => this.toggleGlobalSelectAll());
1012
+ e.appendChild(t), r.selectAll = t;
1013
+ }
1014
+ if (this.callbacks.addable) {
1008
1015
  this.addClasses(n, this.classes.addable);
1009
1016
  let t = document.createElementNS("http://www.w3.org/2000/svg", "svg");
1010
1017
  t.setAttribute("viewBox", "0 0 100 100");
@@ -1132,35 +1139,24 @@ var P = class {
1132
1139
  this.addClasses(i, this.classes.optgroupLabelText), i.textContent = n.label, r.appendChild(i);
1133
1140
  let a = document.createElement("div");
1134
1141
  if (this.addClasses(a, this.classes.optgroupActions), r.appendChild(a), this.settings.isMultiple && n.selectAll) {
1135
- let e = document.createElement("div");
1136
- this.addClasses(e, this.classes.optgroupSelectAll);
1137
- let t = this.isOptgroupAllSelected(n.options);
1138
- t && this.addClasses(e, this.classes.selected);
1139
- let r = document.createElement("span");
1140
- r.textContent = this.optgroupSelectAllLabel(t), e.appendChild(r);
1141
- let i = document.createElementNS("http://www.w3.org/2000/svg", "svg");
1142
- i.setAttribute("viewBox", "0 0 100 100"), e.appendChild(i);
1143
- let o = document.createElementNS("http://www.w3.org/2000/svg", "path");
1144
- o.setAttribute("d", this.classes.optgroupSelectAllBox), i.appendChild(o);
1145
- let s = document.createElementNS("http://www.w3.org/2000/svg", "path");
1146
- s.setAttribute("d", this.classes.optgroupSelectAllCheck), i.appendChild(s), e.addEventListener("click", (e) => {
1147
- e.preventDefault(), e.stopPropagation();
1148
- let t = this.store.getSelected();
1149
- if (this.isOptgroupAllSelected(n.options, new Set(t))) {
1150
- let e = t.filter((e) => {
1142
+ let e = this.createSelectAllControl(() => {
1143
+ let e = this.store.getSelected();
1144
+ if (this.isOptgroupAllSelected(n.options, new Set(e))) {
1145
+ let t = e.filter((e) => {
1151
1146
  for (let t of n.options) if (e === t.id) return !1;
1152
1147
  return !0;
1153
1148
  });
1154
- this.callbacks.setSelected(e, !0);
1149
+ this.callbacks.setSelected(t, !0);
1155
1150
  return;
1156
1151
  }
1157
1152
  {
1158
- let e = n.options.map((e) => e.id).filter((e) => e !== void 0), r = t.concat(e);
1153
+ let t = n.options.map((e) => e.id).filter((e) => e !== void 0), r = e.concat(t);
1159
1154
  for (let e of n.options) e.id && !this.store.getOptionByID(e.id) && this.callbacks.addOption(new I(e));
1160
1155
  this.callbacks.setSelected(r, !0);
1161
1156
  return;
1162
1157
  }
1163
- }), a.appendChild(e);
1158
+ }, this.isOptgroupAllSelected(n.options));
1159
+ a.appendChild(e);
1164
1160
  }
1165
1161
  if (n.closable !== "off") {
1166
1162
  let t = document.createElement("div");
@@ -1177,7 +1173,7 @@ var P = class {
1177
1173
  }
1178
1174
  n instanceof I && t.appendChild(this.option(n));
1179
1175
  }
1180
- this.content.list.appendChild(t), this.setOptionsListFullData(e), this.announce(this.settings.resultsText.replace("{count}", String(this.lastRenderedOptions.length)));
1176
+ this.content.list.appendChild(t), this.setOptionsListFullData(e), this.announce(this.settings.resultsText.replace("{count}", String(this.lastRenderedOptions.length))), this.updateGlobalSelectAllState();
1181
1177
  }
1182
1178
  canFilterOptionsInPlace() {
1183
1179
  return this.optionsListIsFullData ? this.content.list.querySelector("." + this.classes.getFirst("option")) !== null : !1;
@@ -1198,7 +1194,7 @@ var P = class {
1198
1194
  let o = a.placeholder || !a.display || a.selected && this.settings.hideSelected, s = t(a, n);
1199
1195
  o || !s ? (this.addClasses(e, this.classes.hide), this.removeClasses(e, this.classes.highlighted)) : (this.removeClasses(e, this.classes.hide), this.setOptionElementContent(e, a, n), r.push(a)), a.selected ? (this.addClasses(e, this.classes.selected), e.setAttribute("aria-selected", "true")) : (this.removeClasses(e, this.classes.selected), e.setAttribute("aria-selected", "false"));
1200
1196
  }
1201
- this.lastRenderedOptions = r, this.updateOptgroupVisibilityAfterSearch(n), r.length === 0 ? this.updateSearchResultsMessage(0, n) : (this.removeListSearchMessage(), this.announce(this.settings.resultsText.replace("{count}", String(r.length)))), this.updateOptgroupSelectAllStates();
1197
+ this.lastRenderedOptions = r, this.updateOptgroupVisibilityAfterSearch(n), r.length === 0 ? this.updateSearchResultsMessage(0, n) : (this.removeListSearchMessage(), this.announce(this.settings.resultsText.replace("{count}", String(r.length)))), this.updateOptgroupSelectAllStates(), this.updateGlobalSelectAllState();
1202
1198
  }
1203
1199
  setOptionsListFullData(e) {
1204
1200
  let t = this.store.getDataOptions(!1), n = e.map((e) => e instanceof I ? [e] : e.options.map((e) => new I(e))).flat();
@@ -1270,7 +1266,48 @@ var P = class {
1270
1266
  let a = e.has(t);
1271
1267
  a ? (this.addClasses(r, this.classes.selected), r.setAttribute("aria-selected", "true"), n = r) : (this.removeClasses(r, this.classes.selected), r.setAttribute("aria-selected", "false")), this.settings.hideSelected && (a ? this.addClasses(r, this.classes.hide) : (this.removeClasses(r, this.classes.hide), i.display || this.addClasses(r, this.classes.hide)));
1272
1268
  }
1273
- !this.settings.isMultiple && n ? this.main.main.setAttribute("aria-activedescendant", n.id) : !this.settings.isMultiple && e.size === 0 && this.main.main.removeAttribute("aria-activedescendant"), this.updateOptgroupSelectAllStates();
1269
+ !this.settings.isMultiple && n ? this.main.main.setAttribute("aria-activedescendant", n.id) : !this.settings.isMultiple && e.size === 0 && this.main.main.removeAttribute("aria-activedescendant"), this.updateOptgroupSelectAllStates(), this.updateGlobalSelectAllState();
1270
+ }
1271
+ createSelectAllControl(e, t = !1) {
1272
+ let n = document.createElement("div");
1273
+ this.addClasses(n, this.classes.optgroupSelectAll), n.setAttribute("role", "checkbox"), n.setAttribute("aria-checked", t ? "true" : "false"), n.setAttribute("aria-label", this.selectAllLabel(t)), n.tabIndex = -1, t && this.addClasses(n, this.classes.selected);
1274
+ let r = document.createElement("span");
1275
+ r.textContent = this.selectAllLabel(t), n.appendChild(r);
1276
+ let i = document.createElementNS("http://www.w3.org/2000/svg", "svg");
1277
+ i.setAttribute("viewBox", "0 0 100 100"), i.setAttribute("aria-hidden", "true"), n.appendChild(i);
1278
+ let a = document.createElementNS("http://www.w3.org/2000/svg", "path");
1279
+ a.setAttribute("d", this.classes.optgroupSelectAllBox), i.appendChild(a);
1280
+ let o = document.createElementNS("http://www.w3.org/2000/svg", "path");
1281
+ return o.setAttribute("d", this.classes.optgroupSelectAllCheck), i.appendChild(o), n.addEventListener("click", (t) => {
1282
+ t.preventDefault(), t.stopPropagation(), e();
1283
+ }), n;
1284
+ }
1285
+ getSelectableOptions() {
1286
+ return this.store.getDataOptions(!1).filter((e) => !e.disabled && !e.placeholder && e.display);
1287
+ }
1288
+ isGlobalAllSelected(e) {
1289
+ let t = this.getSelectableOptions();
1290
+ if (t.length === 0) return !1;
1291
+ let n = e || new Set(this.store.getSelected());
1292
+ for (let e of t) if (!n.has(e.id)) return !1;
1293
+ return !0;
1294
+ }
1295
+ toggleGlobalSelectAll() {
1296
+ let e = this.getSelectableOptions(), t = new Set(this.store.getSelected());
1297
+ if (this.isGlobalAllSelected(t)) {
1298
+ let t = new Set(e.map((e) => e.id)), n = this.store.getSelected().filter((e) => !t.has(e));
1299
+ this.callbacks.setSelected(n, !0);
1300
+ return;
1301
+ }
1302
+ this.callbacks.setSelected(e.map((e) => e.id), !0);
1303
+ }
1304
+ updateGlobalSelectAllState() {
1305
+ let e = this.content.search.selectAll;
1306
+ if (!e || !this.settings.isMultiple || !this.settings.selectAll) return;
1307
+ let t = this.isGlobalAllSelected();
1308
+ t ? this.addClasses(e, this.classes.selected) : this.removeClasses(e, this.classes.selected), e.setAttribute("aria-checked", t ? "true" : "false"), e.setAttribute("aria-label", this.selectAllLabel(t));
1309
+ let n = e.querySelector("span");
1310
+ n && (n.textContent = this.selectAllLabel(t));
1274
1311
  }
1275
1312
  updateOptgroupSelectAllStates() {
1276
1313
  if (!this.settings.isMultiple) return;
@@ -1286,13 +1323,13 @@ var P = class {
1286
1323
  break;
1287
1324
  }
1288
1325
  }
1289
- i ? this.addClasses(t, this.classes.selected) : this.removeClasses(t, this.classes.selected);
1326
+ i ? this.addClasses(t, this.classes.selected) : this.removeClasses(t, this.classes.selected), t.setAttribute("aria-checked", i ? "true" : "false"), t.setAttribute("aria-label", this.selectAllLabel(i));
1290
1327
  let a = t.querySelector("span");
1291
- a && (a.textContent = this.optgroupSelectAllLabel(i));
1328
+ a && (a.textContent = this.selectAllLabel(i));
1292
1329
  }
1293
1330
  }
1294
- optgroupSelectAllLabel(e) {
1295
- return e ? "Unselect All" : "Select All";
1331
+ selectAllLabel(e) {
1332
+ return e ? this.settings.unselectAllText : this.settings.selectAllText;
1296
1333
  }
1297
1334
  isOptgroupAllSelected(e, t) {
1298
1335
  if (e.length === 0) return !1;
@@ -1866,7 +1903,7 @@ var W = class {
1866
1903
  e.events && e.events.error && e.events.error(/* @__PURE__ */ Error("Element isnt of type select"));
1867
1904
  return;
1868
1905
  }
1869
- this.selectEl.dataset.ssid && this.destroy(), this.settings = new _(e.settings), this.cssClasses = new s(e.cssClasses);
1906
+ this.selectEl.dataset.ssid && this.destroy(), this.settings = new _(e.settings), e.settings?.selectAll === void 0 && this.selectEl.dataset.selectall === "true" && (this.settings.selectAll = !0), this.cssClasses = new s(e.cssClasses);
1870
1907
  let t = [
1871
1908
  "beforeOpen",
1872
1909
  "afterOpen",