xpine 0.0.33 → 0.0.34

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 CHANGED
@@ -57,7 +57,10 @@ setupEnv also supports AWS secrets manager. Simply add SECRETS_NAME=your_aws_sec
57
57
  - spa-update-page-content
58
58
  - sent when the page content has update
59
59
  - spa-update-page-url
60
- - send when the page URL has update
60
+ - sent when the page URL has update
61
+ - spa-link-click
62
+ - sent when link initially gets clicked and when link is done updating content
63
+ - the "state" value in the event detail will be "start" or "end"
61
64
 
62
65
  #### Custom scripts for certain pages
63
66
 
@@ -13,8 +13,17 @@ async function updatePageOnLinkClick(e) {
13
13
  if (isExternal && !e?.target?.getAttribute("data-spa-crossorigin")) return;
14
14
  e.preventDefault();
15
15
  try {
16
+ if (targetHref === window.location.href) return;
17
+ const newURL = isExternal ? safeParseURL(targetHref) : safeParseURL(window.location.href);
18
+ const startEvent = new CustomEvent("spa-link-click", {
19
+ detail: {
20
+ state: "start",
21
+ href: targetHref,
22
+ url: newURL
23
+ }
24
+ });
25
+ window.dispatchEvent(startEvent);
16
26
  await getNewPageContent(targetHref);
17
- if (targetHref === window.location.pathname) return;
18
27
  window.history.pushState(
19
28
  {
20
29
  type: "link-click",
@@ -26,10 +35,18 @@ async function updatePageOnLinkClick(e) {
26
35
  const event = new CustomEvent("spa-update-page-url", {
27
36
  detail: {
28
37
  href: targetHref,
29
- url: isExternal ? safeParseURL(targetHref) : safeParseURL(window.location.href)
38
+ url: newURL
30
39
  }
31
40
  });
32
41
  window.dispatchEvent(event);
42
+ const endEvent = new CustomEvent("spa-link-click", {
43
+ detail: {
44
+ state: "end",
45
+ href: targetHref,
46
+ url: newURL
47
+ }
48
+ });
49
+ window.dispatchEvent(endEvent);
33
50
  } catch (err) {
34
51
  console.error(err);
35
52
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xpine",
3
- "version": "0.0.33",
3
+ "version": "0.0.34",
4
4
  "main": "dist/index.js",
5
5
  "dependencies": {
6
6
  "@aws-sdk/client-secrets-manager": "^3.758.0",