@pushwoosh/smart-components-kit 0.0.3 → 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.
@@ -1,4 +1,4 @@
1
- import { PushwooshSPAContextType } from './context';
1
+ import { type PushwooshSPAContextType } from '../context';
2
2
  export type ParcelResult<P> = {
3
3
  render: (props: P) => void;
4
4
  unmount: () => void;
@@ -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,2 @@
1
+ import React from 'react';
2
+ export declare function DynamicContentPickerExample(): React.JSX.Element;
@@ -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,8 @@
1
+ import React from 'react';
2
+ import { RouteComponentProps } from 'react-router-dom';
3
+ interface MatchParams {
4
+ path: string;
5
+ url: string;
6
+ }
7
+ export declare const Lib: React.FC<RouteComponentProps<MatchParams>>;
8
+ export {};
@@ -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,2 @@
1
+ import React from 'react';
2
+ export declare function TestPlace(): React.JSX.Element;
@@ -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: DynamicContent;
7
+ dc?: DynamicContent;
9
8
  onChange: (dc: DynamicContent) => void;
10
9
  };
11
10
  export declare const DynamicContentPicker: FC<PropsWithChildren<DynamicContentFormProps>>;
@@ -1,21 +1,9 @@
1
- import React, { useContext } from 'react';
2
- import styled from 'styled-components';
3
- import { useAsync, Vertical } from '@pushwoosh/kit-helpers';
1
+ import React from 'react';
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
- 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%;"]);
5
+ import { useDynamicContentTags } from './hooks';
6
+ import { FieldTitle, TagPickerDiv } from './styled';
19
7
  export const Field = ({
20
8
  title,
21
9
  children
@@ -24,37 +12,23 @@ export const Field = ({
24
12
  "$gap": 4
25
13
  }, React.createElement(FieldTitle, null, title), children);
26
14
  };
27
- const ignoreTagTypes = ['boolean', 'list'];
15
+ const defaultDynamicContent = {
16
+ tagName: '',
17
+ modifier: 'regular',
18
+ defaultValue: ''
19
+ };
28
20
  export const DynamicContentPicker = ({
29
- dc,
21
+ dc = defaultDynamicContent,
30
22
  onChange,
31
23
  children
32
24
  }) => {
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]);
25
+ const asyncResult = useDynamicContentTags();
53
26
  if (asyncResult.loading) {
54
27
  return React.createElement("div", null);
55
28
  }
56
29
  const tags = asyncResult.value || [];
57
30
  const currentTag = tags.find(tag => tag.name === dc.tagName) || {
31
+ name: '',
58
32
  modifiers: ['regular']
59
33
  };
60
34
  return React.createElement(TagPickerDiv, null, React.createElement(Field, {
@@ -70,7 +44,9 @@ export const DynamicContentPicker = ({
70
44
  defaultValue: ''
71
45
  });
72
46
  }
73
- }, tags.map(tag => React.createElement("option", {
47
+ }, !currentTag.name && React.createElement("option", {
48
+ value: ""
49
+ }, "Select tag"), tags.map(tag => React.createElement("option", {
74
50
  value: tag.name,
75
51
  key: tag.name
76
52
  }, tag.name))), React.createElement(NativeSelect, {
@@ -80,7 +56,8 @@ export const DynamicContentPicker = ({
80
56
  ...dc,
81
57
  modifier: e.target.value
82
58
  });
83
- }
59
+ },
60
+ disabled: !currentTag.name
84
61
  }, currentTag.modifiers.map(modifier => React.createElement("option", {
85
62
  value: modifier,
86
63
  key: modifier
@@ -93,6 +70,7 @@ export const DynamicContentPicker = ({
93
70
  ...dc,
94
71
  defaultValue: e.target.value
95
72
  });
96
- }
73
+ },
74
+ disabled: !currentTag.name
97
75
  })), children);
98
76
  };
@@ -0,0 +1,20 @@
1
+ import { PushwooshSPAContextType } from '../context';
2
+ import type { FullTagData } from './DynamicContentPicker.types';
3
+ export declare function fetchDynamicContentTags(context: PushwooshSPAContextType): Promise<FullTagData[]>;
4
+ export declare function useDynamicContentTags(): {
5
+ loading: boolean;
6
+ error?: undefined;
7
+ value?: undefined;
8
+ } | {
9
+ loading: false;
10
+ error: Error;
11
+ value?: undefined;
12
+ } | {
13
+ loading: true;
14
+ error?: Error | undefined;
15
+ value?: FullTagData[] | undefined;
16
+ } | {
17
+ loading: false;
18
+ error?: undefined;
19
+ value: FullTagData[];
20
+ };
@@ -0,0 +1,30 @@
1
+ import { useContext } from 'react';
2
+ import { useAsync } from '@pushwoosh/kit-helpers';
3
+ import { collectPaginatedData } from '../asyncHelpers';
4
+ import { PushwooshSPAContext } from '../context';
5
+ const ignoreTagTypes = ['boolean', 'list'];
6
+ const numberTypes = ['integer', 'decimal'];
7
+ export async function fetchDynamicContentTags(context) {
8
+ const [originalTags, modifiers] = await Promise.all([collectPaginatedData(1000, async (perPage, page) => {
9
+ const res = await context.grpcBridge.tags.list({
10
+ orderBy: 'name',
11
+ orderDirection: 'asc',
12
+ page,
13
+ perPage
14
+ });
15
+ return res.tags;
16
+ }), context.rpcClient.callRemoteProcedure('base.modifiers', {})]);
17
+ const {
18
+ result
19
+ } = modifiers.response;
20
+ return originalTags.filter(tag => !ignoreTagTypes.includes(tag.type)).map(tag => ({
21
+ ...tag,
22
+ modifiers: numberTypes.includes(tag.type) ? result[1] : result[2]
23
+ }));
24
+ }
25
+ export function useDynamicContentTags() {
26
+ const context = useContext(PushwooshSPAContext);
27
+ return useAsync(async () => {
28
+ return fetchDynamicContentTags(context);
29
+ }, [context]);
30
+ }
@@ -1,2 +1,3 @@
1
1
  export type { DynamicContent } from './DynamicContentPicker.types';
2
2
  export { DynamicContentPicker } from './DynamicContentPicker';
3
+ export * from './hooks';
@@ -1 +1,2 @@
1
- export { DynamicContentPicker } from './DynamicContentPicker';
1
+ export { DynamicContentPicker } from './DynamicContentPicker';
2
+ export * from './hooks';
@@ -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",
@@ -43,11 +45,10 @@
43
45
  "@pushwoosh/http-client": "^2.4.12",
44
46
  "@pushwoosh/session-store": "^2.4.1",
45
47
  "react": "^16.14.0 || ^18.0.0",
46
- "react-dom": "^16.14.0 || ^18.0.0",
47
- "single-spa": "^5.9.3"
48
+ "react-dom": "^16.14.0 || ^18.0.0"
48
49
  },
49
50
  "engines": {
50
51
  "node": ">= 18"
51
52
  },
52
- "version": "0.0.3"
53
+ "version": "0.1.0"
53
54
  }
package/parcel.js DELETED
@@ -1,21 +0,0 @@
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
- }