@tunghtml/strapi-plugin-dynamic-enum 1.0.1 → 1.0.2

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.
@@ -29,9 +29,22 @@ const DynamicEnumInput = ({
29
29
  let opts = [];
30
30
  if (typeof initialOptions === 'string') {
31
31
  try {
32
- opts = JSON.parse(initialOptions);
32
+ const parsed = JSON.parse(initialOptions);
33
+ if (Array.isArray(parsed)) {
34
+ opts = parsed;
35
+ } else {
36
+ // If valid JSON but not an array (e.g. string/number), treat as text
37
+ opts = initialOptions
38
+ .split('\n')
39
+ .map((o) => o.trim())
40
+ .filter(Boolean);
41
+ }
33
42
  } catch {
34
- opts = [];
43
+ // Not valid JSON, treat as newline-separated text
44
+ opts = initialOptions
45
+ .split('\n')
46
+ .map((o) => o.trim())
47
+ .filter(Boolean);
35
48
  }
36
49
  } else {
37
50
  opts = Array.isArray(initialOptions) ? initialOptions : [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tunghtml/strapi-plugin-dynamic-enum",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "A Strapi custom field plugin for enum with dynamic option creation",
5
5
  "keywords": [
6
6
  "strapi",
package/strapi-admin.js CHANGED
@@ -35,12 +35,11 @@ export default {
35
35
  },
36
36
  description: {
37
37
  id: 'dynamic-enum.options.enum.description',
38
- defaultMessage:
39
- 'Enter initial enum values as JSON array: ["Option 1", "Option 2"]',
38
+ defaultMessage: 'Enter initial enum values, one per line',
40
39
  },
41
40
  placeholder: {
42
41
  id: 'dynamic-enum.options.enum.placeholder',
43
- defaultMessage: '["Option 1", "Option 2", "Option 3"]',
42
+ defaultMessage: 'Option 1\nOption 2\nOption 3',
44
43
  },
45
44
  },
46
45
  {