mirror of
https://github.com/lowdefy/lowdefy.git
synced 2025-04-12 15:40:30 +08:00
fix(blocks): Add onTextSelection to Paragraph and document.
This commit is contained in:
parent
4f00d5e885
commit
7325633d27
@ -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>
|
||||
);
|
||||
|
||||
|
@ -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."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user