@satorijs/adapter-lark 3.10.1 → 3.10.3

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/lib/content.d.ts CHANGED
@@ -419,12 +419,29 @@ export declare namespace MessageContent {
419
419
  type: 'text' | 'primary_text' | 'danger_text';
420
420
  }
421
421
  }
422
+ interface ColumnSetElement extends BaseElement<'column_set'> {
423
+ horizontal_spacing?: string;
424
+ horizontal_align?: 'left' | 'center' | 'right';
425
+ margin?: string;
426
+ flex_mode?: 'none' | 'stretch' | 'flow' | 'bisect' | 'trisect';
427
+ background_style?: string;
428
+ columns: ColumnElement[];
429
+ }
430
+ interface ColumnElement extends BaseElement<'column'> {
431
+ background_style?: string;
432
+ width?: 'auto' | 'weighted' | string;
433
+ weight?: number;
434
+ vertical_align?: 'top' | 'center' | 'bottom';
435
+ vertical_spacing?: 'default' | 'medium' | 'large' | string;
436
+ padding?: string;
437
+ elements: Element[];
438
+ }
422
439
  namespace ButtonElement {
423
440
  type Size = 'tiny' | 'small' | 'medium' | 'large';
424
441
  type Width = 'default' | 'fill' | string;
425
442
  type Type = 'default' | 'primary' | 'danger' | 'text' | 'primary_text' | 'danger_text' | 'primary_filled' | 'danger_filled' | 'laser';
426
443
  }
427
- type Element = DivElement | MarkdownElement | HRElement | ActionElement | NoteElement | ChartElement | TableElement | ImageElement | FormElement | InputElement | ButtonElement | CheckerElement;
444
+ type Element = DivElement | MarkdownElement | HRElement | ActionElement | NoteElement | ChartElement | TableElement | ImageElement | FormElement | InputElement | ButtonElement | CheckerElement | ColumnSetElement;
428
445
  }
429
446
  interface Template {
430
447
  type: 'template';
package/lib/index.cjs CHANGED
@@ -71,10 +71,12 @@ async function adaptMessage(bot, data, session, details = true) {
71
71
  text.split(" ").forEach((word) => {
72
72
  if (word.startsWith("@")) {
73
73
  const mention = data.message.mentions.find((mention2) => mention2.key === word);
74
- content.push(import_core.h.at(mention.id.open_id, { name: mention.name }));
75
- } else {
76
- content.push(word);
74
+ if (mention) {
75
+ content.push(import_core.h.at(mention.id.open_id, { name: mention.name }));
76
+ return;
77
+ }
77
78
  }
79
+ content.push(word);
78
80
  });
79
81
  break;
80
82
  }
@@ -203,10 +205,12 @@ async function decodeMessage(bot, body, details = true) {
203
205
  text.split(" ").forEach((word) => {
204
206
  if (word.startsWith("@")) {
205
207
  const mention = body.mentions.find((mention2) => mention2.key === word);
206
- content.push(import_core.h.at(mention.id, { name: mention.name }));
207
- } else {
208
- content.push(import_core.h.text(word));
208
+ if (mention) {
209
+ content.push(import_core.h.at(mention.id, { name: mention.name }));
210
+ return;
211
+ }
209
212
  }
213
+ content.push(import_core.h.text(word));
210
214
  });
211
215
  break;
212
216
  }
@@ -801,6 +805,37 @@ var LarkMessageEncoder = class extends import_core3.MessageEncoder {
801
805
  tag: "standard_icon",
802
806
  token: attrs.token
803
807
  });
808
+ } else if (tag === "column-set") {
809
+ this.flushText();
810
+ const parent = this.card;
811
+ const columns = [];
812
+ parent?.elements.push({
813
+ tag: "column_set",
814
+ margin: attrs.margin,
815
+ flex_mode: attrs.flexMode,
816
+ horizontal_align: attrs.horizontalAlign,
817
+ horizontal_spacing: attrs.horizontalSpacing,
818
+ background_style: attrs.backgroundStyle,
819
+ columns
820
+ });
821
+ for (const child of children) {
822
+ if (child.type !== "lark:column" && child.type !== "feishu:column") {
823
+ continue;
824
+ }
825
+ this.card = { elements: [] };
826
+ await this.render(child.children);
827
+ columns.push({
828
+ tag: "column",
829
+ width: child.attrs.width,
830
+ weight: child.attrs.weight,
831
+ padding: child.attrs.padding,
832
+ vertical_align: child.attrs.verticalAlign,
833
+ vertical_spacing: child.attrs.verticalSpacing,
834
+ background_style: child.attrs.backgroundStyle,
835
+ elements: this.card.elements
836
+ });
837
+ }
838
+ this.card = parent;
804
839
  }
