Commit Graph
279 Commits
Author SHA1 Message Date
Antoine Guenet 9b4ff416b2 [MOV] web_editor: move DOMPurify to the lib directory
DOMPurify is a library but it was mixed in with Odoo code.

Part-of: odoo/odoo#94516
2022-07-04 18:53:06 +02:00
Antoine Guenet 920cffdd96 [MOV] web_editor, knowledge, mass_mailing, website: editor lib to src
Odoo-Editor, having originally been developed with the purpose of being
a standalone library, was put into a `lib` folder. Since in the meantime
the library plans were aborted and since its presence outside the `src`
directory makes translations unavailable for it, this moves the editor
to `src/js/editor/odoo-editor`.

task-2880723

Part-of: odoo/odoo#94516
2022-07-04 18:53:05 +02:00
Nicolas Bayet ac0cb67f36 [FIX] web_editor: transform space to nbsp when deleterange
Before this commit
When removing the last word of an html container, the last space was
not transformed into an `nbsp`. This caused google chrome to not
render the space.

Task-2809312

closes odoo/odoo#95124

X-original-commit: cd4f1c4bce66817640eea20f0b297095d48ea647
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
2022-07-02 11:41:21 +02:00
Nicolas Bayet eb9c991c60 [FIX] web_editor: make o_not_editable contenteditable=false
The fix 1b80fe9 removed the behavior that made `.o_not_editable`
`contenteditable=false`. Without this behavior, other issues could
arises.

closes odoo/odoo#94889

X-original-commit: 4e7d6e1a70e44df3476c2602119fbcedc7c04199
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
2022-07-01 16:35:38 +02:00
David Monjoie 2dc9406932 [FIX] web_editor: less sanitize _parse recursive calls
The _parse function of sanitize used to be recursive both along the
length and depth of the DOM tree, making it exceed maximum stack size
limit for long documents. This updated version is now only recursive in
the depth of the tree, not its length. It would be possible to write a
fully non-recursive version of this function but it is out of scope of
this task and is unlikely to happen anyway as DOM trees are way more
unlikely to exceed stack limits in depth rather than length.

task-2895671

closes odoo/odoo#94967

X-original-commit: c711a2c4106da0c2d5c35ee7a367ba86a9dcbdb7
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
2022-06-30 18:52:41 +02:00
Nicolas Bayet 31d03da243 [FIX] web_editor: prevent selection on sanitize
Before this commit, it was possible to set the selection of the document
whenever sanitizing an element that was not present in the dom.

task-2877501

closes odoo/odoo#94900

X-original-commit: 7b60241e01914ffc0176c24d4e780f773f9a277f
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
2022-06-30 09:29:54 +02:00
Nicolas Bayet 023153896d [FIX] web_editor: resolve shortcut conflict of link dialog & command palette
Whenever the user hit ctrl+k when being on an html field, both the
link dialog and the command palette opened.

In order to resolve the conflict, now ctrl+k open the command palette
with the first entry being the command to open the linktool and
a subsequent hit to ctrl+k when the command palette is open to open
the link dialog.

Task-2738457

Forward-port-of: #89940
Forward-port-of: #82994
Part-of: odoo/odoo#91102
2022-06-29 17:11:27 +02:00
Nicolas Bayet 2712e0d1ca [REF] web_editor: adapt editor tests to use triggerEvent
A new method `triggerEvent` has been introduced in order to simplify
event creation. This commit adapt the tests to use that method.

closes odoo/odoo#92653

Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
2022-06-02 16:54:12 +02:00
Nicolas Bayet a88bb2250a [FIX] web_editor: convert link only a space after it
Before this commit, when adding a space anywhere in the a text node,
a plain text link gets transformed into a proper link.

It might be an undesired behavior as we could want to manually remove
the link but it will be re-transformed when completing a paragraph.

task-2795019

