Skip to content

Commit 312f75d

Browse files
committed
feat(rich-text-web): add quill-resize-module for image resizing
1 parent 9b0729c commit 312f75d

File tree

9 files changed

+423
-17
lines changed

9 files changed

+423
-17
lines changed

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

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

77
## [Unreleased]
88

9+
### Added
10+
11+
- We added support for resizing images, videos, and other embeds.
12+
913
## [4.3.0] - 2025-02-14
1014

1115
### Fixed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@
5151
"@mendix/widget-plugin-component-kit": "workspace:*",
5252
"@mendix/widget-plugin-platform": "workspace:*",
5353
"@mendix/widget-plugin-test-utils": "workspace:*",
54+
"@rollup/plugin-alias": "^5.1.1",
55+
"@rollup/plugin-image": "^3.0.3",
5456
"@rollup/plugin-json": "^4.1.0",
57+
"@rollup/plugin-replace": "^6.0.2",
58+
"@rollup/plugin-url": "^8.0.2",
5559
"@types/dompurify": "^2.4.0",
5660
"@types/katex": "^0.16.7",
5761
"@types/sanitize-html": "^1.27.2",
@@ -69,6 +73,7 @@
6973
"katex": "^0.16.11",
7074
"linkifyjs": "^4.1.3",
7175
"parchment": "^3.0.0",
72-
"quill": "^2.0.2"
76+
"quill": "^2.0.2",
77+
"quill-resize-module": "^2.0.4"
7378
}
7479
}
Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,31 @@
11
import preserveDirectives from "rollup-preserve-directives";
2+
import url from "@rollup/plugin-url";
3+
import image from "@rollup/plugin-image";
4+
import alias from "@rollup/plugin-alias";
25

36
export default args => {
47
const result = args.configDefaultConfig;
58
return result.map((config, _index) => {
6-
config.plugins = [...config.plugins, preserveDirectives()];
9+
config.plugins = [
10+
...config.plugins,
11+
preserveDirectives(),
12+
alias({
13+
entries: [
14+
{
15+
find: /(.*)\.svg\?raw$/,
16+
replacement: "$1.svg"
17+
}
18+
]
19+
}),
20+
url({
21+
include: ["**/*.svg"],
22+
limit: 0,
23+
fileName: "[name][extname]"
24+
}),
25+
image({
26+
include: ["**/*.svg"]
27+
})
28+
];
729
return config;
830
});
931
};

packages/pluggableWidgets/rich-text-web/src/components/Editor.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
MutableRefObject,
99
useEffect,
1010
useLayoutEffect,
11-
// useState,
1211
useRef
1312
} from "react";
1413
import "../utils/customPluginRegisters";
@@ -21,7 +20,6 @@ import {
2120
} from "./CustomToolbars/toolbarHandlers";
2221
import { useEmbedModal } from "./CustomToolbars/useEmbedModal";
2322
import Dialog from "./ModalDialog/Dialog";
24-
2523
export interface EditorProps {
2624
defaultValue?: string;
2725
onTextChange?: (...args: [delta: Delta, oldContent: Delta, source: EmitterSource]) => void;
@@ -112,7 +110,8 @@ const Editor = forwardRef((props: EditorProps, ref: MutableRefObject<Quill | nul
112110
image: customImageUploadHandler
113111
}
114112
}
115-
: false
113+
: false,
114+
resize: {}
116115
},
117116
readOnly
118117
};

packages/pluggableWidgets/rich-text-web/src/ui/RichTextIcons.scss

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ $icons: (
4242
List-roman: "\e921",
4343
Inline-code: "\e923",
4444
View-edit-code: "\e924",
45-
Code-block: "\e925"
45+
Code-block: "\e923",
46+
Resize-left: "\e923",
47+
Resize-right: "\e923",
48+
Resize-center: "\e923",
49+
Resize-restore: "\e923",
50+
Resize-alt: "\e923"
4651
);
4752

4853
.widget-rich-text {
@@ -52,6 +57,52 @@ $icons: (
5257
}
5358
}
5459

