cordo 2.3.1 → 2.3.4

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": "cordo",
3
- "version": "2.3.1",
3
+ "version": "2.3.4",
4
4
  "description": "A framework for handling complex discord api interactions",
5
5
  "exports": {
6
6
  ".": "./src/index.ts",
@@ -2,12 +2,15 @@ import { ComponentType, createComponent } from "../component"
2
2
  import { Hooks } from "../../core/hooks"
3
3
 
4
4
 
5
- export function textInput(name: string) {
5
+ export function textInput() {
6
6
  let placeholderVal: string | undefined = undefined
7
+ let labelVal: string | undefined = undefined
7
8
  let minLength: number | undefined = undefined
8
9
  let maxLength: number | undefined = undefined
9
10
  let requiredVal: boolean | undefined = undefined
10
11
  let sizeVal: number | undefined = undefined
12
+ let currentVal: string | undefined = undefined
13
+ let ref: string | undefined = undefined
11
14
 
12
15
  function getPlaceholder() {
13
16
  if (!placeholderVal)
@@ -19,26 +22,54 @@ export function textInput(name: string) {
19
22
  )
20
23
  }
21
24
 
25
+ function getLabel() {
26
+ if (!labelVal)
27
+ return 'Your response'
28
+ return Hooks.callHook(
29
+ 'transformUserFacingText',
30
+ labelVal,
31
+ { component: 'TextInput', position: 'label' }
32
+ )
33
+ }
34
+
22
35
  const out = {
23
36
  ...createComponent('TextInput', () => ({
24
37
  type: ComponentType.TextInput,
25
38
  placeholder: getPlaceholder(),
39
+ label: getLabel(),
26
40
  min_length: minLength,
27
41
  max_length: maxLength,
28
42
  required: requiredVal,
29
43
  size: sizeVal ?? 1,
30
- custom_id: name
44
+ value: currentVal,
45
+ custom_id: ref
31
46
  })),
32
47
 
48
+ as: (id: string) => {
49
+ ref = id
50
+ return out
51
+ },
33
52
  placeholder: (text: string) => {
34
53
  placeholderVal = text
35
54
  return out
36
55
  },
37
- min: (num: number = 1) => {
56
+ label: (text: string) => {
57
+ labelVal = text
58
+ return out
59
+ },
60
+ current: (text: string) => {
61
+ currentVal = text
62
+ return out
63
+ },
64
+ min: (num: number = 0) => {
65
+ if (num < 0) num = 0
66
+ if (num > 4000) num = 4000
38
67
  minLength = num
39
68
  return out
40
69
  },
41
- max: (num: number = 25) => {
70
+ max: (num: number = 4000) => {
71
+ if (num < 1) num = 1
72
+ if (num > 4000) num = 4000
42
73
  maxLength = num
43
74
  return out
44
75
  },
@@ -138,7 +138,7 @@ export function renderComponentList(
138
138
  continue
139
139
  }
140
140
 
141
- if (parsed.nativeName === 'StringSelect') {
141
+ if (parsed.nativeName === 'StringSelect' || parsed.nativeName === 'TextInput') {
142
142
  if (rowBuilder.length > 0) {
143
143
  pipeline.push(readComponent(row(...rowBuilder as any)))
144
144
  rowBuilder.splice(0)