X-original-commit: 76b5ecc88001ae9decaf3943550ecb4ddb874599
Part-of: odoo/odoo#92653
2022-06-02 16:54:11 +02:00
Nicolas Bayet f3cbb27fc1 [FIX] web_editor: correct selection after applying a color
Ensure the selection in the fonts tags after `applyColor`, otherwise an
undetermined race condition could generate a wrong selection during
multiples call of `_processAndApplyColor` from the color picker.

task-2822221

closes odoo/odoo#92654

X-original-commit: 2b2aba49550cf7c2ba1914f03beef9cbdf60b166
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
2022-06-01 16:26:40 +02:00
Antoine Guenet 756243ecd3 [FIX] web_editor: properly convert Bootstrap buttons for Outlook
Outlook's renderer doesn't understand Bootstrap's styling of buttons we
have a special rendering just for it but its design was suboptimal so
this improves it.

task-2761098

Part-of: odoo/odoo#87962
2022-05-31 11:06:47 +02:00
Antoine Guenet 14cb5ccfea [FIX] mass_mailing: do not allow links within background-image elements
Since background-image elements and their children will be flattened
into images, links within them won't work. This removes the link button
of the editor toolbar, as well as the link and button commands in those
contexts.

task-2856858

Part-of: odoo/odoo#91314
2022-05-24 14:51:07 +02:00
Antoine Guenet 3fcb74533a [MOV] web_editor, point_of_sale: move html2canvas to web_editor
This moves the `html2canvas` library from `point_of_sale` to
`web_editor` so as to be able to use it in `convert_inline`.
`point_of_sale`, depending from `web_editor`, doesn't lose access to the
library.

task-2856858

Part-of: odoo/odoo#91314
2022-05-24 14:51:05 +02:00
Sébastien Geelen (sge) ce067c3b56 [FIX] web_editor,website,website_sale : fix products header edition
Prevent edition on e-commerce products header bar.
Since we cannot save any change done in the header object anyway,
And some edition would trigger error.
We put the all bar in a read-only mode.

task-2745151

X-original-commit: e2f7b8fad76dc816b2f6864340d3740446117cdb
Part-of: odoo/odoo#91840
2022-05-20 13:15:39 +02:00
Sébastien Geelen (sge) 6a9fd6b827 [FIX] web_editor: fix some linting errors
closes odoo/odoo#91786

X-original-commit: 46094420d70bfef0e9834a1ed7ef60beab1ccb22
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
2022-05-20 13:15:30 +02:00
Sébastien Geelen (sge) a3ee176405 [FIX] web_editor: Fix style formating traceback
In some case, when removing format on element with multiple textNode,
the code generate a traceback.

The loops in `toggleFormat` provide a limit element `closestDecorated` to
the `splitAroundUntil` util. However this limit element can be split and
dumped by the format removal. In this case the reference was never encountered
in the DOM by the `splitAroundUntil` code and will bubble all the way to the
`<html>` TAG an try to split it, which generate an error.

We fix it by getting the `closestDecorated` in every loop.

task-2850686

X-original-commit: 2d93345c38f55c276370d0059d562d28320db2fb
Part-of: odoo/odoo#91786
2022-05-20 13:15:30 +02:00
Sébastien Geelen (sge) cc80572ee6 [FIX] web_editor: fix missing strikeThrough tests
Add some unit test for strikeThrough format.
Those tests reveal some bug in the current formating code.

task-2850686

X-original-commit: 4d8e1dc381d01bb254d2e806a335a40733608f2e
Part-of: odoo/odoo#91786
2022-05-20 13:15:30 +02:00
Sébastien Geelen (sge) 491a9d6399 [FIX] web_editor: fix unit test
Wrong contentAfter labeling.

X-original-commit: 22bb8ae8e131a576987e95911d229aad42d00193
Part-of: odoo/odoo#91786
2022-05-20 13:15:30 +02:00
Nicolas Bayet 814659b73d [FIX] web_editor: disable element hint for website
Task-2674569

closes odoo/odoo#91148

