8
0
فهرست منبع

Remove POC code.

Maciej Gołaszewski 6 سال پیش
والد
کامیت
4a96b23a41

+ 0 - 117
packages/ckeditor5-mention/src/mentioneditingelement.js

@@ -1,117 +0,0 @@
-/**
- * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
-
-/**
- * @module mention/mentionediting
- */
-
-import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
-import Command from '@ckeditor/ckeditor5-core/src/command';
-import { viewToModelPositionOutsideModelElement } from '@ckeditor/ckeditor5-widget/src/utils';
-
-class MentionCommand extends Command {
-	/**
-	 * @inheritDoc
-	 */
-	refresh() {
-		// @todo implement refresh
-		this.isEnabled = true;
-	}
-
-	/**
-	 * Executes the command.
-	 *
-	 * @protected
-	 * @param {Object} [options] Options for the executed command.
-	 * @param {String} [options.marker='@'] The mention marker.
-	 * @param {String} options.mention.
-	 * @param {String} [options.range].
-	 * @fires execute
-	 */
-	execute( options = {} ) {
-		const model = this.editor.model;
-		const document = model.document;
-		const selection = document.selection;
-
-		const item = options.mention;
-		const range = options.range || selection.getFirstRange();
-
-		const name = item.name || item;
-
-		model.change( writer => {
-			writer.remove( range );
-
-			const mention = writer.createElement( 'mentionElement', { name, item } );
-
-			model.insertContent( mention );
-			writer.insertText( ' ', model.document.selection.focus );
-		} );
-	}
-}
-
-/**
- * The mention editing feature.
- *
- * @extends module:core/plugin~Plugin
- */
-export default class MentionElementEditing extends Plugin {
-	/**
-	 * @inheritDoc
-	 */
-	static get pluginName() {
-		return 'MentionElementEditing';
-	}
-
-	/**
-	 * @inheritDoc
-	 */
-	init() {
-		const editor = this.editor;
-
-		editor.model.schema.register( 'mentionElement', {
-			allowWhere: '$text',
-			isObject: true,
-			isInline: true,
-			allowAttributes: [ 'name', 'item' ]
-		} );
-
-		editor.conversion.for( 'downcast' ).elementToElement( {
-			model: 'mentionElement',
-			view: ( modelItem, viewWriter ) => {
-				const mentionElement = viewWriter.createContainerElement( 'span', { class: 'mention' } );
-
-				const viewText = viewWriter.createText( modelItem.getAttribute( 'name' ) );
-
-				viewWriter.insert( viewWriter.createPositionAt( mentionElement, 0 ), viewText );
-
-				return mentionElement;
-			}
-		} );
-
-		editor.conversion.for( 'upcast' ).elementToElement( {
-			view: 'mentionElement',
-			model: ( viewElement, modelWriter ) => {
-				let name = 'general';
-
-				if ( viewElement.childCount ) {
-					const text = viewElement.getChild( 0 );
-
-					if ( text.is( 'text' ) ) {
-						name = text;
-					}
-				}
-
-				return modelWriter.createElement( 'mentionElement', { name } );
-			}
-		} );
-
-		editor.editing.mapper.on(
-			'viewToModelPosition',
-			viewToModelPositionOutsideModelElement( editor.model, viewElement => viewElement.name == 'mentionElement' )
-		);
-
-		editor.commands.add( 'mention', new MentionCommand( editor ) );
-	}
-}

+ 0 - 131
packages/ckeditor5-mention/src/mentioneditingmarker.js

