@lexriver/dome 2.0.2 → 2.0.3
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/out/index.cjs +802 -0
- package/out/index.mjs +1987 -0
- package/out/src/AnimatedArray.d.ts +29 -0
- package/out/src/AnimatedTable.d.mts +2 -1
- package/out/src/AnimatedTable.d.ts +39 -0
- package/out/src/AnimatedTable.mjs +2 -1
- package/out/src/AnimatedText.d.mts +1 -1
- package/out/src/AnimatedText.d.ts +13 -0
- package/out/src/AnimatedText.mjs +1 -1
- package/out/src/Animation.d.ts +4 -0
- package/out/src/Dome.d.ts +9 -0
- package/out/src/Dome.mjs +1 -1
- package/out/src/DomeComponent.d.ts +25 -0
- package/out/src/DomeManipulator.d.ts +52 -0
- package/out/src/DomeRouter.console-test.d.ts +1 -0
- package/out/src/DomeRouter.d.ts +32 -0
- package/out/src/LongestCommonSubsequence.d.ts +15 -0
- package/out/src/concurrent-updates.test.d.ts +1 -0
- package/out/src/index.d.ts +11 -0
- package/out/src/temp-test.d.ts +1 -0
- package/package.json +20 -3
- package/out/vitest.config.d.ts +0 -2
- package/out/vitest.config.js +0 -9
- package/src/AnimatedArray.mts +0 -74
- package/src/AnimatedTable.mts +0 -120
- package/src/AnimatedText.mts +0 -30
- package/src/Animation.mts +0 -4
- package/src/Dome.mts +0 -346
- package/src/DomeComponent.mts +0 -84
- package/src/DomeManipulator.mts +0 -391
- package/src/DomeRouter.console-test.mts +0 -52
- package/src/DomeRouter.mts +0 -287
- package/src/LongestCommonSubsequence.mts +0 -201
- package/src/concurrent-updates.test.mts +0 -252
- package/src/index.mts +0 -12
- package/src/temp-test.mts +0 -23
- package/tsconfig.json +0 -59
- package/vitest.config.ts +0 -10
|
@@ -0,0 +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
|
+
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,6 +1,7 @@
|
|
|
1
1
|
import { ObservableVariable } from '@lexriver/observable';
|
|
2
2
|
import { Animation } from './Animation.mjs';
|
|
3
|
-
import { AnimatedArray
|
|
3
|
+
import { AnimatedArray } from "./AnimatedArray.mjs";
|
|
4
|
+
import { DomeComponent } from "./DomeComponent.mjs";
|
|
4
5
|
interface Attrs<T> {
|
|
5
6
|
isLoadingO?: ObservableVariable<boolean>;
|
|
6
7
|
itemsO: ObservableVariable<T[]>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ObservableVariable } from '@lexriver/observable';
|
|
2
|
+
import { Animation } from './Animation';
|
|
3
|
+
import { AnimatedArray } from "./AnimatedArray";
|
|
4
|
+
import { DomeComponent } from "./DomeComponent";
|
|
5
|
+
interface Attrs<T> {
|
|
6
|
+
isLoadingO?: ObservableVariable<boolean>;
|
|
7
|
+
itemsO: ObservableVariable<T[]>;
|
|
8
|
+
animationShowRow: Animation;
|
|
9
|
+
animationHideRow: Animation;
|
|
10
|
+
animationHideTable?: Animation;
|
|
11
|
+
animationShowTable?: Animation;
|
|
12
|
+
animationHideEmptyList?: Animation;
|
|
13
|
+
animationShowEmptyList?: Animation;
|
|
14
|
+
animationShowLoading?: Animation;
|
|
15
|
+
animationHideLoading?: Animation;
|
|
16
|
+
getKey: (item: T) => string;
|
|
17
|
+
rootElement?: HTMLElement;
|
|
18
|
+
tableElement?: HTMLElement;
|
|
19
|
+
tableBody?: HTMLElement;
|
|
20
|
+
renderTableHead?: (items: T[]) => HTMLElement;
|
|
21
|
+
renderTableRow: (item: T) => HTMLElement;
|
|
22
|
+
renderTableFooter?: (items: T[]) => HTMLElement;
|
|
23
|
+
renderEmptyList: () => HTMLElement;
|
|
24
|
+
renderLoading?: () => HTMLElement;
|
|
25
|
+
}
|
|
26
|
+
export declare class AnimatedTable<T> extends DomeComponent<Attrs<T>> {
|
|
27
|
+
refRoot: HTMLElement;
|
|
28
|
+
refTable: HTMLElement;
|
|
29
|
+
refTableHead: Element;
|
|
30
|
+
refTableBody: HTMLElement;
|
|
31
|
+
refTableFooter: Element;
|
|
32
|
+
refEmptyList: Element;
|
|
33
|
+
refLoading: Element;
|
|
34
|
+
animatedArray: AnimatedArray<T>;
|
|
35
|
+
render(): HTMLElement;
|
|
36
|
+
afterRender(): void;
|
|
37
|
+
updateAsync(): Promise<void>;
|
|
38
|
+
}
|
|
39
|
+
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DomeManipulator } from "./DomeManipulator.mjs";
|
|
2
|
-
import { AnimatedArray
|
|
2
|
+
import { AnimatedArray } from "./AnimatedArray.mjs";
|
|
3
|
+
import { DomeComponent } from "./DomeComponent.mjs";
|
|
3
4
|
export class AnimatedTable extends DomeComponent {
|
|
4
5
|
// rootElement
|
|
5
6
|
// table
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ObservableVariable } from "@lexriver/observable";
|
|
2
2
|
import { CssClass } from "./DomeManipulator.mjs";
|
|
3
|
-
import { DomeComponent } from "./
|
|
3
|
+
import { DomeComponent } from "./DomeComponent.mjs";
|
|
4
4
|
interface Attrs {
|
|
5
5
|
textO: ObservableVariable<string>;
|
|
6
6
|
tag?: string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ObservableVariable } from "@lexriver/observable";
|
|
2
|
+
import { CssClass } from "./DomeManipulator";
|
|
3
|
+
import { DomeComponent } from "./DomeComponent";
|
|
4
|
+
interface Attrs {
|
|
5
|
+
textO: ObservableVariable<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 {};
|
package/out/src/AnimatedText.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DomeManipulator } from "./DomeManipulator.mjs";
|
|
2
|
-
import { DomeComponent } from "./
|
|
2
|
+
import { DomeComponent } from "./DomeComponent.mjs";
|
|
3
3
|
export class AnimatedText extends DomeComponent {
|
|
4
4
|
render() {
|
|
5
5
|
//const result = this.attrs.tag ? document.createElement(this.attrs.tag) : document.createElement('span')
|
package/out/src/Dome.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// inspiration: https://github.com/vadimdemedes/dom-chef/blob/master/index.js
|
|
2
|
-
|
|
2
|
+
import { svgTagNames } from 'svg-tag-names';
|
|
3
3
|
import { DataTypes } from '@lexriver/data-types';
|
|
4
4
|
import { checkIfObservable } from '@lexriver/observable';
|
|
5
5
|
import { DomeManipulator } from './DomeManipulator.mjs';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Animation } from './Animation';
|
|
2
|
+
interface InternalAttrs {
|
|
3
|
+
ref?: (ref: any) => void;
|
|
4
|
+
onShowAnimation?: Animation;
|
|
5
|
+
onHideAnimation?: Animation;
|
|
6
|
+
}
|
|
7
|
+
export declare abstract class DomeComponent<Attrs> {
|
|
8
|
+
attrs: Attrs & InternalAttrs;
|
|
9
|
+
children: any;
|
|
10
|
+
rootElement: Element | HTMLElement;
|
|
11
|
+
private updateInProgress;
|
|
12
|
+
private updateRequested;
|
|
13
|
+
constructor(attrs: Attrs & InternalAttrs, children: any);
|
|
14
|
+
protected init(): void;
|
|
15
|
+
protected abstract render(): HTMLElement;
|
|
16
|
+
protected afterRender(): void;
|
|
17
|
+
updateAsync(): Promise<void>;
|
|
18
|
+
private runScheduledUpdateAsync;
|
|
19
|
+
scheduleUpdate: {
|
|
20
|
+
(this: unknown, ...args: [] & any[]): Promise<Promise<void>>;
|
|
21
|
+
cancel: (reason?: any) => void;
|
|
22
|
+
};
|
|
23
|
+
protected afterUpdate(): void;
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { ObservableVariable } from "@lexriver/observable";
|
|
2
|
+
import { Animation } from './Animation';
|
|
3
|
+
export type CssClass = {
|
|
4
|
+
[key: string]: boolean | ObservableVariable<boolean>;
|
|
5
|
+
} | string[] | string;
|
|
6
|
+
export declare namespace DomeManipulator {
|
|
7
|
+
function hideElementAsync(element: Element, animation?: Animation): Promise<void>;
|
|
8
|
+
function unhideElementAsync(element: Element, animation?: Animation): Promise<void>;
|
|
9
|
+
function insertAsFirstChildAsync(elementToInsert: Element, parentElement: Element | DocumentFragment, animation?: Animation): Promise<void>;
|
|
10
|
+
function insertBeforeAsync(elementToInsert: Element, refElement: Element | null, parentElement: Element | DocumentFragment, animation?: Animation): Promise<void>;
|
|
11
|
+
function insertAfterAsync(elementToInsert: Element, refElement: Element | null | undefined, parentElement: Element | DocumentFragment, animation?: Animation): Promise<void>;
|
|
12
|
+
function insertByIndexAsync(elementToInsert: Element, index: number, parentElement: Element | DocumentFragment, animation?: Animation): Promise<void>;
|
|
13
|
+
function replaceAsync(oldElement: Element, newElement: Element, animationHide?: Animation, animationShow?: Animation): Promise<Element>;
|
|
14
|
+
function removeElementAsync(element: Element, animation?: Animation): Promise<void>;
|
|
15
|
+
function forEachChildrenOf(element: Element, action: (child: ChildNode) => void): void;
|
|
16
|
+
function removeAllChildrenAsync(element: Element, animation?: Animation): Promise<void>;
|
|
17
|
+
function appendChildAsync(containerElement: Element, child: Element, animation?: Animation): Promise<void>;
|
|
18
|
+
function appendChildrenAsync(containerElement: Element, children: Element | Element[] | DocumentFragment | Text | string | null | undefined, animation?: Animation): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Replacements for the same container run in call order. A rejected replacement does
|
|
21
|
+
* not block the queue, and replacements for different containers remain independent.
|
|
22
|
+
*/
|
|
23
|
+
function replaceAllChildrenAsync(containerElement: Element, childrenToInsert: Element | Element[] | DocumentFragment | Text | string | null | undefined, animationForHide?: Animation, animationForShow?: Animation): Promise<void>;
|
|
24
|
+
function isInDom(el: Element | undefined): boolean;
|
|
25
|
+
function isOnScreen(el: Element | undefined): boolean;
|
|
26
|
+
function addCssClassAsync(element: Element, cssClassName: string, removeAfterMs?: number): Promise<void>;
|
|
27
|
+
function addCssClassesAsync(element: Element, cssClassNames: string[], removeAfterMs?: number): Promise<void>;
|
|
28
|
+
function removeCssClass(element: Element, cssClassName: string): void;
|
|
29
|
+
function removeCssClasses(element: Element, cssClassNames: string[]): void;
|
|
30
|
+
/**
|
|
31
|
+
* set css classes by array ['class1', 'class2'] or
|
|
32
|
+
* by object {class1:true, class2:false} or
|
|
33
|
+
* by Observable<boolean> {class1:true, class2:myVarO} or
|
|
34
|
+
* by string
|
|
35
|
+
* this function will replace class attribute so all classes that are not in params will be removed
|
|
36
|
+
* @param value
|
|
37
|
+
* @param element
|
|
38
|
+
*/
|
|
39
|
+
function setCssClasses(element: Element, value: CssClass): void;
|
|
40
|
+
function setAttribute(element: Element, name: string, value: any): void;
|
|
41
|
+
function hasFocus(el: Element): boolean;
|
|
42
|
+
function scrollIntoView(element: Element, paddingFromTop?: number): void;
|
|
43
|
+
const scrollToTop: () => void;
|
|
44
|
+
function getCurrentScrollPosition(): number;
|
|
45
|
+
function scrollToAsync(p: {
|
|
46
|
+
pxFromTop?: number;
|
|
47
|
+
pxFromLeft?: number;
|
|
48
|
+
smooth?: boolean;
|
|
49
|
+
msStep?: number;
|
|
50
|
+
maxMsToWait?: number;
|
|
51
|
+
}): Promise<void>;
|
|
52
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export type RouteAction = (params: {
|
|
2
|
+
[key: string]: string | number;
|
|
3
|
+
}, url: string, scrollToPreviousPositionAsync: () => Promise<void>, query: {
|
|
4
|
+
[key: string]: string;
|
|
5
|
+
}) => void | Promise<void>;
|
|
6
|
+
export declare namespace DomeRouter {
|
|
7
|
+
let maxHistoryUrlsCount: number;
|
|
8
|
+
function navigate(url: string): void;
|
|
9
|
+
function goBack(): void;
|
|
10
|
+
function goForward(): void;
|
|
11
|
+
function changeUrl(url: string): void;
|
|
12
|
+
function getCurrentUrl(): string;
|
|
13
|
+
/**
|
|
14
|
+
* get previous page url navigated by router
|
|
15
|
+
* @param previousPageIndex 0=previousPage, 1=previousPage-1, etc
|
|
16
|
+
*/
|
|
17
|
+
function getPreviousPageUrl(previousPageIndex?: number): string | undefined;
|
|
18
|
+
function resolveUrl(url?: string, addToHistory?: boolean): void;
|
|
19
|
+
function onRoute(route: string, exactMatch: boolean, action: RouteAction): void;
|
|
20
|
+
function onNotFound(action: () => void): void;
|
|
21
|
+
/**
|
|
22
|
+
* Check if url matched route.
|
|
23
|
+
* example: /get-product/445345, /get-product/:productId, true ==> Map([productId:445345])
|
|
24
|
+
* example: /get-product/123, /another-route, true ==> undefined
|
|
25
|
+
* example: /articles, /articles, true ==> Map()
|
|
26
|
+
* example: /articles/some-article, /articles, false ==> Map()
|
|
27
|
+
* @param url
|
|
28
|
+
* @param route
|
|
29
|
+
* @param exactMatch
|
|
30
|
+
*/
|
|
31
|
+
function checkUrlMatchRouteAndGetParameters(url: string, route: string, exactMatch?: boolean): Object | undefined;
|
|
32
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare namespace LongestCommonSubsequence {
|
|
2
|
+
function getLongestCommonSubsequence(set1: string[], set2: string[]): string[];
|
|
3
|
+
function getPatch({ oldArray, newArray, onRemove, onAdd }: {
|
|
4
|
+
oldArray: string[];
|
|
5
|
+
newArray: string[];
|
|
6
|
+
onRemove: (index: number, item: string) => void;
|
|
7
|
+
onAdd: (index: number, item: string) => void;
|
|
8
|
+
}): number;
|
|
9
|
+
function getPatchOrdered({ oldArray, newArray, onRemove, onAdd }: {
|
|
10
|
+
oldArray: string[];
|
|
11
|
+
newArray: string[];
|
|
12
|
+
onRemove: (index: number, item: string) => void;
|
|
13
|
+
onAdd: (index: number, item: string) => void;
|
|
14
|
+
}): number;
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from '@lexriver/async';
|
|
2
|
+
export * from '@lexriver/data-types';
|
|
3
|
+
export * from '@lexriver/observable';
|
|
4
|
+
export * from '@lexriver/type-event';
|
|
5
|
+
export * from './AnimatedArray';
|
|
6
|
+
export * from './AnimatedTable';
|
|
7
|
+
export * from './AnimatedText';
|
|
8
|
+
export * from './Dome';
|
|
9
|
+
export * from './DomeComponent';
|
|
10
|
+
export * from './DomeManipulator';
|
|
11
|
+
export * from './DomeRouter.console-test';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,13 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"sideEffects": false,
|
|
3
3
|
"name": "@lexriver/dome",
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.3",
|
|
5
5
|
"description": "DOM manipulator",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"
|
|
7
|
+
"types": "./out/src/index.d.ts",
|
|
8
|
+
"main": "./out/index.cjs",
|
|
9
|
+
"module": "./out/index.mjs",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./out/src/index.d.mts",
|
|
13
|
+
"import": "./out/src/index.mjs",
|
|
14
|
+
"require": "./out/index.cjs",
|
|
15
|
+
"default": "./out/src/index.mjs"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"out",
|
|
20
|
+
"README.md"
|
|
21
|
+
],
|
|
8
22
|
"scripts": {
|
|
9
23
|
"test": "vitest",
|
|
10
|
-
"build": "rimraf out && tsc"
|
|
24
|
+
"build": "rimraf out && tsc && node scripts/build-compat.mjs",
|
|
25
|
+
"test:compat": "npm run build && npm --prefix compatibility/ts39-webpack4 install && npm --prefix compatibility/ts39-webpack4 run build"
|
|
11
26
|
},
|
|
12
27
|
"keywords": [
|
|
13
28
|
"typescript",
|
|
@@ -24,6 +39,7 @@
|
|
|
24
39
|
"license": "MIT",
|
|
25
40
|
"devDependencies": {
|
|
26
41
|
"@types/node": "^22.7.0",
|
|
42
|
+
"esbuild": "^0.21.5",
|
|
27
43
|
"rimraf": "^6.0.1",
|
|
28
44
|
"typescript": "^5.6.2",
|
|
29
45
|
"vitest": "^2.1.1"
|
|
@@ -32,6 +48,7 @@
|
|
|
32
48
|
"@lexriver/async": "^3.0.1",
|
|
33
49
|
"@lexriver/data-types": "^3.0.5",
|
|
34
50
|
"@lexriver/observable": "^3.0.0",
|
|
51
|
+
"@lexriver/type-event": "^2.0.0",
|
|
35
52
|
"svg-tag-names": "^3.0.1",
|
|
36
53
|
"ts-debounce": "^4.0.0"
|
|
37
54
|
}
|
package/out/vitest.config.d.ts
DELETED
package/out/vitest.config.js
DELETED
package/src/AnimatedArray.mts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { Animation } from './Animation.mjs'
|
|
2
|
-
import { DomeManipulator } from "./DomeManipulator.mjs"
|
|
3
|
-
import { LongestCommonSubsequence } from "./LongestCommonSubsequence.mjs"
|
|
4
|
-
|
|
5
|
-
interface KeyToElementPair{
|
|
6
|
-
key:string
|
|
7
|
-
element:HTMLElement
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export class AnimatedArray<T>{
|
|
11
|
-
arrayOfKeyToElement:KeyToElementPair[] = []
|
|
12
|
-
|
|
13
|
-
constructor(protected params:{
|
|
14
|
-
parentElement?:HTMLElement,
|
|
15
|
-
array?:T[],
|
|
16
|
-
getKey:(o:T)=>string,
|
|
17
|
-
getHtmlElement:(o:T)=>HTMLElement,
|
|
18
|
-
animationShow?:Animation
|
|
19
|
-
animationHide?:Animation
|
|
20
|
-
//renderEmptyList?:()=>HTMLElement
|
|
21
|
-
emptyList?:HTMLElement
|
|
22
|
-
}){
|
|
23
|
-
if(params.array && params.parentElement){
|
|
24
|
-
this.update(params.array)
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
get size():number{
|
|
29
|
-
return this.arrayOfKeyToElement.length
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
update(array:T[], parentElement?:HTMLElement|Element){
|
|
33
|
-
parentElement = parentElement || this.params.parentElement
|
|
34
|
-
if(!parentElement){
|
|
35
|
-
console.warn('AnimatedArray unable to update, no parentElement')
|
|
36
|
-
return
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if(array.length == 0 && this.params.emptyList){
|
|
40
|
-
DomeManipulator.replaceAllChildrenAsync(parentElement, this.params.emptyList)
|
|
41
|
-
return
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if(array.length > 0 && this.params.emptyList){
|
|
45
|
-
DomeManipulator.removeElementAsync(this.params.emptyList, this.params.animationHide)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
//let arrayOfKeyToElement:KeyToElementPair[] = []
|
|
49
|
-
let newArrayOfKeys = array.map((item:T) => this.params.getKey(item))
|
|
50
|
-
let oldArrayOfKeys = this.arrayOfKeyToElement.map(x => x.key)
|
|
51
|
-
LongestCommonSubsequence.getPatchOrdered({
|
|
52
|
-
oldArray: oldArrayOfKeys,
|
|
53
|
-
newArray: newArrayOfKeys,
|
|
54
|
-
onAdd:(index:number, key:string) => {
|
|
55
|
-
if(!parentElement) throw new Error('no parent element') //TODO: remove this
|
|
56
|
-
let itemIndex = newArrayOfKeys.indexOf(key)
|
|
57
|
-
if(itemIndex == -1) throw new Error('no itemIndex') //TODO: remove this
|
|
58
|
-
let item = array[itemIndex]
|
|
59
|
-
let element = this.params.getHtmlElement(item)
|
|
60
|
-
this.arrayOfKeyToElement.splice(index,0,{key, element})
|
|
61
|
-
DomeManipulator.insertByIndexAsync(element, index, parentElement, this.params.animationShow)
|
|
62
|
-
//this.insertNewElementWithAnimation(element, index, parentElement)
|
|
63
|
-
|
|
64
|
-
},
|
|
65
|
-
onRemove: (index:number, key:string) => {
|
|
66
|
-
DomeManipulator.removeElementAsync(this.arrayOfKeyToElement[index].element, this.params.animationHide)
|
|
67
|
-
this.arrayOfKeyToElement.splice(index,1)
|
|
68
|
-
}
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
package/src/AnimatedTable.mts
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { ObservableVariable } from '@lexriver/observable'
|
|
2
|
-
import { Animation } from './Animation.mjs'
|
|
3
|
-
import { DomeManipulator } from "./DomeManipulator.mjs"
|
|
4
|
-
import { AnimatedArray, DomeComponent } from "./index.mjs"
|
|
5
|
-
|
|
6
|
-
interface Attrs<T>{
|
|
7
|
-
isLoadingO?:ObservableVariable<boolean>
|
|
8
|
-
itemsO:ObservableVariable<T[]>
|
|
9
|
-
animationShowRow:Animation
|
|
10
|
-
animationHideRow:Animation
|
|
11
|
-
animationHideTable?:Animation
|
|
12
|
-
animationShowTable?:Animation
|
|
13
|
-
animationHideEmptyList?:Animation
|
|
14
|
-
animationShowEmptyList?:Animation
|
|
15
|
-
animationShowLoading?:Animation
|
|
16
|
-
animationHideLoading?:Animation
|
|
17
|
-
getKey:(item:T)=>string
|
|
18
|
-
rootElement?:HTMLElement
|
|
19
|
-
tableElement?:HTMLElement
|
|
20
|
-
tableBody?:HTMLElement
|
|
21
|
-
renderTableHead?:(items:T[])=>HTMLElement
|
|
22
|
-
renderTableRow:(item:T)=>HTMLElement
|
|
23
|
-
renderTableFooter?:(items:T[]) => HTMLElement
|
|
24
|
-
renderEmptyList:()=>HTMLElement
|
|
25
|
-
renderLoading?:()=>HTMLElement
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export class AnimatedTable<T> extends DomeComponent<Attrs<T>>{
|
|
29
|
-
// rootElement
|
|
30
|
-
// table
|
|
31
|
-
// thead
|
|
32
|
-
// tbody
|
|
33
|
-
// tfooter
|
|
34
|
-
// emptyList
|
|
35
|
-
refRoot:HTMLElement = this.attrs.rootElement || document.createElement('div')
|
|
36
|
-
refTable:HTMLElement = this.attrs.tableElement || document.createElement('table')
|
|
37
|
-
refTableHead:Element = this.attrs.renderTableHead ? this.attrs.renderTableHead(this.attrs.itemsO.get()) : document.createElement('thead')
|
|
38
|
-
refTableBody:HTMLElement = this.attrs.tableBody || document.createElement('tbody')
|
|
39
|
-
refTableFooter:Element = this.attrs.renderTableFooter ? this.attrs.renderTableFooter(this.attrs.itemsO.get()) : document.createElement('tfoot')
|
|
40
|
-
refEmptyList:Element = this.attrs.renderEmptyList ? this.attrs.renderEmptyList() : document.createElement('div')
|
|
41
|
-
refLoading:Element = this.attrs.renderLoading ? this.attrs.renderLoading() : document.createElement('div')
|
|
42
|
-
|
|
43
|
-
animatedArray = new AnimatedArray<T>({
|
|
44
|
-
animationHide: this.attrs.animationHideRow,
|
|
45
|
-
animationShow: this.attrs.animationShowRow,
|
|
46
|
-
array: [],
|
|
47
|
-
getKey: this.attrs.getKey,
|
|
48
|
-
getHtmlElement: this.attrs.renderTableRow
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
render(){
|
|
52
|
-
// refRoot
|
|
53
|
-
// refTable
|
|
54
|
-
// refTableHead
|
|
55
|
-
// refTableBody
|
|
56
|
-
// refTableFooter
|
|
57
|
-
// refEmptyListEl
|
|
58
|
-
// refLoading
|
|
59
|
-
|
|
60
|
-
this.refRoot.appendChild(this.refTable)
|
|
61
|
-
this.refRoot.appendChild(this.refEmptyList)
|
|
62
|
-
this.refRoot.appendChild(this.refLoading)
|
|
63
|
-
if(this.refTableHead) this.refTable.appendChild(this.refTableHead)
|
|
64
|
-
if(this.refTableBody) this.refTable.appendChild(this.refTableBody)
|
|
65
|
-
if(this.refTableFooter) this.refTable.appendChild(this.refTableFooter)
|
|
66
|
-
console.log('AnimatedTable render()', 'refRoot=', this.refRoot)
|
|
67
|
-
return this.refRoot
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
afterRender(){
|
|
71
|
-
this.updateAsync()
|
|
72
|
-
//this.animatedArray.update(this.attrs.items, this.el)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
async updateAsync(){
|
|
76
|
-
try {
|
|
77
|
-
if(this.attrs.renderLoading){
|
|
78
|
-
this.refLoading = await DomeManipulator.replaceAsync(this.refLoading, this.attrs.renderLoading())
|
|
79
|
-
}
|
|
80
|
-
if(this.attrs.isLoadingO && this.attrs.isLoadingO.get()){
|
|
81
|
-
// show loading
|
|
82
|
-
await DomeManipulator.unhideElementAsync(this.refLoading, this.attrs.animationShowLoading)
|
|
83
|
-
} else {
|
|
84
|
-
// hide loading
|
|
85
|
-
await DomeManipulator.hideElementAsync(this.refLoading, this.attrs.animationHideLoading)
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const items = this.attrs.itemsO.get()
|
|
89
|
-
const currentCount = items.length
|
|
90
|
-
|
|
91
|
-
if(currentCount == 0){
|
|
92
|
-
// render empty list
|
|
93
|
-
await DomeManipulator.hideElementAsync(this.refTable, this.attrs.animationHideTable)
|
|
94
|
-
if(this.attrs.renderEmptyList){
|
|
95
|
-
this.refEmptyList = await DomeManipulator.replaceAsync(this.refEmptyList, this.attrs.renderEmptyList())
|
|
96
|
-
}
|
|
97
|
-
await DomeManipulator.unhideElementAsync(this.refEmptyList, this.attrs.animationShowEmptyList)
|
|
98
|
-
|
|
99
|
-
} else {
|
|
100
|
-
|
|
101
|
-
// render list with items
|
|
102
|
-
await DomeManipulator.hideElementAsync(this.refEmptyList, this.attrs.animationHideEmptyList)
|
|
103
|
-
if(this.attrs.renderTableHead){
|
|
104
|
-
this.refTableHead = await DomeManipulator.replaceAsync(this.refTableHead, this.attrs.renderTableHead(items))
|
|
105
|
-
}
|
|
106
|
-
if(this.attrs.renderTableFooter){
|
|
107
|
-
this.refTableFooter = await DomeManipulator.replaceAsync(this.refTableFooter, this.attrs.renderTableFooter(items))
|
|
108
|
-
}
|
|
109
|
-
await DomeManipulator.unhideElementAsync(this.refTable, this.attrs.animationShowTable)
|
|
110
|
-
|
|
111
|
-
this.animatedArray.update(items, this.refTableBody)
|
|
112
|
-
}
|
|
113
|
-
} catch(x){
|
|
114
|
-
console.error('AnimatedTable update failed', x)
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
}
|
package/src/AnimatedText.mts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { ObservableVariable } from "@lexriver/observable";
|
|
2
|
-
import { CssClass, DomeManipulator } from "./DomeManipulator.mjs";
|
|
3
|
-
import { DomeComponent } from "./index.mjs";
|
|
4
|
-
|
|
5
|
-
interface Attrs{
|
|
6
|
-
textO:ObservableVariable<string>
|
|
7
|
-
tag?:string
|
|
8
|
-
class?:CssClass
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export class AnimatedText extends DomeComponent<Attrs>{
|
|
12
|
-
render(){
|
|
13
|
-
//const result = this.attrs.tag ? document.createElement(this.attrs.tag) : document.createElement('span')
|
|
14
|
-
const result = document.createElement(this.attrs.tag || 'span')
|
|
15
|
-
//console.log('AnimatedText', 'this.attrs.class=',this.attrs.class)
|
|
16
|
-
if(this.attrs.class){
|
|
17
|
-
DomeManipulator.setCssClasses(result, this.attrs.class)
|
|
18
|
-
}
|
|
19
|
-
result.append(this.attrs.textO.get())
|
|
20
|
-
return result
|
|
21
|
-
}
|
|
22
|
-
async updateAsync(){
|
|
23
|
-
if(!this.rootElement) return
|
|
24
|
-
try {
|
|
25
|
-
this.rootElement = await DomeManipulator.replaceAsync(this.rootElement, this.render(), this.attrs.onHideAnimation, this.attrs.onShowAnimation)
|
|
26
|
-
} catch(x){
|
|
27
|
-
console.error('AnimatedText update failed', x)
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
package/src/Animation.mts
DELETED