@photonhealth/react 0.0.0-stage → 2.0.0-rc.1
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 +15 -0
- package/README.md +84 -2
- package/dist/adapters/index.d.ts +2 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +2 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/tailwind.d.ts +3 -0
- package/dist/adapters/tailwind.d.ts.map +1 -0
- package/dist/adapters/tailwind.js +123 -0
- package/dist/adapters/tailwind.js.map +1 -0
- package/dist/components/ChangeList.d.ts +21 -0
- package/dist/components/ChangeList.d.ts.map +1 -0
- package/dist/components/ChangeList.js +40 -0
- package/dist/components/ChangeList.js.map +1 -0
- package/dist/components/PhotonOrder.d.ts +46 -0
- package/dist/components/PhotonOrder.d.ts.map +1 -0
- package/dist/components/PhotonOrder.js +270 -0
- package/dist/components/PhotonOrder.js.map +1 -0
- package/dist/components/PhotonPatient.d.ts +48 -0
- package/dist/components/PhotonPatient.d.ts.map +1 -0
- package/dist/components/PhotonPatient.js +83 -0
- package/dist/components/PhotonPatient.js.map +1 -0
- package/dist/components/PhotonPrescription.d.ts +43 -0
- package/dist/components/PhotonPrescription.d.ts.map +1 -0
- package/dist/components/PhotonPrescription.js +364 -0
- package/dist/components/PhotonPrescription.js.map +1 -0
- package/dist/components/ScreeningAlerts.d.ts +6 -0
- package/dist/components/ScreeningAlerts.d.ts.map +1 -0
- package/dist/components/ScreeningAlerts.js +11 -0
- package/dist/components/ScreeningAlerts.js.map +1 -0
- package/dist/components/SignedIn.d.ts +12 -0
- package/dist/components/SignedIn.d.ts.map +1 -0
- package/dist/components/SignedIn.js +84 -0
- package/dist/components/SignedIn.js.map +1 -0
- package/dist/components/TreatmentPicker.d.ts +45 -0
- package/dist/components/TreatmentPicker.d.ts.map +1 -0
- package/dist/components/TreatmentPicker.js +279 -0
- package/dist/components/TreatmentPicker.js.map +1 -0
- package/dist/components/activity.d.ts +7 -0
- package/dist/components/activity.d.ts.map +1 -0
- package/dist/components/activity.js +24 -0
- package/dist/components/activity.js.map +1 -0
- package/dist/components/display.d.ts +90 -0
- package/dist/components/display.d.ts.map +1 -0
- package/dist/components/display.js +223 -0
- package/dist/components/display.js.map +1 -0
- package/dist/components/flow.d.ts +35 -0
- package/dist/components/flow.d.ts.map +1 -0
- package/dist/components/flow.js +53 -0
- package/dist/components/flow.js.map +1 -0
- package/dist/components/format.d.ts +26 -0
- package/dist/components/format.d.ts.map +1 -0
- package/dist/components/format.js +61 -0
- package/dist/components/format.js.map +1 -0
- package/dist/components/index.d.ts +6 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +6 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/open.d.ts +47 -0
- package/dist/components/open.d.ts.map +1 -0
- package/dist/components/open.js +73 -0
- package/dist/components/open.js.map +1 -0
- package/dist/components/patient/Benefits.d.ts +25 -0
- package/dist/components/patient/Benefits.d.ts.map +1 -0
- package/dist/components/patient/Benefits.js +47 -0
- package/dist/components/patient/Benefits.js.map +1 -0
- package/dist/components/patient/Clinical.d.ts +55 -0
- package/dist/components/patient/Clinical.d.ts.map +1 -0
- package/dist/components/patient/Clinical.js +117 -0
- package/dist/components/patient/Clinical.js.map +1 -0
- package/dist/components/patient/IntakeForm.d.ts +10 -0
- package/dist/components/patient/IntakeForm.d.ts.map +1 -0
- package/dist/components/patient/IntakeForm.js +324 -0
- package/dist/components/patient/IntakeForm.js.map +1 -0
- package/dist/components/patient/Summary.d.ts +48 -0
- package/dist/components/patient/Summary.d.ts.map +1 -0
- package/dist/components/patient/Summary.js +80 -0
- package/dist/components/patient/Summary.js.map +1 -0
- package/dist/components/patient/fields.d.ts +43 -0
- package/dist/components/patient/fields.d.ts.map +1 -0
- package/dist/components/patient/fields.js +71 -0
- package/dist/components/patient/fields.js.map +1 -0
- package/dist/components/patient/query.d.ts +23 -0
- package/dist/components/patient/query.d.ts.map +1 -0
- package/dist/components/patient/query.js +65 -0
- package/dist/components/patient/query.js.map +1 -0
- package/dist/components/search.d.ts +154 -0
- package/dist/components/search.d.ts.map +1 -0
- package/dist/components/search.js +295 -0
- package/dist/components/search.js.map +1 -0
- package/dist/hooks/index.d.ts +5 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +5 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/useLatestCallback.d.ts +7 -0
- package/dist/hooks/useLatestCallback.d.ts.map +1 -0
- package/dist/hooks/useLatestCallback.js +14 -0
- package/dist/hooks/useLatestCallback.js.map +1 -0
- package/dist/hooks/useLive.d.ts +15 -0
- package/dist/hooks/useLive.d.ts.map +1 -0
- package/dist/hooks/useLive.js +6 -0
- package/dist/hooks/useLive.js.map +1 -0
- package/dist/hooks/useOnChange.d.ts +11 -0
- package/dist/hooks/useOnChange.d.ts.map +1 -0
- package/dist/hooks/useOnChange.js +28 -0
- package/dist/hooks/useOnChange.js.map +1 -0
- package/dist/hooks/useSession.d.ts +7 -0
- package/dist/hooks/useSession.d.ts.map +1 -0
- package/dist/hooks/useSession.js +10 -0
- package/dist/hooks/useSession.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/primitives/PhotonProvider.d.ts +58 -0
- package/dist/primitives/PhotonProvider.d.ts.map +1 -0
- package/dist/primitives/PhotonProvider.js +91 -0
- package/dist/primitives/PhotonProvider.js.map +1 -0
- package/dist/primitives/defaults.d.ts +3 -0
- package/dist/primitives/defaults.d.ts.map +1 -0
- package/dist/primitives/defaults.js +67 -0
- package/dist/primitives/defaults.js.map +1 -0
- package/dist/primitives/icons.d.ts +6 -0
- package/dist/primitives/icons.d.ts.map +1 -0
- package/dist/primitives/icons.js +6 -0
- package/dist/primitives/icons.js.map +1 -0
- package/dist/primitives/index.d.ts +5 -0
- package/dist/primitives/index.d.ts.map +1 -0
- package/dist/primitives/index.js +5 -0
- package/dist/primitives/index.js.map +1 -0
- package/dist/primitives/select.d.ts +7 -0
- package/dist/primitives/select.d.ts.map +1 -0
- package/dist/primitives/select.js +16 -0
- package/dist/primitives/select.js.map +1 -0
- package/dist/primitives/types.d.ts +276 -0
- package/dist/primitives/types.d.ts.map +1 -0
- package/dist/primitives/types.js +3 -0
- package/dist/primitives/types.js.map +1 -0
- package/dist/styles.css +611 -0
- package/dist/test-utils/contract.d.ts +17 -0
- package/dist/test-utils/contract.d.ts.map +1 -0
- package/dist/test-utils/contract.js +261 -0
- package/dist/test-utils/contract.js.map +1 -0
- package/package.json +74 -4
- package/src/adapters/index.ts +1 -0
- package/src/adapters/tailwind.tsx +544 -0
- package/src/components/ChangeList.tsx +85 -0
- package/src/components/PhotonOrder.tsx +493 -0
- package/src/components/PhotonPatient.tsx +184 -0
- package/src/components/PhotonPrescription.tsx +605 -0
- package/src/components/ScreeningAlerts.tsx +28 -0
- package/src/components/SignedIn.tsx +144 -0
- package/src/components/TreatmentPicker.tsx +350 -0
- package/src/components/activity.ts +23 -0
- package/src/components/display.ts +278 -0
- package/src/components/flow.ts +67 -0
- package/src/components/format.ts +73 -0
- package/src/components/index.ts +5 -0
- package/src/components/open.ts +100 -0
- package/src/components/patient/Benefits.tsx +125 -0
- package/src/components/patient/Clinical.tsx +210 -0
- package/src/components/patient/IntakeForm.tsx +532 -0
- package/src/components/patient/Summary.tsx +310 -0
- package/src/components/patient/fields.tsx +144 -0
- package/src/components/patient/query.ts +77 -0
- package/src/components/search.tsx +377 -0
- package/src/hooks/index.ts +4 -0
- package/src/hooks/useLatestCallback.ts +16 -0
- package/src/hooks/useLive.ts +21 -0
- package/src/hooks/useOnChange.ts +34 -0
- package/src/hooks/useSession.ts +11 -0
- package/src/index.ts +19 -0
- package/src/primitives/PhotonProvider.tsx +153 -0
- package/src/primitives/defaults.tsx +409 -0
- package/src/primitives/icons.tsx +37 -0
- package/src/primitives/index.ts +4 -0
- package/src/primitives/select.ts +15 -0
- package/src/primitives/types.ts +276 -0
- package/src/styles.css +611 -0
- package/src/test-utils/contract.tsx +410 -0
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Every search on the cards works one way — patients, drugs, allergies, medications, diagnoses, and the
|
|
4
|
+
* server's other choices:
|
|
5
|
+
*
|
|
6
|
+
* - Type-ahead (`useTypeAhead`): once a field has the caller's `minChars` (each search says its own: the
|
|
7
|
+
* patient search 2, drugs and clinical entries 3) and typing pauses, it searches; each
|
|
8
|
+
* keystroke cancels the search waiting, and the live object aborts one in flight. Leaving the field (or
|
|
9
|
+
* Enter) sends at once. Patients and drugs search without writing; for allergies, meds and diagnoses a
|
|
10
|
+
* search is an add — a unique match is the entry (see ClinicalList).
|
|
11
|
+
* - Results (`SearchResults`): the first five, then "Show N more". In the list, 1–9 and 0 pick one (of those shown),
|
|
12
|
+
* ↑ ↓ (or K J) move, Home / End (or g / G) go to the first / last, and Esc goes back to the field that searched
|
|
13
|
+
* (← → and h l are the card flow's, / its search box: flow.ts).
|
|
14
|
+
* The one picked reads as selected while its call runs. Pressing one isn't leaving the field: the field
|
|
15
|
+
* doesn't send or open more of the form under the pointer (`pointing`).
|
|
16
|
+
* - A few results (fewer than five) for what's typed, for a patient or a drug: focus goes to the first, ready to
|
|
17
|
+
* pick (`focus(true)`). Typing carries on: until a key acts on the list, one that types (a character,
|
|
18
|
+
* Backspace) goes back to the field and types there (`typesBack`).
|
|
19
|
+
* - From the field (`searchKeys`): Option/Alt + 1–9 / 0 picks one (plain digits stay text: "amoxicillin 500"),
|
|
20
|
+
* ↓ moves into the list, and Tab does when there are only a few results and they answer what's typed.
|
|
21
|
+
* - The field whose call is in flight shows the spinner — nowhere else.
|
|
22
|
+
*/
|
|
23
|
+
import { useEffect, useId, useRef, useState } from "react";
|
|
24
|
+
import { useLatestCallback } from "../hooks/index.js";
|
|
25
|
+
import { useComponents } from "../primitives/index.js";
|
|
26
|
+
import { CHOICE_ACTION } from "../primitives/types.js";
|
|
27
|
+
/** A search waits until typing has paused this long. */
|
|
28
|
+
const PAUSE_MS = 300;
|
|
29
|
+
/** Results shown before "Show N more". */
|
|
30
|
+
export const SHOWN = 5;
|
|
31
|
+
/** Fewer results than this are few enough that focus goes to them (more: keep narrowing). */
|
|
32
|
+
export const FEW = 5;
|
|
33
|
+
/** Type-ahead for a card's search fields: `search(field)` runs once `minChars` are typed and typing pauses. */
|
|
34
|
+
export function useTypeAhead(search, { minChars }) {
|
|
35
|
+
const latest = useLatestCallback(search);
|
|
36
|
+
const timer = useRef(null);
|
|
37
|
+
const cancel = () => {
|
|
38
|
+
if (timer.current)
|
|
39
|
+
clearTimeout(timer.current);
|
|
40
|
+
timer.current = null;
|
|
41
|
+
};
|
|
42
|
+
useEffect(() => cancel, []);
|
|
43
|
+
const tooShort = (text) => text.trim().length < minChars;
|
|
44
|
+
return {
|
|
45
|
+
typed: (field, text) => {
|
|
46
|
+
cancel();
|
|
47
|
+
if (tooShort(text))
|
|
48
|
+
return;
|
|
49
|
+
timer.current = setTimeout(() => {
|
|
50
|
+
timer.current = null;
|
|
51
|
+
latest(field);
|
|
52
|
+
}, PAUSE_MS);
|
|
53
|
+
},
|
|
54
|
+
tooShort,
|
|
55
|
+
cancel,
|
|
56
|
+
waiting: () => timer.current !== null,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
// Whether a pointer is pressed anywhere on the page (one listener for every card).
|
|
60
|
+
let pressing = false;
|
|
61
|
+
let pressEnded = [];
|
|
62
|
+
if (typeof document !== "undefined") {
|
|
63
|
+
document.addEventListener("pointerdown", () => (pressing = true), true);
|
|
64
|
+
const end = () => {
|
|
65
|
+
pressing = false;
|
|
66
|
+
const queued = pressEnded;
|
|
67
|
+
pressEnded = [];
|
|
68
|
+
setTimeout(() => queued.forEach((run) => run())); // after the press's click
|
|
69
|
+
};
|
|
70
|
+
document.addEventListener("pointerup", end, true);
|
|
71
|
+
document.addEventListener("pointercancel", end, true);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Run `fn` now — or, if a press took focus from a field, once that press (and its click) is done. Leaving a
|
|
75
|
+
* field can close it or open more of the form; doing that mid-press moves whatever was pressed out from
|
|
76
|
+
* under the pointer, and the click lands somewhere else.
|
|
77
|
+
*/
|
|
78
|
+
export function afterPress(fn) {
|
|
79
|
+
if (pressing)
|
|
80
|
+
pressEnded.push(fn);
|
|
81
|
+
else
|
|
82
|
+
fn();
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* 1–9 then 0 as a 0-based index (0 is the tenth), or -1. By physical key first: Option + 1 on a Mac reports
|
|
86
|
+
* key "¡". Plain digits also match by key, for keyboards whose number row isn't Digit1…
|
|
87
|
+
*/
|
|
88
|
+
export function digitKey(e) {
|
|
89
|
+
const code = /^(?:Digit|Numpad)([0-9])$/.exec(e.code)?.[1];
|
|
90
|
+
const key = !e.altKey && /^[0-9]$/.test(e.key) ? e.key : undefined;
|
|
91
|
+
const digit = code ?? key;
|
|
92
|
+
return digit ? (Number(digit) + 9) % 10 : -1;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* A key a card acts on stops there: handled, it's not also a host page's shortcut (a host's own `j` or `/`).
|
|
96
|
+
* Keys the cards don't use pass through untouched.
|
|
97
|
+
*/
|
|
98
|
+
export function took(e) {
|
|
99
|
+
e.preventDefault();
|
|
100
|
+
e.stopPropagation();
|
|
101
|
+
}
|
|
102
|
+
/** In a list: Home or g is the first item, End or G the last; null for any other key. */
|
|
103
|
+
export function edge(e) {
|
|
104
|
+
if (e.altKey || e.metaKey || e.ctrlKey)
|
|
105
|
+
return null;
|
|
106
|
+
return e.key === "Home" || e.key === "g" ? "first" : e.key === "End" || e.key === "G" ? "last" : null;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* A key that types — a character, Backspace, Delete. In a list focus was put in for the prescriber (a few results
|
|
110
|
+
* came back), it goes back to the field instead: the list sends focus there and lets the key through, so the
|
|
111
|
+
* browser types it in the field.
|
|
112
|
+
*/
|
|
113
|
+
export function typesBack(e) {
|
|
114
|
+
if (e.altKey || e.metaKey || e.ctrlKey)
|
|
115
|
+
return false;
|
|
116
|
+
return e.key.length === 1 || e.key === "Backspace" || e.key === "Delete";
|
|
117
|
+
}
|
|
118
|
+
/** In a list: ↓ or J is the next item (1), ↑ or K the previous (-1); 0 for any other key. */
|
|
119
|
+
export function vertical(e) {
|
|
120
|
+
if (e.altKey || e.metaKey || e.ctrlKey)
|
|
121
|
+
return 0;
|
|
122
|
+
return e.key === "ArrowDown" || e.key === "j" ? 1 : e.key === "ArrowUp" || e.key === "k" ? -1 : 0;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* A search field's keys (its onKeyDown): Option/Alt + 1–9 / 0 picks a result, ↓ moves into them, and Tab does
|
|
126
|
+
* when they're few and `answered` (they're for what's in the field now). True when it took the key.
|
|
127
|
+
*
|
|
128
|
+
* A field that keeps the cursor (`inField`) takes only ↑ ↓, Return and Esc, and never gives up focus — no
|
|
129
|
+
* j / k, no digits, no Tab into the list: every one of those is a character someone may be typing, and a
|
|
130
|
+
* field that takes a name, a date or a phone can't quietly swallow them.
|
|
131
|
+
*/
|
|
132
|
+
export function searchKeys(e, results, answered) {
|
|
133
|
+
if (!results?.total)
|
|
134
|
+
return false;
|
|
135
|
+
if (results.inField) {
|
|
136
|
+
if (e.altKey || e.metaKey || e.ctrlKey)
|
|
137
|
+
return false;
|
|
138
|
+
const step = e.key === "ArrowDown" ? 1 : e.key === "ArrowUp" ? -1 : 0;
|
|
139
|
+
const took_ = step !== 0
|
|
140
|
+
? results.move?.(step)
|
|
141
|
+
: e.key === "Enter"
|
|
142
|
+
? results.accept?.()
|
|
143
|
+
: e.key === "Escape"
|
|
144
|
+
? results.clear?.()
|
|
145
|
+
: false;
|
|
146
|
+
if (took_)
|
|
147
|
+
took(e);
|
|
148
|
+
return Boolean(took_);
|
|
149
|
+
}
|
|
150
|
+
const digit = e.altKey ? digitKey(e) : -1;
|
|
151
|
+
const handled = digit >= 0
|
|
152
|
+
? results.pick(digit)
|
|
153
|
+
: e.key === "ArrowDown"
|
|
154
|
+
? results.focus()
|
|
155
|
+
: e.key === "Tab" && !e.shiftKey && answered && results.total < FEW && results.focus();
|
|
156
|
+
if (handled)
|
|
157
|
+
took(e);
|
|
158
|
+
return handled;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* A search's results: the first five, then "Show N more". In the list, 1–9 / 0 picks one and ↑ ↓ (or K J) move. `busy`: the
|
|
162
|
+
* object is working — the result picked reads as selected until it's done, and another pick waits for it.
|
|
163
|
+
*/
|
|
164
|
+
export function SearchResults({ label, results, onPick, busy, disabled, handleRef, onBack, action, inField, onActive, }) {
|
|
165
|
+
const { Button, ChoiceList, Stack } = useComponents();
|
|
166
|
+
const listId = useId();
|
|
167
|
+
const [showAll, setShowAll] = useState(false);
|
|
168
|
+
/** Where the keys are, when the field keeps the cursor. Null until ↓ or an answer puts it somewhere. */
|
|
169
|
+
const [active, setActive] = useState(null);
|
|
170
|
+
useEffect(() => {
|
|
171
|
+
onActive?.(active ? `${listId}-${active}` : null);
|
|
172
|
+
}, [active, listId, onActive]);
|
|
173
|
+
const shown = showAll ? results : results.slice(0, SHOWN);
|
|
174
|
+
const list = useRef(null);
|
|
175
|
+
const pointing = useRef(false);
|
|
176
|
+
// Focus was put here for the prescriber, mid-typing: keys that type go back to the field (typesBack).
|
|
177
|
+
const typing = useRef(false);
|
|
178
|
+
const buttons = () => [...(list.current?.querySelectorAll("button:not(:disabled)") ?? [])];
|
|
179
|
+
// The pick, while its call runs (it starts at once: the object goes busy as it's picked).
|
|
180
|
+
const [picked, setPicked] = useState(null);
|
|
181
|
+
if (picked && busy && !picked.started)
|
|
182
|
+
setPicked({ ...picked, started: true });
|
|
183
|
+
if (picked?.started && !busy)
|
|
184
|
+
setPicked(null);
|
|
185
|
+
const pickKey = (key) => {
|
|
186
|
+
if (disabled || (picked && busy))
|
|
187
|
+
return;
|
|
188
|
+
setPicked({ key, started: false });
|
|
189
|
+
onPick(key);
|
|
190
|
+
};
|
|
191
|
+
const pick = (index) => {
|
|
192
|
+
const result = !disabled ? shown[index] : undefined;
|
|
193
|
+
if (result)
|
|
194
|
+
pickKey(result.key);
|
|
195
|
+
return Boolean(result);
|
|
196
|
+
};
|
|
197
|
+
/** Every row the keys run through, in order: the results shown, then the way out. */
|
|
198
|
+
const keys = [...shown.map((r) => r.key), ...(action ? [CHOICE_ACTION] : [])];
|
|
199
|
+
const take = (key) => {
|
|
200
|
+
if (!key)
|
|
201
|
+
return false;
|
|
202
|
+
if (key === CHOICE_ACTION)
|
|
203
|
+
action?.onChoose();
|
|
204
|
+
else
|
|
205
|
+
pickKey(key);
|
|
206
|
+
return true;
|
|
207
|
+
};
|
|
208
|
+
useEffect(() => {
|
|
209
|
+
if (!handleRef)
|
|
210
|
+
return;
|
|
211
|
+
handleRef.current = {
|
|
212
|
+
// The action counts: with nobody matching it's the only row, and ↓ from the field must still reach it.
|
|
213
|
+
total: results.length + (action ? 1 : 0),
|
|
214
|
+
focus: (fromTyping) => {
|
|
215
|
+
if (inField) {
|
|
216
|
+
// The cursor stays where it is; the first row is simply where the keys now are.
|
|
217
|
+
setActive(keys[0] ?? null);
|
|
218
|
+
return keys.length > 0;
|
|
219
|
+
}
|
|
220
|
+
const first = buttons()[0];
|
|
221
|
+
typing.current = Boolean(fromTyping && first && onBack);
|
|
222
|
+
first?.focus();
|
|
223
|
+
return Boolean(first);
|
|
224
|
+
},
|
|
225
|
+
pick,
|
|
226
|
+
pointing: () => pointing.current,
|
|
227
|
+
...(inField
|
|
228
|
+
? {
|
|
229
|
+
inField: true,
|
|
230
|
+
// The ends are ends: leaning on ↓ parks on the last row and stops, rather than looping round
|
|
231
|
+
// to the top where Return would take someone else entirely. ↓ is the way in.
|
|
232
|
+
move: (step) => {
|
|
233
|
+
if (!keys.length)
|
|
234
|
+
return false;
|
|
235
|
+
const at = active ? keys.indexOf(active) : -1;
|
|
236
|
+
if (at < 0) {
|
|
237
|
+
if (step < 0)
|
|
238
|
+
return false;
|
|
239
|
+
setActive(keys[0]);
|
|
240
|
+
return true;
|
|
241
|
+
}
|
|
242
|
+
const next = Math.max(0, Math.min(keys.length - 1, at + step));
|
|
243
|
+
if (next === at)
|
|
244
|
+
return true; // at the end: taken, so the page doesn't scroll instead
|
|
245
|
+
setActive(keys[next]);
|
|
246
|
+
return true;
|
|
247
|
+
},
|
|
248
|
+
accept: () => (disabled ? false : take(active)),
|
|
249
|
+
clear: () => {
|
|
250
|
+
if (active === null)
|
|
251
|
+
return false;
|
|
252
|
+
setActive(null);
|
|
253
|
+
return true;
|
|
254
|
+
},
|
|
255
|
+
activeId: active ? `${listId}-${active}` : null,
|
|
256
|
+
}
|
|
257
|
+
: {}),
|
|
258
|
+
};
|
|
259
|
+
return () => {
|
|
260
|
+
handleRef.current = null;
|
|
261
|
+
};
|
|
262
|
+
});
|
|
263
|
+
const onKeyDown = (e) => {
|
|
264
|
+
if (typing.current && typesBack(e))
|
|
265
|
+
return onBack?.(); // not taken: the browser types it in the field
|
|
266
|
+
typing.current = false;
|
|
267
|
+
if (e.metaKey || e.ctrlKey)
|
|
268
|
+
return;
|
|
269
|
+
const digit = digitKey(e);
|
|
270
|
+
const all = buttons();
|
|
271
|
+
const at = all.indexOf(e.target);
|
|
272
|
+
if (digit >= 0) {
|
|
273
|
+
if (!pick(digit))
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
else if (vertical(e) && at >= 0) {
|
|
277
|
+
all[Math.max(0, Math.min(all.length - 1, at + vertical(e)))]?.focus();
|
|
278
|
+
}
|
|
279
|
+
else if (edge(e) && at >= 0) {
|
|
280
|
+
all[edge(e) === "first" ? 0 : all.length - 1]?.focus();
|
|
281
|
+
}
|
|
282
|
+
else if (e.key === "Escape" && onBack) {
|
|
283
|
+
onBack();
|
|
284
|
+
}
|
|
285
|
+
else
|
|
286
|
+
return;
|
|
287
|
+
took(e);
|
|
288
|
+
};
|
|
289
|
+
return (_jsxs(Stack, { gap: "1", children: [_jsx("div", { ref: list, onKeyDown: onKeyDown, onBlur: (e) => !list.current?.contains(e.relatedTarget) && (typing.current = false), onPointerDown: () => {
|
|
290
|
+
// Until the press ends: the field it leaves mustn't send, or open rows that move the list under it.
|
|
291
|
+
pointing.current = true;
|
|
292
|
+
window.addEventListener("pointerup", () => setTimeout(() => (pointing.current = false)), { once: true });
|
|
293
|
+
}, children: _jsx(ChoiceList, { label: label, choices: shown, onChoose: pickKey, disabled: disabled, pendingKey: picked && busy ? picked.key : null, action: action, ...(inField ? { activeKey: keys.includes(active ?? "") ? active : null, id: listId } : {}) }) }), results.length > shown.length && (_jsx("div", { children: _jsxs(Button, { variant: "ghost", onClick: () => setShowAll(true), children: ["Show ", results.length - shown.length, " more"] }) }))] }));
|
|
294
|
+
}
|
|
295
|
+
//# sourceMappingURL=search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.js","sourceRoot":"","sources":["../../src/components/search.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAsB,MAAM,OAAO,CAAC;AAC/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAwB,MAAM,wBAAwB,CAAC;AAE7E,wDAAwD;AACxD,MAAM,QAAQ,GAAG,GAAG,CAAC;AACrB,0CAA0C;AAC1C,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,CAAC;AACvB,6FAA6F;AAC7F,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC;AAarB,+GAA+G;AAC/G,MAAM,UAAU,YAAY,CAC1B,MAA0B,EAC1B,EAAE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BAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A stable function that always calls the latest `fn` — for handing host callbacks
|
|
3
|
+
* (onChange, …) to core objects created once. The ref is updated after
|
|
4
|
+
* render, never during it (react-hooks/refs).
|
|
5
|
+
*/
|
|
6
|
+
export declare function useLatestCallback<A extends unknown[], R>(fn: ((...args: A) => R) | undefined): (...args: A) => R | undefined;
|
|
7
|
+
//# sourceMappingURL=useLatestCallback.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLatestCallback.d.ts","sourceRoot":"","sources":["../../src/hooks/useLatestCallback.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,OAAO,EAAE,EAAE,CAAC,EACtD,EAAE,EAAE,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,SAAS,GAClC,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,SAAS,CAM/B"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useCallback, useLayoutEffect, useRef } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* A stable function that always calls the latest `fn` — for handing host callbacks
|
|
4
|
+
* (onChange, …) to core objects created once. The ref is updated after
|
|
5
|
+
* render, never during it (react-hooks/refs).
|
|
6
|
+
*/
|
|
7
|
+
export function useLatestCallback(fn) {
|
|
8
|
+
const ref = useRef(fn);
|
|
9
|
+
useLayoutEffect(() => {
|
|
10
|
+
ref.current = fn;
|
|
11
|
+
});
|
|
12
|
+
return useCallback((...args) => ref.current?.(...args), []);
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=useLatestCallback.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLatestCallback.js","sourceRoot":"","sources":["../../src/hooks/useLatestCallback.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE7D;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAC/B,EAAmC;IAEnC,MAAM,GAAG,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;IACvB,eAAe,CAAC,GAAG,EAAE;QACnB,GAAG,CAAC,OAAO,GAAG,EAAE,CAAC;IACnB,CAAC,CAAC,CAAC;IACH,OAAO,WAAW,CAAC,CAAC,GAAG,IAAO,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;AACjE,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AnySnapshot, LiveObject } from "@photonhealth/client";
|
|
2
|
+
interface Live<S> {
|
|
3
|
+
subscribe(listener: () => void): () => void;
|
|
4
|
+
readonly snapshot: S;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Bind a live object from @photonhealth/client (a Patient, Prescription or Order): re-renders when anything
|
|
8
|
+
* changes it — this component, another card, an order's response. Returns its snapshot
|
|
9
|
+
* `{ state, status, error }`, or null without an object.
|
|
10
|
+
*/
|
|
11
|
+
export declare function useLive<S>(obj: Live<S> | null | undefined): S | null;
|
|
12
|
+
/** Any of the three (e.g. an inspector over every object): the snapshot, typed as any of theirs. */
|
|
13
|
+
export declare function useLive(obj: LiveObject | null | undefined): AnySnapshot | null;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=useLive.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLive.d.ts","sourceRoot":"","sources":["../../src/hooks/useLive.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAGpE,UAAU,IAAI,CAAC,CAAC;IACd,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC;IAC5C,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC;CACtB;AAID;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,GAAG,CAAC,GAAG,IAAI,CAAC;AACtE,oGAAoG;AACpG,wBAAgB,OAAO,CAAC,GAAG,EAAE,UAAU,GAAG,IAAI,GAAG,SAAS,GAAG,WAAW,GAAG,IAAI,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLive.js","sourceRoot":"","sources":["../../src/hooks/useLive.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAO7C,MAAM,WAAW,GAAG,GAAG,EAAE,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC;AAUnC,MAAM,UAAU,OAAO,CAAC,GAAqC;IAC3D,OAAO,oBAAoB,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE,QAAQ,IAAI,IAAI,CAAC,CAAC;AAC9F,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
interface Live {
|
|
2
|
+
subscribe(listener: () => void): () => void;
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* A card's record event: call `fire(obj)` with its live object once it has a record (`select` returns
|
|
6
|
+
* something), then each time that record changes from the backend — compared by value, so a save that
|
|
7
|
+
* brings back the same record, or a saving / idle flip, doesn't count.
|
|
8
|
+
*/
|
|
9
|
+
export declare function useOnChange<T extends Live>(obj: T | null | undefined, select: (obj: T) => unknown, fire: ((obj: T) => void) | undefined): void;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=useOnChange.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useOnChange.d.ts","sourceRoot":"","sources":["../../src/hooks/useOnChange.ts"],"names":[],"mappings":"AAGA,UAAU,IAAI;IACZ,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC;CAC7C;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,IAAI,EACxC,GAAG,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,EACzB,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,OAAO,EAC3B,IAAI,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,KAAK,IAAI,CAAC,GAAG,SAAS,QAkBrC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import { useLatestCallback } from "./useLatestCallback.js";
|
|
3
|
+
/**
|
|
4
|
+
* A card's record event: call `fire(obj)` with its live object once it has a record (`select` returns
|
|
5
|
+
* something), then each time that record changes from the backend — compared by value, so a save that
|
|
6
|
+
* brings back the same record, or a saving / idle flip, doesn't count.
|
|
7
|
+
*/
|
|
8
|
+
export function useOnChange(obj, select, fire) {
|
|
9
|
+
const call = useLatestCallback(fire);
|
|
10
|
+
const pick = useLatestCallback(select);
|
|
11
|
+
// What was last reported for each object — so an effect that runs again (React's StrictMode mounts
|
|
12
|
+
// twice in development) doesn't report the same record twice.
|
|
13
|
+
const [reported] = useState(() => new WeakMap());
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (!obj)
|
|
16
|
+
return;
|
|
17
|
+
const report = () => {
|
|
18
|
+
const key = JSON.stringify(pick(obj) ?? null);
|
|
19
|
+
if (key === (reported.get(obj) ?? "null"))
|
|
20
|
+
return;
|
|
21
|
+
reported.set(obj, key);
|
|
22
|
+
call(obj);
|
|
23
|
+
};
|
|
24
|
+
report();
|
|
25
|
+
return obj.subscribe(report);
|
|
26
|
+
}, [obj, call, pick, reported]);
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=useOnChange.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useOnChange.js","sourceRoot":"","sources":["../../src/hooks/useOnChange.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAM3D;;;;GAIG;AACH,MAAM,UAAU,WAAW,CACzB,GAAyB,EACzB,MAA2B,EAC3B,IAAoC;IAEpC,MAAM,IAAI,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC;IACrC,MAAM,IAAI,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAAC;IACvC,mGAAmG;IACnG,8DAA8D;IAC9D,MAAM,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,OAAO,EAAa,CAAC,CAAC;IAC5D,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,GAAG;YAAE,OAAO;QACjB,MAAM,MAAM,GAAG,GAAG,EAAE;YAClB,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,CAAC;YAC9C,IAAI,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC;gBAAE,OAAO;YAClD,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;YACvB,IAAI,CAAC,GAAG,CAAC,CAAC;QACZ,CAAC,CAAC;QACF,MAAM,EAAE,CAAC;QACT,OAAO,GAAG,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAC/B,CAAC,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { SessionSnapshot } from "@photonhealth/client";
|
|
2
|
+
/**
|
|
3
|
+
* The prescriber's sign-in, for the host's own chrome (their name, their organization) — when the provider signs
|
|
4
|
+
* in (`clientId`). Null when the host signs in itself. Signing in is `usePhoton().session.signIn()`.
|
|
5
|
+
*/
|
|
6
|
+
export declare function useSession(): SessionSnapshot | null;
|
|
7
|
+
//# sourceMappingURL=useSession.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSession.d.ts","sourceRoot":"","sources":["../../src/hooks/useSession.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAI5D;;;GAGG;AACH,wBAAgB,UAAU,IAAI,eAAe,GAAG,IAAI,CAEnD"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { usePhoton } from "../primitives/index.js";
|
|
2
|
+
import { useLive } from "./useLive.js";
|
|
3
|
+
/**
|
|
4
|
+
* The prescriber's sign-in, for the host's own chrome (their name, their organization) — when the provider signs
|
|
5
|
+
* in (`clientId`). Null when the host signs in itself. Signing in is `usePhoton().session.signIn()`.
|
|
6
|
+
*/
|
|
7
|
+
export function useSession() {
|
|
8
|
+
return useLive(usePhoton().session);
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=useSession.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSession.js","sourceRoot":"","sources":["../../src/hooks/useSession.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC;;;GAGG;AACH,MAAM,UAAU,UAAU;IACxB,OAAO,OAAO,CAAC,SAAS,EAAE,CAAC,OAAO,CAAC,CAAC;AACtC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @photonhealth/react — Photon Rx for React. No design-system dependency:
|
|
3
|
+
* the cards render through a small set of building blocks that default to
|
|
4
|
+
* unstyled, page-inheriting HTML, and can be mapped to any design system.
|
|
5
|
+
*
|
|
6
|
+
* <PhotonProvider clientId="…" components={myComponents?}> — signs the prescriber in, then the cards call
|
|
7
|
+
* <PhotonProvider client={photon({ environment, auth })}> — or a client of the host's own
|
|
8
|
+
*
|
|
9
|
+
* primitives/ PhotonComponents (the building-block interface), defaultComponents, PhotonProvider
|
|
10
|
+
* hooks/ useLive (bind a live object)
|
|
11
|
+
* components/ PhotonOrder, PhotonPatient, PhotonPrescription — bound to @photonhealth/client's live objects (ids or objects in,
|
|
12
|
+
* events out)
|
|
13
|
+
*
|
|
14
|
+
* Optional: import "@photonhealth/react/styles.css" for structural styles that inherit the page.
|
|
15
|
+
*/
|
|
16
|
+
export * from "./primitives/index.ts";
|
|
17
|
+
export { useLive, useSession } from "./hooks/index.ts";
|
|
18
|
+
export { PhotonOrder, PhotonPatient, PhotonPrescription } from "./components/index.ts";
|
|
19
|
+
export type { PhotonOrderProps, PhotonPatientProps, PhotonPrescriptionProps } from "./components/index.ts";
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,cAAc,uBAAuB,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AACvF,YAAY,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @photonhealth/react — Photon Rx for React. No design-system dependency:
|
|
3
|
+
* the cards render through a small set of building blocks that default to
|
|
4
|
+
* unstyled, page-inheriting HTML, and can be mapped to any design system.
|
|
5
|
+
*
|
|
6
|
+
* <PhotonProvider clientId="…" components={myComponents?}> — signs the prescriber in, then the cards call
|
|
7
|
+
* <PhotonProvider client={photon({ environment, auth })}> — or a client of the host's own
|
|
8
|
+
*
|
|
9
|
+
* primitives/ PhotonComponents (the building-block interface), defaultComponents, PhotonProvider
|
|
10
|
+
* hooks/ useLive (bind a live object)
|
|
11
|
+
* components/ PhotonOrder, PhotonPatient, PhotonPrescription — bound to @photonhealth/client's live objects (ids or objects in,
|
|
12
|
+
* events out)
|
|
13
|
+
*
|
|
14
|
+
* Optional: import "@photonhealth/react/styles.css" for structural styles that inherit the page.
|
|
15
|
+
*/
|
|
16
|
+
export * from "./primitives/index.js";
|
|
17
|
+
export { useLive, useSession } from "./hooks/index.js";
|
|
18
|
+
export { PhotonOrder, PhotonPatient, PhotonPrescription } from "./components/index.js";
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,cAAc,uBAAuB,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { type Photon, type PhotonEnvironment, type PhotonError } from "@photonhealth/client";
|
|
2
|
+
import { type ReactNode } from "react";
|
|
3
|
+
import type { PhotonComponents } from "./types.ts";
|
|
4
|
+
/** What `onAuth` reports: network-api took the instance's token, or why not. */
|
|
5
|
+
export type PhotonAuthCheck = {
|
|
6
|
+
ok: true;
|
|
7
|
+
error: null;
|
|
8
|
+
} | {
|
|
9
|
+
ok: false;
|
|
10
|
+
error: PhotonError;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Why the sign-in's check failed — network-api refused the token (`unauthorized`), or couldn't be reached or answer —
|
|
14
|
+
* for the cards to say so; `retry` checks again (`checking` until it's answered).
|
|
15
|
+
*/
|
|
16
|
+
interface CheckFailure {
|
|
17
|
+
error: PhotonError;
|
|
18
|
+
checking: boolean;
|
|
19
|
+
retry: () => void;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* One provider for Photon Rx components — and their sign-in: everything inside it can make web calls.
|
|
23
|
+
* clientId sign the prescriber in here (core's session: Auth0, PKCE, renewed tokens). Opportunistic: a
|
|
24
|
+
* sign-in coming back from Auth0 is finished and a stored one renewed, on load; otherwise the
|
|
25
|
+
* first card in the page offers "Sign in" (a click; never an unasked redirect).
|
|
26
|
+
* environment with `clientId`: which Photon environment — production (`photon`) unless said.
|
|
27
|
+
* organization sign in straight to this Photon organization (no picker); signed in to another, the first card
|
|
28
|
+
* offers to sign in to this one.
|
|
29
|
+
* client or a Photon client of the host's own (`photon({ environment, auth })` — e.g. `{ getToken }`
|
|
30
|
+
* when the host signs in itself).
|
|
31
|
+
* components optional — map any building blocks to your design system; the rest are unstyled defaults.
|
|
32
|
+
* onAuth optional — once signed in, whether network-api takes the token (one ping per instance).
|
|
33
|
+
*
|
|
34
|
+
* At any level of the page: a provider without a client inherits its parent's, and providers with the same
|
|
35
|
+
* `clientId` share one sign-in.
|
|
36
|
+
*/
|
|
37
|
+
export declare function PhotonProvider({ client, clientId, environment, organization, components, onAuth, children, }: {
|
|
38
|
+
/** A Photon client of the host's own. Optional: a nested provider inherits its parent's. */
|
|
39
|
+
client?: Photon;
|
|
40
|
+
/** Sign the prescriber in with this Auth0 client (public, not a secret). */
|
|
41
|
+
clientId?: string;
|
|
42
|
+
/** With `clientId`: the Photon environment. Production unless said. */
|
|
43
|
+
environment?: PhotonEnvironment;
|
|
44
|
+
/** Sign in straight to this organization (`org_…`), skipping Auth0's picker. Optional: inherited. */
|
|
45
|
+
organization?: string;
|
|
46
|
+
components?: Partial<PhotonComponents>;
|
|
47
|
+
onAuth?: (auth: PhotonAuthCheck) => void;
|
|
48
|
+
children: ReactNode;
|
|
49
|
+
}): import("react").JSX.Element;
|
|
50
|
+
export declare const useComponents: () => PhotonComponents;
|
|
51
|
+
/** The photon instance PhotonProvider was given (or made) — for a host's own calls next to the cards. */
|
|
52
|
+
export declare function usePhoton(): Photon;
|
|
53
|
+
/** Why the sign-in's check failed, if it did (refused, or Photon unreachable) — for the cards. */
|
|
54
|
+
export declare const useCheckFailure: () => CheckFailure | null;
|
|
55
|
+
/** The organization the provider names, if it does — for the cards (signing in, and checking the sign-in's). */
|
|
56
|
+
export declare const useOrganization: () => string | null;
|
|
57
|
+
export {};
|
|
58
|
+
//# sourceMappingURL=PhotonProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PhotonProvider.d.ts","sourceRoot":"","sources":["../../src/primitives/PhotonProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,MAAM,EAAE,KAAK,iBAAiB,EAAE,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACrG,OAAO,EAAiF,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAGtH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAKnD,gFAAgF;AAChF,MAAM,MAAM,eAAe,GAAG;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,WAAW,CAAA;CAAE,CAAC;AAmB5F;;;GAGG;AACH,UAAU,YAAY;IACpB,KAAK,EAAE,WAAW,CAAC;IACnB,QAAQ,EAAE,OAAO,CAAC;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