@appcorp/stellar-solutions-modules 0.1.49 → 0.1.51
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.
|
@@ -15,6 +15,8 @@ export type EnhancedDropzoneProps = {
|
|
|
15
15
|
initial?: Array<File | string>;
|
|
16
16
|
/** Called when selected File[] changes */
|
|
17
17
|
onChange?: (files: File[]) => void;
|
|
18
|
+
/** Called when the rendered previews (string[]) change */
|
|
19
|
+
onPreviewsChange?: (previews: string[]) => void;
|
|
18
20
|
/** Called when a provided remote URL preview is removed (if provided) */
|
|
19
21
|
onRemoveUrl?: (url: string) => void;
|
|
20
22
|
};
|
|
@@ -63,7 +63,7 @@ var button_1 = require("./button");
|
|
|
63
63
|
var lucide_react_1 = require("lucide-react");
|
|
64
64
|
var dropzone_1 = require("./shadcn-io/dropzone");
|
|
65
65
|
var EnhancedDropzone = function (_a) {
|
|
66
|
-
var id = _a.id, label = _a.label, info = _a.info, error = _a.error, accept = _a.accept, _b = _a.maxFiles, maxFiles = _b === void 0 ? 10 : _b, maxSize = _a.maxSize, minSize = _a.minSize, disabled = _a.disabled, _c = _a.initial, initial = _c === void 0 ? [] : _c, onChange = _a.onChange, onRemoveUrl = _a.onRemoveUrl, className = _a.className;
|
|
66
|
+
var id = _a.id, label = _a.label, info = _a.info, error = _a.error, accept = _a.accept, _b = _a.maxFiles, maxFiles = _b === void 0 ? 10 : _b, maxSize = _a.maxSize, minSize = _a.minSize, disabled = _a.disabled, _c = _a.initial, initial = _c === void 0 ? [] : _c, onChange = _a.onChange, onPreviewsChange = _a.onPreviewsChange, onRemoveUrl = _a.onRemoveUrl, className = _a.className;
|
|
67
67
|
// Files selected locally (File objects)
|
|
68
68
|
var _d = (0, react_1.useState)([]), files = _d[0], setFiles = _d[1];
|
|
69
69
|
// Previews array contains strings (object URLs or provided URLs) in display order
|
|
@@ -74,6 +74,9 @@ var EnhancedDropzone = function (_a) {
|
|
|
74
74
|
// Track remote URLs removed by the user so they don't reappear when
|
|
75
75
|
// previews are rebuilt from the unchanged `initial` prop.
|
|
76
76
|
var removedRemoteRef = (0, react_1.useRef)(new Set());
|
|
77
|
+
// Track previous previews and remote map to avoid emitting unchanged values
|
|
78
|
+
var previewsRef = (0, react_1.useRef)([]);
|
|
79
|
+
var remotePreviewsRef = (0, react_1.useRef)({});
|
|
77
80
|
var dropzoneOptions = {
|
|
78
81
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
79
82
|
accept: (Array.isArray(accept) ? undefined : accept) || undefined,
|
|
@@ -137,8 +140,49 @@ var EnhancedDropzone = function (_a) {
|
|
|
137
140
|
next.push("");
|
|
138
141
|
}
|
|
139
142
|
});
|
|
140
|
-
|
|
141
|
-
|
|
143
|
+
// Avoid unnecessary updates: only set state / notify parent when previews
|
|
144
|
+
// or remoteMap actually changed (shallow equality check). This prevents
|
|
145
|
+
// a cycle when parent mirrors the previews back into `initial`.
|
|
146
|
+
var prev = previewsRef.current || [];
|
|
147
|
+
var arraysEqual = function (a, b) {
|
|
148
|
+
if (a === b)
|
|
149
|
+
return true;
|
|
150
|
+
if (!a || !b)
|
|
151
|
+
return false;
|
|
152
|
+
if (a.length !== b.length)
|
|
153
|
+
return false;
|
|
154
|
+
for (var i = 0; i < a.length; i++)
|
|
155
|
+
if (a[i] !== b[i])
|
|
156
|
+
return false;
|
|
157
|
+
return true;
|
|
158
|
+
};
|
|
159
|
+
var remoteKeysEqual = function (m1, m2) {
|
|
160
|
+
var k1 = Object.keys(m1 || {});
|
|
161
|
+
var k2 = Object.keys(m2 || {});
|
|
162
|
+
if (k1.length !== k2.length)
|
|
163
|
+
return false;
|
|
164
|
+
k1.sort();
|
|
165
|
+
k2.sort();
|
|
166
|
+
for (var i = 0; i < k1.length; i++)
|
|
167
|
+
if (k1[i] !== k2[i])
|
|
168
|
+
return false;
|
|
169
|
+
return true;
|
|
170
|
+
};
|
|
171
|
+
var previewsChanged = !arraysEqual(prev, next);
|
|
172
|
+
var remoteChanged = !remoteKeysEqual(remotePreviewsRef.current || {}, remoteMap);
|
|
173
|
+
if (previewsChanged) {
|
|
174
|
+
setPreviews(next);
|
|
175
|
+
previewsRef.current = next.slice();
|
|
176
|
+
}
|
|
177
|
+
if (remoteChanged) {
|
|
178
|
+
setRemotePreviews(remoteMap);
|
|
179
|
+
remotePreviewsRef.current = __assign({}, remoteMap);
|
|
180
|
+
}
|
|
181
|
+
if (previewsChanged) {
|
|
182
|
+
onPreviewsChange === null || onPreviewsChange === void 0 ? void 0 : onPreviewsChange(next);
|
|
183
|
+
}
|
|
184
|
+
// notify parent about the current rendered previews (object URLs and remote URLs)
|
|
185
|
+
onPreviewsChange === null || onPreviewsChange === void 0 ? void 0 : onPreviewsChange(next);
|
|
142
186
|
return function () {
|
|
143
187
|
(createdUrlsRef.current || []).forEach(function (u) {
|
|
144
188
|
try {
|
|
@@ -149,7 +193,7 @@ var EnhancedDropzone = function (_a) {
|
|
|
149
193
|
createdUrlsRef.current = [];
|
|
150
194
|
};
|
|
151
195
|
// files and initial are the dependencies
|
|
152
|
-
}, [files, initial]);
|
|
196
|
+
}, [files, initial, onPreviewsChange]);
|
|
153
197
|
// Remove a local file by index (index relative to files slice after initial length)
|
|
154
198
|
var handleRemoveLocal = function (index) {
|
|
155
199
|
var next = files.filter(function (_, i) { return i !== index; });
|
|
@@ -166,10 +210,8 @@ var EnhancedDropzone = function (_a) {
|
|
|
166
210
|
return;
|
|
167
211
|
var isRemote = Boolean(remotePreviews[entry]);
|
|
168
212
|
if (isRemote) {
|
|
169
|
-
// notify parent
|
|
213
|
+
// notify parent and mark as removed so it won't reappear from `initial`
|
|
170
214
|
onRemoveUrl === null || onRemoveUrl === void 0 ? void 0 : onRemoveUrl(entry);
|
|
171
|
-
// record removal locally so the value isn't re-added from the `initial`
|
|
172
|
-
// prop on the next rebuild
|
|
173
215
|
removedRemoteRef.current.add(entry);
|
|
174
216
|
// remove only the specific preview at previewIndex
|
|
175
217
|
setPreviews(function (p) {
|
|
@@ -182,6 +224,9 @@ var EnhancedDropzone = function (_a) {
|
|
|
182
224
|
delete next[entry];
|
|
183
225
|
return next;
|
|
184
226
|
});
|
|
227
|
+
// inform parent of the immediate change
|
|
228
|
+
var updatedPreviews = previews.filter(function (_, i) { return i !== previewIndex; });
|
|
229
|
+
onPreviewsChange === null || onPreviewsChange === void 0 ? void 0 : onPreviewsChange(updatedPreviews);
|
|
185
230
|
return;
|
|
186
231
|
}
|
|
187
232
|
// local file - compute index relative to files array and remove
|
package/package.json
CHANGED