@budibase/frontend-core 2.8.29-alpha.5 → 2.8.29-alpha.7

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,17 +1,17 @@
1
1
  {
2
2
  "name": "@budibase/frontend-core",
3
- "version": "2.8.29-alpha.5",
3
+ "version": "2.8.29-alpha.7",
4
4
  "description": "Budibase frontend core libraries used in builder and client",
5
5
  "author": "Budibase",
6
6
  "license": "MPL-2.0",
7
7
  "svelte": "src/index.js",
8
8
  "dependencies": {
9
- "@budibase/bbui": "2.8.29-alpha.5",
10
- "@budibase/shared-core": "2.8.29-alpha.5",
9
+ "@budibase/bbui": "2.8.29-alpha.7",
10
+ "@budibase/shared-core": "2.8.29-alpha.7",
11
11
  "dayjs": "^1.11.7",
12
12
  "lodash": "^4.17.21",
13
13
  "socket.io-client": "^4.6.1",
14
14
  "svelte": "^3.46.2"
15
15
  },
16
- "gitHead": "51a46a236606dfc158218904951ff776994d9e5b"
16
+ "gitHead": "97abef1bfaf70097b5dbcaae302a27b9de11da97"
17
17
  }
@@ -1,7 +1,7 @@
1
1
  <script>
2
- import { getContext } from "svelte"
2
+ import { getContext, onMount, tick } from "svelte"
3
3
  import GridCell from "./GridCell.svelte"
4
- import { Icon, Popover, Menu, MenuItem } from "@budibase/bbui"
4
+ import { Icon, Popover, Menu, MenuItem, clickOutside } from "@budibase/bbui"
5
5
  import { getColumnIcon } from "../lib/utils"
6
6
 
7
7
  export let column
@@ -16,6 +16,7 @@
16
16
  sort,
17
17
  renderedColumns,
18
18
  dispatch,
19
+ subscribe,
19
20
  config,
20
21
  ui,
21
22
  columns,
@@ -32,7 +33,9 @@
32
33
 
33
34
  let anchor
34
35
  let open = false
36
+ let editIsOpen = false
35
37
  let timeout
38
+ let popover
36
39
 
37
40
  $: sortedBy = column.name === $sort.column
38
41
  $: canMoveLeft = orderable && idx > 0
@@ -44,11 +47,16 @@
44
47
  ? "high-low"
45
48
  : "Z-A"
46
49
 
