@tunghtml/strapi-plugin-composite-field 1.1.6 → 1.1.9

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