@notis_ai/cli 0.2.29 → 0.2.31
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/README.md +26 -8
- package/dist/agent-hooks/notis-agent-hook.mjs +38399 -10883
- package/dist/base-skills/notis-cli/.notis-base-skill.json +1 -1
- package/dist/base-skills/notis-cli/SKILL.md +11 -0
- package/dist/base-skills/notis-cli/references/native-databases.md +1 -1
- package/dist/base-skills/notis-query/.notis-base-skill.json +1 -1
- package/dist/base-skills/notis-query/references/query.md +6 -4
- package/dist/base-skills/notis-spaces/.notis-base-skill.json +1 -1
- package/dist/base-skills/notis-spaces/SKILL.md +8 -3
- package/dist/base-skills/notis-spaces/references/architecture.md +4 -1
- package/dist/base-skills/notis-spaces/references/design.md +7 -1
- package/dist/base-skills/notis-spaces/references/fixtures.md +27 -2
- package/dist/base-skills/notis-spaces/references/release.md +6 -5
- package/dist/base-skills/notis-spaces/references/sdk.md +172 -48
- package/dist/base-skills/notis-spaces/references/troubleshooting.md +3 -0
- package/dist/base-skills/notis-spaces/references/views.md +20 -0
- package/dist/sdk/src/hooks/useNativeDocuments.ts +50 -12
- package/dist/sdk/src/hooks/useThreadItem.ts +56 -0
- package/dist/sdk/src/index.ts +7 -2
- package/dist/sdk/src/runtime.ts +8 -1
- package/dist/sdk/src/space.ts +233 -1
- package/dist/sdk/src/tailwind.ts +53 -3
- package/dist/sdk/src/ui/icons.tsx +1 -0
- package/dist/sdk/src/words/types.ts +28 -0
- package/dist/skill-sync/index.js +10 -90
- package/dist/skill-sync-worker.mjs +232 -120
- package/dist/space-harness/host.js +309 -96
- package/dist/space-sdk/dist/chunk-3DFOGU26.js +3 -0
- package/dist/space-sdk/dist/index.js +4 -2
- package/dist/space-sdk/dist/ui.js +19 -14
- package/dist/space-sdk/src/hooks/useNativeDocuments.d.ts +23 -0
- package/dist/space-sdk/src/hooks/useThreadItem.d.ts +28 -0
- package/dist/space-sdk/src/index.d.ts +4 -2
- package/dist/space-sdk/src/runtime.d.ts +8 -1
- package/dist/space-sdk/src/space.ts +233 -1
- package/dist/space-sdk/src/tailwind-candidates.d.ts +765 -16
- package/dist/space-sdk/src/tailwind.ts +53 -3
- package/dist/space-sdk/src/ui/actions/useToast.d.ts +2 -0
- package/dist/space-sdk/src/ui/blocks/DataTable.d.ts +19 -4
- package/dist/space-sdk/src/ui/blocks/Meter.d.ts +12 -3
- package/dist/space-sdk/src/ui/blocks/Tabs.d.ts +7 -1
- package/dist/space-sdk/src/ui/blocks/index.d.ts +1 -1
- package/dist/space-sdk/src/ui/charts/CalendarHeatmap.d.ts +69 -0
- package/dist/space-sdk/src/ui/charts/Chart.d.ts +18 -3
- package/dist/space-sdk/src/ui/charts/chartData.d.ts +19 -0
- package/dist/space-sdk/src/ui/charts/heatmapData.d.ts +81 -0
- package/dist/space-sdk/src/ui/comments/CommentPane.d.ts +56 -10
- package/dist/space-sdk/src/ui/comments/PassageComments.d.ts +16 -7
- package/dist/space-sdk/src/ui/comments/agentRuntime.d.ts +59 -0
- package/dist/space-sdk/src/ui/comments/commentFiles.d.ts +5 -2
- package/dist/space-sdk/src/ui/comments/commentModel.d.ts +103 -8
- package/dist/space-sdk/src/ui/comments/commentWords.d.ts +82 -0
- package/dist/space-sdk/src/ui/comments/hostComments.d.ts +37 -0
- package/dist/space-sdk/src/ui/comments/index.d.ts +4 -0
- package/dist/space-sdk/src/ui/comments/paneParts.d.ts +119 -0
- package/dist/space-sdk/src/ui/comments/useCommentRouting.d.ts +75 -0
- package/dist/space-sdk/src/ui/comments/useComments.d.ts +147 -15
- package/dist/space-sdk/src/ui/comments/usePassageComments.d.ts +24 -8
- package/dist/space-sdk/src/ui/index.d.ts +6 -3
- package/dist/space-sdk/src/ui/layout/SidePane.d.ts +6 -1
- package/dist/space-sdk/src/ui/list/Row.d.ts +11 -1
- package/dist/space-sdk/src/ui/overlay/Tooltip.d.ts +8 -2
- package/dist/space-sdk/src/ui/period/dateFormat.d.ts +2 -0
- package/dist/space-sdk/src/ui/period/dateWords.d.ts +9 -0
- package/dist/space-sdk/src/ui/period/periods.d.ts +15 -2
- package/dist/space-sdk/src/ui/styles.d.ts +27 -5
- package/dist/space-sdk/src/words/types.ts +28 -0
- package/dist/view-renderer/dist/host.js +379 -166
- package/dist/view-renderer/src/dom.js +3 -2
- package/dist/view-renderer/src/errors.js +9 -0
- package/dist/view-renderer/src/host.tsx +18 -8
- package/dist/view-renderer/src/remote-broker.js +3 -1
- package/dist/view-renderer/src/renderer.js +87 -17
- package/dist/view-renderer/src/skeleton.js +70 -18
- package/package.json +5 -4
- package/skills/notis-cli/AGENT_INSTRUCTIONS.md +2 -1
- package/skills/notis-query/cli.md +3 -0
- package/skills/notis-spaces/cli.md +8 -8
- package/src/cli.js +10 -2
- package/src/command-specs/computer.js +21 -1
- package/src/command-specs/profile.js +12 -5
- package/src/command-specs/spaces.js +101 -31
- package/src/command-specs/tools.js +3 -0
- package/src/runtime/agent-identity.js +187 -0
- package/src/runtime/api-hosts.generated.js +35 -0
- package/src/runtime/api-hosts.js +109 -0
- package/src/runtime/app-platform.js +68 -24
- package/src/runtime/channel.js +3 -7
- package/src/runtime/http-agent.js +53 -0
- package/src/runtime/native-record-files.js +11 -0
- package/src/runtime/oauth.js +97 -5
- package/src/runtime/profiles.js +200 -41
- package/src/runtime/skill-sync/cloud-client.ts +0 -10
- package/src/runtime/skill-sync/index.ts +13 -15
- package/src/runtime/skill-sync/local-scanner.ts +0 -67
- package/src/runtime/skill-sync/types.ts +1 -0
- package/src/runtime/skill-sync/write-cloud-skill.ts +7 -23
- package/src/runtime/skill-sync-service.js +4 -5
- package/src/runtime/space-dependencies.js +66 -0
- package/src/runtime/space-fixture-broker.js +23 -8
- package/src/runtime/space-platform.js +49 -3
- package/src/runtime/space-source.js +76 -2
- package/src/runtime/space-test-server.js +125 -10
- package/src/runtime/space-verification.js +106 -42
- package/src/runtime/space-view-manifest.js +38 -5
- package/src/runtime/telemetry.js +14 -1
- package/src/runtime/transport.js +31 -4
- package/src/runtime/upsell.js +3 -6
- package/src/runtime/view-render.js +6 -1
- package/src/skill-sync-worker.js +13 -2
- package/src/space-harness-host.ts +6 -3
- package/template/tailwind.config.ts +2 -35
- package/dist/space-sdk/dist/chunk-BFGB6XXC.js +0 -5
|
@@ -1,20 +1,37 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The comment controller: reads a Comments database through the view's declared list, follows its live feed, writes
|
|
3
3
|
* through the normal native mutations and keeps every change on screen at once (optimistic patches and drafts) until
|
|
4
|
-
* the server rows carry it. `CommentPane`, `CommentPins` and `CommentThreadCard` render from it.
|
|
4
|
+
* the server rows carry it. `CommentPane`, `CommentPins`, `CommentToolBar` and `CommentThreadCard` render from it.
|
|
5
|
+
*
|
|
6
|
+
* People archive (Status `Resolved`, shown Done) and delete at once with a 6-second Undo toast and Z (SPC-124,
|
|
7
|
+
* SPC-133); agents never archive through it. Deleting a first comment deletes its thread; a later one leaves a "Comment
|
|
8
|
+
* deleted" line (SPC-127). Rights come from the host's viewer (SPC-128): you edit and delete your own comments, and a
|
|
9
|
+
* whole thread or someone else's comment needs Space edit rights. Without a viewer nothing can be edited or deleted.
|
|
10
|
+
* Under the host Comments panel a comment is written as the viewer (their name in Author, which the server stamps too)
|
|
11
|
+
* and nothing can be sent until the viewer is known (`canWrite`).
|
|
5
12
|
*/
|
|
6
13
|
import { type MouseEvent as ReactMouseEvent, type PointerEvent as ReactPointerEvent } from 'react';
|
|
14
|
+
import { type SpaceCommentViewer } from '../../space';
|
|
7
15
|
import { type Locale, type Words } from '../../words';
|
|
8
16
|
import { type ToastController } from '../actions/useToast';
|
|
9
|
-
import { type CommentAnchor, type CommentColumns, type CommentDigestOptions, type CommentRecord, type CommentScope, type CommentThread } from './commentModel';
|
|
17
|
+
import { type CommentAnchor, type CommentColumns, type CommentDigestOptions, type CommentGroup, type CommentRecord, type CommentScope, type CommentThread } from './commentModel';
|
|
10
18
|
import { type CommentWordKey, type CommentWords } from './commentWords';
|
|
19
|
+
import { type CommentRouting } from './useCommentRouting';
|
|
11
20
|
/** Which threads the pane lists: the current anchor's, or every thread in the scope. */
|
|
12
21
|
export type CommentAnchorFilter = 'anchor' | 'all';
|
|
13
|
-
/** Open threads, or
|
|
14
|
-
export type
|
|
22
|
+
/** Open threads (default), archived ones (Done, stored as `Resolved`) or both (SPC-126): what the pane shows. */
|
|
23
|
+
export type CommentStatusView = 'open' | 'done' | 'all';
|
|
24
|
+
/** A status filter as `setStatusFilter` takes it: 'resolved' is an older name of 'done' and reads as 'done'. */
|
|
25
|
+
export type CommentStatusFilter = CommentStatusView | 'resolved';
|
|
26
|
+
/**
|
|
27
|
+
* What a new comment points at (SPC-118): words of the text, a point or a box on an anchor, some items (records or
|
|
28
|
+
* rows), a moment of a recording, or the whole page (no anchor).
|
|
29
|
+
*/
|
|
30
|
+
export type CommentMode = 'text' | 'point' | 'box' | 'items' | 'time' | 'page';
|
|
15
31
|
/**
|
|
16
32
|
* A new comment being written: on an anchor, with a pin (x and y, 0 to 1), a zone (w and h too, 0 to 1 of the
|
|
17
|
-
* anchor's size) or neither (on the whole anchor).
|
|
33
|
+
* anchor's size) or neither (on the whole anchor; `anchorKey` null: on the whole page). `items` lists the record keys
|
|
34
|
+
* (records or rows) of an items comment, `time` the seconds of a time comment.
|
|
18
35
|
*/
|
|
19
36
|
export interface CommentDraftPin {
|
|
20
37
|
anchorKey: string | null;
|
|
@@ -22,6 +39,8 @@ export interface CommentDraftPin {
|
|
|
22
39
|
y: number | null;
|
|
23
40
|
w: number | null;
|
|
24
41
|
h: number | null;
|
|
42
|
+
items?: readonly CommentAnchor[] | null;
|
|
43
|
+
time?: number | null;
|
|
25
44
|
}
|
|
26
45
|
/** The zone being dragged on an anchor, 0 to 1 of its size. */
|
|
27
46
|
export interface CommentDragZone {
|
|
@@ -51,15 +70,39 @@ export interface CommentFile {
|
|
|
51
70
|
export type CommentAttachMode = 'on' | 'off' | 'checking';
|
|
52
71
|
export interface CommentActions {
|
|
53
72
|
/**
|
|
54
|
-
* Adds a reply, with the files already uploaded for it.
|
|
55
|
-
* ask
|
|
73
|
+
* Adds a reply, with the files already uploaded for it. It answers `answers` (an input ask on the first comment or a
|
|
74
|
+
* reply), else the latest open input ask in the thread; an archived thread stays archived (the server brings it back
|
|
75
|
+
* when a reply waits for someone). True once saved.
|
|
56
76
|
*/
|
|
57
|
-
reply(thread: CommentThread, body: string, files?: readonly CommentFile[]): Promise<boolean>;
|
|
77
|
+
reply(thread: CommentThread, body: string, files?: readonly CommentFile[], answers?: CommentRecord): Promise<boolean>;
|
|
58
78
|
/** Answers a check or choice ask. */
|
|
59
79
|
answer(root: CommentRecord, answer: string): void;
|
|
80
|
+
/** Writes the status without a toast. People archive with `archive` and `unarchive`. */
|
|
60
81
|
setStatus(root: CommentRecord, status: 'Open' | 'Resolved'): void;
|
|
61
|
-
/**
|
|
82
|
+
/** Archives an open thread (Done) with a 6-second Undo toast; Z undoes. */
|
|
83
|
+
archive(root: CommentRecord): void;
|
|
84
|
+
/** Brings an archived thread back to Open, with Undo. */
|
|
85
|
+
unarchive(root: CommentRecord): void;
|
|
86
|
+
/**
|
|
87
|
+
* Deletes at once with Undo (no dialog): a first comment deletes its whole thread, a later one leaves a "Comment
|
|
88
|
+
* deleted" line. Does nothing unless `canDelete` allows it.
|
|
89
|
+
*/
|
|
90
|
+
remove(comment: CommentRecord): void;
|
|
91
|
+
/** Same as `remove` on a thread's first comment. */
|
|
62
92
|
askDelete(root: CommentRecord): void;
|
|
93
|
+
/**
|
|
94
|
+
* Saves new text for your own comment and marks it edited (Edited at, which Copy changes reports). Change keeps what
|
|
95
|
+
* it said (an archive or an answer is never overwritten); without an Edited at column Change and Changed at mark the
|
|
96
|
+
* edit unless they say resolved or answered. True once saved (or unchanged).
|
|
97
|
+
*/
|
|
98
|
+
edit(comment: CommentRecord, body: string): Promise<boolean>;
|
|
99
|
+
/**
|
|
100
|
+
* Copies the link that opens this page with the thread revealed (`comment=<root key>`, as a push or a chat pill
|
|
101
|
+
* opens it): the host's address for it (`commentLink`), else the page's own address with that param. A toast says
|
|
102
|
+
* Link copied, or that it could not be copied. `host` (the card) holds the selection copy when the clipboard API is
|
|
103
|
+
* refused. True once copied.
|
|
104
|
+
*/
|
|
105
|
+
copyLink(root: CommentRecord, host?: HTMLElement | null): Promise<boolean>;
|
|
63
106
|
notify(words: Words | string): void;
|
|
64
107
|
}
|
|
65
108
|
export interface UseCommentsOptions {
|
|
@@ -76,7 +119,8 @@ export interface UseCommentsOptions {
|
|
|
76
119
|
/**
|
|
77
120
|
* The person using the Space; their comments count as changes and never as new activity. Default: the viewer's
|
|
78
121
|
* first name from the host, and when the Author column refuses it (a choice list without that name) "Person",
|
|
79
|
-
* then no author. Pass it to sign comments with a fixed name.
|
|
122
|
+
* then no author. Pass it to sign comments with a fixed name. Ignored under the host Comments panel: the viewer's
|
|
123
|
+
* name is used, for reading and writing.
|
|
80
124
|
*/
|
|
81
125
|
me?: string;
|
|
82
126
|
/** Authors the Author select knows; anyone else reads as `fallbackAuthor`. Default: any name. */
|
|
@@ -94,6 +138,26 @@ export interface UseCommentsOptions {
|
|
|
94
138
|
live?: boolean;
|
|
95
139
|
/** Called when a thread is picked (a pin, a card): the Space can move to its anchor and open its panel. */
|
|
96
140
|
onSelectThread?(thread: CommentThread): void;
|
|
141
|
+
/**
|
|
142
|
+
* Open this comment's thread (a root or a reply key) once it is read, and scroll to it. Default: the `comment` view
|
|
143
|
+
* param of a link (`useCommentFocusParam`); null turns that off.
|
|
144
|
+
*/
|
|
145
|
+
focusKey?: string | null;
|
|
146
|
+
/**
|
|
147
|
+
* The comment modes the Space offers (SPC-118), in the order the New comment menu and the tool bar list them.
|
|
148
|
+
* Default: point (and box with zone columns) when there are anchors, items and time when their call-backs are given,
|
|
149
|
+
* and the whole page. 'items' needs `onStartItems`, 'time' needs `currentTime`.
|
|
150
|
+
*/
|
|
151
|
+
modes?: readonly CommentMode[];
|
|
152
|
+
/**
|
|
153
|
+
* Items mode: show your way of picking records or rows (checkboxes, a selection), then call
|
|
154
|
+
* `controller.startItems(items)` with the anchors picked. The hint shows until then; Escape cancels.
|
|
155
|
+
*/
|
|
156
|
+
onStartItems?(): void;
|
|
157
|
+
/** Time mode: the current moment of the recording, in seconds. The new comment is written at that moment. */
|
|
158
|
+
currentTime?(): number | null | undefined;
|
|
159
|
+
/** Names of the pages (scope records, by id or record key) the Space home groups comments under. */
|
|
160
|
+
scopeNames?: Readonly<Record<string, string>>;
|
|
97
161
|
}
|
|
98
162
|
export interface CommentController {
|
|
99
163
|
comments: CommentRecord[];
|
|
@@ -106,7 +170,10 @@ export interface CommentController {
|
|
|
106
170
|
checkpoint: string | null;
|
|
107
171
|
isNew(comment: CommentRecord): boolean;
|
|
108
172
|
threadsOn(anchorKey: string | null | undefined): CommentThread[];
|
|
109
|
-
/**
|
|
173
|
+
/**
|
|
174
|
+
* The thread's pin number (1-based), 0 when it has none: per page (scope record), in the order its first comments
|
|
175
|
+
* were written, deleted ones keeping theirs, so a number never moves and reads the same on the page and the Space home.
|
|
176
|
+
*/
|
|
110
177
|
numberOf(thread: CommentThread): number;
|
|
111
178
|
scope: CommentScope | null;
|
|
112
179
|
anchors: readonly CommentAnchor[];
|
|
@@ -114,17 +181,65 @@ export interface CommentController {
|
|
|
114
181
|
anchor: CommentAnchor | undefined;
|
|
115
182
|
filter: CommentAnchorFilter;
|
|
116
183
|
setFilter(filter: CommentAnchorFilter): void;
|
|
184
|
+
/** What the pane shows: never 'resolved' (typed wide so older comparisons with 'resolved' still compile). */
|
|
117
185
|
statusFilter: CommentStatusFilter;
|
|
186
|
+
/** 'resolved' is read as 'done'. */
|
|
118
187
|
setStatusFilter(filter: CommentStatusFilter): void;
|
|
188
|
+
/** Threads per status filter, for the current anchor filter. */
|
|
189
|
+
counts: Readonly<Record<CommentStatusView, number>>;
|
|
190
|
+
/** Threads per anchor filter ("This item", "All items"), for the current status filter. */
|
|
191
|
+
scopeCounts: Readonly<Record<CommentAnchorFilter, number>>;
|
|
192
|
+
/** True when the controller covers the whole Space (no scope record): the pane groups threads by page. */
|
|
193
|
+
wholeSpace: boolean;
|
|
194
|
+
/** The page a thread sits on, for grouping on the Space home: its scope record, else its anchor, else the Space. */
|
|
195
|
+
groupOf(thread: CommentThread): CommentGroup | null;
|
|
119
196
|
threadKey: string | null;
|
|
120
197
|
setThreadKey(key: string | null): void;
|
|
198
|
+
/** Picks a thread from the pane (a card): the page follows, the host panel stays as it is. */
|
|
121
199
|
selectThread(thread: CommentThread): void;
|
|
200
|
+
/**
|
|
201
|
+
* Picks a thread from the page (a pin, a highlight, a key on the page): like `selectThread`, and asks the host to
|
|
202
|
+
* show it in its Comments panel (`revealRequest` goes up by one).
|
|
203
|
+
*/
|
|
204
|
+
revealThread(thread: CommentThread): void;
|
|
205
|
+
/**
|
|
206
|
+
* Starts at 0 and goes up by one each time a comment is picked on the page (C8). The host opens its Comments panel
|
|
207
|
+
* on each increase and the pane scrolls the thread into view; picking inside the pane leaves it as it is.
|
|
208
|
+
*/
|
|
209
|
+
revealRequest: number;
|
|
122
210
|
actions: CommentActions;
|
|
123
|
-
/**
|
|
211
|
+
/** The signed-in viewer from the host (name and Space edit rights), or null while unknown. */
|
|
212
|
+
viewer: SpaceCommentViewer | null;
|
|
213
|
+
/** Whether the viewer may edit this comment: their own, never an agent's. */
|
|
214
|
+
canEdit(comment: CommentRecord): boolean;
|
|
215
|
+
/** Whether the viewer may delete it: their own comment; a whole thread or someone else's needs Space edit rights. */
|
|
216
|
+
canDelete(comment: CommentRecord): boolean;
|
|
217
|
+
/** False while the host's viewer is not known: Send stays off, so no comment is written under a wrong name. */
|
|
218
|
+
canWrite: boolean;
|
|
219
|
+
/** Threads, Goes to and the To chip (SPC-113, SPC-114, SPC-117). */
|
|
220
|
+
routing: CommentRouting;
|
|
221
|
+
/** The comment modes this Space offers, in order. */
|
|
222
|
+
modes: readonly CommentMode[];
|
|
223
|
+
/** The mode waiting for you to point at something (its hint shows), or null. */
|
|
224
|
+
commentMode: CommentMode | null;
|
|
225
|
+
/** Starts a mode: point and box wait for a click or drag, text for a selection, items for `startItems`; time and page open the box at once. */
|
|
226
|
+
startMode(mode: CommentMode): void;
|
|
227
|
+
cancelMode(): void;
|
|
228
|
+
/** Items mode: starts a new comment on these anchors (records or rows). */
|
|
229
|
+
startItems(items: readonly CommentAnchor[]): void;
|
|
230
|
+
/** Whether the page comment tool bar shows (`CommentToolBar`, C toggles it). */
|
|
231
|
+
toolBar: boolean;
|
|
232
|
+
setToolBar(on: boolean): void;
|
|
233
|
+
/** Add comment mode (point or box): the next click on the anchor drops a pin. Escape leaves it. */
|
|
124
234
|
commenting: boolean;
|
|
125
235
|
setCommenting(on: boolean): void;
|
|
126
236
|
toggleCommenting(): void;
|
|
127
237
|
draftPin: CommentDraftPin | null;
|
|
238
|
+
/**
|
|
239
|
+
* Names this page's comments (the Space, the table and the scope record) for the drafts the boxes keep while they are
|
|
240
|
+
* away (`commentDrafts`): a reply, a new comment and an answer come back with what was typed and attached.
|
|
241
|
+
*/
|
|
242
|
+
draftScope: string;
|
|
128
243
|
/**
|
|
129
244
|
* Starts a new comment on `anchorKey` at x, y (0 to 1), on a zone when w and h are given too, or on the whole
|
|
130
245
|
* anchor when x and y are null.
|
|
@@ -138,9 +253,16 @@ export interface CommentController {
|
|
|
138
253
|
dragZone: CommentDragZone | null;
|
|
139
254
|
/** In Add comment mode: a click on the element drops a pin, a press and drag marks a zone. */
|
|
140
255
|
zoneHandlers(anchorKey: string | null): CommentZoneHandlers;
|
|
256
|
+
/** Drops the new comment, and the thread picked for it. */
|
|
141
257
|
cancelPin(): void;
|
|
142
258
|
/** Saves the new comment with the files already uploaded for it. True once saved. */
|
|
143
259
|
sendNew(body: string, files?: readonly CommentFile[]): Promise<boolean>;
|
|
260
|
+
/** @deprecated Delete happens at once with Undo (SPC-133): always null. */
|
|
261
|
+
deleting: CommentRecord | null;
|
|
262
|
+
/** @deprecated Nothing to cancel: delete happens at once with Undo. */
|
|
263
|
+
cancelDelete(): void;
|
|
264
|
+
/** @deprecated Deletes `comment` at once with Undo (`actions.remove`); without one it does nothing. */
|
|
265
|
+
confirmDelete(comment?: CommentRecord): Promise<void>;
|
|
144
266
|
/**
|
|
145
267
|
* 'on' when people can attach pictures and files: the table has the Attachments column and the host uploads files
|
|
146
268
|
* (signed-in Editors in Notis; never on a Site, a link or a preview). 'off' leaves the pane text only.
|
|
@@ -155,9 +277,6 @@ export interface CommentController {
|
|
|
155
277
|
}): Promise<CommentFile>;
|
|
156
278
|
/** A shown picture failed to load (its signed address expired): reads the comments again, at most twice a minute. */
|
|
157
279
|
refreshFiles(): void;
|
|
158
|
-
deleting: CommentRecord | null;
|
|
159
|
-
cancelDelete(): void;
|
|
160
|
-
confirmDelete(): Promise<void>;
|
|
161
280
|
/** Copies the digest and records the checkpoint. `host` is the Space's own element, for the selection fallback. */
|
|
162
281
|
copyChanges(host: HTMLElement | null): Promise<boolean>;
|
|
163
282
|
copying: boolean;
|
|
@@ -182,6 +301,19 @@ export interface CommentController {
|
|
|
182
301
|
error: Error | null;
|
|
183
302
|
refetch(): Promise<unknown>;
|
|
184
303
|
}
|
|
304
|
+
/** How long a delete's Undo toast stays on a touch screen (a coarse pointer, or a phone-width window). */
|
|
305
|
+
export declare const DELETE_UNDO_TOUCH_MS = 8000;
|
|
306
|
+
/**
|
|
307
|
+
* The link that opens the page with one comment thread revealed: the host's (`commentLink`, a full address that names
|
|
308
|
+
* the thread's own page, possibly later as a promise), else the page's own address with `comment=<root key>` (any
|
|
309
|
+
* earlier comment param replaced). Null when neither is known.
|
|
310
|
+
*/
|
|
311
|
+
export declare function commentLinkFor(host: {
|
|
312
|
+
commentLink?(input: {
|
|
313
|
+
rootKey: string;
|
|
314
|
+
database?: string;
|
|
315
|
+
}): string | null | Promise<string | null>;
|
|
316
|
+
} | null | undefined, rootKey: string, database?: string): string | null | Promise<string | null>;
|
|
185
317
|
/** The neutral author a Comments database's choice list can offer for anyone it does not name. */
|
|
186
318
|
export declare const COMMENT_PERSON_AUTHOR = "Person";
|
|
187
319
|
/**
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The controller for comments on passages of a record's text: a `useComments` controller (reading, live feed,
|
|
3
|
-
* replies,
|
|
4
|
-
* selection, which threads read
|
|
5
|
-
* `PassageCommentPane` render from
|
|
3
|
+
* replies, Archive, Delete, Edit, where a thread goes) plus where each thread sits (its field and quoted words), the
|
|
4
|
+
* comment being written on a selection, which threads read Passage changed (their words are gone; they stay open with
|
|
5
|
+
* the old quote), and the reading order. `CommentableText`, `CommentableRichText` and `PassageCommentPane` render from
|
|
6
|
+
* it. Its modes default to text (a selection) and the whole page.
|
|
6
7
|
*/
|
|
7
8
|
import { type CommentThread } from './commentModel';
|
|
8
|
-
import { type CommentController, type UseCommentsOptions } from './useComments';
|
|
9
|
+
import { type CommentController, type CommentFile, type UseCommentsOptions } from './useComments';
|
|
9
10
|
import { type PassageAnchor, type PassageColumns, type PassageField } from './passageModel';
|
|
10
11
|
/** Where a thread was opened: its highlight in the text, its card or its quote in the pane, or a link to one comment. */
|
|
11
12
|
export type PassageOpenedFrom = 'passage' | 'pane' | 'quote' | 'link';
|
|
@@ -25,11 +26,14 @@ export interface UsePassageCommentsOptions extends Omit<UseCommentsOptions, 'anc
|
|
|
25
26
|
onOpen?(thread: CommentThread, passage: PassageAnchor | undefined, from: PassageOpenedFrom): void;
|
|
26
27
|
/** A selection started a new comment: show the pane, which holds its box. */
|
|
27
28
|
onDraft?(passage: PassageAnchor): void;
|
|
28
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* Open the thread of this comment (a root or a reply) once it is read: a link to one comment. Default: the
|
|
31
|
+
* `comment` view param (`useCommentFocusParam`); null turns that off.
|
|
32
|
+
*/
|
|
29
33
|
focusKey?: string | null;
|
|
30
34
|
}
|
|
31
35
|
export interface PassageCommentController {
|
|
32
|
-
/** The underlying comment controller: thread cards,
|
|
36
|
+
/** The underlying comment controller: thread cards, Archive, Delete, Edit, the status filter, routing and the toast. */
|
|
33
37
|
controller: CommentController;
|
|
34
38
|
fields: readonly PassageField[];
|
|
35
39
|
field(key: string): PassageField | undefined;
|
|
@@ -46,10 +50,15 @@ export interface PassageCommentController {
|
|
|
46
50
|
isChanged(rootKey: string): boolean;
|
|
47
51
|
/** The comment being written on a selection. */
|
|
48
52
|
draft: PassageAnchor | null;
|
|
53
|
+
/** The comment being placed or written on the page (the New comment menu): the same as `controller.draftPin`. */
|
|
54
|
+
draftPin: CommentController['draftPin'];
|
|
49
55
|
startDraft(passage: PassageAnchor): void;
|
|
50
56
|
cancelDraft(): void;
|
|
51
|
-
/**
|
|
52
|
-
|
|
57
|
+
/**
|
|
58
|
+
* Saves the draft with its text and the pictures and files attached to it (SPC-131: paste, drop or the paperclip),
|
|
59
|
+
* either one enough. True once saved; its thread is then selected.
|
|
60
|
+
*/
|
|
61
|
+
send(body: string, files?: readonly CommentFile[]): Promise<boolean>;
|
|
53
62
|
sending: boolean;
|
|
54
63
|
/** The last send failed. */
|
|
55
64
|
failed: boolean;
|
|
@@ -59,8 +68,15 @@ export interface PassageCommentController {
|
|
|
59
68
|
scroll: boolean;
|
|
60
69
|
n: number;
|
|
61
70
|
} | null;
|
|
71
|
+
/**
|
|
72
|
+
* Opens a thread: its passage flashes and the pane selects it. From the page ('passage': a highlight or a field's
|
|
73
|
+
* Comment count) or a link ('link') it is a reveal: `revealRequest` goes up by one and the host shows its Comments
|
|
74
|
+
* panel (C8). From the pane ('pane', 'quote') the panel stays as it is.
|
|
75
|
+
*/
|
|
62
76
|
open(thread: CommentThread, from: PassageOpenedFrom): void;
|
|
63
77
|
openKey(rootKey: string, from: PassageOpenedFrom): void;
|
|
78
|
+
/** Starts at 0 and goes up by one on each comment picked on the page: the same number as `controller.revealRequest`. */
|
|
79
|
+
revealRequest: number;
|
|
64
80
|
/** Rich text on screen reports which passages it shows: Text changed then follows what is rendered. */
|
|
65
81
|
reportFound(field: string, keys: ReadonlySet<string> | null): void;
|
|
66
82
|
}
|
|
@@ -18,12 +18,13 @@ export * from './open';
|
|
|
18
18
|
export * from './blocks';
|
|
19
19
|
export * from './gallery';
|
|
20
20
|
export { Icon, hasIcon, renderIcon } from './icons';
|
|
21
|
-
export { adoptToolkitStyles, getToolkitStyleSheet, getToolkitStyleText, registerToolkitStyles } from './styles';
|
|
22
|
-
export {
|
|
21
|
+
export { adoptToolkitStyles, getToolkitStyleSheet, getToolkitStyleText, registerToolkitStyles, toolkitCascadeFor, TOOLKIT_CASCADE_LAYER } from './styles';
|
|
22
|
+
export type { AdoptToolkitOptions, ToolkitCascade } from './styles';
|
|
23
|
+
export { COMPARES, DEFAULT_COMPARE, DEFAULT_PRESET, EXTRA_PRESETS, PRESETS, compareRange, customPeriod, dayCount, formatPeriodParam, fromIsoDay, isCompareId, isPresetId, normalizePeriod, parsePeriodParam, periodRanges, presetRange, samePeriod, toIsoDay, } from './period/periods';
|
|
23
24
|
export type { CompareId, DateRange as PeriodRange, Period, PresetId } from './period/periods';
|
|
24
25
|
export { dayNumberLabel, formatDateRange, formatDayHeading, formatDelta, formatDuration, formatLongDay, formatMonthYear, formatNumber, formatShortDay, formatValue, intlLocale, weekdayNames, } from './period/dateFormat';
|
|
25
26
|
export type { Delta, DeltaTone, FormatDurationOptions } from './period/dateFormat';
|
|
26
|
-
export { CALENDAR_WORDS, CHART_WORDS, COMPARE_WORDS, PERIOD_WORDS, PRESET_WORDS, TIMELINE_WORDS, VS_WORDS, } from './period/dateWords';
|
|
27
|
+
export { CALENDAR_WORDS, CHART_WORDS, COMPARE_WORDS, HEATMAP_WORDS, PERIOD_WORDS, PRESET_WORDS, TIMELINE_WORDS, VS_WORDS, } from './period/dateWords';
|
|
27
28
|
export { usePeriod } from './period/usePeriod';
|
|
28
29
|
export type { UsePeriodOptions, UsePeriodResult } from './period/usePeriod';
|
|
29
30
|
export { PERIOD_PICKER_TWO_MONTHS_MIN, PeriodPicker } from './period/PeriodPicker';
|
|
@@ -46,6 +47,8 @@ export { StatRow, metricView } from './charts/StatRow';
|
|
|
46
47
|
export type { StatMetric, StatRowProps } from './charts/StatRow';
|
|
47
48
|
export { ChartTable, Sparkline } from './charts/ChartTable';
|
|
48
49
|
export type { ChartTableProps, SparklineProps } from './charts/ChartTable';
|
|
50
|
+
export { CalendarHeatmap } from './charts/CalendarHeatmap';
|
|
51
|
+
export type { CalendarHeatmapDay, CalendarHeatmapProps } from './charts/CalendarHeatmap';
|
|
49
52
|
export { RenderChartData } from './charts/RenderChartData';
|
|
50
53
|
export type { RenderChartDataProps } from './charts/RenderChartData';
|
|
51
54
|
export { Area, AreaChart, Bar, BarChart, CartesianGrid, Cell, ComposedChart, LabelList, Legend, Line, LineChart, Pie, PieChart, ReferenceDot, ReferenceLine, ResponsiveContainer, Scatter, XAxis, YAxis, } from './charts/Chart';
|
|
@@ -23,7 +23,12 @@ export declare function clampSidePaneWidth(want: number, container: number | nul
|
|
|
23
23
|
export interface SidePaneProps {
|
|
24
24
|
/** The page. */
|
|
25
25
|
children: ReactNode;
|
|
26
|
-
/**
|
|
26
|
+
/**
|
|
27
|
+
* The pane, always shown: beside the page while both fit, after it otherwise. A retired comment pane
|
|
28
|
+
* (`CommentPane`, `PassageCommentPane`) shows nothing here: the host Comments panel lists its threads. Only a
|
|
29
|
+
* direct `<CommentPane />` or `<PassageCommentPane />` element passed as `pane` is detected; one wrapped in another
|
|
30
|
+
* element or component keeps its pane column like any other pane.
|
|
31
|
+
*/
|
|
27
32
|
pane: ReactNode;
|
|
28
33
|
/** The page never gets narrower than this beside the pane. */
|
|
29
34
|
mainMin?: number;
|
|
@@ -36,11 +36,21 @@ export interface RowProps {
|
|
|
36
36
|
icon?: ReactNode | {
|
|
37
37
|
status: string;
|
|
38
38
|
};
|
|
39
|
+
/**
|
|
40
|
+
* The lead's size in px, for a lead that is a picture (a meal photo, a cover, a logo) rather than an icon. Default 20;
|
|
41
|
+
* an icon glyph draws at 80% of it. The row grows to fit a lead taller than its title and meta.
|
|
42
|
+
*/
|
|
43
|
+
iconSize?: number;
|
|
39
44
|
title: ReactNode;
|
|
40
45
|
/** The start of the muted line under the title (12/16); `labels` follow it after a " · ". */
|
|
41
46
|
meta?: ReactNode;
|
|
42
47
|
/** One clamped line (13/18). */
|
|
43
48
|
snippet?: ReactNode;
|
|
49
|
+
/**
|
|
50
|
+
* The labels keep their whole width and the meta start truncates first, for labels that say where the row stands
|
|
51
|
+
* (a stage, a plan). Default false: the labels give way first, then the meta start.
|
|
52
|
+
*/
|
|
53
|
+
keepLabels?: boolean;
|
|
44
54
|
/**
|
|
45
55
|
* Words on the meta line, as text joined by ", ". A warning or danger label (Overdue, Failed) comes first as a small
|
|
46
56
|
* tinted pill: state is never shown by text colour alone.
|
|
@@ -153,4 +163,4 @@ export declare function Check(): import("react").JSX.Element;
|
|
|
153
163
|
/** The dash of a partly checked select-all. */
|
|
154
164
|
export declare function Dash(): import("react").JSX.Element;
|
|
155
165
|
/** One list row: lead icon, a title over a meta line, then the trail (trailing, time, avatar, More). */
|
|
156
|
-
export declare function Row({ icon, title, meta, snippet, labels, tags, owner, time, dateOnly, now, trailing, more, state, wrap, className, onPress, pressLabel, }: RowProps): import("react").JSX.Element;
|
|
166
|
+
export declare function Row({ icon, iconSize, title, meta, snippet, keepLabels, labels, tags, owner, time, dateOnly, now, trailing, more, state, wrap, className, onPress, pressLabel, }: RowProps): import("react").JSX.Element;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Tooltip (toolkit spec 2.8): a label and an optional shortcut on a black pill, the Manager's tooltip. Shows after
|
|
3
3
|
* 500ms of hover or at once on keyboard focus; hides on leave, blur, a press or any key. Never takes focus.
|
|
4
|
+
* With `card`, it shows that content on a popover card instead (the chat timeline's hover card), still never focusable.
|
|
4
5
|
*/
|
|
5
|
-
import React, { type ReactElement } from 'react';
|
|
6
|
+
import React, { type ReactElement, type ReactNode } from 'react';
|
|
6
7
|
import type { KeySpec, Words } from '../../words';
|
|
7
8
|
import type { Align, Side } from './position';
|
|
8
9
|
export interface TooltipProps {
|
|
@@ -15,5 +16,10 @@ export interface TooltipProps {
|
|
|
15
16
|
/** One focusable element. */
|
|
16
17
|
children: ReactElement;
|
|
17
18
|
disabled?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Rich content shown on a popover card in place of the label (several lines, logos). The card only describes the
|
|
21
|
+
* trigger (aria-describedby), so give the trigger an accessible name that says the same in words.
|
|
22
|
+
*/
|
|
23
|
+
card?: ReactNode;
|
|
18
24
|
}
|
|
19
|
-
export declare function Tooltip({ label, keys, side, align, delay, children, disabled }: TooltipProps): React.JSX.Element;
|
|
25
|
+
export declare function Tooltip({ label, keys, side, align, delay, children, disabled, card }: TooltipProps): React.JSX.Element;
|
|
@@ -10,6 +10,8 @@ export declare function intlLocale(locale: Locale): string;
|
|
|
10
10
|
export declare function dateFormat(locale: Locale, options: Intl.DateTimeFormatOptions): Intl.DateTimeFormat;
|
|
11
11
|
/** The text with its first letter upper case ("lundi" reads "Lundi"). */
|
|
12
12
|
export declare function upFirst(text: string): string;
|
|
13
|
+
/** A date through `fmt`, French writing the first of the month "1er". */
|
|
14
|
+
export declare function formatDay(fmt: Intl.DateTimeFormat, date: Date, locale: Locale): string;
|
|
13
15
|
/**
|
|
14
16
|
* A date range in words, never a dash: "May 17 to Jun 15, 2026" / "17 mai au 15 juin 2026". A month or year both days
|
|
15
17
|
* share shows once ("Oct 1 to 15, 2026" / "1er au 15 oct. 2026"). One day reads as that day.
|
|
@@ -32,6 +32,15 @@ export declare const CHART_WORDS: Readonly<{
|
|
|
32
32
|
stats: Words;
|
|
33
33
|
noValue: Words;
|
|
34
34
|
}>;
|
|
35
|
+
/** The calendar heatmap (CalendarHeatmap): a day's cell, its legend and its default name. */
|
|
36
|
+
export declare const HEATMAP_WORDS: Readonly<{
|
|
37
|
+
title: Words;
|
|
38
|
+
/** A day's cell and its tooltip: the value (through `format`), then the day. */
|
|
39
|
+
day: Words;
|
|
40
|
+
noData: Words;
|
|
41
|
+
less: Words;
|
|
42
|
+
more: Words;
|
|
43
|
+
}>;
|
|
35
44
|
export declare const CALENDAR_WORDS: Readonly<{
|
|
36
45
|
month: Words;
|
|
37
46
|
week: Words;
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* `2026-01-01..2026-01-31~none` custom range
|
|
11
11
|
* The comparison is left out when it equals the default, so links stay short.
|
|
12
12
|
*/
|
|
13
|
-
export type PresetId = 'today' | 'yesterday' | 'last7' | 'last30' | 'last90' | 'thisMonth' | 'lastMonth' | 'thisQuarter' | 'thisYear' | 'custom';
|
|
13
|
+
export type PresetId = 'today' | 'yesterday' | 'last7' | 'last30' | 'last90' | 'thisMonth' | 'lastMonth' | 'thisQuarter' | 'thisYear' | 'last6Months' | 'last12Months' | 'custom';
|
|
14
14
|
export type CompareId = 'prev' | 'year' | 'none';
|
|
15
15
|
export interface Period {
|
|
16
16
|
preset: PresetId;
|
|
@@ -25,6 +25,12 @@ export interface DateRange {
|
|
|
25
25
|
to: Date;
|
|
26
26
|
}
|
|
27
27
|
export declare const PRESETS: readonly PresetId[];
|
|
28
|
+
/**
|
|
29
|
+
* Presets a picker can offer that the default list leaves out: trailing windows of whole months (this month and the 5
|
|
30
|
+
* or 11 before it), for monthly figures such as spending. Pass them in `presets`, such as
|
|
31
|
+
* `[...PRESETS.slice(0, -1), ...EXTRA_PRESETS, 'custom']`.
|
|
32
|
+
*/
|
|
33
|
+
export declare const EXTRA_PRESETS: readonly PresetId[];
|
|
28
34
|
export declare const COMPARES: readonly CompareId[];
|
|
29
35
|
export declare const DEFAULT_PRESET: PresetId;
|
|
30
36
|
export declare const DEFAULT_COMPARE: CompareId;
|
|
@@ -44,9 +50,16 @@ export declare function presetRange(preset: PresetId, now?: Date, custom?: {
|
|
|
44
50
|
from?: string;
|
|
45
51
|
to?: string;
|
|
46
52
|
}): DateRange;
|
|
53
|
+
/**
|
|
54
|
+
* The calendar months a range spans when it is binned by month: it starts on the 1st and spans six months or more
|
|
55
|
+
* (Last 6 months, Last 12 months, a year to date from June). 0 otherwise.
|
|
56
|
+
*/
|
|
57
|
+
export declare function monthSpan(range: DateRange): number;
|
|
47
58
|
/**
|
|
48
59
|
* The range a period is compared with.
|
|
49
|
-
* - prev: the same number of days just before (`[from - n, from - 1]`).
|
|
60
|
+
* - prev: the same number of days just before (`[from - n, from - 1]`). A range binned by month (`monthSpan`: it
|
|
61
|
+
* starts on the 1st and spans six calendar months or more, such as Last 6 months) moves back by that many months
|
|
62
|
+
* instead, so each month is compared with a whole month; a range ending on a month's last day ends on one too.
|
|
50
63
|
* - year: the same calendar days one year back (29 February lands on 28 February).
|
|
51
64
|
* - none: no comparison.
|
|
52
65
|
*/
|
|
@@ -6,16 +6,38 @@
|
|
|
6
6
|
* the SDK never looks for the sheet among the page's own stylesheets, because a host that bundles its CSS would hand
|
|
7
7
|
* over its whole merged stylesheet instead of the toolkit.
|
|
8
8
|
*/
|
|
9
|
+
/**
|
|
10
|
+
* The cascade layer the toolkit sits in inside a Space shadow root. It comes after Tailwind 4's preflight (`base`) and
|
|
11
|
+
* before its `utilities`, so a Space's utilities and its own CSS override a toolkit piece (`hidden sm:flex`, `px-6`)
|
|
12
|
+
* the way they override any element, while preflight never reaches it. The SDK shell (`styles.css`) sits just before.
|
|
13
|
+
*/
|
|
14
|
+
export declare const TOOLKIT_CASCADE_LAYER = "components.notis-toolkit";
|
|
15
|
+
/**
|
|
16
|
+
* How the toolkit joins a root's cascade. `layered` (the default): in TOOLKIT_CASCADE_LAYER. `unlayered`: as plain
|
|
17
|
+
* rules, for a Space built with Tailwind 3, whose preflight is unlayered and would otherwise reset toolkit buttons.
|
|
18
|
+
*/
|
|
19
|
+
export type ToolkitCascade = 'layered' | 'unlayered';
|
|
20
|
+
/**
|
|
21
|
+
* The cascade a Space's own compiled CSS needs: `unlayered` for Tailwind 3 output (its banner, or `--tw-` rules with
|
|
22
|
+
* no Tailwind 4 `base` or `utilities` layer block; the SDK stylesheet's order statement and its own sublayer do not
|
|
23
|
+
* count), else `layered`.
|
|
24
|
+
*/
|
|
25
|
+
export declare function toolkitCascadeFor(css: string | null | undefined): ToolkitCascade;
|
|
9
26
|
/** Registers the toolkit stylesheet: its CSS text, or an already built sheet. Later roots adopt this one. */
|
|
10
27
|
export declare function registerToolkitStyles(source: string | CSSStyleSheet): void;
|
|
11
|
-
/** The registered toolkit CSS text; null until the host registers it. */
|
|
28
|
+
/** The registered toolkit CSS text, as registered (no layer); null until the host registers it. */
|
|
12
29
|
export declare function getToolkitStyleText(): string | null;
|
|
13
|
-
/** The shared sheet; null without constructable stylesheets or until the host registers the CSS. */
|
|
14
|
-
export declare function getToolkitStyleSheet(): CSSStyleSheet | null;
|
|
30
|
+
/** The shared sheet for a cascade; null without constructable stylesheets or until the host registers the CSS. */
|
|
31
|
+
export declare function getToolkitStyleSheet(cascade?: ToolkitCascade): CSSStyleSheet | null;
|
|
32
|
+
export interface AdoptToolkitOptions {
|
|
33
|
+
/** Default `layered`; pass `toolkitCascadeFor(spaceCss)` when the Space's CSS is known. */
|
|
34
|
+
cascade?: ToolkitCascade;
|
|
35
|
+
}
|
|
15
36
|
/**
|
|
16
37
|
* Adds the registered toolkit sheet to a document or shadow root, once. Without constructable stylesheets the root
|
|
17
|
-
* gets one `<style>` element instead.
|
|
38
|
+
* gets one `<style>` element instead. Adopting again with the other cascade swaps the sheet in place. Returns false,
|
|
39
|
+
* and adds nothing, while the host has not registered the CSS.
|
|
18
40
|
*/
|
|
19
|
-
export declare function adoptToolkitStyles(root: Document | ShadowRoot): boolean;
|
|
41
|
+
export declare function adoptToolkitStyles(root: Document | ShadowRoot, options?: AdoptToolkitOptions): boolean;
|
|
20
42
|
/** Test hook: forget the registered sheet. */
|
|
21
43
|
export declare function resetToolkitStylesForTests(): void;
|
|
@@ -48,6 +48,34 @@ export function fillWords(words: Words, vars: Readonly<Record<string, string | n
|
|
|
48
48
|
return { en: interpolate(words.en, vars), fr: interpolate(words.fr, vars) };
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
const PLURAL_INTL = new Map<Locale, { rules: Intl.PluralRules; number: Intl.NumberFormat }>();
|
|
52
|
+
function pluralIntl(locale: Locale) {
|
|
53
|
+
let intl = PLURAL_INTL.get(locale);
|
|
54
|
+
if (!intl) {
|
|
55
|
+
const tag = locale === 'fr' ? 'fr-FR' : 'en-US';
|
|
56
|
+
intl = { rules: new Intl.PluralRules(tag), number: new Intl.NumberFormat(tag) };
|
|
57
|
+
PLURAL_INTL.set(locale, intl);
|
|
58
|
+
}
|
|
59
|
+
return intl;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The words for a count, in the grammar of each language: English "1 campaign" / "2 campaigns", French "1 campagne" /
|
|
64
|
+
* "2 campagnes" (French also uses the singular for 0 and 1.5). `forms` holds the singular (`one`) and the plural
|
|
65
|
+
* (`other`) of each language; `{n}` in them is the count as written in that locale ("1,250" / "1 250").
|
|
66
|
+
* `pluralWords(3, { one: w('{n} campaign', '{n} campagne'), other: w('{n} campaigns', '{n} campagnes') })`.
|
|
67
|
+
*/
|
|
68
|
+
export function pluralWords(count: number, forms: { one: Words; other: Words }): Words {
|
|
69
|
+
const form = (locale: Locale) => {
|
|
70
|
+
const intl = pluralIntl(locale);
|
|
71
|
+
const rule = Number.isFinite(count) ? intl.rules.select(count) : 'other';
|
|
72
|
+
const words = rule === 'one' ? forms.one : forms.other;
|
|
73
|
+
const n = Number.isFinite(count) ? intl.number.format(count) : String(count);
|
|
74
|
+
return interpolate(locale === 'fr' ? words.fr : words.en, { n });
|
|
75
|
+
};
|
|
76
|
+
return { en: form('en'), fr: form('fr') };
|
|
77
|
+
}
|
|
78
|
+
|
|
51
79
|
/** Shorthand for a Words pair. */
|
|
52
80
|
export function w(en: string, fr: string): Words {
|
|
53
81
|
return { en, fr };
|