@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.esm.js
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/dist/index.js
CHANGED
@@ -331,7 +331,6 @@ __export(src_exports, {
|
|
331
331
|
createEventBus: () => createEventBus,
|
332
332
|
createLimitPolicy: () => createLimitPolicy,
|
333
333
|
createUniformApiEnhancer: () => createUniformApiEnhancer,
|
334
|
-
createVariableReference: () => createVariableReference,
|
335
334
|
enhance: () => enhance,
|
336
335
|
extractLocales: () => extractLocales,
|
337
336
|
generateHash: () => generateHash,
|
@@ -357,7 +356,6 @@ __export(src_exports, {
|
|
357
356
|
mapSlotToPersonalizedVariations: () => mapSlotToPersonalizedVariations,
|
358
357
|
mapSlotToTestVariations: () => mapSlotToTestVariations,
|
359
358
|
nullLimitPolicy: () => nullLimitPolicy,
|
360
|
-
parseVariableExpression: () => parseVariableExpression,
|
361
359
|
subscribeToComposition: () => subscribeToComposition,
|
362
360
|
unstable_CompositionRelationshipClient: () => unstable_CompositionRelationshipClient,
|
363
361
|
walkComponentTree: () => walkComponentTree
|
@@ -1738,6 +1736,80 @@ var RouteClient = class extends import_api6.ApiClient {
|
|
1738
1736
|
}
|
1739
1737
|
};
|
1740
1738
|
|
1739
|
+
// src/utils/bindVariables.ts
|
1740
|
+
function bindVariables({
|
1741
|
+
variables,
|
1742
|
+
value,
|
1743
|
+
errorPrefix = "Variable",
|
1744
|
+
handleBinding
|
1745
|
+
}) {
|
1746
|
+
let boundCount = 0;
|
1747
|
+
const errors = [];
|
1748
|
+
const defaultHandleBinding = (variableName, variables2, errors2) => {
|
1749
|
+
const variableValue = variables2[variableName];
|
1750
|
+
if (variableValue === void 0) {
|
1751
|
+
errors2.push(`${errorPrefix} "${variableName}" is not defined`);
|
1752
|
+
return "";
|
1753
|
+
}
|
1754
|
+
return variableValue;
|
1755
|
+
};
|
1756
|
+
const result = value.replace(/(?<!\\)\${([^}]+)}/g, (_match, variableName) => {
|
1757
|
+
const variableValue = (handleBinding != null ? handleBinding : defaultHandleBinding)(variableName, variables, errors);
|
1758
|
+
boundCount++;
|
1759
|
+
return variableValue;
|
1760
|
+
});
|
1761
|
+
return { result, boundCount, errors: errors.length > 0 ? errors : void 0 };
|
1762
|
+
}
|
1763
|
+
|
1764
|
+
// src/utils/bindVariablesToObject.ts
|
1765
|
+
var import_immer = require("immer");
|
1766
|
+
function bindVariablesToObject(options) {
|
1767
|
+
return bindVariablesToObjectRecursive(options);
|
1768
|
+
}
|
1769
|
+
function bindVariablesToObjectRecursive({
|
1770
|
+
value,
|
1771
|
+
recursivePath,
|
1772
|
+
...bindVariablesOptions
|
1773
|
+
}) {
|
1774
|
+
let boundCount = 0;
|
1775
|
+
const errors = [];
|
1776
|
+
if (typeof value === "string") {
|
1777
|
+
return bindVariables({ ...bindVariablesOptions, value });
|
1778
|
+
}
|
1779
|
+
if (typeof value !== "object" || value === null) {
|
1780
|
+
return { boundCount: 0, result: value };
|
1781
|
+
}
|
1782
|
+
const result = (0, import_immer.produce)(value, (draft) => {
|
1783
|
+
Object.entries(draft).forEach(([property, oldValue]) => {
|
1784
|
+
const currentObjectPath = recursivePath ? `${recursivePath}.${property}` : property;
|
1785
|
+
if (typeof oldValue === "string") {
|
1786
|
+
const bindResult = bindVariables({ ...bindVariablesOptions, value: oldValue });
|
1787
|
+
if (oldValue !== bindResult.result || bindResult.errors) {
|
1788
|
+
boundCount += bindResult.boundCount;
|
1789
|
+
draft[property] = bindResult.result;
|
1790
|
+
if (bindResult.errors) {
|
1791
|
+
errors.push(...bindResult.errors.map((e) => `${currentObjectPath}: ${e}`));
|
1792
|
+
}
|
1793
|
+
}
|
1794
|
+
return;
|
1795
|
+
}
|
1796
|
+
const childBind = bindVariablesToObjectRecursive({
|
1797
|
+
...bindVariablesOptions,
|
1798
|
+
value: oldValue,
|
1799
|
+
recursivePath: currentObjectPath
|
1800
|
+
});
|
1801
|
+
if (childBind.boundCount || childBind.errors) {
|
1802
|
+
boundCount += childBind.boundCount;
|
1803
|
+
draft[property] = childBind.result;
|
1804
|
+
if (childBind.errors) {
|
1805
|
+
errors.push(...childBind.errors.map((e) => `${currentObjectPath}: ${e}`));
|
1806
|
+
}
|
1807
|
+
}
|
1808
|
+
});
|
1809
|
+
});
|
1810
|
+
return { boundCount, result, errors: errors.length > 0 ? errors : void 0 };
|
1811
|
+
}
|
1812
|
+
|
1741
1813
|
// src/utils/createApiEnhancer.ts
|
1742
1814
|
var createUniformApiEnhancer = ({ apiUrl }) => {
|
1743
1815
|
return async (message) => {
|
@@ -1785,8 +1857,8 @@ var getParameterAttributes = ({
|
|
1785
1857
|
[ATTRIBUTE_PARAMETER_VALUE]: String(value != null ? value : ""),
|
1786
1858
|
[ATTRIBUTE_PARAMETER_TYPE]: type,
|
1787
1859
|
[ATTRIBUTE_PLACEHOLDER]: placeholder,
|
1788
|
-
[ATTRIBUTE_MULTILINE]:
|
1789
|
-
contentEditable:
|
1860
|
+
[ATTRIBUTE_MULTILINE]: isMultiline,
|
1861
|
+
contentEditable: isEditable
|
1790
1862
|
};
|
1791
1863
|
};
|
1792
1864
|
|
@@ -1827,180 +1899,6 @@ function mapSlotToTestVariations(slot) {
|
|
1827
1899
|
});
|
1828
1900
|
}
|
1829
1901
|
|
1830
|
-
// src/utils/variables/parseVariableExpression.ts
|
1831
|
-
var escapeCharacter = "\\";
|
1832
|
-
var variablePrefix = "${";
|
1833
|
-
var variableSuffix = "}";
|
1834
|
-
function parseVariableExpression(serialized, onToken) {
|
1835
|
-
let bufferStartIndex = 0;
|
1836
|
-
let bufferEndIndex = 0;
|
1837
|
-
let tokenCount = 0;
|
1838
|
-
const handleToken = (token, type) => {
|
1839
|
-
tokenCount++;
|
1840
|
-
return onToken == null ? void 0 : onToken(token, type);
|
1841
|
-
};
|
1842
|
-
let state = "text";
|
1843
|
-
for (let index = 0; index < serialized.length; index++) {
|
1844
|
-
const char = serialized[index];
|
1845
|
-
if (bufferStartIndex > bufferEndIndex) {
|
1846
|
-
bufferEndIndex = bufferStartIndex;
|
1847
|
-
}
|
1848
|
-
if (char === variablePrefix[0] && serialized[index + 1] === variablePrefix[1]) {
|
1849
|
-
if (serialized[index - 1] === escapeCharacter) {
|
1850
|
-
bufferEndIndex -= escapeCharacter.length;
|
1851
|
-
if (handleToken(serialized.substring(bufferStartIndex, bufferEndIndex), "text") === false) {
|
1852
|
-
return tokenCount;
|
1853
|
-
}
|
1854
|
-
bufferStartIndex = index;
|
1855
|
-
bufferEndIndex = index + 1;
|
1856
|
-
continue;
|
1857
|
-
}
|
1858
|
-
state = "variable";
|
1859
|
-
if (bufferEndIndex > bufferStartIndex) {
|
1860
|
-
if (handleToken(serialized.substring(bufferStartIndex, bufferEndIndex), "text") === false) {
|
1861
|
-
return tokenCount;
|
1862
|
-
}
|
1863
|
-
bufferStartIndex = bufferEndIndex;
|
1864
|
-
}
|
1865
|
-
index += variablePrefix.length - 1;
|
1866
|
-
bufferStartIndex += variablePrefix.length;
|
1867
|
-
continue;
|
1868
|
-
}
|
1869
|
-
if (char === variableSuffix && state === "variable") {
|
1870
|
-
state = "text";
|
1871
|
-
if (bufferEndIndex > bufferStartIndex) {
|
1872
|
-
if (handleToken(serialized.substring(bufferStartIndex, bufferEndIndex), "variable") === false) {
|
1873
|
-
return tokenCount;
|
1874
|
-
}
|
1875
|
-
bufferStartIndex = bufferEndIndex + variableSuffix.length;
|
1876
|
-
}
|
1877
|
-
continue;
|
1878
|
-
}
|
1879
|
-
bufferEndIndex++;
|
1880
|
-
}
|
1881
|
-
if (bufferEndIndex > bufferStartIndex) {
|
1882
|
-
if (state === "variable") {
|
1883
|
-
state = "text";
|
1884
|
-
bufferStartIndex -= variablePrefix.length;
|
1885
|
-
}
|
1886
|
-
handleToken(serialized.substring(bufferStartIndex), state);
|
1887
|
-
}
|
1888
|
-
return tokenCount;
|
1889
|
-
}
|
1890
|
-
|
1891
|
-
// src/utils/variables/bindVariables.ts
|
1892
|
-
function bindVariables({
|
1893
|
-
variables,
|
1894
|
-
value,
|
1895
|
-
errorPrefix = "Variable",
|
1896
|
-
handleBinding
|
1897
|
-
}) {
|
1898
|
-
let boundCount = 0;
|
1899
|
-
let tokenCount = 0;
|
1900
|
-
const errors = [];
|
1901
|
-
const defaultHandleBinding = (variableName, variables2, errors2) => {
|
1902
|
-
const variableValue = variables2[variableName];
|
1903
|
-
if (variableValue === void 0) {
|
1904
|
-
errors2.push(`${errorPrefix} "${variableName}" is not defined`);
|
1905
|
-
return "";
|
1906
|
-
}
|
1907
|
-
return variableValue;
|
1908
|
-
};
|
1909
|
-
const result = [];
|
1910
|
-
parseVariableExpression(value, (token, tokenType) => {
|
1911
|
-
tokenCount++;
|
1912
|
-
if (tokenType === "text") {
|
1913
|
-
result.push(token);
|
1914
|
-
return;
|
1915
|
-
}
|
1916
|
-
const variableValue = (handleBinding != null ? handleBinding : defaultHandleBinding)(token, variables, errors);
|
1917
|
-
boundCount++;
|
1918
|
-
result.push(variableValue);
|
1919
|
-
});
|
1920
|
-
return {
|
1921
|
-
result: tokenCount === 1 ? result[0] : result.join(""),
|
1922
|
-
boundCount,
|
1923
|
-
errors: errors.length > 0 ? errors : void 0
|
1924
|
-
};
|
1925
|
-
}
|
1926
|
-
|
1927
|
-
// src/utils/variables/bindVariablesToObject.ts
|
1928
|
-
var import_immer = require("immer");
|
1929
|
-
|
1930
|
-
// src/utils/variables/createVariableReference.ts
|
1931
|
-
function createVariableReference(variableName) {
|
1932
|
-
return `\${${variableName}}`;
|
1933
|
-
}
|
1934
|
-
|
1935
|
-
// src/utils/variables/bindVariablesToObject.ts
|
1936
|
-
function bindVariablesToObject(options) {
|
1937
|
-
return bindVariablesToObjectRecursive(options);
|
1938
|
-
}
|
1939
|
-
function bindVariablesToObjectRecursive({
|
1940
|
-
value,
|
1941
|
-
recursivePath,
|
1942
|
-
...bindVariablesOptions
|
1943
|
-
}) {
|
1944
|
-
let boundCount = 0;
|
1945
|
-
const errors = [];
|
1946
|
-
if (typeof value === "string") {
|
1947
|
-
return bindVariables({ ...bindVariablesOptions, value });
|
1948
|
-
}
|
1949
|
-
if (typeof value !== "object" || value === null) {
|
1950
|
-
return { boundCount: 0, result: value };
|
1951
|
-
}
|
1952
|
-
const richTextNodeResult = handleRichTextNodeBinding(value, bindVariablesOptions);
|
1953
|
-
if (richTextNodeResult !== void 0) {
|
1954
|
-
return richTextNodeResult;
|
1955
|
-
}
|
1956
|
-
const result = (0, import_immer.produce)(value, (draft) => {
|
1957
|
-
Object.entries(draft).forEach(([property, oldValue]) => {
|
1958
|
-
const currentObjectPath = recursivePath ? `${recursivePath}.${property}` : property;
|
1959
|
-
if (typeof oldValue === "string") {
|
1960
|
-
const bindResult = bindVariables({ ...bindVariablesOptions, value: oldValue });
|
1961
|
-
if (oldValue !== bindResult.result || bindResult.errors) {
|
1962
|
-
boundCount += bindResult.boundCount;
|
1963
|
-
draft[property] = bindResult.result;
|
1964
|
-
if (bindResult.errors) {
|
1965
|
-
errors.push(...bindResult.errors.map((e) => `${currentObjectPath}: ${e}`));
|
1966
|
-
}
|
1967
|
-
}
|
1968
|
-
return;
|
1969
|
-
}
|
1970
|
-
const childBind = bindVariablesToObjectRecursive({
|
1971
|
-
...bindVariablesOptions,
|
1972
|
-
value: oldValue,
|
1973
|
-
recursivePath: currentObjectPath
|
1974
|
-
});
|
1975
|
-
if (childBind.boundCount || childBind.errors) {
|
1976
|
-
boundCount += childBind.boundCount;
|
1977
|
-
draft[property] = childBind.result;
|
1978
|
-
if (childBind.errors) {
|
1979
|
-
errors.push(...childBind.errors);
|
1980
|
-
}
|
1981
|
-
}
|
1982
|
-
});
|
1983
|
-
});
|
1984
|
-
return { boundCount, result, errors: errors.length > 0 ? errors : void 0 };
|
1985
|
-
}
|
1986
|
-
function handleRichTextNodeBinding(object, options) {
|
1987
|
-
if ("type" in object && object.type === "variable" && "reference" in object && typeof object.reference === "string" && "version" in object && object.version === 1) {
|
1988
|
-
const value = createVariableReference(object.reference);
|
1989
|
-
const bindResult = bindVariables({ ...options, value });
|
1990
|
-
const bindResultAsTextNode = {
|
1991
|
-
detail: 0,
|
1992
|
-
format: 0,
|
1993
|
-
mode: "normal",
|
1994
|
-
style: "",
|
1995
|
-
text: bindResult.result,
|
1996
|
-
type: "text",
|
1997
|
-
version: 1
|
1998
|
-
};
|
1999
|
-
return { ...bindResult, result: bindResultAsTextNode };
|
2000
|
-
}
|
2001
|
-
return void 0;
|
2002
|
-
}
|
2003
|
-
|
2004
1902
|
// src/index.ts
|
2005
1903
|
var import_api7 = require("@uniformdev/context/api");
|
2006
1904
|
var CanvasClientError = import_api7.ApiClientError;
|
@@ -2060,7 +1958,6 @@ var CanvasClientError = import_api7.ApiClientError;
|
|
2060
1958
|
createEventBus,
|
2061
1959
|
createLimitPolicy,
|
2062
1960
|
createUniformApiEnhancer,
|
2063
|
-
createVariableReference,
|
2064
1961
|
enhance,
|
2065
1962
|
extractLocales,
|
2066
1963
|
generateHash,
|
@@ -2086,7 +1983,6 @@ var CanvasClientError = import_api7.ApiClientError;
|
|
2086
1983
|
mapSlotToPersonalizedVariations,
|
2087
1984
|
mapSlotToTestVariations,
|
2088
1985
|
nullLimitPolicy,
|
2089
|
-
parseVariableExpression,
|
2090
1986
|
subscribeToComposition,
|
2091
1987
|
unstable_CompositionRelationshipClient,
|
2092
1988
|
walkComponentTree
|