@molecule/app-file-card-vue 0.0.0-stage → 1.1.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.
- package/LICENSE +202 -0
- package/README.md +404 -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/dist/format.d.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Format helpers for the file card. Pure functions — UI-agnostic so they can
|
|
3
|
+
* be unit-tested directly.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
/** The unit token a formatted byte count ends in (`B` plus the binary steps). */
|
|
8
|
+
export type SizeUnit = 'B' | 'KB' | 'MB' | 'GB' | 'TB' | 'PB';
|
|
9
|
+
/** A formatted size's displayed number and its unit token, split for `t()`. */
|
|
10
|
+
export interface SizeParts {
|
|
11
|
+
/** The displayed number, rounded the way {@link bytes} displays it. */
|
|
12
|
+
n: string;
|
|
13
|
+
/** The unit token the number counts. */
|
|
14
|
+
unit: SizeUnit;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Split a non-negative byte count into its displayed number and unit token
|
|
18
|
+
* (e.g. `420` + `B`, `1.4` + `KB`, `471` + `MB`) — the two halves
|
|
19
|
+
* {@link bytes} joins, exposed so the card can translate the unit word via
|
|
20
|
+
* `t()` (one literal key per {@link SizeUnit}, as the kind labels do).
|
|
21
|
+
*
|
|
22
|
+
* Uses a 1024 base (binary) and 1 fractional digit for KB+. Returns the
|
|
23
|
+
* `0 B` parts for non-finite or negative inputs so callers do not need to
|
|
24
|
+
* pre-validate.
|
|
25
|
+
*
|
|
26
|
+
* @param value - Byte count (>= 0).
|
|
27
|
+
* @returns The displayed number and unit token.
|
|
28
|
+
*/
|
|
29
|
+
export declare function sizeParts(value: number): SizeParts;
|
|
30
|
+
/**
|
|
31
|
+
* Format a non-negative byte count as a short human-readable string
|
|
32
|
+
* (e.g. `420 B`, `1.4 KB`, `2.3 MB`, `4.7 GB`, `8.1 TB`).
|
|
33
|
+
*
|
|
34
|
+
* The unlocalized join of {@link sizeParts}'s two halves, for callers that
|
|
35
|
+
* want the raw SI shorthand. The card itself renders the unit through `t()`
|
|
36
|
+
* (`file-card.size.<unit>` keys in the locale bond) so a locale switch
|
|
37
|
+
* translates it; the unit token is universal SI shorthand — a language that
|
|
38
|
+
* names bytes differently (French octets, Russian КБ) changes only the token,
|
|
39
|
+
* never the magnitude.
|
|
40
|
+
*
|
|
41
|
+
* @param value - Byte count (>= 0).
|
|
42
|
+
* @returns Formatted size string.
|
|
43
|
+
*/
|
|
44
|
+
export declare function bytes(value: number): string;
|
|
45
|
+
/**
|
|
46
|
+
* A relative-time bucket used to pick a translation key. Higher granularity
|
|
47
|
+
* buckets first; falls through to absolute date when older than ~1 year.
|
|
48
|
+
*/
|
|
49
|
+
export type RelativeBucket = {
|
|
50
|
+
kind: 'just-now';
|
|
51
|
+
} | {
|
|
52
|
+
kind: 'minutes';
|
|
53
|
+
n: number;
|
|
54
|
+
} | {
|
|
55
|
+
kind: 'hours';
|
|
56
|
+
n: number;
|
|
57
|
+
} | {
|
|
58
|
+
kind: 'days';
|
|
59
|
+
n: number;
|
|
60
|
+
} | {
|
|
61
|
+
kind: 'weeks';
|
|
62
|
+
n: number;
|
|
63
|
+
} | {
|
|
64
|
+
kind: 'months';
|
|
65
|
+
n: number;
|
|
66
|
+
} | {
|
|
67
|
+
kind: 'absolute';
|
|
68
|
+
iso: string;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Bucket a `Date` (or ISO string / ms timestamp) against `now` into a
|
|
72
|
+
* relative-time bucket. The bucket is purely structural — translation keys
|
|
73
|
+
* and pluralization are applied by the consumer.
|
|
74
|
+
*
|
|
75
|
+
* @param at - Modified-at timestamp (ISO string, ms epoch, or `Date`).
|
|
76
|
+
* @param now - Reference "now" (defaults to `new Date()`). Injected for tests.
|
|
77
|
+
* @returns A `RelativeBucket` describing the offset from `now`.
|
|
78
|
+
*/
|
|
79
|
+
export declare function relativeBucket(at: string | number | Date, now?: Date): RelativeBucket;
|
|
80
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,iFAAiF;AACjF,MAAM,MAAM,QAAQ,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAA;AAE7D,+EAA+E;AAC/E,MAAM,WAAW,SAAS;IACxB,uEAAuE;IACvE,CAAC,EAAE,MAAM,CAAA;IACT,wCAAwC;IACxC,IAAI,EAAE,QAAQ,CAAA;CACf;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAalD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAG3C;AAED;;;GAGG;AACH,MAAM,MAAM,cAAc,GACtB;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,GACpB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,GAC9B;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,GAC5B;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,GAC3B;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,GAC5B;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,GAC7B;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAA;AAErC;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,EAAE,GAAG,GAAE,IAAiB,GAAG,cAAc,CAiBjG"}
|
package/dist/format.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Format helpers for the file card. Pure functions — UI-agnostic so they can
|
|
3
|
+
* be unit-tested directly.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Split a non-negative byte count into its displayed number and unit token
|
|
9
|
+
* (e.g. `420` + `B`, `1.4` + `KB`, `471` + `MB`) — the two halves
|
|
10
|
+
* {@link bytes} joins, exposed so the card can translate the unit word via
|
|
11
|
+
* `t()` (one literal key per {@link SizeUnit}, as the kind labels do).
|
|
12
|
+
*
|
|
13
|
+
* Uses a 1024 base (binary) and 1 fractional digit for KB+. Returns the
|
|
14
|
+
* `0 B` parts for non-finite or negative inputs so callers do not need to
|
|
15
|
+
* pre-validate.
|
|
16
|
+
*
|
|
17
|
+
* @param value - Byte count (>= 0).
|
|
18
|
+
* @returns The displayed number and unit token.
|
|
19
|
+
*/
|
|
20
|
+
export function sizeParts(value) {
|
|
21
|
+
if (!Number.isFinite(value) || value < 0)
|
|
22
|
+
return { n: '0', unit: 'B' };
|
|
23
|
+
if (value < 1024)
|
|
24
|
+
return { n: String(Math.round(value)), unit: 'B' };
|
|
25
|
+
const units = ['KB', 'MB', 'GB', 'TB', 'PB'];
|
|
26
|
+
let n = value / 1024;
|
|
27
|
+
let unitIndex = 0;
|
|
28
|
+
while (n >= 1024 && unitIndex < units.length - 1) {
|
|
29
|
+
n /= 1024;
|
|
30
|
+
unitIndex += 1;
|
|
31
|
+
}
|
|
32
|
+
// 1 decimal place when < 100, else round
|
|
33
|
+
const display = n >= 100 ? Math.round(n).toString() : n.toFixed(1).replace(/\.0$/, '');
|
|
34
|
+
return { n: display, unit: units[unitIndex] };
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Format a non-negative byte count as a short human-readable string
|
|
38
|
+
* (e.g. `420 B`, `1.4 KB`, `2.3 MB`, `4.7 GB`, `8.1 TB`).
|
|
39
|
+
*
|
|
40
|
+
* The unlocalized join of {@link sizeParts}'s two halves, for callers that
|
|
41
|
+
* want the raw SI shorthand. The card itself renders the unit through `t()`
|
|
42
|
+
* (`file-card.size.<unit>` keys in the locale bond) so a locale switch
|
|
43
|
+
* translates it; the unit token is universal SI shorthand — a language that
|
|
44
|
+
* names bytes differently (French octets, Russian КБ) changes only the token,
|
|
45
|
+
* never the magnitude.
|
|
46
|
+
*
|
|
47
|
+
* @param value - Byte count (>= 0).
|
|
48
|
+
* @returns Formatted size string.
|
|
49
|
+
*/
|
|
50
|
+
export function bytes(value) {
|
|
51
|
+
const { n, unit } = sizeParts(value);
|
|
52
|
+
return `${n} ${unit}`;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Bucket a `Date` (or ISO string / ms timestamp) against `now` into a
|
|
56
|
+
* relative-time bucket. The bucket is purely structural — translation keys
|
|
57
|
+
* and pluralization are applied by the consumer.
|
|
58
|
+
*
|
|
59
|
+
* @param at - Modified-at timestamp (ISO string, ms epoch, or `Date`).
|
|
60
|
+
* @param now - Reference "now" (defaults to `new Date()`). Injected for tests.
|
|
61
|
+
* @returns A `RelativeBucket` describing the offset from `now`.
|
|
62
|
+
*/
|
|
63
|
+
export function relativeBucket(at, now = new Date()) {
|
|
64
|
+
const then = at instanceof Date ? at : new Date(at);
|
|
65
|
+
const ms = now.getTime() - then.getTime();
|
|
66
|
+
if (!Number.isFinite(ms))
|
|
67
|
+
return { kind: 'absolute', iso: String(at) };
|
|
68
|
+
if (ms < 60_000)
|
|
69
|
+
return { kind: 'just-now' };
|
|
70
|
+
const minute = 60_000;
|
|
71
|
+
const hour = 60 * minute;
|
|
72
|
+
const day = 24 * hour;
|
|
73
|
+
const week = 7 * day;
|
|
74
|
+
const month = 30 * day;
|
|
75
|
+
const year = 365 * day;
|
|
76
|
+
if (ms < hour)
|
|
77
|
+
return { kind: 'minutes', n: Math.floor(ms / minute) };
|
|
78
|
+
if (ms < day)
|
|
79
|
+
return { kind: 'hours', n: Math.floor(ms / hour) };
|
|
80
|
+
if (ms < week)
|
|
81
|
+
return { kind: 'days', n: Math.floor(ms / day) };
|
|
82
|
+
if (ms < month)
|
|
83
|
+
return { kind: 'weeks', n: Math.floor(ms / week) };
|
|
84
|
+
if (ms < year)
|
|
85
|
+
return { kind: 'months', n: Math.floor(ms / month) };
|
|
86
|
+
return { kind: 'absolute', iso: then.toISOString().slice(0, 10) };
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.js","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAaH;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,SAAS,CAAC,KAAa;IACrC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC;QAAE,OAAO,EAAE,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,CAAA;IACtE,IAAI,KAAK,GAAG,IAAI;QAAE,OAAO,EAAE,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,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,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAA;AACnE,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vue file card primitives.
|
|
3
|
+
*
|
|
4
|
+
* Exports:
|
|
5
|
+
* - `<FileCard>` — file representation card (icon/thumbnail + name + size + modified date + optional actions).
|
|
6
|
+
* Two layouts: `'grid'` (square tile, default) and `'row'` (horizontal list line).
|
|
7
|
+
* - `<FileIcon>` — stroke-currentColor SVG glyph keyed by `FileKind`.
|
|
8
|
+
* - `bytes(value)` — pure helper that formats a byte count as `420 B` / `1.4 KB` / `2.3 MB` / etc.
|
|
9
|
+
* - `sizeParts(value)` — the same split as `{ n, unit }`, for rendering the unit through `t()`.
|
|
10
|
+
* - `relativeBucket(at, now?)` — pure helper that buckets a timestamp into `just-now` / `minutes` /
|
|
11
|
+
* `hours` / `days` / `weeks` / `months` / `absolute`.
|
|
12
|
+
* - `FileSummary` / `FileKind` / `SizeParts` types — stable shape for the consumer's domain model.
|
|
13
|
+
*
|
|
14
|
+
* Used by cloud-file-manager (grid + list views), social-media + email-client
|
|
15
|
+
* (attachment previews), and document-collaboration (sidebars).
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { createApp, defineComponent, h } from 'vue'
|
|
20
|
+
* import { FileCard, type FileSummary } from '@molecule/app-file-card-vue'
|
|
21
|
+
*
|
|
22
|
+
* const file: FileSummary = {
|
|
23
|
+
* id: 'f-1',
|
|
24
|
+
* name: 'Q3-report.pdf',
|
|
25
|
+
* size: 482_137,
|
|
26
|
+
* kind: 'document',
|
|
27
|
+
* modifiedAt: '2026-04-30T18:23:00Z',
|
|
28
|
+
* }
|
|
29
|
+
*
|
|
30
|
+
* const Card = defineComponent({
|
|
31
|
+
* setup() {
|
|
32
|
+
* return () =>
|
|
33
|
+
* h(FileCard, {
|
|
34
|
+
* file,
|
|
35
|
+
* layout: 'grid',
|
|
36
|
+
* onClick: (f) => openFile(f.id),
|
|
37
|
+
* actions: h(KebabMenu, { fileId: file.id }),
|
|
38
|
+
* })
|
|
39
|
+
* },
|
|
40
|
+
* })
|
|
41
|
+
*
|
|
42
|
+
* createApp(Card).mount('#app')
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @remarks
|
|
46
|
+
* All styling routes through `getClassMap()` from `@molecule/app-ui` —
|
|
47
|
+
* swap the ClassMap bond to restyle without touching this package.
|
|
48
|
+
*
|
|
49
|
+
* All user-visible text routes through `t()` (via `@molecule/app-vue`'s
|
|
50
|
+
* `useTranslation`) and translates via the companion
|
|
51
|
+
* `@molecule/app-locales-file-card` locale bond. English fallbacks are
|
|
52
|
+
* inlined so the card works without the locale bond present.
|
|
53
|
+
*
|
|
54
|
+
* @module
|
|
55
|
+
*/
|
|
56
|
+
export * from './FileCard.js';
|
|
57
|
+
export * from './FileIcon.js';
|
|
58
|
+
export * from './format.js';
|
|
59
|
+
export * from './types.js';
|
|
60
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AAEH,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vue file card primitives.
|
|
3
|
+
*
|
|
4
|
+
* Exports:
|
|
5
|
+
* - `<FileCard>` — file representation card (icon/thumbnail + name + size + modified date + optional actions).
|
|
6
|
+
* Two layouts: `'grid'` (square tile, default) and `'row'` (horizontal list line).
|
|
7
|
+
* - `<FileIcon>` — stroke-currentColor SVG glyph keyed by `FileKind`.
|
|
8
|
+
* - `bytes(value)` — pure helper that formats a byte count as `420 B` / `1.4 KB` / `2.3 MB` / etc.
|
|
9
|
+
* - `sizeParts(value)` — the same split as `{ n, unit }`, for rendering the unit through `t()`.
|
|
10
|
+
* - `relativeBucket(at, now?)` — pure helper that buckets a timestamp into `just-now` / `minutes` /
|
|
11
|
+
* `hours` / `days` / `weeks` / `months` / `absolute`.
|
|
12
|
+
* - `FileSummary` / `FileKind` / `SizeParts` types — stable shape for the consumer's domain model.
|
|
13
|
+
*
|
|
14
|
+
* Used by cloud-file-manager (grid + list views), social-media + email-client
|
|
15
|
+
* (attachment previews), and document-collaboration (sidebars).
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { createApp, defineComponent, h } from 'vue'
|
|
20
|
+
* import { FileCard, type FileSummary } from '@molecule/app-file-card-vue'
|
|
21
|
+
*
|
|
22
|
+
* const file: FileSummary = {
|
|
23
|
+
* id: 'f-1',
|
|
24
|
+
* name: 'Q3-report.pdf',
|
|
25
|
+
* size: 482_137,
|
|
26
|
+
* kind: 'document',
|
|
27
|
+
* modifiedAt: '2026-04-30T18:23:00Z',
|
|
28
|
+
* }
|
|
29
|
+
*
|
|
30
|
+
* const Card = defineComponent({
|
|
31
|
+
* setup() {
|
|
32
|
+
* return () =>
|
|
33
|
+
* h(FileCard, {
|
|
34
|
+
* file,
|
|
35
|
+
* layout: 'grid',
|
|
36
|
+
* onClick: (f) => openFile(f.id),
|
|
37
|
+
* actions: h(KebabMenu, { fileId: file.id }),
|
|
38
|
+
* })
|
|
39
|
+
* },
|
|
40
|
+
* })
|
|
41
|
+
*
|
|
42
|
+
* createApp(Card).mount('#app')
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @remarks
|
|
46
|
+
* All styling routes through `getClassMap()` from `@molecule/app-ui` —
|
|
47
|
+
* swap the ClassMap bond to restyle without touching this package.
|
|
48
|
+
*
|
|
49
|
+
* All user-visible text routes through `t()` (via `@molecule/app-vue`'s
|
|
50
|
+
* `useTranslation`) and translates via the companion
|
|
51
|
+
* `@molecule/app-locales-file-card` locale bond. English fallbacks are
|
|
52
|
+
* inlined so the card works without the locale bond present.
|
|
53
|
+
*
|
|
54
|
+
* @module
|
|
55
|
+
*/
|
|
56
|
+
export * from './FileCard.js';
|
|
57
|
+
export * from './FileIcon.js';
|
|
58
|
+
export * from './format.js';
|
|
59
|
+
export * from './types.js';
|
|
60
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AAEH,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for the Vue file card primitives — the same shapes
|
|
3
|
+
* `@molecule/app-file-card-react` exports, with Vue's node type for the
|
|
4
|
+
* actions slot.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import type { VNodeChild } from 'vue';
|
|
9
|
+
/**
|
|
10
|
+
* Supported file kinds. Drives icon selection and the "<kind>" portion of
|
|
11
|
+
* the aria label translation key (e.g. `file-card.kind.image`).
|
|
12
|
+
*/
|
|
13
|
+
export type FileKind = 'image' | 'video' | 'audio' | 'document' | 'archive' | 'code' | 'folder' | 'other';
|
|
14
|
+
/**
|
|
15
|
+
* Minimal description of a file shown in a `<FileCard>`. Apps map their own
|
|
16
|
+
* domain types onto this shape — there is no required mime field; pass
|
|
17
|
+
* `kind` instead so the icon matches even when only a filename is known.
|
|
18
|
+
*/
|
|
19
|
+
export interface FileSummary {
|
|
20
|
+
/** Stable identifier for the file (parent key + `data-mol-id` suffix). */
|
|
21
|
+
id: string;
|
|
22
|
+
/** Display name (filename including extension). */
|
|
23
|
+
name: string;
|
|
24
|
+
/** Size in bytes. Pass `0` for folders or unknown. */
|
|
25
|
+
size: number;
|
|
26
|
+
/** File kind — drives the icon and the "kind" aria token. */
|
|
27
|
+
kind: FileKind;
|
|
28
|
+
/** Last-modified timestamp (ISO string, ms epoch, or `Date`). Optional. */
|
|
29
|
+
modifiedAt?: string | number | Date;
|
|
30
|
+
/** Optional thumbnail URL. When set, replaces the icon in `'grid'` layout. */
|
|
31
|
+
thumbnail?: string;
|
|
32
|
+
}
|
|
33
|
+
/** Props for `<FileCard>`. */
|
|
34
|
+
export interface FileCardProps {
|
|
35
|
+
/** The file to render. */
|
|
36
|
+
file: FileSummary;
|
|
37
|
+
/** Selected highlight state. */
|
|
38
|
+
selected?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Handler fired when the card body is activated: a click anywhere on it, or
|
|
41
|
+
* Enter / Space on its select button (a transparent button covering the card,
|
|
42
|
+
* with `aria-pressed` for `selected`). Not fired for the actions slot, which
|
|
43
|
+
* sits above that button.
|
|
44
|
+
*/
|
|
45
|
+
onClick?: (file: FileSummary, event: MouseEvent) => void;
|
|
46
|
+
/** Context-menu (right-click) handler. */
|
|
47
|
+
onContextMenu?: (file: FileSummary, event: MouseEvent) => void;
|
|
48
|
+
/** Layout — `'grid'` (default) is a square tile, `'row'` is a horizontal list line. */
|
|
49
|
+
layout?: 'grid' | 'row';
|
|
50
|
+
/**
|
|
51
|
+
* Optional trailing action slot (button row, kebab menu). Clicks here do not
|
|
52
|
+
* fire `onClick`. Passed as a prop or as the same-named slot — both work.
|
|
53
|
+
*/
|
|
54
|
+
actions?: VNodeChild;
|
|
55
|
+
/** Reference "now" for relative-time formatting. Useful for testing/snapshots. */
|
|
56
|
+
now?: Date;
|
|
57
|
+
/** Extra classes merged onto the root element. */
|
|
58
|
+
className?: string;
|
|
59
|
+
/** Override the root `data-mol-id` (defaults to `file-card-${file.id}`). */
|
|
60
|
+
dataMolId?: string;
|
|
61
|
+
}
|
|
62
|
+
/** Props for `<FileIcon>`. */
|
|
63
|
+
export interface FileIconProps {
|
|
64
|
+
/** File kind — picks the SVG glyph. */
|
|
65
|
+
kind: FileKind;
|
|
66
|
+
/** Pixel size of the rendered SVG (default 24). */
|
|
67
|
+
size?: number;
|
|
68
|
+
/** Optional aria-label. When omitted the icon is `aria-hidden`. */
|
|
69
|
+
ariaLabel?: string;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AAErC;;;GAGG;AACH,MAAM,MAAM,QAAQ,GAClB,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,UAAU,GAAG,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAA;AAEpF;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC1B,0EAA0E;IAC1E,EAAE,EAAE,MAAM,CAAA;IACV,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAA;IACZ,sDAAsD;IACtD,IAAI,EAAE,MAAM,CAAA;IACZ,6DAA6D;IAC7D,IAAI,EAAE,QAAQ,CAAA;IACd,2EAA2E;IAC3E,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;IACnC,8EAA8E;IAC9E,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,8BAA8B;AAC9B,MAAM,WAAW,aAAa;IAC5B,0BAA0B;IAC1B,IAAI,EAAE,WAAW,CAAA;IACjB,gCAAgC;IAChC,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,UAAU,KAAK,IAAI,CAAA;IACxD,0CAA0C;IAC1C,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,UAAU,KAAK,IAAI,CAAA;IAC9D,uFAAuF;IACvF,MAAM,CAAC,EAAE,MAAM,GAAG,KAAK,CAAA;IACvB;;;OAGG;IACH,OAAO,CAAC,EAAE,UAAU,CAAA;IACpB,kFAAkF;IAClF,GAAG,CAAC,EAAE,IAAI,CAAA;IACV,kDAAkD;IAClD,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,4EAA4E;IAC5E,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,8BAA8B;AAC9B,MAAM,WAAW,aAAa;IAC5B,uCAAuC;IACvC,IAAI,EAAE,QAAQ,CAAA;IACd,mDAAmD;IACnD,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,mEAAmE;IACnE,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,67 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/app-file-card-vue",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Vue file card primitives — icon, name, size, modified date, actions; grid + row layouts",
|
|
5
|
+
"homepage": "https://www.molecule.dev/packages/app-file-card-vue",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc",
|
|
21
|
+
"dev": "vue-tsc --watch",
|
|
22
|
+
"test": "vitest run",
|
|
23
|
+
"test:watch": "vitest"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"molecule",
|
|
27
|
+
"file-card",
|
|
28
|
+
"attachment",
|
|
29
|
+
"file-tile",
|
|
30
|
+
"vue"
|
|
31
|
+
],
|
|
32
|
+
"author": "Molecule Dev, Inc. (https://molecule.dev)",
|
|
33
|
+
"license": "Apache-2.0",
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "https://github.com/molecule-dev/molecule.git",
|
|
37
|
+
"directory": "packages/app/features/file-card-vue"
|
|
38
|
+
},
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=20"
|
|
41
|
+
},
|
|
42
|
+
"bugs": "https://github.com/molecule-dev/molecule/issues",
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"@molecule/app-ui": "^1.0.1",
|
|
48
|
+
"@molecule/app-ui-vue": "^1.1.0",
|
|
49
|
+
"@molecule/app-vue": "^3.5.0",
|
|
50
|
+
"vue": "^3.4.0"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@molecule/app-framework-conformance": "0.0.0",
|
|
54
|
+
"@molecule/app-i18n": "1.2.2",
|
|
55
|
+
"@molecule/app-icons": "1.0.4",
|
|
56
|
+
"@molecule/app-ui": "1.5.0",
|
|
57
|
+
"@molecule/app-ui-vue": "1.2.1",
|
|
58
|
+
"@molecule/app-vue": "3.9.0",
|
|
59
|
+
"@types/node": "26.6.5",
|
|
60
|
+
"jsdom": "30.1.3",
|
|
61
|
+
"typescript": "6.0.3",
|
|
62
|
+
"vite": "8.3.5",
|
|
63
|
+
"vitest": "4.1.12",
|
|
64
|
+
"vue": "3.5.44",
|
|
65
|
+
"vue-tsc": "3.3.13"
|
|
66
|
+
}
|
|
67
|
+
}
|