@alizarin/filelist 0.2.1-alpha.83
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/filelist.js +146 -0
- package/dist/main.d.ts +113 -0
- package/package.json +31 -0
package/dist/filelist.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { registerExtensionHandler, utils, viewModels, wasmReady } from "alizarin";
|
|
2
|
+
var FileListItem = class {
|
|
3
|
+
accepted;
|
|
4
|
+
alt_text;
|
|
5
|
+
attribution;
|
|
6
|
+
content;
|
|
7
|
+
description;
|
|
8
|
+
file_id;
|
|
9
|
+
index;
|
|
10
|
+
last_modified;
|
|
11
|
+
name;
|
|
12
|
+
path;
|
|
13
|
+
selected;
|
|
14
|
+
size;
|
|
15
|
+
status;
|
|
16
|
+
title;
|
|
17
|
+
type;
|
|
18
|
+
url;
|
|
19
|
+
renderer;
|
|
20
|
+
constructor(e) {
|
|
21
|
+
this.accepted = e.accepted ?? !1, this.alt_text = e.alt_text, this.attribution = e.attribution, this.content = e.content, this.description = e.description, this.file_id = e.file_id, this.index = e.index, this.last_modified = e.last_modified, this.name = e.name || "", this.path = e.path, this.selected = e.selected ?? !1, this.size = e.size, this.status = e.status, this.title = e.title, this.type = e.type, this.url = e.url, this.renderer = e.renderer;
|
|
22
|
+
}
|
|
23
|
+
toDisplayString(e) {
|
|
24
|
+
let r = e || utils.getCurrentLanguage() || "en";
|
|
25
|
+
if (this.title) {
|
|
26
|
+
if (this.title[r]?.value) return this.title[r].value;
|
|
27
|
+
for (let e of Object.values(this.title)) if (e.value) return e.value;
|
|
28
|
+
}
|
|
29
|
+
return this.name ? this.name : this.file_id || "(unnamed file)";
|
|
30
|
+
}
|
|
31
|
+
getAltText(e) {
|
|
32
|
+
let r = e || utils.getCurrentLanguage() || "en";
|
|
33
|
+
return this.alt_text && this.alt_text[r]?.value ? this.alt_text[r].value : null;
|
|
34
|
+
}
|
|
35
|
+
isImage() {
|
|
36
|
+
return this.type?.startsWith("image/") ?? !1;
|
|
37
|
+
}
|
|
38
|
+
toJson() {
|
|
39
|
+
let e = {
|
|
40
|
+
name: this.name,
|
|
41
|
+
accepted: this.accepted,
|
|
42
|
+
selected: this.selected
|
|
43
|
+
};
|
|
44
|
+
return this.alt_text && (e.alt_text = this.alt_text), this.attribution && (e.attribution = this.attribution), this.content && (e.content = this.content), this.description && (e.description = this.description), this.file_id && (e.file_id = this.file_id), this.index !== void 0 && (e.index = this.index), this.last_modified && (e.last_modified = this.last_modified), this.path && (e.path = this.path), this.size !== void 0 && (e.size = this.size), this.status && (e.status = this.status), this.title && (e.title = this.title), this.type && (e.type = this.type), this.url && (e.url = this.url), this.renderer && (e.renderer = this.renderer), e;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
wasmReady.then(() => {
|
|
48
|
+
registerExtensionHandler("file-list", { renderDisplay: (e, n) => e ? Array.isArray(e) ? e.length === 0 ? null : e.map((e) => !e || typeof e != "object" ? null : new FileListItem(e).toDisplayString(n)).filter((e) => e !== null).join(", ") : typeof e == "object" && e ? new FileListItem(e).toDisplayString(n) : null : null });
|
|
49
|
+
});
|
|
50
|
+
var FileItemViewModel = class extends String {
|
|
51
|
+
_ = void 0;
|
|
52
|
+
__parentPseudo;
|
|
53
|
+
describeField = () => this.__parentPseudo ? this.__parentPseudo.describeField() : null;
|
|
54
|
+
describeFieldGroup = () => this.__parentPseudo ? this.__parentPseudo.describeFieldGroup() : null;
|
|
55
|
+
_file;
|
|
56
|
+
constructor(e) {
|
|
57
|
+
super(e.toDisplayString()), this._file = e;
|
|
58
|
+
}
|
|
59
|
+
async forJson() {
|
|
60
|
+
return this._file.toJson();
|
|
61
|
+
}
|
|
62
|
+
getValue() {
|
|
63
|
+
return this._file;
|
|
64
|
+
}
|
|
65
|
+
get name() {
|
|
66
|
+
return this._file.name;
|
|
67
|
+
}
|
|
68
|
+
get url() {
|
|
69
|
+
return this._file.url;
|
|
70
|
+
}
|
|
71
|
+
get file_id() {
|
|
72
|
+
return this._file.file_id;
|
|
73
|
+
}
|
|
74
|
+
get fileType() {
|
|
75
|
+
return this._file.type;
|
|
76
|
+
}
|
|
77
|
+
get size() {
|
|
78
|
+
return this._file.size;
|
|
79
|
+
}
|
|
80
|
+
isImage() {
|
|
81
|
+
return this._file.isImage();
|
|
82
|
+
}
|
|
83
|
+
getAltText(e) {
|
|
84
|
+
return this._file.getAltText(e);
|
|
85
|
+
}
|
|
86
|
+
async __asTileData() {
|
|
87
|
+
return this._file ? this._file.toJson() : null;
|
|
88
|
+
}
|
|
89
|
+
}, FileListViewModel = class e extends Array {
|
|
90
|
+
_ = void 0;
|
|
91
|
+
__parentPseudo;
|
|
92
|
+
describeField = () => this.__parentPseudo ? this.__parentPseudo.describeField() : null;
|
|
93
|
+
describeFieldGroup = () => this.__parentPseudo ? this.__parentPseudo.describeFieldGroup() : null;
|
|
94
|
+
_value = null;
|
|
95
|
+
async forJson() {
|
|
96
|
+
let e = await this._value;
|
|
97
|
+
return e ? Promise.all(e.map(async (e) => e ? e.forJson() : null)) : null;
|
|
98
|
+
}
|
|
99
|
+
async getImages() {
|
|
100
|
+
let e = Array.from(this);
|
|
101
|
+
return (await Promise.all(e)).filter((e) => e !== null && e.isImage());
|
|
102
|
+
}
|
|
103
|
+
async getByName(e) {
|
|
104
|
+
let n = Array.from(this);
|
|
105
|
+
return (await Promise.all(n)).find((n) => n !== null && n.name === e) ?? null;
|
|
106
|
+
}
|
|
107
|
+
async getById(e) {
|
|
108
|
+
let n = Array.from(this);
|
|
109
|
+
return (await Promise.all(n)).find((n) => n !== null && n.file_id === e) ?? null;
|
|
110
|
+
}
|
|
111
|
+
static async __create(n, r, i, o = null) {
|
|
112
|
+
let s = r.nodeid, c = [];
|
|
113
|
+
if (n.data.has(s) || n.data.set(s, null), i != null) {
|
|
114
|
+
if (n.data.set(s, []), i instanceof Promise) {
|
|
115
|
+
let a = await i;
|
|
116
|
+
return e.__create(n, r, a, o);
|
|
117
|
+
}
|
|
118
|
+
let l;
|
|
119
|
+
if (Array.isArray(i)) l = i;
|
|
120
|
+
else if (typeof i == "object") l = [i];
|
|
121
|
+
else throw Error(`Cannot set file-list value on node ${s} except via array or object: ${JSON.stringify(i)}`);
|
|
122
|
+
c = l.map((e, n) => {
|
|
123
|
+
if (e instanceof FileItemViewModel) return e;
|
|
124
|
+
if (typeof e == "object" && e) {
|
|
125
|
+
let r = e;
|
|
126
|
+
return r.index === void 0 && (r.index = n), new FileItemViewModel(new FileListItem(r));
|
|
127
|
+
}
|
|
128
|
+
return null;
|
|
129
|
+
}), Promise.all(c).then((e) => {
|
|
130
|
+
let r = e.filter((e) => e !== null).map((e) => e.getValue().toJson());
|
|
131
|
+
n.data.set(s, r);
|
|
132
|
+
});
|
|
133
|
+
} else c = [];
|
|
134
|
+
let l = new e(...c);
|
|
135
|
+
return l._value = Promise.all(c), l;
|
|
136
|
+
}
|
|
137
|
+
async __asTileData() {
|
|
138
|
+
return this.forJson();
|
|
139
|
+
}
|
|
140
|
+
}, FileListDataType = class {
|
|
141
|
+
static async __create(e, n, r, i) {
|
|
142
|
+
return FileListViewModel.__create(e, n, r, i);
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
viewModels.CUSTOM_DATATYPES.set("file-list", FileListDataType);
|
|
146
|
+
export { FileItemViewModel, FileListDataType, FileListItem, FileListViewModel };
|
package/dist/main.d.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type { interfaces, staticTypes } from "alizarin";
|
|
2
|
+
type IPseudo = interfaces.IPseudo;
|
|
3
|
+
type IViewModel = interfaces.IViewModel;
|
|
4
|
+
type StaticTile = staticTypes.StaticTile;
|
|
5
|
+
type StaticNode = staticTypes.StaticNode;
|
|
6
|
+
interface LocalizedStringValue {
|
|
7
|
+
direction: string;
|
|
8
|
+
value: string;
|
|
9
|
+
}
|
|
10
|
+
type LocalizedString = {
|
|
11
|
+
[lang: string]: LocalizedStringValue;
|
|
12
|
+
};
|
|
13
|
+
interface FileListItemData {
|
|
14
|
+
accepted?: boolean;
|
|
15
|
+
alt_text?: LocalizedString;
|
|
16
|
+
attribution?: LocalizedString;
|
|
17
|
+
content?: string;
|
|
18
|
+
description?: LocalizedString;
|
|
19
|
+
file_id?: string;
|
|
20
|
+
index?: number;
|
|
21
|
+
last_modified?: number;
|
|
22
|
+
name: string;
|
|
23
|
+
path?: string;
|
|
24
|
+
selected?: boolean;
|
|
25
|
+
size?: number;
|
|
26
|
+
status?: string;
|
|
27
|
+
title?: LocalizedString;
|
|
28
|
+
type?: string;
|
|
29
|
+
url?: string;
|
|
30
|
+
renderer?: string;
|
|
31
|
+
}
|
|
32
|
+
declare class FileListItem {
|
|
33
|
+
accepted: boolean;
|
|
34
|
+
alt_text?: LocalizedString;
|
|
35
|
+
attribution?: LocalizedString;
|
|
36
|
+
content?: string;
|
|
37
|
+
description?: LocalizedString;
|
|
38
|
+
file_id?: string;
|
|
39
|
+
index?: number;
|
|
40
|
+
last_modified?: number;
|
|
41
|
+
name: string;
|
|
42
|
+
path?: string;
|
|
43
|
+
selected: boolean;
|
|
44
|
+
size?: number;
|
|
45
|
+
status?: string;
|
|
46
|
+
title?: LocalizedString;
|
|
47
|
+
type?: string;
|
|
48
|
+
url?: string;
|
|
49
|
+
renderer?: string;
|
|
50
|
+
constructor(data: FileListItemData);
|
|
51
|
+
/**
|
|
52
|
+
* Get the display string for this file.
|
|
53
|
+
* Uses title if available (in specified language), otherwise falls back to filename.
|
|
54
|
+
*/
|
|
55
|
+
toDisplayString(lang?: string): string;
|
|
56
|
+
/**
|
|
57
|
+
* Get the alt text in a specific language.
|
|
58
|
+
*/
|
|
59
|
+
getAltText(lang?: string): string | null;
|
|
60
|
+
/**
|
|
61
|
+
* Check if this is an image file based on MIME type.
|
|
62
|
+
*/
|
|
63
|
+
isImage(): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Convert to plain object for JSON serialization.
|
|
66
|
+
*/
|
|
67
|
+
toJson(): FileListItemData;
|
|
68
|
+
}
|
|
69
|
+
declare class FileItemViewModel extends String implements IViewModel {
|
|
70
|
+
_: IViewModel | Promise<IViewModel> | undefined;
|
|
71
|
+
__parentPseudo: IPseudo | undefined;
|
|
72
|
+
describeField: () => string | null;
|
|
73
|
+
describeFieldGroup: () => string | null;
|
|
74
|
+
_file: FileListItem;
|
|
75
|
+
constructor(file: FileListItem);
|
|
76
|
+
forJson(): Promise<FileListItemData>;
|
|
77
|
+
getValue(): FileListItem;
|
|
78
|
+
get name(): string;
|
|
79
|
+
get url(): string | undefined;
|
|
80
|
+
get file_id(): string | undefined;
|
|
81
|
+
get fileType(): string | undefined;
|
|
82
|
+
get size(): number | undefined;
|
|
83
|
+
isImage(): boolean;
|
|
84
|
+
getAltText(lang?: string): string | null;
|
|
85
|
+
__asTileData(): Promise<FileListItemData | null>;
|
|
86
|
+
}
|
|
87
|
+
declare class FileListViewModel extends Array<FileItemViewModel | Promise<FileItemViewModel | null> | null> implements IViewModel {
|
|
88
|
+
_: IViewModel | Promise<IViewModel> | undefined;
|
|
89
|
+
__parentPseudo: IPseudo | undefined;
|
|
90
|
+
describeField: () => string | null;
|
|
91
|
+
describeFieldGroup: () => string | null;
|
|
92
|
+
_value: Promise<(FileItemViewModel | null)[]> | null;
|
|
93
|
+
forJson(): Promise<(FileListItemData | null)[] | null>;
|
|
94
|
+
/**
|
|
95
|
+
* Get only image files from the list.
|
|
96
|
+
*/
|
|
97
|
+
getImages(): Promise<FileItemViewModel[]>;
|
|
98
|
+
/**
|
|
99
|
+
* Find a file by name.
|
|
100
|
+
*/
|
|
101
|
+
getByName(name: string): Promise<FileItemViewModel | null>;
|
|
102
|
+
/**
|
|
103
|
+
* Find a file by ID.
|
|
104
|
+
*/
|
|
105
|
+
getById(fileId: string): Promise<FileItemViewModel | null>;
|
|
106
|
+
static __create(tile: StaticTile, node: StaticNode, value: unknown, _cacheEntry?: object | null): Promise<FileListViewModel>;
|
|
107
|
+
__asTileData(): Promise<(FileListItemData | null)[] | null>;
|
|
108
|
+
}
|
|
109
|
+
declare class FileListDataType {
|
|
110
|
+
static __create(tile: StaticTile, node: StaticNode, value: unknown, _cacheEntry: object): Promise<FileListViewModel>;
|
|
111
|
+
}
|
|
112
|
+
export { FileListItem, FileItemViewModel, FileListViewModel, FileListDataType, };
|
|
113
|
+
export type { LocalizedStringValue, LocalizedString, FileListItemData, };
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@alizarin/filelist",
|
|
3
|
+
"version": "0.2.1-alpha.83",
|
|
4
|
+
"description": "Alizarin display serializers and view models for file-list datatypes",
|
|
5
|
+
"license": "AGPL-3.0",
|
|
6
|
+
"author": "Phil Weir <phil.weir@flaxandteal.co.uk>",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./dist/filelist.js",
|
|
9
|
+
"types": "./dist/main.d.ts",
|
|
10
|
+
"files": [
|
|
11
|
+
"dist/filelist.js",
|
|
12
|
+
"dist/main.d.ts"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"dev": "vite",
|
|
16
|
+
"build": "vite build && tsc -p tsconfig.build.json",
|
|
17
|
+
"preview": "vite preview",
|
|
18
|
+
"test": "cd ../../../.. && npm test -- ext/js/@alizarin/filelist/tests/filelist.test.ts"
|
|
19
|
+
},
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"alizarin": "0.2.1-alpha.83"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"alizarin": "file:../../../..",
|
|
25
|
+
"typescript": "~5.9.3",
|
|
26
|
+
"vite": "npm:rolldown-vite@7.2.5"
|
|
27
|
+
},
|
|
28
|
+
"overrides": {
|
|
29
|
+
"vite": "npm:rolldown-vite@7.2.5"
|
|
30
|
+
}
|
|
31
|
+
}
|