X-original-commit: 117d465eff2c79a9d17164306c17f3f87aa11848
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
2022-05-18 09:42:48 +02:00
3cd87ca0dc [IMP] knowledge: add the template and file commands
This commit adds some commands that can be used in the html editor.

Editor Commands
---------------

Some new editor commands have been added:

- */article:*
This command is available on every html field using the Odoo Editor.
This command allows to add a direct link to the selected knowledge article.

- */file:*
This command is only available in the Knowledge App.
This command allows to add a file (or an image) download button inside the
body. The user can choose a file to add from its own file directory or an
existing attachment already present in the database.

- */template:*
This command is only available in the Knowledge App.
This command allows the user to create a block where them can write and lay out
content destined to be reused by the readers of the article. The lasts will be
able to copy and paste it to send it as message or use it as a description on
other records.
No /command can be added inside a template.

Technical notes:
/file and /template commands can be activated in other modules by adding
knowledge_commands = True on the html field in the view where they should
be activated.

Task-2674460

Part-of: odoo/odoo#82315
Co-authored-by: Damien Abeloos <abd@odoo.com>
Co-authored-by: Julien Banken <jbn@odoo.com>
Co-authored-by: David Beguin <dbe@odoo.com>
Co-authored-by: Fabio Barbero <faba@odoo.com>
Co-authored-by: Thibault Delavallee <tde@odoo.com>
Co-authored-by: Aurelien Warnong <awa@odoo.com>
2022-05-13 02:58:51 +02:00
Nicolas Bayet 53b4afe747 [FIX] web_editor: keep content on enter on mobile
Before this commit, when hitting enter while not in composition mode,
the editor sometimes removed all the content that was added the previous
composition.

task-4720

closes odoo/odoo#91235

X-original-commit: eddc820417d97b4100a9fb2f9f8934a84bb2417c
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
2022-05-12 17:35:04 +02:00
Nicolas Bayet 6f9110bfb0 [FIX] web_editor: prevent deleteBackspace to move nodes
Before this commit, whenever the element that must be deleted by
`deleteBackspace` matches `isMediaElement` or `isNotEditableNode` and
the cursor was in the beginning of a `<p>` with inline content, the
inline content moved to the parent and the `<p>` was deleted.
Which is wrong.

Now, whenever the element that must be deleted by `deleteBackspace`
matches `isMediaElement` or `isNotEditableNode`, no inline content
moves.

Task-2781328

closes odoo/odoo#91233

X-original-commit: 34d06958d053b070b1e07541214899649602873a
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
2022-05-12 17:35:00 +02:00
Nicolas Bayet 4338881cd4 [FIX] web_editor: restrict url regex
Inserting `w.r.t` in the editor transformed it into an url.
This kind of content should not be considered as an url.

task-2795012

closes odoo/odoo#91221

X-original-commit: 75c146fac019b952543403736948b803689bd15b
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
2022-05-12 16:05:16 +02:00
Hiral Bhavsar cfa916379b [FIX] web_editor: traceback on strikethrough with a checklist
Before this commit:

When having a checked checklist and clicking on the `strikethrough` gives
traceback.

After this commit:

No traceback is being generated.

Task-2833325

closes odoo/odoo#91114

X-original-commit: 491a79f6f8f734990a2ece3fd1b3f90d09a55c85
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
2022-05-11 18:50:14 +02:00
Nicolas Bayet 57d3211c99 [FIX] web_editor: disable observer only when necessary
Before this commit, the linktool was disabling the editor observer
until it was destroyed. This messed up with the undo/redo and the
isDirty.

This commit only disable the observer when necessary.

task-2836351

Forward-port-of: #90064
X-original-commit: 57c98f314332bbb4c3225942e1d3748eb131d8b0
Part-of: odoo/odoo#91074
2022-05-11 14:54:28 +02:00
abd-msyukyu-odoo f75462eeaf [IMP] web_editor: expand deleterange for uneditables
In Chrome, it is possible to partially select the contents of a
contenteditable=false element if it has a contenteditable=true child.

This commit prevents breaking such uneditables by expanding the range in a
deleterange to fully contain such elements.

