@nextcloud/files 2.1.0 → 3.0.0-beta.1

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 CHANGED
@@ -1,14 +1,233 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "formatFileSize", {
7
- enumerable: true,
8
- get: function get() {
9
- return _humanfilesize.formatFileSize;
10
- }
11
- });
12
-
13
- var _humanfilesize = require("./humanfilesize");
14
- //# sourceMappingURL=index.js.map
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var l10n = require('@nextcloud/l10n');
6
+ var auth = require('@nextcloud/auth');
7
+ var logger$1 = require('@nextcloud/logger');
8
+
9
+ /**
10
+ * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
11
+ *
12
+ * @author Christoph Wurst <christoph@winzerhof-wurst.at>
13
+ * @author John Molakvoæ <skjnldsv@protonmail.com>
14
+ *
15
+ * @license AGPL-3.0-or-later
16
+ *
17
+ * This program is free software: you can redistribute it and/or modify
18
+ * it under the terms of the GNU Affero General Public License as
19
+ * published by the Free Software Foundation, either version 3 of the
20
+ * License, or (at your option) any later version.
21
+ *
22
+ * This program is distributed in the hope that it will be useful,
23
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
24
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25
+ * GNU Affero General Public License for more details.
26
+ *
27
+ * You should have received a copy of the GNU Affero General Public License
28
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
29
+ *
30
+ */
31
+ var humanList = ['B', 'KB', 'MB', 'GB', 'TB'];
32
+ /**
33
+ * Format a file size in a human-like format. e.g. 42GB
34
+ *
35
+ * @param size in bytes
36
+ * @param skipSmallSizes avoid rendering tiny sizes and return '< 1 KB' instead
37
+ */
38
+ function formatFileSize(size, skipSmallSizes) {
39
+ if (skipSmallSizes === void 0) { skipSmallSizes = false; }
40
+ if (typeof size === 'string') {
41
+ size = Number(size);
42
+ }
43
+ // Calculate Log with base 1024: size = 1024 ** order
44
+ var order = size > 0 ? Math.floor(Math.log(size) / Math.log(1024)) : 0;
45
+ // Stay in range of the byte sizes that are defined
46
+ order = Math.min(humanList.length - 1, order);
47
+ var readableFormat = humanList[order];
48
+ var relativeSize = (size / Math.pow(1024, order)).toFixed(1);
49
+ if (skipSmallSizes === true && order === 0) {
50
+ if (relativeSize !== "0.0") {
51
+ return '< 1 KB';
52
+ }
53
+ else {
54
+ return '0 KB';
55
+ }
56
+ }
57
+ if (order < 2) {
58
+ relativeSize = parseFloat(relativeSize).toFixed(0);
59
+ }
60
+ else if (relativeSize.slice(-2) === '.0') {
61
+ relativeSize = relativeSize.slice(0, -2);
62
+ }
63
+ else {
64
+ relativeSize = parseFloat(relativeSize).toLocaleString(l10n.getCanonicalLocale());
65
+ }
66
+ return relativeSize + ' ' + readableFormat;
67
+ }
68
+
69
+ /**
70
+ * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
71
+ *
72
+ * @author Christoph Wurst <christoph@winzerhof-wurst.at>
73
+ *
74
+ * @license AGPL-3.0-or-later
75
+ *
76
+ * This program is free software: you can redistribute it and/or modify
77
+ * it under the terms of the GNU Affero General Public License as
78
+ * published by the Free Software Foundation, either version 3 of the
79
+ * License, or (at your option) any later version.
80
+ *
81
+ * This program is distributed in the hope that it will be useful,
82
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
83
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
84
+ * GNU Affero General Public License for more details.
85
+ *
86
+ * You should have received a copy of the GNU Affero General Public License
87
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
88
+ *
89
+ */
90
+ var getLogger = function (user) {
91
+ if (user === null) {
92
+ return logger$1.getLoggerBuilder()
93
+ .setApp('files')
94
+ .build();
95
+ }
96
+ return logger$1.getLoggerBuilder()
97
+ .setApp('files')
98
+ .setUid(user.uid)
99
+ .build();
100
+ };
101
+ var logger = getLogger(auth.getCurrentUser());
102
+
103
+ /**
104
+ * @copyright Copyright (c) 2021 John Molakvoæ <skjnldsv@protonmail.com>
105
+ *
106
+ * @author John Molakvoæ <skjnldsv@protonmail.com>
107
+ *
108
+ * @license AGPL-3.0-or-later
109
+ *
110
+ * This program is free software: you can redistribute it and/or modify
111
+ * it under the terms of the GNU Affero General Public License as
112
+ * published by the Free Software Foundation, either version 3 of the
113
+ * License, or (at your option) any later version.
114
+ *
115
+ * This program is distributed in the hope that it will be useful,
116
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
117
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
118
+ * GNU Affero General Public License for more details.
119
+ *
120
+ * You should have received a copy of the GNU Affero General Public License
121
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
122
+ *
123
+ */
124
+ exports.FileType = void 0;
125
+ (function (FileType) {
126
+ FileType["FILE"] = "file";
127
+ FileType["FOLDER"] = "folder";
128
+ })(exports.FileType || (exports.FileType = {}));
129
+ var NewFileMenu = /** @class */ (function () {
130
+ function NewFileMenu() {
131
+ this._entries = [];
132
+ }
133
+ NewFileMenu.prototype.registerEntry = function (entry) {
134
+ this.validateEntry(entry);
135
+ this._entries.push(entry);
136
+ };
137
+ NewFileMenu.prototype.unregisterEntry = function (entry) {
138
+ var entryIndex = typeof entry === 'string'
139
+ ? this.getEntryIndex(entry)
140
+ : this.getEntryIndex(entry.id);
141
+ if (entryIndex === -1) {
142
+ logger.warn('Entry not found, nothing removed', { entry: entry, entries: this.getEntries() });
143
+ return;
144
+ }
145
+ this._entries.splice(entryIndex, 1);
146
+ };
147
+ NewFileMenu.prototype.getEntries = function () {
148
+ return this._entries;
149
+ };
150
+ NewFileMenu.prototype.getEntryIndex = function (id) {
151
+ return this._entries.findIndex(function (entry) { return entry.id === id; });
152
+ };
153
+ NewFileMenu.prototype.validateEntry = function (entry) {
154
+ if (!entry.id || !entry.displayName || !entry.templateName || !(entry.iconSvgInline || entry.iconClass) || !entry.fileType || !entry.handler) {
155
+ throw new Error('Invalid entry');
156
+ }
157
+ if (typeof entry.id !== 'string'
158
+ || typeof entry.displayName !== 'string'
159
+ || typeof entry.templateName !== 'string'
160
+ || (entry.iconClass && typeof entry.iconClass !== 'string')
161
+ || (entry.iconSvgInline && typeof entry.iconSvgInline !== 'string')) {
162
+ throw new Error('Invalid entry');
163
+ }
164
+ if (typeof entry.fileType !== 'string'
165
+ || !(entry.fileType === exports.FileType.FILE || entry.fileType === exports.FileType.FOLDER)) {
166
+ throw new Error('Invalid entry fileType');
167
+ }
168
+ if (typeof entry.handler !== 'function') {
169
+ throw new Error('Invalid entry handler');
170
+ }
171
+ if (this.getEntryIndex(entry.id) !== -1) {
172
+ throw new Error('Duplicate entry');
173
+ }
174
+ };
175
+ return NewFileMenu;
176
+ }());
177
+ var getNewFileMenu = function () {
178
+ if (typeof window._nc_newfilemenu === 'undefined') {
179
+ window._nc_newfilemenu = new NewFileMenu();
180
+ logger.debug('NewFileMenu initialized');
181
+ }
182
+ return window._nc_newfilemenu;
183
+ };
184
+
185
+ /**
186
+ * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
187
+ *
188
+ * @author Christoph Wurst <christoph@winzerhof-wurst.at>
189
+ * @author John Molakvoæ <skjnldsv@protonmail.com>
190
+ *
191
+ * @license AGPL-3.0-or-later
192
+ *
193
+ * This program is free software: you can redistribute it and/or modify
194
+ * it under the terms of the GNU Affero General Public License as
195
+ * published by the Free Software Foundation, either version 3 of the
196
+ * License, or (at your option) any later version.
197
+ *
198
+ * This program is distributed in the hope that it will be useful,
199
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
200
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
201
+ * GNU Affero General Public License for more details.
202
+ *
203
+ * You should have received a copy of the GNU Affero General Public License
204
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
205
+ *
206
+ */
207
+ /**
208
+ * Add a new menu entry to the upload manager menu
209
+ */
210
+ var addNewFileMenuEntry = function (entry) {
211
+ var newFileMenu = getNewFileMenu();
212
+ return newFileMenu.registerEntry(entry);
213
+ };
214
+ /**
215
+ * Remove a previously registered entry from the upload menu
216
+ */
217
+ var removeNewFileMenuEntry = function (entry) {
218
+ var newFileMenu = getNewFileMenu();
219
+ return newFileMenu.unregisterEntry(entry);
220
+ };
221
+ /**
222
+ * Get the list of registered entries from the upload menu
223
+ */
224
+ var getNewFileMenuEntries = function () {
225
+ var newFileMenu = getNewFileMenu();
226
+ return newFileMenu.getEntries();
227
+ };
228
+
229
+ exports.addNewFileMenuEntry = addNewFileMenuEntry;
230
+ exports.formatFileSize = formatFileSize;
231
+ exports.getNewFileMenuEntries = getNewFileMenuEntries;
232
+ exports.removeNewFileMenuEntry = removeNewFileMenuEntry;
233
+ //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../lib/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA","sourcesContent":["export { formatFileSize } from './humanfilesize'\n"],"file":"index.js"}
1
+ {"version":3,"file":"index.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\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\tif (order < 2) {\n\t\trelativeSize = parseFloat(relativeSize).toFixed(0);\n\t} else if (relativeSize.slice(-2) === '.0') {\n\t\trelativeSize = relativeSize.slice(0, -2);\n\t} else {\n\t\trelativeSize = parseFloat(relativeSize).toLocaleString(getCanonicalLocale());\n\t}\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 enum FileType {\n\tFILE = 'file',\n\tFOLDER = 'folder',\n}\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/**\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\tfileType: FileType\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\tpublic getEntries(): Array<Entry> {\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.fileType || !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')\n\t\t}\n\n\t\tif (typeof entry.fileType !== 'string'\n\t\t\t|| !(entry.fileType === FileType.FILE || entry.fileType === FileType.FOLDER)) {\n\t\t\tthrow new Error('Invalid entry fileType')\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 { FileType, 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":["getCanonicalLocale","getLoggerBuilder","getCurrentUser","FileType"],"mappings":";;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;;;AAqBG;AAIH,IAAM,SAAS,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAEhD;;;;;AAKG;AACa,SAAA,cAAc,CAAC,IAAmB,EAAE,cAA+B,EAAA;AAA/B,IAAA,IAAA,cAAA,KAAA,KAAA,CAAA,EAAA,EAAA,cAA+B,GAAA,KAAA,CAAA,EAAA;AAElF,IAAA,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;AAC7B,QAAA,IAAI,G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GAAG,cAAc,EAAE,CAAA;AACpC,IAAA,OAAO,WAAW,CAAC,eAAe,CAAC,KAAK,CAAC,CAAA;AAC1C,EAAC;AAED;;AAEG;AACU,IAAA,qBAAqB,GAAG,YAAA;AACpC,IAAA,IAAM,WAAW,GAAG,cAAc,EAAE,CAAA;AACpC,IAAA,OAAO,WAAW,CAAC,UAAU,EAAE,CAAA;AAChC;;;;;;;"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * @copyright Copyright (c) 2021 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
+ export declare enum FileType {
23
+ FILE = "file",
24
+ FOLDER = "folder"
25
+ }
26
+ export interface Entry {
27
+ /** Unique ID */
28
+ id: string;
29
+ /** Translatable string displayed in the menu */
30
+ displayName: string;
31
+ templateName: string;
32
+ /**
33
+ * Either iconSvgInline or iconClass must be defined
34
+ * Svg as inline string. <svg><path fill="..." /></svg>
35
+ */
36
+ iconSvgInline?: string;
37
+ /** Existing icon css class */
38
+ iconClass?: string;
39
+ fileType: FileType;
40
+ /** Function to be run after creation */
41
+ handler?: Function;
42
+ }
43
+ export declare class NewFileMenu {
44
+ private _entries;
45
+ registerEntry(entry: Entry): void;
46
+ unregisterEntry(entry: Entry | string): void;
47
+ getEntries(): Array<Entry>;
48
+ private getEntryIndex;
49
+ private validateEntry;
50
+ }
51
+ export declare const getNewFileMenu: () => NewFileMenu;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
3
+ *
4
+ * @author Christoph Wurst <christoph@winzerhof-wurst.at>
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
+ declare const _default: import("@nextcloud/logger/dist/contracts").ILogger;
23
+ export default _default;
package/package.json CHANGED
@@ -1,39 +1,71 @@
1
1
  {
2
2
  "name": "@nextcloud/files",
3
- "version": "2.1.0",
4
- "description": "",
3
+ "version": "3.0.0-beta.1",
4
+ "description": "Nextcloud files utils",
5
5
  "main": "dist/index.js",
6
+ "module": "dist/index.esm.js",
6
7
  "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.esm.js",
11
+ "require": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "author": "Christoph Wurst <christoph@winzerhof-wurst.at>",
18
+ "contributors": [
19
+ "John Molakvoæ <skjnldsv@protonmail.com>"
20
+ ],
21
+ "license": "AGPL-3.0-or-later",
22
+ "keywords": [
23
+ "nextcloud",
24
+ "files",
25
+ "library"
26
+ ],
7
27
  "scripts": {
8
- "build": "babel ./lib --out-dir dist --extensions '.ts,.tsx' --source-maps && tsc --emitDeclarationOnly",
28
+ "build": "rollup --config rollup.config.js",
9
29
  "build:doc": "typedoc --out dist/doc lib && touch dist/doc/.nojekyll",
10
- "check-types": "tsc",
11
- "dev": "babel ./lib --out-dir dist --extensions '.ts,.tsx' --watch",
30
+ "dev": "echo 'No dev build available, production only' && npm run build",
31
+ "watch": "rollup --config rollup.config.js --watch",
12
32
  "test": "jest",
13
- "test:watch": "jest --watchAll"
33
+ "test:watch": "jest --watchAll --verbose true",
34
+ "test:coverage": "jest --coverage"
14
35
  },
15
- "keywords": [
16
- "nextcloud"
17
- ],
18
- "author": "Christoph Wurst",
19
- "license": "GPL-3.0-or-later",
20
- "dependencies": {
21
- "@nextcloud/l10n": "^1.3.0",
22
- "core-js": "^3.6.4"
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "https://github.com/nextcloud/nextcloud-files.git"
39
+ },
40
+ "bugs": {
41
+ "url": "https://github.com/nextcloud/nextcloud-files/issues"
23
42
  },
43
+ "engines": {
44
+ "node": "^16.0.0",
45
+ "npm": "^7.0.0 || ^8.0.0"
46
+ },
47
+ "homepage": "https://github.com/nextcloud/nextcloud-files",
24
48
  "devDependencies": {
25
- "@babel/cli": "^7.8.4",
26
- "@babel/core": "^7.8.7",
27
- "@babel/preset-env": "^7.8.7",
28
- "@babel/preset-typescript": "^7.8.3",
29
- "@nextcloud/browserslist-config": "^2.0.0",
30
- "babel-jest": "^27.0.2",
31
- "babel-plugin-transform-class-properties": "^6.24.1",
32
- "jest": "^27.0.4",
33
- "typedoc": "^0.22.4",
34
- "typescript": "^4.0"
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"
35
65
  },
36
- "browserslist": [
37
- "extends @nextcloud/browserslist-config"
38
- ]
66
+ "dependencies": {
67
+ "@nextcloud/auth": "^2.0.0",
68
+ "@nextcloud/l10n": "^1.6.0",
69
+ "@nextcloud/logger": "^2.1.0"
70
+ }
39
71
  }
@@ -1,10 +0,0 @@
1
- version: 2
2
- updates:
3
- - package-ecosystem: npm
4
- directory: "/"
5
- schedule:
6
- interval: weekly
7
- day: saturday
8
- time: "03:00"
9
- timezone: Europe/Paris
10
- open-pull-requests-limit: 10
@@ -1,29 +0,0 @@
1
- # This workflow is provided via the organization template repository
2
- #
3
- # https://github.com/nextcloud/.github
4
- # https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization
5
-
6
- name: Dependabot
7
-
8
- on:
9
- pull_request_target:
10
- branches:
11
- - master
12
- - stable*
13
-
14
- jobs:
15
- auto-approve-merge:
16
- if: github.actor == 'dependabot[bot]'
17
- runs-on: ubuntu-latest
18
-
19
- steps:
20
- # Github actions bot approve
21
- - uses: hmarr/auto-approve-action@v2
22
- with:
23
- github-token: ${{ secrets.GITHUB_TOKEN }}
24
-
25
- # Nextcloud bot approve and merge request
26
- - uses: ahmadnassri/action-dependabot-auto-merge@v2
27
- with:
28
- target: minor
29
- github-token: ${{ secrets.DEPENDABOT_AUTOMERGE_TOKEN }}
package/.travis.yml DELETED
@@ -1,19 +0,0 @@
1
- language: node_js
2
- node_js: node
3
- branches:
4
- only:
5
- - master
6
- - /^v\d++(\.\d+)?+(\.\d+)?+(\.\d+)?$/
7
- script:
8
- - npm run build
9
- - npm run test
10
- - npm run build
11
- - npm run build:doc
12
- deploy:
13
- provider: pages
14
- skip-cleanup: true
15
- github-token: $GITHUB_TOKEN
16
- keep-history: true
17
- local-dir: dist/doc
18
- on:
19
- tags: true
package/CHANGELOG.md DELETED
@@ -1,23 +0,0 @@
1
- # Changelog
2
-
3
- All notable changes to this project will be documented in this file.
4
-
5
- ## 2.1.0 – 2021-09-28
6
- ### Changed
7
- - Dependency updates
8
-
9
- ## 2.0.0 – 2021-04-07
10
- ### Changed
11
- - Browserslist config updated, which means some older browsers are not supported anymore
12
- - Dependency updates
13
-
14
- ## 1.1.0 - 2020-06-04
15
- ### Changed
16
- - formatFileSize works without the global OC
17
- - Dependency updates
18
-
19
- ## 1.0.1 - 2020-03-19
20
- ### Changed
21
- - Dependency updates
22
- ### Fixed
23
- - Update vulnerable packages
package/babel.config.js DELETED
@@ -1,15 +0,0 @@
1
- module.exports = {
2
- presets: [
3
- "@babel/typescript",
4
- [
5
- "@babel/env",
6
- {
7
- useBuiltIns: "usage",
8
- corejs: "3.0.0",
9
- },
10
- ],
11
- ],
12
- "plugins": [
13
- "transform-class-properties",
14
- ],
15
- };
File without changes