@htmlplus/element 0.1.9 → 0.3.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 +34 -4
- package/package.json +10 -47
- package/dist/client/decorators/attributes.d.ts +0 -2
- package/dist/client/decorators/attributes.js +0 -13
- package/dist/client/decorators/bind.d.ts +0 -4
- package/dist/client/decorators/bind.js +0 -17
- package/dist/client/decorators/element.d.ts +0 -2
- package/dist/client/decorators/element.js +0 -49
- package/dist/client/decorators/event.d.ts +0 -21
- package/dist/client/decorators/event.js +0 -18
- package/dist/client/decorators/index.d.ts +0 -9
- package/dist/client/decorators/index.js +0 -9
- package/dist/client/decorators/listen.d.ts +0 -12
- package/dist/client/decorators/listen.js +0 -30
- package/dist/client/decorators/method.d.ts +0 -2
- package/dist/client/decorators/method.js +0 -12
- package/dist/client/decorators/property.d.ts +0 -12
- package/dist/client/decorators/property.js +0 -51
- package/dist/client/decorators/state.d.ts +0 -2
- package/dist/client/decorators/state.js +0 -32
- package/dist/client/decorators/watch.d.ts +0 -2
- package/dist/client/decorators/watch.js +0 -17
- package/dist/client/helpers/classes.d.ts +0 -1
- package/dist/client/helpers/classes.js +0 -62
- package/dist/client/helpers/direction.d.ts +0 -3
- package/dist/client/helpers/direction.js +0 -4
- package/dist/client/helpers/index.d.ts +0 -9
- package/dist/client/helpers/index.js +0 -9
- package/dist/client/helpers/is-rtl.d.ts +0 -2
- package/dist/client/helpers/is-rtl.js +0 -2
- package/dist/client/helpers/query-all.d.ts +0 -3
- package/dist/client/helpers/query-all.js +0 -5
- package/dist/client/helpers/query.d.ts +0 -3
- package/dist/client/helpers/query.js +0 -5
- package/dist/client/helpers/slots.d.ts +0 -6
- package/dist/client/helpers/slots.js +0 -15
- package/dist/client/helpers/styles.d.ts +0 -1
- package/dist/client/helpers/styles.js +0 -16
- package/dist/client/helpers/to-unit.d.ts +0 -1
- package/dist/client/helpers/to-unit.js +0 -7
- package/dist/client/index.d.ts +0 -3
- package/dist/client/index.js +0 -3
- package/dist/client/services/index.d.ts +0 -1
- package/dist/client/services/index.js +0 -1
- package/dist/client/services/link.d.ts +0 -4
- package/dist/client/services/link.js +0 -196
- package/dist/client/utils/append-to-method.d.ts +0 -2
- package/dist/client/utils/append-to-method.js +0 -7
- package/dist/client/utils/call.d.ts +0 -2
- package/dist/client/utils/call.js +0 -4
- package/dist/client/utils/define-property.d.ts +0 -1
- package/dist/client/utils/define-property.js +0 -1
- package/dist/client/utils/event.d.ts +0 -2
- package/dist/client/utils/event.js +0 -6
- package/dist/client/utils/get-members.d.ts +0 -2
- package/dist/client/utils/get-members.js +0 -5
- package/dist/client/utils/get-styles.d.ts +0 -2
- package/dist/client/utils/get-styles.js +0 -5
- package/dist/client/utils/host.d.ts +0 -2
- package/dist/client/utils/host.js +0 -4
- package/dist/client/utils/index.d.ts +0 -20
- package/dist/client/utils/index.js +0 -20
- package/dist/client/utils/is-event.d.ts +0 -1
- package/dist/client/utils/is-event.js +0 -3
- package/dist/client/utils/is-ready.d.ts +0 -2
- package/dist/client/utils/is-ready.js +0 -4
- package/dist/client/utils/is-server.d.ts +0 -1
- package/dist/client/utils/is-server.js +0 -3
- package/dist/client/utils/on-ready.d.ts +0 -2
- package/dist/client/utils/on-ready.js +0 -6
- package/dist/client/utils/parse-value.d.ts +0 -1
- package/dist/client/utils/parse-value.js +0 -15
- package/dist/client/utils/render.d.ts +0 -2
- package/dist/client/utils/render.js +0 -17
- package/dist/client/utils/request.d.ts +0 -2
- package/dist/client/utils/request.js +0 -25
- package/dist/client/utils/sync.d.ts +0 -1
- package/dist/client/utils/sync.js +0 -31
- package/dist/client/utils/task.d.ts +0 -6
- package/dist/client/utils/task.js +0 -46
- package/dist/client/utils/to-boolean.d.ts +0 -1
- package/dist/client/utils/to-boolean.js +0 -3
- package/dist/client/utils/to-event.d.ts +0 -1
- package/dist/client/utils/to-event.js +0 -3
- package/dist/client/utils/type-of.d.ts +0 -3
- package/dist/client/utils/type-of.js +0 -6
- package/dist/client/utils/update-attribute.d.ts +0 -1
- package/dist/client/utils/update-attribute.js +0 -7
- package/dist/compiler/compiler.d.ts +0 -7
- package/dist/compiler/compiler.js +0 -56
- package/dist/compiler/index.d.ts +0 -2
- package/dist/compiler/index.js +0 -2
- package/dist/compiler/plugins/attach.d.ts +0 -11
- package/dist/compiler/plugins/attach.js +0 -101
- package/dist/compiler/plugins/docs.d.ts +0 -11
- package/dist/compiler/plugins/docs.js +0 -320
- package/dist/compiler/plugins/extract.d.ts +0 -8
- package/dist/compiler/plugins/extract.js +0 -77
- package/dist/compiler/plugins/index.d.ts +0 -11
- package/dist/compiler/plugins/index.js +0 -11
- package/dist/compiler/plugins/parse.d.ts +0 -5
- package/dist/compiler/plugins/parse.js +0 -16
- package/dist/compiler/plugins/print.d.ts +0 -5
- package/dist/compiler/plugins/print.js +0 -11
- package/dist/compiler/plugins/react.proxy/index.d.ts +0 -1
- package/dist/compiler/plugins/react.proxy/index.js +0 -1
- package/dist/compiler/plugins/react.proxy/react.proxy.d.ts +0 -11
- package/dist/compiler/plugins/react.proxy/react.proxy.js +0 -121
- package/dist/compiler/plugins/react.proxy/templates/README.md.hbs +0 -1
- package/dist/compiler/plugins/react.proxy/templates/_.gitignore.hbs +0 -2
- package/dist/compiler/plugins/react.proxy/templates/package.json.hbs +0 -37
- package/dist/compiler/plugins/react.proxy/templates/rollup.config.js.hbs +0 -21
- package/dist/compiler/plugins/react.proxy/templates/src/components/index.ts.hbs +0 -17
- package/dist/compiler/plugins/react.proxy/templates/src/components/{{fileName}}.compact.ts.hbs +0 -18
- package/dist/compiler/plugins/react.proxy/templates/src/components/{{fileName}}.ts.hbs +0 -26
- package/dist/compiler/plugins/react.proxy/templates/src/index.ts.hbs +0 -1
- package/dist/compiler/plugins/react.proxy/templates/src/proxy.ts.hbs +0 -278
- package/dist/compiler/plugins/react.proxy/templates/tsconfig.json.hbs +0 -17
- package/dist/compiler/plugins/read.d.ts +0 -5
- package/dist/compiler/plugins/read.js +0 -13
- package/dist/compiler/plugins/sass.d.ts +0 -6
- package/dist/compiler/plugins/sass.js +0 -15
- package/dist/compiler/plugins/uhtml.d.ts +0 -5
- package/dist/compiler/plugins/uhtml.js +0 -59
- package/dist/compiler/plugins/validate.d.ts +0 -5
- package/dist/compiler/plugins/validate.js +0 -8
- package/dist/compiler/plugins/vscode.d.ts +0 -11
- package/dist/compiler/plugins/vscode.js +0 -83
- package/dist/compiler/utils/__dirname.d.ts +0 -1
- package/dist/compiler/utils/__dirname.js +0 -5
- package/dist/compiler/utils/get-initializer.d.ts +0 -2
- package/dist/compiler/utils/get-initializer.js +0 -10
- package/dist/compiler/utils/get-tags.d.ts +0 -6
- package/dist/compiler/utils/get-tags.js +0 -34
- package/dist/compiler/utils/get-type.d.ts +0 -2
- package/dist/compiler/utils/get-type.js +0 -69
- package/dist/compiler/utils/has-decorator.d.ts +0 -1
- package/dist/compiler/utils/has-decorator.js +0 -5
- package/dist/compiler/utils/index.d.ts +0 -10
- package/dist/compiler/utils/index.js +0 -10
- package/dist/compiler/utils/is-directory-empty.d.ts +0 -1
- package/dist/compiler/utils/is-directory-empty.js +0 -10
- package/dist/compiler/utils/print-type.d.ts +0 -1
- package/dist/compiler/utils/print-type.js +0 -69
- package/dist/compiler/utils/print.d.ts +0 -2
- package/dist/compiler/utils/print.js +0 -5
- package/dist/compiler/utils/render-template.d.ts +0 -1
- package/dist/compiler/utils/render-template.js +0 -25
- package/dist/compiler/utils/visitor.d.ts +0 -2
- package/dist/compiler/utils/visitor.js +0 -5
- package/dist/configs/constants.d.ts +0 -22
- package/dist/configs/constants.js +0 -28
- package/dist/runtime/index.d.ts +0 -1
- package/dist/runtime/index.js +0 -4
- package/dist/types/context.d.ts +0 -29
- package/dist/types/context.js +0 -1
- package/dist/types/index.d.ts +0 -3
- package/dist/types/index.js +0 -3
- package/dist/types/plugin.d.ts +0 -8
- package/dist/types/plugin.js +0 -1
- package/dist/types/plus-element.d.ts +0 -2
- package/dist/types/plus-element.js +0 -1
package/README.md
CHANGED
|
@@ -258,6 +258,36 @@ export class MyCounter {
|
|
|
258
258
|
|
|
259
259
|
</details>
|
|
260
260
|
|
|
261
|
+
<details>
|
|
262
|
+
<summary>Attributes</summary>
|
|
263
|
+
|
|
264
|
+
TODO
|
|
265
|
+
|
|
266
|
+
```tsx
|
|
267
|
+
import { Attributes, Element } from '@htmlplus/element';
|
|
268
|
+
|
|
269
|
+
@Element('my-button')
|
|
270
|
+
export class MyButton {
|
|
271
|
+
|
|
272
|
+
@Attributes()
|
|
273
|
+
get attributes() {
|
|
274
|
+
return {
|
|
275
|
+
role: 'button'
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
render() {
|
|
280
|
+
return <button><slot /></button>
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
```html
|
|
286
|
+
<my-button role="button"></my-button>
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
</details>
|
|
290
|
+
|
|
261
291
|
<details>
|
|
262
292
|
<summary>Watch</summary>
|
|
263
293
|
|
|
@@ -912,15 +942,15 @@ TODO
|
|
|
912
942
|
|
|
913
943
|
```js
|
|
914
944
|
import compiler from '@htmlplus/element/compiler';
|
|
915
|
-
import {
|
|
945
|
+
import { customElement, extract, parse, read, style, validate } from '@htmlplus/element/compiler';
|
|
916
946
|
|
|
917
947
|
const { start, next, finish } = compiler(
|
|
918
948
|
read(),
|
|
919
949
|
parse(),
|
|
950
|
+
validate(),
|
|
920
951
|
extract(),
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
print(),
|
|
952
|
+
style(),
|
|
953
|
+
customElement(),
|
|
924
954
|
);
|
|
925
955
|
|
|
926
956
|
await start();
|
package/package.json
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@htmlplus/element",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Masood Abdolian <m.abdolian@gmail.com>",
|
|
6
6
|
"description": "Compiler of HTMLPlus",
|
|
7
7
|
"type": "module",
|
|
8
|
+
"main": "./client/index.js",
|
|
9
|
+
"types": "./client/index.d.ts",
|
|
8
10
|
"scripts": {
|
|
9
11
|
"prebuild": "npm run clean",
|
|
10
12
|
"build": "tsc",
|
|
@@ -12,53 +14,15 @@
|
|
|
12
14
|
"postbuild": "node scripts/build.post.js",
|
|
13
15
|
"clean": "rimraf dist",
|
|
14
16
|
"format": "prettier --write .",
|
|
15
|
-
"dev:start": "node src/dev/start.js",
|
|
16
|
-
"dev:build": "node src/dev/build.js"
|
|
17
|
-
},
|
|
18
|
-
"exports": {
|
|
19
|
-
".": {
|
|
20
|
-
"default": "./dist/client/index.js"
|
|
21
|
-
},
|
|
22
|
-
"./compiler": {
|
|
23
|
-
"default": "./dist/compiler/index.js"
|
|
24
|
-
},
|
|
25
|
-
"./decorators": {
|
|
26
|
-
"default": "./dist/client/decorators/index.js"
|
|
27
|
-
},
|
|
28
|
-
"./helpers": {
|
|
29
|
-
"default": "./dist/client/helpers/index.js"
|
|
30
|
-
},
|
|
31
|
-
"./runtime": {
|
|
32
|
-
"default": "./dist/runtime/index.js"
|
|
33
|
-
},
|
|
34
|
-
"./services": {
|
|
35
|
-
"default": "./dist/client/services/index.js"
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
"typesVersions": {
|
|
39
|
-
"*": {
|
|
40
|
-
"*": [
|
|
41
|
-
"./dist/client/index.d.ts"
|
|
42
|
-
],
|
|
43
|
-
"compiler": [
|
|
44
|
-
"./dist/compiler/index.d.ts"
|
|
45
|
-
],
|
|
46
|
-
"decorators": [
|
|
47
|
-
"./dist/client/decorators/index.d.ts"
|
|
48
|
-
],
|
|
49
|
-
"helpers": [
|
|
50
|
-
"./dist/client/helpers/index.d.ts"
|
|
51
|
-
],
|
|
52
|
-
"runtime": [
|
|
53
|
-
"./dist/runtime/index.d.ts"
|
|
54
|
-
],
|
|
55
|
-
"services": [
|
|
56
|
-
"./dist/client/services/index.d.ts"
|
|
57
|
-
]
|
|
58
|
-
}
|
|
17
|
+
"dev:start": "node src/dev/scripts/start.js",
|
|
18
|
+
"dev:build": "node src/dev/scripts/build.js"
|
|
59
19
|
},
|
|
60
20
|
"files": [
|
|
61
|
-
"
|
|
21
|
+
"client",
|
|
22
|
+
"compiler",
|
|
23
|
+
"constants",
|
|
24
|
+
"runtime",
|
|
25
|
+
"types",
|
|
62
26
|
"package.json",
|
|
63
27
|
"README.md"
|
|
64
28
|
],
|
|
@@ -84,7 +48,6 @@
|
|
|
84
48
|
"fast-glob": "^3.2.11",
|
|
85
49
|
"handlebars": "^4.7.7",
|
|
86
50
|
"log-update": "^5.0.0",
|
|
87
|
-
"sass": "^1.43.4",
|
|
88
51
|
"ts-node": "^10.4.0",
|
|
89
52
|
"typescript": "^4.5.2",
|
|
90
53
|
"uhtml": "^2.7.6"
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import * as CONSTANTS from '../../configs/constants.js';
|
|
2
|
-
import { appendToMethod, host, sync } from '../utils/index.js';
|
|
3
|
-
export function Attributes() {
|
|
4
|
-
return function (target, propertyKey) {
|
|
5
|
-
let update;
|
|
6
|
-
appendToMethod(target, CONSTANTS.LIFECYCLE_CONNECTED, function () {
|
|
7
|
-
update = sync(host(this));
|
|
8
|
-
});
|
|
9
|
-
appendToMethod(target, CONSTANTS.LIFECYCLE_UPDATED, function () {
|
|
10
|
-
update(this[propertyKey]);
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { defineProperty } from '../utils/index.js';
|
|
2
|
-
export function Bind() {
|
|
3
|
-
return function (target, propertyKey, descriptor) {
|
|
4
|
-
return {
|
|
5
|
-
configurable: true,
|
|
6
|
-
get() {
|
|
7
|
-
const value = descriptor === null || descriptor === void 0 ? void 0 : descriptor.value.bind(this);
|
|
8
|
-
defineProperty(this, propertyKey, {
|
|
9
|
-
value,
|
|
10
|
-
configurable: true,
|
|
11
|
-
writable: true
|
|
12
|
-
});
|
|
13
|
-
return value;
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { camelCase, paramCase } from 'change-case';
|
|
2
|
-
import * as CONSTANTS from '../../configs/constants.js';
|
|
3
|
-
import { call, getMembers, isServer, parseValue, request } from '../utils/index.js';
|
|
4
|
-
export function Element(tag) {
|
|
5
|
-
return function (constructor) {
|
|
6
|
-
if (isServer())
|
|
7
|
-
return;
|
|
8
|
-
const members = getMembers(constructor);
|
|
9
|
-
class Plus extends HTMLElement {
|
|
10
|
-
constructor() {
|
|
11
|
-
var _a;
|
|
12
|
-
super();
|
|
13
|
-
this.plus = new constructor();
|
|
14
|
-
this.plus[CONSTANTS.API_HOST] = () => this;
|
|
15
|
-
(_a = this.plus[CONSTANTS.API_SETUP]) === null || _a === void 0 ? void 0 : _a.forEach((setup) => setup.call(this.plus));
|
|
16
|
-
this.attachShadow({ mode: 'open' });
|
|
17
|
-
}
|
|
18
|
-
static get observedAttributes() {
|
|
19
|
-
return Object.keys(members)
|
|
20
|
-
.filter((key) => members[key][0] != CONSTANTS.TYPE_FUNCTION)
|
|
21
|
-
.map((key) => paramCase(key));
|
|
22
|
-
}
|
|
23
|
-
adoptedCallback() {
|
|
24
|
-
call(this.plus, CONSTANTS.LIFECYCLE_ADOPTED);
|
|
25
|
-
}
|
|
26
|
-
attributeChangedCallback(name, prev, next) {
|
|
27
|
-
const key = camelCase(name);
|
|
28
|
-
const [type] = members[key];
|
|
29
|
-
const parsed = parseValue(next, type);
|
|
30
|
-
this.plus[key] = parsed;
|
|
31
|
-
}
|
|
32
|
-
connectedCallback() {
|
|
33
|
-
this.plus[CONSTANTS.API_READY] = true;
|
|
34
|
-
call(this.plus, CONSTANTS.LIFECYCLE_CONNECTED);
|
|
35
|
-
request(this.plus)
|
|
36
|
-
.then(() => {
|
|
37
|
-
call(this.plus, CONSTANTS.LIFECYCLE_LOADED);
|
|
38
|
-
})
|
|
39
|
-
.catch((error) => {
|
|
40
|
-
throw error;
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
disconnectedCallback() {
|
|
44
|
-
call(this.plus, CONSTANTS.LIFECYCLE_DISCONNECTED);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
customElements.define(tag, Plus);
|
|
48
|
-
};
|
|
49
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { PlusElement } from '../../types/index.js';
|
|
2
|
-
export declare type EventEmitter<T = any> = (data?: T) => CustomEvent<T>;
|
|
3
|
-
export interface EventOptions {
|
|
4
|
-
/**
|
|
5
|
-
* A string custom event name to override the default.
|
|
6
|
-
*/
|
|
7
|
-
name?: string;
|
|
8
|
-
/**
|
|
9
|
-
* A Boolean indicating whether the event bubbles up through the DOM or not. default is `false`.
|
|
10
|
-
*/
|
|
11
|
-
bubbles?: boolean;
|
|
12
|
-
/**
|
|
13
|
-
* A Boolean indicating whether the event is cancelable. default is `false`.
|
|
14
|
-
*/
|
|
15
|
-
cancelable?: boolean;
|
|
16
|
-
/**
|
|
17
|
-
* A Boolean value indicating whether or not the event can bubble across the boundary between the shadow DOM and the regular DOM. The default is false.
|
|
18
|
-
*/
|
|
19
|
-
composed?: boolean;
|
|
20
|
-
}
|
|
21
|
-
export declare function Event<T = any>(options?: EventOptions): (target: PlusElement, propertyKey: PropertyKey) => void;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { defineProperty, host } from '../utils/index.js';
|
|
2
|
-
// TODO: add global hook
|
|
3
|
-
export function Event(options = {}) {
|
|
4
|
-
return function (target, propertyKey) {
|
|
5
|
-
defineProperty(target, propertyKey, {
|
|
6
|
-
get() {
|
|
7
|
-
return (detail) => {
|
|
8
|
-
var _a;
|
|
9
|
-
(_a = options.bubbles) !== null && _a !== void 0 ? _a : (options.bubbles = false);
|
|
10
|
-
const name = options.name || String(propertyKey);
|
|
11
|
-
const event = new CustomEvent(name, Object.assign(Object.assign({}, options), { detail }));
|
|
12
|
-
host(this).dispatchEvent(event);
|
|
13
|
-
return event;
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
};
|
|
18
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export * from './attributes.js';
|
|
2
|
-
export * from './bind.js';
|
|
3
|
-
export * from './element.js';
|
|
4
|
-
export * from './event.js';
|
|
5
|
-
export * from './listen.js';
|
|
6
|
-
export * from './method.js';
|
|
7
|
-
export * from './property.js';
|
|
8
|
-
export * from './state.js';
|
|
9
|
-
export * from './watch.js';
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export * from './attributes.js';
|
|
2
|
-
export * from './bind.js';
|
|
3
|
-
export * from './element.js';
|
|
4
|
-
export * from './event.js';
|
|
5
|
-
export * from './listen.js';
|
|
6
|
-
export * from './method.js';
|
|
7
|
-
export * from './property.js';
|
|
8
|
-
export * from './state.js';
|
|
9
|
-
export * from './watch.js';
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { PlusElement } from '../../types/index.js';
|
|
2
|
-
export interface ListenOptions {
|
|
3
|
-
target?: 'host' | 'body' | 'document' | 'window';
|
|
4
|
-
once?: boolean;
|
|
5
|
-
passive?: boolean;
|
|
6
|
-
signal?: AbortSignal;
|
|
7
|
-
capture?: boolean;
|
|
8
|
-
}
|
|
9
|
-
export declare function Listen(name: string, options?: ListenOptions): (target: PlusElement, propertyKey: PropertyKey, descriptor: PropertyDescriptor) => {
|
|
10
|
-
configurable: boolean;
|
|
11
|
-
get(): any;
|
|
12
|
-
};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import * as CONSTANTS from '../../configs/constants.js';
|
|
2
|
-
import { appendToMethod, host, on, off } from '../utils/index.js';
|
|
3
|
-
import { Bind } from './bind.js';
|
|
4
|
-
const defaults = {
|
|
5
|
-
target: 'host'
|
|
6
|
-
};
|
|
7
|
-
export function Listen(name, options = defaults) {
|
|
8
|
-
return function (target, propertyKey, descriptor) {
|
|
9
|
-
// TODO: types
|
|
10
|
-
const element = (instance) => {
|
|
11
|
-
switch (options.target) {
|
|
12
|
-
case 'body':
|
|
13
|
-
return window.document.body;
|
|
14
|
-
case 'document':
|
|
15
|
-
return window.document;
|
|
16
|
-
case 'window':
|
|
17
|
-
return window;
|
|
18
|
-
case 'host':
|
|
19
|
-
return host(instance);
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
appendToMethod(target, CONSTANTS.LIFECYCLE_CONNECTED, function () {
|
|
23
|
-
on(element(this), name, this[propertyKey], options);
|
|
24
|
-
});
|
|
25
|
-
appendToMethod(target, CONSTANTS.LIFECYCLE_DISCONNECTED, function () {
|
|
26
|
-
off(element(this), name, this[propertyKey], options);
|
|
27
|
-
});
|
|
28
|
-
return Bind()(target, propertyKey, descriptor);
|
|
29
|
-
};
|
|
30
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { defineProperty, host, onReady } from '../utils/index.js';
|
|
2
|
-
export function Method() {
|
|
3
|
-
return function (target, propertyKey) {
|
|
4
|
-
onReady(target, function () {
|
|
5
|
-
defineProperty(host(this), propertyKey, {
|
|
6
|
-
get: () => {
|
|
7
|
-
return this[propertyKey].bind(this);
|
|
8
|
-
}
|
|
9
|
-
});
|
|
10
|
-
});
|
|
11
|
-
};
|
|
12
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { PlusElement } from '../../types/index.js';
|
|
2
|
-
export interface PropertyOptions {
|
|
3
|
-
/**
|
|
4
|
-
* TODO
|
|
5
|
-
*/
|
|
6
|
-
attribute?: boolean | string;
|
|
7
|
-
/**
|
|
8
|
-
* Whether property value is reflected back to the associated attribute. default is `false`.
|
|
9
|
-
*/
|
|
10
|
-
reflect?: boolean;
|
|
11
|
-
}
|
|
12
|
-
export declare function Property(options?: PropertyOptions): (target: PlusElement, propertyKey: PropertyKey) => void;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { defineProperty, getMembers, host, isReady, parseValue, request, updateAttribute, onReady } from '../utils/index.js';
|
|
2
|
-
export function Property(options) {
|
|
3
|
-
return function (target, propertyKey) {
|
|
4
|
-
const values = new Map();
|
|
5
|
-
defineProperty(target, propertyKey, {
|
|
6
|
-
get() {
|
|
7
|
-
return values.get(this);
|
|
8
|
-
},
|
|
9
|
-
set(input) {
|
|
10
|
-
const value = values.get(this);
|
|
11
|
-
if (value === input)
|
|
12
|
-
return;
|
|
13
|
-
values.set(this, input);
|
|
14
|
-
// TODO
|
|
15
|
-
const ready = isReady(this);
|
|
16
|
-
request(this, { [propertyKey]: [input, value] })
|
|
17
|
-
.then((renderd) => {
|
|
18
|
-
const name = String(propertyKey);
|
|
19
|
-
const element = host(this);
|
|
20
|
-
const hasAttribute = element.hasAttribute(name);
|
|
21
|
-
// TODO
|
|
22
|
-
if ((options === null || options === void 0 ? void 0 : options.reflect) && !hasAttribute && !renderd && !ready)
|
|
23
|
-
updateAttribute(element, name, input);
|
|
24
|
-
if (!renderd)
|
|
25
|
-
return;
|
|
26
|
-
if (!(options === null || options === void 0 ? void 0 : options.reflect))
|
|
27
|
-
return;
|
|
28
|
-
const raw = element.getAttribute(name);
|
|
29
|
-
const [type] = getMembers(target)[propertyKey];
|
|
30
|
-
const parsed = parseValue(raw, type);
|
|
31
|
-
if (parsed === input)
|
|
32
|
-
return;
|
|
33
|
-
updateAttribute(element, name, input);
|
|
34
|
-
})
|
|
35
|
-
.catch((error) => {
|
|
36
|
-
throw error;
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
onReady(target, function () {
|
|
41
|
-
defineProperty(host(this), propertyKey, {
|
|
42
|
-
get: () => {
|
|
43
|
-
return this[propertyKey];
|
|
44
|
-
},
|
|
45
|
-
set: (value) => {
|
|
46
|
-
this[propertyKey] = value;
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
};
|
|
51
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { defineProperty, host, onReady, request } from '../utils/index.js';
|
|
2
|
-
export function State() {
|
|
3
|
-
return function (target, propertyKey) {
|
|
4
|
-
const values = new Map();
|
|
5
|
-
defineProperty(target, propertyKey, {
|
|
6
|
-
get() {
|
|
7
|
-
return values.get(this);
|
|
8
|
-
},
|
|
9
|
-
set(input) {
|
|
10
|
-
const value = values.get(this);
|
|
11
|
-
if (value === input)
|
|
12
|
-
return;
|
|
13
|
-
values.set(this, input);
|
|
14
|
-
request(this, { [propertyKey]: [input, value] })
|
|
15
|
-
.then(() => { })
|
|
16
|
-
.catch((error) => {
|
|
17
|
-
throw error;
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
onReady(target, function () {
|
|
22
|
-
defineProperty(host(this), propertyKey, {
|
|
23
|
-
get: () => {
|
|
24
|
-
return this[propertyKey];
|
|
25
|
-
},
|
|
26
|
-
set: (value) => {
|
|
27
|
-
this[propertyKey] = value;
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import * as CONSTANTS from '../../configs/constants.js';
|
|
2
|
-
import { appendToMethod } from '../utils/index.js';
|
|
3
|
-
// TODO: support * key
|
|
4
|
-
export function Watch(...keys) {
|
|
5
|
-
return function (target, propertyKey) {
|
|
6
|
-
if (!keys.length)
|
|
7
|
-
return;
|
|
8
|
-
appendToMethod(target, CONSTANTS.LIFECYCLE_UPDATED, function (args) {
|
|
9
|
-
const [states] = args;
|
|
10
|
-
for (const key of keys) {
|
|
11
|
-
if (states === null || states === void 0 ? void 0 : states[key]) {
|
|
12
|
-
this[propertyKey](...states[key], key);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const classes: (input: any, smart?: boolean | undefined) => string;
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { paramCase } from 'change-case';
|
|
2
|
-
import { typeOf } from '../utils/index.js';
|
|
3
|
-
export const classes = (input, smart) => {
|
|
4
|
-
const result = [];
|
|
5
|
-
switch (typeOf(input)) {
|
|
6
|
-
case 'array': {
|
|
7
|
-
input.forEach((item) => {
|
|
8
|
-
const value = classes(item, smart);
|
|
9
|
-
if (!value)
|
|
10
|
-
return;
|
|
11
|
-
result.push(value);
|
|
12
|
-
});
|
|
13
|
-
break;
|
|
14
|
-
}
|
|
15
|
-
case 'object': {
|
|
16
|
-
const keys = Object.keys(input);
|
|
17
|
-
for (const key of keys) {
|
|
18
|
-
const value = input[key];
|
|
19
|
-
const name = paramCase(key);
|
|
20
|
-
const type = typeOf(value);
|
|
21
|
-
if (!smart) {
|
|
22
|
-
if (!value)
|
|
23
|
-
continue;
|
|
24
|
-
result.push(name);
|
|
25
|
-
continue;
|
|
26
|
-
}
|
|
27
|
-
switch (type) {
|
|
28
|
-
case 'boolean': {
|
|
29
|
-
if (!value)
|
|
30
|
-
continue;
|
|
31
|
-
result.push(`${name}`);
|
|
32
|
-
break;
|
|
33
|
-
}
|
|
34
|
-
case 'number': {
|
|
35
|
-
result.push(`${name}-${value}`);
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
case 'string': {
|
|
39
|
-
switch (value) {
|
|
40
|
-
case '':
|
|
41
|
-
case 'true':
|
|
42
|
-
result.push(`${name}`);
|
|
43
|
-
break;
|
|
44
|
-
case 'false':
|
|
45
|
-
break;
|
|
46
|
-
default:
|
|
47
|
-
result.push(`${name}-${value}`);
|
|
48
|
-
break;
|
|
49
|
-
}
|
|
50
|
-
break;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
break;
|
|
55
|
-
}
|
|
56
|
-
case 'string': {
|
|
57
|
-
result.push(input);
|
|
58
|
-
break;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return result.join(' ');
|
|
62
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export * from './classes.js';
|
|
2
|
-
export * from './direction.js';
|
|
3
|
-
export * from './is-rtl.js';
|
|
4
|
-
export * from './query.js';
|
|
5
|
-
export * from './query-all.js';
|
|
6
|
-
export * from './slots.js';
|
|
7
|
-
export * from './styles.js';
|
|
8
|
-
export * from './to-unit.js';
|
|
9
|
-
export { host, isServer, on, off } from '../utils/index.js';
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export * from './classes.js';
|
|
2
|
-
export * from './direction.js';
|
|
3
|
-
export * from './is-rtl.js';
|
|
4
|
-
export * from './query.js';
|
|
5
|
-
export * from './query-all.js';
|
|
6
|
-
export * from './slots.js';
|
|
7
|
-
export * from './styles.js';
|
|
8
|
-
export * from './to-unit.js';
|
|
9
|
-
export { host, isServer, on, off } from '../utils/index.js';
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
export declare function queryAll<K extends keyof HTMLElementTagNameMap>(target: any, selectors: K): NodeListOf<HTMLElementTagNameMap[K]>;
|
|
2
|
-
export declare function queryAll<K extends keyof SVGElementTagNameMap>(target: any, selectors: K): NodeListOf<SVGElementTagNameMap[K]>;
|
|
3
|
-
export declare function queryAll<E extends Element = Element>(target: any, selectors: string): NodeListOf<E>;
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
export declare function query<K extends keyof HTMLElementTagNameMap>(target: any, selectors: K): HTMLElementTagNameMap[K] | null;
|
|
2
|
-
export declare function query<K extends keyof SVGElementTagNameMap>(target: any, selectors: K): SVGElementTagNameMap[K] | null;
|
|
3
|
-
export declare function query<E extends Element = Element>(target: any, selectors: string): E | null;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { defineProperty } from '../utils/index.js';
|
|
2
|
-
import { queryAll } from './query-all.js';
|
|
3
|
-
export const slots = (target) => {
|
|
4
|
-
var _a;
|
|
5
|
-
const result = {};
|
|
6
|
-
(_a = queryAll(target, 'slot')) === null || _a === void 0 ? void 0 : _a.forEach((slot) => {
|
|
7
|
-
const name = slot.name || 'default';
|
|
8
|
-
defineProperty(result, name, {
|
|
9
|
-
get() {
|
|
10
|
-
return !!slot.assignedNodes().filter((node) => { var _a; return node.nodeName != '#text' || ((_a = node.nodeValue) === null || _a === void 0 ? void 0 : _a.trim()); }).length;
|
|
11
|
-
}
|
|
12
|
-
});
|
|
13
|
-
});
|
|
14
|
-
return result;
|
|
15
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const styles: (input: any) => string;
|