It will be useful with the new blocks introduced with the Knowledge module.

Task-id: 2794990
Part-of: odoo/odoo#86489
2022-05-05 11:41:57 +02:00
abd-msyukyu-odoo f4d72dd1ed [IMP] web_editor: prevent command refocus when unnecessary
Currently, the focus is forced on this.editable when using a powerbox command.

Knowledge /template will introduce blocks which are contentEditable=False, but
contains sub-elements with contentEditable=True, which are allowed to use
powerbox commands. Those sub-elements have another editable context as
this.editable. As such, forcing a refocus on this.editable will remove the
caret from the sub-element.

Avoid doing the refocus if the currently focused element is a child of
this.editable and is contentEditable=true.

Task-id: 2794990
Part-of: odoo/odoo#86489
2022-05-05 11:41:56 +02:00
abd-msyukyu-odoo c007dafae8 [IMP] web_editor: add failsafe upon CTRL+BACKSPACE
Prevents the user to remove the last child (if it is an empty block) of an
editable, in order to avoid the case where the user can add text nodes directly
in a block where it should not be possible (i.e. directly under this.editable).

Replaces any empty block other than `<P>` by an empty `<P>` which is the default
block for the editor.

Task-id: 2794990
Part-of: odoo/odoo#86489
2022-05-05 11:41:55 +02:00
abd-msyukyu-odoo e82e96f173 [IMP] web_editor: set contenteditable as a safe attribute
Add the attribute 'contenteditable' to the frozen list for html elements of
DOMPurify, so that this attribute is not sanitized in collaborative mode when
using _safeSetAttribute.

Task-id: 2794990
Part-of: odoo/odoo#86489
2022-05-05 11:41:54 +02:00
David Monjoie f3372799ae [FIX] web_editor: fix traceback on paste
When fakeEl is empty, firstChild and lastChild both equal null.

task-2842638

closes odoo/odoo#90523

X-original-commit: 626caa89cf290f226b19dfa73bc4ab41c7f95fc0
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
2022-05-04 17:46:41 +02:00
Sébastien Geelen (sge) d8fd724cb3 [FIX] web_editor: transform orphan LI into P
Avoid living `<li>` tags without a `<ul>` or `<ol>` parent
in the editable html.

task-2842638

closes odoo/odoo#90518

X-original-commit: c6660d9ae1c931da3ad442b30f610db463ede894
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
2022-05-04 17:46:35 +02:00
Antoine Guenet 53aba047ce [FIX] web_editor: apply original element attributes on toggle list
When converting an element to a list element, we didn't preserve that
original element's attributes. As a consequence the text direction was
lost.

closes odoo/odoo#90247

X-original-commit: 0731ff677491d80540fa2ffc645fd2b471a9f61c
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
2022-05-02 07:43:55 +02:00
Antoine Guenet 618d5bc3ca [FIX] web_editor: provide proper support for mixed language directions
This introduces a "direction" option on the editor to set the text
direction of the editor (passed by Odoo based on the localization), and
a Powerbox command to switch said direction on a given block. This
allows users to mix several text directions within the same text, eg.
when quoting Hebrew in an English text.

task-2814004

X-original-commit: 693df325588ccaf6385c9f610709f687ccdf61a8
Part-of: odoo/odoo#90247
2022-05-02 07:43:55 +02:00
Nicolas Bayet fa796c76ad [FIX] web_editor: past mulitple lines and undo
Before this commit, when pasting multiples lines a new step per line.
So when performing an undo, only one line was removed instead of the
whole pasted text.

task-2833740

closes odoo/odoo#89932

X-original-commit: 06fb4e3e8377dedb02644779f0077e0d883df918
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
2022-04-28 09:00:50 +02:00
Nicolas Bayet 444fb09d1e [FIX] web_editor: prevent crash when inserting empty string
Before this commit, when unsing the function `insert()` with data being
an empty string, the function crashed but shouldn't.

task-2833740

