@htmlplus/element 0.3.0 → 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 +4 -4
- package/package.json +8 -45
- 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 -19
- package/dist/client/utils/request.d.ts +0 -2
- package/dist/client/utils/request.js +0 -28
- 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 -37
- 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 -55
- package/dist/compiler/index.d.ts +0 -2
- package/dist/compiler/index.js +0 -2
- package/dist/compiler/plugins/componentDependencyResolver.d.ts +0 -5
- package/dist/compiler/plugins/componentDependencyResolver.js +0 -40
- package/dist/compiler/plugins/customElement.d.ts +0 -5
- package/dist/compiler/plugins/customElement.js +0 -138
- package/dist/compiler/plugins/customElementReact/customElementReact.d.ts +0 -12
- package/dist/compiler/plugins/customElementReact/customElementReact.js +0 -125
- package/dist/compiler/plugins/customElementReact/index.d.ts +0 -1
- package/dist/compiler/plugins/customElementReact/index.js +0 -1
- package/dist/compiler/plugins/customElementReact/templates/README.md.hbs +0 -1
- package/dist/compiler/plugins/customElementReact/templates/_.gitignore.hbs +0 -2
- package/dist/compiler/plugins/customElementReact/templates/package.json.hbs +0 -37
- package/dist/compiler/plugins/customElementReact/templates/rollup.config.js.hbs +0 -21
- package/dist/compiler/plugins/customElementReact/templates/src/components/index.ts.hbs +0 -17
- package/dist/compiler/plugins/customElementReact/templates/src/components/{{fileName}}.compact.ts.hbs +0 -18
- package/dist/compiler/plugins/customElementReact/templates/src/components/{{fileName}}.ts.hbs +0 -26
- package/dist/compiler/plugins/customElementReact/templates/src/index.ts.hbs +0 -1
- package/dist/compiler/plugins/customElementReact/templates/src/proxy.ts.hbs +0 -278
- package/dist/compiler/plugins/customElementReact/templates/tsconfig.json.hbs +0 -17
- 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 -70
- package/dist/compiler/plugins/index.d.ts +0 -7
- package/dist/compiler/plugins/index.js +0 -7
- package/dist/compiler/plugins/parse.d.ts +0 -5
- package/dist/compiler/plugins/parse.js +0 -16
- package/dist/compiler/plugins/read.d.ts +0 -5
- package/dist/compiler/plugins/read.js +0 -13
- package/dist/compiler/plugins/style.d.ts +0 -12
- package/dist/compiler/plugins/style.js +0 -42
- package/dist/compiler/plugins/validate.d.ts +0 -5
- package/dist/compiler/plugins/validate.js +0 -40
- 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/constants/index.d.ts +0 -23
- package/dist/constants/index.js +0 -29
- package/dist/runtime/index.d.ts +0 -1
- package/dist/runtime/index.js +0 -4
- package/dist/types/context.d.ts +0 -32
- package/dist/types/context.js +0 -1
- package/dist/types/global.d.ts +0 -4
- package/dist/types/global.js +0 -1
- package/dist/types/index.d.ts +0 -4
- package/dist/types/index.js +0 -4
- package/dist/types/plugin.d.ts +0 -9
- 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 +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 '../../constants/index.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,19 +0,0 @@
|
|
|
1
|
-
import { html, render as renderer } from 'uhtml';
|
|
2
|
-
import * as CONSTANTS from '../../constants/index.js';
|
|
3
|
-
import { call } from './call.js';
|
|
4
|
-
import { getStyles } from './get-styles.js';
|
|
5
|
-
import { host } from './host.js';
|
|
6
|
-
export const render = (target) => {
|
|
7
|
-
const element = host(target);
|
|
8
|
-
renderer(element.shadowRoot, () => {
|
|
9
|
-
const markup = call(target, CONSTANTS.METHOD_RENDER);
|
|
10
|
-
const styles = getStyles(target);
|
|
11
|
-
if (!styles && !markup)
|
|
12
|
-
return html ``;
|
|
13
|
-
if (!styles)
|
|
14
|
-
return markup;
|
|
15
|
-
if (!markup)
|
|
16
|
-
return html `<style>${styles}</style>`;
|
|
17
|
-
return html `<style>${styles}</style>${markup}`;
|
|
18
|
-
});
|
|
19
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import * as CONSTANTS from '../../constants/index.js';
|
|
2
|
-
import { call } from '../utils/call';
|
|
3
|
-
import { isReady } from '../utils/is-ready';
|
|
4
|
-
import { render } from '../utils/render';
|
|
5
|
-
import { task } from '../utils/task';
|
|
6
|
-
const targets = new Map();
|
|
7
|
-
export const request = (target, state) => {
|
|
8
|
-
if (!isReady(target))
|
|
9
|
-
return Promise.resolve(false);
|
|
10
|
-
let run = targets.get(target);
|
|
11
|
-
if (run)
|
|
12
|
-
return run(state);
|
|
13
|
-
run = task({
|
|
14
|
-
canStart: (states, state) => {
|
|
15
|
-
return /* hasChange */ true;
|
|
16
|
-
},
|
|
17
|
-
canRun: (states) => {
|
|
18
|
-
return /* shouldUpdate */ true;
|
|
19
|
-
},
|
|
20
|
-
run: (states) => {
|
|
21
|
-
call(target, CONSTANTS.LIFECYCLE_UPDATE, states);
|
|
22
|
-
render(target);
|
|
23
|
-
call(target, CONSTANTS.LIFECYCLE_UPDATED, states);
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
targets.set(target, run);
|
|
27
|
-
return run(state);
|
|
28
|
-
};
|
|
@@ -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,37 +0,0 @@
|
|
|
1
|
-
export const task = (options) => {
|
|
2
|
-
let states, isPending, updatePromise;
|
|
3
|
-
const run = (state) => {
|
|
4
|
-
const newStates = Object.assign({}, states, state);
|
|
5
|
-
if (options.canStart && !options.canStart(newStates, state))
|
|
6
|
-
return Promise.resolve(false);
|
|
7
|
-
states = newStates;
|
|
8
|
-
if (!isPending)
|
|
9
|
-
updatePromise = enqueue();
|
|
10
|
-
return updatePromise;
|
|
11
|
-
};
|
|
12
|
-
const enqueue = async () => {
|
|
13
|
-
isPending = true;
|
|
14
|
-
try {
|
|
15
|
-
await updatePromise;
|
|
16
|
-
}
|
|
17
|
-
catch (error) {
|
|
18
|
-
Promise.reject(error);
|
|
19
|
-
}
|
|
20
|
-
// TODO: maybe is optional
|
|
21
|
-
if (!isPending)
|
|
22
|
-
return updatePromise;
|
|
23
|
-
try {
|
|
24
|
-
if (options.canRun && !options.canRun(states))
|
|
25
|
-
return (isPending = false);
|
|
26
|
-
options.run(states);
|
|
27
|
-
states = undefined;
|
|
28
|
-
isPending = false;
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
catch (error) {
|
|
32
|
-
isPending = false;
|
|
33
|
-
throw error;
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
return run;
|
|
37
|
-
};
|
|
@@ -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
|
-
};
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import logUpdate from 'log-update';
|
|
2
|
-
const log = (namespace, message, persist) => {
|
|
3
|
-
logUpdate(`${new Date().toLocaleTimeString()} [@htmlplus/element]${namespace ? `[${namespace}]` : ''} ${message}`);
|
|
4
|
-
persist && logUpdate.done();
|
|
5
|
-
};
|
|
6
|
-
export default (...plugins) => {
|
|
7
|
-
let global = {
|
|
8
|
-
contexts: []
|
|
9
|
-
};
|
|
10
|
-
const start = async () => {
|
|
11
|
-
log(undefined, 'Starting...', true);
|
|
12
|
-
for (const plugin of plugins) {
|
|
13
|
-
if (plugin.start) {
|
|
14
|
-
global = (await plugin.start(global)) || global;
|
|
15
|
-
}
|
|
16
|
-
log(plugin.name, 'Started successfully.');
|
|
17
|
-
}
|
|
18
|
-
log(undefined, `${plugins.length} Plugins started successfully.`, true);
|
|
19
|
-
};
|
|
20
|
-
const next = async (filePath) => {
|
|
21
|
-
const key = filePath.split(/[\/|\\]/g).pop();
|
|
22
|
-
let context = {
|
|
23
|
-
filePath
|
|
24
|
-
};
|
|
25
|
-
log(`${key}`, 'Executing...');
|
|
26
|
-
for (const plugin of plugins) {
|
|
27
|
-
if (!plugin.next)
|
|
28
|
-
continue;
|
|
29
|
-
context = (await plugin.next(context, global)) || context;
|
|
30
|
-
global.contexts = global.contexts.filter((current) => current.filePath != context.filePath).concat(context);
|
|
31
|
-
if (context.isInvalid)
|
|
32
|
-
break;
|
|
33
|
-
}
|
|
34
|
-
if (context.isInvalid)
|
|
35
|
-
log(key, 'Break executing because file is invalid.');
|
|
36
|
-
else
|
|
37
|
-
log(key, 'Executed successfully.');
|
|
38
|
-
return context;
|
|
39
|
-
};
|
|
40
|
-
const finish = async () => {
|
|
41
|
-
log(undefined, 'Finishing...', true);
|
|
42
|
-
for (const plugin of plugins) {
|
|
43
|
-
if (plugin.finish) {
|
|
44
|
-
global = (await plugin.finish(global)) || global;
|
|
45
|
-
}
|
|
46
|
-
log(plugin.name, 'Finished successfully.');
|
|
47
|
-
}
|
|
48
|
-
log(undefined, `${plugins.length} Plugins finished successfully.`, true);
|
|
49
|
-
};
|
|
50
|
-
return {
|
|
51
|
-
start,
|
|
52
|
-
next,
|
|
53
|
-
finish
|
|
54
|
-
};
|
|
55
|
-
};
|
package/dist/compiler/index.d.ts
DELETED
package/dist/compiler/index.js
DELETED