@ew-color-picker/input-number 2.0.0 → 2.0.1
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.
package/README.md
CHANGED
|
@@ -27,7 +27,7 @@ import '@ew-color-picker/style/dist/input-number.css'
|
|
|
27
27
|
|
|
28
28
|
## 相关链接
|
|
29
29
|
|
|
30
|
-
- 插件文档:https://eveningwater.github.io/ew-color-picker/plugins/input-number
|
|
30
|
+
- 插件文档:https://eveningwater.github.io/ew-color-picker/zh/plugins/input-number
|
|
31
31
|
- 源码仓库:https://github.com/eveningwater/ew-color-picker
|
|
32
32
|
|
|
33
33
|
## License
|
package/dist/input-number.esm.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* (c) 2024-2026 eveningwater(854806732@qq.com)
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
|
-
import { create, addClass, setAttr, upArrowIcon, downArrowIcon, insertNode, on, hasClass, removeClass, off, removeElement, isFunction, extend, debounce, isUndefined } from '@ew-color-picker/utils';
|
|
6
|
+
import { create, addClass, setAttr, upArrowIcon, downArrowIcon, insertNode, on, hasClass, removeClass, off, removeElement, isFunction, extend, debounce, DEFAULT_PREFIX, isUndefined, getPrefix } from '@ew-color-picker/utils';
|
|
7
7
|
|
|
8
8
|
/******************************************************************************
|
|
9
9
|
Copyright (c) Microsoft Corporation.
|
|
@@ -52,6 +52,7 @@ var InputNumber = /** @class */ (function () {
|
|
|
52
52
|
disabled: false,
|
|
53
53
|
placeholder: "",
|
|
54
54
|
size: "default",
|
|
55
|
+
prefix: DEFAULT_PREFIX,
|
|
55
56
|
onChange: function () { },
|
|
56
57
|
onBlur: function () { },
|
|
57
58
|
onFocus: function () { },
|
|
@@ -64,14 +65,22 @@ var InputNumber = /** @class */ (function () {
|
|
|
64
65
|
// 初始化时只同步显示值,不触发 onChange,避免实例创建阶段误改颜色
|
|
65
66
|
this.updateValue(this.currentValue, false);
|
|
66
67
|
}
|
|
68
|
+
Object.defineProperty(InputNumber.prototype, "prefix", {
|
|
69
|
+
get: function () {
|
|
70
|
+
return this.options.prefix || DEFAULT_PREFIX;
|
|
71
|
+
},
|
|
72
|
+
enumerable: false,
|
|
73
|
+
configurable: true
|
|
74
|
+
});
|
|
67
75
|
InputNumber.prototype.createElements = function () {
|
|
76
|
+
var p = this.prefix;
|
|
68
77
|
// 创建容器
|
|
69
78
|
this.container = create("div");
|
|
70
|
-
addClass(this.container, "
|
|
71
|
-
addClass(this.container, "
|
|
79
|
+
addClass(this.container, "".concat(p, "input-number"));
|
|
80
|
+
addClass(this.container, "".concat(p, "input-number--").concat(this.options.size));
|
|
72
81
|
// 创建输入框
|
|
73
82
|
this.input = create("input");
|
|
74
|
-
addClass(this.input, "
|
|
83
|
+
addClass(this.input, "".concat(p, "input-number__input"));
|
|
75
84
|
setAttr(this.input, {
|
|
76
85
|
type: "text",
|
|
77
86
|
inputmode: "decimal",
|
|
@@ -79,19 +88,19 @@ var InputNumber = /** @class */ (function () {
|
|
|
79
88
|
});
|
|
80
89
|
// 创建按钮容器
|
|
81
90
|
var buttonContainer = create("div");
|
|
82
|
-
addClass(buttonContainer, "
|
|
91
|
+
addClass(buttonContainer, "".concat(p, "input-number__buttons"));
|
|
83
92
|
// 创建上按钮
|
|
84
93
|
this.upButton = create("button");
|
|
85
|
-
addClass(this.upButton, "
|
|
86
|
-
addClass(this.upButton, "
|
|
94
|
+
addClass(this.upButton, "".concat(p, "input-number__button"));
|
|
95
|
+
addClass(this.upButton, "".concat(p, "input-number__button--up"));
|
|
87
96
|
setAttr(this.upButton, { type: "button" });
|
|
88
|
-
this.upButton.innerHTML = upArrowIcon();
|
|
97
|
+
this.upButton.innerHTML = upArrowIcon(undefined, undefined, p);
|
|
89
98
|
// 创建下按钮
|
|
90
99
|
this.downButton = create("button");
|
|
91
|
-
addClass(this.downButton, "
|
|
92
|
-
addClass(this.downButton, "
|
|
100
|
+
addClass(this.downButton, "".concat(p, "input-number__button"));
|
|
101
|
+
addClass(this.downButton, "".concat(p, "input-number__button--down"));
|
|
93
102
|
setAttr(this.downButton, { type: "button" });
|
|
94
|
-
this.downButton.innerHTML = downArrowIcon();
|
|
103
|
+
this.downButton.innerHTML = downArrowIcon(undefined, undefined, p);
|
|
95
104
|
// 组装DOM结构
|
|
96
105
|
insertNode(buttonContainer, this.upButton);
|
|
97
106
|
insertNode(buttonContainer, this.downButton);
|
|
@@ -136,7 +145,7 @@ var InputNumber = /** @class */ (function () {
|
|
|
136
145
|
};
|
|
137
146
|
InputNumber.prototype.handleBlur = function (event) {
|
|
138
147
|
this.isFocused = false;
|
|
139
|
-
this.removeClass(this.container, "
|
|
148
|
+
this.removeClass(this.container, "".concat(this.prefix, "input-number--focused"));
|
|
140
149
|
// 应用精度限制和边界检查
|
|
141
150
|
this.updateValue(this.currentValue, false);
|
|
142
151
|
// 触发blur回调
|
|
@@ -144,7 +153,7 @@ var InputNumber = /** @class */ (function () {
|
|
|
144
153
|
};
|
|
145
154
|
InputNumber.prototype.handleFocus = function (event) {
|
|
146
155
|
this.isFocused = true;
|
|
147
|
-
this.addClass(this.container, "
|
|
156
|
+
this.addClass(this.container, "".concat(this.prefix, "input-number--focused"));
|
|
148
157
|
// 触发focus回调
|
|
149
158
|
this.options.onFocus(event);
|
|
150
159
|
};
|
|
@@ -239,13 +248,13 @@ var InputNumber = /** @class */ (function () {
|
|
|
239
248
|
InputNumber.prototype.setDisabled = function (disabled) {
|
|
240
249
|
this.options.disabled = disabled;
|
|
241
250
|
if (disabled) {
|
|
242
|
-
this.addClass(this.container, "
|
|
251
|
+
this.addClass(this.container, "".concat(this.prefix, "input-number--disabled"));
|
|
243
252
|
setAttr(this.input, { disabled: "true" });
|
|
244
253
|
setAttr(this.upButton, { disabled: "true" });
|
|
245
254
|
setAttr(this.downButton, { disabled: "true" });
|
|
246
255
|
}
|
|
247
256
|
else {
|
|
248
|
-
this.removeClass(this.container, "
|
|
257
|
+
this.removeClass(this.container, "".concat(this.prefix, "input-number--disabled"));
|
|
249
258
|
setAttr(this.input, { disabled: "false" });
|
|
250
259
|
setAttr(this.upButton, { disabled: "false" });
|
|
251
260
|
setAttr(this.downButton, { disabled: "false" });
|
|
@@ -315,14 +324,16 @@ var ewColorPickerInputNumberPlugin = /** @class */ (function () {
|
|
|
315
324
|
ewColorPickerInputNumberPlugin.prototype.run = function () {
|
|
316
325
|
if (!this.ewColorPicker)
|
|
317
326
|
return;
|
|
327
|
+
var prefix = getPrefix(this.ewColorPicker);
|
|
318
328
|
var inputNumber = this.createInputNumber({
|
|
319
329
|
value: 0,
|
|
320
330
|
disabled: this.options.disabled || false,
|
|
331
|
+
prefix: prefix,
|
|
321
332
|
});
|
|
322
333
|
this.instances.set("default", inputNumber);
|
|
323
334
|
var panelContainer = this.ewColorPicker.getMountPoint("panelContainer");
|
|
324
335
|
if (panelContainer) {
|
|
325
|
-
var bottomRow = panelContainer.querySelector(".
|
|
336
|
+
var bottomRow = panelContainer.querySelector(".".concat(prefix, "color-picker-bottom-row"));
|
|
326
337
|
if (bottomRow) {
|
|
327
338
|
bottomRow.appendChild(inputNumber.getElement());
|
|
328
339
|
}
|
package/dist/input-number.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
((t,
|
|
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})});
|
|
@@ -8,6 +8,7 @@ export interface InputNumberOptions {
|
|
|
8
8
|
disabled?: boolean;
|
|
9
9
|
placeholder?: string;
|
|
10
10
|
size?: "small" | "default" | "large";
|
|
11
|
+
prefix?: string;
|
|
11
12
|
onChange?: (value: number) => void;
|
|
12
13
|
onBlur?: (value: number) => void;
|
|
13
14
|
onFocus?: (event: FocusEvent) => void;
|
|
@@ -20,6 +21,7 @@ export default class InputNumber {
|
|
|
20
21
|
private downButton;
|
|
21
22
|
private currentValue;
|
|
22
23
|
private isFocused;
|
|
24
|
+
private get prefix();
|
|
23
25
|
private debouncedOnChange;
|
|
24
26
|
ewColorPicker: ewColorPicker;
|
|
25
27
|
handleOptions?: () => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ew-color-picker/input-number",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
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",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"rollup-plugin-typescript2": "^0.34.0",
|
|
26
26
|
"typescript": "^4.9.0",
|
|
27
27
|
"rimraf": "^3.0.2",
|
|
28
|
-
"@ew-color-picker/
|
|
29
|
-
"@ew-color-picker/
|
|
28
|
+
"@ew-color-picker/utils": "2.0.1",
|
|
29
|
+
"@ew-color-picker/core": "2.0.1"
|
|
30
30
|
},
|
|
31
31
|
"publishConfig": {
|
|
32
32
|
"access": "public"
|