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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7441460ff6c611510525a11808f5fe2deb724574380f91b5ffab5edbb1c571a0
4
- data.tar.gz: 157944fd97ba5e0b6aba79409fd0b456bd6bef4cb802ed836eba2dc9b693de15
3
+ metadata.gz: 902cb70c9fa801865eb767b180e48c892600b733fa3dbd68aecd7037c26be303
4
+ data.tar.gz: 6d446f80c7e37f3ff23f2c35dff923ed91a4d78dfcaacd6ec334991a3f711158
5
5
  SHA512:
6
- metadata.gz: 5fd0f51df8afd88331e30b3349eee6e1dfb6df988ab1f17b5a5362d2e94f71d6fbabfb2e62001c8627c6e2a2c5c0a0ad998c4ae9b192319b6cf37d392ef13fe2
7
- data.tar.gz: a6a1b3169c158dae96b9190b0553b0e83eaf450df510cefcc70915aca31087284d495fc28269c271a9827f3a59f2d04cca87657b00e22e0e392cd3eedbec8ae7
6
+ metadata.gz: f5ea399948c341b561a0bc750b6f8cfa77125ae7b19e9cbf5771530ce59d65d2de131fb670675a487f805e88027ee603de18715e34b9d9affbbb70bf4f4dbd07
7
+ data.tar.gz: 6bfd83e521d7c923be66718088dbef7a07ac1cc466eb89fbec9d0da7e6d0f186c66365f32e395e89df42470fcffdc7b5acbf78cfa0ff1a7731763602d12d374a
@@ -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);
@@ -29,6 +29,7 @@
29
29
  @import './components/selection-list.css';
30
30
  @import './components/file-scope-picker.css';
31
31
  @import './components/content-type-card.css';
32
+ @import './components/file-upload.css';
32
33
  @import './lexxy.css';
33
34
 
34
35
  @plugin '@tailwindcss/typography';
@@ -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
- if (this.hasPreviewTarget) {
20
- this.previewTarget.src = URL.createObjectURL(file);
21
- }
22
- if (this.hasPlaceholderTarget) {
23
- this.placeholderTarget.classList.add("hidden");
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
- this.previewElement?.classList.remove("hidden");
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
@@ -1,3 +1,3 @@
1
1
  module Iron
2
- VERSION = "0.17.2"
2
+ VERSION = "0.17.3"
3
3
  end
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.2
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