@open-feishu-card/adapter 0.3.12 → 0.3.13

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 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
- out.push({ type, action: { url: normalizeUrl(b.default_url) } });
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
  }
@@ -1739,6 +1743,47 @@ function unwrap(node, ctx) {
1739
1743
  return tag ? { tag, ...converted } : converted;
1740
1744
  }
1741
1745
  var DROP = /* @__PURE__ */ Symbol("drop");
1746
+ function projectOpenUrlFields(actionInner) {
1747
+ let bag;
1748
+ let defaultUrl;
1749
+ if (typeof actionInner.url === "string") {
1750
+ defaultUrl = actionInner.url;
1751
+ bag = actionInner;
1752
+ } else if (isRecord3(actionInner.url)) {
1753
+ bag = actionInner.url;
1754
+ defaultUrl = typeof bag.url === "string" ? bag.url : void 0;
1755
+ } else if (isRecord3(actionInner.multiURL)) {
1756
+ bag = actionInner.multiURL;
1757
+ defaultUrl = typeof bag.url === "string" ? bag.url : void 0;
1758
+ } else if (isRecord3(actionInner.multi_url)) {
1759
+ bag = actionInner.multi_url;
1760
+ defaultUrl = typeof bag.url === "string" ? bag.url : void 0;
1761
+ }
1762
+ if (!defaultUrl) return void 0;
1763
+ const pick = (...keys) => {
1764
+ if (!bag) return void 0;
1765
+ for (const k of keys) {
1766
+ const v = bag[k];
1767
+ if (typeof v === "string" && v.length > 0) return v;
1768
+ }
1769
+ return void 0;
1770
+ };
1771
+ const out = { default_url: defaultUrl };
1772
+ const pc = pick("pcURL", "pc_url");
1773
+ const ios = pick("iosURL", "ios_url");
1774
+ const android = pick("androidURL", "android_url");
1775
+ if (pc) out.pc_url = pc;
1776
+ if (ios) out.ios_url = ios;
1777
+ if (android) out.android_url = android;
1778
+ return out;
1779
+ }
1780
+ function openUrlFieldsToMultiUrl(fields) {
1781
+ const multi = { url: fields.default_url };
1782
+ if (fields.pc_url) multi.pc_url = fields.pc_url;
1783
+ if (fields.ios_url) multi.ios_url = fields.ios_url;
1784
+ if (fields.android_url) multi.android_url = fields.android_url;
1785
+ return multi;
1786
+ }
1742
1787
  function convertProperty(property, ownerTag, ctx) {
1743
1788
  const out = {};
1744
1789
  const siblings = {
@@ -1881,15 +1926,17 @@ function convertField(rawKey, rawValue, ownerTag, ctx, siblings = {}) {
1881
1926
  if (!isRecord3(a)) continue;
1882
1927
  const inner = isRecord3(a.action) ? a.action : {};
1883
1928
  const t = typeof a.type === "string" ? a.type : void 0;
1884
- if (t === "open_url" && typeof inner.url === "string") openUrls.push(inner.url);
1929
+ if (t !== "open_url") continue;
1930
+ const fields = projectOpenUrlFields(inner);
1931
+ if (fields) openUrls.push(fields);
1885
1932
  }
1886
1933
  if (openUrls.length === 0) return DROP;
1887
1934
  if (siblings.buttonActionType === "link") {
1888
- return ["multi_url", { url: openUrls[0] }];
1935
+ return ["multi_url", openUrlFieldsToMultiUrl(openUrls[0])];
1889
1936
  }
1890
1937
  return [
1891
1938
  "behaviors",
1892
- openUrls.map((url) => ({ type: "open_url", default_url: url }))
1939
+ openUrls.map((fields) => ({ type: "open_url", ...fields }))
1893
1940
  ];
1894
1941
  }
1895
1942
  if (ownerTag === "interactive_container" && key === "actions" && Array.isArray(rawValue)) {
@@ -1897,8 +1944,9 @@ function convertField(rawKey, rawValue, ownerTag, ctx, siblings = {}) {
1897
1944
  if (!isRecord3(a)) return void 0;
1898
1945
  const inner = isRecord3(a.action) ? a.action : {};
1899
1946
  const t = typeof a.type === "string" ? a.type : void 0;
1900
- if (t === "open_url" && typeof inner.url === "string") {
1901
- return { type: "open_url", default_url: inner.url };
1947
+ if (t === "open_url") {
1948
+ const fields = projectOpenUrlFields(inner);
1949
+ return fields ? { type: "open_url", ...fields } : void 0;
1902
1950
  }
1903
1951
  if (t === "callback") {
1904
1952
  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
- out.push({ type, action: { url: normalizeUrl(b.default_url) } });
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
  }
@@ -1737,6 +1741,47 @@ function unwrap(node, ctx) {
1737
1741
  return tag ? { tag, ...converted } : converted;
1738
1742
  }
1739
1743
  var DROP = /* @__PURE__ */ Symbol("drop");
1744
+ function projectOpenUrlFields(actionInner) {
1745
+ let bag;
1746
+ let defaultUrl;
1747
+ if (typeof actionInner.url === "string") {
1748
+ defaultUrl = actionInner.url;
1749
+ bag = actionInner;
1750
+ } else if (isRecord3(actionInner.url)) {
1751
+ bag = actionInner.url;
1752
+ defaultUrl = typeof bag.url === "string" ? bag.url : void 0;
1753
+ } else if (isRecord3(actionInner.multiURL)) {
1754
+ bag = actionInner.multiURL;
1755
+ defaultUrl = typeof bag.url === "string" ? bag.url : void 0;
1756
+ } else if (isRecord3(actionInner.multi_url)) {
1757
+ bag = actionInner.multi_url;
1758
+ defaultUrl = typeof bag.url === "string" ? bag.url : void 0;
1759
+ }
1760
+ if (!defaultUrl) return void 0;
1761
+ const pick = (...keys) => {
1762
+ if (!bag) return void 0;
1763
+ for (const k of keys) {
1764
+ const v = bag[k];
1765
+ if (typeof v === "string" && v.length > 0) return v;
1766
+ }
1767
+ return void 0;
1768
+ };
1769
+ const out = { default_url: defaultUrl };
1770
+ const pc = pick("pcURL", "pc_url");
1771
+ const ios = pick("iosURL", "ios_url");
1772
+ const android = pick("androidURL", "android_url");
1773
+ if (pc) out.pc_url = pc;
1774
+ if (ios) out.ios_url = ios;
1775
+ if (android) out.android_url = android;
1776
+ return out;
1777
+ }
1778
+ function openUrlFieldsToMultiUrl(fields) {
1779
+ const multi = { url: fields.default_url };
1780
+ if (fields.pc_url) multi.pc_url = fields.pc_url;
1781
+ if (fields.ios_url) multi.ios_url = fields.ios_url;
1782
+ if (fields.android_url) multi.android_url = fields.android_url;
1783
+ return multi;
1784
+ }
1740
1785
  function convertProperty(property, ownerTag, ctx) {
1741
1786
  const out = {};
1742
1787
  const siblings = {
@@ -1879,15 +1924,17 @@ function convertField(rawKey, rawValue, ownerTag, ctx, siblings = {}) {
1879
1924
  if (!isRecord3(a)) continue;
1880
1925
  const inner = isRecord3(a.action) ? a.action : {};
1881
1926
  const t = typeof a.type === "string" ? a.type : void 0;
1882
- if (t === "open_url" && typeof inner.url === "string") openUrls.push(inner.url);
1927
+ if (t !== "open_url") continue;
1928
+ const fields = projectOpenUrlFields(inner);
1929
+ if (fields) openUrls.push(fields);
1883
1930
  }
1884
1931
  if (openUrls.length === 0) return DROP;
1885
1932
  if (siblings.buttonActionType === "link") {
1886
- return ["multi_url", { url: openUrls[0] }];
1933
+ return ["multi_url", openUrlFieldsToMultiUrl(openUrls[0])];
1887
1934
  }
1888
1935
  return [
1889
1936
  "behaviors",
1890
- openUrls.map((url) => ({ type: "open_url", default_url: url }))
1937
+ openUrls.map((fields) => ({ type: "open_url", ...fields }))
1891
1938
  ];
1892
1939
  }
1893
1940
  if (ownerTag === "interactive_container" && key === "actions" && Array.isArray(rawValue)) {
@@ -1895,8 +1942,9 @@ function convertField(rawKey, rawValue, ownerTag, ctx, siblings = {}) {
1895
1942
  if (!isRecord3(a)) return void 0;
1896
1943
  const inner = isRecord3(a.action) ? a.action : {};
1897
1944
  const t = typeof a.type === "string" ? a.type : void 0;
1898
- if (t === "open_url" && typeof inner.url === "string") {
1899
- return { type: "open_url", default_url: inner.url };
1945
+ if (t === "open_url") {
1946
+ const fields = projectOpenUrlFields(inner);
1947
+ return fields ? { type: "open_url", ...fields } : void 0;
1900
1948
  }
1901
1949
  if (t === "callback") {
1902
1950
  return { type: "callback", value: inner.value ?? {} };
@@ -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;AA6mDD;;;;;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"}
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;AAorDD;;;;;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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-feishu-card/adapter",
3
- "version": "0.3.12",
3
+ "version": "0.3.13",
4
4
  "description": "公开 DSL 与飞书内部 RAW JSON 的双向适配器;raw→DSL 对齐 feishu-raw-card-to-dsl",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",