Skip to content

Commit c730c4b

Browse files
author
tohosaku
committed
Extract css from object.js
1 parent 4659b6b commit c730c4b

File tree

3 files changed

+54
-19
lines changed

3 files changed

+54
-19
lines changed

src/core.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class JSONEditor {
3232
this.element.setAttribute('data-theme', themeName)
3333
// eslint-disable-next-line new-cap
3434
this.theme = new themeClass(this)
35-
const rules = extend(themeClass.rules, this.getEditorsRules())
35+
const rules = extend(styleRules, this.getEditorsRules())
3636

3737
/* Call addNewStyleRulesToShadowRoot if shadowRoot is found, otherwise call addNewStyleRules */
3838
const addRules = (themeName, rules, shadowRoot) => shadowRoot
@@ -42,8 +42,8 @@ export class JSONEditor {
4242
if (!this.theme.options.disable_theme_rules) {
4343
/* Attempt to locate a shadowRoot parent (i.e. in Web Components) */
4444
const shadowRoot = getShadowParent(this.element)
45-
addRules('default', styleRules, shadowRoot)
46-
addRules(themeName, rules, shadowRoot)
45+
addRules('default', rules, shadowRoot)
46+
addRules(themeName, themeClass.rules, shadowRoot)
4747
}
4848

4949
/* Init icon class */

src/editors/object.css

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
.je-object__title {
2+
display: inline-block
3+
}
4+
5+
.je-object__controls {
6+
margin: 0 0 0 10px
7+
}
8+
9+
.je-object__container {
10+
position: relative
11+
}
12+
13+
.je-object__property-checkbox {
14+
margin: 0;
15+
height: auto;
16+
}
17+
18+
.property-selector {
19+
width: 295px;
20+
max-height: 160px;
21+
padding: 5px 0;
22+
overflow-y: auto;
23+
overflow-x: hidden;
24+
padding-left: 5px
25+
}
26+
27+
.property-selector-input {
28+
width: 220px;
29+
margin-bottom: 0;
30+
display: inline-block;
31+
}
32+
33+
.json-editor-btntype-toggle {
34+
margin: 0 10px 0 0;
35+
}
36+
37+
.je-edit-json--textarea {
38+
height: 170px !important;
39+
width: 300px !important;
40+
display: block;
41+
}

src/editors/object.js

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { AbstractEditor } from '../editor.js'
22
import { extend, trigger, hasOwnProperty } from '../utilities.js'
3+
import rules from './object.css.js'
34

45
export class ObjectEditor extends AbstractEditor {
56
constructor (options, defaults, depth) {
@@ -552,19 +553,18 @@ export class ObjectEditor extends AbstractEditor {
552553
this.header.textContent = this.getTitle()
553554
}
554555
this.title = this.theme.getHeader(this.header)
556+
this.title.classList.add('je-object__title')
555557
this.controls = this.theme.getButtonHolder()
556-
this.controls.style.margin = '0 0 0 10px'
558+
this.controls.classList.add('je-object__controls')
557559

558560
this.container.appendChild(this.title)
559561
this.container.appendChild(this.controls)
560-
this.container.style.position = 'relative'
562+
this.container.classList.add('je-object__container')
561563

562564
/* Edit JSON modal */
563565
this.editjson_holder = this.theme.getModal()
564566
this.editjson_textarea = this.theme.getTextareaInput()
565-
this.editjson_textarea.style.height = '170px'
566-
this.editjson_textarea.style.width = '300px'
567-
this.editjson_textarea.style.display = 'block'
567+
this.editjson_textarea.classList.add('je-edit-json--textarea')
568568
this.editjson_save = this.getButton('Save', 'save', 'Save')
569569
this.editjson_save.classList.add('json-editor-btntype-save')
570570
this.editjson_save.addEventListener('click', (e) => {
@@ -594,20 +594,13 @@ export class ObjectEditor extends AbstractEditor {
594594
/* Manage Properties modal */
595595
this.addproperty_holder = this.theme.getModal()
596596
this.addproperty_list = document.createElement('div')
597-
this.addproperty_list.style.width = '295px'
598-
this.addproperty_list.style.maxHeight = '160px'
599-
this.addproperty_list.style.padding = '5px 0'
600-
this.addproperty_list.style.overflowY = 'auto'
601-
this.addproperty_list.style.overflowX = 'hidden'
602-
this.addproperty_list.style.paddingLeft = '5px'
603-
this.addproperty_list.setAttribute('class', 'property-selector')
597+
this.addproperty_list.classList.add('property-selector')
604598
this.addproperty_add = this.getButton('add', 'add', 'add')
605599
this.addproperty_add.classList.add('json-editor-btntype-add')
600+
606601
this.addproperty_input = this.theme.getFormInputField('text')
607602
this.addproperty_input.setAttribute('placeholder', 'Property name...')
608-
this.addproperty_input.style.width = '220px'
609-
this.addproperty_input.style.marginBottom = '0'
610-
this.addproperty_input.style.display = 'inline-block'
603+
this.addproperty_input.classList.add('property-selector-input')
611604
this.addproperty_add.addEventListener('click', (e) => {
612605
e.preventDefault()
613606
e.stopPropagation()
@@ -716,7 +709,6 @@ export class ObjectEditor extends AbstractEditor {
716709
/* Show/Hide button */
717710
this.collapsed = false
718711
this.collapse_control = this.getButton('', 'collapse', this.translate('button_collapse'))
719-
this.collapse_control.style.margin = '0 10px 0 0'
720712
this.collapse_control.classList.add('json-editor-btntype-toggle')
721713
this.title.insertBefore(this.collapse_control, this.title.childNodes[0])
722714

@@ -1264,3 +1256,5 @@ export class ObjectEditor extends AbstractEditor {
12641256
})
12651257
}
12661258
}
1259+
1260+
ObjectEditor.rules = rules

0 commit comments

Comments
 (0)