@open-feishu-card/adapter 0.3.15 → 0.3.16

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
@@ -768,6 +768,14 @@ function convertNode(node, colors) {
768
768
  if (isRecord2(node) && typeof node.tag === "string") return convertEl(node, colors);
769
769
  return node;
770
770
  }
771
+ var PUBLIC_ELEMENT_ID_RE = /^[A-Za-z][A-Za-z0-9_]{0,19}$/;
772
+ function withRawElementId(el, raw) {
773
+ const eid = typeof el.element_id === "string" ? el.element_id : void 0;
774
+ if (eid && PUBLIC_ELEMENT_ID_RE.test(eid)) {
775
+ raw.id = eid;
776
+ }
777
+ return raw;
778
+ }
771
779
  function convertEl(el, colors) {
772
780
  const tag = String(el.tag);
773
781
  if (tag === "person") {
@@ -776,13 +784,16 @@ function convertEl(el, colors) {
776
784
  property.pillShaped = true;
777
785
  delete property.style;
778
786
  }
779
- return { tag: "person_v1", property };
787
+ return withRawElementId(el, { tag: "person_v1", property });
780
788
  }
781
789
  if (tag === "avatar") {
782
- return { tag: "avatar", property: buildProperty(el, "avatar", colors) };
790
+ return withRawElementId(el, { tag: "avatar", property: buildProperty(el, "avatar", colors) });
783
791
  }
784
792
  if (tag === "picker_date") {
785
- return { tag: "date_picker", property: buildProperty(el, "date_picker", colors) };
793
+ return withRawElementId(el, {
794
+ tag: "date_picker",
795
+ property: buildProperty(el, "date_picker", colors)
796
+ });
786
797
  }
787
798
  if (tag === "markdown" || tag === "lark_md") {
788
799
  const property = buildProperty(el, "markdown", colors);
@@ -794,10 +805,10 @@ function convertEl(el, colors) {
794
805
  }
795
806
  delete property.content;
796
807
  delete property.font_color;
797
- return { tag: "markdown", property };
808
+ return withRawElementId(el, { tag: "markdown", property });
798
809
  }
799
810
  if (tag === "table") {
800
- return { tag, property: convertTableProperty(el, colors) };
811
+ return withRawElementId(el, { tag, property: convertTableProperty(el, colors) });
801
812
  }
802
813
  if (tag === "audio" || tag === "video") {
803
814
  const property = buildProperty(el, tag, colors);
@@ -816,9 +827,9 @@ function convertEl(el, colors) {
816
827
  delete property.image_key;
817
828
  delete property.cover_image_key;
818
829
  }
819
- return { tag, property };
830
+ return withRawElementId(el, { tag, property });
820
831
  }
821
- return { tag, property: buildProperty(el, tag, colors) };
832
+ return withRawElementId(el, { tag, property: buildProperty(el, tag, colors) });
822
833
  }
