@yaks/ux 0.0.0-stage → 0.2.36

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.
Files changed (286) hide show
  1. package/Answer.js +43 -0
  2. package/Answer.js.map +1 -0
  3. package/Answer.ts +84 -0
  4. package/Conversation.js +520 -0
  5. package/Conversation.js.map +1 -0
  6. package/Conversation.ts +649 -0
  7. package/ConversationBox.js +106 -0
  8. package/ConversationBox.js.map +1 -0
  9. package/ConversationBox.ts +198 -0
  10. package/ConversationLines.js +29 -0
  11. package/ConversationLines.js.map +1 -0
  12. package/ConversationLines.ts +48 -0
  13. package/Disclosure.js +79 -0
  14. package/Disclosure.js.map +1 -0
  15. package/Disclosure.ts +130 -0
  16. package/Edit.js +330 -0
  17. package/Edit.js.map +1 -0
  18. package/Edit.ts +488 -0
  19. package/EntityPopup.js +35 -0
  20. package/EntityPopup.js.map +1 -0
  21. package/EntityPopup.ts +52 -0
  22. package/Fields.js +161 -0
  23. package/Fields.js.map +1 -0
  24. package/Fields.ts +276 -0
  25. package/LICENSE +202 -0
  26. package/Order.js +105 -0
  27. package/Order.js.map +1 -0
  28. package/Order.ts +159 -0
  29. package/README.md +1023 -2
  30. package/Save.js +50 -0
  31. package/Save.js.map +1 -0
  32. package/Save.ts +115 -0
  33. package/Sort.js +49 -0
  34. package/Sort.js.map +1 -0
  35. package/Sort.ts +98 -0
  36. package/Submit.js +115 -0
  37. package/Submit.js.map +1 -0
  38. package/Submit.ts +174 -0
  39. package/Text.js +114 -0
  40. package/Text.js.map +1 -0
  41. package/Text.ts +140 -0
  42. package/TokenPicker.js +65 -0
  43. package/TokenPicker.js.map +1 -0
  44. package/TokenPicker.ts +117 -0
  45. package/_dist/Answer.d.ts +39 -0
  46. package/_dist/Answer.d.ts.map +1 -0
  47. package/_dist/Conversation.d.ts +131 -0
  48. package/_dist/Conversation.d.ts.map +1 -0
  49. package/_dist/ConversationBox.d.ts +29 -0
  50. package/_dist/ConversationBox.d.ts.map +1 -0
  51. package/_dist/ConversationLines.d.ts +13 -0
  52. package/_dist/ConversationLines.d.ts.map +1 -0
  53. package/_dist/Disclosure.d.ts +36 -0
  54. package/_dist/Disclosure.d.ts.map +1 -0
  55. package/_dist/Edit.d.ts +87 -0
  56. package/_dist/Edit.d.ts.map +1 -0
  57. package/_dist/EntityPopup.d.ts +12 -0
  58. package/_dist/EntityPopup.d.ts.map +1 -0
  59. package/_dist/Fields.d.ts +29 -0
  60. package/_dist/Fields.d.ts.map +1 -0
  61. package/_dist/Order.d.ts +40 -0
  62. package/_dist/Order.d.ts.map +1 -0
  63. package/_dist/Save.d.ts +28 -0
  64. package/_dist/Save.d.ts.map +1 -0
  65. package/_dist/Sort.d.ts +28 -0
  66. package/_dist/Sort.d.ts.map +1 -0
  67. package/_dist/Submit.d.ts +48 -0
  68. package/_dist/Submit.d.ts.map +1 -0
  69. package/_dist/Text.d.ts +27 -0
  70. package/_dist/Text.d.ts.map +1 -0
  71. package/_dist/TokenPicker.d.ts +19 -0
  72. package/_dist/TokenPicker.d.ts.map +1 -0
  73. package/_dist/anchor.d.ts +52 -0
  74. package/_dist/anchor.d.ts.map +1 -0
  75. package/_dist/anchored.d.ts +30 -0
  76. package/_dist/anchored.d.ts.map +1 -0
  77. package/_dist/completion-state.d.ts +65 -0
  78. package/_dist/completion-state.d.ts.map +1 -0
  79. package/_dist/completion.d.ts +73 -0
  80. package/_dist/completion.d.ts.map +1 -0
  81. package/_dist/composer-browser.d.ts +1 -0
  82. package/_dist/composer-browser.d.ts.map +1 -0
  83. package/_dist/composer.d.ts +31 -0
  84. package/_dist/composer.d.ts.map +1 -0
  85. package/_dist/context-menu-browser.d.ts +4 -0
  86. package/_dist/context-menu-browser.d.ts.map +1 -0
  87. package/_dist/context-menu.d.ts +95 -0
  88. package/_dist/context-menu.d.ts.map +1 -0
  89. package/_dist/drag.d.ts +29 -0
  90. package/_dist/drag.d.ts.map +1 -0
  91. package/_dist/edit-keys.d.ts +42 -0
  92. package/_dist/edit-keys.d.ts.map +1 -0
  93. package/_dist/emit.d.ts +7 -0
  94. package/_dist/emit.d.ts.map +1 -0
  95. package/_dist/entity-popup-browser.d.ts +3 -0
  96. package/_dist/entity-popup-browser.d.ts.map +1 -0
  97. package/_dist/face/FaceTagger.d.ts +25 -0
  98. package/_dist/face/FaceTagger.d.ts.map +1 -0
  99. package/_dist/face/review.d.ts +5 -0
  100. package/_dist/face/review.d.ts.map +1 -0
  101. package/_dist/face/tags.d.ts +99 -0
  102. package/_dist/face/tags.d.ts.map +1 -0
  103. package/_dist/field-values.d.ts +4 -0
  104. package/_dist/field-values.d.ts.map +1 -0
  105. package/_dist/fit-list.d.ts +4 -0
  106. package/_dist/fit-list.d.ts.map +1 -0
  107. package/_dist/hits.d.ts +27 -0
  108. package/_dist/hits.d.ts.map +1 -0
  109. package/_dist/host.d.ts +91 -0
  110. package/_dist/host.d.ts.map +1 -0
  111. package/_dist/image-fallback.d.ts +5 -0
  112. package/_dist/image-fallback.d.ts.map +1 -0
  113. package/_dist/keys.d.ts +95 -0
  114. package/_dist/keys.d.ts.map +1 -0
  115. package/_dist/kit.d.ts +23 -0
  116. package/_dist/kit.d.ts.map +1 -0
  117. package/_dist/lightbox-browser.d.ts +2 -0
  118. package/_dist/lightbox-browser.d.ts.map +1 -0
  119. package/_dist/lightbox.d.ts +42 -0
  120. package/_dist/lightbox.d.ts.map +1 -0
  121. package/_dist/live.d.ts +21 -0
  122. package/_dist/live.d.ts.map +1 -0
  123. package/_dist/mod.d.ts +67 -0
  124. package/_dist/mod.d.ts.map +1 -0
  125. package/_dist/read.d.ts +12 -0
  126. package/_dist/read.d.ts.map +1 -0
  127. package/_dist/resize.d.ts +43 -0
  128. package/_dist/resize.d.ts.map +1 -0
  129. package/_dist/rows.d.ts +31 -0
  130. package/_dist/rows.d.ts.map +1 -0
  131. package/_dist/save-browser.d.ts +29 -0
  132. package/_dist/save-browser.d.ts.map +1 -0
  133. package/_dist/select-browser.d.ts +1 -0
  134. package/_dist/select-browser.d.ts.map +1 -0
  135. package/_dist/select.d.ts +12 -0
  136. package/_dist/select.d.ts.map +1 -0
  137. package/_dist/sending.d.ts +10 -0
  138. package/_dist/sending.d.ts.map +1 -0
  139. package/_dist/sort-browser.d.ts +11 -0
  140. package/_dist/sort-browser.d.ts.map +1 -0
  141. package/_dist/state.d.ts +74 -0
  142. package/_dist/state.d.ts.map +1 -0
  143. package/_dist/suggest.d.ts +18 -0
  144. package/_dist/suggest.d.ts.map +1 -0
  145. package/_dist/swipe.d.ts +60 -0
  146. package/_dist/swipe.d.ts.map +1 -0
  147. package/_dist/ui.d.ts +6 -0
  148. package/_dist/ui.d.ts.map +1 -0
  149. package/_dist/upload-browser.d.ts +13 -0
  150. package/_dist/upload-browser.d.ts.map +1 -0
  151. package/_dist/views.d.ts +8 -0
  152. package/_dist/views.d.ts.map +1 -0
  153. package/_dist/vocab.d.ts +6 -0
  154. package/_dist/vocab.d.ts.map +1 -0
  155. package/anchor.js +58 -0
  156. package/anchor.js.map +1 -0
  157. package/anchor.ts +87 -0
  158. package/anchored.js +180 -0
  159. package/anchored.js.map +1 -0
  160. package/anchored.ts +232 -0
  161. package/completion-state.js +76 -0
  162. package/completion-state.js.map +1 -0
  163. package/completion-state.ts +120 -0
  164. package/completion.js +301 -0
  165. package/completion.js.map +1 -0
  166. package/completion.ts +433 -0
  167. package/composer-browser.js +4 -0
  168. package/composer-browser.js.map +1 -0
  169. package/composer-browser.ts +5 -0
  170. package/composer.js +42 -0
  171. package/composer.js.map +1 -0
  172. package/composer.ts +53 -0
  173. package/context-menu-browser.js +221 -0
  174. package/context-menu-browser.js.map +1 -0
  175. package/context-menu-browser.ts +231 -0
  176. package/context-menu.js +146 -0
  177. package/context-menu.js.map +1 -0
  178. package/context-menu.ts +194 -0
  179. package/deno.json +1 -0
  180. package/drag.js +33 -0
  181. package/drag.js.map +1 -0
  182. package/drag.ts +41 -0
  183. package/edit-keys.js +51 -0
  184. package/edit-keys.js.map +1 -0
  185. package/edit-keys.ts +81 -0
  186. package/emit.js +34 -0
  187. package/emit.js.map +1 -0
  188. package/emit.ts +55 -0
  189. package/entity-popup-browser.js +94 -0
  190. package/entity-popup-browser.js.map +1 -0
  191. package/entity-popup-browser.ts +100 -0
  192. package/face/FaceTagger.js +361 -0
  193. package/face/FaceTagger.js.map +1 -0
  194. package/face/FaceTagger.ts +507 -0
  195. package/face/NameProposal.js +61 -0
  196. package/face/NameProposal.js.map +1 -0
  197. package/face/NameProposal.ts +100 -0
  198. package/face/review.js +33 -0
  199. package/face/review.js.map +1 -0
  200. package/face/review.ts +49 -0
  201. package/face/tags.js +344 -0
  202. package/face/tags.js.map +1 -0
  203. package/face/tags.ts +357 -0
  204. package/field-values.js +20 -0
  205. package/field-values.js.map +1 -0
  206. package/field-values.ts +35 -0
  207. package/fit-list.js +66 -0
  208. package/fit-list.js.map +1 -0
  209. package/fit-list.ts +81 -0
  210. package/hits.js +65 -0
  211. package/hits.js.map +1 -0
  212. package/hits.ts +75 -0
  213. package/host.js +88 -0
  214. package/host.js.map +1 -0
  215. package/host.ts +212 -0
  216. package/image-fallback.js +32 -0
  217. package/image-fallback.js.map +1 -0
  218. package/image-fallback.ts +37 -0
  219. package/keys.js +418 -0
  220. package/keys.js.map +1 -0
  221. package/keys.ts +444 -0
  222. package/kit.js +41 -0
  223. package/kit.js.map +1 -0
  224. package/kit.ts +71 -0
  225. package/lightbox-browser.js +248 -0
  226. package/lightbox-browser.js.map +1 -0
  227. package/lightbox-browser.ts +232 -0
  228. package/lightbox.js +84 -0
  229. package/lightbox.js.map +1 -0
  230. package/lightbox.ts +103 -0
  231. package/live.js +111 -0
  232. package/live.js.map +1 -0
  233. package/live.ts +139 -0
  234. package/mod.js +67 -0
  235. package/mod.js.map +1 -0
  236. package/mod.ts +180 -0
  237. package/package.json +143 -4
  238. package/read.js +33 -0
  239. package/read.js.map +1 -0
  240. package/read.ts +56 -0
  241. package/resize.js +159 -0
  242. package/resize.js.map +1 -0
  243. package/resize.ts +203 -0
  244. package/rows.js +73 -0
  245. package/rows.js.map +1 -0
  246. package/rows.ts +97 -0
  247. package/save-browser.js +469 -0
  248. package/save-browser.js.map +1 -0
  249. package/save-browser.ts +530 -0
  250. package/select-browser.js +4 -0
  251. package/select-browser.js.map +1 -0
  252. package/select-browser.ts +5 -0
  253. package/select.js +296 -0
  254. package/select.js.map +1 -0
  255. package/select.ts +343 -0
  256. package/sending.js +36 -0
  257. package/sending.js.map +1 -0
  258. package/sending.ts +44 -0
  259. package/sort-browser.js +51 -0
  260. package/sort-browser.js.map +1 -0
  261. package/sort-browser.ts +70 -0
  262. package/state.js +99 -0
  263. package/state.js.map +1 -0
  264. package/state.ts +121 -0
  265. package/suggest.js +28 -0
  266. package/suggest.js.map +1 -0
  267. package/suggest.ts +32 -0
  268. package/swipe.js +186 -0
  269. package/swipe.js.map +1 -0
  270. package/swipe.ts +250 -0
  271. package/ui.js +507 -0
  272. package/ui.js.map +1 -0
  273. package/ui.ts +378 -0
  274. package/upload-browser.js +195 -0
  275. package/upload-browser.js.map +1 -0
  276. package/upload-browser.ts +303 -0
  277. package/upload-files.js +41 -0
  278. package/upload-files.js.map +1 -0
  279. package/upload-files.ts +49 -0
  280. package/views.js +8 -0
  281. package/views.js.map +1 -0
  282. package/views.ts +9 -0
  283. package/vocab.js +16 -0
  284. package/vocab.js.map +1 -0
  285. package/vocab.json +287 -0
  286. package/vocab.ts +17 -0
