-
Notifications
You must be signed in to change notification settings - Fork 592
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement vue-color in Apostrophe (#4803)
* wip * implementation * prevent closing one color select * cleanup * remove import from rt colorpicker * move sub components out of /components * specify ext * ext * ext * more clean * changelog * changelog * lint
- Loading branch information
1 parent
ca1e5df
commit 96eac29
Showing
17 changed files
with
1,239 additions
and
56 deletions.
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
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
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
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,44 @@ | ||
const { TinyColor } = require('@ctrl/tinycolor'); | ||
const _ = require('lodash'); | ||
|
||
module.exports = { | ||
options: { | ||
name: 'color', | ||
alias: 'colorFields' | ||
}, | ||
init(self) { | ||
self.name = self.options.name; | ||
self.addFieldType(); | ||
self.enableBrowserData(); | ||
}, | ||
methods(self) { | ||
return { | ||
addFieldType() { | ||
self.apos.schema.addFieldType({ | ||
name: 'color', | ||
async convert(req, field, data, destination) { | ||
destination[field.name] = self.apos.launder.string(data[field.name]); | ||
|
||
if (field.required && (_.isUndefined(destination[field.name]) || !destination[field.name].toString().length)) { | ||
throw self.apos.error('required'); | ||
} | ||
|
||
const test = new TinyColor(destination[field.name]); | ||
if (!test.isValid) { | ||
destination[field.name] = null; | ||
} | ||
}, | ||
isEmpty: function (field, value) { | ||
return !value.length; | ||
} | ||
}); | ||
}, | ||
getBrowserData(req) { | ||
return { | ||
name: self.name, | ||
action: self.action | ||
}; | ||
} | ||
}; | ||
} | ||
}; |
Oops, something went wrong.