govuk_publishing_components 12.13.0 → 12.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/govuk_publishing_components/components/accessible-autocomplete.js +37 -0
  3. data/app/assets/javascripts/govuk_publishing_components/components/checkboxes.js +6 -5
  4. data/app/assets/javascripts/govuk_publishing_components/components/copy-to-clipboard.js +15 -15
  5. data/app/assets/javascripts/govuk_publishing_components/components/feedback.js +2 -4
  6. data/app/assets/javascripts/govuk_publishing_components/components/initial-focus.js +8 -8
  7. data/app/assets/javascripts/govuk_publishing_components/components/step-by-step-nav.js +3 -3
  8. data/app/assets/stylesheets/govuk_publishing_components/_all_components.scss +1 -0
  9. data/app/assets/stylesheets/govuk_publishing_components/components/_accessible-autocomplete.scss +16 -0
  10. data/app/views/govuk_publishing_components/components/_accessible_autocomplete.html.erb +24 -0
  11. data/app/views/govuk_publishing_components/components/docs/accessible_autocomplete.yml +42 -0
  12. data/config/initializers/assets.rb +1 -0
  13. data/lib/govuk_publishing_components/version.rb +1 -1
  14. data/node_modules/accessible-autocomplete/CHANGELOG.md +269 -0
  15. data/node_modules/accessible-autocomplete/CONTRIBUTING.md +150 -0
  16. data/node_modules/accessible-autocomplete/LICENSE.txt +20 -0
  17. data/node_modules/accessible-autocomplete/Procfile +1 -0
  18. data/node_modules/accessible-autocomplete/README.md +416 -0
  19. data/node_modules/accessible-autocomplete/accessibility-criteria.md +42 -0
  20. data/node_modules/accessible-autocomplete/app.json +15 -0
  21. data/node_modules/accessible-autocomplete/dist/accessible-autocomplete.min.css +1 -0
  22. data/node_modules/accessible-autocomplete/dist/accessible-autocomplete.min.js +2 -0
  23. data/node_modules/accessible-autocomplete/dist/accessible-autocomplete.min.js.map +1 -0
  24. data/node_modules/accessible-autocomplete/dist/lib/accessible-autocomplete.preact.min.js +2 -0
  25. data/node_modules/accessible-autocomplete/dist/lib/accessible-autocomplete.preact.min.js.map +1 -0
  26. data/node_modules/accessible-autocomplete/dist/lib/accessible-autocomplete.react.min.js +2 -0
  27. data/node_modules/accessible-autocomplete/dist/lib/accessible-autocomplete.react.min.js.map +1 -0
  28. data/node_modules/accessible-autocomplete/examples/form.html +671 -0
  29. data/node_modules/accessible-autocomplete/examples/index.html +616 -0
  30. data/node_modules/accessible-autocomplete/examples/preact/index.html +346 -0
  31. data/node_modules/accessible-autocomplete/examples/react/index.html +347 -0
  32. data/node_modules/accessible-autocomplete/package.json +192 -0
  33. data/node_modules/accessible-autocomplete/preact.js +1 -0
  34. data/node_modules/accessible-autocomplete/react.js +1 -0
  35. data/node_modules/accessible-autocomplete/scripts/check-staged.js +14 -0
  36. data/node_modules/accessible-autocomplete/src/autocomplete.css +141 -0
  37. data/node_modules/accessible-autocomplete/src/autocomplete.js +524 -0
  38. data/node_modules/accessible-autocomplete/src/dropdown-arrow-down.js +11 -0
  39. data/node_modules/accessible-autocomplete/src/status.js +80 -0
  40. data/node_modules/accessible-autocomplete/src/wrapper.js +60 -0
  41. data/node_modules/accessible-autocomplete/test/functional/dropdown-arrow-down.js +44 -0
  42. data/node_modules/accessible-autocomplete/test/functional/index.js +485 -0
  43. data/node_modules/accessible-autocomplete/test/functional/wrapper.js +267 -0
  44. data/node_modules/accessible-autocomplete/test/integration/index.js +188 -0
  45. data/node_modules/accessible-autocomplete/test/karma.config.js +42 -0
  46. data/node_modules/accessible-autocomplete/test/wdio.config.js +80 -0
  47. data/node_modules/accessible-autocomplete/webpack.config.babel.js +193 -0
  48. data/node_modules/preact/LICENSE +21 -0
  49. data/node_modules/preact/README.md +580 -0
  50. data/node_modules/preact/debug.js +112 -0
  51. data/node_modules/preact/debug.js.map +1 -0
  52. data/node_modules/preact/debug/index.js +121 -0
  53. data/node_modules/preact/devtools.js +403 -0
  54. data/node_modules/preact/devtools.js.map +1 -0
  55. data/node_modules/preact/devtools/devtools.js +395 -0
  56. data/node_modules/preact/devtools/index.js +4 -0
  57. data/node_modules/preact/dist/preact.d.ts +891 -0
  58. data/node_modules/preact/dist/preact.dev.js +718 -0
  59. data/node_modules/preact/dist/preact.dev.js.map +1 -0
  60. data/node_modules/preact/dist/preact.js +408 -0
  61. data/node_modules/preact/dist/preact.js.flow +13 -0
  62. data/node_modules/preact/dist/preact.js.map +1 -0
  63. data/node_modules/preact/dist/preact.min.js +2 -0
  64. data/node_modules/preact/dist/preact.min.js.map +1 -0
  65. data/node_modules/preact/dist/preact.mjs +715 -0
  66. data/node_modules/preact/dist/preact.mjs.map +1 -0
  67. data/node_modules/preact/package.json +218 -0
  68. data/node_modules/preact/src/clone-element.js +18 -0
  69. data/node_modules/preact/src/component.js +90 -0
  70. data/node_modules/preact/src/constants.js +17 -0
  71. data/node_modules/preact/src/dom/index.js +138 -0
  72. data/node_modules/preact/src/h.js +86 -0
  73. data/node_modules/preact/src/options.js +22 -0
  74. data/node_modules/preact/src/preact.d.ts +891 -0
  75. data/node_modules/preact/src/preact.js +26 -0
  76. data/node_modules/preact/src/preact.js.flow +13 -0
  77. data/node_modules/preact/src/render-queue.js +28 -0
  78. data/node_modules/preact/src/render.js +22 -0
  79. data/node_modules/preact/src/util.js +19 -0
  80. data/node_modules/preact/src/vdom/component-recycler.js +48 -0
  81. data/node_modules/preact/src/vdom/component.js +296 -0
  82. data/node_modules/preact/src/vdom/diff.js +336 -0
  83. data/node_modules/preact/src/vdom/index.js +54 -0
  84. data/node_modules/preact/src/vnode.js +9 -0
  85. data/node_modules/preact/typings.json +5 -0
  86. metadata +78 -2
