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

Commit

Permalink
integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Goaman committed Jun 5, 2020
1 parent 6f07893 commit 601ca2f
Show file tree
Hide file tree
Showing 45 changed files with 1,443 additions and 142 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ ehthumbs.db
Thumbs.db
data/
build/
!src/build/
package-lock.json
coverage/
238 changes: 238 additions & 0 deletions bundles/OdooWebsiteEditor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
import JWEditor from '../packages/core/src/JWEditor';
import { Parser } from '../packages/plugin-parser/src/Parser';
import { Html } from '../packages/plugin-html/src/Html';
import { Char } from '../packages/plugin-char/src/Char';
import { LineBreak } from '../packages/plugin-linebreak/src/LineBreak';
import { Heading } from '../packages/plugin-heading/src/Heading';
import { Paragraph } from '../packages/plugin-paragraph/src/Paragraph';
import { List } from '../packages/plugin-list/src/List';
import { Indent } from '../packages/plugin-indent/src/Indent';
import { ParagraphNode } from '../packages/plugin-paragraph/src/ParagraphNode';
import { LineBreakNode } from '../packages/plugin-linebreak/src/LineBreakNode';
import { Span } from '../packages/plugin-span/src/Span';
import { Bold } from '../packages/plugin-bold/src/Bold';
import { Italic } from '../packages/plugin-italic/src/Italic';
import { Underline } from '../packages/plugin-underline/src/Underline';
import { Inline } from '../packages/plugin-inline/src/Inline';
import { Link } from '../packages/plugin-link/src/Link';
import { Divider } from '../packages/plugin-divider/src/Divider';
import { Image } from '../packages/plugin-image/src/Image';
import { Subscript } from '../packages/plugin-subscript/src/Subscript';
import { Superscript } from '../packages/plugin-superscript/src/Superscript';
import { Blockquote } from '../packages/plugin-blockquote/src/Blockquote';
import { Youtube } from '../packages/plugin-youtube/src/Youtube';
import { Table } from '../packages/plugin-table/src/Table';
import { Metadata } from '../packages/plugin-metadata/src/Metadata';
import { Renderer } from '../packages/plugin-renderer/src/Renderer';
import { Keymap } from '../packages/plugin-keymap/src/Keymap';
import { Align } from '../packages/plugin-align/src/Align';
import { Pre } from '../packages/plugin-pre/src/Pre';
import { TextColor } from '../packages/plugin-textcolor/src/TextColor';
import { BackgroundColor } from '../packages/plugin-backgroundcolor/src/BackgroundColor';
import { Layout } from '../packages/plugin-layout/src/Layout';
import { DomLayout } from '../packages/plugin-dom-layout/src/DomLayout';
import { DomEditable } from '../packages/plugin-dom-editable/src/DomEditable';
import { VNode } from '../packages/core/src/VNodes/VNode';

import './basicLayout.css';
import { OdooSnippet } from '../packages/plugin-odoo-snippets/src/OdooSnippet';

import { Toolbar } from '../packages/plugin-toolbar/src/Toolbar';
import { ParagraphButton } from '../packages/plugin-heading/src/HeadingButtons';
import { Heading1Button } from '../packages/plugin-heading/src/HeadingButtons';
import { Heading2Button } from '../packages/plugin-heading/src/HeadingButtons';
import { Heading3Button } from '../packages/plugin-heading/src/HeadingButtons';
import { Heading4Button } from '../packages/plugin-heading/src/HeadingButtons';
import { Heading5Button } from '../packages/plugin-heading/src/HeadingButtons';
import { Heading6Button } from '../packages/plugin-heading/src/HeadingButtons';
import { PreButton } from '../packages/plugin-pre/src/PreButtons';
import { BoldButton } from '../packages/plugin-bold/src/BoldButtons';
import { ItalicButton } from '../packages/plugin-italic/src/ItalicButtons';
import { UnderlineButton } from '../packages/plugin-underline/src/UnderlineButtons';
import { OrderedListButton } from '../packages/plugin-list/src/ListButtons';
import { UnorderedListButton } from '../packages/plugin-list/src/ListButtons';
import { IndentButton } from '../packages/plugin-indent/src/IndentButtons';
import { OutdentButton } from '../packages/plugin-indent/src/IndentButtons';
import { SaveButton } from '../packages/plugin-odoo-snippets/src/SaveButton';
import { HtmlNode } from '../packages/plugin-html/src/HtmlNode';
import { MediaButton } from '../packages/plugin-odoo-snippets/src/MediaButton';
import { CommandImplementation, CommandIdentifier } from '../packages/core/src/Dispatcher';
import { JWPlugin } from '../packages/core/src/JWPlugin';
import { OdooVideo } from '../packages/plugin-odoo-video/src/OdooVideo';
import { LinkButton } from '../packages/plugin-odoo-snippets/src/LinkButton';
import { DomZonePosition } from '../packages/plugin-layout/src/LayoutEngine';
import { HtmlDomRenderingEngine } from '../packages/plugin-html/src/HtmlDomRenderingEngine';
import {
AlignLeftButton,
AlignCenterButton,
AlignRightButton,
AlignJustifyButton,
} from '../packages/plugin-align/src/AlignButtons';

