@mantou/gem 1.7.5 → 1.7.7

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.
Files changed (45) hide show
  1. package/dist/gem.es.js +59 -50
  2. package/dist/gem.umd.js +23 -23
  3. package/elements/base/modal-factory.d.ts +2 -1
  4. package/elements/base/modal-factory.d.ts.map +1 -1
  5. package/elements/base/route.d.ts +1 -1
  6. package/elements/base/route.d.ts.map +1 -1
  7. package/elements/base/title.d.ts +3 -1
  8. package/elements/base/title.d.ts.map +1 -1
  9. package/elements/base/title.js +15 -16
  10. package/elements/base/title.js.map +1 -1
  11. package/helper/theme.d.ts +3 -0
  12. package/helper/theme.d.ts.map +1 -1
  13. package/helper/theme.js +6 -0
  14. package/helper/theme.js.map +1 -1
  15. package/lib/element.d.ts +1 -1
  16. package/lib/element.d.ts.map +1 -1
  17. package/lib/element.js +16 -18
  18. package/lib/element.js.map +1 -1
  19. package/lib/history.d.ts.map +1 -1
  20. package/lib/history.js +18 -13
  21. package/lib/history.js.map +1 -1
  22. package/lib/store.d.ts +2 -9
  23. package/lib/store.d.ts.map +1 -1
  24. package/lib/store.js +7 -9
  25. package/lib/store.js.map +1 -1
  26. package/lib/utils.d.ts +21 -4
  27. package/lib/utils.d.ts.map +1 -1
  28. package/lib/utils.js +87 -1
  29. package/lib/utils.js.map +1 -1
  30. package/lib/version.d.ts +1 -1
  31. package/lib/version.js +1 -1
  32. package/package.json +11 -7
  33. package/src/elements/base/route.ts +1 -1
  34. package/src/elements/base/title.ts +14 -11
  35. package/src/helper/theme.ts +7 -0
  36. package/src/lib/element.ts +10 -10
  37. package/src/lib/history.ts +18 -13
  38. package/src/lib/store.ts +7 -17
  39. package/src/lib/utils.ts +102 -5
  40. package/src/lib/version.ts +1 -1
  41. package/src/test/gem-element/advance.test.ts +12 -1
  42. package/src/test/gem-element/decorators.test.ts +17 -21
  43. package/src/test/gem-element/multi.test.ts +8 -5
  44. package/src/test/store.test.ts +1 -3
  45. package/src/test/utils.test.ts +24 -0
@@ -1,3 +1,11 @@
1
+ /**
2
+ * 测试 HTMLElement 没有的特性或者不常用的特性
3
+ * - 异步渲染
4
+ * - Light DOM 自定义元素
5
+ * - 生命周期以及 Effect/Memo
6
+ * - 派生元素(类扩展)
7
+ * - 无渲染内容 Gem 元素
8
+ */
1
9
  import { fixture, expect, nextFrame } from '@open-wc/testing';
2
10
 
3
11
  import { GemElement, html } from '../../lib/element';
