Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drop/vuex #6930

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
975 changes: 544 additions & 431 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@
"vue": "^2.7.16",
"vue-click-outside": "^1.1.0",
"vue-material-design-icons": "^5.3.1",
"vuex": "^3.6.2",
"webdav": "^5.7.1",
"y-prosemirror": "^1.2.15",
"y-protocols": "^1.0.6",
Expand Down Expand Up @@ -142,7 +141,7 @@
"raw-loader": "^4.0.2",
"rollup-plugin-webpack-stats": "^1.2.4-beta.6",
"typescript": "^5.7.3",
"vite": "^5.4.14",
"vite": "^6.2.0",
"vite-plugin-commonjs": "^0.10.4",
"vitest": "^3.0.7",
"vue-demi": "^0.14.10",
Expand Down
2 changes: 0 additions & 2 deletions src/components/Editor/EditorOutline.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import { NcButton } from '@nextcloud/vue'
import TableOfContents from './TableOfContents.vue'
import { useOutlineStateMixin, useOutlineActions } from './Wrapper.provider.js'
import { Close } from './../icons.js'
import useStore from '../../mixins/store.js'
import { useIsMobileMixin } from '../Editor.provider.js'

export default {
Expand All @@ -37,7 +36,6 @@ export default {
},
mixins: [
useIsMobileMixin,
useStore,
useOutlineStateMixin,
useOutlineActions,
],
Expand Down
24 changes: 15 additions & 9 deletions src/components/Editor/TableOfContents.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,28 @@
</template>

<script>
import { mapState } from 'vuex'
import { useEditorMixin } from '../Editor.provider.js'
import useStore from '../../mixins/store.js'
import { useEditorMixin } from '../../components/Editor.provider.js'
import { headingAnchorPluginKey } from '../../plugins/headingAnchor.js'

export default {
name: 'TableOfContents',
mixins: [useStore, useEditorMixin],
mixins: [useEditorMixin],
data: () => ({
initialRender: true,
headings: [],
}),
computed: {
...mapState({
headings: (state) => state.text.headings,
}),
},
mounted() {
if (this.$editor) {
this.$editor.on('update', this.updateHeadings)
this.updateHeadings()
}
setTimeout(() => {
this.initialRender = false
}, 1000)
},
beforeDestroy() {
this.$editor.off('update', this.updateHeadings)
},
methods: {
goto(heading) {
document.getElementById(heading.id).scrollIntoView()
Expand All @@ -51,6 +53,10 @@ export default {
window.location.hash = heading.id
})
},
updateHeadings() {
this.headings = headingAnchorPluginKey
.getState(this.$editor.state)?.headings ?? []
},
},
}
</script>
Expand Down
7 changes: 1 addition & 6 deletions src/components/Editor/Wrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@
<script>
import { useIsRichEditorMixin, useIsRichWorkspaceMixin } from './../Editor.provider.js'
import { OUTLINE_STATE, OUTLINE_ACTIONS, READ_ONLY_ACTIONS } from './Wrapper.provider.js'
import useStore from '../../mixins/store.js'
import { mapState } from 'vuex'

export default {
name: 'Wrapper',
mixins: [useStore, useIsRichEditorMixin, useIsRichWorkspaceMixin],
mixins: [useIsRichEditorMixin, useIsRichWorkspaceMixin],

Check warning on line 23 in src/components/Editor/Wrapper.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/Wrapper.vue#L23

Added line #L23 was not covered by tests
provide() {
const val = {}

Expand Down Expand Up @@ -72,9 +70,6 @@
}),

