@molecule/app-file-card-vue 0.0.0-stage → 0.0.1-stage
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/LICENSE +202 -0
- package/README.md +10 -2
- package/dist/FileCard.d.ts +110 -0
- package/dist/FileCard.d.ts.map +1 -0
- package/dist/FileCard.js +336 -0
- package/dist/FileCard.js.map +1 -0
- package/dist/FileIcon.d.ts +48 -0
- package/dist/FileIcon.d.ts.map +1 -0
- package/dist/FileIcon.js +98 -0
- package/dist/FileIcon.js.map +1 -0
- package/dist/format.d.ts +80 -0
- package/dist/format.d.ts.map +1 -0
- package/dist/format.js +88 -0
- package/dist/format.js.map +1 -0
- package/dist/index.d.ts +60 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +60 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +71 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -0
- package/package.json +65 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @molecule/app-file-card-vue
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Vue file card primitives — icon, name, size, modified date, actions; grid + row layouts
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
npm install @molecule/app-file-card-vue
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Part of the [Molecule](https://www.molecule.dev) package fleet. This page carries the manifest summary; the full generated documentation ships with the package's first committed version.
|
|
10
|
+
|
|
11
|
+
License: Apache-2.0
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vue file representation card — icon (or thumbnail), filename, formatted
|
|
3
|
+
* size, relative modified date, and an optional trailing actions slot, in
|
|
4
|
+
* `'grid'` (square tile) or `'row'` (horizontal line) layout.
|
|
5
|
+
*
|
|
6
|
+
* Vue counterpart of `@molecule/app-file-card-react`'s `FileCard` — the same
|
|
7
|
+
* props (React names) and the same DOM for the same input.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
import { type PropType, type VNode } from 'vue';
|
|
12
|
+
import type { FileCardProps, FileSummary } from './types.js';
|
|
13
|
+
/**
|
|
14
|
+
* File representation card — icon (or thumbnail), filename, formatted size,
|
|
15
|
+
* relative modified date, and optional trailing actions slot. Used by
|
|
16
|
+
* cloud-file-manager grids/lists, social-media + email-client attachment
|
|
17
|
+
* previews, and document-collaboration sidebars.
|
|
18
|
+
*
|
|
19
|
+
* Two layouts:
|
|
20
|
+
* - `'grid'` (default) — square tile with the icon/thumbnail stacked above
|
|
21
|
+
* the metadata. Suitable for finder-style grids and attachment galleries.
|
|
22
|
+
* - `'row'` — horizontal line item with the icon on the left, metadata in
|
|
23
|
+
* the middle, and the actions slot on the right. Suitable for list views
|
|
24
|
+
* and chat/email attachment rows.
|
|
25
|
+
*
|
|
26
|
+
* All styling routes through `getClassMap()`. All user-visible text routes
|
|
27
|
+
* through `t()` so the card translates via the companion
|
|
28
|
+
* `@molecule/app-locales-file-card` locale bond.
|
|
29
|
+
*
|
|
30
|
+
* @param props - Component props (see {@link FileCardProps}).
|
|
31
|
+
* @returns The file card component.
|
|
32
|
+
*/
|
|
33
|
+
export declare const FileCard: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
34
|
+
file: {
|
|
35
|
+
type: PropType<FileSummary>;
|
|
36
|
+
required: true;
|
|
37
|
+
};
|
|
38
|
+
selected: {
|
|
39
|
+
type: BooleanConstructor;
|
|
40
|
+
default: undefined;
|
|
41
|
+
};
|
|
42
|
+
onClick: {
|
|
43
|
+
type: PropType<FileCardProps["onClick"]>;
|
|
44
|
+
default: undefined;
|
|
45
|
+
};
|
|
46
|
+
onContextMenu: {
|
|
47
|
+
type: PropType<FileCardProps["onContextMenu"]>;
|
|
48
|
+
default: undefined;
|
|
49
|
+
};
|
|
50
|
+
layout: {
|
|
51
|
+
type: PropType<"grid" | "row">;
|
|
52
|
+
default: string;
|
|
53
|
+
};
|
|
54
|
+
actions: null;
|
|
55
|
+
now: {
|
|
56
|
+
type: PropType<Date>;
|
|
57
|
+
default: undefined;
|
|
58
|
+
};
|
|
59
|
+
className: {
|
|
60
|
+
type: StringConstructor;
|
|
61
|
+
default: undefined;
|
|
62
|
+
};
|
|
63
|
+
dataMolId: {
|
|
64
|
+
type: StringConstructor;
|
|
65
|
+
default: undefined;
|
|
66
|
+
};
|
|
67
|
+
}>, () => VNode, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
68
|
+
file: {
|
|
69
|
+
type: PropType<FileSummary>;
|
|
70
|
+
required: true;
|
|
71
|
+
};
|
|
72
|
+
selected: {
|
|
73
|
+
type: BooleanConstructor;
|
|
74
|
+
default: undefined;
|
|
75
|
+
};
|
|
76
|
+
onClick: {
|
|
77
|
+
type: PropType<FileCardProps["onClick"]>;
|
|
78
|
+
default: undefined;
|
|
79
|
+
};
|
|
80
|
+
onContextMenu: {
|
|
81
|
+
type: PropType<FileCardProps["onContextMenu"]>;
|
|
82
|
+
default: undefined;
|
|
83
|
+
};
|
|
84
|
+
layout: {
|
|
85
|
+
type: PropType<"grid" | "row">;
|
|
86
|
+
default: string;
|
|
87
|
+
};
|
|
88
|
+
actions: null;
|
|
89
|
+
now: {
|
|
90
|
+
type: PropType<Date>;
|
|
91
|
+
default: undefined;
|
|
92
|
+
};
|
|
93
|
+
className: {
|
|
94
|
+
type: StringConstructor;
|
|
95
|
+
default: undefined;
|
|
96
|
+
};
|
|
97
|
+
dataMolId: {
|
|
98
|
+
type: StringConstructor;
|
|
99
|
+
default: undefined;
|
|
100
|
+
};
|
|
101
|
+
}>> & Readonly<{}>, {
|
|
102
|
+
onClick: ((file: FileSummary, event: MouseEvent) => void) | undefined;
|
|
103
|
+
onContextMenu: ((file: FileSummary, event: MouseEvent) => void) | undefined;
|
|
104
|
+
selected: boolean;
|
|
105
|
+
layout: "grid" | "row";
|
|
106
|
+
now: Date;
|
|
107
|
+
className: string;
|
|
108
|
+
dataMolId: string;
|
|
109
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
110
|
+
//# sourceMappingURL=FileCard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileCard.d.ts","sourceRoot":"","sources":["../src/FileCard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAsB,KAAK,QAAQ,EAAE,KAAK,KAAK,EAAmB,MAAM,KAAK,CAAA;AAOpF,OAAO,KAAK,EAAE,aAAa,EAAY,WAAW,EAAE,MAAM,YAAY,CAAA;AAqItE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,QAAQ;;cAIC,QAAQ,CAAC,WAAW,CAAC;;;;;;;;cAQnB,QAAQ,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;;;;cAIlC,QAAQ,CAAC,aAAa,CAAC,eAAe,CAAC,CAAC;;;;cAI1C,QAAQ,CAAC,MAAM,GAAG,KAAK,CAAC;;;;;cAOxB,QAAQ,CAAC,IAAI,CAAC;;;;;;;;;;;UAmCrB,KAAK;;cA1DE,QAAQ,CAAC,WAAW,CAAC;;;;;;;;cAQnB,QAAQ,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;;;;cAIlC,QAAQ,CAAC,aAAa,CAAC,eAAe,CAAC,CAAC;;;;cAI1C,QAAQ,CAAC,MAAM,GAAG,KAAK,CAAC;;;;;cAOxB,QAAQ,CAAC,IAAI,CAAC;;;;;;;;;;;;;;;;;;;4EA8OlC,CAAA"}
|
package/dist/FileCard.js
ADDED
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vue file representation card — icon (or thumbnail), filename, formatted
|
|
3
|
+
* size, relative modified date, and an optional trailing actions slot, in
|
|
4
|
+
* `'grid'` (square tile) or `'row'` (horizontal line) layout.
|
|
5
|
+
*
|
|
6
|
+
* Vue counterpart of `@molecule/app-file-card-react`'s `FileCard` — the same
|
|
7
|
+
* props (React names) and the same DOM for the same input.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
import { defineComponent, h } from 'vue';
|
|
12
|
+
import { getClassMap } from '@molecule/app-ui';
|
|
13
|
+
import { useTranslation } from '@molecule/app-vue';
|
|
14
|
+
import { FileIcon } from './FileIcon.js';
|
|
15
|
+
import { relativeBucket, sizeParts } from './format.js';
|
|
16
|
+
/**
|
|
17
|
+
* Resolves the node-valued `actions` prop that may also arrive as a
|
|
18
|
+
* same-named slot: the prop wins, and an absent pair contributes nothing.
|
|
19
|
+
*
|
|
20
|
+
* @param prop - The prop value, when the caller passed the prop.
|
|
21
|
+
* @param slot - The slot render function, when the caller passed the slot.
|
|
22
|
+
* @returns The children to render.
|
|
23
|
+
*/
|
|
24
|
+
const propOrSlot = (prop, slot) => {
|
|
25
|
+
if (prop !== undefined && prop !== null && prop !== false)
|
|
26
|
+
return [prop];
|
|
27
|
+
if (slot)
|
|
28
|
+
return slot();
|
|
29
|
+
return [];
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Resolve the relative-time text for a file via `t()`. Keeps the render clean
|
|
33
|
+
* and centralizes the bucket → key mapping.
|
|
34
|
+
*
|
|
35
|
+
* @param at - Modified-at timestamp.
|
|
36
|
+
* @param t - The `useTranslation()` `t` function.
|
|
37
|
+
* @param now - Reference "now".
|
|
38
|
+
* @returns The localized relative-time string.
|
|
39
|
+
*/
|
|
40
|
+
function relativeText(at, t, now) {
|
|
41
|
+
const bucket = relativeBucket(at, now);
|
|
42
|
+
switch (bucket.kind) {
|
|
43
|
+
case 'just-now':
|
|
44
|
+
return t('file-card.modified.just-now', {}, { defaultValue: 'just now' });
|
|
45
|
+
case 'minutes':
|
|
46
|
+
return t(bucket.n === 1 ? 'file-card.modified.minute-one' : 'file-card.modified.minute-other', { count: bucket.n }, { defaultValue: bucket.n === 1 ? '1 min ago' : `${bucket.n} min ago` });
|
|
47
|
+
case 'hours':
|
|
48
|
+
return t(bucket.n === 1 ? 'file-card.modified.hour-one' : 'file-card.modified.hour-other', { count: bucket.n }, { defaultValue: bucket.n === 1 ? '1 hr ago' : `${bucket.n} hr ago` });
|
|
49
|
+
case 'days':
|
|
50
|
+
return t(bucket.n === 1 ? 'file-card.modified.day-one' : 'file-card.modified.day-other', { count: bucket.n }, { defaultValue: bucket.n === 1 ? 'yesterday' : `${bucket.n} days ago` });
|
|
51
|
+
case 'weeks':
|
|
52
|
+
return t(bucket.n === 1 ? 'file-card.modified.week-one' : 'file-card.modified.week-other', { count: bucket.n }, { defaultValue: bucket.n === 1 ? '1 wk ago' : `${bucket.n} wk ago` });
|
|
53
|
+
case 'months':
|
|
54
|
+
return t(bucket.n === 1 ? 'file-card.modified.month-one' : 'file-card.modified.month-other', { count: bucket.n }, { defaultValue: bucket.n === 1 ? '1 mo ago' : `${bucket.n} mo ago` });
|
|
55
|
+
case 'absolute':
|
|
56
|
+
return bucket.iso;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Resolve the human-readable kind label via `t()`. One literal key per
|
|
61
|
+
* `FileKind` so the i18n gate can verify every key exists in the locale
|
|
62
|
+
* bond (a runtime-built `` `file-card.kind.${kind}` `` cannot be checked).
|
|
63
|
+
*
|
|
64
|
+
* @param kind - File kind.
|
|
65
|
+
* @param t - The `useTranslation()` `t` function.
|
|
66
|
+
* @returns The localized kind label.
|
|
67
|
+
*/
|
|
68
|
+
function kindText(kind, t) {
|
|
69
|
+
switch (kind) {
|
|
70
|
+
case 'image':
|
|
71
|
+
return t('file-card.kind.image', {}, { defaultValue: 'Image file' });
|
|
72
|
+
case 'video':
|
|
73
|
+
return t('file-card.kind.video', {}, { defaultValue: 'Video file' });
|
|
74
|
+
case 'audio':
|
|
75
|
+
return t('file-card.kind.audio', {}, { defaultValue: 'Audio file' });
|
|
76
|
+
case 'document':
|
|
77
|
+
return t('file-card.kind.document', {}, { defaultValue: 'Document' });
|
|
78
|
+
case 'archive':
|
|
79
|
+
return t('file-card.kind.archive', {}, { defaultValue: 'Archive' });
|
|
80
|
+
case 'code':
|
|
81
|
+
return t('file-card.kind.code', {}, { defaultValue: 'Code file' });
|
|
82
|
+
case 'folder':
|
|
83
|
+
return t('file-card.kind.folder', {}, { defaultValue: 'Folder' });
|
|
84
|
+
case 'other':
|
|
85
|
+
return t('file-card.kind.other', {}, { defaultValue: 'File' });
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Resolve the size's unit word via `t()`, with the number {@link sizeParts}
|
|
90
|
+
* already displayed: one literal key per `SizeUnit` — the same pattern as
|
|
91
|
+
* {@link kindText} — so the i18n gate can verify every key exists in the
|
|
92
|
+
* locale bond, and the `{{n}}` placeholder lets a translation move the number
|
|
93
|
+
* or rename the token (French octets, Russian КБ).
|
|
94
|
+
*
|
|
95
|
+
* @param size - The size's displayed number and unit (`sizeParts(file.size)`).
|
|
96
|
+
* @param t - The `useTranslation()` `t` function.
|
|
97
|
+
* @returns The localized size text.
|
|
98
|
+
*/
|
|
99
|
+
function sizeUnitText(size, t) {
|
|
100
|
+
switch (size.unit) {
|
|
101
|
+
case 'B':
|
|
102
|
+
return t('file-card.size.b', { n: size.n }, { defaultValue: '{{n}} B' });
|
|
103
|
+
case 'KB':
|
|
104
|
+
return t('file-card.size.kb', { n: size.n }, { defaultValue: '{{n}} KB' });
|
|
105
|
+
case 'MB':
|
|
106
|
+
return t('file-card.size.mb', { n: size.n }, { defaultValue: '{{n}} MB' });
|
|
107
|
+
case 'GB':
|
|
108
|
+
return t('file-card.size.gb', { n: size.n }, { defaultValue: '{{n}} GB' });
|
|
109
|
+
case 'TB':
|
|
110
|
+
return t('file-card.size.tb', { n: size.n }, { defaultValue: '{{n}} TB' });
|
|
111
|
+
case 'PB':
|
|
112
|
+
return t('file-card.size.pb', { n: size.n }, { defaultValue: '{{n}} PB' });
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* File representation card — icon (or thumbnail), filename, formatted size,
|
|
117
|
+
* relative modified date, and optional trailing actions slot. Used by
|
|
118
|
+
* cloud-file-manager grids/lists, social-media + email-client attachment
|
|
119
|
+
* previews, and document-collaboration sidebars.
|
|
120
|
+
*
|
|
121
|
+
* Two layouts:
|
|
122
|
+
* - `'grid'` (default) — square tile with the icon/thumbnail stacked above
|
|
123
|
+
* the metadata. Suitable for finder-style grids and attachment galleries.
|
|
124
|
+
* - `'row'` — horizontal line item with the icon on the left, metadata in
|
|
125
|
+
* the middle, and the actions slot on the right. Suitable for list views
|
|
126
|
+
* and chat/email attachment rows.
|
|
127
|
+
*
|
|
128
|
+
* All styling routes through `getClassMap()`. All user-visible text routes
|
|
129
|
+
* through `t()` so the card translates via the companion
|
|
130
|
+
* `@molecule/app-locales-file-card` locale bond.
|
|
131
|
+
*
|
|
132
|
+
* @param props - Component props (see {@link FileCardProps}).
|
|
133
|
+
* @returns The file card component.
|
|
134
|
+
*/
|
|
135
|
+
export const FileCard = defineComponent({
|
|
136
|
+
name: 'FileCard',
|
|
137
|
+
props: {
|
|
138
|
+
file: {
|
|
139
|
+
type: Object,
|
|
140
|
+
required: true,
|
|
141
|
+
},
|
|
142
|
+
selected: {
|
|
143
|
+
type: Boolean,
|
|
144
|
+
default: undefined,
|
|
145
|
+
},
|
|
146
|
+
onClick: {
|
|
147
|
+
type: Function,
|
|
148
|
+
default: undefined,
|
|
149
|
+
},
|
|
150
|
+
onContextMenu: {
|
|
151
|
+
type: Function,
|
|
152
|
+
default: undefined,
|
|
153
|
+
},
|
|
154
|
+
layout: {
|
|
155
|
+
type: String,
|
|
156
|
+
default: 'grid',
|
|
157
|
+
},
|
|
158
|
+
// Node-valued prop: declared with `null` (any runtime type, no
|
|
159
|
+
// validation — a VNode, a string, or nothing to hide the region).
|
|
160
|
+
actions: null,
|
|
161
|
+
now: {
|
|
162
|
+
type: Object,
|
|
163
|
+
default: undefined,
|
|
164
|
+
},
|
|
165
|
+
className: {
|
|
166
|
+
type: String,
|
|
167
|
+
default: undefined,
|
|
168
|
+
},
|
|
169
|
+
dataMolId: {
|
|
170
|
+
type: String,
|
|
171
|
+
default: undefined,
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
setup(props, { slots }) {
|
|
175
|
+
const { t } = useTranslation();
|
|
176
|
+
const cm = getClassMap();
|
|
177
|
+
/**
|
|
178
|
+
* Forward a body activation (a click on the select button, or Enter / Space
|
|
179
|
+
* on it) to the consumer.
|
|
180
|
+
*
|
|
181
|
+
* @param event - DOM mouse event.
|
|
182
|
+
*/
|
|
183
|
+
const handleClick = (event) => {
|
|
184
|
+
props.onClick?.(props.file, event);
|
|
185
|
+
};
|
|
186
|
+
/**
|
|
187
|
+
* Forward right-click to the consumer.
|
|
188
|
+
*
|
|
189
|
+
* @param event - DOM mouse event.
|
|
190
|
+
*/
|
|
191
|
+
const handleContextMenu = (event) => {
|
|
192
|
+
if (props.onContextMenu)
|
|
193
|
+
props.onContextMenu(props.file, event);
|
|
194
|
+
};
|
|
195
|
+
return () => {
|
|
196
|
+
const file = props.file;
|
|
197
|
+
const kindLabel = kindText(file.kind, t);
|
|
198
|
+
const size = file.kind === 'folder' ? undefined : sizeParts(file.size);
|
|
199
|
+
const sizeText = size ? sizeUnitText(size, t) : '';
|
|
200
|
+
const sizeLabel = sizeText
|
|
201
|
+
? t('file-card.aria.size', { size: sizeText }, { defaultValue: 'Size {{size}}' })
|
|
202
|
+
: '';
|
|
203
|
+
const modifiedText = file.modifiedAt ? relativeText(file.modifiedAt, t, props.now) : '';
|
|
204
|
+
const modifiedLabel = modifiedText
|
|
205
|
+
? t('file-card.aria.modified', { when: modifiedText }, { defaultValue: 'Modified {{when}}' })
|
|
206
|
+
: '';
|
|
207
|
+
const ariaLabel = t('file-card.aria.root', { name: file.name, kind: kindLabel }, { defaultValue: '{{name}}, {{kind}}' });
|
|
208
|
+
const rootMolId = props.dataMolId ?? `file-card-${file.id}`;
|
|
209
|
+
// The card's select control: a transparent native button covering the
|
|
210
|
+
// card (Enter / Space activate it natively), above the content and
|
|
211
|
+
// below the actions slot. A sibling of the actions, not their wrapper,
|
|
212
|
+
// so the action buttons stay reachable controls (a button's children
|
|
213
|
+
// are presentational).
|
|
214
|
+
const selectButton = props.onClick
|
|
215
|
+
? h('button', {
|
|
216
|
+
type: 'button',
|
|
217
|
+
'aria-label': ariaLabel,
|
|
218
|
+
'aria-pressed': props.selected ? 'true' : 'false',
|
|
219
|
+
'data-mol-id': 'file-card-select',
|
|
220
|
+
onClick: handleClick,
|
|
221
|
+
// mol-bespoke-button: the whole card is the hit area, not a CTA —
|
|
222
|
+
// an empty, transparent button over the card; the inline
|
|
223
|
+
// background/border/padding are native resets.
|
|
224
|
+
class: cm.cn(cm.position('absolute'), cm.inset0, cm.cursorPointer),
|
|
225
|
+
style: { background: 'transparent', border: 'none', padding: '0' },
|
|
226
|
+
})
|
|
227
|
+
: null;
|
|
228
|
+
// React renders `{sizeText && modifiedText && <span aria-hidden>·</span>}`.
|
|
229
|
+
const separator = sizeText && modifiedText ? h('span', { 'aria-hidden': 'true' }, ['·']) : null;
|
|
230
|
+
const meta = sizeText || modifiedText
|
|
231
|
+
? h('div', {
|
|
232
|
+
class: cm.cn(cm.flex({ align: 'center', gap: 'sm' }), cm.textSize('xs')),
|
|
233
|
+
'data-mol-id': 'file-card-meta',
|
|
234
|
+
}, [
|
|
235
|
+
...(sizeText
|
|
236
|
+
? [
|
|
237
|
+
h('span', { 'aria-label': sizeLabel, 'data-mol-id': 'file-card-size' }, [
|
|
238
|
+
sizeText,
|
|
239
|
+
]),
|
|
240
|
+
]
|
|
241
|
+
: []),
|
|
242
|
+
...(separator ? [separator] : []),
|
|
243
|
+
...(modifiedText
|
|
244
|
+
? [
|
|
245
|
+
h('span', {
|
|
246
|
+
'aria-label': modifiedLabel,
|
|
247
|
+
'data-mol-id': 'file-card-modified',
|
|
248
|
+
}, [modifiedText]),
|
|
249
|
+
]
|
|
250
|
+
: []),
|
|
251
|
+
])
|
|
252
|
+
: null;
|
|
253
|
+
const actionNodes = propOrSlot(props.actions, slots.actions);
|
|
254
|
+
const actions = actionNodes.length
|
|
255
|
+
? h('div', {
|
|
256
|
+
class: props.layout === 'row'
|
|
257
|
+
? cm.cn(cm.shrink0, cm.position('relative'))
|
|
258
|
+
: cm.cn(cm.flex({ align: 'center', justify: 'end', gap: 'sm' }), cm.position('relative')),
|
|
259
|
+
'data-mol-id': 'file-card-actions',
|
|
260
|
+
}, actionNodes)
|
|
261
|
+
: null;
|
|
262
|
+
if (props.layout === 'row') {
|
|
263
|
+
return h('div', {
|
|
264
|
+
role: 'group',
|
|
265
|
+
'aria-label': ariaLabel,
|
|
266
|
+
'data-mol-id': rootMolId,
|
|
267
|
+
'data-selected': props.selected ? 'true' : undefined,
|
|
268
|
+
class: cm.cn(cm.flex({ align: 'center', gap: 'md' }), cm.sp('p', 2), props.onClick ? cm.position('relative') : undefined, props.className),
|
|
269
|
+
onContextmenu: handleContextMenu,
|
|
270
|
+
}, [
|
|
271
|
+
h('div', { class: cm.shrink0, 'data-mol-id': 'file-card-icon' }, [
|
|
272
|
+
file.thumbnail
|
|
273
|
+
? h('img', {
|
|
274
|
+
src: file.thumbnail,
|
|
275
|
+
alt: '',
|
|
276
|
+
style: {
|
|
277
|
+
width: '40px',
|
|
278
|
+
height: '40px',
|
|
279
|
+
objectFit: 'cover',
|
|
280
|
+
borderRadius: '4px',
|
|
281
|
+
},
|
|
282
|
+
})
|
|
283
|
+
: h(FileIcon, { kind: file.kind, size: 28 }),
|
|
284
|
+
]),
|
|
285
|
+
h('div', { class: cm.stack(0), style: { flex: '1', minWidth: '0' } }, [
|
|
286
|
+
h('div', {
|
|
287
|
+
class: cm.cn(cm.textSize('sm'), cm.fontWeight('semibold')),
|
|
288
|
+
'data-mol-id': 'file-card-name',
|
|
289
|
+
style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' },
|
|
290
|
+
}, [file.name]),
|
|
291
|
+
meta,
|
|
292
|
+
]),
|
|
293
|
+
selectButton,
|
|
294
|
+
actions,
|
|
295
|
+
]);
|
|
296
|
+
}
|
|
297
|
+
// Grid layout (default).
|
|
298
|
+
return h('div', {
|
|
299
|
+
role: 'group',
|
|
300
|
+
'aria-label': ariaLabel,
|
|
301
|
+
'data-mol-id': rootMolId,
|
|
302
|
+
'data-selected': props.selected ? 'true' : undefined,
|
|
303
|
+
class: cm.cn(cm.stack(1), cm.sp('p', 3), props.onClick ? cm.position('relative') : undefined, props.className),
|
|
304
|
+
onContextmenu: handleContextMenu,
|
|
305
|
+
}, [
|
|
306
|
+
h('div', {
|
|
307
|
+
class: cm.flex({ align: 'center', justify: 'center' }),
|
|
308
|
+
'data-mol-id': 'file-card-icon',
|
|
309
|
+
style: { aspectRatio: '1 / 1', width: '100%' },
|
|
310
|
+
}, [
|
|
311
|
+
file.thumbnail
|
|
312
|
+
? h('img', {
|
|
313
|
+
src: file.thumbnail,
|
|
314
|
+
alt: '',
|
|
315
|
+
style: {
|
|
316
|
+
width: '100%',
|
|
317
|
+
height: '100%',
|
|
318
|
+
objectFit: 'cover',
|
|
319
|
+
borderRadius: '4px',
|
|
320
|
+
},
|
|
321
|
+
})
|
|
322
|
+
: h(FileIcon, { kind: file.kind, size: 48 }),
|
|
323
|
+
]),
|
|
324
|
+
h('div', {
|
|
325
|
+
class: cm.cn(cm.textSize('sm'), cm.fontWeight('semibold')),
|
|
326
|
+
'data-mol-id': 'file-card-name',
|
|
327
|
+
style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' },
|
|
328
|
+
}, [file.name]),
|
|
329
|
+
meta,
|
|
330
|
+
selectButton,
|
|
331
|
+
actions,
|
|
332
|
+
]);
|
|
333
|
+
};
|
|
334
|
+
},
|
|
335
|
+
});
|
|
336
|
+
//# sourceMappingURL=FileCard.js.map
|