-
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
548 additions
and
22 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
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
28 changes: 28 additions & 0 deletions
28
Tests/IntegrationTests/SharedNodeTypesPackage/NodeTypes/Content/InlineHeadline.yaml
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,28 @@ | ||
'Neos.TestNodeTypes:Content.InlineHeadline': | ||
superTypes: | ||
'Neos.Neos:Content': true | ||
ui: | ||
label: Inline_Headline_Test | ||
icon: icon-header | ||
position: 200 | ||
inspector: | ||
groups: | ||
default: | ||
label: 'Default' | ||
position: 5 | ||
icon: 'icon-cogs' | ||
|
||
properties: | ||
title: | ||
type: string | ||
ui: | ||
reloadIfChanged: true | ||
|
||
inlineEditable: true | ||
inline: | ||
editorOptions: | ||
autoparagraph: false | ||
# we show it also in the inspector so we can easily see the raw text content | ||
inspector: | ||
group: 'default' | ||
editor: 'Neos.Neos/Inspector/Editors/TextAreaEditor' |
9 changes: 9 additions & 0 deletions
9
...redNodeTypesPackage/Resources/Private/Fusion/Content/InlineHeadline/InlineHeadline.fusion
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,9 @@ | ||
prototype(Neos.TestNodeTypes:Content.InlineHeadline) < prototype(Neos.Neos:ContentComponent) { | ||
title = Neos.Neos:Editable { | ||
property = 'title' | ||
} | ||
|
||
renderer = afx` | ||
<h1 class="test-inline-headline">{props.title}</h1> | ||
` | ||
} |
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
28 changes: 28 additions & 0 deletions
28
packages/neos-ui-ckeditor5-bindings/src/cleanupContentBeforeCommit.js
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,28 @@ | ||
// We remove opening and closing span tags that are produced by the inlineMode plugin | ||
/** @param {String} content */ | ||
export const cleanupContentBeforeCommit = content => { | ||
// TODO: remove when this is fixed: https://github.com/ckeditor/ckeditor5/issues/401 | ||
if (content.match(/^<([a-z][a-z0-9]*)\b[^>]*> <\/\1>$/)) { | ||
return ''; | ||
} | ||
|
||
if (content.includes('<neos-inline-wrapper>')) { | ||
let contentWithoutOuterInlineWrapper = content; | ||
|
||
if (content.startsWith('<neos-inline-wrapper>') && content.endsWith('</neos-inline-wrapper>')) { | ||
contentWithoutOuterInlineWrapper = content | ||
.replace(/^<neos-inline-wrapper>/, '') | ||
.replace(/<\/neos-inline-wrapper>$/, ''); | ||
} | ||
|
||
if (contentWithoutOuterInlineWrapper.includes('<neos-inline-wrapper>')) { | ||
// in the case, multiple root paragraph elements were inserted into the ckeditor (wich is currently not prevented if the html is modified from outside) | ||
// we have multiple root elements of type <neos-inline-wrapper>. We will convert all of them into spans. | ||
return content | ||
.replace(/<neos-inline-wrapper>/g, '<span>') | ||
.replace(/<\/neos-inline-wrapper>/g, '</span>'); | ||
} | ||
return contentWithoutOuterInlineWrapper; | ||
} | ||
return content; | ||
}; |
36 changes: 36 additions & 0 deletions
36
packages/neos-ui-ckeditor5-bindings/src/cleanupContentBeforeCommit.spec.js
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,36 @@ | ||
import {cleanupContentBeforeCommit} from './cleanupContentBeforeCommit' | ||
|
||
const assertCleanedUpContent = (input, expected) => { | ||
expect(cleanupContentBeforeCommit(input)).toBe(expected); | ||
} | ||
|
||
test('remove empty nbsp', () => { | ||
assertCleanedUpContent('<p> </p>', ''); | ||
assertCleanedUpContent('<span> </span>', ''); | ||
}) | ||
|
||
describe('ckeditor inline mode hack, cleanup <neos-inline-wrapper>', () => { | ||
test('noop', () => { | ||
assertCleanedUpContent('<p></p>', '<p></p>'); | ||
|
||
assertCleanedUpContent('', ''); | ||
}) | ||
|
||
test('cleanup single <neos-inline-wrapper>', () => { | ||
assertCleanedUpContent('<neos-inline-wrapper></neos-inline-wrapper>', ''); | ||
assertCleanedUpContent('<neos-inline-wrapper>foo</neos-inline-wrapper>', 'foo'); | ||
|
||
assertCleanedUpContent('<neos-inline-wrapper><span>foo</span></neos-inline-wrapper>', '<span>foo</span>'); | ||
}) | ||
|
||
test('cleanup multiple <neos-inline-wrapper>', () => { | ||
assertCleanedUpContent('<neos-inline-wrapper>foo</neos-inline-wrapper><neos-inline-wrapper>bar</neos-inline-wrapper>', '<span>foo</span><span>bar</span>'); | ||
|
||
assertCleanedUpContent('<neos-inline-wrapper>foo</neos-inline-wrapper><neos-inline-wrapper>bar</neos-inline-wrapper>', '<span>foo</span><span>bar</span>'); | ||
}) | ||
|
||
test('cleanup <neos-inline-wrapper> after other root', () => { | ||
// in the case you had multiple paragraphs and a headline and switched to autoparagrahp: false | ||
assertCleanedUpContent('<h1>foo</h1><neos-inline-wrapper>bar</neos-inline-wrapper>', '<h1>foo</h1><span>bar</span>'); | ||
}) | ||
}) |
22 changes: 19 additions & 3 deletions
22
packages/neos-ui-ckeditor5-bindings/src/plugins/inlineMode.js
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 @@ | ||
dist |
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,56 @@ | ||
const {sep} = require('path') | ||
|
||
const esbuild = require('esbuild'); | ||
|
||
const isWatch = process.argv.includes("--watch"); | ||
|
||
/** @type {import("esbuild").BuildOptions} */ | ||
const options = { | ||
entryPoints: ['./index.js'], | ||
absWorkingDir: __dirname, | ||
outdir: './dist', | ||
sourcemap: true, | ||
minify: false, | ||
logLevel: 'info', | ||
target: 'es2020', | ||
color: true, | ||
bundle: true, | ||
loader: { | ||
'.js': 'tsx', | ||
'.svg': 'dataurl', | ||
'.vanilla-css': 'css', | ||
'.woff2': 'file' | ||
}, | ||
plugins: [ | ||
{ | ||
name: 'neos-ui-build', | ||
setup: ({onResolve, onLoad, resolve}) => { | ||
// exclude CKEditor styles | ||
// the filter must match the import statement - and as one usually uses relative paths we cannot look for `@ckeditor` here | ||
// we are currently intercepting all `/\.css/` files, as this is the most accurate way and has nearly no impact on performance | ||
onResolve({filter: /\.css$/, namespace: 'file'}, ({path, ...options}) => { | ||
if (!options.importer.includes(`${sep}@ckeditor${sep}`)) { | ||
return resolve(path, {...options, namespace: 'noRecurse'}) | ||
} | ||
return { | ||
external: true, | ||
sideEffects: false | ||
} | ||
}) | ||
|
||
// load ckeditor icons as plain text and not via `.svg: dataurl` | ||
// (currently neccessary for the table select handle icon) | ||
onLoad({filter: /node_modules\/@ckeditor\/.*\.svg$/}, async ({path}) => ({ | ||
contents: (await require('fs/promises').readFile(path)).toString(), | ||
loader: 'text' | ||
})) | ||
} | ||
} | ||
], | ||
} | ||
|
||
if (isWatch) { | ||
esbuild.context(options).then((ctx) => ctx.watch()) | ||
} else { | ||
esbuild.build(options) | ||
} |
21 changes: 21 additions & 0 deletions
21
packages/neos-ui-ckeditor5-bindings/tests/manual/index.html
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,21 @@ | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<script src="./dist/index.js" defer></script> | ||
<title>CKEditor Manual Test</title> | ||
</head> | ||
<body> | ||
<h2>Test Neos + CKEditor Version <span id="ckVersion"></span></h2> | ||
|
||
<h3>Input</h3> | ||
<div id="input">Insert text here</div> | ||
|
||
<h3>Output</h3> | ||
<pre id="output">...</pre> | ||
|
||
<h3>Enabled Commands (via editor options)</h3> | ||
<p>You can run them via <code>editor.execute('bold')</code> or <code>editor.execute('heading', { value: 'heading1' })</code></p> | ||
<pre id="enabledCommands"></pre> | ||
</body> | ||
</html> |
Oops, something went wrong.