@photonhealth/react 0.0.0-stage → 2.0.0-rc.2
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 +111 -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 +126 -0
- package/dist/adapters/tailwind.js.map +1 -0
- package/dist/analytics/PhotonAnalyticsProvider.d.ts +16 -0
- package/dist/analytics/PhotonAnalyticsProvider.d.ts.map +1 -0
- package/dist/analytics/PhotonAnalyticsProvider.js +57 -0
- package/dist/analytics/PhotonAnalyticsProvider.js.map +1 -0
- package/dist/analytics/fieldInteraction.d.ts +18 -0
- package/dist/analytics/fieldInteraction.d.ts.map +1 -0
- package/dist/analytics/fieldInteraction.js +102 -0
- package/dist/analytics/fieldInteraction.js.map +1 -0
- package/dist/analytics/tracker.d.ts +17 -0
- package/dist/analytics/tracker.d.ts.map +1 -0
- package/dist/analytics/tracker.js +36 -0
- package/dist/analytics/tracker.js.map +1 -0
- package/dist/analytics/viewed.d.ts +11 -0
- package/dist/analytics/viewed.d.ts.map +1 -0
- package/dist/analytics/viewed.js +16 -0
- package/dist/analytics/viewed.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 +274 -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 +85 -0
- package/dist/components/PhotonPatient.js.map +1 -0
- package/dist/components/PhotonPrescription.d.ts +32 -0
- package/dist/components/PhotonPrescription.d.ts.map +1 -0
- package/dist/components/PhotonPrescription.js +11 -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/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/order/DraftOrderPrompt.d.ts +18 -0
- package/dist/components/order/DraftOrderPrompt.d.ts.map +1 -0
- package/dist/components/order/DraftOrderPrompt.js +26 -0
- package/dist/components/order/DraftOrderPrompt.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 +48 -0
- package/dist/components/patient/Benefits.js.map +1 -0
- package/dist/components/patient/Clinical.d.ts +56 -0
- package/dist/components/patient/Clinical.d.ts.map +1 -0
- package/dist/components/patient/Clinical.js +118 -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 +333 -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 +90 -0
- package/dist/components/patient/Summary.js.map +1 -0
- package/dist/components/patient/fields.d.ts +42 -0
- package/dist/components/patient/fields.d.ts.map +1 -0
- package/dist/components/patient/fields.js +72 -0
- package/dist/components/patient/fields.js.map +1 -0
- package/dist/components/patient/query.d.ts +37 -0
- package/dist/components/patient/query.d.ts.map +1 -0
- package/dist/components/patient/query.js +70 -0
- package/dist/components/patient/query.js.map +1 -0
- package/dist/components/prescription/PrescriptionCard.d.ts +45 -0
- package/dist/components/prescription/PrescriptionCard.d.ts.map +1 -0
- package/dist/components/prescription/PrescriptionCard.js +179 -0
- package/dist/components/prescription/PrescriptionCard.js.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.d.ts +15 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.d.ts.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.js +18 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.js.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.d.ts +23 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.d.ts.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.js +42 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.js.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.d.ts +27 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.d.ts.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.js +169 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.js.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.d.ts +8 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.d.ts.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.js +12 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.js.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.d.ts +11 -0
- package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.d.ts.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.js +25 -0
- package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.js.map +1 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentPicker.d.ts +50 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentPicker.d.ts.map +1 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentPicker.js +287 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentPicker.js.map +1 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentSearch.d.ts +28 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentSearch.d.ts.map +1 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentSearch.js +146 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentSearch.js.map +1 -0
- package/dist/components/schemaErrors.d.ts +12 -0
- package/dist/components/schemaErrors.d.ts.map +1 -0
- package/dist/components/schemaErrors.js +24 -0
- package/dist/components/schemaErrors.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 +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/meta/version.d.ts +5 -0
- package/dist/meta/version.d.ts.map +1 -0
- package/dist/meta/version.js +5 -0
- package/dist/meta/version.js.map +1 -0
- package/dist/primitives/PhotonProvider.d.ts +60 -0
- package/dist/primitives/PhotonProvider.d.ts.map +1 -0
- package/dist/primitives/PhotonProvider.js +103 -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 +70 -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/photonContext.d.ts +3 -0
- package/dist/primitives/photonContext.d.ts.map +1 -0
- package/dist/primitives/photonContext.js +3 -0
- package/dist/primitives/photonContext.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 +288 -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/primitives/useProvidedPhoton.d.ts +8 -0
- package/dist/primitives/useProvidedPhoton.d.ts.map +1 -0
- package/dist/primitives/useProvidedPhoton.js +8 -0
- package/dist/primitives/useProvidedPhoton.js.map +1 -0
- package/dist/styles.css +653 -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 +282 -0
- package/dist/test-utils/contract.js.map +1 -0
- package/package.json +76 -4
- package/src/adapters/index.ts +1 -0
- package/src/adapters/tailwind.tsx +572 -0
- package/src/analytics/PhotonAnalyticsProvider.test.tsx +191 -0
- package/src/analytics/PhotonAnalyticsProvider.tsx +96 -0
- package/src/analytics/fieldInteraction.test.tsx +184 -0
- package/src/analytics/fieldInteraction.tsx +148 -0
- package/src/analytics/tracker.test.ts +52 -0
- package/src/analytics/tracker.ts +42 -0
- package/src/analytics/viewed.ts +27 -0
- package/src/components/ChangeList.tsx +85 -0
- package/src/components/PhotonOrder.test.tsx +256 -0
- package/src/components/PhotonOrder.tsx +508 -0
- package/src/components/PhotonPatient.tsx +188 -0
- package/src/components/PhotonPrescription.test.tsx +116 -0
- package/src/components/PhotonPrescription.tsx +45 -0
- package/src/components/ScreeningAlerts.tsx +28 -0
- package/src/components/SignedIn.tsx +144 -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/order/DraftOrderPrompt.test.tsx +80 -0
- package/src/components/order/DraftOrderPrompt.tsx +81 -0
- package/src/components/patient/Benefits.tsx +133 -0
- package/src/components/patient/Clinical.tsx +215 -0
- package/src/components/patient/IntakeForm.test.tsx +89 -0
- package/src/components/patient/IntakeForm.tsx +564 -0
- package/src/components/patient/Summary.test.tsx +106 -0
- package/src/components/patient/Summary.tsx +330 -0
- package/src/components/patient/fields.tsx +158 -0
- package/src/components/patient/query.ts +83 -0
- package/src/components/prescription/PrescriptionCard.test.tsx +85 -0
- package/src/components/prescription/PrescriptionCard.tsx +347 -0
- package/src/components/prescription/PrescriptionDetailsForm/DirectionsInput.test.tsx +85 -0
- package/src/components/prescription/PrescriptionDetailsForm/DirectionsInput.tsx +41 -0
- package/src/components/prescription/PrescriptionDetailsForm/DispenseInputs.test.tsx +209 -0
- package/src/components/prescription/PrescriptionDetailsForm/DispenseInputs.tsx +99 -0
- package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.test.tsx +456 -0
- package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.tsx +238 -0
- package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.test.ts +63 -0
- package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.ts +15 -0
- package/src/components/prescription/PrescriptionDetailsForm/TemplatePicker.test.tsx +75 -0
- package/src/components/prescription/PrescriptionDetailsForm/TemplatePicker.tsx +41 -0
- package/src/components/prescription/TreatmentSearch/TreatmentPicker.tsx +375 -0
- package/src/components/prescription/TreatmentSearch/TreatmentSearch.test.tsx +699 -0
- package/src/components/prescription/TreatmentSearch/TreatmentSearch.tsx +220 -0
- package/src/components/schemaErrors.test.ts +49 -0
- package/src/components/schemaErrors.ts +33 -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 +21 -0
- package/src/meta/version.test.ts +10 -0
- package/src/meta/version.ts +4 -0
- package/src/primitives/PhotonProvider.tsx +168 -0
- package/src/primitives/defaults.tsx +432 -0
- package/src/primitives/icons.tsx +37 -0
- package/src/primitives/index.ts +4 -0
- package/src/primitives/photonContext.ts +4 -0
- package/src/primitives/select.ts +15 -0
- package/src/primitives/types.ts +288 -0
- package/src/primitives/useProvidedPhoton.ts +21 -0
- package/src/styles.css +653 -0
- package/src/test-utils/contract.tsx +453 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every search on the cards works one way — patients, drugs, allergies, medications, diagnoses, and the
|
|
3
|
+
* server's other choices:
|
|
4
|
+
*
|
|
5
|
+
* - Type-ahead (`useTypeAhead`): once a field has the caller's `minChars` (each search says its own: the
|
|
6
|
+
* patient search 2, drugs and clinical entries 3) and typing pauses, it searches; each
|
|
7
|
+
* keystroke cancels the search waiting, and the live object aborts one in flight. Leaving the field (or
|
|
8
|
+
* Enter) sends at once. Patients and drugs search without writing; for allergies, meds and diagnoses a
|
|
9
|
+
* search is an add — a unique match is the entry (see ClinicalList).
|
|
10
|
+
* - Results (`SearchResults`): the first five, then "Show N more". In the list, 1–9 and 0 pick one (of those shown),
|
|
11
|
+
* ↑ ↓ (or K J) move, Home / End (or g / G) go to the first / last, and Esc goes back to the field that searched
|
|
12
|
+
* (← → and h l are the card flow's, / its search box: flow.ts).
|
|
13
|
+
* The one picked reads as selected while its call runs. Pressing one isn't leaving the field: the field
|
|
14
|
+
* doesn't send or open more of the form under the pointer (`pointing`).
|
|
15
|
+
* - A few results (fewer than five) for what's typed, for a patient or a drug: focus goes to the first, ready to
|
|
16
|
+
* pick (`focus(true)`). Typing carries on: until a key acts on the list, one that types (a character,
|
|
17
|
+
* Backspace) goes back to the field and types there (`typesBack`).
|
|
18
|
+
* - From the field (`searchKeys`): Option/Alt + 1–9 / 0 picks one (plain digits stay text: "amoxicillin 500"),
|
|
19
|
+
* ↓ moves into the list, and Tab does when there are only a few results and they answer what's typed.
|
|
20
|
+
* - The field whose call is in flight shows the spinner — nowhere else.
|
|
21
|
+
*/
|
|
22
|
+
import { type KeyboardEvent } from "react";
|
|
23
|
+
import { type ChoiceListProps } from "../primitives/types.ts";
|
|
24
|
+
/** Results shown before "Show N more". */
|
|
25
|
+
export declare const SHOWN = 5;
|
|
26
|
+
/** Fewer results than this are few enough that focus goes to them (more: keep narrowing). */
|
|
27
|
+
export declare const FEW = 5;
|
|
28
|
+
export interface TypeAhead<F extends string> {
|
|
29
|
+
/** `field` changed to `text`: the search waiting is dropped, and (`minChars`+) a new one waits for a pause. */
|
|
30
|
+
typed: (field: F, text: string) => void;
|
|
31
|
+
/** Too little to search on — under `minChars` once trimmed. */
|
|
32
|
+
tooShort: (text: string) => boolean;
|
|
33
|
+
/** Drop the search waiting — e.g. leaving the field sends now instead. */
|
|
34
|
+
cancel: () => void;
|
|
35
|
+
/** A search is waiting for typing to pause. */
|
|
36
|
+
waiting: () => boolean;
|
|
37
|
+
}
|
|
38
|
+
/** Type-ahead for a card's search fields: `search(field)` runs once `minChars` are typed and typing pauses. */
|
|
39
|
+
export declare function useTypeAhead<F extends string>(search: (field: F) => void, { minChars }: {
|
|
40
|
+
minChars: number;
|
|
41
|
+
}): TypeAhead<F>;
|
|
42
|
+
/**
|
|
43
|
+
* Run `fn` now — or, if a press took focus from a field, once that press (and its click) is done. Leaving a
|
|
44
|
+
* field can close it or open more of the form; doing that mid-press moves whatever was pressed out from
|
|
45
|
+
* under the pointer, and the click lands somewhere else.
|
|
46
|
+
*/
|
|
47
|
+
export declare function afterPress(fn: () => void): void;
|
|
48
|
+
/**
|
|
49
|
+
* 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
|
|
50
|
+
* key "¡". Plain digits also match by key, for keyboards whose number row isn't Digit1…
|
|
51
|
+
*/
|
|
52
|
+
export declare function digitKey(e: {
|
|
53
|
+
key: string;
|
|
54
|
+
code: string;
|
|
55
|
+
altKey: boolean;
|
|
56
|
+
}): number;
|
|
57
|
+
/**
|
|
58
|
+
* A key a card acts on stops there: handled, it's not also a host page's shortcut (a host's own `j` or `/`).
|
|
59
|
+
* Keys the cards don't use pass through untouched.
|
|
60
|
+
*/
|
|
61
|
+
export declare function took(e: {
|
|
62
|
+
preventDefault(): void;
|
|
63
|
+
stopPropagation(): void;
|
|
64
|
+
}): void;
|
|
65
|
+
/** In a list: Home or g is the first item, End or G the last; null for any other key. */
|
|
66
|
+
export declare function edge(e: {
|
|
67
|
+
key: string;
|
|
68
|
+
altKey: boolean;
|
|
69
|
+
metaKey: boolean;
|
|
70
|
+
ctrlKey: boolean;
|
|
71
|
+
}): "first" | "last" | null;
|
|
72
|
+
/**
|
|
73
|
+
* A key that types — a character, Backspace, Delete. In a list focus was put in for the prescriber (a few results
|
|
74
|
+
* came back), it goes back to the field instead: the list sends focus there and lets the key through, so the
|
|
75
|
+
* browser types it in the field.
|
|
76
|
+
*/
|
|
77
|
+
export declare function typesBack(e: {
|
|
78
|
+
key: string;
|
|
79
|
+
altKey: boolean;
|
|
80
|
+
metaKey: boolean;
|
|
81
|
+
ctrlKey: boolean;
|
|
82
|
+
}): boolean;
|
|
83
|
+
/** In a list: ↓ or J is the next item (1), ↑ or K the previous (-1); 0 for any other key. */
|
|
84
|
+
export declare function vertical(e: {
|
|
85
|
+
key: string;
|
|
86
|
+
altKey: boolean;
|
|
87
|
+
metaKey: boolean;
|
|
88
|
+
ctrlKey: boolean;
|
|
89
|
+
}): number;
|
|
90
|
+
/** How a search field reaches its results (`SearchResults`, or the drug picker). */
|
|
91
|
+
export interface SearchHandle {
|
|
92
|
+
/** How many results there are, shown or not. */
|
|
93
|
+
total: number;
|
|
94
|
+
/**
|
|
95
|
+
* Put focus on the first result; false if there's none. `typing`: the field put it there (a few results came
|
|
96
|
+
* back) — keys that type go back to it until one acts on the list.
|
|
97
|
+
*/
|
|
98
|
+
focus: (typing?: boolean) => boolean;
|
|
99
|
+
/** Pick the result at this index (0-based) — the drug picker opens it; false if there's none shown there. */
|
|
100
|
+
pick: (index: number) => boolean;
|
|
101
|
+
/** A result is being pressed: the field's blur is the press, not the prescriber leaving it. */
|
|
102
|
+
pointing?: () => boolean;
|
|
103
|
+
/**
|
|
104
|
+
* Set when the field keeps the cursor (`inField`). The keys then move a highlight rather than focus, so
|
|
105
|
+
* the prescriber can carry on typing at any point — which is what a search box that takes a name, a date
|
|
106
|
+
* or a phone has to allow. `activeId` is the highlighted option's DOM id, for `aria-activedescendant`.
|
|
107
|
+
*/
|
|
108
|
+
inField?: true;
|
|
109
|
+
/** Move the highlight by `step`, wrapping at the ends; false when there is nothing to move. */
|
|
110
|
+
move?: (step: number) => boolean;
|
|
111
|
+
/** Take the highlighted row; false when nothing is highlighted. */
|
|
112
|
+
accept?: () => boolean;
|
|
113
|
+
/** Drop the highlight; false when there was none. */
|
|
114
|
+
clear?: () => boolean;
|
|
115
|
+
activeId?: string | null;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* A search field's keys (its onKeyDown): Option/Alt + 1–9 / 0 picks a result, ↓ moves into them, and Tab does
|
|
119
|
+
* when they're few and `answered` (they're for what's in the field now). True when it took the key.
|
|
120
|
+
*
|
|
121
|
+
* A field that keeps the cursor (`inField`) takes only ↑ ↓, Return and Esc, and never gives up focus — no
|
|
122
|
+
* j / k, no digits, no Tab into the list: every one of those is a character someone may be typing, and a
|
|
123
|
+
* field that takes a name, a date or a phone can't quietly swallow them.
|
|
124
|
+
*/
|
|
125
|
+
export declare function searchKeys(e: KeyboardEvent, results: SearchHandle | null | undefined, answered: boolean): boolean;
|
|
126
|
+
/**
|
|
127
|
+
* 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
|
|
128
|
+
* object is working — the result picked reads as selected until it's done, and another pick waits for it.
|
|
129
|
+
*/
|
|
130
|
+
export declare function SearchResults({ label, results, onPick, busy, disabled, handleRef, onBack, action, inField, onActive, }: {
|
|
131
|
+
label: string;
|
|
132
|
+
results: ChoiceListProps["choices"];
|
|
133
|
+
onPick: (key: string) => void;
|
|
134
|
+
busy?: boolean;
|
|
135
|
+
disabled?: boolean;
|
|
136
|
+
handleRef?: {
|
|
137
|
+
current: SearchHandle | null;
|
|
138
|
+
};
|
|
139
|
+
/** Esc in the list: back to the field that searched. */
|
|
140
|
+
onBack?: () => void;
|
|
141
|
+
/**
|
|
142
|
+
* The way out of the list, after the results — the patient card's "Add new patient". It renders as the
|
|
143
|
+
* last row, so ↓ carries on into it from the last result and ↑ comes back.
|
|
144
|
+
*/
|
|
145
|
+
action?: ChoiceListProps["action"];
|
|
146
|
+
/**
|
|
147
|
+
* The field below keeps the cursor: the rows become options it highlights, so typing, Backspace and
|
|
148
|
+
* Delete always reach the field — the prescriber can narrow or start over without first coming back.
|
|
149
|
+
*/
|
|
150
|
+
inField?: boolean;
|
|
151
|
+
/** With `inField`: the highlighted option's DOM id, for the field's `aria-activedescendant`. */
|
|
152
|
+
onActive?: (id: string | null) => void;
|
|
153
|
+
}): import("react").JSX.Element;
|
|
154
|
+
//# sourceMappingURL=search.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/components/search.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EAAsC,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;AAG/E,OAAO,EAAiB,KAAK,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAI7E,0CAA0C;AAC1C,eAAO,MAAM,KAAK,IAAI,CAAC;AACvB,6FAA6F;AAC7F,eAAO,MAAM,GAAG,IAAI,CAAC;AAErB,MAAM,WAAW,SAAS,CAAC,CAAC,SAAS,MAAM;IACzC,+GAA+G;IAC/G,KAAK,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,+DAA+D;IAC/D,QAAQ,EA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C,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE;QAAE,OAAO,EAAE,YAAY,GAAG,IAAI,CAAA;KAAE,CAAC;IAC7C,wDAAwD;IACxD,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB;;;OAGG;IACH,MAAM,CAAC,EAAE,eAAe,CAAC,QAAQ,CAAC,CAAC;IACnC;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,gGAAgG;IAChG,QAAQ,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;CACxC,+BA0IA"}
|
|
@@ -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,wBA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CAAC,IAAI,CAAC,sBAC/C,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,aAC5B,GACL,CACP,IACK,CACT,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","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 @@
|
|
|
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"}
|