Skip to content

Commit 96eac29

Browse files
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
1 parent ca1e5df commit 96eac29

File tree

17 files changed

+1239
-56
lines changed

17 files changed

+1239
-56
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ did not actually use any noncompliant cookie names or values, so there was no vu
2222
### Changes
2323

2424
* 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.
25+
* Implement `vue-color` directly in Apostrophe rather than as a dependency
26+
* Switch color handling library from `tinycolor2` to `@ctrl/tinycolor`
2527
* 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.
2628
* Removes invalid error messages on select fields appearing while opening an existing valid document.
2729

LICENSE.md

+24
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,27 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
55
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
66

77
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.
8+
9+
Portions derived from vue-color require the following statement:
10+
11+
MIT License
12+
13+
Copyright (c) 2021 chenkai0520
14+
15+
Permission is hereby granted, free of charge, to any person obtaining a copy
16+
of this software and associated documentation files (the "Software"), to deal
17+
in the Software without restriction, including without limitation the rights
18+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19+
copies of the Software, and to permit persons to whom the Software is
20+
furnished to do so, subject to the following conditions:
21+
22+
The above copyright notice and this permission notice shall be included in all
23+
copies or substantial portions of the Software.
24+
25+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31+
SOFTWARE.

defaults.js

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ module.exports = {
4444
'@apostrophecms/rich-text-widget': {},
4545
'@apostrophecms/html-widget': {},
4646
'@apostrophecms/image-widget': {},
47+
'@apostrophecms/color-field': {},
4748
'@apostrophecms/oembed-field': {},
4849
'@apostrophecms/video-widget': {},
4950
'@apostrophecms/ui': {},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const { TinyColor } = require('@ctrl/tinycolor');
2+
const _ = require('lodash');
3+
4+
module.exports = {
5+
options: {
6+
name: 'color',
7+
alias: 'colorFields'
8+
},
9+
init(self) {
10+
self.name = self.options.name;
11+
self.addFieldType();
12+
self.enableBrowserData();
13+
},
14+
methods(self) {
15+
return {
16+
addFieldType() {
17+
self.apos.schema.addFieldType({
18+
name: 'color',
19+
async convert(req, field, data, destination) {
20+
destination[field.name] = self.apos.launder.string(data[field.name]);
21+
22+
if (field.required && (_.isUndefined(destination[field.name]) || !destination[field.name].toString().length)) {
23+
throw self.apos.error('required');
24+
}
25+
26+
const test = new TinyColor(destination[field.name]);
27+
if (!test.isValid) {
28+
destination[field.name] = null;
29+
}
30+
},
31+
isEmpty: function (field, value) {
32+
return !value.length;
33+
}
34+
});
35+
},
36+
getBrowserData(req) {
37+
return {
38+
name: self.name,
39+
action: self.action
40+
};
41+
}
42+
};
43+
}
44+
};

0 commit comments

Comments
 (0)