elegance-js 2.0.11 → 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.
@@ -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
- return state.subjects.find((s) => s.id === id);
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)) {
@@ -800,7 +800,6 @@ var buildPages = async (DIST_DIR2) => {
800
800
  if (isPage == false) {
801
801
  continue;
802
802
  }
803
- console.log("building page with", DIST_DIR2, `d: ${directory}`, filePath, name);
804
803
  try {
805
804
  const hardReloadForPage = await buildPage(DIST_DIR2, directory, filePath, name);
806
805
  if (hardReloadForPage) {
@@ -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
- bind?: number;
7
+ isGlobal: boolean;
8
8
  }) => {
9
9
  id: number;
10
10
  value: Widen<U>;
@@ -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)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "elegance-js",
3
- "version": "2.0.11",
3
+ "version": "2.0.12",
4
4
  "description": "Web-Framework",
5
5
  "type": "module",
6
6
  "bin": {