@uniformdev/canvas 19.2.0 → 19.5.1-alpha.22

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.d.ts CHANGED
@@ -6807,6 +6807,10 @@ type DismissPlaceholderMessage = {
6807
6807
  parentId: string;
6808
6808
  slotName: string;
6809
6809
  };
6810
+ type TriggerCompositionActionMessage = {
6811
+ type: 'trigger-composition-action';
6812
+ action: 'save' | 'publish';
6813
+ };
6810
6814
  type UpdatePreviewSettingsMessage = {
6811
6815
  type: 'update-preview-settings';
6812
6816
  settings: PreviewPanelSettings;
@@ -6816,7 +6820,7 @@ type ReportRenderedCompositionsMessage = {
6816
6820
  compositionIds: string[];
6817
6821
  url: string;
6818
6822
  };
6819
- type ChannelMessage = SelectComponentMessage | ReadyMessage | UpdateCompositionMessage | UpdateCompositionInternalMessage | AddComponentMessage | MoveComponentMessage | DismissPlaceholderMessage | UpdatePreviewSettingsMessage | ReportRenderedCompositionsMessage | UpdateComponentParameterMessage | DismissPlaceholderMessage;
6823
+ type ChannelMessage = SelectComponentMessage | ReadyMessage | UpdateCompositionMessage | UpdateCompositionInternalMessage | AddComponentMessage | MoveComponentMessage | DismissPlaceholderMessage | TriggerCompositionActionMessage | UpdatePreviewSettingsMessage | ReportRenderedCompositionsMessage | UpdateComponentParameterMessage | DismissPlaceholderMessage;
6820
6824
  declare const isSelectComponentMessage: (message: ChannelMessage) => message is SelectComponentMessage;
6821
6825
  declare const isReadyMessage: (message: ChannelMessage) => message is ReadyMessage;
6822
6826
  declare const isUpdateCompositionMessage: (message: ChannelMessage) => message is UpdateCompositionMessage;
@@ -6825,6 +6829,7 @@ declare const isAddComponentMessage: (message: ChannelMessage) => message is Add
6825
6829
  declare const isMovingComponentMessage: (message: ChannelMessage) => message is MoveComponentMessage;
6826
6830
  declare const isUpdateComponentParameterMessage: (message: ChannelMessage) => message is UpdateComponentParameterMessage;
6827
6831
  declare const isDismissPlaceholderMessage: (message: ChannelMessage) => message is DismissPlaceholderMessage;
6832
+ declare const isTriggerCompositionActionMessage: (message: ChannelMessage) => message is TriggerCompositionActionMessage;
6828
6833
  declare const isUpdatePreviewSettingsMessage: (message: ChannelMessage) => message is UpdatePreviewSettingsMessage;
6829
6834
  declare const isReportRenderedCompositionsMessage: (message: ChannelMessage) => message is ReportRenderedCompositionsMessage;
6830
6835
  type MessageHandler = (message: ChannelMessage, originalEvent: MessageEvent) => void;
@@ -6839,6 +6844,7 @@ type Channel = {
6839
6844
  moveComponent: (options: Omit<MoveComponentMessage, 'type'>) => void;
6840
6845
  updateComponentParameter: (options: Omit<UpdateComponentParameterMessage, 'type'>) => void;
6841
6846
  dismissPlaceholder: (options: Omit<DismissPlaceholderMessage, 'type'>) => void;
6847
+ triggerCompositionAction: (options: Omit<TriggerCompositionActionMessage, 'type'>) => void;
6842
6848
  updatePreviewSettings: (options: Omit<UpdatePreviewSettingsMessage, 'type'>) => void;
6843
6849
  reportRenderedCompositions: (options: Omit<ReportRenderedCompositionsMessage, 'type'>) => void;
6844
6850
  };
@@ -6904,6 +6910,51 @@ declare class unstable_RouteClient extends ApiClient<RouteClientOptions> {
6904
6910
  getRoute(options?: Omit<RouteGetParameters, 'projectId'>): Promise<ResolvedRouteGetResponse>;
6905
6911
  }
6906
6912
 
6913
+ type BindVariablesResult<TValue> = {
6914
+ boundCount: number;
6915
+ result: TValue;
6916
+ errors?: string[];
6917
+ };
6918
+ type BindVariablesToObjectOptions<T> = {
6919
+ /** The object to bind variables to. Only strings or objects are bound. */
6920
+ value: T;
6921
+ recursivePath?: string;
6922
+ } & Omit<BindVariablesOptions, 'value'>;
6923
+ /**
6924
+ * Binds composition variables to an object whose string keys may have variable expressions in them.
6925
+ * Binding is recursive.
6926
+ */
6927
+ declare function bindVariablesToObject<T>(options: BindVariablesToObjectOptions<T>): BindVariablesResult<T>;
6928
+
6929
+ type BindVariablesOptions = {
6930
+ /** Current variable values table */
6931
+ variables: DataResourceVariables;
6932
+ /** String value to bind variables to */
6933
+ value: string;
6934
+ /**
6935
+ * Text prefix for any variable binding errors that might be returned
6936
+ * @default "Variable"
6937
+ */
6938
+ errorPrefix?: string;
6939
+ /**
6940
+ * Optionally provide overridden binding behaviour with a function.
6941
+ * Default behaviour:
6942
+ * - If variable is not defined, its expression is replaced by empty string and an error is returned
6943
+ * - If variable is defined, its expression is replaced by its value
6944
+ * @param variableName The variable name referred to in the `value` string. This is the name inside the ${} expression.
6945
+ * @param variables The current variables table.
6946
+ * @param errors Errors array. Push to it to add errors to the result.
6947
+ * @returns New value for the variable reference expression, will replace the whole ${} in the result.
6948
+ */
6949
+ handleBinding?: (variableName: string, variables: DataResourceVariables, errors: string[]) => string;
6950
+ };
6951
+ /**
6952
+ * Binds variables to a string that could have variable values in it.
6953
+ * Variables are referenced in the string as ${variableName}.
6954
+ * Literal variable values are escaped with a backslash, e.g. \${literal}
6955
+ */
6956
+ declare function bindVariables({ variables, value, errorPrefix, handleBinding, }: BindVariablesOptions): BindVariablesResult<string>;
6957
+
6907
6958
  /** Public ID of Canvas personalization component type */
6908
6959
  declare const CANVAS_PERSONALIZE_TYPE = "$personalization";
6909
6960
  /** Public ID of Canvas A/B test component type */
@@ -7118,4 +7169,4 @@ declare function mapSlotToTestVariations(slot: ComponentInstance[] | undefined):
7118
7169
 
7119
7170
  declare const CanvasClientError: typeof ApiClientError;
7120
7171
 
7121
- export { AddComponentMessage, BatchEnhancer, BatchEntry, BatchInvalidationPayload, CANVAS_DRAFT_STATE, CANVAS_ENRICHMENT_TAG_PARAM, CANVAS_INTENT_TAG_PARAM, CANVAS_LOCALE_TAG_PARAM, CANVAS_LOCALIZATION_SLOT, CANVAS_LOCALIZATION_TYPE, CANVAS_PERSONALIZATION_PARAM, CANVAS_PERSONALIZE_SLOT, CANVAS_PERSONALIZE_TYPE, CANVAS_PUBLISHED_STATE, CANVAS_TEST_SLOT, CANVAS_TEST_TYPE, CANVAS_TEST_VARIANT_PARAM, CanvasClient, CanvasClientError, CanvasDefinitions, Channel, ChannelMessage, ChannelSubscription, ChildEnhancerBuilder, ComponentDefinition, ComponentDefinitionDeleteParameters, ComponentDefinitionGetParameters, ComponentDefinitionGetResponse, ComponentDefinitionParameter, ComponentDefinitionPermission, ComponentDefinitionPutParameters, ComponentDefinitionSlot, ComponentDefinitionSlugSettings, ComponentDefinitionVariant, ComponentEnhancer, ComponentEnhancerFunction, ComponentEnhancerOptions, ComponentInstance, ComponentLocationReference, ComponentOverridability, ComponentOverride, ComponentOverrides, ComponentParameter, ComponentParameterContextualEditing, ComponentParameterEnhancer, ComponentParameterEnhancerFunction, ComponentParameterEnhancerOptions, CompositionDataDiagnostic, CompositionDeleteParameters, CompositionDiagnostics, CompositionGetByIdParameters, CompositionGetByNodeIdParameters, CompositionGetByNodePathParameters, CompositionGetBySlugParameters, CompositionGetListResponse, CompositionGetOrderBy, CompositionGetParameters, CompositionGetResponse, CompositionGetValidResponses, CompositionIssue, CompositionPatternIssue, CompositionPutParameters, CompositionRelationshipsClientOptions, CompositionRelationshipsDDefinitionGetResponse, CompositionRelationshipsDefinitionApi, CompositionRelationshipsDefinitionGetParameters, CompositionResolvedGetResponse, CompositionUIStatus, DataElementBindingIssue, DataElementConnectionDefinition, DataResolutionConfigIssue, DataResolutionOption, DataResolutionOptionNegative, DataResolutionOptionPositive, DataResolutionParameters, DataResourceDefinition, DataResourceDefinitions, DataResourceInputIssue, DataResourceIssue, DataResourceVariables, DataSource, DataSourceClient, DataSourceDeleteParameters, DataSourceGetParameters, DataSourceGetResponse, DataSourcePutParameters, DataSourcesGetParameters, DataSourcesGetResponse, DataType, DataTypeClient, DataTypeDeleteParameters, DataTypeGetParameters, DataTypeGetResponse, DataTypePutParameters, DataVariableDefinition, DismissPlaceholderMessage, EDGE_CACHE_DISABLED, EDGE_DEFAULT_CACHE_TTL, EDGE_DEFAULT_L2_CACHE_TTL_IN_HOURS, EDGE_MAX_CACHE_TTL, EDGE_MAX_L2_CACHE_TTL_IN_HOURS, EDGE_MIN_CACHE_TTL, EDGE_MIN_L2_CACHE_TTL_IN_HOURS, EMPTY_COMPOSITION, EnhancerBuilder, EnhancerContext, EnhancerError, EventNames, IN_CONTEXT_EDITOR_COMPONENT_END_ROLE, IN_CONTEXT_EDITOR_COMPONENT_START_ROLE, IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID, IN_CONTEXT_EDITOR_QUERY_STRING_PARAM, IS_RENDERED_BY_UNIFORM_ATTRIBUTE, InvalidationPayload, InvalidationResult, LimitPolicy, MessageHandler, MoveComponentMessage, OverrideIssue, OverrideOptions, PLACEHOLDER_ID, PreviewEventBus, PreviewPanelSettings, ReadyMessage, ReportRenderedCompositionsMessage, ResolvedRouteGetResponse, RootComponentInstance, RouteDynamicInputs, RouteGetParameters, RouteGetResponse, RouteGetResponseComposition, RouteGetResponseEdgehancedComposition, RouteGetResponseNotFound, RouteGetResponseRedirect, SelectComponentMessage, SpecificProjectMap, SubscribeToCompositionOptions, UncachedCanvasClient, UniqueBatchEntries, UnsubscribeCallback, UpdateComponentParameterMessage, UpdateCompositionInternalMessage, UpdateCompositionMessage, UpdatePreviewSettingsMessage, UsageTrackingApi, UsageTrackingGetParameters, UsageTrackingGetResponse, UsageTrackingPostParameters, UsageTrackingPostResponse, WalkComponentTreeActions, compose, createBatchEnhancer, createCanvasChannel, createEventBus, createLimitPolicy, createUniformApiEnhancer, enhance, extractLocales, generateHash, getChannelName, getComponentJsonPointer, getComponentPath, isAddComponentMessage, isDismissPlaceholderMessage, isMovingComponentMessage, isReadyMessage, isReportRenderedCompositionsMessage, isSelectComponentMessage, isSystemComponentDefinition, isUpdateComponentParameterMessage, isUpdateCompositionInternalMessage, isUpdateCompositionMessage, isUpdatePreviewSettingsMessage, localize, mapSlotToPersonalizedVariations, mapSlotToTestVariations, nullLimitPolicy, subscribeToComposition, unstable_CompositionRelationshipClient, unstable_RouteClient, walkComponentTree };
7172
+ export { AddComponentMessage, BatchEnhancer, BatchEntry, BatchInvalidationPayload, BindVariablesOptions, BindVariablesResult, BindVariablesToObjectOptions, CANVAS_DRAFT_STATE, CANVAS_ENRICHMENT_TAG_PARAM, CANVAS_INTENT_TAG_PARAM, CANVAS_LOCALE_TAG_PARAM, CANVAS_LOCALIZATION_SLOT, CANVAS_LOCALIZATION_TYPE, CANVAS_PERSONALIZATION_PARAM, CANVAS_PERSONALIZE_SLOT, CANVAS_PERSONALIZE_TYPE, CANVAS_PUBLISHED_STATE, CANVAS_TEST_SLOT, CANVAS_TEST_TYPE, CANVAS_TEST_VARIANT_PARAM, CanvasClient, CanvasClientError, CanvasDefinitions, Channel, ChannelMessage, ChannelSubscription, ChildEnhancerBuilder, ComponentDefinition, ComponentDefinitionDeleteParameters, ComponentDefinitionGetParameters, ComponentDefinitionGetResponse, ComponentDefinitionParameter, ComponentDefinitionPermission, ComponentDefinitionPutParameters, ComponentDefinitionSlot, ComponentDefinitionSlugSettings, ComponentDefinitionVariant, ComponentEnhancer, ComponentEnhancerFunction, ComponentEnhancerOptions, ComponentInstance, ComponentLocationReference, ComponentOverridability, ComponentOverride, ComponentOverrides, ComponentParameter, ComponentParameterContextualEditing, ComponentParameterEnhancer, ComponentParameterEnhancerFunction, ComponentParameterEnhancerOptions, CompositionDataDiagnostic, CompositionDeleteParameters, CompositionDiagnostics, CompositionGetByIdParameters, CompositionGetByNodeIdParameters, CompositionGetByNodePathParameters, CompositionGetBySlugParameters, CompositionGetListResponse, CompositionGetOrderBy, CompositionGetParameters, CompositionGetResponse, CompositionGetValidResponses, CompositionIssue, CompositionPatternIssue, CompositionPutParameters, CompositionRelationshipsClientOptions, CompositionRelationshipsDDefinitionGetResponse, CompositionRelationshipsDefinitionApi, CompositionRelationshipsDefinitionGetParameters, CompositionResolvedGetResponse, CompositionUIStatus, DataElementBindingIssue, DataElementConnectionDefinition, DataResolutionConfigIssue, DataResolutionOption, DataResolutionOptionNegative, DataResolutionOptionPositive, DataResolutionParameters, DataResourceDefinition, DataResourceDefinitions, DataResourceInputIssue, DataResourceIssue, DataResourceVariables, DataSource, DataSourceClient, DataSourceDeleteParameters, DataSourceGetParameters, DataSourceGetResponse, DataSourcePutParameters, DataSourcesGetParameters, DataSourcesGetResponse, DataType, DataTypeClient, DataTypeDeleteParameters, DataTypeGetParameters, DataTypeGetResponse, DataTypePutParameters, DataVariableDefinition, DismissPlaceholderMessage, EDGE_CACHE_DISABLED, EDGE_DEFAULT_CACHE_TTL, EDGE_DEFAULT_L2_CACHE_TTL_IN_HOURS, EDGE_MAX_CACHE_TTL, EDGE_MAX_L2_CACHE_TTL_IN_HOURS, EDGE_MIN_CACHE_TTL, EDGE_MIN_L2_CACHE_TTL_IN_HOURS, EMPTY_COMPOSITION, EnhancerBuilder, EnhancerContext, EnhancerError, EventNames, IN_CONTEXT_EDITOR_COMPONENT_END_ROLE, IN_CONTEXT_EDITOR_COMPONENT_START_ROLE, IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID, IN_CONTEXT_EDITOR_QUERY_STRING_PARAM, IS_RENDERED_BY_UNIFORM_ATTRIBUTE, InvalidationPayload, InvalidationResult, LimitPolicy, MessageHandler, MoveComponentMessage, OverrideIssue, OverrideOptions, PLACEHOLDER_ID, PreviewEventBus, PreviewPanelSettings, ReadyMessage, ReportRenderedCompositionsMessage, ResolvedRouteGetResponse, RootComponentInstance, RouteDynamicInputs, RouteGetParameters, RouteGetResponse, RouteGetResponseComposition, RouteGetResponseEdgehancedComposition, RouteGetResponseNotFound, RouteGetResponseRedirect, SelectComponentMessage, SpecificProjectMap, SubscribeToCompositionOptions, TriggerCompositionActionMessage, UncachedCanvasClient, UniqueBatchEntries, UnsubscribeCallback, UpdateComponentParameterMessage, UpdateCompositionInternalMessage, UpdateCompositionMessage, UpdatePreviewSettingsMessage, UsageTrackingApi, UsageTrackingGetParameters, UsageTrackingGetResponse, UsageTrackingPostParameters, UsageTrackingPostResponse, WalkComponentTreeActions, bindVariables, bindVariablesToObject, compose, createBatchEnhancer, createCanvasChannel, createEventBus, createLimitPolicy, createUniformApiEnhancer, enhance, extractLocales, generateHash, getChannelName, getComponentJsonPointer, getComponentPath, isAddComponentMessage, isDismissPlaceholderMessage, isMovingComponentMessage, isReadyMessage, isReportRenderedCompositionsMessage, isSelectComponentMessage, isSystemComponentDefinition, isTriggerCompositionActionMessage, isUpdateComponentParameterMessage, isUpdateCompositionInternalMessage, isUpdateCompositionMessage, isUpdatePreviewSettingsMessage, localize, mapSlotToPersonalizedVariations, mapSlotToTestVariations, nullLimitPolicy, subscribeToComposition, unstable_CompositionRelationshipClient, unstable_RouteClient, walkComponentTree };
package/dist/index.esm.js CHANGED
@@ -1307,6 +1307,9 @@ var isUpdateComponentParameterMessage = (message) => {
1307
1307
  var isDismissPlaceholderMessage = (message) => {
1308
1308
  return message.type === "dismiss-placeholder";
1309
1309
  };
1310
+ var isTriggerCompositionActionMessage = (message) => {
1311
+ return message.type === "trigger-composition-action";
1312
+ };
1310
1313
  var isUpdatePreviewSettingsMessage = (message) => {
1311
1314
  return message.type === "update-preview-settings";
1312
1315
  };
@@ -1401,6 +1404,13 @@ var createCanvasChannel = ({
1401
1404
  };
1402
1405
  postMessage(message);
1403
1406
  };
1407
+ const triggerCompositionAction = (options) => {
1408
+ const message = {
1409
+ ...options,
1410
+ type: "trigger-composition-action"
1411
+ };
1412
+ postMessage(message);
1413
+ };
1404
1414
  const updatePreviewSettings = (options) => {
1405
1415
  const message = {
1406
1416
  ...options,
@@ -1452,6 +1462,7 @@ var createCanvasChannel = ({
1452
1462
  moveComponent,
1453
1463
  updateComponentParameter,
1454
1464
  dismissPlaceholder,
1465
+ triggerCompositionAction,
1455
1466
  updatePreviewSettings,
1456
1467
  reportRenderedCompositions
1457
1468
  };
@@ -1555,6 +1566,80 @@ var unstable_RouteClient = class extends ApiClient5 {
1555
1566
  }
1556
1567
  };
1557
1568
 
1569
+ // src/utils/bindVariables.ts
1570
+ function bindVariables({
1571
+ variables,
1572
+ value,
1573
+ errorPrefix = "Variable",
1574
+ handleBinding
1575
+ }) {
1576
+ let boundCount = 0;
1577
+ const errors = [];
1578
+ const defaultHandleBinding = (variableName, variables2, errors2) => {
1579
+ const variableValue = variables2[variableName];
1580
+ if (variableValue === void 0) {
1581
+ errors2.push(`${errorPrefix} "${variableName}" is not defined`);
1582
+ return "";
1583
+ }
1584
+ return variableValue;
1585
+ };
1586
+ const result = value.replace(/(?<!\\)\${([^}]+)}/g, (_match, variableName) => {
1587
+ const variableValue = (handleBinding != null ? handleBinding : defaultHandleBinding)(variableName, variables, errors);
1588
+ boundCount++;
1589
+ return variableValue;
1590
+ });
1591
+ return { result, boundCount, errors: errors.length > 0 ? errors : void 0 };
1592
+ }
1593
+
1594
+ // src/utils/bindVariablesToObject.ts
1595
+ import { produce } from "immer";
1596
+ function bindVariablesToObject(options) {
1597
+ return bindVariablesToObjectRecursive(options);
1598
+ }
1599
+ function bindVariablesToObjectRecursive({
1600
+ value,
1601
+ recursivePath,
1602
+ ...bindVariablesOptions
1603
+ }) {
1604
+ let boundCount = 0;
1605
+ const errors = [];
1606
+ if (typeof value === "string") {
1607
+ return bindVariables({ ...bindVariablesOptions, value });
1608
+ }
1609
+ if (typeof value !== "object" || value === null) {
1610
+ return { boundCount: 0, result: value };
1611
+ }
1612
+ const result = produce(value, (draft) => {
1613
+ Object.entries(draft).forEach(([property, oldValue]) => {
1614
+ const currentObjectPath = recursivePath ? `${recursivePath}.${property}` : property;
1615
+ if (typeof oldValue === "string") {
1616
+ const bindResult = bindVariables({ ...bindVariablesOptions, value: oldValue });
1617
+ if (oldValue !== bindResult.result || bindResult.errors) {
1618
+ boundCount += bindResult.boundCount;
1619
+ draft[property] = bindResult.result;
1620
+ if (bindResult.errors) {
1621
+ errors.push(...bindResult.errors.map((e) => `${currentObjectPath}: ${e}`));
1622
+ }
1623
+ }
1624
+ return;
1625
+ }
1626
+ const childBind = bindVariablesToObject({
1627
+ ...bindVariablesOptions,
1628
+ value: oldValue,
1629
+ recursivePath: currentObjectPath
1630
+ });
1631
+ if (childBind.boundCount || childBind.errors) {
1632
+ boundCount += childBind.boundCount;
1633
+ draft[property] = childBind.result;
1634
+ if (childBind.errors) {
1635
+ errors.push(...childBind.errors.map((e) => `${currentObjectPath}: ${e}`));
1636
+ }
1637
+ }
1638
+ });
1639
+ });
1640
+ return { boundCount, result, errors: errors.length > 0 ? errors : void 0 };
1641
+ }
1642
+
1558
1643
  // src/utils/createApiEnhancer.ts
1559
1644
  var createUniformApiEnhancer = ({ apiUrl }) => {
1560
1645
  return async (message) => {
@@ -1655,6 +1740,8 @@ export {
1655
1740
  PLACEHOLDER_ID,
1656
1741
  UncachedCanvasClient,
1657
1742
  UniqueBatchEntries,
1743
+ bindVariables,
1744
+ bindVariablesToObject,
1658
1745
  compose,
1659
1746
  createBatchEnhancer,
1660
1747
  createCanvasChannel,
@@ -1674,6 +1761,7 @@ export {
1674
1761
  isReportRenderedCompositionsMessage,
1675
1762
  isSelectComponentMessage,
1676
1763
  isSystemComponentDefinition,
1764
+ isTriggerCompositionActionMessage,
1677
1765
  isUpdateComponentParameterMessage,
1678
1766
  isUpdateCompositionInternalMessage,
1679
1767
  isUpdateCompositionMessage,
package/dist/index.js CHANGED
@@ -311,6 +311,8 @@ __export(src_exports, {
311
311
  PLACEHOLDER_ID: () => PLACEHOLDER_ID,
312
312
  UncachedCanvasClient: () => UncachedCanvasClient,
313
313
  UniqueBatchEntries: () => UniqueBatchEntries,
314
+ bindVariables: () => bindVariables,
315
+ bindVariablesToObject: () => bindVariablesToObject,
314
316
  compose: () => compose,
315
317
  createBatchEnhancer: () => createBatchEnhancer,
316
318
  createCanvasChannel: () => createCanvasChannel,
@@ -330,6 +332,7 @@ __export(src_exports, {
330
332
  isReportRenderedCompositionsMessage: () => isReportRenderedCompositionsMessage,
331
333
  isSelectComponentMessage: () => isSelectComponentMessage,
332
334
  isSystemComponentDefinition: () => isSystemComponentDefinition,
335
+ isTriggerCompositionActionMessage: () => isTriggerCompositionActionMessage,
333
336
  isUpdateComponentParameterMessage: () => isUpdateComponentParameterMessage,
334
337
  isUpdateCompositionInternalMessage: () => isUpdateCompositionInternalMessage,
335
338
  isUpdateCompositionMessage: () => isUpdateCompositionMessage,
@@ -1387,6 +1390,9 @@ var isUpdateComponentParameterMessage = (message) => {
1387
1390
  var isDismissPlaceholderMessage = (message) => {
1388
1391
  return message.type === "dismiss-placeholder";
1389
1392
  };
1393
+ var isTriggerCompositionActionMessage = (message) => {
1394
+ return message.type === "trigger-composition-action";
1395
+ };
1390
1396
  var isUpdatePreviewSettingsMessage = (message) => {
1391
1397
  return message.type === "update-preview-settings";
1392
1398
  };
@@ -1481,6 +1487,13 @@ var createCanvasChannel = ({
1481
1487
  };
1482
1488
  postMessage(message);
1483
1489
  };
1490
+ const triggerCompositionAction = (options) => {
1491
+ const message = {
1492
+ ...options,
1493
+ type: "trigger-composition-action"
1494
+ };
1495
+ postMessage(message);
1496
+ };
1484
1497
  const updatePreviewSettings = (options) => {
1485
1498
  const message = {
1486
1499
  ...options,
@@ -1532,6 +1545,7 @@ var createCanvasChannel = ({
1532
1545
  moveComponent,
1533
1546
  updateComponentParameter,
1534
1547
  dismissPlaceholder,
1548
+ triggerCompositionAction,
1535
1549
  updatePreviewSettings,
1536
1550
  reportRenderedCompositions
1537
1551
  };
@@ -1635,6 +1649,80 @@ var unstable_RouteClient = class extends import_api5.ApiClient {
1635
1649
  }
1636
1650
  };
1637
1651
 
1652
+ // src/utils/bindVariables.ts
1653
+ function bindVariables({
1654
+ variables,
1655
+ value,
1656
+ errorPrefix = "Variable",
1657
+ handleBinding
1658
+ }) {
1659
+ let boundCount = 0;
1660
+ const errors = [];
1661
+ const defaultHandleBinding = (variableName, variables2, errors2) => {
1662
+ const variableValue = variables2[variableName];
1663
+ if (variableValue === void 0) {
1664
+ errors2.push(`${errorPrefix} "${variableName}" is not defined`);
1665
+ return "";
1666
+ }
1667
+ return variableValue;
1668
+ };
1669
+ const result = value.replace(/(?<!\\)\${([^}]+)}/g, (_match, variableName) => {
1670
+ const variableValue = (handleBinding != null ? handleBinding : defaultHandleBinding)(variableName, variables, errors);
1671
+ boundCount++;
1672
+ return variableValue;
1673
+ });
1674
+ return { result, boundCount, errors: errors.length > 0 ? errors : void 0 };
1675
+ }
1676
+
1677
+ // src/utils/bindVariablesToObject.ts
1678
+ var import_immer = require("immer");
1679
+ function bindVariablesToObject(options) {
1680
+ return bindVariablesToObjectRecursive(options);
1681
+ }
1682
+ function bindVariablesToObjectRecursive({
1683
+ value,
1684
+ recursivePath,
1685
+ ...bindVariablesOptions
1686
+ }) {
1687
+ let boundCount = 0;
1688
+ const errors = [];
1689
+ if (typeof value === "string") {
1690
+ return bindVariables({ ...bindVariablesOptions, value });
1691
+ }
1692
+ if (typeof value !== "object" || value === null) {
1693
+ return { boundCount: 0, result: value };
1694
+ }
1695
+ const result = (0, import_immer.produce)(value, (draft) => {
1696
+ Object.entries(draft).forEach(([property, oldValue]) => {
1697
+ const currentObjectPath = recursivePath ? `${recursivePath}.${property}` : property;
1698
+ if (typeof oldValue === "string") {
1699
+ const bindResult = bindVariables({ ...bindVariablesOptions, value: oldValue });
1700
+ if (oldValue !== bindResult.result || bindResult.errors) {
1701
+ boundCount += bindResult.boundCount;
1702
+ draft[property] = bindResult.result;
1703
+ if (bindResult.errors) {
1704
+ errors.push(...bindResult.errors.map((e) => `${currentObjectPath}: ${e}`));
1705
+ }
1706
+ }
1707
+ return;
1708
+ }
1709
+ const childBind = bindVariablesToObject({
1710
+ ...bindVariablesOptions,
1711
+ value: oldValue,
1712
+ recursivePath: currentObjectPath
1713
+ });
1714
+ if (childBind.boundCount || childBind.errors) {
1715
+ boundCount += childBind.boundCount;
1716
+ draft[property] = childBind.result;
1717
+ if (childBind.errors) {
1718
+ errors.push(...childBind.errors.map((e) => `${currentObjectPath}: ${e}`));
1719
+ }
1720
+ }
1721
+ });
1722
+ });
1723
+ return { boundCount, result, errors: errors.length > 0 ? errors : void 0 };
1724
+ }
1725
+
1638
1726
  // src/utils/createApiEnhancer.ts
1639
1727
  var createUniformApiEnhancer = ({ apiUrl }) => {
1640
1728
  return async (message) => {
@@ -1736,6 +1824,8 @@ var CanvasClientError = import_api6.ApiClientError;
1736
1824
  PLACEHOLDER_ID,
1737
1825
  UncachedCanvasClient,
1738
1826
  UniqueBatchEntries,
1827
+ bindVariables,
1828
+ bindVariablesToObject,
1739
1829
  compose,
1740
1830
  createBatchEnhancer,
1741
1831
  createCanvasChannel,
@@ -1755,6 +1845,7 @@ var CanvasClientError = import_api6.ApiClientError;
1755
1845
  isReportRenderedCompositionsMessage,
1756
1846
  isSelectComponentMessage,
1757
1847
  isSystemComponentDefinition,
1848
+ isTriggerCompositionActionMessage,
1758
1849
  isUpdateComponentParameterMessage,
1759
1850
  isUpdateCompositionInternalMessage,
1760
1851
  isUpdateCompositionMessage,
package/dist/index.mjs CHANGED
@@ -1307,6 +1307,9 @@ var isUpdateComponentParameterMessage = (message) => {
1307
1307
  var isDismissPlaceholderMessage = (message) => {
1308
1308
  return message.type === "dismiss-placeholder";
1309
1309
  };
1310
+ var isTriggerCompositionActionMessage = (message) => {
1311
+ return message.type === "trigger-composition-action";
1312
+ };
1310
1313
  var isUpdatePreviewSettingsMessage = (message) => {
1311
1314
  return message.type === "update-preview-settings";
1312
1315
  };
@@ -1401,6 +1404,13 @@ var createCanvasChannel = ({
1401
1404
  };
1402
1405
  postMessage(message);
1403
1406
  };
1407
+ const triggerCompositionAction = (options) => {
1408
+ const message = {
1409
+ ...options,
1410
+ type: "trigger-composition-action"
1411
+ };
1412
+ postMessage(message);
1413
+ };
1404
1414
  const updatePreviewSettings = (options) => {
1405
1415
  const message = {
1406
1416
  ...options,
@@ -1452,6 +1462,7 @@ var createCanvasChannel = ({
1452
1462
  moveComponent,
1453
1463
  updateComponentParameter,
1454
1464
  dismissPlaceholder,
1465
+ triggerCompositionAction,
1455
1466
  updatePreviewSettings,
1456
1467
  reportRenderedCompositions
1457
1468
  };
@@ -1555,6 +1566,80 @@ var unstable_RouteClient = class extends ApiClient5 {
1555
1566
  }
1556
1567
  };
1557
1568
 
1569
+ // src/utils/bindVariables.ts
1570
+ function bindVariables({
1571
+ variables,
1572
+ value,
1573
+ errorPrefix = "Variable",
1574
+ handleBinding
1575
+ }) {
1576
+ let boundCount = 0;
1577
+ const errors = [];
1578
+ const defaultHandleBinding = (variableName, variables2, errors2) => {
1579
+ const variableValue = variables2[variableName];
1580
+ if (variableValue === void 0) {
1581
+ errors2.push(`${errorPrefix} "${variableName}" is not defined`);
1582
+ return "";
1583
+ }
1584
+ return variableValue;
1585
+ };
1586
+ const result = value.replace(/(?<!\\)\${([^}]+)}/g, (_match, variableName) => {
1587
+ const variableValue = (handleBinding != null ? handleBinding : defaultHandleBinding)(variableName, variables, errors);
1588
+ boundCount++;
1589
+ return variableValue;
1590
+ });
1591
+ return { result, boundCount, errors: errors.length > 0 ? errors : void 0 };
1592
+ }
1593
+
1594
+ // src/utils/bindVariablesToObject.ts
1595
+ import { produce } from "immer";
1596
+ function bindVariablesToObject(options) {
1597
+ return bindVariablesToObjectRecursive(options);
1598
+ }
1599
+ function bindVariablesToObjectRecursive({
1600
+ value,
1601
+ recursivePath,
1602
+ ...bindVariablesOptions
1603
+ }) {
1604
+ let boundCount = 0;
1605
+ const errors = [];
1606
+ if (typeof value === "string") {
1607
+ return bindVariables({ ...bindVariablesOptions, value });
1608
+ }
1609
+ if (typeof value !== "object" || value === null) {
1610
+ return { boundCount: 0, result: value };
1611
+ }
1612
+ const result = produce(value, (draft) => {
1613
+ Object.entries(draft).forEach(([property, oldValue]) => {
1614
+ const currentObjectPath = recursivePath ? `${recursivePath}.${property}` : property;
1615
+ if (typeof oldValue === "string") {
1616
+ const bindResult = bindVariables({ ...bindVariablesOptions, value: oldValue });
1617
+ if (oldValue !== bindResult.result || bindResult.errors) {
1618
+ boundCount += bindResult.boundCount;
1619
+ draft[property] = bindResult.result;
1620
+ if (bindResult.errors) {
1621
+ errors.push(...bindResult.errors.map((e) => `${currentObjectPath}: ${e}`));
1622
+ }
1623
+ }
1624
+ return;
1625
+ }
1626
+ const childBind = bindVariablesToObject({
1627
+ ...bindVariablesOptions,
1628
+ value: oldValue,
1629
+ recursivePath: currentObjectPath
1630
+ });
1631
+ if (childBind.boundCount || childBind.errors) {
1632
+ boundCount += childBind.boundCount;
1633
+ draft[property] = childBind.result;
1634
+ if (childBind.errors) {
1635
+ errors.push(...childBind.errors.map((e) => `${currentObjectPath}: ${e}`));
1636
+ }
1637
+ }
1638
+ });
1639
+ });
1640
+ return { boundCount, result, errors: errors.length > 0 ? errors : void 0 };
1641
+ }
1642
+
1558
1643
  // src/utils/createApiEnhancer.ts
1559
1644
  var createUniformApiEnhancer = ({ apiUrl }) => {
1560
1645
  return async (message) => {
@@ -1655,6 +1740,8 @@ export {
1655
1740
  PLACEHOLDER_ID,
1656
1741
  UncachedCanvasClient,
1657
1742
  UniqueBatchEntries,
1743
+ bindVariables,
1744
+ bindVariablesToObject,
1658
1745
  compose,
1659
1746
  createBatchEnhancer,
1660
1747
  createCanvasChannel,
@@ -1674,6 +1761,7 @@ export {
1674
1761
  isReportRenderedCompositionsMessage,
1675
1762
  isSelectComponentMessage,
1676
1763
  isSystemComponentDefinition,
1764
+ isTriggerCompositionActionMessage,
1677
1765
  isUpdateComponentParameterMessage,
1678
1766
  isUpdateCompositionInternalMessage,
1679
1767
  isUpdateCompositionMessage,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/canvas",
3
- "version": "19.2.0",
3
+ "version": "19.5.1-alpha.22+5b4a94102",
4
4
  "description": "Common functionality and types for Uniform Canvas",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./dist/index.js",
@@ -47,7 +47,8 @@
47
47
  "pusher-js": "8.0.1"
48
48
  },
49
49
  "dependencies": {
50
- "@uniformdev/context": "19.2.0"
50
+ "@uniformdev/context": "19.5.1-alpha.22+5b4a94102",
51
+ "immer": "9.0.21"
51
52
  },
52
53
  "files": [
53
54
  "/dist"
@@ -55,5 +56,5 @@
55
56
  "publishConfig": {
56
57
  "access": "public"
57
58
  },
58
- "gitHead": "9eb2423cd12a5db527f9f3a9d46b47ac2a0e7eb3"
59
+ "gitHead": "5b4a94102c83a88c9fbf888a24d633e8abf96b76"
59
60
  }