@panneau/modal-form 4.0.49 → 4.0.50

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,19 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { ReactNode, ForwardedRef } from 'react';
3
- import { Field } from '@panneau/core';
3
+ import { FormProps } from '@panneau/form';
4
+ import { DialogProps } from '@panneau/modal-dialog';
4
5
 
5
- interface ModalFormProps {
6
- id: string | number;
7
- title?: ReactNode | null;
6
+ interface FormModalProps extends Omit<FormProps, 'id' | 'title'>, Pick<DialogProps, 'id' | 'title' | 'size'> {
8
7
  name?: string | null;
9
- fields?: Field[] | null;
10
- action?: string | null;
11
8
  type?: string;
12
- onComplete?: ((value: unknown) => void) | null;
13
9
  onCancel?: (() => void) | null;
14
10
  onClosed?: (() => void) | null;
15
- submitButtonLabel?: ReactNode | null;
16
11
  withoutCloseOnComplete?: boolean;
17
12
  className?: string | null;
18
13
  children?: ReactNode | null;
19
14
  formRef?: ForwardedRef<HTMLFormElement> | null;
20
15
  }
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;
16
+ declare function FormModal({ id, title, name, fields, type, size, onComplete, onCancel, onClosed, withoutCloseOnComplete, className, children, formRef: customFormRef, submitButtonLabel, cancelButtonLabel, withCancelButton, withoutSubmitButton, ...props }: FormModalProps): react_jsx_runtime.JSX.Element;
22
17
 
23
- export { ModalForm as default };
18
+ export { FormModal as default };
19
+ 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(51);
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;
@@ -28,16 +32,19 @@ function ModalForm(t0) {
28
32
  title: t1,
29
33
  name: t2,
30
34
  fields: t3,
31
- action: t4,
32
- type: t5,
35
+ type: t4,
36
+ size: 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,56 +74,63 @@ 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
90
  const name = t2 === undefined ? null : t2;
78
91
  const fields = t3 === undefined ? null : t3;
79
- const action = t4 === undefined ? null : t4;
80
- const type = t5 === undefined ? "normal" : t5;
92
+ const type = t4 === undefined ? "normal" : t4;
93
+ const size = t5 === undefined ? "lg" : 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] === Symbol.for("react.memo_cache_sentinel")) {
109
+ t17 = () => {
93
110
  setOpened(false);
94
111
  };
95
- $[16] = t14;
112
+ $[19] = t17;
96
113
  } else {
97
- t14 = $[16];
114
+ t17 = $[19];
98
115
  }
