@whity/ui 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (205) hide show
  1. package/README.md +106 -2
  2. package/package.json +219 -4
  3. package/src/access-denied.stories.tsx +179 -0
  4. package/src/access-denied.tsx +305 -0
  5. package/src/action-proposal.tsx +338 -0
  6. package/src/actor-chip.tsx +71 -0
  7. package/src/agent-activity.tsx +163 -0
  8. package/src/agent-collaboration.stories.tsx +156 -0
  9. package/src/agent-run-status.tsx +196 -0
  10. package/src/alert-dialog.stories.tsx +45 -0
  11. package/src/alert-dialog.tsx +147 -0
  12. package/src/alert.stories.tsx +91 -0
  13. package/src/alert.tsx +89 -0
  14. package/src/app-sidebar.stories.tsx +195 -0
  15. package/src/app-sidebar.tsx +604 -0
  16. package/src/approval-queue.tsx +109 -0
  17. package/src/audience-group-picker.stories.tsx +198 -0
  18. package/src/audience-group-picker.tsx +362 -0
  19. package/src/audience-people-picker.stories.tsx +102 -0
  20. package/src/audience-people-picker.tsx +279 -0
  21. package/src/avatar-pattern.ts +138 -0
  22. package/src/avatar.tsx +125 -0
  23. package/src/badge.stories.tsx +105 -0
  24. package/src/badge.tsx +68 -0
  25. package/src/beta-warning.stories.tsx +79 -0
  26. package/src/beta-warning.tsx +189 -0
  27. package/src/bilingual-input.stories.tsx +82 -0
  28. package/src/bilingual-input.tsx +188 -0
  29. package/src/board.tsx +216 -0
  30. package/src/breadcrumb.stories.tsx +51 -0
  31. package/src/breadcrumb.tsx +90 -0
  32. package/src/built-on-whity.tsx +52 -0
  33. package/src/button.stories.tsx +87 -0
  34. package/src/button.tsx +123 -0
  35. package/src/card.stories.tsx +423 -0
  36. package/src/card.tsx +180 -0
  37. package/src/chart.stories.tsx +66 -0
  38. package/src/chart.tsx +228 -0
  39. package/src/checkbox.stories.tsx +62 -0
  40. package/src/checkbox.tsx +54 -0
  41. package/src/collapsible.stories.tsx +48 -0
  42. package/src/collapsible.tsx +34 -0
  43. package/src/color-card.stories.tsx +61 -0
  44. package/src/color-card.tsx +270 -0
  45. package/src/color-picker.stories.tsx +65 -0
  46. package/src/color-picker.tsx +425 -0
  47. package/src/column-matcher.tsx +84 -0
  48. package/src/command-palette.tsx +398 -0
  49. package/src/confirm-action.tsx +98 -0
  50. package/src/copy-block.stories.tsx +38 -0
  51. package/src/copy-block.tsx +85 -0
  52. package/src/data-table.stories.tsx +200 -0
  53. package/src/data-table.tsx +1686 -0
  54. package/src/date-picker.stories.tsx +61 -0
  55. package/src/date-picker.tsx +456 -0
  56. package/src/design-cards.stories.tsx +551 -0
  57. package/src/dialog.stories.tsx +48 -0
  58. package/src/dialog.tsx +179 -0
  59. package/src/display-preferences.tsx +50 -0
  60. package/src/documents/barcode-svg.stories.tsx +72 -0
  61. package/src/documents/barcode-svg.tsx +79 -0
  62. package/src/dropdown-menu.stories.tsx +77 -0
  63. package/src/dropdown-menu.tsx +271 -0
  64. package/src/editor/agent-panel.tsx +222 -0
  65. package/src/editor/agents.stories.tsx +81 -0
  66. package/src/editor/agents.ts +55 -0
  67. package/src/editor/behaviour.ts +279 -0
  68. package/src/editor/block-ids.ts +44 -0
  69. package/src/editor/block-list.tsx +104 -0
  70. package/src/editor/block-toolbar.tsx +490 -0
  71. package/src/editor/bubble.tsx +119 -0
  72. package/src/editor/catalogue.ts +169 -0
  73. package/src/editor/collab-rail.tsx +746 -0
  74. package/src/editor/collab.stories.tsx +207 -0
  75. package/src/editor/collab.ts +87 -0
  76. package/src/editor/contract.ts +476 -0
  77. package/src/editor/convert.ts +414 -0
  78. package/src/editor/doc-editor.stories.tsx +98 -0
  79. package/src/editor/doc-editor.tsx +1492 -0
  80. package/src/editor/editor.css +636 -0
  81. package/src/editor/extensions.ts +86 -0
  82. package/src/editor/field-bar.tsx +154 -0
  83. package/src/editor/field-picker.tsx +109 -0
  84. package/src/editor/fields.ts +100 -0
  85. package/src/editor/gutter.tsx +443 -0
  86. package/src/editor/index.ts +23 -0
  87. package/src/editor/label-sheet.tsx +289 -0
  88. package/src/editor/labels.ts +394 -0
  89. package/src/editor/link-tools.tsx +141 -0
  90. package/src/editor/node-views.tsx +461 -0
  91. package/src/editor/page-view.tsx +372 -0
  92. package/src/editor/phone.tsx +310 -0
  93. package/src/editor/plugin-block-view.tsx +230 -0
  94. package/src/editor/plugin-blocks.stories.tsx +96 -0
  95. package/src/editor/plugin-blocks.ts +52 -0
  96. package/src/editor/publish-check.tsx +201 -0
  97. package/src/editor/rich-blocks.stories.tsx +146 -0
  98. package/src/editor/sample.ts +40 -0
  99. package/src/editor/save-block-dialog.tsx +141 -0
  100. package/src/editor/saved-block-view.tsx +205 -0
  101. package/src/editor/saved-blocks.stories.tsx +105 -0
  102. package/src/editor/saved-parts.ts +192 -0
  103. package/src/editor/schema-rich.ts +156 -0
  104. package/src/editor/schema.ts +368 -0
  105. package/src/editor/services.tsx +205 -0
  106. package/src/editor/slash.ts +64 -0
  107. package/src/editor/suggesting.ts +372 -0
  108. package/src/editor/suggestions.ts +763 -0
  109. package/src/editor/table-keys.ts +66 -0
  110. package/src/editor/templates.stories.tsx +324 -0
  111. package/src/editor/toolbar.tsx +364 -0
  112. package/src/empty-state.stories.tsx +51 -0
  113. package/src/empty-state.tsx +126 -0
  114. package/src/empty-state.usage-notes.md +30 -0
  115. package/src/form.stories.tsx +112 -0
  116. package/src/form.tsx +176 -0
  117. package/src/globals.css +20 -0
  118. package/src/icon-button.tsx +85 -0
  119. package/src/icon-map.ts +335 -0
  120. package/src/icon.tsx +41 -0
  121. package/src/index.ts +90 -0
  122. package/src/input.stories.tsx +157 -0
  123. package/src/input.tsx +768 -0
  124. package/src/kpi-strip.tsx +47 -0
  125. package/src/localized-text.ts +76 -0
  126. package/src/locked-screen.stories.tsx +29 -0
  127. package/src/locked-screen.tsx +75 -0
  128. package/src/lockup.tsx +42 -0
  129. package/src/lottie.tsx +441 -0
  130. package/src/mark.tsx +62 -0
  131. package/src/math-text.stories.tsx +33 -0
  132. package/src/math-text.tsx +43 -0
  133. package/src/menu-bar.stories.tsx +198 -0
  134. package/src/menu-bar.tsx +373 -0
  135. package/src/message-thread.tsx +181 -0
  136. package/src/money/currency.ts +244 -0
  137. package/src/money/money-input.tsx +131 -0
  138. package/src/money/money.tsx +33 -0
  139. package/src/open-on-computer.tsx +150 -0
  140. package/src/otp-input.tsx +161 -0
  141. package/src/page-header.stories.tsx +95 -0
  142. package/src/page-header.tsx +122 -0
  143. package/src/page-shell.stories.tsx +42 -0
  144. package/src/page-shell.tsx +32 -0
  145. package/src/page-states.tsx +277 -0
  146. package/src/pagination.stories.tsx +45 -0
  147. package/src/pagination.tsx +98 -0
  148. package/src/paper-sheet.stories.tsx +88 -0
  149. package/src/paper-sheet.tsx +85 -0
  150. package/src/phone-tab-bar.tsx +152 -0
  151. package/src/plugin-card.stories.tsx +208 -0
  152. package/src/plugin-card.tsx +931 -0
  153. package/src/popover.stories.tsx +48 -0
  154. package/src/popover.tsx +55 -0
  155. package/src/radio-group.stories.tsx +26 -0
  156. package/src/radio-group.tsx +44 -0
  157. package/src/route-flow/editor.tsx +1087 -0
  158. package/src/route-flow/model.ts +771 -0
  159. package/src/save-bar.tsx +94 -0
  160. package/src/scope-grant.tsx +139 -0
  161. package/src/screen-too-small.stories.tsx +61 -0
  162. package/src/screen-too-small.tsx +104 -0
  163. package/src/search-field.tsx +65 -0
  164. package/src/select.stories.tsx +44 -0
  165. package/src/select.tsx +197 -0
  166. package/src/separator.stories.tsx +34 -0
  167. package/src/separator.tsx +34 -0
  168. package/src/sheet.stories.tsx +49 -0
  169. package/src/sheet.tsx +168 -0
  170. package/src/skeleton.stories.tsx +28 -0
  171. package/src/skeleton.tsx +19 -0
  172. package/src/slider.stories.tsx +78 -0
  173. package/src/slider.tsx +300 -0
  174. package/src/spinner.stories.tsx +33 -0
  175. package/src/spinner.tsx +55 -0
  176. package/src/stepper.tsx +85 -0
  177. package/src/switch.stories.tsx +42 -0
  178. package/src/switch.tsx +41 -0
  179. package/src/switcher.stories.tsx +111 -0
  180. package/src/switcher.tsx +131 -0
  181. package/src/system-state.tsx +55 -0
  182. package/src/table.stories.tsx +48 -0
  183. package/src/table.tsx +121 -0
  184. package/src/tabs.stories.tsx +74 -0
  185. package/src/tabs.tsx +90 -0
  186. package/src/tag-input.stories.tsx +67 -0
  187. package/src/tag-input.tsx +117 -0
  188. package/src/tenant-logo.tsx +63 -0
  189. package/src/tenant-switcher.stories.tsx +38 -0
  190. package/src/tenant-switcher.tsx +164 -0
  191. package/src/textarea.stories.tsx +27 -0
  192. package/src/textarea.tsx +18 -0
  193. package/src/theme-mode.ts +52 -0
  194. package/src/time-grid.tsx +163 -0
  195. package/src/time-picker.stories.tsx +62 -0
  196. package/src/time-picker.tsx +615 -0
  197. package/src/toggle-group.tsx +138 -0
  198. package/src/tooltip.stories.tsx +43 -0
  199. package/src/tooltip.tsx +73 -0
  200. package/src/top-nav.stories.tsx +58 -0
  201. package/src/top-nav.tsx +324 -0
  202. package/src/undo-bar.tsx +107 -0
  203. package/src/utils.ts +45 -0
  204. package/src/view-toggle.stories.tsx +84 -0
  205. package/src/view-toggle.tsx +110 -0
