@composable-os/pack-dailychecks 0.0.0-stage → 0.1.0-beta.13

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/LICENSE ADDED
@@ -0,0 +1,109 @@
1
+ # Functional Source License, Version 1.1, ALv2 Future License
2
+
3
+ > This licence covers the repository except the directories listed in NOTICE. In particular, the
4
+ > assistant packages `packages/agent-*` (agent-core, agent-a2ui, agent-voice, agent-plugins) are
5
+ > licensed under the MIT License; see the LICENSE file in each of those directories (ADR 0350).
6
+
7
+ ## Abbreviation
8
+
9
+ FSL-1.1-ALv2
10
+
11
+ ## Notice
12
+
13
+ Copyright 2026 Tim O'Connell
14
+
15
+ ## Terms and Conditions
16
+
17
+ ### Licensor ("We")
18
+
19
+ The party offering the Software under these Terms and Conditions.
20
+
21
+ ### The Software
22
+
23
+ The "Software" is each version of the software that we make available under
24
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
25
+ Conditions with the Software.
26
+
27
+ ### License Grant
28
+
29
+ Subject to your compliance with this License Grant and the Patents,
30
+ Redistribution and Trademark clauses below, we hereby grant you the right to
31
+ use, copy, modify, create derivative works, publicly perform, publicly display
32
+ and redistribute the Software for any Permitted Purpose identified below.
33
+
34
+ ### Permitted Purpose
35
+
36
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
37
+ means making the Software available to others in a commercial product or
38
+ service that:
39
+
40
+ 1. substitutes for the Software;
41
+
42
+ 2. substitutes for any other product or service we offer using the Software
43
+ that exists as of the date we make the Software available; or
44
+
45
+ 3. offers the same or substantially similar functionality as the Software.
46
+
47
+ Permitted Purposes specifically include using the Software:
48
+
49
+ 1. for your internal use and access;
50
+
51
+ 2. for non-commercial education;
52
+
53
+ 3. for non-commercial research; and
54
+
55
+ 4. in connection with professional services that you provide to a licensee
56
+ using the Software in accordance with these Terms and Conditions.
57
+
58
+ ### Patents
59
+
60
+ To the extent your use for a Permitted Purpose would necessarily infringe our
61
+ patents, the license grant above includes a license under our patents. If you
62
+ make a claim against any party that the Software infringes or contributes to
63
+ the infringement of any patent, then your patent license to the Software ends
64
+ immediately.
65
+
66
+ ### Redistribution
67
+
68
+ The Terms and Conditions apply to all copies, modifications and derivatives of
69
+ the Software.
70
+
71
+ If you redistribute any copies, modifications or derivatives of the Software,
72
+ you must include a copy of or a link to these Terms and Conditions and not
73
+ remove any copyright notices provided in or with the Software.
74
+
75
+ ### Disclaimer
76
+
77
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
78
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
79
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
80
+
81
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
82
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
83
+ EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
84
+
85
+ ### Trademarks
86
+
87
+ Except for displaying the License Details and identifying us as the origin of
88
+ the Software, you have no right under these Terms and Conditions to use our
89
+ trademarks, trade names, service marks or product names.
90
+
91
+ ## Grant of Future License
92
+
93
+ We hereby irrevocably grant you an additional license to use the Software under
94
+ the Apache License, Version 2.0 that is effective on the second anniversary of
95
+ the date we make the Software available. On or after that date, you may use the
96
+ Software under the Apache License, Version 2.0, in which case the following
97
+ will apply:
98
+
99
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
100
+ this file except in compliance with the License.
101
+
102
+ You may obtain a copy of the License at
103
+
104
+ http://www.apache.org/licenses/LICENSE-2.0
105
+
106
+ Unless required by applicable law or agreed to in writing, software distributed
107
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
108
+ CONDITIONS OF ANY KIND, either express or implied. See the License for the
109
+ specific language governing permissions and limitations under the License.
@@ -0,0 +1,8 @@
1
+ import { type DailyChecksHooks } from "@composable-os/pack-dailychecks/client";
2
+ export type HistoryHooks = Pick<DailyChecksHooks, "useHistory" | "useDay">;
3
+ export declare function ChecklistHistory({ dailychecks, locale, days, }: {
4
+ dailychecks: HistoryHooks;
5
+ locale?: string;
6
+ /** How many days back the list starts with (at most 62). */
7
+ days?: number;
8
+ }): import("react").JSX.Element;
@@ -0,0 +1,38 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // How each day went (ADR 0651), for those who manage checklists: every checklist done on its own,
3
+ // day by day, done (by whom, for whom, when, and whether after its due time) or missed (with the
4
+ // steps nobody ticked). Opening a day shows its steps and who ticked each and when. Read-only: a
5
+ // finished or missed day never changes, and today's is ticked on Today's checklists.
6
+ //
7
+ // The host decides who reads this (checklists:write); anyone else is refused and sees that state.
8
+ // What someone wrote on a step is kept no longer than it is on screen (`gcTime: 0`).
9
+ import { addDays, dateLabel, dayRefusal, dayStateLabel, stepsOf, tickLabel, timeIn, } from "@composable-os/pack-dailychecks/client";
10
+ import { useId, useState } from "react";
11
+ import { Button } from "../ui-button/button.js";
12
+ /** Today in the browser's zone: only a starting point for the dates shown; the host decides. */
13
+ function localToday() {
14
+ return new Intl.DateTimeFormat("en-CA").format(new Date());
15
+ }
16
+ export function ChecklistHistory({ dailychecks, locale = "en-AU", days = 14, }) {
17
+ const id = useId();
18
+ const [to, setTo] = useState(localToday);
19
+ const span = Math.min(Math.max(days, 1), 62);
20
+ const from = addDays(to, -(span - 1));
21
+ const answer = dailychecks.useHistory({ from, to });
22
+ const [open, setOpen] = useState(null);
23
+ const data = answer.data;
24
+ return (_jsxs("section", { className: "grid gap-3", "aria-labelledby": `${id}-title`, children: [_jsx("h2", { id: `${id}-title`, className: "text-lg font-semibold", children: "Checklist history" }), _jsxs("div", { className: "flex flex-wrap items-end gap-2", children: [_jsxs("label", { className: "grid gap-1 text-sm", htmlFor: `${id}-to`, children: [_jsx("span", { children: "Up to" }), _jsx("input", { id: `${id}-to`, type: "date", className: "rounded-md border px-2 py-1", value: to, onChange: (e) => e.target.value && setTo(e.target.value) })] }), _jsx(Button, { type: "button", variant: "outline", onClick: () => setTo(addDays(to, -span)), children: "Earlier" })] }), answer.isPending ? _jsx("p", { "aria-busy": "true", children: "Loading how each day went\u2026" }) : null, answer.error ? (_jsx("p", { role: "alert", "data-refusal": dayRefusal(answer.error).kind, children: dayRefusal(answer.error).message })) : null, data && !data.days.length ? (_jsx("p", { "data-empty": "history", children: "No checklist was due in these days." })) : null, data?.days.length ? (_jsxs("table", { className: "w-full text-sm", children: [_jsx("thead", { children: _jsxs("tr", { className: "text-left", children: [_jsx("th", { scope: "col", children: "Day" }), _jsx("th", { scope: "col", children: "Checklist" }), _jsx("th", { scope: "col", children: "How it went" }), _jsx("th", { scope: "col", children: "Steps" }), _jsx("th", { scope: "col", children: _jsx("span", { className: "sr-only", children: "Open" }) })] }) }), _jsx("tbody", { children: data.days.map((d) => (_jsxs("tr", { "data-history-run": d.run, "data-state": d.state, children: [_jsx("td", { children: dateLabel(d.date, locale) }), _jsx("td", { children: d.template.name }), _jsxs("td", { children: [dayStateLabel(d.state), d.state === "done" && d.finishedBy
25
+ ? ` by ${d.finishedBy}${d.finishedFor ? ` for ${d.finishedFor}` : ""}${d.finishedAt ? ` at ${timeIn(d.finishedAt, data.zone, locale)}` : ""}`
26
+ : "", d.late ? (d.state === "done" ? " (after it was due)" : " (past due)") : "", d.missed.length ? ` · Not done: ${d.missed.join("; ")}` : "", d.notDone
27
+ ? ` · ${d.notDone} ${d.notDone === 1 ? "step" : "steps"} ticked not done`
28
+ : "", d.onBehalf ? ` · ${d.onBehalf} ticked for someone` : ""] }), _jsxs("td", { children: [d.ticked, " of ", d.steps] }), _jsx("td", { children: _jsx(Button, { type: "button", variant: "outline", "aria-label": `Open ${d.template.name} on ${dateLabel(d.date, locale)}`, onClick: () => setOpen(open?.run === d.run ? null : d), children: open?.run === d.run ? "Close" : "Open" }) })] }, d.run))) })] })) : null, data?.truncated ? (_jsx("p", { className: "text-xs", children: "Only the latest 500 are shown: choose fewer days." })) : null, open && data ? (_jsx(DayDetail, { hooks: dailychecks, day: open, zone: data.zone, locale: locale })) : null] }));
29
+ }
30
+ function DayDetail({ hooks, day, zone, locale, }) {
31
+ const answer = hooks.useDay({ template: day.template.id, date: day.date });
32
+ const item = answer.data?.item;
33
+ return (_jsxs("section", { className: "grid gap-2 rounded-md border p-3 text-sm", "aria-label": `${day.template.name} on ${dateLabel(day.date, locale)}`, "data-history-detail": day.run, children: [_jsxs("h3", { className: "font-medium", children: [day.template.name, ", ", dateLabel(day.date, locale)] }), answer.isPending ? _jsx("p", { "aria-busy": "true", children: "Loading\u2026" }) : null, answer.error ? _jsx("p", { role: "alert", children: dayRefusal(answer.error).message }) : null, item ? (_jsx("ol", { className: "grid gap-1", children: stepsOf(item).map((s) => (_jsxs("li", { "data-step": s.position, children: [_jsx("span", { className: "font-medium", children: s.text }), s.tick
34
+ ? ` · ${tickLabel(s.tick)} at ${timeIn(s.tick.at, zone, locale)}${s.tick.why ? ` · Why: ${s.tick.why}` : ""}${s.tick.note ? ` · Note: ${s.tick.note}` : ""}${s.tick.onBehalfWhy ? ` · For them because: ${s.tick.onBehalfWhy}` : ""}`
35
+ : s.missed
36
+ ? " · Missed"
37
+ : " · Not ticked"] }, s.position))) })) : null, item?.run?.closedWhy ? (_jsxs("p", { className: "text-xs", children: ["Finished for them because: ", item.run.closedWhy] })) : null] }));
38
+ }
@@ -0,0 +1,6 @@
1
+ import { type DailyChecksHooks } from "@composable-os/pack-dailychecks/client";
2
+ export type TodayHooks = Pick<DailyChecksHooks, "useToday" | "useTick" | "useDone">;
3
+ export declare function TodaysChecklistsScreen({ dailychecks, locale, }: {
4
+ dailychecks: TodayHooks;
5
+ locale?: string;
6
+ }): import("react").JSX.Element;
@@ -0,0 +1,92 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // Today's checklists in the app (ADR 0651): the same as the web's, over the native base. The
3
+ // checklists done on their own that are due today and that the viewer may do; anyone who may do
4
+ // one ticks its steps (done, with a note where the step asks; not done, with why), and whoever
5
+ // ticks the last step finishes it, which is final. The host decides what is due, who may do it and
6
+ // when it is finished: this shows its answer and its refusals. Ticking for someone else is on the
7
+ // web (those who manage checklists use the admin).
8
+ //
9
+ // What someone writes on a step is private: kept only in this screen's state, sent with
10
+ // `forgetAfter`, and cleared when the app goes to the background (so the app switcher's snapshot
11
+ // never shows it). Today's checklists are kept no longer than they are shown.
12
+ import { dayRefusal, dayStateLabel, finishedLabel, forgetAfter, stepsOf, tickLabel, timeIn, } from "@composable-os/pack-dailychecks/client";
13
+ import { useEffect, useState } from "react";
14
+ import { AppState, View } from "react-native";
15
+ import { Button } from "../native-base/button.js";
16
+ import { Field } from "../native-base/field.js";
17
+ import { Screen } from "../native-base/screen.js";
18
+ import { Text } from "../native-base/text.js";
19
+ const EMPTY = { note: "", why: "", notDone: false };
20
+ export function TodaysChecklistsScreen({ dailychecks, locale = "en-AU", }) {
21
+ const answer = dailychecks.useToday();
22
+ const [hidden, setHidden] = useState(false);
23
+ const [epoch, setEpoch] = useState(0);
24
+ useEffect(() => {
25
+ const listener = AppState.addEventListener("change", (state) => {
26
+ if (state !== "active") {
27
+ setHidden(true);
28
+ setEpoch((e) => e + 1);
29
+ }
30
+ else {
31
+ void Promise.resolve(answer.refetch?.()).then(() => setHidden(false));
32
+ }
33
+ });
34
+ return () => listener.remove();
35
+ }, [answer.refetch]);
36
+ const data = hidden ? undefined : answer.data;
37
+ // In the app a person does their own: the ones they may do (someone who manages checklists
38
+ // ticks for others in the admin).
39
+ const items = data?.items.filter((item) => item.mayDo) ?? [];
40
+ return (_jsxs(Screen, { title: "Today's checklists", children: [answer.isPending || hidden ? (_jsx(Text, { tone: "muted", accessibilityRole: "progressbar", children: "Loading today's checklists\u2026" })) : null, answer.error ? (_jsx(Text, { tone: "danger", accessibilityRole: "alert", children: dayRefusal(answer.error).message })) : null, data && !items.length ? _jsx(Text, { children: "Nothing is due for you today." }) : null, data
41
+ ? items.map((item) => (_jsx(DayChecklistNative, { hooks: dailychecks, item: item, zone: data.zone, you: data.you, locale: locale, refetch: () => answer.refetch?.() }, `${item.template.id}:${epoch}`)))
42
+ : null] }));
43
+ }
44
+ function DayChecklistNative({ hooks, item, zone, you, locale, refetch, }) {
45
+ const tick = hooks.useTick();
46
+ const done = hooks.useDone();
47
+ const [drafts, setDrafts] = useState({});
48
+ const [refusal, setRefusal] = useState(null);
49
+ const [said, setSaid] = useState(null);
50
+ const busy = tick.isPending || done.isPending;
51
+ const steps = stepsOf(item);
52
+ // In the app a person ticks only for themselves.
53
+ const canTick = item.canTick && item.mayDo;
54
+ const draftOf = (p) => drafts[p] ?? EMPTY;
55
+ const setDraft = (p, patch) => setDrafts((d) => ({ ...d, [p]: { ...(d[p] ?? EMPTY), ...patch } }));
56
+ const requiredLeft = steps.some((s) => s.required && !s.tick);
57
+ const anyLeft = steps.some((s) => !s.tick);
58
+ async function act(step, what, words) {
59
+ setRefusal(null);
60
+ setSaid(null);
61
+ try {
62
+ await what();
63
+ setSaid(words);
64
+ if (step !== null)
65
+ setDrafts((d) => ({ ...d, [step]: EMPTY }));
66
+ }
67
+ catch (error) {
68
+ setRefusal({ step, refusal: dayRefusal(error) });
69
+ }
70
+ await refetch();
71
+ }
72
+ const tickStep = (position, state) => {
73
+ const d = draftOf(position);
74
+ return act(position, () => forgetAfter(tick, {
75
+ template: item.template.id,
76
+ date: item.date,
77
+ step: position,
78
+ state,
79
+ ...(state === "done" && d.note.trim() ? { note: d.note.trim() } : {}),
80
+ ...(state === "not_done" && d.why.trim() ? { why: d.why.trim() } : {}),
81
+ }), state === "clear" ? "Tick cleared." : "Ticked.");
82
+ };
83
+ const alert = (r) => (_jsx(Text, { tone: "danger", accessibilityRole: "alert", children: r.message }));
84
+ const finished = finishedLabel(item, locale, zone);
85
+ return (_jsxs(View, { children: [_jsxs(Text, { accessibilityRole: "header", children: [item.template.name, " \u00B7 ", dayStateLabel(item.state), item.late ? (item.state === "done" ? " · done late" : " · past due") : ""] }), item.dueAt ? _jsxs(Text, { children: ["Due by ", timeIn(item.dueAt, zone, locale)] }) : null, finished ? _jsx(Text, { children: finished }) : null, steps.map((step) => {
86
+ const d = draftOf(step.position);
87
+ const mine = !step.tick || step.tick.by === you;
88
+ return (_jsxs(View, { accessible: false, children: [_jsxs(Text, { children: [step.text, " (", step.required ? "required" : "optional", step.asksNote ? ", asks for a note" : "", ")"] }), step.tick ? (_jsxs(Text, { children: [tickLabel(step.tick), " at ", timeIn(step.tick.at, zone, locale)] })) : null, step.tick?.why ? _jsxs(Text, { children: ["Why: ", step.tick.why] }) : null, step.tick?.note ? _jsxs(Text, { children: ["Note: ", step.tick.note] }) : null, step.missed ? _jsx(Text, { children: "Missed" }) : null, canTick && mine ? (_jsxs(View, { children: [_jsx(Field, { label: step.asksNote ? `Note on ${step.text} (needed)` : `Note on ${step.text}`, value: d.note, maxLength: 1000, onChangeText: (note) => setDraft(step.position, { note }) }), d.notDone ? (_jsx(Field, { label: `Why ${step.text} was not done`, value: d.why, maxLength: 500, onChangeText: (why) => setDraft(step.position, { why }) })) : null, _jsx(Button, { label: `Tick ${step.text} done`, busy: busy, onPress: () => tickStep(step.position, "done") }), _jsx(Button, { label: d.notDone ? `Save ${step.text} as not done` : `${step.text}: not done`, quiet: true, busy: busy, onPress: () => d.notDone
89
+ ? tickStep(step.position, "not_done")
90
+ : setDraft(step.position, { notDone: true }) }), step.tick ? (_jsx(Button, { label: `Clear the tick of ${step.text}`, quiet: true, busy: busy, onPress: () => tickStep(step.position, "clear") })) : null] })) : null, refusal?.step === step.position ? alert(refusal.refusal) : null] }, step.position));
91
+ }), canTick && !requiredLeft && anyLeft ? (_jsx(Button, { label: `Finish ${item.template.name}`, busy: busy, onPress: () => act(null, () => forgetAfter(done, { template: item.template.id, date: item.date }), "Finished. It does not change now.") })) : null, said ? _jsx(Text, { accessibilityRole: "alert", children: said }) : null, refusal && refusal.step === null ? alert(refusal.refusal) : null] }));
92
+ }
@@ -0,0 +1,6 @@
1
+ import { type DailyChecksHooks } from "@composable-os/pack-dailychecks/client";
2
+ export type TodayHooks = Pick<DailyChecksHooks, "useToday" | "useDay" | "useTick" | "useDone">;
3
+ export declare function TodaysChecklists({ dailychecks, locale, }: {
4
+ dailychecks: TodayHooks;
5
+ locale?: string;
6
+ }): import("react").JSX.Element;
@@ -0,0 +1,113 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // Today's checklists (ADR 0651): the checklists done on their own (opening, closing, cleaning) that
3
+ // are due today and that the viewer may do, each with when it is due by and its steps. Anyone who
4
+ // may do one ticks its steps (done, with a note where the step asks; not done, with why); whoever
5
+ // ticks the last step finishes it, and a finished one never changes. Someone who manages checklists
6
+ // sees every one and may tick for someone who may do it, saying why: kept, and shown, as ticked by
7
+ // them for that person.
8
+ //
9
+ // The host decides everything here: what is due, who may do it (`mayDo`, `canTick`), who may tick
10
+ // for whom, whether a step needs a note, when it is finished. This shows its answer and refusals.
11
+ //
12
+ // What someone writes on a step, why it was not done and why it was ticked for someone are
13
+ // private: kept only in this screen's state, sent with `forgetAfter` (never in a URL, storage or a
14
+ // query's key), cleared when the page is left, and read again when the browser brings it back.
15
+ import { dayRefusal, dayStateLabel, finishedLabel, forgetAfter, stepsOf, tickLabel, timeIn, } from "@composable-os/pack-dailychecks/client";
16
+ import { useEffect, useId, useRef, useState } from "react";
17
+ import { Button } from "../ui-button/button.js";
18
+ const EMPTY = { note: "", why: "", notDone: false };
19
+ /** Forgets what was typed when the page is left, or brought back from the back-forward cache. */
20
+ function useForgetOnLeave(forget, cameBack) {
21
+ const latest = useRef({ forget, cameBack });
22
+ latest.current = { forget, cameBack };
23
+ useEffect(() => {
24
+ const hide = () => latest.current.forget();
25
+ const show = (event) => {
26
+ if (!event.persisted)
27
+ return;
28
+ latest.current.forget();
29
+ latest.current.cameBack();
30
+ };
31
+ window.addEventListener("pagehide", hide);
32
+ window.addEventListener("pageshow", show);
33
+ return () => {
34
+ window.removeEventListener("pagehide", hide);
35
+ window.removeEventListener("pageshow", show);
36
+ };
37
+ }, []);
38
+ }
39
+ export function TodaysChecklists({ dailychecks, locale = "en-AU", }) {
40
+ const answer = dailychecks.useToday();
41
+ const [hidden, setHidden] = useState(false);
42
+ const [epoch, setEpoch] = useState(0);
43
+ useForgetOnLeave(() => {
44
+ setHidden(true);
45
+ setEpoch((e) => e + 1);
46
+ }, () => void Promise.resolve(answer.refetch?.()).then(() => setHidden(false)));
47
+ const data = hidden ? undefined : answer.data;
48
+ return (_jsxs("section", { className: "grid gap-3", "aria-label": "Today's checklists", children: [_jsx("h2", { className: "text-lg font-semibold", children: "Today's checklists" }), answer.isPending || hidden ? _jsx("p", { "aria-busy": "true", children: "Loading today's checklists\u2026" }) : null, answer.error ? (_jsx("p", { role: "alert", "data-refusal": dayRefusal(answer.error).kind, children: dayRefusal(answer.error).message })) : null, data && !data.items.length ? _jsx("p", { "data-empty": "today", children: "Nothing is due for you today." }) : null, data?.items.map((item) => (_jsx(DayChecklist, { hooks: dailychecks, item: item, zone: data.zone, you: data.you, youManage: data.youManage, locale: locale, refetch: () => answer.refetch?.() }, `${item.template.id}:${epoch}`)))] }));
49
+ }
50
+ function DayChecklist({ hooks, item, zone, you, youManage, locale, refetch, }) {
51
+ const id = useId();
52
+ const tick = hooks.useTick();
53
+ const done = hooks.useDone();
54
+ // Someone who manages checklists ticks for someone who may do it: whom, from the host.
55
+ const detail = hooks.useDay(youManage && item.canTick ? { template: item.template.id, date: item.date } : null);
56
+ const [forWhom, setForWhom] = useState(item.mayDo ? you : "");
57
+ const [forWhy, setForWhy] = useState("");
58
+ const [drafts, setDrafts] = useState({});
59
+ const [refusal, setRefusal] = useState(null);
60
+ const [said, setSaid] = useState(null);
61
+ const busy = tick.isPending || done.isPending;
62
+ const steps = stepsOf(item);
63
+ const draftOf = (p) => drafts[p] ?? EMPTY;
64
+ const setDraft = (p, patch) => setDrafts((d) => ({ ...d, [p]: { ...(d[p] ?? EMPTY), ...patch } }));
65
+ const forOther = forWhom !== "" && forWhom !== you;
66
+ const forInput = forOther
67
+ ? { for: forWhom, ...(forWhy.trim() ? { forWhy: forWhy.trim() } : {}) }
68
+ : {};
69
+ // Someone else's tick is changed only by whoever manages checklists (the host refuses it).
70
+ const mayChange = (step) => !step.tick || step.tick.by === you || youManage;
71
+ const requiredLeft = steps.some((s) => s.required && !s.tick);
72
+ const anyLeft = steps.some((s) => !s.tick);
73
+ const name = item.template.name;
74
+ async function act(step, what, words) {
75
+ setRefusal(null);
76
+ setSaid(null);
77
+ try {
78
+ await what();
79
+ setSaid(words);
80
+ if (step !== null)
81
+ setDrafts((d) => ({ ...d, [step]: EMPTY }));
82
+ }
83
+ catch (error) {
84
+ setRefusal({ step, refusal: dayRefusal(error) });
85
+ }
86
+ await refetch();
87
+ }
88
+ function tickStep(position, state) {
89
+ const d = draftOf(position);
90
+ return act(position, () => forgetAfter(tick, {
91
+ template: item.template.id,
92
+ date: item.date,
93
+ step: position,
94
+ state,
95
+ ...(state === "done" && d.note.trim() ? { note: d.note.trim() } : {}),
96
+ ...(state === "not_done" && d.why.trim() ? { why: d.why.trim() } : {}),
97
+ ...forInput,
98
+ }), state === "clear" ? "Tick cleared." : "Ticked.");
99
+ }
100
+ const finished = finishedLabel(item, locale, zone);
101
+ return (_jsxs("article", { className: "grid gap-2 rounded-md border p-3 text-sm", "aria-labelledby": `${id}-name`, "data-day-checklist": item.template.id, "data-state": item.state, children: [_jsxs("header", { className: "flex flex-wrap items-center justify-between gap-2", children: [_jsxs("h3", { id: `${id}-name`, className: "font-medium", children: [name, _jsx("span", { className: "ml-2 rounded border px-1 text-xs", "data-checklist-state": item.state, children: dayStateLabel(item.state) }), item.late ? (_jsx("span", { className: "ml-2 rounded border px-1 text-xs", "data-late": "true", children: item.state === "done" ? "Done late" : "Past due" })) : null] }), item.dueAt ? (_jsxs("p", { className: "text-muted-foreground", children: ["Due by ", timeIn(item.dueAt, zone, locale)] })) : null] }), item.template.purpose ? (_jsx("p", { className: "text-muted-foreground", children: item.template.purpose })) : null, finished ? _jsx("p", { "data-finished": "true", children: finished }) : null, item.run?.closedWhy ? _jsxs("p", { className: "text-xs", children: ["Why: ", item.run.closedWhy] }) : null, item.canTick && youManage ? (_jsxs("div", { className: "grid gap-1 rounded-md border p-2", children: [_jsxs("label", { className: "grid gap-1", htmlFor: `${id}-for`, children: [_jsx("span", { children: "Ticking as" }), _jsxs("select", { id: `${id}-for`, className: "rounded-md border px-2 py-1", value: forWhom, onChange: (e) => setForWhom(e.target.value), children: [item.mayDo ? (_jsx("option", { value: you, children: "Myself" })) : (_jsx("option", { value: "", children: "Choose someone" })), (detail.data?.doers ?? [])
102
+ .filter((d) => d.id !== you)
103
+ .map((d) => (_jsxs("option", { value: d.id, children: ["For ", d.name] }, d.id)))] })] }), forOther ? (_jsxs("label", { className: "grid gap-1", htmlFor: `${id}-forwhy`, children: [_jsx("span", { children: "Why you are ticking it for them" }), _jsx("input", { id: `${id}-forwhy`, className: "rounded-md border px-2 py-1", value: forWhy, maxLength: 500, autoComplete: "off", onChange: (e) => setForWhy(e.target.value) })] })) : null] })) : null, _jsx("ol", { className: "grid gap-2", "aria-label": `Steps of ${name}`, children: steps.map((step) => {
104
+ const d = draftOf(step.position);
105
+ const editable = item.canTick && mayChange(step);
106
+ return (_jsxs("li", { className: "grid gap-1 rounded-md border p-2", "data-step": step.position, "data-ticked": step.tick ? (step.tick.done ? "done" : "not_done") : undefined, "data-missed": step.missed ? "true" : undefined, children: [_jsxs("p", { children: [_jsx("span", { className: "font-medium", children: step.text }), _jsxs("span", { className: "ml-2 text-xs text-muted-foreground", children: [step.required ? "Required" : "Optional", step.asksNote ? " · asks for a note" : ""] })] }), step.tick ? (_jsxs("p", { className: "text-xs", "data-tick-label": "true", children: [tickLabel(step.tick), " \u00B7 ", timeIn(step.tick.at, zone, locale), step.tick.why ? ` · Why: ${step.tick.why}` : "", step.tick.onBehalfWhy ? ` · For them because: ${step.tick.onBehalfWhy}` : ""] })) : null, step.tick?.note ? _jsxs("p", { className: "text-xs", children: ["Note: ", step.tick.note] }) : null, step.tick?.withheld ? (_jsx("p", { className: "text-xs text-muted-foreground", children: "What they wrote is theirs and whoever manages checklists' to read." })) : null, step.missed ? _jsx("p", { className: "text-xs font-semibold", children: "Missed" }) : null, editable ? (_jsxs("div", { className: "grid gap-1", children: [_jsxs("label", { className: "grid gap-1", htmlFor: `${id}-note-${step.position}`, children: [_jsx("span", { className: "text-xs", children: step.asksNote ? "Note (needed to tick it done)" : "Note (optional)" }), _jsx("input", { id: `${id}-note-${step.position}`, className: "rounded-md border px-2 py-1", value: d.note, maxLength: 1000, autoComplete: "off", "aria-label": `Note on ${step.text}`, onChange: (e) => setDraft(step.position, { note: e.target.value }) })] }), d.notDone ? (_jsxs("label", { className: "grid gap-1", htmlFor: `${id}-why-${step.position}`, children: [_jsx("span", { className: "text-xs", children: "Why it was not done" }), _jsx("input", { id: `${id}-why-${step.position}`, className: "rounded-md border px-2 py-1", value: d.why, maxLength: 500, autoComplete: "off", "aria-label": `Why ${step.text} was not done`, onChange: (e) => setDraft(step.position, { why: e.target.value }) })] })) : null, _jsxs("div", { className: "flex flex-wrap gap-2", children: [_jsx(Button, { type: "button", disabled: busy, "aria-busy": busy, "aria-label": `Tick ${step.text} done`, onClick: () => tickStep(step.position, "done"), children: "Done" }), _jsx(Button, { type: "button", variant: "outline", disabled: busy, "aria-label": d.notDone ? `Save ${step.text} as not done` : `Mark ${step.text} not done`, onClick: () => d.notDone
107
+ ? tickStep(step.position, "not_done")
108
+ : setDraft(step.position, { notDone: true }), children: d.notDone ? "Save not done" : "Not done" }), step.tick ? (_jsx(Button, { type: "button", variant: "outline", disabled: busy, "aria-label": `Clear the tick of ${step.text}`, onClick: () => tickStep(step.position, "clear"), children: "Clear" })) : null] })] })) : null, refusal?.step === step.position ? _jsx(Refusal, { refusal: refusal.refusal }) : null] }, step.position));
109
+ }) }), item.canTick && !requiredLeft && anyLeft ? (_jsx(Button, { type: "button", disabled: busy, "aria-busy": busy, "aria-label": `Finish ${name} with the optional steps left`, onClick: () => act(null, () => forgetAfter(done, { template: item.template.id, date: item.date, ...forInput }), "Finished. It does not change now."), children: "Finish" })) : null, item.canTick ? (_jsx("p", { className: "text-xs text-muted-foreground", children: "Ticking the last step finishes it. Not finished by the end of the day, it is missed." })) : null, said ? (_jsx("p", { role: "status", className: "text-xs", children: said })) : null, refusal && refusal.step === null ? _jsx(Refusal, { refusal: refusal.refusal }) : null] }));
110
+ }
111
+ function Refusal({ refusal }) {
112
+ return (_jsx("p", { role: "alert", className: "text-xs", "data-refusal": refusal.kind, children: refusal.message }));
113
+ }