Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include indent paragraph plugin #16

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 32 additions & 56 deletions package-lock.json

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

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lawmatics/ckeditor5-build-classic",
"version": "41.3.4",
"version": "41.4.5",
"description": "Lawmatics' custom CKeditor5 build",
"main": "./build/ckeditor.js",
"files": [
Expand Down Expand Up @@ -40,8 +40,7 @@
"@ckeditor/ckeditor5-table": "^41.3.1",
"@ckeditor/ckeditor5-typing": "^41.3.1",
"@ckeditor/ckeditor5-widget": "^41.3.1",
"@lawmatics/ckeditor5-paragraph-indent": "^1.0.4",
"dompurify": "^3.1.2",
"dompurify": "^3.1.3",
"sanitize-html": "^2.13.0"
},
"devDependencies": {
Expand All @@ -57,7 +56,7 @@
"style-loader": "^4.0.0",
"terser-webpack-plugin": "^5.3.9",
"typescript": "^5.4.5",
"webpack": "^5.91.0",
"webpack": "5.94.0",
"webpack-cli": "^5.1.4"
},
"engines": {
Expand Down
96 changes: 1 addition & 95 deletions src/ckeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,108 +33,15 @@ import { TextTransformation } from '@ckeditor/ckeditor5-typing';
import { CloudServices } from '@ckeditor/ckeditor5-cloud-services';
import { HtmlEmbed } from '@ckeditor/ckeditor5-html-embed';
import { MediaEmbed } from '@ckeditor/ckeditor5-media-embed';
import { Plugin } from '@ckeditor/ckeditor5-core';
import { Widget } from "@ckeditor/ckeditor5-widget";
import { Mention } from '@ckeditor/ckeditor5-mention';
import { Indent, IndentBlock } from '@ckeditor/ckeditor5-indent';
import { IndentParagraph } from '@lawmatics/ckeditor5-paragraph-indent';
import { ImportWord } from '@ckeditor/ckeditor5-import-word';
import MergeFieldCommand from "./commands/mergeFieldCommand";
import { EmTagItalicPlugin, MergeFieldPlugin, IndentParagraph } from './plugins'
import * as DOMPurify from 'dompurify';
import * as sanitizeHtml from 'sanitize-html';



import { toWidget, viewToModelPositionOutsideModelElement } from '@ckeditor/ckeditor5-widget/src/utils';

export default class ClassicEditor extends ClassicEditorBase {}

class EmTagItalicPlugin extends Plugin {
init() {
this.editor.conversion.for('downcast').attributeToElement({
model: 'italic',
view: 'em',
converterPriority: 'high',
});
this.editor.conversion.for('editingDowncast').attributeToElement({
model: 'italic',
view: 'em',
converterPriority: 'high',
upcastAlso: ['i', { styles: { 'font-style': 'italic' } }],
});
}
}

class MergeFieldPlugin extends Plugin {
static get requires() {
return [Widget];
}
init() {
this._defineSchema();
this._defineConverters();
this.editor.commands.add('mergeField', new MergeFieldCommand(this.editor));
this.editor.editing.mapper.on(
'viewToModelPosition',
viewToModelPositionOutsideModelElement(this.editor.model, viewElement => viewElement.hasClass('mergeField'))
);
}

_defineSchema() {
const schema = this.editor.model.schema;

schema.register('mergeField', {
allowWhere: '$text',
isInline: true,
isObject: true,
allowAttributesOf: '$text',
allowAttributes: ['name']
});
}

_defineConverters() {
const conversion = this.editor.conversion;

conversion.for('upcast').elementToElement({
view: { name: 'span', classes: ['mergeField'] },
model: (viewElement, { writer: modelWriter }) => {
// Seems that older iOS versions (<= 13) don't handle the optional chaining operator (?.) very well.
const element = viewElement.getChild(0);
if (element) {
const name = element.data;
if (name) return modelWriter.createElement('mergeField', { name });
}
}
});

conversion.for('editingDowncast').elementToElement({
model: 'mergeField',
view: (modelItem, { writer: viewWriter }) => {
const widgetElement = createMergeFieldView(modelItem, viewWriter);
return toWidget(widgetElement, viewWriter);
}
});

conversion.for('dataDowncast').elementToElement({
model: 'mergeField',
view: (modelItem, { writer: viewWriter }) => createMergeFieldView(modelItem, viewWriter)
});

// Helper method for both downcast converters.
function createMergeFieldView(modelItem, viewWriter) {
const name = modelItem.getAttribute('name');

const mergeFieldView = viewWriter.createContainerElement('span', {
class: 'mergeField'
});

const innerText = viewWriter.createText(name);
viewWriter.insert(viewWriter.createPositionAt(mergeFieldView, 0), innerText);

return mergeFieldView;
}
}
}

// Plugins to include in the build.
ClassicEditor.builtinPlugins = [
Essentials,
Expand Down Expand Up @@ -190,7 +97,6 @@ ClassicEditor.builtinPlugins = [
MediaEmbed,
Mention,
ImportWord,

EmTagItalicPlugin,
TextTransformation,
MergeFieldPlugin,
Expand Down
26 changes: 0 additions & 26 deletions src/commands/mergeFieldCommand.js

This file was deleted.

Loading