X-original-commit: d44302550ddc027d4891ad04bf16c364e171e5ad
Part-of: odoo/odoo#89932
2022-04-28 09:00:50 +02:00
Nicolas Bayet c40d9e513c [FIX] web_editor: make checklist work in firefox
task-2833778

closes odoo/odoo#89918

X-original-commit: e3304148035ec04f435475bbf9ba803dc630ae37
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
2022-04-28 09:00:45 +02:00
David Monjoie 5951960bcf [REV] web_editor: revert fix onChange event
task-2832078

closes odoo/odoo#89834

X-original-commit: 50dc710363a5222098e1fea2919b6fc4ae0aee65
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
2022-04-27 14:29:10 +02:00
Sébastien Geelen (sge) 77178fe5ae [FIX] web_editor: fix onChange event
Ensure the `onChange()` callback is called
after each history steps in the editor.

Call the `_doAction()` directly, to avoid using the
disabled `_doDebouncedAction()`.

task-2760436

closes odoo/odoo#89339

X-original-commit: 18eaabcb4dab4682e3a94e16dbe66ff3c6f35a77
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
Signed-off-by: Geelen Sébastien (sge) <sge@odoo.com>
2022-04-22 08:03:38 +02:00
Nicolas Bayet 54f499cc86 [FIX] web_editor: make HR element not editable
task-2778511

closes odoo/odoo#89267

X-original-commit: af23ab272fcf9c33980679b0215be2fff0ea1a86
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
2022-04-21 15:06:48 +02:00
Sébastien Geelen (sge) 9b022bf2ff [FIX] web_editor : fix url transform & embed in paste
* Avoid auto-transforming an valid url inside an existing <a> tag.
* Ensure the current selection range is deleted
  before embedding an image or video.

task-2604627

closes odoo/odoo#89210

X-original-commit: 070bceeadd16e0b5643b91ad583449d31c48313d
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
2022-04-21 07:59:44 +02:00
Sébastien Geelen (sge) a538919bad [FIX] web_editor : fix html paste
We change the way we handle paste of html data :

The basic flow is :
1. if any range => deleteRange and continue from here
2. if the paste data has only one root <p> :
    > we unwrap its content in place
2. if the paste data has two root <p> :
    > we unwrap the content of the two p in place
    > we force a oEnter between the two contents
3. if the paste data has more than two root <p> :
    > we unwrap the content of the first and last p
    > we force a oEnter between the two contents
    > we insert the rest in between, out of focus block element

@see unit tests in `test/spec/copyPaste.test.js`

task-2604627

X-original-commit: 4dde6d37f30c35714c52e7e28f7011414fed7b6a
Part-of: odoo/odoo#89210
2022-04-21 07:59:44 +02:00
Sébastien Geelen (sge) b17cdad276 [FIX] web_editor : fix whitelist of html pasted elements
whitelist of html element was not designed to keep the style
set by our own editor ( style on <span>).

We add a system to keep the spans when they meet some requirements.
Requirements are basically having one of the few allowed inline styling css rule.

@see tests in `test/spec/copyPaste.test.js` section 'Html Paste cleaning'

task-2604627

X-original-commit: da92c2335a1241ec9f3974d3bac1c4b7227b2d28
Part-of: odoo/odoo#89210
2022-04-21 07:59:44 +02:00
Sébastien Geelen (sge) fcc035bcaa [FIX] web_editor : ensure break line consistency on delete
When delete backward/forward OR deleteRange,
we need to ensure the break lines stay consistent with the user action.

Some cases where not handled correctly.

Mainly when a <p> tags was removed and not directly adjacent to another block element.
In those case we kept too much or too little break lines.

@see tests added in `test/spec/editor.test.js`

task-2604627

X-original-commit: 9f14422ffceadd48b76ff460e4080e0cf5bc6fa2
Part-of: odoo/odoo#89210
2022-04-21 07:59:43 +02:00
Sébastien Geelen (sge) 4bd57e41a4 [FIX] web_editor : fix element merge on deleteBackward
Ensure we never move nodes that were not initially in the deleted element.

