@ckeditor/ckeditor5-indent 36.0.1 → 37.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/indent.js +1 -1
- package/package.json +18 -13
- package/src/augmentation.d.ts +24 -0
- package/src/augmentation.js +5 -0
- package/src/indent.d.ts +38 -0
- package/src/indent.js +12 -19
- package/src/indentblock.d.ts +42 -0
- package/src/indentblock.js +120 -212
- package/src/indentblockcommand.d.ts +45 -0
- package/src/indentblockcommand.js +53 -97
- package/src/indentcommandbehavior/indentbehavior.d.ts +21 -0
- package/src/indentcommandbehavior/indentbehavior.js +5 -0
- package/src/indentcommandbehavior/indentusingclasses.d.ts +39 -0
- package/src/indentcommandbehavior/indentusingclasses.js +30 -52
- package/src/indentcommandbehavior/indentusingoffset.d.ts +45 -0
- package/src/indentcommandbehavior/indentusingoffset.js +33 -65
- package/src/indentconfig.d.ts +72 -0
- package/src/indentconfig.js +5 -0
- package/src/indentediting.d.ts +26 -0
- package/src/indentediting.js +14 -21
- package/src/indentui.d.ts +27 -0
- package/src/indentui.js +39 -58
- package/src/index.d.ts +14 -0
- package/src/index.js +1 -2
package/build/indent.js
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
/*!
|
|
3
3
|
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
4
4
|
* For licensing, see LICENSE.md.
|
|
5
|
-
*/(()=>{var t={704:(t,e,n)=>{t.exports=n(79)("./src/core.js")},492:(t,e,n)=>{t.exports=n(79)("./src/engine.js")},273:(t,e,n)=>{t.exports=n(79)("./src/ui.js")},209:(t,e,n)=>{t.exports=n(79)("./src/utils.js")},79:t=>{"use strict";t.exports=CKEditor5.dll}},e={};function n(s){var i=e[s];if(void 0!==i)return i.exports;var o=e[s]={exports:{}};return t[s](o,o.exports,n),o.exports}n.d=(t,e)=>{for(var s in e)n.o(e,s)&&!n.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:e[s]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var s={};(()=>{"use strict";n.r(s),n.d(s,{Indent:()=>a,IndentBlock:()=>f,IndentEditing:()=>e,IndentUI:()=>d});var t=n(704);class e extends t.Plugin{static get pluginName(){return"IndentEditing"}init(){const e=this.editor;e.commands.add("indent",new t.MultiCommand(e)),e.commands.add("outdent",new t.MultiCommand(e))}}var i=n(273);const o='<svg viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M2 3.75c0 .414.336.75.75.75h14.5a.75.75 0 1 0 0-1.5H2.75a.75.75 0 0 0-.75.75zm5 6c0 .414.336.75.75.75h9.5a.75.75 0 1 0 0-1.5h-9.5a.75.75 0 0 0-.75.75zM2.75 16.5h14.5a.75.75 0 1 0 0-1.5H2.75a.75.75 0 1 0 0 1.5zM1.632 6.95 5.02 9.358a.4.4 0 0 1-.013.661l-3.39 2.207A.4.4 0 0 1 1 11.892V7.275a.4.4 0 0 1 .632-.326z"/></svg>',r='<svg viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M2 3.75c0 .414.336.75.75.75h14.5a.75.75 0 1 0 0-1.5H2.75a.75.75 0 0 0-.75.75zm5 6c0 .414.336.75.75.75h9.5a.75.75 0 1 0 0-1.5h-9.5a.75.75 0 0 0-.75.75zM2.75 16.5h14.5a.75.75 0 1 0 0-1.5H2.75a.75.75 0 1 0 0 1.5zm1.618-9.55L.98 9.358a.4.4 0 0 0 .013.661l3.39 2.207A.4.4 0 0 0 5 11.892V7.275a.4.4 0 0 0-.632-.326z"/></svg>';class d extends t.Plugin{static get pluginName(){return"IndentUI"}init(){const t=this.editor,e=t.locale,n=t.t,s="ltr"==e.uiLanguageDirection?o:r,i="ltr"==e.uiLanguageDirection?r:o;this._defineButton("indent",n("Increase indent"),s),this._defineButton("outdent",n("Decrease indent"),i)}_defineButton(t,e,n){const s=this.editor;s.ui.componentFactory.add(t,(o=>{const r=s.commands.get(t),d=new i.ButtonView(o);return d.set({label:e,icon:n,tooltip:!0}),d.bind("
|
|
5
|
+
*/(()=>{var t={704:(t,e,n)=>{t.exports=n(79)("./src/core.js")},492:(t,e,n)=>{t.exports=n(79)("./src/engine.js")},273:(t,e,n)=>{t.exports=n(79)("./src/ui.js")},209:(t,e,n)=>{t.exports=n(79)("./src/utils.js")},79:t=>{"use strict";t.exports=CKEditor5.dll}},e={};function n(s){var i=e[s];if(void 0!==i)return i.exports;var o=e[s]={exports:{}};return t[s](o,o.exports,n),o.exports}n.d=(t,e)=>{for(var s in e)n.o(e,s)&&!n.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:e[s]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var s={};(()=>{"use strict";n.r(s),n.d(s,{Indent:()=>a,IndentBlock:()=>f,IndentEditing:()=>e,IndentUI:()=>d});var t=n(704);class e extends t.Plugin{static get pluginName(){return"IndentEditing"}init(){const e=this.editor;e.commands.add("indent",new t.MultiCommand(e)),e.commands.add("outdent",new t.MultiCommand(e))}}var i=n(273);const o='<svg viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M2 3.75c0 .414.336.75.75.75h14.5a.75.75 0 1 0 0-1.5H2.75a.75.75 0 0 0-.75.75zm5 6c0 .414.336.75.75.75h9.5a.75.75 0 1 0 0-1.5h-9.5a.75.75 0 0 0-.75.75zM2.75 16.5h14.5a.75.75 0 1 0 0-1.5H2.75a.75.75 0 1 0 0 1.5zM1.632 6.95 5.02 9.358a.4.4 0 0 1-.013.661l-3.39 2.207A.4.4 0 0 1 1 11.892V7.275a.4.4 0 0 1 .632-.326z"/></svg>',r='<svg viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M2 3.75c0 .414.336.75.75.75h14.5a.75.75 0 1 0 0-1.5H2.75a.75.75 0 0 0-.75.75zm5 6c0 .414.336.75.75.75h9.5a.75.75 0 1 0 0-1.5h-9.5a.75.75 0 0 0-.75.75zM2.75 16.5h14.5a.75.75 0 1 0 0-1.5H2.75a.75.75 0 1 0 0 1.5zm1.618-9.55L.98 9.358a.4.4 0 0 0 .013.661l3.39 2.207A.4.4 0 0 0 5 11.892V7.275a.4.4 0 0 0-.632-.326z"/></svg>';class d extends t.Plugin{static get pluginName(){return"IndentUI"}init(){const t=this.editor,e=t.locale,n=t.t,s="ltr"==e.uiLanguageDirection?o:r,i="ltr"==e.uiLanguageDirection?r:o;this._defineButton("indent",n("Increase indent"),s),this._defineButton("outdent",n("Decrease indent"),i)}_defineButton(t,e,n){const s=this.editor;s.ui.componentFactory.add(t,(o=>{const r=s.commands.get(t),d=new i.ButtonView(o);return d.set({label:e,icon:n,tooltip:!0}),d.bind("isEnabled").to(r,"isEnabled"),this.listenTo(d,"execute",(()=>{s.execute(t),s.editing.view.focus()})),d}))}}class a extends t.Plugin{static get pluginName(){return"Indent"}static get requires(){return[e,d]}}var c=n(492),l=n(209);class u extends t.Command{constructor(t,e){super(t),this._indentBehavior=e}refresh(){const t=this.editor.model,e=(0,l.first)(t.document.selection.getSelectedBlocks());e&&t.schema.checkAttribute(e,"blockIndent")?this.isEnabled=this._indentBehavior.checkEnabled(e.getAttribute("blockIndent")):this.isEnabled=!1}execute(){const t=this.editor.model,e=function(t){const e=t.document.selection,n=t.schema;return Array.from(e.getSelectedBlocks()).filter((t=>n.checkAttribute(t,"blockIndent")))}(t);t.change((t=>{for(const n of e){const e=n.getAttribute("blockIndent"),s=this._indentBehavior.getNextIndent(e);s?t.setAttribute("blockIndent",s,n):t.removeAttribute("blockIndent",n)}}))}}class h{constructor(t){this.isForward="forward"===t.direction,this.offset=t.offset,this.unit=t.unit}checkEnabled(t){const e=parseFloat(t||"0");return this.isForward||e>0}getNextIndent(t){const e=parseFloat(t||"0");if(!(!t||t.endsWith(this.unit)))return this.isForward?this.offset+this.unit:void 0;const n=e+(this.isForward?this.offset:-this.offset);return n>0?n+this.unit:void 0}}class g{constructor(t){this.isForward="forward"===t.direction,this.classes=t.classes}checkEnabled(t){const e=this.classes.indexOf(t);return this.isForward?e<this.classes.length-1:e>=0}getNextIndent(t){const e=this.classes.indexOf(t),n=this.isForward?1:-1;return this.classes[e+n]}}const m=["paragraph","heading1","heading2","heading3","heading4","heading5","heading6"];class f extends t.Plugin{constructor(t){super(t),t.config.define("indentBlock",{offset:40,unit:"px"})}static get pluginName(){return"IndentBlock"}init(){const t=this.editor,e=t.config.get("indentBlock");e.classes&&e.classes.length?(this._setupConversionUsingClasses(e.classes),t.commands.add("indentBlock",new u(t,new g({direction:"forward",classes:e.classes}))),t.commands.add("outdentBlock",new u(t,new g({direction:"backward",classes:e.classes})))):(t.data.addStyleProcessorRules(c.addMarginRules),this._setupConversionUsingOffset(),t.commands.add("indentBlock",new u(t,new h({direction:"forward",offset:e.offset,unit:e.unit}))),t.commands.add("outdentBlock",new u(t,new h({direction:"backward",offset:e.offset,unit:e.unit}))))}afterInit(){const t=this.editor,e=t.model.schema,n=t.commands.get("indent"),s=t.commands.get("outdent"),i=t.config.get("heading.options");(i&&i.map((t=>t.model))||m).forEach((t=>{e.isRegistered(t)&&e.extend(t,{allowAttributes:"blockIndent"})})),e.setAttributeProperties("blockIndent",{isFormatting:!0}),n.registerChildCommand(t.commands.get("indentBlock")),s.registerChildCommand(t.commands.get("outdentBlock"))}_setupConversionUsingOffset(){const t=this.editor.conversion,e="rtl"===this.editor.locale.contentLanguageDirection?"margin-right":"margin-left";t.for("upcast").attributeToAttribute({view:{styles:{[e]:/[\s\S]+/}},model:{key:"blockIndent",value:t=>t.getStyle(e)}}),t.for("downcast").attributeToAttribute({model:"blockIndent",view:t=>({key:"style",value:{[e]:t}})})}_setupConversionUsingClasses(t){const e={model:{key:"blockIndent",values:[]},view:{}};for(const n of t)e.model.values.push(n),e.view[n]={key:"class",value:[n]};this.editor.conversion.attributeToAttribute(e)}}})(),(window.CKEditor5=window.CKEditor5||{}).indent=s})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckeditor/ckeditor5-indent",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "37.0.0-alpha.1",
|
|
4
4
|
"description": "Block indentation feature for CKEditor 5.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ckeditor",
|
|
@@ -12,17 +12,18 @@
|
|
|
12
12
|
],
|
|
13
13
|
"main": "src/index.js",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"ckeditor5": "^
|
|
15
|
+
"ckeditor5": "^37.0.0-alpha.1"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"@ckeditor/ckeditor5-core": "^
|
|
19
|
-
"@ckeditor/ckeditor5-dev-utils": "^
|
|
20
|
-
"@ckeditor/ckeditor5-editor-classic": "^
|
|
21
|
-
"@ckeditor/ckeditor5-engine": "^
|
|
22
|
-
"@ckeditor/ckeditor5-heading": "^
|
|
23
|
-
"@ckeditor/ckeditor5-paragraph": "^
|
|
24
|
-
"@ckeditor/ckeditor5-theme-lark": "^
|
|
25
|
-
"@ckeditor/ckeditor5-ui": "^
|
|
18
|
+
"@ckeditor/ckeditor5-core": "^37.0.0-alpha.1",
|
|
19
|
+
"@ckeditor/ckeditor5-dev-utils": "^35.0.0",
|
|
20
|
+
"@ckeditor/ckeditor5-editor-classic": "^37.0.0-alpha.1",
|
|
21
|
+
"@ckeditor/ckeditor5-engine": "^37.0.0-alpha.1",
|
|
22
|
+
"@ckeditor/ckeditor5-heading": "^37.0.0-alpha.1",
|
|
23
|
+
"@ckeditor/ckeditor5-paragraph": "^37.0.0-alpha.1",
|
|
24
|
+
"@ckeditor/ckeditor5-theme-lark": "^37.0.0-alpha.1",
|
|
25
|
+
"@ckeditor/ckeditor5-ui": "^37.0.0-alpha.1",
|
|
26
|
+
"typescript": "^4.8.4",
|
|
26
27
|
"webpack": "^5.58.1",
|
|
27
28
|
"webpack-cli": "^4.9.0"
|
|
28
29
|
},
|
|
@@ -41,13 +42,17 @@
|
|
|
41
42
|
},
|
|
42
43
|
"files": [
|
|
43
44
|
"lang",
|
|
44
|
-
"src",
|
|
45
|
+
"src/**/*.js",
|
|
46
|
+
"src/**/*.d.ts",
|
|
45
47
|
"theme",
|
|
46
48
|
"build",
|
|
47
49
|
"ckeditor5-metadata.json",
|
|
48
50
|
"CHANGELOG.md"
|
|
49
51
|
],
|
|
50
52
|
"scripts": {
|
|
51
|
-
"dll:build": "webpack"
|
|
52
|
-
|
|
53
|
+
"dll:build": "webpack",
|
|
54
|
+
"build": "tsc -p ./tsconfig.json",
|
|
55
|
+
"postversion": "npm run build"
|
|
56
|
+
},
|
|
57
|
+
"types": "src/index.d.ts"
|
|
53
58
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
import type { IndentBlockConfig, Indent, IndentBlock, IndentUI, IndentBlockCommand } from './index';
|
|
6
|
+
declare module '@ckeditor/ckeditor5-core' {
|
|
7
|
+
interface EditorConfig {
|
|
8
|
+
/**
|
|
9
|
+
* The configuration of the {@link module:indent/indentblock~IndentBlock block indentation feature}.
|
|
10
|
+
*
|
|
11
|
+
* Read more in {@link module:indent/indentconfig~IndentBlockConfig}.
|
|
12
|
+
*/
|
|
13
|
+
indentBlock?: IndentBlockConfig;
|
|
14
|
+
}
|
|
15
|
+
interface PluginsMap {
|
|
16
|
+
[Indent.pluginName]: Indent;
|
|
17
|
+
[IndentBlock.pluginName]: IndentBlock;
|
|
18
|
+
[IndentUI.pluginName]: IndentUI;
|
|
19
|
+
}
|
|
20
|
+
interface CommandsMap {
|
|
21
|
+
indentBlock: IndentBlockCommand;
|
|
22
|
+
outdentBlock: IndentBlockCommand;
|
|
23
|
+
}
|
|
24
|
+
}
|
package/src/indent.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module indent/indent
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin, type PluginDependencies } from 'ckeditor5/src/core';
|
|
9
|
+
/**
|
|
10
|
+
* The indent feature.
|
|
11
|
+
*
|
|
12
|
+
* This plugin acts as a single entry point plugin for other features that implement indentation of elements like lists or paragraphs.
|
|
13
|
+
*
|
|
14
|
+
* The compatible features are:
|
|
15
|
+
*
|
|
16
|
+
* * The {@link module:list/list~List} or {@link module:list/list/listediting~ListEditing} feature for list indentation.
|
|
17
|
+
* * The {@link module:indent/indentblock~IndentBlock} feature for block indentation.
|
|
18
|
+
*
|
|
19
|
+
* This is a "glue" plugin that loads the following plugins:
|
|
20
|
+
*
|
|
21
|
+
* * The {@link module:indent/indentediting~IndentEditing indent editing feature}.
|
|
22
|
+
* * The {@link module:indent/indentui~IndentUI indent UI feature}.
|
|
23
|
+
*
|
|
24
|
+
* The dependent plugins register the `'indent'` and `'outdent'` commands and introduce the `'indent'` and `'outdent'` buttons
|
|
25
|
+
* that allow to increase or decrease text indentation of supported elements.
|
|
26
|
+
*
|
|
27
|
+
* **Note**: In order for the commands and buttons to work, at least one of compatible features is required.
|
|
28
|
+
*/
|
|
29
|
+
export default class Indent extends Plugin {
|
|
30
|
+
/**
|
|
31
|
+
* @inheritDoc
|
|
32
|
+
*/
|
|
33
|
+
static get pluginName(): 'Indent';
|
|
34
|
+
/**
|
|
35
|
+
* @inheritDoc
|
|
36
|
+
*/
|
|
37
|
+
static get requires(): PluginDependencies;
|
|
38
|
+
}
|
package/src/indent.js
CHANGED
|
@@ -2,16 +2,12 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* @module indent/indent
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
import { Plugin } from 'ckeditor5/src/core';
|
|
11
|
-
|
|
12
9
|
import IndentEditing from './indentediting';
|
|
13
10
|
import IndentUI from './indentui';
|
|
14
|
-
|
|
15
11
|
/**
|
|
16
12
|
* The indent feature.
|
|
17
13
|
*
|
|
@@ -31,21 +27,18 @@ import IndentUI from './indentui';
|
|
|
31
27
|
* that allow to increase or decrease text indentation of supported elements.
|
|
32
28
|
*
|
|
33
29
|
* **Note**: In order for the commands and buttons to work, at least one of compatible features is required.
|
|
34
|
-
*
|
|
35
|
-
* @extends module:core/plugin~Plugin
|
|
36
30
|
*/
|
|
37
31
|
export default class Indent extends Plugin {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
32
|
+
/**
|
|
33
|
+
* @inheritDoc
|
|
34
|
+
*/
|
|
35
|
+
static get pluginName() {
|
|
36
|
+
return 'Indent';
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* @inheritDoc
|
|
40
|
+
*/
|
|
41
|
+
static get requires() {
|
|
42
|
+
return [IndentEditing, IndentUI];
|
|
43
|
+
}
|
|
51
44
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module indent/indentblock
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin, type Editor } from 'ckeditor5/src/core';
|
|
9
|
+
/**
|
|
10
|
+
* The block indentation feature.
|
|
11
|
+
*
|
|
12
|
+
* It registers the `'indentBlock'` and `'outdentBlock'` commands.
|
|
13
|
+
*
|
|
14
|
+
* If the plugin {@link module:indent/indent~Indent} is defined, it also attaches the `'indentBlock'` and `'outdentBlock'` commands to
|
|
15
|
+
* the `'indent'` and `'outdent'` commands.
|
|
16
|
+
*/
|
|
17
|
+
export default class IndentBlock extends Plugin {
|
|
18
|
+
/**
|
|
19
|
+
* @inheritDoc
|
|
20
|
+
*/
|
|
21
|
+
constructor(editor: Editor);
|
|
22
|
+
/**
|
|
23
|
+
* @inheritDoc
|
|
24
|
+
*/
|
|
25
|
+
static get pluginName(): 'IndentBlock';
|
|
26
|
+
/**
|
|
27
|
+
* @inheritDoc
|
|
28
|
+
*/
|
|
29
|
+
init(): void;
|
|
30
|
+
/**
|
|
31
|
+
* @inheritDoc
|
|
32
|
+
*/
|
|
33
|
+
afterInit(): void;
|
|
34
|
+
/**
|
|
35
|
+
* Setups conversion for using offset indents.
|
|
36
|
+
*/
|
|
37
|
+
private _setupConversionUsingOffset;
|
|
38
|
+
/**
|
|
39
|
+
* Setups conversion for using classes.
|
|
40
|
+
*/
|
|
41
|
+
private _setupConversionUsingClasses;
|
|
42
|
+
}
|
package/src/indentblock.js
CHANGED
|
@@ -2,20 +2,15 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* @module indent/indentblock
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
import { Plugin } from 'ckeditor5/src/core';
|
|
11
9
|
import { addMarginRules } from 'ckeditor5/src/engine';
|
|
12
|
-
|
|
13
10
|
import IndentBlockCommand from './indentblockcommand';
|
|
14
11
|
import IndentUsingOffset from './indentcommandbehavior/indentusingoffset';
|
|
15
12
|
import IndentUsingClasses from './indentcommandbehavior/indentusingclasses';
|
|
16
|
-
|
|
17
|
-
const DEFAULT_ELEMENTS = [ 'paragraph', 'heading1', 'heading2', 'heading3', 'heading4', 'heading5', 'heading6' ];
|
|
18
|
-
|
|
13
|
+
const DEFAULT_ELEMENTS = ['paragraph', 'heading1', 'heading2', 'heading3', 'heading4', 'heading5', 'heading6'];
|
|
19
14
|
/**
|
|
20
15
|
* The block indentation feature.
|
|
21
16
|
*
|
|
@@ -23,212 +18,125 @@ const DEFAULT_ELEMENTS = [ 'paragraph', 'heading1', 'heading2', 'heading3', 'hea
|
|
|
23
18
|
*
|
|
24
19
|
* If the plugin {@link module:indent/indent~Indent} is defined, it also attaches the `'indentBlock'` and `'outdentBlock'` commands to
|
|
25
20
|
* the `'indent'` and `'outdent'` commands.
|
|
26
|
-
*
|
|
27
|
-
* @extends module:core/plugin~Plugin
|
|
28
21
|
*/
|
|
29
22
|
export default class IndentBlock extends Plugin {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
for ( const className of classes ) {
|
|
152
|
-
definition.model.values.push( className );
|
|
153
|
-
definition.view[ className ] = {
|
|
154
|
-
key: 'class',
|
|
155
|
-
value: [ className ]
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
this.editor.conversion.attributeToAttribute( definition );
|
|
160
|
-
}
|
|
23
|
+
/**
|
|
24
|
+
* @inheritDoc
|
|
25
|
+
*/
|
|
26
|
+
constructor(editor) {
|
|
27
|
+
super(editor);
|
|
28
|
+
editor.config.define('indentBlock', {
|
|
29
|
+
offset: 40,
|
|
30
|
+
unit: 'px'
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* @inheritDoc
|
|
35
|
+
*/
|
|
36
|
+
static get pluginName() {
|
|
37
|
+
return 'IndentBlock';
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* @inheritDoc
|
|
41
|
+
*/
|
|
42
|
+
init() {
|
|
43
|
+
const editor = this.editor;
|
|
44
|
+
const configuration = editor.config.get('indentBlock');
|
|
45
|
+
if (configuration.classes && configuration.classes.length) {
|
|
46
|
+
this._setupConversionUsingClasses(configuration.classes);
|
|
47
|
+
editor.commands.add('indentBlock', new IndentBlockCommand(editor, new IndentUsingClasses({
|
|
48
|
+
direction: 'forward',
|
|
49
|
+
classes: configuration.classes
|
|
50
|
+
})));
|
|
51
|
+
editor.commands.add('outdentBlock', new IndentBlockCommand(editor, new IndentUsingClasses({
|
|
52
|
+
direction: 'backward',
|
|
53
|
+
classes: configuration.classes
|
|
54
|
+
})));
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
editor.data.addStyleProcessorRules(addMarginRules);
|
|
58
|
+
this._setupConversionUsingOffset();
|
|
59
|
+
editor.commands.add('indentBlock', new IndentBlockCommand(editor, new IndentUsingOffset({
|
|
60
|
+
direction: 'forward',
|
|
61
|
+
offset: configuration.offset,
|
|
62
|
+
unit: configuration.unit
|
|
63
|
+
})));
|
|
64
|
+
editor.commands.add('outdentBlock', new IndentBlockCommand(editor, new IndentUsingOffset({
|
|
65
|
+
direction: 'backward',
|
|
66
|
+
offset: configuration.offset,
|
|
67
|
+
unit: configuration.unit
|
|
68
|
+
})));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* @inheritDoc
|
|
73
|
+
*/
|
|
74
|
+
afterInit() {
|
|
75
|
+
const editor = this.editor;
|
|
76
|
+
const schema = editor.model.schema;
|
|
77
|
+
const indentCommand = editor.commands.get('indent');
|
|
78
|
+
const outdentCommand = editor.commands.get('outdent');
|
|
79
|
+
// Enable block indentation to heading configuration options. If it is not defined enable in paragraph and default headings.
|
|
80
|
+
const options = editor.config.get('heading.options');
|
|
81
|
+
const configuredElements = options && options.map(option => option.model);
|
|
82
|
+
const knownElements = configuredElements || DEFAULT_ELEMENTS;
|
|
83
|
+
knownElements.forEach(elementName => {
|
|
84
|
+
if (schema.isRegistered(elementName)) {
|
|
85
|
+
schema.extend(elementName, { allowAttributes: 'blockIndent' });
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
schema.setAttributeProperties('blockIndent', { isFormatting: true });
|
|
89
|
+
indentCommand.registerChildCommand(editor.commands.get('indentBlock'));
|
|
90
|
+
outdentCommand.registerChildCommand(editor.commands.get('outdentBlock'));
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Setups conversion for using offset indents.
|
|
94
|
+
*/
|
|
95
|
+
_setupConversionUsingOffset() {
|
|
96
|
+
const conversion = this.editor.conversion;
|
|
97
|
+
const locale = this.editor.locale;
|
|
98
|
+
const marginProperty = locale.contentLanguageDirection === 'rtl' ? 'margin-right' : 'margin-left';
|
|
99
|
+
conversion.for('upcast').attributeToAttribute({
|
|
100
|
+
view: {
|
|
101
|
+
styles: {
|
|
102
|
+
[marginProperty]: /[\s\S]+/
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
model: {
|
|
106
|
+
key: 'blockIndent',
|
|
107
|
+
value: (viewElement) => viewElement.getStyle(marginProperty)
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
conversion.for('downcast').attributeToAttribute({
|
|
111
|
+
model: 'blockIndent',
|
|
112
|
+
view: modelAttributeValue => {
|
|
113
|
+
return {
|
|
114
|
+
key: 'style',
|
|
115
|
+
value: {
|
|
116
|
+
[marginProperty]: modelAttributeValue
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Setups conversion for using classes.
|
|
124
|
+
*/
|
|
125
|
+
_setupConversionUsingClasses(classes) {
|
|
126
|
+
const definition = {
|
|
127
|
+
model: {
|
|
128
|
+
key: 'blockIndent',
|
|
129
|
+
values: []
|
|
130
|
+
},
|
|
131
|
+
view: {}
|
|
132
|
+
};
|
|
133
|
+
for (const className of classes) {
|
|
134
|
+
definition.model.values.push(className);
|
|
135
|
+
definition.view[className] = {
|
|
136
|
+
key: 'class',
|
|
137
|
+
value: [className]
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
this.editor.conversion.attributeToAttribute(definition);
|
|
141
|
+
}
|
|
161
142
|
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* The configuration of the {@link module:indent/indentblock~IndentBlock block indentation feature}.
|
|
165
|
-
*
|
|
166
|
-
* Read more in {@link module:indent/indentblock~IndentBlockConfig}.
|
|
167
|
-
*
|
|
168
|
-
* @member {module:indent/indentblock~IndentBlockConfig} module:core/editor/editorconfig~EditorConfig#indentBlock
|
|
169
|
-
*/
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* The configuration of the block indentation feature.
|
|
173
|
-
*
|
|
174
|
-
* If no {@link module:indent/indentblock~IndentBlockConfig#classes} are set, the block indentation feature will use
|
|
175
|
-
* {@link module:indent/indentblock~IndentBlockConfig#offset} and {@link module:indent/indentblock~IndentBlockConfig#unit} to
|
|
176
|
-
* create indentation steps.
|
|
177
|
-
*
|
|
178
|
-
* ClassicEditor
|
|
179
|
-
* .create( editorElement, {
|
|
180
|
-
* indentBlock: {
|
|
181
|
-
* offset: 2,
|
|
182
|
-
* unit: 'em'
|
|
183
|
-
* }
|
|
184
|
-
* } )
|
|
185
|
-
* .then( ... )
|
|
186
|
-
* .catch( ... );
|
|
187
|
-
*
|
|
188
|
-
* Alternatively, the block indentation feature may set one of defined {@link module:indent/indentblock~IndentBlockConfig#classes} as
|
|
189
|
-
* indentation steps:
|
|
190
|
-
*
|
|
191
|
-
* ClassicEditor
|
|
192
|
-
* .create( editorElement, {
|
|
193
|
-
* indentBlock: {
|
|
194
|
-
* classes: [
|
|
195
|
-
* 'indent-a', // The first step - smallest indentation.
|
|
196
|
-
* 'indent-b',
|
|
197
|
-
* 'indent-c',
|
|
198
|
-
* 'indent-d',
|
|
199
|
-
* 'indent-e' // The last step - biggest indentation.
|
|
200
|
-
* ]
|
|
201
|
-
* }
|
|
202
|
-
* } )
|
|
203
|
-
* .then( ... )
|
|
204
|
-
* .catch( ... );
|
|
205
|
-
*
|
|
206
|
-
* In the example above only 5 indentation steps will be available.
|
|
207
|
-
*
|
|
208
|
-
* See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
|
|
209
|
-
*
|
|
210
|
-
* @interface IndentBlockConfig
|
|
211
|
-
*/
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* The size of indentation {@link module:indent/indentblock~IndentBlockConfig#unit units} for each indentation step.
|
|
215
|
-
*
|
|
216
|
-
* @default 40
|
|
217
|
-
* @member {Number} module:indent/indentblock~IndentBlockConfig#offset
|
|
218
|
-
*/
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* The unit used for indentation {@link module:indent/indentblock~IndentBlockConfig#offset}.
|
|
222
|
-
*
|
|
223
|
-
* @default 'px'
|
|
224
|
-
* @member {String} module:indent/indentblock~IndentBlockConfig#unit
|
|
225
|
-
*/
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* An optional list of classes to use for indenting the editor content. If not set or set to an empty array, no classes will be used.
|
|
229
|
-
* The {@link module:indent/indentblock~IndentBlockConfig#unit `indentBlock.unit`} and
|
|
230
|
-
* {@link module:indent/indentblock~IndentBlockConfig#offset `indentBlock.offset`} properties will be used instead.
|
|
231
|
-
*
|
|
232
|
-
* @default undefined
|
|
233
|
-
* @member {Array.<String>|undefined} module:indent/indentblock~IndentBlockConfig#classes
|
|
234
|
-
*/
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module indent/indentblockcommand
|
|
7
|
+
*/
|
|
8
|
+
import { Command, type Editor } from 'ckeditor5/src/core';
|
|
9
|
+
import type { IndentBehavior } from './indentcommandbehavior/indentbehavior';
|
|
10
|
+
/**
|
|
11
|
+
* The indent block command.
|
|
12
|
+
*
|
|
13
|
+
* The command is registered by the {@link module:indent/indentblock~IndentBlock} as `'indentBlock'` for indenting blocks and
|
|
14
|
+
* `'outdentBlock'` for outdenting blocks.
|
|
15
|
+
*
|
|
16
|
+
* To increase block indentation at the current selection, execute the command:
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* editor.execute( 'indentBlock' );
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* To decrease block indentation at the current selection, execute the command:
|
|
23
|
+
*
|
|
24
|
+
* ```ts
|
|
25
|
+
* editor.execute( 'outdentBlock' );
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export default class IndentBlockCommand extends Command {
|
|
29
|
+
/**
|
|
30
|
+
* The command's indentation behavior.
|
|
31
|
+
*/
|
|
32
|
+
private readonly _indentBehavior;
|
|
33
|
+
/**
|
|
34
|
+
* Creates an instance of the command.
|
|
35
|
+
*/
|
|
36
|
+
constructor(editor: Editor, indentBehavior: IndentBehavior);
|
|
37
|
+
/**
|
|
38
|
+
* @inheritDoc
|
|
39
|
+
*/
|
|
40
|
+
refresh(): void;
|
|
41
|
+
/**
|
|
42
|
+
* @inheritDoc
|
|
43
|
+
*/
|
|
44
|
+
execute(): void;
|
|
45
|
+
}
|