package/README.md CHANGED
@@ -1,3 +1,1024 @@
1
- # Temporary Holding Version
1
+ # @yaks/ux
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Controlled components for React and Preact that handle editing properties,
4
+ opening disclosures, completing input, rendering controlled fields and
5
+ submitting durable drafts. Component state lives in a page graph; drafts and
6
+ emitted bundles belong to the caller.
7
+
8
+ A **UX component** supplies behavior between [@yaks/ui](../ui/README.md)'s
9
+ presentation and an application's data. It takes a
10
+ [bundle](../graph/README.md#data-model) and emits a bundle through `onChange`,
11
+ or through its host's `write` when `onChange` is absent. Its state is a
12
+ [component](../graph/README.md#data-model) in the page's
13
+ [graph](../graph/README.md#data-model), rather than private component state.
14
+
15
+ A **host** (`Host`) supplies the vocabulary, page graph, drafts, writes and
16
+ presentation callbacks to UX components. `Ux` passes it down the tree. An
17
+ **owner** is the consumer named by `Ux`'s `at`; nested names join with `/`.
18
+ Owners distinguish two editors of the same property while their
19
+ [draft](../draft/README.md) is shared by the property's place (`place`).
20
+
21
+ A **face** is a property's presentation at rest. A **control** changes that
22
+ property while its `Edit` state is open. `Edit` selects both from the property's
23
+ [vocabulary](../vocab/README.md#vocabulary) declaration.
24
+
25
+ ## Behavior lookup
26
+
27
+ A screen takes its behavior from here the way it takes its parts from
28
+ [@yaks/ui's component lookup](../ui/README.md#component-lookup). A behavior this
29
+ table lacks goes into this package, where every screen and both hosts get it,
30
+ never into the one screen that needs it first.
31
+
32
+ | A screen needs | Use |
33
+ | --------------------------------------------------------------------- | --------------------------------------------------------------------------- |
34
+ | a value changed where it stands, Enter keeping it and Escape undoing | `Edit`, `Edit.Text`, `Text` |
35
+ | a chat or log that stays at the newest line and draws earlier ones | `Conversation` (`@yaks/ux/conversation`) |
36
+ | a box to write in whose words survive a reload and a failed send | `Conversation.Box`, over the host's [drafts](../draft/README.md) |
37
+ | a form kept as a draft until its save is answered, saying why not | `Submit` with `Fields`; `bindSave` (`@yaks/ux/save`) on a server-drawn page |
38
+ | a list that says loading, empty or could not load from its query | `Answer` over `useAnswered`; `useRows` for the rows alone |
39
+ | an edit shown at once, put back with the refusal's words if refused | `useStoreEdit` |
40
+ | a fold that remembers being open | `Disclosure`, `Fold` |
41
+ | rows put in order, or an entity moved between lists, by dragging | `Order`, `drag` |
42
+ | a table sorted by a column | `Sort` (`@yaks/ux/sort`) |
43
+ | several values picked by typing | `TokenPicker` (`@yaks/ux/token-picker`), `completion` for what is offered |
44
+ | Enter keeping and Escape cancelling in an editor of no one property | `editKeys` (`@yaks/ux/edit-keys`) |
45
+ | one choice among several, walked by key and found by typing | `selecting` (`@yaks/ux/select`) over @yaks/ui `Select` |
46
+ | keys walking the page, and Escape closing the front layer | `walk` and `keymap` (`@yaks/ux/keys`) |
47
+ | Escape closing a layer no kit part draws (a server's, a frame's) | `layer` (`@yaks/ux/keys`); a kit part's own `onCancel` |
48
+ | files dropped, picked or pasted, uploaded with resume | `bindUploads` (`@yaks/ux/upload`) |
49
+ | a form's button showing the send it is waiting on | `@yaks/ux/sending` |
50
+ | a picture attachment opened over the page, zoomed and stepped through | `LightboxShell` (`@yaks/ux/lightbox`) and `lightboxes` (`-browser`) |
51
+ | a sidebar opened by a sideways swipe | `@yaks/ux/swipe` |
52
+ | a pane resized by dragging its edge, or by keys on its grip | `@yaks/ux/resize` |
53
+ | whole rows only, in a list too long for its space | `fitList` (`@yaks/ux/fit-list`) |
54
+
55
+ ## Use
56
+
57
+ The page graph holds UX state separately from the vocabulary of the values being
58
+ edited. This example supplies host-owned drafts with signals; a persistent host
59
+ can use [@yaks/draft](../draft/README.md).
60
+
61
+ ```ts
62
+ import { createElement as h } from 'react'
63
+ import { render } from '@yaks/react/draw'
64
+ import { signal } from '@preact/signals-core'
65
+ import { parseHTML } from 'linkedom'
66
+ import { client } from '@yaks/client'
67
+ import { loadVocab } from '@yaks/vocab'
68
+ import { equal } from '@yaks/testing'
69
+ import { Edit, emit, type Host, useEdit, useHost, useOwner, Ux } from '@yaks/ux'
70
+ import { docs } from '@yaks/ux/vocab'
71
+
72
+ let front = client(loadVocab(docs), [], { vault: false, wireVault: false })
73
+ let typed = signal<Record<string, string>>({})
74
+ let e = { entity: { eid: 'book' }, book: { title: 'Draft' } }
75
+ let sent: unknown[] = []
76
+ let host: Host = {
77
+ vocab: loadVocab({
78
+ $defs: {
79
+ book: { component: true, properties: { title: { type: 'string' } } },
80
+ },
81
+ }),
82
+ front,
83
+ drafts: {
84
+ text: (place) => typed.value[place] ?? '',
85
+ type: (place, text) => typed.value = { ...typed.value, [place]: text },
86
+ spend: (place) => typed.value = { ...typed.value, [place]: '' },
87
+ },
88
+ write: (b) => sent.push(b),
89
+ name: (eid) => eid,
90
+ id: (b) => b.entity.eid,
91
+ kind: () => 'book',
92
+ when: (at) => at,
93
+ find: async () => [],
94
+ }
95
+ let { document } = parseHTML('<html><body><main></main></body></html>')
96
+ let prior = Object.getOwnPropertyDescriptor(globalThis, 'document')
97
+ Object.defineProperty(globalThis, 'document', {
98
+ value: document,
99
+ configurable: true,
100
+ })
101
+ let root = document.querySelector('main')!
102
+ let editing: ReturnType<typeof useEdit> | undefined
103
+ let Probe = () => {
104
+ equal(useHost(), host)
105
+ equal(useOwner(), 'catalog')
106
+ editing = useEdit('book', 'book', 'title')
107
+ return h(Edit, { e, comp: 'book', prop: 'title', editable: true })
108
+ }
109
+ try {
110
+ render(h(Ux, { host, at: 'catalog' }, h(Probe, {})), root)
111
+ equal(root.textContent, 'Draft')
112
+ editing!.begin()
113
+ equal(editing!.now()?.open, true)
114
+ editing!.type('Published')
115
+ equal(host.drafts.text(editing!.place), 'Published')
116
+ editing!.spend()
117
+ editing!.end()
118
+ equal(editing!.now(), undefined)
119
+ emit(host, undefined, e, 'book', 'title', 'Published')
120
+ equal(sent, [{ entity: { eid: 'book' }, book: { title: 'Published' } }])
121
+ } finally {
122
+ render(null, root)
123
+ front.close()
124
+ if (prior) Object.defineProperty(globalThis, 'document', prior)
125
+ else Reflect.deleteProperty(globalThis, 'document')
126
+ }
127
+ ```
128
+
129
+ ## Exports
130
+
131
+ | Entry point | Provides |
132
+ | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
133
+ | `@yaks/ux` | `Edit`, `Text`, `Disclosure`, `Conversation`, `Order`, `Fields`, `Submit`; `useRows`; `Ux`, `useHost`, `useOwner`; `useEdit`; state, emission, formatting and picker helpers; `defineKit`, `kitDocs`; `completion`; their types |
134
+ | `@yaks/ux/views` | `editorViews`, `views`: editor registrations and their registry |
135
+ | `@yaks/ux/vocab` | `uxDoc`, `docs`, `description`: the UX vocabulary documents and package summary |
136
+ | `@yaks/ux/conversation` | `Conversation` and its `Box`, their helpers and `TAKE`; `Fold`, `Folds`, `useFold`, `Disclosure`, `DisclosureMark`: alone, for a page that draws nothing else of this package |
137
+ | `@yaks/ux/ui` | `kit`, `ux`: the base UX kit and `{ base: kit }` |
138
+ | `@yaks/ux/completion` | `completion`; `typed`, `placed`, `moved`, `taken`, `dismissed`, `act`, `CAP`; controller, input and transition types |
139
+ | `@yaks/ux/anchored` | `anchored`, `Anchored`, `AnchoredOptions`: a list in a browser that keeps its reader where they were while it changes |
140
+ | `@yaks/ux/keys` | `walk`, `keymap`, `walkKeys`, `chord`, `land`, `items`, `front`, `typing`, `layer`; `Box`, `Move`: vim's keys walking a page, and a layer no kit part draws |
141
+ | `@yaks/ux/edit-keys` | `editKey`, `editKeys`; `Key`, `Edit`, `EditKeys`: Enter keeping and Escape cancelling what is typed |
142
+
143
+ ## Kits from outside
144
+
145
+ A **UX kit** (`Kit`, distinct from a
146
+ [UI kit](../ui/README.md#parts-and-rendering)) carries controlled components,
147
+ descriptions and [specimens](../ui/README.md#parts-and-rendering). It also
148
+ carries the vocabulary document declaring their state. `defineKit` checks this
149
+ boundary and returns it with its component types intact. The package owns those
150
+ state components: each state component is CamelCase, explicitly `sync: none`,
151
+ and has a page lifetime (`durable: connection`, or a duration; `0s` for an
152
+ event), never `forever`. A UX kit brings no rules, effects or tools. Values it
153
+ edits and persistent typing drafts belong to its caller, not to this vocabulary.
154
+
155
+ ```ts
156
+ import { createElement as h } from 'react'
157
+ import { defineKit, kitDocs } from '@yaks/ux'
158
+ import { equal } from '@yaks/testing'
159
+ import { type Bundle } from '@yaks/graph'
160
+ import { ux as base } from '@yaks/ux/ui'
161
+
162
+ // An outside package's controlled component; its owner supplies the bundle and
163
+ // writes the emitted bundle into the page graph.
164
+ let Toggle = ({ e, onChange }: { e: Bundle; onChange: (b: Bundle) => void }) =>
165
+ h('button', {
166
+ onClick: () =>
167
+ onChange({
168
+ entity: e.entity,
169
+ Toggle: { open: !(e.Toggle as { open?: boolean } | undefined)?.open },
170
+ }),
171
+ }, (e.Toggle as { open?: boolean } | undefined)?.open ? 'Close' : 'Open')
172
+
173
+ let toggle = defineKit({
174
+ description: 'A controlled toggle',
175
+ vocab: {
176
+ $defs: {
177
+ Toggle: {
178
+ component: true,
179
+ sync: 'none',
180
+ durable: 'connection',
181
+ properties: { open: { type: 'boolean' } },
182
+ },
183
+ },
184
+ },
185
+ components: {
186
+ Toggle: {
187
+ Component: Toggle,
188
+ description: 'Open or close the consumer-named entity',
189
+ state: ['Toggle'],
190
+ specimens: () => [[
191
+ 'Closed',
192
+ h(
193
+ 'div',
194
+ {},
195
+ h(Toggle, {
196
+ e: { entity: { eid: 'guide-toggle' }, Toggle: { open: false } },
197
+ onChange: () => {},
198
+ }),
199
+ ),
200
+ ]],
201
+ },
202
+ },
203
+ })
204
+
205
+ let kits = { ...base, toggle }
206
+ equal(kitDocs(kits), [base.base.vocab, toggle.vocab])
207
+ equal(toggle.components.Toggle.specimens()[0][0], 'Closed')
208
+ let sent: Bundle[] = []
209
+ let button = Toggle({
210
+ e: { entity: { eid: 'my-toggle' }, Toggle: { open: false } },
211
+ onChange: (b) => sent.push(b),
212
+ })
213
+ button.props.onClick()
214
+ equal(sent, [{ entity: { eid: 'my-toggle' }, Toggle: { open: true } }])
215
+ ```
216
+
217
+ `kitDocs(kits)` supplies the checked vocabulary documents, deduplicated by
218
+ identity. A page loads them beside its other page words when making its client;
219
+ discovering a facet does not load state into a graph. A shared client with a
220
+ server still keeps these words in page memory, not on the wire or in its vault.
221
+ On that client, use a local watch (`front.watch('.Toggle', {remote: false})`)
222
+ for page-only state rather than requesting a server subscription.
223
+
224
+ A package's `./ui` facet exports `ux = {toggle}` beside any `kits`, `themes` and
225
+ `skins` it contributes. `@yaks/ux/ui` exports `kit` and `ux = {base: kit}`:
226
+ `Edit`, `Disclosure`, `Order`, `Submit` and `Text`, with labelled component
227
+ specimens. `Text` shares `Edit` state. **Refused** is the transient event
228
+ component emitted when input cannot be read; its `said` property is the reason.
229
+ The guide reads `components[name].description` and `specimens()` without
230
+ importing UX or invoking its component references. Guide identities must include
231
+ the kind and kit name: UI `base/Edit` and UX `base/Edit` are separate entries
232
+ even though they have the same component name. The UI composition supplies the
233
+ look; UX kits supply behavior and page words, not CSS or terminal sheets.
234
+
235
+ ## Edit
236
+
237
+ `Edit` changes a property's value where it stands. Its face and its control are
238
+ selected by the property's type through a
239
+ [@yaks/render registry](../render/README.md) (`views`, the `./views` facet) and
240
+ drawn with @yaks/ui's `Prop` and `Edit` parts.
241
+
242
+ | a property's type | its control | its face |
243
+ | ------------------------------------- | ------------------------------------------------------------ | -------------------------------------------------------- |
244
+ | text, a body, number, url, time, JSON | typed over in place, read as its type; a body on many lines | the text; a priority `P2`; a url a link; a time in words |
245
+ | enum, bool | a popout row of choices, the held one marked; a flag toggles | the value |
246
+ | ref | a popout search of the graph over the entities it may name | what the entity is called |
247
+ | text with a `well` | a popout of the values seen so far, what is typed one too | the text |
248
+ | query | the host's query field (@yaks/filter), or text without one | the line |
249
+
250
+ A 'none' choice in a reference or well control clears the value. Typed over in
251
+ place, the value keeps its element, font and box, so nothing on the page moves;
252
+ Enter (a body: leaving it) emits what was typed, and Escape puts the value back.
253
+ A [body](../blob/README.md) (`store: 'blob'`) the bundle does not carry is one
254
+ the page has not loaded, and is not offered for typing over.
255
+
256
+ ```ts
257
+ import { createElement as h } from 'react'
258
+ import { Edit, editorViews, formatProp, reading } from '@yaks/ux'
259
+ import { loadVocab } from '@yaks/vocab'
260
+ import { equal } from '@yaks/testing'
261
+
262
+ let vocab = loadVocab({
263
+ $defs: {
264
+ book: {
265
+ component: true,
266
+ properties: {
267
+ title: { type: 'string' },
268
+ price: { type: 'number' },
269
+ status: { type: 'string', enum: ['draft', 'published'] },
270
+ },
271
+ },
272
+ },
273
+ })
274
+ let e = { entity: { eid: 'book' }, book: { title: 'Draft', price: 3 } }
275
+ equal(reading({ vocab }, e, 'book', 'price', '12'), {
276
+ entity: { eid: 'book' },
277
+ book: { price: 12 },
278
+ })
279
+ equal(formatProp(vocab, 'book', 'price', 12), '12')
280
+ let text = h(Edit.Text, { e, comp: 'book', prop: 'title', inline: true })
281
+ let control = h(Edit.Control, {
282
+ e,
283
+ comp: 'book',
284
+ prop: 'status',
285
+ anchor: { current: null },
286
+ })
287
+ equal(text.type, Edit.Text)
288
+ equal(control.type, Edit.Control)
289
+ equal(editorViews().every((entry) => entry.view == 'Edit'), true)
290
+ ```
291
+
292
+ | export | what it is |
293
+ | ---------------------------------- | ----------------------------------------------------------------------------------------------------------- |
294
+ | `Edit` | the value; editable, a press opens its control. `show` paints a custom face, `handle` gives a link a handle |
295
+ | `Edit.Text` | the value typed over in place, opened by a double-click or by its owner (`multi`, `inline`, `readOnly`) |
296
+ | `Edit.Control` | the control alone, anchored where its caller says, drawn while its state is open |
297
+ | `useEdit`, `Editing` | an `Edit`'s state and its value's draft, read live, and `begin`, `end`, `type`, `spend`, `search` |
298
+ | `at`, `place`, `put`, `changed` | the names and bundles, pure; `refused`, `source`, `valueOf` too |
299
+ | `Ux`, `useHost`, `Host` | what a page hands down |
300
+ | `views`, `editorViews` | the controls as registrations; `TimeVal`, `UrlVal` are faces |
301
+ | `pickLine`, `useHits`, `label` | a picker's candidates, asked of the graph |
302
+ | `drag`, `drags`, `dragged` | an entity dragged from one list to another |
303
+ | `Order`, `orderAt`, `placing` | a list put in order by dragging its rows; its page eid, and where a dropped row lands |
304
+ | `canEdit`, `formatProp`, `reading` | what a value is, pure |
305
+
306
+ ## Disclosure
307
+
308
+ A **disclosure** is the kit's fold (@yaks/ui `More`): a `details` whose summary
309
+ opens what it holds. `Disclosure` takes `e` and emits `Disclosure{open}` through
310
+ `onChange` when its summary is pressed; its owner writes that bundle into the
311
+ page graph and supplies it again, and it is open as that state says. Missing
312
+ state is closed. What it holds is drawn closed too, so a page a server drew
313
+ opens it with no script; `lazy` draws it only while open, for content that asks
314
+ for rows or is too large to send unopened, holding only `Loading…` until then,
315
+ and marks it `data-lazy` so a page holding the server's drawing knows to fetch
316
+ what it holds as it opens. `summary` is its line, and `mod` its look (`quiet`
317
+ for a step). `DisclosureMark` is a second way to open it, drawn outside it: a
318
+ button over the same `e`, such as a phone mark in a caller's words. Without `e`
319
+ a disclosure is a plain `details` its host opens by itself.
320
+
321
+ ```ts
322
+ import { createElement as h } from 'react'
323
+ import { renderToStaticMarkup as renderToString } from 'react-dom/server'
324
+ import { disclosed, Disclosure, disclosureAt, isOpen } from '@yaks/ux'
325
+ import { equal } from '@yaks/testing'
326
+
327
+ let e = { entity: { eid: disclosureAt('journal/meadow') } }
328
+ equal(isOpen(e), false)
329
+ let opened = disclosed(e, true)
330
+ equal(isOpen(opened), true)
331
+ let sent: unknown[] = []
332
+ let tree = h(Disclosure, {
333
+ e,
334
+ onChange: (b) => sent.push(b),
335
+ summary: 'Completed',
336
+ mod: 'quiet',
337
+ }, h('p', {}, 'Saved the village'))
338
+ tree.props.onChange!(opened)
339
+ equal(sent, [opened])
340
+ equal(renderToString(tree).includes('<p>Saved the village</p>'), true)
341
+ ```
342
+
343
+ ## Conversation
344
+
345
+ A **conversation** draws a session's lines, the newest last, and follows them as
346
+ a reader does: it stays at the newest line while lines arrive until the reader
347
+ scrolls up to read, and draws the last `take` lines it is given (40, `TAKE`),
348
+ with a Button above them that draws earlier ones without moving the reader, as
349
+ scrolling up near the oldest drawn line also does. It knows no data names: its
350
+ owner gives it `lines`, each `{id, node}` already drawn (or `{id, html}`, a line
351
+ a server drew, kept as it is), what the conversation is doing now (`now`), and
352
+ how many lines came before these that it was not given (`earlier`). Any other
353
+ prop lands on the `Transcript` it draws. Each line is at `#row-<id>`: an address
354
+ naming one opens there, and scrolling while the address names a place outside it
355
+ (a menu over it) is not the reader's. Where the reader is, it keeps in an
356
+ anchored list (below), so lines loading above, a picture or a fold sizing in and
357
+ a reply streaming below never move what they were reading.
358
+
359
+ Where it scrolls in a place of its own (`pane`) rather than the page, it holds
360
+ the page to what a person sees (`fit`): it sets `--viewport-height` on the root
361
+ from the visual viewport, which a frame takes its height from (@yaks/ui's
362
+ `Shell` does), and keeps the page at its top. A phone's keyboard then shortens
363
+ the frame and the conversation's scroll area, the box sits on the keyboard, and
364
+ the newest lines stay in view. iOS Safari needs this; elsewhere the viewport
365
+ meta's `interactive-widget=resizes-content` does the same.
366
+
367
+ Its state is `Conversation{take, away}` on `conversationAt(owner, session)`,
368
+ emitted through `onChange` like a disclosure's. Its owner keeps the bundle and
369
+ supplies it again; writing `away: false` takes the reader back to the newest
370
+ line, which is what a page's "Newest" button does.
371
+
372
+ Whether each fold in a line is open is `Disclosure{open}`, emitted through the
373
+ same `onChange` and read through `state`, the page graph's state by eid. A fold
374
+ in a line is a `Fold`, or a `Disclosure` and its `DisclosureMark` on what
375
+ `useFold` gives them: the page entity of the line and the fold's place in it,
376
+ the order the line first drew its folds in. So a line drawn again keeps its
377
+ folds as the reader left them, though its words changed ("Reading…" to "Read").
378
+ A fold of a line the server drew opens as a browser's does, or by its mark, and
379
+ the page then holds it so; drawn again, it is open. A line inside a fold (a
380
+ call's turn) owns its folds when it is drawn under a `Folds` of its own.
381
+
382
+ ```ts
383
+ import { createElement as h } from 'react'
384
+ import { renderToStaticMarkup as renderToString } from 'react-dom/server'
385
+ import { Conversation, conversationAt, conversed, shown } from '@yaks/ux'
386
+ import { equal } from '@yaks/testing'
387
+
388
+ let e = { entity: { eid: conversationAt('chat', 'session-1') } }
389
+ let lines = [1, 2, 3].map((n) => ({
390
+ id: `l${n}`,
391
+ node: h('p', {}, `Line ${n}`),
392
+ }))
393
+ equal(shown(lines, 2).hidden, 1)
394
+ equal(conversed(e, { away: true }), { ...e, Conversation: { away: true } })
395
+ let html = renderToString(
396
+ h(Conversation, { e, onChange: () => {}, lines, now: 'Writing…' }),
397
+ )
398
+ equal(html.includes('id="row-l3"'), true)
399
+ ```
400
+
401
+ `Conversation.Box` is where a person writes to it, wearing @yaks/ui's
402
+ `Composer`. Its words are a draft at `place` in the host's `drafts` (or its own
403
+ `drafts`), so nothing typed is lost and the words follow the person to their
404
+ other interfaces. Enter sends and Shift+Enter starts a line; Send emits the
405
+ bundle its owner's `words` makes of them through `onSend`, and Stop emits a
406
+ `Stop` event on the `session` (`stopped`) through `onStop`. The owner says where
407
+ each goes and spends the draft once the words are taken, so a send that fails
408
+ keeps them. What is the owner's own (files, a microphone, who the words go to)
409
+ it hands the box as `top`, `tools` and `beside`; any other prop lands on its
410
+ form, which posts as it is where no script runs. Given `onFiles`, the box takes
411
+ files pasted or dropped anywhere on it and emits them, lit (`Drop-over`) while
412
+ they are held over it; its owner holds them, within what it takes, and draws
413
+ them in its slots.
414
+
415
+ ```ts
416
+ import { createElement as h } from 'react'
417
+ import { renderToStaticMarkup as renderToString } from 'react-dom/server'
418
+ import { Conversation, stopped } from '@yaks/ux'
419
+ import { equal } from '@yaks/testing'
420
+
421
+ let drafts = { text: () => 'Add it to Sunday', type() {}, spend() {} }
422
+ let html = renderToString(h(Conversation.Box, {
423
+ place: 'chat:session-1',
424
+ drafts,
425
+ session: 'session-1',
426
+ words: (body) => ({ entity: { eid: 'said-1' }, content: { body } }),
427
+ onSend: () => {},
428
+ onStop: () => {},
429
+ name: 'say',
430
+ method: 'post',
431
+ }))
432
+ equal(html.includes('Add it to Sunday</textarea>'), true)
433
+ equal(stopped('session-1'), { entity: { eid: 'session-1' }, Stop: {} })
434
+ ```
435
+
436
+ ## Anchored lists
437
+
438
+ An **anchored list** keeps its reader where they were while the list changes
439
+ under them. Where they are is an item, by its id, and how far into it their view
440
+ begins. Earlier items put above, an image or a code block above sizing in, a
441
+ fold opening and items arriving below all leave the item they were reading where
442
+ it was; an item removed hands its place to the one after it. A reader at the end
443
+ follows it, and stays at it as items arrive and a reply grows, until they scroll
444
+ up from it.
445
+
446
+ `anchored(pane, { content, rows, follow, onFollow, idle })` holds the reader of
447
+ `pane`, the place that scrolls (or the page's scrolling element): it watches
448
+ `content` for changes and sizes, and after each puts the reader back before it
449
+ is painted. `rows()` gives the items in order, each known by its `id`;
450
+ `onFollow` hears the reader come to the end or leave it; while `idle()` is true
451
+ (the list hidden, or a layer over it) it moves nothing. It turns the browser's
452
+ own scroll anchoring off on the pane while it holds it. It returns `newest`
453
+ (take the reader to the end, sliding unless they asked for less motion), `read`
454
+ (take where they are now as their place, after something else moved them),
455
+ `hold`, `follows` and `stop`. It draws nothing, so a list drawn by any renderer,
456
+ or morphed in by hand, is held the same way. `Conversation` holds its lines in
457
+ one.
458
+
459
+ ### Anchor core
460
+
461
+ `@yaks/ux/anchor` says where a reader stands in a list that changes under them:
462
+ its item ID and offset (`Anchor`), or that it follows the end (`ViewportState`).
463
+ The browser adapter uses pixels and @yaks/tui's `VirtualList` uses rows.
464
+
465
+ - `rekey(anchor, was, now)`: the anchor once the list's ids went from `was` to
466
+ `now`; an item removed hands the reader to the nearest one after it that
467
+ stayed, else before it.
468
+ - `anchorAt(boxes, top)` and `topOf(anchor, boxes)`: the anchor of a view
469
+ beginning at `top` among items laid out as `boxes`, and where that view begins
470
+ once they are laid out again.
471
+ - `walk(at, by, size, count)`: the item and offset `by` past `at`, measuring
472
+ only the items it passes.
473
+ - `follows(follow, {was, now, end})`: whether a reader follows the end after
474
+ their view moved: once at it, and no longer once they moved up.
475
+
476
+ ```ts
477
+ import { anchorAt, rekey, topOf } from '@yaks/ux/anchor'
478
+ import { equal } from '@yaks/testing'
479
+
480
+ let was = [{ id: 'a', top: 0, height: 100 }, { id: 'b', top: 100, height: 50 }]
481
+ let anchor = anchorAt(was, 120)!
482
+ equal(anchor, { id: 'b', offset: 20 })
483
+ // Earlier items load above: the reader stays on b.
484
+ let now = [
485
+ { id: 'z', top: 0, height: 300 },
486
+ ...was.map((b) => ({ ...b, top: b.top + 300 })),
487
+ ]
488
+ equal(topOf(rekey(anchor, ['a', 'b'], ['z', 'a', 'b'])!, now), 420)
489
+ ```
490
+
491
+ `useRows(front, query)` draws the rows of a live query. Pass a page graph or the
492
+ default client from the app’s `./api/client.js`. The hook manages the
493
+ subscription for the component.
494
+
495
+ ## Fields and submissions
496
+
497
+ `Fields` renders controlled text fields, choices, checkboxes, file inputs and
498
+ repeat groups using @yaks/ui's `Form`, `Field`, `Check` and `Card`. A
499
+ `FieldSpec` names the input by `path`, `label` and interface `kind`; optional
500
+ `required`, `hint`, `type`, `autocomplete` and `inputMode` describe its control.
501
+ Choices supply `options` and `multiple`; repeats supply visible `entries` and
502
+ `blank`, the values for an added entry. The caller supplies visibility,
503
+ validation and the values themselves.
504
+
505
+ ```ts
506
+ import { createElement as h } from 'react'
507
+ import { Fields, type FieldSpec, putValue, type Values } from '@yaks/ux'
508
+ import { equal } from '@yaks/testing'
509
+
510
+ let fields: FieldSpec[] = [
511
+ { path: ['title'], label: 'Title', kind: 'text', required: true },
512
+ {
513
+ path: ['layout'],
514
+ label: 'Layout',
515
+ kind: 'choice',
516
+ options: ['Compact', 'Comfortable'],
517
+ },
518
+ ]
519
+ let values: Values = { title: 'Notebook' }
520
+ let tree = h(Fields, {
521
+ at: 'settings',
522
+ fields,
523
+ values,
524
+ onChange: (path, value) => values = putValue(values, path, value),
525
+ })
526
+ tree.props.onChange(['title'], 'Notes')
527
+ equal(values, { title: 'Notes' })
528
+ ```
529
+
530
+ `onChange(path, value)` emits edits; `onFile(path, file)` hands a selected file
531
+ to its caller. `owed` is a set of dot-separated paths requiring an answer;
532
+ `disabled` holds all controls while an operation is pending. Fields hold no page
533
+ state and require no host.
534
+
535
+ `Submit` loads content through `read(at)` and keeps draft values through the
536
+ supplied `drafts` desk, or the enclosing `Ux` host. A desk that offers
537
+ `follow(fn)` is followed at the draft's place, so a draft restored once the
538
+ person is known, or typed in another tab, draws even where the page's Preact
539
+ does not track the desk's signals: a yaks app's `./api/client.js` `drafts()` is
540
+ bundled apart from the page. Its caller chooses a stable `place` for that draft.
541
+ The `render` callback receives the loaded `content`, `state`, `change`, `send`
542
+ and `file` operations and composes the form. It owns validation and the form's
543
+ labels. `initial(content)` supplies empty repeat values; `feedback()` optionally
544
+ consumes native navigation feedback.
545
+
546
+ State is `Submit{content, unread, values, tried, sending, sent, said, shown}` on
547
+ `submitAt(at)`, emitted through `onChange` and read with `submitOf(e)`. `shown`
548
+ is when the content arrived, in epoch milliseconds. Values mirror the durable
549
+ draft. `send(at, values, signs)` takes what the page saw of the sending beside
550
+ its values, such as how long it took, and passes it to the caller's `send`. A
551
+ successful send spends that draft only if nobody edited it while the send
552
+ waited; a refusal retains it. The supplied uploader returns `{value}` for a
553
+ selected file, or a refusal string. The component has no endpoint or question
554
+ vocabulary of its own.
555
+
556
+ [@yaks/forms/fill](../forms/README.md#filling-forms) supplies a complete adapter
557
+ for form questions, including conditional fields, required answers, repeat
558
+ groups, upload URLs, native posts and thanks.
559
+
560
+ ## Dragging an entity
561
+
562
+ A drag between two lists on one page says which entity the dragged row stands
563
+ for under one type, `DRAGGED`, whichever package drew either list.
564
+ `drag(ev, eid)` puts it in the drag as it starts; `drags(ev)` is all a place can
565
+ know while the drag moves over it, so a list says it would take one by
566
+ cancelling the `dragover`; `dragged(ev)` reads the eid on the drop. Browse's
567
+ rows drag their entity, so a row from any list it draws drops on a list a
568
+ package draws.
569
+
570
+ ## Putting rows in order
571
+
572
+ `Order` is a list put in order by dragging its rows. Each row drags the entity
573
+ it stands for, so it drops on other lists too, and the list takes any dragged
574
+ entity: dropped between two rows, it goes to `onPlace(eid, at)`, its index among
575
+ the other rows, whether it was one of them or came from elsewhere. A drop that
576
+ leaves a row where it was says nothing. While an entity is dragged over the
577
+ list, `Order{at}` on the consumer-named page entity (`orderAt(owner)`) holds the
578
+ index of the row it would land before, and that row is marked; its owner keeps
579
+ the state bundles from `onChange` as a disclosure's owner does. Without
580
+ `onPlace` the rows are a plain list. What each row says is `row(id)`. A row
581
+ `open(id)` says is open for reading and typing is no drag handle, so selecting
582
+ its text, clicking into it and typing never pick it up.
583
+
584
+ ```ts
585
+ import { createElement as h } from 'react'
586
+ import { landed, landing, Order, orderAt, placing } from '@yaks/ux'
587
+ import { equal } from '@yaks/testing'
588
+
589
+ let e = { entity: { eid: orderAt('binder/contains') } }
590
+ equal(landing(landed(e, 1)), 1)
591
+ // b dropped before c stays where it is; a dropped there moves between b and c
592
+ equal(placing(['a', 'b', 'c'], 'b', 2), undefined)
593
+ equal(placing(['a', 'b', 'c'], 'a', 2), 1)
594
+ let list = h(Order, {
595
+ e,
596
+ onChange: () => {},
597
+ ids: ['a', 'b', 'c'],
598
+ row: (id) => id,
599
+ onPlace: () => {},
600
+ })
601
+ equal(list.type, Order)
602
+ ```
603
+
604
+ ## State and events
605
+
606
+ | component | on | what it holds |
607
+ | -------------- | --------------------------------- | ------------------------------------------------------------------------- |
608
+ | `Edit` | `at(owner, eid, comp, prop)` | `open` while it is changed here, `query` in its picker |
609
+ | `Disclosure` | `disclosureAt(owner)` | `open`, whether its content is shown |
610
+ | `Conversation` | `conversationAt(owner, session)` | `take`, how many lines back it draws; `away`, scrolled up from the newest |
611
+ | `Order` | `orderAt(owner)` | `at`, where an entity dragged over it would land |
612
+ | `Submit` | `submitAt(at)`, its submission | `content`, `unread`, `values`, `tried`, `sending`, `sent`, `said` |
613
+ | `Completion` | field id | `caret`, `from`, `to`, `cands`, `pick` |
614
+ | `Refused` | the entity whose value it changes | an event: `said`, why what was typed could not be read |
615
+
616
+ Each state component is `sync: none`: nothing leaves the page. `Edit`,
617
+ `Disclosure`, `Conversation`, `Order`, `Submit` and `Completion` are
618
+ `durable: connection`, gone with the page and kept across every remount before
619
+ that; closing an `Edit` removes it. What is typed over a value is not its state
620
+ but the person's draft, in the value's own place (`place(eid, comp, prop)`),
621
+ kept by the host's `drafts`: every view of the value, and every interface the
622
+ host syncs drafts to, types on from it, and a value whose draft says something
623
+ else shows it, open, wherever it is drawn. Leaving a value typed over emits it
624
+ and spends the draft, Escape puts the value back and spends it, and being taken
625
+ off the page is neither: the draft waits for the remount. `Refused` is
626
+ `durable: "0s"`; see [component lifetimes](../vocab/README.md#state-lifetimes).
627
+
628
+ The state helpers can also be used without rendering a component.
629
+
630
+ ```ts
631
+ import {
632
+ at,
633
+ changed,
634
+ label,
635
+ pickLine,
636
+ place,
637
+ put,
638
+ refused,
639
+ source,
640
+ valueOf,
641
+ } from '@yaks/ux'
642
+ import { equal } from '@yaks/testing'
643
+
644
+ let e = { entity: { eid: 'book' }, book: { title: 'Draft' } }
645
+ equal(
646
+ at('list', 'book', 'book', 'title') == at('detail', 'book', 'book', 'title'),
647
+ false,
648
+ )
649
+ equal(place('book', 'book', 'title'), 'edit:book:book.title')
650
+ equal(put('editing', { open: true }), [
651
+ { entity: { eid: 'editing' }, Edit: { open: true } },
652
+ ])
653
+ equal(
654
+ valueOf(changed(e, 'book', 'title', 'Published'), 'book', 'title'),
655
+ 'Published',
656
+ )
657
+ equal(source({ pages: 12 }), '{"pages":12}')
658
+ equal(refused(e, 'Expected a number'), {
659
+ entity: { eid: 'book' },
660
+ Refused: { said: 'Expected a number' },
661
+ })
662
+ equal(pickLine('Ada', 'person'), 'Ada .person *')
663
+ equal(
664
+ label({ id: (b) => b.entity.eid, kind: () => 'book' }, {
665
+ entity: { eid: 'book' },
666
+ doc: { title: 'Dune' },
667
+ }),
668
+ 'book — Dune',
669
+ )
670
+ ```
671
+
672
+ `pickLine` builds a [query](../query/README.md#query-model) for a reference
673
+ picker. `useHits` asks `find` once the line has rested `settle` ms (150 by
674
+ default; a picker takes its host's `settle`), aborts the previous request, and
675
+ clears an empty line without a request. `Find` implementations should honor the
676
+ abort signal. `label` uses the returned bundle's `rank.title`, then `doc.title`,
677
+ then the host's `kind`.
678
+
679
+ ## Completion
680
+
681
+ `@yaks/ux/completion` manages [completion](../query/README.md#completion) state,
682
+ candidate selection, keyboard actions and presentation for domain adapters such
683
+ as [@yaks/filter](../filter/README.md). The domain still decides which
684
+ replacements to offer, and `@yaks/ui`'s `Field` and `Choices` present them.
685
+
686
+ `completion(front, opts)` returns a controller for fields in one front-end
687
+ graph. Supply `opts.complete(text, caret)`, returning a `Result` or a promise of
688
+ one, and host-owned `drafts{text, type}`. `Result` uses the
689
+ [completion shape](../query/README.md#completion), `{from, to, cands, whole}`.
690
+ Async results are applied only while the field still has the matching text and
691
+ caret.
692
+
693
+ The default state component is `Completion{caret, from, to, cands, pick}`; text
694
+ stays in the host's draft. `opts.component` can name another component:
695
+ `@yaks/filter` uses `filter` for its state and supplies query completion.
696
+ `opts.Float` hosts the candidate list; without it, the list paints in the flow.
697
+
698
+ The controller provides `Field` for a managed input, or `bind(id, element)` and
699
+ `List` for an existing input. `bind` returns listener cleanup; `dispose()`
700
+ releases the controller's graph subscription. Its actions are `type`, `set`,
701
+ `move`, `accept`, `dismiss` and `press`, with reactive `row` and `text` reads.
702
+ Tab accepts, arrows move the selection, Escape dismisses, and Enter accepts only
703
+ when a candidate is selected; otherwise the key belongs to the host. The pure
704
+ transitions (`typed`, `placed`, `moved`, `taken`, `dismissed`, `act`) and their
705
+ types are exported from the same entry point.
706
+
707
+ ```ts
708
+ import { client } from '@yaks/client'
709
+ import { desk, draftDoc, drafts } from '@yaks/draft'
710
+ import { loadVocab } from '@yaks/vocab'
711
+ import { docs } from '@yaks/ux/vocab'
712
+ import {
713
+ act,
714
+ completion,
715
+ dismissed,
716
+ moved,
717
+ placed,
718
+ taken,
719
+ typed,
720
+ } from '@yaks/ux/completion'
721
+ import { equal } from '@yaks/testing'
722
+
723
+ let front = client(loadVocab(docs), [], { vault: false, wireVault: false })
724
+ let draftFront = client(loadVocab(draftDoc), [drafts()], {
725
+ vault: false,
726
+ wireVault: false,
727
+ })
728
+ let kept = desk(draftFront, { by: () => 'reader' })
729
+ let offers = (text: string, caret: number) => ({
730
+ from: 0,
731
+ to: caret,
732
+ cands: text == 'pe'
733
+ ? [
734
+ { text: 'pear', kind: 'fruit' },
735
+ { text: 'peach', kind: 'fruit' },
736
+ ]
737
+ : [],
738
+ whole: false,
739
+ })
740
+ let c = completion(front, { drafts: kept, complete: offers })
741
+ try {
742
+ c.type('field', 'pe')
743
+ equal(c.row('field')?.pick, 0)
744
+ equal(c.press('field', 'ArrowDown'), true)
745
+ equal(c.press('field', 'Enter'), true)
746
+ equal(c.text('field'), 'peach')
747
+ equal(kept.text('field'), 'peach')
748
+ c.set('field', 'pe')
749
+ equal(c.row('field')?.cands, [])
750
+ c.type('field', 'pe')
751
+ c.dismiss('field')
752
+ equal(c.press('field', 'Tab'), false)
753
+
754
+ let row = typed('pe', 2, offers('pe', 2))
755
+ equal(taken({ ...row, ...moved(row, 1) }), { text: 'peach', caret: 5 })
756
+ equal(act({ ...row, ...dismissed }, 'Tab'), undefined)
757
+ equal(placed('pear').caret, 4)
758
+ } finally {
759
+ c.dispose()
760
+ front.close()
761
+ draftFront.close()
762
+ }
763
+ ```
764
+
765
+ `Field` supplies a managed input; `bind` attaches the same behavior to an
766
+ existing input and `List` draws its candidates. Render these components in your
767
+ component tree. Constructing a managed field does not require mounting a DOM:
768
+
769
+ ```ts
770
+ import { createElement as h } from 'react'
771
+ import { client } from '@yaks/client'
772
+ import { signal } from '@preact/signals-core'
773
+ import { loadVocab } from '@yaks/vocab'
774
+ import { docs } from '@yaks/ux/vocab'
775
+ import { completion } from '@yaks/ux/completion'
776
+ import { equal } from '@yaks/testing'
777
+
778
+ let front = client(loadVocab(docs), [], { vault: false, wireVault: false })
779
+ let text = signal('')
780
+ let c = completion(front, {
781
+ drafts: {
782
+ text: () => text.value,
783
+ type: (_id, value) => text.value = value,
784
+ },
785
+ complete: (_text, caret) => ({
786
+ from: 0,
787
+ to: caret,
788
+ whole: false,
789
+ cands: [{ text: 'pear', kind: 'fruit' }],
790
+ }),
791
+ })
792
+ try {
793
+ let field = h(c.Field, { id: 'fruit', initial: 'pe' })
794
+ equal(field.props.id, 'fruit')
795
+ equal(field.props.initial, 'pe')
796
+ } finally {
797
+ c.dispose()
798
+ front.close()
799
+ }
800
+ ```
801
+
802
+ ## Vim's keys
803
+
804
+ `walk` moves a **cursor** over a page by vim's keys, one **keymap** for every
805
+ door. The cursor is the item the keys stand on, drawn by its own mark
806
+ (`data-cursor`), never the browser's focus: standing on a field types nothing
807
+ into it. An **item** is anything a person can press or type into that shows
808
+ (`items`).
809
+
810
+ In normal mode h, j, k and l move the cursor to the item left of, below, above
811
+ or right of it; gg and G to the first and the last; Enter or Space presses the
812
+ item (a link opens, a button presses); H and L go back and forward. Insert mode
813
+ is the focus in a field (`typing`): i, or Enter on a field, gives the item under
814
+ the cursor the focus, every key is the field's until Esc, and the cursor stays
815
+ on the field. Text typed over in place (`Edit.Text`, `role="textbox"`) opens as
816
+ a double press opens it. A key held with Ctrl, Alt or Meta, or one a listener
817
+ took before it, passes by.
818
+
819
+ A **layer** is what floats over the page: a peek, a menu, a popover or a dialog
820
+ (`role="dialog"`, `role="menu"`, `aria-modal`). The front-most one (`front`)
821
+ takes the keys: the cursor walks only its items, and Esc or q sends it `cancel`,
822
+ the event an HTML dialog closes on. A layer answers by closing, and the cursor
823
+ goes back to what it stood on when the layer opened. A part becomes a layer by
824
+ its role and an `onCancel` that closes it; nothing registers it. Without a
825
+ layer, the keys walk the whole surface, a sidebar beside the page included.
826
+
827
+ Where a move lands is pure (`land`): each item's box, from the platform's
828
+ `getBoundingClientRect`, and the rules Android's FocusFinder walks a screen by.
829
+ An item with no box is out of sight, as a terminal paints only what its window
830
+ shows: a walk up or down that finds nothing in sight reaches it in reading
831
+ order. `chord` reads keys into moves, a prefix such as the first g pending.
832
+
833
+ ```ts
834
+ import { chord, land } from '@yaks/ux/keys'
835
+ import { equal } from '@yaks/testing'
836
+
837
+ let at = (left: number, top: number) => ({
838
+ left,
839
+ top,
840
+ right: left + 10,
841
+ bottom: top + 10,
842
+ })
843
+ // A link beside a link, and a button under the first.
844
+ let page = [at(0, 0), at(20, 0), at(0, 20)]
845
+ equal(chord('', 'g'), { pending: 'g' })
846
+ equal(chord('g', 'g'), { move: 'first', pending: '' })
847
+ equal(land(page, 1, 'left'), 0)
848
+ equal(land(page, 0, 'down'), 2)
849
+ ```
850
+
851
+ The browser hears the keys as it hears any. @yaks/tui's document sends each key
852
+ as a keydown on the element in focus, measures what it painted, and presses,
853
+ focuses and reveals as a browser does, so the same walk walks a page there. Its
854
+ `key` hears keydowns and its `point` hears presses, which carry the cursor to
855
+ the item pressed; a walk from nowhere starts in `start`:
856
+
857
+ ```ts ignore
858
+ let keys = walk({
859
+ surface: () => frame,
860
+ start: () => frame.querySelector('main'),
861
+ back: history.back,
862
+ forward: history.forward,
863
+ })
864
+ document.addEventListener('keydown', keys.key)
865
+ document.addEventListener('pointerdown', keys.point)
866
+ ```
867
+
868
+ ## The host
869
+
870
+ `h(Ux, { host }, tree)` hands the host to every UX component under it, so one
871
+ page may hold several. An inner `h(Ux, { at }, …)` names a consumer within the
872
+ one above it, keeping the host: web names each card by its eid and each view
873
+ drawn on it by the view's name, so a title in a card's bar and in its body, or
874
+ on two cards, keeps a state of its own. The host supplies:
875
+
876
+ - `vocab`: what a property is, and whether a client may write it.
877
+ - `front`: the page's own graph, where each state lives (a @yaks/client over
878
+ this package's `./vocab`).
879
+ - `drafts`: where what is typed waits until it is sent or put back, by place
880
+ (`text`, `type`, `spend`); @yaks/draft's `desk` keeps a person's drafts in the
881
+ graph, synced to every interface they use.
882
+ - `write(b)`: where an emitted bundle goes when its caller names nowhere else.
883
+ - `name`, `id`, `kind`, `when`: what an entity is called, its human id and kind,
884
+ and a moment in words.
885
+ - `find(line, limit)`: a server search, the entities a query line answers.
886
+
887
+ and, where the page has them: `editing` (its input language, @yaks/render
888
+ `EditOptions`), `useValues` (a well's values, a hook), `fields` (its query
889
+ fields), `markup` (inline markdown), `wears` (what a choice wears beside its
890
+ word, a status's dot), and `Float`, the platform's popover (@yaks/ui's, in a
891
+ browser); without it a popout paints in the flow, as a terminal wants.
892
+
893
+ ## Limits
894
+
895
+ UX components do not fetch bodies, keep persistent drafts or decide navigation
896
+ URLs. `Submit` calls the reader, sender and uploader supplied by its caller. The
897
+ host supplies those policies. Styling belongs to [@yaks/ui](../ui/README.md);
898
+ vocabulary declarations belong to [@yaks/vocab](../vocab/README.md); query
899
+ syntax and query completion belong to [@yaks/query](../query/README.md).
900
+
901
+ ## Files
902
+
903
+ | file | owns |
904
+ | --------------------- | ------------------------------------------------------------------------------------------ |
905
+ | `kit.ts` | external kit metadata, boundary validation and vocabulary documents |
906
+ | `ui.ts` | the base kit and its browser-safe `./ui` facet and specimens |
907
+ | `vocab.json` | the `Edit`, `Disclosure`, `Conversation`, `Order`, `Submit`, `Completion`, `Refused` words |
908
+ | `state.ts` | the bundles: an `Edit`'s eid, its patches, what it emits |
909
+ | `live.ts` | `useEdit`: an `Edit`'s state and its value's draft, read live |
910
+ | `emit.ts` | typed or picked input, read as its type, sent as a bundle |
911
+ | `host.ts` | `Host`, `Ux` |
912
+ | `Edit.ts` | `Edit`, its controls and faces, `views` |
913
+ | `Text.ts` | `Edit.Text` |
914
+ | `Order.ts` | `Order`, rows put in order by dragging |
915
+ | `Conversation.ts` | `Conversation`, a session's lines followed at the newest |
916
+ | `anchored.ts` | `anchored`, a browser list holding its reader at an item and an offset into it |
917
+ | `rows.ts` | `useRows`: a query's rows in the page's graph, read live |
918
+ | `Fields.ts` | controlled inputs and repeat groups |
919
+ | `Submit.ts` | `Submit`, loading, durable drafts and submission callbacks |
920
+ | `hits.ts` | a picker's line and its debounced search |
921
+ | `read.ts` | what a property is, off the vocabulary |
922
+ | `completion.ts` | shared completion controller, field, list and input binding |
923
+ | `completion-state.ts` | pure completion transitions and candidate types |
924
+ | `keys.ts` | vim's keys: the keymap, where a move lands, the cursor and layers |
925
+
926
+ ## Saving several fields
927
+
928
+ `Save` shows a viewport bar with a change count, Discard and Save. Its host
929
+ supplies `count`, `onSave`, `onDiscard` and optional `busy` and `message` props.
930
+ `Save.Field` marks a control's wrapper when `changed` is true. The host owns its
931
+ values, persistence and writes.
932
+
933
+ Server-rendered pages can use `bindSave` from `@yaks/ux/save`. It groups named
934
+ controls in `form[data-save]`, counts changed names, and marks their fields. One
935
+ bar saves page forms together. Dialog forms save individually and can place
936
+ their actions with `Save.Slot`. A radio group is one change. The `data-save`
937
+ value is a stable draft place for that form. Drafts supply reactive
938
+ `text(place)` and synchronous `type(place, text)`; an optional asynchronous
939
+ `spend(place)` acknowledges clearing before `saved()` runs. The
940
+ [@yaks/draft](../draft/README.md) desk supplies these methods and recovery.
941
+
942
+ ```ts ignore
943
+ // In a connected page, with a durable draft desk supplied by its host:
944
+ import { bindSave } from '@yaks/ux/save'
945
+ let binding = bindSave(document, {
946
+ drafts,
947
+ save: async (form, body) => {
948
+ let response = await fetch(form.action, { method: 'POST', body })
949
+ if (!response.ok) throw new Error('Your changes could not be saved.')
950
+ },
951
+ })
952
+ // Before replacing the page's forms:
953
+ binding.close()
954
+ ```
955
+
956
+ The controls say “Saving…” while the write is out, then show the receipt or
957
+ refusal. A field's draft stays until its write is confirmed. Newer edits remain
958
+ pending and Discard restores the last submitted values. A form with
959
+ `data-save-reset` clears its confirmed edits back to their initial values, for
960
+ fields such as pasted keys.
961
+
962
+ ## Sorting tables
963
+
964
+ `Sort` draws a controlled table with keyboard-reachable header buttons. It reads
965
+ `Sort{column, direction}` from `e` and emits a replacement bundle through
966
+ `onChange`. `sortAt(owner)` names its page entity. Pressing a new column sorts
967
+ ascending; pressing it again reverses the direction, shown beside its heading
968
+ and through `aria-sort`.
969
+
970
+ Supply `cols`, `heads` and `rows`. Each row has `values` (raw strings, numbers,
971
+ or null) and `content` (one or more `Table.Row` elements). Money, counts and
972
+ timestamps are numbers; formatting belongs in the content. Related detail rows
973
+ move with their parent. Equal values retain input order, and null values stay
974
+ last in either direction.
975
+
976
+ Server-rendered pages use `bindSort(root, {read, write})` from `@yaks/ux/sort`.
977
+ The host reads and writes bundles in its page graph; the binding orders the same
978
+ row groups without replacing their content. It returns listener cleanup.
979
+
980
+ ## Sending a form
981
+
982
+ A server-rendered page loads `@yaks/ux/sending` once, and a form the browser
983
+ sends shows it in the frame of the press: the pressed button (else the form)
984
+ takes `aria-busy="true"` until the next page replaces this one. A send a script
985
+ prevents, one into another tab and a dialog's close are left to the page. A page
986
+ restored by Back drops the mark.
987
+
988
+ ## Writing and sending
989
+
990
+ A composer (@yaks/ui `Composer`) sends its form on Enter; Shift+Enter starts a
991
+ new line, and the Enter that ends a composition (an IME, a phone's keyboard)
992
+ only ends it. A part drawn in the browser asks `sends(event)` from
993
+ `@yaks/ux/composer` of its own keys. A server-rendered page loads
994
+ `@yaks/ux/composer-browser` once, which binds every `Composer_Field` it holds
995
+ and every one a later page swaps in (`composing(document)`); a field whose own
996
+ handler took the key is left to it. The field grows with its lines by CSS alone.
997
+
998
+ ## Choosing one of several
999
+
1000
+ A Select (@yaks/ui `Select`) opens the kit's list of its choices: arrow keys,
1001
+ Home and End walk it, typing the start of a choice's words finds it, Enter,
1002
+ Space or a click picks it, and Escape shuts it and gives the focus back to the
1003
+ box. Under a fine pointer `selecting(document)` from `@yaks/ux/select` opens
1004
+ that list in place of a native select's own; a pick sets the select's value and
1005
+ fires `input` and `change`, so a form sends it and a script hears it as before.
1006
+ A phone keeps the browser's own sheet. A Select whose choices are links (a
1007
+ `Menu.Fold` holding `Select.Button` and `Select.List`, as the space switcher is)
1008
+ is walked the same way, Down on its box opening it. A server-rendered page loads
1009
+ `@yaks/ux/select-browser` once; a page drawn in the browser calls
1010
+ `selecting(document)` as it mounts.
1011
+
1012
+ ## Face tagger
1013
+
1014
+ `bindFaceTagger(root, {store, api, photo, people, label, portrait})` from
1015
+ `@yaks/ux/face-tagger` mounts a photo with its live face boxes. Pass the app's
1016
+ `client.js` store, the app's API directory as a URL, and
1017
+ `photo: {eid, url, alt}`. Set `people` to the component that describes a person
1018
+ in the app. `label(row)` may supply their display name.
1019
+
1020
+ Choosing a person records a confirmation and offers similar untagged faces. You
1021
+ can reject individual suggestions before confirming the rest. Set
1022
+ `portrait: {component, property}` to fill an empty person portrait from their
1023
+ best confirmed crop. The returned function unmounts the tagger and closes its
1024
+ subscriptions.