@molecule/app-file-card-svelte 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/dist/index.js ADDED
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Svelte 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
+ * ```svelte
19
+ * <script lang="ts">
20
+ * import { FileCard, type FileSummary } from '@molecule/app-file-card-svelte'
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
+ * </script>
30
+ *
31
+ * <FileCard {file} layout="grid" onClick={(f) => openFile(f.id)}>
32
+ * {#snippet actions()}
33
+ * <KebabMenu fileId={file.id} />
34
+ * {/snippet}
35
+ * </FileCard>
36
+ * ```
37
+ *
38
+ * @remarks
39
+ * All styling routes through `getClassMap()` from `@molecule/app-ui` —
40
+ * swap the ClassMap bond to restyle without touching this package.
41
+ *
42
+ * All user-visible text routes through `t()` (via `@molecule/app-svelte`'s
43
+ * `useTranslation`) and translates via the companion
44
+ * `@molecule/app-locales-file-card` locale bond. English fallbacks are
45
+ * inlined so the card works without the locale bond present.
46
+ *
47
+ * @module
48
+ */
49
+ export * from './components.js';
50
+ export * from './format.js';
51
+ export * from './types.js';
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Inline styles shared by this package's components: a Svelte action that
3
+ * applies a React-shaped style object the way react-dom does, so both
4
+ * frameworks leave the same declarations on the element.
5
+ *
6
+ * @module
7
+ */
8
+ /**
9
+ * A React-shaped inline style object (camelCase properties, numbers allowed).
10
+ */
11
+ export type CSSStyle = Record<string, string | number | undefined | null | false>;
12
+ /**
13
+ * Svelte action applying a React-shaped style object to an element the way
14
+ * React applies it: every entry is assigned through the CSSOM property setter
15
+ * (in object order, numbers gaining `px` unless unitless, falsy entries
16
+ * cleared), and keys removed by a re-render are cleared too. React never
17
+ * writes a literal `style` string, so shorthand/longhand pairs
18
+ * (`borderColor` + `borderTopColor`) merge in the CSSOM exactly as React's
19
+ * serialized attribute does.
20
+ *
21
+ * @param node - The element to style.
22
+ * @param style - The React-shaped style object (may be undefined).
23
+ * @returns The action with an update that re-applies on prop changes.
24
+ */
25
+ export declare function reactStyle(node: HTMLElement, style: CSSStyle | undefined): {
26
+ update: (next: CSSStyle | undefined) => void;
27
+ };
28
+ //# sourceMappingURL=style.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"style.d.ts","sourceRoot":"","sources":["../src/style.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,KAAK,CAAC,CAAA;AA2EjF;;;;;;;;;;;;GAYG;AACH,wBAAgB,UAAU,CACxB,IAAI,EAAE,WAAW,EACjB,KAAK,EAAE,QAAQ,GAAG,SAAS,GAC1B;IAAE,MAAM,EAAE,CAAC,IAAI,EAAE,QAAQ,GAAG,SAAS,KAAK,IAAI,CAAA;CAAE,CAqBlD"}
package/dist/style.js ADDED
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Inline styles shared by this package's components: a Svelte action that
3
+ * applies a React-shaped style object the way react-dom does, so both
4
+ * frameworks leave the same declarations on the element.
5
+ *
6
+ * @module
7
+ */
8
+ /**
9
+ * Properties whose numeric values take no unit (React's `isUnitlessNumber`).
10
+ */
11
+ const UNITLESS = new Set([
12
+ 'animationIterationCount',
13
+ 'aspectRatio',
14
+ 'borderImageOutset',
15
+ 'borderImageSlice',
16
+ 'borderImageWidth',
17
+ 'boxFlex',
18
+ 'boxFlexGroup',
19
+ 'boxOrdinalGroup',
20
+ 'columnCount',
21
+ 'columns',
22
+ 'flex',
23
+ 'flexGrow',
24
+ 'flexPositive',
25
+ 'flexShrink',
26
+ 'flexNegative',
27
+ 'flexOrder',
28
+ 'gridArea',
29
+ 'gridRow',
30
+ 'gridRowEnd',
31
+ 'gridRowStart',
32
+ 'gridColumn',
33
+ 'gridColumnEnd',
34
+ 'gridColumnStart',
35
+ 'fontWeight',
36
+ 'lineClamp',
37
+ 'lineHeight',
38
+ 'opacity',
39
+ 'order',
40
+ 'orphans',
41
+ 'scale',
42
+ 'tabSize',
43
+ 'widows',
44
+ 'zIndex',
45
+ 'zoom',
46
+ 'fillOpacity',
47
+ 'floodOpacity',
48
+ 'stopOpacity',
49
+ 'strokeDasharray',
50
+ 'strokeDashoffset',
51
+ 'strokeOpacity',
52
+ 'strokeWidth',
53
+ ]);
54
+ /**
55
+ * Turns a camelCase CSS property name into its kebab-case DOM spelling.
56
+ *
57
+ * @param name - The camelCase property (`marginTop`, `zIndex`).
58
+ * @returns The kebab-case property (`margin-top`, `z-index`).
59
+ */
60
+ const kebab = (name) => name.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`);
61
+ /**
62
+ * React's `dangerousStyleValue`: null/undefined/boolean/empty values clear the
63
+ * property, numbers other than 0 take `px` unless the property is unitless,
64
+ * and strings are trimmed.
65
+ *
66
+ * @param name - The camelCase property name.
67
+ * @param value - The style value.
68
+ * @returns The string React would assign, or `''` to clear.
69
+ */
70
+ const reactStyleValue = (name, value) => {
71
+ if (value === undefined || value === null || value === false || value === '')
72
+ return '';
73
+ if (typeof value === 'number' && value !== 0 && !UNITLESS.has(name))
74
+ return `${value}px`;
75
+ return String(value).trim();
76
+ };
77
+ /**
78
+ * Svelte action applying a React-shaped style object to an element the way
79
+ * React applies it: every entry is assigned through the CSSOM property setter
80
+ * (in object order, numbers gaining `px` unless unitless, falsy entries
81
+ * cleared), and keys removed by a re-render are cleared too. React never
82
+ * writes a literal `style` string, so shorthand/longhand pairs
83
+ * (`borderColor` + `borderTopColor`) merge in the CSSOM exactly as React's
84
+ * serialized attribute does.
85
+ *
86
+ * @param node - The element to style.
87
+ * @param style - The React-shaped style object (may be undefined).
88
+ * @returns The action with an update that re-applies on prop changes.
89
+ */
90
+ export function reactStyle(node, style) {
91
+ const applied = new Set();
92
+ const apply = (next) => {
93
+ const removed = new Set(applied);
94
+ if (next) {
95
+ for (const key of Object.keys(next)) {
96
+ removed.delete(key);
97
+ const text = reactStyleValue(key, next[key]);
98
+ if (key.startsWith('--'))
99
+ node.style.setProperty(key, text);
100
+ else
101
+ node.style.setProperty(kebab(key), text);
102
+ if (text)
103
+ applied.add(key);
104
+ else
105
+ applied.delete(key);
106
+ }
107
+ }
108
+ for (const key of removed) {
109
+ node.style.setProperty(kebab(key), '');
110
+ applied.delete(key);
111
+ }
112
+ };
113
+ apply(style);
114
+ return { update: apply };
115
+ }
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Types for the Svelte file card primitives — the same shapes
3
+ * `@molecule/app-file-card-react` exports, with Svelte 5 snippets for the
4
+ * actions slot.
5
+ *
6
+ * @module
7
+ */
8
+ import type { Snippet } from 'svelte';
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
+ /** Optional trailing action slot (button row, kebab menu). Clicks here do not fire `onClick`. */
51
+ actions?: Snippet;
52
+ /** Reference "now" for relative-time formatting. Useful for testing/snapshots. */
53
+ now?: Date;
54
+ /** Extra classes merged onto the root element. */
55
+ className?: string;
56
+ /** Override the root `data-mol-id` (defaults to `file-card-${file.id}`). */
57
+ dataMolId?: string;
58
+ }
59
+ /** Props for `<FileIcon>`. */
60
+ export interface FileIconProps {
61
+ /** File kind — picks the SVG glyph. */
62
+ kind: FileKind;
63
+ /** Pixel size of the rendered SVG (default 24). */
64
+ size?: number;
65
+ /** Optional aria-label. When omitted the icon is `aria-hidden`. */
66
+ ariaLabel?: string;
67
+ }
68
+ //# 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,OAAO,EAAE,MAAM,QAAQ,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,iGAAiG;IACjG,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,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,8 @@
1
+ /**
2
+ * Types for the Svelte file card primitives — the same shapes
3
+ * `@molecule/app-file-card-react` exports, with Svelte 5 snippets for the
4
+ * actions slot.
5
+ *
6
+ * @module
7
+ */
8
+ export {};
package/package.json CHANGED
@@ -1,6 +1,75 @@
1
1
  {
2
2
  "name": "@molecule/app-file-card-svelte",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.1.0",
4
+ "description": "Svelte file card primitives — icon, name, size, modified date, actions; grid + row layouts",
5
+ "homepage": "https://www.molecule.dev/packages/app-file-card-svelte",
6
+ "type": "module",
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "svelte": "./dist/index.js",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "./package.json": "./package.json"
16
+ },
17
+ "svelte": "./dist/index.js",
18
+ "files": [
19
+ "dist",
20
+ "!dist/**/__tests__",
21
+ "!dist/**/*.test.*",
22
+ "!dist/**/*.spec.*",
23
+ "README.md"
24
+ ],
25
+ "scripts": {
26
+ "build": "svelte-check --tsconfig ./tsconfig.json --fail-on-warnings && svelte-package --input src --output dist --tsconfig ./tsconfig.json",
27
+ "dev": "svelte-package --input src --output dist --tsconfig ./tsconfig.json --watch",
28
+ "test": "vitest run",
29
+ "test:watch": "vitest"
30
+ },
31
+ "keywords": [
32
+ "molecule",
33
+ "file-card",
34
+ "attachment",
35
+ "file-tile",
36
+ "svelte"
37
+ ],
38
+ "author": "Molecule Dev, Inc. (https://molecule.dev)",
39
+ "license": "Apache-2.0",
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "https://github.com/molecule-dev/molecule.git",
43
+ "directory": "packages/app/features/file-card-svelte"
44
+ },
45
+ "engines": {
46
+ "node": ">=20"
47
+ },
48
+ "bugs": "https://github.com/molecule-dev/molecule/issues",
49
+ "publishConfig": {
50
+ "access": "public"
51
+ },
52
+ "peerDependencies": {
53
+ "@molecule/app-svelte": "^3.5.0",
54
+ "@molecule/app-ui": "^1.0.1",
55
+ "@molecule/app-ui-svelte": "^1.1.0",
56
+ "svelte": "^5.0.0"
57
+ },
58
+ "devDependencies": {
59
+ "@molecule/app-framework-conformance": "0.0.0",
60
+ "@molecule/app-i18n": "1.2.2",
61
+ "@molecule/app-icons": "1.0.4",
62
+ "@molecule/app-svelte": "3.9.0",
63
+ "@molecule/app-ui": "1.5.0",
64
+ "@molecule/app-ui-svelte": "1.2.1",
65
+ "@sveltejs/package": "3.0.2",
66
+ "@sveltejs/vite-plugin-svelte": "7.1.2",
67
+ "@types/node": "26.6.5",
68
+ "jsdom": "30.1.3",
69
+ "svelte": "5.57.2",
70
+ "svelte-check": "4.7.7",
71
+ "typescript": "6.0.3",
72
+ "vite": "8.3.5",
73
+ "vitest": "4.1.12"
74
+ }
75
+ }