@pushwoosh/smart-components-kit 1.0.54 → 1.0.56
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/SystemParcel/SystemParcel.d.ts +9 -0
- package/SystemParcel/SystemParcel.js +46 -0
- package/SystemParcel/helpers.d.ts +7 -0
- package/SystemParcel/helpers.js +14 -0
- package/SystemParcel/index.d.ts +2 -0
- package/SystemParcel/index.js +2 -0
- package/Table/components/DataTable/DataTable.js +19 -14
- package/Table/components/DataTable/types.d.ts +6 -0
- package/Table/hooks/useDataTableGetParams.js +1 -1
- package/Table/styles.d.ts +1 -0
- package/Table/styles.js +3 -1
- package/index.d.ts +1 -0
- package/index.js +2 -1
- package/package.json +1 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
type SystemParcelProps = {
|
|
3
|
+
importPath: string;
|
|
4
|
+
methodName?: string;
|
|
5
|
+
mountRootParcel: any;
|
|
6
|
+
Parcel: React.ComponentType<any>;
|
|
7
|
+
} & Record<string, unknown>;
|
|
8
|
+
export declare function SystemParcel({ importPath, mountRootParcel, methodName, Parcel, ...restProps }: SystemParcelProps): React.JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import { useSPAContext } from '../context';
|
|
3
|
+
export function SystemParcel({
|
|
4
|
+
importPath,
|
|
5
|
+
mountRootParcel,
|
|
6
|
+
methodName = 'parcel',
|
|
7
|
+
Parcel,
|
|
8
|
+
...restProps
|
|
9
|
+
}) {
|
|
10
|
+
const spaContext = useSPAContext();
|
|
11
|
+
const parcelConfig = useMemo(() => createSystemParcelConfig(importPath, methodName), [importPath, methodName]);
|
|
12
|
+
return React.createElement(Parcel, {
|
|
13
|
+
config: parcelConfig,
|
|
14
|
+
spaContext: spaContext,
|
|
15
|
+
mountParcel: mountRootParcel,
|
|
16
|
+
...restProps
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
function createSystemParcelConfig(importPath, methodName) {
|
|
20
|
+
let parcel;
|
|
21
|
+
return {
|
|
22
|
+
bootstrap({
|
|
23
|
+
domElement
|
|
24
|
+
}) {
|
|
25
|
+
return System.import(importPath).then(module => {
|
|
26
|
+
const factory = module[methodName];
|
|
27
|
+
if (typeof factory !== 'function') {
|
|
28
|
+
throw new Error(`Method "${methodName}" is not a function in module "${importPath}"`);
|
|
29
|
+
}
|
|
30
|
+
parcel = factory(domElement);
|
|
31
|
+
});
|
|
32
|
+
},
|
|
33
|
+
mount(props) {
|
|
34
|
+
parcel.render(props);
|
|
35
|
+
return Promise.resolve();
|
|
36
|
+
},
|
|
37
|
+
unmount() {
|
|
38
|
+
parcel.unmount();
|
|
39
|
+
return Promise.resolve();
|
|
40
|
+
},
|
|
41
|
+
update(props) {
|
|
42
|
+
parcel.render(props);
|
|
43
|
+
return Promise.resolve();
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type ReactElement } from 'react';
|
|
2
|
+
type ParcelResult<T> = {
|
|
3
|
+
render: (props: T) => void;
|
|
4
|
+
unmount: () => void;
|
|
5
|
+
};
|
|
6
|
+
export declare function createParcelFunction<T>(render: (props: T) => ReactElement): (container: HTMLElement) => ParcelResult<T>;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createRoot } from 'react-dom/client';
|
|
2
|
+
export function createParcelFunction(render) {
|
|
3
|
+
return container => {
|
|
4
|
+
const root = createRoot(container);
|
|
5
|
+
return {
|
|
6
|
+
render(props) {
|
|
7
|
+
root.render(render(props));
|
|
8
|
+
},
|
|
9
|
+
unmount() {
|
|
10
|
+
root.unmount();
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -13,11 +13,14 @@ export function DataTable(props) {
|
|
|
13
13
|
const {
|
|
14
14
|
columns,
|
|
15
15
|
width,
|
|
16
|
+
bgColor,
|
|
16
17
|
isBordered = true,
|
|
17
18
|
paginationPadding,
|
|
18
19
|
context,
|
|
20
|
+
allLimits,
|
|
19
21
|
renderTableTop,
|
|
20
22
|
renderAfter,
|
|
23
|
+
onClearRequest,
|
|
21
24
|
hidePagination,
|
|
22
25
|
hidePageSizeSelector
|
|
23
26
|
} = props;
|
|
@@ -26,16 +29,27 @@ export function DataTable(props) {
|
|
|
26
29
|
params
|
|
27
30
|
} = context;
|
|
28
31
|
const isFiltered = ((_data$value = data.value) === null || _data$value === void 0 ? void 0 : _data$value.isFiltered) || params.search;
|
|
32
|
+
const onClearRequestDefault = () => {
|
|
33
|
+
const keys = ['perPage', 'order', 'direction'];
|
|
34
|
+
context.onChangeParams(keys.reduce((acc, key) => ({
|
|
35
|
+
...acc,
|
|
36
|
+
[key]: context.params[key]
|
|
37
|
+
}), {
|
|
38
|
+
page: 1,
|
|
39
|
+
search: ''
|
|
40
|
+
}));
|
|
41
|
+
};
|
|
29
42
|
return React.createElement(DataTableContext.Provider, {
|
|
30
43
|
value: context
|
|
31
44
|
}, React.createElement(Table, {
|
|
32
45
|
columns: columns,
|
|
33
46
|
width: width,
|
|
34
|
-
isBordered: isBordered
|
|
47
|
+
isBordered: isBordered,
|
|
48
|
+
"$bgColor": bgColor
|
|
35
49
|
}, renderTableTop === null || renderTableTop === void 0 ? void 0 : renderTableTop(context), 'renderHead' in props && props.renderHead(), 'renderList' in props ? props.renderList(context) : React.createElement(DataTableList, {
|
|
36
50
|
renderItem: props.renderItem
|
|
37
51
|
}), !hidePagination && React.createElement(DataTablePagination, {
|
|
38
|
-
allLimits: [10, 20, 50, 100],
|
|
52
|
+
allLimits: allLimits ?? [10, 20, 50, 100],
|
|
39
53
|
padding: paginationPadding,
|
|
40
54
|
hidePageSizeSelector: hidePageSizeSelector
|
|
41
55
|
}, data.loading && React.createElement(Horizontal, {
|
|
@@ -58,23 +72,14 @@ export function DataTable(props) {
|
|
|
58
72
|
"$gap": 4
|
|
59
73
|
}, "Result:", React.createElement(LockedText, null, `${(_data$value3 = data.value) === null || _data$value3 === void 0 ? void 0 : _data$value3.total} item${(((_data$value4 = data.value) === null || _data$value4 === void 0 ? void 0 : _data$value4.total) ?? 0) > 1 ? 's' : ''}`)), !data.loading && !data.error && (((_data$value5 = data.value) === null || _data$value5 === void 0 ? void 0 : _data$value5.total) ?? 0) === 0 && !isFiltered && React.createElement(Horizontal, {
|
|
60
74
|
"$placeItems": "center"
|
|
61
|
-
}, React.createElement(LockedText, null, "No items yet")), !data.loading &&
|
|
75
|
+
}, React.createElement(LockedText, null, "No items yet")), !data.loading && isFiltered && React.createElement(Horizontal, {
|
|
62
76
|
"$gap": 16
|
|
63
|
-
}, !data.error && React.createElement(Horizontal, {
|
|
77
|
+
}, !data.error && (((_data$value6 = data.value) === null || _data$value6 === void 0 || (_data$value6 = _data$value6.items) === null || _data$value6 === void 0 ? void 0 : _data$value6.length) ?? 0) === 0 && React.createElement(Horizontal, {
|
|
64
78
|
"$placeItems": "center",
|
|
65
79
|
"$gap": 4
|
|
66
80
|
}, "Result:", React.createElement(LockedText, null, "No match found")), React.createElement(Button, {
|
|
67
81
|
color: "primary",
|
|
68
82
|
view: "ghost",
|
|
69
|
-
onClick:
|
|
70
|
-
const keys = ['perPage', 'order', 'direction'];
|
|
71
|
-
context.onChangeParams(keys.reduce((acc, key) => ({
|
|
72
|
-
...acc,
|
|
73
|
-
[key]: context.params[key]
|
|
74
|
-
}), {
|
|
75
|
-
page: 1,
|
|
76
|
-
search: ''
|
|
77
|
-
}));
|
|
78
|
-
}
|
|
83
|
+
onClick: onClearRequest ?? onClearRequestDefault
|
|
79
84
|
}, "Clear request")))), renderAfter === null || renderAfter === void 0 ? void 0 : renderAfter(context));
|
|
80
85
|
}
|
|
@@ -4,25 +4,31 @@ export type DataTableListProps<I, P extends DataTableParams> = {
|
|
|
4
4
|
columns: string;
|
|
5
5
|
width?: string | number;
|
|
6
6
|
isBordered?: boolean;
|
|
7
|
+
bgColor?: string;
|
|
7
8
|
context: DataTableContextType<I, P>;
|
|
8
9
|
hidePagination?: boolean;
|
|
9
10
|
hidePageSizeSelector?: boolean;
|
|
10
11
|
paginationPadding?: string;
|
|
12
|
+
allLimits?: number[];
|
|
11
13
|
renderTableTop?: (ctxValue: DataTableContextType<I, P>) => ReactNode;
|
|
12
14
|
renderList: (ctxValue: DataTableContextType<I, P>) => ReactNode;
|
|
13
15
|
renderAfter?: (ctxValue: DataTableContextType<I, P>) => ReactNode;
|
|
16
|
+
onClearRequest?: () => void;
|
|
14
17
|
};
|
|
15
18
|
export type DataTableItemProps<I, P extends DataTableParams> = {
|
|
16
19
|
columns: string;
|
|
17
20
|
width?: string | number;
|
|
18
21
|
isBordered?: boolean;
|
|
22
|
+
bgColor?: string;
|
|
19
23
|
context: DataTableContextType<I, P>;
|
|
20
24
|
hidePagination?: boolean;
|
|
21
25
|
hidePageSizeSelector?: boolean;
|
|
22
26
|
paginationPadding?: string;
|
|
27
|
+
allLimits?: number[];
|
|
23
28
|
renderTableTop?: (ctxValue: DataTableContextType<I, P>) => ReactNode;
|
|
24
29
|
renderHead: () => ReactNode;
|
|
25
30
|
renderItem: (item: I) => ReactNode;
|
|
26
31
|
renderAfter?: (ctxValue: DataTableContextType<I, P>) => ReactNode;
|
|
32
|
+
onClearRequest?: () => void;
|
|
27
33
|
};
|
|
28
34
|
export type DataTableProps<I, P extends DataTableParams> = DataTableListProps<I, P> | DataTableItemProps<I, P>;
|
|
@@ -39,7 +39,7 @@ export function useDataTableGetParams({
|
|
|
39
39
|
const searchParams = new URLSearchParams(locationSearch);
|
|
40
40
|
const paramsWithPrefix = mapKeys(params, key => `${prefix}${key}`);
|
|
41
41
|
for (const [key, value] of Object.entries(paramsWithPrefix)) {
|
|
42
|
-
if (value === undefined || value === null || value === '') {
|
|
42
|
+
if (value === undefined || value === null || value === '' || Array.isArray(value) && value.length === 0) {
|
|
43
43
|
searchParams.delete(key);
|
|
44
44
|
} else {
|
|
45
45
|
searchParams.set(key, String(value));
|
package/Table/styles.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export type TableProps = {
|
|
|
3
3
|
columns: string;
|
|
4
4
|
width?: string | number;
|
|
5
5
|
isBordered?: boolean;
|
|
6
|
+
$bgColor?: string;
|
|
6
7
|
};
|
|
7
8
|
export declare const Table: import("styled-components").StyledComponent<"div", any, {
|
|
8
9
|
$alignContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
|
package/Table/styles.js
CHANGED
|
@@ -8,7 +8,9 @@ export const Table = styled(Vertical).withConfig({
|
|
|
8
8
|
columns
|
|
9
9
|
}) => columns, ({
|
|
10
10
|
isBordered
|
|
11
|
-
}) => isBordered ? `1px solid ${Color.DIVIDER}` : 'none', ShapeRadius.SECTION,
|
|
11
|
+
}) => isBordered ? `1px solid ${Color.DIVIDER}` : 'none', ShapeRadius.SECTION, ({
|
|
12
|
+
$bgColor
|
|
13
|
+
}) => $bgColor ?? Color.CLEAR, ({
|
|
12
14
|
width
|
|
13
15
|
}) => width ? `width: ${toCssValue(width)};` : '', Color.DIVIDER);
|
|
14
16
|
export const Td = styled(GridContainer).attrs({
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
package/package.json
CHANGED