@khanacademy/wonder-blocks-core 4.6.1 → 4.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/dist/es/index.js +2 -2
- package/dist/index.js +550 -0
- package/dist/index.js.flow +1 -1
- package/package.json +3 -4
- package/src/components/__docs__/id-provider.stories.js +1 -1
- package/src/components/__docs__/unique-id-provider.stories.js +1 -1
- package/src/components/__docs__/view.stories.js +2 -2
- package/src/components/__docs__/with-ssr-placeholder.stories.js +1 -1
- package/src/components/__tests__/id-provider.test.js +1 -1
- package/src/components/__tests__/render-state-root.test.js +2 -6
- package/src/components/__tests__/unique-id-provider.test.js +7 -7
- package/src/components/__tests__/view.test.js +1 -1
- package/src/components/__tests__/with-ssr-placeholder.test.js +3 -3
- package/src/components/id-provider.js +2 -2
- package/src/components/render-state-context.js +7 -6
- package/src/components/render-state-root.js +2 -6
- package/src/components/text.js +2 -2
- package/src/components/unique-id-provider.js +4 -4
- package/src/components/view.js +2 -2
- package/src/components/with-ssr-placeholder.js +2 -7
- package/src/hooks/__tests__/use-force-update.test.js +1 -1
- package/src/hooks/__tests__/use-is-mounted.test.js +1 -1
- package/src/hooks/__tests__/use-on-mount-effect.test.js +1 -1
- package/src/hooks/__tests__/use-online.test.js +1 -1
- package/src/hooks/__tests__/use-render-state.test.js +3 -7
- package/src/hooks/__tests__/use-unique-id.test.js +4 -4
- package/src/hooks/use-is-mounted.js +1 -1
- package/src/hooks/use-online.js +1 -1
- package/src/hooks/use-render-state.js +6 -4
- package/src/hooks/use-unique-id.js +5 -11
- package/src/index.js +16 -20
- package/src/util/__tests__/add-style.test.js +1 -1
- package/src/util/__tests__/server.test.js +1 -1
- package/src/util/__tests__/ssr-id-factory.test.js +1 -1
- package/src/util/__tests__/unique-id-factory.test.js +1 -1
- package/src/util/add-style.js +2 -2
- package/src/util/add-styles.flowtest.js +1 -1
- package/src/util/ssr-id-factory.js +1 -1
- package/src/util/unique-id-factory.js +1 -1
- package/src/util/util.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @khanacademy/wonder-blocks-core
|
|
2
2
|
|
|
3
|
+
## 4.7.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 91cb727c: Convert enums to POJOs
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 91cb727c: Remove file extensions from imports
|
|
12
|
+
|
|
13
|
+
## 4.6.2
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- 496119f2: Cleanup WB interdependencies
|
|
18
|
+
|
|
3
19
|
## 4.6.1
|
|
4
20
|
|
|
5
21
|
## 4.6.0
|
package/dist/es/index.js
CHANGED
|
@@ -196,11 +196,11 @@ View.defaultProps = {
|
|
|
196
196
|
tag: "div"
|
|
197
197
|
};
|
|
198
198
|
|
|
199
|
-
const RenderState =
|
|
199
|
+
const RenderState = {
|
|
200
200
|
Root: "root",
|
|
201
201
|
Initial: "initial",
|
|
202
202
|
Standard: "standard"
|
|
203
|
-
}
|
|
203
|
+
};
|
|
204
204
|
const RenderStateContext = React.createContext(RenderState.Root);
|
|
205
205
|
|
|
206
206
|
class WithSSRPlaceholder extends React.Component {
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,550 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _extends = require('@babel/runtime/helpers/extends');
|
|
6
|
+
var _objectWithoutPropertiesLoose = require('@babel/runtime/helpers/objectWithoutPropertiesLoose');
|
|
7
|
+
var React = require('react');
|
|
8
|
+
var aphrodite = require('aphrodite');
|
|
9
|
+
|
|
10
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
11
|
+
|
|
12
|
+
function _interopNamespace(e) {
|
|
13
|
+
if (e && e.__esModule) return e;
|
|
14
|
+
var n = Object.create(null);
|
|
15
|
+
if (e) {
|
|
16
|
+
Object.keys(e).forEach(function (k) {
|
|
17
|
+
if (k !== 'default') {
|
|
18
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
19
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () { return e[k]; }
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
n["default"] = e;
|
|
27
|
+
return Object.freeze(n);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
|
|
31
|
+
var _objectWithoutPropertiesLoose__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutPropertiesLoose);
|
|
32
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
33
|
+
|
|
34
|
+
function flatten(list) {
|
|
35
|
+
const result = [];
|
|
36
|
+
|
|
37
|
+
if (!list) {
|
|
38
|
+
return result;
|
|
39
|
+
} else if (Array.isArray(list)) {
|
|
40
|
+
for (const item of list) {
|
|
41
|
+
result.push.apply(result, flatten(item));
|
|
42
|
+
}
|
|
43
|
+
} else {
|
|
44
|
+
result.push(list);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function processStyleList(style) {
|
|
51
|
+
const stylesheetStyles = [];
|
|
52
|
+
const inlineStyles = [];
|
|
53
|
+
|
|
54
|
+
if (!style) {
|
|
55
|
+
return {
|
|
56
|
+
style: {},
|
|
57
|
+
className: ""
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const shouldInlineStyles = typeof global !== "undefined" && global.SNAPSHOT_INLINE_APHRODITE;
|
|
62
|
+
flatten(style).forEach(child => {
|
|
63
|
+
const _definition = child._definition;
|
|
64
|
+
|
|
65
|
+
if (_definition != null) {
|
|
66
|
+
if (shouldInlineStyles) {
|
|
67
|
+
const def = {};
|
|
68
|
+
|
|
69
|
+
for (const [key, value] of Object.entries(_definition)) {
|
|
70
|
+
def[key.replace(/-[a-z]/g, match => match[1].toUpperCase())] = value;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
inlineStyles.push(def);
|
|
74
|
+
} else {
|
|
75
|
+
stylesheetStyles.push(child);
|
|
76
|
+
}
|
|
77
|
+
} else {
|
|
78
|
+
inlineStyles.push(child);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
const inlineStylesObject = Object.assign.apply(Object, [{}].concat(inlineStyles));
|
|
82
|
+
|
|
83
|
+
if (inlineStyles.length > 0 && !shouldInlineStyles) {
|
|
84
|
+
const inlineStylesStyleSheet = aphrodite.StyleSheet.create({
|
|
85
|
+
inlineStyles: inlineStylesObject
|
|
86
|
+
});
|
|
87
|
+
stylesheetStyles.push(inlineStylesStyleSheet.inlineStyles);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return {
|
|
91
|
+
style: shouldInlineStyles ? inlineStylesObject : {},
|
|
92
|
+
className: aphrodite.css.apply(void 0, stylesheetStyles)
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const _excluded$2 = ["children", "style", "tag", "testId"];
|
|
97
|
+
const isHeaderRegex = /^h[1-6]$/;
|
|
98
|
+
const styles$1 = aphrodite.StyleSheet.create({
|
|
99
|
+
text: {
|
|
100
|
+
WebkitFontSmoothing: "antialiased",
|
|
101
|
+
MozOsxFontSmoothing: "grayscale"
|
|
102
|
+
},
|
|
103
|
+
header: {
|
|
104
|
+
marginTop: 0,
|
|
105
|
+
marginBottom: 0
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
class Text extends React__namespace.Component {
|
|
109
|
+
render() {
|
|
110
|
+
const _this$props = this.props,
|
|
111
|
+
{
|
|
112
|
+
children,
|
|
113
|
+
style,
|
|
114
|
+
tag: Tag,
|
|
115
|
+
testId
|
|
116
|
+
} = _this$props,
|
|
117
|
+
otherProps = _objectWithoutPropertiesLoose__default["default"](_this$props, _excluded$2);
|
|
118
|
+
|
|
119
|
+
const isHeader = isHeaderRegex.test(Tag);
|
|
120
|
+
const styleAttributes = processStyleList([styles$1.text, isHeader && styles$1.header, style]);
|
|
121
|
+
return React__namespace.createElement(Tag, _extends__default["default"]({}, otherProps, {
|
|
122
|
+
style: styleAttributes.style,
|
|
123
|
+
className: styleAttributes.className,
|
|
124
|
+
"data-test-id": testId
|
|
125
|
+
}), children);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
}
|
|
129
|
+
Text.defaultProps = {
|
|
130
|
+
tag: "span"
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const _excluded$1 = ["className", "style"];
|
|
134
|
+
function addStyle(Component, defaultStyle) {
|
|
135
|
+
function StyleComponent(props) {
|
|
136
|
+
const {
|
|
137
|
+
className,
|
|
138
|
+
style
|
|
139
|
+
} = props,
|
|
140
|
+
tmpOtherProps = _objectWithoutPropertiesLoose__default["default"](props, _excluded$1);
|
|
141
|
+
|
|
142
|
+
const otherProps = tmpOtherProps;
|
|
143
|
+
const reset = typeof Component === "string" ? overrides[Component] : null;
|
|
144
|
+
const {
|
|
145
|
+
className: aphroditeClassName,
|
|
146
|
+
style: inlineStyles
|
|
147
|
+
} = processStyleList([reset, defaultStyle, style]);
|
|
148
|
+
return React__namespace.createElement(Component, _extends__default["default"]({}, otherProps, {
|
|
149
|
+
className: [aphroditeClassName, className].filter(Boolean).join(" "),
|
|
150
|
+
style: inlineStyles
|
|
151
|
+
}));
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return StyleComponent;
|
|
155
|
+
}
|
|
156
|
+
const overrides = aphrodite.StyleSheet.create({
|
|
157
|
+
button: {
|
|
158
|
+
margin: 0,
|
|
159
|
+
"::-moz-focus-inner": {
|
|
160
|
+
border: 0
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
const _excluded = ["testId", "tag"];
|
|
166
|
+
const styles = aphrodite.StyleSheet.create({
|
|
167
|
+
default: {
|
|
168
|
+
alignItems: "stretch",
|
|
169
|
+
borderWidth: 0,
|
|
170
|
+
borderStyle: "solid",
|
|
171
|
+
boxSizing: "border-box",
|
|
172
|
+
display: "flex",
|
|
173
|
+
flexDirection: "column",
|
|
174
|
+
margin: 0,
|
|
175
|
+
padding: 0,
|
|
176
|
+
position: "relative",
|
|
177
|
+
zIndex: 0,
|
|
178
|
+
minHeight: 0,
|
|
179
|
+
minWidth: 0
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
const StyledDiv = addStyle("div", styles.default);
|
|
183
|
+
const StyledArticle = addStyle("article", styles.default);
|
|
184
|
+
const StyledAside = addStyle("aside", styles.default);
|
|
185
|
+
const StyledNav = addStyle("nav", styles.default);
|
|
186
|
+
const StyledSection = addStyle("section", styles.default);
|
|
187
|
+
class View extends React__namespace.Component {
|
|
188
|
+
render() {
|
|
189
|
+
const _this$props = this.props,
|
|
190
|
+
{
|
|
191
|
+
testId,
|
|
192
|
+
tag
|
|
193
|
+
} = _this$props,
|
|
194
|
+
restProps = _objectWithoutPropertiesLoose__default["default"](_this$props, _excluded);
|
|
195
|
+
|
|
196
|
+
const props = _extends__default["default"]({}, restProps, {
|
|
197
|
+
"data-test-id": testId
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
switch (tag) {
|
|
201
|
+
case "article":
|
|
202
|
+
return React__namespace.createElement(StyledArticle, props);
|
|
203
|
+
|
|
204
|
+
case "aside":
|
|
205
|
+
return React__namespace.createElement(StyledAside, props);
|
|
206
|
+
|
|
207
|
+
case "nav":
|
|
208
|
+
return React__namespace.createElement(StyledNav, props);
|
|
209
|
+
|
|
210
|
+
case "section":
|
|
211
|
+
return React__namespace.createElement(StyledSection, props);
|
|
212
|
+
|
|
213
|
+
case "div":
|
|
214
|
+
return React__namespace.createElement(StyledDiv, props);
|
|
215
|
+
|
|
216
|
+
default:
|
|
217
|
+
throw Error(`${tag} is not an allowed value for the 'tag' prop`);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
}
|
|
222
|
+
View.defaultProps = {
|
|
223
|
+
tag: "div"
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
const RenderState = {
|
|
227
|
+
Root: "root",
|
|
228
|
+
Initial: "initial",
|
|
229
|
+
Standard: "standard"
|
|
230
|
+
};
|
|
231
|
+
const RenderStateContext = React__namespace.createContext(RenderState.Root);
|
|
232
|
+
|
|
233
|
+
class WithSSRPlaceholder extends React__namespace.Component {
|
|
234
|
+
constructor(...args) {
|
|
235
|
+
super(...args);
|
|
236
|
+
this.state = {
|
|
237
|
+
mounted: false
|
|
238
|
+
};
|
|
239
|
+
this._isTheRootComponent = false;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
componentDidMount() {
|
|
243
|
+
if (this._isTheRootComponent) {
|
|
244
|
+
this.setState({
|
|
245
|
+
mounted: true
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
_renderAsRootComponent() {
|
|
251
|
+
const {
|
|
252
|
+
mounted
|
|
253
|
+
} = this.state;
|
|
254
|
+
const {
|
|
255
|
+
children,
|
|
256
|
+
placeholder
|
|
257
|
+
} = this.props;
|
|
258
|
+
this._isTheRootComponent = true;
|
|
259
|
+
|
|
260
|
+
if (mounted) {
|
|
261
|
+
return React__namespace.createElement(RenderStateContext.Provider, {
|
|
262
|
+
value: RenderState.Standard
|
|
263
|
+
}, children());
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (placeholder) {
|
|
267
|
+
return React__namespace.createElement(RenderStateContext.Provider, {
|
|
268
|
+
value: RenderState.Initial
|
|
269
|
+
}, placeholder());
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
return null;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
_maybeRender(renderState) {
|
|
276
|
+
const {
|
|
277
|
+
children,
|
|
278
|
+
placeholder
|
|
279
|
+
} = this.props;
|
|
280
|
+
|
|
281
|
+
switch (renderState) {
|
|
282
|
+
case RenderState.Root:
|
|
283
|
+
return this._renderAsRootComponent();
|
|
284
|
+
|
|
285
|
+
case RenderState.Initial:
|
|
286
|
+
if (placeholder) {
|
|
287
|
+
return placeholder();
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
return null;
|
|
291
|
+
|
|
292
|
+
case RenderState.Standard:
|
|
293
|
+
return children();
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
{
|
|
297
|
+
var _JSON$stringify;
|
|
298
|
+
|
|
299
|
+
console.log(`We got a render state we don't understand: "${(_JSON$stringify = JSON.stringify(renderState)) != null ? _JSON$stringify : ""}"`);
|
|
300
|
+
return this._maybeRender(RenderState.Root);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
render() {
|
|
305
|
+
return React__namespace.createElement(RenderStateContext.Consumer, null, value => this._maybeRender(value));
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
class UniqueIDFactory {
|
|
311
|
+
constructor(scope) {
|
|
312
|
+
this.get = key => {
|
|
313
|
+
const normalizedKey = key.toLowerCase();
|
|
314
|
+
|
|
315
|
+
if (!this._hasValidIdChars(key)) {
|
|
316
|
+
throw new Error(`Invalid identifier key: ${key}`);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
return `${this._uniqueFactoryName}-${normalizedKey}`;
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
scope = typeof scope === "string" ? scope : "";
|
|
323
|
+
const normalizedScope = scope.toLowerCase();
|
|
324
|
+
|
|
325
|
+
if (!this._hasValidIdChars(normalizedScope)) {
|
|
326
|
+
throw new Error(`Invalid factory scope: ${scope}`);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
this._uniqueFactoryName = `uid-${normalizedScope}-${UniqueIDFactory._factoryUniquenessCounter++}`;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
_hasValidIdChars(value) {
|
|
333
|
+
if (typeof value !== "string") {
|
|
334
|
+
return false;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
const invalidCharsReplaced = value.replace(/[^\d\w-]/g, "-");
|
|
338
|
+
return value === invalidCharsReplaced;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
}
|
|
342
|
+
UniqueIDFactory._factoryUniquenessCounter = 0;
|
|
343
|
+
|
|
344
|
+
class SsrIDFactory {
|
|
345
|
+
get(id) {
|
|
346
|
+
return id;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
SsrIDFactory.Default = new SsrIDFactory();
|
|
352
|
+
var SsrIDFactory$1 = SsrIDFactory.Default;
|
|
353
|
+
|
|
354
|
+
class UniqueIDProvider extends React__namespace.Component {
|
|
355
|
+
_performRender(firstRender) {
|
|
356
|
+
const {
|
|
357
|
+
children,
|
|
358
|
+
mockOnFirstRender,
|
|
359
|
+
scope
|
|
360
|
+
} = this.props;
|
|
361
|
+
|
|
362
|
+
if (firstRender) {
|
|
363
|
+
if (mockOnFirstRender) {
|
|
364
|
+
return children(SsrIDFactory$1);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
return null;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
if (!this._idFactory) {
|
|
371
|
+
this._idFactory = new UniqueIDFactory(scope);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
return children(this._idFactory);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
render() {
|
|
378
|
+
return React__namespace.createElement(WithSSRPlaceholder, {
|
|
379
|
+
placeholder: () => this._performRender(true)
|
|
380
|
+
}, () => this._performRender(false));
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
class IDProvider extends React__namespace.Component {
|
|
386
|
+
renderChildren(ids) {
|
|
387
|
+
const {
|
|
388
|
+
id,
|
|
389
|
+
children
|
|
390
|
+
} = this.props;
|
|
391
|
+
const uniqueId = ids ? ids.get(IDProvider.defaultId) : id;
|
|
392
|
+
|
|
393
|
+
if (!uniqueId) {
|
|
394
|
+
throw new Error("Did not get an identifier factory nor a id prop");
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
return children(uniqueId);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
render() {
|
|
401
|
+
const {
|
|
402
|
+
id,
|
|
403
|
+
scope
|
|
404
|
+
} = this.props;
|
|
405
|
+
|
|
406
|
+
if (id) {
|
|
407
|
+
return this.renderChildren();
|
|
408
|
+
} else {
|
|
409
|
+
return React__namespace.createElement(UniqueIDProvider, {
|
|
410
|
+
scope: scope,
|
|
411
|
+
mockOnFirstRender: true
|
|
412
|
+
}, ids => this.renderChildren(ids));
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
}
|
|
417
|
+
IDProvider.defaultId = "wb-id";
|
|
418
|
+
|
|
419
|
+
let serverSide = false;
|
|
420
|
+
var server = {
|
|
421
|
+
isServerSide: () => serverSide,
|
|
422
|
+
setServerSide: () => {
|
|
423
|
+
serverSide = true;
|
|
424
|
+
}
|
|
425
|
+
};
|
|
426
|
+
|
|
427
|
+
const useRenderState = () => React.useContext(RenderStateContext);
|
|
428
|
+
|
|
429
|
+
const useUniqueIdWithMock = scope => {
|
|
430
|
+
const renderState = useRenderState();
|
|
431
|
+
const idFactory = React.useRef(null);
|
|
432
|
+
|
|
433
|
+
if (renderState === RenderState.Root) {
|
|
434
|
+
throw new Error("Components using useUniqueIdWithMock() should be descendants of <RenderStateRoot>");
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
if (renderState === RenderState.Initial) {
|
|
438
|
+
return SsrIDFactory$1;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
if (!idFactory.current) {
|
|
442
|
+
idFactory.current = new UniqueIDFactory(scope);
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
return idFactory.current;
|
|
446
|
+
};
|
|
447
|
+
const useUniqueIdWithoutMock = scope => {
|
|
448
|
+
const renderState = useRenderState();
|
|
449
|
+
const idFactory = React.useRef(null);
|
|
450
|
+
|
|
451
|
+
if (renderState === RenderState.Root) {
|
|
452
|
+
throw new Error("Components using useUniqueIdWithoutMock() should be descendants of <RenderStateRoot>");
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
if (renderState === RenderState.Initial) {
|
|
456
|
+
return null;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
if (!idFactory.current) {
|
|
460
|
+
idFactory.current = new UniqueIDFactory(scope);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
return idFactory.current;
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
const useForceUpdate = () => {
|
|
467
|
+
const [, setState] = React__namespace.useState(false);
|
|
468
|
+
const forceUpdate = React__namespace.useCallback(() => setState(state => !state), []);
|
|
469
|
+
return forceUpdate;
|
|
470
|
+
};
|
|
471
|
+
|
|
472
|
+
const useOnMountEffect = callback => {
|
|
473
|
+
React__namespace.useEffect(callback, []);
|
|
474
|
+
};
|
|
475
|
+
|
|
476
|
+
const useIsMounted = () => {
|
|
477
|
+
const isMounted = React__namespace.useRef(false);
|
|
478
|
+
useOnMountEffect(() => {
|
|
479
|
+
isMounted.current = true;
|
|
480
|
+
return () => {
|
|
481
|
+
isMounted.current = false;
|
|
482
|
+
};
|
|
483
|
+
});
|
|
484
|
+
return React__namespace.useCallback(() => isMounted.current, []);
|
|
485
|
+
};
|
|
486
|
+
|
|
487
|
+
const useOnline = () => {
|
|
488
|
+
const forceUpdate = useForceUpdate();
|
|
489
|
+
React.useEffect(() => {
|
|
490
|
+
const handleChange = () => forceUpdate();
|
|
491
|
+
|
|
492
|
+
window.addEventListener("online", handleChange);
|
|
493
|
+
window.addEventListener("offline", handleChange);
|
|
494
|
+
return () => {
|
|
495
|
+
window.removeEventListener("online", handleChange);
|
|
496
|
+
window.removeEventListener("offline", handleChange);
|
|
497
|
+
};
|
|
498
|
+
}, [forceUpdate]);
|
|
499
|
+
return navigator.onLine;
|
|
500
|
+
};
|
|
501
|
+
|
|
502
|
+
const {
|
|
503
|
+
useEffect,
|
|
504
|
+
useState
|
|
505
|
+
} = React__namespace;
|
|
506
|
+
|
|
507
|
+
const RenderStateRoot = ({
|
|
508
|
+
children,
|
|
509
|
+
throwIfNested
|
|
510
|
+
}) => {
|
|
511
|
+
const [firstRender, setFirstRender] = useState(true);
|
|
512
|
+
const renderState = useRenderState();
|
|
513
|
+
useEffect(() => {
|
|
514
|
+
setFirstRender(false);
|
|
515
|
+
}, []);
|
|
516
|
+
|
|
517
|
+
if (renderState !== RenderState.Root) {
|
|
518
|
+
if (throwIfNested) {
|
|
519
|
+
throw new Error("There's already a <RenderStateRoot> above this instance in " + "the render tree. This instance should be removed.");
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
return children;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
const value = firstRender ? RenderState.Initial : RenderState.Standard;
|
|
526
|
+
return React__namespace.createElement(RenderStateContext.Provider, {
|
|
527
|
+
value: value
|
|
528
|
+
}, children);
|
|
529
|
+
};
|
|
530
|
+
|
|
531
|
+
RenderStateRoot.defaultProps = {
|
|
532
|
+
throwIfNested: true
|
|
533
|
+
};
|
|
534
|
+
|
|
535
|
+
exports.IDProvider = IDProvider;
|
|
536
|
+
exports.RenderState = RenderState;
|
|
537
|
+
exports.RenderStateRoot = RenderStateRoot;
|
|
538
|
+
exports.Server = server;
|
|
539
|
+
exports.Text = Text;
|
|
540
|
+
exports.UniqueIDProvider = UniqueIDProvider;
|
|
541
|
+
exports.View = View;
|
|
542
|
+
exports.WithSSRPlaceholder = WithSSRPlaceholder;
|
|
543
|
+
exports.addStyle = addStyle;
|
|
544
|
+
exports.useForceUpdate = useForceUpdate;
|
|
545
|
+
exports.useIsMounted = useIsMounted;
|
|
546
|
+
exports.useOnMountEffect = useOnMountEffect;
|
|
547
|
+
exports.useOnline = useOnline;
|
|
548
|
+
exports.useRenderState = useRenderState;
|
|
549
|
+
exports.useUniqueIdWithMock = useUniqueIdWithMock;
|
|
550
|
+
exports.useUniqueIdWithoutMock = useUniqueIdWithoutMock;
|
package/dist/index.js.flow
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @flow
|
|
2
|
-
export * from "../src/index
|
|
2
|
+
export * from "../src/index";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@khanacademy/wonder-blocks-core",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.7.0",
|
|
4
4
|
"design": "v1",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -13,8 +13,7 @@
|
|
|
13
13
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@babel/runtime": "^7.18.6"
|
|
17
|
-
"@khanacademy/wonder-blocks-spacing": "^3.0.5"
|
|
16
|
+
"@babel/runtime": "^7.18.6"
|
|
18
17
|
},
|
|
19
18
|
"peerDependencies": {
|
|
20
19
|
"aphrodite": "^1.2.5",
|
|
@@ -25,7 +24,7 @@
|
|
|
25
24
|
"react-router-dom": "5.3.0"
|
|
26
25
|
},
|
|
27
26
|
"devDependencies": {
|
|
28
|
-
"wb-dev-build-settings": "^0.
|
|
27
|
+
"wb-dev-build-settings": "^0.7.1"
|
|
29
28
|
},
|
|
30
29
|
"author": "",
|
|
31
30
|
"license": "MIT"
|
|
@@ -5,7 +5,7 @@ import {IDProvider, View} from "@khanacademy/wonder-blocks-core";
|
|
|
5
5
|
|
|
6
6
|
import type {StoryComponentType} from "@storybook/react";
|
|
7
7
|
|
|
8
|
-
import ComponentInfo from "../../../../../.storybook/components/component-info
|
|
8
|
+
import ComponentInfo from "../../../../../.storybook/components/component-info";
|
|
9
9
|
import {name, version} from "../../../package.json";
|
|
10
10
|
|
|
11
11
|
export default {
|
|
@@ -8,7 +8,7 @@ import {Body, HeadingSmall} from "@khanacademy/wonder-blocks-typography";
|
|
|
8
8
|
|
|
9
9
|
import type {StoryComponentType} from "@storybook/react";
|
|
10
10
|
|
|
11
|
-
import ComponentInfo from "../../../../../.storybook/components/component-info
|
|
11
|
+
import ComponentInfo from "../../../../../.storybook/components/component-info";
|
|
12
12
|
import {name, version} from "../../../package.json";
|
|
13
13
|
|
|
14
14
|
export default {
|
|
@@ -13,9 +13,9 @@ import {
|
|
|
13
13
|
|
|
14
14
|
import type {StoryComponentType} from "@storybook/react";
|
|
15
15
|
|
|
16
|
-
import ComponentInfo from "../../../../../.storybook/components/component-info
|
|
16
|
+
import ComponentInfo from "../../../../../.storybook/components/component-info";
|
|
17
17
|
import {name, version} from "../../../package.json";
|
|
18
|
-
import viewArgTypes from "./view.argtypes
|
|
18
|
+
import viewArgTypes from "./view.argtypes";
|
|
19
19
|
|
|
20
20
|
export default {
|
|
21
21
|
title: "Core / View",
|
|
@@ -5,7 +5,7 @@ import {Body} from "@khanacademy/wonder-blocks-typography";
|
|
|
5
5
|
|
|
6
6
|
import type {StoryComponentType} from "@storybook/react";
|
|
7
7
|
|
|
8
|
-
import ComponentInfo from "../../../../../.storybook/components/component-info
|
|
8
|
+
import ComponentInfo from "../../../../../.storybook/components/component-info";
|
|
9
9
|
import {name, version} from "../../../package.json";
|
|
10
10
|
|
|
11
11
|
export default {
|
|
@@ -2,12 +2,8 @@
|
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import {render} from "@testing-library/react";
|
|
4
4
|
|
|
5
|
-
import {RenderStateRoot} from "../render-state-root
|
|
6
|
-
|
|
7
|
-
// have fixed:
|
|
8
|
-
// https://github.com/import-js/eslint-plugin-import/issues/2073
|
|
9
|
-
// eslint-disable-next-line import/named
|
|
10
|
-
import {RenderState, RenderStateContext} from "../render-state-context.js";
|
|
5
|
+
import {RenderStateRoot} from "../render-state-root";
|
|
6
|
+
import {RenderState, RenderStateContext} from "../render-state-context";
|
|
11
7
|
|
|
12
8
|
const {useContext} = React;
|
|
13
9
|
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import * as React from "react";
|
|
3
|
-
import * as ReactDOMServer from "react-dom/server
|
|
3
|
+
import * as ReactDOMServer from "react-dom/server";
|
|
4
4
|
import {render} from "@testing-library/react";
|
|
5
5
|
|
|
6
|
-
import View from "../view
|
|
6
|
+
import View from "../view";
|
|
7
7
|
|
|
8
|
-
import SsrIDFactory from "../../util/ssr-id-factory
|
|
9
|
-
import UniqueIDFactory from "../../util/unique-id-factory
|
|
10
|
-
import UniqueIDProvider from "../unique-id-provider
|
|
11
|
-
import WithSSRPlaceholder from "../with-ssr-placeholder
|
|
12
|
-
import {RenderStateRoot} from "../render-state-root
|
|
8
|
+
import SsrIDFactory from "../../util/ssr-id-factory";
|
|
9
|
+
import UniqueIDFactory from "../../util/unique-id-factory";
|
|
10
|
+
import UniqueIDProvider from "../unique-id-provider";
|
|
11
|
+
import WithSSRPlaceholder from "../with-ssr-placeholder";
|
|
12
|
+
import {RenderStateRoot} from "../render-state-root";
|
|
13
13
|
|
|
14
14
|
describe("UniqueIDProvider", () => {
|
|
15
15
|
describe("mockOnFirstRender is default (false)", () => {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import * as React from "react";
|
|
3
|
-
import * as ReactDOMServer from "react-dom/server
|
|
3
|
+
import * as ReactDOMServer from "react-dom/server";
|
|
4
4
|
import {render} from "@testing-library/react";
|
|
5
5
|
|
|
6
|
-
import WithSSRPlaceholder from "../with-ssr-placeholder
|
|
7
|
-
import {RenderStateRoot} from "../render-state-root
|
|
6
|
+
import WithSSRPlaceholder from "../with-ssr-placeholder";
|
|
7
|
+
import {RenderStateRoot} from "../render-state-root";
|
|
8
8
|
|
|
9
9
|
describe("WithSSRPlaceholder", () => {
|
|
10
10
|
describe("client-side rendering", () => {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
|
|
4
|
-
import UniqueIDProvider from "./unique-id-provider
|
|
4
|
+
import UniqueIDProvider from "./unique-id-provider";
|
|
5
5
|
|
|
6
|
-
import type {IIdentifierFactory} from "../util/types
|
|
6
|
+
import type {IIdentifierFactory} from "../util/types";
|
|
7
7
|
|
|
8
8
|
type Props = {|
|
|
9
9
|
/**
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
// TODO(FEI-5000): Convert to TS enum after all codebases have been migrated
|
|
5
|
+
export const RenderState = {
|
|
6
|
+
Root: ("root": "root"),
|
|
7
|
+
Initial: ("initial": "initial"),
|
|
8
|
+
Standard: ("standard": "standard"),
|
|
9
|
+
};
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* This is the context that tracks who is doing what in our SSR component tree.
|
|
@@ -22,5 +23,5 @@ export enum RenderState {
|
|
|
22
23
|
* standard:
|
|
23
24
|
* means that we're all now doing non-SSR rendering
|
|
24
25
|
*/
|
|
25
|
-
export const RenderStateContext: React.Context<RenderState
|
|
26
|
+
export const RenderStateContext: React.Context<$Values<typeof RenderState>> =
|
|
26
27
|
React.createContext(RenderState.Root);
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
// https://github.com/import-js/eslint-plugin-import/issues/2073
|
|
7
|
-
// eslint-disable-next-line import/named
|
|
8
|
-
import {RenderState, RenderStateContext} from "./render-state-context.js";
|
|
9
|
-
import {useRenderState} from "../hooks/use-render-state.js";
|
|
4
|
+
import {RenderState, RenderStateContext} from "./render-state-context";
|
|
5
|
+
import {useRenderState} from "../hooks/use-render-state";
|
|
10
6
|
|
|
11
7
|
const {useEffect, useState} = React;
|
|
12
8
|
|
package/src/components/text.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import {StyleSheet} from "aphrodite";
|
|
4
4
|
|
|
5
|
-
import {processStyleList} from "../util/util
|
|
5
|
+
import {processStyleList} from "../util/util";
|
|
6
6
|
|
|
7
|
-
import type {TextViewSharedProps} from "../util/types
|
|
7
|
+
import type {TextViewSharedProps} from "../util/types";
|
|
8
8
|
|
|
9
9
|
// NOTE(jeresig): We want to leave the props for these open so that we can
|
|
10
10
|
// handle uncommon props for elements (e.g. htmlFor for labels).
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
|
|
4
|
-
import WithSSRPlaceholder from "./with-ssr-placeholder
|
|
4
|
+
import WithSSRPlaceholder from "./with-ssr-placeholder";
|
|
5
5
|
|
|
6
|
-
import UniqueIDFactory from "../util/unique-id-factory
|
|
7
|
-
import SsrIDFactory from "../util/ssr-id-factory
|
|
6
|
+
import UniqueIDFactory from "../util/unique-id-factory";
|
|
7
|
+
import SsrIDFactory from "../util/ssr-id-factory";
|
|
8
8
|
|
|
9
|
-
import type {IIdentifierFactory} from "../util/types
|
|
9
|
+
import type {IIdentifierFactory} from "../util/types";
|
|
10
10
|
|
|
11
11
|
// TODO(FEI-4202): update to use `useUniqueId`
|
|
12
12
|
type Props = {|
|
package/src/components/view.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import {StyleSheet} from "aphrodite";
|
|
4
4
|
|
|
5
|
-
import addStyle from "../util/add-style
|
|
5
|
+
import addStyle from "../util/add-style";
|
|
6
6
|
|
|
7
|
-
import type {TextViewSharedProps} from "../util/types
|
|
7
|
+
import type {TextViewSharedProps} from "../util/types";
|
|
8
8
|
|
|
9
9
|
const styles = StyleSheet.create({
|
|
10
10
|
// https://github.com/facebook/css-layout#default-values
|
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
// TODO(somewhatabstract, FEI-4174): Update eslint-plugin-import when they
|
|
6
|
-
// have fixed:
|
|
7
|
-
// https://github.com/import-js/eslint-plugin-import/issues/2073
|
|
8
|
-
// eslint-disable-next-line import/named
|
|
9
|
-
import {RenderState, RenderStateContext} from "./render-state-context.js";
|
|
4
|
+
import {RenderState, RenderStateContext} from "./render-state-context";
|
|
10
5
|
|
|
11
6
|
/**
|
|
12
7
|
* We use render functions so that we don't do any work unless we need to.
|
|
@@ -117,7 +112,7 @@ export default class WithSSRPlaceholder extends React.Component<Props, State> {
|
|
|
117
112
|
return null;
|
|
118
113
|
}
|
|
119
114
|
|
|
120
|
-
_maybeRender(renderState: RenderState): React.Node {
|
|
115
|
+
_maybeRender(renderState: $Values<typeof RenderState>): React.Node {
|
|
121
116
|
const {children, placeholder} = this.props;
|
|
122
117
|
|
|
123
118
|
switch (renderState) {
|
|
@@ -3,7 +3,7 @@ import * as React from "react";
|
|
|
3
3
|
import {render, act} from "@testing-library/react";
|
|
4
4
|
import {renderHook} from "@testing-library/react-hooks";
|
|
5
5
|
|
|
6
|
-
import {useForceUpdate} from "../use-force-update
|
|
6
|
+
import {useForceUpdate} from "../use-force-update";
|
|
7
7
|
|
|
8
8
|
describe("#useForceUpdate", () => {
|
|
9
9
|
it("should return a function", () => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import {renderHook} from "@testing-library/react-hooks";
|
|
3
3
|
|
|
4
|
-
import {useOnMountEffect} from "../use-on-mount-effect
|
|
4
|
+
import {useOnMountEffect} from "../use-on-mount-effect";
|
|
5
5
|
|
|
6
6
|
describe("#useOnMountEffect", () => {
|
|
7
7
|
it("should call the callback once", () => {
|
|
@@ -3,7 +3,7 @@ import * as React from "react";
|
|
|
3
3
|
import {render, act as reactAct} from "@testing-library/react";
|
|
4
4
|
import {renderHook} from "@testing-library/react-hooks";
|
|
5
5
|
|
|
6
|
-
import {useOnline} from "../use-online
|
|
6
|
+
import {useOnline} from "../use-online";
|
|
7
7
|
|
|
8
8
|
describe("useOnline", () => {
|
|
9
9
|
it("should return true when navigator.onLine is true", () => {
|
|
@@ -3,13 +3,9 @@ import * as React from "react";
|
|
|
3
3
|
import {renderHook as renderHookOnServer} from "@testing-library/react-hooks/server";
|
|
4
4
|
import {renderHook} from "@testing-library/react-hooks";
|
|
5
5
|
|
|
6
|
-
import {useRenderState} from "../use-render-state
|
|
7
|
-
import {RenderStateRoot} from "../../components/render-state-root
|
|
8
|
-
|
|
9
|
-
// have fixed:
|
|
10
|
-
// https://github.com/import-js/eslint-plugin-import/issues/2073
|
|
11
|
-
// eslint-disable-next-line import/named
|
|
12
|
-
import {RenderState} from "../../components/render-state-context.js";
|
|
6
|
+
import {useRenderState} from "../use-render-state";
|
|
7
|
+
import {RenderStateRoot} from "../../components/render-state-root";
|
|
8
|
+
import {RenderState} from "../../components/render-state-context";
|
|
13
9
|
|
|
14
10
|
describe("useRenderState", () => {
|
|
15
11
|
test("server-side render returns RenderState.Initial", () => {
|
|
@@ -3,10 +3,10 @@ import * as React from "react";
|
|
|
3
3
|
import {render} from "@testing-library/react";
|
|
4
4
|
import {renderHook} from "@testing-library/react-hooks/server";
|
|
5
5
|
|
|
6
|
-
import SsrIDFactory from "../../util/ssr-id-factory
|
|
7
|
-
import UniqueIDFactory from "../../util/unique-id-factory
|
|
8
|
-
import {useUniqueIdWithMock, useUniqueIdWithoutMock} from "../use-unique-id
|
|
9
|
-
import {RenderStateRoot} from "../../components/render-state-root
|
|
6
|
+
import SsrIDFactory from "../../util/ssr-id-factory";
|
|
7
|
+
import UniqueIDFactory from "../../util/unique-id-factory";
|
|
8
|
+
import {useUniqueIdWithMock, useUniqueIdWithoutMock} from "../use-unique-id";
|
|
9
|
+
import {RenderStateRoot} from "../../components/render-state-root";
|
|
10
10
|
|
|
11
11
|
describe("useUniqueIdWithoutMock", () => {
|
|
12
12
|
test("server-side render returns null", () => {
|
package/src/hooks/use-online.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import {useContext} from "react";
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
RenderState,
|
|
6
|
+
RenderStateContext,
|
|
7
|
+
} from "../components/render-state-context";
|
|
5
8
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export const useRenderState = (): RenderState => useContext(RenderStateContext);
|
|
9
|
+
export const useRenderState = (): $Values<typeof RenderState> =>
|
|
10
|
+
useContext(RenderStateContext);
|
|
@@ -1,19 +1,13 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import {useRef} from "react";
|
|
3
3
|
|
|
4
|
-
import {useRenderState} from "./use-render-state
|
|
5
|
-
import SsrIDFactory from "../util/ssr-id-factory
|
|
6
|
-
import UniqueIDFactory from "../util/unique-id-factory
|
|
4
|
+
import {useRenderState} from "./use-render-state";
|
|
5
|
+
import SsrIDFactory from "../util/ssr-id-factory";
|
|
6
|
+
import UniqueIDFactory from "../util/unique-id-factory";
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
// TODO(somewhatabstract, FEI-4174): Update eslint-plugin-import when they
|
|
10
|
-
// have fixed:
|
|
11
|
-
// https://github.com/import-js/eslint-plugin-import/issues/2073
|
|
12
|
-
// eslint-disable-next-line import/named
|
|
13
|
-
RenderState,
|
|
14
|
-
} from "../components/render-state-context.js";
|
|
8
|
+
import {RenderState} from "../components/render-state-context";
|
|
15
9
|
|
|
16
|
-
import type {IIdentifierFactory} from "../util/types
|
|
10
|
+
import type {IIdentifierFactory} from "../util/types";
|
|
17
11
|
|
|
18
12
|
/**
|
|
19
13
|
* Returns a unique identifier factory. If the parent component hasn't
|
package/src/index.js
CHANGED
|
@@ -1,27 +1,23 @@
|
|
|
1
1
|
// @flow
|
|
2
|
-
import type {AriaProps, IIdentifierFactory, StyleType} from "./util/types
|
|
2
|
+
import type {AriaProps, IIdentifierFactory, StyleType} from "./util/types";
|
|
3
3
|
|
|
4
|
-
export {default as Text} from "./components/text
|
|
5
|
-
export {default as View} from "./components/view
|
|
6
|
-
export {default as WithSSRPlaceholder} from "./components/with-ssr-placeholder
|
|
7
|
-
export {default as IDProvider} from "./components/id-provider
|
|
8
|
-
export {default as UniqueIDProvider} from "./components/unique-id-provider
|
|
9
|
-
export {default as addStyle} from "./util/add-style
|
|
10
|
-
export {default as Server} from "./util/server
|
|
4
|
+
export {default as Text} from "./components/text";
|
|
5
|
+
export {default as View} from "./components/view";
|
|
6
|
+
export {default as WithSSRPlaceholder} from "./components/with-ssr-placeholder";
|
|
7
|
+
export {default as IDProvider} from "./components/id-provider";
|
|
8
|
+
export {default as UniqueIDProvider} from "./components/unique-id-provider";
|
|
9
|
+
export {default as addStyle} from "./util/add-style";
|
|
10
|
+
export {default as Server} from "./util/server";
|
|
11
11
|
export {
|
|
12
12
|
useUniqueIdWithMock,
|
|
13
13
|
useUniqueIdWithoutMock,
|
|
14
|
-
} from "./hooks/use-unique-id
|
|
15
|
-
export {useForceUpdate} from "./hooks/use-force-update
|
|
16
|
-
export {useIsMounted} from "./hooks/use-is-mounted
|
|
17
|
-
export {useOnMountEffect} from "./hooks/use-on-mount-effect
|
|
18
|
-
export {useOnline} from "./hooks/use-online
|
|
19
|
-
export {useRenderState} from "./hooks/use-render-state
|
|
20
|
-
export {RenderStateRoot} from "./components/render-state-root
|
|
21
|
-
|
|
22
|
-
// have fixed:
|
|
23
|
-
// https://github.com/import-js/eslint-plugin-import/issues/2073
|
|
24
|
-
// eslint-disable-next-line import/named
|
|
25
|
-
export {RenderState} from "./components/render-state-context.js";
|
|
14
|
+
} from "./hooks/use-unique-id";
|
|
15
|
+
export {useForceUpdate} from "./hooks/use-force-update";
|
|
16
|
+
export {useIsMounted} from "./hooks/use-is-mounted";
|
|
17
|
+
export {useOnMountEffect} from "./hooks/use-on-mount-effect";
|
|
18
|
+
export {useOnline} from "./hooks/use-online";
|
|
19
|
+
export {useRenderState} from "./hooks/use-render-state";
|
|
20
|
+
export {RenderStateRoot} from "./components/render-state-root";
|
|
21
|
+
export {RenderState} from "./components/render-state-context";
|
|
26
22
|
|
|
27
23
|
export type {AriaProps, IIdentifierFactory, StyleType};
|
|
@@ -3,7 +3,7 @@ describe("SsrIDFactory", () => {
|
|
|
3
3
|
test("returns the same id, regardless of client or server render", async () => {
|
|
4
4
|
// Arrange
|
|
5
5
|
const id = "this-is-the-id";
|
|
6
|
-
const {default: SsrIDFactory} = await import("../ssr-id-factory
|
|
6
|
+
const {default: SsrIDFactory} = await import("../ssr-id-factory");
|
|
7
7
|
|
|
8
8
|
// Act
|
|
9
9
|
const result = SsrIDFactory.get(id);
|
package/src/util/add-style.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import {StyleSheet} from "aphrodite";
|
|
4
4
|
|
|
5
|
-
import {processStyleList} from "./util
|
|
5
|
+
import {processStyleList} from "./util";
|
|
6
6
|
|
|
7
|
-
import type {StyleType} from "./types
|
|
7
|
+
import type {StyleType} from "./types";
|
|
8
8
|
|
|
9
9
|
// TODO(kevinb): have an a version which uses exact object types
|
|
10
10
|
export default function addStyle<T: React.AbstractComponent<any> | string>(
|
package/src/util/util.js
CHANGED