Skip to content
This repository was archived by the owner on May 5, 2021. It is now read-only.

Commit 095015b

Browse files
Goamandmo-odoo
authored andcommitted
[IMP] ReactiveInfo: info through ReactiveValue
1 parent 1a131f4 commit 095015b

File tree

3 files changed

+36
-32
lines changed

3 files changed

+36
-32
lines changed

packages/bundle-odoo-website-editor/OdooWebsiteEditor.ts

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ import { DividerNode } from '../plugin-divider/src/DividerNode';
6666
import { Attributes } from '../plugin-xml/src/Attributes';
6767
import { Strikethrough } from '../plugin-strikethrough/src/Strikethrough';
6868
import { ActionableNode } from '../plugin-layout/src/ActionableNode';
69+
import { ReactiveEditorInfo } from '../plugin-reactive-info/src/ReactiveEditorInfo';
6970

7071
interface OdooWebsiteEditorOptions {
7172
source: HTMLElement;
@@ -163,6 +164,7 @@ export class OdooWebsiteEditor extends JWEditor {
163164
[History],
164165
[Iframe],
165166
[Button],
167+
[ReactiveEditorInfo],
166168
...(options.plugins || []),
167169
],
168170
});
@@ -260,44 +262,12 @@ export class OdooWebsiteEditor extends JWEditor {
260262
}
261263
},
262264
},
263-
{
264-
id: 'historyButtons',
265-
render: async (editor: JWEditor): Promise<VNode[]> => {
266-
const history = editor.plugins.get(History);
267-
const undo = new ActionableNode({
268-
name: 'undo',
269-
label: 'Undo',
270-
commandId: 'undo',
271-
enabled: history.canUndo.bind(history),
272-
modifiers: [new Attributes({
273-
class: 'btn btn-secondary fa fa-undo',
274-
'data-action': 'undo',
275-
})],
276-
htmlTag: 'BUTTON',
277-
});
278-
const redo = new ActionableNode({
279-
name: 'redo',
280-
label: 'Redo',
281-
commandId: 'redo',
282-
enabled: history.canRedo.bind(history),
283-
modifiers: [new Attributes({
284-
class: 'btn btn-secondary fa fa-repeat',
285-
'data-action': 'redo',
286-
})],
287-
htmlTag: 'BUTTON',
288-
});
289-
return [undo, redo];
290-
},
291-
},
292265
],
293266
componentZones: [
294267
['main_template', ['root']],
295268
['snippet_menu', ['main_sidebar']],
296269
['snippetManipulators', ['snippetManipulators']],
297270
],
298-
locations: [
299-
['historyButtons', [document.body, 'append']],
300-
],
301271
location: options.location,
302272
pressedActionablesClassName: 'active',
303273
});

packages/bundle-odoo-website-editor/odoo-integration.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { FontAwesomeNode } from '../plugin-fontawesome/src/FontAwesomeNode';
2424
import { SeparatorNode } from '../core/src/VNodes/SeparatorNode';
2525
import { Format } from '../core/src/Format';
2626
import { OdooVideoNode } from '../plugin-odoo-video/src/OdooVideoNode';
27+
import { ReactiveEditorInfo } from '../plugin-reactive-info/src/ReactiveEditorInfo';
2728

2829
export {
2930
OdooWebsiteEditor,
@@ -52,4 +53,5 @@ export {
5253
OdooVideoNode,
5354
SeparatorNode,
5455
Format,
56+
ReactiveEditorInfo,
5557
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { History } from '../../plugin-history/src/History';
2+
import { JWPluginConfig, JWPlugin } from '../../core/src/JWPlugin';
3+
import { ReactiveValue } from '../../utils/src/ReactiveValue';
4+
5+
interface EditorCurrentState {
6+
canUndo: boolean;
7+
canRedo: boolean;
8+
}
9+
10+
export class ReactiveEditorInfo<T extends JWPluginConfig = JWPluginConfig> extends JWPlugin<T> {
11+
static dependencies = [History];
12+
13+
editorInfo: ReactiveValue<EditorCurrentState> = new ReactiveValue({
14+
canUndo: false,
15+
canRedo: false,
16+
});
17+
18+
commandHooks = {
19+
'@commit': this._updateInfo,
20+
};
21+
22+
/**
23+
* Update the information of the `editorInfo`.
24+
*/
25+
private _updateInfo(): void {
26+
const history = this.editor.plugins.get(History);
27+
this.editorInfo.set({
28+
canUndo: history.canUndo(),
29+
canRedo: history.canRedo(),
30+
});
31+
}
32+
}

0 commit comments

Comments
 (0)