@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-kaush/pi-content-layout",
3
- "version": "0.1.18",
3
+ "version": "0.1.19",
4
4
  "description": "Inset Pi's conversation surface and style active and submitted prompts as matching blocks.",
5
5
  "license": "MIT",
6
6
  "author": "Kaushik Gopal",
@@ -94,41 +94,52 @@ class IntercomMessageComponent implements Component {
94
94
  );
95
95
  const topBorder = `${margin}${border("╭")} ${styledTitle} ${border(dashes + "╮")}${margin}`;
96
96
 
97
- const lines: string[] = [topBorder];
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
- if (!this.expanded) {
100
- this.collapsedPreview ??= this.bodyText.replace(/\s+/g, " ").trim();
101
- lines.push(frameLine(bodyColor(this.collapsedPreview)));
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
- const meta: string[] = [];
104
- if (this.details.replyCommand) {
105
- meta.push(`To reply: ${this.details.replyCommand}`);
106
- }
107
- const attachments = this.details.message?.content?.attachments;
108
- if (attachments?.length) {
109
- meta.push(
110
- `${attachments.length} attachment${attachments.length === 1 ? "" : "s"}`,
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
- for (const line of this.wrappedBody.lines) {
130
- lines.push(frameLine(bodyColor(line)));
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
  }