computed: {
...mapState({
viewWidth: (state) => state.text.viewWidth,
}),
showOutline() {
return this.isAbleToShowOutline
? this.outline.visible
Expand Down
3 changes: 1 addition & 2 deletions src/components/Menu/ActionList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import ActionListItem from './ActionListItem.vue'
import { getActionState, getIsActive } from './utils.js'
import { useOutlineStateMixin } from '../Editor/Wrapper.provider.js'
import useStore from '../../mixins/store.js'
import { useMenuIDMixin } from './MenuBar.provider.js'
import debounce from 'debounce'

Expand All @@ -50,7 +49,7 @@
ActionListItem,
},
extends: BaseActionEntry,
mixins: [useStore, useOutlineStateMixin, useMenuIDMixin],
mixins: [useOutlineStateMixin, useMenuIDMixin],

Check warning on line 52 in src/components/Menu/ActionList.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Menu/ActionList.vue#L52

Added line #L52 was not covered by tests
props: {
forceEnabled: {
type: Boolean,
Expand Down
2 changes: 0 additions & 2 deletions src/components/Menu/BaseActionEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import debounce from 'debounce'
import { useEditorMixin, useIsMobileMixin } from '../Editor.provider.js'
import { useOutlineActions, useOutlineStateMixin, useReadOnlyActions } from '../Editor/Wrapper.provider.js'
import { getActionState, getKeys, getKeyshortcuts } from './utils.js'
import useStore from '../../mixins/store.js'

import './ActionEntry.scss'

Expand All @@ -21,7 +20,6 @@ const BaseActionEntry = {
mixins: [
useEditorMixin,
useIsMobileMixin,
useStore,
useOutlineActions,
useOutlineStateMixin,
useReadOnlyActions,
Expand Down
2 changes: 0 additions & 2 deletions src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/

import Vue from 'vue'
import store from './store/index.js'
import { subscribe } from '@nextcloud/event-bus'
import { EDITOR_UPLOAD, HOOK_MENTION_SEARCH, HOOK_MENTION_INSERT, ATTACHMENT_RESOLVER } from './components/Editor.provider.js'
import { ACTION_ATTACHMENT_PROMPT } from './components/Editor/MediaHandler.provider.js'
Expand Down Expand Up @@ -254,7 +253,6 @@ window.OCA.Text.createEditor = async function({
scopedSlots,
})
},
store,
})
return new TextEditorEmbed(vm, data)
.onCreate(onCreate)
Expand Down
2 changes: 0 additions & 2 deletions src/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@ document.addEventListener('DOMContentLoaded', async () => {
if (workspaceAvailable && OCA && OCA?.Files?.Settings) {
const { default: Vue } = await import('vue')
const { default: FilesSettings } = await import('./views/FilesSettings.vue')
const { default: store } = await import('./store/index.js')

Vue.prototype.t = window.t
Vue.prototype.n = window.n
Vue.prototype.OCA = window.OCA
const vm = new Vue({
render: h => h(FilesSettings, {}),
store,
})
const el = vm.$mount().$el
OCA.Files.Settings.register(new OCA.Files.Settings.Setting('text', {
Expand Down
2 changes: 0 additions & 2 deletions src/helpers/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import axios from '@nextcloud/axios'
import TextSvg from '@mdi/svg/svg/text.svg?raw'

import { openMimetypes } from './mime.js'
import store from '../store/index.js'

const FILE_ACTION_IDENTIFIER = 'Edit with text app'

Expand Down Expand Up @@ -205,7 +204,6 @@ export const FilesWorkspaceHeader = new Header({
hasRichWorkspace,
content,
},
store,
}).$mount(el)
})
},
Expand Down
2 changes: 0 additions & 2 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import store from './store/index.js'
// eslint-disable-next-line import/no-unresolved, n/no-missing-import
import 'vite/modulepreload-polyfill'

Expand All @@ -18,7 +17,6 @@ if (document.getElementById('app-content')) {
const DirectEditing = imports[1].default
const vm = new Vue({
render: h => h(DirectEditing),
store,
})
vm.$mount(document.getElementById('app-content'))
})
Expand Down
28 changes: 0 additions & 28 deletions src/mixins/store.js

This file was deleted.

12 changes: 1 addition & 11 deletions src/nodes/Heading.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
*/

import TipTapHeading from '@tiptap/extension-heading'
import headingAnchor, { headingAnchorPluginKey } from '../plugins/headingAnchor.js'
import store from '../store/index.js'

const setHeadings = (val) => store.dispatch('text/setHeadings', val)
import headingAnchor from '../plugins/headingAnchor.js'

const Heading = TipTapHeading.extend({

Expand All @@ -18,13 +15,6 @@ const Heading = TipTapHeading.extend({
}), {})
},

// sync heading data structure to the vuex store
onUpdate({ editor }) {
const headings = headingAnchorPluginKey
.getState(editor.state)?.headings ?? []
setHeadings(headings)
},

addProseMirrorPlugins() {
return [headingAnchor()]
},
Expand Down
6 changes: 0 additions & 6 deletions src/nodes/ImageView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,9 @@

<script>
import ClickOutside from 'vue-click-outside'
import { mapGetters } from 'vuex'
import { NcButton } from '@nextcloud/vue'
import { showError } from '@nextcloud/dialogs'
import ShowImageModal from '../components/ImageView/ShowImageModal.vue'
import store from '../mixins/store.js'
import { useAttachmentResolver } from '../components/Editor.provider.js'
import { emit } from '@nextcloud/event-bus'
import { NodeViewWrapper } from '@tiptap/vue-2'
Expand Down Expand Up @@ -147,7 +145,6 @@ export default {
ClickOutside,
},
mixins: [
store,
useAttachmentResolver,
],
props: ['editor', 'node', 'extension', 'updateAttributes', 'deleteNode'], // eslint-disable-line
Expand All @@ -168,9 +165,6 @@ export default {
}
},
computed: {
...mapGetters({
imageAttachments: 'text/imageAttachments',
}),
attachmentType() {
if (this.attachment) {
return this.attachment.isImage ? 'image' : 'media'
Expand Down
13 changes: 9 additions & 4 deletions src/plugins/extractHeadings.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import { slugify } from './slug.js'
* Extract heading data structure from doc
*
* @param {Document} doc - the prosemirror doc
* @param {Array} oldVal - the previous headings
* @return {Array} headings found in the doc
*/
export default function extractHeadings(doc) {
export default function extractHeadings(doc, oldVal = []) {
const counter = new Map()
const headings = []

Expand All @@ -28,20 +29,24 @@ export default function extractHeadings(doc) {
return 'h-' + id
}

doc.descendants((node, offset) => {
doc.descendants((node, offset, _parent, index) => {
if (node.type.name !== 'heading') {
return
}
const text = node.textContent
// ignore empty headings
if (!text) return
const id = getId(text)
headings.push(Object.freeze({
const old = oldVal.at(index)
const prev = old?.id === id ? { previous: old.level } : {}
const heading = Object.freeze({
level: node.attrs.level,
text,
id,
offset,
}))
...prev,
})
headings.push(heading)
})

return headings
Expand Down
3 changes: 0 additions & 3 deletions src/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
import { logger } from './helpers/logger.js'
import { openMimetypes } from './helpers/mime.js'
import { documentReady } from './helpers/index.js'
import store from './store/index.js'
import { emit, subscribe } from '@nextcloud/event-bus'
import RichWorkspace from './views/RichWorkspace.vue'

Expand Down Expand Up @@ -82,7 +81,6 @@ const filesWorkspacePlugin = {
path: fileList.getCurrentDirectory(),
hasRichWorkspace: true,
},
store,
}).$mount(this.el)
subscribe('files:navigation:changed', () => {
// Expose if the default file list is active to the component
Expand Down Expand Up @@ -126,7 +124,6 @@ const loadEditor = ({ sharingToken, mimetype, fileId, $el }) => {
fileId,
},
}),
store,
})
.$mount($el)

Expand Down
Loading
Loading