interface OdooWebsiteEditorOption {
source: HTMLElement;
location: [Node, DomZonePosition];
customCommands: Record<CommandIdentifier, CommandImplementation>;
afterRender?: Function;
snippetMenuElement?: HTMLElement;
snippetManipulators?: HTMLElement;
template?: string;
// todo: Remove when configuring the toolbar in another way.
saveButton?: boolean;
}

export class OdooWebsiteEditor extends JWEditor {
constructor(options: OdooWebsiteEditorOption) {
super();
class CustomPlugin extends JWPlugin {
commands = options.customCommands;
}

this.configure({
defaults: {
Container: ParagraphNode,
Separator: LineBreakNode,
},
plugins: [
[Parser],
[Renderer],
[Layout],
[Keymap],
[Html],
[Inline],
[Char],
[LineBreak],
[Heading],
[Paragraph],
[List],
[Indent],
[Span],
[Bold],
[Italic],
[Underline],
[Link],
[Divider],
[Image],
[Subscript],
[Superscript],
[Blockquote],
[Youtube],
[Table],
[Metadata],
[Align],
[Pre],
[TextColor],
[BackgroundColor],
[OdooSnippet],
[OdooVideo],
[CustomPlugin],
],
});
this.configure(Toolbar, {
layout: [
[
[
ParagraphButton,
Heading1Button,
Heading2Button,
Heading3Button,
Heading4Button,
Heading5Button,
Heading6Button,
PreButton,
],
],
[BoldButton, ItalicButton, UnderlineButton],
[AlignLeftButton, AlignCenterButton, AlignRightButton, AlignJustifyButton],
[OrderedListButton, UnorderedListButton],
[IndentButton, OutdentButton],
[LinkButton],
[MediaButton],
...(options.saveButton ? [[SaveButton]] : []),
],
});

const defaultTemplate = `
<t t-zone="float"/>
<t t-zone="default"/>
<div class="wrap_editor d-flex flex-column">
<div class="d-flex flex-row overflow-auto">
<t t-zone="main_sidebar"/>
<div class="d-flex flex-column overflow-auto o_editor_center">
<div class="o_toolbar">
<t t-zone="tools"/>
</div>
<div class="d-flex overflow-auto">
<t t-zone="snippetManipulators"/>
<t t-zone="main"/>
</div>
</div>
</div>
<div class="o_debug_zone">
<t t-zone="debug"/>
</div>
</div>
`;
this.configure(DomLayout, {
components: [
{
id: 'main_template',
render(editor: JWEditor): Promise<VNode[]> {
return editor.plugins
.get(Parser)
.parse('text/html', options.template || defaultTemplate);
},
},
{
id: 'snippet_menu',
render(): Promise<VNode[]> {
const node: VNode = options.snippetMenuElement
? new HtmlNode({ domNode: options.snippetMenuElement })
: new LineBreakNode();
return Promise.resolve([node]);
},
},
{
id: 'snippetManipulators',
render(): Promise<VNode[]> {
const node: VNode = options.snippetMenuElement
? new HtmlNode({ domNode: options.snippetManipulators })
: new LineBreakNode();
return Promise.resolve([node]);
},
},
],
componentZones: [
['main_template', 'root'],
['snippet_menu', 'main_sidebar'],
['snippetManipulators', 'snippetManipulators'],
],
location: options.location,
afterRender: options.afterRender,
});
this.configure(DomEditable, {
autoFocus: true,
source: options.source.firstElementChild as HTMLElement,
});
}

/**
* Get the value by rendering the "editable" component of the editor.
*/
async getValue(): Promise<Node> {
const renderer = this.plugins.get(Renderer);
const layout = this.plugins.get(Layout);
const domLayout = layout.engines.dom;
const domRenderingEngine = renderer.engines[
HtmlDomRenderingEngine.id
] as HtmlDomRenderingEngine;
const editable = domLayout.components.get('editable')[0];
const nodes = await domRenderingEngine.render(editable);
return nodes[0];
}

async render(): Promise<void> {
const domLayout = this.plugins.get(DomLayout);
return domLayout.redraw();
}
}
14 changes: 14 additions & 0 deletions dev/odoo-integration-dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// todo: replace this file with the actual code of the lib.
odoo.define('web_editor.jabberwock', function(require) {
'use strict';

const script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'http://localhost:8095/odoo-integration.js';
document.getElementsByTagName('head')[0].appendChild(script);
return new Promise(resolve => {
script.onload = () => {
resolve(JWEditor);
};
});
});
30 changes: 30 additions & 0 deletions doc/odoo_integration_workflow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Odoo integration

