musae 0.2.2 → 0.2.4
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 +1 -1
- package/dist/components/avatar/avatar.js +1 -1
- package/dist/components/avatar/context.d.ts +0 -1
- package/dist/components/breadcrumb/breadcrumb.js +1 -1
- package/dist/components/breadcrumb/item.js +1 -1
- package/dist/components/button/button.js +1 -1
- package/dist/components/button-toggle/context.d.ts +0 -1
- package/dist/components/calendar/calendar.js +1 -1
- package/dist/components/calendar/hooks.js +1 -1
- package/dist/components/cascader/hooks.d.ts +1 -8
- package/dist/components/cascader/utils.d.ts +0 -1
- package/dist/components/checkbox/checkbox.js +4 -3
- package/dist/components/checkbox/context.d.ts +0 -1
- package/dist/components/checkbox/index.d.ts +0 -1
- package/dist/components/clock/column.js +1 -1
- package/dist/components/collapse/collapse.d.ts +4 -0
- package/dist/components/collapse/collapse.js +97 -0
- package/dist/components/collapse/context.d.ts +6 -0
- package/dist/components/collapse/context.js +12 -0
- package/dist/components/collapse/hooks.d.ts +12 -0
- package/dist/components/collapse/hooks.js +43 -0
- package/dist/components/collapse/index.d.ts +2 -0
- package/dist/components/collapse/item.d.ts +4 -0
- package/dist/components/collapse/item.js +144 -0
- package/dist/components/collapse/types.d.ts +87 -0
- package/dist/components/config/context.d.ts +0 -1
- package/dist/components/date-picker/date-picker.js +1 -1
- package/dist/components/date-picker/hooks.d.ts +1 -5
- package/dist/components/date-range-picker/hooks.d.ts +1 -5
- package/dist/components/dialog/hooks.d.ts +1 -5
- package/dist/components/dialog/popup.js +2 -2
- package/dist/components/divider/divider.js +1 -1
- package/dist/components/drawer/popup.js +2 -2
- package/dist/components/empty/empty.js +1 -1
- package/dist/components/form/context.d.ts +0 -1
- package/dist/components/form/field/field.d.ts +1 -1
- package/dist/components/form/field/field.js +8 -7
- package/dist/components/form/field/layout.js +1 -1
- package/dist/components/grid/col.js +1 -1
- package/dist/components/grid/index.d.ts +0 -1
- package/dist/components/grid/row.js +1 -1
- package/dist/components/icon/icon.js +2 -2
- package/dist/components/icon/icons/index.js +1 -0
- package/dist/components/icon/icons/navigation/index.d.ts +2 -1
- package/dist/components/icon/icons/navigation/index.js +1 -0
- package/dist/components/icon/icons/navigation/unfold-more.d.ts +3 -0
- package/dist/components/icon/icons/navigation/unfold-more.js +10 -0
- package/dist/components/image/index.d.ts +0 -1
- package/dist/components/image/preview/context.d.ts +0 -1
- package/dist/components/image/preview/operations.js +1 -1
- package/dist/components/image/preview/preview.js +1 -1
- package/dist/components/input/input.d.ts +20 -20
- package/dist/components/input/input.js +3 -11
- package/dist/components/layout/header.js +1 -1
- package/dist/components/layout/layout.js +1 -1
- package/dist/components/layout/main.d.ts +0 -1
- package/dist/components/loading/loading.d.ts +1 -1
- package/dist/components/loading/loading.js +70 -5
- package/dist/components/loading/types.d.ts +13 -0
- package/dist/components/menu/context.d.ts +0 -1
- package/dist/components/menu/group.d.ts +2 -2
- package/dist/components/menu/group.js +1 -1
- package/dist/components/menu/hooks.js +1 -1
- package/dist/components/menu/item.d.ts +1 -1
- package/dist/components/menu/item.js +1 -1
- package/dist/components/notification/holder.js +1 -1
- package/dist/components/notification/notification.js +1 -1
- package/dist/components/pagination/hooks.d.ts +2 -3
- package/dist/components/picker/context.d.ts +0 -1
- package/dist/components/picker/picker.js +1 -1
- package/dist/components/popover/popover.js +1 -1
- package/dist/components/popper/dropdown.js +1 -1
- package/dist/components/popper/hooks.d.ts +3 -3
- package/dist/components/progress/circular.js +1 -1
- package/dist/components/progress/hooks.d.ts +0 -1
- package/dist/components/progress/linear.js +1 -1
- package/dist/components/radio/context.d.ts +0 -1
- package/dist/components/radio/radio.js +22 -13
- package/dist/components/rate/rate.js +1 -1
- package/dist/components/rate/star.js +12 -14
- package/dist/components/ripple/hooks.js +4 -1
- package/dist/components/ripple/ripple.js +1 -1
- package/dist/components/select/selector.js +1 -1
- package/dist/components/select/utils.d.ts +0 -1
- package/dist/components/space/space.js +1 -1
- package/dist/components/steps/context.d.ts +0 -1
- package/dist/components/steps/item.js +1 -1
- package/dist/components/steps/steps.js +1 -1
- package/dist/components/switch/switch.js +1 -1
- package/dist/components/table/body.js +36 -4
- package/dist/components/table/context.d.ts +6 -1
- package/dist/components/table/context.js +10 -2
- package/dist/components/table/header/cell.d.ts +3 -0
- package/dist/components/table/header/cell.js +129 -0
- package/dist/components/table/{header.d.ts → header/header.d.ts} +1 -1
- package/dist/components/table/{header.js → header/header.js} +37 -10
- package/dist/components/table/hooks.d.ts +8 -21
- package/dist/components/table/hooks.js +36 -58
- package/dist/components/table/table.d.ts +1 -1
- package/dist/components/table/table.js +12 -6
- package/dist/components/table/types.d.ts +72 -4
- package/dist/components/tabs/context.d.ts +0 -1
- package/dist/components/tabs/item.js +3 -1
- package/dist/components/tabs/tabs.js +1 -1
- package/dist/components/tag/tag.js +1 -1
- package/dist/components/theme/hooks.d.ts +1 -2
- package/dist/components/time-picker/panel.js +1 -1
- package/dist/components/time-picker/time-picker.js +1 -1
- package/dist/components/timeline/context.d.ts +0 -1
- package/dist/components/timeline/item.js +1 -1
- package/dist/components/tour/tour.js +1 -1
- package/dist/components/tree/context.d.ts +0 -1
- package/dist/components/tree/hooks.d.ts +0 -1
- package/dist/components/tree/list.js +1 -1
- package/dist/components/tree/node.js +1 -1
- package/dist/components/upload/types.d.ts +8 -6
- package/dist/components/upload/upload.d.ts +1 -1
- package/dist/components/upload/upload.js +11 -4
- package/dist/components/upload/uploadeds.js +8 -3
- package/dist/components/waterfall/hooks.d.ts +1 -3
- package/dist/components/waterfall/hooks.js +2 -8
- package/dist/components/waterfall/sequential.js +1 -1
- package/dist/components/waterfall/waterfall.js +10 -6
- package/dist/components/watermark/types.d.ts +1 -1
- package/dist/components/watermark/watermark.js +1 -1
- package/dist/hooks/use-class-names.d.ts +15 -0
- package/dist/hooks/use-expand-effect.d.ts +1 -1
- package/dist/hooks/use-expand-effect.js +12 -8
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/stylex.css +22 -7
- package/dist/utils/class-name.d.ts +42 -184
- package/dist/utils/class-name.js +39 -5
- package/dist/utils/styles.d.ts +1 -1
- package/package.json +15 -15
- /package/dist/node_modules/{@aiszlab → .pnpm/@aiszlab_relax@1.2.55_react-dom@18.3.1_react@18.3.1/node_modules/@aiszlab}/relax/dist/dom/contains.js +0 -0
- /package/dist/node_modules/{@stylexjs → .pnpm/@stylexjs_stylex@0.6.1/node_modules/@stylexjs}/stylex/lib/es/stylex.js +0 -0
|
@@ -1,72 +1,50 @@
|
|
|
1
1
|
import { createColumnHelper } from '@tanstack/react-table';
|
|
2
|
-
import { useRef, useMemo,
|
|
3
|
-
import
|
|
2
|
+
import { useRef, useMemo, createElement } from 'react';
|
|
3
|
+
import Cell from './header/cell.js';
|
|
4
|
+
import { useControlledState, useEvent } from '@aiszlab/relax';
|
|
4
5
|
|
|
5
|
-
const styles = {
|
|
6
|
-
cell: props => [{
|
|
7
|
-
paddingInline: "musae-iujutg",
|
|
8
|
-
paddingStart: null,
|
|
9
|
-
paddingLeft: null,
|
|
10
|
-
paddingEnd: null,
|
|
11
|
-
paddingRight: null,
|
|
12
|
-
paddingBlock: "musae-avjae4",
|
|
13
|
-
paddingTop: null,
|
|
14
|
-
paddingBottom: null,
|
|
15
|
-
borderColor: "musae-eqt46j",
|
|
16
|
-
borderInlineColor: null,
|
|
17
|
-
borderInlineStartColor: null,
|
|
18
|
-
borderLeftColor: null,
|
|
19
|
-
borderInlineEndColor: null,
|
|
20
|
-
borderRightColor: null,
|
|
21
|
-
borderBlockColor: null,
|
|
22
|
-
borderTopColor: null,
|
|
23
|
-
borderBottomColor: null,
|
|
24
|
-
borderStyle: "musae-1y0btm7",
|
|
25
|
-
borderInlineStyle: null,
|
|
26
|
-
borderInlineStartStyle: null,
|
|
27
|
-
borderLeftStyle: null,
|
|
28
|
-
borderInlineEndStyle: null,
|
|
29
|
-
borderRightStyle: null,
|
|
30
|
-
borderBlockStyle: null,
|
|
31
|
-
borderTopStyle: null,
|
|
32
|
-
borderBottomStyle: null,
|
|
33
|
-
borderBottomWidth: "musae-lntmim",
|
|
34
|
-
$$css: true
|
|
35
|
-
}, {
|
|
36
|
-
"--borderColor": props.outlineColor != null ? props.outlineColor : "initial"
|
|
37
|
-
}]
|
|
38
|
-
};
|
|
39
6
|
/**
|
|
40
7
|
* @description
|
|
41
8
|
* use columns
|
|
42
9
|
*/
|
|
43
|
-
const useColumns = (
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
10
|
+
const useColumns = ({ columns }) => {
|
|
11
|
+
const helper = useRef(createColumnHelper());
|
|
12
|
+
return useMemo(() => {
|
|
13
|
+
return columns.map(({ key, render, title, sortable = false, sortDirections = ["ascending", "descending"] }) => {
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
return helper.current.accessor(key, {
|
|
16
|
+
header: createElement(Cell, { children: title, sortable, value: key, sortDirections }),
|
|
17
|
+
cell: (_context) => {
|
|
18
|
+
const value = _context.getValue();
|
|
19
|
+
if (!render) {
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
return render(value, _context.row.original, _context.row.index);
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
}, [columns]);
|
|
56
27
|
};
|
|
57
28
|
/**
|
|
58
29
|
* @author murukal
|
|
59
30
|
* @description
|
|
60
31
|
* for context value
|
|
61
32
|
*/
|
|
62
|
-
const useContextValue = ({
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
33
|
+
const useContextValue = ({ table: _table, bordered, sortDescriptor: _sortDescriptor, onSortChange: _onSortChange, }) => {
|
|
34
|
+
const [sortDescriptor, setSortDescriptor] = useControlledState(_sortDescriptor);
|
|
35
|
+
// sort change handler
|
|
36
|
+
const onSortChange = useEvent((sortDescriptor) => {
|
|
37
|
+
setSortDescriptor(sortDescriptor);
|
|
38
|
+
_onSortChange?.(sortDescriptor);
|
|
39
|
+
});
|
|
40
|
+
return useMemo(() => ({
|
|
41
|
+
// @ts-ignore
|
|
42
|
+
table: _table,
|
|
43
|
+
bordered,
|
|
44
|
+
// sort descriptor
|
|
45
|
+
sortDescriptor,
|
|
46
|
+
onSortChange,
|
|
47
|
+
}), [_table, bordered, sortDescriptor, onSortChange]);
|
|
70
48
|
};
|
|
71
49
|
|
|
72
|
-
export {
|
|
50
|
+
export { useColumns, useContextValue };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import type { TableProps } from "./types";
|
|
3
|
-
declare const Table: <T>({ bordered, dataSource,
|
|
3
|
+
declare const Table: <T>({ bordered, dataSource, columns: _columns, sortDescriptor, onSortChange, }: TableProps<T>) => React.JSX.Element;
|
|
4
4
|
export default Table;
|
|
@@ -1,30 +1,36 @@
|
|
|
1
1
|
import { useReactTable, getCoreRowModel } from '@tanstack/react-table';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { useColumns, useContextValue } from './hooks.js';
|
|
4
|
-
import Header from './header.js';
|
|
4
|
+
import Header from './header/header.js';
|
|
5
5
|
import Context from './context.js';
|
|
6
6
|
import Body from './body.js';
|
|
7
7
|
|
|
8
8
|
const Table = ({
|
|
9
9
|
bordered = false,
|
|
10
10
|
dataSource = [],
|
|
11
|
-
|
|
11
|
+
columns: _columns = [],
|
|
12
|
+
sortDescriptor,
|
|
13
|
+
onSortChange
|
|
12
14
|
}) => {
|
|
13
|
-
const columns = useColumns(
|
|
15
|
+
const columns = useColumns({
|
|
16
|
+
columns: _columns
|
|
17
|
+
});
|
|
14
18
|
const table = useReactTable({
|
|
15
|
-
columns
|
|
19
|
+
columns,
|
|
16
20
|
data: dataSource,
|
|
17
21
|
getCoreRowModel: getCoreRowModel()
|
|
18
22
|
});
|
|
19
23
|
const contextValue = useContextValue({
|
|
20
24
|
table,
|
|
21
|
-
bordered
|
|
25
|
+
bordered,
|
|
26
|
+
sortDescriptor,
|
|
27
|
+
onSortChange
|
|
22
28
|
});
|
|
23
29
|
return React.createElement(Context.Provider, {
|
|
24
30
|
value: contextValue
|
|
25
31
|
}, React.createElement("table", {
|
|
26
32
|
...{
|
|
27
|
-
className: "musae-
|
|
33
|
+
className: "musae-h8yej3"
|
|
28
34
|
}
|
|
29
35
|
}, React.createElement(Header, null), React.createElement(Body, null)));
|
|
30
36
|
};
|
|
@@ -1,6 +1,44 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { DeepKeys } from "@tanstack/react-table";
|
|
2
2
|
import type { Table } from "@tanstack/react-table";
|
|
3
3
|
import type { ComponentProps } from "../../types/element";
|
|
4
|
+
import type { Key, ReactNode } from "react";
|
|
5
|
+
export type SortDirection = "ascending" | "descending" | null;
|
|
6
|
+
export type SortDescriptor = {
|
|
7
|
+
key: Key;
|
|
8
|
+
direction: SortDirection;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* @description
|
|
12
|
+
* column def
|
|
13
|
+
*/
|
|
14
|
+
export type Column<T, V = unknown> = {
|
|
15
|
+
/**
|
|
16
|
+
* @description
|
|
17
|
+
* key
|
|
18
|
+
*/
|
|
19
|
+
key: DeepKeys<T>;
|
|
20
|
+
/**
|
|
21
|
+
* @description
|
|
22
|
+
* title
|
|
23
|
+
*/
|
|
24
|
+
title: ReactNode | (() => ReactNode);
|
|
25
|
+
/**
|
|
26
|
+
* @description
|
|
27
|
+
* custom render, render is not provided, just render value
|
|
28
|
+
*/
|
|
29
|
+
render?: (value: V, record: T, index: number) => ReactNode | unknown;
|
|
30
|
+
/**
|
|
31
|
+
* @description
|
|
32
|
+
* enable sort
|
|
33
|
+
* @default false
|
|
34
|
+
*/
|
|
35
|
+
sortable?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* @description
|
|
38
|
+
* allowed sort orders
|
|
39
|
+
*/
|
|
40
|
+
sortDirections?: SortDirection[];
|
|
41
|
+
};
|
|
4
42
|
/**
|
|
5
43
|
* @description
|
|
6
44
|
* table props
|
|
@@ -14,17 +52,28 @@ export type TableProps<T> = {
|
|
|
14
52
|
dataSource?: T[];
|
|
15
53
|
/**
|
|
16
54
|
* @description
|
|
17
|
-
*
|
|
18
|
-
* so in musae, we use this function to create columns
|
|
55
|
+
* columns
|
|
19
56
|
* @default void 0
|
|
20
57
|
*/
|
|
21
|
-
columns?:
|
|
58
|
+
columns?: Column<T>[];
|
|
22
59
|
/**
|
|
23
60
|
* @description
|
|
24
61
|
* bordered
|
|
25
62
|
* @default false
|
|
26
63
|
*/
|
|
27
64
|
bordered?: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* @description
|
|
67
|
+
* sort descriptor
|
|
68
|
+
* @default void 0
|
|
69
|
+
*/
|
|
70
|
+
sortDescriptor?: SortDescriptor;
|
|
71
|
+
/**
|
|
72
|
+
* @description
|
|
73
|
+
* callback when table has changed, like sort
|
|
74
|
+
* @default void 0
|
|
75
|
+
*/
|
|
76
|
+
onSortChange?: (sortDescriptor: SortDescriptor) => void;
|
|
28
77
|
};
|
|
29
78
|
/**
|
|
30
79
|
* @author murukal
|
|
@@ -42,6 +91,15 @@ export type ContextValue<T> = {
|
|
|
42
91
|
* if current table is bordered
|
|
43
92
|
*/
|
|
44
93
|
bordered: boolean;
|
|
94
|
+
/**
|
|
95
|
+
* {@link} `SortDescriptor`
|
|
96
|
+
*/
|
|
97
|
+
sortDescriptor?: SortDescriptor;
|
|
98
|
+
/**
|
|
99
|
+
* @description
|
|
100
|
+
* `SortDescriptor` Setter
|
|
101
|
+
*/
|
|
102
|
+
onSortChange?: (sortDescriptor: SortDescriptor) => void;
|
|
45
103
|
};
|
|
46
104
|
/**
|
|
47
105
|
* @description
|
|
@@ -53,3 +111,13 @@ export type HeaderProps = ComponentProps;
|
|
|
53
111
|
* body props
|
|
54
112
|
*/
|
|
55
113
|
export type BodyProps = ComponentProps;
|
|
114
|
+
/**
|
|
115
|
+
* @description
|
|
116
|
+
* header cell props
|
|
117
|
+
*/
|
|
118
|
+
export type HeaderCellProps = {
|
|
119
|
+
sortable?: boolean;
|
|
120
|
+
children: ReactNode | (() => ReactNode);
|
|
121
|
+
value: Key;
|
|
122
|
+
sortDirections: SortDirection[];
|
|
123
|
+
};
|
|
@@ -14,7 +14,9 @@ const Item = ({ value, onClick, ...props }) => {
|
|
|
14
14
|
const click = useCallback(() => {
|
|
15
15
|
onClick(value);
|
|
16
16
|
}, [onClick, value]);
|
|
17
|
-
return (React.createElement(Button, { variant: "text", color: isActive ? "primary" : "secondary", ref: setItem, onClick: click, className: classNames[TabsClassToken.Item], ripple: false
|
|
17
|
+
return (React.createElement(Button, { variant: "text", color: isActive ? "primary" : "secondary", ref: setItem, onClick: click, className: classNames[TabsClassToken.Item], ripple: false, style: {
|
|
18
|
+
borderRadius: "10% 10% 0 0",
|
|
19
|
+
} }, props.label));
|
|
18
20
|
};
|
|
19
21
|
|
|
20
22
|
export { Item as default };
|
|
@@ -3,7 +3,7 @@ import { useControlledState, useMounted } from '@aiszlab/relax';
|
|
|
3
3
|
import { useAnimate } from 'framer-motion';
|
|
4
4
|
import Context from './context.js';
|
|
5
5
|
import Item from './item.js';
|
|
6
|
-
import { props } from '../../node_modules/@stylexjs/stylex/lib/es/stylex.js';
|
|
6
|
+
import { props } from '../../node_modules/.pnpm/@stylexjs_stylex@0.6.1/node_modules/@stylexjs/stylex/lib/es/stylex.js';
|
|
7
7
|
import { useTheme } from '../theme/hooks.js';
|
|
8
8
|
import { ColorToken } from '../../utils/colors.js';
|
|
9
9
|
import { useClassNames } from '../../hooks/use-class-names.js';
|
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import clsx from 'clsx';
|
|
3
3
|
import { useClassNames } from '../../hooks/use-class-names.js';
|
|
4
4
|
import { ComponentToken, TagClassToken } from '../../utils/class-name.js';
|
|
5
|
-
import { props } from '../../node_modules/@stylexjs/stylex/lib/es/stylex.js';
|
|
5
|
+
import { props } from '../../node_modules/.pnpm/@stylexjs_stylex@0.6.1/node_modules/@stylexjs/stylex/lib/es/stylex.js';
|
|
6
6
|
import { useTheme } from '../theme/hooks.js';
|
|
7
7
|
import { typography } from '../theme/theme.js';
|
|
8
8
|
import { ColorToken } from '../../utils/colors.js';
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import type { Palette, ContextValue, Theme, Mode } from "./types";
|
|
3
2
|
export declare const PALETTE: Readonly<Palette>;
|
|
4
3
|
/**
|
|
@@ -28,6 +27,6 @@ export declare const useSwitchable: ({ theme }: {
|
|
|
28
27
|
theme: Theme;
|
|
29
28
|
}) => {
|
|
30
29
|
mode: Mode;
|
|
31
|
-
toggle: (event: import("react").MouseEvent
|
|
30
|
+
toggle: (event: import("react").MouseEvent) => void;
|
|
32
31
|
colors: Record<import("../../utils/colors").ColorToken, string>;
|
|
33
32
|
};
|
|
@@ -4,7 +4,7 @@ import { useClassNames } from '../../hooks/use-class-names.js';
|
|
|
4
4
|
import { ComponentToken, TimePickerClassToken } from '../../utils/class-name.js';
|
|
5
5
|
import Button from '../button/button.js';
|
|
6
6
|
import dayjs from 'dayjs';
|
|
7
|
-
import { props } from '../../node_modules/@stylexjs/stylex/lib/es/stylex.js';
|
|
7
|
+
import { props } from '../../node_modules/.pnpm/@stylexjs_stylex@0.6.1/node_modules/@stylexjs/stylex/lib/es/stylex.js';
|
|
8
8
|
import { useTheme } from '../theme/hooks.js';
|
|
9
9
|
import { ColorToken } from '../../utils/colors.js';
|
|
10
10
|
import clsx from 'clsx';
|
|
@@ -5,7 +5,7 @@ import { useClassNames } from '../../hooks/use-class-names.js';
|
|
|
5
5
|
import { ComponentToken, TimePickerClassToken } from '../../utils/class-name.js';
|
|
6
6
|
import Panel from './panel.js';
|
|
7
7
|
import { useValue } from './hooks.js';
|
|
8
|
-
import { props } from '../../node_modules/@stylexjs/stylex/lib/es/stylex.js';
|
|
8
|
+
import { props } from '../../node_modules/.pnpm/@stylexjs_stylex@0.6.1/node_modules/@stylexjs/stylex/lib/es/stylex.js';
|
|
9
9
|
import { useEvent } from '@aiszlab/relax';
|
|
10
10
|
import { styles } from '../input/input.js';
|
|
11
11
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useContext } from 'react';
|
|
2
|
-
import _stylex from '../../node_modules/@stylexjs/stylex/lib/es/stylex.js';
|
|
2
|
+
import _stylex from '../../node_modules/.pnpm/@stylexjs_stylex@0.6.1/node_modules/@stylexjs/stylex/lib/es/stylex.js';
|
|
3
3
|
import { Context } from './context.js';
|
|
4
4
|
import { useClassNames } from '../../hooks/use-class-names.js';
|
|
5
5
|
import { ComponentToken, TimelineClassToken } from '../../utils/class-name.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import Portal from '../portal/portal.js';
|
|
3
3
|
import Popper from '../popper/popper.js';
|
|
4
|
-
import _stylex from '../../node_modules/@stylexjs/stylex/lib/es/stylex.js';
|
|
4
|
+
import _stylex from '../../node_modules/.pnpm/@stylexjs_stylex@0.6.1/node_modules/@stylexjs/stylex/lib/es/stylex.js';
|
|
5
5
|
import Button from '../button/button.js';
|
|
6
6
|
import { useTheme } from '../theme/hooks.js';
|
|
7
7
|
import { ColorToken } from '../../utils/colors.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { props } from '../../node_modules/@stylexjs/stylex/lib/es/stylex.js';
|
|
1
|
+
import { props } from '../../node_modules/.pnpm/@stylexjs_stylex@0.6.1/node_modules/@stylexjs/stylex/lib/es/stylex.js';
|
|
2
2
|
import React, { useContext } from 'react';
|
|
3
3
|
import Node from './node.js';
|
|
4
4
|
import clsx from 'clsx';
|
|
@@ -3,7 +3,7 @@ import { useClassNames } from '../../hooks/use-class-names.js';
|
|
|
3
3
|
import { ComponentToken, TreeClassToken } from '../../utils/class-name.js';
|
|
4
4
|
import Context from './context.js';
|
|
5
5
|
import { Checkbox } from '../checkbox/index.js';
|
|
6
|
-
import { props } from '../../node_modules/@stylexjs/stylex/lib/es/stylex.js';
|
|
6
|
+
import { props } from '../../node_modules/.pnpm/@stylexjs_stylex@0.6.1/node_modules/@stylexjs/stylex/lib/es/stylex.js';
|
|
7
7
|
import clsx from 'clsx';
|
|
8
8
|
import { useTheme } from '../theme/hooks.js';
|
|
9
9
|
import { ColorToken } from '../../utils/colors.js';
|
|
@@ -7,37 +7,39 @@ export type UploadProps = {
|
|
|
7
7
|
/**
|
|
8
8
|
* @description
|
|
9
9
|
* on upload wrapper click handler
|
|
10
|
+
* @default void 0
|
|
10
11
|
*/
|
|
11
|
-
onClick
|
|
12
|
+
onClick?: () => void;
|
|
12
13
|
/**
|
|
13
14
|
* @description
|
|
14
15
|
* disabled
|
|
15
|
-
*
|
|
16
16
|
* @default false
|
|
17
17
|
*/
|
|
18
18
|
disabled?: boolean;
|
|
19
19
|
/**
|
|
20
20
|
* @description
|
|
21
21
|
* multiple
|
|
22
|
-
*
|
|
23
22
|
* @default false
|
|
24
23
|
*/
|
|
25
24
|
multiple?: boolean;
|
|
26
25
|
/**
|
|
27
26
|
* @description
|
|
28
27
|
* children
|
|
28
|
+
* @default void 0
|
|
29
29
|
*/
|
|
30
30
|
children?: ReactNode;
|
|
31
31
|
/**
|
|
32
32
|
* @description
|
|
33
33
|
* uploader
|
|
34
|
+
* @default void 0
|
|
34
35
|
*/
|
|
35
|
-
uploader
|
|
36
|
+
uploader?: (file: File) => Promise<string>;
|
|
36
37
|
/**
|
|
37
38
|
* @description
|
|
38
39
|
* error
|
|
40
|
+
* @default void 0
|
|
39
41
|
*/
|
|
40
|
-
onError?: (
|
|
42
|
+
onError?: (error: unknown) => void;
|
|
41
43
|
};
|
|
42
44
|
/**
|
|
43
45
|
* @description
|
|
@@ -54,7 +56,7 @@ export type UploadedsRef = {
|
|
|
54
56
|
* @description
|
|
55
57
|
* uploaded list props
|
|
56
58
|
*/
|
|
57
|
-
export type UploadedsProps = Pick<UploadProps, "uploader">;
|
|
59
|
+
export type UploadedsProps = Pick<UploadProps, "uploader" | "onError">;
|
|
58
60
|
/**
|
|
59
61
|
* @description
|
|
60
62
|
* status
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { UploadProps } from "./types";
|
|
3
|
-
declare const Upload: ({ onClick: _onClick, disabled, multiple, children, uploader, onError }: UploadProps) => React.JSX.Element;
|
|
3
|
+
declare const Upload: ({ onClick: _onClick, disabled, multiple, children: _children, uploader, onError }: UploadProps) => React.JSX.Element;
|
|
4
4
|
export default Upload;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useRef } from 'react';
|
|
1
|
+
import React, { useRef, useMemo, cloneElement } from 'react';
|
|
2
2
|
import { useEvent } from '@aiszlab/relax';
|
|
3
3
|
import { Keyboard } from '../../utils/keyboard.js';
|
|
4
4
|
import Uploadeds from './uploadeds.js';
|
|
@@ -7,7 +7,7 @@ const Upload = ({
|
|
|
7
7
|
onClick: _onClick,
|
|
8
8
|
disabled,
|
|
9
9
|
multiple,
|
|
10
|
-
children,
|
|
10
|
+
children: _children,
|
|
11
11
|
uploader,
|
|
12
12
|
onError
|
|
13
13
|
}) => {
|
|
@@ -28,7 +28,7 @@ const Upload = ({
|
|
|
28
28
|
});
|
|
29
29
|
const onClick = useEvent(() => {
|
|
30
30
|
inputRef.current?.click();
|
|
31
|
-
_onClick();
|
|
31
|
+
_onClick?.();
|
|
32
32
|
});
|
|
33
33
|
const onKeyDown = useEvent(e => {
|
|
34
34
|
if (e.key !== Keyboard.Enter) return;
|
|
@@ -47,6 +47,12 @@ const Upload = ({
|
|
|
47
47
|
className: "musae-1s85apg"
|
|
48
48
|
}
|
|
49
49
|
};
|
|
50
|
+
const children = useMemo(() => {
|
|
51
|
+
// @ts-ignore
|
|
52
|
+
return cloneElement(_children, {
|
|
53
|
+
disabled
|
|
54
|
+
});
|
|
55
|
+
}, [_children, disabled]);
|
|
50
56
|
return React.createElement("div", null, React.createElement("div", {
|
|
51
57
|
...(!disabled && {
|
|
52
58
|
onClick,
|
|
@@ -64,7 +70,8 @@ const Upload = ({
|
|
|
64
70
|
onChange: onChange
|
|
65
71
|
}), children), React.createElement(Uploadeds, {
|
|
66
72
|
ref: uploadedsRef,
|
|
67
|
-
uploader: uploader
|
|
73
|
+
uploader: uploader,
|
|
74
|
+
onError: onError
|
|
68
75
|
}));
|
|
69
76
|
};
|
|
70
77
|
var Upload$1 = Upload;
|
|
@@ -4,7 +4,8 @@ import Loading from '../icon/icons/mock/loading.js';
|
|
|
4
4
|
import Clear from '../icon/icons/content/clear.js';
|
|
5
5
|
|
|
6
6
|
const Uploadeds = forwardRef(({
|
|
7
|
-
uploader
|
|
7
|
+
uploader,
|
|
8
|
+
onError
|
|
8
9
|
}, ref) => {
|
|
9
10
|
const [items, setItems] = useState(new Map());
|
|
10
11
|
const _counter = useRef(0);
|
|
@@ -22,17 +23,21 @@ const Uploadeds = forwardRef(({
|
|
|
22
23
|
useImperativeHandle(ref, () => {
|
|
23
24
|
return {
|
|
24
25
|
add: async file => {
|
|
26
|
+
const hasUploader = !!uploader;
|
|
27
|
+
const status = hasUploader ? "loading" : "success";
|
|
25
28
|
// push current file
|
|
26
29
|
const id = _counter.current++;
|
|
27
30
|
setItems(items => {
|
|
28
31
|
return new Map(items).set(id, {
|
|
29
32
|
file,
|
|
30
|
-
status
|
|
33
|
+
status
|
|
31
34
|
});
|
|
32
35
|
});
|
|
33
36
|
// call request by user provided
|
|
34
|
-
|
|
37
|
+
if (!hasUploader) return;
|
|
38
|
+
const url = await uploader(file).catch(error => {
|
|
35
39
|
loaded(id, "error");
|
|
40
|
+
onError?.(error);
|
|
36
41
|
return null;
|
|
37
42
|
});
|
|
38
43
|
if (!url) return;
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
/**
|
|
3
2
|
* @description
|
|
4
3
|
* repaint child
|
|
5
4
|
*/
|
|
6
|
-
export declare const useRepaint: ({ columns, rowGap
|
|
5
|
+
export declare const useRepaint: ({ columns, rowGap }: {
|
|
7
6
|
columns: number;
|
|
8
7
|
rowGap: number;
|
|
9
|
-
isSequential: boolean;
|
|
10
8
|
}) => {
|
|
11
9
|
maxHeight: number;
|
|
12
10
|
collect: (index: number, ref: HTMLDivElement | null) => void;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { useEvent
|
|
1
|
+
import { useEvent } from '@aiszlab/relax';
|
|
2
2
|
import { useRef, useState, useCallback } from 'react';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @description
|
|
6
6
|
* repaint child
|
|
7
7
|
*/
|
|
8
|
-
const useRepaint = ({ columns, rowGap
|
|
8
|
+
const useRepaint = ({ columns, rowGap }) => {
|
|
9
9
|
const items = useRef(new Map());
|
|
10
10
|
const [maxHeight, setMaxHeight] = useState(0);
|
|
11
11
|
const [orders, setOrders] = useState(new Map());
|
|
@@ -30,12 +30,6 @@ const useRepaint = ({ columns, rowGap, isSequential, }) => {
|
|
|
30
30
|
setMaxHeight(Math.max(...columnHeights));
|
|
31
31
|
setOrders(_orders);
|
|
32
32
|
});
|
|
33
|
-
useUpdateEffect(() => {
|
|
34
|
-
// no need to repaint when `sequential`
|
|
35
|
-
if (isSequential)
|
|
36
|
-
return;
|
|
37
|
-
repaint();
|
|
38
|
-
}, [rowGap]);
|
|
39
33
|
const order = useCallback((index) => {
|
|
40
34
|
return orders.get(index) ?? null;
|
|
41
35
|
}, [orders]);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useMemo } from 'react';
|
|
2
|
-
import { props } from '../../node_modules/@stylexjs/stylex/lib/es/stylex.js';
|
|
2
|
+
import { props } from '../../node_modules/.pnpm/@stylexjs_stylex@0.6.1/node_modules/@stylexjs/stylex/lib/es/stylex.js';
|
|
3
3
|
|
|
4
4
|
const styles = {
|
|
5
5
|
column: props => [{
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { props } from '../../node_modules/@stylexjs/stylex/lib/es/stylex.js';
|
|
1
|
+
import { props } from '../../node_modules/.pnpm/@stylexjs_stylex@0.6.1/node_modules/@stylexjs/stylex/lib/es/stylex.js';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { useRepaint } from './hooks.js';
|
|
4
4
|
import clsx from 'clsx';
|
|
5
5
|
import { useGutters } from '../../hooks/use-gutters.js';
|
|
6
|
-
import { useMounted } from '@aiszlab/relax';
|
|
6
|
+
import { useUpdateEffect, useMounted } from '@aiszlab/relax';
|
|
7
7
|
import Sequential from './sequential.js';
|
|
8
8
|
|
|
9
9
|
const styles = {
|
|
@@ -60,8 +60,7 @@ const Waterfall = ({
|
|
|
60
60
|
repaint
|
|
61
61
|
} = useRepaint({
|
|
62
62
|
columns,
|
|
63
|
-
rowGap
|
|
64
|
-
isSequential: sequential
|
|
63
|
+
rowGap
|
|
65
64
|
});
|
|
66
65
|
const styled = props(styles.waterfall({
|
|
67
66
|
rowGap,
|
|
@@ -69,17 +68,22 @@ const Waterfall = ({
|
|
|
69
68
|
}), !sequential && maxHeight > 0 && styles.repainted({
|
|
70
69
|
maxHeight: maxHeight
|
|
71
70
|
}));
|
|
71
|
+
useUpdateEffect(() => {
|
|
72
|
+
// no need to repaint when `sequential`
|
|
73
|
+
if (sequential) return;
|
|
74
|
+
repaint();
|
|
75
|
+
}, [rowGap]);
|
|
72
76
|
useMounted(() => {
|
|
73
77
|
// no need to observer when `sequential`
|
|
74
78
|
if (sequential) return;
|
|
75
79
|
// observer be called when the component is mounted
|
|
76
80
|
// so in waterfall we use current time to first render
|
|
77
|
-
// FIXME: repaint twice in layout effect & resize observer
|
|
78
81
|
const resizer = new ResizeObserver(() => {
|
|
79
82
|
repaint();
|
|
80
83
|
});
|
|
81
84
|
Array.from(items.current.values()).forEach(node => {
|
|
82
|
-
|
|
85
|
+
if (!node) return;
|
|
86
|
+
resizer.observe(node);
|
|
83
87
|
});
|
|
84
88
|
return () => {
|
|
85
89
|
resizer.disconnect();
|