Browse Source

fix: add option chain for frame

pull/6059/head
danstarns 2 years ago
parent
commit
0551bc8494
  1. 13
      src/canvas/view/FrameView.ts
  2. 5
      src/editor/model/Editor.ts

13
src/canvas/view/FrameView.ts

@ -122,7 +122,7 @@ export default class FrameView extends ModuleView<Frame, HTMLIFrameElement> {
} }
getCanvasModel(): Canvas { getCanvasModel(): Canvas {
return this.em.Canvas.getModel(); return this?.em.Canvas?.getModel();
} }
getWindow() { getWindow() {
@ -344,7 +344,7 @@ export default class FrameView extends ModuleView<Frame, HTMLIFrameElement> {
renderStyles(opts: any = {}) { renderStyles(opts: any = {}) {
const head = this.getHead(); const head = this.getHead();
const canvas = this.getCanvasModel(); const canvas = this.getCanvasModel();
const normalize = (stls: any[]) => const normalize = (stls: any[] = []) =>
stls.map(href => ({ stls.map(href => ({
tag: 'link', tag: 'link',
attributes: { attributes: {
@ -353,7 +353,7 @@ export default class FrameView extends ModuleView<Frame, HTMLIFrameElement> {
}, },
})); }));
const prevStyles = normalize(opts.prev || canvas.previous('styles')); const prevStyles = normalize(opts.prev || canvas.previous('styles'));
const styles = normalize(canvas.get('styles')); const styles = normalize(canvas?.get('styles'));
const toRemove: any[] = []; const toRemove: any[] = [];
const toAdd: any[] = []; const toAdd: any[] = [];
const find = (items: any[], stack: any[], res: any[]) => { const find = (items: any[], stack: any[], res: any[]) => {
@ -375,7 +375,8 @@ export default class FrameView extends ModuleView<Frame, HTMLIFrameElement> {
renderHead() { renderHead() {
const { model, em } = this; const { model, em } = this;
const { root } = model; const { root } = model;
const HeadView = em.Components.getType(typeHead)!.view; const HeadView = em?.Components?.getType(typeHead)!.view;
if(!HeadView) return;
this.headView = new HeadView({ this.headView = new HeadView({
el: this.getHead(), el: this.getHead(),
model: root.head, model: root.head,
@ -475,7 +476,9 @@ export default class FrameView extends ModuleView<Frame, HTMLIFrameElement> {
</style>` </style>`
); );
const { root } = model; const { root } = model;
const { view } = em.Components.getType('wrapper')!; const { view } = em?.Components?.getType('wrapper') || {}
if(!view) return;
this.wrapper = new view({ this.wrapper = new view({
model: root, model: root,
config: { config: {

5
src/editor/model/Editor.ts

@ -894,6 +894,7 @@ export default class EditorModel extends Model {
*/ */
stopDefault(opts = {}) { stopDefault(opts = {}) {
const commands = this.get('Commands'); const commands = this.get('Commands');
if(!commands) return;
const command = commands.get(this.config.defaultCommand); const command = commands.get(this.config.defaultCommand);
if (!command || !this.defaultRunning) return; if (!command || !this.defaultRunning) return;
command.stop(this, this, opts); command.stop(this, this, opts);
@ -1013,11 +1014,11 @@ export default class EditorModel extends Model {
shallow?.destroyAll(); shallow?.destroyAll();
this.stopListening(); this.stopListening();
this.stopDefault(); this.stopDefault();
this.modules (this.modules || [])
.slice() .slice()
.reverse() .reverse()
.forEach(mod => mod.destroy()); .forEach(mod => mod.destroy());
view && view.remove(); view?.remove && view.remove();
this.clear({ silent: true }); this.clear({ silent: true });
this.destroyed = true; this.destroyed = true;
['_config', 'view', '_previousAttributes', '_events', '_listeners'].forEach( ['_config', 'view', '_previousAttributes', '_events', '_listeners'].forEach(

Loading…
Cancel
Save