@zcomponent/html 2.0.0-alpha.1 → 2.0.0-alpha.2

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.js CHANGED
@@ -1,4 +1 @@
1
- /* eslint-disable n/no-unsupported-features/es-syntax */
2
- /* eslint-disable n/no-missing-import */
3
-
4
1
  export * from './lib';
package/lib/CSS.d.ts CHANGED
@@ -1,12 +1,11 @@
1
- import { Component, ContextManager } from '@zcomponent/core';
2
- interface CSSConstructorProps {
3
- /** @zprop
4
- * @zvalues files *.css
1
+ import { Component, ConstructorProps, ContextManager, ProjectFile } from '@zcomponent/core';
2
+ interface CSSConstructorProps extends ConstructorProps {
3
+ /**
5
4
  */
6
- source: string;
5
+ source: ProjectFile<'*.css'>;
7
6
  /**
8
- * @zprop
9
- * @zdefault true
7
+ *
8
+ * @default true
10
9
  */
11
10
  includeAtDesignTime: boolean;
12
11
  }
@@ -14,7 +13,6 @@ interface CSSConstructorProps {
14
13
  * 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.
15
14
  *
16
15
  * This component is particularly useful if you'd like to style with CSS any HTML elements that you've added to your Hierarchy.
17
- *
18
16
  * @zcomponent
19
17
  * @zicon html
20
18
  */
package/lib/CSS.js CHANGED
@@ -1,49 +1,101 @@
1
- import { Component, isDesignTime, registerLoadable } from '@zcomponent/core';
1
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
2
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
3
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
4
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
5
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
6
+ var _, done = false;
7
+ for (var i = decorators.length - 1; i >= 0; i--) {
8
+ var context = {};
9
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
10
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
11
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
12
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
13
+ if (kind === "accessor") {
14
+ if (result === void 0) continue;
15
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
16
+ if (_ = accept(result.get)) descriptor.get = _;
17
+ if (_ = accept(result.set)) descriptor.set = _;
18
+ if (_ = accept(result.init)) initializers.unshift(_);
19
+ }
20
+ else if (_ = accept(result)) {
21
+ if (kind === "field") initializers.unshift(_);
22
+ else descriptor[key] = _;
23
+ }
24
+ }
25
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
26
+ done = true;
27
+ };
28
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
29
+ var useValue = arguments.length > 2;
30
+ for (var i = 0; i < initializers.length; i++) {
31
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
32
+ }
33
+ return useValue ? value : void 0;
34
+ };
35
+ import { Component, isDesignTime, registerLoadable, zComponent } from '@zcomponent/core';
2
36
  import { HTMLContext } from './context';
3
37
  const alreadyAdded = new Map();
4
38
  /**
5
39
  * 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.
6
40
  *
7
41
  * This component is particularly useful if you'd like to style with CSS any HTML elements that you've added to your Hierarchy.
8
- *
9
42
  * @zcomponent
10
43
  * @zicon html
11
44
  */
