@satorijs/adapter-lark 3.10.5 → 3.10.6

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
@@ -360,6 +360,7 @@ export declare namespace MessageContent {
360
360
  interface SelectElement extends BaseSelectElement<'select_static'> {
361
361
  options: OptionElement[];
362
362
  initial_option?: string;
363
+ behaviors?: ActionBehavior[];
363
364
  }
364
365
  interface MultiSelectElement extends BaseSelectElement<'multi_select_static'> {
365
366
  options: OptionElement[];
@@ -441,7 +442,7 @@ export declare namespace MessageContent {
441
442
  type Width = 'default' | 'fill' | string;
442
443
  type Type = 'default' | 'primary' | 'danger' | 'text' | 'primary_text' | 'danger_text' | 'primary_filled' | 'danger_filled' | 'laser';
443
444
  }
444
- type Element = DivElement | MarkdownElement | HRElement | ActionElement | NoteElement | ChartElement | TableElement | ImageElement | FormElement | InputElement | ButtonElement | CheckerElement | ColumnSetElement;
445
+ type Element = DivElement | MarkdownElement | HRElement | ActionElement | NoteElement | ChartElement | TableElement | ImageElement | FormElement | InputElement | ButtonElement | CheckerElement | ColumnSetElement | SelectElement;
445
446
  }
446
447
  interface Template {
447
448
  type: 'template';
package/lib/index.cjs CHANGED
@@ -47,6 +47,353 @@ var import_core2 = require("@satorijs/core");
47
47
  // src/utils.ts
48
48
  var import_crypto = __toESM(require("crypto"), 1);
49
49
  var import_core = require("@satorijs/core");
50
+
51
+ // node_modules/cosmokit/lib/index.mjs
52
+ var __defProp2 = Object.defineProperty;
53
+ var __name2 = /* @__PURE__ */ __name((target, value) => __defProp2(target, "name", { value, configurable: true }), "__name");
54
+ function noop() {
55
+ }
56
+ __name(noop, "noop");
57
+ __name2(noop, "noop");
58
+ function isNullable(value) {
59
+ return value === null || value === void 0;
60
+ }
61
+ __name(isNullable, "isNullable");
62
+ __name2(isNullable, "isNullable");
63
+ function isNonNullable(value) {
64
+ return !isNullable(value);
65
+ }
66
+ __name(isNonNullable, "isNonNullable");
67
+ __name2(isNonNullable, "isNonNullable");
68
+ function isPlainObject(data) {
69
+ return data && typeof data === "object" && !Array.isArray(data);
70
+ }
71
+ __name(isPlainObject, "isPlainObject");
72
+ __name2(isPlainObject, "isPlainObject");
73
+ function filterKeys(object, filter) {
74
+ return Object.fromEntries(Object.entries(object).filter(([key, value]) => filter(key, value)));
75
+ }
76
+ __name(filterKeys, "filterKeys");
77
+ __name2(filterKeys, "filterKeys");
78
+ function mapValues(object, transform) {
79
+ return Object.fromEntries(Object.entries(object).map(([key, value]) => [key, transform(value, key)]));
80
+ }
81
+ __name(mapValues, "mapValues");
82
+ __name2(mapValues, "mapValues");
83
+ function pick(source, keys, forced) {
84
+ if (!keys) return { ...source };
85
+ const result = {};
86
+ for (const key of keys) {
87
+ if (forced || source[key] !== void 0) result[key] = source[key];
88
+ }
89
+ return result;
90
+ }
91
+ __name(pick, "pick");
92
+ __name2(pick, "pick");
93
+ function omit(source, keys) {
94
+ if (!keys) return { ...source };
95
+ const result = { ...source };
96
+ for (const key of keys) {
97
+ Reflect.deleteProperty(result, key);
98
+ }
99
+ return result;
100
+ }
101
+ __name(omit, "omit");
102
+ __name2(omit, "omit");
103
+ function defineProperty(object, key, value) {
104
+ return Object.defineProperty(object, key, { writable: true, value, enumerable: false });
105
+ }
106
+ __name(defineProperty, "defineProperty");
107
+ __name2(defineProperty, "defineProperty");
108
+ function contain(array1, array2) {
109
+ return array2.every((item) => array1.includes(item));
110
+ }
111
+ __name(contain, "contain");
112
+ __name2(contain, "contain");
113
+ function intersection(array1, array2) {
114
+ return array1.filter((item) => array2.includes(item));
115
+ }
116
+ __name(intersection, "intersection");
117
+ __name2(intersection, "intersection");
118
+ function difference(array1, array2) {
119
+ return array1.filter((item) => !array2.includes(item));
120
+ }
121
+ __name(difference, "difference");
122
+ __name2(difference, "difference");
123
+ function union(array1, array2) {
124
+ return Array.from(/* @__PURE__ */ new Set([...array1, ...array2]));
125
+ }
126
+ __name(union, "union");
127
+ __name2(union, "union");
128
+ function deduplicate(array) {
129
+ return [...new Set(array)];
130
+ }
131
+ __name(deduplicate, "deduplicate");
132
+ __name2(deduplicate, "deduplicate");
133
+ function remove(list, item) {
134
+ const index = list?.indexOf(item);
135
+ if (index >= 0) {
136
+ list.splice(index, 1);
137
+ return true;
138
+ } else {
139
+ return false;
140
+ }
141
+ }
142
+ __name(remove, "remove");
143
+ __name2(remove, "remove");
144
+ function makeArray(source) {
145
+ return Array.isArray(source) ? source : isNullable(source) ? [] : [source];
146
+ }
147
+ __name(makeArray, "makeArray");
148
+ __name2(makeArray, "makeArray");
149
+ function is(type, value) {
150
+ if (arguments.length === 1) return (value2) => is(type, value2);
151
+ return type in globalThis && value instanceof globalThis[type] || Object.prototype.toString.call(value).slice(8, -1) === type;
152
+ }
153
+ __name(is, "is");
154
+ __name2(is, "is");
155
+ function isArrayBufferLike(value) {
156
+ return is("ArrayBuffer", value) || is("SharedArrayBuffer", value);
157
+ }
158
+ __name(isArrayBufferLike, "isArrayBufferLike");
159
+ __name2(isArrayBufferLike, "isArrayBufferLike");
160
+ function isArrayBufferSource(value) {
161
+ return isArrayBufferLike(value) || ArrayBuffer.isView(value);
162
+ }
163
+ __name(isArrayBufferSource, "isArrayBufferSource");
164
+ __name2(isArrayBufferSource, "isArrayBufferSource");
165
+ var Binary;
166
+ ((Binary2) => {
167
+ Binary2.is = isArrayBufferLike;
168
+ Binary2.isSource = isArrayBufferSource;
169
+ function fromSource(source) {
170
+ if (ArrayBuffer.isView(source)) {
171
+ return source.buffer.slice(source.byteOffset, source.byteOffset + source.byteLength);
172
+ } else {
173
+ return source;
174
+ }
175
+ }
176
+ __name(fromSource, "fromSource");
177
+ Binary2.fromSource = fromSource;
178
+ __name2(fromSource, "fromSource");
179
+ function toBase64(source) {
180
+ if (typeof Buffer !== "undefined") {
181
+ return Buffer.from(source).toString("base64");
182
+ }
183
+ let binary = "";
184
+ const bytes = new Uint8Array(source);
185
+ for (let i = 0; i < bytes.byteLength; i++) {
186
+ binary += String.fromCharCode(bytes[i]);
187
+ }
188
+ return btoa(binary);
189
+ }
190
+ __name(toBase64, "toBase64");
191
+ Binary2.toBase64 = toBase64;
192
+ __name2(toBase64, "toBase64");
193
+ function fromBase64(source) {
194
+ if (typeof Buffer !== "undefined") return fromSource(Buffer.from(source, "base64"));
195
+ return Uint8Array.from(atob(source), (c) => c.charCodeAt(0));
196
+ }
197
+ __name(fromBase64, "fromBase64");
198
+ Binary2.fromBase64 = fromBase64;
199
+ __name2(fromBase64, "fromBase64");
200
+ function toHex(source) {
201
+ if (typeof Buffer !== "undefined") return Buffer.from(source).toString("hex");
202
+ return Array.from(new Uint8Array(source), (byte) => byte.toString(16).padStart(2, "0")).join("");
203
+ }
204
+ __name(toHex, "toHex");
205
+ Binary2.toHex = toHex;
206
+ __name2(toHex, "toHex");
207
+ function fromHex(source) {
208
+ if (typeof Buffer !== "undefined") return fromSource(Buffer.from(source, "hex"));
209
+ const hex = source.length % 2 === 0 ? source : source.slice(0, source.length - 1);
210
+ const buffer = [];
211
+ for (let i = 0; i < hex.length; i += 2) {
212
+ buffer.push(parseInt(`${hex[i]}${hex[i + 1]}`, 16));
213
+ }
214
+ return Uint8Array.from(buffer).buffer;
215
+ }
216
+ __name(fromHex, "fromHex");
217
+ Binary2.fromHex = fromHex;
218
+ __name2(fromHex, "fromHex");
219
+ })(Binary || (Binary = {}));
220
+ var base64ToArrayBuffer = Binary.fromBase64;
221
+ var arrayBufferToBase64 = Binary.toBase64;
222
+ var hexToArrayBuffer = Binary.fromHex;
223
+ var arrayBufferToHex = Binary.toHex;
224
+ function clone(source) {
225
+ if (!source || typeof source !== "object") return source;
226
+ if (Array.isArray(source)) return source.map(clone);
227
+ if (is("Date", source)) return new Date(source.valueOf());
228
+ if (is("RegExp", source)) return new RegExp(source.source, source.flags);
229
+ if (isArrayBufferLike(source)) return source.slice(0);
230
+ if (ArrayBuffer.isView(source)) return source.buffer.slice(source.byteOffset, source.byteOffset + source.byteLength);
231
+ const result = Object.create(Object.getPrototypeOf(source));
232
+ for (const key of Reflect.ownKeys(source)) {
233
+ Reflect.defineProperty(result, key, Reflect.getOwnPropertyDescriptor(source, key));
234
+ }
235
+ return result;
236
+ }
237
+ __name(clone, "clone");
238
+ __name2(clone, "clone");
239
+ function deepEqual(a, b, strict) {
240
+ if (a === b) return true;
241
+ if (!strict && isNullable(a) && isNullable(b)) return true;
242
+ if (typeof a !== typeof b) return false;
243
+ if (typeof a !== "object") return false;
244
+ if (!a || !b) return false;
245
+ function check(test, then) {
246
+ return test(a) ? test(b) ? then(a, b) : false : test(b) ? false : void 0;
247
+ }
248
+ __name(check, "check");
249
+ __name2(check, "check");
250
+ return check(Array.isArray, (a2, b2) => a2.length === b2.length && a2.every((item, index) => deepEqual(item, b2[index]))) ?? check(is("Date"), (a2, b2) => a2.valueOf() === b2.valueOf()) ?? check(is("RegExp"), (a2, b2) => a2.source === b2.source && a2.flags === b2.flags) ?? check(isArrayBufferLike, (a2, b2) => {
251
+ if (a2.byteLength !== b2.byteLength) return false;
252
+ const viewA = new Uint8Array(a2);
253
+ const viewB = new Uint8Array(b2);
254
+ for (let i = 0; i < viewA.length; i++) {
255
+ if (viewA[i] !== viewB[i]) return false;
256
+ }
257
+ return true;
258
+ }) ?? Object.keys({ ...a, ...b }).every((key) => deepEqual(a[key], b[key], strict));
259
+ }
260
+ __name(deepEqual, "deepEqual");
261
+ __name2(deepEqual, "deepEqual");
262
+ function capitalize(source) {
263
+ return source.charAt(0).toUpperCase() + source.slice(1);
264
+ }
265
+ __name(capitalize, "capitalize");
266
+ __name2(capitalize, "capitalize");
267
+ function uncapitalize(source) {
268
+ return source.charAt(0).toLowerCase() + source.slice(1);
269
+ }
270
+ __name(uncapitalize, "uncapitalize");
271
+ __name2(uncapitalize, "uncapitalize");
272
+ function camelCase(source) {
273
+ return source.replace(/[_-][a-z]/g, (str) => str.slice(1).toUpperCase());
274
+ }
275
+ __name(camelCase, "camelCase");
276
+ __name2(camelCase, "camelCase");
277
+ function paramCase(source) {
278
+ return uncapitalize(source).replace(/_/g, "-").replace(/.[A-Z]+/g, (str) => str[0] + "-" + str.slice(1).toLowerCase());
279
+ }
280
+ __name(paramCase, "paramCase");
281
+ __name2(paramCase, "paramCase");
282
+ function snakeCase(source) {
283
+ return uncapitalize(source).replace(/-/g, "_").replace(/.[A-Z]+/g, (str) => str[0] + "_" + str.slice(1).toLowerCase());
284
+ }
285
+ __name(snakeCase, "snakeCase");
286
+ __name2(snakeCase, "snakeCase");
287
+ var hyphenate = paramCase;
288
+ function trimSlash(source) {
289
+ return source.replace(/\/$/, "");
290
+ }
291
+ __name(trimSlash, "trimSlash");
292
+ __name2(trimSlash, "trimSlash");
293
+ function sanitize(source) {
294
+ if (!source.startsWith("/")) source = "/" + source;
295
+ return trimSlash(source);
296
+ }
297
+ __name(sanitize, "sanitize");
298
+ __name2(sanitize, "sanitize");
299
+ var Time;
300
+ ((Time22) => {
301
+ Time22.millisecond = 1;
302
+ Time22.second = 1e3;
303
+ Time22.minute = Time22.second * 60;
304
+ Time22.hour = Time22.minute * 60;
305
+ Time22.day = Time22.hour * 24;
306
+ Time22.week = Time22.day * 7;
307
+ let timezoneOffset = (/* @__PURE__ */ new Date()).getTimezoneOffset();
308
+ function setTimezoneOffset(offset) {
309
+ timezoneOffset = offset;
310
+ }
311
+ __name(setTimezoneOffset, "setTimezoneOffset");
312
+ Time22.setTimezoneOffset = setTimezoneOffset;
313
+ __name2(setTimezoneOffset, "setTimezoneOffset");
314
+ function getTimezoneOffset() {
315
+ return timezoneOffset;
316
+ }
317
+ __name(getTimezoneOffset, "getTimezoneOffset");
318
+ Time22.getTimezoneOffset = getTimezoneOffset;
319
+ __name2(getTimezoneOffset, "getTimezoneOffset");
320
+ function getDateNumber(date = /* @__PURE__ */ new Date(), offset) {
321
+ if (typeof date === "number") date = new Date(date);
322
+ if (offset === void 0) offset = timezoneOffset;
323
+ return Math.floor((date.valueOf() / Time22.minute - offset) / 1440);
324
+ }
325
+ __name(getDateNumber, "getDateNumber");
326
+ Time22.getDateNumber = getDateNumber;
327
+ __name2(getDateNumber, "getDateNumber");
328
+ function fromDateNumber(value, offset) {
329
+ const date = new Date(value * Time22.day);
330
+ if (offset === void 0) offset = timezoneOffset;
331
+ return new Date(+date + offset * Time22.minute);
332
+ }
333
+ __name(fromDateNumber, "fromDateNumber");
334
+ Time22.fromDateNumber = fromDateNumber;
335
+ __name2(fromDateNumber, "fromDateNumber");
336
+ const numeric = /\d+(?:\.\d+)?/.source;
337
+ const timeRegExp = new RegExp(`^${[
338
+ "w(?:eek(?:s)?)?",
339
+ "d(?:ay(?:s)?)?",
340
+ "h(?:our(?:s)?)?",
341
+ "m(?:in(?:ute)?(?:s)?)?",
342
+ "s(?:ec(?:ond)?(?:s)?)?"
343
+ ].map((unit) => `(${numeric}${unit})?`).join("")}$`);
344
+ function parseTime(source) {
345
+ const capture = timeRegExp.exec(source);
346
+ if (!capture) return 0;
347
+ return (parseFloat(capture[1]) * Time22.week || 0) + (parseFloat(capture[2]) * Time22.day || 0) + (parseFloat(capture[3]) * Time22.hour || 0) + (parseFloat(capture[4]) * Time22.minute || 0) + (parseFloat(capture[5]) * Time22.second || 0);
348
+ }
349
+ __name(parseTime, "parseTime");
350
+ Time22.parseTime = parseTime;
351
+ __name2(parseTime, "parseTime");
352
+ function parseDate(date) {
353
+ const parsed = parseTime(date);
354
+ if (parsed) {
355
+ date = Date.now() + parsed;
356
+ } else if (/^\d{1,2}(:\d{1,2}){1,2}$/.test(date)) {
357
+ date = `${(/* @__PURE__ */ new Date()).toLocaleDateString()}-${date}`;
358
+ } else if (/^\d{1,2}-\d{1,2}-\d{1,2}(:\d{1,2}){1,2}$/.test(date)) {
359
+ date = `${(/* @__PURE__ */ new Date()).getFullYear()}-${date}`;
360
+ }
361
+ return date ? new Date(date) : /* @__PURE__ */ new Date();
362
+ }
363
+ __name(parseDate, "parseDate");
364
+ Time22.parseDate = parseDate;
365
+ __name2(parseDate, "parseDate");
366
+ function format(ms) {
367
+ const abs = Math.abs(ms);
368
+ if (abs >= Time22.day - Time22.hour / 2) {
369
+ return Math.round(ms / Time22.day) + "d";
370
+ } else if (abs >= Time22.hour - Time22.minute / 2) {
371
+ return Math.round(ms / Time22.hour) + "h";
372
+ } else if (abs >= Time22.minute - Time22.second / 2) {
373
+ return Math.round(ms / Time22.minute) + "m";
374
+ } else if (abs >= Time22.second) {
375
+ return Math.round(ms / Time22.second) + "s";
376
+ }
377
+ return ms + "ms";
378
+ }
379
+ __name(format, "format");
380
+ Time22.format = format;
381
+ __name2(format, "format");
382
+ function toDigits(source, length = 2) {
383
+ return source.toString().padStart(length, "0");
384
+ }
385
+ __name(toDigits, "toDigits");
386
+ Time22.toDigits = toDigits;
387
+ __name2(toDigits, "toDigits");
388
+ function template(template2, time = /* @__PURE__ */ new Date()) {
389
+ return template2.replace("yyyy", time.getFullYear().toString()).replace("yy", time.getFullYear().toString().slice(2)).replace("MM", toDigits(time.getMonth() + 1)).replace("dd", toDigits(time.getDate())).replace("hh", toDigits(time.getHours())).replace("mm", toDigits(time.getMinutes())).replace("ss", toDigits(time.getSeconds())).replace("SSS", toDigits(time.getMilliseconds(), 3));
390
+ }
391
+ __name(template, "template");
392
+ Time22.template = template;
393
+ __name2(template, "template");
394
+ })(Time || (Time = {}));
395
+
396
+ // src/utils.ts
50
397
  function adaptSender(sender, session) {
51
398
  let userId;
52
399
  if ("sender_id" in sender) {
@@ -171,11 +518,11 @@ async function adaptSession(bot, body) {
171
518
  }
172
519
  for (const [key, value] of Object.entries(options)) {
173
520
  if (value === true) {
174
- content += ` --${key} 1`;
521
+ content += ` --${hyphenate(key)} 1`;
175
522
  } else if (value === false) {
176
- content += ` --${key} 0`;
523
+ content += ` --${hyphenate(key)} 0`;
177
524
  } else {
178
- content += ` --${key} ${toArg(value)}`;
525
+ content += ` --${hyphenate(key)} ${toArg(value)}`;
179
526
  }
180
527
  }
181
528
  if (body.event.action.input_value) {
@@ -424,6 +771,7 @@ var LarkMessageEncoder = class extends import_core3.MessageEncoder {
424
771
  card;
425
772
  noteElements;
426
773
  actionElements = [];
774
+ isForm = false;
427
775
  editMessageIds;
428
776
  async post(data) {
429
777
  try {
@@ -641,7 +989,9 @@ var LarkMessageEncoder = class extends import_core3.MessageEncoder {
641
989
  } else if (type === "form") {
642
990
  this.flushText();
643
991
  const length = this.card?.elements.length;
992
+ this.isForm = true;
644
993
  await this.render(children);
994
+ this.isForm = false;
645
995
  if (this.card?.elements.length > length) {
646
996
  const elements = this.card?.elements.splice(length);
647
997
  this.card.elements.push({
@@ -657,7 +1007,7 @@ var LarkMessageEncoder = class extends import_core3.MessageEncoder {
657
1007
  this.card?.elements.push({
658
1008
  tag: "checker",
659
1009
  name: (attrs.argument ? "@@" : attrs.option ? `@${attrs.option}=` : "") + attrs.name,
660
- checked: attrs.checked,
1010
+ checked: attrs.value,
661
1011
  text: {
662
1012
  tag: "plain_text",
663
1013
  content: this.textContent
@@ -683,20 +1033,68 @@ var LarkMessageEncoder = class extends import_core3.MessageEncoder {
683
1033
  this.textContent = "";
684
1034
  } else {
685
1035
  this.flushText();
1036
+ const input = {
1037
+ tag: "input",
1038
+ name: attrs.name,
1039
+ width: attrs.width,
1040
+ label: attrs.label && {
1041
+ tag: "plain_text",
1042
+ content: attrs.label
1043
+ },
1044
+ placeholder: attrs.placeholder && {
1045
+ tag: "plain_text",
1046
+ content: attrs.placeholder
1047
+ },
1048
+ default_value: attrs.value,
1049
+ disabled: attrs.disabled,
1050
+ required: attrs.required
1051
+ };
1052
+ if (this.isForm) {
1053
+ this.card?.elements.push(input);
1054
+ } else {
1055
+ this.card?.elements.push({
1056
+ tag: "action",
1057
+ actions: [{
1058
+ ...input,
1059
+ behaviors: this.createBehavior(attrs)
1060
+ }]
1061
+ });
1062
+ }
1063
+ }
1064
+ } else if (type === "select") {
1065
+ this.flushText();
1066
+ const select = {
1067
+ tag: "select_static",
1068
+ name: attrs.name,
1069
+ width: attrs.width,
1070
+ initial_option: attrs.value,
1071
+ disabled: attrs.disabled,
1072
+ required: attrs.required,
1073
+ placeholder: attrs.placeholder && {
1074
+ tag: "plain_text",
1075
+ content: attrs.placeholder
1076
+ },
1077
+ options: []
1078
+ };
1079
+ for (const child of children) {
1080
+ if (child.type !== "option") continue;
1081
+ await this.render(child.children);
1082
+ select.options.push({
1083
+ value: child.attrs.value,
1084
+ text: {
1085
+ tag: "plain_text",
1086
+ content: this.textContent ?? child.attrs.value
1087
+ }
1088
+ });
1089
+ this.textContent = "";
1090
+ }
1091
+ if (this.isForm) {
1092
+ this.card?.elements.push(select);
1093
+ } else {
686
1094
  this.card?.elements.push({
687
1095
  tag: "action",
688
1096
  actions: [{
689
- tag: "input",
690
- name: attrs.name,
691
- width: attrs.width,
692
- label: attrs.label && {
693
- tag: "plain_text",
694
- content: attrs.label
695
- },
696
- placeholder: attrs.placeholder && {
697
- tag: "plain_text",
698
- content: attrs.placeholder
699
- },
1097
+ ...select,
700
1098
  behaviors: this.createBehavior(attrs)
701
1099
  }]
702
1100
  });
@@ -826,13 +1224,14 @@ var LarkMessageEncoder = class extends import_core3.MessageEncoder {
826
1224
  }
827
1225
  this.card = { elements: [] };
828
1226
  await this.render(child.children);
1227
+ this.flushText();
829
1228
  columns.push({
830
1229
  tag: "column",
831
1230
  width: child.attrs.width,
832
1231
  weight: child.attrs.weight,
833
1232
  padding: child.attrs.padding,
834
- vertical_align: child.attrs.verticalAlign,
835
- vertical_spacing: child.attrs.verticalSpacing,
1233
+ vertical_align: child.attrs.verticalAlign ?? "center",
1234
+ vertical_spacing: child.attrs.verticalSpacing ?? "0px",
836
1235
  background_style: child.attrs.backgroundStyle,
837
1236
  elements: this.card.elements
838
1237
  });
package/lib/message.d.ts CHANGED
@@ -9,6 +9,7 @@ export declare class LarkMessageEncoder<C extends Context = Context> extends Mes
9
9
  private card;
10
10
  private noteElements;
11
11
  private actionElements;
12
+ private isForm;
12
13
  editMessageIds: string[] | undefined;
13
14
  post(data?: any): Promise<void>;
14
15
  private flushText;
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.5",
4
+ "version": "3.10.6",
5
5
  "type": "module",
6
6
  "main": "lib/index.cjs",
7
7
  "types": "lib/index.d.ts",
package/src/content.ts CHANGED
@@ -447,6 +447,7 @@ export namespace MessageContent {
447
447
  export interface SelectElement extends BaseSelectElement<'select_static'> {
448
448
  options: OptionElement[]
449
449
  initial_option?: string
450
+ behaviors?: ActionBehavior[]
450
451
  }
451
452
 
452
453
  export interface MultiSelectElement extends BaseSelectElement<'multi_select_static'> {
@@ -553,6 +554,7 @@ export namespace MessageContent {
553
554
  | ButtonElement
554
555
  | CheckerElement
555
556
  | ColumnSetElement
557
+ | SelectElement
556
558
  }
557
559
 
558
560
  export interface Template {
package/src/message.ts CHANGED
@@ -13,6 +13,7 @@ export class LarkMessageEncoder<C extends Context = Context> extends MessageEnco
13
13
  private card: MessageContent.Card | undefined
14
14
  private noteElements: MessageContent.Card.NoteElement.InnerElement[] | undefined
15
15
  private actionElements: MessageContent.Card.Element[] = []
16
+ private isForm = false
16
17
 
17
18
  public editMessageIds: string[] | undefined
18
19
 
@@ -251,7 +252,9 @@ export class LarkMessageEncoder<C extends Context = Context> extends MessageEnco
251
252
  } else if (type === 'form') {
252
253
  this.flushText()
253
254
  const length = this.card?.elements.length
255
+ this.isForm = true
254
256
  await this.render(children)
257
+ this.isForm = false
255
258
  if (this.card?.elements.length > length) {
256
259
  const elements = this.card?.elements.splice(length)
257
260
  this.card.elements.push({
@@ -267,7 +270,7 @@ export class LarkMessageEncoder<C extends Context = Context> extends MessageEnco
267
270
  this.card?.elements.push({
268
271
  tag: 'checker',
269
272
  name: (attrs.argument ? '@@' : attrs.option ? `@${attrs.option}=` : '') + attrs.name,
270
- checked: attrs.checked,
273
+ checked: attrs.value,
271
274
  text: {
272
275
  tag: 'plain_text',
273
276
  content: this.textContent,
@@ -293,20 +296,68 @@ export class LarkMessageEncoder<C extends Context = Context> extends MessageEnco
293
296
  this.textContent = ''
294
297
  } else {
295
298
  this.flushText()
299
+ const input: MessageContent.Card.InputElement = {
300
+ tag: 'input',
301
+ name: attrs.name,
302
+ width: attrs.width,
303
+ label: attrs.label && {
304
+ tag: 'plain_text',
305
+ content: attrs.label,
306
+ },
307
+ placeholder: attrs.placeholder && {
308
+ tag: 'plain_text',
309
+ content: attrs.placeholder,
310
+ },
311
+ default_value: attrs.value,
312
+ disabled: attrs.disabled,
313
+ required: attrs.required,
314
+ }
315
+ if (this.isForm) {
316
+ this.card?.elements.push(input)
317
+ } else {
318
+ this.card?.elements.push({
319
+ tag: 'action',
320
+ actions: [{
321
+ ...input,
322
+ behaviors: this.createBehavior(attrs),
323
+ }],
324
+ })
325
+ }
326
+ }
327
+ } else if (type === 'select') {
328
+ this.flushText()
329
+ const select: MessageContent.Card.SelectElement = {
330
+ tag: 'select_static',
331
+ name: attrs.name,
332
+ width: attrs.width,
333
+ initial_option: attrs.value,
334
+ disabled: attrs.disabled,
335
+ required: attrs.required,
336
+ placeholder: attrs.placeholder && {
337
+ tag: 'plain_text',
338
+ content: attrs.placeholder,
339
+ },
340
+ options: [],
341
+ }
342
+ for (const child of children) {
343
+ if (child.type !== 'option') continue
344
+ await this.render(child.children)
345
+ select.options.push({
346
+ value: child.attrs.value,
347
+ text: {
348
+ tag: 'plain_text',
349
+ content: this.textContent ?? child.attrs.value,
350
+ },
351
+ })
352
+ this.textContent = ''
353
+ }
354
+ if (this.isForm) {
355
+ this.card?.elements.push(select)
356
+ } else {
296
357
  this.card?.elements.push({
297
358
  tag: 'action',
298
359
  actions: [{
299
- tag: 'input',
300
- name: attrs.name,
301
- width: attrs.width,
302
- label: attrs.label && {
303
- tag: 'plain_text',
304
- content: attrs.label,
305
- },
306
- placeholder: attrs.placeholder && {
307
- tag: 'plain_text',
308
- content: attrs.placeholder,
309
- },
360
+ ...select,
310
361
  behaviors: this.createBehavior(attrs),
311
362
  }],
312
363
  })
@@ -437,13 +488,14 @@ export class LarkMessageEncoder<C extends Context = Context> extends MessageEnco
437
488
  }
438
489
  this.card = { elements: [] }
439
490
  await this.render(child.children)
491
+ this.flushText()
440
492
  columns.push({
441
493
  tag: 'column',
442
494
  width: child.attrs.width,
443
495
  weight: child.attrs.weight,
444
496
  padding: child.attrs.padding,
445
- vertical_align: child.attrs.verticalAlign,
446
- vertical_spacing: child.attrs.verticalSpacing,
497
+ vertical_align: child.attrs.verticalAlign ?? 'center',
498
+ vertical_spacing: child.attrs.verticalSpacing ?? '0px',
447
499
  background_style: child.attrs.backgroundStyle,
448
500
  elements: this.card.elements,
449
501
  })
package/src/utils.ts CHANGED
@@ -3,6 +3,7 @@ import { Context, h, pick, Session, Universal } from '@satorijs/core'
3
3
  import { LarkBot } from './bot'
4
4
  import { GetImChatResponse, ListChat, Message, User } from './types'
5
5
  import { MessageContent } from './content'
6
+ import { hyphenate } from 'cosmokit'
6
7
 
7
8
  export interface EventHeader<K extends keyof Events> {
8
9
  event_id: string
@@ -291,11 +292,11 @@ export async function adaptSession<C extends Context>(bot: LarkBot<C>, body: Eve
291
292
  }
292
293
  for (const [key, value] of Object.entries(options)) {
293
294
  if (value === true) {
294
- content += ` --${key} 1`
295
+ content += ` --${hyphenate(key)} 1`
295
296
  } else if (value === false) {
296
- content += ` --${key} 0`
297
+ content += ` --${hyphenate(key)} 0`
297
298
  } else {
298
- content += ` --${key} ${toArg(value)}`
299
+ content += ` --${hyphenate(key)} ${toArg(value)}`
299
300
  }
300
301
  }
301
302
  if (body.event.action.input_value) {