@asyra/ui-context 0.2.4 → 0.5.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/LICENSE +21 -0
- package/README.md +13 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/property-registry.d.ts +78 -0
- package/dist/property-registry.d.ts.map +1 -0
- package/dist/property-registry.js +119 -0
- package/dist/property-registry.js.map +1 -0
- package/dist/ui-context.d.ts +9 -21
- package/dist/ui-context.d.ts.map +1 -1
- package/dist/ui-context.js +58 -81
- package/dist/ui-context.js.map +1 -1
- package/package.json +24 -9
- package/.turbo/turbo-test$colon$ci.log +0 -117
- package/.turbo/turbo-test$colon$local.log +0 -23
- package/.turbo/turbo-test.log +0 -0
- package/CHANGELOG.md +0 -49
- package/coverage/base.css +0 -224
- package/coverage/block-navigation.js +0 -87
- package/coverage/clover.xml +0 -538
- package/coverage/coverage-final.json +0 -7443
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +0 -176
- package/coverage/prettify.css +0 -1
- package/coverage/prettify.js +0 -2
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +0 -196
- package/coverage/src/index.html +0 -146
- package/coverage/src/index.ts.html +0 -97
- package/coverage/src/stores/index.html +0 -146
- package/coverage/src/stores/render.ts.html +0 -106
- package/coverage/src/stores/scene-tree.ts.html +0 -790
- package/coverage/src/stores/selection.ts.html +0 -220
- package/coverage/src/stores/system-context/index.html +0 -146
- package/coverage/src/stores/system-context/index.ts.html +0 -88
- package/coverage/src/stores/system-context/primary-tool.ts.html +0 -109
- package/coverage/src/stores/system-context/system-context.ts.html +0 -85
- package/coverage/src/subscribes/index.html +0 -161
- package/coverage/src/subscribes/index.ts.html +0 -124
- package/coverage/src/subscribes/render.ts.html +0 -151
- package/coverage/src/subscribes/scene-tree.ts.html +0 -373
- package/coverage/src/subscribes/selection.ts.html +0 -253
- package/coverage/src/subscribes/system-context/index.html +0 -131
- package/coverage/src/subscribes/system-context/index.ts.html +0 -100
- package/coverage/src/subscribes/system-context/primary-tool.ts.html +0 -151
- package/coverage/src/types.ts.html +0 -124
- package/coverage/src/ui-context.ts.html +0 -568
- package/dist/__tests__/ui-context.test.d.ts +0 -2
- package/dist/__tests__/ui-context.test.d.ts.map +0 -1
- package/dist/__tests__/ui-context.test.js +0 -170
- package/dist/__tests__/ui-context.test.js.map +0 -1
- package/dist/stores/__tests__/render.test.d.ts +0 -2
- package/dist/stores/__tests__/render.test.d.ts.map +0 -1
- package/dist/stores/__tests__/render.test.js +0 -30
- package/dist/stores/__tests__/render.test.js.map +0 -1
- package/dist/stores/__tests__/selection.test.d.ts +0 -2
- package/dist/stores/__tests__/selection.test.d.ts.map +0 -1
- package/dist/stores/__tests__/selection.test.js +0 -128
- package/dist/stores/__tests__/selection.test.js.map +0 -1
- package/dist/stores/render.d.ts +0 -4
- package/dist/stores/render.d.ts.map +0 -1
- package/dist/stores/render.js +0 -7
- package/dist/stores/render.js.map +0 -1
- package/dist/stores/scene-tree.d.ts +0 -35
- package/dist/stores/scene-tree.d.ts.map +0 -1
- package/dist/stores/scene-tree.js +0 -158
- package/dist/stores/scene-tree.js.map +0 -1
- package/dist/stores/selection.d.ts +0 -8
- package/dist/stores/selection.d.ts.map +0 -1
- package/dist/stores/selection.js +0 -38
- package/dist/stores/selection.js.map +0 -1
- package/dist/stores/system-context/__tests__/primary-tool.test.d.ts +0 -2
- package/dist/stores/system-context/__tests__/primary-tool.test.d.ts.map +0 -1
- package/dist/stores/system-context/__tests__/primary-tool.test.js +0 -27
- package/dist/stores/system-context/__tests__/primary-tool.test.js.map +0 -1
- package/dist/stores/system-context/index.d.ts +0 -2
- package/dist/stores/system-context/index.d.ts.map +0 -1
- package/dist/stores/system-context/index.js +0 -2
- package/dist/stores/system-context/index.js.map +0 -1
- package/dist/stores/system-context/primary-tool.d.ts +0 -5
- package/dist/stores/system-context/primary-tool.d.ts.map +0 -1
- package/dist/stores/system-context/primary-tool.js +0 -7
- package/dist/stores/system-context/primary-tool.js.map +0 -1
- package/dist/stores/system-context/system-context.d.ts +0 -1
- package/dist/stores/system-context/system-context.d.ts.map +0 -1
- package/dist/stores/system-context/system-context.js +0 -2
- package/dist/stores/system-context/system-context.js.map +0 -1
- package/dist/subscribes/index.d.ts +0 -5
- package/dist/subscribes/index.d.ts.map +0 -1
- package/dist/subscribes/index.js +0 -12
- package/dist/subscribes/index.js.map +0 -1
- package/dist/subscribes/render.d.ts +0 -2
- package/dist/subscribes/render.d.ts.map +0 -1
- package/dist/subscribes/render.js +0 -15
- package/dist/subscribes/render.js.map +0 -1
- package/dist/subscribes/scene-tree.d.ts +0 -5
- package/dist/subscribes/scene-tree.d.ts.map +0 -1
- package/dist/subscribes/scene-tree.js +0 -71
- package/dist/subscribes/scene-tree.js.map +0 -1
- package/dist/subscribes/selection.d.ts +0 -5
- package/dist/subscribes/selection.d.ts.map +0 -1
- package/dist/subscribes/selection.js +0 -42
- package/dist/subscribes/selection.js.map +0 -1
- package/dist/subscribes/system-context/index.d.ts +0 -2
- package/dist/subscribes/system-context/index.d.ts.map +0 -1
- package/dist/subscribes/system-context/index.js +0 -5
- package/dist/subscribes/system-context/index.js.map +0 -1
- package/dist/subscribes/system-context/primary-tool.d.ts +0 -4
- package/dist/subscribes/system-context/primary-tool.d.ts.map +0 -1
- package/dist/subscribes/system-context/primary-tool.js +0 -15
- package/dist/subscribes/system-context/primary-tool.js.map +0 -1
- package/dist/types.d.ts +0 -11
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/src/__tests__/ui-context.test.ts +0 -220
- package/src/index.ts +0 -4
- package/src/stores/__tests__/render.test.ts +0 -38
- package/src/stores/__tests__/selection.test.ts +0 -190
- package/src/stores/render.ts +0 -7
- package/src/stores/scene-tree.ts +0 -235
- package/src/stores/selection.ts +0 -45
- package/src/stores/system-context/__tests__/primary-tool.test.ts +0 -37
- package/src/stores/system-context/index.ts +0 -1
- package/src/stores/system-context/primary-tool.ts +0 -8
- package/src/stores/system-context/system-context.ts +0 -0
- package/src/subscribes/index.ts +0 -13
- package/src/subscribes/render.ts +0 -22
- package/src/subscribes/scene-tree.ts +0 -96
- package/src/subscribes/selection.ts +0 -56
- package/src/subscribes/system-context/index.ts +0 -5
- package/src/subscribes/system-context/primary-tool.ts +0 -22
- package/src/types.ts +0 -13
- package/src/ui-context.ts +0 -161
- package/tsconfig.json +0 -17
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Asa Tsai
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1 +1,13 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@asyra/ui-context`
|
|
2
|
+
|
|
3
|
+
Framework and app state projection for UI consumers without transferring
|
|
4
|
+
canonical state ownership to presentation code.
|
|
5
|
+
|
|
6
|
+
```ts
|
|
7
|
+
import uiContext from '@asyra/ui-context'
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Release support
|
|
11
|
+
|
|
12
|
+
The `0.2.5` ESM artifact supports Node.js 24.x. Use only package-root exports.
|
|
13
|
+
See the [Framework release support contract](../../docs/ai/framework/RELEASE_SUPPORT.md).
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import uiContext from './ui-context';
|
|
2
|
-
export
|
|
3
|
-
export {
|
|
1
|
+
import uiContext, { UIContext } from './ui-context.js';
|
|
2
|
+
export { UIContext };
|
|
3
|
+
export { propertyRegistry } from './property-registry.js';
|
|
4
|
+
export type { PropertyValue, PropertyRegistration, TriggerConfig, PropertyComputeContext } from './property-registry.js';
|
|
5
|
+
export default uiContext;
|
|
4
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,EAAE,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAEtD,OAAO,EAAE,SAAS,EAAE,CAAA;AACpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AACzD,YAAY,EACV,aAAa,EACb,oBAAoB,EACpB,aAAa,EACb,sBAAsB,EACvB,MAAM,wBAAwB,CAAA;AAC/B,eAAe,SAAS,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import uiContext from './ui-context';
|
|
2
|
-
export
|
|
3
|
-
export {
|
|
1
|
+
import uiContext, { UIContext } from './ui-context.js';
|
|
2
|
+
export { UIContext };
|
|
3
|
+
export { propertyRegistry } from './property-registry.js';
|
|
4
|
+
export default uiContext;
|
|
4
5
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,EAAE,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAEtD,OAAO,EAAE,SAAS,EAAE,CAAA;AACpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAOzD,eAAe,SAAS,CAAA"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { BehaviorSubject } from 'rxjs';
|
|
2
|
+
import type { SceneTreeYjsChange, ComputedAttrs, RegistrationDefinitionMetadata } from '@asyra/utils';
|
|
3
|
+
export type PropertyValue = string | number | boolean | null | Set<string> | string[] | Record<string, unknown>[] | Record<string, unknown> | undefined;
|
|
4
|
+
export interface TriggerConfig {
|
|
5
|
+
/** YJS change action to watch for */
|
|
6
|
+
action?: string;
|
|
7
|
+
/** Specific key within the action (for element properties) */
|
|
8
|
+
key?: string;
|
|
9
|
+
/** Whether selection changes should trigger recompute */
|
|
10
|
+
onSelectionChange?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface PropertyComputeContext<TElementData extends object = Record<never, never>> {
|
|
13
|
+
selectedIds: Set<string>;
|
|
14
|
+
elements: (ComputedAttrs & TElementData)[];
|
|
15
|
+
}
|
|
16
|
+
/** Preserve default-facade assignability while retaining app callback input. */
|
|
17
|
+
type PropertyCompute<T extends PropertyValue, TElementData extends object> = {
|
|
18
|
+
bivarianceHack(context: PropertyComputeContext<TElementData>): T;
|
|
19
|
+
}['bivarianceHack'];
|
|
20
|
+
export interface PropertyRegistration<T extends PropertyValue, TElementData extends object = Record<never, never>> {
|
|
21
|
+
defaultValue: T;
|
|
22
|
+
/** Optional registration-graph metadata owned by the defining package. */
|
|
23
|
+
registration?: RegistrationDefinitionMetadata;
|
|
24
|
+
/**
|
|
25
|
+
* If true, this is an aggregate property computed from selected elements.
|
|
26
|
+
* The system will automatically compute shared values (MIXED if different).
|
|
27
|
+
*/
|
|
28
|
+
aggregate?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Optional computed key for aggregate properties.
|
|
31
|
+
* Defaults to the property key when omitted.
|
|
32
|
+
*/
|
|
33
|
+
aggregateKey?: keyof ComputedAttrs;
|
|
34
|
+
/**
|
|
35
|
+
* Custom compute function for derived properties.
|
|
36
|
+
* When provided, it takes priority over aggregate computation.
|
|
37
|
+
*/
|
|
38
|
+
compute?: PropertyCompute<T, TElementData>;
|
|
39
|
+
/**
|
|
40
|
+
* Value to use when selection is empty. Defaults to defaultValue.
|
|
41
|
+
*/
|
|
42
|
+
emptyValue?: T;
|
|
43
|
+
/**
|
|
44
|
+
* Source observable for the property.
|
|
45
|
+
* The property value will sync from this observable.
|
|
46
|
+
* Used for system properties from systemContext observables.
|
|
47
|
+
*/
|
|
48
|
+
source$?: BehaviorSubject<T>;
|
|
49
|
+
/**
|
|
50
|
+
* Triggers that cause this property to recompute.
|
|
51
|
+
* Only used for aggregate properties.
|
|
52
|
+
*/
|
|
53
|
+
triggers?: TriggerConfig;
|
|
54
|
+
}
|
|
55
|
+
export declare class PropertyRegistry {
|
|
56
|
+
private properties;
|
|
57
|
+
private registrations;
|
|
58
|
+
private subscriptions;
|
|
59
|
+
private yjsFilters;
|
|
60
|
+
register<T extends PropertyValue, TElementData extends object = Record<never, never>>(key: string, config: PropertyRegistration<T, TElementData>): void;
|
|
61
|
+
private setupYJSFilter;
|
|
62
|
+
getMatchingProperties(change: SceneTreeYjsChange['payload']): string[];
|
|
63
|
+
getSelectionTriggeredKeys(): string[];
|
|
64
|
+
isAggregateProperty(key: string): boolean;
|
|
65
|
+
shouldRecomputeOnSelectionChange(key: string): boolean;
|
|
66
|
+
get<T extends PropertyValue>(key: string): T | undefined;
|
|
67
|
+
set<T extends PropertyValue>(key: string, value: T): void;
|
|
68
|
+
onChange<T extends PropertyValue>(key: string, callback: (value: T) => void): () => void;
|
|
69
|
+
getSubject(key: string): BehaviorSubject<PropertyValue> | undefined;
|
|
70
|
+
getAllPropertyKeys(): string[];
|
|
71
|
+
getAggregatePropertyKeys(): string[];
|
|
72
|
+
getRegistration<T extends PropertyValue, TElementData extends object = Record<never, never>>(key: string): PropertyRegistration<T, TElementData> | undefined;
|
|
73
|
+
unregister(key: string): void;
|
|
74
|
+
clear(): void;
|
|
75
|
+
}
|
|
76
|
+
export declare const propertyRegistry: PropertyRegistry;
|
|
77
|
+
export {};
|
|
78
|
+
//# sourceMappingURL=property-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"property-registry.d.ts","sourceRoot":"","sources":["../src/property-registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,MAAM,CAAA;AACtC,OAAO,KAAK,EACV,kBAAkB,EAClB,aAAa,EACb,8BAA8B,EAC/B,MAAM,cAAc,CAAA;AAWrB,MAAM,MAAM,aAAa,GACrB,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,GAAG,CAAC,MAAM,CAAC,GACX,MAAM,EAAE,GACR,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GACzB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACvB,SAAS,CAAA;AAEb,MAAM,WAAW,aAAa;IAC5B,qCAAqC;IACrC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,8DAA8D;IAC9D,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,yD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3
|
+
const lodash = lodashModule.default ?? lodashModule;
|
|
4
|
+
const { isEqual } = lodash;
|
|
5
|
+
export class PropertyRegistry {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.properties = new Map();
|
|
8
|
+
/* eslint-disable-next-line @typescript-eslint/no-explicit-any -- heterogeneous property types */
|
|
9
|
+
this.registrations = new Map();
|
|
10
|
+
this.subscriptions = new Map();
|
|
11
|
+
this.yjsFilters = new Map();
|
|
12
|
+
}
|
|
13
|
+
register(key, config) {
|
|
14
|
+
if (this.properties.has(key)) {
|
|
15
|
+
console.warn(`[PropertyRegistry] Property "${key}" already registered, skipping`);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const subject = new BehaviorSubject(config.defaultValue);
|
|
19
|
+
this.properties.set(key, subject);
|
|
20
|
+
this.registrations.set(key, config);
|
|
21
|
+
// Setup YJS filter for aggregate properties with triggers
|
|
22
|
+
if (config.aggregate && config.triggers) {
|
|
23
|
+
this.setupYJSFilter(key, config.triggers);
|
|
24
|
+
}
|
|
25
|
+
// Setup subscription for properties with source$
|
|
26
|
+
if (config.source$) {
|
|
27
|
+
const subscription = config.source$.subscribe((value) => {
|
|
28
|
+
subject.next(value);
|
|
29
|
+
});
|
|
30
|
+
this.subscriptions.set(key, subscription);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
setupYJSFilter(key, trigger) {
|
|
34
|
+
this.yjsFilters.set(key, (change) => {
|
|
35
|
+
if (trigger.action && change.action !== trigger.action)
|
|
36
|
+
return false;
|
|
37
|
+
if (trigger.key && 'key' in change && change.key !== trigger.key)
|
|
38
|
+
return false;
|
|
39
|
+
return true;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
getMatchingProperties(change) {
|
|
43
|
+
const matching = [];
|
|
44
|
+
this.yjsFilters.forEach((filter, key) => {
|
|
45
|
+
if (filter(change)) {
|
|
46
|
+
matching.push(key);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
return matching;
|
|
50
|
+
}
|
|
51
|
+
getSelectionTriggeredKeys() {
|
|
52
|
+
return Array.from(this.registrations.entries())
|
|
53
|
+
.filter(([, config]) => config.triggers?.onSelectionChange)
|
|
54
|
+
.map(([key]) => key);
|
|
55
|
+
}
|
|
56
|
+
isAggregateProperty(key) {
|
|
57
|
+
return this.registrations.get(key)?.aggregate ?? false;
|
|
58
|
+
}
|
|
59
|
+
shouldRecomputeOnSelectionChange(key) {
|
|
60
|
+
return this.registrations.get(key)?.triggers?.onSelectionChange ?? false;
|
|
61
|
+
}
|
|
62
|
+
get(key) {
|
|
63
|
+
return this.properties.get(key)?.getValue();
|
|
64
|
+
}
|
|
65
|
+
set(key, value) {
|
|
66
|
+
const subject = this.properties.get(key);
|
|
67
|
+
if (!subject) {
|
|
68
|
+
console.warn(`[PropertyRegistry] Property "${key}" not found`);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const currentValue = subject.getValue();
|
|
72
|
+
if (!isEqual(currentValue, value)) {
|
|
73
|
+
subject.next(value);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
onChange(key, callback) {
|
|
77
|
+
const subject = this.properties.get(key);
|
|
78
|
+
if (!subject) {
|
|
79
|
+
console.warn(`[PropertyRegistry] Cannot subscribe to "${key}", property not found`);
|
|
80
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
81
|
+
return () => { };
|
|
82
|
+
}
|
|
83
|
+
const subscription = subject.subscribe((value) => {
|
|
84
|
+
callback(value);
|
|
85
|
+
});
|
|
86
|
+
return () => subscription.unsubscribe();
|
|
87
|
+
}
|
|
88
|
+
getSubject(key) {
|
|
89
|
+
return this.properties.get(key);
|
|
90
|
+
}
|
|
91
|
+
getAllPropertyKeys() {
|
|
92
|
+
return Array.from(this.properties.keys());
|
|
93
|
+
}
|
|
94
|
+
getAggregatePropertyKeys() {
|
|
95
|
+
return Array.from(this.registrations.entries())
|
|
96
|
+
.filter(([, config]) => config.aggregate)
|
|
97
|
+
.map(([key]) => key);
|
|
98
|
+
}
|
|
99
|
+
getRegistration(key) {
|
|
100
|
+
return this.registrations.get(key);
|
|
101
|
+
}
|
|
102
|
+
unregister(key) {
|
|
103
|
+
const subscription = this.subscriptions.get(key);
|
|
104
|
+
subscription?.unsubscribe();
|
|
105
|
+
this.subscriptions.delete(key);
|
|
106
|
+
this.properties.delete(key);
|
|
107
|
+
this.registrations.delete(key);
|
|
108
|
+
this.yjsFilters.delete(key);
|
|
109
|
+
}
|
|
110
|
+
clear() {
|
|
111
|
+
this.subscriptions.forEach((sub) => sub.unsubscribe());
|
|
112
|
+
this.subscriptions.clear();
|
|
113
|
+
this.properties.clear();
|
|
114
|
+
this.registrations.clear();
|
|
115
|
+
this.yjsFilters.clear();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
export const propertyRegistry = new PropertyRegistry();
|
|
119
|
+
//# sourceMappingURL=property-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"property-registry.js","sourceRoot":"","sources":["../src/property-registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,MAAM,CAAA;AAMtC,OAAO,KAAK,YAAY,MAAM,QAAQ,CAAA;AAEtC,MAAM,MAAM,GAER,YAGD,CAAC,OAAO,IAAI,YAAY,CAAA;AAC3B,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAA;AAyE1B,MAAM,OAAO,gBAAgB;IAA7B;QACU,eAAU,GAAG,IAAI,GAAG,EAA0C,CAAA;QACtE,iGAAiG;QACzF,kBAAa,GAAG,IAAI,GAAG,EAA0C,CAAA;QACjE,kBAAa,GAAG,IAAI,GAAG,EAAuC,CAAA;QAC9D,eAAU,GAAG,IAAI,GAAG,EAGzB,CAAA;IA2IL,CAAC;IAzIC,QAAQ,CAGN,GAAW,EAAE,MAA6C;QAC1D,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAC7B,OAAO,CA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pB,MAAM,YAAY,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAChD,YAAY,EAAE,WAAW,EAAE,CAAA;QAC3B,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QAC9B,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QAC3B,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QAC9B,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;IAC7B,CAAC;IAED,KAAK;QACH,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,CAAA;QACtD,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAA;QAC1B,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAA;QACvB,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAA;QAC1B,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAA;IACzB,CAAC;CACF;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,gBAAgB,EAAE,CAAA"}
|
package/dist/ui-context.d.ts
CHANGED
|
@@ -1,26 +1,14 @@
|
|
|
1
1
|
import { BehaviorSubject } from 'rxjs';
|
|
2
|
-
import {
|
|
3
|
-
import { ElementProperties } from './types';
|
|
2
|
+
import { PropertyValue, PropertyComputeContext, PropertyRegistration } from './property-registry.js';
|
|
4
3
|
declare class UIContext {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
rotation: BehaviorSubject<ElementProperties['rotation']>;
|
|
14
|
-
primaryTool: BehaviorSubject<PrimaryToolType>;
|
|
15
|
-
constructor();
|
|
16
|
-
updateElementSelection(selectedIds: Set<string>): void;
|
|
17
|
-
updateVertexSelection(selectedIds: Set<string>): void;
|
|
18
|
-
updateComputedProperty<K extends keyof ComputedAttrs>(key: K, data: ComputedAttrs[K][]): void;
|
|
19
|
-
updateComputedProperties(allElementData: ComputedAttrs[]): void;
|
|
20
|
-
computedSharedProperty<K extends keyof ElementProperties>(data: ElementProperties[K][]): "MIX" | ElementProperties[K];
|
|
21
|
-
computeSharedProperties(allElementData: ComputedAttrs[]): ElementProperties;
|
|
22
|
-
updateZoom(newZoom: number): void;
|
|
23
|
-
updatePrimaryTool(tool: PrimaryToolType): void;
|
|
4
|
+
registerProperty<T extends PropertyValue, TElementData extends object = Record<never, never>>(key: string, config: PropertyRegistration<T, TElementData>): void;
|
|
5
|
+
get<T extends PropertyValue>(key: string): T | undefined;
|
|
6
|
+
set<T extends PropertyValue>(key: string, value: T): void;
|
|
7
|
+
getSubject<T extends PropertyValue>(key: string): BehaviorSubject<T> | undefined;
|
|
8
|
+
onChange<T extends PropertyValue>(key: string, callback: (value: T) => void): () => void;
|
|
9
|
+
recomputeSelectionProperties(context: PropertyComputeContext): void;
|
|
10
|
+
recomputeProperties(keys: string[], context: PropertyComputeContext): void;
|
|
11
|
+
private computePropertyValue;
|
|
24
12
|
}
|
|
25
13
|
declare const uiContext: UIContext;
|
|
26
14
|
export default uiContext;
|
package/dist/ui-context.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ui-context.d.ts","sourceRoot":"","sources":["../src/ui-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"ui-context.d.ts","sourceRoot":"","sources":["../src/ui-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,MAAM,CAAA;AAGtC,OAAO,EAEL,aAAa,EACb,sBAAsB,EACtB,oBAAoB,EACrB,MAAM,wBAAwB,CAAA;AAU/B,cAAM,SAAS;IACb,gBAAgB,CACd,CAAC,SAAS,aAAa,EACvB,YAAY,SAAS,MAAM,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,EAClD,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,oBAAoB,CAAC,CAAC,EAAE,YAAY,CAAC,GAAG,IAAI;IAInE,GAAG,CAAC,CAAC,SAAS,aAAa,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAIxD,GAAG,CAAC,CAAC,SAAS,aAAa,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI;IAIzD,UAAU,CAAC,CAAC,SAAS,aAAa,EAChC,GAAG,EAAE,MAAM,GACV,eAAe,CAAC,CAAC,CAAC,GAAG,SAAS;IAIjC,QAAQ,CAAC,CAAC,SAAS,aAAa,EAC9B,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAC3B,MAAM,IAAI;IAIb,4BAA4B,CAAC,OAAO,EAAE,sBAAsB,GAAG,IAAI;IAQnE,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,sBAAsB,GAAG,IAAI;IAS1E,OAAO,CAAC,oBAAoB;CAoC7B;AAED,QAAA,MAAM,SAAS,WAAkB,CAAA;AAEjC,eAAe,SAAS,CAAA;AACxB,OAAO,EAAE,SAAS,EAAE,CAAA"}
|
package/dist/ui-context.js
CHANGED
|
@@ -1,101 +1,78 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
'y',
|
|
7
|
-
'width',
|
|
8
|
-
'height',
|
|
9
|
-
'rotation'
|
|
10
|
-
];
|
|
1
|
+
import { MIXED_STRING } from '@asyra/utils';
|
|
2
|
+
import * as lodashModule from 'lodash';
|
|
3
|
+
import { propertyRegistry } from './property-registry.js';
|
|
4
|
+
const lodash = lodashModule.default ?? lodashModule;
|
|
5
|
+
const { isEqual } = lodash;
|
|
11
6
|
class UIContext {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
this.flattenedElementIds = new BehaviorSubject([]);
|
|
15
|
-
this.elementSelection = new BehaviorSubject(new Set());
|
|
16
|
-
this.vertexSelection = new BehaviorSubject(new Set());
|
|
17
|
-
this.x = new BehaviorSubject(0);
|
|
18
|
-
this.y = new BehaviorSubject(0);
|
|
19
|
-
this.width = new BehaviorSubject(0);
|
|
20
|
-
this.height = new BehaviorSubject(0);
|
|
21
|
-
this.rotation = new BehaviorSubject(0);
|
|
22
|
-
// this.fills = new BehaviorSubject<ElementProperties['fills']>([])
|
|
23
|
-
this.primaryTool = new BehaviorSubject(PrimaryToolType.SELECT);
|
|
7
|
+
registerProperty(key, config) {
|
|
8
|
+
propertyRegistry.register(key, config);
|
|
24
9
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
this.elementSelection.next(selectedIds);
|
|
28
|
-
}
|
|
10
|
+
get(key) {
|
|
11
|
+
return propertyRegistry.get(key);
|
|
29
12
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
13
|
+
set(key, value) {
|
|
14
|
+
propertyRegistry.set(key, value);
|
|
15
|
+
}
|
|
16
|
+
getSubject(key) {
|
|
17
|
+
return propertyRegistry.getSubject(key);
|
|
34
18
|
}
|
|
35
|
-
|
|
36
|
-
|
|
19
|
+
onChange(key, callback) {
|
|
20
|
+
return propertyRegistry.onChange(key, callback);
|
|
21
|
+
}
|
|
22
|
+
recomputeSelectionProperties(context) {
|
|
23
|
+
const keys = propertyRegistry.getSelectionTriggeredKeys();
|
|
24
|
+
if (keys.length === 0) {
|
|
37
25
|
return;
|
|
38
26
|
}
|
|
39
|
-
|
|
40
|
-
if (generalKeysToCompare.includes(compareKey)) {
|
|
41
|
-
const result = this.computedSharedProperty(data);
|
|
42
|
-
if (result !== this[compareKey].getValue()) {
|
|
43
|
-
this[compareKey].next(result);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
27
|
+
this.recomputeProperties(keys, context);
|
|
46
28
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (
|
|
51
|
-
|
|
29
|
+
recomputeProperties(keys, context) {
|
|
30
|
+
keys.forEach((key) => {
|
|
31
|
+
const nextValue = this.computePropertyValue(key, context);
|
|
32
|
+
if (nextValue !== SKIP_UPDATE) {
|
|
33
|
+
propertyRegistry.set(key, nextValue);
|
|
52
34
|
}
|
|
53
35
|
});
|
|
54
36
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const result = {};
|
|
60
|
-
result.x = compareValues(allElementData, 'x');
|
|
61
|
-
result.y = compareValues(allElementData, 'y');
|
|
62
|
-
result.width = compareValues(allElementData, 'width');
|
|
63
|
-
result.height = compareValues(allElementData, 'height');
|
|
64
|
-
result.rotation = compareValues(allElementData, 'rotation');
|
|
65
|
-
return result;
|
|
66
|
-
}
|
|
67
|
-
updateZoom(newZoom) {
|
|
68
|
-
this.zoom.next(newZoom);
|
|
69
|
-
}
|
|
70
|
-
updatePrimaryTool(tool) {
|
|
71
|
-
if (tool !== this.primaryTool.getValue()) {
|
|
72
|
-
this.primaryTool.next(tool);
|
|
37
|
+
computePropertyValue(key, context) {
|
|
38
|
+
const registration = propertyRegistry.getRegistration(key);
|
|
39
|
+
if (!registration) {
|
|
40
|
+
return SKIP_UPDATE;
|
|
73
41
|
}
|
|
42
|
+
if (registration.source$) {
|
|
43
|
+
return SKIP_UPDATE;
|
|
44
|
+
}
|
|
45
|
+
const emptyValue = registration.emptyValue ?? registration.defaultValue;
|
|
46
|
+
if (context.selectedIds.size === 0) {
|
|
47
|
+
return emptyValue;
|
|
48
|
+
}
|
|
49
|
+
if (registration.compute) {
|
|
50
|
+
return registration.compute(context);
|
|
51
|
+
}
|
|
52
|
+
if (registration.aggregate) {
|
|
53
|
+
const aggregateKey = registration.aggregateKey ?? key;
|
|
54
|
+
const values = context.elements
|
|
55
|
+
.map((element) => element[aggregateKey])
|
|
56
|
+
.filter((value) => value !== undefined);
|
|
57
|
+
if (values.length === 0) {
|
|
58
|
+
return emptyValue;
|
|
59
|
+
}
|
|
60
|
+
return compareAggregateValues(values);
|
|
61
|
+
}
|
|
62
|
+
return SKIP_UPDATE;
|
|
74
63
|
}
|
|
75
64
|
}
|
|
76
65
|
const uiContext = new UIContext();
|
|
77
66
|
export default uiContext;
|
|
78
67
|
export { UIContext };
|
|
79
|
-
const
|
|
80
|
-
const firstValue =
|
|
81
|
-
let
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
isMixed = true;
|
|
85
|
-
break;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return isMixed ? MIXED_STRING : firstValue;
|
|
89
|
-
};
|
|
90
|
-
const compareValues = (allElementData, compareKey) => {
|
|
91
|
-
const firstValue = allElementData[0][compareKey];
|
|
92
|
-
let isMixed = false;
|
|
93
|
-
for (let i = 1; i < allElementData.length; i++) {
|
|
94
|
-
if (allElementData[i][compareKey] !== firstValue) {
|
|
95
|
-
isMixed = true;
|
|
96
|
-
break;
|
|
68
|
+
const compareAggregateValues = (values) => {
|
|
69
|
+
const firstValue = values[0];
|
|
70
|
+
for (let i = 1; i < values.length; i++) {
|
|
71
|
+
if (!isEqual(values[i], firstValue)) {
|
|
72
|
+
return MIXED_STRING;
|
|
97
73
|
}
|
|
98
74
|
}
|
|
99
|
-
return
|
|
75
|
+
return firstValue;
|
|
100
76
|
};
|
|
77
|
+
const SKIP_UPDATE = Symbol('skip-ui-property-update');
|
|
101
78
|
//# sourceMappingURL=ui-context.js.map
|
package/dist/ui-context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ui-context.js","sourceRoot":"","sources":["../src/ui-context.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ui-context.js","sourceRoot":"","sources":["../src/ui-context.ts"],"names":[],"mappings":"AACA,OAAO,EAAiB,YAAY,EAAE,MAAM,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AS,EAAE,CAAA;AAEpB,MAAM,sBAAsB,GAAG,CAAC,MAAiB,EAAiB,EAAE;IAClE,MAAM,UAAU,GAAG,MAAM,CAAC,CAAC,CAAC,CAAA;IAC5B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACvC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,EAAE,CAAC;YACpC,OAAO,YAAY,CAAA;QACrB,CAAC;IACH,CAAC;IACD,OAAO,UAA2B,CAAA;AACpC,CAAC,CAAA;AAED,MAAM,WAAW,GAAG,MAAM,CAAC,yBAAyB,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,20 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asyra/ui-context",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Manages and optimizes data from data contexts for UI consumption, ensuring efficient rendering and framework flexibility.",
|
|
5
5
|
"author": "Asa Tsai",
|
|
6
6
|
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"engines": {
|
|
9
|
+
"node": "24.x"
|
|
10
|
+
},
|
|
7
11
|
"packageManager": "yarn@4.3.1",
|
|
8
12
|
"keywords": [],
|
|
9
13
|
"main": "dist/index.js",
|
|
10
14
|
"types": "dist/index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"import": "./dist/index.js",
|
|
19
|
+
"default": "./dist/index.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist",
|
|
24
|
+
"!dist/**/__tests__",
|
|
25
|
+
"!dist/**/*.test.*",
|
|
26
|
+
"!dist/**/*.spec.*",
|
|
27
|
+
"!dist/**/*.stories.*"
|
|
28
|
+
],
|
|
11
29
|
"scripts": {
|
|
12
30
|
"dev": "tsc --watch --preserveWatchOutput",
|
|
13
31
|
"build:ui-context": "tsc",
|
|
14
32
|
"clean": "rm -rf dist",
|
|
15
33
|
"has:test": "find . -type f \\( -name \"*.test.ts\" -o -name \"*.test.tsx\" \\) | grep -q .",
|
|
16
34
|
"test": "yarn has:test && vitest || echo 'No test files found. Skipping test.'",
|
|
17
|
-
"test:local": "
|
|
35
|
+
"test:local": "vitest run",
|
|
18
36
|
"test:ci": "yarn has:test && vitest run --coverage --reporter=default --reporter=junit || echo 'No test files found. Skipping test:ci.'"
|
|
19
37
|
},
|
|
20
38
|
"devDependencies": {
|
|
@@ -24,13 +42,10 @@
|
|
|
24
42
|
"vitest": "^2.1.8"
|
|
25
43
|
},
|
|
26
44
|
"dependencies": {
|
|
27
|
-
"@asyra/
|
|
28
|
-
"@asyra/
|
|
29
|
-
"@asyra/
|
|
30
|
-
"@asyra/selection": "^0.2.4",
|
|
31
|
-
"@asyra/utils": "^0.2.4",
|
|
45
|
+
"@asyra/scene-tree": "0.5.0",
|
|
46
|
+
"@asyra/selection": "0.5.0",
|
|
47
|
+
"@asyra/utils": "0.5.0",
|
|
32
48
|
"lodash": "^4.17.21",
|
|
33
|
-
"rxjs": "^7.8.1"
|
|
34
|
-
"yjs": "13.6.20"
|
|
49
|
+
"rxjs": "^7.8.1"
|
|
35
50
|
}
|
|
36
51
|
}
|