Skip to content

Commit a736e67

Browse files
author
tohosaku
committed
Extract default style to css
1 parent 3bbbf01 commit a736e67

File tree

4 files changed

+187
-103
lines changed

4 files changed

+187
-103
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
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

Lines changed: 14 additions & 6 deletions
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 = {}) {
@@ -32,12 +33,17 @@ export class JSONEditor {
3233
// eslint-disable-next-line new-cap
3334
this.theme = new themeClass(this)
3435
const rules = extend(themeClass.rules, 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', styleRules, shadowRoot)
46+
addRules(themeName, rules, shadowRoot)
4147
}
4248

4349
/* Init icon class */
@@ -365,9 +371,11 @@ export class JSONEditor {
365371

366372
const sheet = styleTag.sheet ? styleTag.sheet : styleTag.styleSheet
367373
const qualifier = this.element.nodeName.toLowerCase()
368-
374+
while (sheet.cssRules.length > 0) {
375+
sheet.deleteRule(0)
376+
}
369377
Object.keys(rules).forEach(selector => {
370-
const sel = `${qualifier}[data-theme="${themeName}"] ${selector}`
378+
const sel = themeName === 'default' ? selector : `${qualifier}[data-theme="${themeName}"] ${selector}`
371379

372380
// all browsers, except IE before version 9
373381
if (sheet.insertRule) sheet.insertRule(sel + ' {' + decodeURIComponent(rules[selector]) + '}', 0)
@@ -381,7 +389,7 @@ export class JSONEditor {
381389
let cssText = ''
382390

383391
Object.keys(rules).forEach(selector => {
384-
const sel = `${qualifier}[data-theme="${themeName}"] ${selector}`
392+
const sel = themeName === 'default' ? selector : `${qualifier}[data-theme="${themeName}"] ${selector}`
385393
cssText += sel + ' {' + decodeURIComponent(rules[selector]) + '}' + '\n'
386394
})
387395
const styleSheet = new CSSStyleSheet()

src/style.css

Lines changed: 150 additions & 0 deletions
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)