Skip to content

Commit 426aa63

Browse files
authored
Merge pull request jdorn#778 from tohosaku/default_style
Some theme related fixes
2 parents 3bbbf01 + b020799 commit 426aa63

File tree

11 files changed

+268
-139
lines changed

11 files changed

+268
-139
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
/tests/codeceptjs/output
77
.vscode
88
.env
9+
/src/*.css.js
910
/src/themes/*.css.js
1011
/src/editors/*.css.js
1112
/.vs

src/core.js

+17-7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { extend, getShadowParent, hasOwnProperty } from './utilities.js'
99
import { AbstractEditor } from './editor'
1010
import { AbstractTheme } from './theme'
1111
import { AbstractIconLib } from './iconlib'
12+
import styleRules from './style.css.js'
1213

1314
export class JSONEditor {
1415
constructor (element, options = {}) {
@@ -31,13 +32,20 @@ export class JSONEditor {
3132
this.element.setAttribute('data-theme', themeName)
3233
// eslint-disable-next-line new-cap
3334
this.theme = new themeClass(this)
34-
const rules = extend(themeClass.rules, this.getEditorsRules())
35+
const rules = extend(styleRules, this.getEditorsRules())
36+
37+
/* Call addNewStyleRulesToShadowRoot if shadowRoot is found, otherwise call addNewStyleRules */
38+
const addRules = (themeName, rules, shadowRoot) => shadowRoot
39+
? this.addNewStyleRulesToShadowRoot(themeName, rules, shadowRoot)
40+
: this.addNewStyleRules(themeName, rules)
41+
3542
if (!this.theme.options.disable_theme_rules) {
3643
/* Attempt to locate a shadowRoot parent (i.e. in Web Components) */
3744
const shadowRoot = getShadowParent(this.element)
38-
39-
/* Call addNewStyleRulesToShadowRoot if shadowRoot is found, otherwise call addNewStyleRules */
40-
this[shadowRoot ? 'addNewStyleRulesToShadowRoot' : 'addNewStyleRules'](themeName, rules, shadowRoot)
45+
addRules('default', rules, shadowRoot)
46+
if (typeof themeClass.rules !== 'undefined') {
47+
addRules(themeName, themeClass.rules, shadowRoot)
48+
}
4149
}
4250

