chayns-api 2.6.10 → 2.6.12

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.
@@ -9,6 +9,7 @@ var comlink = _interopRequireWildcard(require("comlink"));
9
9
  var _postIframeForm = _interopRequireDefault(require("../../util/postIframeForm"));
10
10
  var _useUpdateData = _interopRequireDefault(require("./utils/useUpdateData"));
11
11
  var _url = require("../../util/url");
12
+ var _transferNestedFunctions = require("../../util/transferNestedFunctions");
12
13
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
14
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
14
15
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
@@ -77,6 +78,7 @@ const HostIframe = ({
77
78
  (0, _react.useEffect)(() => {
78
79
  var _ref$current;
79
80
  if ((_ref$current = ref.current) !== null && _ref$current !== void 0 && _ref$current.contentWindow) {
81
+ (0, _transferNestedFunctions.initTransferNestedFunctions)();
80
82
  const obj = {
81
83
  [iFrameProps.name]: {
82
84
  functions: {
package/dist/cjs/index.js CHANGED
@@ -91,7 +91,6 @@ Object.defineProperty(exports, "withHydrationBoundary", {
91
91
  return _withHydrationBoundary.default;
92
92
  }
93
93
  });
94
- require("./util/transferNestedFunctions");
95
94
  var _ChaynsProvider = _interopRequireDefault(require("./components/ChaynsProvider"));
96
95
  var _deviceHelper = _interopRequireWildcard(require("./util/deviceHelper"));
97
96
  var _ChaynsHost = _interopRequireDefault(require("./host/ChaynsHost"));
@@ -42,7 +42,6 @@ Object.defineProperty(exports, "getScreenSize", {
42
42
  return _deviceHelper.getScreenSize;
43
43
  }
44
44
  });
45
- require("./util/transferNestedFunctions");
46
45
  var _deviceHelper = _interopRequireWildcard(require("./util/deviceHelper"));
47
46
  var _calls = require("./calls");
48
47
  Object.keys(_calls).forEach(function (key) {
@@ -1,35 +1,49 @@
1
1
  "use strict";
2
2
 
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.initTransferNestedFunctions = void 0;
3
7
  var Comlink = _interopRequireWildcard(require("comlink"));
4
8
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
5
- Comlink.transferHandlers.set("FUNCTION", {
6
- canHandle: obj => {
7
- return obj && typeof obj === "object" && Object.values(obj).some(x => typeof x === 'function');
8
- },
9
- serialize(obj) {
10
- obj._functionKeys = [];
11
- const ports = [];
12
- Object.entries(obj).forEach(([k, v]) => {
13
- if (typeof v === 'function') {
14
- const {
15
- port1,
16
- port2
17
- } = new MessageChannel();
18
- obj._functionKeys.push(k);
19
- Comlink.expose(obj[k], port1);
20
- obj[k] = port2;
21
- ports.push(port2);
22
- }
23
- });
24
- return [obj, ports];
25
- },
26
- deserialize(obj) {
27
- obj._functionKeys.forEach(x => {
28
- if (obj[x] instanceof MessagePort) {
29
- obj[x].start();
30
- obj[x] = Comlink.wrap(obj[x]);
31
- }
32
- });
33
- return obj;
9
+ const TRANSFER_HANDLER_NAME = 'FUNCTION';
10
+ let isInitialized = false;
11
+ const initTransferNestedFunctions = () => {
12
+ if (isInitialized || Comlink.transferHandlers.has(TRANSFER_HANDLER_NAME)) {
13
+ isInitialized = true;
14
+ return;
34
15
  }
35
- });
16
+ Comlink.transferHandlers.set(TRANSFER_HANDLER_NAME, {
17
+ canHandle: obj => {
18
+ return obj && typeof obj === 'object' && Object.values(obj).some(x => typeof x === 'function');
19
+ },
20
+ serialize(obj) {
21
+ obj._functionKeys = [];
22
+ const ports = [];
23
+ Object.entries(obj).forEach(([k, v]) => {
24
+ if (typeof v === 'function') {
25
+ const {
26
+ port1,
27
+ port2
28
+ } = new MessageChannel();
29
+ obj._functionKeys.push(k);
30
+ Comlink.expose(obj[k], port1);
31
+ obj[k] = port2;
32
+ ports.push(port2);
33
+ }
34
+ });
35
+ return [obj, ports];
36
+ },
37
+ deserialize(obj) {
38
+ obj._functionKeys.forEach(x => {
39
+ if (obj[x] instanceof MessagePort) {
40
+ obj[x].start();
41
+ obj[x] = Comlink.wrap(obj[x]);
42
+ }
43
+ });
44
+ return obj;
45
+ }
46
+ });
47
+ isInitialized = true;
48
+ };
49
+ exports.initTransferNestedFunctions = initTransferNestedFunctions;
@@ -617,7 +617,8 @@ class AppWrapper {
617
617
  },
618
618
  createDialog: config => {
619
619
  if (config.type === _IChaynsReact.DialogType.INPUT && typeof config.formatter === 'function') {
620
- config.formatter = config.formatter.toString();
620
+ console.warn('[chayns-api] passing a function as formatter is not supported in the app environment, the formatter will be ignored');
621
+ delete config.formatter;
621
622
  }
622
623
  return new _DialogHandler.default(config, this.functions.openDialog, this.functions.closeDialog, this.functions.dispatchEventToDialogClient, this.functions.addDialogClientEventListener);
623
624
  },
@@ -9,8 +9,8 @@ var _getUserInfo = _interopRequireDefault(require("../calls/getUserInfo"));
9
9
  var _sendMessage = require("../calls/sendMessage");
10
10
  var _visibilityChangeListener = require("../calls/visibilityChangeListener");
11
11
  var _DialogHandler = _interopRequireDefault(require("../handler/DialogHandler"));
12
- var _IChaynsReact = require("../types/IChaynsReact");
13
12
  var _heightHelper = require("../util/heightHelper");
13
+ var _transferNestedFunctions = require("../util/transferNestedFunctions");
14
14
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
15
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
16
16
  class FrameWrapper {
@@ -249,9 +249,6 @@ class FrameWrapper {
249
249
  return this.exposedFunctions.scrollByY(value, duration);
250
250
  },
251
251
  createDialog: config => {
252
- if (config.type === _IChaynsReact.DialogType.INPUT && typeof config.formatter === 'function') {
253
- config.formatter = comlink.proxy(config.formatter);
254
- }
255
252
  return new _DialogHandler.default(config, this.functions.openDialog, this.exposedFunctions.closeDialog, this.functions.dispatchEventToDialogClient, this.functions.addDialogClientEventListener);
256
253
  },
257
254
  closeDialog: async dialogId => {
@@ -320,6 +317,7 @@ class FrameWrapper {
320
317
  });
321
318
  initialized = false;
322
319
  constructor() {
320
+ (0, _transferNestedFunctions.initTransferNestedFunctions)();
323
321
  const initialDataTag = document.querySelector('#__CHAYNS_DATA__');
324
322
  if (initialDataTag) {
325
323
  this.values = JSON.parse(initialDataTag.innerHTML);
@@ -4,6 +4,7 @@ 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
+ import { initTransferNestedFunctions } from '../../util/transferNestedFunctions';
7
8
  const HostIframe = ({
8
9
  iFrameProps,
9
10
  src,
@@ -69,6 +70,7 @@ const HostIframe = ({
69
70
  useEffect(() => {
70
71
  var _ref$current;
71
72
  if ((_ref$current = ref.current) !== null && _ref$current !== void 0 && _ref$current.contentWindow) {
73
+ initTransferNestedFunctions();
72
74
  const obj = {
73
75
  [iFrameProps.name]: {
74
76
  functions: {
package/dist/esm/index.js CHANGED
@@ -1,4 +1,3 @@
1
- import './util/transferNestedFunctions';
2
1
  export { default as ChaynsProvider } from './components/ChaynsProvider';
3
2
  export { default as getDeviceInfo, getScreenSize, getClientDeviceInfo } from './util/deviceHelper';
4
3
  export { default as ChaynsHost } from './host/ChaynsHost';
@@ -1,4 +1,3 @@
1
- import './util/transferNestedFunctions';
2
1
  export { default as getDeviceInfo, getScreenSize, getClientDeviceInfo } from './util/deviceHelper';
3
2
  export * from './calls';
4
3
  export * from './types/IChaynsReact';
@@ -1,32 +1,41 @@
1
1
  import * as Comlink from 'comlink';
2
- Comlink.transferHandlers.set("FUNCTION", {
3
- canHandle: obj => {
4
- return obj && typeof obj === "object" && Object.values(obj).some(x => typeof x === 'function');
5
- },
6
- serialize(obj) {
7
- obj._functionKeys = [];
8
- const ports = [];
9
- Object.entries(obj).forEach(([k, v]) => {
10
- if (typeof v === 'function') {
11
- const {
12
- port1,
13
- port2
14
- } = new MessageChannel();
15
- obj._functionKeys.push(k);
16
- Comlink.expose(obj[k], port1);
17
- obj[k] = port2;
18
- ports.push(port2);
19
- }
20
- });
21
- return [obj, ports];
22
- },
23
- deserialize(obj) {
24
- obj._functionKeys.forEach(x => {
25
- if (obj[x] instanceof MessagePort) {
26
- obj[x].start();
27
- obj[x] = Comlink.wrap(obj[x]);
28
- }
29
- });
30
- return obj;
2
+ const TRANSFER_HANDLER_NAME = 'FUNCTION';
3
+ let isInitialized = false;
4
+ export const initTransferNestedFunctions = () => {
5
+ if (isInitialized || Comlink.transferHandlers.has(TRANSFER_HANDLER_NAME)) {
6
+ isInitialized = true;
7
+ return;
31
8
  }
32
- });
9
+ Comlink.transferHandlers.set(TRANSFER_HANDLER_NAME, {
10
+ canHandle: obj => {
11
+ return obj && typeof obj === 'object' && Object.values(obj).some(x => typeof x === 'function');
12
+ },
13
+ serialize(obj) {
14
+ obj._functionKeys = [];
15
+ const ports = [];
16
+ Object.entries(obj).forEach(([k, v]) => {
17
+ if (typeof v === 'function') {
18
+ const {
19
+ port1,
20
+ port2
21
+ } = new MessageChannel();
22
+ obj._functionKeys.push(k);
23
+ Comlink.expose(obj[k], port1);
24
+ obj[k] = port2;
25
+ ports.push(port2);
26
+ }
27
+ });
28
+ return [obj, ports];
29
+ },
30
+ deserialize(obj) {
31
+ obj._functionKeys.forEach(x => {
32
+ if (obj[x] instanceof MessagePort) {
33
+ obj[x].start();
34
+ obj[x] = Comlink.wrap(obj[x]);
35
+ }
36
+ });
37
+ return obj;
38
+ }
39
+ });
40
+ isInitialized = true;
41
+ };
@@ -579,7 +579,8 @@ export class AppWrapper {
579
579
  },
580
580
  createDialog: config => {
581
581
  if (config.type === DialogType.INPUT && typeof config.formatter === 'function') {
582
- config.formatter = config.formatter.toString();
582
+ console.warn('[chayns-api] passing a function as formatter is not supported in the app environment, the formatter will be ignored');
583
+ delete config.formatter;
583
584
  }
584
585
  return new DialogHandler(config, this.functions.openDialog, this.functions.closeDialog, this.functions.dispatchEventToDialogClient, this.functions.addDialogClientEventListener);
585
586
  },
@@ -6,8 +6,8 @@ import getUserInfo from '../calls/getUserInfo';
6
6
  import { sendMessageToGroup, sendMessageToPage, sendMessageToUser } from '../calls/sendMessage';
7
7
  import { addVisibilityChangeListener, removeVisibilityChangeListener } from '../calls/visibilityChangeListener';
8
8
  import DialogHandler from '../handler/DialogHandler';
9
- import { DialogType } from '../types/IChaynsReact';
10
9
  import { setTappHeight } from '../util/heightHelper';
10
+ import { initTransferNestedFunctions } from '../util/transferNestedFunctions';
11
11
  export class FrameWrapper {
12
12
  constructor() {
13
13
  _defineProperty(this, "resolve", null);
@@ -245,9 +245,6 @@ export class FrameWrapper {
245
245
  return this.exposedFunctions.scrollByY(value, duration);
246
246
  },
247
247
  createDialog: config => {
248
- if (config.type === DialogType.INPUT && typeof config.formatter === 'function') {
249
- config.formatter = comlink.proxy(config.formatter);
250
- }
251
248
  return new DialogHandler(config, this.functions.openDialog, this.exposedFunctions.closeDialog, this.functions.dispatchEventToDialogClient, this.functions.addDialogClientEventListener);
252
249
  },
253
250
  closeDialog: async dialogId => {
@@ -324,6 +321,7 @@ export class FrameWrapper {
324
321
  _defineProperty(this, "emitChange", () => {
325
322
  this.listeners.forEach(l => l());
326
323
  });
324
+ initTransferNestedFunctions();
327
325
  const initialDataTag = document.querySelector('#__CHAYNS_DATA__');
328
326
  if (initialDataTag) {
329
327
  this.values = JSON.parse(initialDataTag.innerHTML);
@@ -1,4 +1,3 @@
1
- import './util/transferNestedFunctions';
2
1
  export { default as ChaynsProvider, type ChaynsProviderProps } from './components/ChaynsProvider';
3
2
  export { default as getDeviceInfo, getScreenSize, getClientDeviceInfo } from './util/deviceHelper';
4
3
  export { default as ChaynsHost } from './host/ChaynsHost';
@@ -128,6 +128,11 @@ export interface DialogInput {
128
128
  placeholder?: string;
129
129
  inputType?: DialogInputType;
130
130
  defaultValue?: string;
131
+ /**
132
+ * Formats the input value shown in the dialog.
133
+ * Not supported in app environments due to security reasons.
134
+ * @param input
135
+ */
131
136
  formatter?: (input: string) => string;
132
137
  regex?: string;
133
138
  }
@@ -1,4 +1,3 @@
1
- import './util/transferNestedFunctions';
2
1
  export { default as getDeviceInfo, getScreenSize, getClientDeviceInfo } from './util/deviceHelper';
3
2
  export * from './calls';
4
3
  export * from './types/IChaynsReact';
@@ -1 +1 @@
1
- export {};
1
+ export declare const initTransferNestedFunctions: () => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chayns-api",
3
- "version": "2.6.10",
3
+ "version": "2.6.12",
4
4
  "description": "new chayns api",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -16,9 +16,7 @@
16
16
  "default": "./dist/esm/index.js"
17
17
  }
18
18
  },
19
- "sideEffects": [
20
- "**/utils/transferNestedFunctions.*"
21
- ],
19
+ "sideEffects": false,
22
20
  "keywords": [
23
21
  "chayns",
24
22
  "chayns-toolkit",