@pequity/squirrel 5.5.0 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,7 +13,7 @@ const pIcon = require("../p-icon.js");
13
13
  * Licensed under MIT.
14
14
  *
15
15
  * @license MIT
16
- * @version 2.1.0
16
+ * @version 2.2.0
17
17
  */
18
18
  const defaultIconDimensions = Object.freeze(
19
19
  {
@@ -163,7 +163,9 @@ const validateIconName = (icon, allowSimpleName) => {
163
163
  if (!icon) {
164
164
  return false;
165
165
  }
166
- return !!((icon.provider === "" || icon.provider.match(matchIconName)) && (allowSimpleName && icon.prefix === "" || icon.prefix.match(matchIconName)) && icon.name.match(matchIconName));
166
+ return !!// Check prefix: cannot be empty, unless allowSimpleName is enabled
167
+ // Check name: cannot be empty
168
+ ((allowSimpleName && icon.prefix === "" || !!icon.prefix) && !!icon.name);
167
169
  };
168
170
  function mergeIconTransformations(obj1, obj2) {
169
171
  const result = {};
@@ -278,10 +280,15 @@ function quicklyValidateIconSet(obj) {
278
280
  const icons = data.icons;
279
281
  for (const name in icons) {
280
282
  const icon = icons[name];
281
- if (!name.match(matchIconName) || typeof icon.body !== "string" || !checkOptionalProps(
282
- icon,
283
- defaultExtendedIconProps
284
- )) {
283
+ if (
284
+ // Name cannot be empty
285
+ !name || // Must have body
286
+ typeof icon.body !== "string" || // Check other props
287
+ !checkOptionalProps(
288
+ icon,
289
+ defaultExtendedIconProps
290
+ )
291
+ ) {
285
292
  return null;
286
293
  }
287
294
  }
@@ -289,10 +296,15 @@ function quicklyValidateIconSet(obj) {
289
296
  for (const name in aliases) {
290
297
  const icon = aliases[name];
291
298
  const parent = icon.parent;
292
- if (!name.match(matchIconName) || typeof parent !== "string" || !icons[parent] && !aliases[parent] || !checkOptionalProps(
293
- icon,
294
- defaultExtendedIconProps
295
- )) {
299
+ if (
300
+ // Name cannot be empty
301
+ !name || // Parent must be set and point to existing icon
302
+ typeof parent !== "string" || !icons[parent] && !aliases[parent] || // Check other props
303
+ !checkOptionalProps(
304
+ icon,
305
+ defaultExtendedIconProps
306
+ )
307
+ ) {
296
308
  return null;
297
309
  }
298
310
  }
@@ -370,7 +382,12 @@ function addIcon$1(name, data) {
370
382
  return false;
371
383
  }
372
384
  const storage2 = getStorage(icon.provider, icon.prefix);
373
- return addIconToStorage(storage2, icon.name, data);
385
+ if (data) {
386
+ return addIconToStorage(storage2, icon.name, data);
387
+ } else {
388
+ storage2.missing.add(icon.name);
389
+ return true;
390
+ }
374
391
  }
375
392
  function addCollection$1(data, provider) {
376
393
  if (typeof data !== "object") {
@@ -384,7 +401,7 @@ function addCollection$1(data, provider) {
384
401
  if (quicklyValidateIconSet(data)) {
385
402
  data.prefix = "";
386
403
  parseIconSet(data, (name, icon) => {
387
- if (icon && addIcon$1(name, icon)) {
404
+ if (addIcon$1(name, icon)) {
388
405
  added = true;
389
406
  }
390
407
  });
@@ -410,7 +427,7 @@ function getIcon$1(name) {
410
427
  return result ? {
411
428
  ...defaultIconProps,
412
429
  ...result
413
- } : null;
430
+ } : result;
414
431
  }
415
432
  function sortIcons(icons) {
416
433
  const result = {
@@ -1070,6 +1087,57 @@ function loadedNewIcons(storage2) {
1070
1087
  });
1071
1088
  }
1072
1089
  }
1090
+ function checkIconNamesForAPI(icons) {
1091
+ const valid = [];
1092
+ const invalid = [];
1093
+ icons.forEach((name) => {
1094
+ (name.match(matchIconName) ? valid : invalid).push(name);
1095
+ });
1096
+ return {
1097
+ valid,
1098
+ invalid
1099
+ };
1100
+ }
1101
+ function parseLoaderResponse(storage2, icons, data, isAPIResponse) {
1102
+ function checkMissing() {
1103
+ const pending = storage2.pendingIcons;
1104
+ icons.forEach((name) => {
1105
+ if (pending) {
1106
+ pending.delete(name);
1107
+ }
1108
+ if (!storage2.icons[name]) {
1109
+ storage2.missing.add(name);
1110
+ }
1111
+ });
1112
+ }
1113
+ if (data && typeof data === "object") {
1114
+ try {
1115
+ const parsed = addIconSet(storage2, data);
1116
+ if (!parsed.length) {
1117
+ checkMissing();
1118
+ return;
1119
+ }
1120
+ if (isAPIResponse) {
1121
+ storeInBrowserStorage(storage2, data);
1122
+ }
1123
+ } catch (err) {
1124
+ console.error(err);
1125
+ }
1126
+ }
1127
+ checkMissing();
1128
+ loadedNewIcons(storage2);
1129
+ }
1130
+ function parsePossiblyAsyncResponse(response, callback) {
1131
+ if (response instanceof Promise) {
1132
+ response.then((data) => {
1133
+ callback(data);
1134
+ }).catch(() => {
1135
+ callback(null);
1136
+ });
1137
+ } else {
1138
+ callback(response);
1139
+ }
1140
+ }
1073
1141
  function loadNewIcons(storage2, icons) {
1074
1142
  if (!storage2.iconsToLoad) {
1075
1143
  storage2.iconsToLoad = icons;
@@ -1083,38 +1151,50 @@ function loadNewIcons(storage2, icons) {
1083
1151
  const { provider, prefix } = storage2;
1084
1152
  const icons2 = storage2.iconsToLoad;
1085
1153
  delete storage2.iconsToLoad;
1086
- let api;
1087
- if (!icons2 || !(api = getAPIModule(provider))) {
1154
+ if (!icons2 || !icons2.length) {
1155
+ return;
1156
+ }
1157
+ const customIconLoader = storage2.loadIcon;
1158
+ if (storage2.loadIcons && (icons2.length > 1 || !customIconLoader)) {
1159
+ parsePossiblyAsyncResponse(
1160
+ storage2.loadIcons(icons2, prefix, provider),
1161
+ (data) => {
1162
+ parseLoaderResponse(storage2, icons2, data, false);
1163
+ }
1164
+ );
1088
1165
  return;
1089
1166
  }
1090
- const params = api.prepare(provider, prefix, icons2);
1167
+ if (customIconLoader) {
1168
+ icons2.forEach((name) => {
1169
+ const response = customIconLoader(name, prefix, provider);
1170
+ parsePossiblyAsyncResponse(response, (data) => {
1171
+ const iconSet = data ? {
1172
+ prefix,
1173
+ icons: {
1174
+ [name]: data
1175
+ }
1176
+ } : null;
1177
+ parseLoaderResponse(storage2, [name], iconSet, false);
1178
+ });
1179
+ });
1180
+ return;
1181
+ }
1182
+ const { valid, invalid } = checkIconNamesForAPI(icons2);
1183
+ if (invalid.length) {
1184
+ parseLoaderResponse(storage2, invalid, null, false);
1185
+ }
1186
+ if (!valid.length) {
1187
+ return;
1188
+ }
1189
+ const api = prefix.match(matchIconName) ? getAPIModule(provider) : null;
1190
+ if (!api) {
1191
+ parseLoaderResponse(storage2, valid, null, false);
1192
+ return;
1193
+ }
1194
+ const params = api.prepare(provider, prefix, valid);
1091
1195
  params.forEach((item) => {
1092
1196
  sendAPIQuery(provider, item, (data) => {
1093
- if (typeof data !== "object") {
1094
- item.icons.forEach((name) => {
1095
- storage2.missing.add(name);
1096
- });
1097
- } else {
1098
- try {
1099
- const parsed = addIconSet(
1100
- storage2,
1101
- data
1102
- );
1103
- if (!parsed.length) {
1104
- return;
1105
- }
1106
- const pending = storage2.pendingIcons;
1107
- if (pending) {
1108
- parsed.forEach((name) => {
1109
- pending.delete(name);
1110
- });
1111
- }
1112
- storeInBrowserStorage(storage2, data);
1113
- } catch (err) {
1114
- console.error(err);
1115
- }
1116
- }
1117
- loadedNewIcons(storage2);
1197
+ parseLoaderResponse(storage2, item.icons, data, true);
1118
1198
  });
1119
1199
  });
1120
1200
  });
@@ -1167,9 +1247,9 @@ const loadIcons$1 = (icons, callback) => {
1167
1247
  }
1168
1248
  });
1169
1249
  sources.forEach((storage2) => {
1170
- const { provider, prefix } = storage2;
1171
- if (newIcons[provider][prefix].length) {
1172
- loadNewIcons(storage2, newIcons[provider][prefix]);
1250
+ const list = newIcons[storage2.provider][storage2.prefix];
1251
+ if (list.length) {
1252
+ loadNewIcons(storage2, list);
1173
1253
  }
1174
1254
  });
1175
1255
  return callback ? storeCallback(callback, sortedIcons, sources) : emptyCallback;
@@ -1208,12 +1288,31 @@ function testIconObject(value) {
1208
1288
  }
1209
1289
  }
1210
1290
  function parseIconValue(value, onload) {
1211
- const name = typeof value === "string" ? stringToIcon(value, true, true) : null;
1212
- if (!name) {
1291
+ if (typeof value === "object") {
1213
1292
  const data2 = testIconObject(value);
1214
1293
  return {
1215
- value,
1216
- data: data2
1294
+ data: data2,
1295
+ value
1296
+ };
1297
+ }
1298
+ if (typeof value !== "string") {
1299
+ return {
1300
+ value
1301
+ };
1302
+ }
1303
+ if (value.includes("{")) {
1304
+ const data2 = testIconObject(value);
1305
+ if (data2) {
1306
+ return {
1307
+ data: data2,
1308
+ value
1309
+ };
1310
+ }
1311
+ }
1312
+ const name = stringToIcon(value, true, true);
1313
+ if (!name) {
1314
+ return {
1315
+ value
1217
1316
  };
1218
1317
  }
1219
1318
  const data = getIconData(name);
@@ -1239,6 +1338,7 @@ try {
1239
1338
  }
1240
1339
  function getRenderMode(body, mode) {
1241
1340
  switch (mode) {
1341
+ // Force mode
1242
1342
  case "svg":
1243
1343
  case "bg":
1244
1344
  case "mask":
@@ -1578,6 +1678,12 @@ const fetchAPIModule = {
1578
1678
  prepare,
1579
1679
  send
1580
1680
  };
1681
+ function setCustomIconsLoader$1(loader, prefix, provider) {
1682
+ getStorage(provider || "", prefix).loadIcons = loader;
1683
+ }
1684
+ function setCustomIconLoader$1(loader, prefix, provider) {
1685
+ getStorage(provider || "", prefix).loadIcon = loader;
1686
+ }
1581
1687
  function toggleBrowserCache(storage2, value) {
1582
1688
  switch (storage2) {
1583
1689
  case "local":
@@ -1603,7 +1709,7 @@ function updateStyle(parent, inline) {
1603
1709
  styleNode.setAttribute(nodeAttr, nodeAttr);
1604
1710
  parent.appendChild(styleNode);
1605
1711
  }
1606
- styleNode.textContent = ":host{display:inline-block;vertical-align:" + (inline ? "-0.125em" : "0") + "}span,svg{display:block}" + customStyle;
1712
+ styleNode.textContent = ":host{display:inline-block;vertical-align:" + (inline ? "-0.125em" : "0") + "}span,svg{display:block;margin:auto}" + customStyle;
1607
1713
  }
1608
1714
  function exportFunctions() {
1609
1715
  setAPIModule("", fetchAPIModule);
@@ -1680,6 +1786,8 @@ function exportFunctions() {
1680
1786
  loadIcons: loadIcons$1,
1681
1787
  loadIcon: loadIcon$1,
1682
1788
  addAPIProvider: addAPIProvider$1,
1789
+ setCustomIconLoader: setCustomIconLoader$1,
1790
+ setCustomIconsLoader: setCustomIconsLoader$1,
1683
1791
  appendCustomStyle,
1684
1792
  _api
1685
1793
  };
@@ -14,6 +14,7 @@ const _sfc_main = /* @__PURE__ */ vue.defineComponent({
14
14
  activeClass: {},
15
15
  exactActiveClass: {},
16
16
  ariaCurrentValue: {},
17
+ viewTransition: { type: Boolean },
17
18
  to: {},
18
19
  replace: { type: Boolean }
19
20
  },
@@ -1,10 +1,21 @@
1
1
  "use strict";
2
2
  const listKeyboardNavigation = require("./listKeyboardNavigation.js");
3
+ const floatingVue = require("floating-vue");
3
4
  const vue = require("vue");
4
5
  const _pluginVue_exportHelper = require("./chunks/_plugin-vue_export-helper.js");
5
6
  const ESCAPE_KEY = "Escape";
7
+ const nextFrame = () => {
8
+ return new Promise(
9
+ (resolve) => requestAnimationFrame(() => {
10
+ requestAnimationFrame(resolve);
11
+ })
12
+ );
13
+ };
6
14
  const _sfc_main = vue.defineComponent({
7
15
  name: "PDropdown",
16
+ components: {
17
+ Dropdown: floatingVue.Dropdown
18
+ },
8
19
  inheritAttrs: false,
9
20
  props: {
10
21
  /**
@@ -31,49 +42,24 @@ const _sfc_main = vue.defineComponent({
31
42
  default: () => ({
32
43
  display: "inline-block"
33
44
  })
34
- },
35
- /**
36
- * Custom reference element that is used to position the popper.
37
- * Can be changed at runtime to create a dynamically positioned dropdown.
38
- */
39
- reference: {
40
- type: HTMLElement,
41
- default: null
42
45
  }
43
46
  },
44
47
  data() {
45
48
  return {
46
49
  defaultAttrs: {
47
50
  triggers: ["click"],
48
- "auto-hide": true,
51
+ autoHide: true,
49
52
  theme: "p-dropdown-theme",
50
- "popper-class": "dropdown",
53
+ popperClass: "dropdown",
51
54
  placement: "bottom-start",
52
55
  distance: 4,
53
56
  delay: 0,
54
57
  handleResize: true
55
58
  },
56
- navigationSvc: null
59
+ navigationSvc: null,
60
+ prevReference: null
57
61
  };
58
62
  },
59
- watch: {
60
- reference: {
61
- async handler(nV, oV) {
62
- if (nV && oV !== nV) {
63
- const popper = this.$refs.vPopper.$refs.popper;
64
- if (popper) {
65
- popper.$_detachPopperNode();
66
- if (popper.shown) {
67
- popper.hide({ skipDelay: true });
68
- }
69
- if (this.reference) {
70
- popper.$_referenceNode = this.reference;
71
- }
72
- }
73
- }
74
- }
75
- }
76
- },
77
63
  mounted() {
78
64
  Object.assign(this.$refs.vPopper.$refs.popper.$el.style, this.triggerStyle);
79
65
  },
@@ -100,12 +86,32 @@ const _sfc_main = vue.defineComponent({
100
86
  var _a;
101
87
  (_a = this.navigationSvc) == null ? void 0 : _a.destroy();
102
88
  document.removeEventListener("keydown", this.popoverEscKeydown);
89
+ },
90
+ async updateReference(newReference) {
91
+ if (!newReference) {
92
+ throw Error("Reference element is required");
93
+ }
94
+ const popper = this.$refs.vPopper.$refs.popper;
95
+ if (popper) {
96
+ popper.$_detachPopperNode();
97
+ if (popper.isShown) {
98
+ popper.$emit("update:shown", false);
99
+ if (newReference === this.prevReference) {
100
+ return;
101
+ }
102
+ }
103
+ await nextFrame();
104
+ popper.$_referenceNode = newReference;
105
+ this.prevReference = newReference;
106
+ await nextFrame();
107
+ popper.$emit("update:shown", true);
108
+ }
103
109
  }
104
110
  }
105
111
  });
106
112
  function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
107
- const _component_VDropdown = vue.resolveComponent("VDropdown");
108
- return vue.openBlock(), vue.createBlock(_component_VDropdown, vue.mergeProps({ ref: "vPopper" }, { ..._ctx.defaultAttrs, ..._ctx.$attrs }, {
113
+ const _component_Dropdown = vue.resolveComponent("Dropdown");
114
+ return vue.openBlock(), vue.createBlock(_component_Dropdown, vue.mergeProps({ ref: "vPopper" }, { ..._ctx.defaultAttrs, ..._ctx.$attrs }, {
109
115
  onShow: _ctx.onShow,
110
116
  onHide: _ctx.destroy
111
117
  }), vue.createSlots({ _: 2 }, [