@uniformdev/canvas 19.214.0 → 19.214.1-alpha.10

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.esm.js 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/dist/index.js CHANGED
@@ -468,7 +468,6 @@ __export(src_exports, {
468
468
  createCanvasChannel: () => createCanvasChannel,
469
469
  createDynamicInputVisibilityRule: () => createDynamicInputVisibilityRule,
470
470
  createDynamicTokenVisibilityRule: () => createDynamicTokenVisibilityRule,
471
- createEventBus: () => createEventBus,
472
471
  createLimitPolicy: () => createLimitPolicy,
473
472
  createLocaleVisibilityRule: () => createLocaleVisibilityRule,
474
473
  createQuirksVisibilityRule: () => createQuirksVisibilityRule,
@@ -486,7 +485,6 @@ __export(src_exports, {
486
485
  generateComponentPlaceholderId: () => generateComponentPlaceholderId,
487
486
  generateHash: () => generateHash,
488
487
  getBlockValue: () => getBlockValue,
489
- getChannelName: () => getChannelName,
490
488
  getComponentJsonPointer: () => getComponentJsonPointer,
491
489
  getComponentPath: () => getComponentPath,
492
490
  getDataSourceVariantFromRouteGetParams: () => getDataSourceVariantFromRouteGetParams,
@@ -495,7 +493,6 @@ __export(src_exports, {
495
493
  getNounForNode: () => getNounForNode,
496
494
  getParameterAttributes: () => getParameterAttributes,
497
495
  getPropertiesValue: () => getPropertiesValue,
498
- getPropertyValue: () => getPropertyValue,
499
496
  hasReferencedVariables: () => hasReferencedVariables,
500
497
  isAddComponentMessage: () => isAddComponentMessage,
501
498
  isAllowedReferrer: () => isAllowedReferrer,
@@ -532,8 +529,6 @@ __export(src_exports, {
532
529
  nullLimitPolicy: () => nullLimitPolicy,
533
530
  parseComponentPlaceholderId: () => parseComponentPlaceholderId,
534
531
  parseVariableExpression: () => parseVariableExpression,
535
- subscribeToComposition: () => subscribeToComposition,
536
- walkComponentTree: () => walkComponentTree,
537
532
  walkNodeTree: () => walkNodeTree
538
533
  });
539
534
  module.exports = __toCommonJS(src_exports);
@@ -1204,7 +1199,7 @@ function getComponentPath(ancestorsAndSelf) {
1204
1199
  }
1205
1200
  continue;
1206
1201
  }
1207
- const parentSlotIndex = "parentSlotIndexFn" in currentLocation ? currentLocation.parentSlotIndexFn() : currentLocation.parentSlotIndex;
1202
+ const parentSlotIndex = currentLocation.parentSlotIndexFn();
1208
1203
  const { parentSlot } = currentLocation;
1209
1204
  if (parentSlot && parentSlotIndex !== void 0) {
1210
1205
  path.push(`${parentSlot}[${parentSlotIndex}]`);
@@ -1278,9 +1273,6 @@ function isLinkParamValue(value) {
1278
1273
  function getPropertiesValue(entity) {
1279
1274
  return "parameters" in entity && entity.parameters ? entity.parameters : "fields" in entity && entity.fields ? entity.fields : void 0;
1280
1275
  }
1281
- function getPropertyValue(parameter) {
1282
- return parameter ? parameter.value : parameter;
1283
- }
1284
1276
  function getLocalizedPropertyValues(parameter) {
1285
1277
  if (!parameter) {
1286
1278
  return parameter;
@@ -1312,7 +1304,7 @@ function flattenSingleNodeValues(data, options = {}) {
1312
1304
  const properties = getPropertiesValue(data);
1313
1305
  return properties ? Object.fromEntries(
1314
1306
  Object.entries(properties).map(([id, parameter]) => {
1315
- const value = getPropertyValue(parameter);
1307
+ const value = parameter ? parameter.value : parameter;
1316
1308
  if (levels > 0 && Array.isArray(value) && // In the future ASSET_PARAMETER_TYPE will be a nested data type
1317
1309
  (isNestedNodeType(parameter.type) || parameter.type === ASSET_PARAMETER_TYPE)) {
1318
1310
  const nestedOptions = { ...options, levels: levels - 1 };
@@ -1483,9 +1475,6 @@ function walkNodeTree(node, visitor, options) {
1483
1475
  type: "block",
1484
1476
  node: enqueueingComponent,
1485
1477
  fieldName,
1486
- get blockIndex() {
1487
- return blockIndexFn2();
1488
- },
1489
1478
  blockIndexFn: blockIndexFn2
1490
1479
  },
1491
1480
  // slice removes 'self' since we are inserting a peer of self
@@ -1580,9 +1569,6 @@ function walkNodeTree(node, visitor, options) {
1580
1569
  type: "slot",
1581
1570
  node: enqueueingComponent,
1582
1571
  parentSlot,
1583
- get parentSlotIndex() {
1584
- return parentSlotIndexFn2();
1585
- },
1586
1572
  parentSlotIndexFn: parentSlotIndexFn2
1587
1573
  },
1588
1574
  // slice removes 'self' since we are inserting a peer of self
@@ -1634,9 +1620,6 @@ function walkNodeTree(node, visitor, options) {
1634
1620
  type: "slot",
1635
1621
  node: enqueueingComponent,
1636
1622
  parentSlot: slotKey,
1637
- get parentSlotIndex() {
1638
- return parentSlotIndexFn();
1639
- },
1640
1623
  parentSlotIndexFn
1641
1624
  },
1642
1625
  ...currentQueueEntry.ancestorsAndSelf
@@ -1682,9 +1665,6 @@ function walkNodeTree(node, visitor, options) {
1682
1665
  type: "block",
1683
1666
  node: enqueueingBlock,
1684
1667
  fieldName: propKey,
1685
- get blockIndex() {
1686
- return blockIndexFn();
1687
- },
1688
1668
  blockIndexFn
1689
1669
  },
1690
1670
  ...currentQueueEntry.ancestorsAndSelf
@@ -1986,7 +1966,7 @@ function getComponentJsonPointer(ancestorsAndSelf) {
1986
1966
  }
1987
1967
  continue;
1988
1968
  }
1989
- const parentSlotIndex = "parentSlotIndexFn" in currentLocation ? currentLocation.parentSlotIndexFn() : currentLocation.parentSlotIndex;
1969
+ const parentSlotIndex = currentLocation.parentSlotIndexFn();
1990
1970
  const { parentSlot } = currentLocation;
1991
1971
  if (parentSlot && parentSlotIndex !== void 0) {
1992
1972
  path.push(`slots/${parentSlot}/${parentSlotIndex}`);
@@ -2405,7 +2385,7 @@ function extractLocales({ component }) {
2405
2385
  return variations;
2406
2386
  }
2407
2387
  function localize(options) {
2408
- const nodes = "nodes" in options ? options.nodes : options.composition;
2388
+ const nodes = options.nodes;
2409
2389
  const locale = options.locale;
2410
2390
  const isUsingModernOptions = typeof locale === "string";
2411
2391
  const vizControlLocaleRule = isUsingModernOptions ? createLocaleVisibilityRule(locale) : {};
@@ -2429,10 +2409,9 @@ function localize(options) {
2429
2409
  }
2430
2410
  if (node.type === CANVAS_LOCALIZATION_TYPE) {
2431
2411
  const locales = extractLocales({ component: node });
2432
- const resolvedLocale = isUsingModernOptions ? locale : locale == null ? void 0 : locale({ component: node, locales });
2433
2412
  let replaceComponent;
2434
- if (resolvedLocale) {
2435
- replaceComponent = locales[resolvedLocale];
2413
+ if (locale) {
2414
+ replaceComponent = locales[locale];
2436
2415
  }
2437
2416
  if (replaceComponent == null ? void 0 : replaceComponent.length) {
2438
2417
  replaceComponent.forEach((component) => {
@@ -2531,123 +2510,6 @@ var UniqueBatchEntries = class {
2531
2510
  }
2532
2511
  };
2533
2512
 
2534
- // src/enhancement/walkComponentTree.ts
2535
- function walkComponentTree(component, visitor, initialContext) {
2536
- var _a;
2537
- const componentQueue = [
2538
- {
2539
- ancestorsAndSelf: [{ component, parentSlot: void 0, parentSlotIndex: void 0 }],
2540
- context: initialContext
2541
- }
2542
- ];
2543
- const childContexts = /* @__PURE__ */ new Map();
2544
- do {
2545
- const currentQueueEntry = componentQueue.pop();
2546
- if (!currentQueueEntry) continue;
2547
- const currentComponent = currentQueueEntry.ancestorsAndSelf[0];
2548
- let visitDescendants = true;
2549
- let descendantContext = (_a = childContexts.get(currentComponent.component)) != null ? _a : currentQueueEntry.context;
2550
- visitor(
2551
- currentComponent.component,
2552
- currentQueueEntry.ancestorsAndSelf,
2553
- {
2554
- replaceComponent: (replacementComponent) => {
2555
- Object.assign(currentComponent.component, replacementComponent);
2556
- const propertiesToCheck = [
2557
- "parameters",
2558
- "variant",
2559
- "slots",
2560
- "data",
2561
- "_pattern",
2562
- "_patternError"
2563
- ];
2564
- propertiesToCheck.forEach((property) => {
2565
- if (!replacementComponent[property]) {
2566
- delete currentComponent.component[property];
2567
- }
2568
- });
2569
- },
2570
- removeComponent: () => {
2571
- const { parentSlot, parentSlotIndex } = currentQueueEntry.ancestorsAndSelf[0];
2572
- const parentComponent = currentQueueEntry.ancestorsAndSelf[1];
2573
- if (parentSlot && typeof parentSlotIndex !== "undefined") {
2574
- parentComponent.component.slots[parentSlot].splice(parentSlotIndex, 1);
2575
- } else {
2576
- throw new Error("Unable to delete composition.");
2577
- }
2578
- },
2579
- insertAfter: (components) => {
2580
- const componentsToInsert = Array.isArray(components) ? components : [components];
2581
- const { parentSlot, parentSlotIndex } = currentQueueEntry.ancestorsAndSelf[0];
2582
- const parentComponent = currentQueueEntry.ancestorsAndSelf[1];
2583
- if (parentSlot && typeof parentSlotIndex !== "undefined") {
2584
- parentComponent.component.slots[parentSlot].splice(
2585
- parentSlotIndex + 1,
2586
- 0,
2587
- ...componentsToInsert
2588
- );
2589
- componentQueue.unshift(
2590
- ...componentsToInsert.map((enqueueingComponent) => ({
2591
- ancestorsAndSelf: [
2592
- {
2593
- component: enqueueingComponent,
2594
- parentSlot,
2595
- get parentSlotIndex() {
2596
- return parentComponent.component.slots[parentSlot].findIndex(
2597
- (x) => x === enqueueingComponent
2598
- );
2599
- }
2600
- },
2601
- ...currentQueueEntry.ancestorsAndSelf
2602
- ],
2603
- context: descendantContext
2604
- }))
2605
- );
2606
- } else {
2607
- throw new Error("Unable to insert after a component not in a slot.");
2608
- }
2609
- },
2610
- stopProcessingDescendants() {
2611
- visitDescendants = false;
2612
- },
2613
- setDescendantsContext(context) {
2614
- descendantContext = context;
2615
- },
2616
- setChildContext(child, context) {
2617
- childContexts.set(child, context);
2618
- }
2619
- },
2620
- descendantContext
2621
- );
2622
- const slots = currentComponent.component.slots;
2623
- if (visitDescendants && slots) {
2624
- const slotKeys = Object.keys(slots);
2625
- for (let slotIndex = slotKeys.length - 1; slotIndex >= 0; slotIndex--) {
2626
- const slotKey = slotKeys[slotIndex];
2627
- const components = slots[slotKey];
2628
- for (let componentIndex = components.length - 1; componentIndex >= 0; componentIndex--) {
2629
- const enqueueingComponent = components[componentIndex];
2630
- componentQueue.push({
2631
- ancestorsAndSelf: [
2632
- {
2633
- component: enqueueingComponent,
2634
- parentSlot: slotKey,
2635
- get parentSlotIndex() {
2636
- return currentComponent.component.slots[slotKey].findIndex(
2637
- (x) => x === enqueueingComponent
2638
- );
2639
- }
2640
- },
2641
- ...currentQueueEntry.ancestorsAndSelf
2642
- ],
2643
- context: descendantContext
2644
- });
2645
- }
2646
- }
2647
- }
2648
- } while (componentQueue.length > 0);
2649
- }
2650
-
2651
2513
  // src/EntityReleasesClient.ts
2652
2514
  var import_api7 = require("@uniformdev/context/api");
2653
2515
  var releaseContentsUrl = "/api/v1/entity-releases";
@@ -3016,84 +2878,6 @@ var createCanvasChannel = ({
3016
2878
  };
3017
2879
  };
3018
2880
 
3019
- // src/preview/createEventBus.ts
3020
- var PUSHER_SRC = "https://js.pusher.com/7.0.3/pusher.min.js";
3021
- async function loadPusher() {
3022
- if (typeof document === "undefined" || typeof window === "undefined") {
3023
- return;
3024
- }
3025
- if (window.Pusher) {
3026
- return window.Pusher;
3027
- }
3028
- return new Promise((resolve, reject) => {
3029
- const timeout = setTimeout(() => {
3030
- if (window.Pusher) {
3031
- resolve(window.Pusher);
3032
- }
3033
- reject(
3034
- `Unable to load pusher.js; Uniform Canvas live preview disabled. Consider adding <script src="${PUSHER_SRC}"></script> manually.`
3035
- );
3036
- }, 5e3);
3037
- const pusher = document.createElement("script");
3038
- pusher.src = PUSHER_SRC;
3039
- pusher.addEventListener("load", () => {
3040
- clearTimeout(timeout);
3041
- resolve(window.Pusher);
3042
- });
3043
- document.head.appendChild(pusher);
3044
- });
3045
- }
3046
- async function createEventBus() {
3047
- const WindowPusher = await loadPusher();
3048
- if (!WindowPusher) {
3049
- return;
3050
- }
3051
- let bus = window.__UNIFORM_EVENT_BUS__;
3052
- if (!bus) {
3053
- const pusher = new WindowPusher("7b5f5abd160fea549ffe", {
3054
- cluster: "mt1"
3055
- });
3056
- pusher.connect();
3057
- console.log("[canvas] \u{1F525} preview connected");
3058
- bus = window.__UNIFORM_EVENT_BUS__ = {
3059
- subscribe: (channel) => {
3060
- const channelObj = pusher.subscribe(channel);
3061
- return {
3062
- unsubscribe: () => pusher.unsubscribe(channel),
3063
- addEventHandler: (eventName, handler) => {
3064
- channelObj.bind(eventName, handler);
3065
- return () => channelObj.unbind(eventName, handler);
3066
- }
3067
- };
3068
- }
3069
- };
3070
- }
3071
- return bus;
3072
- }
3073
-
3074
- // src/preview/getChannelName.ts
3075
- function getChannelName(projectId, compositionId, state) {
3076
- return `${projectId}.${compositionId}@${state}`;
3077
- }
3078
-
3079
- // src/preview/subscribeToComposition.ts
3080
- function subscribeToComposition({
3081
- projectId,
3082
- compositionId,
3083
- compositionState = 0,
3084
- eventBus: { subscribe },
3085
- callback,
3086
- event = "updated"
3087
- }) {
3088
- const channelName = getChannelName(projectId, compositionId, compositionState);
3089
- const channel = subscribe(channelName);
3090
- const off = channel.addEventHandler(event, callback);
3091
- return () => {
3092
- off();
3093
- channel.unsubscribe();
3094
- };
3095
- }
3096
-
3097
2881
  // src/PreviewClient.ts
3098
2882
  var import_api9 = require("@uniformdev/context/api");
3099
2883
  var previewUrlsUrl = "/api/v1/preview-urls";
@@ -3716,7 +3500,6 @@ var CanvasClientError = import_api16.ApiClientError;
3716
3500
  createCanvasChannel,
3717
3501
  createDynamicInputVisibilityRule,
3718
3502
  createDynamicTokenVisibilityRule,
3719
- createEventBus,
3720
3503
  createLimitPolicy,
3721
3504
  createLocaleVisibilityRule,
3722
3505
  createQuirksVisibilityRule,
@@ -3734,7 +3517,6 @@ var CanvasClientError = import_api16.ApiClientError;
3734
3517
  generateComponentPlaceholderId,
3735
3518
  generateHash,
3736
3519
  getBlockValue,
3737
- getChannelName,
3738
3520
  getComponentJsonPointer,
3739
3521
  getComponentPath,
3740
3522
  getDataSourceVariantFromRouteGetParams,
@@ -3743,7 +3525,6 @@ var CanvasClientError = import_api16.ApiClientError;
3743
3525
  getNounForNode,
3744
3526
  getParameterAttributes,
3745
3527
  getPropertiesValue,
3746
- getPropertyValue,
3747
3528
  hasReferencedVariables,
3748
3529
  isAddComponentMessage,
3749
3530
  isAllowedReferrer,
@@ -3780,7 +3561,5 @@ var CanvasClientError = import_api16.ApiClientError;
3780
3561
  nullLimitPolicy,
3781
3562
  parseComponentPlaceholderId,
3782
3563
  parseVariableExpression,
3783
- subscribeToComposition,
3784
- walkComponentTree,
3785
3564
  walkNodeTree
3786
3565
  });