1 | "use strict";
|
2 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3 | if (k2 === undefined) k2 = k;
|
4 | var desc = Object.getOwnPropertyDescriptor(m, k);
|
5 | if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6 | desc = { enumerable: true, get: function() { return m[k]; } };
|
7 | }
|
8 | Object.defineProperty(o, k2, desc);
|
9 | }) : (function(o, m, k, k2) {
|
10 | if (k2 === undefined) k2 = k;
|
11 | o[k2] = m[k];
|
12 | }));
|
13 | var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14 | Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15 | }) : function(o, v) {
|
16 | o["default"] = v;
|
17 | });
|
18 | var __importStar = (this && this.__importStar) || function (mod) {
|
19 | if (mod && mod.__esModule) return mod;
|
20 | var result = {};
|
21 | if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22 | __setModuleDefault(result, mod);
|
23 | return result;
|
24 | };
|
25 | Object.defineProperty(exports, "__esModule", { value: true });
|
26 | exports.inlineKeyboard = exports.keyboard = exports.forceReply = exports.removeKeyboard = exports.button = exports.Markup = void 0;
|
27 | const check_1 = require("./core/helpers/check");
|
28 | class Markup {
|
29 | constructor(reply_markup) {
|
30 | this.reply_markup = reply_markup;
|
31 | }
|
32 | selective(value = true) {
|
33 | return new Markup({ ...this.reply_markup, selective: value });
|
34 | }
|
35 | placeholder(placeholder) {
|
36 | return new Markup({
|
37 | ...this.reply_markup,
|
38 | input_field_placeholder: placeholder,
|
39 | });
|
40 | }
|
41 | resize(value = true) {
|
42 | return new Markup({
|
43 | ...this.reply_markup,
|
44 | resize_keyboard: value,
|
45 | });
|
46 | }
|
47 | oneTime(value = true) {
|
48 | return new Markup({
|
49 | ...this.reply_markup,
|
50 | one_time_keyboard: value,
|
51 | });
|
52 | }
|
53 | }
|
54 | exports.Markup = Markup;
|
55 | exports.button = __importStar(require("./button"));
|
56 | function removeKeyboard() {
|
57 | return new Markup({ remove_keyboard: true });
|
58 | }
|
59 | exports.removeKeyboard = removeKeyboard;
|
60 | function forceReply() {
|
61 | return new Markup({ force_reply: true });
|
62 | }
|
63 | exports.forceReply = forceReply;
|
64 | function keyboard(buttons, options) {
|
65 | const keyboard = buildKeyboard(buttons, {
|
66 | columns: 1,
|
67 | ...options,
|
68 | });
|
69 | return new Markup({ keyboard });
|
70 | }
|
71 | exports.keyboard = keyboard;
|
72 | function inlineKeyboard(buttons, options) {
|
73 | const inlineKeyboard = buildKeyboard(buttons, {
|
74 | columns: buttons.length,
|
75 | ...options,
|
76 | });
|
77 | return new Markup({ inline_keyboard: inlineKeyboard });
|
78 | }
|
79 | exports.inlineKeyboard = inlineKeyboard;
|
80 | function buildKeyboard(buttons, options) {
|
81 | const result = [];
|
82 | if (!Array.isArray(buttons)) {
|
83 | return result;
|
84 | }
|
85 | if ((0, check_1.is2D)(buttons)) {
|
86 | return buttons.map((row) => row.filter((button) => !button.hide));
|
87 | }
|
88 | const wrapFn = options.wrap !== undefined
|
89 | ? options.wrap
|
90 | : (_btn, _index, currentRow) => currentRow.length >= options.columns;
|
91 | let currentRow = [];
|
92 | let index = 0;
|
93 | for (const btn of buttons.filter((button) => !button.hide)) {
|
94 | if (wrapFn(btn, index, currentRow) && currentRow.length > 0) {
|
95 | result.push(currentRow);
|
96 | currentRow = [];
|
97 | }
|
98 | currentRow.push(btn);
|
99 | index++;
|
100 | }
|
101 | if (currentRow.length > 0) {
|
102 | result.push(currentRow);
|
103 | }
|
104 | return result;
|
105 | }
|