@raketa-builder/builder 0.40.0 → 0.42.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raketa-builder/builder",
3
- "version": "0.40.0",
3
+ "version": "0.42.0",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "license": "MIT",
File without changes
@@ -0,0 +1,28 @@
1
+ import React from "react";
2
+ import TextArea from "../forms/TextArea";
3
+ import TextInput from "../forms/TextInput";
4
+ import SelectMenu from "../forms/SelectMenu";
5
+ import ButtonSettings from "../forms/ButtonSettings";
6
+ import LinkSettings from "../forms/LinkSettings";
7
+
8
+ const FIELDS_MAPPING = {
9
+ text: TextInput,
10
+ textarea: TextArea,
11
+ select: SelectMenu,
12
+ button: ButtonSettings,
13
+ link: LinkSettings,
14
+ };
15
+
16
+ function fetchComponent(opts) {
17
+ return FIELDS_MAPPING[opts.type];
18
+ }
19
+
20
+ const SimpleInput = ({ label, value, opts, onChange }) => {
21
+ const Component = fetchComponent(opts);
22
+
23
+ return (
24
+ <Component label={label} value={value} onChange={onChange} {...opts} />
25
+ );
26
+ };
27
+
28
+ export default SimpleInput;
@@ -0,0 +1,131 @@
1
+ import React from "react";
2
+ import { FieldSet } from "@raketa-builder/ui";
3
+ import { humanize, capitalize } from "../helpers/humanize";
4
+ import List from "../List";
5
+ import SimpleInput from "./SimpleInput";
6
+
7
+ const ListWrapper = ({ field, path, value, opts, onChange }) => {
8
+ const { label, template, primaryField, itemsAlwaysOpen = false } = opts;
9
+
10
+ return (
11
+ <List
12
+ label={label}
13
+ items={value}
14
+ listItem={(settings, onChangeItem) => {
15
+ return Object.keys(opts.schema).map((subField) => {
16
+ const subOpts = Object.assign(
17
+ { label: capitalize(humanize(subField)) },
18
+ opts.schema[subField]
19
+ );
20
+
21
+ return (
22
+ <FormField
23
+ key={`${field}.${subField}`}
24
+ path={`${path}.${subField}`}
25
+ field={subField}
26
+ value={settings?.[subField]}
27
+ opts={subOpts}
28
+ onChange={(newValue) => onChangeItem(subField, newValue)}
29
+ />
30
+ );
31
+ });
32
+ }}
33
+ template={template}
34
+ primaryField={primaryField}
35
+ itemsAlwaysOpen={itemsAlwaysOpen}
36
+ onChangeList={(_key, newList) => onChange(newList)}
37
+ />
38
+ );
39
+ };
40
+
41
+ const SchemaInput = ({ field, value, path, opts, onChange }) => (
42
+ <FieldSet legend={opts?.label}>
43
+ {Object.keys(opts.schema).map((subField) => {
44
+ const subOpts = Object.assign(
45
+ { label: capitalize(humanize(subField)) },
46
+ opts.schema[subField]
47
+ );
48
+
49
+ return (
50
+ <FormField
51
+ key={`${field}.${subField}`}
52
+ path={`${path}.${subField}`}
53
+ field={subField}
54
+ value={value?.[subField]}
55
+ opts={subOpts}
56
+ onChange={(newValue) => onChange({ ...value, [subField]: newValue })}
57
+ />
58
+ );
59
+ })}
60
+ </FieldSet>
61
+ );
62
+
63
+ const FIELDS_MAPPING = {
64
+ text: SimpleInput,
65
+ textarea: SimpleInput,
66
+ select: SimpleInput,
67
+ button: SimpleInput,
68
+ link: SimpleInput,
69
+ list: ListWrapper,
70
+ };
71
+
72
+ function fetchComponent(opts) {
73
+ if (opts.type === "custom" && opts.schema) {
74
+ return SchemaInput;
75
+ }
76
+
77
+ if (opts.type === "custom" && opts.component) {
78
+ return opts.component;
79
+ }
80
+
81
+ return FIELDS_MAPPING[opts.type];
82
+ }
83
+
84
+ const FormField = ({ field, value, path, opts, onChange }) => {
85
+ const Component = fetchComponent(opts);
86
+
87
+ if (!Component) {
88
+ return (
89
+ <p
90
+ style={{
91
+ marginBlock: "1rem",
92
+ }}
93
+ >
94
+ Component of type <strong>{opts.type}</strong> for{" "}
95
+ <strong>{field}</strong> does not exist!
96
+ </p>
97
+ );
98
+ }
99
+
100
+ return (
101
+ <Component
102
+ label={opts.label}
103
+ value={value}
104
+ path={path}
105
+ opts={opts}
106
+ onChange={onChange}
107
+ />
108
+ );
109
+ };
110
+
111
+ const AdminForm = ({ schema = {}, value = {}, onChange }) => {
112
+ return Object.keys(schema).map((field) => {
113
+ const opts = Object.assign(
114
+ { label: capitalize(humanize(field)) },
115
+ schema[field]
116
+ );
117
+
118
+ return (
119
+ <FormField
120
+ key={`${field}`}
121
+ path={field}
122
+ field={field}
123
+ value={value[field]}
124
+ onChange={(newValue) => onChange({ ...value, [field]: newValue })}
125
+ opts={opts}
126
+ />
127
+ );
128
+ });
129
+ };
130
+
131
+ export default AdminForm;
@@ -1,146 +1,16 @@
1
1
  import React from "react";
