@webbycrown/advanced-fields 1.0.6 → 1.0.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.
@@ -0,0 +1,167 @@
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: "color",
44
+ type: "string",
45
+ validate: (value, { required, options = {} }) => {
46
+ const { customErrorMessage = "" } = options;
47
+ const stringValue = value === void 0 || value === null ? "" : String(value).trim();
48
+ if (required && !stringValue) {
49
+ return customErrorMessage || "This field is required";
50
+ }
51
+ if (!stringValue) {
52
+ return null;
53
+ }
54
+ const hexRegex = /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;
55
+ if (!hexRegex.test(stringValue)) {
56
+ return customErrorMessage || "Invalid color (use hex like #RRGGBB)";
57
+ }
58
+ return null;
59
+ }
60
+ },
61
+ {
62
+ name: "checkbox",
63
+ type: "json",
64
+ validate: (value, { required, options = {} }) => {
65
+ const {
66
+ checkboxType = "single",
67
+ minChoices = 0,
68
+ maxChoices = 0,
69
+ customErrorMessage = ""
70
+ } = options;
71
+ if (required) {
72
+ if (!value || Array.isArray(value) && value.length === 0 || typeof value === "string" && value.trim() === "" || value === null || value === void 0) {
73
+ return customErrorMessage || "This field is required";
74
+ }
75
+ }
76
+ if (!value || Array.isArray(value) && value.length === 0) {
77
+ return null;
78
+ }
79
+ const values = Array.isArray(value) ? value : [];
80
+ if (checkboxType === "multiple") {
81
+ if (minChoices > 0 && values.length < minChoices) {
82
+ return customErrorMessage || `Please select at least ${minChoices} option${minChoices > 1 ? "s" : ""}`;
83
+ }
84
+ if (maxChoices > 0 && values.length > maxChoices) {
85
+ return customErrorMessage || `Please select at most ${maxChoices} option${maxChoices > 1 ? "s" : ""}`;
86
+ }
87
+ }
88
+ return null;
89
+ }
90
+ },
91
+ {
92
+ name: "radio",
93
+ type: "json",
94
+ validate: (value, { required, options = {} }) => {
95
+ const {
96
+ selectionType = "single",
97
+ minChoices = 0,
98
+ maxChoices = 0,
99
+ customErrorMessage = ""
100
+ } = options;
101
+ if (required) {
102
+ if (!value || Array.isArray(value) && value.length === 0 || typeof value === "string" && value.trim() === "" || value === null || value === void 0) {
103
+ return customErrorMessage || "This field is required";
104
+ }
105
+ }
106
+ if (!value || Array.isArray(value) && value.length === 0) {
107
+ return null;
108
+ }
109
+ const values = Array.isArray(value) ? value : [];
110
+ if (selectionType === "multiple") {
111
+ if (minChoices > 0 && values.length < minChoices) {
112
+ return customErrorMessage || `Please select at least ${minChoices} option${minChoices > 1 ? "s" : ""}`;
113
+ }
114
+ if (maxChoices > 0 && values.length > maxChoices) {
115
+ return customErrorMessage || `Please select at most ${maxChoices} option${maxChoices > 1 ? "s" : ""}`;
116
+ }
117
+ }
118
+ return null;
119
+ }
120
+ },
121
+ {
122
+ name: "enumeration",
123
+ type: "json",
124
+ validate: (value, { required, options = {} }) => {
125
+ const {
126
+ minChoices = 0,
127
+ maxChoices = 0,
128
+ customErrorMessage = ""
129
+ } = options;
130
+ if (required) {
131
+ if (!value || Array.isArray(value) && value.length === 0 || typeof value === "string" && value.trim() === "" || value === null || value === void 0) {
132
+ return customErrorMessage || "This field is required";
133
+ }
134
+ }
135
+ if (!value || Array.isArray(value) && value.length === 0) {
136
+ return null;
137
+ }
138
+ const values = Array.isArray(value) ? value : [];
139
+ if (minChoices > 0 && values.length < minChoices) {
140
+ return customErrorMessage || `Please select at least ${minChoices} option${minChoices > 1 ? "s" : ""}`;
141
+ }
142
+ if (maxChoices > 0 && values.length > maxChoices) {
143
+ return customErrorMessage || `Please select at most ${maxChoices} option${maxChoices > 1 ? "s" : ""}`;
144
+ }
145
+ return null;
146
+ }
147
+ }
148
+ ];
149
+ var server = {
150
+ register({ strapi }) {
151
+ customFields.forEach((field) => {
152
+ const fieldConfig = {
153
+ name: field.name,
154
+ plugin: PLUGIN_ID,
155
+ type: field.type
156
+ };
157
+ if (field.validate) {
158
+ fieldConfig.validate = field.validate;
159
+ }
160
+ strapi.customFields.register(fieldConfig);
161
+ });
162
+ },
163
+ bootstrap({ strapi }) {
164
+ }
165
+ };
166
+ const index = /* @__PURE__ */ getDefaultExportFromCjs(server);
167
+ module.exports = index;
@@ -0,0 +1,168 @@
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: "color",
43
+ type: "string",
44
+ validate: (value, { required, options = {} }) => {
45
+ const { customErrorMessage = "" } = options;
46
+ const stringValue = value === void 0 || value === null ? "" : String(value).trim();
47
+ if (required && !stringValue) {
48
+ return customErrorMessage || "This field is required";
49
+ }
50
+ if (!stringValue) {
51
+ return null;
52
+ }
53
+ const hexRegex = /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;
54
+ if (!hexRegex.test(stringValue)) {
55
+ return customErrorMessage || "Invalid color (use hex like #RRGGBB)";
56
+ }
57
+ return null;
58
+ }
59
+ },
60
+ {
61
+ name: "checkbox",
62
+ type: "json",
63
+ validate: (value, { required, options = {} }) => {
64
+ const {
65
+ checkboxType = "single",
66
+ minChoices = 0,
67
+ maxChoices = 0,
68
+ customErrorMessage = ""
69
+ } = options;
70
+ if (required) {
71
+ if (!value || Array.isArray(value) && value.length === 0 || typeof value === "string" && value.trim() === "" || value === null || value === void 0) {
72
+ return customErrorMessage || "This field is required";
73
+ }
74
+ }
75
+ if (!value || Array.isArray(value) && value.length === 0) {
76
+ return null;
77
+ }
78
+ const values = Array.isArray(value) ? value : [];
79
+ if (checkboxType === "multiple") {
80
+ if (minChoices > 0 && values.length < minChoices) {
81
+ return customErrorMessage || `Please select at least ${minChoices} option${minChoices > 1 ? "s" : ""}`;
82
+ }
83
+ if (maxChoices > 0 && values.length > maxChoices) {
84
+ return customErrorMessage || `Please select at most ${maxChoices} option${maxChoices > 1 ? "s" : ""}`;
85
+ }
86
+ }
87
+ return null;
88
+ }
89
+ },
90
+ {
91
+ name: "radio",
92
+ type: "json",
93
+ validate: (value, { required, options = {} }) => {
94
+ const {
95
+ selectionType = "single",
96
+ minChoices = 0,
97
+ maxChoices = 0,
98
+ customErrorMessage = ""
99
+ } = options;
100
+ if (required) {
101
+ if (!value || Array.isArray(value) && value.length === 0 || typeof value === "string" && value.trim() === "" || value === null || value === void 0) {
102
+ return customErrorMessage || "This field is required";
103
+ }
104
+ }
105
+ if (!value || Array.isArray(value) && value.length === 0) {
106
+ return null;
107
+ }
108
+ const values = Array.isArray(value) ? value : [];
109
+ if (selectionType === "multiple") {
110
+ if (minChoices > 0 && values.length < minChoices) {
111
+ return customErrorMessage || `Please select at least ${minChoices} option${minChoices > 1 ? "s" : ""}`;
112
+ }
113
+ if (maxChoices > 0 && values.length > maxChoices) {
114
+ return customErrorMessage || `Please select at most ${maxChoices} option${maxChoices > 1 ? "s" : ""}`;
115
+ }
116
+ }
117
+ return null;
118
+ }
119
+ },
120
+ {
121
+ name: "enumeration",
122
+ type: "json",
123
+ validate: (value, { required, options = {} }) => {
124
+ const {
125
+ minChoices = 0,
126
+ maxChoices = 0,
127
+ customErrorMessage = ""
128
+ } = options;
129
+ if (required) {
130
+ if (!value || Array.isArray(value) && value.length === 0 || typeof value === "string" && value.trim() === "" || value === null || value === void 0) {
131
+ return customErrorMessage || "This field is required";
132
+ }
133
+ }
134
+ if (!value || Array.isArray(value) && value.length === 0) {
135
+ return null;
136
+ }
137
+ const values = Array.isArray(value) ? value : [];
138
+ if (minChoices > 0 && values.length < minChoices) {
139
+ return customErrorMessage || `Please select at least ${minChoices} option${minChoices > 1 ? "s" : ""}`;
140
+ }
141
+ if (maxChoices > 0 && values.length > maxChoices) {
142
+ return customErrorMessage || `Please select at most ${maxChoices} option${maxChoices > 1 ? "s" : ""}`;
143
+ }
144
+ return null;
145
+ }
146
+ }
147
+ ];
148
+ var server = {
149
+ register({ strapi }) {
150
+ customFields.forEach((field) => {
151
+ const fieldConfig = {
152
+ name: field.name,
153
+ plugin: PLUGIN_ID,
154
+ type: field.type
155
+ };
156
+ if (field.validate) {
157
+ fieldConfig.validate = field.validate;
158
+ }
159
+ strapi.customFields.register(fieldConfig);
160
+ });
161
+ },
162
+ bootstrap({ strapi }) {
163
+ }
164
+ };
165
+ const index = /* @__PURE__ */ getDefaultExportFromCjs(server);
166
+ export {
167
+ index as default
168
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webbycrown/advanced-fields",
3
- "version": "1.0.6",
3
+ "version": "1.0.9",
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": "./strapi-server.js"
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",
@@ -72,7 +76,8 @@
72
76
  "email": "info@webbycrown.com",
73
77
  "url": "https://webbycrown.com"
74
78
  },
75
- "homepage": "https://github.com/webbycrown/strapi-advanced-fields",
79
+ "homepage": "https://www.webbycrown.com/guides/advanced-fields-for-strapi/implementation-guide",
80
+ "documentation": "https://www.webbycrown.com/guides/advanced-fields-for-strapi/implementation-guide",
76
81
  "repository": {
77
82
  "type": "git",
78
83
  "url": "https://github.com/webbycrown/strapi-advanced-fields.git"
@@ -84,4 +89,4 @@
84
89
  "node": ">=18.0.0",
85
90
  "npm": ">=8.0.0"
86
91
  }
87
- }
92
+ }
Binary file