Skip to content

Commit 24e807b

Browse files
Arne HasselArne Hassel
Arne Hassel
authored and
Arne Hassel
committed
Adding support for optional chaining
1 parent 3a9830d commit 24e807b

File tree

4 files changed

+55
-10
lines changed

4 files changed

+55
-10
lines changed

.babelrc

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
],
66
"plugins": [
77
"@babel/plugin-proposal-class-properties",
8+
"@babel/plugin-proposal-optional-chaining",
89
"@babel/plugin-transform-async-to-generator",
910
"@babel/plugin-transform-runtime"
1011
]

package-lock.json

+35
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"@babel/cli": "^7.6.2",
7070
"@babel/core": "^7.6.2",
7171
"@babel/plugin-proposal-class-properties": "^7.7.4",
72+
"@babel/plugin-proposal-optional-chaining": "^7.8.3",
7273
"@babel/plugin-transform-async-to-generator": "^7.5.0",
7374
"@babel/plugin-transform-runtime": "^7.6.2",
7475
"@babel/preset-env": "^7.6.2",

src/tabs.ts

+18-10
Original file line numberDiff line numberDiff line change
@@ -148,23 +148,23 @@ export function tabWidget (options: TabWidgetOptions) {
148148
div.setAttribute('style', selectedStyle)
149149
if (!ele.bodyTR) return
150150
ele.bodyTR.setAttribute('style', shownStyle)
151-
let bodyMain = ele.bodyTR.children[0] as ContainerElement
152-
if (!bodyMain) {
151+
const bodyMain = getOrCreateContainerElement(ele)
152+
if (options.renderTabSettings && e.altKey && ele.subject && bodyMain.asSettings !== true) {
153153
bodyMain = ele.bodyTR.appendChild(dom.createElement('main'))
154154
bodyMain.setAttribute('style', bodyMainStyle)
155155
}
156156
if (options.renderTabSettings && e.altKey && ele.subject) {
157157
if (bodyMain.asSettings !== true) {
158-
bodyMain.innerHTML = 'loading settings ...' + item
159-
options.renderTabSettings(bodyMain, ele.subject)
160-
bodyMain.asSettings = true
161-
}
158+
bodyMain.innerHTML = 'loading settings ...' + item
159+
options.renderTabSettings(bodyMain, ele.subject)
160+
bodyMain.asSettings = true
161+
} else if (options.renderMain && ele.subject && bodyMain.asSettings !== false) {
162162
} else if (options.renderMain && ele.subject) {
163163
if (bodyMain.asSettings !== false) {
164-
bodyMain.innerHTML = 'loading item ...' + item
165-
options.renderMain(bodyMain, ele.subject)
166-
bodyMain.asSettings = false
167-
}
164+
bodyMain.innerHTML = 'loading item ...' + item
165+
options.renderMain(bodyMain, ele.subject)
166+
bodyMain.asSettings = false
167+
}
168168
}
169169
})
170170

@@ -174,6 +174,14 @@ export function tabWidget (options: TabWidgetOptions) {
174174
div.textContent = label(item)
175175
}
176176
return ele
177+
178+
function getOrCreateContainerElement (ele: TabElement): ContainerElement {
179+
const bodyMain = ele.bodyTR?.children[0] as ContainerElement
180+
if (bodyMain) return bodyMain
181+
const newBodyMain = ele.bodyTR!.appendChild(dom.createElement('main'))
182+
newBodyMain.setAttribute('style', bodyMainStyle)
183+
return newBodyMain
184+
}
177185
}
178186

179187
// @@ Use common one from utils?

0 commit comments

Comments
 (0)