@ew-color-picker/input-number 2.0.2 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -94,13 +94,13 @@ var InputNumber = /** @class */ (function () {
94
94
  addClass(this.upButton, "".concat(p, "input-number__button"));
95
95
  addClass(this.upButton, "".concat(p, "input-number__button--up"));
96
96
  setAttr(this.upButton, { type: "button" });
97
- this.upButton.innerHTML = upArrowIcon(undefined, undefined, p);
97
+ this.upButton.innerHTML = upArrowIcon("".concat(p, "input-number__icon"), undefined, p);
98
98
  // 创建下按钮
99
99
  this.downButton = create("button");
100
100
  addClass(this.downButton, "".concat(p, "input-number__button"));
101
101
  addClass(this.downButton, "".concat(p, "input-number__button--down"));
102
102
  setAttr(this.downButton, { type: "button" });
103
- this.downButton.innerHTML = downArrowIcon(undefined, undefined, p);
103
+ this.downButton.innerHTML = downArrowIcon("".concat(p, "input-number__icon"), undefined, p);
104
104
  // 组装DOM结构
105
105
  insertNode(buttonContainer, this.upButton);
106
106
  insertNode(buttonContainer, this.downButton);
@@ -242,8 +242,10 @@ var InputNumber = /** @class */ (function () {
242
242
  InputNumber.prototype.getValue = function () {
243
243
  return this.currentValue;
244
244
  };
245
- InputNumber.prototype.setValue = function (value) {
246
- this.updateValue(value);
245
+ InputNumber.prototype.setValue = function (value, triggerChange) {
246
+ if (triggerChange === void 0) { triggerChange = true; }
247
+ // triggerChange 为 false 时只同步显示值与内部值,不触发 onChange
248
+ this.updateValue(value, triggerChange);
247
249
  };
248
250
  InputNumber.prototype.setDisabled = function (disabled) {
249
251
  this.options.disabled = disabled;
@@ -1 +1 @@
1
- ((t,n)=>{"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("@ew-color-picker/utils")):"function"==typeof define&&define.amd?define(["exports","@ew-color-picker/utils"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).InputNumber={},t.Utils)})(this,function(t,e){var n=function(){return(n=Object.assign||function(t){for(var n,i=1,e=arguments.length;i<e;i++)for(var o in n=arguments[i])Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o]);return t}).apply(this,arguments)},i=(Object.defineProperty(o.prototype,"prefix",{get:function(){return this.options.prefix||e.DEFAULT_PREFIX},enumerable:!1,configurable:!0}),o.prototype.createElements=function(){var t=this.prefix,n=(this.container=e.create("div"),e.addClass(this.container,"".concat(t,"input-number")),e.addClass(this.container,"".concat(t,"input-number--").concat(this.options.size)),this.input=e.create("input"),e.addClass(this.input,"".concat(t,"input-number__input")),e.setAttr(this.input,{type:"text",inputmode:"decimal",placeholder:this.options.placeholder}),e.create("div"));e.addClass(n,"".concat(t,"input-number__buttons")),this.upButton=e.create("button"),e.addClass(this.upButton,"".concat(t,"input-number__button")),e.addClass(this.upButton,"".concat(t,"input-number__button--up")),e.setAttr(this.upButton,{type:"button"}),this.upButton.innerHTML=e.upArrowIcon(void 0,void 0,t),this.downButton=e.create("button"),e.addClass(this.downButton,"".concat(t,"input-number__button")),e.addClass(this.downButton,"".concat(t,"input-number__button--down")),e.setAttr(this.downButton,{type:"button"}),this.downButton.innerHTML=e.downArrowIcon(void 0,void 0,t),e.insertNode(n,this.upButton),e.insertNode(n,this.downButton),e.insertNode(this.container,this.input),e.insertNode(this.container,n),this.setStyles()},o.prototype.setStyles=function(){this.options.disabled&&this.setDisabled(!0)},o.prototype.bindEvents=function(){e.on(this.input,"input",this.handleInput.bind(this)),e.on(this.input,"blur",this.handleBlur.bind(this)),e.on(this.input,"focus",this.handleFocus.bind(this)),e.on(this.input,"keydown",this.handleKeydown.bind(this)),e.on(this.upButton,"click",this.handleUpClick.bind(this)),e.on(this.downButton,"click",this.handleDownClick.bind(this)),e.on(this.container,"wheel",this.handleWheel.bind(this))},o.prototype.handleInput=function(t){var t=t.target.value;""!==t&&"-"!==t&&"."!==t&&(t=parseFloat(t),isNaN(t)?this.input.value=this.currentValue.toString():this.currentValue=t)},o.prototype.handleBlur=function(t){this.isFocused=!1,this.removeClass(this.container,"".concat(this.prefix,"input-number--focused")),this.updateValue(this.currentValue,!1),this.options.onBlur(this.currentValue)},o.prototype.handleFocus=function(t){this.isFocused=!0,this.addClass(this.container,"".concat(this.prefix,"input-number--focused")),this.options.onFocus(t)},o.prototype.handleKeydown=function(t){switch(t.key){case"ArrowUp":t.preventDefault(),this.increment();break;case"ArrowDown":t.preventDefault(),this.decrement();break;case"Enter":t.preventDefault(),this.input.blur()}},o.prototype.handleUpClick=function(){this.options.disabled||this.increment()},o.prototype.handleDownClick=function(){this.options.disabled||this.decrement()},o.prototype.handleWheel=function(t){this.isFocused&&!this.options.disabled&&(t.preventDefault(),t.deltaY<0?this.increment():this.decrement())},o.prototype.increment=function(){var t=this.currentValue+this.options.step;this.updateValue(t)},o.prototype.decrement=function(){var t=this.currentValue-this.options.step;this.updateValue(t)},o.prototype.updateValue=function(t,n){void 0===n&&(n=!0);var i=this.options.min,e=this.options.max,i=(t<i?t=i:e<t&&(t=e),this.options.precision);t=Math.round(t*Math.pow(10,i))/Math.pow(10,i),this.currentValue=t,this.formatDisplayValue(),n&&this.debouncedOnChange(t)},o.prototype.formatDisplayValue=function(){var t=this.options.precision;this.input.value=this.currentValue.toFixed(t)},o.prototype.addClass=function(t,n){e.hasClass(t,n)||e.addClass(t,n)},o.prototype.removeClass=function(t,n){e.hasClass(t,n)&&e.removeClass(t,n)},o.prototype.getValue=function(){return this.currentValue},o.prototype.setValue=function(t){this.updateValue(t)},o.prototype.setDisabled=function(t){(this.options.disabled=t)?(this.addClass(this.container,"".concat(this.prefix,"input-number--disabled")),e.setAttr(this.input,{disabled:"true"}),e.setAttr(this.upButton,{disabled:"true"}),e.setAttr(this.downButton,{disabled:"true"})):(this.removeClass(this.container,"".concat(this.prefix,"input-number--disabled")),e.setAttr(this.input,{disabled:"false"}),e.setAttr(this.upButton,{disabled:"false"}),e.setAttr(this.downButton,{disabled:"false"}))},o.prototype.getElement=function(){return this.container},o.prototype.destroy=function(){var t;e.off(this.input,"input",this.handleInput.bind(this)),e.off(this.input,"blur",this.handleBlur.bind(this)),e.off(this.input,"focus",this.handleFocus.bind(this)),e.off(this.input,"keydown",this.handleKeydown.bind(this)),e.off(this.upButton,"click",this.handleUpClick.bind(this)),e.off(this.downButton,"click",this.handleDownClick.bind(this)),e.off(this.container,"wheel",this.handleWheel.bind(this)),null!=(t=this.container)&&t.parentNode&&e.removeElement(this.container),this.container=null,this.input=null,this.upButton=null,this.downButton=null},o.prototype.install=function(t){var n;this.ewColorPicker=t,null!=(n=this.handleOptions)&&n.call(this),!1!==(null==(n=this.ewColorPicker.options)?void 0:n.showInputNumber)&&(e.isFunction(t.on)&&t.on("change",function(){}),null!=(n=this.run))&&n.call(this)},o);function o(t){void 0===t&&(t={});var n={value:0,min:-1/0,max:1/0,step:1,precision:0,disabled:this.isFocused=!1,placeholder:"",size:"default",prefix:e.DEFAULT_PREFIX,onChange:function(){},onBlur:function(){},onFocus:function(){}};this.options=e.extend(n,t),this.currentValue=null!=(n=this.options.value)?n:0,this.debouncedOnChange=e.debounce(this.options.onChange,300),this.createElements(),this.bindEvents(),this.updateValue(this.currentValue,!1)}u.prototype.install=function(t){this.ewColorPicker=t,this.handleOptions(),this.run()},u.prototype.updateOptions=function(){var n=this;this.handleOptions(),this.instances.forEach(function(t){e.isUndefined(n.options.disabled)||t.setDisabled(n.options.disabled)})},u.prototype.run=function(){var t,n,i;this.ewColorPicker&&(t=e.getPrefix(this.ewColorPicker),n=this.createInputNumber({value:0,disabled:this.options.disabled||!1,prefix:t}),this.instances.set("default",n),i=this.ewColorPicker.getMountPoint("panelContainer"))&&(i=i.querySelector(".".concat(t,"color-picker-bottom-row")))&&i.appendChild(n.getElement())},u.prototype.handleOptions=function(){var t=null==(t=this.ewColorPicker)?void 0:t.options;t&&(this.options=n(n(n({},this.options),t),{disabled:e.isUndefined(t.disabled)?this.options.disabled||!1:t.disabled}))},u.prototype.createInputNumber=function(t){return new i(t)},u.prototype.destroy=function(){this.instances.forEach(function(t){t.destroy()}),this.instances.clear(),this.ewColorPicker=null},u.pluginName="ewColorPickerInputNumber",u.applyOrder="post";var s=u;function u(t){this.options={},this.instances=new Map,this.ewColorPicker=t,this.handleOptions()}t.InputNumber=i,t.default=s,t.ewColorPickerInputNumberPlugin=s,Object.defineProperty(t,"__esModule",{value:!0})});
1
+ ((t,n)=>{"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("@ew-color-picker/utils")):"function"==typeof define&&define.amd?define(["exports","@ew-color-picker/utils"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).InputNumber={},t.Utils)})(this,function(t,e){var n=function(){return(n=Object.assign||function(t){for(var n,i=1,e=arguments.length;i<e;i++)for(var o in n=arguments[i])Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o]);return t}).apply(this,arguments)},i=(Object.defineProperty(o.prototype,"prefix",{get:function(){return this.options.prefix||e.DEFAULT_PREFIX},enumerable:!1,configurable:!0}),o.prototype.createElements=function(){var t=this.prefix,n=(this.container=e.create("div"),e.addClass(this.container,"".concat(t,"input-number")),e.addClass(this.container,"".concat(t,"input-number--").concat(this.options.size)),this.input=e.create("input"),e.addClass(this.input,"".concat(t,"input-number__input")),e.setAttr(this.input,{type:"text",inputmode:"decimal",placeholder:this.options.placeholder}),e.create("div"));e.addClass(n,"".concat(t,"input-number__buttons")),this.upButton=e.create("button"),e.addClass(this.upButton,"".concat(t,"input-number__button")),e.addClass(this.upButton,"".concat(t,"input-number__button--up")),e.setAttr(this.upButton,{type:"button"}),this.upButton.innerHTML=e.upArrowIcon("".concat(t,"input-number__icon"),void 0,t),this.downButton=e.create("button"),e.addClass(this.downButton,"".concat(t,"input-number__button")),e.addClass(this.downButton,"".concat(t,"input-number__button--down")),e.setAttr(this.downButton,{type:"button"}),this.downButton.innerHTML=e.downArrowIcon("".concat(t,"input-number__icon"),void 0,t),e.insertNode(n,this.upButton),e.insertNode(n,this.downButton),e.insertNode(this.container,this.input),e.insertNode(this.container,n),this.setStyles()},o.prototype.setStyles=function(){this.options.disabled&&this.setDisabled(!0)},o.prototype.bindEvents=function(){e.on(this.input,"input",this.handleInput.bind(this)),e.on(this.input,"blur",this.handleBlur.bind(this)),e.on(this.input,"focus",this.handleFocus.bind(this)),e.on(this.input,"keydown",this.handleKeydown.bind(this)),e.on(this.upButton,"click",this.handleUpClick.bind(this)),e.on(this.downButton,"click",this.handleDownClick.bind(this)),e.on(this.container,"wheel",this.handleWheel.bind(this))},o.prototype.handleInput=function(t){var t=t.target.value;""!==t&&"-"!==t&&"."!==t&&(t=parseFloat(t),isNaN(t)?this.input.value=this.currentValue.toString():this.currentValue=t)},o.prototype.handleBlur=function(t){this.isFocused=!1,this.removeClass(this.container,"".concat(this.prefix,"input-number--focused")),this.updateValue(this.currentValue,!1),this.options.onBlur(this.currentValue)},o.prototype.handleFocus=function(t){this.isFocused=!0,this.addClass(this.container,"".concat(this.prefix,"input-number--focused")),this.options.onFocus(t)},o.prototype.handleKeydown=function(t){switch(t.key){case"ArrowUp":t.preventDefault(),this.increment();break;case"ArrowDown":t.preventDefault(),this.decrement();break;case"Enter":t.preventDefault(),this.input.blur()}},o.prototype.handleUpClick=function(){this.options.disabled||this.increment()},o.prototype.handleDownClick=function(){this.options.disabled||this.decrement()},o.prototype.handleWheel=function(t){this.isFocused&&!this.options.disabled&&(t.preventDefault(),t.deltaY<0?this.increment():this.decrement())},o.prototype.increment=function(){var t=this.currentValue+this.options.step;this.updateValue(t)},o.prototype.decrement=function(){var t=this.currentValue-this.options.step;this.updateValue(t)},o.prototype.updateValue=function(t,n){void 0===n&&(n=!0);var i=this.options.min,e=this.options.max,i=(t<i?t=i:e<t&&(t=e),this.options.precision);t=Math.round(t*Math.pow(10,i))/Math.pow(10,i),this.currentValue=t,this.formatDisplayValue(),n&&this.debouncedOnChange(t)},o.prototype.formatDisplayValue=function(){var t=this.options.precision;this.input.value=this.currentValue.toFixed(t)},o.prototype.addClass=function(t,n){e.hasClass(t,n)||e.addClass(t,n)},o.prototype.removeClass=function(t,n){e.hasClass(t,n)&&e.removeClass(t,n)},o.prototype.getValue=function(){return this.currentValue},o.prototype.setValue=function(t,n){this.updateValue(t,n=void 0===n?!0:n)},o.prototype.setDisabled=function(t){(this.options.disabled=t)?(this.addClass(this.container,"".concat(this.prefix,"input-number--disabled")),e.setAttr(this.input,{disabled:"true"}),e.setAttr(this.upButton,{disabled:"true"}),e.setAttr(this.downButton,{disabled:"true"})):(this.removeClass(this.container,"".concat(this.prefix,"input-number--disabled")),e.setAttr(this.input,{disabled:"false"}),e.setAttr(this.upButton,{disabled:"false"}),e.setAttr(this.downButton,{disabled:"false"}))},o.prototype.getElement=function(){return this.container},o.prototype.destroy=function(){var t;e.off(this.input,"input",this.handleInput.bind(this)),e.off(this.input,"blur",this.handleBlur.bind(this)),e.off(this.input,"focus",this.handleFocus.bind(this)),e.off(this.input,"keydown",this.handleKeydown.bind(this)),e.off(this.upButton,"click",this.handleUpClick.bind(this)),e.off(this.downButton,"click",this.handleDownClick.bind(this)),e.off(this.container,"wheel",this.handleWheel.bind(this)),null!=(t=this.container)&&t.parentNode&&e.removeElement(this.container),this.container=null,this.input=null,this.upButton=null,this.downButton=null},o.prototype.install=function(t){var n;this.ewColorPicker=t,null!=(n=this.handleOptions)&&n.call(this),!1!==(null==(n=this.ewColorPicker.options)?void 0:n.showInputNumber)&&(e.isFunction(t.on)&&t.on("change",function(){}),null!=(n=this.run))&&n.call(this)},o);function o(t){void 0===t&&(t={});var n={value:0,min:-1/0,max:1/0,step:1,precision:0,disabled:this.isFocused=!1,placeholder:"",size:"default",prefix:e.DEFAULT_PREFIX,onChange:function(){},onBlur:function(){},onFocus:function(){}};this.options=e.extend(n,t),this.currentValue=null!=(n=this.options.value)?n:0,this.debouncedOnChange=e.debounce(this.options.onChange,300),this.createElements(),this.bindEvents(),this.updateValue(this.currentValue,!1)}u.prototype.install=function(t){this.ewColorPicker=t,this.handleOptions(),this.run()},u.prototype.updateOptions=function(){var n=this;this.handleOptions(),this.instances.forEach(function(t){e.isUndefined(n.options.disabled)||t.setDisabled(n.options.disabled)})},u.prototype.run=function(){var t,n,i;this.ewColorPicker&&(t=e.getPrefix(this.ewColorPicker),n=this.createInputNumber({value:0,disabled:this.options.disabled||!1,prefix:t}),this.instances.set("default",n),i=this.ewColorPicker.getMountPoint("panelContainer"))&&(i=i.querySelector(".".concat(t,"color-picker-bottom-row")))&&i.appendChild(n.getElement())},u.prototype.handleOptions=function(){var t=null==(t=this.ewColorPicker)?void 0:t.options;t&&(this.options=n(n(n({},this.options),t),{disabled:e.isUndefined(t.disabled)?this.options.disabled||!1:t.disabled}))},u.prototype.createInputNumber=function(t){return new i(t)},u.prototype.destroy=function(){this.instances.forEach(function(t){t.destroy()}),this.instances.clear(),this.ewColorPicker=null},u.pluginName="ewColorPickerInputNumber",u.applyOrder="post";var s=u;function u(t){this.options={},this.instances=new Map,this.ewColorPicker=t,this.handleOptions()}t.InputNumber=i,t.default=s,t.ewColorPickerInputNumberPlugin=s,Object.defineProperty(t,"__esModule",{value:!0})});
@@ -44,7 +44,7 @@ export default class InputNumber {
44
44
  private addClass;
45
45
  private removeClass;
46
46
  getValue(): number;
47
- setValue(value: number): void;
47
+ setValue(value: number, triggerChange?: boolean): void;
48
48
  setDisabled(disabled: boolean): void;
49
49
  getElement(): HTMLElement;
50
50
  destroy(): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ew-color-picker/input-number",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "description": "EW Color Picker Input Number Plugin",
5
5
  "main": "dist/input-number.min.js",
6
6
  "module": "dist/input-number.esm.js",
@@ -11,22 +11,24 @@
11
11
  "keywords": [
12
12
  "color-picker",
13
13
  "input-number",
14
+ "numeric-input",
14
15
  "plugin",
15
- "typescript"
16
+ "typescript",
17
+ "ui"
16
18
  ],
17
19
  "author": "eveningwater(854806732@qq.com)",
18
20
  "license": "MIT",
19
21
  "dependencies": {
20
- "@ew-color-picker/core": "^2.0.2",
21
- "@ew-color-picker/utils": "^2.0.2"
22
+ "@ew-color-picker/core": "^2.0.3",
23
+ "@ew-color-picker/utils": "^2.0.3"
22
24
  },
23
25
  "devDependencies": {
24
26
  "rollup": "^3.0.0",
25
27
  "rollup-plugin-typescript2": "^0.34.0",
26
28
  "typescript": "^4.9.0",
27
29
  "rimraf": "^3.0.2",
28
- "@ew-color-picker/core": "2.0.2",
29
- "@ew-color-picker/utils": "2.0.2"
30
+ "@ew-color-picker/utils": "2.0.3",
31
+ "@ew-color-picker/core": "2.0.3"
30
32
  },
31
33
  "publishConfig": {
32
34
  "access": "public"