@peerproblem/sw3-ui 0.0.0-stage → 0.3.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 +21 -0
- package/README.md +109 -2
- package/agent/components/accordion.md +95 -0
- package/agent/components/action-square.md +106 -0
- package/agent/components/agent-bridge.md +87 -0
- package/agent/components/agent-console.md +123 -0
- package/agent/components/alert-dialog.md +82 -0
- package/agent/components/app-shell.md +105 -0
- package/agent/components/area-chart.md +56 -0
- package/agent/components/async-options.md +47 -0
- package/agent/components/autocomplete.md +69 -0
- package/agent/components/avatar.md +88 -0
- package/agent/components/badge.md +51 -0
- package/agent/components/bar-chart.md +56 -0
- package/agent/components/bar-list.md +49 -0
- package/agent/components/breadcrumbs.md +43 -0
- package/agent/components/button.md +109 -0
- package/agent/components/calendar.md +114 -0
- package/agent/components/canvas.md +105 -0
- package/agent/components/card.md +78 -0
- package/agent/components/carousel.md +113 -0
- package/agent/components/chart-card.md +41 -0
- package/agent/components/chart-surface.md +56 -0
- package/agent/components/checkbox.md +88 -0
- package/agent/components/citation-chip.md +61 -0
- package/agent/components/collapsible.md +69 -0
- package/agent/components/color-picker.md +82 -0
- package/agent/components/combobox.md +104 -0
- package/agent/components/command.md +92 -0
- package/agent/components/dashboard-grid.md +73 -0
- package/agent/components/date-input.md +87 -0
- package/agent/components/date-picker.md +122 -0
- package/agent/components/dialog.md +97 -0
- package/agent/components/donut-chart.md +50 -0
- package/agent/components/drawer.md +101 -0
- package/agent/components/empty-state.md +52 -0
- package/agent/components/field.md +80 -0
- package/agent/components/file-input.md +84 -0
- package/agent/components/hover-card.md +64 -0
- package/agent/components/image-cropper.md +77 -0
- package/agent/components/input.md +49 -0
- package/agent/components/label.md +53 -0
- package/agent/components/line-chart.md +60 -0
- package/agent/components/listbox.md +84 -0
- package/agent/components/map-view.md +104 -0
- package/agent/components/menu.md +117 -0
- package/agent/components/menubar.md +67 -0
- package/agent/components/meter.md +59 -0
- package/agent/components/navigation-menu.md +98 -0
- package/agent/components/number-input.md +81 -0
- package/agent/components/otp-input.md +67 -0
- package/agent/components/pagination.md +80 -0
- package/agent/components/password-input.md +67 -0
- package/agent/components/pill-button.md +116 -0
- package/agent/components/popover.md +85 -0
- package/agent/components/poster-card.md +61 -0
- package/agent/components/preferences.md +92 -0
- package/agent/components/progress.md +63 -0
- package/agent/components/provider.md +47 -0
- package/agent/components/radio.md +91 -0
- package/agent/components/rating.md +66 -0
- package/agent/components/reorder.md +61 -0
- package/agent/components/resizable.md +87 -0
- package/agent/components/scatter-chart.md +49 -0
- package/agent/components/scroll-area.md +81 -0
- package/agent/components/segmented-control.md +56 -0
- package/agent/components/select.md +130 -0
- package/agent/components/separator.md +60 -0
- package/agent/components/shortcuts.md +50 -0
- package/agent/components/sidebar-nav.md +68 -0
- package/agent/components/skeleton.md +58 -0
- package/agent/components/slider.md +79 -0
- package/agent/components/sparkline.md +39 -0
- package/agent/components/squircle.md +58 -0
- package/agent/components/stat.md +58 -0
- package/agent/components/switch.md +48 -0
- package/agent/components/table.md +58 -0
- package/agent/components/tabs.md +108 -0
- package/agent/components/textarea.md +68 -0
- package/agent/components/time-input.md +84 -0
- package/agent/components/timeline.md +91 -0
- package/agent/components/toast.md +85 -0
- package/agent/components/toggle.md +76 -0
- package/agent/components/token-input.md +66 -0
- package/agent/components/toolbar.md +76 -0
- package/agent/components/tooltip.md +83 -0
- package/agent/components/tracker.md +47 -0
- package/agent/components/tree.md +87 -0
- package/agent/components/treemap.md +72 -0
- package/agent/components/trend-chart.md +80 -0
- package/agent/components/trigger-menu.md +67 -0
- package/agent/components/typography.md +51 -0
- package/agent/components/waterfall.md +78 -0
- package/agent/components/week-schedule.md +113 -0
- package/agent/llms/actions-and-layout.txt +1749 -0
- package/agent/llms/agents.txt +505 -0
- package/agent/llms/charts.txt +778 -0
- package/agent/llms/dashboards.txt +457 -0
- package/agent/llms/extend.txt +132 -0
- package/agent/llms/extras.txt +527 -0
- package/agent/llms/forms.txt +2152 -0
- package/agent/llms/foundations.txt +674 -0
- package/agent/llms/hooks.txt +178 -0
- package/agent/llms/maps.txt +229 -0
- package/agent/llms/overlays-and-navigation.txt +1167 -0
- package/agent/llms-full.txt +8717 -0
- package/agent/llms.txt +145 -0
- package/agent/registry.json +11289 -0
- package/agent/tokens.md +66 -0
- package/dist/agent/index.d.ts +235 -0
- package/dist/agent/index.js +21 -0
- package/dist/card-Ipm-Cj5f.d.ts +490 -0
- package/dist/charts/index.d.ts +289 -0
- package/dist/charts/index.js +815 -0
- package/dist/check/cli.d.ts +1 -0
- package/dist/check/cli.js +48 -0
- package/dist/check/rendered.d.ts +11 -0
- package/dist/check/rendered.js +77 -0
- package/dist/check/source.d.ts +13 -0
- package/dist/check/source.js +182 -0
- package/dist/chunk-3DXBM65D.js +65 -0
- package/dist/chunk-3H5X4ZP6.js +55 -0
- package/dist/chunk-6XC4BC5C.js +92 -0
- package/dist/chunk-7H6TEAWD.js +507 -0
- package/dist/chunk-I63ZTJOI.js +1089 -0
- package/dist/chunk-JCIRUM4W.js +33 -0
- package/dist/chunk-LTBEHZ3P.js +25 -0
- package/dist/chunk-QDPPLO4U.js +60 -0
- package/dist/chunk-U2XFBPU4.js +56 -0
- package/dist/chunk-UY2WH5AY.js +681 -0
- package/dist/extras.d.ts +203 -0
- package/dist/extras.js +904 -0
- package/dist/icons-BJiGEAnU.d.ts +68 -0
- package/dist/index.d.ts +3737 -0
- package/dist/index.js +14477 -0
- package/dist/map/index.d.ts +115 -0
- package/dist/map/index.js +394 -0
- package/dist/meta/index.d.ts +3314 -0
- package/dist/meta/index.js +5106 -0
- package/dist/rules-1RIZ_JZr.d.ts +38 -0
- package/dist/styles.css +4037 -0
- package/dist/themes/calm.css +42 -0
- package/dist/themes/frost.css +40 -0
- package/package.json +142 -4
package/dist/extras.js
ADDED
|
@@ -0,0 +1,904 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import {
|
|
3
|
+
NumberInput,
|
|
4
|
+
SegmentedControl,
|
|
5
|
+
Slider,
|
|
6
|
+
Toggle,
|
|
7
|
+
ToggleGroup
|
|
8
|
+
} from "./chunk-I63ZTJOI.js";
|
|
9
|
+
import {
|
|
10
|
+
Button
|
|
11
|
+
} from "./chunk-U2XFBPU4.js";
|
|
12
|
+
import {
|
|
13
|
+
Card,
|
|
14
|
+
Icon,
|
|
15
|
+
SquircleLayers,
|
|
16
|
+
cx,
|
|
17
|
+
mergeRefs,
|
|
18
|
+
press,
|
|
19
|
+
useControllableState,
|
|
20
|
+
useSquircle
|
|
21
|
+
} from "./chunk-UY2WH5AY.js";
|
|
22
|
+
import {
|
|
23
|
+
actionSquareRecipe,
|
|
24
|
+
pillButtonRecipe
|
|
25
|
+
} from "./chunk-QDPPLO4U.js";
|
|
26
|
+
import "./chunk-LTBEHZ3P.js";
|
|
27
|
+
import {
|
|
28
|
+
useAgentBinding
|
|
29
|
+
} from "./chunk-JCIRUM4W.js";
|
|
30
|
+
import "./chunk-6XC4BC5C.js";
|
|
31
|
+
|
|
32
|
+
// src/components/poster-card.tsx
|
|
33
|
+
import { forwardRef } from "react";
|
|
34
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
35
|
+
var PosterCard = forwardRef(function PosterCard2({ title, outline = "first", caption, action, radius = "lg", className, children, ...rest }, ref) {
|
|
36
|
+
const words = Array.isArray(title) ? title : title.split(" ");
|
|
37
|
+
const wordEl = (w, i) => {
|
|
38
|
+
const last = i === words.length - 1;
|
|
39
|
+
const mode = outline === "all" ? "outline" : outline === "none" ? "solid" : outline === "first" ? i === 0 && words.length > 1 ? "outline" : "solid" : outline === "last" ? last && words.length > 1 ? "outline" : "solid" : i === 0 && words.length > 1 ? "muted" : "solid";
|
|
40
|
+
return /* @__PURE__ */ jsx("span", { "aria-hidden": true, className: "sw-poster__word", "data-mode": mode, children: w }, i);
|
|
41
|
+
};
|
|
42
|
+
const titleEl = /* @__PURE__ */ jsx("div", { className: "sw-poster__title", children: words.map(wordEl) });
|
|
43
|
+
const captionEl = caption?.length ? /* @__PURE__ */ jsx("p", { className: "sw-poster__caption", children: caption.map((c, i) => /* @__PURE__ */ jsx("span", { children: c }, i)) }) : null;
|
|
44
|
+
const demo = /* @__PURE__ */ jsx("div", { className: "sw-poster__demo", children });
|
|
45
|
+
const label = words.join(" ");
|
|
46
|
+
return /* @__PURE__ */ jsx(
|
|
47
|
+
Card,
|
|
48
|
+
{
|
|
49
|
+
ref,
|
|
50
|
+
"data-sw": "poster-card",
|
|
51
|
+
"aria-label": label,
|
|
52
|
+
role: "group",
|
|
53
|
+
radius,
|
|
54
|
+
padding: "none",
|
|
55
|
+
className: cx("sw-poster", className),
|
|
56
|
+
...rest,
|
|
57
|
+
children: /* @__PURE__ */ jsxs("div", { className: "sw-poster__inner", children: [
|
|
58
|
+
/* @__PURE__ */ jsxs("div", { className: "sw-poster__head", children: [
|
|
59
|
+
titleEl,
|
|
60
|
+
captionEl,
|
|
61
|
+
action != null && /* @__PURE__ */ jsx("div", { className: "sw-poster__action", children: action })
|
|
62
|
+
] }),
|
|
63
|
+
demo
|
|
64
|
+
] })
|
|
65
|
+
}
|
|
66
|
+
);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// src/components/action-square.tsx
|
|
70
|
+
import { forwardRef as forwardRef2 } from "react";
|
|
71
|
+
import { motion } from "motion/react";
|
|
72
|
+
import { Fragment, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
73
|
+
var tileRadius = { md: 14, lg: 18 };
|
|
74
|
+
var ActionSquare = forwardRef2(function ActionSquare2({ label, icon = "corner", iconFirst, hideLabel, radius, smoothing, decorative, tone, size, className, type = "button", ...rest }, ref) {
|
|
75
|
+
const values = actionSquareRecipe.resolve({ tone, size });
|
|
76
|
+
const sq = useSquircle({ radius: radius ?? tileRadius[values.size], smoothing });
|
|
77
|
+
const attrs = actionSquareRecipe.attrs(values);
|
|
78
|
+
const content = /* @__PURE__ */ jsxs2(Fragment, { children: [
|
|
79
|
+
/* @__PURE__ */ jsx2("span", { className: cx("sw-action-square__label", hideLabel && "sw-sr-only"), children: label }),
|
|
80
|
+
/* @__PURE__ */ jsxs2("span", { ref: sq.ref, className: "sw-action-square__tile sw-sq", "aria-hidden": "true", children: [
|
|
81
|
+
/* @__PURE__ */ jsx2(SquircleLayers, { paths: sq.paths, radius: sq.radius, ringOffset: sq.ringOffset, borderWidth: 1 }),
|
|
82
|
+
/* @__PURE__ */ jsx2(Icon, { name: icon })
|
|
83
|
+
] })
|
|
84
|
+
] });
|
|
85
|
+
const classes = cx("sw-action-square", iconFirst && "sw-action-square--icon-first", className);
|
|
86
|
+
if (decorative) {
|
|
87
|
+
return /* @__PURE__ */ jsx2(motion.span, { className: classes, ...attrs, "data-decorative": "", ...rest, children: content });
|
|
88
|
+
}
|
|
89
|
+
return /* @__PURE__ */ jsx2(motion.button, { ref, type, className: classes, ...attrs, ...press, ...rest, children: content });
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// src/components/pill-button.tsx
|
|
93
|
+
import { forwardRef as forwardRef3 } from "react";
|
|
94
|
+
import { motion as motion2 } from "motion/react";
|
|
95
|
+
import { Fragment as Fragment2, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
96
|
+
function renderIcon(icon, className) {
|
|
97
|
+
if (icon == null) return null;
|
|
98
|
+
return typeof icon === "string" ? /* @__PURE__ */ jsx3(Icon, { name: icon, className }) : /* @__PURE__ */ jsx3("span", { className, children: icon });
|
|
99
|
+
}
|
|
100
|
+
var PillButton = forwardRef3(function PillButton2({ tone, size, icon, trailingIcon, href, download, className, children, type = "button", ...rest }, ref) {
|
|
101
|
+
const attrs = pillButtonRecipe.attrs({ tone, size });
|
|
102
|
+
const classes = cx("sw-pill-button", className);
|
|
103
|
+
const inner = /* @__PURE__ */ jsxs3(Fragment2, { children: [
|
|
104
|
+
renderIcon(icon, "sw-pill-button__icon"),
|
|
105
|
+
/* @__PURE__ */ jsx3("span", { className: "sw-pill-button__label", children }),
|
|
106
|
+
renderIcon(trailingIcon, "sw-pill-button__icon sw-pill-button__icon--trailing")
|
|
107
|
+
] });
|
|
108
|
+
if (href) {
|
|
109
|
+
return /* @__PURE__ */ jsx3(
|
|
110
|
+
motion2.a,
|
|
111
|
+
{
|
|
112
|
+
ref,
|
|
113
|
+
href,
|
|
114
|
+
download,
|
|
115
|
+
className: classes,
|
|
116
|
+
...attrs,
|
|
117
|
+
...press,
|
|
118
|
+
...rest,
|
|
119
|
+
children: inner
|
|
120
|
+
}
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
return /* @__PURE__ */ jsx3(motion2.button, { ref, type, className: classes, ...attrs, ...press, ...rest, children: inner });
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
// src/components/canvas.tsx
|
|
127
|
+
import {
|
|
128
|
+
useCallback,
|
|
129
|
+
useEffect,
|
|
130
|
+
useId,
|
|
131
|
+
useRef,
|
|
132
|
+
useState
|
|
133
|
+
} from "react";
|
|
134
|
+
import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
135
|
+
var MIN = 8;
|
|
136
|
+
var FILLS = [
|
|
137
|
+
{ value: "ink", label: "Ink" },
|
|
138
|
+
{ value: "gray", label: "Gray" },
|
|
139
|
+
{ value: "white", label: "White" },
|
|
140
|
+
{ value: "hatch", label: "Hatch" }
|
|
141
|
+
];
|
|
142
|
+
var clamp = (n, a, b) => Math.min(Math.max(n, a), Math.max(a, b));
|
|
143
|
+
var round = (n, s = 1) => Math.round(n / s) * s;
|
|
144
|
+
var NO_SHAPES = [];
|
|
145
|
+
function fit(s, W, H) {
|
|
146
|
+
const w = clamp(Math.round(s.w), MIN, W);
|
|
147
|
+
const h = clamp(Math.round(s.h), MIN, H);
|
|
148
|
+
return {
|
|
149
|
+
...s,
|
|
150
|
+
w,
|
|
151
|
+
h,
|
|
152
|
+
x: clamp(Math.round(s.x), 0, W - w),
|
|
153
|
+
y: clamp(Math.round(s.y), 0, H - h),
|
|
154
|
+
opacity: clamp(Math.round(s.opacity), 10, 100)
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
function LayerIcon({ type }) {
|
|
158
|
+
return /* @__PURE__ */ jsxs4("svg", { viewBox: "0 0 16 16", width: 16, height: 16, fill: "none", stroke: "currentColor", strokeWidth: 1.25, "aria-hidden": true, children: [
|
|
159
|
+
type === "rect" && /* @__PURE__ */ jsx4("rect", { x: 2.5, y: 2.5, width: 11, height: 11, rx: 1.5 }),
|
|
160
|
+
type === "ellipse" && /* @__PURE__ */ jsx4("circle", { cx: 8, cy: 8, r: 5.75 }),
|
|
161
|
+
type === "text" && /* @__PURE__ */ jsx4("path", { d: "M3 3.5h10M8 3.5v9.5M6 13h4M3 3.5V5M13 3.5V5", strokeLinecap: "round" })
|
|
162
|
+
] });
|
|
163
|
+
}
|
|
164
|
+
function Canvas({
|
|
165
|
+
shapes: shapesProp,
|
|
166
|
+
defaultShapes,
|
|
167
|
+
onShapesChange,
|
|
168
|
+
onShapesCommit,
|
|
169
|
+
selectedId: selectedProp,
|
|
170
|
+
defaultSelectedId = null,
|
|
171
|
+
onSelectedIdChange,
|
|
172
|
+
width: W = 560,
|
|
173
|
+
height: H = 320,
|
|
174
|
+
inspector = true,
|
|
175
|
+
framed = true,
|
|
176
|
+
snap = 1,
|
|
177
|
+
radius = "lg",
|
|
178
|
+
className,
|
|
179
|
+
style,
|
|
180
|
+
onKeyDown,
|
|
181
|
+
...rest
|
|
182
|
+
}) {
|
|
183
|
+
const uid = useId();
|
|
184
|
+
const rootRef = useRef(null);
|
|
185
|
+
const boardRef = useRef(null);
|
|
186
|
+
const sq = useSquircle({ radius, enabled: framed });
|
|
187
|
+
const [shapes, setShapes] = useControllableState({ value: shapesProp, defaultValue: defaultShapes ?? NO_SHAPES, onChange: onShapesChange });
|
|
188
|
+
const [selectedRaw, setSelected] = useControllableState({ value: selectedProp, defaultValue: defaultSelectedId, onChange: onSelectedIdChange });
|
|
189
|
+
const shapesRef = useRef(shapes);
|
|
190
|
+
shapesRef.current = shapes;
|
|
191
|
+
const selectedShape = shapes.find((s) => s.id === selectedRaw) ?? null;
|
|
192
|
+
const selectedId = selectedShape ? selectedShape.id : null;
|
|
193
|
+
const [drag, setDrag] = useState(null);
|
|
194
|
+
const cancelDrag = useRef(null);
|
|
195
|
+
const commit = useCallback(() => onShapesCommit?.(shapesRef.current), [onShapesCommit]);
|
|
196
|
+
const patch = (id, p) => setShapes((prev) => {
|
|
197
|
+
let changed = false;
|
|
198
|
+
const next = prev.map((s) => {
|
|
199
|
+
if (s.id !== id) return s;
|
|
200
|
+
const n = fit({ ...s, ...typeof p === "function" ? p(s) : p }, W, H);
|
|
201
|
+
if (Object.keys(n).some((k) => n[k] !== s[k])) {
|
|
202
|
+
changed = true;
|
|
203
|
+
return n;
|
|
204
|
+
}
|
|
205
|
+
return s;
|
|
206
|
+
});
|
|
207
|
+
if (!changed) return prev;
|
|
208
|
+
shapesRef.current = next;
|
|
209
|
+
return next;
|
|
210
|
+
});
|
|
211
|
+
const find = (key) => {
|
|
212
|
+
if (key == null) return null;
|
|
213
|
+
const k = String(key).trim().toLowerCase();
|
|
214
|
+
return shapesRef.current.find((s) => s.id === key) ?? shapesRef.current.find((s) => s.name.toLowerCase() === k || s.id.toLowerCase() === k) ?? null;
|
|
215
|
+
};
|
|
216
|
+
useEffect(() => {
|
|
217
|
+
if (!drag) return;
|
|
218
|
+
const onKey = (e) => {
|
|
219
|
+
if (e.key !== "Escape" || !cancelDrag.current) return;
|
|
220
|
+
e.preventDefault();
|
|
221
|
+
e.stopPropagation();
|
|
222
|
+
cancelDrag.current();
|
|
223
|
+
};
|
|
224
|
+
window.addEventListener("keydown", onKey, true);
|
|
225
|
+
return () => window.removeEventListener("keydown", onKey, true);
|
|
226
|
+
}, [drag]);
|
|
227
|
+
const startDrag = (e, kind, shape, apply) => {
|
|
228
|
+
const board = boardRef.current;
|
|
229
|
+
if (!board) return;
|
|
230
|
+
const el = e.currentTarget;
|
|
231
|
+
el.setPointerCapture(e.pointerId);
|
|
232
|
+
const scale = board.getBoundingClientRect().width / W || 1;
|
|
233
|
+
const sx = e.clientX;
|
|
234
|
+
const sy = e.clientY;
|
|
235
|
+
const before = shapesRef.current;
|
|
236
|
+
let started = kind !== "move";
|
|
237
|
+
if (started) setDrag(kind);
|
|
238
|
+
const move = (ev) => {
|
|
239
|
+
const dx = (ev.clientX - sx) / scale;
|
|
240
|
+
const dy = (ev.clientY - sy) / scale;
|
|
241
|
+
if (!started) {
|
|
242
|
+
if (Math.hypot(ev.clientX - sx, ev.clientY - sy) < 3) return;
|
|
243
|
+
started = true;
|
|
244
|
+
setDrag(kind);
|
|
245
|
+
}
|
|
246
|
+
patch(shape.id, apply(dx, dy, ev.shiftKey));
|
|
247
|
+
};
|
|
248
|
+
const end = (keep) => {
|
|
249
|
+
el.removeEventListener("pointermove", move);
|
|
250
|
+
el.removeEventListener("pointerup", up);
|
|
251
|
+
el.removeEventListener("pointercancel", cancel);
|
|
252
|
+
if (el.hasPointerCapture(e.pointerId)) el.releasePointerCapture(e.pointerId);
|
|
253
|
+
cancelDrag.current = null;
|
|
254
|
+
setDrag(null);
|
|
255
|
+
if (!keep) {
|
|
256
|
+
shapesRef.current = before;
|
|
257
|
+
setShapes(before);
|
|
258
|
+
}
|
|
259
|
+
if (started) commit();
|
|
260
|
+
};
|
|
261
|
+
const up = () => end(true);
|
|
262
|
+
const cancel = () => end(false);
|
|
263
|
+
cancelDrag.current = cancel;
|
|
264
|
+
el.addEventListener("pointermove", move);
|
|
265
|
+
el.addEventListener("pointerup", up);
|
|
266
|
+
el.addEventListener("pointercancel", cancel);
|
|
267
|
+
};
|
|
268
|
+
const onShapeDown = (e, s) => {
|
|
269
|
+
if (e.button !== 0) return;
|
|
270
|
+
e.preventDefault();
|
|
271
|
+
e.currentTarget.focus({ preventScroll: true });
|
|
272
|
+
setSelected(s.id);
|
|
273
|
+
startDrag(e, "move", s, (dx, dy) => ({ x: round(s.x + dx, snap), y: round(s.y + dy, snap) }));
|
|
274
|
+
};
|
|
275
|
+
const onHandleDown = (e, corner) => {
|
|
276
|
+
if (e.button !== 0 || !selectedShape) return;
|
|
277
|
+
e.preventDefault();
|
|
278
|
+
e.stopPropagation();
|
|
279
|
+
const s = selectedShape;
|
|
280
|
+
const east = corner === "ne" || corner === "se";
|
|
281
|
+
const south = corner === "se" || corner === "sw";
|
|
282
|
+
const ax = east ? s.x : s.x + s.w;
|
|
283
|
+
const ay = south ? s.y : s.y + s.h;
|
|
284
|
+
const maxW = east ? W - ax : ax;
|
|
285
|
+
const maxH = south ? H - ay : ay;
|
|
286
|
+
startDrag(e, corner, s, (dx, dy, shift) => {
|
|
287
|
+
let w = round(s.w + (east ? dx : -dx), snap);
|
|
288
|
+
let h = round(s.h + (south ? dy : -dy), snap);
|
|
289
|
+
if (shift) {
|
|
290
|
+
let k = Math.max(w / s.w, h / s.h);
|
|
291
|
+
k = clamp(k, Math.max(MIN / s.w, MIN / s.h), Math.min(maxW / s.w, maxH / s.h));
|
|
292
|
+
w = Math.round(s.w * k);
|
|
293
|
+
h = Math.round(s.h * k);
|
|
294
|
+
} else {
|
|
295
|
+
w = clamp(w, MIN, maxW);
|
|
296
|
+
h = clamp(h, MIN, maxH);
|
|
297
|
+
}
|
|
298
|
+
return { w, h, x: east ? ax : ax - w, y: south ? ay : ay - h };
|
|
299
|
+
});
|
|
300
|
+
};
|
|
301
|
+
const onShapeKey = (e, s) => {
|
|
302
|
+
const step = e.shiftKey ? 10 : 1;
|
|
303
|
+
const d = { ArrowLeft: [-step, 0], ArrowRight: [step, 0], ArrowUp: [0, -step], ArrowDown: [0, step] };
|
|
304
|
+
if (d[e.key]) {
|
|
305
|
+
e.preventDefault();
|
|
306
|
+
setSelected(s.id);
|
|
307
|
+
patch(s.id, (cur) => ({ x: cur.x + d[e.key][0], y: cur.y + d[e.key][1] }));
|
|
308
|
+
commit();
|
|
309
|
+
} else if (e.key === "Delete" || e.key === "Backspace") {
|
|
310
|
+
e.preventDefault();
|
|
311
|
+
} else if (e.key === "Enter" || e.key === " ") {
|
|
312
|
+
e.preventDefault();
|
|
313
|
+
setSelected(s.id);
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
useAgentBinding(rootRef, {
|
|
317
|
+
kind: "canvas",
|
|
318
|
+
state: () => ({
|
|
319
|
+
shapes: shapesRef.current.map((s) => ({ ...s })),
|
|
320
|
+
selected: selectedShape ? selectedShape.name : null,
|
|
321
|
+
selectedId,
|
|
322
|
+
width: W,
|
|
323
|
+
height: H
|
|
324
|
+
}),
|
|
325
|
+
items: () => shapesRef.current.map((s) => ({ value: s.id, label: s.name })),
|
|
326
|
+
actions: {
|
|
327
|
+
select: (nameOrId) => setSelected(nameOrId == null ? null : find(nameOrId)?.id ?? selectedId),
|
|
328
|
+
update: (nameOrId, p) => {
|
|
329
|
+
const s = find(nameOrId);
|
|
330
|
+
if (!s || !p || typeof p !== "object") return;
|
|
331
|
+
const clean = {};
|
|
332
|
+
for (const k of ["x", "y", "w", "h", "opacity"]) if (p[k] != null && Number.isFinite(Number(p[k]))) clean[k] = Number(p[k]);
|
|
333
|
+
if (p.fill && FILLS.some((f) => f.value === p.fill)) clean.fill = p.fill;
|
|
334
|
+
if (typeof p.text === "string" && s.type === "text") clean.text = p.text;
|
|
335
|
+
if (typeof p.name === "string" && p.name.trim()) clean.name = p.name.trim();
|
|
336
|
+
patch(s.id, clean);
|
|
337
|
+
commit();
|
|
338
|
+
},
|
|
339
|
+
move: (nameOrId, dx, dy) => {
|
|
340
|
+
const s = find(nameOrId);
|
|
341
|
+
if (!s) return;
|
|
342
|
+
patch(s.id, (cur) => ({ x: cur.x + (Number(dx) || 0), y: cur.y + (Number(dy) || 0) }));
|
|
343
|
+
commit();
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
const pct = (n, of) => `${n / of * 100}%`;
|
|
348
|
+
const box = (s) => ({ left: pct(s.x, W), top: pct(s.y, H), width: pct(s.w, W), height: pct(s.h, H) });
|
|
349
|
+
const off = !selectedShape;
|
|
350
|
+
const sel = selectedShape;
|
|
351
|
+
return /* @__PURE__ */ jsxs4(
|
|
352
|
+
"div",
|
|
353
|
+
{
|
|
354
|
+
ref: mergeRefs(rootRef, sq.ref),
|
|
355
|
+
role: "group",
|
|
356
|
+
"data-sw": "canvas",
|
|
357
|
+
"data-framed": framed ? "" : void 0,
|
|
358
|
+
"data-dragging": drag ? "" : void 0,
|
|
359
|
+
"data-selected": selectedId ?? void 0,
|
|
360
|
+
className: cx("sw-canvas", framed && "sw-sq", className),
|
|
361
|
+
style,
|
|
362
|
+
onKeyDown: (e) => {
|
|
363
|
+
onKeyDown?.(e);
|
|
364
|
+
if (e.defaultPrevented || e.key !== "Escape" || !selectedId) return;
|
|
365
|
+
if (!boardRef.current?.contains(e.target) && e.target !== e.currentTarget) return;
|
|
366
|
+
e.preventDefault();
|
|
367
|
+
setSelected(null);
|
|
368
|
+
},
|
|
369
|
+
...rest,
|
|
370
|
+
children: [
|
|
371
|
+
framed && /* @__PURE__ */ jsx4(SquircleLayers, { paths: sq.paths, radius: sq.radius, borderWidth: 1 }),
|
|
372
|
+
/* @__PURE__ */ jsxs4(
|
|
373
|
+
"div",
|
|
374
|
+
{
|
|
375
|
+
ref: boardRef,
|
|
376
|
+
role: "group",
|
|
377
|
+
"aria-label": "Artboard",
|
|
378
|
+
className: "sw-canvas__board",
|
|
379
|
+
style: { aspectRatio: `${W} / ${H}`, "--sw-canvas-w": W },
|
|
380
|
+
onPointerDown: (e) => {
|
|
381
|
+
if (e.button === 0 && e.target === e.currentTarget) setSelected(null);
|
|
382
|
+
},
|
|
383
|
+
children: [
|
|
384
|
+
shapes.map((s) => {
|
|
385
|
+
const on = s.id === selectedId;
|
|
386
|
+
return /* @__PURE__ */ jsx4(
|
|
387
|
+
"div",
|
|
388
|
+
{
|
|
389
|
+
role: "button",
|
|
390
|
+
tabIndex: 0,
|
|
391
|
+
"aria-roledescription": "shape",
|
|
392
|
+
"aria-label": `${s.name}. Arrow keys move it.`,
|
|
393
|
+
"aria-pressed": on,
|
|
394
|
+
"data-shape": s.type,
|
|
395
|
+
"data-fill": s.fill,
|
|
396
|
+
"data-selected": on ? "" : void 0,
|
|
397
|
+
"data-id": s.id,
|
|
398
|
+
className: "sw-canvas__shape",
|
|
399
|
+
style: { ...box(s), "--sw-canvas-h": s.h },
|
|
400
|
+
onPointerDown: (e) => onShapeDown(e, s),
|
|
401
|
+
onFocus: () => {
|
|
402
|
+
if (!drag) setSelected(s.id);
|
|
403
|
+
},
|
|
404
|
+
onKeyDown: (e) => onShapeKey(e, s),
|
|
405
|
+
children: /* @__PURE__ */ jsx4("span", { className: "sw-canvas__paint", style: { opacity: s.opacity / 100 }, "aria-hidden": true, children: s.type === "text" ? s.text ?? s.name : null })
|
|
406
|
+
},
|
|
407
|
+
s.id
|
|
408
|
+
);
|
|
409
|
+
}),
|
|
410
|
+
sel && /* @__PURE__ */ jsx4("div", { className: "sw-canvas__selection", style: box(sel), "aria-hidden": true, children: ["nw", "ne", "se", "sw"].map((c) => /* @__PURE__ */ jsx4("span", { className: "sw-canvas__handle", "data-corner": c, "data-active": drag === c ? "" : void 0, onPointerDown: (e) => onHandleDown(e, c) }, c)) })
|
|
411
|
+
]
|
|
412
|
+
}
|
|
413
|
+
),
|
|
414
|
+
inspector && /* @__PURE__ */ jsxs4("div", { className: "sw-canvas__inspector", children: [
|
|
415
|
+
/* @__PURE__ */ jsxs4("section", { className: "sw-canvas__section", "aria-labelledby": `${uid}-layers`, children: [
|
|
416
|
+
/* @__PURE__ */ jsx4("div", { id: `${uid}-layers`, className: "sw-canvas__label", children: "Layers" }),
|
|
417
|
+
/* @__PURE__ */ jsx4(
|
|
418
|
+
ToggleGroup,
|
|
419
|
+
{
|
|
420
|
+
className: "sw-canvas__layers",
|
|
421
|
+
orientation: "vertical",
|
|
422
|
+
variant: "outline",
|
|
423
|
+
radius: "md",
|
|
424
|
+
deselectable: false,
|
|
425
|
+
"aria-labelledby": `${uid}-layers`,
|
|
426
|
+
value: selectedId ? [selectedId] : [],
|
|
427
|
+
onValueChange: (v) => v[0] && setSelected(v[0]),
|
|
428
|
+
children: shapes.map((s) => /* @__PURE__ */ jsx4(Toggle, { value: s.id, icon: /* @__PURE__ */ jsx4(LayerIcon, { type: s.type }), children: s.name }, s.id))
|
|
429
|
+
}
|
|
430
|
+
)
|
|
431
|
+
] }),
|
|
432
|
+
/* @__PURE__ */ jsx4("div", { className: "sw-canvas__fields", role: "group", "aria-label": sel ? `${sel.name} position and size` : "Position and size", children: [
|
|
433
|
+
["x", "X", "X position", 0, sel ? W - sel.w : W],
|
|
434
|
+
["y", "Y", "Y position", 0, sel ? H - sel.h : H],
|
|
435
|
+
["w", "W", "Width", MIN, sel ? W - sel.x : W],
|
|
436
|
+
["h", "H", "Height", MIN, sel ? H - sel.y : H]
|
|
437
|
+
].map(([k, letter, label, lo, hi]) => /* @__PURE__ */ jsxs4("div", { className: "sw-canvas__num", children: [
|
|
438
|
+
/* @__PURE__ */ jsx4("span", { className: "sw-canvas__num-key", "aria-hidden": true, children: letter }),
|
|
439
|
+
/* @__PURE__ */ jsx4(
|
|
440
|
+
NumberInput,
|
|
441
|
+
{
|
|
442
|
+
size: "sm",
|
|
443
|
+
radius: "xs",
|
|
444
|
+
stepper: false,
|
|
445
|
+
"aria-label": label,
|
|
446
|
+
placeholder: "\u2014",
|
|
447
|
+
disabled: off,
|
|
448
|
+
min: lo,
|
|
449
|
+
max: hi,
|
|
450
|
+
value: sel ? sel[k] : null,
|
|
451
|
+
onValueChange: (v) => {
|
|
452
|
+
if (sel && v != null && Number.isFinite(v)) patch(sel.id, { [k]: v });
|
|
453
|
+
},
|
|
454
|
+
onValueCommit: commit
|
|
455
|
+
}
|
|
456
|
+
)
|
|
457
|
+
] }, k)) }),
|
|
458
|
+
/* @__PURE__ */ jsxs4("section", { className: "sw-canvas__section", "aria-labelledby": `${uid}-fill`, children: [
|
|
459
|
+
/* @__PURE__ */ jsx4("div", { id: `${uid}-fill`, className: "sw-canvas__label", children: "Fill" }),
|
|
460
|
+
/* @__PURE__ */ jsx4(
|
|
461
|
+
ToggleGroup,
|
|
462
|
+
{
|
|
463
|
+
className: "sw-canvas__fills",
|
|
464
|
+
deselectable: false,
|
|
465
|
+
disabled: off,
|
|
466
|
+
"aria-labelledby": `${uid}-fill`,
|
|
467
|
+
value: sel ? [sel.fill] : [],
|
|
468
|
+
onValueChange: (v) => {
|
|
469
|
+
if (!sel || !v[0]) return;
|
|
470
|
+
patch(sel.id, { fill: v[0] });
|
|
471
|
+
commit();
|
|
472
|
+
},
|
|
473
|
+
children: FILLS.map((f) => /* @__PURE__ */ jsx4(Toggle, { value: f.value, "aria-label": f.label, title: f.label, icon: /* @__PURE__ */ jsx4("span", { className: "sw-canvas__swatch", "data-fill": f.value }) }, f.value))
|
|
474
|
+
}
|
|
475
|
+
)
|
|
476
|
+
] }),
|
|
477
|
+
/* @__PURE__ */ jsxs4("section", { className: "sw-canvas__section", "aria-labelledby": `${uid}-opacity`, children: [
|
|
478
|
+
/* @__PURE__ */ jsxs4("div", { className: "sw-canvas__row", children: [
|
|
479
|
+
/* @__PURE__ */ jsx4("div", { id: `${uid}-opacity`, className: "sw-canvas__label", children: "Opacity" }),
|
|
480
|
+
/* @__PURE__ */ jsx4("output", { className: "sw-canvas__readout", "aria-live": "off", children: sel ? `${sel.opacity}%` : "\u2014" })
|
|
481
|
+
] }),
|
|
482
|
+
/* @__PURE__ */ jsx4(
|
|
483
|
+
Slider,
|
|
484
|
+
{
|
|
485
|
+
className: "sw-canvas__opacity",
|
|
486
|
+
size: "sm",
|
|
487
|
+
min: 10,
|
|
488
|
+
max: 100,
|
|
489
|
+
step: 1,
|
|
490
|
+
disabled: off,
|
|
491
|
+
"aria-labelledby": `${uid}-opacity`,
|
|
492
|
+
value: sel ? sel.opacity : 100,
|
|
493
|
+
onValueChange: (v) => {
|
|
494
|
+
if (sel) patch(sel.id, { opacity: v });
|
|
495
|
+
},
|
|
496
|
+
onValueCommit: commit
|
|
497
|
+
}
|
|
498
|
+
)
|
|
499
|
+
] })
|
|
500
|
+
] })
|
|
501
|
+
]
|
|
502
|
+
}
|
|
503
|
+
);
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
// src/components/week-schedule.tsx
|
|
507
|
+
import {
|
|
508
|
+
useEffect as useEffect2,
|
|
509
|
+
useRef as useRef2,
|
|
510
|
+
useState as useState2
|
|
511
|
+
} from "react";
|
|
512
|
+
import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
513
|
+
var DEFAULT_DAYS = ["Mon", "Tue", "Wed", "Thu", "Fri"];
|
|
514
|
+
var KINDS = ["meeting", "focus", "away"];
|
|
515
|
+
var clamp2 = (n, a, b) => Math.min(b, Math.max(a, n));
|
|
516
|
+
var pad = (n) => String(n).padStart(2, "0");
|
|
517
|
+
var toHHMM = (min) => `${pad(Math.floor(min / 60))}:${pad(min % 60)}`;
|
|
518
|
+
function formatClock(min, format = "24h") {
|
|
519
|
+
const h = Math.floor(min / 60);
|
|
520
|
+
const m = min % 60;
|
|
521
|
+
if (format === "24h") return `${h}:${pad(m)}`;
|
|
522
|
+
return `${short12(min)} ${meridiem(min)}`;
|
|
523
|
+
}
|
|
524
|
+
var meridiem = (min) => Math.floor(min / 60) % 24 < 12 ? "AM" : "PM";
|
|
525
|
+
var short12 = (min) => {
|
|
526
|
+
const h = Math.floor(min / 60) % 12 || 12;
|
|
527
|
+
const m = min % 60;
|
|
528
|
+
return m ? `${h}:${pad(m)}` : `${h}`;
|
|
529
|
+
};
|
|
530
|
+
function formatRange(start, end, format = "24h") {
|
|
531
|
+
if (format === "24h") return `${formatClock(start)}\u2013${formatClock(end)}`;
|
|
532
|
+
const a = meridiem(start);
|
|
533
|
+
const b = meridiem(end);
|
|
534
|
+
return a === b ? `${short12(start)}\u2013${short12(end)} ${b}` : `${short12(start)} ${a}\u2013${short12(end)} ${b}`;
|
|
535
|
+
}
|
|
536
|
+
function parseTime(v) {
|
|
537
|
+
if (typeof v === "number" && isFinite(v)) return Math.round(v);
|
|
538
|
+
if (typeof v !== "string") return null;
|
|
539
|
+
const m = /^\s*(\d{1,2})(?:[:.](\d{2}))?\s*([ap])?\.?m?\.?\s*$/i.exec(v);
|
|
540
|
+
if (!m) return null;
|
|
541
|
+
let h = Number(m[1]);
|
|
542
|
+
const min = Number(m[2] ?? 0);
|
|
543
|
+
const ap = m[3]?.toLowerCase();
|
|
544
|
+
if (ap === "p" && h < 12) h += 12;
|
|
545
|
+
if (ap === "a" && h === 12) h = 0;
|
|
546
|
+
if (h > 24 || min > 59) return null;
|
|
547
|
+
return h * 60 + min;
|
|
548
|
+
}
|
|
549
|
+
var hoursOf = (events) => events.reduce((s, e) => s + ((e.kind ?? "meeting") === "away" ? 0 : Math.max(0, e.end - e.start)), 0) / 60;
|
|
550
|
+
var fmtHours = (h) => String(Number(h.toFixed(2)));
|
|
551
|
+
var same = (a, b) => a.day === b.day && a.start === b.start && a.end === b.end;
|
|
552
|
+
function WeekSchedule({
|
|
553
|
+
events: eventsProp,
|
|
554
|
+
defaultEvents,
|
|
555
|
+
onEventsChange,
|
|
556
|
+
onEventCommit,
|
|
557
|
+
onEventActivate,
|
|
558
|
+
days = DEFAULT_DAYS,
|
|
559
|
+
startHour = 9,
|
|
560
|
+
endHour = 17,
|
|
561
|
+
step = 15,
|
|
562
|
+
hourHeight = 60,
|
|
563
|
+
hourFormat: formatProp,
|
|
564
|
+
defaultHourFormat = "24h",
|
|
565
|
+
onHourFormatChange,
|
|
566
|
+
summary = true,
|
|
567
|
+
summaryLabel = "Hours booked",
|
|
568
|
+
clockToggle = true,
|
|
569
|
+
legend = true,
|
|
570
|
+
readOnly = false,
|
|
571
|
+
radius = "lg",
|
|
572
|
+
className,
|
|
573
|
+
style,
|
|
574
|
+
...rest
|
|
575
|
+
}) {
|
|
576
|
+
const rootRef = useRef2(null);
|
|
577
|
+
const bodyRef = useRef2(null);
|
|
578
|
+
const viewportRef = useRef2(null);
|
|
579
|
+
const sq = useSquircle({ radius });
|
|
580
|
+
const [events, setEvents] = useControllableState({ value: eventsProp, defaultValue: defaultEvents ?? [], onChange: onEventsChange });
|
|
581
|
+
const [format, setFormat] = useControllableState({ value: formatProp, defaultValue: defaultHourFormat, onChange: onHourFormatChange });
|
|
582
|
+
const [drag, setDrag] = useState2(null);
|
|
583
|
+
const [selected, setSelected] = useState2(null);
|
|
584
|
+
const [pointerFocused, setPointerFocused] = useState2(null);
|
|
585
|
+
const [message, setMessage] = useState2("");
|
|
586
|
+
const [dayCapacity, setDayCapacity] = useState2(days.length);
|
|
587
|
+
const [anchorDay, setAnchorDay] = useState2(0);
|
|
588
|
+
const eventsRef = useRef2(events);
|
|
589
|
+
eventsRef.current = events;
|
|
590
|
+
const cancelRef = useRef2(null);
|
|
591
|
+
const n = Math.max(1, days.length);
|
|
592
|
+
const visibleCount = Math.max(1, Math.min(n, dayCapacity));
|
|
593
|
+
const firstDay = Math.floor(clamp2(anchorDay, 0, n - 1) / visibleCount) * visibleCount;
|
|
594
|
+
const lastDay = Math.min(n, firstDay + visibleCount);
|
|
595
|
+
const visibleDays = days.slice(firstDay, lastDay);
|
|
596
|
+
const lo = clamp2(Math.min(startHour, endHour - 1), 0, 23) * 60;
|
|
597
|
+
const hi = clamp2(Math.max(endHour, startHour + 1), 1, 24) * 60;
|
|
598
|
+
const snapStep = Math.max(1, step);
|
|
599
|
+
const hours = (hi - lo) / 60;
|
|
600
|
+
useEffect2(() => () => cancelRef.current?.(), []);
|
|
601
|
+
useEffect2(() => {
|
|
602
|
+
const viewport = viewportRef.current;
|
|
603
|
+
if (!viewport || typeof ResizeObserver === "undefined") return;
|
|
604
|
+
const observer = new ResizeObserver(([entry]) => {
|
|
605
|
+
const styles = getComputedStyle(viewport);
|
|
606
|
+
const gutter = parseFloat(styles.getPropertyValue("--sw-week-gutter"));
|
|
607
|
+
const dayWidth = parseFloat(styles.getPropertyValue("--sw-week-min-day"));
|
|
608
|
+
setDayCapacity(Math.max(1, Math.floor((entry.contentRect.width - gutter) / dayWidth)));
|
|
609
|
+
});
|
|
610
|
+
observer.observe(viewport);
|
|
611
|
+
return () => observer.disconnect();
|
|
612
|
+
}, []);
|
|
613
|
+
const place = (ev, day, start) => {
|
|
614
|
+
const dur = ev.end - ev.start;
|
|
615
|
+
const s = clamp2(Math.round(start / snapStep) * snapStep, lo, Math.max(lo, hi - dur));
|
|
616
|
+
return { ...ev, day: clamp2(Math.round(day), 0, n - 1), start: s, end: s + dur };
|
|
617
|
+
};
|
|
618
|
+
const withEnd = (ev, end) => {
|
|
619
|
+
const e = clamp2(Math.round(end / snapStep) * snapStep, ev.start + snapStep, Math.max(ev.start + snapStep, hi));
|
|
620
|
+
return { ...ev, end: e };
|
|
621
|
+
};
|
|
622
|
+
const replace = (next) => {
|
|
623
|
+
const list = eventsRef.current.map((e) => e.id === next.id ? next : e);
|
|
624
|
+
eventsRef.current = list;
|
|
625
|
+
setEvents(list);
|
|
626
|
+
return list;
|
|
627
|
+
};
|
|
628
|
+
const describe = (ev) => `${ev.title}, ${days[ev.day] ?? ""} ${formatRange(ev.start, ev.end, format)}.`;
|
|
629
|
+
const commit = (ev) => {
|
|
630
|
+
setMessage(describe(ev));
|
|
631
|
+
onEventCommit?.(ev, eventsRef.current);
|
|
632
|
+
};
|
|
633
|
+
const onPointerDown = (ev, e) => {
|
|
634
|
+
const el = e.currentTarget;
|
|
635
|
+
if (e.button !== 0) return;
|
|
636
|
+
setPointerFocused(ev.id);
|
|
637
|
+
el.focus({ preventScroll: true });
|
|
638
|
+
if (readOnly) return;
|
|
639
|
+
const body = bodyRef.current;
|
|
640
|
+
if (!body) return;
|
|
641
|
+
e.preventDefault();
|
|
642
|
+
const mode = e.target.closest(".sw-week-schedule__handle") ? "resize" : "move";
|
|
643
|
+
el.setPointerCapture(e.pointerId);
|
|
644
|
+
const sx = e.clientX;
|
|
645
|
+
const sy = e.clientY;
|
|
646
|
+
const colOf = (x) => {
|
|
647
|
+
const r = body.getBoundingClientRect();
|
|
648
|
+
const column = Math.floor((x - r.left) / r.width * visibleDays.length);
|
|
649
|
+
return clamp2(column, firstDay > 0 ? -1 : 0, lastDay < n ? visibleDays.length : visibleDays.length - 1);
|
|
650
|
+
};
|
|
651
|
+
const startCol = colOf(sx);
|
|
652
|
+
const snapshot = eventsRef.current;
|
|
653
|
+
const orig = snapshot.find((x) => x.id === ev.id) ?? ev;
|
|
654
|
+
let moved = false;
|
|
655
|
+
let last = orig;
|
|
656
|
+
const move = (pe) => {
|
|
657
|
+
if (!moved && Math.hypot(pe.clientX - sx, pe.clientY - sy) < 4) return;
|
|
658
|
+
if (!moved) {
|
|
659
|
+
moved = true;
|
|
660
|
+
setDrag({ id: ev.id, mode });
|
|
661
|
+
}
|
|
662
|
+
const dm = (pe.clientY - sy) / hourHeight * 60;
|
|
663
|
+
const next = mode === "move" ? place(orig, orig.day + colOf(pe.clientX) - startCol, orig.start + dm) : withEnd(orig, orig.end + dm);
|
|
664
|
+
if (!same(next, last)) {
|
|
665
|
+
last = next;
|
|
666
|
+
replace(next);
|
|
667
|
+
}
|
|
668
|
+
};
|
|
669
|
+
const finish = (cancel) => {
|
|
670
|
+
el.removeEventListener("pointermove", move);
|
|
671
|
+
el.removeEventListener("pointerup", up);
|
|
672
|
+
el.removeEventListener("pointercancel", abort);
|
|
673
|
+
document.removeEventListener("keydown", onKey, true);
|
|
674
|
+
if (el.hasPointerCapture(e.pointerId)) el.releasePointerCapture(e.pointerId);
|
|
675
|
+
cancelRef.current = null;
|
|
676
|
+
setDrag(null);
|
|
677
|
+
if (cancel) {
|
|
678
|
+
if (moved) {
|
|
679
|
+
eventsRef.current = snapshot;
|
|
680
|
+
setEvents(snapshot);
|
|
681
|
+
setMessage(`${orig.title}: move cancelled.`);
|
|
682
|
+
}
|
|
683
|
+
return;
|
|
684
|
+
}
|
|
685
|
+
if (!moved) {
|
|
686
|
+
onEventActivate?.(orig);
|
|
687
|
+
return;
|
|
688
|
+
}
|
|
689
|
+
if (!same(last, orig)) {
|
|
690
|
+
setAnchorDay(last.day);
|
|
691
|
+
commit(last);
|
|
692
|
+
}
|
|
693
|
+
};
|
|
694
|
+
const up = () => finish(false);
|
|
695
|
+
const abort = () => finish(true);
|
|
696
|
+
const onKey = (ke) => {
|
|
697
|
+
if (ke.key !== "Escape") return;
|
|
698
|
+
ke.preventDefault();
|
|
699
|
+
ke.stopPropagation();
|
|
700
|
+
finish(true);
|
|
701
|
+
};
|
|
702
|
+
cancelRef.current = abort;
|
|
703
|
+
el.addEventListener("pointermove", move);
|
|
704
|
+
el.addEventListener("pointerup", up);
|
|
705
|
+
el.addEventListener("pointercancel", abort);
|
|
706
|
+
document.addEventListener("keydown", onKey, true);
|
|
707
|
+
};
|
|
708
|
+
const onKeyDown = (rendered, e) => {
|
|
709
|
+
setPointerFocused(null);
|
|
710
|
+
const ev = eventsRef.current.find((x) => x.id === rendered.id) ?? rendered;
|
|
711
|
+
if (e.key === "Escape" && cancelRef.current) {
|
|
712
|
+
e.preventDefault();
|
|
713
|
+
cancelRef.current();
|
|
714
|
+
return;
|
|
715
|
+
}
|
|
716
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
717
|
+
e.preventDefault();
|
|
718
|
+
onEventActivate?.(ev);
|
|
719
|
+
return;
|
|
720
|
+
}
|
|
721
|
+
if (readOnly || cancelRef.current) return;
|
|
722
|
+
let next = null;
|
|
723
|
+
if (e.key === "ArrowUp") next = e.shiftKey ? withEnd(ev, ev.end - snapStep) : place(ev, ev.day, ev.start - snapStep);
|
|
724
|
+
else if (e.key === "ArrowDown") next = e.shiftKey ? withEnd(ev, ev.end + snapStep) : place(ev, ev.day, ev.start + snapStep);
|
|
725
|
+
else if (e.key === "ArrowLeft") next = place(ev, ev.day - 1, ev.start);
|
|
726
|
+
else if (e.key === "ArrowRight") next = place(ev, ev.day + 1, ev.start);
|
|
727
|
+
if (!next) return;
|
|
728
|
+
e.preventDefault();
|
|
729
|
+
if (same(next, ev)) return;
|
|
730
|
+
setAnchorDay(next.day);
|
|
731
|
+
replace(next);
|
|
732
|
+
commit(next);
|
|
733
|
+
};
|
|
734
|
+
const find = (key) => {
|
|
735
|
+
const list = eventsRef.current;
|
|
736
|
+
const q = String(key ?? "").trim().toLowerCase();
|
|
737
|
+
const hit = list.find((x) => x.id === key) ?? list.find((x) => x.title.toLowerCase() === q) ?? list.find((x) => x.title.toLowerCase().includes(q));
|
|
738
|
+
if (!q || !hit) throw new Error(`No event "${String(key)}". Events: ${list.map((x) => x.title).join(", ")}`);
|
|
739
|
+
return hit;
|
|
740
|
+
};
|
|
741
|
+
const dayIndex = (v) => {
|
|
742
|
+
if (typeof v === "number") return v;
|
|
743
|
+
const s = String(v ?? "").trim().toLowerCase();
|
|
744
|
+
if (/^\d+$/.test(s)) return Number(s);
|
|
745
|
+
const i = days.findIndex((d) => {
|
|
746
|
+
const dl = d.toLowerCase();
|
|
747
|
+
return dl === s || s.length >= 2 && (dl.startsWith(s.slice(0, 3)) || s.startsWith(dl));
|
|
748
|
+
});
|
|
749
|
+
if (i < 0) throw new Error(`No day "${String(v)}". Days: ${days.join(", ")}`);
|
|
750
|
+
return i;
|
|
751
|
+
};
|
|
752
|
+
const timeOf = (v) => {
|
|
753
|
+
const t = parseTime(v);
|
|
754
|
+
if (t == null) throw new Error(`Bad time "${String(v)}" \u2014 use "HH:MM"`);
|
|
755
|
+
return t;
|
|
756
|
+
};
|
|
757
|
+
useAgentBinding(rootRef, {
|
|
758
|
+
kind: "week-schedule",
|
|
759
|
+
state: () => ({
|
|
760
|
+
events: events.map((e) => ({ id: e.id, title: e.title, day: days[e.day] ?? e.day, dayIndex: e.day, start: toHHMM(e.start), end: toHHMM(e.end), kind: e.kind ?? "meeting" })),
|
|
761
|
+
hourFormat: format,
|
|
762
|
+
hoursBooked: Number(hoursOf(events).toFixed(2)),
|
|
763
|
+
days,
|
|
764
|
+
hours: `${toHHMM(lo)}\u2013${toHHMM(hi)}`,
|
|
765
|
+
step,
|
|
766
|
+
readOnly
|
|
767
|
+
}),
|
|
768
|
+
items: () => events.map((e) => ({ value: e.id, label: e.title })),
|
|
769
|
+
actions: {
|
|
770
|
+
moveEvent: (titleOrId, day, start) => {
|
|
771
|
+
const ev = find(titleOrId);
|
|
772
|
+
const next = place(ev, dayIndex(day), start == null ? ev.start : timeOf(start));
|
|
773
|
+
replace(next);
|
|
774
|
+
commit(next);
|
|
775
|
+
return describe(next);
|
|
776
|
+
},
|
|
777
|
+
resizeEvent: (titleOrId, end) => {
|
|
778
|
+
const ev = find(titleOrId);
|
|
779
|
+
const next = withEnd(ev, timeOf(end));
|
|
780
|
+
replace(next);
|
|
781
|
+
commit(next);
|
|
782
|
+
return describe(next);
|
|
783
|
+
},
|
|
784
|
+
setHourFormat: (f) => {
|
|
785
|
+
if (f !== "24h" && f !== "12h") throw new Error('Use "24h" or "12h"');
|
|
786
|
+
setFormat(f);
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
});
|
|
790
|
+
const total = hoursOf(events);
|
|
791
|
+
const hourLabels = Array.from({ length: hours }, (_, i) => lo + i * 60);
|
|
792
|
+
return /* @__PURE__ */ jsxs5(
|
|
793
|
+
"div",
|
|
794
|
+
{
|
|
795
|
+
ref: mergeRefs(rootRef, sq.ref),
|
|
796
|
+
role: "group",
|
|
797
|
+
"data-sw": "week-schedule",
|
|
798
|
+
"data-hour-format": format,
|
|
799
|
+
"data-dragging": drag ? drag.mode : void 0,
|
|
800
|
+
"data-readonly": readOnly ? "" : void 0,
|
|
801
|
+
className: cx("sw-week-schedule sw-sq", className),
|
|
802
|
+
style: { "--sw-week-hour": `${hourHeight}px`, "--sw-week-hours": hours, ...style, "--sw-week-days": Math.max(1, visibleDays.length) },
|
|
803
|
+
...rest,
|
|
804
|
+
children: [
|
|
805
|
+
/* @__PURE__ */ jsx5(SquircleLayers, { paths: sq.paths, radius: sq.radius, borderWidth: 1 }),
|
|
806
|
+
summary && /* @__PURE__ */ jsxs5("div", { className: "sw-week-schedule__summary", children: [
|
|
807
|
+
/* @__PURE__ */ jsx5("span", { className: "sw-week-schedule__total", "data-value": fmtHours(total), children: fmtHours(total) }),
|
|
808
|
+
/* @__PURE__ */ jsx5("span", { className: "sw-week-schedule__summary-label", children: summaryLabel })
|
|
809
|
+
] }),
|
|
810
|
+
/* @__PURE__ */ jsxs5("div", { ref: viewportRef, className: "sw-week-schedule__viewport", children: [
|
|
811
|
+
visibleCount < n && /* @__PURE__ */ jsxs5("div", { className: "sw-week-schedule__navigation", children: [
|
|
812
|
+
/* @__PURE__ */ jsx5(Button, { size: "sm", variant: "ghost", iconOnly: true, "aria-label": "Previous days", disabled: firstDay === 0, onClick: () => setAnchorDay(firstDay - visibleCount), leading: /* @__PURE__ */ jsx5(Icon, { name: "chevron-left" }) }),
|
|
813
|
+
/* @__PURE__ */ jsxs5("span", { "aria-live": "polite", children: [
|
|
814
|
+
visibleDays[0],
|
|
815
|
+
visibleDays.length > 1 && ` \u2013 ${visibleDays.at(-1)}`
|
|
816
|
+
] }),
|
|
817
|
+
/* @__PURE__ */ jsx5(Button, { size: "sm", variant: "ghost", iconOnly: true, "aria-label": "Next days", disabled: lastDay === n, onClick: () => setAnchorDay(lastDay), leading: /* @__PURE__ */ jsx5(Icon, { name: "chevron-right" }) })
|
|
818
|
+
] }),
|
|
819
|
+
/* @__PURE__ */ jsxs5("div", { className: "sw-week-schedule__board", children: [
|
|
820
|
+
/* @__PURE__ */ jsx5("div", { className: "sw-week-schedule__days", "aria-hidden": true, children: visibleDays.map((d, i) => /* @__PURE__ */ jsx5("span", { className: "sw-week-schedule__day", title: d, children: d }, firstDay + i)) }),
|
|
821
|
+
/* @__PURE__ */ jsx5("div", { className: "sw-week-schedule__hours", "aria-hidden": true, children: /* @__PURE__ */ jsx5("div", { className: "sw-week-schedule__hours-inner", children: hourLabels.map((m, i) => /* @__PURE__ */ jsx5("span", { className: "sw-week-schedule__hour", style: { top: i * hourHeight }, children: formatClock(m, format) }, m)) }) }),
|
|
822
|
+
/* @__PURE__ */ jsxs5("div", { ref: bodyRef, className: "sw-week-schedule__body", children: [
|
|
823
|
+
visibleDays.map((_, i) => /* @__PURE__ */ jsx5("span", { className: "sw-week-schedule__col", "aria-hidden": true }, firstDay + i)),
|
|
824
|
+
events.map((ev) => {
|
|
825
|
+
const dragging = drag?.id === ev.id;
|
|
826
|
+
if (!dragging && (ev.day < firstDay || ev.day >= lastDay) || ev.end <= lo || ev.start >= hi) return null;
|
|
827
|
+
const kind = ev.kind ?? "meeting";
|
|
828
|
+
const top = (Math.max(ev.start, lo) - lo) / 60 * hourHeight;
|
|
829
|
+
const height = (Math.min(ev.end, hi) - Math.max(ev.start, lo)) / 60 * hourHeight;
|
|
830
|
+
const range = formatRange(ev.start, ev.end, format);
|
|
831
|
+
return /* @__PURE__ */ jsxs5(
|
|
832
|
+
"div",
|
|
833
|
+
{
|
|
834
|
+
role: "button",
|
|
835
|
+
tabIndex: 0,
|
|
836
|
+
"aria-roledescription": "event",
|
|
837
|
+
"aria-label": `${ev.title}, ${range}, ${days[ev.day]}${kind === "meeting" ? "" : `, ${kind}`}.${readOnly ? "" : " Arrow keys move it; Shift+Arrow changes its length."}`,
|
|
838
|
+
"data-event-id": ev.id,
|
|
839
|
+
"data-kind": kind,
|
|
840
|
+
"data-day": ev.day,
|
|
841
|
+
"data-start": toHHMM(ev.start),
|
|
842
|
+
"data-end": toHHMM(ev.end),
|
|
843
|
+
"data-size": height < 52 ? "sm" : "md",
|
|
844
|
+
"data-selected": selected === ev.id ? "" : void 0,
|
|
845
|
+
"data-pointer-focus": pointerFocused === ev.id ? "" : void 0,
|
|
846
|
+
"data-dragging": dragging ? drag.mode : void 0,
|
|
847
|
+
className: "sw-week-schedule__event",
|
|
848
|
+
style: { "--sw-week-d": clamp2(ev.day - firstDay, 0, visibleDays.length - 1), "--sw-week-t": top, "--sw-week-h": height },
|
|
849
|
+
onPointerDown: (e) => onPointerDown(ev, e),
|
|
850
|
+
onKeyDown: (e) => onKeyDown(ev, e),
|
|
851
|
+
onFocus: () => {
|
|
852
|
+
setSelected(ev.id);
|
|
853
|
+
setAnchorDay(ev.day);
|
|
854
|
+
},
|
|
855
|
+
onBlur: () => {
|
|
856
|
+
setSelected((s) => s === ev.id ? null : s);
|
|
857
|
+
setPointerFocused((id) => id === ev.id ? null : id);
|
|
858
|
+
},
|
|
859
|
+
children: [
|
|
860
|
+
/* @__PURE__ */ jsx5("span", { className: "sw-week-schedule__title", children: ev.title }),
|
|
861
|
+
/* @__PURE__ */ jsx5("span", { className: "sw-week-schedule__range", children: range }),
|
|
862
|
+
!readOnly && /* @__PURE__ */ jsx5("span", { className: "sw-week-schedule__handle", "aria-hidden": true })
|
|
863
|
+
]
|
|
864
|
+
},
|
|
865
|
+
ev.id
|
|
866
|
+
);
|
|
867
|
+
})
|
|
868
|
+
] })
|
|
869
|
+
] })
|
|
870
|
+
] }),
|
|
871
|
+
(clockToggle || legend) && /* @__PURE__ */ jsxs5("div", { className: "sw-week-schedule__footer", children: [
|
|
872
|
+
clockToggle && /* @__PURE__ */ jsx5(
|
|
873
|
+
SegmentedControl,
|
|
874
|
+
{
|
|
875
|
+
"aria-label": "Clock",
|
|
876
|
+
size: "sm",
|
|
877
|
+
options: [{ value: "24h", label: "24h" }, { value: "12h", label: "12h" }],
|
|
878
|
+
value: format,
|
|
879
|
+
onValueChange: (v) => setFormat(v)
|
|
880
|
+
}
|
|
881
|
+
),
|
|
882
|
+
legend && /* @__PURE__ */ jsx5("ul", { className: "sw-week-schedule__legend", "aria-label": "Legend", children: KINDS.map((k) => /* @__PURE__ */ jsxs5("li", { className: "sw-week-schedule__legend-item", children: [
|
|
883
|
+
/* @__PURE__ */ jsx5("span", { className: "sw-week-schedule__swatch", "data-kind": k, "aria-hidden": true }),
|
|
884
|
+
k
|
|
885
|
+
] }, k)) })
|
|
886
|
+
] }),
|
|
887
|
+
/* @__PURE__ */ jsx5("span", { className: "sw-week-schedule__live", role: "status", "aria-live": "polite", children: message })
|
|
888
|
+
]
|
|
889
|
+
}
|
|
890
|
+
);
|
|
891
|
+
}
|
|
892
|
+
export {
|
|
893
|
+
ActionSquare,
|
|
894
|
+
Canvas,
|
|
895
|
+
PillButton,
|
|
896
|
+
PosterCard,
|
|
897
|
+
WeekSchedule,
|
|
898
|
+
actionSquareRecipe,
|
|
899
|
+
formatClock,
|
|
900
|
+
formatRange,
|
|
901
|
+
parseTime,
|
|
902
|
+
pillButtonRecipe,
|
|
903
|
+
toHHMM
|
|
904
|
+
};
|