-
Notifications
You must be signed in to change notification settings - Fork 408
/
Copy pathPage.tsx
137 lines (134 loc) · 4.48 KB
/
Page.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import * as React from "react";
import { Action, Base, IAction, PageModel, SurveyModel } from "survey-core";
import {
attachKey2click,
Popup,
SurveyActionBar,
ReactElementFactory,
SurveyPage,
SvgIcon,
SurveyElementBase
} from "survey-react-ui";
import { CreatorModelElement } from "../ModelElement";
import {
SurveyCreatorModel,
PageAdorner,
SurveyHelper,
toggleHovered
} from "survey-creator-core";
import { ReactMouseEvent } from "../events";
interface ICreatorSurveyPageComponentProps {
creator: SurveyCreatorModel;
survey: SurveyModel;
page: PageModel;
isGhost: boolean;
}
export class CreatorSurveyPageComponent extends CreatorModelElement<
ICreatorSurveyPageComponentProps,
any
> {
private model: PageAdorner;
private rootRef: React.RefObject<HTMLDivElement>;
constructor(props: ICreatorSurveyPageComponentProps) {
super(props);
this.rootRef = React.createRef();
}
protected createModel(props: ICreatorSurveyPageComponentProps): void {
if (this.model) {
this.model.attachToUI(props.page, this.rootRef.current);
}
this.model = new PageAdorner(
props.creator,
props.page,
);
this.model.isGhost = this.props.isGhost;
}
shouldComponentUpdate(nextProps: any, nextState: any): boolean {
const res = super.shouldComponentUpdate(nextProps, nextState);
if (this.model) {
this.model.isGhost = this.props.isGhost;
}
return res;
}
public componentDidUpdate(prevProps: any, prevState: any): void {
super.componentDidUpdate(prevProps, prevState);
}
protected getUpdatedModelProps(): string[] {
return ["creator", "page"];
}
protected getStateElement(): Base {
return this.model;
}
componentDidMount() {
super.componentDidMount();
this.model.attachToUI(this.props.page, this.rootRef.current);
this.model.isGhost = this.props.isGhost;
}
componentWillUnmount() {
super.componentWillUnmount();
this.model.detachFromUI();
}
protected canRender(): boolean {
return super.canRender();
}
renderElement(): React.JSX.Element {
if (!this.props.page) return null;
return (
attachKey2click(<div
ref={this.rootRef}
id={this.props.page.id}
data-sv-drop-target-survey-page={this.model.dropTargetName}
className={"svc-page__content " + this.model.css}
onClick={(e) => {
return this.model.select(this.model, new ReactMouseEvent(e));
}}
onDoubleClick={e => this.model.dblclick(e.nativeEvent)}
onMouseLeave={(e) => this.model.hover(e.nativeEvent, e.currentTarget)}
onMouseOver={(e) => this.model.hover(e.nativeEvent, e.currentTarget)}
>
<div className="svc-question__drop-indicator svc-question__drop-indicator--top"></div>
<div className="svc-question__drop-indicator svc-question__drop-indicator--bottom"></div>
{this.renderContent()}
{this.renderPlaceholder()}
{this.renderHeader()}
{this.renderFooter()}
</div>)
);
}
protected renderPlaceholder(): React.JSX.Element {
if (!this.model.showPlaceholder) return null;
return (
<div className="svc-page__placeholder_frame">
<div className="svc-panel__placeholder_frame">
<div className="svc-panel__placeholder">{this.model.placeholderText}</div>
</div>
</div>
);
}
protected renderContent(): React.JSX.Element {
return (<SurveyPage page={this.props.page} survey={this.props.survey} creator={this.props.creator} css={this.model.css}></SurveyPage>);
}
protected renderHeader(): React.JSX.Element {
const actions = (<div className="svc-page__content-actions">
<SurveyActionBar model={this.model.actionContainer}></SurveyActionBar>
{(this.model.topActionContainer.hasActions ? <SurveyActionBar model={this.model.topActionContainer}></SurveyActionBar> : null)}
</div>);
if (this.model.isGhost || !this.model.allowDragging) {
return actions;
}
return (
<div className={"svc-question__drag-area"}
onPointerDown={(event: any) => this.model.onPointerDown(event)}
>
<SvgIcon className="svc-question__drag-element" size={"auto"} iconName={"icon-drag-area-indicator_24x16"}></SvgIcon>
{actions}
</div>
);
}
protected renderFooter(): React.JSX.Element {
return <SurveyActionBar model={this.model.footerActionsBar}></SurveyActionBar>;
}
}
ReactElementFactory.Instance.registerElement("svc-page", (props) => {
return React.createElement(CreatorSurveyPageComponent, props);
});