@veltdev/react 4.6.0-beta.1 → 4.6.0-beta.3

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/cjs/index.js CHANGED
@@ -145,18 +145,78 @@ var loadVelt = function (callback, version, staging, develop, proxyDomain, integ
145
145
  }
146
146
  };
147
147
 
148
- var VELT_SDK_VERSION = '4.6.0-beta.1';
148
+ var VELT_SDK_VERSION = '4.6.0-beta.3';
149
149
  var VELT_SDK_INIT_EVENT = 'onVeltInit';
150
150
  var VELT_TAB_ID = 'veltTabId';
151
151
  // integrity map for the Velt SDK
152
152
  // Note: generate integrity hashes with: https://www.srihash.org/
153
153
  var INTEGRITY_MAP = {
154
- '4.6.0-beta.1': 'sha384-JTbW/nmhPvyQyQBXASPMBZ93/7NqYXcqb2pIV9ejr6jQHNQpSMR8rihlSRyZuorA',
154
+ '4.6.0-beta.3': 'sha384-I43R8H4FvLLkIXuBB7IuEflos7YyuglKuuyslDHH5LpLCUqVK78p1Rh01hbkBxg0',
155
+ };
156
+
157
+ var validProps = ['veltIf', 'veltClass', 'className', 'variant'];
158
+ var transformWireframeProps = function (props) {
159
+ try {
160
+ var transformedProps_1 = {};
161
+ Object.entries(props).forEach(function (_a) {
162
+ var key = _a[0], value = _a[1];
163
+ if (key === 'children' || key === 'ref' || !validProps.includes(key)) {
164
+ transformedProps_1[key] = value;
165
+ return;
166
+ }
167
+ if (key === 'className') {
168
+ transformedProps_1['class'] = value;
169
+ return;
170
+ }
171
+ // Convert camelCase to dash-case
172
+ var dashKey = key.replace(/[A-Z]/g, function (letter) { return "-".concat(letter.toLowerCase()); });
173
+ transformedProps_1[dashKey] = value;
174
+ // // Handle boolean values - only convert if explicitly true/false
175
+ // if (typeof value === 'boolean') {
176
+ // transformedProps[dashKey] = [true, false].includes(value) ? (value ? 'true' : 'false') : undefined;
177
+ // } else {
178
+ // transformedProps[dashKey] = value;
179
+ // }
180
+ });
181
+ return transformedProps_1;
182
+ }
183
+ catch (error) {
184
+ return props;
185
+ }
186
+ };
187
+ /**
188
+ * To deep compare two objects.
189
+ * @param arg1 object 1
190
+ * @param arg2 object 2
191
+ * @returns true if both objects are equal, false otherwise
192
+ */
193
+ var deepCompare = function (arg1, arg2) {
194
+ try {
195
+ if (Object.prototype.toString.call(arg1) === Object.prototype.toString.call(arg2)) {
196
+ if (Object.prototype.toString.call(arg1) === '[object Object]' || Object.prototype.toString.call(arg1) === '[object Array]') {
197
+ if (Object.keys(arg1).length !== Object.keys(arg2).length) {
198
+ return false;
199
+ }
200
+ return (Object.keys(arg1).every(function (key) {
201
+ return deepCompare(arg1[key], arg2[key]);
202
+ }));
203
+ }
204
+ return (arg1 === arg2);
205
+ }
206
+ return false;
207
+ }
208
+ catch (err) {
209
+ return false;
210
+ }
155
211
  };
156
212
 
