@chat-adapter/teams 4.15.0 → 4.16.0

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.d.ts CHANGED
@@ -69,6 +69,11 @@ declare class TeamsFormatConverter extends BaseFormatConverter {
69
69
  */
70
70
  toAst(teamsText: string): Root;
71
71
  private nodeToTeams;
72
+ /**
73
+ * Render an mdast table node as a GFM markdown table.
74
+ * Teams renders markdown tables natively.
75
+ */
76
+ private tableToGfm;
72
77
  }
73
78
 
74
79
  interface TeamsAdapterConfig {
package/dist/index.js CHANGED
@@ -3588,6 +3588,7 @@ import {
3588
3588
  mapButtonStyle,
3589
3589
  cardToFallbackText as sharedCardToFallbackText
3590
3590
  } from "@chat-adapter/shared";
3591
+ import { cardChildToFallbackText } from "chat";
3591
3592
  var convertEmoji = createEmojiConverter("teams");
3592
3593
  var ADAPTIVE_CARD_SCHEMA = "http://adaptivecards.io/schemas/adaptive-card.json";
3593
3594
  var ADAPTIVE_CARD_VERSION = "1.4";
@@ -3659,8 +3660,18 @@ function convertChildToAdaptive(child) {
3659
3660
  ],
3660
3661
  actions: []
3661
3662
  };
3662
- default:
3663
+ case "table":
3664
+ return { elements: [convertTableToElement(child)], actions: [] };
3665
+ default: {
3666
+ const text = cardChildToFallbackText(child);
3667
+ if (text) {
3668
+ return {
3669
+ elements: [{ type: "TextBlock", text, wrap: true }],
3670
+ actions: []
3671
+ };
3672
+ }
3663
3673
  return { elements: [], actions: [] };
3674
+ }
3664
3675
  }
3665
3676
  }
3666
3677
  function convertTextToElement(element) {
@@ -3744,6 +3755,42 @@ function convertSectionToElements(element) {
3744
3755
  }
3745
3756
  return { elements, actions };
3746
3757
  }
3758
+ function convertTableToElement(element) {
3759
+ const columns = element.headers.map((header) => ({
3760
+ type: "Column",
3761
+ width: "stretch",
3762
+ items: [
3763
+ {
3764
+ type: "TextBlock",
3765
+ text: convertEmoji(header),
3766
+ weight: "bolder",
3767
+ wrap: true
3768
+ }
3769
+ ]
3770
+ }));
3771
+ const headerRow = {
3772
+ type: "ColumnSet",
3773
+ columns
3774
+ };
3775
+ const dataRows = element.rows.map((row) => ({
3776
+ type: "ColumnSet",
3777
+ columns: row.map((cell) => ({
3778
+ type: "Column",
3779
+ width: "stretch",
3780
+ items: [
3781
+ {
3782
+ type: "TextBlock",
3783
+ text: convertEmoji(cell),
3784
+ wrap: true
3785
+ }
3786
+ ]
3787
+ }))
3788
+ }));
3789
+ return {
3790
+ type: "Container",
3791
+ items: [headerRow, ...dataRows]
3792
+ };
3793
+ }
3747
3794
  function convertFieldsToElement(element) {
3748
3795
  const facts = element.children.map((field) => ({
3749
3796
  title: convertEmoji(field.label),
@@ -3763,10 +3810,10 @@ function cardToFallbackText(card) {
3763
3810
  }
3764
3811
 
3765
3812
  // src/markdown.ts
3813
+ import { escapeTableCell } from "@chat-adapter/shared";
3766
3814
  import {
3767
3815
  BaseFormatConverter,
3768
3816
  getNodeChildren,
3769
- getNodeValue,
3770
3817
  isBlockquoteNode,
3771
3818
  isCodeNode,
3772
3819
  isDeleteNode,
@@ -3777,6 +3824,7 @@ import {
3777
3824
  isListNode,
3778
3825
  isParagraphNode,
3779
3826
  isStrongNode,
3827
+ isTableNode,
3780
3828
  isTextNode,
3781
3829
  parseMarkdown
3782
3830
  } from "chat";
@@ -3889,11 +3937,36 @@ ${node.value}
3889
3937
  if (node.type === "thematicBreak") {
3890
3938
  return "---";
3891
3939
  }
3892
- const children = getNodeChildren(node);
3893
- if (children.length > 0) {
3894
- return children.map((child) => this.nodeToTeams(child)).join("");
3940
+ if (isTableNode(node)) {
3941
+ return this.tableToGfm(node);
3942
+ }
3943
+ return this.defaultNodeToText(node, (child) => this.nodeToTeams(child));
3944
+ }
3945
+ /**
3946
+ * Render an mdast table node as a GFM markdown table.
3947
+ * Teams renders markdown tables natively.
3948
+ */
3949
+ tableToGfm(node) {
3950
+ const rows = [];
3951
+ for (const row of node.children) {
3952
+ const cells = [];
3953
+ for (const cell of row.children) {
3954
+ const cellContent = getNodeChildren(cell).map((child) => this.nodeToTeams(child)).join("");
3955
+ cells.push(cellContent);
3956
+ }
3957
+ rows.push(cells);
3958
+ }
3959
+ if (rows.length === 0) {
3960
+ return "";
3961
+ }
3962
+ const lines = [];
3963
+ lines.push(`| ${rows[0].map(escapeTableCell).join(" | ")} |`);
3964
+ const separators = rows[0].map(() => "---");
3965
+ lines.push(`| ${separators.join(" | ")} |`);
3966
+ for (let i = 1; i < rows.length; i++) {
3967
+ lines.push(`| ${rows[i].map(escapeTableCell).join(" | ")} |`);
3895
3968
  }
3896
- return getNodeValue(node);
3969
+ return lines.join("\n");
3897
3970
  }
3898
3971
  };
3899
3972