Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const callChangeHandlers = (
handlers: MultishiftChangeHandlerProps,
{ changes, state, prevState }: MultishiftStateChangeset,
) => {
const changedKeys = keys(changes);
const { onStateChange } = handlers;
changedKeys.forEach(key => {
changeHandlerMap[key](handlers, { changes, state, prevState });
});
if (changedKeys.length && onStateChange) {
onStateChange(changes, state);
}
};
export const schemaToJSON = (
schema: EditorSchema,
): SchemaJSON => {
const nodes = keys(schema.nodes).reduce((acc, key) => {
const { spec } = schema.nodes[key];
return { ...acc, [key]: spec };
}, Object.create(null));
const marks = keys(schema.marks).reduce((acc, key) => {
const { spec } = schema.marks[key];
return { ...acc, [key]: spec };
}, Object.create(null));
return {
nodes,
marks,
};
};
if (isString(domSpec) || isDOMNode(domSpec)) {
return;
}
const attrs = domSpec[1];
if (isPlainObject(attrs)) {
keys(attrs).forEach(attr => {
element.setAttribute(attr, String(attrs[attr]));
});
return;
}
}
keys(node.attrs).forEach(attr => {
element.setAttribute(attr, node.attrs[attr]);
});
}
print: val => {
if (isEditorState(val)) {
return `Prosemirror doc: ${JSON.stringify(
val.doc.toJSON(),
null,
2,
)}\nProsemirror selection: ${JSON.stringify(val.selection, null, 2)}`;
}
if (isEditorSchema(val)) {
const nodes = keys(val.nodes).reduce((acc, key) => {
const { spec } = val.nodes[key];
return { ...acc, [key]: spec };
}, {});
const marks = keys(val.marks).reduce((acc, key) => {
const { spec } = val.marks[key];
return { ...acc, [key]: spec };
}, {});
return `Prosemirror schema: ${JSON.stringify(
{
nodes,
marks,
},
null,
2,
)}`;
}
return `Prosemirror node: ${JSON.stringify(val, null, 2)}`;
},
public setDomAttrs(node: ProsemirrorNode, element: HTMLElement) {
const { toDOM } = this.node.type.spec;
if (toDOM) {
const domSpec = toDOM(node);
if (isString(domSpec) || isDOMNode(domSpec)) {
return;
}
const attrs = domSpec[1];
if (isPlainObject(attrs)) {
keys(attrs).forEach(attr => {
element.setAttribute(attr, String(attrs[attr]));
});
return;
}
}
keys(node.attrs).forEach(attr => {
element.setAttribute(attr, node.attrs[attr]);
});
}
export const bindActionCreators = <
GAction,
GCreatorMap extends ActionCreatorsMapObject,
GDispatch extends Dispatch
>(
actionCreators: GCreatorMap,
dispatch: GDispatch,
): ActionCreatorMapToDispatch => {
const boundActionCreators: ActionCreatorMapToDispatch = Object.create(null);
const creatorKeys = keys(actionCreators);
for (const key of creatorKeys) {
const actionCreator = actionCreators[key];
boundActionCreators[key] = bindActionCreator(actionCreator, dispatch);
}
return boundActionCreators;
};
print: val => {
if (isEditorState(val)) {
return `Prosemirror doc: ${JSON.stringify(
val.doc.toJSON(),
null,
2,
)}\nProsemirror selection: ${JSON.stringify(val.selection, null, 2)}`;
}
if (isEditorSchema(val)) {
const nodes = keys(val.nodes).reduce((acc, key) => {
const { spec } = val.nodes[key];
return { ...acc, [key]: spec };
}, {});
const marks = keys(val.marks).reduce((acc, key) => {
const { spec } = val.marks[key];
return { ...acc, [key]: spec };
}, {});
return `Prosemirror schema: ${JSON.stringify(
{
nodes,
marks,
},
null,
2,
)}`;