我试图创建一个块,我想使用InspectorControl,但我无法让它工作。我知道它的反对意见/改为wp。组件。*(https://developer.wordpress.org/block-editor/developers/backward-compatibility/deprecations/)
但如果是那样使用它,它仍然不起作用。我尝试了以下方法:
InspectorControls = wp.editor;
InspectorControls = wp.editor.InspectorControls;
InspectorControls = wp.blocks;
InspectorControls = wp.blocks.InspectorControls;
InspectorControls = wp.components;
InspectorControls = wp.components.InspectorControls;
这是我的代码:
let el = wp.element.createElement,
registerBlockType = wp.blocks.registerBlockType,
ServerSideRender = wp.components.ServerSideRender,
TextControl = wp.components.TextControl,
TextareaControl = wp.components.TextareaControl,
InspectorControls = wp.editor;
registerBlockType( \'mir-shortcodes-plugin/msc-rotating-icon-circle\', {
title: \'Rotating icon circle\',
category: \'msc-shortcodes\',
attributes: {
\'icon\': {
type: \'string\',
default: "arrows-alt"
},
\'icon_style\': {
type: \'string\',
default: "fas"
}
},
edit: (props) => {
if(props.isSelected){
// do something...
//console.debug(props.attributes);
};
return [
/**
* Server side render
*/
el("div", {
className: "mb-editor-container",
style: {textAlign: "center"}
},
el( ServerSideRender, {
block: \'mir-shortcodes-plugin/msc-rotating-icon-circle\',
attributes: props.attributes
} )
),
/**
* Inspector
*/
el( InspectorControls,
{}, [
el( "hr", {
style: {marginTop:20}
}),
el( TextControl, {
label: \'Icon\',
value: props.attributes.icon,
onChange: ( value ) => {
props.setAttributes( { icon: value } );
}
} ),
el( TextControl, {
label: \'Icon color\',
value: props.attributes.icon_color,
onChange: ( value ) => {
props.setAttributes( { icon_color: value } );
}
} ),
]
)
]
},
save: () => {
/** this is resolved server side */
return null
}
} );
错误日志:
[Error] Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it\'s defined in, or you might have mixed up default and named imports.
Check the render method of `edit`.
in edit (created by Edit)
in Edit (created by WithToolbarControls(Edit))
in WithToolbarControls(Edit) (created by WithInspectorControl(WithToolbarControls(Edit)))
in WithInspectorControl(WithToolbarControls(Edit)) (created by WithInspectorControl(WithInspectorControl(WithToolbarControls(Edit))))
in WithInspectorControl(WithInspectorControl(WithToolbarControls(Edit)))
in Unknown (created by ComponentWithDispatch)
in ComponentWithDispatch (created by Context.Consumer)
in WithDispatch(Component) (created by ComponentWithSelect)
in ComponentWithSelect (created by Context.Consumer)
in WithMultipleValidation(WithInspectorControl(WithInspectorControl(WithToolbarControls(Edit)))) (created by WithFilters(Edit))
in WithFilters(Edit) (created by BlockEdit)
in BlockEdit (created by HoverArea)
in BlockCrashBoundary (created by HoverArea)
in div (created by IgnoreNestedEvents)
in IgnoreNestedEvents (created by ForwardRef(IgnoreNestedEvents))
in ForwardRef(IgnoreNestedEvents) (created by HoverArea)
in div (created by HoverArea)
in div (created by IgnoreNestedEvents)
in IgnoreNestedEvents (created by ForwardRef(IgnoreNestedEvents))
in ForwardRef(IgnoreNestedEvents) (created by HoverArea)
in HoverArea (created by ComponentWithSelect)
in ComponentWithSelect (created by Context.Consumer)
in WithSelect(HoverArea) (created by BlockListBlock)
in BlockListBlock
in Unknown (created by ComponentWithSelect)
in ComponentWithSelect (created by Context.Consumer)
in (BlockListBlock) (created by WithFilters(BlockListBlock))
in WithFilters(BlockListBlock) (created by ComponentWithDispatch)
in ComponentWithDispatch (created by Context.Consumer)
in WithDispatch(WithFilters(BlockListBlock)) (created by ComponentWithSelect)
in ComponentWithSelect (created by Context.Consumer)
in WithSelect(WithDispatch(WithFilters(BlockListBlock))) (created by ComponentWithSelect)
in ComponentWithSelect (created by Context.Consumer)
in WithViewportMatch(WithSelect(WithDispatch(WithFilters(BlockListBlock)))) (created by Pure(WithViewportMatch(WithSelect(WithDispatch(WithFilters(BlockListBlock))))))
in Pure(WithViewportMatch(WithSelect(WithDispatch(WithFilters(BlockListBlock))))) (created by BlockList)
in div (created by BlockList)
in BlockList (created by ComponentWithDispatch)
in ComponentWithDispatch (created by Context.Consumer)
in WithDispatch(BlockList) (created by ComponentWithSelect)
in ComponentWithSelect (created by Context.Consumer)
in WithSelect(WithDispatch(BlockList))
in Unknown (created by VisualEditor)
in div (created by CopyHandler)
in CopyHandler (created by ComponentWithDispatch)
in ComponentWithDispatch (created by Context.Consumer)
in WithDispatch(CopyHandler) (created by VisualEditor)
in div (created by ObserveTyping)
in ObserveTyping (created by WithSafeTimeout(ObserveTyping))
in WithSafeTimeout(ObserveTyping) (created by ComponentWithDispatch)
in ComponentWithDispatch (created by Context.Consumer)
in WithDispatch(WithSafeTimeout(ObserveTyping)) (created by ComponentWithSelect)
in ComponentWithSelect (created by Context.Consumer)
in WithSelect(WithDispatch(WithSafeTimeout(ObserveTyping))) (created by VisualEditor)
in div (created by WritingFlow)
in div (created by WritingFlow)
in WritingFlow (created by ComponentWithDispatch)
in ComponentWithDispatch (created by Context.Consumer)
in WithDispatch(WritingFlow) (created by ComponentWithSelect)
in ComponentWithSelect (created by Context.Consumer)
in WithSelect(WithDispatch(WritingFlow)) (created by VisualEditor)
in div (created by BlockSelectionClearer)
in BlockSelectionClearer (created by ComponentWithDispatch)
in ComponentWithDispatch (created by Context.Consumer)
in WithDispatch(BlockSelectionClearer) (created by ComponentWithSelect)
in ComponentWithSelect (created by Context.Consumer)
in WithSelect(WithDispatch(BlockSelectionClearer)) (created by VisualEditor)
in VisualEditor (created by Layout)
in div (created by Layout)
in div (created by FocusReturnProvider)
in FocusReturnProvider (created by Layout)
in Layout (created by ComponentWithSelect)
in ComponentWithSelect (created by Context.Consumer)
in WithViewportMatch(Layout) (created by NavigateRegions(WithViewportMatch(Layout)))
in div (created by NavigateRegions(WithViewportMatch(Layout)))
in NavigateRegions(WithViewportMatch(Layout)) (created by ComponentWithDispatch)
in ComponentWithDispatch (created by Context.Consumer)
in WithDispatch(NavigateRegions(WithViewportMatch(Layout))) (created by ComponentWithSelect)
in ComponentWithSelect (created by Context.Consumer)
in WithSelect(WithDispatch(NavigateRegions(WithViewportMatch(Layout)))) (created by Editor)
in ErrorBoundary (created by Editor)
in div (created by DropZoneProvider)
in DropZoneProvider (created by BlockEditorProvider)
in SlotFillProvider (created by BlockEditorProvider)
in BlockEditorProvider (created by Context.Consumer)
in WithRegistry(BlockEditorProvider) (created by ComponentWithDispatch)
in ComponentWithDispatch (created by Context.Consumer)
in WithDispatch(WithRegistry(BlockEditorProvider)) (created by EditorProvider)
in EditorProvider (created by ComponentWithDispatch)
in ComponentWithDispatch (created by Context.Consumer)
in WithDispatch(EditorProvider) (created by ComponentWithSelect)
in ComponentWithSelect (created by Context.Consumer)
in WithSelect(WithDispatch(EditorProvider)) (created by Editor)
in StrictMode (created by Editor)
in Editor (created by ComponentWithSelect)
in ComponentWithSelect (created by Context.Consumer)
in WithSelect(Editor)
warningWithoutStack (react.js:276)
warning (react.js:1791)
createElementWithValidation (react.js:3023)
edit (index.js:74)
renderWithHooks (react-dom.js:13027)
mountIndeterminateComponent (react-dom.js:15109)
performUnitOfWork (react-dom.js:19401)
workLoop (react-dom.js:19441)
renderRoot (react-dom.js:19524)
performWorkOnRoot (react-dom.js:20431)
performWork (react-dom.js:20343)
performSyncWork (react-dom.js:20317)
interactiveUpdates$1 (react-dom.js:20584)
dispatchInteractiveEvent (react-dom.js:4985)
dispatchInteractiveEvent
[Error] Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it\'s defined in, or you might have mixed up default and named imports.
Check the render method of `edit`.
in edit (created by Edit)
in Edit (created by WithToolbarControls(Edit))
in WithToolbarControls(Edit) (created by WithInspectorControl(WithToolbarControls(Edit)))
in WithInspectorControl(WithToolbarControls(Edit)) (created by WithInspectorControl(WithInspectorControl(WithToolbarControls(Edit))))
in WithInspectorControl(WithInspectorControl(WithToolbarControls(Edit)))
in Unknown (created by ComponentWithDispatch)
in ComponentWithDispatch (created by Context.Consumer)
in WithDispatch(Component) (created by ComponentWithSelect)
in ComponentWithSelect (created by Context.Consumer)
in WithMultipleValidation(WithInspectorControl(WithInspectorControl(WithToolbarControls(Edit)))) (created by WithFilters(Edit))
in WithFilters(Edit) (created by BlockEdit)
in BlockEdit (created by HoverArea)
in BlockCrashBoundary (created by HoverArea)
in div (created by IgnoreNestedEvents)
in IgnoreNestedEvents (created by ForwardRef(IgnoreNestedEvents))
in ForwardRef(IgnoreNestedEvents) (created by HoverArea)
in div (created by HoverArea)
in div (created by IgnoreNestedEvents)
in IgnoreNestedEvents (created by ForwardRef(IgnoreNestedEvents))
in ForwardRef(IgnoreNestedEvents) (created by HoverArea)
in HoverArea (created by ComponentWithSelect)
in ComponentWithSelect (created by Context.Consumer)
in WithSelect(HoverArea) (created by BlockListBlock)
in BlockListBlock
in Unknown (created by ComponentWithSelect)
in ComponentWithSelect (created by Context.Consumer)
in (BlockListBlock) (created by WithFilters(BlockListBlock))
in WithFilters(BlockListBlock) (created by ComponentWithDispatch)
in ComponentWithDispatch (created by Context.Consumer)
in WithDispatch(WithFilters(BlockListBlock)) (created by ComponentWithSelect)
in ComponentWithSelect (created by Context.Consumer)
in WithSelect(WithDispatch(WithFilters(BlockListBlock))) (created by ComponentWithSelect)
in ComponentWithSelect (created by Context.Consumer)
in WithViewportMatch(WithSelect(WithDispatch(WithFilters(BlockListBlock)))) (created by Pure(WithViewportMatch(WithSelect(WithDispatch(WithFilters(BlockListBlock))))))
in Pure(WithViewportMatch(WithSelect(WithDispatch(WithFilters(BlockListBlock))))) (created by BlockList)
in div (created by BlockList)
in BlockList (created by ComponentWithDispatch)
in ComponentWithDispatch (created by Context.Consumer)
in WithDispatch(BlockList) (created by ComponentWithSelect)
in ComponentWithSelect (created by Context.Consumer)
in WithSelect(WithDispatch(BlockList))
in Unknown (created by VisualEditor)
in div (created by CopyHandler)
in CopyHandler (created by ComponentWithDispatch)
in ComponentWithDispatch (created by Context.Consumer)
in WithDispatch(CopyHandler) (created by VisualEditor)
in div (created by ObserveTyping)
in ObserveTyping (created by WithSafeTimeout(ObserveTyping))
in WithSafeTimeout(ObserveTyping) (created by ComponentWithDispatch)
in ComponentWithDispatch (created by Context.Consumer)
in WithDispatch(WithSafeTimeout(ObserveTyping)) (created by ComponentWithSelect)
in ComponentWithSelect (created by Context.Consumer)
in WithSelect(WithDispatch(WithSafeTimeout(ObserveTyping))) (created by VisualEditor)
in div (created by WritingFlow)
in div (created by WritingFlow)
in WritingFlow (created by ComponentWithDispatch)
in ComponentWithDispatch (created by Context.Consumer)
in WithDispatch(WritingFlow) (created by ComponentWithSelect)
in ComponentWithSelect (created by Context.Consumer)
in WithSelect(WithDispatch(WritingFlow)) (created by VisualEditor)
in div (created by BlockSelectionClearer)
in BlockSelectionClearer (created by ComponentWithDispatch)
in ComponentWithDispatch (created by Context.Consumer)
in WithDispatch(BlockSelectionClearer) (created by ComponentWithSelect)
in ComponentWithSelect (created by Context.Consumer)
in WithSelect(WithDispatch(BlockSelectionClearer)) (created by VisualEditor)
in VisualEditor (created by Layout)
in div (created by Layout)
in div (created by FocusReturnProvider)
in FocusReturnProvider (created by Layout)
in Layout (created by ComponentWithSelect)
in ComponentWithSelect (created by Context.Consumer)
in WithViewportMatch(Layout) (created by NavigateRegions(WithViewportMatch(Layout)))
in div (created by NavigateRegions(WithViewportMatch(Layout)))
in NavigateRegions(WithViewportMatch(Layout)) (created by ComponentWithDispatch)
in ComponentWithDispatch (created by Context.Consumer)
in WithDispatch(NavigateRegions(WithViewportMatch(Layout))) (created by ComponentWithSelect)
in ComponentWithSelect (created by Context.Consumer)
in WithSelect(WithDispatch(NavigateRegions(WithViewportMatch(Layout)))) (created by Editor)
in ErrorBoundary (created by Editor)
in div (created by DropZoneProvider)
in DropZoneProvider (created by BlockEditorProvider)
in SlotFillProvider (created by BlockEditorProvider)
in BlockEditorProvider (created by Context.Consumer)
in WithRegistry(BlockEditorProvider) (created by ComponentWithDispatch)
in ComponentWithDispatch (created by Context.Consumer)
in WithDispatch(WithRegistry(BlockEditorProvider)) (created by EditorProvider)
in EditorProvider (created by ComponentWithDispatch)
in ComponentWithDispatch (created by Context.Consumer)
in WithDispatch(EditorProvider) (created by ComponentWithSelect)
in ComponentWithSelect (created by Context.Consumer)
in WithSelect(WithDispatch(EditorProvider)) (created by Editor)
in StrictMode (created by Editor)
in Editor (created by ComponentWithSelect)
in ComponentWithSelect (created by Context.Consumer)
in WithSelect(Editor)
warningWithoutStack (react.js:276)
warning (react.js:1791)
createElementWithValidation (react.js:3023)
edit (index.js:74)
renderWithHooks (react-dom.js:13027)
mountIndeterminateComponent (react-dom.js:15109)
performUnitOfWork (react-dom.js:19401)
workLoop (react-dom.js:19441)
callCallback (react-dom.js:143)
dispatchEvent
invokeGuardedCallbackDev (react-dom.js:193)
invokeGuardedCallback (react-dom.js:250)
replayUnitOfWork (react-dom.js:18667)
renderRoot (react-dom.js:19557)
performWorkOnRoot (react-dom.js:20431)
performWork (react-dom.js:20343)
performSyncWork (react-dom.js:20317)
interactiveUpdates$1 (react-dom.js:20584)
dispatchInteractiveEvent (react-dom.js:4985)
dispatchInteractiveEvent
[Error] Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it\'s defined in, or you might have mixed up default and named imports.
Check the render method of `edit`.
invariant (react-dom.js:56)
createFiberFromTypeAndProps (react-dom.js:10314)
createFiberFromElement (react-dom.js:10335)
createChild (react-dom.js:12114)
reconcileChildrenArray (react-dom.js:12365)
reconcileChildren (react-dom.js:14491)
mountIndeterminateComponent (react-dom.js:15153)
performUnitOfWork (react-dom.js:19401)
workLoop (react-dom.js:19441)
callCallback (react-dom.js:143)
dispatchEvent
invokeGuardedCallbackDev (react-dom.js:193)
invokeGuardedCallback (react-dom.js:250)
replayUnitOfWork (react-dom.js:18667)
renderRoot (react-dom.js:19557)
performWorkOnRoot (react-dom.js:20431)
performWork (react-dom.js:20343)
performSyncWork (react-dom.js:20317)
interactiveUpdates$1 (react-dom.js:20584)
dispatchInteractiveEvent (react-dom.js:4985)
dispatchInteractiveEvent
[Error] The above error occurred in the <edit> component:
in edit (created by Edit)
in Edit (created by WithToolbarControls(Edit))
in WithToolbarControls(Edit) (created by WithInspectorControl(WithToolbarControls(Edit)))
in WithInspectorControl(WithToolbarControls(Edit)) (created by WithInspectorControl(WithInspectorControl(WithToolbarControls(Edit))))
in WithInspectorControl(WithInspectorControl(WithToolbarControls(Edit)))
in Unknown (created by ComponentWithDispatch)
in ComponentWithDispatch (created by Context.Consumer)
in WithDispatch(Component) (created by ComponentWithSelect)
in ComponentWithSelect (created by Context.Consumer)
in WithMultipleValidation(WithInspectorControl(WithInspectorControl(WithToolbarControls(Edit)))) (created by WithFilters(Edit))
in WithFilters(Edit) (created by BlockEdit)
in BlockEdit (created by HoverArea)
in BlockCrashBoundary (created by HoverArea)
in div (created by IgnoreNestedEvents)
in IgnoreNestedEvents (created by ForwardRef(IgnoreNestedEvents))
in ForwardRef(IgnoreNestedEvents) (created by HoverArea)
in div (created by HoverArea)
in div (created by IgnoreNestedEvents)
in IgnoreNestedEvents (created by ForwardRef(IgnoreNestedEvents))
in ForwardRef(IgnoreNestedEvents) (created by HoverArea)
in HoverArea (created by ComponentWithSelect)
in ComponentWithSelect (created by Context.Consumer)
in WithSelect(HoverArea) (created by BlockListBlock)
in BlockListBlock
in Unknown (created by ComponentWithSelect)
in ComponentWithSelect (created by Context.Consumer)
in (BlockListBlock) (created by WithFilters(BlockListBlock))
in WithFilters(BlockListBlock) (created by ComponentWithDispatch)
in ComponentWithDispatch (created by Context.Consumer)
in WithDispatch(WithFilters(BlockListBlock)) (created by ComponentWithSelect)
in ComponentWithSelect (created by Context.Consumer)
in WithSelect(WithDispatch(WithFilters(BlockListBlock))) (created by ComponentWithSelect)
in ComponentWithSelect (created by Context.Consumer)
in WithViewportMatch(WithSelect(WithDispatch(WithFilters(BlockListBlock)))) (created by Pure(WithViewportMatch(WithSelect(WithDispatch(WithFilters(BlockListBlock))))))
in Pure(WithViewportMatch(WithSelect(WithDispatch(WithFilters(BlockListBlock))))) (created by BlockList)
in div (created by BlockList)
in BlockList (created by ComponentWithDispatch)
in ComponentWithDispatch (created by Context.Consumer)
in WithDispatch(BlockList) (created by ComponentWithSelect)
in ComponentWithSelect (created by Context.Consumer)
in WithSelect(WithDispatch(BlockList))
in Unknown (created by VisualEditor)
in div (created by CopyHandler)
in CopyHandler (created by ComponentWithDispatch)
in ComponentWithDispatch (created by Context.Consumer)
in WithDispatch(CopyHandler) (created by VisualEditor)
in div (created by ObserveTyping)
in ObserveTyping (created by WithSafeTimeout(ObserveTyping))
in WithSafeTimeout(ObserveTyping) (created by ComponentWithDispatch)
in ComponentWithDispatch (created by Context.Consumer)
in WithDispatch(WithSafeTimeout(ObserveTyping)) (created by ComponentWithSelect)
in ComponentWithSelect (created by Context.Consumer)
in WithSelect(WithDispatch(WithSafeTimeout(ObserveTyping))) (created by VisualEditor)
in div (created by WritingFlow)
in div (created by WritingFlow)
in WritingFlow (created by ComponentWithDispatch)
in ComponentWithDispatch (created by Context.Consumer)
in WithDispatch(WritingFlow) (created by ComponentWithSelect)
in ComponentWithSelect (created by Context.Consumer)
in WithSelect(WithDispatch(WritingFlow)) (created by VisualEditor)
in div (created by BlockSelectionClearer)
in BlockSelectionClearer (created by ComponentWithDispatch)
in ComponentWithDispatch (created by Context.Consumer)
in WithDispatch(BlockSelectionClearer) (created by ComponentWithSelect)
in ComponentWithSelect (created by Context.Consumer)
in WithSelect(WithDispatch(BlockSelectionClearer)) (created by VisualEditor)
in VisualEditor (created by Layout)
in div (created by Layout)
in div (created by FocusReturnProvider)
in FocusReturnProvider (created by Layout)
in Layout (created by ComponentWithSelect)
in ComponentWithSelect (created by Context.Consumer)
in WithViewportMatch(Layout) (created by NavigateRegions(WithViewportMatch(Layout)))
in div (created by NavigateRegions(WithViewportMatch(Layout)))
in NavigateRegions(WithViewportMatch(Layout)) (created by ComponentWithDispatch)
in ComponentWithDispatch (created by Context.Consumer)
in WithDispatch(NavigateRegions(WithViewportMatch(Layout))) (created by ComponentWithSelect)
in ComponentWithSelect (created by Context.Consumer)
in WithSelect(WithDispatch(NavigateRegions(WithViewportMatch(Layout)))) (created by Editor)
in ErrorBoundary (created by Editor)
in div (created by DropZoneProvider)
in DropZoneProvider (created by BlockEditorProvider)
in SlotFillProvider (created by BlockEditorProvider)
in BlockEditorProvider (created by Context.Consumer)
in WithRegistry(BlockEditorProvider) (created by ComponentWithDispatch)
in ComponentWithDispatch (created by Context.Consumer)
in WithDispatch(WithRegistry(BlockEditorProvider)) (created by EditorProvider)
in EditorProvider (created by ComponentWithDispatch)
in ComponentWithDispatch (created by Context.Consumer)
in WithDispatch(EditorProvider) (created by ComponentWithSelect)
in ComponentWithSelect (created by Context.Consumer)
in WithSelect(WithDispatch(EditorProvider)) (created by Editor)
in StrictMode (created by Editor)
in Editor (created by ComponentWithSelect)
in ComponentWithSelect (created by Context.Consumer)
in WithSelect(Editor)
React will try to recreate this component tree from scratch using the error boundary you provided, BlockCrashBoundary.
logCapturedError (react-dom.js:17206)
logError (react-dom.js:17242)
callback (react-dom.js:18183)
callCallback (react-dom.js:16522)
commitUpdateEffects (react-dom.js:16561)
commitUpdateQueue (react-dom.js:16552)
commitLifeCycles (react-dom.js:17453)
commitAllLifeCycles (react-dom.js:18825)
callCallback (react-dom.js:143)
dispatchEvent
invokeGuardedCallbackDev (react-dom.js:193)
invokeGuardedCallback (react-dom.js:250)
commitRoot (react-dom.js:19037)
(anonyme Funktion) (react-dom.js:20507)
unstable_runWithPriority (react.js:735)
completeRoot (react-dom.js:20506)
performWorkOnRoot (react-dom.js:20435)
performWork (react-dom.js:20343)
performSyncWork (react-dom.js:20317)
interactiveUpdates$1 (react-dom.js:20584)
dispatchInteractiveEvent (react-dom.js:4985)
dispatchInteractiveEvent