@etsoo/materialui 1.1.6 → 1.1.8

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/lib/DnDList.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { UniqueIdentifier } from '@dnd-kit/core';
2
- import { DataTypes } from '@etsoo/shared';
3
- import { Theme } from '@mui/material';
4
- import React, { CSSProperties } from 'react';
1
+ import { UniqueIdentifier } from "@dnd-kit/core";
2
+ import { DataTypes } from "@etsoo/shared";
3
+ import { Theme } from "@mui/material";
4
+ import React, { CSSProperties } from "react";
5
5
  /**
6
6
  * DnD item default style
7
7
  * @param index Item index
@@ -76,6 +76,10 @@ export interface DnDListPros<D extends object, K extends DataTypes.Keys<D>> {
76
76
  * Data change handler
77
77
  */
78
78
  onChange?: (items: D[]) => void;
79
+ /**
80
+ * Form data change handler
81
+ */
82
+ onFormChange?: (items: D[]) => void;
79
83
  /**
80
84
  * Drag end handler
81
85
  */
package/lib/DnDList.js CHANGED
@@ -1,8 +1,8 @@
1
- import { DndContext } from '@dnd-kit/core';
2
- import { SortableContext, useSortable, verticalListSortingStrategy } from '@dnd-kit/sortable';
3
- import { CSS } from '@dnd-kit/utilities';
4
- import { useTheme } from '@mui/material';
5
- import React from 'react';
1
+ import { DndContext } from "@dnd-kit/core";
2
+ import { SortableContext, useSortable, verticalListSortingStrategy } from "@dnd-kit/sortable";
3
+ import { CSS } from "@dnd-kit/utilities";
4
+ import { useTheme } from "@mui/material";
5
+ import React from "react";
6
6
  function SortableItem(props) {
7
7
  // Destruct
8
8
  const { id, itemRenderer, style = {} } = props;
@@ -33,7 +33,7 @@ function SortableItem(props) {
33
33
  */
34
34
  export const DnDItemStyle = (index, isDragging, theme) => ({
35
35
  padding: theme.spacing(1),
36
- zIndex: isDragging ? 1 : 'auto',
36
+ zIndex: isDragging ? 1 : "auto",
37
37
  background: isDragging
38
38
  ? theme.palette.primary.light
39
39
  : index % 2 === 0
@@ -47,7 +47,7 @@ export const DnDItemStyle = (index, isDragging, theme) => ({
47
47
  */
48
48
  export function DnDList(props) {
49
49
  // Destruct
50
- const { keyField, itemRenderer, labelField, mRef, onChange, onDragEnd } = props;
50
+ const { keyField, itemRenderer, labelField, mRef, onChange, onFormChange, onDragEnd } = props;
51
51
  let getItemStyle = props.getItemStyle;
52
52
  if (getItemStyle == null) {
53
53
  // Theme
@@ -57,10 +57,15 @@ export function DnDList(props) {
57
57
  // States
58
58
  const [items, setItems] = React.useState([]);
59
59
  const [activeId, setActiveId] = React.useState();
60
+ const doFormChange = (newItems) => {
61
+ if (onFormChange)
62
+ onFormChange(newItems !== null && newItems !== void 0 ? newItems : items);
63
+ };
60
64
  const changeItems = (newItems) => {
61
65
  // Possible to alter items with the handler
62
66
  if (onChange)
63
67
  onChange(newItems);
68
+ doFormChange(newItems);
64
69
  // Update state
65
70
  setItems(newItems);
66
71
  };
@@ -145,12 +150,30 @@ export function DnDList(props) {
145
150
  }
146
151
  };
147
152
  }, [items]);
153
+ const setupDiv = (div) => {
154
+ // Inputs
155
+ div
156
+ .querySelectorAll("input")
157
+ .forEach((input) => input.addEventListener("change", () => doFormChange()));
158
+ // Textareas
159
+ div
160
+ .querySelectorAll("textarea")
161
+ .forEach((input) => input.addEventListener("change", () => doFormChange()));
162
+ // Select
163
+ div
164
+ .querySelectorAll("select")
165
+ .forEach((input) => input.addEventListener("change", () => doFormChange()));
166
+ };
148
167
  React.useEffect(() => {
149
168
  setItems(props.items);
150
169
  }, [props.items]);
151
- return (React.createElement(DndContext, { onDragStart: handleDragStart, onDragEnd: handleDragEnd },
152
- React.createElement(SortableContext, { items: items, strategy: verticalListSortingStrategy }, items.map((item, index) => {
153
- const id = item[keyField];
154
- return (React.createElement(SortableItem, { id: id, key: id, style: getItemStyle(index, id === activeId), itemRenderer: (nodeRef, actionNodeRef) => itemRenderer(item, index, nodeRef, actionNodeRef) }));
155
- }))));
170
+ return (React.createElement("div", { ref: (div) => {
171
+ if (div)
172
+ setupDiv(div);
173
+ } },
174
+ React.createElement(DndContext, { onDragStart: handleDragStart, onDragEnd: handleDragEnd },
175
+ React.createElement(SortableContext, { items: items, strategy: verticalListSortingStrategy }, items.map((item, index) => {
176
+ const id = item[keyField];
177
+ return (React.createElement(SortableItem, { id: id, key: id, style: getItemStyle(index, id === activeId), itemRenderer: (nodeRef, actionNodeRef) => itemRenderer(item, index, nodeRef, actionNodeRef) }));
178
+ })))));
156
179
  }
@@ -1,6 +1,6 @@
1
- import { NotificationAlign, NotificationRenderProps } from '@etsoo/notificationbase';
2
- import React from 'react';
3
- import { INotificationBaseReact, INotificationReact, NotificationReact, NotifierReact } from '@etsoo/react';
1
+ import { NotificationAlign, NotificationRenderProps } from "@etsoo/notificationbase";
2
+ import React from "react";
3
+ import { INotificationBaseReact, INotificationReact, NotificationReact, NotifierReact } from "@etsoo/react";
4
4
  /**
5
5
  * MU notification
6
6
  */
package/lib/NotifierMU.js CHANGED
@@ -1,21 +1,27 @@
1
- import { NotificationAlign, NotificationMessageType, NotificationType } from '@etsoo/notificationbase';
2
- import { DomUtils } from '@etsoo/shared';
3
- import { Alert, AlertTitle, Backdrop, Box, Button, CircularProgress, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, Fade, Slider, Snackbar, styled, Switch, TextField, Typography } from '@mui/material';
4
- import { Error, Info, Help, Warning, Done } from '@mui/icons-material';
5
- import React from 'react';
6
- import { NotificationReact, NotifierReact } from '@etsoo/react';
7
- import { DraggablePaperComponent } from './DraggablePaperComponent';
8
- import { LoadingButton } from './LoadingButton';
9
- import { Labels } from './app/Labels';
1
+ import { NotificationAlign, NotificationMessageType, NotificationType } from "@etsoo/notificationbase";
2
+ import { DomUtils } from "@etsoo/shared";
3
+ import { Alert, AlertTitle, Backdrop, Box, Button, CircularProgress, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, Fade, IconButton, Slider, Snackbar, styled, Switch, TextField, Typography } from "@mui/material";
4
+ import { Error, Info, Help, Warning, Done } from "@mui/icons-material";
5
+ import CloseIcon from "@mui/icons-material/Close";
6
+ import React from "react";
7
+ import { NotificationReact, NotifierReact } from "@etsoo/react";
8
+ import { DraggablePaperComponent } from "./DraggablePaperComponent";
9
+ import { LoadingButton } from "./LoadingButton";
10
+ import { Labels } from "./app/Labels";
10
11
  // Custom icon dialog title bar
11
12
  const IconDialogTitle = styled(DialogTitle) `
12
- ${({ theme }) => `
13
+ ${({ theme }) => `
13
14
  cursor: move;
14
15
  display: flex;
15
16
  align-items: center;
16
17
  & .dialogTitle {
17
18
  font-weight: bold;
18
19
  font-size: 1.17em;
20
+ flex-grow: 3;
21
+ text-overflow: ellipsis;
22
+ padding-left: ${theme.spacing(1)};
23
+ }
24
+ & .closeButton {
19
25
  padding-left: ${theme.spacing(1)};
20
26
  }
21
27
  `}
@@ -28,7 +34,7 @@ export class NotificationMU extends NotificationReact {
28
34
  createAlert(_props, className) {
29
35
  var _a;
30
36
  const labels = Labels.NotificationMU;
31
- const { buttons, inputs, fullScreen, fullWidth = true, maxWidth, okLabel = labels.alertOK, primaryButton } = (_a = this.inputProps) !== null && _a !== void 0 ? _a : {};
37
+ const { buttons, inputs, fullScreen, fullWidth = true, maxWidth, okLabel = labels.alertOK, primaryButton, closable = false } = (_a = this.inputProps) !== null && _a !== void 0 ? _a : {};
32
38
  let title = this.title;
33
39
  let icon;
34
40
  if (this.type === NotificationMessageType.Success) {
@@ -48,7 +54,7 @@ export class NotificationMU extends NotificationReact {
48
54
  title !== null && title !== void 0 ? title : (title = labels.alertTitle);
49
55
  }
50
56
  const setupProps = {
51
- color: 'primary'
57
+ color: "primary"
52
58
  };
53
59
  // Setup callback
54
60
  if (this.renderSetup)
@@ -61,7 +67,9 @@ export class NotificationMU extends NotificationReact {
61
67
  return (React.createElement(Dialog, { key: this.id, open: this.open, PaperComponent: DraggablePaperComponent, className: className, fullWidth: fullWidth, maxWidth: maxWidth, fullScreen: fullScreen },
62
68
  React.createElement(IconDialogTitle, { className: "draggable-dialog-title" },
63
69
  icon,
64
- React.createElement("span", { className: "dialogTitle" }, title)),
70
+ React.createElement("span", { className: "dialogTitle" }, title),
71
+ closable && (React.createElement(IconButton, { className: "closeButton", size: "small", onClick: () => this.dismiss() },
72
+ React.createElement(CloseIcon, null)))),
65
73
  React.createElement(DialogContent, null,
66
74
  React.createElement(DialogContentText, null, this.content),
67
75
  inputs),
@@ -72,7 +80,7 @@ export class NotificationMU extends NotificationReact {
72
80
  var _a, _b;
73
81
  const labels = Labels.NotificationMU;
74
82
  const title = (_a = this.title) !== null && _a !== void 0 ? _a : labels.confirmTitle;
75
- const { buttons, okLabel = labels.confirmYes, cancelLabel = labels.confirmNo, cancelButton = true, inputs, fullScreen, fullWidth = true, maxWidth, primaryButton } = (_b = this.inputProps) !== null && _b !== void 0 ? _b : {};
83
+ const { buttons, okLabel = labels.confirmYes, cancelLabel = labels.confirmNo, cancelButton = true, inputs, fullScreen, fullWidth = true, maxWidth, primaryButton, closable = false } = (_b = this.inputProps) !== null && _b !== void 0 ? _b : {};
76
84
  const callback = async (_event, value) => {
77
85
  await this.returnValue(value);
78
86
  return true;
@@ -80,7 +88,9 @@ export class NotificationMU extends NotificationReact {
80
88
  return (React.createElement(Dialog, { key: this.id, open: this.open, PaperComponent: DraggablePaperComponent, className: className, fullWidth: fullWidth, maxWidth: maxWidth, fullScreen: fullScreen },
81
89
  React.createElement(IconDialogTitle, { className: "draggable-dialog-title" },
82
90
  React.createElement(Help, { color: "action" }),
83
- React.createElement("span", { className: "dialogTitle" }, title)),
91
+ React.createElement("span", { className: "dialogTitle" }, title),
92
+ closable && (React.createElement(IconButton, { className: "closeButton", size: "small", onClick: () => this.dismiss() },
93
+ React.createElement(CloseIcon, null)))),
84
94
  React.createElement(DialogContent, null,
85
95
  React.createElement(DialogContentText, null, this.content),
86
96
  inputs),
@@ -90,26 +100,28 @@ export class NotificationMU extends NotificationReact {
90
100
  }
91
101
  createMessageColor() {
92
102
  if (this.type === NotificationMessageType.Danger)
93
- return 'error';
103
+ return "error";
94
104
  if (this.type === NotificationMessageType.Success)
95
- return 'success';
105
+ return "success";
96
106
  if (this.type === NotificationMessageType.Warning)
97
- return 'warning';
98
- return 'info';
107
+ return "warning";
108
+ return "info";
99
109
  }
100
110
  // Create message
101
- createMessage(_props, className) {
111
+ createMessage(props, className) {
102
112
  if (!this.open)
103
113
  return React.createElement(React.Fragment, { key: this.id });
114
+ const { closable = false } = props;
104
115
  const setupProps = {
105
116
  severity: this.createMessageColor(),
106
- variant: 'filled'
117
+ variant: "filled"
107
118
  };
108
119
  // Setup callback
109
120
  if (this.renderSetup)
110
121
  this.renderSetup(setupProps);
111
122
  return (React.createElement(Fade, { in: true, key: this.id },
112
- React.createElement(Alert, { ...setupProps, onClose: () => this.dismiss(), className: className },
123
+ React.createElement(Alert, { ...setupProps, action: closable ? (React.createElement(IconButton, { size: "small", onClick: () => this.dismiss() },
124
+ React.createElement(CloseIcon, null))) : undefined, onClose: () => this.dismiss(), className: className },
113
125
  this.title && React.createElement(AlertTitle, null, this.title),
114
126
  this.content)));
115
127
  }
@@ -118,13 +130,13 @@ export class NotificationMU extends NotificationReact {
118
130
  var _a, _b;
119
131
  const labels = Labels.NotificationMU;
120
132
  const title = (_a = this.title) !== null && _a !== void 0 ? _a : labels.promptTitle;
121
- const { buttons, cancelLabel = labels.promptCancel, okLabel = labels.promptOK, cancelButton = true, inputs, type, fullScreen, fullWidth = true, maxWidth, primaryButton, inputProps } = (_b = this.inputProps) !== null && _b !== void 0 ? _b : {};
133
+ const { buttons, cancelLabel = labels.promptCancel, okLabel = labels.promptOK, cancelButton = true, inputs, type, fullScreen, fullWidth = true, maxWidth, primaryButton, inputProps, closable = false } = (_b = this.inputProps) !== null && _b !== void 0 ? _b : {};
122
134
  const inputRef = React.createRef();
123
135
  const errorRef = React.createRef();
124
136
  const setError = (error) => {
125
137
  if (errorRef.current == null)
126
138
  return;
127
- errorRef.current.innerText = error !== null && error !== void 0 ? error : '';
139
+ errorRef.current.innerText = error !== null && error !== void 0 ? error : "";
128
140
  };
129
141
  const handleSubmit = async (event) => {
130
142
  // Result
@@ -135,14 +147,13 @@ export class NotificationMU extends NotificationReact {
135
147
  if (inputs && value == null)
136
148
  value = event.currentTarget.form;
137
149
  if (input) {
138
- if (type === 'switch') {
139
- const boolValue = input.value === 'true';
150
+ if (type === "switch") {
151
+ const boolValue = input.value === "true";
140
152
  result = this.onReturn(boolValue);
141
153
  }
142
154
  else {
143
155
  const inputValue = DomUtils.getInputValue(input);
144
- if ((inputValue == null || inputValue === '') &&
145
- input.required) {
156
+ if ((inputValue == null || inputValue === "") && input.required) {
146
157
  input.focus();
147
158
  return false;
148
159
  }
@@ -160,7 +171,7 @@ export class NotificationMU extends NotificationReact {
160
171
  input === null || input === void 0 ? void 0 : input.focus();
161
172
  return false;
162
173
  }
163
- if (typeof v === 'string') {
174
+ if (typeof v === "string") {
164
175
  setError(v);
165
176
  input === null || input === void 0 ? void 0 : input.focus();
166
177
  return false;
@@ -171,10 +182,10 @@ export class NotificationMU extends NotificationReact {
171
182
  let localInputs;
172
183
  let value = undefined;
173
184
  if (inputs == null) {
174
- if (type === 'switch') {
185
+ if (type === "switch") {
175
186
  localInputs = (React.createElement(Switch, { inputRef: inputRef, ...inputProps, value: "true", autoFocus: true, required: true }));
176
187
  }
177
- else if (type === 'slider') {
188
+ else if (type === "slider") {
178
189
  localInputs = React.createElement(Slider, { onChange: (_e, v) => (value = v) });
179
190
  }
180
191
  else {
@@ -188,12 +199,14 @@ export class NotificationMU extends NotificationReact {
188
199
  React.createElement("form", { onSubmit: (event) => {
189
200
  var _a;
190
201
  event.preventDefault();
191
- (_a = event.currentTarget.elements.namedItem('okButton')) === null || _a === void 0 ? void 0 : _a.click();
202
+ (_a = event.currentTarget.elements.namedItem("okButton")) === null || _a === void 0 ? void 0 : _a.click();
192
203
  return false;
193
204
  } },
194
205
  React.createElement(IconDialogTitle, { className: "draggable-dialog-title" },
195
206
  React.createElement(Info, { color: "primary" }),
196
- React.createElement("span", { className: "dialogTitle" }, title)),
207
+ React.createElement("span", { className: "dialogTitle" }, title),
208
+ closable && (React.createElement(IconButton, { className: "closeButton", size: "small", onClick: () => this.dismiss() },
209
+ React.createElement(CloseIcon, null)))),
197
210
  React.createElement(DialogContent, null,
198
211
  React.createElement(DialogContentText, null, this.content),
199
212
  localInputs,
@@ -210,23 +223,23 @@ export class NotificationMU extends NotificationReact {
210
223
  createLoading(_props, className) {
211
224
  var _a;
212
225
  // Properties
213
- const setupProps = { color: 'primary' };
226
+ const setupProps = { color: "primary" };
214
227
  const labels = Labels.NotificationMU;
215
228
  // Input props
216
- const { maxWidth = 'xs' } = (_a = this.inputProps) !== null && _a !== void 0 ? _a : {};
229
+ const { maxWidth = "xs" } = (_a = this.inputProps) !== null && _a !== void 0 ? _a : {};
217
230
  // Content
218
231
  let content = this.content;
219
- if (content === '@')
232
+ if (content === "@")
220
233
  content = labels.loading.toString();
221
234
  // Setup callback
222
235
  if (this.renderSetup)
223
236
  this.renderSetup(setupProps);
224
237
  return (React.createElement(Backdrop, { key: this.id, className: className, sx: {
225
- color: '#fff',
238
+ color: "#fff",
226
239
  zIndex: (theme) => theme.zIndex.modal + 1
227
240
  }, open: this.open },
228
241
  React.createElement(Box, { display: "flex", flexDirection: "column", flexWrap: "nowrap", alignItems: "center", sx: {
229
- '& > :not(style) + :not(style)': {
242
+ "& > :not(style) + :not(style)": {
230
243
  marginTop: (theme) => theme.spacing(1)
231
244
  }
232
245
  } },
@@ -285,10 +298,10 @@ export class NotifierMU extends NotifierReact {
285
298
  }
286
299
  // Use SnackBar for layout
287
300
  return (React.createElement(Snackbar, { anchorOrigin: NotifierMU.getOrigin(align), className: className, key: `layout-${alignText}`, sx: align === NotificationAlign.Center
288
- ? { position: 'fixed', top: '50%!important' }
301
+ ? { position: "fixed", top: "50%!important" }
289
302
  : undefined, open: true },
290
303
  React.createElement(Box, { display: "flex", flexDirection: "column", flexWrap: "nowrap", key: `box-${alignText}`, sx: {
291
- '& > :not(style) + :not(style)': {
304
+ "& > :not(style) + :not(style)": {
292
305
  marginTop: (theme) => theme.spacing(1)
293
306
  }
294
307
  } }, children)));
@@ -299,7 +312,7 @@ export class NotifierMU extends NotifierReact {
299
312
  * @param className Style class name
300
313
  * @returns Provider
301
314
  */
302
- static setup(className = 'notifier-mu') {
315
+ static setup(className = "notifier-mu") {
303
316
  // Create an instance
304
317
  const instance = new NotifierMU();
305
318
  const provider = instance.createProvider(className);
@@ -310,43 +323,43 @@ export class NotifierMU extends NotifierReact {
310
323
  static getOrigin(align) {
311
324
  if (align === NotificationAlign.TopLeft) {
312
325
  return {
313
- horizontal: 'left',
314
- vertical: 'top'
326
+ horizontal: "left",
327
+ vertical: "top"
315
328
  };
316
329
  }
317
330
  if (align === NotificationAlign.TopCenter) {
318
331
  return {
319
- horizontal: 'center',
320
- vertical: 'top'
332
+ horizontal: "center",
333
+ vertical: "top"
321
334
  };
322
335
  }
323
336
  if (align === NotificationAlign.TopRight) {
324
337
  return {
325
- horizontal: 'right',
326
- vertical: 'top'
338
+ horizontal: "right",
339
+ vertical: "top"
327
340
  };
328
341
  }
329
342
  if (align === NotificationAlign.BottomLeft) {
330
343
  return {
331
- horizontal: 'left',
332
- vertical: 'bottom'
344
+ horizontal: "left",
345
+ vertical: "bottom"
333
346
  };
334
347
  }
335
348
  if (align === NotificationAlign.BottomCenter) {
336
349
  return {
337
- horizontal: 'center',
338
- vertical: 'bottom'
350
+ horizontal: "center",
351
+ vertical: "bottom"
339
352
  };
340
353
  }
341
354
  if (align === NotificationAlign.BottomRight) {
342
355
  return {
343
- horizontal: 'right',
344
- vertical: 'bottom'
356
+ horizontal: "right",
357
+ vertical: "bottom"
345
358
  };
346
359
  }
347
360
  return {
348
- horizontal: 'center',
349
- vertical: 'top'
361
+ horizontal: "center",
362
+ vertical: "top"
350
363
  };
351
364
  }
352
365
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/materialui",
3
- "version": "1.1.6",
3
+ "version": "1.1.8",
4
4
  "description": "TypeScript Material-UI Implementation",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -52,7 +52,7 @@
52
52
  "@emotion/styled": "^11.10.5",
53
53
  "@etsoo/appscript": "^1.3.58",
54
54
  "@etsoo/notificationbase": "^1.1.23",
55
- "@etsoo/react": "^1.6.41",
55
+ "@etsoo/react": "^1.6.42",
56
56
  "@etsoo/shared": "^1.1.88",
57
57
  "@mui/icons-material": "^5.11.0",
58
58
  "@mui/material": "^5.11.4",