Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
654eb22
Writing Flow: Collapse range in horizontal edge check by direction
aduth Apr 27, 2018
f7dcc8a
Try alternative approach
ellatrix Apr 30, 2018
bef44c3
Writing Flow: Move collapsed selection condition to WritingFlow
aduth May 2, 2018
a8728bf
Writing Flow: Vertical navigate from uncollapsed selections
aduth May 2, 2018
79fc388
Writing Flow: Use Selection#isCollapsed in place of hasCollapsedSelec…
aduth May 2, 2018
83d3ff7
Rich Text: Verify collapsed selection in delete behavior
aduth May 2, 2018
33184f9
Utils: Improve range rect detection for br-separated content
aduth May 2, 2018
f2ae9ef
Testing: Add Writing Flow E2E tests
aduth May 2, 2018
d81ac98
Try getRectangleFromRange fix without manipulating live DOM
ellatrix May 2, 2018
284900e
Utils: Update caret to selection in edge tests comments
aduth May 3, 2018
bc252af
Writing Flow: Invert position when isReverse not aligned to backward
aduth May 3, 2018
a961282
Try direct selection
ellatrix May 3, 2018
6431770
Only look at focusNode
ellatrix May 3, 2018
c0a0fc3
Utils: Document horizontal edge focusOffset
aduth May 3, 2018
b5a54df
Utils: Use temporary text node for rect fallback
aduth May 3, 2018
e087ddd
Writing Flow: Test horizontal navigation as handled
aduth May 3, 2018
7b174ad
Element: Fix Fragment render error on empty children
aduth May 10, 2018
a528868
Testing: Add global guard against ZWSP in E2E content retrieval
aduth May 10, 2018
d6f1ab9
RichText: Remove ZWSP on focusout
aduth May 10, 2018
4523390
RichText: Consider emptiness by Children count utility
aduth May 10, 2018
31596df
Writing Flow: Consider horizontal handled by stopPropagation in RichText
aduth May 10, 2018
fa4ad6d
RichText: Get content by converting tree node to element
aduth May 10, 2018
2afb649
Writing Flow: Consider as edge by effective caret position
aduth May 10, 2018
dab93de
Rich Text: Return element fragment as array
aduth May 10, 2018
9dde841
Testing: Attempt to resolve race conditions with TinyMCE initialization
aduth May 10, 2018
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
Prev Previous commit
Next Next commit
RichText: Get content by converting tree node to element
format: 'tree' is only available in versions newer than 4.7.2, thus requiring update
  • Loading branch information
aduth committed May 10, 2018
commit fa4ad6d67824d0f9ee0457c73708137886b7cf4a
36 changes: 34 additions & 2 deletions editor/components/rich-text/format.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
/**
* External dependencies
*/
import { omitBy } from 'lodash';
import { omitBy, get } from 'lodash';
import { nodeListToReact } from 'dom-react';

/**
* WordPress dependencies
*/
import { createElement, renderToString } from '@wordpress/element';
import { Fragment, createElement, renderToString } from '@wordpress/element';

/**
* Browser dependencies
*/

const { Node } = window;

/**
* Transforms a WP Element to its corresponding HTML string.
Expand Down Expand Up @@ -62,6 +68,32 @@ export function createTinyMCEElement( type, props, ...children ) {
);
}

/**
* Given a TinyMCE Node instance, returns an equivalent WordPress element.
*
* @param {tinyMCE.html.Node} node TinyMCE node
*
* @return {WPElement} WordPress element
*/
export function tinyMCENodeToElement( node ) {
if ( node.type === Node.TEXT_NODE ) {
return node.value;
}

const children = [];

let child = node.firstChild;
while ( child ) {
children.push( tinyMCENodeToElement( child ) );
child = child.next;
}

const tagName = node.type === Node.DOCUMENT_FRAGMENT_NODE ? Fragment : node.name;
const attributes = get( node.attributes, [ 'map' ], {} );

return createElement( tagName, attributes, ...children );
}

/**
* Transforms an array of DOM Elements to their corresponding WP element.
*
Expand Down
10 changes: 6 additions & 4 deletions editor/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ import { pickAriaProps } from './aria';
import patterns from './patterns';
import { EVENTS } from './constants';
import { withBlockEditContext } from '../block-edit/context';
import { domToFormat, valueToString } from './format';
import {
domToFormat,
valueToString,
tinyMCENodeToElement,
} from './format';

/**
* Browser dependencies
Expand Down Expand Up @@ -820,9 +824,7 @@ export class RichText extends Component {
case 'string':
return this.editor.getContent();
default:
return this.editor.dom.isEmpty( this.editor.getBody() ) ?
[] :
domToFormat( this.editor.getBody().childNodes || [], 'element', this.editor );
return tinyMCENodeToElement( this.editor.getContent( { format: 'tree' } ) );
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ function gutenberg_register_vendor_scripts() {
'https://unpkg.com/[email protected]/' . $moment_script,
array()
);
$tinymce_version = '4.7.2';
$tinymce_version = '4.7.12';
gutenberg_register_vendor_script(
'tinymce-latest',
'https://unpkg.com/tinymce@' . $tinymce_version . '/tinymce' . $suffix . '.js'
Expand Down