diff --git a/src/wireframes/model/actions/appearance.ts b/src/wireframes/model/actions/appearance.ts index 503f79e..6fdcafa 100644 --- a/src/wireframes/model/actions/appearance.ts +++ b/src/wireframes/model/actions/appearance.ts @@ -62,13 +62,13 @@ export function buildAppearance(builder: ActionReducerMapBuilder) { const { key, value } = appearance; return diagram.updateItems(itemIds, item => { - const rendererInstance = PluginRegistry.get(item.renderer); - - if (!rendererInstance) { + const plugin = PluginRegistry.get(item.renderer)?.plugin; + + if (!plugin) { throw new Error(`Cannot find renderer for ${item.renderer}.`); } - if (force || !Types.isUndefined(rendererInstance.defaultAppearance()[key])) { + if (force || !Types.isUndefined(plugin.defaultAppearance()[key])) { return item.setAppearance(key, value); } diff --git a/src/wireframes/model/actions/items.ts b/src/wireframes/model/actions/items.ts index cfe9fec..55d494e 100644 --- a/src/wireframes/model/actions/items.ts +++ b/src/wireframes/model/actions/items.ts @@ -121,13 +121,13 @@ export function buildItems(builder: ActionReducerMapBuilder) { const { diagramId, appearance, id, position, renderer, size } = action.payload; return state.updateDiagram(diagramId, diagram => { - const rendererInstance = PluginRegistry.get(renderer); + const registration = PluginRegistry.get(renderer); - if (!rendererInstance) { + if (!registration) { throw new Error(`Cannot find renderer for ${renderer}.`); } - const { size: defaultSize, appearance: defaultAppearance, ...other } = rendererInstance.createDefaultShape(); + const { size: defaultSize, appearance: defaults, ...other } = registration.createDefaultShape(); const initialSize = size || defaultSize; const initialProps = { @@ -141,7 +141,7 @@ export function buildItems(builder: ActionReducerMapBuilder) { initialSize.x, initialSize.y), Rotation.ZERO), - appearance: { ...defaultAppearance || {}, ...appearance }, + appearance: { ...defaults || {}, ...appearance }, }; const shape = DiagramItem.createShape(initialProps); diff --git a/src/wireframes/model/diagram-item-set.spec.ts b/src/wireframes/model/diagram-item-set.spec.ts index cfa607e..2bcbf5b 100644 --- a/src/wireframes/model/diagram-item-set.spec.ts +++ b/src/wireframes/model/diagram-item-set.spec.ts @@ -86,7 +86,7 @@ describe('Diagram Item Set', () => { const editable1 = set.editableIds; const editable2 = set.editableIds; - expect(editable1).toEqual([root1.id, groupId, child1.id, child2.id]); + expect(editable1).toEqual(new Set([root1.id, groupId, child1.id, child2.id])); expect(editable1).toBe(editable2); }); }); \ No newline at end of file diff --git a/src/wireframes/model/registry.spec.ts b/src/wireframes/model/registry.spec.ts index 1d3cf70..31e3078 100644 --- a/src/wireframes/model/registry.spec.ts +++ b/src/wireframes/model/registry.spec.ts @@ -9,10 +9,12 @@ import { PluginRegistry } from '@app/wireframes/model'; describe('PluginRegistry', () => { it('should register renderer with identifier', () => { - const plugin: any = 42; + const plugin = { + identifier: () => 'MyPlugin', + } as any; PluginRegistry.addPlugin(plugin); - expect(PluginRegistry.get('identifier')).toBe(plugin); + expect(PluginRegistry.get('MyPlugin')?.plugin).toBe(plugin); }); }); diff --git a/src/wireframes/renderer/ItemsLayer.tsx b/src/wireframes/renderer/ItemsLayer.tsx index 3b56f37..14bd461 100644 --- a/src/wireframes/renderer/ItemsLayer.tsx +++ b/src/wireframes/renderer/ItemsLayer.tsx @@ -90,13 +90,13 @@ export const ItemsLayer = React.memo((props: ItemsLayerProps) => { // Create missing shapes. for (const shape of allShapes) { if (!references[shape.id]) { - const rendererInstance = PluginRegistry.get(shape.renderer); - - if (!rendererInstance) { + const plugin = PluginRegistry.get(shape.renderer)?.plugin; + + if (!plugin) { throw new Error(`Cannot find renderer for ${shape.renderer}.`); } - references[shape.id] = diagramLayer.item(rendererInstance.plugin); + references[shape.id] = diagramLayer.item(plugin); } }