Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor(props: RemirrorProps, context: RemirrorThemeContextType) {
super(props, context);
// Ensure that children is a render prop.
propIsFunction(props.children);
// Initialize the manager and create the initial state.
this.manager.init({
getState: this.getState,
getTheme: this.getTheme,
portalContainer: this.portalContainer,
});
this.state = this.createInitialState();
// Create the ProsemirrorView and initialize our extension manager with it.
this.view = this.createView();
this.manager.initView(this.view);
}
if (this.rootPropsConfig.called) {
// Simply return the element as this method can never actually be called
// within a domless environment
return element;
} else if (
// When called by a provider `getRootProps` can't actually be called until
// the jsx is generated. Check if this is being rendered via any remirror
// context provider. In this case `getRootProps` **must** be called by the
// consumer.
isRemirrorContextProvider(element) ||
isRemirrorProvider(element) ||
isManagedRemirrorProvider(element)
) {
const { childAsRoot } = element.props;
return childAsRoot
? cloneElement(element, props, this.renderClonedElement(children, childAsRoot))
: element;
} else {
return isReactDOMElement(element) ? (
this.renderClonedElement(element)
) : (
<div>
);
}
}
</div>
private renderReactElement() {
const element: JSX.Element | null = this.props.children({
...this.renderParams,
});
const { children, ...props } = getElementProps(element);
if (this.rootPropsConfig.called) {
// Simply return the element as this method can never actually be called
// within a domless environment
return element;
} else if (
// When called by a provider `getRootProps` can't actually be called until
// the jsx is generated. Check if this is being rendered via any remirror
// context provider. In this case `getRootProps` **must** be called by the
// consumer.
isRemirrorContextProvider(element) ||
isRemirrorProvider(element) ||
isManagedRemirrorProvider(element)
) {
const { childAsRoot } = element.props;
return childAsRoot
return element;
} else if (
// When called by a provider `getRootProps` can't actually be called until
// the jsx is generated. Check if this is being rendered via any remirror
// context provider. In this case `getRootProps` **must** be called by the
// consumer.
isRemirrorContextProvider(element) ||
isRemirrorProvider(element) ||
isManagedRemirrorProvider(element)
) {
const { childAsRoot } = element.props;
return childAsRoot
? cloneElement(element, props, this.renderClonedElement(children, childAsRoot))
: element;
} else {
return isReactDOMElement(element) ? (
this.renderClonedElement(element)
) : (
<div>
);
}
}
</div>
});
const { children, ...props } = getElementProps(element);
if (this.rootPropsConfig.called) {
// Simply return the element as this method can never actually be called
// within a domless environment
return element;
} else if (
// When called by a provider `getRootProps` can't actually be called until
// the jsx is generated. Check if this is being rendered via any remirror
// context provider. In this case `getRootProps` **must** be called by the
// consumer.
isRemirrorContextProvider(element) ||
isRemirrorProvider(element) ||
isManagedRemirrorProvider(element)
) {
const { childAsRoot } = element.props;
return childAsRoot
? cloneElement(element, props, this.renderClonedElement(children, childAsRoot))
: element;
} else {
return isReactDOMElement(element) ? (
this.renderClonedElement(element)
) : (
<div>
);
}
}
</div>
const element: JSX.Element | null = this.props.children({
...this.renderParams,
});
const { children, ...props } = getElementProps(element);
if (this.rootPropsConfig.called) {
// Simply return the element as this method can never actually be called
// within a domless environment
return element;
} else if (
// When called by a provider `getRootProps` can't actually be called until
// the jsx is generated. Check if this is being rendered via any remirror
// context provider. In this case `getRootProps` **must** be called by the
// consumer.
isRemirrorContextProvider(element) ||
isRemirrorProvider(element) ||
isManagedRemirrorProvider(element)
) {
const { childAsRoot } = element.props;
return childAsRoot
? cloneElement(element, props, this.renderClonedElement(children, childAsRoot))
: element;
} else {
return isReactDOMElement(element) ? (
this.renderClonedElement(element)
) : (
<div>
);
}
}
</div>
...this.renderParams,
});
const { children, ...props } = getElementProps(element);
if (this.rootPropsConfig.called) {
// Simply return the element as this method can never actually be called
// within a domless environment
return element;
} else if (
// When called by a provider `getRootProps` can't actually be called until
// the jsx is generated. Check if this is being rendered via any remirror
// context provider. In this case `getRootProps` **must** be called by the
// consumer.
isRemirrorContextProvider(element) ||
isRemirrorProvider(element) ||
isManagedRemirrorProvider(element)
) {
const { childAsRoot } = element.props;
return childAsRoot
? cloneElement(element, props, this.renderClonedElement(children, childAsRoot))
: element;
} else {
return isReactDOMElement(element) ? (
this.renderClonedElement(element)
) : (
<div>
);
}
}
</div>
public componentDidUpdate(
{ editable, manager: prevManager }: RemirrorProps,
prevState: RemirrorState>,
) {
// Ensure that children is still a render prop
propIsFunction(this.props.children);
// Check whether the editable prop has been updated
if (this.props.editable !== editable && this.view && this.editorRef) {
this.view.setProps({ ...this.view.props, editable: () => this.props.editable });
}
// Check if the manager has changed
if (!prevManager.isEqual(this.props.manager)) {
this.updateExtensionManager();
this.view.setProps({ ...this.view.props, nodeViews: this.manager.data.nodeViews });
// The following converts the current content to HTML and then uses the
// new manager schema to convert it back into a ProsemirrorNode for
// compatibility with the new manager.
const htmlString = toHTML({ node: this.state.editor.newState.doc, schema: prevManager.schema });
const newContent = fromHTML({ schema: this.manager.schema, content: htmlString, doc: this.doc });
export const cloneSSRElement = (
element: JSX.Element,
transformChildElements: (
children: JSX.Element | JSX.Element[],
childrenProps: PlainObject,
) => JSX.Element | JSX.Element[],
) => {
if (!isReactFragment(element)) {
throw new Error('Invalid element passed. The top level element must be a fragment');
}
const { children } = getElementProps(element);
const childrenProps = getElementProps(children);
return cloneElement(element, {}, transformChildElements(children, childrenProps));
};
return Children.map(children, child => {
if (!(isReactDOMElement(child) && elementIsEmpty(child) && elementIsOfType(child, 'p'))) {
return child;
}
const props = getElementProps(child);
return cloneElement(child, props, jsx('br'));
});
});