juxscript 1.1.252 → 1.1.253
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.
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
type InputType = 'text' | 'email' | 'password' | 'number' | 'tel' | 'url' | 'search' | 'date' | 'time' | 'datetime-local' | 'color' | 'range' | 'file' | 'hidden';
|
|
2
|
+
interface InputOptions {
|
|
3
|
+
type?: InputType;
|
|
4
|
+
label?: string;
|
|
5
|
+
placeholder?: string;
|
|
6
|
+
value?: string;
|
|
7
|
+
name?: string;
|
|
8
|
+
required?: boolean;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
readonly?: boolean;
|
|
11
|
+
min?: string | number;
|
|
12
|
+
max?: string | number;
|
|
13
|
+
step?: string | number;
|
|
14
|
+
pattern?: string;
|
|
15
|
+
autocomplete?: string;
|
|
16
|
+
class?: string;
|
|
17
|
+
style?: string;
|
|
18
|
+
}
|
|
19
|
+
declare class Input {
|
|
20
|
+
id: string;
|
|
21
|
+
options: InputOptions;
|
|
22
|
+
private _element;
|
|
23
|
+
private _wrapper;
|
|
24
|
+
private _onChange;
|
|
25
|
+
constructor(id: string, options?: InputOptions);
|
|
26
|
+
type(value: InputType): this;
|
|
27
|
+
label(value: string): this;
|
|
28
|
+
placeholder(value: string): this;
|
|
29
|
+
value(value: string): this;
|
|
30
|
+
name(value: string): this;
|
|
31
|
+
required(value?: boolean): this;
|
|
32
|
+
disabled(value?: boolean): this;
|
|
33
|
+
readonly(value?: boolean): this;
|
|
34
|
+
style(value: string): this;
|
|
35
|
+
class(value: string): this;
|
|
36
|
+
onChange(fn: (value: string, event: Event) => void): this;
|
|
37
|
+
getValue(): string;
|
|
38
|
+
setValue(val: string): this;
|
|
39
|
+
render(target?: string | HTMLElement): this;
|
|
40
|
+
}
|
|
41
|
+
export declare function input(id: string, options?: InputOptions): Input;
|
|
42
|
+
export { Input, InputOptions };
|
|
43
|
+
//# sourceMappingURL=input.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AC1B,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAChC,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAC1B,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IACzB,QAAQ,CAAC,KAAK,GAAE,OAAc,GAAG,IAAI;IACrC,QAAQ,CAAC,KAAK,GAAE,OAAc,GAAG,IAAI;IACrC,QAAQ,CAAC,KAAK,GAAE,OAAc,GAAG,IAAI;IACrC,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAC1B,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAE1B,QAAQ,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,KAAK,IAAI,GAAG,IAAI;IAKzD,QAAQ,IAAI,MAAM;IAIlB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAM3B,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,WAAW;CA8CvC;AAED,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB,GAAG,KAAK,CAInE;AAED,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import generateId from '../utils/idgen.js';
|
|
2
|
+
class Input {
|
|
3
|
+
constructor(id, options = {}) {
|
|
4
|
+
this._element = null;
|
|
5
|
+
this._wrapper = null;
|
|
6
|
+
this._onChange = null;
|
|
7
|
+
this.id = id || generateId();
|
|
8
|
+
this.options = {
|
|
9
|
+
type: 'text',
|
|
10
|
+
...options
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
// Fluent API
|
|
14
|
+
type(value) { this.options.type = value; return this; }
|
|
15
|
+
label(value) { this.options.label = value; return this; }
|
|
16
|
+
placeholder(value) { this.options.placeholder = value; return this; }
|
|
17
|
+
value(value) { this.options.value = value; if (this._element)
|
|
18
|
+
this._element.value = value; return this; }
|
|
19
|
+
name(value) { this.options.name = value; return this; }
|
|
20
|
+
required(value = true) { this.options.required = value; return this; }
|
|
21
|
+
disabled(value = true) { this.options.disabled = value; if (this._element)
|
|
22
|
+
this._element.disabled = value; return this; }
|
|
23
|
+
readonly(value = true) { this.options.readonly = value; return this; }
|
|
24
|
+
style(value) { this.options.style = value; return this; }
|
|
25
|
+
class(value) { this.options.class = value; return this; }
|
|
26
|
+
onChange(fn) {
|
|
27
|
+
this._onChange = fn;
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
getValue() {
|
|
31
|
+
return this._element?.value ?? this.options.value ?? '';
|
|
32
|
+
}
|
|
33
|
+
setValue(val) {
|
|
34
|
+
if (this._element)
|
|
35
|
+
this._element.value = val;
|
|
36
|
+
this.options.value = val;
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
render(target) {
|
|
40
|
+
const wrapper = document.createElement('div');
|
|
41
|
+
wrapper.className = 'jux-input';
|
|
42
|
+
wrapper.id = `${this.id}-wrapper`;
|
|
43
|
+
if (this.options.class)
|
|
44
|
+
wrapper.className += ` ${this.options.class}`;
|
|
45
|
+
if (this.options.style)
|
|
46
|
+
wrapper.setAttribute('style', this.options.style);
|
|
47
|
+
if (this.options.label) {
|
|
48
|
+
const labelEl = document.createElement('label');
|
|
49
|
+
labelEl.htmlFor = this.id;
|
|
50
|
+
labelEl.textContent = this.options.label;
|
|
51
|
+
labelEl.className = 'jux-input-label';
|
|
52
|
+
wrapper.appendChild(labelEl);
|
|
53
|
+
}
|
|
54
|
+
const input = document.createElement('input');
|
|
55
|
+
input.id = this.id;
|
|
56
|
+
input.type = this.options.type || 'text';
|
|
57
|
+
input.className = 'jux-input-element';
|
|
58
|
+
if (this.options.placeholder)
|
|
59
|
+
input.placeholder = this.options.placeholder;
|
|
60
|
+
if (this.options.value)
|
|
61
|
+
input.value = this.options.value;
|
|
62
|
+
if (this.options.name)
|
|
63
|
+
input.name = this.options.name;
|
|
64
|
+
if (this.options.required)
|
|
65
|
+
input.required = true;
|
|
66
|
+
if (this.options.disabled)
|
|
67
|
+
input.disabled = true;
|
|
68
|
+
if (this.options.readonly)
|
|
69
|
+
input.readOnly = true;
|
|
70
|
+
if (this.options.min != null)
|
|
71
|
+
input.min = String(this.options.min);
|
|
72
|
+
if (this.options.max != null)
|
|
73
|
+
input.max = String(this.options.max);
|
|
74
|
+
if (this.options.step != null)
|
|
75
|
+
input.step = String(this.options.step);
|
|
76
|
+
if (this.options.pattern)
|
|
77
|
+
input.pattern = this.options.pattern;
|
|
78
|
+
if (this.options.autocomplete)
|
|
79
|
+
input.autocomplete = this.options.autocomplete;
|
|
80
|
+
input.addEventListener('input', (e) => {
|
|
81
|
+
if (this._onChange)
|
|
82
|
+
this._onChange(input.value, e);
|
|
83
|
+
});
|
|
84
|
+
wrapper.appendChild(input);
|
|
85
|
+
this._element = input;
|
|
86
|
+
this._wrapper = wrapper;
|
|
87
|
+
const container = target
|
|
88
|
+
? (typeof target === 'string' ? document.getElementById(target) || document.querySelector(target) : target)
|
|
89
|
+
: document.getElementById('app');
|
|
90
|
+
container?.appendChild(wrapper);
|
|
91
|
+
return this;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
export function input(id, options = {}) {
|
|
95
|
+
const inp = new Input(id, options);
|
|
96
|
+
inp.render();
|
|
97
|
+
return inp;
|
|
98
|
+
}
|
|
99
|
+
export { Input };
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { tag, div, h1, h2, h3, h4, h5, h6, p, span, pre } from "./components/tag";
|
|
2
|
-
import { include } from "./components/include";
|
|
1
|
+
import { tag, div, h1, h2, h3, h4, h5, h6, p, span, pre } from "./components/tag.js";
|
|
2
|
+
import { include } from "./components/include.js";
|
|
3
|
+
import { input } from "./components/input.js";
|
|
3
4
|
export declare const jux: {
|
|
4
5
|
tag: typeof tag;
|
|
5
6
|
div: typeof div;
|
|
@@ -13,5 +14,6 @@ export declare const jux: {
|
|
|
13
14
|
span: typeof span;
|
|
14
15
|
pre: typeof pre;
|
|
15
16
|
include: typeof include;
|
|
17
|
+
input: typeof input;
|
|
16
18
|
};
|
|
17
19
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;AACrF,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAE9C,eAAO,MAAM,GAAG;;;;;;;;;;;;;;CASf,CAAA"}
|
package/dist/lib/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { tag, div, h1, h2, h3, h4, h5, h6, p, span, pre } from "./components/tag";
|
|
2
|
-
import { include } from "./components/include";
|
|
1
|
+
import { tag, div, h1, h2, h3, h4, h5, h6, p, span, pre } from "./components/tag.js";
|
|
2
|
+
import { include } from "./components/include.js";
|
|
3
|
+
import { input } from "./components/input.js";
|
|
3
4
|
export const jux = {
|
|
4
5
|
tag,
|
|
5
6
|
div,
|
|
@@ -7,5 +8,6 @@ export const jux = {
|
|
|
7
8
|
p,
|
|
8
9
|
span,
|
|
9
10
|
pre,
|
|
10
|
-
include
|
|
11
|
+
include,
|
|
12
|
+
input
|
|
11
13
|
};
|