Generic block editor.
npm install @gechiui/block-editorThis module allows you to create and use standalone block editors.
Install the module
``bash`
npm install @gechiui/block-editor --save
_This package assumes that your code will run in an ES2015+ environment. If you're using an environment that has limited or no support for such language features and APIs, you should include the polyfill shipped in @gechiui/babel-preset-default in your code._
`js
import {
BlockEditorProvider,
BlockList,
BlockTools,
WritingFlow,
ObserveTyping,
} from '@gechiui/block-editor';
import { SlotFillProvider, Popover } from '@gechiui/components';
import { useState } from '@gechiui/element';
function MyEditorComponent() {
const [ blocks, updateBlocks ] = useState( [] );
return (
onInput={ ( blocks ) => updateBlocks( blocks ) }
onChange={ ( blocks ) => updateBlocks( blocks ) }
>
);
}
// Make sure to load the block editor stylesheets too
// import '@gechiui/components/build-style/style.css';
// import '@gechiui/block-editor/build-style/style.css';
`
In this example, we're instantiating a block editor. A block editor is composed by a BlockEditorProvider wrapper component where you pass the current array of blocks and on each change the onInput or onChange callbacks are called depending on whether the change is considered persistent or not.
Inside BlockEditorProvider, you can nest any of the available @gechiui/block-editor UI components to build the UI of your editor.
In the example above we're rendering the BlockList to show and edit the block list. For instance we could add a custom sidebar and use the BlockInspector component to be able to edit the advanced settings for the currently selected block. (See the API for the list of all the available components).
The BlockTools component is used to render the toolbar for a selected block.
In the example above, there's no registered block type, in order to use the block editor successfully make sure to register some block types. For instance, registering the core block types can be done like so:
`js
import { registerCoreBlocks } from '@gechiui/block-library';
registerCoreBlocks();
// Make sure to load the block stylesheets too
// import '@gechiui/block-library/build-style/style.css';
// import '@gechiui/block-library/build-style/editor.css';
// import '@gechiui/block-library/build-style/theme.css';
`
Undocumented declaration.
Undocumented declaration.
_Related_
-
Undocumented declaration.
Undocumented declaration.
Block breadcrumb component, displaying the hierarchy of the current block selection as a breadcrumb.
_Parameters_
- _props_ Object: Component props.string
- _props.rootLabelText_ : Translated label for the root element of the breadcrumb trail.
_Returns_
- GCElement: Block Breadcrumb.
Undocumented declaration.
Component which merges passed value with current consumed block context.
_Related_
-
_Parameters_
- _props_ BlockContextProviderProps:
Undocumented declaration.
Undocumented declaration.
Undocumented declaration.
Undocumented declaration.
Undocumented declaration.
Undocumented declaration.
Undocumented declaration.
Undocumented declaration.
Undocumented declaration.
Undocumented declaration.
BlockPreview renders a preview of a block or array of blocks.
_Related_
-
_Parameters_
- _preview_ Object: options for how the preview should be shownArray|Object
- _preview.blocks_ : A block instance (object) or an array of blocks to be previewed.number
- _preview.viewportWidth_ : Width of the preview container in pixels. Controls at what size the blocks will be rendered inside the preview. Default: 700.
_Returns_
- GCComponent: The component to be rendered.
Undocumented declaration.
Undocumented declaration.
_Related_
-
_Parameters_
- _props_ Object: Fill props.
_Returns_
- GCElement: Element.
Renders the block's configured title as a string, or empty if the title
cannot be determined.
_Usage_
`jsx`
_Parameters_
- _props_ Object:string
- _props.clientId_ : Client ID of block.
_Returns_
- ?string: Block title.
Undocumented declaration.
Renders block tools (the block toolbar, select/navigation mode toolbar, the
insertion point and a slot for the inline rich text toolbar). Must be wrapped
around the block content and editor styles wrapper or iframe.
_Parameters_
- _$0_ Object: Props.Object
- _$0.children_ : The block content and style container.Object
- _$0.\_\_unstableContentRef_ : Ref holding the content scroll container.
Undocumented declaration.
Undocumented declaration.
_Related_
-
> Deprecated
Use ButtonBlockAppender instead.
Undocumented declaration.
Undocumented declaration.
Undocumented declaration.
Undocumented declaration.
A higher-order component factory for creating a 'withCustomColors' HOC, which handles color logic
for class generation color value, retrieval and color attribute setting.
Use this higher-order component to work with a custom set of colors.
_Usage_
`jsx`
const CUSTOM_COLORS = [
{ name: 'Red', slug: 'red', color: '#ff0000' },
{ name: 'Blue', slug: 'blue', color: '#0000ff' },
];
const withCustomColors = createCustomColorsHOC( CUSTOM_COLORS );
// ...
export default compose(
withCustomColors( 'backgroundColor', 'borderColor' ),
MyColorfulComponent
);
_Parameters_
- _colorsArray_ Array: The array of color objects (name, slug, color, etc... ).
_Returns_
- Function: Higher-order component.
Undocumented declaration.
Undocumented declaration.
Returns a class based on the context a color is being used and its slug.
_Parameters_
- _colorContextName_ string: Context/place where color is being used e.g: background, text etc...string
- _colorSlug_ : Slug of the color.
_Returns_
- ?string: String with the class corresponding to the color in the provided context. Returns undefined if either colorContextName or colorSlug are not provided.
Provided an array of color objects as set by the theme or by the editor defaults,
and the values of the defined color or custom color returns a color object describing the color.
_Parameters_
- _colors_ Array: Array of color objects as set by the theme or by the editor defaults.?string
- _definedColor_ : A string containing the color slug.?string
- _customColor_ : A string containing the customColor value.
_Returns_
- ?Object: If definedColor is passed and the name is found in colors, the color object exactly as set by the theme or editor defaults is returned. Otherwise, an object that just sets the color is defined.
Provided an array of color objects as set by the theme or by the editor defaults, and a color value returns the color object matching that value or undefined.
_Parameters_
- _colors_ Array: Array of color objects as set by the theme or by the editor defaults.?string
- _colorValue_ : A string containing the color value.
_Returns_
- ?Object: Color object included in the colors array whose color property equals colorValue. Returns undefined if no color object matches this requirement.
Returns the font size object based on an array of named font sizes and the namedFontSize and customFontSize values.
If namedFontSize is undefined or not found in fontSizes an object with just the size value based on customFontSize is returned.
_Parameters_
- _fontSizes_ Array: Array of font size objects containing at least the "name" and "size" values as properties.?string
- _fontSizeAttribute_ : Content of the font size attribute (slug).?number
- _customFontSizeAttribute_ : Contents of the custom font size attribute (value).
_Returns_
- ?Object: If fontSizeAttribute is set and an equal slug is found in fontSizes it returns the font size object for that slug. Otherwise, an object with just the size value based on customFontSize is returned.
Returns a class based on fontSizeName.
_Parameters_
- _fontSizeSlug_ string: Slug of the fontSize.
_Returns_
- string: String with the class corresponding to the fontSize passed. The class is generated by appending 'has-' followed by fontSizeSlug in kebabCase and ending with '-font-size'.
Returns the corresponding font size object for a given value.
_Parameters_
- _fontSizes_ Array: Array of font size objects.number
- _value_ : Font size value.
_Returns_
- Object: Font size object.
Retrieves the gradient slug per slug.
_Parameters_
- _gradients_ Array: Gradient Palettestring
- _value_ : Gradient value
_Returns_
- string: Gradient slug.
Retrieves the gradient value per slug.
_Parameters_
- _gradients_ Array: Gradient Palettestring
- _slug_ : Gradient slug
_Returns_
- string: Gradient value.
Returns the px value of a cssUnit. The memoized version of getPxFromCssUnit;
_Parameters_
- _cssUnit_ string:Object
- _options_ :
_Returns_
- string: returns the cssUnit value in a simple px format.
_Related_
-
Undocumented declaration.
Undocumented declaration.
_Related_
-
Undocumented declaration.
Undocumented declaration.
Undocumented declaration.
_Related_
-
Undocumented declaration.
_Related_
-
_Related_
-
> Deprecated
Scrolls the multi block selection end into view if not in view already. This
is important to do after selection by keyboard.
Undocumented declaration.
_Related_
-
Undocumented declaration.
_Related_
-
Undocumented declaration.
_Related_
-
Undocumented declaration.
Undocumented declaration.
The default editor settings
_Type Definition_
- _SETTINGS_DEFAULT_ Object
_Properties_
- _alignWide_ boolean: Enable/Disable Wide/Full Alignmentsboolean
- _supportsLayout_ : Enable/disable layouts support in container blocks.boolean
- _imageEditing_ : Image Editing settings set to false to disable.Array
- _imageSizes_ : Available image sizesnumber
- _maxWidth_ : Max width to constraint resizingboolean|Array
- _allowedBlockTypes_ : Allowed block typesboolean
- _hasFixedToolbar_ : Whether or not the editor toolbar is fixedboolean
- _focusMode_ : Whether the focus mode is enabled or notArray
- _styles_ : Editor Stylesboolean
- _keepCaretInsideBlock_ : Whether caret should move between blocks in edit modestring
- _bodyPlaceholder_ : Empty post placeholderstring
- _titlePlaceholder_ : Empty title placeholderboolean
- _codeEditingEnabled_ : Whether or not the user can switch to the code editorboolean
- _\_\_experimentalCanUserUseUnfilteredHTML_ : Whether the user should be able to use unfiltered HTML or the HTML should be filtered e.g., to remove elements considered insecure like iframes.boolean
- _\_\_experimentalBlockDirectory_ : Whether the user has enabled the Block DirectoryArray
- _\_\_experimentalBlockPatterns_ : Array of objects representing the block patternsArray
- _\_\_experimentalBlockPatternCategories_ : Array of objects representing the block pattern categoriesboolean
- _\_\_unstableGalleryWithImageBlocks_ : Whether the user has enabled the refactored gallery block which uses InnerBlocks
Undocumented declaration.
Store definition for the block editor namespace.
_Related_
-
_Type_
- Object
Block editor data store configuration.
_Related_
-
_Type_
- Object
Undocumented declaration.
Applies a series of CSS rule transforms to wrap selectors inside a given class and/or rewrite URLs depending on the parameters passed.
_Parameters_
- _styles_ Array: CSS rules.string
- _wrapperClassName_ : Wrapper Class Name.
_Returns_
- Array: converted rules.
Ensures that the text selection keeps the same vertical distance from the
viewport during keyboard events within this component. The vertical distance
can vary. It is the last clicked or scrolled to position.
_Related_
-
_Related_
-
_Related_
-
Hook used to try to find a matching block variation and return
the appropriate information for display reasons. In order to
to try to find a match we need to things:
1\. Block's client id to extract it's current attributes.
2\. A block variation should have set isActive prop to a proper function.
If for any reason a block variaton match cannot be found,
the returned information come from the Block Type.
If no blockType is found with the provided clientId, returns null.
_Parameters_
- _clientId_ string: Block's client id.
_Returns_
- ?GCBlockDisplayInformation: Block's display information, or null when the block or its type not found.
Undocumented declaration.
This hook is used to lightly mark an element as a block element. The element
should be the outermost element of a block. Call this hook and pass the
returned props to the element to mark as a block. If you define a ref for the
element, it is important to pass the ref to this hook, which the hook in turn
will pass to the component through the props it returns. Optionally, you can
also pass any other props through this hook, and they will be merged and
returned.
_Parameters_
- _props_ Object: Optional. Props to pass to the element. Must contain the ref if one is defined.Object
- _options_ : Options for internal use only.boolean
- _options.\_\_unstableIsHtml_ :
_Returns_
- Object: Props to pass to the element to mark as a block.
Keeps an up-to-date copy of the passed value and returns it. If value becomes falsy, it will return the last truthy copy.
_Parameters_
- _value_ any:
_Returns_
- any: value
This hook is used to lightly mark an element as an inner blocks wrapper
element. Call this hook and pass the returned props to the element to mark as
an inner blocks wrapper, automatically rendering inner blocks as children. If
you define a ref for the element, it is important to pass the ref to this
hook, which the hook in turn will pass to the component through the props it
returns. Optionally, you can also pass any other props through this hook, and
they will be merged and returned.
_Related_
-
_Parameters_
- _props_ Object: Optional. Props to pass to the element. Must contain the ref if one is defined.Object
- _options_ : Optional. Inner blocks options.
Hook that retrieves the editor setting.
It works with nested objects using by finding the value at path.
_Usage_
`js`
const isEnabled = useSetting( 'typography.dropCap' );
_Parameters_
- _path_ string: The path to the setting.
_Returns_
- any: Returns the value defined for the setting.
Given an array of theme colors checks colors for validity
_Parameters_
- _colors_ Array: The array of theme colors
_Returns_
- Array: The array of valid theme colors or the default colors
Given an array of theme gradients checks gradients for validity
_Parameters_
- _gradients_ Array: The array of theme gradients
_Returns_
- Array: The array of valid theme gradients or the default gradients
_Related_
-
Undocumented declaration.
A higher-order component, which handles color logic for class generation color value, retrieval and color attribute setting.
For use with the default editor/theme color palette.
_Usage_
`jsx`
export default compose(
withColors( 'backgroundColor', { textColor: 'color' } ),
MyColorfulComponent
);
_Parameters_
- _colorTypes_ ...(Object|string): The arguments can be strings or objects. If the argument is an object, it should contain the color attribute name as key and the color context as value. If the argument is a string the value should be the color attribute name, the color context is computed by applying a kebab case transform to the value. Color context represents the context/place where the color is going to be used. The class name of the color is generated using 'has' followed by the color name and ending with the color context all in kebab case e.g: has-green-background-color.
_Returns_
- Function: Higher-order component.
Higher-order component, which handles font size logic for class generation,
font size value retrieval, and font size change handling.
_Parameters_
- _fontSizeNames_ ...(Object|string): The arguments should all be strings. Each string contains the font size attribute name e.g: 'fontSize'.
_Returns_
- Function: Higher-order component.
Handles selection and navigation across blocks. This component should be
wrapped around BlockList.
_Parameters_
- _props_ Object: Component properties.GCElement`: Children to be rendered.
- _props.children_
