@pushwoosh/smart-components-kit 0.0.3 → 0.0.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.
@@ -1,10 +1,9 @@
1
- import React, { useContext } from 'react';
1
+ import React from 'react';
2
2
  import styled from 'styled-components';
3
- import { useAsync, Vertical } from '@pushwoosh/kit-helpers';
3
+ import { Vertical } from '@pushwoosh/kit-helpers';
4
4
  import { TextInputField } from '@pushwoosh/kit-text-input';
5
5
  import { NativeSelect } from '@pushwoosh/kit-select';
6
- import { PushwooshSPAContext } from '../context';
7
- import { collectPaginatedData } from '../asyncHelpers';
6
+ import { useDynamicContentTags } from './hooks';
8
7
  const TagPickerDiv = styled(Vertical).attrs({
9
8
  $gap: 16,
10
9
  $padding: 16
@@ -24,32 +23,12 @@ export const Field = ({
24
23
  "$gap": 4
25
24
  }, React.createElement(FieldTitle, null, title), children);
26
25
  };
27
- const ignoreTagTypes = ['boolean', 'list'];
28
26
  export const DynamicContentPicker = ({
29
27
  dc,
30
28
  onChange,
31
29
  children
32
30
  }) => {
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]);
31
+ const asyncResult = useDynamicContentTags();
53
32
  if (asyncResult.loading) {
54
33
  return React.createElement("div", null);
55
34
  }
@@ -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
+ export async function fetchDynamicContentTags(context) {
7
+ const [originalTags, modifiers] = await Promise.all([collectPaginatedData(1000, async (perPage, page) => {
8
+ const res = await context.grpcBridge.tags.list({
9
+ orderBy: 'name',
10
+ orderDirection: 'asc',
11
+ page,
12
+ perPage
13
+ });
14
+ return res.tags;
15
+ }), context.rpcClient.callRemoteProcedure('base.modifiers', {})]);
16
+ const {
17
+ 1: numbers,
18
+ 2: strings
19
+ } = modifiers.response.result;
20
+ return originalTags.filter(tag => !ignoreTagTypes.includes(tag.type)).map(tag => ({
21
+ ...tag,
22
+ modifiers: tag.type === 'integer' || tag.type === 'decimal' ? numbers : strings
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';
package/package.json CHANGED
@@ -43,11 +43,10 @@
43
43
  "@pushwoosh/http-client": "^2.4.12",
44
44
  "@pushwoosh/session-store": "^2.4.1",
45
45
  "react": "^16.14.0 || ^18.0.0",
46
- "react-dom": "^16.14.0 || ^18.0.0",
47
- "single-spa": "^5.9.3"
46
+ "react-dom": "^16.14.0 || ^18.0.0"
48
47
  },
49
48
  "engines": {
50
49
  "node": ">= 18"
51
50
  },
52
- "version": "0.0.3"
51
+ "version": "0.0.4"
53
52
  }
package/parcel.d.ts CHANGED
@@ -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;
package/parcel.js CHANGED
@@ -1,10 +1,15 @@
1
1
  import React from 'react';
2
2
  import { createRoot } from 'react-dom/client';
3
3
  import { PushwooshSPAContextProvider, usePushwooshSPAContext } from './context';
4
+ import { DynamicContentPicker } from './dynamic-content-picker';
4
5
  function TestParcel() {
5
6
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
6
7
  const context = usePushwooshSPAContext();
7
- return React.createElement("div", null, "Test Parcel");
8
+ const [dc, setDc] = React.useState({});
9
+ return React.createElement("div", null, React.createElement(DynamicContentPicker, {
10
+ dc: dc,
11
+ onChange: setDc
12
+ }));
8
13
  }
9
14
  export function parcel(container) {
10
15
  const root = createRoot(container);