4351
/* Init icon class */
@@ -365,9 +373,11 @@ export class JSONEditor {
365373

366374
const sheet = styleTag.sheet ? styleTag.sheet : styleTag.styleSheet
367375
const qualifier = this.element.nodeName.toLowerCase()
368-
376+
while (sheet.cssRules.length > 0) {
377+
sheet.deleteRule(0)
378+
}
369379
Object.keys(rules).forEach(selector => {
370-
const sel = `${qualifier}[data-theme="${themeName}"] ${selector}`
380+
const sel = themeName === 'default' ? selector : `${qualifier}[data-theme="${themeName}"] ${selector}`
371381

372382
// all browsers, except IE before version 9
373383
if (sheet.insertRule) sheet.insertRule(sel + ' {' + decodeURIComponent(rules[selector]) + '}', 0)
@@ -381,7 +391,7 @@ export class JSONEditor {
381391
let cssText = ''
382392

383393
Object.keys(rules).forEach(selector => {
384-
const sel = `${qualifier}[data-theme="${themeName}"] ${selector}`
394+
const sel = themeName === 'default' ? selector : `${qualifier}[data-theme="${themeName}"] ${selector}`
385395
cssText += sel + ' {' + decodeURIComponent(rules[selector]) + '}' + '\n'
386396
})
387397
const styleSheet = new CSSStyleSheet()

src/editors/array.css

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.json-editor-btntype-toggle {
2+
margin: 0 10px 0 0;
3+
}
4+
5+
.je-array-control-btn {
6+
width: 100%;
7+
text-align: left;
8+
margin-bottom: 3px
9+
}

src/editors/array.js

+5-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { AbstractEditor } from '../editor.js'
22
import { extend, trigger } from '../utilities.js'
3+
import rules from './array.css.js'
34

45
export class ArrayEditor extends AbstractEditor {
56
askConfirmation () {
@@ -631,7 +632,6 @@ export class ArrayEditor extends AbstractEditor {
631632
this.collapsed = false
632633
this.toggle_button = this.getButton('', 'collapse', this.translate('button_collapse'))
633634
this.toggle_button.classList.add('json-editor-btntype-toggle')
634-
this.toggle_button.style.margin = '0 10px 0 0'
635635
this.title.insertBefore(this.toggle_button, this.title.childNodes[0])
636636

637637
const rowHolderDisplay = this.row_holder.style.display
@@ -742,17 +742,9 @@ export class ArrayEditor extends AbstractEditor {
742742
this.controls.appendChild(this.remove_all_rows_button)
743743

744744
if (this.tabs) {
745-
this.add_row_button.style.width = '100%'
746-
this.add_row_button.style.textAlign = 'left'
747-
this.add_row_button.style.marginBottom = '3px'
748-
749-
this.delete_last_row_button.style.width = '100%'
750-
this.delete_last_row_button.style.textAlign = 'left'
751-
this.delete_last_row_button.style.marginBottom = '3px'
752-
753-
this.remove_all_rows_button.style.width = '100%'
754-
this.remove_all_rows_button.style.textAlign = 'left'
755-
this.remove_all_rows_button.style.marginBottom = '3px'
745+
this.add_row_button.classList.add('je-array-control-btn')
746+
this.delete_last_row_button.classList.add('je-array-control-btn')
747+
this.remove_all_rows_button.classList.add('je-array-control-btn')
756748
}
757749
}
758750

@@ -788,3 +780,4 @@ export class ArrayEditor extends AbstractEditor {
788780
)
789781
}
790782
}
783+
ArrayEditor.rules = rules

src/editors/object.css

+41
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

+10-16
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

src/editors/table.js

-1
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,6 @@ export class TableEditor extends ArrayEditor {
415415
this.collapsed = false
416416
this.toggle_button = this.getButton('', 'collapse', this.translate('button_collapse'))
417417
this.toggle_button.classList.add('json-editor-btntype-toggle')
418-
this.toggle_button.style.margin = '0 10px 0 0'
419418
if (this.title_controls) {
420419
this.title.insertBefore(this.toggle_button, this.title.childNodes[0])
421420
this.toggle_button.addEventListener('click', e => {

src/style.css

+150
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
.je-float-right-linkholder {
2+
float: right;
3+
margin-left: 10px;
4+
}
5+
6+
.je-modal {
7+
background-color: white;
8+
border: 1px solid black;
9+
box-shadow: 3px 3px black;
10+
position: absolute;
11+
z-index: 10;
12+
}
13+
14+
.je-infobutton-icon {
15+
font-size: 16px;
16+
font-weight: bold;
17+
padding: 0.25rem;
18+
position: relative;
19+
display: inline-block;
20+
}
21+
22+
.je-infobutton-tooltip {
23+
font-size: 12px;
24+
font-weight: normal;
25+
font-family: sans-serif;
26+
visibility: hidden;
27+
background-color: rgba(50, 50, 50, 0.75);
28+
margin: 0 0.25rem;
29+
color: #fafafa;
30+
padding: 0.5rem 1rem;
31+
border-radius: 0.25rem;
32+
width: 20rem;
33+
position: absolute;
34+
}
35+
36+
.je-header {
37+
display: inline-block
38+
}
39+
40+
.je-upload-preview img {
41+
float: left;
42+
margin: 0 0.5rem 0.5rem 0;
43+
max-width: 100%;
44+
max-height: 5rem;
45+
}
46+
47+
.je-checkbox {
48+
display: inline-block;
49+
width: auto
50+
}
51+
52+
.je-checkbox-control--compact {
53+
display: inline-block;
54+
margin-right: 1rem
55+
}
56+
57+
.je-radio {
58+
display: inline-block;
59+
width: auto
60+
}
61+
62+
.je-radio-control--compact {
63+
display: inline-block;
64+
margin-right: 1rem
65+
}
66+
67+
.je-switcher {
68+
background-color: transparent;
69+
display: inline-block;
70+
font-style: italic;
71+
font-weight: normal;
72+
height: auto;
73+
width: auto;
74+
margin-bottom: 0;
75+
margin-left: 5px;
76+
padding: 0 0 0 3px;
77+
}
78+
79+
.je-textarea {
80+
width: 100%;
81+
height: 300px;
82+
box-sizing: border-box
83+
}
84+
85+
.je-range-control {
86+
text-align: center
87+
}
88+
89+
.je-indented-panel {
90+
padding-left: 10px;
91+
margin-left: 10px;
92+
border-left: 1px solid #ccc
93+
}
94+
95+
.je-indented-panel--top {
96+
padding-left: 10px;
97+
margin-left: 10px;
98+
}
99+
100+
.je-tabholder {
101+
float: left;
102+
width: 130px;
103+
}
104+
105+
.je-tabholder .content {
106+
margin-left: 120px;
107+
}
108+
109+
.je-tabholder--top {
110+
margin-left: 10px;
111+
}
112+
113+
.je-tabholder--clear {
114+
clear:both;
115+
}
116+
117+
.je-tab {
118+
border: 1px solid #ccc;
119+
border-width: 1px 0 1px 1px;
120+
text-align: center;
121+
line-height: 30px;
122+
border-radius: 5px;
123+
border-bottom-right-radius: 0;
124+
border-top-right-radius: 0;
125+
font-weight: bold;
126+
cursor: pointer
127+
}
128+
129+
.je-tab--top {
130+
float: left;
131+
border: 1px solid #ccc;
132+
border-width: 1px 1px 0px 1px;
133+
text-align: center;
134+
line-height: 30px;
135+
border-radius: 5px;
136+
padding-left: 5px;
137+
padding-right: 5px;
138+
border-bottom-right-radius: 0;
139+
border-bottom-left-radius: 0;
140+
font-weight: bold;
141+
cursor: pointer
142+
}
143+
144+
.je-block-link {
145+
display: block
146+
}
147+
148+
.je-media {
149+
width: 100%
150+
}

0 commit comments

Comments
 (0)