Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { PanelBody, ToggleControl, withFallbackStyles } from '@wordpress/components';
import { FontSizePicker } from '@wordpress/block-editor';
import { compose } from '@wordpress/compose';
/**
* Internal dependencies
*/
import { FontFamilyPicker } from './';
const { getComputedStyle } = window;
const applyFallbackStyles = withFallbackStyles( ( node, ownProps ) => {
const { fontSize, customFontSize } = ownProps;
const editableNode = node.querySelector( '[contenteditable="true"]' );
const computedStyles = editableNode ? getComputedStyle( editableNode ) : null;
return {
fallbackFontSize: fontSize || customFontSize || ! computedStyles ? undefined : parseInt( computedStyles.fontSize ) || undefined,
};
} );
const TextSettings = ( { children, fontSize, setFontSize, fontFamily, setFontFamily, fitText, setFitText } ) => {
return (
import { RangeControl, withFallbackStyles, ToggleControl, Dropdown, IconButton, SelectControl } from '@wordpress/components';
/**
* Export
*/
export {
TypographyAttributes,
TypograpyClasses,
TypographyTransforms,
};
/**
* Fallback styles
*/
const { getComputedStyle } = window;
const applyFallbackStyles = withFallbackStyles( ( node, ownProps ) => {
const { textColor, fontSize, customFontSize } = ownProps.attributes;
const editableNode = node.querySelector( '[contenteditable="true"]' );
//verify if editableNode is available, before using getComputedStyle.
const computedStyles = editableNode ? getComputedStyle( editableNode ) : null;
return {
fallbackTextColor: textColor || ! computedStyles ? undefined : computedStyles.color,
fallbackFontSize: fontSize || customFontSize || ! computedStyles ? undefined : parseInt( computedStyles.fontSize ) || undefined,
};
} );
/**
* Typography Component
*/
class TypographyControls extends Component {
render() {
const {
import DimensionsControl from '../../components/dimensions-control/';
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { Component, Fragment } from '@wordpress/element';
import { compose } from '@wordpress/compose';
import { InspectorControls, PanelColorSettings } from '@wordpress/block-editor';
import { PanelBody, RangeControl, SelectControl, withFallbackStyles } from '@wordpress/components';
/**
* Fallback styles
*/
const { getComputedStyle } = window;
const applyFallbackStyles = withFallbackStyles( ( node, ownProps ) => {
const { backgroundColor } = ownProps.attributes;
const editableNode = node.querySelector( '[contenteditable="true"]' );
//verify if editableNode is available, before using getComputedStyle.
const computedStyles = editableNode ? getComputedStyle( editableNode ) : null;
return {
fallbackBackgroundColor: backgroundColor || ! computedStyles ? undefined : computedStyles.backgroundColor,
};
} );
/**
* Inspector controls
*/
class Inspector extends Component {
render() {
const {
clientId,
import DimensionsControl from '../../../components/dimensions-control/';
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { Component, Fragment } from '@wordpress/element';
import { compose } from '@wordpress/compose';
import { InspectorControls, PanelColorSettings } from '@wordpress/block-editor';
import { PanelBody, withFallbackStyles } from '@wordpress/components';
/**
* Fallback styles
*/
const { getComputedStyle } = window;
const applyFallbackStyles = withFallbackStyles( ( node, ownProps ) => {
const { backgroundColor } = ownProps.attributes;
const editableNode = node.querySelector( '[contenteditable="true"]' );
//verify if editableNode is available, before using getComputedStyle.
const computedStyles = editableNode ? getComputedStyle( editableNode ) : null;
return {
fallbackBackgroundColor: backgroundColor || ! computedStyles ? undefined : computedStyles.backgroundColor,
};
} );
/**
* Inspector controls
*/
class Inspector extends Component {
render() {
const {
attributes,
BlockControls,
ContrastChecker,
InspectorControls,
PanelColor,
RichText,
} from '@wordpress/editor';
import { createBlock, getPhrasingContentSchema } from '@wordpress/blocks';
/**
* Internal dependencies
*/
import './style.scss';
const { getComputedStyle } = window;
const FallbackStyles = withFallbackStyles( ( node, ownProps ) => {
const { textColor, backgroundColor, fontSize, customFontSize } = ownProps.attributes;
const editableNode = node.querySelector( '[contenteditable="true"]' );
//verify if editableNode is available, before using getComputedStyle.
const computedStyles = editableNode ? getComputedStyle( editableNode ) : null;
return {
fallbackBackgroundColor: backgroundColor || ! computedStyles ? undefined : computedStyles.backgroundColor,
fallbackTextColor: textColor || ! computedStyles ? undefined : computedStyles.color,
fallbackFontSize: fontSize || customFontSize || ! computedStyles ? undefined : parseInt( computedStyles.fontSize ) || undefined,
};
} );
const FONT_SIZES = [
{
name: 'small',
shortName: 'S',
size: 14,
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { Component, Fragment } from '@wordpress/element';
import { compose } from '@wordpress/compose';
import { InspectorControls, PanelColorSettings } from '@wordpress/block-editor';
import { PanelBody, SelectControl, ButtonGroup, Button, Tooltip, withFallbackStyles } from '@wordpress/components';
/**
* Fallback styles
*/
const { getComputedStyle } = window;
const FallbackStyles = withFallbackStyles( ( node, ownProps ) => {
const { backgroundColor } = ownProps.attributes;
const editableNode = node.querySelector( '[contenteditable="true"]' );
//verify if editableNode is available, before using getComputedStyle.
const computedStyles = editableNode ? getComputedStyle( editableNode ) : null;
return {
fallbackBackgroundColor: backgroundColor || ! computedStyles ? undefined : computedStyles.backgroundColor,
};
} );
/**
* Inspector controls
*/
class Inspector extends Component {
Dashicon,
IconButton,
withFallbackStyles,
} from '@wordpress/components';
import {
URLInput,
RichText,
ContrastChecker,
InspectorControls,
withColors,
PanelColorSettings,
} from '@wordpress/block-editor';
const { getComputedStyle } = window;
const applyFallbackStyles = withFallbackStyles( ( node, ownProps ) => {
const { textColor, backgroundColor } = ownProps;
const backgroundColorValue = backgroundColor && backgroundColor.color;
const textColorValue = textColor && textColor.color;
//avoid the use of querySelector if textColor color is known and verify if node is available.
const textNode = ! textColorValue && node ? node.querySelector( '[contenteditable="true"]' ) : null;
return {
fallbackBackgroundColor: backgroundColorValue || ! node ? undefined : getComputedStyle( node ).backgroundColor,
fallbackTextColor: textColorValue || ! textNode ? undefined : getComputedStyle( textNode ).color,
};
} );
class ButtonEdit extends Component {
constructor() {
super( ...arguments );
this.nodeRef = null;
this.bindRef = this.bindRef.bind( this );
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { Component, Fragment } from '@wordpress/element';
import { compose } from '@wordpress/compose';
import { InspectorControls, ContrastChecker, PanelColorSettings, FontSizePicker, withFontSizes } from '@wordpress/block-editor';
import { PanelBody, withFallbackStyles } from '@wordpress/components';
/**
* Contrast checker
*/
const { getComputedStyle } = window;
const applyFallbackStyles = withFallbackStyles( ( node, ownProps ) => {
const { textColor, buttonColor, fontSize, customFontSize } = ownProps.attributes;
const editableNode = node.querySelector( '[contenteditable="true"]' );
//verify if editableNode is available, before using getComputedStyle.
const computedStyles = editableNode ? getComputedStyle( editableNode ) : null;
return {
fallbackButtonColor: buttonColor || ! computedStyles ? undefined : computedStyles.buttonColor,
fallbackTextColor: textColor || ! computedStyles ? undefined : computedStyles.color,
fallbackFontSize: fontSize || customFontSize || ! computedStyles ? undefined : parseInt( computedStyles.fontSize ) || undefined,
};
} );
/**
* Inspector controls
*/
class Inspector extends Component {
render() {
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { Component, Fragment } from '@wordpress/element';
import { compose } from '@wordpress/compose';
import { InspectorControls, PanelColorSettings } from '@wordpress/block-editor';
import { PanelBody, RangeControl, withFallbackStyles } from '@wordpress/components';
/**
* Fallback styles
*/
const { getComputedStyle } = window;
const FallbackStyles = withFallbackStyles( ( node, ownProps ) => {
const { backgroundColor } = ownProps.attributes;
const editableNode = node.querySelector( '[contenteditable="true"]' );
//verify if editableNode is available, before using getComputedStyle.
const computedStyles = editableNode ? getComputedStyle( editableNode ) : null;
return {
fallbackBackgroundColor: backgroundColor || ! computedStyles ? undefined : computedStyles.backgroundColor,
};
} );
/**
* Inspector controls
*/
class Inspector extends Component {
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { Component, Fragment } from '@wordpress/element';
import { compose } from '@wordpress/compose';
import { withFallbackStyles } from '@wordpress/components';
import { InspectorControls,
PanelColorSettings,
ContrastChecker,
RichText,
withColors,
} from '@wordpress/block-editor';
const { getComputedStyle } = window;
const applyFallbackStyles = withFallbackStyles( ( node, ownProps ) => {
const { textButtonColor, backgroundButtonColor } = ownProps;
const backgroundColorValue = backgroundButtonColor && backgroundButtonColor.color;
const textColorValue = textButtonColor && textButtonColor.color;
//avoid the use of querySelector if textColor color is known and verify if node is available.
let textNode;
let button;
if ( ! textColorValue && node ) {
textNode = node.querySelector( '[contenteditable="true"]' );
}
if ( node.querySelector( '.wp-block-button__link' ) ) {
button = node.querySelector( '.wp-block-button__link' );
} else {
button = node;