Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from idrawjs/dev
v0.1.13
- Loading branch information
Showing
26 changed files
with
627 additions
and
144 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,5 @@ | |
"packages/core", | ||
"packages/idraw" | ||
], | ||
"version": "0.1.12" | ||
"version": "0.1.13" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// import { TypeData } from '@idraw/types'; | ||
import Core from '../../src'; | ||
import { getData } from '../data'; | ||
|
||
describe("@idraw/core: Element API", () => { | ||
document.body.innerHTML = ` | ||
<div id="mount"></div> | ||
`; | ||
const opts = { | ||
width: 600, | ||
height: 400, | ||
contextWidth: 600, | ||
contextHeight: 400, | ||
devicePixelRatio: 4 | ||
} | ||
const mount = document.querySelector('#mount') as HTMLDivElement; | ||
const core = new Core(mount, opts); | ||
const data = getData(); | ||
core.setData(data); | ||
const _data = core.getData(); | ||
|
||
test('getSelectedElements', async () => { | ||
core.selectElement(_data.elements[1].uuid || ''); | ||
const elems = core.getSelectedElements(); | ||
expect(elems).toStrictEqual([_data.elements[1]]); | ||
}); | ||
|
||
|
||
}); | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { | ||
TypeElement, TypeElemDesc, | ||
} from '@idraw/types'; | ||
import util from '@idraw/util'; | ||
import { | ||
_board, _data, _opts, _config, _renderer, _element, _helper, _hasInited, | ||
_mode, _tempData, _prevPoint, _draw, _selectedDotDirection, _coreEvent, _mapper, _initEvent, | ||
_handlePoint, _handleClick, _handleDoubleClick, _handleMoveStart, _handleMove, | ||
_handleMoveEnd, _handleHover, _handleLeave, _dragElements, _transfromElement, | ||
_emitChangeScreen, _emitChangeData, _onlyRender, _cursorStatus, | ||
} from './../names'; | ||
import { diffElementResourceChange } from './../lib/diff'; | ||
import Core from './../index'; | ||
|
||
// const { time } = util; | ||
const { deepClone } = util.data; | ||
|
||
export function getSelectedElements(core: Core): TypeElement<keyof TypeElemDesc>[] { | ||
const elems: TypeElement<keyof TypeElemDesc>[] = []; | ||
let list: string[] = []; | ||
const uuid = core[_tempData].get('selectedUUID'); | ||
if (typeof uuid === 'string' && uuid) { | ||
list.push(uuid); | ||
} else { | ||
list = core[_tempData].get('selectedUUIDList'); | ||
} | ||
list.forEach((uuid) => { | ||
const index = core[_helper].getElementIndexByUUID(uuid); | ||
if (index !== null && index >= 0) { | ||
const elem = core[_data]?.elements[index]; | ||
if (elem) elems.push(elem); | ||
} | ||
}); | ||
return elems; | ||
} | ||
|
||
export function updateElement(core: Core, elem: TypeElement<keyof TypeElemDesc>) { | ||
const _elem = deepClone(elem) as TypeElement<keyof TypeElemDesc>; | ||
const data = core[_data]; | ||
const resourceChangeUUIDs: string[] = []; | ||
for (let i = 0; i < data.elements.length; i++) { | ||
if (_elem.uuid === data.elements[i]?.uuid) { | ||
const result = diffElementResourceChange(data.elements[i], _elem); | ||
if (typeof result === 'string') { | ||
resourceChangeUUIDs.push(result); | ||
} | ||
data.elements[i] = _elem; | ||
break; | ||
} | ||
} | ||
core[_emitChangeData](); | ||
core[_draw]({ resourceChangeUUIDs }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.