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

WIP: Make build run without additional ram #5818

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion cypress/e2e/directediting.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { initUserAndFiles, randUser } from '../utils/index.js'

const user = randUser()

function enterContentAndClose() {
const enterContentAndClose = () => {
cy.intercept({ method: 'POST', url: '**/session/*/close' }).as('closeRequest')
cy.intercept({ method: 'POST', url: '**/session/*/push' }).as('push')
cy.intercept({ method: 'POST', url: '**/session/*/sync' }).as('sync')
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/nodes/ListItem.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ListItem from '@tiptap/extension-list-item'
import TaskList from './../../../src/nodes/TaskList.js'
import TaskItem from './../../../src/nodes/TaskItem.js'
import BulletList from './../../../src/nodes/BulletList.js'
import Markdown from './../../../src/extensions/Markdown.js'
import Serializer from './../../../src/extensions/Serializer.js'
import { createCustomEditor } from './../../support/components.js'
import { loadMarkdown, runCommands, expectMarkdown } from './helpers.js'

Expand All @@ -18,7 +18,7 @@ describe('ListItem extension integrated in the editor', () => {
const editor = createCustomEditor({
content: '',
extensions: [
Markdown,
Serializer,
BulletList,
OrderedList,
ListItem,
Expand Down
54 changes: 23 additions & 31 deletions cypress/e2e/nodes/Preview.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
*
*/

import Markdown from './../../../src/extensions/Markdown.js'
import Serializer from './../../../src/extensions/Serializer.js'
import Preview from './../../../src/nodes/Preview.js'
import { Italic, Link } from './../../../src/marks/index.js'
import { createCustomEditor } from './../../support/components.js'
import { loadMarkdown, runCommands, expectMarkdown } from './helpers.js'
import { isNodeActive, getMarkAttributes, getNodeAttributes } from '@tiptap/core'

// https://github.com/import-js/eslint-plugin-import/issues/1739
/* eslint-disable-next-line import/no-unresolved */
Expand All @@ -36,7 +37,7 @@ describe('Preview extension', { retries: 0 }, () => {
const editor = createCustomEditor({
content: '',
extensions: [
Markdown,
Serializer,
Preview,
Link,
Italic,
Expand Down Expand Up @@ -133,51 +134,42 @@ describe('Preview extension', { retries: 0 }, () => {
prepareEditor('[link text](https://nextcloud.com)\n')
editor.commands.setPreview()
editor.commands.unsetPreview()
expect(getParentNode().type.name).to.equal('paragraph')
})

it('includes a link', () => {
prepareEditor('[link text](https://nextcloud.com)\n')
editor.commands.setPreview()
editor.commands.unsetPreview()
expect(getMark().attrs.href).to.equal('https://nextcloud.com')
expectParagraphWithLink()
})

})

/**
* Expect a preview in the editor.
* Expect a preview at the current position.
*/
function expectPreview() {
expect(getParentNode().type.name).to.equal('preview')
expect(getParentNode().attrs.href).to.equal('https://nextcloud.com')
expect(getMark().attrs.href).to.equal('https://nextcloud.com')
}

/**
*
*/
function getParentNode() {
const { state: { selection } } = editor
return selection.$head.parent
expect(isNodeActive(editor.state, 'paragraph'))
.to.be.false
expect(getNodeAttributes(editor.state, 'preview'))
.to.include({ href: 'https://nextcloud.com' })
expect(getMarkAttributes(editor.state, 'link'))
.to.include({ href: 'https://nextcloud.com' })
}

/**
*
* Expect a paragraph with a link at the current position.
*/
function getMark() {
const { state: { selection } } = editor
console.info(selection.$head)
return selection.$head.nodeAfter.marks[0]
function expectParagraphWithLink() {
expect(isNodeActive(editor.state, 'preview'))
.to.be.false
expect(isNodeActive(editor.state, 'paragraph'))
.to.be.true
expect(getMarkAttributes(editor.state, 'link'))
.to.include({ href: 'https://nextcloud.com' })
}

/**
*
* @param input
* Load input and position the cursor inside.
* @param { string } input - markdown to load
*/
function prepareEditor(input) {
loadMarkdown(editor, input)
editor.commands.setTextSelection(1)
editor.commands.setTextSelection(2)
}

})
Expand All @@ -186,7 +178,7 @@ describe('Markdown tests for Previews in the editor', { retries: 0 }, () => {
const editor = createCustomEditor({
content: '',
extensions: [
Markdown,
Serializer,
Preview,
Link,
],
Expand Down
9 changes: 3 additions & 6 deletions cypress/e2e/nodes/Table.spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { findChildren } from './../../../src/helpers/prosemirrorUtils.js'
import { initUserAndFiles, randUser } from '../../utils/index.js'
import { createCustomEditor } from './../../support/components.js'
import { getMarkdown } from './helpers.js'

import markdownit from './../../../src/markdownit/index.js'
import EditableTable from './../../../src/nodes/EditableTable.js'
import Markdown, { createMarkdownSerializer } from './../../../src/extensions/Markdown.js'
import { Serializer } from './../../../src/extensions/index.js'

// https://github.com/import-js/eslint-plugin-import/issues/1739
/* eslint-disable-next-line import/no-unresolved */
Expand Down Expand Up @@ -146,7 +147,7 @@ describe('Table extension integrated in the editor', () => {
const editor = createCustomEditor({
content: '',
extensions: [
Markdown,
Serializer,
EditableTable,
],
})
Expand Down Expand Up @@ -198,8 +199,4 @@ describe('Table extension integrated in the editor', () => {
expect(getMarkdown().replace(/\n$/, '')).to.equal(markdown)
}

const getMarkdown = () => {
const serializer = createMarkdownSerializer(editor.schema)
return serializer.serialize(editor.state.doc)
}
})
37 changes: 7 additions & 30 deletions cypress/e2e/nodes/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,14 @@

import markdownit from './../../../src/markdownit/index.js'
import { findChildren } from './../../../src/helpers/prosemirrorUtils.js'
import { createMarkdownSerializer } from './../../../src/extensions/Markdown.js'
import { serializeEditorContent } from './../../../src/extensions/Serializer.js'

/**
*
* @param editor
* @param markdown
*/
export function loadMarkdown(editor, markdown) {
export const loadMarkdown = (editor, markdown) => {
const stripped = markdown.replace(/\t*/g, '')
editor.commands.setContent(markdownit.render(stripped))
}

/**
*
* @param editor
*/
export function runCommands(editor) {
export const runCommands = (editor) => {
let found
while ((found = findCommand(editor))) {
const { node, pos } = found
Expand All @@ -49,32 +40,18 @@ export function runCommands(editor) {
}
}

/**
*
* @param editor
*/
function findCommand(editor) {
const findCommand = (editor) => {
const doc = editor.state.doc
return findChildren(doc, child => {
return child.isText && Object.prototype.hasOwnProperty.call(editor.commands, child.text)
})[0]
}

/**
*
* @param editor
* @param markdown
*/
export function expectMarkdown(editor, markdown) {
export const expectMarkdown = (editor, markdown) => {
const stripped = markdown.replace(/\t*/g, '')
expect(getMarkdown(editor)).to.equal(stripped)
}

/**
*
* @param editor
*/
function getMarkdown(editor) {
const serializer = createMarkdownSerializer(editor.schema)
return serializer.serialize(editor.state.doc)
export const getMarkdown = (editor) => {
return serializeEditorContent(editor)
}
11 changes: 0 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"build": "NODE_OPTIONS='--max-old-space-size=4096' vite --mode production build",
"dev": "NODE_OPTIONS='--max-old-space-size=4096' vite --mode development build",
"watch": "NODE_OPTIONS='--max-old-space-size=4096' vite --mode development build --watch",
"lint": "tsc && eslint --ext .js,.vue src cypress",
"lint:fix": "tsc && eslint --ext .js,.vue src cypress --fix",
"lint": "tsc && eslint --ext .ts,.js,.vue src cypress",
"lint:fix": "tsc && eslint --ext .ts,.js,.vue src cypress --fix",
"stylelint": "stylelint src/**/*.vue src/**/*.scss src/**/*.css css/*.scss",
"stylelint:fix": "stylelint src/**/*.vue src/**/*.scss src/**/*.css css/*.scss --fix",
"test": "NODE_ENV=test jest",
Expand Down Expand Up @@ -98,7 +98,6 @@
"mermaid": "^10.9.1",
"mitt": "^3.0.1",
"path-normalize": "^6.0.13",
"proxy-polyfill": "^0.3.2",
"slug": "^9.0.0",
"tippy.js": "^6.3.7",
"uuid": "^9.0.1",
Expand Down
69 changes: 30 additions & 39 deletions src/EditorFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,15 @@

import MentionSuggestion from './components/Suggestion/Mention/suggestions.js'

import 'proxy-polyfill'

import { Editor } from '@tiptap/core'
import { lowlight } from 'lowlight/lib/core.js'
import hljs from 'highlight.js/lib/core'

import { logger } from './helpers/logger.js'
import { FocusTrap, Mention, PlainText, RichText } from './extensions/index.js'
// eslint-disable-next-line import/no-named-as-default
import CodeBlockLowlight from '@tiptap/extension-code-block-lowlight'
import { PlainTextLowlight } from './nodes/PlainTextLowlight.js'

const loadSyntaxHighlight = async (language) => {
export const loadSyntaxHighlight = async (language) => {
const list = hljs.listLanguages()
logger.debug('Supported languages', { list })
if (!lowlight.listLanguages().includes(language)) {
Expand All @@ -49,42 +46,36 @@ const loadSyntaxHighlight = async (language) => {
}
}

const createEditor = ({ language, onCreate = () => {}, onUpdate = () => {}, extensions, enableRichEditing, session, relativePath, isEmbedded = false }) => {
let defaultExtensions
if (enableRichEditing) {
defaultExtensions = [
RichText.configure({
relativePath,
isEmbedded,
component: this,
extensions: [
Mention.configure({
suggestion: MentionSuggestion({
session,
}),
export const createRichEditor = ({ extensions = [], session, relativePath, isEmbedded = false } = {}) => {
return _createEditor([
FocusTrap,
RichText.configure({
relativePath,
isEmbedded,
extensions: [
Mention.configure({
suggestion: MentionSuggestion({
session,
}),
],
}),
FocusTrap,
]
} else {
defaultExtensions = [PlainText, CodeBlockLowlight.configure({ lowlight, defaultLanguage: language })]
}

return new Editor({
onCreate,
onUpdate,
editorProps: {
scrollMargin: 50,
scrollThreshold: 50,
},
extensions: defaultExtensions.concat(extensions || []),
})
}),
],
}),
...extensions,
])
}

const serializePlainText = (doc) => {
return doc.textContent
export const createPlainEditor = ({ language, extensions = [] } = {}) => {
return _createEditor([
PlainText,
PlainTextLowlight
.configure({ lowlight, defaultLanguage: language }),
...extensions,
])
}

export default createEditor
export { createEditor, serializePlainText, loadSyntaxHighlight }
const _createEditor = extensions => {
return new Editor({
editorProps: { scrollMargin: 50, scrollThreshold: 50 },
extensions,
})
}
Loading
Loading