Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RichText & Docs: remove or rename undocumented functions and constants #14239

Merged
merged 2 commits into from
Apr 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
30 changes: 7 additions & 23 deletions bin/update-readmes.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,15 @@ const packages = [
'wordcount',
];

const getArgsForPackage = ( packageName ) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

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 ) {
Expand Down
29 changes: 14 additions & 15 deletions packages/block-editor/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -985,7 +984,7 @@ export class RichText extends Component {
}

valueToEditableHTML( value ) {
return unstableToDom( {
return toDom( {
value,
multilineTag: this.multilineTag,
prepareEditableTree: this.props.prepareEditableTree,
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions packages/block-editor/src/components/rich-text/list-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand Down
5 changes: 2 additions & 3 deletions packages/block-editor/src/components/rich-text/patterns.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
remove,
applyFormat,
getTextContent,
getSelectionStart,
slice,
} from '@wordpress/rich-text';

Expand All @@ -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 );

Expand All @@ -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 );

Expand Down
8 changes: 4 additions & 4 deletions packages/block-library/src/list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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',
} ),
} );
Expand Down Expand Up @@ -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 } ),
Expand Down
4 changes: 2 additions & 2 deletions packages/docgen/coverage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions packages/rich-text/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 0 additions & 12 deletions packages/rich-text/src/char-at.js

This file was deleted.

12 changes: 0 additions & 12 deletions packages/rich-text/src/get-selection-end.js

This file was deleted.

12 changes: 0 additions & 12 deletions packages/rich-text/src/get-selection-start.js

This file was deleted.

18 changes: 7 additions & 11 deletions packages/rich-text/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renaming the symbol at this point to use the __unstable prefix will work as far as the doc generator is concerned because it uses the export statements to filter out the symbols to be ignored. However, I would lean towards renaming the symbol declaration as well. It may be benefitial as an urge to settle this API every time we work on it. Thoughts?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, maybe it's good to do that. But the reason it's marked unstable is that it was never meant to be exported. It's only used by the RichText component, which should eventually live in these packages. So it's meant as an internal helper function, temporarily exported because these's one component left that's not been moved to this package yet.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be benefitial as an urge to settle this API every time we work on it.

So, regarding this, there's nothing to be settled. We need to move RichText so we can remove the export statements.

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';
16 changes: 0 additions & 16 deletions packages/rich-text/src/insert-line-break.js

This file was deleted.