@tunghtml/strapi-plugin-composite-field 1.0.0

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/README.md ADDED
@@ -0,0 +1,150 @@
1
+ # Strapi Plugin Composite Field
2
+
3
+ A Strapi v5 plugin that creates composite display fields by combining multiple text fields.
4
+
5
+ ![Composite Field Demo](https://img.shields.io/badge/Strapi-v5-blue)
6
+ ![npm version](https://img.shields.io/npm/v/@tunghtml/strapi-plugin-composite-field)
7
+ ![License](https://img.shields.io/npm/l/@tunghtml/strapi-plugin-composite-field)
8
+
9
+ ## Features
10
+
11
+ - 🔗 **Multiple Fields**: Combine any text/string fields
12
+ - 🔄 **Generate Button**: Click icon to generate composite value
13
+ - 📝 **Easy Config**: Textarea input (one field per line)
14
+ - ⚙️ **Custom Separator**: Configure separator (default: " - ")
15
+ - ✨ **Auto Spacing**: Automatically adds spaces around separator
16
+ - 🎨 **Clean UI**: Matches Strapi admin design system
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ npm install @tunghtml/strapi-plugin-composite-field
22
+ ```
23
+
24
+ Then add the plugin to your `config/plugins.js`:
25
+
26
+ ```javascript
27
+ module.exports = {
28
+ // ...
29
+ "composite-field": {
30
+ enabled: true,
31
+ },
32
+ };
33
+ ```
34
+
35
+ Rebuild your admin panel:
36
+
37
+ ```bash
38
+ npm run build
39
+ npm run develop
40
+ ```
41
+
42
+ ## Usage
43
+
44
+ ### 1. Add Custom Field
45
+
46
+ - Go to **Content-Type Builder**
47
+ - Select your content type (e.g., Corp Rep List)
48
+ - Click **"Add another field"**
49
+ - Choose **"Composite"** from custom fields
50
+ - Name it (e.g., `displayName`)
51
+
52
+ ### 2. Configure Fields
53
+
54
+ **Fields to combine** (one per line):
55
+
56
+ ```
57
+ salutation
58
+ firstName
59
+ lastName
60
+ email
61
+ ```
62
+
63
+ **Separator** (optional, default: " - "):
64
+
65
+ ```
66
+ -
67
+ ```
68
+
69
+ ### 3. Generate Value
70
+
71
+ - Fill in source fields (firstName, lastName, email, etc.)
72
+ - Click the **Play icon** button
73
+ - Composite field populates automatically with proper spacing!
74
+
75
+ ## Examples
76
+
77
+ ### Representative Display Name
78
+
79
+ ```
80
+ Fields:
81
+ salutation
82
+ firstName
83
+ lastName
84
+ email
85
+
86
+ Separator: -
87
+
88
+ Result: Mr. - Tung - Le - tung@example.com
89
+ ```
90
+
91
+ ### Product SKU
92
+
93
+ ```
94
+ Fields:
95
+ category
96
+ brand
97
+ model
98
+
99
+ Separator: -
100
+
101
+ Result: Electronics - Apple - iPhone15
102
+ ```
103
+
104
+ ### Full Name
105
+
106
+ ```
107
+ Fields:
108
+ firstName
109
+ lastName
110
+
111
+ Separator: (space)
112
+
113
+ Result: Tung Le
114
+ ```
115
+
116
+ ## Configuration Options
117
+
118
+ | Option | Type | Default | Description |
119
+ | ----------- | -------- | ------- | ------------------------------------- |
120
+ | `fields` | textarea | - | Field names to combine (one per line) |
121
+ | `separator` | text | `" - "` | Separator between fields |
122
+
123
+ ## Notes
124
+
125
+ - Only combines simple text/string fields
126
+ - Automatically adds spaces around separator for clean output
127
+ - Empty fields are skipped automatically
128
+ - Relation fields are not supported (use simple fields only)
129
+
130
+ ## Requirements
131
+
132
+ - Strapi v5.0.0 or higher
133
+ - Node.js 18.x or higher
134
+
135
+ ## Contributing
136
+
137
+ Contributions are welcome! Please feel free to submit a Pull Request.
138
+
139
+ ## Issues
140
+
141
+ If you encounter any issues, please report them at:
142
+ https://github.com/finnwasabi/strapi-plugin-composite-field/issues
143
+
144
+ ## License
145
+
146
+ MIT
147
+
148
+ ## Author
149
+
150
+ Tung Le - [@finnwasabi](https://github.com/finnwasabi)
@@ -0,0 +1,560 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const jsxRuntime = require("react/jsx-runtime");
4
+ const React = require("react");
5
+ const designSystem = require("@strapi/design-system");
6
+ const icons = require("@strapi/icons");
7
+ function _interopNamespace(e) {
8
+ if (e && e.__esModule) return e;
9
+ const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
10
+ if (e) {
11
+ for (const k in e) {
12
+ if (k !== "default") {
13
+ const d = Object.getOwnPropertyDescriptor(e, k);
14
+ Object.defineProperty(n, k, d.get ? d : {
15
+ enumerable: true,
16
+ get: () => e[k]
17
+ });
18
+ }
19
+ }
20
+ }
21
+ n.default = e;
22
+ return Object.freeze(n);
23
+ }
24
+ const React__namespace = /* @__PURE__ */ _interopNamespace(React);
25
+ var __assign = function() {
26
+ __assign = Object.assign || function __assign2(t) {
27
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
28
+ s = arguments[i];
29
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
30
+ }
31
+ return t;
32
+ };
33
+ return __assign.apply(this, arguments);
34
+ };
35
+ function __rest(s, e) {
36
+ var t = {};
37
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
38
+ t[p] = s[p];
39
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
40
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
41
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
42
+ t[p[i]] = s[p[i]];
43
+ }
44
+ return t;
45
+ }
46
+ typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
47
+ var e = new Error(message);
48
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
49
+ };
50
+ var reactIs$1 = { exports: {} };
51
+ var reactIs_production_min = {};
52
+ /** @license React v16.13.1
53
+ * react-is.production.min.js
54
+ *
55
+ * Copyright (c) Facebook, Inc. and its affiliates.
56
+ *
57
+ * This source code is licensed under the MIT license found in the
58
+ * LICENSE file in the root directory of this source tree.
59
+ */
60
+ var hasRequiredReactIs_production_min;
61
+ function requireReactIs_production_min() {
62
+ if (hasRequiredReactIs_production_min) return reactIs_production_min;
63
+ hasRequiredReactIs_production_min = 1;
64
+ var b = "function" === typeof Symbol && Symbol.for, c = b ? Symbol.for("react.element") : 60103, d = b ? Symbol.for("react.portal") : 60106, e = b ? Symbol.for("react.fragment") : 60107, f = b ? Symbol.for("react.strict_mode") : 60108, g = b ? Symbol.for("react.profiler") : 60114, h = b ? Symbol.for("react.provider") : 60109, k = b ? Symbol.for("react.context") : 60110, l = b ? Symbol.for("react.async_mode") : 60111, m = b ? Symbol.for("react.concurrent_mode") : 60111, n = b ? Symbol.for("react.forward_ref") : 60112, p = b ? Symbol.for("react.suspense") : 60113, q = b ? Symbol.for("react.suspense_list") : 60120, r = b ? Symbol.for("react.memo") : 60115, t = b ? Symbol.for("react.lazy") : 60116, v = b ? Symbol.for("react.block") : 60121, w = b ? Symbol.for("react.fundamental") : 60117, x = b ? Symbol.for("react.responder") : 60118, y = b ? Symbol.for("react.scope") : 60119;
65
+ function z(a) {
66
+ if ("object" === typeof a && null !== a) {
67
+ var u = a.$$typeof;
68
+ switch (u) {
69
+ case c:
70
+ switch (a = a.type, a) {
71
+ case l:
72
+ case m:
73
+ case e:
74
+ case g:
75
+ case f:
76
+ case p:
77
+ return a;
78
+ default:
79
+ switch (a = a && a.$$typeof, a) {
80
+ case k:
81
+ case n:
82
+ case t:
83
+ case r:
84
+ case h:
85
+ return a;
86
+ default:
87
+ return u;
88
+ }
89
+ }
90
+ case d:
91
+ return u;
92
+ }
93
+ }
94
+ }
95
+ function A(a) {
96
+ return z(a) === m;
97
+ }
98
+ reactIs_production_min.AsyncMode = l;
99
+ reactIs_production_min.ConcurrentMode = m;
100
+ reactIs_production_min.ContextConsumer = k;
101
+ reactIs_production_min.ContextProvider = h;
102
+ reactIs_production_min.Element = c;
103
+ reactIs_production_min.ForwardRef = n;
104
+ reactIs_production_min.Fragment = e;
105
+ reactIs_production_min.Lazy = t;
106
+ reactIs_production_min.Memo = r;
107
+ reactIs_production_min.Portal = d;
108
+ reactIs_production_min.Profiler = g;
109
+ reactIs_production_min.StrictMode = f;
110
+ reactIs_production_min.Suspense = p;
111
+ reactIs_production_min.isAsyncMode = function(a) {
112
+ return A(a) || z(a) === l;
113
+ };
114
+ reactIs_production_min.isConcurrentMode = A;
115
+ reactIs_production_min.isContextConsumer = function(a) {
116
+ return z(a) === k;
117
+ };
118
+ reactIs_production_min.isContextProvider = function(a) {
119
+ return z(a) === h;
120
+ };
121
+ reactIs_production_min.isElement = function(a) {
122
+ return "object" === typeof a && null !== a && a.$$typeof === c;
123
+ };
124
+ reactIs_production_min.isForwardRef = function(a) {
125
+ return z(a) === n;
126
+ };
127
+ reactIs_production_min.isFragment = function(a) {
128
+ return z(a) === e;
129
+ };
130
+ reactIs_production_min.isLazy = function(a) {
131
+ return z(a) === t;
132
+ };
133
+ reactIs_production_min.isMemo = function(a) {
134
+ return z(a) === r;
135
+ };
136
+ reactIs_production_min.isPortal = function(a) {
137
+ return z(a) === d;
138
+ };
139
+ reactIs_production_min.isProfiler = function(a) {
140
+ return z(a) === g;
141
+ };
142
+ reactIs_production_min.isStrictMode = function(a) {
143
+ return z(a) === f;
144
+ };
145
+ reactIs_production_min.isSuspense = function(a) {
146
+ return z(a) === p;
147
+ };
148
+ reactIs_production_min.isValidElementType = function(a) {
149
+ return "string" === typeof a || "function" === typeof a || a === e || a === m || a === g || a === f || a === p || a === q || "object" === typeof a && null !== a && (a.$$typeof === t || a.$$typeof === r || a.$$typeof === h || a.$$typeof === k || a.$$typeof === n || a.$$typeof === w || a.$$typeof === x || a.$$typeof === y || a.$$typeof === v);
150
+ };
151
+ reactIs_production_min.typeOf = z;
152
+ return reactIs_production_min;
153
+ }
154
+ var reactIs_development = {};
155
+ /** @license React v16.13.1
156
+ * react-is.development.js
157
+ *
158
+ * Copyright (c) Facebook, Inc. and its affiliates.
159
+ *
160
+ * This source code is licensed under the MIT license found in the
161
+ * LICENSE file in the root directory of this source tree.
162
+ */
163
+ var hasRequiredReactIs_development;
164
+ function requireReactIs_development() {
165
+ if (hasRequiredReactIs_development) return reactIs_development;
166
+ hasRequiredReactIs_development = 1;
167
+ if (process.env.NODE_ENV !== "production") {
168
+ (function() {
169
+ var hasSymbol = typeof Symbol === "function" && Symbol.for;
170
+ var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for("react.element") : 60103;
171
+ var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for("react.portal") : 60106;
172
+ var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for("react.fragment") : 60107;
173
+ var REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for("react.strict_mode") : 60108;
174
+ var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for("react.profiler") : 60114;
175
+ var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for("react.provider") : 60109;
176
+ var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for("react.context") : 60110;
177
+ var REACT_ASYNC_MODE_TYPE = hasSymbol ? Symbol.for("react.async_mode") : 60111;
178
+ var REACT_CONCURRENT_MODE_TYPE = hasSymbol ? Symbol.for("react.concurrent_mode") : 60111;
179
+ var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for("react.forward_ref") : 60112;
180
+ var REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for("react.suspense") : 60113;
181
+ var REACT_SUSPENSE_LIST_TYPE = hasSymbol ? Symbol.for("react.suspense_list") : 60120;
182
+ var REACT_MEMO_TYPE = hasSymbol ? Symbol.for("react.memo") : 60115;
183
+ var REACT_LAZY_TYPE = hasSymbol ? Symbol.for("react.lazy") : 60116;
184
+ var REACT_BLOCK_TYPE = hasSymbol ? Symbol.for("react.block") : 60121;
185
+ var REACT_FUNDAMENTAL_TYPE = hasSymbol ? Symbol.for("react.fundamental") : 60117;
186
+ var REACT_RESPONDER_TYPE = hasSymbol ? Symbol.for("react.responder") : 60118;
187
+ var REACT_SCOPE_TYPE = hasSymbol ? Symbol.for("react.scope") : 60119;
188
+ function isValidElementType(type) {
189
+ return typeof type === "string" || typeof type === "function" || // Note: its typeof might be other than 'symbol' or 'number' if it's a polyfill.
190
+ type === REACT_FRAGMENT_TYPE || type === REACT_CONCURRENT_MODE_TYPE || type === REACT_PROFILER_TYPE || type === REACT_STRICT_MODE_TYPE || type === REACT_SUSPENSE_TYPE || type === REACT_SUSPENSE_LIST_TYPE || typeof type === "object" && type !== null && (type.$$typeof === REACT_LAZY_TYPE || type.$$typeof === REACT_MEMO_TYPE || type.$$typeof === REACT_PROVIDER_TYPE || type.$$typeof === REACT_CONTEXT_TYPE || type.$$typeof === REACT_FORWARD_REF_TYPE || type.$$typeof === REACT_FUNDAMENTAL_TYPE || type.$$typeof === REACT_RESPONDER_TYPE || type.$$typeof === REACT_SCOPE_TYPE || type.$$typeof === REACT_BLOCK_TYPE);
191
+ }
192
+ function typeOf(object) {
193
+ if (typeof object === "object" && object !== null) {
194
+ var $$typeof = object.$$typeof;
195
+ switch ($$typeof) {
196
+ case REACT_ELEMENT_TYPE:
197
+ var type = object.type;
198
+ switch (type) {
199
+ case REACT_ASYNC_MODE_TYPE:
200
+ case REACT_CONCURRENT_MODE_TYPE:
201
+ case REACT_FRAGMENT_TYPE:
202
+ case REACT_PROFILER_TYPE:
203
+ case REACT_STRICT_MODE_TYPE:
204
+ case REACT_SUSPENSE_TYPE:
205
+ return type;
206
+ default:
207
+ var $$typeofType = type && type.$$typeof;
208
+ switch ($$typeofType) {
209
+ case REACT_CONTEXT_TYPE:
210
+ case REACT_FORWARD_REF_TYPE:
211
+ case REACT_LAZY_TYPE:
212
+ case REACT_MEMO_TYPE:
213
+ case REACT_PROVIDER_TYPE:
214
+ return $$typeofType;
215
+ default:
216
+ return $$typeof;
217
+ }
218
+ }
219
+ case REACT_PORTAL_TYPE:
220
+ return $$typeof;
221
+ }
222
+ }
223
+ return void 0;
224
+ }
225
+ var AsyncMode = REACT_ASYNC_MODE_TYPE;
226
+ var ConcurrentMode = REACT_CONCURRENT_MODE_TYPE;
227
+ var ContextConsumer = REACT_CONTEXT_TYPE;
228
+ var ContextProvider = REACT_PROVIDER_TYPE;
229
+ var Element = REACT_ELEMENT_TYPE;
230
+ var ForwardRef = REACT_FORWARD_REF_TYPE;
231
+ var Fragment = REACT_FRAGMENT_TYPE;
232
+ var Lazy = REACT_LAZY_TYPE;
233
+ var Memo = REACT_MEMO_TYPE;
234
+ var Portal = REACT_PORTAL_TYPE;
235
+ var Profiler = REACT_PROFILER_TYPE;
236
+ var StrictMode = REACT_STRICT_MODE_TYPE;
237
+ var Suspense = REACT_SUSPENSE_TYPE;
238
+ var hasWarnedAboutDeprecatedIsAsyncMode = false;
239
+ function isAsyncMode(object) {
240
+ {
241
+ if (!hasWarnedAboutDeprecatedIsAsyncMode) {
242
+ hasWarnedAboutDeprecatedIsAsyncMode = true;
243
+ console["warn"]("The ReactIs.isAsyncMode() alias has been deprecated, and will be removed in React 17+. Update your code to use ReactIs.isConcurrentMode() instead. It has the exact same API.");
244
+ }
245
+ }
246
+ return isConcurrentMode(object) || typeOf(object) === REACT_ASYNC_MODE_TYPE;
247
+ }
248
+ function isConcurrentMode(object) {
249
+ return typeOf(object) === REACT_CONCURRENT_MODE_TYPE;
250
+ }
251
+ function isContextConsumer(object) {
252
+ return typeOf(object) === REACT_CONTEXT_TYPE;
253
+ }
254
+ function isContextProvider(object) {
255
+ return typeOf(object) === REACT_PROVIDER_TYPE;
256
+ }
257
+ function isElement(object) {
258
+ return typeof object === "object" && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
259
+ }
260
+ function isForwardRef(object) {
261
+ return typeOf(object) === REACT_FORWARD_REF_TYPE;
262
+ }
263
+ function isFragment(object) {
264
+ return typeOf(object) === REACT_FRAGMENT_TYPE;
265
+ }
266
+ function isLazy(object) {
267
+ return typeOf(object) === REACT_LAZY_TYPE;
268
+ }
269
+ function isMemo(object) {
270
+ return typeOf(object) === REACT_MEMO_TYPE;
271
+ }
272
+ function isPortal(object) {
273
+ return typeOf(object) === REACT_PORTAL_TYPE;
274
+ }
275
+ function isProfiler(object) {
276
+ return typeOf(object) === REACT_PROFILER_TYPE;
277
+ }
278
+ function isStrictMode(object) {
279
+ return typeOf(object) === REACT_STRICT_MODE_TYPE;
280
+ }
281
+ function isSuspense(object) {
282
+ return typeOf(object) === REACT_SUSPENSE_TYPE;
283
+ }
284
+ reactIs_development.AsyncMode = AsyncMode;
285
+ reactIs_development.ConcurrentMode = ConcurrentMode;
286
+ reactIs_development.ContextConsumer = ContextConsumer;
287
+ reactIs_development.ContextProvider = ContextProvider;
288
+ reactIs_development.Element = Element;
289
+ reactIs_development.ForwardRef = ForwardRef;
290
+ reactIs_development.Fragment = Fragment;
291
+ reactIs_development.Lazy = Lazy;
292
+ reactIs_development.Memo = Memo;
293
+ reactIs_development.Portal = Portal;
294
+ reactIs_development.Profiler = Profiler;
295
+ reactIs_development.StrictMode = StrictMode;
296
+ reactIs_development.Suspense = Suspense;
297
+ reactIs_development.isAsyncMode = isAsyncMode;
298
+ reactIs_development.isConcurrentMode = isConcurrentMode;
299
+ reactIs_development.isContextConsumer = isContextConsumer;
300
+ reactIs_development.isContextProvider = isContextProvider;
301
+ reactIs_development.isElement = isElement;
302
+ reactIs_development.isForwardRef = isForwardRef;
303
+ reactIs_development.isFragment = isFragment;
304
+ reactIs_development.isLazy = isLazy;
305
+ reactIs_development.isMemo = isMemo;
306
+ reactIs_development.isPortal = isPortal;
307
+ reactIs_development.isProfiler = isProfiler;
308
+ reactIs_development.isStrictMode = isStrictMode;
309
+ reactIs_development.isSuspense = isSuspense;
310
+ reactIs_development.isValidElementType = isValidElementType;
311
+ reactIs_development.typeOf = typeOf;
312
+ })();
313
+ }
314
+ return reactIs_development;
315
+ }
316
+ if (process.env.NODE_ENV === "production") {
317
+ reactIs$1.exports = requireReactIs_production_min();
318
+ } else {
319
+ reactIs$1.exports = requireReactIs_development();
320
+ }
321
+ var reactIsExports = reactIs$1.exports;
322
+ var reactIs = reactIsExports;
323
+ var FORWARD_REF_STATICS = {
324
+ "$$typeof": true,
325
+ render: true,
326
+ defaultProps: true,
327
+ displayName: true,
328
+ propTypes: true
329
+ };
330
+ var MEMO_STATICS = {
331
+ "$$typeof": true,
332
+ compare: true,
333
+ defaultProps: true,
334
+ displayName: true,
335
+ propTypes: true,
336
+ type: true
337
+ };
338
+ var TYPE_STATICS = {};
339
+ TYPE_STATICS[reactIs.ForwardRef] = FORWARD_REF_STATICS;
340
+ TYPE_STATICS[reactIs.Memo] = MEMO_STATICS;
341
+ function invariant(condition, message, Err) {
342
+ if (Err === void 0) {
343
+ Err = Error;
344
+ }
345
+ if (!condition) {
346
+ throw new Err(message);
347
+ }
348
+ }
349
+ var defaultErrorHandler = function(error) {
350
+ if (process.env.NODE_ENV !== "production") {
351
+ console.error(error);
352
+ }
353
+ };
354
+ var defaultWarnHandler = function(warning) {
355
+ if (process.env.NODE_ENV !== "production") {
356
+ console.warn(warning);
357
+ }
358
+ };
359
+ var DEFAULT_INTL_CONFIG = {
360
+ formats: {},
361
+ messages: {},
362
+ timeZone: void 0,
363
+ defaultLocale: "en",
364
+ defaultFormats: {},
365
+ fallbackOnEmptyString: true,
366
+ onError: defaultErrorHandler,
367
+ onWarn: defaultWarnHandler
368
+ };
369
+ function invariantIntlContext(intl) {
370
+ invariant(intl, "[React Intl] Could not find required `intl` object. <IntlProvider> needs to exist in the component ancestry.");
371
+ }
372
+ __assign(__assign({}, DEFAULT_INTL_CONFIG), { textComponent: React__namespace.Fragment });
373
+ var IntlContext = typeof window !== "undefined" && !window.__REACT_INTL_BYPASS_GLOBAL_CONTEXT__ ? window.__REACT_INTL_CONTEXT__ || (window.__REACT_INTL_CONTEXT__ = React__namespace.createContext(null)) : React__namespace.createContext(null);
374
+ IntlContext.Consumer;
375
+ IntlContext.Provider;
376
+ var Context = IntlContext;
377
+ function useIntl() {
378
+ var intl = React__namespace.useContext(Context);
379
+ invariantIntlContext(intl);
380
+ return intl;
381
+ }
382
+ var DisplayName;
383
+ (function(DisplayName2) {
384
+ DisplayName2["formatDate"] = "FormattedDate";
385
+ DisplayName2["formatTime"] = "FormattedTime";
386
+ DisplayName2["formatNumber"] = "FormattedNumber";
387
+ DisplayName2["formatList"] = "FormattedList";
388
+ DisplayName2["formatDisplayName"] = "FormattedDisplayName";
389
+ })(DisplayName || (DisplayName = {}));
390
+ var DisplayNameParts;
391
+ (function(DisplayNameParts2) {
392
+ DisplayNameParts2["formatDate"] = "FormattedDateParts";
393
+ DisplayNameParts2["formatTime"] = "FormattedTimeParts";
394
+ DisplayNameParts2["formatNumber"] = "FormattedNumberParts";
395
+ DisplayNameParts2["formatList"] = "FormattedListParts";
396
+ })(DisplayNameParts || (DisplayNameParts = {}));
397
+ function createFormattedDateTimePartsComponent(name) {
398
+ var ComponentParts = function(props) {
399
+ var intl = useIntl();
400
+ var value = props.value, children = props.children, formatProps = __rest(props, ["value", "children"]);
401
+ var date = typeof value === "string" ? new Date(value || 0) : value;
402
+ var formattedParts = name === "formatDate" ? intl.formatDateToParts(date, formatProps) : intl.formatTimeToParts(date, formatProps);
403
+ return children(formattedParts);
404
+ };
405
+ ComponentParts.displayName = DisplayNameParts[name];
406
+ return ComponentParts;
407
+ }
408
+ function createFormattedComponent(name) {
409
+ var Component = function(props) {
410
+ var intl = useIntl();
411
+ var value = props.value, children = props.children, formatProps = __rest(
412
+ props,
413
+ ["value", "children"]
414
+ );
415
+ var formattedValue = intl[name](value, formatProps);
416
+ if (typeof children === "function") {
417
+ return children(formattedValue);
418
+ }
419
+ var Text = intl.textComponent || React__namespace.Fragment;
420
+ return React__namespace.createElement(Text, null, formattedValue);
421
+ };
422
+ Component.displayName = DisplayName[name];
423
+ return Component;
424
+ }
425
+ createFormattedComponent("formatDate");
426
+ createFormattedComponent("formatTime");
427
+ createFormattedComponent("formatNumber");
428
+ createFormattedComponent("formatList");
429
+ createFormattedComponent("formatDisplayName");
430
+ createFormattedDateTimePartsComponent("formatDate");
431
+ createFormattedDateTimePartsComponent("formatTime");
432
+ const CompositeInput = (props) => {
433
+ if (!props) {
434
+ return null;
435
+ }
436
+ const {
437
+ attribute,
438
+ name,
439
+ value,
440
+ onChange,
441
+ disabled,
442
+ required,
443
+ error,
444
+ description,
445
+ labelAction,
446
+ label,
447
+ intlLabel
448
+ } = props;
449
+ const { formatMessage } = useIntl();
450
+ const [localValue, setLocalValue] = React__namespace.default.useState(value || "");
451
+ React__namespace.default.useEffect(() => {
452
+ setLocalValue(value || "");
453
+ }, [value]);
454
+ const fieldsConfig = attribute?.options?.fields || "";
455
+ const separator = attribute?.options?.separator || " - ";
456
+ let fields = [];
457
+ if (typeof fieldsConfig === "string") {
458
+ fields = fieldsConfig.split("\n").map((f) => f.trim()).filter(Boolean);
459
+ }
460
+ const handleChange = (e) => {
461
+ const newValue = e.target.value;
462
+ setLocalValue(newValue);
463
+ if (onChange) {
464
+ onChange({ target: { name, value: newValue, type: "text" } });
465
+ }
466
+ };
467
+ const handleGenerate = () => {
468
+ const formData = {};
469
+ fields.forEach((fieldPath) => {
470
+ const input = document.querySelector(
471
+ `input[name="${fieldPath}"], textarea[name="${fieldPath}"], select[name="${fieldPath}"]`
472
+ );
473
+ if (input && input.value) {
474
+ formData[fieldPath] = input.value;
475
+ }
476
+ });
477
+ const parts = [];
478
+ fields.forEach((fieldPath) => {
479
+ const fieldValue = formData[fieldPath];
480
+ if (fieldValue) {
481
+ parts.push(fieldValue);
482
+ }
483
+ });
484
+ const cleanSeparator = separator.trim();
485
+ const result = parts.join(` ${cleanSeparator} `).trim();
486
+ setLocalValue(result);
487
+ if (onChange) {
488
+ onChange({ target: { name, value: result, type: "text" } });
489
+ }
490
+ };
491
+ return /* @__PURE__ */ jsxRuntime.jsx(
492
+ designSystem.Field.Root,
493
+ {
494
+ name,
495
+ id: name,
496
+ error,
497
+ hint: description?.id ? formatMessage(description) : description,
498
+ required,
499
+ children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 1, children: [
500
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { action: labelAction, children: label || intlLabel?.defaultMessage || name }) }),
501
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { position: "relative" }, children: [
502
+ /* @__PURE__ */ jsxRuntime.jsx(
503
+ designSystem.Field.Input,
504
+ {
505
+ type: "text",
506
+ value: localValue,
507
+ onChange: handleChange,
508
+ disabled,
509
+ placeholder: "Click button to generate",
510
+ style: { paddingRight: "40px" }
511
+ }
512
+ ),
513
+ /* @__PURE__ */ jsxRuntime.jsx(
514
+ "div",
515
+ {
516
+ style: {
517
+ position: "absolute",
518
+ right: "8px",
519
+ top: "50%",
520
+ transform: "translateY(-50%)",
521
+ display: "flex",
522
+ alignItems: "center",
523
+ justifyContent: "center"
524
+ },
525
+ children: /* @__PURE__ */ jsxRuntime.jsx(
526
+ designSystem.Button,
527
+ {
528
+ type: "button",
529
+ onClick: handleGenerate,
530
+ disabled: disabled || fields.length === 0,
531
+ variant: "tertiary",
532
+ "aria-label": "Generate composite value",
533
+ style: {
534
+ width: "28px",
535
+ height: "28px",
536
+ padding: "0",
537
+ minWidth: "auto",
538
+ border: "none",
539
+ background: "transparent",
540
+ display: "flex",
541
+ alignItems: "center",
542
+ justifyContent: "center",
543
+ color: "#8e8ea9"
544
+ },
545
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.Play, { style: { width: "14px", height: "14px" } })
546
+ }
547
+ )
548
+ }
549
+ )
550
+ ] }),
551
+ fields.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Hint, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: [
552
+ "Combines: ",
553
+ fields.join(", ")
554
+ ] }) }),
555
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Error, {})
556
+ ] })
557
+ }
558
+ );
559
+ };
560
+ exports.default = CompositeInput;