elegance-js 2.0.10 → 2.0.12
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/client/client.mjs +21 -1
- package/dist/index.mjs +1 -2
- package/dist/page_compiler.mjs +4 -1
- package/dist/server/state.d.ts +1 -1
- package/dist/server/state.mjs +1 -2
- package/package.json +1 -1
package/dist/client/client.mjs
CHANGED
|
@@ -177,6 +177,16 @@ var sanitizePathname = (pn) => {
|
|
|
177
177
|
return pn.slice(0, -1);
|
|
178
178
|
};
|
|
179
179
|
var currentPage = sanitizePathname(loc.pathname);
|
|
180
|
+
function getAllPaths(pathname) {
|
|
181
|
+
const sanitized = pathname.endsWith("/") && pathname !== "/" ? pathname.slice(0, -1) : pathname;
|
|
182
|
+
const parts = sanitized.split("/").filter(Boolean);
|
|
183
|
+
const subpaths = [
|
|
184
|
+
"/",
|
|
185
|
+
...parts.map((_, i) => "/" + parts.slice(0, i + 1).join("/"))
|
|
186
|
+
];
|
|
187
|
+
if (sanitized === "/") return ["/"];
|
|
188
|
+
return subpaths;
|
|
189
|
+
}
|
|
180
190
|
var createStateManager = (subjects) => {
|
|
181
191
|
const state = {
|
|
182
192
|
subjects: subjects.map((subject) => {
|
|
@@ -203,7 +213,17 @@ var createStateManager = (subjects) => {
|
|
|
203
213
|
Bind is deprecated, but kept as a paramater to not upset legacy code.
|
|
204
214
|
*/
|
|
205
215
|
get: (id, bind) => {
|
|
206
|
-
|
|
216
|
+
const subject = state.subjects.find((s) => s.id === id);
|
|
217
|
+
if (subject) return subject;
|
|
218
|
+
const stack = getAllPaths(currentPage);
|
|
219
|
+
for (const item of stack) {
|
|
220
|
+
const sanitized = sanitizePathname(item);
|
|
221
|
+
const data = ld[sanitized];
|
|
222
|
+
if (!data) continue;
|
|
223
|
+
const entry = data.stateManager.get(id);
|
|
224
|
+
if (entry) return entry;
|
|
225
|
+
}
|
|
226
|
+
return void 0;
|
|
207
227
|
},
|
|
208
228
|
/**
|
|
209
229
|
Bind is deprecated, but kept as a paramater to not upset legacy code.
|
package/dist/index.mjs
CHANGED
|
@@ -57,8 +57,7 @@ var state = (value, options) => {
|
|
|
57
57
|
const serverStateEntry = {
|
|
58
58
|
id: __SERVER_CURRENT_STATE_ID__ += 1,
|
|
59
59
|
value,
|
|
60
|
-
type: 1 /* STATE
|
|
61
|
-
bind: options?.bind
|
|
60
|
+
type: 1 /* STATE */
|
|
62
61
|
};
|
|
63
62
|
globalThis.__SERVER_CURRENT_STATE__.push(serverStateEntry);
|
|
64
63
|
if (Array.isArray(value)) {
|
package/dist/page_compiler.mjs
CHANGED
|
@@ -549,6 +549,10 @@ var pageToHTML = async (pageLocation, pageElements, metadata, DIST_DIR2, pageNam
|
|
|
549
549
|
const resultHTML = `${headHTML}${bodyHTML}`;
|
|
550
550
|
const htmlLocation = path.join(pageLocation, (pageName === "page" ? "index" : pageName) + ".html");
|
|
551
551
|
if (doWrite) {
|
|
552
|
+
const dirname = path.dirname(htmlLocation);
|
|
553
|
+
if (fs.existsSync(dirname) === false) {
|
|
554
|
+
fs.mkdirSync(dirname, { recursive: true });
|
|
555
|
+
}
|
|
552
556
|
fs.writeFileSync(
|
|
553
557
|
htmlLocation,
|
|
554
558
|
resultHTML,
|
|
@@ -796,7 +800,6 @@ var buildPages = async (DIST_DIR2) => {
|
|
|
796
800
|
if (isPage == false) {
|
|
797
801
|
continue;
|
|
798
802
|
}
|
|
799
|
-
console.log("building page with", DIST_DIR2, `d: ${directory}`, filePath, name);
|
|
800
803
|
try {
|
|
801
804
|
const hardReloadForPage = await buildPage(DIST_DIR2, directory, filePath, name);
|
|
802
805
|
if (hardReloadForPage) {
|
package/dist/server/state.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ type ClientSubjectGeneric<T> = Omit<ClientSubject, "value"> & {
|
|
|
4
4
|
};
|
|
5
5
|
type Widen<T> = T extends number ? number : T extends string ? string : T extends boolean ? boolean : T extends {} ? T & Record<string, any> : T;
|
|
6
6
|
export declare const state: <U extends number | string | boolean | {} | undefined | null | Array<any>>(value: U, options?: {
|
|
7
|
-
|
|
7
|
+
isGlobal: boolean;
|
|
8
8
|
}) => {
|
|
9
9
|
id: number;
|
|
10
10
|
value: Widen<U>;
|
package/dist/server/state.mjs
CHANGED
|
@@ -28,8 +28,7 @@ var state = (value, options) => {
|
|
|
28
28
|
const serverStateEntry = {
|
|
29
29
|
id: __SERVER_CURRENT_STATE_ID__ += 1,
|
|
30
30
|
value,
|
|
31
|
-
type: 1 /* STATE
|
|
32
|
-
bind: options?.bind
|
|
31
|
+
type: 1 /* STATE */
|
|
33
32
|
};
|
|
34
33
|
globalThis.__SERVER_CURRENT_STATE__.push(serverStateEntry);
|
|
35
34
|
if (Array.isArray(value)) {
|