@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/Text.js ADDED
@@ -0,0 +1,114 @@
1
+ /**
2
+ * A value typed over where it stands: `Edit.Text`. At rest it is the value's
3
+ * text (or its inline markdown); opened, by a double-click or by whoever holds
4
+ * its `Edit` state, the element becomes plaintext-editable in place, the same
5
+ * face, font and box, so nothing on the page moves. Enter (a body: Ctrl+Enter,
6
+ * or leaving it) emits what was typed, Escape puts the value back
7
+ * (`@yaks/ux/edit-keys`), and what is typed is the
8
+ * person's draft (the host's `drafts`) as it is typed: a remount, a reload,
9
+ * another view or another interface types on from it, and a value with a
10
+ * draft shows it, open, wherever it is drawn, until it is sent or put back.
11
+ *
12
+ * @module
13
+ */ /* @ts-types="npm:@types/react@19.3.0" */ import { createElement as h, useLayoutEffect, useRef } from "react";
14
+ import { Edit as Span } from "@yaks/ui/parts";
15
+ import { useHost } from "./host.js";
16
+ import { emit } from "./emit.js";
17
+ import { editKeys } from "./edit-keys.js";
18
+ import { useEdit } from "./live.js";
19
+ import { isBody } from "./read.js";
20
+ import { source, valueOf } from "./state.js";
21
+ /** A value typed over where it stands. */ export let Text = ({ e, comp, prop, onChange, at, multi, inline, readOnly })=>{
22
+ let host = useHost();
23
+ let { vocab, markup } = host;
24
+ // Prose is typed over as it is read, its eids drawn as ids.
25
+ let stored = valueOf(e, comp, prop);
26
+ let held = typeof stored == 'string' && host.prose && vocab.prop(comp, prop)?.prose ? host.prose(stored) : stored;
27
+ let edit = useEdit(e.entity.eid, comp, prop, {
28
+ at,
29
+ value: held
30
+ });
31
+ // A body a bundle does not carry is one the page has not loaded, not an
32
+ // empty one: typing over it would write a fragment over the stored text.
33
+ let unloaded = held === undefined && isBody(vocab, comp, prop);
34
+ let still = readOnly || unloaded;
35
+ let value = source(held);
36
+ let open = edit.open && !still;
37
+ let ref = useRef(null);
38
+ let md = inline && markup;
39
+ // Opened, the element holds what was typed so far, and, opened here, takes
40
+ // the keyboard. One its draft opened waits for a press to take it.
41
+ useLayoutEffect(()=>{
42
+ let t = ref.current;
43
+ if (!open || !t) return;
44
+ let row = t.closest('[draggable="true"]');
45
+ if (row) row.draggable = false;
46
+ let text = edit.text || value;
47
+ t.contentEditable = 'plaintext-only';
48
+ if (md || text != value) t.textContent = text;
49
+ if (edit.row?.open) {
50
+ t.focus();
51
+ globalThis.getSelection?.()?.setPosition(t, t.childNodes.length);
52
+ }
53
+ return ()=>{
54
+ if (row) row.draggable = true;
55
+ };
56
+ }, [
57
+ open
58
+ ]);
59
+ // The draft typed on elsewhere (another view, another interface) shows
60
+ // here as it lands; what is typed here is already what it says.
61
+ useLayoutEffect(()=>{
62
+ let t = ref.current;
63
+ if (!open || !t || !edit.text || edit.text == t.textContent) return;
64
+ t.textContent = edit.text;
65
+ if (globalThis.document?.activeElement == t) {
66
+ globalThis.getSelection?.()?.setPosition(t, t.childNodes.length);
67
+ }
68
+ }, [
69
+ edit.text
70
+ ]);
71
+ // Read-only while open (a permission change): it closes, emitting nothing,
72
+ // and its draft stays for when it is not.
73
+ useLayoutEffect(()=>{
74
+ if (still && edit.row?.open) edit.end();
75
+ }, [
76
+ still
77
+ ]);
78
+ // Leaving it emits, and the draft is spent. Being taken off the page (a
79
+ // remount) is not leaving it: a browser blurs the focused element as it
80
+ // removes it, so finishing waits a microtask and asks whether it is still
81
+ // there, and the draft stays for the remount.
82
+ let finish = (t)=>queueMicrotask(()=>{
83
+ if (!t.isConnected || !t.isContentEditable || !edit.now()?.open) return;
84
+ let text = (t.textContent ?? '').trim();
85
+ if (text && text != value) emit(host, onChange, e, comp, prop, text);
86
+ edit.spend();
87
+ edit.end();
88
+ });
89
+ // What is typed is emitted on leaving: one path, Enter's too.
90
+ let keys = editKeys({
91
+ multi,
92
+ keep: (t)=>t.blur(),
93
+ cancel: (t)=>{
94
+ t.textContent = value;
95
+ t.blur();
96
+ }
97
+ });
98
+ let key = (ev)=>ev.currentTarget.isContentEditable && keys(ev);
99
+ // Open and at rest are two elements: the one typed in is dropped whole
100
+ // when it closes, so the value paints fresh however the typing left it.
101
+ return /*#__PURE__*/ h(Span, {
102
+ key: open ? 'open' : 'rest',
103
+ elRef: ref,
104
+ // Typed into once opened: what vim's keys enter (@yaks/ux/keys).
105
+ role: still ? undefined : 'textbox',
106
+ onDoubleClick: ()=>still || open || edit.begin(),
107
+ // Pressed into, a draft opened elsewhere is being typed in here.
108
+ onFocus: ()=>open && !edit.now()?.open && edit.begin(),
109
+ onKeyDown: key,
110
+ onInput: (ev)=>edit.type(ev.currentTarget.textContent ?? ''),
111
+ onBlur: (ev)=>finish(ev.currentTarget)
112
+ }, md && !open ? md(value) : value);
113
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AAI,OAAO,SAAS;IAClB;IACA,MAAM,CAAC,IAAM,EAAE,IAAI;IACnB,QAAQ,CAAC;MACP,EAAE,WAAW,GAAG;MAChB,EAAE,IAAI;IACR;EACF;EACA,IAAI,MAAM,CAAC,KACT,AAAC,GAAG,aAAa,CAAiB,iBAAiB,IAAI,KAAK;EAE9D,uEAAuE;EACvE,wEAAwE;EACxE,qBAAO,EAAE,MAAM;IACb,KAAK,OAAO,SAAS;IACrB,OAAO;IACP,iEAAiE;IACjE,MAAM,QAAQ,YAAY;IAC1B,eAAe,IAAM,SAAS,QAAQ,KAAK,KAAK;IAChD,iEAAiE;IACjE,SAAS,IAAM,QAAQ,CAAC,KAAK,GAAG,IAAI,QAAQ,KAAK,KAAK;IACtD,WAAW;IACX,SAAS,CAAC,KACR,KAAK,IAAI,CAAC,AAAC,GAAG,aAAa,CAAiB,WAAW,IAAI;IAC7D,QAAQ,CAAC,KAAmB,OAAO,GAAG,aAAa;EACrD,GAAG,MAAM,CAAC,OAAO,GAAG,SAAS;AAC/B,EAAC"}
package/Text.ts ADDED
@@ -0,0 +1,140 @@
1
+ /**
2
+ * A value typed over where it stands: `Edit.Text`. At rest it is the value's
3
+ * text (or its inline markdown); opened, by a double-click or by whoever holds
4
+ * its `Edit` state, the element becomes plaintext-editable in place, the same
5
+ * face, font and box, so nothing on the page moves. Enter (a body: Ctrl+Enter,
6
+ * or leaving it) emits what was typed, Escape puts the value back
7
+ * (`@yaks/ux/edit-keys`), and what is typed is the
8
+ * person's draft (the host's `drafts`) as it is typed: a remount, a reload,
9
+ * another view or another interface types on from it, and a value with a
10
+ * draft shows it, open, wherever it is drawn, until it is sent or put back.
11
+ *
12
+ * @module
13
+ */
14
+
15
+ /* @ts-types="npm:@types/react@19.3.0" */ import { createElement as h, type JSX, useLayoutEffect, useRef } from 'react'
16
+ import { Edit as Span } from '@yaks/ui/parts'
17
+ import { type Bundle, useHost } from './host.js'
18
+ import { emit, type OnChange } from './emit.js'
19
+ import { editKeys } from './edit-keys.js'
20
+ import { useEdit } from './live.js'
21
+ import { isBody } from './read.js'
22
+ import { source, valueOf } from './state.js'
23
+
24
+ /** What an `Edit.Text` is drawn with. */
25
+ export type TextProps = {
26
+ /** what controls it: the value is `e[comp][prop]` */
27
+ e: Bundle
28
+ comp: string
29
+ prop: string
30
+ /** where what it emits goes (default: the host's `write`) */
31
+ onChange?: OnChange
32
+ /** its `Edit` state's eid, when its caller names it */
33
+ at?: string
34
+ /** Enter types a new line; Ctrl+Enter or leaving it is what emits */
35
+ multi?: boolean
36
+ /** inline markdown at rest (the host's `markup`); its source typed over */
37
+ inline?: boolean
38
+ /** shown, never opened; an open one closes, emitting nothing */
39
+ readOnly?: boolean
40
+ }
41
+
42
+ /** A value typed over where it stands. */
43
+ export let Text = (
44
+ { e, comp, prop, onChange, at, multi, inline, readOnly }: TextProps,
45
+ ): JSX.Element => {
46
+ let host = useHost()
47
+ let { vocab, markup } = host
48
+ // Prose is typed over as it is read, its eids drawn as ids.
49
+ let stored = valueOf(e, comp, prop)
50
+ let held = typeof stored == 'string' && host.prose &&
51
+ vocab.prop(comp, prop)?.prose
52
+ ? host.prose(stored)
53
+ : stored
54
+ let edit = useEdit(e.entity.eid, comp, prop, { at, value: held })
55
+ // A body a bundle does not carry is one the page has not loaded, not an
56
+ // empty one: typing over it would write a fragment over the stored text.
57
+ let unloaded = held === undefined && isBody(vocab, comp, prop)
58
+ let still = readOnly || unloaded
59
+ let value = source(held)
60
+ let open = edit.open && !still
61
+ let ref = useRef<HTMLElement>(null)
62
+ let md = inline && markup
63
+
64
+ // Opened, the element holds what was typed so far, and, opened here, takes
65
+ // the keyboard. One its draft opened waits for a press to take it.
66
+ useLayoutEffect(() => {
67
+ let t = ref.current
68
+ if (!open || !t) return
69
+ let row = t.closest<HTMLElement>('[draggable="true"]')
70
+ if (row) row.draggable = false
71
+ let text = edit.text || value
72
+ t.contentEditable = 'plaintext-only'
73
+ if (md || text != value) t.textContent = text
74
+ if (edit.row?.open) {
75
+ t.focus()
76
+ globalThis.getSelection?.()?.setPosition(t, t.childNodes.length)
77
+ }
78
+ return () => {
79
+ if (row) row.draggable = true
80
+ }
81
+ }, [open])
82
+
83
+ // The draft typed on elsewhere (another view, another interface) shows
84
+ // here as it lands; what is typed here is already what it says.
85
+ useLayoutEffect(() => {
86
+ let t = ref.current
87
+ if (!open || !t || !edit.text || edit.text == t.textContent) return
88
+ t.textContent = edit.text
89
+ if (globalThis.document?.activeElement == t) {
90
+ globalThis.getSelection?.()?.setPosition(t, t.childNodes.length)
91
+ }
92
+ }, [edit.text])
93
+
94
+ // Read-only while open (a permission change): it closes, emitting nothing,
95
+ // and its draft stays for when it is not.
96
+ useLayoutEffect(() => {
97
+ if (still && edit.row?.open) edit.end()
98
+ }, [still])
99
+
100
+ // Leaving it emits, and the draft is spent. Being taken off the page (a
101
+ // remount) is not leaving it: a browser blurs the focused element as it
102
+ // removes it, so finishing waits a microtask and asks whether it is still
103
+ // there, and the draft stays for the remount.
104
+ let finish = (t: HTMLElement) =>
105
+ queueMicrotask(() => {
106
+ if (!t.isConnected || !t.isContentEditable || !edit.now()?.open) return
107
+ let text = (t.textContent ?? '').trim()
108
+ if (text && text != value) emit(host, onChange, e, comp, prop, text)
109
+ edit.spend()
110
+ edit.end()
111
+ })
112
+
113
+ // What is typed is emitted on leaving: one path, Enter's too.
114
+ let keys = editKeys({
115
+ multi,
116
+ keep: (t) => t.blur(),
117
+ cancel: (t) => {
118
+ t.textContent = value
119
+ t.blur()
120
+ },
121
+ })
122
+ let key = (ev: KeyboardEvent) =>
123
+ (ev.currentTarget as HTMLElement).isContentEditable && keys(ev)
124
+
125
+ // Open and at rest are two elements: the one typed in is dropped whole
126
+ // when it closes, so the value paints fresh however the typing left it.
127
+ return h(Span, {
128
+ key: open ? 'open' : 'rest',
129
+ elRef: ref,
130
+ // Typed into once opened: what vim's keys enter (@yaks/ux/keys).
131
+ role: still ? undefined : 'textbox',
132
+ onDoubleClick: () => still || open || edit.begin(),
133
+ // Pressed into, a draft opened elsewhere is being typed in here.
134
+ onFocus: () => open && !edit.now()?.open && edit.begin(),
135
+ onKeyDown: key,
136
+ onInput: (ev: InputEvent) =>
137
+ edit.type((ev.currentTarget as HTMLElement).textContent ?? ''),
138
+ onBlur: (ev: FocusEvent) => finish(ev.currentTarget as HTMLElement),
139
+ }, md && !open ? md(value) : value)
140
+ }
package/TokenPicker.js ADDED
@@ -0,0 +1,65 @@
1
+ /**
2
+ * A field that holds what was chosen as pills before the words being typed
3
+ * (@yaks/ui's `Pills-field`): a matching choice taken, or a typed value
4
+ * `typed` accepts, becomes a pill, and a pill's cross, or Backspace in the
5
+ * empty field, takes the last one back. Pills wrap with the words, so adding
6
+ * one never moves the field.
7
+ *
8
+ * @module
9
+ */ import { Combobox, Pills } from "@yaks/ui/parts";
10
+ /* @ts-types="npm:@types/react@19.3.0" */ import { createElement as h, useRef, useState } from "react";
11
+ /** A multi-select with keyboard navigation and optional type-in choices. */ export let TokenPicker = ({ id, name, initial = '', placeholder, choices, find, tokens, onTokens, typed })=>{
12
+ let [text, setText] = useState(initial);
13
+ let field = useRef(null);
14
+ let well = useRef(null);
15
+ let q = text.trim().toLocaleLowerCase();
16
+ let free = typed(text.trim());
17
+ let picked = new Set(tokens.map((t)=>t.value));
18
+ let matches = q ? (find?.(q) ?? choices.filter((t)=>t.label.toLocaleLowerCase().includes(q))).filter((t)=>!picked.has(t.value)).slice(0, 8) : [];
19
+ if (free && !picked.has(free.value) && !matches.some((t)=>t.value == free.value)) {
20
+ matches.push(free);
21
+ }
22
+ let drop = (value)=>{
23
+ onTokens(tokens.filter((t)=>t.value != value));
24
+ field.current?.focus();
25
+ };
26
+ return /*#__PURE__*/ h(Pills, {
27
+ mod: 'field',
28
+ elRef: well,
29
+ // The well around the words is theirs to click into.
30
+ onClick: (e)=>{
31
+ if (e.target == e.currentTarget) field.current?.focus();
32
+ }
33
+ }, tokens.map((token)=>/*#__PURE__*/ h(Pills.Item, {
34
+ key: token.value,
35
+ as: 'span'
36
+ }, token.label, /*#__PURE__*/ h(Pills.Remove, {
37
+ label: `Remove ${token.label}`,
38
+ onClick: ()=>drop(token.value)
39
+ }))), /*#__PURE__*/ h(Combobox, {
40
+ id,
41
+ name,
42
+ mod: 'bare',
43
+ elRef: field,
44
+ under: well,
45
+ value: text,
46
+ placeholder: tokens.length ? '' : placeholder,
47
+ options: matches,
48
+ onText: setText,
49
+ onChoose: (_value, index)=>{
50
+ onTokens([
51
+ ...tokens,
52
+ matches[index]
53
+ ]);
54
+ setText('');
55
+ },
56
+ onKey: (e)=>{
57
+ let at = e.currentTarget;
58
+ if (e.key == 'Backspace' && tokens.length && !at.value && !e.altKey && !e.ctrlKey && !e.metaKey) {
59
+ e.preventDefault();
60
+ onTokens(tokens.slice(0, -1));
61
+ }
62
+ }
63
+ }));
64
+ };
65
+ //# sourceMappingURL=TokenPicker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TokenPicker.js","sources":["./TokenPicker.ts"],"names":[],"mappings":"AAAA;;;;;;;;CAQC,GACD,SAAS,QAAQ,EAAE,KAAK,8BAAmC;AAC3D,uCAAuC,GAAG,SACxC,iBAAiB,CAAC,EAIlB,MAAM,EACN,QAAQ,gBACe;AAgBzB,0EAA0E,GAC1E,OAAO,IAAI,cAAc,CACvB,EACE,EAAE,EACF,IAAI,EACJ,UAAU,EAAE,EACZ,WAAW,EACX,OAAO,EACP,IAAI,EACJ,MAAM,EACN,QAAQ,EACR,KAAK,EACC;EAER,IAAI,CAAC,MAAM,QAAQ,GAAG,SAAS;EAC/B,IAAI,QAAQ,OAAyB;EACrC,IAAI,OAAO,OAAoB;EAC/B,IAAI,IAAI,KAAK,IAAI,GAAG,iBAAiB;EACrC,IAAI,OAAO,MAAM,KAAK,IAAI;EAC1B,IAAI,SAAS,IAAI,IAAI,OAAO,GAAG,CAAC,CAAC,IAAM,EAAE,KAAK;EAC9C,IAAI,UAAU,IACV,CAAC,OAAO,MACR,QAAQ,MAAM,CAAC,CAAC,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AO,EACrC;QACA,EAAE,cAAc;QAChB,SAAS,OAAO,KAAK,CAAC,GAAG,CAAC;MAC5B;IACF;EACF;AAEJ,EAAC"}
package/TokenPicker.ts ADDED
@@ -0,0 +1,117 @@
1
+ /**
2
+ * A field that holds what was chosen as pills before the words being typed
3
+ * (@yaks/ui's `Pills-field`): a matching choice taken, or a typed value
4
+ * `typed` accepts, becomes a pill, and a pill's cross, or Backspace in the
5
+ * empty field, takes the last one back. Pills wrap with the words, so adding
6
+ * one never moves the field.
7
+ *
8
+ * @module
9
+ */
10
+ import { Combobox, Pills } from '@yaks/ui/parts'
11
+ /* @ts-types="npm:@types/react@19.3.0" */ import {
12
+ createElement as h,
13
+ type KeyboardEvent,
14
+ type MouseEvent,
15
+ type ReactElement,
16
+ useRef,
17
+ useState,
18
+ } from 'react'
19
+
20
+ export type Token = { value: string; label: string; note?: string }
21
+
22
+ type Props = {
23
+ id: string
24
+ name?: string
25
+ initial?: string
26
+ placeholder: string
27
+ choices: readonly Token[]
28
+ find?: (text: string) => readonly Token[]
29
+ tokens: readonly Token[]
30
+ onTokens: (tokens: Token[]) => void
31
+ typed: (text: string) => Token | undefined
32
+ }
33
+
34
+ /** A multi-select with keyboard navigation and optional type-in choices. */
35
+ export let TokenPicker = (
36
+ {
37
+ id,
38
+ name,
39
+ initial = '',
40
+ placeholder,
41
+ choices,
42
+ find,
43
+ tokens,
44
+ onTokens,
45
+ typed,
46
+ }: Props,
47
+ ): ReactElement => {
48
+ let [text, setText] = useState(initial)
49
+ let field = useRef<HTMLInputElement>(null)
50
+ let well = useRef<HTMLElement>(null)
51
+ let q = text.trim().toLocaleLowerCase()
52
+ let free = typed(text.trim())
53
+ let picked = new Set(tokens.map((t) => t.value))
54
+ let matches = q
55
+ ? (find?.(q) ??
56
+ choices.filter((t) => t.label.toLocaleLowerCase().includes(q))).filter((
57
+ t,
58
+ ) => !picked.has(t.value)).slice(0, 8)
59
+ : []
60
+ if (
61
+ free && !picked.has(free.value) &&
62
+ !matches.some((t) => t.value == free.value)
63
+ ) {
64
+ matches.push(free)
65
+ }
66
+ let drop = (value: string) => {
67
+ onTokens(tokens.filter((t) => t.value != value))
68
+ field.current?.focus()
69
+ }
70
+ return h(
71
+ Pills,
72
+ {
73
+ mod: 'field',
74
+ elRef: well,
75
+ // The well around the words is theirs to click into.
76
+ onClick: (e: MouseEvent<HTMLElement>) => {
77
+ if (e.target == e.currentTarget) field.current?.focus()
78
+ },
79
+ },
80
+ tokens.map((token) =>
81
+ h(
82
+ Pills.Item,
83
+ { key: token.value, as: 'span' },
84
+ token.label,
85
+ h(Pills.Remove, {
86
+ label: `Remove ${token.label}`,
87
+ onClick: () => drop(token.value),
88
+ }),
89
+ )
90
+ ),
91
+ h(Combobox, {
92
+ id,
93
+ name,
94
+ mod: 'bare',
95
+ elRef: field,
96
+ under: well,
97
+ value: text,
98
+ placeholder: tokens.length ? '' : placeholder,
99
+ options: matches,
100
+ onText: setText,
101
+ onChoose: (_value, index) => {
102
+ onTokens([...tokens, matches[index]])
103
+ setText('')
104
+ },
105
+ onKey: (e: KeyboardEvent<HTMLInputElement>) => {
106
+ let at = e.currentTarget
107
+ if (
108
+ e.key == 'Backspace' && tokens.length && !at.value &&
109
+ !e.altKey && !e.ctrlKey && !e.metaKey
110
+ ) {
111
+ e.preventDefault()
112
+ onTokens(tokens.slice(0, -1))
113
+ }
114
+ },
115
+ }),
116
+ )
117
+ }
@@ -0,0 +1,39 @@
1
+ /**
2
+ * What a query answered, drawn the same on every screen: `Loading` until its
3
+ * first answer arrives, `Empty` when it answered none, `ErrorNotice` with the
4
+ * refusal when it was refused, and otherwise its rows, drawn by the caller. A
5
+ * screen draws only its rows; the other three states are this component's.
6
+ *
7
+ * It draws from an `Answered`: `useAnswered` (./rows.ts) reads one off a
8
+ * query's watch, and a host with its own subscriptions hands its state over in
9
+ * that shape.
10
+ *
11
+ * @module
12
+ */ import { type ReactNode } from "@types/react";
13
+ import type { Bundle } from "@yaks/graph";
14
+ /** A query's state: the rows it answered so far, whether its first answer
15
+ * has arrived, and why it was refused. A refused query is not ready. */ export type Answered<T = Bundle> = {
16
+ rows: T[];
17
+ ready: boolean;
18
+ refused?: string;
19
+ };
20
+ /** What `Answer` takes. */ export type AnswerProps<T> = {
21
+ answered: Answered<T>;
22
+ /** what fills `Empty` when the query answered none: words become its
23
+ * title; nodes are drawn as given (an `Empty.Title` and a line saying how
24
+ * to start) */ empty: ReactNode;
25
+ /** what is awaited, in words; `Loading…` */ loading?: ReactNode;
26
+ /** a diagnostic name for the read, on its `Loading` */ name?: string;
27
+ /** what could not load, as a person reads it; the refusal follows */ failed?: string;
28
+ /** ask again, offered beside the refusal */ retry?: () => unknown;
29
+ /** the rows, drawn */ children: (rows: T[]) => ReactNode;
30
+ };
31
+ /** What `Refused` takes. */ export type RefusedProps = Pick<AnswerProps<never>, 'failed' | 'retry'> & {
32
+ refused: string;
33
+ };
34
+ /** Say a read was refused: what could not load, the refusal's words, and a
35
+ * way to ask again. `Answer` says it of a query; a read of one entity says
36
+ * it alone. */ export declare let Refused: ({}: RefusedProps) => ReactNode;
37
+ /** Draw a query's rows, or say it is loading, empty or could not load. Rows
38
+ * already on screen stay while the next answer is awaited. */ export declare let Answer: <T>({}: AnswerProps<T>) => ReactNode;
39
+ //# sourceMappingURL=Answer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Answer.d.ts","sources":["../Answer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;CAWC,GAEyC,SAAuC,KAAK,SAAS,uBAA0B;AAKzH,cAAc,MAAM,2BAAgC;AAEpD;sEACsE,GACtE,YAAY,SAAS,IAAI;EACvB,MAAM;EACN,OAAO,OAAO;EACd,UAAU,MAAM;;AAGlB,yBAAyB,GACzB,YAAY,YAAY;EACtB,UAAU,SAAS;EACnB;;eAEa,GACb,OAAO;EACP,0CAA0C,GAC1C,UAAU;EACV,qDAAqD,GACrD,OAAO,MAAM;EACb,mEAAmE,GACnE,SAAS,MAAM;EACf,0CAA0C,GAC1C,cAAc,OAAO;EACrB,oBAAoB,GACpB,WAAW,MAAM,QAAQ;;AAG3B,0BAA0B,GAC1B,YAAY,eAAe,KAAK,YAAY,KAAK,GAAG,WAAW;EAC7D,SAAS,MAAM;;AAGjB;;aAEa,GACb,OAAO,YAAI,UAAW,IAA4B,YAAY,KAAG,UAQ9D;AAEH;4DAC4D,GAC5D,OAAO,YAAI,SAAU,GACnB,IAA6D,YAC3D,EACD,KACA,UAYF"}
@@ -0,0 +1,131 @@
1
+ /**
2
+ * A conversation's lines, newest last, as a reader follows them: it stays at
3
+ * the newest line while lines arrive, until the reader scrolls up to read,
4
+ * and it draws the last `take` lines it is given, more when asked. Its state
5
+ * is `Conversation{take, away}` on the page entity its owner names
6
+ * (`conversationAt`): how many lines back it draws, and whether the reader
7
+ * has scrolled away from the newest. It knows no data names: its owner
8
+ * gives it lines already drawn, and what the conversation is doing now.
9
+ *
10
+ * `Conversation.Box` is where a person writes to it: their words are a draft
11
+ * (the host's `drafts`), Enter sends them and Shift+Enter starts a line, and
12
+ * Send emits them as the bundle its owner says they become, Stop a `Stop`
13
+ * event; the owner says where each goes, and spends the draft once the words
14
+ * are taken. Given `onFiles`, it takes files pasted or dropped anywhere on it
15
+ * and emits them, lit while they are held over it; the owner holds them and
16
+ * draws them in its slots.
17
+ *
18
+ * Where it scrolls in a place of its own rather than the page, it holds the
19
+ * page to what a person sees (`fit`): a phone's keyboard shortens the page,
20
+ * so its own scroll area gets shorter and the box sits on the keyboard, and
21
+ * the page itself never scrolls.
22
+ *
23
+ * Whether each fold in a line is open is `Disclosure{open}` in the same page
24
+ * graph, on the page entity of the line and the fold's place in it (`Folds`,
25
+ * `useFold`), so a line drawn again keeps its folds as the reader left them
26
+ * though its words changed ("Reading…" to "Read").
27
+ *
28
+ * Only `h` and hooks, so it paints under any renderer that has them.
29
+ *
30
+ * @module
31
+ */ import { type JSX, type ReactNode } from "@types/react";
32
+ import type { Bundle } from "@yaks/graph";
33
+ import { type DatedRow, type Timed } from "./ConversationLines.js";
34
+ export { activityRuns, type DatedRow, DatedRows, datedRows } from "./ConversationLines.js";
35
+ import { type BoxProps } from "./ConversationBox.js";
36
+ import { type Disclosed, disclosed, Disclosure, DisclosureMark, type DisclosureProps, isOpen, Loading, UNFETCHED } from "./Disclosure.js";
37
+ /** How many lines it draws before it is asked for more, and how many more
38
+ * each time: a screen or two, so moving to a page holding it lays over a few
39
+ * thousand nodes rather than tens of thousands. A reader scrolling up to the
40
+ * oldest drawn asks for the next. */ export declare let TAKE: number;
41
+ /** How close to the oldest line drawn, in px, a reader scrolling up brings
42
+ * the earlier ones in. */ export declare let NEAR: number;
43
+ /** A line, by the id it is put under (`#row-<id>`): drawn here (`node`), or
44
+ * as it was drawn elsewhere, the server's page (`html`), kept as it is until
45
+ * it is given drawn. */ export type Line = Timed & {
46
+ id: string;
47
+ node?: ReactNode;
48
+ html?: string;
49
+ /** In-progress work, drawn in the reserved activity slot. */ transient?: boolean;
50
+ /** The lines grouped in this row. */ of?: string[];
51
+ };
52
+ /** What a conversation holds of its own. */ export type Conversing = {
53
+ /** how many lines back it draws */ take?: number;
54
+ /** the reader has scrolled up from the newest line */ away?: boolean;
55
+ };
56
+ /** The page entity of `owner`'s conversation with `session`. */ export declare let conversationAt: (owner: string, session: string) => string;
57
+ /** Its state, as `e` holds it. */ export declare let conversingOf: (e?: Bundle) => Conversing;
58
+ /** The bundle it emits: its state, changed. */ export declare let conversed: (e: Bundle, change: Conversing) => Bundle;
59
+ /** The lines it draws of those it is given, and how many earlier it does
60
+ * not: those before its `take`, and those its owner was not given
61
+ * (`earlier`). */ export declare let shown: (lines: Line[], earlier?: number) => {
62
+ lines: Line[];
63
+ hidden: number;
64
+ };
65
+ /** What its owner gives it. Any other prop goes on the conversation itself. */ export type ConversationProps = {
66
+ e: Bundle;
67
+ onChange: (b: Bundle) => void;
68
+ /** the page graph's state an eid names: its folds', which it emits through
69
+ * `onChange` too; without it every fold is drawn closed */ state?: (eid: string) => Bundle | undefined;
70
+ lines: Line[];
71
+ display?: (lines: Line[], row: DatedRow<Line>, now: number) => ReactNode;
72
+ beforeLines?: ReactNode;
73
+ /** what the conversation is doing now, said under its lines */ now?: ReactNode;
74
+ /** how many lines came before these, that its owner can bring */ earlier?: number;
75
+ /** older history is available, with its size unknown */ more?: boolean;
76
+ /** what scrolls it: the nearest scrolling place around it, or the page */ pane?: () => HTMLElement | null;
77
+ /** whether a line arriving below a reader away from the newest is news to
78
+ * them, which the way back to the newest says ("New message"): every line,
79
+ * unless told */ news?: (line: Line) => boolean;
80
+ [attribute: string]: unknown;
81
+ };
82
+ /** What is drawn under it is a line's, `line` its id: each fold in it is
83
+ * owned by the line and its place there. A conversation puts every line it
84
+ * draws under one, and a line inside a fold (a call's turn) is under one of
85
+ * its own. */ export declare let Folds: ({}: {
86
+ line: string;
87
+ children?: ReactNode;
88
+ }) => JSX.Element;
89
+ /** The state of a fold its line draws, for a `Disclosure` and its
90
+ * `DisclosureMark`: on `disclosureAt` its line and its place in it, the
91
+ * order its line first drew its folds in, which a server's drawing and the
92
+ * page's mounted over it share. Its conversation reads and keeps it; outside
93
+ * one it is closed, and outside a line it is none and the fold is a plain
94
+ * `details`. */ export declare let useFold: () => Disclosed;
95
+ /** A fold in a line: a `Disclosure` on the state `useFold` gives it. */ export declare let Fold: (props: Omit<DisclosureProps, keyof Disclosed>) => JSX.Element;
96
+ export { type BoxProps, stopped } from "./ConversationBox.js";
97
+ export { disclosed, Disclosure, DisclosureMark, isOpen, Loading, UNFETCHED };
98
+ export declare let transcriptRow: (line: Line, divider?: ReactNode, before?: string) => JSX.Element;
99
+ /** The visual viewport, as much of it as `seen` reads. */ export type Seen = {
100
+ height: number;
101
+ scale: number;
102
+ offsetTop: number;
103
+ };
104
+ /** What the page is held to, given the visual viewport, how far the page is
105
+ * scrolled, whether a field is typed in, and the window's height: while one
106
+ * is and a keyboard covers part of the window, the visual viewport's height
107
+ * in px at the page's own scale, and otherwise none, so it is the whole
108
+ * window; and whether the page goes back to its top, which it does unless a
109
+ * person pinched it larger, when where it is shown is theirs. A field typed
110
+ * in with nothing over the window holds no height: the root's property
111
+ * changing restyles every element on the page, so leaving the field would
112
+ * cost a press a frame of the whole page for nothing. */ export declare let seen: (view: Seen, scrollY: number, typing: boolean, whole: number) => {
113
+ height?: number;
114
+ top: boolean;
115
+ };
116
+ /** The property a page's frame takes its height from, set on its root:
117
+ * `height: var(--viewport-height, 100dvh)`. */ export declare let VIEWPORT: string;
118
+ /** Holds `doc`'s page to what a person sees as it changes (`seen`): a
119
+ * keyboard opening shortens it rather than scrolling it, which iOS Safari
120
+ * does whatever the viewport meta says. It holds a height only while a field
121
+ * is typed in, and reads it again whenever the visual viewport or window
122
+ * changes, focus moves and a finger lifts, since iOS does not always tell the
123
+ * visual viewport a keyboard closed (around a swipe). Returns what lets it
124
+ * go. */ export declare let fit: (doc: Document) => () => void;
125
+ /** The lines, the newest last, with what it is doing now under them;
126
+ * `Conversation.Box` is where a person writes to it. Showing nothing at all,
127
+ * no line, no way to earlier ones and nothing going on, it is marked
128
+ * `data-empty`, for its owner's empty state. */ export declare let Conversation: ((p: ConversationProps) => JSX.Element) & {
129
+ Box: (p: BoxProps) => JSX.Element;
130
+ };
131
+ //# sourceMappingURL=Conversation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Conversation.d.ts","sources":["../Conversation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8BC,GAEyC,SAGxC,KAAK,GAAG,EACR,KAAK,SAAS,uBAKS;AACzB,cAAc,MAAM,2BAAgC;AAIpD,SAAS,KAAK,QAAQ,EAAa,KAAK,KAAK,iCAAgC;AAE7E,SACE,YAAY,EACZ,KAAK,QAAQ,EACb,SAAS,EACT,SAAS,iCACoB;AAC/B,SAAc,KAAK,QAAQ,+BAA8B;AACzD,SACE,KAAK,SAAS,EACd,SAAS,EACT,UAAU,EAEV,cAAc,EACd,KAAK,eAAe,EACpB,MAAM,EAC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,YAAI,OACT,OAAO,KAAK,uBAAuB,eAClC,IAAI,QAAoD;AAE3D,SAAS,KAAK,QAAQ,EAAE,OAAO,+BAA8B;AAC7D,SAAS,SAAS,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,GAAE;AAoB5E,OAAO,YAAI,gBACT,MAAM,MACN,UAAU,WACV,SAAS,MAAM,KACd,IAAI,QAsBN;AAaD,wDAAwD,GACxD,YAAY;EAAS,QAAQ,MAAM;EAAE,OAAO,MAAM;EAAE,WAAW,MAAM;;AAErE;;;;;;;;uDAQuD,GACvD,OAAO,YAAI,OACT,MAAM,MACN,SAAS,MAAM,EACf,QAAQ,OAAO,EACf,OAAO,MAAM;EACV,SAAS,MAAM;EAAE,KAAK,OAAO;EAMjC;AAED;6CAC6C,GAC7C,OAAO,YAAI,iBAA8B;AAKzC;;;;;;OAMO,GACP,OAAO,YAAI,MAAO,KAAK,mBAAiB,IAAI,CA8B3C;AAED;;;8CAG8C,GAC9C,OAAO,YAAI,gBAAgB,GAAG,sBAAsB,IAAI;EACtD,MAAM,GAAG,aAAa,IAAI;EA0TjB"}
@@ -0,0 +1,29 @@
1
+ import { type ReactNode } from "@types/react";
2
+ import type { Bundle } from "@yaks/graph";
3
+ import { type Drafts } from "./host.js";
4
+ /** What a box's owner gives it. Any other prop goes on its form, which
5
+ * posts as it is where no script runs. */ export type BoxProps = {
6
+ /** where its words are typed, as a draft */ place: string;
7
+ /** the drafts they are kept in; the host's without them */ drafts?: Drafts;
8
+ /** the conversation they go to, which a stop is said on */ session?: string;
9
+ /** the bundle the words become */ words: (text: string) => Bundle;
10
+ /** the words, sent; the draft stays until its owner spends it */ onSend: (b: Bundle) => void;
11
+ /** Stop, pressed: `{entity: {eid: session}, Stop: {}}` */ onStop: (b: Bundle) => void;
12
+ /** the conversation is at work, so Stop shows */ busy?: boolean;
13
+ /** a send is under way, so Send waits */ sending?: boolean;
14
+ /** what it says under itself */ said?: ReactNode;
15
+ /** a failure beside the composer controls */ error?: string;
16
+ onDismissError?: () => void;
17
+ /** the field's name, the words in a form posted without script */ name?: string;
18
+ placeholder?: string;
19
+ /** its owner's, over the field: who the words go to */ top?: ReactNode;
20
+ /** its owner's, before the field: the press that adds files */ before?: ReactNode;
21
+ /** its owner's, inside the field's edge along its bottom: files held */ held?: ReactNode;
22
+ /** its owner's, beside Send */ beside?: ReactNode;
23
+ /** its owner's, in the form before the box */ children?: ReactNode;
24
+ /** files pasted or dropped on it, which its owner holds; without it, it
25
+ * takes none */ onFiles?: (files: File[]) => void;
26
+ [attribute: string]: unknown;
27
+ };
28
+ /** The event Stop emits. */ export declare let stopped: (session?: string) => Bundle;
29
+ //# sourceMappingURL=ConversationBox.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConversationBox.d.ts","sources":["../ConversationBox.ts"],"names":[],"mappings":"AAA0C,SAGxC,KAAK,SAAS,uBAIS;AACzB,cAAc,MAAM,2BAAgC;AAEpD,SAAS,KAAK,MAAM,oBAAwC;AAG5D;wCACwC,GACxC,YAAY;EACV,0CAA0C,GAC1C,OAAO,MAAM;EACb,yDAAyD,GACzD,SAAS;EACT,yDAAyD,GACzD,UAAU,MAAM;EAChB,gCAAgC,GAChC,QAAQ,MAAM,MAAM,KAAK;EACzB,+DAA+D,GAC/D,SAAS,GAAG,WAAW,IAAI;EAC3B,wDAAwD,GACxD,SAAS,GAAG,WAAW,IAAI;EAC3B,+CAA+C,GAC/C,OAAO,OAAO;EACd,uCAAuC,GACvC,UAAU,OAAO;EACjB,8BAA8B,GAC9B,OAAO;EACP,2CAA2C,GAC3C,QAAQ,MAAM;EACd,uBAAuB,IAAI;EAC3B,gEAAgE,GAChE,OAAO,MAAM;EACb,cAAc,MAAM;EACpB,qDAAqD,GACrD,MAAM;EACN,6DAA6D,GAC7D,SAAS;EACT,sEAAsE,GACtE,OAAO;EACP,6BAA6B,GAC7B,SAAS;EACT,4CAA4C,GAC5C,WAAW;EACX;gBACc,GACd,WAAW,OAAO,WAAW,IAAI;GAChC,WAAW,MAAM,GAAG,OAAO;;AAG9B,0BAA0B,GAC1B,OAAO,YAAI,UAAW,qBAAe,OAGnC"}