@@ -1,131 +0,0 @@
-/**
- * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
-
-/**
- * @module mention/mentionediting
- */
-
-import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
-import Command from '@ckeditor/ckeditor5-core/src/command';
-
-export function createMentionMarkerId( someString ) {
-	const randId = parseInt( Math.random() * 10000 );
-	const normalizedString = someString.toLowerCase().replace( ' ', '-' );
-
-	return `mention:${ normalizedString }:${ randId }`;
-}
-
-class MentionCommand extends Command {
-	/**
-	 * @inheritDoc
-	 */
-	refresh() {
-		// @todo implement refresh
-		this.isEnabled = true;
-	}
-
-	/**
-	 * Executes the command.
-	 *
-	 * @protected
-	 * @param {Object} [options] Options for the executed command.
-	 * @param {String} [options.marker='@'] The mention marker.
-	 * @param {String} options.mention.
-	 * @param {String} [options.range].
-	 * @fires execute
-	 */
-	execute( options = {} ) {
-		const model = this.editor.model;
-		const document = model.document;
-		const selection = document.selection;
-
-		const item = options.mention;
-		const range = options.range || selection.getFirstRange();
-
-		const name = item.name || item;
-
-		model.change( writer => {
-			writer.remove( range );
-
-			const text = writer.createText( '@' + name );
-
-			writer.insert( text, selection.focus );
-
-			// TODO dumb
-			const markerName = createMentionMarkerId( name );
-
-			writer.addMarker( markerName, {
-				range: writer.createRange( selection.focus.getShiftedBy( -text.data.length ), selection.focus ),
-				usingOperation: true,
-				affectData: true
-			} );
-		} );
-	}
-}
-
-/**
- * The mention editing feature.
- *
- * @extends module:core/plugin~Plugin
- */
-export default class MentionElementEditing extends Plugin {
-	/**
-	 * @inheritDoc
-	 */
-	static get pluginName() {
-		return 'MentionElementEditing';
-	}
-
-	/**
-	 * @inheritDoc
-	 */
-	init() {
-		const editor = this.editor;
-
-		// Allow comment on text nodes.
-		editor.model.schema.extend( '$text', { allowAttributes: [ 'mention' ] } );
-
-		// Allow comment on all objects.
-		editor.model.schema.addAttributeCheck( ( context, attributeName ) => {
-			if ( attributeName == 'mention' && editor.model.schema.isObject( context.last ) ) {
-				return true;
-			}
-		} );
-
-		// Convert marker m->v for editing pipeline.
-		editor.conversion.for( 'downcast' ).markerToHighlight( {
-			model: 'mention',
-			view: data => {
-				const { id } = splitMarkerName( data.markerName );
-
-				return {
-					classes: [ 'mention' ],
-					attributes: {
-						'data-mention': id
-					}
-				};
-			}
-		} );
-
-		// Convert marker v->m.
-		editor.conversion.for( 'upcast' ).elementToMarker( {
-			view: {
-				name: 'mention',
-				attribute: {
-					id: /^\w/
-				}
-			},
-			model: viewElement => 'mention:' + viewElement.getAttribute( 'id' )
-		} );
-
-		editor.commands.add( 'mention', new MentionCommand( editor ) );
-	}
-}
-
-function splitMarkerName( name ) {
-	const path = name.split( ':' );
-
-	return { group: path[ 0 ], id: path[ 1 ] };
-}

+ 2 - 5
packages/ckeditor5-mention/tests/manual/mention-custom-view.html

@@ -1,10 +1,7 @@
 <div id="editor">
 <div id="editor">
-	<p>Have you met... <a class="mention" data-mention="Ted Mosby" href="https://www.imdb.com/title/tt0460649/characters/nm1102140">Ted Mosby</a></p>
+	<p>Have you met... <a class="mention" data-mention="Ted Mosby" href="https://www.imdb.com/title/tt0460649/characters/nm1102140">@Ted Mosby</a></p>
 
 
-	<h2>Test cases:</h2>
-	<ul>
-		<li><strong>Same mention twice in data:</strong> <a class="mention" data-mention="Ted Mosby" href="https://www.imdb.com/title/tt0460649/characters/nm1102140">Ted Mosby</a><a class="mention" data-mention="Ted Mosby" href="https://www.imdb.com/title/tt0460649/characters/nm1102140">Ted Mosby</a></li>
-	</ul>
+	<p>Same mention twice in data: <a class="mention" data-mention="Ted Mosby" href="https://www.imdb.com/title/tt0460649/characters/nm1102140">@Ted Mosby</a><a class="mention" data-mention="Ted Mosby" href="https://www.imdb.com/title/tt0460649/characters/nm1102140">@Ted Mosby</a></p>
 </div>
 </div>
 
 
 <style>
 <style>

+ 1 - 141
packages/ckeditor5-mention/tests/manual/mention-custom-view.js

@@ -23,20 +23,12 @@ import Italic from '@ckeditor/ckeditor5-basic-styles/src/italic';
 import Underline from '@ckeditor/ckeditor5-basic-styles/src/underline';
 import Underline from '@ckeditor/ckeditor5-basic-styles/src/underline';
 import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
 import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
 import priorities from '@ckeditor/ckeditor5-utils/src/priorities';
 import priorities from '@ckeditor/ckeditor5-utils/src/priorities';
-import ModelSelection from '@ckeditor/ckeditor5-engine/src/model/selection';
-import DocumentSelection from '@ckeditor/ckeditor5-engine/src/model/documentselection';
 
 
 import MentionUI from '../../src/mentionui';
 import MentionUI from '../../src/mentionui';
-// eslint-disable-next-line no-unused-vars
 import MentionEditing from '../../src/mentionediting';
 import MentionEditing from '../../src/mentionediting';
-// eslint-disable-next-line no-unused-vars
-import MentionElementEditing from '../../src/mentioneditingelement';
-// eslint-disable-next-line no-unused-vars
-import MentionMarkerEditing, { createMentionMarkerId } from '../../src/mentioneditingmarker';
 
 
 const HIGHER_THEN_HIGHEST = priorities.highest + 50;
 const HIGHER_THEN_HIGHEST = priorities.highest + 50;
 
 
