@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/face/tags.ts ADDED
@@ -0,0 +1,357 @@
1
+ import { resolvers } from '@yaks/fp'
2
+ import {
3
+ type Bundle,
4
+ derivedEid,
5
+ type Eid,
6
+ identityEid,
7
+ mint,
8
+ } from '@yaks/graph'
9
+ import { line } from '@yaks/query'
10
+ import { token } from '@yaks/graph/sha256'
11
+
12
+ export type Watch = {
13
+ readonly value: Bundle[]
14
+ subscribe: (listener: (rows: Bundle[]) => void) => () => void
15
+ close?: () => void
16
+ }
17
+
18
+ /** The app store client returned by the platform's client.js. */
19
+ export type TagStore = {
20
+ watch: (query: string) => Watch
21
+ query: (query: string) => Promise<Bundle[]>
22
+ apply: (bundles: Bundle[]) => unknown
23
+ }
24
+
25
+ type TagReceipt = { bundles: Bundle[] }
26
+
27
+ export type Tag = { face: string; person: string }
28
+ export type Match = { face: string; person?: string; score: number }
29
+ export type ReviewMatch = Match & {
30
+ kind: 'person' | 'group' | 'face'
31
+ photo: string
32
+ }
33
+ export type FaceFind = Match & { source: string; photo: string }
34
+ export type Frame = { eid: string; url: string; alt?: string }
35
+ export type Portrait = {
36
+ component: string
37
+ property: string
38
+ /** The app may also keep a portrait through a related record. */
39
+ present?: (person: string) => boolean | Promise<boolean>
40
+ }
41
+ export type NameClue = {
42
+ label: string
43
+ text?: string
44
+ source?: string
45
+ image?: string
46
+ }
47
+ export type Face = Bundle & {
48
+ face: {
49
+ photo: string
50
+ box: { x: number; y: number; w: number; h: number }
51
+ score: number
52
+ }
53
+ portrait?: { artifact: string; batch?: string }
54
+ identified?: { person: string }
55
+ face_embedded?: { model: string }
56
+ }
57
+
58
+ /** A face row projected with its portrait and confirmed person. */
59
+ export let faces = (photo: string): string =>
60
+ line`.face.photo=${photo} ?portrait ?identified ?face_embedded ?face_copy`
61
+
62
+ /** One photo mark governs its current and future detections. */
63
+ export let asideFaces = (photo: string, setAside: boolean): Bundle => ({
64
+ entity: { eid: photo },
65
+ faces_set_aside: setAside ? {} : null,
66
+ })
67
+
68
+ /** Read strong cross-photo matches for a set-aside photo. */
69
+ export let faceFinds = async (
70
+ url: URL,
71
+ photo: string,
72
+ signal?: AbortSignal,
73
+ ): Promise<FaceFind[]> => (await faceAnswer(url, { photo }, signal)).finds ?? []
74
+
75
+ /** Read private, ephemeral similarity suggestions. */
76
+ export let lookup = async (
77
+ url: URL,
78
+ face: string,
79
+ untagged: boolean,
80
+ signal?: AbortSignal,
81
+ ): Promise<Match[]> =>
82
+ await faceMatches(url, { face, ...untagged ? { untagged: '1' } : {} }, signal)
83
+
84
+ /** Read review suggestions for a face or for a person's confirmed examples. */
85
+ export let faceSuggestions = async (
86
+ url: URL,
87
+ target: { face: string } | { person: string; grouped?: boolean },
88
+ signal?: AbortSignal,
89
+ ): Promise<Match[]> =>
90
+ await faceMatches(
91
+ url,
92
+ 'face' in target ? { face: target.face, suggest: '1' } : {
93
+ person: target.person,
94
+ suggest: '1',
95
+ ...target.grouped ? { grouped: '1' } : {},
96
+ },
97
+ signal,
98
+ )
99
+
100
+ /** One read returns named, grouped and unassigned comparison faces. */
101
+ export let compareFaces = async (
102
+ url: URL,
103
+ face: string,
104
+ signal?: AbortSignal,
105
+ ): Promise<{ matches: ReviewMatch[]; enabled: boolean }> => {
106
+ let answer = await faceAnswer(url, { face, review: '1' }, signal)
107
+ return {
108
+ matches: (answer.matches ?? []) as ReviewMatch[],
109
+ enabled: answer.enabled !== false,
110
+ }
111
+ }
112
+
113
+ let faceMatches = async (
114
+ url: URL,
115
+ params: Record<string, string>,
116
+ signal?: AbortSignal,
117
+ ): Promise<Match[]> => (await faceAnswer(url, params, signal)).matches ?? []
118
+
119
+ let faceAnswer = async (
120
+ url: URL,
121
+ params: Record<string, string>,
122
+ signal?: AbortSignal,
123
+ ): Promise<{ enabled?: boolean; matches?: Match[]; finds?: FaceFind[] }> => {
124
+ let at = new URL('face/matches', url)
125
+ at.search = new URLSearchParams(params).toString()
126
+ let response = await fetch(at, { signal })
127
+ if (!response.ok) throw new Error('Face matches could not be loaded')
128
+ return await response.json()
129
+ }
130
+
131
+ let calls = async (
132
+ store: TagStore,
133
+ name: string,
134
+ args: Record<string, unknown>[],
135
+ ids: Eid[] = args.map(() => mint()),
136
+ ): Promise<void> => {
137
+ let to = identityEid('tool', [name])
138
+ let rows = args.map((args, i) => ({
139
+ entity: { eid: ids[i] },
140
+ call: { to, args },
141
+ }))
142
+ let eids = rows.map((row) => row.entity.eid)
143
+ let watch = store.watch(line`(.result.call=${eids}|.output.source=${eids}) *`)
144
+ let timer = AbortSignal.timeout(60_000)
145
+ let { promise, resolve, reject } = resolvers<void>()
146
+ let timeout = () => reject(new Error('The tags are still being saved'))
147
+ let check = (rows: Bundle[]) => {
148
+ let failure = rows.find((row) => row.refusal || row.exception)
149
+ if (failure) {
150
+ reject(
151
+ new Error(
152
+ String(
153
+ (failure.content as { body?: string })?.body ??
154
+ 'The face could not be tagged',
155
+ ),
156
+ ),
157
+ )
158
+ } else if (rows.filter((row) => row.result).length >= eids.length) resolve()
159
+ }
160
+ let stop = watch.subscribe(check)
161
+ check(watch.value)
162
+ timer.addEventListener('abort', timeout, { once: true })
163
+ try {
164
+ await Promise.all([
165
+ promise,
166
+ Promise.resolve().then(() => store.apply(rows)),
167
+ ])
168
+ } finally {
169
+ timer.removeEventListener('abort', timeout)
170
+ stop()
171
+ watch.close?.()
172
+ }
173
+ }
174
+
175
+ let identify = ({ face, person }: Tag): Bundle => ({
176
+ entity: { eid: face },
177
+ identified: { person, score: null },
178
+ })
179
+
180
+ /** Write one or more tags in one batch. The store supplies attribution. */
181
+ export let confirmTags = async (
182
+ store: TagStore,
183
+ tags: Tag[],
184
+ ): Promise<void> => {
185
+ if (tags.length) await store.apply(tags.map(identify))
186
+ }
187
+
188
+ export type FaceEdit = { face: string; before?: string; after?: string }
189
+
190
+ /** Guard a group transfer against a membership change since it was shown. */
191
+ export let groupTransfer = (
192
+ group: string,
193
+ person: string,
194
+ touched?: string,
195
+ ): { patch: Bundle; inverse: Bundle } => ({
196
+ patch: {
197
+ entity: { eid: group },
198
+ face_merged: { person },
199
+ $was: {
200
+ face_group: { touched: touched == null ? null : token(touched) },
201
+ face_merged: { person: null },
202
+ },
203
+ },
204
+ inverse: {
205
+ entity: { eid: group },
206
+ face_merged: null,
207
+ $was: { face_merged: { person: token(person) } },
208
+ },
209
+ })
210
+
211
+ /** Compare a value against the store's current field token. */
212
+ export let faceNote = (id: string, text: string, before?: string): Bundle => ({
213
+ entity: { eid: id },
214
+ face_note: text ? { text } : null,
215
+ $was: { face_note: { text: before ? token(before) : null } },
216
+ })
217
+
218
+ /** Save face assignments and return an inverse guarded against later edits. */
219
+ export let editFaceTags = async (
220
+ store: TagStore,
221
+ edits: FaceEdit[],
222
+ accompanying: Bundle[] = [],
223
+ inverse: Bundle[] = [],
224
+ ): Promise<(extra?: Bundle[]) => Promise<void>> => {
225
+ let patch = (face: string, person: string | undefined): Bundle =>
226
+ person
227
+ ? identify({ face, person })
228
+ : { entity: { eid: face }, identified: null }
229
+ let result = await store.apply([
230
+ ...accompanying,
231
+ ...edits.map(({ face, before, after }) => ({
232
+ ...patch(face, after),
233
+ $was: { identified: { person: before == null ? null : token(before) } },
234
+ })),
235
+ ]) as TagReceipt
236
+ let saved = new Map(result.bundles.map((row) => [row.entity.eid, row]))
237
+ return async (extra = []) => {
238
+ await store.apply([
239
+ ...inverse,
240
+ ...extra,
241
+ ...edits.map(({ face, before, after }) => {
242
+ let updated = (saved.get(face)?.updated as { at?: string })?.at
243
+ return {
244
+ ...patch(face, before),
245
+ $was: {
246
+ identified: { person: after == null ? null : token(after) },
247
+ ...updated ? { updated: { at: token(updated) } } : {},
248
+ },
249
+ }
250
+ }),
251
+ ])
252
+ }
253
+ }
254
+
255
+ /** Dismiss one suggestion wherever the app presents it. */
256
+ export let rejectTag = async (store: TagStore, tag: Tag): Promise<void> => {
257
+ await store.apply([{
258
+ entity: {
259
+ eid: derivedEid('face-rejection|' + tag.face + '|' + tag.person),
260
+ },
261
+ face_rejection: { ...tag },
262
+ }])
263
+ }
264
+
265
+ /** Remove the identified person from a face. */
266
+ export let removeTag = async (store: TagStore, face: string): Promise<void> => {
267
+ await store.apply([{ entity: { eid: face }, identified: null }])
268
+ }
269
+
270
+ /** Confirm the selected faces as one unnamed person, in one write. */
271
+ export let confirmGroup = async (
272
+ store: TagStore,
273
+ faces: string[],
274
+ ): Promise<Eid> => {
275
+ let person = mint()
276
+ let unique = [...new Set(faces)]
277
+ if (!unique.length) throw new Error('Choose faces to confirm')
278
+ await store.apply([
279
+ { entity: { eid: person }, face_group: { sample: unique[0] } },
280
+ ...unique.map((face) => ({
281
+ ...identify({ face, person }),
282
+ $was: { identified: { person: null } },
283
+ })),
284
+ ])
285
+ return person
286
+ }
287
+
288
+ /** Transfer a group to a person, creating that person when supplied. */
289
+ export let mergeGroup = async (
290
+ store: TagStore,
291
+ group: string,
292
+ person: string,
293
+ create?: Record<string, unknown>,
294
+ visible: string[] = [],
295
+ ): Promise<void> => {
296
+ await store.apply([
297
+ { entity: { eid: group }, face_merged: { person } },
298
+ ...create ? [{ ...create, entity: { eid: person } }] : [],
299
+ ...visible.map((face) => ({
300
+ ...identify({ face, person }),
301
+ $was: { identified: { person: token(group) } },
302
+ })),
303
+ ])
304
+ }
305
+
306
+ let set = (row: Bundle | undefined, { component, property }: Portrait) =>
307
+ (row?.[component] as Record<string, unknown> | undefined)?.[property]
308
+
309
+ /** Fill an empty portrait with the highest-scoring confirmed crop.
310
+ * A concurrent manual selection wins through the graph's precondition. */
311
+ export let fillPortrait = async (
312
+ store: TagStore,
313
+ person: string,
314
+ field: Portrait,
315
+ ): Promise<Bundle | undefined> => {
316
+ if (await field.present?.(person)) return
317
+ let [row] = await store.query(line`.entity.eid=${person} *`)
318
+ if (!row || set(row, field) != null) return
319
+ let [best] = await store.query(
320
+ line`.identified.person=${person} .face .portrait .order=-face.score .limit=1`,
321
+ ) as Face[]
322
+ if (!best?.portrait) return
323
+ if (best.portrait.batch) {
324
+ await calls(store, 'face_crop', [{ face: best.entity.eid }])
325
+ }
326
+ let { component, property } = field
327
+ try {
328
+ await store.apply([{
329
+ entity: { eid: person },
330
+ [component]: { [property]: best.portrait.artifact },
331
+ $was: { [component]: { [property]: null } },
332
+ }])
333
+ } catch (error) {
334
+ let [after] = await store.query(line`.entity.eid=${person} *`)
335
+ if (set(after, field) == null) throw error
336
+ return
337
+ }
338
+ return {
339
+ entity: { eid: person },
340
+ [component]: { [property]: null },
341
+ $was: { [component]: { [property]: token(best.portrait.artifact) } },
342
+ }
343
+ }
344
+
345
+ /** Rank matching people first and show each only once. */
346
+ export let rankPeople = (found: Bundle[], suggestions: Match[]): Bundle[] => {
347
+ let by = new Map(found.map((row) => [row.entity.eid, row]))
348
+ let ranked: Bundle[] = []
349
+ for (let match of suggestions) {
350
+ let row = match.person && by.get(match.person)
351
+ if (row) {
352
+ ranked.push(row)
353
+ by.delete(row.entity.eid)
354
+ }
355
+ }
356
+ return [...ranked, ...by.values()]
357
+ }
@@ -0,0 +1,20 @@
1
+ /** Paths and immutable values shared by controlled fields and submissions. @module */ export let named = (path)=>path.join('.');
2
+ /** The value at `path`, set to `value`; undefined removes it. */ export let put = (values, [key, ...rest], value)=>{
3
+ let next = {
4
+ ...values
5
+ };
6
+ if (rest.length == 0) {
7
+ if (value === undefined) delete next[key];
8
+ else next[key] = value;
9
+ return next;
10
+ }
11
+ let list = Array.isArray(values[key]) ? [
12
+ ...values[key]
13
+ ] : [];
14
+ let [at, ...deeper] = rest;
15
+ list[at] = deeper.length ? put(list[at] ?? {}, deeper, value) : value;
16
+ next[key] = list;
17
+ return next;
18
+ };
19
+ /** The value at `path`. */ export let valueAt = (values, path)=>path.reduce((at, key)=>at?.[key], values);
20
+ //# sourceMappingURL=field-values.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"field-values.js","sources":["./field-values.ts"],"names":[],"mappings":"AAAA,oFAAoF,GAGpF,OAAO,IAAI,QAAQ,CAAC,OAClB,KAAK,IAAI,CAAC,KAAI;AAChB,+DAA+D,GAC/D,OAAO,IAAI,MAAM,CACf,QACA,CAAC,KAAK,GAAG,KAAmC,EAC5C;EAEA,IAAI,OAAgC;IAAE,GAAG,MAAM;EAAC;EAChD,IAAI,KAAK,MAAM,IAAI,GAAG;IACpB,IAAI,UAAU,WAAW,OAAO,IAAI,CAAC,IAAI;SACpC,IAAI,CAAC,IAAI,GAAG;IACjB,OAAO;EACT;EACA,IAAI,OAAO,MAAM,OAAO,CAAC,MAAM,CAAC,IAAI,IAAI;OAAI,MAAM,CAAC,IAAI;GAAa,GAAG,EAAE;EACzE,IAAI,CAAC,IAAI,GAAG,OAAO,GAAG;EACtB,IAAI,CAAC,GAAG,GAAG,OAAO,MAAM,GACpB,IAAI,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,QAAQ,SAC5B;EACJ,IAAI,CAAC,IAAI,GAAG;EACZ,OAAO;AACT,EAAC;AAED,yBAAyB,GACzB,OAAO,IAAI,UAAU,CACnB,QACA,OAEA,KAAK,MAAM,CACT,CAAC,IAAI,MAAS,IAAqD,CAAC,IAAI,EACxE,QACD"}
@@ -0,0 +1,35 @@
1
+ /** Paths and immutable values shared by controlled fields and submissions. @module */
2
+ export type Values = Readonly<Record<string, unknown>>
3
+ export type Path = (string | number)[]
4
+ export let named = (path: readonly (string | number)[]): string =>
5
+ path.join('.')
6
+ /** The value at `path`, set to `value`; undefined removes it. */
7
+ export let put = (
8
+ values: Values,
9
+ [key, ...rest]: readonly (string | number)[],
10
+ value: unknown,
11
+ ): Values => {
12
+ let next: Record<string, unknown> = { ...values }
13
+ if (rest.length == 0) {
14
+ if (value === undefined) delete next[key]
15
+ else next[key] = value
16
+ return next
17
+ }
18
+ let list = Array.isArray(values[key]) ? [...values[key] as Values[]] : []
19
+ let [at, ...deeper] = rest as [number, ...(string | number)[]]
20
+ list[at] = deeper.length
21
+ ? put(list[at] ?? {}, deeper, value)
22
+ : value as Values
23
+ next[key] = list
24
+ return next
25
+ }
26
+
27
+ /** The value at `path`. */
28
+ export let valueAt = (
29
+ values: Values,
30
+ path: readonly (string | number)[],
31
+ ): unknown =>
32
+ path.reduce<unknown>(
33
+ (at, key) => (at as Record<string | number, unknown> | undefined)?.[key],
34
+ values,
35
+ )
package/fit-list.js ADDED
@@ -0,0 +1,66 @@
1
+ let bottom = (view, win)=>view.getBoundingClientRect().top + view.clientTop + view.clientHeight - parseFloat(win.getComputedStyle(view).paddingBottom);
2
+ /** Keep whole rows in view, leaving room for the disclosure and everything
3
+ * after the list. Without the browser enhancement, every row is shown. */ export let fitList = (list, win)=>{
4
+ let view = list.closest('[data-fit-scroll]');
5
+ let more = list.querySelector('[data-fit-more]');
6
+ let label = more.querySelector('[data-fit-label]');
7
+ // Read each time: rows come and go as what the list shows changes.
8
+ let rows = ()=>[
9
+ ...list.children
10
+ ].filter((row)=>row !== more);
11
+ let expand = (open)=>{
12
+ more.setAttribute('aria-expanded', String(open));
13
+ label.textContent = more.title = open ? 'Less' : 'More';
14
+ };
15
+ let fit = ()=>{
16
+ let all = rows();
17
+ if (!view.clientHeight || !all.length) return;
18
+ for (let row of all)row.hidden = false;
19
+ more.hidden = false;
20
+ let end = view.lastElementChild.getBoundingClientRect().bottom;
21
+ let overflow = end + view.scrollTop - bottom(view, win);
22
+ let last = all.at(-1).getBoundingClientRect().bottom;
23
+ let reserve = more.getBoundingClientRect().bottom - last;
24
+ if (overflow <= reserve) {
25
+ more.hidden = true;
26
+ expand(false);
27
+ } else if (more.getAttribute('aria-expanded') != 'true') {
28
+ let cropped = all.filter((row)=>row.getBoundingClientRect().bottom > last - overflow);
29
+ for (let row of cropped)row.hidden = true;
30
+ }
31
+ };
32
+ let toggle = ()=>{
33
+ let first = rows().find((row)=>row.hidden);
34
+ expand(!!first);
35
+ fit();
36
+ first?.focus();
37
+ };
38
+ // Hiding overflow changes the observed list's height. Fit after delivery.
39
+ let frame = null;
40
+ let size = new win.ResizeObserver(()=>{
41
+ frame ??= win.requestAnimationFrame(()=>{
42
+ frame = null;
43
+ fit();
44
+ });
45
+ });
46
+ size.observe(view);
47
+ size.observe(list);
48
+ more.addEventListener('click', toggle);
49
+ fit();
50
+ return ()=>{
51
+ size.disconnect();
52
+ if (frame != null) win.cancelAnimationFrame(frame);
53
+ more.removeEventListener('click', toggle);
54
+ };
55
+ };
56
+ if (typeof document != 'undefined') {
57
+ let stop;
58
+ let bind = ()=>{
59
+ stop?.();
60
+ let list = document.querySelector('[data-fit-list]');
61
+ stop = list ? fitList(list, globalThis) : undefined;
62
+ };
63
+ bind();
64
+ document.addEventListener('yak-page', bind);
65
+ }
66
+ //# sourceMappingURL=fit-list.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fit-list.js","sources":["./fit-list.ts"],"names":[],"mappings":"AAQA,IAAI,SAAS,CAAC,MAAmB,MAC/B,KAAK,qBAAqB,GAAG,GAAG,GAAG,KAAK,SAAS,GAAG,KAAK,YAAY,GACrE,WAAW,IAAI,gBAAgB,CAAC,MAAM,aAAa;AAErD;wEACwE,GACxE,OAAO,IAAI,UAAU,CAAC,MAAmB;EACvC,IAAI,OAAO,KAAK,OAAO,CAAc;EACrC,IAAI,OAAO,KAAK,aAAa,CAAoB;EACjD,IAAI,QAAQ,KAAK,aAAa,CAAc;EAC5C,mEAAmE;EACnE,IAAI,OAAO,IACT;SAAI,KAAK,QAAQ;KAAC,CAAC,MAAM,CAAC,CAAC,MAAQ,QAAQ;EAE7C,IAAI,SAAS,CAAC;IACZ,KAAK,YAAY,CAAC,iBAAiB,OAAO;IAC1C,MAAM,WAAW,GAAG,KAAK,KAAK,GAAG,OAAO,SAAS;EACnD;EACA,IAAI,MAAM;IACR,IAAI,MAAM;IACV,IAAI,CAAC,KAAK,YAAY,IAAI,CAAC,IAAI,MAAM,EAAE;IACvC,KAAK,IAAI,OAAO,IAAK,IAAI,MAAM,GAAG;IAClC,KAAK,MAAM,GAAG;IAEd,IAAI,MAAM,KAAK,gBAAgB,CAAE,qBAAqB,GAAG,MAAM;IAC/D,IAAI,WAAW,MAAM,KAAK,SAAS,GAAG,OAAO,MAAM;IACnD,IAAI,OAAO,IAAI,EAAE,CAAC,CAAC,GAAI,qBAAqB,GAAG,MAAM;IACrD,IAAI,UAAU,KAAK,qBAAqB,GAAG,MAAM,GAAG;IACpD,IAAI,YAAY,SAAS;MACvB,KAAK,MAAM,GAAG;MACd,OAAO;IACT,OAAO,IAAI,KAAK,YAAY,CAAC,oBAAoB,QAAQ;MACvD,IAAI,UAAU,IAAI,MAAM,CAAC,CAAC,MACxB,IAAI,qBAAqB,GAAG,MAAM,GAAG,OAAO;MAE9C,KAAK,IAAI,OAAO,QAAS,IAAI,MAAM,GAAG;IACxC;EACF;EACA,IAAI,SAAS;IACX,IAAI,QAAQ,OAAO,IAAI,CAAC,CAAC,MAAQ,IAAI,MAAM;IAC3C,OAAO,CAAC,CAAC;IACT;IACA,OAAO;EACT;EACA,0EAA0E;EAC1E,IAAI,QAAuB;EAC3B,IAAI,OAAO,IAAI,IAAI,cAAc,CAAC;IAChC,UAAU,IAAI,qBAAqB,CAAC;MAClC,QAAQ;MACR;IACF;EACF;EACA,KAAK,OAAO,CAAC;EACb,KAAK,OAAO,CAAC;EACb,KAAK,gBAAgB,CAAC,SAAS;EAC/B;EACA,OAAO;IACL,KAAK,UAAU;IACf,IAAI,SAAS,MAAM,IAAI,oBAAoB,CAAC;IAC5C,KAAK,mBAAmB,CAAC,SAAS;EACpC;AACF,EAAC;AAED,IAAI,OAAO,YAAY,aAAa;EAClC,IAAI;EACJ,IAAI,OAAO;IACT;IACA,IAAI,OAAO,SAAS,aAAa,CAAc;IAC/C,OAAO,OAAO,QAAQ,MAAM,cAAc;EAC5C;EACA;EACA,SAAS,gBAAgB,CAAC,YAAY;AACxC"}
package/fit-list.ts ADDED
@@ -0,0 +1,81 @@
1
+ type Browser = Pick<
2
+ typeof globalThis,
3
+ | 'getComputedStyle'
4
+ | 'ResizeObserver'
5
+ | 'requestAnimationFrame'
6
+ | 'cancelAnimationFrame'
7
+ >
8
+
9
+ let bottom = (view: HTMLElement, win: Browser) =>
10
+ view.getBoundingClientRect().top + view.clientTop + view.clientHeight -
11
+ parseFloat(win.getComputedStyle(view).paddingBottom)
12
+
13
+ /** Keep whole rows in view, leaving room for the disclosure and everything
14
+ * after the list. Without the browser enhancement, every row is shown. */
15
+ export let fitList = (list: HTMLElement, win: Browser): () => void => {
16
+ let view = list.closest<HTMLElement>('[data-fit-scroll]')!
17
+ let more = list.querySelector<HTMLButtonElement>('[data-fit-more]')!
18
+ let label = more.querySelector<HTMLElement>('[data-fit-label]')!
19
+ // Read each time: rows come and go as what the list shows changes.
20
+ let rows = () =>
21
+ [...list.children].filter((row) => row !== more) as HTMLElement[]
22
+
23
+ let expand = (open: boolean) => {
24
+ more.setAttribute('aria-expanded', String(open))
25
+ label.textContent = more.title = open ? 'Less' : 'More'
26
+ }
27
+ let fit = () => {
28
+ let all = rows()
29
+ if (!view.clientHeight || !all.length) return
30
+ for (let row of all) row.hidden = false
31
+ more.hidden = false
32
+
33
+ let end = view.lastElementChild!.getBoundingClientRect().bottom
34
+ let overflow = end + view.scrollTop - bottom(view, win)
35
+ let last = all.at(-1)!.getBoundingClientRect().bottom
36
+ let reserve = more.getBoundingClientRect().bottom - last
37
+ if (overflow <= reserve) {
38
+ more.hidden = true
39
+ expand(false)
40
+ } else if (more.getAttribute('aria-expanded') != 'true') {
41
+ let cropped = all.filter((row) =>
42
+ row.getBoundingClientRect().bottom > last - overflow
43
+ )
44
+ for (let row of cropped) row.hidden = true
45
+ }
46
+ }
47
+ let toggle = () => {
48
+ let first = rows().find((row) => row.hidden)
49
+ expand(!!first)
50
+ fit()
51
+ first?.focus()
52
+ }
53
+ // Hiding overflow changes the observed list's height. Fit after delivery.
54
+ let frame: number | null = null
55
+ let size = new win.ResizeObserver(() => {
56
+ frame ??= win.requestAnimationFrame(() => {
57
+ frame = null
58
+ fit()
59
+ })
60
+ })
61
+ size.observe(view)
62
+ size.observe(list)
63
+ more.addEventListener('click', toggle)
64
+ fit()
65
+ return () => {
66
+ size.disconnect()
67
+ if (frame != null) win.cancelAnimationFrame(frame)
68
+ more.removeEventListener('click', toggle)
69
+ }
70
+ }
71
+
72
+ if (typeof document != 'undefined') {
73
+ let stop: (() => void) | undefined
74
+ let bind = () => {
75
+ stop?.()
76
+ let list = document.querySelector<HTMLElement>('[data-fit-list]')
77
+ stop = list ? fitList(list, globalThis) : undefined
78
+ }
79
+ bind()
80
+ document.addEventListener('yak-page', bind)
81
+ }
package/hits.js ADDED
@@ -0,0 +1,65 @@
1
+ // A picker's options, asked of the GRAPH rather than scanned from what the
2
+ // page holds. A scan offers only what happens to be resident, so under a
3
+ // partial cache a picker silently narrows to the entities already loaded;
4
+ // the server answers over the whole graph. The host's `find` is the one
5
+ // server search; the hook here debounces it and aborts a stale request, so a
6
+ // late answer never repaints a newer query.
7
+ /* @ts-types="npm:@types/react@19.3.0" */ import { useEffect, useState } from "react";
8
+ import { system } from "@yaks/fp";
9
+ /// pickLine('T-3') -> 'T-3 *'
10
+ /// pickLine('') -> '.doc *'
11
+ /// pickLine('ali', 'person') -> 'ali .person *'
12
+ /// pickLine('', 'person') -> '.person *'
13
+ /**
14
+ * A picker's query line: its standing component filter ANDed with what's
15
+ * typed. `comp` is the component every candidate must wear ('' = any doc); an
16
+ * empty line still lists recent candidates by the presence filter. A doc
17
+ * picker passes '' rather than 'doc' on purpose: with no component filter a
18
+ * typed line stays a SINGLE text predicate, so the server's id addressing
19
+ * still resolves a typed human id (T-3); full-text search returns only
20
+ * documented entities anyway.
21
+ *
22
+ * The typed text leads and the presence filter trails ('ali .person', never
23
+ * '.person ali'): an &-segment that STARTS with a dot-param reads as one
24
+ * token, so a term after it would land inside the value; a leading term puts
25
+ * a ' .' in the segment, the boundary that splits it into a text predicate
26
+ * plus the presence one. An empty line is the bare filter, which parses
27
+ * alone.
28
+ *
29
+ * `*` asks for each candidate whole: a presence filter alone answers only the
30
+ * component it names, and a candidate is labelled by its title.
31
+ */ export let pickLine = (q, comp = '')=>{
32
+ q = q.trim();
33
+ let filter = comp ? `.${comp}` : q ? '' : '.doc';
34
+ return [
35
+ q,
36
+ filter,
37
+ '*'
38
+ ].filter(Boolean).join(' ');
39
+ };
40
+ /** A live picker's hits, asked of `find`: refetched as the line settles
41
+ * (`settle` ms on `clock` without a change, 150 by default), the last request
42
+ * aborted so a slow answer can't overwrite a newer one. An empty line clears
43
+ * the list without a round trip. The answer is an answer to a query, not a
44
+ * component's own state, so it is held here. */ export let useHits = (line, limit, find, settle = 150, clock = system)=>{
45
+ let [found, setFound] = useState([]);
46
+ useEffect(()=>{
47
+ if (!line) {
48
+ setFound([]);
49
+ return;
50
+ }
51
+ let abort = new AbortController();
52
+ let cancel = clock.after(settle, ()=>find(line, limit, abort.signal).then(setFound).catch(()=>{}));
53
+ return ()=>{
54
+ cancel();
55
+ abort.abort();
56
+ };
57
+ }, [
58
+ line,
59
+ limit,
60
+ settle,
61
+ clock
62
+ ]);
63
+ return found;
64
+ };
65
+ //# sourceMappingURL=hits.js.map
package/hits.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hits.js","sources":["./hits.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,yEAAyE;AACzE,0EAA0E;AAC1E,wEAAwE;AACxE,6EAA6E;AAC7E,4CAA4C;AAC5C,uCAAuC,GAAG,SAAS,SAAS,EAAE,QAAQ,gBAA0B;AAChG,SAAqB,MAAM,wBAA6B;AASxD,8BAA8B;AAC9B,4BAA4B;AAC5B,gDAAgD;AAChD,yCAAyC;AACzC;;;;;;;;;;;;;;;;;;CAkBC,GACD,OAAO,IAAI,WAAW,CAAC,GAAW,OAAO,EAAE;EACzC,IAAI,EAAE,IAAI;EACV,IAAI,SAAS,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,KAAK;EAC1C,OAAO;IAAC;IAAG;IAAQ;GAAI,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC;AAC/C,EAAC;AAED;;;;8CAI8C,GAC9C,OAAO,IAAI,UAAU,CACnB,MACA,OACA,MACA,SAAS,GAAG,EACZ,QAAe,MAAM;EAErB,IAAI,CAAC,OAAO,SAAS,GAAG,SAAc,EAAE;EACxC,UAAU;IACR,IAAI,CAAC,MAAM;MACT,SAAS,EAAE;MACX;IACF;IACA,IAAI,QAAQ,IAAI;IAChB,IAAI,SAAS,MAAM,KAAK,CACtB,QACA,IAAM,KAAK,MAAM,OAAO,MAAM,MAAM,EAAE,IAAI,CAAC,UAAU,KAAK,CAAC,KAAO;IAEpE,OAAO;MACL;MACA,MAAM,KAAK;IACb;EACF,GAAG;IAAC;IAAM;IAAO;IAAQ;GAAM;EAC/B,OAAO;AACT,EAAC"}