Skip to content

Commit 21d1faf

Browse files
committed
Format code using Prettier
1 parent 0777836 commit 21d1faf

25 files changed

+794
-424
lines changed

packages/draft-js-export-html/src/__tests__/stateToHTML-test.js

+100-25
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,30 @@ let testCasesCustomRaw = fs.readFileSync(
2020
'utf8',
2121
);
2222

23-
let testCases = testCasesRaw.slice(1).trim().split(SEP).map((text) => {
24-
let lines = text.split('\n');
25-
let description = lines.shift().trim();
26-
let state = JSON.parse(lines.shift());
27-
let html = lines.join('\n');
28-
return {description, state, html};
29-
});
23+
let testCases = testCasesRaw
24+
.slice(1)
25+
.trim()
26+
.split(SEP)
27+
.map((text) => {
28+
let lines = text.split('\n');
29+
let description = lines.shift().trim();
30+
let state = JSON.parse(lines.shift());
31+
let html = lines.join('\n');
32+
return {description, state, html};
33+
});
3034

31-
let testCasesCustom = testCasesCustomRaw.slice(1).trim().split(SEP).map((text) => {
32-
let lines = text.split('\n');
33-
let description = lines.shift().trim();
34-
let options = JSON.parse(lines.shift());
35-
let state = JSON.parse(lines.shift());
36-
let html = lines.join('\n');
37-
return {description, options, state, html};
38-
});
35+
let testCasesCustom = testCasesCustomRaw
36+
.slice(1)
37+
.trim()
38+
.split(SEP)
39+
.map((text) => {
40+
let lines = text.split('\n');
41+
let description = lines.shift().trim();
42+
let options = JSON.parse(lines.shift());
43+
let state = JSON.parse(lines.shift());
44+
let html = lines.join('\n');
45+
return {description, options, state, html};
46+
});
3947

