@bpmn-io/properties-panel 0.8.0 → 0.10.1

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.
Files changed (177) hide show
  1. package/CHANGELOG.md +112 -85
  2. package/LICENSE +20 -20
  3. package/README.md +34 -34
  4. package/assets/properties-panel.css +891 -848
  5. package/dist/index.esm.js +1609 -0
  6. package/dist/index.esm.js.map +1 -0
  7. package/dist/index.js +1650 -0
  8. package/dist/index.js.map +1 -0
  9. package/package.json +87 -78
  10. package/preact/LICENSE +21 -0
  11. package/preact/README.md +185 -0
  12. package/preact/compat/dist/compat.js +2 -0
  13. package/preact/compat/dist/compat.js.map +1 -0
  14. package/preact/compat/dist/compat.mjs +2 -0
  15. package/preact/compat/dist/compat.module.js +2 -0
  16. package/preact/compat/dist/compat.module.js.map +1 -0
  17. package/preact/compat/dist/compat.umd.js +2 -0
  18. package/preact/compat/dist/compat.umd.js.map +1 -0
  19. package/preact/compat/jsx-dev-runtime.js +1 -0
  20. package/preact/compat/jsx-dev-runtime.mjs +1 -0
  21. package/preact/compat/jsx-runtime.js +1 -0
  22. package/preact/compat/jsx-runtime.mjs +1 -0
  23. package/preact/compat/package.json +19 -0
  24. package/preact/compat/server.js +15 -0
  25. package/preact/compat/server.mjs +4 -0
  26. package/preact/compat/src/Children.js +21 -0
  27. package/preact/compat/src/PureComponent.js +15 -0
  28. package/preact/compat/src/forwardRef.js +51 -0
  29. package/preact/compat/src/index.d.ts +140 -0
  30. package/preact/compat/src/index.js +175 -0
  31. package/preact/compat/src/internal.d.ts +47 -0
  32. package/preact/compat/src/memo.js +34 -0
  33. package/preact/compat/src/portals.js +80 -0
  34. package/preact/compat/src/render.js +219 -0
  35. package/preact/compat/src/scheduler.js +24 -0
  36. package/preact/compat/src/suspense-list.d.ts +14 -0
  37. package/preact/compat/src/suspense-list.js +126 -0
  38. package/preact/compat/src/suspense.d.ts +15 -0
  39. package/preact/compat/src/suspense.js +270 -0
  40. package/preact/compat/src/util.js +28 -0
  41. package/preact/compat/test-utils.js +1 -0
  42. package/preact/debug/dist/debug.js +2 -0
  43. package/preact/debug/dist/debug.js.map +1 -0
  44. package/preact/debug/dist/debug.mjs +2 -0
  45. package/preact/debug/dist/debug.module.js +2 -0
  46. package/preact/debug/dist/debug.module.js.map +1 -0
  47. package/preact/debug/dist/debug.umd.js +2 -0
  48. package/preact/debug/dist/debug.umd.js.map +1 -0
  49. package/preact/debug/package.json +18 -0
  50. package/preact/debug/src/check-props.js +54 -0
  51. package/preact/debug/src/component-stack.js +146 -0
  52. package/preact/debug/src/constants.js +3 -0
  53. package/preact/debug/src/debug.js +442 -0
  54. package/preact/debug/src/index.js +6 -0
  55. package/preact/debug/src/internal.d.ts +82 -0
  56. package/preact/debug/src/util.js +11 -0
  57. package/preact/devtools/dist/devtools.js +2 -0
  58. package/preact/devtools/dist/devtools.js.map +1 -0
  59. package/preact/devtools/dist/devtools.mjs +2 -0
  60. package/preact/devtools/dist/devtools.module.js +2 -0
  61. package/preact/devtools/dist/devtools.module.js.map +1 -0
  62. package/preact/devtools/dist/devtools.umd.js +2 -0
  63. package/preact/devtools/dist/devtools.umd.js.map +1 -0
  64. package/preact/devtools/package.json +16 -0
  65. package/preact/devtools/src/devtools.js +10 -0
  66. package/preact/devtools/src/index.d.ts +8 -0
  67. package/preact/devtools/src/index.js +15 -0
  68. package/preact/dist/preact.js +2 -0
  69. package/preact/dist/preact.js.map +1 -0
  70. package/preact/dist/preact.min.js +2 -0
  71. package/preact/dist/preact.min.js.map +1 -0
  72. package/preact/dist/preact.mjs +2 -0
  73. package/preact/dist/preact.module.js +2 -0
  74. package/preact/dist/preact.module.js.map +1 -0
  75. package/preact/dist/preact.umd.js +2 -0
  76. package/preact/dist/preact.umd.js.map +1 -0
  77. package/preact/hooks/dist/hooks.js +2 -0
  78. package/preact/hooks/dist/hooks.js.map +1 -0
  79. package/preact/hooks/dist/hooks.mjs +2 -0
  80. package/preact/hooks/dist/hooks.module.js +2 -0
  81. package/preact/hooks/dist/hooks.module.js.map +1 -0
  82. package/preact/hooks/dist/hooks.umd.js +2 -0
  83. package/preact/hooks/dist/hooks.umd.js.map +1 -0
  84. package/preact/hooks/package.json +26 -0
  85. package/preact/hooks/src/index.d.ts +130 -0
  86. package/preact/hooks/src/index.js +386 -0
  87. package/preact/hooks/src/internal.d.ts +75 -0
  88. package/preact/jsx-runtime/dist/jsxRuntime.js +2 -0
  89. package/preact/jsx-runtime/dist/jsxRuntime.js.map +1 -0
  90. package/preact/jsx-runtime/dist/jsxRuntime.mjs +2 -0
  91. package/preact/jsx-runtime/dist/jsxRuntime.module.js +2 -0
  92. package/preact/jsx-runtime/dist/jsxRuntime.module.js.map +1 -0
  93. package/preact/jsx-runtime/dist/jsxRuntime.umd.js +2 -0
  94. package/preact/jsx-runtime/dist/jsxRuntime.umd.js.map +1 -0
  95. package/preact/jsx-runtime/package.json +19 -0
  96. package/preact/jsx-runtime/src/index.d.ts +50 -0
  97. package/preact/jsx-runtime/src/index.js +72 -0
  98. package/preact/package.json +268 -0
  99. package/preact/src/cjs.js +3 -0
  100. package/preact/src/clone-element.js +39 -0
  101. package/preact/src/component.js +225 -0
  102. package/preact/src/constants.js +3 -0
  103. package/preact/src/create-context.js +68 -0
  104. package/preact/src/create-element.js +100 -0
  105. package/preact/src/diff/catch-error.js +38 -0
  106. package/preact/src/diff/children.js +347 -0
  107. package/preact/src/diff/index.js +516 -0
  108. package/preact/src/diff/props.js +158 -0
  109. package/preact/src/index.d.ts +310 -0
  110. package/preact/src/index.js +13 -0
  111. package/preact/src/internal.d.ts +147 -0
  112. package/preact/src/jsx.d.ts +955 -0
  113. package/preact/src/options.js +17 -0
  114. package/preact/src/render.js +74 -0
  115. package/preact/src/util.js +23 -0
  116. package/preact/test-utils/dist/testUtils.js +2 -0
  117. package/preact/test-utils/dist/testUtils.js.map +1 -0
  118. package/preact/test-utils/dist/testUtils.mjs +2 -0
  119. package/preact/test-utils/dist/testUtils.module.js +2 -0
  120. package/preact/test-utils/dist/testUtils.module.js.map +1 -0
  121. package/preact/test-utils/dist/testUtils.umd.js +2 -0
  122. package/preact/test-utils/dist/testUtils.umd.js.map +1 -0
  123. package/preact/test-utils/package.json +19 -0
  124. package/preact/test-utils/src/index.d.ts +3 -0
  125. package/preact/test-utils/src/index.js +117 -0
  126. package/lib/PropertiesPanel.js +0 -126
  127. package/lib/PropertiesPanel.js.map +0 -1
  128. package/lib/components/DropdownButton.js +0 -109
  129. package/lib/components/DropdownButton.js.map +0 -1
  130. package/lib/components/Group.js +0 -75
  131. package/lib/components/Group.js.map +0 -1
  132. package/lib/components/Header.js +0 -49
  133. package/lib/components/Header.js.map +0 -1
  134. package/lib/components/HeaderButton.js +0 -16
  135. package/lib/components/HeaderButton.js.map +0 -1
  136. package/lib/components/ListGroup.js +0 -167
  137. package/lib/components/ListGroup.js.map +0 -1
  138. package/lib/components/ListItem.js +0 -37
  139. package/lib/components/ListItem.js.map +0 -1
  140. package/lib/components/entries/Checkbox.js +0 -81
  141. package/lib/components/entries/Checkbox.js.map +0 -1
  142. package/lib/components/entries/Collapsible.js +0 -48
  143. package/lib/components/entries/Collapsible.js.map +0 -1
  144. package/lib/components/entries/List.js +0 -204
  145. package/lib/components/entries/List.js.map +0 -1
  146. package/lib/components/entries/NumberField.js +0 -108
  147. package/lib/components/entries/NumberField.js.map +0 -1
  148. package/lib/components/entries/Select.js +0 -107
  149. package/lib/components/entries/Select.js.map +0 -1
  150. package/lib/components/entries/Simple.js +0 -56
  151. package/lib/components/entries/Simple.js.map +0 -1
  152. package/lib/components/entries/TextArea.js +0 -96
  153. package/lib/components/entries/TextArea.js.map +0 -1
  154. package/lib/components/entries/TextField.js +0 -121
  155. package/lib/components/entries/TextField.js.map +0 -1
  156. package/lib/components/entries/ToggleSwitch.js +0 -87
  157. package/lib/components/entries/ToggleSwitch.js.map +0 -1
  158. package/lib/components/icons/index.js +0 -51
  159. package/lib/components/icons/index.js.map +0 -1
  160. package/lib/context/LayoutContext.js +0 -9
  161. package/lib/context/LayoutContext.js.map +0 -1
  162. package/lib/context/index.js +0 -2
  163. package/lib/context/index.js.map +0 -1
  164. package/lib/features/debounce-input/debounceInput.js +0 -14
  165. package/lib/features/debounce-input/debounceInput.js.map +0 -1
  166. package/lib/features/debounce-input/index.js +0 -5
  167. package/lib/features/debounce-input/index.js.map +0 -1
  168. package/lib/hooks/index.js +0 -4
  169. package/lib/hooks/index.js.map +0 -1
  170. package/lib/hooks/useKeyFactory.js +0 -39
  171. package/lib/hooks/useKeyFactory.js.map +0 -1
  172. package/lib/hooks/useLayoutState.js +0 -36
  173. package/lib/hooks/useLayoutState.js.map +0 -1
  174. package/lib/hooks/usePrevious.js +0 -16
  175. package/lib/hooks/usePrevious.js.map +0 -1
  176. package/lib/index.js +0 -2
  177. package/lib/index.js.map +0 -1
