@zcomponent/html 0.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/index.d.ts +1 -0
- package/index.js +2 -0
- package/lib/CSS.d.ts +21 -0
- package/lib/CSS.js +44 -0
- package/lib/HTMLElement.d.ts +140 -0
- package/lib/HTMLElement.js +174 -0
- package/lib/button.d.ts +11 -0
- package/lib/button.js +11 -0
- package/lib/context.d.ts +10 -0
- package/lib/context.js +13 -0
- package/lib/div.d.ts +11 -0
- package/lib/div.js +11 -0
- package/lib/img.d.ts +18 -0
- package/lib/img.js +18 -0
- package/lib/index.d.ts +0 -0
- package/lib/index.js +0 -0
- package/package.json +29 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lib';
|
package/index.js
ADDED
package/lib/CSS.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Component, ConstructorProps, ContextManager } from '@zcomponent/core';
|
|
2
|
+
interface CSSConstructorProps extends ConstructorProps {
|
|
3
|
+
/** @zprop
|
|
4
|
+
* @zvalues files *.css
|
|
5
|
+
*/
|
|
6
|
+
source: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The CSS component will ensure that the CSS file referenced by its `source` constructor prop is added to your page and loaded by the browser.
|
|
10
|
+
*
|
|
11
|
+
* This component is particularly useful if you'd like to style with CSS any HTML elements that you've added to your Hierarchy.
|
|
12
|
+
*
|
|
13
|
+
* @zcomponent
|
|
14
|
+
* @zicon html
|
|
15
|
+
*/
|
|
16
|
+
export declare class CSS extends Component<CSSConstructorProps> {
|
|
17
|
+
private _elm;
|
|
18
|
+
constructor(props: CSSConstructorProps, contextManager: ContextManager);
|
|
19
|
+
dispose(): never;
|
|
20
|
+
}
|
|
21
|
+
export {};
|
package/lib/CSS.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Component, registerLoadable } from '@zcomponent/core';
|
|
2
|
+
const alreadyAdded = new Map();
|
|
3
|
+
/**
|
|
4
|
+
* The CSS component will ensure that the CSS file referenced by its `source` constructor prop is added to your page and loaded by the browser.
|
|
5
|
+
*
|
|
6
|
+
* This component is particularly useful if you'd like to style with CSS any HTML elements that you've added to your Hierarchy.
|
|
7
|
+
*
|
|
8
|
+
* @zcomponent
|
|
9
|
+
* @zicon html
|
|
10
|
+
*/
|
|
11
|
+
export class CSS extends Component {
|
|
12
|
+
constructor(props, contextManager) {
|
|
13
|
+
super(props, contextManager);
|
|
14
|
+
if (!props.source)
|
|
15
|
+
return;
|
|
16
|
+
this._elm = alreadyAdded.get(props.source);
|
|
17
|
+
if (this._elm)
|
|
18
|
+
this._elm[0]++;
|
|
19
|
+
else {
|
|
20
|
+
this._elm = [1, document.createElement('link')];
|
|
21
|
+
registerLoadable(contextManager, new Promise((resolve, reject) => {
|
|
22
|
+
this._elm[1].addEventListener('load', resolve);
|
|
23
|
+
this._elm[1].addEventListener('error', reject);
|
|
24
|
+
}));
|
|
25
|
+
this._elm[1].setAttribute('rel', 'stylesheet');
|
|
26
|
+
this._elm[1].setAttribute('href', props.source);
|
|
27
|
+
if (document.head)
|
|
28
|
+
document.head.appendChild(this._elm[1]);
|
|
29
|
+
else if (document.body)
|
|
30
|
+
document.body.appendChild(this._elm[1]);
|
|
31
|
+
alreadyAdded.set(props.source, this._elm);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
dispose() {
|
|
35
|
+
if (this._elm) {
|
|
36
|
+
this._elm[0] = this._elm[0] - 1;
|
|
37
|
+
if (this._elm[0] <= 0) {
|
|
38
|
+
this._elm[1]?.remove();
|
|
39
|
+
alreadyAdded.delete(this.constructorProps.source);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return super.dispose();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { Component, ComponentChildren, ConstructorProps, ContextManager, Event, Observable } from '@zcomponent/core';
|
|
2
|
+
export interface HTMLElementProps extends ConstructorProps {
|
|
3
|
+
children?: ComponentChildren;
|
|
4
|
+
/** @zprop */
|
|
5
|
+
innerText?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare class ZHTMLElement<T extends HTMLElement> extends Component {
|
|
8
|
+
root: T;
|
|
9
|
+
/** @zprop */
|
|
10
|
+
onClick: Event<[MouseEvent]>;
|
|
11
|
+
constructor(props: HTMLElementProps, contextManager: ContextManager, root: T);
|
|
12
|
+
private _cssLengthObservable;
|
|
13
|
+
private _attachEvent;
|
|
14
|
+
/** @zprop */
|
|
15
|
+
id: Observable<string>;
|
|
16
|
+
/** @zprop */
|
|
17
|
+
classList: Observable<string[]>;
|
|
18
|
+
/** @zprop
|
|
19
|
+
* @zdefault [0, "px"]
|
|
20
|
+
* @zgroup Position
|
|
21
|
+
*/
|
|
22
|
+
left: Observable<[number, CSSLengthUnit] | undefined>;
|
|
23
|
+
/** @zprop
|
|
24
|
+
* @zdefault [0, "px"]
|
|
25
|
+
* @zgroup Position
|
|
26
|
+
*/
|
|
27
|
+
right: Observable<[number, CSSLengthUnit] | undefined>;
|
|
28
|
+
/** @zprop
|
|
29
|
+
* @zdefault [0, "px"]
|
|
30
|
+
* @zgroup Position
|
|
31
|
+
*/
|
|
32
|
+
top: Observable<[number, CSSLengthUnit] | undefined>;
|
|
33
|
+
/** @zprop
|
|
34
|
+
* @zdefault [0, "px"]
|
|
35
|
+
* @zgroup Position
|
|
36
|
+
*/
|
|
37
|
+
bottom: Observable<[number, CSSLengthUnit] | undefined>;
|
|
38
|
+
/** @zprop
|
|
39
|
+
* @zdefault [0, "px"]
|
|
40
|
+
* @zgroup Size
|
|
41
|
+
*/
|
|
42
|
+
width: Observable<[number, CSSLengthUnit] | undefined>;
|
|
43
|
+
/** @zprop
|
|
44
|
+
* @zdefault [0, "px"]
|
|
45
|
+
* @zgroup Size
|
|
46
|
+
*/
|
|
47
|
+
height: Observable<[number, CSSLengthUnit] | undefined>;
|
|
48
|
+
/** @zprop
|
|
49
|
+
* @zdefault [0, "px"]
|
|
50
|
+
* @zgroup Spacing
|
|
51
|
+
*/
|
|
52
|
+
marginLeft: Observable<[number, CSSLengthUnit] | undefined>;
|
|
53
|
+
/** @zprop
|
|
54
|
+
* @zdefault [0, "px"]
|
|
55
|
+
* @zgroup Spacing
|
|
56
|
+
*/
|
|
57
|
+
marginRight: Observable<[number, CSSLengthUnit] | undefined>;
|
|
58
|
+
/** @zprop
|
|
59
|
+
* @zdefault [0, "px"]
|
|
60
|
+
* @zgroup Spacing
|
|
61
|
+
*/
|
|
62
|
+
marginTop: Observable<[number, CSSLengthUnit] | undefined>;
|
|
63
|
+
/** @zprop
|
|
64
|
+
* @zdefault [0, "px"]
|
|
65
|
+
* @zgroup Spacing
|
|
66
|
+
*/
|
|
67
|
+
marginBottom: Observable<[number, CSSLengthUnit] | undefined>;
|
|
68
|
+
/** @zprop
|
|
69
|
+
* @zdefault [0, "px"]
|
|
70
|
+
* @zgroup Spacing
|
|
71
|
+
*/
|
|
72
|
+
paddingLeft: Observable<[number, CSSLengthUnit] | undefined>;
|
|
73
|
+
/** @zprop
|
|
74
|
+
* @zdefault [0, "px"]
|
|
75
|
+
* @zgroup Spacing
|
|
76
|
+
*/
|
|
77
|
+
paddingRight: Observable<[number, CSSLengthUnit] | undefined>;
|
|
78
|
+
/** @zprop
|
|
79
|
+
* @zdefault [0, "px"]
|
|
80
|
+
* @zgroup Spacing
|
|
81
|
+
*/
|
|
82
|
+
paddingTop: Observable<[number, CSSLengthUnit] | undefined>;
|
|
83
|
+
/** @zprop
|
|
84
|
+
* @zdefault [0, "px"]
|
|
85
|
+
* @zgroup Spacing
|
|
86
|
+
*/
|
|
87
|
+
paddingBottom: Observable<[number, CSSLengthUnit] | undefined>;
|
|
88
|
+
/** @zprop
|
|
89
|
+
* @zgroup Position
|
|
90
|
+
* @zdefault static
|
|
91
|
+
*/
|
|
92
|
+
position: Observable<CSSPosition>;
|
|
93
|
+
/** @zprop */
|
|
94
|
+
display: Observable<CSSDisplay | undefined>;
|
|
95
|
+
/** @zprop
|
|
96
|
+
* @zdefault row
|
|
97
|
+
*/
|
|
98
|
+
flexDirection: Observable<CSSFlexDirection>;
|
|
99
|
+
dispose(): never;
|
|
100
|
+
}
|
|
101
|
+
export declare enum CSSLengthUnit {
|
|
102
|
+
'cm' = "cm",
|
|
103
|
+
'mm' = "mm",
|
|
104
|
+
'in' = "in",
|
|
105
|
+
'px' = "px",
|
|
106
|
+
'pt' = "pt",
|
|
107
|
+
'pc' = "pc",
|
|
108
|
+
'em' = "em",
|
|
109
|
+
'ex' = "ex",
|
|
110
|
+
'ch' = "ch",
|
|
111
|
+
'rem' = "rem",
|
|
112
|
+
'vw' = "vw",
|
|
113
|
+
'vh' = "vh",
|
|
114
|
+
'vmin' = "vmin",
|
|
115
|
+
'vmax' = "vmax",
|
|
116
|
+
'%' = "%"
|
|
117
|
+
}
|
|
118
|
+
export declare enum CSSPosition {
|
|
119
|
+
'static' = "static",
|
|
120
|
+
'relative' = "relative",
|
|
121
|
+
'absolute' = "absolute",
|
|
122
|
+
'fixed' = "fixed",
|
|
123
|
+
'sticky' = "sticky"
|
|
124
|
+
}
|
|
125
|
+
export declare enum CSSDisplay {
|
|
126
|
+
'none' = "none",
|
|
127
|
+
'block' = "block",
|
|
128
|
+
'inline' = "inline",
|
|
129
|
+
'inline-block' = "inline-block",
|
|
130
|
+
'flex' = "flex",
|
|
131
|
+
'inline-flex' = "inline-flex",
|
|
132
|
+
'grid' = "grid",
|
|
133
|
+
'inline-grid' = "inline-grid"
|
|
134
|
+
}
|
|
135
|
+
export declare enum CSSFlexDirection {
|
|
136
|
+
'row' = "row",
|
|
137
|
+
'row-reverse' = "row-reverse",
|
|
138
|
+
'column' = "column",
|
|
139
|
+
'column-reverse' = "column-reverse"
|
|
140
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { Component, Event, Observable } from '@zcomponent/core';
|
|
2
|
+
import { useOnNodeConstructed, useOnNodeDisposed } from './context';
|
|
3
|
+
export class ZHTMLElement extends Component {
|
|
4
|
+
constructor(props, contextManager, root) {
|
|
5
|
+
super(props, contextManager);
|
|
6
|
+
this.root = root;
|
|
7
|
+
/** @zprop */
|
|
8
|
+
this.onClick = new Event();
|
|
9
|
+
/** @zprop */
|
|
10
|
+
this.id = new Observable('', v => (this.root.id = v));
|
|
11
|
+
/** @zprop */
|
|
12
|
+
this.classList = new Observable([], v => (this.root.className = v.join(' ')));
|
|
13
|
+
/** @zprop
|
|
14
|
+
* @zdefault [0, "px"]
|
|
15
|
+
* @zgroup Position
|
|
16
|
+
*/
|
|
17
|
+
this.left = this._cssLengthObservable('left');
|
|
18
|
+
/** @zprop
|
|
19
|
+
* @zdefault [0, "px"]
|
|
20
|
+
* @zgroup Position
|
|
21
|
+
*/
|
|
22
|
+
this.right = this._cssLengthObservable('right');
|
|
23
|
+
/** @zprop
|
|
24
|
+
* @zdefault [0, "px"]
|
|
25
|
+
* @zgroup Position
|
|
26
|
+
*/
|
|
27
|
+
this.top = this._cssLengthObservable('top');
|
|
28
|
+
/** @zprop
|
|
29
|
+
* @zdefault [0, "px"]
|
|
30
|
+
* @zgroup Position
|
|
31
|
+
*/
|
|
32
|
+
this.bottom = this._cssLengthObservable('bottom');
|
|
33
|
+
/** @zprop
|
|
34
|
+
* @zdefault [0, "px"]
|
|
35
|
+
* @zgroup Size
|
|
36
|
+
*/
|
|
37
|
+
this.width = this._cssLengthObservable('width');
|
|
38
|
+
/** @zprop
|
|
39
|
+
* @zdefault [0, "px"]
|
|
40
|
+
* @zgroup Size
|
|
41
|
+
*/
|
|
42
|
+
this.height = this._cssLengthObservable('height');
|
|
43
|
+
/** @zprop
|
|
44
|
+
* @zdefault [0, "px"]
|
|
45
|
+
* @zgroup Spacing
|
|
46
|
+
*/
|
|
47
|
+
this.marginLeft = this._cssLengthObservable('marginLeft');
|
|
48
|
+
/** @zprop
|
|
49
|
+
* @zdefault [0, "px"]
|
|
50
|
+
* @zgroup Spacing
|
|
51
|
+
*/
|
|
52
|
+
this.marginRight = this._cssLengthObservable('marginRight');
|
|
53
|
+
/** @zprop
|
|
54
|
+
* @zdefault [0, "px"]
|
|
55
|
+
* @zgroup Spacing
|
|
56
|
+
*/
|
|
57
|
+
this.marginTop = this._cssLengthObservable('marginTop');
|
|
58
|
+
/** @zprop
|
|
59
|
+
* @zdefault [0, "px"]
|
|
60
|
+
* @zgroup Spacing
|
|
61
|
+
*/
|
|
62
|
+
this.marginBottom = this._cssLengthObservable('marginBottom');
|
|
63
|
+
/** @zprop
|
|
64
|
+
* @zdefault [0, "px"]
|
|
65
|
+
* @zgroup Spacing
|
|
66
|
+
*/
|
|
67
|
+
this.paddingLeft = this._cssLengthObservable('paddingLeft');
|
|
68
|
+
/** @zprop
|
|
69
|
+
* @zdefault [0, "px"]
|
|
70
|
+
* @zgroup Spacing
|
|
71
|
+
*/
|
|
72
|
+
this.paddingRight = this._cssLengthObservable('paddingRight');
|
|
73
|
+
/** @zprop
|
|
74
|
+
* @zdefault [0, "px"]
|
|
75
|
+
* @zgroup Spacing
|
|
76
|
+
*/
|
|
77
|
+
this.paddingTop = this._cssLengthObservable('paddingTop');
|
|
78
|
+
/** @zprop
|
|
79
|
+
* @zdefault [0, "px"]
|
|
80
|
+
* @zgroup Spacing
|
|
81
|
+
*/
|
|
82
|
+
this.paddingBottom = this._cssLengthObservable('paddingBottom');
|
|
83
|
+
/** @zprop
|
|
84
|
+
* @zgroup Position
|
|
85
|
+
* @zdefault static
|
|
86
|
+
*/
|
|
87
|
+
this.position = new Observable(CSSPosition.static, v => (this.root.style.position = v));
|
|
88
|
+
/** @zprop */
|
|
89
|
+
this.display = new Observable(undefined, v => (this.root.style.display = v ?? ''));
|
|
90
|
+
/** @zprop
|
|
91
|
+
* @zdefault row
|
|
92
|
+
*/
|
|
93
|
+
this.flexDirection = new Observable(CSSFlexDirection.row, v => (this.root.style.flexDirection = v));
|
|
94
|
+
if (props.innerText !== undefined)
|
|
95
|
+
root.innerText = props.innerText;
|
|
96
|
+
for (const child of this.children) {
|
|
97
|
+
child.forEachRoot(root => {
|
|
98
|
+
if (root instanceof Node)
|
|
99
|
+
this.root.appendChild(root);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
this._attachEvent(this.onClick, 'click');
|
|
103
|
+
useOnNodeConstructed(contextManager).emit(this.root);
|
|
104
|
+
}
|
|
105
|
+
_cssLengthObservable(prop) {
|
|
106
|
+
return new Observable(undefined, v => {
|
|
107
|
+
this.root.style[prop] = converCSSLength(v) ?? '';
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
_attachEvent(evt, evtName) {
|
|
111
|
+
const handler = (e) => {
|
|
112
|
+
evt.emit(e);
|
|
113
|
+
};
|
|
114
|
+
evt.hasBindings.withValue(b => {
|
|
115
|
+
if (b)
|
|
116
|
+
this.root.addEventListener(evtName, handler);
|
|
117
|
+
else
|
|
118
|
+
this.root.removeEventListener(evtName, handler);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
dispose() {
|
|
122
|
+
useOnNodeDisposed(this.contextManager).emit(this.root);
|
|
123
|
+
return super.dispose();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function converCSSLength(v) {
|
|
127
|
+
if (v === undefined)
|
|
128
|
+
return undefined;
|
|
129
|
+
return v[0].toString() + v[1];
|
|
130
|
+
}
|
|
131
|
+
export var CSSLengthUnit;
|
|
132
|
+
(function (CSSLengthUnit) {
|
|
133
|
+
CSSLengthUnit["cm"] = "cm";
|
|
134
|
+
CSSLengthUnit["mm"] = "mm";
|
|
135
|
+
CSSLengthUnit["in"] = "in";
|
|
136
|
+
CSSLengthUnit["px"] = "px";
|
|
137
|
+
CSSLengthUnit["pt"] = "pt";
|
|
138
|
+
CSSLengthUnit["pc"] = "pc";
|
|
139
|
+
CSSLengthUnit["em"] = "em";
|
|
140
|
+
CSSLengthUnit["ex"] = "ex";
|
|
141
|
+
CSSLengthUnit["ch"] = "ch";
|
|
142
|
+
CSSLengthUnit["rem"] = "rem";
|
|
143
|
+
CSSLengthUnit["vw"] = "vw";
|
|
144
|
+
CSSLengthUnit["vh"] = "vh";
|
|
145
|
+
CSSLengthUnit["vmin"] = "vmin";
|
|
146
|
+
CSSLengthUnit["vmax"] = "vmax";
|
|
147
|
+
CSSLengthUnit["%"] = "%";
|
|
148
|
+
})(CSSLengthUnit || (CSSLengthUnit = {}));
|
|
149
|
+
export var CSSPosition;
|
|
150
|
+
(function (CSSPosition) {
|
|
151
|
+
CSSPosition["static"] = "static";
|
|
152
|
+
CSSPosition["relative"] = "relative";
|
|
153
|
+
CSSPosition["absolute"] = "absolute";
|
|
154
|
+
CSSPosition["fixed"] = "fixed";
|
|
155
|
+
CSSPosition["sticky"] = "sticky";
|
|
156
|
+
})(CSSPosition || (CSSPosition = {}));
|
|
157
|
+
export var CSSDisplay;
|
|
158
|
+
(function (CSSDisplay) {
|
|
159
|
+
CSSDisplay["none"] = "none";
|
|
160
|
+
CSSDisplay["block"] = "block";
|
|
161
|
+
CSSDisplay["inline"] = "inline";
|
|
162
|
+
CSSDisplay["inline-block"] = "inline-block";
|
|
163
|
+
CSSDisplay["flex"] = "flex";
|
|
164
|
+
CSSDisplay["inline-flex"] = "inline-flex";
|
|
165
|
+
CSSDisplay["grid"] = "grid";
|
|
166
|
+
CSSDisplay["inline-grid"] = "inline-grid";
|
|
167
|
+
})(CSSDisplay || (CSSDisplay = {}));
|
|
168
|
+
export var CSSFlexDirection;
|
|
169
|
+
(function (CSSFlexDirection) {
|
|
170
|
+
CSSFlexDirection["row"] = "row";
|
|
171
|
+
CSSFlexDirection["row-reverse"] = "row-reverse";
|
|
172
|
+
CSSFlexDirection["column"] = "column";
|
|
173
|
+
CSSFlexDirection["column-reverse"] = "column-reverse";
|
|
174
|
+
})(CSSFlexDirection || (CSSFlexDirection = {}));
|
package/lib/button.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ContextManager } from '@zcomponent/core';
|
|
2
|
+
import { HTMLElementProps, ZHTMLElement } from './HTMLElement';
|
|
3
|
+
export declare type ButtonConstructorProps = HTMLElementProps;
|
|
4
|
+
/** @zcomponent
|
|
5
|
+
* @ztag html/element/button
|
|
6
|
+
* @zparents html/element/**
|
|
7
|
+
* @zicon html
|
|
8
|
+
*/
|
|
9
|
+
export declare class Button extends ZHTMLElement<HTMLButtonElement> {
|
|
10
|
+
constructor(props: ButtonConstructorProps, mgr: ContextManager);
|
|
11
|
+
}
|
package/lib/button.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ZHTMLElement } from './HTMLElement';
|
|
2
|
+
/** @zcomponent
|
|
3
|
+
* @ztag html/element/button
|
|
4
|
+
* @zparents html/element/**
|
|
5
|
+
* @zicon html
|
|
6
|
+
*/
|
|
7
|
+
export class Button extends ZHTMLElement {
|
|
8
|
+
constructor(props, mgr) {
|
|
9
|
+
super(props, mgr, document.createElement('button'));
|
|
10
|
+
}
|
|
11
|
+
}
|
package/lib/context.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Event, ContextManager } from '@zcomponent/core';
|
|
2
|
+
export interface HTMLContextProperties {
|
|
3
|
+
}
|
|
4
|
+
export interface HTMLContext {
|
|
5
|
+
readonly onNodeConstructed: Event<[Node]>;
|
|
6
|
+
readonly onNodeDisposed: Event<[Node]>;
|
|
7
|
+
}
|
|
8
|
+
export declare const HTMLContext: import("@zcomponent/core").ContextTypeWithDefault<HTMLContext, [props?: HTMLContextProperties | undefined]>;
|
|
9
|
+
export declare function useOnNodeConstructed(mgr: ContextManager): Event<[Node]>;
|
|
10
|
+
export declare function useOnNodeDisposed(mgr: ContextManager): Event<[Node]>;
|
package/lib/context.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { defineContextType, Event } from '@zcomponent/core';
|
|
2
|
+
export const HTMLContext = defineContextType((ctx, props) => {
|
|
3
|
+
return {
|
|
4
|
+
onNodeConstructed: new Event(),
|
|
5
|
+
onNodeDisposed: new Event(),
|
|
6
|
+
};
|
|
7
|
+
});
|
|
8
|
+
export function useOnNodeConstructed(mgr) {
|
|
9
|
+
return mgr.get(HTMLContext).onNodeConstructed;
|
|
10
|
+
}
|
|
11
|
+
export function useOnNodeDisposed(mgr) {
|
|
12
|
+
return mgr.get(HTMLContext).onNodeDisposed;
|
|
13
|
+
}
|
package/lib/div.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ContextManager } from '@zcomponent/core';
|
|
2
|
+
import { HTMLElementProps, ZHTMLElement } from './HTMLElement';
|
|
3
|
+
export declare type ButtonConstructorProps = HTMLElementProps;
|
|
4
|
+
/** @zcomponent
|
|
5
|
+
* @ztag html/element/div
|
|
6
|
+
* @zparents html/element/**
|
|
7
|
+
* @zicon html
|
|
8
|
+
*/
|
|
9
|
+
export declare class Div extends ZHTMLElement<HTMLDivElement> {
|
|
10
|
+
constructor(props: ButtonConstructorProps, mgr: ContextManager);
|
|
11
|
+
}
|
package/lib/div.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ZHTMLElement } from './HTMLElement';
|
|
2
|
+
/** @zcomponent
|
|
3
|
+
* @ztag html/element/div
|
|
4
|
+
* @zparents html/element/**
|
|
5
|
+
* @zicon html
|
|
6
|
+
*/
|
|
7
|
+
export class Div extends ZHTMLElement {
|
|
8
|
+
constructor(props, mgr) {
|
|
9
|
+
super(props, mgr, document.createElement('div'));
|
|
10
|
+
}
|
|
11
|
+
}
|
package/lib/img.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ContextManager } from '@zcomponent/core';
|
|
2
|
+
import { HTMLElementProps, ZHTMLElement } from './HTMLElement';
|
|
3
|
+
export interface ImgConstructorProps extends HTMLElementProps {
|
|
4
|
+
/** @zprop
|
|
5
|
+
* @zvalues files *.jpg
|
|
6
|
+
* @zvalues files *.jpeg
|
|
7
|
+
* @zvalues files *.png
|
|
8
|
+
*/
|
|
9
|
+
src: string;
|
|
10
|
+
}
|
|
11
|
+
/** @zcomponent
|
|
12
|
+
* @ztag html/element/img
|
|
13
|
+
* @zicon html
|
|
14
|
+
* @zparents html/element/**
|
|
15
|
+
*/
|
|
16
|
+
export declare class Img extends ZHTMLElement<HTMLImageElement> {
|
|
17
|
+
constructor(props: ImgConstructorProps, mgr: ContextManager);
|
|
18
|
+
}
|
package/lib/img.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { registerLoadable } from '@zcomponent/core';
|
|
2
|
+
import { ZHTMLElement } from './HTMLElement';
|
|
3
|
+
/** @zcomponent
|
|
4
|
+
* @ztag html/element/img
|
|
5
|
+
* @zicon html
|
|
6
|
+
* @zparents html/element/**
|
|
7
|
+
*/
|
|
8
|
+
export class Img extends ZHTMLElement {
|
|
9
|
+
constructor(props, mgr) {
|
|
10
|
+
const elm = document.createElement('img');
|
|
11
|
+
registerLoadable(mgr, new Promise((resolve, reject) => {
|
|
12
|
+
elm.src = props.src;
|
|
13
|
+
elm.addEventListener('load', () => resolve());
|
|
14
|
+
elm.addEventListener('error', () => reject());
|
|
15
|
+
}));
|
|
16
|
+
super(props, mgr, elm);
|
|
17
|
+
}
|
|
18
|
+
}
|
package/lib/index.d.ts
ADDED
|
File without changes
|
package/lib/index.js
ADDED
|
File without changes
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zcomponent/html",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"directories": {
|
|
8
|
+
"lib": "lib"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"index.js",
|
|
15
|
+
"index.d.ts",
|
|
16
|
+
"lib/**/*"
|
|
17
|
+
],
|
|
18
|
+
"author": "Zappar Limited",
|
|
19
|
+
"license": "Proprietary",
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@zcomponent/core": "~0.0.2"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"typescript": "^4.6.3"
|
|
25
|
+
},
|
|
26
|
+
"zexports": [
|
|
27
|
+
"./lib/**/*"
|
|
28
|
+
]
|
|
29
|
+
}
|