@budibase/frontend-core 2.30.8 → 2.31.1

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,18 +1,18 @@
1
1
  {
2
2
  "name": "@budibase/frontend-core",
3
- "version": "2.30.8",
3
+ "version": "2.31.1",
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.30.8",
10
- "@budibase/shared-core": "2.30.8",
11
- "@budibase/types": "2.30.8",
9
+ "@budibase/bbui": "2.31.1",
10
+ "@budibase/shared-core": "2.31.1",
11
+ "@budibase/types": "2.31.1",
12
12
  "dayjs": "^1.10.8",
13
13
  "lodash": "4.17.21",
14
14
  "shortid": "2.2.15",
15
15
  "socket.io-client": "^4.7.5"
16
16
  },
17
- "gitHead": "0d9bb274bc8d227ff41514d2b8192bdbea029d82"
17
+ "gitHead": "c02bf714eddb14569578363bc1b3e3aa582995b8"
18
18
  }
@@ -58,7 +58,6 @@
58
58
  height: 100%;
59
59
  display: flex;
60
60
  flex-direction: column;
61
- border-radius: 4px;
62
61
  overflow: hidden;
63
62
  background-color: var(--spectrum-global-color-gray-200);
64
63
  }
@@ -9,3 +9,4 @@ export { memo, derivedMemo } from "./memo"
9
9
  export { createWebsocket } from "./websocket"
10
10
  export * from "./download"
11
11
  export * from "./theme"
12
+ export * from "./settings"
package/src/utils/memo.js CHANGED
@@ -4,32 +4,23 @@ import { writable, get, derived } from "svelte/store"
4
4
  // subscribed children will only fire when a new value is actually set
5
5
  export const memo = initialValue => {
6
6
  const store = writable(initialValue)
7
+ let currentJSON = JSON.stringify(initialValue)
7
8
 
8
- const tryUpdateValue = (newValue, currentValue) => {
9
- // Sanity check for primitive equality
10
- if (currentValue === newValue) {
11
- return
12
- }
13
-
14
- // Otherwise deep compare via JSON stringify
15
- const currentString = JSON.stringify(currentValue)
16
- const newString = JSON.stringify(newValue)
17
- if (currentString !== newString) {
9
+ const tryUpdateValue = newValue => {
10
+ const newJSON = JSON.stringify(newValue)
11
+ if (newJSON !== currentJSON) {
18
12
  store.set(newValue)
13
+ currentJSON = newJSON
19
14
  }
20
15
  }
21
16
 
22
17
  return {
23
18
  subscribe: store.subscribe,
24
- set: newValue => {
25
- const currentValue = get(store)
26
- tryUpdateValue(newValue, currentValue)
27
- },
19
+ set: tryUpdateValue,
28
20
  update: updateFn => {
29
- const currentValue = get(store)
30
- let mutableCurrentValue = JSON.parse(JSON.stringify(currentValue))
21
+ let mutableCurrentValue = JSON.parse(currentJSON)
31
22
  const newValue = updateFn(mutableCurrentValue)
32
- tryUpdateValue(newValue, currentValue)
23
+ tryUpdateValue(newValue)
33
24
  },
34
25
  }
35
26
  }
@@ -0,0 +1,43 @@
1
+ import { helpers } from "@budibase/shared-core"
2
+
3
+ // Util to check if a setting can be rendered for a certain instance, based on
4
+ // the "dependsOn" metadata in the manifest
5
+ export const shouldDisplaySetting = (instance, setting) => {
6
+ let dependsOn = setting.dependsOn
7
+ if (dependsOn && !Array.isArray(dependsOn)) {
8
+ dependsOn = [dependsOn]
9
+ }
10
+ if (!dependsOn?.length) {
11
+ return true
12
+ }
13
+
14
+ // Ensure all conditions are met
15
+ return dependsOn.every(condition => {
16
+ let dependantSetting = condition
17
+ let dependantValues = null
18
+ let invert = !!condition.invert
19
+ if (typeof condition === "object") {
20
+ dependantSetting = condition.setting
21
+ dependantValues = condition.value
22
+ }
23
+ if (!dependantSetting) {
24
+ return false
25
+ }
26
+
27
+ // Ensure values is an array
28
+ if (!Array.isArray(dependantValues)) {
29
+ dependantValues = [dependantValues]
30
+ }
31
+
32
+ // If inverting, we want to ensure that we don't have any matches.
33
+ // If not inverting, we want to ensure that we do have any matches.
34
+ const currentVal = helpers.deepGet(instance, dependantSetting)
35
+ const anyMatches = dependantValues.some(dependantVal => {
36
+ if (dependantVal == null) {
37
+ return currentVal != null && currentVal !== false && currentVal !== ""
38
+ }
39
+ return dependantVal === currentVal
40
+ })
41
+ return anyMatches !== invert
42
+ })
43
+ }