@hussmartinez/ui 0.8.0 → 0.10.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/README.md +4 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +16 -2
- package/dist/index.js.map +1 -1
- package/dist/react.d.ts +247 -1
- package/dist/react.js +516 -92
- package/dist/react.js.map +1 -1
- package/dist/shared/{pair-DLVFV6vU.js → pair-MeX064R6.js} +3 -1
- package/dist/shared/pair-MeX064R6.js.map +1 -0
- package/dist/styles.css +185 -0
- package/dist/ui.d.ts +247 -1
- package/package.json +1 -1
- package/dist/shared/pair-DLVFV6vU.js.map +0 -1
package/dist/react.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { a as uiMessages, i as warnInDevelopment, n as cssWriterOf, o as UiError, t as isThemePair } from "./shared/pair-
|
|
2
|
+
import { a as uiMessages, i as warnInDevelopment, n as cssWriterOf, o as UiError, t as isThemePair } from "./shared/pair-MeX064R6.js";
|
|
3
3
|
import { createMessages, platformOf, sdkCoreMessages } from "@hussmartinez/sdk-core";
|
|
4
4
|
import { cloneElement, createContext, forwardRef, isValidElement, useCallback, useContext, useEffect, useId, useMemo, useRef, useState, useSyncExternalStore, version } from "react";
|
|
5
5
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -9,7 +9,7 @@ var REGISTRY = /* @__PURE__ */ Symbol.for("@hussmartinez/ui");
|
|
|
9
9
|
var THIS_COPY = {};
|
|
10
10
|
var checked = false;
|
|
11
11
|
function ownVersion() {
|
|
12
|
-
return "0.
|
|
12
|
+
return "0.10.0";
|
|
13
13
|
}
|
|
14
14
|
function checkSingleCopy() {
|
|
15
15
|
if (checked || !(typeof process !== "undefined" && process.env.NODE_ENV !== "production")) return;
|
|
@@ -144,6 +144,39 @@ var IconButton = /* @__PURE__ */ forwardRef(function IconButton({ label, icon, c
|
|
|
144
144
|
startIcon: icon
|
|
145
145
|
});
|
|
146
146
|
});
|
|
147
|
+
// src/components/field/field-context.ts
|
|
148
|
+
var FieldContext = /* @__PURE__ */ createContext(void 0);
|
|
149
|
+
var FieldLabelContext = /* @__PURE__ */ createContext(void 0);
|
|
150
|
+
function useFieldLabelId() {
|
|
151
|
+
return useContext(FieldLabelContext);
|
|
152
|
+
}
|
|
153
|
+
function useFieldControl() {
|
|
154
|
+
checkSingleCopy();
|
|
155
|
+
return useContext(FieldContext);
|
|
156
|
+
}
|
|
157
|
+
function joinIds(...ids) {
|
|
158
|
+
const joined = ids.filter(Boolean).join(" ");
|
|
159
|
+
return joined === "" ? void 0 : joined;
|
|
160
|
+
}
|
|
161
|
+
function useFieldProps(own, label) {
|
|
162
|
+
const field = useFieldControl();
|
|
163
|
+
if (!field) return {
|
|
164
|
+
id: own.id,
|
|
165
|
+
"aria-describedby": own["aria-describedby"],
|
|
166
|
+
"aria-invalid": own["aria-invalid"]
|
|
167
|
+
};
|
|
168
|
+
if (label !== void 0 || own["aria-label"] !== void 0) {
|
|
169
|
+
if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") warnInDevelopment("A control inside Field has its own label or aria-label, which replaces the field's visible label for screen readers. Leave it out, and set Field's label instead.");
|
|
170
|
+
}
|
|
171
|
+
if (own.id !== void 0 && own.id !== field.id) {
|
|
172
|
+
if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") warnInDevelopment("A control inside Field has its own id, so the field's label doesn't point at it. Pass the id to Field's controlId instead.");
|
|
173
|
+
}
|
|
174
|
+
return {
|
|
175
|
+
id: own.id ?? field.id,
|
|
176
|
+
"aria-describedby": joinIds(field["aria-describedby"], own["aria-describedby"]),
|
|
177
|
+
"aria-invalid": own["aria-invalid"] ?? field["aria-invalid"]
|
|
178
|
+
};
|
|
179
|
+
}
|
|
147
180
|
// src/components/messages/UiMessagesProvider.tsx
|
|
148
181
|
var UiMessagesContext = /* @__PURE__ */ createContext(void 0);
|
|
149
182
|
var english;
|
|
@@ -174,6 +207,170 @@ function useUiLocale() {
|
|
|
174
207
|
checkSingleCopy();
|
|
175
208
|
return useContext(UiMessagesContext)?.locale ?? "en";
|
|
176
209
|
}
|
|
210
|
+
// src/components/color-field/ColorField.tsx
|
|
211
|
+
var HEX = /^#?(?:([0-9a-f]{3})|([0-9a-f]{6}))$/i;
|
|
212
|
+
function parseHex(text) {
|
|
213
|
+
const match = HEX.exec(text.trim());
|
|
214
|
+
if (!match) return;
|
|
215
|
+
return `#${(match[2] ?? match[1].replace(/./g, "$&$&")).toLowerCase()}`;
|
|
216
|
+
}
|
|
217
|
+
function Fill({ color, className }) {
|
|
218
|
+
return /* @__PURE__ */ jsx("svg", {
|
|
219
|
+
className,
|
|
220
|
+
viewBox: "0 0 1 1",
|
|
221
|
+
preserveAspectRatio: "none",
|
|
222
|
+
"aria-hidden": "true",
|
|
223
|
+
focusable: "false",
|
|
224
|
+
children: /* @__PURE__ */ jsx("rect", {
|
|
225
|
+
width: "1",
|
|
226
|
+
height: "1",
|
|
227
|
+
fill: color
|
|
228
|
+
})
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
var ColorField = /* @__PURE__ */ forwardRef(function ColorField({ value: controlled, defaultValue, onValueChange, swatches, label, swatchesLabel, name, form, disabled, className, classNames, unstyled, onBlur, onKeyDown, ...props }, ref) {
|
|
232
|
+
const [uncontrolled, setUncontrolled] = useState(() => parseHex(defaultValue ?? "") ?? "#000000");
|
|
233
|
+
const [draft, setDraft] = useState(null);
|
|
234
|
+
const value = (controlled === void 0 ? void 0 : parseHex(controlled)) ?? uncontrolled;
|
|
235
|
+
const generated = useId();
|
|
236
|
+
const ownLabelId = `${generated}-label`;
|
|
237
|
+
const swatchesLabelId = `${generated}-swatches`;
|
|
238
|
+
const fieldLabelId = useFieldLabelId();
|
|
239
|
+
const swatchesText = useUiText("colorField.swatches");
|
|
240
|
+
const fieldProps = useFieldProps(props, label);
|
|
241
|
+
if (label === void 0 && !props["aria-label"] && !props["aria-labelledby"] && fieldProps.id === void 0) {
|
|
242
|
+
if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") warnInDevelopment("ColorField needs an accessible name: pass label, or put it in a Field. Use text from your message catalogue.");
|
|
243
|
+
}
|
|
244
|
+
const options = [];
|
|
245
|
+
for (const swatch of swatches ?? []) {
|
|
246
|
+
const color = parseHex(swatch.value);
|
|
247
|
+
if (color === void 0) {
|
|
248
|
+
if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") warnInDevelopment(`ColorField skipped the swatch "${swatch.label}": its value isn't a colour such as #1570ef.`);
|
|
249
|
+
} else if (!options.some((option) => option.value === color)) options.push({
|
|
250
|
+
value: color,
|
|
251
|
+
label: swatch.label
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
const tabStop = options.find((option) => option.value === value) ?? options[0];
|
|
255
|
+
const commit = (next) => {
|
|
256
|
+
setDraft(null);
|
|
257
|
+
if (next === value) return;
|
|
258
|
+
if (controlled === void 0) setUncontrolled(next);
|
|
259
|
+
onValueChange?.(next);
|
|
260
|
+
};
|
|
261
|
+
const commitDraft = () => {
|
|
262
|
+
if (draft === null) return;
|
|
263
|
+
const parsed = parseHex(draft);
|
|
264
|
+
if (parsed === void 0) setDraft(null);
|
|
265
|
+
else commit(parsed);
|
|
266
|
+
};
|
|
267
|
+
const handleChange = (event) => {
|
|
268
|
+
setDraft(event.currentTarget.value);
|
|
269
|
+
};
|
|
270
|
+
const handleBlur = (event) => {
|
|
271
|
+
commitDraft();
|
|
272
|
+
onBlur?.(event);
|
|
273
|
+
};
|
|
274
|
+
const handleKeyDown = (event) => {
|
|
275
|
+
onKeyDown?.(event);
|
|
276
|
+
if (event.defaultPrevented || event.nativeEvent.isComposing) return;
|
|
277
|
+
if (event.key === "Enter") flushSync(commitDraft);
|
|
278
|
+
else if (event.key === "Escape" && draft !== null) {
|
|
279
|
+
event.preventDefault();
|
|
280
|
+
setDraft(null);
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
const handleSwatchKeyDown = (event) => {
|
|
284
|
+
const step = event.key === "ArrowRight" || event.key === "ArrowDown" ? 1 : event.key === "ArrowLeft" || event.key === "ArrowUp" ? -1 : 0;
|
|
285
|
+
if (step === 0 || options.length === 0 || event.altKey || event.ctrlKey || event.metaKey) return;
|
|
286
|
+
event.preventDefault();
|
|
287
|
+
const rtl = getComputedStyle(event.currentTarget).direction === "rtl";
|
|
288
|
+
const horizontal = event.key === "ArrowRight" || event.key === "ArrowLeft";
|
|
289
|
+
const direction = rtl && horizontal ? -step : step;
|
|
290
|
+
const focused = options.findIndex((option) => option.value === event.target.dataset["hmValue"]);
|
|
291
|
+
const next = options[(Math.max(0, focused) + direction + options.length) % options.length];
|
|
292
|
+
if (next) {
|
|
293
|
+
commit(next.value);
|
|
294
|
+
event.currentTarget.querySelector(`[data-hm-value="${CSS.escape(next.value)}"]`)?.focus();
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
const groupLabelIds = [fieldLabelId ?? (label === void 0 ? props["aria-labelledby"] : ownLabelId), swatchesLabelId].filter(Boolean).join(" ");
|
|
298
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
299
|
+
ref,
|
|
300
|
+
className: cx("hm-color-field", classNames?.root, className),
|
|
301
|
+
"data-hm-unstyled": unstyledAttribute(unstyled),
|
|
302
|
+
children: [
|
|
303
|
+
/* @__PURE__ */ jsxs("div", {
|
|
304
|
+
className: cx("hm-color-field-control", classNames?.control),
|
|
305
|
+
children: [/* @__PURE__ */ jsx(Fill, {
|
|
306
|
+
color: value,
|
|
307
|
+
className: cx("hm-color-field-preview", classNames?.preview)
|
|
308
|
+
}), /* @__PURE__ */ jsx("input", {
|
|
309
|
+
...props,
|
|
310
|
+
...fieldProps,
|
|
311
|
+
type: "text",
|
|
312
|
+
autoComplete: props.autoComplete ?? "off",
|
|
313
|
+
autoCapitalize: props.autoCapitalize ?? "off",
|
|
314
|
+
autoCorrect: props.autoCorrect ?? "off",
|
|
315
|
+
spellCheck: props.spellCheck ?? false,
|
|
316
|
+
maxLength: props.maxLength ?? 7,
|
|
317
|
+
disabled,
|
|
318
|
+
value: draft ?? value,
|
|
319
|
+
"aria-label": label ?? props["aria-label"],
|
|
320
|
+
className: cx("hm-text-field", "hm-color-field-input", classNames?.input),
|
|
321
|
+
"data-hm-unstyled": unstyledAttribute(unstyled),
|
|
322
|
+
onChange: handleChange,
|
|
323
|
+
onBlur: handleBlur,
|
|
324
|
+
onKeyDown: handleKeyDown
|
|
325
|
+
})]
|
|
326
|
+
}),
|
|
327
|
+
options.length === 0 ? null : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
328
|
+
label === void 0 ? null : /* @__PURE__ */ jsx("span", {
|
|
329
|
+
id: ownLabelId,
|
|
330
|
+
hidden: true,
|
|
331
|
+
children: label
|
|
332
|
+
}),
|
|
333
|
+
/* @__PURE__ */ jsx("span", {
|
|
334
|
+
id: swatchesLabelId,
|
|
335
|
+
hidden: true,
|
|
336
|
+
children: swatchesLabel ?? swatchesText
|
|
337
|
+
}),
|
|
338
|
+
/* @__PURE__ */ jsx("div", {
|
|
339
|
+
role: "radiogroup",
|
|
340
|
+
"aria-labelledby": groupLabelIds,
|
|
341
|
+
"aria-disabled": disabled ? true : void 0,
|
|
342
|
+
className: cx("hm-color-field-swatches", classNames?.swatches),
|
|
343
|
+
onKeyDown: handleSwatchKeyDown,
|
|
344
|
+
children: options.map((option) => {
|
|
345
|
+
const checked = option.value === value;
|
|
346
|
+
return /* @__PURE__ */ jsx("button", {
|
|
347
|
+
type: "button",
|
|
348
|
+
role: "radio",
|
|
349
|
+
"aria-checked": checked,
|
|
350
|
+
"aria-label": option.label,
|
|
351
|
+
disabled,
|
|
352
|
+
tabIndex: option === tabStop ? 0 : -1,
|
|
353
|
+
"data-hm-value": option.value,
|
|
354
|
+
className: cx("hm-color-field-swatch", classNames?.swatch),
|
|
355
|
+
onClick: () => commit(option.value),
|
|
356
|
+
children: /* @__PURE__ */ jsx(Fill, {
|
|
357
|
+
color: option.value,
|
|
358
|
+
className: "hm-color-field-swatch-fill"
|
|
359
|
+
})
|
|
360
|
+
}, option.value);
|
|
361
|
+
})
|
|
362
|
+
})
|
|
363
|
+
] }),
|
|
364
|
+
name === void 0 ? null : /* @__PURE__ */ jsx("input", {
|
|
365
|
+
type: "hidden",
|
|
366
|
+
name,
|
|
367
|
+
form,
|
|
368
|
+
disabled,
|
|
369
|
+
value
|
|
370
|
+
})
|
|
371
|
+
]
|
|
372
|
+
});
|
|
373
|
+
});
|
|
177
374
|
// src/components/dialog/CloseIcon.tsx
|
|
178
375
|
function CloseIcon$1() {
|
|
179
376
|
return /* @__PURE__ */ jsx("svg", {
|
|
@@ -287,39 +484,11 @@ var Dialog = /* @__PURE__ */ forwardRef(function Dialog({ open, onOpenChange, ti
|
|
|
287
484
|
]
|
|
288
485
|
});
|
|
289
486
|
});
|
|
290
|
-
// src/components/field/field-context.ts
|
|
291
|
-
var FieldContext = /* @__PURE__ */ createContext(void 0);
|
|
292
|
-
function useFieldControl() {
|
|
293
|
-
checkSingleCopy();
|
|
294
|
-
return useContext(FieldContext);
|
|
295
|
-
}
|
|
296
|
-
function joinIds(...ids) {
|
|
297
|
-
const joined = ids.filter(Boolean).join(" ");
|
|
298
|
-
return joined === "" ? void 0 : joined;
|
|
299
|
-
}
|
|
300
|
-
function useFieldProps(own, label) {
|
|
301
|
-
const field = useFieldControl();
|
|
302
|
-
if (!field) return {
|
|
303
|
-
id: own.id,
|
|
304
|
-
"aria-describedby": own["aria-describedby"],
|
|
305
|
-
"aria-invalid": own["aria-invalid"]
|
|
306
|
-
};
|
|
307
|
-
if (label !== void 0 || own["aria-label"] !== void 0) {
|
|
308
|
-
if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") warnInDevelopment("A control inside Field has its own label or aria-label, which replaces the field's visible label for screen readers. Leave it out, and set Field's label instead.");
|
|
309
|
-
}
|
|
310
|
-
if (own.id !== void 0 && own.id !== field.id) {
|
|
311
|
-
if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") warnInDevelopment("A control inside Field has its own id, so the field's label doesn't point at it. Pass the id to Field's controlId instead.");
|
|
312
|
-
}
|
|
313
|
-
return {
|
|
314
|
-
id: own.id ?? field.id,
|
|
315
|
-
"aria-describedby": joinIds(field["aria-describedby"], own["aria-describedby"]),
|
|
316
|
-
"aria-invalid": own["aria-invalid"] ?? field["aria-invalid"]
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
487
|
// src/components/field/Field.tsx
|
|
320
488
|
var Field = /* @__PURE__ */ forwardRef(function Field({ label, description, error, controlId, className, classNames, unstyled, children, ...props }, ref) {
|
|
321
489
|
const generated = useId();
|
|
322
490
|
const id = controlId ?? `${generated}-control`;
|
|
491
|
+
const labelId = `${generated}-label`;
|
|
323
492
|
const descriptionId = `${generated}-description`;
|
|
324
493
|
const errorId = `${generated}-error`;
|
|
325
494
|
const hasDescription = description != null && description !== false;
|
|
@@ -336,6 +505,7 @@ var Field = /* @__PURE__ */ forwardRef(function Field({ label, description, erro
|
|
|
336
505
|
"data-hm-unstyled": unstyledAttribute(unstyled),
|
|
337
506
|
children: [
|
|
338
507
|
/* @__PURE__ */ jsx("label", {
|
|
508
|
+
id: labelId,
|
|
339
509
|
htmlFor: id,
|
|
340
510
|
className: cx("hm-field-label", classNames?.label),
|
|
341
511
|
children: label
|
|
@@ -347,7 +517,10 @@ var Field = /* @__PURE__ */ forwardRef(function Field({ label, description, erro
|
|
|
347
517
|
}) : null,
|
|
348
518
|
/* @__PURE__ */ jsx(FieldContext.Provider, {
|
|
349
519
|
value: control,
|
|
350
|
-
children:
|
|
520
|
+
children: /* @__PURE__ */ jsx(FieldLabelContext.Provider, {
|
|
521
|
+
value: labelId,
|
|
522
|
+
children: typeof children === "function" ? children(control) : children
|
|
523
|
+
})
|
|
351
524
|
}),
|
|
352
525
|
hasError ? /* @__PURE__ */ jsx("div", {
|
|
353
526
|
id: errorId,
|
|
@@ -665,6 +838,274 @@ var ProgressBar = /* @__PURE__ */ forwardRef(function ProgressBar({ value, max =
|
|
|
665
838
|
"data-hm-unstyled": unstyledAttribute(unstyled)
|
|
666
839
|
});
|
|
667
840
|
});
|
|
841
|
+
// src/components/toolbar/roving-focus.ts
|
|
842
|
+
var FOCUSABLE = "button:not(:disabled), a[href], input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex^=\"-\"]):not(button, a, input, select, textarea), [data-hm-roving]:not(:disabled)";
|
|
843
|
+
function items(toolbar) {
|
|
844
|
+
return [...toolbar.querySelectorAll(FOCUSABLE)].filter((element) => !element.closest("[hidden], [inert]") && element.getClientRects().length > 0);
|
|
845
|
+
}
|
|
846
|
+
function syncTabStop$1(toolbar, active) {
|
|
847
|
+
const list = items(toolbar);
|
|
848
|
+
const current = list.find((item) => item === active) ?? list.find((item) => item.tabIndex === 0 && item.dataset["hmTabStop"] !== void 0) ?? list[0];
|
|
849
|
+
for (const item of list) {
|
|
850
|
+
const isStop = item === current;
|
|
851
|
+
item.dataset["hmRoving"] = "";
|
|
852
|
+
item.tabIndex = isStop ? 0 : -1;
|
|
853
|
+
if (isStop) item.dataset["hmTabStop"] = "";
|
|
854
|
+
else delete item.dataset["hmTabStop"];
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
function editsText$1(target) {
|
|
858
|
+
if (!(target instanceof HTMLElement)) return false;
|
|
859
|
+
return target.isContentEditable || target instanceof HTMLTextAreaElement || target instanceof HTMLSelectElement || target instanceof HTMLInputElement && ![
|
|
860
|
+
"button",
|
|
861
|
+
"checkbox",
|
|
862
|
+
"radio",
|
|
863
|
+
"reset",
|
|
864
|
+
"submit"
|
|
865
|
+
].includes(target.type);
|
|
866
|
+
}
|
|
867
|
+
function moveFocus(toolbar, event, orientation) {
|
|
868
|
+
if (editsText$1(event.target)) return false;
|
|
869
|
+
const rtl = getComputedStyle(toolbar).direction === "rtl";
|
|
870
|
+
const next = orientation === "vertical" ? "ArrowDown" : rtl ? "ArrowLeft" : "ArrowRight";
|
|
871
|
+
const previous = orientation === "vertical" ? "ArrowUp" : rtl ? "ArrowRight" : "ArrowLeft";
|
|
872
|
+
const list = items(toolbar);
|
|
873
|
+
if (list.length === 0) return false;
|
|
874
|
+
const index = list.indexOf(event.target);
|
|
875
|
+
let target;
|
|
876
|
+
switch (event.key) {
|
|
877
|
+
case next:
|
|
878
|
+
target = list[(index + 1) % list.length];
|
|
879
|
+
break;
|
|
880
|
+
case previous:
|
|
881
|
+
target = list[(index - 1 + list.length) % list.length];
|
|
882
|
+
break;
|
|
883
|
+
case "Home":
|
|
884
|
+
target = list[0];
|
|
885
|
+
break;
|
|
886
|
+
case "End":
|
|
887
|
+
target = list[list.length - 1];
|
|
888
|
+
break;
|
|
889
|
+
default: return false;
|
|
890
|
+
}
|
|
891
|
+
if (target) {
|
|
892
|
+
syncTabStop$1(toolbar, target);
|
|
893
|
+
target.focus();
|
|
894
|
+
}
|
|
895
|
+
return true;
|
|
896
|
+
}
|
|
897
|
+
// src/components/reorderable-list/ReorderableList.tsx
|
|
898
|
+
var ReorderableListContext = /* @__PURE__ */ createContext(void 0);
|
|
899
|
+
function editsText(target) {
|
|
900
|
+
return target instanceof HTMLElement && (target.isContentEditable || target instanceof HTMLTextAreaElement || target instanceof HTMLSelectElement || target instanceof HTMLInputElement && ![
|
|
901
|
+
"button",
|
|
902
|
+
"checkbox",
|
|
903
|
+
"radio",
|
|
904
|
+
"reset",
|
|
905
|
+
"submit"
|
|
906
|
+
].includes(target.type));
|
|
907
|
+
}
|
|
908
|
+
function rowsOf(list) {
|
|
909
|
+
return [...list.children].filter((child) => child instanceof HTMLElement && child.getAttribute("role") === "row");
|
|
910
|
+
}
|
|
911
|
+
function cellsOf(row) {
|
|
912
|
+
const targets = [];
|
|
913
|
+
for (const cell of row.children) {
|
|
914
|
+
if (!(cell instanceof HTMLElement)) continue;
|
|
915
|
+
if (cell.dataset["hmCell"] === "item") targets.push(cell);
|
|
916
|
+
else {
|
|
917
|
+
const control = items(cell)[0];
|
|
918
|
+
if (control) targets.push(control);
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
return targets;
|
|
922
|
+
}
|
|
923
|
+
var idOf = (row) => row?.dataset["hmId"] ?? "";
|
|
924
|
+
var orderOf = (rows) => JSON.stringify(rows.map(idOf));
|
|
925
|
+
var selectedRow = (rows) => rows.find((row) => row.getAttribute("aria-selected") === "true");
|
|
926
|
+
function syncTabStop(list, active) {
|
|
927
|
+
const rows = rowsOf(list);
|
|
928
|
+
const all = rows.flatMap(cellsOf);
|
|
929
|
+
const current = all.find((cell) => cell === active) ?? all.find((cell) => cell.dataset["hmTabStop"] !== void 0) ?? cellsOf(selectedRow(rows) ?? rows[0] ?? list)[0];
|
|
930
|
+
for (const cell of all) {
|
|
931
|
+
const isStop = cell === current;
|
|
932
|
+
cell.dataset["hmRoving"] = "";
|
|
933
|
+
cell.tabIndex = isStop ? 0 : -1;
|
|
934
|
+
if (isStop) cell.dataset["hmTabStop"] = "";
|
|
935
|
+
else delete cell.dataset["hmTabStop"];
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
var ReorderableList = /* @__PURE__ */ forwardRef(function ReorderableList({ label, selectedId, onSelectedChange, onMove, onRemove, announceMoves = true, className, classNames, unstyled, onKeyDown, onClick, onFocus, onBlur, children, ...props }, ref) {
|
|
939
|
+
const list = useRef(null);
|
|
940
|
+
const pending = useRef(void 0);
|
|
941
|
+
const lastSelected = useRef(selectedId);
|
|
942
|
+
const announce = useAnnounce();
|
|
943
|
+
const messages = useUiMessages();
|
|
944
|
+
useEffect(() => {
|
|
945
|
+
const element = list.current;
|
|
946
|
+
if (!element) return;
|
|
947
|
+
const change = pending.current;
|
|
948
|
+
const rows = rowsOf(element);
|
|
949
|
+
if (change && orderOf(rows) !== change.order) {
|
|
950
|
+
pending.current = void 0;
|
|
951
|
+
const index = change.kind === "move" ? rows.findIndex((row) => idOf(row) === change.id) : Math.min(change.index, rows.length - 1);
|
|
952
|
+
const row = rows[index];
|
|
953
|
+
const active = document.activeElement;
|
|
954
|
+
const free = !active || active === document.body || element.contains(active);
|
|
955
|
+
if (row && free) {
|
|
956
|
+
const cells = cellsOf(row);
|
|
957
|
+
const target = cells[change.cell] ?? cells[0];
|
|
958
|
+
syncTabStop(element, target);
|
|
959
|
+
target?.focus();
|
|
960
|
+
}
|
|
961
|
+
if (row && change.kind === "move" && announceMoves) announce(messages.t("reorderableList.moved", {
|
|
962
|
+
label: cellsOf(row)[0]?.getAttribute("aria-label") ?? "",
|
|
963
|
+
position: index + 1,
|
|
964
|
+
count: rows.length
|
|
965
|
+
}));
|
|
966
|
+
}
|
|
967
|
+
const inside = element.contains(document.activeElement);
|
|
968
|
+
const reselected = lastSelected.current !== selectedId;
|
|
969
|
+
lastSelected.current = selectedId;
|
|
970
|
+
syncTabStop(element, inside ? document.activeElement : reselected ? cellsOf(selectedRow(rowsOf(element)) ?? element)[0] : null);
|
|
971
|
+
});
|
|
972
|
+
const select = (id) => {
|
|
973
|
+
if (id !== "" && id !== selectedId) onSelectedChange?.(id);
|
|
974
|
+
};
|
|
975
|
+
const focusCell = (row, cell) => {
|
|
976
|
+
if (!row || !list.current) return;
|
|
977
|
+
const cells = cellsOf(row);
|
|
978
|
+
const target = cells[cell] ?? cells[0];
|
|
979
|
+
syncTabStop(list.current, target);
|
|
980
|
+
target?.focus();
|
|
981
|
+
};
|
|
982
|
+
const handleKeyDown = (event) => {
|
|
983
|
+
onKeyDown?.(event);
|
|
984
|
+
pending.current = void 0;
|
|
985
|
+
if (event.defaultPrevented || event.nativeEvent.isComposing || event.shiftKey || editsText(event.target)) return;
|
|
986
|
+
const element = event.currentTarget;
|
|
987
|
+
const rows = rowsOf(element);
|
|
988
|
+
const index = rows.findIndex((row) => row.contains(event.target));
|
|
989
|
+
const row = rows[index];
|
|
990
|
+
if (!row) return;
|
|
991
|
+
const cells = cellsOf(row);
|
|
992
|
+
const cell = cells.indexOf(event.target);
|
|
993
|
+
if (cell === -1) return;
|
|
994
|
+
const quiet = event.ctrlKey || event.metaKey;
|
|
995
|
+
const vertical = event.key === "ArrowUp" ? -1 : event.key === "ArrowDown" ? 1 : 0;
|
|
996
|
+
if (event.altKey) {
|
|
997
|
+
if (vertical !== 0 && !quiet && onMove) {
|
|
998
|
+
event.preventDefault();
|
|
999
|
+
const toIndex = index + vertical;
|
|
1000
|
+
if (toIndex >= 0 && toIndex < rows.length) {
|
|
1001
|
+
pending.current = {
|
|
1002
|
+
kind: "move",
|
|
1003
|
+
id: idOf(row),
|
|
1004
|
+
index,
|
|
1005
|
+
cell,
|
|
1006
|
+
order: orderOf(rows)
|
|
1007
|
+
};
|
|
1008
|
+
onMove(idOf(row), toIndex);
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
return;
|
|
1012
|
+
}
|
|
1013
|
+
if (vertical !== 0) {
|
|
1014
|
+
event.preventDefault();
|
|
1015
|
+
const next = rows[index + vertical];
|
|
1016
|
+
if (next) {
|
|
1017
|
+
focusCell(next, cell);
|
|
1018
|
+
if (!quiet) select(idOf(next));
|
|
1019
|
+
}
|
|
1020
|
+
return;
|
|
1021
|
+
}
|
|
1022
|
+
if (event.key === "Home" || event.key === "End") {
|
|
1023
|
+
event.preventDefault();
|
|
1024
|
+
if (quiet) focusCell(event.key === "Home" ? rows[0] : rows[rows.length - 1], cell);
|
|
1025
|
+
else focusCell(row, event.key === "Home" ? 0 : cells.length - 1);
|
|
1026
|
+
return;
|
|
1027
|
+
}
|
|
1028
|
+
if (quiet) return;
|
|
1029
|
+
if (event.key === "ArrowLeft" || event.key === "ArrowRight") {
|
|
1030
|
+
event.preventDefault();
|
|
1031
|
+
const rtl = getComputedStyle(element).direction === "rtl";
|
|
1032
|
+
const step = event.key === "ArrowRight" === rtl ? -1 : 1;
|
|
1033
|
+
if (cells[cell + step]) focusCell(row, cell + step);
|
|
1034
|
+
} else if ((event.key === "Delete" || event.key === "Backspace") && onRemove) {
|
|
1035
|
+
event.preventDefault();
|
|
1036
|
+
pending.current = {
|
|
1037
|
+
kind: "remove",
|
|
1038
|
+
id: idOf(row),
|
|
1039
|
+
index,
|
|
1040
|
+
cell,
|
|
1041
|
+
order: orderOf(rows)
|
|
1042
|
+
};
|
|
1043
|
+
onRemove(idOf(row));
|
|
1044
|
+
} else if ((event.key === " " || event.key === "Enter") && cell === 0) {
|
|
1045
|
+
event.preventDefault();
|
|
1046
|
+
select(idOf(row));
|
|
1047
|
+
}
|
|
1048
|
+
};
|
|
1049
|
+
const handleClick = (event) => {
|
|
1050
|
+
onClick?.(event);
|
|
1051
|
+
const target = event.target;
|
|
1052
|
+
const row = rowsOf(event.currentTarget).find((candidate) => candidate.contains(target));
|
|
1053
|
+
if (row && !event.defaultPrevented && target.closest("[data-hm-cell=\"control\"]") === null) select(idOf(row));
|
|
1054
|
+
};
|
|
1055
|
+
const handleFocus = (event) => {
|
|
1056
|
+
onFocus?.(event);
|
|
1057
|
+
syncTabStop(event.currentTarget, event.target);
|
|
1058
|
+
};
|
|
1059
|
+
const handleBlur = (event) => {
|
|
1060
|
+
onBlur?.(event);
|
|
1061
|
+
if (event.relatedTarget && !event.currentTarget.contains(event.relatedTarget)) pending.current = void 0;
|
|
1062
|
+
};
|
|
1063
|
+
return /* @__PURE__ */ jsx("div", {
|
|
1064
|
+
...props,
|
|
1065
|
+
ref: (node) => {
|
|
1066
|
+
list.current = node;
|
|
1067
|
+
if (typeof ref === "function") ref(node);
|
|
1068
|
+
else if (ref) ref.current = node;
|
|
1069
|
+
},
|
|
1070
|
+
role: "grid",
|
|
1071
|
+
"aria-label": label,
|
|
1072
|
+
className: cx("hm-reorderable-list", classNames?.root, className),
|
|
1073
|
+
"data-hm-unstyled": unstyledAttribute(unstyled),
|
|
1074
|
+
onKeyDown: handleKeyDown,
|
|
1075
|
+
onClick: handleClick,
|
|
1076
|
+
onFocus: handleFocus,
|
|
1077
|
+
onBlur: handleBlur,
|
|
1078
|
+
children: /* @__PURE__ */ jsx(ReorderableListContext.Provider, {
|
|
1079
|
+
value: { selectedId },
|
|
1080
|
+
children
|
|
1081
|
+
})
|
|
1082
|
+
});
|
|
1083
|
+
});
|
|
1084
|
+
var ReorderableListItem = /* @__PURE__ */ forwardRef(function ReorderableListItem({ id, label, controls, className, classNames, unstyled, children, ...props }, ref) {
|
|
1085
|
+
const selected = useContext(ReorderableListContext)?.selectedId === id;
|
|
1086
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1087
|
+
...props,
|
|
1088
|
+
ref,
|
|
1089
|
+
role: "row",
|
|
1090
|
+
"aria-selected": selected,
|
|
1091
|
+
"data-hm-id": id,
|
|
1092
|
+
className: cx("hm-reorderable-list-row", classNames?.root, className),
|
|
1093
|
+
"data-hm-unstyled": unstyledAttribute(unstyled),
|
|
1094
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
1095
|
+
role: "gridcell",
|
|
1096
|
+
"aria-label": label,
|
|
1097
|
+
tabIndex: selected ? 0 : -1,
|
|
1098
|
+
"data-hm-cell": "item",
|
|
1099
|
+
className: cx("hm-reorderable-list-item", classNames?.item),
|
|
1100
|
+
children
|
|
1101
|
+
}), controls?.map((control, index) => /* @__PURE__ */ jsx("div", {
|
|
1102
|
+
role: "gridcell",
|
|
1103
|
+
"data-hm-cell": "control",
|
|
1104
|
+
className: cx("hm-reorderable-list-control", classNames?.control),
|
|
1105
|
+
children: control
|
|
1106
|
+
}, index))]
|
|
1107
|
+
});
|
|
1108
|
+
});
|
|
668
1109
|
// src/components/toolbar/toolbar-context.ts
|
|
669
1110
|
var ToolbarContext = /* @__PURE__ */ createContext(void 0);
|
|
670
1111
|
function useToolbar() {
|
|
@@ -800,6 +1241,27 @@ var Spinner = /* @__PURE__ */ forwardRef(function Spinner({ label, className, cl
|
|
|
800
1241
|
"data-hm-unstyled": unstyledAttribute(unstyled)
|
|
801
1242
|
});
|
|
802
1243
|
});
|
|
1244
|
+
// src/components/text-area/TextArea.tsx
|
|
1245
|
+
var TextArea = /* @__PURE__ */ forwardRef(function TextArea({ rows = 3, onValueChange, onChange, label, className, classNames, unstyled, ...props }, ref) {
|
|
1246
|
+
const fieldProps = useFieldProps(props, label);
|
|
1247
|
+
if (label === void 0 && !props["aria-label"] && !props["aria-labelledby"] && fieldProps.id === void 0) {
|
|
1248
|
+
if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") warnInDevelopment("TextArea needs an accessible name: pass label, or put it in a Field. Use text from your message catalogue.");
|
|
1249
|
+
}
|
|
1250
|
+
const handleChange = (event) => {
|
|
1251
|
+
onChange?.(event);
|
|
1252
|
+
onValueChange?.(event.currentTarget.value);
|
|
1253
|
+
};
|
|
1254
|
+
return /* @__PURE__ */ jsx("textarea", {
|
|
1255
|
+
...props,
|
|
1256
|
+
...fieldProps,
|
|
1257
|
+
ref,
|
|
1258
|
+
rows,
|
|
1259
|
+
"aria-label": label ?? props["aria-label"],
|
|
1260
|
+
className: cx("hm-text-field", "hm-text-area", classNames?.root, className),
|
|
1261
|
+
"data-hm-unstyled": unstyledAttribute(unstyled),
|
|
1262
|
+
onChange: handleChange
|
|
1263
|
+
});
|
|
1264
|
+
});
|
|
803
1265
|
// src/components/text-field/TextField.tsx
|
|
804
1266
|
var TextField = /* @__PURE__ */ forwardRef(function TextField({ type = "text", onValueChange, onChange, label, className, classNames, unstyled, ...props }, ref) {
|
|
805
1267
|
const fieldProps = useFieldProps(props, label);
|
|
@@ -847,62 +1309,6 @@ var ToggleButton = /* @__PURE__ */ forwardRef(function ToggleButton({ pressed: c
|
|
|
847
1309
|
onClick: handleClick
|
|
848
1310
|
});
|
|
849
1311
|
});
|
|
850
|
-
// src/components/toolbar/roving-focus.ts
|
|
851
|
-
var FOCUSABLE = "button:not(:disabled), a[href], input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex^=\"-\"]):not(button, a, input, select, textarea), [data-hm-roving]:not(:disabled)";
|
|
852
|
-
function items(toolbar) {
|
|
853
|
-
return [...toolbar.querySelectorAll(FOCUSABLE)].filter((element) => !element.closest("[hidden], [inert]") && element.getClientRects().length > 0);
|
|
854
|
-
}
|
|
855
|
-
function syncTabStop(toolbar, active) {
|
|
856
|
-
const list = items(toolbar);
|
|
857
|
-
const current = list.find((item) => item === active) ?? list.find((item) => item.tabIndex === 0 && item.dataset["hmTabStop"] !== void 0) ?? list[0];
|
|
858
|
-
for (const item of list) {
|
|
859
|
-
const isStop = item === current;
|
|
860
|
-
item.dataset["hmRoving"] = "";
|
|
861
|
-
item.tabIndex = isStop ? 0 : -1;
|
|
862
|
-
if (isStop) item.dataset["hmTabStop"] = "";
|
|
863
|
-
else delete item.dataset["hmTabStop"];
|
|
864
|
-
}
|
|
865
|
-
}
|
|
866
|
-
function editsText(target) {
|
|
867
|
-
if (!(target instanceof HTMLElement)) return false;
|
|
868
|
-
return target.isContentEditable || target instanceof HTMLTextAreaElement || target instanceof HTMLSelectElement || target instanceof HTMLInputElement && ![
|
|
869
|
-
"button",
|
|
870
|
-
"checkbox",
|
|
871
|
-
"radio",
|
|
872
|
-
"reset",
|
|
873
|
-
"submit"
|
|
874
|
-
].includes(target.type);
|
|
875
|
-
}
|
|
876
|
-
function moveFocus(toolbar, event, orientation) {
|
|
877
|
-
if (editsText(event.target)) return false;
|
|
878
|
-
const rtl = getComputedStyle(toolbar).direction === "rtl";
|
|
879
|
-
const next = orientation === "vertical" ? "ArrowDown" : rtl ? "ArrowLeft" : "ArrowRight";
|
|
880
|
-
const previous = orientation === "vertical" ? "ArrowUp" : rtl ? "ArrowRight" : "ArrowLeft";
|
|
881
|
-
const list = items(toolbar);
|
|
882
|
-
if (list.length === 0) return false;
|
|
883
|
-
const index = list.indexOf(event.target);
|
|
884
|
-
let target;
|
|
885
|
-
switch (event.key) {
|
|
886
|
-
case next:
|
|
887
|
-
target = list[(index + 1) % list.length];
|
|
888
|
-
break;
|
|
889
|
-
case previous:
|
|
890
|
-
target = list[(index - 1 + list.length) % list.length];
|
|
891
|
-
break;
|
|
892
|
-
case "Home":
|
|
893
|
-
target = list[0];
|
|
894
|
-
break;
|
|
895
|
-
case "End":
|
|
896
|
-
target = list[list.length - 1];
|
|
897
|
-
break;
|
|
898
|
-
default: return false;
|
|
899
|
-
}
|
|
900
|
-
if (target) {
|
|
901
|
-
syncTabStop(toolbar, target);
|
|
902
|
-
target.focus();
|
|
903
|
-
}
|
|
904
|
-
return true;
|
|
905
|
-
}
|
|
906
1312
|
// src/components/toolbar/Toolbar.tsx
|
|
907
1313
|
function useMergedRef(forwarded) {
|
|
908
1314
|
const local = useRef(null);
|
|
@@ -917,8 +1323,8 @@ var Toolbar = /* @__PURE__ */ forwardRef(function Toolbar({ label, orientation =
|
|
|
917
1323
|
useEffect(() => {
|
|
918
1324
|
const toolbar = ref.current;
|
|
919
1325
|
if (!toolbar) return;
|
|
920
|
-
syncTabStop(toolbar);
|
|
921
|
-
const observer = new MutationObserver(() => syncTabStop(toolbar, document.activeElement));
|
|
1326
|
+
syncTabStop$1(toolbar);
|
|
1327
|
+
const observer = new MutationObserver(() => syncTabStop$1(toolbar, document.activeElement));
|
|
922
1328
|
observer.observe(toolbar, {
|
|
923
1329
|
childList: true,
|
|
924
1330
|
subtree: true,
|
|
@@ -933,7 +1339,7 @@ var Toolbar = /* @__PURE__ */ forwardRef(function Toolbar({ label, orientation =
|
|
|
933
1339
|
};
|
|
934
1340
|
const handleFocus = (event) => {
|
|
935
1341
|
onFocus?.(event);
|
|
936
|
-
if (ref.current && event.target !== ref.current) syncTabStop(ref.current, event.target);
|
|
1342
|
+
if (ref.current && event.target !== ref.current) syncTabStop$1(ref.current, event.target);
|
|
937
1343
|
};
|
|
938
1344
|
return /* @__PURE__ */ jsx(ToolbarContext.Provider, {
|
|
939
1345
|
value: { orientation },
|
|
@@ -1262,6 +1668,24 @@ function HiddenIcon(props) {
|
|
|
1262
1668
|
function HighlighterIcon(props) {
|
|
1263
1669
|
return renderIcon("highlighter", [["path", { d: "m9 11-6 6v3h9l3-3" }], ["path", { d: "m22 12-4.6 4.6a2 2 0 0 1-2.8 0l-5.2-5.2a2 2 0 0 1 0-2.8L14 4" }]], false, props);
|
|
1264
1670
|
}
|
|
1671
|
+
function ImageIcon(props) {
|
|
1672
|
+
return renderIcon("image", [
|
|
1673
|
+
["rect", {
|
|
1674
|
+
width: "18",
|
|
1675
|
+
height: "18",
|
|
1676
|
+
x: "3",
|
|
1677
|
+
y: "3",
|
|
1678
|
+
rx: "2",
|
|
1679
|
+
ry: "2"
|
|
1680
|
+
}],
|
|
1681
|
+
["circle", {
|
|
1682
|
+
cx: "9",
|
|
1683
|
+
cy: "9",
|
|
1684
|
+
r: "2"
|
|
1685
|
+
}],
|
|
1686
|
+
["path", { d: "m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21" }]
|
|
1687
|
+
], false, props);
|
|
1688
|
+
}
|
|
1265
1689
|
function InfoIcon(props) {
|
|
1266
1690
|
return renderIcon("info", [
|
|
1267
1691
|
["circle", {
|
|
@@ -1605,6 +2029,6 @@ function ThemeProvider(props) {
|
|
|
1605
2029
|
}), children]
|
|
1606
2030
|
});
|
|
1607
2031
|
}
|
|
1608
|
-
export { AddIcon, AnnouncerProvider, ArrowIcon, Button, CheckIcon, ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, CloseIcon, CropIcon, DeleteIcon, Dialog, DownloadIcon, DuplicateIcon, EllipseIcon, FadeInIcon, FadeOutIcon, Field, FileDropZone, FitIcon, FlipHorizontalIcon, FlipVerticalIcon, HiddenIcon, HighlighterIcon, IconButton, InfoIcon, LayersIcon, LoopIcon, MenuIcon, MoreIcon, MoveDownIcon, MoveUpIcon, MutedIcon, NumberField, OpenIcon, PageAddIcon, PageGridIcon, PageSingleIcon, PanIcon, PauseIcon, PenIcon, PlayIcon, ProgressBar, RectangleIcon, RedactIcon, RedoIcon, RemoveIcon, RotateLeftIcon, RotateRightIcon, SearchIcon, SegmentedControl, SelectIcon, SkipBackIcon, SkipForwardIcon, Slider, SnapIcon, Spinner, SplitIcon, StopIcon, TextField, TextIcon, ThemeProvider, ToggleButton, Toolbar, ToolbarGroup, ToolbarSeparator, Tooltip, TrimEndIcon, TrimStartIcon, UiMessagesProvider, UndoIcon, UploadIcon, VisibleIcon, VisuallyHidden, VolumeIcon, WarningIcon, ZoomInIcon, ZoomOutIcon, uiMessages, useAnnounce, usePlatform, useUiMessages };
|
|
2032
|
+
export { AddIcon, AnnouncerProvider, ArrowIcon, Button, CheckIcon, ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, CloseIcon, ColorField, CropIcon, DeleteIcon, Dialog, DownloadIcon, DuplicateIcon, EllipseIcon, FadeInIcon, FadeOutIcon, Field, FileDropZone, FitIcon, FlipHorizontalIcon, FlipVerticalIcon, HiddenIcon, HighlighterIcon, IconButton, ImageIcon, InfoIcon, LayersIcon, LoopIcon, MenuIcon, MoreIcon, MoveDownIcon, MoveUpIcon, MutedIcon, NumberField, OpenIcon, PageAddIcon, PageGridIcon, PageSingleIcon, PanIcon, PauseIcon, PenIcon, PlayIcon, ProgressBar, RectangleIcon, RedactIcon, RedoIcon, RemoveIcon, ReorderableList, ReorderableListItem, RotateLeftIcon, RotateRightIcon, SearchIcon, SegmentedControl, SelectIcon, SkipBackIcon, SkipForwardIcon, Slider, SnapIcon, Spinner, SplitIcon, StopIcon, TextArea, TextField, TextIcon, ThemeProvider, ToggleButton, Toolbar, ToolbarGroup, ToolbarSeparator, Tooltip, TrimEndIcon, TrimStartIcon, UiMessagesProvider, UndoIcon, UploadIcon, VisibleIcon, VisuallyHidden, VolumeIcon, WarningIcon, ZoomInIcon, ZoomOutIcon, uiMessages, useAnnounce, usePlatform, useUiMessages };
|
|
1609
2033
|
|
|
1610
2034
|
//# sourceMappingURL=react.js.map
|