Skip to content

Commit

Permalink
Merge pull request #2227 from nextcloud/feature/2184-custom-containers
Browse files Browse the repository at this point in the history
New feature: Callouts
  • Loading branch information
juliusknorr authored Mar 15, 2022
2 parents d808955 + 1bcf179 commit 646376b
Show file tree
Hide file tree
Showing 36 changed files with 471 additions and 41 deletions.
5 changes: 3 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = {
root: true,
extends: [
'@nextcloud'
]
'@nextcloud',
],
}
4 changes: 3 additions & 1 deletion css/icons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
@include icon-black-white('paragraph', 'text', 1);
@include icon-black-white('code', 'text', 1);
@include icon-black-white('image', 'text', 1);
@include icon-black-white('help', 'text', 1);
@include icon-black-white('warn', 'text', 1);
@include icon-black-white('success', 'text', 1);
@include icon-black-white('emoji', 'text', 1);
@include icon-black-white('h1', 'text', 1);
@include icon-black-white('h2', 'text', 1);
@include icon-black-white('h3', 'text', 1);
@include icon-black-white('h4', 'text', 1);
@include icon-black-white('h5', 'text', 1);
@include icon-black-white('h6', 'text', 1);

62 changes: 62 additions & 0 deletions css/prosemirror.scss
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,68 @@ div.ProseMirror {
margin-right: 0;
}

// Callout Block
.callout {
background-color: var(--callout-background, var(--color-background-hover));
border-left-color: var(--callout-border, var(--color-primary-element));
border-radius: var(--border-radius);
padding: 1em;
padding-left: 2em;
border-left-width: 0.3em;
border-left-style: solid;
position: relative;
margin-bottom: 0.5em;
+ & {
margin-top: 0.5em;
}

// Block icon
&::before {
content: '';
background-image: var(--callout-icon, var(--icon-info-000));
background-size: contain;
position: absolute;
top: calc(50% - 8px);
left: 0.4em;
height: 16px;
width: 16px;
}

> p {
&:last-child {
margin-bottom: 0;
}
}

// Info (default) variables
&, &-info {
// --callout-background: var(--color-primary-light);
--callout-border: var(--color-primary-element);
--callout-icon: var(--icon-info-000);
}

// Warn variables
&-warn {
// --callout-background: var(--color-warning-hover);
--callout-border: var(--color-warning);
--callout-icon: var(--icon-text-warn-000);
}

// Error variables
&-error {
// --callout-background: var(--color-error-hover);
--callout-border: var(--color-error);
--callout-icon: var(--icon-error-000);
}

// Success variables
&-success {
// --callout-background: var(--color-success-hover);
--callout-border: var(--color-success);
--callout-icon: var(--icon-text-success-000);
}
}

}

.ProseMirror-focused .ProseMirror-gapcursor {
Expand Down
5 changes: 5 additions & 0 deletions cypress/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": [
"plugin:cypress/recommended"
]
}
65 changes: 63 additions & 2 deletions cypress/integration/workspace.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*
*/


import { randHash } from '../utils/'
const randUser = randHash()

Expand Down Expand Up @@ -57,7 +56,7 @@ describe('Workspace', function() {
['bold', 'strong'],
['italic', 'em'],
['underline', 'u'],
['strike', 's']
['strike', 's'],
].forEach(([button, tag]) => {
menuButton(button)
.click()
Expand Down Expand Up @@ -152,6 +151,68 @@ describe('Workspace', function() {
cy.get('.empty-workspace').should('contain', 'Ajoutez des notes, listes ou liens')
})

describe('callouts', () => {
const types = ['info', 'warn', 'error', 'success']
it('create callouts', () => {
const workspace = openWorkspace()
workspace.type('Callout')

types.forEach(type => {
// enable callout
menuButton('info').click()
submenuButton(type).click()

// check if is active
menuButton(type).should('have.class', 'is-active')

// check content
cy.get(`.ProseMirror .callout.callout-${type}`)
.should('contain', 'Callout')

// disable
menuButton(type).click()
submenuButton(type).click()

// check if is inactive
menuButton('info').should('not.have.class', 'is-active')
})
})

it('toggle callouts', () => {
const workspace = openWorkspace()
workspace.type('Callout')

const [first, ...rest] = types

let last = first

// enable callout
menuButton('info').click()
submenuButton(first).click()

rest.forEach(type => {
// enable callout
menuButton(last).click()
submenuButton(type).click()

last = type

// check if is active
menuButton(type).should('have.class', 'is-active')

// check content
cy.get(`.ProseMirror .callout.callout-${type}`)
.should('contain', 'Callout')
})

// disable
menuButton(last).click()
submenuButton(last).click()

// check if is inactive
menuButton('info').should('not.have.class', 'is-active')
})
})
})

const menuButton = (name) => {
Expand Down
1 change: 1 addition & 0 deletions img/help.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions img/success.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions img/warn.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions js/editor-collab.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/editor-collab.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/editor-rich.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/editor-rich.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/editor.js

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions js/editor.js.LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,25 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

/*
* @copyright Copyright (c) 2022 Vinicius Reis <[email protected]>
*
* @author Vinicius Reis <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
2 changes: 1 addition & 1 deletion js/editor.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-files.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-files.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-public.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-public.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-text.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-text.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-viewer.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-viewer.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/vendors.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/vendors.js.map

Large diffs are not rendered by default.

45 changes: 39 additions & 6 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"highlight.js": "^10.7.2",
"lowlight": "^1.20.0",
"markdown-it": "^12.3.2",
"markdown-it-container": "^3.0.0",
"markdown-it-task-lists": "^2.1.1",
"prosemirror-collab": "^1.2.2",
"prosemirror-inputrules": "^1.1.3",
Expand Down Expand Up @@ -100,6 +101,7 @@
"babel-core": "^7.0.0-bridge.0",
"cypress": "^9.5.1",
"cypress-file-upload": "^5.0.8",
"eslint-plugin-cypress": "^2.12.1",
"jest": "^27.5.1",
"jest-environment-jsdom": "^27.5.1",
"jest-serializer-vue": "^2.0.2",
Expand Down
2 changes: 2 additions & 0 deletions src/EditorFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
BulletList,
TaskList,
TaskItem,
Callout,
} from './nodes'
import { Markdown, Emoji } from './extensions'
import { translate as t } from '@nextcloud/l10n'
Expand Down Expand Up @@ -89,6 +90,7 @@ const createEditor = ({ content, onCreate, onUpdate, extensions, enableRichEditi
ListItem,
TaskList,
TaskItem,
Callout,
Underline,
Image.configure({ currentDirectory, inline: true }),
Emoji.configure({
Expand Down
2 changes: 1 addition & 1 deletion src/components/MenuBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ export default {
class: 'icon-image',
}, {
label: t('text', 'Formatting help'),
class: 'icon-info',
class: 'icon-help',
click: () => {
this.$emit('show-help')
},
Expand Down
Loading

0 comments on commit 646376b

Please sign in to comment.