@uniformdev/canvas 19.161.0 → 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.d.mts +183 -207
- package/dist/index.d.ts +183 -207
- package/dist/index.esm.js +232 -7
- package/dist/index.js +242 -7
- package/dist/index.mjs +232 -7
- package/package.json +4 -4
package/dist/index.esm.js
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
|
-
|
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 (
|
1826
|
+
if (isUsingModernOptions) {
|
1632
1827
|
localizeProperties(node.fields, locale);
|
1633
1828
|
}
|
1634
1829
|
return;
|
1635
1830
|
}
|
1636
|
-
|
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 =
|
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 (
|
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 (
|
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/dist/index.js
CHANGED
@@ -305,6 +305,10 @@ __export(src_exports, {
|
|
305
305
|
CANVAS_TEST_SLOT: () => CANVAS_TEST_SLOT,
|
306
306
|
CANVAS_TEST_TYPE: () => CANVAS_TEST_TYPE,
|
307
307
|
CANVAS_TEST_VARIANT_PARAM: () => CANVAS_TEST_VARIANT_PARAM,
|
308
|
+
CANVAS_VIZ_CONTROL_PARAM: () => CANVAS_VIZ_CONTROL_PARAM,
|
309
|
+
CANVAS_VIZ_DI_RULE: () => CANVAS_VIZ_DI_RULE,
|
310
|
+
CANVAS_VIZ_LOCALE_RULE: () => CANVAS_VIZ_LOCALE_RULE,
|
311
|
+
CANVAS_VIZ_QUIRKS_RULE: () => CANVAS_VIZ_QUIRKS_RULE,
|
308
312
|
CanvasClient: () => CanvasClient,
|
309
313
|
CanvasClientError: () => CanvasClientError,
|
310
314
|
CategoryClient: () => CategoryClient,
|
@@ -346,11 +350,16 @@ __export(src_exports, {
|
|
346
350
|
convertEntryToPutEntry: () => convertEntryToPutEntry,
|
347
351
|
createBatchEnhancer: () => createBatchEnhancer,
|
348
352
|
createCanvasChannel: () => createCanvasChannel,
|
353
|
+
createDynamicInputVisibilityRule: () => createDynamicInputVisibilityRule,
|
349
354
|
createEventBus: () => createEventBus,
|
350
355
|
createLimitPolicy: () => createLimitPolicy,
|
356
|
+
createLocaleVisibilityRule: () => createLocaleVisibilityRule,
|
357
|
+
createQuirksVisibilityRule: () => createQuirksVisibilityRule,
|
351
358
|
createUniformApiEnhancer: () => createUniformApiEnhancer,
|
352
359
|
createVariableReference: () => createVariableReference,
|
353
360
|
enhance: () => enhance,
|
361
|
+
evaluateVisibilityCriteriaGroup: () => evaluateVisibilityCriteriaGroup,
|
362
|
+
evaluateWalkTreeVisibility: () => evaluateWalkTreeVisibility,
|
354
363
|
extractLocales: () => extractLocales,
|
355
364
|
findParameterInNodeTree: () => findParameterInNodeTree,
|
356
365
|
flattenValues: () => flattenValues,
|
@@ -372,6 +381,7 @@ __export(src_exports, {
|
|
372
381
|
isAssetParamValueItem: () => isAssetParamValueItem,
|
373
382
|
isComponentActionMessage: () => isComponentActionMessage,
|
374
383
|
isComponentPlaceholderId: () => isComponentPlaceholderId,
|
384
|
+
isContextStorageUpdatedMessage: () => isContextStorageUpdatedMessage,
|
375
385
|
isDismissPlaceholderMessage: () => isDismissPlaceholderMessage,
|
376
386
|
isEntryData: () => isEntryData,
|
377
387
|
isMovingComponentMessage: () => isMovingComponentMessage,
|
@@ -1745,6 +1755,198 @@ function findParameterInNodeTree(data, predicate) {
|
|
1745
1755
|
return results;
|
1746
1756
|
}
|
1747
1757
|
|
1758
|
+
// src/enhancement/visibility/evaluateVisibilityCriteriaGroup.ts
|
1759
|
+
function evaluateVisibilityCriteriaGroup(options) {
|
1760
|
+
const { criteriaGroup, simplifyCriteria } = options;
|
1761
|
+
const earlyExitResult = criteriaGroup.op === "&" || !criteriaGroup.op ? false : true;
|
1762
|
+
let hasIndeterminateClauses = false;
|
1763
|
+
for (let index = criteriaGroup.clauses.length - 1; index >= 0; index--) {
|
1764
|
+
const clause = criteriaGroup.clauses[index];
|
1765
|
+
const criteriaResult = evaluateCriterion(clause, options);
|
1766
|
+
if (criteriaResult === null) {
|
1767
|
+
hasIndeterminateClauses = true;
|
1768
|
+
} else if (criteriaResult === earlyExitResult) {
|
1769
|
+
return earlyExitResult;
|
1770
|
+
} else if (criteriaResult !== null && simplifyCriteria) {
|
1771
|
+
criteriaGroup.clauses.splice(index, 1);
|
1772
|
+
}
|
1773
|
+
}
|
1774
|
+
return hasIndeterminateClauses ? null : !earlyExitResult;
|
1775
|
+
}
|
1776
|
+
function evaluateCriterion(clause, rootOptions) {
|
1777
|
+
if ("clauses" in clause) {
|
1778
|
+
return evaluateVisibilityCriteriaGroup({
|
1779
|
+
...rootOptions,
|
1780
|
+
criteriaGroup: clause
|
1781
|
+
});
|
1782
|
+
}
|
1783
|
+
const rule = rootOptions.rules[clause.rule];
|
1784
|
+
if (rule) {
|
1785
|
+
return rule(clause);
|
1786
|
+
}
|
1787
|
+
return null;
|
1788
|
+
}
|
1789
|
+
|
1790
|
+
// src/enhancement/visibility/types.ts
|
1791
|
+
var CANVAS_VIZ_CONTROL_PARAM = "$viz";
|
1792
|
+
|
1793
|
+
// src/enhancement/visibility/evaluateNodeVisibility.ts
|
1794
|
+
function evaluateNodeVisibility({
|
1795
|
+
node,
|
1796
|
+
...evaluateGroupOptions
|
1797
|
+
}) {
|
1798
|
+
var _a;
|
1799
|
+
const properties = getPropertiesValue(node);
|
1800
|
+
const vizCriteria = (_a = properties == null ? void 0 : properties[CANVAS_VIZ_CONTROL_PARAM]) == null ? void 0 : _a.value;
|
1801
|
+
if (vizCriteria == null ? void 0 : vizCriteria.explicitlyHidden) {
|
1802
|
+
return false;
|
1803
|
+
}
|
1804
|
+
if (!(vizCriteria == null ? void 0 : vizCriteria.criteria)) {
|
1805
|
+
return true;
|
1806
|
+
}
|
1807
|
+
const result = evaluateVisibilityCriteriaGroup({
|
1808
|
+
...evaluateGroupOptions,
|
1809
|
+
criteriaGroup: vizCriteria.criteria
|
1810
|
+
});
|
1811
|
+
if (vizCriteria.criteria.clauses.length === 0 && evaluateGroupOptions.simplifyCriteria) {
|
1812
|
+
properties == null ? true : delete properties[CANVAS_VIZ_CONTROL_PARAM];
|
1813
|
+
}
|
1814
|
+
return result;
|
1815
|
+
}
|
1816
|
+
|
1817
|
+
// src/enhancement/visibility/evaluateWalkTreeVisibility.ts
|
1818
|
+
function evaluateWalkTreeVisibility({
|
1819
|
+
rules,
|
1820
|
+
showIndeterminate,
|
1821
|
+
context
|
1822
|
+
}) {
|
1823
|
+
const { type, node, actions } = context;
|
1824
|
+
if (type !== "component") {
|
1825
|
+
return;
|
1826
|
+
}
|
1827
|
+
const result = evaluateNodeVisibility({ node, rules, simplifyCriteria: true });
|
1828
|
+
if (result === null && !showIndeterminate || result === false) {
|
1829
|
+
actions.remove();
|
1830
|
+
return false;
|
1831
|
+
}
|
1832
|
+
return true;
|
1833
|
+
}
|
1834
|
+
|
1835
|
+
// src/enhancement/visibility/rules/evaluateStringMatch.ts
|
1836
|
+
var isEvaluator = (criteria, matchValue) => {
|
1837
|
+
if (Array.isArray(criteria)) {
|
1838
|
+
return criteria.includes(matchValue);
|
1839
|
+
}
|
1840
|
+
return criteria === matchValue;
|
1841
|
+
};
|
1842
|
+
var containsEvaluator = (criteria, matchValue) => {
|
1843
|
+
if (Array.isArray(criteria)) {
|
1844
|
+
return criteria.some((criterion) => matchValue.includes(criterion));
|
1845
|
+
}
|
1846
|
+
return matchValue.includes(criteria);
|
1847
|
+
};
|
1848
|
+
var startsWithEvaluator = (criteria, matchValue) => {
|
1849
|
+
if (Array.isArray(criteria)) {
|
1850
|
+
return criteria.some((criterion) => matchValue.startsWith(criterion));
|
1851
|
+
}
|
1852
|
+
return matchValue.startsWith(criteria);
|
1853
|
+
};
|
1854
|
+
var endsWithEvaluator = (criteria, matchValue) => {
|
1855
|
+
if (Array.isArray(criteria)) {
|
1856
|
+
return criteria.some((criterion) => matchValue.endsWith(criterion));
|
1857
|
+
}
|
1858
|
+
return matchValue.endsWith(criteria);
|
1859
|
+
};
|
1860
|
+
var emptyEvaluator = (_, matchValue) => {
|
1861
|
+
return matchValue === "";
|
1862
|
+
};
|
1863
|
+
var stringOperatorEvaluators = {
|
1864
|
+
is: isEvaluator,
|
1865
|
+
has: containsEvaluator,
|
1866
|
+
startswith: startsWithEvaluator,
|
1867
|
+
endswith: endsWithEvaluator,
|
1868
|
+
empty: emptyEvaluator
|
1869
|
+
};
|
1870
|
+
function evaluateStringMatch(criteria, matchValue, allow) {
|
1871
|
+
const { op, value } = criteria;
|
1872
|
+
if (allow && !allow.has(op)) {
|
1873
|
+
return null;
|
1874
|
+
}
|
1875
|
+
let opMatch = op;
|
1876
|
+
const negation = op.startsWith("!");
|
1877
|
+
if (negation) {
|
1878
|
+
opMatch = opMatch.slice(1);
|
1879
|
+
}
|
1880
|
+
const evaluator = stringOperatorEvaluators[opMatch];
|
1881
|
+
if (!evaluator) {
|
1882
|
+
return null;
|
1883
|
+
}
|
1884
|
+
const result = evaluator(value, matchValue);
|
1885
|
+
return negation ? !result : result;
|
1886
|
+
}
|
1887
|
+
|
1888
|
+
// src/enhancement/visibility/rules/dynamicInputVisibilityRule.ts
|
1889
|
+
var dynamicInputVisibilityOperators = /* @__PURE__ */ new Set([
|
1890
|
+
"is",
|
1891
|
+
"!is",
|
1892
|
+
"has",
|
1893
|
+
"!has",
|
1894
|
+
"startswith",
|
1895
|
+
"!startswith",
|
1896
|
+
"endswith",
|
1897
|
+
"!endswith",
|
1898
|
+
"empty",
|
1899
|
+
"!empty"
|
1900
|
+
]);
|
1901
|
+
var CANVAS_VIZ_DI_RULE = "$di";
|
1902
|
+
function createDynamicInputVisibilityRule(dynamicInputs) {
|
1903
|
+
return {
|
1904
|
+
[CANVAS_VIZ_DI_RULE]: (criterion) => {
|
1905
|
+
const { source } = criterion;
|
1906
|
+
const diValue = source ? dynamicInputs[source] : void 0;
|
1907
|
+
return evaluateStringMatch(criterion, diValue != null ? diValue : "", dynamicInputVisibilityOperators);
|
1908
|
+
}
|
1909
|
+
};
|
1910
|
+
}
|
1911
|
+
|
1912
|
+
// src/enhancement/visibility/rules/localeVisibilityRule.ts
|
1913
|
+
var localeVisibilityOperators = /* @__PURE__ */ new Set(["is", "!is"]);
|
1914
|
+
var CANVAS_VIZ_LOCALE_RULE = "$locale";
|
1915
|
+
function createLocaleVisibilityRule(currentLocale) {
|
1916
|
+
return {
|
1917
|
+
[CANVAS_VIZ_LOCALE_RULE]: (criterion) => {
|
1918
|
+
if (!currentLocale) {
|
1919
|
+
return false;
|
1920
|
+
}
|
1921
|
+
return evaluateStringMatch(criterion, currentLocale, localeVisibilityOperators);
|
1922
|
+
}
|
1923
|
+
};
|
1924
|
+
}
|
1925
|
+
|
1926
|
+
// src/enhancement/visibility/rules/quirksRule.ts
|
1927
|
+
var quirksVisibilityOperators = /* @__PURE__ */ new Set([
|
1928
|
+
"is",
|
1929
|
+
"!is",
|
1930
|
+
"has",
|
1931
|
+
"!has",
|
1932
|
+
"startswith",
|
1933
|
+
"!startswith",
|
1934
|
+
"endswith",
|
1935
|
+
"!endswith",
|
1936
|
+
"empty",
|
1937
|
+
"!empty"
|
1938
|
+
]);
|
1939
|
+
var CANVAS_VIZ_QUIRKS_RULE = "$qk";
|
1940
|
+
function createQuirksVisibilityRule(quirks) {
|
1941
|
+
return {
|
1942
|
+
[CANVAS_VIZ_QUIRKS_RULE]: (criterion) => {
|
1943
|
+
const { source } = criterion;
|
1944
|
+
const quirkValue = source ? quirks[source] : void 0;
|
1945
|
+
return evaluateStringMatch(criterion, quirkValue != null ? quirkValue : "", quirksVisibilityOperators);
|
1946
|
+
}
|
1947
|
+
};
|
1948
|
+
}
|
1949
|
+
|
1748
1950
|
// src/enhancement/localize.ts
|
1749
1951
|
function extractLocales({ component }) {
|
1750
1952
|
var _a;
|
@@ -1763,17 +1965,29 @@ function extractLocales({ component }) {
|
|
1763
1965
|
function localize(options) {
|
1764
1966
|
const nodes = "nodes" in options ? options.nodes : options.composition;
|
1765
1967
|
const locale = options.locale;
|
1766
|
-
|
1968
|
+
const isUsingModernOptions = typeof locale === "string";
|
1969
|
+
const vizControlLocaleRule = isUsingModernOptions ? createLocaleVisibilityRule(locale) : {};
|
1970
|
+
walkNodeTree(nodes, (context) => {
|
1971
|
+
const { type, node, actions } = context;
|
1767
1972
|
if (type !== "component") {
|
1768
|
-
if (
|
1973
|
+
if (isUsingModernOptions) {
|
1769
1974
|
localizeProperties(node.fields, locale);
|
1770
1975
|
}
|
1771
1976
|
return;
|
1772
1977
|
}
|
1773
|
-
|
1978
|
+
if (isUsingModernOptions) {
|
1979
|
+
const result = evaluateWalkTreeVisibility({
|
1980
|
+
context,
|
1981
|
+
rules: vizControlLocaleRule,
|
1982
|
+
showIndeterminate: true
|
1983
|
+
});
|
1984
|
+
if (!result) {
|
1985
|
+
return;
|
1986
|
+
}
|
1987
|
+
}
|
1774
1988
|
if (node.type === CANVAS_LOCALIZATION_TYPE) {
|
1775
1989
|
const locales = extractLocales({ component: node });
|
1776
|
-
const resolvedLocale =
|
1990
|
+
const resolvedLocale = isUsingModernOptions ? locale : locale == null ? void 0 : locale({ component: node, locales });
|
1777
1991
|
let replaceComponent;
|
1778
1992
|
if (resolvedLocale) {
|
1779
1993
|
replaceComponent = locales[resolvedLocale];
|
@@ -1781,7 +1995,7 @@ function localize(options) {
|
|
1781
1995
|
if (replaceComponent == null ? void 0 : replaceComponent.length) {
|
1782
1996
|
replaceComponent.forEach((component) => {
|
1783
1997
|
removeLocaleProperty(component);
|
1784
|
-
if (
|
1998
|
+
if (isUsingModernOptions) {
|
1785
1999
|
localizeProperties(getPropertiesValue(component), locale);
|
1786
2000
|
}
|
1787
2001
|
});
|
@@ -1793,7 +2007,7 @@ function localize(options) {
|
|
1793
2007
|
} else {
|
1794
2008
|
actions.remove();
|
1795
2009
|
}
|
1796
|
-
} else if (
|
2010
|
+
} else if (isUsingModernOptions) {
|
1797
2011
|
localizeProperties(getPropertiesValue(node), locale);
|
1798
2012
|
}
|
1799
2013
|
});
|
@@ -2087,6 +2301,9 @@ var isRequestComponentSuggestionMessage = (message) => {
|
|
2087
2301
|
var isSuggestComponentMessage = (message) => {
|
2088
2302
|
return message.type === "suggest-component";
|
2089
2303
|
};
|
2304
|
+
var isContextStorageUpdatedMessage = (message) => {
|
2305
|
+
return message.type === "context-storage-command-executed";
|
2306
|
+
};
|
2090
2307
|
var createCanvasChannel = ({
|
2091
2308
|
listenTo,
|
2092
2309
|
broadcastTo
|
@@ -2267,6 +2484,13 @@ var createCanvasChannel = ({
|
|
2267
2484
|
};
|
2268
2485
|
postMessage(message);
|
2269
2486
|
};
|
2487
|
+
const contextStorageUpdated = (options) => {
|
2488
|
+
const message = {
|
2489
|
+
...options,
|
2490
|
+
type: "context-storage-command-executed"
|
2491
|
+
};
|
2492
|
+
postMessage(message);
|
2493
|
+
};
|
2270
2494
|
const messageEventListener = (event) => {
|
2271
2495
|
if (typeof event.data !== "string") {
|
2272
2496
|
return;
|
@@ -2316,7 +2540,8 @@ var createCanvasChannel = ({
|
|
2316
2540
|
editorStateUpdated,
|
2317
2541
|
updateComponentReferences,
|
2318
2542
|
requestComponentSuggestion,
|
2319
|
-
suggestComponent
|
2543
|
+
suggestComponent,
|
2544
|
+
contextStorageUpdated
|
2320
2545
|
};
|
2321
2546
|
};
|
2322
2547
|
|
@@ -2948,6 +3173,10 @@ var CanvasClientError = import_api14.ApiClientError;
|
|
2948
3173
|
CANVAS_TEST_SLOT,
|
2949
3174
|
CANVAS_TEST_TYPE,
|
2950
3175
|
CANVAS_TEST_VARIANT_PARAM,
|
3176
|
+
CANVAS_VIZ_CONTROL_PARAM,
|
3177
|
+
CANVAS_VIZ_DI_RULE,
|
3178
|
+
CANVAS_VIZ_LOCALE_RULE,
|
3179
|
+
CANVAS_VIZ_QUIRKS_RULE,
|
2951
3180
|
CanvasClient,
|
2952
3181
|
CanvasClientError,
|
2953
3182
|
CategoryClient,
|
@@ -2989,11 +3218,16 @@ var CanvasClientError = import_api14.ApiClientError;
|
|
2989
3218
|
convertEntryToPutEntry,
|
2990
3219
|
createBatchEnhancer,
|
2991
3220
|
createCanvasChannel,
|
3221
|
+
createDynamicInputVisibilityRule,
|
2992
3222
|
createEventBus,
|
2993
3223
|
createLimitPolicy,
|
3224
|
+
createLocaleVisibilityRule,
|
3225
|
+
createQuirksVisibilityRule,
|
2994
3226
|
createUniformApiEnhancer,
|
2995
3227
|
createVariableReference,
|
2996
3228
|
enhance,
|
3229
|
+
evaluateVisibilityCriteriaGroup,
|
3230
|
+
evaluateWalkTreeVisibility,
|
2997
3231
|
extractLocales,
|
2998
3232
|
findParameterInNodeTree,
|
2999
3233
|
flattenValues,
|
@@ -3015,6 +3249,7 @@ var CanvasClientError = import_api14.ApiClientError;
|
|
3015
3249
|
isAssetParamValueItem,
|
3016
3250
|
isComponentActionMessage,
|
3017
3251
|
isComponentPlaceholderId,
|
3252
|
+
isContextStorageUpdatedMessage,
|
3018
3253
|
isDismissPlaceholderMessage,
|
3019
3254
|
isEntryData,
|
3020
3255
|
isMovingComponentMessage,
|