4048
describe('stateToHTML', () => {
4149
testCases.forEach((testCase) => {
@@ -64,17 +72,41 @@ describe('stateToHTML', () => {
6472
};
6573
let contentState = convertFromRaw(
6674
// <pre><code>Hello <em>world</em>.</code></pre>
67-
{"entityMap":{},"blocks":[{"key":"dn025","text":"Hello world.","type":"code-block","depth":0,"inlineStyleRanges":[{"offset":6,"length":5,"style":"ITALIC"}],"entityRanges":[]}]} // eslint-disable-line
75+
{
76+
entityMap: {},
77+
blocks: [
78+
{
79+
key: 'dn025',
80+
text: 'Hello world.',
81+
type: 'code-block',
82+
depth: 0,
83+
inlineStyleRanges: [{offset: 6, length: 5, style: 'ITALIC'}],
84+
entityRanges: [],
85+
},
86+
],
87+
}, // eslint-disable-line
6888
);
6989
expect(stateToHTML(contentState, options)).toBe(
70-
'<div class="code">Hello world.</div>'
90+
'<div class="code">Hello world.</div>',
7191
);
7292
let contentState2 = convertFromRaw(
7393
// <h1>Hello <em>world</em>.</h1>
74-
{"entityMap":{},"blocks":[{"key":"dn025","text":"Hello world.","type":"header-one","depth":0,"inlineStyleRanges":[{"offset":6,"length":5,"style":"ITALIC"}],"entityRanges":[]}]} // eslint-disable-line
94+
{
95+
entityMap: {},
96+
blocks: [
97+
{
98+
key: 'dn025',
99+
text: 'Hello world.',
100+
type: 'header-one',
101+
depth: 0,
102+
inlineStyleRanges: [{offset: 6, length: 5, style: 'ITALIC'}],
103+
entityRanges: [],
104+
},
105+
],
106+
}, // eslint-disable-line
75107
);
76108
expect(stateToHTML(contentState2, options)).toBe(
77-
'<h1>Hello <em>world</em>.</h1>'
109+
'<h1>Hello <em>world</em>.</h1>',
78110
);
79111
});
80112

@@ -93,21 +125,46 @@ describe('stateToHTML', () => {
93125
};
94126
let contentState1 = convertFromRaw(
95127
// <h1 style="text-align: left;">Hello <em>world</em>.</h1>
96-
{"entityMap":{},"blocks":[{"data":{"alignment":"left"},"key":"dn025","text":"Hello world.","type":"header-one","depth":0,"inlineStyleRanges":[{"offset":6,"length":5,"style":"ITALIC"}],"entityRanges":[]}]} // eslint-disable-line
128+
{
129+
entityMap: {},
130+
blocks: [
131+
{
132+
data: {alignment: 'left'},
133+
key: 'dn025',
134+
text: 'Hello world.',
135+
type: 'header-one',
136+
depth: 0,
137+
inlineStyleRanges: [{offset: 6, length: 5, style: 'ITALIC'}],
138+
entityRanges: [],
139+
},
140+
],
141+
}, // eslint-disable-line
97142
);
98143
if (contentState1.getFirstBlock().getData == null) {
99144
// Older DraftJS does not support block.getData()
100145
return;
101146
}
102147
expect(stateToHTML(contentState1, options)).toBe(
103-
'<h1 style="text-align: left">Hello <em>world</em>.</h1>'
148+
'<h1 style="text-align: left">Hello <em>world</em>.</h1>',
104149
);
105150
let contentState2 = convertFromRaw(
106151
// <h1>Hello <em>world</em>.</h1>
107-
{"entityMap":{},"blocks":[{"key":"dn025","text":"Hello world.","type":"header-one","depth":0,"inlineStyleRanges":[{"offset":6,"length":5,"style":"ITALIC"}],"entityRanges":[]}]} // eslint-disable-line
152+
{
153+
entityMap: {},
154+
blocks: [
155+
{
156+
key: 'dn025',
157+
text: 'Hello world.',
158+
type: 'header-one',
159+
depth: 0,
160+
inlineStyleRanges: [{offset: 6, length: 5, style: 'ITALIC'}],
161+
entityRanges: [],
162+
},
163+
],
164+
}, // eslint-disable-line
108165
);
109166
expect(stateToHTML(contentState2, options)).toBe(
110-
'<h1>Hello <em>world</em>.</h1>'
167+
'<h1>Hello <em>world</em>.</h1>',
111168
);
112169
});
113170

@@ -128,14 +185,32 @@ describe('stateToHTML', () => {
128185
};
129186
let contentState1 = convertFromRaw(
130187
// <p><em>a</em></p>
131-
{"entityMap":{"0":{"type":"MENTION","mutability":"MUTABLE","data":{"userId":"mikaelwaltersson"}}},"blocks":[{"key":"8r91j","text":"a","type":"unstyled","depth":0,"inlineStyleRanges":[{"offset":0,"length":1,"style":"ITALIC"}],"entityRanges":[{"offset":0,"length":1,"key":0}]}]} // eslint-disable-line
188+
{
189+
entityMap: {
190+
[0]: {
191+
type: 'MENTION',
192+
mutability: 'MUTABLE',
193+
data: {userId: 'mikaelwaltersson'},
194+
},
195+
},
196+
blocks: [
197+
{
198+
key: '8r91j',
199+
text: 'a',
200+
type: 'unstyled',
201+
depth: 0,
202+
inlineStyleRanges: [{offset: 0, length: 1, style: 'ITALIC'}],
203+
entityRanges: [{offset: 0, length: 1, key: 0}],
204+
},
205+
],
206+
}, // eslint-disable-line
132207
);
133208
if (contentState1.getFirstBlock().getData == null) {
134209
// Older DraftJS does not support block.getData()
135210
return;
136211
}
137212
expect(stateToHTML(contentState1, options)).toBe(
138-
'<p><a href="/users/mikaelwaltersson" class="mention"><em>a</em></a></p>'
213+
'<p><a href="/users/mikaelwaltersson" class="mention"><em>a</em></a></p>',
139214
);
140215
});
141216
});

