From 6ec1bc5ba50960d2ceefcc0370b43e3f86f99fcc Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 25 Sep 2024 10:23:25 -0700 Subject: [PATCH] feat: Add the IFlyoutInflater interface. (#8581) * feat: Add the IFlyoutInflater interface. * fix: Add a return type for IFlyoutInflater.disposeElement(). * refactor: Add the gapForElement method. --- core/interfaces/i_flyout_inflater.ts | 41 ++++++++++++++++++++++++++++ core/registry.ts | 3 ++ 2 files changed, 44 insertions(+) create mode 100644 core/interfaces/i_flyout_inflater.ts diff --git a/core/interfaces/i_flyout_inflater.ts b/core/interfaces/i_flyout_inflater.ts new file mode 100644 index 000000000..f4a3b6ee9 --- /dev/null +++ b/core/interfaces/i_flyout_inflater.ts @@ -0,0 +1,41 @@ +import type {IBoundedElement} from './i_bounded_element.js'; +import type {WorkspaceSvg} from '../workspace_svg.js'; + +export interface IFlyoutInflater { + /** + * Loads the object represented by the given state onto the workspace. + * + * Note that this method's interface is identical to that in ISerializer, to + * allow for code reuse. + * + * @param state A JSON representation of an element to inflate on the flyout. + * @param flyoutWorkspace The flyout's workspace, where the inflated element + * should be created. If the inflated element is an `IRenderedElement` it + * itself or the inflater should append it to the workspace; the flyout + * will not do so itself. The flyout is responsible for positioning the + * element, however. + * @returns The newly inflated flyout element. + */ + load(state: Object, flyoutWorkspace: WorkspaceSvg): IBoundedElement; + + /** + * Returns the amount of spacing that should follow the element corresponding + * to the given JSON representation. + * + * @param state A JSON representation of the element preceding the gap. + * @param defaultGap The default gap for elements in this flyout. + * @returns The gap that should follow the given element. + */ + gapForElement(state: Object, defaultGap: number): number; + + /** + * Disposes of the given element. + * + * If the element in question resides on the flyout workspace, it should remove + * itself. Implementers are not otherwise required to fully dispose of the + * element; it may be e.g. cached for performance purposes. + * + * @param element The flyout element to dispose of. + */ + disposeElement(element: IBoundedElement): void; +} diff --git a/core/registry.ts b/core/registry.ts index c7e16e935..7d70fe2eb 100644 --- a/core/registry.ts +++ b/core/registry.ts @@ -10,6 +10,7 @@ import type {Abstract} from './events/events_abstract.js'; import type {Field} from './field.js'; import type {IConnectionChecker} from './interfaces/i_connection_checker.js'; import type {IFlyout} from './interfaces/i_flyout.js'; +import type {IFlyoutInflater} from './interfaces/i_flyout_inflater.js'; import type {IMetricsManager} from './interfaces/i_metrics_manager.js'; import type {IIcon} from './interfaces/i_icon.js'; import type {Input} from './inputs/input.js'; @@ -99,6 +100,8 @@ export class Type<_T> { 'flyoutsHorizontalToolbox', ); + static FLYOUT_INFLATER = new Type('flyoutInflater'); + static METRICS_MANAGER = new Type('metricsManager'); /**