@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/sending.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sending.js","sources":["./sending.ts"],"names":[],"mappings":"AAAA;;;;;;CAMC,GAID,IAAI,OAAO,CAAC,KAAkC,CAAC,MAAM,GAAG,WAAW,MAAM;AAEzE,wEAAwE,GACxE,OAAO,IAAI,UAAU,CAAC;EACpB,IAAI,OAAO,EAAE,MAAM;EACnB,IAAI,CAAC,MAAM;EACX,IAAI,KAAK,EAAE,SAAS;EACpB,IAAI,SAAS,IAAI,aAAa,iBAAiB,KAAK,YAAY,CAAC;EACjE,IAAI,SAAS,IAAI,aAAa,iBAAiB,KAAK,YAAY,CAAC;EACjE,IAAI,CAAC,KAAK,WAAW,QAAQ,iBAAiB,UAAU;EACxD,OAAO,MAAM;AACf,EAAC;AAED,uDAAuD,GACvD,OAAO,IAAI,UAAU,CAAC;EACpB,IAAI,SAAS,IAAI;EACjB,IAAI,QAAQ,CAAC,gBAAgB,CAAC,UAAU,CAAC;IACvC,IAAI,KAAK,QAAQ;IACjB,IAAI,CAAC,IAAI;IACT,oEAAoE;IACpE,IAAI,qBAAqB,CAAC;MACxB,IAAI,EAAE,gBAAgB,EAAE;MACxB,GAAG,YAAY,CAAC,aAAa;MAC7B,OAAO,GAAG,CAAC;IACb;EACF;EACA,IAAI,gBAAgB,CAAC,YAAY,CAAC;IAChC,IAAI,CAAC,AAAC,EAA0B,SAAS,EAAE;IAC3C,KAAK,IAAI,MAAM,OAAQ,GAAG,eAAe,CAAC;IAC1C,OAAO,KAAK;EACd;AACF,EAAC;AAED,IAAI,OAAO,YAAY,aAAa,QAAQ"}
package/sending.ts ADDED
@@ -0,0 +1,44 @@
1
+ /** A form the browser sends shows it is sending in the frame of the press:
2
+ * the button pressed waits (`aria-busy`) until the next page replaces this
3
+ * one. A send a script took over (`preventDefault`), one into another tab and
4
+ * a dialog's close are the page's own to show. A page restored by Back is
5
+ * drawn as it was before the send.
6
+ * @module
7
+ */
8
+
9
+ type Window = typeof globalThis
10
+
11
+ let self = (at: string | null | undefined) => !at || at.toLowerCase() == '_self'
12
+
13
+ /** The element that waits on `e`'s send, or none where the page stays. */
14
+ export let waiting = (e: SubmitEvent): Element | undefined => {
15
+ let form = e.target as HTMLFormElement | null
16
+ if (!form) return
17
+ let by = e.submitter
18
+ let target = by?.getAttribute('formtarget') ?? form.getAttribute('target')
19
+ let method = by?.getAttribute('formmethod') ?? form.getAttribute('method')
20
+ if (!self(target) || method?.toLowerCase() == 'dialog') return
21
+ return by ?? form
22
+ }
23
+
24
+ /** Show each native send of `win`'s forms as pending. */
25
+ export let sending = (win: Window): void => {
26
+ let marked = new Set<Element>()
27
+ win.document.addEventListener('submit', (e) => {
28
+ let at = waiting(e as SubmitEvent)
29
+ if (!at) return
30
+ // Every listener has had its say by the frame the send is drawn in.
31
+ win.requestAnimationFrame(() => {
32
+ if (e.defaultPrevented) return
33
+ at.setAttribute('aria-busy', 'true')
34
+ marked.add(at)
35
+ })
36
+ })
37
+ win.addEventListener('pageshow', (e) => {
38
+ if (!(e as PageTransitionEvent).persisted) return
39
+ for (let at of marked) at.removeAttribute('aria-busy')
40
+ marked.clear()
41
+ })
42
+ }
43
+
44
+ if (typeof document != 'undefined') sending(globalThis)
@@ -0,0 +1,51 @@
1
+ /** Sort behavior for server-rendered Sort tables, controlled by page bundles.
2
+ * @module
3
+ */ import { sorted, sortOf, sortRows } from "./Sort.js";
4
+ export { Sort, sortAt, sorted, sortOf, sortRows } from "./Sort.js";
5
+ /** Bind all Sort tables under a surface; returns listener cleanup. */ export let bindSort = (root, host)=>{
6
+ let cleanup = [
7
+ ...root.querySelectorAll('[data-sort]')
8
+ ].map((table)=>{
9
+ let eid = table.dataset.sort;
10
+ let groups = [
11
+ ...table.querySelectorAll('[data-sort-values]')
12
+ ];
13
+ let values = new Map(groups.map((g)=>[
14
+ g,
15
+ JSON.parse(g.dataset.sortValues)
16
+ ]));
17
+ let buttons = [
18
+ ...table.querySelectorAll('[data-sort-column]')
19
+ ];
20
+ let draw = ()=>{
21
+ let state = sortOf(host.read(eid));
22
+ for (let group of sortRows(groups, (g)=>values.get(g), state)){
23
+ table.appendChild(group);
24
+ }
25
+ for (let button of buttons){
26
+ let heading = button.parentElement;
27
+ let dir = state?.column == Number(button.dataset.sortColumn) && state.direction;
28
+ heading.setAttribute('aria-sort', dir ? dir == 'asc' ? 'ascending' : 'descending' : 'none');
29
+ heading.classList.toggle('Table_Heading-asc', dir == 'asc');
30
+ heading.classList.toggle('Table_Heading-desc', dir == 'desc');
31
+ heading.querySelector('.Table_Direction').textContent = dir == 'asc' ? ' ↑' : dir == 'desc' ? ' ↓' : '';
32
+ }
33
+ };
34
+ let handlers = buttons.map((button)=>{
35
+ let press = async ()=>{
36
+ await host.write(sorted(host.read(eid) ?? {
37
+ entity: {
38
+ eid
39
+ }
40
+ }, Number(button.dataset.sortColumn)));
41
+ draw();
42
+ };
43
+ button.addEventListener('click', press);
44
+ return ()=>button.removeEventListener('click', press);
45
+ });
46
+ draw();
47
+ return ()=>handlers.forEach((off)=>off());
48
+ });
49
+ return ()=>cleanup.forEach((off)=>off());
50
+ };
51
+ //# sourceMappingURL=sort-browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sort-browser.js","sources":["./sort-browser.ts"],"names":[],"mappings":"AAAA;;CAEC,GAED,SAAS,MAAM,EAAE,MAAM,EAAE,QAAQ,oBAAmC;AACpE,SAAS,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,oBAAmB;AAQlE,oEAAoE,GACpE,OAAO,IAAI,WAAW,CAAC,MAAkB;EACvC,IAAI,UAAU;OAAI,KAAK,gBAAgB,CAAc;GAAe,CAAC,GAAG,CACtE,CAAC;IACC,IAAI,MAAM,MAAM,OAAO,CAAC,IAAI;IAC5B,IAAI,SAAS;SACR,MAAM,gBAAgB,CAAc;KACxC;IACD,IAAI,SAAS,IAAI,IACf,OAAO,GAAG,CAAC,CACT,IACG;QAAC;QAAG,KAAK,KAAK,CAAC,EAAE,OAAO,CAAC,UAAU;OAAkB;IAE5D,IAAI,UAAU;SACT,MAAM,gBAAgB,CAAoB;KAC9C;IACD,IAAI,OAAO;MACT,IAAI,QAAQ,OAAO,KAAK,IAAI,CAAC;MAC7B,KAAK,IAAI,SAAS,SAAS,QAAQ,CAAC,IAAM,OAAO,GAAG,CAAC,IAAK,OAAQ;QAChE,MAAM,WAAW,CAAC;MACpB;MACA,KAAK,IAAI,UAAU,QAAS;QAC1B,IAAI,UAAU,OAAO,aAAa;QAClC,IAAI,MAAM,OAAO,UAAU,OAAO,OAAO,OAAO,CAAC,UAAU,KACzD,MAAM,SAAS;QACjB,QAAQ,YAAY,CAClB,aACA,MAAM,OAAO,QAAQ,cAAc,eAAe;QAEpD,QAAQ,SAAS,CAAC,MAAM,CAAC,qBAAqB,OAAO;QACrD,QAAQ,SAAS,CAAC,MAAM,CAAC,sBAAsB,OAAO;QACtD,QAAQ,aAAa,CAAC,oBAAqB,WAAW,GAAG,OAAO,QAC5D,OACA,OAAO,SACP,OACA;MACN;IACF;IACA,IAAI,WAAW,QAAQ,GAAG,CAAC,CAAC;MAC1B,IAAI,QAAQ;QACV,MAAM,KAAK,KAAK,CACd,OACE,KAAK,IAAI,CAAC,QAAQ;UAAE,QAAQ;YAAE;UAAI;QAAE,GACpC,OAAO,OAAO,OAAO,CAAC,UAAU;QAGpC;MACF;MACA,OAAO,gBAAgB,CAAC,SAAS;MACjC,OAAO,IAAM,OAAO,mBAAmB,CAAC,SAAS;IACnD;IACA;IACA,OAAO,IAAM,SAAS,OAAO,CAAC,CAAC,MAAQ;EACzC;EAEF,OAAO,IAAM,QAAQ,OAAO,CAAC,CAAC,MAAQ;AACxC,EAAC"}
@@ -0,0 +1,70 @@
1
+ /** Sort behavior for server-rendered Sort tables, controlled by page bundles.
2
+ * @module
3
+ */
4
+ import type { Bundle } from 'jsr:@yaks/graph@0.2.36'
5
+ import { sorted, sortOf, sortRows, type SortValue } from './Sort.js'
6
+ export { Sort, sortAt, sorted, sortOf, sortRows } from './Sort.js'
7
+ export type { SortProps, SortRow, SortState, SortValue } from './Sort.js'
8
+
9
+ /** The host keeps choices in its page graph and returns them on each press. */
10
+ export type SortHost = {
11
+ read: (eid: string) => Bundle | undefined
12
+ write: (bundle: Bundle) => unknown | Promise<unknown>
13
+ }
14
+ /** Bind all Sort tables under a surface; returns listener cleanup. */
15
+ export let bindSort = (root: ParentNode, host: SortHost): () => void => {
16
+ let cleanup = [...root.querySelectorAll<HTMLElement>('[data-sort]')].map(
17
+ (table) => {
18
+ let eid = table.dataset.sort!
19
+ let groups = [
20
+ ...table.querySelectorAll<HTMLElement>('[data-sort-values]'),
21
+ ]
22
+ let values = new Map(
23
+ groups.map((
24
+ g,
25
+ ) => [g, JSON.parse(g.dataset.sortValues!) as SortValue[]]),
26
+ )
27
+ let buttons = [
28
+ ...table.querySelectorAll<HTMLButtonElement>('[data-sort-column]'),
29
+ ]
30
+ let draw = () => {
31
+ let state = sortOf(host.read(eid))
32
+ for (let group of sortRows(groups, (g) => values.get(g)!, state)) {
33
+ table.appendChild(group)
34
+ }
35
+ for (let button of buttons) {
36
+ let heading = button.parentElement!
37
+ let dir = state?.column == Number(button.dataset.sortColumn) &&
38
+ state.direction
39
+ heading.setAttribute(
40
+ 'aria-sort',
41
+ dir ? dir == 'asc' ? 'ascending' : 'descending' : 'none',
42
+ )
43
+ heading.classList.toggle('Table_Heading-asc', dir == 'asc')
44
+ heading.classList.toggle('Table_Heading-desc', dir == 'desc')
45
+ heading.querySelector('.Table_Direction')!.textContent = dir == 'asc'
46
+ ? ' ↑'
47
+ : dir == 'desc'
48
+ ? ' ↓'
49
+ : ''
50
+ }
51
+ }
52
+ let handlers = buttons.map((button) => {
53
+ let press = async () => {
54
+ await host.write(
55
+ sorted(
56
+ host.read(eid) ?? { entity: { eid } },
57
+ Number(button.dataset.sortColumn),
58
+ ),
59
+ )
60
+ draw()
61
+ }
62
+ button.addEventListener('click', press)
63
+ return () => button.removeEventListener('click', press)
64
+ })
65
+ draw()
66
+ return () => handlers.forEach((off) => off())
67
+ },
68
+ )
69
+ return () => cleanup.forEach((off) => off())
70
+ }
package/state.js ADDED
@@ -0,0 +1,99 @@
1
+ /**
2
+ * What an `Edit` keeps and says, as bundles: pure. Its own state is the `Edit`
3
+ * component (./vocab.json) on an entity of its own in the page's graph, whose
4
+ * eid is derived from its owner and the value it changes, so a remount finds
5
+ * it again; each change to that state is a patch built here. What is typed
6
+ * over a value is the person's draft, in the place named for the value alone
7
+ * (`place`), so every view of it, in every interface, types on from the same
8
+ * text. What it emits is a bundle of the shape it was handed (the value,
9
+ * changed), or, the exception, an event bundle: `Refused`, input that could
10
+ * not be read.
11
+ *
12
+ * @module
13
+ */ import { derivedEid } from "@yaks/graph/identity";
14
+ /** The eid of the `Edit` that changes `comp.prop` of `eid` for `owner`: the
15
+ * same every time it is asked, so a remount finds its state again.
16
+ *
17
+ * ```ts
18
+ * import { assertEquals, assertNotEquals } from '@std/assert'
19
+ * import { at } from '@yaks/ux'
20
+ *
21
+ * assertEquals(at('', 'e1', 'doc', 'title'), at('', 'e1', 'doc', 'title'))
22
+ * assertNotEquals(at('card', 'e1', 'doc', 'title'), at('', 'e1', 'doc', 'title'))
23
+ * ```
24
+ */ export let at = (owner, eid, comp, prop)=>derivedEid([
25
+ 'Edit',
26
+ owner,
27
+ eid,
28
+ `${comp}.${prop}`
29
+ ].join('|'));
30
+ /** The place the person's draft of `comp.prop` of `eid` is typed in: the
31
+ * value's own, whichever view or interface types over it.
32
+ *
33
+ * ```ts
34
+ * import { assertEquals } from '@std/assert'
35
+ * import { place } from '@yaks/ux'
36
+ *
37
+ * assertEquals(place('e1', 'doc', 'title'), 'edit:e1:doc.title')
38
+ * ```
39
+ */ export let place = (eid, comp, prop)=>`edit:${eid}:${comp}.${prop}`;
40
+ /** A patch to an `Edit`'s state; `null` closes it, leaving nothing behind.
41
+ *
42
+ * ```ts
43
+ * import { assertEquals } from '@std/assert'
44
+ * import { put } from '@yaks/ux'
45
+ *
46
+ * assertEquals(put('x', { open: true }), [{ entity: { eid: 'x' }, Edit: { open: true } }])
47
+ * assertEquals(put('x', null), [{ entity: { eid: 'x' }, Edit: null }])
48
+ * ```
49
+ */ export let put = (eid, patch)=>[
50
+ {
51
+ entity: {
52
+ eid
53
+ },
54
+ Edit: patch
55
+ }
56
+ ];
57
+ /** A value as the text it is typed over as: a JSON value as its JSON text.
58
+ *
59
+ * ```ts
60
+ * import { assertEquals } from '@std/assert'
61
+ * import { source } from '@yaks/ux'
62
+ *
63
+ * assertEquals([source(null), source(3), source({ a: 1 })], ['', '3', '{"a":1}'])
64
+ * ```
65
+ */ export let source = (v)=>v == null ? '' : typeof v == 'object' ? JSON.stringify(v) : String(v);
66
+ /** The value `comp.prop` of `e` holds. */ export let valueOf = (e, comp, prop)=>{
67
+ let row = e?.[comp];
68
+ return row && typeof row == 'object' ? row[prop] : undefined;
69
+ };
70
+ /** `e`, its `comp.prop` changed to `value`: the bundle an `Edit` emits.
71
+ *
72
+ * ```ts
73
+ * import { assertEquals } from '@std/assert'
74
+ * import { changed } from '@yaks/ux'
75
+ *
76
+ * let e = { entity: { eid: 'e1', num: 3 }, doc: { title: 'Draft', body: 'b' } }
77
+ * assertEquals(changed(e, 'doc', 'title', 'Ship it'), {
78
+ * entity: { eid: 'e1' },
79
+ * doc: { title: 'Ship it' },
80
+ * })
81
+ * ```
82
+ */ export let changed = (e, comp, prop, value)=>({
83
+ entity: {
84
+ eid: e.entity.eid
85
+ },
86
+ [comp]: {
87
+ [prop]: value
88
+ }
89
+ });
90
+ /** The event an `Edit` emits when what was typed could not be read: on the
91
+ * entity the value belongs to, saying why. */ export let refused = (e, said)=>({
92
+ entity: {
93
+ eid: e.entity.eid
94
+ },
95
+ Refused: {
96
+ said
97
+ }
98
+ });
99
+ //# sourceMappingURL=state.js.map
package/state.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.js","sources":["./state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;CAYC,GAGD,SAAS,UAAU,oCAAyC;AAU5D;;;;;;;;;;CAUC,GACD,OAAO,IAAI,KAAK,CACd,OACA,KACA,MACA,OACW,WAAW;IAAC;IAAQ;IAAO;IAAK,GAAG,KAAK,CAAC,EAAE,MAAM;GAAC,CAAC,IAAI,CAAC,MAAK;AAE1E;;;;;;;;;CASC,GACD,OAAO,IAAI,QAAQ,CAAC,KAAa,MAAc,OAC7C,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,KAAK,CAAC,EAAE,MAAM,CAAA;AAE/B;;;;;;;;;CASC,GACD,OAAO,IAAI,MAAM,CAAC,KAAa,QAAgC;IAAC;MAC9D,QAAQ;QAAE;MAAI;MACd,MAAM;IACR;GAAE,CAAA;AAEF;;;;;;;;CAQC,GACD,OAAO,IAAI,SAAS,CAAC,IACnB,KAAK,OAAO,KAAK,OAAO,KAAK,WAAW,KAAK,SAAS,CAAC,KAAK,OAAO,GAAE;AAEvE,wCAAwC,GACxC,OAAO,IAAI,UAAU,CACnB,GACA,MACA;EAEA,IAAI,MAAM,GAAG,CAAC,KAAK;EACnB,OAAO,OAAO,OAAO,OAAO,WACxB,AAAC,GAA+B,CAAC,KAAK,GACtC;AACN,EAAC;AAED;;;;;;;;;;;;CAYC,GACD,OAAO,IAAI,UAAU,CACnB,GACA,MACA,MACA,QACW,CAAC;IAAE,QAAQ;MAAE,KAAK,EAAE,MAAM,CAAC,GAAG;IAAC;IAAG,CAAC,KAAK,EAAE;MAAE,CAAC,KAAK,EAAE;IAAM;EAAE,CAAC,EAAC;AAE3E;4CAC4C,GAC5C,OAAO,IAAI,UAAU,CAAC,GAAW,OAAyB,CAAC;IACzD,QAAQ;MAAE,KAAK,EAAE,MAAM,CAAC,GAAG;IAAC;IAC5B,SAAS;MAAE;IAAK;EAClB,CAAC,EAAC"}
package/state.ts ADDED
@@ -0,0 +1,121 @@
1
+ /**
2
+ * What an `Edit` keeps and says, as bundles: pure. Its own state is the `Edit`
3
+ * component (./vocab.json) on an entity of its own in the page's graph, whose
4
+ * eid is derived from its owner and the value it changes, so a remount finds
5
+ * it again; each change to that state is a patch built here. What is typed
6
+ * over a value is the person's draft, in the place named for the value alone
7
+ * (`place`), so every view of it, in every interface, types on from the same
8
+ * text. What it emits is a bundle of the shape it was handed (the value,
9
+ * changed), or, the exception, an event bundle: `Refused`, input that could
10
+ * not be read.
11
+ *
12
+ * @module
13
+ */
14
+
15
+ import type { Bundle } from 'jsr:@yaks/graph@0.2.36'
16
+ import { derivedEid } from '@yaks/graph/identity'
17
+
18
+ /** What the `Edit` component holds. */
19
+ export type Row = {
20
+ /** being changed: typed over in place, or its picker floating beside it */
21
+ open?: boolean
22
+ /** what is typed in its picker's search */
23
+ query?: string
24
+ }
25
+
26
+ /** The eid of the `Edit` that changes `comp.prop` of `eid` for `owner`: the
27
+ * same every time it is asked, so a remount finds its state again.
28
+ *
29
+ * ```ts
30
+ * import { assertEquals, assertNotEquals } from '@std/assert'
31
+ * import { at } from '@yaks/ux'
32
+ *
33
+ * assertEquals(at('', 'e1', 'doc', 'title'), at('', 'e1', 'doc', 'title'))
34
+ * assertNotEquals(at('card', 'e1', 'doc', 'title'), at('', 'e1', 'doc', 'title'))
35
+ * ```
36
+ */
37
+ export let at = (
38
+ owner: string,
39
+ eid: string,
40
+ comp: string,
41
+ prop: string,
42
+ ): string => derivedEid(['Edit', owner, eid, `${comp}.${prop}`].join('|'))
43
+
44
+ /** The place the person's draft of `comp.prop` of `eid` is typed in: the
45
+ * value's own, whichever view or interface types over it.
46
+ *
47
+ * ```ts
48
+ * import { assertEquals } from '@std/assert'
49
+ * import { place } from '@yaks/ux'
50
+ *
51
+ * assertEquals(place('e1', 'doc', 'title'), 'edit:e1:doc.title')
52
+ * ```
53
+ */
54
+ export let place = (eid: string, comp: string, prop: string): string =>
55
+ `edit:${eid}:${comp}.${prop}`
56
+
57
+ /** A patch to an `Edit`'s state; `null` closes it, leaving nothing behind.
58
+ *
59
+ * ```ts
60
+ * import { assertEquals } from '@std/assert'
61
+ * import { put } from '@yaks/ux'
62
+ *
63
+ * assertEquals(put('x', { open: true }), [{ entity: { eid: 'x' }, Edit: { open: true } }])
64
+ * assertEquals(put('x', null), [{ entity: { eid: 'x' }, Edit: null }])
65
+ * ```
66
+ */
67
+ export let put = (eid: string, patch: Row | null): Bundle[] => [{
68
+ entity: { eid },
69
+ Edit: patch,
70
+ }]
71
+
72
+ /** A value as the text it is typed over as: a JSON value as its JSON text.
73
+ *
74
+ * ```ts
75
+ * import { assertEquals } from '@std/assert'
76
+ * import { source } from '@yaks/ux'
77
+ *
78
+ * assertEquals([source(null), source(3), source({ a: 1 })], ['', '3', '{"a":1}'])
79
+ * ```
80
+ */
81
+ export let source = (v: unknown): string =>
82
+ v == null ? '' : typeof v == 'object' ? JSON.stringify(v) : String(v)
83
+
84
+ /** The value `comp.prop` of `e` holds. */
85
+ export let valueOf = (
86
+ e: Bundle | undefined,
87
+ comp: string,
88
+ prop: string,
89
+ ): unknown => {
90
+ let row = e?.[comp]
91
+ return row && typeof row == 'object'
92
+ ? (row as Record<string, unknown>)[prop]
93
+ : undefined
94
+ }
95
+
96
+ /** `e`, its `comp.prop` changed to `value`: the bundle an `Edit` emits.
97
+ *
98
+ * ```ts
99
+ * import { assertEquals } from '@std/assert'
100
+ * import { changed } from '@yaks/ux'
101
+ *
102
+ * let e = { entity: { eid: 'e1', num: 3 }, doc: { title: 'Draft', body: 'b' } }
103
+ * assertEquals(changed(e, 'doc', 'title', 'Ship it'), {
104
+ * entity: { eid: 'e1' },
105
+ * doc: { title: 'Ship it' },
106
+ * })
107
+ * ```
108
+ */
109
+ export let changed = (
110
+ e: Bundle,
111
+ comp: string,
112
+ prop: string,
113
+ value: unknown,
114
+ ): Bundle => ({ entity: { eid: e.entity.eid }, [comp]: { [prop]: value } })
115
+
116
+ /** The event an `Edit` emits when what was typed could not be read: on the
117
+ * entity the value belongs to, saying why. */
118
+ export let refused = (e: Bundle, said: string): Bundle => ({
119
+ entity: { eid: e.entity.eid },
120
+ Refused: { said },
121
+ })
package/suggest.js ADDED
@@ -0,0 +1,28 @@
1
+ // Entity suggestions speak the same human id + title vocabulary wherever a
2
+ // picker appears. Candidates are the server's rows, a ranked one carrying a
3
+ // transient `rank` component (a picker asks the graph, not what the page
4
+ // holds: ./hits.ts), so the label reads the row's own fields: the entity may
5
+ // not be held here, and the query already ranked it, so no sort remains.
6
+ // A row's title: the ranked one a search gives, else its document's.
7
+ let titleOf = (b)=>{
8
+ let rank = b.rank;
9
+ let doc = b.doc;
10
+ return String(rank?.title ?? doc?.title ?? '');
11
+ };
12
+ /** A candidate as a picker lists it: `T-9 — Draw the map`, its ranked
13
+ * title where a search gave one, else its document's, else its kind.
14
+ *
15
+ * ```ts
16
+ * import { assertEquals } from '@std/assert'
17
+ * import { label } from '@yaks/ux'
18
+ *
19
+ * import type { Bundle } from '@yaks/graph'
20
+ *
21
+ * let host = { id: (b: Bundle) => `T-${b.entity.num}`, kind: () => 'task' }
22
+ * let row = (num: number, comps = {}) => ({ entity: { eid: 'e', num }, ...comps })
23
+ * assertEquals(label(host, row(1, { doc: { title: 'Older' } })), 'T-1 — Older')
24
+ * assertEquals(label(host, row(2, { rank: { title: 'Ranked' } })), 'T-2 — Ranked')
25
+ * assertEquals(label(host, row(3)), 'T-3 — task')
26
+ * ```
27
+ */ export let label = (host, b)=>`${host.id(b)} — ${titleOf(b) || host.kind(b)}`;
28
+ //# sourceMappingURL=suggest.js.map
package/suggest.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"suggest.js","sources":["./suggest.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,4EAA4E;AAC5E,yEAAyE;AACzE,6EAA6E;AAC7E,yEAAyE;AAGzE,qEAAqE;AACrE,IAAI,UAAU,CAAC;EACb,IAAI,OAAO,EAAE,IAAI;EACjB,IAAI,MAAM,EAAE,GAAG;EACf,OAAO,OAAO,MAAM,SAAS,KAAK,SAAS;AAC7C;AAEA;;;;;;;;;;;;;;;CAeC,GACD,OAAO,IAAI,QAAQ,CAAC,MAAiC,IACnD,GAAG,KAAK,EAAE,CAAC,GAAG,GAAG,EAAE,QAAQ,MAAM,KAAK,IAAI,CAAC,IAAI,CAAA"}
package/suggest.ts ADDED
@@ -0,0 +1,32 @@
1
+ // Entity suggestions speak the same human id + title vocabulary wherever a
2
+ // picker appears. Candidates are the server's rows, a ranked one carrying a
3
+ // transient `rank` component (a picker asks the graph, not what the page
4
+ // holds: ./hits.ts), so the label reads the row's own fields: the entity may
5
+ // not be held here, and the query already ranked it, so no sort remains.
6
+ import type { Bundle, Host } from './host.ts'
7
+
8
+ // A row's title: the ranked one a search gives, else its document's.
9
+ let titleOf = (b: Bundle): string => {
10
+ let rank = b.rank as { title?: unknown } | undefined
11
+ let doc = b.doc as { title?: unknown } | undefined
12
+ return String(rank?.title ?? doc?.title ?? '')
13
+ }
14
+
15
+ /** A candidate as a picker lists it: `T-9 — Draw the map`, its ranked
16
+ * title where a search gave one, else its document's, else its kind.
17
+ *
18
+ * ```ts
19
+ * import { assertEquals } from '@std/assert'
20
+ * import { label } from '@yaks/ux'
21
+ *
22
+ * import type { Bundle } from '@yaks/graph'
23
+ *
24
+ * let host = { id: (b: Bundle) => `T-${b.entity.num}`, kind: () => 'task' }
25
+ * let row = (num: number, comps = {}) => ({ entity: { eid: 'e', num }, ...comps })
26
+ * assertEquals(label(host, row(1, { doc: { title: 'Older' } })), 'T-1 — Older')
27
+ * assertEquals(label(host, row(2, { rank: { title: 'Ranked' } })), 'T-2 — Ranked')
28
+ * assertEquals(label(host, row(3)), 'T-3 — task')
29
+ * ```
30
+ */
31
+ export let label = (host: Pick<Host, 'id' | 'kind'>, b: Bundle): string =>
32
+ `${host.id(b)} — ${titleOf(b) || host.kind(b)}`
package/swipe.js ADDED
@@ -0,0 +1,186 @@
1
+ /**
2
+ * A finger swiping sideways anywhere on the page opens its sidebar: moving
3
+ * right, the one that comes from the left; moving left, the one from the
4
+ * right. Moving back closes the open one. The sidebar follows the finger and,
5
+ * let go, settles open or shut by how far it came and how fast it was moving,
6
+ * with its own motion (@yaks/ui `Layer`).
7
+ *
8
+ * A sidebar is a `Layer-left` or `Layer-right` with an id and `data-swipe`,
9
+ * opened by the address as its link opens it (`#menu`, replacing the
10
+ * fragment, so no history entry). One that stands under the page
11
+ * (`Layer-under`) stays still, and the page over it (its `Layer_Cover`)
12
+ * follows the finger instead, uncovering it. It is one a swipe may open
13
+ * only while the page shows a link to it: where the page lays it beside
14
+ * itself, or has nothing in it, it has none to show.
15
+ *
16
+ * The gesture leaves alone what is not its own:
17
+ * - its axis is locked once the finger has moved `SLOP`, and a mostly
18
+ * upright move scrolls the page as ever;
19
+ * - a touch within `EDGE` of the screen's sides is the browser's (iOS
20
+ * Safari's back and forward);
21
+ * - a field being typed in keeps its touches, to place the caret;
22
+ * - what scrolls sideways under the finger (a carousel, a wide table, a row
23
+ * of tabs) keeps the swipe while it can still scroll that way.
24
+ *
25
+ * ```ts
26
+ * import { axis, placed, settles } from '@yaks/ux/swipe'
27
+ * import { equal } from '@yaks/testing'
28
+ *
29
+ * equal([axis(4, 2), axis(12, 5), axis(5, 12)], [undefined, 'x', 'y'])
30
+ * // A shut sidebar from the left, 300 wide, dragged 120 right.
31
+ * equal(placed('left', 300, false, 120), -180)
32
+ * equal(settles('left', 300, -180, 0), false)
33
+ * equal(settles('left', 300, -180, 0.5), true)
34
+ * ```
35
+ *
36
+ * @module
37
+ */ /** The side a sidebar comes from. */ /** How far in from each side of the screen a touch is the browser's, px. */ export let EDGE = 24;
38
+ /** How far a finger moves before its swipe's axis is locked, px. */ export let SLOP = 10;
39
+ /** How fast a release settles the way it moves, however far, px/ms. */ export let FLING = 0.3;
40
+ /** How long the moves a release's speed is read over, ms. */ let RECENT = 100;
41
+ /** The axis a move of `dx`, `dy` locks to, or none until it is past `SLOP`. */ export let axis = (dx, dy)=>Math.hypot(dx, dy) < SLOP ? undefined : Math.abs(dx) > Math.abs(dy) ? 'x' : 'y';
42
+ /** Which of `sidebars` a swipe moving `dx` moves: the open one when it moves
43
+ * toward its edge, or, none open, the one from the side the finger leaves. */ export let moves = (sidebars, dx)=>{
44
+ let shown = sidebars.find((s)=>s.open);
45
+ if (shown) return shown.edge == 'left' == dx < 0 ? shown : undefined;
46
+ return sidebars.find((s)=>s.edge == (dx > 0 ? 'left' : 'right'));
47
+ };
48
+ /** Where a sidebar from `edge`, `width` wide, stands once the finger has
49
+ * moved `dx` from where it touched: 0 open, `width` off its edge shut. */ export let placed = (edge, width, open, dx)=>{
50
+ let off = edge == 'left' ? -width : width;
51
+ let at = (open ? 0 : off) + dx;
52
+ return Math.min(Math.max(at, Math.min(off, 0)), Math.max(off, 0));
53
+ };
54
+ /** Whether a sidebar let go `at` (as `placed`), moving `speed` px/ms,
55
+ * settles open: the way it was flung, or else open past its middle. */ export let settles = (edge, width, at, speed)=>Math.abs(speed) >= FLING ? edge == 'left' == speed > 0 : Math.abs(at) < width / 2;
56
+ /** Whether what is under the finger, `from` or what holds it, scrolls
57
+ * sideways and can still go the way a finger moving `dx` takes it. */ export let kept = (from, dx, style)=>{
58
+ for(let el = from; el && el != el.ownerDocument.body; el = el.parentElement){
59
+ if (el.scrollWidth <= el.clientWidth + 1) continue;
60
+ if (!/auto|scroll/.test(style(el).overflowX)) continue;
61
+ let room = dx > 0 ? el.scrollLeft > 0 : el.scrollLeft + el.clientWidth < el.scrollWidth - 1;
62
+ if (room) return true;
63
+ }
64
+ return false;
65
+ };
66
+ // What covers a layer under the page: the cover after it.
67
+ let cover = (el)=>{
68
+ let at = el.nextElementSibling;
69
+ while(at && !at.classList.contains('Layer_Cover'))at = at.nextElementSibling;
70
+ return at;
71
+ };
72
+ let EDITABLE = 'input:not([type=button], [type=submit], [type=reset], [type=image]), textarea, select, [contenteditable]';
73
+ // The page's sidebars a swipe may move now, or none while another layer is
74
+ // open over the page.
75
+ let sidebars = (doc, win)=>{
76
+ let hash = win.location.hash;
77
+ let over = hash.length > 1 ? doc.getElementById(hash.slice(1)) : null;
78
+ if (over?.matches('.Layer:not([data-swipe])')) return [];
79
+ return [
80
+ ...doc.querySelectorAll('.Layer[data-swipe][id]')
81
+ ].map((el)=>({
82
+ el,
83
+ edge: el.classList.contains('Layer-left') ? 'left' : 'right',
84
+ open: el == over
85
+ })).filter((s)=>s.open || [
86
+ ...doc.querySelectorAll(`a[href="#${s.el.id}"]`)
87
+ ].some((a)=>a.getClientRects().length > 0));
88
+ };
89
+ /** Open and close `doc`'s sidebars by a finger's swipe. */ export let swipe = (doc, win)=>{
90
+ let touch;
91
+ let drag;
92
+ let point = (e)=>e.touches[0] ?? e.changedTouches[0];
93
+ let start = (e)=>{
94
+ let p = e.touches[0];
95
+ let target = e.target;
96
+ touch = e.touches.length != 1 || drag || p.clientX < EDGE || p.clientX > win.innerWidth - EDGE || target?.closest?.(EDITABLE) ? undefined : {
97
+ x: p.clientX,
98
+ y: p.clientY,
99
+ target
100
+ };
101
+ };
102
+ let lock = (dx)=>{
103
+ let s = moves(sidebars(doc, win), dx);
104
+ if (!s || kept(touch.target, dx, win.getComputedStyle)) return;
105
+ let { el, edge, open } = s;
106
+ let under = el.classList.contains('Layer-under');
107
+ let moved = under ? cover(el) : el;
108
+ if (!moved) return;
109
+ // Held where it stands, so the address opening it moves nothing yet.
110
+ moved.style.transition = 'none';
111
+ if (!open) {
112
+ moved.style.translate = under ? '0px 0' : `${edge == 'left' ? -100 : 100}% 0`;
113
+ win.location.replace(`#${el.id}`);
114
+ }
115
+ let width = el.getBoundingClientRect().width;
116
+ let at = open ? 0 : edge == 'left' ? -width : width;
117
+ let drag = {
118
+ ...s,
119
+ moved,
120
+ under,
121
+ width,
122
+ at,
123
+ recent: []
124
+ };
125
+ put(drag);
126
+ return drag;
127
+ };
128
+ let put = (d)=>d.moved.style.translate = `${d.under ? d.at + d.width : d.at}px 0`;
129
+ let move = (e)=>{
130
+ if (!touch) return;
131
+ let p = point(e);
132
+ let dx = p.clientX - touch.x;
133
+ if (!drag) {
134
+ let locked = axis(dx, p.clientY - touch.y);
135
+ if (!locked) return;
136
+ drag = locked == 'x' && e.cancelable ? lock(dx) : undefined;
137
+ if (!drag) return void (touch = undefined);
138
+ }
139
+ if (e.cancelable) e.preventDefault();
140
+ drag.at = placed(drag.edge, drag.width, drag.open, dx);
141
+ put(drag);
142
+ drag.recent = [
143
+ ...drag.recent,
144
+ [
145
+ e.timeStamp,
146
+ p.clientX
147
+ ]
148
+ ].filter(([t])=>t >= e.timeStamp - RECENT);
149
+ };
150
+ let end = (e)=>{
151
+ let d = drag;
152
+ touch = drag = undefined;
153
+ if (!d) return;
154
+ // A drag owns the release too, so a link or button only activates on a tap.
155
+ if (e.cancelable) e.preventDefault();
156
+ let [first, last] = [
157
+ d.recent[0],
158
+ d.recent.at(-1)
159
+ ];
160
+ let took = first && last ? last[0] - first[0] : 0;
161
+ let speed = took ? (last[1] - first[1]) / took : 0;
162
+ let open = e.type == 'touchcancel' ? d.open : settles(d.edge, d.width, d.at, speed);
163
+ // Handed back to its own motion, which carries it on from the finger.
164
+ d.moved.style.removeProperty('translate');
165
+ d.moved.style.removeProperty('transition');
166
+ if (!open) win.location.replace('#');
167
+ };
168
+ doc.addEventListener('touchstart', start, {
169
+ passive: true
170
+ });
171
+ doc.addEventListener('touchmove', move, {
172
+ passive: false
173
+ });
174
+ doc.addEventListener('touchend', end, {
175
+ passive: false
176
+ });
177
+ doc.addEventListener('touchcancel', end);
178
+ return ()=>{
179
+ doc.removeEventListener('touchstart', start);
180
+ doc.removeEventListener('touchmove', move);
181
+ doc.removeEventListener('touchend', end);
182
+ doc.removeEventListener('touchcancel', end);
183
+ };
184
+ };
185
+ if (typeof document != 'undefined') swipe(document, globalThis);
186
+ //# sourceMappingURL=swipe.js.map
package/swipe.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"swipe.js","sources":["./swipe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoCC,GAED,mCAAmC,GAGnC,0EAA0E,GAC1E,OAAO,IAAI,OAAO,GAAE;AACpB,kEAAkE,GAClE,OAAO,IAAI,OAAO,GAAE;AACpB,qEAAqE,GACrE,OAAO,IAAI,QAAQ,IAAG;AACtB,2DAA2D,GAC3D,IAAI,SAAS;AAEb,6EAA6E,GAC7E,OAAO,IAAI,OAAO,CAAC,IAAY,KAC7B,KAAK,KAAK,CAAC,IAAI,MAAM,OACjB,YACA,KAAK,GAAG,CAAC,MAAM,KAAK,GAAG,CAAC,MACxB,MACA,IAAG;AAET;4EAC4E,GAC5E,OAA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