@budibase/bbui 2.2.12-alpha.62 → 2.2.12-alpha.63

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.62",
4
+ "version": "2.2.12-alpha.63",
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.62",
41
+ "@budibase/string-templates": "2.2.12-alpha.63",
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": "f81de225cc6967619f671eeeb0cb716ae6e3d647"
92
+ "gitHead": "f884c90740b9573adae97d020127f24c4a7b5cbf"
93
93
  }
@@ -86,7 +86,7 @@
86
86
  }
87
87
  .is-selected:not(.spectrum-ActionButton--emphasized):not(.spectrum-ActionButton--quiet) {
88
88
  background: var(--spectrum-global-color-gray-300);
89
- border-color: var(--spectrum-global-color-gray-700);
89
+ border-color: var(--spectrum-global-color-gray-500);
90
90
  }
91
91
  .noPadding {
92
92
  padding: 0;
@@ -1,11 +1,21 @@
1
- export default function positionDropdown(
2
- element,
3
- { anchor, align, maxWidth, useAnchorWidth, offset = 5 }
4
- ) {
5
- const update = () => {
1
+ export default function positionDropdown(element, opts) {
2
+ let resizeObserver
3
+ let latestOpts = opts
4
+
5
+ // We need a static reference to this function so that we can properly
6
+ // clean up the scroll listener.
7
+ const scrollUpdate = () => {
8
+ updatePosition(latestOpts)
9
+ }
10
+
11
+ // Updates the position of the dropdown
12
+ const updatePosition = opts => {
13
+ const { anchor, align, maxWidth, useAnchorWidth, offset = 5 } = opts
6
14
  if (!anchor) {
7
15
  return
8
16
  }
17
+
18
+ // Compute bounds
9
19
  const anchorBounds = anchor.getBoundingClientRect()
10
20
  const elementBounds = element.getBoundingClientRect()
11
21
  let styles = {
@@ -51,26 +61,47 @@ export default function positionDropdown(
51
61
  })
52
62
  }
53
63
 
64
+ // The actual svelte action callback which creates observers on the relevant
65
+ // DOM elements
66
+ const update = newOpts => {
67
+ latestOpts = newOpts
68
+
69
+ // Cleanup old state
70
+ if (resizeObserver) {
71
+ resizeObserver.disconnect()
72
+ }
73
+
74
+ // Do nothing if no anchor
75
+ const { anchor } = newOpts
76
+ if (!anchor) {
77
+ return
78
+ }
79
+
80
+ // Observe both anchor and element and resize the popover as appropriate
81
+ resizeObserver = new ResizeObserver(() => updatePosition(newOpts))
82
+ resizeObserver.observe(anchor)
83
+ resizeObserver.observe(element)
84
+ resizeObserver.observe(document.body)
85
+ }
86
+
54
87
  // Apply initial styles which don't need to change
55
88
  element.style.position = "absolute"
56
89
  element.style.zIndex = "9999"
57
90
 
58
- // Observe both anchor and element and resize the popover as appropriate
59
- const resizeObserver = new ResizeObserver(entries => {
60
- entries.forEach(update)
61
- })
62
- if (anchor) {
63
- resizeObserver.observe(anchor)
64
- }
65
- resizeObserver.observe(element)
66
- resizeObserver.observe(document.body)
91
+ // Set up a scroll listener
92
+ document.addEventListener("scroll", scrollUpdate, true)
67
93
 
68
- document.addEventListener("scroll", update, true)
94
+ // Perform initial update
95
+ update(opts)
69
96
 
70
97
  return {
98
+ update,
71
99
  destroy() {
72
- resizeObserver.disconnect()
73
- document.removeEventListener("scroll", update, true)
100
+ // Cleanup
101
+ if (resizeObserver) {
102
+ resizeObserver.disconnect()
103
+ }
104
+ document.removeEventListener("scroll", scrollUpdate, true)
74
105
  },
75
106
  }
76
107
  }
@@ -57,30 +57,28 @@
57
57
  </script>
58
58
 
59
59
  {#if open}
60
- {#key anchor}
61
- <Portal {target}>
62
- <div
63
- tabindex="0"
64
- use:positionDropdown={{
65
- anchor,
66
- align,
67
- maxWidth,
68
- useAnchorWidth,
69
- offset,
70
- }}
71
- use:clickOutside={{
72
- callback: dismissible ? handleOutsideClick : () => {},
73
- anchor,
74
- }}
75
- on:keydown={handleEscape}
76
- class="spectrum-Popover is-open"
77
- role="presentation"
78
- transition:fly|local={{ y: -20, duration: 200 }}
79
- >
80
- <slot />
81
- </div>
82
- </Portal>
83
- {/key}
60
+ <Portal {target}>
61
+ <div
62
+ tabindex="0"
63
+ use:positionDropdown={{
64
+ anchor,
65
+ align,
66
+ maxWidth,
67
+ useAnchorWidth,
68
+ offset,
69
+ }}
70
+ use:clickOutside={{
71
+ callback: dismissible ? handleOutsideClick : () => {},
72
+ anchor,
73
+ }}
74
+ on:keydown={handleEscape}
75
+ class="spectrum-Popover is-open"
76
+ role="presentation"
77
+ transition:fly|local={{ y: -20, duration: 200 }}
78
+ >
79
+ <slot />
80
+ </div>
81
+ </Portal>
84
82
  {/if}
85
83
 
86
84
  <style>