@caspeco/casper-ui-library 10.0.0 → 10.0.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.
@@ -1,2 +1,5 @@
1
+ import { FileItem } from './image-upload-dropzone.js';
1
2
  export declare function sanitizeFilename(filename: string): string;
3
+ export declare function readBlobAsDataUrl(blob: Blob): Promise<string>;
4
+ export declare function loadImageFileItem(src: string, signal?: AbortSignal): Promise<FileItem>;
2
5
  //# sourceMappingURL=image-upload-helper.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"image-upload-helper.d.ts","sourceRoot":"","sources":["../../../lib/components/image-upload/image-upload-helper.ts"],"names":[],"mappings":"AAAA,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAGzD"}
1
+ {"version":3,"file":"image-upload-helper.d.ts","sourceRoot":"","sources":["../../../lib/components/image-upload/image-upload-helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAExD,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAGzD;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAO7D;AAED,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,CAO5F"}
@@ -1,6 +1,23 @@
1
- function n(e) {
2
- return e.replace(/[^a-zA-Z0-9-.]/g, "_");
1
+ function t(a) {
2
+ return a.replace(/[^a-zA-Z0-9-.]/g, "_");
3
+ }
4
+ function o(a) {
5
+ return new Promise((r, n) => {
6
+ const e = new FileReader();
7
+ e.onload = () => r(e.result), e.onerror = () => n(e.error ?? new Error("Failed to read image data")), e.readAsDataURL(a);
8
+ });
9
+ }
10
+ async function i(a, r) {
11
+ const e = await (await fetch(a, {
12
+ signal: r
13
+ })).blob();
14
+ return {
15
+ data: await o(e),
16
+ fileName: t(a)
17
+ };
3
18
  }
4
19
  export {
5
- n as sanitizeFilename
20
+ i as loadImageFileItem,
21
+ o as readBlobAsDataUrl,
22
+ t as sanitizeFilename
6
23
  };
@@ -1 +1 @@
1
- {"version":3,"file":"image-upload-modal.d.ts","sourceRoot":"","sources":["../../../lib/components/image-upload/image-upload-modal.tsx"],"names":[],"mappings":"AAOA,OAAiB,EAAE,KAAK,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAIlE,OAAO,EAAE,KAAK,IAAI,EAAE,sBAAsB,EAAE,KAAK,OAAO,EAAE,MAAM,SAAS,CAAC;AAE1E,UAAU,uBAAuB;IAChC,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IACxB,SAAS,EAAE,IAAI,GAAG,SAAS,CAAC;IAC5B,MAAM,EAAE,OAAO,CAAC;IAChB,WAAW,EAAE,sBAAsB,CAAC;IACpC,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IAClB,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,eAAe,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI,EAAE,eAAe,EAAE,OAAO,KAAK,IAAI,CAAC;IAC3F,eAAe,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,KAAK,IAAI,CAAC;CACrC;AAED,wBAAgB,gBAAgB,CAAC,EAChC,KAAK,EACL,GAAG,EACH,SAAS,EACT,MAAM,EACN,WAAW,EACX,IAAI,EACJ,MAAM,EACN,OAAO,EACP,eAAe,EACf,eAAe,EACf,OAAO,GACP,EAAE,uBAAuB,+BAqHzB"}
1
+ {"version":3,"file":"image-upload-modal.d.ts","sourceRoot":"","sources":["../../../lib/components/image-upload/image-upload-modal.tsx"],"names":[],"mappings":"AAOA,OAAiB,EAAE,KAAK,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAIlE,OAAO,EAAE,KAAK,IAAI,EAAE,sBAAsB,EAAE,KAAK,OAAO,EAAE,MAAM,SAAS,CAAC;AAE1E,UAAU,uBAAuB;IAChC,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IACxB,SAAS,EAAE,IAAI,GAAG,SAAS,CAAC;IAC5B,MAAM,EAAE,OAAO,CAAC;IAChB,WAAW,EAAE,sBAAsB,CAAC;IACpC,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IAClB,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,eAAe,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI,EAAE,eAAe,EAAE,OAAO,KAAK,IAAI,CAAC;IAC3F,eAAe,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,KAAK,IAAI,CAAC;CACrC;AAED,wBAAgB,gBAAgB,CAAC,EAChC,KAAK,EACL,GAAG,EACH,SAAS,EACT,MAAM,EACN,WAAW,EACX,IAAI,EACJ,MAAM,EACN,OAAO,EACP,eAAe,EACf,eAAe,EACf,OAAO,GACP,EAAE,uBAAuB,+BA8GzB"}
@@ -1,82 +1,107 @@
1
- import { jsxs as t, jsx as e, Fragment as k } from "react/jsx-runtime";
2
- import { ButtonGroup as D } from "@chakra-ui/react";
3
- import { useState as u, useEffect as H } from "react";
4
- import { ImageCropper as L } from "./image-cropper.js";
5
- import R from "./image-upload-dropzone.js";
6
- import { sanitizeFilename as V } from "./image-upload-helper.js";
7
- import { RemoveIcon as j } from "./image-upload-icons.js";
8
- import { translations as s } from "./translations.js";
9
- import { Modal as O } from "../modal/modal.js";
10
- import { ModalHeader as $ } from "../modal/modal-header.js";
11
- import { Text as w } from "../text/text.js";
12
- import { ModalCloseButton as U } from "../modal/modal-close-button.js";
13
- import { ModalBody as W } from "../modal/modal-body.js";
14
- import { Button as p } from "../button/button.js";
15
- import { ModalFooter as X } from "../modal/modal-footer.js";
16
- import { ThemeSpaceVariable as o, ThemeFontSizeVariable as A, ThemeFontVariable as E, ThemeColorVariable as g } from "../../theme/theme-types.js";
17
- function de({
18
- title: b,
19
- src: r,
20
- savedCrop: S,
21
- isOpen: C,
22
- aspectRatio: x,
23
- crop: c,
24
- locale: i,
25
- onClose: y,
26
- handleSaveImage: I,
27
- setPreviewImage: n,
28
- setCrop: l
29
- }) {
30
- const [M, F] = u(!1), [a, m] = u({
1
+ import { jsx as l, jsxs as b, Fragment as q } from "react/jsx-runtime";
2
+ import { c as J } from "../../_virtual/compiler-runtime.js";
3
+ import { ButtonGroup as K } from "@chakra-ui/react";
4
+ import { useState as E, useEffect as Q } from "react";
5
+ import { ImageCropper as Y } from "./image-cropper.js";
6
+ import Z from "./image-upload-dropzone.js";
7
+ import { loadImageFileItem as W } from "./image-upload-helper.js";
8
+ import { RemoveIcon as ee } from "./image-upload-icons.js";
9
+ import { translations as D } from "./translations.js";
10
+ import { Text as te } from "../text/text.js";
11
+ import { ModalHeader as oe } from "../modal/modal-header.js";
12
+ import { ModalBody as re } from "../modal/modal-body.js";
13
+ import { Button as L } from "../button/button.js";
14
+ import { ModalFooter as ae } from "../modal/modal-footer.js";
15
+ import { ModalCloseButton as le } from "../modal/modal-close-button.js";
16
+ import { Modal as ie } from "../modal/modal.js";
17
+ import { ThemeFontSizeVariable as me, ThemeFontVariable as ne, ThemeColorVariable as X, ThemeSpaceVariable as i } from "../../theme/theme-types.js";
18
+ function Te(A) {
19
+ const e = J.c(48), {
20
+ title: T,
21
+ src: o,
22
+ savedCrop: F,
23
+ isOpen: B,
24
+ aspectRatio: k,
25
+ crop: m,
26
+ locale: n,
27
+ onClose: w,
28
+ handleSaveImage: z,
29
+ setPreviewImage: r,
30
+ setCrop: a
31
+ } = A, [H, G] = E(!1);
32
+ let C;
33
+ e[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (C = {
31
34
  data: "",
32
35
  fileName: ""
33
- }), d = () => {
34
- (async () => {
35
- if (!r)
36
- return;
37
- const B = await (await fetch(r)).blob(), f = new FileReader();
38
- f.readAsDataURL(B), f.onloadend = () => {
39
- m({
40
- data: f.result,
41
- fileName: V(r)
42
- });
43
- };
44
- })().catch(console.error);
45
- };
46
- H(() => {
47
- d();
48
- }, [d]);
49
- const T = () => {
50
- I(a, c, M);
51
- }, N = (!a.data || !a.fileName) && !r, v = (!a.data || !a.fileName) && r, h = () => {
52
- m({
36
+ }, e[0] = C) : C = e[0];
37
+ const [t, u] = E(C);
38
+ let I, S;
39
+ e[1] !== o ? (I = () => {
40
+ if (!o)
41
+ return;
42
+ const j = new AbortController();
43
+ return W(o, j.signal).then((U) => {
44
+ j.signal.aborted || u(U);
45
+ }).catch(console.error), () => {
46
+ j.abort();
47
+ };
48
+ }, S = [o], e[1] = o, e[2] = I, e[3] = S) : (I = e[2], S = e[3]), Q(I, S);
49
+ let v;
50
+ e[4] !== m || e[5] !== t || e[6] !== z || e[7] !== H ? (v = () => {
51
+ z(t, m, H);
52
+ }, e[4] = m, e[5] = t, e[6] = z, e[7] = H, e[8] = v) : v = e[8];
53
+ const O = v, R = (!t.data || !t.fileName) && !o, P = (!t.data || !t.fileName) && o;
54
+ let y;
55
+ e[9] !== w || e[10] !== F || e[11] !== a || e[12] !== r || e[13] !== o ? (y = () => {
56
+ u({
53
57
  data: "",
54
58
  fileName: ""
55
- }), n(""), r && (d(), n(r)), l(S || null), y();
56
- }, z = () => {
57
- m({
59
+ }), r(""), o && (W(o).then(u).catch(console.error), r(o)), a(F || null), w();
60
+ }, e[9] = w, e[10] = F, e[11] = a, e[12] = r, e[13] = o, e[14] = y) : y = e[14];
61
+ const s = y;
62
+ let x;
63
+ e[15] !== a || e[16] !== r ? (x = () => {
64
+ u({
58
65
  data: "",
59
66
  fileName: ""
60
- }), n(""), l(null);
61
- };
62
- return /* @__PURE__ */ t(O, { isOpen: C, onClose: h, size: "md", children: [
63
- /* @__PURE__ */ t($, { display: "flex", alignItems: "center", justifyContent: "space-between", p: o.Medium, children: [
64
- /* @__PURE__ */ e(w, { color: g.OnSurfaceHeader, fontFamily: E.SubHeader, fontWeight: "medium", fontSize: A.XLarge, children: b }),
65
- /* @__PURE__ */ e(U, {})
66
- ] }),
67
- /* @__PURE__ */ e(W, { display: "flex", flexDirection: "column", p: `${o.Large} ${o.Medium}`, children: a.data && a.fileName ? /* @__PURE__ */ t(k, { children: [
68
- /* @__PURE__ */ e(L, { src: a.data, crop: c, onCropCallback: l, aspectRatio: x, setPreviewImage: n }),
69
- /* @__PURE__ */ e(D, { gap: o.Small, mt: o.Large, flexWrap: "wrap", children: /* @__PURE__ */ t(p, { variant: "ghost", onClick: z, gap: o.XSmall, children: [
70
- /* @__PURE__ */ e(j, {}),
71
- "Ta bort bild"
72
- ] }) })
73
- ] }) : /* @__PURE__ */ e(R, { locale: i, setFileItem: m, setHasImageChanged: F }) }),
74
- /* @__PURE__ */ t(X, { p: o.Medium, gap: o.Medium, borderTop: `1px solid ${g.OnSurfaceBorder}`, children: [
75
- /* @__PURE__ */ e(p, { variant: "ghost", onClick: h, children: s[i].secondary }),
76
- /* @__PURE__ */ e(p, { variant: "primary", onClick: T, isDisabled: N, children: v ? s[i].remove : s[i].primary })
77
- ] })
78
- ] });
67
+ }), r(""), a(null);
68
+ }, e[15] = a, e[16] = r, e[17] = x) : x = e[17];
69
+ const V = x;
70
+ let c;
71
+ e[18] !== T ? (c = /* @__PURE__ */ l(te, { color: X.OnSurfaceHeader, fontFamily: ne.SubHeader, fontWeight: "medium", fontSize: me.XLarge, children: T }), e[18] = T, e[19] = c) : c = e[19];
72
+ let M;
73
+ e[20] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (M = /* @__PURE__ */ l(le, {}), e[20] = M) : M = e[20];
74
+ let f;
75
+ e[21] !== c ? (f = /* @__PURE__ */ b(oe, { display: "flex", alignItems: "center", justifyContent: "space-between", p: i.Medium, children: [
76
+ c,
77
+ M
78
+ ] }), e[21] = c, e[22] = f) : f = e[22];
79
+ let d;
80
+ e[23] !== k || e[24] !== m || e[25] !== t.data || e[26] !== t.fileName || e[27] !== V || e[28] !== n || e[29] !== a || e[30] !== r ? (d = /* @__PURE__ */ l(re, { display: "flex", flexDirection: "column", p: `${i.Large} ${i.Medium}`, children: t.data && t.fileName ? /* @__PURE__ */ b(q, { children: [
81
+ /* @__PURE__ */ l(Y, { src: t.data, crop: m, onCropCallback: a, aspectRatio: k, setPreviewImage: r }),
82
+ /* @__PURE__ */ l(K, { gap: i.Small, mt: i.Large, flexWrap: "wrap", children: /* @__PURE__ */ b(L, { variant: "ghost", onClick: V, gap: i.XSmall, children: [
83
+ /* @__PURE__ */ l(ee, {}),
84
+ "Ta bort bild"
85
+ ] }) })
86
+ ] }) : /* @__PURE__ */ l(Z, { locale: n, setFileItem: u, setHasImageChanged: G }) }), e[23] = k, e[24] = m, e[25] = t.data, e[26] = t.fileName, e[27] = V, e[28] = n, e[29] = a, e[30] = r, e[31] = d) : d = e[31];
87
+ const _ = D[n];
88
+ let p;
89
+ e[32] !== s || e[33] !== _.secondary ? (p = /* @__PURE__ */ l(L, { variant: "ghost", onClick: s, children: _.secondary }), e[32] = s, e[33] = _.secondary, e[34] = p) : p = e[34];
90
+ const $ = P ? D[n].remove : D[n].primary;
91
+ let h;
92
+ e[35] !== R || e[36] !== O || e[37] !== $ ? (h = /* @__PURE__ */ l(L, { variant: "primary", onClick: O, isDisabled: R, children: $ }), e[35] = R, e[36] = O, e[37] = $, e[38] = h) : h = e[38];
93
+ let g;
94
+ e[39] !== p || e[40] !== h ? (g = /* @__PURE__ */ b(ae, { p: i.Medium, gap: i.Medium, borderTop: `1px solid ${X.OnSurfaceBorder}`, children: [
95
+ p,
96
+ h
97
+ ] }), e[39] = p, e[40] = h, e[41] = g) : g = e[41];
98
+ let N;
99
+ return e[42] !== s || e[43] !== B || e[44] !== d || e[45] !== g || e[46] !== f ? (N = /* @__PURE__ */ b(ie, { isOpen: B, onClose: s, size: "md", children: [
100
+ f,
101
+ d,
102
+ g
103
+ ] }), e[42] = s, e[43] = B, e[44] = d, e[45] = g, e[46] = f, e[47] = N) : N = e[47], N;
79
104
  }
80
105
  export {
81
- de as ImageUploadModal
106
+ Te as ImageUploadModal
82
107
  };