@@ -5,7 +5,6 @@ import { encodeHTML, getOffsetLT } from '../utils/index'
55import { layoutChildren } from './layout'
66
77// DOM manipulation
8- const $d = document
98export const findEle = function ( this : MindElixirInstance , id : string , el ?: HTMLElement ) {
109 const scope = this ?. el ? this . el : el ? el : document
1110 const ele = scope . querySelector < Topic > ( `[data-nodeid="me${ id } "]` )
@@ -32,7 +31,7 @@ export const shapeTpc = function (this: MindElixirInstance, tpc: Topic, nodeObj:
3231 if ( nodeObj . image ) {
3332 const img = nodeObj . image
3433 if ( img . url && img . width && img . height ) {
35- const imgEl = $d . createElement ( 'img' )
34+ const imgEl = document . createElement ( 'img' )
3635 // Use imageProxy function if provided, otherwise use original URL
3736 imgEl . src = this . imageProxy ? this . imageProxy ( img . url ) : img . url
3837 imgEl . style . width = img . width + 'px'
@@ -48,7 +47,7 @@ export const shapeTpc = function (this: MindElixirInstance, tpc: Topic, nodeObj:
4847 }
4948
5049 {
51- const textEl = $d . createElement ( 'span' )
50+ const textEl = document . createElement ( 'span' )
5251 textEl . className = 'text'
5352
5453 // Check if markdown parser is provided and topic contains markdown syntax
@@ -63,7 +62,7 @@ export const shapeTpc = function (this: MindElixirInstance, tpc: Topic, nodeObj:
6362 }
6463
6564 if ( nodeObj . hyperLink ) {
66- const linkEl = $d . createElement ( 'a' )
65+ const linkEl = document . createElement ( 'a' )
6766 linkEl . className = 'hyper-link'
6867 linkEl . target = '_blank'
6968 linkEl . innerText = '🔗'
@@ -75,7 +74,7 @@ export const shapeTpc = function (this: MindElixirInstance, tpc: Topic, nodeObj:
7574 }
7675
7776 if ( nodeObj . icons && nodeObj . icons . length ) {
78- const iconsEl = $d . createElement ( 'span' )
77+ const iconsEl = document . createElement ( 'span' )
7978 iconsEl . className = 'icons'
8079 iconsEl . innerHTML = nodeObj . icons . map ( icon => `<span>${ encodeHTML ( icon ) } </span>` ) . join ( '' )
8180 tpc . appendChild ( iconsEl )
@@ -85,11 +84,11 @@ export const shapeTpc = function (this: MindElixirInstance, tpc: Topic, nodeObj:
8584 }
8685
8786 if ( nodeObj . tags && nodeObj . tags . length ) {
88- const tagsEl = $d . createElement ( 'div' )
87+ const tagsEl = document . createElement ( 'div' )
8988 tagsEl . className = 'tags'
9089
9190 nodeObj . tags . forEach ( tag => {
92- const span = $d . createElement ( 'span' )
91+ const span = document . createElement ( 'span' )
9392
9493 if ( typeof tag === 'string' ) {
9594 span . textContent = tag
@@ -115,7 +114,7 @@ export const shapeTpc = function (this: MindElixirInstance, tpc: Topic, nodeObj:
115114
116115// everything start from `Wrapper`
117116export const createWrapper = function ( this : MindElixirInstance , nodeObj : NodeObj , omitChildren ?: boolean ) {
118- const grp = $d . createElement ( 'me-wrapper' ) as Wrapper
117+ const grp = document . createElement ( 'me-wrapper' ) as Wrapper
119118 const { p, tpc } = this . createParent ( nodeObj )
120119 grp . appendChild ( p )
121120 if ( ! omitChildren && nodeObj . children && nodeObj . children . length > 0 ) {
@@ -131,28 +130,28 @@ export const createWrapper = function (this: MindElixirInstance, nodeObj: NodeOb
131130}
132131
133132export const createParent = function ( this : MindElixirInstance , nodeObj : NodeObj ) {
134- const p = $d . createElement ( 'me-parent' ) as Parent
133+ const p = document . createElement ( 'me-parent' ) as Parent
135134 const tpc = this . createTopic ( nodeObj )
136135 shapeTpc . call ( this , tpc , nodeObj )
137136 p . appendChild ( tpc )
138137 return { p, tpc }
139138}
140139
141140export const createChildren = function ( this : MindElixirInstance , wrappers : Wrapper [ ] ) {
142- const children = $d . createElement ( 'me-children' ) as Children
141+ const children = document . createElement ( 'me-children' ) as Children
143142 children . append ( ...wrappers )
144143 return children
145144}
146145
147146export const createTopic = function ( this : MindElixirInstance , nodeObj : NodeObj ) {
148- const topic = $d . createElement ( 'me-tpc' ) as Topic
147+ const topic = document . createElement ( 'me-tpc' ) as Topic
149148 topic . nodeObj = nodeObj
150149 topic . dataset . nodeid = 'me' + nodeObj . id
151150 return topic
152151}
153152
154153export function selectText ( div : HTMLElement ) {
155- const range = $d . createRange ( )
154+ const range = document . createRange ( )
156155 range . selectNodeContents ( div )
157156 const getSelection = window . getSelection ( )
158157 if ( getSelection ) {
@@ -164,7 +163,7 @@ export function selectText(div: HTMLElement) {
164163export const editTopic = function ( this : MindElixirInstance , el : Topic ) {
165164 console . time ( 'editTopic' )
166165 if ( ! el ) return
167- const div = $d . createElement ( 'div' )
166+ const div = document . createElement ( 'div' )
168167 const node = el . nodeObj
169168
170169 // Get the original content from topic
@@ -240,7 +239,7 @@ export const editTopic = function (this: MindElixirInstance, el: Topic) {
240239}
241240
242241export const createExpander = function ( expanded : boolean | undefined ) : Expander {
243- const expander = $d . createElement ( 'me-epd' ) as Expander
242+ const expander = document . createElement ( 'me-epd' ) as Expander
244243 // if expanded is undefined, treat as expanded
245244 expander . expanded = expanded !== false
246245 expander . className = expanded !== false ? 'minus' : ''
0 commit comments