@webbycrown/advanced-fields 1.0.6 → 1.0.7
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 +2 -0
- package/dist/server/index.js +139 -0
- package/dist/server/index.mjs +140 -0
- package/package.json +11 -7
- package/assets/advanced-field-play-img.png +0 -0
package/README.md
CHANGED
|
@@ -274,6 +274,8 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
|
|
|
274
274
|
|
|
275
275
|
## 📊 Changelog
|
|
276
276
|
|
|
277
|
+
### v1.0.7
|
|
278
|
+
- 📝 Updated Plugin for latest version.
|
|
277
279
|
|
|
278
280
|
### v1.0.6
|
|
279
281
|
- 📝 Updated the README to properly display the YouTube preview image in Any documentation.
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
function getDefaultExportFromCjs(x) {
|
|
3
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
4
|
+
}
|
|
5
|
+
const PLUGIN_ID = "advanced-fields";
|
|
6
|
+
const customFields = [
|
|
7
|
+
{
|
|
8
|
+
name: "input",
|
|
9
|
+
type: "string",
|
|
10
|
+
validate: (value, { required, options = {} }) => {
|
|
11
|
+
const {
|
|
12
|
+
minLength = 0,
|
|
13
|
+
maxLength = 0,
|
|
14
|
+
regex = "",
|
|
15
|
+
customErrorMessage = ""
|
|
16
|
+
} = options;
|
|
17
|
+
if (required && (!value || value.trim().length === 0)) {
|
|
18
|
+
return customErrorMessage || "This field is required";
|
|
19
|
+
}
|
|
20
|
+
if (!value || value.trim().length === 0) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
const stringValue = value.toString().trim();
|
|
24
|
+
if (minLength > 0 && stringValue.length < minLength) {
|
|
25
|
+
return customErrorMessage || `Minimum length is ${minLength} characters`;
|
|
26
|
+
}
|
|
27
|
+
if (maxLength > 0 && stringValue.length > maxLength) {
|
|
28
|
+
return customErrorMessage || `Maximum length is ${maxLength} characters`;
|
|
29
|
+
}
|
|
30
|
+
if (regex && regex.trim()) {
|
|
31
|
+
try {
|
|
32
|
+
const regexPattern = new RegExp(regex);
|
|
33
|
+
if (!regexPattern.test(stringValue)) {
|
|
34
|
+
return customErrorMessage || "Value does not match the required pattern";
|
|
35
|
+
}
|
|
36
|
+
} catch (e) {
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: "checkbox",
|
|
44
|
+
type: "json",
|
|
45
|
+
validate: (value, { required, options = {} }) => {
|
|
46
|
+
const {
|
|
47
|
+
checkboxType = "single",
|
|
48
|
+
minChoices = 0,
|
|
49
|
+
maxChoices = 0,
|
|
50
|
+
customErrorMessage = ""
|
|
51
|
+
} = options;
|
|
52
|
+
if (required) {
|
|
53
|
+
if (!value || Array.isArray(value) && value.length === 0 || typeof value === "string" && value.trim() === "" || value === null || value === void 0) {
|
|
54
|
+
return customErrorMessage || "This field is required";
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (!value || Array.isArray(value) && value.length === 0) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
const values = Array.isArray(value) ? value : [];
|
|
61
|
+
if (checkboxType === "multiple") {
|
|
62
|
+
if (minChoices > 0 && values.length < minChoices) {
|
|
63
|
+
return customErrorMessage || `Please select at least ${minChoices} option${minChoices > 1 ? "s" : ""}`;
|
|
64
|
+
}
|
|
65
|
+
if (maxChoices > 0 && values.length > maxChoices) {
|
|
66
|
+
return customErrorMessage || `Please select at most ${maxChoices} option${maxChoices > 1 ? "s" : ""}`;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
name: "radio",
|
|
74
|
+
type: "json",
|
|
75
|
+
validate: (value, { required, options = {} }) => {
|
|
76
|
+
const {
|
|
77
|
+
selectionType = "single",
|
|
78
|
+
minChoices = 0,
|
|
79
|
+
maxChoices = 0,
|
|
80
|
+
customErrorMessage = ""
|
|
81
|
+
} = options;
|
|
82
|
+
if (required) {
|
|
83
|
+
if (!value || Array.isArray(value) && value.length === 0 || typeof value === "string" && value.trim() === "" || value === null || value === void 0) {
|
|
84
|
+
return customErrorMessage || "This field is required";
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (!value || Array.isArray(value) && value.length === 0) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
const values = Array.isArray(value) ? value : [];
|
|
91
|
+
if (selectionType === "multiple") {
|
|
92
|
+
if (minChoices > 0 && values.length < minChoices) {
|
|
93
|
+
return customErrorMessage || `Please select at least ${minChoices} option${minChoices > 1 ? "s" : ""}`;
|
|
94
|
+
}
|
|
95
|
+
if (maxChoices > 0 && values.length > maxChoices) {
|
|
96
|
+
return customErrorMessage || `Please select at most ${maxChoices} option${maxChoices > 1 ? "s" : ""}`;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
];
|
|
103
|
+
var server = {
|
|
104
|
+
register({ strapi }) {
|
|
105
|
+
if (!strapi.customFields) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
customFields.forEach((field) => {
|
|
109
|
+
try {
|
|
110
|
+
const fieldConfig = {
|
|
111
|
+
name: field.name,
|
|
112
|
+
plugin: PLUGIN_ID,
|
|
113
|
+
type: field.type
|
|
114
|
+
};
|
|
115
|
+
if (field.validate) {
|
|
116
|
+
fieldConfig.validate = field.validate;
|
|
117
|
+
}
|
|
118
|
+
strapi.customFields.register(fieldConfig);
|
|
119
|
+
} catch (error) {
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
},
|
|
123
|
+
bootstrap({ strapi }) {
|
|
124
|
+
setTimeout(() => {
|
|
125
|
+
if (strapi.customFields && typeof strapi.customFields.get === "function") {
|
|
126
|
+
customFields.forEach((field) => {
|
|
127
|
+
try {
|
|
128
|
+
const registeredField = strapi.customFields.get(
|
|
129
|
+
`${PLUGIN_ID}.${field.name}`
|
|
130
|
+
);
|
|
131
|
+
} catch (error) {
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}, 1e3);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
const index = /* @__PURE__ */ getDefaultExportFromCjs(server);
|
|
139
|
+
module.exports = index;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
function getDefaultExportFromCjs(x) {
|
|
2
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
3
|
+
}
|
|
4
|
+
const PLUGIN_ID = "advanced-fields";
|
|
5
|
+
const customFields = [
|
|
6
|
+
{
|
|
7
|
+
name: "input",
|
|
8
|
+
type: "string",
|
|
9
|
+
validate: (value, { required, options = {} }) => {
|
|
10
|
+
const {
|
|
11
|
+
minLength = 0,
|
|
12
|
+
maxLength = 0,
|
|
13
|
+
regex = "",
|
|
14
|
+
customErrorMessage = ""
|
|
15
|
+
} = options;
|
|
16
|
+
if (required && (!value || value.trim().length === 0)) {
|
|
17
|
+
return customErrorMessage || "This field is required";
|
|
18
|
+
}
|
|
19
|
+
if (!value || value.trim().length === 0) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
const stringValue = value.toString().trim();
|
|
23
|
+
if (minLength > 0 && stringValue.length < minLength) {
|
|
24
|
+
return customErrorMessage || `Minimum length is ${minLength} characters`;
|
|
25
|
+
}
|
|
26
|
+
if (maxLength > 0 && stringValue.length > maxLength) {
|
|
27
|
+
return customErrorMessage || `Maximum length is ${maxLength} characters`;
|
|
28
|
+
}
|
|
29
|
+
if (regex && regex.trim()) {
|
|
30
|
+
try {
|
|
31
|
+
const regexPattern = new RegExp(regex);
|
|
32
|
+
if (!regexPattern.test(stringValue)) {
|
|
33
|
+
return customErrorMessage || "Value does not match the required pattern";
|
|
34
|
+
}
|
|
35
|
+
} catch (e) {
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
name: "checkbox",
|
|
43
|
+
type: "json",
|
|
44
|
+
validate: (value, { required, options = {} }) => {
|
|
45
|
+
const {
|
|
46
|
+
checkboxType = "single",
|
|
47
|
+
minChoices = 0,
|
|
48
|
+
maxChoices = 0,
|
|
49
|
+
customErrorMessage = ""
|
|
50
|
+
} = options;
|
|
51
|
+
if (required) {
|
|
52
|
+
if (!value || Array.isArray(value) && value.length === 0 || typeof value === "string" && value.trim() === "" || value === null || value === void 0) {
|
|
53
|
+
return customErrorMessage || "This field is required";
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (!value || Array.isArray(value) && value.length === 0) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
const values = Array.isArray(value) ? value : [];
|
|
60
|
+
if (checkboxType === "multiple") {
|
|
61
|
+
if (minChoices > 0 && values.length < minChoices) {
|
|
62
|
+
return customErrorMessage || `Please select at least ${minChoices} option${minChoices > 1 ? "s" : ""}`;
|
|
63
|
+
}
|
|
64
|
+
if (maxChoices > 0 && values.length > maxChoices) {
|
|
65
|
+
return customErrorMessage || `Please select at most ${maxChoices} option${maxChoices > 1 ? "s" : ""}`;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
name: "radio",
|
|
73
|
+
type: "json",
|
|
74
|
+
validate: (value, { required, options = {} }) => {
|
|
75
|
+
const {
|
|
76
|
+
selectionType = "single",
|
|
77
|
+
minChoices = 0,
|
|
78
|
+
maxChoices = 0,
|
|
79
|
+
customErrorMessage = ""
|
|
80
|
+
} = options;
|
|
81
|
+
if (required) {
|
|
82
|
+
if (!value || Array.isArray(value) && value.length === 0 || typeof value === "string" && value.trim() === "" || value === null || value === void 0) {
|
|
83
|
+
return customErrorMessage || "This field is required";
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (!value || Array.isArray(value) && value.length === 0) {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
const values = Array.isArray(value) ? value : [];
|
|
90
|
+
if (selectionType === "multiple") {
|
|
91
|
+
if (minChoices > 0 && values.length < minChoices) {
|
|
92
|
+
return customErrorMessage || `Please select at least ${minChoices} option${minChoices > 1 ? "s" : ""}`;
|
|
93
|
+
}
|
|
94
|
+
if (maxChoices > 0 && values.length > maxChoices) {
|
|
95
|
+
return customErrorMessage || `Please select at most ${maxChoices} option${maxChoices > 1 ? "s" : ""}`;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
];
|
|
102
|
+
var server = {
|
|
103
|
+
register({ strapi }) {
|
|
104
|
+
if (!strapi.customFields) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
customFields.forEach((field) => {
|
|
108
|
+
try {
|
|
109
|
+
const fieldConfig = {
|
|
110
|
+
name: field.name,
|
|
111
|
+
plugin: PLUGIN_ID,
|
|
112
|
+
type: field.type
|
|
113
|
+
};
|
|
114
|
+
if (field.validate) {
|
|
115
|
+
fieldConfig.validate = field.validate;
|
|
116
|
+
}
|
|
117
|
+
strapi.customFields.register(fieldConfig);
|
|
118
|
+
} catch (error) {
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
},
|
|
122
|
+
bootstrap({ strapi }) {
|
|
123
|
+
setTimeout(() => {
|
|
124
|
+
if (strapi.customFields && typeof strapi.customFields.get === "function") {
|
|
125
|
+
customFields.forEach((field) => {
|
|
126
|
+
try {
|
|
127
|
+
const registeredField = strapi.customFields.get(
|
|
128
|
+
`${PLUGIN_ID}.${field.name}`
|
|
129
|
+
);
|
|
130
|
+
} catch (error) {
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}, 1e3);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
const index = /* @__PURE__ */ getDefaultExportFromCjs(server);
|
|
138
|
+
export {
|
|
139
|
+
index as default
|
|
140
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webbycrown/advanced-fields",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"strapi",
|
|
6
6
|
"plugin",
|
|
@@ -22,13 +22,17 @@
|
|
|
22
22
|
"require": "./dist/admin/index.js",
|
|
23
23
|
"default": "./dist/admin/index.js"
|
|
24
24
|
},
|
|
25
|
-
"./strapi-server":
|
|
25
|
+
"./strapi-server": {
|
|
26
|
+
"source": "./server/index.js",
|
|
27
|
+
"import": "./dist/server/index.mjs",
|
|
28
|
+
"require": "./dist/server/index.js",
|
|
29
|
+
"default": "./dist/server/index.js"
|
|
30
|
+
}
|
|
26
31
|
},
|
|
27
|
-
"files": [
|
|
28
|
-
"dist",
|
|
32
|
+
"files": [
|
|
33
|
+
"dist",
|
|
29
34
|
"README.md",
|
|
30
|
-
"LICENSE"
|
|
31
|
-
"assets"
|
|
35
|
+
"LICENSE"
|
|
32
36
|
],
|
|
33
37
|
"scripts": {
|
|
34
38
|
"build": "npm run build:admin",
|
|
@@ -84,4 +88,4 @@
|
|
|
84
88
|
"node": ">=18.0.0",
|
|
85
89
|
"npm": ">=8.0.0"
|
|
86
90
|
}
|
|
87
|
-
}
|
|
91
|
+
}
|
|
Binary file
|