@nextcloud/files 3.0.0-beta.2 → 3.0.0-beta.21

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.
@@ -0,0 +1,103 @@
1
+ /**
2
+ * @copyright Copyright (c) 2022 John Molakvoæ <skjnldsv@protonmail.com>
3
+ *
4
+ * @author John Molakvoæ <skjnldsv@protonmail.com>
5
+ *
6
+ * @license AGPL-3.0-or-later
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU Affero General Public License as
10
+ * published by the Free Software Foundation, either version 3 of the
11
+ * License, or (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ * GNU Affero General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU Affero General Public License
19
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+ import type { Folder, Node } from '@nextcloud/files';
23
+ import { Column } from './column.js';
24
+ export type ContentsWithRoot = {
25
+ folder: Folder;
26
+ contents: Node[];
27
+ };
28
+ interface ViewData {
29
+ /** Unique view ID */
30
+ id: string;
31
+ /** Translated view name */
32
+ name: string;
33
+ /** Translated accessible description of the view */
34
+ caption?: string;
35
+ /** Translated title of the empty view */
36
+ emptyTitle?: string;
37
+ /** Translated description of the empty view */
38
+ emptyCaption?: string;
39
+ /**
40
+ * Method return the content of the provided path
41
+ * This ideally should be a cancellable promise.
42
+ * promise.cancel(reason) will be called when the directory
43
+ * change and the promise is not resolved yet.
44
+ * You _must_ also return the current directory
45
+ * information alongside with its content.
46
+ */
47
+ getContents: (path: string) => Promise<ContentsWithRoot>;
48
+ /** The view icon as an inline svg */
49
+ icon: string;
50
+ /** The view order */
51
+ order: number;
52
+ /**
53
+ * Custom params to give to the router on click
54
+ * If defined, will be treated as a dummy view and
55
+ * will just redirect and not fetch any contents.
56
+ */
57
+ params?: Record<string, string>;
58
+ /**
59
+ * This view column(s). Name and actions are
60
+ * by default always included
61
+ */
62
+ columns?: Column[];
63
+ /** The empty view element to render your empty content into */
64
+ emptyView?: (div: HTMLDivElement) => void;
65
+ /** The parent unique ID */
66
+ parent?: string;
67
+ /** This view is sticky (sent at the bottom) */
68
+ sticky?: boolean;
69
+ /**
70
+ * This view has children and is expanded (by default)
71
+ * or not. This will be overridden by user config.
72
+ */
73
+ expanded?: boolean;
74
+ /**
75
+ * Will be used as default if the user
76
+ * haven't customized their sorting column
77
+ */
78
+ defaultSortKey?: string;
79
+ }
80
+ export declare class View implements ViewData {
81
+ private _view;
82
+ constructor(view: ViewData);
83
+ get id(): string;
84
+ get name(): string;
85
+ get caption(): string | undefined;
86
+ get emptyTitle(): string | undefined;
87
+ get emptyCaption(): string | undefined;
88
+ get getContents(): (path: string) => Promise<ContentsWithRoot>;
89
+ get icon(): string;
90
+ set icon(icon: string);
91
+ get order(): number;
92
+ set order(order: number);
93
+ get params(): Record<string, string> | undefined;
94
+ set params(params: Record<string, string> | undefined);
95
+ get columns(): Column[] | undefined;
96
+ get emptyView(): ((div: HTMLDivElement) => void) | undefined;
97
+ get parent(): string | undefined;
98
+ get sticky(): boolean | undefined;
99
+ get expanded(): boolean | undefined;
100
+ set expanded(expanded: boolean | undefined);
101
+ get defaultSortKey(): string | undefined;
102
+ }
103
+ export {};
@@ -19,22 +19,35 @@
19
19
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20
20
  *
21
21
  */
