@pushwoosh/smart-components-kit 0.0.1 → 0.0.3
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/asyncHelpers.d.ts +1 -0
- package/asyncHelpers.js +12 -0
- package/dynamic-content-picker/DynamicContentPicker.d.ts +12 -0
- package/dynamic-content-picker/DynamicContentPicker.js +98 -0
- package/dynamic-content-picker/DynamicContentPicker.types.d.ts +9 -0
- package/dynamic-content-picker/DynamicContentPicker.types.js +1 -0
- package/dynamic-content-picker/index.d.ts +2 -0
- package/dynamic-content-picker/index.js +1 -0
- package/package.json +15 -3
- package/parcel.d.ts +9 -0
- package/parcel.js +21 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function collectPaginatedData<T>(limit: number, fn: (limit: number, page: number) => Promise<T[]>): Promise<T[]>;
|
package/asyncHelpers.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export async function collectPaginatedData(limit, fn) {
|
|
2
|
+
const result = [];
|
|
3
|
+
let page = 0;
|
|
4
|
+
let items;
|
|
5
|
+
do {
|
|
6
|
+
// eslint-disable-next-line no-await-in-loop
|
|
7
|
+
items = await fn(limit, page);
|
|
8
|
+
result.push(...items);
|
|
9
|
+
page += 1;
|
|
10
|
+
} while (items.length === limit);
|
|
11
|
+
return result;
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type FC, type PropsWithChildren, type ReactNode } from 'react';
|
|
2
|
+
import type { DynamicContent } from './DynamicContentPicker.types';
|
|
3
|
+
export declare const FieldTitle: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
4
|
+
export declare const Field: FC<PropsWithChildren<{
|
|
5
|
+
title: ReactNode;
|
|
6
|
+
}>>;
|
|
7
|
+
type DynamicContentFormProps = {
|
|
8
|
+
dc: DynamicContent;
|
|
9
|
+
onChange: (dc: DynamicContent) => void;
|
|
10
|
+
};
|
|
11
|
+
export declare const DynamicContentPicker: FC<PropsWithChildren<DynamicContentFormProps>>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import React, { useContext } from 'react';
|
|
2
|
+
import styled from 'styled-components';
|
|
3
|
+
import { useAsync, Vertical } from '@pushwoosh/kit-helpers';
|
|
4
|
+
import { TextInputField } from '@pushwoosh/kit-text-input';
|
|
5
|
+
import { NativeSelect } from '@pushwoosh/kit-select';
|
|
6
|
+
import { PushwooshSPAContext } from '../context';
|
|
7
|
+
import { collectPaginatedData } from '../asyncHelpers';
|
|
8
|
+
const TagPickerDiv = styled(Vertical).attrs({
|
|
9
|
+
$gap: 16,
|
|
10
|
+
$padding: 16
|
|
11
|
+
}).withConfig({
|
|
12
|
+
displayName: "TagPickerDiv",
|
|
13
|
+
componentId: "sc-j19s3d-0"
|
|
14
|
+
})(["width:240px;border-radius:4px;background:#F7F9FA;box-shadow:0 0 4px 0 rgba(0,0,0,0.06),0 4px 6px 0 rgba(0,0,0,0.06);"]);
|
|
15
|
+
export const FieldTitle = styled.div.withConfig({
|
|
16
|
+
displayName: "FieldTitle",
|
|
17
|
+
componentId: "sc-j19s3d-1"
|
|
18
|
+
})(["font-size:12px;font-style:normal;font-weight:500;line-height:130%;"]);
|
|
19
|
+
export const Field = ({
|
|
20
|
+
title,
|
|
21
|
+
children
|
|
22
|
+
}) => {
|
|
23
|
+
return React.createElement(Vertical, {
|
|
24
|
+
"$gap": 4
|
|
25
|
+
}, React.createElement(FieldTitle, null, title), children);
|
|
26
|
+
};
|
|
27
|
+
const ignoreTagTypes = ['boolean', 'list'];
|
|
28
|
+
export const DynamicContentPicker = ({
|
|
29
|
+
dc,
|
|
30
|
+
onChange,
|
|
31
|
+
children
|
|
32
|
+
}) => {
|
|
33
|
+
const context = useContext(PushwooshSPAContext);
|
|
34
|
+
const asyncResult = useAsync(async () => {
|
|
35
|
+
const [originalTags, modifiers] = await Promise.all([collectPaginatedData(1000, async (perPage, page) => {
|
|
36
|
+
const res = await context.grpcBridge.tags.list({
|
|
37
|
+
orderBy: 'name',
|
|
38
|
+
orderDirection: 'asc',
|
|
39
|
+
page,
|
|
40
|
+
perPage
|
|
41
|
+
});
|
|
42
|
+
return res.tags;
|
|
43
|
+
}), context.rpcClient.callRemoteProcedure('base.modifiers', {})]);
|
|
44
|
+
const {
|
|
45
|
+
1: numbers,
|
|
46
|
+
2: strings
|
|
47
|
+
} = modifiers.response.result;
|
|
48
|
+
return originalTags.filter(tag => !ignoreTagTypes.includes(tag.type)).map(tag => ({
|
|
49
|
+
...tag,
|
|
50
|
+
modifiers: tag.type === 'integer' || tag.type === 'decimal' ? numbers : strings
|
|
51
|
+
}));
|
|
52
|
+
}, [context]);
|
|
53
|
+
if (asyncResult.loading) {
|
|
54
|
+
return React.createElement("div", null);
|
|
55
|
+
}
|
|
56
|
+
const tags = asyncResult.value || [];
|
|
57
|
+
const currentTag = tags.find(tag => tag.name === dc.tagName) || {
|
|
58
|
+
modifiers: ['regular']
|
|
59
|
+
};
|
|
60
|
+
return React.createElement(TagPickerDiv, null, React.createElement(Field, {
|
|
61
|
+
title: "Tag"
|
|
62
|
+
}, React.createElement(Vertical, {
|
|
63
|
+
"$gap": 8
|
|
64
|
+
}, React.createElement(NativeSelect, {
|
|
65
|
+
value: dc.tagName,
|
|
66
|
+
onChange: e => {
|
|
67
|
+
onChange({
|
|
68
|
+
tagName: e.target.value,
|
|
69
|
+
modifier: currentTag.modifiers[0],
|
|
70
|
+
defaultValue: ''
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}, tags.map(tag => React.createElement("option", {
|
|
74
|
+
value: tag.name,
|
|
75
|
+
key: tag.name
|
|
76
|
+
}, tag.name))), React.createElement(NativeSelect, {
|
|
77
|
+
value: dc.modifier,
|
|
78
|
+
onChange: e => {
|
|
79
|
+
onChange({
|
|
80
|
+
...dc,
|
|
81
|
+
modifier: e.target.value
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}, currentTag.modifiers.map(modifier => React.createElement("option", {
|
|
85
|
+
value: modifier,
|
|
86
|
+
key: modifier
|
|
87
|
+
}, modifier))))), React.createElement(Field, {
|
|
88
|
+
title: "Default Tag Value"
|
|
89
|
+
}, React.createElement(TextInputField, {
|
|
90
|
+
value: dc.defaultValue,
|
|
91
|
+
onChange: e => {
|
|
92
|
+
onChange({
|
|
93
|
+
...dc,
|
|
94
|
+
defaultValue: e.target.value
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
})), children);
|
|
98
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DynamicContentPicker } from './DynamicContentPicker';
|
package/package.json
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pushwoosh/smart-components-kit",
|
|
3
3
|
"main": "index.js",
|
|
4
|
+
"module": "index.js",
|
|
4
5
|
"types": "index.d.ts",
|
|
6
|
+
"sideEffects": false,
|
|
5
7
|
"scripts": {
|
|
6
8
|
"start": "`pushwoosh-engine app:command:dev`",
|
|
7
9
|
"build": "pushwoosh-engine lib:build",
|
|
@@ -11,6 +13,13 @@
|
|
|
11
13
|
"check:types": "echo \"Run check:types\" && tsc --project tsconfig.json --skipLibCheck --emitDeclarationOnly false --noEmit"
|
|
12
14
|
},
|
|
13
15
|
"pre-commit": "check",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@pushwoosh/kit-constants": "^1.6.5",
|
|
18
|
+
"@pushwoosh/kit-helpers": "^4.6.1",
|
|
19
|
+
"@pushwoosh/kit-select": "^1.1.0",
|
|
20
|
+
"@pushwoosh/kit-spinner": "^1.5.1",
|
|
21
|
+
"@pushwoosh/kit-text-input": "^1.5.1"
|
|
22
|
+
},
|
|
14
23
|
"devDependencies": {
|
|
15
24
|
"@eslint/js": "^9.10.0",
|
|
16
25
|
"@pushwoosh/frontend-builder-engine": "^0.6.0",
|
|
@@ -20,9 +29,12 @@
|
|
|
20
29
|
"@types/eslint__js": "^8.42.3",
|
|
21
30
|
"@types/react": "^18.3.5",
|
|
22
31
|
"@types/react-dom": "^18.3.0",
|
|
32
|
+
"@types/styled-components": "^5.1.34",
|
|
23
33
|
"eslint": "^9.10.0",
|
|
24
34
|
"react": "^18.3.1",
|
|
25
35
|
"react-dom": "^18.3.1",
|
|
36
|
+
"react-router-dom": "^5.3.4",
|
|
37
|
+
"styled-components": "^5.3.11",
|
|
26
38
|
"typescript": "^5.6.2",
|
|
27
39
|
"typescript-eslint": "^8.5.0"
|
|
28
40
|
},
|
|
@@ -30,12 +42,12 @@
|
|
|
30
42
|
"@pushwoosh/grpc-bridge": "^1.5.10",
|
|
31
43
|
"@pushwoosh/http-client": "^2.4.12",
|
|
32
44
|
"@pushwoosh/session-store": "^2.4.1",
|
|
33
|
-
"react": "^18.0.0",
|
|
34
|
-
"react-dom": "^18.0.0",
|
|
45
|
+
"react": "^16.14.0 || ^18.0.0",
|
|
46
|
+
"react-dom": "^16.14.0 || ^18.0.0",
|
|
35
47
|
"single-spa": "^5.9.3"
|
|
36
48
|
},
|
|
37
49
|
"engines": {
|
|
38
50
|
"node": ">= 18"
|
|
39
51
|
},
|
|
40
|
-
"version": "0.0.
|
|
52
|
+
"version": "0.0.3"
|
|
41
53
|
}
|
package/parcel.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { PushwooshSPAContextType } from './context';
|
|
2
|
+
export type ParcelResult<P> = {
|
|
3
|
+
render: (props: P) => void;
|
|
4
|
+
unmount: () => void;
|
|
5
|
+
};
|
|
6
|
+
export type ParcelProps = {
|
|
7
|
+
context: PushwooshSPAContextType;
|
|
8
|
+
};
|
|
9
|
+
export declare function parcel(container: HTMLElement): ParcelResult<ParcelProps>;
|
package/parcel.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { createRoot } from 'react-dom/client';
|
|
3
|
+
import { PushwooshSPAContextProvider, usePushwooshSPAContext } from './context';
|
|
4
|
+
function TestParcel() {
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
6
|
+
const context = usePushwooshSPAContext();
|
|
7
|
+
return React.createElement("div", null, "Test Parcel");
|
|
8
|
+
}
|
|
9
|
+
export function parcel(container) {
|
|
10
|
+
const root = createRoot(container);
|
|
11
|
+
return {
|
|
12
|
+
render(props) {
|
|
13
|
+
root.render(React.createElement(PushwooshSPAContextProvider, {
|
|
14
|
+
value: props.context
|
|
15
|
+
}, React.createElement(TestParcel, null)));
|
|
16
|
+
},
|
|
17
|
+
unmount() {
|
|
18
|
+
root.unmount();
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}
|