@@ -0,0 +1,289 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+ import type { Editor } from "@tiptap/core"
5
+
6
+ import { Icon } from "../icon"
7
+ import { Input } from "../input"
8
+ import { Popover, PopoverContent, PopoverTrigger } from "../popover"
9
+ import { ToggleGroup } from "../toggle-group"
10
+ import { cn } from "../utils"
11
+ import type { LabelGrid, ResolvedThemeTokens } from "./contract"
12
+ import { fill, type EditorLabels } from "./labels"
13
+ import { themeStyle } from "./page-view"
14
+
15
+ /** 96 dpi, as the page view (EditorPageView). */
16
+ const PX_PER_MM = 96 / 25.4
17
+
18
+ /** The sheets a label document prints on (E.43): A4 or Letter, portrait. */
19
+ export const SHEETS = {
20
+ A4: { widthMm: 210, heightMm: 297 },
21
+ Letter: { widthMm: 215.9, heightMm: 279.4 },
22
+ } as const
23
+ export type SheetSize = keyof typeof SHEETS
24
+
25
+ /**
26
+ * Common label stock. The grid is centred on the sheet, which matches these
27
+ * sheets' own margins to within half a millimetre. A certificate is a
28
+ * one-label sheet.
29
+ */
30
+ export const LABEL_PRESETS: { id: string; name: string; sheet: SheetSize; grid: LabelGrid }[] = [
31
+ { id: "avery-l7160", name: "Avery L7160", sheet: "A4", grid: { columns: 3, rows: 7, size: { widthMm: 63.5, heightMm: 38.1 }, gapMm: 2.5, gapYMm: 0 } },
32
+ { id: "avery-l7159", name: "Avery L7159", sheet: "A4", grid: { columns: 3, rows: 8, size: { widthMm: 63.5, heightMm: 33.9 }, gapMm: 2.5, gapYMm: 0 } },
33
+ { id: "avery-l7165", name: "Avery L7165", sheet: "A4", grid: { columns: 2, rows: 4, size: { widthMm: 99.1, heightMm: 67.7 }, gapMm: 2.5, gapYMm: 0 } },
34
+ { id: "avery-l7651", name: "Avery L7651", sheet: "A4", grid: { columns: 5, rows: 13, size: { widthMm: 38.1, heightMm: 21.2 }, gapMm: 2.5, gapYMm: 0 } },
35
+ { id: "letter-2x5", name: "Letter 2 × 5", sheet: "Letter", grid: { columns: 2, rows: 5, size: { widthMm: 101.6, heightMm: 50.8 }, gapMm: 4.8, gapYMm: 0 } },
36
+ { id: "certificate", name: "Certificate", sheet: "A4", grid: { columns: 1, rows: 1, size: { widthMm: 190, heightMm: 277 }, gapMm: 0 } },
37
+ ]
38
+
39
+ export const DEFAULT_LABEL_GRID: LabelGrid = LABEL_PRESETS[0].grid
40
+
41
+ /** Where each label sits on the sheet, in mm from the top start corner. */
42
+ export function labelCells(grid: LabelGrid, sheet: SheetSize): { x: number; y: number }[] {
43
+ const { widthMm, heightMm } = SHEETS[sheet]
44
+ const gapX = grid.gapMm
45
+ const gapY = grid.gapYMm ?? grid.gapMm
46
+ const left = (widthMm - grid.columns * grid.size.widthMm - (grid.columns - 1) * gapX) / 2
47
+ const top = (heightMm - grid.rows * grid.size.heightMm - (grid.rows - 1) * gapY) / 2
48
+ const cells: { x: number; y: number }[] = []
49
+ for (let r = 0; r < grid.rows; r++) {
50
+ for (let c = 0; c < grid.columns; c++) {
51
+ cells.push({ x: left + c * (grid.size.widthMm + gapX), y: top + r * (grid.size.heightMm + gapY) })
52
+ }
53
+ }
54
+ return cells
55
+ }
56
+
57
+ /** Whether the labels fit on the sheet. */
58
+ export function gridFits(grid: LabelGrid, sheet: SheetSize): boolean {
59
+ const cells = labelCells(grid, sheet)
60
+ const last = cells[cells.length - 1]
61
+ const { widthMm, heightMm } = SHEETS[sheet]
62
+ return !!last && cells[0].x >= 0 && cells[0].y >= 0 && last.x + grid.size.widthMm <= widthMm + 0.01 && last.y + grid.size.heightMm <= heightMm + 0.01
63
+ }
64
+
65
+ /** The inner padding of a label, in px (2 mm). */
66
+ const LABEL_PAD = Math.round(2 * PX_PER_MM)
67
+
68
+ /**
69
+ * The page view of a label sheet (E.43): one sheet with the grid. The first
70
+ * label is the one you edit; the others repeat it, as Print fills one label
71
+ * per record or CSV row. Content that runs past the label is cut off on
72
+ * paper, so the label shows where it ends and `onOverflow` reports it.
73
+ */
74
+ export function LabelSheetView({
75
+ editor,
76
+ grid,
77
+ sheet,
78
+ zoom,
79
+ theme,
80
+ labels,
81
+ onOverflow,
82
+ children,
83
+ }: {
84
+ editor: Editor | null
85
+ grid: LabelGrid
86
+ sheet: SheetSize
87
+ zoom: number
88
+ /** The document's resolved theme: the print colour, and the headings with `title-and-headings`. */
89
+ theme?: ResolvedThemeTokens | null
90
+ labels: EditorLabels
91
+ onOverflow?: (overflow: boolean) => void
92
+ children: React.ReactNode
93
+ }) {
94
+ const cells = labelCells(grid, sheet)
95
+ const w = SHEETS[sheet].widthMm * PX_PER_MM
96
+ const h = SHEETS[sheet].heightMm * PX_PER_MM
97
+ const copies = React.useRef<(HTMLDivElement | null)[]>([])
98
+ const first = React.useRef<HTMLDivElement>(null)
99
+ const [overflow, setOverflow] = React.useState(false)
100
+
101
+ React.useEffect(() => {
102
+ if (!editor) return
103
+ let frame = 0
104
+ const mirror = () => {
105
+ cancelAnimationFrame(frame)
106
+ frame = requestAnimationFrame(() => {
107
+ if (editor.isDestroyed) return
108
+ const source = editor.view.dom
109
+ for (const slot of copies.current) {
110
+ if (!slot) continue
111
+ const copy = source.cloneNode(true) as HTMLElement
112
+ copy.removeAttribute("contenteditable")
113
+ copy.removeAttribute("role")
114
+ copy.removeAttribute("aria-label")
115
+ copy.removeAttribute("aria-multiline")
116
+ copy.classList.remove("ProseMirror-focused")
117
+ slot.replaceChildren(copy)
118
+ }
119
+ const box = first.current
120
+ const over = !!box && source.scrollHeight > box.clientHeight - 2 * LABEL_PAD + 1
121
+ setOverflow(over)
122
+ })
123
+ }
124
+ mirror()
125
+ editor.on("update", mirror)
126
+ const dom = editor.view.dom
127
+ dom.addEventListener("load", mirror, true)
128
+ return () => {
129
+ cancelAnimationFrame(frame)
130
+ editor.off("update", mirror)
131
+ dom.removeEventListener("load", mirror, true)
132
+ }
133
+ }, [editor, grid, sheet])
134
+
135
+ React.useEffect(() => onOverflow?.(overflow), [overflow, onOverflow])
136
+
137
+ const place = (i: number): React.CSSProperties => ({
138
+ insetInlineStart: cells[i].x * PX_PER_MM,
139
+ top: cells[i].y * PX_PER_MM,
140
+ width: grid.size.widthMm * PX_PER_MM,
141
+ height: grid.size.heightMm * PX_PER_MM,
142
+ padding: LABEL_PAD,
143
+ })
144
+
145
+ return (
146
+ <div className="wy-pv" style={{ zoom, width: w } as React.CSSProperties}>
147
+ <div className="wy-pv__stack wy-ls light" data-accent-use={theme?.accentUse} style={{ ...themeStyle(theme), width: w, height: h }}>
148
+ <div className="wy-pv__page" style={{ top: 0, width: w, height: h }} aria-hidden="true" />
149
+ {cells.map((_, i) =>
150
+ i === 0 ? (
151
+ <div key={i} ref={first} className={cn("wy-ls__label is-first", overflow && "is-over")} style={place(i)}>
152
+ {children}
153
+ {overflow && (
154
+ <span className="wy-ls__over" role="status">
155
+ <Icon name="alert" size={12} />
156
+ {labels.labelOverflow}
157
+ </span>
158
+ )}
159
+ </div>
160
+ ) : (
161
+ <div
162
+ key={i}
163
+ ref={(el) => {
164
+ copies.current[i - 1] = el
165
+ }}
166
+ className="wy-ls__label"
167
+ style={place(i)}
168
+ aria-hidden="true"
169
+ inert
170
+ />
171
+ )
172
+ )}
173
+ </div>
174
+ </div>
175
+ )
176
+ }
177
+
178
+ /** The sheet setup for a label document: a stock preset, or the grid by hand. */
179
+ export function LabelSetup({
180
+ grid,
181
+ sheet,
182
+ onChange,
183
+ labels,
184
+ disabled,
185
+ }: {
186
+ grid: LabelGrid
187
+ sheet: SheetSize
188
+ onChange: (grid: LabelGrid, sheet: SheetSize) => void
189
+ labels: EditorLabels
190
+ disabled?: boolean
191
+ }) {
192
+ const preset = LABEL_PRESETS.find((p) => p.sheet === sheet && sameGrid(p.grid, grid))
193
+ const fits = gridFits(grid, sheet)
194
+ const num = (value: number, set: (n: number) => LabelGrid, opts: { min: number; max: number; step: number; label: string }) => (
195
+ <Input
196
+ label={opts.label}
197
+ type="number"
198
+ inputMode="decimal"
199
+ min={opts.min}
200
+ max={opts.max}
201
+ step={opts.step}
202
+ value={value}
203
+ onChange={(e) => {
204
+ const n = Number(e.target.value)
205
+ if (Number.isFinite(n) && n >= opts.min && n <= opts.max) onChange(set(n), sheet)
206
+ }}
207
+ />
208
+ )
209
+
210
+ return (
211
+ <Popover>
212
+ <PopoverTrigger asChild>
213
+ <button
214
+ type="button"
215
+ disabled={disabled}
216
+ className="inline-flex h-7 items-center gap-1 rounded-control px-2 text-xs text-foreground hover:bg-accent disabled:opacity-50"
217
+ >
218
+ <Icon name="table" size={14} />
219
+ {fill(labels.labelGrid, { columns: grid.columns, rows: grid.rows })}
220
+ <Icon name="chevron-down" size={12} />
221
+ </button>
222
+ </PopoverTrigger>
223
+ <PopoverContent align="end" className="grid w-[300px] gap-3">
224
+ <div className="grid gap-1">
225
+ <span className="text-xs font-semibold text-foreground">{labels.labelStock}</span>
226
+ <div role="listbox" aria-label={labels.labelStock} className="grid gap-0.5">
227
+ {LABEL_PRESETS.map((p) => (
228
+ <button
229
+ key={p.id}
230
+ type="button"
231
+ role="option"
232
+ aria-selected={p === preset}
233
+ onClick={() => onChange(p.grid, p.sheet)}
234
+ className={cn(
235
+ "flex items-center justify-between rounded-control px-2 py-1.5 text-start text-sm hover:bg-accent",
236
+ p === preset && "bg-primary-tint text-primary-tint-foreground"
237
+ )}
238
+ >
239
+ <span>{p.id === "certificate" ? labels.labelCertificate : p.name}</span>
240
+ <span className="text-xs text-muted-foreground" dir="ltr">
241
+ {p.sheet} · {p.grid.columns} × {p.grid.rows}
242
+ </span>
243
+ </button>
244
+ ))}
245
+ </div>
246
+ </div>
247
+ <div className="grid grid-cols-2 gap-2">
248
+ <div className="col-span-2 flex items-center justify-between gap-2 text-xs text-muted-foreground">
249
+ {labels.labelSheet}
250
+ <ToggleGroup
251
+ size="sm"
252
+ label={labels.labelSheet}
253
+ required
254
+ value={sheet}
255
+ onChange={(v) => v && onChange(grid, v as SheetSize)}
256
+ options={[
257
+ { value: "A4", label: "A4" },
258
+ { value: "Letter", label: "Letter" },
259
+ ]}
260
+ />
261
+ </div>
262
+ {num(grid.columns, (n) => ({ ...grid, columns: Math.round(n) }), { min: 1, max: 10, step: 1, label: labels.labelColumns })}
263
+ {num(grid.rows, (n) => ({ ...grid, rows: Math.round(n) }), { min: 1, max: 30, step: 1, label: labels.labelRows })}
264
+ {num(grid.size.widthMm, (n) => ({ ...grid, size: { ...grid.size, widthMm: n } }), { min: 10, max: 216, step: 0.1, label: labels.labelWidth })}
265
+ {num(grid.size.heightMm, (n) => ({ ...grid, size: { ...grid.size, heightMm: n } }), { min: 10, max: 297, step: 0.1, label: labels.labelHeight })}
266
+ {num(grid.gapMm, (n) => ({ ...grid, gapMm: n }), { min: 0, max: 20, step: 0.1, label: labels.labelGapX })}
267
+ {num(grid.gapYMm ?? grid.gapMm, (n) => ({ ...grid, gapYMm: n }), { min: 0, max: 20, step: 0.1, label: labels.labelGapY })}
268
+ </div>
269
+ {!fits && (
270
+ <p role="alert" className="m-0 flex items-center gap-1.5 text-xs text-error-text">
271
+ <Icon name="alert" size={12} />
272
+ {labels.labelTooBig}
273
+ </p>
274
+ )}
275
+ </PopoverContent>
276
+ </Popover>
277
+ )
278
+ }
279
+
280
+ function sameGrid(a: LabelGrid, b: LabelGrid): boolean {
281
+ return (
282
+ a.columns === b.columns &&
283
+ a.rows === b.rows &&
284
+ a.size.widthMm === b.size.widthMm &&
285
+ a.size.heightMm === b.size.heightMm &&
286
+ a.gapMm === b.gapMm &&
287
+ (a.gapYMm ?? a.gapMm) === (b.gapYMm ?? b.gapMm)
288
+ )
289
+ }
@@ -0,0 +1,394 @@
1
+ /**
2
+ * Every string the editor shows, with its English default. Pass Arabic (or
3
+ * any language) through `labels`; the feature layer fills it from t().
4
+ */
5
+ export const EDITOR_LABELS = {
6
+ back: "Back",
7
+ documentTitle: "Document title",
8
+ untitled: "Untitled",
9
+ saved: "Saved {time}",
10
+ saving: "Saving…",
11
+ offline: "Offline. Changes save when you’re back online",
12
+ saveFailed: "Not saved. Try again",
13
+ modeEditing: "Editing",
14
+ modeViewing: "Viewing",
15
+ modeMenu: "Mode",
16
+ modeEditingHint: "Change the document directly",
17
+ modeViewingHint: "Read only",
18
+ formatting: "Formatting",
19
+ undo: "Undo",
20
+ redo: "Redo",
21
+ styleMenu: "Text style",
22
+ normalText: "Normal text",
23
+ bold: "Bold",
24
+ italic: "Italic",
25
+ underline: "Underline",
26
+ strike: "Strikethrough",
27
+ code: "Code",
28
+ link: "Link",
29
+ highlight: "Highlight",
30
+ insert: "Insert",
31
+ moreTools: "More tools",
32
+ hideKeyboard: "Hide keyboard",
33
+ outline: "Outline",
34
+ outlineEmpty: "Headings appear here",
35
+ selection: "Selection",
36
+ linkAddress: "Link address",
37
+ linkApply: "Apply",
38
+ linkOpen: "Open link",
39
+ linkCopy: "Copy link",
40
+ linkEdit: "Edit link",
41
+ linkRemove: "Remove link",
42
+ addBelow: "Add a block below",
43
+ dragHandle: "Drag to move, click for options",
44
+ blockMenu: "Block options",
45
+ turnInto: "Turn into",
46
+ duplicate: "Duplicate",
47
+ copyLinkToBlock: "Copy link to block",
48
+ moveUp: "Move up",
49
+ moveDown: "Move down",
50
+ delete: "Delete",
51
+ searchBlocks: "Search blocks",
52
+ noBlocks: "No blocks match",
53
+ slashMove: "↑↓ to move",
54
+ slashInsert: "Enter to insert",
55
+ slashInsertAfter: "Enter inserts after this line",
56
+ slashClose: "Esc to close",
57
+ placeholder: "Type / for blocks, {{ for fields, or just write",
58
+ laterBlock: "{block} block · edited in a later version",
59
+ words: "{n} words",
60
+ word: "1 word",
61
+ lastEdited: "Last edited by {name} at {time}",
62
+ lastEditedAt: "Last edited at {time}",
63
+ english: "English",
64
+ arabic: "Arabic",
65
+ kindTemplate: "Template",
66
+ kindLetter: "Letter",
67
+ kindReport: "Report",
68
+ kindNote: "Note",
69
+ kindWiki: "Wiki page",
70
+ kindLabel: "Label sheet",
71
+ groupBasic: "Basic",
72
+ groupLists: "Lists",
73
+ groupStructure: "Structure",
74
+ groupMedia: "Media",
75
+ groupWhity: "Whity",
76
+ groupSaved: "Saved blocks",
77
+ groupPlugin: "Plugins",
78
+ blockCallout: "Callout",
79
+ blockCalloutHint: "A note or something important",
80
+ blockToggle: "Toggle",
81
+ blockToggleHint: "A line that hides blocks under it",
82
+ blockColumns: "Columns",
83
+ blockColumnsHint: "Two columns side by side",
84
+ blockPageBreak: "Page break",
85
+ blockPageBreakHint: "Start a new page when printed",
86
+ blockTable: "Table",
87
+ blockTableHint: "Rows and columns",
88
+ blockImage: "Image",
89
+ blockImageHint: "A picture with a caption",
90
+ blockFile: "File",
91
+ blockFileHint: "A file to download",
92
+ blockRecord: "Record",
93
+ blockRecordHint: "A live invoice, customer or any record",
94
+ blockChart: "Chart",
95
+ blockChartHint: "A live chart",
96
+ blockSignature: "Signature and stamp",
97
+ blockSignatureHint: "For letters and contracts",
98
+ blockBarcode: "Barcode",
99
+ blockBarcodeHint: "Code 128, EAN-13 or Code 39",
100
+ blockQr: "QR code",
101
+ blockQrHint: "A link or value as a QR code",
102
+ blockMath: "Maths",
103
+ blockMathHint: "A formula in TeX",
104
+ toggleOpen: "Show what’s inside",
105
+ toggleClose: "Hide what’s inside",
106
+ imageEmpty: "Choose an image",
107
+ fileEmpty: "Choose a file",
108
+ fileDownload: "Download {name}",
109
+ live: "Live",
110
+ recordEmpty: "Choose a record",
111
+ recordHidden: "You can’t see this record",
112
+ recordUnavailable: "Records aren’t available here",
113
+ recordFailed: "The record didn’t load",
114
+ chartEmpty: "Choose what the chart shows",
115
+ chartHidden: "You can’t see this chart’s data",
116
+ chartUnavailable: "Charts aren’t available here",
117
+ chartFailed: "The chart didn’t load",
118
+ chartNoData: "No data yet",
119
+ chartLiveRange: "{range} · live",
120
+ chartShowTable: "Show as table",
121
+ chartShowChart: "Show as chart",
122
+ chartCategory: "Item",
123
+ signatureName: "Name",
124
+ signatureDate: "Date",
125
+ signatureStamp: "Company stamp",
126
+ barcodeEmpty: "Set the barcode’s value",
127
+ qrEmpty: "Set the QR code’s value",
128
+ codeFromField: "Drawn from {value} when printed",
129
+ mathEmpty: "Write a formula",
130
+ blockToolbar: "Block",
131
+ calloutNote: "Note",
132
+ calloutImportant: "Important",
133
+ widthHalf: "Half width",
134
+ widthWide: "Wide",
135
+ widthFull: "Full width",
136
+ caption: "Caption",
137
+ altText: "Alt text",
138
+ replace: "Replace",
139
+ upload: "Upload",
140
+ uploading: "Uploading…",
141
+ uploadFailed: "The upload didn’t finish. Try again.",
142
+ headerRow: "Header row",
143
+ addRow: "Row",
144
+ addColumn: "Column",
145
+ deleteRow: "Delete row",
146
+ deleteColumn: "Delete column",
147
+ columnAlign: "Column alignment",
148
+ alignStart: "Align to start",
149
+ alignEnd: "Align to end",
150
+ deleteBlock: "Delete block",
151
+ recordChoose: "Change record",
152
+ recordType: "Record type",
153
+ recordId: "Record",
154
+ viewCard: "Card",
155
+ viewSummary: "Summary",
156
+ chartBar: "Bars",
157
+ chartLine: "Line",
158
+ chartDonut: "Donut",
159
+ chartSource: "Data",
160
+ chartTitle: "Title",
161
+ addSigner: "Signer",
162
+ signerRole: "Role",
163
+ stamp: "Stamp",
164
+ symbology: "Type",
165
+ value: "Value",
166
+ showText: "Show the value under it",
167
+ formula: "Formula",
168
+ done: "Done",
169
+ blockText: "Text",
170
+ blockTextHint: "Plain paragraph",
171
+ blockH1: "Heading 1",
172
+ blockH1Hint: "Big section heading",
173
+ blockH2: "Heading 2",
174
+ blockH2Hint: "Medium heading",
175
+ blockH3: "Heading 3",
176
+ blockH3Hint: "Small heading",
177
+ blockQuote: "Quote",
178
+ blockQuoteHint: "A quotation",
179
+ blockCode: "Code",
180
+ blockCodeHint: "Code or a fixed-width snippet",
181
+ blockBullet: "Bulleted list",
182
+ blockBulletHint: "A simple list",
183
+ blockNumber: "Numbered list",
184
+ blockNumberHint: "A list with numbers",
185
+ blockChecklist: "Checklist",
186
+ blockChecklistHint: "Tasks with checkboxes",
187
+ blockDivider: "Divider",
188
+ blockDividerHint: "A line between sections",
189
+ field: "Field",
190
+ fieldPicker: "Fields",
191
+ fieldSearch: "Search fields",
192
+ fieldBar: "Field",
193
+ fieldExample: "e.g.",
194
+ fieldChange: "Change field",
195
+ fieldRemove: "Remove field",
196
+ noFields: "No fields match",
197
+ fieldMissing: "No value for this record",
198
+ zoom: "Zoom",
199
+ zoomFit: "Fit width",
200
+ zoomPercent: "{n}%",
201
+ view: "View",
202
+ viewContinuous: "Continuous",
203
+ viewPage: "Page view",
204
+ pageOf: "Page {page} of {pages}",
205
+ pageContinued: "{title} · continued",
206
+ pageSetup: "A4 · margins 16 mm",
207
+ reference: "Ref",
208
+ preview: "Preview",
209
+ previewingWith: "Previewing with",
210
+ changeRecord: "Change record",
211
+ showFields: "Show fields",
212
+ backToEditing: "Back to editing",
213
+ exampleValues: "example values",
214
+ typedValues: "the values you type",
215
+ previewStatus: "Previewing {record}: as it will print, read-only",
216
+ previewEditingStatus: "Previewing {record}: as it will print",
217
+ pdf: "PDF",
218
+ publish: "Publish",
219
+ draftSaved: "Draft saved {time}",
220
+ publishedInUse: "published version {n} is in use",
221
+ notPublished: "not published yet",
222
+ publishTitle: "Before you publish",
223
+ publishExplain: "Publishing makes this draft the version new documents are issued from.",
224
+ publishExplainFor: "Publishing makes this draft the version new documents are issued from, for every {records}.",
225
+ publishChecking: "Checking the template…",
226
+ publishBlockers: "What blocks publishing",
227
+ publishClear: "Nothing blocks publishing.",
228
+ publishFailed: "Not published. Try again",
229
+ publishVersion: "Publish version {n}",
230
+ keepEditing: "Keep editing",
231
+ review: "Review",
232
+ show: "Show",
233
+ blockerSuggestion: "1 open suggestion",
234
+ blockerSuggestions: "{n} open suggestions",
235
+ blockerSuggestionsHint: "Accept or reject them first.",
236
+ blockerPlugin: "{plugin} is turned off",
237
+ blockerPluginHint: "Its blocks can’t be printed until it’s on again.",
238
+ blockerNoPrint: "A block has no print view",
239
+ blockerNoPrintHint: "It can’t be printed. Remove it, or keep it for notes.",
240
+ blockerField: "{field} isn’t a field of this record type",
241
+ blockerFieldHint: "Remove it, or pick a field the record has.",
242
+ blockerTheme: "This document uses a theme the workspace doesn’t have: {ref}",
243
+ blockerThemeHint: "Choose another theme or restore it.",
244
+ blockerTooLarge: "This template is too large to print: {size}, and the limit is {max}",
245
+ blockerTooLargeHint: "Use smaller images or fewer of them, then publish again.",
246
+ labelGrid: "{columns} × {rows} labels",
247
+ labelStock: "Label stock",
248
+ labelCertificate: "Certificate",
249
+ labelSheet: "Sheet",
250
+ labelColumns: "Columns",
251
+ labelRows: "Rows",
252
+ labelWidth: "Label width (mm)",
253
+ labelHeight: "Label height (mm)",
254
+ labelGapX: "Gap between columns (mm)",
255
+ labelGapY: "Gap between rows (mm)",
256
+ labelTooBig: "The labels don’t fit on the sheet.",
257
+ labelOverflow: "Doesn’t fit the label",
258
+ labelsPerSheet: "{n} labels a sheet",
259
+ printLabels: "Print labels",
260
+ fieldsThisTemplate: "This template",
261
+ fieldNew: "New field “{name}”",
262
+ fieldNewHint: "Type a name to add a field of this template.",
263
+ modeSuggesting: "Suggesting",
264
+ modeSuggestingHint: "Your edits become suggestions to accept",
265
+ modeSuggestingHintNoEdit: "An editor accepts your changes",
266
+ modeEditingLocked: "Ask an owner for edit access",
267
+ modeViewingCommentHint: "Read and comment, nothing changes",
268
+ comment: "Comment",
269
+ commentsAndSuggestions: "Comments and suggestions",
270
+ close: "Close",
271
+ cancel: "Cancel",
272
+ commentPlaceholder: "Comment or add others with @",
273
+ replyPlaceholder: "Reply or add others with @",
274
+ reply: "Reply",
275
+ resolve: "Resolve",
276
+ reopen: "Reopen",
277
+ resolvedBy: "Resolved by {name} · {time}",
278
+ accept: "Accept",
279
+ reject: "Reject",
280
+ railAll: "All",
281
+ acceptAll: "Accept all",
282
+ rejectAll: "Reject all",
283
+ acceptAllFrom: "Accept all from {name}",
284
+ rejectAllFrom: "Reject all from {name}",
285
+ countSuggestion: "1 suggestion",
286
+ countSuggestions: "{n} suggestions",
287
+ countComment: "1 comment",
288
+ countComments: "{n} comments",
289
+ countResolved: "{n} resolved",
290
+ tabAll: "All",
291
+ tabComments: "Comments",
292
+ tabSuggestions: "Suggestions",
293
+ tabResolved: "Resolved",
294
+ railEmpty: "No comments or suggestions yet. Select text and choose Comment.",
295
+ resolvedEmpty: "No resolved comments",
296
+ mentionPeople: "People",
297
+ mentionNone: "No one matches",
298
+ mentionHint: "Type a name to mention someone",
299
+ you: "You",
300
+ now: "now",
301
+ oneReply: "1 reply",
302
+ replies: "{n} replies",
303
+ actorFor: "for",
304
+ sugReplace: "Replace {from} with {to}",
305
+ sugAdd: "Add {text}",
306
+ sugDelete: "Delete {text}",
307
+ sugFormat: "Make {text} {mark}",
308
+ sugUnformat: "Remove {mark} from {text}",
309
+ sugAddBlocks: "Add {text}",
310
+ sugDeleteBlocks: "Delete {text}",
311
+ sugMoveBlock: "Move {text}",
312
+ sugBlock: "a block",
313
+ sugSending: "Sending…",
314
+ sugUnplaced: "Its text has changed since",
315
+ sugRefused: "That change can’t be a suggestion yet, so it was undone.",
316
+ collabFailed: "That didn’t work. Try again.",
317
+ agentAsk: "Ask an agent",
318
+ agentClose: "Close",
319
+ agentNoneConnected: "You haven't connected an agent yet. Connect your AI app to Whity, then ask it here.",
320
+ agentConnect: "Connect an agent",
321
+ agentPicker: "Agent",
322
+ agentAny: "Any of my agents",
323
+ agentThisDocument: "This document",
324
+ agentRequest: "What should the agent do?",
325
+ agentRequestPlaceholder: "Ask for a paragraph, a rewrite or a check",
326
+ agentWritesFor: "Writes only suggestions, for {name}",
327
+ agentWrites: "Writes only suggestions",
328
+ agentAskButton: "Ask",
329
+ agentRequests: "Your requests",
330
+ agentWaiting: "Waiting for your agent to pick this up",
331
+ agentWorking: "Working on it",
332
+ agentStopped: "Stopped before it finished",
333
+ agentFailedNext: "Check that your agent is still connected, then try again.",
334
+ agentQueued: "Waiting",
335
+ agentRunning: "Running",
336
+ agentDone: "Done",
337
+ agentStoppedBadge: "Stopped",
338
+ agentFailed: "Failed",
339
+ agentStop: "Stop",
340
+ agentRetry: "Try again",
341
+ agentRewrite: "Rewrite with an agent",
342
+ agentRewriteRequest: "Rewrite this, keeping the meaning",
343
+ saveBlockTitle: "Save as block",
344
+ saveBlockExplain: "Saves the {n} selected blocks as one block you can insert from the / menu.",
345
+ saveBlockName: "Name",
346
+ saveBlockNamePlaceholder: "Bank details",
347
+ saveBlockHow: "When it's inserted",
348
+ saveBlockSynced: "Synced",
349
+ saveBlockSyncedHint: "Editing it once updates every document that uses it. Published templates pick up the change when they're published again.",
350
+ saveBlockCopy: "Copy",
351
+ saveBlockCopyHint: "Inserts a copy people change freely.",
352
+ saveBlockWho: "Who can use it",
353
+ saveBlockOnlyMe: "Only me",
354
+ saveBlockOnlyMeHint: "It's in your / menu only.",
355
+ saveBlockEveryone: "Everyone in the workspace",
356
+ saveBlockEveryoneHint: "It joins the workspace library.",
357
+ saveBlockSave: "Save block",
358
+ saveBlockCancel: "Cancel",
359
+ saveBlockExplainOne: "Saves this block so you can insert it from the / menu.",
360
+ saveAsBlock: "Save as block",
361
+ savedBlockLabel: "Saved block: {name}",
362
+ savedBlockSynced: "Synced",
363
+ savedBlockUsedIn: "used in {n} documents",
364
+ savedBlockUsedInOne: "used in 1 document",
365
+ savedBlockDetach: "Detach",
366
+ savedBlockDetachHint: "Turn it into ordinary blocks you change here only",
367
+ savedBlockMissing: "This saved block was deleted or isn't shared with you.",
368
+ savedBlockSyncedHint: "Synced: changes reach every document",
369
+ savedBlockCopyHint: "Inserts a copy you change freely",
370
+ perDocumentMark: "Filled per document",
371
+ perDocumentFill: "Filled per document: {text}",
372
+ pluginBlockLabel: "{name}, from {plugin}",
373
+ pluginVerified: "Verified",
374
+ pluginNotVerified: "Not verified",
375
+ pluginPrints: "Prints",
376
+ pluginNotesOnly: "Notes only",
377
+ pluginEdit: "Edit",
378
+ pluginEditTitle: "Edit {name}",
379
+ pluginSave: "Save",
380
+ pluginCancel: "Cancel",
381
+ pluginChoose: "Choose",
382
+ pluginNeeds: "Needs the {plugin} plugin",
383
+ pluginNeedsHint: "Its data is kept. A template with it can't be published until the plugin is on.",
384
+ pluginEnable: "Enable",
385
+ pluginEnableFailed: "The plugin wasn't turned on. Try again.",
386
+ pluginNoView: "This block has nothing to show yet.",
387
+ }
388
+
389
+ export type EditorLabels = typeof EDITOR_LABELS
390
+
391
+ /** Fill `{name}` placeholders. */
392
+ export function fill(template: string, values: Record<string, string | number>): string {
393
+ return template.replace(/\{(\w+)\}/g, (_, key: string) => String(values[key] ?? `{${key}}`))
394
+ }