@open-feishu-card/adapter 0.3.16 → 0.3.17

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
@@ -1017,6 +1017,10 @@ function behaviorsToActions(behaviors) {
1017
1017
  for (const b of behaviors) {
1018
1018
  if (!isRecord2(b)) continue;
1019
1019
  const type = typeof b.type === "string" ? b.type : "open_url";
1020
+ if (type === "callback") {
1021
+ out.push({ type: "callback", action: { value: isRecord2(b.value) ? b.value : {} } });
1022
+ continue;
1023
+ }
1020
1024
  const action = { url: normalizeUrl(b.default_url) };
1021
1025
  if (typeof b.pc_url === "string" && b.pc_url) action.pcURL = b.pc_url;
1022
1026
  if (typeof b.ios_url === "string" && b.ios_url) action.iosURL = b.ios_url;
@@ -1923,23 +1927,26 @@ function convertField(rawKey, rawValue, ownerTag, ctx, siblings = {}) {
1923
1927
  }
1924
1928
  if (ownerTag === "button" && key === "action_type") return DROP;
1925
1929
  if (ownerTag === "button" && key === "actions" && Array.isArray(rawValue)) {
1926
- const openUrls = [];
1930
+ const behaviors = [];
1927
1931
  for (const a of rawValue) {
1928
1932
  if (!isRecord3(a)) continue;
1929
1933
  const inner = isRecord3(a.action) ? a.action : {};
1930
1934
  const t = typeof a.type === "string" ? a.type : void 0;
1935
+ if (t === "callback") {
1936
+ behaviors.push({ type: "callback", value: isRecord3(inner.value) ? inner.value : {} });
1937
+ continue;
1938
+ }
1931
1939
  if (t !== "open_url") continue;
1932
1940
  const fields = projectOpenUrlFields(inner);
1933
- if (fields) openUrls.push(fields);
1941
+ if (fields) behaviors.push({ type: "open_url", ...fields });
1934
1942
  }
1935
- if (openUrls.length === 0) return DROP;
1936
- if (siblings.buttonActionType === "link") {
1937
- return ["multi_url", openUrlFieldsToMultiUrl(openUrls[0])];
1943
+ if (behaviors.length === 0) return DROP;
1944
+ if (siblings.buttonActionType === "link" && behaviors.length === 1 && behaviors[0]?.type === "open_url") {
1945
+ const only = behaviors[0];
1946
+ const { type: _type, ...fields } = only;
1947
+ return ["multi_url", openUrlFieldsToMultiUrl(fields)];
1938
1948
  }
1939
- return [
1940
- "behaviors",
1941
- openUrls.map((fields) => ({ type: "open_url", ...fields }))
1942
- ];
1949
+ return ["behaviors", behaviors];
1943
1950
  }
1944
1951
  if (ownerTag === "interactive_container" && key === "actions" && Array.isArray(rawValue)) {
1945
1952
  const behaviors = rawValue.map((a) => {
package/dist/index.js CHANGED
@@ -1015,6 +1015,10 @@ function behaviorsToActions(behaviors) {
1015
1015
  for (const b of behaviors) {
1016
1016
  if (!isRecord2(b)) continue;
1017
1017
  const type = typeof b.type === "string" ? b.type : "open_url";
1018
+ if (type === "callback") {
1019
+ out.push({ type: "callback", action: { value: isRecord2(b.value) ? b.value : {} } });
1020
+ continue;
1021
+ }
1018
1022
  const action = { url: normalizeUrl(b.default_url) };
1019
1023
  if (typeof b.pc_url === "string" && b.pc_url) action.pcURL = b.pc_url;
1020
1024
  if (typeof b.ios_url === "string" && b.ios_url) action.iosURL = b.ios_url;
@@ -1921,23 +1925,26 @@ function convertField(rawKey, rawValue, ownerTag, ctx, siblings = {}) {
1921
1925
  }
1922
1926
  if (ownerTag === "button" && key === "action_type") return DROP;
1923
1927
  if (ownerTag === "button" && key === "actions" && Array.isArray(rawValue)) {
1924
- const openUrls = [];
1928
+ const behaviors = [];
1925
1929
  for (const a of rawValue) {
1926
1930
  if (!isRecord3(a)) continue;
1927
1931
  const inner = isRecord3(a.action) ? a.action : {};
1928
1932
  const t = typeof a.type === "string" ? a.type : void 0;
1933
+ if (t === "callback") {
1934
+ behaviors.push({ type: "callback", value: isRecord3(inner.value) ? inner.value : {} });
1935
+ continue;
1936
+ }
1929
1937
  if (t !== "open_url") continue;
1930
1938
  const fields = projectOpenUrlFields(inner);
1931
- if (fields) openUrls.push(fields);
1939
+ if (fields) behaviors.push({ type: "open_url", ...fields });
1932
1940
  }
1933
- if (openUrls.length === 0) return DROP;
1934
- if (siblings.buttonActionType === "link") {
1935
- return ["multi_url", openUrlFieldsToMultiUrl(openUrls[0])];
1941
+ if (behaviors.length === 0) return DROP;
1942
+ if (siblings.buttonActionType === "link" && behaviors.length === 1 && behaviors[0]?.type === "open_url") {
1943
+ const only = behaviors[0];
1944
+ const { type: _type, ...fields } = only;
1945
+ return ["multi_url", openUrlFieldsToMultiUrl(fields)];
1936
1946
  }
1937
- return [
1938
- "behaviors",
1939
- openUrls.map((fields) => ({ type: "open_url", ...fields }))
1940
- ];
1947
+ return ["behaviors", behaviors];
1941
1948
  }
1942
1949
  if (ownerTag === "interactive_container" && key === "actions" && Array.isArray(rawValue)) {
1943
1950
  const behaviors = rawValue.map((a) => {
@@ -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;AAqvDD;;;;;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;AA2vDD;;;;;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.16",
3
+ "version": "0.3.17",
4
4
  "description": "公开 DSL 与飞书内部 RAW JSON 的双向适配器;raw→DSL 对齐 feishu-raw-card-to-dsl",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -22,7 +22,7 @@
22
22
  "tsx": "^4.19.3",
23
23
  "typescript": "^7.0.2",
24
24
  "vitest": "^2.1.9",
25
- "@open-feishu-card/schema": "0.1.5"
25
+ "@open-feishu-card/schema": "0.1.6"
26
26
  },
27
27
  "license": "MIT",
28
28
  "publishConfig": {