22
+ import { Folder } from './files/folder';
22
23
  export interface Entry {
23
24
  /** Unique ID */
24
25
  id: string;
25
26
  /** Translatable string displayed in the menu */
26
27
  displayName: string;
27
- templateName: string;
28
- if?: (context: Object) => Boolean;
28
+ /** Default new file name */
29
+ templateName?: string;
30
+ /**
31
+ * Condition wether this entry is shown or not
32
+ * @param {Folder} context the creation context. Usually the current folder
33
+ */
34
+ if?: (context: Folder) => boolean;
29
35
  /**
30
36
  * Either iconSvgInline or iconClass must be defined
31
37
  * Svg as inline string. <svg><path fill="..." /></svg>
32
38
  */
33
39
  iconSvgInline?: string;
34
- /** Existing icon css class */
40
+ /**
41
+ * Existing icon css class
42
+ * @deprecated use iconSvgInline instead
43
+ */
35
44
  iconClass?: string;
36
- /** Function to be run after creation */
37
- handler?: Function;
45
+ /**
46
+ * Function to be run after creation
47
+ * @param {Folder} context the creation context. Usually the current folder
48
+ * @param {Node[]} content list of file/folders present in the context folder
49
+ */
50
+ handler: (context: Folder, content: Node[]) => void;
38
51
  }
