@glimstone/react 4.1.0 → 4.1.2
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 +7 -0
- package/dist/Button.d.ts +19 -6
- package/dist/Button.js +10 -5
- package/dist/Card.d.ts +3 -1
- package/dist/Card.js +2 -2
- package/dist/Combobox.d.ts +1 -1
- package/dist/Combobox.js +3 -1
- package/dist/ContextMenu.d.ts +3 -1
- package/dist/ContextMenu.js +3 -3
- package/dist/CopyField.d.ts +5 -3
- package/dist/CopyField.js +5 -3
- package/dist/FieldRow.d.ts +20 -0
- package/dist/FieldRow.js +13 -0
- package/dist/FieldRowGroup.d.ts +9 -0
- package/dist/FieldRowGroup.js +5 -0
- package/dist/GlyphField.d.ts +16 -0
- package/dist/GlyphField.js +8 -0
- package/dist/GlyphTile.d.ts +12 -0
- package/dist/GlyphTile.js +5 -0
- package/dist/IconButton.d.ts +16 -0
- package/dist/IconButton.js +9 -0
- package/dist/IconTipButton.d.ts +6 -4
- package/dist/IconTipButton.js +4 -9
- package/dist/ListRow.d.ts +16 -0
- package/dist/ListRow.js +14 -0
- package/dist/MenuBar.d.ts +2 -0
- package/dist/MenuBar.js +1 -1
- package/dist/NumberField.d.ts +1 -1
- package/dist/NumberField.js +4 -2
- package/dist/PasswordField.d.ts +6 -2
- package/dist/PasswordField.js +5 -2
- package/dist/PathField.d.ts +28 -0
- package/dist/PathField.js +32 -0
- package/dist/RowMark.d.ts +5 -0
- package/dist/RowMark.js +6 -0
- package/dist/Select.d.ts +12 -6
- package/dist/Select.js +21 -15
- package/dist/Selector.d.ts +15 -11
- package/dist/Selector.js +11 -6
- package/dist/SidebarRow.d.ts +10 -2
- package/dist/SidebarRow.js +8 -3
- package/dist/Slider.d.ts +1 -1
- package/dist/Slider.js +3 -1
- package/dist/SubCard.d.ts +1 -1
- package/dist/SubCard.js +1 -1
- package/dist/Table.d.ts +14 -0
- package/dist/Table.js +6 -0
- package/dist/TextField.d.ts +23 -0
- package/dist/TextField.js +11 -0
- package/dist/Toast.d.ts +5 -2
- package/dist/Toast.js +9 -4
- package/dist/Toggle.d.ts +5 -4
- package/dist/Toggle.js +7 -2
- package/dist/Tree.d.ts +20 -0
- package/dist/Tree.js +59 -0
- package/dist/Window.d.ts +9 -3
- package/dist/Window.js +7 -5
- package/dist/fieldName.d.ts +4 -0
- package/dist/fieldName.js +9 -0
- package/dist/glyphs.d.ts +1 -0
- package/dist/glyphs.js +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +12 -0
- package/package.json +2 -2
package/dist/Tree.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createElement as _createElement } from "react";
|
|
3
|
+
import { useEffect, useRef, useState } from "react";
|
|
4
|
+
import { focusTreeRow, treeRows, treeStep } from "@glimstone/core";
|
|
5
|
+
import { IconExpand } from "./glyphs.js";
|
|
6
|
+
export function Tree({ label, load, value, onChange, onActivate, open, onOpenChange, defaultOpen = [] }) {
|
|
7
|
+
const [ownOpen, setOwnOpen] = useState(defaultOpen);
|
|
8
|
+
const opened = open ?? ownOpen;
|
|
9
|
+
const [children, setChildren] = useState(new Map());
|
|
10
|
+
const asked = useRef(new Set());
|
|
11
|
+
const tree = useRef(null);
|
|
12
|
+
// The ids stand in for `opened` in the deps, since a caller may rebuild the array on every render.
|
|
13
|
+
const openKey = opened.join("\n");
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
for (const id of [null, ...opened]) {
|
|
16
|
+
if (asked.current.has(id))
|
|
17
|
+
continue;
|
|
18
|
+
asked.current.add(id);
|
|
19
|
+
Promise.resolve(load(id)).then((nodes) => setChildren((known) => new Map(known).set(id, nodes)), () => asked.current.delete(id));
|
|
20
|
+
}
|
|
21
|
+
}, [openKey]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
22
|
+
const rows = treeRows(children, opened);
|
|
23
|
+
const stop = Math.max(rows.findIndex((r) => r.node.id === value), 0);
|
|
24
|
+
function toggle(id) {
|
|
25
|
+
const next = opened.includes(id) ? opened.filter((o) => o !== id) : [...opened, id];
|
|
26
|
+
setOwnOpen(next);
|
|
27
|
+
onOpenChange?.(next);
|
|
28
|
+
}
|
|
29
|
+
function keys(e, at) {
|
|
30
|
+
if (e.ctrlKey || e.metaKey || e.altKey)
|
|
31
|
+
return;
|
|
32
|
+
const id = rows[at].node.id;
|
|
33
|
+
if (e.key === " " || e.key === "Enter") {
|
|
34
|
+
e.preventDefault();
|
|
35
|
+
onChange(id);
|
|
36
|
+
if (e.key === "Enter")
|
|
37
|
+
onActivate?.(id);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const step = treeStep(rows, at, e.key, getComputedStyle(tree.current).direction === "rtl");
|
|
41
|
+
if (!step)
|
|
42
|
+
return;
|
|
43
|
+
e.preventDefault();
|
|
44
|
+
if ("focus" in step) {
|
|
45
|
+
onChange(step.focus);
|
|
46
|
+
focusTreeRow(tree.current, step.focus);
|
|
47
|
+
}
|
|
48
|
+
else
|
|
49
|
+
toggle("open" in step ? step.open : step.close);
|
|
50
|
+
}
|
|
51
|
+
return (_jsx("div", { ref: tree, role: "tree", "aria-label": label, className: "glim-tree", children: rows.map((r, i) => (_createElement("div", { ...r.node.attrs, key: r.node.id, role: "treeitem", "aria-level": r.level, "aria-posinset": r.position, "aria-setsize": r.siblings, "aria-expanded": r.node.hasChildren ? r.open : undefined, "aria-selected": r.node.id === value, tabIndex: i === stop ? 0 : -1, "data-tree-id": r.node.id, className: "glim-tree-row", style: { "--tree-level": r.level - 1 }, onClick: () => onChange(r.node.id), onDoubleClick: () => onActivate?.(r.node.id), onKeyDown: (e) => keys(e, i) },
|
|
52
|
+
_jsx("span", { className: "glim-tree-toggle", "aria-hidden": "true", onClick: (e) => {
|
|
53
|
+
e.stopPropagation();
|
|
54
|
+
if (r.node.hasChildren)
|
|
55
|
+
toggle(r.node.id);
|
|
56
|
+
}, onDoubleClick: (e) => e.stopPropagation(), children: r.node.hasChildren && _jsx(IconExpand, {}) }),
|
|
57
|
+
r.node.glyph && (_jsx("span", { className: "glim-tree-glyph", "aria-hidden": "true", children: (r.open && r.node.openGlyph) || r.node.glyph })),
|
|
58
|
+
_jsx("span", { className: "glim-tree-label", children: r.node.label })))) }));
|
|
59
|
+
}
|
package/dist/Window.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ReactNode } from "react";
|
|
1
|
+
import { type HTMLAttributes, type ReactNode, type Ref } from "react";
|
|
2
2
|
import { type WindowSize } from "@glimstone/core";
|
|
3
3
|
export type { WindowSize } from "@glimstone/core";
|
|
4
4
|
export interface WindowAction {
|
|
@@ -11,12 +11,16 @@ export interface WindowAction {
|
|
|
11
11
|
/** This action already leaves the window, such as Done, so no Cancel or Close is added. */
|
|
12
12
|
wayOut?: boolean;
|
|
13
13
|
disabled?: boolean;
|
|
14
|
+
/** Attributes for the action's button, such as a data hook. */
|
|
15
|
+
attrs?: Record<string, string>;
|
|
14
16
|
/** Runs on press. The window closes afterwards unless it returns false. */
|
|
15
17
|
onClick?: () => void | false;
|
|
16
18
|
}
|
|
17
|
-
export interface WindowProps {
|
|
19
|
+
export interface WindowProps extends Omit<HTMLAttributes<HTMLDivElement>, "title" | "children"> {
|
|
18
20
|
/** The notch's words, also the window's accessible name. */
|
|
19
21
|
title: string;
|
|
22
|
+
/** Takes the words' place in the notch with markup, such as a count. `title` alone stays the name. */
|
|
23
|
+
drawn?: ReactNode;
|
|
20
24
|
children: ReactNode;
|
|
21
25
|
/** The foot's buttons, in reading order. Cancel or Close is added before
|
|
22
26
|
* them unless one of them is a way out itself. */
|
|
@@ -33,5 +37,7 @@ export interface WindowProps {
|
|
|
33
37
|
/** Called for every way out: the foot, Escape and a press beside the window. */
|
|
34
38
|
onClose: () => void;
|
|
35
39
|
className?: string;
|
|
40
|
+
/** The card element. */
|
|
41
|
+
ref?: Ref<HTMLDivElement>;
|
|
36
42
|
}
|
|
37
|
-
export declare function Window({ title, children, actions, start, size, text, onClose, className }: WindowProps): import("react").ReactPortal;
|
|
43
|
+
export declare function Window({ title, drawn, children, actions, start, size, text, onClose, className, ref, ...rest }: WindowProps): import("react").ReactPortal;
|
package/dist/Window.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
|
+
import { createElement as _createElement } from "react";
|
|
1
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
3
|
// The general window: a notch with the title, a body for anything and a foot
|
|
3
4
|
// whose actions stand at the end. It owns the portal, its place on the stack,
|
|
4
5
|
// Escape, the Tab trap and the focus, so a caller only mounts it and unmounts
|
|
5
|
-
// it on onClose.
|
|
6
|
-
import { useId, useLayoutEffect, useRef, useState } from "react";
|
|
6
|
+
// it on onClose. The other props of a <div> go to the card.
|
|
7
|
+
import { useId, useImperativeHandle, useLayoutEffect, useRef, useState } from "react";
|
|
7
8
|
import { createPortal } from "react-dom";
|
|
8
9
|
import { focusedAsker, menuIsOpen, returnFocus, stackWindow, windowFocusTarget, windowFoot, } from "@glimstone/core";
|
|
9
10
|
import { Badge } from "./Badge.js";
|
|
10
11
|
import { Button } from "./Button.js";
|
|
11
12
|
import { IconCancel, IconClose } from "./glyphs.js";
|
|
12
|
-
export function Window({ title, children, actions = [], start, size = "normal", text, onClose, className }) {
|
|
13
|
+
export function Window({ title, drawn, children, actions = [], start, size = "normal", text, onClose, className, ref, ...rest }) {
|
|
13
14
|
const card = useRef(null);
|
|
15
|
+
useImperativeHandle(ref, () => card.current);
|
|
14
16
|
const titleId = useId();
|
|
15
17
|
// Read before the window takes the focus.
|
|
16
18
|
const [asker] = useState(focusedAsker);
|
|
@@ -36,8 +38,8 @@ export function Window({ title, children, actions = [], start, size = "normal",
|
|
|
36
38
|
onMouseDown: (e) => {
|
|
37
39
|
if (e.target === e.currentTarget && !menuIsOpen())
|
|
38
40
|
close.current();
|
|
39
|
-
}, children: _jsxs("div", { ref: card, role: "dialog", "aria-modal": "true", "aria-labelledby": titleId, className: ["glim-modal-card", "glim-window", size !== "normal" && `glim-window--${size}`, className].filter(Boolean).join(" "), children: [_jsx("h2", { id: titleId, className: "glim-window-title", children: _jsx(Badge, { tone: "heading", size: "heading", wrap: true, insetStart: 5, children: title }) }), _jsx("div", { className: "glim-modal-body glim-window-body", children: children }), foot.length > 0 && (_jsxs("div", { className: "glim-modal-foot", children: [start !== undefined && _jsx("span", { className: "glim-window-start", children: start }), foot.map((a, i) => (
|
|
41
|
+
}, children: _jsxs("div", { ...rest, ref: card, role: "dialog", "aria-modal": "true", "aria-labelledby": drawn ? undefined : titleId, "aria-label": drawn ? title : undefined, className: ["glim-modal-card", "glim-window", size !== "normal" && `glim-window--${size}`, className].filter(Boolean).join(" "), children: [_jsx("h2", { id: titleId, className: "glim-window-title", children: _jsx(Badge, { tone: "heading", size: "heading", wrap: true, insetStart: 5, children: drawn ?? title }) }), _jsx("div", { className: "glim-modal-body glim-window-body", children: children }), foot.length > 0 && (_jsxs("div", { className: "glim-modal-foot", children: [start !== undefined && _jsx("span", { className: "glim-window-start", children: start }), foot.map((a, i) => (_createElement(Button, { ...a.attrs, key: i, label: a.label, labelKey: a.labelKey, glyph: a.glyph, tone: a.primary ? "accent" : "neutral", disabled: a.disabled, onClick: () => {
|
|
40
42
|
if (a.onClick?.() !== false)
|
|
41
43
|
close.current();
|
|
42
|
-
} }
|
|
44
|
+
} })))] }))] }) }), document.body);
|
|
43
45
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const FieldRowContext: import("react").Context<string | undefined>;
|
|
2
|
+
export declare const FieldRowGroupContext: import("react").Context<boolean>;
|
|
3
|
+
/** A control's accessible name: its own, or the label of the row it stands in. */
|
|
4
|
+
export declare function useFieldName(own: string | undefined): string | undefined;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// How a FieldRow names the control inside it.
|
|
2
|
+
import { createContext, useContext } from "react";
|
|
3
|
+
export const FieldRowContext = createContext(undefined);
|
|
4
|
+
export const FieldRowGroupContext = createContext(false);
|
|
5
|
+
/** A control's accessible name: its own, or the label of the row it stands in. */
|
|
6
|
+
export function useFieldName(own) {
|
|
7
|
+
const row = useContext(FieldRowContext);
|
|
8
|
+
return own ?? row;
|
|
9
|
+
}
|
package/dist/glyphs.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export declare const IconClose: () => import("react").JSX.Element;
|
|
|
17
17
|
export declare const IconCancel: () => import("react").JSX.Element;
|
|
18
18
|
export declare const IconCheck: () => import("react").JSX.Element;
|
|
19
19
|
export declare const IconExpand: () => import("react").JSX.Element;
|
|
20
|
+
export declare const IconFolderOpen: () => import("react").JSX.Element;
|
|
20
21
|
export declare const IconPencil: () => import("react").JSX.Element;
|
|
21
22
|
export declare const IconWindowMinimise: () => import("react").JSX.Element;
|
|
22
23
|
export declare const IconWindowMaximise: () => import("react").JSX.Element;
|
package/dist/glyphs.js
CHANGED
|
@@ -25,6 +25,7 @@ export const IconClose = () => _jsx(MarkSvg, { mark: MARKS.close, className: "gl
|
|
|
25
25
|
export const IconCancel = () => _jsx(MarkSvg, { mark: MARKS.cancel, className: "glim-mark" });
|
|
26
26
|
export const IconCheck = () => _jsx(MarkSvg, { mark: MARKS.check, className: "glim-mark" });
|
|
27
27
|
export const IconExpand = () => _jsx(MarkSvg, { mark: MARKS.expand, className: "glim-mark" });
|
|
28
|
+
export const IconFolderOpen = () => _jsx(MarkSvg, { mark: MARKS.folderOpen, className: "glim-mark" });
|
|
28
29
|
export const IconPencil = () => _jsx(MarkSvg, { mark: MARKS.pencil, className: "glim-mark" });
|
|
29
30
|
export const IconWindowMinimise = () => _jsx(MarkSvg, { mark: MARKS.windowMinimise, className: "glim-mark" });
|
|
30
31
|
export const IconWindowMaximise = () => _jsx(MarkSvg, { mark: MARKS.windowMaximise, className: "glim-mark" });
|
package/dist/index.d.ts
CHANGED
|
@@ -11,22 +11,34 @@ export * from "./CopyField.tsx";
|
|
|
11
11
|
export * from "./CryptoDonateDialog.tsx";
|
|
12
12
|
export * from "./DropdownListbox.tsx";
|
|
13
13
|
export * from "./EmptyState.tsx";
|
|
14
|
+
export * from "./FieldRow.tsx";
|
|
15
|
+
export * from "./FieldRowGroup.tsx";
|
|
16
|
+
export * from "./GlyphField.tsx";
|
|
17
|
+
export * from "./GlyphTile.tsx";
|
|
18
|
+
export { useFieldName } from "./fieldName.ts";
|
|
19
|
+
export * from "./IconButton.tsx";
|
|
14
20
|
export * from "./IconTipButton.tsx";
|
|
15
21
|
export * from "./InfoBubble.tsx";
|
|
16
22
|
export * from "./Kbd.tsx";
|
|
23
|
+
export * from "./ListRow.tsx";
|
|
17
24
|
export * from "./MenuBar.tsx";
|
|
18
25
|
export * from "./Meter.tsx";
|
|
19
26
|
export * from "./NumberField.tsx";
|
|
20
27
|
export * from "./PasswordField.tsx";
|
|
28
|
+
export * from "./PathField.tsx";
|
|
21
29
|
export * from "./PaypalDialog.tsx";
|
|
22
30
|
export * from "./Pill.tsx";
|
|
23
31
|
export * from "./ProgressBar.tsx";
|
|
24
32
|
export * from "./ReadmeButton.tsx";
|
|
33
|
+
export * from "./RowMark.tsx";
|
|
25
34
|
export * from "./Selector.tsx";
|
|
26
35
|
export * from "./SidebarRow.tsx";
|
|
27
36
|
export * from "./SubCard.tsx";
|
|
37
|
+
export * from "./Table.tsx";
|
|
38
|
+
export * from "./TextField.tsx";
|
|
28
39
|
export * from "./Toast.tsx";
|
|
29
40
|
export * from "./Toggle.tsx";
|
|
41
|
+
export * from "./Tree.tsx";
|
|
30
42
|
export * from "./UnavailableNotice.tsx";
|
|
31
43
|
export * from "./Window.tsx";
|
|
32
44
|
export * from "./WindowBar.tsx";
|
|
@@ -36,4 +48,5 @@ export * from "./useConfirm.tsx";
|
|
|
36
48
|
export * from "./useLabelMode.ts";
|
|
37
49
|
export * from "./usePaypalButtons.ts";
|
|
38
50
|
export * from "./useTipBubble.tsx";
|
|
51
|
+
export type { ToastAction } from "@glimstone/core";
|
|
39
52
|
export { GLIMSTONE_VERSION } from "@glimstone/core";
|
package/dist/index.js
CHANGED
|
@@ -11,22 +11,34 @@ export * from "./CopyField.js";
|
|
|
11
11
|
export * from "./CryptoDonateDialog.js";
|
|
12
12
|
export * from "./DropdownListbox.js";
|
|
13
13
|
export * from "./EmptyState.js";
|
|
14
|
+
export * from "./FieldRow.js";
|
|
15
|
+
export * from "./FieldRowGroup.js";
|
|
16
|
+
export * from "./GlyphField.js";
|
|
17
|
+
export * from "./GlyphTile.js";
|
|
18
|
+
export { useFieldName } from "./fieldName.js";
|
|
19
|
+
export * from "./IconButton.js";
|
|
14
20
|
export * from "./IconTipButton.js";
|
|
15
21
|
export * from "./InfoBubble.js";
|
|
16
22
|
export * from "./Kbd.js";
|
|
23
|
+
export * from "./ListRow.js";
|
|
17
24
|
export * from "./MenuBar.js";
|
|
18
25
|
export * from "./Meter.js";
|
|
19
26
|
export * from "./NumberField.js";
|
|
20
27
|
export * from "./PasswordField.js";
|
|
28
|
+
export * from "./PathField.js";
|
|
21
29
|
export * from "./PaypalDialog.js";
|
|
22
30
|
export * from "./Pill.js";
|
|
23
31
|
export * from "./ProgressBar.js";
|
|
24
32
|
export * from "./ReadmeButton.js";
|
|
33
|
+
export * from "./RowMark.js";
|
|
25
34
|
export * from "./Selector.js";
|
|
26
35
|
export * from "./SidebarRow.js";
|
|
27
36
|
export * from "./SubCard.js";
|
|
37
|
+
export * from "./Table.js";
|
|
38
|
+
export * from "./TextField.js";
|
|
28
39
|
export * from "./Toast.js";
|
|
29
40
|
export * from "./Toggle.js";
|
|
41
|
+
export * from "./Tree.js";
|
|
30
42
|
export * from "./UnavailableNotice.js";
|
|
31
43
|
export * from "./Window.js";
|
|
32
44
|
export * from "./WindowBar.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glimstone/react",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.2",
|
|
4
4
|
"description": "GlimStone's components for React",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"repository": { "type": "git", "url": "git+https://github.com/junkerderprovinz/glimstone.git", "directory": "packages/react" },
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"build": "tsc -p tsconfig.build.json"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@glimstone/core": "4.1.
|
|
19
|
+
"@glimstone/core": "4.1.2"
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
22
|
"@zag-js/combobox": "^1.46.0",
|