@nextcloud/files 3.9.1 → 3.10.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.
Files changed (39) hide show
  1. package/README.md +63 -26
  2. package/dist/chunks/dav-BBwoJ8WE.cjs +703 -0
  3. package/dist/chunks/dav-BBwoJ8WE.cjs.map +1 -0
  4. package/dist/chunks/dav-DxfiR0wZ.mjs +704 -0
  5. package/dist/chunks/dav-DxfiR0wZ.mjs.map +1 -0
  6. package/dist/dav.cjs +19 -0
  7. package/dist/dav.cjs.map +1 -0
  8. package/dist/dav.d.ts +370 -0
  9. package/dist/dav.mjs +19 -0
  10. package/dist/dav.mjs.map +1 -0
  11. package/dist/index.cjs +99 -709
  12. package/dist/index.cjs.map +1 -1
  13. package/dist/index.d.ts +1099 -40
  14. package/dist/index.mjs +403 -1012
  15. package/dist/index.mjs.map +1 -1
  16. package/package.json +13 -8
  17. package/dist/dav/dav.d.ts +0 -56
  18. package/dist/dav/davPermissions.d.ts +0 -6
  19. package/dist/dav/davProperties.d.ts +0 -57
  20. package/dist/fileAction.d.ts +0 -84
  21. package/dist/fileListFilters.d.ts +0 -90
  22. package/dist/fileListHeaders.d.ts +0 -27
  23. package/dist/files/file.d.ts +0 -16
  24. package/dist/files/fileType.d.ts +0 -8
  25. package/dist/files/folder.d.ts +0 -22
  26. package/dist/files/node.d.ts +0 -174
  27. package/dist/files/nodeData.d.ts +0 -54
  28. package/dist/navigation/column.d.ts +0 -28
  29. package/dist/navigation/index.d.ts +0 -7
  30. package/dist/navigation/navigation.d.ts +0 -74
  31. package/dist/navigation/view.d.ts +0 -92
  32. package/dist/newFileMenu.d.ts +0 -66
  33. package/dist/permissions.d.ts +0 -16
  34. package/dist/utils/fileSize.d.ts +0 -25
  35. package/dist/utils/fileSorting.d.ts +0 -35
  36. package/dist/utils/filename-validation.d.ts +0 -51
  37. package/dist/utils/filename.d.ts +0 -24
  38. package/dist/utils/logger.d.ts +0 -2
  39. package/dist/utils/sorting.d.ts +0 -12
package/README.md CHANGED
@@ -7,70 +7,107 @@
7
7
 
8
8
  Nextcloud Files helpers for Nextcloud apps and libraries.
9
9
 
