|
1 |
| -import {compressToEncodedURIComponent} from 'lz-string' |
| 1 | +import {getPlaygroundUrl} from './playground-helper' |
2 | 2 | import * as queries from './queries'
|
3 | 3 | import {getQueriesForElement} from './get-queries-for-element'
|
4 | 4 | import {logDOM} from './pretty-dom'
|
5 | 5 | import {getDocument} from './helpers'
|
6 | 6 |
|
7 |
| -function unindent(string) { |
8 |
| - // remove white spaces first, to save a few bytes. |
9 |
| - // testing-playground will reformat on load any ways. |
10 |
| - return string.replace(/[ \t]*[\n][ \t]*/g, '\n') |
11 |
| -} |
12 |
| - |
13 |
| -function encode(value) { |
14 |
| - return compressToEncodedURIComponent(unindent(value)) |
15 |
| -} |
16 |
| - |
17 |
| -function getPlaygroundUrl(markup) { |
18 |
| - return `https://testing-playground.com/#markup=${encode(markup)}` |
19 |
| -} |
20 |
| - |
21 | 7 | const debug = (element, maxLength, options) =>
|
22 | 8 | Array.isArray(element)
|
23 | 9 | ? element.forEach(el => logDOM(el, maxLength, options))
|
24 | 10 | : logDOM(element, maxLength, options)
|
25 | 11 |
|
26 | 12 | const logTestingPlaygroundURL = (element = getDocument().body) => {
|
27 |
| - if (!element || !('innerHTML' in element)) { |
28 |
| - console.log(`The element you're providing isn't a valid DOM element.`) |
29 |
| - return |
30 |
| - } |
31 |
| - if (!element.innerHTML) { |
32 |
| - console.log(`The provided element doesn't have any children.`) |
33 |
| - return |
| 13 | + const url = getPlaygroundUrl(element, console.log) |
| 14 | + if (url) { |
| 15 | + console.log(`Open this URL in your browser\n\n${url}`) |
34 | 16 | }
|
35 |
| - console.log( |
36 |
| - `Open this URL in your browser\n\n${getPlaygroundUrl(element.innerHTML)}`, |
37 |
| - ) |
38 | 17 | }
|
39 | 18 |
|
40 | 19 | const initialValue = {debug, logTestingPlaygroundURL}
|
|
0 commit comments