Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}) => {
if (json.type === 'text' && json.text && (!json.marks || !json.marks.length)) {
return {json.text}; // For some reason FunctionalComponent don't allow returning react-nodes
}
const rest = { markMap, typeMap, skipUnknownMarks, skipUnknownTypes };
const TypeHandler = typeMap[json.type];
if (!TypeHandler) {
if (!skipUnknownTypes) {
throw new Error(`No handler for node type \`${json.type}\` registered`);
}
return null;
}
const props = isString(TypeHandler) ? json.attrs ?? Object.create(null) : { ...rest, node: json };
const { content } = json;
if (!content || !content.length) {
return ;
}
const children = content.map((child, ii) => {
return ;
});
return {children};
};
getAttrs: node => (isString(node) && /^(bold(er)?|[5-9]\d{2,})$/.test(node) ? null : false),
},
getAttrs: node => (isString(node) && /^(bold(er)?|[5-9]\d{2,})$/.test(node) ? null : false),
},
getAttrs: dom => {
if (isString(dom)) {
return false;
}
const id = (dom as Element).getAttribute(dataAttribute);
const label = (dom as HTMLElement).innerText;
return { id, label };
},
},
const createInitialContent = ({ content, schema }: CreateInitialContentParams): Content => {
if (isString(content)) {
return {
markdown: content,
wysiwyg: fromMarkdown(content, schema),
};
}
if (isProsemirrorNode(content)) {
return {
markdown: toMarkdown(content),
wysiwyg: content,
};
}
if (!isObjectNode(content)) {
throw new Error('Invalid content passed into the editor');
}
public static renderSpec(structure: DOMOutputSpec, wraps?: ReactNode): ReactNode {
if (isString(structure)) {
return structure;
}
const Component = structure[0];
const props: PlainObject = Object.create(null);
const attrs = structure[1];
const children: ReactNode[] = [];
let currentIndex = 1;
if (isPlainObject(attrs) && !isArray(attrs)) {
currentIndex = 2;
for (const name in attrs) {
if (attrs[name] != null) {
props[name] = attrs[name];
}
}
}
const taggedContent = content.map(item => (isString(item) ? text(item, schema) : item)) as Array<
TaggedContentItem | TaggedContentItem[]
export const getAppendText = (preferred: string | undefined, fallback: string | undefined) => {
if (isString(preferred)) {
return preferred;
}
if (isString(fallback)) {
return fallback;
}
return DEFAULT_MATCHER.appendText;
};
public ssrTransformer(element: JSX.Element, { getState }: ExtensionManagerParams) {
const state = getState();
const { emptyNodeClass, placeholder } = this.options;
const { children } = getElementProps(element);
if (Children.count(children) > 1 || !isDocNodeEmpty(state.doc)) {
return element;
}
const props = getElementProps(children);
return cloneElement(
element,
{},
cloneElement(children, {
...props,
className: isString(props.className) ? `${props.className} ${emptyNodeClass}` : emptyNodeClass,
'data-placeholder': placeholder,
}),
);
}
}
export const getAppendText = (preferred: string | undefined, fallback: string | undefined) => {
if (isString(preferred)) {
return preferred;
}
if (isString(fallback)) {
return fallback;
}
return DEFAULT_MATCHER.appendText;
};