@lenso/primitives 0.7.0 → 0.9.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 +25 -8
- package/dist/list/list.d.ts +56 -0
- package/dist/list/list.js +163 -0
- package/dist/model-control/model-control.d.ts +50 -0
- package/dist/model-control/model-control.js +113 -0
- package/dist/section-index/index.d.ts +9 -0
- package/dist/section-index/index.js +8 -0
- package/dist/section-index/section-index.d.ts +42 -0
- package/dist/section-index/section-index.js +145 -0
- package/dist/sidebar/index.d.ts +31 -110
- package/dist/sidebar/index.js +29 -301
- package/dist/sidebar/sidebar.d.ts +41 -0
- package/dist/sidebar/sidebar.js +151 -0
- package/dist/swipe-actions/index.d.ts +12 -0
- package/dist/swipe-actions/index.js +11 -0
- package/dist/swipe-actions/swipe-actions.d.ts +40 -0
- package/dist/swipe-actions/swipe-actions.js +200 -0
- package/dist/wheel-picker/wheel-picker.d.ts +36 -0
- package/dist/wheel-picker/wheel-picker.js +68 -0
- package/package.json +49 -31
- package/dist/data-grid/index.d.ts +0 -117
- package/dist/data-grid/index.js +0 -179
- package/dist/resize-handle/index.d.ts +0 -44
- package/dist/resize-handle/index.js +0 -180
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createSwipeActionsController, swipeActions } from "./swipe-actions.js";
|
|
3
|
+
import { createParts } from "@ui-sdk/react/primitive";
|
|
4
|
+
const SwipeActions = createParts(swipeActions, {
|
|
5
|
+
root: "div",
|
|
6
|
+
content: "div",
|
|
7
|
+
body: "div",
|
|
8
|
+
actions: "div",
|
|
9
|
+
trigger: "button"
|
|
10
|
+
});
|
|
11
|
+
export { SwipeActions, createSwipeActionsController, swipeActions };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { createSwipeActions, definePrimitive, type ChangeDetails, type ChangeOptions, type SlotDefinition, type SwipeDraft, type SwipeOpen, type SwipeSide } from "@ui-sdk/core";
|
|
2
|
+
export type SwipeActionsReason = "swipe" | "trigger-press" | "escape-key" | "outside-press" | "imperative";
|
|
3
|
+
export type SwipeActionsController = {
|
|
4
|
+
getOpenSide(): SwipeSide | null;
|
|
5
|
+
setOpenSide(side: SwipeSide | null, options?: ChangeOptions<SwipeActionsReason>): boolean;
|
|
6
|
+
};
|
|
7
|
+
export type SwipeActionsOptions = {
|
|
8
|
+
open?: SwipeOpen | null;
|
|
9
|
+
defaultOpen?: SwipeOpen | null;
|
|
10
|
+
onOpenChange?: (open: SwipeOpen | null, details: ChangeDetails<SwipeActionsReason>) => void;
|
|
11
|
+
onFullSwipe?: (side: SwipeSide, details: {
|
|
12
|
+
event: Event;
|
|
13
|
+
}) => boolean;
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
controller?: SwipeActionsController;
|
|
16
|
+
};
|
|
17
|
+
type State = {
|
|
18
|
+
open: SwipeOpen | null;
|
|
19
|
+
swiping: SwipeDraft | null;
|
|
20
|
+
disabled: boolean;
|
|
21
|
+
};
|
|
22
|
+
type Api = SwipeActionsController & {
|
|
23
|
+
swipe: ReturnType<typeof createSwipeActions<State>>;
|
|
24
|
+
run(event: Event, action: () => void): void;
|
|
25
|
+
keydown(event: KeyboardEvent): void;
|
|
26
|
+
};
|
|
27
|
+
type ActionProps = {
|
|
28
|
+
side: SwipeSide;
|
|
29
|
+
value: string;
|
|
30
|
+
};
|
|
31
|
+
type Slots = {
|
|
32
|
+
root: SlotDefinition<State, Api, {}, State>;
|
|
33
|
+
content: SlotDefinition<State, Api, {}>;
|
|
34
|
+
body: SlotDefinition<State, Api, {}>;
|
|
35
|
+
actions: SlotDefinition<State, Api, ActionProps>;
|
|
36
|
+
trigger: SlotDefinition<State, Api, ActionProps>;
|
|
37
|
+
};
|
|
38
|
+
export declare function createSwipeActionsController(): SwipeActionsController;
|
|
39
|
+
export declare const swipeActions: ReturnType<typeof definePrimitive<SwipeActionsOptions, State, Api, Slots>>;
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { createChange, createController, createSwipeActions, definePrimitive, elements, live } from "@ui-sdk/core";
|
|
2
|
+
// src/swipe-actions/swipe-actions.ts
|
|
3
|
+
function createSwipeActionsController() {
|
|
4
|
+
return createController();
|
|
5
|
+
}
|
|
6
|
+
const swipeActions = definePrimitive({
|
|
7
|
+
name: "swipe-actions",
|
|
8
|
+
options: {
|
|
9
|
+
open: "value",
|
|
10
|
+
defaultOpen: "value",
|
|
11
|
+
onOpenChange: "callback",
|
|
12
|
+
onFullSwipe: "action",
|
|
13
|
+
disabled: "boolean",
|
|
14
|
+
controller: "value"
|
|
15
|
+
},
|
|
16
|
+
controlled: ["open"],
|
|
17
|
+
live: ["swiping"],
|
|
18
|
+
state: (options) => ({
|
|
19
|
+
open: options.open === void 0 ? options.defaultOpen ?? null : options.open,
|
|
20
|
+
swiping: null,
|
|
21
|
+
disabled: !!options.disabled
|
|
22
|
+
}),
|
|
23
|
+
sync: (options) => ({
|
|
24
|
+
...options.open === void 0 ? {} : { open: options.open },
|
|
25
|
+
disabled: !!options.disabled
|
|
26
|
+
}),
|
|
27
|
+
api: (context) => {
|
|
28
|
+
const change = createChange(context);
|
|
29
|
+
let cause = { reason: "imperative" };
|
|
30
|
+
let accepted = false;
|
|
31
|
+
let canceled = false;
|
|
32
|
+
const store = {
|
|
33
|
+
...context.store,
|
|
34
|
+
set(patch, delivered) {
|
|
35
|
+
const { open, ...internal } = patch;
|
|
36
|
+
if (open !== void 0 && !canceled) accepted = change("open", open, {
|
|
37
|
+
...cause,
|
|
38
|
+
reason: cause.reason ?? "imperative"
|
|
39
|
+
});
|
|
40
|
+
context.store.set(internal, delivered);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const swipe = createSwipeActions({
|
|
44
|
+
...context,
|
|
45
|
+
store
|
|
46
|
+
}, {
|
|
47
|
+
key: "open",
|
|
48
|
+
draft: "swiping",
|
|
49
|
+
disabled: () => context.store.get().disabled,
|
|
50
|
+
fullSwipe: () => context.options().onFullSwipe ? .8 : Infinity,
|
|
51
|
+
onFullSwipe: (_key, side, details) => context.options().onFullSwipe?.(side, details) ?? false
|
|
52
|
+
});
|
|
53
|
+
const run = (event, action) => {
|
|
54
|
+
if (event.type === "pointerdown" || event instanceof KeyboardEvent) canceled = false;
|
|
55
|
+
if (event.type === "pointercancel" || event.type === "lostpointercapture") canceled = true;
|
|
56
|
+
cause = {
|
|
57
|
+
event,
|
|
58
|
+
reason: event instanceof KeyboardEvent ? event.key === "Escape" ? "escape-key" : "trigger-press" : event instanceof PointerEvent && event.target instanceof Element && event.target.closest("[data-swipe-body]") && elements(context, "root").some(({ el }) => el.contains(event.target)) ? "swipe" : "outside-press"
|
|
59
|
+
};
|
|
60
|
+
action();
|
|
61
|
+
};
|
|
62
|
+
const setOpenSide = (side, options = {}) => {
|
|
63
|
+
if (context.store.get().disabled && side !== null) return false;
|
|
64
|
+
canceled = false;
|
|
65
|
+
cause = {
|
|
66
|
+
...options,
|
|
67
|
+
reason: options.reason ?? "imperative"
|
|
68
|
+
};
|
|
69
|
+
accepted = false;
|
|
70
|
+
if (side) swipe.show("row", side);
|
|
71
|
+
else swipe.close();
|
|
72
|
+
return accepted;
|
|
73
|
+
};
|
|
74
|
+
const keydown = (event) => run(event, () => {
|
|
75
|
+
const side = context.store.get().open?.side;
|
|
76
|
+
swipe.keydown(event, "row");
|
|
77
|
+
if (event.key === "Escape" && side && !context.store.get().open) elements(context, "trigger").find((part) => context.props("trigger", part.key)?.side === side)?.el.focus();
|
|
78
|
+
});
|
|
79
|
+
return {
|
|
80
|
+
swipe,
|
|
81
|
+
run,
|
|
82
|
+
keydown,
|
|
83
|
+
getOpenSide: () => context.store.get().open?.side ?? null,
|
|
84
|
+
setOpenSide
|
|
85
|
+
};
|
|
86
|
+
},
|
|
87
|
+
slots: (slot) => ({
|
|
88
|
+
root: slot({
|
|
89
|
+
state: (state) => state,
|
|
90
|
+
attrs: (state) => ({
|
|
91
|
+
role: "group",
|
|
92
|
+
tabindex: "-1",
|
|
93
|
+
"data-disabled": state.disabled ? "" : void 0,
|
|
94
|
+
"data-open-side": state.open?.side
|
|
95
|
+
}),
|
|
96
|
+
live: live((state, { api }) => {
|
|
97
|
+
const attrs = api.swipe.contentAttrs(state, "row");
|
|
98
|
+
return {
|
|
99
|
+
"data-swipe": attrs["data-swipe"],
|
|
100
|
+
"data-swiping": attrs["data-swiping"]
|
|
101
|
+
};
|
|
102
|
+
}),
|
|
103
|
+
on: {
|
|
104
|
+
pointerdown: (event, { api, el }) => {
|
|
105
|
+
const body = event.target instanceof Element ? event.target.closest("[data-swipe-body]") : null;
|
|
106
|
+
if (body && el?.contains(body)) api.run(event, () => api.swipe.pointerdown(event, "row", body));
|
|
107
|
+
},
|
|
108
|
+
keydown: (event, { api }) => api.keydown(event)
|
|
109
|
+
},
|
|
110
|
+
bind: (el, { api }) => {
|
|
111
|
+
const unbind = api.swipe.bindRow(el, "row");
|
|
112
|
+
let pointer;
|
|
113
|
+
const capture = (event) => {
|
|
114
|
+
if (event.type === "pointerdown") {
|
|
115
|
+
if (!(event.target instanceof Node) || !el.contains(event.target)) api.run(event, () => {});
|
|
116
|
+
const body = event.target instanceof Element ? event.target.closest("[data-swipe-body]") : null;
|
|
117
|
+
if (event.button !== 0 || !event.isPrimary || !body || !el.contains(body)) return;
|
|
118
|
+
pointer = {
|
|
119
|
+
id: event.pointerId,
|
|
120
|
+
body
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
if (!pointer || event.pointerId !== pointer.id) return;
|
|
124
|
+
if (event.type === "lostpointercapture" && (event.target !== pointer.body || pointer.body.hasPointerCapture(pointer.id))) return;
|
|
125
|
+
api.run(event, () => {});
|
|
126
|
+
if (event.type !== "pointerdown") pointer = void 0;
|
|
127
|
+
};
|
|
128
|
+
const selection = (event) => {
|
|
129
|
+
if (!(event.target instanceof Element) || !event.target.closest("input,textarea,select,[contenteditable]")) event.preventDefault();
|
|
130
|
+
};
|
|
131
|
+
el.addEventListener("selectstart", selection);
|
|
132
|
+
for (const type of [
|
|
133
|
+
"pointerdown",
|
|
134
|
+
"pointerup",
|
|
135
|
+
"pointercancel",
|
|
136
|
+
"lostpointercapture"
|
|
137
|
+
]) el.ownerDocument.addEventListener(type, capture, true);
|
|
138
|
+
return () => {
|
|
139
|
+
el.removeEventListener("selectstart", selection);
|
|
140
|
+
for (const type of [
|
|
141
|
+
"pointerdown",
|
|
142
|
+
"pointerup",
|
|
143
|
+
"pointercancel",
|
|
144
|
+
"lostpointercapture"
|
|
145
|
+
]) el.ownerDocument.removeEventListener(type, capture, true);
|
|
146
|
+
unbind();
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
}),
|
|
150
|
+
body: slot({ attrs: () => ({ "data-swipe-body": "" }) }),
|
|
151
|
+
content: slot({ live: live((state, { api }) => api.swipe.contentAttrs(state, "row")) }),
|
|
152
|
+
actions: slot({
|
|
153
|
+
props: {
|
|
154
|
+
side: "string",
|
|
155
|
+
value: "string"
|
|
156
|
+
},
|
|
157
|
+
attrs: (state, { api, props, id }) => ({
|
|
158
|
+
id: elementsId(id, props.side),
|
|
159
|
+
...api.swipe.actionsAttrs(state, "row", props.side),
|
|
160
|
+
"aria-hidden": String(state.disabled || state.open?.side !== props.side)
|
|
161
|
+
}),
|
|
162
|
+
bind: (el, { api, props }) => api.swipe.bindActions(el, "row", props.side)
|
|
163
|
+
}),
|
|
164
|
+
trigger: slot({
|
|
165
|
+
props: {
|
|
166
|
+
side: "string",
|
|
167
|
+
value: "string"
|
|
168
|
+
},
|
|
169
|
+
role: "button",
|
|
170
|
+
focus: "native",
|
|
171
|
+
attrs: (state, { id, props }) => ({
|
|
172
|
+
type: "button",
|
|
173
|
+
disabled: state.disabled ? "" : void 0,
|
|
174
|
+
"aria-expanded": String(state.open?.side === props.side),
|
|
175
|
+
"aria-controls": elementsId(id, props.side)
|
|
176
|
+
}),
|
|
177
|
+
press: ({ api, props }, event) => {
|
|
178
|
+
api.setOpenSide(api.getOpenSide() === props.side ? null : props.side, {
|
|
179
|
+
reason: "trigger-press",
|
|
180
|
+
...event ? { event } : {}
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
})
|
|
184
|
+
}),
|
|
185
|
+
agent: {
|
|
186
|
+
actions: ["setOpenSide"],
|
|
187
|
+
reveals: true,
|
|
188
|
+
items: () => [{
|
|
189
|
+
value: "start",
|
|
190
|
+
label: "Leading actions"
|
|
191
|
+
}, {
|
|
192
|
+
value: "end",
|
|
193
|
+
label: "Trailing actions"
|
|
194
|
+
}]
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
function elementsId(id, side) {
|
|
198
|
+
return `${id}-${side}-actions`;
|
|
199
|
+
}
|
|
200
|
+
export { createSwipeActionsController, swipeActions };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { definePrimitive, type ChangeDetails, type ChangeOptions, type SlotDefinition } from "@ui-sdk/core";
|
|
2
|
+
export type WheelOption = {
|
|
3
|
+
value: string;
|
|
4
|
+
label: string;
|
|
5
|
+
disabled?: boolean;
|
|
6
|
+
};
|
|
7
|
+
export type WheelReason = "item-press" | "list-navigation" | "scroll" | "drag" | "reset" | "restore" | "imperative";
|
|
8
|
+
export type WheelController = {
|
|
9
|
+
getValue(): string | null;
|
|
10
|
+
setValue(value: string | null, options?: ChangeOptions<WheelReason>): boolean;
|
|
11
|
+
clear(options?: ChangeOptions<WheelReason>): boolean;
|
|
12
|
+
reset(): boolean;
|
|
13
|
+
};
|
|
14
|
+
export type WheelOptions = {
|
|
15
|
+
options: readonly WheelOption[];
|
|
16
|
+
value?: string | null;
|
|
17
|
+
defaultValue?: string | null;
|
|
18
|
+
onValueChange?: (value: string | null, details: ChangeDetails<WheelReason>) => void;
|
|
19
|
+
disabled?: boolean;
|
|
20
|
+
readOnly?: boolean;
|
|
21
|
+
controller?: WheelController;
|
|
22
|
+
};
|
|
23
|
+
type State = {
|
|
24
|
+
value: string | null;
|
|
25
|
+
disabled: boolean;
|
|
26
|
+
readOnly: boolean;
|
|
27
|
+
};
|
|
28
|
+
type Api = WheelController & {
|
|
29
|
+
items(): readonly WheelOption[];
|
|
30
|
+
};
|
|
31
|
+
type Slots = {
|
|
32
|
+
root: SlotDefinition<State, Api, {}, State>;
|
|
33
|
+
};
|
|
34
|
+
export declare function createWheelPickerController(): WheelController;
|
|
35
|
+
export declare const wheelPicker: ReturnType<typeof definePrimitive<WheelOptions, State, Api, Slots>>;
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { createChange, createController, definePrimitive } from "@ui-sdk/core";
|
|
2
|
+
// src/wheel-picker/wheel-picker.ts
|
|
3
|
+
function createWheelPickerController() {
|
|
4
|
+
return createController();
|
|
5
|
+
}
|
|
6
|
+
const wheelPicker = definePrimitive({
|
|
7
|
+
name: "wheel-picker",
|
|
8
|
+
options: {
|
|
9
|
+
options: "list",
|
|
10
|
+
value: "string",
|
|
11
|
+
defaultValue: "string",
|
|
12
|
+
onValueChange: "callback",
|
|
13
|
+
disabled: "boolean",
|
|
14
|
+
readOnly: "boolean",
|
|
15
|
+
controller: "value"
|
|
16
|
+
},
|
|
17
|
+
controlled: ["value"],
|
|
18
|
+
state: (options) => ({
|
|
19
|
+
value: options.value === void 0 ? options.defaultValue ?? options.options.find((item) => !item.disabled)?.value ?? null : options.value,
|
|
20
|
+
disabled: !!options.disabled,
|
|
21
|
+
readOnly: !!options.readOnly
|
|
22
|
+
}),
|
|
23
|
+
sync: (options) => ({
|
|
24
|
+
...options.value === void 0 ? {} : { value: options.value },
|
|
25
|
+
disabled: !!options.disabled,
|
|
26
|
+
readOnly: !!options.readOnly
|
|
27
|
+
}),
|
|
28
|
+
api: (context) => {
|
|
29
|
+
const change = createChange(context);
|
|
30
|
+
const setValue = (value, options = {}) => {
|
|
31
|
+
const state = context.store.get();
|
|
32
|
+
if ((state.disabled || state.readOnly) && options.reason !== "reset" && options.reason !== "restore") return false;
|
|
33
|
+
if (value !== null && !context.options().options.some((item) => item.value === value && !item.disabled)) return false;
|
|
34
|
+
return change("value", value, {
|
|
35
|
+
...options,
|
|
36
|
+
reason: options.reason ?? "imperative"
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
return {
|
|
40
|
+
reset: () => setValue(context.options().defaultValue ?? context.options().options.find((item) => !item.disabled)?.value ?? null, { reason: "reset" }),
|
|
41
|
+
getValue: () => context.store.get().value,
|
|
42
|
+
setValue,
|
|
43
|
+
clear: (options) => setValue(null, options),
|
|
44
|
+
items: () => context.options().options
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
slots: (slot) => ({ root: slot({
|
|
48
|
+
state: (state) => state,
|
|
49
|
+
attrs: (state) => ({
|
|
50
|
+
role: "group",
|
|
51
|
+
"data-disabled": state.disabled ? "" : void 0,
|
|
52
|
+
"data-readonly": state.readOnly ? "" : void 0
|
|
53
|
+
})
|
|
54
|
+
}) }),
|
|
55
|
+
agent: {
|
|
56
|
+
actions: [
|
|
57
|
+
"setValue",
|
|
58
|
+
"clear",
|
|
59
|
+
"reset"
|
|
60
|
+
],
|
|
61
|
+
closed: true,
|
|
62
|
+
items: (api) => api.items().map(({ value, label }) => ({
|
|
63
|
+
value,
|
|
64
|
+
label
|
|
65
|
+
}))
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
export { createWheelPickerController, wheelPicker };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lenso/primitives",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Headless product primitives for Lenso UI.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -10,52 +10,70 @@
|
|
|
10
10
|
},
|
|
11
11
|
"files": [
|
|
12
12
|
"dist",
|
|
13
|
+
"LICENSE",
|
|
13
14
|
"README.md"
|
|
14
15
|
],
|
|
15
16
|
"type": "module",
|
|
16
17
|
"exports": {
|
|
17
|
-
"./resize-handle": {
|
|
18
|
-
"types": "./dist/resize-handle/index.d.ts",
|
|
19
|
-
"import": "./dist/resize-handle/index.js"
|
|
20
|
-
},
|
|
21
|
-
"./data-grid": {
|
|
22
|
-
"types": "./dist/data-grid/index.d.ts",
|
|
23
|
-
"import": "./dist/data-grid/index.js"
|
|
24
|
-
},
|
|
25
18
|
"./sidebar": {
|
|
26
19
|
"types": "./dist/sidebar/index.d.ts",
|
|
27
20
|
"import": "./dist/sidebar/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./sidebar/core": {
|
|
23
|
+
"types": "./dist/sidebar/sidebar.d.ts",
|
|
24
|
+
"import": "./dist/sidebar/sidebar.js"
|
|
25
|
+
},
|
|
26
|
+
"./section-index": {
|
|
27
|
+
"types": "./dist/section-index/index.d.ts",
|
|
28
|
+
"import": "./dist/section-index/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./section-index/core": {
|
|
31
|
+
"types": "./dist/section-index/section-index.d.ts",
|
|
32
|
+
"import": "./dist/section-index/section-index.js"
|
|
33
|
+
},
|
|
34
|
+
"./swipe-actions": {
|
|
35
|
+
"types": "./dist/swipe-actions/index.d.ts",
|
|
36
|
+
"import": "./dist/swipe-actions/index.js"
|
|
37
|
+
},
|
|
38
|
+
"./swipe-actions/core": {
|
|
39
|
+
"types": "./dist/swipe-actions/swipe-actions.d.ts",
|
|
40
|
+
"import": "./dist/swipe-actions/swipe-actions.js"
|
|
41
|
+
},
|
|
42
|
+
"./model-control": {
|
|
43
|
+
"types": "./dist/model-control/model-control.d.ts",
|
|
44
|
+
"import": "./dist/model-control/model-control.js"
|
|
45
|
+
},
|
|
46
|
+
"./list/core": {
|
|
47
|
+
"types": "./dist/list/list.d.ts",
|
|
48
|
+
"import": "./dist/list/list.js"
|
|
49
|
+
},
|
|
50
|
+
"./wheel-picker/core": {
|
|
51
|
+
"types": "./dist/wheel-picker/wheel-picker.d.ts",
|
|
52
|
+
"import": "./dist/wheel-picker/wheel-picker.js"
|
|
28
53
|
}
|
|
29
54
|
},
|
|
30
55
|
"publishConfig": {
|
|
31
56
|
"access": "public"
|
|
32
57
|
},
|
|
58
|
+
"scripts": {
|
|
59
|
+
"build": "tsdown --config tsdown.config.ts && tsc -p tsconfig.build.json --declaration --emitDeclarationOnly --noEmit false --outDir dist",
|
|
60
|
+
"test": "bun test --preload ../../tests/setup/dom.ts src",
|
|
61
|
+
"typecheck": "bun check --no-script --noEmit"
|
|
62
|
+
},
|
|
33
63
|
"dependencies": {
|
|
34
|
-
"@
|
|
64
|
+
"@ui-sdk/core": "0.1.0-beta.1",
|
|
65
|
+
"@ui-sdk/react": "0.1.0-beta.1"
|
|
35
66
|
},
|
|
36
67
|
"devDependencies": {
|
|
37
|
-
"@
|
|
38
|
-
"@
|
|
39
|
-
"@
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"react": "19.2.8",
|
|
45
|
-
"react-dom": "19.2.8",
|
|
46
|
-
"tsdown": "0.22.14",
|
|
47
|
-
"typescript": "7.0.2",
|
|
48
|
-
"vitest": "4.1.10",
|
|
49
|
-
"vitest-browser-react": "2.2.0"
|
|
68
|
+
"@types/bun": "1.4.4",
|
|
69
|
+
"@types/react": "19.3.0",
|
|
70
|
+
"@types/react-dom": "19.3.0",
|
|
71
|
+
"react": "19.3.1",
|
|
72
|
+
"react-dom": "19.3.1",
|
|
73
|
+
"tsdown": "0.23.7",
|
|
74
|
+
"typescript": "7.0.2"
|
|
50
75
|
},
|
|
51
76
|
"peerDependencies": {
|
|
52
|
-
"@base-ui/react": ">=1.7.0 <2.0.0",
|
|
53
|
-
"@stylexjs/stylex": ">=0.19.0 <1.0.0",
|
|
54
77
|
"react": ">=19.2.0 <20.0.0"
|
|
55
|
-
},
|
|
56
|
-
"scripts": {
|
|
57
|
-
"build": "tsdown --config tsdown.config.ts && tsc -p tsconfig.build.json --declaration --emitDeclarationOnly --noEmit false --outDir dist",
|
|
58
|
-
"test": "vitest run --config vitest.config.ts",
|
|
59
|
-
"typecheck": "tsc --noEmit"
|
|
60
78
|
}
|
|
61
|
-
}
|
|
79
|
+
}
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { type ColumnDef, type CellSelectionState, type RowData, type ReactTable, type SortingState, type TableOptions } from "@tanstack/react-table";
|
|
2
|
-
export type DataGridValue = string | number | boolean | null;
|
|
3
|
-
export type DataGridEditReason = "edit" | "paste" | "fill" | "programmatic";
|
|
4
|
-
export interface DataGridCellChange<TRow> {
|
|
5
|
-
rowId: string;
|
|
6
|
-
rowIndex: number;
|
|
7
|
-
columnId: string;
|
|
8
|
-
previousValue: DataGridValue;
|
|
9
|
-
value: DataGridValue;
|
|
10
|
-
previousRow: TRow;
|
|
11
|
-
row: TRow;
|
|
12
|
-
reason: DataGridEditReason;
|
|
13
|
-
}
|
|
14
|
-
export interface DataGridRowChange<TRow> {
|
|
15
|
-
rowId: string;
|
|
16
|
-
rowIndex: number;
|
|
17
|
-
previousRow: TRow;
|
|
18
|
-
row: TRow;
|
|
19
|
-
changes: readonly DataGridCellChange<TRow>[];
|
|
20
|
-
reason: DataGridEditReason;
|
|
21
|
-
}
|
|
22
|
-
export interface DataGridColumn<TRow extends RowData, TValidationData = unknown> {
|
|
23
|
-
id: string;
|
|
24
|
-
header: string;
|
|
25
|
-
getValue: (row: TRow) => DataGridValue;
|
|
26
|
-
setValue?: (row: TRow, value: DataGridValue) => TRow;
|
|
27
|
-
parse?: (input: string, row: TRow) => DataGridValue;
|
|
28
|
-
validate?: (value: DataGridValue, row: TRow, context: DataGridValidationContext<TRow, TValidationData>) => string | null;
|
|
29
|
-
editable?: boolean | ((row: TRow) => boolean);
|
|
30
|
-
sortable?: boolean;
|
|
31
|
-
width?: number;
|
|
32
|
-
minWidth?: number;
|
|
33
|
-
maxWidth?: number;
|
|
34
|
-
pinned?: boolean;
|
|
35
|
-
onCellEditComplete?: (change: DataGridCellChange<TRow>) => void;
|
|
36
|
-
tableColumn?: Omit<Partial<ColumnDef<typeof dataGridFeatures, TRow, unknown>>, "id" | "header" | "accessorFn">;
|
|
37
|
-
}
|
|
38
|
-
export interface DataGridEdit {
|
|
39
|
-
rowId: string;
|
|
40
|
-
columnId: string;
|
|
41
|
-
value: DataGridValue;
|
|
42
|
-
}
|
|
43
|
-
export interface DataGridCellEvent<TRow> {
|
|
44
|
-
rowId: string;
|
|
45
|
-
columnId: string;
|
|
46
|
-
onEditComplete: (change: DataGridCellChange<TRow>) => void;
|
|
47
|
-
}
|
|
48
|
-
export type DataGridCommitResult<TRow> = {
|
|
49
|
-
ok: true;
|
|
50
|
-
changes: readonly DataGridCellChange<TRow>[];
|
|
51
|
-
} | {
|
|
52
|
-
ok: false;
|
|
53
|
-
error: string;
|
|
54
|
-
edit: DataGridEdit;
|
|
55
|
-
};
|
|
56
|
-
export interface UseDataGridOptions<TRow extends RowData, TValidationData = unknown> {
|
|
57
|
-
rows: readonly TRow[];
|
|
58
|
-
columns: readonly DataGridColumn<TRow, TValidationData>[];
|
|
59
|
-
getRowId: (row: TRow) => string;
|
|
60
|
-
readOnly?: boolean;
|
|
61
|
-
rowSelection?: boolean;
|
|
62
|
-
cellSelection?: boolean;
|
|
63
|
-
sorting?: boolean;
|
|
64
|
-
onRowsChange?: (rows: TRow[], changes: readonly DataGridCellChange<TRow>[]) => void;
|
|
65
|
-
onCellEditComplete?: (change: DataGridCellChange<TRow>) => void;
|
|
66
|
-
cellEvents?: readonly DataGridCellEvent<TRow>[];
|
|
67
|
-
onRowEditComplete?: (change: DataGridRowChange<TRow>) => void;
|
|
68
|
-
onRowSelectionChange?: (rowIds: ReadonlySet<string>) => void;
|
|
69
|
-
onCellSelectionChange?: (ranges: CellSelectionState) => void;
|
|
70
|
-
onSortingChange?: (sorting: SortingState) => void;
|
|
71
|
-
validationData?: TValidationData;
|
|
72
|
-
tableOptions?: DataGridTableOptions<TRow>;
|
|
73
|
-
}
|
|
74
|
-
export declare const dataGridFeatures: {
|
|
75
|
-
cellSelectionFeature: import("@tanstack/react-table").TableFeature;
|
|
76
|
-
columnSizingFeature: import("@tanstack/react-table").TableFeature;
|
|
77
|
-
columnResizingFeature: import("@tanstack/react-table").TableFeature;
|
|
78
|
-
rowSelectionFeature: import("@tanstack/react-table").TableFeature;
|
|
79
|
-
rowSortingFeature: import("@tanstack/react-table").TableFeature;
|
|
80
|
-
sortedRowModel: (table: import("@tanstack/react-table").Table<any, any>) => () => import("@tanstack/react-table").RowModel<any, any>;
|
|
81
|
-
sortFns: {
|
|
82
|
-
alphanumeric: import("@tanstack/react-table").CreatedSortFn<any, any>;
|
|
83
|
-
basic: import("@tanstack/react-table").CreatedSortFn<any, any>;
|
|
84
|
-
datetime: import("@tanstack/react-table").CreatedSortFn<any, any>;
|
|
85
|
-
text: import("@tanstack/react-table").CreatedSortFn<any, any>;
|
|
86
|
-
};
|
|
87
|
-
};
|
|
88
|
-
export type DataGridTable<TRow extends RowData> = ReactTable<typeof dataGridFeatures, TRow>;
|
|
89
|
-
export type DataGridTableOptions<TRow extends RowData> = Partial<Omit<TableOptions<typeof dataGridFeatures, TRow>, "features" | "columns" | "data" | "getRowId">>;
|
|
90
|
-
export interface DataGridValidationContext<TRow extends RowData, TValidationData = unknown> {
|
|
91
|
-
rowId: string;
|
|
92
|
-
rowIndex: number;
|
|
93
|
-
columnId: string;
|
|
94
|
-
rows: readonly TRow[];
|
|
95
|
-
originalRows: readonly TRow[];
|
|
96
|
-
changes: readonly DataGridCellChange<TRow>[];
|
|
97
|
-
reason: DataGridEditReason;
|
|
98
|
-
data: TValidationData | undefined;
|
|
99
|
-
table: DataGridTable<TRow>;
|
|
100
|
-
}
|
|
101
|
-
export declare function useDataGrid<TRow extends RowData, TValidationData = unknown>({ rows, columns, getRowId, readOnly, rowSelection, cellSelection, sorting, onRowsChange, onCellEditComplete, cellEvents, onRowEditComplete, onRowSelectionChange, onCellSelectionChange, onSortingChange, validationData, tableOptions, }: UseDataGridOptions<TRow, TValidationData>): {
|
|
102
|
-
table: ReactTable<{
|
|
103
|
-
cellSelectionFeature: import("@tanstack/react-table").TableFeature;
|
|
104
|
-
columnSizingFeature: import("@tanstack/react-table").TableFeature;
|
|
105
|
-
columnResizingFeature: import("@tanstack/react-table").TableFeature;
|
|
106
|
-
rowSelectionFeature: import("@tanstack/react-table").TableFeature;
|
|
107
|
-
rowSortingFeature: import("@tanstack/react-table").TableFeature;
|
|
108
|
-
sortedRowModel: (table: import("@tanstack/react-table").Table<any, any>) => () => import("@tanstack/react-table").RowModel<any, any>;
|
|
109
|
-
sortFns: {
|
|
110
|
-
alphanumeric: import("@tanstack/react-table").CreatedSortFn<any, any>;
|
|
111
|
-
basic: import("@tanstack/react-table").CreatedSortFn<any, any>;
|
|
112
|
-
datetime: import("@tanstack/react-table").CreatedSortFn<any, any>;
|
|
113
|
-
text: import("@tanstack/react-table").CreatedSortFn<any, any>;
|
|
114
|
-
};
|
|
115
|
-
}, TRow, import("@tanstack/react-table").TableState_CellSelection & import("@tanstack/react-table").TableState_ColumnResizing & import("@tanstack/react-table").TableState_ColumnSizing & import("@tanstack/react-table").TableState_RowSelection & import("@tanstack/react-table").TableState_RowSorting>;
|
|
116
|
-
commitCells: (edits: readonly DataGridEdit[], reason?: DataGridEditReason) => DataGridCommitResult<TRow>;
|
|
117
|
-
};
|