@uniformdev/canvas 19.35.3-alpha.82 → 19.36.0
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 +47 -76
- package/dist/index.d.ts +47 -76
- package/dist/index.esm.js +76 -178
- package/dist/index.js +76 -180
- package/dist/index.mjs +76 -178
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
@@ -1642,6 +1642,80 @@ var RouteClient = class extends ApiClient6 {
|
|
1642
1642
|
}
|
1643
1643
|
};
|
1644
1644
|
|
1645
|
+
// src/utils/bindVariables.ts
|
1646
|
+
function bindVariables({
|
1647
|
+
variables,
|
1648
|
+
value,
|
1649
|
+
errorPrefix = "Variable",
|
1650
|
+
handleBinding
|
1651
|
+
}) {
|
1652
|
+
let boundCount = 0;
|
1653
|
+
const errors = [];
|
1654
|
+
const defaultHandleBinding = (variableName, variables2, errors2) => {
|
1655
|
+
const variableValue = variables2[variableName];
|
1656
|
+
if (variableValue === void 0) {
|
1657
|
+
errors2.push(`${errorPrefix} "${variableName}" is not defined`);
|
1658
|
+
return "";
|
1659
|
+
}
|
1660
|
+
return variableValue;
|
1661
|
+
};
|
1662
|
+
const result = value.replace(/(?<!\\)\${([^}]+)}/g, (_match, variableName) => {
|
1663
|
+
const variableValue = (handleBinding != null ? handleBinding : defaultHandleBinding)(variableName, variables, errors);
|
1664
|
+
boundCount++;
|
1665
|
+
return variableValue;
|
1666
|
+
});
|
1667
|
+
return { result, boundCount, errors: errors.length > 0 ? errors : void 0 };
|
1668
|
+
}
|
1669
|
+
|
1670
|
+
// src/utils/bindVariablesToObject.ts
|
1671
|
+
import { produce } from "immer";
|
1672
|
+
function bindVariablesToObject(options) {
|
1673
|
+
return bindVariablesToObjectRecursive(options);
|
1674
|
+
}
|
1675
|
+
function bindVariablesToObjectRecursive({
|
1676
|
+
value,
|
1677
|
+
recursivePath,
|
1678
|
+
...bindVariablesOptions
|
1679
|
+
}) {
|
1680
|
+
let boundCount = 0;
|
1681
|
+
const errors = [];
|
1682
|
+
if (typeof value === "string") {
|
1683
|
+
return bindVariables({ ...bindVariablesOptions, value });
|
1684
|
+
}
|
1685
|
+
if (typeof value !== "object" || value === null) {
|
1686
|
+
return { boundCount: 0, result: value };
|
1687
|
+
}
|
1688
|
+
const result = produce(value, (draft) => {
|
1689
|
+
Object.entries(draft).forEach(([property, oldValue]) => {
|
1690
|
+
const currentObjectPath = recursivePath ? `${recursivePath}.${property}` : property;
|
1691
|
+
if (typeof oldValue === "string") {
|
1692
|
+
const bindResult = bindVariables({ ...bindVariablesOptions, value: oldValue });
|
1693
|
+
if (oldValue !== bindResult.result || bindResult.errors) {
|
1694
|
+
boundCount += bindResult.boundCount;
|
1695
|
+
draft[property] = bindResult.result;
|
1696
|
+
if (bindResult.errors) {
|
1697
|
+
errors.push(...bindResult.errors.map((e) => `${currentObjectPath}: ${e}`));
|
1698
|
+
}
|
1699
|
+
}
|
1700
|
+
return;
|
1701
|
+
}
|
1702
|
+
const childBind = bindVariablesToObjectRecursive({
|
1703
|
+
...bindVariablesOptions,
|
1704
|
+
value: oldValue,
|
1705
|
+
recursivePath: currentObjectPath
|
1706
|
+
});
|
1707
|
+
if (childBind.boundCount || childBind.errors) {
|
1708
|
+
boundCount += childBind.boundCount;
|
1709
|
+
draft[property] = childBind.result;
|
1710
|
+
if (childBind.errors) {
|
1711
|
+
errors.push(...childBind.errors.map((e) => `${currentObjectPath}: ${e}`));
|
1712
|
+
}
|
1713
|
+
}
|
1714
|
+
});
|
1715
|
+
});
|
1716
|
+
return { boundCount, result, errors: errors.length > 0 ? errors : void 0 };
|
1717
|
+
}
|
1718
|
+
|
1645
1719
|
// src/utils/createApiEnhancer.ts
|
1646
1720
|
var createUniformApiEnhancer = ({ apiUrl }) => {
|
1647
1721
|
return async (message) => {
|
@@ -1689,8 +1763,8 @@ var getParameterAttributes = ({
|
|
1689
1763
|
[ATTRIBUTE_PARAMETER_VALUE]: String(value != null ? value : ""),
|
1690
1764
|
[ATTRIBUTE_PARAMETER_TYPE]: type,
|
1691
1765
|
[ATTRIBUTE_PLACEHOLDER]: placeholder,
|
1692
|
-
[ATTRIBUTE_MULTILINE]:
|
1693
|
-
contentEditable:
|
1766
|
+
[ATTRIBUTE_MULTILINE]: isMultiline,
|
1767
|
+
contentEditable: isEditable
|
1694
1768
|
};
|
1695
1769
|
};
|
1696
1770
|
|
@@ -1731,180 +1805,6 @@ function mapSlotToTestVariations(slot) {
|
|
1731
1805
|
});
|
1732
1806
|
}
|
1733
1807
|
|
1734
|
-
// src/utils/variables/parseVariableExpression.ts
|
1735
|
-
var escapeCharacter = "\\";
|
1736
|
-
var variablePrefix = "${";
|
1737
|
-
var variableSuffix = "}";
|
1738
|
-
function parseVariableExpression(serialized, onToken) {
|
1739
|
-
let bufferStartIndex = 0;
|
1740
|
-
let bufferEndIndex = 0;
|
1741
|
-
let tokenCount = 0;
|
1742
|
-
const handleToken = (token, type) => {
|
1743
|
-
tokenCount++;
|
1744
|
-
return onToken == null ? void 0 : onToken(token, type);
|
1745
|
-
};
|
1746
|
-
let state = "text";
|
1747
|
-
for (let index = 0; index < serialized.length; index++) {
|
1748
|
-
const char = serialized[index];
|
1749
|
-
if (bufferStartIndex > bufferEndIndex) {
|
1750
|
-
bufferEndIndex = bufferStartIndex;
|
1751
|
-
}
|
1752
|
-
if (char === variablePrefix[0] && serialized[index + 1] === variablePrefix[1]) {
|
1753
|
-
if (serialized[index - 1] === escapeCharacter) {
|
1754
|
-
bufferEndIndex -= escapeCharacter.length;
|
1755
|
-
if (handleToken(serialized.substring(bufferStartIndex, bufferEndIndex), "text") === false) {
|
1756
|
-
return tokenCount;
|
1757
|
-
}
|
1758
|
-
bufferStartIndex = index;
|
1759
|
-
bufferEndIndex = index + 1;
|
1760
|
-
continue;
|
1761
|
-
}
|
1762
|
-
state = "variable";
|
1763
|
-
if (bufferEndIndex > bufferStartIndex) {
|
1764
|
-
if (handleToken(serialized.substring(bufferStartIndex, bufferEndIndex), "text") === false) {
|
1765
|
-
return tokenCount;
|
1766
|
-
}
|
1767
|
-
bufferStartIndex = bufferEndIndex;
|
1768
|
-
}
|
1769
|
-
index += variablePrefix.length - 1;
|
1770
|
-
bufferStartIndex += variablePrefix.length;
|
1771
|
-
continue;
|
1772
|
-
}
|
1773
|
-
if (char === variableSuffix && state === "variable") {
|
1774
|
-
state = "text";
|
1775
|
-
if (bufferEndIndex > bufferStartIndex) {
|
1776
|
-
if (handleToken(serialized.substring(bufferStartIndex, bufferEndIndex), "variable") === false) {
|
1777
|
-
return tokenCount;
|
1778
|
-
}
|
1779
|
-
bufferStartIndex = bufferEndIndex + variableSuffix.length;
|
1780
|
-
}
|
1781
|
-
continue;
|
1782
|
-
}
|
1783
|
-
bufferEndIndex++;
|
1784
|
-
}
|
1785
|
-
if (bufferEndIndex > bufferStartIndex) {
|
1786
|
-
if (state === "variable") {
|
1787
|
-
state = "text";
|
1788
|
-
bufferStartIndex -= variablePrefix.length;
|
1789
|
-
}
|
1790
|
-
handleToken(serialized.substring(bufferStartIndex), state);
|
1791
|
-
}
|
1792
|
-
return tokenCount;
|
1793
|
-
}
|
1794
|
-
|
1795
|
-
// src/utils/variables/bindVariables.ts
|
1796
|
-
function bindVariables({
|
1797
|
-
variables,
|
1798
|
-
value,
|
1799
|
-
errorPrefix = "Variable",
|
1800
|
-
handleBinding
|
1801
|
-
}) {
|
1802
|
-
let boundCount = 0;
|
1803
|
-
let tokenCount = 0;
|
1804
|
-
const errors = [];
|
1805
|
-
const defaultHandleBinding = (variableName, variables2, errors2) => {
|
1806
|
-
const variableValue = variables2[variableName];
|
1807
|
-
if (variableValue === void 0) {
|
1808
|
-
errors2.push(`${errorPrefix} "${variableName}" is not defined`);
|
1809
|
-
return "";
|
1810
|
-
}
|
1811
|
-
return variableValue;
|
1812
|
-
};
|
1813
|
-
const result = [];
|
1814
|
-
parseVariableExpression(value, (token, tokenType) => {
|
1815
|
-
tokenCount++;
|
1816
|
-
if (tokenType === "text") {
|
1817
|
-
result.push(token);
|
1818
|
-
return;
|
1819
|
-
}
|
1820
|
-
const variableValue = (handleBinding != null ? handleBinding : defaultHandleBinding)(token, variables, errors);
|
1821
|
-
boundCount++;
|
1822
|
-
result.push(variableValue);
|
1823
|
-
});
|
1824
|
-
return {
|
1825
|
-
result: tokenCount === 1 ? result[0] : result.join(""),
|
1826
|
-
boundCount,
|
1827
|
-
errors: errors.length > 0 ? errors : void 0
|
1828
|
-
};
|
1829
|
-
}
|
1830
|
-
|
1831
|
-
// src/utils/variables/bindVariablesToObject.ts
|
1832
|
-
import { produce } from "immer";
|
1833
|
-
|
1834
|
-
// src/utils/variables/createVariableReference.ts
|
1835
|
-
function createVariableReference(variableName) {
|
1836
|
-
return `\${${variableName}}`;
|
1837
|
-
}
|
1838
|
-
|
1839
|
-
// src/utils/variables/bindVariablesToObject.ts
|
1840
|
-
function bindVariablesToObject(options) {
|
1841
|
-
return bindVariablesToObjectRecursive(options);
|
1842
|
-
}
|
1843
|
-
function bindVariablesToObjectRecursive({
|
1844
|
-
value,
|
1845
|
-
recursivePath,
|
1846
|
-
...bindVariablesOptions
|
1847
|
-
}) {
|
1848
|
-
let boundCount = 0;
|
1849
|
-
const errors = [];
|
1850
|
-
if (typeof value === "string") {
|
1851
|
-
return bindVariables({ ...bindVariablesOptions, value });
|
1852
|
-
}
|
1853
|
-
if (typeof value !== "object" || value === null) {
|
1854
|
-
return { boundCount: 0, result: value };
|
1855
|
-
}
|
1856
|
-
const richTextNodeResult = handleRichTextNodeBinding(value, bindVariablesOptions);
|
1857
|
-
if (richTextNodeResult !== void 0) {
|
1858
|
-
return richTextNodeResult;
|
1859
|
-
}
|
1860
|
-
const result = produce(value, (draft) => {
|
1861
|
-
Object.entries(draft).forEach(([property, oldValue]) => {
|
1862
|
-
const currentObjectPath = recursivePath ? `${recursivePath}.${property}` : property;
|
1863
|
-
if (typeof oldValue === "string") {
|
1864
|
-
const bindResult = bindVariables({ ...bindVariablesOptions, value: oldValue });
|
1865
|
-
if (oldValue !== bindResult.result || bindResult.errors) {
|
1866
|
-
boundCount += bindResult.boundCount;
|
1867
|
-
draft[property] = bindResult.result;
|
1868
|
-
if (bindResult.errors) {
|
1869
|
-
errors.push(...bindResult.errors.map((e) => `${currentObjectPath}: ${e}`));
|
1870
|
-
}
|
1871
|
-
}
|
1872
|
-
return;
|
1873
|
-
}
|
1874
|
-
const childBind = bindVariablesToObjectRecursive({
|
1875
|
-
...bindVariablesOptions,
|
1876
|
-
value: oldValue,
|
1877
|
-
recursivePath: currentObjectPath
|
1878
|
-
});
|
1879
|
-
if (childBind.boundCount || childBind.errors) {
|
1880
|
-
boundCount += childBind.boundCount;
|
1881
|
-
draft[property] = childBind.result;
|
1882
|
-
if (childBind.errors) {
|
1883
|
-
errors.push(...childBind.errors);
|
1884
|
-
}
|
1885
|
-
}
|
1886
|
-
});
|
1887
|
-
});
|
1888
|
-
return { boundCount, result, errors: errors.length > 0 ? errors : void 0 };
|
1889
|
-
}
|
1890
|
-
function handleRichTextNodeBinding(object, options) {
|
1891
|
-
if ("type" in object && object.type === "variable" && "reference" in object && typeof object.reference === "string" && "version" in object && object.version === 1) {
|
1892
|
-
const value = createVariableReference(object.reference);
|
1893
|
-
const bindResult = bindVariables({ ...options, value });
|
1894
|
-
const bindResultAsTextNode = {
|
1895
|
-
detail: 0,
|
1896
|
-
format: 0,
|
1897
|
-
mode: "normal",
|
1898
|
-
style: "",
|
1899
|
-
text: bindResult.result,
|
1900
|
-
type: "text",
|
1901
|
-
version: 1
|
1902
|
-
};
|
1903
|
-
return { ...bindResult, result: bindResultAsTextNode };
|
1904
|
-
}
|
1905
|
-
return void 0;
|
1906
|
-
}
|
1907
|
-
|
1908
1808
|
// src/index.ts
|
1909
1809
|
import { ApiClientError } from "@uniformdev/context/api";
|
1910
1810
|
var CanvasClientError = ApiClientError;
|
@@ -1963,7 +1863,6 @@ export {
|
|
1963
1863
|
createEventBus,
|
1964
1864
|
createLimitPolicy,
|
1965
1865
|
createUniformApiEnhancer,
|
1966
|
-
createVariableReference,
|
1967
1866
|
enhance,
|
1968
1867
|
extractLocales,
|
1969
1868
|
generateHash,
|
@@ -1989,7 +1888,6 @@ export {
|
|
1989
1888
|
mapSlotToPersonalizedVariations,
|
1990
1889
|
mapSlotToTestVariations,
|
1991
1890
|
nullLimitPolicy,
|
1992
|
-
parseVariableExpression,
|
1993
1891
|
subscribeToComposition,
|
1994
1892
|
unstable_CompositionRelationshipClient,
|
1995
1893
|
walkComponentTree
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@uniformdev/canvas",
|
3
|
-
"version": "19.
|
3
|
+
"version": "19.36.0",
|
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,7 +38,7 @@
|
|
38
38
|
"pusher-js": "8.2.0"
|
39
39
|
},
|
40
40
|
"dependencies": {
|
41
|
-
"@uniformdev/context": "19.
|
41
|
+
"@uniformdev/context": "19.36.0",
|
42
42
|
"immer": "9.0.21"
|
43
43
|
},
|
44
44
|
"files": [
|
@@ -47,5 +47,5 @@
|
|
47
47
|
"publishConfig": {
|
48
48
|
"access": "public"
|
49
49
|
},
|
50
|
-
"gitHead": "
|
50
|
+
"gitHead": "3ae246a7f0f39adeaf04ecba4c7e48c478c019ad"
|
51
51
|
}
|