boto-rb-web 0.34.0 → 0.34.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: efaa259cf78b84f8b78b45cb4e36452a982fba79986b5ecdf1f873c8eda9f0c9
4
- data.tar.gz: be3d173870a9acf1553f890e337cc9d736522ccca6aec8d6e3a4e42b68d60602
3
+ metadata.gz: c1a08dcbea002d4a065df5be90aa92457b9499f29b6a0c9895aeca748ec6ce8f
4
+ data.tar.gz: b83063d20b0f30efd56cda07ee1e9a67f666148daae063198a36f27cdef42dac
5
5
  SHA512:
6
- metadata.gz: 6b91aa308677c69355585d9db3989fabd180a454c4153a8bf5d442d707296fcbfefbefb582cf7432c4e7e7d4e82278c5d2ffd363d7174b6ab3511b791eaccdee
7
- data.tar.gz: 5a261461c3671cf05306ada26d9e0f41ca8245ec71a9498a8ef96216b323e295f26209b148808a199d53445695b566d6afbc16aaeebd62b89089c9ed45bac92b
6
+ metadata.gz: 5f07000e55c81cc9b331681a2f849916de69d1805c28db456349314adc180e29174aafe15dd77a7623d87f8bc6c6c176ed05c4aeb94630ac9f866f6ebd7dcc04
7
+ data.tar.gz: 8a57786346ac7c4335250c9985df6c3700ef1fee5385915544d5bb8a1c9d53cae8f0ad96e3d189235bac3d4f13688b95de11e7793b44e2e078c3c1d252927108
@@ -4,7 +4,7 @@ import { batch, effect } from "./signals.js";
4
4
  import { createScope } from "./scope.js";
5
5
  import { readPayload } from "../net/token.js";
6
6
  import { morph, ownerOf } from "../dom/morph.js";
7
- import { MODEL_EVENTS, declaredTypes, eventData, listen } from "./events.js";
7
+ import { MODEL_EVENTS, declaredTypes, eventData, listen, typedModels } from "./events.js";
8
8
  import { actionEnvelope, blockEnvelope, refreshEnvelope } from "../net/protocol.js";
9
9
 
10
10
  const INPUT_DELAY_MS = 100;
@@ -21,6 +21,9 @@ export function pathOf(root) {
21
21
  export function mountComponent(root, { module, runtime }) {
22
22
  const scope = createScope({ module, payload: readPayload(root.dataset.snapshot) });
23
23
  const context = { root, module, scope, runtime, timers: new WeakMap(), listened: new Set() };
24
+ // Text typed before the mount wins over the snapshot, so the first render keeps it.
25
+ const typed = typedModels(root);
26
+ for (const { el, value } of typed) scope.setModel(el.dataset.model, value);
24
27
 
25
28
  effect(() => {
26
29
  morph(root, module.render(scope.$));
@@ -33,6 +36,8 @@ export function mountComponent(root, { module, runtime }) {
33
36
  });
34
37
  for (const type of MODEL_EVENTS) listen(context, type, invokeHandler);
35
38
  for (const [id, deps] of Object.entries(module.blocks ?? {})) watchBlock(context, id, deps);
39
+ // Replayed once the listeners exist, so the field's handlers run as if the typing came after the mount.
40
+ for (const { el } of typed) el.dispatchEvent(new Event(modelEvent(el), { bubbles: true }));
36
41
 
37
42
  // A burst of input changes sends one refresh, INPUT_DELAY_MS after the last one.
38
43
  const refreshInputs = () => exchange(context, (params) => refreshEnvelope({ ...params, inputs: scope.inputs() }));
@@ -48,6 +53,8 @@ export function mountComponent(root, { module, runtime }) {
48
53
  };
49
54
  }
50
55
 
56
+ const modelEvent = (el) => (el.localName === "select" || el.type === "checkbox" || el.type === "radio" ? "change" : "input");
57
+
51
58
  // The data-inputs the parent's render writes on each direct child reach that child.
52
59
  export function syncChildInputs(root, runtime) {
53
60
  for (const el of root.querySelectorAll("[data-component][data-inputs]")) {
@@ -17,6 +17,21 @@ export function listen(context, type, invoke) {
17
17
  });
18
18
  }
19
19
 
20
+ // The [(model)] fields of root the user changed before the mount: the value differs from the one the server wrote.
21
+ export function typedModels(root) {
22
+ return [...root.querySelectorAll("[data-model]")]
23
+ .filter((el) => ownerOf(el) === root)
24
+ .map((el) => ({ el, value: typedValue(el) }))
25
+ .filter(({ value }) => value !== undefined);
26
+ }
27
+
28
+ export function typedValue(el) {
29
+ if (el.type === "checkbox") return el.checked === el.defaultChecked ? undefined : el.checked;
30
+ if (el.type === "radio") return el.checked && !el.defaultChecked ? el.value : undefined;
31
+ if (el.localName === "select") return [...el.options].some((o) => o.selected !== o.defaultSelected) ? el.value : undefined;
32
+ return el.value === el.defaultValue ? undefined : el.value;
33
+ }
34
+
20
35
  function assignModel({ root, scope }, ev) {
21
36
  const el = ev.target.closest("[data-model]");
22
37
  if (!el || ownerOf(el) !== root) return;
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Boto
4
4
  module Web
5
- VERSION = "0.34.0"
5
+ VERSION = "0.34.1"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: boto-rb-web
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.34.0
4
+ version: 0.34.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evo Tech Builder
@@ -15,28 +15,28 @@ dependencies:
15
15
  requirements:
16
16
  - - '='
17
17
  - !ruby/object:Gem::Version
18
- version: 0.34.0
18
+ version: 0.34.1
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - '='
24
24
  - !ruby/object:Gem::Version
25
- version: 0.34.0
25
+ version: 0.34.1
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: boto-rb-security
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
30
30
  - - '='
31
31
  - !ruby/object:Gem::Version
32
- version: 0.34.0
32
+ version: 0.34.1
33
33
  type: :runtime
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - '='
38
38
  - !ruby/object:Gem::Version
39
- version: 0.34.0
39
+ version: 0.34.1
40
40
  description: 'Stateful views and components for Boto: server-rendered pages that react
41
41
  in the browser.'
42
42
  executables: []