@raketa-builder/builder 1.4.21 → 1.4.23

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.
@@ -1,11 +1,39 @@
1
1
  import { __spreadProps, __spreadValues } from '../chunk-BBZEL7EG.js';
2
2
  import { jsx, jsxs } from 'react/jsx-runtime';
3
3
  import 'react';
4
- import { FieldSet } from '@raketa-builder/ui';
4
+ import { Panel, PanelTitle, PanelContent } from '@raketa-builder/ui';
5
5
  import { capitalize, humanize } from '../helpers/humanize';
6
6
  import List from '../List';
7
7
  import SimpleInput from './SimpleInput';
8
8
 
9
+ const InputSection = ({ title, children }) => /* @__PURE__ */ jsxs(Panel, { children: [
10
+ /* @__PURE__ */ jsx(PanelTitle, { children: title }),
11
+ /* @__PURE__ */ jsx(PanelContent, { children })
12
+ ] });
13
+ function renderListSubfield({
14
+ field,
15
+ subField,
16
+ path,
17
+ settings,
18
+ schema,
19
+ onChangeItem
20
+ }) {
21
+ const subOpts = Object.assign(
22
+ { label: capitalize(humanize(subField)) },
23
+ schema[subField]
24
+ );
25
+ return /* @__PURE__ */ jsx(
26
+ FormField,
27
+ {
28
+ path: `${path}.${subField}`,
29
+ field: subField,
30
+ value: settings == null ? void 0 : settings[subField],
31
+ opts: subOpts,
32
+ onChange: (newValue) => onChangeItem(subField, newValue)
33
+ },
34
+ `${field}.${subField}`
35
+ );
36
+ }
9
37
  const ListWrapper = ({ field, path, value, opts, onChange }) => {
10
38
  const { label, template, primaryField, itemsAlwaysOpen = false } = opts;
11
39
  return /* @__PURE__ */ jsx(
@@ -15,21 +43,33 @@ const ListWrapper = ({ field, path, value, opts, onChange }) => {
15
43
  items: value,
16
44
  listItem: (settings, onChangeItem) => {
17
45
  return Object.keys(opts.schema).map((subField) => {
18
- const subOpts = Object.assign(
19
- { label: capitalize(humanize(subField)) },
20
- opts.schema[subField]
21
- );
22
- return /* @__PURE__ */ jsx(
23
- FormField,
24
- {
25
- path: `${path}.${subField}`,
26
- field: subField,
27
- value: settings == null ? void 0 : settings[subField],
28
- opts: subOpts,
29
- onChange: (newValue) => onChangeItem(subField, newValue)
30
- },
31
- `${field}.${subField}`
32
- );
46
+ if (opts.schema[subField].type === "section") {
47
+ const section = opts.schema[subField];
48
+ return /* @__PURE__ */ jsx(
49
+ InputSection,
50
+ {
51
+ title: section.title || capitalize(humanize(subField)),
52
+ children: Object.keys(section.schema).map((sectionField) => {
53
+ return renderListSubfield({
54
+ field,
55
+ subField: sectionField,
56
+ path,
57
+ settings,
58
+ schema: section.schema,
59
+ onChangeItem
60
+ });
61
+ })
62
+ }
63
+ );
64
+ }
65
+ return renderListSubfield({
66
+ field,
67
+ subField,
68
+ path,
69
+ settings,
70
+ schema: opts.schema,
71
+ onChangeItem
72
+ });
33
73
  });
34
74
  },
35
75
  template,
@@ -39,10 +79,10 @@ const ListWrapper = ({ field, path, value, opts, onChange }) => {
39
79
  }
40
80
  );
41
81
  };
42
- const SchemaInput = ({ field, value, path, opts, onChange }) => /* @__PURE__ */ jsx(FieldSet, { legend: opts == null ? void 0 : opts.label, children: Object.keys(opts.schema).map((subField) => {
82
+ function renderSchemaField({ field, subField, value, path, schema, onChange }) {
43
83
  const subOpts = Object.assign(
44
84
  { label: capitalize(humanize(subField)) },
45
- opts.schema[subField]
85
+ schema[subField]
46
86
  );
47
87
  return /* @__PURE__ */ jsx(
48
88
  FormField,
@@ -55,6 +95,29 @@ const SchemaInput = ({ field, value, path, opts, onChange }) => /* @__PURE__ */
55
95
  },
56
96
  `${field}.${subField}`
57
97
  );
98
+ }
99
+ const SchemaInput = ({ field, value, path, opts, onChange }) => /* @__PURE__ */ jsx(InputSection, { title: opts == null ? void 0 : opts.label, children: Object.keys(opts.schema).map((subField) => {
100
+ if (opts.schema[subField].type === "section") {
101
+ const section = opts.schema[subField];
102
+ return /* @__PURE__ */ jsx(InputSection, { title: section.title || capitalize(humanize(subField)), children: Object.keys(section.schema).map((sectionField) => {
103
+ return renderSchemaField({
104
+ field,
105
+ subField: sectionField,
106
+ value,
107
+ path,
108
+ schema: section.schema,
109
+ onChange
110
+ });
111
+ }) });
112
+ }
113
+ return renderSchemaField({
114
+ field,
115
+ subField,
116
+ value,
117
+ path,
118
+ schema: opts.schema,
119
+ onChange
120
+ });
58
121
  }) });
59
122
  const FIELDS_MAPPING = {
60
123
  text: SimpleInput,
@@ -112,23 +175,37 @@ function sanitezeOpts(opts) {
112
175
  });
113
176
  return opts;
114
177
  }
178
+ function renderField({ field, schema, value, onChange }) {
179
+ const opts = Object.assign(
180
+ { label: capitalize(humanize(field)) },
181
+ schema[field]
182
+ );
183
+ return /* @__PURE__ */ jsx(
184
+ FormField,
185
+ {
186
+ path: field,
187
+ field,
188
+ value: value[field],
189
+ onChange: (newValue) => onChange(__spreadProps(__spreadValues({}, value), { [field]: newValue })),
190
+ opts
191
+ },
192
+ `${field}`
193
+ );
194
+ }
115
195
  const AdminForm = ({ schema = {}, value = {}, onChange }) => {
116
196
  return Object.keys(schema).map((field) => {
117
- const opts = Object.assign(
118
- { label: capitalize(humanize(field)) },
119
- schema[field]
120
- );
121
- return /* @__PURE__ */ jsx(
122
- FormField,
123
- {
124
- path: field,
125
- field,
126
- value: value[field],
127
- onChange: (newValue) => onChange(__spreadProps(__spreadValues({}, value), { [field]: newValue })),
128
- opts
129
- },
130
- `${field}`
131
- );
197
+ if (schema[field].type === "section") {
198
+ const section = schema[field];
199
+ return /* @__PURE__ */ jsx(InputSection, { title: section.title || capitalize(humanize(field)), children: Object.keys(section.schema).map((sectionField) => {
200
+ return renderField({
201
+ field: sectionField,
202
+ schema: section.schema,
203
+ value,
204
+ onChange
205
+ });
206
+ }) });
207
+ }
208
+ return renderField({ field, schema, value, onChange });
132
209
  });
133
210
  };
134
211
  var AdminForm_default = AdminForm;
package/dist/List.js CHANGED
@@ -136,16 +136,8 @@ const Item = ({
136
136
  display: "flex"
137
137
  },
138
138
  children: [
139
- /* @__PURE__ */ jsx(
140
- ListButton,
141
- {
142
- type: "button",
143
- danger: true,
144
- onClick: () => handleDuplicate(item, idx),
145
- children: /* @__PURE__ */ jsx(IconDuplicate, {})
146
- }
147
- ),
148
- (template || !template && items.length !== 1) && /* @__PURE__ */ jsx(ListButton, { type: "button", danger: true, onClick: () => handleRemove(idx), children: /* @__PURE__ */ jsx(IconDelete, {}) })
139
+ /* @__PURE__ */ jsx(ListButton, { type: "button", onClick: () => handleDuplicate(item, idx), children: /* @__PURE__ */ jsx(IconDuplicate, {}) }),
140
+ (template || !template && items.length !== 1) && /* @__PURE__ */ jsx(ListButton, { type: "button", onClick: () => handleRemove(idx), children: /* @__PURE__ */ jsx(IconDelete, {}) })
149
141
  ]
150
142
  }
151
143
  )
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raketa-builder/builder",
3
- "version": "1.4.21",
3
+ "version": "1.4.23",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -31,8 +31,8 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "react-sortablejs": "6.1.4",
34
- "@raketa-builder/support": "1.4.21",
35
- "@raketa-builder/ui": "1.4.21"
34
+ "@raketa-builder/support": "1.4.23",
35
+ "@raketa-builder/ui": "1.4.23"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@biomejs/biome": "2.1.2",