UNPKG

@wordpress/block-editor

Version:
8 lines (7 loc) 6.12 kB
{ "version": 3, "sources": ["../../../src/components/block-canvas/index.js"], "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useMergeRefs, useViewportMatch } from '@wordpress/compose';\nimport { useRef } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport BlockList from '../block-list';\nimport BlockTools from '../block-tools';\nimport EditorStyles from '../editor-styles';\nimport Iframe from '../iframe';\nimport WritingFlow from '../writing-flow';\nimport { useMouseMoveTypingReset } from '../observe-typing';\nimport { useBlockSelectionClearer } from '../block-selection-clearer';\nimport { useBlockCommands } from '../use-block-commands';\nimport { store as blockEditorStore } from '../../store';\nimport { unlock } from '../../lock-unlock';\n\n// EditorStyles is a memoized component, so avoid passing a new\n// object reference on each render.\nconst EDITOR_STYLE_TRANSFORM_OPTIONS = {\n\t// Don't transform selectors that already specify `.editor-styles-wrapper`.\n\tignoredSelectors: [ /\\.editor-styles-wrapper/gi ],\n};\n\nexport function ExperimentalBlockCanvas( {\n\tshouldIframe = true,\n\theight = '300px',\n\tchildren = <BlockList />,\n\tstyles,\n\tcontentRef: contentRefProp,\n\tiframeProps,\n} ) {\n\tuseBlockCommands();\n\tconst isTabletViewport = useViewportMatch( 'medium', '<' );\n\tconst resetTypingRef = useMouseMoveTypingReset();\n\tconst clearerRef = useBlockSelectionClearer();\n\tconst localRef = useRef();\n\tconst contentRef = useMergeRefs( [ contentRefProp, clearerRef, localRef ] );\n\tconst zoomLevel = useSelect(\n\t\t( select ) => unlock( select( blockEditorStore ) ).getZoomLevel(),\n\t\t[]\n\t);\n\tconst zoomOutIframeProps =\n\t\tzoomLevel !== 100 && ! isTabletViewport\n\t\t\t? {\n\t\t\t\t\tscale: zoomLevel,\n\t\t\t\t\tframeSize: '40px',\n\t\t\t }\n\t\t\t: {};\n\n\tif ( ! shouldIframe ) {\n\t\treturn (\n\t\t\t<BlockTools\n\t\t\t\t__unstableContentRef={ localRef }\n\t\t\t\tstyle={ { height, display: 'flex' } }\n\t\t\t>\n\t\t\t\t<EditorStyles\n\t\t\t\t\tstyles={ styles }\n\t\t\t\t\tscope=\":where(.editor-styles-wrapper)\"\n\t\t\t\t\ttransformOptions={ EDITOR_STYLE_TRANSFORM_OPTIONS }\n\t\t\t\t/>\n\t\t\t\t<WritingFlow\n\t\t\t\t\tref={ contentRef }\n\t\t\t\t\tclassName=\"editor-styles-wrapper\"\n\t\t\t\t\ttabIndex={ -1 }\n\t\t\t\t\tstyle={ {\n\t\t\t\t\t\theight: '100%',\n\t\t\t\t\t\twidth: '100%',\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t{ children }\n\t\t\t\t</WritingFlow>\n\t\t\t</BlockTools>\n\t\t);\n\t}\n\n\treturn (\n\t\t<BlockTools\n\t\t\t__unstableContentRef={ localRef }\n\t\t\tstyle={ { height, display: 'flex' } }\n\t\t>\n\t\t\t<Iframe\n\t\t\t\t{ ...iframeProps }\n\t\t\t\t{ ...zoomOutIframeProps }\n\t\t\t\tref={ resetTypingRef }\n\t\t\t\tcontentRef={ contentRef }\n\t\t\t\tstyle={ {\n\t\t\t\t\t...iframeProps?.style,\n\t\t\t\t} }\n\t\t\t\tname=\"editor-canvas\"\n\t\t\t>\n\t\t\t\t<EditorStyles styles={ styles } />\n\t\t\t\t{ children }\n\t\t\t</Iframe>\n\t\t</BlockTools>\n\t);\n}\n\n/**\n * BlockCanvas component is a component used to display the canvas of the block editor.\n * What we call the canvas is an iframe containing the block list that you can manipulate.\n * The component is also responsible of wiring up all the necessary hooks to enable\n * the keyboard navigation across blocks in the editor and inject content styles into the iframe.\n *\n * @example\n *\n * ```jsx\n * function MyBlockEditor() {\n * const [ blocks, updateBlocks ] = useState([]);\n * return (\n * <BlockEditorProvider\n * value={ blocks }\n * onInput={ updateBlocks }\n * onChange={ persistBlocks }\n * >\n * <BlockCanvas height=\"400px\" />\n * </BlockEditorProvider>\n * );\n * }\n * ```\n *\n * @param {Object} props Component props.\n * @param {string} props.height Canvas height, defaults to 300px.\n * @param {Array} props.styles Content styles to inject into the iframe.\n * @param {Element} props.children Content of the canvas, defaults to the BlockList component.\n * @return {Element} Block Breadcrumb.\n */\nfunction BlockCanvas( { children, height, styles } ) {\n\treturn (\n\t\t<ExperimentalBlockCanvas height={ height } styles={ styles }>\n\t\t\t{ children }\n\t\t</ExperimentalBlockCanvas>\n\t);\n}\n\nexport default BlockCanvas;\n"], "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA+C;AAC/C,qBAAuB;AACvB,kBAA0B;AAK1B,wBAAsB;AACtB,yBAAuB;AACvB,2BAAyB;AACzB,oBAAmB;AACnB,0BAAwB;AACxB,4BAAwC;AACxC,qCAAyC;AACzC,gCAAiC;AACjC,mBAA0C;AAC1C,yBAAuB;AAYX;AARZ,IAAM,iCAAiC;AAAA;AAAA,EAEtC,kBAAkB,CAAE,2BAA4B;AACjD;AAEO,SAAS,wBAAyB;AAAA,EACxC,eAAe;AAAA,EACf,SAAS;AAAA,EACT,WAAW,4CAAC,kBAAAA,SAAA,EAAU;AAAA,EACtB;AAAA,EACA,YAAY;AAAA,EACZ;AACD,GAAI;AACH,kDAAiB;AACjB,QAAM,uBAAmB,iCAAkB,UAAU,GAAI;AACzD,QAAM,qBAAiB,+CAAwB;AAC/C,QAAM,iBAAa,yDAAyB;AAC5C,QAAM,eAAW,uBAAO;AACxB,QAAM,iBAAa,6BAAc,CAAE,gBAAgB,YAAY,QAAS,CAAE;AAC1E,QAAM,gBAAY;AAAA,IACjB,CAAE,eAAY,2BAAQ,OAAQ,aAAAC,KAAiB,CAAE,EAAE,aAAa;AAAA,IAChE,CAAC;AAAA,EACF;AACA,QAAM,qBACL,cAAc,OAAO,CAAE,mBACpB;AAAA,IACA,OAAO;AAAA,IACP,WAAW;AAAA,EACX,IACA,CAAC;AAEL,MAAK,CAAE,cAAe;AACrB,W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