@abgov/web-components 1.15.0 → 1.15.1-alpha.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abgov/web-components",
3
- "version": "1.15.0",
3
+ "version": "1.15.1-alpha.1",
4
4
  "description": "Government of Alberta - UI Web components",
5
5
  "bugs": {
6
6
  "url": "https://github.com/GovAlta/ui-components/issues"
@@ -11,7 +11,7 @@
11
11
  "semantic-release": "semantic-release",
12
12
  "main": "web-components.es.js",
13
13
  "unpkg": "web-components.es.js",
14
- "module": "web-components.umd.js",
14
+ "module": "web-components.es.js",
15
15
  "scripts": {
16
16
  "dev": "rollup -c rollup.config.js -w",
17
17
  "playground": "rollup -c rollup.playground.config.js -w",
@@ -26176,6 +26176,32 @@ class Pages extends SvelteElement {
26176
26176
 
26177
26177
  customElements.define("goa-pages", Pages);
26178
26178
 
26179
+ function isUrlMatch(windowUrl, testUrl) {
26180
+ if (testUrl === void 0)
26181
+ return -1;
26182
+ const windowUrlParts = windowUrl.pathname.replace(/^\//, "").split("/");
26183
+ const urlParts = testUrl.replace(/^\//, "").split("/");
26184
+ if (windowUrlParts.length < urlParts.length) {
26185
+ return -1;
26186
+ }
26187
+ if (windowUrl.hash.length > 0 && windowUrl.hash === testUrl) {
26188
+ return 1;
26189
+ }
26190
+ if (urlParts.length === 1 && urlParts[0] === "") {
26191
+ return 0;
26192
+ }
26193
+ let weight = -1;
26194
+ let index = 0;
26195
+ for (const part of windowUrlParts) {
26196
+ if (urlParts[index] !== part) {
26197
+ break;
26198
+ }
26199
+ weight += 1;
26200
+ index++;
26201
+ }
26202
+ return weight >= 0 ? weight + 1 : weight;
26203
+ }
26204
+
26179
26205
  /* src/components/side-menu/SideMenu.svelte generated by Svelte v3.59.2 */
26180
26206
 
26181
26207
  function create_fragment$4(ctx) {
@@ -26207,11 +26233,11 @@ function instance$4($$self, $$props, $$invalidate) {
26207
26233
 
26208
26234
  onMount(async () => {
26209
26235
  await tick();
26210
- setCurrent(window.location.toString());
26236
+ setCurrentUrl();
26211
26237
  addEventListeners();
26212
26238
  });
26213
26239
 
26214
- function setCurrent(url) {
26240
+ function setCurrentUrl() {
26215
26241
  const slot = _rootEl.querySelector("slot");
26216
26242
 
26217
26243
  if (!slot) {
@@ -26219,16 +26245,23 @@ function instance$4($$self, $$props, $$invalidate) {
26219
26245
  }
26220
26246
 
26221
26247
  const links = slot.assignedElements().filter(el => el.tagName === "A");
26248
+ let currentEl;
26249
+ let maxWeight = 0;
26222
26250
 
26223
26251
  links.forEach(child => {
26224
- const current = url.endsWith(child.getAttribute("href"));
26252
+ const weight = isUrlMatch(document.location, child.getAttribute("href"));
26225
26253
 
26226
- if (current) {
26227
- child.classList.add("current");
26228
- } else {
26229
- child.classList.remove("current");
26254
+ if (weight > maxWeight) {
26255
+ maxWeight = weight;
26256
+ currentEl = child;
26230
26257
  }
26258
+
26259
+ child.classList.remove("current");
26231
26260
  });
26261
+
26262
+ if (currentEl) {
26263
+ currentEl.classList.add("current");
26264
+ }
26232
26265
  }
26233
26266
 
26234
26267
  function addEventListeners() {
@@ -26236,9 +26269,9 @@ function instance$4($$self, $$props, $$invalidate) {
26236
26269
  let currentLocation = document.location.href;
26237
26270
 
26238
26271
  const observer = new MutationObserver(_mutationList => {
26239
- if (currentLocation !== document.location.href) {
26272
+ if (isUrlMatch(document.location, currentLocation)) {
26240
26273
  currentLocation = document.location.href;
26241
- setCurrent(currentLocation);
26274
+ setCurrentUrl();
26242
26275
  }
26243
26276
  });
26244
26277
 
@@ -26246,7 +26279,7 @@ function instance$4($$self, $$props, $$invalidate) {
26246
26279
 
26247
26280
  // watch hash / browser history changes
26248
26281
  window.addEventListener("popstate", () => {
26249
- setCurrent(document.location.href);
26282
+ setCurrentUrl();
26250
26283
  });
26251
26284
  }
26252
26285
 
@@ -26310,7 +26343,7 @@ function create_else_block(ctx) {
26310
26343
  };
26311
26344
  }
26312
26345
 
26313
- // (189:4) {#if _open}
26346
+ // (193:4) {#if _open}
26314
26347
  function create_if_block$2(ctx) {
26315
26348
  let goa_icon;
26316
26349
 
@@ -26424,24 +26457,6 @@ function toSlug(path) {
26424
26457
  : path.toLowerCase().replace(/ /g, "-");
26425
26458
  }
26426
26459
 
26427
- function matchesChild(el, url) {
26428
- if (url.endsWith(toSlug(el.heading))) {
26429
- return true;
26430
- }
26431
-
26432
- const slot = el.querySelector("slot");
26433
-
26434
- if (!slot) {
26435
- return false;
26436
- }
26437
-
26438
- const children = slot.assignedElements();
26439
-
26440
- return !!children.find(child => {
26441
- return url.endsWith(child.getAttribute("href"));
26442
- });
26443
- }
26444
-
26445
26460
  function instance$3($$self, $$props, $$invalidate) {
26446
26461
  let _slug;
26447
26462
  let { heading } = $$props;
@@ -26457,8 +26472,7 @@ function instance$3($$self, $$props, $$invalidate) {
26457
26472
  });
26458
26473
 
26459
26474
  function checkUrlMatches() {
26460
- const url = window.location.href;
26461
- $$invalidate(1, _open = matchesMenu(url) || matchesChild(_rootEl, url));
26475
+ $$invalidate(1, _open = matchesMenu() || matchesChild(_rootEl));
26462
26476
 
26463
26477
  if (_open) {
26464
26478
  notifyParent(true);
@@ -26491,12 +26505,29 @@ function instance$3($$self, $$props, $$invalidate) {
26491
26505
  });
26492
26506
  }
26493
26507
 
26494
- function matchesMenu(url) {
26495
- return url.endsWith(_slug);
26508
+ function matchesMenu() {
26509
+ return isUrlMatch(document.location, _slug) >= 0;
26510
+ }
26511
+
26512
+ function matchesChild(el) {
26513
+ if (isUrlMatch(document.location, toSlug(el.heading)) >= 0) {
26514
+ return true;
26515
+ }
26516
+
26517
+ const slot = el.querySelector("slot");
26518
+
26519
+ if (!slot) {
26520
+ return false;
26521
+ }
26522
+
26523
+ const children = slot.assignedElements();
26524
+
26525
+ return !!children.find(child => {
26526
+ return isUrlMatch(document.location, child.getAttribute("href")) >= 0;
26527
+ });
26496
26528
  }
26497
26529
 
26498
26530
  function setCurrent() {
26499
- const url = document.location.href;
26500
26531
  const slot = _rootEl.querySelector("slot");
26501
26532
 
26502
26533
  if (!slot) {
@@ -26504,24 +26535,32 @@ function instance$3($$self, $$props, $$invalidate) {
26504
26535
  }
26505
26536
 
26506
26537
  const children = slot.assignedElements();
26538
+ let maxMatchWeight = -1;
26539
+ let matchedChild = null;
26507
26540
  $$invalidate(2, _current = false);
26508
26541
 
26509
26542
  children.forEach(child => {
26510
- const current = url.endsWith(child.getAttribute("href"));
26543
+ const url = child.getAttribute("href");
26544
+ const weight = isUrlMatch(document.location, url);
26511
26545
 
26512
- if (current) {
26513
- $$invalidate(2, _current = true);
26514
- child.classList.add("current");
26515
- notifyParent(true);
26516
- } else {
26517
- child.classList.remove("current");
26546
+ if (weight > maxMatchWeight) {
26547
+ maxMatchWeight = weight;
26548
+ matchedChild = child;
26518
26549
  }
26519
26550
 
26551
+ child.classList.remove("current");
26552
+
26520
26553
  // get side-menu-group (level >= 2) marked as children
26521
26554
  if (child.tagName === "GOA-SIDE-MENU-GROUP") {
26522
26555
  child.setAttribute("child", "true");
26523
26556
  }
26524
26557
  });
26558
+
26559
+ if (matchedChild) {
26560
+ $$invalidate(2, _current = true);
26561
+ matchedChild.classList.add("current");
26562
+ notifyParent(true);
26563
+ }
26525
26564
  }
26526
26565
 
26527
26566
  function handleClick(e) {