@nextcloud/files 3.5.1 → 3.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -6,6 +6,7 @@ import { generateRemoteUrl } from "@nextcloud/router";
6
6
  import { CancelablePromise } from "cancelable-promise";
7
7
  import { createClient, getPatcher } from "webdav";
8
8
  import { isPublicShare, getSharingToken } from "@nextcloud/sharing/public";
9
+ import { getCapabilities } from "@nextcloud/capabilities";
9
10
  import { getCanonicalLocale, getLanguage } from "@nextcloud/l10n";
10
11
  import { TypedEventTarget } from "typescript-event-target";
11
12
  const logger = getLoggerBuilder().setApp("@nextcloud/files").detectUser().build();
@@ -428,6 +429,9 @@ const validateData = (data, davService) => {
428
429
  if (!data.source.startsWith("http")) {
429
430
  throw new Error("Invalid source format, only http(s) is supported");
430
431
  }
432
+ if (data.displayname && typeof data.displayname !== "string") {
433
+ throw new Error("Invalid displayname type");
434
+ }
431
435
  if (data.mtime && !(data.mtime instanceof Date)) {
432
436
  throw new Error("Invalid mtime type");
433
437
  }
@@ -504,7 +508,12 @@ class Node {
504
508
  };
505
509
  constructor(data, davService) {
506
510
  validateData(data, davService || this._knownDavService);
507
- this._data = { ...data, attributes: {} };
511
+ this._data = {
512
+ // TODO: Remove with next major release, this is just for compatibility
513
+ displayname: data.attributes?.displayname,
514
+ ...data,
515
+ attributes: {}
516
+ };
508
517
  this._attributes = new Proxy(this._data.attributes, this.handler);
509
518
  this.update(data.attributes ?? {});
510
519
  if (davService) {
@@ -534,6 +543,21 @@ class Node {
534
543
  get basename() {
535
544
  return basename(this.source);
536
545
  }
546
+ /**
547
+ * The nodes displayname
548
+ * By default the display name and the `basename` are identical,
549
+ * but it is possible to have a different name. This happens
550
+ * on the files app for example for shared folders.
551
+ */
552
+ get displayname() {
553
+ return this._data.displayname || this.basename;
554
+ }
555
+ /**
556
+ * Set the displayname
557
+ */
558
+ set displayname(displayname) {
559
+ this._data.displayname = displayname;
560
+ }
537
561
  /**
538
562
  * Get this object's extension
539
563
  * There is no setter as the source is not meant to be changed manually.
@@ -696,7 +720,11 @@ class Node {
696
720
  */
697
721
  move(destination) {
698
722
  validateData({ ...this._data, source: destination }, this._knownDavService);
723
+ const oldBasename = this.basename;
699
724
  this._data.source = destination;
725
+ if (this.displayname === oldBasename && this.basename !== oldBasename) {
726
+ this.displayname = this.basename;
727
+ }
700
728
  this.updateMtime();
701
729
  }
702
730
  /**
@@ -841,6 +869,8 @@ const davResultToNode = function(node, filesRoot = davRootPath, remoteURL = davR
841
869
  source: `${remoteURL}${node.filename}`,
842
870
  mtime: new Date(Date.parse(node.lastmod)),
843
871
  mime: node.mime || "application/octet-stream",
872
+ // Manually cast to work around for https://github.com/perry-mitchell/webdav-client/pull/380
873
+ displayname: props.displayname !== void 0 ? String(props.displayname) : void 0,
844
874
  size: props?.size || Number.parseInt(props.getcontentlength || "0"),
845
875
  // The fileid is set to -1 for failed requests
846
876
  status: id < 0 ? NodeStatus.FAILED : void 0,
@@ -856,16 +886,81 @@ const davResultToNode = function(node, filesRoot = davRootPath, remoteURL = davR
856
886
  delete nodeData.attributes?.props;
857
887
  return node.type === "file" ? new File(nodeData) : new Folder(nodeData);
858
888
  };
859
- const forbiddenCharacters = window._oc_config?.forbidden_filenames_characters ?? ["/", "\\"];
860
- const forbiddenFilenameRegex = window._oc_config?.blacklist_files_regex ? new RegExp(window._oc_config.blacklist_files_regex) : null;
861
- function isFilenameValid(filename) {
862
- if (forbiddenCharacters.some((character) => filename.includes(character))) {
863
- return false;
889
+ var InvalidFilenameErrorReason = /* @__PURE__ */ ((InvalidFilenameErrorReason2) => {
890
+ InvalidFilenameErrorReason2["ReservedName"] = "reserved name";
891
+ InvalidFilenameErrorReason2["Character"] = "character";
892
+ InvalidFilenameErrorReason2["Extension"] = "extension";
893
+ return InvalidFilenameErrorReason2;
894
+ })(InvalidFilenameErrorReason || {});
895
+ class InvalidFilenameError extends Error {
896
+ constructor(options) {
897
+ super(`Invalid ${options.reason} '${options.segment}' in filename '${options.filename}'`, { cause: options });
864
898
  }
865
- if (forbiddenFilenameRegex !== null && filename.match(forbiddenFilenameRegex)) {
866
- return false;
899
+ /**
900
+ * The filename that was validated
901
+ */
902
+ get filename() {
903
+ return this.cause.filename;
904
+ }
905
+ /**
906
+ * Reason why the validation failed
907
+ */
908
+ get reason() {
909
+ return this.cause.reason;
910
+ }
911
+ /**
912
+ * Part of the filename that caused this error
913
+ */
914
+ get segment() {
915
+ return this.cause.segment;
916
+ }
917
+ }
918
+ function validateFilename(filename) {
919
+ const capabilities = getCapabilities().files;
920
+ const forbiddenCharacters = capabilities.forbidden_filename_characters ?? window._oc_config?.forbidden_filenames_characters ?? ["/", "\\"];
921
+ for (const character of forbiddenCharacters) {
922
+ if (filename.includes(character)) {
923
+ throw new InvalidFilenameError({ segment: character, reason: "character", filename });
924
+ }
925
+ }
926
+ filename = filename.toLocaleLowerCase();
927
+ const forbiddenFilenames = capabilities.forbidden_filenames ?? [".htaccess"];
928
+ if (forbiddenFilenames.includes(filename)) {
929
+ throw new InvalidFilenameError({
930
+ filename,
931
+ segment: filename,
932
+ reason: "reserved name"
933
+ /* ReservedName */
934
+ });
935
+ }
936
+ const endOfBasename = filename.indexOf(".", 1);
937
+ const basename2 = filename.substring(0, endOfBasename === -1 ? void 0 : endOfBasename);
938
+ const forbiddenFilenameBasenames = capabilities.forbidden_filename_basenames ?? [];
939
+ if (forbiddenFilenameBasenames.includes(basename2)) {
940
+ throw new InvalidFilenameError({
941
+ filename,
942
+ segment: basename2,
943
+ reason: "reserved name"
944
+ /* ReservedName */
945
+ });
946
+ }
947
+ const forbiddenFilenameExtensions = capabilities.forbidden_filename_extensions ?? [".part", ".filepart"];
948
+ for (const extension of forbiddenFilenameExtensions) {
949
+ if (filename.length > extension.length && filename.endsWith(extension)) {
950
+ throw new InvalidFilenameError({ segment: extension, reason: "extension", filename });
951
+ }
952
+ }
953
+ }
954
+ function isFilenameValid(filename) {
955
+ try {
956
+ validateFilename(filename);
957
+ return true;
958
+ } catch (error) {
959
+ if (error instanceof InvalidFilenameError) {
960
+ return false;
961
+ }
962
+ throw error;
867
963
  }
868
- return true;
869
964
  }
870
965
  function getUniqueName(name, otherNames, options) {
871
966
  const opts = {
@@ -932,10 +1027,10 @@ function stringify(value) {
932
1027
  }
933
1028
  return String(value);
934
1029
  }
935
- function orderBy(collection, identifiers, orders) {
936
- identifiers = identifiers ?? [(value) => value];
1030
+ function orderBy(collection, identifiers2, orders) {
1031
+ identifiers2 = identifiers2 ?? [(value) => value];
937
1032
  orders = orders ?? [];
938
- const sorting = identifiers.map((_, index) => (orders[index] ?? "asc") === "asc" ? 1 : -1);
1033
+ const sorting = identifiers2.map((_, index) => (orders[index] ?? "asc") === "asc" ? 1 : -1);
939
1034
  const collator = Intl.Collator(
940
1035
  [getLanguage(), getCanonicalLocale()],
941
1036
  {
@@ -945,7 +1040,7 @@ function orderBy(collection, identifiers, orders) {
945
1040
  }
946
1041
  );
947
1042
  return [...collection].sort((a, b) => {
948
- for (const [index, identifier] of identifiers.entries()) {
1043
+ for (const [index, identifier] of identifiers2.entries()) {
949
1044
  const value = collator.compare(stringify(identifier(a)), stringify(identifier(b)));
950
1045
  if (value !== 0) {
951
1046
  return value * sorting[index];
@@ -969,14 +1064,14 @@ function sortNodes(nodes, options = {}) {
969
1064
  ...options
970
1065
  };
971
1066
  const basename2 = (name) => name.lastIndexOf(".") > 0 ? name.slice(0, name.lastIndexOf(".")) : name;
972
- const identifiers = [
1067
+ const identifiers2 = [
973
1068
  // 1: Sort favorites first if enabled
974
1069
  ...sortingOptions.sortFavoritesFirst ? [(v) => v.attributes?.favorite !== 1] : [],
975
1070
  // 2: Sort folders first if sorting by name
976
1071
  ...sortingOptions.sortFoldersFirst ? [(v) => v.type !== "folder"] : [],
977
- // 3: Use sorting mode if NOT basename (to be able to use displayname too)
1072
+ // 3: Use sorting mode if NOT basename (to be able to use display name too)
978
1073
  ...sortingOptions.sortingMode !== "basename" ? [(v) => v[sortingOptions.sortingMode]] : [],
979
- // 4: Use displayname if available, fallback to name
1074
+ // 4: Use display name if available, fallback to name
980
1075
  (v) => basename2(v.attributes?.displayname || v.basename),
981
1076
  // 5: Finally, use basename if all previous sorting methods failed
982
1077
  (v) => v.basename
@@ -995,7 +1090,7 @@ function sortNodes(nodes, options = {}) {
995
1090
  // for 5: use configured sorting direction
996
1091
  sortingOptions.sortingOrder
997
1092
  ];
998
- return orderBy(nodes, identifiers, orders);
1093
+ return orderBy(nodes, identifiers2, orders);
999
1094
  }
1000
1095
  class Navigation extends TypedEventTarget {
1001
1096
  _views = [];
@@ -1093,6 +1188,9 @@ const isValidColumn = function(column) {
1093
1188
  }
1094
1189
  return true;
1095
1190
  };
1191
+ function getDefaultExportFromCjs(x) {
1192
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
1193
+ }
1096
1194
  var validator$2 = {};
1097
1195
  var util$3 = {};
1098
1196
  (function(exports) {
@@ -1286,7 +1384,7 @@ validator$2.validate = function(xmlData, options) {
1286
1384
  } else if (tags.length == 1) {
1287
1385
  return getErrorObject("InvalidTag", "Unclosed tag '" + tags[0].tagName + "'.", getLineNumberForPosition(xmlData, tags[0].tagStartPos));
1288
1386
  } else if (tags.length > 0) {
1289
- return getErrorObject("InvalidXml", "Invalid '" + JSON.stringify(tags.map((t) => t.tagName), null, 4).replace(/\r?\n/g, "") + "' found.", { line: 1, col: 1 });
1387
+ return getErrorObject("InvalidXml", "Invalid '" + JSON.stringify(tags.map((t2) => t2.tagName), null, 4).replace(/\r?\n/g, "") + "' found.", { line: 1, col: 1 });
1290
1388
  }
1291
1389
  return true;
1292
1390
  };
@@ -1396,15 +1494,15 @@ function validateAttributeString(attrStr, options) {
1396
1494
  return true;
1397
1495
  }
1398
1496
  function validateNumberAmpersand(xmlData, i) {
1399
- let re = /\d/;
1497
+ let re2 = /\d/;
1400
1498
  if (xmlData[i] === "x") {
1401
1499
  i++;
1402
- re = /[\da-fA-F]/;
1500
+ re2 = /[\da-fA-F]/;
1403
1501
  }
1404
1502
  for (; i < xmlData.length; i++) {
1405
1503
  if (xmlData[i] === ";")
1406
1504
  return i;
1407
- if (!xmlData[i].match(re))
1505
+ if (!xmlData[i].match(re2))
1408
1506
  break;
1409
1507
  }
1410
1508
  return -1;
@@ -2786,6 +2884,534 @@ const isValidView = function(view) {
2786
2884
  }
2787
2885
  return true;
2788
2886
  };
2887
+ const debug$1 = typeof process === "object" && process.env && process.env.NODE_DEBUG && /\bsemver\b/i.test(process.env.NODE_DEBUG) ? (...args) => console.error("SEMVER", ...args) : () => {
2888
+ };
2889
+ var debug_1 = debug$1;
2890
+ const SEMVER_SPEC_VERSION = "2.0.0";
2891
+ const MAX_LENGTH$1 = 256;
2892
+ const MAX_SAFE_INTEGER$1 = Number.MAX_SAFE_INTEGER || /* istanbul ignore next */
2893
+ 9007199254740991;
2894
+ const MAX_SAFE_COMPONENT_LENGTH = 16;
2895
+ const MAX_SAFE_BUILD_LENGTH = MAX_LENGTH$1 - 6;
2896
+ const RELEASE_TYPES = [
2897
+ "major",
2898
+ "premajor",
2899
+ "minor",
2900
+ "preminor",
2901
+ "patch",
2902
+ "prepatch",
2903
+ "prerelease"
2904
+ ];
2905
+ var constants = {
2906
+ MAX_LENGTH: MAX_LENGTH$1,
2907
+ MAX_SAFE_COMPONENT_LENGTH,
2908
+ MAX_SAFE_BUILD_LENGTH,
2909
+ MAX_SAFE_INTEGER: MAX_SAFE_INTEGER$1,
2910
+ RELEASE_TYPES,
2911
+ SEMVER_SPEC_VERSION,
2912
+ FLAG_INCLUDE_PRERELEASE: 1,
2913
+ FLAG_LOOSE: 2
2914
+ };
2915
+ var re$1 = { exports: {} };
2916
+ (function(module, exports) {
2917
+ const {
2918
+ MAX_SAFE_COMPONENT_LENGTH: MAX_SAFE_COMPONENT_LENGTH2,
2919
+ MAX_SAFE_BUILD_LENGTH: MAX_SAFE_BUILD_LENGTH2,
2920
+ MAX_LENGTH: MAX_LENGTH2
2921
+ } = constants;
2922
+ const debug2 = debug_1;
2923
+ exports = module.exports = {};
2924
+ const re2 = exports.re = [];
2925
+ const safeRe = exports.safeRe = [];
2926
+ const src = exports.src = [];
2927
+ const t2 = exports.t = {};
2928
+ let R = 0;
2929
+ const LETTERDASHNUMBER = "[a-zA-Z0-9-]";
2930
+ const safeRegexReplacements = [
2931
+ ["\\s", 1],
2932
+ ["\\d", MAX_LENGTH2],
2933
+ [LETTERDASHNUMBER, MAX_SAFE_BUILD_LENGTH2]
2934
+ ];
2935
+ const makeSafeRegex = (value) => {
2936
+ for (const [token, max] of safeRegexReplacements) {
2937
+ value = value.split(`${token}*`).join(`${token}{0,${max}}`).split(`${token}+`).join(`${token}{1,${max}}`);
2938
+ }
2939
+ return value;
2940
+ };
2941
+ const createToken = (name, value, isGlobal) => {
2942
+ const safe = makeSafeRegex(value);
2943
+ const index = R++;
2944
+ debug2(name, index, value);
2945
+ t2[name] = index;
2946
+ src[index] = value;
2947
+ re2[index] = new RegExp(value, isGlobal ? "g" : void 0);
2948
+ safeRe[index] = new RegExp(safe, isGlobal ? "g" : void 0);
2949
+ };
2950
+ createToken("NUMERICIDENTIFIER", "0|[1-9]\\d*");
2951
+ createToken("NUMERICIDENTIFIERLOOSE", "\\d+");
2952
+ createToken("NONNUMERICIDENTIFIER", `\\d*[a-zA-Z-]${LETTERDASHNUMBER}*`);
2953
+ createToken("MAINVERSION", `(${src[t2.NUMERICIDENTIFIER]})\\.(${src[t2.NUMERICIDENTIFIER]})\\.(${src[t2.NUMERICIDENTIFIER]})`);
2954
+ createToken("MAINVERSIONLOOSE", `(${src[t2.NUMERICIDENTIFIERLOOSE]})\\.(${src[t2.NUMERICIDENTIFIERLOOSE]})\\.(${src[t2.NUMERICIDENTIFIERLOOSE]})`);
2955
+ createToken("PRERELEASEIDENTIFIER", `(?:${src[t2.NUMERICIDENTIFIER]}|${src[t2.NONNUMERICIDENTIFIER]})`);
2956
+ createToken("PRERELEASEIDENTIFIERLOOSE", `(?:${src[t2.NUMERICIDENTIFIERLOOSE]}|${src[t2.NONNUMERICIDENTIFIER]})`);
2957
+ createToken("PRERELEASE", `(?:-(${src[t2.PRERELEASEIDENTIFIER]}(?:\\.${src[t2.PRERELEASEIDENTIFIER]})*))`);
2958
+ createToken("PRERELEASELOOSE", `(?:-?(${src[t2.PRERELEASEIDENTIFIERLOOSE]}(?:\\.${src[t2.PRERELEASEIDENTIFIERLOOSE]})*))`);
2959
+ createToken("BUILDIDENTIFIER", `${LETTERDASHNUMBER}+`);
2960
+ createToken("BUILD", `(?:\\+(${src[t2.BUILDIDENTIFIER]}(?:\\.${src[t2.BUILDIDENTIFIER]})*))`);
2961
+ createToken("FULLPLAIN", `v?${src[t2.MAINVERSION]}${src[t2.PRERELEASE]}?${src[t2.BUILD]}?`);
2962
+ createToken("FULL", `^${src[t2.FULLPLAIN]}$`);
2963
+ createToken("LOOSEPLAIN", `[v=\\s]*${src[t2.MAINVERSIONLOOSE]}${src[t2.PRERELEASELOOSE]}?${src[t2.BUILD]}?`);
2964
+ createToken("LOOSE", `^${src[t2.LOOSEPLAIN]}$`);
2965
+ createToken("GTLT", "((?:<|>)?=?)");
2966
+ createToken("XRANGEIDENTIFIERLOOSE", `${src[t2.NUMERICIDENTIFIERLOOSE]}|x|X|\\*`);
2967
+ createToken("XRANGEIDENTIFIER", `${src[t2.NUMERICIDENTIFIER]}|x|X|\\*`);
2968
+ createToken("XRANGEPLAIN", `[v=\\s]*(${src[t2.XRANGEIDENTIFIER]})(?:\\.(${src[t2.XRANGEIDENTIFIER]})(?:\\.(${src[t2.XRANGEIDENTIFIER]})(?:${src[t2.PRERELEASE]})?${src[t2.BUILD]}?)?)?`);
2969
+ createToken("XRANGEPLAINLOOSE", `[v=\\s]*(${src[t2.XRANGEIDENTIFIERLOOSE]})(?:\\.(${src[t2.XRANGEIDENTIFIERLOOSE]})(?:\\.(${src[t2.XRANGEIDENTIFIERLOOSE]})(?:${src[t2.PRERELEASELOOSE]})?${src[t2.BUILD]}?)?)?`);
2970
+ createToken("XRANGE", `^${src[t2.GTLT]}\\s*${src[t2.XRANGEPLAIN]}$`);
2971
+ createToken("XRANGELOOSE", `^${src[t2.GTLT]}\\s*${src[t2.XRANGEPLAINLOOSE]}$`);
2972
+ createToken("COERCEPLAIN", `${"(^|[^\\d])(\\d{1,"}${MAX_SAFE_COMPONENT_LENGTH2}})(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH2}}))?(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH2}}))?`);
2973
+ createToken("COERCE", `${src[t2.COERCEPLAIN]}(?:$|[^\\d])`);
2974
+ createToken("COERCEFULL", src[t2.COERCEPLAIN] + `(?:${src[t2.PRERELEASE]})?(?:${src[t2.BUILD]})?(?:$|[^\\d])`);
2975
+ createToken("COERCERTL", src[t2.COERCE], true);
2976
+ createToken("COERCERTLFULL", src[t2.COERCEFULL], true);
2977
+ createToken("LONETILDE", "(?:~>?)");
2978
+ createToken("TILDETRIM", `(\\s*)${src[t2.LONETILDE]}\\s+`, true);
2979
+ exports.tildeTrimReplace = "$1~";
2980
+ createToken("TILDE", `^${src[t2.LONETILDE]}${src[t2.XRANGEPLAIN]}$`);
2981
+ createToken("TILDELOOSE", `^${src[t2.LONETILDE]}${src[t2.XRANGEPLAINLOOSE]}$`);
2982
+ createToken("LONECARET", "(?:\\^)");
2983
+ createToken("CARETTRIM", `(\\s*)${src[t2.LONECARET]}\\s+`, true);
2984
+ exports.caretTrimReplace = "$1^";
2985
+ createToken("CARET", `^${src[t2.LONECARET]}${src[t2.XRANGEPLAIN]}$`);
2986
+ createToken("CARETLOOSE", `^${src[t2.LONECARET]}${src[t2.XRANGEPLAINLOOSE]}$`);
2987
+ createToken("COMPARATORLOOSE", `^${src[t2.GTLT]}\\s*(${src[t2.LOOSEPLAIN]})$|^$`);
2988
+ createToken("COMPARATOR", `^${src[t2.GTLT]}\\s*(${src[t2.FULLPLAIN]})$|^$`);
2989
+ createToken("COMPARATORTRIM", `(\\s*)${src[t2.GTLT]}\\s*(${src[t2.LOOSEPLAIN]}|${src[t2.XRANGEPLAIN]})`, true);
2990
+ exports.comparatorTrimReplace = "$1$2$3";
2991
+ createToken("HYPHENRANGE", `^\\s*(${src[t2.XRANGEPLAIN]})\\s+-\\s+(${src[t2.XRANGEPLAIN]})\\s*$`);
2992
+ createToken("HYPHENRANGELOOSE", `^\\s*(${src[t2.XRANGEPLAINLOOSE]})\\s+-\\s+(${src[t2.XRANGEPLAINLOOSE]})\\s*$`);
2993
+ createToken("STAR", "(<|>)?=?\\s*\\*");
2994
+ createToken("GTE0", "^\\s*>=\\s*0\\.0\\.0\\s*$");
2995
+ createToken("GTE0PRE", "^\\s*>=\\s*0\\.0\\.0-0\\s*$");
2996
+ })(re$1, re$1.exports);
2997
+ var reExports = re$1.exports;
2998
+ const looseOption = Object.freeze({ loose: true });
2999
+ const emptyOpts = Object.freeze({});
3000
+ const parseOptions$1 = (options) => {
3001
+ if (!options) {
3002
+ return emptyOpts;
3003
+ }
3004
+ if (typeof options !== "object") {
3005
+ return looseOption;
3006
+ }
3007
+ return options;
3008
+ };
3009
+ var parseOptions_1 = parseOptions$1;
3010
+ const numeric = /^[0-9]+$/;
3011
+ const compareIdentifiers$1 = (a, b) => {
3012
+ const anum = numeric.test(a);
3013
+ const bnum = numeric.test(b);
3014
+ if (anum && bnum) {
3015
+ a = +a;
3016
+ b = +b;
3017
+ }
3018
+ return a === b ? 0 : anum && !bnum ? -1 : bnum && !anum ? 1 : a < b ? -1 : 1;
3019
+ };
3020
+ const rcompareIdentifiers = (a, b) => compareIdentifiers$1(b, a);
3021
+ var identifiers = {
3022
+ compareIdentifiers: compareIdentifiers$1,
3023
+ rcompareIdentifiers
3024
+ };
3025
+ const debug = debug_1;
3026
+ const { MAX_LENGTH, MAX_SAFE_INTEGER } = constants;
3027
+ const { safeRe: re, t } = reExports;
3028
+ const parseOptions = parseOptions_1;
3029
+ const { compareIdentifiers } = identifiers;
3030
+ let SemVer$2 = class SemVer {
3031
+ constructor(version, options) {
3032
+ options = parseOptions(options);
3033
+ if (version instanceof SemVer) {
3034
+ if (version.loose === !!options.loose && version.includePrerelease === !!options.includePrerelease) {
3035
+ return version;
3036
+ } else {
3037
+ version = version.version;
3038
+ }
3039
+ } else if (typeof version !== "string") {
3040
+ throw new TypeError(`Invalid version. Must be a string. Got type "${typeof version}".`);
3041
+ }
3042
+ if (version.length > MAX_LENGTH) {
3043
+ throw new TypeError(
3044
+ `version is longer than ${MAX_LENGTH} characters`
3045
+ );
3046
+ }
3047
+ debug("SemVer", version, options);
3048
+ this.options = options;
3049
+ this.loose = !!options.loose;
3050
+ this.includePrerelease = !!options.includePrerelease;
3051
+ const m = version.trim().match(options.loose ? re[t.LOOSE] : re[t.FULL]);
3052
+ if (!m) {
3053
+ throw new TypeError(`Invalid Version: ${version}`);
3054
+ }
3055
+ this.raw = version;
3056
+ this.major = +m[1];
3057
+ this.minor = +m[2];
3058
+ this.patch = +m[3];
3059
+ if (this.major > MAX_SAFE_INTEGER || this.major < 0) {
3060
+ throw new TypeError("Invalid major version");
3061
+ }
3062
+ if (this.minor > MAX_SAFE_INTEGER || this.minor < 0) {
3063
+ throw new TypeError("Invalid minor version");
3064
+ }
3065
+ if (this.patch > MAX_SAFE_INTEGER || this.patch < 0) {
3066
+ throw new TypeError("Invalid patch version");
3067
+ }
3068
+ if (!m[4]) {
3069
+ this.prerelease = [];
3070
+ } else {
3071
+ this.prerelease = m[4].split(".").map((id) => {
3072
+ if (/^[0-9]+$/.test(id)) {
3073
+ const num = +id;
3074
+ if (num >= 0 && num < MAX_SAFE_INTEGER) {
3075
+ return num;
3076
+ }
3077
+ }
3078
+ return id;
3079
+ });
3080
+ }
3081
+ this.build = m[5] ? m[5].split(".") : [];
3082
+ this.format();
3083
+ }
3084
+ format() {
3085
+ this.version = `${this.major}.${this.minor}.${this.patch}`;
3086
+ if (this.prerelease.length) {
3087
+ this.version += `-${this.prerelease.join(".")}`;
3088
+ }
3089
+ return this.version;
3090
+ }
3091
+ toString() {
3092
+ return this.version;
3093
+ }
3094
+ compare(other) {
3095
+ debug("SemVer.compare", this.version, this.options, other);
3096
+ if (!(other instanceof SemVer)) {
3097
+ if (typeof other === "string" && other === this.version) {
3098
+ return 0;
3099
+ }
3100
+ other = new SemVer(other, this.options);
3101
+ }
3102
+ if (other.version === this.version) {
3103
+ return 0;
3104
+ }
3105
+ return this.compareMain(other) || this.comparePre(other);
3106
+ }
3107
+ compareMain(other) {
3108
+ if (!(other instanceof SemVer)) {
3109
+ other = new SemVer(other, this.options);
3110
+ }
3111
+ return compareIdentifiers(this.major, other.major) || compareIdentifiers(this.minor, other.minor) || compareIdentifiers(this.patch, other.patch);
3112
+ }
3113
+ comparePre(other) {
3114
+ if (!(other instanceof SemVer)) {
3115
+ other = new SemVer(other, this.options);
3116
+ }
3117
+ if (this.prerelease.length && !other.prerelease.length) {
3118
+ return -1;
3119
+ } else if (!this.prerelease.length && other.prerelease.length) {
3120
+ return 1;
3121
+ } else if (!this.prerelease.length && !other.prerelease.length) {
3122
+ return 0;
3123
+ }
3124
+ let i = 0;
3125
+ do {
3126
+ const a = this.prerelease[i];
3127
+ const b = other.prerelease[i];
3128
+ debug("prerelease compare", i, a, b);
3129
+ if (a === void 0 && b === void 0) {
3130
+ return 0;
3131
+ } else if (b === void 0) {
3132
+ return 1;
3133
+ } else if (a === void 0) {
3134
+ return -1;
3135
+ } else if (a === b) {
3136
+ continue;
3137
+ } else {
3138
+ return compareIdentifiers(a, b);
3139
+ }
3140
+ } while (++i);
3141
+ }
3142
+ compareBuild(other) {
3143
+ if (!(other instanceof SemVer)) {
3144
+ other = new SemVer(other, this.options);
3145
+ }
3146
+ let i = 0;
3147
+ do {
3148
+ const a = this.build[i];
3149
+ const b = other.build[i];
3150
+ debug("build compare", i, a, b);
3151
+ if (a === void 0 && b === void 0) {
3152
+ return 0;
3153
+ } else if (b === void 0) {
3154
+ return 1;
3155
+ } else if (a === void 0) {
3156
+ return -1;
3157
+ } else if (a === b) {
3158
+ continue;
3159
+ } else {
3160
+ return compareIdentifiers(a, b);
3161
+ }
3162
+ } while (++i);
3163
+ }
3164
+ // preminor will bump the version up to the next minor release, and immediately
3165
+ // down to pre-release. premajor and prepatch work the same way.
3166
+ inc(release, identifier, identifierBase) {
3167
+ switch (release) {
3168
+ case "premajor":
3169
+ this.prerelease.length = 0;
3170
+ this.patch = 0;
3171
+ this.minor = 0;
3172
+ this.major++;
3173
+ this.inc("pre", identifier, identifierBase);
3174
+ break;
3175
+ case "preminor":
3176
+ this.prerelease.length = 0;
3177
+ this.patch = 0;
3178
+ this.minor++;
3179
+ this.inc("pre", identifier, identifierBase);
3180
+ break;
3181
+ case "prepatch":
3182
+ this.prerelease.length = 0;
3183
+ this.inc("patch", identifier, identifierBase);
3184
+ this.inc("pre", identifier, identifierBase);
3185
+ break;
3186
+ case "prerelease":
3187
+ if (this.prerelease.length === 0) {
3188
+ this.inc("patch", identifier, identifierBase);
3189
+ }
3190
+ this.inc("pre", identifier, identifierBase);
3191
+ break;
3192
+ case "major":
3193
+ if (this.minor !== 0 || this.patch !== 0 || this.prerelease.length === 0) {
3194
+ this.major++;
3195
+ }
3196
+ this.minor = 0;
3197
+ this.patch = 0;
3198
+ this.prerelease = [];
3199
+ break;
3200
+ case "minor":
3201
+ if (this.patch !== 0 || this.prerelease.length === 0) {
3202
+ this.minor++;
3203
+ }
3204
+ this.patch = 0;
3205
+ this.prerelease = [];
3206
+ break;
3207
+ case "patch":
3208
+ if (this.prerelease.length === 0) {
3209
+ this.patch++;
3210
+ }
3211
+ this.prerelease = [];
3212
+ break;
3213
+ case "pre": {
3214
+ const base = Number(identifierBase) ? 1 : 0;
3215
+ if (!identifier && identifierBase === false) {
3216
+ throw new Error("invalid increment argument: identifier is empty");
3217
+ }
3218
+ if (this.prerelease.length === 0) {
3219
+ this.prerelease = [base];
3220
+ } else {
3221
+ let i = this.prerelease.length;
3222
+ while (--i >= 0) {
3223
+ if (typeof this.prerelease[i] === "number") {
3224
+ this.prerelease[i]++;
3225
+ i = -2;
3226
+ }
3227
+ }
3228
+ if (i === -1) {
3229
+ if (identifier === this.prerelease.join(".") && identifierBase === false) {
3230
+ throw new Error("invalid increment argument: identifier already exists");
3231
+ }
3232
+ this.prerelease.push(base);
3233
+ }
3234
+ }
3235
+ if (identifier) {
3236
+ let prerelease = [identifier, base];
3237
+ if (identifierBase === false) {
3238
+ prerelease = [identifier];
3239
+ }
3240
+ if (compareIdentifiers(this.prerelease[0], identifier) === 0) {
3241
+ if (isNaN(this.prerelease[1])) {
3242
+ this.prerelease = prerelease;
3243
+ }
3244
+ } else {
3245
+ this.prerelease = prerelease;
3246
+ }
3247
+ }
3248
+ break;
3249
+ }
3250
+ default:
3251
+ throw new Error(`invalid increment argument: ${release}`);
3252
+ }
3253
+ this.raw = this.format();
3254
+ if (this.build.length) {
3255
+ this.raw += `+${this.build.join(".")}`;
3256
+ }
3257
+ return this;
3258
+ }
3259
+ };
3260
+ var semver = SemVer$2;
3261
+ const SemVer$1 = semver;
3262
+ const parse$1 = (version, options, throwErrors = false) => {
3263
+ if (version instanceof SemVer$1) {
3264
+ return version;
3265
+ }
3266
+ try {
3267
+ return new SemVer$1(version, options);
3268
+ } catch (er) {
3269
+ if (!throwErrors) {
3270
+ return null;
3271
+ }
3272
+ throw er;
3273
+ }
3274
+ };
3275
+ var parse_1 = parse$1;
3276
+ const parse = parse_1;
3277
+ const valid = (version, options) => {
3278
+ const v = parse(version, options);
3279
+ return v ? v.version : null;
3280
+ };
3281
+ var valid_1 = valid;
3282
+ const valid$1 = /* @__PURE__ */ getDefaultExportFromCjs(valid_1);
3283
+ const SemVer2 = semver;
3284
+ const major = (a, loose) => new SemVer2(a, loose).major;
3285
+ var major_1 = major;
3286
+ const major$1 = /* @__PURE__ */ getDefaultExportFromCjs(major_1);
3287
+ class ProxyBus {
3288
+ bus;
3289
+ constructor(bus2) {
3290
+ if (typeof bus2.getVersion !== "function" || !valid$1(bus2.getVersion())) {
3291
+ console.warn("Proxying an event bus with an unknown or invalid version");
3292
+ } else if (major$1(bus2.getVersion()) !== major$1(this.getVersion())) {
3293
+ console.warn(
3294
+ "Proxying an event bus of version " + bus2.getVersion() + " with " + this.getVersion()
3295
+ );
3296
+ }
3297
+ this.bus = bus2;
3298
+ }
3299
+ getVersion() {
3300
+ return "3.3.1";
3301
+ }
3302
+ subscribe(name, handler) {
3303
+ this.bus.subscribe(name, handler);
3304
+ }
3305
+ unsubscribe(name, handler) {
3306
+ this.bus.unsubscribe(name, handler);
3307
+ }
3308
+ emit(name, event) {
3309
+ this.bus.emit(name, event);
3310
+ }
3311
+ }
3312
+ class SimpleBus {
3313
+ handlers = /* @__PURE__ */ new Map();
3314
+ getVersion() {
3315
+ return "3.3.1";
3316
+ }
3317
+ subscribe(name, handler) {
3318
+ this.handlers.set(
3319
+ name,
3320
+ (this.handlers.get(name) || []).concat(
3321
+ handler
3322
+ )
3323
+ );
3324
+ }
3325
+ unsubscribe(name, handler) {
3326
+ this.handlers.set(
3327
+ name,
3328
+ (this.handlers.get(name) || []).filter((h) => h !== handler)
3329
+ );
3330
+ }
3331
+ emit(name, event) {
3332
+ (this.handlers.get(name) || []).forEach((h) => {
3333
+ try {
3334
+ h(event);
3335
+ } catch (e) {
3336
+ console.error("could not invoke event listener", e);
3337
+ }
3338
+ });
3339
+ }
3340
+ }
3341
+ let bus = null;
3342
+ function getBus() {
3343
+ if (bus !== null) {
3344
+ return bus;
3345
+ }
3346
+ if (typeof window === "undefined") {
3347
+ return new Proxy({}, {
3348
+ get: () => {
3349
+ return () => console.error(
3350
+ "Window not available, EventBus can not be established!"
3351
+ );
3352
+ }
3353
+ });
3354
+ }
3355
+ if (window.OC?._eventBus && typeof window._nc_event_bus === "undefined") {
3356
+ console.warn(
3357
+ "found old event bus instance at OC._eventBus. Update your version!"
3358
+ );
3359
+ window._nc_event_bus = window.OC._eventBus;
3360
+ }
3361
+ if (typeof window?._nc_event_bus !== "undefined") {
3362
+ bus = new ProxyBus(window._nc_event_bus);
3363
+ } else {
3364
+ bus = window._nc_event_bus = new SimpleBus();
3365
+ }
3366
+ return bus;
3367
+ }
3368
+ function emit(name, event) {
3369
+ getBus().emit(name, event);
3370
+ }
3371
+ /*!
3372
+ * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
3373
+ * SPDX-License-Identifier: AGPL-3.0-or-later
3374
+ */
3375
+ class FileListFilter extends TypedEventTarget {
3376
+ id;
3377
+ order;
3378
+ constructor(id, order = 100) {
3379
+ super();
3380
+ this.id = id;
3381
+ this.order = order;
3382
+ }
3383
+ filter(nodes) {
3384
+ throw new Error("Not implemented");
3385
+ }
3386
+ updateChips(chips) {
3387
+ this.dispatchTypedEvent("update:chips", new CustomEvent("update:chips", { detail: chips }));
3388
+ }
3389
+ filterUpdated() {
3390
+ this.dispatchTypedEvent("update:filter", new CustomEvent("update:filter"));
3391
+ }
3392
+ }
3393
+ function registerFileListFilter(filter) {
3394
+ if (!window._nc_filelist_filters) {
3395
+ window._nc_filelist_filters = /* @__PURE__ */ new Map();
3396
+ }
3397
+ if (window._nc_filelist_filters.has(filter.id)) {
3398
+ throw new Error(`File list filter "${filter.id}" already registered`);
3399
+ }
3400
+ window._nc_filelist_filters.set(filter.id, filter);
3401
+ emit("files:filter:added", filter);
3402
+ }
3403
+ function unregisterFileListFilter(filterId) {
3404
+ if (window._nc_filelist_filters && window._nc_filelist_filters.has(filterId)) {
3405
+ window._nc_filelist_filters.delete(filterId);
3406
+ emit("files:filter:removed", filterId);
3407
+ }
3408
+ }
3409
+ function getFileListFilters() {
3410
+ if (!window._nc_filelist_filters) {
3411
+ return [];
3412
+ }
3413
+ return [...window._nc_filelist_filters.values()];
3414
+ }
2789
3415
  const addNewFileMenuEntry = function(entry) {
2790
3416
  const newFileMenu = getNewFileMenu();
2791
3417
  return newFileMenu.registerEntry(entry);
@@ -2808,10 +3434,13 @@ export {
2808
3434
  DefaultType,
2809
3435
  File,
2810
3436
  FileAction,
3437
+ FileListFilter,
2811
3438
  FileType,
2812
3439
  FilesSortingMode,
2813
3440
  Folder,
2814
3441
  Header,
3442
+ InvalidFilenameError,
3443
+ InvalidFilenameErrorReason,
2815
3444
  Navigation,
2816
3445
  NewMenuEntryCategory,
2817
3446
  Node,
@@ -2836,6 +3465,7 @@ export {
2836
3465
  getDavProperties,
2837
3466
  getFavoriteNodes,
2838
3467
  getFileActions,
3468
+ getFileListFilters,
2839
3469
  getFileListHeaders,
2840
3470
  getNavigation,
2841
3471
  getNewFileMenuEntries,
@@ -2845,7 +3475,10 @@ export {
2845
3475
  parseFileSize,
2846
3476
  registerDavProperty,
2847
3477
  registerFileAction,
3478
+ registerFileListFilter,
2848
3479
  registerFileListHeaders,
2849
3480
  removeNewFileMenuEntry,
2850
- sortNodes
3481
+ sortNodes,
3482
+ unregisterFileListFilter,
3483
+ validateFilename
2851
3484
  };