@uniformdev/canvas 19.214.0 → 19.214.1-alpha.17

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/dist/index.mjs CHANGED
@@ -1045,7 +1045,7 @@ function getComponentPath(ancestorsAndSelf) {
1045
1045
  }
1046
1046
  continue;
1047
1047
  }
1048
- const parentSlotIndex = "parentSlotIndexFn" in currentLocation ? currentLocation.parentSlotIndexFn() : currentLocation.parentSlotIndex;
1048
+ const parentSlotIndex = currentLocation.parentSlotIndexFn();
1049
1049
  const { parentSlot } = currentLocation;
1050
1050
  if (parentSlot && parentSlotIndex !== void 0) {
1051
1051
  path.push(`${parentSlot}[${parentSlotIndex}]`);
@@ -1119,9 +1119,6 @@ function isLinkParamValue(value) {
1119
1119
  function getPropertiesValue(entity) {
1120
1120
  return "parameters" in entity && entity.parameters ? entity.parameters : "fields" in entity && entity.fields ? entity.fields : void 0;
1121
1121
  }
1122
- function getPropertyValue(parameter) {
1123
- return parameter ? parameter.value : parameter;
1124
- }
1125
1122
  function getLocalizedPropertyValues(parameter) {
1126
1123
  if (!parameter) {
1127
1124
  return parameter;
@@ -1153,7 +1150,7 @@ function flattenSingleNodeValues(data, options = {}) {
1153
1150
  const properties = getPropertiesValue(data);
1154
1151
  return properties ? Object.fromEntries(
1155
1152
  Object.entries(properties).map(([id, parameter]) => {
1156
- const value = getPropertyValue(parameter);
1153
+ const value = parameter ? parameter.value : parameter;
1157
1154
  if (levels > 0 && Array.isArray(value) && // In the future ASSET_PARAMETER_TYPE will be a nested data type
1158
1155
  (isNestedNodeType(parameter.type) || parameter.type === ASSET_PARAMETER_TYPE)) {
1159
1156
  const nestedOptions = { ...options, levels: levels - 1 };
@@ -1324,9 +1321,6 @@ function walkNodeTree(node, visitor, options) {
1324
1321
  type: "block",
1325
1322
  node: enqueueingComponent,
1326
1323
  fieldName,
1327
- get blockIndex() {
1328
- return blockIndexFn2();
1329
- },
1330
1324
  blockIndexFn: blockIndexFn2
1331
1325
  },
1332
1326
  // slice removes 'self' since we are inserting a peer of self
@@ -1421,9 +1415,6 @@ function walkNodeTree(node, visitor, options) {
1421
1415
  type: "slot",
1422
1416
  node: enqueueingComponent,
1423
1417
  parentSlot,
1424
- get parentSlotIndex() {
1425
- return parentSlotIndexFn2();
1426
- },
1427
1418
  parentSlotIndexFn: parentSlotIndexFn2
1428
1419
  },
1429
1420
  // slice removes 'self' since we are inserting a peer of self
@@ -1475,9 +1466,6 @@ function walkNodeTree(node, visitor, options) {
1475
1466
  type: "slot",
1476
1467
  node: enqueueingComponent,
1477
1468
  parentSlot: slotKey,
1478
- get parentSlotIndex() {
1479
- return parentSlotIndexFn();
1480
- },
1481
1469
  parentSlotIndexFn
1482
1470
  },
1483
1471
  ...currentQueueEntry.ancestorsAndSelf
@@ -1523,9 +1511,6 @@ function walkNodeTree(node, visitor, options) {
1523
1511
  type: "block",
1524
1512
  node: enqueueingBlock,
1525
1513
  fieldName: propKey,
1526
- get blockIndex() {
1527
- return blockIndexFn();
1528
- },
1529
1514
  blockIndexFn
1530
1515
  },
1531
1516
  ...currentQueueEntry.ancestorsAndSelf
@@ -1827,7 +1812,7 @@ function getComponentJsonPointer(ancestorsAndSelf) {
1827
1812
  }
1828
1813
  continue;
1829
1814
  }
1830
- const parentSlotIndex = "parentSlotIndexFn" in currentLocation ? currentLocation.parentSlotIndexFn() : currentLocation.parentSlotIndex;
1815
+ const parentSlotIndex = currentLocation.parentSlotIndexFn();
1831
1816
  const { parentSlot } = currentLocation;
1832
1817
  if (parentSlot && parentSlotIndex !== void 0) {
1833
1818
  path.push(`slots/${parentSlot}/${parentSlotIndex}`);
@@ -2246,7 +2231,7 @@ function extractLocales({ component }) {
2246
2231
  return variations;
2247
2232
  }
2248
2233
  function localize(options) {
2249
- const nodes = "nodes" in options ? options.nodes : options.composition;
2234
+ const nodes = options.nodes;
2250
2235
  const locale = options.locale;
2251
2236
  const isUsingModernOptions = typeof locale === "string";
2252
2237
  const vizControlLocaleRule = isUsingModernOptions ? createLocaleVisibilityRule(locale) : {};
@@ -2270,10 +2255,9 @@ function localize(options) {
2270
2255
  }
2271
2256
  if (node.type === CANVAS_LOCALIZATION_TYPE) {
2272
2257
  const locales = extractLocales({ component: node });
2273
- const resolvedLocale = isUsingModernOptions ? locale : locale == null ? void 0 : locale({ component: node, locales });
2274
2258
  let replaceComponent;
2275
- if (resolvedLocale) {
2276
- replaceComponent = locales[resolvedLocale];
2259
+ if (locale) {
2260
+ replaceComponent = locales[locale];
2277
2261
  }
2278
2262
  if (replaceComponent == null ? void 0 : replaceComponent.length) {
2279
2263
  replaceComponent.forEach((component) => {
@@ -2372,123 +2356,6 @@ var UniqueBatchEntries = class {
2372
2356
  }
2373
2357
  };
2374
2358
 
2375
- // src/enhancement/walkComponentTree.ts
2376
- function walkComponentTree(component, visitor, initialContext) {
2377
- var _a;
2378
- const componentQueue = [
2379
- {
2380
- ancestorsAndSelf: [{ component, parentSlot: void 0, parentSlotIndex: void 0 }],
2381
- context: initialContext
2382
- }
2383
- ];
2384
- const childContexts = /* @__PURE__ */ new Map();
2385
- do {
2386
- const currentQueueEntry = componentQueue.pop();
2387
- if (!currentQueueEntry) continue;
2388
- const currentComponent = currentQueueEntry.ancestorsAndSelf[0];
2389
- let visitDescendants = true;
2390
- let descendantContext = (_a = childContexts.get(currentComponent.component)) != null ? _a : currentQueueEntry.context;
2391
- visitor(
2392
- currentComponent.component,
2393
- currentQueueEntry.ancestorsAndSelf,
2394
- {
2395
- replaceComponent: (replacementComponent) => {
2396
- Object.assign(currentComponent.component, replacementComponent);
2397
- const propertiesToCheck = [
2398
- "parameters",
2399
- "variant",
2400
- "slots",
2401
- "data",
2402
- "_pattern",
2403
- "_patternError"
2404
- ];
2405
- propertiesToCheck.forEach((property) => {
2406
- if (!replacementComponent[property]) {
2407
- delete currentComponent.component[property];
2408
- }
2409
- });
2410
- },
2411
- removeComponent: () => {
2412
- const { parentSlot, parentSlotIndex } = currentQueueEntry.ancestorsAndSelf[0];
2413
- const parentComponent = currentQueueEntry.ancestorsAndSelf[1];
2414
- if (parentSlot && typeof parentSlotIndex !== "undefined") {
2415
- parentComponent.component.slots[parentSlot].splice(parentSlotIndex, 1);
2416
- } else {
2417
- throw new Error("Unable to delete composition.");
2418
- }
2419
- },
2420
- insertAfter: (components) => {
2421
- const componentsToInsert = Array.isArray(components) ? components : [components];
2422
- const { parentSlot, parentSlotIndex } = currentQueueEntry.ancestorsAndSelf[0];
2423
- const parentComponent = currentQueueEntry.ancestorsAndSelf[1];
2424
- if (parentSlot && typeof parentSlotIndex !== "undefined") {
2425
- parentComponent.component.slots[parentSlot].splice(
2426
- parentSlotIndex + 1,
2427
- 0,
2428
- ...componentsToInsert
2429
- );
2430
- componentQueue.unshift(
2431
- ...componentsToInsert.map((enqueueingComponent) => ({
2432
- ancestorsAndSelf: [
2433
- {
2434
- component: enqueueingComponent,
2435
- parentSlot,
2436
- get parentSlotIndex() {
2437
- return parentComponent.component.slots[parentSlot].findIndex(
2438
- (x) => x === enqueueingComponent
2439
- );
2440
- }
2441
- },
2442
- ...currentQueueEntry.ancestorsAndSelf
2443
- ],
2444
- context: descendantContext
2445
- }))
2446
- );
2447
- } else {
2448
- throw new Error("Unable to insert after a component not in a slot.");
2449
- }
2450
- },
2451
- stopProcessingDescendants() {
2452
- visitDescendants = false;
2453
- },
2454
- setDescendantsContext(context) {
2455
- descendantContext = context;
2456
- },
2457
- setChildContext(child, context) {
2458
- childContexts.set(child, context);
2459
- }
2460
- },
2461
- descendantContext
2462
- );
2463
- const slots = currentComponent.component.slots;
2464
- if (visitDescendants && slots) {
2465
- const slotKeys = Object.keys(slots);
2466
- for (let slotIndex = slotKeys.length - 1; slotIndex >= 0; slotIndex--) {
2467
- const slotKey = slotKeys[slotIndex];
2468
- const components = slots[slotKey];
2469
- for (let componentIndex = components.length - 1; componentIndex >= 0; componentIndex--) {
2470
- const enqueueingComponent = components[componentIndex];
2471
- componentQueue.push({
2472
- ancestorsAndSelf: [
2473
- {
2474
- component: enqueueingComponent,
2475
- parentSlot: slotKey,
2476
- get parentSlotIndex() {
2477
- return currentComponent.component.slots[slotKey].findIndex(
2478
- (x) => x === enqueueingComponent
2479
- );
2480
- }
2481
- },
2482
- ...currentQueueEntry.ancestorsAndSelf
2483
- ],
2484
- context: descendantContext
2485
- });
2486
- }
2487
- }
2488
- }
2489
- } while (componentQueue.length > 0);
2490
- }
2491
-
2492
2359
  // src/EntityReleasesClient.ts
2493
2360
  import { ApiClient as ApiClient6 } from "@uniformdev/context/api";
2494
2361
  var releaseContentsUrl = "/api/v1/entity-releases";
@@ -2857,84 +2724,6 @@ var createCanvasChannel = ({
2857
2724
  };
2858
2725
  };
2859
2726
 
2860
- // src/preview/createEventBus.ts
2861
- var PUSHER_SRC = "https://js.pusher.com/7.0.3/pusher.min.js";
2862
- async function loadPusher() {
2863
- if (typeof document === "undefined" || typeof window === "undefined") {
2864
- return;
2865
- }
2866
- if (window.Pusher) {
2867
- return window.Pusher;
2868
- }
2869
- return new Promise((resolve, reject) => {
2870
- const timeout = setTimeout(() => {
2871
- if (window.Pusher) {
2872
- resolve(window.Pusher);
2873
- }
2874
- reject(
2875
- `Unable to load pusher.js; Uniform Canvas live preview disabled. Consider adding <script src="${PUSHER_SRC}"></script> manually.`
2876
- );
2877
- }, 5e3);
2878
- const pusher = document.createElement("script");
2879
- pusher.src = PUSHER_SRC;
2880
- pusher.addEventListener("load", () => {
2881
- clearTimeout(timeout);
2882
- resolve(window.Pusher);
2883
- });
2884
- document.head.appendChild(pusher);
2885
- });
2886
- }
2887
- async function createEventBus() {
2888
- const WindowPusher = await loadPusher();
2889
- if (!WindowPusher) {
2890
- return;
2891
- }
2892
- let bus = window.__UNIFORM_EVENT_BUS__;
2893
- if (!bus) {
2894
- const pusher = new WindowPusher("7b5f5abd160fea549ffe", {
2895
- cluster: "mt1"
2896
- });
2897
- pusher.connect();
2898
- console.log("[canvas] \u{1F525} preview connected");
2899
- bus = window.__UNIFORM_EVENT_BUS__ = {
2900
- subscribe: (channel) => {
2901
- const channelObj = pusher.subscribe(channel);
2902
- return {
2903
- unsubscribe: () => pusher.unsubscribe(channel),
2904
- addEventHandler: (eventName, handler) => {
2905
- channelObj.bind(eventName, handler);
2906
- return () => channelObj.unbind(eventName, handler);
2907
- }
2908
- };
2909
- }
2910
- };
2911
- }
2912
- return bus;
2913
- }
2914
-
2915
- // src/preview/getChannelName.ts
2916
- function getChannelName(projectId, compositionId, state) {
2917
- return `${projectId}.${compositionId}@${state}`;
2918
- }
2919
-
2920
- // src/preview/subscribeToComposition.ts
2921
- function subscribeToComposition({
2922
- projectId,
2923
- compositionId,
2924
- compositionState = 0,
2925
- eventBus: { subscribe },
2926
- callback,
2927
- event = "updated"
2928
- }) {
2929
- const channelName = getChannelName(projectId, compositionId, compositionState);
2930
- const channel = subscribe(channelName);
2931
- const off = channel.addEventHandler(event, callback);
2932
- return () => {
2933
- off();
2934
- channel.unsubscribe();
2935
- };
2936
- }
2937
-
2938
2727
  // src/PreviewClient.ts
2939
2728
  import { ApiClient as ApiClient8 } from "@uniformdev/context/api";
2940
2729
  var previewUrlsUrl = "/api/v1/preview-urls";
@@ -3556,7 +3345,6 @@ export {
3556
3345
  createCanvasChannel,
3557
3346
  createDynamicInputVisibilityRule,
3558
3347
  createDynamicTokenVisibilityRule,
3559
- createEventBus,
3560
3348
  createLimitPolicy,
3561
3349
  createLocaleVisibilityRule,
3562
3350
  createQuirksVisibilityRule,
@@ -3574,7 +3362,6 @@ export {
3574
3362
  generateComponentPlaceholderId,
3575
3363
  generateHash,
3576
3364
  getBlockValue,
3577
- getChannelName,
3578
3365
  getComponentJsonPointer,
3579
3366
  getComponentPath,
3580
3367
  getDataSourceVariantFromRouteGetParams,
@@ -3583,7 +3370,6 @@ export {
3583
3370
  getNounForNode,
3584
3371
  getParameterAttributes,
3585
3372
  getPropertiesValue,
3586
- getPropertyValue,
3587
3373
  hasReferencedVariables,
3588
3374
  isAddComponentMessage,
3589
3375
  isAllowedReferrer,
@@ -3620,7 +3406,5 @@ export {
3620
3406
  nullLimitPolicy,
3621
3407
  parseComponentPlaceholderId,
3622
3408
  parseVariableExpression,
3623
- subscribeToComposition,
3624
- walkComponentTree,
3625
3409
  walkNodeTree
3626
3410
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/canvas",
3
- "version": "19.214.0",
3
+ "version": "19.214.1-alpha.17+15e689c12c",
4
4
  "description": "Common functionality and types for Uniform Canvas",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./dist/index.js",
@@ -35,13 +35,12 @@
35
35
  "lexical": "0.17.1",
36
36
  "p-limit": "3.1.0",
37
37
  "p-retry": "5.1.2",
38
- "p-throttle": "5.0.0",
39
- "pusher-js": "8.2.0"
38
+ "p-throttle": "5.0.0"
40
39
  },
41
40
  "dependencies": {
42
- "@uniformdev/assets": "19.214.0",
43
- "@uniformdev/context": "19.214.0",
44
- "@uniformdev/richtext": "19.214.0",
41
+ "@uniformdev/assets": "19.214.1-alpha.17+15e689c12c",
42
+ "@uniformdev/context": "19.214.1-alpha.17+15e689c12c",
43
+ "@uniformdev/richtext": "19.214.1-alpha.17+15e689c12c",
45
44
  "immer": "10.1.1"
46
45
  },
47
46
  "files": [
@@ -50,5 +49,5 @@
50
49
  "publishConfig": {
51
50
  "access": "public"
52
51
  },
53
- "gitHead": "057019805f3d07ac560a53b0a621268a9c3c3518"
52
+ "gitHead": "15e689c12ce848ce17d170f9be8c6f3d2c29ffe1"
54
53
  }