diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b3c5fcaa9..937cca39a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/LICENSE.md b/LICENSE.md index 2dfb61b633..73ec097e55 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -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. \ No newline at end of file diff --git a/defaults.js b/defaults.js index 0312284ca5..4cbefd2f9f 100644 --- a/defaults.js +++ b/defaults.js @@ -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': {}, diff --git a/modules/@apostrophecms/color-field/index.js b/modules/@apostrophecms/color-field/index.js new file mode 100644 index 0000000000..bae839cc18 --- /dev/null +++ b/modules/@apostrophecms/color-field/index.js @@ -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 + }; + } + }; + } +}; diff --git a/modules/@apostrophecms/color-field/ui/apos/components/AposColor.vue b/modules/@apostrophecms/color-field/ui/apos/components/AposColor.vue new file mode 100644 index 0000000000..b9614a7f42 --- /dev/null +++ b/modules/@apostrophecms/color-field/ui/apos/components/AposColor.vue @@ -0,0 +1,316 @@ + + + + + diff --git a/modules/@apostrophecms/schema/ui/apos/components/AposInputColor.vue b/modules/@apostrophecms/color-field/ui/apos/components/AposInputColor.vue similarity index 72% rename from modules/@apostrophecms/schema/ui/apos/components/AposInputColor.vue rename to modules/@apostrophecms/color-field/ui/apos/components/AposInputColor.vue index be61f6a472..7dd54fd128 100644 --- a/modules/@apostrophecms/schema/ui/apos/components/AposInputColor.vue +++ b/modules/@apostrophecms/color-field/ui/apos/components/AposInputColor.vue @@ -7,8 +7,8 @@ :display-options="displayOptions" >