157
213
  var SnippylyProvider = function (props) {
158
214
  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;
159
215
  var _a = React.useState(null), client = _a[0], setClient = _a[1];
216
+ var prevAuthProviderRef = React.useRef(undefined);
217
+ var prevUserDataProviderRef = React.useRef(undefined);
218
+ var prevDataProvidersRef = React.useRef(undefined);
219
+ var prevPermissionProviderRef = React.useRef(undefined);
160
220
  React.useEffect(function () {
161
221
  if (apiKey) {
162
222
  var staging = config === null || config === void 0 ? void 0 : config.staging;
@@ -182,16 +242,36 @@ var SnippylyProvider = function (props) {
182
242
  }
183
243
  }, []);
184
244
  React.useEffect(function () {
185
- if (client && userDataProvider) {
186
- if (typeof (client === null || client === void 0 ? void 0 : client.setUserDataProvider) === "function") {
187
- client === null || client === void 0 ? void 0 : client.setUserDataProvider(userDataProvider);
245
+ if (!deepCompare(prevUserDataProviderRef.current, userDataProvider)) {
246
+ if (client && userDataProvider) {
247
+ if (typeof (client === null || client === void 0 ? void 0 : client.setUserDataProvider) === "function") {
248
+ client === null || client === void 0 ? void 0 : client.setUserDataProvider(userDataProvider);
249
+ }
250
+ prevUserDataProviderRef.current = userDataProvider;
251
+ }
252
+ else {
253
+ // Only update ref to undefined if client is available (to track removal)
254
+ // If client is not available, keep old ref so we can set provider when client becomes available
255
+ if (client) {
256
+ prevUserDataProviderRef.current = userDataProvider;
257
+ }
188
258
  }
189
259
  }
190
260
  }, [client, userDataProvider]);
191
261
  React.useEffect(function () {
192
- if (client && dataProviders) {
193
- if (typeof (client === null || client === void 0 ? void 0 : client.setDataProviders) === "function") {
194
- client === null || client === void 0 ? void 0 : client.setDataProviders(dataProviders);
262
+ if (!deepCompare(prevDataProvidersRef.current, dataProviders)) {
263
+ if (client && dataProviders) {
264
+ if (typeof (client === null || client === void 0 ? void 0 : client.setDataProviders) === "function") {
265
+ client === null || client === void 0 ? void 0 : client.setDataProviders(dataProviders);
266
+ }
267
+ prevDataProvidersRef.current = dataProviders;
268
+ }
269
+ else {
270
+ // Only update ref to undefined if client is available (to track removal)
271
+ // If client is not available, keep old ref so we can set provider when client becomes available
272
+ if (client) {
273
+ prevDataProvidersRef.current = dataProviders;
274
+ }
195
275
  }
196
276
  }
197
277
  }, [client, dataProviders]);
@@ -203,14 +283,34 @@ var SnippylyProvider = function (props) {
203
283
  }
204
284
  }, [client, encryptionProvider]);
205
285
  React.useEffect(function () {
206
- if (client && authProvider && authProvider.user) {
207
- client.setVeltAuthProvider(authProvider);
286
+ if (!deepCompare(prevAuthProviderRef.current, authProvider)) {
287
+ if (client && authProvider && authProvider.user) {
288
+ client.setVeltAuthProvider(authProvider);
289
+ prevAuthProviderRef.current = authProvider;
290
+ }
291
+ else {
292
+ // Only update ref to undefined if client is available (to track removal)
293
+ // If client is not available, keep old ref so we can set provider when client becomes available
294
+ if (client) {
295
+ prevAuthProviderRef.current = authProvider;
296
+ }
297
+ }
208
298
  }
209
299
  }, [client, authProvider]);
210
300
  React.useEffect(function () {
211
- if (client && permissionProvider) {
212
- if (typeof (client === null || client === void 0 ? void 0 : client.setPermissionProvider) === "function") {
213
- client === null || client === void 0 ? void 0 : client.setPermissionProvider(permissionProvider);
301
+ if (!deepCompare(prevPermissionProviderRef.current, permissionProvider)) {
302
+ if (client && permissionProvider) {
303
+ if (typeof (client === null || client === void 0 ? void 0 : client.setPermissionProvider) === "function") {
304
+ client === null || client === void 0 ? void 0 : client.setPermissionProvider(permissionProvider);
305
+ }
306
+ prevPermissionProviderRef.current = permissionProvider;
307
+ }
308
+ else {
309
+ // Only update ref to undefined if client is available (to track removal)
310
+ // If client is not available, keep old ref so we can set provider when client becomes available
311
+ if (client) {
312
+ prevPermissionProviderRef.current = permissionProvider;
313
+ }
214
314
  }
215
315
  }
216
316
  }, [client, permissionProvider]);
@@ -1551,37 +1651,6 @@ var VeltWireframe = function (props) {
1551
1651
  return (React__default["default"].createElement("velt-wireframe", { style: { display: 'none' } }, children));
1552
1652
  };
1553
1653
 
1554
- var validProps = ['veltIf', 'veltClass', 'className', 'variant'];
1555
- var transformWireframeProps = function (props) {
1556
- try {
1557
- var transformedProps_1 = {};
1558
- Object.entries(props).forEach(function (_a) {
1559
- var key = _a[0], value = _a[1];
1560
- if (key === 'children' || key === 'ref' || !validProps.includes(key)) {
1561
- transformedProps_1[key] = value;
1562
- return;
1563
- }
1564
- if (key === 'className') {
1565
- transformedProps_1['class'] = value;
1566
- return;
1567
- }
1568
- // Convert camelCase to dash-case
1569
- var dashKey = key.replace(/[A-Z]/g, function (letter) { return "-".concat(letter.toLowerCase()); });
1570
- transformedProps_1[dashKey] = value;
1571
- // // Handle boolean values - only convert if explicitly true/false
1572
- // if (typeof value === 'boolean') {
1573
- // transformedProps[dashKey] = [true, false].includes(value) ? (value ? 'true' : 'false') : undefined;
1574
- // } else {
1575
- // transformedProps[dashKey] = value;
1576
- // }
1577
- });
1578
- return transformedProps_1;
1579
- }
1580
- catch (error) {
1581
- return props;
1582
- }
1583
- };
1584
-
1585
1654
  var VeltCommentDialogAllComment = function (props) {
1586
1655
  var children = props.children, remainingProps = __rest(props, ["children"]);
1587
1656
  var transformedProps = transformWireframeProps(remainingProps);