@veltdev/react 4.6.0-beta.1 → 4.6.0-beta.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.
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- export declare const VELT_SDK_VERSION = "4.6.0-beta.1";
2
+ export declare const VELT_SDK_VERSION = "4.6.0-beta.2";
3
3
  export declare const VELT_SDK_INIT_EVENT = "onVeltInit";
4
4
  export declare const VELT_TAB_ID = "veltTabId";
5
5
  export declare const INTEGRITY_MAP: Record<string, string>;
@@ -3,3 +3,10 @@ export declare const transformWireframeProps: (props: {
3
3
  }) => {
4
4
  [key: string]: any;
5
5
  };
6
+ /**
7
+ * To deep compare two objects.
8
+ * @param arg1 object 1
9
+ * @param arg2 object 2
10
+ * @returns true if both objects are equal, false otherwise
11
+ */
12
+ export declare const deepCompare: (arg1: any, arg2: any) => any;
package/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import React, { createContext, useContext, useState, useEffect, useRef, useMemo } from 'react';
1
+ import React, { createContext, useContext, useState, useRef, useEffect, useMemo } from 'react';
2
2
  import { flushSync } from 'react-dom';
3
3
 
4
4
  /******************************************************************************
@@ -137,18 +137,78 @@ var loadVelt = function (callback, version, staging, develop, proxyDomain, integ
137
137
  }
138
138
  };
139
139
 
140
- var VELT_SDK_VERSION = '4.6.0-beta.1';
140
+ var VELT_SDK_VERSION = '4.6.0-beta.2';
141
141
  var VELT_SDK_INIT_EVENT = 'onVeltInit';
142
142
  var VELT_TAB_ID = 'veltTabId';
143
143
  // integrity map for the Velt SDK
144
144
  // Note: generate integrity hashes with: https://www.srihash.org/
145
145
  var INTEGRITY_MAP = {
146
- '4.6.0-beta.1': 'sha384-JTbW/nmhPvyQyQBXASPMBZ93/7NqYXcqb2pIV9ejr6jQHNQpSMR8rihlSRyZuorA',
146
+ '4.6.0-beta.2': 'sha384-41x97x3xSGab/Dq34QMkc5JBQo0LyNpWETn21C3UbdJO1qink0t99J3j/Xl3G3H9',
147
+ };
148
+
149
+ var validProps = ['veltIf', 'veltClass', 'className', 'variant'];
150
+ var transformWireframeProps = function (props) {
151
+ try {
152
+ var transformedProps_1 = {};
153
+ Object.entries(props).forEach(function (_a) {
154
+ var key = _a[0], value = _a[1];
155
+ if (key === 'children' || key === 'ref' || !validProps.includes(key)) {
156
+ transformedProps_1[key] = value;
157
+ return;
158
+ }
159
+ if (key === 'className') {
160
+ transformedProps_1['class'] = value;
161
+ return;
162
+ }
163
+ // Convert camelCase to dash-case
164
+ var dashKey = key.replace(/[A-Z]/g, function (letter) { return "-".concat(letter.toLowerCase()); });
165
+ transformedProps_1[dashKey] = value;
166
+ // // Handle boolean values - only convert if explicitly true/false
167
+ // if (typeof value === 'boolean') {
168
+ // transformedProps[dashKey] = [true, false].includes(value) ? (value ? 'true' : 'false') : undefined;
169
+ // } else {
170
+ // transformedProps[dashKey] = value;
171
+ // }
172
+ });
173
+ return transformedProps_1;
174
+ }
175
+ catch (error) {
176
+ return props;
177
+ }
178
+ };
179
+ /**
180
+ * To deep compare two objects.
181
+ * @param arg1 object 1
182
+ * @param arg2 object 2
183
+ * @returns true if both objects are equal, false otherwise
184
+ */
185
+ var deepCompare = function (arg1, arg2) {
186
+ try {
187
+ if (Object.prototype.toString.call(arg1) === Object.prototype.toString.call(arg2)) {
188
+ if (Object.prototype.toString.call(arg1) === '[object Object]' || Object.prototype.toString.call(arg1) === '[object Array]') {
189
+ if (Object.keys(arg1).length !== Object.keys(arg2).length) {
190
+ return false;
191
+ }
192
+ return (Object.keys(arg1).every(function (key) {
193
+ return deepCompare(arg1[key], arg2[key]);
194
+ }));
195
+ }
196
+ return (arg1 === arg2);
197
+ }
198
+ return false;
199
+ }
200
+ catch (err) {
201
+ return false;
202
+ }
147
203
  };
148
204
 
