@panneau/field-resource-item 4.0.39 → 4.0.40-alpha.3

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.
Files changed (3) hide show
  1. package/dist/index.d.ts +3 -7
  2. package/dist/index.js +142 -251
  3. package/package.json +12 -12
package/dist/index.d.ts CHANGED
@@ -1,11 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { FormError, Message } from '@panneau/core';
2
+ import { Item, FormError, Message } from '@panneau/core';
3
3
 
4
- interface Item {
5
- id?: string | number | null;
6
- type?: string;
7
- [key: string]: unknown;
8
- }
9
4
  interface ResourceItemFieldProps {
10
5
  name?: string | null;
11
6
  value?: Item | null;
@@ -31,6 +26,7 @@ interface ResourceItemFieldProps {
31
26
  canEdit?: boolean;
32
27
  canFind?: boolean;
33
28
  withoutModal?: boolean;
29
+ withoutSelect?: boolean;
34
30
  createButtonLabel?: Message | null;
35
31
  editButtonLabel?: Message | null;
36
32
  findButtonLabel?: Message | null;
@@ -40,7 +36,7 @@ interface ResourceItemFieldProps {
40
36
  inputClassName?: string | null;
41
37
  onChange?: ((value: Item | Item[] | null) => void) | null;
42
38
  }
43
- declare function ResourceItemField({ name, value, errors, resource: resourceId, resourceType, paginated, query: initialQuery, requestQuery: initialRequestQuery, page: initialPage, count: initialCount, options: initialOptions, searchParamName, getItemLabel: initialGetItemLabel, getItemDescription, getItemImage, itemLabelPath, itemDescriptionPath, itemImagePath, itemLabelWithId, placeholder, canCreate, canEdit, canFind, withoutModal, createButtonLabel, editButtonLabel, findButtonLabel, multiple, disabled, className, inputClassName, onChange, }: ResourceItemFieldProps): react_jsx_runtime.JSX.Element;
39
+ declare function ResourceItemField({ name, value, errors, resource: resourceId, resourceType, paginated, query: initialQuery, requestQuery: initialRequestQuery, page: initialPage, count: initialCount, options: initialOptions, searchParamName, getItemLabel: initialGetItemLabel, getItemDescription, getItemImage, itemLabelPath, itemDescriptionPath, itemImagePath, itemLabelWithId, placeholder, canCreate, canEdit, canFind, withoutModal, withoutSelect, createButtonLabel, editButtonLabel, findButtonLabel, multiple, disabled, className, inputClassName, onChange, }: ResourceItemFieldProps): react_jsx_runtime.JSX.Element;
44
40
 
45
41
  declare namespace _default {
46
42
  let id: string;
package/dist/index.js CHANGED
@@ -1,7 +1,3 @@
1
- import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
2
- import _defineProperty from '@babel/runtime/helpers/defineProperty';
3
- import _objectSpread from '@babel/runtime/helpers/objectSpread2';
4
- import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
5
1
  import classNames from 'classnames';
6
2
  import isArray from 'lodash/isArray';
7
3
  import isEmpty from 'lodash/isEmpty';
@@ -14,166 +10,98 @@ import { useResourceItems } from '@panneau/data';
14
10
  import Button from '@panneau/element-button';
15
11
  import ResourceCard from '@panneau/element-resource-card';
16
12
  import Select from '@panneau/element-select';
17
- import ResourceForm from '@panneau/form-resource';
18
13
  import { useResourceValues } from '@panneau/intl';
19
- import Dialog from '@panneau/modal-dialog';
14
+ import ModalResourceForm from '@panneau/modal-resource-form';
20
15
  import ModalResourceItems from '@panneau/modal-resource-items';
21
16
  import { jsxs, jsx } from 'react/jsx-runtime';
22
17
 
23
- function ResourceItemField(_ref) {
24
- var _ref$name = _ref.name,
25
- name = _ref$name === void 0 ? null : _ref$name,
26
- _ref$value = _ref.value,
27
- value = _ref$value === void 0 ? null : _ref$value,
28
- _ref$errors = _ref.errors,
29
- errors = _ref$errors === void 0 ? null : _ref$errors,
30
- _ref$resource = _ref.resource,
31
- resourceId = _ref$resource === void 0 ? null : _ref$resource,
32
- _ref$resourceType = _ref.resourceType,
33
- resourceType = _ref$resourceType === void 0 ? null : _ref$resourceType,
34
- _ref$paginated = _ref.paginated,
35
- paginated = _ref$paginated === void 0 ? true : _ref$paginated,
36
- _ref$query = _ref.query,
37
- initialQuery = _ref$query === void 0 ? null : _ref$query,
38
- _ref$requestQuery = _ref.requestQuery,
39
- initialRequestQuery = _ref$requestQuery === void 0 ? null : _ref$requestQuery,
40
- _ref$page = _ref.page,
41
- initialPage = _ref$page === void 0 ? null : _ref$page,
42
- _ref$count = _ref.count,
43
- initialCount = _ref$count === void 0 ? null : _ref$count,
44
- _ref$options = _ref.options,
45
- initialOptions = _ref$options === void 0 ? null : _ref$options,
46
- _ref$searchParamName = _ref.searchParamName,
47
- searchParamName = _ref$searchParamName === void 0 ? 'search' : _ref$searchParamName,
48
- _ref$getItemLabel = _ref.getItemLabel,
49
- initialGetItemLabel = _ref$getItemLabel === void 0 ? getPathValue : _ref$getItemLabel,
50
- _ref$getItemDescripti = _ref.getItemDescription,
51
- getItemDescription = _ref$getItemDescripti === void 0 ? getPathValue : _ref$getItemDescripti,
52
- _ref$getItemImage = _ref.getItemImage,
53
- getItemImage = _ref$getItemImage === void 0 ? getPathValue : _ref$getItemImage,
54
- _ref$itemLabelPath = _ref.itemLabelPath,
55
- itemLabelPath = _ref$itemLabelPath === void 0 ? 'label' : _ref$itemLabelPath,
56
- _ref$itemDescriptionP = _ref.itemDescriptionPath,
57
- itemDescriptionPath = _ref$itemDescriptionP === void 0 ? null : _ref$itemDescriptionP,
58
- _ref$itemImagePath = _ref.itemImagePath,
59
- itemImagePath = _ref$itemImagePath === void 0 ? 'image.thumbnail_url' : _ref$itemImagePath,
60
- _ref$itemLabelWithId = _ref.itemLabelWithId,
61
- itemLabelWithId = _ref$itemLabelWithId === void 0 ? false : _ref$itemLabelWithId,
62
- _ref$placeholder = _ref.placeholder,
63
- placeholder = _ref$placeholder === void 0 ? null : _ref$placeholder,
64
- _ref$canCreate = _ref.canCreate,
65
- canCreate = _ref$canCreate === void 0 ? false : _ref$canCreate,
66
- _ref$canEdit = _ref.canEdit,
67
- canEdit = _ref$canEdit === void 0 ? false : _ref$canEdit,
68
- _ref$canFind = _ref.canFind,
69
- canFind = _ref$canFind === void 0 ? false : _ref$canFind,
70
- _ref$withoutModal = _ref.withoutModal,
71
- withoutModal = _ref$withoutModal === void 0 ? false : _ref$withoutModal,
72
- _ref$createButtonLabe = _ref.createButtonLabel,
73
- createButtonLabel = _ref$createButtonLabe === void 0 ? null : _ref$createButtonLabe,
74
- _ref$editButtonLabel = _ref.editButtonLabel,
75
- editButtonLabel = _ref$editButtonLabel === void 0 ? null : _ref$editButtonLabel,
76
- _ref$findButtonLabel = _ref.findButtonLabel,
77
- findButtonLabel = _ref$findButtonLabel === void 0 ? null : _ref$findButtonLabel,
78
- _ref$multiple = _ref.multiple,
79
- multiple = _ref$multiple === void 0 ? false : _ref$multiple,
80
- _ref$disabled = _ref.disabled,
81
- disabled = _ref$disabled === void 0 ? false : _ref$disabled,
82
- _ref$className = _ref.className,
83
- className = _ref$className === void 0 ? null : _ref$className,
84
- _ref$inputClassName = _ref.inputClassName,
85
- inputClassName = _ref$inputClassName === void 0 ? null : _ref$inputClassName,
86
- _ref$onChange = _ref.onChange,
87
- onChange = _ref$onChange === void 0 ? null : _ref$onChange;
88
- var intl = useIntl();
89
- var resource = usePanneauResource(resourceId);
90
- var resourceValues = useResourceValues(resource);
91
- var defaultPage = useMemo(function () {
92
- return initialPage || (paginated ? 1 : null);
93
- }, [initialPage, paginated]);
94
- var defaultCount = useMemo(function () {
95
- return initialCount || (paginated ? 8 : null);
96
- }, [initialCount, paginated]);
97
- var hasValue = value !== null && !isEmpty(value);
18
+ function ResourceItemField({
19
+ name = null,
20
+ value = null,
21
+ errors = null,
22
+ resource: resourceId = null,
23
+ resourceType = null,
24
+ paginated = true,
25
+ query: initialQuery = null,
26
+ requestQuery: initialRequestQuery = null,
27
+ page: initialPage = null,
28
+ count: initialCount = null,
29
+ options: initialOptions = null,
30
+ searchParamName = 'search',
31
+ getItemLabel: initialGetItemLabel = getPathValue,
32
+ getItemDescription = getPathValue,
33
+ getItemImage = getPathValue,
34
+ itemLabelPath = 'label',
35
+ itemDescriptionPath = null,
36
+ itemImagePath = 'image.thumbnail_url',
37
+ itemLabelWithId = false,
38
+ placeholder = null,
39
+ canCreate = false,
40
+ canEdit = false,
41
+ canFind = false,
42
+ withoutModal = false,
43
+ withoutSelect = false,
44
+ createButtonLabel = null,
45
+ editButtonLabel = null,
46
+ findButtonLabel = null,
47
+ multiple = false,
48
+ disabled = false,
49
+ className = null,
50
+ inputClassName = null,
51
+ onChange = null
52
+ }) {
53
+ const intl = useIntl();
54
+ const resource = usePanneauResource(resourceId);
55
+ useResourceValues(resource);
56
+ const defaultPage = useMemo(() => initialPage || (paginated ? 1 : null), [initialPage, paginated]);
57
+ const defaultCount = useMemo(() => initialCount || (paginated ? 8 : null), [initialCount, paginated]);
58
+ const hasValue = value !== null && !isEmpty(value);
98
59
 
99
60
  // const [initialValue] = useState(value);
100
61
 
101
- var _useState = useState(false),
102
- _useState2 = _slicedToArray(_useState, 2),
103
- formOpen = _useState2[0],
104
- setFormOpen = _useState2[1];
105
- var _useState3 = useState(false),
106
- _useState4 = _slicedToArray(_useState3, 2),
107
- listOpen = _useState4[0],
108
- setListOpen = _useState4[1];
62
+ const [formOpen, setFormOpen] = useState(false);
63
+ const [listOpen, setListOpen] = useState(false);
109
64
 
110
65
  // TODO: list state controls?
111
- var _useState5 = useState(initialQuery || initialRequestQuery || {}),
112
- _useState6 = _slicedToArray(_useState5, 2),
113
- query = _useState6[0];
114
- _useState6[1];
115
- var _useState7 = useState(defaultPage),
116
- _useState8 = _slicedToArray(_useState7, 2),
117
- page = _useState8[0],
118
- setPage = _useState8[1];
119
- var _useState9 = useState(defaultCount),
120
- _useState0 = _slicedToArray(_useState9, 2),
121
- count = _useState0[0];
122
- _useState0[1];
123
- var _useState1 = useState(initialOptions),
124
- _useState10 = _slicedToArray(_useState1, 2),
125
- resourceOptions = _useState10[0];
126
- _useState10[1];
66
+ const [query, setQuery] = useState(initialQuery || initialRequestQuery || {});
67
+ const [page, setPage] = useState(defaultPage);
68
+ const [count, setCount] = useState(defaultCount);
69
+ const [resourceOptions, setOptions] = useState(initialOptions);
127
70
 
128
71
  // The text input search query
129
- var _useState11 = useState(''),
130
- _useState12 = _slicedToArray(_useState11, 2),
131
- inputTextValue = _useState12[0],
132
- setInputTextValue = _useState12[1];
133
- var _useState13 = useState(''),
134
- _useState14 = _slicedToArray(_useState13, 2),
135
- queryTextValue = _useState14[0],
136
- setQueryTextValue = _useState14[1];
137
- var onInputChange = useCallback(function (textValue) {
72
+ const [inputTextValue, setInputTextValue] = useState('');
73
+ const [queryTextValue, setQueryTextValue] = useState('');
74
+ const onInputChange = useCallback(textValue => {
138
75
  setInputTextValue(textValue);
139
76
  setPage(defaultPage);
140
77
  }, [setInputTextValue, setPage, defaultPage]);
141
- useEffect(function () {
142
- var id = setTimeout(function () {
78
+ useEffect(() => {
79
+ const id = setTimeout(() => {
143
80
  setQueryTextValue(inputTextValue);
144
81
  }, 500);
145
- return function () {
82
+ return () => {
146
83
  clearTimeout(id);
147
84
  };
148
85
  }, [inputTextValue, setQueryTextValue]);
149
- var queryResource = useMemo(function () {
150
- return {
151
- id: resourceId
152
- };
153
- }, [resourceId]);
154
- var finalQuery = useMemo(function () {
155
- return _objectSpread(_objectSpread(_objectSpread({}, query), !isEmpty(queryTextValue) ? _defineProperty({}, searchParamName, queryTextValue) : null), {}, {
156
- paginated: paginated
157
- });
158
- }, [queryTextValue, paginated, query, searchParamName]);
159
- var _useResourceItems = useResourceItems(queryResource, finalQuery, paginated ? page : null, paginated ? count : null, resourceOptions),
160
- _useResourceItems$all = _useResourceItems.allItems,
161
- partialItems = _useResourceItems$all === void 0 ? null : _useResourceItems$all,
162
- _useResourceItems$rel = _useResourceItems.reload,
163
- reload = _useResourceItems$rel === void 0 ? null : _useResourceItems$rel,
164
- _useResourceItems$pag = _useResourceItems.pagination,
165
- pagination = _useResourceItems$pag === void 0 ? null : _useResourceItems$pag;
166
- var _ref3 = pagination || {},
167
- _ref3$lastPage = _ref3.lastPage,
168
- lastPage = _ref3$lastPage === void 0 ? null : _ref3$lastPage;
169
- var items = uniqBy((partialItems || []).concat(multiple && isArray(value) ? value : [value]).filter(function (it) {
170
- return it !== null;
171
- }), function (_ref4) {
172
- var _ref4$id = _ref4.id,
173
- id = _ref4$id === void 0 ? null : _ref4$id;
174
- return id;
175
- });
176
- var onScrollEnd = useCallback(function () {
86
+ const finalQuery = useMemo(() => ({
87
+ ...query,
88
+ ...(!isEmpty(queryTextValue) ? {
89
+ [searchParamName]: queryTextValue
90
+ } : null),
91
+ paginated
92
+ }), [queryTextValue, paginated, query, searchParamName]);
93
+ const {
94
+ allItems: partialItems = null,
95
+ reload = null,
96
+ pagination = null
97
+ } = useResourceItems(resource, finalQuery, paginated ? page : null, paginated ? count : null, resourceOptions);
98
+ const {
99
+ lastPage = null
100
+ } = pagination || {};
101
+ const items = uniqBy((partialItems || []).concat(multiple && isArray(value) ? value : [value]).filter(it => it !== null), ({
102
+ id: id_0 = null
103
+ }) => id_0);
104
+ const onScrollEnd = useCallback(() => {
177
105
  if (page !== null && typeof page === 'number' && typeof lastPage === 'number' && page >= lastPage) {
178
106
  return;
179
107
  }
@@ -181,87 +109,80 @@ function ResourceItemField(_ref) {
181
109
  setPage(page + 1);
182
110
  }
183
111
  }, [paginated, page, setPage, lastPage]);
184
- var getItemLabel = useCallback(function (it, path) {
185
- var _ref5 = it || {},
186
- _ref5$id = _ref5.id,
187
- id = _ref5$id === void 0 ? null : _ref5$id;
112
+ const getItemLabel = useCallback((it_0, path) => {
113
+ const {
114
+ id: id_1 = null
115
+ } = it_0 || {};
188
116
  if (itemLabelWithId) {
189
- var label = initialGetItemLabel(it, path);
190
- return label ? "".concat(label, " (#").concat(id, ")") : "#".concat(id);
117
+ const label = initialGetItemLabel(it_0, path);
118
+ return label ? `${label} (#${id_1})` : `#${id_1}`;
191
119
  }
192
- return path !== null ? initialGetItemLabel(it, path) : "#".concat(id);
120
+ return path !== null ? initialGetItemLabel(it_0, path) : `#${id_1}`;
193
121
  }, [initialGetItemLabel, itemLabelWithId]);
194
- var parseItem = useCallback(function (it) {
195
- var label = getItemLabel(it, itemLabelPath);
196
- var description = getItemDescription(it, itemDescriptionPath);
197
- var finalLabel = description !== null ? "".concat(label, ": ").concat(description) : label;
122
+ const parseItem = useCallback(it_1 => {
123
+ const label_0 = getItemLabel(it_1, itemLabelPath);
124
+ const description = getItemDescription(it_1, itemDescriptionPath);
125
+ const finalLabel = description !== null ? `${label_0}: ${description}` : label_0;
198
126
  return {
199
- value: it.id,
127
+ value: it_1.id,
200
128
  label: finalLabel
201
129
  };
202
130
  }, [getItemLabel, getItemDescription, itemLabelPath, itemDescriptionPath]);
203
- var finalValue = multiple && isArray(value) ? value.map(function (_ref6) {
204
- var _ref6$id = _ref6.id,
205
- id = _ref6$id === void 0 ? null : _ref6$id;
206
- return id;
207
- }) : (value === null || value === void 0 ? void 0 : value.id) || null;
208
- var _ref7 = !multiple && hasValue ? value : {
209
- type: resourceType
210
- },
211
- _ref7$type = _ref7.type,
212
- finalType = _ref7$type === void 0 ? null : _ref7$type;
213
- var options = (items || []).map(function (it) {
214
- return parseItem(it);
215
- });
216
- var onValueChange = useCallback(function (newId) {
131
+ const finalValue = multiple && isArray(value) ? value.map(({
132
+ id: id_2 = null
133
+ }) => id_2) : value?.id || null;
134
+ const {
135
+ type: finalType = null
136
+ } = !multiple && hasValue ? value : {
137
+ type: resourceType
138
+ };
139
+ const options = (items || []).map(it_2 => parseItem(it_2));
140
+ const onValueChange = useCallback(newId => {
217
141
  if (onChange === null) return;
218
142
  if (multiple && isArray(newId)) {
219
- var newValue = items.filter(function (_ref8) {
220
- var _ref8$id = _ref8.id,
221
- id = _ref8$id === void 0 ? null : _ref8$id;
222
- return newId.indexOf(id) !== -1;
223
- }) || [];
143
+ const newValue = items.filter(({
144
+ id: id_3 = null
145
+ }) => newId.indexOf(id_3) !== -1) || [];
224
146
  onChange(newValue);
225
147
  } else if (!isArray(newId)) {
226
- var _newValue = items.filter(function (_ref9) {
227
- var _ref9$id = _ref9.id,
228
- id = _ref9$id === void 0 ? null : _ref9$id;
229
- return id === newId;
230
- }) || [];
231
- if (_newValue !== null && _newValue.length > 0) {
232
- onChange(_newValue[0]);
148
+ const newValue_0 = items.filter(({
149
+ id: id_4 = null
150
+ }) => id_4 === newId) || [];
151
+ if (newValue_0 !== null && newValue_0.length > 0) {
152
+ onChange(newValue_0[0]);
233
153
  } else {
234
154
  onChange(null);
235
155
  }
236
156
  }
237
157
  }, [items, onChange, multiple]);
238
- var onOpenForm = useCallback(function () {
158
+ const onOpenForm = useCallback(() => {
239
159
  setFormOpen(true);
240
160
  }, [setFormOpen]);
241
- var onCloseForm = useCallback(function () {
161
+ const onClosedForm = useCallback(() => {
242
162
  setFormOpen(false);
243
163
  }, [setFormOpen]);
244
- var onFormSuccess = useCallback(function (newValue) {
164
+ const onFormSuccess = useCallback(newValue_1 => {
245
165
  if (onChange === null) return;
246
- var finalNewValue = resourceType !== null ? _objectSpread({
247
- type: resourceType
248
- }, newValue) : newValue;
166
+ const finalNewValue = resourceType !== null ? {
167
+ type: resourceType,
168
+ ...newValue_1
169
+ } : newValue_1;
249
170
  if (multiple) {
250
- onChange(isArray(value) ? [].concat(_toConsumableArray(value), [finalNewValue]) : [finalNewValue]);
171
+ onChange(isArray(value) ? [...value, finalNewValue] : [finalNewValue]);
251
172
  } else {
252
173
  onChange(finalNewValue);
253
174
  }
254
175
  setFormOpen(false);
255
176
  }, [onChange, multiple, value, setFormOpen, resourceType]);
256
- var onOpenList = useCallback(function () {
257
- setListOpen(false); // TODO: fix this, see Upload Field
177
+ const onOpenList = useCallback(() => {
178
+ setListOpen(true); // TODO: fix this, see Upload Field
258
179
  }, [setListOpen]);
259
- var onCloseList = useCallback(function () {
180
+ const onClosedList = useCallback(() => {
260
181
  setListOpen(false);
261
182
  }, [setListOpen]);
262
- var onSelectListItem = useCallback(function (newValue) {
183
+ const onSelectListItem = useCallback(newValue_2 => {
263
184
  if (onChange !== null) {
264
- onChange(newValue);
185
+ onChange(isArray(newValue_2) && !multiple ? newValue_2?.[0] || null : newValue_2);
265
186
  setListOpen(false);
266
187
  }
267
188
  }, [onChange, setListOpen]);
@@ -273,7 +194,7 @@ function ResourceItemField(_ref) {
273
194
  // }
274
195
  // }, [paginated, reloadall]);
275
196
 
276
- var onClickRemove = useCallback(function () {
197
+ const onClickRemove = useCallback(() => {
277
198
  if (onChange !== null) {
278
199
  onChange(null);
279
200
  }
@@ -286,15 +207,10 @@ function ResourceItemField(_ref) {
286
207
  if (reload) reload();
287
208
  }
288
209
  }, [onChange, paginated, defaultPage, reload]);
289
- var form = formOpen ? /*#__PURE__*/jsx(ResourceForm, {
290
- resource: resource,
291
- type: finalType,
292
- item: !multiple ? value : null,
293
- onSuccess: onFormSuccess,
294
- isModal: true
295
- }) : null;
296
210
  return /*#__PURE__*/jsxs("div", {
297
- className: classNames(['position-relative', _defineProperty({}, className, className != null)]),
211
+ className: classNames(['position-relative', {
212
+ [className]: className != null
213
+ }]),
298
214
  children: [hasValue && !multiple ? /*#__PURE__*/jsx("div", {
299
215
  className: "row",
300
216
  children: /*#__PURE__*/jsx("div", {
@@ -310,17 +226,21 @@ function ResourceItemField(_ref) {
310
226
  itemImagePath: itemImagePath,
311
227
  itemLabelWithId: itemLabelWithId,
312
228
  disable: disabled,
313
- onClickEdit: canEdit && !multiple ? formOpen ? onCloseForm : onOpenForm : null,
229
+ onClickEdit: canEdit && !multiple ? onOpenForm : null,
314
230
  onClickRemove: onClickRemove,
315
231
  editButtonLabel: editButtonLabel
316
232
  })
317
233
  })
318
234
  }) : /*#__PURE__*/jsxs("div", {
319
- className: "row align-items-center",
320
- children: [/*#__PURE__*/jsx("div", {
235
+ className: "row align-items-center gx-1",
236
+ children: [!withoutSelect ? /*#__PURE__*/jsx("div", {
321
237
  className: "col-8 flex-grow-1",
322
238
  children: /*#__PURE__*/jsx(Select, {
323
- className: classNames(['py-1', 'shadow-none', _defineProperty(_defineProperty(_defineProperty({}, disabled, disabled), 'is-invalid', errors !== null), inputClassName, inputClassName !== null)]),
239
+ className: classNames(['py-1', 'shadow-none', {
240
+ disabled: disabled,
241
+ 'is-invalid': errors !== null,
242
+ [inputClassName]: inputClassName !== null
243
+ }]),
324
244
  disabled: disabled,
325
245
  name: name,
326
246
  value: finalValue,
@@ -328,11 +248,7 @@ function ResourceItemField(_ref) {
328
248
  isClearable: true,
329
249
  isSearchable: true,
330
250
  placeholder: isMessage(placeholder) ? intl.formatMessage(placeholder) : /*#__PURE__*/jsx(FormattedMessage, {
331
- id: "oc3YLT",
332
- defaultMessage: [{
333
- "type": 0,
334
- "value": "Choose an item"
335
- }]
251
+ id: "oc3YLT"
336
252
  }),
337
253
  onChange: onValueChange,
338
254
  onInputChange: onInputChange
@@ -341,21 +257,21 @@ function ResourceItemField(_ref) {
341
257
  onMenuScrollToBottom: onScrollEnd,
342
258
  multiple: multiple
343
259
  })
344
- }), canFind ? /*#__PURE__*/jsx("div", {
260
+ }) : null, canFind ? /*#__PURE__*/jsx("div", {
345
261
  className: "col-auto",
346
262
  children: /*#__PURE__*/jsx(Button, {
347
- theme: "primary",
263
+ theme: "secondary",
348
264
  icon: findButtonLabel === null ? 'search' : null,
349
- onClick: listOpen ? onCloseList : onOpenList,
265
+ onClick: onOpenList,
350
266
  outline: true,
351
267
  children: findButtonLabel
352
268
  })
353
269
  }) : null, canCreate ? /*#__PURE__*/jsx("div", {
354
270
  className: "col-auto",
355
271
  children: /*#__PURE__*/jsx(Button, {
356
- theme: "primary",
272
+ theme: "secondary",
357
273
  icon: createButtonLabel === null ? 'plus-lg' : null,
358
- onClick: formOpen ? onCloseForm : onOpenForm,
274
+ onClick: onOpenForm,
359
275
  outline: true,
360
276
  children: createButtonLabel
361
277
  })
@@ -363,41 +279,16 @@ function ResourceItemField(_ref) {
363
279
  }), formOpen ? withoutModal ? /*#__PURE__*/jsx("div", {
364
280
  className: "card mt-4 p-4",
365
281
  children: form
366
- }) : /*#__PURE__*/jsx(Dialog, {
367
- id: resourceId,
368
- title: hasValue && !multiple ? /*#__PURE__*/jsx(FormattedMessage, {
369
- values: resourceValues,
370
- id: "mCfzkJ",
371
- defaultMessage: [{
372
- "type": 0,
373
- "value": "Edit "
374
- }, {
375
- "type": 1,
376
- "value": "a_singular"
377
- }]
378
- }) : /*#__PURE__*/jsx(FormattedMessage, {
379
- values: resourceValues,
380
- id: "6viUpq",
381
- defaultMessage: [{
382
- "type": 0,
383
- "value": "Create "
384
- }, {
385
- "type": 1,
386
- "value": "a_singular"
387
- }]
388
- }),
389
- size: "lg",
390
- onClose: onCloseForm,
391
- children: form
282
+ }) : /*#__PURE__*/jsx(ModalResourceForm, {
283
+ resource: resource,
284
+ item: !multiple ? value : null,
285
+ isCreate: true,
286
+ onClosed: onClosedForm,
287
+ onComplete: onFormSuccess
392
288
  }) : null, listOpen ? /*#__PURE__*/jsx(ModalResourceItems, {
393
289
  resource: resourceId,
394
- onClose: onCloseList,
395
- listProps: {
396
- actions: ['select'],
397
- actionsProps: {
398
- onClickSelect: onSelectListItem
399
- }
400
- }
290
+ onClosed: onClosedList,
291
+ onSelect: onSelectListItem
401
292
  }) : null]
402
293
  });
403
294
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@panneau/field-resource-item",
3
- "version": "4.0.39",
3
+ "version": "4.0.40-alpha.3",
4
4
  "description": "An item mapping a resource",
5
5
  "keywords": [
6
6
  "javascript"
@@ -52,16 +52,16 @@
52
52
  },
53
53
  "dependencies": {
54
54
  "@babel/runtime": "^7.28.6",
55
- "@panneau/core": "^4.0.38",
56
- "@panneau/data": "^4.0.38",
57
- "@panneau/element-button": "^4.0.39",
58
- "@panneau/element-resource-card": "^4.0.39",
59
- "@panneau/element-select": "^4.0.39",
60
- "@panneau/form-resource": "^4.0.39",
61
- "@panneau/intl": "^4.0.38",
62
- "@panneau/modal-dialog": "^4.0.39",
63
- "@panneau/modal-resource-form": "^4.0.39",
64
- "@panneau/modal-resource-items": "^4.0.39",
55
+ "@panneau/core": "^4.0.40-alpha.3",
56
+ "@panneau/data": "^4.0.40-alpha.3",
57
+ "@panneau/element-button": "^4.0.40-alpha.3",
58
+ "@panneau/element-resource-card": "^4.0.40-alpha.3",
59
+ "@panneau/element-select": "^4.0.40-alpha.3",
60
+ "@panneau/form-resource": "^4.0.40-alpha.3",
61
+ "@panneau/intl": "^4.0.40-alpha.3",
62
+ "@panneau/modal-dialog": "^4.0.40-alpha.3",
63
+ "@panneau/modal-resource-form": "^4.0.40-alpha.3",
64
+ "@panneau/modal-resource-items": "^4.0.40-alpha.3",
65
65
  "classnames": "^2.5.1",
66
66
  "lodash": "^4.17.21",
67
67
  "react-intl": "^6.0.0 || ^7.0.0 || ^8.0.0 || ^10.0.0"
@@ -69,5 +69,5 @@
69
69
  "publishConfig": {
70
70
  "access": "public"
71
71
  },
72
- "gitHead": "621c5233f083c1ba95cd46cd427c38361723d5d6"
72
+ "gitHead": "1735964a2702ae0480b642225286e4184f36680d"
73
73
  }