@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,278 +0,0 @@
|
|
|
1
|
-
/**************************************************
|
|
2
|
-
* THIS FILE IS AUTO-GENERATED, DO NOT EDIT MANUALY
|
|
3
|
-
**************************************************/
|
|
4
|
-
|
|
5
|
-
import { camelCase, paramCase, pascalCase } from 'change-case';
|
|
6
|
-
import React from 'react';
|
|
7
|
-
|
|
8
|
-
type EventHandlerType = (event: Event) => any;
|
|
9
|
-
|
|
10
|
-
type FinalPropsType<ElementType> = Omit<PropsType<ElementType>, 'forwardedRef'>;
|
|
11
|
-
|
|
12
|
-
type Mutable<T> = { -readonly [P in keyof T]-?: T[P] };
|
|
13
|
-
|
|
14
|
-
interface ExtraType {
|
|
15
|
-
props?: Array<string>;
|
|
16
|
-
events?: Array<string>;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
interface PropsType<ElementType> extends React.HTMLAttributes<ElementType> {
|
|
20
|
-
forwardedRef: React.RefObject<ElementType>;
|
|
21
|
-
ref?: React.Ref<any>;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface StyleReactProps {
|
|
25
|
-
class?: string;
|
|
26
|
-
className?: string;
|
|
27
|
-
style?: {
|
|
28
|
-
[key: string]: any;
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const arrayToMap = (array: string[] | DOMTokenList) => {
|
|
33
|
-
const map = new Map<string, string>();
|
|
34
|
-
|
|
35
|
-
(array as string[]).forEach((s: string) => map.set(s, s));
|
|
36
|
-
|
|
37
|
-
return map;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const getCustomEvent = (name: string, events: Array<string>) => {
|
|
41
|
-
// TODO
|
|
42
|
-
name = camelCase(name.slice(3));
|
|
43
|
-
|
|
44
|
-
const event = events.find((event) => event.endsWith(name));
|
|
45
|
-
|
|
46
|
-
if (!event) return;
|
|
47
|
-
|
|
48
|
-
return event;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const forwardRef = <ElementType, PropType>(ReactComponent: any) => {
|
|
52
|
-
const forwardRef = (
|
|
53
|
-
props: PropType & Omit<React.HTMLAttributes<ElementType>, 'style'> & StyleReactProps,
|
|
54
|
-
ref: React.Ref<ElementType>
|
|
55
|
-
) => {
|
|
56
|
-
const { children, ...remainedProps } = props;
|
|
57
|
-
|
|
58
|
-
const newProps = {
|
|
59
|
-
...remainedProps,
|
|
60
|
-
forwardedRef: ref
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
return React.createElement(ReactComponent, newProps, children);
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
forwardRef.displayName = ReactComponent.displayName;
|
|
67
|
-
|
|
68
|
-
return React.forwardRef(forwardRef);
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
const isEvent = (name: string) => {
|
|
72
|
-
return name.indexOf('on') === 0 && name[2] === name[2].toUpperCase();
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
const isPrimitive = (value: any) => {
|
|
76
|
-
const type = typeof value;
|
|
77
|
-
|
|
78
|
-
const match = type.match(/boolean|string|number/);
|
|
79
|
-
|
|
80
|
-
return match;
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const getProps = <ElementType>(ref: React.Ref<ElementType>, props: PropsType<ElementType>, extra: ExtraType) => {
|
|
84
|
-
const { forwardedRef } = props;
|
|
85
|
-
|
|
86
|
-
const result: FinalPropsType<ElementType> = {
|
|
87
|
-
ref: mergeRefs(forwardedRef, ref)
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
Object.keys(props).forEach((name) => {
|
|
91
|
-
if (name === 'children' || name === 'className' || name === 'forwardedRef' || name === 'ref') return;
|
|
92
|
-
|
|
93
|
-
const value = props[name];
|
|
94
|
-
|
|
95
|
-
if (isEvent(name)) {
|
|
96
|
-
if (typeof document === 'undefined') return;
|
|
97
|
-
|
|
98
|
-
const event = getCustomEvent(name, extra.events);
|
|
99
|
-
|
|
100
|
-
if (event) return;
|
|
101
|
-
|
|
102
|
-
result[name] = value;
|
|
103
|
-
} else if (extra.props.includes(name)) {
|
|
104
|
-
if (!isPrimitive(value)) return;
|
|
105
|
-
|
|
106
|
-
result[paramCase(name)] = value;
|
|
107
|
-
} else {
|
|
108
|
-
result[name] = value;
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
return result;
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
const mergeRefs =
|
|
116
|
-
<ElementType>(...refs: React.Ref<ElementType>[]) =>
|
|
117
|
-
(value: ElementType) => {
|
|
118
|
-
return refs.forEach((ref) => {
|
|
119
|
-
if (typeof ref === 'function') return ref(value);
|
|
120
|
-
|
|
121
|
-
if (ref == null) return;
|
|
122
|
-
|
|
123
|
-
(ref as Mutable<React.RefObject<ElementType>>).current = value;
|
|
124
|
-
});
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
const setClass = <ElementType>(element: ElementType, props: PropsType<ElementType>) => {
|
|
128
|
-
const classes: string[] = [];
|
|
129
|
-
|
|
130
|
-
const current = arrayToMap((element as any).classList);
|
|
131
|
-
|
|
132
|
-
const prev: string = element['$class'];
|
|
133
|
-
const next: string = props.className || (props as any).class;
|
|
134
|
-
|
|
135
|
-
const prevClass = arrayToMap(prev ? prev.split(' ') : []);
|
|
136
|
-
const nextClass = arrayToMap(next ? next.split(' ') : []);
|
|
137
|
-
|
|
138
|
-
current.forEach((key) => {
|
|
139
|
-
if (nextClass.has(key)) {
|
|
140
|
-
classes.push(key);
|
|
141
|
-
|
|
142
|
-
nextClass.delete(key);
|
|
143
|
-
} else if (!prevClass.has(key)) {
|
|
144
|
-
classes.push(key);
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
nextClass.forEach((key) => classes.push(key));
|
|
149
|
-
|
|
150
|
-
const className = classes.join(' ');
|
|
151
|
-
|
|
152
|
-
(element as any).className = className;
|
|
153
|
-
|
|
154
|
-
element['$class'] = className;
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
const setEvent = (element: Element, name: string, handler: EventHandlerType) => {
|
|
158
|
-
const events = element['$events'] || (element['$events'] = {});
|
|
159
|
-
|
|
160
|
-
const previous = events[name];
|
|
161
|
-
|
|
162
|
-
previous && element.removeEventListener(name, previous);
|
|
163
|
-
|
|
164
|
-
function callback(event: Event) {
|
|
165
|
-
handler && handler.call(this, event);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
element.addEventListener(name, (events[name] = callback));
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
const setProps = <ElementType>(element: ElementType, props: PropsType<ElementType>, extra: ExtraType) => {
|
|
172
|
-
if (!(element instanceof Element)) return;
|
|
173
|
-
|
|
174
|
-
setClass<ElementType>(element, props);
|
|
175
|
-
|
|
176
|
-
Object.keys(props).forEach((name) => {
|
|
177
|
-
if (
|
|
178
|
-
name === 'children' ||
|
|
179
|
-
name === 'class' ||
|
|
180
|
-
name === 'className' ||
|
|
181
|
-
name === 'forwardedRef' ||
|
|
182
|
-
name === 'ref' ||
|
|
183
|
-
name === 'style'
|
|
184
|
-
)
|
|
185
|
-
return;
|
|
186
|
-
|
|
187
|
-
const value = props[name];
|
|
188
|
-
|
|
189
|
-
if (isEvent(name)) {
|
|
190
|
-
if (typeof document === 'undefined') return;
|
|
191
|
-
|
|
192
|
-
const event = getCustomEvent(name, extra.events);
|
|
193
|
-
|
|
194
|
-
if (!event) return;
|
|
195
|
-
|
|
196
|
-
setEvent(element, event, value);
|
|
197
|
-
} else if (extra.props.includes(name)) {
|
|
198
|
-
if (isPrimitive(value)) {
|
|
199
|
-
element.setAttribute(paramCase(name), value);
|
|
200
|
-
} else {
|
|
201
|
-
element[name] = value;
|
|
202
|
-
}
|
|
203
|
-
} else {
|
|
204
|
-
element[name] = value;
|
|
205
|
-
}
|
|
206
|
-
});
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
export const proxy = <ElementType, PropType>(
|
|
210
|
-
tagName: string,
|
|
211
|
-
props: Array<string> = [],
|
|
212
|
-
events: Array<string> = []
|
|
213
|
-
) => {
|
|
214
|
-
const extra: ExtraType = {
|
|
215
|
-
props,
|
|
216
|
-
events
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
const ReactComponent = class extends React.Component<PropsType<ElementType>> {
|
|
220
|
-
element!: ElementType;
|
|
221
|
-
|
|
222
|
-
setElement = (element: ElementType) => {
|
|
223
|
-
this.element = element;
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
constructor(props: PropsType<ElementType>) {
|
|
227
|
-
super(props);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
componentDidMount() {
|
|
231
|
-
this.componentDidUpdate(/*this.props*/);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
componentDidUpdate(/*prevProps: InternalProps<ElementType>*/) {
|
|
235
|
-
setProps<ElementType>(this.element as any, this.props, extra);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
componentWillUnmount() {
|
|
239
|
-
if (!this.element) return;
|
|
240
|
-
|
|
241
|
-
const events = this.element['$events'] || {};
|
|
242
|
-
|
|
243
|
-
Object.keys(events).forEach((name) => {
|
|
244
|
-
const handler = events[name];
|
|
245
|
-
|
|
246
|
-
(this.element as any).removeEventListener(name, handler);
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
delete this.element['$events'];
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
render() {
|
|
253
|
-
const { children } = this.props;
|
|
254
|
-
|
|
255
|
-
const props = getProps<ElementType>(this.setElement, this.props, extra);
|
|
256
|
-
|
|
257
|
-
return React.createElement(tagName, props, children);
|
|
258
|
-
}
|
|
259
|
-
};
|
|
260
|
-
|
|
261
|
-
// TODO
|
|
262
|
-
// const ReactComponentNew = (props: InternalPropsType<ElementType>) => {
|
|
263
|
-
|
|
264
|
-
// const { children } = props;
|
|
265
|
-
|
|
266
|
-
// const ref = useRef(null);
|
|
267
|
-
|
|
268
|
-
// const newProps: FinalPropsType<ElementType> = getProps(ref, props, events);
|
|
269
|
-
|
|
270
|
-
// useEffect(() => setProps(ref.current, props, events));
|
|
271
|
-
|
|
272
|
-
// return React.createElement(tagName, newProps, children);
|
|
273
|
-
// }
|
|
274
|
-
|
|
275
|
-
ReactComponent['displayName'] = pascalCase(tagName);
|
|
276
|
-
|
|
277
|
-
return forwardRef<ElementType, PropType>(ReactComponent);
|
|
278
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Context } from '../../types/index.js';
|
|
2
|
-
export interface DocsOptions {
|
|
3
|
-
dist: string;
|
|
4
|
-
prefix: string;
|
|
5
|
-
}
|
|
6
|
-
export declare const docs: (options: DocsOptions) => {
|
|
7
|
-
name: string;
|
|
8
|
-
start: (global: any) => void;
|
|
9
|
-
next: (context: Context, global: any) => void;
|
|
10
|
-
finish: (global: any) => void;
|
|
11
|
-
};
|
|
@@ -1,320 +0,0 @@
|
|
|
1
|
-
import { capitalCase, paramCase } from 'change-case';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
// import glob from 'glob';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
import { getInitializer, getTags, getType, printType } from '../utils/index.js';
|
|
6
|
-
export const docs = (options) => {
|
|
7
|
-
const name = 'docs';
|
|
8
|
-
const start = (global) => {
|
|
9
|
-
global.docs = {
|
|
10
|
-
prefix: options.prefix,
|
|
11
|
-
components: []
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
const next = (context, global) => {
|
|
15
|
-
var _a;
|
|
16
|
-
const tags = getTags(context.class);
|
|
17
|
-
const development = tags.some((tag) => tag.key == 'development');
|
|
18
|
-
const experimental = tags.some((tag) => tag.key == 'experimental');
|
|
19
|
-
const externals = fs.existsSync(path.resolve(context.directoryPath || '', 'externals'));
|
|
20
|
-
const examples = (() => {
|
|
21
|
-
const items = [];
|
|
22
|
-
const source = path.join(context.directoryPath || '', 'examples');
|
|
23
|
-
if (!fs.existsSync(source))
|
|
24
|
-
return items;
|
|
25
|
-
return fs
|
|
26
|
-
.readdirSync(source)
|
|
27
|
-
.filter((file) => file.endsWith('.md'))
|
|
28
|
-
.map((file) => {
|
|
29
|
-
const item = {};
|
|
30
|
-
const regex = /```\w+\s\[\w+(:\w+)?\]\s[\S\s]*?```/g;
|
|
31
|
-
const filePath = path.join(source, file);
|
|
32
|
-
const content = fs.readFileSync(filePath, 'utf8');
|
|
33
|
-
item.key = path.basename(filePath).replace('.md', '');
|
|
34
|
-
item.title = capitalCase(item.key);
|
|
35
|
-
item.readme = content.replace(regex, '').trim();
|
|
36
|
-
item.codes = (content.match(regex) || []).map((section) => {
|
|
37
|
-
try {
|
|
38
|
-
const lines = section.split('\n');
|
|
39
|
-
const key = ((lines[0].match(/\[\w+(:\w+)?\]/) || []).shift() || '').replace('[', '').replace(']', '');
|
|
40
|
-
const type = ((lines[0].match(/```\w+/) || []).pop() || '').replace('```', '');
|
|
41
|
-
const value = lines.slice(1, -1).join('\n');
|
|
42
|
-
return {
|
|
43
|
-
key,
|
|
44
|
-
type,
|
|
45
|
-
value
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
catch (_a) { }
|
|
49
|
-
});
|
|
50
|
-
return item;
|
|
51
|
-
});
|
|
52
|
-
})();
|
|
53
|
-
const readme = (() => {
|
|
54
|
-
try {
|
|
55
|
-
const source = path.resolve(context.directoryPath || '', `${context.fileName}.md`);
|
|
56
|
-
return fs.readFileSync(source, 'utf8');
|
|
57
|
-
}
|
|
58
|
-
catch (_a) { }
|
|
59
|
-
})();
|
|
60
|
-
const description = (() => {
|
|
61
|
-
const content = readme || '';
|
|
62
|
-
if (!content.startsWith('# '))
|
|
63
|
-
return '';
|
|
64
|
-
const sections = content.split('\n');
|
|
65
|
-
for (let i = 1; i < sections.length; i++) {
|
|
66
|
-
const section = sections[i].trim();
|
|
67
|
-
if (!section)
|
|
68
|
-
continue;
|
|
69
|
-
return section;
|
|
70
|
-
}
|
|
71
|
-
return '';
|
|
72
|
-
})();
|
|
73
|
-
const properties = (context.classProperties || []).map((property) => {
|
|
74
|
-
var _a;
|
|
75
|
-
const tags = getTags(property);
|
|
76
|
-
const name = property.key['name'];
|
|
77
|
-
const attribute = paramCase(name);
|
|
78
|
-
// TODO
|
|
79
|
-
const initializer = getInitializer(property.value);
|
|
80
|
-
// TODO
|
|
81
|
-
const reflect = (() => {
|
|
82
|
-
if (!property.decorators)
|
|
83
|
-
return false;
|
|
84
|
-
try {
|
|
85
|
-
for (const decorator of property.decorators) {
|
|
86
|
-
for (const argument of decorator.expression['arguments']) {
|
|
87
|
-
for (const property of argument.properties) {
|
|
88
|
-
if (property.key.name != 'reflect')
|
|
89
|
-
continue;
|
|
90
|
-
if (property.value.type != 'BooleanLiteral')
|
|
91
|
-
continue;
|
|
92
|
-
if (!property.value.value)
|
|
93
|
-
continue;
|
|
94
|
-
return true;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
catch (_a) { }
|
|
100
|
-
return false;
|
|
101
|
-
})();
|
|
102
|
-
const required = !property.optional;
|
|
103
|
-
// TODO
|
|
104
|
-
const { type, members } = (() => {
|
|
105
|
-
const ast = getType(context.fileAST, (property.typeAnnotation || {})['typeAnnotation'], {
|
|
106
|
-
directory: context.directoryPath
|
|
107
|
-
});
|
|
108
|
-
return printType(ast);
|
|
109
|
-
})();
|
|
110
|
-
const experimental = tags.some((tag) => tag.key == 'experimental');
|
|
111
|
-
const description = (_a = tags.find((tag) => !tag.key)) === null || _a === void 0 ? void 0 : _a.value;
|
|
112
|
-
const model = tags.some((tag) => tag.key == 'model');
|
|
113
|
-
return {
|
|
114
|
-
name,
|
|
115
|
-
attribute,
|
|
116
|
-
initializer,
|
|
117
|
-
reflect,
|
|
118
|
-
required,
|
|
119
|
-
type,
|
|
120
|
-
experimental,
|
|
121
|
-
description,
|
|
122
|
-
members,
|
|
123
|
-
model
|
|
124
|
-
};
|
|
125
|
-
});
|
|
126
|
-
const parts = tags
|
|
127
|
-
.filter((tag) => tag.key == 'part')
|
|
128
|
-
.map((tag) => {
|
|
129
|
-
var _a;
|
|
130
|
-
const sections = ((_a = tag.value) === null || _a === void 0 ? void 0 : _a.split('-')) || [];
|
|
131
|
-
const name = sections[0].trim();
|
|
132
|
-
const description = sections.slice(1).join('-').trim();
|
|
133
|
-
return {
|
|
134
|
-
name,
|
|
135
|
-
description
|
|
136
|
-
};
|
|
137
|
-
});
|
|
138
|
-
const methods = (context.classMethods || []).map((method) => {
|
|
139
|
-
var _a;
|
|
140
|
-
const tags = getTags(method);
|
|
141
|
-
const name = method.key['name'];
|
|
142
|
-
const experimental = tags.some((tag) => tag.key == 'experimental');
|
|
143
|
-
// TODO
|
|
144
|
-
// const params = printType(getType(
|
|
145
|
-
// context.ast,
|
|
146
|
-
// method.params,
|
|
147
|
-
// {
|
|
148
|
-
// directory: context.directory,
|
|
149
|
-
// }
|
|
150
|
-
// ));
|
|
151
|
-
// console.log(111, params)
|
|
152
|
-
// TODO: returnType
|
|
153
|
-
const type = (() => {
|
|
154
|
-
try {
|
|
155
|
-
return printType(getType(context.fileAST, (method.returnType || {})['typeAnnotation'], {
|
|
156
|
-
directory: context.directoryPath
|
|
157
|
-
}));
|
|
158
|
-
}
|
|
159
|
-
catch (_a) { }
|
|
160
|
-
})();
|
|
161
|
-
// TODO
|
|
162
|
-
const signature = `${method.key['name']}(${''}) => ${type}`;
|
|
163
|
-
const description = (_a = tags.find((tag) => !tag.key)) === null || _a === void 0 ? void 0 : _a.value;
|
|
164
|
-
// TODO
|
|
165
|
-
const parameters = [
|
|
166
|
-
// {
|
|
167
|
-
// "name": "offsetX",
|
|
168
|
-
// "description": "Moving size (px) in the `horizontal` direction. Use `null` to ignore this."
|
|
169
|
-
// },
|
|
170
|
-
// {
|
|
171
|
-
// "name": "offsetY",
|
|
172
|
-
// "description": "Moving size (px) in the `vertical` direction. Use `null` to ignore this."
|
|
173
|
-
// }
|
|
174
|
-
];
|
|
175
|
-
return {
|
|
176
|
-
name,
|
|
177
|
-
experimental,
|
|
178
|
-
type,
|
|
179
|
-
signature,
|
|
180
|
-
description,
|
|
181
|
-
parameters
|
|
182
|
-
};
|
|
183
|
-
});
|
|
184
|
-
const slots = tags
|
|
185
|
-
.filter((tag) => tag.key == 'slot')
|
|
186
|
-
.map((tag) => {
|
|
187
|
-
var _a;
|
|
188
|
-
const sections = ((_a = tag.value) === null || _a === void 0 ? void 0 : _a.split('-')) || [];
|
|
189
|
-
const name = sections[0].trim();
|
|
190
|
-
const description = sections.slice(1).join('-').trim();
|
|
191
|
-
return {
|
|
192
|
-
name,
|
|
193
|
-
description
|
|
194
|
-
};
|
|
195
|
-
});
|
|
196
|
-
const events = (context.classEvents || []).map((event) => {
|
|
197
|
-
var _a;
|
|
198
|
-
const tags = getTags(event);
|
|
199
|
-
const name = event.key['name'];
|
|
200
|
-
const cancelable = (() => {
|
|
201
|
-
if (!event.decorators)
|
|
202
|
-
return false;
|
|
203
|
-
try {
|
|
204
|
-
for (const decorator of event.decorators) {
|
|
205
|
-
for (const argument of decorator.expression['arguments']) {
|
|
206
|
-
for (const property of argument.properties) {
|
|
207
|
-
if (property.key.name != 'cancelable')
|
|
208
|
-
continue;
|
|
209
|
-
if (property.value.type != 'BooleanLiteral')
|
|
210
|
-
continue;
|
|
211
|
-
if (!property.value.value)
|
|
212
|
-
continue;
|
|
213
|
-
return true;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
catch (_a) { }
|
|
219
|
-
return false;
|
|
220
|
-
})();
|
|
221
|
-
// TODO
|
|
222
|
-
const detail = (() => {
|
|
223
|
-
try {
|
|
224
|
-
return printType(getType(context.fileAST, (event.typeAnnotation || {})['typeAnnotation'].typeParameters.params[0], {
|
|
225
|
-
directory: context.directoryPath
|
|
226
|
-
}));
|
|
227
|
-
}
|
|
228
|
-
catch (_a) { }
|
|
229
|
-
})();
|
|
230
|
-
const experimental = tags.some((tag) => tag.key == 'experimental');
|
|
231
|
-
const description = (_a = tags.find((tag) => !tag.key)) === null || _a === void 0 ? void 0 : _a.value;
|
|
232
|
-
const model = tags.some((tag) => tag.key == 'model');
|
|
233
|
-
return {
|
|
234
|
-
name,
|
|
235
|
-
cancelable,
|
|
236
|
-
detail,
|
|
237
|
-
experimental,
|
|
238
|
-
description,
|
|
239
|
-
model
|
|
240
|
-
};
|
|
241
|
-
});
|
|
242
|
-
const styles = (() => {
|
|
243
|
-
const styles = [];
|
|
244
|
-
try {
|
|
245
|
-
fs.readFileSync(context.stylePath || '', 'utf8')
|
|
246
|
-
.split('@prop')
|
|
247
|
-
.slice(1)
|
|
248
|
-
.map((section) => {
|
|
249
|
-
var _a;
|
|
250
|
-
let [description, name] = section.split(/\n/);
|
|
251
|
-
name = name.split(':').slice(0, -1).join(':').trim();
|
|
252
|
-
description = description.trim();
|
|
253
|
-
let [initializer] = ((_a = context.styleParsed) === null || _a === void 0 ? void 0 : _a.split(name).slice(1, 2)) || [];
|
|
254
|
-
if (initializer)
|
|
255
|
-
initializer = initializer.split(/;|}/)[0].replace(':', '').trim();
|
|
256
|
-
styles.push({
|
|
257
|
-
name,
|
|
258
|
-
initializer,
|
|
259
|
-
description
|
|
260
|
-
});
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
catch (_a) { }
|
|
264
|
-
return styles;
|
|
265
|
-
})();
|
|
266
|
-
// TODO
|
|
267
|
-
const lastModified = 0;
|
|
268
|
-
// glob
|
|
269
|
-
// .sync(path.join(context.directory, '**/*.*'))
|
|
270
|
-
// .reduce((result, file) => {
|
|
271
|
-
// const state = fs.statSync(file);
|
|
272
|
-
// return result > state.mtime ? result : state.mtime
|
|
273
|
-
// }, 0);
|
|
274
|
-
const group = ((_a = tags.find((tag) => tag.key == 'group')) === null || _a === void 0 ? void 0 : _a.value) || null;
|
|
275
|
-
const main = (group && context.componentKey == group) || !group;
|
|
276
|
-
// TODO
|
|
277
|
-
// context.types = (() => {
|
|
278
|
-
// return [];
|
|
279
|
-
// })();
|
|
280
|
-
global.docs.components.push({
|
|
281
|
-
key: context.componentKey,
|
|
282
|
-
tag: context.componentTag,
|
|
283
|
-
title: capitalCase(context.componentKey || ''),
|
|
284
|
-
main,
|
|
285
|
-
group,
|
|
286
|
-
development,
|
|
287
|
-
experimental,
|
|
288
|
-
// TODO
|
|
289
|
-
deprecated: false,
|
|
290
|
-
externals,
|
|
291
|
-
lastModified,
|
|
292
|
-
// TODO
|
|
293
|
-
tags: [],
|
|
294
|
-
// TODO
|
|
295
|
-
source: context.componentKey,
|
|
296
|
-
description,
|
|
297
|
-
readme,
|
|
298
|
-
properties,
|
|
299
|
-
slots,
|
|
300
|
-
events,
|
|
301
|
-
styles,
|
|
302
|
-
parts,
|
|
303
|
-
methods,
|
|
304
|
-
examples
|
|
305
|
-
});
|
|
306
|
-
};
|
|
307
|
-
const finish = (global) => {
|
|
308
|
-
global.docs.components = global.docs.components.sort((a, b) => (a.key > b.key ? 1 : -1));
|
|
309
|
-
// TODO
|
|
310
|
-
// fs.ensureDirSync(path.dirname(options.dist));
|
|
311
|
-
// TODO
|
|
312
|
-
// fs.writeJSONSync(options.dist, global.docs, { replacer: null, spaces: 2 });
|
|
313
|
-
};
|
|
314
|
-
return {
|
|
315
|
-
name,
|
|
316
|
-
start,
|
|
317
|
-
next,
|
|
318
|
-
finish
|
|
319
|
-
};
|
|
320
|
-
};
|