Skip to content

Commit 933bef2

Browse files
committed
Merge pull request #178 from plotly/129-obsolete-docs
Document discouraged elements, and fix ObjectEl data
1 parent 6c20ebc commit 933bef2

10 files changed

+231
-297
lines changed

Diff for: packages/dash-html-components/.circleci/config.yml

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
version: 2
22

33
jobs:
4+
percy-finalize:
5+
docker:
6+
- image: percyio/agent
7+
auth:
8+
username: dashautomation
9+
password: $DASH_PAT_DOCKERHUB
10+
steps:
11+
- run: percy finalize --all
12+
413
python-2.7: &test-template
514
docker:
615
- image: circleci/python:2.7-stretch-node-browsers
@@ -9,7 +18,7 @@ jobs:
918
password: $DASH_PAT_DOCKERHUB
1019
environment:
1120
PYTHON_VERSION: py27
12-
PERCY_ENABLE: 1
21+
PERCY_ENABLE: 0
1322

1423
working_directory: ~/repo
1524

@@ -76,7 +85,8 @@ jobs:
7685
password: $DASH_PAT_DOCKERHUB
7786
environment:
7887
PYTHON_VERSION: py37
79-
PERCY_ENABLE: 0
88+
PERCY_ENABLE: 1
89+
PERCY_PARALLEL_TOTAL: -1
8090

8191
workflows:
8292
version: 2
@@ -85,3 +95,6 @@ workflows:
8595
- python-2.7
8696
- python-3.6
8797
- python-3.7
98+
- percy-finalize:
99+
requires:
100+
- python-3.7

