@satorijs/adapter-lark 3.10.0 → 3.10.2

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
@@ -136,11 +136,23 @@ async function adaptSession(bot, body) {
136
136
  session.type = "interaction/command";
137
137
  let content = body.event.action.value.content;
138
138
  const args = [], options = /* @__PURE__ */ Object.create(null);
139
+ const setOption = /* @__PURE__ */ __name((key, value) => {
140
+ if (key in options) {
141
+ options[key] += "," + value;
142
+ } else {
143
+ options[key] = value;
144
+ }
145
+ }, "setOption");
139
146
  for (const [key, value] of Object.entries(body.event.action.form_value ?? {})) {
140
- if (+key * 0 === 0) {
147
+ if (key.startsWith("@@")) {
148
+ if (value) args.push(key.slice(2));
149
+ } else if (key.startsWith("@")) {
150
+ const [_key] = key.slice(1).split("=", 1);
151
+ setOption(_key, key.slice(2 + _key.length));
152
+ } else if (+key * 0 === 0) {
141
153
  args[+key] = value;
142
154
  } else {
143
- options[key] = value;
155
+ setOption(key, value);
144
156
  }
145
157
  }
146
158
  const toArg = /* @__PURE__ */ __name((value) => {
@@ -155,9 +167,9 @@ async function adaptSession(bot, body) {
155
167
  }
156
168
  for (const [key, value] of Object.entries(options)) {
157
169
  if (value === true) {
158
- content += ` --${key}`;
170
+ content += ` --${key} 1`;
159
171
  } else if (value === false) {
160
- content += ` --no-${key}`;
172
+ content += ` --${key} 0`;
161
173
  } else {
162
174
  content += ` --${key} ${toArg(value)}`;
163
175
  }
@@ -638,7 +650,7 @@ var LarkMessageEncoder = class extends import_core3.MessageEncoder {
638
650
  await this.render(children);
639
651
  this.card?.elements.push({
640
652
  tag: "checker",
641
- name: attrs.name,
653
+ name: (attrs.argument ? "@@" : attrs.option ? `@${attrs.option}=` : "") + attrs.name,
642
654
  checked: attrs.checked,
643
655
  text: {
644
656
  tag: "plain_text",
@@ -789,6 +801,37 @@ var LarkMessageEncoder = class extends import_core3.MessageEncoder {
789
801
  tag: "standard_icon",
790
802
  token: attrs.token
791
803
  });
804
+ } else if (tag === "column-set") {
805
+ this.flushText();
806
+ const parent = this.card;
807
+ const columns = [];
808
+ parent?.elements.push({
809
+ tag: "column_set",
810
+ margin: attrs.margin,
811
+ flex_mode: attrs.flexMode,
812
+ horizontal_align: attrs.horizontalAlign,
813
+ horizontal_spacing: attrs.horizontalSpacing,
814
+ background_style: attrs.backgroundStyle,
815
+ columns
816
+ });
817
+ for (const child of children) {
818
+ if (child.type !== "lark:column" && child.type !== "feishu:column") {
819
+ continue;
820
+ }
821
+ this.card = { elements: [] };
822
+ await this.render(child.children);
823
+ columns.push({
824
+ tag: "column",
825
+ width: child.attrs.width,
826
+ weight: child.attrs.weight,
827
+ padding: child.attrs.padding,
828
+ vertical_align: child.attrs.verticalAlign,
829
+ vertical_spacing: child.attrs.verticalSpacing,
830
+ background_style: child.attrs.backgroundStyle,
831
+ elements: this.card.elements
832
+ });
833
+ }
834
+ this.card = parent;
792
835
  }
793
836
  } else {
794
837
  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.0",
4
+ "version": "3.10.2",
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
@@ -266,7 +266,7 @@ export class LarkMessageEncoder<C extends Context = Context> extends MessageEnco
266
266
  await this.render(children)
267
267
  this.card?.elements.push({
268
268
  tag: 'checker',
269
- name: attrs.name,
269
+ name: (attrs.argument ? '@@' : attrs.option ? `@${attrs.option}=` : '') + attrs.name,
270
270
  checked: attrs.checked,
271
271
  text: {
272
272
  tag: 'plain_text',
@@ -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
@@ -256,11 +256,23 @@ export async function adaptSession<C extends Context>(bot: LarkBot<C>, body: Eve
256
256
  session.type = 'interaction/command'
257
257
  let content = body.event.action.value.content
258
258
  const args: any[] = [], options = Object.create(null)
259
+ const setOption = (key: string, value: any) => {
260
+ if (key in options) {
261
+ options[key] += ',' + value
262
+ } else {
263
+ options[key] = value
264
+ }
265
+ }
259
266
  for (const [key, value] of Object.entries(body.event.action.form_value ?? {})) {
260
- if (+key * 0 === 0) {
267
+ if (key.startsWith('@@')) {
268
+ if (value) args.push(key.slice(2))
269
+ } else if (key.startsWith('@')) {
270
+ const [_key] = key.slice(1).split('=', 1)
271
+ setOption(_key, key.slice(2 + _key.length))
272
+ } else if (+key * 0 === 0) {
261
273
  args[+key] = value
262
274
  } else {
263
- options[key] = value
275
+ setOption(key, value)
264
276
  }
265
277
  }
266
278
  const toArg = (value: any) => {
@@ -275,9 +287,9 @@ export async function adaptSession<C extends Context>(bot: LarkBot<C>, body: Eve
275
287
  }
276
288
  for (const [key, value] of Object.entries(options)) {
277
289
  if (value === true) {
278
- content += ` --${key}`
290
+ content += ` --${key} 1`
279
291
  } else if (value === false) {
280
- content += ` --no-${key}`
292
+ content += ` --${key} 0`
281
293
  } else {
282
294
  content += ` --${key} ${toArg(value)}`
283
295
  }