b67e0aef40e82fc9f8878e16babb76fa1e3406bb5b1a199be192580e7086bdbb43235b942dd13b208d1b32b9324be08e17827ca867f301f66ddf7bf773fa13 1.0 KB

1234567891011121314151617181920212223242526272829
  1. import { Registry } from 'parchment';
  2. const MAX_REGISTER_ITERATIONS = 100;
  3. const CORE_FORMATS = ['block', 'break', 'cursor', 'inline', 'scroll', 'text'];
  4. const createRegistryWithFormats = (formats, sourceRegistry, debug) => {
  5. const registry = new Registry();
  6. CORE_FORMATS.forEach(name => {
  7. const coreBlot = sourceRegistry.query(name);
  8. if (coreBlot) registry.register(coreBlot);
  9. });
  10. formats.forEach(name => {
  11. let format = sourceRegistry.query(name);
  12. if (!format) {
  13. debug.error(`Cannot register "${name}" specified in "formats" config. Are you sure it was registered?`);
  14. }
  15. let iterations = 0;
  16. while (format) {
  17. registry.register(format);
  18. format = 'blotName' in format ? format.requiredContainer ?? null : null;
  19. iterations += 1;
  20. if (iterations > MAX_REGISTER_ITERATIONS) {
  21. debug.error(`Cycle detected in registering blot requiredContainer: "${name}"`);
  22. break;
  23. }
  24. }
  25. });
  26. return registry;
  27. };
  28. export default createRegistryWithFormats;
  29. //# sourceMappingURL=createRegistryWithFormats.js.map