@budibase/bbui 2.24.1 → 2.24.2

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.24.1",
4
+ "version": "2.24.2",
5
5
  "license": "MPL-2.0",
6
6
  "svelte": "src/index.js",
7
7
  "module": "dist/bbui.es.js",
@@ -35,8 +35,8 @@
35
35
  ],
36
36
  "dependencies": {
37
37
  "@adobe/spectrum-css-workflow-icons": "1.2.1",
38
- "@budibase/shared-core": "2.24.1",
39
- "@budibase/string-templates": "2.24.1",
38
+ "@budibase/shared-core": "2.24.2",
39
+ "@budibase/string-templates": "2.24.2",
40
40
  "@spectrum-css/accordion": "3.0.24",
41
41
  "@spectrum-css/actionbutton": "1.0.1",
42
42
  "@spectrum-css/actiongroup": "1.0.1",
@@ -103,5 +103,5 @@
103
103
  }
104
104
  }
105
105
  },
106
- "gitHead": "5cb6ac027c7f45e174e3545a7399d425822970d8"
106
+ "gitHead": "9c6e0823094ac5bbf514d628152050bf25faf98d"
107
107
  }
@@ -1,22 +1,25 @@
1
+ // These class names will never trigger a callback if clicked, no matter what
1
2
  const ignoredClasses = [
2
3
  ".download-js-link",
3
4
  ".spectrum-Menu",
4
5
  ".date-time-popover",
5
6
  ]
7
+
8
+ // These class names will only trigger a callback when clicked if the registered
9
+ // component is not nested inside them. For example, clicking inside a modal
10
+ // will not close the modal, or clicking inside a popover will not close the
11
+ // popover.
6
12
  const conditionallyIgnoredClasses = [
7
13
  ".spectrum-Underlay",
8
14
  ".drawer-wrapper",
9
15
  ".spectrum-Popover",
10
16
  ]
11
17
  let clickHandlers = []
18
+ let candidateTarget
12
19
 
13
- /**
14
- * Handle a body click event
15
- */
20
+ // Processes a "click outside" event and invokes callbacks if our source element
21
+ // is valid
16
22
  const handleClick = event => {
17
- // Treat right clicks (context menu events) as normal clicks
18
- const eventType = event.type === "contextmenu" ? "click" : event.type
19
-
20
23
  // Ignore click if this is an ignored class
21
24
  if (event.target.closest('[data-ignore-click-outside="true"]')) {
22
25
  return
@@ -29,11 +32,6 @@ const handleClick = event => {
29
32
 
30
33
  // Process handlers
31
34
  clickHandlers.forEach(handler => {
32
- // Check that we're the right kind of click event
33
- if (handler.allowedType && eventType !== handler.allowedType) {
34
- return
35
- }
36
-
37
35
  // Check that the click isn't inside the target
38
36
  if (handler.element.contains(event.target)) {
39
37
  return
@@ -51,17 +49,43 @@ const handleClick = event => {
51
49
  handler.callback?.(event)
52
50
  })
53
51
  }
54
- document.documentElement.addEventListener("click", handleClick, true)
55
- document.documentElement.addEventListener("mousedown", handleClick, true)
56
- document.documentElement.addEventListener("contextmenu", handleClick, true)
52
+
53
+ // On mouse up we only trigger a "click outside" callback if we targetted the
54
+ // same element that we did on mouse down. This fixes all sorts of issues where
55
+ // we get annoying callbacks firing when we drag to select text.
56
+ const handleMouseUp = e => {
57
+ if (candidateTarget === e.target) {
58
+ handleClick(e)
59
+ }
60
+ candidateTarget = null
61
+ }
62
+
63
+ // On mouse down we store which element was targetted for comparison later
64
+ const handleMouseDown = e => {
65
+ // Only handle the primary mouse button here.
66
+ // We handle context menu (right click) events in another handler.
67
+ if (e.button !== 0) {
68
+ return
69
+ }
70
+ candidateTarget = e.target
71
+
72
+ // Clear any previous listeners in case of multiple down events, and register
73
+ // a single mouse up listener
74
+ document.removeEventListener("mouseup", handleMouseUp)
75
+ document.addEventListener("mouseup", handleMouseUp, true)
76
+ }
77
+
78
+ // Global singleton listeners for our events
79
+ document.addEventListener("mousedown", handleMouseDown)
80
+ document.addEventListener("contextmenu", handleClick)
57
81
 
58
82
  /**
59
83
  * Adds or updates a click handler
60
84
  */
61
- const updateHandler = (id, element, anchor, callback, allowedType) => {
85
+ const updateHandler = (id, element, anchor, callback) => {
62
86
  let existingHandler = clickHandlers.find(x => x.id === id)
63
87
  if (!existingHandler) {
64
- clickHandlers.push({ id, element, anchor, callback, allowedType })
88
+ clickHandlers.push({ id, element, anchor, callback })
65
89
  } else {
66
90
  existingHandler.callback = callback
67
91
  }
@@ -88,8 +112,7 @@ export default (element, opts) => {
88
112
  const callback =
89
113
  newOpts?.callback || (typeof newOpts === "function" ? newOpts : null)
90
114
  const anchor = newOpts?.anchor || element
91
- const allowedType = newOpts?.allowedType || "click"
92
- updateHandler(id, element, anchor, callback, allowedType)
115
+ updateHandler(id, element, anchor, callback)
93
116
  }
94
117
  update(opts)
95
118
  return {
@@ -8,6 +8,8 @@
8
8
  export let size = "S"
9
9
  export let extraButtonText
10
10
  export let extraButtonAction
11
+ export let extraLinkText
12
+ export let extraLinkAction
11
13
  export let showCloseButton = true
12
14
 
13
15
  let show = true
@@ -28,8 +30,13 @@
28
30
  <use xlink:href="#spectrum-icon-18-{icon}" />
29
31
  </svg>
30
32
  <div class="spectrum-Toast-body">
31
- <div class="spectrum-Toast-content">
33
+ <div class="spectrum-Toast-content row-content">
32
34
  <slot />
35
+ {#if extraLinkText}
36
+ <button class="link" on:click={extraLinkAction}>
37
+ <u>{extraLinkText}</u>
38
+ </button>
39
+ {/if}
33
40
  </div>
34
41
  {#if extraButtonText && extraButtonAction}
35
42
  <button
@@ -73,4 +80,23 @@
73
80
  .spectrum-Button {
74
81
  border: 1px solid rgba(255, 255, 255, 0.2);
75
82
  }
83
+
84
+ .row-content {
85
+ display: flex;
86
+ }
87
+
88
+ .link {
89
+ background: none;
90
+ border: none;
91
+ margin: 0;
92
+ margin-left: 0.5em;
93
+ padding: 0;
94
+ cursor: pointer;
95
+ color: white;
96
+ font-weight: 600;
97
+ }
98
+
99
+ u {
100
+ font-weight: 600;
101
+ }
76
102
  </style>