@pushwoosh/smart-components-kit 0.0.4 → 0.1.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/{parcel.d.ts → _devel/index.d.ts} +1 -1
- package/_devel/index.js +39 -0
- package/_devel/lib/dynamic-content-picker.d.ts +2 -0
- package/_devel/lib/dynamic-content-picker.js +16 -0
- package/_devel/lib/index.d.ts +8 -0
- package/_devel/lib/index.js +29 -0
- package/_devel/test-place.d.ts +2 -0
- package/_devel/test-place.js +6 -0
- package/dynamic-content-picker/DynamicContentPicker.d.ts +1 -2
- package/dynamic-content-picker/DynamicContentPicker.js +15 -16
- package/dynamic-content-picker/hooks.js +4 -4
- package/dynamic-content-picker/styled.d.ts +17 -0
- package/dynamic-content-picker/styled.js +13 -0
- package/package.json +3 -1
- package/parcel.js +0 -26
package/_devel/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { createRoot } from 'react-dom/client';
|
|
3
|
+
import { Router, Route, Switch, Link } from 'react-router-dom';
|
|
4
|
+
import { PushwooshSPAContextProvider } from '../context';
|
|
5
|
+
import { Lib } from './lib';
|
|
6
|
+
import { TestPlace } from './test-place';
|
|
7
|
+
export function parcel(container) {
|
|
8
|
+
const root = createRoot(container);
|
|
9
|
+
return {
|
|
10
|
+
render(props) {
|
|
11
|
+
root.render(React.createElement(Router, {
|
|
12
|
+
history: props.context.history
|
|
13
|
+
}, React.createElement(PushwooshSPAContextProvider, {
|
|
14
|
+
value: props.context
|
|
15
|
+
}, React.createElement(Switch, null, React.createElement(Route, {
|
|
16
|
+
path: "/:url",
|
|
17
|
+
exact: true,
|
|
18
|
+
render: ({
|
|
19
|
+
match
|
|
20
|
+
}) => {
|
|
21
|
+
return React.createElement("ul", null, React.createElement("li", null, React.createElement(Link, {
|
|
22
|
+
to: `${match.url}/test`
|
|
23
|
+
}, "Test your new component")), React.createElement("li", null, React.createElement(Link, {
|
|
24
|
+
to: `${match.url}/lib`
|
|
25
|
+
}, "Components lib")));
|
|
26
|
+
}
|
|
27
|
+
}), React.createElement(Route, {
|
|
28
|
+
path: "/:url/test",
|
|
29
|
+
component: TestPlace
|
|
30
|
+
}), React.createElement(Route, {
|
|
31
|
+
path: "/:url/lib",
|
|
32
|
+
component: Lib
|
|
33
|
+
})))));
|
|
34
|
+
},
|
|
35
|
+
unmount() {
|
|
36
|
+
root.unmount();
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { DynamicContentPicker } from '../../dynamic-content-picker';
|
|
3
|
+
import { Horizontal } from '@pushwoosh/kit-helpers';
|
|
4
|
+
import { Button } from '@pushwoosh/kit-button';
|
|
5
|
+
export function DynamicContentPickerExample() {
|
|
6
|
+
const [dc, setDc] = useState();
|
|
7
|
+
return React.createElement("div", null, React.createElement(DynamicContentPicker, {
|
|
8
|
+
dc: dc,
|
|
9
|
+
onChange: setDc
|
|
10
|
+
}, React.createElement(Horizontal, {
|
|
11
|
+
"$justifyContent": "end"
|
|
12
|
+
}, React.createElement(Button, {
|
|
13
|
+
color: "primary",
|
|
14
|
+
onClick: () => console.log(dc)
|
|
15
|
+
}, "Log to console"))));
|
|
16
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Route, Switch, Link } from 'react-router-dom';
|
|
3
|
+
import { Columns } from '@pushwoosh/kit-helpers';
|
|
4
|
+
import { DynamicContentPickerExample } from './dynamic-content-picker';
|
|
5
|
+
function Example() {
|
|
6
|
+
return React.createElement("div", null, React.createElement("h3", null, "component example"));
|
|
7
|
+
}
|
|
8
|
+
export const Lib = ({
|
|
9
|
+
match
|
|
10
|
+
}) => {
|
|
11
|
+
return React.createElement(Columns, {
|
|
12
|
+
"$gap": 12,
|
|
13
|
+
"$sizes": "200px 780px"
|
|
14
|
+
}, React.createElement("ul", null, React.createElement("li", null, React.createElement(Link, {
|
|
15
|
+
to: `${match.url}/dynamic-content-picker`
|
|
16
|
+
}, "Child 1")), React.createElement("li", null, React.createElement(Link, {
|
|
17
|
+
to: `${match.url}/example`
|
|
18
|
+
}, "Child 2"))), React.createElement("div", null, React.createElement(Switch, null, React.createElement(Route, {
|
|
19
|
+
path: `${match.path}/dynamic-content-picker`,
|
|
20
|
+
component: DynamicContentPickerExample
|
|
21
|
+
}), React.createElement(Route, {
|
|
22
|
+
path: `${match.path}/example`,
|
|
23
|
+
component: Example
|
|
24
|
+
}), React.createElement(Route, {
|
|
25
|
+
path: match.path,
|
|
26
|
+
exact: true,
|
|
27
|
+
render: () => React.createElement("div", null, "Please select a child route.")
|
|
28
|
+
}))));
|
|
29
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// PLEASE, DON'T COMMIT THIS FILE
|
|
2
|
+
// I is for testing components, you can add your component here to test it
|
|
3
|
+
import React from 'react';
|
|
4
|
+
export function TestPlace() {
|
|
5
|
+
return React.createElement("div", null, "add your component to test please, don't commit this file");
|
|
6
|
+
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { type FC, type PropsWithChildren, type ReactNode } from 'react';
|
|
2
2
|
import type { DynamicContent } from './DynamicContentPicker.types';
|
|
3
|
-
export declare const FieldTitle: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
4
3
|
export declare const Field: FC<PropsWithChildren<{
|
|
5
4
|
title: ReactNode;
|
|
6
5
|
}>>;
|
|
7
6
|
type DynamicContentFormProps = {
|
|
8
|
-
dc
|
|
7
|
+
dc?: DynamicContent;
|
|
9
8
|
onChange: (dc: DynamicContent) => void;
|
|
10
9
|
};
|
|
11
10
|
export declare const DynamicContentPicker: FC<PropsWithChildren<DynamicContentFormProps>>;
|
|
@@ -1,20 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import styled from 'styled-components';
|
|
3
2
|
import { Vertical } from '@pushwoosh/kit-helpers';
|
|
4
3
|
import { TextInputField } from '@pushwoosh/kit-text-input';
|
|
5
4
|
import { NativeSelect } from '@pushwoosh/kit-select';
|
|
6
5
|
import { useDynamicContentTags } from './hooks';
|
|
7
|
-
|
|
8
|
-
$gap: 16,
|
|
9
|
-
$padding: 16
|
|
10
|
-
}).withConfig({
|
|
11
|
-
displayName: "TagPickerDiv",
|
|
12
|
-
componentId: "sc-j19s3d-0"
|
|
13
|
-
})(["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);"]);
|
|
14
|
-
export const FieldTitle = styled.div.withConfig({
|
|
15
|
-
displayName: "FieldTitle",
|
|
16
|
-
componentId: "sc-j19s3d-1"
|
|
17
|
-
})(["font-size:12px;font-style:normal;font-weight:500;line-height:130%;"]);
|
|
6
|
+
import { FieldTitle, TagPickerDiv } from './styled';
|
|
18
7
|
export const Field = ({
|
|
19
8
|
title,
|
|
20
9
|
children
|
|
@@ -23,8 +12,13 @@ export const Field = ({
|
|
|
23
12
|
"$gap": 4
|
|
24
13
|
}, React.createElement(FieldTitle, null, title), children);
|
|
25
14
|
};
|
|
15
|
+
const defaultDynamicContent = {
|
|
16
|
+
tagName: '',
|
|
17
|
+
modifier: 'regular',
|
|
18
|
+
defaultValue: ''
|
|
19
|
+
};
|
|
26
20
|
export const DynamicContentPicker = ({
|
|
27
|
-
dc,
|
|
21
|
+
dc = defaultDynamicContent,
|
|
28
22
|
onChange,
|
|
29
23
|
children
|
|
30
24
|
}) => {
|
|
@@ -34,6 +28,7 @@ export const DynamicContentPicker = ({
|
|
|
34
28
|
}
|
|
35
29
|
const tags = asyncResult.value || [];
|
|
36
30
|
const currentTag = tags.find(tag => tag.name === dc.tagName) || {
|
|
31
|
+
name: '',
|
|
37
32
|
modifiers: ['regular']
|
|
38
33
|
};
|
|
39
34
|
return React.createElement(TagPickerDiv, null, React.createElement(Field, {
|
|
@@ -49,7 +44,9 @@ export const DynamicContentPicker = ({
|
|
|
49
44
|
defaultValue: ''
|
|
50
45
|
});
|
|
51
46
|
}
|
|
52
|
-
},
|
|
47
|
+
}, !currentTag.name && React.createElement("option", {
|
|
48
|
+
value: ""
|
|
49
|
+
}, "Select tag"), tags.map(tag => React.createElement("option", {
|
|
53
50
|
value: tag.name,
|
|
54
51
|
key: tag.name
|
|
55
52
|
}, tag.name))), React.createElement(NativeSelect, {
|
|
@@ -59,7 +56,8 @@ export const DynamicContentPicker = ({
|
|
|
59
56
|
...dc,
|
|
60
57
|
modifier: e.target.value
|
|
61
58
|
});
|
|
62
|
-
}
|
|
59
|
+
},
|
|
60
|
+
disabled: !currentTag.name
|
|
63
61
|
}, currentTag.modifiers.map(modifier => React.createElement("option", {
|
|
64
62
|
value: modifier,
|
|
65
63
|
key: modifier
|
|
@@ -72,6 +70,7 @@ export const DynamicContentPicker = ({
|
|
|
72
70
|
...dc,
|
|
73
71
|
defaultValue: e.target.value
|
|
74
72
|
});
|
|
75
|
-
}
|
|
73
|
+
},
|
|
74
|
+
disabled: !currentTag.name
|
|
76
75
|
})), children);
|
|
77
76
|
};
|
|
@@ -3,6 +3,7 @@ import { useAsync } from '@pushwoosh/kit-helpers';
|
|
|
3
3
|
import { collectPaginatedData } from '../asyncHelpers';
|
|
4
4
|
import { PushwooshSPAContext } from '../context';
|
|
5
5
|
const ignoreTagTypes = ['boolean', 'list'];
|
|
6
|
+
const numberTypes = ['integer', 'decimal'];
|
|
6
7
|
export async function fetchDynamicContentTags(context) {
|
|
7
8
|
const [originalTags, modifiers] = await Promise.all([collectPaginatedData(1000, async (perPage, page) => {
|
|
8
9
|
const res = await context.grpcBridge.tags.list({
|
|
@@ -14,12 +15,11 @@ export async function fetchDynamicContentTags(context) {
|
|
|
14
15
|
return res.tags;
|
|
15
16
|
}), context.rpcClient.callRemoteProcedure('base.modifiers', {})]);
|
|
16
17
|
const {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
} = modifiers.response.result;
|
|
18
|
+
result
|
|
19
|
+
} = modifiers.response;
|
|
20
20
|
return originalTags.filter(tag => !ignoreTagTypes.includes(tag.type)).map(tag => ({
|
|
21
21
|
...tag,
|
|
22
|
-
modifiers:
|
|
22
|
+
modifiers: numberTypes.includes(tag.type) ? result[1] : result[2]
|
|
23
23
|
}));
|
|
24
24
|
}
|
|
25
25
|
export function useDynamicContentTags() {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare const TagPickerDiv: import("styled-components").StyledComponent<"div", any, {
|
|
2
|
+
$alignContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
|
|
3
|
+
$alignItems?: "end" | "start" | "center" | "stretch" | "baseline" | undefined;
|
|
4
|
+
$gap?: string | number | undefined;
|
|
5
|
+
$gridAutoFlow?: "row" | "column" | "dense" | "row dense" | "column dense" | undefined;
|
|
6
|
+
$justifyContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
|
|
7
|
+
$justifyItems?: "end" | "start" | "center" | "stretch" | "baseline" | undefined;
|
|
8
|
+
$margin?: string | number | undefined;
|
|
9
|
+
$padding?: string | number | undefined;
|
|
10
|
+
$placeItems?: "end" | "start" | "center" | "stretch" | undefined;
|
|
11
|
+
} & {
|
|
12
|
+
$gridAutoFlow: string;
|
|
13
|
+
} & {
|
|
14
|
+
$gap: number;
|
|
15
|
+
$padding: number;
|
|
16
|
+
}, "$gridAutoFlow" | "$gap" | "$padding">;
|
|
17
|
+
export declare const FieldTitle: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import styled from 'styled-components';
|
|
2
|
+
import { Vertical } from '@pushwoosh/kit-helpers';
|
|
3
|
+
export const TagPickerDiv = styled(Vertical).attrs({
|
|
4
|
+
$gap: 16,
|
|
5
|
+
$padding: 16
|
|
6
|
+
}).withConfig({
|
|
7
|
+
displayName: "TagPickerDiv",
|
|
8
|
+
componentId: "sc-gptaqm-0"
|
|
9
|
+
})(["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);"]);
|
|
10
|
+
export const FieldTitle = styled.div.withConfig({
|
|
11
|
+
displayName: "FieldTitle",
|
|
12
|
+
componentId: "sc-gptaqm-1"
|
|
13
|
+
})(["font-size:12px;font-style:normal;font-weight:500;line-height:130%;"]);
|
package/package.json
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
},
|
|
15
15
|
"pre-commit": "check",
|
|
16
16
|
"dependencies": {
|
|
17
|
+
"@pushwoosh/kit-button": "^2.2.5",
|
|
17
18
|
"@pushwoosh/kit-constants": "^1.6.5",
|
|
18
19
|
"@pushwoosh/kit-helpers": "^4.6.1",
|
|
19
20
|
"@pushwoosh/kit-select": "^1.1.0",
|
|
@@ -29,6 +30,7 @@
|
|
|
29
30
|
"@types/eslint__js": "^8.42.3",
|
|
30
31
|
"@types/react": "^18.3.5",
|
|
31
32
|
"@types/react-dom": "^18.3.0",
|
|
33
|
+
"@types/react-router-dom": "^5.3.3",
|
|
32
34
|
"@types/styled-components": "^5.1.34",
|
|
33
35
|
"eslint": "^9.10.0",
|
|
34
36
|
"react": "^18.3.1",
|
|
@@ -48,5 +50,5 @@
|
|
|
48
50
|
"engines": {
|
|
49
51
|
"node": ">= 18"
|
|
50
52
|
},
|
|
51
|
-
"version": "0.0
|
|
53
|
+
"version": "0.1.0"
|
|
52
54
|
}
|
package/parcel.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { createRoot } from 'react-dom/client';
|
|
3
|
-
import { PushwooshSPAContextProvider, usePushwooshSPAContext } from './context';
|
|
4
|
-
import { DynamicContentPicker } from './dynamic-content-picker';
|
|
5
|
-
function TestParcel() {
|
|
6
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
7
|
-
const context = usePushwooshSPAContext();
|
|
8
|
-
const [dc, setDc] = React.useState({});
|
|
9
|
-
return React.createElement("div", null, React.createElement(DynamicContentPicker, {
|
|
10
|
-
dc: dc,
|
|
11
|
-
onChange: setDc
|
|
12
|
-
}));
|
|
13
|
-
}
|
|
14
|
-
export function parcel(container) {
|
|
15
|
-
const root = createRoot(container);
|
|
16
|
-
return {
|
|
17
|
-
render(props) {
|
|
18
|
-
root.render(React.createElement(PushwooshSPAContextProvider, {
|
|
19
|
-
value: props.context
|
|
20
|
-
}, React.createElement(TestParcel, null)));
|
|
21
|
-
},
|
|
22
|
-
unmount() {
|
|
23
|
-
root.unmount();
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
}
|