@tunghtml/strapi-plugin-composite-field 1.1.7 → 1.1.10

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.
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const jsxRuntime = require("react/jsx-runtime");
4
- const React = require("react");
5
4
  const designSystem = require("@strapi/design-system");
6
5
  const icons = require("@strapi/icons");
6
+ const admin = require("@strapi/strapi/admin");
7
+ const React = require("react");
7
8
  function _interopNamespace(e) {
8
9
  if (e && e.__esModule) return e;
9
10
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
@@ -22,6 +23,463 @@ function _interopNamespace(e) {
22
23
  return Object.freeze(n);
23
24
  }
24
25
  const React__namespace = /* @__PURE__ */ _interopNamespace(React);
26
+ var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
27
+ function getDefaultExportFromCjs(x) {
28
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
29
+ }
30
+ var isArray$3 = Array.isArray;
31
+ var isArray_1 = isArray$3;
32
+ var freeGlobal$1 = typeof commonjsGlobal == "object" && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal;
33
+ var _freeGlobal = freeGlobal$1;
34
+ var freeGlobal = _freeGlobal;
35
+ var freeSelf = typeof self == "object" && self && self.Object === Object && self;
36
+ var root$3 = freeGlobal || freeSelf || Function("return this")();
37
+ var _root = root$3;
38
+ var root$2 = _root;
39
+ var Symbol$4 = root$2.Symbol;
40
+ var _Symbol = Symbol$4;
41
+ var Symbol$3 = _Symbol;
42
+ var objectProto$4 = Object.prototype;
43
+ var hasOwnProperty$3 = objectProto$4.hasOwnProperty;
44
+ var nativeObjectToString$1 = objectProto$4.toString;
45
+ var symToStringTag$1 = Symbol$3 ? Symbol$3.toStringTag : void 0;
46
+ function getRawTag$1(value) {
47
+ var isOwn = hasOwnProperty$3.call(value, symToStringTag$1), tag = value[symToStringTag$1];
48
+ try {
49
+ value[symToStringTag$1] = void 0;
50
+ var unmasked = true;
51
+ } catch (e) {
52
+ }
53
+ var result = nativeObjectToString$1.call(value);
54
+ if (unmasked) {
55
+ if (isOwn) {
56
+ value[symToStringTag$1] = tag;
57
+ } else {
58
+ delete value[symToStringTag$1];
59
+ }
60
+ }
61
+ return result;
62
+ }
63
+ var _getRawTag = getRawTag$1;
64
+ var objectProto$3 = Object.prototype;
65
+ var nativeObjectToString = objectProto$3.toString;
66
+ function objectToString$1(value) {
67
+ return nativeObjectToString.call(value);
68
+ }
69
+ var _objectToString = objectToString$1;
70
+ var Symbol$2 = _Symbol, getRawTag = _getRawTag, objectToString = _objectToString;
71
+ var nullTag = "[object Null]", undefinedTag = "[object Undefined]";
72
+ var symToStringTag = Symbol$2 ? Symbol$2.toStringTag : void 0;
73
+ function baseGetTag$2(value) {
74
+ if (value == null) {
75
+ return value === void 0 ? undefinedTag : nullTag;
76
+ }
77
+ return symToStringTag && symToStringTag in Object(value) ? getRawTag(value) : objectToString(value);
78
+ }
79
+ var _baseGetTag = baseGetTag$2;
80
+ function isObjectLike$1(value) {
81
+ return value != null && typeof value == "object";
82
+ }
83
+ var isObjectLike_1 = isObjectLike$1;
84
+ var baseGetTag$1 = _baseGetTag, isObjectLike = isObjectLike_1;
85
+ var symbolTag = "[object Symbol]";
86
+ function isSymbol$3(value) {
87
+ return typeof value == "symbol" || isObjectLike(value) && baseGetTag$1(value) == symbolTag;
88
+ }
89
+ var isSymbol_1 = isSymbol$3;
90
+ var isArray$2 = isArray_1, isSymbol$2 = isSymbol_1;
91
+ var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/, reIsPlainProp = /^\w*$/;
92
+ function isKey$1(value, object) {
93
+ if (isArray$2(value)) {
94
+ return false;
95
+ }
96
+ var type = typeof value;
97
+ if (type == "number" || type == "symbol" || type == "boolean" || value == null || isSymbol$2(value)) {
98
+ return true;
99
+ }
100
+ return reIsPlainProp.test(value) || !reIsDeepProp.test(value) || object != null && value in Object(object);
101
+ }
102
+ var _isKey = isKey$1;
103
+ function isObject$2(value) {
104
+ var type = typeof value;
105
+ return value != null && (type == "object" || type == "function");
106
+ }
107
+ var isObject_1 = isObject$2;
108
+ var baseGetTag = _baseGetTag, isObject$1 = isObject_1;
109
+ var asyncTag = "[object AsyncFunction]", funcTag = "[object Function]", genTag = "[object GeneratorFunction]", proxyTag = "[object Proxy]";
110
+ function isFunction$1(value) {
111
+ if (!isObject$1(value)) {
112
+ return false;
113
+ }
114
+ var tag = baseGetTag(value);
115
+ return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
116
+ }
117
+ var isFunction_1 = isFunction$1;
118
+ var root$1 = _root;
119
+ var coreJsData$1 = root$1["__core-js_shared__"];
120
+ var _coreJsData = coreJsData$1;
121
+ var coreJsData = _coreJsData;
122
+ var maskSrcKey = function() {
123
+ var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || "");
124
+ return uid ? "Symbol(src)_1." + uid : "";
125
+ }();
126
+ function isMasked$1(func) {
127
+ return !!maskSrcKey && maskSrcKey in func;
128
+ }
129
+ var _isMasked = isMasked$1;
130
+ var funcProto$1 = Function.prototype;
131
+ var funcToString$1 = funcProto$1.toString;
132
+ function toSource$1(func) {
133
+ if (func != null) {
134
+ try {
135
+ return funcToString$1.call(func);
136
+ } catch (e) {
137
+ }
138
+ try {
139
+ return func + "";
140
+ } catch (e) {
141
+ }
142
+ }
143
+ return "";
144
+ }
145
+ var _toSource = toSource$1;
146
+ var isFunction = isFunction_1, isMasked = _isMasked, isObject = isObject_1, toSource = _toSource;
147
+ var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
148
+ var reIsHostCtor = /^\[object .+?Constructor\]$/;
149
+ var funcProto = Function.prototype, objectProto$2 = Object.prototype;
150
+ var funcToString = funcProto.toString;
151
+ var hasOwnProperty$2 = objectProto$2.hasOwnProperty;
152
+ var reIsNative = RegExp(
153
+ "^" + funcToString.call(hasOwnProperty$2).replace(reRegExpChar, "\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, "$1.*?") + "$"
154
+ );
155
+ function baseIsNative$1(value) {
156
+ if (!isObject(value) || isMasked(value)) {
157
+ return false;
158
+ }
159
+ var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
160
+ return pattern.test(toSource(value));
161
+ }
162
+ var _baseIsNative = baseIsNative$1;
163
+ function getValue$1(object, key) {
164
+ return object == null ? void 0 : object[key];
165
+ }
166
+ var _getValue = getValue$1;
167
+ var baseIsNative = _baseIsNative, getValue = _getValue;
168
+ function getNative$2(object, key) {
169
+ var value = getValue(object, key);
170
+ return baseIsNative(value) ? value : void 0;
171
+ }
172
+ var _getNative = getNative$2;
173
+ var getNative$1 = _getNative;
174
+ var nativeCreate$4 = getNative$1(Object, "create");
175
+ var _nativeCreate = nativeCreate$4;
176
+ var nativeCreate$3 = _nativeCreate;
177
+ function hashClear$1() {
178
+ this.__data__ = nativeCreate$3 ? nativeCreate$3(null) : {};
179
+ this.size = 0;
180
+ }
181
+ var _hashClear = hashClear$1;
182
+ function hashDelete$1(key) {
183
+ var result = this.has(key) && delete this.__data__[key];
184
+ this.size -= result ? 1 : 0;
185
+ return result;
186
+ }
187
+ var _hashDelete = hashDelete$1;
188
+ var nativeCreate$2 = _nativeCreate;
189
+ var HASH_UNDEFINED$1 = "__lodash_hash_undefined__";
190
+ var objectProto$1 = Object.prototype;
191
+ var hasOwnProperty$1 = objectProto$1.hasOwnProperty;
192
+ function hashGet$1(key) {
193
+ var data = this.__data__;
194
+ if (nativeCreate$2) {
195
+ var result = data[key];
196
+ return result === HASH_UNDEFINED$1 ? void 0 : result;
197
+ }
198
+ return hasOwnProperty$1.call(data, key) ? data[key] : void 0;
199
+ }
200
+ var _hashGet = hashGet$1;
201
+ var nativeCreate$1 = _nativeCreate;
202
+ var objectProto = Object.prototype;
203
+ var hasOwnProperty = objectProto.hasOwnProperty;
204
+ function hashHas$1(key) {
205
+ var data = this.__data__;
206
+ return nativeCreate$1 ? data[key] !== void 0 : hasOwnProperty.call(data, key);
207
+ }
208
+ var _hashHas = hashHas$1;
209
+ var nativeCreate = _nativeCreate;
210
+ var HASH_UNDEFINED = "__lodash_hash_undefined__";
211
+ function hashSet$1(key, value) {
212
+ var data = this.__data__;
213
+ this.size += this.has(key) ? 0 : 1;
214
+ data[key] = nativeCreate && value === void 0 ? HASH_UNDEFINED : value;
215
+ return this;
216
+ }
217
+ var _hashSet = hashSet$1;
218
+ var hashClear = _hashClear, hashDelete = _hashDelete, hashGet = _hashGet, hashHas = _hashHas, hashSet = _hashSet;
219
+ function Hash$1(entries) {
220
+ var index = -1, length = entries == null ? 0 : entries.length;
221
+ this.clear();
222
+ while (++index < length) {
223
+ var entry = entries[index];
224
+ this.set(entry[0], entry[1]);
225
+ }
226
+ }
227
+ Hash$1.prototype.clear = hashClear;
228
+ Hash$1.prototype["delete"] = hashDelete;
229
+ Hash$1.prototype.get = hashGet;
230
+ Hash$1.prototype.has = hashHas;
231
+ Hash$1.prototype.set = hashSet;
232
+ var _Hash = Hash$1;
233
+ function listCacheClear$1() {
234
+ this.__data__ = [];
235
+ this.size = 0;
236
+ }
237
+ var _listCacheClear = listCacheClear$1;
238
+ function eq$1(value, other) {
239
+ return value === other || value !== value && other !== other;
240
+ }
241
+ var eq_1 = eq$1;
242
+ var eq = eq_1;
243
+ function assocIndexOf$4(array, key) {
244
+ var length = array.length;
245
+ while (length--) {
246
+ if (eq(array[length][0], key)) {
247
+ return length;
248
+ }
249
+ }
250
+ return -1;
251
+ }
252
+ var _assocIndexOf = assocIndexOf$4;
253
+ var assocIndexOf$3 = _assocIndexOf;
254
+ var arrayProto = Array.prototype;
255
+ var splice = arrayProto.splice;
256
+ function listCacheDelete$1(key) {
257
+ var data = this.__data__, index = assocIndexOf$3(data, key);
258
+ if (index < 0) {
259
+ return false;
260
+ }
261
+ var lastIndex = data.length - 1;
262
+ if (index == lastIndex) {
263
+ data.pop();
264
+ } else {
265
+ splice.call(data, index, 1);
266
+ }
267
+ --this.size;
268
+ return true;
269
+ }
270
+ var _listCacheDelete = listCacheDelete$1;
271
+ var assocIndexOf$2 = _assocIndexOf;
272
+ function listCacheGet$1(key) {
273
+ var data = this.__data__, index = assocIndexOf$2(data, key);
274
+ return index < 0 ? void 0 : data[index][1];
275
+ }
276
+ var _listCacheGet = listCacheGet$1;
277
+ var assocIndexOf$1 = _assocIndexOf;
278
+ function listCacheHas$1(key) {
279
+ return assocIndexOf$1(this.__data__, key) > -1;
280
+ }
281
+ var _listCacheHas = listCacheHas$1;
282
+ var assocIndexOf = _assocIndexOf;
283
+ function listCacheSet$1(key, value) {
284
+ var data = this.__data__, index = assocIndexOf(data, key);
285
+ if (index < 0) {
286
+ ++this.size;
287
+ data.push([key, value]);
288
+ } else {
289
+ data[index][1] = value;
290
+ }
291
+ return this;
292
+ }
293
+ var _listCacheSet = listCacheSet$1;
294
+ var listCacheClear = _listCacheClear, listCacheDelete = _listCacheDelete, listCacheGet = _listCacheGet, listCacheHas = _listCacheHas, listCacheSet = _listCacheSet;
295
+ function ListCache$1(entries) {
296
+ var index = -1, length = entries == null ? 0 : entries.length;
297
+ this.clear();
298
+ while (++index < length) {
299
+ var entry = entries[index];
300
+ this.set(entry[0], entry[1]);
301
+ }
302
+ }
303
+ ListCache$1.prototype.clear = listCacheClear;
304
+ ListCache$1.prototype["delete"] = listCacheDelete;
305
+ ListCache$1.prototype.get = listCacheGet;
306
+ ListCache$1.prototype.has = listCacheHas;
307
+ ListCache$1.prototype.set = listCacheSet;
308
+ var _ListCache = ListCache$1;
309
+ var getNative = _getNative, root = _root;
310
+ var Map$1 = getNative(root, "Map");
311
+ var _Map = Map$1;
312
+ var Hash = _Hash, ListCache = _ListCache, Map = _Map;
313
+ function mapCacheClear$1() {
314
+ this.size = 0;
315
+ this.__data__ = {
316
+ "hash": new Hash(),
317
+ "map": new (Map || ListCache)(),
318
+ "string": new Hash()
319
+ };
320
+ }
321
+ var _mapCacheClear = mapCacheClear$1;
322
+ function isKeyable$1(value) {
323
+ var type = typeof value;
324
+ return type == "string" || type == "number" || type == "symbol" || type == "boolean" ? value !== "__proto__" : value === null;
325
+ }
326
+ var _isKeyable = isKeyable$1;
327
+ var isKeyable = _isKeyable;
328
+ function getMapData$4(map, key) {
329
+ var data = map.__data__;
330
+ return isKeyable(key) ? data[typeof key == "string" ? "string" : "hash"] : data.map;
331
+ }
332
+ var _getMapData = getMapData$4;
333
+ var getMapData$3 = _getMapData;
334
+ function mapCacheDelete$1(key) {
335
+ var result = getMapData$3(this, key)["delete"](key);
336
+ this.size -= result ? 1 : 0;
337
+ return result;
338
+ }
339
+ var _mapCacheDelete = mapCacheDelete$1;
340
+ var getMapData$2 = _getMapData;
341
+ function mapCacheGet$1(key) {
342
+ return getMapData$2(this, key).get(key);
343
+ }
344
+ var _mapCacheGet = mapCacheGet$1;
345
+ var getMapData$1 = _getMapData;
346
+ function mapCacheHas$1(key) {
347
+ return getMapData$1(this, key).has(key);
348
+ }
349
+ var _mapCacheHas = mapCacheHas$1;
350
+ var getMapData = _getMapData;
351
+ function mapCacheSet$1(key, value) {
352
+ var data = getMapData(this, key), size = data.size;
353
+ data.set(key, value);
354
+ this.size += data.size == size ? 0 : 1;
355
+ return this;
356
+ }
357
+ var _mapCacheSet = mapCacheSet$1;
358
+ var mapCacheClear = _mapCacheClear, mapCacheDelete = _mapCacheDelete, mapCacheGet = _mapCacheGet, mapCacheHas = _mapCacheHas, mapCacheSet = _mapCacheSet;
359
+ function MapCache$1(entries) {
360
+ var index = -1, length = entries == null ? 0 : entries.length;
361
+ this.clear();
362
+ while (++index < length) {
363
+ var entry = entries[index];
364
+ this.set(entry[0], entry[1]);
365
+ }
366
+ }
367
+ MapCache$1.prototype.clear = mapCacheClear;
368
+ MapCache$1.prototype["delete"] = mapCacheDelete;
369
+ MapCache$1.prototype.get = mapCacheGet;
370
+ MapCache$1.prototype.has = mapCacheHas;
371
+ MapCache$1.prototype.set = mapCacheSet;
372
+ var _MapCache = MapCache$1;
373
+ var MapCache = _MapCache;
374
+ var FUNC_ERROR_TEXT = "Expected a function";
375
+ function memoize$1(func, resolver) {
376
+ if (typeof func != "function" || resolver != null && typeof resolver != "function") {
377
+ throw new TypeError(FUNC_ERROR_TEXT);
378
+ }
379
+ var memoized = function() {
380
+ var args = arguments, key = resolver ? resolver.apply(this, args) : args[0], cache = memoized.cache;
381
+ if (cache.has(key)) {
382
+ return cache.get(key);
383
+ }
384
+ var result = func.apply(this, args);
385
+ memoized.cache = cache.set(key, result) || cache;
386
+ return result;
387
+ };
388
+ memoized.cache = new (memoize$1.Cache || MapCache)();
389
+ return memoized;
390
+ }
391
+ memoize$1.Cache = MapCache;
392
+ var memoize_1 = memoize$1;
393
+ var memoize = memoize_1;
394
+ var MAX_MEMOIZE_SIZE = 500;
395
+ function memoizeCapped$1(func) {
396
+ var result = memoize(func, function(key) {
397
+ if (cache.size === MAX_MEMOIZE_SIZE) {
398
+ cache.clear();
399
+ }
400
+ return key;
401
+ });
402
+ var cache = result.cache;
403
+ return result;
404
+ }
405
+ var _memoizeCapped = memoizeCapped$1;
406
+ var memoizeCapped = _memoizeCapped;
407
+ var rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
408
+ var reEscapeChar = /\\(\\)?/g;
409
+ var stringToPath$1 = memoizeCapped(function(string) {
410
+ var result = [];
411
+ if (string.charCodeAt(0) === 46) {
412
+ result.push("");
413
+ }
414
+ string.replace(rePropName, function(match, number, quote, subString) {
415
+ result.push(quote ? subString.replace(reEscapeChar, "$1") : number || match);
416
+ });
417
+ return result;
418
+ });
419
+ var _stringToPath = stringToPath$1;
420
+ function arrayMap$1(array, iteratee) {
421
+ var index = -1, length = array == null ? 0 : array.length, result = Array(length);
422
+ while (++index < length) {
423
+ result[index] = iteratee(array[index], index, array);
424
+ }
425
+ return result;
426
+ }
427
+ var _arrayMap = arrayMap$1;
428
+ var Symbol$1 = _Symbol, arrayMap = _arrayMap, isArray$1 = isArray_1, isSymbol$1 = isSymbol_1;
429
+ var symbolProto = Symbol$1 ? Symbol$1.prototype : void 0, symbolToString = symbolProto ? symbolProto.toString : void 0;
430
+ function baseToString$1(value) {
431
+ if (typeof value == "string") {
432
+ return value;
433
+ }
434
+ if (isArray$1(value)) {
435
+ return arrayMap(value, baseToString$1) + "";
436
+ }
437
+ if (isSymbol$1(value)) {
438
+ return symbolToString ? symbolToString.call(value) : "";
439
+ }
440
+ var result = value + "";
441
+ return result == "0" && 1 / value == -Infinity ? "-0" : result;
442
+ }
443
+ var _baseToString = baseToString$1;
444
+ var baseToString = _baseToString;
445
+ function toString$1(value) {
446
+ return value == null ? "" : baseToString(value);
447
+ }
448
+ var toString_1 = toString$1;
449
+ var isArray = isArray_1, isKey = _isKey, stringToPath = _stringToPath, toString = toString_1;
450
+ function castPath$1(value, object) {
451
+ if (isArray(value)) {
452
+ return value;
453
+ }
454
+ return isKey(value, object) ? [value] : stringToPath(toString(value));
455
+ }
456
+ var _castPath = castPath$1;
457
+ var isSymbol = isSymbol_1;
458
+ function toKey$1(value) {
459
+ if (typeof value == "string" || isSymbol(value)) {
460
+ return value;
461
+ }
462
+ var result = value + "";
463
+ return result == "0" && 1 / value == -Infinity ? "-0" : result;
464
+ }
465
+ var _toKey = toKey$1;
466
+ var castPath = _castPath, toKey = _toKey;
467
+ function baseGet$1(object, path) {
468
+ path = castPath(path, object);
469
+ var index = 0, length = path.length;
470
+ while (object != null && index < length) {
471
+ object = object[toKey(path[index++])];
472
+ }
473
+ return index && index == length ? object : void 0;
474
+ }
475
+ var _baseGet = baseGet$1;
476
+ var baseGet = _baseGet;
477
+ function get(object, path, defaultValue) {
478
+ var result = object == null ? void 0 : baseGet(object, path);
479
+ return result === void 0 ? defaultValue : result;
480
+ }
481
+ var get_1 = get;
482
+ const get$1 = /* @__PURE__ */ getDefaultExportFromCjs(get_1);
25
483
  var __assign = function() {
26
484
  __assign = Object.assign || function __assign2(t) {
27
485
  for (var s, i = 1, n = arguments.length; i < n; i++) {
@@ -430,9 +888,6 @@ createFormattedComponent("formatDisplayName");
430
888
  createFormattedDateTimePartsComponent("formatDate");
431
889
  createFormattedDateTimePartsComponent("formatTime");
432
890
  const CompositeInput = (props) => {
433
- if (!props) {
434
- return null;
435
- }
436
891
  const {
437
892
  attribute,
438
893
  name,
@@ -447,128 +902,107 @@ const CompositeInput = (props) => {
447
902
  intlLabel
448
903
  } = props;
449
904
  const { formatMessage } = useIntl();
905
+ const { form } = admin.unstable_useContentManagerContext();
906
+ const { values } = form;
450
907
  const [localValue, setLocalValue] = React__namespace.default.useState(value || "");
908
+ const lastGeneratedVal = React__namespace.default.useRef(value || "");
451
909
  React__namespace.default.useEffect(() => {
452
- setLocalValue(value || "");
910
+ const validValue = value || "";
911
+ setLocalValue(validValue);
912
+ lastGeneratedVal.current = validValue;
453
913
  }, [value]);
454
914
  const fieldsConfig = attribute?.options?.fields || "";
455
915
  const separator = attribute?.options?.separator || " - ";
456
916
  const editable = attribute?.options?.editable !== false;
457
917
  const autoGenerate = attribute?.options?.autoGenerate === true;
458
- let fields = [];
459
- if (typeof fieldsConfig === "string") {
460
- fields = fieldsConfig.split("\n").map((f) => f.trim()).filter(Boolean);
461
- }
918
+ const fields = React__namespace.default.useMemo(() => {
919
+ if (typeof fieldsConfig === "string") {
920
+ return fieldsConfig.split("\n").map((f) => f.trim()).filter(Boolean);
921
+ }
922
+ return [];
923
+ }, [fieldsConfig]);
462
924
  const handleChange = (e) => {
463
925
  const newValue = e.target.value;
464
926
  setLocalValue(newValue);
927
+ lastGeneratedVal.current = newValue;
465
928
  if (onChange) {
466
929
  onChange({ target: { name, value: newValue, type: "text" } });
467
930
  }
468
931
  };
469
- const formatTimeValue = (value2) => {
470
- if (!value2) return value2;
932
+ const formatFieldValue = React__namespace.default.useCallback((val) => {
933
+ if (val === null || val === void 0) return "";
934
+ if (val instanceof Date) {
935
+ return val.toLocaleTimeString([], {
936
+ hour: "2-digit",
937
+ minute: "2-digit",
938
+ hour12: false
939
+ });
940
+ }
941
+ const stringVal = String(val);
942
+ const isoDateRegex = /^(\d{4})-(\d{2})-(\d{2})(T[\d:.]+Z?)?$/;
943
+ const dateMatch = stringVal.match(isoDateRegex);
944
+ if (dateMatch) {
945
+ const [, year, month, day] = dateMatch;
946
+ return `${month}/${day}/${year}`;
947
+ }
471
948
  const timeRegex = /^(\d{2}):(\d{2}):(\d{2})(\.\d{3})?$/;
472
- const match = value2.match(timeRegex);
473
- if (match) {
474
- return `${match[1]}:${match[2]}`;
949
+ const timeMatch = stringVal.match(timeRegex);
950
+ if (timeMatch) {
951
+ return `${timeMatch[1]}:${timeMatch[2]}`;
475
952
  }
476
- return value2;
477
- };
953
+ return stringVal;
954
+ }, []);
478
955
  const handleGenerate = React__namespace.default.useCallback(() => {
479
- const parts = [];
480
- fields.forEach((fieldPath) => {
481
- let fieldValue = null;
482
- const input = document.querySelector(
483
- `input[name="${fieldPath}"], textarea[name="${fieldPath}"]`
484
- );
485
- if (input && input.value) {
486
- fieldValue = input.value;
487
- }
488
- if (!fieldValue) {
489
- const select = document.querySelector(`select[name="${fieldPath}"]`);
490
- if (select && select.value) {
491
- fieldValue = select.value;
492
- }
493
- }
494
- if (!fieldValue) {
495
- const combobox = document.querySelector(
496
- `div[role="combobox"][name="${fieldPath}"]`
497
- );
498
- if (combobox) {
499
- const selectedText = combobox.textContent?.trim();
500
- if (selectedText && selectedText !== "Select..." && selectedText !== "") {
501
- fieldValue = selectedText;
502
- }
956
+ const parts = name.split(".");
957
+ parts.pop();
958
+ const parentPath = parts.join(".");
959
+ const generatedParts = [];
960
+ fields.forEach((fieldName) => {
961
+ const fullPath = parentPath ? `${parentPath}.${fieldName}` : fieldName;
962
+ let rawValue = get$1(values, fullPath);
963
+ if (rawValue !== null && rawValue !== void 0) {
964
+ let stringValue = "";
965
+ if (typeof rawValue === "object" && !(rawValue instanceof Date)) {
966
+ if (rawValue.name) stringValue = String(rawValue.name);
967
+ else if (rawValue.title) stringValue = String(rawValue.title);
968
+ else if (rawValue.label) stringValue = String(rawValue.label);
969
+ } else {
970
+ stringValue = formatFieldValue(rawValue);
503
971
  }
504
- }
505
- if (!fieldValue) {
506
- const fieldById = document.getElementById(fieldPath);
507
- if (fieldById) {
508
- if (fieldById.tagName === "SELECT") {
509
- fieldValue = fieldById.value;
510
- } else if (fieldById.value) {
511
- fieldValue = fieldById.value;
512
- }
972
+ if (stringValue) {
973
+ generatedParts.push(stringValue);
513
974
  }
514
975
  }
515
- if (fieldValue) {
516
- fieldValue = formatTimeValue(fieldValue);
517
- parts.push(fieldValue);
518
- }
519
976
  });
520
977
  const cleanSeparator = separator.trim();
521
- const result = parts.join(` ${cleanSeparator} `).trim();
522
- setLocalValue(result);
523
- if (onChange) {
524
- onChange({ target: { name, value: result, type: "text" } });
978
+ const result = generatedParts.join(` ${cleanSeparator} `).trim();
979
+ if (result !== lastGeneratedVal.current) {
980
+ setLocalValue(result);
981
+ lastGeneratedVal.current = result;
982
+ if (onChange) {
983
+ onChange({ target: { name, value: result, type: "text" } });
984
+ }
525
985
  }
526
- }, [fields, separator, onChange, name]);
986
+ }, [fields, separator, onChange, name, values, formatFieldValue]);
987
+ const watchedValues = React__namespace.default.useMemo(() => {
988
+ const parts = name.split(".");
989
+ parts.pop();
990
+ const parentPath = parts.join(".");
991
+ return fields.map((fieldName) => {
992
+ const fullPath = parentPath ? `${parentPath}.${fieldName}` : fieldName;
993
+ return get$1(values, fullPath);
994
+ });
995
+ }, [fields, name, values]);
527
996
  React__namespace.default.useEffect(() => {
528
997
  if (!autoGenerate || fields.length === 0) return;
529
- let debounceTimer;
530
- const handleFieldChange = () => {
531
- clearTimeout(debounceTimer);
532
- debounceTimer = setTimeout(() => {
533
- handleGenerate();
534
- }, 300);
535
- };
536
- const listeners = [];
537
- const observers = [];
538
- fields.forEach((fieldPath) => {
539
- const elements = document.querySelectorAll(
540
- `input[name="${fieldPath}"], textarea[name="${fieldPath}"], select[name="${fieldPath}"]`
541
- );
542
- elements.forEach((element) => {
543
- element.addEventListener("change", handleFieldChange);
544
- element.addEventListener("input", handleFieldChange);
545
- listeners.push({ element, handler: handleFieldChange });
546
- });
547
- const combobox = document.querySelector(
548
- `div[role="combobox"][name="${fieldPath}"]`
549
- );
550
- if (combobox) {
551
- const observer = new MutationObserver(handleFieldChange);
552
- observer.observe(combobox, {
553
- childList: true,
554
- subtree: true,
555
- characterData: true
556
- });
557
- observers.push(observer);
558
- combobox.addEventListener("click", handleFieldChange);
559
- listeners.push({ element: combobox, handler: handleFieldChange });
560
- }
561
- });
562
- return () => {
563
- clearTimeout(debounceTimer);
564
- listeners.forEach(({ element, handler }) => {
565
- element.removeEventListener("change", handler);
566
- element.removeEventListener("input", handler);
567
- element.removeEventListener("click", handler);
568
- });
569
- observers.forEach((observer) => observer.disconnect());
570
- };
571
- }, [autoGenerate, fields, handleGenerate]);
998
+ const timeoutId = setTimeout(() => {
999
+ handleGenerate();
1000
+ }, 300);
1001
+ return () => clearTimeout(timeoutId);
1002
+ }, [autoGenerate, fields, handleGenerate, watchedValues, name]);
1003
+ if (!props) {
1004
+ return null;
1005
+ }
572
1006
  return /* @__PURE__ */ jsxRuntime.jsx(
573
1007
  designSystem.Field.Root,
574
1008
  {