@budibase/frontend-core 3.2.45 → 3.2.47

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@budibase/frontend-core",
3
- "version": "3.2.45",
3
+ "version": "3.2.47",
4
4
  "description": "Budibase frontend core libraries used in builder and client",
5
5
  "author": "Budibase",
6
6
  "license": "MPL-2.0",
@@ -20,5 +20,5 @@
20
20
  "devDependencies": {
21
21
  "svelte-check": "^4.1.0"
22
22
  },
23
- "gitHead": "a636af7d5f402da86321a48f64745fefd2f9d4a1"
23
+ "gitHead": "b05548bb07650275f45856cff116a59b5e78f5d3"
24
24
  }
@@ -1,8 +1,8 @@
1
- import { GetOldMigrationStatus } from "@budibase/types"
1
+ import { GetMigrationStatus } from "@budibase/types"
2
2
  import { BaseAPIClient } from "./types"
3
3
 
4
4
  export interface MigrationEndpoints {
5
- getMigrationStatus: () => Promise<GetOldMigrationStatus>
5
+ getMigrationStatus: () => Promise<GetMigrationStatus>
6
6
  }
7
7
 
8
8
  export const buildMigrationEndpoints = (
@@ -8,6 +8,7 @@ export * as search from "./searchFields"
8
8
  export * as SchemaUtils from "./schema"
9
9
  export { memo, derivedMemo } from "./memo"
10
10
  export { createWebsocket } from "./websocket"
11
+ export * as JsonFormatter from "./jsonFormatter"
11
12
  export * from "./download"
12
13
  export * from "./settings"
13
14
  export * from "./relatedColumns"
@@ -0,0 +1,71 @@
1
+ import { JSONValue } from "@budibase/types"
2
+
3
+ export type ColorsOptions = {
4
+ keyColor?: string
5
+ numberColor?: string
6
+ stringColor?: string
7
+ trueColor?: string
8
+ falseColor?: string
9
+ nullColor?: string
10
+ }
11
+
12
+ const defaultColors: ColorsOptions = {
13
+ keyColor: "dimgray",
14
+ numberColor: "lightskyblue",
15
+ stringColor: "lightcoral",
16
+ trueColor: "lightseagreen",
17
+ falseColor: "#f66578",
18
+ nullColor: "cornflowerblue",
19
+ }
20
+
21
+ const entityMap = {
22
+ "&": "&amp;",
23
+ "<": "&lt;",
24
+ ">": "&gt;",
25
+ '"': "&quot;",
26
+ "'": "&#39;",
27
+ "`": "&#x60;",
28
+ "=": "&#x3D;",
29
+ }
30
+
31
+ function escapeHtml(html: string) {
32
+ return String(html).replace(/[&<>"'`=]/g, function (s) {
33
+ return entityMap[s as keyof typeof entityMap]
34
+ })
35
+ }
36
+
37
+ export function format(json: JSONValue, colorOptions: ColorsOptions = {}) {
38
+ const valueType = typeof json
39
+ let jsonString =
40
+ typeof json === "string" ? json : JSON.stringify(json, null, 2) || valueType
41
+ let colors = Object.assign({}, defaultColors, colorOptions)
42
+ jsonString = jsonString
43
+ .replace(/&/g, "&")
44
+ .replace(/</g, "<")
45
+ .replace(/>/g, ">")
46
+ return jsonString.replace(
47
+ /("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+]?\d+)?)/g,
48
+ (match: string) => {
49
+ let color = colors.numberColor
50
+ let style = ""
51
+ if (/^"/.test(match)) {
52
+ if (/:$/.test(match)) {
53
+ color = colors.keyColor
54
+ } else {
55
+ color = colors.stringColor
56
+ match = '"' + escapeHtml(match.substr(1, match.length - 2)) + '"'
57
+ style = "word-wrap:break-word;white-space:pre-wrap;"
58
+ }
59
+ } else {
60
+ color = /true/.test(match)
61
+ ? colors.trueColor
62
+ : /false/.test(match)
63
+ ? colors.falseColor
64
+ : /null/.test(match)
65
+ ? colors.nullColor
66
+ : color
67
+ }
68
+ return `<span style="${style}color:${color}">${match}</span>`
69
+ }
70
+ )
71
+ }
@@ -43,7 +43,7 @@ export const sequential = fn => {
43
43
  * invocations is enforced.
44
44
  * @param callback an async function to run
45
45
  * @param minDelay the minimum delay between invocations
46
- * @returns {Promise} a debounced version of the callback
46
+ * @returns a debounced version of the callback
47
47
  */
48
48
  export const debounce = (callback, minDelay = 1000) => {
49
49
  let timeout