To develop Jabberwock in Odoo, follow these steps:
1) Use the dev mode for the live reloading feature of Webpack. (optional)
2) Build the source and include it in Odoo.

## 1) Use the dev mode for the live reloading feature of Webpack.

Temporarily replace the library with the following script.
```bash
cp dev/odoo-integration-dev.js <your_odoo_path>/addons/web_editor/static/lib/jabberwock/jabberwock.js
```
`odoo-integration-dev.js` will load the script `build-full.js`.
The default loaded script is `http://localhost:8095/odoo-integration.js`.
You might want to change the port if your development port is not "8095".

Launch the development server (on port 8095):
```bash
npm run dev -- --port 8095
```

Once finished developing, rebuild the source and put it back in Odoo.

## 2) Build the source and include it in Odoo.

```bash
npm run build
npm run build-odoo
cp build/webpack/build/odoo-integration.js <your_odoo_path>/addons/web_editor/static/lib/jabberwock/jabberwock.js
```
Binary file added examples/assets/img/s_quotes_carousel_2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions examples/demo/demo.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ jw-editor table.mondrian {
width: 65vh;
height: 50vh;
}

.jw_selected_image {
outline: 1px red solid;
}
7 changes: 6 additions & 1 deletion examples/demo/demo.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<a class="o_scroll_button rounded-circle align-items-center justify-content-center mx-auto bg-primary" href="#" contenteditable="false" title="Scroll down to next section">
<i class="fa fa-angle-down fa-3x">&nbsp;</i>
</a>

<h1 style="text-align: center;"><i class="fab fa-opera"></i>doo
Jabberw<i class="fab fa-opera"></i>ck Dem<i class="fab fa-opera"></i></h1>

<p>
An image:<img src="/assets/img/s_quotes_carousel_2.jpg" />hehe
</p>
"<b>Jabberwocky</b>" is a nonsense poem written by Lewis Carroll about the
killing of a creature named "the Jabberwock". It was included in his 1871 novel
<i>Through the Looking-Glass, and What Alice Found There</i>, the sequel to
Expand Down
2 changes: 1 addition & 1 deletion examples/utils/jabberwocky.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ He chortled in his joy.<br/>
’Twas brillig, and the slithy toves<br/>
Did gyre and gimble in the wabe:<br/>
All mimsy were the borogoves,<br/>
And the mome raths outgrabe.<br/></i></p>
And the mome raths outgrabe.<br/></i></p>
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
"description": "The best editor in the world",
"main": "src/index.ts",
"scripts": {
"dev": "webpack-dev-server",
"build": "rm -rf build/examples; mkdir -p build/examples/; cp -r ./examples ./build; webpack",
"dev": "webpack-dev-server --config webpack-examples.config.js",
"build": "rm -rf build/examples; mkdir -p build/examples/; cp -r ./examples ./build; webpack --config webpack-examples.config.js",
"build-odoo": "rm -rf build/examples; mkdir -p build/examples/; cp -r ./examples ./build; webpack --config webpack-odoo.config.js",
"perf": "karma start --include-files test/**/*.perf.ts",
"coverage": "karma start --coverage",
"debug": "karma start --no-browsers --debug",
Expand Down
22 changes: 22 additions & 0 deletions packages/build-odoo-integration/odoo-integration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { BasicEditor } from './../../bundles/BasicEditor';
import { DevTools } from '../plugin-devtools/src/DevTools';
import { OdooWebsiteEditor } from '../../bundles/OdooWebsiteEditor';
import { VRange, withRange } from '../core/src/VRange';
import { DomLayoutEngine } from '../plugin-dom-layout/src/ui/DomLayoutEngine';
import { Layout } from '../plugin-layout/src/Layout';
import { Renderer } from '../plugin-renderer/src/Renderer';
import { ImageNode } from '../plugin-image/src/ImageNode';
import { createExecCommandHelpersForOdoo } from '../plugin-odoo-snippets/src/OdooBindings';

export {
OdooWebsiteEditor,
BasicEditor,
DevTools,
Layout,
DomLayoutEngine,
Renderer,
ImageNode,
withRange,
VRange,
createExecCommandHelpersForOdoo,
};
4 changes: 3 additions & 1 deletion packages/core/src/Dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ export class Dispatcher {
const args = { ...params, context };

// Call command handler.
await command.handler(args);
const result = await command.handler(args);

await this._dispatchHooks(commandId, args);

return result;
}
}

Expand Down
Loading

0 comments on commit 601ca2f

Please sign in to comment.