@pushwoosh/smart-components-kit 0.1.0 → 0.2.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/_devel/index.d.ts +2 -2
- package/_devel/index.js +2 -2
- package/context/index.d.ts +4 -4
- package/context/index.js +5 -5
- package/dynamic-content-picker/DynamicContentPicker.js +8 -2
- package/dynamic-content-picker/hooks.d.ts +2 -2
- package/dynamic-content-picker/hooks.js +2 -2
- package/package.json +1 -1
package/_devel/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type SPAContextType } from '../context';
|
|
2
2
|
export type ParcelResult<P> = {
|
|
3
3
|
render: (props: P) => void;
|
|
4
4
|
unmount: () => void;
|
|
5
5
|
};
|
|
6
6
|
export type ParcelProps = {
|
|
7
|
-
context:
|
|
7
|
+
context: SPAContextType;
|
|
8
8
|
};
|
|
9
9
|
export declare function parcel(container: HTMLElement): ParcelResult<ParcelProps>;
|
package/_devel/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { createRoot } from 'react-dom/client';
|
|
3
3
|
import { Router, Route, Switch, Link } from 'react-router-dom';
|
|
4
|
-
import {
|
|
4
|
+
import { SPAContextProvider } from '../context';
|
|
5
5
|
import { Lib } from './lib';
|
|
6
6
|
import { TestPlace } from './test-place';
|
|
7
7
|
export function parcel(container) {
|
|
@@ -10,7 +10,7 @@ export function parcel(container) {
|
|
|
10
10
|
render(props) {
|
|
11
11
|
root.render(React.createElement(Router, {
|
|
12
12
|
history: props.context.history
|
|
13
|
-
}, React.createElement(
|
|
13
|
+
}, React.createElement(SPAContextProvider, {
|
|
14
14
|
value: props.context
|
|
15
15
|
}, React.createElement(Switch, null, React.createElement(Route, {
|
|
16
16
|
path: "/:url",
|
package/context/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { type History } from 'history';
|
|
|
2
2
|
import type { GrpcBridge } from '@pushwoosh/grpc-bridge';
|
|
3
3
|
import type { HttpClient, RpcClient, GrpcClient } from '@pushwoosh/http-client';
|
|
4
4
|
import type { SessionStore } from '@pushwoosh/session-store';
|
|
5
|
-
export type
|
|
5
|
+
export type SPAContextType = {
|
|
6
6
|
readonly history: History;
|
|
7
7
|
readonly httpClient: HttpClient;
|
|
8
8
|
readonly rpcClient: RpcClient;
|
|
@@ -10,6 +10,6 @@ export type PushwooshSPAContextType = {
|
|
|
10
10
|
readonly grpcBridge: GrpcBridge;
|
|
11
11
|
readonly sessionStore: SessionStore;
|
|
12
12
|
};
|
|
13
|
-
export declare const
|
|
14
|
-
export declare const
|
|
15
|
-
export declare function
|
|
13
|
+
export declare const SPAContext: import("react").Context<SPAContextType | undefined>;
|
|
14
|
+
export declare const SPAContextProvider: import("react").Provider<SPAContextType | undefined>;
|
|
15
|
+
export declare function useSPAContext(): SPAContextType;
|
package/context/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { createContext, useContext } from 'react';
|
|
2
|
-
export const
|
|
3
|
-
export const
|
|
4
|
-
export function
|
|
5
|
-
const contextValue = useContext(
|
|
2
|
+
export const SPAContext = createContext(undefined);
|
|
3
|
+
export const SPAContextProvider = SPAContext.Provider;
|
|
4
|
+
export function useSPAContext() {
|
|
5
|
+
const contextValue = useContext(SPAContext);
|
|
6
6
|
if (!contextValue) {
|
|
7
|
-
throw new Error('
|
|
7
|
+
throw new Error('useSPAContext must be used within a SPAContextProvider');
|
|
8
8
|
}
|
|
9
9
|
return contextValue;
|
|
10
10
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { Vertical } from '@pushwoosh/kit-helpers';
|
|
2
|
+
import { Horizontal, Vertical } from '@pushwoosh/kit-helpers';
|
|
3
3
|
import { TextInputField } from '@pushwoosh/kit-text-input';
|
|
4
4
|
import { NativeSelect } from '@pushwoosh/kit-select';
|
|
5
|
+
import { Spinner } from '@pushwoosh/kit-spinner';
|
|
5
6
|
import { useDynamicContentTags } from './hooks';
|
|
6
7
|
import { FieldTitle, TagPickerDiv } from './styled';
|
|
7
8
|
export const Field = ({
|
|
@@ -24,7 +25,12 @@ export const DynamicContentPicker = ({
|
|
|
24
25
|
}) => {
|
|
25
26
|
const asyncResult = useDynamicContentTags();
|
|
26
27
|
if (asyncResult.loading) {
|
|
27
|
-
return React.createElement(
|
|
28
|
+
return React.createElement(TagPickerDiv, null, React.createElement(Horizontal, {
|
|
29
|
+
"$placeItems": "center",
|
|
30
|
+
"$padding": 36
|
|
31
|
+
}, React.createElement(Spinner, {
|
|
32
|
+
size: "medium"
|
|
33
|
+
})));
|
|
28
34
|
}
|
|
29
35
|
const tags = asyncResult.value || [];
|
|
30
36
|
const currentTag = tags.find(tag => tag.name === dc.tagName) || {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SPAContextType } from '../context';
|
|
2
2
|
import type { FullTagData } from './DynamicContentPicker.types';
|
|
3
|
-
export declare function fetchDynamicContentTags(context:
|
|
3
|
+
export declare function fetchDynamicContentTags(context: SPAContextType): Promise<FullTagData[]>;
|
|
4
4
|
export declare function useDynamicContentTags(): {
|
|
5
5
|
loading: boolean;
|
|
6
6
|
error?: undefined;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useContext } from 'react';
|
|
2
2
|
import { useAsync } from '@pushwoosh/kit-helpers';
|
|
3
3
|
import { collectPaginatedData } from '../asyncHelpers';
|
|
4
|
-
import {
|
|
4
|
+
import { SPAContext } from '../context';
|
|
5
5
|
const ignoreTagTypes = ['boolean', 'list'];
|
|
6
6
|
const numberTypes = ['integer', 'decimal'];
|
|
7
7
|
export async function fetchDynamicContentTags(context) {
|
|
@@ -23,7 +23,7 @@ export async function fetchDynamicContentTags(context) {
|
|
|
23
23
|
}));
|
|
24
24
|
}
|
|
25
25
|
export function useDynamicContentTags() {
|
|
26
|
-
const context = useContext(
|
|
26
|
+
const context = useContext(SPAContext);
|
|
27
27
|
return useAsync(async () => {
|
|
28
28
|
return fetchDynamicContentTags(context);
|
|
29
29
|
}, [context]);
|
package/package.json
CHANGED