@nextcloud/files 4.0.0-beta.9 → 4.0.0-rc.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.mjs CHANGED
@@ -1,798 +1,145 @@
1
+ import { TypedEventTarget } from "typescript-event-target";
1
2
  import { l as logger, F as FileType } from "./chunks/folder-CeyZUHai.mjs";
2
3
  import { a, b, N, c, P } from "./chunks/folder-CeyZUHai.mjs";
3
- import { TypedEventTarget } from "typescript-event-target";
4
4
  import isSvg from "is-svg";
5
5
  import { getCapabilities } from "@nextcloud/capabilities";
6
6
  import { extname, basename } from "@nextcloud/paths";
7
7
  import { getCanonicalLocale, getLanguage } from "@nextcloud/l10n";
8
+ class FilesRegistryV4 extends TypedEventTarget {
9
+ }
10
+ function getRegistry() {
11
+ window._nc_files_registry_v4 ??= new FilesRegistryV4();
12
+ return window._nc_files_registry_v4;
13
+ }
14
+ function getFilesRegistry() {
15
+ return getRegistry();
16
+ }
8
17
  const DefaultType = Object.freeze({
9
18
  DEFAULT: "default",
10
19
  HIDDEN: "hidden"
11
20
  });
12
- class FileAction {
13
- _action;
14
- constructor(action) {
15
- this.validateAction(action);
16
- this._action = action;
17
- }
18
- get id() {
19
- return this._action.id;
20
- }
21
- get displayName() {
22
- return this._action.displayName;
23
- }
24
- get title() {
25
- return this._action.title;
26
- }
27
- get iconSvgInline() {
28
- return this._action.iconSvgInline;
29
- }
30
- get enabled() {
31
- return this._action.enabled;
32
- }
33
- get exec() {
34
- return this._action.exec;
35
- }
36
- get execBatch() {
37
- return this._action.execBatch;
38
- }
39
- get hotkey() {
40
- return this._action.hotkey;
41
- }
42
- get order() {
43
- return this._action.order;
44
- }
45
- get parent() {
46
- return this._action.parent;
47
- }
48
- get default() {
49
- return this._action.default;
50
- }
51
- get destructive() {
52
- return this._action.destructive;
53
- }
54
- get inline() {
55
- return this._action.inline;
56
- }
57
- get renderInline() {
58
- return this._action.renderInline;
59
- }
60
- validateAction(action) {
61
- if (!action.id || typeof action.id !== "string") {
62
- throw new Error("Invalid id");
63
- }
64
- if (!action.displayName || typeof action.displayName !== "function") {
65
- throw new Error("Invalid displayName function");
66
- }
67
- if ("title" in action && typeof action.title !== "function") {
68
- throw new Error("Invalid title function");
69
- }
70
- if (!action.iconSvgInline || typeof action.iconSvgInline !== "function") {
71
- throw new Error("Invalid iconSvgInline function");
72
- }
73
- if (!action.exec || typeof action.exec !== "function") {
74
- throw new Error("Invalid exec function");
75
- }
76
- if ("enabled" in action && typeof action.enabled !== "function") {
77
- throw new Error("Invalid enabled function");
78
- }
79
- if ("execBatch" in action && typeof action.execBatch !== "function") {
80
- throw new Error("Invalid execBatch function");
81
- }
82
- if ("order" in action && typeof action.order !== "number") {
83
- throw new Error("Invalid order");
84
- }
85
- if (action.destructive !== void 0 && typeof action.destructive !== "boolean") {
86
- throw new Error("Invalid destructive flag");
87
- }
88
- if ("parent" in action && typeof action.parent !== "string") {
89
- throw new Error("Invalid parent");
90
- }
91
- if (action.default && !Object.values(DefaultType).includes(action.default)) {
92
- throw new Error("Invalid default");
93
- }
94
- if ("inline" in action && typeof action.inline !== "function") {
95
- throw new Error("Invalid inline function");
96
- }
97
- if ("renderInline" in action && typeof action.renderInline !== "function") {
98
- throw new Error("Invalid renderInline function");
99
- }
100
- if ("hotkey" in action && action.hotkey !== void 0) {
101
- if (typeof action.hotkey !== "object") {
102
- throw new Error("Invalid hotkey configuration");
103
- }
104
- if (typeof action.hotkey.key !== "string" || !action.hotkey.key) {
105
- throw new Error("Missing or invalid hotkey key");
106
- }
107
- if (typeof action.hotkey.description !== "string" || !action.hotkey.description) {
108
- throw new Error("Missing or invalid hotkey description");
109
- }
110
- }
111
- }
112
- }
113
21
  function registerFileAction(action) {
114
- if (typeof window._nc_fileactions === "undefined") {
115
- window._nc_fileactions = [];
116
- logger.debug("FileActions initialized");
117
- }
22
+ validateAction$1(action);
23
+ window._nc_fileactions ??= [];
118
24
  if (window._nc_fileactions.find((search) => search.id === action.id)) {
119
25
  logger.error(`FileAction ${action.id} already registered`, { action });
120
26
  return;
121
27
  }
122
28
  window._nc_fileactions.push(action);
29
+ getRegistry().dispatchTypedEvent("register:action", new CustomEvent("register:action", { detail: action }));
123
30
  }
124
31
  function getFileActions() {
125
- if (typeof window._nc_fileactions === "undefined") {
126
- window._nc_fileactions = [];
127
- logger.debug("FileActions initialized");
128
- }
129
- return window._nc_fileactions;
32
+ return window._nc_fileactions ?? [];
130
33
  }
