@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.
- package/Answer.js +43 -0
- package/Answer.js.map +1 -0
- package/Answer.ts +84 -0
- package/Conversation.js +520 -0
- package/Conversation.js.map +1 -0
- package/Conversation.ts +649 -0
- package/ConversationBox.js +106 -0
- package/ConversationBox.js.map +1 -0
- package/ConversationBox.ts +198 -0
- package/ConversationLines.js +29 -0
- package/ConversationLines.js.map +1 -0
- package/ConversationLines.ts +48 -0
- package/Disclosure.js +79 -0
- package/Disclosure.js.map +1 -0
- package/Disclosure.ts +130 -0
- package/Edit.js +330 -0
- package/Edit.js.map +1 -0
- package/Edit.ts +488 -0
- package/EntityPopup.js +35 -0
- package/EntityPopup.js.map +1 -0
- package/EntityPopup.ts +52 -0
- package/Fields.js +161 -0
- package/Fields.js.map +1 -0
- package/Fields.ts +276 -0
- package/LICENSE +202 -0
- package/Order.js +105 -0
- package/Order.js.map +1 -0
- package/Order.ts +159 -0
- package/README.md +1023 -2
- package/Save.js +50 -0
- package/Save.js.map +1 -0
- package/Save.ts +115 -0
- package/Sort.js +49 -0
- package/Sort.js.map +1 -0
- package/Sort.ts +98 -0
- package/Submit.js +115 -0
- package/Submit.js.map +1 -0
- package/Submit.ts +174 -0
- package/Text.js +114 -0
- package/Text.js.map +1 -0
- package/Text.ts +140 -0
- package/TokenPicker.js +65 -0
- package/TokenPicker.js.map +1 -0
- package/TokenPicker.ts +117 -0
- package/_dist/Answer.d.ts +39 -0
- package/_dist/Answer.d.ts.map +1 -0
- package/_dist/Conversation.d.ts +131 -0
- package/_dist/Conversation.d.ts.map +1 -0
- package/_dist/ConversationBox.d.ts +29 -0
- package/_dist/ConversationBox.d.ts.map +1 -0
- package/_dist/ConversationLines.d.ts +13 -0
- package/_dist/ConversationLines.d.ts.map +1 -0
- package/_dist/Disclosure.d.ts +36 -0
- package/_dist/Disclosure.d.ts.map +1 -0
- package/_dist/Edit.d.ts +87 -0
- package/_dist/Edit.d.ts.map +1 -0
- package/_dist/EntityPopup.d.ts +12 -0
- package/_dist/EntityPopup.d.ts.map +1 -0
- package/_dist/Fields.d.ts +29 -0
- package/_dist/Fields.d.ts.map +1 -0
- package/_dist/Order.d.ts +40 -0
- package/_dist/Order.d.ts.map +1 -0
- package/_dist/Save.d.ts +28 -0
- package/_dist/Save.d.ts.map +1 -0
- package/_dist/Sort.d.ts +28 -0
- package/_dist/Sort.d.ts.map +1 -0
- package/_dist/Submit.d.ts +48 -0
- package/_dist/Submit.d.ts.map +1 -0
- package/_dist/Text.d.ts +27 -0
- package/_dist/Text.d.ts.map +1 -0
- package/_dist/TokenPicker.d.ts +19 -0
- package/_dist/TokenPicker.d.ts.map +1 -0
- package/_dist/anchor.d.ts +52 -0
- package/_dist/anchor.d.ts.map +1 -0
- package/_dist/anchored.d.ts +30 -0
- package/_dist/anchored.d.ts.map +1 -0
- package/_dist/completion-state.d.ts +65 -0
- package/_dist/completion-state.d.ts.map +1 -0
- package/_dist/completion.d.ts +73 -0
- package/_dist/completion.d.ts.map +1 -0
- package/_dist/composer-browser.d.ts +1 -0
- package/_dist/composer-browser.d.ts.map +1 -0
- package/_dist/composer.d.ts +31 -0
- package/_dist/composer.d.ts.map +1 -0
- package/_dist/context-menu-browser.d.ts +4 -0
- package/_dist/context-menu-browser.d.ts.map +1 -0
- package/_dist/context-menu.d.ts +95 -0
- package/_dist/context-menu.d.ts.map +1 -0
- package/_dist/drag.d.ts +29 -0
- package/_dist/drag.d.ts.map +1 -0
- package/_dist/edit-keys.d.ts +42 -0
- package/_dist/edit-keys.d.ts.map +1 -0
- package/_dist/emit.d.ts +7 -0
- package/_dist/emit.d.ts.map +1 -0
- package/_dist/entity-popup-browser.d.ts +3 -0
- package/_dist/entity-popup-browser.d.ts.map +1 -0
- package/_dist/face/FaceTagger.d.ts +25 -0
- package/_dist/face/FaceTagger.d.ts.map +1 -0
- package/_dist/face/review.d.ts +5 -0
- package/_dist/face/review.d.ts.map +1 -0
- package/_dist/face/tags.d.ts +99 -0
- package/_dist/face/tags.d.ts.map +1 -0
- package/_dist/field-values.d.ts +4 -0
- package/_dist/field-values.d.ts.map +1 -0
- package/_dist/fit-list.d.ts +4 -0
- package/_dist/fit-list.d.ts.map +1 -0
- package/_dist/hits.d.ts +27 -0
- package/_dist/hits.d.ts.map +1 -0
- package/_dist/host.d.ts +91 -0
- package/_dist/host.d.ts.map +1 -0
- package/_dist/image-fallback.d.ts +5 -0
- package/_dist/image-fallback.d.ts.map +1 -0
- package/_dist/keys.d.ts +95 -0
- package/_dist/keys.d.ts.map +1 -0
- package/_dist/kit.d.ts +23 -0
- package/_dist/kit.d.ts.map +1 -0
- package/_dist/lightbox-browser.d.ts +2 -0
- package/_dist/lightbox-browser.d.ts.map +1 -0
- package/_dist/lightbox.d.ts +42 -0
- package/_dist/lightbox.d.ts.map +1 -0
- package/_dist/live.d.ts +21 -0
- package/_dist/live.d.ts.map +1 -0
- package/_dist/mod.d.ts +67 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/read.d.ts +12 -0
- package/_dist/read.d.ts.map +1 -0
- package/_dist/resize.d.ts +43 -0
- package/_dist/resize.d.ts.map +1 -0
- package/_dist/rows.d.ts +31 -0
- package/_dist/rows.d.ts.map +1 -0
- package/_dist/save-browser.d.ts +29 -0
- package/_dist/save-browser.d.ts.map +1 -0
- package/_dist/select-browser.d.ts +1 -0
- package/_dist/select-browser.d.ts.map +1 -0
- package/_dist/select.d.ts +12 -0
- package/_dist/select.d.ts.map +1 -0
- package/_dist/sending.d.ts +10 -0
- package/_dist/sending.d.ts.map +1 -0
- package/_dist/sort-browser.d.ts +11 -0
- package/_dist/sort-browser.d.ts.map +1 -0
- package/_dist/state.d.ts +74 -0
- package/_dist/state.d.ts.map +1 -0
- package/_dist/suggest.d.ts +18 -0
- package/_dist/suggest.d.ts.map +1 -0
- package/_dist/swipe.d.ts +60 -0
- package/_dist/swipe.d.ts.map +1 -0
- package/_dist/ui.d.ts +6 -0
- package/_dist/ui.d.ts.map +1 -0
- package/_dist/upload-browser.d.ts +13 -0
- package/_dist/upload-browser.d.ts.map +1 -0
- package/_dist/views.d.ts +8 -0
- package/_dist/views.d.ts.map +1 -0
- package/_dist/vocab.d.ts +6 -0
- package/_dist/vocab.d.ts.map +1 -0
- package/anchor.js +58 -0
- package/anchor.js.map +1 -0
- package/anchor.ts +87 -0
- package/anchored.js +180 -0
- package/anchored.js.map +1 -0
- package/anchored.ts +232 -0
- package/completion-state.js +76 -0
- package/completion-state.js.map +1 -0
- package/completion-state.ts +120 -0
- package/completion.js +301 -0
- package/completion.js.map +1 -0
- package/completion.ts +433 -0
- package/composer-browser.js +4 -0
- package/composer-browser.js.map +1 -0
- package/composer-browser.ts +5 -0
- package/composer.js +42 -0
- package/composer.js.map +1 -0
- package/composer.ts +53 -0
- package/context-menu-browser.js +221 -0
- package/context-menu-browser.js.map +1 -0
- package/context-menu-browser.ts +231 -0
- package/context-menu.js +146 -0
- package/context-menu.js.map +1 -0
- package/context-menu.ts +194 -0
- package/deno.json +1 -0
- package/drag.js +33 -0
- package/drag.js.map +1 -0
- package/drag.ts +41 -0
- package/edit-keys.js +51 -0
- package/edit-keys.js.map +1 -0
- package/edit-keys.ts +81 -0
- package/emit.js +34 -0
- package/emit.js.map +1 -0
- package/emit.ts +55 -0
- package/entity-popup-browser.js +94 -0
- package/entity-popup-browser.js.map +1 -0
- package/entity-popup-browser.ts +100 -0
- package/face/FaceTagger.js +361 -0
- package/face/FaceTagger.js.map +1 -0
- package/face/FaceTagger.ts +507 -0
- package/face/NameProposal.js +61 -0
- package/face/NameProposal.js.map +1 -0
- package/face/NameProposal.ts +100 -0
- package/face/review.js +33 -0
- package/face/review.js.map +1 -0
- package/face/review.ts +49 -0
- package/face/tags.js +344 -0
- package/face/tags.js.map +1 -0
- package/face/tags.ts +357 -0
- package/field-values.js +20 -0
- package/field-values.js.map +1 -0
- package/field-values.ts +35 -0
- package/fit-list.js +66 -0
- package/fit-list.js.map +1 -0
- package/fit-list.ts +81 -0
- package/hits.js +65 -0
- package/hits.js.map +1 -0
- package/hits.ts +75 -0
- package/host.js +88 -0
- package/host.js.map +1 -0
- package/host.ts +212 -0
- package/image-fallback.js +32 -0
- package/image-fallback.js.map +1 -0
- package/image-fallback.ts +37 -0
- package/keys.js +418 -0
- package/keys.js.map +1 -0
- package/keys.ts +444 -0
- package/kit.js +41 -0
- package/kit.js.map +1 -0
- package/kit.ts +71 -0
- package/lightbox-browser.js +248 -0
- package/lightbox-browser.js.map +1 -0
- package/lightbox-browser.ts +232 -0
- package/lightbox.js +84 -0
- package/lightbox.js.map +1 -0
- package/lightbox.ts +103 -0
- package/live.js +111 -0
- package/live.js.map +1 -0
- package/live.ts +139 -0
- package/mod.js +67 -0
- package/mod.js.map +1 -0
- package/mod.ts +180 -0
- package/package.json +143 -4
- package/read.js +33 -0
- package/read.js.map +1 -0
- package/read.ts +56 -0
- package/resize.js +159 -0
- package/resize.js.map +1 -0
- package/resize.ts +203 -0
- package/rows.js +73 -0
- package/rows.js.map +1 -0
- package/rows.ts +97 -0
- package/save-browser.js +469 -0
- package/save-browser.js.map +1 -0
- package/save-browser.ts +530 -0
- package/select-browser.js +4 -0
- package/select-browser.js.map +1 -0
- package/select-browser.ts +5 -0
- package/select.js +296 -0
- package/select.js.map +1 -0
- package/select.ts +343 -0
- package/sending.js +36 -0
- package/sending.js.map +1 -0
- package/sending.ts +44 -0
- package/sort-browser.js +51 -0
- package/sort-browser.js.map +1 -0
- package/sort-browser.ts +70 -0
- package/state.js +99 -0
- package/state.js.map +1 -0
- package/state.ts +121 -0
- package/suggest.js +28 -0
- package/suggest.js.map +1 -0
- package/suggest.ts +32 -0
- package/swipe.js +186 -0
- package/swipe.js.map +1 -0
- package/swipe.ts +250 -0
- package/ui.js +507 -0
- package/ui.js.map +1 -0
- package/ui.ts +378 -0
- package/upload-browser.js +195 -0
- package/upload-browser.js.map +1 -0
- package/upload-browser.ts +303 -0
- package/upload-files.js +41 -0
- package/upload-files.js.map +1 -0
- package/upload-files.ts +49 -0
- package/views.js +8 -0
- package/views.js.map +1 -0
- package/views.ts +9 -0
- package/vocab.js +16 -0
- package/vocab.js.map +1 -0
- package/vocab.json +287 -0
- package/vocab.ts +17 -0
package/context-menu.ts
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What can be done with an item, and the menu that offers it. An item's
|
|
3
|
+
* actions are declared once, beside what draws that kind of item (an app's
|
|
4
|
+
* beside its tile, @yaks/platform/app-tile `appActions`), as data: a label
|
|
5
|
+
* and what a press does. The item's menu (`ActionMenu`) and its own buttons
|
|
6
|
+
* (`actionProps`) are drawn from the same declaration, so they cannot drift.
|
|
7
|
+
*
|
|
8
|
+
* An item opens its menu (`menuOf`) by a right-click, a long press on a touch
|
|
9
|
+
* screen, the menu key or Shift+F10 while it holds the focus, and its ⋯
|
|
10
|
+
* (`Menu.More`). The menu is @yaks/ui's `Menu.Context`, a popover: Escape and
|
|
11
|
+
* a press elsewhere close it, the arrow keys walk its items, and the focus
|
|
12
|
+
* goes back to the item. The page's script binds it all once
|
|
13
|
+
* (./context-menu-browser.ts `contextMenus`).
|
|
14
|
+
*
|
|
15
|
+
* A press does one of:
|
|
16
|
+
* - `href`: opens a page, in a new tab with `tab`;
|
|
17
|
+
* - `opens`: opens the dialog (a popover) of that id on the page;
|
|
18
|
+
* - `submits`: sends the form of that id on the page, as its own button
|
|
19
|
+
* would, with the name and value of `sends` where the button carries one;
|
|
20
|
+
* - `copy`: puts the words on the clipboard;
|
|
21
|
+
* - `link`: puts a link on the clipboard, a path made whole against the page;
|
|
22
|
+
* - `share`: hands a link to the device's share sheet, or copies it where
|
|
23
|
+
* there is none;
|
|
24
|
+
* - `data`: marks the press with data attributes the page's own script
|
|
25
|
+
* answers, as it answers the item's own button (the friends dock's
|
|
26
|
+
* `data-dock-friend`).
|
|
27
|
+
*
|
|
28
|
+
* ```ts
|
|
29
|
+
* import { actionProps, moved, opensMenu } from '@yaks/ux/context-menu'
|
|
30
|
+
* import { equal } from '@yaks/testing'
|
|
31
|
+
*
|
|
32
|
+
* equal(opensMenu({ key: 'ContextMenu', shiftKey: false }), true)
|
|
33
|
+
* equal(opensMenu({ key: 'F10', shiftKey: true }), true)
|
|
34
|
+
* equal(opensMenu({ key: 'F10', shiftKey: false }), false)
|
|
35
|
+
* // Three items: down from the last wraps to the first; End to the last.
|
|
36
|
+
* equal(moved('ArrowDown', 2, 3), 0)
|
|
37
|
+
* equal(moved('ArrowUp', 0, 3), 2)
|
|
38
|
+
* equal(moved('End', 0, 3), 2)
|
|
39
|
+
* equal(moved('Enter', 1, 3), undefined)
|
|
40
|
+
* // A press the page's own script answers wears its marks.
|
|
41
|
+
* equal(actionProps({ label: 'Message', data: { 'dock-friend': 'bo' } }), {
|
|
42
|
+
* as: 'button',
|
|
43
|
+
* type: 'button',
|
|
44
|
+
* 'data-dock-friend': 'bo',
|
|
45
|
+
* })
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @module
|
|
49
|
+
*/
|
|
50
|
+
/* @ts-types="npm:@types/react@19.3.0" */ import { createElement as h, Fragment, type ReactNode } from 'react'
|
|
51
|
+
import { Icon } from '@yaks/ui/Icon'
|
|
52
|
+
import { Menu } from '@yaks/ui/Menu'
|
|
53
|
+
import type { IconNode } from 'npm:lucide@1.31.0'
|
|
54
|
+
// @ts-types="@yaks/ui/lucide"
|
|
55
|
+
import Ellipsis from 'lucide/dist/esm/icons/ellipsis.mjs'
|
|
56
|
+
|
|
57
|
+
/** One thing a person can do with an item. */
|
|
58
|
+
export type Action = {
|
|
59
|
+
label: string
|
|
60
|
+
href?: string
|
|
61
|
+
/** Whether to open a new tab. Omit to use the page's link behavior. */
|
|
62
|
+
tab?: boolean
|
|
63
|
+
opens?: string
|
|
64
|
+
submits?: string
|
|
65
|
+
/** The name and value a press sends with the form it `submits`. */
|
|
66
|
+
sends?: [string, string]
|
|
67
|
+
copy?: string
|
|
68
|
+
link?: string
|
|
69
|
+
share?: string
|
|
70
|
+
/** Data attributes, without their `data-`, the page's script answers. */
|
|
71
|
+
data?: Record<string, string>
|
|
72
|
+
/** It loses something: drawn last, after a rule, in the danger ink. */
|
|
73
|
+
danger?: boolean
|
|
74
|
+
icon?: IconNode
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** An item's actions by name, in the order its menu offers them; a name
|
|
78
|
+
* whose action the page cannot offer is left undefined. */
|
|
79
|
+
export type Actions = Record<string, Action | undefined>
|
|
80
|
+
|
|
81
|
+
/** The attribute naming the menu an item opens. */
|
|
82
|
+
export let ITEM = 'data-context-menu'
|
|
83
|
+
|
|
84
|
+
/** How long a finger rests on an item before its menu opens, ms. */
|
|
85
|
+
export let HOLD = 500
|
|
86
|
+
/** How far a finger may wander and still be holding, px. */
|
|
87
|
+
export let SLOP = 10
|
|
88
|
+
|
|
89
|
+
/** The props an item wears to open the menu `id`. */
|
|
90
|
+
export let menuOf = (id: string): Record<string, string> => ({ [ITEM]: id })
|
|
91
|
+
|
|
92
|
+
/** The props of a button or link that does `a`: an `href` for a link, the
|
|
93
|
+
* rest for a `button`. A menu's items and an item's own buttons both wear
|
|
94
|
+
* them. */
|
|
95
|
+
export let actionProps = (a: Action): Record<string, unknown> =>
|
|
96
|
+
a.href
|
|
97
|
+
? {
|
|
98
|
+
as: 'a',
|
|
99
|
+
href: a.href,
|
|
100
|
+
...a.tab === true ? { target: '_blank', rel: 'noopener' } : {},
|
|
101
|
+
...a.tab === false ? { target: '_self' } : {},
|
|
102
|
+
}
|
|
103
|
+
: a.submits
|
|
104
|
+
? {
|
|
105
|
+
as: 'button',
|
|
106
|
+
type: 'submit',
|
|
107
|
+
form: a.submits,
|
|
108
|
+
...a.sends ? { name: a.sends[0], value: a.sends[1] } : {},
|
|
109
|
+
}
|
|
110
|
+
: {
|
|
111
|
+
as: 'button',
|
|
112
|
+
type: 'button',
|
|
113
|
+
...a.opens ? { popovertarget: a.opens } : {},
|
|
114
|
+
...a.copy != null ? { 'data-copy': a.copy } : {},
|
|
115
|
+
...a.link != null ? { 'data-link': a.link } : {},
|
|
116
|
+
...a.share != null ? { 'data-share': a.share } : {},
|
|
117
|
+
...Object.fromEntries(
|
|
118
|
+
Object.entries(a.data ?? {}).map(([k, v]) => [`data-${k}`, v]),
|
|
119
|
+
),
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// What can be offered: those the page left undefined drop out, the ones that
|
|
123
|
+
// lose something go last.
|
|
124
|
+
let offered = (actions: Actions) => {
|
|
125
|
+
let all = Object.values(actions).filter((a): a is Action => !!a)
|
|
126
|
+
return [all.filter((a) => !a.danger), all.filter((a) => a.danger)]
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** The item's menu, `id`, offering `actions`: what its right-click, long
|
|
130
|
+
* press and ⋯ open. `label` names it to a screen reader. */
|
|
131
|
+
export let ActionMenu = (
|
|
132
|
+
{ id, label, actions }: { id: string; label: string; actions: Actions },
|
|
133
|
+
): ReactNode => {
|
|
134
|
+
let [safe, danger] = offered(actions)
|
|
135
|
+
let item = (a: Action) =>
|
|
136
|
+
h(
|
|
137
|
+
Menu.Item,
|
|
138
|
+
{
|
|
139
|
+
key: a.label,
|
|
140
|
+
role: 'menuitem',
|
|
141
|
+
mod: a.danger ? 'danger' : undefined,
|
|
142
|
+
...actionProps(a),
|
|
143
|
+
},
|
|
144
|
+
a.icon ? h(Icon, { of: a.icon }) : null,
|
|
145
|
+
a.label,
|
|
146
|
+
)
|
|
147
|
+
return h(
|
|
148
|
+
Menu.Context,
|
|
149
|
+
{ id, 'aria-label': label },
|
|
150
|
+
safe.map(item),
|
|
151
|
+
safe.length && danger.length ? h(Menu.Rule, { role: 'separator' }) : null,
|
|
152
|
+
danger.map(item),
|
|
153
|
+
)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** The item's ⋯, opening its menu `id`; `label` says whose menu it is. */
|
|
157
|
+
export let MoreButton = (
|
|
158
|
+
{ id, label }: { id: string; label: string },
|
|
159
|
+
): ReactNode =>
|
|
160
|
+
h(
|
|
161
|
+
Menu.More,
|
|
162
|
+
{
|
|
163
|
+
type: 'button',
|
|
164
|
+
popovertarget: id,
|
|
165
|
+
'aria-haspopup': 'menu',
|
|
166
|
+
'aria-expanded': 'false',
|
|
167
|
+
'aria-label': label,
|
|
168
|
+
'data-tip': 'More',
|
|
169
|
+
},
|
|
170
|
+
h(Icon, { of: Ellipsis }),
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
/** An item's menu and its ⋯ together, for a row that shows both. */
|
|
174
|
+
export let MoreMenu = (
|
|
175
|
+
props: { id: string; label: string; actions: Actions },
|
|
176
|
+
): ReactNode => h(Fragment, null, h(MoreButton, props), h(ActionMenu, props))
|
|
177
|
+
|
|
178
|
+
/** Whether a key opens the focused item's menu: the menu key, or Shift+F10. */
|
|
179
|
+
export let opensMenu = (e: { key: string; shiftKey: boolean }): boolean =>
|
|
180
|
+
e.key == 'ContextMenu' || (e.key == 'F10' && e.shiftKey)
|
|
181
|
+
|
|
182
|
+
/** Where the arrow keys, Home and End move from item `at` of `n`, wrapping
|
|
183
|
+
* at either end, or undefined for a key that does not move. */
|
|
184
|
+
export let moved = (
|
|
185
|
+
key: string,
|
|
186
|
+
at: number,
|
|
187
|
+
n: number,
|
|
188
|
+
): number | undefined =>
|
|
189
|
+
!n ? undefined : {
|
|
190
|
+
ArrowDown: (at + 1) % n,
|
|
191
|
+
ArrowUp: (at - 1 + n) % n,
|
|
192
|
+
Home: 0,
|
|
193
|
+
End: n - 1,
|
|
194
|
+
}[key]
|
package/deno.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"publish":{"exclude":["**/*_test.ts","**/*_test.tsx"]},"name":"@yaks/ux","version":"0.2.36","license":"Apache-2.0","description":"Controlled components for editing, navigation, fields and submissions. Page state lives in graph bundles; durable drafts belong to the host.","exports":{".":"./mod.ts","./views":"./views.ts","./vocab":"./vocab.ts","./ui":"./ui.ts","./conversation":"./Conversation.ts","./anchor":"./anchor.ts","./anchored":"./anchored.ts","./completion":"./completion.ts","./entity-popup":"./EntityPopup.ts","./entity-popup-browser":"./entity-popup-browser.ts","./lightbox":"./lightbox.ts","./lightbox-browser":"./lightbox-browser.ts","./keys":"./keys.ts","./edit-keys":"./edit-keys.ts","./save":"./save-browser.ts","./sort":"./sort-browser.ts","./sending":"./sending.ts","./composer":"./composer.ts","./composer-browser":"./composer-browser.ts","./select":"./select.ts","./select-browser":"./select-browser.ts","./context-menu":"./context-menu.ts","./context-menu-browser":"./context-menu-browser.ts","./fit-list":"./fit-list.ts","./swipe":"./swipe.ts","./resize":"./resize.ts","./image-fallback":"./image-fallback.ts","./upload":"./upload-browser.ts","./token-picker":"./TokenPicker.ts","./face-tagger":"./face/FaceTagger.ts"},"imports":{"@yaks/ux":"./mod.ts","@yaks/ux/views":"./views.ts","@yaks/ux/vocab":"./vocab.ts","@yaks/ux/ui":"./ui.ts","@yaks/ux/conversation":"./Conversation.ts","@yaks/ux/anchor":"./anchor.ts","@yaks/ux/anchored":"./anchored.ts","@yaks/ux/completion":"./completion.ts","@yaks/ux/entity-popup":"./EntityPopup.ts","@yaks/ux/entity-popup-browser":"./entity-popup-browser.ts","@yaks/ux/lightbox":"./lightbox.ts","@yaks/ux/lightbox-browser":"./lightbox-browser.ts","@yaks/ux/keys":"./keys.ts","@yaks/ux/edit-keys":"./edit-keys.ts","@yaks/ux/save":"./save-browser.ts","@yaks/ux/sort":"./sort-browser.ts","@yaks/ux/sending":"./sending.ts","@yaks/ux/composer":"./composer.ts","@yaks/ux/composer-browser":"./composer-browser.ts","@yaks/ux/select":"./select.ts","@yaks/ux/select-browser":"./select-browser.ts","@yaks/ux/context-menu":"./context-menu.ts","@yaks/ux/context-menu-browser":"./context-menu-browser.ts","@yaks/ux/fit-list":"./fit-list.ts","@yaks/ux/swipe":"./swipe.ts","@yaks/ux/resize":"./resize.ts","@yaks/ux/image-fallback":"./image-fallback.ts","@yaks/ux/upload":"./upload-browser.ts","@yaks/ux/token-picker":"./TokenPicker.ts","@yaks/ux/face-tagger":"./face/FaceTagger.ts"}}
|
package/drag.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An entity dragged from any place on a page to any other: a row dragged out
|
|
3
|
+
* of one list says which entity it stands for under one type, and the list it
|
|
4
|
+
* is dropped on reads it, whichever package drew either. A drag says which
|
|
5
|
+
* entity it holds only when it is dropped; while it moves, a place can ask
|
|
6
|
+
* only whether it holds one (`drags`), to say it would take it.
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { drag, dragged, drags } from '@yaks/ux'
|
|
10
|
+
* import { equal } from '@yaks/testing'
|
|
11
|
+
*
|
|
12
|
+
* let kept = new Map<string, string>()
|
|
13
|
+
* let dataTransfer = {
|
|
14
|
+
* get types() { return [...kept.keys()] },
|
|
15
|
+
* setData: (type: string, value: string) => kept.set(type, value),
|
|
16
|
+
* getData: (type: string) => kept.get(type) ?? '',
|
|
17
|
+
* }
|
|
18
|
+
* let ev = { dataTransfer } as unknown as DragEvent
|
|
19
|
+
* equal(drags(ev), false)
|
|
20
|
+
* drag(ev, 'M-1')
|
|
21
|
+
* equal([drags(ev), dragged(ev)], [true, 'M-1'])
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @module
|
|
25
|
+
*/ /** The type a dragged entity's eid travels under. */ export let DRAGGED = 'application/x-yaks-entity';
|
|
26
|
+
/** Put an entity in a drag, as it starts. */ export let drag = (ev, eid)=>{
|
|
27
|
+
ev.dataTransfer?.setData(DRAGGED, eid);
|
|
28
|
+
};
|
|
29
|
+
/** Whether a drag holds an entity: all a place can know before the drop. */ export let drags = (ev)=>[
|
|
30
|
+
...ev.dataTransfer?.types ?? []
|
|
31
|
+
].includes(DRAGGED);
|
|
32
|
+
/** The entity a dropped drag holds, or nothing. */ export let dragged = (ev)=>ev.dataTransfer?.getData(DRAGGED) ?? '';
|
|
33
|
+
//# sourceMappingURL=drag.js.map
|
package/drag.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drag.js","sources":["./drag.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;CAwBC,GAED,mDAAmD,GACnD,OAAO,IAAI,UAAU,4BAA2B;AAEhD,2CAA2C,GAC3C,OAAO,IAAI,OAAO,CAAC,IAAe;EAChC,GAAG,YAAY,EAAE,QAAQ,SAAS;AACpC,EAAC;AAED,0EAA0E,GAC1E,OAAO,IAAI,QAAQ,CAAC,KAClB;OAAI,GAAG,YAAY,EAAE,SAAS,EAAE;GAAC,CAAC,QAAQ,CAAC,SAAQ;AAErD,iDAAiD,GACjD,OAAO,IAAI,UAAU,CAAC,KACpB,GAAG,YAAY,EAAE,QAAQ,YAAY,GAAE"}
|
package/drag.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An entity dragged from any place on a page to any other: a row dragged out
|
|
3
|
+
* of one list says which entity it stands for under one type, and the list it
|
|
4
|
+
* is dropped on reads it, whichever package drew either. A drag says which
|
|
5
|
+
* entity it holds only when it is dropped; while it moves, a place can ask
|
|
6
|
+
* only whether it holds one (`drags`), to say it would take it.
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { drag, dragged, drags } from '@yaks/ux'
|
|
10
|
+
* import { equal } from '@yaks/testing'
|
|
11
|
+
*
|
|
12
|
+
* let kept = new Map<string, string>()
|
|
13
|
+
* let dataTransfer = {
|
|
14
|
+
* get types() { return [...kept.keys()] },
|
|
15
|
+
* setData: (type: string, value: string) => kept.set(type, value),
|
|
16
|
+
* getData: (type: string) => kept.get(type) ?? '',
|
|
17
|
+
* }
|
|
18
|
+
* let ev = { dataTransfer } as unknown as DragEvent
|
|
19
|
+
* equal(drags(ev), false)
|
|
20
|
+
* drag(ev, 'M-1')
|
|
21
|
+
* equal([drags(ev), dragged(ev)], [true, 'M-1'])
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @module
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/** The type a dragged entity's eid travels under. */
|
|
28
|
+
export let DRAGGED = 'application/x-yaks-entity'
|
|
29
|
+
|
|
30
|
+
/** Put an entity in a drag, as it starts. */
|
|
31
|
+
export let drag = (ev: DragEvent, eid: string): void => {
|
|
32
|
+
ev.dataTransfer?.setData(DRAGGED, eid)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Whether a drag holds an entity: all a place can know before the drop. */
|
|
36
|
+
export let drags = (ev: DragEvent): boolean =>
|
|
37
|
+
[...ev.dataTransfer?.types ?? []].includes(DRAGGED)
|
|
38
|
+
|
|
39
|
+
/** The entity a dropped drag holds, or nothing. */
|
|
40
|
+
export let dragged = (ev: DragEvent): string =>
|
|
41
|
+
ev.dataTransfer?.getData(DRAGGED) ?? ''
|
package/edit-keys.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The keys of anything typed where it stands: Enter keeps what is typed and
|
|
3
|
+
* Escape cancels it. `Edit.Text` reads its keys here, and so does every
|
|
4
|
+
* editor that is not one property (a line that files a task, a filter, a
|
|
5
|
+
* command line, a note), so each answers the same keys.
|
|
6
|
+
*
|
|
7
|
+
* A line keeps on Enter, and Shift+Enter starts a new line in it. A field of
|
|
8
|
+
* many lines (`multi`) types a new line on Enter and keeps on Ctrl+Enter or
|
|
9
|
+
* ⌘+Enter. The key that ends a composition (an IME, a phone's keyboard) only
|
|
10
|
+
* ends it, and a key another handler took first (`defaultPrevented`: a
|
|
11
|
+
* completion list choosing, the layer in front closing) is left to it.
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { editKey } from '@yaks/ux/edit-keys'
|
|
15
|
+
* import { equal } from '@yaks/testing'
|
|
16
|
+
*
|
|
17
|
+
* let key = (key: string, more = {}, multi = false) =>
|
|
18
|
+
* editKey({ key, ...more }, multi)
|
|
19
|
+
* equal(key('Enter'), 'keep')
|
|
20
|
+
* equal(key('Escape'), 'cancel')
|
|
21
|
+
* equal(key('Enter', { shiftKey: true }), undefined)
|
|
22
|
+
* equal(key('Enter', {}, true), undefined)
|
|
23
|
+
* equal(key('Enter', { metaKey: true }, true), 'keep')
|
|
24
|
+
* equal(key('Escape', { isComposing: true }), undefined)
|
|
25
|
+
* equal(key('a'), undefined)
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @module
|
|
29
|
+
*/ /** What of a key press decides what it does to what is typed. */ // React's own event leaves out whether a composition is on: its browser's
|
|
30
|
+
// event says.
|
|
31
|
+
let composing = (ev)=>ev.isComposing || !!ev.nativeEvent?.isComposing;
|
|
32
|
+
/** What `ev` does to what is typed in a line, or in a field of many lines
|
|
33
|
+
* (`multi`); undefined when it types, or is not this editor's. */ export let editKey = (ev, multi = false)=>{
|
|
34
|
+
if (composing(ev) || ev.defaultPrevented) return;
|
|
35
|
+
if (ev.key == 'Escape') return 'cancel';
|
|
36
|
+
if (ev.key != 'Enter' || ev.shiftKey) return;
|
|
37
|
+
if (!multi || ev.ctrlKey || ev.metaKey) return 'keep';
|
|
38
|
+
};
|
|
39
|
+
/** A field's keydown handler: Enter keeps and Escape cancels, each taking
|
|
40
|
+
* its key. Answers whether it took it, for a handler that reads other keys
|
|
41
|
+
* after it. */ export let editKeys = (o)=>(ev)=>{
|
|
42
|
+
let field = ev.currentTarget;
|
|
43
|
+
let edit = editKey(ev, o.multi);
|
|
44
|
+
if (!edit || edit == 'keep' && !o.keep) return false;
|
|
45
|
+
ev.preventDefault();
|
|
46
|
+
if (edit == 'keep') o.keep(field);
|
|
47
|
+
else if (o.cancel) o.cancel(field);
|
|
48
|
+
else field.blur();
|
|
49
|
+
return true;
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=edit-keys.js.map
|
package/edit-keys.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"edit-keys.js","sources":["./edit-keys.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4BC,GAED,+DAA+D,GAU/D,0EAA0E;AAC1E,cAAc;AACd,IAAI,YAAY,CAAC,KACf,GAAG,WAAW,IAAI,CAAC,CAAC,AAAC,GAA6B,WAAW,EAAE;AAKjE;gEACgE,GAChE,OAAO,IAAI,UAAU,CAAC,IAAS,QAAQ,KAAK;EAC1C,IAAI,UAAU,OAAO,GAAG,gBAAgB,EAAE;EAC1C,IAAI,GAAG,GAAG,IAAI,UAAU,OAAO;EAC/B,IAAI,GAAG,GAAG,IAAI,WAAW,GAAG,QAAQ,EAAE;EACtC,IAAI,CAAC,SAAS,GAAG,OAAO,IAAI,GAAG,OAAO,EAAE,OAAO;AACjD,EAAC;AAaD;;aAEa,GACb,OAAO,IAAI,WAAW,CAAC,IAAgB,CAAC;IACtC,IAAI,QAAQ,GAAG,aAAa;IAC5B,IAAI,OAAO,QAAQ,IAAI,EAAE,KAAK;IAC9B,IAAI,CAAC,QAAQ,QAAQ,UAAU,CAAC,EAAE,IAAI,EAAE,OAAO;IAC/C,GAAG,cAAc;IACjB,IAAI,QAAQ,QAAQ,EAAE,IAAI,CAAE;SACvB,IAAI,EAAE,MAAM,EAAE,EAAE,MAAM,CAAC;SACvB,MAAM,IAAI;IACf,OAAO;EACT,EAAC"}
|
package/edit-keys.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The keys of anything typed where it stands: Enter keeps what is typed and
|
|
3
|
+
* Escape cancels it. `Edit.Text` reads its keys here, and so does every
|
|
4
|
+
* editor that is not one property (a line that files a task, a filter, a
|
|
5
|
+
* command line, a note), so each answers the same keys.
|
|
6
|
+
*
|
|
7
|
+
* A line keeps on Enter, and Shift+Enter starts a new line in it. A field of
|
|
8
|
+
* many lines (`multi`) types a new line on Enter and keeps on Ctrl+Enter or
|
|
9
|
+
* ⌘+Enter. The key that ends a composition (an IME, a phone's keyboard) only
|
|
10
|
+
* ends it, and a key another handler took first (`defaultPrevented`: a
|
|
11
|
+
* completion list choosing, the layer in front closing) is left to it.
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { editKey } from '@yaks/ux/edit-keys'
|
|
15
|
+
* import { equal } from '@yaks/testing'
|
|
16
|
+
*
|
|
17
|
+
* let key = (key: string, more = {}, multi = false) =>
|
|
18
|
+
* editKey({ key, ...more }, multi)
|
|
19
|
+
* equal(key('Enter'), 'keep')
|
|
20
|
+
* equal(key('Escape'), 'cancel')
|
|
21
|
+
* equal(key('Enter', { shiftKey: true }), undefined)
|
|
22
|
+
* equal(key('Enter', {}, true), undefined)
|
|
23
|
+
* equal(key('Enter', { metaKey: true }, true), 'keep')
|
|
24
|
+
* equal(key('Escape', { isComposing: true }), undefined)
|
|
25
|
+
* equal(key('a'), undefined)
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @module
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/** What of a key press decides what it does to what is typed. */
|
|
32
|
+
export type Key =
|
|
33
|
+
& Pick<KeyboardEvent, 'key'>
|
|
34
|
+
& Partial<
|
|
35
|
+
Pick<
|
|
36
|
+
KeyboardEvent,
|
|
37
|
+
'isComposing' | 'defaultPrevented' | 'shiftKey' | 'ctrlKey' | 'metaKey'
|
|
38
|
+
>
|
|
39
|
+
>
|
|
40
|
+
|
|
41
|
+
// React's own event leaves out whether a composition is on: its browser's
|
|
42
|
+
// event says.
|
|
43
|
+
let composing = (ev: Key) =>
|
|
44
|
+
ev.isComposing || !!(ev as { nativeEvent?: Key }).nativeEvent?.isComposing
|
|
45
|
+
|
|
46
|
+
/** What a key does to what is typed: keeps it, or cancels it. */
|
|
47
|
+
export type Edit = 'keep' | 'cancel'
|
|
48
|
+
|
|
49
|
+
/** What `ev` does to what is typed in a line, or in a field of many lines
|
|
50
|
+
* (`multi`); undefined when it types, or is not this editor's. */
|
|
51
|
+
export let editKey = (ev: Key, multi = false): Edit | undefined => {
|
|
52
|
+
if (composing(ev) || ev.defaultPrevented) return
|
|
53
|
+
if (ev.key == 'Escape') return 'cancel'
|
|
54
|
+
if (ev.key != 'Enter' || ev.shiftKey) return
|
|
55
|
+
if (!multi || ev.ctrlKey || ev.metaKey) return 'keep'
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** What an editor does with what is typed in `field`. */
|
|
59
|
+
export type EditKeys = {
|
|
60
|
+
/** Enter: what is typed is kept. Without it, Enter types as it would. */
|
|
61
|
+
keep?: (field: HTMLElement) => void
|
|
62
|
+
/** Escape: what is typed is put back or dropped (default: the field is
|
|
63
|
+
* left, keeping what it holds) */
|
|
64
|
+
cancel?: (field: HTMLElement) => void
|
|
65
|
+
/** Enter types a new line; Ctrl or ⌘ with it keeps */
|
|
66
|
+
multi?: boolean
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** A field's keydown handler: Enter keeps and Escape cancels, each taking
|
|
70
|
+
* its key. Answers whether it took it, for a handler that reads other keys
|
|
71
|
+
* after it. */
|
|
72
|
+
export let editKeys = (o: EditKeys) => (ev: KeyboardEvent): boolean => {
|
|
73
|
+
let field = ev.currentTarget as HTMLElement
|
|
74
|
+
let edit = editKey(ev, o.multi)
|
|
75
|
+
if (!edit || edit == 'keep' && !o.keep) return false
|
|
76
|
+
ev.preventDefault()
|
|
77
|
+
if (edit == 'keep') o.keep!(field)
|
|
78
|
+
else if (o.cancel) o.cancel(field)
|
|
79
|
+
else field.blur()
|
|
80
|
+
return true
|
|
81
|
+
}
|
package/emit.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one way an `Edit` says anything: what was typed or picked, read as the
|
|
3
|
+
* property's type (@yaks/render `edit`, in the host's input language), is the
|
|
4
|
+
* bundle it was handed with that value changed, and goes to its caller's
|
|
5
|
+
* `onChange`, or the host's `write`. Input that cannot be read goes the same
|
|
6
|
+
* way as a `Refused` event, never thrown at the component.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/ import { edit } from "@yaks/render";
|
|
10
|
+
import { canEdit } from "./read.js";
|
|
11
|
+
import { changed, refused } from "./state.js";
|
|
12
|
+
let said = (e)=>e instanceof Error ? e.message : String(e);
|
|
13
|
+
/** `input` for `comp.prop` of `e`, as the bundle it becomes: read against the
|
|
14
|
+
* declaration where a client may write the property, and passed as it is to a
|
|
15
|
+
* caller that owns a derived one (a status its caller turns into marks). */ export let reading = (host, e, comp, prop, input)=>canEdit(host.vocab, comp, prop) ? {
|
|
16
|
+
entity: {
|
|
17
|
+
eid: e.entity.eid
|
|
18
|
+
},
|
|
19
|
+
...edit(host.vocab, {
|
|
20
|
+
comp,
|
|
21
|
+
prop
|
|
22
|
+
}, host.editing).run(e, input)
|
|
23
|
+
} : changed(e, comp, prop, input);
|
|
24
|
+
/** Emit `input` for `comp.prop` of `e`: the changed bundle, or the refusal. */ export let emit = (host, onChange, e, comp, prop, input)=>{
|
|
25
|
+
let send = onChange ?? host.write;
|
|
26
|
+
let b;
|
|
27
|
+
try {
|
|
28
|
+
b = reading(host, e, comp, prop, input);
|
|
29
|
+
} catch (err) {
|
|
30
|
+
return void send(refused(e, said(err)));
|
|
31
|
+
}
|
|
32
|
+
send(b);
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=emit.js.map
|
package/emit.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emit.js","sources":["./emit.ts"],"names":[],"mappings":"AAAA;;;;;;;;CAQC,GAED,SAAS,IAAI,4BAAiC;AAE9C,SAAS,OAAO,oBAAmB;AACnC,SAAS,OAAO,EAAE,OAAO,qBAAoB;AAK7C,IAAI,OAAO,CAAC,IAAe,aAAa,QAAQ,EAAE,OAAO,GAAG,OAAO;AAEnE;;0EAE0E,GAC1E,OAAO,IAAI,UAAU,CACnB,MACA,GACA,MACA,MACA,QAEA,QAAQ,KAAK,KAAK,EAAE,MAAM,QACtB;IACA,QAAQ;MAAE,KAAK,EAAE,MAAM,CAAC,GAAG;IAAC;IAC5B,GAAG,KAAK,KAAK,KAAK,EAAE;MAAE;MAAM;IAAK,GAAG,KAAK,OAAO,EAAE,GAAG,CAAC,GAAG,MAAM;EACjE,IACE,QAAQ,GAAG,MAAM,MAAM,OAAM;AAEnC,6EAA6E,GAC7E,OAAO,IAAI,OAAO,CAChB,MACA,UACA,GACA,MACA,MACA;EAEA,IAAI,OAAO,YAAY,KAAK,KAAK;EACjC,IAAI;EACJ,IAAI;IACF,IAAI,QAAQ,MAAM,GAAG,MAAM,MAAM;EACnC,EAAE,OAAO,KAAK;IACZ,OAAO,KAAK,KAAK,QAAQ,GAAG,KAAK;EACnC;EACA,KAAK;AACP,EAAC"}
|
package/emit.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one way an `Edit` says anything: what was typed or picked, read as the
|
|
3
|
+
* property's type (@yaks/render `edit`, in the host's input language), is the
|
|
4
|
+
* bundle it was handed with that value changed, and goes to its caller's
|
|
5
|
+
* `onChange`, or the host's `write`. Input that cannot be read goes the same
|
|
6
|
+
* way as a `Refused` event, never thrown at the component.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { edit } from '@yaks/render'
|
|
12
|
+
import type { Bundle, Host } from './host.ts'
|
|
13
|
+
import { canEdit } from './read.js'
|
|
14
|
+
import { changed, refused } from './state.js'
|
|
15
|
+
|
|
16
|
+
/** Where an `Edit` sends what it emits: its caller's, or else the host's. */
|
|
17
|
+
export type OnChange = (b: Bundle) => unknown
|
|
18
|
+
|
|
19
|
+
let said = (e: unknown) => e instanceof Error ? e.message : String(e)
|
|
20
|
+
|
|
21
|
+
/** `input` for `comp.prop` of `e`, as the bundle it becomes: read against the
|
|
22
|
+
* declaration where a client may write the property, and passed as it is to a
|
|
23
|
+
* caller that owns a derived one (a status its caller turns into marks). */
|
|
24
|
+
export let reading = (
|
|
25
|
+
host: Pick<Host, 'vocab' | 'editing'>,
|
|
26
|
+
e: Bundle,
|
|
27
|
+
comp: string,
|
|
28
|
+
prop: string,
|
|
29
|
+
input: unknown,
|
|
30
|
+
): Bundle =>
|
|
31
|
+
canEdit(host.vocab, comp, prop)
|
|
32
|
+
? {
|
|
33
|
+
entity: { eid: e.entity.eid },
|
|
34
|
+
...edit(host.vocab, { comp, prop }, host.editing).run(e, input),
|
|
35
|
+
}
|
|
36
|
+
: changed(e, comp, prop, input)
|
|
37
|
+
|
|
38
|
+
/** Emit `input` for `comp.prop` of `e`: the changed bundle, or the refusal. */
|
|
39
|
+
export let emit = (
|
|
40
|
+
host: Host,
|
|
41
|
+
onChange: OnChange | undefined,
|
|
42
|
+
e: Bundle,
|
|
43
|
+
comp: string,
|
|
44
|
+
prop: string,
|
|
45
|
+
input: unknown,
|
|
46
|
+
): void => {
|
|
47
|
+
let send = onChange ?? host.write
|
|
48
|
+
let b: Bundle
|
|
49
|
+
try {
|
|
50
|
+
b = reading(host, e, comp, prop, input)
|
|
51
|
+
} catch (err) {
|
|
52
|
+
return void send(refused(e, said(err)))
|
|
53
|
+
}
|
|
54
|
+
send(b)
|
|
55
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { slideIn } from "@yaks/ui/slide";
|
|
2
|
+
let OPEN = 'yak-entity-popup';
|
|
3
|
+
let STATE = 'entityPopup';
|
|
4
|
+
/** Open an entity detail through the popup already mounted by the page. */ export let openEntity = (doc, to)=>!doc.dispatchEvent(new (doc.defaultView ?? globalThis).CustomEvent(OPEN, {
|
|
5
|
+
detail: to,
|
|
6
|
+
cancelable: true
|
|
7
|
+
}));
|
|
8
|
+
/** Opens a server-rendered entity detail over the page that linked to it. */ export let entityPopups = (doc, read = fetch)=>{
|
|
9
|
+
let win = doc.defaultView;
|
|
10
|
+
let active;
|
|
11
|
+
let popup;
|
|
12
|
+
let closing = false;
|
|
13
|
+
let close = ()=>{
|
|
14
|
+
active?.abort();
|
|
15
|
+
if (!popup?.open) return;
|
|
16
|
+
closing = true;
|
|
17
|
+
popup.close();
|
|
18
|
+
};
|
|
19
|
+
let open = (to, push, slide = false)=>{
|
|
20
|
+
let dialog = doc.querySelector('#entity-popup');
|
|
21
|
+
if (!win || !dialog?.showModal || to.origin != win.location.origin) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
popup = dialog;
|
|
25
|
+
active?.abort();
|
|
26
|
+
let loading = active = new AbortController();
|
|
27
|
+
let title = dialog.querySelector('#entity-popup-title');
|
|
28
|
+
let content = dialog.querySelector('[data-entity-content]');
|
|
29
|
+
dialog.onclose = ()=>{
|
|
30
|
+
loading.abort();
|
|
31
|
+
if (!closing && win.history.state?.[STATE]) win.history.back();
|
|
32
|
+
closing = false;
|
|
33
|
+
};
|
|
34
|
+
dialog.onclick = (event)=>{
|
|
35
|
+
if (event.target.closest('[data-entity-close]')) {
|
|
36
|
+
dialog.close();
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
title.textContent = 'Details';
|
|
40
|
+
content.textContent = 'Loading…';
|
|
41
|
+
if (push && win.history.state?.[STATE] != to.href) {
|
|
42
|
+
let state = {
|
|
43
|
+
...win.history.state,
|
|
44
|
+
[STATE]: to.href
|
|
45
|
+
};
|
|
46
|
+
if (dialog.open) win.history.replaceState(state, '');
|
|
47
|
+
else win.history.pushState(state, '');
|
|
48
|
+
}
|
|
49
|
+
if (!dialog.open) dialog.showModal();
|
|
50
|
+
if (slide) slideIn(dialog.querySelector('.Modal_Body') ?? dialog);
|
|
51
|
+
let url = new URL(to);
|
|
52
|
+
url.searchParams.set('popup', '');
|
|
53
|
+
void read(url, {
|
|
54
|
+
signal: loading.signal
|
|
55
|
+
}).then(async (response)=>{
|
|
56
|
+
if (!response.ok) {
|
|
57
|
+
throw new Error(`Entity detail answered ${response.status}`);
|
|
58
|
+
}
|
|
59
|
+
let html = await response.text();
|
|
60
|
+
if (loading.signal.aborted) return;
|
|
61
|
+
let page = new win.DOMParser().parseFromString(html, 'text/html');
|
|
62
|
+
let detail = page.querySelector('[data-entity-detail]');
|
|
63
|
+
if (!detail) throw new Error('Entity detail is missing');
|
|
64
|
+
title.textContent = detail.getAttribute('data-entity-title') || 'Details';
|
|
65
|
+
content.replaceChildren(...detail.childNodes);
|
|
66
|
+
}).catch((error)=>{
|
|
67
|
+
if (loading.signal.aborted) return;
|
|
68
|
+
globalThis.reportError?.(error);
|
|
69
|
+
content.textContent = 'This item could not be opened.';
|
|
70
|
+
}).finally(()=>{
|
|
71
|
+
if (active == loading) active = undefined;
|
|
72
|
+
});
|
|
73
|
+
return true;
|
|
74
|
+
};
|
|
75
|
+
doc.addEventListener('yak-leave', close);
|
|
76
|
+
win?.addEventListener('popstate', ()=>{
|
|
77
|
+
let to = win.history.state?.[STATE];
|
|
78
|
+
if (to) open(new URL(to), false);
|
|
79
|
+
else close();
|
|
80
|
+
});
|
|
81
|
+
doc.addEventListener(OPEN, (event)=>{
|
|
82
|
+
if (open(event.detail, true, true)) {
|
|
83
|
+
event.preventDefault();
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
doc.addEventListener('click', (event)=>{
|
|
87
|
+
let link = event.target?.closest('a[data-entity-popup][href]');
|
|
88
|
+
if (!link || event.defaultPrevented || event.button != 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey || link.target || link.origin != doc.location.origin) return;
|
|
89
|
+
if (open(new URL(link.href), true)) event.preventDefault();
|
|
90
|
+
}, {
|
|
91
|
+
capture: true
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
//# sourceMappingURL=entity-popup-browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity-popup-browser.js","sources":["./entity-popup-browser.ts"],"names":[],"mappings":"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"}
|