@panneau/modal-form 4.0.49 → 4.0.52

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,23 +1,13 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { ReactNode, ForwardedRef } from 'react';
3
- import { Field } from '@panneau/core';
2
+ import { ForwardedRef } from 'react';
3
+ import { FormProps } from '@panneau/form';
4
+ import { DialogModalProps } from '@panneau/modal-dialog';
4
5
 
5
- interface ModalFormProps {
6
- id: string | number;
7
- title?: ReactNode | null;
8
- name?: string | null;
9
- fields?: Field[] | null;
10
- action?: string | null;
11
- type?: string;
12
- onComplete?: ((value: unknown) => void) | null;
13
- onCancel?: (() => void) | null;
14
- onClosed?: (() => void) | null;
15
- submitButtonLabel?: ReactNode | null;
6
+ interface FormModalProps extends Omit<FormProps, 'id' | 'title'>, DialogModalProps {
16
7
  withoutCloseOnComplete?: boolean;
17
- className?: string | null;
18
- children?: ReactNode | null;
19
8
  formRef?: ForwardedRef<HTMLFormElement> | null;
20
9
  }
21
- declare function ModalForm({ id, title, name, fields, action, type, onComplete, onCancel, onClosed, submitButtonLabel, withoutCloseOnComplete, className, children, formRef, ...props }: ModalFormProps): react_jsx_runtime.JSX.Element;
10
+ declare function FormModal({ id, title, fields, size, visible, requestClose: customRequestClose, onComplete, onCancel, onClosed, withoutCloseOnComplete, className, children, formRef: customFormRef, submitButtonLabel, cancelButtonLabel, withCancelButton, withoutSubmitButton, ...props }: FormModalProps): react_jsx_runtime.JSX.Element;
22
11
 
23
- export { ModalForm as default };
12
+ export { FormModal as default };
13
+ export type { FormModalProps };
package/dist/index.js CHANGED
@@ -1,12 +1,13 @@
1
1
  import { c } from 'react/compiler-runtime';
2
- import { useState } from 'react';
2
+ import { useState, useRef } from 'react';
3
3
  import { FormattedMessage } from 'react-intl';
4
+ import { mergeRefs } from '@panneau/core/utils';
4
5
  import Form from '@panneau/form';
5
6
  import Dialog from '@panneau/modal-dialog';
6
7
  import { jsx, jsxs } from 'react/jsx-runtime';
7
8
 
8
- function ModalForm(t0) {
9
- const $ = c(42);
9
+ function FormModal(t0) {
10
+ const $ = c(53);
10
11
  let id;
11
12
  let props;
12
13
  let t1;
@@ -14,6 +15,9 @@ function ModalForm(t0) {
14
15
  let t11;
15
16
  let t12;
16
17
  let t13;
18
+ let t14;
19
+ let t15;
20
+ let t16;
17
21
  let t2;
18
22
  let t3;
19
23
  let t4;
@@ -26,18 +30,21 @@ function ModalForm(t0) {
26
30
  ({
27
31
  id,
28
32
  title: t1,
29
- name: t2,
30
- fields: t3,
31
- action: t4,
32
- type: t5,
33
+ fields: t2,
34
+ size: t3,
35
+ visible: t4,
36
+ requestClose: t5,
33
37
  onComplete: t6,
34
38
  onCancel: t7,
35
39
  onClosed: t8,
36
- submitButtonLabel: t9,
37
- withoutCloseOnComplete: t10,
38
- className: t11,
39
- children: t12,
40
- formRef: t13,
40
+ withoutCloseOnComplete: t9,
41
+ className: t10,
42
+ children: t11,
43
+ formRef: t12,
44
+ submitButtonLabel: t13,
45
+ cancelButtonLabel: t14,
46
+ withCancelButton: t15,
47
+ withoutSubmitButton: t16,
41
48
  ...props
42
49
  } = t0);
43
50
  $[0] = t0;
@@ -48,14 +55,17 @@ function ModalForm(t0) {
48
55
  $[5] = t11;
49
56
  $[6] = t12;
50
57
  $[7] = t13;
51
- $[8] = t2;
52
- $[9] = t3;
53
- $[10] = t4;
54
- $[11] = t5;
55
- $[12] = t6;
56
- $[13] = t7;
57
- $[14] = t8;
58
- $[15] = t9;
58
+ $[8] = t14;
59
+ $[9] = t15;
60
+ $[10] = t16;
61
+ $[11] = t2;
62
+ $[12] = t3;
63
+ $[13] = t4;
64
+ $[14] = t5;
65
+ $[15] = t6;
66
+ $[16] = t7;
67
+ $[17] = t8;
68
+ $[18] = t9;
59
69
  } else {
60
70
  id = $[1];
61
71
  props = $[2];
@@ -64,135 +74,166 @@ function ModalForm(t0) {
64
74
  t11 = $[5];
65
75
  t12 = $[6];
66
76
  t13 = $[7];
67
- t2 = $[8];
68
- t3 = $[9];
69
- t4 = $[10];
70
- t5 = $[11];
71
- t6 = $[12];
72
- t7 = $[13];
73
- t8 = $[14];
74
- t9 = $[15];
77
+ t14 = $[8];
78
+ t15 = $[9];
79
+ t16 = $[10];
80
+ t2 = $[11];
81
+ t3 = $[12];
82
+ t4 = $[13];
83
+ t5 = $[14];
84
+ t6 = $[15];
85
+ t7 = $[16];
86
+ t8 = $[17];
87
+ t9 = $[18];
75
88
  }
76
89
  const title = t1 === undefined ? null : t1;
77
- const name = t2 === undefined ? null : t2;
78
- const fields = t3 === undefined ? null : t3;
79
- const action = t4 === undefined ? null : t4;
80
- const type = t5 === undefined ? "normal" : t5;
90
+ const fields = t2 === undefined ? null : t2;
91
+ const size = t3 === undefined ? "lg" : t3;
92
+ const visible = t4 === undefined ? null : t4;
93
+ const customRequestClose = t5 === undefined ? null : t5;
81
94
  const onComplete = t6 === undefined ? null : t6;
82
95
  const onCancel = t7 === undefined ? null : t7;
83
96
  const onClosed = t8 === undefined ? null : t8;
84
- const submitButtonLabel = t9 === undefined ? null : t9;
85
- const withoutCloseOnComplete = t10 === undefined ? false : t10;
86
- const className = t11 === undefined ? null : t11;
87
- const children = t12 === undefined ? null : t12;
88
- const formRef = t13 === undefined ? null : t13;
97
+ const withoutCloseOnComplete = t9 === undefined ? false : t9;
98
+ const className = t10 === undefined ? null : t10;
99
+ const children = t11 === undefined ? null : t11;
100
+ const customFormRef = t12 === undefined ? null : t12;
101
+ const submitButtonLabel = t13 === undefined ? null : t13;
102
+ const cancelButtonLabel = t14 === undefined ? null : t14;
103
+ const withCancelButton = t15 === undefined ? true : t15;
104
+ const withoutSubmitButton = t16 === undefined ? false : t16;
89
105
  const [opened, setOpened] = useState(true);
90
- let t14;
91
- if ($[16] === Symbol.for("react.memo_cache_sentinel")) {
92
- t14 = () => {
106
+ const formRef = useRef(null);
107
+ let t17;
108
+ if ($[19] !== customRequestClose) {
109
+ t17 = customRequestClose ?? (() => {
93
110
  setOpened(false);
94
- };
95
- $[16] = t14;
111
+ });
112
+ $[19] = customRequestClose;
113
+ $[20] = t17;
96
114
  } else {
97
- t14 = $[16];
115
+ t17 = $[20];
98
116
  }
99
- const requestClose = t14;
100
- let t15;
101
- if ($[17] !== onCancel) {
102
- t15 = () => {
103
- setOpened(false);
117
+ const requestClose = t17;
118
+ let t18;
119
+ if ($[21] !== onCancel || $[22] !== requestClose) {
120
+ t18 = () => {
121
+ requestClose();
104
122
  if (onCancel !== null) {
105
123
  onCancel();
106
124
  }
107
125
  };
108
- $[17] = onCancel;
109
- $[18] = t15;
126
+ $[21] = onCancel;
127
+ $[22] = requestClose;
128
+ $[23] = t18;
110
129
  } else {
111
- t15 = $[18];
130
+ t18 = $[23];
112
131
  }
113
- const onFormCancel = t15;
114
- let t16;
115
- if ($[19] !== onComplete || $[20] !== withoutCloseOnComplete) {
116
- t16 = value => {
132
+ const onFormCancel = t18;
133
+ let t19;
134
+ if ($[24] !== onComplete || $[25] !== requestClose || $[26] !== withoutCloseOnComplete) {
135
+ t19 = value => {
117
136
  if (!withoutCloseOnComplete) {
118
- setOpened(false);
137
+ requestClose();
119
138
  }
120
139
  if (onComplete !== null) {
121
140
  onComplete(value);
122
141
  }
123
142
  };
124
- $[19] = onComplete;
125
- $[20] = withoutCloseOnComplete;
126
- $[21] = t16;
143
+ $[24] = onComplete;
144
+ $[25] = requestClose;
145
+ $[26] = withoutCloseOnComplete;
146
+ $[27] = t19;
127
147
  } else {
128
- t16 = $[21];
148
+ t19 = $[27];
129
149
  }
130
- const onFormComplete = t16;
131
- let t17;
132
- if ($[22] !== name || $[23] !== title) {
133
- t17 = title || (name !== null ? /*#__PURE__*/jsx(FormattedMessage, {
134
- id: "smqUAV",
135
- values: {
136
- name
150
+ const onFormComplete = t19;
151
+ let t20;
152
+ if ($[28] === Symbol.for("react.memo_cache_sentinel")) {
153
+ t20 = () => {
154
+ if (formRef.current !== null) {
155
+ formRef.current.requestSubmit();
137
156
  }
138
- }) : /*#__PURE__*/jsx(FormattedMessage, {
157
+ };
158
+ $[28] = t20;
159
+ } else {
160
+ t20 = $[28];
161
+ }
162
+ const onClickSubmit = t20;
163
+ let t21;
164
+ if ($[29] !== title) {
165
+ t21 = title || /*#__PURE__*/jsx(FormattedMessage, {
139
166
  id: "T/NPHK"
140
- }));
141
- $[22] = name;
142
- $[23] = title;
143
- $[24] = t17;
167
+ });
168
+ $[29] = title;
169
+ $[30] = t21;
144
170
  } else {
145
- t17 = $[24];
171
+ t21 = $[30];
146
172
  }
147
- let t18;
148
- if ($[25] !== action || $[26] !== fields || $[27] !== formRef || $[28] !== onFormCancel || $[29] !== onFormComplete || $[30] !== props || $[31] !== submitButtonLabel || $[32] !== type) {
149
- t18 = /*#__PURE__*/jsx(Form, {
173
+ const t22 = visible ?? opened;
174
+ const t23 = !withoutSubmitButton;
175
+ let t24;
176
+ if ($[31] !== customFormRef) {
177
+ t24 = mergeRefs(formRef, customFormRef);
178
+ $[31] = customFormRef;
179
+ $[32] = t24;
180
+ } else {
181
+ t24 = $[32];
182
+ }
183
+ let t25;
184
+ if ($[33] !== fields || $[34] !== onFormCancel || $[35] !== onFormComplete || $[36] !== props || $[37] !== t24) {
185
+ t25 = /*#__PURE__*/jsx(Form, {
186
+ withoutActions: true,
150
187
  ...props,
151
- ref: formRef,
188
+ ref: t24,
152
189
  fields: fields,
153
- action: action,
154
- type: type,
155
- buttonSize: "md",
156
190
  onComplete: onFormComplete,
157
- onCancel: onFormCancel,
158
- submitButtonLabel: submitButtonLabel
191
+ onCancel: onFormCancel
159
192
  });
160
- $[25] = action;
161
- $[26] = fields;
162
- $[27] = formRef;
163
- $[28] = onFormCancel;
164
- $[29] = onFormComplete;
165
- $[30] = props;
166
- $[31] = submitButtonLabel;
167
- $[32] = type;
168
- $[33] = t18;
193
+ $[33] = fields;
194
+ $[34] = onFormCancel;
195
+ $[35] = onFormComplete;
196
+ $[36] = props;
197
+ $[37] = t24;
198
+ $[38] = t25;
169
199
  } else {
170
- t18 = $[33];
200
+ t25 = $[38];
171
201
  }
172
- let t19;
173
- if ($[34] !== children || $[35] !== className || $[36] !== id || $[37] !== onClosed || $[38] !== opened || $[39] !== t17 || $[40] !== t18) {
174
- t19 = /*#__PURE__*/jsxs(Dialog, {
202
+ let t26;
203
+ if ($[39] !== cancelButtonLabel || $[40] !== children || $[41] !== className || $[42] !== id || $[43] !== onClosed || $[44] !== requestClose || $[45] !== size || $[46] !== submitButtonLabel || $[47] !== t21 || $[48] !== t22 || $[49] !== t23 || $[50] !== t25 || $[51] !== withCancelButton) {
204
+ t26 = /*#__PURE__*/jsxs(Dialog, {
175
205
  id: id,
176
- title: t17,
177
- size: "lg",
178
- visible: opened,
206
+ title: t21,
207
+ size: size,
208
+ visible: t22,
209
+ withCancelButton: withCancelButton,
210
+ withSubmitButton: t23,
179
211
  requestClose: requestClose,
180
212
  onClosed: onClosed,
213
+ onClickSubmit: onClickSubmit,
181
214
  className: className,
182
- children: [children, t18]
215
+ submitButtonLabel: submitButtonLabel,
216
+ cancelButtonLabel: cancelButtonLabel,
217
+ children: [children, t25]
183
218
  });
184
- $[34] = children;
185
- $[35] = className;
186
- $[36] = id;
187
- $[37] = onClosed;
188
- $[38] = opened;
189
- $[39] = t17;
190
- $[40] = t18;
191
- $[41] = t19;
219
+ $[39] = cancelButtonLabel;
220
+ $[40] = children;
221
+ $[41] = className;
222
+ $[42] = id;
223
+ $[43] = onClosed;
224
+ $[44] = requestClose;
225
+ $[45] = size;
226
+ $[46] = submitButtonLabel;
227
+ $[47] = t21;
228
+ $[48] = t22;
229
+ $[49] = t23;
230
+ $[50] = t25;
231
+ $[51] = withCancelButton;
232
+ $[52] = t26;
192
233
  } else {
193
- t19 = $[41];
234
+ t26 = $[52];
194
235
  }
195
- return t19;
236
+ return t26;
196
237
  }
197
238
 
198
- export { ModalForm as default };
239
+ export { FormModal as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@panneau/modal-form",
3
- "version": "4.0.49",
3
+ "version": "4.0.52",
4
4
  "description": "Resource form modal",
5
5
  "keywords": [
6
6
  "javascript"
@@ -52,11 +52,11 @@
52
52
  },
53
53
  "dependencies": {
54
54
  "@babel/runtime": "^7.28.6",
55
- "@panneau/core": "^4.0.48",
56
- "@panneau/form": "^4.0.49",
57
- "@panneau/intl": "^4.0.48",
58
- "@panneau/modal-dialog": "^4.0.48",
59
- "@panneau/themes": "^4.0.48",
55
+ "@panneau/core": "^4.0.50",
56
+ "@panneau/form": "^4.0.50",
57
+ "@panneau/intl": "^4.0.50",
58
+ "@panneau/modal-dialog": "^4.0.50",
59
+ "@panneau/themes": "^4.0.50",
60
60
  "classnames": "^2.5.1",
61
61
  "lodash": "^4.17.21",
62
62
  "react-intl": "^6.0.0 || ^7.0.0 || ^8.0.0 || ^10.0.0"
@@ -64,5 +64,5 @@
64
64
  "publishConfig": {
65
65
  "access": "public"
66
66
  },
67
- "gitHead": "cc6f219752687293408ee6b8a08be173ef85f80e"
67
+ "gitHead": "280155c90cf1dfc39e0c36c76ef8bc2fea627041"
68
68
  }