-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feature/SD-532-reroll-patch-searchapi
- Loading branch information
Showing
16 changed files
with
3,133 additions
and
1 deletion.
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
2 changes: 2 additions & 0 deletions
2
modules/tide_ckeditor/modules/ckeditor_tablecol_resize/.gitignore
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,2 @@ | ||
node_modules | ||
yarn-error.log |
20 changes: 20 additions & 0 deletions
20
...les/tide_ckeditor/modules/ckeditor_tablecol_resize/ckeditor_tablecol_resize.ckeditor5.yml
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,20 @@ | ||
ckeditor_tablecol_resize_tableColResize: | ||
ckeditor5: | ||
plugins: | ||
- table.TableColumnResize | ||
- tableColResize.TableColResize | ||
config: | ||
tableColResize: | ||
dataAttribute: data-resize-width | ||
drupal: | ||
label: Table Column Resize | ||
library: ckeditor_tablecol_resize/editor | ||
conditions: | ||
filter: filter_resize_tablecolumns | ||
plugins: | ||
- ckeditor5_table | ||
elements: | ||
- <table data-resize-width> | ||
- <colgroup> | ||
- <col> | ||
- <col data-resize-width> |
7 changes: 7 additions & 0 deletions
7
modules/tide_ckeditor/modules/ckeditor_tablecol_resize/ckeditor_tablecol_resize.info.yml
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,7 @@ | ||
name: Ckeditor Table Column Resize | ||
type: module | ||
description: Provides a ckeditor5 plugin that allows resizing of table columns | ||
package: Custom | ||
core_version_requirement: ^9.4 || ^10 | ||
dependencies: | ||
- drupal:tide_ckeditor |
5 changes: 5 additions & 0 deletions
5
...les/tide_ckeditor/modules/ckeditor_tablecol_resize/ckeditor_tablecol_resize.libraries.yml
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,5 @@ | ||
editor: | ||
js: | ||
js/build/tableColResize.js: { preprocess: false, minified: true } | ||
dependencies: | ||
- ckeditor5/ckeditor5 |
15 changes: 15 additions & 0 deletions
15
modules/tide_ckeditor/modules/ckeditor_tablecol_resize/composer.json
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,15 @@ | ||
{ | ||
"name": "drupal/ckeditor_tablecol_resize", | ||
"description": "Provides a ckeditor5 plugin that allows resizing of table columns.", | ||
"type": "drupal-module", | ||
"homepage": "https://drupal.org/project/ckeditor_tablecol_resize", | ||
"authors": [ | ||
{ | ||
"name": "Sebastian Leu", | ||
"homepage": "https://www.drupal.org/u/s_leu", | ||
"role": "Maintainer" | ||
} | ||
], | ||
"license": "GPL-2.0-or-later", | ||
"minimum-stability": "dev" | ||
} |
1 change: 1 addition & 0 deletions
1
modules/tide_ckeditor/modules/ckeditor_tablecol_resize/js/build/tableColResize.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
...keditor/modules/ckeditor_tablecol_resize/js/ckeditor5_plugins/tableColResize/src/index.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,22 @@ | ||
import { Plugin } from 'ckeditor5/src/core'; | ||
import TableColResizeEditing from './tablecolresizeediting'; | ||
|
||
class TableColResize extends Plugin { | ||
/** | ||
* @inheritDoc | ||
*/ | ||
static get requires() { | ||
return [ TableColResizeEditing ]; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
static get pluginName() { | ||
return 'TableColResize'; | ||
} | ||
} | ||
|
||
export default { | ||
TableColResize, | ||
}; |
104 changes: 104 additions & 0 deletions
104
...ckeditor_tablecol_resize/js/ckeditor5_plugins/tableColResize/src/tablecolresizeediting.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,104 @@ | ||
import { Plugin } from 'ckeditor5/src/core'; | ||
|
||
export default class TableColResizeEditing extends Plugin { | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
static get pluginName() { | ||
return 'TableColResizeEditing'; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
afterInit() { | ||
if ( this.editor.plugins.has( 'TableColumnResizeEditing' ) ) { | ||
this._registerConverters(); | ||
} | ||
} | ||
|
||
/** | ||
* Registers converters necessary for column resizing. | ||
*/ | ||
_registerConverters() { | ||
const editor = this.editor; | ||
const dataAttribute = editor.config._config.tableColResize.dataAttribute; | ||
|
||
// Converts the width style of a tableColumn model into a data attribute on | ||
// the <col> view. | ||
editor.conversion.for( 'downcast' ).add( dispatcher => | ||
dispatcher.on( 'attribute:columnWidth:tableColumn', ( evt, data, conversionApi ) => { | ||
const viewWriter = conversionApi.writer; | ||
const elementView = conversionApi.mapper.toViewElement( data.item ); | ||
|
||
if ( data.attributeNewValue !== null ) { | ||
// The data attribute is set for applying the width via a style | ||
// attribute when drupal renders the WYSIWYG content via the | ||
// resize_tablecolumns_filter. We use a data attribute to work around | ||
// the filter_html restriction that prohibits usage of the style | ||
// attribute. | ||
viewWriter.setAttribute( dataAttribute, data.attributeNewValue, elementView ); | ||
} else { | ||
viewWriter.removeAttribute( dataAttribute, elementView ); | ||
} | ||
} ) | ||
); | ||
|
||
// Ensures that the value of the data-resize-width attribute is added to the | ||
// ckeditor model when the editor loads. | ||
editor.conversion.for( 'upcast' ).add( dispatcher => | ||
dispatcher.on( `element:col`, ( evt, data, conversionApi ) => { | ||
const { schema, writer } = conversionApi; | ||
const colWidth = data.viewItem.getAttribute( dataAttribute ); | ||
|
||
// Do not go for the model element after data.modelCursor because it might happen | ||
// that a single view element was converted to multiple model elements. Get all of them. | ||
for ( const item of data.modelRange.getItems( { shallow: true } ) ) { | ||
if ( schema.checkAttribute( item, 'columnWidth' ) ) { | ||
writer.setAttribute( 'columnWidth', colWidth, item ); | ||
} | ||
} | ||
}) | ||
); | ||
|
||
// Converts the width style of a table model into a data attribute on the | ||
// <table> view. | ||
editor.conversion.for( 'downcast' ).add( dispatcher => | ||
dispatcher.on( 'attribute:tableWidth:table', ( evt, data, conversionApi ) => { | ||
const viewWriter = conversionApi.writer; | ||
const elementView = conversionApi.mapper.toViewElement( data.item ); | ||
|
||
if ( data.attributeNewValue !== null ) { | ||
// The data attribute is set for applying the width via a style | ||
// attribute when drupal renders the WYSIWYG content via the | ||
// resize_tablecolumns_filter. We use a data attribute to work around | ||
// the filter_html restriction that prohibits usage of the style | ||
// attribute. | ||
viewWriter.setAttribute( dataAttribute, data.attributeNewValue, elementView ); | ||
} else { | ||
viewWriter.removeAttribute( dataAttribute, elementView ); | ||
} | ||
} ) | ||
); | ||
|
||
// Ensures that the value of the data-resize-width attribute is added to the | ||
// ckeditor model when the editor loads. | ||
editor.conversion.for( 'upcast' ).add( dispatcher => | ||
dispatcher.on( `element:table`, ( evt, data, conversionApi ) => { | ||
const { schema, writer } = conversionApi; | ||
const tableWidth = data.viewItem.getAttribute( dataAttribute ); | ||
|
||
// Do not go for the model element after data.modelCursor because it might happen | ||
// that a single view element was converted to multiple model elements. Get all of them. | ||
for ( const item of data.modelRange.getItems( { shallow: true } ) ) { | ||
if ( schema.checkAttribute( item, 'tableWidth' ) ) { | ||
writer.setAttribute( 'tableWidth', tableWidth, item ); | ||
} | ||
} | ||
}) | ||
); | ||
|
||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
modules/tide_ckeditor/modules/ckeditor_tablecol_resize/package.json
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 @@ | ||
{ | ||
"name": "drupal-editor-material-icons", | ||
"version": "2.0.0", | ||
"description": "Add material icons to ckeditor.", | ||
"author": "", | ||
"license": "GPL-2.0-or-later", | ||
"scripts": { | ||
"watch": "webpack --mode development --watch", | ||
"build": "webpack" | ||
}, | ||
"devDependencies": { | ||
"@ckeditor/ckeditor5-dev-utils": "^30.0.0", | ||
"ckeditor5": "~35.1.0", | ||
"css-loader": "^6.8.1", | ||
"raw-loader": "^4.0.2", | ||
"style-loader": "^3.3.3", | ||
"terser-webpack-plugin": "^5.3.3", | ||
"webpack": "^5.51.1", | ||
"webpack-cli": "^4.4.0" | ||
} | ||
} |
121 changes: 121 additions & 0 deletions
121
..._ckeditor/modules/ckeditor_tablecol_resize/src/Plugin/Filter/FilterResizeTableColumns.php
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,121 @@ | ||
<?php | ||
|
||
namespace Drupal\ckeditor_tablecol_resize\Plugin\Filter; | ||
|
||
use Drupal\ckeditor5\Plugin\CKEditor5PluginManagerInterface; | ||
use Drupal\Component\Utility\Html; | ||
use Drupal\Core\Entity\EntityTypeManagerInterface; | ||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface; | ||
use Drupal\Core\Routing\CurrentRouteMatch; | ||
use Drupal\filter\FilterProcessResult; | ||
use Drupal\filter\Plugin\FilterBase; | ||
use Psr\Container\ContainerInterface; | ||
|
||
/** | ||
* Provides a filter to apply resizing of table columns. | ||
* | ||
* @Filter( | ||
* id = "filter_resize_tablecolumns", | ||
* title = @Translation("Resize table columns"), | ||
* description = @Translation("Uses a <code>data-resize-width</code> attribute on <code><col></code> tags to apply resizing of table columns. This filter needs to run after the <strong>Limit allowed HTML tags and correct faulty HTML</strong> filter."), | ||
* type = Drupal\filter\Plugin\FilterInterface::TYPE_TRANSFORM_REVERSIBLE, | ||
* weight = 99, | ||
* ) | ||
*/ | ||
class FilterResizeTableColumns extends FilterBase implements ContainerFactoryPluginInterface { | ||
|
||
protected CKEditor5PluginManagerInterface $ckeditor5PluginManager; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { | ||
$instance = new static($configuration, $plugin_id, $plugin_definition); | ||
$instance->ckeditor5PluginManager = $container->get('plugin.manager.ckeditor5.plugin'); | ||
return $instance; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function process($text, $langcode) { | ||
$ckeditor5_plugin = $this->ckeditor5PluginManager | ||
->createInstance('ckeditor_tablecol_resize_tableColResize'); | ||
$ckeditor5_plugin_config = $ckeditor5_plugin->getPluginDefinition()->getCkeditor5Config()['tableColResize']; | ||
$column_data_attribute = $ckeditor5_plugin_config['dataAttribute']; | ||
$result = new FilterProcessResult($text); | ||
|
||
if (stristr($text, $column_data_attribute) !== FALSE) { | ||
$dom = Html::load($text); | ||
$xpath = new \DOMXPath($dom); | ||
|
||
/** @var \DOMNode $node */ | ||
foreach ($xpath->query('//*[@' . $column_data_attribute . ']') as $node) { | ||
$this->processDomNode($node, $column_data_attribute); | ||
} | ||
|
||
$result->setProcessedText(Html::serialize($dom)); | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* Adds a style and class attributes to passed DOMNode. | ||
*/ | ||
private function processDomNode(\DOMNode $node, string $attribute) : void { | ||
[, $attribute_value] = $this->getStyleAttributeFromNode($node, $attribute); | ||
$node->setAttribute('style', $attribute_value); | ||
|
||
// Set a class that allows targetting resized columns in CSS/JS. | ||
$node->setAttribute( | ||
'class', | ||
$node->getAttribute('class') | ||
? $node->getAttribute('class') . ' ckeditor-tablecol-resized' | ||
: 'ckeditor-tablecol-resized' | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function tips($long = FALSE) { | ||
if ($long) { | ||
return $this->t(' | ||
<p>Applies the resizing of tables and columns when rendering the ckeditor content in Drupal.</p> | ||
<p>This works via a the <code>data-resize-width</code> attribute on <code><col></code> tags, for example: <code><col data-resize-width="99%"</code>.</p> | ||
'); | ||
} | ||
else { | ||
return $this->t('Allows resizing of table columns by adding the <code>data-resize-width</code> attribute on <code><col></code> tags, for example: <code><col data-resize-width="99%"</code>.'); | ||
} | ||
} | ||
|
||
/** | ||
* Gets $width from style attribute on given node and attribute. | ||
*/ | ||
public function getStyleAttributeFromNode(\DOMNode $node, string $attribute): array { | ||
$width = $node->getAttribute($attribute); | ||
$node->removeAttribute($attribute); | ||
$attribute_value = $node->getAttribute('style'); | ||
|
||
// Replace existing width style with new one. | ||
$styles = \explode(';', $attribute_value); | ||
$to_replace = ''; | ||
foreach ($styles as $style) { | ||
if (\mb_strpos($style, 'width') === 0) { | ||
$to_replace = $style; | ||
break; | ||
} | ||
} | ||
if ($to_replace) { | ||
$attribute_value = \str_replace($to_replace, 'width:' . $width, $attribute_value); | ||
} | ||
else { | ||
$attribute_value .= 'width:' . $width . ';'; | ||
} | ||
|
||
return [(int) $width, $attribute_value]; | ||
} | ||
|
||
} |
Oops, something went wrong.