xpine 0.0.28 → 0.0.30

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.js CHANGED
@@ -121,10 +121,12 @@ function createContext(value) {
121
121
  },
122
122
  runArrayQueue() {
123
123
  Object.keys(arrayQueue).forEach((key) => {
124
- arrayQueue[key].sort((a, b) => {
125
- return (a?.position ?? Infinity) - (b.position ?? Infinity);
126
- });
127
- for (const item of arrayQueue[key]) {
124
+ const dates = arrayQueue[key].filter((item) => item?.position instanceof Date);
125
+ const numbers = arrayQueue[key].filter((item) => typeof item?.position === "number" || !item?.position);
126
+ const sortedDates = dates.toSorted((a, b) => b?.position.getTime() - a?.position.getTime());
127
+ const sortedNumbers = numbers.toSorted((a, b) => (a?.position ?? Infinity) - (b.position ?? Infinity));
128
+ const output = sortedNumbers.concat(sortedDates);
129
+ for (const item of output) {
128
130
  this.set(key, item.value, []);
129
131
  }
130
132
  });
@@ -4,7 +4,7 @@ export type State<StateProps> = {
4
4
  set: (id: string, callback: SetContext<StateProps>, defaultValue?: any) => void;
5
5
  clear: () => void;
6
6
  getAll: () => any;
7
- addToArray: (id: string, value: any, position?: number) => void;
7
+ addToArray: (id: string, value: any, position?: number | Date) => void;
8
8
  getArrayQueue: () => any;
9
9
  runArrayQueue: () => void;
10
10
  };
@@ -1 +1 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/context.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,CAAC,IAAI,IAAI,CAAC,cAAc,EAAE,IAAI,KAAK,IAAI,CAAC;AAE9D,MAAM,MAAM,KAAK,CAAC,UAAU,IAAI;IAC9B,GAAG,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,UAAU,CAAC;IAChC,GAAG,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,CAAC,UAAU,CAAC,EAAE,YAAY,CAAC,EAAE,GAAG,KAAK,IAAI,CAA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C;IACzB,aAAa,EAAE,MAAM,IAAI,CAAC;CAC3B,CAAA;AAED,KAAK,WAAW,CAAC,IAAI,IAAI;IACvB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB,CAAA;AAQD,wBAAgB,aAAa,CAAC,KAAK,EAAE,WAAW,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAmDjE;AAED,eAAO,MAAM,OAAO,YAAoB,CAAC;AAEzC,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,GAAG,EAAE,QAAQ,CAAC,EAAE,MAAM,kBACjC,GAAG,SAYnC"}
@@ -116,10 +116,12 @@ function createContext(value) {
116
116
  },
117
117
  runArrayQueue() {
118
118
  Object.keys(arrayQueue).forEach((key) => {
119
- arrayQueue[key].sort((a, b) => {
120
- return (a?.position ?? Infinity) - (b.position ?? Infinity);
121
- });
122
- for (const item of arrayQueue[key]) {
119
+ const dates = arrayQueue[key].filter((item) => item?.position instanceof Date);
120
+ const numbers = arrayQueue[key].filter((item) => typeof item?.position === "number" || !item?.position);
121
+ const sortedDates = dates.toSorted((a, b) => b?.position.getTime() - a?.position.getTime());
122
+ const sortedNumbers = numbers.toSorted((a, b) => (a?.position ?? Infinity) - (b.position ?? Infinity));
123
+ const output = sortedNumbers.concat(sortedDates);
124
+ for (const item of output) {
123
125
  this.set(key, item.value, []);
124
126
  }
125
127
  });
@@ -123,10 +123,12 @@ function createContext(value) {
123
123
  },
124
124
  runArrayQueue() {
125
125
  Object.keys(arrayQueue).forEach((key) => {
126
- arrayQueue[key].sort((a, b) => {
127
- return (a?.position ?? Infinity) - (b.position ?? Infinity);
128
- });
129
- for (const item of arrayQueue[key]) {
126
+ const dates = arrayQueue[key].filter((item) => item?.position instanceof Date);
127
+ const numbers = arrayQueue[key].filter((item) => typeof item?.position === "number" || !item?.position);
128
+ const sortedDates = dates.toSorted((a, b) => b?.position.getTime() - a?.position.getTime());
129
+ const sortedNumbers = numbers.toSorted((a, b) => (a?.position ?? Infinity) - (b.position ?? Infinity));
130
+ const output = sortedNumbers.concat(sortedDates);
131
+ for (const item of output) {
130
132
  this.set(key, item.value, []);
131
133
  }
132
134
  });
@@ -40,16 +40,26 @@ async function getNewPageContent(href) {
40
40
  const dom = parser.parseFromString(text, "text/html");
41
41
  diffHead(dom);
42
42
  const newScripts = removeBodyScripts(dom);
43
- const clonedPersistentNodes = getPersistentNodesFromDocument(dom);
44
- const body = dom.body.innerHTML;
45
- document.body.innerHTML = body;
46
- for (const clonedNode of clonedPersistentNodes) {
47
- const newNode = document.body.querySelector(`[data-persistent="${clonedNode?.getAttribute("data-persistent")}"]`);
48
- newNode.replaceWith(clonedNode);
43
+ const { persistentArea, persistentElements } = replacePersistentNodesOnDocument(dom);
44
+ const documentRoot = document.body.querySelector("#xpine-root");
45
+ const domRoot = dom?.body?.querySelector("#xpine-root");
46
+ if (!documentRoot || !domRoot) {
47
+ throw {
48
+ message: "Every page must be wrapped in an #xpine-root tag",
49
+ documentRoot,
50
+ domRoot
51
+ };
49
52
  }
53
+ documentRoot?.replaceWith(domRoot);
54
+ for (const el of persistentElements) {
55
+ const newNode = document.body.querySelector(`[data-persistent="${el?.getAttribute("data-persistent")}"]`);
56
+ newNode.replaceWith(el);
57
+ }
58
+ persistentArea.remove();
50
59
  replaceAttributesOnDocumentBody(dom);
51
60
  replaceDocumentContentsWithLinkResponse();
52
- for (const script of newScripts) document.body.appendChild(script);
61
+ const newDocumentRoot = document.body.querySelector("#xpine-root");
62
+ for (const script of newScripts) newDocumentRoot.appendChild(script);
53
63
  const event = new CustomEvent("spa:updatePageContent", {
54
64
  detail: {
55
65
  href
@@ -100,7 +110,7 @@ function removeBodyScripts(dom) {
100
110
  const element = document.createElement("script");
101
111
  portAttributesToElement(script, element);
102
112
  element.innerHTML = script.innerHTML;
103
- dom.body.removeChild(script);
113
+ script.remove();
104
114
  newElements.push(element);
105
115
  }
106
116
  return newElements;
@@ -110,13 +120,25 @@ function portAttributesToElement(oldEl, newEl) {
110
120
  newEl.setAttribute(attribute.name, attribute.nodeValue);
111
121
  }
112
122
  }
113
- function getPersistentNodesFromDocument(dom) {
114
- const persistentNodesFromDom = [...dom.querySelectorAll("[data-persistent]")].map((el) => el.getAttribute("data-persistent"));
123
+ function replacePersistentNodesOnDocument(dom) {
124
+ const persistentArea = document.createElement("div");
125
+ persistentArea.style.display = "none";
126
+ document.body.appendChild(persistentArea);
127
+ const domPersistentNodes = [...dom.querySelectorAll("[data-persistent]")];
128
+ const persistentNodesFromDom = domPersistentNodes.map((el) => el.getAttribute("data-persistent"));
115
129
  const persistentNodesFromBody = [...document.body.querySelectorAll("[data-persistent]")];
116
- const validPersistentNodes = persistentNodesFromBody.filter((el) => {
117
- return persistentNodesFromDom.includes(el.getAttribute("data-persistent"));
130
+ const persistentElements = [];
131
+ persistentNodesFromBody.forEach((el) => {
132
+ const persistentAttribute = el.getAttribute("data-persistent");
133
+ if (!persistentNodesFromDom.includes(persistentAttribute)) return false;
134
+ dom.querySelector(`[data-persistent="${persistentAttribute}"]`).innerHTML = "";
135
+ persistentArea.appendChild(el);
136
+ persistentElements.push(el);
118
137
  });
119
- return validPersistentNodes.map((el) => el.cloneNode(true));
138
+ return {
139
+ persistentElements,
140
+ persistentArea
141
+ };
120
142
  }
121
143
  function replaceAttributesOnDocumentBody(dom) {
122
144
  while (document.body.attributes.length > 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xpine",
3
- "version": "0.0.28",
3
+ "version": "0.0.30",
4
4
  "main": "dist/index.js",
5
5
  "dependencies": {
6
6
  "@aws-sdk/client-secrets-manager": "^3.758.0",
@@ -0,0 +1,4 @@
1
+ {
2
+ "status": "failed",
3
+ "failedTests": []
4
+ }
@@ -1,3 +0,0 @@
1
- import { ConfigFile } from "../../../types";
2
- export default function createOnInit(onInit: ConfigFile['onInit']): () => Promise<void>;
3
- //# sourceMappingURL=onInit.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"onInit.d.ts","sourceRoot":"","sources":["../../../../src/util/hooks/onInit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAI5C,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,MAAM,EAAE,UAAU,CAAC,QAAQ,CAAC,uBAOhE"}