99
- const requestClose = t14;
100
- let t15;
101
- if ($[17] !== onCancel) {
102
- t15 = () => {
116
+ const requestClose = t17;
117
+ let t18;
118
+ if ($[20] !== onCancel) {
119
+ t18 = () => {
103
120
  setOpened(false);
104
121
  if (onCancel !== null) {
105
122
  onCancel();
106
123
  }
107
124
  };
108
- $[17] = onCancel;
109
- $[18] = t15;
125
+ $[20] = onCancel;
126
+ $[21] = t18;
110
127
  } else {
111
- t15 = $[18];
128
+ t18 = $[21];
112
129
  }
113
- const onFormCancel = t15;
114
- let t16;
115
- if ($[19] !== onComplete || $[20] !== withoutCloseOnComplete) {
116
- t16 = value => {
130
+ const onFormCancel = t18;
131
+ let t19;
132
+ if ($[22] !== onComplete || $[23] !== withoutCloseOnComplete) {
133
+ t19 = value => {
117
134
  if (!withoutCloseOnComplete) {
118
135
  setOpened(false);
119
136
  }
@@ -121,16 +138,28 @@ function ModalForm(t0) {
121
138
  onComplete(value);
122
139
  }
123
140
  };
124
- $[19] = onComplete;
125
- $[20] = withoutCloseOnComplete;
126
- $[21] = t16;
141
+ $[22] = onComplete;
142
+ $[23] = withoutCloseOnComplete;
143
+ $[24] = t19;
127
144
  } else {
128
- t16 = $[21];
145
+ t19 = $[24];
129
146
  }
130
- const onFormComplete = t16;
131
- let t17;
132
- if ($[22] !== name || $[23] !== title) {
133
- t17 = title || (name !== null ? /*#__PURE__*/jsx(FormattedMessage, {
147
+ const onFormComplete = t19;
148
+ let t20;
149
+ if ($[25] === Symbol.for("react.memo_cache_sentinel")) {
150
+ t20 = () => {
151
+ if (formRef.current !== null) {
152
+ formRef.current.submit();
153
+ }
154
+ };
155
+ $[25] = t20;
156
+ } else {
157
+ t20 = $[25];
158
+ }
159
+ const onClickSubmit = t20;
160
+ let t21;
161
+ if ($[26] !== name || $[27] !== title) {
162
+ t21 = title || (name !== null ? /*#__PURE__*/jsx(FormattedMessage, {
134
163
  id: "smqUAV",
135
164
  values: {
136
165
  name
@@ -138,61 +167,76 @@ function ModalForm(t0) {
138
167
  }) : /*#__PURE__*/jsx(FormattedMessage, {
139
168
  id: "T/NPHK"
140
169
  }));
141
- $[22] = name;
142
- $[23] = title;
143
- $[24] = t17;
170
+ $[26] = name;
171
+ $[27] = title;
172
+ $[28] = t21;
144
173
  } else {
145
- t17 = $[24];
174
+ t21 = $[28];
146
175
  }
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, {
176
+ const t22 = !withoutSubmitButton;
177
+ let t23;
178
+ if ($[29] !== customFormRef) {
179
+ t23 = mergeRefs(formRef, customFormRef);
180
+ $[29] = customFormRef;
181
+ $[30] = t23;
182
+ } else {
183
+ t23 = $[30];
184
+ }
185
+ let t24;
186
+ if ($[31] !== fields || $[32] !== onFormCancel || $[33] !== onFormComplete || $[34] !== props || $[35] !== t23 || $[36] !== type) {
187
+ t24 = /*#__PURE__*/jsx(Form, {
188
+ withoutActions: true,
150
189
  ...props,
151
- ref: formRef,
190
+ ref: t23,
152
191
  fields: fields,
153
- action: action,
154
192
  type: type,
155
- buttonSize: "md",
156
193
  onComplete: onFormComplete,
157
- onCancel: onFormCancel,
158
- submitButtonLabel: submitButtonLabel
194
+ onCancel: onFormCancel
159
195
  });
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;
196
+ $[31] = fields;
197
+ $[32] = onFormCancel;
198
+ $[33] = onFormComplete;
199
+ $[34] = props;
200
+ $[35] = t23;
201
+ $[36] = type;
202
+ $[37] = t24;
169
203
  } else {
170
- t18 = $[33];
204
+ t24 = $[37];
171
205
  }
172
- let t19;
173
- if ($[34] !== children || $[35] !== className || $[36] !== id || $[37] !== onClosed || $[38] !== opened || $[39] !== t17 || $[40] !== t18) {
174
- t19 = /*#__PURE__*/jsxs(Dialog, {
206
+ let t25;
207
+ if ($[38] !== cancelButtonLabel || $[39] !== children || $[40] !== className || $[41] !== id || $[42] !== onClosed || $[43] !== opened || $[44] !== size || $[45] !== submitButtonLabel || $[46] !== t21 || $[47] !== t22 || $[48] !== t24 || $[49] !== withCancelButton) {
208
+ t25 = /*#__PURE__*/jsxs(Dialog, {
175
209
  id: id,
176
- title: t17,
177
- size: "lg",
210
+ title: t21,
211
+ size: size,
178
212
  visible: opened,
213
+ withCancelButton: withCancelButton,
214
+ withSubmitButton: t22,
179
215
  requestClose: requestClose,
180
216
  onClosed: onClosed,
217
+ onClickSubmit: onClickSubmit,
181
218
  className: className,
182
- children: [children, t18]
219
+ submitButtonLabel: submitButtonLabel,
220
+ cancelButtonLabel: cancelButtonLabel,
221
+ children: [children, t24]
183
222
  });
184
- $[34] = children;
185
- $[35] = className;
186
- $[36] = id;
187
- $[37] = onClosed;
188
- $[38] = opened;
189
- $[39] = t17;
190
- $[40] = t18;
191
- $[41] = t19;
223
+ $[38] = cancelButtonLabel;
224
+ $[39] = children;
225
+ $[40] = className;
226
+ $[41] = id;
227
+ $[42] = onClosed;
228
+ $[43] = opened;
229
+ $[44] = size;
230
+ $[45] = submitButtonLabel;
231
+ $[46] = t21;
232
+ $[47] = t22;
233
+ $[48] = t24;
234
+ $[49] = withCancelButton;
235
+ $[50] = t25;
192
236
  } else {
193
- t19 = $[41];
237
+ t25 = $[50];
194
238
  }
195
- return t19;
239
+ return t25;
196
240
  }
197
241
 
198
- export { ModalForm as default };
242
+ 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.50",
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": "c5d4004686dae5529035f8eac83571739e24340d"
68
68
  }