iron-cms 0.17.2 → 0.17.3
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.
- checksums.yaml +4 -4
- data/app/assets/builds/iron.css +19 -0
- data/app/assets/tailwind/iron/application.css +1 -0
- data/app/assets/tailwind/iron/components/file-upload.css +26 -0
- data/app/javascript/iron/controllers/file_upload_controller.js +38 -7
- data/app/views/iron/entries/fields/_file.html.erb +7 -0
- data/lib/iron/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 902cb70c9fa801865eb767b180e48c892600b733fa3dbd68aecd7037c26be303
|
|
4
|
+
data.tar.gz: 6d446f80c7e37f3ff23f2c35dff923ed91a4d78dfcaacd6ec334991a3f711158
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f5ea399948c341b561a0bc750b6f8cfa77125ae7b19e9cbf5771530ce59d65d2de131fb670675a487f805e88027ee603de18715e34b9d9affbbb70bf4f4dbd07
|
|
7
|
+
data.tar.gz: 6bfd83e521d7c923be66718088dbef7a07ac1cc466eb89fbec9d0da7e6d0f186c66365f32e395e89df42470fcffdc7b5acbf78cfa0ff1a7731763602d12d374a
|
data/app/assets/builds/iron.css
CHANGED
|
@@ -7032,6 +7032,25 @@ dialog.modal {
|
|
|
7032
7032
|
color: var(--color-amber-400);
|
|
7033
7033
|
}
|
|
7034
7034
|
}
|
|
7035
|
+
[data-controller="file-upload"] {
|
|
7036
|
+
[data-file-upload-target="documentPreview"] {
|
|
7037
|
+
display: none;
|
|
7038
|
+
}
|
|
7039
|
+
[data-file-icon] {
|
|
7040
|
+
display: none;
|
|
7041
|
+
}
|
|
7042
|
+
[data-file-upload-target="previewWrapper"]:not([data-file-kind="image"]) {
|
|
7043
|
+
[data-file-upload-target="preview"] {
|
|
7044
|
+
display: none;
|
|
7045
|
+
}
|
|
7046
|
+
[data-file-upload-target="documentPreview"] {
|
|
7047
|
+
display: flex;
|
|
7048
|
+
}
|
|
7049
|
+
}
|
|
7050
|
+
[data-file-kind="pdf"] [data-file-icon="pdf"], [data-file-kind="audio"] [data-file-icon="audio"], [data-file-kind="video"] [data-file-icon="video"], [data-file-kind="file"] [data-file-icon="file"] {
|
|
7051
|
+
display: block;
|
|
7052
|
+
}
|
|
7053
|
+
}
|
|
7035
7054
|
:root {
|
|
7036
7055
|
--highlight-1: rgb(136, 118, 38);
|
|
7037
7056
|
--highlight-2: rgb(185, 94, 6);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
[data-controller="file-upload"] {
|
|
2
|
+
[data-file-upload-target="documentPreview"] {
|
|
3
|
+
@apply hidden;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
[data-file-icon] {
|
|
7
|
+
@apply hidden;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
[data-file-upload-target="previewWrapper"]:not([data-file-kind="image"]) {
|
|
11
|
+
[data-file-upload-target="preview"] {
|
|
12
|
+
@apply hidden;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
[data-file-upload-target="documentPreview"] {
|
|
16
|
+
@apply flex;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
[data-file-kind="pdf"] [data-file-icon="pdf"],
|
|
21
|
+
[data-file-kind="audio"] [data-file-icon="audio"],
|
|
22
|
+
[data-file-kind="video"] [data-file-icon="video"],
|
|
23
|
+
[data-file-kind="file"] [data-file-icon="file"] {
|
|
24
|
+
@apply block;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Controller } from "@hotwired/stimulus";
|
|
2
2
|
|
|
3
3
|
export default class FileUploadController extends Controller {
|
|
4
|
-
static targets = ["preview", "placeholder", "previewWrapper"];
|
|
4
|
+
static targets = ["preview", "placeholder", "previewWrapper", "filename"];
|
|
5
5
|
|
|
6
6
|
connect() {
|
|
7
7
|
if (this.hasPreviewTarget) {
|
|
@@ -16,19 +16,27 @@ export default class FileUploadController extends Controller {
|
|
|
16
16
|
const file = event.target.files[0];
|
|
17
17
|
if (!file) return;
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
const kind = this.#kindOf(file.type);
|
|
20
|
+
|
|
21
|
+
if (kind === "image") {
|
|
22
|
+
if (this.hasPreviewTarget) {
|
|
23
|
+
this.previewTarget.src = URL.createObjectURL(file);
|
|
24
|
+
}
|
|
25
|
+
} else if (this.hasFilenameTarget) {
|
|
26
|
+
this.filenameTarget.textContent = file.name;
|
|
24
27
|
}
|
|
25
|
-
|
|
28
|
+
|
|
29
|
+
this.#markFileKind(kind);
|
|
30
|
+
this.#revealPreview();
|
|
26
31
|
}
|
|
27
32
|
|
|
28
33
|
reset() {
|
|
29
34
|
if (this.hasPreviewTarget) {
|
|
30
35
|
this.previewTarget.src = this.originalSrc;
|
|
31
36
|
}
|
|
37
|
+
if (this.hasPreviewWrapperTarget) {
|
|
38
|
+
delete this.previewWrapperTarget.dataset.fileKind;
|
|
39
|
+
}
|
|
32
40
|
if (this.originalHidden) {
|
|
33
41
|
this.previewElement?.classList.add("hidden");
|
|
34
42
|
if (this.hasPlaceholderTarget) {
|
|
@@ -42,4 +50,27 @@ export default class FileUploadController extends Controller {
|
|
|
42
50
|
if (this.hasPreviewTarget) return this.previewTarget;
|
|
43
51
|
return null;
|
|
44
52
|
}
|
|
53
|
+
|
|
54
|
+
// Private
|
|
55
|
+
|
|
56
|
+
#markFileKind(kind) {
|
|
57
|
+
if (this.hasPreviewWrapperTarget) {
|
|
58
|
+
this.previewWrapperTarget.dataset.fileKind = kind;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
#revealPreview() {
|
|
63
|
+
if (this.hasPlaceholderTarget) {
|
|
64
|
+
this.placeholderTarget.classList.add("hidden");
|
|
65
|
+
}
|
|
66
|
+
this.previewElement?.classList.remove("hidden");
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
#kindOf(contentType) {
|
|
70
|
+
if (contentType.startsWith("image/")) return "image";
|
|
71
|
+
if (contentType === "application/pdf") return "pdf";
|
|
72
|
+
if (contentType.startsWith("audio/")) return "audio";
|
|
73
|
+
if (contentType.startsWith("video/")) return "video";
|
|
74
|
+
return "file";
|
|
75
|
+
}
|
|
45
76
|
}
|
|
@@ -49,6 +49,13 @@
|
|
|
49
49
|
class="h-full w-full object-cover object-center"
|
|
50
50
|
data-file-upload-target="preview"
|
|
51
51
|
>
|
|
52
|
+
<div class="h-full w-full flex-col items-center justify-center gap-2 p-4 text-stone-500 dark:text-stone-400" data-file-upload-target="documentPreview">
|
|
53
|
+
<%= icon "file", class: "size-10", data: { file_icon: "file" } %>
|
|
54
|
+
<%= icon "file-text", class: "size-10", data: { file_icon: "pdf" } %>
|
|
55
|
+
<%= icon "file-audio", class: "size-10", data: { file_icon: "audio" } %>
|
|
56
|
+
<%= icon "file-video", class: "size-10", data: { file_icon: "video" } %>
|
|
57
|
+
<p class="text-sm font-medium truncate max-w-full" data-file-upload-target="filename"></p>
|
|
58
|
+
</div>
|
|
52
59
|
</div>
|
|
53
60
|
<% end %>
|
|
54
61
|
|
data/lib/iron/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: iron-cms
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.17.
|
|
4
|
+
version: 0.17.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Massimo De Marchi
|
|
@@ -290,6 +290,7 @@ files:
|
|
|
290
290
|
- app/assets/tailwind/iron/components/field-definition.css
|
|
291
291
|
- app/assets/tailwind/iron/components/fieldset.css
|
|
292
292
|
- app/assets/tailwind/iron/components/file-scope-picker.css
|
|
293
|
+
- app/assets/tailwind/iron/components/file-upload.css
|
|
293
294
|
- app/assets/tailwind/iron/components/form.css
|
|
294
295
|
- app/assets/tailwind/iron/components/icon-picker.css
|
|
295
296
|
- app/assets/tailwind/iron/components/input.css
|