foldkit 0.47.0 → 0.47.1

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.
@@ -0,0 +1,3 @@
1
+ import type { Module } from 'snabbdom';
2
+ export declare const propsModule: Module;
3
+ //# sourceMappingURL=propsModule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"propsModule.d.ts","sourceRoot":"","sources":["../src/propsModule.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAyDtC,eAAO,MAAM,WAAW,EAAE,MAAqD,CAAA"}
@@ -0,0 +1,50 @@
1
+ /** A custom props module that extends snabbdom's built-in propsModule with
2
+ * proper cleanup of removed properties.
3
+ *
4
+ * Snabbdom's propsModule only iterates over _new_ props — it never resets
5
+ * old props that disappeared between renders. This means `elm.disabled = true`
6
+ * persists even after `Disabled(true)` is removed from the attribute array.
7
+ * Since a disabled button swallows click events at the browser level, an
8
+ * `OnClick` handler that replaces `Disabled` at the same index silently fails.
9
+ *
10
+ * This module adds a second loop (mirroring what snabbdom's attributesModule
11
+ * already does) that resets removed props to type-appropriate defaults:
12
+ * booleans → false, strings → '', numbers → 0. */
13
+ function updateProps(oldVnode, vnode) {
14
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
15
+ const elm = vnode.elm;
16
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
17
+ let oldProps = oldVnode.data?.props;
18
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
19
+ let props = vnode.data?.props;
20
+ if (!oldProps && !props) {
21
+ return;
22
+ }
23
+ if (oldProps === props) {
24
+ return;
25
+ }
26
+ oldProps = oldProps ?? {};
27
+ props = props ?? {};
28
+ for (const key in props) {
29
+ const cur = props[key];
30
+ const old = oldProps[key];
31
+ if (old !== cur && (key !== 'value' || elm[key] !== cur)) {
32
+ elm[key] = cur;
33
+ }
34
+ }
35
+ for (const key in oldProps) {
36
+ if (!(key in props)) {
37
+ const old = oldProps[key];
38
+ if (typeof old === 'boolean') {
39
+ elm[key] = false;
40
+ }
41
+ else if (typeof old === 'string') {
42
+ elm[key] = '';
43
+ }
44
+ else if (typeof old === 'number') {
45
+ elm[key] = 0;
46
+ }
47
+ }
48
+ }
49
+ }
50
+ export const propsModule = { create: updateProps, update: updateProps };
@@ -1 +1 @@
1
- {"version":3,"file":"vdom.d.ts","sourceRoot":"","sources":["../src/vdom.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,OAAO,EACR,MAAM,UAAU,CAAA;AAEjB,YAAY,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AACrC,OAAO,EAAE,OAAO,EAAE,CAAA;AAElB,eAAO,MAAM,KAAK,gIAOhB,CAAA"}
1
+ {"version":3,"file":"vdom.d.ts","sourceRoot":"","sources":["../src/vdom.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,OAAO,EACR,MAAM,UAAU,CAAA;AAIjB,YAAY,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AACrC,OAAO,EAAE,OAAO,EAAE,CAAA;AAElB,eAAO,MAAM,KAAK,gIAOhB,CAAA"}
package/dist/vdom.js CHANGED
@@ -1,4 +1,5 @@
1
- import { attributesModule, classModule, datasetModule, eventListenersModule, init, propsModule, styleModule, toVNode, } from 'snabbdom';
1
+ import { attributesModule, classModule, datasetModule, eventListenersModule, init, styleModule, toVNode, } from 'snabbdom';
2
+ import { propsModule } from './propsModule';
2
3
  export { toVNode };
3
4
  export const patch = init([
4
5
  attributesModule,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foldkit",
3
- "version": "0.47.0",
3
+ "version": "0.47.1",
4
4
  "description": "A frontend framework for TypeScript, built on Effect, using The Elm Architecture",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",