@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
package/src/index.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* 不支持多个 gem
|
|
3
|
+
*/
|
|
2
4
|
import * as Gem from './';
|
|
3
5
|
|
|
4
|
-
export
|
|
5
|
-
updateStore: typeof updateStore;
|
|
6
|
-
}
|
|
7
|
-
|
|
6
|
+
export type DevToolsHook = typeof Gem;
|
|
8
7
|
declare global {
|
|
9
8
|
interface Window {
|
|
10
9
|
__GEM_DEVTOOLS__HOOK__?: DevToolsHook;
|
|
@@ -12,7 +11,6 @@ declare global {
|
|
|
12
11
|
}
|
|
13
12
|
|
|
14
13
|
if (window.__GEM_DEVTOOLS__HOOK__) {
|
|
15
|
-
// 不支持多个 gem
|
|
16
14
|
Object.assign(window.__GEM_DEVTOOLS__HOOK__, { ...Gem });
|
|
17
15
|
}
|
|
18
16
|
|
package/src/lib/element.ts
CHANGED
package/src/lib/history.ts
CHANGED
|
@@ -89,7 +89,7 @@ function initParams(params: UpdateHistoryParams): HistoryParams {
|
|
|
89
89
|
const query = new QueryString(params.query || (params.path ? '' : location.search));
|
|
90
90
|
const pathChanged =
|
|
91
91
|
(params.path && params.path !== current.path) || (params.query && String(params.query) !== String(current.query));
|
|
92
|
-
const title = params.title || '';
|
|
92
|
+
const title = params.title || (pathChanged ? '' : document.title);
|
|
93
93
|
const statusChanged = params.close || params.data || params.open || params.shouldClose;
|
|
94
94
|
// 没提供 hash 又没有改变路径又不是状态更新时使用当前 hash
|
|
95
95
|
const hash = params.hash || (!pathChanged && statusChanged ? decodeURIComponent(location.hash) : '');
|
package/src/lib/utils.ts
CHANGED
|
@@ -355,6 +355,7 @@ export class GemError extends Error {
|
|
|
355
355
|
|
|
356
356
|
export function isArrayChange(newValues: any[], oldValues: any[]) {
|
|
357
357
|
const length = newValues.length;
|
|
358
|
+
if (oldValues.length !== length) return true;
|
|
358
359
|
for (let i = 0; i < length; i++) {
|
|
359
360
|
if (newValues[i] !== oldValues[i]) return true;
|
|
360
361
|
}
|
|
@@ -372,11 +373,16 @@ export function removeItems(target: any[], items: any[]) {
|
|
|
372
373
|
});
|
|
373
374
|
}
|
|
374
375
|
|
|
375
|
-
|
|
376
|
+
type StyleProp = keyof CSSStyleDeclaration | `--${string}`;
|
|
377
|
+
|
|
378
|
+
export type StyleObject = Partial<Record<StyleProp, string | number | undefined>>;
|
|
379
|
+
|
|
380
|
+
// 不支持 webkit 属性
|
|
381
|
+
export function styleMap(object: StyleObject) {
|
|
376
382
|
let styleString = '';
|
|
377
|
-
for (const key in
|
|
378
|
-
if (
|
|
379
|
-
styleString += `${camelToKebabCase(key)}:${
|
|
383
|
+
for (const key in object) {
|
|
384
|
+
if (object[key as StyleProp] !== undefined) {
|
|
385
|
+
styleString += `${camelToKebabCase(key)}:${object[key as StyleProp]};`;
|
|
380
386
|
}
|
|
381
387
|
}
|
|
382
388
|
return styleString;
|
package/src/lib/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Do not modify manually
|
|
2
|
-
export const version = '1.6.
|
|
2
|
+
export const version = '1.6.5';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { fixture, expect, nextFrame } from '@open-wc/testing';
|
|
2
|
+
|
|
2
3
|
import { GemElement, html } from '../../lib/element';
|
|
3
4
|
import { createStore, updateStore } from '../../lib/store';
|
|
4
5
|
import { attribute, property, customElement, emitter, adoptedStyle } from '../../lib/decorators';
|
package/src/test/history.test.ts
CHANGED
package/src/test/store.test.ts
CHANGED
package/src/test/utils.test.ts
CHANGED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { GemElement, html, history, render, customElement } from '../../';
|
|
2
|
-
import '../../elements/link';
|
|
3
|
-
|
|
4
|
-
import '../elements/layout';
|
|
5
|
-
|
|
6
|
-
@customElement('app-root')
|
|
7
|
-
export class App extends GemElement {
|
|
8
|
-
state = {
|
|
9
|
-
count: 5,
|
|
10
|
-
};
|
|
11
|
-
constructor() {
|
|
12
|
-
super();
|
|
13
|
-
this.onclick = () => {
|
|
14
|
-
this.setState({ count: this.state.count - 1 });
|
|
15
|
-
if (!this.state.count) {
|
|
16
|
-
history.basePath = '/base-path';
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
render() {
|
|
21
|
-
return html`
|
|
22
|
-
<main>
|
|
23
|
-
${this.state.count > 0
|
|
24
|
-
? html`<div>${this.state.count} 次后将改变 \`basePath\`</div>`
|
|
25
|
-
: html`<div>\`basePath\` 为 ${history.basePath}</div>`}
|
|
26
|
-
<gem-link href="/a">href="/a"</gem-link>
|
|
27
|
-
<button @click=${() => history.push({ path: '/b' })}>push({ path: '/b' })</button>
|
|
28
|
-
<button @click=${() => history.push({ hash: '#b' })}>push({ hash: '#b' })</button>
|
|
29
|
-
<button @click=${() => history.pushIgnoreCloseHandle({ path: '/c' })}>
|
|
30
|
-
push({ pushIgnoreCloseHandle: '/c' })
|
|
31
|
-
</button>
|
|
32
|
-
</main>
|
|
33
|
-
`;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
render(
|
|
38
|
-
html`
|
|
39
|
-
<gem-examples-layout>
|
|
40
|
-
<app-root slot="main"></app-root>
|
|
41
|
-
</gem-examples-layout>
|
|
42
|
-
`,
|
|
43
|
-
document.body,
|
|
44
|
-
);
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { html, customElement, GemElement, render, attribute, emitter, Emitter, refobject, RefObject } from '../../';
|
|
2
|
-
|
|
3
|
-
import '../elements/layout';
|
|
4
|
-
|
|
5
|
-
@customElement('app-form-text')
|
|
6
|
-
export class FormText extends GemElement {
|
|
7
|
-
@refobject inputRef: RefObject<HTMLInputElement>;
|
|
8
|
-
@attribute value: string;
|
|
9
|
-
@emitter change: Emitter<string>;
|
|
10
|
-
|
|
11
|
-
nextState = {
|
|
12
|
-
value: '',
|
|
13
|
-
selectionStart: 0,
|
|
14
|
-
selectionEnd: 0,
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
mounted() {
|
|
18
|
-
this.effect(
|
|
19
|
-
() => {
|
|
20
|
-
const { element } = this.inputRef;
|
|
21
|
-
if (!element) return;
|
|
22
|
-
if (this.value === this.nextState.value) {
|
|
23
|
-
element.value = this.nextState.value;
|
|
24
|
-
element.selectionStart = this.nextState.selectionStart;
|
|
25
|
-
element.selectionEnd = this.nextState.selectionEnd;
|
|
26
|
-
} else {
|
|
27
|
-
element.value = this.value;
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
() => [this.value],
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
inputHandle = (e: InputEvent) => {
|
|
35
|
-
if (!e.isComposing) {
|
|
36
|
-
const { element } = this.inputRef;
|
|
37
|
-
if (!element) return;
|
|
38
|
-
const { value, selectionStart, selectionEnd } = element;
|
|
39
|
-
this.nextState = {
|
|
40
|
-
value,
|
|
41
|
-
selectionStart: selectionStart || 0,
|
|
42
|
-
selectionEnd: selectionEnd || 0,
|
|
43
|
-
};
|
|
44
|
-
element.value = this.value;
|
|
45
|
-
this.change(value);
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
render() {
|
|
50
|
-
return html`<input ref=${this.inputRef.ref} @input=${this.inputHandle} />`;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
@customElement('app-root')
|
|
55
|
-
export class Root extends GemElement {
|
|
56
|
-
state = { value: '' };
|
|
57
|
-
|
|
58
|
-
changeHandle = (e: CustomEvent<string>) => this.setState({ value: e.detail });
|
|
59
|
-
|
|
60
|
-
render() {
|
|
61
|
-
return html`
|
|
62
|
-
Controlled input:
|
|
63
|
-
<app-form-text @change=${this.changeHandle} value=${this.state.value}></app-form-text>
|
|
64
|
-
`;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
render(
|
|
69
|
-
html`
|
|
70
|
-
<gem-examples-layout>
|
|
71
|
-
<app-root slot="main"></app-root>
|
|
72
|
-
</gem-examples-layout>
|
|
73
|
-
`,
|
|
74
|
-
document.body,
|
|
75
|
-
);
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
GemElement,
|
|
3
|
-
html,
|
|
4
|
-
property,
|
|
5
|
-
attribute,
|
|
6
|
-
slot,
|
|
7
|
-
part,
|
|
8
|
-
state,
|
|
9
|
-
emitter,
|
|
10
|
-
Emitter,
|
|
11
|
-
customElement,
|
|
12
|
-
numattribute,
|
|
13
|
-
boolattribute,
|
|
14
|
-
rootElement,
|
|
15
|
-
} from '../../';
|
|
16
|
-
|
|
17
|
-
export type Message = number[];
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* @attr first-name
|
|
21
|
-
* @attr last-name
|
|
22
|
-
* @attr count
|
|
23
|
-
* @attr disabled
|
|
24
|
-
* @fires say-hi
|
|
25
|
-
* @fires load
|
|
26
|
-
* @state odd
|
|
27
|
-
* @slot light
|
|
28
|
-
* @part paragraph
|
|
29
|
-
*/
|
|
30
|
-
@customElement('app-children')
|
|
31
|
-
@rootElement('app-root')
|
|
32
|
-
export class Children extends GemElement {
|
|
33
|
-
@slot static light: string;
|
|
34
|
-
@part static paragraph: string;
|
|
35
|
-
|
|
36
|
-
@attribute firstName: string;
|
|
37
|
-
@attribute lastName: string;
|
|
38
|
-
@numattribute count: number;
|
|
39
|
-
@boolattribute disabled: boolean;
|
|
40
|
-
@property message: Message | undefined;
|
|
41
|
-
@emitter sayHi: Emitter;
|
|
42
|
-
@emitter load: Emitter;
|
|
43
|
-
@state odd: boolean;
|
|
44
|
-
|
|
45
|
-
constructor() {
|
|
46
|
-
super();
|
|
47
|
-
console.log('child cons');
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
mounted = () => {
|
|
51
|
-
console.log('child mounted');
|
|
52
|
-
setTimeout(() => this.load(new Date()), 1000);
|
|
53
|
-
this.addEventListener('click', () => {
|
|
54
|
-
this.odd = !this.odd;
|
|
55
|
-
});
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
updated = () => {
|
|
59
|
-
console.log('child updated');
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
render() {
|
|
63
|
-
console.log('child render');
|
|
64
|
-
return html`
|
|
65
|
-
<p>
|
|
66
|
-
attributes:
|
|
67
|
-
<span>${this.firstName},</span>
|
|
68
|
-
<span>${this.lastName},</span>
|
|
69
|
-
<span>${this.disabled},</span>
|
|
70
|
-
<span>${this.count}.</span>
|
|
71
|
-
</p>
|
|
72
|
-
<p part=${Children.paragraph}>properties: ${JSON.stringify(this.message)}</p>
|
|
73
|
-
<slot name=${Children.light}></slot>
|
|
74
|
-
<button @click=${() => this.sayHi({}, { bubbles: true, composed: true })}>say hi</button>
|
|
75
|
-
`;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createStore,
|
|
3
|
-
updateStore,
|
|
4
|
-
createCSSSheet,
|
|
5
|
-
GemElement,
|
|
6
|
-
html,
|
|
7
|
-
refobject,
|
|
8
|
-
RefObject,
|
|
9
|
-
attribute,
|
|
10
|
-
connectStore,
|
|
11
|
-
customElement,
|
|
12
|
-
adoptedStyle,
|
|
13
|
-
css,
|
|
14
|
-
render,
|
|
15
|
-
} from '../../';
|
|
16
|
-
|
|
17
|
-
import '../elements/layout';
|
|
18
|
-
|
|
19
|
-
import { Message, Children } from './chidren';
|
|
20
|
-
import './chidren';
|
|
21
|
-
|
|
22
|
-
interface GlobalState {
|
|
23
|
-
msg: Message;
|
|
24
|
-
now: Date;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const store = createStore<GlobalState>({
|
|
28
|
-
msg: [1, 2],
|
|
29
|
-
now: new Date(),
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
const styles = createCSSSheet(css`
|
|
33
|
-
h1 {
|
|
34
|
-
text-decoration: underline;
|
|
35
|
-
}
|
|
36
|
-
`);
|
|
37
|
-
|
|
38
|
-
@connectStore(store)
|
|
39
|
-
@adoptedStyle(styles)
|
|
40
|
-
@customElement('app-root')
|
|
41
|
-
export class App extends GemElement {
|
|
42
|
-
@refobject childRef: RefObject<Children>;
|
|
43
|
-
@attribute appTitle: string;
|
|
44
|
-
|
|
45
|
-
constructor(title: string) {
|
|
46
|
-
super();
|
|
47
|
-
this.appTitle = title;
|
|
48
|
-
console.log('parent cons');
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
mounted = () => {
|
|
52
|
-
console.log('parent mounted');
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
updated = () => {
|
|
56
|
-
console.log('parent updated');
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
onSayHi = () => {
|
|
60
|
-
const [foo, bar] = store.msg;
|
|
61
|
-
updateStore(store, {
|
|
62
|
-
msg: [bar, foo],
|
|
63
|
-
now: new Date(),
|
|
64
|
-
});
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
loadHandle = () => {
|
|
68
|
-
const { element } = this.childRef;
|
|
69
|
-
if (!element) return;
|
|
70
|
-
const { firstName, lastName, disabled, count } = element;
|
|
71
|
-
console.log({ firstName, lastName, disabled, count });
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
render() {
|
|
75
|
-
console.log('parent render');
|
|
76
|
-
return html`
|
|
77
|
-
<style>
|
|
78
|
-
app-children:where(:--odd, [data-odd])::part(${Children.paragraph}) {
|
|
79
|
-
color: red;
|
|
80
|
-
}
|
|
81
|
-
</style>
|
|
82
|
-
<h1>${this.appTitle}</h1>
|
|
83
|
-
<app-children
|
|
84
|
-
ref=${this.childRef.ref}
|
|
85
|
-
@load=${this.loadHandle}
|
|
86
|
-
@say-hi=${this.onSayHi}
|
|
87
|
-
.message=${store.msg}
|
|
88
|
-
first-name="hello"
|
|
89
|
-
last-name="world"
|
|
90
|
-
count=${1}
|
|
91
|
-
disabled
|
|
92
|
-
>
|
|
93
|
-
<p slot=${Children.light}>now: ${store.now}</p>
|
|
94
|
-
</app-children>
|
|
95
|
-
`;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
document.addEventListener('say-hi', (e: CustomEvent) => {
|
|
100
|
-
console.log('`sayhi` target', e.composedPath()[0]);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
render(
|
|
104
|
-
html`
|
|
105
|
-
<gem-examples-layout>
|
|
106
|
-
<app-root app-title="I'm Title" slot="main"></app-root>
|
|
107
|
-
</gem-examples-layout>
|
|
108
|
-
`,
|
|
109
|
-
document.body,
|
|
110
|
-
);
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import { GemElement, html, customElement, refobject, RefObject, render } from '../../';
|
|
2
|
-
import { createModalClass } from '../../elements/modal-base';
|
|
3
|
-
import { DialogBaseElement } from '../../elements/dialog-base';
|
|
4
|
-
import '../../elements/link';
|
|
5
|
-
|
|
6
|
-
import '../elements/layout';
|
|
7
|
-
|
|
8
|
-
@customElement('app-confirm')
|
|
9
|
-
class Confirm extends createModalClass({
|
|
10
|
-
content: html``,
|
|
11
|
-
confirmHandle: () => {
|
|
12
|
-
/** */
|
|
13
|
-
},
|
|
14
|
-
}) {
|
|
15
|
-
label = 'confirm title';
|
|
16
|
-
|
|
17
|
-
confirm = () => {
|
|
18
|
-
Confirm.close();
|
|
19
|
-
Confirm.store.confirmHandle();
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
render() {
|
|
23
|
-
return html`
|
|
24
|
-
<style>
|
|
25
|
-
.root {
|
|
26
|
-
position: fixed;
|
|
27
|
-
z-index: 3;
|
|
28
|
-
top: 0;
|
|
29
|
-
left: 0;
|
|
30
|
-
width: 100%;
|
|
31
|
-
height: 100%;
|
|
32
|
-
background: rgba(0, 0, 0, 0.5);
|
|
33
|
-
}
|
|
34
|
-
.body {
|
|
35
|
-
position: absolute;
|
|
36
|
-
top: 50%;
|
|
37
|
-
left: 50%;
|
|
38
|
-
transform: translate(-50%, -50%);
|
|
39
|
-
width: 200px;
|
|
40
|
-
height: 100px;
|
|
41
|
-
background: white;
|
|
42
|
-
}
|
|
43
|
-
</style>
|
|
44
|
-
<div class="root" ?hidden=${!Confirm.isOpen}>
|
|
45
|
-
<div class="body">
|
|
46
|
-
<h2>${Confirm.store.content}</h2>
|
|
47
|
-
<button @click=${this.confirm}>close dialog</button>
|
|
48
|
-
</div>
|
|
49
|
-
</div>
|
|
50
|
-
`;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
@customElement('app-dialog')
|
|
55
|
-
class Dialog extends DialogBaseElement {
|
|
56
|
-
shouldClose = () => {
|
|
57
|
-
if (this.opened) {
|
|
58
|
-
Confirm.open({
|
|
59
|
-
content: html`Confirm?`,
|
|
60
|
-
confirmHandle: this.forceClose, // 不能使用 `close` 方法
|
|
61
|
-
});
|
|
62
|
-
return false;
|
|
63
|
-
} else {
|
|
64
|
-
return true;
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
render() {
|
|
69
|
-
return html`
|
|
70
|
-
<style>
|
|
71
|
-
:host {
|
|
72
|
-
display: none;
|
|
73
|
-
}
|
|
74
|
-
:host(:where(:--opened, [data-opened])) {
|
|
75
|
-
display: block;
|
|
76
|
-
}
|
|
77
|
-
.root {
|
|
78
|
-
position: fixed;
|
|
79
|
-
z-index: 2;
|
|
80
|
-
top: 0;
|
|
81
|
-
left: 0;
|
|
82
|
-
width: 100%;
|
|
83
|
-
height: 100%;
|
|
84
|
-
background: rgba(0, 0, 0, 0.5);
|
|
85
|
-
backdrop-filter: blur(5px);
|
|
86
|
-
}
|
|
87
|
-
.body {
|
|
88
|
-
position: absolute;
|
|
89
|
-
top: 50%;
|
|
90
|
-
left: 50%;
|
|
91
|
-
transform: translate(-50%, -50%);
|
|
92
|
-
width: 300px;
|
|
93
|
-
height: 200px;
|
|
94
|
-
background: white;
|
|
95
|
-
}
|
|
96
|
-
</style>
|
|
97
|
-
<div class="root">
|
|
98
|
-
<div class="body">
|
|
99
|
-
<h2>Dialog Title</h2>
|
|
100
|
-
<slot></slot>
|
|
101
|
-
<button @click=${this.close}>x</button>
|
|
102
|
-
</div>
|
|
103
|
-
</div>
|
|
104
|
-
`;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
@customElement('app-root')
|
|
109
|
-
export class Root extends GemElement {
|
|
110
|
-
@refobject dialog: RefObject<Dialog>;
|
|
111
|
-
|
|
112
|
-
state = {
|
|
113
|
-
modal: false,
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
clickHandle = () => {
|
|
117
|
-
this.dialog.element?.open();
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
render() {
|
|
121
|
-
return html`
|
|
122
|
-
<style>
|
|
123
|
-
:host {
|
|
124
|
-
font-size: x-large;
|
|
125
|
-
}
|
|
126
|
-
</style>
|
|
127
|
-
<button ?inert=${this.state.modal} @click="${this.clickHandle}">open dialog</button>
|
|
128
|
-
<app-dialog
|
|
129
|
-
label="dialog title"
|
|
130
|
-
ref=${this.dialog.ref}
|
|
131
|
-
@open=${() => this.setState({ modal: true })}
|
|
132
|
-
@close=${() => this.setState({ modal: false })}
|
|
133
|
-
>
|
|
134
|
-
<div>dialog body</div>
|
|
135
|
-
<gem-link path="/hi" style="cursor: pointer; color: blue">replace route</gem-link>
|
|
136
|
-
</app-dialog>
|
|
137
|
-
`;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
render(
|
|
142
|
-
html`
|
|
143
|
-
<gem-examples-layout>
|
|
144
|
-
<app-root slot="main"></app-root>
|
|
145
|
-
</gem-examples-layout>
|
|
146
|
-
`,
|
|
147
|
-
document.body,
|
|
148
|
-
);
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { GemElement, html, customElement, RefObject, refobject, render } from '../../';
|
|
2
|
-
|
|
3
|
-
import '../elements/layout';
|
|
4
|
-
|
|
5
|
-
function effect([textareaElement, callback]: [HTMLTextAreaElement | undefined, (height: number) => void]) {
|
|
6
|
-
if (!textareaElement) return callback(0);
|
|
7
|
-
const ro = new ResizeObserver(([entry]: [any]) => {
|
|
8
|
-
callback(entry.contentRect.height);
|
|
9
|
-
});
|
|
10
|
-
ro.observe(textareaElement, {});
|
|
11
|
-
return () => ro.disconnect();
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
@customElement('app-root')
|
|
15
|
-
export class App extends GemElement {
|
|
16
|
-
@refobject textAreaRef: RefObject<HTMLTextAreaElement>;
|
|
17
|
-
state = {
|
|
18
|
-
height: 0,
|
|
19
|
-
hidden: false,
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
#updateHeight = (height: number) => {
|
|
23
|
-
this.setState({ height });
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
render() {
|
|
27
|
-
return html`
|
|
28
|
-
<div><button @click=${() => this.setState({ hidden: !this.state.hidden })}>switch</button></div>
|
|
29
|
-
${this.state.hidden ? null : html`<textarea ref=${this.textAreaRef.ref}></textarea>`}
|
|
30
|
-
<div>${this.state.height}</div>
|
|
31
|
-
`;
|
|
32
|
-
}
|
|
33
|
-
mounted() {
|
|
34
|
-
this.effect(effect, () => [this.textAreaRef.element, this.#updateHeight]);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
render(
|
|
39
|
-
html`
|
|
40
|
-
<gem-examples-layout>
|
|
41
|
-
<app-root slot="main"></app-root>
|
|
42
|
-
</gem-examples-layout>
|
|
43
|
-
`,
|
|
44
|
-
document.body,
|
|
45
|
-
);
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
type Manifest = typeof import('../index/manifest.json');
|
|
2
|
-
|
|
3
|
-
export const MATADATA = process.env.METADATA as unknown as Record<string, Partial<Manifest>>;
|
|
4
|
-
export const EXAMPLES = process.env.EXAMPLES as unknown as string[];
|
|
5
|
-
export const EXAMPLE = process.env.EXAMPLE as string;
|
|
6
|
-
export const FILES = process.env.FILES as unknown as string[];
|
|
7
|
-
export const PATH = process.env.TAEGET === 'pages' && EXAMPLE !== 'index' ? EXAMPLE : '';
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { GemElement, html } from '../../lib/element';
|
|
2
|
-
import { customElement, slot } from '../../lib/decorators';
|
|
3
|
-
import '../../elements/reflect';
|
|
4
|
-
import '../../elements/title';
|
|
5
|
-
|
|
6
|
-
import { MATADATA, EXAMPLE } from './env';
|
|
7
|
-
import './nav';
|
|
8
|
-
import './source';
|
|
9
|
-
|
|
10
|
-
@customElement('gem-examples-layout')
|
|
11
|
-
export class Layout extends GemElement {
|
|
12
|
-
@slot main: string;
|
|
13
|
-
|
|
14
|
-
render() {
|
|
15
|
-
return html`
|
|
16
|
-
<gem-title suffix=" - Gem Examples" hidden>${MATADATA[EXAMPLE].name || EXAMPLE}</gem-title>
|
|
17
|
-
<gem-reflect>
|
|
18
|
-
<style>
|
|
19
|
-
body {
|
|
20
|
-
margin: 0;
|
|
21
|
-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans',
|
|
22
|
-
sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
|
|
23
|
-
}
|
|
24
|
-
</style>
|
|
25
|
-
</gem-reflect>
|
|
26
|
-
<style>
|
|
27
|
-
:host {
|
|
28
|
-
display: grid;
|
|
29
|
-
grid-template-areas: 'nav main' 'nav source';
|
|
30
|
-
grid-template-columns: 260px 1fr;
|
|
31
|
-
grid-template-rows: 1fr 400px;
|
|
32
|
-
height: 100vh;
|
|
33
|
-
}
|
|
34
|
-
::slotted(*) {
|
|
35
|
-
overflow: auto;
|
|
36
|
-
padding: 2em;
|
|
37
|
-
}
|
|
38
|
-
@media (max-width: 480px) {
|
|
39
|
-
:host {
|
|
40
|
-
display: block;
|
|
41
|
-
}
|
|
42
|
-
gem-examples-nav,
|
|
43
|
-
gem-examples-source {
|
|
44
|
-
display: none;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
</style>
|
|
48
|
-
<gem-examples-nav></gem-examples-nav>
|
|
49
|
-
<slot name=${this.main}></slot>
|
|
50
|
-
<gem-examples-source></gem-examples-source>
|
|
51
|
-
`;
|
|
52
|
-
}
|
|
53
|
-
}
|