muffin-admin 1.44.3 → 1.45.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.
Files changed (142) hide show
  1. package/dist/MuffinAdmin.d.ts +2 -0
  2. package/dist/MuffinAdmin.js +25 -0
  3. package/dist/MuffinDashboard.d.ts +2 -0
  4. package/dist/MuffinDashboard.js +16 -0
  5. package/dist/MuffinResource.d.ts +2 -0
  6. package/dist/MuffinResource.js +19 -0
  7. package/dist/MuffinResourceCreate.d.ts +4 -0
  8. package/dist/MuffinResourceCreate.js +11 -0
  9. package/dist/MuffinResourceEdit.d.ts +2 -0
  10. package/dist/MuffinResourceEdit.js +26 -0
  11. package/dist/MuffinResourceList.d.ts +2 -0
  12. package/dist/MuffinResourceList.js +16 -0
  13. package/dist/MuffinResourceShow.d.ts +2 -0
  14. package/dist/MuffinResourceShow.js +13 -0
  15. package/dist/actions/LinkAction.d.ts +4 -0
  16. package/dist/actions/LinkAction.js +10 -0
  17. package/dist/actions/index.d.ts +1 -0
  18. package/dist/actions/index.js +1 -0
  19. package/dist/authprovider.d.ts +9 -0
  20. package/dist/authprovider.js +80 -0
  21. package/dist/buildRA.d.ts +2 -0
  22. package/dist/buildRA.js +63 -0
  23. package/dist/buttons/ActionButton.d.ts +7 -0
  24. package/dist/buttons/ActionButton.js +51 -0
  25. package/dist/buttons/LinkButton.d.ts +6 -0
  26. package/dist/buttons/LinkButton.js +12 -0
  27. package/dist/buttons/index.d.ts +2 -0
  28. package/dist/buttons/index.js +2 -0
  29. package/dist/dataprovider.d.ts +59 -0
  30. package/dist/dataprovider.js +106 -0
  31. package/dist/fields/AvatarField.d.ts +13 -0
  32. package/dist/fields/AvatarField.js +33 -0
  33. package/dist/fields/EditableBooleanField.d.ts +3 -0
  34. package/dist/fields/EditableBooleanField.js +5 -0
  35. package/dist/fields/FKField.d.ts +14 -0
  36. package/dist/fields/FKField.js +21 -0
  37. package/dist/fields/JsonField.d.ts +4 -0
  38. package/dist/fields/JsonField.js +11 -0
  39. package/dist/fields/index.d.ts +4 -0
  40. package/dist/fields/index.js +4 -0
  41. package/dist/hooks/useAction.d.ts +5 -0
  42. package/dist/hooks/useAction.js +6 -0
  43. package/dist/index.d.ts +14 -0
  44. package/dist/index.js +35 -0
  45. package/dist/inputs/FKInput.d.ts +8 -0
  46. package/dist/inputs/FKInput.js +27 -0
  47. package/dist/inputs/JsonInput.d.ts +19 -0
  48. package/dist/inputs/JsonInput.js +69 -0
  49. package/dist/inputs/index.d.ts +2 -0
  50. package/dist/inputs/index.js +2 -0
  51. package/dist/tsconfig.tsbuildinfo +1 -0
  52. package/dist/types.d.ts +76 -0
  53. package/dist/types.js +1 -0
  54. package/dist/utils.d.ts +28 -0
  55. package/dist/utils.js +57 -0
  56. package/dist/web.d.ts +1 -0
  57. package/dist/web.js +3 -0
  58. package/package.json +31 -14
  59. package/src/MuffinAdmin.tsx +73 -0
  60. package/src/MuffinDashboard.tsx +52 -0
  61. package/src/MuffinResource.tsx +27 -0
  62. package/src/MuffinResourceCreate.tsx +24 -0
  63. package/src/MuffinResourceEdit.tsx +42 -0
  64. package/src/MuffinResourceList.tsx +46 -0
  65. package/src/MuffinResourceShow.tsx +39 -0
  66. package/src/actions/LinkAction.tsx +10 -0
  67. package/src/actions/index.ts +1 -0
  68. package/src/{authprovider.js → authprovider.ts} +27 -22
  69. package/src/{ui.jsx → buildRA.tsx} +30 -35
  70. package/src/buttons/{ActionButton.jsx → ActionButton.tsx} +18 -30
  71. package/src/buttons/{LinkButton.jsx → LinkButton.tsx} +11 -6
  72. package/src/buttons/index.ts +2 -0
  73. package/src/{dataprovider.js → dataprovider.ts} +8 -6
  74. package/src/fields/{AvatarField.jsx → AvatarField.tsx} +3 -7
  75. package/src/fields/EditableBooleanField.tsx +5 -0
  76. package/src/fields/{FKField.jsx → FKField.tsx} +2 -10
  77. package/src/fields/{JsonField.jsx → JsonField.tsx} +2 -3
  78. package/src/fields/index.ts +4 -0
  79. package/src/hooks/{useAction.js → useAction.ts} +2 -2
  80. package/src/index.tsx +25 -0
  81. package/src/inputs/FKInput.tsx +27 -0
  82. package/src/inputs/{JsonInput.jsx → JsonInput.tsx} +3 -4
  83. package/src/inputs/index.ts +2 -0
  84. package/src/types.ts +73 -0
  85. package/src/utils.tsx +69 -0
  86. package/src/web.ts +4 -0
  87. package/dist/cjs/admin.js +0 -80
  88. package/dist/cjs/authprovider.js +0 -214
  89. package/dist/cjs/buttons/ActionButton.js +0 -96
  90. package/dist/cjs/buttons/LinkButton.js +0 -34
  91. package/dist/cjs/dashboard.js +0 -63
  92. package/dist/cjs/dataprovider.js +0 -304
  93. package/dist/cjs/fields/AvatarField.js +0 -37
  94. package/dist/cjs/fields/EditableBooleanField.js +0 -25
  95. package/dist/cjs/fields/FKField.js +0 -35
  96. package/dist/cjs/fields/JsonField.js +0 -38
  97. package/dist/cjs/hooks/useAction.js +0 -14
  98. package/dist/cjs/index.js +0 -76
  99. package/dist/cjs/inputs/FKInput.js +0 -41
  100. package/dist/cjs/inputs/JsonInput.js +0 -70
  101. package/dist/cjs/resources.js +0 -52
  102. package/dist/cjs/ui.js +0 -76
  103. package/dist/cjs/utils.js +0 -49
  104. package/dist/cjs/views/create.js +0 -18
  105. package/dist/cjs/views/edit.js +0 -31
  106. package/dist/cjs/views/list.js +0 -67
  107. package/dist/cjs/views/show.js +0 -37
  108. package/dist/cjs/web.js +0 -4
  109. package/dist/esm/admin.js +0 -74
  110. package/dist/esm/authprovider.js +0 -206
  111. package/dist/esm/buttons/ActionButton.js +0 -83
  112. package/dist/esm/buttons/LinkButton.js +0 -23
  113. package/dist/esm/dashboard.js +0 -60
  114. package/dist/esm/dataprovider.js +0 -296
  115. package/dist/esm/fields/AvatarField.js +0 -29
  116. package/dist/esm/fields/EditableBooleanField.js +0 -17
  117. package/dist/esm/fields/FKField.js +0 -27
  118. package/dist/esm/fields/JsonField.js +0 -28
  119. package/dist/esm/hooks/useAction.js +0 -8
  120. package/dist/esm/index.js +0 -42
  121. package/dist/esm/inputs/FKInput.js +0 -33
  122. package/dist/esm/inputs/JsonInput.js +0 -63
  123. package/dist/esm/resources.js +0 -47
  124. package/dist/esm/ui.js +0 -70
  125. package/dist/esm/utils.js +0 -38
  126. package/dist/esm/views/create.js +0 -16
  127. package/dist/esm/views/edit.js +0 -29
  128. package/dist/esm/views/list.js +0 -64
  129. package/dist/esm/views/show.js +0 -35
  130. package/dist/esm/web.js +0 -2
  131. package/src/admin.jsx +0 -78
  132. package/src/dashboard.jsx +0 -74
  133. package/src/fields/EditableBooleanField.jsx +0 -11
  134. package/src/index.js +0 -16
  135. package/src/inputs/FKInput.jsx +0 -42
  136. package/src/resources.jsx +0 -39
  137. package/src/utils.js +0 -38
  138. package/src/views/create.jsx +0 -30
  139. package/src/views/edit.jsx +0 -48
  140. package/src/views/list.jsx +0 -86
  141. package/src/views/show.jsx +0 -51
  142. package/src/web.js +0 -3
