@accelint/map-toolkit 0.2.0 → 0.3.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/CHANGELOG.md +74 -0
- package/catalog-info.yaml +6 -3
- package/dist/cursor-coordinates/index.d.ts +3 -0
- package/dist/cursor-coordinates/index.js +3 -0
- package/dist/cursor-coordinates/index.js.map +1 -0
- package/dist/cursor-coordinates/use-cursor-coordinates.d.ts +76 -0
- package/dist/cursor-coordinates/use-cursor-coordinates.js +161 -0
- package/dist/cursor-coordinates/use-cursor-coordinates.js.map +1 -0
- package/dist/deckgl/base-map/events.d.ts +1 -0
- package/dist/deckgl/base-map/events.js +2 -1
- package/dist/deckgl/base-map/events.js.map +1 -1
- package/dist/deckgl/base-map/index.d.ts +1 -1
- package/dist/deckgl/base-map/index.js +69 -15
- package/dist/deckgl/base-map/index.js.map +1 -1
- package/dist/deckgl/base-map/provider.d.ts +12 -16
- package/dist/deckgl/base-map/provider.js +2 -6
- package/dist/deckgl/base-map/provider.js.map +1 -1
- package/dist/deckgl/base-map/types.d.ts +29 -8
- package/dist/deckgl/text-layer/character-sets.d.ts +7 -0
- package/dist/deckgl/text-layer/character-sets.js.map +1 -1
- package/dist/deckgl/text-layer/default-settings.js.map +1 -1
- package/dist/decorators/deckgl.d.ts +1 -1
- package/dist/decorators/deckgl.js.map +1 -1
- package/dist/map-mode/index.d.ts +1 -1
- package/dist/map-mode/index.js +1 -1
- package/dist/map-mode/store.d.ts +35 -109
- package/dist/map-mode/store.js +268 -289
- package/dist/map-mode/store.js.map +1 -1
- package/dist/map-mode/use-map-mode.d.ts +3 -5
- package/dist/map-mode/use-map-mode.js +8 -10
- package/dist/map-mode/use-map-mode.js.map +1 -1
- package/dist/metafile-esm.json +1 -1
- package/dist/viewport/constants.d.ts +9 -0
- package/dist/viewport/constants.js +11 -0
- package/dist/viewport/constants.js.map +1 -0
- package/dist/viewport/index.d.ts +13 -0
- package/dist/viewport/index.js +6 -0
- package/dist/viewport/index.js.map +1 -0
- package/dist/viewport/types.d.ts +22 -0
- package/dist/viewport/types.js +3 -0
- package/dist/viewport/types.js.map +1 -0
- package/dist/viewport/use-viewport-state.d.ts +85 -0
- package/dist/viewport/use-viewport-state.js +109 -0
- package/dist/viewport/use-viewport-state.js.map +1 -0
- package/dist/viewport/utils.d.ts +37 -0
- package/dist/viewport/utils.js +46 -0
- package/dist/viewport/utils.js.map +1 -0
- package/dist/viewport/viewport-size.d.ts +42 -0
- package/dist/viewport/viewport-size.js +16 -0
- package/dist/viewport/viewport-size.js.map +1 -0
- package/package.json +15 -20
package/dist/map-mode/store.js
CHANGED
|
@@ -4,324 +4,303 @@ import { MapModeEvents } from './events.js';
|
|
|
4
4
|
|
|
5
5
|
const DEFAULT_MODE = "default";
|
|
6
6
|
const mapModeBus = Broadcast.getInstance();
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
const modeStore = /* @__PURE__ */ new Map();
|
|
8
|
+
const componentSubscribers = /* @__PURE__ */ new Map();
|
|
9
|
+
const busUnsubscribers = /* @__PURE__ */ new Map();
|
|
10
|
+
const subscriptionCache = /* @__PURE__ */ new Map();
|
|
11
|
+
const snapshotCache = /* @__PURE__ */ new Map();
|
|
12
|
+
const requestModeChangeCache = /* @__PURE__ */ new Map();
|
|
13
|
+
function getOrCreateState(instanceId) {
|
|
14
|
+
if (!modeStore.has(instanceId)) {
|
|
15
|
+
modeStore.set(instanceId, {
|
|
16
|
+
mode: DEFAULT_MODE,
|
|
17
|
+
modeOwners: /* @__PURE__ */ new Map(),
|
|
18
|
+
pendingRequests: /* @__PURE__ */ new Map()
|
|
19
|
+
});
|
|
12
20
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Get current mode snapshot (for useSyncExternalStore)
|
|
22
|
-
*/
|
|
23
|
-
getSnapshot = () => {
|
|
24
|
-
return this.mode;
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* Subscribe to mode changes (for useSyncExternalStore)
|
|
28
|
-
*/
|
|
29
|
-
subscribe = (listener) => {
|
|
30
|
-
this.listeners.add(listener);
|
|
31
|
-
return () => {
|
|
32
|
-
this.listeners.delete(listener);
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
/**
|
|
36
|
-
* Request a mode change
|
|
37
|
-
*
|
|
38
|
-
* If the mode change can be auto-accepted (no ownership conflicts), the mode changes immediately.
|
|
39
|
-
* Otherwise, an authorization request is emitted and stored as a pending request.
|
|
40
|
-
*
|
|
41
|
-
* **Important**: If the requester already has a pending authorization request, it will be replaced
|
|
42
|
-
* with this new request. Only one pending request per requester is maintained at a time.
|
|
43
|
-
*
|
|
44
|
-
* @param desiredMode - The mode to switch to (automatically trimmed of whitespace)
|
|
45
|
-
* @param requestOwner - Unique identifier of the component requesting the change (automatically trimmed of whitespace)
|
|
46
|
-
* @throws Error if either parameter is empty or whitespace-only
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* ```ts
|
|
50
|
-
* // First request from 'drawing-tool'
|
|
51
|
-
* store.requestModeChange('drawing', 'drawing-tool');
|
|
52
|
-
* // → Creates pending request with authId 'abc-123'
|
|
53
|
-
*
|
|
54
|
-
* // Second request from same 'drawing-tool' before first is resolved
|
|
55
|
-
* store.requestModeChange('measuring', 'drawing-tool');
|
|
56
|
-
* // → Replaces pending request, new authId 'def-456', old 'abc-123' is discarded
|
|
57
|
-
* ```
|
|
58
|
-
*/
|
|
59
|
-
requestModeChange = (desiredMode, requestOwner) => {
|
|
60
|
-
const trimmedDesiredMode = desiredMode.trim();
|
|
61
|
-
const trimmedRequestOwner = requestOwner.trim();
|
|
62
|
-
if (!trimmedDesiredMode) {
|
|
63
|
-
throw new Error("requestModeChange requires non-empty desiredMode");
|
|
64
|
-
}
|
|
65
|
-
if (!trimmedRequestOwner) {
|
|
66
|
-
throw new Error("requestModeChange requires non-empty requestOwner");
|
|
21
|
+
return modeStore.get(instanceId);
|
|
22
|
+
}
|
|
23
|
+
function notifySubscribers(instanceId) {
|
|
24
|
+
const subscribers = componentSubscribers.get(instanceId);
|
|
25
|
+
if (subscribers) {
|
|
26
|
+
for (const onStoreChange of subscribers) {
|
|
27
|
+
onStoreChange();
|
|
67
28
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function shouldAutoAcceptRequest(state, desiredMode, requestOwner) {
|
|
32
|
+
const currentModeOwner = state.modeOwners.get(state.mode);
|
|
33
|
+
const desiredModeOwner = state.modeOwners.get(desiredMode);
|
|
34
|
+
if (desiredMode === DEFAULT_MODE && requestOwner === currentModeOwner) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
if (requestOwner === currentModeOwner) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
if (!(currentModeOwner || desiredModeOwner)) {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
if (state.mode === DEFAULT_MODE && requestOwner === desiredModeOwner) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
function setMode(instanceId, state, newMode) {
|
|
49
|
+
const previousMode = state.mode;
|
|
50
|
+
state.mode = newMode;
|
|
51
|
+
mapModeBus.emit(MapModeEvents.changed, {
|
|
52
|
+
previousMode,
|
|
53
|
+
currentMode: newMode,
|
|
54
|
+
id: instanceId
|
|
55
|
+
});
|
|
56
|
+
notifySubscribers(instanceId);
|
|
57
|
+
}
|
|
58
|
+
function approveRequestAndRejectOthers(instanceId, state, approvedRequest, excludeAuthId, decisionOwner, reason, emitApproval) {
|
|
59
|
+
const requestsToReject = [];
|
|
60
|
+
for (const request of state.pendingRequests.values()) {
|
|
61
|
+
if (request.authId !== excludeAuthId) {
|
|
62
|
+
requestsToReject.push(request);
|
|
80
63
|
}
|
|
81
64
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
this.unsubscribers.push(unsubRequest);
|
|
98
|
-
const unsubDecision = this.bus.on(MapModeEvents.changeDecision, (event) => {
|
|
99
|
-
const { id, approved, authId, owner } = event.payload;
|
|
100
|
-
if (id !== this.id) {
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
this.handleAuthorizationDecision({ approved, authId, owner });
|
|
65
|
+
state.pendingRequests.clear();
|
|
66
|
+
setMode(instanceId, state, approvedRequest.desiredMode);
|
|
67
|
+
if (approvedRequest.desiredMode !== DEFAULT_MODE) {
|
|
68
|
+
state.modeOwners.set(
|
|
69
|
+
approvedRequest.desiredMode,
|
|
70
|
+
approvedRequest.requestOwner
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
if (emitApproval) {
|
|
74
|
+
mapModeBus.emit(MapModeEvents.changeDecision, {
|
|
75
|
+
authId: approvedRequest.authId,
|
|
76
|
+
approved: true,
|
|
77
|
+
owner: decisionOwner,
|
|
78
|
+
reason,
|
|
79
|
+
id: instanceId
|
|
104
80
|
});
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
81
|
+
}
|
|
82
|
+
for (const request of requestsToReject) {
|
|
83
|
+
mapModeBus.emit(MapModeEvents.changeDecision, {
|
|
84
|
+
authId: request.authId,
|
|
85
|
+
approved: false,
|
|
86
|
+
owner: decisionOwner,
|
|
87
|
+
reason: "Request auto-rejected because another request was approved",
|
|
88
|
+
id: instanceId
|
|
114
89
|
});
|
|
115
|
-
this.unsubscribers.push(unsubChanged);
|
|
116
90
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
91
|
+
}
|
|
92
|
+
function handlePendingRequestsOnDefaultMode(instanceId, state, previousMode) {
|
|
93
|
+
const firstEntry = Array.from(state.pendingRequests.values())[0];
|
|
94
|
+
if (!firstEntry) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const previousModeOwner = state.modeOwners.get(previousMode);
|
|
98
|
+
if (!previousModeOwner) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (firstEntry.desiredMode === DEFAULT_MODE) {
|
|
102
|
+
const allRequests = Array.from(state.pendingRequests.values());
|
|
103
|
+
state.pendingRequests.clear();
|
|
104
|
+
for (const request of allRequests) {
|
|
105
|
+
mapModeBus.emit(MapModeEvents.changeDecision, {
|
|
106
|
+
authId: request.authId,
|
|
107
|
+
approved: false,
|
|
108
|
+
owner: previousModeOwner,
|
|
109
|
+
reason: "Request rejected - already in requested mode",
|
|
110
|
+
id: instanceId
|
|
111
|
+
});
|
|
132
112
|
}
|
|
133
|
-
|
|
113
|
+
} else {
|
|
114
|
+
approveRequestAndRejectOthers(
|
|
115
|
+
instanceId,
|
|
116
|
+
state,
|
|
117
|
+
firstEntry,
|
|
118
|
+
firstEntry.authId,
|
|
119
|
+
previousModeOwner,
|
|
120
|
+
"Auto-accepted when mode owner returned to default",
|
|
121
|
+
true
|
|
122
|
+
);
|
|
134
123
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
return;
|
|
124
|
+
}
|
|
125
|
+
function handleAuthorizationDecision(instanceId, state, payload) {
|
|
126
|
+
const { approved, authId, owner: decisionOwner } = payload;
|
|
127
|
+
const currentModeOwner = state.modeOwners.get(state.mode);
|
|
128
|
+
if (decisionOwner !== currentModeOwner) {
|
|
129
|
+
console.warn(
|
|
130
|
+
`[MapMode] Authorization decision from "${decisionOwner}" ignored - not the owner of mode "${state.mode}" (owner: ${currentModeOwner || "none"})`
|
|
131
|
+
);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
let matchingRequestOwner = null;
|
|
135
|
+
let matchingRequest = null;
|
|
136
|
+
for (const [requestOwner, request] of state.pendingRequests.entries()) {
|
|
137
|
+
if (request.authId === authId) {
|
|
138
|
+
matchingRequestOwner = requestOwner;
|
|
139
|
+
matchingRequest = request;
|
|
140
|
+
break;
|
|
153
141
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
142
|
+
}
|
|
143
|
+
if (!(matchingRequest && matchingRequestOwner)) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
if (approved) {
|
|
147
|
+
approveRequestAndRejectOthers(
|
|
148
|
+
instanceId,
|
|
149
|
+
state,
|
|
150
|
+
matchingRequest,
|
|
162
151
|
authId,
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
152
|
+
decisionOwner,
|
|
153
|
+
"",
|
|
154
|
+
false
|
|
155
|
+
);
|
|
156
|
+
} else {
|
|
157
|
+
state.pendingRequests.delete(matchingRequestOwner);
|
|
167
158
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
* @param payload - The authorization decision containing authId, approved status, and owner
|
|
176
|
-
*/
|
|
177
|
-
handleAuthorizationDecision(payload) {
|
|
178
|
-
const { approved, authId, owner: decisionOwner } = payload;
|
|
179
|
-
const currentModeOwner = this.modeOwners.get(this.mode);
|
|
180
|
-
if (decisionOwner !== currentModeOwner) {
|
|
181
|
-
console.warn(
|
|
182
|
-
`[MapMode] Authorization decision from "${decisionOwner}" ignored - not the owner of mode "${this.mode}" (owner: ${currentModeOwner || "none"})`
|
|
183
|
-
);
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
let matchingRequestOwner = null;
|
|
187
|
-
let matchingRequest = null;
|
|
188
|
-
for (const [requestOwner, request] of this.pendingRequests.entries()) {
|
|
189
|
-
if (request.authId === authId) {
|
|
190
|
-
matchingRequestOwner = requestOwner;
|
|
191
|
-
matchingRequest = request;
|
|
192
|
-
break;
|
|
193
|
-
}
|
|
159
|
+
}
|
|
160
|
+
function handleModeChangeRequest(instanceId, state, desiredMode, requestOwner) {
|
|
161
|
+
const desiredModeOwner = state.modeOwners.get(desiredMode);
|
|
162
|
+
if (shouldAutoAcceptRequest(state, desiredMode, requestOwner)) {
|
|
163
|
+
setMode(instanceId, state, desiredMode);
|
|
164
|
+
if (desiredMode !== DEFAULT_MODE && !desiredModeOwner) {
|
|
165
|
+
state.modeOwners.set(desiredMode, requestOwner);
|
|
194
166
|
}
|
|
195
|
-
|
|
167
|
+
state.pendingRequests.delete(requestOwner);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
const authId = uuid();
|
|
171
|
+
state.pendingRequests.set(requestOwner, {
|
|
172
|
+
authId,
|
|
173
|
+
desiredMode,
|
|
174
|
+
currentMode: state.mode,
|
|
175
|
+
requestOwner
|
|
176
|
+
});
|
|
177
|
+
mapModeBus.emit(MapModeEvents.changeAuthorization, {
|
|
178
|
+
authId,
|
|
179
|
+
desiredMode,
|
|
180
|
+
currentMode: state.mode,
|
|
181
|
+
id: instanceId
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
function ensureBusListener(instanceId) {
|
|
185
|
+
if (busUnsubscribers.has(instanceId)) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
const state = getOrCreateState(instanceId);
|
|
189
|
+
const unsubRequest = mapModeBus.on(MapModeEvents.changeRequest, (event) => {
|
|
190
|
+
const { desiredMode, owner: requestOwner, id } = event.payload;
|
|
191
|
+
if (id !== instanceId || desiredMode === state.mode) {
|
|
196
192
|
return;
|
|
197
193
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
false
|
|
205
|
-
);
|
|
206
|
-
} else {
|
|
207
|
-
this.pendingRequests.delete(matchingRequestOwner);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* Approve a request and reject all others
|
|
212
|
-
*/
|
|
213
|
-
approveRequestAndRejectOthers(approvedRequest, excludeAuthId, decisionOwner, reason, emitApproval) {
|
|
214
|
-
const requestsToReject = [];
|
|
215
|
-
for (const request of this.pendingRequests.values()) {
|
|
216
|
-
if (request.authId !== excludeAuthId) {
|
|
217
|
-
requestsToReject.push(request);
|
|
218
|
-
}
|
|
194
|
+
handleModeChangeRequest(instanceId, state, desiredMode, requestOwner);
|
|
195
|
+
});
|
|
196
|
+
const unsubDecision = mapModeBus.on(MapModeEvents.changeDecision, (event) => {
|
|
197
|
+
const { id, approved, authId, owner } = event.payload;
|
|
198
|
+
if (id !== instanceId) {
|
|
199
|
+
return;
|
|
219
200
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
);
|
|
201
|
+
handleAuthorizationDecision(instanceId, state, { approved, authId, owner });
|
|
202
|
+
});
|
|
203
|
+
const unsubChanged = mapModeBus.on(MapModeEvents.changed, (event) => {
|
|
204
|
+
const { currentMode, previousMode, id } = event.payload;
|
|
205
|
+
if (id !== instanceId) {
|
|
206
|
+
return;
|
|
227
207
|
}
|
|
228
|
-
if (
|
|
229
|
-
|
|
230
|
-
authId: approvedRequest.authId,
|
|
231
|
-
approved: true,
|
|
232
|
-
owner: decisionOwner,
|
|
233
|
-
reason,
|
|
234
|
-
id: this.id
|
|
235
|
-
});
|
|
208
|
+
if (currentMode === DEFAULT_MODE && state.pendingRequests.size > 0) {
|
|
209
|
+
handlePendingRequestsOnDefaultMode(instanceId, state, previousMode);
|
|
236
210
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
211
|
+
});
|
|
212
|
+
busUnsubscribers.set(instanceId, () => {
|
|
213
|
+
unsubRequest();
|
|
214
|
+
unsubDecision();
|
|
215
|
+
unsubChanged();
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
function cleanupBusListenerIfNeeded(instanceId) {
|
|
219
|
+
const subscribers = componentSubscribers.get(instanceId);
|
|
220
|
+
if (!subscribers || subscribers.size === 0) {
|
|
221
|
+
const unsub = busUnsubscribers.get(instanceId);
|
|
222
|
+
if (unsub) {
|
|
223
|
+
unsub();
|
|
224
|
+
busUnsubscribers.delete(instanceId);
|
|
245
225
|
}
|
|
226
|
+
modeStore.delete(instanceId);
|
|
227
|
+
componentSubscribers.delete(instanceId);
|
|
228
|
+
subscriptionCache.delete(instanceId);
|
|
229
|
+
snapshotCache.delete(instanceId);
|
|
230
|
+
requestModeChangeCache.delete(instanceId);
|
|
246
231
|
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
if (!previousModeOwner) {
|
|
257
|
-
return;
|
|
232
|
+
}
|
|
233
|
+
function getOrCreateSubscription(instanceId) {
|
|
234
|
+
const subscription = subscriptionCache.get(instanceId) ?? ((onStoreChange) => {
|
|
235
|
+
getOrCreateState(instanceId);
|
|
236
|
+
ensureBusListener(instanceId);
|
|
237
|
+
let subscriberSet = componentSubscribers.get(instanceId);
|
|
238
|
+
if (!subscriberSet) {
|
|
239
|
+
subscriberSet = /* @__PURE__ */ new Set();
|
|
240
|
+
componentSubscribers.set(instanceId, subscriberSet);
|
|
258
241
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
authId: request.authId,
|
|
265
|
-
approved: false,
|
|
266
|
-
owner: previousModeOwner,
|
|
267
|
-
reason: "Request rejected - already in requested mode",
|
|
268
|
-
id: this.id
|
|
269
|
-
});
|
|
242
|
+
subscriberSet.add(onStoreChange);
|
|
243
|
+
return () => {
|
|
244
|
+
const currentSubscriberSet = componentSubscribers.get(instanceId);
|
|
245
|
+
if (currentSubscriberSet) {
|
|
246
|
+
currentSubscriberSet.delete(onStoreChange);
|
|
270
247
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
248
|
+
cleanupBusListenerIfNeeded(instanceId);
|
|
249
|
+
};
|
|
250
|
+
});
|
|
251
|
+
subscriptionCache.set(instanceId, subscription);
|
|
252
|
+
return subscription;
|
|
253
|
+
}
|
|
254
|
+
function getOrCreateSnapshot(instanceId) {
|
|
255
|
+
const snapshot = snapshotCache.get(instanceId) ?? (() => {
|
|
256
|
+
const state = modeStore.get(instanceId);
|
|
257
|
+
if (!state) {
|
|
258
|
+
return DEFAULT_MODE;
|
|
279
259
|
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
});
|
|
292
|
-
this.notify();
|
|
293
|
-
}
|
|
294
|
-
/**
|
|
295
|
-
* Clean up store resources
|
|
296
|
-
*/
|
|
297
|
-
destroy() {
|
|
298
|
-
for (const unsubscribe of this.unsubscribers) {
|
|
299
|
-
unsubscribe();
|
|
260
|
+
return state.mode;
|
|
261
|
+
});
|
|
262
|
+
snapshotCache.set(instanceId, snapshot);
|
|
263
|
+
return snapshot;
|
|
264
|
+
}
|
|
265
|
+
function getOrCreateRequestModeChange(instanceId) {
|
|
266
|
+
const requestModeChange = requestModeChangeCache.get(instanceId) ?? ((desiredMode, requestOwner) => {
|
|
267
|
+
const trimmedDesiredMode = desiredMode.trim();
|
|
268
|
+
const trimmedRequestOwner = requestOwner.trim();
|
|
269
|
+
if (!trimmedDesiredMode) {
|
|
270
|
+
throw new Error("requestModeChange requires non-empty desiredMode");
|
|
300
271
|
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
272
|
+
if (!trimmedRequestOwner) {
|
|
273
|
+
throw new Error("requestModeChange requires non-empty requestOwner");
|
|
274
|
+
}
|
|
275
|
+
mapModeBus.emit(MapModeEvents.changeRequest, {
|
|
276
|
+
desiredMode: trimmedDesiredMode,
|
|
277
|
+
owner: trimmedRequestOwner,
|
|
278
|
+
id: instanceId
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
requestModeChangeCache.set(instanceId, requestModeChange);
|
|
282
|
+
return requestModeChange;
|
|
306
283
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
if (!
|
|
310
|
-
|
|
284
|
+
function getCurrentModeOwner(instanceId) {
|
|
285
|
+
const state = modeStore.get(instanceId);
|
|
286
|
+
if (!state) {
|
|
287
|
+
return void 0;
|
|
311
288
|
}
|
|
312
|
-
return
|
|
289
|
+
return state.modeOwners.get(state.mode);
|
|
313
290
|
}
|
|
314
|
-
function
|
|
315
|
-
const
|
|
316
|
-
if (
|
|
317
|
-
|
|
318
|
-
|
|
291
|
+
function clearMapModeState(instanceId) {
|
|
292
|
+
const unsub = busUnsubscribers.get(instanceId);
|
|
293
|
+
if (unsub) {
|
|
294
|
+
unsub();
|
|
295
|
+
busUnsubscribers.delete(instanceId);
|
|
319
296
|
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
297
|
+
modeStore.delete(instanceId);
|
|
298
|
+
componentSubscribers.delete(instanceId);
|
|
299
|
+
subscriptionCache.delete(instanceId);
|
|
300
|
+
snapshotCache.delete(instanceId);
|
|
301
|
+
requestModeChangeCache.delete(instanceId);
|
|
323
302
|
}
|
|
324
303
|
|
|
325
|
-
export {
|
|
304
|
+
export { clearMapModeState, getCurrentModeOwner, getOrCreateRequestModeChange, getOrCreateSnapshot, getOrCreateSubscription };
|
|
326
305
|
//# sourceMappingURL=store.js.map
|
|
327
306
|
//# sourceMappingURL=store.js.map
|