Skip to content

Commit 73e9ca7

Browse files
committed
feat(rte): allow button tag
1 parent 59cdf85 commit 73e9ca7

File tree

5 files changed

+63
-3
lines changed

5 files changed

+63
-3
lines changed

packages/pluggableWidgets/rich-text-web/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1010

1111
- We fixed an issue where the attribute not refreshed when the widget is not reloaded.
1212

13+
### Added
14+
15+
- We allow user to create html button tag on the widget.
16+
1317
## [4.0.0] - 2024-10-29
1418

1519
### Breaking changes

packages/pluggableWidgets/rich-text-web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@mendix/rich-text-web",
33
"widgetName": "RichText",
4-
"version": "4.0.1",
4+
"version": "4.1.0",
55
"description": "Rich inline or toolbar text editing",
66
"copyright": "© Mendix Technology BV 2024. All rights reserved.",
77
"repository": {

packages/pluggableWidgets/rich-text-web/src/package.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<package xmlns="http://www.mendix.com/package/1.0/">
3-
<clientModule name="RichText" version="4.0.1" xmlns="http://www.mendix.com/clientModule/1.0/">
3+
<clientModule name="RichText" version="4.1.0" xmlns="http://www.mendix.com/clientModule/1.0/">
44
<widgetFiles>
55
<widgetFile path="RichText.xml" />
66
</widgetFiles>

packages/pluggableWidgets/rich-text-web/src/utils/customPluginRegisters.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import "./formats/fontsize";
55
import CustomListItem from "./formats/customList";
66
import CustomLink from "./formats/link";
77
import CustomVideo from "./formats/video";
8+
import Button from "./formats/button";
89
import { Attributor } from "parchment";
910
const direction = Quill.import("attributors/style/direction") as Attributor;
1011
const alignment = Quill.import("attributors/style/align") as Attributor;
@@ -16,7 +17,6 @@ class Empty {
1617
return "";
1718
}
1819
}
19-
2020
/**
2121
* Custom format registration for quill.
2222
*/
@@ -31,5 +31,6 @@ Quill.register(IndentLeftStyle, true);
3131
Quill.register(IndentRightStyle, true);
3232
Quill.register(Formula, true);
3333
Quill.register(CustomHeader, true);
34+
Quill.register(Button, true);
3435
// add empty handler for view code, this format is handled by toolbar's custom config via ViewCodeDialog
3536
Quill.register({ "ui/view-code": Empty });
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import Inline from "quill/blots/inline";
2+
const ATTRIBUTES = ["alt", "height", "width", "class", "id"];
3+
4+
type buttonAttributes = {
5+
id?: string;
6+
class?: string;
7+
alt?: string;
8+
height?: string;
9+
width?: string;
10+
};
11+
class Button extends Inline {
12+
static blotName = "button";
13+
static tagName = "BUTTON";
14+
15+
format(name: string, value: unknown): void {
16+
if (name !== this.statics.blotName || !value) {
17+
super.format(name, value);
18+
} else {
19+
// @ts-expect-error the constructor is generic function, ts will consider sanitize not exist
20+
this.domNode.textContent = value;
21+
}
22+
}
23+
24+
static create(value: unknown): HTMLElement {
25+
const domNode = super.create(value) as HTMLElement;
26+
domNode.setAttribute("type", "button");
27+
if (value as buttonAttributes) {
28+
const buttonAttr = value as buttonAttributes;
29+
if (buttonAttr.id) {
30+
domNode.setAttribute("id", buttonAttr.id);
31+
}
32+
if (buttonAttr.class) {
33+
domNode.setAttribute("class", buttonAttr.class);
34+
}
35+
if (buttonAttr.width) {
36+
domNode.setAttribute("width", buttonAttr.width);
37+
}
38+
if (buttonAttr.height) {
39+
domNode.setAttribute("height", buttonAttr.height);
40+
}
41+
}
42+
return domNode;
43+
}
44+
45+
static formats(domNode: Element) {
46+
return ATTRIBUTES.reduce((formats: Record<string, string | null>, attribute) => {
47+
if (domNode.hasAttribute(attribute)) {
48+
formats[attribute] = domNode.getAttribute(attribute);
49+
}
50+
return formats;
51+
}, {});
52+
}
53+
}
54+
55+
export default Button;

0 commit comments

Comments
 (0)