diff --git a/calcit.cirru b/calcit.cirru index 2e6c1fa..5245371 100644 --- a/calcit.cirru +++ b/calcit.cirru @@ -2374,6 +2374,11 @@ :code $ quote $ defunion StateKey Tag String Number :examples $ [] :schema $ quote UnionDef + 'TextInputEvent $ %{} 'CodeEntry (:doc |) + :code $ quote $ defunion TextInputEvent respo.schema/RespoEvent + Map Tag $ JsNullish String + :examples $ [] + :schema $ quote UnionDef 'command $ %{} 'CodeEntry (:doc |) :code $ quote $ def command {} (:id nil) (:title |) (:path |.) (:code |) @@ -2468,15 +2473,18 @@ 'event-value $ %{} 'CodeEntry :doc "|Text value of an input event. Respo passes a RespoEvent struct; tests and legacy callers pass a map." :code $ quote $ defn event-value (event) - let - fields $ if (struct? event) (&struct:to-map event) - decode-map-as event $ Map Tag Dynamic - match (get fields :value) - (:some value) + match event + (respo.schema/RespoEvent input) + let + value $ :value input if (nil? value) | $ decode-map-as value 'String - (:none) | + (Map fields) + match (get fields :value) + (:some value) + if (js-nullish? value) | $ decode-map-as value 'String + (:none) | :examples $ [] - :schema $ quote $ Fn Dynamic (-> String) + :schema $ quote $ Fn TextInputEvent (-> String) (:features :js-ffi) 'field-or $ %{} 'CodeEntry :doc "|Read an optional wire field. A missing or nil field gives the fallback." :code $ quote $ defn field-or (fields field fallback) diff --git a/tests/components.test.mjs b/tests/components.test.mjs index 2f1c822..5f05a08 100644 --- a/tests/components.test.mjs +++ b/tests/components.test.mjs @@ -15,6 +15,7 @@ import { comp_container, decode_view } from '../out-page/app.comp.container.mjs' import { Op, decode_changes, op_to_wire } from '../out-page/app.schema.mjs'; import { patch_twig } from '../out-page/recollect.patch.mjs'; import { websocket_url, clear_current_route_$x_ } from '../out-page/app.util.mjs'; +import { event__GT_edn } from '../out-page/respo.util.format.mjs'; const tags = c.init_tags(['tree', 'children', 'node', 'key', 'name', 'attrs', 'event', 'input', 'click', 'value', 'inner-text', 'title', 'code', 'path', 'command', 'cwd', 'router', 'count', 'color']); const read = (value, key) => c.option_$o_unwrap(c.get(value, tags[key])); @@ -115,7 +116,10 @@ test('command editor preserves legacy draft values, edits each field and submits const inputs = nodes.filter(node => read(node, 'name').value === 'input'); assert.deepEqual(values(inputs), ['合成🐈', 'never-run', './sandbox']); for (const [index, field] of ['title', 'code', 'path'].entries()) { - read(read(inputs[index], 'event'), 'input')(parse('{} (:value |更新🌱)'), dispatch); + const event = index === 0 + ? event__GT_edn({ type: 'input', target: { value: '更新🌱', checked: false } }) + : parse('{} (:value |更新🌱)'); + read(read(inputs[index], 'event'), 'input')(event, dispatch); const args = calls.at(-1); assert.equal(args.length, 1); assert.equal(part(args[0], 0).value, 'states');