-
-
Notifications
You must be signed in to change notification settings - Fork 739
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Alin Voinea <contact@avoinea.com> Co-authored-by: nileshgulia1 <nileshgulia@gmail.com> Co-authored-by: Timo Stollenwerk <tisto@users.noreply.github.com>
- Loading branch information
1 parent
37fce92
commit e2ed2fc
Showing
38 changed files
with
447 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { slateBeforeEach } from '../../../support/volto-slate'; | ||
|
||
describe('Block Tests: Anchors', () => { | ||
beforeEach(slateBeforeEach); | ||
|
||
it('Add Block: Links', () => { | ||
// Change page title | ||
cy.clearSlateTitle(); | ||
cy.getSlateTitle().type('Slate Heading Anchors'); | ||
cy.getSlate().click(); | ||
|
||
// Add TOC block | ||
cy.get('.ui.basic.icon.button.block-add-button').first().click(); | ||
cy.get(".blocks-chooser .ui.form .field.searchbox input[type='text']").type( | ||
'table of contents', | ||
); | ||
cy.get('.button.toc').click(); | ||
|
||
// Save page | ||
cy.get('#toolbar-save').click(); | ||
cy.url().should('eq', Cypress.config().baseUrl + '/my-page'); | ||
cy.get('h1.documentFirstHeading') | ||
.trigger('mouseover', { eventConstructor: 'MouseEvent' }) | ||
.children() | ||
.should('have.length', 1); | ||
}); | ||
|
||
it('Add Block: add content to TOC', () => { | ||
// Change page title | ||
cy.clearSlateTitle(); | ||
cy.getSlateTitle().type('Slate Heading Anchors'); | ||
cy.getSlate().click(); | ||
|
||
// Add TOC block | ||
cy.get('.ui.basic.icon.button.block-add-button').first().click(); | ||
cy.get(".blocks-chooser .ui.form .field.searchbox input[type='text']").type( | ||
'table of contents', | ||
); | ||
cy.get('.button.toc').click(); | ||
|
||
// Add headings | ||
cy.get('.ui.drag.block.inner.slate').click().type('Title 1').click(); | ||
cy.get('.ui.drag.block.inner.slate span span span').setSelection('Title 1'); | ||
cy.get('.slate-inline-toolbar .button-wrapper a[title="Title"]').click({ | ||
force: true, | ||
}); | ||
cy.get('.ui.drag.block.inner.slate').click().type('{enter}'); | ||
|
||
cy.get('.ui.drag.block.inner.slate').eq(1).click().type('Title 2').click(); | ||
cy.get('.ui.drag.block.inner.slate span span span') | ||
.eq(1) | ||
.setSelection('Title 2'); | ||
cy.get('.slate-inline-toolbar .button-wrapper a[title="Title"]').click({ | ||
force: true, | ||
}); | ||
cy.get('.ui.drag.block.inner.slate').eq(1).click().type('{enter}'); | ||
|
||
// Save page | ||
cy.get('#toolbar-save').click(); | ||
cy.url().should('eq', Cypress.config().baseUrl + '/my-page'); | ||
|
||
// Check if the page contains the TOC and scrolls to each entry on click | ||
cy.contains('Slate Heading Anchors'); | ||
cy.get('h2[id="title-1"]').contains('Title 1'); | ||
cy.get('h2[id="title-2"]').contains('Title 2'); | ||
cy.get('a[href="#title-1"]').click(); | ||
cy.get('h2[id="title-1"]').scrollIntoView().should('be.visible'); | ||
cy.get('a[href="#title-2"]').click(); | ||
cy.get('h2[id="title-2"]').scrollIntoView().should('be.visible'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Added slug-based linked headings in `volto-slate`. @tiberiuichim, @nileshgulia1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,30 @@ | ||
import { serializeNodes } from '@plone/volto-slate/editor/render'; | ||
import { | ||
serializeNodes, | ||
serializeNodesToText, | ||
} from '@plone/volto-slate/editor/render'; | ||
import config from '@plone/volto/registry'; | ||
import { isEqual } from 'lodash'; | ||
import Slugger from 'github-slugger'; | ||
|
||
const TextBlockView = (props) => { | ||
const { id, data, styling = {} } = props; | ||
const { value, override_toc } = data; | ||
const metadata = props.metadata || props.properties; | ||
return serializeNodes( | ||
value, | ||
(node, path) => { | ||
const res = { ...styling }; | ||
if (node.type) { | ||
if ( | ||
config.settings.slate.topLevelTargetElements.includes(node.type) || | ||
override_toc | ||
) { | ||
res.id = id; | ||
} | ||
const { topLevelTargetElements } = config.settings.slate; | ||
|
||
const getAttributes = (node, path) => { | ||
const res = { ...styling }; | ||
if (node.type && isEqual(path, [0])) { | ||
if (topLevelTargetElements.includes(node.type) || override_toc) { | ||
const text = serializeNodesToText(node?.children || []); | ||
const slug = Slugger.slug(text); | ||
res.id = slug || id; | ||
} | ||
return res; | ||
}, | ||
{ metadata: metadata }, | ||
); | ||
} | ||
return res; | ||
}; | ||
|
||
return serializeNodes(value, getAttributes, { metadata: metadata }); | ||
}; | ||
|
||
export default TextBlockView; |
Oops, something went wrong.