@budibase/bbui 2.2.12-alpha.44 → 2.2.12-alpha.46

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,7 +1,7 @@
1
1
  {
2
2
  "name": "@budibase/bbui",
3
3
  "description": "A UI solution used in the different Budibase projects.",
4
- "version": "2.2.12-alpha.44",
4
+ "version": "2.2.12-alpha.46",
5
5
  "license": "MPL-2.0",
6
6
  "svelte": "src/index.js",
7
7
  "module": "dist/bbui.es.js",
@@ -38,7 +38,7 @@
38
38
  ],
39
39
  "dependencies": {
40
40
  "@adobe/spectrum-css-workflow-icons": "1.2.1",
41
- "@budibase/string-templates": "2.2.12-alpha.44",
41
+ "@budibase/string-templates": "2.2.12-alpha.46",
42
42
  "@spectrum-css/accordion": "3.0.24",
43
43
  "@spectrum-css/actionbutton": "1.0.1",
44
44
  "@spectrum-css/actiongroup": "1.0.1",
@@ -89,5 +89,5 @@
89
89
  "resolutions": {
90
90
  "loader-utils": "1.4.1"
91
91
  },
92
- "gitHead": "c32d7662664662455be9bfef8bfedad89d208903"
92
+ "gitHead": "7b6d2fbb2fedbd3b6872e830c7961b75004ea04b"
93
93
  }