2
2
  import { Tabs } from "@raketa-builder/ui";
3
3
  import BuilderContext from "../contexts/BuilderContext";
4
- import TextArea from "../forms/TextArea";
5
- import RichText from "../forms/RichText";
6
- import TextInput from "../forms/TextInput";
7
- import SelectMenu from "../forms/SelectMenu";
8
- import ButtonSettings from "../forms/ButtonSettings";
9
- import { humanize, capitalize } from "../helpers/humanize";
10
4
  import Dialog from "./Dialog";
11
- import ImagePicker from "../pickers/ImagePicker/ImagePicker";
12
5
  import widgetData from "../helpers/widgetData";
13
-
14
- const renderField = (field, value, onChange, opts) => {
15
- const handleChange = (newValue) => onChange(field, newValue);
16
-
17
- switch (opts.type) {
18
- case "text": {
19
- return (
20
- <TextInput
21
- key={`dialog-${field}`}
22
- label={opts.label}
23
- value={value}
24
- onChange={handleChange}
25
- {...opts}
26
- />
27
- );
28
- }
29
-
30
- case "textarea": {
31
- return (
32
- <TextArea
33
- key={`dialog-${field}`}
34
- label={opts.label}
35
- value={value}
36
- onChange={handleChange}
37
- {...opts}
38
- />
39
- );
40
- }
41
-
42
- case "rich": {
43
- return (
44
- <RichText
45
- key={`dialog-${field}`}
46
- label={opts.label}
47
- value={value}
48
- onChange={handleChange}
49
- {...opts}
50
- />
51
- );
52
- }
53
-
54
- case "select": {
55
- return (
56
- <SelectMenu
57
- key={`dialog-${field}`}
58
- label={opts.label}
59
- options={opts.options}
60
- value={value}
61
- onChange={handleChange}
62
- {...opts}
63
- />
64
- );
65
- }
66
-
67
- case "image": {
68
- return (
69
- <ImagePicker
70
- key={`dialog-${field}`}
71
- label={opts.label}
72
- value={value}
73
- onChange={handleChange}
74
- {...opts}
75
- />
76
- );
77
- }
78
-
79
- case "button": {
80
- return (
81
- <ButtonSettings
82
- key={`dialog-${field}`}
83
- label={opts.label}
84
- value={value}
85
- onChange={handleChange}
86
- {...opts}
87
- />
88
- );
89
- }
90
-
91
- case "custom": {
92
- const Component = opts.component;
93
-
94
- return (
95
- <Component
96
- key={`dialog-${field}`}
97
- label={opts.label}
98
- value={value}
99
- onChange={handleChange}
100
- {...opts}
101
- />
102
- );
103
- }
104
-
105
- default: {
106
- return (
107
- <TextInput
108
- key={`dialog-${field}`}
109
- label={field}
110
- value={value}
111
- onChange={handleChange}
112
- />
113
- );
114
- }
115
- }
116
- };
117
-
118
- const renderAdmin = (schema = {}, settings = {}, onChange) =>
119
- Object.keys(schema).map((field) => {
120
- const opts = Object.assign(
121
- { label: capitalize(humanize(field)) },
122
- schema[field]
123
- );
124
-
125
- return renderField(field, settings[field], onChange, opts);
126
- });
6
+ import AdminForm from "../AdminForm";
127
7
 
