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