@@ -0,0 +1,282 @@
1
+ <script>
2
+ import "@spectrum-css/textfield/dist/index-vars.css"
3
+ import { createEventDispatcher, onMount } from "svelte"
4
+ import clickOutside from "../../Actions/click_outside"
5
+ import Divider from "../../Divider/Divider.svelte"
6
+
7
+ export let value = null
8
+ export let placeholder = null
9
+ export let type = "text"
10
+ export let disabled = false
11
+ export let id = null
12
+ export let readonly = false
13
+ export let updateOnChange = true
14
+ export let dataCy
15
+ export let align
16
+ export let autofocus = false
17
+ export let variables
18
+ export let showModal
19
+ export let environmentVariablesEnabled
20
+ export let handleUpgradePanel
21
+ const dispatch = createEventDispatcher()
22
+
23
+ let field
24
+ let focus = false
25
+ let iconFocused = false
26
+ let open = false
27
+
28
+ //eslint-disable-next-line
29
+ const STRIP_NAME_REGEX = /(?<=\.)(.*?)(?=\ })/g
30
+
31
+ // Strips the name out of the value which is {{ env.Variable }} resulting in an array like ["Variable"]
32
+ $: hbsValue = String(value)?.match(STRIP_NAME_REGEX) || []
33
+
34
+ const updateValue = newValue => {
35
+ if (readonly) {
36
+ return
37
+ }
38
+ if (type === "number") {
39
+ const float = parseFloat(newValue)
40
+ newValue = isNaN(float) ? null : float
41
+ }
42
+ dispatch("change", newValue)
43
+ }
44
+
45
+ const onFocus = () => {
46
+ if (readonly) {
47
+ return
48
+ }
49
+ focus = true
50
+ }
51
+
52
+ const onBlur = event => {
53
+ if (readonly) {
54
+ return
55
+ }
56
+ focus = false
57
+ updateValue(event.target.value)
58
+ }
59
+
60
+ const onInput = event => {
61
+ if (readonly || !updateOnChange) {
62
+ return
63
+ }
64
+ updateValue(event.target.value)
65
+ }
66
+
67
+ const handleOutsideClick = event => {
68
+ if (open) {
69
+ event.stopPropagation()
70
+ open = false
71
+ focus = false
72
+ iconFocused = false
73
+ dispatch("closed")
74
+ }
75
+ }
76
+
77
+ const handleVarSelect = variable => {
78
+ open = false
79
+ focus = false
80
+ iconFocused = false
81
+ updateValue(`{{ env.${variable} }}`)
82
+ }
83
+
84
+ onMount(() => {
85
+ focus = autofocus
86
+ if (focus) field.focus()
87
+ })
88
+
89
+ function removeVariable() {
90
+ updateValue("")
91
+ }
92
+
93
+ function openPopover() {
94
+ open = true
95
+ focus = true
96
+ iconFocused = true
97
+ }
98
+ </script>
99
+
100
+ <div class="spectrum-InputGroup">
101
+ <div
102
+ class:is-disabled={disabled || hbsValue.length}
103
+ class:is-focused={focus}
104
+ class="spectrum-Textfield"
105
+ >
106
+ <svg
107
+ class:close-color={hbsValue.length}
108
+ class:focused={iconFocused}
109
+ class="hoverable icon-position spectrum-Icon spectrum-Icon--sizeS spectrum-Textfield-validationIcon"
110
+ focusable="false"
111
+ aria-hidden="true"
112
+ on:click={() => {
113
+ hbsValue.length ? removeVariable() : openPopover()
114
+ }}
115
+ >
116
+ <use
117
+ xlink:href={`#spectrum-icon-18-${!hbsValue.length ? "Key" : "Close"}`}
118
+ />
119
+ </svg>
120
+
121
+ <input
122
+ bind:this={field}
123
+ disabled={hbsValue.length || disabled}
124
+ {readonly}
125
+ {id}
126
+ data-cy={dataCy}
127
+ value={hbsValue.length ? `{{ ${hbsValue[0]} }}` : value}
128
+ placeholder={placeholder || ""}
129
+ on:click
130
+ on:blur
131
+ on:focus
132
+ on:input
133
+ on:keyup
134
+ on:blur={onBlur}
135
+ on:focus={onFocus}
136
+ on:input={onInput}
137
+ {type}
138
+ style={align ? `text-align: ${align};` : ""}
139
+ class="spectrum-Textfield-input"
140
+ inputmode={type === "number" ? "decimal" : "text"}
141
+ />
142
+ </div>
143
+ {#if open}
144
+ <div
145
+ use:clickOutside={handleOutsideClick}
146
+ class="spectrum-Popover spectrum-Popover--bottom spectrum-Picker-popover is-open"
147
+ >
148
+ <ul class="spectrum-Menu" role="listbox">
149
+ {#if !environmentVariablesEnabled}
150
+ <div class="no-variables-text primary-text">
151
+ Upgrade your plan to get environment variables
152
+ </div>
153
+ {:else if variables.length}
154
+ <div style="max-height: 100px">
155
+ {#each variables as variable, idx}
156
+ <li
157
+ class="spectrum-Menu-item"
158
+ role="option"
159
+ aria-selected="true"
160
+ tabindex="0"
161
+ on:click={() => handleVarSelect(variable.name)}
162
+ >
163
+ <span class="spectrum-Menu-itemLabel">
164
+ <div class="primary-text">
165
+ {variable.name}
166
+ <span />
167
+ </div>
168
+ <svg
169
+ class="spectrum-Icon spectrum-UIIcon-Checkmark100 spectrum-Menu-checkmark spectrum-Menu-itemIcon"
170
+ focusable="false"
171
+ aria-hidden="true"
172
+ >
173
+ <use xlink:href="#spectrum-css-icon-Checkmark100" />
174
+ </svg>
175
+ </span>
176
+ </li>
177
+ {/each}
178
+ </div>
179
+ {:else}
180
+ <div class="no-variables-text primary-text">
181
+ You don't have any environment variables yet
182
+ </div>
183
+ {/if}
184
+ </ul>
185
+ <Divider noMargin />
186
+ {#if environmentVariablesEnabled}
187
+ <div on:click={() => showModal()} class="add-variable">
188
+ <svg
189
+ class="spectrum-Icon spectrum-Icon--sizeS "
190
+ focusable="false"
191
+ aria-hidden="true"
192
+ >
193
+ <use xlink:href="#spectrum-icon-18-Add" />
194
+ </svg>
195
+ <div class="primary-text">Add Variable</div>
196
+ </div>
197
+ {:else}
198
+ <div on:click={() => handleUpgradePanel()} class="add-variable">
199
+ <svg
200
+ class="spectrum-Icon spectrum-Icon--sizeS "
201
+ focusable="false"
202
+ aria-hidden="true"
203
+ >
204
+ <use xlink:href="#spectrum-icon-18-ArrowUp" />
205
+ </svg>
206
+ <div class="primary-text">Upgrade plan</div>
207
+ </div>
208
+ {/if}
209
+ </div>
210
+ {/if}
211
+ </div>
212
+
213
+ <style>
214
+ .spectrum-Textfield {
215
+ width: 100%;
216
+ }
217
+
218
+ .icon-position {
219
+ position: absolute;
220
+ top: 25%;
221
+ right: 2%;
222
+ }
223
+
224
+ .hoverable:hover {
225
+ cursor: pointer;
226
+ color: var(--spectrum-global-color-blue-400);
227
+ }
228
+
229
+ .primary-text {
230
+ white-space: nowrap;
231
+ overflow: hidden;
232
+ text-overflow: ellipsis;
233
+ }
234
+
235
+ .spectrum-InputGroup {
236
+ min-width: 0;
237
+ width: 100%;
238
+ }
239
+
240
+ .spectrum-Popover {
241
+ max-height: 240px;
242
+ z-index: 999;
243
+ top: 100%;
244
+ }
245
+
246
+ .spectrum-Popover.spectrum-Popover--bottom.spectrum-Picker-popover.is-open {
247
+ width: 100%;
248
+ }
249
+
250
+ .no-variables-height {
251
+ height: 100px;
252
+ }
253
+
254
+ .no-variables-text {
255
+ padding: var(--spacing-m);
256
+ color: var(--spectrum-global-color-gray-600);
257
+ }
258
+
259
+ .add-variable {
260
+ display: flex;
261
+ padding: var(--spacing-m) 0 var(--spacing-m) var(--spacing-m);
262
+ align-items: center;
263
+ gap: var(--spacing-s);
264
+ cursor: pointer;
265
+ }
266
+
267
+ .focused {
268
+ color: var(--spectrum-global-color-blue-400);
269
+ }
270
+
271
+ .add-variable:hover {
272
+ background: var(--grey-1);
273
+ }
274
+
275
+ .close-color {
276
+ color: var(--spectrum-global-color-gray-900) !important;
277
+ }
278
+
279
+ .close-color:hover {
280
+ color: var(--spectrum-global-color-blue-400) !important;
281
+ }
282
+ </style>
@@ -0,0 +1,52 @@
1
+ <script>
2
+ import Field from "./Field.svelte"
3
+ import EnvDropdown from "./Core/EnvDropdown.svelte"
4
+ import { createEventDispatcher } from "svelte"
5
+
6
+ export let value = null
7
+ export let label = null
8
+ export let labelPosition = "above"
9
+ export let placeholder = null
10
+ export let type = "text"
11
+ export let disabled = false
12
+ export let readonly = false
13
+ export let error = null
14
+ export let updateOnChange = true
15
+ export let quiet = false
16
+ export let dataCy
17
+ export let autofocus
18
+ export let variables
19
+ export let showModal
20
+ export let environmentVariablesEnabled
21
+ export let handleUpgradePanel
22
+ const dispatch = createEventDispatcher()
23
+ const onChange = e => {
24
+ value = e.detail
25
+ dispatch("change", e.detail)
26
+ }
27
+ </script>
28
+
29
+ <Field {label} {labelPosition} {error}>
30
+ <EnvDropdown
31
+ {dataCy}
32
+ {updateOnChange}
33
+ {error}
34
+ {disabled}
35
+ {readonly}
36
+ {value}
37
+ {placeholder}
38
+ {type}
39
+ {quiet}
40
+ {autofocus}
41
+ {variables}
42
+ {showModal}
43
+ {environmentVariablesEnabled}
44
+ {handleUpgradePanel}
45
+ on:change={onChange}
46
+ on:click
47
+ on:input
48
+ on:blur
49
+ on:focus
50
+ on:keyup
51
+ />
52
+ </Field>
package/src/index.js CHANGED
@@ -27,6 +27,7 @@ export { default as RadioGroup } from "./Form/RadioGroup.svelte"
27
27
  export { default as Checkbox } from "./Form/Checkbox.svelte"
28
28
  export { default as InputDropdown } from "./Form/InputDropdown.svelte"
29
29
  export { default as PickerDropdown } from "./Form/PickerDropdown.svelte"
30
+ export { default as EnvDropdown } from "./Form/EnvDropdown.svelte"
30
31
  export { default as DetailSummary } from "./DetailSummary/DetailSummary.svelte"
31
32
  export { default as Popover } from "./Popover/Popover.svelte"
32
33
  export { default as ProgressBar } from "./ProgressBar/ProgressBar.svelte"