@inglorious/web 6.1.2 → 6.2.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/LICENSE
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright © 2025 Inglorious Coderz Srl.
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
-
|
|
7
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
-
|
|
9
|
-
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright © 2025 Inglorious Coderz Srl.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inglorious/web",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.2.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": "IceOnFire <antony.mistretta@gmail.com> (https://ingloriouscoderz.it)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -30,6 +30,10 @@
|
|
|
30
30
|
"types": "./types/compass.d.ts",
|
|
31
31
|
"import": "./src/compass/index.js"
|
|
32
32
|
},
|
|
33
|
+
"./decorators/with-debounce": {
|
|
34
|
+
"types": "./types/decorators/with-debounce.d.ts",
|
|
35
|
+
"import": "./src/decorators/with-debounce/index.js"
|
|
36
|
+
},
|
|
33
37
|
"./directives/*": {
|
|
34
38
|
"types": "./types/directives/*.d.ts",
|
|
35
39
|
"import": "./src/directives/*.js"
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { debounce } from "@inglorious/utils/functions/functions.js"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Wraps selected event handlers of a type with debouncing, scoped per-entity.
|
|
5
|
+
*
|
|
6
|
+
* IMPORTANT: because state is managed with `mutative`, the `entity` object
|
|
7
|
+
* passed into a handler is a draft proxy that gets revoked as soon as the
|
|
8
|
+
* current update tick finishes. Debounced calls fire *later*, on their own
|
|
9
|
+
* timer, well after that draft is dead. So we must never close over `entity`
|
|
10
|
+
* itself across the debounce boundary — only its primitive `id`. When the
|
|
11
|
+
* debounced callback actually runs, we re-fetch a live entity from the
|
|
12
|
+
* current state via `api.getEntity(entityId)`. Primitives and `payload` are safe to
|
|
13
|
+
* hold onto as-is; only draft/entity references are not.
|
|
14
|
+
*
|
|
15
|
+
* @param {number|Object} config - Either a single delay (ms) applied to all
|
|
16
|
+
* handlers listed in `handlerNames`, or a map of handlerName -> delay (ms).
|
|
17
|
+
* @param {string[]} [handlerNames] - Handler names to debounce. Required when
|
|
18
|
+
* `config` is a single number; ignored when `config` is a map (its keys
|
|
19
|
+
* are used instead).
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* // same delay for every listed handler
|
|
23
|
+
* const types = {
|
|
24
|
+
* AutosaveForm: [Form, withDebounce(500, ["saveData"])],
|
|
25
|
+
* }
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* // per-handler delays
|
|
29
|
+
* const types = {
|
|
30
|
+
* SearchBox: [Combobox, withDebounce({ optionsLoad: 300, saveQuery: 800 })],
|
|
31
|
+
* }
|
|
32
|
+
*/
|
|
33
|
+
export function withDebounce(config, handlerNames) {
|
|
34
|
+
const delays =
|
|
35
|
+
typeof config === "number"
|
|
36
|
+
? Object.fromEntries(handlerNames.map((name) => [name, config]))
|
|
37
|
+
: config
|
|
38
|
+
|
|
39
|
+
return (type) => {
|
|
40
|
+
// one debounced-fn map per entity, so instances don't share timers
|
|
41
|
+
const debouncedByEntity = new Map()
|
|
42
|
+
|
|
43
|
+
const behavior = {}
|
|
44
|
+
|
|
45
|
+
for (const handlerName of Object.keys(delays)) {
|
|
46
|
+
const originalHandler = type[handlerName]
|
|
47
|
+
if (!originalHandler) continue // nothing to wrap if the base type doesn't define it
|
|
48
|
+
|
|
49
|
+
behavior[handlerName] = (entity, payload, api) => {
|
|
50
|
+
const entityId = entity.id // capture the primitive now, while the draft is live
|
|
51
|
+
|
|
52
|
+
let perEntity = debouncedByEntity.get(entityId)
|
|
53
|
+
if (!perEntity) {
|
|
54
|
+
perEntity = {}
|
|
55
|
+
debouncedByEntity.set(entityId, perEntity)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (!perEntity[handlerName]) {
|
|
59
|
+
perEntity[handlerName] = debounce((entityId, payload, api) => {
|
|
60
|
+
const liveEntity = api.getEntity(entityId) // fresh, live reference
|
|
61
|
+
if (!liveEntity) return // entity was destroyed before the debounce fired
|
|
62
|
+
originalHandler(liveEntity, payload, api)
|
|
63
|
+
}, delays[handlerName])
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
perEntity[handlerName](entityId, payload, api)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// clean up any pending timers when the entity is destroyed
|
|
71
|
+
behavior.destroy = (entity, payload, api) => {
|
|
72
|
+
const entityId = entity.id // same rule applies here: capture before it's gone
|
|
73
|
+
|
|
74
|
+
const perEntity = debouncedByEntity.get(entityId)
|
|
75
|
+
if (perEntity) {
|
|
76
|
+
Object.values(perEntity).forEach((d) => d.cancel())
|
|
77
|
+
debouncedByEntity.delete(entityId)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
type.destroy?.(entity, payload, api)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return behavior
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Api } from "../mount"
|
|
2
|
+
|
|
3
|
+
export interface DebounceBehavior {
|
|
4
|
+
destroy?: (entity: any, payload?: any, api?: Api) => void
|
|
5
|
+
[handlerName: string]:
|
|
6
|
+
| ((entity: any, payload?: any, api?: Api) => void)
|
|
7
|
+
| undefined
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export declare function withDebounce(
|
|
11
|
+
config: number | Record<string, number>,
|
|
12
|
+
handlerNames?: string[],
|
|
13
|
+
): <T extends Record<string, any>>(type: T) => DebounceBehavior
|
package/types/form.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Api } from "./mount"
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Represents the structure of form values, which can be a nested object.
|
|
3
5
|
*/
|
|
@@ -286,7 +288,7 @@ export interface FormType {
|
|
|
286
288
|
validateAsync<T extends FormValues>(
|
|
287
289
|
entity: FormEntity<T>,
|
|
288
290
|
payload: FormValidateAsyncPayload<T>,
|
|
289
|
-
api:
|
|
291
|
+
api: Api,
|
|
290
292
|
): Promise<void>
|
|
291
293
|
|
|
292
294
|
/**
|