muffin-admin 11.2.10 → 11.3.0

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/buildRA.js CHANGED
@@ -2,7 +2,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { ArrayField, ArrayInput, AutocompleteArrayInput, AutocompleteInput, BooleanField, BooleanInput, CheckboxGroupInput, ChipField, DateField, DateInput, DateTimeInput, EmailField, FileField, FileInput, ImageField, ImageInput, NullableBooleanInput, NumberField, NumberInput, PasswordInput, RadioButtonGroupInput, ReferenceArrayField, ReferenceArrayInput, ReferenceField, ReferenceInput, ReferenceManyField, required, RichTextField, SearchInput, SelectArrayInput, SelectField, SelectInput, TextField, TextInput, UrlField, } from "react-admin";
3
3
  import { AvatarField, CopyField, EditableBooleanField, FKField, JsonField } from "./fields";
4
4
  import { DateRangeFilter, Filter, SearchFilter } from "./filters";
5
- import { FKInput, JsonInput, TimestampInput } from "./inputs";
5
+ import { FKInput, ImgInput, JsonInput, TimestampInput } from "./inputs";
6
6
  const UI = {
7
7
  // Fields
8
8
  BooleanField,
@@ -36,6 +36,7 @@ const UI = {
36
36
  FKInput,
37
37
  FileInput,
38
38
  ImageInput,
39
+ ImgInput,
39
40
  JsonInput,
40
41
  NullableBooleanInput,
41
42
  NumberInput,
@@ -43,11 +44,11 @@ const UI = {
43
44
  RadioButtonGroupInput,
44
45
  ReferenceArrayInput,
45
46
  ReferenceInput,
47
+ SearchInput,
46
48
  SelectArrayInput,
47
49
  SelectInput,
48
50
  TextInput,
49
51
  TimestampInput,
50
- SearchInput,
51
52
  // Filters
52
53
  Filter,
53
54
  DateRangeFilter,
@@ -74,16 +74,10 @@ export function MuffinDataprovider(apiUrl) {
74
74
  return response;
75
75
  }),
76
76
  create: (resource_1, _a) => __awaiter(this, [resource_1, _a], void 0, function* (resource, { data }) {
77
- return yield request(resource, {
78
- data,
79
- method: "POST",
80
- });
77
+ return yield request(resource, Object.assign({ method: "POST" }, prepareDataParams(data)));
81
78
  }),
82
79
  update: (resource_1, _a) => __awaiter(this, [resource_1, _a], void 0, function* (resource, { id, data }) {
83
- return yield makeRequest(`${apiUrl}/${resource}/${id}`, {
84
- data,
85
- method: "PUT",
86
- }).then(({ json }) => ({ data: json }));
80
+ return yield makeRequest(`${apiUrl}/${resource}/${id}`, Object.assign({ method: "PUT" }, prepareDataParams(data))).then(({ json }) => ({ data: json }));
87
81
  }),
88
82
  updateMany: (resource_1, _a) => __awaiter(this, [resource_1, _a], void 0, function* (resource, { ids, data }) {
89
83
  yield Promise.all(ids.map((id) => methods.update(resource, { id, data })));
@@ -128,3 +122,25 @@ export function MuffinDataprovider(apiUrl) {
128
122
  return methods;
129
123
  }
130
124
  setupAdmin(["data-provider"], MuffinDataprovider);
125
+ function isFileValue(value) {
126
+ return value && typeof value === "object" && value.rawFile instanceof File;
127
+ }
128
+ function prepareDataParams(data) {
129
+ const hasFiles = Object.values(data).some(isFileValue);
130
+ if (!hasFiles)
131
+ return { data };
132
+ const formData = new FormData();
133
+ for (const key in data) {
134
+ const value = data[key];
135
+ if (isFileValue(value)) {
136
+ formData.append(key, value.rawFile);
137
+ }
138
+ else if (typeof value === "object" && value !== null) {
139
+ formData.append(key, JSON.stringify(value));
140
+ }
141
+ else if (value !== undefined && value !== null) {
142
+ formData.append(key, value);
143
+ }
144
+ }
145
+ return { body: formData };
146
+ }
@@ -9,11 +9,17 @@ var __rest = (this && this.__rest) || function (s, e) {
9
9
  }
10
10
  return t;
11
11
  };
12
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
13
- import { ReferenceField, TextField } from "react-admin";
12
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
13
+ import { ReferenceField, TextField, useFieldValue } from "react-admin";
14
14
  export function FKField(_a) {
15
15
  var { reference, refSource, refKey, link, source } = _a, props = __rest(_a, ["reference", "refSource", "refKey", "link", "source"]);
16
16
  refKey = refKey || "id";
17
- return (_jsx(ReferenceField, Object.assign({ source: source, link: link || "show", reference: reference, queryOptions: { meta: { key: refKey } } }, props, { children: _jsxs(_Fragment, { children: [_jsx(TextField, { source: refSource }), refSource !== refKey && (_jsxs(_Fragment, { children: [" (#", _jsx(TextField, { source: refKey }), ")"] }))] }) })));
17
+ return (_jsxs(ReferenceField, Object.assign({ source: source, link: link || "show", reference: reference, queryOptions: { meta: { key: refKey } } }, props, { children: [_jsx(TextField, { source: refSource }), refSource !== refKey && _jsx(FKFieldValue, { source: refKey })] })));
18
+ }
19
+ function FKFieldValue(props) {
20
+ const value = useFieldValue(props);
21
+ if (value === undefined)
22
+ return null;
23
+ return (_jsxs(_Fragment, { children: [" (#", _jsx(TextField, Object.assign({}, props)), ")"] }));
18
24
  }
19
25
  FKField.displayName = "FKField";
package/dist/index.d.ts CHANGED
@@ -19,4 +19,4 @@ export * from "./fields";
19
19
  export * from "./hooks";
20
20
  export * from "./types";
21
21
  export declare function initAdmin(prefix?: string, containerId?: string): Promise<void>;
22
- export declare const VERSION = "11.2.10";
22
+ export declare const VERSION = "11.3.0";
package/dist/index.js CHANGED
@@ -42,4 +42,4 @@ export function initAdmin() {
42
42
  root.render(_jsx(MuffinAdminContext.Provider, { value: adminOpts, children: _jsx(MuffinAdmin, {}) }));
43
43
  });
44
44
  }
45
- export const VERSION = "11.2.10";
45
+ export const VERSION = "11.3.0";
@@ -0,0 +1,5 @@
1
+ export declare function ImgInput({ source, label, ...props }: {
2
+ [x: string]: any;
3
+ source: any;
4
+ label: any;
5
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,25 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { startCase } from "lodash";
14
+ import { ImageField, ImageInput, RecordContext, useInput, useRecordContext } from "react-admin";
15
+ export function ImgInput(_a) {
16
+ var { source, label } = _a, props = __rest(_a, ["source", "label"]);
17
+ const { field } = useInput({ source });
18
+ label = label || field.name;
19
+ return (_jsx(ImageInput, Object.assign({ source: source, label: startCase(label || field.name) }, props, { children: _jsx(PreviewImage, {}) })));
20
+ }
21
+ function PreviewImage() {
22
+ const value = useRecordContext();
23
+ const source = (value === null || value === void 0 ? void 0 : value.src) || value;
24
+ return (_jsx(RecordContext.Provider, { value: { source }, children: _jsx(ImageField, { source: "source", title: "source" }) }));
25
+ }
@@ -1,3 +1,4 @@
1
1
  export * from "./FKInput";
2
+ export * from "./ImgInput";
2
3
  export * from "./JsonInput";
3
4
  export * from "./TimestampInput";
@@ -1,3 +1,4 @@
1
1
  export * from "./FKInput";
2
+ export * from "./ImgInput";
2
3
  export * from "./JsonInput";
3
4
  export * from "./TimestampInput";