@lexriver/dome 1.3.0 → 1.4.0

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 CHANGED
@@ -1607,6 +1607,7 @@ export class AnimatedListTest extends DomeComponent<Attrs>{
1607
1607
  getHtmlElement: (x:number) => { // render element
1608
1608
  return <div>the number is {x}</div>
1609
1609
  },
1610
+ emptyList:<div>Loading</div>
1610
1611
  })
1611
1612
 
1612
1613
  render(){
package/jest.config.js CHANGED
File without changes
@@ -1,27 +1,29 @@
1
- import { Animation } from './Animation';
2
- interface KeyToElementPair {
3
- key: string;
4
- element: HTMLElement;
5
- }
6
- export declare class AnimatedArray<T> {
7
- protected params: {
8
- parentElement?: HTMLElement;
9
- array?: T[];
10
- getKey: (o: T) => string;
11
- getHtmlElement: (o: T) => HTMLElement;
12
- animationShow?: Animation;
13
- animationHide?: Animation;
14
- };
15
- arrayOfKeyToElement: KeyToElementPair[];
16
- constructor(params: {
17
- parentElement?: HTMLElement;
18
- array?: T[];
19
- getKey: (o: T) => string;
20
- getHtmlElement: (o: T) => HTMLElement;
21
- animationShow?: Animation;
22
- animationHide?: Animation;
23
- });
24
- get size(): number;
25
- update(array: T[], parentElement?: HTMLElement | Element): void;
26
- }
27
- export {};
1
+ import { Animation } from './Animation';
2
+ interface KeyToElementPair {
3
+ key: string;
4
+ element: HTMLElement;
5
+ }
6
+ export declare class AnimatedArray<T> {
7
+ protected params: {
8
+ parentElement?: HTMLElement;
9
+ array?: T[];
10
+ getKey: (o: T) => string;
11
+ getHtmlElement: (o: T) => HTMLElement;
12
+ animationShow?: Animation;
13
+ animationHide?: Animation;
14
+ emptyList?: HTMLElement;
15
+ };
16
+ arrayOfKeyToElement: KeyToElementPair[];
17
+ constructor(params: {
18
+ parentElement?: HTMLElement;
19
+ array?: T[];
20
+ getKey: (o: T) => string;
21
+ getHtmlElement: (o: T) => HTMLElement;
22
+ animationShow?: Animation;
23
+ animationHide?: Animation;
24
+ emptyList?: HTMLElement;
25
+ });
26
+ get size(): number;
27
+ update(array: T[], parentElement?: HTMLElement | Element): void;
28
+ }
29
+ export {};
@@ -1,44 +1,51 @@
1
- import { DomeManipulator } from "./DomeManipulator";
2
- import { LongestCommonSubsequence } from "./LongestCommonSubsequence";
3
- export class AnimatedArray {
4
- constructor(params) {
5
- this.params = params;
6
- this.arrayOfKeyToElement = [];
7
- if (params.array && params.parentElement) {
8
- this.update(params.array);
9
- }
10
- }
11
- get size() {
12
- return this.arrayOfKeyToElement.length;
13
- }
14
- update(array, parentElement) {
15
- parentElement = parentElement || this.params.parentElement;
16
- if (!parentElement) {
17
- console.warn('AnimatedArray unable to update, no parentElement');
18
- return;
19
- }
20
- //let arrayOfKeyToElement:KeyToElementPair[] = []
21
- let newArrayOfKeys = array.map((item) => this.params.getKey(item));
22
- let oldArrayOfKeys = this.arrayOfKeyToElement.map(x => x.key);
23
- LongestCommonSubsequence.getPatchOrdered({
24
- oldArray: oldArrayOfKeys,
25
- newArray: newArrayOfKeys,
26
- onAdd: (index, key) => {
27
- if (!parentElement)
28
- throw new Error('no parent element'); //TODO: remove this
29
- let itemIndex = newArrayOfKeys.indexOf(key);
30
- if (itemIndex == -1)
31
- throw new Error('no itemIndex'); //TODO: remove this
32
- let item = array[itemIndex];
33
- let element = this.params.getHtmlElement(item);
34
- this.arrayOfKeyToElement.splice(index, 0, { key, element });
35
- DomeManipulator.insertByIndexAsync(element, index, parentElement, this.params.animationShow);
36
- //this.insertNewElementWithAnimation(element, index, parentElement)
37
- },
38
- onRemove: (index, key) => {
39
- DomeManipulator.removeElementAsync(this.arrayOfKeyToElement[index].element, this.params.animationHide);
40
- this.arrayOfKeyToElement.splice(index, 1);
41
- }
42
- });
43
- }
44
- }
1
+ import { DomeManipulator } from "./DomeManipulator";
2
+ import { LongestCommonSubsequence } from "./LongestCommonSubsequence";
3
+ export class AnimatedArray {
4
+ constructor(params) {
5
+ this.params = params;
6
+ this.arrayOfKeyToElement = [];
7
+ if (params.array && params.parentElement) {
8
+ this.update(params.array);
9
+ }
10
+ }
11
+ get size() {
12
+ return this.arrayOfKeyToElement.length;
13
+ }
14
+ update(array, parentElement) {
15
+ parentElement = parentElement || this.params.parentElement;
16
+ if (!parentElement) {
17
+ console.warn('AnimatedArray unable to update, no parentElement');
18
+ return;
19
+ }
20
+ if (array.length == 0 && this.params.emptyList) {
21
+ DomeManipulator.replaceAllChildrenAsync(parentElement, this.params.emptyList);
22
+ return;
23
+ }
24
+ if (array.length > 0 && this.params.emptyList) {
25
+ DomeManipulator.removeElementAsync(this.params.emptyList, this.params.animationHide);
26
+ }
27
+ //let arrayOfKeyToElement:KeyToElementPair[] = []
28
+ let newArrayOfKeys = array.map((item) => this.params.getKey(item));
29
+ let oldArrayOfKeys = this.arrayOfKeyToElement.map(x => x.key);
30
+ LongestCommonSubsequence.getPatchOrdered({
31
+ oldArray: oldArrayOfKeys,
32
+ newArray: newArrayOfKeys,
33
+ onAdd: (index, key) => {
34
+ if (!parentElement)
35
+ throw new Error('no parent element'); //TODO: remove this
36
+ let itemIndex = newArrayOfKeys.indexOf(key);
37
+ if (itemIndex == -1)
38
+ throw new Error('no itemIndex'); //TODO: remove this
39
+ let item = array[itemIndex];
40
+ let element = this.params.getHtmlElement(item);
41
+ this.arrayOfKeyToElement.splice(index, 0, { key, element });
42
+ DomeManipulator.insertByIndexAsync(element, index, parentElement, this.params.animationShow);
43
+ //this.insertNewElementWithAnimation(element, index, parentElement)
44
+ },
45
+ onRemove: (index, key) => {
46
+ DomeManipulator.removeElementAsync(this.arrayOfKeyToElement[index].element, this.params.animationHide);
47
+ this.arrayOfKeyToElement.splice(index, 1);
48
+ }
49
+ });
50
+ }
51
+ }
@@ -1,38 +1,38 @@
1
- import { DomeComponent, AnimatedArray } from ".";
2
- import { Animation } from './Animation';
3
- import { ObservableValue } from '@lexriver/observable';
4
- interface Attrs<T> {
5
- isLoadingO?: ObservableValue<boolean>;
6
- itemsO: ObservableValue<T[]>;
7
- animationShowRow: Animation;
8
- animationHideRow: Animation;
9
- animationHideTable?: Animation;
10
- animationShowTable?: Animation;
11
- animationHideEmptyList?: Animation;
12
- animationShowEmptyList?: Animation;
13
- animationShowLoading?: Animation;
14
- animationHideLoading?: Animation;
15
- getKey: (item: T) => string;
16
- rootElement?: HTMLElement;
17
- tableElement?: HTMLElement;
18
- tableBody?: HTMLElement;
19
- renderTableHead?: (items: T[]) => HTMLElement;
20
- renderTableRow: (item: T) => HTMLElement;
21
- renderTableFooter?: (items: T[]) => HTMLElement;
22
- renderEmptyList: () => HTMLElement;
23
- renderLoading?: () => HTMLElement;
24
- }
25
- export declare class AnimatedTable<T> extends DomeComponent<Attrs<T>> {
26
- refRoot: HTMLElement;
27
- refTable: HTMLElement;
28
- refTableHead: Element;
29
- refTableBody: HTMLElement;
30
- refTableFooter: Element;
31
- refEmptyList: Element;
32
- refLoading: Element;
33
- animatedArray: AnimatedArray<T>;
34
- render(): HTMLElement;
35
- afterRender(): void;
36
- updateAsync(): Promise<void>;
37
- }
38
- export {};
1
+ import { DomeComponent, AnimatedArray } from ".";
2
+ import { Animation } from './Animation';
3
+ import { ObservableValue } from '@lexriver/observable';
4
+ interface Attrs<T> {
5
+ isLoadingO?: ObservableValue<boolean>;
6
+ itemsO: ObservableValue<T[]>;
7
+ animationShowRow: Animation;
8
+ animationHideRow: Animation;
9
+ animationHideTable?: Animation;
10
+ animationShowTable?: Animation;
11
+ animationHideEmptyList?: Animation;
12
+ animationShowEmptyList?: Animation;
13
+ animationShowLoading?: Animation;
14
+ animationHideLoading?: Animation;
15
+ getKey: (item: T) => string;
16
+ rootElement?: HTMLElement;
17
+ tableElement?: HTMLElement;
18
+ tableBody?: HTMLElement;
19
+ renderTableHead?: (items: T[]) => HTMLElement;
20
+ renderTableRow: (item: T) => HTMLElement;
21
+ renderTableFooter?: (items: T[]) => HTMLElement;
22
+ renderEmptyList: () => HTMLElement;
23
+ renderLoading?: () => HTMLElement;
24
+ }
25
+ export declare class AnimatedTable<T> extends DomeComponent<Attrs<T>> {
26
+ refRoot: HTMLElement;
27
+ refTable: HTMLElement;
28
+ refTableHead: Element;
29
+ refTableBody: HTMLElement;
30
+ refTableFooter: Element;
31
+ refEmptyList: Element;
32
+ refLoading: Element;
33
+ animatedArray: AnimatedArray<T>;
34
+ render(): HTMLElement;
35
+ afterRender(): void;
36
+ updateAsync(): Promise<void>;
37
+ }
38
+ export {};
@@ -1,91 +1,91 @@
1
- import { DomeComponent, AnimatedArray } from ".";
2
- import { DomeManipulator } from "./DomeManipulator";
3
- export class AnimatedTable extends DomeComponent {
4
- constructor() {
5
- super(...arguments);
6
- // rootElement
7
- // table
8
- // thead
9
- // tbody
10
- // tfooter
11
- // emptyList
12
- this.refRoot = this.attrs.rootElement || document.createElement('div');
13
- this.refTable = this.attrs.tableElement || document.createElement('table');
14
- this.refTableHead = this.attrs.renderTableHead ? this.attrs.renderTableHead(this.attrs.itemsO.get()) : document.createElement('thead');
15
- this.refTableBody = this.attrs.tableBody || document.createElement('tbody');
16
- this.refTableFooter = this.attrs.renderTableFooter ? this.attrs.renderTableFooter(this.attrs.itemsO.get()) : document.createElement('tfoot');
17
- this.refEmptyList = this.attrs.renderEmptyList ? this.attrs.renderEmptyList() : document.createElement('div');
18
- this.refLoading = this.attrs.renderLoading ? this.attrs.renderLoading() : document.createElement('div');
19
- this.animatedArray = new AnimatedArray({
20
- animationHide: this.attrs.animationHideRow,
21
- animationShow: this.attrs.animationShowRow,
22
- array: [],
23
- getKey: this.attrs.getKey,
24
- getHtmlElement: this.attrs.renderTableRow
25
- });
26
- }
27
- render() {
28
- // refRoot
29
- // refTable
30
- // refTableHead
31
- // refTableBody
32
- // refTableFooter
33
- // refEmptyListEl
34
- // refLoading
35
- this.refRoot.appendChild(this.refTable);
36
- this.refRoot.appendChild(this.refEmptyList);
37
- this.refRoot.appendChild(this.refLoading);
38
- if (this.refTableHead)
39
- this.refTable.appendChild(this.refTableHead);
40
- if (this.refTableBody)
41
- this.refTable.appendChild(this.refTableBody);
42
- if (this.refTableFooter)
43
- this.refTable.appendChild(this.refTableFooter);
44
- console.log('AnimatedTable render()', 'refRoot=', this.refRoot);
45
- return this.refRoot;
46
- }
47
- afterRender() {
48
- this.updateAsync();
49
- //this.animatedArray.update(this.attrs.items, this.el)
50
- }
51
- async updateAsync() {
52
- try {
53
- if (this.attrs.renderLoading) {
54
- this.refLoading = await DomeManipulator.replaceAsync(this.refLoading, this.attrs.renderLoading());
55
- }
56
- if (this.attrs.isLoadingO && this.attrs.isLoadingO.get()) {
57
- // show loading
58
- await DomeManipulator.unhideElementAsync(this.refLoading, this.attrs.animationShowLoading);
59
- }
60
- else {
61
- // hide loading
62
- await DomeManipulator.hideElementAsync(this.refLoading, this.attrs.animationHideLoading);
63
- }
64
- const items = this.attrs.itemsO.get();
65
- const currentCount = items.length;
66
- if (currentCount == 0) {
67
- // render empty list
68
- await DomeManipulator.hideElementAsync(this.refTable, this.attrs.animationHideTable);
69
- if (this.attrs.renderEmptyList) {
70
- this.refEmptyList = await DomeManipulator.replaceAsync(this.refEmptyList, this.attrs.renderEmptyList());
71
- }
72
- await DomeManipulator.unhideElementAsync(this.refEmptyList, this.attrs.animationShowEmptyList);
73
- }
74
- else {
75
- // render list with items
76
- await DomeManipulator.hideElementAsync(this.refEmptyList, this.attrs.animationHideEmptyList);
77
- if (this.attrs.renderTableHead) {
78
- this.refTableHead = await DomeManipulator.replaceAsync(this.refTableHead, this.attrs.renderTableHead(items));
79
- }
80
- if (this.attrs.renderTableFooter) {
81
- this.refTableFooter = await DomeManipulator.replaceAsync(this.refTableFooter, this.attrs.renderTableFooter(items));
82
- }
83
- await DomeManipulator.unhideElementAsync(this.refTable, this.attrs.animationShowTable);
84
- this.animatedArray.update(items, this.refTableBody);
85
- }
86
- }
87
- catch (x) {
88
- console.error('AnimatedTable update failed', x);
89
- }
90
- }
91
- }
1
+ import { DomeComponent, AnimatedArray } from ".";
2
+ import { DomeManipulator } from "./DomeManipulator";
3
+ export class AnimatedTable extends DomeComponent {
4
+ constructor() {
5
+ super(...arguments);
6
+ // rootElement
7
+ // table
8
+ // thead
9
+ // tbody
10
+ // tfooter
11
+ // emptyList
12
+ this.refRoot = this.attrs.rootElement || document.createElement('div');
13
+ this.refTable = this.attrs.tableElement || document.createElement('table');
14
+ this.refTableHead = this.attrs.renderTableHead ? this.attrs.renderTableHead(this.attrs.itemsO.get()) : document.createElement('thead');
15
+ this.refTableBody = this.attrs.tableBody || document.createElement('tbody');
16
+ this.refTableFooter = this.attrs.renderTableFooter ? this.attrs.renderTableFooter(this.attrs.itemsO.get()) : document.createElement('tfoot');
17
+ this.refEmptyList = this.attrs.renderEmptyList ? this.attrs.renderEmptyList() : document.createElement('div');
18
+ this.refLoading = this.attrs.renderLoading ? this.attrs.renderLoading() : document.createElement('div');
19
+ this.animatedArray = new AnimatedArray({
20
+ animationHide: this.attrs.animationHideRow,
21
+ animationShow: this.attrs.animationShowRow,
22
+ array: [],
23
+ getKey: this.attrs.getKey,
24
+ getHtmlElement: this.attrs.renderTableRow
25
+ });
26
+ }
27
+ render() {
28
+ // refRoot
29
+ // refTable
30
+ // refTableHead
31
+ // refTableBody
32
+ // refTableFooter
33
+ // refEmptyListEl
34
+ // refLoading
35
+ this.refRoot.appendChild(this.refTable);
36
+ this.refRoot.appendChild(this.refEmptyList);
37
+ this.refRoot.appendChild(this.refLoading);
38
+ if (this.refTableHead)
39
+ this.refTable.appendChild(this.refTableHead);
40
+ if (this.refTableBody)
41
+ this.refTable.appendChild(this.refTableBody);
42
+ if (this.refTableFooter)
43
+ this.refTable.appendChild(this.refTableFooter);
44
+ console.log('AnimatedTable render()', 'refRoot=', this.refRoot);
45
+ return this.refRoot;
46
+ }
47
+ afterRender() {
48
+ this.updateAsync();
49
+ //this.animatedArray.update(this.attrs.items, this.el)
50
+ }
51
+ async updateAsync() {
52
+ try {
53
+ if (this.attrs.renderLoading) {
54
+ this.refLoading = await DomeManipulator.replaceAsync(this.refLoading, this.attrs.renderLoading());
55
+ }
56
+ if (this.attrs.isLoadingO && this.attrs.isLoadingO.get()) {
57
+ // show loading
58
+ await DomeManipulator.unhideElementAsync(this.refLoading, this.attrs.animationShowLoading);
59
+ }
60
+ else {
61
+ // hide loading
62
+ await DomeManipulator.hideElementAsync(this.refLoading, this.attrs.animationHideLoading);
63
+ }
64
+ const items = this.attrs.itemsO.get();
65
+ const currentCount = items.length;
66
+ if (currentCount == 0) {
67
+ // render empty list
68
+ await DomeManipulator.hideElementAsync(this.refTable, this.attrs.animationHideTable);
69
+ if (this.attrs.renderEmptyList) {
70
+ this.refEmptyList = await DomeManipulator.replaceAsync(this.refEmptyList, this.attrs.renderEmptyList());
71
+ }
72
+ await DomeManipulator.unhideElementAsync(this.refEmptyList, this.attrs.animationShowEmptyList);
73
+ }
74
+ else {
75
+ // render list with items
76
+ await DomeManipulator.hideElementAsync(this.refEmptyList, this.attrs.animationHideEmptyList);
77
+ if (this.attrs.renderTableHead) {
78
+ this.refTableHead = await DomeManipulator.replaceAsync(this.refTableHead, this.attrs.renderTableHead(items));
79
+ }
80
+ if (this.attrs.renderTableFooter) {
81
+ this.refTableFooter = await DomeManipulator.replaceAsync(this.refTableFooter, this.attrs.renderTableFooter(items));
82
+ }
83
+ await DomeManipulator.unhideElementAsync(this.refTable, this.attrs.animationShowTable);
84
+ this.animatedArray.update(items, this.refTableBody);
85
+ }
86
+ }
87
+ catch (x) {
88
+ console.error('AnimatedTable update failed', x);
89
+ }
90
+ }
91
+ }
@@ -1,13 +1,13 @@
1
- import { ObservableValue } from "@lexriver/observable";
2
- import { DomeComponent } from ".";
3
- import { CssClass } from "./DomeManipulator";
4
- interface Attrs {
5
- textO: ObservableValue<string>;
6
- tag?: string;
7
- class?: CssClass;
8
- }
9
- export declare class AnimatedText extends DomeComponent<Attrs> {
10
- render(): HTMLElement;
11
- updateAsync(): Promise<void>;
12
- }
13
- export {};
1
+ import { ObservableValue } from "@lexriver/observable";
2
+ import { DomeComponent } from ".";
3
+ import { CssClass } from "./DomeManipulator";
4
+ interface Attrs {
5
+ textO: ObservableValue<string>;
6
+ tag?: string;
7
+ class?: CssClass;
8
+ }
9
+ export declare class AnimatedText extends DomeComponent<Attrs> {
10
+ render(): HTMLElement;
11
+ updateAsync(): Promise<void>;
12
+ }
13
+ export {};
@@ -1,24 +1,24 @@
1
- import { DomeComponent } from ".";
2
- import { DomeManipulator } from "./DomeManipulator";
3
- export class AnimatedText extends DomeComponent {
4
- render() {
5
- //const result = this.attrs.tag ? document.createElement(this.attrs.tag) : document.createElement('span')
6
- const result = document.createElement(this.attrs.tag || 'span');
7
- //console.log('AnimatedText', 'this.attrs.class=',this.attrs.class)
8
- if (this.attrs.class) {
9
- DomeManipulator.setCssClasses(result, this.attrs.class);
10
- }
11
- result.append(this.attrs.textO.get());
12
- return result;
13
- }
14
- async updateAsync() {
15
- if (!this.rootElement)
16
- return;
17
- try {
18
- this.rootElement = await DomeManipulator.replaceAsync(this.rootElement, this.render(), this.attrs.onHideAnimation, this.attrs.onShowAnimation);
19
- }
20
- catch (x) {
21
- console.error('AnimatedText update failed', x);
22
- }
23
- }
24
- }
1
+ import { DomeComponent } from ".";
2
+ import { DomeManipulator } from "./DomeManipulator";
3
+ export class AnimatedText extends DomeComponent {
4
+ render() {
5
+ //const result = this.attrs.tag ? document.createElement(this.attrs.tag) : document.createElement('span')
6
+ const result = document.createElement(this.attrs.tag || 'span');
7
+ //console.log('AnimatedText', 'this.attrs.class=',this.attrs.class)
8
+ if (this.attrs.class) {
9
+ DomeManipulator.setCssClasses(result, this.attrs.class);
10
+ }
11
+ result.append(this.attrs.textO.get());
12
+ return result;
13
+ }
14
+ async updateAsync() {
15
+ if (!this.rootElement)
16
+ return;
17
+ try {
18
+ this.rootElement = await DomeManipulator.replaceAsync(this.rootElement, this.render(), this.attrs.onHideAnimation, this.attrs.onShowAnimation);
19
+ }
20
+ catch (x) {
21
+ console.error('AnimatedText update failed', x);
22
+ }
23
+ }
24
+ }
@@ -1,4 +1,4 @@
1
- export interface Animation {
2
- cssClassName: string;
3
- timeMs: number;
4
- }
1
+ export interface Animation {
2
+ cssClassName: string;
3
+ timeMs: number;
4
+ }
package/out/Animation.js CHANGED
File without changes
package/out/Dome.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- export declare function h(tagName: any, attrs: any, ...childrenArgs: any[]): any;
2
- export declare const React: {
3
- createElement: typeof h;
4
- Fragment: {
5
- new (): DocumentFragment;
6
- prototype: DocumentFragment;
7
- } | (() => void);
8
- };
9
- export default React;
1
+ export declare function h(tagName: any, attrs: any, ...childrenArgs: any[]): any;
2
+ export declare const React: {
3
+ createElement: typeof h;
4
+ Fragment: {
5
+ new (): DocumentFragment;
6
+ prototype: DocumentFragment;
7
+ } | (() => void);
8
+ };
9
+ export default React;