@open-feishu-card/adapter 0.3.0 → 0.3.1

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
@@ -642,6 +642,10 @@ function convertHeader(header) {
642
642
  const property = {};
643
643
  for (const [k, v] of Object.entries(header)) {
644
644
  if (k === "tag") continue;
645
+ if (k === "title" || k === "subtitle") {
646
+ property[k] = wrapHeaderText(v);
647
+ continue;
648
+ }
645
649
  if (TEXT_LEAF_KEYS.has(k)) {
646
650
  property[k] = wrapTextLeaf(v);
647
651
  continue;
@@ -806,6 +810,22 @@ function wrapTextLeaf(v) {
806
810
  }
807
811
  return { tag: "plain_text", property: { content: "" } };
808
812
  }
813
+ function wrapHeaderText(v) {
814
+ if (typeof v === "string") return { tag: "plain_text", property: { content: v } };
815
+ if (!isRecord(v)) return { tag: "plain_text", property: { content: "" } };
816
+ const tag = typeof v.tag === "string" ? v.tag : "plain_text";
817
+ const content = typeof v.content === "string" ? v.content : "";
818
+ if (tag === "lark_md" || tag === "markdown") {
819
+ return {
820
+ tag: "markdown",
821
+ property: {
822
+ elements: parseMarkdown(content),
823
+ originTag: "lark_md"
824
+ }
825
+ };
826
+ }
827
+ return wrapTextLeaf(v);
828
+ }
809
829
  function behaviorsToActions(behaviors) {
810
830
  const out = [];
811
831
  for (const b of behaviors) {
@@ -962,10 +982,32 @@ function convertConfig(_node) {
962
982
  return { update_multi: true };
963
983
  }
964
984
  function convertHeader2(node, ctx) {
965
- const property = isRecord2(node.property) ? node.property : {};
985
+ const property = isRecord2(node.property) ? node.property : node;
966
986
  const out = convertProperty(property, "header", ctx);
987
+ delete out.tag;
967
988
  return out;
968
989
  }
990
+ function convertHeaderText(rawValue, ctx) {
991
+ const tag = typeof rawValue.tag === "string" ? rawValue.tag : "";
992
+ const wrapped = isRecord2(rawValue.property);
993
+ const property = wrapped ? rawValue.property : rawValue;
994
+ if (tag === "plain_text") {
995
+ const content = typeof property.content === "string" ? property.content : "";
996
+ return { tag: "plain_text", content };
997
+ }
998
+ if (tag === "markdown" || tag === "lark_md") {
999
+ if (wrapped && Array.isArray(property.elements)) {
1000
+ const rebuilt = rebuildMarkdown(property, ctx);
1001
+ return { tag: "lark_md", content: typeof rebuilt.content === "string" ? rebuilt.content : "" };
1002
+ }
1003
+ const content = typeof property.content === "string" ? property.content : "";
1004
+ return { tag: "lark_md", content };
1005
+ }
1006
+ if (!wrapped && typeof rawValue.content === "string" && !tag) {
1007
+ return { tag: "plain_text", content: rawValue.content };
1008
+ }
1009
+ return void 0;
1010
+ }
969
1011
  function convertBody2(node, ctx) {
970
1012
  const property = isRecord2(node.property) ? node.property : node;
971
1013
  return convertProperty(property, "body", ctx);
@@ -1264,6 +1306,10 @@ function convertField(rawKey, rawValue, ownerTag, ctx, siblings = {}) {
1264
1306
  const p = isRecord2(rawValue.property) ? rawValue.property : {};
1265
1307
  return [key, { tag: "plain_text", content: typeof p.content === "string" ? p.content : "" }];
1266
1308
  }
1309
+ if (ownerTag === "header" && (key === "title" || key === "subtitle") && isRecord2(rawValue)) {
1310
+ const headerText = convertHeaderText(rawValue, ctx);
1311
+ if (headerText) return [key, headerText];
1312
+ }
1267
1313
  if (ownerTag === "header" && key === "ud_icon" && isRecord2(rawValue) && rawValue.tag === "ud_icon") {
1268
1314
  const p = isRecord2(rawValue.property) ? rawValue.property : {};
1269
1315
  const token = typeof p.token === "string" ? p.token : void 0;
package/dist/index.js CHANGED
@@ -640,6 +640,10 @@ function convertHeader(header) {
640
640
  const property = {};
641
641
  for (const [k, v] of Object.entries(header)) {
642
642
  if (k === "tag") continue;
643
+ if (k === "title" || k === "subtitle") {
644
+ property[k] = wrapHeaderText(v);
645
+ continue;
646
+ }
643
647
  if (TEXT_LEAF_KEYS.has(k)) {
644
648
  property[k] = wrapTextLeaf(v);
645
649
  continue;
@@ -804,6 +808,22 @@ function wrapTextLeaf(v) {
804
808
  }
805
809
  return { tag: "plain_text", property: { content: "" } };
806
810
  }
811
+ function wrapHeaderText(v) {
812
+ if (typeof v === "string") return { tag: "plain_text", property: { content: v } };
813
+ if (!isRecord(v)) return { tag: "plain_text", property: { content: "" } };
814
+ const tag = typeof v.tag === "string" ? v.tag : "plain_text";
815
+ const content = typeof v.content === "string" ? v.content : "";
816
+ if (tag === "lark_md" || tag === "markdown") {
817
+ return {
818
+ tag: "markdown",
819
+ property: {
820
+ elements: parseMarkdown(content),
821
+ originTag: "lark_md"
822
+ }
823
+ };
824
+ }
825
+ return wrapTextLeaf(v);
826
+ }
807
827
  function behaviorsToActions(behaviors) {
808
828
  const out = [];
809
829
  for (const b of behaviors) {
@@ -960,10 +980,32 @@ function convertConfig(_node) {
960
980
  return { update_multi: true };
961
981
  }
962
982
  function convertHeader2(node, ctx) {
963
- const property = isRecord2(node.property) ? node.property : {};
983
+ const property = isRecord2(node.property) ? node.property : node;
964
984
  const out = convertProperty(property, "header", ctx);
985
+ delete out.tag;
965
986
  return out;
966
987
  }
988
+ function convertHeaderText(rawValue, ctx) {
989
+ const tag = typeof rawValue.tag === "string" ? rawValue.tag : "";
990
+ const wrapped = isRecord2(rawValue.property);
991
+ const property = wrapped ? rawValue.property : rawValue;
992
+ if (tag === "plain_text") {
993
+ const content = typeof property.content === "string" ? property.content : "";
994
+ return { tag: "plain_text", content };
995
+ }
996
+ if (tag === "markdown" || tag === "lark_md") {
997
+ if (wrapped && Array.isArray(property.elements)) {
998
+ const rebuilt = rebuildMarkdown(property, ctx);
999
+ return { tag: "lark_md", content: typeof rebuilt.content === "string" ? rebuilt.content : "" };
1000
+ }
1001
+ const content = typeof property.content === "string" ? property.content : "";
1002
+ return { tag: "lark_md", content };
1003
+ }
1004
+ if (!wrapped && typeof rawValue.content === "string" && !tag) {
1005
+ return { tag: "plain_text", content: rawValue.content };
1006
+ }
1007
+ return void 0;
1008
+ }
967
1009
  function convertBody2(node, ctx) {
968
1010
  const property = isRecord2(node.property) ? node.property : node;
969
1011
  return convertProperty(property, "body", ctx);
@@ -1262,6 +1304,10 @@ function convertField(rawKey, rawValue, ownerTag, ctx, siblings = {}) {
1262
1304
  const p = isRecord2(rawValue.property) ? rawValue.property : {};
1263
1305
  return [key, { tag: "plain_text", content: typeof p.content === "string" ? p.content : "" }];
1264
1306
  }
1307
+ if (ownerTag === "header" && (key === "title" || key === "subtitle") && isRecord2(rawValue)) {
1308
+ const headerText = convertHeaderText(rawValue, ctx);
1309
+ if (headerText) return [key, headerText];
1310
+ }
1265
1311
  if (ownerTag === "header" && key === "ud_icon" && isRecord2(rawValue) && rawValue.tag === "ud_icon") {
1266
1312
  const p = isRecord2(rawValue.property) ? rawValue.property : {};
1267
1313
  const token = typeof p.token === "string" ? p.token : void 0;
@@ -1 +1 @@
1
- {"version":3,"file":"raw-to-dsl.d.ts","sourceRoot":"","sources":["../src/raw-to-dsl.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AAWH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAIzD;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,OAAO,GAAG,OAAO,CAcvD;AAo9CD;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CA8C9C;AAED;;;;GAIG;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;AAWH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAIzD;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,OAAO,GAAG,OAAO,CAcvD;AAmgDD;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CA8C9C;AAED;;;;GAIG;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.0",
3
+ "version": "0.3.1",
4
4
  "description": "公开 DSL 与飞书内部 RAW JSON 的双向适配器;raw→DSL 对齐 feishu-raw-card-to-dsl",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",