128
8
  const SettingsDialog = ({ widget, settings, onSave, onClose }) => {
129
9
  const { containerAdmin } = React.useContext(BuilderContext);
130
10
  const [localSettings, setLocalSettings] = React.useState(settings);
131
11
 
132
- const handleChange = (field, value) => {
133
- setLocalSettings({
134
- ...localSettings,
135
- [field]: value,
136
- });
137
- };
138
-
139
- const handleChangeContainer = (field, value) => {
140
- handleChange("containerSettings", {
141
- ...localSettings.containerSettings,
142
- [field]: value,
143
- });
12
+ const handleChangeContainer = (value) => {
13
+ setLocalSettings({ ...localSettings, containerSettings: { ...value } });
144
14
  };
145
15
 
146
16
  const schema = widgetData.adminFields(widget);
@@ -152,15 +22,6 @@ const SettingsDialog = ({ widget, settings, onSave, onClose }) => {
152
22
  );
153
23
  }
154
24
 
155
- const fields = renderAdmin(schema, localSettings, handleChange);
156
-
157
- const { containerSettings } = localSettings;
158
- const containerAdminFields = renderAdmin(
159
- containerAdmin,
160
- containerSettings,
161
- handleChangeContainer
162
- );
163
-
164
25
  const areChanges = JSON.stringify(settings) !== JSON.stringify(localSettings);
165
26
 
166
27
  return (
@@ -173,8 +34,20 @@ const SettingsDialog = ({ widget, settings, onSave, onClose }) => {
173
34
  areChanges={areChanges}
174
35
  >
175
36
  <Tabs>
176
- <div title="Content">{fields}</div>
177
- <div title="Container">{containerAdminFields}</div>
37
+ <div title="Content">
38
+ <AdminForm
39
+ schema={schema}
40
+ value={localSettings}
41
+ onChange={(newValue) => setLocalSettings({ ...newValue })}
42
+ />
43
+ </div>
44
+ <div title="Container">
45
+ <AdminForm
46
+ schema={containerAdmin}
47
+ value={localSettings.containerSettings}
48
+ onChange={handleChangeContainer}
49
+ />
50
+ </div>
178
51
  </Tabs>
179
52
  </Dialog>
180
53
  );
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { Hint, cn } from "@raketa-builder/ui";
2
+ import { Hint, FormGroup, cn } from "@raketa-builder/ui";
3
3
  import BuilderContext from "../contexts/BuilderContext";
4
4
 
5
5
  import TextInput from "./TextInput";
@@ -20,10 +20,6 @@ const FormSectionTitle = ({ className, ...props }) => (
20
20
  />
21
21
  );
22
22
 
23
- const ButtonControl = ({ className, ...props }) => (
24
- <div className={cn("r-reset", "r-button-control", className)} {...props} />
25
- );
26
-
27
23
  const DEFAULT_BUTTON_STYLES = [
28
24
  ["primary", "Primary"],
29
25
  ["secondary", "Secondary"],
@@ -52,7 +48,7 @@ const ButtonSettings = ({
52
48
  React.useContext(BuilderContext) || DEFAULT_BUTTON_STYLES;
53
49
 
54
50
  return (
55
- <ButtonControl>
51
+ <FormGroup>
56
52
  <FormSectionTitle>
57
53
  <SettingsIcon /> {label}
58
54
  </FormSectionTitle>
@@ -109,7 +105,7 @@ const ButtonSettings = ({
109
105
  </ThreeColumns>
110
106
 
111
107
  {hint ? <Hint>{hint}</Hint> : ""}
112
- </ButtonControl>
108
+ </FormGroup>
113
109
  );
114
110
  };
115
111
 
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { Hint, cn } from "@raketa-builder/ui";
2
+ import { Hint, FormGroup, cn } from "@raketa-builder/ui";
3
3
 
4
4
  import TextInput from "./TextInput";
5
5
  import SelectMenu from "./SelectMenu";
@@ -19,10 +19,6 @@ const FormSectionTitle = ({ className, ...props }) => (
19
19
  />
20
20
  );
21
21
 
22
- const ButtonControl = ({ className, ...props }) => (
23
- <div className={cn("r-reset", "r-button-control", className)} {...props} />
24
- );
25
-
26
22
  const mergeSettings = (settings, key, value) =>
27
23
  Object.assign({}, settings, { [key]: value });
28
24
 
@@ -36,7 +32,7 @@ const DEFAULTS = {
36
32
  };
37
33
 
38
34
  const LinkSettings = ({ label = "Link", hint, value = DEFAULTS, onChange }) => (
39
- <ButtonControl>
35
+ <FormGroup>
40
36
  <FormSectionTitle>
41
37
  <SettingsIcon /> {label}
42
38
  </FormSectionTitle>
@@ -92,7 +88,7 @@ const LinkSettings = ({ label = "Link", hint, value = DEFAULTS, onChange }) => (
92
88
  </ThreeColumns>
93
89
 
94
90
  {hint ? <Hint>{hint}</Hint> : ""}
95
- </ButtonControl>
91
+ </FormGroup>
96
92
  );
97
93
 
98
94
  LinkSettings.defaults = DEFAULTS;
@@ -10,7 +10,7 @@ const getOptions = (options, placeholder) => {
10
10
  };
11
11
 
12
12
  const SelectField = (props) => {
13
- const id = randomString();
13
+ const id = props.id || randomString();
14
14
  const { label, hint, options, placeholder, onChange } = props;
15
15
  const inputProps = Object.assign({}, props);
16
16
  delete inputProps.label;
package/src/index.js CHANGED
@@ -1,12 +1,8 @@
1
- import React from "react";
2
1
  import { Label, FormGroup } from "@raketa-builder/ui";
3
2
  import PageBuilder from "./PageBuilder";
4
3
  import TextInput from "./forms/TextInput";
5
4
  import TextArea from "./forms/TextArea";
6
- import RichText from "./forms/RichText";
7
5
  import SelectMenu from "./forms/SelectMenu";
8
- import ImagePicker from "./pickers/ImagePicker/ImagePicker";
9
- import ImageInput from "./pickers/ImagePicker/ImageInput";
10
6
  import Dialog from "./dialogs/Dialog";
11
7
  import Img from "./lib/Image";
12
8
  import List from "./List";
@@ -17,19 +13,17 @@ import ButtonSettings from "./forms/ButtonSettings";
17
13
  import LinkSettings from "./forms/LinkSettings";
18
14
  import Link from "./lib/Link";
19
15
  import BuilderContext from "./contexts/BuilderContext";
16
+ import AdminForm from "./AdminForm";
20
17
 
21
18
  export {
22
19
  PageBuilder,
23
20
  TextInput,
24
21
  TextArea,
25
- RichText,
26
22
  SelectMenu,
27
23
  Dialog,
28
24
  Img,
29
25
  List,
30
26
  MediaManager,
31
- ImagePicker,
32
- ImageInput,
33
27
  ListInput,
34
28
  Button,
35
29
  ButtonSettings,
@@ -38,4 +32,5 @@ export {
38
32
  Label,
39
33
  FormGroup,
40
34
  BuilderContext,
35
+ AdminForm,
41
36
  };
package/src/styles.css CHANGED
@@ -68,14 +68,6 @@
68
68
  font-weight: bold;
69
69
  }
70
70
 
71
- .r-button-control {
72
- margin-bottom: 0;
73
- }
74
-
75
- .r-button-control + div {
76
- margin-top: 14px;
77
- }
78
-
79
71
  .r-admin-widget-label {
80
72
  position: absolute;
81
73
  top: 1rem;
@@ -1,22 +0,0 @@
1
- import React from "react";
2
-
3
- const RichText = () => (
4
- <div>
5
- <p>
6
- RichText is no longer part of @raketa-builder/builder. Please use
7
- @raketa-cms/raketa-rte
8
- </p>
9
-
10
- <strong>Update your imports</strong>
11
- <p>
12
- <code>{`import {RichText} from '@raketa-cms/raketa-rte';`}</code>
13
- </p>
14
-
15
- <strong>Update usage in JSON adminFields</strong>
16
- <p>
17
- <code>{`text: { type: 'custom', component: RichText },`}</code>
18
- </p>
19
- </div>
20
- );
21
-
22
- export default RichText;
@@ -1,17 +0,0 @@
1
- import React from "react";
2
-
3
- const ImageInput = () => (
4
- <div>
5
- <p>
6
- ImageInput is no longer part of @raketa-builder/builder. Please use
7
- @raketa-builder/image-input.{" "}
8
- </p>
9
-
10
- <strong>Update imports</strong>
11
- <p>
12
- <code>{`import { ImageInput } from '@raketa-builder/image-input';`}</code>
13
- </p>
14
- </div>
15
- );
16
-
17
- export default ImageInput;
@@ -1,22 +0,0 @@
1
- import React from "react";
2
-
3
- const ImagePicker = () => (
4
- <div>
5
- <p>
6
- ImagePicker is no longer part of @raketa-builder/builder. Please use
7
- @raketa-builder/image-input.{" "}
8
- </p>
9
-
10
- <strong>Update imports</strong>
11
- <p>
12
- <code>{`import { ImagePicker } from '@raketa-builder/image-input';`}</code>
13
- </p>
14
-
15
- <strong>Update JSON adminFields</strong>
16
- <p>
17
- <code>{`image: { type: 'custom', component: ImagePicker },`}</code>
18
- </p>
19
- </div>
20
- );
21
-
22
- export default ImagePicker;