@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
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { paramCase } from 'change-case';
|
|
2
|
-
import { typeOf } from '../utils/index.js';
|
|
3
|
-
export const styles = (input) => {
|
|
4
|
-
switch (typeOf(input)) {
|
|
5
|
-
case 'array':
|
|
6
|
-
return input.join('; ');
|
|
7
|
-
case 'object':
|
|
8
|
-
return Object.keys(input)
|
|
9
|
-
.map((key) => `${paramCase(key)}: ${input[key]}`)
|
|
10
|
-
.join('; ');
|
|
11
|
-
case 'string':
|
|
12
|
-
return input;
|
|
13
|
-
default:
|
|
14
|
-
return '';
|
|
15
|
-
}
|
|
16
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const toUnit: (input: string | number, unit?: string) => string | undefined;
|
package/dist/client/index.d.ts
DELETED
package/dist/client/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './link.js';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './link.js';
|
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
import { defineProperty, host } from '../utils/index.js';
|
|
2
|
-
const links = new Map();
|
|
3
|
-
// TODO: return type
|
|
4
|
-
export const createLink = (namespace) => {
|
|
5
|
-
if (links.has(namespace))
|
|
6
|
-
return links.get(namespace);
|
|
7
|
-
const config = {
|
|
8
|
-
scope: (i) => i.connector
|
|
9
|
-
};
|
|
10
|
-
let disconnecting = false;
|
|
11
|
-
const children = new Map();
|
|
12
|
-
const parents = new Map();
|
|
13
|
-
const properties = [];
|
|
14
|
-
const find = (source) => {
|
|
15
|
-
return properties.find((destination) => destination.instance === source.instance && destination.name === source.name);
|
|
16
|
-
};
|
|
17
|
-
const register = (source) => {
|
|
18
|
-
properties.push(source);
|
|
19
|
-
if (!children.has(source.instance))
|
|
20
|
-
children.set(source.instance, new Set());
|
|
21
|
-
// TODO: any
|
|
22
|
-
const siblings = children.get(source.instance);
|
|
23
|
-
siblings.add(source);
|
|
24
|
-
};
|
|
25
|
-
const unregister = (source) => {
|
|
26
|
-
// TODO: any
|
|
27
|
-
source = find(source);
|
|
28
|
-
const index = properties.findIndex((property) => property === source);
|
|
29
|
-
if (index === -1)
|
|
30
|
-
return;
|
|
31
|
-
properties.splice(index, 1);
|
|
32
|
-
// TODO: any
|
|
33
|
-
const siblings = children.get(source.instance);
|
|
34
|
-
siblings.delete(source);
|
|
35
|
-
if (siblings.size)
|
|
36
|
-
return;
|
|
37
|
-
children.delete(source.instance);
|
|
38
|
-
parents.delete(source.instance);
|
|
39
|
-
};
|
|
40
|
-
const get = (source) => {
|
|
41
|
-
// TODO: any
|
|
42
|
-
return source.instance[source.name];
|
|
43
|
-
};
|
|
44
|
-
const set = (source, value) => {
|
|
45
|
-
// TODO: any
|
|
46
|
-
source.instance[source.name] = value;
|
|
47
|
-
};
|
|
48
|
-
const reset = (source) => {
|
|
49
|
-
if (source.type === 'action')
|
|
50
|
-
return;
|
|
51
|
-
if (source.type === 'inject')
|
|
52
|
-
return set(source, source.value /* TODO */);
|
|
53
|
-
// TODO: any
|
|
54
|
-
defineProperty(source.instance, source.name, {
|
|
55
|
-
value: get(source) /* TODO */,
|
|
56
|
-
enumerable: true,
|
|
57
|
-
configurable: true
|
|
58
|
-
});
|
|
59
|
-
};
|
|
60
|
-
const map = (source, destination) => {
|
|
61
|
-
let value = get(source);
|
|
62
|
-
if (typeof value === 'function')
|
|
63
|
-
value = value.bind(source.instance);
|
|
64
|
-
set(destination, value);
|
|
65
|
-
};
|
|
66
|
-
const proxy = (source) => {
|
|
67
|
-
let value = get(source);
|
|
68
|
-
// TODO: any
|
|
69
|
-
defineProperty(source.instance, source.name, {
|
|
70
|
-
enumerable: true,
|
|
71
|
-
configurable: true,
|
|
72
|
-
get() {
|
|
73
|
-
return value;
|
|
74
|
-
},
|
|
75
|
-
set(input) {
|
|
76
|
-
if (input === value)
|
|
77
|
-
return;
|
|
78
|
-
value = input;
|
|
79
|
-
siblings(source, ['inject']).map((destination) => set(destination, value));
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
};
|
|
83
|
-
const parent = (source) => {
|
|
84
|
-
var _a;
|
|
85
|
-
const cache = parents.get(source.instance);
|
|
86
|
-
if (cache)
|
|
87
|
-
return cache;
|
|
88
|
-
// TODO: element? and any
|
|
89
|
-
let parent = (_a = source.element) === null || _a === void 0 ? void 0 : _a.parentElement;
|
|
90
|
-
while (parent) {
|
|
91
|
-
if (parent.shadowRoot) {
|
|
92
|
-
const item = properties.find((property) => property.element === parent && property.name === source.name);
|
|
93
|
-
if (item) {
|
|
94
|
-
parents.set(source.instance, item);
|
|
95
|
-
return item;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
parent = parent.parentElement;
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
const scope = (source) => {
|
|
102
|
-
var _a, _b;
|
|
103
|
-
if (!source)
|
|
104
|
-
return;
|
|
105
|
-
// TODO
|
|
106
|
-
if (disconnecting)
|
|
107
|
-
return source.instance['$scope-prev'];
|
|
108
|
-
// TODO: &&
|
|
109
|
-
let input = config.scope && config.scope(source.instance);
|
|
110
|
-
if (typeof input !== 'undefined')
|
|
111
|
-
return input;
|
|
112
|
-
// TODO: any
|
|
113
|
-
return ((_b = (_a = scope(parent(source))) !== null && _a !== void 0 ? _a : source.instance['$scope-auto']) !== null && _b !== void 0 ? _b : (source.instance['$scope-auto'] = Math.random()));
|
|
114
|
-
};
|
|
115
|
-
const siblings = (source, types) => {
|
|
116
|
-
return properties.filter((destination) => {
|
|
117
|
-
// TODO: any
|
|
118
|
-
if (!types.includes(destination.type))
|
|
119
|
-
return false;
|
|
120
|
-
if (source === destination)
|
|
121
|
-
return false;
|
|
122
|
-
if (source.name !== destination.name)
|
|
123
|
-
return false;
|
|
124
|
-
if (scope(source) !== scope(destination))
|
|
125
|
-
return false;
|
|
126
|
-
return true;
|
|
127
|
-
});
|
|
128
|
-
};
|
|
129
|
-
const connect = (source) => {
|
|
130
|
-
// TODO
|
|
131
|
-
source.instance['$scope-prev'] = scope(source);
|
|
132
|
-
register(source);
|
|
133
|
-
switch (source.type) {
|
|
134
|
-
case 'action':
|
|
135
|
-
siblings(source, ['inject']).forEach((destination) => map(source, destination));
|
|
136
|
-
break;
|
|
137
|
-
case 'observable':
|
|
138
|
-
proxy(source);
|
|
139
|
-
siblings(source, ['inject']).forEach((destination) => map(source, destination));
|
|
140
|
-
break;
|
|
141
|
-
case 'inject':
|
|
142
|
-
siblings(source, ['action', 'observable']).forEach((destination) => map(destination, source));
|
|
143
|
-
break;
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
const disconnect = (source) => {
|
|
147
|
-
reset(source);
|
|
148
|
-
if (source.type === 'inject')
|
|
149
|
-
return unregister(source);
|
|
150
|
-
siblings(source, ['inject']).forEach(reset);
|
|
151
|
-
unregister(source);
|
|
152
|
-
};
|
|
153
|
-
const reconnect = (instance) => {
|
|
154
|
-
const p = properties.filter((property) => property.instance === instance);
|
|
155
|
-
disconnecting = true;
|
|
156
|
-
p.forEach(disconnect);
|
|
157
|
-
disconnecting = false;
|
|
158
|
-
p.forEach(connect);
|
|
159
|
-
};
|
|
160
|
-
const decorator = (type) => () => (target, name) => {
|
|
161
|
-
const connected = target.connectedCallback;
|
|
162
|
-
target.connectedCallback = function () {
|
|
163
|
-
connected && connected.bind(this)();
|
|
164
|
-
const property = {
|
|
165
|
-
element: host(this),
|
|
166
|
-
instance: this,
|
|
167
|
-
name,
|
|
168
|
-
type,
|
|
169
|
-
value: this[name]
|
|
170
|
-
};
|
|
171
|
-
if (find(property))
|
|
172
|
-
console.error('TODO: Error log');
|
|
173
|
-
connect(property);
|
|
174
|
-
};
|
|
175
|
-
const disconnected = target.disconnectedCallback;
|
|
176
|
-
target.disconnectedCallback = function () {
|
|
177
|
-
disconnected && disconnected.bind(this)();
|
|
178
|
-
const property = find({ instance: this, name });
|
|
179
|
-
if (!property)
|
|
180
|
-
console.error('TODO: Error log');
|
|
181
|
-
// TODO: any
|
|
182
|
-
disconnect(property);
|
|
183
|
-
};
|
|
184
|
-
};
|
|
185
|
-
const Action = decorator('action');
|
|
186
|
-
const Inject = decorator('inject');
|
|
187
|
-
const Observable = decorator('observable');
|
|
188
|
-
const result = {
|
|
189
|
-
Action,
|
|
190
|
-
Inject,
|
|
191
|
-
Observable,
|
|
192
|
-
reconnect
|
|
193
|
-
};
|
|
194
|
-
links.set(namespace, result);
|
|
195
|
-
return result;
|
|
196
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export const appendToMethod = (target, propertyKey, handler) => {
|
|
2
|
-
const callback = target[propertyKey];
|
|
3
|
-
target[propertyKey] = function () {
|
|
4
|
-
handler.bind(this)(Array.from(arguments));
|
|
5
|
-
return callback === null || callback === void 0 ? void 0 : callback.bind(this)(arguments);
|
|
6
|
-
};
|
|
7
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const defineProperty: <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const defineProperty = Object.defineProperty;
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
export declare const on: (target: Window | Document | Element, event: string, handler: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions | undefined) => void;
|
|
2
|
-
export declare const off: (target: Window | Document | Element, event: string, handler: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions | undefined) => void;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export * from './append-to-method.js';
|
|
2
|
-
export * from './call.js';
|
|
3
|
-
export * from './define-property.js';
|
|
4
|
-
export * from './event.js';
|
|
5
|
-
export * from './get-members.js';
|
|
6
|
-
export * from './get-styles.js';
|
|
7
|
-
export * from './host.js';
|
|
8
|
-
export * from './is-event.js';
|
|
9
|
-
export * from './is-ready.js';
|
|
10
|
-
export * from './is-server.js';
|
|
11
|
-
export * from './on-ready.js';
|
|
12
|
-
export * from './parse-value.js';
|
|
13
|
-
export * from './render.js';
|
|
14
|
-
export * from './request.js';
|
|
15
|
-
export * from './sync.js';
|
|
16
|
-
export * from './task.js';
|
|
17
|
-
export * from './to-boolean.js';
|
|
18
|
-
export * from './to-event.js';
|
|
19
|
-
export * from './type-of.js';
|
|
20
|
-
export * from './update-attribute.js';
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export * from './append-to-method.js';
|
|
2
|
-
export * from './call.js';
|
|
3
|
-
export * from './define-property.js';
|
|
4
|
-
export * from './event.js';
|
|
5
|
-
export * from './get-members.js';
|
|
6
|
-
export * from './get-styles.js';
|
|
7
|
-
export * from './host.js';
|
|
8
|
-
export * from './is-event.js';
|
|
9
|
-
export * from './is-ready.js';
|
|
10
|
-
export * from './is-server.js';
|
|
11
|
-
export * from './on-ready.js';
|
|
12
|
-
export * from './parse-value.js';
|
|
13
|
-
export * from './render.js';
|
|
14
|
-
export * from './request.js';
|
|
15
|
-
export * from './sync.js';
|
|
16
|
-
export * from './task.js';
|
|
17
|
-
export * from './to-boolean.js';
|
|
18
|
-
export * from './to-event.js';
|
|
19
|
-
export * from './type-of.js';
|
|
20
|
-
export * from './update-attribute.js';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const isEvent: (input: string) => boolean;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const isServer: () => boolean;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const parseValue: (value: any, type: any) => any;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import * as CONSTANTS from '../../configs/constants.js';
|
|
2
|
-
import { toBoolean } from './to-boolean.js';
|
|
3
|
-
// TODO: input type & validate date
|
|
4
|
-
export const parseValue = (value, type) => {
|
|
5
|
-
switch (type) {
|
|
6
|
-
case CONSTANTS.TYPE_BOOLEAN:
|
|
7
|
-
return toBoolean(value);
|
|
8
|
-
case CONSTANTS.TYPE_DATE:
|
|
9
|
-
return new Date(value);
|
|
10
|
-
case CONSTANTS.TYPE_NUMBER:
|
|
11
|
-
return parseFloat(value);
|
|
12
|
-
default:
|
|
13
|
-
return value;
|
|
14
|
-
}
|
|
15
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { html, render as renderer } from 'uhtml';
|
|
2
|
-
import * as CONSTANTS from '../../configs/constants.js';
|
|
3
|
-
import { call, getStyles, host } from '../utils/index.js';
|
|
4
|
-
export const render = (target) => {
|
|
5
|
-
const element = host(target);
|
|
6
|
-
renderer(element.shadowRoot, () => {
|
|
7
|
-
const markup = call(target, CONSTANTS.METHOD_RENDER);
|
|
8
|
-
const styles = getStyles(target);
|
|
9
|
-
if (!styles && !markup)
|
|
10
|
-
return html ``;
|
|
11
|
-
if (!styles)
|
|
12
|
-
return markup;
|
|
13
|
-
if (!markup)
|
|
14
|
-
return html `<style>${styles}</style>`;
|
|
15
|
-
return html `<style>${styles}</style>${markup}`;
|
|
16
|
-
});
|
|
17
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import * as CONSTANTS from '../../configs/constants.js';
|
|
2
|
-
import { call, isReady, render, task } from '../utils/index.js';
|
|
3
|
-
const targets = new Map();
|
|
4
|
-
export const request = (target, state) => {
|
|
5
|
-
if (!isReady(target))
|
|
6
|
-
return Promise.resolve(false);
|
|
7
|
-
let run = targets.get(target);
|
|
8
|
-
if (run)
|
|
9
|
-
return run(state);
|
|
10
|
-
run = task({
|
|
11
|
-
canStart: (states, state) => {
|
|
12
|
-
return /* hasChange */ true;
|
|
13
|
-
},
|
|
14
|
-
canRun: (states) => {
|
|
15
|
-
return /* shouldUpdate */ true;
|
|
16
|
-
},
|
|
17
|
-
run: (states) => {
|
|
18
|
-
call(target, CONSTANTS.LIFECYCLE_UPDATE, states);
|
|
19
|
-
render(target);
|
|
20
|
-
call(target, CONSTANTS.LIFECYCLE_UPDATED, states);
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
targets.set(target, run);
|
|
24
|
-
return run(state);
|
|
25
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const sync: (node: HTMLElement) => (next?: any) => void;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { on, off } from './event.js';
|
|
2
|
-
import { isEvent } from './is-event.js';
|
|
3
|
-
import { toEvent } from './to-event.js';
|
|
4
|
-
import { updateAttribute } from './update-attribute.js';
|
|
5
|
-
export const sync = (node) => {
|
|
6
|
-
let prev = {};
|
|
7
|
-
return (next = {}) => {
|
|
8
|
-
const prevClass = (prev.class || '').split(' ');
|
|
9
|
-
const nextClass = (next.class || '').split(' ');
|
|
10
|
-
const newClass = node.className
|
|
11
|
-
.split(' ')
|
|
12
|
-
.filter((key) => !prevClass.includes(key) && !nextClass.includes(key))
|
|
13
|
-
.concat(nextClass)
|
|
14
|
-
.filter((key) => key)
|
|
15
|
-
.join(' ');
|
|
16
|
-
updateAttribute(node, 'class', newClass || undefined);
|
|
17
|
-
if (prev.style || next.style)
|
|
18
|
-
node.setAttribute('style', next.style || '');
|
|
19
|
-
for (const key in prev)
|
|
20
|
-
isEvent(key) && off(node, toEvent(key), prev[key]);
|
|
21
|
-
for (const key in next) {
|
|
22
|
-
if (['class', 'style'].includes(key))
|
|
23
|
-
continue;
|
|
24
|
-
if (isEvent(key))
|
|
25
|
-
on(node, toEvent(key), next[key]);
|
|
26
|
-
else
|
|
27
|
-
updateAttribute(node, key, next[key]);
|
|
28
|
-
}
|
|
29
|
-
prev = Object.assign({}, next);
|
|
30
|
-
};
|
|
31
|
-
};
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
export const task = (options) => {
|
|
11
|
-
let states, isPending, updatePromise;
|
|
12
|
-
const run = (state) => {
|
|
13
|
-
const newStates = Object.assign({}, states, state);
|
|
14
|
-
if (options.canStart && !options.canStart(newStates, state))
|
|
15
|
-
return Promise.resolve(false);
|
|
16
|
-
states = newStates;
|
|
17
|
-
if (!isPending)
|
|
18
|
-
updatePromise = enqueue();
|
|
19
|
-
return updatePromise;
|
|
20
|
-
};
|
|
21
|
-
const enqueue = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
-
isPending = true;
|
|
23
|
-
try {
|
|
24
|
-
yield updatePromise;
|
|
25
|
-
}
|
|
26
|
-
catch (error) {
|
|
27
|
-
Promise.reject(error);
|
|
28
|
-
}
|
|
29
|
-
// TODO: maybe is optional
|
|
30
|
-
if (!isPending)
|
|
31
|
-
return updatePromise;
|
|
32
|
-
try {
|
|
33
|
-
if (options.canRun && !options.canRun(states))
|
|
34
|
-
return (isPending = false);
|
|
35
|
-
options.run(states);
|
|
36
|
-
states = undefined;
|
|
37
|
-
isPending = false;
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
catch (error) {
|
|
41
|
-
isPending = false;
|
|
42
|
-
throw error;
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
return run;
|
|
46
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const toBoolean: (input: any) => boolean;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const toEvent: (input: string) => string;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const updateAttribute: (node: Element, key: string, value: any) => void;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { paramCase } from 'change-case';
|
|
2
|
-
export const updateAttribute = (node, key, value) => {
|
|
3
|
-
const name = paramCase(key);
|
|
4
|
-
if ([undefined, null, false].includes(value))
|
|
5
|
-
return node.removeAttribute(name);
|
|
6
|
-
node.setAttribute(name, value === true ? '' : value);
|
|
7
|
-
};
|