@budibase/frontend-core 2.5.6-alpha.3 → 2.5.6-alpha.31

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 (66) 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 +88 -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 +162 -0
  9. package/src/components/grid/cells/GutterCell.svelte +127 -0
  10. package/src/components/grid/cells/HeaderCell.svelte +246 -0
  11. package/src/components/grid/cells/JSONCell.svelte +36 -0
  12. package/src/components/grid/cells/LongFormCell.svelte +120 -0
  13. package/src/components/grid/cells/MultiSelectCell.svelte +7 -0
  14. package/src/components/grid/cells/NumberCell.svelte +7 -0
  15. package/src/components/grid/cells/OptionsCell.svelte +240 -0
  16. package/src/components/grid/cells/RelationshipCell.svelte +504 -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 +116 -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 +57 -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/NewRow.svelte +265 -0
  34. package/src/components/grid/layout/RowCount.svelte +9 -0
  35. package/src/components/grid/layout/StickyColumn.svelte +171 -0
  36. package/src/components/grid/layout/UserAvatars.svelte +20 -0
  37. package/src/components/grid/lib/constants.js +14 -0
  38. package/src/components/grid/lib/events.js +29 -0
  39. package/src/components/grid/lib/renderers.js +29 -0
  40. package/src/components/grid/lib/utils.js +26 -0
  41. package/src/components/grid/lib/websocket.js +63 -0
  42. package/src/components/grid/overlays/KeyboardManager.svelte +223 -0
  43. package/src/components/grid/overlays/MenuOverlay.svelte +96 -0
  44. package/src/components/grid/overlays/ReorderOverlay.svelte +63 -0
  45. package/src/components/grid/overlays/ResizeOverlay.svelte +70 -0
  46. package/src/components/grid/overlays/ScrollOverlay.svelte +121 -0
  47. package/src/components/grid/stores/bounds.js +16 -0
  48. package/src/components/grid/stores/clipboard.js +34 -0
  49. package/src/components/grid/stores/columns.js +206 -0
  50. package/src/components/grid/stores/index.js +48 -0
  51. package/src/components/grid/stores/menu.js +49 -0
  52. package/src/components/grid/stores/pagination.js +24 -0
  53. package/src/components/grid/stores/reorder.js +155 -0
  54. package/src/components/grid/stores/resize.js +124 -0
  55. package/src/components/grid/stores/rows.js +467 -0
  56. package/src/components/grid/stores/scroll.js +201 -0
  57. package/src/components/grid/stores/ui.js +159 -0
  58. package/src/components/grid/stores/users.js +115 -0
  59. package/src/components/grid/stores/validation.js +45 -0
  60. package/src/components/grid/stores/viewport.js +145 -0
  61. package/src/components/index.js +1 -0
  62. package/src/fetch/DataFetch.js +27 -21
  63. package/src/fetch/QueryFetch.js +1 -1
  64. package/src/themes/midnight.css +3 -0
  65. package/src/themes/nord.css +3 -0
  66. 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,116 @@
1
+ <script>
2
+ import { getContext } from "svelte"
3
+ import { ActionButton, Popover, Select } from "@budibase/bbui"
4
+
5
+ const { sort, columns, stickyColumn } = getContext("grid")
6
+ const orderOptions = [
7
+ { label: "A-Z", value: "ascending" },
8
+ { label: "Z-A", value: "descending" },
9
+ ]
10
+
11
+ let open = false
12
+ let anchor
13
+
14
+ $: columnOptions = getColumnOptions($stickyColumn, $columns)
15
+ $: checkValidSortColumn($sort.column, $stickyColumn, $columns)
16
+
17
+ const getColumnOptions = (stickyColumn, columns) => {
18
+ let options = []
19
+ if (stickyColumn) {
20
+ options.push({
21
+ label: stickyColumn.label || stickyColumn.name,
22
+ value: stickyColumn.name,
23
+ })
24
+ }
25
+ return [
26
+ ...options,
27
+ ...columns.map(col => ({
28
+ label: col.label || col.name,
29
+ value: col.name,
30
+ })),
31
+ ]
32
+ }
33
+
34
+ const updateSortColumn = e => {
35
+ sort.update(state => ({
36
+ ...state,
37
+ column: e.detail,
38
+ }))
39
+ }
40
+
41
+ const updateSortOrder = e => {
42
+ sort.update(state => ({
43
+ ...state,
44
+ order: e.detail,
45
+ }))
46
+ }
47
+
48
+ // Ensure we never have a sort column selected that is not visible
49
+ const checkValidSortColumn = (sortColumn, stickyColumn, columns) => {
50
+ if (!sortColumn) {
51
+ return
52
+ }
53
+ if (
54
+ sortColumn !== stickyColumn?.name &&
55
+ !columns.some(col => col.name === sortColumn)
56
+ ) {
57
+ if (stickyColumn) {
58
+ sort.update(state => ({
59
+ ...state,
60
+ column: stickyColumn.name,
61
+ }))
62
+ } else {
63
+ sort.update(state => ({
64
+ ...state,
65
+ column: columns[0]?.name,
66
+ }))
67
+ }
68
+ }
69
+ }
70
+ </script>
71
+
72
+ <div bind:this={anchor}>
73
+ <ActionButton
74
+ icon="SortOrderDown"
75
+ quiet
76
+ size="M"
77
+ on:click={() => (open = !open)}
78
+ selected={open}
79
+ disabled={!columnOptions.length}
80
+ >
81
+ Sort
82
+ </ActionButton>
83
+ </div>
84
+
85
+ <Popover bind:open {anchor} align="left">
86
+ <div class="content">
87
+ <Select
88
+ placeholder={null}
89
+ value={$sort.column}
90
+ options={columnOptions}
91
+ autoWidth
92
+ on:change={updateSortColumn}
93
+ label="Column"
94
+ />
95
+ <Select
96
+ placeholder={null}
97
+ value={$sort.order}
98
+ options={orderOptions}
99
+ autoWidth
100
+ on:change={updateSortOrder}
101
+ label="Order"
102
+ />
103
+ </div>
104
+ </Popover>
105
+
106
+ <style>
107
+ .content {
108
+ padding: 6px 12px 12px 12px;
109
+ display: flex;
110
+ align-items: center;
111
+ gap: 8px;
112
+ }
113
+ .content :global(.spectrum-Picker) {
114
+ width: 140px;
115
+ }
116
+ </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>