@budibase/frontend-core 2.5.6-alpha.4 → 2.5.6-alpha.41

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.
Files changed (67) hide show
  1. package/package.json +6 -4
  2. package/src/api/other.js +0 -9
  3. package/src/components/grid/cells/AttachmentCell.svelte +154 -0
  4. package/src/components/grid/cells/BooleanCell.svelte +44 -0
  5. package/src/components/grid/cells/DataCell.svelte +91 -0
  6. package/src/components/grid/cells/DateCell.svelte +77 -0
  7. package/src/components/grid/cells/FormulaCell.svelte +5 -0
  8. package/src/components/grid/cells/GridCell.svelte +165 -0
  9. package/src/components/grid/cells/GutterCell.svelte +127 -0
  10. package/src/components/grid/cells/HeaderCell.svelte +248 -0
  11. package/src/components/grid/cells/JSONCell.svelte +36 -0
  12. package/src/components/grid/cells/LongFormCell.svelte +122 -0
  13. package/src/components/grid/cells/MultiSelectCell.svelte +7 -0
  14. package/src/components/grid/cells/NumberCell.svelte +14 -0
  15. package/src/components/grid/cells/OptionsCell.svelte +249 -0
  16. package/src/components/grid/cells/RelationshipCell.svelte +518 -0
  17. package/src/components/grid/cells/TextCell.svelte +111 -0
  18. package/src/components/grid/controls/AddColumnButton.svelte +16 -0
  19. package/src/components/grid/controls/AddRowButton.svelte +18 -0
  20. package/src/components/grid/controls/BetaButton.svelte +46 -0
  21. package/src/components/grid/controls/ColumnWidthButton.svelte +91 -0
  22. package/src/components/grid/controls/DeleteButton.svelte +66 -0
  23. package/src/components/grid/controls/HideColumnsButton.svelte +95 -0
  24. package/src/components/grid/controls/RowHeightButton.svelte +70 -0
  25. package/src/components/grid/controls/SortButton.svelte +129 -0
  26. package/src/components/grid/index.js +1 -0
  27. package/src/components/grid/layout/Avatar.svelte +24 -0
  28. package/src/components/grid/layout/Grid.svelte +254 -0
  29. package/src/components/grid/layout/GridBody.svelte +73 -0
  30. package/src/components/grid/layout/GridRow.svelte +59 -0
  31. package/src/components/grid/layout/GridScrollWrapper.svelte +81 -0
  32. package/src/components/grid/layout/HeaderRow.svelte +62 -0
  33. package/src/components/grid/layout/KeyboardShortcut.svelte +53 -0
  34. package/src/components/grid/layout/NewRow.svelte +334 -0
  35. package/src/components/grid/layout/RowCount.svelte +9 -0
  36. package/src/components/grid/layout/StickyColumn.svelte +176 -0
  37. package/src/components/grid/layout/UserAvatars.svelte +20 -0
  38. package/src/components/grid/lib/constants.js +14 -0
  39. package/src/components/grid/lib/events.js +29 -0
  40. package/src/components/grid/lib/renderers.js +29 -0
  41. package/src/components/grid/lib/utils.js +26 -0
  42. package/src/components/grid/lib/websocket.js +63 -0
  43. package/src/components/grid/overlays/KeyboardManager.svelte +232 -0
  44. package/src/components/grid/overlays/MenuOverlay.svelte +96 -0
  45. package/src/components/grid/overlays/ReorderOverlay.svelte +63 -0
  46. package/src/components/grid/overlays/ResizeOverlay.svelte +70 -0
  47. package/src/components/grid/overlays/ScrollOverlay.svelte +121 -0
  48. package/src/components/grid/stores/bounds.js +16 -0
  49. package/src/components/grid/stores/clipboard.js +34 -0
  50. package/src/components/grid/stores/columns.js +206 -0
  51. package/src/components/grid/stores/index.js +48 -0
  52. package/src/components/grid/stores/menu.js +49 -0
  53. package/src/components/grid/stores/pagination.js +24 -0
  54. package/src/components/grid/stores/reorder.js +155 -0
  55. package/src/components/grid/stores/resize.js +124 -0
  56. package/src/components/grid/stores/rows.js +467 -0
  57. package/src/components/grid/stores/scroll.js +201 -0
  58. package/src/components/grid/stores/ui.js +159 -0
  59. package/src/components/grid/stores/users.js +115 -0
  60. package/src/components/grid/stores/validation.js +45 -0
  61. package/src/components/grid/stores/viewport.js +145 -0
  62. package/src/components/index.js +1 -0
  63. package/src/fetch/DataFetch.js +27 -21
  64. package/src/fetch/QueryFetch.js +1 -1
  65. package/src/themes/midnight.css +3 -0
  66. package/src/themes/nord.css +3 -0
  67. package/src/utils/utils.js +20 -0
