authscape 1.0.326 → 1.0.327

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/index.js CHANGED
@@ -134,6 +134,8 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
134
134
  function AutoSaveTextField(_ref) {
135
135
  var _ref$label = _ref.label,
136
136
  label = _ref$label === void 0 ? "" : _ref$label,
137
+ _ref$value = _ref.value,
138
+ value = _ref$value === void 0 ? null : _ref$value,
137
139
  _ref$variant = _ref.variant,
138
140
  variant = _ref$variant === void 0 ? "outlined" : _ref$variant,
139
141
  _ref$timeout = _ref.timeout,
@@ -146,7 +148,7 @@ function AutoSaveTextField(_ref) {
146
148
  fullWidth = _ref$fullWidth === void 0 ? false : _ref$fullWidth,
147
149
  _ref$onChanged = _ref.onChanged,
148
150
  onChanged = _ref$onChanged === void 0 ? null : _ref$onChanged;
149
- var _useState = (0, _react.useState)(''),
151
+ var _useState = (0, _react.useState)(value),
150
152
  _useState2 = _slicedToArray(_useState, 2),
151
153
  text = _useState2[0],
152
154
  setText = _useState2[1];
@@ -154,32 +156,41 @@ function AutoSaveTextField(_ref) {
154
156
  _useState4 = _slicedToArray(_useState3, 2),
155
157
  isComponentMounted = _useState4[0],
156
158
  setComponentMounted = _useState4[1];
159
+ var _useState5 = (0, _react.useState)(false),
160
+ _useState6 = _slicedToArray(_useState5, 2),
161
+ isFirstLoaded = _useState6[0],
162
+ setIsFirstLoaded = _useState6[1];
157
163
  (0, _react.useEffect)(function () {
158
164
  // Set the componentMounted flag to true after the initial render
159
- setComponentMounted(true);
165
+ if (!isComponentMounted) {
166
+ setComponentMounted(true);
167
+ }
160
168
  }, []);
161
169
  (0, _react.useEffect)(function () {
162
- if (isComponentMounted) {
163
- // Simulate saving text to a server or any storage mechanism
164
- // In a real-world scenario, you would send a request to a server to save the text
165
- // For this example, we'll just update the savedText state after 2 seconds
166
- var saveTimeout = setTimeout(function () {
167
- if (onChanged != null) {
168
- onChanged(text);
169
- }
170
- }, timeout);
170
+ if (isComponentMounted && text != null) {
171
+ if (isFirstLoaded) {
172
+ // Simulate saving text to a server or any storage mechanism
173
+ // In a real-world scenario, you would send a request to a server to save the text
174
+ // For this example, we'll just update the savedText state after 2 seconds
175
+ var saveTimeout = setTimeout(function () {
176
+ if (onChanged != null) {
177
+ onChanged(text);
178
+ }
179
+ }, timeout);
171
180
 
172
- // Clean up the timeout to avoid unnecessary saves if the text changes again
173
- return function () {
174
- return clearTimeout(saveTimeout);
175
- };
181
+ // Clean up the timeout to avoid unnecessary saves if the text changes again
182
+ return function () {
183
+ return clearTimeout(saveTimeout);
184
+ };
185
+ }
186
+ setIsFirstLoaded(true);
176
187
  }
177
188
  }, [text, isComponentMounted]);
178
189
  var handleTextChange = function handleTextChange(event) {
179
190
  var newText = event.target.value;
180
191
  setText(newText);
181
192
  };
182
- return /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(_TextField["default"], {
193
+ return /*#__PURE__*/_react["default"].createElement(_TextField["default"], {
183
194
  label: label,
184
195
  fullWidth: fullWidth,
185
196
  variant: variant,
@@ -187,7 +198,7 @@ function AutoSaveTextField(_ref) {
187
198
  rows: rows,
188
199
  value: text,
189
200
  onChange: handleTextChange
190
- }));
201
+ });
191
202
  }
192
203
  ;
193
204
  "use strict";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "authscape",
3
- "version": "1.0.326",
3
+ "version": "1.0.327",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,31 +1,40 @@
1
1
  import React, { useState, useEffect } from 'react';
2
2
  import TextField from '@mui/material/TextField';
3
3
 
4
- export function AutoSaveTextField ({label = "", variant = "outlined", timeout = 2000, isMultiLine = false, rows = 1, fullWidth = false, onChanged = null}) {
5
- const [text, setText] = useState('');
4
+ export function AutoSaveTextField ({label = "", value = null, variant = "outlined", timeout = 2000, isMultiLine = false, rows = 1, fullWidth = false, onChanged = null}) {
5
+ const [text, setText] = useState(value);
6
6
  const [isComponentMounted, setComponentMounted] = useState(false);
7
+ const [isFirstLoaded, setIsFirstLoaded] = useState(false);
7
8
 
8
9
  useEffect(() => {
9
10
  // Set the componentMounted flag to true after the initial render
10
- setComponentMounted(true);
11
+ if (!isComponentMounted)
12
+ {
13
+ setComponentMounted(true);
14
+ }
11
15
  }, []);
12
16
 
13
17
  useEffect(() => {
14
18
 
15
- if (isComponentMounted)
19
+ if (isComponentMounted && text != null)
16
20
  {
17
- // Simulate saving text to a server or any storage mechanism
18
- // In a real-world scenario, you would send a request to a server to save the text
19
- // For this example, we'll just update the savedText state after 2 seconds
20
- const saveTimeout = setTimeout(() => {
21
- if (onChanged != null)
21
+ if (isFirstLoaded)
22
22
  {
23
- onChanged(text);
23
+ // Simulate saving text to a server or any storage mechanism
24
+ // In a real-world scenario, you would send a request to a server to save the text
25
+ // For this example, we'll just update the savedText state after 2 seconds
26
+ const saveTimeout = setTimeout(() => {
27
+ if (onChanged != null)
28
+ {
29
+ onChanged(text);
30
+ }
31
+ }, timeout);
32
+
33
+ // Clean up the timeout to avoid unnecessary saves if the text changes again
34
+ return () => clearTimeout(saveTimeout);
24
35
  }
25
- }, timeout);
26
36
 
27
- // Clean up the timeout to avoid unnecessary saves if the text changes again
28
- return () => clearTimeout(saveTimeout);
37
+ setIsFirstLoaded(true);
29
38
  }
30
39
  }, [text, isComponentMounted]);
31
40
 
@@ -35,8 +44,7 @@ export function AutoSaveTextField ({label = "", variant = "outlined", timeout =
35
44
  };
36
45
 
37
46
  return (
38
- <div>
39
- <TextField
47
+ <TextField
40
48
  label={label}
41
49
  fullWidth={fullWidth}
42
50
  variant={variant}
@@ -44,7 +52,6 @@ export function AutoSaveTextField ({label = "", variant = "outlined", timeout =
44
52
  rows={rows}
45
53
  value={text}
46
54
  onChange={handleTextChange}
47
- />
48
- </div>
55
+ />
49
56
  );
50
57
  };