cx 26.1.0 → 26.1.1
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/build/ui/Widget.js +0 -5
- package/build/util/Component.js +5 -0
- package/build/util/test/createTestRenderer.d.ts +3 -1
- package/build/util/test/createTestRenderer.js +8 -2
- package/build/widgets/icons/calendar.js +4 -3
- package/build/widgets/icons/check.js +2 -2
- package/build/widgets/icons/clear.js +2 -2
- package/build/widgets/icons/close.js +2 -2
- package/build/widgets/icons/cx.js +2 -2
- package/build/widgets/icons/drop-down.js +2 -2
- package/build/widgets/icons/file.js +2 -2
- package/build/widgets/icons/folder-open.js +2 -2
- package/build/widgets/icons/folder.js +2 -2
- package/build/widgets/icons/forward.js +2 -2
- package/build/widgets/icons/loading.js +2 -2
- package/build/widgets/icons/menu.js +2 -2
- package/build/widgets/icons/pixel-picker.js +2 -2
- package/build/widgets/icons/search.js +2 -2
- package/build/widgets/icons/sort-asc.js +2 -2
- package/build/widgets/icons/square.js +2 -2
- package/dist/manifest.js +896 -896
- package/dist/ui.js +1 -8
- package/dist/util.js +4 -0
- package/dist/widgets.js +377 -313
- package/package.json +3 -1
- package/src/core.d.ts +182 -182
- package/src/data/ArrayElementView.ts +90 -90
- package/src/data/AugmentedViewBase.ts +88 -88
- package/src/data/Binding.ts +104 -104
- package/src/data/ExposedRecordView.ts +95 -95
- package/src/data/ExposedValueView.ts +89 -89
- package/src/data/Grouper.spec.ts +57 -57
- package/src/data/NestedDataView.ts +43 -43
- package/src/data/ReadOnlyDataView.ts +39 -39
- package/src/data/Ref.ts +104 -104
- package/src/data/Store.ts +52 -52
- package/src/data/StoreProxy.ts +19 -19
- package/src/data/StoreRef.ts +66 -66
- package/src/data/StringTemplate.ts +93 -93
- package/src/data/StructuredSelector.spec.ts +113 -113
- package/src/data/SubscribableView.ts +63 -63
- package/src/data/ZoomIntoPropertyView.ts +45 -45
- package/src/data/comparer.ts +78 -78
- package/src/data/ops/updateArray.ts +31 -31
- package/src/hooks/invokeCallback.spec.tsx +4 -4
- package/src/hooks/resolveCallback.spec.tsx +4 -4
- package/src/hooks/store.spec.tsx +15 -15
- package/src/hooks/useTrigger.spec.tsx +16 -10
- package/src/jsx-dev-runtime.ts +4 -4
- package/src/jsx-runtime.ts +79 -79
- package/src/ui/CSS.ts +87 -87
- package/src/ui/ContentResolver.spec.tsx +31 -29
- package/src/ui/Controller.spec.tsx +47 -39
- package/src/ui/Cx.spec.tsx +10 -8
- package/src/ui/DataProxy.spec.tsx +18 -18
- package/src/ui/DataProxy.ts +55 -55
- package/src/ui/FocusManager.ts +171 -171
- package/src/ui/IsolatedScope.spec.tsx +16 -9
- package/src/ui/PureContainer.spec.tsx +20 -18
- package/src/ui/Repeater.spec.tsx +8 -6
- package/src/ui/Rescope.spec.tsx +13 -13
- package/src/ui/Rescope.ts +49 -49
- package/src/ui/Restate.spec.tsx +31 -27
- package/src/ui/VDOM.ts +1 -1
- package/src/ui/Widget.tsx +0 -7
- package/src/ui/adapter/ArrayAdapter.spec.ts +55 -55
- package/src/ui/createFunctionalComponent.spec.tsx +20 -18
- package/src/ui/layout/Content.ts +30 -30
- package/src/ui/layout/ContentPlaceholder.spec.tsx +46 -34
- package/src/ui/layout/FirstVisibleChildLayout.spec.tsx +31 -19
- package/src/ui/selection/PropertySelection.ts +87 -87
- package/src/util/Component.spec.ts +30 -0
- package/src/util/Component.ts +301 -296
- package/src/util/DOM.ts +88 -88
- package/src/util/Format.spec.ts +69 -69
- package/src/util/Format.ts +267 -267
- package/src/util/addEventListenerWithOptions.ts +41 -41
- package/src/util/browserSupportsPassiveEventHandlers.ts +20 -20
- package/src/util/color/rgbToHsl.ts +35 -35
- package/src/util/getActiveElement.ts +4 -4
- package/src/util/innerTextTrim.ts +10 -10
- package/src/util/isDataRecord.ts +5 -5
- package/src/util/test/createTestRenderer.tsx +9 -2
- package/src/widgets/AccessorBindings.spec.tsx +4 -4
- package/src/widgets/HtmlElement.spec.tsx +6 -6
- package/src/widgets/ReactElementWrapper.spec.tsx +37 -37
- package/src/widgets/Sandbox.ts +103 -103
- package/src/widgets/form/ValidationGroup.spec.tsx +12 -12
- package/src/widgets/grid/GridCell.ts +143 -143
- package/src/widgets/icons/calendar.tsx +22 -17
- package/src/widgets/icons/check.tsx +14 -13
- package/src/widgets/icons/clear.tsx +16 -15
- package/src/widgets/icons/close.tsx +20 -20
- package/src/widgets/icons/cx.tsx +39 -38
- package/src/widgets/icons/drop-down.tsx +16 -15
- package/src/widgets/icons/file.tsx +14 -13
- package/src/widgets/icons/folder-open.tsx +16 -15
- package/src/widgets/icons/folder.tsx +14 -13
- package/src/widgets/icons/forward.tsx +23 -22
- package/src/widgets/icons/loading.tsx +25 -24
- package/src/widgets/icons/menu.tsx +18 -17
- package/src/widgets/icons/pixel-picker.tsx +18 -18
- package/src/widgets/icons/search.tsx +14 -13
- package/src/widgets/icons/sort-asc.tsx +15 -14
- package/src/widgets/icons/square.tsx +19 -18
- package/src/widgets/nav/Route.spec.tsx +2 -2
- package/src/widgets/nav/Route.ts +142 -142
- package/src/widgets/overlay/Dropdown.tsx +762 -762
- package/src/widgets/overlay/MsgBox.tsx +141 -141
- package/src/widgets/overlay/Toast.ts +111 -111
- package/src/widgets/overlay/Window.tsx +299 -299
- package/src/widgets/overlay/alerts.ts +46 -46
- package/src/widgets/overlay/index.ts +11 -11
|
@@ -1,88 +1,88 @@
|
|
|
1
|
-
import { View, ViewConfig } from "./View";
|
|
2
|
-
import { Binding } from "./Binding";
|
|
3
|
-
|
|
4
|
-
export interface AugmentedViewBaseConfig extends ViewConfig {
|
|
5
|
-
store: View<any>;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export class AugmentedViewBase<D = any> extends View<D> {
|
|
9
|
-
declare immutable: boolean;
|
|
10
|
-
declare store: View;
|
|
11
|
-
|
|
12
|
-
constructor(config: AugmentedViewBaseConfig) {
|
|
13
|
-
super(config);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
getData() {
|
|
17
|
-
if (this.sealed && this.meta.version === this.cache.version && this.meta === this.store.meta)
|
|
18
|
-
return this.cache.result;
|
|
19
|
-
let parentStoreData = this.store.getData();
|
|
20
|
-
let result = this.getBaseData(parentStoreData);
|
|
21
|
-
this.embedAugmentData(result, parentStoreData);
|
|
22
|
-
this.cache.result = result;
|
|
23
|
-
this.cache.parentStoreData = parentStoreData;
|
|
24
|
-
this.cache.version = this.meta.version;
|
|
25
|
-
this.meta = this.store.meta;
|
|
26
|
-
return this.cache.result;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
protected getBaseData(parentStoreData: any): any {
|
|
30
|
-
if (this.sealed || this.immutable || this.store.sealed) return { ...parentStoreData };
|
|
31
|
-
return parentStoreData;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
protected embedAugmentData(result: any, parentStoreData: any): void {
|
|
35
|
-
throw new Error("abstract");
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
protected isExtraKey(key: string): boolean {
|
|
39
|
-
throw new Error("abstract");
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Stores which need to support nested aliases should override this method
|
|
43
|
-
protected getExtraKeyBinding(key: string): any {
|
|
44
|
-
let binding = Binding.get(key);
|
|
45
|
-
return this.isExtraKey(binding.parts[0]) ? Binding.get(binding.parts[0]) : null;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
protected setExtraKeyValue(key: string, value: any): boolean {
|
|
49
|
-
throw new Error("abstract");
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
protected deleteExtraKeyValue(key: string): boolean {
|
|
53
|
-
throw new Error("abstract");
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
setItem(path: string, value: any): boolean {
|
|
57
|
-
let extraKeyBinding = this.getExtraKeyBinding(path);
|
|
58
|
-
if (extraKeyBinding) {
|
|
59
|
-
let binding = Binding.get(path);
|
|
60
|
-
let newValue = value;
|
|
61
|
-
if (binding.parts.length > extraKeyBinding.parts.length) {
|
|
62
|
-
let data = {};
|
|
63
|
-
this.embedAugmentData(data, this.store.getData());
|
|
64
|
-
let binding = Binding.get(path);
|
|
65
|
-
data = binding.set(data, value);
|
|
66
|
-
newValue = extraKeyBinding.value(data);
|
|
67
|
-
}
|
|
68
|
-
return this.setExtraKeyValue(extraKeyBinding.path, newValue);
|
|
69
|
-
}
|
|
70
|
-
return super.setItem(path, value);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
deleteItem(path: string): boolean {
|
|
74
|
-
let extraKeyBinding = this.getExtraKeyBinding(path);
|
|
75
|
-
if (extraKeyBinding) {
|
|
76
|
-
if (path == extraKeyBinding.path) return this.deleteExtraKeyValue(extraKeyBinding.path);
|
|
77
|
-
let data = {};
|
|
78
|
-
this.embedAugmentData(data, this.store.getData());
|
|
79
|
-
let binding = Binding.get(path);
|
|
80
|
-
data = binding.delete(data);
|
|
81
|
-
let newValue = extraKeyBinding.value(data);
|
|
82
|
-
return this.setExtraKeyValue(extraKeyBinding.path, newValue);
|
|
83
|
-
}
|
|
84
|
-
return super.deleteItem(path);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
AugmentedViewBase.prototype.immutable = false;
|
|
1
|
+
import { View, ViewConfig } from "./View";
|
|
2
|
+
import { Binding } from "./Binding";
|
|
3
|
+
|
|
4
|
+
export interface AugmentedViewBaseConfig extends ViewConfig {
|
|
5
|
+
store: View<any>;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export class AugmentedViewBase<D = any> extends View<D> {
|
|
9
|
+
declare immutable: boolean;
|
|
10
|
+
declare store: View;
|
|
11
|
+
|
|
12
|
+
constructor(config: AugmentedViewBaseConfig) {
|
|
13
|
+
super(config);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
getData() {
|
|
17
|
+
if (this.sealed && this.meta.version === this.cache.version && this.meta === this.store.meta)
|
|
18
|
+
return this.cache.result;
|
|
19
|
+
let parentStoreData = this.store.getData();
|
|
20
|
+
let result = this.getBaseData(parentStoreData);
|
|
21
|
+
this.embedAugmentData(result, parentStoreData);
|
|
22
|
+
this.cache.result = result;
|
|
23
|
+
this.cache.parentStoreData = parentStoreData;
|
|
24
|
+
this.cache.version = this.meta.version;
|
|
25
|
+
this.meta = this.store.meta;
|
|
26
|
+
return this.cache.result;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
protected getBaseData(parentStoreData: any): any {
|
|
30
|
+
if (this.sealed || this.immutable || this.store.sealed) return { ...parentStoreData };
|
|
31
|
+
return parentStoreData;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
protected embedAugmentData(result: any, parentStoreData: any): void {
|
|
35
|
+
throw new Error("abstract");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
protected isExtraKey(key: string): boolean {
|
|
39
|
+
throw new Error("abstract");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Stores which need to support nested aliases should override this method
|
|
43
|
+
protected getExtraKeyBinding(key: string): any {
|
|
44
|
+
let binding = Binding.get(key);
|
|
45
|
+
return this.isExtraKey(binding.parts[0]) ? Binding.get(binding.parts[0]) : null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
protected setExtraKeyValue(key: string, value: any): boolean {
|
|
49
|
+
throw new Error("abstract");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
protected deleteExtraKeyValue(key: string): boolean {
|
|
53
|
+
throw new Error("abstract");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
setItem(path: string, value: any): boolean {
|
|
57
|
+
let extraKeyBinding = this.getExtraKeyBinding(path);
|
|
58
|
+
if (extraKeyBinding) {
|
|
59
|
+
let binding = Binding.get(path);
|
|
60
|
+
let newValue = value;
|
|
61
|
+
if (binding.parts.length > extraKeyBinding.parts.length) {
|
|
62
|
+
let data = {};
|
|
63
|
+
this.embedAugmentData(data, this.store.getData());
|
|
64
|
+
let binding = Binding.get(path);
|
|
65
|
+
data = binding.set(data, value);
|
|
66
|
+
newValue = extraKeyBinding.value(data);
|
|
67
|
+
}
|
|
68
|
+
return this.setExtraKeyValue(extraKeyBinding.path, newValue);
|
|
69
|
+
}
|
|
70
|
+
return super.setItem(path, value);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
deleteItem(path: string): boolean {
|
|
74
|
+
let extraKeyBinding = this.getExtraKeyBinding(path);
|
|
75
|
+
if (extraKeyBinding) {
|
|
76
|
+
if (path == extraKeyBinding.path) return this.deleteExtraKeyValue(extraKeyBinding.path);
|
|
77
|
+
let data = {};
|
|
78
|
+
this.embedAugmentData(data, this.store.getData());
|
|
79
|
+
let binding = Binding.get(path);
|
|
80
|
+
data = binding.delete(data);
|
|
81
|
+
let newValue = extraKeyBinding.value(data);
|
|
82
|
+
return this.setExtraKeyValue(extraKeyBinding.path, newValue);
|
|
83
|
+
}
|
|
84
|
+
return super.deleteItem(path);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
AugmentedViewBase.prototype.immutable = false;
|
package/src/data/Binding.ts
CHANGED
|
@@ -1,104 +1,104 @@
|
|
|
1
|
-
import { isString } from "../util/isString";
|
|
2
|
-
import { isObject } from "../util/isObject";
|
|
3
|
-
import { isAccessorChain } from "./createAccessorModelProxy";
|
|
4
|
-
import { AccessorChain } from "./createAccessorModelProxy";
|
|
5
|
-
import { hasStringAtKey, hasValueAtKey } from "../util/hasKey";
|
|
6
|
-
|
|
7
|
-
let bindingCache: Record<string, Binding<any>> = {};
|
|
8
|
-
|
|
9
|
-
export interface BindingObject {
|
|
10
|
-
bind: string;
|
|
11
|
-
defaultValue?: any;
|
|
12
|
-
throttle?: number;
|
|
13
|
-
debounce?: number;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export type BindingInput<T = any> = string | BindingObject | Binding<T> | AccessorChain<T>;
|
|
17
|
-
|
|
18
|
-
export type ValueGetter<T> = (state: any) => T | undefined;
|
|
19
|
-
|
|
20
|
-
export class Binding<T = any> {
|
|
21
|
-
public readonly path: string;
|
|
22
|
-
public readonly parts: readonly string[];
|
|
23
|
-
public readonly value: ValueGetter<T>;
|
|
24
|
-
|
|
25
|
-
constructor(path: string) {
|
|
26
|
-
this.path = path;
|
|
27
|
-
this.parts = path.split(".") as readonly string[];
|
|
28
|
-
let body = "return x";
|
|
29
|
-
for (let i = 0; i < this.parts.length; i++) body += '?.["' + this.parts[i] + '"]';
|
|
30
|
-
this.value = new Function("x", body) as ValueGetter<T>;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
set<S extends Record<string, any> = any>(state: S, value: T): S {
|
|
34
|
-
const cv = this.value(state);
|
|
35
|
-
if (cv === value) return state;
|
|
36
|
-
|
|
37
|
-
const ns = Object.assign({}, state) as S;
|
|
38
|
-
let o: any = ns;
|
|
39
|
-
|
|
40
|
-
for (let i = 0; i < this.parts.length; i++) {
|
|
41
|
-
const part = this.parts[i];
|
|
42
|
-
const no = i === this.parts.length - 1 ? value : Object.assign({}, o[part]);
|
|
43
|
-
o[part] = no;
|
|
44
|
-
o = no;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return ns;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
delete<S extends Record<string, any> = any>(state: S): S {
|
|
51
|
-
const ns = Object.assign({}, state) as S;
|
|
52
|
-
let o: any = ns;
|
|
53
|
-
let part: string;
|
|
54
|
-
|
|
55
|
-
for (let i = 0; i < this.parts.length - 1; i++) {
|
|
56
|
-
part = this.parts[i];
|
|
57
|
-
const no = Object.assign({}, o[part]);
|
|
58
|
-
o[part] = no;
|
|
59
|
-
o = no;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
part = this.parts[this.parts.length - 1];
|
|
63
|
-
if (!o.hasOwnProperty(part)) return state;
|
|
64
|
-
|
|
65
|
-
delete o[part];
|
|
66
|
-
|
|
67
|
-
return ns;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
static get<T = any>(path: BindingInput<T>): Binding<T> {
|
|
71
|
-
if (isString(path)) {
|
|
72
|
-
let b = bindingCache[path] as Binding<T> | undefined;
|
|
73
|
-
if (b) return b;
|
|
74
|
-
|
|
75
|
-
b = new Binding<T>(path);
|
|
76
|
-
bindingCache[path] = b;
|
|
77
|
-
return b;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (isBindingObject(path)) return this.get<T>(path.bind);
|
|
81
|
-
|
|
82
|
-
if (path instanceof Binding) return path as Binding<T>;
|
|
83
|
-
|
|
84
|
-
if (isAccessorChain(path)) return this.get<T>((path as AccessorChain<T>).toString());
|
|
85
|
-
|
|
86
|
-
throw new Error("Invalid binding definition provided.");
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export function isBinding(value: unknown): value is BindingInput {
|
|
91
|
-
if (isObject(value)) {
|
|
92
|
-
if (hasStringAtKey(value, "bind")) return true;
|
|
93
|
-
if (hasValueAtKey(value, "isAccessorChain", true)) return true;
|
|
94
|
-
}
|
|
95
|
-
return value instanceof Binding;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export type BindingValue<B> = B extends Binding<infer T> ? T : unknown;
|
|
99
|
-
|
|
100
|
-
export function isBindingObject(value: unknown): value is BindingObject {
|
|
101
|
-
return isObject(value) && hasStringAtKey(value, "bind");
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export { bindingCache };
|
|
1
|
+
import { isString } from "../util/isString";
|
|
2
|
+
import { isObject } from "../util/isObject";
|
|
3
|
+
import { isAccessorChain } from "./createAccessorModelProxy";
|
|
4
|
+
import { AccessorChain } from "./createAccessorModelProxy";
|
|
5
|
+
import { hasStringAtKey, hasValueAtKey } from "../util/hasKey";
|
|
6
|
+
|
|
7
|
+
let bindingCache: Record<string, Binding<any>> = {};
|
|
8
|
+
|
|
9
|
+
export interface BindingObject {
|
|
10
|
+
bind: string;
|
|
11
|
+
defaultValue?: any;
|
|
12
|
+
throttle?: number;
|
|
13
|
+
debounce?: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type BindingInput<T = any> = string | BindingObject | Binding<T> | AccessorChain<T>;
|
|
17
|
+
|
|
18
|
+
export type ValueGetter<T> = (state: any) => T | undefined;
|
|
19
|
+
|
|
20
|
+
export class Binding<T = any> {
|
|
21
|
+
public readonly path: string;
|
|
22
|
+
public readonly parts: readonly string[];
|
|
23
|
+
public readonly value: ValueGetter<T>;
|
|
24
|
+
|
|
25
|
+
constructor(path: string) {
|
|
26
|
+
this.path = path;
|
|
27
|
+
this.parts = path.split(".") as readonly string[];
|
|
28
|
+
let body = "return x";
|
|
29
|
+
for (let i = 0; i < this.parts.length; i++) body += '?.["' + this.parts[i] + '"]';
|
|
30
|
+
this.value = new Function("x", body) as ValueGetter<T>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
set<S extends Record<string, any> = any>(state: S, value: T): S {
|
|
34
|
+
const cv = this.value(state);
|
|
35
|
+
if (cv === value) return state;
|
|
36
|
+
|
|
37
|
+
const ns = Object.assign({}, state) as S;
|
|
38
|
+
let o: any = ns;
|
|
39
|
+
|
|
40
|
+
for (let i = 0; i < this.parts.length; i++) {
|
|
41
|
+
const part = this.parts[i];
|
|
42
|
+
const no = i === this.parts.length - 1 ? value : Object.assign({}, o[part]);
|
|
43
|
+
o[part] = no;
|
|
44
|
+
o = no;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return ns;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
delete<S extends Record<string, any> = any>(state: S): S {
|
|
51
|
+
const ns = Object.assign({}, state) as S;
|
|
52
|
+
let o: any = ns;
|
|
53
|
+
let part: string;
|
|
54
|
+
|
|
55
|
+
for (let i = 0; i < this.parts.length - 1; i++) {
|
|
56
|
+
part = this.parts[i];
|
|
57
|
+
const no = Object.assign({}, o[part]);
|
|
58
|
+
o[part] = no;
|
|
59
|
+
o = no;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
part = this.parts[this.parts.length - 1];
|
|
63
|
+
if (!o.hasOwnProperty(part)) return state;
|
|
64
|
+
|
|
65
|
+
delete o[part];
|
|
66
|
+
|
|
67
|
+
return ns;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
static get<T = any>(path: BindingInput<T>): Binding<T> {
|
|
71
|
+
if (isString(path)) {
|
|
72
|
+
let b = bindingCache[path] as Binding<T> | undefined;
|
|
73
|
+
if (b) return b;
|
|
74
|
+
|
|
75
|
+
b = new Binding<T>(path);
|
|
76
|
+
bindingCache[path] = b;
|
|
77
|
+
return b;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (isBindingObject(path)) return this.get<T>(path.bind);
|
|
81
|
+
|
|
82
|
+
if (path instanceof Binding) return path as Binding<T>;
|
|
83
|
+
|
|
84
|
+
if (isAccessorChain(path)) return this.get<T>((path as AccessorChain<T>).toString());
|
|
85
|
+
|
|
86
|
+
throw new Error("Invalid binding definition provided.");
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function isBinding(value: unknown): value is BindingInput {
|
|
91
|
+
if (isObject(value)) {
|
|
92
|
+
if (hasStringAtKey(value, "bind")) return true;
|
|
93
|
+
if (hasValueAtKey(value, "isAccessorChain", true)) return true;
|
|
94
|
+
}
|
|
95
|
+
return value instanceof Binding;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export type BindingValue<B> = B extends Binding<infer T> ? T : unknown;
|
|
99
|
+
|
|
100
|
+
export function isBindingObject(value: unknown): value is BindingObject {
|
|
101
|
+
return isObject(value) && hasStringAtKey(value, "bind");
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export { bindingCache };
|
|
@@ -1,95 +1,95 @@
|
|
|
1
|
-
import { View } from "./View";
|
|
2
|
-
import { Binding } from "./Binding";
|
|
3
|
-
|
|
4
|
-
export interface ExposedRecordViewConfig {
|
|
5
|
-
store: View;
|
|
6
|
-
itemIndex: number;
|
|
7
|
-
immutable?: boolean;
|
|
8
|
-
collectionBinding: any;
|
|
9
|
-
recordName: string;
|
|
10
|
-
indexName: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export class ExposedRecordView<D = any> extends View<D> {
|
|
14
|
-
declare store: View;
|
|
15
|
-
itemIndex: number;
|
|
16
|
-
immutable: boolean;
|
|
17
|
-
collectionBinding: Binding;
|
|
18
|
-
recordName: string;
|
|
19
|
-
indexName: string;
|
|
20
|
-
|
|
21
|
-
constructor(config: ExposedRecordViewConfig) {
|
|
22
|
-
super(config);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
getData(): any {
|
|
26
|
-
if (
|
|
27
|
-
this.sealed &&
|
|
28
|
-
this.meta.version === this.cache.version &&
|
|
29
|
-
this.cache.itemIndex === this.itemIndex &&
|
|
30
|
-
this.meta === this.store.meta
|
|
31
|
-
)
|
|
32
|
-
return this.cache.result;
|
|
33
|
-
|
|
34
|
-
this.cache.result = this.embed(this.store.getData());
|
|
35
|
-
this.cache.version = this.meta.version;
|
|
36
|
-
this.cache.itemIndex = this.itemIndex;
|
|
37
|
-
this.meta = this.store.meta;
|
|
38
|
-
return this.cache.result;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
embed(data: any) {
|
|
42
|
-
const collection = this.collectionBinding.value(data);
|
|
43
|
-
const record = collection[this.itemIndex];
|
|
44
|
-
const copy = this.sealed || this.immutable || this.store.sealed ? { ...data } : data;
|
|
45
|
-
copy[this.recordName] = record;
|
|
46
|
-
if (this.indexName) copy[this.indexName] = this.itemIndex;
|
|
47
|
-
return copy;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
setIndex(index: number) {
|
|
51
|
-
this.itemIndex = index;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
setItem(path: string, value: any) {
|
|
55
|
-
if (path == this.recordName || path.indexOf(this.recordName + ".") == 0) {
|
|
56
|
-
const storeData = this.store.getData();
|
|
57
|
-
const collection = this.collectionBinding.value(storeData);
|
|
58
|
-
const data = this.embed(storeData);
|
|
59
|
-
const d = Binding.get(path).set(data, value);
|
|
60
|
-
if (d === data) return false;
|
|
61
|
-
const record = d[this.recordName];
|
|
62
|
-
const newCollection = [
|
|
63
|
-
...collection.slice(0, this.itemIndex),
|
|
64
|
-
record,
|
|
65
|
-
...collection.slice(this.itemIndex + 1),
|
|
66
|
-
];
|
|
67
|
-
return this.store.setItem(this.collectionBinding.path, newCollection);
|
|
68
|
-
}
|
|
69
|
-
return this.store.setItem(path, value);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
deleteItem(path: string) {
|
|
73
|
-
let storeData, collection, newCollection;
|
|
74
|
-
|
|
75
|
-
if (path == this.recordName) {
|
|
76
|
-
storeData = this.store.getData();
|
|
77
|
-
collection = this.collectionBinding.value(storeData);
|
|
78
|
-
newCollection = [...collection.slice(0, this.itemIndex), ...collection.slice(this.itemIndex + 1)];
|
|
79
|
-
return this.store.setItem(this.collectionBinding.path, newCollection);
|
|
80
|
-
} else if (path.indexOf(this.recordName + ".") == 0) {
|
|
81
|
-
storeData = this.store.getData();
|
|
82
|
-
collection = this.collectionBinding.value(storeData);
|
|
83
|
-
const data = this.embed(storeData);
|
|
84
|
-
const d = Binding.get(path).delete(data);
|
|
85
|
-
if (d === data) return false;
|
|
86
|
-
const record = d[this.recordName];
|
|
87
|
-
newCollection = [...collection.slice(0, this.itemIndex), record, ...collection.slice(this.itemIndex + 1)];
|
|
88
|
-
return this.store.setItem(this.collectionBinding.path, newCollection);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return this.store.deleteItem(path);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
ExposedRecordView.prototype.immutable = false;
|
|
1
|
+
import { View } from "./View";
|
|
2
|
+
import { Binding } from "./Binding";
|
|
3
|
+
|
|
4
|
+
export interface ExposedRecordViewConfig {
|
|
5
|
+
store: View;
|
|
6
|
+
itemIndex: number;
|
|
7
|
+
immutable?: boolean;
|
|
8
|
+
collectionBinding: any;
|
|
9
|
+
recordName: string;
|
|
10
|
+
indexName: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class ExposedRecordView<D = any> extends View<D> {
|
|
14
|
+
declare store: View;
|
|
15
|
+
itemIndex: number;
|
|
16
|
+
immutable: boolean;
|
|
17
|
+
collectionBinding: Binding;
|
|
18
|
+
recordName: string;
|
|
19
|
+
indexName: string;
|
|
20
|
+
|
|
21
|
+
constructor(config: ExposedRecordViewConfig) {
|
|
22
|
+
super(config);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
getData(): any {
|
|
26
|
+
if (
|
|
27
|
+
this.sealed &&
|
|
28
|
+
this.meta.version === this.cache.version &&
|
|
29
|
+
this.cache.itemIndex === this.itemIndex &&
|
|
30
|
+
this.meta === this.store.meta
|
|
31
|
+
)
|
|
32
|
+
return this.cache.result;
|
|
33
|
+
|
|
34
|
+
this.cache.result = this.embed(this.store.getData());
|
|
35
|
+
this.cache.version = this.meta.version;
|
|
36
|
+
this.cache.itemIndex = this.itemIndex;
|
|
37
|
+
this.meta = this.store.meta;
|
|
38
|
+
return this.cache.result;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
embed(data: any) {
|
|
42
|
+
const collection = this.collectionBinding.value(data);
|
|
43
|
+
const record = collection[this.itemIndex];
|
|
44
|
+
const copy = this.sealed || this.immutable || this.store.sealed ? { ...data } : data;
|
|
45
|
+
copy[this.recordName] = record;
|
|
46
|
+
if (this.indexName) copy[this.indexName] = this.itemIndex;
|
|
47
|
+
return copy;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
setIndex(index: number) {
|
|
51
|
+
this.itemIndex = index;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
setItem(path: string, value: any) {
|
|
55
|
+
if (path == this.recordName || path.indexOf(this.recordName + ".") == 0) {
|
|
56
|
+
const storeData = this.store.getData();
|
|
57
|
+
const collection = this.collectionBinding.value(storeData);
|
|
58
|
+
const data = this.embed(storeData);
|
|
59
|
+
const d = Binding.get(path).set(data, value);
|
|
60
|
+
if (d === data) return false;
|
|
61
|
+
const record = d[this.recordName];
|
|
62
|
+
const newCollection = [
|
|
63
|
+
...collection.slice(0, this.itemIndex),
|
|
64
|
+
record,
|
|
65
|
+
...collection.slice(this.itemIndex + 1),
|
|
66
|
+
];
|
|
67
|
+
return this.store.setItem(this.collectionBinding.path, newCollection);
|
|
68
|
+
}
|
|
69
|
+
return this.store.setItem(path, value);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
deleteItem(path: string) {
|
|
73
|
+
let storeData, collection, newCollection;
|
|
74
|
+
|
|
75
|
+
if (path == this.recordName) {
|
|
76
|
+
storeData = this.store.getData();
|
|
77
|
+
collection = this.collectionBinding.value(storeData);
|
|
78
|
+
newCollection = [...collection.slice(0, this.itemIndex), ...collection.slice(this.itemIndex + 1)];
|
|
79
|
+
return this.store.setItem(this.collectionBinding.path, newCollection);
|
|
80
|
+
} else if (path.indexOf(this.recordName + ".") == 0) {
|
|
81
|
+
storeData = this.store.getData();
|
|
82
|
+
collection = this.collectionBinding.value(storeData);
|
|
83
|
+
const data = this.embed(storeData);
|
|
84
|
+
const d = Binding.get(path).delete(data);
|
|
85
|
+
if (d === data) return false;
|
|
86
|
+
const record = d[this.recordName];
|
|
87
|
+
newCollection = [...collection.slice(0, this.itemIndex), record, ...collection.slice(this.itemIndex + 1)];
|
|
88
|
+
return this.store.setItem(this.collectionBinding.path, newCollection);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return this.store.deleteItem(path);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
ExposedRecordView.prototype.immutable = false;
|