-// eslint-disable-next-line no-unused-vars
 class CustomMentionAttributeView extends Plugin {
 class CustomMentionAttributeView extends Plugin {
 	init() {
 	init() {
 		const editor = this.editor;
 		const editor = this.editor;
@@ -82,142 +74,10 @@ class CustomMentionAttributeView extends Plugin {
 	}
 	}
 }
 }
 
 
-// eslint-disable-next-line no-unused-vars
-class CustomMentionElementView extends Plugin {
-	init() {
-		const editor = this.editor;
-
-		editor.conversion.for( 'upcast' ).elementToElement( {
-			view: {
-				name: 'a',
-				classes: 'mention',
-				attributes: {
-					href: true
-				}
-			},
-			model: ( viewItem, modelWriter ) => {
-				const item = {
-					name: viewItem.getAttribute( 'data-mention' ),
-					link: viewItem.getAttribute( 'href' )
-				};
-
-				const frag = modelWriter.createDocumentFragment();
-				const mention = modelWriter.createElement( 'mention', { item } );
-
-				modelWriter.insert( mention, frag, 0 );
-
-				modelWriter.insertText( item.name, mention, 0 );
-
-				return mention;
-			},
-			converterPriority: HIGHER_THEN_HIGHEST
-		} );
-
-		editor.conversion.for( 'downcast' ).elementToElement( {
-			model: 'mentionElement',
-			view: ( modelElement, viewWriter ) => {
-				const item = modelElement.getAttribute( 'item' );
-
-				const link = viewWriter.createContainerElement( 'a', {
-					class: 'mention',
-					'data-mention': item.name,
-					'href': item.link
-				} );
-
-				return link;
-			},
-			converterPriority: HIGHER_THEN_HIGHEST
-		} );
-	}
-}
-
-// eslint-disable-next-line no-unused-vars
-class CustomMentionMarkerView extends Plugin {
-	init() {
-		const editor = this.editor;
-
-		// Convert marker v->m.
-		editor.conversion.for( 'upcast' ).elementToMarker( {
-			view: {
-				name: 'a',
-				attribute: {
-					'data-mention': /^\w/
-				}
-			},
-			model: viewElement => createMentionMarkerId( viewElement.getAttribute( 'data-mention' ) )
-		} );
-
-		editor.conversion.for( 'downcast' ).add( dispatcher => {
-			dispatcher.on( 'addMarker:mention', ( evt, data, conversionApi ) => {
-				const name = data.markerName.split( ':' )[ 1 ];
-				const id = data.markerName.split( ':' )[ 2 ];
-
-				if ( !conversionApi.consumable.consume( data.item, evt.name ) ) {
-					return;
-				}
-
-				const viewWriter = conversionApi.writer;
-
-				const item = getFeed( name.replace( '-', ' ' ) )[ 0 ];
-
-				const attributes = {
-					class: [ 'mention' ],
-					'data-mention': name,
-					id
-				};
-
-				if ( item ) {
-					attributes.href = item.link;
-					attributes.title = item.name;
-				}
-
-				// OMG I just wanted to change `<span>` to `<a>`...
-				const viewElement = viewWriter.createAttributeElement( 'a', attributes );
-
-				const viewSelection = viewWriter.document.selection;
-
-				if ( data.item instanceof ModelSelection || data.item instanceof DocumentSelection ) {
-					viewWriter.wrap( viewSelection.getFirstRange(), viewElement, viewSelection );
-				} else {
-					const viewRange = conversionApi.mapper.toViewRange( data.range );
-					const rangeAfterWrap = viewWriter.wrap( viewRange, viewElement );
-
-					for ( const element of rangeAfterWrap.getItems() ) {
-						if ( element.is( 'attributeElement' ) && element.isSimilar( viewElement ) ) {
-							conversionApi.mapper.bindElementToMarker( element, data.markerName );
-
-							// One attribute element is enough, because all of them are bound together by the view writer.
-							// Mapper uses this binding to get all the elements no matter how many of them are registered in the mapper.
-							break;
-						}
-					}
-				}
-			}, { priority: HIGHER_THEN_HIGHEST } );
-		} );
-	}
-}
-
 ClassicEditor
 ClassicEditor
 	.create( global.document.querySelector( '#editor' ), {
 	.create( global.document.querySelector( '#editor' ), {
 		plugins: [ Enter, Typing, Paragraph, Link, Heading, Bold, Italic, Underline, Undo, Clipboard, Widget, ShiftEnter, Table,
 		plugins: [ Enter, Typing, Paragraph, Link, Heading, Bold, Italic, Underline, Undo, Clipboard, Widget, ShiftEnter, Table,
-
-			// Uncomment below groups while commenting other to change model behavior.
-
-			// 1. Using attributes
-			MentionEditing,
-			CustomMentionAttributeView,
-
-			// 2. Using Element - buggy
-			// MentionElementEditing,
-			// CustomMentionElementView,
-
-			// 3. Using marker - promising
-			// MentionMarkerEditing,
-			// CustomMentionMarkerView,
-
-			// Common: ui
-			MentionUI
-		],
+			MentionEditing, CustomMentionAttributeView, MentionUI ],
 		toolbar: [ 'heading', '|', 'bold', 'italic', 'underline', 'link', '|', 'insertTable', '|', 'undo', 'redo' ],
 		toolbar: [ 'heading', '|', 'bold', 'italic', 'underline', 'link', '|', 'insertTable', '|', 'undo', 'redo' ],
 		mention: [
 		mention: [
 			{
 			{