From 02054d62c213319d82d439367fa64c5258483bfd Mon Sep 17 00:00:00 2001 From: Val Erastov Date: Sun, 14 Aug 2022 20:48:44 -0700 Subject: [PATCH] simplify bundle system --- modules/bundler/bundleSystem.ts | 148 ++++++------- modules/bundler/bundlerContext.ts | 6 + test/coreTests/subjects/modellerTPI.js | 2 +- web/app/cad/actions/actionSystemBundle.ts | 6 +- web/app/cad/assembly/assemblyBundle.ts | 5 +- web/app/cad/attributes/attributesBundle.ts | 22 +- web/app/cad/context/LegacyStructureBundle.ts | 22 ++ web/app/cad/context/index.ts | 31 +-- web/app/cad/craft/cadRegistryBundle.ts | 4 +- web/app/cad/craft/craftBundle.ts | 4 +- web/app/cad/craft/craftEnginePlugin.js | 6 - .../{craftUiPlugin.js => craftUIBundle.js} | 2 + web/app/cad/craft/e0/occtBundle.ts | 6 +- ...xtensionsPlugin.js => extensionsBundle.js} | 2 + web/app/cad/craft/operationBundle.ts | 6 +- web/app/cad/craft/wizard/wizardBundle.ts | 9 +- ...tionPlugin.ts => wizardSelectionBundle.ts} | 31 ++- .../cad/{debugPlugin.js => debugBundle.js} | 2 + .../cad/dom/actionInfo/actionInfoPlugin.js | 4 - web/app/cad/dom/appTabsBundle.ts | 5 +- .../cad/dom/components/PlugableControlBar.jsx | 2 +- web/app/cad/dom/domBundle.ts | 25 +-- .../dom/menu/{menuPlugin.js => menuBundle.js} | 2 + web/app/cad/dom/uiBundle.ts | 5 +- .../cad/{exportPlugin.js => exportBundle.js} | 2 + .../{exposurePlugin.js => exposureBundle.js} | 2 + web/app/cad/expressions/expressionsBundle.ts | 8 +- ...{lifecyclePlugin.js => lifecycleBundle.js} | 2 + web/app/cad/init/startApplication.js | 208 ++++++++---------- .../{keyboardPlugin.js => keyboardBundle.js} | 4 +- web/app/cad/location/LocationBundle.ts | 6 +- web/app/cad/partImport/remotePartsBundle.ts | 30 +-- web/app/cad/plugins.js | 11 - .../{previewPlugin.ts => previewBundle.ts} | 2 + web/app/cad/projectBundle.ts | 6 +- .../projectManager/projectManagerBundle.ts | 5 +- web/app/cad/repository/repositoryPlugin.ts | 3 - ...temPlugin.js => mouseEventSystemBundle.js} | 2 + ...kControlPlugin.ts => pickControlBundle.ts} | 6 +- web/app/cad/scene/entityContextBundle.ts | 7 +- web/app/cad/scene/highlightBundle.ts | 20 +- web/app/cad/scene/sceneBundle.ts | 7 +- .../{markerPlugin.ts => markerBundle.ts} | 4 +- .../{viewSyncPlugin.js => viewSyncBundle.js} | 15 +- web/app/cad/sketch/sketchStorageBundle.ts | 5 +- web/app/cad/sketch/sketcherBundle.ts | 4 +- web/app/cad/storage/storageBundle.ts | 4 +- .../{uiConfigPlugin.js => uiConfigBundle.js} | 2 + web/app/cad/workbench/workbenchBundle.ts | 19 +- ...erPlugin.ts => workbenchesLoaderBundle.ts} | 20 +- 50 files changed, 325 insertions(+), 436 deletions(-) create mode 100644 modules/bundler/bundlerContext.ts create mode 100644 web/app/cad/context/LegacyStructureBundle.ts delete mode 100644 web/app/cad/craft/craftEnginePlugin.js rename web/app/cad/craft/{craftUiPlugin.js => craftUIBundle.js} (82%) rename web/app/cad/craft/{extensionsPlugin.js => extensionsBundle.js} (97%) rename web/app/cad/craft/wizard/{wizardSelectionPlugin.ts => wizardSelectionBundle.ts} (85%) rename web/app/cad/{debugPlugin.js => debugBundle.js} (99%) delete mode 100644 web/app/cad/dom/actionInfo/actionInfoPlugin.js rename web/app/cad/dom/menu/{menuPlugin.js => menuBundle.js} (97%) rename web/app/cad/{exportPlugin.js => exportBundle.js} (97%) rename web/app/cad/exposure/{exposurePlugin.js => exposureBundle.js} (93%) rename web/app/cad/init/{lifecyclePlugin.js => lifecycleBundle.js} (96%) rename web/app/cad/keyboard/{keyboardPlugin.js => keyboardBundle.js} (90%) delete mode 100644 web/app/cad/plugins.js rename web/app/cad/preview/{previewPlugin.ts => previewBundle.ts} (97%) delete mode 100644 web/app/cad/repository/repositoryPlugin.ts rename web/app/cad/scene/controls/{mouseEventSystemPlugin.js => mouseEventSystemBundle.js} (99%) rename web/app/cad/scene/controls/{pickControlPlugin.ts => pickControlBundle.ts} (99%) rename web/app/cad/scene/selectionMarker/{markerPlugin.ts => markerBundle.ts} (97%) rename web/app/cad/scene/{viewSyncPlugin.js => viewSyncBundle.js} (89%) rename web/app/cad/workbench/{uiConfigPlugin.js => uiConfigBundle.js} (97%) rename web/app/cad/workbench/{workbenchesLoaderPlugin.ts => workbenchesLoaderBundle.ts} (71%) diff --git a/modules/bundler/bundleSystem.ts b/modules/bundler/bundleSystem.ts index 5a68fe1b..eac4b32b 100644 --- a/modules/bundler/bundleSystem.ts +++ b/modules/bundler/bundleSystem.ts @@ -1,109 +1,95 @@ -type BagOfPlugins = Set>; export class BundleSystem { - plugins: BagOfPlugins = new Set(); - waitingQueue: BagOfPlugins = new Set(); globalContext: any; + activatedBundles = new Set(); + waitingQueue = new Set>(); + perfectLoad = true; - constructor(globalContext: any) { + constructor(globalContext) { this.globalContext = globalContext; } - load(plugin: Bundle) { - this.waitingQueue.add(plugin); + activate(bundle: Bundle) { + + if (!bundle.BundleName) { + console.error("BundleName is not provided for the bundle"); + bundle.BundleName = "@Unknown_" + (UNKNOWNS_COUNTER++); + } + + if (this.activatedBundles.has(bundle.BundleName)) { + throw `Bundle ${bundle.BundleName} has already activated. Possible name collision`; + } + + if (!this.readinessCheck(bundle)) { + this.perfectLoad = false; + this.waitingQueue.add(bundle); + return; + } + + this.doActivate(bundle); + this.processWaitingQueue(); } + private doActivate(bundle) { + bundle.activate(this.globalContext); + this.activatedBundles.add(bundle.BundleName); + } + processWaitingQueue() { - let needPass = true; - while (needPass) { - needPass = false; - this.waitingQueue.forEach(plugin => { - const ready = readiness(plugin, this.globalContext); - if (ready) { - try { - plugin.activate(this.globalContext); - checkActivation(plugin, this.globalContext); - needPass = true; - this.plugins.add(plugin); - } catch (error) { - console.error(error); - } finally { - this.waitingQueue.delete(plugin) - } - } - }) - } - } - - unload(plugin: Bundle) { - this.waitingQueue.delete(plugin); - this.plugins.delete(plugin); - try { - if (plugin.deactivate) { - plugin.deactivate(this.globalContext); + for (let bundle of this.waitingQueue) { + if (this.readinessCheck(bundle)) { + this.waitingQueue.delete(bundle); + this.doActivate(bundle); } - } catch (error) { - console.error(error); + } + } + + readinessCheck(bundle) { + + if (!bundle.activationDependencies) { + return true; } - let needPass = true; - while (needPass) { - needPass = false; - this.plugins.forEach(plugin => { - if (!plugin.deactivate) { - return; - } - const isReady = readiness(plugin, this.globalContext); - if (!isReady) { - try { - plugin.deactivate(this.globalContext); - this.plugins.delete(plugin); - this.waitingQueue.add(plugin); - needPass = true; - } catch (error) { - console.error(error); - } - } - }) + for (let dep of bundle.activationDependencies) { + if (!this.activatedBundles.has(dep)) { + return false; + } + } + return true; + } + + checkDanglingBundles() { + this.waitingQueue.forEach(dangling => { + const unsatisfied = new Set(dangling.activationDependencies); + this.activatedBundles.forEach(activated => unsatisfied.delete(activated)); + console.error('Bundle', dangling.BundleName, 'was never activated because of unsatisfied dependencies: ', Array.from(unsatisfied).join(', ')); + }) + } + + checkPerfectLoad() { + if (!this.perfectLoad) { + console.warn("Bundle activation wasn't perfect. Consider reordering bundles to following:"); + console.info(Array.from(this.activatedBundles)); } } } -function readiness(plugin: Bundle, globalContext: any) { - const specKeys = Object.keys(plugin.inputContextSpec); - for (let key of specKeys) { - if (!globalContext[key] && plugin.inputContextSpec[key] === 'required') { - return false; - } - } - return true; -} - -function checkActivation(plugin: Bundle, globalContext: any) { - const specKeys = Object.keys(plugin.outputContextSpec); - for (let key of specKeys) { - if (!globalContext[key] && plugin.outputContextSpec[key] === 'required') { - console.error("declared service was never activated: " + key); - } - } -} - -export type Spec = 'required' | 'optional'; - +export type Spec = 'required'; export type ContextSpec = { [Property in keyof T]: Spec; }; -export interface Bundle { +export interface Bundle { - inputContextSpec: ContextSpec; + activationDependencies?: string[]; - outputContextSpec: ContextSpec; + runtimeDependencies?: string[]; - activate(ctx: InputContext&OutputContext); - - deactivate?(ctx: InputContext&OutputContext); + activate(ctx: WorkingContext); + BundleName: string, } + +let UNKNOWNS_COUNTER = 0; \ No newline at end of file diff --git a/modules/bundler/bundlerContext.ts b/modules/bundler/bundlerContext.ts new file mode 100644 index 00000000..38e242f6 --- /dev/null +++ b/modules/bundler/bundlerContext.ts @@ -0,0 +1,6 @@ + + + +export function createBundlerContext() { + +} \ No newline at end of file diff --git a/test/coreTests/subjects/modellerTPI.js b/test/coreTests/subjects/modellerTPI.js index 447ae784..04edfd69 100644 --- a/test/coreTests/subjects/modellerTPI.js +++ b/test/coreTests/subjects/modellerTPI.js @@ -3,7 +3,7 @@ import { ALL_EXCLUDING_SOLID_KINDS, PICK_KIND, traversePickResults -} from '../../../web/app/cad/scene/controls/pickControlPlugin'; +} from 'cad/scene/controls/pickControlBundle'; import {Vector3} from "three"; function waitFor(checkFn) { diff --git a/web/app/cad/actions/actionSystemBundle.ts b/web/app/cad/actions/actionSystemBundle.ts index addfe6a3..2067737d 100644 --- a/web/app/cad/actions/actionSystemBundle.ts +++ b/web/app/cad/actions/actionSystemBundle.ts @@ -4,7 +4,6 @@ import {state, StateStream, Stream} from 'lstream'; import {LOG_FLAGS} from '../logFlags'; import {ApplicationContext} from "cad/context"; import {IconType} from "react-icons"; -import {ContextSpec} from "bundler/bundleSystem"; export function activate(context: ApplicationContext) { @@ -160,7 +159,6 @@ export interface ActionSystemBundleContext { actionService: ActionService; } -export const outputContextSpec: ContextSpec = { - actionService: 'required' -} +export const BundleName = "@ActionSystem"; + diff --git a/web/app/cad/assembly/assemblyBundle.ts b/web/app/cad/assembly/assemblyBundle.ts index 5f4841f2..3852ae27 100644 --- a/web/app/cad/assembly/assemblyBundle.ts +++ b/web/app/cad/assembly/assemblyBundle.ts @@ -9,7 +9,6 @@ import {AssemblyView} from "./ui/AssemblyView"; import {IoMdConstruct} from "react-icons/io"; import {AssemblyConstraintDefinition} from "./assemblyConstraint"; import {AssemblyConstraintsSchemas} from "./assemblySchemas"; -import {ContextSpec} from "bundler/bundleSystem"; export function activate(ctx: ApplicationContext) { @@ -105,6 +104,4 @@ export interface AssemblyBundleContext { assemblyService: AssemblyService; } -export const outputContextSpec: ContextSpec = { - assemblyService: 'required' -} +export const BundleName = "@Assembly"; diff --git a/web/app/cad/attributes/attributesBundle.ts b/web/app/cad/attributes/attributesBundle.ts index 3900dca9..42790658 100644 --- a/web/app/cad/attributes/attributesBundle.ts +++ b/web/app/cad/attributes/attributesBundle.ts @@ -2,31 +2,22 @@ import {Bundle} from "bundler/bundleSystem"; import {AttributesService} from "cad/attributes/attributesService"; import {contributeComponent} from "cad/dom/components/ContributedComponents"; import {DisplayOptionsDialogManager} from "cad/attributes/ui/DisplayOptionsDialog"; -import {ActionSystemBundleContext} from "cad/actions/actionSystemBundle"; import {RequiresAnyModelSelection} from "cad/actions/actionHelpers"; import {IoColorPalette} from "react-icons/io5"; import {FaTable} from "react-icons/fa"; import {ApplicationContext} from "cad/context"; -type AttributesPluginInputContext = ActionSystemBundleContext; - -export interface AttributesPluginContext { +export interface AttributesBundleContext { attributesService: AttributesService; } -type AttributesPluginWorkingContext = AttributesPluginInputContext&AttributesPluginContext; +export const AttributesBundle: Bundle = { -export const AttributesBundle: Bundle = { + activationDependencies: [ + '@ActionSystem' + ], - inputContextSpec: { - actionService: 'required', - }, - - outputContextSpec: { - attributesService: 'required', - }, - - activate(ctx: AttributesPluginWorkingContext) { + activate(ctx: ApplicationContext) { ctx.attributesService = new AttributesService(); contributeComponent(DisplayOptionsDialogManager); @@ -55,6 +46,7 @@ export const AttributesBundle: Bundle = { + + activate(ctx: ApplicationContext) { + ctx.services = {}; + ctx.streams = {}; + }, + + BundleName: "@Legacy", + +} + + diff --git a/web/app/cad/context/index.ts b/web/app/cad/context/index.ts index 737693b2..7d59cf60 100644 --- a/web/app/cad/context/index.ts +++ b/web/app/cad/context/index.ts @@ -1,52 +1,48 @@ import {ProjectBundleContext} from "cad/projectBundle"; import {ActionSystemBundleContext} from "cad/actions/actionSystemBundle"; import {AssemblyBundleContext} from "cad/assembly/assemblyBundle"; -import {AttributesPluginContext} from "cad/attributes/attributesBundle"; +import {AttributesBundleContext} from "cad/attributes/attributesBundle"; import {CadRegistryBundleContext} from "cad/craft/cadRegistryBundle"; import {CraftBundleContext} from "cad/craft/craftBundle"; import {OperationBundleContext} from "cad/craft/operationBundle"; import {OCCBundleContext} from "cad/craft/e0/occtBundle"; -import {WizardPluginContext} from "cad/craft/wizard/wizardBundle"; +import {WizardBundleContext} from "cad/craft/wizard/wizardBundle"; import {AppTabsBundleContext} from "cad/dom/appTabsBundle"; -import {DomPluginContext} from "cad/dom/domBundle"; +import {DomBundleContext} from "cad/dom/domBundle"; import {UIBundleContext} from "cad/dom/uiBundle"; import {ExpressionBundleContext} from "cad/expressions/expressionsBundle"; import {LocationBundleContext} from "cad/location/LocationBundle"; import {RemotePartsBundleContext} from "cad/partImport/remotePartsBundle"; import {ProjectManagerBundleContext} from "cad/projectManager/projectManagerBundle"; import {EntityContextBundleContext} from "cad/scene/entityContextBundle"; -import {HighlightPluginContext} from "cad/scene/highlightBundle"; +import {HighlightBundleContext} from "cad/scene/highlightBundle"; import {SceneBundleContext} from "cad/scene/sceneBundle"; import {SketcherBundleContext} from "cad/sketch/sketcherBundle"; import {SketchStorageBundleContext} from "cad/sketch/sketchStorageBundle"; import {StorageBundleContext} from "cad/storage/storageBundle"; import {WorkbenchBundleContext} from "cad/workbench/workbenchBundle"; - -export interface LegacyContext { - services: any, - streams: any, -} +import {LegacyStructureBundleContext} from "cad/context/LegacyStructureBundle"; export interface ApplicationContext extends - LegacyContext, + LegacyStructureBundleContext, ProjectBundleContext, ActionSystemBundleContext, AssemblyBundleContext, - AttributesPluginContext, + AttributesBundleContext, CadRegistryBundleContext, CraftBundleContext, OperationBundleContext, OCCBundleContext, - WizardPluginContext, + WizardBundleContext, AppTabsBundleContext, - DomPluginContext, + DomBundleContext, UIBundleContext, ExpressionBundleContext, LocationBundleContext, RemotePartsBundleContext, ProjectManagerBundleContext, EntityContextBundleContext, - HighlightPluginContext, + HighlightBundleContext, SceneBundleContext, SketcherBundleContext, SketchStorageBundleContext, @@ -56,10 +52,5 @@ export interface ApplicationContext extends export type CoreContext = ApplicationContext; -export default { - - services: {}, - streams: {} - -} as ApplicationContext; +export default {} as ApplicationContext; diff --git a/web/app/cad/craft/cadRegistryBundle.ts b/web/app/cad/craft/cadRegistryBundle.ts index 9f9e0740..6ef86c4d 100644 --- a/web/app/cad/craft/cadRegistryBundle.ts +++ b/web/app/cad/craft/cadRegistryBundle.ts @@ -114,6 +114,4 @@ export interface CadRegistryBundleContext { cadRegistry: CadRegistry; } -export const outputContextSpec: ContextSpec = { - cadRegistry: 'required' -} +export const BundleName = "@CadRegistry"; diff --git a/web/app/cad/craft/craftBundle.ts b/web/app/cad/craft/craftBundle.ts index 63453c8d..c82cbf0c 100644 --- a/web/app/cad/craft/craftBundle.ts +++ b/web/app/cad/craft/craftBundle.ts @@ -297,6 +297,4 @@ export interface CraftBundleContext { craftService: CraftService; } -export const outputContextSpec: ContextSpec = { - craftService: 'required' -} +export const BundleName = "@Craft"; \ No newline at end of file diff --git a/web/app/cad/craft/craftEnginePlugin.js b/web/app/cad/craft/craftEnginePlugin.js deleted file mode 100644 index ac75417e..00000000 --- a/web/app/cad/craft/craftEnginePlugin.js +++ /dev/null @@ -1,6 +0,0 @@ -import defaultCraftEngine from './defaultCraftEngine'; - - -export function activate(ctx) { - ctx.services.craftEngine = defaultCraftEngine -} \ No newline at end of file diff --git a/web/app/cad/craft/craftUiPlugin.js b/web/app/cad/craft/craftUIBundle.js similarity index 82% rename from web/app/cad/craft/craftUiPlugin.js rename to web/app/cad/craft/craftUIBundle.js index 6d95df38..8b262ad2 100644 --- a/web/app/cad/craft/craftUiPlugin.js +++ b/web/app/cad/craft/craftUIBundle.js @@ -1,6 +1,8 @@ import {state} from 'lstream'; import {EMPTY_OBJECT} from 'gems/objects'; +export const BundleName = "@CraftUI"; + export function activate({streams}) { streams.ui.craft = { modificationSelection: state(EMPTY_OBJECT) diff --git a/web/app/cad/craft/e0/occtBundle.ts b/web/app/cad/craft/e0/occtBundle.ts index 5632d618..2d40cbfc 100644 --- a/web/app/cad/craft/e0/occtBundle.ts +++ b/web/app/cad/craft/e0/occtBundle.ts @@ -1,7 +1,6 @@ import {GenericWASMEngine_V1} from "engine/impl/wasm/GenericWASMEngine_V1"; import {CraftEngine} from "./craftEngine"; import {createOCCService, OCCService} from "cad/craft/e0/occService"; -import {ContextSpec} from "bundler/bundleSystem"; export interface OCCBundleContext { @@ -55,10 +54,7 @@ function loadWasm(ctx) { document.head.appendChild(mainScript); } -export const outputContextSpec: ContextSpec = { - craftEngine: 'required', - occService: 'required' -} +export const BundleName = "@OCCT"; diff --git a/web/app/cad/craft/extensionsPlugin.js b/web/app/cad/craft/extensionsBundle.js similarity index 97% rename from web/app/cad/craft/extensionsPlugin.js rename to web/app/cad/craft/extensionsBundle.js index 157d14a2..1e3bc612 100644 --- a/web/app/cad/craft/extensionsPlugin.js +++ b/web/app/cad/craft/extensionsBundle.js @@ -1,5 +1,7 @@ import {STORAGE_GLOBAL_PREFIX} from '../projectBundle'; +export const BundleName = "@Extensions"; + const EXTENSIONS_STORAGE_PREFIX = `${STORAGE_GLOBAL_PREFIX}.Extensions`; let extensions = []; diff --git a/web/app/cad/craft/operationBundle.ts b/web/app/cad/craft/operationBundle.ts index 3cb17905..003809c4 100644 --- a/web/app/cad/craft/operationBundle.ts +++ b/web/app/cad/craft/operationBundle.ts @@ -10,11 +10,9 @@ import {Types} from "cad/craft/schema/types"; import {EntityTypeSchema} from "cad/craft/schema/types/entityType"; import {FlattenPath, ParamsPath} from "cad/craft/wizard/wizardTypes"; import {IconDeclaration} from "cad/icons/IconDeclaration"; -import {resolveIcon} from "cad/craft/ui/iconResolver"; import {loadDeclarativeForm} from "cad/mdf/declarativeFormLoader"; import {operationIconToActionIcon} from "cad/craft/operationHelper"; import {GenerateWorkbenchOperationDocumentationLink} from "doc/documentationHelper"; -import {ContextSpec} from "bundler/bundleSystem"; export function activate(ctx: ApplicationContext) { @@ -239,8 +237,6 @@ export interface OperationBundleContext { operationService: OperationService; } -export const outputContextSpec: ContextSpec = { - operationService: 'required' -} +export const BundleName = "@Operation"; diff --git a/web/app/cad/craft/wizard/wizardBundle.ts b/web/app/cad/craft/wizard/wizardBundle.ts index 777115c2..7184e73a 100644 --- a/web/app/cad/craft/wizard/wizardBundle.ts +++ b/web/app/cad/craft/wizard/wizardBundle.ts @@ -183,15 +183,12 @@ export function activate(ctx: ApplicationContext) { ctx.wizardService = services.wizard = wizardService; } -export interface WizardPluginContext { +export interface WizardBundleContext { wizardService: WizardService } -export const outputContextSpec: ContextSpec = { - wizardService: 'required' -} - - function applyOverrides(params, initialOverrides) { Object.assign(params, initialOverrides); } + +export const BundleName = "@Wizard"; \ No newline at end of file diff --git a/web/app/cad/craft/wizard/wizardSelectionPlugin.ts b/web/app/cad/craft/wizard/wizardSelectionBundle.ts similarity index 85% rename from web/app/cad/craft/wizard/wizardSelectionPlugin.ts rename to web/app/cad/craft/wizard/wizardSelectionBundle.ts index 9bcba628..5202ad81 100644 --- a/web/app/cad/craft/wizard/wizardSelectionPlugin.ts +++ b/web/app/cad/craft/wizard/wizardSelectionBundle.ts @@ -1,34 +1,29 @@ -import {FACE, SHELL} from 'cad/model/entities'; +import {FACE} from 'cad/model/entities'; import {OperationRequest} from "cad/craft/craftBundle"; import {ParamsPath, WizardService} from "cad/craft/wizard/wizardTypes"; import {OperationParamPrimitive} from "cad/craft/schema/schema"; import {EntityReference} from "cad/craft/operationBundle"; import {Bundle} from "bundler/bundleSystem"; -import {MarkerPluginContext} from "cad/scene/selectionMarker/markerPlugin"; -import {WizardPluginContext} from "cad/craft/wizard/wizardBundle"; -import {PickControlPluginContext} from "cad/scene/controls/pickControlPlugin"; +import {MarkerBundleContext} from "cad/scene/selectionMarker/markerBundle"; +import {WizardBundleContext} from "cad/craft/wizard/wizardBundle"; +import {PickControlBundleContext} from "cad/scene/controls/pickControlBundle"; import _ from "lodash"; import {MObject} from "cad/model/mobject"; -export type WizardSelectionPluginInputContext = MarkerPluginContext & WizardPluginContext & PickControlPluginContext; +type WizardSelectionBundleActivationContext = MarkerBundleContext & WizardBundleContext & PickControlBundleContext; -export interface WizardSelectionPluginContext { +export interface WizardSelectionBundleContext { } -export type WizardSelectionWorkingContext = WizardSelectionPluginInputContext & WizardSelectionPluginContext; +export type WizardSelectionBundleWorkingContext = WizardSelectionBundleActivationContext & WizardSelectionBundleContext; -export const WizardSelectionPlugin: Bundle = { +export const WizardSelectionBundle: Bundle = { - inputContextSpec: { - markerService: 'required', - pickControlService: 'required', - wizardService: 'required' - }, + activationDependencies: [ + '@Marker', '@Wizard', '@PickControl' + ], - outputContextSpec: { - }, - - activate(ctx: WizardSelectionWorkingContext) { + activate(ctx: WizardSelectionBundleWorkingContext) { const wizardService = ctx.wizardService; let wizardPickHandler = null; @@ -70,6 +65,8 @@ export const WizardSelectionPlugin: Bundle = { - appTabsService: 'required' -} +export const BundleName = "@AppTabs"; \ No newline at end of file diff --git a/web/app/cad/dom/components/PlugableControlBar.jsx b/web/app/cad/dom/components/PlugableControlBar.jsx index 2c995d97..48524117 100644 --- a/web/app/cad/dom/components/PlugableControlBar.jsx +++ b/web/app/cad/dom/components/PlugableControlBar.jsx @@ -3,7 +3,7 @@ import ControlBar, {ControlBarButton} from './ControlBar'; import connect from 'ui/connect'; import Fa from 'ui/components/Fa'; import {toIdAndOverrides} from '../../actions/actionRef'; -import {isMenuAction} from '../menu/menuPlugin'; +import {isMenuAction} from '../menu/menuBundle'; import {menuAboveElementHint} from '../menu/menuUtils'; import {useStream} from "ui/effects"; import {ActionButtonBehavior} from "../../actions/ActionButtonBehavior"; diff --git a/web/app/cad/dom/domBundle.ts b/web/app/cad/dom/domBundle.ts index dbbaad82..8cc12363 100644 --- a/web/app/cad/dom/domBundle.ts +++ b/web/app/cad/dom/domBundle.ts @@ -1,6 +1,7 @@ import {contributeComponent} from './components/ContributedComponents'; import {Bundle} from "bundler/bundleSystem"; import {AppTabsService} from "cad/dom/appTabsBundle"; +import {LegacyStructureBundle, LegacyStructureBundleContext} from "cad/context/LegacyStructureBundle"; export interface DomService { @@ -12,29 +13,25 @@ export interface DomService { } -interface DomPluginInputContext { +interface DomBundleActivationContext extends LegacyStructureBundleContext { appTabsService: AppTabsService; - services: any; } -export interface DomPluginContext { +export interface DomBundleContext { domService: DomService; } -type DomPluginWorkingContext = DomPluginInputContext&DomPluginContext; +type DomBundleWorkingContext = DomBundleActivationContext&DomBundleContext; -export const DomBundle: Bundle = { - inputContextSpec: { - appTabsService: 'required', - services: 'required', - }, +export const DomBundle: Bundle = { - outputContextSpec: { - domService: 'required', - }, + activationDependencies: [ + '@AppTabs', + LegacyStructureBundle.BundleName + ], - activate(ctx: DomPluginInputContext&DomPluginContext) { + activate(ctx: DomBundleWorkingContext) { ctx.domService = { viewerContainer: document.getElementById('viewer-container'), contributeComponent, @@ -56,6 +53,8 @@ export const DomBundle: Bundle = { - uiService: undefined -} - +export const BundleName = "@UI"; diff --git a/web/app/cad/exportPlugin.js b/web/app/cad/exportBundle.js similarity index 97% rename from web/app/cad/exportPlugin.js rename to web/app/cad/exportBundle.js index 8616dbc4..66d209fc 100644 --- a/web/app/cad/exportPlugin.js +++ b/web/app/cad/exportBundle.js @@ -1,6 +1,8 @@ import {STLExporter} from './stl/stlExporter'; import exportTextData from 'gems/exportTextData'; +export const BundleName = "@Export"; + export function activate(ctx) { function toStlAsciiString() { diff --git a/web/app/cad/exposure/exposurePlugin.js b/web/app/cad/exposure/exposureBundle.js similarity index 93% rename from web/app/cad/exposure/exposurePlugin.js rename to web/app/cad/exposure/exposureBundle.js index 4387e1c7..574c6b2d 100644 --- a/web/app/cad/exposure/exposurePlugin.js +++ b/web/app/cad/exposure/exposureBundle.js @@ -1,6 +1,8 @@ import exposure from './exposure'; import {MBrepShell} from '../model/mshell'; +export const BundleName = "@Exposure"; + /* * exposure stands for the Test Program Interface */ diff --git a/web/app/cad/expressions/expressionsBundle.ts b/web/app/cad/expressions/expressionsBundle.ts index d745277b..4722d609 100644 --- a/web/app/cad/expressions/expressionsBundle.ts +++ b/web/app/cad/expressions/expressionsBundle.ts @@ -1,8 +1,8 @@ import {merge, state, StateStream, Stream} from 'lstream'; import {indexArray} from 'gems/iterables'; import {CoreContext} from "cad/context"; -import {ContextSpec} from "bundler/bundleSystem"; +export const BundleName = "@Expressions"; export function activate(ctx: CoreContext) { let _evaluateExpression: (string) => any = () => {}; @@ -120,9 +120,3 @@ export interface ExpressionBundleContext { expressionService: ExpressionService; } - -export const outputContextSpec: ContextSpec = { - expressionService: 'required' -} - - diff --git a/web/app/cad/init/lifecyclePlugin.js b/web/app/cad/init/lifecycleBundle.js similarity index 96% rename from web/app/cad/init/lifecyclePlugin.js rename to web/app/cad/init/lifecycleBundle.js index 788f7948..3dd4d921 100644 --- a/web/app/cad/init/lifecyclePlugin.js +++ b/web/app/cad/init/lifecycleBundle.js @@ -37,3 +37,5 @@ export function activate(ctx) { } } } + +export const BundleName = "@Lifecycle"; diff --git a/web/app/cad/init/startApplication.js b/web/app/cad/init/startApplication.js index a7a64fed..40760a41 100644 --- a/web/app/cad/init/startApplication.js +++ b/web/app/cad/init/startApplication.js @@ -1,141 +1,117 @@ -import * as LifecyclePlugin from './lifecyclePlugin'; -import * as AppTabsPlugin from '../dom/appTabsBundle'; +import * as LifecycleBundle from './lifecycleBundle'; +import * as AppTabsBundle from '../dom/appTabsBundle'; import {DomBundle} from '../dom/domBundle'; -import * as PickControlPlugin from '../scene/controls/pickControlPlugin'; -import * as MouseEventSystemPlugin from '../scene/controls/mouseEventSystemPlugin'; -import * as ScenePlugin from '../scene/sceneBundle'; -import * as MarkerPlugin from '../scene/selectionMarker/markerPlugin'; -import * as ActionSystemPlugin from '../actions/actionSystemBundle'; -import * as UiPlugin from '../dom/uiBundle'; -import * as MenuPlugin from '../dom/menu/menuPlugin'; -import * as KeyboardPlugin from '../keyboard/keyboardPlugin'; -import * as WizardPlugin from '../craft/wizard/wizardBundle'; -import {WizardSelectionPlugin} from '../craft/wizard/wizardSelectionPlugin'; -import * as PreviewPlugin from '../preview/previewPlugin'; -import * as OperationPlugin from '../craft/operationBundle'; -import * as ExtensionsPlugin from '../craft/extensionsPlugin'; -import * as CadRegistryPlugin from '../craft/cadRegistryBundle'; -import * as CraftPlugin from '../craft/craftBundle'; -import * as RemotePartsPlugin from '../partImport/remotePartsBundle'; -import * as CraftUiPlugin from '../craft/craftUiPlugin'; -import * as StoragePlugin from '../storage/storageBundle'; -import * as ProjectPlugin from '../projectBundle'; -import * as ProjectManagerPlugin from '../projectManager/projectManagerBundle'; -import * as SketcherPlugin from '../sketch/sketcherBundle'; -import * as SketcherStoragePlugin from '../sketch/sketchStorageBundle'; -import * as ExportPlugin from '../exportPlugin'; -import * as ExposurePlugin from '../exposure/exposurePlugin'; -import {ViewSyncPlugin} from '../scene/viewSyncPlugin'; +import * as PickControlBundle from '../scene/controls/pickControlBundle'; +import * as MouseEventSystemBundle from '../scene/controls/mouseEventSystemBundle'; +import * as SceneBundle from '../scene/sceneBundle'; +import * as MarkerBundle from '../scene/selectionMarker/markerBundle'; +import * as ActionSystemBundle from '../actions/actionSystemBundle'; +import * as UIBundle from '../dom/uiBundle'; +import * as MenuBundle from '../dom/menu/menuBundle'; +import * as KeyboardBundle from '../keyboard/keyboardBundle'; +import * as WizardBundle from '../craft/wizard/wizardBundle'; +import {WizardSelectionBundle} from '../craft/wizard/wizardSelectionBundle'; +import * as PreviewBundle from '../preview/previewBundle'; +import * as OperationBundle from '../craft/operationBundle'; +import * as ExtensionsBundle from '../craft/extensionsBundle'; +import * as CadRegistryBundle from '../craft/cadRegistryBundle'; +import * as CraftBundle from '../craft/craftBundle'; +import * as RemotePartsBundle from '../partImport/remotePartsBundle'; +import * as CraftUIBundle from '../craft/craftUIBundle'; +import * as StorageBundle from '../storage/storageBundle'; +import * as ProjectBundle from '../projectBundle'; +import * as ProjectManagerBundle from '../projectManager/projectManagerBundle'; +import * as SketcherBundle from '../sketch/sketcherBundle'; +import * as SketcherStorageBundle from '../sketch/sketchStorageBundle'; +import * as ExportBundle from '../exportBundle'; +import * as ExposureBundle from '../exposure/exposureBundle'; +import {ViewSyncBundle} from '../scene/viewSyncBundle'; import * as EntityContextPlugin from '../scene/entityContextBundle'; -import * as OCCTPlugin from '../craft/e0/occtBundle'; - -import context from 'cad/context'; - +import * as OCCTBundle from '../craft/e0/occtBundle'; import startReact from "../dom/startReact"; -import * as UIConfigPlugin from "../workbench/uiConfigPlugin"; -import * as DebugPlugin from "../debugPlugin"; -import * as ExpressionsPlugin from "../expressions/expressionsBundle"; +import * as UIConfigBundle from "../workbench/uiConfigBundle"; +import * as DebugBundle from "../debugBundle"; +import * as ExpressionsBundle from "../expressions/expressionsBundle"; import {WorkbenchBundle} from "../workbench/workbenchBundle"; -import * as LocationPlugin from "../location/LocationBundle"; -import * as AssemblyPlugin from "../assembly/assemblyBundle"; -import {WorkbenchesLoaderPlugin} from "cad/workbench/workbenchesLoaderPlugin"; -import {BundleSystem} from "bundler/bundleSystem"; +import * as LocationBundle from "../location/LocationBundle"; +import * as AssemblyBundle from "../assembly/assemblyBundle"; +import {WorkbenchesLoaderBundle} from "cad/workbench/workbenchesLoaderBundle"; import {AttributesBundle} from "cad/attributes/attributesBundle"; import {HighlightBundle} from "cad/scene/highlightBundle"; +import {LegacyStructureBundle} from "cad/context/LegacyStructureBundle"; +import context from "cad/context"; +import {BundleSystem} from "bundler/bundleSystem"; export default function startApplication(callback) { - let preUIPlugins = [ - LifecyclePlugin, - ProjectPlugin, - StoragePlugin, - AppTabsPlugin, - ActionSystemPlugin, - UiPlugin, - MenuPlugin, - KeyboardPlugin, - ExpressionsPlugin, - OperationPlugin, - CraftPlugin, - ExtensionsPlugin, - SketcherStoragePlugin, - WizardPlugin, - PreviewPlugin, - CraftUiPlugin, - CadRegistryPlugin, - ExportPlugin, - ExposurePlugin, - OCCTPlugin, - ProjectManagerPlugin + let preUIBundles = [ + LifecycleBundle, + ProjectBundle, + StorageBundle, + AppTabsBundle, + ActionSystemBundle, + UIBundle, + MenuBundle, + KeyboardBundle, + ExpressionsBundle, + OperationBundle, + CraftBundle, + ExtensionsBundle, + SketcherStorageBundle, + WizardBundle, + PreviewBundle, + CraftUIBundle, + CadRegistryBundle, + ExportBundle, + ExposureBundle, + OCCTBundle, + ProjectManagerBundle ]; - let plugins = [ + let bundles = [ DomBundle, - ScenePlugin, - MouseEventSystemPlugin, - MarkerPlugin, - PickControlPlugin, + SceneBundle, + MouseEventSystemBundle, + MarkerBundle, + PickControlBundle, EntityContextPlugin, - WorkbenchesLoaderPlugin, + WorkbenchesLoaderBundle, WorkbenchBundle, - SketcherPlugin, - UIConfigPlugin, - DebugPlugin, - LocationPlugin, - AssemblyPlugin, - RemotePartsPlugin, - ViewSyncPlugin, - WizardSelectionPlugin, + SketcherBundle, + UIConfigBundle, + DebugBundle, + LocationBundle, + AssemblyBundle, + RemotePartsBundle, + ViewSyncBundle, + WizardSelectionBundle, AttributesBundle, HighlightBundle ]; - let allPlugins = [...preUIPlugins, ...plugins]; - const pluginSystem = new BundleSystem(context); - context.pluginSystem = pluginSystem; + const allBundle = [...preUIBundles, ...bundles]; + const bundleSystem = new BundleSystem(context); - defineStreams(allPlugins, context); - - activatePlugins(preUIPlugins, pluginSystem); + bundleSystem.activate(LegacyStructureBundle); + allBundle.forEach(bundle => { + if (bundle.defineStreams) { + bundle.defineStreams(context); + } + }); + + preUIBundles.forEach(bundle => { + bundleSystem.activate(bundle); + }); startReact(context, () => { - activatePlugins(plugins, pluginSystem); + bundles.forEach(bundle => { + bundleSystem.activate(bundle); + }); context.services.lifecycle.declareAppReady(); - context.services.viewer.render(); + context.viewer.render(); callback(context); }); -} - -export function defineStreams(plugins, context) { - for (let plugin of plugins) { - if (plugin.defineStreams) { - plugin.defineStreams(context); - } - } -} - -function adapter(oldStylePlugin) { - - if (oldStylePlugin.inputContextSpec) { - return oldStylePlugin; - } - - return { - - inputContextSpec: {}, - - outputContextSpec: {}, - - activate: oldStylePlugin.activate, - - deactivate: ctx => {} - - } - -} - -export function activatePlugins(plugins, pluginSystem) { - for (let plugin of plugins) { - pluginSystem.load(adapter(plugin)); - } + + bundleSystem.checkDanglingBundles(); + bundleSystem.checkPerfectLoad(); } diff --git a/web/app/cad/keyboard/keyboardPlugin.js b/web/app/cad/keyboard/keyboardBundle.js similarity index 90% rename from web/app/cad/keyboard/keyboardPlugin.js rename to web/app/cad/keyboard/keyboardBundle.js index 2a914d6e..d2f2f543 100644 --- a/web/app/cad/keyboard/keyboardPlugin.js +++ b/web/app/cad/keyboard/keyboardBundle.js @@ -1,8 +1,10 @@ import Mousetrap from 'mousetrap'; import DefaultKeymap from './keymaps/default'; -import {isMenuAction} from '../dom/menu/menuPlugin'; +import {isMenuAction} from '../dom/menu/menuBundle'; import {state} from 'lstream'; +export const BundleName = "@Keyboard"; + export function activate(ctx) { const {services, streams} = ctx; diff --git a/web/app/cad/location/LocationBundle.ts b/web/app/cad/location/LocationBundle.ts index 693c5c2f..f75cccd4 100644 --- a/web/app/cad/location/LocationBundle.ts +++ b/web/app/cad/location/LocationBundle.ts @@ -2,7 +2,6 @@ import {state, StateStream} from "lstream"; import {ApplicationContext} from "cad/context"; import {MShell} from "../model/mshell"; import {LocationDialog} from "./LocationDialog"; -import {ContextSpec} from "bundler/bundleSystem"; export function activate(ctx: ApplicationContext) { @@ -41,7 +40,4 @@ export interface LocationBundleContext { locationService: LocationService; } -export const outputContextSpec: ContextSpec = { - locationService: 'required' -} - +export const BundleName = "@Location"; \ No newline at end of file diff --git a/web/app/cad/partImport/remotePartsBundle.ts b/web/app/cad/partImport/remotePartsBundle.ts index 2a5b0482..c7fe7b35 100644 --- a/web/app/cad/partImport/remotePartsBundle.ts +++ b/web/app/cad/partImport/remotePartsBundle.ts @@ -1,22 +1,18 @@ -import {ApplicationContext, CoreContext} from "cad/context"; +import {ApplicationContext} from "cad/context"; import {Repository} from "../repository/repository"; import {IconType} from "react-icons"; import {Emitter, stream} from "lstream"; import {ShowDialogRequest} from "ui/showDialogRequest"; -import {CatalogPartChooser} from "./ui/CatalogPartChooser"; -import {ImportPartOperation} from "./importPartOperation/importPartOperation"; import {MObject, MObjectIdGenerator} from "../model/mobject"; -import {WEB_CAD_ORG_PARTS_REPO, WEB_CAD_ORG_COMMONS_CATALOG} from "./remotePartsConfig"; import {indexById} from "gems/iterables"; import {ModelBundle} from "../projectManager/projectManagerBundle"; import {PartRepository} from "./partRepository"; import {initProjectService} from "../projectBundle"; -import {activate as activateCraftPlugin} from '../craft/craftBundle'; -import {activate as activateExpressionsPlugin} from '../expressions/expressionsBundle'; -import {activate as activateCadRegistryPlugin} from '../craft/cadRegistryBundle'; -import {activate as activateStoragePlugin} from '../storage/storageBundle'; -import {activate as activateSketchStoragePlugin} from '../sketch/sketchStorageBundle'; -import {ContextSpec} from "bundler/bundleSystem"; +import {activate as activateCraftBundle} from '../craft/craftBundle'; +import {activate as activateExpressionsBundle} from '../expressions/expressionsBundle'; +import {activate as activateCadRegistryBundle} from '../craft/cadRegistryBundle'; +import {activate as activateStorageBundle} from '../storage/storageBundle'; +import {activate as activateSketchStorageBundle} from '../sketch/sketchStorageBundle'; export function activate(ctx: ApplicationContext) { @@ -75,12 +71,12 @@ export function activate(ctx: ApplicationContext) { }; initProjectService(evalContext, partRef, {}); - activateStoragePlugin(evalContext); - activateSketchStoragePlugin(evalContext); - activateExpressionsPlugin(evalContext); - activateCraftPlugin(evalContext); + activateStorageBundle(evalContext); + activateSketchStorageBundle(evalContext); + activateExpressionsBundle(evalContext); + activateCraftBundle(evalContext); // @ts-ignore - activateCadRegistryPlugin(evalContext); + activateCadRegistryBundle(evalContext); // initProject(evalContext, partRef, {}); evalContext.expressionService.load(projectModel.expressions); @@ -185,7 +181,5 @@ export interface RemotePartsBundleContext { remotePartsService: RemotePartsService; } -export const outputContextSpec: ContextSpec = { - remotePartsService: 'required' -} +export const BundleName = "@RemoteParts"; diff --git a/web/app/cad/plugins.js b/web/app/cad/plugins.js deleted file mode 100644 index 15ae0402..00000000 --- a/web/app/cad/plugins.js +++ /dev/null @@ -1,11 +0,0 @@ -import * as DomPlugin from './dom/domBundle'; -import * as PickControlPlugin from './scene/controls/pickControlPlugin'; -import * as ScenePlugin from './scene/sceneBundle'; -import * as SelectionMarkerPlugin from './scene/selectionMarker/markerPlugin'; - -export default [ - DomPlugin, - ScenePlugin, - PickControlPlugin, - SelectionMarkerPlugin -] \ No newline at end of file diff --git a/web/app/cad/preview/previewPlugin.ts b/web/app/cad/preview/previewBundle.ts similarity index 97% rename from web/app/cad/preview/previewPlugin.ts rename to web/app/cad/preview/previewBundle.ts index 2a4c2385..4cd7afa1 100644 --- a/web/app/cad/preview/previewPlugin.ts +++ b/web/app/cad/preview/previewBundle.ts @@ -1,6 +1,8 @@ import {createPreviewer} from './scenePreviewer'; import {ApplicationContext} from "cad/context"; +export const BundleName = "@Preview"; + export function activate(ctx: ApplicationContext) { let previewer = null; ctx.wizardService.materializedWorkingRequest$.attach(materializedWorkingRequest => { diff --git a/web/app/cad/projectBundle.ts b/web/app/cad/projectBundle.ts index c66eee75..5f4667e7 100644 --- a/web/app/cad/projectBundle.ts +++ b/web/app/cad/projectBundle.ts @@ -5,7 +5,6 @@ import {ApplicationContext} from "cad/context"; import {ProjectModel} from "./projectManager/projectManagerBundle"; import {DebugMode$} from "debugger/Debugger"; import {fillUpMissingFields} from "cad/craft/schema/initializeBySchema"; -import {ContextSpec} from "bundler/bundleSystem"; export const STORAGE_GLOBAL_PREFIX = 'TCAD'; export const PROJECTS_PREFIX = `${STORAGE_GLOBAL_PREFIX}.projects.`; @@ -192,8 +191,5 @@ export interface ProjectBundleContext { } -export const outputContextSpec: ContextSpec = { - projectService: 'required' -} - +export const BundleName = "@Project"; diff --git a/web/app/cad/projectManager/projectManagerBundle.ts b/web/app/cad/projectManager/projectManagerBundle.ts index b67f51d3..e9abc8de 100644 --- a/web/app/cad/projectManager/projectManagerBundle.ts +++ b/web/app/cad/projectManager/projectManagerBundle.ts @@ -5,7 +5,6 @@ import {SketchFormat_V3} from "sketcher/io"; import {ApplicationContext} from "cad/context"; import {OperationRequest} from "../craft/craftBundle"; import {AssemblyConstraintDefinition} from "cad/assembly/assemblyConstraint"; -import {ContextSpec} from "bundler/bundleSystem"; export function activate(ctx: ApplicationContext) { @@ -253,6 +252,4 @@ export interface ProjectManagerBundleContext { projectManager: IProjectManager; } -export const outputContextSpec: ContextSpec = { - projectManager: 'required' -} +export const BundleName = "@ProjectManager"; diff --git a/web/app/cad/repository/repositoryPlugin.ts b/web/app/cad/repository/repositoryPlugin.ts deleted file mode 100644 index 908e5c1c..00000000 --- a/web/app/cad/repository/repositoryPlugin.ts +++ /dev/null @@ -1,3 +0,0 @@ -import {GitHubRepoRepository} from "./GitHubRepoRepository"; - -new GitHubRepoRepository('xibyte/jsketcher', 'master'); \ No newline at end of file diff --git a/web/app/cad/scene/controls/mouseEventSystemPlugin.js b/web/app/cad/scene/controls/mouseEventSystemBundle.js similarity index 99% rename from web/app/cad/scene/controls/mouseEventSystemPlugin.js rename to web/app/cad/scene/controls/mouseEventSystemBundle.js index 129f6af8..7f260619 100644 --- a/web/app/cad/scene/controls/mouseEventSystemPlugin.js +++ b/web/app/cad/scene/controls/mouseEventSystemBundle.js @@ -2,6 +2,8 @@ import {printRaycastDebugInfo, RayCastDebugInfo} from "./rayCastDebug"; import {LOG_FLAGS} from "cad/logFlags"; import {stream} from "lstream"; +export const BundleName = "@MouseEventSystem"; + const MouseStates = { IDLE: 'IDLE', DOWN: 'DOWN' diff --git a/web/app/cad/scene/controls/pickControlPlugin.ts b/web/app/cad/scene/controls/pickControlBundle.ts similarity index 99% rename from web/app/cad/scene/controls/pickControlPlugin.ts rename to web/app/cad/scene/controls/pickControlBundle.ts index 010368e5..4eddd783 100644 --- a/web/app/cad/scene/controls/pickControlPlugin.ts +++ b/web/app/cad/scene/controls/pickControlBundle.ts @@ -29,7 +29,7 @@ export interface PickControlService { simulatePickFromRay() } -export interface PickControlPluginContext { +export interface PickControlBundleContext { pickControlService: PickControlService; } @@ -339,4 +339,6 @@ function printPickInfo(model, rayCastData?) { console.log('POINT: ' + pt.x + ', ' + pt.y + ',' + pt.z); printRaycastDebugInfo('selection', rayCastData); } -} \ No newline at end of file +} + +export const BundleName = "@PickControl"; \ No newline at end of file diff --git a/web/app/cad/scene/entityContextBundle.ts b/web/app/cad/scene/entityContextBundle.ts index eb7efa48..2dd0969d 100644 --- a/web/app/cad/scene/entityContextBundle.ts +++ b/web/app/cad/scene/entityContextBundle.ts @@ -1,9 +1,8 @@ -import {combine, state, StateStream, Stream} from 'lstream'; +import {combine, state, StateStream} from 'lstream'; import {addToListInMap, EMPTY_ARRAY} from 'gems/iterables'; import {DATUM, EDGE, FACE, LOOP, SHELL, SKETCH_OBJECT} from '../model/entities'; import {MObject} from "cad/model/mobject"; -import {ContextSpec} from "bundler/bundleSystem"; export const SELECTABLE_ENTITIES = [FACE, EDGE, SKETCH_OBJECT, DATUM, SHELL]; @@ -72,6 +71,4 @@ export interface EntityContextBundleContext { }; } -export const outputContextSpec: ContextSpec = { - entityContextService: 'required' -} +export const BundleName = "@EntityContext"; diff --git a/web/app/cad/scene/highlightBundle.ts b/web/app/cad/scene/highlightBundle.ts index 3c3fbeb8..5b0cf6f2 100644 --- a/web/app/cad/scene/highlightBundle.ts +++ b/web/app/cad/scene/highlightBundle.ts @@ -1,7 +1,6 @@ import {Bundle} from "bundler/bundleSystem"; import {combine, merge, Stream, stream} from "lstream"; import Viewer from "cad/scene/viewer"; -import {ScanStream} from "lstream/scan"; export class HighlightService { @@ -43,30 +42,23 @@ export class HighlightService { } -interface HighlightPluginInputContext { +interface HighlightBundleInputContext { viewer: Viewer; } -export interface HighlightPluginContext { +export interface HighlightBundleContext { highlightService: HighlightService; } -type HighlightPluginWorkingContext = HighlightPluginInputContext&HighlightPluginContext; +type HighlightBundleWorkingContext = HighlightBundleInputContext&HighlightBundleContext; -export const HighlightBundle: Bundle = { +export const HighlightBundle: Bundle = { - inputContextSpec: { - viewer: 'required', - }, - - outputContextSpec: { - highlightService: 'required', - }, - - activate(ctx: HighlightPluginWorkingContext) { + activate(ctx: HighlightBundleWorkingContext) { ctx.highlightService = new HighlightService(ctx.viewer); }, + BundleName: "@Highlight", } diff --git a/web/app/cad/scene/sceneBundle.ts b/web/app/cad/scene/sceneBundle.ts index 25cf851d..1ba85da8 100644 --- a/web/app/cad/scene/sceneBundle.ts +++ b/web/app/cad/scene/sceneBundle.ts @@ -1,8 +1,6 @@ import Viewer from './viewer'; import CadScene from './cadScene'; -import {externalState, stream} from 'lstream'; import {ApplicationContext} from "cad/context"; -import {ContextSpec} from "bundler/bundleSystem"; export function activate(ctx: ApplicationContext) { const {services} = ctx; @@ -58,7 +56,4 @@ export interface SceneBundleContext { viewer: Viewer; } -export const outputContextSpec: ContextSpec = { - cadScene: 'required', - viewer: 'required' -} +export const BundleName = "@Scene"; \ No newline at end of file diff --git a/web/app/cad/scene/selectionMarker/markerPlugin.ts b/web/app/cad/scene/selectionMarker/markerBundle.ts similarity index 97% rename from web/app/cad/scene/selectionMarker/markerPlugin.ts rename to web/app/cad/scene/selectionMarker/markerBundle.ts index a55495da..3c5b4140 100644 --- a/web/app/cad/scene/selectionMarker/markerPlugin.ts +++ b/web/app/cad/scene/selectionMarker/markerBundle.ts @@ -2,6 +2,8 @@ import {OrderedMap} from 'gems/linkedMap'; import {eventStream, Stream} from 'lstream'; import {MObject} from "cad/model/mobject"; +export const BundleName = "@Marker"; + export interface MarkerService { clear(); @@ -24,7 +26,7 @@ export interface MarkerService { $markedEntities: Stream } -export interface MarkerPluginContext { +export interface MarkerBundleContext { markerService: MarkerService; } diff --git a/web/app/cad/scene/viewSyncPlugin.js b/web/app/cad/scene/viewSyncBundle.js similarity index 89% rename from web/app/cad/scene/viewSyncPlugin.js rename to web/app/cad/scene/viewSyncBundle.js index 0f1dae29..75a935e4 100644 --- a/web/app/cad/scene/viewSyncPlugin.js +++ b/web/app/cad/scene/viewSyncBundle.js @@ -7,16 +7,17 @@ import {MShell} from '../model/mshell'; import {MDatum} from '../model/mdatum'; import DatumView from './views/datumView'; import {View} from './views/view'; +import {HighlightBundle} from "cad/scene/highlightBundle"; +import {AttributesBundle} from "cad/attributes/attributesBundle"; -export const ViewSyncPlugin = { +export const ViewSyncBundle = { - inputContextSpec: { - highlightService: 'required', - attributesService: 'required', - }, + BundleName: "@ViewSync", - outputContextSpec: { - }, + activationDependencies: [ + HighlightBundle.BundleName, + AttributesBundle.BundleName + ], activate(ctx) { let {streams} = ctx; diff --git a/web/app/cad/sketch/sketchStorageBundle.ts b/web/app/cad/sketch/sketchStorageBundle.ts index 46aa0735..d980070c 100644 --- a/web/app/cad/sketch/sketchStorageBundle.ts +++ b/web/app/cad/sketch/sketchStorageBundle.ts @@ -74,8 +74,5 @@ export interface SketchStorageBundleContext { sketchStorageService: SketchStorageService; } -export const outputContextSpec: ContextSpec = { - sketchStorageService: 'required' -} - +export const BundleName = "@SketchStorage"; diff --git a/web/app/cad/sketch/sketcherBundle.ts b/web/app/cad/sketch/sketcherBundle.ts index 36677cbf..809cba59 100644 --- a/web/app/cad/sketch/sketcherBundle.ts +++ b/web/app/cad/sketch/sketcherBundle.ts @@ -206,6 +206,4 @@ export interface SketcherBundleContext { sketcherService: SketcherService; } -export const outputContextSpec: ContextSpec = { - sketcherService: 'required' -} +export const BundleName = "@Sketcher"; diff --git a/web/app/cad/storage/storageBundle.ts b/web/app/cad/storage/storageBundle.ts index ed45c858..12509c3e 100644 --- a/web/app/cad/storage/storageBundle.ts +++ b/web/app/cad/storage/storageBundle.ts @@ -88,6 +88,4 @@ export interface StorageBundleContext { storageService: StorageService; } -export const outputContextSpec: ContextSpec = { - storageService: 'required' -} +export const BundleName = "@Storage"; \ No newline at end of file diff --git a/web/app/cad/workbench/uiConfigPlugin.js b/web/app/cad/workbench/uiConfigBundle.js similarity index 97% rename from web/app/cad/workbench/uiConfigPlugin.js rename to web/app/cad/workbench/uiConfigBundle.js index 3a172daf..081f51df 100644 --- a/web/app/cad/workbench/uiConfigPlugin.js +++ b/web/app/cad/workbench/uiConfigBundle.js @@ -10,6 +10,8 @@ import {SelectionView} from "../dom/components/SelectionView"; import {GrSelect} from "react-icons/gr"; import {Explorer} from "cad/dom/components/Explorer"; +export const BundleName = "@UIConfig"; + export function activate(ctx) { const {services, streams} = ctx; streams.ui.controlBars.left.value = ['menu.file', 'menu.craft', 'menu.boolean', 'menu.primitives', 'menu.views', 'menu.viewModes', 'Donate', 'GitHub']; diff --git a/web/app/cad/workbench/workbenchBundle.ts b/web/app/cad/workbench/workbenchBundle.ts index 9106603a..ccce2d54 100644 --- a/web/app/cad/workbench/workbenchBundle.ts +++ b/web/app/cad/workbench/workbenchBundle.ts @@ -3,25 +3,12 @@ import {WorkbenchService} from "cad/workbench/workbenchService"; import {CurrentWorkbenchIcon} from "cad/workbench/CurrentWorkbenchIcon"; import {Bundle} from "bundler/bundleSystem"; - export interface WorkbenchBundleContext { workbenchService: WorkbenchService; } -export const WorkbenchBundle: Bundle = { - - deactivate(ctx: ApplicationContext & WorkbenchBundleContext) { - }, - - inputContextSpec: { - - }, - - outputContextSpec: { - workbenchService: 'required' - }, - +export const WorkbenchBundle: Bundle = { activate(ctx: ApplicationContext) { @@ -40,6 +27,8 @@ export const WorkbenchBundle: Bundle } } ]); - } + }, + + BundleName: "@Workbench", } diff --git a/web/app/cad/workbench/workbenchesLoaderPlugin.ts b/web/app/cad/workbench/workbenchesLoaderBundle.ts similarity index 71% rename from web/app/cad/workbench/workbenchesLoaderPlugin.ts rename to web/app/cad/workbench/workbenchesLoaderBundle.ts index 17876a82..1db5ed95 100644 --- a/web/app/cad/workbench/workbenchesLoaderPlugin.ts +++ b/web/app/cad/workbench/workbenchesLoaderBundle.ts @@ -8,29 +8,29 @@ import {Bundle} from "bundler/bundleSystem"; import {WorkbenchService} from "cad/workbench/workbenchService"; import {OperationService} from "cad/craft/operationBundle"; -export interface WorkbenchesLoaderInputContext { +interface WorkbenchesLoaderActivationContext { workbenchService: WorkbenchService, operationService: OperationService } -export const WorkbenchesLoaderPlugin: Bundle = { +type WorkbenchesLoaderWorkingContext = WorkbenchesLoaderActivationContext; - inputContextSpec: { - workbenchService: 'required', - operationService: 'required' - }, +export const WorkbenchesLoaderBundle: Bundle = { - outputContextSpec: {}, + activationDependencies: [ + '@Workbench', '@Operation' + ], - activate(ctx) { + activate(ctx: WorkbenchesLoaderWorkingContext) { registerCoreOperations(ctx); WorkbenchRegistry.forEach(wConfig => ctx.workbenchService.registerWorkbench(wConfig)); ctx.workbenchService.switchToDefaultWorkbench(); - } + }, + BundleName: "@WorkbenchesLoader", } -function registerCoreOperations(ctx: WorkbenchesLoaderInputContext) { +function registerCoreOperations(ctx: WorkbenchesLoaderActivationContext) { ctx.operationService.registerOperations([ planeOperation,