@open-feishu-card/adapter 0.3.12 → 0.3.14
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.cjs +62 -7
- package/dist/index.js +62 -7
- package/dist/raw-to-dsl.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -999,7 +999,11 @@ function behaviorsToActions(behaviors) {
|
|
|
999
999
|
for (const b of behaviors) {
|
|
1000
1000
|
if (!isRecord2(b)) continue;
|
|
1001
1001
|
const type = typeof b.type === "string" ? b.type : "open_url";
|
|
1002
|
-
|
|
1002
|
+
const action = { url: normalizeUrl(b.default_url) };
|
|
1003
|
+
if (typeof b.pc_url === "string" && b.pc_url) action.pcURL = b.pc_url;
|
|
1004
|
+
if (typeof b.ios_url === "string" && b.ios_url) action.iosURL = b.ios_url;
|
|
1005
|
+
if (typeof b.android_url === "string" && b.android_url) action.androidURL = b.android_url;
|
|
1006
|
+
out.push({ type, action });
|
|
1003
1007
|
}
|
|
1004
1008
|
return out;
|
|
1005
1009
|
}
|
|
@@ -1728,7 +1732,14 @@ function unwrap(node, ctx) {
|
|
|
1728
1732
|
const tp = isRecord3(text.property) ? text.property : {};
|
|
1729
1733
|
const content = typeof tp.content === "string" ? tp.content : "";
|
|
1730
1734
|
const textAlign = typeof tp.textAlign === "string" ? tp.textAlign : "left";
|
|
1731
|
-
|
|
1735
|
+
const outText = { tag: "plain_text", content, text_align: textAlign };
|
|
1736
|
+
const ts = isRecord3(tp.textStyle) ? tp.textStyle : void 0;
|
|
1737
|
+
if (ts && typeof ts.size === "string") outText.text_size = ts.size;
|
|
1738
|
+
const { color } = resolveInlineStyle(ts, ctx);
|
|
1739
|
+
if (color) outText.text_color = color;
|
|
1740
|
+
out.text = outText;
|
|
1741
|
+
if (isRecord3(property.margin) && hasSide(property.margin)) out.margin = formatBox(property.margin);
|
|
1742
|
+
else if (typeof property.margin === "string") out.margin = property.margin;
|
|
1732
1743
|
if (isRecord3(property.icon)) {
|
|
1733
1744
|
out.icon = unwrap(property.icon, ctx);
|
|
1734
1745
|
}
|
|
@@ -1739,6 +1750,47 @@ function unwrap(node, ctx) {
|
|
|
1739
1750
|
return tag ? { tag, ...converted } : converted;
|
|
1740
1751
|
}
|
|
1741
1752
|
var DROP = /* @__PURE__ */ Symbol("drop");
|
|
1753
|
+
function projectOpenUrlFields(actionInner) {
|
|
1754
|
+
let bag;
|
|
1755
|
+
let defaultUrl;
|
|
1756
|
+
if (typeof actionInner.url === "string") {
|
|
1757
|
+
defaultUrl = actionInner.url;
|
|
1758
|
+
bag = actionInner;
|
|
1759
|
+
} else if (isRecord3(actionInner.url)) {
|
|
1760
|
+
bag = actionInner.url;
|
|
1761
|
+
defaultUrl = typeof bag.url === "string" ? bag.url : void 0;
|
|
1762
|
+
} else if (isRecord3(actionInner.multiURL)) {
|
|
1763
|
+
bag = actionInner.multiURL;
|
|
1764
|
+
defaultUrl = typeof bag.url === "string" ? bag.url : void 0;
|
|
1765
|
+
} else if (isRecord3(actionInner.multi_url)) {
|
|
1766
|
+
bag = actionInner.multi_url;
|
|
1767
|
+
defaultUrl = typeof bag.url === "string" ? bag.url : void 0;
|
|
1768
|
+
}
|
|
1769
|
+
if (!defaultUrl) return void 0;
|
|
1770
|
+
const pick = (...keys) => {
|
|
1771
|
+
if (!bag) return void 0;
|
|
1772
|
+
for (const k of keys) {
|
|
1773
|
+
const v = bag[k];
|
|
1774
|
+
if (typeof v === "string" && v.length > 0) return v;
|
|
1775
|
+
}
|
|
1776
|
+
return void 0;
|
|
1777
|
+
};
|
|
1778
|
+
const out = { default_url: defaultUrl };
|
|
1779
|
+
const pc = pick("pcURL", "pc_url");
|
|
1780
|
+
const ios = pick("iosURL", "ios_url");
|
|
1781
|
+
const android = pick("androidURL", "android_url");
|
|
1782
|
+
if (pc) out.pc_url = pc;
|
|
1783
|
+
if (ios) out.ios_url = ios;
|
|
1784
|
+
if (android) out.android_url = android;
|
|
1785
|
+
return out;
|
|
1786
|
+
}
|
|
1787
|
+
function openUrlFieldsToMultiUrl(fields) {
|
|
1788
|
+
const multi = { url: fields.default_url };
|
|
1789
|
+
if (fields.pc_url) multi.pc_url = fields.pc_url;
|
|
1790
|
+
if (fields.ios_url) multi.ios_url = fields.ios_url;
|
|
1791
|
+
if (fields.android_url) multi.android_url = fields.android_url;
|
|
1792
|
+
return multi;
|
|
1793
|
+
}
|
|
1742
1794
|
function convertProperty(property, ownerTag, ctx) {
|
|
1743
1795
|
const out = {};
|
|
1744
1796
|
const siblings = {
|
|
@@ -1881,15 +1933,17 @@ function convertField(rawKey, rawValue, ownerTag, ctx, siblings = {}) {
|
|
|
1881
1933
|
if (!isRecord3(a)) continue;
|
|
1882
1934
|
const inner = isRecord3(a.action) ? a.action : {};
|
|
1883
1935
|
const t = typeof a.type === "string" ? a.type : void 0;
|
|
1884
|
-
if (t
|
|
1936
|
+
if (t !== "open_url") continue;
|
|
1937
|
+
const fields = projectOpenUrlFields(inner);
|
|
1938
|
+
if (fields) openUrls.push(fields);
|
|
1885
1939
|
}
|
|
1886
1940
|
if (openUrls.length === 0) return DROP;
|
|
1887
1941
|
if (siblings.buttonActionType === "link") {
|
|
1888
|
-
return ["multi_url",
|
|
1942
|
+
return ["multi_url", openUrlFieldsToMultiUrl(openUrls[0])];
|
|
1889
1943
|
}
|
|
1890
1944
|
return [
|
|
1891
1945
|
"behaviors",
|
|
1892
|
-
openUrls.map((
|
|
1946
|
+
openUrls.map((fields) => ({ type: "open_url", ...fields }))
|
|
1893
1947
|
];
|
|
1894
1948
|
}
|
|
1895
1949
|
if (ownerTag === "interactive_container" && key === "actions" && Array.isArray(rawValue)) {
|
|
@@ -1897,8 +1951,9 @@ function convertField(rawKey, rawValue, ownerTag, ctx, siblings = {}) {
|
|
|
1897
1951
|
if (!isRecord3(a)) return void 0;
|
|
1898
1952
|
const inner = isRecord3(a.action) ? a.action : {};
|
|
1899
1953
|
const t = typeof a.type === "string" ? a.type : void 0;
|
|
1900
|
-
if (t === "open_url"
|
|
1901
|
-
|
|
1954
|
+
if (t === "open_url") {
|
|
1955
|
+
const fields = projectOpenUrlFields(inner);
|
|
1956
|
+
return fields ? { type: "open_url", ...fields } : void 0;
|
|
1902
1957
|
}
|
|
1903
1958
|
if (t === "callback") {
|
|
1904
1959
|
return { type: "callback", value: inner.value ?? {} };
|
package/dist/index.js
CHANGED
|
@@ -997,7 +997,11 @@ function behaviorsToActions(behaviors) {
|
|
|
997
997
|
for (const b of behaviors) {
|
|
998
998
|
if (!isRecord2(b)) continue;
|
|
999
999
|
const type = typeof b.type === "string" ? b.type : "open_url";
|
|
1000
|
-
|
|
1000
|
+
const action = { url: normalizeUrl(b.default_url) };
|
|
1001
|
+
if (typeof b.pc_url === "string" && b.pc_url) action.pcURL = b.pc_url;
|
|
1002
|
+
if (typeof b.ios_url === "string" && b.ios_url) action.iosURL = b.ios_url;
|
|
1003
|
+
if (typeof b.android_url === "string" && b.android_url) action.androidURL = b.android_url;
|
|
1004
|
+
out.push({ type, action });
|
|
1001
1005
|
}
|
|
1002
1006
|
return out;
|
|
1003
1007
|
}
|
|
@@ -1726,7 +1730,14 @@ function unwrap(node, ctx) {
|
|
|
1726
1730
|
const tp = isRecord3(text.property) ? text.property : {};
|
|
1727
1731
|
const content = typeof tp.content === "string" ? tp.content : "";
|
|
1728
1732
|
const textAlign = typeof tp.textAlign === "string" ? tp.textAlign : "left";
|
|
1729
|
-
|
|
1733
|
+
const outText = { tag: "plain_text", content, text_align: textAlign };
|
|
1734
|
+
const ts = isRecord3(tp.textStyle) ? tp.textStyle : void 0;
|
|
1735
|
+
if (ts && typeof ts.size === "string") outText.text_size = ts.size;
|
|
1736
|
+
const { color } = resolveInlineStyle(ts, ctx);
|
|
1737
|
+
if (color) outText.text_color = color;
|
|
1738
|
+
out.text = outText;
|
|
1739
|
+
if (isRecord3(property.margin) && hasSide(property.margin)) out.margin = formatBox(property.margin);
|
|
1740
|
+
else if (typeof property.margin === "string") out.margin = property.margin;
|
|
1730
1741
|
if (isRecord3(property.icon)) {
|
|
1731
1742
|
out.icon = unwrap(property.icon, ctx);
|
|
1732
1743
|
}
|
|
@@ -1737,6 +1748,47 @@ function unwrap(node, ctx) {
|
|
|
1737
1748
|
return tag ? { tag, ...converted } : converted;
|
|
1738
1749
|
}
|
|
1739
1750
|
var DROP = /* @__PURE__ */ Symbol("drop");
|
|
1751
|
+
function projectOpenUrlFields(actionInner) {
|
|
1752
|
+
let bag;
|
|
1753
|
+
let defaultUrl;
|
|
1754
|
+
if (typeof actionInner.url === "string") {
|
|
1755
|
+
defaultUrl = actionInner.url;
|
|
1756
|
+
bag = actionInner;
|
|
1757
|
+
} else if (isRecord3(actionInner.url)) {
|
|
1758
|
+
bag = actionInner.url;
|
|
1759
|
+
defaultUrl = typeof bag.url === "string" ? bag.url : void 0;
|
|
1760
|
+
} else if (isRecord3(actionInner.multiURL)) {
|
|
1761
|
+
bag = actionInner.multiURL;
|
|
1762
|
+
defaultUrl = typeof bag.url === "string" ? bag.url : void 0;
|
|
1763
|
+
} else if (isRecord3(actionInner.multi_url)) {
|
|
1764
|
+
bag = actionInner.multi_url;
|
|
1765
|
+
defaultUrl = typeof bag.url === "string" ? bag.url : void 0;
|
|
1766
|
+
}
|
|
1767
|
+
if (!defaultUrl) return void 0;
|
|
1768
|
+
const pick = (...keys) => {
|
|
1769
|
+
if (!bag) return void 0;
|
|
1770
|
+
for (const k of keys) {
|
|
1771
|
+
const v = bag[k];
|
|
1772
|
+
if (typeof v === "string" && v.length > 0) return v;
|
|
1773
|
+
}
|
|
1774
|
+
return void 0;
|
|
1775
|
+
};
|
|
1776
|
+
const out = { default_url: defaultUrl };
|
|
1777
|
+
const pc = pick("pcURL", "pc_url");
|
|
1778
|
+
const ios = pick("iosURL", "ios_url");
|
|
1779
|
+
const android = pick("androidURL", "android_url");
|
|
1780
|
+
if (pc) out.pc_url = pc;
|
|
1781
|
+
if (ios) out.ios_url = ios;
|
|
1782
|
+
if (android) out.android_url = android;
|
|
1783
|
+
return out;
|
|
1784
|
+
}
|
|
1785
|
+
function openUrlFieldsToMultiUrl(fields) {
|
|
1786
|
+
const multi = { url: fields.default_url };
|
|
1787
|
+
if (fields.pc_url) multi.pc_url = fields.pc_url;
|
|
1788
|
+
if (fields.ios_url) multi.ios_url = fields.ios_url;
|
|
1789
|
+
if (fields.android_url) multi.android_url = fields.android_url;
|
|
1790
|
+
return multi;
|
|
1791
|
+
}
|
|
1740
1792
|
function convertProperty(property, ownerTag, ctx) {
|
|
1741
1793
|
const out = {};
|
|
1742
1794
|
const siblings = {
|
|
@@ -1879,15 +1931,17 @@ function convertField(rawKey, rawValue, ownerTag, ctx, siblings = {}) {
|
|
|
1879
1931
|
if (!isRecord3(a)) continue;
|
|
1880
1932
|
const inner = isRecord3(a.action) ? a.action : {};
|
|
1881
1933
|
const t = typeof a.type === "string" ? a.type : void 0;
|
|
1882
|
-
if (t
|
|
1934
|
+
if (t !== "open_url") continue;
|
|
1935
|
+
const fields = projectOpenUrlFields(inner);
|
|
1936
|
+
if (fields) openUrls.push(fields);
|
|
1883
1937
|
}
|
|
1884
1938
|
if (openUrls.length === 0) return DROP;
|
|
1885
1939
|
if (siblings.buttonActionType === "link") {
|
|
1886
|
-
return ["multi_url",
|
|
1940
|
+
return ["multi_url", openUrlFieldsToMultiUrl(openUrls[0])];
|
|
1887
1941
|
}
|
|
1888
1942
|
return [
|
|
1889
1943
|
"behaviors",
|
|
1890
|
-
openUrls.map((
|
|
1944
|
+
openUrls.map((fields) => ({ type: "open_url", ...fields }))
|
|
1891
1945
|
];
|
|
1892
1946
|
}
|
|
1893
1947
|
if (ownerTag === "interactive_container" && key === "actions" && Array.isArray(rawValue)) {
|
|
@@ -1895,8 +1949,9 @@ function convertField(rawKey, rawValue, ownerTag, ctx, siblings = {}) {
|
|
|
1895
1949
|
if (!isRecord3(a)) return void 0;
|
|
1896
1950
|
const inner = isRecord3(a.action) ? a.action : {};
|
|
1897
1951
|
const t = typeof a.type === "string" ? a.type : void 0;
|
|
1898
|
-
if (t === "open_url"
|
|
1899
|
-
|
|
1952
|
+
if (t === "open_url") {
|
|
1953
|
+
const fields = projectOpenUrlFields(inner);
|
|
1954
|
+
return fields ? { type: "open_url", ...fields } : void 0;
|
|
1900
1955
|
}
|
|
1901
1956
|
if (t === "callback") {
|
|
1902
1957
|
return { type: "callback", value: inner.value ?? {} };
|
package/dist/raw-to-dsl.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"raw-to-dsl.d.ts","sourceRoot":"","sources":["../src/raw-to-dsl.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AAwBH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAIzD;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,OAAO,GAAG,OAAO,CAcvD;
|
|
1
|
+
{"version":3,"file":"raw-to-dsl.d.ts","sourceRoot":"","sources":["../src/raw-to-dsl.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AAwBH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAIzD;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,OAAO,GAAG,OAAO,CAcvD;AA8rDD;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CA8C9C;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAGnF"}
|