@uniformdev/canvas 19.161.2-alpha.1 → 19.162.2-alpha.11

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
@@ -1608,6 +1608,198 @@ function findParameterInNodeTree(data, predicate) {
1608
1608
  return results;
1609
1609
  }
1610
1610
 
1611
+ // src/enhancement/visibility/evaluateVisibilityCriteriaGroup.ts
1612
+ function evaluateVisibilityCriteriaGroup(options) {
1613
+ const { criteriaGroup, simplifyCriteria } = options;
1614
+ const earlyExitResult = criteriaGroup.op === "&" || !criteriaGroup.op ? false : true;
1615
+ let hasIndeterminateClauses = false;
1616
+ for (let index = criteriaGroup.clauses.length - 1; index >= 0; index--) {
1617
+ const clause = criteriaGroup.clauses[index];
1618
+ const criteriaResult = evaluateCriterion(clause, options);
1619
+ if (criteriaResult === null) {
1620
+ hasIndeterminateClauses = true;
1621
+ } else if (criteriaResult === earlyExitResult) {
1622
+ return earlyExitResult;
1623
+ } else if (criteriaResult !== null && simplifyCriteria) {
1624
+ criteriaGroup.clauses.splice(index, 1);
1625
+ }
1626
+ }
1627
+ return hasIndeterminateClauses ? null : !earlyExitResult;
1628
+ }
1629
+ function evaluateCriterion(clause, rootOptions) {
1630
+ if ("clauses" in clause) {
1631
+ return evaluateVisibilityCriteriaGroup({
1632
+ ...rootOptions,
1633
+ criteriaGroup: clause
1634
+ });
1635
+ }
1636
+ const rule = rootOptions.rules[clause.rule];
1637
+ if (rule) {
1638
+ return rule(clause);
1639
+ }
1640
+ return null;
1641
+ }
1642
+
1643
+ // src/enhancement/visibility/types.ts
1644
+ var CANVAS_VIZ_CONTROL_PARAM = "$viz";
1645
+
1646
+ // src/enhancement/visibility/evaluateNodeVisibility.ts
1647
+ function evaluateNodeVisibility({
1648
+ node,
1649
+ ...evaluateGroupOptions
1650
+ }) {
1651
+ var _a;
1652
+ const properties = getPropertiesValue(node);
1653
+ const vizCriteria = (_a = properties == null ? void 0 : properties[CANVAS_VIZ_CONTROL_PARAM]) == null ? void 0 : _a.value;
1654
+ if (vizCriteria == null ? void 0 : vizCriteria.explicitlyHidden) {
1655
+ return false;
1656
+ }
1657
+ if (!(vizCriteria == null ? void 0 : vizCriteria.criteria)) {
1658
+ return true;
1659
+ }
1660
+ const result = evaluateVisibilityCriteriaGroup({
1661
+ ...evaluateGroupOptions,
1662
+ criteriaGroup: vizCriteria.criteria
1663
+ });
1664
+ if (vizCriteria.criteria.clauses.length === 0 && evaluateGroupOptions.simplifyCriteria) {
1665
+ properties == null ? true : delete properties[CANVAS_VIZ_CONTROL_PARAM];
1666
+ }
1667
+ return result;
1668
+ }
1669
+
1670
+ // src/enhancement/visibility/evaluateWalkTreeVisibility.ts
1671
+ function evaluateWalkTreeVisibility({
1672
+ rules,
1673
+ showIndeterminate,
1674
+ context
1675
+ }) {
1676
+ const { type, node, actions } = context;
1677
+ if (type !== "component") {
1678
+ return;
1679
+ }
1680
+ const result = evaluateNodeVisibility({ node, rules, simplifyCriteria: true });
1681
+ if (result === null && !showIndeterminate || result === false) {
1682
+ actions.remove();
1683
+ return false;
1684
+ }
1685
+ return true;
1686
+ }
1687
+
1688
+ // src/enhancement/visibility/rules/evaluateStringMatch.ts
1689
+ var isEvaluator = (criteria, matchValue) => {
1690
+ if (Array.isArray(criteria)) {
1691
+ return criteria.includes(matchValue);
1692
+ }
1693
+ return criteria === matchValue;
1694
+ };
1695
+ var containsEvaluator = (criteria, matchValue) => {
1696
+ if (Array.isArray(criteria)) {
1697
+ return criteria.some((criterion) => matchValue.includes(criterion));
1698
+ }
1699
+ return matchValue.includes(criteria);
1700
+ };
1701
+ var startsWithEvaluator = (criteria, matchValue) => {
1702
+ if (Array.isArray(criteria)) {
1703
+ return criteria.some((criterion) => matchValue.startsWith(criterion));
1704
+ }
1705
+ return matchValue.startsWith(criteria);
1706
+ };
1707
+ var endsWithEvaluator = (criteria, matchValue) => {
1708
+ if (Array.isArray(criteria)) {
1709
+ return criteria.some((criterion) => matchValue.endsWith(criterion));
1710
+ }
1711
+ return matchValue.endsWith(criteria);
1712
+ };
1713
+ var emptyEvaluator = (_, matchValue) => {
1714
+ return matchValue === "";
1715
+ };
1716
+ var stringOperatorEvaluators = {
1717
+ is: isEvaluator,
1718
+ has: containsEvaluator,
1719
+ startswith: startsWithEvaluator,
1720
+ endswith: endsWithEvaluator,
1721
+ empty: emptyEvaluator
1722
+ };
1723
+ function evaluateStringMatch(criteria, matchValue, allow) {
1724
+ const { op, value } = criteria;
1725
+ if (allow && !allow.has(op)) {
1726
+ return null;
1727
+ }
1728
+ let opMatch = op;
1729
+ const negation = op.startsWith("!");
1730
+ if (negation) {
1731
+ opMatch = opMatch.slice(1);
1732
+ }
1733
+ const evaluator = stringOperatorEvaluators[opMatch];
1734
+ if (!evaluator) {
1735
+ return null;
1736
+ }
1737
+ const result = evaluator(value, matchValue);
1738
+ return negation ? !result : result;
1739
+ }
1740
+
1741
+ // src/enhancement/visibility/rules/dynamicInputVisibilityRule.ts
1742
+ var dynamicInputVisibilityOperators = /* @__PURE__ */ new Set([
1743
+ "is",
1744
+ "!is",
1745
+ "has",
1746
+ "!has",
1747
+ "startswith",
1748
+ "!startswith",
1749
+ "endswith",
1750
+ "!endswith",
1751
+ "empty",
1752
+ "!empty"
1753
+ ]);
1754
+ var CANVAS_VIZ_DI_RULE = "$di";
1755
+ function createDynamicInputVisibilityRule(dynamicInputs) {
1756
+ return {
1757
+ [CANVAS_VIZ_DI_RULE]: (criterion) => {
1758
+ const { source } = criterion;
1759
+ const diValue = source ? dynamicInputs[source] : void 0;
1760
+ return evaluateStringMatch(criterion, diValue != null ? diValue : "", dynamicInputVisibilityOperators);
1761
+ }
1762
+ };
1763
+ }
1764
+
1765
+ // src/enhancement/visibility/rules/localeVisibilityRule.ts
1766
+ var localeVisibilityOperators = /* @__PURE__ */ new Set(["is", "!is"]);
1767
+ var CANVAS_VIZ_LOCALE_RULE = "$locale";
1768
+ function createLocaleVisibilityRule(currentLocale) {
1769
+ return {
1770
+ [CANVAS_VIZ_LOCALE_RULE]: (criterion) => {
1771
+ if (!currentLocale) {
1772
+ return false;
1773
+ }
1774
+ return evaluateStringMatch(criterion, currentLocale, localeVisibilityOperators);
1775
+ }
1776
+ };
1777
+ }
1778
+
1779
+ // src/enhancement/visibility/rules/quirksRule.ts
1780
+ var quirksVisibilityOperators = /* @__PURE__ */ new Set([
1781
+ "is",
1782
+ "!is",
1783
+ "has",
1784
+ "!has",
1785
+ "startswith",
1786
+ "!startswith",
1787
+ "endswith",
1788
+ "!endswith",
1789
+ "empty",
1790
+ "!empty"
1791
+ ]);
1792
+ var CANVAS_VIZ_QUIRKS_RULE = "$qk";
1793
+ function createQuirksVisibilityRule(quirks) {
1794
+ return {
1795
+ [CANVAS_VIZ_QUIRKS_RULE]: (criterion) => {
1796
+ const { source } = criterion;
1797
+ const quirkValue = source ? quirks[source] : void 0;
1798
+ return evaluateStringMatch(criterion, quirkValue != null ? quirkValue : "", quirksVisibilityOperators);
1799
+ }
1800
+ };
1801
+ }
1802
+
1611
1803
  // src/enhancement/localize.ts
