@yaks/inbox 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 (88) hide show
  1. package/LICENSE +202 -0
  2. package/Person.tsx +275 -0
  3. package/Project.tsx +83 -0
  4. package/README.md +311 -2
  5. package/_dist/actions-browser.d.ts +8 -0
  6. package/_dist/actions-browser.d.ts.map +1 -0
  7. package/_dist/actions.d.ts +22 -0
  8. package/_dist/actions.d.ts.map +1 -0
  9. package/_dist/asks.d.ts +15 -0
  10. package/_dist/asks.d.ts.map +1 -0
  11. package/_dist/graph.d.ts +12 -0
  12. package/_dist/graph.d.ts.map +1 -0
  13. package/_dist/letters.d.ts +24 -0
  14. package/_dist/letters.d.ts.map +1 -0
  15. package/_dist/mail.d.ts +4 -0
  16. package/_dist/mail.d.ts.map +1 -0
  17. package/_dist/mod.d.ts +7 -0
  18. package/_dist/mod.d.ts.map +1 -0
  19. package/_dist/options.d.ts +18 -0
  20. package/_dist/options.d.ts.map +1 -0
  21. package/_dist/queries.d.ts +23 -0
  22. package/_dist/queries.d.ts.map +1 -0
  23. package/_dist/read.d.ts +18 -0
  24. package/_dist/read.d.ts.map +1 -0
  25. package/_dist/reader.d.ts +25 -0
  26. package/_dist/reader.d.ts.map +1 -0
  27. package/_dist/service.d.ts +8 -0
  28. package/_dist/service.d.ts.map +1 -0
  29. package/_dist/threads.d.ts +33 -0
  30. package/_dist/threads.d.ts.map +1 -0
  31. package/_dist/tools.d.ts +12 -0
  32. package/_dist/tools.d.ts.map +1 -0
  33. package/_dist/vocab.d.ts +5 -0
  34. package/_dist/vocab.d.ts.map +1 -0
  35. package/actions-browser.js +165 -0
  36. package/actions-browser.js.map +1 -0
  37. package/actions-browser.ts +158 -0
  38. package/actions.js +34 -0
  39. package/actions.js.map +1 -0
  40. package/actions.ts +53 -0
  41. package/asks.js +76 -0
  42. package/asks.js.map +1 -0
  43. package/asks.ts +94 -0
  44. package/deno.json +1 -0
  45. package/front.js +41 -0
  46. package/front.js.map +1 -0
  47. package/front.json +68 -0
  48. package/front.ts +38 -0
  49. package/graph.js +176 -0
  50. package/graph.js.map +1 -0
  51. package/graph.ts +182 -0
  52. package/inspect.tsx +22 -0
  53. package/letters.js +233 -0
  54. package/letters.js.map +1 -0
  55. package/letters.ts +325 -0
  56. package/mail.js +122 -0
  57. package/mail.js.map +1 -0
  58. package/mail.ts +148 -0
  59. package/mod.js +11 -0
  60. package/mod.js.map +1 -0
  61. package/mod.ts +24 -0
  62. package/options.js +15 -0
  63. package/options.js.map +1 -0
  64. package/options.ts +42 -0
  65. package/package.json +76 -4
  66. package/queries.js +240 -0
  67. package/queries.js.map +1 -0
  68. package/queries.ts +302 -0
  69. package/read.js +453 -0
  70. package/read.js.map +1 -0
  71. package/read.ts +476 -0
  72. package/reader.js +105 -0
  73. package/reader.js.map +1 -0
  74. package/reader.ts +147 -0
  75. package/service.js +29 -0
  76. package/service.js.map +1 -0
  77. package/service.ts +45 -0
  78. package/threads.js +182 -0
  79. package/threads.js.map +1 -0
  80. package/threads.ts +276 -0
  81. package/tools.js +101 -0
  82. package/tools.js.map +1 -0
  83. package/tools.ts +103 -0
  84. package/views.tsx +30 -0
  85. package/vocab.js +12 -0
  86. package/vocab.js.map +1 -0
  87. package/vocab.json +242 -0
  88. package/vocab.ts +11 -0
