Skip to content

Commit e5d4cb1

Browse files
committed
Disable the TinyMCE context menu by default
1 parent 92cd146 commit e5d4cb1

File tree

5 files changed

+34
-5
lines changed

5 files changed

+34
-5
lines changed

CHANGELOG.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [unreleased]
99

10+
## [0.2.2] - 2025-03-19
11+
12+
### Changed
13+
14+
- The TinyMCE contextual menu is disabled by default. ([#8](https://github.com/torchbox/wagtail-tinytableblock/pull/8))
15+
Pass `enable_context_menu=True` to your block definition to enable the TinyMCE context menu.
16+
1017
## [0.2.2] - 2025-03-18
1118

1219
### Changed
@@ -36,7 +43,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3643
Initial release
3744

3845

39-
[unreleased]: https://github.com/torchbox/wagtail-tinytableblock/compare/v0.2.2...HEAD
46+
[unreleased]: https://github.com/torchbox/wagtail-tinytableblock/compare/v0.2.3...HEAD
47+
[0.2.3]: https://github.com/torchbox/wagtail-tinytableblock/compare/v0.2.2...v0.2.3
4048
[0.2.2]: https://github.com/torchbox/wagtail-tinytableblock/compare/v0.2.1...v0.2.2
4149
[0.2.1]: https://github.com/torchbox/wagtail-tinytableblock/compare/v0.2...v0.2.1
4250
[0.2]: https://github.com/torchbox/wagtail-tinytableblock/compare/v0.1...v0.2

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,17 @@ class ContentBlocks(StreamBlock):
7373
table_block = TinyTableBlock(allow_links=True)
7474
```
7575

76+
By default, we disable the TinyMCE contextual menu to allow the browser native one. If you want to use TinyMCE one,
77+
pass `enable_context_menu=True`:
78+
79+
```python
80+
from wagtail.blocks import StreamBlock
81+
from wagtail_tinytableblock.blocks import TinyTableBlock
82+
83+
class ContentBlocks(StreamBlock):
84+
table_block = TinyTableBlock(enable_context_menu=True)
85+
```
86+
7687

7788
## Data representation
7889

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.2.2"
1+
__version__ = "0.2.3"

src/wagtail_tinytableblock/blocks.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def js_args(self, block) -> list:
5959
the_args = super().js_args(block)
6060

6161
the_args[2]["enableLinks"] = block.meta.allow_links
62+
the_args[2]["enableContextMenu"] = block.meta.enable_context_menu
6263

6364
return the_args
6465

@@ -84,7 +85,9 @@ def __init__(self, *, local_blocks=None, search_index=True, **kwargs):
8485
super().__init__(local_blocks=local_blocks, search_index=search_index, **kwargs)
8586
# manually define the data block so we can pass on configuration kwargs
8687
block = TinyTableFieldBlock(
87-
required=False, allow_links=kwargs.get("allow_links", False)
88+
required=False,
89+
allow_links=kwargs.get("allow_links", False),
90+
enable_context_menu=kwargs.get("enable_context_menu", False),
8891
)
8992
block.set_name("data")
9093
self.child_blocks["data"] = block
@@ -93,3 +96,4 @@ class Meta:
9396
icon = "table"
9497
template = "wagtail_tinytableblock/table_block.html"
9598
allow_links = False
99+
enable_context_menu = False

src/wagtail_tinytableblock/static/wagtail_tinytableblock/js/tiny-table-block.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class TinyTableBlockDefinition extends window.wagtailStreamField.blocks.FieldBlo
44
const block = super.render(placeholder, prefix, initialState, initialError);
55

66
let plugins = "table autoresize";
7-
let toolbar = "undo redo copy paste | tablerowheader tablecolheader tablemergecells tablesplitcells | tableinsertcolbefore tableinsertcolafter tableinsertrowbefore tableinsertrowafter";
7+
let toolbar = "undo redo copy paste | tablerowheader tablecolheader tablemergecells tablesplitcells | tableinsertcolbefore tableinsertcolafter tableinsertrowbefore tableinsertrowafter tabledelete";
88
let contextmenu = "copy paste table";
99
let valid_elements = "br,table[border|width|height|align|summary],tr[align|valign],td[align|valign|width|colspan|rowspan],th[align|valign|width|colspan|rowspan|scope],thead,tbody";
1010
if (this.meta.enableLinks) {
@@ -14,6 +14,12 @@ class TinyTableBlockDefinition extends window.wagtailStreamField.blocks.FieldBlo
1414
valid_elements += ",a[href|target|rel]";
1515
}
1616

17+
let contextmenu_never_use_native = true;
18+
if (!this.meta.enableContextMenu) {
19+
contextmenu = false;
20+
contextmenu_never_use_native = false;
21+
}
22+
1723
tinymce.init({
1824
selector: "#" + prefix,
1925
plugins: plugins,
@@ -29,7 +35,7 @@ class TinyTableBlockDefinition extends window.wagtailStreamField.blocks.FieldBlo
2935
table_sizing_mode: 'responsive',
3036
table_resize_bars: false,
3137
object_resizing: false,
32-
contextmenu_never_use_native: true,
38+
contextmenu_never_use_native: contextmenu_never_use_native,
3339
skin: (window.matchMedia("(prefers-color-scheme: dark)").matches ? "oxide-dark" : "oxide"),
3440
content_css: (window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "default"),
3541
content_style: 'thead th, thead td { font-weight: 700; }',

0 commit comments

Comments
 (0)