From 0551bc8494d965124090355120d6a7db2d05029d Mon Sep 17 00:00:00 2001 From: danstarns Date: Fri, 16 Aug 2024 18:49:56 -0700 Subject: [PATCH] fix: add option chain for frame --- src/canvas/view/FrameView.ts | 13 ++++++++----- src/editor/model/Editor.ts | 5 +++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/canvas/view/FrameView.ts b/src/canvas/view/FrameView.ts index 9a1722d8a..da7457c0e 100644 --- a/src/canvas/view/FrameView.ts +++ b/src/canvas/view/FrameView.ts @@ -122,7 +122,7 @@ export default class FrameView extends ModuleView { } getCanvasModel(): Canvas { - return this.em.Canvas.getModel(); + return this?.em.Canvas?.getModel(); } getWindow() { @@ -344,7 +344,7 @@ export default class FrameView extends ModuleView { renderStyles(opts: any = {}) { const head = this.getHead(); const canvas = this.getCanvasModel(); - const normalize = (stls: any[]) => + const normalize = (stls: any[] = []) => stls.map(href => ({ tag: 'link', attributes: { @@ -353,7 +353,7 @@ export default class FrameView extends ModuleView { }, })); const prevStyles = normalize(opts.prev || canvas.previous('styles')); - const styles = normalize(canvas.get('styles')); + const styles = normalize(canvas?.get('styles')); const toRemove: any[] = []; const toAdd: any[] = []; const find = (items: any[], stack: any[], res: any[]) => { @@ -375,7 +375,8 @@ export default class FrameView extends ModuleView { renderHead() { const { model, em } = this; const { root } = model; - const HeadView = em.Components.getType(typeHead)!.view; + const HeadView = em?.Components?.getType(typeHead)!.view; + if(!HeadView) return; this.headView = new HeadView({ el: this.getHead(), model: root.head, @@ -475,7 +476,9 @@ export default class FrameView extends ModuleView { ` ); const { root } = model; - const { view } = em.Components.getType('wrapper')!; + const { view } = em?.Components?.getType('wrapper') || {} + + if(!view) return; this.wrapper = new view({ model: root, config: { diff --git a/src/editor/model/Editor.ts b/src/editor/model/Editor.ts index 96aa11817..2bc6f912c 100644 --- a/src/editor/model/Editor.ts +++ b/src/editor/model/Editor.ts @@ -894,6 +894,7 @@ export default class EditorModel extends Model { */ stopDefault(opts = {}) { const commands = this.get('Commands'); + if(!commands) return; const command = commands.get(this.config.defaultCommand); if (!command || !this.defaultRunning) return; command.stop(this, this, opts); @@ -1013,11 +1014,11 @@ export default class EditorModel extends Model { shallow?.destroyAll(); this.stopListening(); this.stopDefault(); - this.modules + (this.modules || []) .slice() .reverse() .forEach(mod => mod.destroy()); - view && view.remove(); + view?.remove && view.remove(); this.clear({ silent: true }); this.destroyed = true; ['_config', 'view', '_previousAttributes', '_events', '_listeners'].forEach(