Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: multiple feedbacks fix #1384

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,24 @@ export function getProperties(values: RichTextPreviewProps, defaultProperties: P
hidePropertiesIn(defaultProperties, values, toolbarGroupKeys);
}

if (values.heightUnit === "pixels") {
if (values.heightUnit === "percentageOfWidth") {
hidePropertyIn(defaultProperties, values, "height");
} else {
hidePropertiesIn(defaultProperties, values, [
"minHeight",
"minHeightUnit",
"maxHeight",
"maxHeightUnit",
"OverflowY"
]);
}

if (values.minHeightUnit === "none") {
hidePropertyIn(defaultProperties, values, "minHeight");
}

if (values.widthUnit === "percentage" && values.heightUnit === "percentageOfWidth") {
hidePropertyIn(defaultProperties, values, "height");
if (values.maxHeightUnit === "none") {
hidePropertiesIn(defaultProperties, values, ["maxHeight", "OverflowY"]);
}

if (!values.onChange) {
Expand Down
11 changes: 2 additions & 9 deletions packages/pluggableWidgets/rich-text-web/src/RichText.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ValidationAlert } from "@mendix/widget-plugin-component-kit/Alert";
import { getDimensions } from "@mendix/widget-plugin-platform/utils/get-dimensions";
import classNames from "classnames";
import { createElement, Fragment, useEffect, useState } from "react";
import { RichTextContainerProps } from "../typings/RichTextProps";
Expand All @@ -8,15 +7,9 @@ import "./ui/RichText.scss";
import { constructWrapperStyle } from "./utils/helpers";

export default function RichText(props: RichTextContainerProps): JSX.Element {
const { stringAttribute, width: w, height: h, widthUnit, heightUnit, readOnlyStyle } = props;
const { stringAttribute, readOnlyStyle } = props;

const { width, height } = getDimensions({
width: w,
widthUnit,
height: h,
heightUnit
});
const wrapperStyle = constructWrapperStyle(props, { width, height });
const wrapperStyle = constructWrapperStyle(props);
const [isIncubator, setIsIncubator] = useState(true);

useEffect(() => {
Expand Down
42 changes: 38 additions & 4 deletions packages/pluggableWidgets/rich-text-web/src/RichText.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
<propertyGroup caption="Dimensions">
<property key="widthUnit" type="enumeration" defaultValue="percentage">
<caption>Width unit</caption>
<description>Percentage: portion of parent size. Pixels: absolute amount of pixels.</description>
<description />
<enumerationValues>
<enumerationValue key="percentage">Percentage</enumerationValue>
<enumerationValue key="pixels">Pixels</enumerationValue>
Expand All @@ -78,18 +78,52 @@
<caption>Height unit</caption>
<description />
<enumerationValues>
<enumerationValue key="percentageOfWidth">Percentage of width</enumerationValue>
<enumerationValue key="percentageOfWidth">Auto</enumerationValue>
<enumerationValue key="pixels">Pixels</enumerationValue>
<enumerationValue key="percentageOfParent">Percentage of parent</enumerationValue>
<enumerationValue key="percentageOfParent">Percentage</enumerationValue>
<enumerationValue key="percentageOfView">Viewport</enumerationValue>
</enumerationValues>
</property>
<property key="height" type="integer" defaultValue="250">
<caption>Height</caption>
<description />
</property>
<property key="minHeightUnit" type="enumeration" defaultValue="none">
<caption>Minimum Height unit</caption>
<description />
<enumerationValues>
<enumerationValue key="none">None</enumerationValue>
<enumerationValue key="pixels">Pixels</enumerationValue>
<enumerationValue key="percentageOfParent">Percentage</enumerationValue>
<enumerationValue key="percentageOfView">Viewport</enumerationValue>
</enumerationValues>
</property>
<property key="minHeight" type="integer" defaultValue="250">
<caption>Minimum height</caption>
<description>Editor's minimum height. The number value is in pixels.</description>
<description />
</property>
<property key="maxHeightUnit" type="enumeration" defaultValue="none">
<caption>Maximum Height unit</caption>
<description />
<enumerationValues>
<enumerationValue key="none">None</enumerationValue>
<enumerationValue key="pixels">Pixels</enumerationValue>
<enumerationValue key="percentageOfParent">Percentage</enumerationValue>
<enumerationValue key="percentageOfView">Viewport</enumerationValue>
</enumerationValues>
</property>
<property key="maxHeight" type="integer" defaultValue="250">
<caption>Maximum height</caption>
<description />
</property>
<property key="OverflowY" type="enumeration" defaultValue="auto">
<caption>Vertical Overflow</caption>
<description />
<enumerationValues>
<enumerationValue key="auto">Auto</enumerationValue>
<enumerationValue key="scroll">Scroll</enumerationValue>
<enumerationValue key="hidden">Hidden</enumerationValue>
</enumerationValues>
</property>
</propertyGroup>
</propertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@
className?: string;
toolbarId?: string | Array<string | string[] | { [k: string]: any }>;
readOnly?: boolean;
tabIndex?: number;
}

// Editor is an uncontrolled React component
const Editor = forwardRef((props: EditorProps, ref: MutableRefObject<Quill | null>) => {
const { theme, defaultValue, style, className, toolbarId, onTextChange, onSelectionChange, readOnly } = props;
const { theme, defaultValue, style, className, toolbarId, onTextChange, onSelectionChange, readOnly, tabIndex } =

Check warning on line 34 in packages/pluggableWidgets/rich-text-web/src/components/Editor.tsx

View workflow job for this annotation

GitHub Actions / Run code quality check

'tabIndex' is assigned a value but never used. Allowed unused vars must match /createElement/u
props;
const containerRef = useRef<HTMLDivElement>(null);
const modalRef = useRef<HTMLDivElement>(null);
const onTextChangeRef = useRef(onTextChange);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
onLoad,
readOnlyStyle,
toolbarOptions,
enableStatusBar
enableStatusBar,
tabIndex
} = props;
const isFirstLoad = useRef<boolean>(false);
const quillRef = useRef<Quill>(null);
Expand All @@ -55,7 +56,7 @@
}
}
}, 200),
[stringAttribute]

Check warning on line 59 in packages/pluggableWidgets/rich-text-web/src/components/EditorWrapper.tsx

View workflow job for this annotation

GitHub Actions / Run code quality check

React Hook useMemo has missing dependencies: 'onChange' and 'onChangeType'. Either include them or remove the dependency array
);
const calculateWordCount = useCallback(
(quill: Quill | null): void => {
Expand Down Expand Up @@ -100,7 +101,6 @@
if (!isFocus) {
setIsFocus(true);
executeAction(onFocus);

editorValueRef.current = quillRef.current?.getText() || "";
}
} else {
Expand Down Expand Up @@ -132,44 +132,40 @@
"flex-column",
`${stringAttribute?.readOnly ? `editor-${readOnlyStyle}` : ""}`
)}
style={{
maxWidth: style?.maxWidth
}}
style={{ width: style?.width }}
onClick={e => {
// click on other parts of editor, such as the toolbar, should also set focus
if (
toolbarRef.current === (e.target as HTMLDivElement) ||
toolbarRef.current?.contains(e.target as Node)
) {
quillRef?.current?.focus();
if (!quillRef?.current?.hasFocus()) {
if (
toolbarRef.current === (e.target as HTMLDivElement) ||
toolbarRef.current?.contains(e.target as Node) ||
e.target === quillRef?.current?.container.parentElement
) {
quillRef?.current?.focus();
}
}
}}
spellCheck={props.spellCheck}
tabIndex={tabIndex}
>
{toolbarLocation === "auto" && <StickySentinel />}
<div
className={classNames(
"flexcontainer",
toolbarLocation === "bottom" ? "flex-column-reverse" : "flex-column"
toolbarLocation === "top" ? "flex-column-reverse" : "flex-column"
)}
>
<If condition={!shouldHideToolbar && toolbarOptions === undefined}>
<Toolbar
ref={toolbarRef}
id={toolbarId}
preset={preset}
quill={quillRef.current}
toolbarContent={toolbarPreset}
/>
</If>
<Editor
tabIndex={tabIndex}
theme={"snow"}
ref={quillRef}
defaultValue={stringAttribute.value}
// style={{height: style?.height}}
style={{
height: style?.height,
minHeight: style?.minHeight,
maxHeight: style?.maxHeight
maxHeight: style?.maxHeight,
overflowY: style?.overflowY
}}
toolbarId={shouldHideToolbar ? undefined : toolbarOptions ? toolbarOptions : toolbarId}
onTextChange={onTextChange}
Expand All @@ -178,6 +174,15 @@
readOnly={stringAttribute.readOnly}
key={`${toolbarId}_${stringAttribute.readOnly}`}
/>
<If condition={!shouldHideToolbar && toolbarOptions === undefined}>
<Toolbar
ref={toolbarRef}
id={toolbarId}
preset={preset}
quill={quillRef.current}
toolbarContent={toolbarPreset}
/>
</If>
</div>
{enableStatusBar && (
<div className="widget-rich-text-footer">
Expand Down
32 changes: 22 additions & 10 deletions packages/pluggableWidgets/rich-text-web/src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,31 @@
import { Delta, Op } from "quill/core";
import { RichTextContainerProps } from "typings/RichTextProps";

export function constructWrapperStyle(props: RichTextContainerProps, currentStyle: CSSProperties): CSSProperties {
const { width, height } = currentStyle;
const { minHeight, heightUnit, widthUnit } = props;
function getHeightScale(height: number, heightUnit: "pixels" | "percentageOfParent" | "percentageOfView") {

Check warning on line 6 in packages/pluggableWidgets/rich-text-web/src/utils/helpers.ts

View workflow job for this annotation

GitHub Actions / Run code quality check

Missing return type on function
return `${height}${heightUnit === "pixels" ? "px" : heightUnit === "percentageOfView" ? "vh" : "%"}`;
}

const wrapperStyle: Pick<CSSProperties, "width" | "height" | "minHeight" | "maxWidth"> = { width, height };
export function constructWrapperStyle(props: RichTextContainerProps): CSSProperties {
const { widthUnit, heightUnit, minHeightUnit, maxHeightUnit, width, height, minHeight, maxHeight, OverflowY } =
props;

if (heightUnit !== "pixels") {
wrapperStyle.minHeight = minHeight;
delete wrapperStyle.height;
}
const wrapperStyle: Pick<CSSProperties, "width" | "height" | "minHeight" | "maxHeight" | "maxWidth" | "overflowY"> =
{};

wrapperStyle.width = `${width}${widthUnit === "pixels" ? "px" : "%"}`;
if (heightUnit === "percentageOfWidth") {
wrapperStyle.height = "auto";

if (widthUnit === "pixels") {
wrapperStyle.maxWidth = width;
if (minHeightUnit !== "none") {
wrapperStyle.minHeight = getHeightScale(minHeight, minHeightUnit);
}

if (maxHeightUnit !== "none") {
wrapperStyle.maxHeight = getHeightScale(maxHeight, maxHeightUnit);
wrapperStyle.overflowY = OverflowY;
}
} else {
wrapperStyle.height = getHeightScale(height, heightUnit);
}

return wrapperStyle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,23 @@ export default class MendixTheme extends SnowTheme {

/** updating font picker selected item based on current's selection font */
updateFontPicker(range: Range): void {
const currentRange = range || { index: 0, length: 0 };
if (!this.fontPicker) {
this.fontPicker = this.pickers.find(picker => picker.container.classList.contains("ql-font"));
}
if (this.pickers) {
const currentRange = range || { index: 0, length: 0 };
if (!this.fontPicker) {
this.fontPicker = this.pickers.find(picker => picker.container.classList.contains("ql-font"));
}

const format = this.quill.getFormat(currentRange.index, currentRange.length);
let font = format ? (format.font as string) : undefined;
if (!font) {
// default font
font = "helvetica";
}
const format = this.quill.getFormat(currentRange.index, currentRange.length);
let font = format ? (format.font as string) : undefined;
if (!font) {
// default font
font = "helvetica";
}

const currentOption = this.fontPicker?.container.querySelector(`[data-value=${font}]`);
if (currentOption) {
this.fontPicker?.selectItem(currentOption as HTMLElement, false);
const currentOption = this.fontPicker?.container.querySelector(`[data-value=${font}]`);
if (currentOption) {
this.fontPicker?.selectItem(currentOption as HTMLElement, false);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ export type ReadOnlyStyleEnum = "text" | "bordered" | "readPanel";

export type WidthUnitEnum = "percentage" | "pixels";

export type HeightUnitEnum = "percentageOfWidth" | "pixels" | "percentageOfParent";
export type HeightUnitEnum = "percentageOfWidth" | "pixels" | "percentageOfParent" | "percentageOfView";

export type MinHeightUnitEnum = "none" | "pixels" | "percentageOfParent" | "percentageOfView";

export type MaxHeightUnitEnum = "none" | "pixels" | "percentageOfParent" | "percentageOfView";

export type OverflowYEnum = "auto" | "scroll" | "hidden";

export type OnChangeTypeEnum = "onLeave" | "onDataChange";

Expand Down Expand Up @@ -42,7 +48,11 @@ export interface RichTextContainerProps {
width: number;
heightUnit: HeightUnitEnum;
height: number;
minHeightUnit: MinHeightUnitEnum;
minHeight: number;
maxHeightUnit: MaxHeightUnitEnum;
maxHeight: number;
OverflowY: OverflowYEnum;
onChange?: ActionValue;
onFocus?: ActionValue;
onBlur?: ActionValue;
Expand Down Expand Up @@ -76,7 +86,11 @@ export interface RichTextPreviewProps {
width: number | null;
heightUnit: HeightUnitEnum;
height: number | null;
minHeightUnit: MinHeightUnitEnum;
minHeight: number | null;
maxHeightUnit: MaxHeightUnitEnum;
maxHeight: number | null;
OverflowY: OverflowYEnum;
onChange: {} | null;
onFocus: {} | null;
onBlur: {} | null;
Expand Down
Loading