Skip to content
This repository was archived by the owner on Oct 30, 2024. It is now read-only.

Commit c8ca18e

Browse files
committed
Initial commit
0 parents  commit c8ca18e

File tree

19 files changed

+8323
-0
lines changed

19 files changed

+8323
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

Configuration/Settings.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Neos:
2+
Neos:
3+
Ui:
4+
resources:
5+
javascript:
6+
'Pmaas.Neos.TableStyles':
7+
resource: resource://Pmaas.Neos.TableStyles/Public/JavaScript/TableStyles/Plugin.js
8+
frontendConfiguration:
9+
'Pmaas.Neos:TableStyles': '${Configuration.setting(''Pmaas.Neos.TableStyles'')}'
10+
11+
Pmaas:
12+
Neos:
13+
TableStyles:
14+
presets:
15+
label: 'Table style'
16+
# options:
17+
# primary:
18+
# label: 'Primary style'
19+
# cssClass: 'table--primary'
20+
# secondary:
21+
# label: 'Secondary style'
22+
# cssClass: 'table--secondary'

Documentation/Screencast.gif

615 KB
Loading

LICENCE.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2020 Philipp Maas
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Table styles plugin for Neos CMS
2+
3+
> This package provides a drop down to add custom CSS classes to CKEditor tables in Neos CMS.
4+
5+
![Table style drop down](Documentation/Screencast.gif)
6+
7+
8+
## Installation
9+
10+
To install the plugin run this in your site package folder:
11+
12+
composer require --no-update pmaas/neos-tablestyles
13+
14+
Then run `composer update` in your project directory.
15+
16+
17+
## Usage
18+
19+
Add your custom css classes to your `settings.yaml`:
20+
21+
Pmaas:
22+
Neos:
23+
TableStyles:
24+
presets:
25+
label: 'Table style'
26+
options:
27+
primary:
28+
label: 'Primary style'
29+
cssClass: 'table--primary'
30+
secondary:
31+
label: 'Secondary style'
32+
cssClass: 'table--secondary'
33+
34+
Then add `tableStyles: true` to your NodeType, to activate the drop down:
35+
36+
'Vendor.Package:Type.Name':
37+
properties:
38+
text:
39+
ui:
40+
inline:
41+
editorOptions:
42+
tableStyles: true
43+
44+
45+
## Contributions
46+
47+
Contributions are always welcome!
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"extends": "@neos-project/eslint-config-neos",
3+
"parser": "babel-eslint",
4+
"globals": {
5+
"expect": true,
6+
"sinon": false
7+
},
8+
"env": {
9+
"node": true,
10+
"mocha": true
11+
}
12+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
^8.11.0
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"description": "CKEditor table styles plugin for for Neos CMS",
3+
"license": "proprietary",
4+
"private": true,
5+
"scripts": {
6+
"build": "NODE_ENV=production neos-react-scripts build && terser --compress --mangle -o ../../../Public/JavaScript/TableStyles/Plugin.js -- ../../../Public/JavaScript/TableStyles/Plugin.js",
7+
"watch": "neos-react-scripts watch"
8+
},
9+
"dependencies": {
10+
"@ckeditor/ckeditor5-basic-styles": "^10.1.0",
11+
"@neos-project/react-ui-components": "^5.2.0"
12+
},
13+
"devDependencies": {
14+
"@ckeditor/ckeditor5-table": "^13.0.0",
15+
"@neos-project/eslint-config-neos": "^2.3.0",
16+
"@neos-project/neos-ui-extensibility": "^5.2.0",
17+
"babel-eslint": "^10.1.0",
18+
"terser": "^4.8.0"
19+
},
20+
"neos": {
21+
"buildTargetDirectory": "../../../Public/JavaScript/TableStyles"
22+
}
23+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import {Command} from 'ckeditor5-exports';
2+
import {findAncestor} from '@ckeditor/ckeditor5-table/src/commands/utils';
3+
4+
export default class TableStylesCommand extends Command {
5+
refresh() {
6+
const table = this.getTable();
7+
8+
this.isEnabled = Boolean(table);
9+
10+
if (table) {
11+
this.value = (table.getAttribute('class') === 'table') ? undefined : table.getAttribute('class');
12+
}
13+
}
14+
15+
execute(options = {}) {
16+
const cssClass = (options.value) ? options.value : 'table';
17+
18+
this.editor.model.change(writer => {
19+
writer.setAttribute('class', cssClass, this.getTable());
20+
});
21+
}
22+
23+
getTable() {
24+
const position = this.editor.model.document.selection.getFirstPosition();
25+
return findAncestor('table', position);
26+
}
27+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import React, {PureComponent} from 'react';
2+
import PropTypes from 'prop-types';
3+
import {SelectBox} from '@neos-project/react-ui-components';
4+
import {connect} from 'react-redux';
5+
import {$transform} from 'plow-js';
6+
import {selectors} from '@neos-project/neos-ui-redux-store';
7+
import * as CkEditorApi from '@neos-project/neos-ui-ckeditor5-bindings';
8+
9+
@connect($transform({
10+
formattingUnderCursor: selectors.UI.ContentCanvas.formattingUnderCursor
11+
}))
12+
13+
export default class TableStylesSelectBox extends PureComponent {
14+
static propTypes = {
15+
presetConfiguration: PropTypes.shape({
16+
label: PropTypes.string.isRequired,
17+
18+
options: PropTypes.objectOf(PropTypes.shape({
19+
label: PropTypes.string.isRequired,
20+
cssClass: PropTypes.string.isRequired
21+
}))
22+
}),
23+
formattingUnderCursor: PropTypes.object
24+
};
25+
26+
constructor(...args) {
27+
super(...args);
28+
this.handleOnSelect = this.handleOnSelect.bind(this);
29+
}
30+
31+
render() {
32+
const selectOptions = Object.entries(this.props.presetConfiguration.options)
33+
.map(([optionIdentifier, optionConfiguration]) => ({
34+
value: optionIdentifier,
35+
label: optionConfiguration.label
36+
}));
37+
38+
if (selectOptions.length === 0) {
39+
return null;
40+
}
41+
42+
const currentValue = this.props.formattingUnderCursor.tableStyles;
43+
44+
return (
45+
<SelectBox
46+
options={selectOptions}
47+
value={currentValue}
48+
allowEmpty={true}
49+
placeholder={this.props.presetConfiguration.label}
50+
onValueChange={this.handleOnSelect}
51+
/>
52+
);
53+
}
54+
55+
handleOnSelect(option) {
56+
CkEditorApi.executeCommand('tableStyles', {value: option});
57+
}
58+
}

0 commit comments

Comments
 (0)