Skip to content

Commit c8ad337

Browse files
committed
feat: v0.19.4 add insertParent
1 parent 2a49714 commit c8ad337

File tree

7 files changed

+63
-16
lines changed

7 files changed

+63
-16
lines changed

global.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ interface Window {
77
currentOperation: any;
88
m: any;
99
M: any;
10+
E: any;
1011
exportSvg: any;
1112
exportPng: any;
1213
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mind-elixir",
3-
"version": "0.19.3",
3+
"version": "0.19.4",
44
"description": "Mind elixir is a free open source mind map core.",
55
"main": "dist/MindElixir.js",
66
"scripts": {

src/__tests__/nodeOperation.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ beforeAll(async() => {
2323
describe('nodeOperation', () => {
2424
it('addChild"', async() => {
2525
await page.evaluate(`m.addChild(E('bd1f07c598e729dc'))`)
26-
await page.waitFor('#input-box')
26+
await page.waitForSelector('#input-box')
2727
await page.keyboard.press('Enter')
2828
const id = await page.evaluate(() => {
2929
return E('bd1f07c598e729dc').nodeObj.children[0].parent.id
@@ -33,7 +33,7 @@ describe('nodeOperation', () => {
3333
it('insertSibling"', async() => {
3434
await page.evaluate(`m.insertSibling(E('bd1f07c598e729dc'))`)
3535
const newId = await page.evaluate(`currentOperation.obj.id`)
36-
await page.waitFor('#input-box')
36+
await page.waitForSelector('#input-box')
3737
await page.keyboard.press('Enter')
3838
const res = await page.evaluate(newId => {
3939
const newNode = E(newId).nodeObj

src/dev.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const mind = new MindElixir({
4545
return true
4646
},
4747
},
48-
primaryLinkStyle: 2,
48+
primaryLinkStyle: 1,
4949
primaryNodeVerticalGap: 15, // 25
5050
primaryNodeHorizontalGap: 15, // 65
5151
})
@@ -89,5 +89,6 @@ mind.bus.addListener('expandNode', node => {
8989
window.m = mind
9090
// window.m2 = mind2
9191
window.M = MindElixir
92+
window.E = MindElixir.E
9293
window.exportSvg = exportSvg
9394
window.exportPng = exportPng

src/index.lite.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ MindElixir.SIDE = SIDE
297297
* @memberof MindElixir
298298
* @static
299299
*/
300-
MindElixir.version = '0.17.0'
300+
MindElixir.version = '0.19.4'
301301
MindElixir.E = findEle
302302

303303
export default MindElixir

src/nodeOperation.ts

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,17 @@ export const insertSibling = function(el, node) {
136136
})
137137
}
138138

139+
/**
140+
* @function
141+
* @instance
142+
* @name insertBefore
143+
* @memberof NodeOperation
144+
* @description Create a sibling node before the selected node.
145+
* @param {TargetElement} el - Target element return by E('...'), default value: currentTarget.
146+
* @param {node} node - New node information.
147+
* @example
148+
* insertBefore(E('bd4313fbac40284b'))
149+
*/
139150
export const insertBefore = function(el, node) {
140151
const nodeEle = el || this.currentNode
141152
if (!nodeEle) return
@@ -171,6 +182,17 @@ export const insertBefore = function(el, node) {
171182
})
172183
}
173184

185+
/**
186+
* @function
187+
* @instance
188+
* @name insertParent
189+
* @memberof NodeOperation
190+
* @description Create a parent node of the selected node.
191+
* @param {TargetElement} el - Target element return by E('...'), default value: currentTarget.
192+
* @param {node} node - New node information.
193+
* @example
194+
* insertParent(E('bd4313fbac40284b'))
195+
*/
174196
export const insertParent = function(el, node) {
175197
const nodeEle = el || this.currentNode
176198
if (!nodeEle) return
@@ -183,18 +205,19 @@ export const insertParent = function(el, node) {
183205
addParentLink(this.nodeData)
184206
const grp0 = nodeEle.parentElement.parentElement
185207
console.time('insertParent_DOM')
186-
const { grp, top } = this.createGroup(newNodeObj)
187-
// console.log(grp)
208+
const { grp, top } = this.createGroup(newNodeObj, true)
188209
const children = grp0.parentNode
189210
children.insertBefore(grp, grp0.nextSibling)
190211

191-
// const c = $d.createElement('children')
192-
// c.appendChild(grp0)
193-
// top.appendChild(createExpander(true))
194-
// top.parentElement.insertBefore(c, top.nextSibling)
195-
grp0.remove()
212+
const c = $d.createElement('children')
213+
c.appendChild(grp0)
214+
top.appendChild(createExpander(true))
215+
top.parentElement.insertBefore(c, top.nextSibling)
216+
196217
if (children.className === 'box') {
197-
this.processPrimaryNode(grp, newNodeObj)
218+
grp.className = grp0.className
219+
grp0.className = ''
220+
grp0.querySelector('.svg3rd').remove()
198221
this.linkDiv()
199222
} else {
200223
this.linkDiv(grp.offsetParent)
@@ -421,7 +444,7 @@ export const removeNode = function(el) {
421444
* @instance
422445
* @name moveNode
423446
* @memberof NodeOperation
424-
* @description Move the target node to another node (as child node).
447+
* @description Move a node to another node (as child node).
425448
* @param {TargetElement} from - The target you want to move.
426449
* @param {TargetElement} to - The target(as parent node) you want to move to.
427450
* @example
@@ -479,6 +502,17 @@ export const moveNode = function(from, to) {
479502
console.timeEnd('moveNode')
480503
}
481504

505+
/**
506+
* @function
507+
* @instance
508+
* @name moveNodeBefore
509+
* @memberof NodeOperation
510+
* @description Move a node and become previous node of another node.
511+
* @param {TargetElement} from
512+
* @param {TargetElement} to
513+
* @example
514+
* moveNodeBefore(E('bd4313fbac402842'),E('bd4313fbac402839'))
515+
*/
482516
export const moveNodeBefore = function(from, to) {
483517
const fromObj = from.nodeObj
484518
const toObj = to.nodeObj
@@ -498,6 +532,17 @@ export const moveNodeBefore = function(from, to) {
498532
})
499533
}
500534

535+
/**
536+
* @function
537+
* @instance
538+
* @name moveNodeAfter
539+
* @memberof NodeOperation
540+
* @description Move a node and become next node of another node.
541+
* @param {TargetElement} from
542+
* @param {TargetElement} to
543+
* @example
544+
* moveNodeAfter(E('bd4313fbac402842'),E('bd4313fbac402839'))
545+
*/
501546
export const moveNodeAfter = function(from, to) {
502547
const fromObj = from.nodeObj
503548
const toObj = to.nodeObj

src/utils/dom.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ export const shapeTpc = function(tpc: Topic, nodeObj: NodeObj) {
6363
}
6464
}
6565

66-
export const createGroup = function(nodeObj: NodeObj) {
66+
export const createGroup = function(nodeObj: NodeObj, omitChildren?: boolean) {
6767
const grp: Group = $d.createElement('GRP')
6868
const top: Top = this.createTop(nodeObj)
6969
grp.appendChild(top)
70-
if (nodeObj.children && nodeObj.children.length > 0) {
70+
if (!omitChildren && nodeObj.children && nodeObj.children.length > 0) {
7171
top.appendChild(createExpander(nodeObj.expanded))
7272
if (nodeObj.expanded !== false) {
7373
const children = this.createChildren(nodeObj.children)

0 commit comments

Comments
 (0)