@pushwoosh/smart-components-kit 2.1.2 → 2.1.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.
- package/DynamicContentPicker/DynamicContentPicker.js +14 -9
- package/MediaStorage/CanvaImportDrawer.js +5 -3
- package/MediaStorage/MediaStorage.js +7 -3
- package/MediaStorage/aiGallery.js +1 -0
- package/PickerSort/usePagedItems.js +1 -1
- package/Table/hooks/useDataTableGetParams.js +22 -10
- package/package.json +3 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { arrow, autoPlacement, offset, useFloating } from '@floating-ui/react-dom';
|
|
3
|
-
import { useEffect, useMemo, useReducer,
|
|
3
|
+
import { useEffect, useMemo, useReducer, useState } from 'react';
|
|
4
4
|
import { Color } from '@pushwoosh/kit-constants';
|
|
5
5
|
import { elementAddListener, Horizontal, usePersistentFunction } from '@pushwoosh/kit-helpers';
|
|
6
6
|
import { WarningRoundIcon } from '@pushwoosh/kit-icons';
|
|
@@ -32,10 +32,15 @@ export const DynamicContentPicker = ({
|
|
|
32
32
|
error,
|
|
33
33
|
renderDynamicContent
|
|
34
34
|
}) => {
|
|
35
|
-
const
|
|
35
|
+
const [arrowElement, setArrowElement] = useState(null);
|
|
36
36
|
const [activeVar, setActiveVar] = useState();
|
|
37
37
|
const {
|
|
38
|
-
refs
|
|
38
|
+
refs: {
|
|
39
|
+
reference,
|
|
40
|
+
floating,
|
|
41
|
+
setReference,
|
|
42
|
+
setFloating
|
|
43
|
+
},
|
|
39
44
|
floatingStyles,
|
|
40
45
|
update,
|
|
41
46
|
middlewareData,
|
|
@@ -45,7 +50,7 @@ export const DynamicContentPicker = ({
|
|
|
45
50
|
middleware: [offset(8), autoPlacement({
|
|
46
51
|
allowedPlacements: ['left', 'left-start', 'left-end', 'right', 'right-start', 'right-end']
|
|
47
52
|
}), arrow({
|
|
48
|
-
element:
|
|
53
|
+
element: arrowElement
|
|
49
54
|
})]
|
|
50
55
|
});
|
|
51
56
|
const [state, dispatch] = useReducer(reducer, initState || initialState);
|
|
@@ -74,14 +79,14 @@ export const DynamicContentPicker = ({
|
|
|
74
79
|
return;
|
|
75
80
|
}
|
|
76
81
|
return elementAddListener(document, ['mousedown', 'touchstart', 'focusin'], event => {
|
|
77
|
-
if (
|
|
82
|
+
if (floating.current instanceof HTMLElement && !floating.current.contains(event.target)) {
|
|
78
83
|
clickAwayHandler();
|
|
79
84
|
}
|
|
80
85
|
});
|
|
81
|
-
}, [clickAwayHandler, activeVar,
|
|
86
|
+
}, [clickAwayHandler, activeVar, reference, floating]);
|
|
82
87
|
return _jsxs(_Fragment, {
|
|
83
88
|
children: [_jsxs(FieldPlace, {
|
|
84
|
-
ref:
|
|
89
|
+
ref: setReference,
|
|
85
90
|
children: [_jsxs(Horizontal, {
|
|
86
91
|
"$padding": "8px 16px",
|
|
87
92
|
"$justifyContent": "space-between",
|
|
@@ -121,7 +126,7 @@ export const DynamicContentPicker = ({
|
|
|
121
126
|
})
|
|
122
127
|
})]
|
|
123
128
|
}), !!activeVar && _jsxs("div", {
|
|
124
|
-
ref:
|
|
129
|
+
ref: setFloating,
|
|
125
130
|
style: floatingStyles,
|
|
126
131
|
children: [renderDynamicContent ? renderDynamicContent({
|
|
127
132
|
activeVar,
|
|
@@ -144,7 +149,7 @@ export const DynamicContentPicker = ({
|
|
|
144
149
|
update: update
|
|
145
150
|
}, activeVar), _jsx(Arrow, {
|
|
146
151
|
"$direction": placementToDirection(placement),
|
|
147
|
-
ref:
|
|
152
|
+
ref: setArrowElement,
|
|
148
153
|
style: {
|
|
149
154
|
left: middlewareData.arrow?.x,
|
|
150
155
|
top: middlewareData.arrow?.y
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
3
3
|
import { Button, Chip, Drawer, DrawerBody, DrawerHeader, DrawerTitle, NativeInput, useToast } from '@pushwoosh/dumb-components';
|
|
4
4
|
import { FlexContainer, useAsync, Vertical } from '@pushwoosh/kit-helpers';
|
|
5
5
|
import { CloseIcon } from '@pushwoosh/kit-icons';
|
|
@@ -40,8 +40,10 @@ export const CanvaImportDrawer = ({
|
|
|
40
40
|
const runRef = useRef(0);
|
|
41
41
|
const queryRef = useRef('');
|
|
42
42
|
const isOpenRef = useRef(isOpen);
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
useLayoutEffect(() => {
|
|
44
|
+
isOpenRef.current = isOpen;
|
|
45
|
+
queryRef.current = debouncedQuery;
|
|
46
|
+
}, [isOpen, debouncedQuery]);
|
|
45
47
|
const isReady = status.connected && status.tokenValid;
|
|
46
48
|
useEffect(() => {
|
|
47
49
|
const timer = window.setTimeout(() => setDebouncedQuery(query.trim()), SEARCH_DELAY_MS);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
3
3
|
import { Button, Checkbox, DropdownMenuButton, DropdownMenuItem, DropdownMenuSection, ModalConfirm, Tab, TabBar, TabPanel, Tabs, useToast } from '@pushwoosh/dumb-components';
|
|
4
4
|
import { FlexContainer, useAsync } from '@pushwoosh/kit-helpers';
|
|
5
5
|
import { CheckIcon, EditIcon, OpenIcon, TrashIcon, UploadIcon } from '@pushwoosh/kit-icons';
|
|
@@ -63,7 +63,9 @@ export const MediaStorage = ({
|
|
|
63
63
|
// `uploadFiles` resolves asynchronously; read the latest page from the ref so
|
|
64
64
|
// the post-upload decision isn't made on a value captured at click time.
|
|
65
65
|
const pageRef = useRef(page);
|
|
66
|
-
|
|
66
|
+
useLayoutEffect(() => {
|
|
67
|
+
pageRef.current = page;
|
|
68
|
+
}, [page]);
|
|
67
69
|
const [cropsByUuid, setCropsByUuid] = useState({});
|
|
68
70
|
// Bumped to force a reload of the current page when the originals list changes
|
|
69
71
|
// without the page prop changing (upload, delete of an original).
|
|
@@ -138,7 +140,9 @@ export const MediaStorage = ({
|
|
|
138
140
|
const total = listAsync.value?.total ?? 0;
|
|
139
141
|
// Read inside the async delete handler to avoid a stale-closure decision.
|
|
140
142
|
const filesCountRef = useRef(files.length);
|
|
141
|
-
|
|
143
|
+
useLayoutEffect(() => {
|
|
144
|
+
filesCountRef.current = files.length;
|
|
145
|
+
}, [files.length]);
|
|
142
146
|
useEffect(() => {
|
|
143
147
|
if (listAsync.error) {
|
|
144
148
|
openToast({
|
|
@@ -45,6 +45,7 @@ export const toMediaFile = (stored, source, fallbackName) => {
|
|
|
45
45
|
filename: file?.filename || fallbackName,
|
|
46
46
|
url: file?.url || stored.url,
|
|
47
47
|
fileSize: file?.fileSize ?? 0,
|
|
48
|
+
originalFileSize: 0,
|
|
48
49
|
mimeType: file?.mimeType ?? '',
|
|
49
50
|
createdAt: file?.createdAt ? new Date(file.createdAt) : new Date(),
|
|
50
51
|
description: file?.description,
|
|
@@ -55,7 +55,7 @@ export function usePagedItems(loadPage, resetKey, enabled = true) {
|
|
|
55
55
|
}));
|
|
56
56
|
requestPage(page);
|
|
57
57
|
}, [requestPage]);
|
|
58
|
-
const resetDeps = [resetKey, enabled,
|
|
58
|
+
const resetDeps = [resetKey, enabled, load];
|
|
59
59
|
const [prevResetDeps, setPrevResetDeps] = useState(null);
|
|
60
60
|
if (prevResetDeps === null || resetDeps.some((dep, index) => dep !== prevResetDeps[index])) {
|
|
61
61
|
setPrevResetDeps(resetDeps);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useMemo,
|
|
1
|
+
import { useMemo, useState } from 'react';
|
|
2
2
|
import { useHistory, useLocation } from 'react-router-dom';
|
|
3
3
|
import { usePersistentFunction } from '@pushwoosh/kit-helpers';
|
|
4
4
|
import { mapKeys, shallowEqual } from './helpers';
|
|
@@ -13,10 +13,7 @@ export function useDataTableGetParams({
|
|
|
13
13
|
const {
|
|
14
14
|
search: locationSearch
|
|
15
15
|
} = useLocation();
|
|
16
|
-
const
|
|
17
|
-
customizeParamsRef.current = customizeParams;
|
|
18
|
-
const prevDataTableParamsRef = useRef({});
|
|
19
|
-
const dataTableParams = useMemo(() => {
|
|
16
|
+
const urlParams = useMemo(() => {
|
|
20
17
|
const searchParams = new URLSearchParams(locationSearch);
|
|
21
18
|
const searchParamsWoPrefix = mapKeys(Object.fromEntries(searchParams), key => key.startsWith(prefix) ? key.slice(prefix.length) : key);
|
|
22
19
|
// eslint-disable-next-line no-nested-ternary
|
|
@@ -28,13 +25,28 @@ export function useDataTableGetParams({
|
|
|
28
25
|
page: +searchParamsWoPrefix.page || 1,
|
|
29
26
|
perPage: +searchParamsWoPrefix.perPage || defaultPerPage
|
|
30
27
|
};
|
|
28
|
+
return {
|
|
29
|
+
searchParamsWoPrefix,
|
|
30
|
+
params
|
|
31
|
+
};
|
|
32
|
+
}, [locationSearch, defaultDirection, defaultOrder, defaultPerPage, prefix]);
|
|
33
|
+
const readParams = () => customizeParams ? customizeParams(urlParams.searchParamsWoPrefix, urlParams.params) : urlParams.params;
|
|
34
|
+
const [stableParams, setStableParams] = useState(() => ({
|
|
35
|
+
urlParams,
|
|
36
|
+
params: readParams()
|
|
37
|
+
}));
|
|
38
|
+
let dataTableParams = stableParams.params;
|
|
39
|
+
if (stableParams.urlParams !== urlParams) {
|
|
40
|
+
const resultParams = readParams();
|
|
31
41
|
// it is necessary to compare with the previous parameters so that there are no extra rerenders
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
prevDataTableParamsRef.current = resultParams;
|
|
42
|
+
if (!shallowEqual(resultParams, dataTableParams)) {
|
|
43
|
+
dataTableParams = resultParams;
|
|
35
44
|
}
|
|
36
|
-
|
|
37
|
-
|
|
45
|
+
setStableParams({
|
|
46
|
+
urlParams,
|
|
47
|
+
params: dataTableParams
|
|
48
|
+
});
|
|
49
|
+
}
|
|
38
50
|
const changeDataTableParams = usePersistentFunction(params => {
|
|
39
51
|
const searchParams = new URLSearchParams(locationSearch);
|
|
40
52
|
const paramsWithPrefix = mapKeys(params, key => `${prefix}${key}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pushwoosh/smart-components-kit",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.4",
|
|
4
4
|
"description": "Stateful, data-connected React components shared by Pushwoosh micro-frontends",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -17,12 +17,12 @@
|
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@floating-ui/react-dom": "^2.1.2",
|
|
20
|
-
"@pushwoosh/dumb-components": "^4.
|
|
20
|
+
"@pushwoosh/dumb-components": "^4.6.0",
|
|
21
21
|
"@pushwoosh/kit-constants": "^3.0.0",
|
|
22
22
|
"@pushwoosh/kit-helpers": "^4.16.0",
|
|
23
23
|
"@pushwoosh/kit-icons": "^2.3.15",
|
|
24
24
|
"@pushwoosh/kit-typography": "^2.0.0",
|
|
25
|
-
"@pushwoosh/rpc-v2-http-api-data": "^0.2.
|
|
25
|
+
"@pushwoosh/rpc-v2-http-api-data": "^0.2.473",
|
|
26
26
|
"jwt-decode": "^4.0.0",
|
|
27
27
|
"react-hook-form": "^7.68.0"
|
|
28
28
|
},
|