Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement vue-color in Apostrophe #4803

Merged
merged 17 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,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
Loading