47
- const editColumn = () => {
50
+ const editColumn = async () => {
51
+ editIsOpen = true
52
+ await tick()
48
53
  dispatch("edit-column", column.schema)
49
- open = false
50
54
  }
51
55
 
56
+ const cancelEdit = () => {
57
+ popover.hide()
58
+ editIsOpen = false
59
+ }
52
60
  const onMouseDown = e => {
53
61
  if (e.button === 0 && orderable) {
54
62
  timeout = setTimeout(() => {
@@ -109,6 +117,7 @@
109
117
  columns.actions.saveChanges()
110
118
  open = false
111
119
  }
120
+ onMount(() => subscribe("close-edit-column", cancelEdit))
112
121
  </script>
113
122
 
114
123
  <div
@@ -157,57 +166,74 @@
157
166
 
158
167
  <Popover
159
168
  bind:open
169
+ bind:this={popover}
160
170
  {anchor}
161
171
  align="right"
162
172
  offset={0}
163
173
  popoverTarget={document.getElementById(`grid-${rand}`)}
164
174
  animate={false}
175
+ customZindex={100}
165
176
  >
166
- <Menu>
167
- <MenuItem
168
- icon="Edit"
169
- on:click={editColumn}
170
- disabled={!$config.allowSchemaChanges || column.schema.disabled}
171
- >
172
- Edit column
173
- </MenuItem>
174
- <MenuItem
175
- icon="Label"
176
- on:click={makeDisplayColumn}
177
- disabled={idx === "sticky" ||
178
- !$config.allowSchemaChanges ||
179
- bannedDisplayColumnTypes.includes(column.schema.type)}
180
- >
181
- Use as display column
182
- </MenuItem>
183
- <MenuItem
184
- icon="SortOrderUp"
185
- on:click={sortAscending}
186
- disabled={column.name === $sort.column && $sort.order === "ascending"}
187
- >
188
- Sort {ascendingLabel}
189
- </MenuItem>
190
- <MenuItem
191
- icon="SortOrderDown"
192
- on:click={sortDescending}
193
- disabled={column.name === $sort.column && $sort.order === "descending"}
177
+ {#if editIsOpen}
178
+ <div
179
+ use:clickOutside={() => {
180
+ editIsOpen = false
181
+ }}
182
+ class="content"
194
183
  >
195
- Sort {descendingLabel}
196
- </MenuItem>
197
- <MenuItem disabled={!canMoveLeft} icon="ChevronLeft" on:click={moveLeft}>
198
- Move left
199
- </MenuItem>
200
- <MenuItem disabled={!canMoveRight} icon="ChevronRight" on:click={moveRight}>
201
- Move right
202
- </MenuItem>
203
- <MenuItem
204
- disabled={idx === "sticky" || !$config.showControls}
205
- icon="VisibilityOff"
206
- on:click={hideColumn}
207
- >
208
- Hide column
209
- </MenuItem>
210
- </Menu>
184
+ <slot />
185
+ </div>
186
+ {:else}
187
+ <Menu>
188
+ <MenuItem
189
+ icon="Edit"
190
+ on:click={editColumn}
191
+ disabled={!$config.allowSchemaChanges || column.schema.disabled}
192
+ >
193
+ Edit column
194
+ </MenuItem>
195
+ <MenuItem
196
+ icon="Label"
197
+ on:click={makeDisplayColumn}
198
+ disabled={idx === "sticky" ||
199
+ !$config.allowSchemaChanges ||
200
+ bannedDisplayColumnTypes.includes(column.schema.type)}
201
+ >
202
+ Use as display column
203
+ </MenuItem>
204
+ <MenuItem
205
+ icon="SortOrderUp"
206
+ on:click={sortAscending}
207
+ disabled={column.name === $sort.column && $sort.order === "ascending"}
208
+ >
209
+ Sort {ascendingLabel}
210
+ </MenuItem>
211
+ <MenuItem
212
+ icon="SortOrderDown"
213
+ on:click={sortDescending}
214
+ disabled={column.name === $sort.column && $sort.order === "descending"}
215
+ >
216
+ Sort {descendingLabel}
217
+ </MenuItem>
218
+ <MenuItem disabled={!canMoveLeft} icon="ChevronLeft" on:click={moveLeft}>
219
+ Move left
220
+ </MenuItem>
221
+ <MenuItem
222
+ disabled={!canMoveRight}
223
+ icon="ChevronRight"
224
+ on:click={moveRight}
225
+ >
226
+ Move right
227
+ </MenuItem>
228
+ <MenuItem
229
+ disabled={idx === "sticky" || !$config.showControls}
230
+ icon="VisibilityOff"
231
+ on:click={hideColumn}
232
+ >
233
+ Hide column
234
+ </MenuItem>
235
+ </Menu>
236
+ {/if}
211
237
  </Popover>
212
238
 
213
239
  <style>
@@ -255,4 +281,13 @@
255
281
  .header-cell:hover .sort-indicator {
256
282
  display: none;
257
283
  }
284
+
285
+ .content {
286
+ width: 300px;
287
+ padding: 20px;
288
+ display: flex;
289
+ flex-direction: column;
290
+ gap: 20px;
291
+ background: var(--spectrum-alias-background-color-secondary);
292
+ }
258
293
  </style>
@@ -18,6 +18,7 @@
18
18
  let focusedOptionIdx = null
19
19
 
20
20
  $: options = schema?.constraints?.inclusion || []
21
+ $: optionColors = schema?.optionColors || {}
21
22
  $: editable = focused && !readonly
22
23
  $: values = Array.isArray(value) ? value : [value].filter(x => x != null)
23
24
  $: {
@@ -93,7 +94,7 @@
93
94
  on:click={editable ? open : null}
94
95
  >
95
96
  {#each values as val}
96
- {@const color = getOptionColor(val)}
97
+ {@const color = optionColors[val] || getOptionColor(val)}
97
98
  {#if color}
98
99
  <div class="badge text" style="--color: {color}">
99
100
  <span>
@@ -121,7 +122,7 @@
121
122
  use:clickOutside={close}
122
123
  >
123
124
  {#each options as option, idx}
124
- {@const color = getOptionColor(option)}
125
+ {@const color = optionColors[option] || getOptionColor(option)}
125
126
  <div
126
127
  class="option"
127
128
  on:click={() => toggleOption(option)}
@@ -139,9 +139,20 @@
139
139
  {#if $loaded}
140
140
  <div class="grid-data-outer" use:clickOutside={ui.actions.blur}>
141
141
  <div class="grid-data-inner">
142
- <StickyColumn />
142
+ <StickyColumn>
143
+ <svelte:fragment slot="edit-column">
144
+ <slot name="edit-column" />
145
+ </svelte:fragment>
146
+ </StickyColumn>
143
147
  <div class="grid-data-content">
144
- <HeaderRow />
148
+ <HeaderRow>
149
+ <svelte:fragment slot="add-column">
150
+ <slot name="add-column" />
151
+ </svelte:fragment>
152
+ <svelte:fragment slot="edit-column">
153
+ <slot name="edit-column" />
154
+ </svelte:fragment>
155
+ </HeaderRow>
145
156
  <GridBody />
146
157
  </div>
147
158
  {#if $canAddRows}
@@ -1,34 +1,22 @@
1
1
  <script>
2
+ import NewColumnButton from "./NewColumnButton.svelte"
3
+
2
4
  import { getContext } from "svelte"
3
5
  import GridScrollWrapper from "./GridScrollWrapper.svelte"
4
6
  import HeaderCell from "../cells/HeaderCell.svelte"
5
- import { Icon, TempTooltip, TooltipType } from "@budibase/bbui"
6
-
7
- const {
8
- renderedColumns,
9
- dispatch,
10
- scroll,
11
- hiddenColumnsWidth,
12
- width,
13
- config,
14
- hasNonAutoColumn,
15
- tableId,
16
- loading,
17
- } = getContext("grid")
7
+ import { TempTooltip, TooltipType } from "@budibase/bbui"
18
8
 
19
- $: columnsWidth = $renderedColumns.reduce(
20
- (total, col) => total + col.width,
21
- 0
22
- )
23
- $: end = $hiddenColumnsWidth + columnsWidth - 1 - $scroll.left
24
- $: left = Math.min($width - 40, end)
9
+ const { renderedColumns, config, hasNonAutoColumn, tableId, loading } =
10
+ getContext("grid")
25
11
  </script>
26
12
 
27
13
  <div class="header">
28
14
  <GridScrollWrapper scrollHorizontally>
29
15
  <div class="row">
30
16
  {#each $renderedColumns as column, idx}
31
- <HeaderCell {column} {idx} />
17
+ <HeaderCell {column} {idx}>
18
+ <slot name="edit-column" />
19
+ </HeaderCell>
32
20
  {/each}
33
21
  </div>
34
22
  </GridScrollWrapper>
@@ -39,13 +27,9 @@
39
27
  type={TooltipType.Info}
40
28
  condition={!$hasNonAutoColumn && !$loading}
41
29
  >
42
- <div
43
- class="add"
44
- style="left:{left}px;"
45
- on:click={() => dispatch("add-column")}
46
- >
47
- <Icon name="Add" />
48
- </div>
30
+ <NewColumnButton>
31
+ <slot name="add-column" />
32
+ </NewColumnButton>
49
33
  </TempTooltip>
50
34
  {/key}
51
35
  {/if}
@@ -61,21 +45,4 @@
61
45
  .row {
62
46
  display: flex;
63
47
  }
64
- .add {
65
- height: var(--default-row-height);
66
- display: grid;
67
- place-items: center;
68
- width: 40px;
69
- position: absolute;
70
- top: 0;
71
- border-left: var(--cell-border);
72
- border-right: var(--cell-border);
73
- border-bottom: var(--cell-border);
74
- background: var(--grid-background-alt);
75
- z-index: 1;
76
- }
77
- .add:hover {
78
- background: var(--spectrum-global-color-gray-200);
79
- cursor: pointer;
80
- }
81
48
  </style>
@@ -0,0 +1,79 @@
1
+ <script>
2
+ import { getContext, onMount } from "svelte"
3
+ import { Icon, Popover, clickOutside } from "@budibase/bbui"
4
+
5
+ const { renderedColumns, scroll, hiddenColumnsWidth, width, subscribe } =
6
+ getContext("grid")
7
+
8
+ let anchor
9
+ let open = false
10
+ $: columnsWidth = $renderedColumns.reduce(
11
+ (total, col) => (total += col.width),
12
+ 0
13
+ )
14
+ $: end = $hiddenColumnsWidth + columnsWidth - 1 - $scroll.left
15
+ $: left = Math.min($width - 40, end)
16
+
17
+ const close = () => {
18
+ open = false
19
+ }
20
+ onMount(() => subscribe("close-edit-column", close))
21
+ </script>
22
+
23
+ <div
24
+ id="add-column-button"
25
+ bind:this={anchor}
26
+ class="add"
27
+ style="left:{left}px"
28
+ on:click={() => (open = true)}
29
+ >
30
+ <Icon name="Add" />
31
+ </div>
32
+ <Popover
33
+ bind:open
34
+ {anchor}
35
+ align="right"
36
+ offset={0}
37
+ popoverTarget={document.getElementById(`add-column-button`)}
38
+ animate={false}
39
+ customZindex={100}
40
+ >
41
+ <div
42
+ use:clickOutside={() => {
43
+ open = false
44
+ }}
45
+ class="content"
46
+ >
47
+ <slot />
48
+ </div>
49
+ </Popover>
50
+
51
+ <style>
52
+ .add {
53
+ height: var(--default-row-height);
54
+ display: grid;
55
+ place-items: center;
56
+ width: 40px;
57
+ position: absolute;
58
+ top: 0;
59
+ border-left: var(--cell-border);
60
+ border-right: var(--cell-border);
61
+ border-bottom: var(--cell-border);
62
+ background: var(--grid-background-alt);
63
+ z-index: 1;
64
+ }
65
+ .add:hover {
66
+ background: var(--spectrum-global-color-gray-200);
67
+ cursor: pointer;
68
+ }
69
+
70
+ .content {
71
+ width: 300px;
72
+ padding: 20px;
73
+ display: flex;
74
+ flex-direction: column;
75
+ gap: 20px;
76
+ z-index: 2;
77
+ background: var(--spectrum-alias-background-color-secondary);
78
+ }
79
+ </style>
@@ -57,7 +57,9 @@
57
57
  disabled={!$renderedRows.length}
58
58
  />
59
59
  {#if $stickyColumn}
60
- <HeaderCell column={$stickyColumn} orderable={false} idx="sticky" />
60
+ <HeaderCell column={$stickyColumn} orderable={false} idx="sticky">
61
+ <slot name="edit-column" />
62
+ </HeaderCell>
61
63
  {/if}
62
64
  </div>
63
65