packages/draft-js-export-html/src/helpers/__tests__/combineOrderedStyles-test.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ describe('combineOrderedStyles', () => {
1919
let defaultStyleMap = {foo: {}, bar: {}};
2020
let defaultStyleOrder = ['foo', 'bar'];
2121
let customStyleMap = {};
22-
let [styleMap, styleOrder] = combineOrderedStyles(customStyleMap, [defaultStyleMap, defaultStyleOrder]);
22+
let [styleMap, styleOrder] = combineOrderedStyles(customStyleMap, [
23+
defaultStyleMap,
24+
defaultStyleOrder,
25+
]);
2326
expect(styleMap).toEqual({foo: {}, bar: {}});
2427
expect(styleMap).toNotBe(defaultStyleMap);
2528
expect(styleOrder).toEqual(['foo', 'bar']);
@@ -30,7 +33,10 @@ describe('combineOrderedStyles', () => {
3033
let defaultStyleMap = {foo: {}, bar: {}};
3134
let defaultStyleOrder = ['foo', 'bar'];
3235
let customStyleMap = {baz: {}};
33-
let [styleMap, styleOrder] = combineOrderedStyles(customStyleMap, [defaultStyleMap, defaultStyleOrder]);
36+
let [styleMap, styleOrder] = combineOrderedStyles(customStyleMap, [
37+
defaultStyleMap,
38+
defaultStyleOrder,
39+
]);
3440
expect(styleMap).toEqual({foo: {}, bar: {}, baz: {}});
3541
expect(styleMap).toNotBe(defaultStyleMap);
3642
expect(styleMap).toNotBe(customStyleMap);
@@ -48,7 +54,10 @@ describe('combineOrderedStyles', () => {
4854
BOLD: {element: 'span', style: {fontWeight: 'bold'}},
4955
ITALIC: {style: {textDecoration: 'underline'}},
5056
};
51-
let [styleMap, styleOrder] = combineOrderedStyles(customStyleMap, [defaultStyleMap, defaultStyleOrder]);
57+
let [styleMap, styleOrder] = combineOrderedStyles(customStyleMap, [
58+
defaultStyleMap,
59+
defaultStyleOrder,
60+
]);
5261
expect(styleMap).toEqual({
5362
BOLD: {element: 'span', style: {fontWeight: 'bold'}},
5463
ITALIC: {element: 'em', style: {textDecoration: 'underline'}},

packages/draft-js-export-html/src/helpers/__tests__/styleToCSS-test.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ describe('styleToCSS', () => {
1919
color: 'red',
2020
padding: '2px',
2121
};
22-
expect(styleToCSS(styles)).toBe(
23-
'color: red; padding: 2px'
24-
);
22+
expect(styleToCSS(styles)).toBe('color: red; padding: 2px');
2523
});
2624

2725
it('should convert camelCase to hyphenated', () => {
@@ -31,7 +29,7 @@ describe('styleToCSS', () => {
3129
webkitAppearance: 'none',
3230
};
3331
expect(styleToCSS(styles)).toBe(
34-
'font-weight: bold; -ms-grid-column: auto; -webkit-appearance: none'
32+
'font-weight: bold; -ms-grid-column: auto; -webkit-appearance: none',
3533
);
3634
});
3735

@@ -40,8 +38,6 @@ describe('styleToCSS', () => {
4038
lineHeight: 1,
4139
fontSize: 12,
4240
};
43-
expect(styleToCSS(styles)).toBe(
44-
'line-height: 1; font-size: 12px'
45-
);
41+
expect(styleToCSS(styles)).toBe('line-height: 1; font-size: 12px');
4642
});
4743
});

packages/draft-js-export-html/src/helpers/combineOrderedStyles.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// @flow
22

3-
type Attributes = {[key: string]: string};
4-
type StyleDescr = {[key: string]: number | string};
3+
type Attributes = { [key: string]: string };
4+
type StyleDescr = { [key: string]: number | string };
55
type RenderConfig = {
66
element?: string;
77
attributes?: Attributes;
88
style?: StyleDescr;
99
};
10-
type StyleMap = {[styleName: string]: RenderConfig};
10+
type StyleMap = { [styleName: string]: RenderConfig };
1111
type StyleOrder = Array<string>;
1212
type OrderedStyleMap = [StyleMap, StyleOrder];
1313

packages/draft-js-export-html/src/helpers/normalizeAttributes.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @flow
22

3-
type Attributes = {[key: string]: string};
4-
type StringMap = {[key: string]: string};
3+
type Attributes = { [key: string]: string };
4+
type StringMap = { [key: string]: string };
55

66
// Lifted from: https://github.com/facebook/react/blob/master/src/renderers/dom/shared/HTMLDOMPropertyConfig.js
77
const ATTR_NAME_MAP: StringMap = {

packages/draft-js-export-html/src/helpers/styleToCSS.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @flow
22

3-
type StyleDescr = {[key: string]: number | string};
3+
type StyleDescr = { [key: string]: number | string };
44

55
const VENDOR_PREFIX = /^(moz|ms|o|webkit)-/;
66
const NUMERIC_STRING = /^\d+$/;
@@ -52,8 +52,6 @@ const isUnitlessNumber = {
5252
strokeWidth: true,
5353
};
5454

55-
56-
5755
// Lifted from: https://github.com/facebook/react/blob/master/src/renderers/dom/shared/CSSPropertyOperations.js
5856
function processStyleName(name: string): string {
5957
return name
@@ -79,11 +77,13 @@ function processStyleValue(name: string, value: number | string): string {
7977
}
8078

8179
function styleToCSS(styleDescr: StyleDescr): string {
82-
return Object.keys(styleDescr).map((name) => {
83-
let styleValue = processStyleValue(name, styleDescr[name]);
84-
let styleName = processStyleName(name);
85-
return `${styleName}: ${styleValue}`;
86-
}).join('; ');
80+
return Object.keys(styleDescr)
81+
.map((name) => {
82+
let styleValue = processStyleValue(name, styleDescr[name]);
83+
let styleName = processStyleName(name);
84+
return `${styleName}: ${styleValue}`;
85+
})
86+
.join('; ');
8787
}
8888

8989
export default styleToCSS;

0 commit comments

Comments
 (0)