@lipsjs/lips 0.0.11 → 0.0.13
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/dist/lips.min.js +2 -2
- package/dist/lips.min.js.map +19 -19
- package/dist/test.component.min.js +67 -2
- package/dist/test.component.min.js.map +22 -20
- package/dist/test.stress.min.js +8 -8
- package/dist/test.stress.min.js.map +19 -19
- package/dist/types/component.d.ts +35 -8
- package/dist/types/iuc/index.d.ts +25 -0
- package/dist/types/iuc/tick.d.ts +38 -0
- package/dist/types/lips.d.ts +2 -2
- package/dist/types/syntax/if.d.ts +5 -6
- package/dist/types/syntax/switch.d.ts +5 -6
- package/dist/types/types.d.ts +55 -28
- package/dist/types/uqs.d.ts +4 -4
- package/dist/types/utils.d.ts +11 -0
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type Lips from './lips';
|
|
2
|
-
import type { Handler, Metavars, ComponentScope, ComponentOptions, VariableSet, RenderedNode, FGUDependencies } from './types';
|
|
2
|
+
import type { Handler, Metavars, ComponentScope, ComponentOptions, VariableSet, RenderedNode, FGUDependencies, FragmentBoundaries, FGUDMemory } from './types';
|
|
3
3
|
import Events from './events';
|
|
4
4
|
import Metrics from './metrics';
|
|
5
5
|
import { Cash } from 'cash-dom';
|
|
@@ -22,6 +22,7 @@ export default class Component<MT extends Metavars> extends Events {
|
|
|
22
22
|
private __macros;
|
|
23
23
|
private __i18nDeps;
|
|
24
24
|
FGUD: FGUDependencies;
|
|
25
|
+
FGUDMemory: FGUDMemory;
|
|
25
26
|
private PCC;
|
|
26
27
|
private VER;
|
|
27
28
|
private prepath;
|
|
@@ -35,44 +36,70 @@ export default class Component<MT extends Metavars> extends Events {
|
|
|
35
36
|
lips: Lips;
|
|
36
37
|
metrics: Metrics;
|
|
37
38
|
stylesheet?: Stylesheet;
|
|
38
|
-
private
|
|
39
|
-
private
|
|
40
|
-
private
|
|
39
|
+
private __inpath__;
|
|
40
|
+
private __inpathCounter__;
|
|
41
|
+
private __renderDepth__;
|
|
42
|
+
private __boundaries__;
|
|
41
43
|
[key: string]: any;
|
|
42
44
|
constructor(name: string, template: string, { input, state, context, _static, handler, stylesheet, macros, declaration }: ComponentScope<MT>, options: ComponentOptions<any>);
|
|
43
45
|
setContext(arg: Partial<Record<string, any>> | string, value?: any): void;
|
|
44
|
-
setInput(input: MT['Input']): void;
|
|
46
|
+
setInput(input: MT['Input'], memo?: VariableSet): void;
|
|
45
47
|
/**
|
|
46
48
|
* Inject grain/partial input to current component
|
|
47
49
|
* instead of sending a whole updated input
|
|
48
50
|
*/
|
|
49
|
-
subInput(data: Record<string, any
|
|
51
|
+
subInput(data: Record<string, any>, memo?: VariableSet): this;
|
|
50
52
|
setMacros(template: string): void;
|
|
51
53
|
setHandler(list: Handler<MT>): void;
|
|
52
54
|
setStylesheet(sheet?: string): void;
|
|
53
|
-
get node(): Cash;
|
|
54
|
-
|
|
55
|
+
get node(): Cash | null | undefined;
|
|
56
|
+
get boundaries(): FragmentBoundaries | undefined;
|
|
57
|
+
render(inpath: string, $nodes?: Cash, scope?: VariableSet, sharedDeps?: FGUDependencies, xmlns?: boolean): RenderedNode<MT>;
|
|
55
58
|
destroy(): void;
|
|
56
59
|
private __meshwire__;
|
|
57
60
|
private __getBoundaries__;
|
|
61
|
+
private __emptyBoundaries__;
|
|
62
|
+
private __fillBoundaries__;
|
|
58
63
|
private __getAttributes__;
|
|
59
64
|
private __withPath__;
|
|
60
65
|
private __getPathParent__;
|
|
61
66
|
private __hasSamePathParent__;
|
|
62
67
|
private __evaluate__;
|
|
63
68
|
private __evaluateFunction__;
|
|
69
|
+
private __evaluateSpreadAttr__;
|
|
64
70
|
private __interpolate__;
|
|
65
71
|
private __attachEvent__;
|
|
66
72
|
private __detachEvent__;
|
|
67
73
|
private __extractTextDeps__;
|
|
68
74
|
private __extractExpressionDeps__;
|
|
69
75
|
private __isReactive__;
|
|
76
|
+
/**
|
|
77
|
+
* Store dependencies memory separately:
|
|
78
|
+
*
|
|
79
|
+
* IMPORTANT: Every node's tracked deps share
|
|
80
|
+
* the same memo reference by the path
|
|
81
|
+
* of that node.
|
|
82
|
+
*
|
|
83
|
+
* Example 1: `<div id=state.item.id style="padding: {input.size/2}">...</div>`
|
|
84
|
+
* The dependencies tracking `id` and `style` attributes
|
|
85
|
+
* will respectively share the memo that is referenced by
|
|
86
|
+
* the `div` element's path
|
|
87
|
+
* Example 2. `<span>{state.label} - {count}</span>`
|
|
88
|
+
* The `state.label` and `count` dependencies will be
|
|
89
|
+
* each tracked using the `span` text content element's
|
|
90
|
+
* memo.
|
|
91
|
+
*
|
|
92
|
+
* Same procedure for `event-handlers`
|
|
93
|
+
*/
|
|
94
|
+
private __bindMemo__;
|
|
95
|
+
private __unbindMemo__;
|
|
70
96
|
private __trackDep__;
|
|
71
97
|
private __trackTranslationDep__;
|
|
72
98
|
private __valueDep__;
|
|
73
99
|
private __shouldUpdate__;
|
|
74
100
|
private __updateDepNodes__;
|
|
75
101
|
private __updateVarDepNodes__;
|
|
102
|
+
private __updateArgumentsDepNodes__;
|
|
76
103
|
private __updateI18nDepNodes__;
|
|
77
104
|
appendTo(arg: Cash | string): this;
|
|
78
105
|
prependTo(arg: Cash | string): this;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal Update Cycle
|
|
3
|
+
*/
|
|
4
|
+
export default class IUC {
|
|
5
|
+
private subscriptions;
|
|
6
|
+
private tick;
|
|
7
|
+
/**
|
|
8
|
+
* Register component update function
|
|
9
|
+
*/
|
|
10
|
+
register(ref: string, ticker: () => void): void;
|
|
11
|
+
/**
|
|
12
|
+
* Unregister component
|
|
13
|
+
*/
|
|
14
|
+
unregister(ref: string): void;
|
|
15
|
+
/**
|
|
16
|
+
* Queue an immediate update for next tick
|
|
17
|
+
*/
|
|
18
|
+
queueUpdate(ref: string): void;
|
|
19
|
+
dispose(): void;
|
|
20
|
+
prepareForPotentialUnload(): void;
|
|
21
|
+
/**
|
|
22
|
+
* Create a state proxy handler to detect mutations
|
|
23
|
+
*/
|
|
24
|
+
proxyState<State extends Object>(componentRef: string, state: State): any;
|
|
25
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A more efficient scheduler using microtasks
|
|
3
|
+
* for component updates
|
|
4
|
+
*/
|
|
5
|
+
export default class NextTick {
|
|
6
|
+
private pendingComponents;
|
|
7
|
+
private isPending;
|
|
8
|
+
private callbacks;
|
|
9
|
+
/**
|
|
10
|
+
* Register a component update callback
|
|
11
|
+
*/
|
|
12
|
+
register(ref: string, callback: Function): void;
|
|
13
|
+
/**
|
|
14
|
+
* Unregister a component
|
|
15
|
+
*/
|
|
16
|
+
unregister(ref: string): void;
|
|
17
|
+
/**
|
|
18
|
+
* Queue a component update to be processed
|
|
19
|
+
* in the next tick of the event loop
|
|
20
|
+
*/
|
|
21
|
+
queue(ref: string): void;
|
|
22
|
+
/**
|
|
23
|
+
* Schedule update using microtasks
|
|
24
|
+
*/
|
|
25
|
+
private schedule;
|
|
26
|
+
/**
|
|
27
|
+
* Process all pending component updates
|
|
28
|
+
*/
|
|
29
|
+
private process;
|
|
30
|
+
/**
|
|
31
|
+
* Clear all pending updates and reset state
|
|
32
|
+
*/
|
|
33
|
+
clear(): void;
|
|
34
|
+
/**
|
|
35
|
+
* Complete disposal of all resources
|
|
36
|
+
*/
|
|
37
|
+
dispose(): void;
|
|
38
|
+
}
|
package/dist/types/lips.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { LipsConfig, Template, Metavars } from './types';
|
|
2
|
-
import I18N from './i18n';
|
|
3
2
|
import IUC from './iuc';
|
|
4
3
|
import DWS from './dws';
|
|
5
|
-
import
|
|
4
|
+
import I18N from './i18n';
|
|
6
5
|
import Stylesheet from './stylesheet';
|
|
6
|
+
import ComponentClass from './component';
|
|
7
7
|
export * from './types';
|
|
8
8
|
export type Component<MT extends Metavars> = ComponentClass<MT>;
|
|
9
9
|
export default class Lips<Context extends Object = {}> {
|
|
@@ -5,11 +5,10 @@ export interface Input {
|
|
|
5
5
|
'else-if'?: MeshTemplate[];
|
|
6
6
|
'else'?: MeshTemplate;
|
|
7
7
|
}
|
|
8
|
-
export interface
|
|
9
|
-
|
|
8
|
+
export interface Static {
|
|
9
|
+
initialized: boolean;
|
|
10
|
+
prevRenderer: MeshRenderer | null;
|
|
10
11
|
}
|
|
11
12
|
export declare const declaration: Declaration;
|
|
12
|
-
export declare const
|
|
13
|
-
export declare const handler: Handler<Metavars<Input,
|
|
14
|
-
declare const _default: "<{state.renderer}/>";
|
|
15
|
-
export default _default;
|
|
13
|
+
export declare const _static: Static;
|
|
14
|
+
export declare const handler: Handler<Metavars<Input, {}, Static>>;
|
|
@@ -7,11 +7,10 @@ export interface Input {
|
|
|
7
7
|
renderer: MeshRenderer;
|
|
8
8
|
default?: MeshTemplate;
|
|
9
9
|
}
|
|
10
|
-
export interface
|
|
11
|
-
|
|
10
|
+
export interface Static {
|
|
11
|
+
initialized: boolean;
|
|
12
|
+
prevRenderer: MeshRenderer | null;
|
|
12
13
|
}
|
|
13
14
|
export declare const declaration: Declaration;
|
|
14
|
-
export declare const
|
|
15
|
-
export declare const handler: Handler<Metavars<Input,
|
|
16
|
-
declare const _default: "<{state.renderer}/>";
|
|
17
|
-
export default _default;
|
|
15
|
+
export declare const _static: Static;
|
|
16
|
+
export declare const handler: Handler<Metavars<Input, {}, Static>>;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -16,7 +16,17 @@ export type Variable = {
|
|
|
16
16
|
value: any;
|
|
17
17
|
type: 'let' | 'const' | 'arg';
|
|
18
18
|
};
|
|
19
|
-
export type
|
|
19
|
+
export type VariableArguments = Record<string, any>;
|
|
20
|
+
export type VariableSet = Record<string, Variable> & {
|
|
21
|
+
__arguments__?: VariableArguments;
|
|
22
|
+
};
|
|
23
|
+
export interface SpreadOpeartor {
|
|
24
|
+
each(key: string, value: any): void;
|
|
25
|
+
nullify?: (attrs: string[]) => void;
|
|
26
|
+
get keystore(): string[];
|
|
27
|
+
set keystore(__: string[]);
|
|
28
|
+
memo: VariableSet;
|
|
29
|
+
}
|
|
20
30
|
export type I18nVariant = Record<string, string>;
|
|
21
31
|
export type I18nFormat = {
|
|
22
32
|
type: string;
|
|
@@ -27,6 +37,7 @@ export type DeclarationTagType = 'nexted' | 'child';
|
|
|
27
37
|
export type DeclarationTag = {
|
|
28
38
|
type: DeclarationTagType;
|
|
29
39
|
many?: boolean;
|
|
40
|
+
alts?: string[];
|
|
30
41
|
optional?: boolean;
|
|
31
42
|
};
|
|
32
43
|
export type Declaration = {
|
|
@@ -39,7 +50,7 @@ export type Declaration = {
|
|
|
39
50
|
export type LifeCycleEventTypes = 'onCreate' | 'onInput' | 'onMount' | 'onRender' | 'onUpdate' | 'onAttach' | 'onDetach' | 'onContext' | 'onDestroy';
|
|
40
51
|
export interface LifecycleEvents<MT extends Metavars> {
|
|
41
52
|
onCreate: (this: Component<MT>) => void;
|
|
42
|
-
onInput: (this: Component<MT>,
|
|
53
|
+
onInput: (this: Component<MT>, memo?: VariableSet) => void;
|
|
43
54
|
onMount: (this: Component<MT>) => void;
|
|
44
55
|
onRender: (this: Component<MT>) => void;
|
|
45
56
|
onUpdate: (this: Component<MT>) => void;
|
|
@@ -79,6 +90,7 @@ export type ComponentOptions<Context extends Object> = {
|
|
|
79
90
|
lips: Lips<Context>;
|
|
80
91
|
debug?: boolean;
|
|
81
92
|
prepath?: string;
|
|
93
|
+
boundaries?: FragmentBoundaries;
|
|
82
94
|
};
|
|
83
95
|
export type LipsConfig<Context extends Object> = {
|
|
84
96
|
debug?: boolean;
|
|
@@ -101,58 +113,71 @@ export type Macro = {
|
|
|
101
113
|
};
|
|
102
114
|
export type SyntaxAttributes = {
|
|
103
115
|
literals: Record<string, any>;
|
|
104
|
-
functions: Record<string, any>;
|
|
105
116
|
expressions: Record<string, any>;
|
|
117
|
+
map: {
|
|
118
|
+
explicitAttrs: string[];
|
|
119
|
+
spreadAttrs: string[];
|
|
120
|
+
beforeSpreadAttrs: string[];
|
|
121
|
+
afterSpreadAttrs: string[];
|
|
122
|
+
metaAttrs: string[];
|
|
123
|
+
};
|
|
106
124
|
};
|
|
107
|
-
export
|
|
108
|
-
|
|
125
|
+
export interface VirtualEvent<MT extends Metavars> {
|
|
126
|
+
element: Cash | Component<MT>;
|
|
109
127
|
_event: string;
|
|
110
128
|
instruction: string;
|
|
129
|
+
nodepath: string;
|
|
111
130
|
scope?: Record<string, any>;
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
element: Cash | T;
|
|
115
|
-
_event: string;
|
|
116
|
-
};
|
|
131
|
+
get __dependencies__(): FGUDependencies;
|
|
132
|
+
}
|
|
117
133
|
/**
|
|
118
134
|
* (FGU) Fine-Grain Update Dependencies
|
|
119
135
|
*/
|
|
120
|
-
export type NodeType = 'component' | 'dynamic' | 'element' | 'macro' | 'text' | 'let' | 'log';
|
|
121
|
-
export type FGUDTarget = 'spread-attr' | 'meta-attr' | 'argument' | 'value' | 'attr' | 'dtag';
|
|
136
|
+
export type NodeType = 'component' | 'dynamic' | 'element' | 'event' | 'macro' | 'text' | 'let' | 'log';
|
|
137
|
+
export type FGUDTarget = 'event-handler' | 'spread-attr' | 'meta-attr' | 'argument' | 'value' | 'attr' | 'dtag';
|
|
122
138
|
export interface FGUSync {
|
|
123
139
|
memo?: VariableSet;
|
|
124
140
|
cleanup?: () => void;
|
|
125
141
|
}
|
|
126
|
-
export interface I18nDependency {
|
|
127
|
-
nodetype: NodeType;
|
|
128
|
-
target: FGUDTarget;
|
|
129
|
-
path: string;
|
|
130
|
-
$fragment: Cash;
|
|
131
|
-
memo: VariableSet;
|
|
132
|
-
update: (memo: VariableSet, by?: string) => FGUSync | void;
|
|
133
|
-
}
|
|
134
142
|
export interface FGUDependency {
|
|
135
143
|
nodetype: NodeType;
|
|
144
|
+
nodepath: string;
|
|
145
|
+
deppath?: string;
|
|
136
146
|
target: FGUDTarget;
|
|
137
|
-
path: string;
|
|
138
147
|
$fragment: Cash | null;
|
|
139
148
|
boundaries?: FragmentBoundaries;
|
|
140
149
|
haslet?: boolean;
|
|
141
|
-
batch?: boolean;
|
|
142
150
|
syntax?: boolean;
|
|
143
151
|
partial?: string[];
|
|
144
|
-
|
|
152
|
+
priority?: number;
|
|
153
|
+
level?: number;
|
|
154
|
+
garbage?: boolean;
|
|
145
155
|
update: (memo: VariableSet, by?: string) => FGUSync | void;
|
|
146
156
|
}
|
|
147
157
|
export type FGUDependencies = Map<string, Map<string, FGUDependency>>;
|
|
148
158
|
export type FGUDBatchEntry = {
|
|
149
159
|
dep: string;
|
|
150
|
-
|
|
160
|
+
deppath: string;
|
|
161
|
+
priority?: number;
|
|
162
|
+
};
|
|
163
|
+
export type FGUDMemorySlot = {
|
|
164
|
+
tracks: Map<string, number>;
|
|
165
|
+
memo: VariableSet;
|
|
151
166
|
};
|
|
152
|
-
export type
|
|
167
|
+
export type FGUDMemory = Map<string, FGUDMemorySlot>;
|
|
168
|
+
export interface I18nDependency {
|
|
169
|
+
nodetype: NodeType;
|
|
170
|
+
nodepath: string;
|
|
171
|
+
deppath?: string;
|
|
172
|
+
target: FGUDTarget;
|
|
173
|
+
$fragment: Cash;
|
|
174
|
+
priority?: number;
|
|
175
|
+
update: (memo: VariableSet, by?: string) => FGUSync | void;
|
|
176
|
+
}
|
|
177
|
+
export type RenderedNode<MT extends Metavars> = {
|
|
153
178
|
$log: Cash;
|
|
154
179
|
dependencies: FGUDependencies;
|
|
155
|
-
events?: VirtualEvent[];
|
|
180
|
+
events?: VirtualEvent<MT>[];
|
|
156
181
|
};
|
|
157
182
|
export type FragmentBoundaries = {
|
|
158
183
|
start: Comment;
|
|
@@ -161,8 +186,10 @@ export type FragmentBoundaries = {
|
|
|
161
186
|
export interface MeshRenderer {
|
|
162
187
|
path: string | null;
|
|
163
188
|
argv: string[];
|
|
164
|
-
mesh(argvalues?: VariableSet): Cash | null;
|
|
165
|
-
update(deps: string[], argvalues: VariableSet, boundaries?: FragmentBoundaries): void;
|
|
189
|
+
mesh(argvalues?: VariableSet, scope?: VariableSet): Cash | null;
|
|
190
|
+
update(deps: string[], argvalues: VariableSet, scope: VariableSet, boundaries?: FragmentBoundaries): void;
|
|
191
|
+
fill($log: Cash, boundaries?: FragmentBoundaries): void;
|
|
192
|
+
cleanup(boundaries?: FragmentBoundaries): void;
|
|
166
193
|
}
|
|
167
194
|
export type MeshTemplate = Record<string, any> & {
|
|
168
195
|
renderer: MeshRenderer;
|
package/dist/types/uqs.d.ts
CHANGED
|
@@ -13,6 +13,10 @@ export default class UpdateQueue<MT extends Metavars> {
|
|
|
13
13
|
* Queue updates to be processed in the next tick
|
|
14
14
|
*/
|
|
15
15
|
queue(entry: FGUDBatchEntry): void;
|
|
16
|
+
/**
|
|
17
|
+
* Apply updates
|
|
18
|
+
*/
|
|
19
|
+
apply({ dep, deppath }: FGUDBatchEntry, by?: string): void;
|
|
16
20
|
/**
|
|
17
21
|
* Schedule processing using microtasks for better performance
|
|
18
22
|
*/
|
|
@@ -21,10 +25,6 @@ export default class UpdateQueue<MT extends Metavars> {
|
|
|
21
25
|
* Process all queued updates in a batch
|
|
22
26
|
*/
|
|
23
27
|
private processQueue;
|
|
24
|
-
/**
|
|
25
|
-
* Apply updates to the DOM
|
|
26
|
-
*/
|
|
27
|
-
private applyUpdates;
|
|
28
28
|
/**
|
|
29
29
|
* Get current metrics
|
|
30
30
|
*/
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -7,6 +7,16 @@ export declare const SPREAD_VAR_PATTERN: RegExp;
|
|
|
7
7
|
export declare const ARGUMENT_VAR_PATTERN: RegExp;
|
|
8
8
|
export declare const INTERPOLATE_PATTERN: RegExp;
|
|
9
9
|
export declare const META_ATTRIBUTES: string[];
|
|
10
|
+
export declare const LAYOUT_AFFECTING_ATTRS: string[];
|
|
11
|
+
export declare const ROOT_PREFIX = ":r";
|
|
12
|
+
export declare const NODE_PREFIX = ":n";
|
|
13
|
+
export declare const MACRO_PREFIX = "m";
|
|
14
|
+
export declare const COMPONENT_PREFIX = "c";
|
|
15
|
+
export declare const SYNTAX_COMPONENT_PREFIX = "x";
|
|
16
|
+
/**
|
|
17
|
+
* Constant for max update type priorities
|
|
18
|
+
*/
|
|
19
|
+
export declare const MAX_PRIORITY_TYPES = 100;
|
|
10
20
|
/**
|
|
11
21
|
* Deep difference checker with support for Map, Set,
|
|
12
22
|
* and various JS built-in types
|
|
@@ -31,3 +41,4 @@ export declare function deepClone(obj: any, seen?: WeakMap<object, any>): any;
|
|
|
31
41
|
* @returns A new object with the assigned values
|
|
32
42
|
*/
|
|
33
43
|
export declare function deepAssign<T>(original: T, toSet: Record<string, any>): T;
|
|
44
|
+
export declare function sterilize(obj: Record<string, any>): any;
|