@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
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/* @ts-types="npm:@types/react@19.3.0" */ import { createElement as h, useLayoutEffect, useRef, useState } from "react";
|
|
2
|
+
import { Composer, ErrorNotice } from "@yaks/ui/parts";
|
|
3
|
+
import { useDraft, useDrafts } from "./host.js";
|
|
4
|
+
import { sends } from "./composer.js";
|
|
5
|
+
/** The event Stop emits. */ export let stopped = (session = '')=>({
|
|
6
|
+
entity: {
|
|
7
|
+
eid: session
|
|
8
|
+
},
|
|
9
|
+
Stop: {}
|
|
10
|
+
});
|
|
11
|
+
// Whether an event carries files a person holds over the box.
|
|
12
|
+
let carries = (ev)=>!!ev.dataTransfer?.types.includes('Files');
|
|
13
|
+
// What the box hears of files, given `onFiles`: a paste of them (pasted
|
|
14
|
+
// words stay words) and a drop, anywhere on it, lit while they are held
|
|
15
|
+
// over it. A drop it takes is its own, so a page's listener for one let go
|
|
16
|
+
// beside it (`defaultPrevented`) leaves it be.
|
|
17
|
+
let useTaking = (onFiles)=>{
|
|
18
|
+
let [over, setOver] = useState(false);
|
|
19
|
+
let box = useRef(null);
|
|
20
|
+
useLayoutEffect(()=>{
|
|
21
|
+
let node = box.current;
|
|
22
|
+
if (!node || !onFiles) return;
|
|
23
|
+
let paste = (ev)=>{
|
|
24
|
+
let files = [
|
|
25
|
+
...ev.clipboardData?.files ?? []
|
|
26
|
+
];
|
|
27
|
+
if (!files.length) return;
|
|
28
|
+
ev.preventDefault();
|
|
29
|
+
onFiles(files);
|
|
30
|
+
};
|
|
31
|
+
node.addEventListener('paste', paste);
|
|
32
|
+
return ()=>node.removeEventListener('paste', paste);
|
|
33
|
+
}, [
|
|
34
|
+
onFiles
|
|
35
|
+
]);
|
|
36
|
+
if (!onFiles) return {};
|
|
37
|
+
let hover = (ev)=>{
|
|
38
|
+
if (!carries(ev)) return;
|
|
39
|
+
ev.preventDefault();
|
|
40
|
+
ev.dataTransfer.dropEffect = 'copy';
|
|
41
|
+
setOver(true);
|
|
42
|
+
};
|
|
43
|
+
return {
|
|
44
|
+
over,
|
|
45
|
+
elRef: box,
|
|
46
|
+
onDragEnter: hover,
|
|
47
|
+
onDragOver: hover,
|
|
48
|
+
onDragLeave: (ev)=>{
|
|
49
|
+
let to = ev.relatedTarget;
|
|
50
|
+
if (!ev.currentTarget.contains(to)) setOver(false);
|
|
51
|
+
},
|
|
52
|
+
onDrop: (ev)=>{
|
|
53
|
+
if (!carries(ev)) return;
|
|
54
|
+
ev.preventDefault();
|
|
55
|
+
setOver(false);
|
|
56
|
+
let files = [
|
|
57
|
+
...ev.dataTransfer.files
|
|
58
|
+
];
|
|
59
|
+
if (files.length) onFiles(files);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
/** The composer submits the form from either Enter or Send. */ export let Box = ({ place, drafts: supplied, session, words, onSend, onStop, busy, sending, said, error, onDismissError, name, placeholder = 'Write a message…', top, before, held, beside, children, onFiles, ...rest })=>{
|
|
64
|
+
let taking = useTaking(onFiles);
|
|
65
|
+
let drafts = useDrafts(supplied);
|
|
66
|
+
let text = useDraft(place, drafts);
|
|
67
|
+
let send = ()=>void (!sending && onSend(words(drafts.text(place))));
|
|
68
|
+
return /*#__PURE__*/ h(Composer.Form, {
|
|
69
|
+
...rest,
|
|
70
|
+
'aria-busy': sending ? 'true' : undefined,
|
|
71
|
+
onSubmit: (ev)=>{
|
|
72
|
+
ev.preventDefault();
|
|
73
|
+
send();
|
|
74
|
+
}
|
|
75
|
+
}, children, /*#__PURE__*/ h(ErrorNotice.Slot, {
|
|
76
|
+
mod: 'above'
|
|
77
|
+
}, /*#__PURE__*/ h(ErrorNotice, {
|
|
78
|
+
onDismiss: onDismissError
|
|
79
|
+
}, error)), /*#__PURE__*/ h(Composer, {
|
|
80
|
+
'data-busy': busy ? '' : undefined,
|
|
81
|
+
...taking
|
|
82
|
+
}, top, before, /*#__PURE__*/ h(Composer.Well, {}, /*#__PURE__*/ h(Composer.Bare, {
|
|
83
|
+
lines: true,
|
|
84
|
+
name,
|
|
85
|
+
value: text,
|
|
86
|
+
placeholder,
|
|
87
|
+
'aria-label': placeholder,
|
|
88
|
+
onInput: (ev)=>drafts.type(place, ev.currentTarget.value),
|
|
89
|
+
onKeyDown: (ev)=>{
|
|
90
|
+
if (!sends(ev)) return;
|
|
91
|
+
ev.preventDefault();
|
|
92
|
+
let form = ev.currentTarget.form;
|
|
93
|
+
if (form?.requestSubmit) form.requestSubmit();
|
|
94
|
+
else send();
|
|
95
|
+
}
|
|
96
|
+
}), held), /*#__PURE__*/ h(Composer.Tools, {}, /*#__PURE__*/ h(Composer.Stop, {
|
|
97
|
+
type: 'button',
|
|
98
|
+
onClick: ()=>onStop(stopped(session))
|
|
99
|
+
}, 'Stop'), beside, /*#__PURE__*/ h(Composer.Send, {
|
|
100
|
+
type: 'submit',
|
|
101
|
+
disabled: sending
|
|
102
|
+
}, 'Send'))), /*#__PURE__*/ h(Composer.Status, {
|
|
103
|
+
role: 'status'
|
|
104
|
+
}, said));
|
|
105
|
+
};
|
|
106
|
+
//# sourceMappingURL=ConversationBox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConversationBox.js","sources":["./ConversationBox.ts"],"names":[],"mappings":"AAAA,uCAAuC,GAAG,SACxC,iBAAiB,CAAC,EAGlB,eAAe,EACf,MAAM,EACN,QAAQ,gBACe;AAEzB,SAAS,QAAQ,EAAE,WAAW,8BAAmC;AACjE,SAAsB,QAAQ,EAAE,SAAS,oBAAmB;AAC5D,SAAS,KAAK,wBAAuB;AA6CrC,0BAA0B,GAC1B,OAAO,IAAI,UAAU,CAAC,UAAU,EAAE,GAAa,CAAC;IAC9C,QAAQ;MAAE,K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AE,SAAS,MAAM,EAAE;IAAE,MAAM;EAAS,GAAG;AAE3C,EAAC"}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/* @ts-types="npm:@types/react@19.3.0" */ import {
|
|
2
|
+
createElement as h,
|
|
3
|
+
type JSX,
|
|
4
|
+
type ReactNode,
|
|
5
|
+
useLayoutEffect,
|
|
6
|
+
useRef,
|
|
7
|
+
useState,
|
|
8
|
+
} from 'react'
|
|
9
|
+
import type { Bundle } from 'jsr:@yaks/graph@0.2.36'
|
|
10
|
+
import { Composer, ErrorNotice } from '@yaks/ui/parts'
|
|
11
|
+
import { type Drafts, useDraft, useDrafts } from './host.js'
|
|
12
|
+
import { sends } from './composer.js'
|
|
13
|
+
|
|
14
|
+
/** What a box's owner gives it. Any other prop goes on its form, which
|
|
15
|
+
* posts as it is where no script runs. */
|
|
16
|
+
export type BoxProps = {
|
|
17
|
+
/** where its words are typed, as a draft */
|
|
18
|
+
place: string
|
|
19
|
+
/** the drafts they are kept in; the host's without them */
|
|
20
|
+
drafts?: Drafts
|
|
21
|
+
/** the conversation they go to, which a stop is said on */
|
|
22
|
+
session?: string
|
|
23
|
+
/** the bundle the words become */
|
|
24
|
+
words: (text: string) => Bundle
|
|
25
|
+
/** the words, sent; the draft stays until its owner spends it */
|
|
26
|
+
onSend: (b: Bundle) => void
|
|
27
|
+
/** Stop, pressed: `{entity: {eid: session}, Stop: {}}` */
|
|
28
|
+
onStop: (b: Bundle) => void
|
|
29
|
+
/** the conversation is at work, so Stop shows */
|
|
30
|
+
busy?: boolean
|
|
31
|
+
/** a send is under way, so Send waits */
|
|
32
|
+
sending?: boolean
|
|
33
|
+
/** what it says under itself */
|
|
34
|
+
said?: ReactNode
|
|
35
|
+
/** a failure beside the composer controls */
|
|
36
|
+
error?: string
|
|
37
|
+
onDismissError?: () => void
|
|
38
|
+
/** the field's name, the words in a form posted without script */
|
|
39
|
+
name?: string
|
|
40
|
+
placeholder?: string
|
|
41
|
+
/** its owner's, over the field: who the words go to */
|
|
42
|
+
top?: ReactNode
|
|
43
|
+
/** its owner's, before the field: the press that adds files */
|
|
44
|
+
before?: ReactNode
|
|
45
|
+
/** its owner's, inside the field's edge along its bottom: files held */
|
|
46
|
+
held?: ReactNode
|
|
47
|
+
/** its owner's, beside Send */
|
|
48
|
+
beside?: ReactNode
|
|
49
|
+
/** its owner's, in the form before the box */
|
|
50
|
+
children?: ReactNode
|
|
51
|
+
/** files pasted or dropped on it, which its owner holds; without it, it
|
|
52
|
+
* takes none */
|
|
53
|
+
onFiles?: (files: File[]) => void
|
|
54
|
+
[attribute: string]: unknown
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** The event Stop emits. */
|
|
58
|
+
export let stopped = (session = ''): Bundle => ({
|
|
59
|
+
entity: { eid: session },
|
|
60
|
+
Stop: {},
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
// Whether an event carries files a person holds over the box.
|
|
64
|
+
let carries = (ev: DragEvent) => !!ev.dataTransfer?.types.includes('Files')
|
|
65
|
+
|
|
66
|
+
// What the box hears of files, given `onFiles`: a paste of them (pasted
|
|
67
|
+
// words stay words) and a drop, anywhere on it, lit while they are held
|
|
68
|
+
// over it. A drop it takes is its own, so a page's listener for one let go
|
|
69
|
+
// beside it (`defaultPrevented`) leaves it be.
|
|
70
|
+
let useTaking = (onFiles?: (files: File[]) => void) => {
|
|
71
|
+
let [over, setOver] = useState(false)
|
|
72
|
+
let box = useRef<HTMLElement>(null)
|
|
73
|
+
useLayoutEffect(() => {
|
|
74
|
+
let node = box.current
|
|
75
|
+
if (!node || !onFiles) return
|
|
76
|
+
let paste = (ev: ClipboardEvent) => {
|
|
77
|
+
let files = [...ev.clipboardData?.files ?? []]
|
|
78
|
+
if (!files.length) return
|
|
79
|
+
ev.preventDefault()
|
|
80
|
+
onFiles(files)
|
|
81
|
+
}
|
|
82
|
+
node.addEventListener('paste', paste)
|
|
83
|
+
return () => node.removeEventListener('paste', paste)
|
|
84
|
+
}, [onFiles])
|
|
85
|
+
if (!onFiles) return {}
|
|
86
|
+
let hover = (ev: DragEvent) => {
|
|
87
|
+
if (!carries(ev)) return
|
|
88
|
+
ev.preventDefault()
|
|
89
|
+
ev.dataTransfer!.dropEffect = 'copy'
|
|
90
|
+
setOver(true)
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
over,
|
|
94
|
+
elRef: box,
|
|
95
|
+
onDragEnter: hover,
|
|
96
|
+
onDragOver: hover,
|
|
97
|
+
onDragLeave: (ev: DragEvent) => {
|
|
98
|
+
let to = ev.relatedTarget as Node | null
|
|
99
|
+
if (!(ev.currentTarget as Element).contains(to)) setOver(false)
|
|
100
|
+
},
|
|
101
|
+
onDrop: (ev: DragEvent) => {
|
|
102
|
+
if (!carries(ev)) return
|
|
103
|
+
ev.preventDefault()
|
|
104
|
+
setOver(false)
|
|
105
|
+
let files = [...ev.dataTransfer!.files]
|
|
106
|
+
if (files.length) onFiles(files)
|
|
107
|
+
},
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** The composer submits the form from either Enter or Send. */
|
|
112
|
+
export let Box = (
|
|
113
|
+
{
|
|
114
|
+
place,
|
|
115
|
+
drafts: supplied,
|
|
116
|
+
session,
|
|
117
|
+
words,
|
|
118
|
+
onSend,
|
|
119
|
+
onStop,
|
|
120
|
+
busy,
|
|
121
|
+
sending,
|
|
122
|
+
said,
|
|
123
|
+
error,
|
|
124
|
+
onDismissError,
|
|
125
|
+
name,
|
|
126
|
+
placeholder = 'Write a message…',
|
|
127
|
+
top,
|
|
128
|
+
before,
|
|
129
|
+
held,
|
|
130
|
+
beside,
|
|
131
|
+
children,
|
|
132
|
+
onFiles,
|
|
133
|
+
...rest
|
|
134
|
+
}: BoxProps,
|
|
135
|
+
): JSX.Element => {
|
|
136
|
+
let taking = useTaking(onFiles)
|
|
137
|
+
let drafts = useDrafts(supplied)
|
|
138
|
+
let text = useDraft(place, drafts)
|
|
139
|
+
let send = () => void (!sending && onSend(words(drafts.text(place))))
|
|
140
|
+
return h(
|
|
141
|
+
Composer.Form,
|
|
142
|
+
{
|
|
143
|
+
...rest,
|
|
144
|
+
'aria-busy': sending ? 'true' : undefined,
|
|
145
|
+
onSubmit: (ev: Event) => {
|
|
146
|
+
ev.preventDefault()
|
|
147
|
+
send()
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
children,
|
|
151
|
+
h(
|
|
152
|
+
ErrorNotice.Slot,
|
|
153
|
+
{ mod: 'above' },
|
|
154
|
+
h(ErrorNotice, {
|
|
155
|
+
onDismiss: onDismissError,
|
|
156
|
+
}, error),
|
|
157
|
+
),
|
|
158
|
+
h(
|
|
159
|
+
Composer,
|
|
160
|
+
{ 'data-busy': busy ? '' : undefined, ...taking },
|
|
161
|
+
top,
|
|
162
|
+
before,
|
|
163
|
+
h(
|
|
164
|
+
Composer.Well,
|
|
165
|
+
{},
|
|
166
|
+
h(Composer.Bare, {
|
|
167
|
+
lines: true,
|
|
168
|
+
name,
|
|
169
|
+
value: text,
|
|
170
|
+
placeholder,
|
|
171
|
+
'aria-label': placeholder,
|
|
172
|
+
onInput: (ev: Event) =>
|
|
173
|
+
drafts.type(place, (ev.currentTarget as HTMLTextAreaElement).value),
|
|
174
|
+
onKeyDown: (ev: KeyboardEvent) => {
|
|
175
|
+
if (!sends(ev)) return
|
|
176
|
+
ev.preventDefault()
|
|
177
|
+
let form = (ev.currentTarget as HTMLTextAreaElement).form
|
|
178
|
+
if (form?.requestSubmit) form.requestSubmit()
|
|
179
|
+
else send()
|
|
180
|
+
},
|
|
181
|
+
}),
|
|
182
|
+
held,
|
|
183
|
+
),
|
|
184
|
+
h(
|
|
185
|
+
Composer.Tools,
|
|
186
|
+
{},
|
|
187
|
+
h(
|
|
188
|
+
Composer.Stop,
|
|
189
|
+
{ type: 'button', onClick: () => onStop(stopped(session)) },
|
|
190
|
+
'Stop',
|
|
191
|
+
),
|
|
192
|
+
beside,
|
|
193
|
+
h(Composer.Send, { type: 'submit', disabled: sending }, 'Send'),
|
|
194
|
+
),
|
|
195
|
+
),
|
|
196
|
+
h(Composer.Status, { role: 'status' }, said),
|
|
197
|
+
)
|
|
198
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/* @ts-types="npm:@types/react@19.3.0" */ import { createElement as h } from "react";
|
|
2
|
+
import { Transcript } from "@yaks/ui/parts";
|
|
3
|
+
import { relative } from "@yaks/ui/relative";
|
|
4
|
+
import { useNow } from "@yaks/ui/Time";
|
|
5
|
+
/** Draw a divider at the start of each run with the same displayed age. */ export let datedRows = (lines, row, now, after)=>{
|
|
6
|
+
let previous = relative(after, now);
|
|
7
|
+
return lines.map((line)=>{
|
|
8
|
+
let age = relative(line.at, now);
|
|
9
|
+
let divider = age && age != previous ? /*#__PURE__*/ h(Transcript.Divider, {}, /*#__PURE__*/ h(Transcript.When, {
|
|
10
|
+
at: line.at,
|
|
11
|
+
now
|
|
12
|
+
})) : undefined;
|
|
13
|
+
if (age) previous = age;
|
|
14
|
+
return row(line, divider);
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
/** A nested transcript uses the same clock and dividers as the conversation. */ export let DatedRows = ({ lines, row, after })=>datedRows(lines, row, useNow(), after);
|
|
18
|
+
/** Adjacent activity can share one fold, with other lines as boundaries. */ export let activityRuns = (lines, activity)=>{
|
|
19
|
+
let runs = [];
|
|
20
|
+
for (let line of lines){
|
|
21
|
+
let last = runs.at(-1);
|
|
22
|
+
if (last && activity(last[0]) && activity(line)) last.push(line);
|
|
23
|
+
else runs.push([
|
|
24
|
+
line
|
|
25
|
+
]);
|
|
26
|
+
}
|
|
27
|
+
return runs;
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=ConversationLines.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConversationLines.js","sources":["./ConversationLines.ts"],"names":[],"mappings":"AAAA,uCAAuC,GAAG,SAAS,iBAAiB,CAAC,gBAA0C;AAC/G,SAAS,UAAU,8BAAmC;AACtD,SAAS,QAAQ,iCAAsC;AACvD,SAAS,MAAM,6BAAkC;AASjD,yEAAyE,GACzE,OAAO,IAAI,YAAY,CACrB,OACA,KACA,KACA;EAEA,IAAI,WAAW,SAAS,OAAO;EAC/B,OAAO,MAAM,GAAG,CAAC,CAAC;IAChB,IAAI,MAAM,SAAS,KAAK,EAAE,EAAE;IAC5B,IAAI,UAAU,OAAO,OAAO,yBACxB,EAAE,WAAW,OAAO,EAAE,CAAC,iBAAG,EAAE,WAAW,IAAI,EAAE;MAAE,IAAI,KAAK,EAAE;MAAE;IAAI,MAChE;IACJ,IAAI,KAAK,WAAW;IACpB,OAAO,IAAI,MAAM;EACnB;AACF,EAAC;AAED,8EAA8E,GAC9E,OAAO,IAAI,YAAY,CACrB,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAoD,GACvD,UAAU,OAAO,KAAK,UAAU,OAAM;AAExD,0EAA0E,GAC1E,OAAO,IAAI,eAAe,CACxB,OACA;EAEA,IAAI,OAAc,EAAE;EACpB,KAAK,IAAI,QAAQ,MAAO;IACtB,IAAI,OAAO,KAAK,EAAE,CAAC,CAAC;IACpB,IAAI,QAAQ,SAAS,IAAI,CAAC,EAAE,KAAK,SAAS,OAAO,KAAK,IAAI,CAAC;SACtD,KAAK,IAAI,CAAC;MAAC;KAAK;EACvB;EACA,OAAO;AACT,EAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/* @ts-types="npm:@types/react@19.3.0" */ import { createElement as h, type ReactNode } from 'react'
|
|
2
|
+
import { Transcript } from '@yaks/ui/parts'
|
|
3
|
+
import { relative } from '@yaks/ui/relative'
|
|
4
|
+
import { useNow } from '@yaks/ui/Time'
|
|
5
|
+
|
|
6
|
+
/** The moment an item entered a conversation. */
|
|
7
|
+
export type Timed = { at?: string }
|
|
8
|
+
export type DatedRow<L extends Timed> = (
|
|
9
|
+
line: L,
|
|
10
|
+
divider?: ReactNode,
|
|
11
|
+
) => ReactNode
|
|
12
|
+
|
|
13
|
+
/** Draw a divider at the start of each run with the same displayed age. */
|
|
14
|
+
export let datedRows = <L extends Timed>(
|
|
15
|
+
lines: L[],
|
|
16
|
+
row: DatedRow<L>,
|
|
17
|
+
now: number,
|
|
18
|
+
after?: string,
|
|
19
|
+
): ReactNode[] => {
|
|
20
|
+
let previous = relative(after, now)
|
|
21
|
+
return lines.map((line) => {
|
|
22
|
+
let age = relative(line.at, now)
|
|
23
|
+
let divider = age && age != previous
|
|
24
|
+
? h(Transcript.Divider, {}, h(Transcript.When, { at: line.at, now }))
|
|
25
|
+
: undefined
|
|
26
|
+
if (age) previous = age
|
|
27
|
+
return row(line, divider)
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** A nested transcript uses the same clock and dividers as the conversation. */
|
|
32
|
+
export let DatedRows = <L extends Timed>(
|
|
33
|
+
{ lines, row, after }: { lines: L[]; row: DatedRow<L>; after?: string },
|
|
34
|
+
): ReactNode[] => datedRows(lines, row, useNow(), after)
|
|
35
|
+
|
|
36
|
+
/** Adjacent activity can share one fold, with other lines as boundaries. */
|
|
37
|
+
export let activityRuns = <L>(
|
|
38
|
+
lines: L[],
|
|
39
|
+
activity: (line: L) => boolean,
|
|
40
|
+
): L[][] => {
|
|
41
|
+
let runs: L[][] = []
|
|
42
|
+
for (let line of lines) {
|
|
43
|
+
let last = runs.at(-1)
|
|
44
|
+
if (last && activity(last[0]) && activity(line)) last.push(line)
|
|
45
|
+
else runs.push([line])
|
|
46
|
+
}
|
|
47
|
+
return runs
|
|
48
|
+
}
|
package/Disclosure.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/** A controlled disclosure is the kit's fold, `More`: a `details` whose
|
|
2
|
+
* summary opens what it holds. The consumer names its page entity and keeps
|
|
3
|
+
* emitted Disclosure{open} bundles, so the same state is found across
|
|
4
|
+
* remounts, and `DisclosureMark` is a second way to open it.
|
|
5
|
+
* @module
|
|
6
|
+
*/ /* @ts-types="npm:@types/react@19.3.0" */ import { createElement as h } from "react";
|
|
7
|
+
import { derivedEid } from "@yaks/graph/identity";
|
|
8
|
+
import { Loading as Pending, More, State } from "@yaks/ui/parts";
|
|
9
|
+
/** The page entity carrying this owner's disclosure state. */ export let disclosureAt = (owner)=>derivedEid([
|
|
10
|
+
'Disclosure',
|
|
11
|
+
owner
|
|
12
|
+
].join('|'));
|
|
13
|
+
/** Missing disclosure state is closed. */ export let isOpen = (e)=>e?.Disclosure?.open === true;
|
|
14
|
+
/** The bundle emitted when this disclosure is opened or closed. */ export let disclosed = (e, open)=>({
|
|
15
|
+
entity: {
|
|
16
|
+
eid: e.entity.eid
|
|
17
|
+
},
|
|
18
|
+
Disclosure: {
|
|
19
|
+
open
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
// The id of what a disclosure holds, which its summary and marks control.
|
|
23
|
+
let bodyOf = (e)=>`disclosure-${e.entity.eid}`;
|
|
24
|
+
// Pressing its summary or a mark emits the other state; the page draws it
|
|
25
|
+
// open or closed from what its owner supplies again.
|
|
26
|
+
let pressed = ({ e, onChange })=>e && onChange ? (ev)=>{
|
|
27
|
+
ev.preventDefault();
|
|
28
|
+
onChange(disclosed(e, !isOpen(e)));
|
|
29
|
+
} : undefined;
|
|
30
|
+
/** The mark on what a lazy disclosure holds until it is opened and drawn. */ export let UNFETCHED = 'data-unfetched';
|
|
31
|
+
/** What a lazy disclosure holds until it is opened and drawn. */ export let Loading = ()=>/*#__PURE__*/ h(Pending, {
|
|
32
|
+
state: 'fold',
|
|
33
|
+
[UNFETCHED]: ''
|
|
34
|
+
}, /*#__PURE__*/ h(State, {
|
|
35
|
+
mod: [
|
|
36
|
+
'pulse',
|
|
37
|
+
'active'
|
|
38
|
+
]
|
|
39
|
+
}, 'Loading…'));
|
|
40
|
+
/** Open as its state says; what it holds is drawn whether open or not, so a
|
|
41
|
+
* page drawn on a server opens it with no script, unless it is `lazy`. */ export let Disclosure = ({ e, onChange, summary, summaryProps, mod, className, class: named, lazy, children })=>{
|
|
42
|
+
let open = isOpen(e);
|
|
43
|
+
return /*#__PURE__*/ h(More, {
|
|
44
|
+
mod,
|
|
45
|
+
className,
|
|
46
|
+
class: named,
|
|
47
|
+
open,
|
|
48
|
+
...e ? {
|
|
49
|
+
'data-disclosure': e.entity.eid
|
|
50
|
+
} : {},
|
|
51
|
+
// what a page holding the server's drawing asks for before it opens
|
|
52
|
+
...lazy ? {
|
|
53
|
+
'data-lazy': ''
|
|
54
|
+
} : {}
|
|
55
|
+
}, /*#__PURE__*/ h(More.Summary, {
|
|
56
|
+
...summaryProps,
|
|
57
|
+
onClick: pressed({
|
|
58
|
+
e,
|
|
59
|
+
onChange
|
|
60
|
+
})
|
|
61
|
+
}, summary), /*#__PURE__*/ h(More.Body, e ? {
|
|
62
|
+
id: bodyOf(e)
|
|
63
|
+
} : {}, lazy && !open ? /*#__PURE__*/ h(Loading, null) : children));
|
|
64
|
+
};
|
|
65
|
+
/** A second way to open a disclosure, drawn outside it: a button over the
|
|
66
|
+
* same state, its own words in `children`. */ export let DisclosureMark = ({ e, onChange, children, ...props })=>/*#__PURE__*/ h(More.Mark, {
|
|
67
|
+
...props,
|
|
68
|
+
type: 'button',
|
|
69
|
+
'aria-expanded': String(isOpen(e)),
|
|
70
|
+
...e ? {
|
|
71
|
+
'aria-controls': bodyOf(e),
|
|
72
|
+
'data-disclosure-mark': e.entity.eid
|
|
73
|
+
} : {},
|
|
74
|
+
onClick: pressed({
|
|
75
|
+
e,
|
|
76
|
+
onChange
|
|
77
|
+
})
|
|
78
|
+
}, children);
|
|
79
|
+
//# sourceMappingURL=Disclosure.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Disclosure.js","sources":["./Disclosure.ts"],"names":[],"mappings":"AAAA;;;;;CAKC,GAED,uCAAuC,GAAG,SAAS,iBAAiB,CAAC,gBAAoD;AAEzH,SAAS,UAAU,oCAAyC;AAC5D,SAAS,WAAW,OAAO,EAAE,IAAI,EAAE,KAA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A,EACE,KAAK,OAAO,EACZ;IAAE,GAAG,YAAY;IAAE,SAAS,QAAQ;MAAE;MAAG;IAAS;EAAG,GACrD,wBAEF,EACE,KAAK,IAAI,EACT,IAAI;IAAE,IAAI,OAAO;EAAG,IAAI,CAAC,GACzB,QAAQ,CAAC,qBAAO,EAAE,SAAS,QAAQ;AAGzC,EAAC;AAED;4CAC4C,GAC5C,OAAO,IAAI,iBAAiB,CAC1B,EAAE,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,OAG3B,iBAED,EAAE,KAAK,IAAI,EAAE;IACX,GAAG,KAAK;IACR,MAAM;IACN,iBAAiB,OAAO,OAAO;IAC/B,GAAG,IACC;MAAE,iBAAiB,OAAO;MAAI,wBAAwB,EAAE,MAAM,CAAC,GAAG;IAAC,IACnE,CAAC,CAAC;IACN,SAAS,QAAQ;MAAE;MAAG;IAAS;EACjC,GAAG,UAAS"}
|
package/Disclosure.ts
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/** A controlled disclosure is the kit's fold, `More`: a `details` whose
|
|
2
|
+
* summary opens what it holds. The consumer names its page entity and keeps
|
|
3
|
+
* emitted Disclosure{open} bundles, so the same state is found across
|
|
4
|
+
* remounts, and `DisclosureMark` is a second way to open it.
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/* @ts-types="npm:@types/react@19.3.0" */ import { createElement as h, type JSX, type ReactNode } from 'react'
|
|
9
|
+
import type { Bundle } from 'jsr:@yaks/graph@0.2.36'
|
|
10
|
+
import { derivedEid } from '@yaks/graph/identity'
|
|
11
|
+
import { Loading as Pending, More, State } from '@yaks/ui/parts'
|
|
12
|
+
|
|
13
|
+
/** The page entity carrying this owner's disclosure state. */
|
|
14
|
+
export let disclosureAt = (owner: string): string =>
|
|
15
|
+
derivedEid(['Disclosure', owner].join('|'))
|
|
16
|
+
|
|
17
|
+
/** Missing disclosure state is closed. */
|
|
18
|
+
export let isOpen = (e?: Bundle): boolean =>
|
|
19
|
+
(e?.Disclosure as { open?: boolean } | undefined)?.open === true
|
|
20
|
+
|
|
21
|
+
/** The bundle emitted when this disclosure is opened or closed. */
|
|
22
|
+
export let disclosed = (e: Bundle, open: boolean): Bundle => ({
|
|
23
|
+
entity: { eid: e.entity.eid },
|
|
24
|
+
Disclosure: { open },
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
/** Where a disclosure's state is, and where what it emits goes. Without a
|
|
28
|
+
* page entity (`e`) it is a plain `details`, which its host opens itself. */
|
|
29
|
+
export type Disclosed = {
|
|
30
|
+
e?: Bundle
|
|
31
|
+
onChange?: (b: Bundle) => void
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** State and presentation supplied by the disclosure's consumer. */
|
|
35
|
+
export type DisclosureProps = Disclosed & {
|
|
36
|
+
summary: ReactNode
|
|
37
|
+
/** its summary's own attributes: a `class`, a `data-` name to find it by */
|
|
38
|
+
summaryProps?: Record<string, unknown>
|
|
39
|
+
/** the fold's look: `quiet` for a step, `on` running, `no` failed */
|
|
40
|
+
mod?: string | (string | false | null | undefined)[]
|
|
41
|
+
className?: string
|
|
42
|
+
class?: string
|
|
43
|
+
/** what it holds is drawn only while open, for content that asks for
|
|
44
|
+
* rows; closed, it holds only `Loading…`, which a page that holds the
|
|
45
|
+
* server's drawing shows as it opens until what it fetches replaces it */
|
|
46
|
+
lazy?: boolean
|
|
47
|
+
children?: ReactNode
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// The id of what a disclosure holds, which its summary and marks control.
|
|
51
|
+
let bodyOf = (e: Bundle) => `disclosure-${e.entity.eid}`
|
|
52
|
+
|
|
53
|
+
// Pressing its summary or a mark emits the other state; the page draws it
|
|
54
|
+
// open or closed from what its owner supplies again.
|
|
55
|
+
let pressed = ({ e, onChange }: Disclosed) =>
|
|
56
|
+
e && onChange
|
|
57
|
+
? (ev: Event) => {
|
|
58
|
+
ev.preventDefault()
|
|
59
|
+
onChange(disclosed(e, !isOpen(e)))
|
|
60
|
+
}
|
|
61
|
+
: undefined
|
|
62
|
+
|
|
63
|
+
/** The mark on what a lazy disclosure holds until it is opened and drawn. */
|
|
64
|
+
export let UNFETCHED = 'data-unfetched'
|
|
65
|
+
|
|
66
|
+
/** What a lazy disclosure holds until it is opened and drawn. */
|
|
67
|
+
export let Loading = (): JSX.Element =>
|
|
68
|
+
h(
|
|
69
|
+
Pending,
|
|
70
|
+
{ state: 'fold', [UNFETCHED]: '' },
|
|
71
|
+
h(State, { mod: ['pulse', 'active'] }, 'Loading…'),
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
/** Open as its state says; what it holds is drawn whether open or not, so a
|
|
75
|
+
* page drawn on a server opens it with no script, unless it is `lazy`. */
|
|
76
|
+
export let Disclosure = (
|
|
77
|
+
{
|
|
78
|
+
e,
|
|
79
|
+
onChange,
|
|
80
|
+
summary,
|
|
81
|
+
summaryProps,
|
|
82
|
+
mod,
|
|
83
|
+
className,
|
|
84
|
+
class: named,
|
|
85
|
+
lazy,
|
|
86
|
+
children,
|
|
87
|
+
}: DisclosureProps,
|
|
88
|
+
): JSX.Element => {
|
|
89
|
+
let open = isOpen(e)
|
|
90
|
+
return h(
|
|
91
|
+
More,
|
|
92
|
+
{
|
|
93
|
+
mod,
|
|
94
|
+
className,
|
|
95
|
+
class: named,
|
|
96
|
+
open,
|
|
97
|
+
...e ? { 'data-disclosure': e.entity.eid } : {},
|
|
98
|
+
// what a page holding the server's drawing asks for before it opens
|
|
99
|
+
...lazy ? { 'data-lazy': '' } : {},
|
|
100
|
+
},
|
|
101
|
+
h(
|
|
102
|
+
More.Summary,
|
|
103
|
+
{ ...summaryProps, onClick: pressed({ e, onChange }) },
|
|
104
|
+
summary,
|
|
105
|
+
),
|
|
106
|
+
h(
|
|
107
|
+
More.Body,
|
|
108
|
+
e ? { id: bodyOf(e) } : {},
|
|
109
|
+
lazy && !open ? h(Loading, null) : children,
|
|
110
|
+
),
|
|
111
|
+
)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** A second way to open a disclosure, drawn outside it: a button over the
|
|
115
|
+
* same state, its own words in `children`. */
|
|
116
|
+
export let DisclosureMark = (
|
|
117
|
+
{ e, onChange, children, ...props }: Disclosed & {
|
|
118
|
+
children?: ReactNode
|
|
119
|
+
[attribute: string]: unknown
|
|
120
|
+
},
|
|
121
|
+
): JSX.Element =>
|
|
122
|
+
h(More.Mark, {
|
|
123
|
+
...props,
|
|
124
|
+
type: 'button',
|
|
125
|
+
'aria-expanded': String(isOpen(e)),
|
|
126
|
+
...e
|
|
127
|
+
? { 'aria-controls': bodyOf(e), 'data-disclosure-mark': e.entity.eid }
|
|
128
|
+
: {},
|
|
129
|
+
onClick: pressed({ e, onChange }),
|
|
130
|
+
}, children)
|