@inglorious/web 6.4.1 → 6.5.0

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
@@ -1290,10 +1290,12 @@ const renderApp = (api) => {
1290
1290
  <p>Loading: ${geolocation.isLoading ? "yes" : "no"}</p>
1291
1291
  <p>
1292
1292
  Position:
1293
- ${position
1294
- ? html`${position.coords.latitude.toFixed(4)},
1295
- ${position.coords.longitude.toFixed(4)}`
1296
- : "unknown"}
1293
+ ${
1294
+ position
1295
+ ? html`${position.coords.latitude.toFixed(4)},
1296
+ ${position.coords.longitude.toFixed(4)}`
1297
+ : "unknown"
1298
+ }
1297
1299
  </p>
1298
1300
  <p>Error: ${geolocation.error ? geolocation.error.message : "none"}</p>
1299
1301
  <button
@@ -1383,9 +1385,11 @@ const renderApp = (api) => {
1383
1385
  <p>Active: ${compass.isCompassActive ? "yes" : "no"}</p>
1384
1386
  <p>
1385
1387
  Heading:
1386
- ${compass.heading !== null
1387
- ? `${compass.heading.toFixed(1)}°`
1388
- : "unknown"}
1388
+ ${
1389
+ compass.heading !== null
1390
+ ? `${compass.heading.toFixed(1)}°`
1391
+ : "unknown"
1392
+ }
1389
1393
  </p>
1390
1394
  <p>Error: ${compass.error ? compass.error.message : "none"}</p>
1391
1395
  <button @click=${() => api.notify("compassPermissionsRequest")}>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inglorious/web",
3
- "version": "6.4.1",
3
+ "version": "6.5.0",
4
4
  "description": "A new web framework that leverages the power of the Inglorious Store combined with the performance and simplicity of lit-html.",
5
5
  "author": "Matteo Antony Mistretta <antony.mistretta@gmail.com> (https://ingloriouscoderz.it)",
6
6
  "contributors": [
@@ -104,17 +104,17 @@
104
104
  },
105
105
  "sideEffects": false,
106
106
  "dependencies": {
107
- "@inglorious/utils": "3.8.0",
107
+ "@inglorious/utils": "4.0.0",
108
108
  "@lit-labs/ssr-client": "^1.1.8",
109
- "lit-html": "^3.3.1"
109
+ "lit-html": "^3.3.3"
110
110
  },
111
111
  "peerDependencies": {
112
- "@inglorious/store": "11.0.1"
112
+ "@inglorious/store": "11.0.2"
113
113
  },
114
114
  "devDependencies": {
115
115
  "@inglorious/eslint-config": "1.1.2",
116
- "prettier": "^3.6.2",
117
- "vitest": "^4.0.15"
116
+ "prettier": "^3.9.6",
117
+ "vitest": "^5.0.0"
118
118
  },
119
119
  "engines": {
120
120
  "node": ">= 22"
@@ -1,4 +1,4 @@
1
- import { debounce } from "@inglorious/utils/functions/functions.js"
1
+ import { debounce } from "@inglorious/utils/functions"
2
2
 
3
3
  /**
4
4
  * Wraps selected event handlers of a type with debouncing, scoped per-entity.
@@ -1,4 +1,4 @@
1
- import { throttle } from "@inglorious/utils/functions/functions.js"
1
+ import { throttle } from "@inglorious/utils/functions"
2
2
 
3
3
  /**
4
4
  * Wraps selected event handlers of a type with throttling, scoped per-entity.
@@ -1,4 +1,4 @@
1
- import { clone, get, set } from "@inglorious/utils/data-structures/object.js"
1
+ import { clone, get, set } from "@inglorious/utils/object.js"
2
2
 
3
3
  /**
4
4
  * @typedef {import('../../types/form.js').FormEntity} FormEntity
@@ -1,4 +1,4 @@
1
- import { get } from "@inglorious/utils/data-structures/object.js"
1
+ import { get } from "@inglorious/utils/object.js"
2
2
 
3
3
  /**
4
4
  * Retrieves the validation error for a specific form field.
@@ -8,6 +8,8 @@ import { toCamelCase } from "@inglorious/utils/data-structures/string.js"
8
8
 
9
9
  const SKIP_FULL_MATCH_GROUP = 1 // .match() result at index 0 is the full string
10
10
  const REMOVE_COLON_PREFIX = 1
11
+ const FIRST_HISTORY_INDEX = 0 // The entry an app starts on, and the fallback for an entry that carries no index.
12
+ const PUSH_HISTORY_STEP = 1 // How far a push advances the index. A replacement leaves it where it is.
11
13
 
12
14
  export function createHandlers(routeConfig) {
13
15
  /**
@@ -25,6 +27,18 @@ export function createHandlers(routeConfig) {
25
27
  * @param {Api} api - The application API.
26
28
  */
27
29
  init(entity, payload, api) {
30
+ /* Stamp the entry the app starts on, so that reloading keeps the app in
31
+ its place in the session history instead of restarting the count.
32
+ `withTransitions` reads this index back to tell a push from a traversal
33
+ and in which direction, so it has to be set before anything navigates. */
34
+ if (window.history.state?.idx == null) {
35
+ window.history.replaceState(
36
+ { ...window.history.state, idx: FIRST_HISTORY_INDEX },
37
+ "",
38
+ )
39
+ }
40
+ entity.idx = window.history.state?.idx ?? FIRST_HISTORY_INDEX
41
+
28
42
  // Handle initial route
29
43
  const { pathname, search } = window.location
30
44
  const initialPath = pathname + search
@@ -107,6 +121,9 @@ export function createHandlers(routeConfig) {
107
121
  }
108
122
 
109
123
  updateRouter(entity, route)
124
+ // Adopt the index of the entry just traversed, so the next push counts
125
+ // from where the history actually is rather than from where it was.
126
+ entity.idx = window.history.state?.idx ?? FIRST_HISTORY_INDEX
110
127
 
111
128
  api.notify("routeChange", {
112
129
  route: entity.route,
@@ -184,6 +201,10 @@ export function createHandlers(routeConfig) {
184
201
  // Prepare history state
185
202
  const historyState = {
186
203
  ...state,
204
+ /* Written before the notification that triggers the render, so that
205
+ anything reading the history entry during that render sees the new
206
+ index. `withTransitions` depends on this ordering. */
207
+ idx: replace ? entity.idx : entity.idx + PUSH_HISTORY_STEP,
187
208
  route: entity.route,
188
209
  params: entity.params,
189
210
  query: entity.query,
@@ -193,6 +214,9 @@ export function createHandlers(routeConfig) {
193
214
  // Navigate
194
215
  const method = replace ? "replaceState" : "pushState"
195
216
  history[method](historyState, "", path)
217
+ // Advance the counter as well as stamping the entry, or the next push
218
+ // writes the same index and reads as a replacement.
219
+ entity.idx = historyState.idx
196
220
 
197
221
  api.notify("routeChange", historyState)
198
222
  },
@@ -3,8 +3,7 @@ import { Api } from "../mount"
3
3
  export interface DebounceBehavior {
4
4
  destroy?: (entity: any, payload?: any, api?: Api) => void
5
5
  [handlerName: string]:
6
- | ((entity: any, payload?: any, api?: Api) => void)
7
- | undefined
6
+ ((entity: any, payload?: any, api?: Api) => void) | undefined
8
7
  }
9
8
 
10
9
  export declare function withDebounce(
@@ -7,8 +7,7 @@ export interface ThrottleOptions {
7
7
  export interface ThrottleBehavior {
8
8
  destroy?: (entity: any, payload?: any, api?: Api) => void
9
9
  [handlerName: string]:
10
- | ((entity: any, payload?: any, api?: Api) => void)
11
- | undefined
10
+ ((entity: any, payload?: any, api?: Api) => void) | undefined
12
11
  }
13
12
 
14
13
  export declare function withThrottle(