10
- The `davGetClient` exported function returns a webDAV client that's a wrapper around [webdav's webDAV client](https://www.npmjs.com/package/webdav); All its methods are available here.
10
+ This library provides three kinds of utils:
11
+ 1. WebDAV helper functions to work with the Nextcloud WebDAV interface.
12
+ Those functions are available in `@nextcloud/files/dav`
13
+ 2. Geneal purpose function related to files or folders, like filename validation.
14
+ 3. Functions and classes to interact with the Nextcloud **files** app, like registering a new view or a file action.
11
15
 
12
- ## Usage example
16
+ ## Usage examples
13
17
 
14
- ### Using WebDAV to query favorite nodes
18
+ ### Files app
19
+
20
+ #### Register a "New"-menu entry
21
+
22
+ The "New"-menu allows to create new entries or upload files, it is also possible for other apps to register their own actions here.
23
+
24
+ ```ts
25
+ import type { Entry } from '@nextcloud/files'
26
+ import { addNewFileMenuEntry } from '@nextcloud/files'
27
+ import { t } from '@nextcloud/l10n'
28
+
29
+ const myEntry: Entry = {
30
+ // unique ID of the entry
31
+ id: 'my-app',
32
+ // The display name in the menu
33
+ displayName: t('my-app', 'New something'),
34
+ // optionally pass an SVG (string) to be used as the menu entry icon
35
+ iconSvgInline: importedSVGFile,
36
+ handler(context: Folder, content: Node[]): void {
37
+ // `context` is the current active folder
38
+ // `content` is the content of the currently active folder
39
+ // You can add new files here e.g. use the WebDAV functions to create files.
40
+ // If new content is added, ensure to emit the event-bus signals so the files app can update the list.
41
+ }
42
+ }
43
+
44
+ addNewFileMenuEntry(myEntry)
45
+ ```
46
+
47
+ ### WebDAV
48
+ The `getClient` exported function returns a webDAV client that's a wrapper around [webdav's webDAV client](https://www.npmjs.com/package/webdav).
49
+ All its methods are available here.
50
+
51
+ #### Using WebDAV to query favorite nodes
15
52
 
16
53
  ```ts
17
- import { davGetClient, davRootPath, getFavoriteNodes } from '@nextcloud/files'
54
+ import { getClient, defaultRootPath, getFavoriteNodes } from '@nextcloud/files/dav'
18
55
 
19
- const client = davGetClient()
56
+ const client = getClient()
20
57
  // query favorites for the root folder (meaning all favorites)
21
58
  const favorites = await getFavoriteNodes(client)
22
59
  // which is the same as writing:
23
- const favorites = await getFavoriteNodes(client, '/', davRootPath)
60
+ const favorites = await getFavoriteNodes(client, '/', defaultRootPath)
24
61
  ```
25
62
 
26
- ### Using WebDAV to list all nodes in directory
63
+ #### Using WebDAV to list all nodes in directory
27
64
 
28
65
  ```ts
29
66
  import {
30
- davGetClient,
31
- davGetDefaultPropfind,
32
- davResultToNode,
33
- davRootPath,
34
- davRemoteURL
35
- } from '@nextcloud/files'
67
+ getClient,
68
+ getDefaultPropfind,
69
+ resultToNode,
70
+ defaultRootPath,
71
+ defaultRemoteURL
72
+ } from '@nextcloud/files/dav'
36
73
 
37
74
  // Get the DAV client for the default remote
38
- const client = davGetClient()
75
+ const client = getClient()
39
76
  // which is the same as writing
40
- const client = davGetClient(davRemoteURL)
77
+ const client = getClient(defaultRemoteURL)
41
78
  // of cause you can also configure another WebDAV remote
42
- const client = davGetClient('https://example.com/dav')
79
+ const client = getClient('https://example.com/dav')
43
80
 
44
81
  const path = '/my-folder/' // the directory you want to list
45
82
 
46
83
  // Query the directory content using the webdav library
47
84
  // `davRootPath` is the files root, for Nextcloud this is '/files/USERID', by default the current user is used
48
- const results = client.getDirectoryContents(`${davRootPath}${path}`, {
85
+ const results = client.getDirectoryContents(`${defaultRootPath}${path}`, {
49
86
  details: true,
50
87
  // Query all required properties for a Node
51
- data: davGetDefaultPropfind()
88
+ data: getDefaultPropfind()
52
89
  })
53
90
 
54
91
  // Convert the result to an array of Node
55
- const nodes = results.data.map((result) => davResultToNode(r))
56
- // If you specified a different root in the `getDirectoryContents` you must add this also on the `davResultToNode` call:
57
- const nodes = results.data.map((result) => davResultToNode(r, myRoot))
92
+ const nodes = results.data.map((result) => resultToNode(r))
93
+ // If you specified a different root in the `getDirectoryContents` you must add this also on the `resultToNode` call:
94
+ const nodes = results.data.map((result) => resultToNode(r, myRoot))
58
95
  // Same if you used a different remote URL:
59
- const nodes = results.data.map((result) => davResultToNode(r, myRoot, myRemoteURL))
96
+ const nodes = results.data.map((result) => resultToNode(r, myRoot, myRemoteURL))
60
97
 
61
98
  ```
62
99
 
63
- ### Using WebDAV to get a Node from a file's name
100
+ #### Using WebDAV to get a Node from a file's name
64
101
 
65
102
  ```ts
66
- import { davGetClient, davGetDefaultPropfind, davResultToNode, davRootPath } from '@nextcloud/files'
103
+ import { getClient, davGetDefaultPropfind, resultToNode, davRootPath } from '@nextcloud/files'
67
104
  import { emit } from '@nextcloud/event-bus'
68
- const client = davGetClient()
105
+ const client = getClient()
69
106
  client.stat(`${davRootPath}${filename}`, {
70
107
  details: true,
71
108
  data: davGetDefaultPropfind(),
72
109
  }).then((result) => {
73
- const node = davResultToNode(result.data)
110
+ const node = resultToNode(result.data)
74
111
  emit('files:node:updated', node)
75
112
  })
76
113
  ```