From 6d4dff36e70ce6abd76d3a1db52ad870334171ac Mon Sep 17 00:00:00 2001 From: Chupurnov Valeriy Date: Tue, 13 Mar 2018 00:26:20 +0500 Subject: [PATCH] Fixed visibiliti for tooltip --- package-lock.json | 18 +++--- package.json | 9 +-- src/modules/Selection.ts | 8 ++- src/plugins/formatBlock.ts | 5 +- src/plugins/source.ts | 29 +++++++++ src/styles/modules/dropdownlist.less | 2 +- test/bootstrap.js | 4 +- test/tests/commandsTest.js | 97 +++++++++++++++++++++++----- test/tests/imageTest.js | 41 ++++++++++++ test/tests/mirrorTest.js | 52 ++++++++++++--- 10 files changed, 218 insertions(+), 47 deletions(-) diff --git a/package-lock.json b/package-lock.json index 51c66496c..69f9b6fa1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,9 +20,9 @@ } }, "@types/node": { - "version": "7.0.55", - "resolved": "https://registry.npmjs.org/@types/node/-/node-7.0.55.tgz", - "integrity": "sha512-diCxfWNT4g2UM9Y+BPgy4s3egcZ2qOXc0mXLauvbsBUq9SBKQfh0SmuEUEhJVFZt/p6UDsjg1s2EgfM6OSlp4g==", + "version": "7.0.56", + "resolved": "https://registry.npmjs.org/@types/node/-/node-7.0.56.tgz", + "integrity": "sha512-NgjN3xPyqbAXSIpznNAR5Cisx5uKqJWxcS9kefzSFEX/9J7O01/FHyfnvPI7SztBf9p6c8mqOn3olZWJx3ja6g==", "dev": true }, "accepts": { @@ -4811,9 +4811,9 @@ } }, "less-loader": { - "version": "4.0.6", - "resolved": "https://registry.npmjs.org/less-loader/-/less-loader-4.0.6.tgz", - "integrity": "sha512-WPFY3NMJGJna8kIxtgSu6AVG7K6uRPdfE2J7vpQqFWMN/RkOosV09rOVUt3wghNClWH2Pg7YumD1dHiv1Thfug==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/less-loader/-/less-loader-4.1.0.tgz", + "integrity": "sha512-KNTsgCE9tMOM70+ddxp9yyt9iHqgmSs0yTZc5XH5Wo+g80RWRIYNqE58QJKm/yMud5wZEvz50ugRDuzVIkyahg==", "dev": true, "requires": { "clone": "2.1.1", @@ -10188,9 +10188,9 @@ } }, "webpack-hot-middleware": { - "version": "2.21.1", - "resolved": "https://registry.npmjs.org/webpack-hot-middleware/-/webpack-hot-middleware-2.21.1.tgz", - "integrity": "sha512-HaxZpATbq/bpuduum2i79pgE1vpSFfV2BVUyYi4lhocTJ5xpofWuYCCmd0c6eoJjY8szCuM5TsQk3M59Z9jpwA==", + "version": "2.21.2", + "resolved": "https://registry.npmjs.org/webpack-hot-middleware/-/webpack-hot-middleware-2.21.2.tgz", + "integrity": "sha512-N5c80o31E0COFJV8HRjiX3hJetDOwQ2Ajt5TTORKA9diOimhFtmaZKSfO3pQKMeQngb7I4TUnNDroJiUzPFhKQ==", "dev": true, "requires": { "ansi-html": "0.0.7", diff --git a/package.json b/package.json index 2387336b9..7ff129ee9 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "newversiongit": "git add --all && git commit -m \"New version %npm_package_version%. Read more https://github.com/xdan/jodit/releases/tag/%npm_package_version% \" && git tag %npm_package_version% && git push --tags origin HEAD:master", "start": "node server.js", "build": "rm -f build/* && cross-env NODE_ENV=production webpack --progress", - "test": "karma start --browsers Firefox karma.conf.js --single-run" + "test": "karma start --browsers Firefox karma.conf.js --single-run", + "jodit": "cd ../jodit-angular/ && npm run newversion && cd ../jodit-joomla && npm run newversion" }, "repository": { "type": "git", @@ -29,7 +30,7 @@ "devDependencies": { "@types/ace": "^0.0.35", "@types/es6-promise": "^3.3.0", - "@types/node": "^7.0.55", + "@types/node": "^7.0.56", "autoprefixer": "^6.7.7", "awesome-typescript-loader": "^3.4.1", "chai": "^3.5.0", @@ -51,7 +52,7 @@ "karma-sourcemap-loader": "^0.3.7", "karma-webpack": "^2.0.9", "less": "^2.7.3", - "less-loader": "^4.0.5", + "less-loader": "^4.1.0", "mocha": "^3.4.2", "optimize-css-assets-webpack-plugin": "^3.2.0", "postcss-loader": "^2.1.0", @@ -63,7 +64,7 @@ "webpack": "^3.11.0", "webpack-dev-middleware": "^1.12.2", "webpack-dev-server": "^2.11.1", - "webpack-hot-middleware": "^2.21.0" + "webpack-hot-middleware": "^2.21.2" }, "dependencies": {} } diff --git a/src/modules/Selection.ts b/src/modules/Selection.ts index bddfb912b..ab06a024d 100644 --- a/src/modules/Selection.ts +++ b/src/modules/Selection.ts @@ -427,7 +427,7 @@ export class Select extends Component{ * parent.selection.insertHTML(''); * ``` */ - insertHTML(html: number|string|Node) { + insertHTML(html: number | string | Node) { if (html === '') { return; } @@ -439,7 +439,7 @@ export class Select extends Component{ lastChild: Node|null, lastEditorElement: Node|null; - if (!this.isFocused()) { + if (!this.isFocused() && this.jodit.isEditorMode()) { this.focus(); } @@ -449,6 +449,10 @@ export class Select extends Component{ node.appendChild(html); } + if (!this.jodit.isEditorMode() && this.jodit.events.fire('insertHTML', node.innerHTML) === false) { + return; + } + lastChild = node.lastChild; while (node.firstChild) { diff --git a/src/plugins/formatBlock.ts b/src/plugins/formatBlock.ts index 032a21536..cb1e2a17f 100644 --- a/src/plugins/formatBlock.ts +++ b/src/plugins/formatBlock.ts @@ -9,6 +9,7 @@ import {Dom} from "../modules/Dom"; import * as consts from '../constants'; import {Config} from "../Config"; import {ToolbarButton, ControlType} from "../modules/ToolbarCollection"; +import {markerInfo} from "../modules/Selection"; Config.prototype.controls.paragraph = { @@ -89,8 +90,8 @@ export function formatBlock(editor: Jodit) { let work: boolean = false; editor.selection.eachSelection((current: Node): false | void => { - const selectionInfo = editor.selection.save(); - let currentBox: HTMLElement|false = current ? Dom.up(current, Dom.isBlock, editor.editor) : false; + const selectionInfo: markerInfo[] = editor.selection.save(); + let currentBox: HTMLElement | false = current ? Dom.up(current, Dom.isBlock, editor.editor) : false; if (!currentBox && current) { currentBox = Dom.wrap(current, editor.options.enter, editor); diff --git a/src/plugins/source.ts b/src/plugins/source.ts index 9c4645b37..efd23b2f5 100644 --- a/src/plugins/source.ts +++ b/src/plugins/source.ts @@ -140,6 +140,21 @@ export class source extends Component { } }; + private insertHTML = (html: string) => { + if (this.mirror.selectionStart || this.mirror.selectionStart === 0) { + let startPos: number = this.mirror.selectionStart, + endPos: number = this.mirror.selectionEnd; + + this.mirror.value = this.mirror.value.substring(0, startPos) + + html + + this.mirror.value.substring(endPos, this.mirror.value.length); + } else { + this.mirror.value += this.mirror; + } + + this.toWYSIWYG(); + }; + private __lock = false; private toWYSIWYG = () => { @@ -190,6 +205,12 @@ export class source extends Component { }); editor.events + .on('insertHTML', (html: string): void | false => { + if (!editor.options.readonly && !this.jodit.isEditorMode()) { + this.insertHTML(html); + return false; + } + }) .on('aceInited', () => { if (editor.options.readonly) { if (this.aceEditor) { @@ -505,6 +526,14 @@ export class source extends Component { this.selectAll = () => { aceEditor.selection.selectAll(); }; + this.insertHTML = (html: string) => { + let start: AceAjax.Position = aceEditor.selection.getCursor(), + end: AceAjax.Position = aceEditor.session.insert(start, html); + + aceEditor.selection.setRange({ + start, end + }, false); + }; this.setMirrorSelectionRange = (start: number, end: number) => { setSelectionRangeIndices(start, end); diff --git a/src/styles/modules/dropdownlist.less b/src/styles/modules/dropdownlist.less index 27828d5fc..2a6b77e46 100644 --- a/src/styles/modules/dropdownlist.less +++ b/src/styles/modules/dropdownlist.less @@ -24,7 +24,7 @@ z-index:@z-index-dropdownlist; left: 0; top: 100%; - + overflow: visible; h5,h4,h3,h2,h1,p,blockquote, pre { font-family: @font-default; margin: 0; diff --git a/test/bootstrap.js b/test/bootstrap.js index 36aa0607d..ffc2b7267 100644 --- a/test/bootstrap.js +++ b/test/bootstrap.js @@ -1,4 +1,4 @@ -chai.config.includeStack = true; +(typeof chai !== 'undefined') && (chai.config.includeStack = true); Jodit.defaultOptions.observer.timeout = 0; Jodit.defaultOptions.useAceEditor = false; @@ -36,7 +36,7 @@ if (String.prototype.repeat === undefined) { })(Element.prototype); -var expect = chai.expect; +var expect = typeof chai !== 'undefined' ? chai.expect : function () {}; var stuff = []; var removeStuff = function () { stuff.forEach(function (elm) { diff --git a/test/tests/commandsTest.js b/test/tests/commandsTest.js index 0c1a3fff0..3aaf7bdc3 100644 --- a/test/tests/commandsTest.js +++ b/test/tests/commandsTest.js @@ -86,24 +86,67 @@ describe('Commands Jodit Editor Tests', function() { expect(editor.getEditorValue()).to.equal('

test

'); }); - describe('For UL>li elements', function () { - it('Should replace all LI elements to P and unwrap it from UL', function () { - var editor = new Jodit(appendTestArea()); - editor.value = '
    ' + - '
  • 1
  • ' + - '
  • 2
  • ' + - '
  • 3
  • ' + - '
'; - - var range = editor.editorDocument.createRange(); - range.selectNodeContents(editor.editor.firstChild); - editor.selection.selectRange(range); - editor.execCommand('formatBlock', false, 'p'); - except(editor.value).to.be.equal('

1

' + - '

2

' + - '

3

' - ) + describe('For UL>li elements', function () { + describe('Select only LI', function () { + it('Should replace all LI elements to P and unwrap it from UL', function () { + var editor = new Jodit(appendTestArea()); + editor.value = '
    ' + + '
  • 1
  • ' + + '
  • 2
  • ' + + '
  • 3
  • ' + + '
'; + + var range = editor.editorDocument.createRange(); + range.setStart(editor.editor.firstChild.firstChild.firstChild, 0); + range.setEnd(editor.editor.firstChild.lastChild.firstChild, 1); + editor.selection.selectRange(range); + + editor.execCommand('formatBlock', false, 'h1'); + expect(editor.value).to.be.equal('
    ' + + '
  • 1

  • ' + + '
  • 2

  • ' + + '
  • 3

  • ' + + '
' + ) + + editor.execCommand('formatBlock', false, 'p'); + expect(editor.value).to.be.equal('
    ' + + '
  • 1
  • ' + + '
  • 2
  • ' + + '
  • 3
  • ' + + '
' + ) + }); + }); + describe('Select UL', function () { + it('Should replace all LI elements to P and unwrap it from UL', function () { + var editor = new Jodit(appendTestArea()); + editor.value = '
    ' + + '
  • 1
  • ' + + '
  • 2
  • ' + + '
  • 3
  • ' + + '
'; + + var range = editor.editorDocument.createRange(); + range.selectNode(editor.editor.firstChild); + editor.selection.selectRange(range); + + editor.execCommand('formatBlock', false, 'h1'); + expect(editor.value).to.be.equal('
    ' + + '
  • 1

  • ' + + '
  • 2

  • ' + + '
  • 3

  • ' + + '
'); + + editor.execCommand('formatBlock', false, 'p'); + expect(editor.value).to.be.equal('
    ' + + '
  • 1
  • ' + + '
  • 2
  • ' + + '
  • 3
  • ' + + '
' + ) + }); }); }); }); @@ -340,6 +383,26 @@ describe('Commands Jodit Editor Tests', function() { expect(editor.getEditorValue()).to.equal('test'); }); }); + describe('Exec bold for collapsed range and move cursor in another place', function () { + it('Should remove stron element', function () { + var editor = new Jodit(appendTestArea()); + editor.value = 'testtest'; + var range = editor.editorDocument.createRange(); + range.setStart(editor.editor.firstChild, 4); + range.collapse(true) + editor.selection.selectRange(range); + + editor.execCommand('bold') + expect(editor.value).to.be.equal('testtest'); + + range.setStart(editor.editor.lastChild, 2); + range.collapse(true) + editor.selection.selectRange(range); + simulateEvent('mousedown', 0, editor.editor) + expect(editor.value).to.be.equal('testtest'); + + }); + }); }); describe('After exec some command', function() { diff --git a/test/tests/imageTest.js b/test/tests/imageTest.js index 133cd092a..5a4626934 100644 --- a/test/tests/imageTest.js +++ b/test/tests/imageTest.js @@ -107,6 +107,47 @@ describe('Test image', function() { expect(Math.abs(positionResizer.left - positionImg.left) < 2).to.be.true; expect(Math.abs(positionResizer.top - positionImg.top) < 2).to.be.true; + editor.destruct(); + document.body.removeChild(div); + }); + }); + describe('After resize - popup', function () { + it('should be hidden and after this should be shown', function () { + var div = document.createElement('div'); + div.innerHTML = '
\n' + + ' wrong image selection\n' + + '
\n' + + ' \n' + + '
\n' + + '
'; + + document.body.appendChild(div); + var editor = new Jodit('#text_area1'); + simulateEvent('mousedown', 0, editor.editor.querySelector('img')); + + var popup = document.querySelector('.jodit_toolbar_popup-inline[data-editor_id=text_area1]'); + + expect(popup.parentNode.parentNode !== null).to.equal(true); + + var resizer = document.querySelector('.jodit_resizer[data-editor_id=text_area1]'); + expect(resizer.style.display === 'block').to.equal(true); + + var positionResizer = offset(resizer); + var positionImg = offset(editor.editor.querySelector('img')); + + simulateEvent('mousedown', 0, resizer.getElementsByTagName('i')[0]); + simulateEvent('mousemove', 0, editor.ownerWindow, function (data) { + data.clientX = positionResizer.left - 10; + data.clientY = positionResizer.top - 10; + }); + + expect(popup.parentNode.parentNode).to.be.equal(null); + simulateEvent('mouseup', 0, editor.ownerWindow, function (data) { + data.clientX = positionResizer.left - 10; + data.clientY = positionResizer.top - 10; + }); + expect(popup.parentNode.parentNode).to.be.not.equal(null); + editor.destruct(); document.body.removeChild(div); }); diff --git a/test/tests/mirrorTest.js b/test/tests/mirrorTest.js index e68731065..b775b07cc 100644 --- a/test/tests/mirrorTest.js +++ b/test/tests/mirrorTest.js @@ -63,22 +63,54 @@ describe('CodeMirror editor source code', function() { expect(1).to.be.equal(count); }); describe('After change mode to source mode and use insertHTML method', function () { - it('Should insert text on caret position', function () { + it('Should insert text on caret position', function (done) { var editor = new Jodit(appendTestArea(), { + useAceEditor: true, + beautifyHTML: false, + events: { + aceInited: function (jodit) { + jodit.value = '

test test test

' + var range = jodit.editorDocument.createRange(); + range.selectNodeContents(jodit.editor.querySelector('span')); + range.collapse(false); + jodit.selection.selectRange(range) + jodit.setMode(Jodit.MODE_SOURCE); + jodit.selection.insertHTML('loop'); + + expect(jodit.value).to.be.equal('

test testloop test

'); + done(); + }, + } }); - editor.value = '

test test test

' - var range = editor.editorDocument.createRange(); - range.selectNodeContents(editor.editor.querySelector('span')); - range.collapse(false); + }).timeout(4000); + describe('Without ace', function () { + it('Should insert text on caret position', function () { + var editor = new Jodit(appendTestArea(), { + useAceEditor: false + }); + editor.value = '

one two three

' + var range = editor.editorDocument.createRange(); + range.selectNodeContents(editor.editor.querySelector('span')); + range.collapse(false); + editor.selection.selectRange(range) + + editor.selection.insertHTML('stop'); + expect(editor.value).to.be.equal('

one twostop three

'); - editor.selection.insertHTML('stop'); - except(editor.value).to.be.equal('

test teststop test

'); + editor.setMode(Jodit.MODE_SOURCE); - seditor.setMode(Jodit.MODE_SOURCE); - editor.selection.insertHTML('loop'); - except(editor.value).to.be.equal('

test teststoploop test

'); + editor.selection.insertHTML('loop'); + expect(editor.value).to.be.equal('

one twostoploop three

'); + }); }); }); }) + afterEach(function () { + var i, keys = Object.keys(Jodit.instances); + for (i = 0; i < keys.length; i += 1) { + Jodit.instances[keys[i]].destruct(); + } + removeStuff(); + }); }); \ No newline at end of file