@suey/rxp-meta 0.0.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.
Files changed (41) hide show
  1. package/LICENSE.md +21 -0
  2. package/dist/commonjs/base/InnerZustandStoreManager.d.ts +14 -0
  3. package/dist/commonjs/base/InnerZustandStoreManager.js +32 -0
  4. package/dist/commonjs/extension/ExtensionManager.d.ts +14 -0
  5. package/dist/commonjs/extension/ExtensionManager.js +150 -0
  6. package/dist/commonjs/extension/declare.d.ts +13 -0
  7. package/dist/commonjs/extension/declare.js +2 -0
  8. package/dist/commonjs/extension/index.d.ts +2 -0
  9. package/dist/commonjs/extension/index.js +5 -0
  10. package/dist/commonjs/index.d.ts +3 -0
  11. package/dist/commonjs/index.js +21 -0
  12. package/dist/commonjs/metadata/MetadataManager.d.ts +19 -0
  13. package/dist/commonjs/metadata/MetadataManager.js +181 -0
  14. package/dist/commonjs/metadata/declare.d.ts +19 -0
  15. package/dist/commonjs/metadata/declare.js +2 -0
  16. package/dist/commonjs/metadata/index.d.ts +2 -0
  17. package/dist/commonjs/metadata/index.js +5 -0
  18. package/dist/commonjs/rApp.d.ts +99 -0
  19. package/dist/commonjs/rApp.js +102 -0
  20. package/dist/commonjs/tsconfig.tsbuildinfo +1 -0
  21. package/dist/esm/base/InnerZustandStoreManager.js +28 -0
  22. package/dist/esm/extension/ExtensionManager.js +146 -0
  23. package/dist/esm/extension/declare.js +1 -0
  24. package/dist/esm/extension/index.js +1 -0
  25. package/dist/esm/index.js +3 -0
  26. package/dist/esm/metadata/MetadataManager.js +177 -0
  27. package/dist/esm/metadata/declare.js +1 -0
  28. package/dist/esm/metadata/index.js +1 -0
  29. package/dist/esm/rApp.js +99 -0
  30. package/dist/esm/tsconfig.tsbuildinfo +1 -0
  31. package/dist/lib/base/InnerZustandStoreManager.d.ts +41 -0
  32. package/dist/lib/extension/ExtensionManager.d.ts +48 -0
  33. package/dist/lib/extension/declare.d.ts +31 -0
  34. package/dist/lib/extension/index.d.ts +2 -0
  35. package/dist/lib/index.d.ts +3 -0
  36. package/dist/lib/metadata/MetadataManager.d.ts +114 -0
  37. package/dist/lib/metadata/declare.d.ts +48 -0
  38. package/dist/lib/metadata/index.d.ts +2 -0
  39. package/dist/lib/rApp.d.ts +99 -0
  40. package/dist/lib/tsconfig.tsbuildinfo +1 -0
  41. package/package.json +27 -0
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Evrone <mail@evrone.com>
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.
@@ -0,0 +1,14 @@
1
+ export interface InnerStore {
2
+ value: {};
3
+ }
4
+ export type InnerStoreListener = () => void;
5
+ export type InnerStoreDestroyListener = () => void;
6
+ export declare abstract class InnerZustandStoreManager {
7
+ private readonly store;
8
+ private readonly listeners;
9
+ private readonly unsubscribe;
10
+ protected updateStore(): void;
11
+ protected useStoreValue(): {};
12
+ protected subscribe(listener: InnerStoreListener): InnerStoreDestroyListener;
13
+ protected destroy(): void;
14
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InnerZustandStoreManager = void 0;
4
+ const zustand_1 = require("zustand");
5
+ const immer_1 = require("zustand/middleware/immer");
6
+ class InnerZustandStoreManager {
7
+ store = (0, zustand_1.create)()((0, immer_1.immer)(() => {
8
+ return {
9
+ value: {}
10
+ };
11
+ }));
12
+ listeners = new Set();
13
+ unsubscribe = this.store.subscribe(() => {
14
+ this.listeners.forEach(listener => listener());
15
+ });
16
+ updateStore() {
17
+ this.store.setState({ value: {} });
18
+ }
19
+ useStoreValue() {
20
+ return this.store(store => store.value);
21
+ }
22
+ subscribe(listener) {
23
+ this.listeners.add(listener);
24
+ return () => {
25
+ this.listeners.delete(listener);
26
+ };
27
+ }
28
+ destroy() {
29
+ this.unsubscribe();
30
+ }
31
+ }
32
+ exports.InnerZustandStoreManager = InnerZustandStoreManager;
@@ -0,0 +1,14 @@
1
+ import type { Extension, ExtensionName, ExtractExtensionContext } from './declare';
2
+ import { InnerZustandStoreManager } from '../base/InnerZustandStoreManager';
3
+ export declare class ExtensionManager<Ext extends Extension> extends InnerZustandStoreManager {
4
+ private readonly extNameMapStore;
5
+ defineExtension<DExt extends Ext>(define: DExt): DExt;
6
+ isExtension<DExt extends Ext>(extension: DExt | any): extension is DExt;
7
+ hasExtension(extensionName: ExtensionName): boolean;
8
+ getExtension(extensionName: ExtensionName): Extension<any> | null;
9
+ registerExtension<DExt extends Ext>(extension: DExt): void;
10
+ activatedExtension<Context extends ExtractExtensionContext<Ext>>(name: ExtensionName, context: Context): Promise<void>;
11
+ deactivatedExtension<Context extends ExtractExtensionContext<Ext>>(name: ExtensionName, context: Context): Promise<void>;
12
+ delExtension<Context extends ExtractExtensionContext<Ext>>(name: ExtensionName, context: Context): Promise<void>;
13
+ useExtensionsList(): readonly [Extension[]];
14
+ }
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExtensionManager = void 0;
4
+ const InnerZustandStoreManager_1 = require("../base/InnerZustandStoreManager");
5
+ const react_1 = require("react");
6
+ const ExtensionSymbolTag = Symbol('ExtensionSymbolTag');
7
+ class ExtensionManager extends InnerZustandStoreManager_1.InnerZustandStoreManager {
8
+ extNameMapStore = new Map();
9
+ defineExtension(define) {
10
+ if (!Reflect.has(define, 'name'))
11
+ throw new Error(`Extension name is required`);
12
+ if (!(typeof define.name === 'symbol') &&
13
+ !(typeof define.name === 'string'))
14
+ throw new Error(`Extension name must be symbol or string`);
15
+ if (!Reflect.has(define, 'version'))
16
+ throw new Error(`Extension version is required`);
17
+ if (Reflect.has(define, 'onActivated') && !Reflect.has(define, 'onDeactivated'))
18
+ throw new Error(`Extension lifecycle: onActivated and onDeactivated must be set at same time`);
19
+ if (Reflect.has(define, 'onDeactivated') && !Reflect.has(define, 'onActivated'))
20
+ throw new Error(`Extension lifecycle: onActivated and onDeactivated must be set at same time`);
21
+ const name = define.name;
22
+ const version = define.version;
23
+ const onActivated = define.onActivated;
24
+ const onDeactivated = define.onDeactivated;
25
+ const extension = {
26
+ ...define,
27
+ onActivated: async (...args) => {
28
+ if (!this.extNameMapStore.has(name)) {
29
+ console.error(`当前扩展还未注册加载, 但却错误得试图激活`);
30
+ return;
31
+ }
32
+ const lifecycle = this.extNameMapStore.get(name);
33
+ if (!lifecycle)
34
+ return;
35
+ if (lifecycle.isActivated) {
36
+ console.error(`当前扩展已被激活, 但却错误得试图再次激活`);
37
+ return;
38
+ }
39
+ await onActivated?.call(extension, ...args);
40
+ lifecycle.isActivated = true;
41
+ },
42
+ onDeactivated: async (...args) => {
43
+ if (!this.extNameMapStore.has(name)) {
44
+ console.error(`当前扩展还未注册加载, 但却错误得试图去活`);
45
+ return;
46
+ }
47
+ const lifecycle = this.extNameMapStore.get(name);
48
+ if (!lifecycle)
49
+ return;
50
+ if (!lifecycle.isActivated) {
51
+ console.error(`当前扩展未被激活, 但却错误得试图去活`);
52
+ return;
53
+ }
54
+ await onDeactivated?.call(extension, ...args);
55
+ lifecycle.isActivated = false;
56
+ }
57
+ };
58
+ Reflect.defineProperty(extension, '__TAG__', {
59
+ enumerable: false,
60
+ writable: false,
61
+ value: ExtensionSymbolTag,
62
+ configurable: false
63
+ });
64
+ return extension;
65
+ }
66
+ isExtension(extension) {
67
+ if (typeof extension !== 'object')
68
+ return false;
69
+ const hasTAG = Reflect.has(extension, '__TAG__');
70
+ return hasTAG;
71
+ }
72
+ hasExtension(extensionName) {
73
+ const has = this.extNameMapStore.has(extensionName);
74
+ const lifecycle = this.extNameMapStore.get(extensionName);
75
+ if (has && !lifecycle)
76
+ throw new Error(`数据状态异常`);
77
+ return has;
78
+ }
79
+ getExtension(extensionName) {
80
+ if (!this.hasExtension(extensionName))
81
+ return null;
82
+ return this.extNameMapStore.get(extensionName)?.extension ?? null;
83
+ }
84
+ registerExtension(extension) {
85
+ if (!this.isExtension(extension))
86
+ throw new Error(`参数非法, 不是一个有效的扩展`);
87
+ const name = extension.name;
88
+ if (this.hasExtension(name)) {
89
+ console.error(`试图重新注册一个已存在得扩展:应该先移除再注册`);
90
+ return;
91
+ }
92
+ const extensionLifecycle = {
93
+ extension: extension,
94
+ isActivated: false,
95
+ };
96
+ this.extNameMapStore.set(name, extensionLifecycle);
97
+ }
98
+ async activatedExtension(name, context) {
99
+ const lifecycle = this.extNameMapStore.get(name);
100
+ if (!lifecycle)
101
+ throw new Error(`试图激活一个不存在得扩展`);
102
+ if (lifecycle.isActivated)
103
+ return;
104
+ if (lifecycle.extension.onActivated)
105
+ await lifecycle.extension.onActivated(context);
106
+ lifecycle.isActivated = true;
107
+ }
108
+ async deactivatedExtension(name, context) {
109
+ const lifecycle = this.extNameMapStore.get(name);
110
+ if (!lifecycle)
111
+ throw new Error(`试图去活一个不存在得扩展`);
112
+ if (!lifecycle.isActivated)
113
+ return;
114
+ if (lifecycle.extension.onDeactivated)
115
+ await lifecycle.extension.onDeactivated(context);
116
+ lifecycle.isActivated = false;
117
+ }
118
+ async delExtension(name, context) {
119
+ const lifecycle = this.extNameMapStore.get(name);
120
+ if (!lifecycle)
121
+ throw new Error(`试图删除一个不存在得扩展`);
122
+ if (lifecycle.isActivated) {
123
+ if (lifecycle.extension.onDeactivated) {
124
+ await lifecycle.extension.onDeactivated(context);
125
+ }
126
+ }
127
+ if (!lifecycle.isActivated) {
128
+ this.extNameMapStore.delete(name);
129
+ }
130
+ }
131
+ useExtensionsList() {
132
+ const value = this.useStoreValue();
133
+ const [statusState] = (0, react_1.useState)(() => ({
134
+ value: void 0
135
+ }));
136
+ const [normalState] = (0, react_1.useState)({
137
+ extensions: [],
138
+ });
139
+ if (statusState.value !== value) {
140
+ statusState.value = value;
141
+ const extensions = [];
142
+ for (const ext of this.extNameMapStore.values()) {
143
+ extensions.push(ext.extension);
144
+ }
145
+ normalState.extensions = extensions;
146
+ }
147
+ return [normalState.extensions];
148
+ }
149
+ }
150
+ exports.ExtensionManager = ExtensionManager;
@@ -0,0 +1,13 @@
1
+ export type ExtensionName = string | symbol;
2
+ export interface Extension<Context = any> {
3
+ readonly name: ExtensionName;
4
+ readonly version: string | number;
5
+ readonly meta?: any;
6
+ readonly onActivated?: (this: this, context: Context) => (void | Promise<void>);
7
+ readonly onDeactivated?: (this: this, context: Context) => (void | Promise<void>);
8
+ }
9
+ export interface ExtensionWithLifecycle {
10
+ readonly extension: Extension;
11
+ isActivated: boolean;
12
+ }
13
+ export type ExtractExtensionContext<Ext extends Extension> = Parameters<Exclude<Ext['onActivated'], undefined>>[0];
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ export type { Extension, ExtensionName, ExtensionWithLifecycle, ExtractExtensionContext } from './declare';
2
+ export { ExtensionManager } from './ExtensionManager';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExtensionManager = void 0;
4
+ var ExtensionManager_1 = require("./ExtensionManager");
5
+ Object.defineProperty(exports, "ExtensionManager", { enumerable: true, get: function () { return ExtensionManager_1.ExtensionManager; } });
@@ -0,0 +1,3 @@
1
+ export * from './extension';
2
+ export * from './metadata';
3
+ export { Commands } from './rApp';
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.Commands = void 0;
18
+ __exportStar(require("./extension"), exports);
19
+ __exportStar(require("./metadata"), exports);
20
+ var rApp_1 = require("./rApp");
21
+ Object.defineProperty(exports, "Commands", { enumerable: true, get: function () { return rApp_1.Commands; } });
@@ -0,0 +1,19 @@
1
+ import type { ExtractSingleEntries, ExtractVectorEntries, ExtractElInArray, MetadataStoreChangeListener, MetadataStoreListenerPayload } from './declare';
2
+ import { InnerZustandStoreManager } from '../base/InnerZustandStoreManager';
3
+ export declare class MetadataManager<MetadataEntries extends Record<string, any>> extends InnerZustandStoreManager {
4
+ private readonly metadataMap;
5
+ private readonly metadataChangeListeners;
6
+ protected triggerMetadataChangeListeners(payload: MetadataStoreListenerPayload): void;
7
+ subscribeMetadataStoreChanged(listener: MetadataStoreChangeListener): () => void;
8
+ defineMetadata<MetadataKey extends keyof MetadataEntries>(metadataKey: MetadataKey, metadata: MetadataEntries[MetadataKey]): void;
9
+ getMetadata<MetadataKey extends keyof MetadataEntries>(metadataKey: MetadataKey): MetadataEntries[MetadataKey] | null;
10
+ delMetadata<MetadataKey extends keyof MetadataEntries>(metadataKey: MetadataKey): void;
11
+ defineMetadataInSingle<MetadataKey extends keyof ExtractSingleEntries<MetadataEntries>>(metadataKey: MetadataKey, metadata: MetadataEntries[MetadataKey]): void;
12
+ defineMetadataInVector<MetadataKey extends keyof ExtractVectorEntries<MetadataEntries>>(metadataKey: MetadataKey, metadata: ExtractElInArray<MetadataEntries[MetadataKey]>): void;
13
+ delMetadataInVector<MetadataKey extends keyof ExtractVectorEntries<MetadataEntries>>(metadataKey: MetadataKey, metadata: ExtractElInArray<MetadataEntries[MetadataKey]>): void;
14
+ useMetadata<MetadataKey extends keyof MetadataEntries>(metadataKey: MetadataKey): MetadataEntries[MetadataKey] | null;
15
+ useOldestMetadataInVector<MetadataKey extends keyof ExtractVectorEntries<MetadataEntries>>(metadataKey: MetadataKey): ExtractElInArray<MetadataEntries[MetadataKey]> | null;
16
+ useLatestMetadataInVector<MetadataKey extends keyof ExtractVectorEntries<MetadataEntries>>(metadataKey: MetadataKey): ExtractElInArray<MetadataEntries[MetadataKey]> | null;
17
+ useAllMetadata(): Map<string | number | symbol, any>;
18
+ hasMetadata<MetadataKey extends keyof MetadataEntries>(metadataKey: MetadataKey): boolean;
19
+ }
@@ -0,0 +1,181 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MetadataManager = void 0;
4
+ const react_1 = require("react");
5
+ const InnerZustandStoreManager_1 = require("../base/InnerZustandStoreManager");
6
+ class MetadataManager extends InnerZustandStoreManager_1.InnerZustandStoreManager {
7
+ metadataMap = new Map();
8
+ metadataChangeListeners = new Set();
9
+ triggerMetadataChangeListeners(payload) {
10
+ this.metadataChangeListeners.forEach(listener => listener(payload));
11
+ }
12
+ subscribeMetadataStoreChanged(listener) {
13
+ this.metadataChangeListeners.add(listener);
14
+ return () => {
15
+ this.metadataChangeListeners.delete(listener);
16
+ };
17
+ }
18
+ defineMetadata(metadataKey, metadata) {
19
+ this.metadataMap.set(metadataKey, metadata);
20
+ super.updateStore();
21
+ this.triggerMetadataChangeListeners({
22
+ action: 'Define',
23
+ type: 'All',
24
+ metadataKey: metadataKey,
25
+ metadata: metadata
26
+ });
27
+ }
28
+ getMetadata(metadataKey) {
29
+ return (this.metadataMap.get(metadataKey)) ?? null;
30
+ }
31
+ delMetadata(metadataKey) {
32
+ if (!this.hasMetadata(metadataKey))
33
+ return;
34
+ this.metadataMap.delete(metadataKey);
35
+ super.updateStore();
36
+ this.triggerMetadataChangeListeners({
37
+ action: 'Remove',
38
+ type: 'All',
39
+ metadataKey: metadataKey,
40
+ metadata: this.metadataMap.get(metadataKey)
41
+ });
42
+ }
43
+ defineMetadataInSingle(metadataKey, metadata) {
44
+ this.metadataMap.set(metadataKey, metadata);
45
+ super.updateStore();
46
+ this.triggerMetadataChangeListeners({
47
+ action: 'Define',
48
+ type: 'Single',
49
+ metadataKey: metadataKey,
50
+ metadata: metadata
51
+ });
52
+ }
53
+ defineMetadataInVector(metadataKey, metadata) {
54
+ if (!this.hasMetadata(metadataKey)) {
55
+ this.metadataMap.set(metadataKey, [metadata]);
56
+ super.updateStore();
57
+ this.triggerMetadataChangeListeners({
58
+ action: 'Define',
59
+ type: 'Vector',
60
+ metadataKey: metadataKey,
61
+ metadata: [metadata]
62
+ });
63
+ return;
64
+ }
65
+ const vector = this.metadataMap.get(metadataKey);
66
+ if (!Array.isArray(vector))
67
+ throw new Error(`defineMetadataInVector: current metadata value is not an array`);
68
+ const vectorSet = new Set(vector);
69
+ if (vectorSet.has(metadata))
70
+ return;
71
+ vectorSet.add(metadata);
72
+ const newMetadata = Array.from(vectorSet);
73
+ this.metadataMap.set(metadataKey, newMetadata);
74
+ super.updateStore();
75
+ this.triggerMetadataChangeListeners({
76
+ action: 'Define',
77
+ type: 'Vector',
78
+ metadataKey: metadataKey,
79
+ metadata: newMetadata
80
+ });
81
+ }
82
+ delMetadataInVector(metadataKey, metadata) {
83
+ if (!this.hasMetadata(metadataKey))
84
+ return;
85
+ const vector = this.metadataMap.get(metadataKey);
86
+ if (!Array.isArray(vector))
87
+ throw new Error(`delMetadataInVector: current metadata value is not an array`);
88
+ if (vector.length === 0) {
89
+ this.metadataMap.delete(metadataKey);
90
+ return;
91
+ }
92
+ const fVector = vector.filter(v => v !== metadata);
93
+ if (fVector.length === 0) {
94
+ this.metadataMap.delete(metadataKey);
95
+ super.updateStore();
96
+ this.triggerMetadataChangeListeners({
97
+ action: 'Remove',
98
+ type: 'Vector',
99
+ metadataKey: metadataKey,
100
+ metadata: []
101
+ });
102
+ return;
103
+ }
104
+ this.metadataMap.delete(metadataKey);
105
+ super.updateStore();
106
+ this.triggerMetadataChangeListeners({
107
+ action: 'Remove',
108
+ type: 'Vector',
109
+ metadataKey: metadataKey,
110
+ metadata: fVector
111
+ });
112
+ }
113
+ useMetadata(metadataKey) {
114
+ const [_, setState] = (0, react_1.useState)({});
115
+ const [normalState] = (0, react_1.useState)(() => ({
116
+ isMounted: false,
117
+ data: this.getMetadata(metadataKey),
118
+ unsubscribe: void 0
119
+ }));
120
+ const [syncState] = (0, react_1.useState)(() => ({
121
+ needSync: false
122
+ }));
123
+ const updateState = (0, react_1.useMemo)(() => {
124
+ const timeout = 20;
125
+ let timer = void 0;
126
+ return () => {
127
+ if (timer)
128
+ clearTimeout(timer);
129
+ timer = setTimeout(() => {
130
+ timer = void 0;
131
+ if (!normalState.isMounted) {
132
+ syncState.needSync = true;
133
+ return;
134
+ }
135
+ setState({});
136
+ }, timeout);
137
+ };
138
+ }, []);
139
+ if (!normalState.unsubscribe) {
140
+ normalState.unsubscribe = super.subscribe(() => {
141
+ const data = this.getMetadata(metadataKey);
142
+ if (data !== normalState.data) {
143
+ normalState.data = data;
144
+ updateState();
145
+ }
146
+ });
147
+ }
148
+ (0, react_1.useLayoutEffect)(() => {
149
+ normalState.isMounted = true;
150
+ if (syncState.needSync)
151
+ updateState();
152
+ return () => {
153
+ normalState.isMounted = false;
154
+ if (normalState.unsubscribe)
155
+ normalState.unsubscribe();
156
+ normalState.unsubscribe = void 0;
157
+ };
158
+ }, []);
159
+ return normalState.data;
160
+ }
161
+ useOldestMetadataInVector(metadataKey) {
162
+ const metadata = this.useMetadata(metadataKey);
163
+ if (metadata && Array.isArray(metadata))
164
+ return metadata[0] ?? null;
165
+ return null;
166
+ }
167
+ useLatestMetadataInVector(metadataKey) {
168
+ const metadata = this.useMetadata(metadataKey);
169
+ if (metadata && Array.isArray(metadata))
170
+ return metadata[metadata.length - 1] ?? null;
171
+ return null;
172
+ }
173
+ useAllMetadata() {
174
+ super.useStoreValue();
175
+ return this.metadataMap;
176
+ }
177
+ hasMetadata(metadataKey) {
178
+ return this.metadataMap.has(metadataKey);
179
+ }
180
+ }
181
+ exports.MetadataManager = MetadataManager;
@@ -0,0 +1,19 @@
1
+ type IsNever<T, SuccessReturnType, FailReturnType> = T extends never ? SuccessReturnType : FailReturnType;
2
+ type IsAny<T, SuccessReturnType, FailReturnType> = IsNever<T, 'yes', 'no'> extends 'no' ? FailReturnType : SuccessReturnType;
3
+ export type ExtractElInArray<T> = IsAny<T, never, T extends (infer U)[] ? U : never>;
4
+ export type ExtractVectorEntries<Entries> = {
5
+ [Key in keyof Entries as (IsAny<Entries[Key], never, Entries[Key] extends unknown[] ? Key : never>)]: Entries[Key];
6
+ };
7
+ export type ExtractSingleEntries<Entries> = {
8
+ [Key in keyof Entries as Entries[Key] extends unknown[] ? never : Key]: Entries[Key];
9
+ };
10
+ export type MetadataAction = 'Define' | 'Remove';
11
+ export type MetadataType = 'Vector' | 'Single' | 'All';
12
+ export interface MetadataStoreListenerPayload {
13
+ action: MetadataAction;
14
+ type: MetadataType;
15
+ metadataKey: number | string | symbol;
16
+ metadata: unknown;
17
+ }
18
+ export type MetadataStoreChangeListener = (payload: MetadataStoreListenerPayload) => void;
19
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ export { MetadataManager } from './MetadataManager';
2
+ export type { MetadataAction, MetadataType, MetadataStoreChangeListener, MetadataStoreListenerPayload } from './declare';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MetadataManager = void 0;
4
+ var MetadataManager_1 = require("./MetadataManager");
5
+ Object.defineProperty(exports, "MetadataManager", { enumerable: true, get: function () { return MetadataManager_1.MetadataManager; } });
@@ -0,0 +1,99 @@
1
+ export declare const Commands: {
2
+ readonly Ctrl: readonly ["ctrl"];
3
+ readonly CtrlLeft: readonly [];
4
+ readonly CtrlRight: readonly [];
5
+ readonly Command: readonly [];
6
+ readonly Mod: readonly ["mod"];
7
+ readonly Option: readonly [];
8
+ readonly Alt: readonly ["alt"];
9
+ readonly AltLeft: readonly [];
10
+ readonly AltRight: readonly [];
11
+ readonly Shift: readonly [];
12
+ readonly ShiftLeft: readonly [];
13
+ readonly ShiftRight: readonly [];
14
+ readonly Esc: readonly [];
15
+ readonly Enter: readonly [];
16
+ readonly Space: readonly [];
17
+ readonly PageUp: readonly [];
18
+ readonly PageDown: readonly [];
19
+ readonly Home: readonly [];
20
+ readonly End: readonly [];
21
+ readonly Tab: readonly [];
22
+ readonly Backspace: readonly [];
23
+ readonly Delete: readonly [];
24
+ readonly Insert: readonly [];
25
+ readonly ArrowUp: readonly [];
26
+ readonly ArrowDown: readonly [];
27
+ readonly ArrowLeft: readonly [];
28
+ readonly ArrowRight: readonly [];
29
+ readonly PrintScreen: readonly [];
30
+ readonly F1: readonly [];
31
+ readonly F2: readonly [];
32
+ readonly F3: readonly [];
33
+ readonly F4: readonly [];
34
+ readonly F5: readonly [];
35
+ readonly F6: readonly [];
36
+ readonly F7: readonly [];
37
+ readonly F8: readonly [];
38
+ readonly F9: readonly [];
39
+ readonly F10: readonly [];
40
+ readonly F11: readonly [];
41
+ readonly F12: readonly [];
42
+ readonly Num0: readonly [];
43
+ readonly Num1: readonly [];
44
+ readonly Num2: readonly [];
45
+ readonly Num3: readonly [];
46
+ readonly Num4: readonly [];
47
+ readonly Num5: readonly [];
48
+ readonly Num6: readonly [];
49
+ readonly Num7: readonly [];
50
+ readonly Num8: readonly [];
51
+ readonly Num9: readonly [];
52
+ readonly Numpad0: readonly [];
53
+ readonly Numpad1: readonly [];
54
+ readonly Numpad2: readonly [];
55
+ readonly Numpad3: readonly [];
56
+ readonly Numpad4: readonly [];
57
+ readonly Numpad5: readonly [];
58
+ readonly Numpad6: readonly [];
59
+ readonly Numpad7: readonly [];
60
+ readonly Numpad8: readonly [];
61
+ readonly Numpad9: readonly [];
62
+ readonly NumpadAdd: readonly [];
63
+ readonly NumpadSubtract: readonly [];
64
+ readonly NumpadMultiply: readonly [];
65
+ readonly NumpadDivide: readonly [];
66
+ readonly NumpadDecimal: readonly [];
67
+ readonly NumpadEnter: readonly [];
68
+ readonly NumLock: readonly [];
69
+ readonly ScrollLock: readonly [];
70
+ readonly Pause: readonly [];
71
+ readonly CapsLock: readonly [];
72
+ readonly Windows: readonly [];
73
+ readonly A: readonly ["a"];
74
+ readonly B: readonly ["b"];
75
+ readonly C: readonly ["c"];
76
+ readonly D: readonly ["d"];
77
+ readonly E: readonly ["e"];
78
+ readonly F: readonly ["f"];
79
+ readonly G: readonly ["g"];
80
+ readonly H: readonly ["h"];
81
+ readonly I: readonly ["i"];
82
+ readonly J: readonly ["j"];
83
+ readonly K: readonly ["k"];
84
+ readonly L: readonly ["l"];
85
+ readonly M: readonly ["m"];
86
+ readonly N: readonly ["n"];
87
+ readonly O: readonly ["o"];
88
+ readonly P: readonly ["p"];
89
+ readonly Q: readonly ["q"];
90
+ readonly R: readonly ["r"];
91
+ readonly S: readonly ["s"];
92
+ readonly T: readonly ["t"];
93
+ readonly U: readonly ["u"];
94
+ readonly V: readonly ["v"];
95
+ readonly W: readonly ["w"];
96
+ readonly X: readonly ["x"];
97
+ readonly Y: readonly ["y"];
98
+ readonly Z: readonly ["z"];
99
+ };