131
- class FileListAction {
132
- _action;
133
- constructor(action) {
134
- this.validateAction(action);
135
- this._action = action;
34
+ function validateAction$1(action) {
35
+ if (!action.id || typeof action.id !== "string") {
36
+ throw new Error("Invalid id");
136
37
  }
137
- get id() {
138
- return this._action.id;
38
+ if (!action.displayName || typeof action.displayName !== "function") {
39
+ throw new Error("Invalid displayName function");
139
40
  }
140
- get displayName() {
141
- return this._action.displayName;
41
+ if ("title" in action && typeof action.title !== "function") {
42
+ throw new Error("Invalid title function");
142
43
  }
143
- get iconSvgInline() {
144
- return this._action.iconSvgInline;
44
+ if (!action.iconSvgInline || typeof action.iconSvgInline !== "function") {
45
+ throw new Error("Invalid iconSvgInline function");
145
46
  }
146
- get order() {
147
- return this._action.order;
47
+ if (!action.exec || typeof action.exec !== "function") {
48
+ throw new Error("Invalid exec function");
148
49
  }
149
- get enabled() {
150
- return this._action.enabled;
50
+ if ("enabled" in action && typeof action.enabled !== "function") {
51
+ throw new Error("Invalid enabled function");
151
52
  }
152
- get exec() {
153
- return this._action.exec;
53
+ if ("execBatch" in action && typeof action.execBatch !== "function") {
54
+ throw new Error("Invalid execBatch function");
154
55
  }
155
- validateAction(action) {
156
- if (!action.id || typeof action.id !== "string") {
157
- throw new Error("Invalid id");
158
- }
159
- if (!action.displayName || typeof action.displayName !== "function") {
160
- throw new Error("Invalid displayName function");
161
- }
162
- if ("iconSvgInline" in action && typeof action.iconSvgInline !== "function") {
163
- throw new Error("Invalid iconSvgInline function");
164
- }
165
- if ("order" in action && typeof action.order !== "number") {
166
- throw new Error("Invalid order");
56
+ if ("order" in action && typeof action.order !== "number") {
57
+ throw new Error("Invalid order");
58
+ }
59
+ if (action.destructive !== void 0 && typeof action.destructive !== "boolean") {
60
+ throw new Error("Invalid destructive flag");
61
+ }
62
+ if ("parent" in action && typeof action.parent !== "string") {
63
+ throw new Error("Invalid parent");
64
+ }
65
+ if (action.default && !Object.values(DefaultType).includes(action.default)) {
66
+ throw new Error("Invalid default");
67
+ }
68
+ if ("inline" in action && typeof action.inline !== "function") {
69
+ throw new Error("Invalid inline function");
70
+ }
71
+ if ("renderInline" in action && typeof action.renderInline !== "function") {
72
+ throw new Error("Invalid renderInline function");
73
+ }
74
+ if ("hotkey" in action && action.hotkey !== void 0) {
75
+ if (typeof action.hotkey !== "object") {
76
+ throw new Error("Invalid hotkey configuration");
167
77
  }
168
- if ("enabled" in action && typeof action.enabled !== "function") {
169
- throw new Error("Invalid enabled function");
78
+ if (typeof action.hotkey.key !== "string" || !action.hotkey.key) {
79
+ throw new Error("Missing or invalid hotkey key");
170
80
  }
171
- if (!action.exec || typeof action.exec !== "function") {
172
- throw new Error("Invalid exec function");
81
+ if (typeof action.hotkey.description !== "string" || !action.hotkey.description) {
82
+ throw new Error("Missing or invalid hotkey description");
173
83
  }
174
84
  }
175
85
  }
176
86
  function registerFileListAction(action) {
177
- if (typeof window._nc_filelistactions === "undefined") {
178
- window._nc_filelistactions = [];
179
- }
87
+ validateAction(action);
88
+ window._nc_filelistactions ??= [];
180
89
  if (window._nc_filelistactions.find((listAction) => listAction.id === action.id)) {
181
90
  logger.error(`FileListAction with id "${action.id}" is already registered`, { action });
182
91
  return;
183
92
  }
184
93
  window._nc_filelistactions.push(action);
94
+ getRegistry().dispatchTypedEvent("register:listAction", new CustomEvent("register:listAction", { detail: action }));
185
95
  }
186
96
  function getFileListActions() {
187
- if (typeof window._nc_filelistactions === "undefined") {
188
- window._nc_filelistactions = [];
189
- }
190
- return window._nc_filelistactions;
191
- }
192
- function getDefaultExportFromCjs(x) {
193
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
97
+ return [...window._nc_filelistactions ?? []];
194
98
  }
195
- var debug_1;
196
- var hasRequiredDebug;
197
- function requireDebug() {
198
- if (hasRequiredDebug) return debug_1;
199
- hasRequiredDebug = 1;
200
- const debug = typeof process === "object" && process.env && process.env.NODE_DEBUG && /\bsemver\b/i.test(process.env.NODE_DEBUG) ? (...args) => console.error("SEMVER", ...args) : () => {
201
- };
202
- debug_1 = debug;
203
- return debug_1;
204
- }
205
- var constants;
206
- var hasRequiredConstants;
207
- function requireConstants() {
208
- if (hasRequiredConstants) return constants;
209
- hasRequiredConstants = 1;
210
- const SEMVER_SPEC_VERSION = "2.0.0";
211
- const MAX_LENGTH = 256;
212
- const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || /* istanbul ignore next */
213
- 9007199254740991;
214
- const MAX_SAFE_COMPONENT_LENGTH = 16;
215
- const MAX_SAFE_BUILD_LENGTH = MAX_LENGTH - 6;
216
- const RELEASE_TYPES = [
217
- "major",
218
- "premajor",
219
- "minor",
220
- "preminor",
221
- "patch",
222
- "prepatch",
223
- "prerelease"
224
- ];
225
- constants = {
226
- MAX_LENGTH,
227
- MAX_SAFE_COMPONENT_LENGTH,
228
- MAX_SAFE_BUILD_LENGTH,
229
- MAX_SAFE_INTEGER,
230
- RELEASE_TYPES,
231
- SEMVER_SPEC_VERSION,
232
- FLAG_INCLUDE_PRERELEASE: 1,
233
- FLAG_LOOSE: 2
234
- };
235
- return constants;
236
- }
237
- var re = { exports: {} };
238
- var hasRequiredRe;
239
- function requireRe() {
240
- if (hasRequiredRe) return re.exports;
241
- hasRequiredRe = 1;
242
- (function(module, exports) {
243
- const {
244
- MAX_SAFE_COMPONENT_LENGTH,
245
- MAX_SAFE_BUILD_LENGTH,
246
- MAX_LENGTH
247
- } = requireConstants();
248
- const debug = requireDebug();
249
- exports = module.exports = {};
250
- const re2 = exports.re = [];
251
- const safeRe = exports.safeRe = [];
252
- const src = exports.src = [];
253
- const safeSrc = exports.safeSrc = [];
254
- const t = exports.t = {};
255
- let R = 0;
256
- const LETTERDASHNUMBER = "[a-zA-Z0-9-]";
257
- const safeRegexReplacements = [
258
- ["\\s", 1],
259
- ["\\d", MAX_LENGTH],
260
- [LETTERDASHNUMBER, MAX_SAFE_BUILD_LENGTH]
261
- ];
262
- const makeSafeRegex = (value) => {
263
- for (const [token, max] of safeRegexReplacements) {
264
- value = value.split(`${token}*`).join(`${token}{0,${max}}`).split(`${token}+`).join(`${token}{1,${max}}`);
265
- }
266
- return value;
267
- };
268
- const createToken = (name, value, isGlobal) => {
269
- const safe = makeSafeRegex(value);
270
- const index = R++;
271
- debug(name, index, value);
272
- t[name] = index;
273
- src[index] = value;
274
- safeSrc[index] = safe;
275
- re2[index] = new RegExp(value, isGlobal ? "g" : void 0);
276
- safeRe[index] = new RegExp(safe, isGlobal ? "g" : void 0);
277
- };
278
- createToken("NUMERICIDENTIFIER", "0|[1-9]\\d*");
279
- createToken("NUMERICIDENTIFIERLOOSE", "\\d+");
280
- createToken("NONNUMERICIDENTIFIER", `\\d*[a-zA-Z-]${LETTERDASHNUMBER}*`);
281
- createToken("MAINVERSION", `(${src[t.NUMERICIDENTIFIER]})\\.(${src[t.NUMERICIDENTIFIER]})\\.(${src[t.NUMERICIDENTIFIER]})`);
282
- createToken("MAINVERSIONLOOSE", `(${src[t.NUMERICIDENTIFIERLOOSE]})\\.(${src[t.NUMERICIDENTIFIERLOOSE]})\\.(${src[t.NUMERICIDENTIFIERLOOSE]})`);
283
- createToken("PRERELEASEIDENTIFIER", `(?:${src[t.NONNUMERICIDENTIFIER]}|${src[t.NUMERICIDENTIFIER]})`);
284
- createToken("PRERELEASEIDENTIFIERLOOSE", `(?:${src[t.NONNUMERICIDENTIFIER]}|${src[t.NUMERICIDENTIFIERLOOSE]})`);
285
- createToken("PRERELEASE", `(?:-(${src[t.PRERELEASEIDENTIFIER]}(?:\\.${src[t.PRERELEASEIDENTIFIER]})*))`);
286
- createToken("PRERELEASELOOSE", `(?:-?(${src[t.PRERELEASEIDENTIFIERLOOSE]}(?:\\.${src[t.PRERELEASEIDENTIFIERLOOSE]})*))`);
287
- createToken("BUILDIDENTIFIER", `${LETTERDASHNUMBER}+`);
288
- createToken("BUILD", `(?:\\+(${src[t.BUILDIDENTIFIER]}(?:\\.${src[t.BUILDIDENTIFIER]})*))`);
289
- createToken("FULLPLAIN", `v?${src[t.MAINVERSION]}${src[t.PRERELEASE]}?${src[t.BUILD]}?`);
290
- createToken("FULL", `^${src[t.FULLPLAIN]}$`);
291
- createToken("LOOSEPLAIN", `[v=\\s]*${src[t.MAINVERSIONLOOSE]}${src[t.PRERELEASELOOSE]}?${src[t.BUILD]}?`);
292
- createToken("LOOSE", `^${src[t.LOOSEPLAIN]}$`);
293
- createToken("GTLT", "((?:<|>)?=?)");
294
- createToken("XRANGEIDENTIFIERLOOSE", `${src[t.NUMERICIDENTIFIERLOOSE]}|x|X|\\*`);
295
- createToken("XRANGEIDENTIFIER", `${src[t.NUMERICIDENTIFIER]}|x|X|\\*`);
296
- createToken("XRANGEPLAIN", `[v=\\s]*(${src[t.XRANGEIDENTIFIER]})(?:\\.(${src[t.XRANGEIDENTIFIER]})(?:\\.(${src[t.XRANGEIDENTIFIER]})(?:${src[t.PRERELEASE]})?${src[t.BUILD]}?)?)?`);
297
- createToken("XRANGEPLAINLOOSE", `[v=\\s]*(${src[t.XRANGEIDENTIFIERLOOSE]})(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})(?:${src[t.PRERELEASELOOSE]})?${src[t.BUILD]}?)?)?`);
298
- createToken("XRANGE", `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAIN]}$`);
299
- createToken("XRANGELOOSE", `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAINLOOSE]}$`);
300
- createToken("COERCEPLAIN", `${"(^|[^\\d])(\\d{1,"}${MAX_SAFE_COMPONENT_LENGTH}})(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?`);
301
- createToken("COERCE", `${src[t.COERCEPLAIN]}(?:$|[^\\d])`);
302
- createToken("COERCEFULL", src[t.COERCEPLAIN] + `(?:${src[t.PRERELEASE]})?(?:${src[t.BUILD]})?(?:$|[^\\d])`);
303
- createToken("COERCERTL", src[t.COERCE], true);
304
- createToken("COERCERTLFULL", src[t.COERCEFULL], true);
305
- createToken("LONETILDE", "(?:~>?)");
306
- createToken("TILDETRIM", `(\\s*)${src[t.LONETILDE]}\\s+`, true);
307
- exports.tildeTrimReplace = "$1~";
308
- createToken("TILDE", `^${src[t.LONETILDE]}${src[t.XRANGEPLAIN]}$`);
309
- createToken("TILDELOOSE", `^${src[t.LONETILDE]}${src[t.XRANGEPLAINLOOSE]}$`);
310
- createToken("LONECARET", "(?:\\^)");
311
- createToken("CARETTRIM", `(\\s*)${src[t.LONECARET]}\\s+`, true);
312
- exports.caretTrimReplace = "$1^";
313
- createToken("CARET", `^${src[t.LONECARET]}${src[t.XRANGEPLAIN]}$`);
314
- createToken("CARETLOOSE", `^${src[t.LONECARET]}${src[t.XRANGEPLAINLOOSE]}$`);
315
- createToken("COMPARATORLOOSE", `^${src[t.GTLT]}\\s*(${src[t.LOOSEPLAIN]})$|^$`);
316
- createToken("COMPARATOR", `^${src[t.GTLT]}\\s*(${src[t.FULLPLAIN]})$|^$`);
317
- createToken("COMPARATORTRIM", `(\\s*)${src[t.GTLT]}\\s*(${src[t.LOOSEPLAIN]}|${src[t.XRANGEPLAIN]})`, true);
318
- exports.comparatorTrimReplace = "$1$2$3";
319
- createToken("HYPHENRANGE", `^\\s*(${src[t.XRANGEPLAIN]})\\s+-\\s+(${src[t.XRANGEPLAIN]})\\s*$`);
320
- createToken("HYPHENRANGELOOSE", `^\\s*(${src[t.XRANGEPLAINLOOSE]})\\s+-\\s+(${src[t.XRANGEPLAINLOOSE]})\\s*$`);
321
- createToken("STAR", "(<|>)?=?\\s*\\*");
322
- createToken("GTE0", "^\\s*>=\\s*0\\.0\\.0\\s*$");
323
- createToken("GTE0PRE", "^\\s*>=\\s*0\\.0\\.0-0\\s*$");
324
- })(re, re.exports);
325
- return re.exports;
326
- }
327
- var parseOptions_1;
328
- var hasRequiredParseOptions;
329
- function requireParseOptions() {
330
- if (hasRequiredParseOptions) return parseOptions_1;
331
- hasRequiredParseOptions = 1;
332
- const looseOption = Object.freeze({ loose: true });
333
- const emptyOpts = Object.freeze({});
334
- const parseOptions = (options) => {
335
- if (!options) {
336
- return emptyOpts;
337
- }
338
- if (typeof options !== "object") {
339
- return looseOption;
340
- }
341
- return options;
342
- };
343
- parseOptions_1 = parseOptions;
344
- return parseOptions_1;
345
- }
346
- var identifiers;
347
- var hasRequiredIdentifiers;
348
- function requireIdentifiers() {
349
- if (hasRequiredIdentifiers) return identifiers;
350
- hasRequiredIdentifiers = 1;
351
- const numeric = /^[0-9]+$/;
352
- const compareIdentifiers = (a2, b2) => {
353
- if (typeof a2 === "number" && typeof b2 === "number") {
354
- return a2 === b2 ? 0 : a2 < b2 ? -1 : 1;
355
- }
356
- const anum = numeric.test(a2);
357
- const bnum = numeric.test(b2);
358
- if (anum && bnum) {
359
- a2 = +a2;
360
- b2 = +b2;
361
- }
362
- return a2 === b2 ? 0 : anum && !bnum ? -1 : bnum && !anum ? 1 : a2 < b2 ? -1 : 1;
363
- };
364
- const rcompareIdentifiers = (a2, b2) => compareIdentifiers(b2, a2);
365
- identifiers = {
366
- compareIdentifiers,
367
- rcompareIdentifiers
368
- };
369
- return identifiers;
370
- }
371
- var semver;
372
- var hasRequiredSemver;
373
- function requireSemver() {
374
- if (hasRequiredSemver) return semver;
375
- hasRequiredSemver = 1;
376
- const debug = requireDebug();
377
- const { MAX_LENGTH, MAX_SAFE_INTEGER } = requireConstants();
378
- const { safeRe: re2, t } = requireRe();
379
- const parseOptions = requireParseOptions();
380
- const { compareIdentifiers } = requireIdentifiers();
381
- class SemVer {
382
- constructor(version, options) {
383
- options = parseOptions(options);
384
- if (version instanceof SemVer) {
385
- if (version.loose === !!options.loose && version.includePrerelease === !!options.includePrerelease) {
386
- return version;
387
- } else {
388
- version = version.version;
389
- }
390
- } else if (typeof version !== "string") {
391
- throw new TypeError(`Invalid version. Must be a string. Got type "${typeof version}".`);
392
- }
393
- if (version.length > MAX_LENGTH) {
394
- throw new TypeError(
395
- `version is longer than ${MAX_LENGTH} characters`
396
- );
397
- }
398
- debug("SemVer", version, options);
399
- this.options = options;
400
- this.loose = !!options.loose;
401
- this.includePrerelease = !!options.includePrerelease;
402
- const m = version.trim().match(options.loose ? re2[t.LOOSE] : re2[t.FULL]);
403
- if (!m) {
404
- throw new TypeError(`Invalid Version: ${version}`);
405
- }
406
- this.raw = version;
407
- this.major = +m[1];
408
- this.minor = +m[2];
409
- this.patch = +m[3];
410
- if (this.major > MAX_SAFE_INTEGER || this.major < 0) {
411
- throw new TypeError("Invalid major version");
412
- }
413
- if (this.minor > MAX_SAFE_INTEGER || this.minor < 0) {
414
- throw new TypeError("Invalid minor version");
415
- }
416
- if (this.patch > MAX_SAFE_INTEGER || this.patch < 0) {
417
- throw new TypeError("Invalid patch version");
418
- }
419
- if (!m[4]) {
420
- this.prerelease = [];
421
- } else {
422
- this.prerelease = m[4].split(".").map((id) => {
423
- if (/^[0-9]+$/.test(id)) {
424
- const num = +id;
425
- if (num >= 0 && num < MAX_SAFE_INTEGER) {
426
- return num;
427
- }
428
- }
429
- return id;
430
- });
431
- }
432
- this.build = m[5] ? m[5].split(".") : [];
433
- this.format();
434
- }
435
- format() {
436
- this.version = `${this.major}.${this.minor}.${this.patch}`;
437
- if (this.prerelease.length) {
438
- this.version += `-${this.prerelease.join(".")}`;
439
- }
440
- return this.version;
441
- }
442
- toString() {
443
- return this.version;
444
- }
445
- compare(other) {
446
- debug("SemVer.compare", this.version, this.options, other);
447
- if (!(other instanceof SemVer)) {
448
- if (typeof other === "string" && other === this.version) {
449
- return 0;
450
- }
451
- other = new SemVer(other, this.options);
452
- }
453
- if (other.version === this.version) {
454
- return 0;
455
- }
456
- return this.compareMain(other) || this.comparePre(other);
457
- }
458
- compareMain(other) {
459
- if (!(other instanceof SemVer)) {
460
- other = new SemVer(other, this.options);
461
- }
462
- if (this.major < other.major) {
463
- return -1;
464
- }
465
- if (this.major > other.major) {
466
- return 1;
467
- }
468
- if (this.minor < other.minor) {
469
- return -1;
470
- }
471
- if (this.minor > other.minor) {
472
- return 1;
473
- }
474
- if (this.patch < other.patch) {
475
- return -1;
476
- }
477
- if (this.patch > other.patch) {
478
- return 1;
479
- }
480
- return 0;
481
- }
482
- comparePre(other) {
483
- if (!(other instanceof SemVer)) {
484
- other = new SemVer(other, this.options);
485
- }
486
- if (this.prerelease.length && !other.prerelease.length) {
487
- return -1;
488
- } else if (!this.prerelease.length && other.prerelease.length) {
489
- return 1;
490
- } else if (!this.prerelease.length && !other.prerelease.length) {
491
- return 0;
492
- }
493
- let i = 0;
494
- do {
495
- const a2 = this.prerelease[i];
496
- const b2 = other.prerelease[i];
497
- debug("prerelease compare", i, a2, b2);
498
- if (a2 === void 0 && b2 === void 0) {
499
- return 0;
500
- } else if (b2 === void 0) {
501
- return 1;
502
- } else if (a2 === void 0) {
503
- return -1;
504
- } else if (a2 === b2) {
505
- continue;
506
- } else {
507
- return compareIdentifiers(a2, b2);
508
- }
509
- } while (++i);
510
- }
511
- compareBuild(other) {
512
- if (!(other instanceof SemVer)) {
513
- other = new SemVer(other, this.options);
514
- }
515
- let i = 0;
516
- do {
517
- const a2 = this.build[i];
518
- const b2 = other.build[i];
519
- debug("build compare", i, a2, b2);
520
- if (a2 === void 0 && b2 === void 0) {
521
- return 0;
522
- } else if (b2 === void 0) {
523
- return 1;
524
- } else if (a2 === void 0) {
525
- return -1;
526
- } else if (a2 === b2) {
527
- continue;
528
- } else {
529
- return compareIdentifiers(a2, b2);
530
- }
531
- } while (++i);
532
- }
533
- // preminor will bump the version up to the next minor release, and immediately
534
- // down to pre-release. premajor and prepatch work the same way.
535
- inc(release, identifier, identifierBase) {
536
- if (release.startsWith("pre")) {
537
- if (!identifier && identifierBase === false) {
538
- throw new Error("invalid increment argument: identifier is empty");
539
- }
540
- if (identifier) {
541
- const match = `-${identifier}`.match(this.options.loose ? re2[t.PRERELEASELOOSE] : re2[t.PRERELEASE]);
542
- if (!match || match[1] !== identifier) {
543
- throw new Error(`invalid identifier: ${identifier}`);
544
- }
545
- }
546
- }
547
- switch (release) {
548
- case "premajor":
549
- this.prerelease.length = 0;
550
- this.patch = 0;
551
- this.minor = 0;
552
- this.major++;
553
- this.inc("pre", identifier, identifierBase);
554
- break;
555
- case "preminor":
556
- this.prerelease.length = 0;
557
- this.patch = 0;
558
- this.minor++;
559
- this.inc("pre", identifier, identifierBase);
560
- break;
561
- case "prepatch":
562
- this.prerelease.length = 0;
563
- this.inc("patch", identifier, identifierBase);
564
- this.inc("pre", identifier, identifierBase);
565
- break;
566
- // If the input is a non-prerelease version, this acts the same as
567
- // prepatch.
568
- case "prerelease":
569
- if (this.prerelease.length === 0) {
570
- this.inc("patch", identifier, identifierBase);
571
- }
572
- this.inc("pre", identifier, identifierBase);
573
- break;
574
- case "release":
575
- if (this.prerelease.length === 0) {
576
- throw new Error(`version ${this.raw} is not a prerelease`);
577
- }
578
- this.prerelease.length = 0;
579
- break;
580
- case "major":
581
- if (this.minor !== 0 || this.patch !== 0 || this.prerelease.length === 0) {
582
- this.major++;
583
- }
584
- this.minor = 0;
585
- this.patch = 0;
586
- this.prerelease = [];
587
- break;
588
- case "minor":
589
- if (this.patch !== 0 || this.prerelease.length === 0) {
590
- this.minor++;
591
- }
592
- this.patch = 0;
593
- this.prerelease = [];
594
- break;
595
- case "patch":
596
- if (this.prerelease.length === 0) {
597
- this.patch++;
598
- }
599
- this.prerelease = [];
600
- break;
601
- // This probably shouldn't be used publicly.
602
- // 1.0.0 'pre' would become 1.0.0-0 which is the wrong direction.
603
- case "pre": {
604
- const base = Number(identifierBase) ? 1 : 0;
605
- if (this.prerelease.length === 0) {
606
- this.prerelease = [base];
607
- } else {
608
- let i = this.prerelease.length;
609
- while (--i >= 0) {
610
- if (typeof this.prerelease[i] === "number") {
611
- this.prerelease[i]++;
612
- i = -2;
613
- }
614
- }
615
- if (i === -1) {
616
- if (identifier === this.prerelease.join(".") && identifierBase === false) {
617
- throw new Error("invalid increment argument: identifier already exists");
618
- }
619
- this.prerelease.push(base);
620
- }
621
- }
622
- if (identifier) {
623
- let prerelease = [identifier, base];
624
- if (identifierBase === false) {
625
- prerelease = [identifier];
626
- }
627
- if (compareIdentifiers(this.prerelease[0], identifier) === 0) {
628
- if (isNaN(this.prerelease[1])) {
629
- this.prerelease = prerelease;
630
- }
631
- } else {
632
- this.prerelease = prerelease;
633
- }
634
- }
635
- break;
636
- }
637
- default:
638
- throw new Error(`invalid increment argument: ${release}`);
639
- }
640
- this.raw = this.format();
641
- if (this.build.length) {
642
- this.raw += `+${this.build.join(".")}`;
643
- }
644
- return this;
645
- }
99
+ function validateAction(action) {
100
+ if (!action.id || typeof action.id !== "string") {
101
+ throw new Error("Invalid id");
646
102
  }
647
- semver = SemVer;
648
- return semver;
649
- }
650
- var major_1;
651
- var hasRequiredMajor;
652
- function requireMajor() {
653
- if (hasRequiredMajor) return major_1;
654
- hasRequiredMajor = 1;
655
- const SemVer = requireSemver();
656
- const major2 = (a2, loose) => new SemVer(a2, loose).major;
657
- major_1 = major2;
658
- return major_1;
659
- }
660
- var majorExports = requireMajor();
661
- const major = /* @__PURE__ */ getDefaultExportFromCjs(majorExports);
662
- var parse_1;
663
- var hasRequiredParse;
664
- function requireParse() {
665
- if (hasRequiredParse) return parse_1;
666
- hasRequiredParse = 1;
667
- const SemVer = requireSemver();
668
- const parse = (version, options, throwErrors = false) => {
669
- if (version instanceof SemVer) {
670
- return version;
671
- }
672
- try {
673
- return new SemVer(version, options);
674
- } catch (er) {
675
- if (!throwErrors) {
676
- return null;
677
- }
678
- throw er;
679
- }
680
- };
681
- parse_1 = parse;
682
- return parse_1;
683
- }
684
- var valid_1;
685
- var hasRequiredValid;
686
- function requireValid() {
687
- if (hasRequiredValid) return valid_1;
688
- hasRequiredValid = 1;
689
- const parse = requireParse();
690
- const valid2 = (version, options) => {
691
- const v = parse(version, options);
692
- return v ? v.version : null;
693
- };
694
- valid_1 = valid2;
695
- return valid_1;
696
- }
697
- var validExports = requireValid();
698
- const valid = /* @__PURE__ */ getDefaultExportFromCjs(validExports);
699
- /*!
700
- * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
701
- * SPDX-License-Identifier: GPL-3.0-or-later
702
- */
703
- class ProxyBus {
704
- bus;
705
- constructor(bus2) {
706
- if (typeof bus2.getVersion !== "function" || !valid(bus2.getVersion())) {
707
- console.warn("Proxying an event bus with an unknown or invalid version");
708
- } else if (major(bus2.getVersion()) !== major(this.getVersion())) {
709
- console.warn(
710
- "Proxying an event bus of version " + bus2.getVersion() + " with " + this.getVersion()
711
- );
712
- }
713
- this.bus = bus2;
103
+ if (!action.displayName || typeof action.displayName !== "function") {
104
+ throw new Error("Invalid displayName function");
714
105
  }
715
- getVersion() {
716
- return "3.3.3";
106
+ if ("iconSvgInline" in action && typeof action.iconSvgInline !== "function") {
107
+ throw new Error("Invalid iconSvgInline function");
717
108
  }
718
- subscribe(name, handler) {
719
- this.bus.subscribe(name, handler);
109
+ if ("order" in action && typeof action.order !== "number") {
110
+ throw new Error("Invalid order");
720
111
  }
721
- unsubscribe(name, handler) {
722
- this.bus.unsubscribe(name, handler);
112
+ if ("enabled" in action && typeof action.enabled !== "function") {
113
+ throw new Error("Invalid enabled function");
723
114
  }
724
- emit(name, ...event) {
725
- this.bus.emit(name, ...event);
115
+ if (!action.exec || typeof action.exec !== "function") {
116
+ throw new Error("Invalid exec function");
726
117
  }
727
118
  }
728
119
  /*!
729
- * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
730
- * SPDX-License-Identifier: GPL-3.0-or-later
120
+ * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
121
+ * SPDX-License-Identifier: AGPL-3.0-or-later
731
122
  */
732
- class SimpleBus {
733
- handlers = /* @__PURE__ */ new Map();
734
- getVersion() {
735
- return "3.3.3";
736
- }
737
- subscribe(name, handler) {
738
- this.handlers.set(
739
- name,
740
- (this.handlers.get(name) || []).concat(
741
- handler
742
- )
743
- );
744
- }
745
- unsubscribe(name, handler) {
746
- this.handlers.set(
747
- name,
748
- (this.handlers.get(name) || []).filter((h) => h !== handler)
749
- );
750
- }
751
- emit(name, ...event) {
752
- const handlers = this.handlers.get(name) || [];
753
- handlers.forEach((h) => {
754
- try {
755
- ;
756
- h(event[0]);
757
- } catch (e) {
758
- console.error("could not invoke event listener", e);
759
- }
760
- });
123
+ function registerFileListFilter(filter) {
124
+ window._nc_filelist_filters ??= /* @__PURE__ */ new Map();
125
+ if (window._nc_filelist_filters.has(filter.id)) {
126
+ throw new Error(`File list filter "${filter.id}" already registered`);
761
127
  }
128
+ window._nc_filelist_filters.set(filter.id, filter);
129
+ getRegistry().dispatchTypedEvent("register:listFilter", new CustomEvent("register:listFilter", { detail: filter }));
762
130
  }
763
- /*!
764
- * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
765
- * SPDX-License-Identifier: GPL-3.0-or-later
766
- */
767
- let bus = null;
768
- function getBus() {
769
- if (bus !== null) {
770
- return bus;
771
- }
772
- if (typeof window === "undefined") {
773
- return new Proxy({}, {
774
- get: () => {
775
- return () => console.error(
776
- "Window not available, EventBus can not be established!"
777
- );
778
- }
779
- });
780
- }
781
- if (window.OC?._eventBus && typeof window._nc_event_bus === "undefined") {
782
- console.warn(
783
- "found old event bus instance at OC._eventBus. Update your version!"
784
- );
785
- window._nc_event_bus = window.OC._eventBus;
786
- }
787
- if (typeof window?._nc_event_bus !== "undefined") {
788
- bus = new ProxyBus(window._nc_event_bus);
789
- } else {
790
- bus = window._nc_event_bus = new SimpleBus();
131
+ function unregisterFileListFilter(filterId) {
132
+ if (window._nc_filelist_filters && window._nc_filelist_filters.has(filterId)) {
133
+ const filter = window._nc_filelist_filters.get(filterId);
134
+ window._nc_filelist_filters.delete(filterId);
135
+ getRegistry().dispatchTypedEvent("unregister:listFilter", new CustomEvent("unregister:listFilter", { detail: filter }));
791
136
  }
792
- return bus;
793
137
  }
794
- function emit(name, ...event) {
795
- getBus().emit(name, ...event);
138
+ function getFileListFilters() {
139
+ if (!window._nc_filelist_filters) {
140
+ return [];
141
+ }
142
+ return [...window._nc_filelist_filters.values()];
796
143
  }
797
144
  /*!
798
145
  * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
@@ -816,28 +163,6 @@ class FileListFilter extends TypedEventTarget {
816
163
  this.dispatchTypedEvent("update:filter", new CustomEvent("update:filter"));
817
164
  }
818
165
  }
819
- function registerFileListFilter(filter) {
820
- if (!window._nc_filelist_filters) {
821
- window._nc_filelist_filters = /* @__PURE__ */ new Map();
822
- }
823
- if (window._nc_filelist_filters.has(filter.id)) {
824
- throw new Error(`File list filter "${filter.id}" already registered`);
825
- }
826
- window._nc_filelist_filters.set(filter.id, filter);
827
- emit("files:filter:added", filter);
828
- }
829
- function unregisterFileListFilter(filterId) {
830
- if (window._nc_filelist_filters && window._nc_filelist_filters.has(filterId)) {
831
- window._nc_filelist_filters.delete(filterId);
832
- emit("files:filter:removed", filterId);
833
- }
834
- }
835
- function getFileListFilters() {
836
- if (!window._nc_filelist_filters) {
837
- return [];
838
- }
839
- return [...window._nc_filelist_filters.values()];
840
- }
841
166
  class Header {
842
167
  _header;
843
168
  constructor(header) {
@@ -887,6 +212,7 @@ function registerFileListHeaders(header) {
887
212
  return;
888
213
  }
889
214
  window._nc_filelistheader.push(header);
215
+ getRegistry().dispatchTypedEvent("register:listHeader", new CustomEvent("register:listHeader", { detail: header }));
890
216
  }
891
217
  function getFileListHeaders() {
892
218
  if (typeof window._nc_filelistheader === "undefined") {
@@ -1056,16 +382,18 @@ class Navigation extends TypedEventTarget {
1056
382
  /**
1057
383
  * Register a new view on the navigation
1058
384
  *
1059
- * @param view The view to register
385
+ * @param views The views to register
1060
386
  * @throws {Error} if a view with the same id is already registered
1061
387
  * @throws {Error} if the registered view is invalid
1062
388
  */
1063
- register(view) {
1064
- if (this._views.find((search) => search.id === view.id)) {
1065
- throw new Error(`IView id ${view.id} is already registered`);
389
+ register(...views) {
390
+ for (const view of views) {
391
+ if (this._views.find((search) => search.id === view.id)) {
392
+ throw new Error(`IView id ${view.id} is already registered`);
393
+ }
394
+ validateView(view);
1066
395
  }
1067
- validateView(view);
1068
- this._views.push(view);
396
+ this._views.push(...views);
1069
397
  this.dispatchTypedEvent("update", new CustomEvent("update"));
1070
398
  }
1071
399
  /**
@@ -1274,7 +602,7 @@ function validateSidebarTab(tab) {
1274
602
  throw new Error("Sidebar tabs need to have the tagName name set");
1275
603
  }
1276
604
  if (!tab.tagName.match(/^[a-z][a-z0-9-_]+$/)) {
1277
- throw new Error("Sidebar tabs tagName name is invalid");
605
+ throw new Error('Sidebar tab "tagName" is invalid');
1278
606
  }
1279
607
  if (!tab.displayName || typeof tab.displayName !== "string") {
1280
608
  throw new Error("Sidebar tabs need to have a name set");
@@ -1285,8 +613,11 @@ function validateSidebarTab(tab) {
1285
613
  if (typeof tab.order !== "number") {
1286
614
  throw new Error("Sidebar tabs need to have a numeric order set");
1287
615
  }
1288
- if (typeof tab.enabled !== "function") {
1289
- throw new Error('Sidebar tabs need to have an "enabled" method');
616
+ if (tab.enabled && typeof tab.enabled !== "function") {
617
+ throw new Error('Sidebar tab "enabled" is not a function');
618
+ }
619
+ if (tab.onInit && typeof tab.onInit !== "function") {
620
+ throw new Error('Sidebar tab "onInit" is not a function');
1290
621
  }
1291
622
  }
1292
623
  class SidebarProxy {
@@ -1460,10 +791,10 @@ function stringify(value) {
1460
791
  }
1461
792
  return String(value);
1462
793
  }
1463
- function orderBy(collection, identifiers2, orders) {
1464
- identifiers2 = identifiers2 ?? [(value) => value];
794
+ function orderBy(collection, identifiers, orders) {
795
+ identifiers = identifiers ?? [(value) => value];
1465
796
  orders = orders ?? [];
1466
- const sorting = identifiers2.map((_, index) => (orders[index] ?? "asc") === "asc" ? 1 : -1);
797
+ const sorting = identifiers.map((_, index) => (orders[index] ?? "asc") === "asc" ? 1 : -1);
1467
798
  const collator = Intl.Collator(
1468
799
  [getLanguage(), getCanonicalLocale()],
1469
800
  {
@@ -1473,7 +804,7 @@ function orderBy(collection, identifiers2, orders) {
1473
804
  }
1474
805
  );
1475
806
  return [...collection].sort((a2, b2) => {
1476
- for (const [index, identifier] of identifiers2.entries()) {
807
+ for (const [index, identifier] of identifiers.entries()) {
1477
808
  const value = collator.compare(stringify(identifier(a2)), stringify(identifier(b2)));
1478
809
  if (value !== 0) {
1479
810
  return value * sorting[index];
@@ -1502,7 +833,7 @@ function sortNodes(nodes, options = {}) {
1502
833
  }
1503
834
  return name.lastIndexOf(".") > 0 ? name.slice(0, name.lastIndexOf(".")) : name;
1504
835
  }
1505
- const identifiers2 = [
836
+ const identifiers = [
1506
837
  // 1: Sort favorites first if enabled
1507
838
  ...sortingOptions.sortFavoritesFirst ? [(v) => v.attributes?.favorite !== 1] : [],
1508
839
  // 2: Sort folders first if sorting by name
@@ -1528,14 +859,12 @@ function sortNodes(nodes, options = {}) {
1528
859
  // for 5: use configured sorting direction
1529
860
  sortingOptions.sortingOrder
1530
861
  ];
1531
- return orderBy(nodes, identifiers2, orders);
862
+ return orderBy(nodes, identifiers, orders);
1532
863
  }
1533
864
  export {
1534
865
  Column,
1535
866
  DefaultType,
1536
867
  a as File,
1537
- FileAction,
1538
- FileListAction,
1539
868
  FileListFilter,
1540
869
  FileType,
1541
870
  FilesSortingMode,
@@ -1555,6 +884,7 @@ export {
1555
884
  getFileListActions,
1556
885
  getFileListFilters,
1557
886
  getFileListHeaders,
887
+ getFilesRegistry,
1558
888
  getNavigation,
1559
889
  getNewFileMenu,
1560
890
  getNewFileMenuEntries,