Skip to content

Commit d38562f

Browse files
committed
MC-10833: Resolve TypeScript errors
- Implement Preview interfaces to resolve toolbar issues
1 parent d9f31ff commit d38562f

File tree

7 files changed

+62
-10
lines changed

7 files changed

+62
-10
lines changed

app/code/Magento/PageBuilder/view/adminhtml/web/js/content-type-toolbar.js

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/content-type-toolbar.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import ko from "knockout";
88
import events from "Magento_PageBuilder/js/events";
99
import {OptionInterface, ValueInterface} from "./content-type-toolbar.types";
1010
import Preview from "./content-type/preview";
11+
import {PreviewCollectionInterface} from "./content-type/preview-collection.types";
12+
import {PreviewInterface} from "./content-type/preview.types";
1113
import checkStageFullScreen from "./utils/check-stage-full-screen";
1214

1315
/**
@@ -54,10 +56,10 @@ export default class Toolbar {
5456
/**
5557
* Set state based on toolbar focusin event for the preview
5658
*
57-
* @param {Preview} context
59+
* @param {ContentTypeToolbarPreviewInterface} context
5860
* @param {Event} event
5961
*/
60-
public onFocusIn(context: Preview, event: Event): void {
62+
public onFocusIn(context: ContentTypeToolbarPreviewInterface, event: Event): void {
6163
const currentContentTypeTarget = context.toolbar.getCurrentContentTypeTarget();
6264
const toolbarOptions = currentContentTypeTarget.find(".pagebuilder-toolbar-options");
6365
// Change toolbar orientation if overflow on full screen mode
@@ -86,10 +88,10 @@ export default class Toolbar {
8688
/**
8789
* Set state based on toolbar focusout event for the preview
8890
*
89-
* @param {Preview} context
91+
* @param {ContentTypeToolbarPreviewInterface} context
9092
* @param {Event} event
9193
*/
92-
public onFocusOut(context: Preview, event: Event): void {
94+
public onFocusOut(context: ContentTypeToolbarPreviewInterface, event: Event): void {
9395
const currentContentTypeTarget = context.toolbar.getCurrentContentTypeTarget();
9496
currentContentTypeTarget.removeClass("pagebuilder-toolbar-active");
9597
currentContentTypeTarget.find(".pagebuilder-toolbar-options").css("transform", "");
@@ -108,3 +110,13 @@ export default class Toolbar {
108110
return $(`#${this.preview.parent.id}`).find(".pagebuilder-content-type");
109111
}
110112
}
113+
114+
/**
115+
* Preview interface for preview instances implementation the toolbar functionality
116+
*/
117+
export interface ContentTypeToolbarPreviewInterface extends PreviewInterface {
118+
toolbar: Toolbar;
119+
}
120+
export interface ContentTypeToolbarPreviewCollectionInterface extends PreviewCollectionInterface {
121+
toolbar: Toolbar;
122+
}

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/content-type/heading/preview.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import _ from "underscore";
99
import ContentTypeConfigInterface from "../../content-type-config.types";
1010
import HideShowOption from "../../content-type-menu/hide-show-option";
1111
import {OptionsInterface} from "../../content-type-menu/option.types";
12-
import Toolbar from "../../content-type-toolbar";
12+
import Toolbar, {ContentTypeToolbarPreviewInterface} from "../../content-type-toolbar";
1313
import {OptionInterface} from "../../content-type-toolbar.types";
1414
import ContentTypeInterface from "../../content-type.types";
1515
import {ContentTypeDroppedCreateEventParamsInterface} from "../content-type-events.types";
@@ -19,7 +19,7 @@ import BasePreview from "../preview";
1919
/**
2020
* @api
2121
*/
22-
export default class Preview extends BasePreview {
22+
export default class Preview extends BasePreview implements ContentTypeToolbarPreviewInterface {
2323
public toolbar: Toolbar;
2424
private element: Element;
2525

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/content-type/preview-collection.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import ContentTypeCollectionInterface from "../content-type-collection.types";
77
import createContentType from "../content-type-factory";
88
import ContentTypeInterface from "../content-type.types";
99
import Preview from "./preview";
10+
import {PreviewCollectionInterface} from "./preview-collection.types";
1011

11-
export default class PreviewCollection extends Preview {
12+
export default class PreviewCollection extends Preview implements PreviewCollectionInterface {
1213
public parent: ContentTypeCollectionInterface;
1314

1415
/**
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
import ContentTypeCollectionInterface from "../content-type-collection.types";
6+
import PreviewCollection from "./preview-collection";
7+
8+
export interface PreviewCollectionInterface extends PreviewCollection {
9+
parent: ContentTypeCollectionInterface;
10+
}

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/content-type/preview.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ import {get, set} from "../utils/object";
2929
import appearanceConfig from "./appearance-config";
3030
import ObservableUpdater from "./observable-updater";
3131
import ObservableObject from "./observable-updater.types";
32+
import {PreviewInterface} from "./preview.types";
3233

3334
/**
3435
* @api
3536
*/
36-
export default class Preview {
37+
export default class Preview implements PreviewInterface {
3738
public parent: ContentTypeInterface;
3839
public config: ContentTypeConfigInterface;
3940
public data: ObservableObject = {};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
import ContentTypeConfigInterface from "../content-type-config.types";
7+
import ContentTypeInterface from "../content-type.types";
8+
import ObservableObject from "./observable-updater.types";
9+
10+
export interface PreviewInterface {
11+
parent: ContentTypeInterface;
12+
config: ContentTypeConfigInterface;
13+
data: ObservableObject;
14+
displayLabel: KnockoutObservable<string>;
15+
display: KnockoutObservable<boolean>;
16+
wrapperElement: Element;
17+
placeholderCss: KnockoutObservable<object>;
18+
isPlaceholderVisible: KnockoutObservable<boolean>;
19+
isEmpty: KnockoutObservable<boolean>;
20+
/**
21+
* @deprecated
22+
*/
23+
previewData: {[key: string]: any};
24+
}

0 commit comments

Comments
 (0)