@@ -0,0 +1,54 @@
1
+ const ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
2
+
3
+ let loggedTypeFailures = {};
4
+
5
+ /**
6
+ * Reset the history of which prop type warnings have been logged.
7
+ */
8
+ export function resetPropWarnings() {
9
+ loggedTypeFailures = {};
10
+ }
11
+
12
+ /**
13
+ * Assert that the values match with the type specs.
14
+ * Error messages are memorized and will only be shown once.
15
+ *
16
+ * Adapted from https://github.com/facebook/prop-types/blob/master/checkPropTypes.js
17
+ *
18
+ * @param {object} typeSpecs Map of name to a ReactPropType
19
+ * @param {object} values Runtime values that need to be type-checked
20
+ * @param {string} location e.g. "prop", "context", "child context"
21
+ * @param {string} componentName Name of the component for error messages.
22
+ * @param {?Function} getStack Returns the component stack.
23
+ */
24
+ export function checkPropTypes(
25
+ typeSpecs,
26
+ values,
27
+ location,
28
+ componentName,
29
+ getStack
30
+ ) {
31
+ Object.keys(typeSpecs).forEach(typeSpecName => {
32
+ let error;
33
+ try {
34
+ error = typeSpecs[typeSpecName](
35
+ values,
36
+ typeSpecName,
37
+ componentName,
38
+ location,
39
+ null,
40
+ ReactPropTypesSecret
41
+ );
42
+ } catch (e) {
43
+ error = e;
44
+ }
45
+ if (error && !(error.message in loggedTypeFailures)) {
46
+ loggedTypeFailures[error.message] = true;
47
+ console.error(
48
+ `Failed ${location} type: ${error.message}${(getStack &&
49
+ `\n${getStack()}`) ||
50
+ ''}`
51
+ );
52
+ }
53
+ });
54
+ }
@@ -0,0 +1,146 @@
1
+ import { options, Fragment } from '../..';
2
+
3
+ /**
4
+ * Get human readable name of the component/dom node
5
+ * @param {import('./internal').VNode} vnode
6
+ * @param {import('./internal').VNode} vnode
7
+ * @returns {string}
8
+ */
9
+ export function getDisplayName(vnode) {
10
+ if (vnode.type === Fragment) {
11
+ return 'Fragment';
12
+ } else if (typeof vnode.type == 'function') {
13
+ return vnode.type.displayName || vnode.type.name;
14
+ } else if (typeof vnode.type == 'string') {
15
+ return vnode.type;
16
+ }
17
+
18
+ return '#text';
19
+ }
20
+
21
+ /**
22
+ * Used to keep track of the currently rendered `vnode` and print it
23
+ * in debug messages.
24
+ */
25
+ let renderStack = [];
26
+
27
+ /**
28
+ * Keep track of the current owners. An owner describes a component
29
+ * which was responsible to render a specific `vnode`. This exclude
30
+ * children that are passed via `props.children`, because they belong
31
+ * to the parent owner.
32
+ *
33
+ * ```jsx
34
+ * const Foo = props => <div>{props.children}</div> // div's owner is Foo
35
+ * const Bar = props => {
36
+ * return (
37
+ * <Foo><span /></Foo> // Foo's owner is Bar, span's owner is Bar
38
+ * )
39
+ * }
40
+ * ```
41
+ *
42
+ * Note: A `vnode` may be hoisted to the root scope due to compiler
43
+ * optimiztions. In these cases the `_owner` will be different.
44
+ */
45
+ let ownerStack = [];
46
+
47
+ /**
48
+ * Get the currently rendered `vnode`
49
+ * @returns {import('./internal').VNode | null}
50
+ */
51
+ export function getCurrentVNode() {
52
+ return renderStack.length > 0 ? renderStack[renderStack.length - 1] : null;
53
+ }
54
+
55
+ /**
56
+ * If the user doesn't have `@babel/plugin-transform-react-jsx-source`
57
+ * somewhere in his tool chain we can't print the filename and source
58
+ * location of a component. In that case we just omit that, but we'll
59
+ * print a helpful message to the console, notifying the user of it.
60
+ */
61
+ let hasBabelPlugin = false;
62
+
63
+ /**
64
+ * Check if a `vnode` is a possible owner.
65
+ * @param {import('./internal').VNode} vnode
66
+ */
67
+ function isPossibleOwner(vnode) {
68
+ return typeof vnode.type == 'function' && vnode.type != Fragment;
69
+ }
70
+
71
+ /**
72
+ * Return the component stack that was captured up to this point.
73
+ * @param {import('./internal').VNode} vnode
74
+ * @returns {string}
75
+ */
76
+ export function getOwnerStack(vnode) {
77
+ const stack = [vnode];
78
+ let next = vnode;
79
+ while (next._owner != null) {
80
+ stack.push(next._owner);
81
+ next = next._owner;
82
+ }
83
+
84
+ return stack.reduce((acc, owner) => {
85
+ acc += ` in ${getDisplayName(owner)}`;
86
+
87
+ const source = owner.__source;
88
+ if (source) {
89
+ acc += ` (at ${source.fileName}:${source.lineNumber})`;
90
+ } else if (!hasBabelPlugin) {
91
+ hasBabelPlugin = true;
92
+ console.warn(
93
+ 'Add @babel/plugin-transform-react-jsx-source to get a more detailed component stack. Note that you should not add it to production builds of your App for bundle size reasons.'
94
+ );
95
+ }
96
+
97
+ return (acc += '\n');
98
+ }, '');
99
+ }
100
+
101
+ /**
102
+ * Setup code to capture the component trace while rendering. Note that
103
+ * we cannot simply traverse `vnode._parent` upwards, because we have some
104
+ * debug messages for `this.setState` where the `vnode` is `undefined`.
105
+ */
106
+ export function setupComponentStack() {
107
+ let oldDiff = options._diff;
108
+ let oldDiffed = options.diffed;
109
+ let oldRoot = options._root;
110
+ let oldVNode = options.vnode;
111
+ let oldRender = options._render;
112
+
113
+ options.diffed = vnode => {
114
+ if (isPossibleOwner(vnode)) {
115
+ ownerStack.pop();
116
+ }
117
+ renderStack.pop();
118
+ if (oldDiffed) oldDiffed(vnode);
119
+ };
120
+
121
+ options._diff = vnode => {
122
+ if (isPossibleOwner(vnode)) {
123
+ renderStack.push(vnode);
124
+ }
125
+ if (oldDiff) oldDiff(vnode);
126
+ };
127
+
128
+ options._root = (vnode, parent) => {
129
+ ownerStack = [];
130
+ if (oldRoot) oldRoot(vnode, parent);
131
+ };
132
+
133
+ options.vnode = vnode => {
134
+ vnode._owner =
135
+ ownerStack.length > 0 ? ownerStack[ownerStack.length - 1] : null;
136
+ if (oldVNode) oldVNode(vnode);
137
+ };
138
+
139
+ options._render = vnode => {
140
+ if (isPossibleOwner(vnode)) {
141
+ ownerStack.push(vnode);
142
+ }
143
+
144
+ if (oldRender) oldRender(vnode);
145
+ };
146
+ }
@@ -0,0 +1,3 @@
1
+ export const ELEMENT_NODE = 1;
2
+ export const DOCUMENT_NODE = 9;
3
+ export const DOCUMENT_FRAGMENT_NODE = 11;
@@ -0,0 +1,442 @@
1
+ import { checkPropTypes } from './check-props';
2
+ import { options, Component } from '../..';
3
+ import {
4
+ ELEMENT_NODE,
5
+ DOCUMENT_NODE,
6
+ DOCUMENT_FRAGMENT_NODE
7
+ } from './constants';
8
+ import {
9
+ getOwnerStack,
10
+ setupComponentStack,
11
+ getCurrentVNode,
12
+ getDisplayName
13
+ } from './component-stack';
14
+ import { assign } from './util';
15
+
16
+ const isWeakMapSupported = typeof WeakMap == 'function';
17
+
18
+ function getClosestDomNodeParent(parent) {
19
+ if (!parent) return {};
20
+ if (typeof parent.type == 'function') {
21
+ return getClosestDomNodeParent(parent._parent);
22
+ }
23
+ return parent;
24
+ }
25
+
26
+ export function initDebug() {
27
+ setupComponentStack();
28
+
29
+ let hooksAllowed = false;
30
+
31
+ /* eslint-disable no-console */
32
+ let oldBeforeDiff = options._diff;
33
+ let oldDiffed = options.diffed;
34
+ let oldVnode = options.vnode;
35
+ let oldCatchError = options._catchError;
36
+ let oldRoot = options._root;
37
+ let oldHook = options._hook;
38
+ const warnedComponents = !isWeakMapSupported
39
+ ? null
40
+ : {
41
+ useEffect: new WeakMap(),
42
+ useLayoutEffect: new WeakMap(),
43
+ lazyPropTypes: new WeakMap()
44
+ };
45
+ const deprecations = [];
46
+
47
+ options._catchError = (error, vnode, oldVNode) => {
48
+ let component = vnode && vnode._component;
49
+ if (component && typeof error.then == 'function') {
50
+ const promise = error;
51
+ error = new Error(
52
+ `Missing Suspense. The throwing component was: ${getDisplayName(vnode)}`
53
+ );
54
+
55
+ let parent = vnode;
56
+ for (; parent; parent = parent._parent) {
57
+ if (parent._component && parent._component._childDidSuspend) {
58
+ error = promise;
59
+ break;
60
+ }
61
+ }
62
+
63
+ // We haven't recovered and we know at this point that there is no
64
+ // Suspense component higher up in the tree
65
+ if (error instanceof Error) {
66
+ throw error;
67
+ }
68
+ }
69
+
70
+ try {
71
+ oldCatchError(error, vnode, oldVNode);
72
+
73
+ // when an error was handled by an ErrorBoundary we will nontheless emit an error
74
+ // event on the window object. This is to make up for react compatibility in dev mode
75
+ // and thus make the Next.js dev overlay work.
76
+ if (typeof error.then != 'function') {
77
+ setTimeout(() => {
78
+ throw error;
79
+ });
80
+ }
81
+ } catch (e) {
82
+ throw e;
83
+ }
84
+ };
85
+
86
+ options._root = (vnode, parentNode) => {
87
+ if (!parentNode) {
88
+ throw new Error(
89
+ 'Undefined parent passed to render(), this is the second argument.\n' +
90
+ 'Check if the element is available in the DOM/has the correct id.'
91
+ );
92
+ }
93
+
94
+ let isValid;
95
+ switch (parentNode.nodeType) {
96
+ case ELEMENT_NODE:
97
+ case DOCUMENT_FRAGMENT_NODE:
98
+ case DOCUMENT_NODE:
99
+ isValid = true;
100
+ break;
101
+ default:
102
+ isValid = false;
103
+ }
104
+
105
+ if (!isValid) {
106
+ let componentName = getDisplayName(vnode);
107
+ throw new Error(
108
+ `Expected a valid HTML node as a second argument to render. Received ${parentNode} instead: render(<${componentName} />, ${parentNode});`
109
+ );
110
+ }
111
+
112
+ if (oldRoot) oldRoot(vnode, parentNode);
113
+ };
114
+
115
+ options._diff = vnode => {
116
+ let { type, _parent: parent } = vnode;
117
+ let parentVNode = getClosestDomNodeParent(parent);
118
+
119
+ hooksAllowed = true;
120
+
121
+ if (type === undefined) {
122
+ throw new Error(
123
+ 'Undefined component passed to createElement()\n\n' +
124
+ 'You likely forgot to export your component or might have mixed up default and named imports' +
125
+ serializeVNode(vnode) +
126
+ `\n\n${getOwnerStack(vnode)}`
127
+ );
128
+ } else if (type != null && typeof type == 'object') {
129
+ if (type._children !== undefined && type._dom !== undefined) {
130
+ throw new Error(
131
+ `Invalid type passed to createElement(): ${type}\n\n` +
132
+ 'Did you accidentally pass a JSX literal as JSX twice?\n\n' +
133
+ ` let My${getDisplayName(vnode)} = ${serializeVNode(type)};\n` +
134
+ ` let vnode = <My${getDisplayName(vnode)} />;\n\n` +
135
+ 'This usually happens when you export a JSX literal and not the component.' +
136
+ `\n\n${getOwnerStack(vnode)}`
137
+ );
138
+ }
139
+
140
+ throw new Error(
141
+ 'Invalid type passed to createElement(): ' +
142
+ (Array.isArray(type) ? 'array' : type)
143
+ );
144
+ }
145
+
146
+ if (
147
+ (type === 'thead' || type === 'tfoot' || type === 'tbody') &&
148
+ parentVNode.type !== 'table'
149
+ ) {
150
+ console.error(
151
+ 'Improper nesting of table. Your <thead/tbody/tfoot> should have a <table> parent.' +
152
+ serializeVNode(vnode) +
153
+ `\n\n${getOwnerStack(vnode)}`
154
+ );
155
+ } else if (
156
+ type === 'tr' &&
157
+ parentVNode.type !== 'thead' &&
158
+ parentVNode.type !== 'tfoot' &&
159
+ parentVNode.type !== 'tbody' &&
160
+ parentVNode.type !== 'table'
161
+ ) {
162
+ console.error(
163
+ 'Improper nesting of table. Your <tr> should have a <thead/tbody/tfoot/table> parent.' +
164
+ serializeVNode(vnode) +
165
+ `\n\n${getOwnerStack(vnode)}`
166
+ );
167
+ } else if (type === 'td' && parentVNode.type !== 'tr') {
168
+ console.error(
169
+ 'Improper nesting of table. Your <td> should have a <tr> parent.' +
170
+ serializeVNode(vnode) +
171
+ `\n\n${getOwnerStack(vnode)}`
172
+ );
173
+ } else if (type === 'th' && parentVNode.type !== 'tr') {
174
+ console.error(
175
+ 'Improper nesting of table. Your <th> should have a <tr>.' +
176
+ serializeVNode(vnode) +
177
+ `\n\n${getOwnerStack(vnode)}`
178
+ );
179
+ }
180
+
181
+ if (
182
+ vnode.ref !== undefined &&
183
+ typeof vnode.ref != 'function' &&
184
+ typeof vnode.ref != 'object' &&
185
+ !('$$typeof' in vnode) // allow string refs when preact-compat is installed
186
+ ) {
187
+ throw new Error(
188
+ `Component's "ref" property should be a function, or an object created ` +
189
+ `by createRef(), but got [${typeof vnode.ref}] instead\n` +
190
+ serializeVNode(vnode) +
191
+ `\n\n${getOwnerStack(vnode)}`
192
+ );
193
+ }
194
+
195
+ if (typeof vnode.type == 'string') {
196
+ for (const key in vnode.props) {
197
+ if (
198
+ key[0] === 'o' &&
199
+ key[1] === 'n' &&
200
+ typeof vnode.props[key] != 'function' &&
201
+ vnode.props[key] != null
202
+ ) {
203
+ throw new Error(
204
+ `Component's "${key}" property should be a function, ` +
205
+ `but got [${typeof vnode.props[key]}] instead\n` +
206
+ serializeVNode(vnode) +
207
+ `\n\n${getOwnerStack(vnode)}`
208
+ );
209
+ }
210
+ }
211
+ }
212
+
213
+ // Check prop-types if available
214
+ if (typeof vnode.type == 'function' && vnode.type.propTypes) {
215
+ if (
216
+ vnode.type.displayName === 'Lazy' &&
217
+ warnedComponents &&
218
+ !warnedComponents.lazyPropTypes.has(vnode.type)
219
+ ) {
220
+ const m =
221
+ 'PropTypes are not supported on lazy(). Use propTypes on the wrapped component itself. ';
222
+ try {
223
+ const lazyVNode = vnode.type();
224
+ warnedComponents.lazyPropTypes.set(vnode.type, true);
225
+ console.warn(
226
+ m + `Component wrapped in lazy() is ${getDisplayName(lazyVNode)}`
227
+ );
228
+ } catch (promise) {
229
+ console.warn(
230
+ m + "We will log the wrapped component's name once it is loaded."
231
+ );
232
+ }
233
+ }
234
+
235
+ let values = vnode.props;
236
+ if (vnode.type._forwarded) {
237
+ values = assign({}, values);
238
+ delete values.ref;
239
+ }
240
+
241
+ checkPropTypes(
242
+ vnode.type.propTypes,
243
+ values,
244
+ 'prop',
245
+ getDisplayName(vnode),
246
+ () => getOwnerStack(vnode)
247
+ );
248
+ }
249
+
250
+ if (oldBeforeDiff) oldBeforeDiff(vnode);
251
+ };
252
+
253
+ options._hook = (comp, index, type) => {
254
+ if (!comp || !hooksAllowed) {
255
+ throw new Error('Hook can only be invoked from render methods.');
256
+ }
257
+
258
+ if (oldHook) oldHook(comp, index, type);
259
+ };
260
+
261
+ // Ideally we'd want to print a warning once per component, but we
262
+ // don't have access to the vnode that triggered it here. As a
263
+ // compromise and to avoid flooding the console with warnings we
264
+ // print each deprecation warning only once.
265
+ const warn = (property, message) => ({
266
+ get() {
267
+ const key = 'get' + property + message;
268
+ if (deprecations && deprecations.indexOf(key) < 0) {
269
+ deprecations.push(key);
270
+ console.warn(`getting vnode.${property} is deprecated, ${message}`);
271
+ }
272
+ },
273
+ set() {
274
+ const key = 'set' + property + message;
275
+ if (deprecations && deprecations.indexOf(key) < 0) {
276
+ deprecations.push(key);
277
+ console.warn(`setting vnode.${property} is not allowed, ${message}`);
278
+ }
279
+ }
280
+ });
281
+
282
+ const deprecatedAttributes = {
283
+ nodeName: warn('nodeName', 'use vnode.type'),
284
+ attributes: warn('attributes', 'use vnode.props'),
285
+ children: warn('children', 'use vnode.props.children')
286
+ };
287
+
288
+ const deprecatedProto = Object.create({}, deprecatedAttributes);
289
+
290
+ options.vnode = vnode => {
291
+ const props = vnode.props;
292
+ if (
293
+ vnode.type !== null &&
294
+ props != null &&
295
+ ('__source' in props || '__self' in props)
296
+ ) {
297
+ const newProps = (vnode.props = {});
298
+ for (let i in props) {
299
+ const v = props[i];
300
+ if (i === '__source') vnode.__source = v;
301
+ else if (i === '__self') vnode.__self = v;
302
+ else newProps[i] = v;
303
+ }
304
+ }
305
+
306
+ // eslint-disable-next-line
307
+ vnode.__proto__ = deprecatedProto;
308
+ if (oldVnode) oldVnode(vnode);
309
+ };
310
+
311
+ options.diffed = vnode => {
312
+ // Check if the user passed plain objects as children. Note that we cannot
313
+ // move this check into `options.vnode` because components can receive
314
+ // children in any shape they want (e.g.
315
+ // `<MyJSONFormatter>{{ foo: 123, bar: "abc" }}</MyJSONFormatter>`).
316
+ // Putting this check in `options.diffed` ensures that
317
+ // `vnode._children` is set and that we only validate the children
318
+ // that were actually rendered.
319
+ if (vnode._children) {
320
+ vnode._children.forEach(child => {
321
+ if (child && child.type === undefined) {
322
+ // Remove internal vnode keys that will always be patched
323
+ delete child._parent;
324
+ delete child._depth;
325
+ const keys = Object.keys(child).join(',');
326
+ throw new Error(
327
+ `Objects are not valid as a child. Encountered an object with the keys {${keys}}.` +
328
+ `\n\n${getOwnerStack(vnode)}`
329
+ );
330
+ }
331
+ });
332
+ }
333
+
334
+ hooksAllowed = false;
335
+
336
+ if (oldDiffed) oldDiffed(vnode);
337
+
338
+ if (vnode._children != null) {
339
+ const keys = [];
340
+ for (let i = 0; i < vnode._children.length; i++) {
341
+ const child = vnode._children[i];
342
+ if (!child || child.key == null) continue;
343
+
344
+ const key = child.key;
345
+ if (keys.indexOf(key) !== -1) {
346
+ console.error(
347
+ 'Following component has two or more children with the ' +
348
+ `same key attribute: "${key}". This may cause glitches and misbehavior ` +
349
+ 'in rendering process. Component: \n\n' +
350
+ serializeVNode(vnode) +
351
+ `\n\n${getOwnerStack(vnode)}`
352
+ );
353
+
354
+ // Break early to not spam the console
355
+ break;
356
+ }
357
+
358
+ keys.push(key);
359
+ }
360
+ }
361
+ };
362
+ }
363
+
364
+ const setState = Component.prototype.setState;
365
+ Component.prototype.setState = function(update, callback) {
366
+ if (this._vnode == null) {
367
+ // `this._vnode` will be `null` during componentWillMount. But it
368
+ // is perfectly valid to call `setState` during cWM. So we
369
+ // need an additional check to verify that we are dealing with a
370
+ // call inside constructor.
371
+ if (this.state == null) {
372
+ console.warn(
373
+ `Calling "this.setState" inside the constructor of a component is a ` +
374
+ `no-op and might be a bug in your application. Instead, set ` +
375
+ `"this.state = {}" directly.\n\n${getOwnerStack(getCurrentVNode())}`
376
+ );
377
+ }
378
+ } else if (this._parentDom == null) {
379
+ console.warn(
380
+ `Can't call "this.setState" on an unmounted component. This is a no-op, ` +
381
+ `but it indicates a memory leak in your application. To fix, cancel all ` +
382
+ `subscriptions and asynchronous tasks in the componentWillUnmount method.` +
383
+ `\n\n${getOwnerStack(this._vnode)}`
384
+ );
385
+ }
386
+
387
+ return setState.call(this, update, callback);
388
+ };
389
+
390
+ const forceUpdate = Component.prototype.forceUpdate;
391
+ Component.prototype.forceUpdate = function(callback) {
392
+ if (this._vnode == null) {
393
+ console.warn(
394
+ `Calling "this.forceUpdate" inside the constructor of a component is a ` +
395
+ `no-op and might be a bug in your application.\n\n${getOwnerStack(
396
+ getCurrentVNode()
397
+ )}`
398
+ );
399
+ } else if (this._parentDom == null) {
400
+ console.warn(
401
+ `Can't call "this.forceUpdate" on an unmounted component. This is a no-op, ` +
402
+ `but it indicates a memory leak in your application. To fix, cancel all ` +
403
+ `subscriptions and asynchronous tasks in the componentWillUnmount method.` +
404
+ `\n\n${getOwnerStack(this._vnode)}`
405
+ );
406
+ }
407
+ return forceUpdate.call(this, callback);
408
+ };
409
+
410
+ /**
411
+ * Serialize a vnode tree to a string
412
+ * @param {import('./internal').VNode} vnode
413
+ * @returns {string}
414
+ */
415
+ export function serializeVNode(vnode) {
416
+ let { props } = vnode;
417
+ let name = getDisplayName(vnode);
418
+
419
+ let attrs = '';
420
+ for (let prop in props) {
421
+ if (props.hasOwnProperty(prop) && prop !== 'children') {
422
+ let value = props[prop];
423
+
424
+ // If it is an object but doesn't have toString(), use Object.toString
425
+ if (typeof value == 'function') {
426
+ value = `function ${value.displayName || value.name}() {}`;
427
+ }
428
+
429
+ value =
430
+ Object(value) === value && !value.toString
431
+ ? Object.prototype.toString.call(value)
432
+ : value + '';
433
+
434
+ attrs += ` ${prop}=${JSON.stringify(value)}`;
435
+ }
436
+ }
437
+
438
+ let children = props.children;
439
+ return `<${name}${attrs}${
440
+ children && children.length ? '>..</' + name + '>' : ' />'
441
+ }`;
442
+ }
@@ -0,0 +1,6 @@
1
+ import { initDebug } from './debug';
2
+ import '../../devtools';
3
+
4
+ initDebug();
5
+
6
+ export { resetPropWarnings } from './check-props';