|
4 | 4 | */ |
5 | 5 |
|
6 | 6 | import { loadState } from '@nextcloud/initial-state' |
7 | | -import { getSharingToken } from '@nextcloud/sharing/public' |
8 | | -// eslint-disable-next-line import/no-unresolved, n/no-missing-import |
9 | | -import 'vite/modulepreload-polyfill' |
10 | | - |
11 | | -import { |
12 | | - registerFileActionFallback, |
13 | | - registerFileCreate, |
14 | | -} from './helpers/files.js' |
15 | | -import { logger } from './helpers/logger.js' |
16 | | -import { openMimetypes } from './helpers/mime.js' |
17 | | -import { documentReady } from './helpers/index.js' |
18 | | -import store from './store/index.js' |
19 | | -import { emit, subscribe } from '@nextcloud/event-bus' |
20 | | -import RichWorkspace from './views/RichWorkspace.vue' |
21 | | - |
22 | | -const newRichWorkspaceFileMenuPlugin = { |
23 | | - attach(menu) { |
24 | | - const fileList = menu.fileList |
25 | | - const descriptionFile = t('text', 'Readme') + '.' + loadState('text', 'default_file_extension') |
26 | | - // only attach to main file list, public view is not supported yet |
27 | | - if (fileList.id !== 'files' && fileList.id !== 'files.public') { |
28 | | - return |
29 | | - } |
30 | | - |
31 | | - // register the new menu entry |
32 | | - menu.addMenuEntry({ |
33 | | - id: 'rich-workspace-init', |
34 | | - displayName: t('text', 'Add folder description'), |
35 | | - templateName: descriptionFile, |
36 | | - iconClass: 'icon-add-folder-description', |
37 | | - fileType: 'file', |
38 | | - useInput: false, |
39 | | - actionHandler() { |
40 | | - return window.FileList |
41 | | - .createFile(descriptionFile, { scrollTo: false, animate: false }) |
42 | | - .then(() => emit('Text::showRichWorkspace', { autofocus: true })) |
43 | | - }, |
44 | | - shouldShow() { |
45 | | - return !fileList.findFile(descriptionFile) |
46 | | - }, |
47 | | - }) |
48 | | - }, |
49 | | -} |
50 | | - |
51 | | -const filesWorkspacePlugin = { |
52 | | - el: null, |
53 | | - |
54 | | - attach(fileList) { |
55 | | - if (fileList.id !== 'files' && fileList.id !== 'files.public') { |
56 | | - return |
57 | | - } |
58 | | - this.el = document.createElement('div') |
59 | | - fileList.registerHeader({ |
60 | | - id: 'workspace', |
61 | | - el: this.el, |
62 | | - render: this.render.bind(this), |
63 | | - priority: 10, |
64 | | - }) |
65 | | - }, |
66 | | - |
67 | | - render(fileList) { |
68 | | - if (fileList.id !== 'files' && fileList.id !== 'files.public') { |
69 | | - return |
70 | | - } |
71 | | - |
72 | | - OC.Plugins.register('OCA.Files.NewFileMenu', newRichWorkspaceFileMenuPlugin) |
73 | | - import('vue').then((module) => { |
74 | | - const Vue = module.default |
75 | | - this.el.id = 'files-workspace-wrapper' |
76 | | - Vue.prototype.t = window.t |
77 | | - Vue.prototype.n = window.n |
78 | | - Vue.prototype.OCA = window.OCA |
79 | | - const View = Vue.extend(RichWorkspace) |
80 | | - const vm = new View({ |
81 | | - propsData: { |
82 | | - path: fileList.getCurrentDirectory(), |
83 | | - hasRichWorkspace: true, |
84 | | - }, |
85 | | - store, |
86 | | - }).$mount(this.el) |
87 | | - subscribe('files:navigation:changed', () => { |
88 | | - // Expose if the default file list is active to the component |
89 | | - // to only render the workspace if the file list is actually visible |
90 | | - vm.active = OCA.Files.App.getCurrentFileList() === fileList |
91 | | - }) |
92 | | - fileList.$el.on('urlChanged', data => { |
93 | | - vm.path = data.dir.toString() |
94 | | - }) |
95 | | - fileList.$el.on('changeDirectory', data => { |
96 | | - vm.path = data.dir.toString() |
97 | | - }) |
98 | | - }) |
99 | | - }, |
100 | | -} |
101 | | - |
102 | | -const loadEditor = ({ sharingToken, mimetype, fileId, $el }) => { |
103 | | - const container = document.createElement('div') |
104 | | - container.id = 'texteditor' |
105 | | - |
106 | | - document.getElementById('app-content').appendChild(container) |
107 | | - |
108 | | - Promise.all([ |
109 | | - import(/* webpackChunkName: "vendor" */'vue'), |
110 | | - import(/* webpackChunkName: "editor" */'./components/Editor.vue'), |
111 | | - ]) |
112 | | - .then(([vue, editor]) => ({ |
113 | | - Vue: vue.default, |
114 | | - Editor: editor.default, |
115 | | - })) |
116 | | - .then(({ Vue, Editor }) => { |
117 | | - Vue.prototype.t = window.t |
118 | | - Vue.prototype.OCA = window.OCA |
119 | | - |
120 | | - new Vue({ |
121 | | - render: h => h(Editor, { |
122 | | - props: { |
123 | | - active: true, |
124 | | - shareToken: sharingToken, |
125 | | - mime: mimetype, |
126 | | - fileId, |
127 | | - }, |
128 | | - }), |
129 | | - store, |
130 | | - }) |
131 | | - .$mount($el) |
132 | | - |
133 | | - }) |
134 | | - .catch((error) => logger.error('Failed to attach editor', { error })) |
135 | | -} |
136 | | - |
137 | | -documentReady(() => { |
138 | | - const sharingToken = getSharingToken() |
139 | | - |
140 | | - if (!sharingToken) { |
141 | | - return |
142 | | - } |
143 | | - |
144 | | - const filesTable = document.querySelector('#preview table.files-filestable') |
145 | | - |
146 | | - // list of files - dir sharing |
147 | | - if (filesTable) { |
148 | | - OC.Plugins.register('OCA.Files.FileList', filesWorkspacePlugin) |
149 | | - registerFileActionFallback() |
150 | | - registerFileCreate() |
151 | | - return |
152 | | - } |
153 | | - |
154 | | - // single file share |
155 | | - const mimetype = document.getElementById('mimetype')?.value |
156 | | - if (mimetype && openMimetypes.indexOf(mimetype) !== -1) { |
157 | | - const $el = document.getElementById('preview') |
158 | | - const fileId = loadState('text', 'file_id') |
159 | | - loadEditor({ mimetype, sharingToken, fileId, $el }) |
160 | | - } |
161 | | -}) |
162 | 7 |
|
163 | 8 | OCA.Text = { |
164 | 9 | RichWorkspaceEnabled: loadState('text', 'workspace_available'), |
|
0 commit comments