cordo 2.3.0 → 2.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cordo",
3
- "version": "2.3.0",
3
+ "version": "2.3.3",
4
4
  "description": "A framework for handling complex discord api interactions",
5
5
  "exports": {
6
6
  ".": "./src/index.ts",
@@ -0,0 +1,91 @@
1
+ import { ComponentType, createComponent } from "../component"
2
+ import { Hooks } from "../../core/hooks"
3
+
4
+
5
+ export function textInput() {
6
+ let placeholderVal: string | undefined = undefined
7
+ let labelVal: string | undefined = undefined
8
+ let minLength: number | undefined = undefined
9
+ let maxLength: number | undefined = undefined
10
+ let requiredVal: boolean | undefined = undefined
11
+ let sizeVal: number | undefined = undefined
12
+ let currentVal: string | undefined = undefined
13
+ let ref: string | undefined = undefined
14
+
15
+ function getPlaceholder() {
16
+ if (!placeholderVal)
17
+ return undefined
18
+ return Hooks.callHook(
19
+ 'transformUserFacingText',
20
+ placeholderVal,
21
+ { component: 'TextInput', position: 'placeholder' }
22
+ )
23
+ }
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
+
35
+ const out = {
36
+ ...createComponent('TextInput', () => ({
37
+ type: ComponentType.TextInput,
38
+ placeholder: getPlaceholder(),
39
+ label: getLabel(),
40
+ min_length: minLength,
41
+ max_length: maxLength,
42
+ required: requiredVal,
43
+ size: sizeVal ?? 1,
44
+ value: currentVal,
45
+ custom_id: ref
46
+ })),
47
+
48
+ as: (id: string) => {
49
+ ref = id
50
+ return out
51
+ },
52
+ placeholder: (text: string) => {
53
+ placeholderVal = text
54
+ return out
55
+ },
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
67
+ minLength = num
68
+ return out
69
+ },
70
+ max: (num: number = 4000) => {
71
+ if (num < 1) num = 1
72
+ if (num > 4000) num = 4000
73
+ maxLength = num
74
+ return out
75
+ },
76
+ required(required = true) {
77
+ requiredVal = required
78
+ return out
79
+ },
80
+ size: (size: 'single' | 'multi') => {
81
+ sizeVal = (size === 'single')
82
+ ? 1
83
+ : (size === 'multi')
84
+ ? 2
85
+ : undefined
86
+ return out
87
+ }
88
+ }
89
+
90
+ return out
91
+ }
@@ -22,6 +22,7 @@ export { section } from './builtin/section'
22
22
  export { selectString } from './builtin/select-string'
23
23
  export { skuButton } from './builtin/sku-button'
24
24
  export { spacer } from './builtin/spacer'
25
+ export { textInput } from './builtin/text-input'
25
26
  export { text } from './builtin/text'
26
27
 
27
28
  export { debugIdToLabel } from './mods/debug-id-to-label'