1612
1804
  function extractLocales({ component }) {
1613
1805
  var _a;
@@ -1626,17 +1818,29 @@ function extractLocales({ component }) {
1626
1818
  function localize(options) {
1627
1819
  const nodes = "nodes" in options ? options.nodes : options.composition;
1628
1820
  const locale = options.locale;
1629
- walkNodeTree(nodes, ({ type, node, actions }) => {
1821
+ const isUsingModernOptions = typeof locale === "string";
1822
+ const vizControlLocaleRule = isUsingModernOptions ? createLocaleVisibilityRule(locale) : {};
1823
+ walkNodeTree(nodes, (context) => {
1824
+ const { type, node, actions } = context;
1630
1825
  if (type !== "component") {
1631
- if (typeof locale === "string") {
1826
+ if (isUsingModernOptions) {
1632
1827
  localizeProperties(node.fields, locale);
1633
1828
  }
1634
1829
  return;
1635
1830
  }
1636
- const shouldRunPropertyLocalization = typeof locale === "string";
1831
+ if (isUsingModernOptions) {
1832
+ const result = evaluateWalkTreeVisibility({
1833
+ context,
1834
+ rules: vizControlLocaleRule,
1835
+ showIndeterminate: true
1836
+ });
1837
+ if (!result) {
1838
+ return;
1839
+ }
1840
+ }
1637
1841
  if (node.type === CANVAS_LOCALIZATION_TYPE) {
1638
1842
  const locales = extractLocales({ component: node });
1639
- const resolvedLocale = typeof locale === "string" ? locale : locale == null ? void 0 : locale({ component: node, locales });
1843
+ const resolvedLocale = isUsingModernOptions ? locale : locale == null ? void 0 : locale({ component: node, locales });
1640
1844
  let replaceComponent;
1641
1845
  if (resolvedLocale) {
1642
1846
  replaceComponent = locales[resolvedLocale];
@@ -1644,7 +1848,7 @@ function localize(options) {
1644
1848
  if (replaceComponent == null ? void 0 : replaceComponent.length) {
1645
1849
  replaceComponent.forEach((component) => {
1646
1850
  removeLocaleProperty(component);
1647
- if (shouldRunPropertyLocalization) {
1851
+ if (isUsingModernOptions) {
1648
1852
  localizeProperties(getPropertiesValue(component), locale);
1649
1853
  }
1650
1854
  });
@@ -1656,7 +1860,7 @@ function localize(options) {
1656
1860
  } else {
1657
1861
  actions.remove();
1658
1862
  }
1659
- } else if (shouldRunPropertyLocalization) {
1863
+ } else if (isUsingModernOptions) {
1660
1864
  localizeProperties(getPropertiesValue(node), locale);
1661
1865
  }
1662
1866
  });
@@ -1950,6 +2154,9 @@ var isRequestComponentSuggestionMessage = (message) => {
1950
2154
  var isSuggestComponentMessage = (message) => {
1951
2155
  return message.type === "suggest-component";
1952
2156
  };
2157
+ var isContextStorageUpdatedMessage = (message) => {
2158
+ return message.type === "context-storage-command-executed";
2159
+ };
1953
2160
  var createCanvasChannel = ({
1954
2161
  listenTo,
1955
2162
  broadcastTo
@@ -2130,6 +2337,13 @@ var createCanvasChannel = ({
2130
2337
  };
2131
2338
  postMessage(message);
2132
2339
  };
2340
+ const contextStorageUpdated = (options) => {
2341
+ const message = {
2342
+ ...options,
2343
+ type: "context-storage-command-executed"
2344
+ };
2345
+ postMessage(message);
2346
+ };
2133
2347
  const messageEventListener = (event) => {
2134
2348
  if (typeof event.data !== "string") {
2135
2349
  return;
@@ -2179,7 +2393,8 @@ var createCanvasChannel = ({
2179
2393
  editorStateUpdated,
2180
2394
  updateComponentReferences,
2181
2395
  requestComponentSuggestion,
2182
- suggestComponent
2396
+ suggestComponent,
2397
+ contextStorageUpdated
2183
2398
  };
2184
2399
  };
2185
2400
 
@@ -2810,6 +3025,10 @@ export {
2810
3025
  CANVAS_TEST_SLOT,
2811
3026
  CANVAS_TEST_TYPE,
2812
3027
  CANVAS_TEST_VARIANT_PARAM,
3028
+ CANVAS_VIZ_CONTROL_PARAM,
3029
+ CANVAS_VIZ_DI_RULE,
3030
+ CANVAS_VIZ_LOCALE_RULE,
3031
+ CANVAS_VIZ_QUIRKS_RULE,
2813
3032
  CanvasClient,
2814
3033
  CanvasClientError,
2815
3034
  CategoryClient,
@@ -2851,11 +3070,16 @@ export {
2851
3070
  convertEntryToPutEntry,
2852
3071
  createBatchEnhancer,
2853
3072
  createCanvasChannel,
3073
+ createDynamicInputVisibilityRule,
2854
3074
  createEventBus,
2855
3075
  createLimitPolicy,
3076
+ createLocaleVisibilityRule,
3077
+ createQuirksVisibilityRule,
2856
3078
  createUniformApiEnhancer,
2857
3079
  createVariableReference,
2858
3080
  enhance,
3081
+ evaluateVisibilityCriteriaGroup,
3082
+ evaluateWalkTreeVisibility,
2859
3083
  extractLocales,
2860
3084
  findParameterInNodeTree,
2861
3085
  flattenValues,
@@ -2877,6 +3101,7 @@ export {
2877
3101
  isAssetParamValueItem,
2878
3102
  isComponentActionMessage,
2879
3103
  isComponentPlaceholderId,
3104
+ isContextStorageUpdatedMessage,
2880
3105
  isDismissPlaceholderMessage,
2881
3106
  isEntryData,
2882
3107
  isMovingComponentMessage,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/canvas",
3
- "version": "19.161.2-alpha.1+d59167950a",
3
+ "version": "19.162.2-alpha.11+5544f3f2ca",
4
4
  "description": "Common functionality and types for Uniform Canvas",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./dist/index.js",
@@ -38,8 +38,8 @@
38
38
  "pusher-js": "8.2.0"
39
39
  },
40
40
  "dependencies": {
41
- "@uniformdev/assets": "19.161.2-alpha.1+d59167950a",
42
- "@uniformdev/context": "19.161.2-alpha.1+d59167950a",
41
+ "@uniformdev/assets": "19.162.2-alpha.11+5544f3f2ca",
42
+ "@uniformdev/context": "19.162.2-alpha.11+5544f3f2ca",
43
43
  "immer": "10.0.4"
44
44
  },
45
45
  "files": [
@@ -48,5 +48,5 @@
48
48
  "publishConfig": {
49
49
  "access": "public"
50
50
  },
51
- "gitHead": "d59167950aa13607d01052f435e2e6b440e8cee6"
51
+ "gitHead": "5544f3f2ca31829767dbe8511c21b1192a811443"
52
52
  }