chayns-api 2.6.0-beta.2 → 2.6.0-beta.4

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 (77) hide show
  1. package/.github/workflows/publish.yml +7 -2
  2. package/dist/cjs/calls/dialogs/date.js +1 -1
  3. package/dist/cjs/calls/dialogs/iFrame.js +9 -6
  4. package/dist/cjs/calls/index.js +3 -1
  5. package/dist/cjs/components/ChaynsProvider.js +2 -3
  6. package/dist/cjs/components/withCompatMode.js +2 -2
  7. package/dist/cjs/components/withHydrationBoundary.js +1 -2
  8. package/dist/cjs/host/ChaynsHost.js +1 -2
  9. package/dist/cjs/host/iframe/HostIframe.js +1 -2
  10. package/dist/cjs/host/module/ModuleHost.js +1 -2
  11. package/dist/cjs/host/module/utils/loadComponent.js +9 -29
  12. package/dist/cjs/index.js +1 -2
  13. package/dist/cjs/plugins/TrustedDomainsPlugins.js +29 -0
  14. package/dist/cjs/plugins/index.js +8 -1
  15. package/dist/cjs/types/IChaynsReact.js +3 -7
  16. package/dist/cjs/types/global.d.js +1 -0
  17. package/dist/cjs/umd.index.js +1 -2
  18. package/dist/cjs/util/deviceHelper.js +17 -4
  19. package/dist/cjs/util/initModuleFederationSharing.js +11 -9
  20. package/dist/cjs/util/is.js +9 -4
  21. package/dist/cjs/util/transferNestedFunctions.js +1 -2
  22. package/dist/cjs/wrapper/AppWrapper.js +9 -3
  23. package/dist/cjs/wrapper/FrameWrapper.js +6 -3
  24. package/dist/cjs/wrapper/StaticChaynsApi.js +1 -3
  25. package/dist/esm/calls/dialogs/alert.js +1 -3
  26. package/dist/esm/calls/dialogs/communication.js +3 -6
  27. package/dist/esm/calls/dialogs/confirm.js +1 -4
  28. package/dist/esm/calls/dialogs/date.js +4 -8
  29. package/dist/esm/calls/dialogs/dropUpAlert.js +1 -2
  30. package/dist/esm/calls/dialogs/fileSelect.js +1 -2
  31. package/dist/esm/calls/dialogs/iFrame.js +11 -9
  32. package/dist/esm/calls/dialogs/input.js +1 -2
  33. package/dist/esm/calls/dialogs/mediaSelect.js +1 -2
  34. package/dist/esm/calls/dialogs/toast.js +1 -2
  35. package/dist/esm/calls/dialogs/utils/callback.js +1 -2
  36. package/dist/esm/calls/index.js +53 -156
  37. package/dist/esm/components/ChaynsProvider.js +18 -21
  38. package/dist/esm/components/WaitUntil.js +5 -6
  39. package/dist/esm/components/withCompatMode.js +1 -0
  40. package/dist/esm/components/withHydrationBoundary.js +5 -6
  41. package/dist/esm/handler/DialogHandler.js +1 -2
  42. package/dist/esm/hooks/geoLocationListener.js +5 -6
  43. package/dist/esm/hooks/scrollListener.js +12 -15
  44. package/dist/esm/hooks/usePages.js +16 -19
  45. package/dist/esm/hooks/windowMetricsListener.js +3 -4
  46. package/dist/esm/host/ChaynsHost.js +23 -24
  47. package/dist/esm/host/iframe/HostIframe.js +21 -22
  48. package/dist/esm/host/module/ModuleHost.js +24 -26
  49. package/dist/esm/host/module/utils/loadComponent.js +11 -34
  50. package/dist/esm/plugins/TrustedDomainsPlugins.js +25 -0
  51. package/dist/esm/plugins/index.js +2 -1
  52. package/dist/esm/types/IChaynsReact.js +2 -6
  53. package/dist/esm/types/global.d.js +0 -0
  54. package/dist/esm/util/appStorage.js +3 -6
  55. package/dist/esm/util/deviceHelper.js +20 -8
  56. package/dist/esm/util/initModuleFederationSharing.js +15 -14
  57. package/dist/esm/util/is.js +11 -8
  58. package/dist/esm/util/transferNestedFunctions.js +1 -2
  59. package/dist/esm/wrapper/AppWrapper.js +23 -26
  60. package/dist/esm/wrapper/FrameWrapper.js +14 -21
  61. package/dist/esm/wrapper/ModuleFederationWrapper.js +2 -5
  62. package/dist/esm/wrapper/StaticChaynsApi.js +2 -5
  63. package/dist/types/calls/dialogs/iFrame.d.ts +10 -4
  64. package/dist/types/calls/index.d.ts +2 -0
  65. package/dist/types/host/module/utils/loadComponent.d.ts +2 -1
  66. package/dist/types/plugins/SSRManifestPlugin.d.ts +2 -2
  67. package/dist/types/plugins/SequentialLoadPlugin.d.ts +2 -2
  68. package/dist/types/plugins/TrustedDomainsPlugins.d.ts +2 -0
  69. package/dist/types/plugins/index.d.ts +1 -0
  70. package/dist/types/types/IChaynsReact.d.ts +29 -12
  71. package/dist/types/util/is.d.ts +1 -0
  72. package/dist/types/wrapper/StaticChaynsApi.d.ts +68 -4
  73. package/eslint.config.mjs +3 -0
  74. package/package.json +32 -22
  75. package/{toolkit.config.js → toolkit.config.ts} +6 -3
  76. package/tsconfig.json +1 -0
  77. package/.eslintrc +0 -17