@@ -0,0 +1,91 @@
1
+ <script>
2
+ import { getContext } from "svelte"
3
+ import { ActionButton, Popover } from "@budibase/bbui"
4
+ import { DefaultColumnWidth } from "../lib/constants"
5
+
6
+ const { stickyColumn, columns } = getContext("grid")
7
+ const smallSize = 120
8
+ const mediumSize = DefaultColumnWidth
9
+ const largeSize = DefaultColumnWidth * 1.5
10
+
11
+ let open = false
12
+ let anchor
13
+
14
+ $: allCols = $columns.concat($stickyColumn ? [$stickyColumn] : [])
15
+ $: allSmall = allCols.every(col => col.width === smallSize)
16
+ $: allMedium = allCols.every(col => col.width === mediumSize)
17
+ $: allLarge = allCols.every(col => col.width === largeSize)
18
+ $: custom = !allSmall && !allMedium && !allLarge
19
+ $: sizeOptions = [
20
+ {
21
+ label: "Small",
22
+ size: smallSize,
23
+ selected: allSmall,
24
+ },
25
+ {
26
+ label: "Medium",
27
+ size: mediumSize,
28
+ selected: allMedium,
29
+ },
30
+ {
31
+ label: "Large",
32
+ size: largeSize,
33
+ selected: allLarge,
34
+ },
35
+ ]
36
+
37
+ const changeColumnWidth = async width => {
38
+ columns.update(state => {
39
+ state.forEach(column => {
40
+ column.width = width
41
+ })
42
+ return state
43
+ })
44
+ if ($stickyColumn) {
45
+ stickyColumn.update(state => ({
46
+ ...state,
47
+ width,
48
+ }))
49
+ }
50
+ await columns.actions.saveChanges()
51
+ }
52
+ </script>
53
+
54
+ <div bind:this={anchor}>
55
+ <ActionButton
56
+ icon="MoveLeftRight"
57
+ quiet
58
+ size="M"
59
+ on:click={() => (open = !open)}
60
+ selected={open}
61
+ disabled={!allCols.length}
62
+ >
63
+ Width
64
+ </ActionButton>
65
+ </div>
66
+
67
+ <Popover bind:open {anchor} align="left">
68
+ <div class="content">
69
+ {#each sizeOptions as option}
70
+ <ActionButton
71
+ quiet
72
+ on:click={() => changeColumnWidth(option.size)}
73
+ selected={option.selected}
74
+ >
75
+ {option.label}
76
+ </ActionButton>
77
+ {/each}
78
+ {#if custom}
79
+ <ActionButton selected={custom} quiet>Custom</ActionButton>
80
+ {/if}
81
+ </div>
82
+ </Popover>
83
+
84
+ <style>
85
+ .content {
86
+ padding: 12px;
87
+ display: flex;
88
+ align-items: center;
89
+ gap: 8px;
90
+ }
91
+ </style>
@@ -0,0 +1,66 @@
1
+ <script>
2
+ import { Modal, ModalContent, Button, notifications } from "@budibase/bbui"
3
+ import { getContext, onMount } from "svelte"
4
+
5
+ const { selectedRows, rows, config, subscribe } = getContext("grid")
6
+
7
+ let modal
8
+
9
+ $: selectedRowCount = Object.values($selectedRows).filter(x => !!x).length
10
+ $: rowsToDelete = Object.entries($selectedRows)
11
+ .map(entry => {
12
+ if (entry[1] === true) {
13
+ return $rows.find(x => x._id === entry[0])
14
+ } else {
15
+ return null
16
+ }
17
+ })
18
+ .filter(x => x != null)
19
+
20
+ // Deletion callback when confirmed
21
+ const performDeletion = async () => {
22
+ const count = rowsToDelete.length
23
+ await rows.actions.deleteRows(rowsToDelete)
24
+ notifications.success(`Deleted ${count} row${count === 1 ? "" : "s"}`)
25
+ }
26
+
27
+ onMount(() => subscribe("request-bulk-delete", () => modal?.show()))
28
+ </script>
29
+
30
+ {#if selectedRowCount}
31
+ <div class="delete-button" data-ignore-click-outside="true">
32
+ <Button
33
+ icon="Delete"
34
+ size="M"
35
+ on:click={modal.show}
36
+ disabled={!$config.allowEditRows}
37
+ cta
38
+ >
39
+ Delete {selectedRowCount} row{selectedRowCount === 1 ? "" : "s"}
40
+ </Button>
41
+ </div>
42
+ {/if}
43
+
44
+ <Modal bind:this={modal}>
45
+ <ModalContent
46
+ title="Delete rows"
47
+ confirmText="Continue"
48
+ cancelText="Cancel"
49
+ onConfirm={performDeletion}
50
+ size="M"
51
+ >
52
+ Are you sure you want to delete {selectedRowCount}
53
+ row{selectedRowCount === 1 ? "" : "s"}?
54
+ </ModalContent>
55
+ </Modal>
56
+
57
+ <style>
58
+ .delete-button :global(.spectrum-Button:not(:disabled)) {
59
+ background-color: var(--spectrum-global-color-red-400);
60
+ border-color: var(--spectrum-global-color-red-400);
61
+ }
62
+ .delete-button :global(.spectrum-Button:not(:disabled):hover) {
63
+ background-color: var(--spectrum-global-color-red-500);
64
+ border-color: var(--spectrum-global-color-red-500);
65
+ }
66
+ </style>
@@ -0,0 +1,95 @@
1
+ <script>
2
+ import { getContext } from "svelte"
3
+ import { ActionButton, Popover, Toggle } from "@budibase/bbui"
4
+
5
+ const { columns, stickyColumn } = getContext("grid")
6
+
7
+ let open = false
8
+ let anchor
9
+
10
+ $: anyHidden = $columns.some(col => !col.visible)
11
+
12
+ const toggleVisibility = (column, visible) => {
13
+ columns.update(state => {
14
+ const index = state.findIndex(col => col.name === column.name)
15
+ state[index].visible = visible
16
+ return state.slice()
17
+ })
18
+ columns.actions.saveChanges()
19
+ }
20
+
21
+ const showAll = () => {
22
+ columns.update(state => {
23
+ return state.map(col => ({
24
+ ...col,
25
+ visible: true,
26
+ }))
27
+ })
28
+ columns.actions.saveChanges()
29
+ }
30
+
31
+ const hideAll = () => {
32
+ columns.update(state => {
33
+ return state.map(col => ({
34
+ ...col,
35
+ visible: false,
36
+ }))
37
+ })
38
+ columns.actions.saveChanges()
39
+ }
40
+ </script>
41
+
42
+ <div bind:this={anchor}>
43
+ <ActionButton
44
+ icon="VisibilityOff"
45
+ quiet
46
+ size="M"
47
+ on:click={() => (open = !open)}
48
+ selected={open || anyHidden}
49
+ disabled={!$columns.length}
50
+ >
51
+ Columns
52
+ </ActionButton>
53
+ </div>
54
+
55
+ <Popover bind:open {anchor} align="left">
56
+ <div class="content">
57
+ <div class="columns">
58
+ {#if $stickyColumn}
59
+ <Toggle disabled size="S" value={true} />
60
+ <span>{$stickyColumn.label}</span>
61
+ {/if}
62
+ {#each $columns as column}
63
+ <Toggle
64
+ size="S"
65
+ value={column.visible}
66
+ on:change={e => toggleVisibility(column, e.detail)}
67
+ />
68
+ <span>{column.label}</span>
69
+ {/each}
70
+ </div>
71
+ <div class="buttons">
72
+ <ActionButton on:click={showAll}>Show all</ActionButton>
73
+ <ActionButton on:click={hideAll}>Hide all</ActionButton>
74
+ </div>
75
+ </div>
76
+ </Popover>
77
+
78
+ <style>
79
+ .content {
80
+ padding: 12px 12px;
81
+ display: flex;
82
+ flex-direction: column;
83
+ gap: 12px;
84
+ }
85
+ .buttons {
86
+ display: flex;
87
+ flex-direction: row;
88
+ gap: 8px;
89
+ }
90
+ .columns {
91
+ display: grid;
92
+ align-items: center;
93
+ grid-template-columns: auto 1fr;
94
+ }
95
+ </style>
@@ -0,0 +1,70 @@
1
+ <script>
2
+ import { getContext } from "svelte"
3
+ import { ActionButton, Popover } from "@budibase/bbui"
4
+ import {
5
+ LargeRowHeight,
6
+ MediumRowHeight,
7
+ SmallRowHeight,
8
+ } from "../lib/constants"
9
+
10
+ const { rowHeight, columns, table } = getContext("grid")
11
+ const sizeOptions = [
12
+ {
13
+ label: "Small",
14
+ size: SmallRowHeight,
15
+ },
16
+ {
17
+ label: "Medium",
18
+ size: MediumRowHeight,
19
+ },
20
+ {
21
+ label: "Large",
22
+ size: LargeRowHeight,
23
+ },
24
+ ]
25
+
26
+ let open = false
27
+ let anchor
28
+
29
+ const changeRowHeight = height => {
30
+ columns.actions.saveTable({
31
+ ...$table,
32
+ rowHeight: height,
33
+ })
34
+ }
35
+ </script>
36
+
37
+ <div bind:this={anchor}>
38
+ <ActionButton
39
+ icon="MoveUpDown"
40
+ quiet
41
+ size="M"
42
+ on:click={() => (open = !open)}
43
+ selected={open}
44
+ >
45
+ Height
46
+ </ActionButton>
47
+ </div>
48
+
49
+ <Popover bind:open {anchor} align="left">
50
+ <div class="content">
51
+ {#each sizeOptions as option}
52
+ <ActionButton
53
+ quiet
54
+ selected={$rowHeight === option.size}
55
+ on:click={() => changeRowHeight(option.size)}
56
+ >
57
+ {option.label}
58
+ </ActionButton>
59
+ {/each}
60
+ </div>
61
+ </Popover>
62
+
63
+ <style>
64
+ .content {
65
+ padding: 12px;
66
+ display: flex;
67
+ align-items: center;
68
+ gap: 8px;
69
+ }
70
+ </style>
@@ -0,0 +1,129 @@
1
+ <script>
2
+ import { getContext } from "svelte"
3
+ import { ActionButton, Popover, Select } from "@budibase/bbui"
4
+
5
+ const { sort, columns, stickyColumn } = getContext("grid")
6
+
7
+ let open = false
8
+ let anchor
9
+
10
+ $: columnOptions = getColumnOptions($stickyColumn, $columns)
11
+ $: checkValidSortColumn($sort.column, $stickyColumn, $columns)
12
+ $: orderOptions = getOrderOptions($sort.column, columnOptions)
13
+
14
+ const getColumnOptions = (stickyColumn, columns) => {
15
+ let options = []
16
+ if (stickyColumn) {
17
+ options.push({
18
+ label: stickyColumn.label || stickyColumn.name,
19
+ value: stickyColumn.name,
20
+ type: stickyColumn.schema?.type,
21
+ })
22
+ }
23
+ return [
24
+ ...options,
25
+ ...columns.map(col => ({
26
+ label: col.label || col.name,
27
+ value: col.name,
28
+ type: col.schema?.type,
29
+ })),
30
+ ]
31
+ }
32
+
33
+ const getOrderOptions = (column, columnOptions) => {
34
+ const type = columnOptions.find(col => col.value === column)?.type
35
+ return [
36
+ {
37
+ label: type === "number" ? "Low-high" : "A-Z",
38
+ value: "ascending",
39
+ },
40
+ {
41
+ label: type === "number" ? "High-low" : "Z-A",
42
+ value: "descending",
43
+ },
44
+ ]
45
+ }
46
+
47
+ const updateSortColumn = e => {
48
+ sort.update(state => ({
49
+ ...state,
50
+ column: e.detail,
51
+ }))
52
+ }
53
+
54
+ const updateSortOrder = e => {
55
+ sort.update(state => ({
56
+ ...state,
57
+ order: e.detail,
58
+ }))
59
+ }
60
+
61
+ // Ensure we never have a sort column selected that is not visible
62
+ const checkValidSortColumn = (sortColumn, stickyColumn, columns) => {
63
+ if (!sortColumn) {
64
+ return
65
+ }
66
+ if (
67
+ sortColumn !== stickyColumn?.name &&
68
+ !columns.some(col => col.name === sortColumn)
69
+ ) {
70
+ if (stickyColumn) {
71
+ sort.update(state => ({
72
+ ...state,
73
+ column: stickyColumn.name,
74
+ }))
75
+ } else {
76
+ sort.update(state => ({
77
+ ...state,
78
+ column: columns[0]?.name,
79
+ }))
80
+ }
81
+ }
82
+ }
83
+ </script>
84
+
85
+ <div bind:this={anchor}>
86
+ <ActionButton
87
+ icon="SortOrderDown"
88
+ quiet
89
+ size="M"
90
+ on:click={() => (open = !open)}
91
+ selected={open}
92
+ disabled={!columnOptions.length}
93
+ >
94
+ Sort
95
+ </ActionButton>
96
+ </div>
97
+
98
+ <Popover bind:open {anchor} align="left">
99
+ <div class="content">
100
+ <Select
101
+ placeholder={null}
102
+ value={$sort.column}
103
+ options={columnOptions}
104
+ autoWidth
105
+ on:change={updateSortColumn}
106
+ label="Column"
107
+ />
108
+ <Select
109
+ placeholder={null}
110
+ value={$sort.order}
111
+ options={orderOptions}
112
+ autoWidth
113
+ on:change={updateSortOrder}
114
+ label="Order"
115
+ />
116
+ </div>
117
+ </Popover>
118
+
119
+ <style>
120
+ .content {
121
+ padding: 6px 12px 12px 12px;
122
+ display: flex;
123
+ align-items: center;
124
+ gap: 8px;
125
+ }
126
+ .content :global(.spectrum-Picker) {
127
+ width: 140px;
128
+ }
129
+ </style>
@@ -0,0 +1 @@
1
+ export { default as Grid } from "./layout/Grid.svelte"
@@ -0,0 +1,24 @@
1
+ <script>
2
+ export let user
3
+ </script>
4
+
5
+ <div class="user" style="background:{user.color};" title={user.email}>
6
+ {user.email[0]}
7
+ </div>
8
+
9
+ <style>
10
+ div {
11
+ width: 24px;
12
+ height: 24px;
13
+ display: grid;
14
+ place-items: center;
15
+ color: white;
16
+ border-radius: 50%;
17
+ font-size: 12px;
18
+ font-weight: 700;
19
+ text-transform: uppercase;
20
+ }
21
+ div:hover {
22
+ cursor: pointer;
23
+ }
24
+ </style>