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ory","NewMenu","entry","entryIndex","logger","context","id","getNewFileMenu","addNewFileMenuEntry","registerFileListHeader","header","validateHeader","TextSvg","addMenuRichWorkspace","descriptionFile","loadState","Permission","content","node","showError","source","response","axios","fileid","file","File","getCurrentUser","showSuccess","emit","FilesHeaderRichWorkspaceApp","FilesHeaderRichWorkspaceView","FilesHeaderRichWorkspaceInstance","FilesHeaderRichWorkspaceState","latestFolder","enabled","_","view","FilesWorkspaceHeader","el","folder","__vitePreload","reactive","createApp","h","workspaceAvailable","registerDavProperty"],"ignoreList":[0,1,2,3,4,5],"sources":["../node_modules/typescript-event-target/dist/index.mjs","../node_modules/@nextcloud/files/dist/ui/registry.mjs","../node_modules/@nextcloud/files/dist/ui/newMenu/NewMenu.mjs","../node_modules/@nextcloud/files/dist/ui/newMenu/functions.mjs","../node_modules/@nextcloud/files/dist/ui/headers/listHeaders.mjs","../node_modules/@mdi/svg/svg/text.svg?raw","../src/helpers/files.js","../src/init.js"],"sourcesContent":["var e=class extends EventTarget{dispatchTypedEvent(s,t){return super.dispatchEvent(t)}};export{e as TypedEventTarget};\n","import { TypedEventTarget } from \"typescript-event-target\";\nimport { scopedGlobals } from \"../globalScope.mjs\";\nclass FilesRegistry extends TypedEventTarget {\n}\nfunction getRegistry() {\n scopedGlobals.registry ??= new FilesRegistry();\n return scopedGlobals.registry;\n}\nfunction getFilesRegistry() {\n return getRegistry();\n}\nexport {\n FilesRegistry,\n getFilesRegistry,\n getRegistry\n};\n//# sourceMappingURL=registry.mjs.map\n","import logger from \"../../utils/logger.mjs\";\nconst NewMenuEntryCategory = Object.freeze({\n /**\n * For actions where the user is intended to upload from their device\n */\n UploadFromDevice: 0,\n /**\n * For actions that create new nodes on the server without uploading\n */\n CreateNew: 1,\n /**\n * For everything not matching the other categories\n */\n Other: 2\n});\nclass NewMenu {\n _entries = [];\n registerEntry(entry) {\n this.validateEntry(entry);\n entry.category = entry.category ?? NewMenuEntryCategory.CreateNew;\n this._entries.push(entry);\n }\n unregisterEntry(entry) {\n const entryIndex = typeof entry === \"string\" ? this.getEntryIndex(entry) : this.getEntryIndex(entry.id);\n if (entryIndex === -1) {\n logger.warn(\"Entry not found, nothing removed\", { entry, entries: this.getEntries() });\n return;\n }\n this._entries.splice(entryIndex, 1);\n }\n /**\n * Get the list of registered entries\n *\n * @param context - The creation context. Usually the current folder\n */\n getEntries(context) {\n if (context) {\n return this._entries.filter((entry) => typeof entry.enabled === \"function\" ? entry.enabled(context) : true);\n }\n return this._entries;\n }\n getEntryIndex(id) {\n return this._entries.findIndex((entry) => entry.id === id);\n }\n validateEntry(entry) {\n if (!entry.id || !entry.displayName || !entry.iconSvgInline || !entry.handler) {\n throw new Error(\"Invalid entry\");\n }\n if (typeof entry.id !== \"string\" || typeof entry.displayName !== \"string\") {\n throw new Error(\"Invalid id or displayName property\");\n }\n if (entry.iconSvgInline && typeof entry.iconSvgInline !== \"string\") {\n throw new Error(\"Invalid icon provided\");\n }\n if (entry.enabled !== void 0 && typeof entry.enabled !== \"function\") {\n throw new Error(\"Invalid enabled property\");\n }\n if (typeof entry.handler !== \"function\") {\n throw new Error(\"Invalid handler property\");\n }\n if (\"order\" in entry && typeof entry.order !== \"number\") {\n throw new Error(\"Invalid order property\");\n }\n if (this.getEntryIndex(entry.id) !== -1) {\n throw new Error(\"Duplicate entry\");\n }\n }\n}\nexport {\n NewMenu,\n NewMenuEntryCategory\n};\n//# sourceMappingURL=NewMenu.mjs.map\n","import { scopedGlobals } from \"../../globalScope.mjs\";\nimport { NewMenu } from \"./NewMenu.mjs\";\nfunction getNewFileMenu() {\n scopedGlobals.newFileMenu ??= new NewMenu();\n return scopedGlobals.newFileMenu;\n}\nfunction addNewFileMenuEntry(entry) {\n const newFileMenu = getNewFileMenu();\n return newFileMenu.registerEntry(entry);\n}\nfunction removeNewFileMenuEntry(entry) {\n const newFileMenu = getNewFileMenu();\n return newFileMenu.unregisterEntry(entry);\n}\nfunction getNewFileMenuEntries(context) {\n const newFileMenu = getNewFileMenu();\n return newFileMenu.getEntries(context).sort((a, b) => {\n if (a.order !== void 0 && b.order !== void 0 && a.order !== b.order) {\n return a.order - b.order;\n }\n return a.displayName.localeCompare(b.displayName, void 0, { numeric: true, sensitivity: \"base\" });\n });\n}\nexport {\n addNewFileMenuEntry,\n getNewFileMenu,\n getNewFileMenuEntries,\n removeNewFileMenuEntry\n};\n//# sourceMappingURL=functions.mjs.map\n","import { scopedGlobals } from \"../../globalScope.mjs\";\nimport logger from \"../../utils/logger.mjs\";\nimport { getRegistry } from \"../registry.mjs\";\nfunction registerFileListHeader(header) {\n validateHeader(header);\n scopedGlobals.fileListHeaders ??= /* @__PURE__ */ new Map();\n if (scopedGlobals.fileListHeaders.has(header.id)) {\n logger.error(`Header ${header.id} already registered`, { header });\n return;\n }\n scopedGlobals.fileListHeaders.set(header.id, header);\n getRegistry().dispatchTypedEvent(\"register:listHeader\", new CustomEvent(\"register:listHeader\", { detail: header }));\n}\nfunction getFileListHeaders() {\n if (!scopedGlobals.fileListHeaders) {\n return [];\n }\n return [...scopedGlobals.fileListHeaders.values()];\n}\nfunction validateHeader(header) {\n if (!header.id || !header.render || !header.updated) {\n throw new Error(\"Invalid header: id, render and updated are required\");\n }\n if (typeof header.id !== \"string\") {\n throw new Error(\"Invalid id property\");\n }\n if (header.enabled !== void 0 && typeof header.enabled !== \"function\") {\n throw new Error(\"Invalid enabled property\");\n }\n if (header.render && typeof header.render !== \"function\") {\n throw new Error(\"Invalid render property\");\n }\n if (header.updated && typeof header.updated !== \"function\") {\n throw new Error(\"Invalid updated property\");\n }\n}\nexport {\n getFileListHeaders,\n registerFileListHeader\n};\n//# sourceMappingURL=listHeaders.mjs.map\n","export default \"\"","/**\n * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\n\nimport TextSvg from '@mdi/svg/svg/text.svg?raw'\nimport { getCurrentUser } from '@nextcloud/auth'\nimport axios from '@nextcloud/axios'\nimport { showError, showSuccess } from '@nextcloud/dialogs'\nimport { emit } from '@nextcloud/event-bus'\nimport {\n\taddNewFileMenuEntry,\n\tFile,\n\tNewMenuEntryCategory,\n\tPermission,\n} from '@nextcloud/files'\nimport { loadState } from '@nextcloud/initial-state'\nimport { t } from '@nextcloud/l10n'\nimport { createApp, h, reactive } from 'vue'\nimport { logger } from './logger.ts'\n\nconst FILE_ACTION_IDENTIFIER = 'Edit with text app'\n\n/**\n *\n */\nexport function addMenuRichWorkspace() {\n\tconst descriptionFile\n\t\t= 'Readme.' + loadState('text', 'default_file_extension')\n\taddNewFileMenuEntry({\n\t\tid: 'rich-workspace-init',\n\t\tdisplayName: t('text', 'Add folder description'),\n\t\tcategory: NewMenuEntryCategory.Other,\n\t\tenabled(context) {\n\t\t\tif (!window?.OCA?.Text?.RichWorkspaceEnabled) {\n\t\t\t\treturn false\n\t\t\t}\n\t\t\tif (Number(context.attributes['rich-workspace-file-flat'])) {\n\t\t\t\treturn false\n\t\t\t}\n\t\t\t// Check read permission to not show option in file drop shares\n\t\t\treturn (\n\t\t\t\t(context.permissions & Permission.READ) !== 0\n\t\t\t\t&& (context.permissions & Permission.CREATE) !== 0\n\t\t\t)\n\t\t},\n\t\ticonSvgInline: TextSvg,\n\t\tasync handler(context, content) {\n\t\t\tconst contentNames = content.map((node) => node.basename)\n\n\t\t\tif (contentNames.includes(descriptionFile)) {\n\t\t\t\tshowError(t('text', '\"{name}\" already exist!', { name: descriptionFile }))\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tconst source\n\t\t\t\t= context.encodedSource + '/' + encodeURIComponent(descriptionFile)\n\t\t\tconst response = await axios({\n\t\t\t\tmethod: 'PUT',\n\t\t\t\turl: source,\n\t\t\t\theaders: {\n\t\t\t\t\tOverwrite: 'F',\n\t\t\t\t},\n\t\t\t})\n\t\t\tconst fileid = parseInt(response.headers['oc-fileid'])\n\t\t\tconst file = new File({\n\t\t\t\tsource: context.source + '/' + descriptionFile,\n\t\t\t\tid: fileid,\n\t\t\t\tmtime: new Date(),\n\t\t\t\tmime: 'text/markdown',\n\t\t\t\towner: getCurrentUser()?.uid || null,\n\t\t\t\tpermissions: Permission.ALL,\n\t\t\t\troot: context?.root || '/files/' + getCurrentUser()?.uid,\n\t\t\t})\n\n\t\t\tshowSuccess(t('text', 'Created \"{name}\"', { name: descriptionFile }))\n\n\t\t\tcontext.attributes['rich-workspace-file-flat'] = fileid\n\t\t\tcontext.attributes['rich-workspace-flat'] = ''\n\n\t\t\temit('files:node:created', file)\n\t\t\temit('files:node:updated', context)\n\t\t},\n\t})\n}\n\nlet FilesHeaderRichWorkspaceApp\nlet FilesHeaderRichWorkspaceView\nlet FilesHeaderRichWorkspaceInstance\nlet FilesHeaderRichWorkspaceState\nlet latestFolder\n\n/**\n * Helper function to check if the workspace header should be enabled\n *\n * @param {object} _ current folder (unused)\n * @param {string} view current view\n */\nfunction enabled(_, view) {\n\treturn ['files', 'favorites', 'public-share', 'personal'].includes(view.id)\n}\n\n/**\n * @type {import('@nexcloud/files').IFileListHeader}\n */\nexport const FilesWorkspaceHeader = {\n\tid: 'workspace',\n\torder: 10,\n\tenabled,\n\n\trender: async (el, folder) => {\n\t\tlatestFolder = folder\n\t\t// Import the RichWorkspace component only when needed\n\t\tif (!FilesHeaderRichWorkspaceView) {\n\t\t\tFilesHeaderRichWorkspaceView = (\n\t\t\t\tawait import('../views/RichWorkspace.vue')\n\t\t\t).default\n\t\t}\n\n\t\t// If an instance already exists, destroy it before creating a new one\n\t\tif (FilesHeaderRichWorkspaceInstance) {\n\t\t\tFilesHeaderRichWorkspaceApp.unmount()\n\t\t\tFilesHeaderRichWorkspaceApp = undefined\n\t\t\tFilesHeaderRichWorkspaceInstance = undefined\n\t\t\tFilesHeaderRichWorkspaceState = undefined\n\t\t\tlogger.debug('Destroying existing FilesHeaderRichWorkspaceInstance')\n\t\t}\n\n\t\tFilesHeaderRichWorkspaceState = reactive({\n\t\t\tcontent: latestFolder.attributes['rich-workspace-flat'] || '',\n\t\t\thasRichWorkspace: !!latestFolder.attributes['rich-workspace-file-flat'],\n\t\t\tpath: latestFolder.path || '',\n\t\t})\n\n\t\t// Create a new instance of the RichWorkspace component\n\t\tFilesHeaderRichWorkspaceApp = createApp({\n\t\t\trender: () => h(FilesHeaderRichWorkspaceView, { ...FilesHeaderRichWorkspaceState }),\n\t\t})\n\t\tFilesHeaderRichWorkspaceInstance = FilesHeaderRichWorkspaceApp.mount(el)\n\t\twindow.FilesHeaderRichWorkspaceInstance = FilesHeaderRichWorkspaceInstance\n\t},\n\n\tupdated(folder, view) {\n\t\tlatestFolder = folder\n\t\tif (!FilesHeaderRichWorkspaceInstance) {\n\t\t\tlogger.error('No vue instance found for FilesWorkspaceHeader')\n\t\t\treturn\n\t\t}\n\n\t\tFilesHeaderRichWorkspaceState.hasRichWorkspace\n\t\t\t= !!folder.attributes['rich-workspace-file-flat'] && enabled(folder, view)\n\t\tFilesHeaderRichWorkspaceState.content\n\t\t\t= folder.attributes['rich-workspace-flat'] || ''\n\t\tFilesHeaderRichWorkspaceState.path = folder.path || ''\n\t},\n}\n\nexport { FILE_ACTION_IDENTIFIER }\n","/**\n * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\n\nimport { registerFileListHeader } from '@nextcloud/files'\nimport { registerDavProperty } from '@nextcloud/files/dav'\nimport { loadState } from '@nextcloud/initial-state'\nimport { addMenuRichWorkspace, FilesWorkspaceHeader } from './helpers/files.js'\n\nimport 'vite/modulepreload-polyfill'\n\nconst workspaceAvailable = loadState('text', 'workspace_available')\n\nregisterDavProperty('nc:rich-workspace-flat', { nc: 'http://nextcloud.org/ns' })\nregisterDavProperty('nc:rich-workspace-file-flat', { nc: 'http://nextcloud.org/ns' })\n\nif (workspaceAvailable) {\n\taddMenuRichWorkspace()\n\tregisterFileListHeader(FilesWorkspaceHeader)\n}\n"],"file":"text-init.mjs"}