@wordpress/rich-text
Advanced tools
Comparing version 3.24.1 to 3.24.2-next.0
@@ -8,9 +8,2 @@ import { createElement } from "@wordpress/element"; | ||
import { getActiveObject } from '../get-active-object'; | ||
/** | ||
* Set of all interactive content tags. | ||
* | ||
* @see https://html.spec.whatwg.org/multipage/dom.html#interactive-content | ||
*/ | ||
var interactiveContentTags = new Set(['a', 'audio', 'button', 'details', 'embed', 'iframe', 'input', 'label', 'select', 'textarea', 'video']); | ||
export default function FormatEdit(_ref) { | ||
@@ -21,9 +14,6 @@ var formatTypes = _ref.formatTypes, | ||
value = _ref.value, | ||
allowedFormats = _ref.allowedFormats, | ||
withoutInteractiveFormatting = _ref.withoutInteractiveFormatting, | ||
forwardedRef = _ref.forwardedRef; | ||
return formatTypes.map(function (settings) { | ||
var name = settings.name, | ||
Edit = settings.edit, | ||
tagName = settings.tagName; | ||
Edit = settings.edit; | ||
@@ -34,10 +24,2 @@ if (!Edit) { | ||
if (allowedFormats && allowedFormats.indexOf(name) === -1) { | ||
return null; | ||
} | ||
if (withoutInteractiveFormatting && interactiveContentTags.has(tagName)) { | ||
return null; | ||
} | ||
var activeFormat = getActiveFormat(value, name); | ||
@@ -44,0 +26,0 @@ var isActive = activeFormat !== undefined; |
@@ -162,3 +162,5 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; | ||
clientId: clientId, | ||
identifier: identifier | ||
identifier: identifier, | ||
withoutInteractiveFormatting: withoutInteractiveFormatting, | ||
allowedFormats: allowedFormats | ||
}), | ||
@@ -1042,4 +1044,2 @@ formatTypes = _useFormatTypes.formatTypes, | ||
return createElement(Fragment, null, isSelected && createElement(FormatEdit, { | ||
allowedFormats: allowedFormats, | ||
withoutInteractiveFormatting: withoutInteractiveFormatting, | ||
value: record.current, | ||
@@ -1046,0 +1046,0 @@ onChange: handleChange, |
@@ -51,2 +51,3 @@ import _extends from "@babel/runtime/helpers/esm/extends"; | ||
import { useFormatTypes } from './use-format-types'; | ||
import FormatEdit from './format-edit'; | ||
@@ -66,3 +67,2 @@ import { applyFormat } from '../apply-format'; | ||
import ToolbarButtonWithOptions from './toolbar-button-with-options'; | ||
import { store as richTextStore } from '../store'; | ||
@@ -827,3 +827,2 @@ var unescapeSpaces = function unescapeSpaces(text) { | ||
parentBlockStyles = _this$props6.parentBlockStyles, | ||
withoutInteractiveFormatting = _this$props6.withoutInteractiveFormatting, | ||
accessibilityLabel = _this$props6.accessibilityLabel, | ||
@@ -960,3 +959,2 @@ _this$props6$disableE = _this$props6.disableEditingMenu, | ||
value: record, | ||
withoutInteractiveFormatting: withoutInteractiveFormatting, | ||
onChange: this.onFormatChange, | ||
@@ -977,2 +975,18 @@ onFocus: function onFocus() {} | ||
}; | ||
var withFormatTypes = function withFormatTypes(WrappedComponent) { | ||
return function (props) { | ||
var _useFormatTypes = useFormatTypes({ | ||
clientId: props.clientId, | ||
identifier: props.identifier, | ||
withoutInteractiveFormatting: props.withoutInteractiveFormatting | ||
}), | ||
formatTypes = _useFormatTypes.formatTypes; | ||
return createElement(WrappedComponent, _extends({}, props, { | ||
formatTypes: formatTypes | ||
})); | ||
}; | ||
}; | ||
export default compose([withSelect(function (select, _ref4) { | ||
@@ -990,3 +1004,2 @@ var clientId = _ref4.clientId; | ||
return _objectSpread({ | ||
formatTypes: select(richTextStore).getFormatTypes(), | ||
areMentionsSupported: getSettings('capabilities').mentions === true, | ||
@@ -997,3 +1010,3 @@ areXPostsSupported: getSettings('capabilities').xposts === true | ||
}); | ||
}), withPreferredColorScheme])(RichText); | ||
}), withPreferredColorScheme, withFormatTypes])(RichText); | ||
//# sourceMappingURL=index.native.js.map |
@@ -49,3 +49,3 @@ import { createElement, Fragment } from "@wordpress/element"; | ||
onClick: firstOption.onClick, | ||
onLongPress: enablePicker && presentPicker | ||
onLongPress: enablePicker ? presentPicker : undefined | ||
})), enablePicker && createElement(Picker, { | ||
@@ -52,0 +52,0 @@ ref: picker, |
@@ -41,4 +41,4 @@ /** | ||
return useMemo(function () { | ||
var ownerDocument = ref.current.ownerDocument; | ||
var defaultView = ownerDocument.defaultView; | ||
if (!ref.current) return; | ||
var defaultView = ref.current.ownerDocument.defaultView; | ||
var selection = defaultView.getSelection(); | ||
@@ -45,0 +45,0 @@ |
@@ -10,2 +10,3 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; | ||
*/ | ||
import { useMemo } from '@wordpress/element'; | ||
import { useSelect, useDispatch } from '@wordpress/data'; | ||
@@ -22,15 +23,42 @@ /** | ||
/** | ||
* Set of all interactive content tags. | ||
* | ||
* @see https://html.spec.whatwg.org/multipage/dom.html#interactive-content | ||
*/ | ||
var interactiveContentTags = new Set(['a', 'audio', 'button', 'details', 'embed', 'iframe', 'input', 'label', 'select', 'textarea', 'video']); | ||
/** | ||
* This hook provides RichText with the `formatTypes` and its derived props from | ||
* experimental format type settings. | ||
* | ||
* @param {Object} $0 Options | ||
* @param {string} $0.clientId Block client ID. | ||
* @param {string} $0.identifier Block attribute. | ||
* @param {Object} $0 Options | ||
* @param {string} $0.clientId Block client ID. | ||
* @param {string} $0.identifier Block attribute. | ||
* @param {boolean} $0.withoutInteractiveFormatting Whether to clean the interactive formattings or not. | ||
* @param {Array} $0.allowedFormats Allowed formats | ||
*/ | ||
export function useFormatTypes(_ref) { | ||
var clientId = _ref.clientId, | ||
identifier = _ref.identifier; | ||
var formatTypes = useSelect(formatTypesSelector, []); | ||
identifier = _ref.identifier, | ||
withoutInteractiveFormatting = _ref.withoutInteractiveFormatting, | ||
allowedFormats = _ref.allowedFormats; | ||
var allFormatTypes = useSelect(formatTypesSelector, []); | ||
var formatTypes = useMemo(function () { | ||
return allFormatTypes.filter(function (_ref2) { | ||
var name = _ref2.name, | ||
tagName = _ref2.tagName; | ||
if (allowedFormats && !allowedFormats.includes(name)) { | ||
return false; | ||
} | ||
if (withoutInteractiveFormatting && interactiveContentTags.has(tagName)) { | ||
return false; | ||
} | ||
return true; | ||
}); | ||
}, [allFormatTypes, allowedFormats, interactiveContentTags]); | ||
var keyedSelected = useSelect(function (select) { | ||
@@ -37,0 +65,0 @@ return formatTypes.reduce(function (accumulator, type) { |
@@ -8,3 +8,3 @@ /** | ||
/** | ||
* Wether or not the selected list has the given tag name. | ||
* Whether or not the selected list has the given tag name. | ||
* | ||
@@ -11,0 +11,0 @@ * @param {RichTextValue} value The value to check. |
@@ -23,5 +23,5 @@ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray"; | ||
* attributes. | ||
* @param {boolean} $1.object Wether or not it is an object | ||
* @param {boolean} $1.object Whether or not it is an object | ||
* format. | ||
* @param {boolean} $1.boundaryClass Wether or not to apply a boundary | ||
* @param {boolean} $1.boundaryClass Whether or not to apply a boundary | ||
* class. | ||
@@ -28,0 +28,0 @@ * @return {Object} Information to be used for |
@@ -17,10 +17,2 @@ "use strict"; | ||
*/ | ||
/** | ||
* Set of all interactive content tags. | ||
* | ||
* @see https://html.spec.whatwg.org/multipage/dom.html#interactive-content | ||
*/ | ||
var interactiveContentTags = new Set(['a', 'audio', 'button', 'details', 'embed', 'iframe', 'input', 'label', 'select', 'textarea', 'video']); | ||
function FormatEdit(_ref) { | ||
@@ -31,9 +23,6 @@ var formatTypes = _ref.formatTypes, | ||
value = _ref.value, | ||
allowedFormats = _ref.allowedFormats, | ||
withoutInteractiveFormatting = _ref.withoutInteractiveFormatting, | ||
forwardedRef = _ref.forwardedRef; | ||
return formatTypes.map(function (settings) { | ||
var name = settings.name, | ||
Edit = settings.edit, | ||
tagName = settings.tagName; | ||
Edit = settings.edit; | ||
@@ -44,10 +33,2 @@ if (!Edit) { | ||
if (allowedFormats && allowedFormats.indexOf(name) === -1) { | ||
return null; | ||
} | ||
if (withoutInteractiveFormatting && interactiveContentTags.has(tagName)) { | ||
return null; | ||
} | ||
var activeFormat = (0, _getActiveFormat.getActiveFormat)(value, name); | ||
@@ -54,0 +35,0 @@ var isActive = activeFormat !== undefined; |
@@ -185,3 +185,5 @@ "use strict"; | ||
clientId: clientId, | ||
identifier: identifier | ||
identifier: identifier, | ||
withoutInteractiveFormatting: withoutInteractiveFormatting, | ||
allowedFormats: allowedFormats | ||
}), | ||
@@ -1065,4 +1067,2 @@ formatTypes = _useFormatTypes.formatTypes, | ||
return (0, _element.createElement)(_element.Fragment, null, isSelected && (0, _element.createElement)(_formatEdit.default, { | ||
allowedFormats: allowedFormats, | ||
withoutInteractiveFormatting: withoutInteractiveFormatting, | ||
value: record.current, | ||
@@ -1069,0 +1069,0 @@ onChange: handleChange, |
@@ -56,2 +56,4 @@ "use strict"; | ||
var _useFormatTypes2 = require("./use-format-types"); | ||
var _formatEdit = _interopRequireDefault(require("./format-edit")); | ||
@@ -85,4 +87,2 @@ | ||
var _store = require("../store"); | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
@@ -853,3 +853,2 @@ | ||
parentBlockStyles = _this$props6.parentBlockStyles, | ||
withoutInteractiveFormatting = _this$props6.withoutInteractiveFormatting, | ||
accessibilityLabel = _this$props6.accessibilityLabel, | ||
@@ -986,3 +985,2 @@ _this$props6$disableE = _this$props6.disableEditingMenu, | ||
value: record, | ||
withoutInteractiveFormatting: withoutInteractiveFormatting, | ||
onChange: this.onFormatChange, | ||
@@ -1005,2 +1003,17 @@ onFocus: function onFocus() {} | ||
var withFormatTypes = function withFormatTypes(WrappedComponent) { | ||
return function (props) { | ||
var _useFormatTypes = (0, _useFormatTypes2.useFormatTypes)({ | ||
clientId: props.clientId, | ||
identifier: props.identifier, | ||
withoutInteractiveFormatting: props.withoutInteractiveFormatting | ||
}), | ||
formatTypes = _useFormatTypes.formatTypes; | ||
return (0, _element.createElement)(WrappedComponent, (0, _extends2.default)({}, props, { | ||
formatTypes: formatTypes | ||
})); | ||
}; | ||
}; | ||
var _default = (0, _compose.compose)([(0, _data.withSelect)(function (select, _ref4) { | ||
@@ -1018,3 +1031,2 @@ var clientId = _ref4.clientId; | ||
return _objectSpread({ | ||
formatTypes: select(_store.store).getFormatTypes(), | ||
areMentionsSupported: getSettings('capabilities').mentions === true, | ||
@@ -1025,5 +1037,5 @@ areXPostsSupported: getSettings('capabilities').xposts === true | ||
}); | ||
}), _compose.withPreferredColorScheme])(RichText); | ||
}), _compose.withPreferredColorScheme, withFormatTypes])(RichText); | ||
exports.default = _default; | ||
//# sourceMappingURL=index.native.js.map |
@@ -57,3 +57,3 @@ "use strict"; | ||
onClick: firstOption.onClick, | ||
onLongPress: enablePicker && presentPicker | ||
onLongPress: enablePicker ? presentPicker : undefined | ||
})), enablePicker && (0, _element.createElement)(_components.Picker, { | ||
@@ -60,0 +60,0 @@ ref: picker, |
@@ -50,4 +50,4 @@ "use strict"; | ||
return (0, _element.useMemo)(function () { | ||
var ownerDocument = ref.current.ownerDocument; | ||
var defaultView = ownerDocument.defaultView; | ||
if (!ref.current) return; | ||
var defaultView = ref.current.ownerDocument.defaultView; | ||
var selection = defaultView.getSelection(); | ||
@@ -54,0 +54,0 @@ |
@@ -12,2 +12,4 @@ "use strict"; | ||
var _element = require("@wordpress/element"); | ||
var _data = require("@wordpress/data"); | ||
@@ -25,15 +27,42 @@ | ||
/** | ||
* Set of all interactive content tags. | ||
* | ||
* @see https://html.spec.whatwg.org/multipage/dom.html#interactive-content | ||
*/ | ||
var interactiveContentTags = new Set(['a', 'audio', 'button', 'details', 'embed', 'iframe', 'input', 'label', 'select', 'textarea', 'video']); | ||
/** | ||
* This hook provides RichText with the `formatTypes` and its derived props from | ||
* experimental format type settings. | ||
* | ||
* @param {Object} $0 Options | ||
* @param {string} $0.clientId Block client ID. | ||
* @param {string} $0.identifier Block attribute. | ||
* @param {Object} $0 Options | ||
* @param {string} $0.clientId Block client ID. | ||
* @param {string} $0.identifier Block attribute. | ||
* @param {boolean} $0.withoutInteractiveFormatting Whether to clean the interactive formattings or not. | ||
* @param {Array} $0.allowedFormats Allowed formats | ||
*/ | ||
function useFormatTypes(_ref) { | ||
var clientId = _ref.clientId, | ||
identifier = _ref.identifier; | ||
var formatTypes = (0, _data.useSelect)(formatTypesSelector, []); | ||
identifier = _ref.identifier, | ||
withoutInteractiveFormatting = _ref.withoutInteractiveFormatting, | ||
allowedFormats = _ref.allowedFormats; | ||
var allFormatTypes = (0, _data.useSelect)(formatTypesSelector, []); | ||
var formatTypes = (0, _element.useMemo)(function () { | ||
return allFormatTypes.filter(function (_ref2) { | ||
var name = _ref2.name, | ||
tagName = _ref2.tagName; | ||
if (allowedFormats && !allowedFormats.includes(name)) { | ||
return false; | ||
} | ||
if (withoutInteractiveFormatting && interactiveContentTags.has(tagName)) { | ||
return false; | ||
} | ||
return true; | ||
}); | ||
}, [allFormatTypes, allowedFormats, interactiveContentTags]); | ||
var keyedSelected = (0, _data.useSelect)(function (select) { | ||
@@ -40,0 +69,0 @@ return formatTypes.reduce(function (accumulator, type) { |
@@ -17,3 +17,3 @@ "use strict"; | ||
/** | ||
* Wether or not the selected list has the given tag name. | ||
* Whether or not the selected list has the given tag name. | ||
* | ||
@@ -20,0 +20,0 @@ * @param {RichTextValue} value The value to check. |
@@ -33,5 +33,5 @@ "use strict"; | ||
* attributes. | ||
* @param {boolean} $1.object Wether or not it is an object | ||
* @param {boolean} $1.object Whether or not it is an object | ||
* format. | ||
* @param {boolean} $1.boundaryClass Wether or not to apply a boundary | ||
* @param {boolean} $1.boundaryClass Whether or not to apply a boundary | ||
* class. | ||
@@ -38,0 +38,0 @@ * @return {Object} Information to be used for |
### WordPress - Web publishing software | ||
Copyright 2011-2020 by the contributors | ||
Copyright 2011-2021 by the contributors | ||
@@ -37,3 +37,3 @@ This program is free software; you can redistribute it and/or modify | ||
WordPress is released under the GPL | ||
--- | ||
@@ -45,3 +45,3 @@ | ||
Copyright (C) 1989, 1991 Free Software Foundation, Inc. | ||
Copyright (C) 1989, 1991 Free Software Foundation, Inc. | ||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA | ||
@@ -140,7 +140,7 @@ | ||
**a)** You must cause the modified files to carry prominent notices | ||
stating that you changed the files and the date of any change. | ||
**b)** You must cause any work that you distribute or publish, that in | ||
@@ -151,3 +151,3 @@ whole or in part contains or is derived from the Program or any part | ||
**c)** If the modified program normally reads commands interactively | ||
@@ -189,3 +189,3 @@ when run, you must cause it, when started running for such interactive | ||
**a)** Accompany it with the complete corresponding machine-readable | ||
@@ -195,3 +195,3 @@ source code, which must be distributed under the terms of Sections 1 | ||
**b)** Accompany it with a written offer, valid for at least three | ||
@@ -204,3 +204,3 @@ years, to give any third party, for a charge no more than your cost of | ||
**c)** Accompany it with the information you received as to the offer | ||
@@ -380,3 +380,3 @@ to distribute corresponding source code. (This alternative is allowed | ||
type `show w'. This is free software, and you are welcome | ||
to redistribute it under certain conditions; type `show c' | ||
to redistribute it under certain conditions; type `show c' | ||
for details. | ||
@@ -396,3 +396,3 @@ | ||
interest in the program `Gnomovision' | ||
(which makes passes at compilers) written | ||
(which makes passes at compilers) written | ||
by James Hacker. | ||
@@ -399,0 +399,0 @@ |
{ | ||
"name": "@wordpress/rich-text", | ||
"version": "3.24.1", | ||
"version": "3.24.2-next.0", | ||
"description": "Rich text value and manipulation API.", | ||
@@ -30,10 +30,10 @@ "author": "The WordPress Contributors", | ||
"@babel/runtime": "^7.12.5", | ||
"@wordpress/compose": "^3.23.1", | ||
"@wordpress/data": "^4.26.1", | ||
"@wordpress/deprecated": "^2.11.0", | ||
"@wordpress/dom": "^2.16.0", | ||
"@wordpress/element": "^2.19.0", | ||
"@wordpress/escape-html": "^1.11.0", | ||
"@wordpress/is-shallow-equal": "^3.0.0", | ||
"@wordpress/keycodes": "^2.18.0", | ||
"@wordpress/compose": "^3.24.0-next.0", | ||
"@wordpress/data": "^4.26.2-next.0", | ||
"@wordpress/deprecated": "^2.11.1-next.0", | ||
"@wordpress/dom": "^2.16.1-next.0", | ||
"@wordpress/element": "^2.19.1-next.0", | ||
"@wordpress/escape-html": "^1.11.1-next.0", | ||
"@wordpress/is-shallow-equal": "^3.0.1-next.0", | ||
"@wordpress/keycodes": "^2.18.1-next.0", | ||
"classnames": "^2.2.5", | ||
@@ -47,3 +47,3 @@ "lodash": "^4.17.19", | ||
}, | ||
"gitHead": "defb705bb3e6285f27d29ea4e32a393b3a9b06ca" | ||
"gitHead": "eb424c9ed3dffb9ca4c31d7c81a3be85b0c94a74" | ||
} |
@@ -7,21 +7,2 @@ /** | ||
/** | ||
* Set of all interactive content tags. | ||
* | ||
* @see https://html.spec.whatwg.org/multipage/dom.html#interactive-content | ||
*/ | ||
const interactiveContentTags = new Set( [ | ||
'a', | ||
'audio', | ||
'button', | ||
'details', | ||
'embed', | ||
'iframe', | ||
'input', | ||
'label', | ||
'select', | ||
'textarea', | ||
'video', | ||
] ); | ||
export default function FormatEdit( { | ||
@@ -32,8 +13,6 @@ formatTypes, | ||
value, | ||
allowedFormats, | ||
withoutInteractiveFormatting, | ||
forwardedRef, | ||
} ) { | ||
return formatTypes.map( ( settings ) => { | ||
const { name, edit: Edit, tagName } = settings; | ||
const { name, edit: Edit } = settings; | ||
@@ -44,13 +23,2 @@ if ( ! Edit ) { | ||
if ( allowedFormats && allowedFormats.indexOf( name ) === -1 ) { | ||
return null; | ||
} | ||
if ( | ||
withoutInteractiveFormatting && | ||
interactiveContentTags.has( tagName ) | ||
) { | ||
return null; | ||
} | ||
const activeFormat = getActiveFormat( value, name ); | ||
@@ -57,0 +25,0 @@ const isActive = activeFormat !== undefined; |
@@ -177,2 +177,4 @@ /** | ||
identifier, | ||
withoutInteractiveFormatting, | ||
allowedFormats, | ||
} ); | ||
@@ -1106,6 +1108,2 @@ | ||
<FormatEdit | ||
allowedFormats={ allowedFormats } | ||
withoutInteractiveFormatting={ | ||
withoutInteractiveFormatting | ||
} | ||
value={ record.current } | ||
@@ -1112,0 +1110,0 @@ onChange={ handleChange } |
@@ -35,2 +35,3 @@ /*eslint no-console: ["error", { allow: ["warn"] }] */ | ||
*/ | ||
import { useFormatTypes } from './use-format-types'; | ||
import FormatEdit from './format-edit'; | ||
@@ -50,3 +51,2 @@ import { applyFormat } from '../apply-format'; | ||
import ToolbarButtonWithOptions from './toolbar-button-with-options'; | ||
import { store as richTextStore } from '../store'; | ||
@@ -804,3 +804,2 @@ const unescapeSpaces = ( text ) => { | ||
parentBlockStyles, | ||
withoutInteractiveFormatting, | ||
accessibilityLabel, | ||
@@ -959,5 +958,2 @@ disableEditingMenu = false, | ||
value={ record } | ||
withoutInteractiveFormatting={ | ||
withoutInteractiveFormatting | ||
} | ||
onChange={ this.onFormatChange } | ||
@@ -984,2 +980,12 @@ onFocus={ () => {} } | ||
const withFormatTypes = ( WrappedComponent ) => ( props ) => { | ||
const { formatTypes } = useFormatTypes( { | ||
clientId: props.clientId, | ||
identifier: props.identifier, | ||
withoutInteractiveFormatting: props.withoutInteractiveFormatting, | ||
} ); | ||
return <WrappedComponent { ...props } formatTypes={ formatTypes } />; | ||
}; | ||
export default compose( [ | ||
@@ -996,3 +1002,2 @@ withSelect( ( select, { clientId } ) => { | ||
return { | ||
formatTypes: select( richTextStore ).getFormatTypes(), | ||
areMentionsSupported: | ||
@@ -1005,2 +1010,3 @@ getSettings( 'capabilities' ).mentions === true, | ||
withPreferredColorScheme, | ||
withFormatTypes, | ||
] )( RichText ); |
@@ -46,3 +46,3 @@ /** | ||
onClick={ firstOption.onClick } | ||
onLongPress={ enablePicker && presentPicker } | ||
onLongPress={ enablePicker ? presentPicker : undefined } | ||
/> | ||
@@ -49,0 +49,0 @@ </ToolbarGroup> |
@@ -34,4 +34,6 @@ /** | ||
return useMemo( () => { | ||
const { ownerDocument } = ref.current; | ||
const { defaultView } = ownerDocument; | ||
if ( ! ref.current ) return; | ||
const { | ||
ownerDocument: { defaultView }, | ||
} = ref.current; | ||
const selection = defaultView.getSelection(); | ||
@@ -38,0 +40,0 @@ |
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useMemo } from '@wordpress/element'; | ||
import { useSelect, useDispatch } from '@wordpress/data'; | ||
@@ -15,11 +16,53 @@ /** | ||
/** | ||
* Set of all interactive content tags. | ||
* | ||
* @see https://html.spec.whatwg.org/multipage/dom.html#interactive-content | ||
*/ | ||
const interactiveContentTags = new Set( [ | ||
'a', | ||
'audio', | ||
'button', | ||
'details', | ||
'embed', | ||
'iframe', | ||
'input', | ||
'label', | ||
'select', | ||
'textarea', | ||
'video', | ||
] ); | ||
/** | ||
* This hook provides RichText with the `formatTypes` and its derived props from | ||
* experimental format type settings. | ||
* | ||
* @param {Object} $0 Options | ||
* @param {string} $0.clientId Block client ID. | ||
* @param {string} $0.identifier Block attribute. | ||
* @param {Object} $0 Options | ||
* @param {string} $0.clientId Block client ID. | ||
* @param {string} $0.identifier Block attribute. | ||
* @param {boolean} $0.withoutInteractiveFormatting Whether to clean the interactive formattings or not. | ||
* @param {Array} $0.allowedFormats Allowed formats | ||
*/ | ||
export function useFormatTypes( { clientId, identifier } ) { | ||
const formatTypes = useSelect( formatTypesSelector, [] ); | ||
export function useFormatTypes( { | ||
clientId, | ||
identifier, | ||
withoutInteractiveFormatting, | ||
allowedFormats, | ||
} ) { | ||
const allFormatTypes = useSelect( formatTypesSelector, [] ); | ||
const formatTypes = useMemo( () => { | ||
return allFormatTypes.filter( ( { name, tagName } ) => { | ||
if ( allowedFormats && ! allowedFormats.includes( name ) ) { | ||
return false; | ||
} | ||
if ( | ||
withoutInteractiveFormatting && | ||
interactiveContentTags.has( tagName ) | ||
) { | ||
return false; | ||
} | ||
return true; | ||
} ); | ||
}, [ allFormatTypes, allowedFormats, interactiveContentTags ] ); | ||
const keyedSelected = useSelect( | ||
@@ -26,0 +69,0 @@ ( select ) => |
@@ -10,3 +10,3 @@ /** | ||
/** | ||
* Wether or not the selected list has the given tag name. | ||
* Whether or not the selected list has the given tag name. | ||
* | ||
@@ -13,0 +13,0 @@ * @param {RichTextValue} value The value to check. |
@@ -41,2 +41,3 @@ /** | ||
// eslint-disable-next-line jest/valid-title | ||
it( description, () => { | ||
@@ -70,2 +71,3 @@ const element = createElement( document, html ); | ||
} ) => { | ||
// eslint-disable-next-line jest/valid-title | ||
it( description, () => { | ||
@@ -72,0 +74,0 @@ if ( formatName ) { |
@@ -68,2 +68,3 @@ /** | ||
spec.forEach( ( { format1, format2, isEqual, description } ) => { | ||
// eslint-disable-next-line jest/valid-title | ||
it( description, () => { | ||
@@ -70,0 +71,0 @@ expect( isFormatEqual( format1, format2 ) ).toBe( isEqual ); |
@@ -26,2 +26,3 @@ /** | ||
( { description, multilineTag, record, startPath, endPath } ) => { | ||
// eslint-disable-next-line jest/valid-title | ||
it( description, () => { | ||
@@ -98,2 +99,3 @@ const { body, selection } = toDom( { | ||
cases.forEach( ( { current, future, description, movedCount } ) => { | ||
// eslint-disable-next-line jest/valid-title | ||
it( description, () => { | ||
@@ -100,0 +102,0 @@ const body = createElement( document, current ).cloneNode( true ); |
@@ -45,2 +45,3 @@ /** | ||
// eslint-disable-next-line jest/valid-title | ||
it( description, () => { | ||
@@ -47,0 +48,0 @@ if ( formatName ) { |
@@ -22,5 +22,5 @@ /** | ||
* attributes. | ||
* @param {boolean} $1.object Wether or not it is an object | ||
* @param {boolean} $1.object Whether or not it is an object | ||
* format. | ||
* @param {boolean} $1.boundaryClass Wether or not to apply a boundary | ||
* @param {boolean} $1.boundaryClass Whether or not to apply a boundary | ||
* class. | ||
@@ -27,0 +27,0 @@ * @return {Object} Information to be used for |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1319764
18674
1