@suphark/ui 0.34.0 → 0.38.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/CHANGELOG.md +57 -0
- package/README.md +16 -1
- package/package.json +1 -1
- package/src/components/app-shell/app-shell.tsx +8 -1
- package/src/components/shared/action-form.tsx +6 -1
- package/src/components/shared/button/button.tsx +59 -1
- package/src/components/shared/form/form-invalid-notice.tsx +226 -0
- package/src/components/shared/form-dialog.tsx +5 -1
- package/src/components/shared/ui-text.tsx +11 -0
- package/src/components/sortable/sortable-list.tsx +586 -33
- package/src/index.ts +5 -0
- package/src/lib/sortable-order.ts +25 -0
- package/src/sortable.ts +3 -0
package/src/index.ts
CHANGED
|
@@ -115,6 +115,11 @@ export {
|
|
|
115
115
|
export { FormFieldRadioCards } from "./components/shared/form/form-field-radio-cards";
|
|
116
116
|
export { FormFieldRadioGroup } from "./components/shared/form/form-field-radio-group";
|
|
117
117
|
export { FormFieldSelect, type SelectOption } from "./components/shared/form/form-field-select";
|
|
118
|
+
export {
|
|
119
|
+
FormInvalidNet,
|
|
120
|
+
type FormInvalidNotice,
|
|
121
|
+
useFormInvalidNotice,
|
|
122
|
+
} from "./components/shared/form/form-invalid-notice";
|
|
118
123
|
export { CheckboxField, LabeledField } from "./components/shared/form/labeled-field";
|
|
119
124
|
export { NumberInput } from "./components/shared/form/number-input";
|
|
120
125
|
export { SearchInput, type SearchInputProps } from "./components/shared/form/search-input";
|
|
@@ -105,6 +105,31 @@ export function moveItemToGroup(
|
|
|
105
105
|
};
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
+
/** รายการทั้งหมดเรียงตามที่แสดง: ของที่ไม่มีกลุ่มก่อน แล้วไล่ตามลำดับกลุ่ม */
|
|
109
|
+
export function flatItems(order: SortableOrder): string[] {
|
|
110
|
+
return [UNGROUPED, ...order.groups].flatMap((group) => order.items[group] ?? []);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* ลากหลายรายการพร้อมกัน (bulk): ดึงรายการใน `ids` ทั้งหมดมารวมที่ตำแหน่งของ `activeId`
|
|
115
|
+
* (ตัวที่ผู้ใช้จับลาก) เรียงตามลำดับใน `ids` — ตัวอื่นหายจากที่เดิม ไม่ว่าจะอยู่กลุ่มไหน
|
|
116
|
+
*/
|
|
117
|
+
export function gatherItems(
|
|
118
|
+
order: SortableOrder,
|
|
119
|
+
activeId: string,
|
|
120
|
+
ids: ReadonlyArray<string>,
|
|
121
|
+
): SortableOrder {
|
|
122
|
+
const present = new Set(flatItems(order));
|
|
123
|
+
const moving = ids.filter((id) => present.has(id));
|
|
124
|
+
if (moving.length <= 1 || !moving.includes(activeId)) return order;
|
|
125
|
+
const others = new Set(moving.filter((id) => id !== activeId));
|
|
126
|
+
const items: Record<string, string[]> = {};
|
|
127
|
+
for (const [group, list] of Object.entries(order.items)) {
|
|
128
|
+
items[group] = list.flatMap((id) => (others.has(id) ? [] : id === activeId ? moving : [id]));
|
|
129
|
+
}
|
|
130
|
+
return { ...order, items };
|
|
131
|
+
}
|
|
132
|
+
|
|
108
133
|
/** ลำดับเหมือนกันไหม (ใช้ตัดสินว่าต้องบันทึกหรือไม่) */
|
|
109
134
|
export function sameOrder(a: SortableOrder, b: SortableOrder): boolean {
|
|
110
135
|
if (a === b) return true;
|
package/src/sortable.ts
CHANGED
|
@@ -7,6 +7,7 @@ export {
|
|
|
7
7
|
DragHandle,
|
|
8
8
|
type SortableAnnouncementContext,
|
|
9
9
|
type SortableAnnouncements,
|
|
10
|
+
type SortableDrag,
|
|
10
11
|
SortableGroup,
|
|
11
12
|
type SortableKind,
|
|
12
13
|
SortableProvider,
|
|
@@ -17,6 +18,8 @@ export {
|
|
|
17
18
|
useSortableState,
|
|
18
19
|
} from "./components/sortable/sortable-list";
|
|
19
20
|
export {
|
|
21
|
+
flatItems,
|
|
22
|
+
gatherItems,
|
|
20
23
|
groupOfItem,
|
|
21
24
|
moveItemToGroup,
|
|
22
25
|
moveWithin,
|