@atlaskit/editor-plugin-block-menu
Version:
BlockMenu plugin for @atlaskit/editor-core
49 lines • 1.47 kB
JavaScript
import { logException } from '@atlaskit/editor-common/monitoring';
export const createBlockMenuTransformSourceRegistry = () => {
const transforms = new Map();
return {
register: registeredTransforms => {
const registered = [];
registeredTransforms.forEach(transform => {
if (transforms.has(transform.key)) {
void logException(new Error(`Duplicate Block Menu transform key: ${transform.key}`), {
location: 'editor-plugin-block-menu'
});
return;
}
transforms.set(transform.key, transform);
registered.push(transform);
});
if (registered.length === 0) {
return () => {};
}
return () => {
registered.forEach(transform => {
if (transforms.get(transform.key) === transform) {
transforms.delete(transform.key);
}
});
};
},
resolve: context => {
const transform = Array.from(transforms.values()).find(({
isSupported
}) => {
try {
return isSupported(context);
} catch (error) {
void logException(error instanceof Error ? error : new Error('Block Menu transform support check failed'), {
location: 'editor-plugin-block-menu'
});
return false;
}
});
return transform ? {
status: 'supported',
transform
} : {
status: 'unsupported'
};
}
};
};