fix(blocks): Add onTextSelection to Paragraph and document.

This commit is contained in:
Johann Moller 2023-10-06 11:04:55 +02:00
parent 4f00d5e885
commit 7325633d27
5 changed files with 19 additions and 4 deletions

View File

@ -101,7 +101,7 @@ const ParagraphBlock = ({ blockId, components: { Icon }, events, methods, proper
type={properties.type}
underline={properties.underline}
>
{renderHtml({ html: properties.content, methods })}
{renderHtml({ html: properties.content, events, methods })}
</Paragraph>
);

View File

@ -125,6 +125,10 @@
"onCopy": {
"type": "array",
"description": "Trigger action when copy text is clicked."
},
"onTextSelection": {
"type": "array",
"description": "Trigger action when text is selected and pass selected text to the event object."
}
}
}

View File

@ -19,5 +19,15 @@
}
}
}
},
"events": {
"type": "object",
"additionalProperties": false,
"properties": {
"onTextSelection": {
"type": "array",
"description": "Trigger action when text is selected and pass selected text to the event object."
}
}
}
}

View File

@ -38,7 +38,7 @@ class HtmlComponent extends React.Component {
}
onTextSelection() {
if (this.props.events.onTextSelection) {
if (this.props.events?.onTextSelection) {
const selection = window.getSelection().toString();
if (selection !== '') {
this.props.methods.triggerEvent({
@ -77,6 +77,7 @@ class HtmlComponent extends React.Component {
}
}}
className={methods.makeCssClass(style)}
onMouseUp={this.onTextSelection}
/>
);
}

View File

@ -19,9 +19,9 @@ import { type } from '@lowdefy/helpers';
import HtmlComponent from './HtmlComponent.js';
const renderHtml = ({ div, html, id, methods, style }) =>
const renderHtml = ({ div, events, html, id, methods, style }) =>
type.isNone(html) ? undefined : (
<HtmlComponent div={div} html={html} id={id} methods={methods} style={style} />
<HtmlComponent div={div} events={events} html={html} id={id} methods={methods} style={style} />
);
export default renderHtml;