823
834
  function convertTableProperty(el, colors) {
824
835
  const property = buildProperty(el, "table", colors);
@@ -857,7 +868,14 @@ function convertTableProperty(el, colors) {
857
868
  function buildProperty(el, tag, colors) {
858
869
  const property = {};
859
870
  for (const [k, v] of Object.entries(el)) {
860
- if (k === "tag" || k === "id") continue;
871
+ if (k === "tag" || k === "id" || k === "element_id") continue;
872
+ if ((tag === "column_set" || tag === "column") && k === "action" && isRecord2(v)) {
873
+ const multi = isRecord2(v.multi_url) ? v.multi_url : void 0;
874
+ if (multi && (typeof multi.url === "string" || typeof multi.default_url === "string")) {
875
+ property.actions = [multiUrlToOpenUrlAction(multi)];
876
+ }
877
+ continue;
878
+ }
861
879
  if ((k === "background_style" || k === "backgroundStyle") && (tag === "column" || tag === "column_set" || tag === "interactive_container")) {
862
880
  const renamed = renameKey(k);
863
881
  property[renamed] = v;
@@ -1007,6 +1025,16 @@ function behaviorsToActions(behaviors) {
1007
1025
  }
1008
1026
  return out;
1009
1027
  }
1028
+ function multiUrlToOpenUrlAction(multi) {
1029
+ const url = typeof multi.url === "string" ? multi.url : typeof multi.default_url === "string" ? multi.default_url : "";
1030
+ const action = { url };
1031
+ if (typeof multi.pc_url === "string" && multi.pc_url) action.pcURL = multi.pc_url;
1032
+ if (typeof multi.ios_url === "string" && multi.ios_url) action.iosURL = multi.ios_url;
1033
+ if (typeof multi.android_url === "string" && multi.android_url) {
1034
+ action.androidURL = multi.android_url;
1035
+ }
1036
+ return { type: "open_url", action };
1037
+ }
1010
1038
  function normalizeUrl(v) {
1011
1039
  if (typeof v === "string") return v;
1012
1040
  if (isRecord2(v)) return v;
@@ -1492,7 +1520,23 @@ function convertBody2(node, ctx) {
1492
1520
  const property = isRecord3(node.property) ? node.property : node;
1493
1521
  return convertProperty(property, "body", ctx);
1494
1522
  }
1523
+ var PUBLIC_ELEMENT_ID_RE2 = /^[A-Za-z][A-Za-z0-9_]{0,19}$/;
1524
+ function isPublicElementId(id) {
1525
+ return PUBLIC_ELEMENT_ID_RE2.test(id);
1526
+ }
1527
+ function attachPublicElementId(node, result) {
1528
+ if (!isRecord3(result)) return result;
1529
+ if (typeof result.element_id === "string" && isPublicElementId(result.element_id)) {
1530
+ return result;
1531
+ }
1532
+ const rawId = typeof node.id === "string" ? node.id : typeof node.element_id === "string" ? node.element_id : void 0;
1533
+ if (!rawId || !isPublicElementId(rawId)) return result;
1534
+ return { ...result, element_id: rawId };
1535
+ }
1495
1536
  function unwrap(node, ctx) {
1537
+ return attachPublicElementId(node, unwrapInner(node, ctx));
1538
+ }
1539
+ function unwrapInner(node, ctx) {
1496
1540
  const tag = typeof node.tag === "string" ? node.tag : void 0;
1497
1541
  const property = isRecord3(node.property) ? node.property : {};
1498
1542
  if (tag === "markdown") return rebuildMarkdown(property, ctx);
@@ -1914,6 +1958,17 @@ function convertField(rawKey, rawValue, ownerTag, ctx, siblings = {}) {
1914
1958
  if (behaviors.length === 0) return DROP;
1915
1959
  return ["behaviors", behaviors];
1916
1960
  }
1961
+ if ((ownerTag === "column_set" || ownerTag === "column") && key === "actions" && Array.isArray(rawValue)) {
1962
+ for (const a of rawValue) {
1963
+ if (!isRecord3(a)) continue;
1964
+ if (a.type !== "open_url") continue;
1965
+ const inner = isRecord3(a.action) ? a.action : {};
1966
+ const fields = projectOpenUrlFields(inner);
1967
+ if (!fields) continue;
1968
+ return ["action", { multi_url: openUrlFieldsToMultiUrl(fields) }];
1969
+ }
1970
+ return DROP;
1971
+ }
1917
1972
  if (key === "border" && isRecord3(rawValue)) {
1918
1973
  const b = rawValue;
1919
1974
  const out = {};
package/dist/index.js CHANGED
@@ -766,6 +766,14 @@ function convertNode(node, colors) {
766
766
  if (isRecord2(node) && typeof node.tag === "string") return convertEl(node, colors);
767
767
  return node;
768
768
  }
769
+ var PUBLIC_ELEMENT_ID_RE = /^[A-Za-z][A-Za-z0-9_]{0,19}$/;
770
+ function withRawElementId(el, raw) {
771
+ const eid = typeof el.element_id === "string" ? el.element_id : void 0;
772
+ if (eid && PUBLIC_ELEMENT_ID_RE.test(eid)) {
773
+ raw.id = eid;
774
+ }
775
+ return raw;
776
+ }
769
777
  function convertEl(el, colors) {
770
778
  const tag = String(el.tag);
771
779
  if (tag === "person") {
@@ -774,13 +782,16 @@ function convertEl(el, colors) {
774
782
  property.pillShaped = true;
775
783
  delete property.style;
776
784
  }
777
- return { tag: "person_v1", property };
785
+ return withRawElementId(el, { tag: "person_v1", property });
778
786
  }
779
787
  if (tag === "avatar") {
780
- return { tag: "avatar", property: buildProperty(el, "avatar", colors) };
788
+ return withRawElementId(el, { tag: "avatar", property: buildProperty(el, "avatar", colors) });
781
789
  }
782
790
  if (tag === "picker_date") {
783
- return { tag: "date_picker", property: buildProperty(el, "date_picker", colors) };
791
+ return withRawElementId(el, {
792
+ tag: "date_picker",
793
+ property: buildProperty(el, "date_picker", colors)
794
+ });
784
795
  }
785
796
  if (tag === "markdown" || tag === "lark_md") {
786
797
  const property = buildProperty(el, "markdown", colors);
@@ -792,10 +803,10 @@ function convertEl(el, colors) {
792
803
  }
793
804
  delete property.content;
794
805
  delete property.font_color;
795
- return { tag: "markdown", property };
806
+ return withRawElementId(el, { tag: "markdown", property });
796
807
  }
797
808
  if (tag === "table") {
798
- return { tag, property: convertTableProperty(el, colors) };
809
+ return withRawElementId(el, { tag, property: convertTableProperty(el, colors) });
799
810
  }
800
811
  if (tag === "audio" || tag === "video") {
801
812
  const property = buildProperty(el, tag, colors);
@@ -814,9 +825,9 @@ function convertEl(el, colors) {
814
825
  delete property.image_key;
815
826
  delete property.cover_image_key;
816
827
  }
817
- return { tag, property };
828
+ return withRawElementId(el, { tag, property });
818
829
  }
819
- return { tag, property: buildProperty(el, tag, colors) };
830
+ return withRawElementId(el, { tag, property: buildProperty(el, tag, colors) });
820
831
  }
821
832
  function convertTableProperty(el, colors) {
822
833
  const property = buildProperty(el, "table", colors);
@@ -855,7 +866,14 @@ function convertTableProperty(el, colors) {
855
866
  function buildProperty(el, tag, colors) {
856
867
  const property = {};
857
868
  for (const [k, v] of Object.entries(el)) {
858
- if (k === "tag" || k === "id") continue;
869
+ if (k === "tag" || k === "id" || k === "element_id") continue;
870
+ if ((tag === "column_set" || tag === "column") && k === "action" && isRecord2(v)) {
871
+ const multi = isRecord2(v.multi_url) ? v.multi_url : void 0;
872
+ if (multi && (typeof multi.url === "string" || typeof multi.default_url === "string")) {
873
+ property.actions = [multiUrlToOpenUrlAction(multi)];
874
+ }
875
+ continue;
876
+ }
859
877
  if ((k === "background_style" || k === "backgroundStyle") && (tag === "column" || tag === "column_set" || tag === "interactive_container")) {
860
878
  const renamed = renameKey(k);
861
879
  property[renamed] = v;
@@ -1005,6 +1023,16 @@ function behaviorsToActions(behaviors) {
1005
1023
  }
1006
1024
  return out;
1007
1025
  }
1026
+ function multiUrlToOpenUrlAction(multi) {
1027
+ const url = typeof multi.url === "string" ? multi.url : typeof multi.default_url === "string" ? multi.default_url : "";
1028
+ const action = { url };
1029
+ if (typeof multi.pc_url === "string" && multi.pc_url) action.pcURL = multi.pc_url;
1030
+ if (typeof multi.ios_url === "string" && multi.ios_url) action.iosURL = multi.ios_url;
1031
+ if (typeof multi.android_url === "string" && multi.android_url) {
1032
+ action.androidURL = multi.android_url;
1033
+ }
1034
+ return { type: "open_url", action };
1035
+ }
1008
1036
  function normalizeUrl(v) {
1009
1037
  if (typeof v === "string") return v;
1010
1038
  if (isRecord2(v)) return v;
@@ -1490,7 +1518,23 @@ function convertBody2(node, ctx) {
1490
1518
  const property = isRecord3(node.property) ? node.property : node;
1491
1519
  return convertProperty(property, "body", ctx);
1492
1520
  }
1521
+ var PUBLIC_ELEMENT_ID_RE2 = /^[A-Za-z][A-Za-z0-9_]{0,19}$/;
1522
+ function isPublicElementId(id) {
1523
+ return PUBLIC_ELEMENT_ID_RE2.test(id);
1524
+ }
1525
+ function attachPublicElementId(node, result) {
1526
+ if (!isRecord3(result)) return result;
1527
+ if (typeof result.element_id === "string" && isPublicElementId(result.element_id)) {
1528
+ return result;
1529
+ }
1530
+ const rawId = typeof node.id === "string" ? node.id : typeof node.element_id === "string" ? node.element_id : void 0;
1531
+ if (!rawId || !isPublicElementId(rawId)) return result;
1532
+ return { ...result, element_id: rawId };
1533
+ }
1493
1534
  function unwrap(node, ctx) {
1535
+ return attachPublicElementId(node, unwrapInner(node, ctx));
1536
+ }
1537
+ function unwrapInner(node, ctx) {
1494
1538
  const tag = typeof node.tag === "string" ? node.tag : void 0;
1495
1539
  const property = isRecord3(node.property) ? node.property : {};
1496
1540
  if (tag === "markdown") return rebuildMarkdown(property, ctx);
@@ -1912,6 +1956,17 @@ function convertField(rawKey, rawValue, ownerTag, ctx, siblings = {}) {
1912
1956
  if (behaviors.length === 0) return DROP;
1913
1957
  return ["behaviors", behaviors];
1914
1958
  }
1959
+ if ((ownerTag === "column_set" || ownerTag === "column") && key === "actions" && Array.isArray(rawValue)) {
1960
+ for (const a of rawValue) {
1961
+ if (!isRecord3(a)) continue;
1962
+ if (a.type !== "open_url") continue;
1963
+ const inner = isRecord3(a.action) ? a.action : {};
1964
+ const fields = projectOpenUrlFields(inner);
1965
+ if (!fields) continue;
1966
+ return ["action", { multi_url: openUrlFieldsToMultiUrl(fields) }];
1967
+ }
1968
+ return DROP;
1969
+ }
1915
1970
  if (key === "border" && isRecord3(rawValue)) {
1916
1971
  const b = rawValue;
1917
1972
  const out = {};
@@ -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;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"}
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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-feishu-card/adapter",
3
- "version": "0.3.15",
3
+ "version": "0.3.16",
4
4
  "description": "公开 DSL 与飞书内部 RAW JSON 的双向适配器;raw→DSL 对齐 feishu-raw-card-to-dsl",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",