@mantou/gem 1.6.3 → 1.6.9
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 +6 -38
- package/dist/gem.es.js +3272 -0
- package/dist/gem.umd.js +229 -0
- package/elements/dialog-base.d.ts +2 -2
- package/elements/dialog-base.d.ts.map +1 -1
- package/elements/dialog-base.js +6 -6
- package/elements/dialog-base.js.map +1 -1
- package/elements/gesture.d.ts +2 -1
- package/elements/gesture.d.ts.map +1 -1
- package/elements/gesture.js +6 -5
- package/elements/gesture.js.map +1 -1
- package/elements/link.d.ts +1 -1
- package/elements/link.d.ts.map +1 -1
- package/elements/link.js +11 -16
- package/elements/link.js.map +1 -1
- package/elements/modal-base.d.ts +4 -4
- package/elements/modal-base.d.ts.map +1 -1
- package/elements/modal-base.js +9 -4
- package/elements/modal-base.js.map +1 -1
- package/elements/reflect.d.ts +1 -1
- package/elements/reflect.d.ts.map +1 -1
- package/elements/reflect.js +2 -1
- package/elements/reflect.js.map +1 -1
- package/elements/route.d.ts +7 -3
- package/elements/route.d.ts.map +1 -1
- package/elements/route.js +12 -6
- package/elements/route.js.map +1 -1
- package/elements/title.d.ts +1 -1
- package/elements/title.d.ts.map +1 -1
- package/elements/title.js +4 -1
- package/elements/title.js.map +1 -1
- package/elements/unsafe.d.ts +1 -1
- package/elements/unsafe.d.ts.map +1 -1
- package/elements/unsafe.js +2 -1
- package/elements/unsafe.js.map +1 -1
- package/elements/use.d.ts +1 -1
- package/elements/use.d.ts.map +1 -1
- package/elements/use.js +2 -1
- package/elements/use.js.map +1 -1
- package/helper/i18n.js +47 -58
- package/helper/i18n.js.map +1 -1
- package/helper/request.js +11 -19
- package/helper/request.js.map +1 -1
- package/index.d.ts +5 -4
- package/index.d.ts.map +1 -1
- package/index.js +4 -2
- package/index.js.map +1 -1
- package/lib/element.d.ts.map +1 -1
- package/lib/element.js +1 -1
- package/lib/element.js.map +1 -1
- package/lib/history.js +17 -5
- package/lib/history.js.map +1 -1
- package/lib/utils.d.ts +3 -1
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +7 -4
- package/lib/utils.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +26 -53
- package/src/{umd.ts → dist.ts} +1 -5
- package/src/elements/dialog-base.ts +5 -4
- package/src/elements/gesture.ts +2 -1
- package/src/elements/link.ts +5 -15
- package/src/elements/modal-base.ts +3 -1
- package/src/elements/reflect.ts +2 -1
- package/src/elements/route.ts +8 -20
- package/src/elements/title.ts +4 -1
- package/src/elements/unsafe.ts +2 -1
- package/src/elements/use.ts +2 -1
- package/src/index.ts +4 -6
- package/src/lib/element.ts +2 -1
- package/src/lib/history.ts +1 -1
- package/src/lib/utils.ts +10 -4
- package/src/lib/version.ts +1 -1
- package/src/test/gem-element/advance.test.ts +1 -0
- package/src/test/gem-element/basic.test.ts +1 -0
- package/src/test/gem-element/decorators.test.ts +1 -0
- package/src/test/gem-element/multi.test.ts +1 -0
- package/src/test/history.test.ts +1 -0
- package/src/test/store.test.ts +1 -0
- package/src/test/utils.test.ts +1 -0
- package/src/examples/base-path/index.ts +0 -44
- package/src/examples/controlled/index.ts +0 -75
- package/src/examples/decorator/chidren.ts +0 -77
- package/src/examples/decorator/index.ts +0 -110
- package/src/examples/dialog/index.ts +0 -148
- package/src/examples/effect/index.ts +0 -45
- package/src/examples/elements/env.ts +0 -7
- package/src/examples/elements/layout.ts +0 -53
- package/src/examples/elements/nav.ts +0 -71
- package/src/examples/elements/source.ts +0 -68
- package/src/examples/gesture/canvas.ts +0 -69
- package/src/examples/gesture/index.ts +0 -97
- package/src/examples/gesture/manifest.json +0 -3
- package/src/examples/hash/index.ts +0 -55
- package/src/examples/i18n/index.ts +0 -63
- package/src/examples/index/index.ts +0 -33
- package/src/examples/index/manifest.json +0 -5
- package/src/examples/light-dom/index.ts +0 -31
- package/src/examples/multi-page/api.ts +0 -9
- package/src/examples/multi-page/index.ts +0 -78
- package/src/examples/multi-page/page-a.ts +0 -16
- package/src/examples/multi-page/page-b.ts +0 -12
- package/src/examples/multi-page/page-c.ts +0 -40
- package/src/examples/multi-page/store.ts +0 -10
- package/src/examples/perf-demo/index.ts +0 -136
- package/src/examples/ref-route/index.ts +0 -109
- package/src/examples/reflect/index.ts +0 -61
- package/src/examples/styled/index.ts +0 -39
- package/src/examples/svg-icon/index.ts +0 -31
- package/src/examples/theme/index.ts +0 -56
- package/src/examples/unsafe/index.ts +0 -29
- package/umd.d.ts +0 -18
- package/umd.d.ts.map +0 -1
- package/umd.js +0 -54
- package/umd.js.LICENSE.txt +0 -13
- package/umd.js.map +0 -1
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { GemElement, html, customElement, version } from '../..';
|
|
2
|
-
import { MATADATA, EXAMPLES, EXAMPLE } from './env';
|
|
3
|
-
|
|
4
|
-
const getGitPageUrl = (name: string) => `../${name}/`;
|
|
5
|
-
|
|
6
|
-
const getName = (name: string) => (MATADATA[name].name || name).replace('-', ' ');
|
|
7
|
-
|
|
8
|
-
@customElement('gem-examples-nav')
|
|
9
|
-
export class Nav extends GemElement {
|
|
10
|
-
render() {
|
|
11
|
-
return html`
|
|
12
|
-
<style>
|
|
13
|
-
:host {
|
|
14
|
-
grid-area: nav;
|
|
15
|
-
padding: 2em 0;
|
|
16
|
-
overflow: auto;
|
|
17
|
-
background: #666;
|
|
18
|
-
color: white;
|
|
19
|
-
}
|
|
20
|
-
.header {
|
|
21
|
-
margin-bottom: 1em;
|
|
22
|
-
padding: 0 2em;
|
|
23
|
-
}
|
|
24
|
-
.name {
|
|
25
|
-
font-size: 1.2em;
|
|
26
|
-
}
|
|
27
|
-
.version {
|
|
28
|
-
font-family: monospace;
|
|
29
|
-
}
|
|
30
|
-
ol {
|
|
31
|
-
margin: 0;
|
|
32
|
-
padding: 0;
|
|
33
|
-
}
|
|
34
|
-
li {
|
|
35
|
-
display: contents;
|
|
36
|
-
}
|
|
37
|
-
a {
|
|
38
|
-
padding: 0.5em 2em;
|
|
39
|
-
display: block;
|
|
40
|
-
color: inherit;
|
|
41
|
-
opacity: 0.8;
|
|
42
|
-
line-height: 1.5;
|
|
43
|
-
text-decoration: none;
|
|
44
|
-
text-transform: capitalize;
|
|
45
|
-
}
|
|
46
|
-
a:hover {
|
|
47
|
-
opacity: 1;
|
|
48
|
-
}
|
|
49
|
-
a.active {
|
|
50
|
-
opacity: 1;
|
|
51
|
-
background: #444;
|
|
52
|
-
}
|
|
53
|
-
</style>
|
|
54
|
-
<a class="header" href="https://github.com/mantou132/gem" target="_blank">
|
|
55
|
-
<div class="name">Gem Examples</div>
|
|
56
|
-
<div class="version">version: ${version}</div>
|
|
57
|
-
</a>
|
|
58
|
-
<ol>
|
|
59
|
-
${EXAMPLES.sort((a, b) => ((MATADATA[a].order || 0) > (MATADATA[b].order || 0) ? 1 : -1)).map(
|
|
60
|
-
(name) =>
|
|
61
|
-
html`<li>
|
|
62
|
-
<a class=${EXAMPLE === name ? 'active' : ''} href=${getGitPageUrl(name)}>
|
|
63
|
-
<div>${getName(name)}</div>
|
|
64
|
-
<div>${MATADATA[name].desc}</div>
|
|
65
|
-
</a>
|
|
66
|
-
</li>`,
|
|
67
|
-
)}
|
|
68
|
-
</ol>
|
|
69
|
-
`;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { GemElement, html, customElement } from '../..';
|
|
2
|
-
import { EXAMPLE, FILES } from './env';
|
|
3
|
-
|
|
4
|
-
@customElement('gem-examples-source')
|
|
5
|
-
export class Source extends GemElement {
|
|
6
|
-
state = {
|
|
7
|
-
files: FILES.map((file) => ({ file: file, content: '' })),
|
|
8
|
-
current: FILES[0],
|
|
9
|
-
};
|
|
10
|
-
render() {
|
|
11
|
-
const { files, current } = this.state;
|
|
12
|
-
return html`
|
|
13
|
-
<style>
|
|
14
|
-
:host {
|
|
15
|
-
border-top: 1px solid #666;
|
|
16
|
-
overflow: auto;
|
|
17
|
-
grid-area: source;
|
|
18
|
-
background: #eee5;
|
|
19
|
-
}
|
|
20
|
-
ul {
|
|
21
|
-
margin: 0;
|
|
22
|
-
padding: 0 1em;
|
|
23
|
-
display: flex;
|
|
24
|
-
gap: 1em 2em;
|
|
25
|
-
border-bottom: 1px solid #eee;
|
|
26
|
-
position: sticky;
|
|
27
|
-
top: 0;
|
|
28
|
-
background: white;
|
|
29
|
-
}
|
|
30
|
-
li {
|
|
31
|
-
cursor: pointer;
|
|
32
|
-
line-height: 2;
|
|
33
|
-
list-style: none;
|
|
34
|
-
border-bottom: 2px solid transparent;
|
|
35
|
-
}
|
|
36
|
-
li.current {
|
|
37
|
-
border-color: #1ecfe3;
|
|
38
|
-
}
|
|
39
|
-
pre {
|
|
40
|
-
margin: 0;
|
|
41
|
-
padding: 1em;
|
|
42
|
-
}
|
|
43
|
-
</style>
|
|
44
|
-
<ul>
|
|
45
|
-
${FILES.map(
|
|
46
|
-
(file) =>
|
|
47
|
-
html`
|
|
48
|
-
<li class=${current === file ? 'current' : ''} @click=${() => this.setState({ current: file })}>
|
|
49
|
-
${file}
|
|
50
|
-
</li>
|
|
51
|
-
`,
|
|
52
|
-
)}
|
|
53
|
-
</ul>
|
|
54
|
-
<pre>${files.find((e) => e.file === current)?.content}</pre>
|
|
55
|
-
`;
|
|
56
|
-
}
|
|
57
|
-
mounted() {
|
|
58
|
-
FILES.forEach(async (file) => {
|
|
59
|
-
const { files } = this.state;
|
|
60
|
-
const item = files.find((e) => e.file === file);
|
|
61
|
-
if (!item) return;
|
|
62
|
-
item.content = await (
|
|
63
|
-
await fetch(`https://raw.githubusercontent.com/mantou132/gem/master/src/examples/${EXAMPLE}/${file}`)
|
|
64
|
-
).text();
|
|
65
|
-
this.update();
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { GemElement, html, customElement, property, refobject, RefObject } from '../..';
|
|
2
|
-
import { PanEventDetail } from '../../elements/gesture';
|
|
3
|
-
|
|
4
|
-
@customElement('app-canvas')
|
|
5
|
-
export class AppCanvas extends GemElement {
|
|
6
|
-
@property data: PanEventDetail[];
|
|
7
|
-
|
|
8
|
-
@refobject canvasRef: RefObject<HTMLCanvasElement>;
|
|
9
|
-
@refobject canvasRef1: RefObject<HTMLCanvasElement>;
|
|
10
|
-
render() {
|
|
11
|
-
return html`
|
|
12
|
-
<br />
|
|
13
|
-
<canvas ref=${this.canvasRef.ref} style="border: 1px solid"></canvas>
|
|
14
|
-
<canvas ref=${this.canvasRef1.ref} style="border: 1px solid"></canvas>
|
|
15
|
-
`;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
mounted() {
|
|
19
|
-
const canvas = this.canvasRef.element!;
|
|
20
|
-
const canvas1 = this.canvasRef1.element!;
|
|
21
|
-
const ctx = canvas.getContext('2d')!;
|
|
22
|
-
const ctx1 = canvas1.getContext('2d')!;
|
|
23
|
-
canvas.height = 150;
|
|
24
|
-
canvas1.height = 150;
|
|
25
|
-
this.effect(() => {
|
|
26
|
-
canvas.width = 0;
|
|
27
|
-
canvas.width = 300;
|
|
28
|
-
canvas1.width = 0;
|
|
29
|
-
canvas1.width = 300;
|
|
30
|
-
const maxX = [...this.data].sort(({ x }, { x: x1 }) => {
|
|
31
|
-
if (x > x1) return -1;
|
|
32
|
-
return 1;
|
|
33
|
-
})[0]?.x;
|
|
34
|
-
ctx.fillText(String(maxX), 0, 8);
|
|
35
|
-
const maxY = [...this.data].sort(({ y }, { y: y1 }) => {
|
|
36
|
-
if (y > y1) return -1;
|
|
37
|
-
return 1;
|
|
38
|
-
})[0]?.y;
|
|
39
|
-
ctx1.fillText(String(maxY), 0, 8);
|
|
40
|
-
console.log('x:', this.data.map(({ x }) => x).join());
|
|
41
|
-
console.log('y:', this.data.map(({ y }) => y).join());
|
|
42
|
-
console.log(
|
|
43
|
-
'timeStamp interval:',
|
|
44
|
-
this.data.reduce(
|
|
45
|
-
(p, c, index) => (index ? `${p}, ${(c.timeStamp - this.data[index - 1].timeStamp).toFixed()}` : ''),
|
|
46
|
-
'',
|
|
47
|
-
),
|
|
48
|
-
);
|
|
49
|
-
this.data.forEach((data, index) => {
|
|
50
|
-
const y = 150 - data.x * (150 / maxX);
|
|
51
|
-
const y1 = 150 - data.y * (150 / maxY);
|
|
52
|
-
const x = index * (300 / this.data.length);
|
|
53
|
-
if (index === 0) {
|
|
54
|
-
ctx.beginPath();
|
|
55
|
-
ctx.moveTo(x, y);
|
|
56
|
-
ctx1.beginPath();
|
|
57
|
-
ctx1.moveTo(x, y1);
|
|
58
|
-
} else {
|
|
59
|
-
ctx.lineTo(x, y);
|
|
60
|
-
ctx1.lineTo(x, y1);
|
|
61
|
-
}
|
|
62
|
-
if (index === this.data.length - 1) {
|
|
63
|
-
ctx.stroke();
|
|
64
|
-
ctx1.stroke();
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { render, GemElement, html, customElement, refobject, RefObject } from '../..';
|
|
2
|
-
|
|
3
|
-
import '../../elements/gesture';
|
|
4
|
-
import { PanEventDetail, PinchEventDetail, RotateEventDetail, SwipeEventDetail } from '../../elements/gesture';
|
|
5
|
-
import '../elements/layout';
|
|
6
|
-
import './canvas';
|
|
7
|
-
|
|
8
|
-
@customElement('app-root')
|
|
9
|
-
export class AppRoot extends GemElement {
|
|
10
|
-
@refobject gestureRef: RefObject<any>;
|
|
11
|
-
state = {
|
|
12
|
-
x: 0,
|
|
13
|
-
y: 0,
|
|
14
|
-
duration: 0,
|
|
15
|
-
scale: 1,
|
|
16
|
-
rotate: 0,
|
|
17
|
-
swipe: '',
|
|
18
|
-
moves: [],
|
|
19
|
-
};
|
|
20
|
-
onPan = (evt: CustomEvent<PanEventDetail>) => {
|
|
21
|
-
const { detail } = evt;
|
|
22
|
-
const { x, y } = this.state;
|
|
23
|
-
this.setState({ x: detail.x + x, y: detail.y + y, duration: 0 });
|
|
24
|
-
};
|
|
25
|
-
onPinch = (evt: CustomEvent<PinchEventDetail>) => {
|
|
26
|
-
this.setState({ scale: evt.detail.scale * this.state.scale });
|
|
27
|
-
};
|
|
28
|
-
onRotate = (evt: CustomEvent<RotateEventDetail>) => {
|
|
29
|
-
this.setState({ rotate: evt.detail.rotate + this.state.rotate });
|
|
30
|
-
};
|
|
31
|
-
onSwipe = (e: CustomEvent<SwipeEventDetail>) => {
|
|
32
|
-
this.setState({ swipe: `${e.detail.direction}, speed: ${e.detail.speed}` });
|
|
33
|
-
};
|
|
34
|
-
onEnd = () => {
|
|
35
|
-
this.setState({
|
|
36
|
-
x: 0,
|
|
37
|
-
y: 0,
|
|
38
|
-
duration: 0.5,
|
|
39
|
-
scale: 1,
|
|
40
|
-
rotate: 0,
|
|
41
|
-
swipe: '',
|
|
42
|
-
moves: [...this.gestureRef.element.movesMap.values().next().value],
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
render() {
|
|
46
|
-
const { x, y, scale, rotate, duration, swipe, moves } = this.state;
|
|
47
|
-
return html`
|
|
48
|
-
<style>
|
|
49
|
-
img {
|
|
50
|
-
translate: ${x}px ${y}px;
|
|
51
|
-
scale: ${scale};
|
|
52
|
-
rotate: ${rotate}deg;
|
|
53
|
-
transition: all ${duration}s;
|
|
54
|
-
}
|
|
55
|
-
</style>
|
|
56
|
-
<gem-gesture
|
|
57
|
-
ref=${this.gestureRef.ref}
|
|
58
|
-
@pan=${this.onPan}
|
|
59
|
-
@end=${this.onEnd}
|
|
60
|
-
@pinch=${this.onPinch}
|
|
61
|
-
@rotate=${this.onRotate}
|
|
62
|
-
@press=${console.log}
|
|
63
|
-
@swipe=${this.onSwipe}
|
|
64
|
-
touch-action="pan-y"
|
|
65
|
-
>
|
|
66
|
-
<gem-gesture
|
|
67
|
-
@pan=${console.log}
|
|
68
|
-
@end=${console.log}
|
|
69
|
-
@pinch=${console.log}
|
|
70
|
-
@rotate=${console.log}
|
|
71
|
-
@press=${console.log}
|
|
72
|
-
@swipe=${console.log}
|
|
73
|
-
touch-action="pan-y"
|
|
74
|
-
>
|
|
75
|
-
<img src="https://gem-book.js.org/logo.png" width="200" />
|
|
76
|
-
</gem-gesture>
|
|
77
|
-
<div>${moves[moves.length - 1] ? `${JSON.stringify(moves[moves.length - 1])}` : ''}</div>
|
|
78
|
-
<div>${swipe}</div>
|
|
79
|
-
<app-canvas .data=${moves}></app-canvas>
|
|
80
|
-
</gem-gesture>
|
|
81
|
-
`;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
render(
|
|
86
|
-
html`
|
|
87
|
-
<style>
|
|
88
|
-
body {
|
|
89
|
-
overscroll-behavior: contain;
|
|
90
|
-
}
|
|
91
|
-
</style>
|
|
92
|
-
<gem-examples-layout>
|
|
93
|
-
<app-root slot="main"></app-root>
|
|
94
|
-
</gem-examples-layout>
|
|
95
|
-
`,
|
|
96
|
-
document.body,
|
|
97
|
-
);
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { GemElement, render, html } from '../../';
|
|
2
|
-
import '../../elements/link';
|
|
3
|
-
|
|
4
|
-
import '../elements/layout';
|
|
5
|
-
|
|
6
|
-
class Article extends GemElement {
|
|
7
|
-
constructor() {
|
|
8
|
-
super();
|
|
9
|
-
window.addEventListener('hashchange', this.checkHash);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
mounted = () => {
|
|
13
|
-
// 在当前页面刷新浏览器会保留滚动位置
|
|
14
|
-
// 开新窗口测试带 hash 链接
|
|
15
|
-
this.checkHash();
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
unmounted = () => {
|
|
19
|
-
window.removeEventListener('hashchange', this.checkHash);
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
checkHash = () => {
|
|
23
|
-
if (this.id === location.hash.substr(1)) {
|
|
24
|
-
this.scrollIntoView();
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
render() {
|
|
29
|
-
return html`<div style="height: 1000px"><slot></slot></div>`;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
customElements.define('app-article', Article);
|
|
33
|
-
|
|
34
|
-
class App extends GemElement {
|
|
35
|
-
render() {
|
|
36
|
-
return html`
|
|
37
|
-
<a href="#article-1">${'<a href="#article-1">'}</a>
|
|
38
|
-
<a href="#article-2">${'<a href="#article-2">'}</a>
|
|
39
|
-
<gem-link path="/" hash="#article-1"><button>go #article-1</button></gem-link>
|
|
40
|
-
<gem-link path="/" hash="#article-2"><button>go #article-2</button></gem-link>
|
|
41
|
-
<app-article id="article-1" style="display: block; margin-top: 100px;">article-1</app-article>
|
|
42
|
-
<app-article id="article-2" style="display: block; margin-top: 100px;">article-2</app-article>
|
|
43
|
-
`;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
customElements.define('app-root', App);
|
|
47
|
-
|
|
48
|
-
render(
|
|
49
|
-
html`
|
|
50
|
-
<gem-examples-layout>
|
|
51
|
-
<app-root slot="main"></app-root>
|
|
52
|
-
</gem-examples-layout>
|
|
53
|
-
`,
|
|
54
|
-
document.body,
|
|
55
|
-
);
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { GemElement, html, connectStore, customElement, render } from '../../';
|
|
2
|
-
|
|
3
|
-
import '../elements/layout';
|
|
4
|
-
|
|
5
|
-
import { I18n } from '../../helper/i18n';
|
|
6
|
-
|
|
7
|
-
const en = {
|
|
8
|
-
title: 'This is I18n',
|
|
9
|
-
hello: 'Hello, $1! $2=> $1, Hello!',
|
|
10
|
-
detail: 'See $1<detail>, $1<detail2>',
|
|
11
|
-
};
|
|
12
|
-
const i18n = new I18n<typeof en>({
|
|
13
|
-
cache: true,
|
|
14
|
-
fallbackLanguage: 'en',
|
|
15
|
-
resources: {
|
|
16
|
-
en,
|
|
17
|
-
de: {
|
|
18
|
-
title: 'Das ist I18n',
|
|
19
|
-
},
|
|
20
|
-
zh: 'data:text/plain;base64,eyJ0aXRsZSI6Iui/meaYr0kxOG4ifQ==',
|
|
21
|
-
},
|
|
22
|
-
onChange: console.log,
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
const i18nModule = i18n.createSubModule<typeof en>('test', {
|
|
26
|
-
en,
|
|
27
|
-
de: {
|
|
28
|
-
title: 'Das ist I18n',
|
|
29
|
-
},
|
|
30
|
-
zh: 'data:text/plain;base64,eyJ0aXRsZSI6Iui/meaYr0kxOG4ifQ==',
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
@connectStore(i18n.store)
|
|
34
|
-
@connectStore(i18nModule.store)
|
|
35
|
-
@customElement('app-root')
|
|
36
|
-
export class App extends GemElement {
|
|
37
|
-
render() {
|
|
38
|
-
return html`
|
|
39
|
-
<button @click=${() => i18n.setLanguage('de')}>de</button>
|
|
40
|
-
<button @click=${() => i18n.setLanguage('zh')}>zh</button>
|
|
41
|
-
<button @click=${() => i18n.setLanguage('en')}>en</button>
|
|
42
|
-
<button @click=${() => i18n.resetLanguage()}>reset</button>
|
|
43
|
-
<p>Current language: ${i18n.currentLanguage}</p>
|
|
44
|
-
<p>${i18n.get('title')}</p>
|
|
45
|
-
<p>${i18n.get('hello', 'World', 'reverse')}</p>
|
|
46
|
-
<p>${i18n.get('detail', (s) => html`<a href="#">${s}</a>`)}</p>
|
|
47
|
-
|
|
48
|
-
<h2>sub module</h2>
|
|
49
|
-
<p>${i18nModule.get('title')}</p>
|
|
50
|
-
<p>${i18nModule.get('hello', 'World', 'reverse')}</p>
|
|
51
|
-
<p>${i18nModule.get('detail', (s) => html`<a href="#">${s}</a>`)}</p>
|
|
52
|
-
`;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
render(
|
|
57
|
-
html`
|
|
58
|
-
<gem-examples-layout>
|
|
59
|
-
<app-root slot="main"></app-root>
|
|
60
|
-
</gem-examples-layout>
|
|
61
|
-
`,
|
|
62
|
-
document.body,
|
|
63
|
-
);
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { render, GemElement, createStore, updateStore, html } from '../../';
|
|
2
|
-
import { connectStore, customElement } from '../../lib/decorators';
|
|
3
|
-
|
|
4
|
-
import '../elements/layout';
|
|
5
|
-
|
|
6
|
-
// 新建全局数据对象
|
|
7
|
-
const store = createStore({
|
|
8
|
-
a: 1,
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
// 定义自定义元素
|
|
12
|
-
@customElement('app-root')
|
|
13
|
-
@connectStore(store)
|
|
14
|
-
export class HelloWorld extends GemElement {
|
|
15
|
-
clickHandle = () => {
|
|
16
|
-
updateStore(store, { a: ++store.a });
|
|
17
|
-
};
|
|
18
|
-
render() {
|
|
19
|
-
return html`
|
|
20
|
-
<button @click="${this.clickHandle}">Hello, World</button>
|
|
21
|
-
<div>store.a: ${store.a}</div>
|
|
22
|
-
`;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
render(
|
|
27
|
-
html`
|
|
28
|
-
<gem-examples-layout>
|
|
29
|
-
<app-root slot="main"></app-root>
|
|
30
|
-
</gem-examples-layout>
|
|
31
|
-
`,
|
|
32
|
-
document.body,
|
|
33
|
-
);
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { GemElement, html, render } from '../../';
|
|
2
|
-
|
|
3
|
-
import '../elements/layout';
|
|
4
|
-
|
|
5
|
-
export class App extends GemElement {
|
|
6
|
-
state = { now: 0 };
|
|
7
|
-
constructor() {
|
|
8
|
-
super({ isLight: true });
|
|
9
|
-
setInterval(() => {
|
|
10
|
-
this.setState({ now: Date.now() });
|
|
11
|
-
}, 1000);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
render() {
|
|
15
|
-
return html`
|
|
16
|
-
<div>hello world!</div>
|
|
17
|
-
<time>${this.state.now}</time>
|
|
18
|
-
`;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
customElements.define('app-root', App);
|
|
23
|
-
|
|
24
|
-
render(
|
|
25
|
-
html`
|
|
26
|
-
<gem-examples-layout>
|
|
27
|
-
<app-root slot="main"></app-root>
|
|
28
|
-
</gem-examples-layout>
|
|
29
|
-
`,
|
|
30
|
-
document.body,
|
|
31
|
-
);
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { GemElement, html, render } from '../../';
|
|
2
|
-
import { GemTitleElement } from '../../elements/title';
|
|
3
|
-
import '../../elements/route';
|
|
4
|
-
import '../../elements/link';
|
|
5
|
-
|
|
6
|
-
import '../elements/layout';
|
|
7
|
-
|
|
8
|
-
import './page-b';
|
|
9
|
-
import './page-c';
|
|
10
|
-
|
|
11
|
-
const routes = [
|
|
12
|
-
{
|
|
13
|
-
pattern: '/',
|
|
14
|
-
redirect: '/c/e',
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
title: 'Page A Title',
|
|
18
|
-
pattern: '/a',
|
|
19
|
-
get content() {
|
|
20
|
-
import('./page-a');
|
|
21
|
-
return html`<app-page-a>A: </app-page-a>`;
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
title: 'Page B Title',
|
|
26
|
-
pattern: '/B',
|
|
27
|
-
content: html` <app-page-b>B: </app-page-b> `,
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
title: 'Page C Title',
|
|
31
|
-
pattern: '/c/*',
|
|
32
|
-
content: html`<app-page-c>C: </app-page-c>`,
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
pattern: '/',
|
|
36
|
-
content: html`<div>hello</div>`,
|
|
37
|
-
},
|
|
38
|
-
];
|
|
39
|
-
|
|
40
|
-
class App extends GemElement {
|
|
41
|
-
render() {
|
|
42
|
-
return html`
|
|
43
|
-
<style>
|
|
44
|
-
:host {
|
|
45
|
-
text-align: center;
|
|
46
|
-
}
|
|
47
|
-
gem-link {
|
|
48
|
-
cursor: pointer;
|
|
49
|
-
}
|
|
50
|
-
gem-link + gem-link {
|
|
51
|
-
margin-left: 0.5em;
|
|
52
|
-
}
|
|
53
|
-
gem-link:hover {
|
|
54
|
-
text-decoration: underline;
|
|
55
|
-
}
|
|
56
|
-
</style>
|
|
57
|
-
<header><gem-title suffix=${GemTitleElement.defaultSuffix}>AppName</gem-title></header>
|
|
58
|
-
<nav>
|
|
59
|
-
<gem-link path="/">Home</gem-link>
|
|
60
|
-
<gem-link path="/A">PageA</gem-link>
|
|
61
|
-
<gem-link path="/b">PageB</gem-link>
|
|
62
|
-
<gem-link path="/c/e" pattern="/c/*">PageC</gem-link>
|
|
63
|
-
</nav>
|
|
64
|
-
<main><gem-light-route .routes=${routes}></gem-light-route></main>
|
|
65
|
-
`;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
customElements.define('app-root', App);
|
|
70
|
-
|
|
71
|
-
render(
|
|
72
|
-
html`
|
|
73
|
-
<gem-examples-layout>
|
|
74
|
-
<app-root slot="main"></app-root>
|
|
75
|
-
</gem-examples-layout>
|
|
76
|
-
`,
|
|
77
|
-
document.body,
|
|
78
|
-
);
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { GemElement, html } from '../../';
|
|
2
|
-
import storeSet from './store';
|
|
3
|
-
import api from './api';
|
|
4
|
-
|
|
5
|
-
customElements.define(
|
|
6
|
-
'app-page-a',
|
|
7
|
-
class extends GemElement {
|
|
8
|
-
static observedStores = [storeSet.pageA];
|
|
9
|
-
mounted() {
|
|
10
|
-
api.getData();
|
|
11
|
-
}
|
|
12
|
-
render() {
|
|
13
|
-
return html`<slot></slot> ${storeSet.pageA.text}`;
|
|
14
|
-
}
|
|
15
|
-
},
|
|
16
|
-
);
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { GemElement, html } from '../../';
|
|
2
|
-
import storeSet from './store';
|
|
3
|
-
|
|
4
|
-
customElements.define(
|
|
5
|
-
'app-page-b',
|
|
6
|
-
class extends GemElement {
|
|
7
|
-
static observedStores = [storeSet.pageB];
|
|
8
|
-
render() {
|
|
9
|
-
return html`<slot></slot> ${storeSet.pageB.text}`;
|
|
10
|
-
}
|
|
11
|
-
},
|
|
12
|
-
);
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { GemElement, html } from '../../';
|
|
2
|
-
import '../../elements/route';
|
|
3
|
-
import '../../elements/link';
|
|
4
|
-
|
|
5
|
-
const routes = [
|
|
6
|
-
{
|
|
7
|
-
title: 'ccccccd',
|
|
8
|
-
pattern: '/c/d',
|
|
9
|
-
content: html`<div>C/D</div>`,
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
// `title` 未设置会使用父路由标题
|
|
13
|
-
pattern: '/c/e',
|
|
14
|
-
content: html`<div>C/E</div>`,
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
pattern: '/c/*',
|
|
18
|
-
content: html`<div>C/E</div>`,
|
|
19
|
-
},
|
|
20
|
-
];
|
|
21
|
-
|
|
22
|
-
customElements.define(
|
|
23
|
-
'app-page-c',
|
|
24
|
-
class extends GemElement {
|
|
25
|
-
render() {
|
|
26
|
-
return html`
|
|
27
|
-
<style>
|
|
28
|
-
gem-link + gem-link {
|
|
29
|
-
margin-left: 0.5em;
|
|
30
|
-
}
|
|
31
|
-
</style>
|
|
32
|
-
<gem-link path="./d">Page c/d</gem-link>
|
|
33
|
-
<gem-link path="./e">Page c/e</gem-link>
|
|
34
|
-
<gem-route .routes=${routes}></gem-route>
|
|
35
|
-
inert route:
|
|
36
|
-
<gem-route ?inert=${true} .routes=${routes}></gem-route>
|
|
37
|
-
`;
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
);
|