@@ -1,22 +1,20 @@
1
1
  import { moduleWrapper } from '../components/moduleWrapper';
2
2
  import { useValuesSelector } from './context';
3
- export const usePages = function () {
4
- let {
5
- siteId
6
- } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
7
- siteId: undefined
8
- };
3
+ export const usePages = ({
4
+ siteId
5
+ } = {
6
+ siteId: undefined
7
+ }) => {
9
8
  const pages = useValuesSelector(v => v.pages);
10
9
  if (siteId) {
11
10
  pages.filter(tapp => tapp.siteId === siteId);
12
11
  }
13
12
  return pages;
14
13
  };
15
- export const usePage = _ref => {
16
- let {
17
- id,
18
- siteId
19
- } = _ref;
14
+ export const usePage = ({
15
+ id,
16
+ siteId
17
+ }) => {
20
18
  const pages = useValuesSelector(v => v.pages);
21
19
  if (id) {
22
20
  var _pages$find;
@@ -24,15 +22,14 @@ export const usePage = _ref => {
24
22
  }
25
23
  return null;
26
24
  };
27
- export const getPage = function () {
25
+ export const getPage = ({
26
+ id,
27
+ siteId
28
+ } = {
29
+ id: null,
30
+ siteId: null
31
+ }) => {
28
32
  var _pages$find3;
29
- let {
30
- id,
31
- siteId
32
- } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
33
- id: null,
34
- siteId: null
35
- };
36
33
  const {
37
34
  pages,
38
35
  currentPage
@@ -13,10 +13,9 @@ export const useWindowMetricsListener = () => {
13
13
  };
14
14
  }, []);
15
15
  };
16
- export const useWindowMetrics = function () {
17
- let {
18
- enabled = true
19
- } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
16
+ export const useWindowMetrics = ({
17
+ enabled = true
18
+ } = {}) => {
20
19
  const [value, setValue] = useState({
21
20
  bottomBarHeight: 0,
22
21
  offsetTop: 0,
@@ -1,30 +1,29 @@
1
1
  import React, { startTransition, useEffect, useState } from 'react';
2
2
  import HostIframe from './iframe/HostIframe';
3
3
  import ModuleHost from './module/ModuleHost';
4
- const ChaynsHost = _ref => {
5
- let {
6
- type,
7
- iFrameProps,
8
- functions,
9
- customFunctions,
10
- src,
11
- iFrameRef = undefined,
12
- loadingComponent = undefined,
13
- system,
14
- pages,
15
- language,
16
- isAdminModeActive,
17
- site,
18
- user,
19
- currentPage,
20
- device,
21
- parameters,
22
- customData,
23
- environment,
24
- preventStagingReplacement,
25
- dialog,
26
- styleSettings
27
- } = _ref;
4
+ const ChaynsHost = ({
5
+ type,
6
+ iFrameProps,
7
+ functions,
8
+ customFunctions,
9
+ src,
10
+ iFrameRef = undefined,
11
+ loadingComponent = undefined,
12
+ system,
13
+ pages,
14
+ language,
15
+ isAdminModeActive,
16
+ site,
17
+ user,
18
+ currentPage,
19
+ device,
20
+ parameters,
21
+ customData,
22
+ environment,
23
+ preventStagingReplacement,
24
+ dialog,
25
+ styleSettings
26
+ }) => {
28
27
  const [isVisible, setIsVisible] = useState(type !== 'client-module' && (type !== 'server-module' || !!(system !== null && system !== void 0 && system.serverUrl)));
29
28
  useEffect(() => {
30
29
  if (isVisible) return;
@@ -4,28 +4,27 @@ import * as comlink from 'comlink';
4
4
  import postIframeForm from '../../util/postIframeForm';
5
5
  import useUpdateData from './utils/useUpdateData';
6
6
  import { replaceStagingUrl } from "../../util/url";
7
- const HostIframe = _ref => {
8
- let {
9
- iFrameProps,
10
- src,
11
- postForm = false,
12
- iFrameRef,
13
- pages,
14
- isAdminModeActive,
15
- site,
16
- user,
17
- currentPage,
18
- functions,
19
- customFunctions,
20
- device,
21
- language,
22
- parameters,
23
- environment,
24
- customData,
25
- preventStagingReplacement,
26
- dialog,
27
- styleSettings
28
- } = _ref;
7
+ const HostIframe = ({
8
+ iFrameProps,
9
+ src,
10
+ postForm = false,
11
+ iFrameRef,
12
+ pages,
13
+ isAdminModeActive,
14
+ site,
15
+ user,
16
+ currentPage,
17
+ functions,
18
+ customFunctions,
19
+ device,
20
+ language,
21
+ parameters,
22
+ environment,
23
+ customData,
24
+ preventStagingReplacement,
25
+ dialog,
26
+ styleSettings
27
+ }) => {
29
28
  const eventTarget = useRef();
30
29
  const ref = useRef();
31
30
  const currentDataRef = useRef();
@@ -2,12 +2,11 @@ import React, { useContext, useMemo } from 'react';
2
2
  import { ModuleContext } from '../../constants/moduleContext';
3
3
  import loadComponent from './utils/loadComponent';
4
4
  import { replaceStagingUrl } from "../../util/url";
5
- const System = _ref => {
6
- let {
7
- system,
8
- fallback,
9
- ...props
10
- } = _ref;
5
+ const System = ({
6
+ system,
7
+ fallback,
8
+ ...props
9
+ }) => {
11
10
  const Component = useMemo(() => loadComponent(system.scope, system.module, globalThis.window ? system.url : system.serverUrl, undefined, system.preventSingleton), [system.scope, system.module, system.url, system.serverUrl, system.preventSingleton]);
12
11
  if (!globalThis.window) {
13
12
  var _system$scope, _moduleContext$_syste;
@@ -22,26 +21,25 @@ const System = _ref => {
22
21
  fallback: fallback || ''
23
22
  }, React.createElement(Component, props));
24
23
  };
25
- const ModuleHost = _ref2 => {
26
- let {
27
- system,
28
- children = null,
29
- functions,
30
- customFunctions,
31
- pages,
32
- isAdminModeActive,
33
- site,
34
- user,
35
- currentPage,
36
- device,
37
- language,
38
- parameters,
39
- customData,
40
- dialog,
41
- environment,
42
- preventStagingReplacement,
43
- styleSettings
44
- } = _ref2;
24
+ const ModuleHost = ({
25
+ system,
26
+ children = null,
27
+ functions,
28
+ customFunctions,
29
+ pages,
30
+ isAdminModeActive,
31
+ site,
32
+ user,
33
+ currentPage,
34
+ device,
35
+ language,
36
+ parameters,
37
+ customData,
38
+ dialog,
39
+ environment,
40
+ preventStagingReplacement,
41
+ styleSettings
42
+ }) => {
45
43
  const data = useMemo(() => {
46
44
  const result = {
47
45
  site,
@@ -1,17 +1,13 @@
1
1
  import React from "react";
2
- export const loadModule = function (scope, module, url) {
3
- let preventSingleton = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
4
- if (!globalThis.moduleFederationRuntime || !globalThis.moduleFederationScopes) {
2
+ export const loadModule = (scope, module, url, preventSingleton = false) => {
3
+ if (!globalThis.moduleFederationScopes) {
5
4
  throw new Error('[chayns-api] moduleFederationSharing has not been initialized. Make sure to call initModuleFederationSharing.');
6
5
  }
7
- const {
8
- loadRemote,
9
- registerRemotes
10
- } = globalThis.moduleFederationRuntime;
11
6
  const {
12
7
  registeredScopes,
13
8
  moduleMap,
14
- componentMap
9
+ componentMap,
10
+ getInstance
15
11
  } = globalThis.moduleFederationScopes;
16
12
  try {
17
13
  url = new URL(url).toString();
@@ -20,7 +16,7 @@ export const loadModule = function (scope, module, url) {
20
16
  if (scope in registeredScopes) {
21
17
  console.error(`[chayns-api] call registerRemote with force for scope ${scope}. url: ${url}`);
22
18
  }
23
- registerRemotes([{
19
+ getInstance().registerRemotes([{
24
20
  shareScope: url.endsWith('v2.remoteEntry.js') || url.endsWith('mf-manifest.json') ? 'chayns-api' : 'default',
25
21
  name: scope,
26
22
  entry: url,
@@ -34,7 +30,7 @@ export const loadModule = function (scope, module, url) {
34
30
  }
35
31
  if (!(module in moduleMap[scope])) {
36
32
  const path = `${scope}/${module.replace(/^\.\//, '')}`;
37
- const promise = loadRemote(path);
33
+ const promise = getInstance().loadRemote(path);
38
34
  promise.catch(e => {
39
35
  console.error("[chayns-api] Failed to load module", scope, url, e);
40
36
  registeredScopes[scope] = '';
@@ -43,22 +39,17 @@ export const loadModule = function (scope, module, url) {
43
39
  }
44
40
  return moduleMap[scope][module];
45
41
  };
46
- const loadComponent = function (scope, module, url) {
47
- let skipCompatMode = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
48
- let preventSingleton = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
42
+ const loadComponent = (scope, module, url, skipCompatMode = false, preventSingleton = false) => {
49
43
  if (skipCompatMode) {
50
44
  console.warn('[chayns-api] skipCompatMode-option is deprecated and is set automatically now');
51
45
  }
52
- if (!globalThis.moduleFederationRuntime || !globalThis.moduleFederationScopes) {
46
+ if (!globalThis.moduleFederationScopes) {
53
47
  throw new Error('[chayns-api] moduleFederationSharing has not been initialized. Make sure to call initModuleFederationSharing.');
54
48
  }
55
- const {
56
- loadShareSync,
57
- getInstance
58
- } = globalThis.moduleFederationRuntime;
59
49
  const {
60
50
  componentMap,
61
- registeredScopes
51
+ registeredScopes,
52
+ getInstance
62
53
  } = globalThis.moduleFederationScopes;
63
54
  if (!componentMap[scope]) {
64
55
  componentMap[scope] = {};
@@ -69,21 +60,7 @@ const loadComponent = function (scope, module, url) {
69
60
  if (typeof Module.default === 'function') {
70
61
  return Module;
71
62
  }
72
- const shareScopes = typeof getInstance === 'function' ? getInstance().shareScopeMap : await new Promise(resolve => {
73
- loadShareSync('react', {
74
- resolver: shareOptions => {
75
- const optionsMap = shareOptions.reduce((p, e) => {
76
- p[e.version] = e;
77
- e.version;
78
- return p;
79
- }, {});
80
- resolve({
81
- 'chayns-api': optionsMap
82
- });
83
- return shareOptions[0];
84
- }
85
- });
86
- });
63
+ const shareScopes = getInstance().shareScopeMap;
87
64
  const sharedReact = (_shareScopes$chaynsA = shareScopes['chayns-api'].react) === null || _shareScopes$chaynsA === void 0 ? void 0 : _shareScopes$chaynsA[React.version];
88
65
  const matchReactVersion = sharedReact && sharedReact.useIn.includes(scope) && ((_sharedReact$lib = sharedReact.lib) === null || _sharedReact$lib === void 0 ? void 0 : _sharedReact$lib.call(sharedReact)) === React;
89
66
  if (!matchReactVersion || Module.default.environment !== 'production' || (Module.default.version || 1) < 2) {
@@ -0,0 +1,25 @@
1
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
2
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
3
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
4
+ class TrustedDomainsError extends Error {
5
+ constructor(entry) {
6
+ super('Remote entry ' + entry + ' is not in trusted domains');
7
+ _defineProperty(this, "name", 'TrustedDomainsError');
8
+ }
9
+ }
10
+ export const TrustedDomainsPlugin = (trustedDomains = []) => {
11
+ return {
12
+ name: 'trusted-domains',
13
+ beforeRequest(args) {
14
+ args.options.remotes.forEach(remote => {
15
+ if ('entry' in remote) {
16
+ const parsed = new URL(remote.entry);
17
+ if (!trustedDomains.some(domain => parsed.hostname.endsWith(domain))) {
18
+ throw new TrustedDomainsError(remote.entry);
19
+ }
20
+ }
21
+ });
22
+ return args;
23
+ }
24
+ };
25
+ };
@@ -1 +1,2 @@
1
- export { SSRManifestPlugin } from './SSRManifestPlugin';
1
+ export { SSRManifestPlugin } from './SSRManifestPlugin';
2
+ export { TrustedDomainsPlugin } from './TrustedDomainsPlugins';
@@ -60,6 +60,7 @@ export let ScreenSize = function (ScreenSize) {
60
60
  export let AppFlavor = function (AppFlavor) {
61
61
  AppFlavor["None"] = "none";
62
62
  AppFlavor["Chayns"] = "chayns";
63
+ AppFlavor["Electron"] = "electron";
63
64
  return AppFlavor;
64
65
  }({});
65
66
  export let AccessMode = function (AccessMode) {
@@ -135,12 +136,6 @@ export let DesignSettingsUpdateCoverTypes = function (DesignSettingsUpdateCoverT
135
136
  DesignSettingsUpdateCoverTypes[DesignSettingsUpdateCoverTypes["None"] = 4] = "None";
136
137
  return DesignSettingsUpdateCoverTypes;
137
138
  }({});
138
- export let DesignSettingsUpdateColorSchemeMode = function (DesignSettingsUpdateColorSchemeMode) {
139
- DesignSettingsUpdateColorSchemeMode[DesignSettingsUpdateColorSchemeMode["Normal"] = 0] = "Normal";
140
- DesignSettingsUpdateColorSchemeMode[DesignSettingsUpdateColorSchemeMode["Dark"] = 1] = "Dark";
141
- DesignSettingsUpdateColorSchemeMode[DesignSettingsUpdateColorSchemeMode["Bright"] = 2] = "Bright";
142
- return DesignSettingsUpdateColorSchemeMode;
143
- }({});
144
139
  export let DesignSettingsUpdateTappViewModes = function (DesignSettingsUpdateTappViewModes) {
145
140
  DesignSettingsUpdateTappViewModes[DesignSettingsUpdateTappViewModes["Normal"] = 0] = "Normal";
146
141
  DesignSettingsUpdateTappViewModes[DesignSettingsUpdateTappViewModes["Exclusive"] = 1] = "Exclusive";
@@ -251,6 +246,7 @@ export let AppName = function (AppName) {
251
246
  AppName[AppName["Team"] = 8] = "Team";
252
247
  AppName[AppName["CityApp"] = 9] = "CityApp";
253
248
  AppName[AppName["ElectronChayns"] = 10] = "ElectronChayns";
249
+ AppName[AppName["ElectronTeam"] = 11] = "ElectronTeam";
254
250
  return AppName;
255
251
  }({});
256
252
  export let BrowserName = function (BrowserName) {
File without changes
@@ -7,8 +7,7 @@ export function isAppStorageAvailable() {
7
7
  }
8
8
  return ((_this$values$device$a2 = this.values.device.app) === null || _this$values$device$a2 === void 0 ? void 0 : _this$values$device$a2.appVersion) >= (['iOS', 'Mac OS'].includes(this.values.device.os) ? 1046 : 1033);
9
9
  }
10
- export function getAppStorageItem(storeName, key) {
11
- let callbackPrefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'chaynsApiV5Callback';
10
+ export function getAppStorageItem(storeName, key, callbackPrefix = 'chaynsApiV5Callback') {
12
11
  const callbackName = `${callbackPrefix}_${this.counter++}`;
13
12
  return new Promise(resolve => {
14
13
  window[callbackName] = (_key, _storeName, value) => {
@@ -31,8 +30,7 @@ export function getAppStorageItem(storeName, key) {
31
30
  }
32
31
  });
33
32
  }
34
- export function setAppStorageItem(storeName, key, value) {
35
- let callbackPrefix = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'chaynsApiV5Callback';
33
+ export function setAppStorageItem(storeName, key, value, callbackPrefix = 'chaynsApiV5Callback') {
36
34
  const callbackName = `${callbackPrefix}_${this.counter++}`;
37
35
  return new Promise((resolve, reject) => {
38
36
  window[callbackName] = () => {
@@ -70,8 +68,7 @@ export function clearAppStorage(storeName) {
70
68
  window.chaynsWebViewStorage.chaynsDataErase(storeName);
71
69
  }
72
70
  }
73
- export async function addAppStorageListener(storeName, prefix, callback) {
74
- let callbackPrefix = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'chaynsApiV5Callback';
71
+ export async function addAppStorageListener(storeName, prefix, callback, callbackPrefix = 'chaynsApiV5Callback') {
75
72
  const callbackName = `${callbackPrefix}_${this.counter++}`;
76
73
  const {
77
74
  shouldInitialize
@@ -1,32 +1,44 @@
1
1
  import { UAParser } from 'ua-parser-js';
2
2
  import { AppFlavor, AppName, ScreenSize } from '../types/IChaynsReact';
3
- const getDeviceInfo = function (userAgent, acceptHeader) {
3
+ const getDeviceInfo = (userAgent, acceptHeader, {
4
+ imei
5
+ } = {}) => {
4
6
  var _match$groups, _match$groups2, _customMatch$groups, _browser$version$spli, _browser$version, _uaParser$getOS, _uaParser$getOS2, _uaParser$getOS3;
5
- let {
6
- imei
7
- } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
8
7
  const uaParser = new UAParser(userAgent);
9
8
  let appName = AppName.Unknown;
10
- const match = /(?:my)?chayns\/(?<version>\d+).*(?<siteId>\d{5}-\d{5})/i.exec(userAgent);
11
- const customMatch = /\s(?<name>intercom|sidekick|team|cityApp|electron-chayns|electron-d3sc)\/(?<version>\d+)/i.exec(userAgent);
9
+ let appFlavor = AppFlavor.None;
10
+ const match = /(?:^|\s)(?:my)?chayns\/(?<version>\d+).*(?<siteId>\d{5}-\d{5})/i.exec(userAgent);
11
+ const customMatch = /\s(?<name>intercom|sidekick|team|cityApp|electron-chayns|electron-d3sc|electron-team)\/(?<version>\d+)/i.exec(userAgent);
12
12
  if (/\sintercom\/\d+/i.test(userAgent)) {
13
13
  appName = AppName.TobitChat;
14
+ appFlavor = AppFlavor.Chayns;
14
15
  } else if (/\ssidekick\/\d+/i.test(userAgent)) {
15
16
  appName = AppName.Sidekick;
17
+ appFlavor = AppFlavor.Chayns;
16
18
  } else if (/\steam\/\d+/i.test(userAgent)) {
17
19
  appName = AppName.Team;
20
+ appFlavor = AppFlavor.Chayns;
18
21
  } else if (/\scityApp\/\d+/i.test(userAgent)) {
19
22
  appName = AppName.CityApp;
23
+ appFlavor = AppFlavor.Chayns;
20
24
  } else if ((match === null || match === void 0 || (_match$groups = match.groups) === null || _match$groups === void 0 ? void 0 : _match$groups.siteId) === '60021-08989') {
21
25
  appName = AppName.Chayns;
26
+ appFlavor = AppFlavor.Chayns;
22
27
  } else if ((match === null || match === void 0 || (_match$groups2 = match.groups) === null || _match$groups2 === void 0 ? void 0 : _match$groups2.siteId) === '77892-10814') {
23
28
  appName = AppName.David;
29
+ appFlavor = AppFlavor.Chayns;
24
30
  } else if (match) {
25
31
  appName = AppName.Location;
32
+ appFlavor = AppFlavor.Chayns;
26
33
  } else if (/dface|h96pp|h96max|jabiru|chaynsterminal|wayter|odroidn2p|chayns-runtime-custom/i.test(userAgent)) {
27
34
  appName = AppName.ChaynsLauncher;
35
+ appFlavor = AppFlavor.Chayns;
28
36
  } else if (/electron-chayns|electron-d3sc/i.test(userAgent)) {
29
37
  appName = AppName.ElectronChayns;
38
+ appFlavor = AppFlavor.Electron;
39
+ } else if (/electron-team/i.test(userAgent)) {
40
+ appName = AppName.ElectronTeam;
41
+ appFlavor = AppFlavor.Electron;
30
42
  }
31
43
  let appVersion = match !== null && match !== void 0 && match.groups ? Number.parseInt(match.groups.version, 10) : NaN;
32
44
  if (customMatch !== null && customMatch !== void 0 && (_customMatch$groups = customMatch.groups) !== null && _customMatch$groups !== void 0 && _customMatch$groups.version) {
@@ -42,7 +54,7 @@ const getDeviceInfo = function (userAgent, acceptHeader) {
42
54
  };
43
55
  result.app = {
44
56
  name: appName,
45
- flavor: appName === AppName.Unknown || appName === AppName.ElectronChayns ? AppFlavor.None : AppFlavor.Chayns,
57
+ flavor: appFlavor,
46
58
  version: match !== null && match !== void 0 && match.groups ? Number.parseInt(match.groups.version, 10) : NaN,
47
59
  appVersion,
48
60
  callVersion: match !== null && match !== void 0 && match.groups ? Number.parseInt(match.groups.version, 10) : NaN
@@ -56,7 +68,7 @@ const getDeviceInfo = function (userAgent, acceptHeader) {
56
68
  result.isTouch = getClientDeviceInfo().isTouch;
57
69
  } else {
58
70
  const screenSizeByUA = /mobi/i.test(userAgent) ? ScreenSize.SM : ScreenSize.XL;
59
- result.screenSize = appName !== AppName.Unknown && appName !== AppName.ElectronChayns ? ScreenSize.XS : screenSizeByUA;
71
+ result.screenSize = appFlavor === AppFlavor.Chayns ? ScreenSize.XS : screenSizeByUA;
60
72
  }
61
73
  return result;
62
74
  };
@@ -5,23 +5,18 @@ let ReactDOMClient;
5
5
  try {
6
6
  ReactDOMClient = require('react-dom/client');
7
7
  } catch (e) {}
8
- export const initModuleFederationSharing = _ref => {
9
- let {
10
- name,
11
- plugins = []
12
- } = _ref;
13
- if (globalThis.moduleFederationRuntime) {
8
+ export const initModuleFederationSharing = ({
9
+ name,
10
+ plugins = []
11
+ }) => {
12
+ if (globalThis.moduleFederationScopes) {
14
13
  return;
15
14
  }
16
- globalThis.moduleFederationRuntime = require('@module-federation/enhanced/runtime');
17
- globalThis.moduleFederationScopes = {
18
- registeredScopes: {},
19
- moduleMap: {},
20
- componentMap: {}
21
- };
15
+ const runtime = require('@module-federation/enhanced/runtime');
16
+ globalThis.moduleFederationRuntime = runtime;
22
17
  const {
23
18
  init
24
- } = globalThis.moduleFederationRuntime;
19
+ } = runtime;
25
20
  const shared = {
26
21
  react: {
27
22
  version: React.version,
@@ -41,10 +36,16 @@ export const initModuleFederationSharing = _ref => {
41
36
  lib: () => ReactDOMClient
42
37
  };
43
38
  }
44
- init({
39
+ const instance = init({
45
40
  name: name !== null && name !== void 0 ? name : '',
46
41
  remotes: [],
47
42
  shared,
48
43
  plugins: [SequentialLoadPlugin(), ...plugins]
49
44
  });
45
+ globalThis.moduleFederationScopes = {
46
+ registeredScopes: {},
47
+ moduleMap: {},
48
+ componentMap: {},
49
+ getInstance: () => instance
50
+ };
50
51
  };
@@ -1,15 +1,14 @@
1
1
  import { getDevice } from '../calls';
2
- import { AppName } from '../types/IChaynsReact';
2
+ import { AppFlavor } from '../types/IChaynsReact';
3
3
  export const isApp = () => {
4
- var _getDevice$app$name, _getDevice$app;
5
- return ((_getDevice$app$name = (_getDevice$app = getDevice().app) === null || _getDevice$app === void 0 ? void 0 : _getDevice$app.name) !== null && _getDevice$app$name !== void 0 ? _getDevice$app$name : AppName.Unknown) !== AppName.Unknown;
4
+ var _getDevice$app;
5
+ return ((_getDevice$app = getDevice().app) === null || _getDevice$app === void 0 ? void 0 : _getDevice$app.flavor) === AppFlavor.Chayns;
6
6
  };
7
- export const isAppCallSupported = _ref => {
7
+ export const isAppCallSupported = ({
8
+ minAndroidVersion = 1,
9
+ minIOSVersion = 1
10
+ }) => {
8
11
  var _device$app;
9
- let {
10
- minAndroidVersion = 1,
11
- minIOSVersion = 1
12
- } = _ref;
13
12
  if (!isApp()) return false;
14
13
  const device = getDevice();
15
14
  if (!((_device$app = device.app) !== null && _device$app !== void 0 && _device$app.callVersion) || isNaN(device.app.callVersion)) return false;
@@ -20,4 +19,8 @@ export const isAppCallSupported = _ref => {
20
19
  return device.app.callVersion >= minAndroidVersion;
21
20
  }
22
21
  return false;
22
+ };
23
+ export const isElectron = () => {
24
+ var _getDevice$app2;
25
+ return ((_getDevice$app2 = getDevice().app) === null || _getDevice$app2 === void 0 ? void 0 : _getDevice$app2.flavor) === AppFlavor.Electron;
23
26
  };
@@ -6,8 +6,7 @@ Comlink.transferHandlers.set("FUNCTION", {
6
6
  serialize(obj) {
7
7
  obj._functionKeys = [];
8
8
  const ports = [];
9
- Object.entries(obj).forEach(_ref => {
10
- let [k, v] = _ref;
9
+ Object.entries(obj).forEach(([k, v]) => {
11
10
  if (typeof v === 'function') {
12
11
  const {
13
12
  port1,