generated from hugomods/template-mod
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add the url widget and todo editor component
- Loading branch information
Showing
9 changed files
with
97 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,4 @@ jobs: | |
with: | ||
node-version: 16 | ||
- run: npm ci | ||
# - run: npm run lint | ||
- run: npm run eslint |
29 changes: 29 additions & 0 deletions
29
editor-components/todo/assets/decap-cms/editor-components/todo.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
export default { | ||
id: 'todo', | ||
label: 'Todo', | ||
fields: [ | ||
{ | ||
name: 'done', | ||
label: 'Done', | ||
widget: 'boolean' | ||
}, | ||
{ | ||
name: 'title', | ||
label: 'Title', | ||
widget: 'string' | ||
} | ||
], | ||
pattern: /^-\s*\[([\sx])\]\s*(.+?)$/ms, | ||
fromBlock: function (match) { | ||
return { | ||
done: match[1] === 'x', | ||
title: match[2] | ||
} | ||
}, | ||
toBlock: function (data) { | ||
return `- [${data.done ? 'x' : ' '}] ${data.title}` | ||
}, | ||
toPreview: function (data) { | ||
return `<p><input ${data.done ? ' checked' : ''} disabled type="checkbox">${data.title}</p>` | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module github.com/hugomods/decap-cms/editor-components/todo | ||
|
||
go 1.21.3 | ||
|
||
require github.com/hugomods/decap-cms v0.4.0 // indirect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github.com/hugomods/decap-cms v0.4.0 h1:DGUWeog+IlQaNXsd5Vm3esoqzy/K66lpQwEVP3lT28c= | ||
github.com/hugomods/decap-cms v0.4.0/go.mod h1:P9gUtk59PZYBCNVIqiovRPqI13WiKkutMtJl2YQLkMA= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[[module.imports]] | ||
path = "github.com/hugomods/decap-cms" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
export const name = 'url' | ||
|
||
// eslint-disable-next-line no-undef | ||
export const control = createClass({ | ||
handleChange: function (e) { | ||
this.props.onChange(e.target.value) | ||
}, | ||
|
||
render: function () { | ||
const value = this.props.value | ||
// eslint-disable-next-line no-undef | ||
return h('input', { | ||
id: this.props.forID, | ||
className: this.props.classNameWrapper, | ||
type: 'url', | ||
value: value ?? '', | ||
onChange: this.handleChange | ||
}) | ||
}, | ||
|
||
isValid: function () { | ||
try { | ||
const url = new URL(this.props.value) | ||
|
||
const protocols = this.props.field.get('protocols') | ||
if (protocols && !protocols.includes(url.protocol)) { | ||
return { | ||
error: { | ||
message: 'invalid protocol.' | ||
} | ||
} | ||
} | ||
|
||
return true | ||
} catch (e) { | ||
return { | ||
error: { | ||
message: 'invalid URL.' | ||
} | ||
} | ||
} | ||
} | ||
}) | ||
|
||
export const schema = { | ||
properties: { | ||
protocols: { type: 'array' } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module github.com/hugomods/decap-cms/widgets/url | ||
|
||
go 1.21.3 | ||
|
||
require github.com/hugomods/decap-cms v0.4.0 // indirect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github.com/hugomods/decap-cms v0.4.0 h1:DGUWeog+IlQaNXsd5Vm3esoqzy/K66lpQwEVP3lT28c= | ||
github.com/hugomods/decap-cms v0.4.0/go.mod h1:P9gUtk59PZYBCNVIqiovRPqI13WiKkutMtJl2YQLkMA= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[[module.imports]] | ||
path = "github.com/hugomods/decap-cms" |