Skip to content

Commit

Permalink
fix add in between
Browse files Browse the repository at this point in the history
  • Loading branch information
ol0lll committed Apr 18, 2024
1 parent 4b5ccda commit 4844016
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ sites/**/libraries/**/*
profiles/**/libraries/**/*
**/js_test_files/**/*
js/build/*
js/ckeditor5_plugins/**/*
webpack.config.js
2 changes: 1 addition & 1 deletion js/build/split_paragraph.js

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

57 changes: 57 additions & 0 deletions js/ckeditor5_plugins/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"extends": [
"airbnb-base",
"plugin:prettier/recommended",
"plugin:yml/recommended"
],
"root": true,
"env": {
"browser": true,
"es6": true,
"node": true
},
"parserOptions": {
"ecmaVersion": 2020
},
"globals": {
"Drupal": true,
"drupalSettings": true,
"drupalTranslations": true,
"jQuery": true,
"_": true,
"Cookies": true,
"Backbone": true,
"Modernizr": true,
"loadjs": true,
"Shepherd": true,
"Sortable": true,
"once": true,
"CKEditor5": true,
"tabbable": true,
"slugify": true,
"bodyScrollLock" : true
},
"rules": {
"prettier/prettier": "error",
"consistent-return": ["off"],
"no-underscore-dangle": ["off"],
"max-nested-callbacks": ["warn", 3],
"import/no-mutable-exports": ["warn"],
"no-plusplus": ["warn", {
"allowForLoopAfterthoughts": true
}],
"no-param-reassign": ["off"],
"no-prototype-builtins": ["off"],
"valid-jsdoc": ["warn", {
"prefer": {
"returns": "return",
"property": "prop"
},
"requireReturn": false
}],
"no-unused-vars": ["warn"],
"operator-linebreak": ["error", "after", { "overrides": { "?": "ignore", ":": "ignore" } }],
"yml/indent": ["error", 2],
"max-len": ["error", { "code": 120 }]
}
}
16 changes: 10 additions & 6 deletions js/ckeditor5_plugins/split_paragraph/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,18 @@ class SplitParagraph extends Plugin {
afterInit() {
// Set value of the new paragraph.
if (window._splitParagraph) {
console.log(this.editor.sourceElement.dataset.drupalSelector);
console.log(this.editor.sourceElement.dataset.drupalSelector.match(window._splitParagraph.selector.replace(/-[0-9]+-?/, '-[0-9]+-')));
if (typeof window._splitParagraph.data.second === 'string') {
const paragraph = this.editor.sourceElement.closest('tr.draggable');
// this.editor.sourceElement.
// closest('.field--widget-paragraphs').querySelector('tr');
const previousParagraph = paragraph?.previousElementSibling;
if (previousParagraph && this.editor.sourceElement.dataset.drupalSelector.match(window._splitParagraph.selector.replace(/-[0-9]+-?/, '-[0-9]+-'))) {
let previousParagraph = paragraph?.previousElementSibling;

while (previousParagraph) {
if (previousParagraph.matches("tr.draggable")) break;
previousParagraph = previousParagraph.previousElementSibling;
}

if (
previousParagraph &&
this.editor.sourceElement.dataset.drupalSelector.match(window._splitParagraph.selector.replace(/-[0-9]+-?/, '-[0-9]+-'))) {
// Defer to wait until init is complete.
setTimeout(() => {
this.editor.setData(window._splitParagraph.data.second);
Expand Down
17 changes: 10 additions & 7 deletions tests/src/FunctionalJavascript/ParagraphsFeaturesSplitTextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,6 @@ public function testSplitTextFeature() {
$script = <<<JS
(function (editorId) {
const editor = Drupal.CKEditor5Instances.get(editorId);
console.log(editorId);
editor.model.change( writer => {
let newPosition;
const selection = writer.createSelection(editor.model.document.getRoot(), 'in');
Expand Down Expand Up @@ -452,7 +451,6 @@ public function testSplitTextFeature() {
$script = <<<JS
(function (editorId) {
const editor = Drupal.CKEditor5Instances.get(editorId);
console.log(editorId);
editor.model.change( writer => {
let newPosition;
const selection = writer.createSelection(editor.model.document.getRoot(), 'in');
Expand Down Expand Up @@ -499,6 +497,16 @@ public function testSplitTextFeature() {
$page->checkField('fields[field_paragraphs][settings_edit_form][third_party_settings][paragraphs_features][add_in_between]');
$this->assertEquals(TRUE, $session->evaluateScript("document.querySelector('.paragraphs-features__add-in-between__option').checked"), 'Checkbox should be checked.');

// Disable auto-collapse.
$page->selectFieldOption('fields[field_paragraphs][settings_edit_form][settings][autocollapse]', 'none');
$session->executeScript("jQuery('[name=\"fields[field_paragraphs][settings_edit_form][settings][autocollapse]\"]').trigger('change');");
$this->assertSession()->assertWaitOnAjaxRequest();

// Set edit mode to open.
$page->selectFieldOption('fields[field_paragraphs][settings_edit_form][settings][edit_mode]', 'open');
$session->executeScript("jQuery('[name=\"fields[field_paragraphs][settings_edit_form][settings][edit_mode]\"]').trigger('change');");
$this->assertSession()->assertWaitOnAjaxRequest();

$this->submitForm([], 'Update');
$this->assertSession()->assertWaitOnAjaxRequest();
$this->submitForm([], 'Save');
Expand All @@ -520,7 +528,6 @@ public function testSplitTextFeature() {
$script = <<<JS
(function (editorId) {
const editor = Drupal.CKEditor5Instances.get(editorId);
console.log(editorId);
editor.model.change( writer => {
let newPosition;
const selection = writer.createSelection(editor.model.document.getRoot(), 'in');
Expand All @@ -546,10 +553,6 @@ public function testSplitTextFeature() {
$driver->evaluateScript("Drupal.CKEditor5Instances.get('$ck_editor_id_1').getData();")
);

// And then original collapsed paragraph.
$this->scrollClick('css', '[name=field_paragraphs_0_edit]');
$this->assertSession()->assertWaitOnAjaxRequest();

$ck_editor_id_0 = $this->getCkEditorId(0);
static::assertEquals(
$paragraph_content_0,
Expand Down

0 comments on commit 4844016

Please sign in to comment.