39
52
  export declare class NewFileMenu {
40
53
  private _entries;
@@ -43,9 +56,9 @@ export declare class NewFileMenu {
43
56
  /**
44
57
  * Get the list of registered entries
45
58
  *
46
- * @param {FileInfo} context the creation context. Usually the current folder FileInfo
59
+ * @param {Folder} context the creation context. Usually the current folder
47
60
  */
48
- getEntries(context?: Object): Array<Entry>;
61
+ getEntries(context?: Folder): Array<Entry>;
49
62
  private getEntryIndex;
50
63
  private validateEntry;
51
64
  }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @copyright Copyright (c) 2022 John Molakvoæ <skjnldsv@protonmail.com>
3
+ *
4
+ * @author John Molakvoæ <skjnldsv@protonmail.com>
5
+ *
6
+ * @license AGPL-3.0-or-later
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU Affero General Public License as
10
+ * published by the Free Software Foundation, either version 3 of the
11
+ * License, or (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ * GNU Affero General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU Affero General Public License
19
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+ /**
23
+ * Node permissions
24
+ */
25
+ export declare enum Permission {
26
+ NONE = 0,
27
+ CREATE = 4,
28
+ READ = 1,
29
+ UPDATE = 2,
30
+ DELETE = 8,
31
+ SHARE = 16,
32
+ ALL = 31
33
+ }
@@ -19,5 +19,5 @@
19
19
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20
20
  *
21
21
  */
22
- declare const _default: import("@nextcloud/logger/dist/contracts").ILogger;
22
+ declare const _default: any;
23
23
  export default _default;
@@ -0,0 +1,13 @@
1
+ Included dependencies:
2
+
3
+ fast-xml-parser
4
+ version: 4.2.7
5
+ license: MIT
6
+
7
+ is-svg
8
+ version: 5.0.0
9
+ license: MIT
10
+
11
+ strnum
12
+ version: 1.0.5
13
+ license: MIT
package/package.json CHANGED
@@ -1,14 +1,16 @@
1
1
  {
2
2
  "name": "@nextcloud/files",
3
- "version": "3.0.0-beta.2",
3
+ "version": "3.0.0-beta.21",
4
4
  "description": "Nextcloud files utils",
5
- "main": "dist/index.js",
6
- "module": "dist/index.esm.js",
5
+ "type": "module",
6
+ "main": "dist/index.cjs",
7
+ "module": "dist/index.mjs",
7
8
  "types": "dist/index.d.ts",
8
9
  "exports": {
9
10
  ".": {
10
- "import": "./dist/index.esm.js",
11
- "require": "./dist/index.js"
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.mjs",
13
+ "require": "./dist/index.cjs"
12
14
  }
13
15
  },
14
16
  "files": [
@@ -16,7 +18,8 @@
16
18
  ],
17
19
  "author": "Christoph Wurst <christoph@winzerhof-wurst.at>",
18
20
  "contributors": [
19
- "John Molakvoæ <skjnldsv@protonmail.com>"
21
+ "John Molakvoæ <skjnldsv@protonmail.com>",
22
+ "Ferdinand Thiessen <opensource@fthiessen.de>"
20
23
  ],
21
24
  "license": "AGPL-3.0-or-later",
22
25
  "keywords": [
@@ -25,47 +28,52 @@
25
28
  "library"
26
29
  ],
27
30
  "scripts": {
28
- "build": "rollup --config rollup.config.js",
31
+ "build": "vite --mode production build",
29
32
  "build:doc": "typedoc --out dist/doc lib && touch dist/doc/.nojekyll",
30
- "dev": "echo 'No dev build available, production only' && npm run build",
31
- "watch": "rollup --config rollup.config.js --watch",
32
- "test": "jest",
33
- "test:watch": "jest --watchAll --verbose true",
34
- "test:coverage": "jest --coverage"
33
+ "dev": "vite --mode development build",
34
+ "dev:watch": "vite --mode development build --watch",
35
+ "lint": "eslint .",
36
+ "lint:fix": "eslint --fix .",
37
+ "test": "vitest run",
38
+ "test:watch": "vitest watch",
39
+ "test:coverage": "vitest run --coverage"
35
40
  },
36
41
  "repository": {
37
42
  "type": "git",
38
- "url": "https://github.com/nextcloud/nextcloud-files.git"
43
+ "url": "https://github.com/nextcloud-libraries/nextcloud-files.git"
39
44
  },
40
45
  "bugs": {
41
- "url": "https://github.com/nextcloud/nextcloud-files/issues"
46
+ "url": "https://github.com/nextcloud-libraries/nextcloud-files/issues"
42
47
  },
43
48
  "engines": {
44
- "node": "^16.0.0",
45
- "npm": "^7.0.0 || ^8.0.0"
49
+ "node": "^20.0.0",
50
+ "npm": "^9.0.0"
46
51
  },
47
- "homepage": "https://github.com/nextcloud/nextcloud-files",
52
+ "homepage": "https://github.com/nextcloud-libraries/nextcloud-files",
48
53
  "devDependencies": {
49
- "@babel/cli": "^7.17.10",
50
- "@babel/core": "^7.18.5",
51
- "@babel/preset-env": "^7.18.2",
52
- "@babel/preset-typescript": "^7.17.12",
53
- "@rollup-extras/plugin-clean": "^1.2.3",
54
- "@rollup/plugin-commonjs": "^22.0.0",
55
- "@rollup/plugin-node-resolve": "^13.3.0",
56
- "@rollup/plugin-typescript": "^8.3.2",
57
- "@types/jest": "^28.1.1",
58
- "jest": "^28.1.1",
59
- "jest-environment-jsdom": "^29.0.1",
60
- "rollup": "^2.75.6",
61
- "ts-jest": "^28.0.4",
62
- "tslib": "^2.4.0",
63
- "typedoc": "^0.23.4",
64
- "typescript": "^4.7.3"
54
+ "@nextcloud/eslint-config": "^8.3.0-beta.2",
55
+ "@nextcloud/typings": "^1.7.0",
56
+ "@nextcloud/vite-config": "^1.0.0-beta.18",
57
+ "@rollup-extras/plugin-clean": "^1.3.6",
58
+ "@rollup/plugin-commonjs": "^25.0.4",
59
+ "@rollup/plugin-node-resolve": "^15.2.1",
60
+ "@rollup/plugin-typescript": "^11.1.2",
61
+ "@types/node": "^20.5.6",
62
+ "@vitest/coverage-istanbul": "^0.34.3",
63
+ "fast-xml-parser": "^4.2.7",
64
+ "rollup": "^3.28.1",
65
+ "tslib": "^2.6.2",
66
+ "typedoc": "^0.25.0",
67
+ "typescript": "^5.2.2",
68
+ "vite": "^4.4.9",
69
+ "vitest": "^0.34.3"
65
70
  },
66
71
  "dependencies": {
67
- "@nextcloud/auth": "^2.0.0",
68
- "@nextcloud/l10n": "^1.6.0",
69
- "@nextcloud/logger": "^2.1.0"
72
+ "@nextcloud/auth": "^2.1.0",
73
+ "@nextcloud/l10n": "^2.2.0",
74
+ "@nextcloud/logger": "^2.5.0",
75
+ "@nextcloud/router": "^2.1.2",
76
+ "is-svg": "^5.0.0",
77
+ "webdav": "^5.2.3"
70
78
  }
71
79
  }
package/dist/index.esm.js DELETED
@@ -1,222 +0,0 @@
1
- import { getCanonicalLocale } from '@nextcloud/l10n';
2
- import { getCurrentUser } from '@nextcloud/auth';
3
- import { getLoggerBuilder } from '@nextcloud/logger';
4
-
5
- /**
6
- * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
7
- *
8
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
9
- * @author John Molakvoæ <skjnldsv@protonmail.com>
10
- *
11
- * @license AGPL-3.0-or-later
12
- *
13
- * This program is free software: you can redistribute it and/or modify
14
- * it under the terms of the GNU Affero General Public License as
15
- * published by the Free Software Foundation, either version 3 of the
16
- * License, or (at your option) any later version.
17
- *
18
- * This program is distributed in the hope that it will be useful,
19
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
- * GNU Affero General Public License for more details.
22
- *
23
- * You should have received a copy of the GNU Affero General Public License
24
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
25
- *
26
- */
27
- const humanList = ['B', 'KB', 'MB', 'GB', 'TB'];
28
- /**
29
- * Format a file size in a human-like format. e.g. 42GB
30
- *
31
- * @param size in bytes
32
- * @param skipSmallSizes avoid rendering tiny sizes and return '< 1 KB' instead
33
- */
34
- function formatFileSize(size, skipSmallSizes = false) {
35
- if (typeof size === 'string') {
36
- size = Number(size);
37
- }
38
- // Calculate Log with base 1024: size = 1024 ** order
39
- let order = size > 0 ? Math.floor(Math.log(size) / Math.log(1024)) : 0;
40
- // Stay in range of the byte sizes that are defined
41
- order = Math.min(humanList.length - 1, order);
42
- const readableFormat = humanList[order];
43
- let relativeSize = (size / Math.pow(1024, order)).toFixed(1);
44
- if (skipSmallSizes === true && order === 0) {
45
- if (relativeSize !== '0.0') {
46
- return '< 1 KB';
47
- }
48
- else {
49
- return '0 KB';
50
- }
51
- }
52
- if (order < 2) {
53
- relativeSize = parseFloat(relativeSize).toFixed(0);
54
- }
55
- else {
56
- relativeSize = parseFloat(relativeSize).toLocaleString(getCanonicalLocale());
57
- }
58
- return relativeSize + ' ' + readableFormat;
59
- }
60
-
61
- /**
62
- * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
63
- *
64
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
65
- *
66
- * @license AGPL-3.0-or-later
67
- *
68
- * This program is free software: you can redistribute it and/or modify
69
- * it under the terms of the GNU Affero General Public License as
70
- * published by the Free Software Foundation, either version 3 of the
71
- * License, or (at your option) any later version.
72
- *
73
- * This program is distributed in the hope that it will be useful,
74
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
75
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
76
- * GNU Affero General Public License for more details.
77
- *
78
- * You should have received a copy of the GNU Affero General Public License
79
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
80
- *
81
- */
82
- const getLogger = user => {
83
- if (user === null) {
84
- return getLoggerBuilder()
85
- .setApp('files')
86
- .build();
87
- }
88
- return getLoggerBuilder()
89
- .setApp('files')
90
- .setUid(user.uid)
91
- .build();
92
- };
93
- var logger = getLogger(getCurrentUser());
94
-
95
- /**
96
- * @copyright Copyright (c) 2021 John Molakvoæ <skjnldsv@protonmail.com>
97
- *
98
- * @author John Molakvoæ <skjnldsv@protonmail.com>
99
- *
100
- * @license AGPL-3.0-or-later
101
- *
102
- * This program is free software: you can redistribute it and/or modify
103
- * it under the terms of the GNU Affero General Public License as
104
- * published by the Free Software Foundation, either version 3 of the
105
- * License, or (at your option) any later version.
106
- *
107
- * This program is distributed in the hope that it will be useful,
108
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
109
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
110
- * GNU Affero General Public License for more details.
111
- *
112
- * You should have received a copy of the GNU Affero General Public License
113
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
114
- *
115
- */
116
- class NewFileMenu {
117
- _entries = [];
118
- registerEntry(entry) {
119
- this.validateEntry(entry);
120
- this._entries.push(entry);
121
- }
122
- unregisterEntry(entry) {
123
- const entryIndex = typeof entry === 'string'
124
- ? this.getEntryIndex(entry)
125
- : this.getEntryIndex(entry.id);
126
- if (entryIndex === -1) {
127
- logger.warn('Entry not found, nothing removed', { entry, entries: this.getEntries() });
128
- return;
129
- }
130
- this._entries.splice(entryIndex, 1);
131
- }
132
- /**
133
- * Get the list of registered entries
134
- *
135
- * @param {FileInfo} context the creation context. Usually the current folder FileInfo
136
- */
137
- getEntries(context) {
138
- if (context) {
139
- return this._entries
140
- .filter(entry => typeof entry.if === 'function' ? entry.if(context) : true);
141
- }
142
- return this._entries;
143
- }
144
- getEntryIndex(id) {
145
- return this._entries.findIndex(entry => entry.id === id);
146
- }
147
- validateEntry(entry) {
148
- if (!entry.id || !entry.displayName || !entry.templateName || !(entry.iconSvgInline || entry.iconClass) || !entry.handler) {
149
- throw new Error('Invalid entry');
150
- }
151
- if (typeof entry.id !== 'string'
152
- || typeof entry.displayName !== 'string'
153
- || typeof entry.templateName !== 'string'
154
- || (entry.iconClass && typeof entry.iconClass !== 'string')
155
- || (entry.iconSvgInline && typeof entry.iconSvgInline !== 'string')) {
156
- throw new Error('Invalid entry property');
157
- }
158
- if (entry.if !== undefined && typeof entry.if !== 'function') {
159
- throw new Error('Invalid entry, if must be a valid function');
160
- }
161
- if (typeof entry.handler !== 'function') {
162
- throw new Error('Invalid entry handler');
163
- }
164
- if (this.getEntryIndex(entry.id) !== -1) {
165
- throw new Error('Duplicate entry');
166
- }
167
- }
168
- }
169
- const getNewFileMenu = function () {
170
- if (typeof window._nc_newfilemenu === 'undefined') {
171
- window._nc_newfilemenu = new NewFileMenu();
172
- logger.debug('NewFileMenu initialized');
173
- }
174
- return window._nc_newfilemenu;
175
- };
176
-
177
- /**
178
- * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
179
- *
180
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
181
- * @author John Molakvoæ <skjnldsv@protonmail.com>
182
- *
183
- * @license AGPL-3.0-or-later
184
- *
185
- * This program is free software: you can redistribute it and/or modify
186
- * it under the terms of the GNU Affero General Public License as
187
- * published by the Free Software Foundation, either version 3 of the
188
- * License, or (at your option) any later version.
189
- *
190
- * This program is distributed in the hope that it will be useful,
191
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
192
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
193
- * GNU Affero General Public License for more details.
194
- *
195
- * You should have received a copy of the GNU Affero General Public License
196
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
197
- *
198
- */
199
- /**
200
- * Add a new menu entry to the upload manager menu
201
- */
202
- const addNewFileMenuEntry = function (entry) {
203
- const newFileMenu = getNewFileMenu();
204
- return newFileMenu.registerEntry(entry);
205
- };
206
- /**
207
- * Remove a previously registered entry from the upload menu
208
- */
209
- const removeNewFileMenuEntry = function (entry) {
210
- const newFileMenu = getNewFileMenu();
211
- return newFileMenu.unregisterEntry(entry);
212
- };
213
- /**
214
- * Get the list of registered entries from the upload menu
215
- */
216
- const getNewFileMenuEntries = function () {
217
- const newFileMenu = getNewFileMenu();
218
- return newFileMenu.getEntries();
219
- };
220
-
221
- export { addNewFileMenuEntry, formatFileSize, getNewFileMenuEntries, removeNewFileMenuEntry };
222
- //# sourceMappingURL=index.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.esm.js","sources":["../lib/humanfilesize.ts","../lib/utils/logger.ts","../lib/newFileMenu.ts","../lib/index.ts"],"sourcesContent":["/**\n * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>\n *\n * @author Christoph Wurst <christoph@winzerhof-wurst.at>\n * @author John Molakvoæ <skjnldsv@protonmail.com>\n *\n * @license AGPL-3.0-or-later\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU Affero General Public License as\n * published by the Free Software Foundation, either version 3 of the\n * License, or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU Affero General Public License for more details.\n *\n * You should have received a copy of the GNU Affero General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n *\n */\n\nimport { getCanonicalLocale } from '@nextcloud/l10n'\n\nconst humanList = ['B', 'KB', 'MB', 'GB', 'TB'];\n\n/**\n * Format a file size in a human-like format. e.g. 42GB\n *\n * @param size in bytes\n * @param skipSmallSizes avoid rendering tiny sizes and return '< 1 KB' instead\n */\nexport function formatFileSize(size: number|string, skipSmallSizes: boolean = false): string {\n\n\tif (typeof size === 'string') {\n\t\tsize = Number(size)\n\t}\n\n\t// Calculate Log with base 1024: size = 1024 ** order\n\tlet order = size > 0 ? Math.floor(Math.log(size) / Math.log(1024)) : 0;\n\t// Stay in range of the byte sizes that are defined\n\torder = Math.min(humanList.length - 1, order);\n\tconst readableFormat = humanList[order];\n\tlet relativeSize = (size / Math.pow(1024, order)).toFixed(1);\n\n\tif (skipSmallSizes === true && order === 0) {\n\t\tif (relativeSize !== '0.0') {\n\t\t\treturn '< 1 KB';\n\t\t} else {\n\t\t\treturn '0 KB';\n\t\t}\n\t}\n\n\tif (order < 2) {\n\t\trelativeSize = parseFloat(relativeSize).toFixed(0);\n\t} else {\n\t\trelativeSize = parseFloat(relativeSize).toLocaleString(getCanonicalLocale());\n\t}\n\n\treturn relativeSize + ' ' + readableFormat;\n}\n","/**\n * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>\n *\n * @author Christoph Wurst <christoph@winzerhof-wurst.at>\n *\n * @license AGPL-3.0-or-later\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU Affero General Public License as\n * published by the Free Software Foundation, either version 3 of the\n * License, or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU Affero General Public License for more details.\n *\n * You should have received a copy of the GNU Affero General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n *\n */\n\nimport { getCurrentUser } from '@nextcloud/auth'\nimport { getLoggerBuilder } from '@nextcloud/logger'\n\nconst getLogger = user => {\n\tif (user === null) {\n\t\treturn getLoggerBuilder()\n\t\t\t.setApp('files')\n\t\t\t.build()\n\t}\n\treturn getLoggerBuilder()\n\t\t.setApp('files')\n\t\t.setUid(user.uid)\n\t\t.build()\n}\n\nexport default getLogger(getCurrentUser())\n","/**\n * @copyright Copyright (c) 2021 John Molakvoæ <skjnldsv@protonmail.com>\n *\n * @author John Molakvoæ <skjnldsv@protonmail.com>\n *\n * @license AGPL-3.0-or-later\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU Affero General Public License as\n * published by the Free Software Foundation, either version 3 of the\n * License, or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU Affero General Public License for more details.\n *\n * You should have received a copy of the GNU Affero General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n *\n */\n\nimport logger from \"./utils/logger\"\n\nexport interface Entry {\n\t/** Unique ID */\n\tid: string\n\t/** Translatable string displayed in the menu */\n\tdisplayName: string\n\t// Default new file name\n\ttemplateName: string\n\t// Condition wether this entry is shown or not\n\tif?: (context: Object) => Boolean\n\t/**\n\t * Either iconSvgInline or iconClass must be defined\n\t * Svg as inline string. <svg><path fill=\"...\" /></svg>\n\t */\n\ticonSvgInline?: string\n\t/** Existing icon css class */\n\ticonClass?: string\n\t/** Function to be run after creation */\n\thandler?: Function\n}\n\nexport class NewFileMenu {\n\tprivate _entries: Array<Entry> = []\n\t\n\tpublic registerEntry(entry: Entry) {\n\t\tthis.validateEntry(entry)\n\t\tthis._entries.push(entry)\n\t}\n\n\tpublic unregisterEntry(entry: Entry | string) {\n\t\tconst entryIndex = typeof entry === 'string'\n\t\t\t? this.getEntryIndex(entry)\n\t\t\t: this.getEntryIndex(entry.id)\n\t\t\n\t\tif (entryIndex === -1) {\n\t\t\tlogger.warn('Entry not found, nothing removed', { entry , entries: this.getEntries() })\n\t\t\treturn\n\t\t}\n\n\t\tthis._entries.splice(entryIndex, 1)\n\t}\n\t\n\t/**\n\t * Get the list of registered entries\n\t * \n\t * @param {FileInfo} context the creation context. Usually the current folder FileInfo\n\t */\n\tpublic getEntries(context?: Object): Array<Entry> {\n\t\tif (context) {\n\t\t\treturn this._entries\n\t\t\t\t.filter(entry => typeof entry.if === 'function' ? entry.if(context) : true)\n\t\t}\n\t\treturn this._entries\n\t}\n\n\tprivate getEntryIndex(id: string): number {\n\t\treturn this._entries.findIndex(entry => entry.id === id)\n\t}\n\n\tprivate validateEntry(entry: Entry) {\n\t\tif (!entry.id || !entry.displayName || !entry.templateName || !(entry.iconSvgInline || entry.iconClass) ||!entry.handler) {\n\t\t\tthrow new Error('Invalid entry')\n\t\t}\n\n\t\tif (typeof entry.id !== 'string'\n\t\t\t|| typeof entry.displayName !== 'string'\n\t\t\t|| typeof entry.templateName !== 'string'\n\t\t\t|| (entry.iconClass && typeof entry.iconClass !== 'string')\n\t\t\t|| (entry.iconSvgInline && typeof entry.iconSvgInline !== 'string')) {\n\t\t\tthrow new Error('Invalid entry property')\n\t\t}\n\n\t\tif (entry.if !== undefined && typeof entry.if !== 'function') {\n\t\t\tthrow new Error('Invalid entry, if must be a valid function')\n\t\t}\n\n\t\tif (typeof entry.handler !== 'function') {\n\t\t\tthrow new Error('Invalid entry handler')\n\t\t}\n\n\t\tif (this.getEntryIndex(entry.id) !== -1) {\n\t\t\tthrow new Error('Duplicate entry')\n\t\t}\n\t}\n}\n\nexport const getNewFileMenu = function(): NewFileMenu {\n\tif (typeof window._nc_newfilemenu === 'undefined') {\n\t\twindow._nc_newfilemenu = new NewFileMenu()\n\t\tlogger.debug('NewFileMenu initialized')\n\t}\n\treturn window._nc_newfilemenu\n}","/**\n * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>\n *\n * @author Christoph Wurst <christoph@winzerhof-wurst.at>\n * @author John Molakvoæ <skjnldsv@protonmail.com>\n *\n * @license AGPL-3.0-or-later\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU Affero General Public License as\n * published by the Free Software Foundation, either version 3 of the\n * License, or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU Affero General Public License for more details.\n *\n * You should have received a copy of the GNU Affero General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n *\n */\n\nexport { formatFileSize } from './humanfilesize'\nexport { type Entry } from './newFileMenu'\nimport { type Entry, getNewFileMenu, NewFileMenu } from './newFileMenu'\n\ndeclare global {\n\tinterface Window {\n\t\tOC: any;\n\t\t_nc_newfilemenu: NewFileMenu;\n\t}\n}\n\n/**\n * Add a new menu entry to the upload manager menu\n */\nexport const addNewFileMenuEntry = function(entry: Entry) {\n\tconst newFileMenu = getNewFileMenu()\n\treturn newFileMenu.registerEntry(entry)\n}\n\n/**\n * Remove a previously registered entry from the upload menu\n */\nexport const removeNewFileMenuEntry = function(entry: Entry | string) {\n\tconst newFileMenu = getNewFileMenu()\n\treturn newFileMenu.unregisterEntry(entry)\n}\n\n/**\n * Get the list of registered entries from the upload menu\n */\nexport const getNewFileMenuEntries = function() {\n\tconst newFileMenu = getNewFileMenu()\n\treturn newFileMenu.getEntries()\n}\n"],"names":[],"mappings":";;;;AAAA;;;;;;;;;;;;;;;;;;;;;AAqBG;AAIH,MAAM,SAAS,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAEhD;;;;;AAKG;SACa,cAAc,CAAC,IAAmB,EAAE,iBAA0B,KAAK,EAAA;AAElF,IAAA,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;AAC7B,QAAA,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,CAAA;AACnB,KAAA;;AAGD,IAAA,IAAI,KAAK,GAAG,IAAI,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;;AAEvE,IAAA,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;AAC9C,IAAA,MAAM,cAAc,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;AACxC,IAAA,IAAI,YAAY,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;AAE7D,IAAA,IAAI,cAAc,KAAK,IAAI,IAAI,KAAK,KAAK,CA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