Skip to content

Commit

Permalink
Support to remove colorstop with alt key
Browse files Browse the repository at this point in the history
  • Loading branch information
easylogic committed Jul 12, 2019
1 parent cffd643 commit 322a28b
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 39 deletions.
65 changes: 53 additions & 12 deletions addon/colorpicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -5277,10 +5277,10 @@ var EventMachin = function () {
value: function checkEventType(e, eventObject) {
var _this8 = this;

var onlyControl = e.ctrlKey ? eventObject.isControl : true;
var onlyShift = e.shiftKey ? eventObject.isShift : true;
var onlyAlt = e.altKey ? eventObject.isAlt : true;
var onlyMeta = e.metaKey ? eventObject.isMeta : true;
var onlyControl = eventObject.isControl ? e.ctrlKey : true;
var onlyShift = eventObject.isShift ? e.shiftKey : true;
var onlyAlt = eventObject.isAlt ? e.altKey : true;
var onlyMeta = eventObject.isMeta ? e.metaKey : true;

var hasKeyCode = true;
if (eventObject.codes.length) {
Expand Down Expand Up @@ -9719,6 +9719,12 @@ var GradientEditor = function (_UIElement) {
offset: Length.percent(percent),
color: 'rgba(0, 0, 0, 1)'
});
} else {
this.colorsteps.push({
cut: false,
offset: Length.percent(0),
color: 'rgba(0, 0, 0, 1)'
});
}

this.refresh();
Expand All @@ -9741,6 +9747,24 @@ var GradientEditor = function (_UIElement) {
this.updateData();
}
}
}, {
key: "removeStep",
value: function removeStep(index) {
if (this.colorsteps.length === 2) return;
this.colorsteps.splice(index, 1);
var currentStep = this.colorsteps[index];
var currentIndex = index;
if (!currentStep) {
currentStep = this.colorsteps[index - 1];
currentIndex = index - 1;
}

if (currentStep) {
this.selectStep(currentIndex);
}
this.refresh();
this.updateData();
}
}, {
key: "selectStep",
value: function selectStep(index) {
Expand All @@ -9761,14 +9785,20 @@ var GradientEditor = function (_UIElement) {
value: function mousedown$stepListStep(e) {
var index = +e.$delegateTarget.attr('data-index');

this.selectStep(index);
if (e.altKey) {
this.removeStep(index);
// return false;
} else {

this.startXY = e.xy;
this.$store.emit('selectColorStep', this.currentStep.color);
this.refs.$cut.checked(this.currentStep.cut);
this.refs.$offset.val(this.currentStep.offset.value);
this.refs.$stepList.attr('data-selected-index', index);
this.cachedStepListRect = this.refs.$stepList.rect();
this.selectStep(index);

this.startXY = e.xy;
this.$store.emit('selectColorStep', this.currentStep.color);
this.refs.$cut.checked(this.currentStep.cut);
this.refs.$offset.val(this.currentStep.offset.value);
this.refs.$stepList.attr('data-selected-index', index);
this.cachedStepListRect = this.refs.$stepList.rect();
}
}
}, {
key: "getStepListRect",
Expand All @@ -9785,7 +9815,6 @@ var GradientEditor = function (_UIElement) {
}, {
key: 'mousemove document',
value: function mousemoveDocument(e) {

if (!this.startXY) return;

var dx = e.xy.x - this.startXY.x;
Expand Down Expand Up @@ -9832,6 +9861,15 @@ var GradientEditor = function (_UIElement) {
value: function getLinearGradient() {
var _this3 = this;

if (this.colorsteps.length === 0) {
return '';
}

if (this.colorsteps.length === 1) {
var colorstep = this.colorsteps[0];
return "linear-gradient(to right, " + colorstep.color + " " + colorstep.offset + ", " + colorstep.color + " 100%)";
}

return "linear-gradient(to right, " + this.colorsteps.map(function (it, index) {

if (it.cut) {
Expand Down Expand Up @@ -9975,6 +10013,7 @@ var LinearGradient = function (_Gradient) {
}, {
key: "toString",
value: function toString() {
if (this.colorsteps.length === 0) return '';
var colorString = this.getColorString();

var opt = '';
Expand Down Expand Up @@ -10109,6 +10148,7 @@ var RadialGradient = function (_Gradient) {
}, {
key: "toString",
value: function toString() {
if (this.colorsteps.length === 0) return '';
var colorString = this.getColorString();
var json = this.json;
var opt = '';
Expand Down Expand Up @@ -10267,6 +10307,7 @@ var ConicGradient = function (_Gradient) {
}, {
key: "getColorString",
value: function getColorString() {
if (this.colorsteps.length === 0) return '';
var colorsteps = this.colorsteps;
if (!colorsteps) return '';

Expand Down
65 changes: 53 additions & 12 deletions dist/colorpicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -5356,10 +5356,10 @@ var EventMachin = function () {
value: function checkEventType(e, eventObject) {
var _this8 = this;

var onlyControl = e.ctrlKey ? eventObject.isControl : true;
var onlyShift = e.shiftKey ? eventObject.isShift : true;
var onlyAlt = e.altKey ? eventObject.isAlt : true;
var onlyMeta = e.metaKey ? eventObject.isMeta : true;
var onlyControl = eventObject.isControl ? e.ctrlKey : true;
var onlyShift = eventObject.isShift ? e.shiftKey : true;
var onlyAlt = eventObject.isAlt ? e.altKey : true;
var onlyMeta = eventObject.isMeta ? e.metaKey : true;

var hasKeyCode = true;
if (eventObject.codes.length) {
Expand Down Expand Up @@ -9799,6 +9799,12 @@ var GradientEditor = function (_UIElement) {
offset: Length.percent(percent),
color: 'rgba(0, 0, 0, 1)'
});
} else {
this.colorsteps.push({
cut: false,
offset: Length.percent(0),
color: 'rgba(0, 0, 0, 1)'
});
}

this.refresh();
Expand All @@ -9821,6 +9827,24 @@ var GradientEditor = function (_UIElement) {
this.updateData();
}
}
}, {
key: "removeStep",
value: function removeStep(index) {
if (this.colorsteps.length === 2) return;
this.colorsteps.splice(index, 1);
var currentStep = this.colorsteps[index];
var currentIndex = index;
if (!currentStep) {
currentStep = this.colorsteps[index - 1];
currentIndex = index - 1;
}

if (currentStep) {
this.selectStep(currentIndex);
}
this.refresh();
this.updateData();
}
}, {
key: "selectStep",
value: function selectStep(index) {
Expand All @@ -9841,14 +9865,20 @@ var GradientEditor = function (_UIElement) {
value: function mousedown$stepListStep(e) {
var index = +e.$delegateTarget.attr('data-index');

this.selectStep(index);
if (e.altKey) {
this.removeStep(index);
// return false;
} else {

this.startXY = e.xy;
this.$store.emit('selectColorStep', this.currentStep.color);
this.refs.$cut.checked(this.currentStep.cut);
this.refs.$offset.val(this.currentStep.offset.value);
this.refs.$stepList.attr('data-selected-index', index);
this.cachedStepListRect = this.refs.$stepList.rect();
this.selectStep(index);

this.startXY = e.xy;
this.$store.emit('selectColorStep', this.currentStep.color);
this.refs.$cut.checked(this.currentStep.cut);
this.refs.$offset.val(this.currentStep.offset.value);
this.refs.$stepList.attr('data-selected-index', index);
this.cachedStepListRect = this.refs.$stepList.rect();
}
}
}, {
key: "getStepListRect",
Expand All @@ -9865,7 +9895,6 @@ var GradientEditor = function (_UIElement) {
}, {
key: 'mousemove document',
value: function mousemoveDocument(e) {

if (!this.startXY) return;

var dx = e.xy.x - this.startXY.x;
Expand Down Expand Up @@ -9912,6 +9941,15 @@ var GradientEditor = function (_UIElement) {
value: function getLinearGradient() {
var _this3 = this;

if (this.colorsteps.length === 0) {
return '';
}

if (this.colorsteps.length === 1) {
var colorstep = this.colorsteps[0];
return "linear-gradient(to right, " + colorstep.color + " " + colorstep.offset + ", " + colorstep.color + " 100%)";
}

return "linear-gradient(to right, " + this.colorsteps.map(function (it, index) {

if (it.cut) {
Expand Down Expand Up @@ -10055,6 +10093,7 @@ var LinearGradient = function (_Gradient) {
}, {
key: "toString",
value: function toString() {
if (this.colorsteps.length === 0) return '';
var colorString = this.getColorString();

var opt = '';
Expand Down Expand Up @@ -10189,6 +10228,7 @@ var RadialGradient = function (_Gradient) {
}, {
key: "toString",
value: function toString() {
if (this.colorsteps.length === 0) return '';
var colorString = this.getColorString();
var json = this.json;
var opt = '';
Expand Down Expand Up @@ -10347,6 +10387,7 @@ var ConicGradient = function (_Gradient) {
}, {
key: "getColorString",
value: function getColorString() {
if (this.colorsteps.length === 0) return '';
var colorsteps = this.colorsteps;
if (!colorsteps) return '';

Expand Down
2 changes: 1 addition & 1 deletion dist/colorpicker.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@easylogic/colorpicker",
"version": "1.9.61",
"version": "1.9.62",
"description": "simple colorpicker used anywhere",
"main": "./dist/colorpicker.js",
"scripts": {
Expand Down
58 changes: 49 additions & 9 deletions src/gradient/GradientEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,13 @@ export default class GradientEditor extends UIElement {
offset: Length.percent(percent),
color: 'rgba(0, 0, 0, 1)'
})
}
} else {
this.colorsteps.push({
cut: false,
offset: Length.percent(0),
color: 'rgba(0, 0, 0, 1)'
})
}

this.refresh();
this.updateData();
Expand All @@ -298,6 +304,25 @@ export default class GradientEditor extends UIElement {
}
}


removeStep(index) {
if (this.colorsteps.length === 2) return;
this.colorsteps.splice(index, 1);
var currentStep = this.colorsteps[index]
var currentIndex = index;
if (!currentStep) {
currentStep = this.colorsteps[index-1]
currentIndex = index - 1;
}

if (currentStep) {
this.selectStep(currentIndex);
}
this.refresh();
this.updateData();
}


selectStep(index) {
this.index = index;
this.currentStep = this.colorsteps[index];
Expand All @@ -318,14 +343,20 @@ export default class GradientEditor extends UIElement {
'mousedown $stepList .step' (e) {
var index = +e.$delegateTarget.attr('data-index')

this.selectStep(index);
if (e.altKey) {
this.removeStep(index);
// return false;
} else {

this.startXY = e.xy;
this.$store.emit('selectColorStep', this.currentStep.color)
this.refs.$cut.checked(this.currentStep.cut);
this.refs.$offset.val(this.currentStep.offset.value);
this.refs.$stepList.attr('data-selected-index', index);
this.cachedStepListRect = this.refs.$stepList.rect();
this.selectStep(index);

this.startXY = e.xy;
this.$store.emit('selectColorStep', this.currentStep.color)
this.refs.$cut.checked(this.currentStep.cut);
this.refs.$offset.val(this.currentStep.offset.value);
this.refs.$stepList.attr('data-selected-index', index);
this.cachedStepListRect = this.refs.$stepList.rect();
}
}


Expand All @@ -341,7 +372,6 @@ export default class GradientEditor extends UIElement {
}

'mousemove document' (e) {

if (!this.startXY) return;

var dx = e.xy.x - this.startXY.x;
Expand Down Expand Up @@ -388,6 +418,16 @@ export default class GradientEditor extends UIElement {
}

getLinearGradient () {
if (this.colorsteps.length === 0) {
return '';
}

if (this.colorsteps.length === 1) {
var colorstep = this.colorsteps[0];
return `linear-gradient(to right, ${colorstep.color} ${colorstep.offset}, ${colorstep.color} 100%)`
}


return `linear-gradient(to right, ${this.colorsteps.map((it, index) => {
if (it.cut) {
Expand Down
1 change: 1 addition & 0 deletions src/gradient/image-resource/ConicGradient.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class ConicGradient extends Gradient {
}

getColorString() {
if(this.colorsteps.length === 0) return '';
var colorsteps = this.colorsteps;
if (!colorsteps) return '';

Expand Down
1 change: 1 addition & 0 deletions src/gradient/image-resource/LinearGradient.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export class LinearGradient extends Gradient {
}

toString() {
if(this.colorsteps.length === 0) return '';
var colorString = this.getColorString();

var opt = '';
Expand Down
1 change: 1 addition & 0 deletions src/gradient/image-resource/RadialGradient.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class RadialGradient extends Gradient {
}

toString() {
if(this.colorsteps.length === 0) return '';
var colorString = this.getColorString();
var json = this.json;
var opt = '';
Expand Down
8 changes: 4 additions & 4 deletions src/util/EventMachin.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,10 @@ export default class EventMachin {
}

checkEventType (e, eventObject ) {
var onlyControl = e.ctrlKey ? eventObject.isControl : true;
var onlyShift = e.shiftKey ? eventObject.isShift : true;
var onlyAlt = e.altKey ? eventObject.isAlt : true;
var onlyMeta = e.metaKey ? eventObject.isMeta : true;
var onlyControl = eventObject.isControl ? e.ctrlKey : true;
var onlyShift = eventObject.isShift ? e.shiftKey : true;
var onlyAlt = eventObject.isAlt ? e.altKey : true;
var onlyMeta = eventObject.isMeta ? e.metaKey : true;

var hasKeyCode = true;
if (eventObject.codes.length) {
Expand Down

0 comments on commit 322a28b

Please sign in to comment.