@htmlplus/element 0.1.1 → 0.1.4
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 +123 -25
- package/dist/client/decorators/attributes.js +5 -8
- package/dist/client/decorators/bind.d.ts +4 -1
- package/dist/client/decorators/bind.js +2 -3
- package/dist/client/decorators/element.js +115 -2
- package/dist/client/decorators/event.d.ts +20 -2
- package/dist/client/decorators/event.js +6 -6
- package/dist/client/decorators/index.js +0 -1
- package/dist/client/decorators/listen.d.ts +12 -2
- package/dist/client/decorators/listen.js +5 -10
- package/dist/client/decorators/method.d.ts +2 -1
- package/dist/client/decorators/method.js +9 -13
- package/dist/client/decorators/property.d.ts +12 -2
- package/dist/client/decorators/property.js +25 -18
- package/dist/client/decorators/state.d.ts +2 -1
- package/dist/client/decorators/state.js +19 -17
- package/dist/client/decorators/watch.js +3 -4
- package/dist/client/helpers/direction.d.ts +1 -1
- package/dist/client/helpers/direction.js +1 -1
- package/dist/client/helpers/index.d.ts +1 -3
- package/dist/client/helpers/index.js +1 -3
- package/dist/client/helpers/query-all.js +1 -1
- package/dist/client/helpers/query.js +1 -1
- package/dist/client/services/link.js +3 -3
- package/dist/client/utils/api.d.ts +5 -1
- package/dist/client/utils/append-to-method.d.ts +1 -0
- package/dist/client/utils/append-to-method.js +7 -0
- package/dist/client/{helpers → utils}/event.d.ts +0 -0
- package/dist/client/{helpers → utils}/event.js +0 -0
- package/dist/client/{helpers → utils}/host.d.ts +0 -0
- package/dist/client/{helpers → utils}/host.js +1 -1
- package/dist/client/utils/index.d.ts +4 -4
- package/dist/client/utils/index.js +4 -4
- package/dist/client/utils/on-ready.d.ts +1 -0
- package/dist/client/utils/on-ready.js +4 -0
- package/dist/client/utils/proxy.js +65 -25
- package/dist/client/utils/sync.js +3 -2
- package/dist/compiler/compiler.js +3 -3
- package/dist/compiler/index.d.ts +1 -2
- package/dist/compiler/index.js +1 -2
- package/dist/compiler/plugins/attach.js +7 -10
- package/dist/compiler/plugins/docs.js +1 -0
- package/dist/compiler/plugins/extract.js +14 -2
- package/dist/compiler/plugins/index.d.ts +1 -0
- package/dist/compiler/plugins/index.js +1 -0
- package/dist/compiler/plugins/react.proxy/index.d.ts +1 -0
- package/dist/compiler/plugins/react.proxy/index.js +1 -0
- package/dist/compiler/plugins/react.proxy/react.proxy.d.ts +9 -0
- package/dist/compiler/plugins/react.proxy/react.proxy.js +60 -0
- package/dist/compiler/plugins/react.proxy/templates/README.md.hbs +1 -0
- package/dist/compiler/plugins/react.proxy/templates/_.gitignore.hbs +2 -0
- package/dist/compiler/plugins/react.proxy/templates/package.json.hbs +36 -0
- package/dist/compiler/plugins/react.proxy/templates/rollup.config.js.hbs +20 -0
- package/dist/compiler/plugins/react.proxy/templates/src/components/index.ts.hbs +3 -0
- package/dist/compiler/plugins/react.proxy/templates/src/components/{{fileName}}.ts.hbs +38 -0
- package/dist/compiler/plugins/react.proxy/templates/src/index.ts.hbs +1 -0
- package/dist/compiler/plugins/react.proxy/templates/src/proxy.ts.hbs +277 -0
- package/dist/compiler/plugins/react.proxy/templates/tsconfig.json.hbs +17 -0
- package/dist/compiler/utils/__dirname.d.ts +1 -0
- package/dist/compiler/utils/__dirname.js +5 -0
- package/dist/compiler/utils/index.d.ts +3 -0
- package/dist/compiler/utils/index.js +3 -0
- package/dist/compiler/utils/is-directory-empty.d.ts +1 -0
- package/dist/compiler/utils/is-directory-empty.js +19 -0
- package/dist/compiler/utils/render-template.d.ts +1 -0
- package/dist/compiler/utils/render-template.js +25 -0
- package/dist/types/context.d.ts +2 -0
- package/dist/types/index.d.ts +0 -5
- package/dist/types/index.js +0 -5
- package/dist/types/plugin.d.ts +4 -3
- package/package.json +9 -6
- package/dist/client/decorators/listen-options.d.ts +0 -2
- package/dist/client/decorators/listen-options.js +0 -2
- package/dist/client/helpers/is-server.d.ts +0 -1
- package/dist/client/helpers/is-server.js +0 -1
- package/dist/client/utils/decorator.d.ts +0 -5
- package/dist/client/utils/decorator.js +0 -14
- package/dist/client/utils/define-element.d.ts +0 -1
- package/dist/client/utils/define-element.js +0 -7
- package/dist/client/utils/define-method.d.ts +0 -1
- package/dist/client/utils/define-method.js +0 -7
- package/dist/types/api.d.ts +0 -5
- package/dist/types/api.js +0 -1
- package/dist/types/direction.d.ts +0 -1
- package/dist/types/direction.js +0 -1
- package/dist/types/event-options.d.ts +0 -18
- package/dist/types/event-options.js +0 -1
- package/dist/types/listen-options.d.ts +0 -7
- package/dist/types/listen-options.js +0 -1
- package/dist/types/property-options.d.ts +0 -10
- package/dist/types/property-options.js +0 -1
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import commonjs from '@rollup/plugin-commonjs';
|
|
2
|
+
import resolve from '@rollup/plugin-node-resolve';
|
|
3
|
+
import peerDepsExternal from 'rollup-plugin-peer-deps-external';
|
|
4
|
+
import typescript from 'rollup-plugin-typescript2';
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
input: 'src/index.ts',
|
|
8
|
+
output: [
|
|
9
|
+
{
|
|
10
|
+
dir: 'dist/components',
|
|
11
|
+
format: 'esm'
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
plugins: [
|
|
15
|
+
peerDepsExternal(),
|
|
16
|
+
resolve(),
|
|
17
|
+
commonjs(),
|
|
18
|
+
typescript()
|
|
19
|
+
]
|
|
20
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/* tslint:disable */
|
|
3
|
+
/* auto-generated */
|
|
4
|
+
|
|
5
|
+
import { proxy } from '../proxy';
|
|
6
|
+
import type { JSX } from '{{options.corePackageName}}';
|
|
7
|
+
|
|
8
|
+
{{#each all}}
|
|
9
|
+
import {{componentClassName}} from '{{../options.corePackageName}}/{{fileName}}';
|
|
10
|
+
{{/each}}
|
|
11
|
+
|
|
12
|
+
{{#each all}}
|
|
13
|
+
const {{componentClassName}} = /*@__PURE__*/ proxy<{{componentInterfaceName}}, JSX.{{componentClassName}}>(
|
|
14
|
+
'{{componentTag}}',
|
|
15
|
+
[
|
|
16
|
+
{{#each classProperties}}
|
|
17
|
+
'{{key.name}}',
|
|
18
|
+
{{/each}}
|
|
19
|
+
],
|
|
20
|
+
[
|
|
21
|
+
{{#each classEvents}}
|
|
22
|
+
'{{key.name}}',
|
|
23
|
+
{{/each}}
|
|
24
|
+
],
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
{{/each}}
|
|
28
|
+
{{#if single}}
|
|
29
|
+
export { {{root.componentClassName}} }
|
|
30
|
+
{{else}}
|
|
31
|
+
const All = /*@__PURE__*/ Object.assign({{root.componentClassName}}, {
|
|
32
|
+
{{#each filterd}}
|
|
33
|
+
{{componentClassNameInCategory}}: {{componentClassName}},
|
|
34
|
+
{{/each}}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
export { All as {{root.componentClassName}} }
|
|
38
|
+
{{/if}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './components';
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* version 0.0.9
|
|
3
|
+
*/
|
|
4
|
+
import { camelCase, paramCase, pascalCase } from 'change-case';
|
|
5
|
+
import React from 'react';
|
|
6
|
+
|
|
7
|
+
type EventHandlerType = (event: Event) => any;
|
|
8
|
+
|
|
9
|
+
type FinalPropsType<ElementType> = Omit<PropsType<ElementType>, 'forwardedRef'>;
|
|
10
|
+
|
|
11
|
+
type Mutable<T> = { -readonly [P in keyof T]-?: T[P] };
|
|
12
|
+
|
|
13
|
+
interface ExtraType {
|
|
14
|
+
props?: Array<string>;
|
|
15
|
+
events?: Array<string>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface PropsType<ElementType> extends React.HTMLAttributes<ElementType> {
|
|
19
|
+
forwardedRef: React.RefObject<ElementType>;
|
|
20
|
+
ref?: React.Ref<any>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface StyleReactProps {
|
|
24
|
+
class?: string;
|
|
25
|
+
className?: string;
|
|
26
|
+
style?: {
|
|
27
|
+
[key: string]: any;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const arrayToMap = (array: string[] | DOMTokenList) => {
|
|
32
|
+
const map = new Map<string, string>();
|
|
33
|
+
|
|
34
|
+
(array as string[]).forEach((s: string) => map.set(s, s));
|
|
35
|
+
|
|
36
|
+
return map;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const getCustomEvent = (name: string, events: Array<string>) => {
|
|
40
|
+
// TODO
|
|
41
|
+
name = camelCase(name.slice(3));
|
|
42
|
+
|
|
43
|
+
const event = events.find((event) => event.endsWith(name));
|
|
44
|
+
|
|
45
|
+
if (!event) return;
|
|
46
|
+
|
|
47
|
+
return event;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const forwardRef = <ElementType, PropType>(ReactComponent: any) => {
|
|
51
|
+
const forwardRef = (
|
|
52
|
+
props: PropType & Omit<React.HTMLAttributes<ElementType>, 'style'> & StyleReactProps,
|
|
53
|
+
ref: React.Ref<ElementType>
|
|
54
|
+
) => {
|
|
55
|
+
const { children, ...remainedProps } = props;
|
|
56
|
+
|
|
57
|
+
const newProps = {
|
|
58
|
+
...remainedProps,
|
|
59
|
+
forwardedRef: ref
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
return React.createElement(ReactComponent, newProps, children);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
forwardRef.displayName = ReactComponent.displayName;
|
|
66
|
+
|
|
67
|
+
return React.forwardRef(forwardRef);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const isEvent = (name: string) => {
|
|
71
|
+
return name.indexOf('on') === 0 && name[2] === name[2].toUpperCase();
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const isPrimitive = (value: any) => {
|
|
75
|
+
const type = typeof value;
|
|
76
|
+
|
|
77
|
+
const match = type.match(/boolean|string|number/);
|
|
78
|
+
|
|
79
|
+
return match;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const getProps = <ElementType>(ref: React.Ref<ElementType>, props: PropsType<ElementType>, extra: ExtraType) => {
|
|
83
|
+
const { forwardedRef } = props;
|
|
84
|
+
|
|
85
|
+
const result: FinalPropsType<ElementType> = {
|
|
86
|
+
ref: mergeRefs(forwardedRef, ref)
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
Object.keys(props).forEach((name) => {
|
|
90
|
+
if (name === 'children' || name === 'className' || name === 'forwardedRef' || name === 'ref') return;
|
|
91
|
+
|
|
92
|
+
const value = props[name];
|
|
93
|
+
|
|
94
|
+
if (isEvent(name)) {
|
|
95
|
+
if (typeof document === 'undefined') return;
|
|
96
|
+
|
|
97
|
+
const event = getCustomEvent(name, extra.events);
|
|
98
|
+
|
|
99
|
+
if (event) return;
|
|
100
|
+
|
|
101
|
+
result[name] = value;
|
|
102
|
+
} else if (extra.props.includes(name)) {
|
|
103
|
+
if (!isPrimitive(value)) return;
|
|
104
|
+
|
|
105
|
+
result[paramCase(name)] = value;
|
|
106
|
+
} else {
|
|
107
|
+
result[name] = value;
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
return result;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const mergeRefs =
|
|
115
|
+
<ElementType>(...refs: React.Ref<ElementType>[]) =>
|
|
116
|
+
(value: ElementType) => {
|
|
117
|
+
return refs.forEach((ref) => {
|
|
118
|
+
if (typeof ref === 'function') return ref(value);
|
|
119
|
+
|
|
120
|
+
if (ref == null) return;
|
|
121
|
+
|
|
122
|
+
(ref as Mutable<React.RefObject<ElementType>>).current = value;
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const setClass = <ElementType>(element: ElementType, props: PropsType<ElementType>) => {
|
|
127
|
+
const classes: string[] = [];
|
|
128
|
+
|
|
129
|
+
const current = arrayToMap((element as any).classList);
|
|
130
|
+
|
|
131
|
+
const prev: string = element['$class'];
|
|
132
|
+
const next: string = props.className || (props as any).class;
|
|
133
|
+
|
|
134
|
+
const prevClass = arrayToMap(prev ? prev.split(' ') : []);
|
|
135
|
+
const nextClass = arrayToMap(next ? next.split(' ') : []);
|
|
136
|
+
|
|
137
|
+
current.forEach((key) => {
|
|
138
|
+
if (nextClass.has(key)) {
|
|
139
|
+
classes.push(key);
|
|
140
|
+
|
|
141
|
+
nextClass.delete(key);
|
|
142
|
+
} else if (!prevClass.has(key)) {
|
|
143
|
+
classes.push(key);
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
nextClass.forEach((key) => classes.push(key));
|
|
148
|
+
|
|
149
|
+
const className = classes.join(' ');
|
|
150
|
+
|
|
151
|
+
(element as any).className = className;
|
|
152
|
+
|
|
153
|
+
element['$class'] = className;
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const setEvent = (element: Element, name: string, handler: EventHandlerType) => {
|
|
157
|
+
const events = element['$events'] || (element['$events'] = {});
|
|
158
|
+
|
|
159
|
+
const previous = events[name];
|
|
160
|
+
|
|
161
|
+
previous && element.removeEventListener(name, previous);
|
|
162
|
+
|
|
163
|
+
function callback(event: Event) {
|
|
164
|
+
handler && handler.call(this, event);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
element.addEventListener(name, (events[name] = callback));
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
const setProps = <ElementType>(element: ElementType, props: PropsType<ElementType>, extra: ExtraType) => {
|
|
171
|
+
if (!(element instanceof Element)) return;
|
|
172
|
+
|
|
173
|
+
setClass<ElementType>(element, props);
|
|
174
|
+
|
|
175
|
+
Object.keys(props).forEach((name) => {
|
|
176
|
+
if (
|
|
177
|
+
name === 'children' ||
|
|
178
|
+
name === 'class' ||
|
|
179
|
+
name === 'className' ||
|
|
180
|
+
name === 'forwardedRef' ||
|
|
181
|
+
name === 'ref' ||
|
|
182
|
+
name === 'style'
|
|
183
|
+
)
|
|
184
|
+
return;
|
|
185
|
+
|
|
186
|
+
const value = props[name];
|
|
187
|
+
|
|
188
|
+
if (isEvent(name)) {
|
|
189
|
+
if (typeof document === 'undefined') return;
|
|
190
|
+
|
|
191
|
+
const event = getCustomEvent(name, extra.events);
|
|
192
|
+
|
|
193
|
+
if (!event) return;
|
|
194
|
+
|
|
195
|
+
setEvent(element, event, value);
|
|
196
|
+
} else if (extra.props.includes(name)) {
|
|
197
|
+
if (isPrimitive(value)) {
|
|
198
|
+
element.setAttribute(paramCase(name), value);
|
|
199
|
+
} else {
|
|
200
|
+
element[name] = value;
|
|
201
|
+
}
|
|
202
|
+
} else {
|
|
203
|
+
element[name] = value;
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
export const proxy = <ElementType, PropType>(
|
|
209
|
+
tagName: string,
|
|
210
|
+
props: Array<string> = [],
|
|
211
|
+
events: Array<string> = []
|
|
212
|
+
) => {
|
|
213
|
+
const extra: ExtraType = {
|
|
214
|
+
props,
|
|
215
|
+
events
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
const ReactComponent = class extends React.Component<PropsType<ElementType>> {
|
|
219
|
+
element!: ElementType;
|
|
220
|
+
|
|
221
|
+
setElement = (element: ElementType) => {
|
|
222
|
+
this.element = element;
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
constructor(props: PropsType<ElementType>) {
|
|
226
|
+
super(props);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
componentDidMount() {
|
|
230
|
+
this.componentDidUpdate(/*this.props*/);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
componentDidUpdate(/*prevProps: InternalProps<ElementType>*/) {
|
|
234
|
+
setProps<ElementType>(this.element as any, this.props, extra);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
componentWillUnmount() {
|
|
238
|
+
if (!this.element) return;
|
|
239
|
+
|
|
240
|
+
const events = this.element['$events'] || {};
|
|
241
|
+
|
|
242
|
+
Object.keys(events).forEach((name) => {
|
|
243
|
+
const handler = events[name];
|
|
244
|
+
|
|
245
|
+
(this.element as any).removeEventListener(name, handler);
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
delete this.element['$events'];
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
render() {
|
|
252
|
+
const { children } = this.props;
|
|
253
|
+
|
|
254
|
+
const props = getProps<ElementType>(this.setElement, this.props, extra);
|
|
255
|
+
|
|
256
|
+
return React.createElement(tagName, props, children);
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
// TODO
|
|
261
|
+
// const ReactComponentNew = (props: InternalPropsType<ElementType>) => {
|
|
262
|
+
|
|
263
|
+
// const { children } = props;
|
|
264
|
+
|
|
265
|
+
// const ref = useRef(null);
|
|
266
|
+
|
|
267
|
+
// const newProps: FinalPropsType<ElementType> = getProps(ref, props, events);
|
|
268
|
+
|
|
269
|
+
// useEffect(() => setProps(ref.current, props, events));
|
|
270
|
+
|
|
271
|
+
// return React.createElement(tagName, newProps, children);
|
|
272
|
+
// }
|
|
273
|
+
|
|
274
|
+
ReactComponent['displayName'] = pascalCase(tagName);
|
|
275
|
+
|
|
276
|
+
return forwardRef<ElementType, PropType>(ReactComponent);
|
|
277
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"experimentalDecorators": true,
|
|
4
|
+
"declaration": true,
|
|
5
|
+
"declarationDir": "dist",
|
|
6
|
+
"module": "esnext",
|
|
7
|
+
"target": "es5",
|
|
8
|
+
"lib": ["es6", "dom", "es2016", "es2017"],
|
|
9
|
+
"sourceMap": true,
|
|
10
|
+
"jsx": "react",
|
|
11
|
+
"moduleResolution": "node",
|
|
12
|
+
"allowSyntheticDefaultImports": true,
|
|
13
|
+
"esModuleInterop": true
|
|
14
|
+
},
|
|
15
|
+
"include": ["src"],
|
|
16
|
+
"exclude": ["dist", "node_modules"]
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const __dirname: (url: string | URL) => string;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
export * from './__dirname.js';
|
|
1
2
|
export * from './get-initializer.js';
|
|
2
3
|
export * from './get-tags.js';
|
|
3
4
|
export * from './get-type.js';
|
|
4
5
|
export * from './has-decorator.js';
|
|
6
|
+
export * from './is-directory-empty.js';
|
|
5
7
|
export * from './print-type.js';
|
|
6
8
|
export * from './print.js';
|
|
9
|
+
export * from './render-template.js';
|
|
7
10
|
export * from './visitor.js';
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
export * from './__dirname.js';
|
|
1
2
|
export * from './get-initializer.js';
|
|
2
3
|
export * from './get-tags.js';
|
|
3
4
|
export * from './get-type.js';
|
|
4
5
|
export * from './has-decorator.js';
|
|
6
|
+
export * from './is-directory-empty.js';
|
|
5
7
|
export * from './print-type.js';
|
|
6
8
|
export * from './print.js';
|
|
9
|
+
export * from './render-template.js';
|
|
7
10
|
export * from './visitor.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isDirectoryEmpty: (directory: string) => Promise<boolean>;
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
import fs from 'fs';
|
|
11
|
+
export const isDirectoryEmpty = (directory) => __awaiter(void 0, void 0, void 0, function* () {
|
|
12
|
+
try {
|
|
13
|
+
const files = yield fs.readdirSync(directory);
|
|
14
|
+
return !files.length;
|
|
15
|
+
}
|
|
16
|
+
catch (_a) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const renderTemplate: (source: string | Array<string>, destination: string, options?: any) => (context: any) => void;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import glob from 'fast-glob';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import handlebars from 'handlebars';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
export const renderTemplate = (source, destination, options) => (context) => {
|
|
6
|
+
const files = glob.sync(source, options);
|
|
7
|
+
for (const file of files) {
|
|
8
|
+
const from = path.resolve((options === null || options === void 0 ? void 0 : options.cwd) || '', file);
|
|
9
|
+
const to = path.join(destination, path
|
|
10
|
+
.normalize(file)
|
|
11
|
+
.split(path.sep)
|
|
12
|
+
.slice(1)
|
|
13
|
+
.map((section) => handlebars.compile(section)(context))
|
|
14
|
+
.join(path.sep)
|
|
15
|
+
.replace('_.', '.')
|
|
16
|
+
.replace('.hbs', ''));
|
|
17
|
+
const directory = path.dirname(to);
|
|
18
|
+
const raw = fs.readFileSync(from, 'utf8');
|
|
19
|
+
const template = handlebars.compile(raw)(context);
|
|
20
|
+
if (!fs.existsSync(directory)) {
|
|
21
|
+
fs.mkdirSync(directory, { recursive: true });
|
|
22
|
+
}
|
|
23
|
+
fs.writeFileSync(to, template, 'utf8');
|
|
24
|
+
}
|
|
25
|
+
};
|
package/dist/types/context.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { ClassBody, ClassDeclaration, ClassMethod, ClassProperty, File } from '@babel/types';
|
|
2
2
|
export interface Context {
|
|
3
3
|
script?: string;
|
|
4
|
+
componentClassName?: string;
|
|
5
|
+
componentInterfaceName?: string;
|
|
4
6
|
componentKey?: string;
|
|
5
7
|
componentTag?: string;
|
|
6
8
|
directoryName?: string;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
export * from './api.js';
|
|
2
1
|
export * from './context.js';
|
|
3
|
-
export * from './direction.js';
|
|
4
|
-
export * from './event-options.js';
|
|
5
|
-
export * from './listen-options.js';
|
|
6
2
|
export * from './plugin.js';
|
|
7
3
|
export * from './plus-element.js';
|
|
8
|
-
export * from './property-options.js';
|
package/dist/types/index.js
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
export * from './api.js';
|
|
2
1
|
export * from './context.js';
|
|
3
|
-
export * from './direction.js';
|
|
4
|
-
export * from './event-options.js';
|
|
5
|
-
export * from './listen-options.js';
|
|
6
2
|
export * from './plugin.js';
|
|
7
3
|
export * from './plus-element.js';
|
|
8
|
-
export * from './property-options.js';
|
package/dist/types/plugin.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Context } from './context.js';
|
|
2
|
+
export declare type Return<T> = void | T | Promise<T>;
|
|
2
3
|
export declare type Plugin = {
|
|
3
4
|
name: string;
|
|
4
|
-
start?: (global: any) =>
|
|
5
|
-
next?: (context: Context, global: any) =>
|
|
6
|
-
finish?: (global: any) =>
|
|
5
|
+
start?: (global: any) => Return<any>;
|
|
6
|
+
next?: (context: Context, global: any) => Return<Context>;
|
|
7
|
+
finish?: (global: any) => Return<any>;
|
|
7
8
|
};
|
package/package.json
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@htmlplus/element",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Masood Abdolian <m.abdolian@gmail.com>",
|
|
6
6
|
"description": "Compiler of HTMLPlus",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"scripts": {
|
|
9
|
-
"build": "
|
|
9
|
+
"build": "tsc",
|
|
10
10
|
"build:watch": "tsc -w",
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"start": "node src/dev/start.js"
|
|
11
|
+
"postbuild": "node scripts/build.post.js",
|
|
12
|
+
"format": "prettier --write .",
|
|
13
|
+
"dev:start": "node src/dev/start.js",
|
|
14
|
+
"dev:build": "node src/dev/build.js"
|
|
14
15
|
},
|
|
15
16
|
"exports": {
|
|
16
17
|
".": {
|
|
@@ -78,6 +79,8 @@
|
|
|
78
79
|
"@babel/types": "^7.16.0",
|
|
79
80
|
"@types/node": "^16.11.11",
|
|
80
81
|
"change-case": "^4.1.2",
|
|
82
|
+
"fast-glob": "^3.2.11",
|
|
83
|
+
"handlebars": "^4.7.7",
|
|
81
84
|
"log-update": "^5.0.0",
|
|
82
85
|
"sass": "^1.43.4",
|
|
83
86
|
"ts-node": "^10.4.0",
|
|
@@ -86,8 +89,8 @@
|
|
|
86
89
|
},
|
|
87
90
|
"devDependencies": {
|
|
88
91
|
"@trivago/prettier-plugin-sort-imports": "^3.1.1",
|
|
92
|
+
"cpy": "^9.0.0",
|
|
89
93
|
"prettier": "^2.5.0",
|
|
90
|
-
"rimraf": "^3.0.2",
|
|
91
94
|
"vite": "^2.7.10"
|
|
92
95
|
}
|
|
93
96
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { isServer } from '../utils/index.js';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { isServer } from '../utils/index.js';
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export declare type DecoratorSetup = (target: Object, propertyKey: PropertyKey, descriptor?: PropertyDescriptor) => DecoratorSetupReturn;
|
|
2
|
-
export declare type DecoratorSetupReturn = PropertyDescriptor & {
|
|
3
|
-
onReady?(): void;
|
|
4
|
-
};
|
|
5
|
-
export declare const decorator: (setup: DecoratorSetup) => (target: Object, propertyKey: PropertyKey, descriptor?: PropertyDescriptor | undefined) => DecoratorSetupReturn | undefined;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { defineProperty } from './define-property.js';
|
|
2
|
-
export const decorator = (setup) => {
|
|
3
|
-
return function (target, propertyKey, descriptor) {
|
|
4
|
-
var _a;
|
|
5
|
-
const options = setup(target, propertyKey, descriptor);
|
|
6
|
-
// TODO
|
|
7
|
-
if (options.onReady)
|
|
8
|
-
((_a = target['setup']) !== null && _a !== void 0 ? _a : (target['setup'] = [])).push(options.onReady);
|
|
9
|
-
if (descriptor)
|
|
10
|
-
return options;
|
|
11
|
-
if (Object.keys(options).some((key) => ['configurable', 'enumerable', 'value', 'writable', 'get', 'set'].includes(key)))
|
|
12
|
-
defineProperty(target, propertyKey, options);
|
|
13
|
-
};
|
|
14
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const defineElement: (name: string, Class: any) => void;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const defineMethod: <T>(target: T, propertyKey: PropertyKey, handler: any) => void;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
// TODO: handler type
|
|
2
|
-
export const defineMethod = (target, propertyKey, handler) => {
|
|
3
|
-
const callback = target[propertyKey];
|
|
4
|
-
target[propertyKey] = function (...args) {
|
|
5
|
-
return handler(this, callback === null || callback === void 0 ? void 0 : callback.bind(this), args);
|
|
6
|
-
};
|
|
7
|
-
};
|
package/dist/types/api.d.ts
DELETED
package/dist/types/api.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare type Direction = 'ltr' | 'rtl';
|
package/dist/types/direction.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export interface EventOptions {
|
|
2
|
-
/**
|
|
3
|
-
* A string custom event name to override the default.
|
|
4
|
-
*/
|
|
5
|
-
name?: string;
|
|
6
|
-
/**
|
|
7
|
-
* A Boolean indicating whether the event bubbles up through the DOM or not. default is `false`.
|
|
8
|
-
*/
|
|
9
|
-
bubbles?: boolean;
|
|
10
|
-
/**
|
|
11
|
-
* A Boolean indicating whether the event is cancelable. default is `false`.
|
|
12
|
-
*/
|
|
13
|
-
cancelable?: boolean;
|
|
14
|
-
/**
|
|
15
|
-
* 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.
|
|
16
|
-
*/
|
|
17
|
-
composed?: boolean;
|
|
18
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|