@bitrix24/b24jssdk 0.2.0 → 0.2.1

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @version @bitrix24/b24jssdk v0.2.0
2
+ * @version @bitrix24/b24jssdk v0.2.1
3
3
  * @copyright (c) 2025 Bitrix24
4
4
  * @licence MIT
5
5
  * @links https://github.com/bitrix24/b24jssdk - GitHub
@@ -504,6 +504,24 @@ class TypeManager {
504
504
  }
505
505
  const Type = new TypeManager();
506
506
 
507
+ function pick(data, keys) {
508
+ const result = {};
509
+ for (const key of keys) {
510
+ result[key] = data[key];
511
+ }
512
+ return result;
513
+ }
514
+ function omit(data, keys) {
515
+ const result = { ...data };
516
+ for (const key of keys) {
517
+ delete result[key];
518
+ }
519
+ return result;
520
+ }
521
+ function isArrayOfArray(item) {
522
+ return Array.isArray(item[0]);
523
+ }
524
+
507
525
  const _state = {};
508
526
  let getRandomValues;
509
527
  const randoms8 = new Uint8Array(16);
@@ -1882,7 +1900,7 @@ class Http {
1882
1900
  result.logTag = this.#logTag;
1883
1901
  }
1884
1902
  result[this.#requestIdGenerator.getQueryStringParameterName()] = this.#requestIdGenerator.getRequestId();
1885
- result[this.#requestIdGenerator.getQueryStringSdkParameterName()] = "0.2.0";
1903
+ result[this.#requestIdGenerator.getQueryStringSdkParameterName()] = "0.2.1";
1886
1904
  if (!!result.data && !!result.data.start) {
1887
1905
  delete result.data.start;
1888
1906
  }
@@ -3044,11 +3062,13 @@ var MessageCommands = /* @__PURE__ */ ((MessageCommands2) => {
3044
3062
  class MessageManager {
3045
3063
  #appFrame;
3046
3064
  #callbackPromises;
3065
+ #callbackSingletone;
3047
3066
  _logger = null;
3048
3067
  runCallbackHandler;
3049
3068
  constructor(appFrame) {
3050
3069
  this.#appFrame = appFrame;
3051
3070
  this.#callbackPromises = /* @__PURE__ */ new Map();
3071
+ this.#callbackSingletone = /* @__PURE__ */ new Map();
3052
3072
  this.runCallbackHandler = this._runCallback.bind(this);
3053
3073
  }
3054
3074
  setLogger(logger) {
@@ -3098,17 +3118,22 @@ class MessageManager {
3098
3118
  timeoutId: null
3099
3119
  };
3100
3120
  const keyPromise = this.#setCallbackPromise(promiseHandler);
3121
+ const paramsSend = omit(params || {}, ["callBack", "isSafely", "safelyTime"]);
3122
+ const { callBack } = params || {};
3123
+ if (callBack) {
3124
+ this.#callbackSingletone.set(keyPromise, callBack);
3125
+ }
3101
3126
  if (command.toString().includes(":")) {
3102
3127
  cmd = {
3103
3128
  method: command.toString(),
3104
- params: params ?? "",
3129
+ params: paramsSend ?? "",
3105
3130
  callback: keyPromise,
3106
3131
  appSid: this.#appFrame.getAppSid()
3107
3132
  };
3108
3133
  } else {
3109
3134
  cmd = command.toString();
3110
3135
  const listParams = [
3111
- params ? JSON.stringify(params) : null,
3136
+ params ? JSON.stringify(paramsSend) : null,
3112
3137
  keyPromise,
3113
3138
  this.#appFrame.getAppSid()
3114
3139
  ];
@@ -3163,6 +3188,11 @@ class MessageManager {
3163
3188
  }
3164
3189
  this.#callbackPromises.delete(cmd.id);
3165
3190
  promise.resolve(cmd.args);
3191
+ } else if (this.#callbackSingletone.has(cmd.id)) {
3192
+ const callBack = this.#callbackSingletone.get(cmd.id);
3193
+ if (callBack) {
3194
+ callBack.apply(globalThis, [cmd.args]);
3195
+ }
3166
3196
  }
3167
3197
  }
3168
3198
  }
@@ -3889,15 +3919,17 @@ class PlacementManager {
3889
3919
  /**
3890
3920
  * Set Up the Interface Event Handler
3891
3921
  * @param {string} eventName
3922
+ * @param {(...args: any[]) => void} callBack
3892
3923
  * @return {Promise<any>}
3893
3924
  *
3894
3925
  * @link https://apidocs.bitrix24.com/api-reference/widgets/ui-interaction/bx24-placement-bind-event.html
3895
3926
  */
3896
- async bindEvent(eventName) {
3927
+ async bindEvent(eventName, callBack) {
3897
3928
  return this.#messageManager.send(
3898
- MessageCommands.getInterface,
3929
+ MessageCommands.placementBindEvent,
3899
3930
  {
3900
3931
  event: eventName,
3932
+ callBack,
3901
3933
  isSafely: true
3902
3934
  }
3903
3935
  );
@@ -13576,6 +13608,9 @@ exports.Type = Type;
13576
13608
  exports.TypeOption = TypeOption;
13577
13609
  exports.TypeSpecificUrl = TypeSpecificUrl;
13578
13610
  exports.initializeB24Frame = initializeB24Frame;
13611
+ exports.isArrayOfArray = isArrayOfArray;
13612
+ exports.omit = omit;
13613
+ exports.pick = pick;
13579
13614
  exports.useB24Helper = useB24Helper;
13580
13615
  exports.useFormatter = useFormatter;
13581
13616
  //# sourceMappingURL=index.cjs.map