diff --git a/bin/update-readmes.js b/bin/update-readmes.js index d226dba560836..809357c68682d 100755 --- a/bin/update-readmes.js +++ b/bin/update-readmes.js @@ -35,31 +35,15 @@ const packages = [ 'wordcount', ]; -const getArgsForPackage = ( packageName ) => { - switch ( packageName ) { - case 'rich-text': - return [ - `packages/${ packageName }/src/index.js`, - `--output packages/${ packageName }/README.md`, - '--to-token', - '--ignore "/unstable|experimental|^apply$|^changeListType$|^charAt$|^getSelectionStart$|^getSelectionEnd$|^indentListItems$|^insertLineBreak$|^insertLineSeparator$|^isEmptyLine$|^LINE_SEPARATOR$|^outdentListItems$/i"', - ]; - default: - return [ - `packages/${ packageName }/src/index.js`, - `--output packages/${ packageName }/README.md`, - '--to-token', - '--ignore "/unstable|experimental/i"', - ]; - } -}; - Promise.all( packages.map( async ( packageName ) => { - const args = getArgsForPackage( packageName ); - const pathToDocGen = path.join( __dirname, '..', 'node_modules', '.bin', 'docgen' ); const { status, stderr } = await spawn( - pathToDocGen, - args, + path.join( __dirname, '..', 'node_modules', '.bin', 'docgen' ), + [ + `packages/${ packageName }/src/index.js`, + `--output packages/${ packageName }/README.md`, + '--to-token', + '--ignore "/unstable|experimental/i"', + ], { shell: true }, ); if ( status !== 0 ) { diff --git a/packages/block-editor/src/components/rich-text/index.js b/packages/block-editor/src/components/rich-text/index.js index ed94653f98be3..4a643917f5bb0 100644 --- a/packages/block-editor/src/components/rich-text/index.js +++ b/packages/block-editor/src/components/rich-text/index.js @@ -27,23 +27,22 @@ import { isURL } from '@wordpress/url'; import { isEmpty, create, - apply, + __unstableApply as apply, applyFormat, split, toHTMLString, getTextContent, insert, - insertLineBreak, - insertLineSeparator, - isEmptyLine, - unstableToDom, + __unstableInsertLineSeparator as insertLineSeparator, + __unstableIsEmptyLine as isEmptyLine, + __unstableToDom as toDom, remove, removeFormat, isCollapsed, - LINE_SEPARATOR, - indentListItems, - __unstableGetActiveFormats, - __unstableUpdateFormats, + __UNSTABLE_LINE_SEPARATOR as LINE_SEPARATOR, + __unstableIndentListItems as indentListItems, + __unstableGetActiveFormats as getActiveFormats, + __unstableUpdateFormats as updateFormats, } from '@wordpress/rich-text'; import { decodeEntities } from '@wordpress/html-entities'; import { withFilters, IsolatedEventContainer } from '@wordpress/components'; @@ -411,7 +410,7 @@ export class RichText extends Component { const { activeFormats = [], start } = this.state; // Update the formats between the last and new caret position. - const change = __unstableUpdateFormats( { + const change = updateFormats( { value, start, end: value.start, @@ -452,7 +451,7 @@ export class RichText extends Component { if ( start !== this.state.start || end !== this.state.end ) { const { isCaretWithinFormattedText } = this.props; - const activeFormats = __unstableGetActiveFormats( value ); + const activeFormats = getActiveFormats( value ); if ( ! isCaretWithinFormattedText && activeFormats.length ) { this.props.onEnterFormattedText(); @@ -705,14 +704,14 @@ export class RichText extends Component { if ( this.multilineTag ) { if ( event.shiftKey ) { - this.onChange( insertLineBreak( record ) ); + this.onChange( insert( record, '\n' ) ); } else if ( this.onSplit && isEmptyLine( record ) ) { this.onSplit( ...split( record ).map( this.valueToFormat ) ); } else { this.onChange( insertLineSeparator( record ) ); } } else if ( event.shiftKey || ! this.onSplit ) { - this.onChange( insertLineBreak( record ) ); + this.onChange( insert( record, '\n' ) ); } else { this.splitContent(); } @@ -985,7 +984,7 @@ export class RichText extends Component { } valueToEditableHTML( value ) { - return unstableToDom( { + return toDom( { value, multilineTag: this.multilineTag, prepareEditableTree: this.props.prepareEditableTree, @@ -1023,7 +1022,7 @@ export class RichText extends Component { // Handle deprecated `children` and `node` sources. if ( this.usedDeprecatedChildrenSource ) { - return children.fromDOM( unstableToDom( { + return children.fromDOM( toDom( { value, multilineTag: this.multilineTag, isEditableTree: false, diff --git a/packages/block-editor/src/components/rich-text/list-edit.js b/packages/block-editor/src/components/rich-text/list-edit.js index aee85983258df..185f317d616fd 100644 --- a/packages/block-editor/src/components/rich-text/list-edit.js +++ b/packages/block-editor/src/components/rich-text/list-edit.js @@ -6,9 +6,9 @@ import { Toolbar } from '@wordpress/components'; import { __, _x } from '@wordpress/i18n'; import { Fragment } from '@wordpress/element'; import { - indentListItems, - outdentListItems, - changeListType, + __unstableIndentListItems as indentListItems, + __unstableOutdentListItems as outdentListItems, + __unstableChangeListType as changeListType, } from '@wordpress/rich-text'; /** diff --git a/packages/block-editor/src/components/rich-text/patterns.js b/packages/block-editor/src/components/rich-text/patterns.js index a1d5794cca828..6f68efa08b1ef 100644 --- a/packages/block-editor/src/components/rich-text/patterns.js +++ b/packages/block-editor/src/components/rich-text/patterns.js @@ -6,7 +6,6 @@ import { remove, applyFormat, getTextContent, - getSelectionStart, slice, } from '@wordpress/rich-text'; @@ -20,7 +19,7 @@ export function getPatterns( { onReplace, valueToFormat } ) { return record; } - const start = getSelectionStart( record ); + const { start } = record; const text = getTextContent( record ); const characterBefore = text.slice( start - 1, start ); @@ -46,7 +45,7 @@ export function getPatterns( { onReplace, valueToFormat } ) { }, ( record ) => { const BACKTICK = '`'; - const start = getSelectionStart( record ); + const { start } = record; const text = getTextContent( record ); const characterBefore = text.slice( start - 1, start ); diff --git a/packages/block-library/src/list/index.js b/packages/block-library/src/list/index.js index c389d914f508a..7be46a76fb322 100644 --- a/packages/block-library/src/list/index.js +++ b/packages/block-library/src/list/index.js @@ -13,7 +13,7 @@ import { getBlockAttributes, } from '@wordpress/blocks'; import { RichText } from '@wordpress/block-editor'; -import { replace, join, split, create, toHTMLString, LINE_SEPARATOR } from '@wordpress/rich-text'; +import { replace, join, split, create, toHTMLString, __UNSTABLE_LINE_SEPARATOR } from '@wordpress/rich-text'; /** * Internal dependencies @@ -87,8 +87,8 @@ export const settings = { // When converting only one block, transform // every line to a list item. - return replace( value, /\n/g, LINE_SEPARATOR ); - } ), LINE_SEPARATOR ), + return replace( value, /\n/g, __UNSTABLE_LINE_SEPARATOR ); + } ), __UNSTABLE_LINE_SEPARATOR ), multilineTag: 'li', } ), } ); @@ -152,7 +152,7 @@ export const settings = { html: values, multilineTag: 'li', multilineWrapperTags: [ 'ul', 'ol' ], - } ), LINE_SEPARATOR ) + } ), __UNSTABLE_LINE_SEPARATOR ) .map( ( piece ) => createBlock( 'core/paragraph', { content: toHTMLString( { value: piece } ), diff --git a/packages/docgen/coverage.md b/packages/docgen/coverage.md index 83c5dfd3d59fa..5fd3bd6544265 100644 --- a/packages/docgen/coverage.md +++ b/packages/docgen/coverage.md @@ -20,8 +20,8 @@ These either happen in private API, aren't relevant, or are pending of decission. -- [ ] go undocummented: `unstable__*`, rich-text `unstableToDom`, `experimental__` -- [ ] `constants` keycodes, rich-text `LINE_SEPARATOR` +- [ ] go undocummented: `unstable__*` +- [ ] `constants` keycodes - [ ] `{?{ time: number, count: number }}`packages/editor/src/store/selectors.js - [ ] `{type=}` packages/block-library/src/image/edit.js - [ ] `@api` packages/editor/src/editor-styles/ast/stringify/compiler.js diff --git a/packages/rich-text/CHANGELOG.md b/packages/rich-text/CHANGELOG.md index f3bb924d1898d..c80223634d1e8 100644 --- a/packages/rich-text/CHANGELOG.md +++ b/packages/rich-text/CHANGELOG.md @@ -1,3 +1,21 @@ +## 3.2.0 (Unreleased) + +### Internal + +- Removed and renamed undocumented functions and constants: + * Removed `charAt` + * Removed `getSelectionStart` + * Removed `getSelectionEnd` + * Removed `insertLineBreak` + * Renamed `isEmptyLine` to `__unstableIsEmptyLine` + * Renamed `insertLineSeparator` to `__unstableInsertLineSeparator` + * Renamed `apply` to `__unstableApply` + * Renamed `unstableToDom` to `__unstableToDom` + * Renamed `LINE_SEPARATOR` to `__UNSTABLE_LINE_SEPARATOR` + * Renamed `indentListItems` to `__unstableIndentListItems` + * Renamed `outdentListItems` to `__unstableOutdentListItems` + * Renamed `changeListType` to `__unstableChangeListType` + ## 3.1.0 (2019-03-06) ### Enhancement diff --git a/packages/rich-text/src/char-at.js b/packages/rich-text/src/char-at.js deleted file mode 100644 index e68d3b6a5a5ac..0000000000000 --- a/packages/rich-text/src/char-at.js +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Gets the character at the specified index, or returns `undefined` if no - * character was found. - * - * @param {Object} value Value to get the character from. - * @param {string} index Index to use. - * - * @return {string|undefined} A one character long string, or undefined. - */ -export function charAt( { text }, index ) { - return text[ index ]; -} diff --git a/packages/rich-text/src/get-selection-end.js b/packages/rich-text/src/get-selection-end.js deleted file mode 100644 index 8154a48b451fb..0000000000000 --- a/packages/rich-text/src/get-selection-end.js +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Gets the end index of the current selection, or returns `undefined` if no - * selection exists. The selection ends right before the character at this - * index. - * - * @param {Object} value Value to get the selection from. - * - * @return {number|undefined} Index where the selection ends. - */ -export function getSelectionEnd( { end } ) { - return end; -} diff --git a/packages/rich-text/src/get-selection-start.js b/packages/rich-text/src/get-selection-start.js deleted file mode 100644 index 442d84d308691..0000000000000 --- a/packages/rich-text/src/get-selection-start.js +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Gets the start index of the current selection, or returns `undefined` if no - * selection exists. The selection starts right before the character at this - * index. - * - * @param {Object} value Value to get the selection from. - * - * @return {number|undefined} Index where the selection starts. - */ -export function getSelectionStart( { start } ) { - return start; -} diff --git a/packages/rich-text/src/index.js b/packages/rich-text/src/index.js index 63da636257619..f9a977b2539b6 100644 --- a/packages/rich-text/src/index.js +++ b/packages/rich-text/src/index.js @@ -4,34 +4,30 @@ import './store'; export { applyFormat } from './apply-format'; -export { charAt } from './char-at'; export { concat } from './concat'; export { create } from './create'; export { getActiveFormat } from './get-active-format'; export { getActiveObject } from './get-active-object'; -export { getSelectionEnd } from './get-selection-end'; -export { getSelectionStart } from './get-selection-start'; export { getTextContent } from './get-text-content'; export { isCollapsed } from './is-collapsed'; -export { isEmpty, isEmptyLine } from './is-empty'; +export { isEmpty, isEmptyLine as __unstableIsEmptyLine } from './is-empty'; export { join } from './join'; export { registerFormatType } from './register-format-type'; export { removeFormat } from './remove-format'; export { remove } from './remove'; export { replace } from './replace'; export { insert } from './insert'; -export { insertLineBreak } from './insert-line-break'; -export { insertLineSeparator } from './insert-line-separator'; +export { insertLineSeparator as __unstableInsertLineSeparator } from './insert-line-separator'; export { insertObject } from './insert-object'; export { slice } from './slice'; export { split } from './split'; -export { apply, toDom as unstableToDom } from './to-dom'; +export { apply as __unstableApply, toDom as __unstableToDom } from './to-dom'; export { toHTMLString } from './to-html-string'; export { toggleFormat } from './toggle-format'; -export { LINE_SEPARATOR } from './special-characters'; +export { LINE_SEPARATOR as __UNSTABLE_LINE_SEPARATOR } from './special-characters'; export { unregisterFormatType } from './unregister-format-type'; -export { indentListItems } from './indent-list-items'; -export { outdentListItems } from './outdent-list-items'; -export { changeListType } from './change-list-type'; +export { indentListItems as __unstableIndentListItems } from './indent-list-items'; +export { outdentListItems as __unstableOutdentListItems } from './outdent-list-items'; +export { changeListType as __unstableChangeListType } from './change-list-type'; export { updateFormats as __unstableUpdateFormats } from './update-formats'; export { getActiveFormats as __unstableGetActiveFormats } from './get-active-formats'; diff --git a/packages/rich-text/src/insert-line-break.js b/packages/rich-text/src/insert-line-break.js deleted file mode 100644 index 08b0b70b864e6..0000000000000 --- a/packages/rich-text/src/insert-line-break.js +++ /dev/null @@ -1,16 +0,0 @@ -/** - * Internal dependencies - */ - -import { insert } from './insert'; - -/** - * Inserts a line break at the given or selected position. - * - * @param {Object} value Value to modify. - * - * @return {Object} The value with the line break inserted. - */ -export function insertLineBreak( value ) { - return insert( value, '\n' ); -}