@@ -0,0 +1,165 @@
1
+ import { actionLabel, answerField, sayKinds } from "./actions.js";
2
+ import front from './front.json' with {
3
+ type: 'json'
4
+ };
5
+ /** The words a page graph speaks to take an inbox's card actions. */ export let actionWords = [
6
+ front
7
+ ];
8
+ let FORM = 'form[data-inbox-action]';
9
+ let CARD = '[data-inbox-card]';
10
+ /** Said, bubbling, by a view that drew its cards again in place: each card
11
+ * keeps its `data-inbox-card`, and the actions paint what they hold on it
12
+ * again. */ export let REDRAWN = 'inbox:redrawn';
13
+ let paint = (card, page, eid)=>{
14
+ let row = page.ent(eid);
15
+ let action = row?.inboxAction;
16
+ let receipt = row?.inboxReceipt;
17
+ let note = row?.inboxActionNote;
18
+ let taken = !!action?.kind;
19
+ let label = receipt?.label ?? note?.message ?? (taken ? actionLabel(action) : '');
20
+ let status = card.querySelector('[data-inbox-status]');
21
+ let focused = card.ownerDocument.activeElement?.closest(FORM);
22
+ for (let form of card.querySelectorAll(FORM))form.hidden = taken;
23
+ for (let part of card.querySelectorAll('[data-inbox-pending]')){
24
+ part.hidden = taken;
25
+ }
26
+ status.textContent = label;
27
+ status.hidden = !label;
28
+ card.hidden = action?.kind == 'dismiss' && !note?.message;
29
+ if (taken && focused && !card.hidden) status.focus();
30
+ return receipt;
31
+ };
32
+ // One fewer waits on the installed page's icon. The side's Updates badges
33
+ // count again from the page graph (@yaks/platform/side-browser).
34
+ let answered = (root, slug)=>{
35
+ let doc = root.ownerDocument;
36
+ if (root.dataset.inboxHome != slug) return;
37
+ let app = doc.querySelector('[data-alerts-offer][data-badge]');
38
+ if (!app) return;
39
+ let count = Math.max(0, Number(app.dataset.badge) - 1);
40
+ app.dataset.badge = String(count);
41
+ void doc.defaultView?.navigator.setAppBadge?.(count)?.catch(()=>{});
42
+ };
43
+ // Words sent from a card, to its Operator or to the friend who wrote it:
44
+ // shown sent at once, the box emptied, each send an action of its own that
45
+ // leaves the card as it was. Once the host takes them, the conversation they
46
+ // went to opens; a refusal puts the words back and says why.
47
+ let say = (card, form, page)=>{
48
+ let kind = form.dataset.inboxAction;
49
+ let field = (name)=>form.querySelector(`[name="${name}"]`);
50
+ let box = field(answerField(kind));
51
+ let inboxAction = {
52
+ kind,
53
+ space: form.dataset.inboxSpace,
54
+ target: field(kind)?.value ?? '',
55
+ answer: box?.value ?? ''
56
+ };
57
+ let status = card.querySelector('[data-inbox-status]');
58
+ let tell = (label)=>{
59
+ status.textContent = label;
60
+ status.hidden = !label;
61
+ };
62
+ if (box) box.value = '';
63
+ tell(actionLabel(inboxAction));
64
+ let entity = {
65
+ eid: crypto.randomUUID()
66
+ };
67
+ let send = async ()=>{
68
+ try {
69
+ let applied = await page.mutate([
70
+ {
71
+ entity,
72
+ inboxAction
73
+ }
74
+ ]);
75
+ let receipt = applied.find((b)=>b.entity.eid == entity.eid)?.inboxReceipt;
76
+ tell(receipt?.label ?? '');
77
+ if (receipt?.href) {
78
+ card.ownerDocument.defaultView?.location.assign(receipt.href);
79
+ }
80
+ } catch (error) {
81
+ // Refused, the words come back to the box. Unconfirmed, they may
82
+ // have gone, and the page graph sends them again.
83
+ if (error?.outcome != 'refused') {
84
+ return tell('Waiting to confirm. We’ll try again.');
85
+ }
86
+ if (box && !box.value) box.value = inboxAction.answer;
87
+ tell(error.message);
88
+ }
89
+ };
90
+ void send().catch((error)=>globalThis.reportError?.(error));
91
+ };
92
+ /** Bind the live state of an inbox to its existing forms and card markup. */ export let bindActions = (root, page, lifetime)=>{
93
+ let held = new Set();
94
+ root.addEventListener(REDRAWN, ()=>{
95
+ for (let eid of held){
96
+ let card = root.querySelector(`[data-inbox-card="${eid}"]`);
97
+ if (card) paint(card, page, eid);
98
+ }
99
+ }, {
100
+ signal: lifetime
101
+ });
102
+ root.addEventListener('submit', (event)=>{
103
+ let form = event.target;
104
+ if (!form?.matches(FORM)) return;
105
+ let card = form.closest(CARD);
106
+ let eid = card.dataset.inboxCard;
107
+ let entity = {
108
+ eid
109
+ };
110
+ event.preventDefault();
111
+ if (sayKinds.includes(form.dataset.inboxAction)) {
112
+ return say(card, form, page);
113
+ }
114
+ if (page.ent(eid)?.inboxAction?.kind) return;
115
+ if (!held.has(eid)) {
116
+ let watch = page.watch(`.entity.eid=${eid}`, {
117
+ remote: false
118
+ });
119
+ let waiting = card.dataset.inboxWaits;
120
+ watch.subscribe(()=>{
121
+ if (paint(card, page, eid) && waiting) {
122
+ answered(root, waiting);
123
+ waiting = undefined;
124
+ }
125
+ });
126
+ lifetime.addEventListener('abort', ()=>watch.close(), {
127
+ once: true
128
+ });
129
+ held.add(eid);
130
+ }
131
+ let kind = form.dataset.inboxAction;
132
+ let data = new FormData(form, event.submitter);
133
+ let inboxAction = {
134
+ kind,
135
+ space: form.dataset.inboxSpace,
136
+ target: String(data.get(kind) ?? ''),
137
+ answer: String(data.get(answerField(kind)) ?? '')
138
+ };
139
+ let send = async ()=>{
140
+ try {
141
+ await page.mutate([
142
+ {
143
+ entity,
144
+ inboxAction,
145
+ inboxActionNote: null
146
+ }
147
+ ]);
148
+ } catch (error) {
149
+ let message = error?.outcome == 'refused' ? error.message : 'Waiting to confirm. We’ll try again.';
150
+ await page.mutate([
151
+ {
152
+ entity,
153
+ inboxActionNote: {
154
+ message
155
+ }
156
+ }
157
+ ]);
158
+ }
159
+ };
160
+ void send().catch((error)=>globalThis.reportError?.(error));
161
+ }, {
162
+ signal: lifetime
163
+ });
164
+ };
165
+ //# sourceMappingURL=actions-browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actions-browser.js","sources":["./actions-browser.ts"],"names":[],"mappings":"AACA,SAEE,WAAW,EACX,WAAW,EAGX,QAAQ,uBACW;AACrB,OAAO,WAAW,oBAAoB;EAAE,MAAM;AAAO,EAAC;AAGtD,mEAAmE,GACnE,OAAO,IAAI,cAA0B;EAAC;CAAkB,CAAA;AAExD,IAAI,OAAO;AACX,IAAI,OAAO;AAEX;;UAEU,GACV,OAAO,IAAI,UAAU,gBAAe;AAEpC,IAAI,QAAQ,CAAC,MAAmB,MAAc;EAC5C,IAAI,MAAM,KAAK,GAAG,CAAC;EACnB,IAAI,SAAS,KAAK;EAClB,IAAI,UAAU,KAAK;EACnB,IAAI,OAAO,KAAK;EAChB,IAAI,QAAQ,CAAC,CAAC,QAAQ;EACtB,IAAI,QAAQ,SAAS,SAAS,MAAM,WAClC,CAAC,QAAQ,YAAY,UAAW,EAAE;EACpC,IAAI,SAAS,KAAK,aAAa,CAAoB;EACnD,IAAI,UAAU,KAAK,aAAa,CAAC,aAAa,EAAE,QAAQ;EACxD,KAAK,IAAI,QAAQ,KAAK,gBAAgB,CAAc,MAAO,KAAK,MAAM,GAAG;EACzE,KA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Receipt,
8
+ sayKinds,
9
+ } from './actions.js'
10
+ import front from './front.json' with { type: 'json' }
11
+ import type { VocabDoc } from 'jsr:@yaks/vocab@0.2.36'
12
+
13
+ /** The words a page graph speaks to take an inbox's card actions. */
14
+ export let actionWords: VocabDoc[] = [front as VocabDoc]
15
+
16
+ let FORM = 'form[data-inbox-action]'
17
+ let CARD = '[data-inbox-card]'
18
+
19
+ /** Said, bubbling, by a view that drew its cards again in place: each card
20
+ * keeps its `data-inbox-card`, and the actions paint what they hold on it
21
+ * again. */
22
+ export let REDRAWN = 'inbox:redrawn'
23
+
24
+ let paint = (card: HTMLElement, page: Client, eid: string) => {
25
+ let row = page.ent(eid)
26
+ let action = row?.inboxAction as InboxAction | undefined
27
+ let receipt = row?.inboxReceipt as InboxReceipt | undefined
28
+ let note = row?.inboxActionNote as { message?: string } | undefined
29
+ let taken = !!action?.kind
30
+ let label = receipt?.label ?? note?.message ??
31
+ (taken ? actionLabel(action!) : '')
32
+ let status = card.querySelector<HTMLOutputElement>('[data-inbox-status]')!
33
+ let focused = card.ownerDocument.activeElement?.closest(FORM)
34
+ for (let form of card.querySelectorAll<HTMLElement>(FORM)) form.hidden = taken
35
+ for (let part of card.querySelectorAll<HTMLElement>('[data-inbox-pending]')) {
36
+ part.hidden = taken
37
+ }
38
+ status.textContent = label
39
+ status.hidden = !label
40
+ card.hidden = action?.kind == 'dismiss' && !note?.message
41
+ if (taken && focused && !card.hidden) status.focus()
42
+ return receipt
43
+ }
44
+
45
+ // One fewer waits on the installed page's icon. The side's Updates badges
46
+ // count again from the page graph (@yaks/platform/side-browser).
47
+ let answered = (root: HTMLElement, slug: string) => {
48
+ let doc = root.ownerDocument
49
+ if (root.dataset.inboxHome != slug) return
50
+ let app = doc.querySelector<HTMLElement>('[data-alerts-offer][data-badge]')
51
+ if (!app) return
52
+ let count = Math.max(0, Number(app.dataset.badge) - 1)
53
+ app.dataset.badge = String(count)
54
+ void doc.defaultView?.navigator.setAppBadge?.(count)?.catch(() => {})
55
+ }
56
+
57
+ // Words sent from a card, to its Operator or to the friend who wrote it:
58
+ // shown sent at once, the box emptied, each send an action of its own that
59
+ // leaves the card as it was. Once the host takes them, the conversation they
60
+ // went to opens; a refusal puts the words back and says why.
61
+ let say = (card: HTMLElement, form: HTMLFormElement, page: Client) => {
62
+ let kind = form.dataset.inboxAction as ActionKind
63
+ let field = (name: string) =>
64
+ form.querySelector<HTMLInputElement>(`[name="${name}"]`)
65
+ let box = field(answerField(kind))
66
+ let inboxAction: InboxAction = {
67
+ kind,
68
+ space: form.dataset.inboxSpace!,
69
+ target: field(kind)?.value ?? '',
70
+ answer: box?.value ?? '',
71
+ }
72
+ let status = card.querySelector<HTMLOutputElement>('[data-inbox-status]')!
73
+ let tell = (label: string) => {
74
+ status.textContent = label
75
+ status.hidden = !label
76
+ }
77
+ if (box) box.value = ''
78
+ tell(actionLabel(inboxAction))
79
+ let entity = { eid: crypto.randomUUID() }
80
+ let send = async () => {
81
+ try {
82
+ let applied = await page.mutate([{ entity, inboxAction }])
83
+ let receipt = applied.find((b) => b.entity.eid == entity.eid)
84
+ ?.inboxReceipt as InboxReceipt | undefined
85
+ tell(receipt?.label ?? '')
86
+ if (receipt?.href) {
87
+ card.ownerDocument.defaultView?.location.assign(receipt.href)
88
+ }
89
+ } catch (error) {
90
+ // Refused, the words come back to the box. Unconfirmed, they may
91
+ // have gone, and the page graph sends them again.
92
+ if ((error as { outcome?: string })?.outcome != 'refused') {
93
+ return tell('Waiting to confirm. We’ll try again.')
94
+ }
95
+ if (box && !box.value) box.value = inboxAction.answer
96
+ tell((error as Error).message)
97
+ }
98
+ }
99
+ void send().catch((error) => globalThis.reportError?.(error))
100
+ }
101
+
102
+ /** Bind the live state of an inbox to its existing forms and card markup. */
103
+ export let bindActions = (
104
+ root: HTMLElement,
105
+ page: Client,
106
+ lifetime: AbortSignal,
107
+ ): void => {
108
+ let held = new Set<string>()
109
+ root.addEventListener(REDRAWN, () => {
110
+ for (let eid of held) {
111
+ let card = root.querySelector<HTMLElement>(`[data-inbox-card="${eid}"]`)
112
+ if (card) paint(card, page, eid)
113
+ }
114
+ }, { signal: lifetime })
115
+ root.addEventListener('submit', (event) => {
116
+ let form = event.target as HTMLFormElement | null
117
+ if (!form?.matches(FORM)) return
118
+ let card = form.closest<HTMLElement>(CARD)!
119
+ let eid = card.dataset.inboxCard!
120
+ let entity = { eid }
121
+ event.preventDefault()
122
+ if (sayKinds.includes(form.dataset.inboxAction as ActionKind)) {
123
+ return say(card, form, page)
124
+ }
125
+ if ((page.ent(eid)?.inboxAction as InboxAction | undefined)?.kind) return
126
+ if (!held.has(eid)) {
127
+ let watch = page.watch(`.entity.eid=${eid}`, { remote: false })
128
+ let waiting = card.dataset.inboxWaits
129
+ watch.subscribe(() => {
130
+ if (paint(card, page, eid) && waiting) {
131
+ answered(root, waiting)
132
+ waiting = undefined
133
+ }
134
+ })
135
+ lifetime.addEventListener('abort', () => watch.close(), { once: true })
136
+ held.add(eid)
137
+ }
138
+ let kind = form.dataset.inboxAction as ActionKind
139
+ let data = new FormData(form, (event as SubmitEvent).submitter)
140
+ let inboxAction: InboxAction = {
141
+ kind,
142
+ space: form.dataset.inboxSpace!,
143
+ target: String(data.get(kind) ?? ''),
144
+ answer: String(data.get(answerField(kind)) ?? ''),
145
+ }
146
+ let send = async () => {
147
+ try {
148
+ await page.mutate([{ entity, inboxAction, inboxActionNote: null }])
149
+ } catch (error) {
150
+ let message = (error as { outcome?: string })?.outcome == 'refused'
151
+ ? (error as Error).message
152
+ : 'Waiting to confirm. We’ll try again.'
153
+ await page.mutate([{ entity, inboxActionNote: { message } }])
154
+ }
155
+ }
156
+ void send().catch((error) => globalThis.reportError?.(error))
157
+ }, { signal: lifetime })
158
+ }
package/actions.js ADDED
@@ -0,0 +1,34 @@
1
+ export let actionKinds = [
2
+ 'choose',
3
+ 'dismiss',
4
+ 'friend',
5
+ 'transfer',
6
+ 'seen',
7
+ 'reply',
8
+ 'message'
9
+ ];
10
+ /** The kinds that send a person's words about a card (to its Operator, or
11
+ * to the friend who wrote it) and leave the card as it was: each send is an
12
+ * action of its own, and the card stays open for another. */ export let sayKinds = [
13
+ 'reply',
14
+ 'message'
15
+ ];
16
+ export let actionLabel = ({ kind, answer })=>{
17
+ switch(kind){
18
+ case 'friend':
19
+ return answer == 'approved' ? 'Request sent' : 'Dismissed';
20
+ case 'choose':
21
+ return 'Answer sent';
22
+ case 'dismiss':
23
+ return 'Dismissed';
24
+ case 'transfer':
25
+ return answer == 'decline' ? 'Declining…' : 'Accepting…';
26
+ case 'seen':
27
+ return 'Read';
28
+ case 'reply':
29
+ case 'message':
30
+ return 'Sending…';
31
+ }
32
+ };
33
+ /** The answer control a card's form submits. */ export let answerField = (kind)=>kind == 'choose' ? 'choice' : sayKinds.includes(kind) ? 'say' : 'answer';
34
+ //# sourceMappingURL=actions.js.map
package/actions.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actions.js","sources":["./actions.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,cAAc;EACvB;EACA;EACA;EACA;EACA;EACA;EACA;CACD,CAAS;AAIV;;2DAE2D,GAC3D,OAAO,IAAI,WAAkC;EAAC;EAAS;CAAU,CAAA;AAiBjE,OAAO,IAAI,cAAc,CAAC,EAAE,IAAI,EAAE,MAAM,EAAe;EACrD,OAAQ;IACN,KAAK;MACH,OAAO,UAAU,aAAa,iBAAiB;IACjD,KAAK;MACH,OAAO;IACT,KAAK;MACH,OAAO;IACT,KAAK;MACH,OAAO,UAAU,YAAY,eAAe;IAC9C,KAAK;MACH,OAAO;IACT,KAAK;IACL,KAAK;MACH,OAAO;EACX;AACF,EAAC;AAED,8CAA8C,GAC9C,OAAO,IAAI,cAAc,CAAC,OACxB,QAAQ,WAAW,WAAW,SAAS,QAAQ,CAAC,QAAQ,QAAQ,SAAQ"}
package/actions.ts ADDED
@@ -0,0 +1,53 @@
1
+ export let actionKinds = [
2
+ 'choose',
3
+ 'dismiss',
4
+ 'friend',
5
+ 'transfer',
6
+ 'seen',
7
+ 'reply',
8
+ 'message',
9
+ ] as const
10
+
11
+ export type ActionKind = typeof actionKinds[number]
12
+
13
+ /** The kinds that send a person's words about a card (to its Operator, or
14
+ * to the friend who wrote it) and leave the card as it was: each send is an
15
+ * action of its own, and the card stays open for another. */
16
+ export let sayKinds: readonly ActionKind[] = ['reply', 'message']
17
+
18
+ /** A card action and the answer its host has committed. `seen` is the
19
+ * person opening a space's Updates where no page was asked for (a view
20
+ * shown in place): what it shows is read, as opening the page reads it. Its
21
+ * target is the space. */
22
+ export type InboxAction = {
23
+ space: string
24
+ kind: ActionKind
25
+ target: string
26
+ answer: string
27
+ }
28
+
29
+ /** What the host says it did, and where the conversation the action
30
+ * started goes on (`href`), which the page opens. */
31
+ export type InboxReceipt = { label: string; href?: string }
32
+
33
+ export let actionLabel = ({ kind, answer }: InboxAction): string => {
34
+ switch (kind) {
35
+ case 'friend':
36
+ return answer == 'approved' ? 'Request sent' : 'Dismissed'
37
+ case 'choose':
38
+ return 'Answer sent'
39
+ case 'dismiss':
40
+ return 'Dismissed'
41
+ case 'transfer':
42
+ return answer == 'decline' ? 'Declining…' : 'Accepting…'
43
+ case 'seen':
44
+ return 'Read'
45
+ case 'reply':
46
+ case 'message':
47
+ return 'Sending…'
48
+ }
49
+ }
50
+
51
+ /** The answer control a card's form submits. */
52
+ export let answerField = (kind: ActionKind): string =>
53
+ kind == 'choose' ? 'choice' : sayKinds.includes(kind) ? 'say' : 'answer'
package/asks.js ADDED
@@ -0,0 +1,76 @@
1
+ /**
2
+ * What the inbox views ask of the host drawing them. A person's threads come
3
+ * from the server-owned summary (`inbox_summary`, ./queries.ts `summaryQuery`):
4
+ * one subscription for the list, one more for an opened thread's messages.
5
+ * Beside it the views hold only the rows they draw (each thread's root and
6
+ * newest message, and an opened thread's messages), never the history behind
7
+ * them. Counts read the same summary, so a count and its list agree, and a
8
+ * host that shares one query between its askers asks the server once. What
9
+ * the views write and draw goes out through the same host (`mark`, `show`).
10
+ *
11
+ * @module
12
+ */ import { toolEid } from "@yaks/tools/result";
13
+ import { summaryQuery } from "./queries.js";
14
+ /** A summary row as the bundle a view draws: its components on its eid. */ export let bundleOf = (r)=>({
15
+ ...r.comps,
16
+ entity: {
17
+ ...r.comps.entity,
18
+ eid: r.eid
19
+ }
20
+ });
21
+ /** The threads read for `actor`, ready once the summary and every row they
22
+ * draw have arrived: a completed summary whose titles are still on their way
23
+ * is not a populated page. A `thread` names one whose messages are read
24
+ * whole. */ export let useThreads = (io, actor, search = {}, thread)=>{
25
+ let read = io.ask({
26
+ summary: summaryQuery(actor, search, thread)
27
+ }).summary;
28
+ let summaries = read.rows.flatMap((b)=>{
29
+ let value = b.inbox_summary?.threads;
30
+ return Array.isArray(value) ? value : [];
31
+ });
32
+ let draws = [
33
+ ...new Set(summaries.flatMap((t)=>[
34
+ t.row.eid,
35
+ t.latest.eid,
36
+ ...thread ? t.messages.map((m)=>m.eid) : []
37
+ ]))
38
+ ];
39
+ let draw = io.ask(draws.length ? {
40
+ draw: `.entity.eid=${draws.join(',')}&*`
41
+ } : {}).draw;
42
+ let ready = read.ready && !read.error && (!draw || draw.ready && !draw.error);
43
+ return {
44
+ threads: ready ? summaries : [],
45
+ ready
46
+ };
47
+ };
48
+ /** One thread with its messages read whole, archived history included. */ export let useThread = (io, actor, eid)=>useThreads(io, actor, {
49
+ all: true
50
+ }, eid);
51
+ /** How many threads wait unread for the entity drawn, from the same summary
52
+ * as its list; undefined until it is read. */ export let waiting = (e, io)=>{
53
+ let found = useThreads(io, e.entity.eid);
54
+ return found.ready ? found.threads.filter((t)=>t.unread).length : undefined;
55
+ };
56
+ /** An entity the host holds, drawn as `view` through its shared renderers. */ export let show = (io, eid, view, ctx)=>io.show(io.get(eid) ?? {
57
+ entity: {
58
+ eid
59
+ }
60
+ }, view, ctx);
61
+ /** Mark a thread read or archived; the policy brings an archived one back on
62
+ * its next activity. */ export let mark = (io, actor, eid, how)=>void Promise.resolve().then(()=>io.apply([
63
+ {
64
+ entity: {
65
+ eid: '$attention'
66
+ },
67
+ call: {
68
+ to: toolEid(how == 'opened' ? 'inbox_open' : 'inbox_archive'),
69
+ args: {
70
+ who: actor,
71
+ item: eid
72
+ }
73
+ }
74
+ }
75
+ ])).catch(()=>{});
76
+ //# sourceMappingURL=asks.js.map
package/asks.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asks.js","sources":["./asks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;CAWC,GAKD,SAAS,OAAO,kCAAuC;AACvD,SAAS,YAAY,uBAAsB;AAK3C,yEAAyE,GACzE,OAAO,IAAI,WAAW,CAAC,IAAmB,CAAC;IACzC,GAAG,EAAE,KAAK;IACV,QAAQ;MAAE,GAAG,EAAE,KAAK,CAAC,MAAM;MAAE,KAAK,EAAE,GAAG;IAAC;EAC1C,CAAC,EAAC;AAEF;;;UAGU,GACV,OAAO,IAAI,aAAa,CACtB,IACA,OACA,SAAiB,CAAC,CAAC,EACnB;EAEA,IAAI,OAAO,GAAG,GAAG,CAAC;IAAE,SAAS,aAAa,OAAO,QAAQ;EAAQ,GAAG,OAAO;EAC3E,IAAI,YAAY,KAAK,IAAI,CAAC,OAAO,CAAC,CAAC;IACjC,IAAI,QAAS,EAAE,aAAa,EAAwC;IACpE,OAAO,MAAM,OAAO,CAAC,SAAS,QAAyB,EAAE;EAC3D;EACA,IAAI,QAAQ;OACP,IAAI,IAAI,UAAU,OAAO,CAAC,CAAC,IAAM;QAClC,EAAE,GAAG,CAAC,GAAG;QACT,EAAE,MAAM,CAAC,GAAG;WACR,SAAS,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAM,EAAE,GAAG,IAAI,EAAE;OAC/C;GACF;EACD,IAAI,OAAO,GAAG,GAAG,CACf,MAAM,MAAM,GAAG;IAAE,MAAM,CAAC,YAAY,EAAE,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;EAAC,IAAI,CAAC,GAC/D,IAAI;EACN,IAAI,QAAQ,KAAK,KAAK,IAAI,CAAC,KAAK,KAAK,IACnC,CAAC,CAAC,QAAQ,KAAK,KAAK,IAAI,CAAC,KAAK,KAAK;EACrC,OAAO;IAAE,SAAS,QAAQ,YAAY,EAAE;IAAE;EAAM;AAClD,EAAC;AAED,wEAAwE,GACxE,OAAO,IAAI,YAAY,CAAC,IAAQ,OAAe,MAC7C,WAAW,IAAI,OAAO;IAAE,KAAK;EAAK,GAAG,KAAI;AAE3C;4CAC4C,GAC5C,OAAO,IAAI,UAAU,CAAC,GAAW;EAC/B,IAAI,QAAQ,WAAW,IAAI,EAAE,MAAM,CAAC,GAAG;EACvC,OAAO,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC,IAAM,EAAE,MAAM,EAAE,MAAM,GAAG;AACtE,EAAC;AAED,4EAA4E,GAC5E,OAAO,IAAI,OAAO,CAChB,IACA,KACA,MACA,MACG,GAAG,IAAI,CAAC,GAAG,GAAG,CAAC,QAAQ;IAAE,QAAQ;MAAE;IAAI;EAAE,GAAG,MAAM,KAAI;AAE3D;sBACsB,GACtB,OAAO,IAAI,OAAO,CAChB,IACA,OACA,KACA,MAEA,KAAK,QAAQ,OAAO,GAAG,IAAI,CAAC,IAC1B,GAAG,KAAK,CAAC;MAAC;QACR,QAAQ;UAAE,KAAK;QAAa;QAC5B,MAAM;UACJ,IAAI,QAAQ,OAAO,WAAW,eAAe;UAC7C,MAAM;YAAE,KAAK;YAAO,MAAM;UAAI;QAChC;MACF;KAAE,GACF,KAAK,CAAC,KAAO,GAAE"}
package/asks.ts ADDED
@@ -0,0 +1,94 @@
1
+ /**
2
+ * What the inbox views ask of the host drawing them. A person's threads come
3
+ * from the server-owned summary (`inbox_summary`, ./queries.ts `summaryQuery`):
4
+ * one subscription for the list, one more for an opened thread's messages.
5
+ * Beside it the views hold only the rows they draw (each thread's root and
6
+ * newest message, and an opened thread's messages), never the history behind
7
+ * them. Counts read the same summary, so a count and its list agree, and a
8
+ * host that shares one query between its askers asks the server once. What
9
+ * the views write and draw goes out through the same host (`mark`, `show`).
10
+ *
11
+ * @module
12
+ */
13
+
14
+ import type { Bundle, Io } from 'jsr:@yaks/inspect@0.2.36'
15
+ import type { Row } from './reader.ts'
16
+ import { type Search, type Thread } from './threads.js'
17
+ import { toolEid } from '@yaks/tools/result'
18
+ import { summaryQuery } from './queries.js'
19
+
20
+ /** A thread's rows as the summary carries them. */
21
+ export type Threads = { threads: Thread<Row>[]; ready: boolean }
22
+
23
+ /** A summary row as the bundle a view draws: its components on its eid. */
24
+ export let bundleOf = (r: Row): Bundle => ({
25
+ ...r.comps,
26
+ entity: { ...r.comps.entity, eid: r.eid },
27
+ })
28
+
29
+ /** The threads read for `actor`, ready once the summary and every row they
30
+ * draw have arrived: a completed summary whose titles are still on their way
31
+ * is not a populated page. A `thread` names one whose messages are read
32
+ * whole. */
33
+ export let useThreads = (
34
+ io: Io,
35
+ actor: string,
36
+ search: Search = {},
37
+ thread?: string,
38
+ ): Threads => {
39
+ let read = io.ask({ summary: summaryQuery(actor, search, thread) }).summary
40
+ let summaries = read.rows.flatMap((b) => {
41
+ let value = (b.inbox_summary as { threads?: unknown } | undefined)?.threads
42
+ return Array.isArray(value) ? value as Thread<Row>[] : []
43
+ })
44
+ let draws = [
45
+ ...new Set(summaries.flatMap((t) => [
46
+ t.row.eid,
47
+ t.latest.eid,
48
+ ...(thread ? t.messages.map((m) => m.eid) : []),
49
+ ])),
50
+ ]
51
+ let draw = io.ask(
52
+ draws.length ? { draw: `.entity.eid=${draws.join(',')}&*` } : {},
53
+ ).draw
54
+ let ready = read.ready && !read.error &&
55
+ (!draw || draw.ready && !draw.error)
56
+ return { threads: ready ? summaries : [], ready }
57
+ }
58
+
59
+ /** One thread with its messages read whole, archived history included. */
60
+ export let useThread = (io: Io, actor: string, eid: string): Threads =>
61
+ useThreads(io, actor, { all: true }, eid)
62
+
63
+ /** How many threads wait unread for the entity drawn, from the same summary
64
+ * as its list; undefined until it is read. */
65
+ export let waiting = (e: Bundle, io: Io): number | undefined => {
66
+ let found = useThreads(io, e.entity.eid)
67
+ return found.ready ? found.threads.filter((t) => t.unread).length : undefined
68
+ }
69
+
70
+ /** An entity the host holds, drawn as `view` through its shared renderers. */
71
+ export let show = (
72
+ io: Io,
73
+ eid: string,
74
+ view: string,
75
+ ctx?: Record<string, unknown>,
76
+ ) => io.show(io.get(eid) ?? { entity: { eid } }, view, ctx)
77
+
78
+ /** Mark a thread read or archived; the policy brings an archived one back on
79
+ * its next activity. */
80
+ export let mark = (
81
+ io: Io,
82
+ actor: string,
83
+ eid: string,
84
+ how: 'opened' | 'archived',
85
+ ): void =>
86
+ void Promise.resolve().then(() =>
87
+ io.apply([{
88
+ entity: { eid: '$attention' },
89
+ call: {
90
+ to: toolEid(how == 'opened' ? 'inbox_open' : 'inbox_archive'),
91
+ args: { who: actor, item: eid },
92
+ },
93
+ }])
94
+ ).catch(() => {})
package/deno.json ADDED
@@ -0,0 +1 @@
1
+ {"publish":{"exclude":["**/*_test.ts","**/*_test.tsx","./testing.tsx"]},"name":"@yaks/inbox","version":"0.2.36","license":"Apache-2.0","description":"Exact person and thread attention policy, with server-owned summaries and lazy conversation reads shared by inbox doors.","exports":{".":"./mod.ts","./queries":"./queries.ts","./vocab":"./vocab.ts","./tools":"./tools.ts","./graph":"./graph.ts","./read":"./read.ts","./service":"./service.ts","./letters":"./letters.ts","./mail":"./mail.ts","./actions":"./actions.ts","./actions-browser":"./actions-browser.ts","./views":"./views.tsx"},"imports":{"@yaks/inbox":"./mod.ts","@yaks/inbox/queries":"./queries.ts","@yaks/inbox/vocab":"./vocab.ts","@yaks/inbox/tools":"./tools.ts","@yaks/inbox/graph":"./graph.ts","@yaks/inbox/read":"./read.ts","@yaks/inbox/service":"./service.ts","@yaks/inbox/letters":"./letters.ts","@yaks/inbox/mail":"./mail.ts","@yaks/inbox/actions":"./actions.ts","@yaks/inbox/actions-browser":"./actions-browser.ts","@yaks/inbox/views":"./views.tsx"}}
package/front.js ADDED
@@ -0,0 +1,41 @@
1
+ /**
2
+ * The inbox views' own state: which threads are expanded and how the search
3
+ * is switched. It is the page's, never the graph's, so it lives in a page
4
+ * graph of the views' own (./front.json), a @yaks/client over RAM that no
5
+ * server hears of, where a remount finds it again. What a person types is a
6
+ * draft (@yaks/draft), kept everywhere, not this.
7
+ *
8
+ * @module
9
+ */ import { client } from "@yaks/client";
10
+ import { derivedEid } from "@yaks/graph/identity";
11
+ import { useRows } from "@yaks/ux";
12
+ import { loadVocab } from "@yaks/vocab";
13
+ import doc from './front.json' with {
14
+ type: 'json'
15
+ };
16
+ let made;
17
+ /** The inbox views' page graph, made when a view first asks for it: a server
18
+ * that imports the views to see what they offer never makes one. */ export let front = ()=>made ??= client(loadVocab([
19
+ doc
20
+ ]), [], {
21
+ vault: false,
22
+ wireVault: false,
23
+ page: false
24
+ });
25
+ /** One view's state at a stable place, read live and changed in place: a
26
+ * thread's (`thread:<eid>`) or a person's search (`search:<eid>`). */ export let usePage = (place)=>{
27
+ let eid = derivedEid(`inboxView|${place}`);
28
+ let [state] = useRows(front(), `.inboxView .entity.eid=${eid}`);
29
+ return {
30
+ value: state?.inboxView,
31
+ set: (value)=>void front().mutate([
32
+ {
33
+ entity: {
34
+ eid
35
+ },
36
+ inboxView: value
37
+ }
38
+ ])
39
+ };
40
+ };
41
+ //# sourceMappingURL=front.js.map
package/front.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"front.js","sources":["./front.ts"],"names":[],"mappings":"AAAA;;;;;;;;CAQC,GAED,SAAsB,MAAM,4BAAiC;AAC7D,SAAS,UAAU,oCAAyC;AAC5D,SAAS,OAAO,wBAA6B;AAC7C,SAAS,SAAS,2BAA+C;AACjE,OAAO,SAAS,oBAAoB;EAAE,MAAM;AAAO,EAAC;AAEpD,IAAI;AAEJ;kEACkE,GAClE,OAAO,IAAI,QAAQ,IACjB,SAAS,OAAO,UAAU;IAAC;GAAgB,GAAG,EAAE,EAAE;IAChD,OAAO;IACP,WAAW;IACX,MAAM;EACR,GAAE;AAEJ;oEACoE,GACpE,OAAO,IAAI,UAAU,CAAoC;EACvD,IAAI,MAAM,WAAW,CAAC,UAAU,EAAE,OAAO;EACzC,IAAI,CAAC,MAAM,GAAG,QAAQ,SAAS,CAAC,uBAAuB,EAAE,KAAK;EAC9D,OAAO;IACL,OAAO,OAAO;IACd,KAAK,CAAC,QACJ,KAAK,QAAQ,MAAM,CAAC;QAAC;UAAE,QAAQ;YAAE;UAAI;UAAG,WAAW;QAAM;OAAE;EAC/D;AACF,EAAC"}