@panneau/action-duplicate 4.0.73 → 4.0.74

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/dist/index.d.ts CHANGED
@@ -1,15 +1,16 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
- import { ActionValue, ButtonTheme } from '@panneau/core';
3
+ import { Resource, ActionValue, ButtonTheme } from '@panneau/core';
4
4
 
5
5
  interface DuplicateActionProps {
6
- id: string;
6
+ resource?: Resource | string | null;
7
7
  title?: ReactNode | null;
8
8
  description?: ReactNode | null;
9
9
  endpoint?: string;
10
10
  endpointIdsParamName?: string;
11
11
  action?: ((value: ActionValue) => Promise<unknown>) | null;
12
12
  label?: string | null;
13
+ href?: string | null;
13
14
  value?: ActionValue | null;
14
15
  icon?: string;
15
16
  theme?: ButtonTheme;
@@ -19,9 +20,10 @@ interface DuplicateActionProps {
19
20
  onConfirmed?: ((response: unknown) => void) | null;
20
21
  valueLabelPath?: string | null;
21
22
  modalComponent?: string;
22
- withConfirmation?: boolean;
23
+ withoutConfirmation?: boolean;
24
+ onClick?: (() => void) | null;
23
25
  className?: string | null;
24
26
  }
25
- declare function DuplicateAction({ id, title, description, endpoint, endpointIdsParamName, action, label: initialLabel, icon, value, theme, disabled, multiple, onChange, onConfirmed, valueLabelPath, modalComponent, withConfirmation, className, ...props }: DuplicateActionProps): react.JSX.Element;
27
+ declare function DuplicateAction({ resource: initialResource, title, description, endpoint, endpointIdsParamName, action, label: initialLabel, href: initialHref, icon, value, theme, disabled, multiple, onChange, onConfirmed, valueLabelPath, modalComponent, withoutConfirmation, className, onClick, ...props }: DuplicateActionProps): react.JSX.Element;
26
28
 
27
29
  export { DuplicateAction as default };
package/dist/index.js CHANGED
@@ -1,70 +1,242 @@
1
+ import { c } from 'react/compiler-runtime';
1
2
  import { postJSON, getCSRFHeaders } from '@folklore/fetch';
3
+ import { isObject } from 'lodash';
2
4
  import isArray from 'lodash-es/isArray';
3
- import { useState, useCallback } from 'react';
5
+ import { useState } from 'react';
4
6
  import { FormattedMessage } from 'react-intl';
5
- import { useModalsComponentsManager } from '@panneau/core/contexts';
7
+ import { useResource, useModalsComponentsManager } from '@panneau/core/contexts';
8
+ import { useResourceUrlGenerator } from '@panneau/core/hooks';
6
9
  import Button from '@panneau/element-button';
7
- import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
10
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
8
11
 
9
- function DuplicateAction({
10
- id,
11
- title = null,
12
- description = null,
13
- endpoint = '/duplicate',
14
- endpointIdsParamName = 'ids',
15
- action = null,
16
- label: initialLabel = null,
17
- icon = 'copy',
18
- value = null,
19
- theme = 'secondary',
20
- disabled = false,
21
- multiple = false,
22
- onChange = null,
23
- onConfirmed = null,
24
- valueLabelPath = null,
25
- modalComponent = 'confirm',
26
- withConfirmation = false,
27
- className = null,
28
- ...props
29
- }) {
30
- const label = initialLabel || /*#__PURE__*/jsx(FormattedMessage, {
31
- id: "HzCxmr"
32
- });
12
+ function DuplicateAction(t0) {
13
+ const $ = c(62);
14
+ let props;
15
+ let t1;
16
+ let t10;
17
+ let t11;
18
+ let t12;
19
+ let t13;
20
+ let t14;
21
+ let t15;
22
+ let t16;
23
+ let t17;
24
+ let t18;
25
+ let t19;
26
+ let t2;
27
+ let t20;
28
+ let t3;
29
+ let t4;
30
+ let t5;
31
+ let t6;
32
+ let t7;
33
+ let t8;
34
+ let t9;
35
+ if ($[0] !== t0) {
36
+ ({
37
+ resource: t1,
38
+ title: t2,
39
+ description: t3,
40
+ endpoint: t4,
41
+ endpointIdsParamName: t5,
42
+ action: t6,
43
+ label: t7,
44
+ href: t8,
45
+ icon: t9,
46
+ value: t10,
47
+ theme: t11,
48
+ disabled: t12,
49
+ multiple: t13,
50
+ onChange: t14,
51
+ onConfirmed: t15,
52
+ valueLabelPath: t16,
53
+ modalComponent: t17,
54
+ withoutConfirmation: t18,
55
+ className: t19,
56
+ onClick: t20,
57
+ ...props
58
+ } = t0);
59
+ $[0] = t0;
60
+ $[1] = props;
61
+ $[2] = t1;
62
+ $[3] = t10;
63
+ $[4] = t11;
64
+ $[5] = t12;
65
+ $[6] = t13;
66
+ $[7] = t14;
67
+ $[8] = t15;
68
+ $[9] = t16;
69
+ $[10] = t17;
70
+ $[11] = t18;
71
+ $[12] = t19;
72
+ $[13] = t2;
73
+ $[14] = t20;
74
+ $[15] = t3;
75
+ $[16] = t4;
76
+ $[17] = t5;
77
+ $[18] = t6;
78
+ $[19] = t7;
79
+ $[20] = t8;
80
+ $[21] = t9;
81
+ } else {
82
+ props = $[1];
83
+ t1 = $[2];
84
+ t10 = $[3];
85
+ t11 = $[4];
86
+ t12 = $[5];
87
+ t13 = $[6];
88
+ t14 = $[7];
89
+ t15 = $[8];
90
+ t16 = $[9];
91
+ t17 = $[10];
92
+ t18 = $[11];
93
+ t19 = $[12];
94
+ t2 = $[13];
95
+ t20 = $[14];
96
+ t3 = $[15];
97
+ t4 = $[16];
98
+ t5 = $[17];
99
+ t6 = $[18];
100
+ t7 = $[19];
101
+ t8 = $[20];
102
+ t9 = $[21];
103
+ }
104
+ const initialResource = t1 === undefined ? null : t1;
105
+ const title = t2 === undefined ? null : t2;
106
+ const description = t3 === undefined ? null : t3;
107
+ const endpoint = t4 === undefined ? "/duplicate" : t4;
108
+ const endpointIdsParamName = t5 === undefined ? "ids" : t5;
109
+ const action = t6 === undefined ? null : t6;
110
+ const initialLabel = t7 === undefined ? null : t7;
111
+ const initialHref = t8 === undefined ? null : t8;
112
+ const icon = t9 === undefined ? "copy" : t9;
113
+ const value = t10 === undefined ? null : t10;
114
+ const theme = t11 === undefined ? "secondary" : t11;
115
+ const disabled = t12 === undefined ? false : t12;
116
+ const multiple = t13 === undefined ? false : t13;
117
+ const onChange = t14 === undefined ? null : t14;
118
+ const onConfirmed = t15 === undefined ? null : t15;
119
+ const modalComponent = t17 === undefined ? "confirm" : t17;
120
+ const withoutConfirmation = t18 === undefined ? false : t18;
121
+ const className = t19 === undefined ? null : t19;
122
+ const onClick = t20 === undefined ? null : t20;
123
+ const contextResource = useResource();
124
+ const resource = initialResource || contextResource;
125
+ const resourceUrl = useResourceUrlGenerator(resource);
126
+ let t21;
127
+ if ($[22] !== initialLabel) {
128
+ t21 = initialLabel || /*#__PURE__*/jsx(FormattedMessage, {
129
+ id: "HzCxmr"
130
+ });
131
+ $[22] = initialLabel;
132
+ $[23] = t21;
133
+ } else {
134
+ t21 = $[23];
135
+ }
136
+ const label = t21;
137
+ let t22;
138
+ if ($[24] !== initialHref || $[25] !== multiple || $[26] !== resourceUrl || $[27] !== value) {
139
+ t22 = initialHref || (!multiple && isObject(value) && !isArray(value) ? resourceUrl("duplicate", value) : null);
140
+ $[24] = initialHref;
141
+ $[25] = multiple;
142
+ $[26] = resourceUrl;
143
+ $[27] = value;
144
+ $[28] = t22;
145
+ } else {
146
+ t22 = $[28];
147
+ }
148
+ const finalHref = t22;
33
149
  const ModalComponents = useModalsComponentsManager();
34
- const ModalComponent = ModalComponents.getComponent(modalComponent);
150
+ let t23;
151
+ if ($[29] !== ModalComponents || $[30] !== modalComponent) {
152
+ t23 = ModalComponents.getComponent(modalComponent);
153
+ $[29] = ModalComponents;
154
+ $[30] = modalComponent;
155
+ $[31] = t23;
156
+ } else {
157
+ t23 = $[31];
158
+ }
159
+ const ModalComponent = t23;
35
160
  const [modalOpen, setModalOpen] = useState(false);
36
161
  const [error, setError] = useState(null);
37
- const onOpen = useCallback(() => {
38
- setModalOpen(true);
39
- }, [setModalOpen]);
40
- const onClosed = useCallback(() => {
41
- setModalOpen(false);
42
- }, [setModalOpen]);
43
- const onConfirm = useCallback(() => (action !== null ? action(value) : postJSON(endpoint, {
44
- [endpointIdsParamName]: (isArray(value) ? value : [value]).filter(it => it !== null).map(it_0 => it_0?.id)
45
- }, {
46
- credentials: 'include',
47
- headers: getCSRFHeaders()
48
- })).then(response => {
49
- if (onConfirmed !== null) {
50
- onConfirmed(response);
51
- }
52
- if (onChange !== null) {
53
- onChange(response);
54
- }
55
- }).catch(err => {
56
- setError(err);
57
- }), [value, endpoint, action, onChange, setError, onConfirmed]);
58
- return /*#__PURE__*/jsxs(Fragment, {
59
- children: [/*#__PURE__*/jsx(Button, {
162
+ let t24;
163
+ if ($[32] === Symbol.for("react.memo_cache_sentinel")) {
164
+ t24 = () => {
165
+ setModalOpen(true);
166
+ };
167
+ $[32] = t24;
168
+ } else {
169
+ t24 = $[32];
170
+ }
171
+ const onOpen = t24;
172
+ let t25;
173
+ if ($[33] === Symbol.for("react.memo_cache_sentinel")) {
174
+ t25 = () => {
175
+ setModalOpen(false);
176
+ };
177
+ $[33] = t25;
178
+ } else {
179
+ t25 = $[33];
180
+ }
181
+ const onClosed = t25;
182
+ let t26;
183
+ if ($[34] !== action || $[35] !== endpoint || $[36] !== endpointIdsParamName || $[37] !== onChange || $[38] !== onConfirmed || $[39] !== value) {
184
+ t26 = () => (action !== null ? action(value) : postJSON(endpoint, {
185
+ [endpointIdsParamName]: (isArray(value) ? value : [value]).filter(_temp).map(_temp2)
186
+ }, {
187
+ credentials: "include",
188
+ headers: getCSRFHeaders()
189
+ })).then(response => {
190
+ if (onConfirmed !== null) {
191
+ onConfirmed(response);
192
+ }
193
+ if (onChange !== null) {
194
+ onChange(response);
195
+ }
196
+ }).catch(err => {
197
+ setError(err);
198
+ });
199
+ $[34] = action;
200
+ $[35] = endpoint;
201
+ $[36] = endpointIdsParamName;
202
+ $[37] = onChange;
203
+ $[38] = onConfirmed;
204
+ $[39] = value;
205
+ $[40] = t26;
206
+ } else {
207
+ t26 = $[40];
208
+ }
209
+ const onConfirm = t26;
210
+ const t27 = onClick ?? (withoutConfirmation ? onConfirm : onOpen);
211
+ const t28 = disabled ? "secondary" : theme;
212
+ const t29 = withoutConfirmation ? finalHref : null;
213
+ let t30;
214
+ if ($[41] !== className || $[42] !== disabled || $[43] !== icon || $[44] !== label || $[45] !== props || $[46] !== t27 || $[47] !== t28 || $[48] !== t29) {
215
+ t30 = /*#__PURE__*/jsx(Button, {
60
216
  className: className,
61
217
  label: label,
62
218
  icon: icon,
63
- onClick: withConfirmation ? onOpen : null,
219
+ onClick: t27,
64
220
  disabled: disabled,
65
- theme: disabled ? 'secondary' : theme,
221
+ theme: t28,
222
+ href: t29,
66
223
  ...props
67
- }), modalOpen ? /*#__PURE__*/jsxs(ModalComponent, {
224
+ });
225
+ $[41] = className;
226
+ $[42] = disabled;
227
+ $[43] = icon;
228
+ $[44] = label;
229
+ $[45] = props;
230
+ $[46] = t27;
231
+ $[47] = t28;
232
+ $[48] = t29;
233
+ $[49] = t30;
234
+ } else {
235
+ t30 = $[49];
236
+ }
237
+ let t31;
238
+ if ($[50] !== ModalComponent || $[51] !== description || $[52] !== error || $[53] !== modalOpen || $[54] !== multiple || $[55] !== onConfirm || $[56] !== title || $[57] !== value) {
239
+ t31 = modalOpen ? /*#__PURE__*/jsxs(ModalComponent, {
68
240
  title: title || /*#__PURE__*/jsx(FormattedMessage, {
69
241
  id: "8T+JE7"
70
242
  }),
@@ -74,7 +246,7 @@ function DuplicateAction({
74
246
  label: /*#__PURE__*/jsx(FormattedMessage, {
75
247
  id: "UaVu03"
76
248
  }),
77
- theme: 'danger'
249
+ theme: "danger"
78
250
  },
79
251
  cancelButton: {
80
252
  label: /*#__PURE__*/jsx(FormattedMessage, {
@@ -85,19 +257,51 @@ function DuplicateAction({
85
257
  children: multiple ? /*#__PURE__*/jsx(FormattedMessage, {
86
258
  id: "GKcYDd",
87
259
  values: {
88
- id: value !== null && !isArray(value) ? `#${value?.id}` : ''
260
+ id: value !== null && !isArray(value) ? `#${value?.id}` : ""
89
261
  }
90
262
  }) : /*#__PURE__*/jsx(FormattedMessage, {
91
263
  id: "XmY7D8",
92
264
  values: {
93
- ids: value !== null && isArray(value) ? value.map(it_1 => `#${it_1?.id}`).join(', ') : ''
265
+ ids: value !== null && isArray(value) ? value.map(_temp3).join(", ") : ""
94
266
  }
95
267
  })
96
268
  }), error !== null ? /*#__PURE__*/jsx(FormattedMessage, {
97
269
  id: "cutyQH"
98
270
  }) : null]
99
- }) : null]
100
- });
271
+ }) : null;
272
+ $[50] = ModalComponent;
273
+ $[51] = description;
274
+ $[52] = error;
275
+ $[53] = modalOpen;
276
+ $[54] = multiple;
277
+ $[55] = onConfirm;
278
+ $[56] = title;
279
+ $[57] = value;
280
+ $[58] = t31;
281
+ } else {
282
+ t31 = $[58];
283
+ }
284
+ let t32;
285
+ if ($[59] !== t30 || $[60] !== t31) {
286
+ t32 = /*#__PURE__*/jsxs(Fragment, {
287
+ children: [t30, t31]
288
+ });
289
+ $[59] = t30;
290
+ $[60] = t31;
291
+ $[61] = t32;
292
+ } else {
293
+ t32 = $[61];
294
+ }
295
+ return t32;
296
+ }
297
+ function _temp3(it_1) {
298
+ return `#${it_1?.id}`;
299
+ }
300
+ function _temp2(it_0) {
301
+ return it_0?.id;
302
+ }
303
+ function _temp(it) {
304
+ return it !== null;
101
305
  }
102
306
 
103
307
  export { DuplicateAction as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@panneau/action-duplicate",
3
- "version": "4.0.73",
3
+ "version": "4.0.74",
4
4
  "description": "Duplicate action",
5
5
  "keywords": [
6
6
  "javascript"
@@ -46,9 +46,9 @@
46
46
  "dependencies": {
47
47
  "@babel/runtime": "^7.28.6",
48
48
  "@folklore/fetch": "^0.1.21",
49
- "@panneau/core": "^4.0.73",
50
- "@panneau/element-button": "^4.0.73",
51
- "@panneau/themes": "^4.0.73",
49
+ "@panneau/core": "^4.0.74",
50
+ "@panneau/element-button": "^4.0.74",
51
+ "@panneau/themes": "^4.0.74",
52
52
  "classnames": "^2.5.1",
53
53
  "react-intl": "^6.0.0 || ^7.0.0 || ^8.0.0 || ^10.0.0"
54
54
  },
@@ -63,5 +63,5 @@
63
63
  "publishConfig": {
64
64
  "access": "public"
65
65
  },
66
- "gitHead": "59fe06241775f60d387d99b22c16bb474964e6d0"
66
+ "gitHead": "122cadcf8ea5faacc035e7fe911fbdfb9fb87d26"
67
67
  }