MCPcopy
hub / github.com/udecode/plate / resolveAndSortPlugins

Function resolveAndSortPlugins

packages/core/src/internal/plugin/resolvePlugins.ts:493–536  ·  view source on GitHub ↗
(
  editor: SlateEditor,
  plugins: SlatePlugins
)

Source from the content-addressed store, hash-verified

491};
492
493export const resolveAndSortPlugins = (
494 editor: SlateEditor,
495 plugins: SlatePlugins
496): SlatePlugins => {
497 // Step 1: Resolve, flatten, and merge all plugins
498 const pluginMap = flattenAndResolvePlugins(editor, plugins);
499
500 // Step 2: Filter out disabled plugins
501 const enabledPlugins = Array.from(pluginMap.values()).filter(
502 (plugin) => plugin.enabled !== false
503 );
504
505 // Step 3: Sort plugins by priority
506 enabledPlugins.sort((a, b) => b.priority - a.priority);
507
508 // Step 4: Reorder based on dependencies
509 const orderedPlugins: SlatePlugins = [];
510 const visited = new Set<string>();
511
512 const visit = (plugin: SlatePlugin) => {
513 if (visited.has(plugin.key)) return;
514
515 visited.add(plugin.key);
516
517 plugin.dependencies?.forEach((depKey) => {
518 const depPlugin = pluginMap.get(depKey);
519
520 if (depPlugin) {
521 visit(depPlugin);
522 } else {
523 editor.api.debug.warn(
524 `Plugin "${plugin.key}" depends on missing plugin "${depKey}"`,
525 'PLUGIN_DEPENDENCY_MISSING'
526 );
527 }
528 });
529
530 orderedPlugins.push(plugin);
531 };
532
533 enabledPlugins.forEach(visit);
534
535 return orderedPlugins;
536};
537
538export const applyPluginsToEditor = (
539 editor: SlateEditor,

Callers 3

getSortedKeysFunction · 0.90
resolvePluginsFunction · 0.85

Calls 1

flattenAndResolvePluginsFunction · 0.85

Tested by 1

getSortedKeysFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…