Skip to content

Commit d099763

Browse files
committed
fix(controls): block elements are not editable in the editor
resolves #161
1 parent b8ce1e7 commit d099763

File tree

7 files changed

+113
-6
lines changed

7 files changed

+113
-6
lines changed

docs/controls/README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Controls
2+
3+
![formeo-controls](https://user-images.githubusercontent.com/1457540/56075239-26cbf100-5d74-11e9-8cd0-d4400705365f.png)
4+
5+
A Control refers to inputs and elements that can be dragged to the stage when editing a form. In their most basic form, they can be a javascript literal object that defines basic information about the element eg.
6+
7+
```javascript
8+
const inputElement = {
9+
tag: 'input',
10+
attrs: {
11+
required: false, // will render a checkbox in the editor to toggle required attribute
12+
type: 'text',
13+
className: '' // accepts string or array of class names
14+
},
15+
config: {
16+
label: 'Input', // label that appears in the control side bar
17+
editorLabel: 'My Custom Input' // label that appears in the editor
18+
},
19+
meta: {
20+
group: 'common', // group id
21+
icon: 'text-input-icon', // needs to be an svg or font icon id
22+
id: 'text-input' // unique that can be used to reference the control
23+
},
24+
}
25+
```
26+
27+
## Control Groups
28+
29+
Formeo comes with a 3 groups of basic controls. These groups can be disabled, extended, ordered, and more. The default control groups are `form`, `html`, and `layout`.
30+
31+
### Form Controls
32+
33+
Form controls are considered controls that users can interact with and at the time of writing Formeo ships with the following `form` controls:
34+
35+
- button
36+
- checkbox-group
37+
- input
38+
- date
39+
- file
40+
- hidden
41+
- number
42+
- text
43+
- radio-group
44+
- select
45+
- textarea
46+
47+
### HTML Controls
48+
49+
HTML Controls are used to render html elements like `<p/>`, `<h1/>` and `<hr/>`. To make a Control's rendered html editable in the editor, set the `editableContent` to `true` when defining your control's `config`. Example:
50+
51+
```javascript
52+
const paragraph = {
53+
tag: 'p',
54+
config: {
55+
label: 'Paragraph',
56+
editableContent: true
57+
},
58+
content:
59+
'This content can be edited in the editor'
60+
}
61+
```

docs/options/controls/README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Controls Options
2+
3+
Control options can be used to disable, extend and modify the Formeo's control panel.
4+
5+
| Option | Type | Description | Example | Default |
6+
| ------------------------- | ------ | --------------------------------------- | -------------------- | ------------------------------ |
7+
| [sortable](#sortable) | String | allow controls to be reordered by users | `true` | `false` |
8+
| [groupOrder](#groupOrder) | Array | allow controls to be reordered by users | `['html', 'layout']` | `['common', 'html', 'layout']` |
9+
10+
## sortable
11+
12+
```javascript
13+
const controlOptions = {
14+
sortable: true,
15+
}
16+
17+
const formeoOptions = {
18+
controls: controlOptions,
19+
}
20+
21+
const formeo = new FormeoEditor(formeoOptions)
22+
```
23+
24+
## groupOrder
25+
26+
Set the group panel order with `groupOrder`
27+
28+
```javascript
29+
const controlOptions = {
30+
groupOrder: ['common', 'html'],
31+
}
32+
33+
const formeoOptions = {
34+
controls: controlOptions,
35+
}
36+
37+
const formeo = new FormeoEditor(formeoOptions)
38+
```

src/js/components/controls/html/header.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class HeaderControl extends Control {
2222
config: {
2323
label: i18n.get(headerKey),
2424
hideLabel: true,
25+
editableContent: true,
2526
},
2627
meta: {
2728
group: 'html',

src/js/components/controls/html/paragraph.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class ParagraphControl extends Control {
1111
config: {
1212
label: i18n.get('controls.html.paragraph'),
1313
hideLabel: true,
14-
editable: true,
14+
editableContent: true,
1515
},
1616
meta: {
1717
group: 'html',

src/js/components/fields/__snapshots__/field.spec.js.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Object {
2323
],
2424
},
2525
],
26+
"config": Object {},
2627
"id": "test-id",
2728
}
2829
`;

src/js/components/fields/field.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export default class Field extends Component {
6767
return
6868
}
6969

70-
const labelVal = this.get('config.label')
70+
const labelVal = this.get('config.editorLabel') || this.get('config.label')
7171
const required = this.get('attrs.required')
7272
const disableHTML = this.config.label.disableHTML
7373

@@ -251,6 +251,10 @@ export default class Field extends Component {
251251
const prevData = clone(this.data)
252252
prevData.id = `prev-${this.id}`
253253

254+
if (this.data.config.editableContent) {
255+
prevData.attrs = Object.assign({}, prevData.attrs, {contenteditable: true})
256+
}
257+
254258
const fieldPreview = {
255259
attrs: {
256260
className: 'field-preview',
@@ -279,11 +283,13 @@ export default class Field extends Component {
279283
}
280284
},
281285
input: evt => {
282-
if (evt.target.contentEditable === 'true') {
283-
super.set('attrs.value', evt.target.innerHTML)
284-
} else {
286+
if (['input', 'meter', 'progress', 'button'].includes(this.data.tag)) {
285287
super.set('attrs.value', evt.target.value)
286288
}
289+
290+
if (evt.target.contentEditable) {
291+
super.set('content', evt.target.innerHTML)
292+
}
287293
},
288294
},
289295
}

src/js/components/fields/field.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Field from './field'
2-
const fieldConfig = { id: 'test-id' }
2+
const fieldConfig = { id: 'test-id', config: {} }
33

44
describe('Field', () => {
55
it('should have data property matching snapshot', () => {

0 commit comments

Comments
 (0)