60+
.ql-container {
61+
.ql-resize-overlay {
62+
.ql-resize-toolbar {
63+
font-family: "RichTextIconFont" !important;
64+
font-style: normal;
65+
-webkit-font-smoothing: antialiased;
66+
-moz-osx-font-smoothing: grayscale;
67+
68+
button {
69+
position: relative;
70+
font-size: 0;
71+
color: transparent;
72+
> * {
73+
display: none;
74+
}
75+
76+
&:before {
77+
position: absolute;
78+
left: 50%;
79+
top: 50%;
80+
transform: translate(-50%, -50%);
81+
font-size: 16px;
82+
color: black;
83+
display: block;
84+
}
85+
86+
&:nth-child(1):before {
87+
content: map.get($icons, Resize-left);
88+
}
89+
&:nth-child(2):before {
90+
content: map.get($icons, Resize-right);
91+
}
92+
&:nth-child(3):before {
93+
content: map.get($icons, Resize-center);
94+
}
95+
&:nth-child(4):before {
96+
content: map.get($icons, Resize-restore);
97+
}
98+
&:nth-child(5):before {
99+
content: map.get($icons, Resize-alt);
100+
}
101+
}
102+
}
103+
}
104+
}
105+
55106
.icons {
56107
font-family: "RichTextIconFont" !important;
57108
font-size: 16px;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const alignment = Quill.import("attributors/style/align") as Attributor;
1212
import { IndentLeftStyle, IndentRightStyle } from "./formats/indent";
1313
import Formula from "./formats/formula";
1414
import CustomHeader from "./formats/header";
15+
import QuillResize from "quill-resize-module";
1516
class Empty {
1617
doSomething(): string {
1718
return "";
@@ -32,5 +33,6 @@ Quill.register(IndentRightStyle, true);
3233
Quill.register(Formula, true);
3334
Quill.register(CustomHeader, true);
3435
Quill.register(Button, true);
36+
Quill.register("modules/resize", QuillResize, true);
3537
// add empty handler for view code, this format is handled by toolbar's custom config via ViewCodeDialog
3638
Quill.register({ "ui/view-code": Empty });

packages/pluggableWidgets/rich-text-web/typings/global.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
export interface MXGlobalObject {
32
remoteUrl: string;
43
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
declare module "*.css";
2+
declare module "*.scss";
3+
4+
// Add quill-resize-module declaration
5+
declare module "quill-resize-module" {
6+
import Quill from "quill";
7+
8+
interface ResizeModuleOptions {
9+
modules?: string[];
10+
handleStyles?: {
11+
backgroundColor?: string;
12+
border?: string;
13+
boxSizing?: string;
14+
};
15+
displayStyles?: {
16+
backgroundColor?: string;
17+
border?: string;
18+
color?: string;
19+
};
20+
toolbarStyles?: {
21+
backgroundColor?: string;
22+
border?: string;
23+
color?: string;
24+
boxShadow?: string;
25+
};
26+
overlayStyles?: {
27+
border?: string;
28+
boxSizing?: string;
29+
};
30+
embedTags?: string[];
31+
tools?: Array<
32+
| string
33+
| {
34+
text: string;
35+
verify: (activeEle: HTMLElement) => boolean;
36+
handler: (evt: MouseEvent, button: HTMLElement, activeEle: HTMLElement) => void;
37+
}
38+
>;
39+
locale?: {
40+
altTip?: string;
41+
inputTip?: string;
42+
floatLeft?: string;
43+
floatRight?: string;
44+
center?: string;
45+
restore?: string;
46+
};
47+
}
48+
49+
interface ResizeModuleConstructor {
50+
new (quill: Quill, options: ResizeModuleOptions): any;
51+
Modules?: any;
52+
}
53+
54+
const ResizeModule: ResizeModuleConstructor;
55+
export default ResizeModule;
56+
}
57+
58+
// Add the dist/resize module declaration
59+
declare module "quill-resize-module/dist/resize" {
60+
export * from "quill-resize-module";
61+
export { default } from "quill-resize-module";
62+
}

0 commit comments

Comments
 (0)