@tunghtml/strapi-plugin-composite-field 1.1.1 → 1.1.3
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.
|
@@ -4,7 +4,6 @@ const jsxRuntime = require("react/jsx-runtime");
|
|
|
4
4
|
const React = require("react");
|
|
5
5
|
const designSystem = require("@strapi/design-system");
|
|
6
6
|
const icons = require("@strapi/icons");
|
|
7
|
-
const admin = require("@strapi/strapi/admin");
|
|
8
7
|
function _interopNamespace(e) {
|
|
9
8
|
if (e && e.__esModule) return e;
|
|
10
9
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
@@ -447,7 +446,6 @@ const CompositeInput = (props) => {
|
|
|
447
446
|
label,
|
|
448
447
|
intlLabel
|
|
449
448
|
} = props;
|
|
450
|
-
const { modifiedData } = admin.useCMEditViewDataManager();
|
|
451
449
|
const { formatMessage } = useIntl();
|
|
452
450
|
const [localValue, setLocalValue] = React__namespace.default.useState(value || "");
|
|
453
451
|
React__namespace.default.useEffect(() => {
|
|
@@ -471,8 +469,42 @@ const CompositeInput = (props) => {
|
|
|
471
469
|
const handleGenerate = React__namespace.default.useCallback(() => {
|
|
472
470
|
const parts = [];
|
|
473
471
|
fields.forEach((fieldPath) => {
|
|
474
|
-
|
|
475
|
-
|
|
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 labels = document.querySelectorAll("label");
|
|
487
|
+
for (const labelEl of labels) {
|
|
488
|
+
const labelText = labelEl.textContent?.trim().toLowerCase();
|
|
489
|
+
const fieldName = fieldPath.toLowerCase();
|
|
490
|
+
if (labelText === fieldName || labelText.includes(fieldName)) {
|
|
491
|
+
const container = labelEl.closest('[role="group"]') || labelEl.parentElement;
|
|
492
|
+
if (container) {
|
|
493
|
+
const combobox = container.querySelector(
|
|
494
|
+
'button[role="combobox"]'
|
|
495
|
+
);
|
|
496
|
+
if (combobox) {
|
|
497
|
+
const selectedText = combobox.textContent?.trim();
|
|
498
|
+
if (selectedText && selectedText !== "Select..." && selectedText !== "") {
|
|
499
|
+
fieldValue = selectedText;
|
|
500
|
+
break;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
if (fieldValue) {
|
|
476
508
|
parts.push(fieldValue);
|
|
477
509
|
}
|
|
478
510
|
});
|
|
@@ -482,14 +514,34 @@ const CompositeInput = (props) => {
|
|
|
482
514
|
if (onChange) {
|
|
483
515
|
onChange({ target: { name, value: result, type: "text" } });
|
|
484
516
|
}
|
|
485
|
-
}, [fields, separator, onChange, name
|
|
517
|
+
}, [fields, separator, onChange, name]);
|
|
486
518
|
React__namespace.default.useEffect(() => {
|
|
487
|
-
if (!autoGenerate || fields.length === 0
|
|
488
|
-
const
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
519
|
+
if (!autoGenerate || fields.length === 0) return;
|
|
520
|
+
const handleFieldChange = () => {
|
|
521
|
+
setTimeout(() => {
|
|
522
|
+
handleGenerate();
|
|
523
|
+
}, 300);
|
|
524
|
+
};
|
|
525
|
+
const listeners = [];
|
|
526
|
+
fields.forEach((fieldPath) => {
|
|
527
|
+
const elements = document.querySelectorAll(
|
|
528
|
+
`input[name="${fieldPath}"], textarea[name="${fieldPath}"], select[name="${fieldPath}"], button[role="combobox"]`
|
|
529
|
+
);
|
|
530
|
+
elements.forEach((element) => {
|
|
531
|
+
element.addEventListener("change", handleFieldChange);
|
|
532
|
+
element.addEventListener("input", handleFieldChange);
|
|
533
|
+
element.addEventListener("click", handleFieldChange);
|
|
534
|
+
listeners.push({ element, handler: handleFieldChange });
|
|
535
|
+
});
|
|
536
|
+
});
|
|
537
|
+
return () => {
|
|
538
|
+
listeners.forEach(({ element, handler }) => {
|
|
539
|
+
element.removeEventListener("change", handler);
|
|
540
|
+
element.removeEventListener("input", handler);
|
|
541
|
+
element.removeEventListener("click", handler);
|
|
542
|
+
});
|
|
543
|
+
};
|
|
544
|
+
}, [autoGenerate, fields, handleGenerate]);
|
|
493
545
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
494
546
|
designSystem.Field.Root,
|
|
495
547
|
{
|
|
@@ -3,7 +3,6 @@ import * as React from "react";
|
|
|
3
3
|
import React__default from "react";
|
|
4
4
|
import { Field, Flex, Button, Typography } from "@strapi/design-system";
|
|
5
5
|
import { Play } from "@strapi/icons";
|
|
6
|
-
import { useCMEditViewDataManager } from "@strapi/strapi/admin";
|
|
7
6
|
var __assign = function() {
|
|
8
7
|
__assign = Object.assign || function __assign2(t) {
|
|
9
8
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
@@ -428,7 +427,6 @@ const CompositeInput = (props) => {
|
|
|
428
427
|
label,
|
|
429
428
|
intlLabel
|
|
430
429
|
} = props;
|
|
431
|
-
const { modifiedData } = useCMEditViewDataManager();
|
|
432
430
|
const { formatMessage } = useIntl();
|
|
433
431
|
const [localValue, setLocalValue] = React__default.useState(value || "");
|
|
434
432
|
React__default.useEffect(() => {
|
|
@@ -452,8 +450,42 @@ const CompositeInput = (props) => {
|
|
|
452
450
|
const handleGenerate = React__default.useCallback(() => {
|
|
453
451
|
const parts = [];
|
|
454
452
|
fields.forEach((fieldPath) => {
|
|
455
|
-
|
|
456
|
-
|
|
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 labels = document.querySelectorAll("label");
|
|
468
|
+
for (const labelEl of labels) {
|
|
469
|
+
const labelText = labelEl.textContent?.trim().toLowerCase();
|
|
470
|
+
const fieldName = fieldPath.toLowerCase();
|
|
471
|
+
if (labelText === fieldName || labelText.includes(fieldName)) {
|
|
472
|
+
const container = labelEl.closest('[role="group"]') || labelEl.parentElement;
|
|
473
|
+
if (container) {
|
|
474
|
+
const combobox = container.querySelector(
|
|
475
|
+
'button[role="combobox"]'
|
|
476
|
+
);
|
|
477
|
+
if (combobox) {
|
|
478
|
+
const selectedText = combobox.textContent?.trim();
|
|
479
|
+
if (selectedText && selectedText !== "Select..." && selectedText !== "") {
|
|
480
|
+
fieldValue = selectedText;
|
|
481
|
+
break;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
if (fieldValue) {
|
|
457
489
|
parts.push(fieldValue);
|
|
458
490
|
}
|
|
459
491
|
});
|
|
@@ -463,14 +495,34 @@ const CompositeInput = (props) => {
|
|
|
463
495
|
if (onChange) {
|
|
464
496
|
onChange({ target: { name, value: result, type: "text" } });
|
|
465
497
|
}
|
|
466
|
-
}, [fields, separator, onChange, name
|
|
498
|
+
}, [fields, separator, onChange, name]);
|
|
467
499
|
React__default.useEffect(() => {
|
|
468
|
-
if (!autoGenerate || fields.length === 0
|
|
469
|
-
const
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
500
|
+
if (!autoGenerate || fields.length === 0) return;
|
|
501
|
+
const handleFieldChange = () => {
|
|
502
|
+
setTimeout(() => {
|
|
503
|
+
handleGenerate();
|
|
504
|
+
}, 300);
|
|
505
|
+
};
|
|
506
|
+
const listeners = [];
|
|
507
|
+
fields.forEach((fieldPath) => {
|
|
508
|
+
const elements = document.querySelectorAll(
|
|
509
|
+
`input[name="${fieldPath}"], textarea[name="${fieldPath}"], select[name="${fieldPath}"], button[role="combobox"]`
|
|
510
|
+
);
|
|
511
|
+
elements.forEach((element) => {
|
|
512
|
+
element.addEventListener("change", handleFieldChange);
|
|
513
|
+
element.addEventListener("input", handleFieldChange);
|
|
514
|
+
element.addEventListener("click", handleFieldChange);
|
|
515
|
+
listeners.push({ element, handler: handleFieldChange });
|
|
516
|
+
});
|
|
517
|
+
});
|
|
518
|
+
return () => {
|
|
519
|
+
listeners.forEach(({ element, handler }) => {
|
|
520
|
+
element.removeEventListener("change", handler);
|
|
521
|
+
element.removeEventListener("input", handler);
|
|
522
|
+
element.removeEventListener("click", handler);
|
|
523
|
+
});
|
|
524
|
+
};
|
|
525
|
+
}, [autoGenerate, fields, handleGenerate]);
|
|
474
526
|
return /* @__PURE__ */ jsx(
|
|
475
527
|
Field.Root,
|
|
476
528
|
{
|
package/dist/admin/index.js
CHANGED
|
@@ -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-
|
|
40
|
+
Input: async () => Promise.resolve().then(() => require("../_chunks/CompositeInput-8DFCNiOg.js"))
|
|
41
41
|
},
|
|
42
42
|
options: {
|
|
43
43
|
base: [
|
package/dist/admin/index.mjs
CHANGED
|
@@ -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-
|
|
37
|
+
Input: async () => import("../_chunks/CompositeInput-CZQYMB_n.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.
|
|
3
|
+
"version": "1.1.3",
|
|
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",
|