@artkit-ai/react 0.0.0-stage → 0.2.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/README.md +145 -2
- package/dist/cache.d.ts +31 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/cache.js +95 -0
- package/dist/cache.js.map +1 -0
- package/dist/client.d.ts +68 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +233 -0
- package/dist/client.js.map +1 -0
- package/dist/components/card.d.ts +22 -0
- package/dist/components/card.d.ts.map +1 -0
- package/dist/components/card.js +16 -0
- package/dist/components/card.js.map +1 -0
- package/dist/components/editor.d.ts +41 -0
- package/dist/components/editor.d.ts.map +1 -0
- package/dist/components/editor.js +111 -0
- package/dist/components/editor.js.map +1 -0
- package/dist/components/icons.d.ts +8 -0
- package/dist/components/icons.d.ts.map +1 -0
- package/dist/components/icons.js +14 -0
- package/dist/components/icons.js.map +1 -0
- package/dist/components/panel.d.ts +31 -0
- package/dist/components/panel.d.ts.map +1 -0
- package/dist/components/panel.js +132 -0
- package/dist/components/panel.js.map +1 -0
- package/dist/components/shared.d.ts +67 -0
- package/dist/components/shared.d.ts.map +1 -0
- package/dist/components/shared.js +100 -0
- package/dist/components/shared.js.map +1 -0
- package/dist/components/view.d.ts +39 -0
- package/dist/components/view.d.ts.map +1 -0
- package/dist/components/view.js +76 -0
- package/dist/components/view.js.map +1 -0
- package/dist/context.d.ts +64 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +13 -0
- package/dist/context.js.map +1 -0
- package/dist/controls.d.ts +145 -0
- package/dist/controls.d.ts.map +1 -0
- package/dist/controls.js +188 -0
- package/dist/controls.js.map +1 -0
- package/dist/download.d.ts +4 -0
- package/dist/download.d.ts.map +1 -0
- package/dist/download.js +20 -0
- package/dist/download.js.map +1 -0
- package/dist/editor-session.d.ts +96 -0
- package/dist/editor-session.d.ts.map +1 -0
- package/dist/editor-session.js +192 -0
- package/dist/editor-session.js.map +1 -0
- package/dist/hooks.d.ts +64 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +205 -0
- package/dist/hooks.js.map +1 -0
- package/dist/i18n.d.ts +135 -0
- package/dist/i18n.d.ts.map +1 -0
- package/dist/i18n.js +145 -0
- package/dist/i18n.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/kit-css.d.ts +3 -0
- package/dist/kit-css.d.ts.map +1 -0
- package/dist/kit-css.js +5 -0
- package/dist/kit-css.js.map +1 -0
- package/dist/partial-json.d.ts +8 -0
- package/dist/partial-json.d.ts.map +1 -0
- package/dist/partial-json.js +176 -0
- package/dist/partial-json.js.map +1 -0
- package/dist/provider.d.ts +42 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +95 -0
- package/dist/provider.js.map +1 -0
- package/dist/styles.d.ts +25 -0
- package/dist/styles.d.ts.map +1 -0
- package/dist/styles.js +203 -0
- package/dist/styles.js.map +1 -0
- package/dist/toolbar.d.ts +90 -0
- package/dist/toolbar.d.ts.map +1 -0
- package/dist/toolbar.js +233 -0
- package/dist/toolbar.js.map +1 -0
- package/package.json +50 -3
- package/src/cache.ts +109 -0
- package/src/client.ts +342 -0
- package/src/components/card.tsx +86 -0
- package/src/components/editor.tsx +292 -0
- package/src/components/icons.tsx +14 -0
- package/src/components/panel.tsx +334 -0
- package/src/components/shared.tsx +198 -0
- package/src/components/view.tsx +196 -0
- package/src/context.ts +87 -0
- package/src/controls.tsx +587 -0
- package/src/download.ts +23 -0
- package/src/editor-session.ts +260 -0
- package/src/hooks.ts +296 -0
- package/src/i18n.ts +155 -0
- package/src/index.ts +128 -0
- package/src/kit-css.ts +5 -0
- package/src/partial-json.ts +160 -0
- package/src/provider.tsx +176 -0
- package/src/styles.ts +222 -0
- package/src/toolbar.tsx +536 -0
package/dist/toolbar.js
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { COLOR_TOKENS } from '@artkit-ai/core';
|
|
3
|
+
import { Check, ChevronDown, X } from 'lucide-react';
|
|
4
|
+
import { useCallback, useEffect, useId, useRef, useState, } from 'react';
|
|
5
|
+
/*
|
|
6
|
+
* Standard editor toolbar shared by every kind editor (document, sheet, slides, diagram) so all of them
|
|
7
|
+
* look and behave the same: icon buttons with tooltips and shortcuts, grouped with dividers, selects,
|
|
8
|
+
* dropdown menus and theme color palettes. Keyboard model follows the WAI-ARIA toolbar pattern: one tab
|
|
9
|
+
* stop, arrows/Home/End move between controls, menus open with Enter/Space/ArrowDown and close with Escape.
|
|
10
|
+
*/
|
|
11
|
+
const ITEM = '[data-ak-tb-item]:not([disabled])';
|
|
12
|
+
function cx(...classes) {
|
|
13
|
+
return classes.filter(Boolean).join(' ');
|
|
14
|
+
}
|
|
15
|
+
/** Keeps the editor selection (text, cells) when a toolbar control is clicked with the mouse. */
|
|
16
|
+
function keepSelection(event) {
|
|
17
|
+
event.preventDefault();
|
|
18
|
+
}
|
|
19
|
+
export function Toolbar({ label, children, className, sticky = true }) {
|
|
20
|
+
const ref = useRef(null);
|
|
21
|
+
// Roving tab index: only the active control is tabbable.
|
|
22
|
+
const sync = useCallback((focusIndex) => {
|
|
23
|
+
const items = [...(ref.current?.querySelectorAll(ITEM) ?? [])].filter((item) => !item.closest('[data-ak-tb-popover]'));
|
|
24
|
+
const active = focusIndex ?? Math.max(0, items.indexOf(document.activeElement));
|
|
25
|
+
items.forEach((item, index) => {
|
|
26
|
+
item.tabIndex = index === active ? 0 : -1;
|
|
27
|
+
});
|
|
28
|
+
return items;
|
|
29
|
+
}, []);
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
sync(0);
|
|
32
|
+
});
|
|
33
|
+
const onKeyDown = (event) => {
|
|
34
|
+
if (event.target.closest('[data-ak-tb-popover]'))
|
|
35
|
+
return;
|
|
36
|
+
if (event.target.tagName === 'SELECT' &&
|
|
37
|
+
(event.key === 'ArrowUp' || event.key === 'ArrowDown'))
|
|
38
|
+
return;
|
|
39
|
+
const items = sync();
|
|
40
|
+
const current = items.indexOf(event.target);
|
|
41
|
+
if (current < 0)
|
|
42
|
+
return;
|
|
43
|
+
let next = -1;
|
|
44
|
+
if (event.key === 'ArrowRight')
|
|
45
|
+
next = (current + 1) % items.length;
|
|
46
|
+
else if (event.key === 'ArrowLeft')
|
|
47
|
+
next = (current - 1 + items.length) % items.length;
|
|
48
|
+
else if (event.key === 'Home')
|
|
49
|
+
next = 0;
|
|
50
|
+
else if (event.key === 'End')
|
|
51
|
+
next = items.length - 1;
|
|
52
|
+
if (next < 0)
|
|
53
|
+
return;
|
|
54
|
+
event.preventDefault();
|
|
55
|
+
sync(next);
|
|
56
|
+
items[next]?.focus();
|
|
57
|
+
};
|
|
58
|
+
return (_jsx("div", { ref: ref, role: "toolbar", "aria-label": label, className: cx('ak-tb', sticky && 'ak-tb--sticky', className), onKeyDown: onKeyDown, onFocus: (event) => {
|
|
59
|
+
if (event.target.matches(ITEM))
|
|
60
|
+
sync([...sync()].indexOf(event.target));
|
|
61
|
+
}, children: children }));
|
|
62
|
+
}
|
|
63
|
+
export function ToolbarGroup({ label, children }) {
|
|
64
|
+
return (_jsxs("fieldset", { className: "ak-tb-group", children: [label ? _jsx("legend", { className: "ak-tb-sr-only", children: label }) : null, children] }));
|
|
65
|
+
}
|
|
66
|
+
export function ToolbarSpacer() {
|
|
67
|
+
return _jsx("span", { className: "ak-tb-spacer", "aria-hidden": "true" });
|
|
68
|
+
}
|
|
69
|
+
function tooltip(label, shortcut) {
|
|
70
|
+
return shortcut ? `${label} (${shortcut})` : label;
|
|
71
|
+
}
|
|
72
|
+
export function ToolbarButton({ icon: Icon, label, onClick, pressed, disabled, shortcut, showLabel, variant = 'default', keepFocus = true, }) {
|
|
73
|
+
return (_jsxs("button", { type: "button", "data-ak-tb-item": "", className: cx('ak-tb-button', (showLabel || !Icon) && 'ak-tb-button--text'), "data-variant": variant === 'default' ? undefined : variant, "aria-label": showLabel ? undefined : label, title: tooltip(label, shortcut), "aria-pressed": pressed, "aria-keyshortcuts": shortcut?.replace(/Ctrl/g, 'Control'), disabled: disabled, onMouseDown: keepFocus ? keepSelection : undefined, onClick: onClick, children: [Icon ? _jsx(Icon, { "aria-hidden": "true" }) : null, showLabel || !Icon ? _jsx("span", { children: label }) : null] }));
|
|
74
|
+
}
|
|
75
|
+
export function ToolbarSelect({ label, value, options, onChange, disabled, width, }) {
|
|
76
|
+
return (_jsx("select", { "data-ak-tb-item": "", className: "ak-tb-select", "aria-label": label, title: label, value: value, disabled: disabled, style: width ? { width } : undefined, onChange: (event) => onChange(event.target.value), children: options.map((option) => (_jsx("option", { value: option.value, children: option.label }, option.value))) }));
|
|
77
|
+
}
|
|
78
|
+
/** Popover anchored under a toolbar trigger; closes on Escape, outside click and selection. */
|
|
79
|
+
function usePopover() {
|
|
80
|
+
const [open, setOpen] = useState(false);
|
|
81
|
+
const root = useRef(null);
|
|
82
|
+
const trigger = useRef(null);
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
if (!open)
|
|
85
|
+
return;
|
|
86
|
+
const onDown = (event) => {
|
|
87
|
+
if (!root.current?.contains(event.target))
|
|
88
|
+
setOpen(false);
|
|
89
|
+
};
|
|
90
|
+
document.addEventListener('mousedown', onDown);
|
|
91
|
+
return () => document.removeEventListener('mousedown', onDown);
|
|
92
|
+
}, [open]);
|
|
93
|
+
const close = (refocus = true) => {
|
|
94
|
+
setOpen(false);
|
|
95
|
+
if (refocus)
|
|
96
|
+
trigger.current?.focus();
|
|
97
|
+
};
|
|
98
|
+
return { open, setOpen, root, trigger, close };
|
|
99
|
+
}
|
|
100
|
+
function focusItems(container, index) {
|
|
101
|
+
const items = [...(container?.querySelectorAll('[role^="menuitem"]:not([disabled])') ?? [])];
|
|
102
|
+
if (items.length === 0)
|
|
103
|
+
return;
|
|
104
|
+
const target = index === 'first' ? 0 : index === 'last' ? items.length - 1 : (index + items.length) % items.length;
|
|
105
|
+
items[target]?.focus();
|
|
106
|
+
}
|
|
107
|
+
function menuKeys(event, close) {
|
|
108
|
+
const items = [...event.currentTarget.querySelectorAll('[role^="menuitem"]:not([disabled])')];
|
|
109
|
+
const current = items.indexOf(document.activeElement);
|
|
110
|
+
const columns = Number(event.currentTarget.dataset.columns ?? 1);
|
|
111
|
+
const step = {
|
|
112
|
+
ArrowDown: columns,
|
|
113
|
+
ArrowUp: -columns,
|
|
114
|
+
ArrowRight: columns > 1 ? 1 : 0,
|
|
115
|
+
ArrowLeft: columns > 1 ? -1 : 0,
|
|
116
|
+
}[event.key];
|
|
117
|
+
if (event.key === 'Escape') {
|
|
118
|
+
event.preventDefault();
|
|
119
|
+
event.stopPropagation();
|
|
120
|
+
close();
|
|
121
|
+
}
|
|
122
|
+
else if (step) {
|
|
123
|
+
event.preventDefault();
|
|
124
|
+
focusItems(event.currentTarget, current + step);
|
|
125
|
+
}
|
|
126
|
+
else if (event.key === 'Home' || event.key === 'End') {
|
|
127
|
+
event.preventDefault();
|
|
128
|
+
focusItems(event.currentTarget, event.key === 'Home' ? 'first' : 'last');
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
export function ToolbarMenu({ icon: Icon, label, items, disabled, showLabel, keepFocus = true, }) {
|
|
132
|
+
const { open, setOpen, root, trigger, close } = usePopover();
|
|
133
|
+
const list = useRef(null);
|
|
134
|
+
const id = useId();
|
|
135
|
+
useEffect(() => {
|
|
136
|
+
if (open)
|
|
137
|
+
focusItems(list.current, 'first');
|
|
138
|
+
}, [open]);
|
|
139
|
+
const hasChecks = items.some((item) => item !== 'separator' && item.checked !== undefined);
|
|
140
|
+
return (_jsxs("span", { ref: root, className: "ak-tb-anchor", children: [_jsxs("button", { ref: trigger, type: "button", "data-ak-tb-item": "", className: cx('ak-tb-button', 'ak-tb-button--menu', (showLabel || !Icon) && 'ak-tb-button--text'), "aria-label": showLabel ? undefined : label, title: label, "aria-haspopup": "menu", "aria-expanded": open, "aria-controls": open ? id : undefined, disabled: disabled, onMouseDown: keepFocus ? keepSelection : undefined, onClick: () => setOpen(!open), onKeyDown: (event) => {
|
|
141
|
+
if (event.key === 'ArrowDown' && !open) {
|
|
142
|
+
event.preventDefault();
|
|
143
|
+
setOpen(true);
|
|
144
|
+
}
|
|
145
|
+
}, children: [Icon ? _jsx(Icon, { "aria-hidden": "true" }) : null, showLabel || !Icon ? _jsx("span", { children: label }) : null, _jsx(ChevronDown, { "aria-hidden": "true", className: "ak-tb-caret" })] }), open ? (_jsx("div", { ref: list, id: id, role: "menu", "aria-label": label, className: "ak-tb-popover", "data-ak-tb-popover": "", onKeyDown: (event) => menuKeys(event, () => close()), children: items.map((item, index) => item === 'separator' ? (_jsx("hr", { className: "ak-tb-separator" }, `sep-${index}`)) : (_jsxs("button", { type: "button", ...(item.checked === undefined
|
|
146
|
+
? { role: 'menuitem' }
|
|
147
|
+
: { role: 'menuitemradio', 'aria-checked': item.checked }), tabIndex: -1, className: "ak-tb-menu-item", "data-danger": item.danger ? '' : undefined, disabled: item.disabled, onMouseDown: keepFocus ? keepSelection : undefined, onClick: () => {
|
|
148
|
+
close(!keepFocus);
|
|
149
|
+
item.onSelect();
|
|
150
|
+
}, children: [hasChecks ? (_jsx("span", { className: "ak-tb-check", "aria-hidden": "true", children: item.checked ? _jsx(Check, {}) : null })) : null, item.icon ? _jsx(item.icon, { "aria-hidden": "true" }) : null, _jsx("span", { className: "ak-tb-menu-label", children: item.label }), item.shortcut ? _jsx("kbd", { className: "ak-tb-kbd", children: item.shortcut }) : null] }, item.key))) })) : null] }));
|
|
151
|
+
}
|
|
152
|
+
/** Swatches for the theme color tokens (labels in pt-BR or English). */
|
|
153
|
+
export function themeSwatches(theme, locale = 'en') {
|
|
154
|
+
const pt = locale.toLowerCase().startsWith('pt');
|
|
155
|
+
const names = {
|
|
156
|
+
text: ['Text', 'Texto'],
|
|
157
|
+
muted: ['Muted', 'Suave'],
|
|
158
|
+
accent: ['Accent', 'Destaque'],
|
|
159
|
+
background: ['Background', 'Fundo'],
|
|
160
|
+
surface: ['Surface', 'Superfície'],
|
|
161
|
+
info: ['Info', 'Informação'],
|
|
162
|
+
warning: ['Warning', 'Atenção'],
|
|
163
|
+
success: ['Success', 'Sucesso'],
|
|
164
|
+
danger: ['Danger', 'Perigo'],
|
|
165
|
+
};
|
|
166
|
+
return COLOR_TOKENS.map((token) => ({
|
|
167
|
+
value: token,
|
|
168
|
+
label: names[token][pt ? 1 : 0],
|
|
169
|
+
swatch: theme.colors[token],
|
|
170
|
+
}));
|
|
171
|
+
}
|
|
172
|
+
export function ToolbarColor({ icon: Icon, label, value, colors, onChange, noneLabel, disabled, keepFocus = true, }) {
|
|
173
|
+
const { open, setOpen, root, trigger, close } = usePopover();
|
|
174
|
+
const grid = useRef(null);
|
|
175
|
+
const id = useId();
|
|
176
|
+
const current = colors.find((color) => color.value === value);
|
|
177
|
+
useEffect(() => {
|
|
178
|
+
if (open)
|
|
179
|
+
focusItems(grid.current, 'first');
|
|
180
|
+
}, [open]);
|
|
181
|
+
return (_jsxs("span", { ref: root, className: "ak-tb-anchor", children: [_jsxs("button", { ref: trigger, type: "button", "data-ak-tb-item": "", className: "ak-tb-button ak-tb-button--menu ak-tb-button--color", "aria-label": `${label}${current ? `: ${current.label}` : ''}`, title: label, "aria-haspopup": "menu", "aria-expanded": open, "aria-controls": open ? id : undefined, disabled: disabled, onMouseDown: keepFocus ? keepSelection : undefined, onClick: () => setOpen(!open), children: [_jsxs("span", { className: "ak-tb-color-icon", children: [_jsx(Icon, { "aria-hidden": "true" }), _jsx("span", { className: "ak-tb-color-bar", style: { background: current?.swatch ?? 'transparent' } })] }), _jsx(ChevronDown, { "aria-hidden": "true", className: "ak-tb-caret" })] }), open ? (_jsxs("div", { ref: grid, id: id, role: "menu", "aria-label": label, className: "ak-tb-popover ak-tb-palette", "data-ak-tb-popover": "", "data-columns": "5", onKeyDown: (event) => menuKeys(event, () => close()), children: [colors.map((color) => (_jsx("button", { type: "button", role: "menuitemradio", "aria-checked": color.value === value, "aria-label": color.label, title: color.label, tabIndex: -1, className: "ak-tb-swatch", style: { background: color.swatch }, onMouseDown: keepFocus ? keepSelection : undefined, onClick: () => {
|
|
182
|
+
close(!keepFocus);
|
|
183
|
+
onChange(color.value);
|
|
184
|
+
} }, color.value))), noneLabel ? (_jsxs("button", { type: "button", role: "menuitemradio", "aria-checked": !value, tabIndex: -1, className: "ak-tb-menu-item ak-tb-palette-none", onMouseDown: keepFocus ? keepSelection : undefined, onClick: () => {
|
|
185
|
+
close(!keepFocus);
|
|
186
|
+
onChange(null);
|
|
187
|
+
}, children: [_jsx(X, { "aria-hidden": "true" }), _jsx("span", { className: "ak-tb-menu-label", children: noneLabel })] })) : null] })) : null] }));
|
|
188
|
+
}
|
|
189
|
+
/** Toolbar styles (Mouts design system); embedded in `artkitCss` and in every kind editor CSS. */
|
|
190
|
+
export const toolbarCss = `
|
|
191
|
+
.ak-tb{display:flex;flex-wrap:wrap;align-items:center;gap:4px;padding:6px;background:var(--ak-color-background,#fff);color:var(--ak-color-text,#1d2f3c);border:1px solid var(--ak-color-border,#dde0e2);border-radius:var(--ak-radius-md,8px);font-family:var(--ak-font-body,"Sora",system-ui,sans-serif);font-size:13px;line-height:1}
|
|
192
|
+
.ak-tb--sticky{position:sticky;top:0;z-index:5}
|
|
193
|
+
.ak-tb-group{display:inline-flex;align-items:center;gap:2px;margin:0;padding:0 0 0 6px;border:0;border-left:1px solid var(--ak-color-border,#dde0e2);min-inline-size:0}
|
|
194
|
+
.ak-tb-group:first-child{padding-left:0;border-left:0}
|
|
195
|
+
.ak-tb-spacer{flex:1}
|
|
196
|
+
.ak-tb-sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0}
|
|
197
|
+
.ak-tb-button{display:inline-flex;align-items:center;justify-content:center;gap:6px;min-width:32px;height:32px;padding:0 6px;border:1px solid transparent;border-radius:var(--ak-radius-sm,6px);background:none;color:var(--ak-color-muted,#56636d);font:inherit;font-weight:600;cursor:pointer;white-space:nowrap;transition:background-color .15s,color .15s,border-color .15s}
|
|
198
|
+
.ak-tb-button svg{width:16px;height:16px;flex-shrink:0}
|
|
199
|
+
.ak-tb-button--text{padding:0 10px;color:var(--ak-color-text,#1d2f3c)}
|
|
200
|
+
.ak-tb-button:hover:not(:disabled){background:var(--ak-color-hover,#f2f3f4);color:var(--ak-color-text,#1d2f3c)}
|
|
201
|
+
.ak-tb-button:active:not(:disabled){background:var(--ak-color-active,#e8eaec)}
|
|
202
|
+
.ak-tb-button[aria-pressed="true"],.ak-tb-button[aria-expanded="true"]{background:var(--ak-color-fill-accent,#e7f2ef);color:var(--ak-color-accent,#0f7a5a);border-color:var(--ak-color-accent,#0f7a5a)}
|
|
203
|
+
.ak-tb-button[data-variant="primary"]{background:var(--ak-gradient-button);color:var(--ak-color-on-primary,#1d2f3c);border-color:transparent}
|
|
204
|
+
.ak-tb-button[data-variant="primary"]:hover:not(:disabled){background:var(--ak-gradient-button-hover)}
|
|
205
|
+
.ak-tb-button[data-variant="danger"]{color:var(--ak-color-danger,#9f343a)}
|
|
206
|
+
.ak-tb-button[data-variant="danger"]:hover:not(:disabled){background:var(--ak-color-fill-danger,#f5ebeb)}
|
|
207
|
+
.ak-tb-button:disabled,.ak-tb-select:disabled{opacity:.4;cursor:not-allowed}
|
|
208
|
+
.ak-tb-button:focus-visible,.ak-tb-select:focus-visible,.ak-tb-menu-item:focus-visible,.ak-tb-swatch:focus-visible{outline:2px solid var(--ak-color-focus,#0f7a5a);outline-offset:2px}
|
|
209
|
+
.ak-tb-button--menu{padding:0 4px 0 6px;gap:2px}
|
|
210
|
+
.ak-tb-button--menu.ak-tb-button--text{padding:0 6px 0 10px}
|
|
211
|
+
.ak-tb-button .ak-tb-caret{width:12px;height:12px;opacity:.7}
|
|
212
|
+
.ak-tb-color-icon{position:relative;display:inline-flex;flex-direction:column;align-items:center;gap:1px}
|
|
213
|
+
.ak-tb-color-bar{display:block;width:16px;height:3px;border-radius:2px;border:1px solid var(--ak-color-border,#dde0e2)}
|
|
214
|
+
.ak-tb-select{height:32px;max-width:200px;padding:0 8px;font:inherit;font-size:13px;color:var(--ak-color-text,#1d2f3c);background:var(--ak-color-background,#fff);border:1px solid var(--ak-color-border-strong,#8e979d);border-radius:var(--ak-radius-sm,6px);cursor:pointer}
|
|
215
|
+
.ak-tb-anchor{position:relative;display:inline-flex}
|
|
216
|
+
.ak-tb-popover{position:absolute;top:calc(100% + 4px);left:0;z-index:30;display:flex;flex-direction:column;min-width:200px;max-height:360px;overflow:auto;padding:4px;background:var(--ak-color-background,#fff);border:1px solid var(--ak-color-border-strong,#8e979d);border-radius:var(--ak-radius-md,8px)}
|
|
217
|
+
.ak-tb-menu-item{display:flex;align-items:center;gap:8px;width:100%;min-height:32px;padding:0 10px;border:0;border-radius:var(--ak-radius-sm,6px);background:none;color:var(--ak-color-text,#1d2f3c);font:inherit;font-size:13px;text-align:left;cursor:pointer}
|
|
218
|
+
.ak-tb-menu-item svg{width:16px;height:16px;flex-shrink:0;color:var(--ak-color-muted,#56636d)}
|
|
219
|
+
.ak-tb-menu-item:hover:not(:disabled),.ak-tb-menu-item:focus{background:var(--ak-color-hover,#f2f3f4)}
|
|
220
|
+
.ak-tb-menu-item:disabled{opacity:.4;cursor:not-allowed}
|
|
221
|
+
.ak-tb-menu-item[data-danger]{color:var(--ak-color-danger,#9f343a)}
|
|
222
|
+
.ak-tb-menu-item[aria-checked="true"]{color:var(--ak-color-accent,#0f7a5a);font-weight:600}
|
|
223
|
+
.ak-tb-menu-label{flex:1}
|
|
224
|
+
.ak-tb-check{display:inline-flex;width:16px}
|
|
225
|
+
.ak-tb-check svg{color:var(--ak-color-accent,#0f7a5a)}
|
|
226
|
+
.ak-tb-kbd{font-family:var(--ak-font-mono,ui-monospace,monospace);font-size:11px;color:var(--ak-color-muted,#56636d)}
|
|
227
|
+
.ak-tb-separator{width:100%;height:1px;margin:4px 0;border:0;background:var(--ak-color-border,#dde0e2)}
|
|
228
|
+
.ak-tb-palette{display:grid;grid-template-columns:repeat(5,28px);gap:6px;min-width:0;padding:8px}
|
|
229
|
+
.ak-tb-swatch{width:28px;height:28px;padding:0;border:1px solid var(--ak-color-border-strong,#8e979d);border-radius:var(--ak-radius-sm,6px);cursor:pointer}
|
|
230
|
+
.ak-tb-swatch[aria-checked="true"]{box-shadow:inset 0 0 0 2px var(--ak-color-background,#fff);border:2px solid var(--ak-color-accent,#0f7a5a)}
|
|
231
|
+
.ak-tb-palette-none{grid-column:1/-1}
|
|
232
|
+
`;
|
|
233
|
+
//# sourceMappingURL=toolbar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toolbar.js","sourceRoot":"","sources":["../src/toolbar.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAA+B,MAAM,iBAAiB,CAAC;AAC5E,OAAO,EAAE,KAAK,EAAE,WAAW,EAAmB,CAAC,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,EAIL,WAAW,EACX,SAAS,EACT,KAAK,EACL,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AAEf;;;;;GAKG;AAEH,MAAM,IAAI,GAAG,mCAAmC,CAAC;AAEjD,SAAS,EAAE,CAAC,GAAG,OAA8C;IAC3D,OAAO,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC3C,CAAC;AAED,iGAAiG;AACjG,SAAS,aAAa,CAAC,KAAiB;IACtC,KAAK,CAAC,cAAc,EAAE,CAAC;AACzB,CAAC;AAUD,MAAM,UAAU,OAAO,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,EAAgB;IACjF,MAAM,GAAG,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;IACzC,yDAAyD;IACzD,MAAM,IAAI,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,CAAC,EACD,SAAS,CAAC,CAAC,CAAC,CACX,kBACE,IAAI,EAAC,QAAQ,EACb,IAAI,EAAC,eAAe,kBACN,CAAC,KAAK,EACpB,QAAQ,EAAE,CAAC,CAAC,EACZ,SAAS,EAAC,oCAAoC,EAC9C,WAAW,EAAE,SAAS,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,EAClD,OAAO,EAAE,GAAG,EAAE;4BACZ,KAAK,CAAC,CAAC,SAAS,CAAC,CAAC;4BAClB,QAAQ,CAAC,IAAI,CAAC,CAAC;wBACjB,CAAC,aAED,KAAC,CAAC,mBAAa,MAAM,GAAG,EACxB,eAAM,SAAS,EAAC,kBAAkB,YAAE,SAAS,GAAQ,IAC9C,CACV,CAAC,CAAC,CAAC,IAAI,IACJ,CACP,CAAC,CAAC,CAAC,IAAI,IACH,CACR,CAAC;AACJ,CAAC;AAED,kGAAkG;AAClG,MAAM,CAAC,MAAM,UAAU,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0CzB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@artkit-ai/react",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "React host for artkit artifacts: provider, view, editor, panel, card, approval, version diff, hooks and streaming preview.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"keywords": [
|
|
9
|
+
"artkit",
|
|
10
|
+
"ai",
|
|
11
|
+
"agents",
|
|
12
|
+
"artifacts"
|
|
13
|
+
],
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"@artkit/source": "./src/index.ts",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"import": "./dist/index.js"
|
|
19
|
+
},
|
|
20
|
+
"./package.json": "./package.json"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist",
|
|
24
|
+
"src",
|
|
25
|
+
"README.md"
|
|
26
|
+
],
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=22"
|
|
29
|
+
},
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/gustavonpco/artkit.git",
|
|
33
|
+
"directory": "packages/react"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public",
|
|
37
|
+
"provenance": true
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"lucide-react": "^1.68.0",
|
|
41
|
+
"@artkit-ai/core": "^0.2.0"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"react": "^19.0.0",
|
|
45
|
+
"react-dom": "^19.0.0"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"zod": "^4.6.7"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"build": "tsc -b"
|
|
52
|
+
}
|
|
6
53
|
}
|
package/src/cache.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type { Artifact } from '@artkit-ai/core';
|
|
2
|
+
import type { ArtifactClient } from './client.js';
|
|
3
|
+
|
|
4
|
+
export interface CacheEntry {
|
|
5
|
+
artifact?: Artifact;
|
|
6
|
+
error?: unknown;
|
|
7
|
+
loading: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const EMPTY: CacheEntry = Object.freeze({ loading: false }) as CacheEntry;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Artifact cache shared by the hooks under one provider (spec §13.2). One entry per artifact: the current content the
|
|
14
|
+
* application last loaded or saved. The library keeps no older versions, so there is nothing else to cache.
|
|
15
|
+
*/
|
|
16
|
+
export class ArtifactCache {
|
|
17
|
+
private readonly entries = new Map<string, CacheEntry>();
|
|
18
|
+
private readonly inflight = new Map<string, Promise<Artifact>>();
|
|
19
|
+
private readonly listeners = new Map<string, Set<() => void>>();
|
|
20
|
+
|
|
21
|
+
constructor(private readonly client: ArtifactClient) {}
|
|
22
|
+
|
|
23
|
+
entry(id: string): CacheEntry {
|
|
24
|
+
return this.entries.get(id) ?? EMPTY;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
latest(id: string): Artifact | undefined {
|
|
28
|
+
return this.entries.get(id)?.artifact;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
subscribe(id: string, listener: () => void): () => void {
|
|
32
|
+
const set = this.listeners.get(id) ?? new Set();
|
|
33
|
+
set.add(listener);
|
|
34
|
+
this.listeners.set(id, set);
|
|
35
|
+
return () => {
|
|
36
|
+
set.delete(listener);
|
|
37
|
+
if (set.size === 0) this.listeners.delete(id);
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
private notify(id: string): void {
|
|
42
|
+
for (const listener of [...(this.listeners.get(id) ?? [])]) listener();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Records an artifact the application loaded or saved. An older version never replaces a newer one; a newer
|
|
47
|
+
* `updatedAt` of the same version replaces it.
|
|
48
|
+
*/
|
|
49
|
+
put(artifact: Artifact): void {
|
|
50
|
+
const current = this.latest(artifact.id);
|
|
51
|
+
if (current) {
|
|
52
|
+
const older = artifact.version < current.version;
|
|
53
|
+
const sameVersionOlder =
|
|
54
|
+
artifact.version === current.version && artifact.meta.updatedAt <= current.meta.updatedAt;
|
|
55
|
+
if (older || sameVersionOlder) return;
|
|
56
|
+
}
|
|
57
|
+
this.entries.set(artifact.id, { artifact, loading: false });
|
|
58
|
+
this.notify(artifact.id);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Loads the artifact unless it is cached. `force` fetches it again. */
|
|
62
|
+
load(id: string, force = false): Promise<Artifact> {
|
|
63
|
+
const existing = this.entries.get(id);
|
|
64
|
+
if (existing?.artifact && !force) return Promise.resolve(existing.artifact);
|
|
65
|
+
const pending = this.inflight.get(id);
|
|
66
|
+
if (pending) return pending;
|
|
67
|
+
this.entries.set(id, { ...(existing ?? {}), loading: true });
|
|
68
|
+
this.notify(id);
|
|
69
|
+
const promise = this.client.get(id).then(
|
|
70
|
+
(artifact) => {
|
|
71
|
+
this.inflight.delete(id);
|
|
72
|
+
// A save may have landed while the request was in flight; never move the cache backwards.
|
|
73
|
+
const current = this.latest(id);
|
|
74
|
+
if (current && current.version > artifact.version) {
|
|
75
|
+
this.entries.set(id, { artifact: current, loading: false });
|
|
76
|
+
this.notify(id);
|
|
77
|
+
return current;
|
|
78
|
+
}
|
|
79
|
+
this.entries.set(id, { artifact, loading: false });
|
|
80
|
+
this.notify(id);
|
|
81
|
+
return artifact;
|
|
82
|
+
},
|
|
83
|
+
(error: unknown) => {
|
|
84
|
+
this.inflight.delete(id);
|
|
85
|
+
const previous = this.entries.get(id);
|
|
86
|
+
this.entries.set(id, {
|
|
87
|
+
...(previous?.artifact ? { artifact: previous.artifact } : {}),
|
|
88
|
+
error,
|
|
89
|
+
loading: false,
|
|
90
|
+
});
|
|
91
|
+
this.notify(id);
|
|
92
|
+
throw error;
|
|
93
|
+
},
|
|
94
|
+
);
|
|
95
|
+
this.inflight.set(id, promise);
|
|
96
|
+
return promise;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const caches = new WeakMap<ArtifactClient, ArtifactCache>();
|
|
101
|
+
|
|
102
|
+
export function cacheFor(client: ArtifactClient): ArtifactCache {
|
|
103
|
+
let cache = caches.get(client);
|
|
104
|
+
if (!cache) {
|
|
105
|
+
cache = new ArtifactCache(client);
|
|
106
|
+
caches.set(client, cache);
|
|
107
|
+
}
|
|
108
|
+
return cache;
|
|
109
|
+
}
|