@adecore/ui 0.16.0-beta.0 → 0.17.0-beta.1
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/dist/file-tree/helpers.d.ts +42 -0
- package/dist/file-tree/helpers.js +167 -0
- package/dist/file-tree/index.parts.d.ts +3 -0
- package/dist/file-tree/index.parts.js +3 -0
- package/dist/file-tree/parts.d.ts +20 -0
- package/dist/file-tree/parts.js +150 -0
- package/dist/file-tree/shift.d.ts +15 -0
- package/dist/file-tree/shift.js +35 -0
- package/dist/file-tree/style.d.ts +1 -0
- package/dist/file-tree/style.js +25 -0
- package/dist/file-tree/use-file-tree-shift.d.ts +6 -0
- package/dist/file-tree/use-file-tree-shift.js +143 -0
- package/dist/file-tree/use-file-tree.d.ts +5 -0
- package/dist/file-tree/use-file-tree.js +26 -0
- package/dist/file-tree/use-slots.d.ts +7 -0
- package/dist/file-tree/use-slots.js +171 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +3 -0
- package/dist/locales/en.json +5 -0
- package/dist/locales/nl.json +5 -0
- package/dist/theme.css +103 -0
- package/dist/tree/index.parts.d.ts +1 -0
- package/dist/tree/index.parts.js +1 -0
- package/dist/tree/parts.d.ts +27 -0
- package/dist/tree/parts.js +113 -0
- package/dist/tree/style.d.ts +2 -0
- package/dist/tree/style.js +29 -0
- package/package.json +6 -4
- package/src/file-tree/LICENSE +110 -0
- package/src/file-tree/helpers.ts +204 -0
- package/src/file-tree/index.parts.ts +25 -0
- package/src/file-tree/parts.tsx +206 -0
- package/src/file-tree/shift.ts +49 -0
- package/src/file-tree/style.ts +26 -0
- package/src/file-tree/use-file-tree-shift.tsx +170 -0
- package/src/file-tree/use-file-tree.ts +31 -0
- package/src/file-tree/use-slots.ts +191 -0
- package/src/index.ts +17 -0
- package/src/locales/en.json +5 -0
- package/src/locales/nl.json +5 -0
- package/src/theme.css +103 -0
- package/src/tree/index.parts.ts +10 -0
- package/src/tree/parts.tsx +170 -0
- package/src/tree/style.ts +30 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { useEffect, useId, useState } from 'react';
|
|
2
|
+
import { pathOfRow, visibleRows } from './helpers.js';
|
|
3
|
+
import { FILE_TREE_CSS } from './style.js';
|
|
4
|
+
// beta.6 owns button rows. Sibling slots keep real controls outside those buttons and in the app's stylesheet.
|
|
5
|
+
export function useFileTreeSlots(model, frame, label) {
|
|
6
|
+
const prefix = useId().replaceAll(':', '');
|
|
7
|
+
const [slots, setSlots] = useState([]);
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
if (frame === null) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const ports = new Map();
|
|
13
|
+
let shadow = null;
|
|
14
|
+
let style = null;
|
|
15
|
+
let serial = 0;
|
|
16
|
+
let disposed = false;
|
|
17
|
+
let pending = false;
|
|
18
|
+
let snapshot = null;
|
|
19
|
+
const position = () => {
|
|
20
|
+
for (const port of ports.values()) {
|
|
21
|
+
const row = port.rowElement;
|
|
22
|
+
const content = row.querySelector('[data-item-section="content"]');
|
|
23
|
+
const icon = row.querySelector('[data-item-section="icon"]');
|
|
24
|
+
const control = port.lightControl;
|
|
25
|
+
const decoration = port.lightDecoration;
|
|
26
|
+
const controlSpace = control.childNodes.length > 0 ? Math.ceil(control.getBoundingClientRect().width) + 6 : 0;
|
|
27
|
+
const decorationSpace = decoration.childNodes.length > 0 ? Math.ceil(decoration.getBoundingClientRect().width) + 6 : 0;
|
|
28
|
+
row.style.setProperty('--adecore-tree-control-space', `${controlSpace}px`);
|
|
29
|
+
row.style.setProperty('--adecore-tree-decoration-space', `${decorationSpace}px`);
|
|
30
|
+
port.control.style.top = `${row.offsetTop}px`;
|
|
31
|
+
port.control.style.left = `${row.offsetLeft + (icon?.offsetLeft ?? 4) - controlSpace}px`;
|
|
32
|
+
port.decoration.style.top = `${row.offsetTop}px`;
|
|
33
|
+
port.decoration.style.left = `${row.offsetLeft + (content === null ? row.offsetWidth - decorationSpace - 2 : content.offsetLeft + content.offsetWidth + 6)}px`;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
const resize = new ResizeObserver(position);
|
|
37
|
+
const scan = () => {
|
|
38
|
+
pending = false;
|
|
39
|
+
if (disposed) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const current = model.getFileTreeContainer();
|
|
43
|
+
if (!current?.shadowRoot) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (shadow !== current.shadowRoot) {
|
|
47
|
+
shadow = current.shadowRoot;
|
|
48
|
+
style = document.createElement('style');
|
|
49
|
+
style.dataset.adecoreTreeStyle = 'true';
|
|
50
|
+
style.textContent = FILE_TREE_CSS;
|
|
51
|
+
shadow.append(style);
|
|
52
|
+
changes.observe(shadow, {
|
|
53
|
+
childList: true,
|
|
54
|
+
subtree: true,
|
|
55
|
+
attributes: true,
|
|
56
|
+
attributeFilter: ['data-item-path', 'aria-selected', 'aria-expanded']
|
|
57
|
+
});
|
|
58
|
+
changes.observe(current, { childList: true, subtree: true });
|
|
59
|
+
resize.observe(current);
|
|
60
|
+
}
|
|
61
|
+
shadow.querySelector('[role="tree"]')?.setAttribute('aria-label', label);
|
|
62
|
+
const rows = visibleRows(model);
|
|
63
|
+
const byPath = new Map(rows.map((row) => [pathOfRow(row), row]));
|
|
64
|
+
const elements = [
|
|
65
|
+
...shadow.querySelectorAll('[data-type="item"]:not([data-item-parked="true"]):not([data-file-tree-sticky-row="true"])')
|
|
66
|
+
];
|
|
67
|
+
const live = new Set(elements);
|
|
68
|
+
for (const [element, port] of ports) {
|
|
69
|
+
if (!live.has(element)) {
|
|
70
|
+
port.control.remove();
|
|
71
|
+
port.decoration.remove();
|
|
72
|
+
resize.unobserve(port.lightControl);
|
|
73
|
+
resize.unobserve(port.lightDecoration);
|
|
74
|
+
port.lightControl.remove();
|
|
75
|
+
port.lightDecoration.remove();
|
|
76
|
+
ports.delete(element);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const next = [];
|
|
80
|
+
for (const element of elements) {
|
|
81
|
+
const path = element.dataset.itemPath;
|
|
82
|
+
const row = path === undefined ? undefined : byPath.get(path);
|
|
83
|
+
if (row === undefined) {
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
element.dataset.interactive = 'true';
|
|
87
|
+
element.dataset.joinedStart = String(row.isSelected && rows[row.index - 1]?.isSelected === true);
|
|
88
|
+
element.dataset.joinedEnd = String(row.isSelected && rows[row.index + 1]?.isSelected === true);
|
|
89
|
+
let port = ports.get(element);
|
|
90
|
+
if (port === undefined) {
|
|
91
|
+
const makePort = (kind) => {
|
|
92
|
+
const container = document.createElement('span');
|
|
93
|
+
container.dataset.treePort = kind;
|
|
94
|
+
const slot = document.createElement('slot');
|
|
95
|
+
slot.name = `${prefix}-${kind}-${serial}`;
|
|
96
|
+
container.append(slot);
|
|
97
|
+
element.parentElement?.append(container);
|
|
98
|
+
const target = document.createElement('span');
|
|
99
|
+
target.slot = slot.name;
|
|
100
|
+
target.dataset.treeSlot = kind;
|
|
101
|
+
target.className = kind === 'control' ? 'adecore-tree-control' : 'adecore-tree-decoration';
|
|
102
|
+
// React delegates to this portal target before the event reaches the engine's shadow tree.
|
|
103
|
+
for (const type of ['click', 'dblclick', 'keydown', 'keyup', 'pointerdown', 'dragstart']) {
|
|
104
|
+
target.addEventListener(type, (event) => event.stopPropagation());
|
|
105
|
+
}
|
|
106
|
+
current.append(target);
|
|
107
|
+
resize.observe(target);
|
|
108
|
+
return { container, target };
|
|
109
|
+
};
|
|
110
|
+
serial++;
|
|
111
|
+
const control = makePort('control');
|
|
112
|
+
const decoration = makePort('decoration');
|
|
113
|
+
port = {
|
|
114
|
+
rowElement: element,
|
|
115
|
+
control: control.container,
|
|
116
|
+
decoration: decoration.container,
|
|
117
|
+
lightControl: control.target,
|
|
118
|
+
lightDecoration: decoration.target
|
|
119
|
+
};
|
|
120
|
+
ports.set(element, port);
|
|
121
|
+
}
|
|
122
|
+
if (port.control.dataset.itemPath !== row.path) {
|
|
123
|
+
port.control.dataset.itemPath = row.path;
|
|
124
|
+
}
|
|
125
|
+
if (port.decoration.dataset.itemPath !== row.path) {
|
|
126
|
+
port.decoration.dataset.itemPath = row.path;
|
|
127
|
+
}
|
|
128
|
+
port.lightControl.dataset.itemPath = row.path;
|
|
129
|
+
port.lightDecoration.dataset.itemPath = row.path;
|
|
130
|
+
next.push({ row, control: port.lightControl, decoration: port.lightDecoration });
|
|
131
|
+
}
|
|
132
|
+
const key = next
|
|
133
|
+
.map(({ row, control }) => `${control.slot}:${row.path}:${row.isSelected}:${row.isExpanded}:${row.isFocused}:${row.name}`)
|
|
134
|
+
.join('|');
|
|
135
|
+
if (snapshot !== key) {
|
|
136
|
+
snapshot = key;
|
|
137
|
+
setSlots(next);
|
|
138
|
+
}
|
|
139
|
+
position();
|
|
140
|
+
};
|
|
141
|
+
const schedule = () => {
|
|
142
|
+
if (!pending && !disposed) {
|
|
143
|
+
pending = true;
|
|
144
|
+
queueMicrotask(scan);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
const shifts = new MutationObserver(position);
|
|
148
|
+
shifts.observe(frame, { attributes: true, attributeFilter: ['style'] });
|
|
149
|
+
const changes = new MutationObserver(schedule);
|
|
150
|
+
changes.observe(frame, { childList: true, subtree: true });
|
|
151
|
+
const unsubscribe = model.subscribe(schedule);
|
|
152
|
+
schedule();
|
|
153
|
+
return () => {
|
|
154
|
+
disposed = true;
|
|
155
|
+
unsubscribe();
|
|
156
|
+
changes.disconnect();
|
|
157
|
+
shifts.disconnect();
|
|
158
|
+
resize.disconnect();
|
|
159
|
+
style?.remove();
|
|
160
|
+
for (const port of ports.values()) {
|
|
161
|
+
port.rowElement.style.removeProperty('--adecore-tree-control-space');
|
|
162
|
+
port.rowElement.style.removeProperty('--adecore-tree-decoration-space');
|
|
163
|
+
port.control.remove();
|
|
164
|
+
port.decoration.remove();
|
|
165
|
+
port.lightControl.remove();
|
|
166
|
+
port.lightDecoration.remove();
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
}, [frame, model, label, prefix]);
|
|
170
|
+
return slots;
|
|
171
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export * as ContextMenu from './context-menu/index.parts.ts';
|
|
2
|
+
export * as FileTree from './file-tree/index.parts.ts';
|
|
3
|
+
export * as Tree from './tree/index.parts.ts';
|
|
2
4
|
export * as Dialog from './dialog/index.parts.ts';
|
|
3
5
|
export * as KeyValueList from './key-value-list/index.parts.ts';
|
|
4
6
|
export * as Menu from './menu/index.parts.ts';
|
|
@@ -76,3 +78,8 @@ export { useContentSize, type ContentSize } from './useContentSize.ts';
|
|
|
76
78
|
export { useMeasuredWidth } from './useMeasuredWidth.ts';
|
|
77
79
|
export { useNow, useTickingText } from './useNow.ts';
|
|
78
80
|
export { ZOOM_PRESETS } from './zoom.ts';
|
|
81
|
+
export { useFileTree, type FileTreeOptions } from './file-tree/use-file-tree.ts';
|
|
82
|
+
export type { FileTreeRootProps } from './file-tree/parts.tsx';
|
|
83
|
+
export type { FileTree as FileTreeModel, FileTreeVisibleRow, FileTreeDragAndDropConfig, FileTreeDropContext, FileTreeDropResult } from '@pierre/trees';
|
|
84
|
+
export type { FoldKeyOf, SortRow } from './file-tree/helpers.ts';
|
|
85
|
+
export type { TreeRootProps, TreeRowProps, TreeChevronProps, TreeChevronSlotProps, TreeLabelProps, TreeDecorationProps, TreeControlProps, TreeCheckboxProps } from './tree/parts.tsx';
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
* `exports.test.ts` turns any change to this list into a diff someone has to accept.
|
|
4
4
|
*/
|
|
5
5
|
export * as ContextMenu from './context-menu/index.parts.js';
|
|
6
|
+
export * as FileTree from './file-tree/index.parts.js';
|
|
7
|
+
export * as Tree from './tree/index.parts.js';
|
|
6
8
|
export * as Dialog from './dialog/index.parts.js';
|
|
7
9
|
export * as KeyValueList from './key-value-list/index.parts.js';
|
|
8
10
|
export * as Menu from './menu/index.parts.js';
|
|
@@ -74,3 +76,4 @@ export { useContentSize } from './useContentSize.js';
|
|
|
74
76
|
export { useMeasuredWidth } from './useMeasuredWidth.js';
|
|
75
77
|
export { useNow, useTickingText } from './useNow.js';
|
|
76
78
|
export { ZOOM_PRESETS } from './zoom.js';
|
|
79
|
+
export { useFileTree } from './file-tree/use-file-tree.js';
|
package/dist/locales/en.json
CHANGED
package/dist/locales/nl.json
CHANGED
package/dist/theme.css
CHANGED
|
@@ -563,3 +563,106 @@
|
|
|
563
563
|
.sliding-column[data-resizing],
|
|
564
564
|
.sliding-column[data-instant] { transition: none; }
|
|
565
565
|
}
|
|
566
|
+
|
|
567
|
+
@layer components {
|
|
568
|
+
.adecore-tree {
|
|
569
|
+
--tree-row-height: 25px;
|
|
570
|
+
--tree-row-gap: 6px;
|
|
571
|
+
--tree-row-radius: 6px;
|
|
572
|
+
--trees-bg-override: transparent;
|
|
573
|
+
--trees-padding-inline-override: 8px;
|
|
574
|
+
--trees-bg-muted-override: var(--surface-hover);
|
|
575
|
+
--trees-fg-override: var(--text);
|
|
576
|
+
--trees-fg-muted-override: var(--text-muted);
|
|
577
|
+
--trees-selected-bg-override: var(--surface-active);
|
|
578
|
+
--trees-selected-fg-override: var(--text);
|
|
579
|
+
--trees-border-color-override: var(--border);
|
|
580
|
+
--trees-accent-override: var(--accent);
|
|
581
|
+
--trees-focus-ring-color-override: var(--accent);
|
|
582
|
+
--trees-selected-focused-border-color-override: var(--accent);
|
|
583
|
+
--trees-status-ignored-override: var(--text-faint);
|
|
584
|
+
--trees-git-ignored-color-override: var(--text-faint);
|
|
585
|
+
--trees-git-modified-color-override: var(--status-needs-you);
|
|
586
|
+
--trees-git-added-color-override: var(--status-idle);
|
|
587
|
+
--trees-git-untracked-color-override: var(--status-idle);
|
|
588
|
+
--trees-git-deleted-color-override: var(--status-error);
|
|
589
|
+
--trees-git-renamed-color-override: var(--status-running);
|
|
590
|
+
--trees-font-family-override: var(--font-sans);
|
|
591
|
+
--trees-font-size-override: var(--text-xs);
|
|
592
|
+
}
|
|
593
|
+
.adecore-tree-row {
|
|
594
|
+
margin-inline: 8px;
|
|
595
|
+
padding-inline-end: 8px;
|
|
596
|
+
}
|
|
597
|
+
.adecore-tree-guide {
|
|
598
|
+
pointer-events: none;
|
|
599
|
+
position: absolute;
|
|
600
|
+
inset-block: 0;
|
|
601
|
+
width: 1px;
|
|
602
|
+
background: var(--border);
|
|
603
|
+
}
|
|
604
|
+
.adecore-tree-chevron-slot {
|
|
605
|
+
display: grid;
|
|
606
|
+
place-items: center;
|
|
607
|
+
flex: none;
|
|
608
|
+
width: 16px;
|
|
609
|
+
height: 16px;
|
|
610
|
+
padding: 0;
|
|
611
|
+
border: 0;
|
|
612
|
+
background: transparent;
|
|
613
|
+
color: var(--text-muted);
|
|
614
|
+
}
|
|
615
|
+
.adecore-tree-label {
|
|
616
|
+
min-width: 0;
|
|
617
|
+
overflow: hidden;
|
|
618
|
+
text-overflow: ellipsis;
|
|
619
|
+
white-space: nowrap;
|
|
620
|
+
}
|
|
621
|
+
.adecore-tree-control,
|
|
622
|
+
.adecore-tree-decoration {
|
|
623
|
+
display: inline-flex;
|
|
624
|
+
flex: none;
|
|
625
|
+
align-items: center;
|
|
626
|
+
gap: 6px;
|
|
627
|
+
}
|
|
628
|
+
.adecore-tree-decoration {
|
|
629
|
+
font-variant-numeric: tabular-nums;
|
|
630
|
+
}
|
|
631
|
+
.adecore-file-tree {
|
|
632
|
+
position: relative;
|
|
633
|
+
min-height: 0;
|
|
634
|
+
overflow: hidden;
|
|
635
|
+
}
|
|
636
|
+
.adecore-file-tree-host {
|
|
637
|
+
display: block;
|
|
638
|
+
height: 100%;
|
|
639
|
+
}
|
|
640
|
+
.adecore-tree-shift {
|
|
641
|
+
pointer-events: none;
|
|
642
|
+
position: sticky;
|
|
643
|
+
bottom: 0;
|
|
644
|
+
height: 0;
|
|
645
|
+
}
|
|
646
|
+
.adecore-tree-shift-track {
|
|
647
|
+
position: absolute;
|
|
648
|
+
inset-inline: 8px;
|
|
649
|
+
bottom: 2px;
|
|
650
|
+
height: 6px;
|
|
651
|
+
opacity: 0;
|
|
652
|
+
transition: opacity 150ms ease-out;
|
|
653
|
+
}
|
|
654
|
+
.adecore-tree-shift-track[data-visible] {
|
|
655
|
+
opacity: 1;
|
|
656
|
+
}
|
|
657
|
+
.adecore-tree-shift-thumb {
|
|
658
|
+
position: absolute;
|
|
659
|
+
inset-block: 0;
|
|
660
|
+
border-radius: 999px;
|
|
661
|
+
background: var(--text-faint);
|
|
662
|
+
}
|
|
663
|
+
@media (prefers-reduced-motion: reduce) {
|
|
664
|
+
.adecore-tree-shift-track {
|
|
665
|
+
transition: none;
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { TreeRoot as Root, TreeRow as Row, TreeChevron as Chevron, TreeChevronSlot as ChevronSlot, TreeLabel as Label, TreeDecoration as Decoration, TreeControl as Control, TreeCheckbox as Checkbox } from './parts.tsx';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { TreeRoot as Root, TreeRow as Row, TreeChevron as Chevron, TreeChevronSlot as ChevronSlot, TreeLabel as Label, TreeDecoration as Decoration, TreeControl as Control, TreeCheckbox as Checkbox } from './parts.js';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useRender } from '@base-ui-components/react/use-render';
|
|
2
|
+
import { type CheckboxProps } from '../Checkbox.tsx';
|
|
3
|
+
export type TreeRootProps = useRender.ComponentProps<'div'>;
|
|
4
|
+
export declare function TreeRoot({ render, className, ref, children, ...props }: TreeRootProps): import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
5
|
+
export type TreeRowProps = useRender.ComponentProps<'div'> & {
|
|
6
|
+
level?: number;
|
|
7
|
+
selected?: boolean;
|
|
8
|
+
joinedStart?: boolean;
|
|
9
|
+
joinedEnd?: boolean;
|
|
10
|
+
interactive?: boolean;
|
|
11
|
+
};
|
|
12
|
+
export declare function TreeRow({ level, selected, joinedStart, joinedEnd, interactive, render, className, ref, style, children, ...props }: TreeRowProps): import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
13
|
+
export type TreeChevronSlotProps = useRender.ComponentProps<'span'>;
|
|
14
|
+
export declare function TreeChevronSlot({ render, className, ref, ...props }: TreeChevronSlotProps): import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
15
|
+
export type TreeChevronProps = useRender.ComponentProps<'button'> & {
|
|
16
|
+
expanded: boolean;
|
|
17
|
+
onExpandedChange?(expanded: boolean): void;
|
|
18
|
+
};
|
|
19
|
+
export declare function TreeChevron({ expanded, onExpandedChange, render, className, ref, onClick, onDoubleClick, ...props }: TreeChevronProps): import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
20
|
+
export type TreeLabelProps = useRender.ComponentProps<'span'>;
|
|
21
|
+
export declare function TreeLabel({ render, className, ref, ...props }: TreeLabelProps): import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
22
|
+
export type TreeDecorationProps = useRender.ComponentProps<'span'>;
|
|
23
|
+
export declare function TreeDecoration({ render, className, ref, ...props }: TreeDecorationProps): import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
24
|
+
export type TreeControlProps = useRender.ComponentProps<'span'>;
|
|
25
|
+
export declare function TreeControl({ render, className, ref, onClick, onDoubleClick, onKeyDown, onPointerDown, ...props }: TreeControlProps): import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
26
|
+
export type TreeCheckboxProps = CheckboxProps;
|
|
27
|
+
export declare function TreeCheckbox(props: TreeCheckboxProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import clsx from 'clsx';
|
|
3
|
+
import { useRender } from '@base-ui-components/react/use-render';
|
|
4
|
+
import { ChevronRight } from 'lucide-react';
|
|
5
|
+
import { useTranslation } from 'react-i18next';
|
|
6
|
+
import { Checkbox as UICheckbox } from '../Checkbox.js';
|
|
7
|
+
import { Icon } from '../Icon.js';
|
|
8
|
+
import { treeRowStyle } from './style.js';
|
|
9
|
+
export function TreeRoot({ render, className, ref, children, ...props }) {
|
|
10
|
+
return useRender({
|
|
11
|
+
render,
|
|
12
|
+
ref,
|
|
13
|
+
defaultTagName: 'div',
|
|
14
|
+
props: {
|
|
15
|
+
role: 'tree',
|
|
16
|
+
...props,
|
|
17
|
+
className: clsx('adecore-tree', className),
|
|
18
|
+
children: (_jsxs(_Fragment, { children: [_jsx("style", { children: treeRowStyle('.adecore-tree-row') }), children] }))
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
export function TreeRow({ level = 1, selected = false, joinedStart = false, joinedEnd = false, interactive = true, render, className, ref, style, children, ...props }) {
|
|
23
|
+
return useRender({
|
|
24
|
+
render,
|
|
25
|
+
ref,
|
|
26
|
+
defaultTagName: 'div',
|
|
27
|
+
props: {
|
|
28
|
+
role: 'treeitem',
|
|
29
|
+
'aria-level': level,
|
|
30
|
+
'aria-selected': selected,
|
|
31
|
+
...props,
|
|
32
|
+
'data-selected': selected,
|
|
33
|
+
'data-joined-start': joinedStart,
|
|
34
|
+
'data-joined-end': joinedEnd,
|
|
35
|
+
'data-interactive': interactive,
|
|
36
|
+
className: clsx('adecore-tree-row', className),
|
|
37
|
+
style: { paddingInlineStart: 4 + (Math.max(1, level) - 1) * 16, ...style },
|
|
38
|
+
children: (_jsxs(_Fragment, { children: [Array.from({ length: Math.max(0, level - 1) }, (_, index) => (_jsx("span", { "aria-hidden": true, className: "adecore-tree-guide", style: { insetInlineStart: 11 + index * 16 } }, index))), children] }))
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
export function TreeChevronSlot({ render, className, ref, ...props }) {
|
|
43
|
+
return useRender({
|
|
44
|
+
render,
|
|
45
|
+
ref,
|
|
46
|
+
defaultTagName: 'span',
|
|
47
|
+
props: { 'aria-hidden': true, ...props, className: clsx('adecore-tree-chevron-slot', className) }
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
export function TreeChevron({ expanded, onExpandedChange, render, className, ref, onClick, onDoubleClick, ...props }) {
|
|
51
|
+
const { t } = useTranslation('ui');
|
|
52
|
+
return useRender({
|
|
53
|
+
render,
|
|
54
|
+
ref,
|
|
55
|
+
defaultTagName: 'button',
|
|
56
|
+
props: {
|
|
57
|
+
type: 'button',
|
|
58
|
+
tabIndex: -1,
|
|
59
|
+
'aria-label': t(expanded ? 'tree.collapse' : 'tree.expand'),
|
|
60
|
+
...props,
|
|
61
|
+
className: clsx('adecore-tree-chevron-slot', className),
|
|
62
|
+
onClick: (event) => {
|
|
63
|
+
event.stopPropagation();
|
|
64
|
+
onClick?.(event);
|
|
65
|
+
if (!event.defaultPrevented) {
|
|
66
|
+
onExpandedChange?.(!expanded);
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
onDoubleClick: (event) => {
|
|
70
|
+
event.stopPropagation();
|
|
71
|
+
onDoubleClick?.(event);
|
|
72
|
+
},
|
|
73
|
+
children: _jsx(Icon, { icon: ChevronRight, size: 12, className: expanded ? 'rotate-90' : undefined })
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
export function TreeLabel({ render, className, ref, ...props }) {
|
|
78
|
+
return useRender({ render, ref, defaultTagName: 'span', props: { ...props, className: clsx('adecore-tree-label', className) } });
|
|
79
|
+
}
|
|
80
|
+
export function TreeDecoration({ render, className, ref, ...props }) {
|
|
81
|
+
return useRender({ render, ref, defaultTagName: 'span', props: { ...props, className: clsx('adecore-tree-decoration', className) } });
|
|
82
|
+
}
|
|
83
|
+
export function TreeControl({ render, className, ref, onClick, onDoubleClick, onKeyDown, onPointerDown, ...props }) {
|
|
84
|
+
return useRender({
|
|
85
|
+
render,
|
|
86
|
+
ref,
|
|
87
|
+
defaultTagName: 'span',
|
|
88
|
+
props: {
|
|
89
|
+
...props,
|
|
90
|
+
'data-tree-control': true,
|
|
91
|
+
className: clsx('adecore-tree-control', className),
|
|
92
|
+
onClick: (event) => {
|
|
93
|
+
event.stopPropagation();
|
|
94
|
+
onClick?.(event);
|
|
95
|
+
},
|
|
96
|
+
onDoubleClick: (event) => {
|
|
97
|
+
event.stopPropagation();
|
|
98
|
+
onDoubleClick?.(event);
|
|
99
|
+
},
|
|
100
|
+
onKeyDown: (event) => {
|
|
101
|
+
event.stopPropagation();
|
|
102
|
+
onKeyDown?.(event);
|
|
103
|
+
},
|
|
104
|
+
onPointerDown: (event) => {
|
|
105
|
+
event.stopPropagation();
|
|
106
|
+
onPointerDown?.(event);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
export function TreeCheckbox(props) {
|
|
112
|
+
return (_jsx(TreeControl, { children: _jsx(UICheckbox, { ...props }) }));
|
|
113
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export const TREE_ROW_HEIGHT = 25;
|
|
2
|
+
export function treeRowStyle(selector, selected = 'data-selected') {
|
|
3
|
+
return `
|
|
4
|
+
${selector} {
|
|
5
|
+
box-sizing: border-box;
|
|
6
|
+
display: flex;
|
|
7
|
+
position: relative;
|
|
8
|
+
align-items: center;
|
|
9
|
+
height: var(--tree-row-height, 25px);
|
|
10
|
+
min-width: 0;
|
|
11
|
+
gap: var(--tree-row-gap, 6px);
|
|
12
|
+
border: 0;
|
|
13
|
+
border-radius: var(--tree-row-radius, 6px);
|
|
14
|
+
background: transparent;
|
|
15
|
+
background-clip: padding-box;
|
|
16
|
+
color: var(--text);
|
|
17
|
+
font-family: var(--font-sans);
|
|
18
|
+
font-size: var(--text-xs);
|
|
19
|
+
line-height: var(--tree-row-height, 25px);
|
|
20
|
+
text-align: start;
|
|
21
|
+
outline: none;
|
|
22
|
+
}
|
|
23
|
+
${selector}[data-interactive="true"]:hover { background: var(--surface-hover); }
|
|
24
|
+
${selector}[${selected}="true"] { background: var(--surface-active); color: var(--text); }
|
|
25
|
+
${selector}[data-joined-start="true"] { border-start-start-radius: 0; border-start-end-radius: 0; }
|
|
26
|
+
${selector}[data-joined-end="true"] { border-end-start-radius: 0; border-end-end-radius: 0; }
|
|
27
|
+
${selector}:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
|
|
28
|
+
`;
|
|
29
|
+
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adecore/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0-beta.1",
|
|
4
4
|
"description": "React components, a theme, formatters and a settings dialog for desktop-grade apps on React 19, Base UI and Tailwind 4.",
|
|
5
|
-
"license": "MIT",
|
|
5
|
+
"license": "(MIT AND FSL-1.1-MIT)",
|
|
6
6
|
"author": "Bas Milius",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
"src",
|
|
25
25
|
"!src/**/*.test.ts",
|
|
26
26
|
"!src/**/*.test.tsx",
|
|
27
|
-
"!src/**/__snapshots__"
|
|
27
|
+
"!src/**/__snapshots__",
|
|
28
|
+
"!src/file-tree/testing"
|
|
28
29
|
],
|
|
29
30
|
"exports": {
|
|
30
31
|
".": {
|
|
@@ -87,6 +88,7 @@
|
|
|
87
88
|
"react": "^19.3.0",
|
|
88
89
|
"react-dom": "^19.3.0",
|
|
89
90
|
"react-i18next": "^17.0.15",
|
|
90
|
-
"typescript": "^7.0.2"
|
|
91
|
+
"typescript": "^7.0.2",
|
|
92
|
+
"@happy-dom/global-registrator": "^20.14.5"
|
|
91
93
|
}
|
|
92
94
|
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# Functional Source License, Version 1.1, MIT Future License
|
|
2
|
+
|
|
3
|
+
## Abbreviation
|
|
4
|
+
|
|
5
|
+
FSL-1.1-MIT
|
|
6
|
+
|
|
7
|
+
## Notice
|
|
8
|
+
|
|
9
|
+
Copyright 2026 Bas Milius
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
|
|
13
|
+
### Licensor ("We")
|
|
14
|
+
|
|
15
|
+
The party offering the Software under these Terms and Conditions.
|
|
16
|
+
|
|
17
|
+
### The Software
|
|
18
|
+
|
|
19
|
+
The "Software" is each version of the software that we make available under
|
|
20
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
21
|
+
Conditions with the Software.
|
|
22
|
+
|
|
23
|
+
### License Grant
|
|
24
|
+
|
|
25
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
26
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
|
27
|
+
use, copy, modify, create derivative works, publicly perform, publicly display
|
|
28
|
+
and redistribute the Software for any Permitted Purpose identified below.
|
|
29
|
+
|
|
30
|
+
### Permitted Purpose
|
|
31
|
+
|
|
32
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
33
|
+
means making the Software available to others in a commercial product or
|
|
34
|
+
service that:
|
|
35
|
+
|
|
36
|
+
1. substitutes for the Software;
|
|
37
|
+
|
|
38
|
+
2. substitutes for any other product or service we offer using the Software
|
|
39
|
+
that exists as of the date we make the Software available; or
|
|
40
|
+
|
|
41
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
42
|
+
|
|
43
|
+
Permitted Purposes specifically include using the Software:
|
|
44
|
+
|
|
45
|
+
1. for your internal use and access;
|
|
46
|
+
|
|
47
|
+
2. for non-commercial education;
|
|
48
|
+
|
|
49
|
+
3. for non-commercial research; and
|
|
50
|
+
|
|
51
|
+
4. in connection with professional services that you provide to a licensee
|
|
52
|
+
using the Software in accordance with these Terms and Conditions.
|
|
53
|
+
|
|
54
|
+
### Patents
|
|
55
|
+
|
|
56
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
57
|
+
patents, the license grant above includes a license under our patents. If you
|
|
58
|
+
make a claim against any party that the Software infringes or contributes to
|
|
59
|
+
the infringement of any patent, then your patent license to the Software ends
|
|
60
|
+
immediately.
|
|
61
|
+
|
|
62
|
+
### Redistribution
|
|
63
|
+
|
|
64
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
65
|
+
the Software.
|
|
66
|
+
|
|
67
|
+
If you redistribute any copies, modifications or derivatives of the Software,
|
|
68
|
+
you must include a copy of or a link to these Terms and Conditions and not
|
|
69
|
+
remove any copyright notices provided in or with the Software.
|
|
70
|
+
|
|
71
|
+
### Disclaimer
|
|
72
|
+
|
|
73
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
|
74
|
+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
|
75
|
+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
76
|
+
|
|
77
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
78
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
|
|
79
|
+
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
80
|
+
|
|
81
|
+
### Trademarks
|
|
82
|
+
|
|
83
|
+
Except for displaying the License Details and identifying us as the origin of
|
|
84
|
+
the Software, you have no right under these Terms and Conditions to use our
|
|
85
|
+
trademarks, trade names, service marks or product names.
|
|
86
|
+
|
|
87
|
+
## Grant of Future License
|
|
88
|
+
|
|
89
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
90
|
+
the MIT license that is effective on the second anniversary of the date we make
|
|
91
|
+
the Software available. On or after that date, you may use the Software under
|
|
92
|
+
the MIT license, in which case the following will apply:
|
|
93
|
+
|
|
94
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
95
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
96
|
+
the Software without restriction, including without limitation the rights to
|
|
97
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
98
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
|
99
|
+
so, subject to the following conditions:
|
|
100
|
+
|
|
101
|
+
The above copyright notice and this permission notice shall be included in all
|
|
102
|
+
copies or substantial portions of the Software.
|
|
103
|
+
|
|
104
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
105
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
106
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
107
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
108
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
109
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
110
|
+
SOFTWARE.
|