apprun 3.33.7 → 3.33.8
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/apprun-cli.js +96 -13
- package/apprun.d.ts +1 -0
- package/cli/colors.js +69 -0
- package/dist/apprun-dev-tools.js +1 -1
- package/dist/apprun-dev-tools.js.map +1 -1
- package/dist/apprun-html.esm.js +4 -5
- package/dist/apprun-html.esm.js.map +1 -1
- package/dist/apprun-html.js +1 -1
- package/dist/apprun-html.js.map +1 -1
- package/dist/apprun-play-html.esm.js +4 -5
- package/dist/apprun-play-html.esm.js.map +1 -1
- package/dist/apprun-play.js +1 -1
- package/dist/apprun-play.js.map +1 -1
- package/dist/apprun.esm.js +1 -1
- package/dist/apprun.esm.js.map +1 -1
- package/dist/apprun.js +1 -1
- package/dist/apprun.js.map +1 -1
- package/esm/apprun.js +56 -54
- package/esm/apprun.js.map +1 -1
- package/package.json +3 -2
- package/react.js +15 -0
- package/src/apprun.ts +59 -56
package/src/apprun.ts
CHANGED
|
@@ -6,6 +6,13 @@ import { on, update, customElement } from './decorator';
|
|
|
6
6
|
import webComponent, { CustomElementOptions } from './web-component';
|
|
7
7
|
import { Route, route, ROUTER_EVENT, ROUTER_404_EVENT } from './router';
|
|
8
8
|
|
|
9
|
+
export type StatelessComponent<T = {}> = (args: T) => string | VNode | void;
|
|
10
|
+
export { App, app, Component, View, Action, Update, on, update, EventOptions, ActionOptions, MountOptions, Fragment, safeHTML }
|
|
11
|
+
export { update as event };
|
|
12
|
+
export { ROUTER_EVENT, ROUTER_404_EVENT };
|
|
13
|
+
export { customElement, CustomElementOptions, AppStartOptions };
|
|
14
|
+
export default app as IApp;
|
|
15
|
+
|
|
9
16
|
export interface IApp {
|
|
10
17
|
start<T, E = any>(element?: Element | string, model?: T, view?: View<T>, update?: Update<T, E>,
|
|
11
18
|
options?: AppStartOptions<T>): Component<T, E>;
|
|
@@ -24,68 +31,64 @@ export interface IApp {
|
|
|
24
31
|
use_react(createRoot);
|
|
25
32
|
}
|
|
26
33
|
|
|
27
|
-
|
|
28
|
-
app.
|
|
29
|
-
app.
|
|
30
|
-
app.
|
|
31
|
-
app.
|
|
34
|
+
if (!app.start) {
|
|
35
|
+
app.h = app.createElement = createElement;
|
|
36
|
+
app.render = render;
|
|
37
|
+
app.Fragment = Fragment;
|
|
38
|
+
app.webComponent = webComponent;
|
|
39
|
+
app.safeHTML = safeHTML;
|
|
32
40
|
|
|
33
|
-
app.start = <T, E = any>(element?: Element | string, model?: T, view?: View<T>, update?: Update<T, E>,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
};
|
|
41
|
+
app.start = <T, E = any>(element?: Element | string, model?: T, view?: View<T>, update?: Update<T, E>,
|
|
42
|
+
options?: AppStartOptions<T>): Component<T, E> => {
|
|
43
|
+
const opts = { render: true, global_event: true, ...options };
|
|
44
|
+
const component = new Component<T, E>(model, view, update);
|
|
45
|
+
if (options && options.rendered) component.rendered = options.rendered;
|
|
46
|
+
if (options && options.mounted) component.mounted = options.mounted;
|
|
47
|
+
component.start(element, opts);
|
|
48
|
+
return component;
|
|
49
|
+
};
|
|
42
50
|
|
|
43
|
-
const NOOP = _ => {/* Intentionally empty */ }
|
|
44
|
-
app.on('$', NOOP);
|
|
45
|
-
app.on('debug', _ => NOOP);
|
|
46
|
-
app.on(ROUTER_EVENT, NOOP);
|
|
47
|
-
app.on('#', NOOP);
|
|
48
|
-
app['route'] = route;
|
|
49
|
-
app.on('route', url => app['route'] && app['route'](url));
|
|
51
|
+
const NOOP = _ => {/* Intentionally empty */ }
|
|
52
|
+
app.on('$', NOOP);
|
|
53
|
+
app.on('debug', _ => NOOP);
|
|
54
|
+
app.on(ROUTER_EVENT, NOOP);
|
|
55
|
+
app.on('#', NOOP);
|
|
56
|
+
app['route'] = route;
|
|
57
|
+
app.on('route', url => app['route'] && app['route'](url));
|
|
50
58
|
|
|
51
|
-
if (typeof document === 'object') {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
export type StatelessComponent<T = {}> = (args: T) => string | VNode | void;
|
|
60
|
-
export { App, app, Component, View, Action, Update, on, update, EventOptions, ActionOptions, MountOptions, Fragment, safeHTML }
|
|
61
|
-
export { update as event };
|
|
62
|
-
export { ROUTER_EVENT, ROUTER_404_EVENT };
|
|
63
|
-
export { customElement, CustomElementOptions, AppStartOptions };
|
|
64
|
-
export default app as IApp;
|
|
59
|
+
if (typeof document === 'object') {
|
|
60
|
+
document.addEventListener("DOMContentLoaded", () => {
|
|
61
|
+
if (app['route'] === route) {
|
|
62
|
+
window.onpopstate = () => route(location.hash);
|
|
63
|
+
document.body.hasAttribute('apprun-no-init') || app['no-init-route'] || route(location.hash);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
65
67
|
|
|
66
|
-
if (typeof window === 'object') {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
68
|
+
if (typeof window === 'object') {
|
|
69
|
+
window['Component'] = Component;
|
|
70
|
+
window['_React'] = window['React'];
|
|
71
|
+
window['React'] = app;
|
|
72
|
+
window['on'] = on;
|
|
73
|
+
window['customElement'] = customElement;
|
|
74
|
+
window['safeHTML'] = safeHTML;
|
|
75
|
+
}
|
|
74
76
|
|
|
75
|
-
app.use_render = (render, mode = 0) =>
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
app.use_render = (render, mode = 0) =>
|
|
78
|
+
mode === 0 ?
|
|
79
|
+
app.render = (el, vdom) => render(vdom, el) : // react style
|
|
80
|
+
app.render = (el, vdom) => render(el, vdom); // apprun style
|
|
79
81
|
|
|
80
|
-
app.use_react = (React, ReactDOM) => {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
82
|
+
app.use_react = (React, ReactDOM) => {
|
|
83
|
+
app.h = app.createElement = React.createElement;
|
|
84
|
+
app.Fragment = React.Fragment;
|
|
85
|
+
app.render = (el, vdom) => ReactDOM.render(vdom, el);
|
|
86
|
+
if (React.version && React.version.startsWith('18')) {
|
|
87
|
+
app.render = (el, vdom) => {
|
|
88
|
+
if (!el || !vdom) return;
|
|
89
|
+
if (!el._root) el._root = ReactDOM.createRoot(el);
|
|
90
|
+
el._root.render(vdom);
|
|
91
|
+
}
|
|
89
92
|
}
|
|
90
93
|
}
|
|
91
94
|
}
|