Diff for: packages/dash-html-components/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## UNRELEASED
6+
### Fixed
7+
- [#178](https://github.com/plotly/dash-html-components/pull/178) - Fix [#161](https://github.com/plotly/dash-html-components/issues/161) <object> `data` property, and fix [#129](https://github.com/plotly/dash-html-components/issues/129) obsolete, deprecated, and discouraged elements. No elements were removed, but comments were added to the documentation about these elements detailing their limitations.
8+
59
## [1.1.2] - 2021-01-19
610
### Fixed
711
- [#169](https://github.com/plotly/dash-html-components/pull/169) - part of fixing dash import bug https://github.com/plotly/dash/issues/1143

Diff for: packages/dash-html-components/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"postbuild": "es-check es5 dash_html_components/*.js",
2525
"build:watch": "watch 'npm run build' src",
2626
"test:import": "python -m unittest tests.test_dash_import",
27-
"test:py": "python -m unittest tests.test_dash_html_components tests.test_integration",
27+
"test:py": "pytest --nopercyfinalize --headless tests/test_dash_html_components.py tests/test_integration.py",
2828
"test": "run-s -c test:py test:import lint"
2929
},
3030
"author": "Chris Parmer <[email protected]>",

Diff for: packages/dash-html-components/scripts/extract-attributes.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@ const dataPath = './data/attributes.json';
1010
const htmlPath = './data/attributes.html';
1111

1212
// From https://facebook.github.io/react/docs/tags-and-attributes.html#supported-attributes
13-
// less the `data` attribute,
14-
// the special `className` and `htmlFor` props,
13+
// less the special `className` and `htmlFor` props,
1514
// and `httpEquiv` + `acceptCharset` which are already correctly camelCased.
1615
const supportedAttributes = ['accept', 'accessKey', 'action',
1716
'allowFullScreen', 'allowTransparency', 'alt', 'async', 'autoComplete',
1817
'autoFocus', 'autoPlay', 'capture', 'cellPadding', 'cellSpacing', 'challenge',
1918
'charSet', 'checked', 'cite', 'classID', 'colSpan', 'cols', 'content',
20-
'contentEditable', 'contextMenu', 'controls', 'coords', 'crossOrigin',
19+
'contentEditable', 'contextMenu', 'controls', 'coords', 'crossOrigin', 'data',
2120
'dateTime', 'default', 'defer', 'dir', 'disabled', 'download', 'draggable',
2221
'encType', 'form', 'formAction', 'formEncType', 'formMethod', 'formNoValidate',
2322
'formTarget', 'frameBorder', 'headers', 'height', 'hidden', 'high', 'href',
@@ -82,7 +81,7 @@ function extractAttributes($) {
8281
.toString();
8382

8483
// Skip `data-*` attributes
85-
if (htmlAttribute.indexOf('data') === 0) {
84+
if (htmlAttribute.indexOf('data-') === 0) {
8685
return;
8786
}
8887

Diff for: packages/dash-html-components/scripts/extract-elements.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,18 @@ function extractElements($) {
2020
'svg', 'math',
2121
// obsolete, non-standard, or deprecated tags
2222
'image', 'dir', 'tt', 'applet', 'noembed', 'bgsound', 'menu', 'menuitem',
23-
'noframes'
23+
'noframes',
24+
// experimental, don't add yet
25+
'portal'
2426
];
2527
// `<section>` is for some reason missing from the reference tables.
28+
// `<command>` and `element` are obsolete and has been removed from the
29+
// reference table, but we had them in the past so we should wait for a
30+
// major to remove
2631
const addElements = [
2732
'base',
33+
'command',
34+
'element',
2835
'section',
2936
'h1',
3037
'h2',
@@ -64,6 +71,7 @@ request(refUrl, (error, response, html) => {
6471
if (elements.length !== expectedElCount) {
6572
throw new Error(
6673
'Unexpected number of elements extracted from ' + refUrl +
74+
' - Found ' + elements.length + ' but expected ' + expectedElCount +
6775
' Check the output and edit expectedElCount if this is intended.'
6876
);
6977
}

Diff for: packages/dash-html-components/scripts/generate-components.js

+53-1
Original file line numberDiff line numberDiff line change
@@ -198,16 +198,68 @@ function generatePropTypes(element, attributes) {
198198
'setProps': PropTypes.func`
199199
}
200200

201+
const obsoleteDoc = element => `
202+
* OBSOLETE: <${element}> is included for completeness, but should be avoided
203+
* as it is not supported by any modern browsers.`;
204+
205+
const customDocs = {
206+
basefont: `
207+
* OBSOLETE: <basefont> is included for completeness, but should be avoided
208+
* as it is only supported by Internet Explorer.`,
209+
blink: obsoleteDoc('blink'),
210+
command: obsoleteDoc('command'),
211+
element: obsoleteDoc('element'),
212+
isindex: obsoleteDoc('isindex'),
213+
keygen: `
214+
* DEPRECATED: <keygen> is included for completeness, but should be avoided
215+
* as it is not supported by all browsers and may be removed at any time from
216+
* those that do support it.`,
217+
listing: obsoleteDoc('listing') + ' Use <pre> or <code> instead.',
218+
marquee: `
219+
* DEPRECATED: <marquee> is included for completeness, but should be avoided
220+
* as browsers may remove it at any time.`,
221+
meta: `
222+
* CAUTION: <meta> is included for completeness, but generally will not behave
223+
* as expected since <meta> tags should be static HTML content in the <head> of
224+
* the document. Dash components are dynamic <body> content.`,
225+
multicol: obsoleteDoc('multicol'),
226+
nextid: obsoleteDoc('nextid'),
227+
output: `
228+
* CAUTION: <output> is included for completeness, but its typical usage
229+
* requires the oninput attribute of the enclosing <form> element, which
230+
* is not accessible to Dash.`,
231+
script: `
232+
* CAUTION: <script> is included for completeness, but you cannot execute
233+
* JavaScript code by providing it to a <script> element. Use a clientside
234+
* callback for this purpose instead.`,
235+
plaintext: `
236+
* OBSOLETE: <plaintext> is included for completeness, but should be avoided
237+
* as browsers may remove it at any time, and its behavior when added
238+
* dynamically by Dash is not what it would be statically on page load.
239+
* Use <pre> or <code> instead.`,
240+
shadow: `
241+
* DEPRECATED: <shadow> is included for completeness, but should be avoided
242+
* as it is not supported by all browsers and may be removed at any time from
243+
* those that do support it.`,
244+
spacer: obsoleteDoc('spacer'),
245+
title: `
246+
* CAUTION: <title> is included for completeness, but is not expected to
247+
* do anything outside of <head>. Dash components are always created in the
248+
* <body>.`
249+
};
250+
201251
function generateComponent(Component, element, attributes) {
202252
const propTypes = generatePropTypes(element, attributes);
203253

254+
const customDoc = customDocs[element] ? ('\n *' + customDocs[element] + '\n *') : '';
255+
204256
return `
205257
import React from 'react';
206258
import PropTypes from 'prop-types';
207259
import {omit} from 'ramda';
208260
209261
/**
210-
* ${Component} is a wrapper for the <${element}> HTML5 element.
262+
* ${Component} is a wrapper for the <${element}> HTML5 element.${customDoc}
211263
* For detailed attribute info see:
212264
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/${element}
213265
*/

Diff for: packages/dash-html-components/tests/IntegrationTests.py

-87
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,48 @@
1-
import unittest
2-
import dash_html_components
3-
4-
5-
class TestDashHtmlComponents(unittest.TestCase):
6-
def test_imports(self):
7-
with open('./scripts/data/elements.txt') as f:
8-
elements = [
9-
s[0].upper() + s[1:] for s in
10-
f.read().split('\n')
11-
]
12-
elements += ['MapEl', 'ObjectEl']
13-
for s in ['Map', 'Object']:
14-
elements.remove(s)
15-
16-
print(dir(dash_html_components))
17-
18-
self.assertEqual(
19-
set([d for d in dir(dash_html_components) if d[0] != '_' and d[0] == d[0].capitalize()]),
20-
set(elements)
21-
)
22-
23-
def test_sample_items(self):
24-
Div = dash_html_components.Div
25-
Img = dash_html_components.Img
26-
27-
layout = Div(
28-
Div(
29-
Img(src='https://plotly.com/~chris/1638.png')
30-
), style={'color': 'red'}
31-
)
32-
33-
self.assertEqual(
34-
repr(layout),
35-
''.join([
36-
"Div(children=Div(Img(src='https://plotly.com/~chris/1638.png')), "
37-
"style={'color': 'red'})"
38-
])
39-
)
40-
41-
self.assertEqual(
42-
layout._namespace, 'dash_html_components'
43-
)
1+
import pytest
2+
import dash_html_components as html
3+
4+
5+
def test_imports():
6+
with open("./scripts/data/elements.txt") as f:
7+
elements = [s[0].upper() + s[1:] for s in f.read().split("\n")]
8+
elements += ["MapEl", "ObjectEl"]
9+
for s in ["Map", "Object"]:
10+
elements.remove(s)
11+
12+
dir_set = set(
13+
[
14+
d
15+
for d in dir(html)
16+
if d[0] != "_" and d[0] == d[0].capitalize()
17+
]
18+
)
19+
assert dir_set == set(elements)
20+
21+
22+
def test_sample_items():
23+
layout = html.Div(
24+
html.Div(html.Img(src="https://plotly.com/~chris/1638.png")),
25+
style={"color": "red"}
26+
)
27+
28+
expected = (
29+
"Div(children=Div(Img(src='https://plotly.com/~chris/1638.png')), "
30+
"style={'color': 'red'})"
31+
)
32+
assert repr(layout) == expected
33+
34+
assert layout._namespace == "dash_html_components"
35+
36+
37+
def test_objectEl():
38+
layout = html.ObjectEl(data="something", **{"data-x": "else"})
39+
assert repr(layout) == "ObjectEl(data='something', data-x='else')"
40+
41+
with pytest.raises(TypeError):
42+
html.ObjectEl(datax="something")
43+
44+
45+
def test_customDocs():
46+
assert "CAUTION" in html.Script.__doc__[:100]
47+
assert "OBSOLETE" in html.Blink.__doc__[:100]
48+
assert "DEPRECATED" in html.Marquee.__doc__[:100]

Diff for: packages/dash-html-components/tests/test_dash_import.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
class TestDashImport(unittest.TestCase):
66
def setUp(self):
77
with open('dash.py', 'w') as f:
8-
pass
9-
8+
pass
9+
1010
def tearDown(self):
1111
try:
1212
os.remove('dash.py')
1313
os.remove('dash.pyc')
1414
except OSError:
1515
pass
16-
16+
1717
def test_dash_import(self):
1818
"""Test that program exits if the wrong dash module was imported"""
19-
19+
2020
with self.assertRaises(SystemExit) as cm:
2121
import dash_html_components
2222

0 commit comments

Comments
 (0)