Skip to content

Commit

Permalink
implement vue-color in Apostrophe (#4803)
Browse files Browse the repository at this point in the history
* 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
stuartromanek authored Nov 14, 2024
1 parent ca1e5df commit 96eac29
Show file tree
Hide file tree
Showing 17 changed files with 1,239 additions and 56 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ did not actually use any noncompliant cookie names or values, so there was no vu
### Changes

* Removes postcss plugin and webpack loader used for breakpoint preview mode. Uses instead the new `postcss-viewport-to-container-toggle` plugin in the webpack config.
* Implement `vue-color` directly in Apostrophe rather than as a dependency
* Switch color handling library from `tinycolor2` to `@ctrl/tinycolor`
* Removes error messages in server console for hidden fields. These messages should not have been printed out in the server console in the first place.
* Removes invalid error messages on select fields appearing while opening an existing valid document.

Expand Down
24 changes: 24 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,27 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Portions derived from vue-color require the following statement:

MIT License

Copyright (c) 2021 chenkai0520

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1 change: 1 addition & 0 deletions defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ module.exports = {
'@apostrophecms/rich-text-widget': {},
'@apostrophecms/html-widget': {},
'@apostrophecms/image-widget': {},
'@apostrophecms/color-field': {},
'@apostrophecms/oembed-field': {},
'@apostrophecms/video-widget': {},
'@apostrophecms/ui': {},
Expand Down
44 changes: 44 additions & 0 deletions modules/@apostrophecms/color-field/index.js
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
};
}
};
}
};
Loading

0 comments on commit 96eac29

Please sign in to comment.