@simpleplatform/sdk 3.0.1 → 3.0.2
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/README.md +3 -0
- package/dist/space/index.js +16 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -358,6 +358,9 @@ while `simple.records.current()` rejects with `SpaceProtocolError` code
|
|
|
358
358
|
In an older host, `records.current()` can remain available through the `record`
|
|
359
359
|
capability while `records.open()` requires the newer `records` capability.
|
|
360
360
|
|
|
361
|
+
A Space has one connection per page. The first `connect()` opens it, and every
|
|
362
|
+
later call returns the same client. A call with a different `targetOrigin` is rejected.
|
|
363
|
+
|
|
361
364
|
When `connect()` runs in the Space document, it disables vertical root
|
|
362
365
|
overscroll bounce. Normal scrolling inside the Space remains enabled.
|
|
363
366
|
|
package/dist/space/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import { createMessagePortTransport } from './browser-transport.js';
|
|
|
2
2
|
import { createSimpleClient, HEADER_ACTIONS_PROTOCOL_VERSION, HEADER_STATUS_PROTOCOL_VERSION, isSpaceContext, MANAGED_RECORD_FORM_PROTOCOL_VERSION, PROTOCOL_VERSION, RECORDS_PROTOCOL_VERSION, SpaceDataError, SpaceProtocolError, TABS_PROTOCOL_VERSION, TOAST_PROTOCOL_VERSION, } from './core.js';
|
|
3
3
|
import { isObjectRecord } from './protocol.js';
|
|
4
4
|
export { HEADER_ACTIONS_PROTOCOL_VERSION, HEADER_STATUS_PROTOCOL_VERSION, PROTOCOL_VERSION, RECORDS_PROTOCOL_VERSION, SpaceDataError, SpaceProtocolError, TABS_PROTOCOL_VERSION, TOAST_PROTOCOL_VERSION };
|
|
5
|
+
const connections = new WeakMap();
|
|
5
6
|
/** Connects this Space to its host using the explicitly supplied host origin. */
|
|
6
7
|
export function connect({ targetOrigin }) {
|
|
7
8
|
if (!isOrigin(targetOrigin)) {
|
|
@@ -17,9 +18,18 @@ export function connect({ targetOrigin }) {
|
|
|
17
18
|
message: 'The Space SDK requires a browser window.',
|
|
18
19
|
}));
|
|
19
20
|
}
|
|
21
|
+
const existing = connections.get(window);
|
|
22
|
+
if (existing) {
|
|
23
|
+
if (existing.targetOrigin === targetOrigin)
|
|
24
|
+
return existing.promise;
|
|
25
|
+
return Promise.reject(new SpaceProtocolError({
|
|
26
|
+
code: 'invalid_request',
|
|
27
|
+
message: 'connect() already opened this Space\'s connection to a different targetOrigin.',
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
20
30
|
// The host cannot style a cross-origin frame's viewport, where edge bounce occurs.
|
|
21
31
|
window.document.documentElement.style.overscrollBehaviorY = 'none';
|
|
22
|
-
|
|
32
|
+
const promise = new Promise((resolve, reject) => {
|
|
23
33
|
const onMessage = (event) => {
|
|
24
34
|
if (event.origin !== targetOrigin || !isInitializationMessage(event.data))
|
|
25
35
|
return;
|
|
@@ -78,7 +88,12 @@ export function connect({ targetOrigin }) {
|
|
|
78
88
|
},
|
|
79
89
|
type: 'SPACE_READY',
|
|
80
90
|
}, targetOrigin);
|
|
91
|
+
}).catch((error) => {
|
|
92
|
+
connections.delete(window);
|
|
93
|
+
throw error;
|
|
81
94
|
});
|
|
95
|
+
connections.set(window, { promise, targetOrigin });
|
|
96
|
+
return promise;
|
|
82
97
|
}
|
|
83
98
|
function isOrigin(targetOrigin) {
|
|
84
99
|
try {
|