805
840
  } else {
806
841
  await this.render(children);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@satorijs/adapter-lark",
3
3
  "description": "Lark (飞书) Adapter for Satorijs",
4
- "version": "3.10.1",
4
+ "version": "3.10.3",
5
5
  "type": "module",
6
6
  "main": "lib/index.cjs",
7
7
  "types": "lib/index.d.ts",
package/src/content.ts CHANGED
@@ -512,6 +512,27 @@ export namespace MessageContent {
512
512
  }
513
513
  }
514
514
 
515
+ export interface ColumnSetElement extends BaseElement<'column_set'> {
516
+ horizontal_spacing?: string
517
+ horizontal_align?: 'left' | 'center' | 'right'
518
+ margin?: string
519
+ flex_mode?: 'none' | 'stretch' | 'flow' | 'bisect' | 'trisect'
520
+ background_style?: string
521
+ columns: ColumnElement[]
522
+ // action?: Action
523
+ }
524
+
525
+ export interface ColumnElement extends BaseElement<'column'> {
526
+ background_style?: string
527
+ width?: 'auto' | 'weighted' | string
528
+ weight?: number
529
+ vertical_align?: 'top' | 'center' | 'bottom'
530
+ vertical_spacing?: 'default' | 'medium' | 'large' | string
531
+ padding?: string
532
+ elements: Element[]
533
+ // action?: Action
534
+ }
535
+
515
536
  export namespace ButtonElement {
516
537
  export type Size = 'tiny' | 'small' | 'medium' | 'large'
517
538
  export type Width = 'default' | 'fill' | string
@@ -531,6 +552,7 @@ export namespace MessageContent {
531
552
  | InputElement
532
553
  | ButtonElement
533
554
  | CheckerElement
555
+ | ColumnSetElement
534
556
  }
535
557
 
536
558
  export interface Template {
package/src/message.ts CHANGED
@@ -417,6 +417,38 @@ export class LarkMessageEncoder<C extends Context = Context> extends MessageEnco
417
417
  tag: 'standard_icon',
418
418
  token: attrs.token,
419
419
  })
420
+ } else if (tag === 'column-set') {
421
+ this.flushText()
422
+ const parent = this.card
423
+ const columns: MessageContent.Card.ColumnElement[] = []
424
+ parent?.elements.push({
425
+ tag: 'column_set',
426
+ margin: attrs.margin,
427
+ flex_mode: attrs.flexMode,
428
+ horizontal_align: attrs.horizontalAlign,
429
+ horizontal_spacing: attrs.horizontalSpacing,
430
+ background_style: attrs.backgroundStyle,
431
+ columns,
432
+ })
433
+ for (const child of children) {
434
+ if (child.type !== 'lark:column' && child.type !== 'feishu:column') {
435
+ // throw unexpected?
436
+ continue
437
+ }
438
+ this.card = { elements: [] }
439
+ await this.render(child.children)
440
+ columns.push({
441
+ tag: 'column',
442
+ width: child.attrs.width,
443
+ weight: child.attrs.weight,
444
+ padding: child.attrs.padding,
445
+ vertical_align: child.attrs.verticalAlign,
446
+ vertical_spacing: child.attrs.verticalSpacing,
447
+ background_style: child.attrs.backgroundStyle,
448
+ elements: this.card.elements,
449
+ })
450
+ }
451
+ this.card = parent
420
452
  }
421
453
  } else {
422
454
  await this.render(children)
package/src/utils.ts CHANGED
@@ -188,10 +188,12 @@ export async function adaptMessage<C extends Context = Context>(
188
188
  text.split(' ').forEach((word) => {
189
189
  if (word.startsWith('@')) {
190
190
  const mention = data.message.mentions.find((mention) => mention.key === word)!
191
- content.push(h.at(mention.id.open_id, { name: mention.name }))
192
- } else {
193
- content.push(word)
191
+ if (mention) {
192
+ content.push(h.at(mention.id.open_id, { name: mention.name }))
193
+ return
194
+ }
194
195
  }
196
+ content.push(word)
195
197
  })
196
198
  break
197
199
  }
@@ -327,10 +329,12 @@ export async function decodeMessage<C extends Context = Context>(bot: LarkBot<C>
327
329
  text.split(' ').forEach((word) => {
328
330
  if (word.startsWith('@')) {
329
331
  const mention = body.mentions!.find((mention) => mention.key === word)!
330
- content.push(h.at(mention.id, { name: mention.name }))
331
- } else {
332
- content.push(h.text(word))
332
+ if (mention) {
333
+ content.push(h.at(mention.id, { name: mention.name }))
334
+ return
335
+ }
333
336
  }
337
+ content.push(h.text(word))
334
338
  })
335
339
  break
336
340
  }