@pi-kaush/pi-content-layout 0.1.18 → 0.1.19
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/package.json +1 -1
- package/src/intercom-message.ts +36 -27
package/package.json
CHANGED
package/src/intercom-message.ts
CHANGED
|
@@ -94,41 +94,52 @@ class IntercomMessageComponent implements Component {
|
|
|
94
94
|
);
|
|
95
95
|
const topBorder = `${margin}${border("╭")} ${styledTitle} ${border(dashes + "╮")}${margin}`;
|
|
96
96
|
|
|
97
|
-
const
|
|
97
|
+
const contentLines = this.expanded
|
|
98
|
+
? this.renderExpanded(innerWidth, frameLine, bodyColor)
|
|
99
|
+
: this.renderCollapsed(frameLine, bodyColor);
|
|
100
|
+
return [topBorder, ...contentLines, bottomBorder];
|
|
101
|
+
}
|
|
98
102
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
103
|
+
private renderCollapsed(
|
|
104
|
+
frameLine: (content: string) => string,
|
|
105
|
+
bodyColor: (text: string) => string,
|
|
106
|
+
): string[] {
|
|
107
|
+
this.collapsedPreview ??= this.bodyText.replace(/\s+/g, " ").trim();
|
|
108
|
+
const lines = [frameLine(bodyColor(this.collapsedPreview))];
|
|
102
109
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
const replyTo = this.details.message?.replyTo;
|
|
114
|
-
if (replyTo && !this.details.message?.expectsReply) {
|
|
115
|
-
meta.push(`Reply to ${replyTo.slice(0, 8)}`);
|
|
116
|
-
}
|
|
117
|
-
meta.push("Ctrl+O to expand");
|
|
118
|
-
lines.push(frameLine(bodyColor(meta.join(" · "))));
|
|
119
|
-
lines.push(bottomBorder);
|
|
120
|
-
return lines;
|
|
110
|
+
const meta: string[] = [];
|
|
111
|
+
if (this.details.replyCommand) {
|
|
112
|
+
meta.push(`To reply: ${this.details.replyCommand}`);
|
|
113
|
+
}
|
|
114
|
+
const attachments = this.details.message?.content?.attachments;
|
|
115
|
+
if (attachments?.length) {
|
|
116
|
+
meta.push(
|
|
117
|
+
`${attachments.length} attachment${attachments.length === 1 ? "" : "s"}`,
|
|
118
|
+
);
|
|
121
119
|
}
|
|
120
|
+
const replyTo = this.details.message?.replyTo;
|
|
121
|
+
if (replyTo && !this.details.message?.expectsReply) {
|
|
122
|
+
meta.push(`Reply to ${replyTo.slice(0, 8)}`);
|
|
123
|
+
}
|
|
124
|
+
meta.push("Ctrl+O to expand");
|
|
125
|
+
lines.push(frameLine(bodyColor(meta.join(" · "))));
|
|
126
|
+
return lines;
|
|
127
|
+
}
|
|
122
128
|
|
|
129
|
+
private renderExpanded(
|
|
130
|
+
innerWidth: number,
|
|
131
|
+
frameLine: (content: string) => string,
|
|
132
|
+
bodyColor: (text: string) => string,
|
|
133
|
+
): string[] {
|
|
123
134
|
if (this.wrappedBody?.width !== innerWidth) {
|
|
124
135
|
this.wrappedBody = {
|
|
125
136
|
width: innerWidth,
|
|
126
137
|
lines: wrapTextWithAnsi(this.bodyText, innerWidth),
|
|
127
138
|
};
|
|
128
139
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
140
|
+
const lines = this.wrappedBody.lines.map((line) =>
|
|
141
|
+
frameLine(bodyColor(line)),
|
|
142
|
+
);
|
|
132
143
|
|
|
133
144
|
if (this.details.replyCommand) {
|
|
134
145
|
lines.push(frameLine(""));
|
|
@@ -154,8 +165,6 @@ class IntercomMessageComponent implements Component {
|
|
|
154
165
|
lines.push(frameLine(""));
|
|
155
166
|
lines.push(frameLine(bodyColor(`Reply to ${replyTo.slice(0, 8)}`)));
|
|
156
167
|
}
|
|
157
|
-
|
|
158
|
-
lines.push(bottomBorder);
|
|
159
168
|
return lines;
|
|
160
169
|
}
|
|
161
170
|
}
|