@@ -0,0 +1,33 @@
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 Avatar from "@mui/material/Avatar";
14
+ import get from "lodash/get";
15
+ import { useRecordContext } from "ra-core";
16
+ export function AvatarField(_a) {
17
+ var { source, alt, style, nameProp } = _a, props = __rest(_a, ["source", "alt", "style", "nameProp"]);
18
+ const record = useRecordContext(props);
19
+ const value = get(record, source), name = record[nameProp];
20
+ const letters = name
21
+ ? name
22
+ .trim(" ")
23
+ .split(/\s+/)
24
+ .slice(0, 2)
25
+ .map((n) => n[0].toUpperCase())
26
+ .join("")
27
+ : "";
28
+ return (_jsx(Avatar, { src: value, alt: alt, style: style, children: letters }));
29
+ }
30
+ AvatarField.displayName = "AvatarField";
31
+ AvatarField.defaultProps = {
32
+ addLabel: true,
33
+ };
@@ -0,0 +1,3 @@
1
+ export declare function EditableBooleanField({ source }: {
2
+ source: any;
3
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,5 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { BooleanInput } from "ra-ui-materialui";
3
+ export function EditableBooleanField({ source }) {
4
+ return _jsx(BooleanInput, { source: source });
5
+ }
@@ -0,0 +1,14 @@
1
+ export declare function FKField({ refSource, refID, link, reference, source, ...props }: {
2
+ [x: string]: any;
3
+ refSource: any;
4
+ refID: any;
5
+ link: any;
6
+ reference: any;
7
+ source: any;
8
+ }): import("react/jsx-runtime").JSX.Element;
9
+ export declare namespace FKField {
10
+ var displayName: string;
11
+ var defaultProps: {
12
+ addLabel: boolean;
13
+ };
14
+ }
@@ -0,0 +1,21 @@
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, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
13
+ import { ReferenceField, TextField } from "react-admin";
14
+ export function FKField(_a) {
15
+ var { refSource, refID, link, reference, source } = _a, props = __rest(_a, ["refSource", "refID", "link", "reference", "source"]);
16
+ return (_jsx(ReferenceField, Object.assign({ link: link || "show", reference: reference, source: source }, props, { children: _jsxs(_Fragment, { children: [_jsx(TextField, { source: refSource }), " (#", _jsx(TextField, { source: refID || "id" }), ")"] }) })));
17
+ }
18
+ FKField.displayName = "FKField";
19
+ FKField.defaultProps = {
20
+ addLabel: true,
21
+ };
@@ -0,0 +1,4 @@
1
+ export declare function JsonField({ label, source }: {
2
+ label: any;
3
+ source: any;
4
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,11 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import get from "lodash/get";
3
+ import { useState } from "react";
4
+ import { Button, FunctionField, useRecordContext } from "react-admin";
5
+ export function JsonField({ label, source }) {
6
+ const [expand, setExpand] = useState(false);
7
+ const record = useRecordContext();
8
+ const src = JSON.stringify(get(record, source), null, 2);
9
+ const retval = (_jsxs("div", { children: [_jsx("p", {}), label, _jsx(Button, { variant: "contained", color: "primary", size: "small", label: expand ? "colapse" : "expand", onClick: () => setExpand(!expand) }), _jsx("p", { children: expand && _jsx("pre", { children: src }) })] }));
10
+ return _jsx(FunctionField, { render: () => retval });
11
+ }
@@ -0,0 +1,4 @@
1
+ export * from "./AvatarField";
2
+ export * from "./EditableBooleanField";
3
+ export * from "./FKField";
4
+ export * from "./JsonField";
@@ -0,0 +1,4 @@
1
+ export * from "./AvatarField";
2
+ export * from "./EditableBooleanField";
3
+ export * from "./FKField";
4
+ export * from "./JsonField";
@@ -0,0 +1,5 @@
1
+ export declare function useAction(resource: any, action: any): import("react-query").UseMutationResult<{
2
+ data: any;
3
+ }, string | {
4
+ message: string;
5
+ }, any, unknown>;
@@ -0,0 +1,6 @@
1
+ import { useDataProvider } from "react-admin";
2
+ import { useMutation } from "react-query";
3
+ export function useAction(resource, action) {
4
+ const dataProvider = useDataProvider();
5
+ return useMutation((params) => dataProvider.runAction(resource, action, params));
6
+ }
@@ -0,0 +1,14 @@
1
+ export * from "./MuffinAdmin";
2
+ export * from "./MuffinResource";
3
+ export * from "./MuffinResourceCreate";
4
+ export * from "./MuffinResourceEdit";
5
+ export * from "./MuffinResourceList";
6
+ export * from "./MuffinResourceShow";
7
+ export * from "./authprovider";
8
+ export * from "./buildRA";
9
+ export * from "./buttons";
10
+ export * from "./dataprovider";
11
+ export * from "./fields";
12
+ export * from "./types";
13
+ export * from "./utils";
14
+ export declare function initAdmin(prefix?: string, containerId?: string): Promise<void>;
package/dist/index.js ADDED
@@ -0,0 +1,35 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { createRoot } from "react-dom/client";
11
+ import { buildAdmin } from "./utils";
12
+ export * from "./MuffinAdmin";
13
+ export * from "./MuffinResource";
14
+ export * from "./MuffinResourceCreate";
15
+ export * from "./MuffinResourceEdit";
16
+ export * from "./MuffinResourceList";
17
+ export * from "./MuffinResourceShow";
18
+ export * from "./authprovider";
19
+ export * from "./buildRA";
20
+ export * from "./buttons";
21
+ export * from "./dataprovider";
22
+ export * from "./fields";
23
+ export * from "./types";
24
+ export * from "./utils";
25
+ export function initAdmin(prefix = "", containerId = "root") {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ const response = yield fetch(`${prefix}/ra.json`);
28
+ const props = yield response.json();
29
+ const container = document.getElementById(containerId);
30
+ if (!container)
31
+ throw new Error(`Container #${containerId} not found`);
32
+ const root = createRoot(container);
33
+ root.render(buildAdmin(["admin"], props));
34
+ });
35
+ }
@@ -0,0 +1,8 @@
1
+ export declare function FKInput({ refProp, refSource, fullWidth, reference, source, ...props }: {
2
+ [x: string]: any;
3
+ refProp: any;
4
+ refSource: any;
5
+ fullWidth: any;
6
+ reference: any;
7
+ source: any;
8
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,27 @@
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 { AutocompleteInput, ReferenceInput } from "react-admin";
14
+ export function FKInput(_a) {
15
+ var { refProp, refSource, fullWidth, reference, source } = _a, props = __rest(_a, ["refProp", "refSource", "fullWidth", "reference", "source"]);
16
+ const filterToQuery = (search) => {
17
+ const filters = {};
18
+ filters[refProp] = search;
19
+ return filters;
20
+ };
21
+ refSource = refSource || "id";
22
+ const renderText = (record) => {
23
+ const pk = record[refSource];
24
+ return (pk && `${record[refProp]} (#${pk})`) || "";
25
+ };
26
+ return (_jsx(ReferenceInput, Object.assign({ reference: reference, source: source, filterToQuery: filterToQuery }, props, { children: _jsx(AutocompleteInput, Object.assign({ source: refSource, optionText: renderText, fullWidth: fullWidth }, props)) })));
27
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ *
3
+ * `JsonInput` validates if the entered value is JSON or not. If entered value is not a invalid JSON, `JsonInput` will throw an error.
4
+ * Default error message is: `Invalid JSON` and can be overridden using `errortext` prop.
5
+ *
6
+ * @example
7
+ * <JsonInput source='config' label='JSON Config' errortext='Enter a valid JSON'/>
8
+ *
9
+ * or use translate function:
10
+ *
11
+ * @example
12
+ * <JsonInput source='config' label={translate('resources.resource_name.fields.config')} errortext={translate('myroot.validate.json')}/>
13
+ *
14
+ * By default, `JsonInput` parses and returns the entered string as object. Instead, to send string directly, please pass `parse` prop as `false`
15
+ *
16
+ * @example
17
+ * <JsonInput source='config' label='JSON Config' parse={false}/>
18
+ */
19
+ export declare function JsonInput(props: any): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,69 @@
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 { TextInput } from "react-admin";
14
+ import isJSON from "validator/lib/isJSON";
15
+ const DEFAULT_ERRORTEXT = "Invalid JSON";
16
+ const parseFunction = (json) => {
17
+ let retval = json;
18
+ try {
19
+ retval = JSON.parse(json);
20
+ }
21
+ finally {
22
+ // eslint-disable-next-line no-unsafe-finally
23
+ return retval;
24
+ }
25
+ };
26
+ /**
27
+ *
28
+ * `JsonInput` validates if the entered value is JSON or not. If entered value is not a invalid JSON, `JsonInput` will throw an error.
29
+ * Default error message is: `Invalid JSON` and can be overridden using `errortext` prop.
30
+ *
31
+ * @example
32
+ * <JsonInput source='config' label='JSON Config' errortext='Enter a valid JSON'/>
33
+ *
34
+ * or use translate function:
35
+ *
36
+ * @example
37
+ * <JsonInput source='config' label={translate('resources.resource_name.fields.config')} errortext={translate('myroot.validate.json')}/>
38
+ *
39
+ * By default, `JsonInput` parses and returns the entered string as object. Instead, to send string directly, please pass `parse` prop as `false`
40
+ *
41
+ * @example
42
+ * <JsonInput source='config' label='JSON Config' parse={false}/>
43
+ */
44
+ export function JsonInput(props) {
45
+ const { validate = [], errortext = DEFAULT_ERRORTEXT, multiline = true, parse = true } = props, rest = __rest(props
46
+ // const errorobj = { message: errortext }
47
+ , ["validate", "errortext", "multiline", "parse"]);
48
+ // const errorobj = { message: errortext }
49
+ const validateJSON = (value) => {
50
+ if (!value || typeof value === "object")
51
+ return undefined;
52
+ return isJSON(value) ? undefined : errortext;
53
+ };
54
+ validate.push(validateJSON);
55
+ rest.validate = validate;
56
+ const formatJSON = (json) => {
57
+ let retval = json;
58
+ if (retval && typeof retval === "object")
59
+ retval = JSON.stringify(retval, null, 2);
60
+ return retval;
61
+ };
62
+ rest.format = formatJSON;
63
+ //
64
+ if (parse)
65
+ rest.parse = parseFunction;
66
+ if (multiline)
67
+ rest.multiline = true;
68
+ return _jsx(TextInput, Object.assign({}, rest));
69
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./FKInput";
2
+ export * from "./JsonInput";
@@ -0,0 +1,2 @@
1
+ export * from "./FKInput";
2
+ export * from "./JsonInput";