@yaks/task 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 (68) hide show
  1. package/DecisionForm.js +118 -0
  2. package/DecisionForm.js.map +1 -0
  3. package/DecisionForm.ts +211 -0
  4. package/LICENSE +202 -0
  5. package/README.md +389 -2
  6. package/_dist/DecisionForm.d.ts +25 -0
  7. package/_dist/DecisionForm.d.ts.map +1 -0
  8. package/_dist/comp.d.ts +20 -0
  9. package/_dist/comp.d.ts.map +1 -0
  10. package/_dist/decision.d.ts +41 -0
  11. package/_dist/decision.d.ts.map +1 -0
  12. package/_dist/deps.d.ts +58 -0
  13. package/_dist/deps.d.ts.map +1 -0
  14. package/_dist/graph.d.ts +3 -0
  15. package/_dist/graph.d.ts.map +1 -0
  16. package/_dist/mod.d.ts +71 -0
  17. package/_dist/mod.d.ts.map +1 -0
  18. package/_dist/plugin.d.ts +28 -0
  19. package/_dist/plugin.d.ts.map +1 -0
  20. package/_dist/text.d.ts +5 -0
  21. package/_dist/text.d.ts.map +1 -0
  22. package/_dist/tools.d.ts +20 -0
  23. package/_dist/tools.d.ts.map +1 -0
  24. package/_dist/views.d.ts +6 -0
  25. package/_dist/views.d.ts.map +1 -0
  26. package/_dist/vocab.d.ts +7 -0
  27. package/_dist/vocab.d.ts.map +1 -0
  28. package/_dist/words.d.ts +28 -0
  29. package/_dist/words.d.ts.map +1 -0
  30. package/comp.js +66 -0
  31. package/comp.js.map +1 -0
  32. package/comp.ts +77 -0
  33. package/decision.js +156 -0
  34. package/decision.js.map +1 -0
  35. package/decision.ts +174 -0
  36. package/deno.json +1 -0
  37. package/deps.js +127 -0
  38. package/deps.js.map +1 -0
  39. package/deps.ts +163 -0
  40. package/graph.js +9 -0
  41. package/graph.js.map +1 -0
  42. package/graph.ts +10 -0
  43. package/inspect.js +131 -0
  44. package/inspect.js.map +1 -0
  45. package/inspect.ts +144 -0
  46. package/mod.js +71 -0
  47. package/mod.js.map +1 -0
  48. package/mod.ts +83 -0
  49. package/package.json +53 -4
  50. package/plugin.js +46 -0
  51. package/plugin.js.map +1 -0
  52. package/plugin.ts +40 -0
  53. package/text.js +22 -0
  54. package/text.js.map +1 -0
  55. package/text.ts +30 -0
  56. package/tools.js +303 -0
  57. package/tools.js.map +1 -0
  58. package/tools.ts +282 -0
  59. package/views.js +35 -0
  60. package/views.js.map +1 -0
  61. package/views.ts +39 -0
  62. package/vocab.js +18 -0
  63. package/vocab.js.map +1 -0
  64. package/vocab.json +860 -0
  65. package/vocab.ts +20 -0
  66. package/words.js +46 -0
  67. package/words.js.map +1 -0
  68. package/words.ts +57 -0