@@ -0,0 +1,112 @@
1
+ 'use strict';
2
+
3
+ /* eslint-disable no-console */
4
+
5
+ if (process.env.NODE_ENV === 'development') {
6
+ var preact = require('preact');
7
+ var options = preact.options;
8
+ var oldVnodeOption = options.vnode;
9
+
10
+ options.vnode = function (vnode) {
11
+ var nodeName = vnode.nodeName,
12
+ attributes = vnode.attributes,
13
+ children = vnode.children;
14
+
15
+
16
+ if (nodeName === void 0) {
17
+ console.error('Undefined component passed to preact.h()\n' + serializeVNode(vnode));
18
+ }
19
+
20
+ if (attributes && attributes.ref !== void 0 && typeof attributes.ref !== 'function' && !('$$typeof' in vnode) // allow string refs when preact-compat is installed
21
+ ) {
22
+ throw new Error('Component\'s "ref" property should be a function,' + (' but [' + typeof attributes.ref + '] passed\n') + serializeVNode(vnode));
23
+ }
24
+
25
+ {
26
+ var keys = {};
27
+
28
+ inspectChildren(children, function (deepChild) {
29
+ if (!deepChild || deepChild.key == null) return;
30
+
31
+ // In Preact, all keys are stored as object values, i.e. being strings
32
+ var key = deepChild.key + '';
33
+
34
+ if (keys.hasOwnProperty(key)) {
35
+ console.error('Following component has two or more children with the ' + 'same "key" attribute. This may cause glitches and misbehavior ' + 'in rendering process. Component: \n\n' + serializeVNode(vnode));
36
+
37
+ // Return early to not spam the console
38
+ return true;
39
+ }
40
+
41
+ keys[key] = true;
42
+ });
43
+ }
44
+
45
+ if (oldVnodeOption) oldVnodeOption.call(this, vnode);
46
+ };
47
+
48
+ try {
49
+ var oldRender = preact.render;
50
+ preact.render = function (vnode, parent, merge) {
51
+ if (parent == null && merge == null) {
52
+ // render(vnode, parent, merge) can't have both parent and merge be undefined
53
+ console.error('The "containerNode" or "replaceNode" is not defined in the render method. ' + 'Component: \n\n' + serializeVNode(vnode));
54
+ } else if (parent == merge) {
55
+ // if parent == merge, it doesn't reason well and would cause trouble when preact
56
+ // tries to update or replace that 'replaceNode' element
57
+ console.error('The "containerNode" and "replaceNode" are the same in render method, ' + 'when the "replaceNode" DOM node is expected to be a child of "containerNode". ' + 'docs-ref: https://preactjs.com/guide/api-reference#-preact-render-. Component: \n\n' + serializeVNode(vnode));
58
+ }
59
+ return oldRender(vnode, parent, merge);
60
+ };
61
+ } catch (e) {}
62
+
63
+ var inspectChildren = function inspectChildren(children, inspect) {
64
+ if (!Array.isArray(children)) {
65
+ children = [children];
66
+ }
67
+ return children.some(function (child, i) {
68
+ if (Array.isArray(child)) {
69
+ return inspectChildren(child, inspect);
70
+ }
71
+
72
+ return inspect(child, i);
73
+ });
74
+ };
75
+
76
+ var serializeVNode = function serializeVNode(_ref) {
77
+ var nodeName = _ref.nodeName,
78
+ attributes = _ref.attributes,
79
+ children = _ref.children;
80
+
81
+ if (typeof nodeName === 'function') {
82
+ nodeName = nodeName.name || nodeName.displayName;
83
+ }
84
+
85
+ var props = '';
86
+ if (attributes) {
87
+ for (var attr in attributes) {
88
+ if (attributes.hasOwnProperty(attr) && attr !== 'children') {
89
+ var value = attributes[attr];
90
+
91
+ // If it is an object but doesn't have toString(), use Object.toString
92
+ if (typeof value === 'function') {
93
+ value = 'function ' + (value.displayName || value.name) + '() {}';
94
+ }
95
+ if (Object(value) === value && !value.toString) {
96
+ value = Object.prototype.toString.call(value);
97
+ } else {
98
+ value = value + '';
99
+ }
100
+
101
+ props += ' ' + attr + '=' + JSON.stringify(value);
102
+ }
103
+ }
104
+ }
105
+
106
+ return '<' + nodeName + props + (children && children.length ? '>..</' + nodeName + '>' : ' />');
107
+ };
108
+
109
+ require('preact/devtools');
110
+ }
111
+
112
+ //# sourceMappingURL=debug.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["debug/index.js"],"names":[],"mappings":";;AAAA;;AAEA,IAAI,QAAQ,GAAR,CAAY,QAAZ,KAAyB,aAA7B,EAA4C;AAC3C,KAAM,SAAS,QAAQ,QAAR,CAAf;AACA,KAAM,UAAU,OAAO,OAAvB;AACA,KAAM,iBAAiB,QAAQ,KAA/B;;AAEA,SAAQ,KAAR,GAAgB,UAAS,KAAT,EAAgB;AAAA,MACvB,QADuB,GACY,KADZ,CACvB,QADuB;AAAA,MACb,UADa,GACY,KADZ,CACb,UADa;AAAA,MACD,QADC,GACY,KADZ,CACD,QADC;;;AAG/B,MAAI,aAAa,KAAK,CAAtB,EAAyB;AACxB,WAAQ,KAAR,CAAc,+CAA6C,eAAe,KAAf,CAA3D;AACA;;AAED,MACC,cAAc,WAAW,GAAX,KAAmB,KAAK,CAAtC,IACA,OAAO,WAAW,GAAlB,KAA0B,UAD1B,IAEA,EAAE,cAAc,KAAhB,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\n\nif (process.env.NODE_ENV === 'development') {\n\tconst preact = require('preact');\n\tconst options = preact.options;\n\tconst oldVnodeOption = options.vnode;\n\n\toptions.vnode = function(vnode) {\n\t\tconst { nodeName, attributes, children } = vnode;\n\n\t\tif (nodeName === void 0) {\n\t\t\tconsole.error('Undefined component passed to preact.h()\\n'+serializeVNode(vnode));\n\t\t}\n\n\t\tif (\n\t\t\tattributes && attributes.ref !== void 0 &&\n\t\t\ttypeof attributes.ref !== 'function' &&\n\t\t\t!('$$typeof' in vnode) // allow string refs when preact-compat is installed\n\t\t) {\n\t\t\tthrow new Error(\n\t\t\t\t`Component's \"ref\" property should be a function,` +\n\t\t\t\t` but [${typeof attributes.ref}] passed\\n` + serializeVNode(vnode)\n\t\t\t);\n\t\t}\n\n\t\t{\n\t\t\tconst keys = {};\n\n\t\t\tinspectChildren(children, (deepChild) => {\n\t\t\t\tif (!deepChild || deepChild.key==null) return;\n\n\t\t\t\t// In Preact, all keys are stored as object values, i.e. being strings\n\t\t\t\tconst key = deepChild.key + '';\n\n\t\t\t\tif (keys.hasOwnProperty(key)) {\n\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t'Following component has two or more children with the ' +\n\t\t\t\t\t\t'same \"key\" attribute. This may cause glitches and misbehavior ' +\n\t\t\t\t\t\t'in rendering process. Component: \\n\\n' +\n\t\t\t\t\t\tserializeVNode(vnode)\n\t\t\t\t\t);\n\n\t\t\t\t\t// Return early to not spam the console\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\n\t\t\t\tkeys[key] = true;\n\t\t\t});\n\t\t}\n\n\t\tif (oldVnodeOption) oldVnodeOption.call(this, vnode);\n\t};\n\n\ttry {\n\t\tconst oldRender = preact.render;\n\t\tpreact.render = function (vnode, parent, merge) {\n\t\t\tif (parent == null && merge == null) {\n\t\t\t\t// render(vnode, parent, merge) can't have both parent and merge be undefined\n\t\t\t\tconsole.error('The \"containerNode\" or \"replaceNode\" is not defined in the render method. ' +\n\t\t\t\t\t'Component: \\n\\n' + serializeVNode(vnode));\n\t\t\t}\n\t\t\telse if (parent == merge) {\n\t\t\t\t// if parent == merge, it doesn't reason well and would cause trouble when preact\n\t\t\t\t// tries to update or replace that 'replaceNode' element\n\t\t\t\tconsole.error(\n\t\t\t\t\t'The \"containerNode\" and \"replaceNode\" are the same in render method, ' +\n\t\t\t\t\t'when the \"replaceNode\" DOM node is expected to be a child of \"containerNode\". ' +\n\t\t\t\t\t'docs-ref: https://preactjs.com/guide/api-reference#-preact-render-. Component: \\n\\n' +\n\t\t\t\t\tserializeVNode(vnode)\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn oldRender(vnode, parent, merge);\n\t\t};\n\t}\n\tcatch (e) {}\n\n\tconst inspectChildren = (children, inspect) => {\n\t\tif (!Array.isArray(children)) {\n\t\t\tchildren = [children];\n\t\t}\n\t\treturn children.some((child, i) => {\n\t\t\tif (Array.isArray(child)) {\n\t\t\t\treturn inspectChildren(child, inspect);\n\t\t\t}\n\n\t\t\treturn inspect(child, i);\n\t\t});\n\t};\n\n\tconst serializeVNode = ({ nodeName, attributes, children }) => {\n\t\tif (typeof nodeName==='function') {\n\t\t\tnodeName = nodeName.name || nodeName.displayName;\n\t\t}\n\n\t\tlet props = '';\n\t\tif (attributes) {\n\t\t\tfor (let attr in attributes) {\n\t\t\t\tif (attributes.hasOwnProperty(attr) && attr!=='children') {\n\t\t\t\t\tlet value = attributes[attr];\n\n\t\t\t\t\t// If it is an object but doesn't have toString(), use Object.toString\n\t\t\t\t\tif (typeof value==='function') {\n\t\t\t\t\t\tvalue = `function ${value.displayName || value.name}() {}`;\n\t\t\t\t\t}\n\t\t\t\t\tif (Object(value) === value && !value.toString) {\n\t\t\t\t\t\tvalue = Object.prototype.toString.call(value);\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tvalue = value + '';\n\t\t\t\t\t}\n\n\t\t\t\t\tprops += ` ${attr}=${JSON.stringify(value)}`;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn `<${nodeName}${props}${children && children.length ? ('>..</'+nodeName+'>') : ' />'}`;\n\t};\n\n\trequire('preact/devtools');\n}\n"]}
@@ -0,0 +1,121 @@
1
+ /* eslint-disable no-console */
2
+
3
+ if (process.env.NODE_ENV === 'development') {
4
+ const preact = require('preact');
5
+ const options = preact.options;
6
+ const oldVnodeOption = options.vnode;
7
+
8
+ options.vnode = function(vnode) {
9
+ const { nodeName, attributes, children } = vnode;
10
+
11
+ if (nodeName === void 0) {
12
+ console.error('Undefined component passed to preact.h()\n'+serializeVNode(vnode));
13
+ }
14
+
15
+ if (
16
+ attributes && attributes.ref !== void 0 &&
17
+ typeof attributes.ref !== 'function' &&
18
+ !('$$typeof' in vnode) // allow string refs when preact-compat is installed
19
+ ) {
20
+ throw new Error(
21
+ `Component's "ref" property should be a function,` +
22
+ ` but [${typeof attributes.ref}] passed\n` + serializeVNode(vnode)
23
+ );
24
+ }
25
+
26
+ {
27
+ const keys = {};
28
+
29
+ inspectChildren(children, (deepChild) => {
30
+ if (!deepChild || deepChild.key==null) return;
31
+
32
+ // In Preact, all keys are stored as object values, i.e. being strings
33
+ const key = deepChild.key + '';
34
+
35
+ if (keys.hasOwnProperty(key)) {
36
+ console.error(
37
+ 'Following component has two or more children with the ' +
38
+ 'same "key" attribute. This may cause glitches and misbehavior ' +
39
+ 'in rendering process. Component: \n\n' +
40
+ serializeVNode(vnode)
41
+ );
42
+
43
+ // Return early to not spam the console
44
+ return true;
45
+ }
46
+
47
+ keys[key] = true;
48
+ });
49
+ }
50
+
51
+ if (oldVnodeOption) oldVnodeOption.call(this, vnode);
52
+ };
53
+
54
+ try {
55
+ const oldRender = preact.render;
56
+ preact.render = function (vnode, parent, merge) {
57
+ if (parent == null && merge == null) {
58
+ // render(vnode, parent, merge) can't have both parent and merge be undefined
59
+ console.error('The "containerNode" or "replaceNode" is not defined in the render method. ' +
60
+ 'Component: \n\n' + serializeVNode(vnode));
61
+ }
62
+ else if (parent == merge) {
63
+ // if parent == merge, it doesn't reason well and would cause trouble when preact
64
+ // tries to update or replace that 'replaceNode' element
65
+ console.error(
66
+ 'The "containerNode" and "replaceNode" are the same in render method, ' +
67
+ 'when the "replaceNode" DOM node is expected to be a child of "containerNode". ' +
68
+ 'docs-ref: https://preactjs.com/guide/api-reference#-preact-render-. Component: \n\n' +
69
+ serializeVNode(vnode)
70
+ );
71
+ }
72
+ return oldRender(vnode, parent, merge);
73
+ };
74
+ }
75
+ catch (e) {}
76
+
77
+ const inspectChildren = (children, inspect) => {
78
+ if (!Array.isArray(children)) {
79
+ children = [children];
80
+ }
81
+ return children.some((child, i) => {
82
+ if (Array.isArray(child)) {
83
+ return inspectChildren(child, inspect);
84
+ }
85
+
86
+ return inspect(child, i);
87
+ });
88
+ };
89
+
90
+ const serializeVNode = ({ nodeName, attributes, children }) => {
91
+ if (typeof nodeName==='function') {
92
+ nodeName = nodeName.name || nodeName.displayName;
93
+ }
94
+
95
+ let props = '';
96
+ if (attributes) {
97
+ for (let attr in attributes) {
98
+ if (attributes.hasOwnProperty(attr) && attr!=='children') {
99
+ let value = attributes[attr];
100
+
101
+ // If it is an object but doesn't have toString(), use Object.toString
102
+ if (typeof value==='function') {
103
+ value = `function ${value.displayName || value.name}() {}`;
104
+ }
105
+ if (Object(value) === value && !value.toString) {
106
+ value = Object.prototype.toString.call(value);
107
+ }
108
+ else {
109
+ value = value + '';
110
+ }
111
+
112
+ props += ` ${attr}=${JSON.stringify(value)}`;
113
+ }
114
+ }
115
+ }
116
+
117
+ return `<${nodeName}${props}${children && children.length ? ('>..</'+nodeName+'>') : ' />'}`;
118
+ };
119
+
120
+ require('preact/devtools');
121
+ }
@@ -0,0 +1,403 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('preact')) :
3
+ typeof define === 'function' && define.amd ? define(['preact'], factory) :
4
+ (factory(global.preact));
5
+ }(this, (function (preact) { 'use strict';
6
+
7
+ // render modes
8
+
9
+ var ATTR_KEY = '__preactattr_';
10
+
11
+ /* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
12
+
13
+ /**
14
+ * Return a ReactElement-compatible object for the current state of a preact
15
+ * component.
16
+ */
17
+ function createReactElement(component) {
18
+ return {
19
+ type: component.constructor,
20
+ key: component.key,
21
+ ref: null, // Unsupported
22
+ props: component.props
23
+ };
24
+ }
25
+
26
+ /**
27
+ * Create a ReactDOMComponent-compatible object for a given DOM node rendered
28
+ * by preact.
29
+ *
30
+ * This implements the subset of the ReactDOMComponent interface that
31
+ * React DevTools requires in order to display DOM nodes in the inspector with
32
+ * the correct type and properties.
33
+ *
34
+ * @param {Node} node
35
+ */
36
+ function createReactDOMComponent(node) {
37
+ var childNodes = node.nodeType === Node.ELEMENT_NODE ? Array.from(node.childNodes) : [];
38
+
39
+ var isText = node.nodeType === Node.TEXT_NODE;
40
+
41
+ return {
42
+ // --- ReactDOMComponent interface
43
+ _currentElement: isText ? node.textContent : {
44
+ type: node.nodeName.toLowerCase(),
45
+ props: node[ATTR_KEY]
46
+ },
47
+ _renderedChildren: childNodes.map(function (child) {
48
+ if (child._component) {
49
+ return updateReactComponent(child._component);
50
+ }
51
+ return updateReactComponent(child);
52
+ }),
53
+ _stringText: isText ? node.textContent : null,
54
+
55
+ // --- Additional properties used by preact devtools
56
+
57
+ // A flag indicating whether the devtools have been notified about the
58
+ // existence of this component instance yet.
59
+ // This is used to send the appropriate notifications when DOM components
60
+ // are added or updated between composite component updates.
61
+ _inDevTools: false,
62
+ node: node
63
+ };
64
+ }
65
+
66
+ /**
67
+ * Return the name of a component created by a `ReactElement`-like object.
68
+ *
69
+ * @param {ReactElement} element
70
+ */
71
+ function typeName(element) {
72
+ if (typeof element.type === 'function') {
73
+ return element.type.displayName || element.type.name;
74
+ }
75
+ return element.type;
76
+ }
77
+
78
+ /**
79
+ * Return a ReactCompositeComponent-compatible object for a given preact
80
+ * component instance.
81
+ *
82
+ * This implements the subset of the ReactCompositeComponent interface that
83
+ * the DevTools requires in order to walk the component tree and inspect the
84
+ * component's properties.
85
+ *
86
+ * See https://github.com/facebook/react-devtools/blob/e31ec5825342eda570acfc9bcb43a44258fceb28/backend/getData.js
87
+ */
88
+ function createReactCompositeComponent(component) {
89
+ var _currentElement = createReactElement(component);
90
+ var node = component.base;
91
+
92
+ var instance = {
93
+ // --- ReactDOMComponent properties
94
+ getName: function getName() {
95
+ return typeName(_currentElement);
96
+ },
97
+
98
+ _currentElement: createReactElement(component),
99
+ props: component.props,
100
+ state: component.state,
101
+ forceUpdate: component.forceUpdate && component.forceUpdate.bind(component),
102
+ setState: component.setState && component.setState.bind(component),
103
+
104
+ // --- Additional properties used by preact devtools
105
+ node: node
106
+ };
107
+
108
+ // React DevTools exposes the `_instance` field of the selected item in the
109
+ // component tree as `$r` in the console. `_instance` must refer to a
110
+ // React Component (or compatible) class instance with `props` and `state`
111
+ // fields and `setState()`, `forceUpdate()` methods.
112
+ instance._instance = component;
113
+
114
+ // If the root node returned by this component instance's render function
115
+ // was itself a composite component, there will be a `_component` property
116
+ // containing the child component instance.
117
+ if (component._component) {
118
+ instance._renderedComponent = updateReactComponent(component._component);
119
+ } else {
120
+ // Otherwise, if the render() function returned an HTML/SVG element,
121
+ // create a ReactDOMComponent-like object for the DOM node itself.
122
+ instance._renderedComponent = updateReactComponent(node);
123
+ }
124
+
125
+ return instance;
126
+ }
127
+
128
+ /**
129
+ * Map of Component|Node to ReactDOMComponent|ReactCompositeComponent-like
130
+ * object.
131
+ *
132
+ * The same React*Component instance must be used when notifying devtools
133
+ * about the initial mount of a component and subsequent updates.
134
+ */
135
+ var instanceMap = typeof Map === 'function' && new Map();
136
+
137
+ /**
138
+ * Update (and create if necessary) the ReactDOMComponent|ReactCompositeComponent-like
139
+ * instance for a given preact component instance or DOM Node.
140
+ *
141
+ * @param {Component|Node} componentOrNode
142
+ */
143
+ function updateReactComponent(componentOrNode) {
144
+ var newInstance = componentOrNode instanceof Node ? createReactDOMComponent(componentOrNode) : createReactCompositeComponent(componentOrNode);
145
+ if (instanceMap.has(componentOrNode)) {
146
+ var inst = instanceMap.get(componentOrNode);
147
+ Object.assign(inst, newInstance);
148
+ return inst;
149
+ }
150
+ instanceMap.set(componentOrNode, newInstance);
151
+ return newInstance;
152
+ }
153
+
154
+ function nextRootKey(roots) {
155
+ return '.' + Object.keys(roots).length;
156
+ }
157
+
158
+ /**
159
+ * Find all root component instances rendered by preact in `node`'s children
160
+ * and add them to the `roots` map.
161
+ *
162
+ * @param {DOMElement} node
163
+ * @param {[key: string] => ReactDOMComponent|ReactCompositeComponent}
164
+ */
165
+ function findRoots(node, roots) {
166
+ Array.from(node.childNodes).forEach(function (child) {
167
+ if (child._component) {
168
+ roots[nextRootKey(roots)] = updateReactComponent(child._component);
169
+ } else {
170
+ findRoots(child, roots);
171
+ }
172
+ });
173
+ }
174
+
175
+ /**
176
+ * Create a bridge for exposing preact's component tree to React DevTools.
177
+ *
178
+ * It creates implementations of the interfaces that ReactDOM passes to
179
+ * devtools to enable it to query the component tree and hook into component
180
+ * updates.
181
+ *
182
+ * See https://github.com/facebook/react/blob/59ff7749eda0cd858d5ee568315bcba1be75a1ca/src/renderers/dom/ReactDOM.js
183
+ * for how ReactDOM exports its internals for use by the devtools and
184
+ * the `attachRenderer()` function in
185
+ * https://github.com/facebook/react-devtools/blob/e31ec5825342eda570acfc9bcb43a44258fceb28/backend/attachRenderer.js
186
+ * for how the devtools consumes the resulting objects.
187
+ */
188
+ function createDevToolsBridge() {
189
+ // The devtools has different paths for interacting with the renderers from
190
+ // React Native, legacy React DOM and current React DOM.
191
+ //
192
+ // Here we emulate the interface for the current React DOM (v15+) lib.
193
+
194
+ // ReactDOMComponentTree-like object
195
+ var ComponentTree = {
196
+ getNodeFromInstance: function getNodeFromInstance(instance) {
197
+ return instance.node;
198
+ },
199
+ getClosestInstanceFromNode: function getClosestInstanceFromNode(node) {
200
+ while (node && !node._component) {
201
+ node = node.parentNode;
202
+ }
203
+ return node ? updateReactComponent(node._component) : null;
204
+ }
205
+ };
206
+
207
+ // Map of root ID (the ID is unimportant) to component instance.
208
+ var roots = {};
209
+ findRoots(document.body, roots);
210
+
211
+ // ReactMount-like object
212
+ //
213
+ // Used by devtools to discover the list of root component instances and get
214
+ // notified when new root components are rendered.
215
+ var Mount = {
216
+ _instancesByReactRootID: roots,
217
+
218
+ // Stub - React DevTools expects to find this method and replace it
219
+ // with a wrapper in order to observe new root components being added
220
+ _renderNewRootComponent: function _renderNewRootComponent() /* instance, ... */{}
221
+ };
222
+
223
+ // ReactReconciler-like object
224
+ var Reconciler = {
225
+ // Stubs - React DevTools expects to find these methods and replace them
226
+ // with wrappers in order to observe components being mounted, updated and
227
+ // unmounted
228
+ mountComponent: function mountComponent() /* instance, ... */{},
229
+ performUpdateIfNecessary: function performUpdateIfNecessary() /* instance, ... */{},
230
+ receiveComponent: function receiveComponent() /* instance, ... */{},
231
+ unmountComponent: function unmountComponent() /* instance, ... */{}
232
+ };
233
+
234
+ /** Notify devtools that a new component instance has been mounted into the DOM. */
235
+ var componentAdded = function componentAdded(component) {
236
+ var instance = updateReactComponent(component);
237
+ if (isRootComponent(component)) {
238
+ instance._rootID = nextRootKey(roots);
239
+ roots[instance._rootID] = instance;
240
+ Mount._renderNewRootComponent(instance);
241
+ }
242
+ visitNonCompositeChildren(instance, function (childInst) {
243
+ childInst._inDevTools = true;
244
+ Reconciler.mountComponent(childInst);
245
+ });
246
+ Reconciler.mountComponent(instance);
247
+ };
248
+
249
+ /** Notify devtools that a component has been updated with new props/state. */
250
+ var componentUpdated = function componentUpdated(component) {
251
+ var prevRenderedChildren = [];
252
+ var instance = instanceMap.get(component);
253
+ if (instance) {
254
+ visitNonCompositeChildren(instance, function (childInst) {
255
+ prevRenderedChildren.push(childInst);
256
+ });
257
+ }
258
+ // Notify devtools about updates to this component and any non-composite
259
+ // children
260
+ instance = updateReactComponent(component);
261
+
262
+ Reconciler.receiveComponent(instance);
263
+ visitNonCompositeChildren(instance, function (childInst) {
264
+ if (!childInst._inDevTools) {
265
+ // New DOM child component
266
+ childInst._inDevTools = true;
267
+ Reconciler.mountComponent(childInst);
268
+ } else {
269
+ // Updated DOM child component
270
+ Reconciler.receiveComponent(childInst);
271
+ }
272
+ });
273
+
274
+ // For any non-composite children that were removed by the latest render,
275
+ // remove the corresponding ReactDOMComponent-like instances and notify
276
+ // the devtools
277
+ prevRenderedChildren.forEach(function (childInst) {
278
+ if (!document.body.contains(childInst.node)) {
279
+ instanceMap.delete(childInst.node);
280
+ Reconciler.unmountComponent(childInst);
281
+ }
282
+ });
283
+ };
284
+
285
+ /** Notify devtools that a component has been unmounted from the DOM. */
286
+ var componentRemoved = function componentRemoved(component) {
287
+ var instance = updateReactComponent(component);
288
+ visitNonCompositeChildren(function (childInst) {
289
+ instanceMap.delete(childInst.node);
290
+ Reconciler.unmountComponent(childInst);
291
+ });
292
+ Reconciler.unmountComponent(instance);
293
+ instanceMap.delete(component);
294
+ if (instance._rootID) {
295
+ delete roots[instance._rootID];
296
+ }
297
+ };
298
+
299
+ return {
300
+ componentAdded: componentAdded,
301
+ componentUpdated: componentUpdated,
302
+ componentRemoved: componentRemoved,
303
+
304
+ // Interfaces passed to devtools via __REACT_DEVTOOLS_GLOBAL_HOOK__.inject()
305
+ ComponentTree: ComponentTree,
306
+ Mount: Mount,
307
+ Reconciler: Reconciler
308
+ };
309
+ }
310
+
311
+ /**
312
+ * Return `true` if a preact component is a top level component rendered by
313
+ * `render()` into a container Element.
314
+ */
315
+ function isRootComponent(component) {
316
+ // `_parentComponent` is actually `__u` after minification
317
+ if (component._parentComponent || component.__u) {
318
+ // Component with a composite parent
319
+ return false;
320
+ }
321
+ if (component.base.parentElement && component.base.parentElement[ATTR_KEY]) {
322
+ // Component with a parent DOM element rendered by Preact
323
+ return false;
324
+ }
325
+ return true;
326
+ }
327
+
328
+ /**
329
+ * Visit all child instances of a ReactCompositeComponent-like object that are
330
+ * not composite components (ie. they represent DOM elements or text)
331
+ *
332
+ * @param {Component} component
333
+ * @param {(Component) => void} visitor
334
+ */
335
+ function visitNonCompositeChildren(component, visitor) {
336
+ if (!component) return;
337
+ if (component._renderedComponent) {
338
+ if (!component._renderedComponent._component) {
339
+ visitor(component._renderedComponent);
340
+ visitNonCompositeChildren(component._renderedComponent, visitor);
341
+ }
342
+ } else if (component._renderedChildren) {
343
+ component._renderedChildren.forEach(function (child) {
344
+ visitor(child);
345
+ if (!child._component) visitNonCompositeChildren(child, visitor);
346
+ });
347
+ }
348
+ }
349
+
350
+ /**
351
+ * Create a bridge between the preact component tree and React's dev tools
352
+ * and register it.
353
+ *
354
+ * After this function is called, the React Dev Tools should be able to detect
355
+ * "React" on the page and show the component tree.
356
+ *
357
+ * This function hooks into preact VNode creation in order to expose functional
358
+ * components correctly, so it should be called before the root component(s)
359
+ * are rendered.
360
+ *
361
+ * Returns a cleanup function which unregisters the hooks.
362
+ */
363
+ function initDevTools() {
364
+ if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ === 'undefined') {
365
+ // React DevTools are not installed
366
+ return;
367
+ }
368
+
369
+ // Notify devtools when preact components are mounted, updated or unmounted
370
+ var bridge = createDevToolsBridge();
371
+
372
+ var nextAfterMount = preact.options.afterMount;
373
+ preact.options.afterMount = function (component) {
374
+ bridge.componentAdded(component);
375
+ if (nextAfterMount) nextAfterMount(component);
376
+ };
377
+
378
+ var nextAfterUpdate = preact.options.afterUpdate;
379
+ preact.options.afterUpdate = function (component) {
380
+ bridge.componentUpdated(component);
381
+ if (nextAfterUpdate) nextAfterUpdate(component);
382
+ };
383
+
384
+ var nextBeforeUnmount = preact.options.beforeUnmount;
385
+ preact.options.beforeUnmount = function (component) {
386
+ bridge.componentRemoved(component);
387
+ if (nextBeforeUnmount) nextBeforeUnmount(component);
388
+ };
389
+
390
+ // Notify devtools about this instance of "React"
391
+ __REACT_DEVTOOLS_GLOBAL_HOOK__.inject(bridge);
392
+
393
+ return function () {
394
+ preact.options.afterMount = nextAfterMount;
395
+ preact.options.afterUpdate = nextAfterUpdate;
396
+ preact.options.beforeUnmount = nextBeforeUnmount;
397
+ };
398
+ }
399
+
400
+ initDevTools();
401
+
402
+ })));
403
+ //# sourceMappingURL=devtools.js.map