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 4 issues #234

Merged
merged 1 commit into from
Feb 13, 2019
Merged
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
7 changes: 2 additions & 5 deletions packages/roosterjs-editor-core/lib/coreAPI/select.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import EditorCore, { Select } from '../interfaces/EditorCore';
import hasFocus from './hasFocus';
import { Browser, contains, createRange, Position } from 'roosterjs-editor-dom';
import { contains, createRange, Position } from 'roosterjs-editor-dom';
import { NodePosition, PositionType } from 'roosterjs-editor-types';

const select: Select = (core: EditorCore, arg1: any, arg2?: any, arg3?: any, arg4?: any) => {
Expand Down Expand Up @@ -40,10 +40,7 @@ const select: Select = (core: EditorCore, arg1: any, arg2?: any, arg3?: any, arg
try {
// Do not remove/add range if current selection is the same with target range
// Without this check, execCommand() may fail in Edge since we changed the selection
let currentRange =
Browser.isEdge && selection.rangeCount == 1
? selection.getRangeAt(0)
: null;
let currentRange = selection.rangeCount == 1 ? selection.getRangeAt(0) : null;
if (
currentRange &&
currentRange.startContainer == range.startContainer &&
Expand Down
12 changes: 7 additions & 5 deletions packages/roosterjs-editor-types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"name": "roosterjs-editor-types",
"description": "Type definition for roosterjs",
"dependencies": {},
"main": "./lib/index.ts"
}
"name": "roosterjs-editor-types",
"description": "Type definition for roosterjs",
"dependencies": {
"@types/dom-inputevent": "^1.0.3"
},
"main": "./lib/index.ts"
}
46 changes: 8 additions & 38 deletions publish/samplesite/scripts/controls/ribbon/RibbonButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { Browser } from 'roosterjs-editor-dom';
import { FormatState } from 'roosterjs-editor-types';

const styles = require('./RibbonButton.scss');
let currentPusingButton: RibbonButtonType;

export interface RibbonButtonProps {
plugin: RibbonPlugin;
Expand All @@ -19,10 +18,6 @@ export interface RibbonButtonState {
isDropDownShown: boolean;
}

interface MouseEvent extends React.MouseEvent<EventTarget> {
detail: number;
}

export default class RibbonButton extends React.Component<RibbonButtonProps, RibbonButtonState> {
private range: Range;

Expand All @@ -49,10 +44,8 @@ export default class RibbonButton extends React.Component<RibbonButtonProps, Rib
return (
<span className={styles.dropDownButton}>
<button
onClick={button.dropDownItems ? this.onShowDropDown : this.onMouseClick}
className={className}
onMouseDown={this.onMouseDown}
onMouseUp={this.onMouseUp}>
onClick={button.dropDownItems ? this.onShowDropDown : () => this.onExecute()}
className={className}>
<img src={button.image} width={32} height={32} title={button.title} />
</button>
{button.dropDownItems &&
Expand All @@ -62,33 +55,6 @@ export default class RibbonButton extends React.Component<RibbonButtonProps, Rib
);
}

private onMouseDown = (e: React.MouseEvent<EventTarget>) => {
if (e.button == 0) {
currentPusingButton = this.props.button;
e.preventDefault();
}
};

private onMouseUp = (e: React.MouseEvent<EventTarget>) => {
if (
e.button == 0 &&
currentPusingButton == this.props.button &&
!this.props.button.dropDownItems
) {
this.onExecute();
}
currentPusingButton = null;
};

private onMouseClick = (e: React.MouseEvent<EventTarget>) => {
if (
(Browser.isIE && e.nativeEvent.x < 0) ||
(!Browser.isIE && (e as MouseEvent).detail == 0)
) {
this.onExecute();
}
};

private onExecute = (value?: string) => {
const { button, plugin } = this.props;
const editor = plugin.getEditor();
Expand All @@ -102,7 +68,9 @@ export default class RibbonButton extends React.Component<RibbonButtonProps, Rib
};

private onShowDropDown = () => {
this.range = this.props.plugin.getEditor().getSelectionRange();
if (Browser.isSafari) {
this.range = this.props.plugin.getEditor().getSelectionRange();
}

if (!this.props.button.preserveOnClickAway) {
document.addEventListener('click', this.onHideDropDown);
Expand All @@ -113,7 +81,9 @@ export default class RibbonButton extends React.Component<RibbonButtonProps, Rib
};

private onHideDropDown = () => {
this.props.plugin.getEditor().select(this.range);
if (Browser.isSafari) {
this.props.plugin.getEditor().select(this.range);
}

document.removeEventListener('click', this.onHideDropDown);
this.setState({
Expand Down
9 changes: 0 additions & 9 deletions tools/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ async function pack(isProduction, isAmd) {
countWord(targetFile);
exploreSourceMap(targetFile);
}
insertLicense(targetFile);
resolve();
}
});
Expand Down Expand Up @@ -288,14 +287,6 @@ function exploreSourceMap(inputFile) {
runNode(`${commandPath} -m --html ${inputFile} > ${targetFile}`, rootPath);
}

function insertLicense(filename) {
var fileContent = fs.readFileSync(filename).toString();
fs.writeFileSync(
filename,
`/*\r\n VERSION: ${version}\r\n\r\n${license}\r\n*/\r\n${fileContent}`
);
}

var dtsQueue = [];
var dtsFileName;

Expand Down