xpine 0.0.27 → 0.0.29
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 +8 -0
- package/dist/src/scripts/build.d.ts.map +1 -1
- package/dist/src/scripts/xpine-build.js +8 -0
- package/dist/src/scripts/xpine-dev.js +8 -0
- package/dist/src/static/spa.js +35 -13
- package/package.json +1 -1
- package/dist/src/util/hooks/onInit.d.ts +0 -3
- package/dist/src/util/hooks/onInit.d.ts.map +0 -1
package/dist/index.js
CHANGED
|
@@ -446,6 +446,7 @@ var doctypeHTML = "<!DOCTYPE html>";
|
|
|
446
446
|
var staticComment = "<!-- static -->";
|
|
447
447
|
|
|
448
448
|
// src/scripts/build.ts
|
|
449
|
+
import ts3 from "typescript";
|
|
449
450
|
var extensions = [".ts", ".tsx"];
|
|
450
451
|
var packageJson = JSON.parse(fs5.readFileSync(config.packageJsonPath, "utf-8"));
|
|
451
452
|
var allPackages = Object.keys(packageJson.devDependencies).concat(Object.keys(packageJson.dependencies));
|
|
@@ -560,6 +561,13 @@ async function buildAlpineDataFile(componentData, dataFiles) {
|
|
|
560
561
|
};
|
|
561
562
|
const componentsAndDataFiles = componentData.concat(dataFiles);
|
|
562
563
|
for (const component of componentsAndDataFiles) {
|
|
564
|
+
if (!component.source) {
|
|
565
|
+
component.source = ts3.createSourceFile(
|
|
566
|
+
component.path,
|
|
567
|
+
component.contents,
|
|
568
|
+
ts3.ScriptTarget.Latest
|
|
569
|
+
);
|
|
570
|
+
}
|
|
563
571
|
const dataFunctionResult = findDataAttributesAndFunctions(component.source, component.source);
|
|
564
572
|
dataFunctionResults.foundDataAttributes.push(...dataFunctionResult.foundDataAttributes);
|
|
565
573
|
const foundFunctionsWithPath = dataFunctionResult.foundFunctions.map((item) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/scripts/build.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,UAAU,EAA2B,aAAa,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/scripts/build.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,UAAU,EAA2B,aAAa,EAAE,MAAM,aAAa,CAAC;AAWjF,KAAK,YAAY,GAAG;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,CAAA;AAED,wBAAsB,QAAQ,CAAC,IAAI,EAAE,YAAY,iBAsBhD;AA8ID,wBAAsB,QAAQ,CAAC,eAAe,CAAC,EAAE,OAAO,iBAavD;AAGD,wBAAsB,yBAAyB,kBAgB9C;AAED,wBAAsB,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,GAAG,QAAQ,GAAG,KAAK,EAAE,eAAe,WAAkB,iBAahH;AAED,wBAAsB,qBAAqB,CAAC,aAAa,EAAE,aAAa,EAAE,iBAezE;AAED,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,eAAe,EAAE,GAAG,EAAE,kBAAkB,EAAE,MAAM,iBAgEpI;AAED,wBAAgB,wBAAwB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,EAAE,CAQxE;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,EAAE,EAAE,MAAM,CAAC;CACZ,CAAA;AAGD,wBAAsB,eAAe,CAAC,aAAa,EAAE,aAAa,EAAE,EAAE,KAAK,CAAC,EAAE,OAAO,iBAoDpF"}
|
|
@@ -441,6 +441,7 @@ var doctypeHTML = "<!DOCTYPE html>";
|
|
|
441
441
|
var staticComment = "<!-- static -->";
|
|
442
442
|
|
|
443
443
|
// src/scripts/build.ts
|
|
444
|
+
import ts3 from "typescript";
|
|
444
445
|
var extensions = [".ts", ".tsx"];
|
|
445
446
|
var packageJson = JSON.parse(fs5.readFileSync(config.packageJsonPath, "utf-8"));
|
|
446
447
|
var allPackages = Object.keys(packageJson.devDependencies).concat(Object.keys(packageJson.dependencies));
|
|
@@ -555,6 +556,13 @@ async function buildAlpineDataFile(componentData, dataFiles) {
|
|
|
555
556
|
};
|
|
556
557
|
const componentsAndDataFiles = componentData.concat(dataFiles);
|
|
557
558
|
for (const component of componentsAndDataFiles) {
|
|
559
|
+
if (!component.source) {
|
|
560
|
+
component.source = ts3.createSourceFile(
|
|
561
|
+
component.path,
|
|
562
|
+
component.contents,
|
|
563
|
+
ts3.ScriptTarget.Latest
|
|
564
|
+
);
|
|
565
|
+
}
|
|
558
566
|
const dataFunctionResult = findDataAttributesAndFunctions(component.source, component.source);
|
|
559
567
|
dataFunctionResults.foundDataAttributes.push(...dataFunctionResult.foundDataAttributes);
|
|
560
568
|
const foundFunctionsWithPath = dataFunctionResult.foundFunctions.map((item) => {
|
|
@@ -448,6 +448,7 @@ var doctypeHTML = "<!DOCTYPE html>";
|
|
|
448
448
|
var staticComment = "<!-- static -->";
|
|
449
449
|
|
|
450
450
|
// src/scripts/build.ts
|
|
451
|
+
import ts3 from "typescript";
|
|
451
452
|
var extensions = [".ts", ".tsx"];
|
|
452
453
|
var packageJson = JSON.parse(fs5.readFileSync(config.packageJsonPath, "utf-8"));
|
|
453
454
|
var allPackages = Object.keys(packageJson.devDependencies).concat(Object.keys(packageJson.dependencies));
|
|
@@ -562,6 +563,13 @@ async function buildAlpineDataFile(componentData, dataFiles) {
|
|
|
562
563
|
};
|
|
563
564
|
const componentsAndDataFiles = componentData.concat(dataFiles);
|
|
564
565
|
for (const component of componentsAndDataFiles) {
|
|
566
|
+
if (!component.source) {
|
|
567
|
+
component.source = ts3.createSourceFile(
|
|
568
|
+
component.path,
|
|
569
|
+
component.contents,
|
|
570
|
+
ts3.ScriptTarget.Latest
|
|
571
|
+
);
|
|
572
|
+
}
|
|
565
573
|
const dataFunctionResult = findDataAttributesAndFunctions(component.source, component.source);
|
|
566
574
|
dataFunctionResults.foundDataAttributes.push(...dataFunctionResult.foundDataAttributes);
|
|
567
575
|
const foundFunctionsWithPath = dataFunctionResult.foundFunctions.map((item) => {
|
package/dist/src/static/spa.js
CHANGED
|
@@ -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
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
114
|
-
const
|
|
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
|
|
117
|
-
|
|
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
|
|
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 +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"}
|