-
Notifications
You must be signed in to change notification settings - Fork 2
/
content.ts
243 lines (209 loc) · 7.09 KB
/
content.ts
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
import {BasePart, LazyUiParts, UiPartComponent, UiPartConfig} from '.';
import {ContentFooterConfig, ContentFooterPart} from './content/footer';
import {ContentHeaderConfig, ContentHeaderPart} from './content/header';
import {ContentSectionPart, ContentSectionPartConfig} from './content/section';
import {ContentToolbarConfig, ContentToolbarPart} from './content/toolbar';
import {
EditorConfig,
TemplateResult,
classMap,
html,
repeat,
} from '@blinkk/selective-edit';
import {EditorState, StatePromiseKeys} from '../../state';
import {Base} from '@blinkk/selective-edit/dist/mixins';
import {DataStorage} from '../../../utility/dataStorage';
import {FieldsPart} from './content/sectionFields';
import {HistoryPart} from './content/sectionHistory';
import {ListenersMixin} from '../../../mixin/listeners';
import {MediaPart} from './content/sectionMedia';
import {RawPart} from './content/sectionRaw';
import {templateLoading} from '../../template';
const STORAGE_SETTING_HIGHLIGHT_AUTO = 'live.content.dev.hightlightAuto';
const STORAGE_SETTING_HIGHLIGHT_DIRTY = 'live.content.dev.hightlightDirty';
const STORAGE_SETTING_SHOW_DEEP_LINKS = 'live.content.dev.showDeepLinks';
export const CONTENT_SECTION_ORDER = [
'fields',
// TODO: Media part does not do anything yet.
// 'media',
'raw',
'history',
];
export interface ContentPartConfig extends UiPartConfig {
/**
* Configuration for creating the selective editor.
*/
selectiveConfig: EditorConfig;
state: EditorState;
/**
* Storage class for working with settings.
*/
storage: DataStorage;
}
/**
* Ui part for displaying the content of a file.
*
* The content is broken up into sections which are displayed individually.
* For example, the fields editor, raw editor, or content history.
*/
export class ContentPart extends BasePart implements UiPartComponent {
config: ContentPartConfig;
contentSettings: ContentSettings;
parts: LazyUiParts;
sections: LazyUiParts;
constructor(config: ContentPartConfig) {
super();
this.config = config;
this.contentSettings = new ContentSettings(this.config.storage);
this.sections = new LazyUiParts();
this.sections.register('fields', FieldsPart, {
editor: this.config.editor,
selectiveConfig: this.config.selectiveConfig,
state: this.config.state,
isDefaultSection: true,
storage: this.config.storage,
} as ContentSectionPartConfig);
this.sections.register('media', MediaPart, {
editor: this.config.editor,
selectiveConfig: this.config.selectiveConfig,
state: this.config.state,
storage: this.config.storage,
} as ContentSectionPartConfig);
this.sections.register('raw', RawPart, {
editor: this.config.editor,
selectiveConfig: this.config.selectiveConfig,
state: this.config.state,
storage: this.config.storage,
} as ContentSectionPartConfig);
this.sections.register('history', HistoryPart, {
editor: this.config.editor,
selectiveConfig: this.config.selectiveConfig,
state: this.config.state,
storage: this.config.storage,
} as ContentSectionPartConfig);
this.parts = new LazyUiParts();
this.parts.register('footer', ContentFooterPart, {
editor: this.config.editor,
contentSettings: this.contentSettings,
} as ContentFooterConfig);
this.parts.register('header', ContentHeaderPart, {
editor: this.config.editor,
sections: this.sections,
state: this.config.state,
storage: this.config.storage,
} as ContentHeaderConfig);
this.parts.register('toolbar', ContentToolbarPart, {
editor: this.config.editor,
state: this.config.state,
storage: this.config.storage,
} as ContentToolbarConfig);
}
classesForPart(): Record<string, boolean> {
return {
le__panel: true,
le__part__content: true,
};
}
get isExpanded(): boolean {
return this.partToolbar.isExpanded || false;
}
get partFooter(): ContentFooterPart {
return this.parts.get('footer') as ContentFooterPart;
}
get partHeader(): ContentHeaderPart {
return this.parts.get('header') as ContentHeaderPart;
}
get partToolbar(): ContentToolbarPart {
return this.parts.get('toolbar') as ContentToolbarPart;
}
template(): TemplateResult {
const subParts: Array<TemplateResult> = [];
subParts.push(this.partToolbar.template());
if (this.config.editor.state.loadingFilePath) {
subParts.push(html`<div class="le__part__content__loading">
${templateLoading(
{},
html`<div class="le__part__content__loading__status">
Loading
<code>${this.config.editor.state.loadingFilePath || 'file'}</code>
</div>`
)}
</div>`);
} else {
subParts.push(this.partHeader.template());
subParts.push(this.templateSections());
}
subParts.push(this.partFooter.template());
return html`<div class=${classMap(this.classesForPart())}>
${subParts}
</div>`;
}
templateSections(): TemplateResult {
const visibleSections: Array<ContentSectionPart> = [];
for (const sectionKey of CONTENT_SECTION_ORDER) {
const section: ContentSectionPart = this.sections.get(
sectionKey
) as ContentSectionPart;
visibleSections.push(section);
}
return html`<div class="le__part__content__sections">
${repeat(
visibleSections,
section => section.section,
section => section.template()
)}
</div>`;
}
}
export class ContentSettings extends ListenersMixin(Base) {
protected _highlightAuto?: boolean;
protected _highlightDirty?: boolean;
protected _showDeepLinks?: boolean;
storage: DataStorage;
constructor(storage: DataStorage) {
super();
this.storage = storage;
this._highlightAuto = this.storage.getItemBoolean(
STORAGE_SETTING_HIGHLIGHT_AUTO
);
this._highlightDirty = this.storage.getItemBoolean(
STORAGE_SETTING_HIGHLIGHT_DIRTY
);
this._showDeepLinks = this.storage.getItemBoolean(
STORAGE_SETTING_SHOW_DEEP_LINKS
);
}
get highlightAuto(): boolean {
return this._highlightAuto || false;
}
set highlightAuto(value: boolean) {
this._highlightAuto = value;
this.storage.setItemBoolean(STORAGE_SETTING_HIGHLIGHT_AUTO, value);
this.triggerListener('highlightAuto', this.highlightAuto);
}
get highlightDirty(): boolean {
return this._highlightDirty || false;
}
set highlightDirty(value: boolean) {
this._highlightDirty = value;
this.storage.setItemBoolean(STORAGE_SETTING_HIGHLIGHT_DIRTY, value);
this.triggerListener('highlightDirty', this.highlightDirty);
}
get showDeepLinks(): boolean {
return this._showDeepLinks || false;
}
set showDeepLinks(value: boolean) {
this._showDeepLinks = value;
this.storage.setItemBoolean(STORAGE_SETTING_SHOW_DEEP_LINKS, value);
this.triggerListener('showDeepLinks', this.showDeepLinks);
}
toggleHighlightAuto() {
this.highlightAuto = !this.highlightAuto;
}
toggleHighlightDirty() {
this.highlightDirty = !this.highlightDirty;
}
toggleShowDeepLinks() {
this.showDeepLinks = !this.showDeepLinks;
}
}