2021-03-11 17:21:05 +00:00
|
|
|
|
2021-01-22 21:20:31 +00:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import { Searchbar, Popover, Popup, View, Page, List, ListItem, Navbar, NavRight, Link } from 'framework7-react';
|
2021-01-27 13:36:16 +00:00
|
|
|
import { Toggle } from 'framework7-react';
|
2021-01-28 10:27:18 +00:00
|
|
|
import { f7 } from 'framework7-react';
|
|
|
|
import { Dom7 } from 'framework7';
|
2021-01-22 21:20:31 +00:00
|
|
|
import { Device } from '../../../../common/mobile/utils/device';
|
2021-03-10 13:58:14 +00:00
|
|
|
import { observable, runInAction } from "mobx";
|
2021-01-28 10:27:18 +00:00
|
|
|
import { observer } from "mobx-react";
|
|
|
|
|
|
|
|
const searchOptions = observable({
|
2021-04-29 22:18:03 +00:00
|
|
|
usereplace: false,
|
|
|
|
isReplaceAll: false
|
2021-01-28 10:27:18 +00:00
|
|
|
});
|
2021-01-22 21:20:31 +00:00
|
|
|
|
|
|
|
const popoverStyle = {
|
|
|
|
height: '300px'
|
|
|
|
};
|
|
|
|
|
2021-01-29 07:01:02 +00:00
|
|
|
const SEARCH_BACKWARD = 'back';
|
|
|
|
const SEARCH_FORWARD = 'next';
|
|
|
|
|
2021-01-22 21:20:31 +00:00
|
|
|
class SearchSettingsView extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
useReplace: false,
|
2021-03-15 18:35:19 +00:00
|
|
|
// caseSensitive: false,
|
|
|
|
// markResults: false
|
|
|
|
searchIn: 0,
|
|
|
|
searchBy: 1,
|
|
|
|
lookIn: 1,
|
|
|
|
isMatchCase: false,
|
2021-04-29 22:18:03 +00:00
|
|
|
isMatchCell: false,
|
|
|
|
isReplaceAll: false
|
2021-01-22 21:20:31 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
onFindReplaceClick(action) {
|
2021-04-29 22:18:03 +00:00
|
|
|
runInAction(() => {
|
|
|
|
searchOptions.usereplace = action == 'replace';
|
|
|
|
searchOptions.isReplaceAll = action == 'replace-all';
|
|
|
|
});
|
2021-03-03 19:52:16 +00:00
|
|
|
|
2021-01-22 21:20:31 +00:00
|
|
|
this.setState({
|
2021-04-29 22:18:03 +00:00
|
|
|
useReplace: searchOptions.usereplace,
|
|
|
|
isReplaceAll: searchOptions.isReplaceAll
|
2021-01-22 21:20:31 +00:00
|
|
|
});
|
2021-01-28 10:27:18 +00:00
|
|
|
|
|
|
|
if (this.onReplaceChecked) {}
|
2021-01-22 21:20:31 +00:00
|
|
|
}
|
|
|
|
|
2021-01-28 16:23:28 +00:00
|
|
|
extraSearchOptions() {
|
|
|
|
}
|
|
|
|
|
2021-01-22 21:20:31 +00:00
|
|
|
render() {
|
2021-03-03 19:52:16 +00:00
|
|
|
const show_popover = !Device.phone;
|
2021-03-15 18:35:19 +00:00
|
|
|
// const navbar =
|
|
|
|
// <Navbar title="Find and replace">
|
|
|
|
// {!show_popover &&
|
|
|
|
// <NavRight>
|
|
|
|
// <Link popupClose=".search-settings-popup">Done</Link>
|
|
|
|
// </NavRight>
|
|
|
|
// }
|
|
|
|
// </Navbar>;
|
2021-01-28 16:23:28 +00:00
|
|
|
const extra = this.extraSearchOptions();
|
2021-01-22 21:20:31 +00:00
|
|
|
const content =
|
2021-03-10 16:51:22 +00:00
|
|
|
<View style={show_popover ? popoverStyle : null}>
|
2021-03-12 17:54:11 +00:00
|
|
|
{/* <Page>
|
|
|
|
{navbar} */}
|
|
|
|
{extra}
|
2021-03-15 18:35:19 +00:00
|
|
|
{/* </Page> */}
|
2021-01-22 21:20:31 +00:00
|
|
|
</View>;
|
|
|
|
return (
|
|
|
|
show_popover ?
|
|
|
|
<Popover id="idx-search-settings" className="popover__titled">{content}</Popover> :
|
2021-03-03 19:52:16 +00:00
|
|
|
<Popup id="idx-search-settings" className="search-settings-popup">{content}</Popup>
|
2021-01-22 21:20:31 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-15 18:35:19 +00:00
|
|
|
// @observer
|
2021-01-22 21:20:31 +00:00
|
|
|
class SearchView extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
2021-03-02 19:33:26 +00:00
|
|
|
this.state = {
|
|
|
|
searchQuery: '',
|
|
|
|
replaceQuery: ''
|
|
|
|
};
|
2021-03-10 16:51:22 +00:00
|
|
|
|
2021-01-22 21:20:31 +00:00
|
|
|
this.onSettingsClick = this.onSettingsClick.bind(this);
|
2021-01-28 10:27:18 +00:00
|
|
|
this.onSearchClick = this.onSearchClick.bind(this);
|
2021-03-02 19:33:26 +00:00
|
|
|
this.onReplaceClick = this.onReplaceClick.bind(this);
|
2021-01-22 21:20:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount(){
|
2021-03-02 19:33:26 +00:00
|
|
|
this.$replace = $$('#idx-replace-val');
|
2021-10-19 20:51:59 +00:00
|
|
|
const $editor = $$('#editor_sdk');
|
2021-12-12 07:12:41 +00:00
|
|
|
|
|
|
|
this.onEditorTouchStart = this.onEditorTouchStart.bind(this);
|
|
|
|
this.onEditorTouchEnd = this.onEditorTouchEnd.bind(this);
|
|
|
|
|
|
|
|
$editor.on('pointerdown', this.onEditorTouchStart);
|
|
|
|
$editor.on('pointerup', this.onEditorTouchEnd);
|
2021-10-19 20:51:59 +00:00
|
|
|
|
|
|
|
if( !this.searchbar ) {
|
|
|
|
this.searchbar = f7.searchbar.get('.searchbar');
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !this.searchbar ) {
|
|
|
|
this.searchbar = f7.searchbar.create({
|
|
|
|
el: '.searchbar',
|
|
|
|
customSearch: true,
|
|
|
|
expandable: true,
|
|
|
|
backdrop: false,
|
|
|
|
on: {
|
|
|
|
search: (bar, curval, prevval) => {
|
|
|
|
},
|
|
|
|
enable: this.onSearchbarShow.bind(this, true),
|
|
|
|
disable: this.onSearchbarShow.bind(this, false)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2021-10-15 22:13:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
2021-12-12 07:12:41 +00:00
|
|
|
$$('#editor_sdk').off('pointerdown', this.onEditorTouchStart)
|
|
|
|
.off('pointerup', this.onEditorTouchEnd);
|
2021-01-22 21:20:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onSettingsClick(e) {
|
|
|
|
if ( Device.phone ) {
|
2021-03-03 19:52:16 +00:00
|
|
|
f7.popup.open('.search-settings-popup');
|
2021-01-24 21:30:49 +00:00
|
|
|
} else f7.popover.open('#idx-search-settings', '#idx-btn-search-settings');
|
2021-01-22 21:20:31 +00:00
|
|
|
}
|
|
|
|
|
2021-01-28 10:27:18 +00:00
|
|
|
searchParams() {
|
|
|
|
let params = {
|
2021-01-28 16:23:28 +00:00
|
|
|
find: this.searchbar.query
|
2021-01-28 10:27:18 +00:00
|
|
|
};
|
2021-01-28 16:23:28 +00:00
|
|
|
|
2021-05-27 12:41:15 +00:00
|
|
|
if (searchOptions.usereplace || searchOptions.isReplaceAll) {
|
2021-01-28 16:23:28 +00:00
|
|
|
params.replace = this.$replace.val();
|
2021-03-05 17:53:37 +00:00
|
|
|
}
|
2021-01-28 16:23:28 +00:00
|
|
|
|
|
|
|
return params;
|
2021-01-28 10:27:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onSearchClick(action) {
|
2021-03-09 19:42:29 +00:00
|
|
|
if (this.searchbar && this.state.searchQuery) {
|
|
|
|
if (this.props.onSearchQuery) {
|
2021-01-28 16:23:28 +00:00
|
|
|
let params = this.searchParams();
|
2021-03-09 19:42:29 +00:00
|
|
|
params.find = this.state.searchQuery;
|
2021-01-29 07:01:02 +00:00
|
|
|
params.forward = action != SEARCH_BACKWARD;
|
2021-03-09 19:42:29 +00:00
|
|
|
// console.log(params);
|
2021-01-28 10:27:18 +00:00
|
|
|
|
|
|
|
this.props.onSearchQuery(params);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-02 19:33:26 +00:00
|
|
|
onReplaceClick() {
|
2022-01-19 17:33:47 +00:00
|
|
|
if (this.searchbar) {
|
2021-03-09 19:42:29 +00:00
|
|
|
if (this.props.onReplaceQuery) {
|
2021-03-02 19:33:26 +00:00
|
|
|
let params = this.searchParams();
|
2021-03-09 19:42:29 +00:00
|
|
|
params.find = this.state.searchQuery;
|
|
|
|
|
2021-03-02 19:33:26 +00:00
|
|
|
this.props.onReplaceQuery(params);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-03 19:52:16 +00:00
|
|
|
onReplaceAllClick() {
|
2022-01-19 17:33:47 +00:00
|
|
|
if (this.searchbar) {
|
2021-03-03 19:52:16 +00:00
|
|
|
if (this.props.onReplaceAllQuery) {
|
|
|
|
let params = this.searchParams();
|
2021-03-09 19:42:29 +00:00
|
|
|
params.find = this.state.searchQuery;
|
|
|
|
|
2021-03-03 19:52:16 +00:00
|
|
|
this.props.onReplaceAllQuery(params);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-29 07:01:02 +00:00
|
|
|
onSearchbarShow(isshowed, bar) {
|
|
|
|
if ( !isshowed ) {
|
2021-03-02 19:33:26 +00:00
|
|
|
this.$replace.val('');
|
2021-01-29 07:01:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onEditorTouchStart(e) {
|
2021-12-12 07:12:41 +00:00
|
|
|
console.log('taouch start');
|
2021-01-29 07:01:02 +00:00
|
|
|
this.startPoint = this.pointerPosition(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
onEditorTouchEnd(e) {
|
|
|
|
const endPoint = this.pointerPosition(e);
|
|
|
|
|
2021-03-15 18:35:19 +00:00
|
|
|
if (this.searchbar.enabled) {
|
|
|
|
let distance;
|
|
|
|
|
|
|
|
if(this.startPoint) {
|
2021-08-06 17:09:38 +00:00
|
|
|
distance = (this.startPoint.x === undefined || this.startPoint.y === undefined) ? 0 :
|
2021-03-15 18:35:19 +00:00
|
|
|
Math.sqrt((endPoint.x -= this.startPoint.x) * endPoint.x + (endPoint.y -= this.startPoint.y) * endPoint.y);
|
|
|
|
} else {
|
|
|
|
distance = 0;
|
|
|
|
}
|
2021-01-29 07:01:02 +00:00
|
|
|
|
2021-03-15 18:35:19 +00:00
|
|
|
if (distance < 1) {
|
2021-01-29 07:01:02 +00:00
|
|
|
this.searchbar.disable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pointerPosition(e) {
|
|
|
|
let out = {x:0, y:0};
|
2021-08-06 17:09:38 +00:00
|
|
|
if ( e.type == 'pointerdown' || e.type == 'pointerup' || e.type == 'mousedown' || e.type == 'mouseup') {
|
2021-01-29 07:01:02 +00:00
|
|
|
out.x = e.pageX;
|
|
|
|
out.y = e.pageY;
|
|
|
|
}
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2021-03-02 19:33:26 +00:00
|
|
|
changeSearchQuery(value) {
|
|
|
|
this.setState({
|
|
|
|
searchQuery: value
|
|
|
|
});
|
2021-10-28 08:31:21 +00:00
|
|
|
|
|
|
|
this.props.onchangeSearchQuery(value);
|
2021-03-02 19:33:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
changeReplaceQuery(value) {
|
|
|
|
this.setState({
|
|
|
|
replaceQuery: value
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-01-22 21:20:31 +00:00
|
|
|
render() {
|
2021-01-28 10:27:18 +00:00
|
|
|
const usereplace = searchOptions.usereplace;
|
2021-04-29 22:18:03 +00:00
|
|
|
const isReplaceAll = searchOptions.isReplaceAll;
|
2021-04-30 13:10:30 +00:00
|
|
|
const hidden = {display: "none"};
|
2021-03-02 19:33:26 +00:00
|
|
|
const searchQuery = this.state.searchQuery;
|
2021-10-28 08:31:21 +00:00
|
|
|
const replaceQuery = this.state.replaceQuery;
|
2021-03-05 17:53:37 +00:00
|
|
|
const isIos = Device.ios;
|
2021-03-15 18:35:19 +00:00
|
|
|
const { _t } = this.props;
|
2021-03-02 19:33:26 +00:00
|
|
|
|
2021-03-05 17:53:37 +00:00
|
|
|
if(this.searchbar && this.searchbar.enabled) {
|
2021-04-29 22:18:03 +00:00
|
|
|
usereplace || isReplaceAll ? this.searchbar.el.classList.add('replace') : this.searchbar.el.classList.remove('replace');
|
2021-03-09 19:42:29 +00:00
|
|
|
}
|
2021-03-02 19:33:26 +00:00
|
|
|
|
2021-01-22 21:20:31 +00:00
|
|
|
return (
|
|
|
|
<form className="searchbar">
|
2021-03-05 17:53:37 +00:00
|
|
|
{isIos ? <div className="searchbar-bg"></div> : null}
|
2021-01-22 21:20:31 +00:00
|
|
|
<div className="searchbar-inner">
|
2021-03-03 19:52:16 +00:00
|
|
|
<div className="buttons-row searchbar-inner__left">
|
2021-05-06 12:01:29 +00:00
|
|
|
<a id="idx-btn-search-settings" className="link icon-only no-fastclick" onClick={this.onSettingsClick}>
|
2021-01-22 21:20:31 +00:00
|
|
|
<i className="icon icon-settings" />
|
|
|
|
</a>
|
|
|
|
</div>
|
2021-03-03 19:52:16 +00:00
|
|
|
<div className="searchbar-inner__center">
|
|
|
|
<div className="searchbar-input-wrap">
|
2021-11-25 16:37:24 +00:00
|
|
|
<input className="searchbar-input" value={searchQuery} placeholder={_t.textSearch} type="search" maxLength="255"
|
2021-12-24 13:53:40 +00:00
|
|
|
onChange={e => {this.changeSearchQuery(e.target.value)}} />
|
2021-03-05 17:53:37 +00:00
|
|
|
{isIos ? <i className="searchbar-icon" /> : null}
|
2021-04-30 13:10:30 +00:00
|
|
|
<span className="input-clear-button" onClick={() => this.changeSearchQuery('')} />
|
2021-03-03 19:52:16 +00:00
|
|
|
</div>
|
2021-04-30 13:10:30 +00:00
|
|
|
{/* {usereplace || isReplaceAll ? */}
|
|
|
|
<div className="searchbar-input-wrap" style={usereplace || isReplaceAll ? null : hidden}>
|
2021-04-29 22:18:03 +00:00
|
|
|
{/* style={!usereplace ? hidden: null} */}
|
2021-10-28 08:31:21 +00:00
|
|
|
<input value={replaceQuery} placeholder={_t.textReplace} type="search" maxLength="255" id="idx-replace-val"
|
2021-04-29 22:18:03 +00:00
|
|
|
onChange={e => {this.changeReplaceQuery(e.target.value)}} />
|
|
|
|
{isIos ? <i className="searchbar-icon" /> : null}
|
2021-04-30 13:10:30 +00:00
|
|
|
<span className="input-clear-button" onClick={() => this.changeReplaceQuery('')} />
|
2021-04-29 22:18:03 +00:00
|
|
|
</div>
|
2021-04-30 13:10:30 +00:00
|
|
|
{/* */}
|
2021-01-22 21:20:31 +00:00
|
|
|
</div>
|
2021-03-03 19:52:16 +00:00
|
|
|
<div className="buttons-row searchbar-inner__right">
|
|
|
|
<div className="buttons-row buttons-row-replace">
|
2021-04-29 22:18:03 +00:00
|
|
|
{/* <a id="replace-link" className={"link " + (searchQuery.trim().length ? "" : "disabled")} style={!usereplace ? hidden: null} onClick={() => this.onReplaceClick()}>{_t.textReplace}</a>
|
|
|
|
<a id="replace-all-link" className={"link " + (searchQuery.trim().length ? "" : "disabled")} style={!usereplace ? hidden: null} onClick={() => this.onReplaceAllClick()}>{_t.textReplaceAll}</a> */}
|
2022-01-19 17:33:47 +00:00
|
|
|
|
|
|
|
{isReplaceAll ? (
|
2022-01-19 18:01:18 +00:00
|
|
|
<a id="replace-all-link" className={"link " + (replaceQuery.trim().length || searchQuery.trim().length ? "" : "disabled")} onClick={() => this.onReplaceAllClick()}>{_t.textReplaceAll}</a>
|
2022-01-19 17:33:47 +00:00
|
|
|
) : usereplace ? (
|
2022-01-19 18:01:18 +00:00
|
|
|
<a id="replace-link" className={"link " + (replaceQuery.trim().length || searchQuery.trim().length ? "" : "disabled")} onClick={() => this.onReplaceClick()}>{_t.textReplace}</a>
|
2021-04-29 22:18:03 +00:00
|
|
|
) : null}
|
2021-03-03 19:52:16 +00:00
|
|
|
</div>
|
|
|
|
<div className="buttons-row">
|
2021-05-06 12:01:29 +00:00
|
|
|
<a className={"link icon-only prev no-fastclick " + (searchQuery.trim().length ? "" : "disabled")} onClick={() => this.onSearchClick(SEARCH_BACKWARD)}>
|
2021-03-03 19:52:16 +00:00
|
|
|
<i className="icon icon-prev" />
|
|
|
|
</a>
|
2021-05-06 12:01:29 +00:00
|
|
|
<a className={"link icon-only next no-fastclick " + (searchQuery.trim().length ? "" : "disabled")} onClick={() => this.onSearchClick(SEARCH_FORWARD)}>
|
2021-03-03 19:52:16 +00:00
|
|
|
<i className="icon icon-next" />
|
|
|
|
</a>
|
|
|
|
</div>
|
2021-01-22 21:20:31 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
)
|
2021-10-15 22:13:31 +00:00
|
|
|
}
|
2021-01-22 21:20:31 +00:00
|
|
|
}
|
|
|
|
|
2021-03-15 18:35:19 +00:00
|
|
|
const SearchViewWithObserver = observer(SearchView);
|
2021-11-24 12:45:04 +00:00
|
|
|
const SearchSettingsViewWithObserver = observer(SearchSettingsView);
|
2021-03-15 18:35:19 +00:00
|
|
|
|
2021-11-24 12:45:04 +00:00
|
|
|
export {SearchViewWithObserver as SearchView, SearchSettingsViewWithObserver as SearchSettingsView};
|