12
- export class CSS extends Component {
13
- constructor(contextManager, constructorProps) {
14
- super(contextManager, constructorProps);
15
- this.constructorProps = constructorProps;
16
- if (!constructorProps.source || (constructorProps.includeAtDesignTime === false && isDesignTime(contextManager)))
17
- return;
18
- this._elm = alreadyAdded.get(constructorProps.source);
19
- if (this._elm)
20
- this._elm[0]++;
21
- else {
22
- this._elm = [1, document.createElement('link')];
23
- registerLoadable(contextManager, new Promise((resolve, reject) => {
24
- this._elm[1].addEventListener('load', () => {
25
- contextManager.get(HTMLContext).onCSSChanged.emit();
26
- resolve();
27
- });
28
- this._elm[1].addEventListener('error', reject);
29
- }));
30
- this._elm[1].setAttribute('rel', 'stylesheet');
31
- this._elm[1].setAttribute('href', constructorProps.source);
32
- if (document.head)
33
- document.head.appendChild(this._elm[1]);
34
- else if (document.body)
35
- document.body.appendChild(this._elm[1]);
36
- alreadyAdded.set(constructorProps.source, this._elm);
45
+ let CSS = (() => {
46
+ let _classDecorators = [zComponent({ icon: 'html' })];
47
+ let _classDescriptor;
48
+ let _classExtraInitializers = [];
49
+ let _classThis;
50
+ let _classSuper = Component;
51
+ var CSS = class extends _classSuper {
52
+ static { _classThis = this; }
53
+ static {
54
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
55
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
56
+ CSS = _classThis = _classDescriptor.value;
57
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
58
+ __runInitializers(_classThis, _classExtraInitializers);
37
59
  }
38
- }
39
- dispose() {
40
- if (this._elm) {
41
- this._elm[0] = this._elm[0] - 1;
42
- if (this._elm[0] <= 0) {
43
- this._elm[1]?.remove();
44
- alreadyAdded.delete(this.constructorProps.source);
60
+ constructorProps;
61
+ _elm;
62
+ constructor(contextManager, constructorProps) {
63
+ super(contextManager, constructorProps);
64
+ this.constructorProps = constructorProps;
65
+ if (!constructorProps.source || (constructorProps.includeAtDesignTime === false && isDesignTime(contextManager)))
66
+ return;
67
+ this._elm = alreadyAdded.get(constructorProps.source);
68
+ if (this._elm)
69
+ this._elm[0]++;
70
+ else {
71
+ this._elm = [1, document.createElement('link')];
72
+ registerLoadable(contextManager, new Promise((resolve, reject) => {
73
+ this._elm[1].addEventListener('load', () => {
74
+ contextManager.get(HTMLContext).onCSSChanged.emit();
75
+ resolve();
76
+ });
77
+ this._elm[1].addEventListener('error', reject);
78
+ }));
79
+ this._elm[1].setAttribute('rel', 'stylesheet');
80
+ this._elm[1].setAttribute('href', constructorProps.source);
81
+ if (document.head)
82
+ document.head.appendChild(this._elm[1]);
83
+ else if (document.body)
84
+ document.body.appendChild(this._elm[1]);
85
+ alreadyAdded.set(constructorProps.source, this._elm);
45
86
  }
46
87
  }
47
- return super.dispose();
48
- }
49
- }
88
+ dispose() {
89
+ if (this._elm) {
90
+ this._elm[0] = this._elm[0] - 1;
91
+ if (this._elm[0] <= 0) {
92
+ this._elm[1]?.remove();
93
+ alreadyAdded.delete(this.constructorProps.source);
94
+ }
95
+ }
96
+ return super.dispose();
97
+ }
98
+ };
99
+ return CSS = _classThis;
100
+ })();
101
+ export { CSS };
@@ -1,146 +1,226 @@
1
- import { Component, ConstructorProps, ContextManager, Event, Observable } from '@zcomponent/core';
1
+ import { Component, ConstructorProps, ContextManager, Event, ValueOf } from '@zcomponent/core';
2
2
  export interface HTMLElementProps extends ConstructorProps {
3
+ /**
4
+ * @zignore
5
+ */
3
6
  innerText?: string;
4
7
  }
5
8
  export declare class ZHTMLElement<T extends HTMLElement> extends Component {
6
- element: T;
7
- /** @zprop */
8
9
  onClick: Event<[MouseEvent]>;
9
10
  /**
10
- * @zprop
11
+ * The inner text of the element.
12
+ * @default ""
13
+ * @zui
11
14
  * @ztype text-multiline
12
- * @zgrouppriority 21
13
15
  */
14
- innerText: Observable<string, never>;
16
+ innerText: string;
17
+ /**
18
+ * @zignore
19
+ */
20
+ element: T;
21
+ /**
22
+ * Creates a new ZHTMLElement.
23
+ * @param contextManager - The context manager
24
+ * @param props - The properties of the element
25
+ * @param element - The element to wrap
26
+ */
15
27
  constructor(contextManager: ContextManager, props: HTMLElementProps, element: T);
16
- appendChild(c: Component): void;
17
- private _connectChild;
18
- private _cssLengthObservable;
28
+ connectElements(): void;
19
29
  private _attachEvent;
20
- /** @zprop */
21
- id: Observable<string, never>;
22
- /** @zprop */
23
- classList: Observable<string[], never>;
24
- /** @zprop
25
- * @zdefault [0, "px"]
30
+ /**
31
+ * @default ""
32
+ */
33
+ id: string;
34
+ /**
35
+ * @default []
36
+ */
37
+ classList: string[];
38
+ /**
39
+ * @default [0,"px"]
40
+ * @zui
26
41
  * @zgroup Position
27
42
  */
28
- left: Observable<[number, CSSLengthUnit] | undefined, never>;
29
- /** @zprop
30
- * @zdefault [0, "px"]
43
+ left: [
44
+ number,
45
+ CSSLengthUnitValue
46
+ ] | undefined;
47
+ /**
48
+ * @default [0,"px"]
49
+ * @zui
31
50
  * @zgroup Position
32
51
  */
33
- right: Observable<[number, CSSLengthUnit] | undefined, never>;
34
- /** @zprop
35
- * @zdefault [0, "px"]
52
+ right: [
53
+ number,
54
+ CSSLengthUnitValue
55
+ ] | undefined;
56
+ /**
57
+ * @default [0,"px"]
58
+ * @zui
36
59
  * @zgroup Position
37
60
  */
38
- top: Observable<[number, CSSLengthUnit] | undefined, never>;
39
- /** @zprop
40
- * @zdefault [0, "px"]
61
+ top: [
62
+ number,
63
+ CSSLengthUnitValue
64
+ ] | undefined;
65
+ /**
66
+ * @default [0,"px"]
67
+ * @zui
41
68
  * @zgroup Position
42
69
  */
43
- bottom: Observable<[number, CSSLengthUnit] | undefined, never>;
44
- /** @zprop
45
- * @zdefault [0, "px"]
70
+ bottom: [
71
+ number,
72
+ CSSLengthUnitValue
73
+ ] | undefined;
74
+ /**
75
+ * @default [0,"px"]
76
+ * @zui
46
77
  * @zgroup Size
47
78
  */
48
- width: Observable<[number, CSSLengthUnit] | undefined, never>;
49
- /** @zprop
50
- * @zdefault [0, "px"]
79
+ width: [
80
+ number,
81
+ CSSLengthUnitValue
82
+ ] | undefined;
83
+ /**
84
+ * @default [0,"px"]
85
+ * @zui
51
86
  * @zgroup Size
52
87
  */
53
- height: Observable<[number, CSSLengthUnit] | undefined, never>;
54
- /** @zprop
55
- * @zdefault [0, "px"]
88
+ height: [
89
+ number,
90
+ CSSLengthUnitValue
91
+ ] | undefined;
92
+ /**
93
+ * @default [0,"px"]
94
+ * @zui
56
95
  * @zgroup Spacing
57
96
  */
58
- marginLeft: Observable<[number, CSSLengthUnit] | undefined, never>;
59
- /** @zprop
60
- * @zdefault [0, "px"]
97
+ marginLeft: [
98
+ number,
99
+ CSSLengthUnitValue
100
+ ] | undefined;
101
+ /**
102
+ * @default [0,"px"]
103
+ * @zui
61
104
  * @zgroup Spacing
62
105
  */
63
- marginRight: Observable<[number, CSSLengthUnit] | undefined, never>;
64
- /** @zprop
65
- * @zdefault [0, "px"]
106
+ marginRight: [
107
+ number,
108
+ CSSLengthUnitValue
109
+ ] | undefined;
110
+ /**
111
+ * @default [0,"px"]
112
+ * @zui
66
113
  * @zgroup Spacing
67
114
  */
68
- marginTop: Observable<[number, CSSLengthUnit] | undefined, never>;
69
- /** @zprop
70
- * @zdefault [0, "px"]
115
+ marginTop: [
116
+ number,
117
+ CSSLengthUnitValue
118
+ ] | undefined;
119
+ /**
120
+ * @default [0,"px"]
121
+ * @zui
71
122
  * @zgroup Spacing
72
123
  */
73
- marginBottom: Observable<[number, CSSLengthUnit] | undefined, never>;
74
- /** @zprop
75
- * @zdefault [0, "px"]
124
+ marginBottom: [
125
+ number,
126
+ CSSLengthUnitValue
127
+ ] | undefined;
128
+ /**
129
+ * @default [0,"px"]
130
+ * @zui
76
131
  * @zgroup Spacing
77
132
  */
78
- paddingLeft: Observable<[number, CSSLengthUnit] | undefined, never>;
79
- /** @zprop
80
- * @zdefault [0, "px"]
133
+ paddingLeft: [
134
+ number,
135
+ CSSLengthUnitValue
136
+ ] | undefined;
137
+ /**
138
+ * @default [0,"px"]
139
+ * @zui
81
140
  * @zgroup Spacing
82
141
  */
83
- paddingRight: Observable<[number, CSSLengthUnit] | undefined, never>;
84
- /** @zprop
85
- * @zdefault [0, "px"]
142
+ paddingRight: [
143
+ number,
144
+ CSSLengthUnitValue
145
+ ] | undefined;
146
+ /**
147
+ * @default [0,"px"]
148
+ * @zui
86
149
  * @zgroup Spacing
87
150
  */
88
- paddingTop: Observable<[number, CSSLengthUnit] | undefined, never>;
89
- /** @zprop
90
- * @zdefault [0, "px"]
151
+ paddingTop: [
152
+ number,
153
+ CSSLengthUnitValue
154
+ ] | undefined;
155
+ /**
156
+ * @default [0,"px"]
157
+ * @zui
91
158
  * @zgroup Spacing
92
159
  */
93
- paddingBottom: Observable<[number, CSSLengthUnit] | undefined, never>;
94
- /** @zprop
160
+ paddingBottom: [
161
+ number,
162
+ CSSLengthUnitValue
163
+ ] | undefined;
164
+ /**
165
+ * @default "static"
166
+ * @zui
95
167
  * @zgroup Position
96
- * @zdefault static
97
168
  */
98
- position: Observable<CSSPosition, never>;
99
- /** @zprop */
100
- display: Observable<CSSDisplay | undefined, never>;
101
- /** @zprop
102
- * @zdefault row
169
+ position: CSSPositionValue;
170
+ /**
171
+ * @zui
172
+ * @zgroup Display
173
+ */
174
+ display: CSSDisplayValue | undefined;
175
+ /**
176
+ * @default "row"
177
+ * @zui
178
+ * @zgroup Display
103
179
  */
104
- flexDirection: Observable<CSSFlexDirection, never>;
180
+ flexDirection: CSSFlexDirectionValue;
105
181
  dispose(): never;
106
182
  }
107
- export declare enum CSSLengthUnit {
108
- 'cm' = "cm",
109
- 'mm' = "mm",
110
- 'in' = "in",
111
- 'px' = "px",
112
- 'pt' = "pt",
113
- 'pc' = "pc",
114
- 'em' = "em",
115
- 'ex' = "ex",
116
- 'ch' = "ch",
117
- 'rem' = "rem",
118
- 'vw' = "vw",
119
- 'vh' = "vh",
120
- 'vmin' = "vmin",
121
- 'vmax' = "vmax",
122
- '%' = "%"
123
- }
124
- export declare enum CSSPosition {
125
- 'static' = "static",
126
- 'relative' = "relative",
127
- 'absolute' = "absolute",
128
- 'fixed' = "fixed",
129
- 'sticky' = "sticky"
130
- }
131
- export declare enum CSSDisplay {
132
- 'none' = "none",
133
- 'block' = "block",
134
- 'inline' = "inline",
135
- 'inline-block' = "inline-block",
136
- 'flex' = "flex",
137
- 'inline-flex' = "inline-flex",
138
- 'grid' = "grid",
139
- 'inline-grid' = "inline-grid"
140
- }
141
- export declare enum CSSFlexDirection {
142
- 'row' = "row",
143
- 'row-reverse' = "row-reverse",
144
- 'column' = "column",
145
- 'column-reverse' = "column-reverse"
146
- }
183
+ export declare const CSSLengthUnit: {
184
+ readonly cm: "cm";
185
+ readonly mm: "mm";
186
+ readonly in: "in";
187
+ readonly px: "px";
188
+ readonly pt: "pt";
189
+ readonly pc: "pc";
190
+ readonly em: "em";
191
+ readonly ex: "ex";
192
+ readonly ch: "ch";
193
+ readonly rem: "rem";
194
+ readonly vw: "vw";
195
+ readonly vh: "vh";
196
+ readonly vmin: "vmin";
197
+ readonly vmax: "vmax";
198
+ readonly '%': "%";
199
+ };
200
+ export type CSSLengthUnitValue = ValueOf<typeof CSSLengthUnit>;
201
+ export declare const CSSPosition: {
202
+ readonly static: "static";
203
+ readonly relative: "relative";
204
+ readonly absolute: "absolute";
205
+ readonly fixed: "fixed";
206
+ readonly sticky: "sticky";
207
+ };
208
+ export type CSSPositionValue = ValueOf<typeof CSSPosition>;
209
+ export declare const CSSDisplay: {
210
+ readonly none: "none";
211
+ readonly block: "block";
212
+ readonly inline: "inline";
213
+ readonly 'inline-block': "inline-block";
214
+ readonly flex: "flex";
215
+ readonly 'inline-flex': "inline-flex";
216
+ readonly grid: "grid";
217
+ readonly 'inline-grid': "inline-grid";
218
+ };
219
+ export type CSSDisplayValue = ValueOf<typeof CSSDisplay>;
220
+ export declare const CSSFlexDirection: {
221
+ readonly row: "row";
222
+ readonly 'row-reverse': "row-reverse";
223
+ readonly column: "column";
224
+ readonly 'column-reverse': "column-reverse";
225
+ };
226
+ export type CSSFlexDirectionValue = ValueOf<typeof CSSFlexDirection>;