When deleting an element and merging its content with its sibling,
the nodes contained in the removed element will temporary be hosted
in the common parent, beside possible other nodes.
We don't ever want to touch those others nodes when merging.

This change fix some instances where nodes would wrongly be carry
into another element.

@see new "merge node" tests in `test/spec/editor.test.js`

task-2604627

X-original-commit: 0af6e15ba9d15f20ec74144fd3069e6f409ef802
Part-of: odoo/odoo#89210
2022-04-21 07:59:43 +02:00
Sébastien Geelen (sge) 7aaa481ee6 [FIX] web_editor : initialize powerbox property
Ensure the `_active` property on the PowerBox object is always a boolean.

@see test/spec/copyPaste.test.js

task-2604627

X-original-commit: 124298546cfbc129eb9ae934923a5e4e47392797
Part-of: odoo/odoo#89210
2022-04-21 07:59:43 +02:00
Sébastien Geelen (sge) d41bf197d1 [FIX] web_editor : fix some linting errors
task-2604627

X-original-commit: df980347f8c8953c2c938343b1558d1a395c716c
Part-of: odoo/odoo#89210
2022-04-21 07:59:43 +02:00
Sébastien Geelen (sge) f75b0635e2 [FIX] web_editor : add and change unit tests
ADD load of units tests covering :
  * text paste
  * html paste
  * image url embed on paste
  * url embed on paste
  * video url embed on paste

  * better coverage on some delete backward and forward

CHANGE some others unit tests :
  * tests about merging of block elements that where not accurate
  * test about insert HTML ( spec change )

task-2604627

X-original-commit: 378e8d1bd64e3758eb0202be33cb2d8c5bf97eea
Part-of: odoo/odoo#89210
2022-04-21 07:59:42 +02:00
Nicolas Bayet 595daa884a [FIX] web_editor: make o_editable unremovable
`o_editable` is not supposed to be removed.

Example of a problem if o_editable can be removed:
In translation mode, when deleting the text of the `o_editable` container,
that container could be removed but shouldn't.
See https://drive.google.com/file/d/1U_NUFBvUninOuFKn2H2c4BDcka3OetlD/view

task-2810332

closes odoo/odoo#89071

X-original-commit: 2010c0e2c402f5bb423a0fe683e51923e1e14042
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
2022-04-20 09:33:01 +02:00
Nicolas Bayet 8b521b25f1 [FIX] web_editor: keep contenteditable=true on links
The function `setContenteditableLink` makes all the `contenteditable=true`
that are not the link or in the link being `contenteditable=false`.

Before this commit:
If we click on a link A then we click on link B, and if link B has
elements being `contenteditable=true`, the first click makes them
`contenteditable=false` and the second do not makes them
`contenteditable=true`.

After this commit
If we click on a link A then we click on link B, and if link B has
elements being `contenteditable=true`, the first click makes them
`contenteditable=false` and the second click now makes them
`contenteditable=true`.

task-2810332

X-original-commit: 72dd8d6e3c95f614353b1e87322a67c877c255c7
Part-of: odoo/odoo#89071
2022-04-20 09:33:00 +02:00
Tom De Caluwé e73fa8f671 [IMP] web_editor: test adding nested editables
Commit e834173314f00e36cb3a1f99690d9f220584682c fixed an issue where editable
elements could not be removed if they were nested in a non-editable element,
because the editor considered them to be an editable root.

However, the same logic also applied when doing a history step after adding
such an element. Adding a nested editable element would make the history step
invalid and result in a rollback.

Such a situation can be encountered when adding a recaptcha legal notice to a
website form. The footer of the form is a non-editable paet of the document,
however the legal notice can still be updated by the user. This commit adds a
separate test for the addition of such editable elements that were previously
considered unremovable.

opw-2723017

closes odoo/odoo#88733

X-original-commit: f693e8ed27f753a728d903dfe4d7d10ae1334526
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
2022-04-14 10:50:07 +02:00