@upscopeio/react 2025.11.12 → 2025.12.5
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/index.d.ts +11 -10
- package/index.js +88 -77
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/sdk.js +24 -13
- package/sdk.js.map +1 -1
package/index.d.ts
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import { CobrowsingSdkConfiguration, Upscope } from "./sdk";
|
|
2
2
|
import { SDKEvents } from "./sdk-types";
|
|
3
3
|
|
|
4
|
-
type UpscopeProviderProps = {
|
|
5
|
-
test?: boolean;
|
|
6
|
-
enabled?: boolean;
|
|
7
|
-
children: React.ReactNode;
|
|
8
|
-
apiKey: string;
|
|
9
|
-
} & Partial<Omit<CobrowsingSdkConfiguration, "apiKey" | "regionWhitelist">>;
|
|
10
|
-
|
|
11
4
|
type UpscopeContext = {
|
|
12
|
-
Upscope: Upscope | undefined;
|
|
13
|
-
shortId: string | undefined;
|
|
14
5
|
getLookupCode: () => Promise<string | undefined>;
|
|
6
|
+
isSharing: boolean;
|
|
15
7
|
listen: (event: keyof SDKEvents, callback: (data: any) => void) => void;
|
|
16
8
|
reset: () => void;
|
|
17
|
-
|
|
9
|
+
shortId: string | undefined;
|
|
10
|
+
Upscope: undefined | Upscope;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
type UpscopeProviderProps = Partial<Omit<CobrowsingSdkConfiguration, "apiKey" | "regionWhitelist">> & {
|
|
14
|
+
apiKey: string;
|
|
15
|
+
children: React.ReactNode;
|
|
16
|
+
enabled?: boolean;
|
|
17
|
+
test?: boolean;
|
|
18
|
+
windowContext?: Window;
|
|
18
19
|
};
|
|
19
20
|
|
|
20
21
|
export function useUpscope(): UpscopeContext;
|
package/index.js
CHANGED
|
@@ -238,10 +238,8 @@ var __generator = this && this.__generator || function(thisArg, body) {
|
|
|
238
238
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
239
239
|
import equal from "fast-deep-equal";
|
|
240
240
|
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
241
|
-
import
|
|
241
|
+
import { upscopeFor } from "./sdk.js";
|
|
242
242
|
var UpscopeContext = createContext({
|
|
243
|
-
Upscope: undefined,
|
|
244
|
-
shortId: undefined,
|
|
245
243
|
getLookupCode: function getLookupCode() {
|
|
246
244
|
return _asyncToGenerator(function() {
|
|
247
245
|
return __generator(this, function(_state) {
|
|
@@ -252,18 +250,77 @@ var UpscopeContext = createContext({
|
|
|
252
250
|
});
|
|
253
251
|
})();
|
|
254
252
|
},
|
|
253
|
+
isSharing: false,
|
|
255
254
|
listen: function(event, callback) {},
|
|
256
255
|
reset: function() {},
|
|
257
|
-
|
|
256
|
+
shortId: undefined,
|
|
257
|
+
Upscope: undefined
|
|
258
258
|
});
|
|
259
|
-
export function
|
|
260
|
-
|
|
259
|
+
export function Masked(param) {
|
|
260
|
+
var children = param.children;
|
|
261
|
+
var beforeRef = useRef(null);
|
|
262
|
+
var afterRef = useRef(null);
|
|
263
|
+
useEffect(function() {
|
|
264
|
+
if (beforeRef.current && afterRef.current) {
|
|
265
|
+
var nextSibling = beforeRef.current.nextSibling;
|
|
266
|
+
while(nextSibling && nextSibling !== afterRef.current){
|
|
267
|
+
nextSibling.dataset.upscopeMasked = "true";
|
|
268
|
+
nextSibling = nextSibling.nextSibling;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}, [
|
|
272
|
+
beforeRef,
|
|
273
|
+
afterRef,
|
|
274
|
+
children
|
|
275
|
+
]);
|
|
276
|
+
return _jsxs(_Fragment, {
|
|
277
|
+
children: [
|
|
278
|
+
_jsx("script", {
|
|
279
|
+
ref: beforeRef
|
|
280
|
+
}),
|
|
281
|
+
children,
|
|
282
|
+
_jsx("script", {
|
|
283
|
+
ref: afterRef
|
|
284
|
+
})
|
|
285
|
+
]
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
export function NoRemoteControl(param) {
|
|
289
|
+
var children = param.children;
|
|
290
|
+
var beforeRef = useRef(null);
|
|
291
|
+
var afterRef = useRef(null);
|
|
292
|
+
useEffect(function() {
|
|
293
|
+
if (beforeRef.current && afterRef.current) {
|
|
294
|
+
var nextSibling = beforeRef.current.nextSibling;
|
|
295
|
+
while(nextSibling && nextSibling !== afterRef.current){
|
|
296
|
+
nextSibling.dataset.upscopeNoRemoteControl = "true";
|
|
297
|
+
nextSibling = nextSibling.nextSibling;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}, [
|
|
301
|
+
beforeRef,
|
|
302
|
+
afterRef,
|
|
303
|
+
children
|
|
304
|
+
]);
|
|
305
|
+
return _jsxs(_Fragment, {
|
|
306
|
+
children: [
|
|
307
|
+
_jsx("script", {
|
|
308
|
+
ref: beforeRef
|
|
309
|
+
}),
|
|
310
|
+
children,
|
|
311
|
+
_jsx("script", {
|
|
312
|
+
ref: afterRef
|
|
313
|
+
})
|
|
314
|
+
]
|
|
315
|
+
});
|
|
261
316
|
}
|
|
262
317
|
export function UpscopeProvider(_param) {
|
|
263
|
-
var
|
|
318
|
+
var _this = this;
|
|
319
|
+
var children = _param.children, enabled = _param.enabled, test = _param.test, windowContext = _param.windowContext, configProps = _objectWithoutProperties(_param, [
|
|
264
320
|
"children",
|
|
265
321
|
"enabled",
|
|
266
|
-
"test"
|
|
322
|
+
"test",
|
|
323
|
+
"windowContext"
|
|
267
324
|
]);
|
|
268
325
|
var Upscope = useMemo(function() {
|
|
269
326
|
return function() {
|
|
@@ -271,10 +328,11 @@ export function UpscopeProvider(_param) {
|
|
|
271
328
|
args[_key] = arguments[_key];
|
|
272
329
|
}
|
|
273
330
|
if (test) return; // Do not use Upscope SDK on test
|
|
274
|
-
|
|
331
|
+
upscopeFor(windowContext !== null && windowContext !== void 0 ? windowContext : window).apply(_this, _toConsumableArray(args));
|
|
275
332
|
};
|
|
276
333
|
}, [
|
|
277
|
-
test
|
|
334
|
+
test,
|
|
335
|
+
windowContext
|
|
278
336
|
]);
|
|
279
337
|
var _useState = _slicedToArray(useState(false), 2), loaded = _useState[0], setLoaded = _useState[1];
|
|
280
338
|
var _useState1 = _slicedToArray(useState(false), 2), sharing = _useState1[0], setSharing = _useState1[1];
|
|
@@ -366,14 +424,22 @@ export function UpscopeProvider(_param) {
|
|
|
366
424
|
loaded,
|
|
367
425
|
Upscope
|
|
368
426
|
]);
|
|
369
|
-
var getLookupCode = useCallback(function() {
|
|
370
|
-
return
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
resolve
|
|
374
|
-
|
|
427
|
+
var getLookupCode = useCallback(/*#__PURE__*/ _asyncToGenerator(function() {
|
|
428
|
+
return __generator(this, function(_state) {
|
|
429
|
+
return [
|
|
430
|
+
2,
|
|
431
|
+
new Promise(function(resolve) {
|
|
432
|
+
if (!upscopeActive) {
|
|
433
|
+
resolve(undefined);
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
Upscope("getLookupCode", function(lookupCode) {
|
|
437
|
+
resolve(lookupCode);
|
|
438
|
+
});
|
|
439
|
+
})
|
|
440
|
+
];
|
|
375
441
|
});
|
|
376
|
-
}, [
|
|
442
|
+
}), [
|
|
377
443
|
upscopeActive,
|
|
378
444
|
Upscope
|
|
379
445
|
]);
|
|
@@ -389,73 +455,18 @@ export function UpscopeProvider(_param) {
|
|
|
389
455
|
]);
|
|
390
456
|
return _jsx(UpscopeContext.Provider, {
|
|
391
457
|
value: {
|
|
392
|
-
Upscope: Upscope,
|
|
393
|
-
shortId: shortId,
|
|
394
458
|
getLookupCode: getLookupCode,
|
|
459
|
+
isSharing: sharing,
|
|
395
460
|
listen: listen,
|
|
396
461
|
reset: reset,
|
|
397
|
-
|
|
462
|
+
shortId: shortId,
|
|
463
|
+
Upscope: Upscope
|
|
398
464
|
},
|
|
399
465
|
children: children
|
|
400
466
|
});
|
|
401
467
|
}
|
|
402
|
-
export function
|
|
403
|
-
|
|
404
|
-
var beforeRef = useRef(null);
|
|
405
|
-
var afterRef = useRef(null);
|
|
406
|
-
useEffect(function() {
|
|
407
|
-
if (beforeRef.current && afterRef.current) {
|
|
408
|
-
var nextSibling = beforeRef.current.nextSibling;
|
|
409
|
-
while(nextSibling && nextSibling !== afterRef.current){
|
|
410
|
-
nextSibling.dataset.upscopeMasked = true;
|
|
411
|
-
nextSibling = nextSibling.nextSibling;
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
}, [
|
|
415
|
-
beforeRef,
|
|
416
|
-
afterRef,
|
|
417
|
-
children
|
|
418
|
-
]);
|
|
419
|
-
return _jsxs(_Fragment, {
|
|
420
|
-
children: [
|
|
421
|
-
_jsx("script", {
|
|
422
|
-
ref: beforeRef
|
|
423
|
-
}),
|
|
424
|
-
children,
|
|
425
|
-
_jsx("script", {
|
|
426
|
-
ref: afterRef
|
|
427
|
-
})
|
|
428
|
-
]
|
|
429
|
-
});
|
|
430
|
-
}
|
|
431
|
-
export function NoRemoteControl(param) {
|
|
432
|
-
var children = param.children;
|
|
433
|
-
var beforeRef = useRef(null);
|
|
434
|
-
var afterRef = useRef(null);
|
|
435
|
-
useEffect(function() {
|
|
436
|
-
if (beforeRef.current && afterRef.current) {
|
|
437
|
-
var nextSibling = beforeRef.current.nextSibling;
|
|
438
|
-
while(nextSibling && nextSibling !== afterRef.current){
|
|
439
|
-
nextSibling.dataset.upscopeNoRemoteControl = true;
|
|
440
|
-
nextSibling = nextSibling.nextSibling;
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
}, [
|
|
444
|
-
beforeRef,
|
|
445
|
-
afterRef,
|
|
446
|
-
children
|
|
447
|
-
]);
|
|
448
|
-
return _jsxs(_Fragment, {
|
|
449
|
-
children: [
|
|
450
|
-
_jsx("script", {
|
|
451
|
-
ref: beforeRef
|
|
452
|
-
}),
|
|
453
|
-
children,
|
|
454
|
-
_jsx("script", {
|
|
455
|
-
ref: afterRef
|
|
456
|
-
})
|
|
457
|
-
]
|
|
458
|
-
});
|
|
468
|
+
export function useUpscope() {
|
|
469
|
+
return useContext(UpscopeContext);
|
|
459
470
|
}
|
|
460
471
|
|
|
461
472
|
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,OAAO,IAAI,EAAE,YAAY,SAAS,EAAE,QAAQ,KAAK,QAAQ,oBAAoB;AACtF,OAAO,WAAW,kBAAkB;AACpC,SAAS,aAAa,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,QAAQ,QAAQ;AACrG,
|
|
1
|
+
{"version":3,"sources":["index.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,OAAO,IAAI,EAAE,YAAY,SAAS,EAAE,QAAQ,KAAK,QAAQ,oBAAoB;AACtF,OAAO,WAAW,kBAAkB;AACpC,SAAS,aAAa,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,QAAQ,QAAQ;A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AM,SAAS,YAAY,SAAC,OAAO,UAAa;QAC5C,QAAQ,MAAM,OAAO;IACzB,GAAG;QAAC;KAAQ;IACZ,IAAM,QAAQ,YAAY,WAAM;QAC5B,QAAQ,SAAS,IAAI;IACzB,GAAG;QAAC;KAAQ;IACZ,OAAQ,KAAK,eAAe,QAAQ,EAAE;QAAE,OAAO;YACvC,eAAA;YACA,WAAW;YACX,QAAA;YACA,OAAA;YACA,SAAA;YACA,SAAA;QACJ;QAAG,UAAU;IAAS;AAC9B,CAAC;AACD,OAAO,SAAS,aAAa;IACzB,OAAO,WAAW;AACtB,CAAC","file":"index.js","sourcesContent":["import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from \"react/jsx-runtime\";\nimport equal from \"fast-deep-equal\";\nimport { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from \"react\";\nimport { upscopeFor } from \"./sdk.js\";\nconst UpscopeContext = createContext({\n async getLookupCode() {\n return \"\";\n },\n isSharing: false,\n listen: (event, callback) => { },\n reset: () => { },\n shortId: undefined,\n Upscope: undefined,\n});\nexport function Masked({ children }) {\n const beforeRef = useRef(null);\n const afterRef = useRef(null);\n useEffect(() => {\n if (beforeRef.current && afterRef.current) {\n let { nextSibling } = beforeRef.current;\n while (nextSibling && nextSibling !== afterRef.current) {\n nextSibling.dataset.upscopeMasked = \"true\";\n nextSibling = nextSibling.nextSibling;\n }\n }\n }, [beforeRef, afterRef, children]);\n return (_jsxs(_Fragment, { children: [_jsx(\"script\", { ref: beforeRef }), children, _jsx(\"script\", { ref: afterRef })] }));\n}\nexport function NoRemoteControl({ children }) {\n const beforeRef = useRef(null);\n const afterRef = useRef(null);\n useEffect(() => {\n if (beforeRef.current && afterRef.current) {\n let { nextSibling } = beforeRef.current;\n while (nextSibling && nextSibling !== afterRef.current) {\n nextSibling.dataset.upscopeNoRemoteControl = \"true\";\n nextSibling = nextSibling.nextSibling;\n }\n }\n }, [beforeRef, afterRef, children]);\n return (_jsxs(_Fragment, { children: [_jsx(\"script\", { ref: beforeRef }), children, _jsx(\"script\", { ref: afterRef })] }));\n}\nexport function UpscopeProvider({ children, enabled, test, windowContext, ...configProps }) {\n const Upscope = useMemo(() => (...args) => {\n if (test)\n return; // Do not use Upscope SDK on test\n upscopeFor(windowContext ?? window)(...args);\n }, [test, windowContext]);\n const [loaded, setLoaded] = useState(false);\n const [sharing, setSharing] = useState(false);\n const [shortId, setShortId] = useState(undefined);\n const [currentConfiguration, setCurrentConfiguration] = useState(undefined);\n const upscopeActive = enabled && loaded;\n const [pendingConfigurationUpdate, setPendingConfigurationUpdate] = useState(null);\n enabled ??= true;\n useEffect(() => {\n if (currentConfiguration === undefined || !upscopeActive) {\n setPendingConfigurationUpdate(null);\n return;\n }\n const config = Object.entries(configProps)\n .filter(([configName, configValue]) => configName !== \"regionWhitelist\" &&\n !equal(configValue, currentConfiguration[configName]))\n .reduce((config, [configName, configValue]) => {\n config[configName] = configValue;\n return config;\n }, {});\n setPendingConfigurationUpdate(Object.keys(config).length === 0 ? null : config);\n }, [currentConfiguration, configProps, upscopeActive]);\n useEffect(() => {\n if (!currentConfiguration)\n return;\n const isEnabledFirstTime = enabled && !loaded;\n const isDisabledAfterInit = !enabled && loaded;\n if (isEnabledFirstTime) {\n Upscope(\"init\", currentConfiguration);\n setLoaded(true);\n }\n else if (isDisabledAfterInit) {\n Upscope(\"reset\", false);\n }\n }, [enabled, loaded, currentConfiguration, Upscope]);\n useEffect(() => {\n if (upscopeActive) {\n Upscope(\"getShortId\", (shortId) => {\n setShortId(shortId);\n });\n }\n else {\n setShortId(undefined);\n }\n }, [upscopeActive, Upscope]);\n useEffect(() => {\n if (!upscopeActive || !pendingConfigurationUpdate || !currentConfiguration)\n return;\n Upscope(\"updateConnection\", pendingConfigurationUpdate);\n setPendingConfigurationUpdate(null);\n const newCurrentConfiguration = { ...currentConfiguration, ...pendingConfigurationUpdate };\n setCurrentConfiguration(newCurrentConfiguration);\n }, [upscopeActive, pendingConfigurationUpdate, currentConfiguration, Upscope]);\n useEffect(() => {\n if (currentConfiguration || !enabled)\n return;\n // Initialize configurations\n setCurrentConfiguration(configProps);\n }, [enabled, currentConfiguration, configProps]);\n useEffect(() => {\n if (!loaded)\n return;\n Upscope(\"on\", \"sessionStart\", () => {\n setSharing(true);\n });\n Upscope(\"on\", \"sessionContinue\", () => {\n setSharing(true);\n });\n Upscope(\"on\", \"sessionEnd\", () => {\n setSharing(false);\n });\n }, [loaded, Upscope]);\n const getLookupCode = useCallback(async () => {\n return new Promise((resolve) => {\n if (!upscopeActive) {\n resolve(undefined);\n return;\n }\n Upscope(\"getLookupCode\", (lookupCode) => {\n resolve(lookupCode);\n });\n });\n }, [upscopeActive, Upscope]);\n const listen = useCallback((event, callback) => {\n Upscope(\"on\", event, callback);\n }, [Upscope]);\n const reset = useCallback(() => {\n Upscope(\"reset\", true);\n }, [Upscope]);\n return (_jsx(UpscopeContext.Provider, { value: {\n getLookupCode,\n isSharing: sharing,\n listen,\n reset,\n shortId,\n Upscope,\n }, children: children }));\n}\nexport function useUpscope() {\n return useContext(UpscopeContext);\n}\n"]}
|
package/package.json
CHANGED
package/sdk.js
CHANGED
|
@@ -23,10 +23,10 @@ function _unsupportedIterableToArray(o, minLen) {
|
|
|
23
23
|
if (n === "Map" || n === "Set") return Array.from(n);
|
|
24
24
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
25
25
|
}
|
|
26
|
-
var
|
|
27
|
-
function loadSDK(apiKey) {
|
|
28
|
-
if (typeof
|
|
29
|
-
|
|
26
|
+
var loadedWindows = new WeakSet();
|
|
27
|
+
function loadSDK(w, apiKey) {
|
|
28
|
+
if (typeof w.Upscope !== "undefined") {
|
|
29
|
+
loadedWindows.add(w);
|
|
30
30
|
return;
|
|
31
31
|
}
|
|
32
32
|
var i = function i1() {
|
|
@@ -37,30 +37,41 @@ function loadSDK(apiKey) {
|
|
|
37
37
|
};
|
|
38
38
|
i.q = [];
|
|
39
39
|
// The real Upscope implementation is loaded below
|
|
40
|
-
|
|
40
|
+
w.Upscope = i;
|
|
41
41
|
var s = document.createElement("script");
|
|
42
42
|
s.type = "text/javascript";
|
|
43
43
|
s.async = true;
|
|
44
44
|
s.src = "https://code.upscope.io/".concat(apiKey, ".js");
|
|
45
45
|
document.head.appendChild(s);
|
|
46
|
-
|
|
46
|
+
loadedWindows.add(w);
|
|
47
47
|
}
|
|
48
|
-
var
|
|
49
|
-
for(var _len = arguments.length, instruction = new Array(_len), _key =
|
|
50
|
-
instruction[_key] = arguments[_key];
|
|
48
|
+
var ScopedUpscope = function ScopedUpscope(w) {
|
|
49
|
+
for(var _len = arguments.length, instruction = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
|
|
50
|
+
instruction[_key - 1] = arguments[_key];
|
|
51
51
|
}
|
|
52
|
-
var
|
|
53
|
-
if (!
|
|
52
|
+
var _w;
|
|
53
|
+
if (!loadedWindows.has(w)) {
|
|
54
54
|
if (instruction[0] === "init") {
|
|
55
55
|
var config = instruction[1];
|
|
56
56
|
if (!(config === null || config === void 0 ? void 0 : config.apiKey)) throw new Error("API key not specified");
|
|
57
|
-
loadSDK(config.apiKey);
|
|
57
|
+
loadSDK(w, config.apiKey);
|
|
58
58
|
} else {
|
|
59
59
|
throw new Error("Upscope is not loaded");
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
|
-
|
|
62
|
+
(_w = w).Upscope.apply(_w, _toConsumableArray(instruction));
|
|
63
63
|
};
|
|
64
|
+
export var upscopeFor = function upscopeFor(w) {
|
|
65
|
+
return function() {
|
|
66
|
+
for(var _len = arguments.length, instruction = new Array(_len), _key = 0; _key < _len; _key++){
|
|
67
|
+
instruction[_key] = arguments[_key];
|
|
68
|
+
}
|
|
69
|
+
ScopedUpscope.apply(void 0, [
|
|
70
|
+
w
|
|
71
|
+
].concat(_toConsumableArray(instruction)));
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
var _Upscope = upscopeFor(window);
|
|
64
75
|
export default _Upscope;
|
|
65
76
|
|
|
66
77
|
|
package/sdk.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["sdk.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"sources":["sdk.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAM,gBAAgB,IAAI;AAC1B,SAAS,QAAQ,CAAC,EAAE,MAAM,EAAE;IACxB,IAAI,OAAO,EAAE,OAAO,KAAK,aAAa;QAClC,cAAc,GAAG,CAAC;QAClB;IACJ,CAAC;IACD,IAAM,IAAI,SAAJ,KAAuB;QAAT,IAAA,IAAA,OAAA,UAAA,QAAA,AAAG,OAAH,UAAA,OAAA,OAAA,GAAA,OAAA,MAAA,OAAA;YAAG,KAAH,QAAA,SAAA,CAAA,KAAO;QAAD;QACtB,EAAE,CAAC,CAAC,IAAI,CAAC;IACb;IACA,EAAE,CAAC,GAAG,EAAE;IACR,kDAAkD;IAClD,EAAE,OAAO,GAAG;IACZ,IAAM,IAAI,SAAS,aAAa,CAAC;IACjC,EAAE,IAAI,GAAG;IACT,EAAE,KAAK,GAAG,IAAI;IACd,EAAE,GAAG,GAAG,AAAC,2BAAiC,OAAP,QAAO;IAC1C,SAAS,IAAI,CAAC,WAAW,CAAC;IAC1B,cAAc,GAAG,CAAC;AACtB;AACA,IAAM,gBAAgB,SAAhB,cAA0B,CAAC,EAAkB;IAAhB,IAAA,IAAA,OAAA,UAAA,QAAA,AAAG,cAAH,UAAA,OAAA,IAAA,OAAA,KAAc,GAAd,OAAA,GAAA,OAAA,MAAA,OAAA;QAAG,YAAH,OAAA,KAAA,SAAA,CAAA,KAAc;IAAD;QAY5C;IAXA,IAAI,CAAC,cAAc,GAAG,CAAC,IAAI;QACvB,IAAI,WAAW,CAAC,EAAE,KAAK,QAAQ;YAC3B,IAAM,SAAS,WAAW,CAAC,EAAE;YAC7B,IAAI,CAAC,CAAA,mBAAA,oBAAA,KAAA,IAAA,OAAQ,MAAK,AAAC,GACf,MAAM,IAAI,MAAM,yBAAyB;YAC7C,QAAQ,GAAG,OAAO,MAAM;QAC5B,OACK;YACD,MAAM,IAAI,MAAM,yBAAyB;QAC7C,CAAC;IACL,CAAC;IACD,CAAA,KAAA,GAAE,OAAO,CAAT,MAAA,IAAU,mBAAG;AACjB;AACA,OAAO,IAAM,aAAa,SAAb,WAAuB,CAAC,EAAE;IACnC,OAAO,WAAoB;yCAAhB;YAAA;;QACP,cAAA,MAAA,KAAA,GAAA;YAAc;SAAkB,CAAhC,OAAiB,mBAAG;IACxB;AACJ,EAAE;AACF,IAAM,WAAW,WAAW;AAC5B,eAAe,SAAS","file":"sdk.js","sourcesContent":["const loadedWindows = new WeakSet();\nfunction loadSDK(w, apiKey) {\n if (typeof w.Upscope !== \"undefined\") {\n loadedWindows.add(w);\n return;\n }\n const i = function (...args) {\n i.q.push(args);\n };\n i.q = [];\n // The real Upscope implementation is loaded below\n w.Upscope = i;\n const s = document.createElement(\"script\");\n s.type = \"text/javascript\";\n s.async = true;\n s.src = `https://code.upscope.io/${apiKey}.js`;\n document.head.appendChild(s);\n loadedWindows.add(w);\n}\nconst ScopedUpscope = function (w, ...instruction) {\n if (!loadedWindows.has(w)) {\n if (instruction[0] === \"init\") {\n const config = instruction[1];\n if (!config?.apiKey)\n throw new Error(\"API key not specified\");\n loadSDK(w, config.apiKey);\n }\n else {\n throw new Error(\"Upscope is not loaded\");\n }\n }\n w.Upscope(...instruction);\n};\nexport const upscopeFor = function (w) {\n return (...instruction) => {\n ScopedUpscope(w, ...instruction);\n };\n};\nconst _Upscope = upscopeFor(window);\nexport default _Upscope;\n"]}
|