muffin-admin 8.5.6 → 9.1.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
@@ -1,7 +1,8 @@
1
1
  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, SelectArrayInput, SelectField, SelectInput, TextField, TextInput, UrlField, } from "react-admin";
3
3
  import { AvatarField, CopyField, EditableBooleanField, FKField, JsonField } from "./fields";
4
- import { FilterInput, FKInput, JsonInput, TimestampInput } from "./inputs";
4
+ import { DateRangeFilter, Filter } from "./filters";
5
+ import { FKInput, JsonInput, TimestampInput } from "./inputs";
5
6
  const UI = {
6
7
  // Fields
7
8
  BooleanField,
@@ -31,7 +32,6 @@ const UI = {
31
32
  BooleanInput,
32
33
  CheckboxGroupInput,
33
34
  DateInput,
34
- FilterInput,
35
35
  DateTimeInput,
36
36
  FKInput,
37
37
  FileInput,
@@ -47,6 +47,9 @@ const UI = {
47
47
  SelectInput,
48
48
  TextInput,
49
49
  TimestampInput,
50
+ // Filters
51
+ Filter,
52
+ DateRangeFilter,
50
53
  };
51
54
  export function buildRAComponent(name, props) {
52
55
  const Item = UI[name];
@@ -0,0 +1 @@
1
+ export declare function DateRangeFilter(props: any): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,17 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useInput } from "react-admin";
3
+ import { DateRangeInput } from "../inputs/DateRangeInput";
4
+ export function DateRangeFilter(props) {
5
+ var _a;
6
+ const { field } = useInput(props);
7
+ const onChange = (dates) => {
8
+ field.onChange({
9
+ $between: dates.map((d) => (d === null || d === void 0 ? void 0 : d.toISOString()) || null),
10
+ });
11
+ };
12
+ let filterValue = (_a = field.value.$between) !== null && _a !== void 0 ? _a : [null, null];
13
+ if (!Array.isArray(filterValue))
14
+ filterValue = [null, null];
15
+ const value = filterValue.map((d) => (d ? new Date(d) : d));
16
+ return _jsx(DateRangeInput, Object.assign({ value: value, onChange: onChange }, props));
17
+ }
@@ -0,0 +1,2 @@
1
+ import { InputProps } from "react-admin";
2
+ export declare function Filter({ type, ...props }: InputProps): import("react/jsx-runtime").JSX.Element;
@@ -16,7 +16,7 @@ import Menu from "@mui/material/Menu";
16
16
  import MenuItem from "@mui/material/MenuItem";
17
17
  import TextField from "@mui/material/TextField";
18
18
  import { useState } from "react";
19
- import { useInput } from "react-admin";
19
+ import { FieldTitle, useInput } from "react-admin";
20
20
  const OPERATORS = {
21
21
  $eq: "=",
22
22
  $ne: "≠",
@@ -25,7 +25,7 @@ const OPERATORS = {
25
25
  $lt: "<",
26
26
  $le: "≤",
27
27
  };
28
- export function FilterInput(_a) {
28
+ export function Filter(_a) {
29
29
  var { type = "text" } = _a, props = __rest(_a, ["type"]);
30
30
  const { field } = useInput(Object.assign({ format: (value) => (value ? value[Object.keys(value)[0]] : "") }, props));
31
31
  const [op, setOp] = useState((field.value && Object.keys(field.value)[0]) || "$eq");
@@ -34,7 +34,8 @@ export function FilterInput(_a) {
34
34
  };
35
35
  const [menuEl, setMenuEl] = useState(null);
36
36
  const open = Boolean(menuEl);
37
- return (_jsxs(_Fragment, { children: [_jsxs(FormGroup, { row: true, sx: { flexWrap: "nowrap" }, children: [_jsx(Button, { size: "small", disableElevation: true, sx: { minWidth: 30 }, onClick: (e) => setMenuEl(e.currentTarget), children: _jsx("span", { style: { fontSize: "1.5em" }, children: OPERATORS[op] }) }), _jsx(TextField, Object.assign({}, field, { onChange: onChange, value: field.value, variant: "outlined", type: type }))] }), _jsx(Menu, { open: open, onClose: () => setMenuEl(null), anchorEl: menuEl, children: Object.entries(OPERATORS).map(([key, value]) => (_jsx(MenuItem, { selected: op === value, onClick: () => {
37
+ const { label, source, resource, isRequired } = props;
38
+ return (_jsxs(_Fragment, { children: [_jsxs(FormGroup, { row: true, sx: { flexWrap: "nowrap" }, children: [_jsx(Button, { size: "small", disableElevation: true, sx: { minWidth: 30 }, onClick: (e) => setMenuEl(e.currentTarget), children: _jsx("span", { style: { fontSize: "1.5em" }, children: OPERATORS[op] }) }), _jsx(TextField, Object.assign({}, field, { onChange: onChange, value: field.value, variant: "outlined", type: type, label: _jsx(FieldTitle, { label: label, source: source, resource: resource, isRequired: isRequired }) }))] }), _jsx(Menu, { open: open, onClose: () => setMenuEl(null), anchorEl: menuEl, children: Object.entries(OPERATORS).map(([key, value]) => (_jsx(MenuItem, { selected: op === value, onClick: () => {
38
39
  setOp(key);
39
40
  setMenuEl(null);
40
41
  field.onChange({ [key]: field.value });
@@ -0,0 +1,2 @@
1
+ export * from "./DateRangeFilter";
2
+ export * from "./Filter";
@@ -0,0 +1,2 @@
1
+ export * from "./DateRangeFilter";
2
+ export * from "./Filter";
package/dist/index.d.ts CHANGED
@@ -18,4 +18,4 @@ export * from "./fields";
18
18
  export * from "./hooks";
19
19
  export * from "./types";
20
20
  export declare function initAdmin(prefix?: string, containerId?: string): Promise<void>;
21
- export declare const VERSION = "8.5.6";
21
+ export declare const VERSION = "9.1.0";
package/dist/index.js CHANGED
@@ -41,4 +41,4 @@ export function initAdmin() {
41
41
  root.render(_jsx(MuffinAdminContext.Provider, { value: adminOpts, children: _jsx(MuffinAdmin, {}) }));
42
42
  });
43
43
  }
44
- export const VERSION = "8.5.6";
44
+ export const VERSION = "9.1.0";
@@ -0,0 +1,8 @@
1
+ import { InputProps } from "react-admin";
2
+ import "react-datepicker/dist/react-datepicker.css";
3
+ type TProps = InputProps & {
4
+ value: [Date, Date];
5
+ onChange: (value: [Date, Date]) => void;
6
+ };
7
+ export declare function DateRangeInput({ value, onChange, ...props }: TProps): import("react/jsx-runtime").JSX.Element;
8
+ export {};
@@ -0,0 +1,26 @@
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 TextField from "@mui/material/TextField";
14
+ import { enGB, ru } from "date-fns/locale";
15
+ import { FieldTitle, useLocale } from "react-admin";
16
+ import DatePicker, { registerLocale } from "react-datepicker";
17
+ import "react-datepicker/dist/react-datepicker.css";
18
+ registerLocale("ru", ru);
19
+ registerLocale("en", enGB);
20
+ export function DateRangeInput(_a) {
21
+ var { value, onChange } = _a, props = __rest(_a, ["value", "onChange"]);
22
+ const [startDate, endDate] = value;
23
+ const locale = useLocale();
24
+ const { label, source, resource, isRequired } = props;
25
+ return (_jsx(DatePicker, { withPortal: true, locale: locale, selectsRange: true, endDate: endDate, onChange: onChange, startDate: startDate, customInput: _jsx(TextField, { variant: "outlined", label: _jsx(FieldTitle, { label: label, source: source, resource: resource, isRequired: isRequired }) }) }));
26
+ }
@@ -1,4 +1,3 @@
1
- export * from "./FilterInput";
2
1
  export * from "./FKInput";
3
2
  export * from "./JsonInput";
4
3
  export * from "./TimestampInput";
@@ -1,4 +1,3 @@
1
- export * from "./FilterInput";
2
1
  export * from "./FKInput";
3
2
  export * from "./JsonInput";
4
3
  export * from "./TimestampInput";