Skip to content

Commit a467d56

Browse files
fix(files): Add text-init script to the files sharing listener
Signed-off-by: julia.kirschenheuter <julia.kirschenheuter@nextcloud.com>
1 parent 76d6bbb commit a467d56

File tree

2 files changed

+2
-155
lines changed

2 files changed

+2
-155
lines changed

lib/Listeners/FilesSharingLoadAdditionalScriptsListener.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public function handle(Event $event): void {
3030

3131
Util::addScript('text', 'text-public');
3232
Util::addStyle('text', 'text-public');
33+
Util::addInitScript('text', 'text-init');
34+
Util::addStyle('text', 'text-init');
3335

3436
$this->initialStateProvider->provideState();
3537
$node = $event->getShare()->getNode();

src/public.js

Lines changed: 0 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -4,161 +4,6 @@
44
*/
55

66
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-
})
1627

1638
OCA.Text = {
1649
RichWorkspaceEnabled: loadState('text', 'workspace_available'),

0 commit comments

Comments
 (0)