@budibase/bbui 3.39.29 → 3.39.30
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/dist/bbui.mjs +5 -4
- package/package.json +7 -4
- package/src/helpers.test.ts +29 -0
- package/src/helpers.ts +10 -2
package/dist/bbui.mjs
CHANGED
|
@@ -3917,9 +3917,10 @@ var Theme = /* @__PURE__ */ function(l) {
|
|
|
3917
3917
|
uuid: () => uuid$1
|
|
3918
3918
|
}), import_dayjs_min = /* @__PURE__ */ __toESM(require_dayjs_min()), deepGet = deepGet$1;
|
|
3919
3919
|
function uuid$1() {
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
|
|
3920
|
+
let l = () => globalThis.crypto?.getRandomValues ? globalThis.crypto.getRandomValues(new Uint8Array(1))[0] & 15 : Math.random() * 16 | 0;
|
|
3921
|
+
return "cxxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx".replace(/[xy]/g, (u) => {
|
|
3922
|
+
let f = l();
|
|
3923
|
+
return (u === "x" ? f : f & 3 | 8).toString(16);
|
|
3923
3924
|
});
|
|
3924
3925
|
}
|
|
3925
3926
|
var capitalise = (l) => l ? l.substring(0, 1).toUpperCase() + l.substring(1) : "", hashString = (l) => {
|
|
@@ -3966,7 +3967,7 @@ var capitalise = (l) => l ? l.substring(0, 1).toUpperCase() + l.substring(1) : "
|
|
|
3966
3967
|
case "month": return "M".repeat(l.value.length);
|
|
3967
3968
|
case "year": return "Y".repeat(l.value.length);
|
|
3968
3969
|
case "literal": return l.value;
|
|
3969
|
-
default: return console.
|
|
3970
|
+
default: return console.warn("Unsupported date part", l), "";
|
|
3970
3971
|
}
|
|
3971
3972
|
}, localeDateFormat = new Intl.DateTimeFormat().formatToParts(/* @__PURE__ */ new Date("2021-01-01")).map(getPatternForPart).join(""), getDateDisplayValue = (l, { enableTime: u = !0, timeOnly: f = !1 } = {}) => (typeof l == "string" && (l = (0, import_dayjs_min.default)(l)), l?.isValid() ? f ? l.format("HH:mm") : u ? l.format(`${localeDateFormat} HH:mm`) : l.format(localeDateFormat) : ""), hexToRGBA = (l, u) => (l.includes("#") && (l = l.replace("#", "")), `rgba(${parseInt(l.substring(0, 2), 16)}, ${parseInt(l.substring(2, 4), 16)}, ${parseInt(l.substring(4, 6), 16)}, ${u})`);
|
|
3972
3973
|
function rgbToHex(l) {
|
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": "3.39.
|
|
4
|
+
"version": "3.39.30",
|
|
5
5
|
"license": "MPL-2.0",
|
|
6
6
|
"module": "dist/bbui.mjs",
|
|
7
7
|
"exports": {
|
|
@@ -13,12 +13,15 @@
|
|
|
13
13
|
},
|
|
14
14
|
"scripts": {
|
|
15
15
|
"build": "vite build",
|
|
16
|
-
"dev": "vite build --watch --mode=dev"
|
|
16
|
+
"dev": "vite build --watch --mode=dev",
|
|
17
|
+
"test": "vitest run",
|
|
18
|
+
"test:watch": "vitest"
|
|
17
19
|
},
|
|
18
20
|
"devDependencies": {
|
|
19
21
|
"@sveltejs/vite-plugin-svelte": "^6.1.3",
|
|
20
22
|
"@types/sanitize-html": "^2.13.0",
|
|
21
|
-
"vite-plugin-css-injected-by-js": "3.5.2"
|
|
23
|
+
"vite-plugin-css-injected-by-js": "3.5.2",
|
|
24
|
+
"vitest": "^4.1.8"
|
|
22
25
|
},
|
|
23
26
|
"keywords": [
|
|
24
27
|
"svelte"
|
|
@@ -105,5 +108,5 @@
|
|
|
105
108
|
}
|
|
106
109
|
}
|
|
107
110
|
},
|
|
108
|
-
"gitHead": "
|
|
111
|
+
"gitHead": "279fc73ae9c28f7ce62b7b7b349fc43b3096635c"
|
|
109
112
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from "vitest"
|
|
2
|
+
import { uuid } from "./helpers"
|
|
3
|
+
|
|
4
|
+
describe("uuid", () => {
|
|
5
|
+
afterEach(() => {
|
|
6
|
+
vi.restoreAllMocks()
|
|
7
|
+
vi.unstubAllGlobals()
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
it("uses crypto.getRandomValues when available", () => {
|
|
11
|
+
const getRandomValues = vi.fn((array: Uint8Array) => {
|
|
12
|
+
array[0] = 0xab
|
|
13
|
+
return array
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
vi.stubGlobal("crypto", { getRandomValues })
|
|
17
|
+
|
|
18
|
+
expect(uuid()).toMatch(/^c[a-f0-9]{12}4[a-f0-9]{3}[89ab][a-f0-9]{15}$/)
|
|
19
|
+
expect(getRandomValues).toHaveBeenCalled()
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
it("falls back to Math.random when crypto is unavailable", () => {
|
|
23
|
+
vi.stubGlobal("crypto", undefined)
|
|
24
|
+
vi.spyOn(Math, "random").mockReturnValue(0)
|
|
25
|
+
|
|
26
|
+
expect(uuid()).toMatch(/^c[a-f0-9]{12}4[a-f0-9]{3}[89ab][a-f0-9]{15}$/)
|
|
27
|
+
expect(Math.random).toHaveBeenCalled()
|
|
28
|
+
})
|
|
29
|
+
})
|
package/src/helpers.ts
CHANGED
|
@@ -8,8 +8,16 @@ export const deepGet = helpers.deepGet
|
|
|
8
8
|
* Starting with a letter is important to make it DOM safe.
|
|
9
9
|
*/
|
|
10
10
|
export function uuid(): string {
|
|
11
|
+
const getRandomNibble = () => {
|
|
12
|
+
if (globalThis.crypto?.getRandomValues) {
|
|
13
|
+
return globalThis.crypto.getRandomValues(new Uint8Array(1))[0] & 0xf
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return (Math.random() * 16) | 0
|
|
17
|
+
}
|
|
18
|
+
|
|
11
19
|
return "cxxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx".replace(/[xy]/g, c => {
|
|
12
|
-
const r = (
|
|
20
|
+
const r = getRandomNibble()
|
|
13
21
|
const v = c === "x" ? r : (r & 0x3) | 0x8
|
|
14
22
|
return v.toString(16)
|
|
15
23
|
})
|
|
@@ -200,7 +208,7 @@ const getPatternForPart = (part: Intl.DateTimeFormatPart): string => {
|
|
|
200
208
|
case "literal":
|
|
201
209
|
return part.value
|
|
202
210
|
default:
|
|
203
|
-
console.
|
|
211
|
+
console.warn("Unsupported date part", part)
|
|
204
212
|
return ""
|
|
205
213
|
}
|
|
206
214
|
}
|