package/deps.js ADDED
@@ -0,0 +1,127 @@
1
+ // The two questions a task list asks about a task that is not finished: is
2
+ // anything in the way, and how much of it is left.
3
+ //
4
+ // They are deliberately different questions with different answers, because
5
+ // conflating them is what makes a board shout.
6
+ //
7
+ // Gated is the alarm. `blocked{on}` records that something outside the graph
8
+ // has stopped this — a vendor, a decision, a person who has not replied. Nobody
9
+ // here can move it, so it is worth a mark on the row.
10
+ //
11
+ // Open deps is not an alarm. A task with three unfinished `requires` children
12
+ // is a task with three unfinished children: ordinary work, in progress, exactly
13
+ // as it should be. It is a count — "3 left" — and zero renders nothing at all.
14
+ // Showing it in red would mean flagging every plan the moment somebody made
15
+ // one.
16
+ //
17
+ // A child that is not a task cannot settle, so it counts as open: a task
18
+ // waiting on a document is waiting until somebody removes the link.
19
+ //
20
+ // Synchronous in, synchronous out: over a storage that answers immediately (a
21
+ // Map, an embedded database) so do these functions, while an asynchronous
22
+ // storage turns the answer into a promise. Nothing in between has to know
23
+ // which.
24
+ import { after } from "@yaks/fp";
25
+ import { detached } from "@yaks/graph/storage";
26
+ import { and, eq, or, present } from "@yaks/query";
27
+ import { EDGE } from "@yaks/edge";
28
+ import { settled, statusComps, statusOf } from "./words.js";
29
+ import { BLOCKED, CONTAINS, REQUIRES } from "./comp.js";
30
+ /**
31
+ * Is something outside the graph in the way? Reads the `blocked` component,
32
+ * which is never a status — a blocked task is still open work, and still shows
33
+ * up in every query for open work.
34
+ *
35
+ * ```ts
36
+ * import { gated } from '@yaks/task'
37
+ *
38
+ * gated({ entity: { eid: 't1' }, task: {}, blocked: { on: 'legal' } }) // true
39
+ * ```
40
+ */ export let gated = (b)=>{
41
+ let c = b[BLOCKED];
42
+ return c != null && typeof c == 'object';
43
+ };
44
+ // The other ends of every edge with any of these relations touching `eid` at
45
+ // `at`, deduplicated: `from` follows edges away from it, `to` edges into it.
46
+ // Read the matching edges together, so one end linked by two relations costs
47
+ // only one read.
48
+ let ends = (tx, eid, rels, at)=>{
49
+ if (!rels.length) return [];
50
+ let far = at == 'from' ? 'to' : 'from';
51
+ return after(tx.read(and(eq(`${EDGE}.${at}`, eid), or(...rels.map(present)))), (bundles)=>{
52
+ let seen = new Set();
53
+ for (let b of bundles){
54
+ let end = b[EDGE]?.[far];
55
+ if (typeof end == 'string') seen.add(end);
56
+ }
57
+ return [
58
+ ...seen
59
+ ];
60
+ });
61
+ };
62
+ /**
63
+ * What this task waits on: the far ends of its `requires` and `contains`
64
+ * edges, settled or not.
65
+ *
66
+ * ```ts
67
+ * import { dependencies } from '@yaks/task'
68
+ *
69
+ * // dependencies(graph, 'p') // → ['a', 'b']
70
+ * ```
71
+ */ export let dependencies = ({ storage }, eid, opts = {})=>ends(detached(storage), eid, opts.relations ?? [
72
+ REQUIRES,
73
+ CONTAINS
74
+ ], 'from');
75
+ /**
76
+ * What waits on this task: the near ends of the `requires` and `contains`
77
+ * edges leading to it, the tasks its finishing may free.
78
+ *
79
+ * ```ts
80
+ * import { dependents } from '@yaks/task'
81
+ *
82
+ * // dependents(graph, 'a') // → ['p']
83
+ * ```
84
+ */ export let dependents = ({ storage }, eid, opts = {})=>ends(detached(storage), eid, opts.relations ?? [
85
+ REQUIRES,
86
+ CONTAINS
87
+ ], 'to');
88
+ /**
89
+ * How many of this task's children are still unfinished — the calm "3 left"
90
+ * count, never an alarm. Follows `requires` and `contains` out of the task and
91
+ * counts the far ends that have not settled; a child that is not a task cannot
92
+ * settle and so counts as open. Zero is the ordinary answer, and renders as
93
+ * nothing.
94
+ *
95
+ * ```ts
96
+ * import { openDeps } from '@yaks/task'
97
+ *
98
+ * // openDeps(graph, 't1') // → 2
99
+ * ```
100
+ */ export let openDeps = ({ storage, vocab }, eid, opts = {})=>{
101
+ let tx = detached(storage);
102
+ let marks = statusComps(vocab);
103
+ return after(ends(tx, eid, opts.relations ?? [
104
+ REQUIRES,
105
+ CONTAINS
106
+ ], 'from'), (kids)=>kids.length == 0 ? 0 : after(tx.get(kids, marks), (bundles)=>{
107
+ // Counted by what has settled, so a child the storage does not hold —
108
+ // and which therefore cannot be shown to have finished — stays counted.
109
+ let done = bundles.filter((b)=>settled(statusOf(vocab, b))).length;
110
+ return kids.length - done;
111
+ }));
112
+ };
113
+ /**
114
+ * Has this task settled and finished its dependencies? Completion alone does
115
+ * not release a parent while `requires` or `contains` children remain open.
116
+ * Like {@link openDeps}, this counts direct far ends, not a recursive walk.
117
+ * A missing entity, or an entity without a `task` component, is never done.
118
+ *
119
+ * Synchronous storage returns a boolean; asynchronous storage returns a
120
+ * promise.
121
+ */ export let done = (held, eid, opts = {})=>after(held.storage.get([
122
+ eid
123
+ ], statusComps(held.vocab)), (bundles)=>{
124
+ if (!bundles[0] || !settled(statusOf(held.vocab, bundles[0]))) return false;
125
+ return after(openDeps(held, eid, opts), (count)=>count == 0);
126
+ });
127
+ //# sourceMappingURL=deps.js.map
package/deps.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deps.js","sources":["./deps.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,mDAAmD;AACnD,EAAE;AACF,4EAA4E;AAC5E,+CAA+C;AAC/C,EAAE;AACF,6EAA6E;AAC7E,gFAAgF;AAChF,sDAAsD;AACtD,EAAE;AACF,8EAA8E;AAC9E,gFAAgF;AAChF,+EAA+E;AAC/E,4EAA4E;AAC5E,OAAO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ACtB,EAAE,OAAO,EAA0B,EACnC,KACA,OAAgB,CAAC,CAAC,GAElB,KAAK,SAAS,UAAU,KAAK,KAAK,SAAS,IAAI;IAAC;IAAU;GAAS,EAAE,MAAK;AAE5E;;;;;;;;;;;;CAYC,GACD,OAAO,IAAI,WAAW,CACpB,EAAE,OAAO,EAAE,KAAK,EAAoC,EACpD,KACA,OAAgB,CAAC,CAAC;EAElB,IAAI,KAAK,SAAS;EAClB,IAAI,QAAQ,YAAY;EACxB,OAAO,MACL,KAAK,IAAI,KAAK,KAAK,SAAS,IAAI;IAAC;IAAU;GAAS,EAAE,SACtD,CAAC,OACC,KAAK,MAAM,IAAI,IAAI,IAAI,MAAM,GAAG,GAAG,CAAC,MAAM,QAAQ,CAAC;MACjD,sEAAsE;MACtE,wEAAwE;MACxE,IAAI,OAAO,QAAQ,MAAM,CAAC,CAAC,IAAM,QAAQ,SAAS,OAAO,KAAK,MAAM;MACpE,OAAO,KAAK,MAAM,GAAG;IACvB;AAEN,EAAC;AAED;;;;;;;;CAQC,GACD,OAAO,IAAI,OAAO,CAChB,MACA,KACA,OAAgB,CAAC,CAAC,GAElB,MAAM,KAAK,OAAO,CAAC,GAAG,CAAC;IAAC;GAAI,EAAE,YAAY,KAAK,KAAK,IAAI,CAAC;IACvD,IAAI,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,QAAQ,SAAS,KAAK,KAAK,EAAE,OAAO,CAAC,EAAE,IAAI,OAAO;IACtE,OAAO,MAAM,SAAS,MAAM,KAAK,OAAO,CAAC,QAAU,SAAS;EAC9D,GAAgC"}
package/deps.ts ADDED
@@ -0,0 +1,163 @@
1
+ // The two questions a task list asks about a task that is not finished: is
2
+ // anything in the way, and how much of it is left.
3
+ //
4
+ // They are deliberately different questions with different answers, because
5
+ // conflating them is what makes a board shout.
6
+ //
7
+ // Gated is the alarm. `blocked{on}` records that something outside the graph
8
+ // has stopped this — a vendor, a decision, a person who has not replied. Nobody
9
+ // here can move it, so it is worth a mark on the row.
10
+ //
11
+ // Open deps is not an alarm. A task with three unfinished `requires` children
12
+ // is a task with three unfinished children: ordinary work, in progress, exactly
13
+ // as it should be. It is a count — "3 left" — and zero renders nothing at all.
14
+ // Showing it in red would mean flagging every plan the moment somebody made
15
+ // one.
16
+ //
17
+ // A child that is not a task cannot settle, so it counts as open: a task
18
+ // waiting on a document is waiting until somebody removes the link.
19
+ //
20
+ // Synchronous in, synchronous out: over a storage that answers immediately (a
21
+ // Map, an embedded database) so do these functions, while an asynchronous
22
+ // storage turns the answer into a promise. Nothing in between has to know
23
+ // which.
24
+
25
+ import type { Bundle, Eid, Graph, Tx } from 'jsr:@yaks/graph@0.2.36'
26
+ import { after } from '@yaks/fp'
27
+ import { detached } from '@yaks/graph/storage'
28
+ import { and, eq, or, present } from '@yaks/query'
29
+ import { EDGE } from '@yaks/edge'
30
+ import { settled, statusComps, statusOf } from './words.js'
31
+ import { BLOCKED, CONTAINS, REQUIRES } from './comp.js'
32
+
33
+ /**
34
+ * Is something outside the graph in the way? Reads the `blocked` component,
35
+ * which is never a status — a blocked task is still open work, and still shows
36
+ * up in every query for open work.
37
+ *
38
+ * ```ts
39
+ * import { gated } from '@yaks/task'
40
+ *
41
+ * gated({ entity: { eid: 't1' }, task: {}, blocked: { on: 'legal' } }) // true
42
+ * ```
43
+ */
44
+ export let gated = (b: Bundle): boolean => {
45
+ let c = b[BLOCKED]
46
+ return c != null && typeof c == 'object'
47
+ }
48
+
49
+ /** Which links count as work this task is waiting on. */
50
+ export type DepOpts = {
51
+ /** the relation tags to follow. Default: `requires` and `contains`. */
52
+ relations?: string[]
53
+ }
54
+
55
+ // The other ends of every edge with any of these relations touching `eid` at
56
+ // `at`, deduplicated: `from` follows edges away from it, `to` edges into it.
57
+ // Read the matching edges together, so one end linked by two relations costs
58
+ // only one read.
59
+ let ends = (
60
+ tx: Tx,
61
+ eid: Eid,
62
+ rels: string[],
63
+ at: 'from' | 'to',
64
+ ): Eid[] | Promise<Eid[]> => {
65
+ if (!rels.length) return []
66
+ let far = at == 'from' ? 'to' : 'from'
67
+ return after(
68
+ tx.read(and(eq(`${EDGE}.${at}`, eid), or(...rels.map(present)))),
69
+ (bundles) => {
70
+ let seen = new Set<Eid>()
71
+ for (let b of bundles) {
72
+ let end = (b[EDGE] as Record<string, unknown> | undefined)?.[far]
73
+ if (typeof end == 'string') seen.add(end)
74
+ }
75
+ return [...seen]
76
+ },
77
+ )
78
+ }
79
+
80
+ /**
81
+ * What this task waits on: the far ends of its `requires` and `contains`
82
+ * edges, settled or not.
83
+ *
84
+ * ```ts
85
+ * import { dependencies } from '@yaks/task'
86
+ *
87
+ * // dependencies(graph, 'p') // → ['a', 'b']
88
+ * ```
89
+ */
90
+ export let dependencies = (
91
+ { storage }: Pick<Graph, 'storage'>,
92
+ eid: Eid,
93
+ opts: DepOpts = {},
94
+ ): Eid[] | Promise<Eid[]> =>
95
+ ends(detached(storage), eid, opts.relations ?? [REQUIRES, CONTAINS], 'from')
96
+
97
+ /**
98
+ * What waits on this task: the near ends of the `requires` and `contains`
99
+ * edges leading to it, the tasks its finishing may free.
100
+ *
101
+ * ```ts
102
+ * import { dependents } from '@yaks/task'
103
+ *
104
+ * // dependents(graph, 'a') // → ['p']
105
+ * ```
106
+ */
107
+ export let dependents = (
108
+ { storage }: Pick<Graph, 'storage'>,
109
+ eid: Eid,
110
+ opts: DepOpts = {},
111
+ ): Eid[] | Promise<Eid[]> =>
112
+ ends(detached(storage), eid, opts.relations ?? [REQUIRES, CONTAINS], 'to')
113
+
114
+ /**
115
+ * How many of this task's children are still unfinished — the calm "3 left"
116
+ * count, never an alarm. Follows `requires` and `contains` out of the task and
117
+ * counts the far ends that have not settled; a child that is not a task cannot
118
+ * settle and so counts as open. Zero is the ordinary answer, and renders as
119
+ * nothing.
120
+ *
121
+ * ```ts
122
+ * import { openDeps } from '@yaks/task'
123
+ *
124
+ * // openDeps(graph, 't1') // → 2
125
+ * ```
126
+ */
127
+ export let openDeps = (
128
+ { storage, vocab }: Pick<Graph, 'storage' | 'vocab'>,
129
+ eid: Eid,
130
+ opts: DepOpts = {},
131
+ ): number | Promise<number> => {
132
+ let tx = detached(storage)
133
+ let marks = statusComps(vocab)
134
+ return after(
135
+ ends(tx, eid, opts.relations ?? [REQUIRES, CONTAINS], 'from'),
136
+ (kids) =>
137
+ kids.length == 0 ? 0 : after(tx.get(kids, marks), (bundles) => {
138
+ // Counted by what has settled, so a child the storage does not hold —
139
+ // and which therefore cannot be shown to have finished — stays counted.
140
+ let done = bundles.filter((b) => settled(statusOf(vocab, b))).length
141
+ return kids.length - done
142
+ }),
143
+ ) as number | Promise<number>
144
+ }
145
+
146
+ /**
147
+ * Has this task settled and finished its dependencies? Completion alone does
148
+ * not release a parent while `requires` or `contains` children remain open.
149
+ * Like {@link openDeps}, this counts direct far ends, not a recursive walk.
150
+ * A missing entity, or an entity without a `task` component, is never done.
151
+ *
152
+ * Synchronous storage returns a boolean; asynchronous storage returns a
153
+ * promise.
154
+ */
155
+ export let done = (
156
+ held: Pick<Graph, 'storage' | 'vocab'>,
157
+ eid: Eid,
158
+ opts: DepOpts = {},
159
+ ): boolean | Promise<boolean> =>
160
+ after(held.storage.get([eid], statusComps(held.vocab)), (bundles) => {
161
+ if (!bundles[0] || !settled(statusOf(held.vocab, bundles[0]))) return false
162
+ return after(openDeps(held, eid, opts), (count) => count == 0)
163
+ }) as boolean | Promise<boolean>
package/graph.js ADDED
@@ -0,0 +1,9 @@
1
+ // What the graph does with a write about a to-do item: the module a server
2
+ // imports as `@yaks/task/graph`. The status is neither written nor checked
3
+ // here; it is computed, and that half is in ./vocab.ts. Who completed a task is
4
+ // kept by @yaks/kernel's rules.
5
+ import { tasks } from "./plugin.js";
6
+ /** The task components. */ export let plugins = ()=>[
7
+ tasks()
8
+ ];
9
+ //# sourceMappingURL=graph.js.map
package/graph.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph.js","sources":["./graph.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,2EAA2E;AAC3E,gFAAgF;AAChF,gCAAgC;AAGhC,SAAS,KAAK,sBAAqB;AAEnC,yBAAyB,GACzB,OAAO,IAAI,UAAU,IAAgB;IAAC;GAAQ,CAAA"}
package/graph.ts ADDED
@@ -0,0 +1,10 @@
1
+ // What the graph does with a write about a to-do item: the module a server
2
+ // imports as `@yaks/task/graph`. The status is neither written nor checked
3
+ // here; it is computed, and that half is in ./vocab.ts. Who completed a task is
4
+ // kept by @yaks/kernel's rules.
5
+
6
+ import type { Plugin } from 'jsr:@yaks/graph@0.2.36'
7
+ import { tasks } from './plugin.js'
8
+
9
+ /** The task components. */
10
+ export let plugins = (): Plugin[] => [tasks()]
package/inspect.js ADDED
@@ -0,0 +1,131 @@
1
+ /**
2
+ * How a task reads in the inspector (@yaks/inspect), registered in this
3
+ * package's `/views` facet ahead of the page any entity has: its title, and
4
+ * under it where it stands (its status, read through the vocabulary's ladder,
5
+ * its priority, project and assignee, what it is blocked on); what it asks,
6
+ * in full; what was said about it (the comments aimed at it, oldest first,
7
+ * each by who wrote it and when); then the parts any page has (`io.show`),
8
+ * what requires what among its links. A note left in the inspector, a comment
9
+ * that is also a task, shows under its heading rather than among the
10
+ * comments.
11
+ *
12
+ * @module
13
+ */ /* @ts-types="npm:@types/react@19.3.0" */ import { createElement as h } from "react";
14
+ import { Markdown } from "@yaks/markdown";
15
+ import { parse } from "@yaks/query";
16
+ import * as ui from "@yaks/ui";
17
+ import { mention, Part, useNamed, usePageNotes } from "@yaks/inspect";
18
+ import { TASK } from "./comp.js";
19
+ import { statusOf } from "./words.js";
20
+ /** How many comments a task's page reads. */ export let COMMENTS = 100;
21
+ let comp = (b, name)=>b?.[name] ?? {};
22
+ let str = (b, name, prop)=>{
23
+ let v = comp(b, name)[prop];
24
+ return typeof v == 'string' ? v : '';
25
+ };
26
+ let rows = (a)=>a?.rows ?? [];
27
+ // Where a task stands, in a line.
28
+ let standing = (io, e)=>{
29
+ let status = statusOf(io.vocab, e) || str(e, TASK, 'status') || 'open';
30
+ let filed = comp(e, 'filed');
31
+ let priority = filed.priority;
32
+ let project = str(e, 'filed', 'project');
33
+ let assignee = str(e, 'filed', 'assignee');
34
+ let on = str(e, 'blocked', 'on');
35
+ return [
36
+ status,
37
+ priority != null ? ` · P${priority}` : null,
38
+ project ? [
39
+ ' · in ',
40
+ mention(io, project)
41
+ ] : null,
42
+ assignee ? [
43
+ ' · for ',
44
+ mention(io, assignee)
45
+ ] : null,
46
+ on ? [
47
+ ' · blocked on ',
48
+ on
49
+ ] : null
50
+ ];
51
+ };
52
+ /** What was said about a task: the comments aimed at it, oldest first. */ let Comments = ({ e, io, notes })=>{
53
+ let eid = e.entity.eid;
54
+ let got = io.ask({
55
+ comments: `.comment.target=${eid}&*&.order=created.at&.limit=${COMMENTS}`
56
+ });
57
+ // A note left in the inspector is a comment that is also a task; it shows
58
+ // under the heading it was left under instead.
59
+ let all = rows(got.comments).filter((b)=>!b[TASK]);
60
+ useNamed(io, all.map((b)=>str(b, 'created', 'by')));
61
+ if (got.comments?.ready && !all.length) return null;
62
+ return /*#__PURE__*/ h(Part, {
63
+ io,
64
+ eid,
65
+ subject: io.id(e),
66
+ heading: 'Comments',
67
+ count: got.comments?.ready ? all.length : undefined,
68
+ notes
69
+ }, got.comments?.error ? /*#__PURE__*/ h(ui.Rows.More, {}, got.comments.error) : !got.comments?.ready && !all.length ? /*#__PURE__*/ h(ui.Loading, {}) : /*#__PURE__*/ h(ui.Notes, {}, all.map((b)=>io.show(b, 'Task.Comment', {}))));
70
+ };
71
+ /** A comment's reading in a task, chosen through the same registry as its page. */ export let TaskComment = ({ e: b, io })=>{
72
+ let by = str(b, 'created', 'by');
73
+ let at = str(b, 'created', 'at');
74
+ useNamed(io, [
75
+ by
76
+ ]);
77
+ return /*#__PURE__*/ h(ui.Notes.Item, {
78
+ 'data-comment': b.entity.eid
79
+ }, /*#__PURE__*/ h(ui.Notes.Text, {}, /*#__PURE__*/ h(Markdown, {
80
+ source: str(b, 'doc', 'body') || str(b, 'doc', 'title')
81
+ })), /*#__PURE__*/ h(ui.Notes.Who, {}, by ? mention(io, by) : ''), /*#__PURE__*/ h(ui.Notes.When, {}, /*#__PURE__*/ h('a', {
82
+ href: io.link(b.entity.eid),
83
+ title: at
84
+ }, io.when(at))));
85
+ };
86
+ /** A task's page. */ export let TaskPage = ({ e, io })=>{
87
+ let notes = usePageNotes(io, e, [
88
+ 'Comments'
89
+ ]);
90
+ useNamed(io, [
91
+ str(e, 'filed', 'project'),
92
+ str(e, 'filed', 'assignee')
93
+ ]);
94
+ return /*#__PURE__*/ h('div', {
95
+ 'data-inspect': e.entity.eid
96
+ }, io.show(e, 'Inspect.Head', {
97
+ sub: standing(io, e),
98
+ notes: notes.get('')
99
+ }), io.show(e, 'Inspect.Body'), /*#__PURE__*/ h(Comments, {
100
+ e,
101
+ io,
102
+ notes
103
+ }), io.show(e, 'Inspect.Facts', {
104
+ notes,
105
+ skip: [
106
+ TASK,
107
+ 'filed',
108
+ 'blocked'
109
+ ]
110
+ }), io.show(e, 'Inspect.Links', {
111
+ notes,
112
+ skip: [
113
+ 'comment.target'
114
+ ]
115
+ }), io.show(e, 'Inspect.History', {
116
+ notes
117
+ }));
118
+ };
119
+ /** The page this package draws in the inspector. */ export let inspectViews = [
120
+ {
121
+ view: 'Task.Comment',
122
+ match: parse('.comment'),
123
+ Render: TaskComment
124
+ },
125
+ {
126
+ view: 'Inspect.Page',
127
+ match: parse(`.${TASK}`),
128
+ Render: TaskPage
129
+ }
130
+ ];
131
+ //# sourceMappingURL=inspect.js.map
package/inspect.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inspect.js","sources":["./inspect.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;CAYC,GAED,uCAAuC,GAAG,SAAS,iBAAiB,CAAC,gBAAoD;AACzH,SAAS,QAAQ,8BAAmC;AACpD,SAAS,KAAK,2BAAgC;AAC9C,YAAY,wBAA6B;AACzC,SAIE,OAAO,EACP,IAAI,EAEJ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jB,EAAC;AAED,mBAAmB,GACnB,OAAO,IAAI,WAAW,CAAC,EAAE,CAAC,EAAE,EAAE,EAAS;EACrC,IAAI,QAAQ,aAAa,IAAI,GAAG;IAAC;GAAW;EAC5C,SAAS,IAAI;IAAC,IAAI,GAAG,SAAS;IAAY,IAAI,GAAG,SAAS;GAAY;EACtE,qBAAO,EACL,OACA;IAAE,gBAAgB,EAAE,MAAM,CAAC,GAAG;EAAC,GAC/B,GAAG,IAAI,CAAC,GAAG,gBAAgB;IAAE,KAAK,SAAS,IAAI;IAAI,OAAO,MAAM,GAAG,CAAC;EAAI,IACxE,GAAG,IAAI,CAAC,GAAG,+BACX,EAAE,UAAU;IAAE;IAAG;IAAI;EAAM,IAC3B,GAAG,IAAI,CAAC,GAAG,iBAAiB;IAAE;IAAO,MAAM;MAAC;MAAM;MAAS;KAAU;EAAC,IACtE,GAAG,IAAI,CAAC,GAAG,iBAAiB;IAAE;IAAO,MAAM;MAAC;KAAiB;EAAC,IAC9D,GAAG,IAAI,CAAC,GAAG,mBAAmB;IAAE;EAAM;AAE1C,EAAC;AAED,kDAAkD,GAClD,OAAO,IAAI,eAAuB;EAChC;IAAE,MAAM;IAAgB,OAAO,MAAM;IAAa,QAAQ;EAAY;EACtE;IAAE,MAAM;IAAgB,OAAO,MAAM,CAAC,CAAC,EAAE,MAAM;IAAG,QAAQ;EAAS;CACpE,CAAA"}
package/inspect.ts ADDED
@@ -0,0 +1,144 @@
1
+ /**
2
+ * How a task reads in the inspector (@yaks/inspect), registered in this
3
+ * package's `/views` facet ahead of the page any entity has: its title, and
4
+ * under it where it stands (its status, read through the vocabulary's ladder,
5
+ * its priority, project and assignee, what it is blocked on); what it asks,
6
+ * in full; what was said about it (the comments aimed at it, oldest first,
7
+ * each by who wrote it and when); then the parts any page has (`io.show`),
8
+ * what requires what among its links. A note left in the inspector, a comment
9
+ * that is also a task, shows under its heading rather than among the
10
+ * comments.
11
+ *
12
+ * @module
13
+ */
14
+
15
+ /* @ts-types="npm:@types/react@19.3.0" */ import { createElement as h, type JSX, type ReactNode } from 'react'
16
+ import { Markdown } from '@yaks/markdown'
17
+ import { parse } from '@yaks/query'
18
+ import * as ui from '@yaks/ui'
19
+ import {
20
+ type Answer,
21
+ type Bundle,
22
+ type Io,
23
+ mention,
24
+ Part,
25
+ type Props,
26
+ useNamed,
27
+ usePageNotes,
28
+ type View,
29
+ } from '@yaks/inspect'
30
+ import { TASK } from './comp.js'
31
+ import { statusOf } from './words.js'
32
+
33
+ /** How many comments a task's page reads. */
34
+ export let COMMENTS = 100
35
+
36
+ type Comp = Record<string, unknown>
37
+ let comp = (b: Bundle | undefined, name: string): Comp =>
38
+ (b?.[name] ?? {}) as Comp
39
+ let str = (b: Bundle | undefined, name: string, prop: string): string => {
40
+ let v = comp(b, name)[prop]
41
+ return typeof v == 'string' ? v : ''
42
+ }
43
+ let rows = (a?: Answer): Bundle[] => a?.rows ?? []
44
+
45
+ // Where a task stands, in a line.
46
+ let standing = (io: Io, e: Bundle): ReactNode[] => {
47
+ let status = statusOf(io.vocab, e) || str(e, TASK, 'status') || 'open'
48
+ let filed = comp(e, 'filed')
49
+ let priority = filed.priority
50
+ let project = str(e, 'filed', 'project')
51
+ let assignee = str(e, 'filed', 'assignee')
52
+ let on = str(e, 'blocked', 'on')
53
+ return [
54
+ status,
55
+ priority != null ? ` · P${priority}` : null,
56
+ project ? [' · in ', mention(io, project)] : null,
57
+ assignee ? [' · for ', mention(io, assignee)] : null,
58
+ on ? [' · blocked on ', on] : null,
59
+ ]
60
+ }
61
+
62
+ /** What was said about a task: the comments aimed at it, oldest first. */
63
+ let Comments = (
64
+ { e, io, notes }: { e: Bundle; io: Io; notes: Map<string, Bundle[]> },
65
+ ): JSX.Element | null => {
66
+ let eid = e.entity.eid
67
+ let got = io.ask({
68
+ comments: `.comment.target=${eid}&*&.order=created.at&.limit=${COMMENTS}`,
69
+ })
70
+ // A note left in the inspector is a comment that is also a task; it shows
71
+ // under the heading it was left under instead.
72
+ let all = rows(got.comments).filter((b) => !b[TASK])
73
+ useNamed(io, all.map((b) => str(b, 'created', 'by')))
74
+ if (got.comments?.ready && !all.length) return null
75
+ return h(
76
+ Part,
77
+ {
78
+ io,
79
+ eid,
80
+ subject: io.id(e),
81
+ heading: 'Comments',
82
+ count: got.comments?.ready ? all.length : undefined,
83
+ notes,
84
+ },
85
+ got.comments?.error
86
+ ? h(ui.Rows.More, {}, got.comments.error)
87
+ : !got.comments?.ready && !all.length
88
+ ? h(ui.Loading, {})
89
+ : h(
90
+ ui.Notes,
91
+ {},
92
+ all.map((b) => io.show(b, 'Task.Comment', {})),
93
+ ),
94
+ )
95
+ }
96
+
97
+ /** A comment's reading in a task, chosen through the same registry as its page. */
98
+ export let TaskComment = ({ e: b, io }: Props): JSX.Element => {
99
+ let by = str(b, 'created', 'by')
100
+ let at = str(b, 'created', 'at')
101
+ useNamed(io, [by])
102
+ return h(
103
+ ui.Notes.Item,
104
+ { 'data-comment': b.entity.eid },
105
+ h(
106
+ ui.Notes.Text,
107
+ {},
108
+ h(Markdown, {
109
+ source: str(b, 'doc', 'body') || str(b, 'doc', 'title'),
110
+ }),
111
+ ),
112
+ h(ui.Notes.Who, {}, by ? mention(io, by) : ''),
113
+ h(
114
+ ui.Notes.When,
115
+ {},
116
+ h('a', {
117
+ href: io.link(b.entity.eid),
118
+ title: at,
119
+ }, io.when(at)),
120
+ ),
121
+ )
122
+ }
123
+
124
+ /** A task's page. */
125
+ export let TaskPage = ({ e, io }: Props): JSX.Element => {
126
+ let notes = usePageNotes(io, e, ['Comments'])
127
+ useNamed(io, [str(e, 'filed', 'project'), str(e, 'filed', 'assignee')])
128
+ return h(
129
+ 'div',
130
+ { 'data-inspect': e.entity.eid },
131
+ io.show(e, 'Inspect.Head', { sub: standing(io, e), notes: notes.get('') }),
132
+ io.show(e, 'Inspect.Body'),
133
+ h(Comments, { e, io, notes }),
134
+ io.show(e, 'Inspect.Facts', { notes, skip: [TASK, 'filed', 'blocked'] }),
135
+ io.show(e, 'Inspect.Links', { notes, skip: ['comment.target'] }),
136
+ io.show(e, 'Inspect.History', { notes }),
137
+ )
138
+ }
139
+
140
+ /** The page this package draws in the inspector. */
141
+ export let inspectViews: View[] = [
142
+ { view: 'Task.Comment', match: parse('.comment'), Render: TaskComment },
143
+ { view: 'Inspect.Page', match: parse(`.${TASK}`), Render: TaskPage },
144
+ ]
package/mod.js ADDED
@@ -0,0 +1,71 @@
1
+ /**
2
+ * @yaks/task — a to-do list as a set of components for a
3
+ * {@link https://jsr.io/@yaks/graph | @yaks/graph}.
4
+ *
5
+ * Say a team keeps a list of what it has to do. Four things come up, and this
6
+ * package is the four answers:
7
+ *
8
+ * - **What is on the list?** An entity with a `task{}` component is a to-do
9
+ * item. `task` is one component among the entity's others, not a record type
10
+ * of its own: the same entity also carries your `doc`, your `estimate`,
11
+ * anything else it is — adding `task` to something makes it something to do
12
+ * without making it stop being what it was. @yaks/project's optional
13
+ * `filed{project, priority, domain, assignee}` places it in a portfolio.
14
+ * - **Where does it stand?** No stored property holds the answer. A task with a
15
+ * `completed` component (@yaks/kernel's mark) is done, one with `cancelled`
16
+ * is cancelled, one with `started` is wip, and one with none is open. `status` is computed from
17
+ * those components, so finishing something records when and by whom instead
18
+ * of overwriting a value, and reopening it means removing a component rather
19
+ * than guessing what the status used to be.
20
+ * - **How do you look at the list?** A `board{query}` is a saved filter. Its
21
+ * membership is never stored — no row records that a task is on a board — so
22
+ * a board is always current, and a task that starts matching the query is on
23
+ * it. The empty query selects nothing, on purpose.
24
+ * - **What is it waiting for?** `requires` and `contains` relate one task to
25
+ * another through {@link https://jsr.io/@yaks/edge | @yaks/edge}, and
26
+ * `blocked{on}` records that something outside the graph is in the way.
27
+ *
28
+ * ## Blocked is not a status
29
+ * There is no `blocked` status, and that is a decision rather than an omission.
30
+ * A blocked task is still open work: rolling it into the status would hide it
31
+ * from every query for open work exactly when somebody needs to see it. So
32
+ * `blocked` is a component read by {@link gated}, and unfinished children are
33
+ * an ordinary count read by {@link openDeps} — "3 left", never an alarm.
34
+ *
35
+ * ## The status rule is written once
36
+ * The rule is data in the vocabulary: `task` declares its status as a ladder
37
+ * of marks (`"status": {"cancelled": "cancelled", "completed": "done",
38
+ * "started": "wip", "default": "open"}`, @yaks/vocab's `status` keyword). @yaks/sql and
39
+ * @yaks/match read it from that declaration, so a saved filter selects the
40
+ * same tasks in a database and in a page, and {@link statusOf} reads it off an
41
+ * entity in hand. A graph that leases its tasks adds a rung where it declares
42
+ * the lease: @yaks/session reads a held claim as `wip`.
43
+ *
44
+ * ## Use
45
+ * ```ts
46
+ * import { loadVocab } from '@yaks/vocab'
47
+ * import { graph } from '@yaks/graph'
48
+ * import { ram } from '@yaks/ram'
49
+ * import { kernel, kernelDoc, kernelKeywords } from '@yaks/kernel'
50
+ * import { edgeDoc, edgeKeywords, edges } from '@yaks/edge'
51
+ * import { taskDoc, tasks } from '@yaks/task'
52
+ *
53
+ * let vocab = loadVocab([kernelDoc, edgeDoc, taskDoc], [
54
+ * kernelKeywords,
55
+ * edgeKeywords,
56
+ * ])
57
+ * let plugins = [kernel(), edges(vocab), tasks()]
58
+ * let g = graph({ storage: ram(vocab), vocab, plugins })
59
+ * await g.apply([{ entity: { eid: 't1' }, task: {}, completed: {} }])
60
+ * ```
61
+ *
62
+ * It imports no platform API, so the same list runs on a server, in a worker,
63
+ * and in a browser tab.
64
+ *
65
+ * @module
66
+ */ export * from "./words.js";
67
+ export * from "./comp.js";
68
+ export * from "./deps.js";
69
+ export * from "./plugin.js";
70
+ export { answer, asked, DECISION_SETTLED, showing, shown, waiting } from "./decision.js";
71
+ //# sourceMappingURL=mod.js.map
package/mod.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.js","sources":["./mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiEC,GAED,2BAA0B;AAC1B,0BAAyB;AACzB,0BAAyB;AACzB,4BAA2B;AAE3B,SACE,MAAM,EACN,KAAK,EAGL,gBAAgB,EAChB,OAAO,EAEP,KAAK,EACL,OAAO,wBACa"}