mirror of
https://github.com/lowdefy/lowdefy.git
synced 2025-04-12 15:40:30 +08:00
feat(blocks): Add onTextSelection event to Html.
This commit is contained in:
parent
ab633e6f59
commit
4f00d5e885
@ -17,9 +17,10 @@
|
||||
import React from 'react';
|
||||
import { blockDefaultProps, HtmlComponent } from '@lowdefy/block-utils';
|
||||
|
||||
const HtmlBlock = ({ blockId, properties, methods }) => (
|
||||
const HtmlBlock = ({ blockId, events, properties, methods }) => (
|
||||
<HtmlComponent
|
||||
div={true}
|
||||
events={events}
|
||||
html={properties.html}
|
||||
id={blockId}
|
||||
methods={methods}
|
||||
|
@ -24,6 +24,7 @@ class HtmlComponent extends React.Component {
|
||||
this.div = {
|
||||
innerHTML: '',
|
||||
};
|
||||
this.onTextSelection = this.onTextSelection.bind(this);
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
@ -36,6 +37,19 @@ class HtmlComponent extends React.Component {
|
||||
this.div.innerHTML = DOMPurify.sanitize(htmlString);
|
||||
}
|
||||
|
||||
onTextSelection() {
|
||||
if (this.props.events.onTextSelection) {
|
||||
const selection = window.getSelection().toString();
|
||||
if (selection !== '') {
|
||||
this.props.methods.triggerEvent({
|
||||
name: 'onTextSelection',
|
||||
event: {
|
||||
selection: selection,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
render() {
|
||||
const { div, id, methods, style } = this.props;
|
||||
if (div === true) {
|
||||
@ -49,6 +63,7 @@ class HtmlComponent extends React.Component {
|
||||
}
|
||||
}}
|
||||
className={methods.makeCssClass(style)}
|
||||
onMouseUp={this.onTextSelection}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user