@@ -120,7 +128,10 @@ describe('gem element 生命周期', () => {
120
128
  const el = container.firstElementChild as LifecycleGemElement;
121
129
  expect(el.appTitle).to.equal('title');
122
130
  expect(el.renderCount).to.equal(1);
123
- expect((el.cloneNode() as LifecycleGemElement).appTitle).to.equal('title');
131
+ const clone = el.cloneNode() as LifecycleGemElement;
132
+ // BUG
133
+ clone.connectedCallback();
134
+ expect(clone.appTitle).to.equal('title');
124
135
 
125
136
  const el2 = new LifecycleGemElement('', '2');
126
137
  expect(el2.appTitle).to.equal('');
@@ -51,20 +51,24 @@ class DecoratorGemElement extends GemElement {
51
51
  }
52
52
  }
53
53
 
54
- @connectStore(store)
55
- @adoptedStyle(styles)
56
- @customElement('decorator-gem-demo2')
57
- class DecoratorGemElement2 extends GemElement {
58
- static observedStores = [];
59
- static adoptedStyleSheets = [];
60
- renderCount = 0;
61
- render() {
62
- this.renderCount++;
63
- return html``;
64
- }
65
- }
66
-
67
54
  describe('装饰器', () => {
55
+ it('使用装饰器定义的未插入文档元素', async () => {
56
+ const el = new DecoratorGemElement();
57
+ expect(el.propData).to.eql({ value: '' });
58
+ expect(el.getAttribute('rank-attr')).to.equal(null);
59
+ // BUG
60
+ expect(el.rankAttr).to.equal(undefined);
61
+ el.connectedCallback();
62
+ expect(el.getAttribute('rank-attr')).to.equal(null);
63
+ expect(el.rankAttr).to.equal('');
64
+
65
+ el.rankAttr = 'attr';
66
+ el.propData = { value: '1' };
67
+ const el2 = el.cloneNode() as DecoratorGemElement;
68
+ expect(el2.getAttribute('rank-attr')).to.equal('attr');
69
+ expect(el2.rankAttr).to.equal('attr');
70
+ expect(el2.propData).to.eql({ value: '' });
71
+ });
68
72
  it('装饰器定义的自定义元素', async () => {
69
73
  let a = 1;
70
74
  const el: DecoratorGemElement = await fixture(html`
@@ -104,12 +108,4 @@ describe('装饰器', () => {
104
108
  expect(el.renderCount).to.equal(3);
105
109
  expect(a).to.equal(2);
106
110
  });
107
-
108
- it('装饰器和静态属性共存', async () => {
109
- const el: DecoratorGemElement2 = await fixture(html`<decorator-gem-demo2></decorator-gem-demo2>`);
110
- updateStore(store, { a: 3 });
111
- await Promise.resolve();
112
- expect(el.renderCount).to.equal(2);
113
- expect(el.shadowRoot?.adoptedStyleSheets.length).to.equal(1);
114
- });
115
111
  });
@@ -1,12 +1,13 @@
1
1
  import { expect, fixture } from '@open-wc/testing';
2
2
 
3
- import { customElement, property, RefObject, refobject } from '../../lib/decorators';
3
+ import { attribute, customElement, property, RefObject, refobject } from '../../lib/decorators';
4
4
  import { GemElement, html } from '../../lib/element';
5
5
 
6
6
  @customElement('app-children')
7
7
  export class Children extends GemElement {
8
8
  @refobject inputRef: RefObject<HTMLInputElement>;
9
9
  @property value?: { value: number };
10
+ @attribute attr: string;
10
11
 
11
12
  render() {
12
13
  return html`<input ref=${this.inputRef.ref} />`;
@@ -19,13 +20,13 @@ export class App extends GemElement {
19
20
  @refobject childrenRef2: RefObject<Children>;
20
21
  render() {
21
22
  return html`
22
- <app-children ref=${this.childrenRef1.ref} .value=${{ value: 1 }}></app-children>
23
- <app-children ref=${this.childrenRef2.ref} .value=${{ value: 2 }}></app-children>
23
+ <app-children ref=${this.childrenRef1.ref} .value=${{ value: 1 }} attr="1"></app-children>
24
+ <app-children ref=${this.childrenRef2.ref} .value=${{ value: 2 }} attr="2"></app-children>
24
25
  `;
25
26
  }
26
27
  }
27
- describe('多个 gem element', () => {
28
- it('ref & prop', async () => {
28
+ describe('多个 gem element 一起工作', () => {
29
+ it('ref & prop & attr', async () => {
29
30
  const el: App = await fixture(html`<app-root></app-root>`);
30
31
  const children1 = el.childrenRef1.element!;
31
32
  const children2 = el.childrenRef2.element!;
@@ -34,5 +35,7 @@ describe('多个 gem element', () => {
34
35
  expect(input1 !== input2).to.equal(true);
35
36
  expect(children1.value).to.eql({ value: 1 });
36
37
  expect(children2.value).to.eql({ value: 2 });
38
+ expect(children1.attr).to.eql('1');
39
+ expect(children2.attr).to.eql('2');
37
40
  });
38
41
  });
@@ -1,6 +1,6 @@
1
1
  import { expect, aTimeout } from '@open-wc/testing';
2
2
 
3
- import { StoreListenerMap, createStore, createStoreSet, updateStore, connect, disconnect } from '../lib/store';
3
+ import { StoreListenerMap, createStore, updateStore, connect, disconnect } from '../lib/store';
4
4
 
5
5
  describe('store 测试', () => {
6
6
  it('create store', () => {
@@ -8,8 +8,6 @@ describe('store 测试', () => {
8
8
  const store = createStore(origin);
9
9
  expect(store).to.equal(origin);
10
10
  expect(!!StoreListenerMap.get(store)).to.equal(true);
11
- const stores = createStoreSet({ a: {} });
12
- expect(!!StoreListenerMap.get(stores.a)).to.equal(true);
13
11
  });
14
12
  it('update store', async () => {
15
13
  const store = createStore({ a: 1 });
@@ -110,4 +110,28 @@ describe('utils 测试', () => {
110
110
  expect(exportPartsMap({ foo: 'bar', content: 'content', false: false })).to.equal(`,foo:bar,content,`);
111
111
  expect(exportPartsMap({ foo: 'bar', content: true })).to.equal(`,foo:bar,content,`);
112
112
  });
113
+ // it('createCSSAnimation', () => {
114
+ // expect(createCSSAnimation([{ opacity: 0 }])).to.equal('100%{;opacity:0;}');
115
+ // expect(createCSSAnimation([{ opacity: 1 }, { opacity: 0 }])).to.equal('0%{;opacity:1;}100%{;opacity:0;}');
116
+ // expect(createCSSAnimation([{ opacity: 1 }, { opacity: 0.1, offset: 0.7 }, { opacity: 0 }])).to.equal(
117
+ // '0%{;opacity:1;}70%{;opacity:0.1;}100%{;opacity:0;}',
118
+ // );
119
+ // expect(createCSSAnimation({ opacity: [0] })).to.equal('100%{;opacity:0;}');
120
+ // expect(createCSSAnimation({ opacity: [1, 0] })).to.equal('0%{;opacity:1;}100%{;opacity:0;}');
121
+ // expect(createCSSAnimation({ opacity: [1, 0], offset: [0, 0.7] })).to.equal(
122
+ // '0%{;opacity:1;}70%{;opacity:0;}100%{;}',
123
+ // );
124
+ // expect(createCSSAnimation({ opacity: [1, 0], backgroundColor: ['red', 'yellow', 'green'] })).to.equal(
125
+ // '0%{;opacity:1;background-color:red;}100%{;opacity:0;background-color:green;}50%{;background-color:yellow;}',
126
+ // );
127
+ // expect(
128
+ // createCSSAnimation({
129
+ // opacity: [1, 0],
130
+ // backgroundColor: ['red', 'yellow', 'green'],
131
+ // offset: [0, 0.7],
132
+ // }),
133
+ // ).to.equal(
134
+ // '0%{;opacity:1;background-color:red;}70%{;opacity:0;background-color:yellow;}100%{;background-color:green;}',
135
+ // );
136
+ // });
113
137
  });