@kiva/kv-components 10.6.1 → 10.7.0

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 +1 @@
1
- .image-upload-icon[data-v-ea802cf6]{background-color:#ffffffbf;border-radius:9px;display:flex;align-items:center;justify-content:center;border-radius:.5rem}.image-upload-icon--circle[data-v-ea802cf6]{--tw-bg-opacity: 1;background-color:rgb(255 255 255 / var(--tw-bg-opacity, 1));--tw-shadow: 0 1px 4px 0 rgb(0 0 0 / .08);--tw-shadow-colored: 0 1px 4px 0 var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000),var(--tw-ring-shadow, 0 0 #0000),var(--tw-shadow)}
1
+ .image-upload-icon[data-v-373dd692]{background-color:#ffffffbf;border-radius:9px;display:flex;align-items:center;justify-content:center;border-radius:.5rem}.image-upload-icon--circle[data-v-373dd692]{--tw-bg-opacity: 1;background-color:rgb(255 255 255 / var(--tw-bg-opacity, 1));--tw-shadow: 0 1px 4px 0 rgb(0 0 0 / .08);--tw-shadow-colored: 0 1px 4px 0 var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000),var(--tw-ring-shadow, 0 0 #0000),var(--tw-shadow)}
@@ -1,72 +1,85 @@
1
- import p from "./KvImageUpload.script.js";
2
- import { resolveComponent as f, openBlock as i, createElementBlock as n, createElementVNode as a, normalizeStyle as g, normalizeClass as l, renderSlot as b, createVNode as c, withModifiers as w, createCommentVNode as m } from "vue";
1
+ import v from "./KvImageUpload.script.js";
2
+ import { resolveComponent as f, openBlock as t, createElementBlock as r, createElementVNode as i, normalizeStyle as b, normalizeClass as l, renderSlot as c, createVNode as s, toDisplayString as p, withModifiers as m, createCommentVNode as w } from "vue";
3
3
  import "./KvImageUpload.css";
4
- import u from "../_virtual/_plugin-vue_export-helper.js";
5
- const v = { class: "tw-flex tw-flex-col" }, h = ["src", "alt"], C = ["accept", "aria-label"];
6
- function k(d, t, s, e, I, _) {
7
- const r = f("kv-material-icon");
8
- return i(), n("div", v, [
9
- a("div", {
10
- class: l(["kv-image-upload tw-relative", e.shapeClass]),
11
- style: g(e.containerStyle)
4
+ import D from "../_virtual/_plugin-vue_export-helper.js";
5
+ const C = { class: "tw-flex tw-flex-col" }, k = ["src", "alt"], y = { class: "tw-text-label" }, I = ["accept", "aria-label"];
6
+ function h(n, o, d, e, u, O) {
7
+ const g = f("kv-material-icon");
8
+ return t(), r("div", C, [
9
+ i("div", {
10
+ class: l(["kv-image-upload tw-relative", [e.shapeClass, { "kv-image-upload--dragging": e.isDraggingOver }]]),
11
+ style: b(e.containerStyle),
12
+ onDragenter: o[3] || (o[3] = (...a) => e.onDragEnter && e.onDragEnter(...a)),
13
+ onDragover: o[4] || (o[4] = (...a) => e.onDragOver && e.onDragOver(...a)),
14
+ onDragleave: o[5] || (o[5] = (...a) => e.onDragLeave && e.onDragLeave(...a)),
15
+ onDrop: o[6] || (o[6] = (...a) => e.onDrop && e.onDrop(...a))
12
16
  }, [
13
- e.previewImage ? (i(), n("img", {
17
+ e.previewImage ? (t(), r("img", {
14
18
  key: 0,
15
19
  src: e.previewImage,
16
- alt: s.imageAlt,
20
+ alt: d.imageAlt,
17
21
  class: l(["tw-w-full tw-h-full tw-object-cover", e.shapeClass])
18
- }, null, 10, h)) : b(d.$slots, "fallback-image", { key: 1 }, () => [
19
- a("div", {
22
+ }, null, 10, k)) : c(n.$slots, "fallback-image", {
23
+ key: 1,
24
+ isDraggingOver: e.isDraggingOver
25
+ }, () => [
26
+ i("div", {
20
27
  class: l(["kv-image-upload__placeholder tw-w-full tw-h-full tw-bg-eco-green-1 tw-p-0.5", e.shapeClass])
21
28
  }, [
22
- a("div", {
23
- class: l(["tw-flex tw-flex-col tw-items-center tw-justify-center tw-gap-0.5 tw-w-full tw-h-full tw-border-2 tw-border-dashed tw-border-black", e.shapeClass])
29
+ i("div", {
30
+ class: l(["tw-flex tw-flex-col tw-items-center tw-justify-center tw-gap-0.5 tw-w-full tw-h-full tw-border-2 tw-border-dashed", [e.shapeClass, e.isDraggingOver ? "tw-border-action" : "tw-border-black"]])
24
31
  }, [
25
- c(r, {
32
+ s(g, {
26
33
  icon: e.mdiCameraPlusOutline,
27
34
  class: "tw-w-3.5"
28
35
  }, null, 8, ["icon"]),
29
- t[3] || (t[3] = a("span", { class: "tw-text-label" }, " Add a photo ", -1))
36
+ i("span", y, p(e.isDraggingOver ? "Drop to upload" : "Add a photo"), 1)
30
37
  ], 2)
31
38
  ], 2)
32
39
  ], !0),
33
- a("input", {
40
+ i("input", {
34
41
  ref: "fileInput",
35
42
  type: "file",
36
43
  accept: e.acceptAttr,
37
44
  "aria-label": e.inputLabel,
38
45
  class: "tw-absolute tw-inset-0 tw-w-full tw-h-full tw-opacity-0 tw-cursor-pointer",
39
- onChange: t[0] || (t[0] = (...o) => e.handleFileChange && e.handleFileChange(...o))
40
- }, null, 40, C),
41
- e.previewImage || s.showEditIcon ? (i(), n("button", {
46
+ onChange: o[0] || (o[0] = (...a) => e.handleFileChange && e.handleFileChange(...a))
47
+ }, null, 40, I),
48
+ e.previewImage || d.showEditIcon ? (t(), r("button", {
42
49
  key: 2,
43
- class: l(["image-upload-icon edit-icon tw-absolute tw-bottom-1 tw-right-1 tw-p-1 tw-z-10", { "image-upload-icon--circle": e.isCircle }]),
50
+ class: l(["image-upload-icon edit-icon tw-absolute tw-bottom-1 tw-right-1 tw-p-1 tw-z-1", { "image-upload-icon--circle": e.isCircle }]),
44
51
  type: "button",
45
52
  "aria-hidden": "true",
46
53
  tabindex: "-1",
47
- onClick: t[1] || (t[1] = w((...o) => e.openFileInput && e.openFileInput(...o), ["stop"]))
54
+ onClick: o[1] || (o[1] = m((...a) => e.openFileInput && e.openFileInput(...a), ["stop"]))
48
55
  }, [
49
- c(r, {
56
+ s(g, {
50
57
  icon: e.mdiPencil,
51
58
  class: "tw-w-2"
52
59
  }, null, 8, ["icon"])
53
- ], 2)) : m("", !0),
54
- e.previewImage ? (i(), n("button", {
60
+ ], 2)) : w("", !0),
61
+ e.previewImage ? (t(), r("button", {
55
62
  key: 3,
56
- class: l(["image-upload-icon remove-icon tw-absolute tw-top-1 tw-right-1 tw-p-1 tw-z-10", { "image-upload-icon--circle": e.isCircle }]),
63
+ class: l(["image-upload-icon remove-icon tw-absolute tw-top-1 tw-right-1 tw-p-1 tw-z-1", { "image-upload-icon--circle": e.isCircle }]),
57
64
  type: "button",
58
65
  "aria-label": "Remove Image",
59
- onClick: t[2] || (t[2] = w((...o) => e.removeImage && e.removeImage(...o), ["stop"]))
66
+ onClick: o[2] || (o[2] = m((...a) => e.removeImage && e.removeImage(...a), ["stop"]))
60
67
  }, [
61
- c(r, {
68
+ s(g, {
62
69
  icon: e.mdiClose,
63
70
  class: "tw-w-2"
64
71
  }, null, 8, ["icon"])
65
- ], 2)) : m("", !0)
66
- ], 6)
72
+ ], 2)) : w("", !0),
73
+ e.isDraggingOver && e.previewImage && n.$slots["drag-overlay"] ? (t(), r("div", {
74
+ key: 4,
75
+ class: l(["tw-absolute tw-inset-0 tw-z-2 tw-pointer-events-none", e.shapeClass])
76
+ }, [
77
+ c(n.$slots, "drag-overlay", {}, void 0, !0)
78
+ ], 2)) : w("", !0)
79
+ ], 38)
67
80
  ]);
68
81
  }
69
- const A = /* @__PURE__ */ u(p, [["render", k], ["__scopeId", "data-v-ea802cf6"]]);
82
+ const F = /* @__PURE__ */ D(v, [["render", h], ["__scopeId", "data-v-373dd692"]]);
70
83
  export {
71
- A as default
84
+ F as default
72
85
  };
@@ -1,10 +1,10 @@
1
- import { toRefs as S, ref as u, watch as x, computed as l } from "vue";
2
- import { mdiCameraPlusOutline as F, mdiClose as w, mdiPencil as I } from "@mdi/js";
3
- import C from "./KvMaterialIcon.js";
4
- import { DEFAULT_ACCEPTED_IMAGE_TYPES as b, validateImageFile as R, cropResizeImageToDataUrl as T } from "../utils/imageUtils.js";
5
- const U = {
1
+ import { toRefs as T, ref as f, watch as w, computed as o } from "vue";
2
+ import { mdiCameraPlusOutline as E, mdiClose as I, mdiPencil as C } from "@mdi/js";
3
+ import b from "./KvMaterialIcon.js";
4
+ import { DEFAULT_ACCEPTED_IMAGE_TYPES as R, validateImageFile as z, cropResizeImageToDataUrl as A } from "../utils/imageUtils.js";
5
+ const H = {
6
6
  components: {
7
- KvMaterialIcon: C
7
+ KvMaterialIcon: b
8
8
  },
9
9
  props: {
10
10
  /**
@@ -27,8 +27,8 @@ const U = {
27
27
  shape: {
28
28
  type: String,
29
29
  default: "square",
30
- validator(e) {
31
- return ["square", "circle"].includes(e);
30
+ validator(a) {
31
+ return ["square", "circle"].includes(a);
32
32
  }
33
33
  },
34
34
  /**
@@ -59,7 +59,7 @@ const U = {
59
59
  */
60
60
  acceptedFileTypes: {
61
61
  type: Array,
62
- default: () => [...b]
62
+ default: () => [...R]
63
63
  },
64
64
  /**
65
65
  * Whether to show the edit (pencil) affordance in the blank state, before an image is
@@ -92,59 +92,85 @@ const U = {
92
92
  */
93
93
  "file-error"
94
94
  ],
95
- setup(e, { emit: r }) {
96
- const { imageUrl: c } = S(e), a = u(c.value || ""), s = u(null);
97
- x(c, (t) => {
98
- a.value = t || "";
95
+ setup(a, { emit: s }) {
96
+ const { imageUrl: d } = T(a), n = f(d.value || ""), m = f(null), c = f(!1);
97
+ let l = 0;
98
+ w(d, (e) => {
99
+ n.value = e || "";
99
100
  });
100
- const m = l(() => e.shape === "circle"), d = l(() => m.value ? "tw-rounded-full" : "tw-rounded"), p = l(() => e.acceptedFileTypes.join(",")), f = l(() => a.value ? "Change image" : "Upload image"), g = l(() => ({
101
- aspectRatio: String(e.aspectRatio),
102
- maxHeight: `${e.previewSize}px`,
103
- maxWidth: `${e.previewSize * e.aspectRatio}px`
104
- })), v = () => {
105
- var t;
106
- (t = s.value) == null || t.click();
107
- }, y = () => {
108
- a.value = "", r("file-removed");
109
- }, h = async (t) => {
110
- const { valid: o, error: i } = R(t, {
111
- maxSizeMb: e.maxSizeMb,
112
- acceptedFileTypes: e.acceptedFileTypes
101
+ const p = o(() => a.shape === "circle"), v = o(() => p.value ? "tw-rounded-full" : "tw-rounded"), y = o(() => a.acceptedFileTypes.join(",")), D = o(() => n.value ? "Change image" : "Upload image"), h = o(() => ({
102
+ aspectRatio: String(a.aspectRatio),
103
+ maxHeight: `${a.previewSize}px`,
104
+ maxWidth: `${a.previewSize * a.aspectRatio}px`
105
+ })), x = () => {
106
+ var e;
107
+ (e = m.value) == null || e.click();
108
+ }, F = () => {
109
+ n.value = "", s("file-removed");
110
+ }, g = async (e) => {
111
+ const { valid: t, error: r } = z(e, {
112
+ maxSizeMb: a.maxSizeMb,
113
+ acceptedFileTypes: a.acceptedFileTypes
113
114
  });
114
- if (!o && i) {
115
- r("file-error", i);
115
+ if (!t && r) {
116
+ s("file-error", r);
116
117
  return;
117
118
  }
118
119
  try {
119
- a.value = await T(t, {
120
- aspectRatio: e.aspectRatio,
121
- maxDimension: e.maxDimension
122
- }), r("file-uploaded", { file: t });
120
+ n.value = await A(e, {
121
+ aspectRatio: a.aspectRatio,
122
+ maxDimension: a.maxDimension
123
+ }), s("file-uploaded", { file: e });
123
124
  } catch {
124
- r("file-error", { type: "other", message: "Failed to read file" });
125
+ s("file-error", { type: "other", message: "Failed to read file" });
125
126
  }
127
+ }, S = (e) => {
128
+ var i;
129
+ const t = e.target, r = (i = t.files) == null ? void 0 : i[0];
130
+ r && (g(r), t.value = "");
131
+ }, u = (e) => {
132
+ var t;
133
+ return Array.from(((t = e.dataTransfer) == null ? void 0 : t.types) ?? []).includes("Files");
126
134
  };
127
135
  return {
128
- mdiPencil: I,
129
- mdiClose: w,
130
- mdiCameraPlusOutline: F,
131
- fileInput: s,
132
- previewImage: a,
133
- isCircle: m,
134
- shapeClass: d,
135
- acceptAttr: p,
136
- inputLabel: f,
137
- containerStyle: g,
138
- openFileInput: v,
139
- removeImage: y,
140
- handleFileChange: (t) => {
141
- var n;
142
- const o = t.target, i = (n = o.files) == null ? void 0 : n[0];
143
- i && (h(i), o.value = "");
136
+ mdiPencil: C,
137
+ mdiClose: I,
138
+ mdiCameraPlusOutline: E,
139
+ fileInput: m,
140
+ previewImage: n,
141
+ isCircle: p,
142
+ isDraggingOver: c,
143
+ shapeClass: v,
144
+ acceptAttr: y,
145
+ inputLabel: D,
146
+ containerStyle: h,
147
+ openFileInput: x,
148
+ removeImage: F,
149
+ handleFileChange: S,
150
+ onDragEnter: (e) => {
151
+ u(e) && (l += 1, c.value = !0);
152
+ },
153
+ onDragOver: (e) => {
154
+ if (!u(e))
155
+ return;
156
+ e.preventDefault();
157
+ const { dataTransfer: t } = e;
158
+ t && (t.dropEffect = "copy");
159
+ },
160
+ onDragLeave: (e) => {
161
+ u(e) && (l = Math.max(0, l - 1), l === 0 && (c.value = !1));
162
+ },
163
+ onDrop: (e) => {
164
+ var r, i;
165
+ if (!u(e))
166
+ return;
167
+ e.preventDefault(), l = 0, c.value = !1;
168
+ const t = (i = (r = e.dataTransfer) == null ? void 0 : r.files) == null ? void 0 : i[0];
169
+ t && g(t);
144
170
  }
145
171
  };
146
172
  }
147
173
  };
148
174
  export {
149
- U as default
175
+ H as default
150
176
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kiva/kv-components",
3
- "version": "10.6.1",
3
+ "version": "10.7.0",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -116,5 +116,5 @@
116
116
  "dependencies": {
117
117
  "fuse.js": "^7.1.0"
118
118
  },
119
- "gitHead": "a55163da474c53d2958af25e6b68684b3f1922db"
119
+ "gitHead": "23f2971b14728c8457a2e3bccd9e57c50fb016d1"
120
120
  }