@openartifactsai/ui 0.0.0-stage → 0.23.0-rc.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.
- package/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +5 -2
- package/package.json +82 -4
- package/src/button.d.ts +30 -0
- package/src/button.js +29 -0
- package/src/clicks.d.ts +63 -0
- package/src/clicks.js +75 -0
- package/src/cn.d.ts +3 -0
- package/src/cn.js +5 -0
- package/src/color-picker.d.ts +98 -0
- package/src/color-picker.js +395 -0
- package/src/color.d.ts +150 -0
- package/src/color.js +543 -0
- package/src/crash-boundary.d.ts +29 -0
- package/src/crash-boundary.js +32 -0
- package/src/data/google-fonts.json +1775 -0
- package/src/drag-cover.d.ts +48 -0
- package/src/drag-cover.js +41 -0
- package/src/effect-editors.d.ts +48 -0
- package/src/effect-editors.js +230 -0
- package/src/effects.d.ts +118 -0
- package/src/effects.js +425 -0
- package/src/escape-to-popup.d.ts +53 -0
- package/src/escape-to-popup.js +78 -0
- package/src/field-announce.d.ts +28 -0
- package/src/field-announce.js +43 -0
- package/src/fields.d.ts +176 -0
- package/src/fields.js +377 -0
- package/src/focusables.d.ts +50 -0
- package/src/focusables.js +61 -0
- package/src/font-picker.d.ts +62 -0
- package/src/font-picker.js +242 -0
- package/src/fonts.d.ts +121 -0
- package/src/fonts.js +273 -0
- package/src/history-diff.d.ts +64 -0
- package/src/history-diff.js +151 -0
- package/src/history.d.ts +95 -0
- package/src/history.js +160 -0
- package/src/index.d.ts +38 -0
- package/src/index.js +38 -0
- package/src/key-chord.d.ts +74 -0
- package/src/key-chord.js +228 -0
- package/src/keys.d.ts +142 -0
- package/src/keys.js +172 -0
- package/src/layout.d.ts +74 -0
- package/src/layout.js +173 -0
- package/src/link-card-view.d.ts +97 -0
- package/src/link-card-view.js +175 -0
- package/src/link-card.d.ts +136 -0
- package/src/link-card.js +158 -0
- package/src/menu-shortcuts.d.ts +31 -0
- package/src/menu-shortcuts.js +91 -0
- package/src/menu.d.ts +120 -0
- package/src/menu.js +100 -0
- package/src/number-entry.d.ts +140 -0
- package/src/number-entry.js +202 -0
- package/src/number-limits.d.ts +2 -0
- package/src/number-limits.js +2 -0
- package/src/number-wheel.d.ts +29 -0
- package/src/number-wheel.js +27 -0
- package/src/numbers.d.ts +28 -0
- package/src/numbers.js +124 -0
- package/src/overlays.d.ts +71 -0
- package/src/overlays.js +131 -0
- package/src/pressed.d.ts +5 -0
- package/src/pressed.js +10 -0
- package/src/scroll.d.ts +24 -0
- package/src/scroll.js +111 -0
- package/src/scrub-number-field.d.ts +79 -0
- package/src/scrub-number-field.js +254 -0
- package/src/select-announce.d.ts +50 -0
- package/src/select-announce.js +71 -0
- package/src/slider-session.d.ts +43 -0
- package/src/slider-session.js +39 -0
- package/src/styles.css +96 -0
- package/src/tab-strip-layout.d.ts +76 -0
- package/src/tab-strip-layout.js +111 -0
- package/src/tab-strip.d.ts +73 -0
- package/src/tab-strip.js +498 -0
- package/src/text-area-view.d.ts +35 -0
- package/src/text-area-view.js +142 -0
- package/src/text-area.d.ts +38 -0
- package/src/text-area.js +51 -0
- package/src/theme.css +34 -0
- package/src/toast-fit.d.ts +21 -0
- package/src/toast-fit.js +30 -0
- package/src/toast-tone.d.ts +27 -0
- package/src/toast-tone.js +22 -0
- package/src/tooltip.d.ts +23 -0
- package/src/tooltip.js +18 -0
package/src/history.js
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* The version history panel every editor can mount: versions grouped by day
|
|
4
|
+
* and author, what each changed, a line diff per file, a preview hook, and
|
|
5
|
+
* restoring a whole version or one file (after a confirm).
|
|
6
|
+
*
|
|
7
|
+
* It takes the page's `history` capability (`window.openartifacts.history`
|
|
8
|
+
* from `@openartifactsai/runtime`) structurally, so this package keeps no
|
|
9
|
+
* dependency on the runtime:
|
|
10
|
+
*
|
|
11
|
+
* ```tsx
|
|
12
|
+
* const history = openartifacts.capabilities.history;
|
|
13
|
+
* {history ? <HistoryPanel history={history} viewerId={me.id} onPreview={setPreview} previewing={preview} /> : null}
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
import { ArrowLeft, Eye, FileMinus, FilePen, FilePlus, History as HistoryIcon, RotateCcw, TriangleAlert, X } from 'lucide-react';
|
|
17
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
18
|
+
import { Button, IconButton } from "./button.js";
|
|
19
|
+
import { cn } from "./cn.js";
|
|
20
|
+
import { diffHunks, diffLines, diffStats, groupVersions } from "./history-diff.js";
|
|
21
|
+
import { EmptyState, toast } from "./layout.js";
|
|
22
|
+
import { ConfirmDialog } from "./overlays.js";
|
|
23
|
+
import { ScrollBody } from "./scroll.js";
|
|
24
|
+
export * from "./history-diff.js";
|
|
25
|
+
/* --------------------------------- Helpers --------------------------------- */
|
|
26
|
+
function defaultFormatPath(path) {
|
|
27
|
+
return path.replace(/^(project|db)\//, '');
|
|
28
|
+
}
|
|
29
|
+
function authorName(author, viewerId) {
|
|
30
|
+
if (author.kind === 'system')
|
|
31
|
+
return 'Original';
|
|
32
|
+
if (author.kind === 'agent')
|
|
33
|
+
return author.name || 'Agent';
|
|
34
|
+
if (viewerId && author.id === viewerId)
|
|
35
|
+
return 'You';
|
|
36
|
+
return author.name || 'Someone';
|
|
37
|
+
}
|
|
38
|
+
const timeFormat = new Intl.DateTimeFormat(undefined, { hour: 'numeric', minute: '2-digit' });
|
|
39
|
+
const dateFormat = new Intl.DateTimeFormat(undefined, { weekday: 'short', month: 'short', day: 'numeric' });
|
|
40
|
+
const yearFormat = new Intl.DateTimeFormat(undefined, { year: 'numeric', month: 'short', day: 'numeric' });
|
|
41
|
+
function dayLabel(date) {
|
|
42
|
+
const today = new Date();
|
|
43
|
+
const start = (d) => new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime();
|
|
44
|
+
const days = Math.round((start(today) - start(date)) / 86_400_000);
|
|
45
|
+
if (days === 0)
|
|
46
|
+
return 'Today';
|
|
47
|
+
if (days === 1)
|
|
48
|
+
return 'Yesterday';
|
|
49
|
+
return date.getFullYear() === today.getFullYear() ? dateFormat.format(date) : yearFormat.format(date);
|
|
50
|
+
}
|
|
51
|
+
function timeRange(version) {
|
|
52
|
+
const first = timeFormat.format(new Date(version.first));
|
|
53
|
+
const last = timeFormat.format(new Date(version.at));
|
|
54
|
+
return first === last ? last : `${first} – ${last}`;
|
|
55
|
+
}
|
|
56
|
+
const OP_ICON = { added: FilePlus, edited: FilePen, deleted: FileMinus };
|
|
57
|
+
const OP_TONE = { added: 'text-success', edited: 'text-fg-muted', deleted: 'text-danger' };
|
|
58
|
+
function summary(version, formatPath) {
|
|
59
|
+
if (version.restoredFrom !== undefined)
|
|
60
|
+
return `Restored version ${version.restoredFrom}`;
|
|
61
|
+
const files = version.files;
|
|
62
|
+
if (files.length === 1)
|
|
63
|
+
return `${files[0].op === 'edited' ? 'Edited' : files[0].op === 'added' ? 'Added' : 'Deleted'} ${formatPath(files[0].path)}`;
|
|
64
|
+
return `${files.length} changes`;
|
|
65
|
+
}
|
|
66
|
+
/* ------------------------------------ Diff ----------------------------------- */
|
|
67
|
+
function DiffRow({ line }) {
|
|
68
|
+
return (_jsxs("div", { className: cn('flex min-w-max', line.op === '+' && 'bg-success/10 text-fg', line.op === '-' && 'bg-danger/10 text-fg', line.op === ' ' && 'text-fg-muted'), children: [_jsx("span", { className: "w-9 shrink-0 select-none pr-1 text-right text-fg-subtle", children: line.before ?? '' }), _jsx("span", { className: "w-9 shrink-0 select-none pr-1 text-right text-fg-subtle", children: line.after ?? '' }), _jsx("span", { className: cn('w-4 shrink-0 select-none text-center', line.op === '+' ? 'text-success' : line.op === '-' ? 'text-danger' : ''), children: line.op === ' ' ? '' : line.op }), _jsx("span", { className: "whitespace-pre pr-3", children: line.text || ' ' })] }));
|
|
69
|
+
}
|
|
70
|
+
/** A file's line diff, changed parts with three lines of context. */
|
|
71
|
+
export function HistoryDiffView({ diff }) {
|
|
72
|
+
const lines = useMemo(() => (diff.binary || diff.tooLarge ? [] : diffLines(diff.before, diff.after)), [diff]);
|
|
73
|
+
const hunks = useMemo(() => diffHunks(lines), [lines]);
|
|
74
|
+
if (diff.binary)
|
|
75
|
+
return _jsx("p", { className: "p-3 text-xs text-fg-muted", children: "A binary file: no text to compare." });
|
|
76
|
+
if (diff.tooLarge)
|
|
77
|
+
return _jsx("p", { className: "p-3 text-xs text-fg-muted", children: "Too large to compare here." });
|
|
78
|
+
if (!hunks.length)
|
|
79
|
+
return _jsx("p", { className: "p-3 text-xs text-fg-muted", children: "No line changes (only whitespace at the end, or an empty file)." });
|
|
80
|
+
const stats = diffStats(lines);
|
|
81
|
+
return (_jsxs("div", { className: "flex flex-col gap-2 p-2", children: [_jsxs("div", { className: "px-1 text-xs text-fg-muted", children: [_jsxs("span", { className: "text-success", children: ["+", stats.added] }), " ", _jsxs("span", { className: "text-danger", children: ["\u2212", stats.removed] })] }), hunks.map((hunk, index) => (_jsxs("div", { className: "overflow-x-auto rounded-control border border-line font-mono text-[11px] leading-[18px]", children: [hunk.skippedBefore > 0 ? (_jsxs("div", { className: "border-b border-line bg-surface-2 px-2 text-fg-subtle", children: ["\u22EF ", hunk.skippedBefore, " unchanged line", hunk.skippedBefore === 1 ? '' : 's'] })) : null, hunk.lines.map((line, i) => (_jsx(DiffRow, { line: line }, i)))] }, index)))] }));
|
|
82
|
+
}
|
|
83
|
+
/* ----------------------------------- Panel ----------------------------------- */
|
|
84
|
+
/** The version history of the open artifact. */
|
|
85
|
+
export function HistoryPanel({ history, viewerId, onPreview, previewing = null, onRestored, onClose, formatPath = defaultFormatPath, className }) {
|
|
86
|
+
const [listing, setListing] = useState(null);
|
|
87
|
+
const [error, setError] = useState(null);
|
|
88
|
+
const [open, setOpen] = useState(null);
|
|
89
|
+
const [file, setFile] = useState(null);
|
|
90
|
+
const [diff, setDiff] = useState(null);
|
|
91
|
+
const [pending, setPending] = useState(null);
|
|
92
|
+
const [busy, setBusy] = useState(false);
|
|
93
|
+
const reload = useCallback(async () => {
|
|
94
|
+
try {
|
|
95
|
+
setListing(await history.list());
|
|
96
|
+
setError(null);
|
|
97
|
+
}
|
|
98
|
+
catch (e) {
|
|
99
|
+
setError(e instanceof Error ? e.message : String(e));
|
|
100
|
+
}
|
|
101
|
+
}, [history]);
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
void reload();
|
|
104
|
+
return history.onChange(() => void reload());
|
|
105
|
+
}, [history, reload]);
|
|
106
|
+
useEffect(() => {
|
|
107
|
+
if (!file)
|
|
108
|
+
return setDiff(null);
|
|
109
|
+
let live = true;
|
|
110
|
+
setDiff(null);
|
|
111
|
+
history.diff(file.n, file.path).then((d) => live && setDiff(d), (e) => live && toast.add({ title: 'Could not load the change', description: e instanceof Error ? e.message : String(e) }));
|
|
112
|
+
return () => {
|
|
113
|
+
live = false;
|
|
114
|
+
};
|
|
115
|
+
}, [history, file]);
|
|
116
|
+
const days = useMemo(() => groupVersions(listing?.versions ?? []), [listing]);
|
|
117
|
+
const byN = useMemo(() => new Map((listing?.versions ?? []).map((v) => [v.n, v])), [listing]);
|
|
118
|
+
const restore = async ({ n, paths }) => {
|
|
119
|
+
setBusy(true);
|
|
120
|
+
try {
|
|
121
|
+
const result = await history.restore(n, paths);
|
|
122
|
+
if (result.version === null)
|
|
123
|
+
toast.add({ title: 'Nothing to restore', description: `Already the same as version ${n}.` });
|
|
124
|
+
else {
|
|
125
|
+
toast.add({ title: `Restored version ${n}`, description: `${result.changed.length} change${result.changed.length === 1 ? '' : 's'}.` });
|
|
126
|
+
onRestored?.(result, n);
|
|
127
|
+
if (previewing !== null)
|
|
128
|
+
onPreview?.(null);
|
|
129
|
+
}
|
|
130
|
+
await reload();
|
|
131
|
+
}
|
|
132
|
+
catch (e) {
|
|
133
|
+
toast.add({ title: 'Could not restore', description: e instanceof Error ? e.message : String(e) });
|
|
134
|
+
}
|
|
135
|
+
finally {
|
|
136
|
+
setBusy(false);
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
const header = (title, back) => (_jsxs("div", { className: "flex h-10 shrink-0 items-center gap-1 border-b border-line px-2", children: [back ? _jsx(IconButton, { label: "Back", size: "sm", icon: _jsx(ArrowLeft, { className: "size-4" }), onClick: back }) : null, _jsx("div", { className: "min-w-0 flex-1 truncate px-1 text-[13px] font-semibold text-fg", children: title }), onClose ? _jsx(IconButton, { label: "Close", size: "sm", icon: _jsx(X, { className: "size-4" }), onClick: onClose }) : null] }));
|
|
140
|
+
const confirm = pending ? (_jsx(ConfirmDialog, { open: true, onOpenChange: (next) => !next && setPending(null), title: pending.paths ? `Restore ${formatPath(pending.paths[0])}?` : `Restore version ${pending.n}?`, description: pending.paths
|
|
141
|
+
? `It goes back to how version ${pending.n} left it. The current content stays in the history.`
|
|
142
|
+
: `Every file goes back to how version ${pending.n} left it. The current files stay in the history, so this can be undone.`, confirmLabel: "Restore", onConfirm: () => {
|
|
143
|
+
const request = pending;
|
|
144
|
+
setPending(null);
|
|
145
|
+
void restore(request);
|
|
146
|
+
} })) : null;
|
|
147
|
+
/* One file's diff. */
|
|
148
|
+
if (file) {
|
|
149
|
+
const version = byN.get(file.n);
|
|
150
|
+
return (_jsxs("div", { className: cn('flex h-full min-h-0 flex-col bg-surface', className), children: [header(formatPath(file.path), () => setFile(null)), _jsxs("div", { className: "flex shrink-0 items-center gap-2 border-b border-line px-3 py-2 text-xs text-fg-muted", children: [_jsxs("span", { className: "min-w-0 flex-1 truncate", children: ["Version ", file.n, version ? ` · ${authorName(version.author, viewerId)} · ${timeRange(version)}` : ''] }), listing?.canRestore && !version?.current ? (_jsx(Button, { size: "sm", disabled: busy, icon: _jsx(RotateCcw, { className: "size-3.5" }), onClick: () => setPending({ n: file.n, paths: [file.path] }), children: "Restore file" })) : null] }), _jsx(ScrollBody, { className: "min-h-0 flex-1 overflow-auto", label: "Changes", children: diff ? _jsx(HistoryDiffView, { diff: diff }) : _jsx("p", { className: "p-3 text-xs text-fg-subtle", children: "Loading\u2026" }) }), confirm] }));
|
|
151
|
+
}
|
|
152
|
+
return (_jsxs("div", { className: cn('flex h-full min-h-0 flex-col bg-surface', className), children: [header('Version history'), listing?.notices.length ? (_jsx("div", { className: "flex shrink-0 flex-col gap-1 border-b border-line p-2", children: listing.notices.map((notice) => (_jsxs("div", { className: "flex gap-2 rounded-control bg-surface-2 p-2 text-xs text-fg", children: [_jsx(TriangleAlert, { className: "mt-0.5 size-3.5 shrink-0 text-warning" }), _jsxs("div", { className: "flex min-w-0 flex-1 flex-col gap-1.5", children: [_jsxs("div", { children: [_jsx("span", { className: "font-medium", children: authorName(notice.author, viewerId) }), " changed", ' ', _jsx("span", { className: "font-medium", children: formatPath(notice.path) }), " right after you, undoing part of your change."] }), _jsxs("div", { className: "flex gap-1", children: [listing.canRestore ? (_jsx(Button, { size: "sm", variant: "primary", disabled: busy, onClick: () => void restore({ n: notice.lost.n, paths: [notice.path] }), children: "Bring mine back" })) : null, _jsx(Button, { size: "sm", variant: "ghost", onClick: () => setFile({ n: notice.n, path: notice.path }), children: "See change" }), _jsx(Button, { size: "sm", variant: "ghost", onClick: () => void history.dismissNotice(notice.id).then(reload), children: "Dismiss" })] })] })] }, notice.id))) })) : null, _jsx(ScrollBody, { className: "min-h-0 flex-1 overflow-auto", label: "Versions", children: error ? (_jsx(EmptyState, { title: "History unavailable", children: error })) : !listing ? (_jsx("p", { className: "p-3 text-xs text-fg-subtle", children: "Loading\u2026" })) : !listing.versions.length ? (_jsx(EmptyState, { icon: _jsx(HistoryIcon, { className: "size-6" }), title: "No versions yet", children: "Changes show up here as they are saved." })) : (days.map((day) => (_jsxs("section", { className: "pb-1", children: [_jsx("h3", { className: "sticky top-0 z-[1] bg-surface px-3 pb-1 pt-3 text-[11px] font-semibold uppercase tracking-wide text-fg-subtle", children: dayLabel(day.date) }), day.runs.map((run) => (_jsxs("div", { className: "mx-2 mb-1", children: [_jsx("div", { className: "px-1 pb-0.5 pt-1 text-xs font-medium text-fg", children: authorName(run.author, viewerId) }), run.versions.map((version) => {
|
|
153
|
+
const expanded = open === version.n;
|
|
154
|
+
const isPreview = previewing === version.n;
|
|
155
|
+
return (_jsxs("div", { className: cn('rounded-control', expanded && 'bg-surface-2', isPreview && 'ring-1 ring-accent'), children: [_jsxs("button", { type: "button", "aria-expanded": expanded, className: "flex w-full min-w-0 items-center gap-2 rounded-control px-2 py-1.5 text-left text-xs hover:bg-hover", onClick: () => setOpen(expanded ? null : version.n), children: [_jsx("span", { className: "w-12 shrink-0 text-fg-subtle", children: timeFormat.format(new Date(version.at)) }), _jsx("span", { className: "min-w-0 flex-1 truncate text-fg", children: summary(version, formatPath) }), version.overwrote?.length ? _jsx(TriangleAlert, { className: "size-3 shrink-0 text-warning", "aria-label": "Undid a recent change" }) : null, version.current ? _jsx("span", { className: "shrink-0 rounded bg-accent-soft px-1.5 text-[10px] font-medium text-accent", children: "Current" }) : null, isPreview ? _jsx("span", { className: "shrink-0 text-[10px] font-medium text-accent", children: "Previewing" }) : null] }), expanded ? (_jsxs("div", { className: "flex flex-col gap-1 px-2 pb-2", children: [_jsxs("div", { className: "text-[11px] text-fg-subtle", children: ["Version ", version.n, " \u00B7 ", timeRange(version)] }), _jsx("ul", { className: "flex flex-col", children: version.files.map((change) => {
|
|
156
|
+
const Icon = OP_ICON[change.op];
|
|
157
|
+
return (_jsxs("li", { className: "group flex items-center gap-1", children: [_jsxs("button", { type: "button", className: "flex min-w-0 flex-1 items-center gap-1.5 rounded-control px-1 py-1 text-left text-xs hover:bg-hover", onClick: () => setFile({ n: version.n, path: change.path }), title: "Show what changed", children: [_jsx(Icon, { className: cn('size-3.5 shrink-0', OP_TONE[change.op]) }), _jsx("span", { className: "min-w-0 flex-1 truncate text-fg", children: formatPath(change.path) }), _jsx("span", { className: "shrink-0 text-[10px] text-fg-subtle", children: change.op })] }), listing.canRestore && !version.current ? (_jsx(IconButton, { label: `Restore ${formatPath(change.path)} from this version`, size: "sm", className: "opacity-0 group-hover:opacity-100 focus-visible:opacity-100", icon: _jsx(RotateCcw, { className: "size-3.5" }), disabled: busy, onClick: () => setPending({ n: version.n, paths: [change.path] }) })) : null] }, change.path));
|
|
158
|
+
}) }), version.overwrote?.length ? (_jsxs("div", { className: "text-[11px] text-warning", children: ["Undid part of", ' ', version.overwrote.map((o) => `${authorName(o.author, viewerId)}’s change to ${formatPath(o.path)}`).join(', '), "."] })) : null, _jsxs("div", { className: "flex flex-wrap gap-1 pt-1", children: [onPreview && !version.current ? (_jsx(Button, { size: "sm", icon: _jsx(Eye, { className: "size-3.5" }), onClick: () => onPreview(isPreview ? null : version.n), children: isPreview ? 'Stop preview' : 'Preview' })) : null, listing.canRestore && !version.current ? (_jsx(Button, { size: "sm", disabled: busy, icon: _jsx(RotateCcw, { className: "size-3.5" }), onClick: () => setPending({ n: version.n }), children: "Restore this version" })) : null] })] })) : null] }, version.n));
|
|
159
|
+
})] }, run.versions[0].n)))] }, day.key)))) }), confirm] }));
|
|
160
|
+
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@openartifactsai/ui`: the editors' shared UI kit.
|
|
3
|
+
*
|
|
4
|
+
* Unstyled, accessible primitives from Base UI, styled with Tailwind CSS
|
|
5
|
+
* against the semantic tokens in `styles.css`; icons come from lucide.
|
|
6
|
+
*/
|
|
7
|
+
export * from './cn.js';
|
|
8
|
+
export * from './button.js';
|
|
9
|
+
export * from './tooltip.js';
|
|
10
|
+
export * from './menu.js';
|
|
11
|
+
export * from './tab-strip.js';
|
|
12
|
+
export * from './tab-strip-layout.js';
|
|
13
|
+
export * from './overlays.js';
|
|
14
|
+
export * from './fields.js';
|
|
15
|
+
export * from './text-area-view.js';
|
|
16
|
+
export * from './layout.js';
|
|
17
|
+
export * from './keys.js';
|
|
18
|
+
export * from './key-chord.js';
|
|
19
|
+
export * from './pressed.js';
|
|
20
|
+
export * from './menu-shortcuts.js';
|
|
21
|
+
export * from './clicks.js';
|
|
22
|
+
export * from './focusables.js';
|
|
23
|
+
export * from './scroll.js';
|
|
24
|
+
export * from './history.js';
|
|
25
|
+
export * from './crash-boundary.js';
|
|
26
|
+
export * from './link-card.js';
|
|
27
|
+
export * from './link-card-view.js';
|
|
28
|
+
export * from './color.js';
|
|
29
|
+
export * from './color-picker.js';
|
|
30
|
+
export * from './effects.js';
|
|
31
|
+
export * from './effect-editors.js';
|
|
32
|
+
export * from './numbers.js';
|
|
33
|
+
export * from './number-entry.js';
|
|
34
|
+
export { announceFromField, prepareFieldAnnounce } from './field-announce.js';
|
|
35
|
+
export * from './slider-session.js';
|
|
36
|
+
export * from './scrub-number-field.js';
|
|
37
|
+
export * from './fonts.js';
|
|
38
|
+
export * from './font-picker.js';
|
package/src/index.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@openartifactsai/ui`: the editors' shared UI kit.
|
|
3
|
+
*
|
|
4
|
+
* Unstyled, accessible primitives from Base UI, styled with Tailwind CSS
|
|
5
|
+
* against the semantic tokens in `styles.css`; icons come from lucide.
|
|
6
|
+
*/
|
|
7
|
+
export * from "./cn.js";
|
|
8
|
+
export * from "./button.js";
|
|
9
|
+
export * from "./tooltip.js";
|
|
10
|
+
export * from "./menu.js";
|
|
11
|
+
export * from "./tab-strip.js";
|
|
12
|
+
export * from "./tab-strip-layout.js";
|
|
13
|
+
export * from "./overlays.js";
|
|
14
|
+
export * from "./fields.js";
|
|
15
|
+
export * from "./text-area-view.js";
|
|
16
|
+
export * from "./layout.js";
|
|
17
|
+
export * from "./keys.js";
|
|
18
|
+
export * from "./key-chord.js";
|
|
19
|
+
export * from "./pressed.js";
|
|
20
|
+
export * from "./menu-shortcuts.js";
|
|
21
|
+
export * from "./clicks.js";
|
|
22
|
+
export * from "./focusables.js";
|
|
23
|
+
export * from "./scroll.js";
|
|
24
|
+
export * from "./history.js";
|
|
25
|
+
export * from "./crash-boundary.js";
|
|
26
|
+
export * from "./link-card.js";
|
|
27
|
+
export * from "./link-card-view.js";
|
|
28
|
+
export * from "./color.js";
|
|
29
|
+
export * from "./color-picker.js";
|
|
30
|
+
export * from "./effects.js";
|
|
31
|
+
export * from "./effect-editors.js";
|
|
32
|
+
export * from "./numbers.js";
|
|
33
|
+
export * from "./number-entry.js";
|
|
34
|
+
export { announceFromField, prepareFieldAnnounce } from "./field-announce.js";
|
|
35
|
+
export * from "./slider-session.js";
|
|
36
|
+
export * from "./scrub-number-field.js";
|
|
37
|
+
export * from "./fonts.js";
|
|
38
|
+
export * from "./font-picker.js";
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keyboard chords as menus show, announce and match them. Pure.
|
|
3
|
+
*
|
|
4
|
+
* A chord is written once, platform-neutral ({ mod: true, shift: true, key: 'K' }), and read on the platform at hand:
|
|
5
|
+
* `mod` is ⌘ on Apple and Ctrl elsewhere.
|
|
6
|
+
*/
|
|
7
|
+
/** True on Apple platforms, where `mod` is ⌘ and chords are shown with symbols. */
|
|
8
|
+
export declare function onApplePlatform(): boolean;
|
|
9
|
+
/** A key combination, platform-neutral. */
|
|
10
|
+
export interface KeyChord {
|
|
11
|
+
/**
|
|
12
|
+
* A letter or digit, a punctuation character, `+`, a function key (`F1`…) or a key as `KeyboardEvent.key` names it
|
|
13
|
+
* (`Enter`, `Escape`, `Tab`, `Backspace`, `Delete`, `ArrowUp`, `PageDown`, `Space`…).
|
|
14
|
+
*/
|
|
15
|
+
key: string;
|
|
16
|
+
/** The platform's command key: ⌘ on Apple, Ctrl elsewhere. */
|
|
17
|
+
mod?: boolean;
|
|
18
|
+
/** The Control key itself (on Apple, in addition to ⌘). */
|
|
19
|
+
ctrl?: boolean;
|
|
20
|
+
alt?: boolean;
|
|
21
|
+
shift?: boolean;
|
|
22
|
+
}
|
|
23
|
+
/** A chord with its modifiers as the keyboard reports them on one platform. */
|
|
24
|
+
export interface HeldChord {
|
|
25
|
+
key: string;
|
|
26
|
+
meta: boolean;
|
|
27
|
+
ctrl: boolean;
|
|
28
|
+
alt: boolean;
|
|
29
|
+
shift: boolean;
|
|
30
|
+
}
|
|
31
|
+
/** The fields of a keydown a chord is matched against. */
|
|
32
|
+
export interface ChordPress {
|
|
33
|
+
key: string;
|
|
34
|
+
code?: string;
|
|
35
|
+
keyCode?: number;
|
|
36
|
+
metaKey: boolean;
|
|
37
|
+
ctrlKey: boolean;
|
|
38
|
+
altKey: boolean;
|
|
39
|
+
shiftKey: boolean;
|
|
40
|
+
/** `getModifierState('AltGraph')`. */
|
|
41
|
+
altGraph?: boolean;
|
|
42
|
+
}
|
|
43
|
+
/** The chord with its modifiers as they are held on this platform. */
|
|
44
|
+
export declare function holdChord(chord: KeyChord, apple: boolean): HeldChord;
|
|
45
|
+
/** The chord as a menu row or tooltip shows it: "⇧⌘K" on Apple, "Ctrl+Shift+K" elsewhere. */
|
|
46
|
+
export declare function chordLabel(chord: KeyChord, apple: boolean): string;
|
|
47
|
+
/** The chord in words, for a screen reader: "Shift+Command+K" on Apple, "Ctrl+Shift+K" elsewhere. */
|
|
48
|
+
export declare function chordSpoken(chord: KeyChord, apple: boolean): string;
|
|
49
|
+
/** The chord as `aria-keyshortcuts` takes it: "Meta+Shift+K" on Apple, "Control+Shift+K" elsewhere. */
|
|
50
|
+
export declare function chordAriaKeys(chord: KeyChord, apple: boolean): string;
|
|
51
|
+
/** Reads an `aria-keyshortcuts` value written by {@link chordAriaKeys} back into a held chord; null when it isn't one. */
|
|
52
|
+
export declare function parseAriaKeys(text: string): HeldChord | null;
|
|
53
|
+
/**
|
|
54
|
+
* Whether an open menu can act on the chord itself: it holds ⌘, Ctrl or Alt, or is a function key. Chords that end in
|
|
55
|
+
* Enter or Space (the menu's own activation), paste, and Control+Option on Apple (the AltGr of some layouts) are left to
|
|
56
|
+
* the page.
|
|
57
|
+
*/
|
|
58
|
+
export declare function menuTakesChord(held: HeldChord, apple: boolean): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Whether a keydown is the held chord. The modifiers must be the same. A letter or digit is taken as typed, so a
|
|
61
|
+
* remapped Latin layout keeps its letters; a non-Latin character falls back to the physical key, except under AltGr.
|
|
62
|
+
* A punctuation chord also matches its physical key when the layout puts another character there. `+` takes `=` too.
|
|
63
|
+
*/
|
|
64
|
+
export declare function chordMatchesPress(held: HeldChord, press: ChordPress): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Whether a keydown edits the text of the field it lands in: it moves the caret, deletes, uses the clipboard or
|
|
67
|
+
* undoes (with or without ⌘ / Ctrl), or types a character with Option.
|
|
68
|
+
*/
|
|
69
|
+
export declare function editsText(press: ChordPress): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Shortcut text written with symbols ("⇧⌘Z", "⌘↵") in words for a screen reader ("Shift+Command+Z"); text that is
|
|
72
|
+
* already words ("Ctrl+Shift+Z") comes back as it is.
|
|
73
|
+
*/
|
|
74
|
+
export declare function spokenShortcut(text: string, apple: boolean): string;
|
package/src/key-chord.js
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keyboard chords as menus show, announce and match them. Pure.
|
|
3
|
+
*
|
|
4
|
+
* A chord is written once, platform-neutral ({ mod: true, shift: true, key: 'K' }), and read on the platform at hand:
|
|
5
|
+
* `mod` is ⌘ on Apple and Ctrl elsewhere.
|
|
6
|
+
*/
|
|
7
|
+
/** True on Apple platforms, where `mod` is ⌘ and chords are shown with symbols. */
|
|
8
|
+
export function onApplePlatform() {
|
|
9
|
+
return typeof navigator !== 'undefined' && /Mac|iPhone|iPad|iPod/.test(navigator.platform || navigator.userAgent);
|
|
10
|
+
}
|
|
11
|
+
const both = (word) => [word, word];
|
|
12
|
+
const NAMED_KEYS = {
|
|
13
|
+
space: { shown: both('Space'), said: both('Space'), aria: 'Space' },
|
|
14
|
+
enter: { shown: ['Enter', '↵'], said: both('Enter'), aria: 'Enter' },
|
|
15
|
+
escape: { shown: both('Esc'), said: both('Esc'), aria: 'Escape' },
|
|
16
|
+
tab: { shown: both('Tab'), said: both('Tab'), aria: 'Tab' },
|
|
17
|
+
backspace: { shown: ['Backspace', '⌫'], said: ['Backspace', 'Delete'], aria: 'Backspace' },
|
|
18
|
+
delete: { shown: ['Delete', '⌦'], said: both('Delete'), aria: 'Delete' },
|
|
19
|
+
insert: { shown: both('Insert'), said: both('Insert'), aria: 'Insert' },
|
|
20
|
+
home: { shown: both('Home'), said: both('Home'), aria: 'Home' },
|
|
21
|
+
end: { shown: both('End'), said: both('End'), aria: 'End' },
|
|
22
|
+
pageup: { shown: both('Page Up'), said: both('Page Up'), aria: 'PageUp' },
|
|
23
|
+
pagedown: { shown: both('Page Down'), said: both('Page Down'), aria: 'PageDown' },
|
|
24
|
+
arrowup: { shown: both('↑'), said: both('Up'), aria: 'ArrowUp' },
|
|
25
|
+
arrowdown: { shown: both('↓'), said: both('Down'), aria: 'ArrowDown' },
|
|
26
|
+
arrowleft: { shown: both('←'), said: both('Left'), aria: 'ArrowLeft' },
|
|
27
|
+
arrowright: { shown: both('→'), said: both('Right'), aria: 'ArrowRight' },
|
|
28
|
+
};
|
|
29
|
+
/** Modifier words, in the order they are written: shown elsewhere, shown on Apple, said elsewhere, said on Apple, aria. */
|
|
30
|
+
const MODIFIERS = [
|
|
31
|
+
{ held: 'ctrl', other: 'Ctrl', apple: '⌃', saidApple: 'Control', aria: 'Control' },
|
|
32
|
+
{ held: 'alt', other: 'Alt', apple: '⌥', saidApple: 'Option', aria: 'Alt' },
|
|
33
|
+
{ held: 'shift', other: 'Shift', apple: '⇧', saidApple: 'Shift', aria: 'Shift' },
|
|
34
|
+
{ held: 'meta', other: 'Ctrl', apple: '⌘', saidApple: 'Command', aria: 'Meta' },
|
|
35
|
+
];
|
|
36
|
+
/** The physical key of each punctuation character on a US layout. */
|
|
37
|
+
const PUNCTUATION_CODES = {
|
|
38
|
+
',': 'Comma',
|
|
39
|
+
'.': 'Period',
|
|
40
|
+
'/': 'Slash',
|
|
41
|
+
';': 'Semicolon',
|
|
42
|
+
"'": 'Quote',
|
|
43
|
+
'[': 'BracketLeft',
|
|
44
|
+
']': 'BracketRight',
|
|
45
|
+
'\\': 'Backslash',
|
|
46
|
+
'-': 'Minus',
|
|
47
|
+
'=': 'Equal',
|
|
48
|
+
'`': 'Backquote',
|
|
49
|
+
};
|
|
50
|
+
const LATIN_KEY = /^[a-z0-9]$/i;
|
|
51
|
+
const FUNCTION_KEY = /^F([1-9]|1\d|2[0-4])$/;
|
|
52
|
+
/** The key's id in {@link NAMED_KEYS}, or undefined for a character or function key. */
|
|
53
|
+
function namedKey(key) {
|
|
54
|
+
const id = key === ' ' ? 'space' : key.toLowerCase();
|
|
55
|
+
return Object.hasOwn(NAMED_KEYS, id) ? id : undefined;
|
|
56
|
+
}
|
|
57
|
+
/** The chord with its modifiers as they are held on this platform. */
|
|
58
|
+
export function holdChord(chord, apple) {
|
|
59
|
+
return {
|
|
60
|
+
key: chord.key === ' ' ? 'Space' : chord.key,
|
|
61
|
+
meta: apple && chord.mod === true,
|
|
62
|
+
ctrl: chord.ctrl === true || (!apple && chord.mod === true),
|
|
63
|
+
alt: chord.alt === true,
|
|
64
|
+
shift: chord.shift === true,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function keyWord(key, pick, apple) {
|
|
68
|
+
const named = namedKey(key);
|
|
69
|
+
if (named !== undefined)
|
|
70
|
+
return NAMED_KEYS[named][pick][apple ? 1 : 0];
|
|
71
|
+
return key.length === 1 ? key.toUpperCase() : key;
|
|
72
|
+
}
|
|
73
|
+
/** The chord as a menu row or tooltip shows it: "⇧⌘K" on Apple, "Ctrl+Shift+K" elsewhere. */
|
|
74
|
+
export function chordLabel(chord, apple) {
|
|
75
|
+
const held = holdChord(chord, apple);
|
|
76
|
+
const key = keyWord(held.key, 'shown', apple);
|
|
77
|
+
if (apple)
|
|
78
|
+
return MODIFIERS.filter((m) => held[m.held]).map((m) => m.apple).join('') + key;
|
|
79
|
+
const words = [...new Set(MODIFIERS.filter((m) => held[m.held]).map((m) => m.other))];
|
|
80
|
+
return [...words, key].join('+');
|
|
81
|
+
}
|
|
82
|
+
/** The chord in words, for a screen reader: "Shift+Command+K" on Apple, "Ctrl+Shift+K" elsewhere. */
|
|
83
|
+
export function chordSpoken(chord, apple) {
|
|
84
|
+
const held = holdChord(chord, apple);
|
|
85
|
+
const words = [...new Set(MODIFIERS.filter((m) => held[m.held]).map((m) => (apple ? m.saidApple : m.other)))];
|
|
86
|
+
return [...words, keyWord(held.key, 'said', apple)].join('+');
|
|
87
|
+
}
|
|
88
|
+
/** The chord as `aria-keyshortcuts` takes it: "Meta+Shift+K" on Apple, "Control+Shift+K" elsewhere. */
|
|
89
|
+
export function chordAriaKeys(chord, apple) {
|
|
90
|
+
const held = holdChord(chord, apple);
|
|
91
|
+
const named = namedKey(held.key);
|
|
92
|
+
const key = named !== undefined ? NAMED_KEYS[named].aria : held.key === '+' ? 'Plus' : keyWord(held.key, 'shown', false);
|
|
93
|
+
return [...MODIFIERS.filter((m) => held[m.held]).map((m) => m.aria), key].join('+');
|
|
94
|
+
}
|
|
95
|
+
/** Reads an `aria-keyshortcuts` value written by {@link chordAriaKeys} back into a held chord; null when it isn't one. */
|
|
96
|
+
export function parseAriaKeys(text) {
|
|
97
|
+
const parts = text.trim().split('+');
|
|
98
|
+
const last = parts.pop();
|
|
99
|
+
if (last === undefined || last === '' || /\s/.test(text.trim()))
|
|
100
|
+
return null;
|
|
101
|
+
const held = { key: last === 'Plus' ? '+' : last, meta: false, ctrl: false, alt: false, shift: false };
|
|
102
|
+
for (const part of parts) {
|
|
103
|
+
const modifier = MODIFIERS.find((m) => m.aria === part);
|
|
104
|
+
if (modifier === undefined)
|
|
105
|
+
return null;
|
|
106
|
+
held[modifier.held] = true;
|
|
107
|
+
}
|
|
108
|
+
return held;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Whether an open menu can act on the chord itself: it holds ⌘, Ctrl or Alt, or is a function key. Chords that end in
|
|
112
|
+
* Enter or Space (the menu's own activation), paste, and Control+Option on Apple (the AltGr of some layouts) are left to
|
|
113
|
+
* the page.
|
|
114
|
+
*/
|
|
115
|
+
export function menuTakesChord(held, apple) {
|
|
116
|
+
const named = namedKey(held.key);
|
|
117
|
+
if (named === 'enter' || named === 'space')
|
|
118
|
+
return false;
|
|
119
|
+
if (!held.meta && !held.ctrl && !held.alt)
|
|
120
|
+
return FUNCTION_KEY.test(held.key);
|
|
121
|
+
if (apple && held.ctrl && held.alt)
|
|
122
|
+
return false;
|
|
123
|
+
const paste = held.key.toLowerCase() === 'v' && !held.alt;
|
|
124
|
+
return !paste;
|
|
125
|
+
}
|
|
126
|
+
/** The Latin letter or digit on the physical key pressed, lower-cased; '' when it isn't one. */
|
|
127
|
+
function physicalLatin(press) {
|
|
128
|
+
const code = /^(?:Key([A-Z])|Digit([0-9]))$/.exec(press.code ?? '');
|
|
129
|
+
if (code)
|
|
130
|
+
return (code[1] ?? code[2] ?? '').toLowerCase();
|
|
131
|
+
const keyCode = press.keyCode ?? 0;
|
|
132
|
+
if ((keyCode >= 65 && keyCode <= 90) || (keyCode >= 48 && keyCode <= 57))
|
|
133
|
+
return String.fromCharCode(keyCode).toLowerCase();
|
|
134
|
+
return '';
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Whether a keydown is the held chord. The modifiers must be the same. A letter or digit is taken as typed, so a
|
|
138
|
+
* remapped Latin layout keeps its letters; a non-Latin character falls back to the physical key, except under AltGr.
|
|
139
|
+
* A punctuation chord also matches its physical key when the layout puts another character there. `+` takes `=` too.
|
|
140
|
+
*/
|
|
141
|
+
export function chordMatchesPress(held, press) {
|
|
142
|
+
if (press.metaKey !== held.meta || press.ctrlKey !== held.ctrl || press.altKey !== held.alt)
|
|
143
|
+
return false;
|
|
144
|
+
// AltGr reports Control and Alt while it types a character: that is text, not a chord.
|
|
145
|
+
if (press.altGraph === true && press.ctrlKey && press.altKey && press.key.length === 1)
|
|
146
|
+
return false;
|
|
147
|
+
const typed = press.key;
|
|
148
|
+
const want = held.key;
|
|
149
|
+
if (want === '+')
|
|
150
|
+
return (typed === '+' || typed === '=' || press.code === 'NumpadAdd') && (press.shiftKey || !held.shift);
|
|
151
|
+
if (LATIN_KEY.test(want)) {
|
|
152
|
+
if (press.shiftKey !== held.shift)
|
|
153
|
+
return false;
|
|
154
|
+
if (typed.toLowerCase() === want.toLowerCase())
|
|
155
|
+
return true;
|
|
156
|
+
if (LATIN_KEY.test(typed) || (press.altGraph === true && !press.altKey))
|
|
157
|
+
return false;
|
|
158
|
+
return physicalLatin(press) === want.toLowerCase();
|
|
159
|
+
}
|
|
160
|
+
if (want.length > 1) {
|
|
161
|
+
const named = namedKey(want);
|
|
162
|
+
const pressedNamed = namedKey(typed);
|
|
163
|
+
const same = named !== undefined ? pressedNamed === named : typed.toLowerCase() === want.toLowerCase();
|
|
164
|
+
return same && press.shiftKey === held.shift;
|
|
165
|
+
}
|
|
166
|
+
const code = PUNCTUATION_CODES[want];
|
|
167
|
+
if (typed === want) {
|
|
168
|
+
if (press.shiftKey === held.shift)
|
|
169
|
+
return true;
|
|
170
|
+
// A layout that needs Shift to type the character still means the plain chord.
|
|
171
|
+
return !held.shift && (code === undefined || press.code !== code);
|
|
172
|
+
}
|
|
173
|
+
if (code === undefined || press.code !== code || press.shiftKey !== held.shift || LATIN_KEY.test(typed))
|
|
174
|
+
return false;
|
|
175
|
+
// Another character on the same physical key: Shift or Option made it, or the layout has something else there.
|
|
176
|
+
return held.shift || press.altKey || !/^[ -~]$/.test(typed);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Whether a keydown edits the text of the field it lands in: it moves the caret, deletes, uses the clipboard or
|
|
180
|
+
* undoes (with or without ⌘ / Ctrl), or types a character with Option.
|
|
181
|
+
*/
|
|
182
|
+
export function editsText(press) {
|
|
183
|
+
if (/^(Arrow|Home$|End$|Backspace$|Delete$)/.test(press.key))
|
|
184
|
+
return true;
|
|
185
|
+
if (press.altKey)
|
|
186
|
+
return !press.metaKey;
|
|
187
|
+
const letter = physicalLatin(press);
|
|
188
|
+
return press.shiftKey ? letter === 'v' || letter === 'z' : ['a', 'c', 'v', 'x', 'y', 'z'].includes(letter);
|
|
189
|
+
}
|
|
190
|
+
/** Symbols shortcut text is written with, and their spoken names: elsewhere, on Apple. */
|
|
191
|
+
const SHORTCUT_SYMBOLS = {
|
|
192
|
+
'⌘': ['Ctrl', 'Command'],
|
|
193
|
+
'⌃': ['Ctrl', 'Control'],
|
|
194
|
+
'⌥': ['Alt', 'Option'],
|
|
195
|
+
'⇧': both('Shift'),
|
|
196
|
+
'↵': both('Enter'),
|
|
197
|
+
'⏎': both('Enter'),
|
|
198
|
+
'⌫': ['Backspace', 'Delete'],
|
|
199
|
+
'⌦': both('Delete'),
|
|
200
|
+
'⎋': both('Esc'),
|
|
201
|
+
'⇥': both('Tab'),
|
|
202
|
+
'↑': both('Up'),
|
|
203
|
+
'↓': both('Down'),
|
|
204
|
+
'←': both('Left'),
|
|
205
|
+
'→': both('Right'),
|
|
206
|
+
};
|
|
207
|
+
/**
|
|
208
|
+
* Shortcut text written with symbols ("⇧⌘Z", "⌘↵") in words for a screen reader ("Shift+Command+Z"); text that is
|
|
209
|
+
* already words ("Ctrl+Shift+Z") comes back as it is.
|
|
210
|
+
*/
|
|
211
|
+
export function spokenShortcut(text, apple) {
|
|
212
|
+
const words = [];
|
|
213
|
+
let rest = '';
|
|
214
|
+
for (const char of text) {
|
|
215
|
+
const symbol = SHORTCUT_SYMBOLS[char];
|
|
216
|
+
if (symbol === undefined) {
|
|
217
|
+
rest += char;
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
if (rest !== '')
|
|
221
|
+
words.push(rest);
|
|
222
|
+
rest = '';
|
|
223
|
+
words.push(symbol[apple ? 1 : 0]);
|
|
224
|
+
}
|
|
225
|
+
if (rest !== '')
|
|
226
|
+
words.push(rest);
|
|
227
|
+
return words.map((word) => word.replace(/^\+|\+$/g, '')).filter((word) => word !== '').join('+');
|
|
228
|
+
}
|