juxscript 1.1.251 → 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.
- package/dist/lib/components/input.d.ts +43 -0
- package/dist/lib/components/input.d.ts.map +1 -0
- package/dist/lib/components/input.js +99 -0
- package/dist/lib/components/tag.d.ts +13 -13
- package/dist/lib/components/tag.d.ts.map +1 -1
- package/dist/lib/components/tag.js +15 -22
- package/dist/lib/index.d.ts +4 -2
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +5 -3
- package/package.json +1 -1
|
@@ -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.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../../../lib/components/input.ts"],"names":[],"mappings":"AAEA,KAAK,SAAS,GAAG,MAAM,GAAG,OAAO,GAAG,UAAU,GAAG,QAAQ,GAAG,KAAK,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,gBAAgB,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,QAAQ,CAAC;AAElK,UAAU,YAAY;IAClB,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACtB,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,cAAM,KAAK;IACP,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,YAAY,CAAC;IACtB,OAAO,CAAC,QAAQ,CAAiC;IACjD,OAAO,CAAC,QAAQ,CAA4B;IAC5C,OAAO,CAAC,SAAS,CAAwD;gBAE7D,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB;IASlD,IAAI,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI;IAC5B,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAC1B,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 };
|
|
@@ -5,19 +5,19 @@ declare class Tag {
|
|
|
5
5
|
tagName: string;
|
|
6
6
|
constructor(data: any);
|
|
7
7
|
modify(): this;
|
|
8
|
-
render(
|
|
8
|
+
render(): HTMLElement;
|
|
9
9
|
}
|
|
10
10
|
export declare function tag(data: any): Tag;
|
|
11
|
-
export declare function div(data
|
|
12
|
-
export declare function span(data
|
|
13
|
-
export declare function p(data
|
|
14
|
-
export declare function code(data
|
|
15
|
-
export declare function pre(data
|
|
16
|
-
export declare function h1(data
|
|
17
|
-
export declare function h2(data
|
|
18
|
-
export declare function h3(data
|
|
19
|
-
export declare function h4(data
|
|
20
|
-
export declare function h5(data
|
|
21
|
-
export declare function h6(data
|
|
22
|
-
export
|
|
11
|
+
export declare function div(data?: any): Tag;
|
|
12
|
+
export declare function span(data?: any): Tag;
|
|
13
|
+
export declare function p(data?: any): Tag;
|
|
14
|
+
export declare function code(data?: any): Tag;
|
|
15
|
+
export declare function pre(data?: any): Tag;
|
|
16
|
+
export declare function h1(data?: any): Tag;
|
|
17
|
+
export declare function h2(data?: any): Tag;
|
|
18
|
+
export declare function h3(data?: any): Tag;
|
|
19
|
+
export declare function h4(data?: any): Tag;
|
|
20
|
+
export declare function h5(data?: any): Tag;
|
|
21
|
+
export declare function h6(data?: any): Tag;
|
|
22
|
+
export default tag;
|
|
23
23
|
//# sourceMappingURL=tag.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tag.d.ts","sourceRoot":"","sources":["../../../lib/components/tag.ts"],"names":[],"mappings":"AAEA,cAAM,GAAG;IACL,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC7B,OAAO,EAAE,MAAM,CAAC;gBAEJ,IAAI,EAAE,GAAG;IAOrB,MAAM;IAIN,MAAM
|
|
1
|
+
{"version":3,"file":"tag.d.ts","sourceRoot":"","sources":["../../../lib/components/tag.ts"],"names":[],"mappings":"AAEA,cAAM,GAAG;IACL,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC7B,OAAO,EAAE,MAAM,CAAC;gBAEJ,IAAI,EAAE,GAAG;IAOrB,MAAM;IAIN,MAAM;CAWT;AAED,wBAAgB,GAAG,CAAC,IAAI,EAAE,GAAG,OAI5B;AAED,wBAAgB,GAAG,CAAC,IAAI,GAAE,GAAQ,OAA8C;AAChF,wBAAgB,IAAI,CAAC,IAAI,GAAE,GAAQ,OAA+C;AAClF,wBAAgB,CAAC,CAAC,IAAI,GAAE,GAAQ,OAA4C;AAC5E,wBAAgB,IAAI,CAAC,IAAI,GAAE,GAAQ,OAA+C;AAClF,wBAAgB,GAAG,CAAC,IAAI,GAAE,GAAQ,OAA8C;AAChF,wBAAgB,EAAE,CAAC,IAAI,GAAE,GAAQ,OAA6C;AAC9E,wBAAgB,EAAE,CAAC,IAAI,GAAE,GAAQ,OAA6C;AAC9E,wBAAgB,EAAE,CAAC,IAAI,GAAE,GAAQ,OAA6C;AAC9E,wBAAgB,EAAE,CAAC,IAAI,GAAE,GAAQ,OAA6C;AAC9E,wBAAgB,EAAE,CAAC,IAAI,GAAE,GAAQ,OAA6C;AAC9E,wBAAgB,EAAE,CAAC,IAAI,GAAE,GAAQ,OAA6C;AAE9E,eAAe,GAAG,CAAC"}
|
|
@@ -9,23 +9,15 @@ class Tag {
|
|
|
9
9
|
modify() {
|
|
10
10
|
return this;
|
|
11
11
|
}
|
|
12
|
-
render(
|
|
12
|
+
render() {
|
|
13
13
|
const el = document.createElement(this.tagName);
|
|
14
14
|
el.id = this.id;
|
|
15
15
|
el.textContent = this.content;
|
|
16
16
|
for (const [key, value] of Object.entries(this.options)) {
|
|
17
17
|
el.setAttribute(key, String(value));
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
? document.getElementById(target) || document.querySelector(target)
|
|
22
|
-
: target;
|
|
23
|
-
container?.appendChild(el);
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
const app = document.getElementById('app');
|
|
27
|
-
app?.appendChild(el);
|
|
28
|
-
}
|
|
19
|
+
const app = document.getElementById('app');
|
|
20
|
+
app?.appendChild(el);
|
|
29
21
|
return el;
|
|
30
22
|
}
|
|
31
23
|
}
|
|
@@ -34,14 +26,15 @@ export function tag(data) {
|
|
|
34
26
|
t.render();
|
|
35
27
|
return t;
|
|
36
28
|
}
|
|
37
|
-
export function div(data) { return tag({ ...data, tagName: 'div' }); }
|
|
38
|
-
export function span(data) { return tag({ ...data, tagName: 'span' }); }
|
|
39
|
-
export function p(data) { return tag({ ...data, tagName: 'p' }); }
|
|
40
|
-
export function code(data) { return tag({ ...data, tagName: 'code' }); }
|
|
41
|
-
export function pre(data) { return tag({ ...data, tagName: 'pre' }); }
|
|
42
|
-
export function h1(data) { return tag({ ...data, tagName: 'h1' }); }
|
|
43
|
-
export function h2(data) { return tag({ ...data, tagName: 'h2' }); }
|
|
44
|
-
export function h3(data) { return tag({ ...data, tagName: 'h3' }); }
|
|
45
|
-
export function h4(data) { return tag({ ...data, tagName: 'h4' }); }
|
|
46
|
-
export function h5(data) { return tag({ ...data, tagName: 'h5' }); }
|
|
47
|
-
export function h6(data) { return tag({ ...data, tagName: 'h6' }); }
|
|
29
|
+
export function div(data = {}) { return tag({ ...data, tagName: 'div' }); }
|
|
30
|
+
export function span(data = {}) { return tag({ ...data, tagName: 'span' }); }
|
|
31
|
+
export function p(data = {}) { return tag({ ...data, tagName: 'p' }); }
|
|
32
|
+
export function code(data = {}) { return tag({ ...data, tagName: 'code' }); }
|
|
33
|
+
export function pre(data = {}) { return tag({ ...data, tagName: 'pre' }); }
|
|
34
|
+
export function h1(data = {}) { return tag({ ...data, tagName: 'h1' }); }
|
|
35
|
+
export function h2(data = {}) { return tag({ ...data, tagName: 'h2' }); }
|
|
36
|
+
export function h3(data = {}) { return tag({ ...data, tagName: 'h3' }); }
|
|
37
|
+
export function h4(data = {}) { return tag({ ...data, tagName: 'h4' }); }
|
|
38
|
+
export function h5(data = {}) { return tag({ ...data, tagName: 'h5' }); }
|
|
39
|
+
export function h6(data = {}) { return tag({ ...data, tagName: 'h6' }); }
|
|
40
|
+
export default tag;
|
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
|
};
|