@ckeditor/ckeditor5-table 47.2.0 → 47.3.0-alpha.0
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/LICENSE.md +4 -4
- package/build/table.js +2 -2
- package/build/translations/af.js +1 -1
- package/build/translations/ar.js +1 -1
- package/build/translations/ast.js +1 -1
- package/build/translations/az.js +1 -1
- package/build/translations/be.js +1 -1
- package/build/translations/bg.js +1 -1
- package/build/translations/bn.js +1 -1
- package/build/translations/bs.js +1 -1
- package/build/translations/ca.js +1 -1
- package/build/translations/cs.js +1 -1
- package/build/translations/da.js +1 -1
- package/build/translations/de-ch.js +1 -1
- package/build/translations/de.js +1 -1
- package/build/translations/el.js +1 -1
- package/build/translations/en-au.js +1 -1
- package/build/translations/en-gb.js +1 -1
- package/build/translations/eo.js +1 -1
- package/build/translations/es-co.js +1 -1
- package/build/translations/es.js +1 -1
- package/build/translations/et.js +1 -1
- package/build/translations/eu.js +1 -1
- package/build/translations/fa.js +1 -1
- package/build/translations/fi.js +1 -1
- package/build/translations/fr.js +1 -1
- package/build/translations/gl.js +1 -1
- package/build/translations/gu.js +1 -1
- package/build/translations/he.js +1 -1
- package/build/translations/hi.js +1 -1
- package/build/translations/hr.js +1 -1
- package/build/translations/hu.js +1 -1
- package/build/translations/hy.js +1 -1
- package/build/translations/id.js +1 -1
- package/build/translations/it.js +1 -1
- package/build/translations/ja.js +1 -1
- package/build/translations/jv.js +1 -1
- package/build/translations/kk.js +1 -1
- package/build/translations/km.js +1 -1
- package/build/translations/kn.js +1 -1
- package/build/translations/ko.js +1 -1
- package/build/translations/ku.js +1 -1
- package/build/translations/lt.js +1 -1
- package/build/translations/lv.js +1 -1
- package/build/translations/ms.js +1 -1
- package/build/translations/nb.js +1 -1
- package/build/translations/ne.js +1 -1
- package/build/translations/nl.js +1 -1
- package/build/translations/no.js +1 -1
- package/build/translations/oc.js +1 -1
- package/build/translations/pl.js +1 -1
- package/build/translations/pt-br.js +1 -1
- package/build/translations/pt.js +1 -1
- package/build/translations/ro.js +1 -1
- package/build/translations/ru.js +1 -1
- package/build/translations/si.js +1 -1
- package/build/translations/sk.js +1 -1
- package/build/translations/sl.js +1 -1
- package/build/translations/sq.js +1 -1
- package/build/translations/sr-latn.js +1 -1
- package/build/translations/sr.js +1 -1
- package/build/translations/sv.js +1 -1
- package/build/translations/th.js +1 -1
- package/build/translations/ti.js +1 -1
- package/build/translations/tk.js +1 -1
- package/build/translations/tr.js +1 -1
- package/build/translations/tt.js +1 -1
- package/build/translations/ug.js +1 -1
- package/build/translations/uk.js +1 -1
- package/build/translations/ur.js +1 -1
- package/build/translations/uz.js +1 -1
- package/build/translations/vi.js +1 -1
- package/build/translations/zh-cn.js +1 -1
- package/build/translations/zh.js +1 -1
- package/dist/index-content.css +32 -3
- package/dist/index-editor.css +181 -88
- package/dist/index.css +302 -160
- package/dist/index.css.map +1 -1
- package/dist/index.js +11215 -8546
- package/dist/index.js.map +1 -1
- package/dist/translations/af.js +1 -1
- package/dist/translations/af.umd.js +1 -1
- package/dist/translations/ar.js +1 -1
- package/dist/translations/ar.umd.js +1 -1
- package/dist/translations/ast.js +1 -1
- package/dist/translations/ast.umd.js +1 -1
- package/dist/translations/az.js +1 -1
- package/dist/translations/az.umd.js +1 -1
- package/dist/translations/be.js +1 -1
- package/dist/translations/be.umd.js +1 -1
- package/dist/translations/bg.js +1 -1
- package/dist/translations/bg.umd.js +1 -1
- package/dist/translations/bn.js +1 -1
- package/dist/translations/bn.umd.js +1 -1
- package/dist/translations/bs.js +1 -1
- package/dist/translations/bs.umd.js +1 -1
- package/dist/translations/ca.js +1 -1
- package/dist/translations/ca.umd.js +1 -1
- package/dist/translations/cs.js +1 -1
- package/dist/translations/cs.umd.js +1 -1
- package/dist/translations/da.js +1 -1
- package/dist/translations/da.umd.js +1 -1
- package/dist/translations/de-ch.js +1 -1
- package/dist/translations/de-ch.umd.js +1 -1
- package/dist/translations/de.js +1 -1
- package/dist/translations/de.umd.js +1 -1
- package/dist/translations/el.js +1 -1
- package/dist/translations/el.umd.js +1 -1
- package/dist/translations/en-au.js +1 -1
- package/dist/translations/en-au.umd.js +1 -1
- package/dist/translations/en-gb.js +1 -1
- package/dist/translations/en-gb.umd.js +1 -1
- package/dist/translations/en.js +1 -1
- package/dist/translations/en.umd.js +1 -1
- package/dist/translations/eo.js +1 -1
- package/dist/translations/eo.umd.js +1 -1
- package/dist/translations/es-co.js +1 -1
- package/dist/translations/es-co.umd.js +1 -1
- package/dist/translations/es.js +1 -1
- package/dist/translations/es.umd.js +1 -1
- package/dist/translations/et.js +1 -1
- package/dist/translations/et.umd.js +1 -1
- package/dist/translations/eu.js +1 -1
- package/dist/translations/eu.umd.js +1 -1
- package/dist/translations/fa.js +1 -1
- package/dist/translations/fa.umd.js +1 -1
- package/dist/translations/fi.js +1 -1
- package/dist/translations/fi.umd.js +1 -1
- package/dist/translations/fr.js +1 -1
- package/dist/translations/fr.umd.js +1 -1
- package/dist/translations/gl.js +1 -1
- package/dist/translations/gl.umd.js +1 -1
- package/dist/translations/gu.js +1 -1
- package/dist/translations/gu.umd.js +1 -1
- package/dist/translations/he.js +1 -1
- package/dist/translations/he.umd.js +1 -1
- package/dist/translations/hi.js +1 -1
- package/dist/translations/hi.umd.js +1 -1
- package/dist/translations/hr.js +1 -1
- package/dist/translations/hr.umd.js +1 -1
- package/dist/translations/hu.js +1 -1
- package/dist/translations/hu.umd.js +1 -1
- package/dist/translations/hy.js +1 -1
- package/dist/translations/hy.umd.js +1 -1
- package/dist/translations/id.js +1 -1
- package/dist/translations/id.umd.js +1 -1
- package/dist/translations/it.js +1 -1
- package/dist/translations/it.umd.js +1 -1
- package/dist/translations/ja.js +1 -1
- package/dist/translations/ja.umd.js +1 -1
- package/dist/translations/jv.js +1 -1
- package/dist/translations/jv.umd.js +1 -1
- package/dist/translations/kk.js +1 -1
- package/dist/translations/kk.umd.js +1 -1
- package/dist/translations/km.js +1 -1
- package/dist/translations/km.umd.js +1 -1
- package/dist/translations/kn.js +1 -1
- package/dist/translations/kn.umd.js +1 -1
- package/dist/translations/ko.js +1 -1
- package/dist/translations/ko.umd.js +1 -1
- package/dist/translations/ku.js +1 -1
- package/dist/translations/ku.umd.js +1 -1
- package/dist/translations/lt.js +1 -1
- package/dist/translations/lt.umd.js +1 -1
- package/dist/translations/lv.js +1 -1
- package/dist/translations/lv.umd.js +1 -1
- package/dist/translations/ms.js +1 -1
- package/dist/translations/ms.umd.js +1 -1
- package/dist/translations/nb.js +1 -1
- package/dist/translations/nb.umd.js +1 -1
- package/dist/translations/ne.js +1 -1
- package/dist/translations/ne.umd.js +1 -1
- package/dist/translations/nl.js +1 -1
- package/dist/translations/nl.umd.js +1 -1
- package/dist/translations/no.js +1 -1
- package/dist/translations/no.umd.js +1 -1
- package/dist/translations/oc.js +1 -1
- package/dist/translations/oc.umd.js +1 -1
- package/dist/translations/pl.js +1 -1
- package/dist/translations/pl.umd.js +1 -1
- package/dist/translations/pt-br.js +1 -1
- package/dist/translations/pt-br.umd.js +1 -1
- package/dist/translations/pt.js +1 -1
- package/dist/translations/pt.umd.js +1 -1
- package/dist/translations/ro.js +1 -1
- package/dist/translations/ro.umd.js +1 -1
- package/dist/translations/ru.js +1 -1
- package/dist/translations/ru.umd.js +1 -1
- package/dist/translations/si.js +1 -1
- package/dist/translations/si.umd.js +1 -1
- package/dist/translations/sk.js +1 -1
- package/dist/translations/sk.umd.js +1 -1
- package/dist/translations/sl.js +1 -1
- package/dist/translations/sl.umd.js +1 -1
- package/dist/translations/sq.js +1 -1
- package/dist/translations/sq.umd.js +1 -1
- package/dist/translations/sr-latn.js +1 -1
- package/dist/translations/sr-latn.umd.js +1 -1
- package/dist/translations/sr.js +1 -1
- package/dist/translations/sr.umd.js +1 -1
- package/dist/translations/sv.js +1 -1
- package/dist/translations/sv.umd.js +1 -1
- package/dist/translations/th.js +1 -1
- package/dist/translations/th.umd.js +1 -1
- package/dist/translations/ti.js +1 -1
- package/dist/translations/ti.umd.js +1 -1
- package/dist/translations/tk.js +1 -1
- package/dist/translations/tk.umd.js +1 -1
- package/dist/translations/tr.js +1 -1
- package/dist/translations/tr.umd.js +1 -1
- package/dist/translations/tt.js +1 -1
- package/dist/translations/tt.umd.js +1 -1
- package/dist/translations/ug.js +1 -1
- package/dist/translations/ug.umd.js +1 -1
- package/dist/translations/uk.js +1 -1
- package/dist/translations/uk.umd.js +1 -1
- package/dist/translations/ur.js +1 -1
- package/dist/translations/ur.umd.js +1 -1
- package/dist/translations/uz.js +1 -1
- package/dist/translations/uz.umd.js +1 -1
- package/dist/translations/vi.js +1 -1
- package/dist/translations/vi.umd.js +1 -1
- package/dist/translations/zh-cn.js +1 -1
- package/dist/translations/zh-cn.umd.js +1 -1
- package/dist/translations/zh.js +1 -1
- package/dist/translations/zh.umd.js +1 -1
- package/lang/contexts.json +6 -0
- package/lang/translations/af.po +24 -0
- package/lang/translations/ar.po +24 -0
- package/lang/translations/ast.po +24 -0
- package/lang/translations/az.po +24 -0
- package/lang/translations/be.po +24 -0
- package/lang/translations/bg.po +24 -0
- package/lang/translations/bn.po +24 -0
- package/lang/translations/bs.po +24 -0
- package/lang/translations/ca.po +24 -0
- package/lang/translations/cs.po +24 -0
- package/lang/translations/da.po +24 -0
- package/lang/translations/de-ch.po +24 -0
- package/lang/translations/de.po +24 -0
- package/lang/translations/el.po +24 -0
- package/lang/translations/en-au.po +24 -0
- package/lang/translations/en-gb.po +24 -0
- package/lang/translations/en.po +24 -0
- package/lang/translations/eo.po +24 -0
- package/lang/translations/es-co.po +24 -0
- package/lang/translations/es.po +24 -0
- package/lang/translations/et.po +24 -0
- package/lang/translations/eu.po +24 -0
- package/lang/translations/fa.po +24 -0
- package/lang/translations/fi.po +24 -0
- package/lang/translations/fr.po +24 -0
- package/lang/translations/gl.po +24 -0
- package/lang/translations/gu.po +24 -0
- package/lang/translations/he.po +24 -0
- package/lang/translations/hi.po +24 -0
- package/lang/translations/hr.po +24 -0
- package/lang/translations/hu.po +24 -0
- package/lang/translations/hy.po +24 -0
- package/lang/translations/id.po +24 -0
- package/lang/translations/it.po +24 -0
- package/lang/translations/ja.po +24 -0
- package/lang/translations/jv.po +24 -0
- package/lang/translations/kk.po +24 -0
- package/lang/translations/km.po +24 -0
- package/lang/translations/kn.po +24 -0
- package/lang/translations/ko.po +24 -0
- package/lang/translations/ku.po +24 -0
- package/lang/translations/lt.po +24 -0
- package/lang/translations/lv.po +24 -0
- package/lang/translations/ms.po +24 -0
- package/lang/translations/nb.po +24 -0
- package/lang/translations/ne.po +24 -0
- package/lang/translations/nl.po +24 -0
- package/lang/translations/no.po +24 -0
- package/lang/translations/oc.po +24 -0
- package/lang/translations/pl.po +24 -0
- package/lang/translations/pt-br.po +24 -0
- package/lang/translations/pt.po +24 -0
- package/lang/translations/ro.po +24 -0
- package/lang/translations/ru.po +24 -0
- package/lang/translations/si.po +24 -0
- package/lang/translations/sk.po +24 -0
- package/lang/translations/sl.po +24 -0
- package/lang/translations/sq.po +24 -0
- package/lang/translations/sr-latn.po +24 -0
- package/lang/translations/sr.po +24 -0
- package/lang/translations/sv.po +24 -0
- package/lang/translations/th.po +24 -0
- package/lang/translations/ti.po +24 -0
- package/lang/translations/tk.po +24 -0
- package/lang/translations/tr.po +24 -0
- package/lang/translations/tt.po +24 -0
- package/lang/translations/ug.po +24 -0
- package/lang/translations/uk.po +24 -0
- package/lang/translations/ur.po +24 -0
- package/lang/translations/uz.po +24 -0
- package/lang/translations/vi.po +24 -0
- package/lang/translations/zh-cn.po +24 -0
- package/lang/translations/zh.po +24 -0
- package/package.json +9 -9
- package/src/augmentation.d.ts +21 -0
- package/src/converters/downcast.d.ts +26 -1
- package/src/converters/downcast.js +129 -3
- package/src/converters/tableproperties.d.ts +46 -2
- package/src/converters/tableproperties.js +218 -1
- package/src/converters/upcasttable.js +147 -36
- package/src/index.d.ts +5 -1
- package/src/index.js +5 -0
- package/src/plaintableoutput.js +0 -91
- package/src/tablecellproperties/tablecellpropertiesediting.js +7 -4
- package/src/tablecellproperties/tablecellpropertiesuiexperimental.d.ts +128 -0
- package/src/tablecellproperties/tablecellpropertiesuiexperimental.js +386 -0
- package/src/tablecellproperties/ui/tablecellpropertiesviewexperimental.d.ts +237 -0
- package/src/tablecellproperties/ui/tablecellpropertiesviewexperimental.js +633 -0
- package/src/tableconfig.d.ts +187 -10
- package/src/tableediting.d.ts +5 -0
- package/src/tableediting.js +28 -1
- package/src/tablelayout/tablelayoutediting.js +8 -2
- package/src/tableproperties/tablepropertiesediting.js +255 -8
- package/src/tableproperties/tablepropertiesuiexperimental.d.ts +136 -0
- package/src/tableproperties/tablepropertiesuiexperimental.js +375 -0
- package/src/tableproperties/ui/tablepropertiesviewexperimental.d.ts +216 -0
- package/src/tableproperties/ui/tablepropertiesviewexperimental.js +544 -0
- package/src/utils/structure.d.ts +5 -1
- package/src/utils/structure.js +10 -0
- package/src/utils/ui/table-propertiesexperimental.d.ts +215 -0
- package/src/utils/ui/table-propertiesexperimental.js +391 -0
- package/theme/formrow-experimental.css +15 -0
- package/theme/table.css +2 -2
- package/theme/tableform-experimental.css +61 -0
- package/theme/tableproperties-experimental.css +78 -0
|
@@ -6,9 +6,10 @@
|
|
|
6
6
|
* @module table/tableproperties/tablepropertiesediting
|
|
7
7
|
*/
|
|
8
8
|
import { Plugin } from 'ckeditor5/src/core.js';
|
|
9
|
-
import { addBackgroundStylesRules, addBorderStylesRules } from 'ckeditor5/src/engine.js';
|
|
9
|
+
import { addBackgroundStylesRules, addBorderStylesRules, addMarginStylesRules } from 'ckeditor5/src/engine.js';
|
|
10
|
+
import { first } from 'ckeditor5/src/utils.js';
|
|
10
11
|
import { TableEditing } from '../tableediting.js';
|
|
11
|
-
import { downcastAttributeToStyle, downcastTableAttribute, getDefaultValueAdjusted, upcastBorderStyles, upcastStyleToAttribute } from '../converters/tableproperties.js';
|
|
12
|
+
import { downcastAttributeToStyle, downcastTableAttribute, getDefaultValueAdjusted, upcastBorderStyles, upcastStyleToAttribute, upcastTableAlignmentConfig, DEFAULT_TABLE_ALIGNMENT_OPTIONS } from '../converters/tableproperties.js';
|
|
12
13
|
import { TableBackgroundColorCommand } from './commands/tablebackgroundcolorcommand.js';
|
|
13
14
|
import { TableBorderColorCommand } from './commands/tablebordercolorcommand.js';
|
|
14
15
|
import { TableBorderStyleCommand } from './commands/tableborderstylecommand.js';
|
|
@@ -17,8 +18,7 @@ import { TableWidthCommand } from './commands/tablewidthcommand.js';
|
|
|
17
18
|
import { TableHeightCommand } from './commands/tableheightcommand.js';
|
|
18
19
|
import { TableAlignmentCommand } from './commands/tablealignmentcommand.js';
|
|
19
20
|
import { getNormalizedDefaultTableProperties } from '../utils/table-properties.js';
|
|
20
|
-
|
|
21
|
-
const FLOAT_VALUES_REG_EXP = /^(left|none|right)$/;
|
|
21
|
+
import { getViewTableFromWrapper } from '../utils/structure.js';
|
|
22
22
|
/**
|
|
23
23
|
* The table properties editing feature.
|
|
24
24
|
*
|
|
@@ -79,8 +79,10 @@ export class TablePropertiesEditing extends Plugin {
|
|
|
79
79
|
const defaultTableProperties = getNormalizedDefaultTableProperties(editor.config.get('table.tableProperties.defaultProperties'), {
|
|
80
80
|
includeAlignmentProperty: true
|
|
81
81
|
});
|
|
82
|
+
const useInlineStyles = editor.config.get('table.tableProperties.alignment.useInlineStyles') !== false;
|
|
83
|
+
editor.data.addStyleProcessorRules(addMarginStylesRules);
|
|
82
84
|
editor.data.addStyleProcessorRules(addBorderStylesRules);
|
|
83
|
-
enableBorderProperties(
|
|
85
|
+
enableBorderProperties(editor, {
|
|
84
86
|
color: defaultTableProperties.borderColor,
|
|
85
87
|
style: defaultTableProperties.borderStyle,
|
|
86
88
|
width: defaultTableProperties.borderWidth
|
|
@@ -88,7 +90,12 @@ export class TablePropertiesEditing extends Plugin {
|
|
|
88
90
|
editor.commands.add('tableBorderColor', new TableBorderColorCommand(editor, defaultTableProperties.borderColor));
|
|
89
91
|
editor.commands.add('tableBorderStyle', new TableBorderStyleCommand(editor, defaultTableProperties.borderStyle));
|
|
90
92
|
editor.commands.add('tableBorderWidth', new TableBorderWidthCommand(editor, defaultTableProperties.borderWidth));
|
|
91
|
-
|
|
93
|
+
if (editor.config.get('experimentalFlags.useExtendedTableBlockAlignment')) {
|
|
94
|
+
enableExtendedAlignmentProperty(schema, conversion, defaultTableProperties.alignment, useInlineStyles);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
enableAlignmentProperty(schema, conversion, defaultTableProperties.alignment);
|
|
98
|
+
}
|
|
92
99
|
editor.commands.add('tableAlignment', new TableAlignmentCommand(editor, defaultTableProperties.alignment));
|
|
93
100
|
enableTableToFigureProperty(schema, conversion, {
|
|
94
101
|
modelAttribute: 'tableWidth',
|
|
@@ -115,8 +122,50 @@ export class TablePropertiesEditing extends Plugin {
|
|
|
115
122
|
defaultValue: defaultTableProperties.backgroundColor
|
|
116
123
|
});
|
|
117
124
|
editor.commands.add('tableBackgroundColor', new TableBackgroundColorCommand(editor, defaultTableProperties.backgroundColor));
|
|
125
|
+
if (editor.config.get('experimentalFlags.useExtendedTableBlockAlignment')) {
|
|
126
|
+
const viewDoc = editor.editing.view.document;
|
|
127
|
+
// Adjust clipboard output to wrap tables in divs if needed (for alignment).
|
|
128
|
+
this.listenTo(viewDoc, 'clipboardOutput', (evt, data) => {
|
|
129
|
+
editor.editing.view.change(writer => {
|
|
130
|
+
for (const { item } of writer.createRangeIn(data.content)) {
|
|
131
|
+
wrapInDivIfNeeded(item, writer);
|
|
132
|
+
}
|
|
133
|
+
data.dataTransfer.setData('text/html', this.editor.data.htmlProcessor.toData(data.content));
|
|
134
|
+
});
|
|
135
|
+
}, { priority: 'lowest' });
|
|
136
|
+
}
|
|
118
137
|
}
|
|
119
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* Checks whether the view element is a table and if it needs to be wrapped in a div for alignment purposes.
|
|
141
|
+
* If so, it wraps it in a div and inserts it into the data content.
|
|
142
|
+
*/
|
|
143
|
+
function wrapInDivIfNeeded(viewItem, writer) {
|
|
144
|
+
if (!viewItem.is('element', 'table')) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
const alignAttribute = viewItem.getAttribute('align');
|
|
148
|
+
const floatAttribute = viewItem.getStyle('float');
|
|
149
|
+
const marginLeft = viewItem.getStyle('margin-left');
|
|
150
|
+
const marginRight = viewItem.getStyle('margin-right');
|
|
151
|
+
if (
|
|
152
|
+
// Align center.
|
|
153
|
+
(alignAttribute && alignAttribute === 'center') ||
|
|
154
|
+
// Align right with text wrapping.
|
|
155
|
+
(floatAttribute && floatAttribute === 'right' && alignAttribute && alignAttribute === 'right')) {
|
|
156
|
+
insertWrapperWithAlignment(writer, alignAttribute, viewItem);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
// Align right with no text wrapping.
|
|
160
|
+
if (floatAttribute === undefined && marginLeft === 'auto' && marginRight === '0') {
|
|
161
|
+
insertWrapperWithAlignment(writer, 'right', viewItem);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function insertWrapperWithAlignment(writer, align, table) {
|
|
165
|
+
const position = writer.createPositionBefore(table);
|
|
166
|
+
const wrapper = writer.createContainerElement('div', { align }, table);
|
|
167
|
+
writer.insert(position, wrapper);
|
|
168
|
+
}
|
|
120
169
|
/**
|
|
121
170
|
* Enables `tableBorderStyle'`, `tableBorderColor'` and `tableBorderWidth'` attributes for table.
|
|
122
171
|
*
|
|
@@ -125,7 +174,9 @@ export class TablePropertiesEditing extends Plugin {
|
|
|
125
174
|
* @param defaultBorder.style The default `tableBorderStyle` value.
|
|
126
175
|
* @param defaultBorder.width The default `tableBorderWidth` value.
|
|
127
176
|
*/
|
|
128
|
-
function enableBorderProperties(
|
|
177
|
+
function enableBorderProperties(editor, defaultBorder) {
|
|
178
|
+
const { conversion } = editor;
|
|
179
|
+
const { schema } = editor.model;
|
|
129
180
|
const modelAttributes = {
|
|
130
181
|
width: 'tableBorderWidth',
|
|
131
182
|
color: 'tableBorderColor',
|
|
@@ -137,17 +188,115 @@ function enableBorderProperties(schema, conversion, defaultBorder) {
|
|
|
137
188
|
for (const modelAttribute of Object.values(modelAttributes)) {
|
|
138
189
|
schema.setAttributeProperties(modelAttribute, { isFormatting: true });
|
|
139
190
|
}
|
|
140
|
-
upcastBorderStyles(
|
|
191
|
+
upcastBorderStyles(editor, 'table', modelAttributes, defaultBorder);
|
|
141
192
|
downcastTableAttribute(conversion, { modelAttribute: modelAttributes.color, styleName: 'border-color' });
|
|
142
193
|
downcastTableAttribute(conversion, { modelAttribute: modelAttributes.style, styleName: 'border-style' });
|
|
143
194
|
downcastTableAttribute(conversion, { modelAttribute: modelAttributes.width, styleName: 'border-width' });
|
|
144
195
|
}
|
|
196
|
+
/**
|
|
197
|
+
* Enables the extended block`'alignment'` attribute for table.
|
|
198
|
+
*
|
|
199
|
+
* @param defaultValue The default alignment value.
|
|
200
|
+
*/
|
|
201
|
+
function enableExtendedAlignmentProperty(schema, conversion, defaultValue, useInlineStyles) {
|
|
202
|
+
schema.extend('table', {
|
|
203
|
+
allowAttributes: ['tableAlignment']
|
|
204
|
+
});
|
|
205
|
+
schema.setAttributeProperties('tableAlignment', { isFormatting: true });
|
|
206
|
+
conversion.for('downcast')
|
|
207
|
+
.attributeToAttribute({
|
|
208
|
+
model: {
|
|
209
|
+
name: 'table',
|
|
210
|
+
key: 'tableAlignment',
|
|
211
|
+
values: ['left', 'center', 'right', 'blockLeft', 'blockRight']
|
|
212
|
+
},
|
|
213
|
+
view: {
|
|
214
|
+
left: useInlineStyles ? {
|
|
215
|
+
key: 'style',
|
|
216
|
+
value: {
|
|
217
|
+
float: 'left',
|
|
218
|
+
'margin-right': 'var(--ck-content-table-style-spacing, 1.5em)'
|
|
219
|
+
}
|
|
220
|
+
} : {
|
|
221
|
+
key: 'class',
|
|
222
|
+
value: DEFAULT_TABLE_ALIGNMENT_OPTIONS.left.className
|
|
223
|
+
},
|
|
224
|
+
right: useInlineStyles ? {
|
|
225
|
+
key: 'style',
|
|
226
|
+
value: {
|
|
227
|
+
float: 'right',
|
|
228
|
+
'margin-left': 'var(--ck-content-table-style-spacing, 1.5em)'
|
|
229
|
+
}
|
|
230
|
+
} : {
|
|
231
|
+
key: 'class',
|
|
232
|
+
value: DEFAULT_TABLE_ALIGNMENT_OPTIONS.right.className
|
|
233
|
+
},
|
|
234
|
+
center: useInlineStyles ? {
|
|
235
|
+
key: 'style',
|
|
236
|
+
value: {
|
|
237
|
+
'margin-left': 'auto',
|
|
238
|
+
'margin-right': 'auto'
|
|
239
|
+
}
|
|
240
|
+
} : {
|
|
241
|
+
key: 'class',
|
|
242
|
+
value: DEFAULT_TABLE_ALIGNMENT_OPTIONS.center.className
|
|
243
|
+
},
|
|
244
|
+
blockLeft: useInlineStyles ? {
|
|
245
|
+
key: 'style',
|
|
246
|
+
value: {
|
|
247
|
+
'margin-left': '0',
|
|
248
|
+
'margin-right': 'auto'
|
|
249
|
+
}
|
|
250
|
+
} : {
|
|
251
|
+
key: 'class',
|
|
252
|
+
value: DEFAULT_TABLE_ALIGNMENT_OPTIONS.blockLeft.className
|
|
253
|
+
},
|
|
254
|
+
blockRight: useInlineStyles ? {
|
|
255
|
+
key: 'style',
|
|
256
|
+
value: {
|
|
257
|
+
'margin-left': 'auto',
|
|
258
|
+
'margin-right': '0'
|
|
259
|
+
}
|
|
260
|
+
} : {
|
|
261
|
+
key: 'class',
|
|
262
|
+
value: DEFAULT_TABLE_ALIGNMENT_OPTIONS.blockRight.className
|
|
263
|
+
}
|
|
264
|
+
},
|
|
265
|
+
converterPriority: 'high'
|
|
266
|
+
});
|
|
267
|
+
/**
|
|
268
|
+
* Enables upcasting of the `tableAlignment` attribute.
|
|
269
|
+
*/
|
|
270
|
+
upcastTableAlignmentConfig.forEach(config => {
|
|
271
|
+
conversion.for('upcast').attributeToAttribute({
|
|
272
|
+
view: config.view,
|
|
273
|
+
model: {
|
|
274
|
+
key: 'tableAlignment',
|
|
275
|
+
value: (viewElement, conversionApi, data) => {
|
|
276
|
+
if (isNonTableFigureElement(viewElement)) {
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
const localDefaultValue = getDefaultValueAdjusted(defaultValue, '', data);
|
|
280
|
+
const align = config.getAlign(viewElement);
|
|
281
|
+
const consumables = config.getConsumables(viewElement);
|
|
282
|
+
conversionApi.consumable.consume(viewElement, consumables);
|
|
283
|
+
if (align !== localDefaultValue) {
|
|
284
|
+
return align;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
conversion.for('upcast').add(upcastTableAlignedDiv(defaultValue));
|
|
291
|
+
}
|
|
145
292
|
/**
|
|
146
293
|
* Enables the `'alignment'` attribute for table.
|
|
147
294
|
*
|
|
148
295
|
* @param defaultValue The default alignment value.
|
|
149
296
|
*/
|
|
150
297
|
function enableAlignmentProperty(schema, conversion, defaultValue) {
|
|
298
|
+
const ALIGN_VALUES_REG_EXP = /^(left|center|right)$/;
|
|
299
|
+
const FLOAT_VALUES_REG_EXP = /^(left|none|right)$/;
|
|
151
300
|
schema.extend('table', {
|
|
152
301
|
allowAttributes: ['tableAlignment']
|
|
153
302
|
});
|
|
@@ -266,6 +415,98 @@ function enableAlignmentProperty(schema, conversion, defaultValue) {
|
|
|
266
415
|
}
|
|
267
416
|
});
|
|
268
417
|
}
|
|
418
|
+
/**
|
|
419
|
+
* Returns a function that converts the table view representation:
|
|
420
|
+
*
|
|
421
|
+
* ```html
|
|
422
|
+
* <div align="right"><table>...</table></div>
|
|
423
|
+
* <!-- or -->
|
|
424
|
+
* <div align="center"><table>...</table></div>
|
|
425
|
+
* <!-- or -->
|
|
426
|
+
* <div align="left"><table>...</table></div>
|
|
427
|
+
* ```
|
|
428
|
+
*
|
|
429
|
+
* to the model representation:
|
|
430
|
+
*
|
|
431
|
+
* ```xml
|
|
432
|
+
* <table tableAlignment="right|center|left"></table>
|
|
433
|
+
* ```
|
|
434
|
+
*
|
|
435
|
+
* @internal
|
|
436
|
+
*/
|
|
437
|
+
function upcastTableAlignedDiv(defaultValue) {
|
|
438
|
+
return (dispatcher) => {
|
|
439
|
+
dispatcher.on('element:div', (evt, data, conversionApi) => {
|
|
440
|
+
// Do not convert if this is not a "table wrapped in div with align attribute".
|
|
441
|
+
if (!conversionApi.consumable.test(data.viewItem, { name: true, attributes: 'align' })) {
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
// Find a table element inside the div element.
|
|
445
|
+
const viewTable = getViewTableFromWrapper(data.viewItem);
|
|
446
|
+
// Do not convert if table element is absent or was already converted.
|
|
447
|
+
if (!viewTable || !conversionApi.consumable.test(viewTable, { name: true })) {
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
// Consume the div to prevent other converters from processing it again.
|
|
451
|
+
conversionApi.consumable.consume(data.viewItem, { name: true, attributes: 'align' });
|
|
452
|
+
// Convert view table to model table.
|
|
453
|
+
const conversionResult = conversionApi.convertItem(viewTable, data.modelCursor);
|
|
454
|
+
// Get table element from conversion result.
|
|
455
|
+
const modelTable = first(conversionResult.modelRange.getItems());
|
|
456
|
+
// When table wasn't successfully converted then finish conversion.
|
|
457
|
+
if (!modelTable || !modelTable.is('element', 'table')) {
|
|
458
|
+
// Revert consumed div so other features can convert it.
|
|
459
|
+
conversionApi.consumable.revert(data.viewItem, { name: true, attributes: 'align' });
|
|
460
|
+
// If anyway some table content was converted, we have to pass the model range and cursor.
|
|
461
|
+
if (conversionResult.modelRange && !conversionResult.modelRange.isCollapsed) {
|
|
462
|
+
data.modelRange = conversionResult.modelRange;
|
|
463
|
+
data.modelCursor = conversionResult.modelCursor;
|
|
464
|
+
}
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
const alignAttributeFromDiv = data.viewItem.getAttribute('align');
|
|
468
|
+
const alignAttributeFromTable = viewTable.getAttribute('align');
|
|
469
|
+
const localDefaultValue = getDefaultValueAdjusted(defaultValue, '', data);
|
|
470
|
+
const align = convertToTableAlignment(alignAttributeFromDiv, alignAttributeFromTable, localDefaultValue);
|
|
471
|
+
if (align) {
|
|
472
|
+
conversionApi.writer.setAttribute('tableAlignment', align, modelTable);
|
|
473
|
+
}
|
|
474
|
+
conversionApi.convertChildren(data.viewItem, conversionApi.writer.createPositionAt(modelTable, 'end'));
|
|
475
|
+
conversionApi.updateConversionResult(modelTable, data);
|
|
476
|
+
});
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Converts div `align` and table `align` attributes to the model `tableAlignment` attribute.
|
|
481
|
+
*
|
|
482
|
+
* @param divAlign The value of the div `align` attribute.
|
|
483
|
+
* @param tableAlign The value of the table `align` attribute.
|
|
484
|
+
* @param defaultValue The default alignment value.
|
|
485
|
+
* @returns The model `tableAlignment` value or `undefined` if no conversion is needed.
|
|
486
|
+
*/
|
|
487
|
+
function convertToTableAlignment(divAlign, tableAlign, defaultValue) {
|
|
488
|
+
if (divAlign) {
|
|
489
|
+
switch (divAlign) {
|
|
490
|
+
case 'right':
|
|
491
|
+
if (tableAlign === 'right') {
|
|
492
|
+
return 'right';
|
|
493
|
+
}
|
|
494
|
+
else if (tableAlign === 'left') {
|
|
495
|
+
return 'left';
|
|
496
|
+
}
|
|
497
|
+
else {
|
|
498
|
+
return 'blockRight';
|
|
499
|
+
}
|
|
500
|
+
case 'center':
|
|
501
|
+
return 'center';
|
|
502
|
+
case 'left':
|
|
503
|
+
return tableAlign === undefined ? 'blockLeft' : 'left';
|
|
504
|
+
default:
|
|
505
|
+
return defaultValue;
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
return undefined;
|
|
509
|
+
}
|
|
269
510
|
/**
|
|
270
511
|
* Enables conversion for an attribute for simple view-model mappings.
|
|
271
512
|
*
|
|
@@ -297,3 +538,9 @@ function enableTableToFigureProperty(schema, conversion, options) {
|
|
|
297
538
|
});
|
|
298
539
|
downcastAttributeToStyle(conversion, { modelElement: 'table', ...options });
|
|
299
540
|
}
|
|
541
|
+
/**
|
|
542
|
+
* Checks whether a given figure element should be ignored when upcasting table properties.
|
|
543
|
+
*/
|
|
544
|
+
function isNonTableFigureElement(viewElement) {
|
|
545
|
+
return viewElement.name == 'figure' && !viewElement.hasClass('table');
|
|
546
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module table/tableproperties/tablepropertiesuiexperimental
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin, type Editor } from 'ckeditor5/src/core.js';
|
|
9
|
+
import { ButtonView, ContextualBalloon } from 'ckeditor5/src/ui.js';
|
|
10
|
+
import { TablePropertiesViewExperimental } from './ui/tablepropertiesviewexperimental.js';
|
|
11
|
+
/**
|
|
12
|
+
* The table properties UI plugin. It introduces the `'tableProperties'` button
|
|
13
|
+
* that opens a form allowing to specify visual styling of an entire table.
|
|
14
|
+
*
|
|
15
|
+
* It uses the {@link module:ui/panel/balloon/contextualballoon~ContextualBalloon contextual balloon plugin}.
|
|
16
|
+
*/
|
|
17
|
+
export declare class TablePropertiesUIExperimental extends Plugin {
|
|
18
|
+
/**
|
|
19
|
+
* The default table properties.
|
|
20
|
+
*/
|
|
21
|
+
private _defaultContentTableProperties;
|
|
22
|
+
/**
|
|
23
|
+
* The default layout table properties.
|
|
24
|
+
*/
|
|
25
|
+
private _defaultLayoutTableProperties;
|
|
26
|
+
/**
|
|
27
|
+
* The contextual balloon plugin instance.
|
|
28
|
+
*/
|
|
29
|
+
private _balloon;
|
|
30
|
+
/**
|
|
31
|
+
* The properties form view displayed inside the balloon.
|
|
32
|
+
*/
|
|
33
|
+
view: TablePropertiesViewExperimental | null;
|
|
34
|
+
/**
|
|
35
|
+
* The properties form view displayed inside the balloon (content table).
|
|
36
|
+
*/
|
|
37
|
+
private _viewWithContentTableDefaults;
|
|
38
|
+
/**
|
|
39
|
+
* The properties form view displayed inside the balloon (layout table).
|
|
40
|
+
*/
|
|
41
|
+
private _viewWithLayoutTableDefaults;
|
|
42
|
+
/**
|
|
43
|
+
* The batch used to undo all changes made by the form (which are live, as the user types)
|
|
44
|
+
* when "Cancel" was pressed. Each time the view is shown, a new batch is created.
|
|
45
|
+
*/
|
|
46
|
+
private _undoStepBatch?;
|
|
47
|
+
/**
|
|
48
|
+
* Flag used to indicate whether view is ready to execute update commands
|
|
49
|
+
* (it finished loading initial data).
|
|
50
|
+
*/
|
|
51
|
+
private _isReady?;
|
|
52
|
+
/**
|
|
53
|
+
* @inheritDoc
|
|
54
|
+
*/
|
|
55
|
+
static get requires(): readonly [typeof ContextualBalloon];
|
|
56
|
+
/**
|
|
57
|
+
* @inheritDoc
|
|
58
|
+
*/
|
|
59
|
+
static get pluginName(): "TablePropertiesUIExperimental";
|
|
60
|
+
/**
|
|
61
|
+
* @inheritDoc
|
|
62
|
+
*/
|
|
63
|
+
static get isOfficialPlugin(): true;
|
|
64
|
+
/**
|
|
65
|
+
* @inheritDoc
|
|
66
|
+
*/
|
|
67
|
+
constructor(editor: Editor);
|
|
68
|
+
/**
|
|
69
|
+
* @inheritDoc
|
|
70
|
+
*/
|
|
71
|
+
init(): void;
|
|
72
|
+
/**
|
|
73
|
+
* Creates the table properties button.
|
|
74
|
+
*
|
|
75
|
+
* @internal
|
|
76
|
+
*/
|
|
77
|
+
_createTablePropertiesButton(): ButtonView;
|
|
78
|
+
/**
|
|
79
|
+
* @inheritDoc
|
|
80
|
+
*/
|
|
81
|
+
destroy(): void;
|
|
82
|
+
/**
|
|
83
|
+
* Creates the {@link module:table/tableproperties/ui/tablepropertiesview~TablePropertiesView} instance.
|
|
84
|
+
*
|
|
85
|
+
* @returns The table properties form view instance.
|
|
86
|
+
*/
|
|
87
|
+
private _createPropertiesView;
|
|
88
|
+
/**
|
|
89
|
+
* In this method the "editor data -> UI" binding is happening.
|
|
90
|
+
*
|
|
91
|
+
* When executed, this method obtains selected table property values from various table commands
|
|
92
|
+
* and passes them to the {@link #view}.
|
|
93
|
+
*
|
|
94
|
+
* This way, the UI stays up–to–date with the editor data.
|
|
95
|
+
*/
|
|
96
|
+
private _fillViewFormFromCommandValues;
|
|
97
|
+
/**
|
|
98
|
+
* Shows the {@link #view} in the {@link #_balloon}.
|
|
99
|
+
*
|
|
100
|
+
* **Note**: Each time a view is shown, the new {@link #_undoStepBatch} is created that contains
|
|
101
|
+
* all changes made to the document when the view is visible, allowing a single undo step
|
|
102
|
+
* for all of them.
|
|
103
|
+
*/
|
|
104
|
+
protected _showView(): void;
|
|
105
|
+
/**
|
|
106
|
+
* Removes the {@link #view} from the {@link #_balloon}.
|
|
107
|
+
*/
|
|
108
|
+
protected _hideView(): void;
|
|
109
|
+
/**
|
|
110
|
+
* Repositions the {@link #_balloon} or hides the {@link #view} if a table is no longer selected.
|
|
111
|
+
*/
|
|
112
|
+
protected _updateView(): void;
|
|
113
|
+
/**
|
|
114
|
+
* Returns `true` when the {@link #view} is the visible in the {@link #_balloon}.
|
|
115
|
+
*/
|
|
116
|
+
private get _isViewVisible();
|
|
117
|
+
/**
|
|
118
|
+
* Returns `true` when the {@link #view} is in the {@link #_balloon}.
|
|
119
|
+
*/
|
|
120
|
+
private get _isViewInBalloon();
|
|
121
|
+
/**
|
|
122
|
+
* Creates a callback that when executed upon {@link #view view's} property change
|
|
123
|
+
* executes a related editor command with the new property value.
|
|
124
|
+
*
|
|
125
|
+
* If new value will be set to the default value, the command will not be executed.
|
|
126
|
+
*
|
|
127
|
+
* @param commandName The command that will be executed.
|
|
128
|
+
*/
|
|
129
|
+
private _getPropertyChangeCallback;
|
|
130
|
+
/**
|
|
131
|
+
* Creates a callback that when executed upon {@link #view view's} property change:
|
|
132
|
+
* * executes a related editor command with the new property value if the value is valid,
|
|
133
|
+
* * or sets the error text next to the invalid field, if the value did not pass the validation.
|
|
134
|
+
*/
|
|
135
|
+
private _getValidatedPropertyChangeCallback;
|
|
136
|
+
}
|