149
205
  var SnippylyProvider = function (props) {
150
206
  var apiKey = props.apiKey, user = props.user, config = props.config, documentId = props.documentId, language = props.language, translations = props.translations, autoTranslation = props.autoTranslation, userDataProvider = props.userDataProvider, dataProviders = props.dataProviders, encryptionProvider = props.encryptionProvider, authProvider = props.authProvider, permissionProvider = props.permissionProvider, onClientLoad = props.onClientLoad, children = props.children;
151
207
  var _a = useState(null), client = _a[0], setClient = _a[1];
208
+ var prevAuthProviderRef = useRef(undefined);
209
+ var prevUserDataProviderRef = useRef(undefined);
210
+ var prevDataProvidersRef = useRef(undefined);
211
+ var prevPermissionProviderRef = useRef(undefined);
152
212
  useEffect(function () {
153
213
  if (apiKey) {
154
214
  var staging = config === null || config === void 0 ? void 0 : config.staging;
@@ -174,16 +234,36 @@ var SnippylyProvider = function (props) {
174
234
  }
175
235
  }, []);
176
236
  useEffect(function () {
177
- if (client && userDataProvider) {
178
- if (typeof (client === null || client === void 0 ? void 0 : client.setUserDataProvider) === "function") {
179
- client === null || client === void 0 ? void 0 : client.setUserDataProvider(userDataProvider);
237
+ if (!deepCompare(prevUserDataProviderRef.current, userDataProvider)) {
238
+ if (client && userDataProvider) {
239
+ if (typeof (client === null || client === void 0 ? void 0 : client.setUserDataProvider) === "function") {
240
+ client === null || client === void 0 ? void 0 : client.setUserDataProvider(userDataProvider);
241
+ }
242
+ prevUserDataProviderRef.current = userDataProvider;
243
+ }
244
+ else {
245
+ // Only update ref to undefined if client is available (to track removal)
246
+ // If client is not available, keep old ref so we can set provider when client becomes available
247
+ if (client) {
248
+ prevUserDataProviderRef.current = userDataProvider;
249
+ }
180
250
  }
181
251
  }
182
252
  }, [client, userDataProvider]);
183
253
  useEffect(function () {
184
- if (client && dataProviders) {
185
- if (typeof (client === null || client === void 0 ? void 0 : client.setDataProviders) === "function") {
186
- client === null || client === void 0 ? void 0 : client.setDataProviders(dataProviders);
254
+ if (!deepCompare(prevDataProvidersRef.current, dataProviders)) {
255
+ if (client && dataProviders) {
256
+ if (typeof (client === null || client === void 0 ? void 0 : client.setDataProviders) === "function") {
257
+ client === null || client === void 0 ? void 0 : client.setDataProviders(dataProviders);
258
+ }
259
+ prevDataProvidersRef.current = dataProviders;
260
+ }
261
+ else {
262
+ // Only update ref to undefined if client is available (to track removal)
263
+ // If client is not available, keep old ref so we can set provider when client becomes available
264
+ if (client) {
265
+ prevDataProvidersRef.current = dataProviders;
266
+ }
187
267
  }
188
268
  }
189
269
  }, [client, dataProviders]);
@@ -195,14 +275,34 @@ var SnippylyProvider = function (props) {
195
275
  }
196
276
  }, [client, encryptionProvider]);
197
277
  useEffect(function () {
198
- if (client && authProvider && authProvider.user) {
199
- client.setVeltAuthProvider(authProvider);
278
+ if (!deepCompare(prevAuthProviderRef.current, authProvider)) {
279
+ if (client && authProvider && authProvider.user) {
280
+ client.setVeltAuthProvider(authProvider);
281
+ prevAuthProviderRef.current = authProvider;
282
+ }
283
+ else {
284
+ // Only update ref to undefined if client is available (to track removal)
285
+ // If client is not available, keep old ref so we can set provider when client becomes available
286
+ if (client) {
287
+ prevAuthProviderRef.current = authProvider;
288
+ }
289
+ }
200
290
  }
201
291
  }, [client, authProvider]);
202
292
  useEffect(function () {
203
- if (client && permissionProvider) {
204
- if (typeof (client === null || client === void 0 ? void 0 : client.setPermissionProvider) === "function") {
205
- client === null || client === void 0 ? void 0 : client.setPermissionProvider(permissionProvider);
293
+ if (!deepCompare(prevPermissionProviderRef.current, permissionProvider)) {
294
+ if (client && permissionProvider) {
295
+ if (typeof (client === null || client === void 0 ? void 0 : client.setPermissionProvider) === "function") {
296
+ client === null || client === void 0 ? void 0 : client.setPermissionProvider(permissionProvider);
297
+ }
298
+ prevPermissionProviderRef.current = permissionProvider;
299
+ }
300
+ else {
301
+ // Only update ref to undefined if client is available (to track removal)
302
+ // If client is not available, keep old ref so we can set provider when client becomes available
303
+ if (client) {
304
+ prevPermissionProviderRef.current = permissionProvider;
305
+ }
206
306
  }
207
307
  }
208
308
  }, [client, permissionProvider]);
@@ -1543,37 +1643,6 @@ var VeltWireframe = function (props) {
1543
1643
  return (React.createElement("velt-wireframe", { style: { display: 'none' } }, children));
1544
1644
  };
1545
1645
 
1546
- var validProps = ['veltIf', 'veltClass', 'className', 'variant'];
1547
- var transformWireframeProps = function (props) {
1548
- try {
1549
- var transformedProps_1 = {};
1550
- Object.entries(props).forEach(function (_a) {
1551
- var key = _a[0], value = _a[1];
1552
- if (key === 'children' || key === 'ref' || !validProps.includes(key)) {
1553
- transformedProps_1[key] = value;
1554
- return;
1555
- }
1556
- if (key === 'className') {
1557
- transformedProps_1['class'] = value;
1558
- return;
1559
- }
1560
- // Convert camelCase to dash-case
1561
- var dashKey = key.replace(/[A-Z]/g, function (letter) { return "-".concat(letter.toLowerCase()); });
1562
- transformedProps_1[dashKey] = value;
1563
- // // Handle boolean values - only convert if explicitly true/false
1564
- // if (typeof value === 'boolean') {
1565
- // transformedProps[dashKey] = [true, false].includes(value) ? (value ? 'true' : 'false') : undefined;
1566
- // } else {
1567
- // transformedProps[dashKey] = value;
1568
- // }
1569
- });
1570
- return transformedProps_1;
1571
- }
1572
- catch (error) {
1573
- return props;
1574
- }
1575
- };
1576
-
1577
1646
  var VeltCommentDialogAllComment = function (props) {
1578
1647
  var children = props.children, remainingProps = __rest(props, ["children"]);
1579
1648
  var transformedProps = transformWireframeProps(remainingProps);