apprun 3.28.3 → 3.28.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/CHANGELOG.md +5 -2
- package/README.md +21 -8
- package/WHATSNEW.md +7 -5
- package/apprun-cli.js +93 -29
- package/cli-templates/_build.js +27 -0
- package/cli-templates/_eslintrc.js +40 -0
- package/cli-templates/index.html +1 -1
- package/cli-templates/spa_index.html +1 -1
- package/cli-templates/webpack.config.js +3 -2
- package/dist/apprun-dev-tools.js +1 -2
- package/dist/apprun-dev-tools.js.map +1 -1
- package/dist/apprun-html.esm.js +10 -112
- package/dist/apprun-html.esm.js.map +1 -1
- package/dist/apprun-html.js +1 -1
- package/dist/apprun-html.js.LICENSE.txt +2 -24
- package/dist/apprun-html.js.map +1 -1
- package/dist/apprun-play.js +2 -0
- package/dist/apprun-play.js.map +1 -0
- 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/error.log +0 -0
- package/esm/app.js +1 -1
- package/esm/apprun-dev-tools.js +2 -1
- package/esm/apprun-dev-tools.js.map +1 -1
- package/esm/apprun-play.js +209 -0
- package/esm/apprun-play.js.map +1 -0
- package/esm/apprun.js +1 -1
- package/esm/apprun.js.map +1 -1
- package/esm/component.js +1 -1
- package/esm/component.js.map +1 -1
- package/esm/vdom-html.js +2 -0
- package/esm/vdom-html.js.map +1 -1
- package/esm/vdom-lit-html.js +40 -21
- package/esm/vdom-lit-html.js.map +1 -1
- package/esm/vdom-to-html.js +1 -2
- package/esm/vdom-to-html.js.map +1 -1
- package/index-apprun-play.html +46 -0
- package/index.html +2 -2
- package/package.json +18 -16
- package/react.js +13 -0
- package/src/app.ts +1 -1
- package/src/apprun-play.tsx +212 -0
- package/src/apprun.ts +1 -1
- package/src/component.ts +1 -1
- package/src/vdom-html.ts_ +1 -0
- package/src/vdom-lit-html.ts +42 -20
- package/src/vdom-to-html.tsx +2 -2
- package/webpack.config.js +3 -1
- package/index-wc.html +0 -36
package/src/vdom-lit-html.ts
CHANGED
|
@@ -1,38 +1,60 @@
|
|
|
1
1
|
import { createElement, updateElement, Fragment } from './vdom-my';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import { render, svg, html, noChange, nothing } from 'lit-html';
|
|
5
|
+
import { directive, Directive, Part, PartInfo, PartType, EventPart } from 'lit-html/directive.js';
|
|
6
|
+
import { unsafeHTML } from 'lit-html/directives/unsafe-html.js';
|
|
4
7
|
|
|
5
8
|
function _render(element, vdom, parent?) {
|
|
9
|
+
if (!vdom) return;
|
|
6
10
|
if (typeof vdom === 'string') {
|
|
7
11
|
render(html`${unsafeHTML(vdom)}`, element);
|
|
8
|
-
} else if (
|
|
12
|
+
} else if ('_$litType$' in vdom) {
|
|
13
|
+
if (!element['_$litPart$']) element.replaceChildren();
|
|
9
14
|
render(vdom, element);
|
|
10
15
|
} else {
|
|
11
16
|
updateElement(element, vdom, parent);
|
|
12
|
-
|
|
17
|
+
element['_$litPart$'] = undefined;
|
|
13
18
|
}
|
|
14
19
|
}
|
|
15
20
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
21
|
+
export class RunDirective extends Directive {
|
|
22
|
+
// State stored in class field
|
|
23
|
+
value: number | undefined;
|
|
24
|
+
constructor(partInfo: PartInfo) {
|
|
25
|
+
super(partInfo);
|
|
26
|
+
// When necessary, validate part in constructor using `part.type`
|
|
27
|
+
if (partInfo.type !== PartType.EVENT) {
|
|
28
|
+
throw new Error('${run} can only be used in event handlers');
|
|
29
|
+
}
|
|
19
30
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
31
|
+
// Optional: override update to perform any direct DOM manipulation
|
|
32
|
+
update(part: Part, params) {
|
|
33
|
+
/* Any imperative updates to DOM/parts would go here */
|
|
34
|
+
|
|
35
|
+
let { element, name } = part as EventPart;
|
|
36
|
+
const getComponent = () => {
|
|
37
|
+
let component = element['_component'];
|
|
38
|
+
while (!component && element) {
|
|
39
|
+
element = element.parentElement;
|
|
40
|
+
component = element && element['_component'];
|
|
41
|
+
}
|
|
42
|
+
console.assert(!!component, 'Component not found.');
|
|
43
|
+
return component;
|
|
44
|
+
}
|
|
45
|
+
const [event, ...args] = params;
|
|
46
|
+
if (typeof event === 'string') {
|
|
47
|
+
element[`on${name}`] = e => getComponent().run(event, ...args, e);
|
|
48
|
+
} else if (typeof event === 'function') {
|
|
49
|
+
element[`on${name}`] = e => getComponent().setState(event(getComponent().state, ...args, e));
|
|
26
50
|
}
|
|
27
|
-
|
|
28
|
-
return component;
|
|
51
|
+
return this.render();
|
|
29
52
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
} else if (typeof event === 'function') {
|
|
33
|
-
element[`on${eventName}`] = e => getComponent().setState(event(getComponent().state, ...args, e));
|
|
53
|
+
render() {
|
|
54
|
+
return noChange;
|
|
34
55
|
}
|
|
35
|
-
}
|
|
56
|
+
}
|
|
36
57
|
|
|
58
|
+
const run = directive(RunDirective) as any;
|
|
37
59
|
export { createElement, Fragment, html, svg, _render as render, run };
|
|
38
60
|
|
package/src/vdom-to-html.tsx
CHANGED
package/webpack.config.js
CHANGED
|
@@ -3,6 +3,7 @@ const path = require('path');
|
|
|
3
3
|
module.exports = {
|
|
4
4
|
entry: {
|
|
5
5
|
'dist/apprun': './src/apprun.ts',
|
|
6
|
+
'dist/apprun-play': './src/apprun-play.tsx',
|
|
6
7
|
'dist/apprun-html': './src/apprun-html.ts',
|
|
7
8
|
'dist/apprun-dev-tools': './src/apprun-dev-tools.tsx',
|
|
8
9
|
'demo/app': './demo/main.ts'
|
|
@@ -23,7 +24,8 @@ module.exports = {
|
|
|
23
24
|
]
|
|
24
25
|
},
|
|
25
26
|
devServer: {
|
|
26
|
-
open: true
|
|
27
|
+
open: true,
|
|
28
|
+
static: path.join(__dirname),
|
|
27
29
|
},
|
|
28
30
|
devtool: 'source-map'
|
|
29
31
|
}
|
package/index-wc.html
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8">
|
|
5
|
-
<title>Counter web component</title>
|
|
6
|
-
<style>
|
|
7
|
-
body {
|
|
8
|
-
font-family: Lato;
|
|
9
|
-
}
|
|
10
|
-
</style>
|
|
11
|
-
</head>
|
|
12
|
-
<body>
|
|
13
|
-
<h1>AppRun component as the web component. </h1>
|
|
14
|
-
<my-app id="counter"></my-app>
|
|
15
|
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/custom-elements/1.1.2/custom-elements.min.js"></script>
|
|
16
|
-
<script src="dist/apprun-html.js"></script>
|
|
17
|
-
<script>
|
|
18
|
-
class Counter extends Component {
|
|
19
|
-
constructor() {
|
|
20
|
-
super();
|
|
21
|
-
this.state = 0;
|
|
22
|
-
this.view = state => `<div>
|
|
23
|
-
<h1>${state}</h1>
|
|
24
|
-
<button onclick='counter.run("-1")'>-1</button>
|
|
25
|
-
<button onclick='counter.run("+1")'>+1</button>
|
|
26
|
-
</div>`;
|
|
27
|
-
this.update = {
|
|
28
|
-
'+1': state => state + 1,
|
|
29
|
-
'-1': state => state - 1
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
app.webComponent('my-app', Counter, {shadow: true});
|
|
34
|
-
</script>
|
|
35
|
-
</body>
|
|
36
|
-
</html>
|