Skip to content

Commit

Permalink
feat: formData setter
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinchappell committed Aug 30, 2020
1 parent 22ed800 commit 0534285
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 10 deletions.
35 changes: 35 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@
"comments": false,
"plugins": [
"@babel/plugin-proposal-object-rest-spread",
"@babel/plugin-proposal-class-properties"
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-optional-chaining"
]
},
"scripts": {
Expand All @@ -92,6 +93,7 @@
"@babel/node": "^7.2.2",
"@babel/plugin-proposal-class-properties": "^7.4.0",
"@babel/plugin-proposal-object-rest-spread": "^7.4.0",
"@babel/plugin-proposal-optional-chaining": "^7.9.0",
"@babel/preset-env": "^7.4.2",
"@commitlint/cli": "^7.5.2",
"@commitlint/config-angular": "^7.5.0",
Expand Down
2 changes: 1 addition & 1 deletion src/js/components/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default class Data {
}
getData = () => {
return Object.entries(this.data).reduce((acc, [key, val]) => {
acc[key] = val.data ? val.getData() : val
acc[key] = val?.data ? val.getData() : val
return acc
}, {})
}
Expand Down
2 changes: 1 addition & 1 deletion src/js/components/fields/edit-panel-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ export default class EditPanelItem {
return segmentTypes[key](val)
}

console.error(`${key}: invalid confirguration`)
console.error(`${key}: invalid condition attribute`)
}

get itemControls() {
Expand Down
2 changes: 1 addition & 1 deletion src/js/components/fields/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ export default class Field extends Component {
const prevData = clone(this.data)
prevData.id = `prev-${this.id}`

if (this.data.config.editableContent) {
if (this.data?.config.editableContent) {
prevData.attrs = Object.assign({}, prevData.attrs, { contenteditable: true })
}

Expand Down
3 changes: 2 additions & 1 deletion src/js/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ export class Components extends Data {
}
}

load = (formData, opts = Object.create(null)) => {
load = (formData, opts = this.opts || Object.create(null)) => {
this.empty()
if (typeof formData === 'string') {
formData = JSON.parse(formData)
}
Expand Down
3 changes: 3 additions & 0 deletions src/js/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ export class FormeoEditor {
get formData() {
return this.Components.formData
}
set formData(data) {
return this.load(data, this.opts)
}
get json() {
return this.Components.json
}
Expand Down
10 changes: 5 additions & 5 deletions tools/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const extractTextLoader = !IS_PRODUCTION
? {
loader: 'style-loader',
options: {
sourceMap: !IS_PRODUCTION,
sourceMap: true,
},
}
: MiniCssExtractPlugin.loader
Expand Down Expand Up @@ -126,7 +126,7 @@ const webpackConfig = {
options: {
camelCase: true,
minimize: true,
sourceMap: !IS_PRODUCTION,
sourceMap: true,
},
},
{
Expand All @@ -137,13 +137,13 @@ const webpackConfig = {
browsers: ['> 1%'],
}),
],
sourceMap: !IS_PRODUCTION,
sourceMap: true,
},
},
{
loader: 'sass-loader',
options: {
sourceMap: !IS_PRODUCTION,
sourceMap: true,
},
},
],
Expand All @@ -157,7 +157,7 @@ const webpackConfig = {
new UglifyJsPlugin({
cache: true,
parallel: true,
sourceMap: !IS_PRODUCTION,
sourceMap: true,
}),
new OptimizeCSSAssetsPlugin(),
],
Expand Down

0 comments on commit 0534285

Please sign in to comment.