@uniformdev/canvas 19.37.1 → 19.38.3-alpha.70
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 +97 -124
- package/dist/index.d.ts +97 -124
- package/dist/index.esm.js +176 -74
- package/dist/index.js +178 -74
- package/dist/index.mjs +176 -74
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
@@ -1658,80 +1658,6 @@ var RouteClient = class extends ApiClient6 {
|
|
1658
1658
|
}
|
1659
1659
|
};
|
1660
1660
|
|
1661
|
-
// src/utils/bindVariables.ts
|
1662
|
-
function bindVariables({
|
1663
|
-
variables,
|
1664
|
-
value,
|
1665
|
-
errorPrefix = "Variable",
|
1666
|
-
handleBinding
|
1667
|
-
}) {
|
1668
|
-
let boundCount = 0;
|
1669
|
-
const errors = [];
|
1670
|
-
const defaultHandleBinding = (variableName, variables2, errors2) => {
|
1671
|
-
const variableValue = variables2[variableName];
|
1672
|
-
if (variableValue === void 0) {
|
1673
|
-
errors2.push(`${errorPrefix} "${variableName}" is not defined`);
|
1674
|
-
return "";
|
1675
|
-
}
|
1676
|
-
return variableValue;
|
1677
|
-
};
|
1678
|
-
const result = value.replace(/(?<!\\)\${([^}]+)}/g, (_match, variableName) => {
|
1679
|
-
const variableValue = (handleBinding != null ? handleBinding : defaultHandleBinding)(variableName, variables, errors);
|
1680
|
-
boundCount++;
|
1681
|
-
return variableValue;
|
1682
|
-
});
|
1683
|
-
return { result, boundCount, errors: errors.length > 0 ? errors : void 0 };
|
1684
|
-
}
|
1685
|
-
|
1686
|
-
// src/utils/bindVariablesToObject.ts
|
1687
|
-
import { produce } from "immer";
|
1688
|
-
function bindVariablesToObject(options) {
|
1689
|
-
return bindVariablesToObjectRecursive(options);
|
1690
|
-
}
|
1691
|
-
function bindVariablesToObjectRecursive({
|
1692
|
-
value,
|
1693
|
-
recursivePath,
|
1694
|
-
...bindVariablesOptions
|
1695
|
-
}) {
|
1696
|
-
let boundCount = 0;
|
1697
|
-
const errors = [];
|
1698
|
-
if (typeof value === "string") {
|
1699
|
-
return bindVariables({ ...bindVariablesOptions, value });
|
1700
|
-
}
|
1701
|
-
if (typeof value !== "object" || value === null) {
|
1702
|
-
return { boundCount: 0, result: value };
|
1703
|
-
}
|
1704
|
-
const result = produce(value, (draft) => {
|
1705
|
-
Object.entries(draft).forEach(([property, oldValue]) => {
|
1706
|
-
const currentObjectPath = recursivePath ? `${recursivePath}.${property}` : property;
|
1707
|
-
if (typeof oldValue === "string") {
|
1708
|
-
const bindResult = bindVariables({ ...bindVariablesOptions, value: oldValue });
|
1709
|
-
if (oldValue !== bindResult.result || bindResult.errors) {
|
1710
|
-
boundCount += bindResult.boundCount;
|
1711
|
-
draft[property] = bindResult.result;
|
1712
|
-
if (bindResult.errors) {
|
1713
|
-
errors.push(...bindResult.errors.map((e) => `${currentObjectPath}: ${e}`));
|
1714
|
-
}
|
1715
|
-
}
|
1716
|
-
return;
|
1717
|
-
}
|
1718
|
-
const childBind = bindVariablesToObjectRecursive({
|
1719
|
-
...bindVariablesOptions,
|
1720
|
-
value: oldValue,
|
1721
|
-
recursivePath: currentObjectPath
|
1722
|
-
});
|
1723
|
-
if (childBind.boundCount || childBind.errors) {
|
1724
|
-
boundCount += childBind.boundCount;
|
1725
|
-
draft[property] = childBind.result;
|
1726
|
-
if (childBind.errors) {
|
1727
|
-
errors.push(...childBind.errors.map((e) => `${currentObjectPath}: ${e}`));
|
1728
|
-
}
|
1729
|
-
}
|
1730
|
-
});
|
1731
|
-
});
|
1732
|
-
return { boundCount, result, errors: errors.length > 0 ? errors : void 0 };
|
1733
|
-
}
|
1734
|
-
|
1735
1661
|
// src/utils/createApiEnhancer.ts
|
1736
1662
|
var createUniformApiEnhancer = ({ apiUrl }) => {
|
1737
1663
|
return async (message) => {
|
@@ -1821,6 +1747,180 @@ function mapSlotToTestVariations(slot) {
|
|
1821
1747
|
});
|
1822
1748
|
}
|
1823
1749
|
|
1750
|
+
// src/utils/variables/parseVariableExpression.ts
|
1751
|
+
var escapeCharacter = "\\";
|
1752
|
+
var variablePrefix = "${";
|
1753
|
+
var variableSuffix = "}";
|
1754
|
+
function parseVariableExpression(serialized, onToken) {
|
1755
|
+
let bufferStartIndex = 0;
|
1756
|
+
let bufferEndIndex = 0;
|
1757
|
+
let tokenCount = 0;
|
1758
|
+
const handleToken = (token, type) => {
|
1759
|
+
tokenCount++;
|
1760
|
+
return onToken == null ? void 0 : onToken(token, type);
|
1761
|
+
};
|
1762
|
+
let state = "text";
|
1763
|
+
for (let index = 0; index < serialized.length; index++) {
|
1764
|
+
const char = serialized[index];
|
1765
|
+
if (bufferStartIndex > bufferEndIndex) {
|
1766
|
+
bufferEndIndex = bufferStartIndex;
|
1767
|
+
}
|
1768
|
+
if (char === variablePrefix[0] && serialized[index + 1] === variablePrefix[1]) {
|
1769
|
+
if (serialized[index - 1] === escapeCharacter) {
|
1770
|
+
bufferEndIndex -= escapeCharacter.length;
|
1771
|
+
if (handleToken(serialized.substring(bufferStartIndex, bufferEndIndex), "text") === false) {
|
1772
|
+
return tokenCount;
|
1773
|
+
}
|
1774
|
+
bufferStartIndex = index;
|
1775
|
+
bufferEndIndex = index + 1;
|
1776
|
+
continue;
|
1777
|
+
}
|
1778
|
+
state = "variable";
|
1779
|
+
if (bufferEndIndex > bufferStartIndex) {
|
1780
|
+
if (handleToken(serialized.substring(bufferStartIndex, bufferEndIndex), "text") === false) {
|
1781
|
+
return tokenCount;
|
1782
|
+
}
|
1783
|
+
bufferStartIndex = bufferEndIndex;
|
1784
|
+
}
|
1785
|
+
index += variablePrefix.length - 1;
|
1786
|
+
bufferStartIndex += variablePrefix.length;
|
1787
|
+
continue;
|
1788
|
+
}
|
1789
|
+
if (char === variableSuffix && state === "variable") {
|
1790
|
+
state = "text";
|
1791
|
+
if (bufferEndIndex > bufferStartIndex) {
|
1792
|
+
if (handleToken(serialized.substring(bufferStartIndex, bufferEndIndex), "variable") === false) {
|
1793
|
+
return tokenCount;
|
1794
|
+
}
|
1795
|
+
bufferStartIndex = bufferEndIndex + variableSuffix.length;
|
1796
|
+
}
|
1797
|
+
continue;
|
1798
|
+
}
|
1799
|
+
bufferEndIndex++;
|
1800
|
+
}
|
1801
|
+
if (bufferEndIndex > bufferStartIndex) {
|
1802
|
+
if (state === "variable") {
|
1803
|
+
state = "text";
|
1804
|
+
bufferStartIndex -= variablePrefix.length;
|
1805
|
+
}
|
1806
|
+
handleToken(serialized.substring(bufferStartIndex), state);
|
1807
|
+
}
|
1808
|
+
return tokenCount;
|
1809
|
+
}
|
1810
|
+
|
1811
|
+
// src/utils/variables/bindVariables.ts
|
1812
|
+
function bindVariables({
|
1813
|
+
variables,
|
1814
|
+
value,
|
1815
|
+
errorPrefix = "Variable",
|
1816
|
+
handleBinding
|
1817
|
+
}) {
|
1818
|
+
let boundCount = 0;
|
1819
|
+
let tokenCount = 0;
|
1820
|
+
const errors = [];
|
1821
|
+
const defaultHandleBinding = (variableName, variables2, errors2) => {
|
1822
|
+
const variableValue = variables2[variableName];
|
1823
|
+
if (variableValue === void 0) {
|
1824
|
+
errors2.push(`${errorPrefix} "${variableName}" is not defined`);
|
1825
|
+
return "";
|
1826
|
+
}
|
1827
|
+
return variableValue;
|
1828
|
+
};
|
1829
|
+
const result = [];
|
1830
|
+
parseVariableExpression(value, (token, tokenType) => {
|
1831
|
+
tokenCount++;
|
1832
|
+
if (tokenType === "text") {
|
1833
|
+
result.push(token);
|
1834
|
+
return;
|
1835
|
+
}
|
1836
|
+
const variableValue = (handleBinding != null ? handleBinding : defaultHandleBinding)(token, variables, errors);
|
1837
|
+
boundCount++;
|
1838
|
+
result.push(variableValue);
|
1839
|
+
});
|
1840
|
+
return {
|
1841
|
+
result: tokenCount === 1 ? result[0] : result.join(""),
|
1842
|
+
boundCount,
|
1843
|
+
errors: errors.length > 0 ? errors : void 0
|
1844
|
+
};
|
1845
|
+
}
|
1846
|
+
|
1847
|
+
// src/utils/variables/bindVariablesToObject.ts
|
1848
|
+
import { produce } from "immer";
|
1849
|
+
|
1850
|
+
// src/utils/variables/createVariableReference.ts
|
1851
|
+
function createVariableReference(variableName) {
|
1852
|
+
return `\${${variableName}}`;
|
1853
|
+
}
|
1854
|
+
|
1855
|
+
// src/utils/variables/bindVariablesToObject.ts
|
1856
|
+
function bindVariablesToObject(options) {
|
1857
|
+
return bindVariablesToObjectRecursive(options);
|
1858
|
+
}
|
1859
|
+
function bindVariablesToObjectRecursive({
|
1860
|
+
value,
|
1861
|
+
recursivePath,
|
1862
|
+
...bindVariablesOptions
|
1863
|
+
}) {
|
1864
|
+
let boundCount = 0;
|
1865
|
+
const errors = [];
|
1866
|
+
if (typeof value === "string") {
|
1867
|
+
return bindVariables({ ...bindVariablesOptions, value });
|
1868
|
+
}
|
1869
|
+
if (typeof value !== "object" || value === null) {
|
1870
|
+
return { boundCount: 0, result: value };
|
1871
|
+
}
|
1872
|
+
const richTextNodeResult = handleRichTextNodeBinding(value, bindVariablesOptions);
|
1873
|
+
if (richTextNodeResult !== void 0) {
|
1874
|
+
return richTextNodeResult;
|
1875
|
+
}
|
1876
|
+
const result = produce(value, (draft) => {
|
1877
|
+
Object.entries(draft).forEach(([property, oldValue]) => {
|
1878
|
+
const currentObjectPath = recursivePath ? `${recursivePath}.${property}` : property;
|
1879
|
+
if (typeof oldValue === "string") {
|
1880
|
+
const bindResult = bindVariables({ ...bindVariablesOptions, value: oldValue });
|
1881
|
+
if (oldValue !== bindResult.result || bindResult.errors) {
|
1882
|
+
boundCount += bindResult.boundCount;
|
1883
|
+
draft[property] = bindResult.result;
|
1884
|
+
if (bindResult.errors) {
|
1885
|
+
errors.push(...bindResult.errors.map((e) => `${currentObjectPath}: ${e}`));
|
1886
|
+
}
|
1887
|
+
}
|
1888
|
+
return;
|
1889
|
+
}
|
1890
|
+
const childBind = bindVariablesToObjectRecursive({
|
1891
|
+
...bindVariablesOptions,
|
1892
|
+
value: oldValue,
|
1893
|
+
recursivePath: currentObjectPath
|
1894
|
+
});
|
1895
|
+
if (childBind.boundCount || childBind.errors) {
|
1896
|
+
boundCount += childBind.boundCount;
|
1897
|
+
draft[property] = childBind.result;
|
1898
|
+
if (childBind.errors) {
|
1899
|
+
errors.push(...childBind.errors);
|
1900
|
+
}
|
1901
|
+
}
|
1902
|
+
});
|
1903
|
+
});
|
1904
|
+
return { boundCount, result, errors: errors.length > 0 ? errors : void 0 };
|
1905
|
+
}
|
1906
|
+
function handleRichTextNodeBinding(object, options) {
|
1907
|
+
if ("type" in object && object.type === "variable" && "reference" in object && typeof object.reference === "string" && "version" in object && object.version === 1) {
|
1908
|
+
const value = createVariableReference(object.reference);
|
1909
|
+
const bindResult = bindVariables({ ...options, value });
|
1910
|
+
const bindResultAsTextNode = {
|
1911
|
+
detail: 0,
|
1912
|
+
format: 0,
|
1913
|
+
mode: "normal",
|
1914
|
+
style: "",
|
1915
|
+
text: bindResult.result,
|
1916
|
+
type: "text",
|
1917
|
+
version: 1
|
1918
|
+
};
|
1919
|
+
return { ...bindResult, result: bindResultAsTextNode };
|
1920
|
+
}
|
1921
|
+
return void 0;
|
1922
|
+
}
|
1923
|
+
|
1824
1924
|
// src/index.ts
|
1825
1925
|
import { ApiClientError as ApiClientError2 } from "@uniformdev/context/api";
|
1826
1926
|
var CanvasClientError = ApiClientError2;
|
@@ -1879,6 +1979,7 @@ export {
|
|
1879
1979
|
createEventBus,
|
1880
1980
|
createLimitPolicy,
|
1881
1981
|
createUniformApiEnhancer,
|
1982
|
+
createVariableReference,
|
1882
1983
|
enhance,
|
1883
1984
|
extractLocales,
|
1884
1985
|
generateHash,
|
@@ -1904,6 +2005,7 @@ export {
|
|
1904
2005
|
mapSlotToPersonalizedVariations,
|
1905
2006
|
mapSlotToTestVariations,
|
1906
2007
|
nullLimitPolicy,
|
2008
|
+
parseVariableExpression,
|
1907
2009
|
subscribeToComposition,
|
1908
2010
|
unstable_CompositionRelationshipClient,
|
1909
2011
|
walkComponentTree
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@uniformdev/canvas",
|
3
|
-
"version": "19.
|
3
|
+
"version": "19.38.3-alpha.70+55e5a8fe1",
|
4
4
|
"description": "Common functionality and types for Uniform Canvas",
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
6
6
|
"main": "./dist/index.js",
|
@@ -32,13 +32,13 @@
|
|
32
32
|
},
|
33
33
|
"devDependencies": {
|
34
34
|
"@types/retry": "0.12.1",
|
35
|
-
"lexical": "^0.11.
|
35
|
+
"lexical": "^0.11.3",
|
36
36
|
"p-retry": "5.1.2",
|
37
37
|
"p-throttle": "5.0.0",
|
38
38
|
"pusher-js": "8.2.0"
|
39
39
|
},
|
40
40
|
"dependencies": {
|
41
|
-
"@uniformdev/context": "19.
|
41
|
+
"@uniformdev/context": "19.38.3-alpha.70+55e5a8fe1",
|
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": "55e5a8fe1d80971a93ea31d3a50cec72e71be70a"
|
51
51
|
}
|