Kaynağa Gözat

Tests: Initial selection manual tests.

Maciej Gołaszewski 7 yıl önce
ebeveyn
işleme
bdd930ea78

+ 51 - 0
packages/ckeditor5-engine/tests/manual/selection.css

@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+table {
+	border-collapse: collapse;
+	border-spacing: 0;
+	border-color: hsl(0,0%,87%);
+}
+
+table, th, td {
+	padding: 5px;
+	border: 1px inset hsl(0,0%,87%);
+}
+
+table th,
+table td {
+	min-width: 1em;
+}
+
+table th {
+	background: hsl(0,0%,96%);
+	font-weight: bold;
+}
+
+table thead th {
+	background: hsl(0,0%,90%);
+}
+
+.ck table.ck-widget th.ck-editor__nested-editable {
+	border-color: inherit;
+	border-style: inset;
+}
+
+.ck table.ck-widget td.ck-editor__nested-editable {
+	border-color: inherit;
+	border-style: inset;
+}
+
+.ck table.ck-widget td.ck-editor__nested-editable.ck-editor__nested-editable_focused,
+.ck table.ck-widget td.ck-editor__nested-editable:focus {
+	background-color: inherit;
+	color: inherit;
+}
+
+.ck table.ck-widget th.ck-editor__nested-editable.ck-editor__nested-editable_focused,
+.ck table.ck-widget th.ck-editor__nested-editable:focus {
+	background-color: inherit;
+	color: inherit;
+}

+ 48 - 0
packages/ckeditor5-engine/tests/manual/selection.html

@@ -0,0 +1,48 @@
+<div id="editor">
+	<p>foo</p>
+
+	<table>
+		<tr>
+			<td>a</td>
+			<td>b</td>
+			<td>c</td>
+		</tr>
+		<tr>
+			<td>d</td>
+			<td>e</td>
+			<td>f</td>
+		</tr>
+	</table>
+
+	<p>bar</p>
+	
+	<table>
+		<tr>
+			<td>1</td>
+			<td>1</td>
+			<td>1</td>
+		</tr>
+		<tr>
+			<td>1</td>
+			<td>1</td>
+			<td>1</td>
+		</tr>
+	</table>
+
+	<table>
+		<tr>
+			<td>2</td>
+			<td>2</td>
+			<td>2</td>
+		</tr>
+		<tr>
+			<td>2</td>
+			<td>2</td>
+			<td>2</td>
+		</tr>
+	</table>
+
+	<p>baz</p>
+</div>
+<h2>Model contents:</h2>
+<div id="model"></div>

+ 102 - 0
packages/ckeditor5-engine/tests/manual/selection.js

@@ -0,0 +1,102 @@
+/**
+ * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* global console */
+
+import { downcastElementToElement } from '../../src/conversion/downcast-converters';
+
+import { getData } from '../../src/dev-utils/model';
+import global from '@ckeditor/ckeditor5-utils/src/dom/global';
+
+import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
+import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
+import Enter from '@ckeditor/ckeditor5-enter/src/enter';
+import Typing from '@ckeditor/ckeditor5-typing/src/typing';
+import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
+import Undo from '@ckeditor/ckeditor5-undo/src/undo';
+import { upcastElementToElement } from '../../src/conversion/upcast-converters';
+
+import './selection.css';
+import { toWidget, toWidgetEditable } from '@ckeditor/ckeditor5-widget/src/utils';
+import Widget from '@ckeditor/ckeditor5-widget/src/widget';
+
+class SelectionTest extends Plugin {
+	init() {
+		const editor = this.editor;
+		const schema = editor.model.schema;
+
+		schema.register( 'table', {
+			allowWhere: '$block',
+			isObject: true,
+			isLimit: true
+		} );
+
+		schema.register( 'tableRow', {
+			allowIn: 'table',
+			isLimit: true
+		} );
+
+		schema.register( 'tableCell', {
+			allowIn: 'tableRow',
+			allowContentOf: '$block',
+			isLimit: true
+		} );
+
+		editor.conversion.for( 'upcast' ).add( upcastElementToElement( { model: 'table', view: 'table' } ) );
+		editor.conversion.for( 'upcast' ).add( upcastElementToElement( { model: 'tableRow', view: 'tr' } ) );
+		editor.conversion.for( 'upcast' ).add( upcastElementToElement( { model: 'tableCell', view: 'td' } ) );
+
+		editor.conversion.for( 'downcast' ).add( downcastElementToElement( {
+			model: 'table',
+			view: ( modelItem, viewWriter ) => {
+				return toWidget( viewWriter.createContainerElement( 'table' ), viewWriter );
+			}
+		} ) );
+		editor.conversion.for( 'downcast' ).add( downcastElementToElement( { model: 'tableRow', view: 'tr' } ) );
+
+		editor.conversion.for( 'downcast' ).add( downcastElementToElement( {
+			model: 'tableCell',
+			view: ( modelItem, viewWriter ) => {
+				return toWidgetEditable( viewWriter.createEditableElement( 'td' ), viewWriter );
+			}
+		} ) );
+	}
+}
+
+ClassicEditor
+	.create( global.document.querySelector( '#editor' ), {
+		plugins: [ Enter, Typing, Paragraph, SelectionTest, Undo, Widget ],
+		toolbar: [ 'undo', 'redo' ]
+	} )
+	.then( editor => {
+		editor.model.document.on( 'change', () => {
+			printModelContents( editor );
+		} );
+
+		printModelContents( editor );
+	} )
+	.catch( err => {
+		console.error( err.stack );
+	} );
+
+const modelDiv = global.document.querySelector( '#model' );
+
+function printModelContents( editor ) {
+	modelDiv.innerText = formatTable( getData( editor.model ) );
+}
+
+function formatTable( tableString ) {
+	return tableString
+		.replace( /<table>/g, '\n<table>' )
+		.replace( /<tableRow>/g, '\n<tableRow>\n    ' )
+		.replace( /<thead>/g, '\n<thead>\n    ' )
+		.replace( /<tbody>/g, '\n<tbody>\n    ' )
+		.replace( /<tr>/g, '\n<tr>\n    ' )
+		.replace( /<\/tableRow>/g, '\n</tableRow>' )
+		.replace( /<\/thead>/g, '\n</thead>' )
+		.replace( /<\/tbody>/g, '\n</tbody>' )
+		.replace( /<\/tr>/g, '\n</tr>' )
+		.replace( /<\/table>/g, '\n</table>' );
+}

+ 1 - 0
packages/ckeditor5-engine/tests/manual/selection.md

@@ -0,0 +1 @@
+### Selection test