@valbuild/react 0.150.6 → 0.150.7

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @valbuild/react
2
2
 
3
+ ## 0.150.7
4
+
5
+ ### Patch Changes
6
+
7
+ - [#965](https://github.com/valbuild/val/pull/965) [`2d5ad2e`](https://github.com/valbuild/val/commit/2d5ad2e90f2a2bdd6ad8af98b21e19bc0bf6dbcc) Thanks [@freekh](https://github.com/freekh)! - In development, a component that passes its children on to a link or another element -- `<TextLink>{label} →</TextLink>` -- no longer leaves the edit tag in the text. React's development build freezes those children, and Val tagged the element without cleaning its text, so the leak warning named it. Production was not affected.
8
+
3
9
  ## 0.150.6
4
10
 
5
11
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valbuild/react",
3
- "version": "0.150.6",
3
+ "version": "0.150.7",
4
4
  "private": false,
5
5
  "description": "Val - React internal helpers",
6
6
  "repository": {
@@ -11,9 +11,9 @@
11
11
  "dependencies": {
12
12
  "@vercel/stega": "^1.1.0",
13
13
  "base64-arraybuffer": "^1.0.2",
14
+ "@valbuild/core": "0.150.3",
14
15
  "@valbuild/shared": "0.150.3",
15
- "@valbuild/ui": "0.150.5",
16
- "@valbuild/core": "0.150.3"
16
+ "@valbuild/ui": "0.150.5"
17
17
  },
18
18
  "devDependencies": {
19
19
  "@testing-library/react": "^16.3.3",
@@ -47,6 +47,28 @@ function pathsOfFragmentChildren(children) {
47
47
  return found;
48
48
  }
49
49
 
50
+ /**
51
+ * `props.children` as an array that can be written to, or null when it is
52
+ * an array that cannot and `props` cannot take another.
53
+ *
54
+ * React's development build freezes an element's static children
55
+ * (`{label} →` is `[label, " →"]`), so a component that hands its
56
+ * `children` on to an intrinsic element -- `<a>{children}</a>` -- hands on a
57
+ * frozen array: the element got its `data-val-path`, and its text kept the
58
+ * edit tag, in development only. Its props are the component's own, fresh
59
+ * object, so the cleaned copy goes there.
60
+ */
61
+ function writableChildren(props) {
62
+ if (!Object.isFrozen(props.children)) {
63
+ return props.children;
64
+ }
65
+ if (Object.isFrozen(props)) {
66
+ return null;
67
+ }
68
+ props.children = _toConsumableArray(props.children);
69
+ return props.children;
70
+ }
71
+
50
72
  /**
51
73
  * Takes the edit tags out of a fragment's text, and returns the paths they
52
74
  * named -- its own and its fragment children's -- for its parent to carry.
@@ -67,9 +89,10 @@ function cleanFragment(props) {
67
89
  return value;
68
90
  };
69
91
  if (Array.isArray(props.children)) {
70
- if (!Object.isFrozen(props.children)) {
71
- props.children.forEach(function (child, index) {
72
- props.children[index] = clean(child);
92
+ var children = writableChildren(props);
93
+ if (children) {
94
+ children.forEach(function (child, index) {
95
+ children[index] = clean(child);
73
96
  });
74
97
  }
75
98
  } else if (!Object.isFrozen(props)) {
@@ -184,12 +207,14 @@ var addValPathIfFound = function addValPathIfFound(type, props) {
184
207
  }
185
208
  }
186
209
  } else if (value instanceof Array) {
187
- for (var _i3 = 0, _Object$entries3 = Object.entries(value); _i3 < _Object$entries3.length; _i3++) {
210
+ var _writableChildren;
211
+ var container = key === "children" && isIntrinsicElement(type) ? (_writableChildren = writableChildren(props)) !== null && _writableChildren !== void 0 ? _writableChildren : value : value;
212
+ for (var _i3 = 0, _Object$entries3 = Object.entries(container); _i3 < _Object$entries3.length; _i3++) {
188
213
  var _Object$entries3$_i = _slicedToArray(_Object$entries3[_i3], 2),
189
214
  index = _Object$entries3$_i[0],
190
215
  item = _Object$entries3$_i[1];
191
216
  if (typeof item === "string" && item.match(VERCEL_STEGA_REGEX)) {
192
- updateValSources(index, item, props, value);
217
+ updateValSources(index, item, props, container);
193
218
  }
194
219
  }
195
220
  }
@@ -56,6 +56,28 @@ function pathsOfFragmentChildren(children) {
56
56
  return found;
57
57
  }
58
58
 
59
+ /**
60
+ * `props.children` as an array that can be written to, or null when it is
61
+ * an array that cannot and `props` cannot take another.
62
+ *
63
+ * React's development build freezes an element's static children
64
+ * (`{label} →` is `[label, " →"]`), so a component that hands its
65
+ * `children` on to an intrinsic element -- `<a>{children}</a>` -- hands on a
66
+ * frozen array: the element got its `data-val-path`, and its text kept the
67
+ * edit tag, in development only. Its props are the component's own, fresh
68
+ * object, so the cleaned copy goes there.
69
+ */
70
+ function writableChildren(props) {
71
+ if (!Object.isFrozen(props.children)) {
72
+ return props.children;
73
+ }
74
+ if (Object.isFrozen(props)) {
75
+ return null;
76
+ }
77
+ props.children = createForOfIteratorHelper._toConsumableArray(props.children);
78
+ return props.children;
79
+ }
80
+
59
81
  /**
60
82
  * Takes the edit tags out of a fragment's text, and returns the paths they
61
83
  * named -- its own and its fragment children's -- for its parent to carry.
@@ -76,9 +98,10 @@ function cleanFragment(props) {
76
98
  return value;
77
99
  };
78
100
  if (Array.isArray(props.children)) {
79
- if (!Object.isFrozen(props.children)) {
80
- props.children.forEach(function (child, index) {
81
- props.children[index] = clean(child);
101
+ var children = writableChildren(props);
102
+ if (children) {
103
+ children.forEach(function (child, index) {
104
+ children[index] = clean(child);
82
105
  });
83
106
  }
84
107
  } else if (!Object.isFrozen(props)) {
@@ -193,12 +216,14 @@ var addValPathIfFound = function addValPathIfFound(type, props) {
193
216
  }
194
217
  }
195
218
  } else if (value instanceof Array) {
196
- for (var _i3 = 0, _Object$entries3 = Object.entries(value); _i3 < _Object$entries3.length; _i3++) {
219
+ var _writableChildren;
220
+ var container = key === "children" && isIntrinsicElement(type) ? (_writableChildren = writableChildren(props)) !== null && _writableChildren !== void 0 ? _writableChildren : value : value;
221
+ for (var _i3 = 0, _Object$entries3 = Object.entries(container); _i3 < _Object$entries3.length; _i3++) {
197
222
  var _Object$entries3$_i = slicedToArray._slicedToArray(_Object$entries3[_i3], 2),
198
223
  index = _Object$entries3$_i[0],
199
224
  item = _Object$entries3$_i[1];
200
225
  if (typeof item === "string" && item.match(stega.VERCEL_STEGA_REGEX)) {
201
- updateValSources(index, item, props, value);
226
+ updateValSources(index, item, props, container);
202
227
  }
203
228
  }
204
229
  }
@@ -56,6 +56,28 @@ function pathsOfFragmentChildren(children) {
56
56
  return found;
57
57
  }
58
58
 
59
+ /**
60
+ * `props.children` as an array that can be written to, or null when it is
61
+ * an array that cannot and `props` cannot take another.
62
+ *
63
+ * React's development build freezes an element's static children
64
+ * (`{label} →` is `[label, " →"]`), so a component that hands its
65
+ * `children` on to an intrinsic element -- `<a>{children}</a>` -- hands on a
66
+ * frozen array: the element got its `data-val-path`, and its text kept the
67
+ * edit tag, in development only. Its props are the component's own, fresh
68
+ * object, so the cleaned copy goes there.
69
+ */
70
+ function writableChildren(props) {
71
+ if (!Object.isFrozen(props.children)) {
72
+ return props.children;
73
+ }
74
+ if (Object.isFrozen(props)) {
75
+ return null;
76
+ }
77
+ props.children = createForOfIteratorHelper._toConsumableArray(props.children);
78
+ return props.children;
79
+ }
80
+
59
81
  /**
60
82
  * Takes the edit tags out of a fragment's text, and returns the paths they
61
83
  * named -- its own and its fragment children's -- for its parent to carry.
@@ -76,9 +98,10 @@ function cleanFragment(props) {
76
98
  return value;
77
99
  };
78
100
  if (Array.isArray(props.children)) {
79
- if (!Object.isFrozen(props.children)) {
80
- props.children.forEach(function (child, index) {
81
- props.children[index] = clean(child);
101
+ var children = writableChildren(props);
102
+ if (children) {
103
+ children.forEach(function (child, index) {
104
+ children[index] = clean(child);
82
105
  });
83
106
  }
84
107
  } else if (!Object.isFrozen(props)) {
@@ -193,12 +216,14 @@ var addValPathIfFound = function addValPathIfFound(type, props) {
193
216
  }
194
217
  }
195
218
  } else if (value instanceof Array) {
196
- for (var _i3 = 0, _Object$entries3 = Object.entries(value); _i3 < _Object$entries3.length; _i3++) {
219
+ var _writableChildren;
220
+ var container = key === "children" && isIntrinsicElement(type) ? (_writableChildren = writableChildren(props)) !== null && _writableChildren !== void 0 ? _writableChildren : value : value;
221
+ for (var _i3 = 0, _Object$entries3 = Object.entries(container); _i3 < _Object$entries3.length; _i3++) {
197
222
  var _Object$entries3$_i = slicedToArray._slicedToArray(_Object$entries3[_i3], 2),
198
223
  index = _Object$entries3$_i[0],
199
224
  item = _Object$entries3$_i[1];
200
225
  if (typeof item === "string" && item.match(stega.VERCEL_STEGA_REGEX)) {
201
- updateValSources(index, item, props, value);
226
+ updateValSources(index, item, props, container);
202
227
  }
203
228
  }
204
229
  }
@@ -47,6 +47,28 @@ function pathsOfFragmentChildren(children) {
47
47
  return found;
48
48
  }
49
49
 
50
+ /**
51
+ * `props.children` as an array that can be written to, or null when it is
52
+ * an array that cannot and `props` cannot take another.
53
+ *
54
+ * React's development build freezes an element's static children
55
+ * (`{label} →` is `[label, " →"]`), so a component that hands its
56
+ * `children` on to an intrinsic element -- `<a>{children}</a>` -- hands on a
57
+ * frozen array: the element got its `data-val-path`, and its text kept the
58
+ * edit tag, in development only. Its props are the component's own, fresh
59
+ * object, so the cleaned copy goes there.
60
+ */
61
+ function writableChildren(props) {
62
+ if (!Object.isFrozen(props.children)) {
63
+ return props.children;
64
+ }
65
+ if (Object.isFrozen(props)) {
66
+ return null;
67
+ }
68
+ props.children = _toConsumableArray(props.children);
69
+ return props.children;
70
+ }
71
+
50
72
  /**
51
73
  * Takes the edit tags out of a fragment's text, and returns the paths they
52
74
  * named -- its own and its fragment children's -- for its parent to carry.
@@ -67,9 +89,10 @@ function cleanFragment(props) {
67
89
  return value;
68
90
  };
69
91
  if (Array.isArray(props.children)) {
70
- if (!Object.isFrozen(props.children)) {
71
- props.children.forEach(function (child, index) {
72
- props.children[index] = clean(child);
92
+ var children = writableChildren(props);
93
+ if (children) {
94
+ children.forEach(function (child, index) {
95
+ children[index] = clean(child);
73
96
  });
74
97
  }
75
98
  } else if (!Object.isFrozen(props)) {
@@ -184,12 +207,14 @@ var addValPathIfFound = function addValPathIfFound(type, props) {
184
207
  }
185
208
  }
186
209
  } else if (value instanceof Array) {
187
- for (var _i3 = 0, _Object$entries3 = Object.entries(value); _i3 < _Object$entries3.length; _i3++) {
210
+ var _writableChildren;
211
+ var container = key === "children" && isIntrinsicElement(type) ? (_writableChildren = writableChildren(props)) !== null && _writableChildren !== void 0 ? _writableChildren : value : value;
212
+ for (var _i3 = 0, _Object$entries3 = Object.entries(container); _i3 < _Object$entries3.length; _i3++) {
188
213
  var _Object$entries3$_i = _slicedToArray(_Object$entries3[_i3], 2),
189
214
  index = _Object$entries3$_i[0],
190
215
  item = _Object$entries3$_i[1];
191
216
  if (typeof item === "string" && item.match(VERCEL_STEGA_REGEX)) {
192
- updateValSources(index, item, props, value);
217
+ updateValSources(index, item, props, container);
193
218
  }
194
219
  }
195
220
  }
@@ -47,6 +47,28 @@ function pathsOfFragmentChildren(children) {
47
47
  return found;
48
48
  }
49
49
 
50
+ /**
51
+ * `props.children` as an array that can be written to, or null when it is
52
+ * an array that cannot and `props` cannot take another.
53
+ *
54
+ * React's development build freezes an element's static children
55
+ * (`{label} →` is `[label, " →"]`), so a component that hands its
56
+ * `children` on to an intrinsic element -- `<a>{children}</a>` -- hands on a
57
+ * frozen array: the element got its `data-val-path`, and its text kept the
58
+ * edit tag, in development only. Its props are the component's own, fresh
59
+ * object, so the cleaned copy goes there.
60
+ */
61
+ function writableChildren(props) {
62
+ if (!Object.isFrozen(props.children)) {
63
+ return props.children;
64
+ }
65
+ if (Object.isFrozen(props)) {
66
+ return null;
67
+ }
68
+ props.children = _toConsumableArray(props.children);
69
+ return props.children;
70
+ }
71
+
50
72
  /**
51
73
  * Takes the edit tags out of a fragment's text, and returns the paths they
52
74
  * named -- its own and its fragment children's -- for its parent to carry.
@@ -67,9 +89,10 @@ function cleanFragment(props) {
67
89
  return value;
68
90
  };
69
91
  if (Array.isArray(props.children)) {
70
- if (!Object.isFrozen(props.children)) {
71
- props.children.forEach(function (child, index) {
72
- props.children[index] = clean(child);
92
+ var children = writableChildren(props);
93
+ if (children) {
94
+ children.forEach(function (child, index) {
95
+ children[index] = clean(child);
73
96
  });
74
97
  }
75
98
  } else if (!Object.isFrozen(props)) {
@@ -184,12 +207,14 @@ var addValPathIfFound = function addValPathIfFound(type, props) {
184
207
  }
185
208
  }
186
209
  } else if (value instanceof Array) {
187
- for (var _i3 = 0, _Object$entries3 = Object.entries(value); _i3 < _Object$entries3.length; _i3++) {
210
+ var _writableChildren;
211
+ var container = key === "children" && isIntrinsicElement(type) ? (_writableChildren = writableChildren(props)) !== null && _writableChildren !== void 0 ? _writableChildren : value : value;
212
+ for (var _i3 = 0, _Object$entries3 = Object.entries(container); _i3 < _Object$entries3.length; _i3++) {
188
213
  var _Object$entries3$_i = _slicedToArray(_Object$entries3[_i3], 2),
189
214
  index = _Object$entries3$_i[0],
190
215
  item = _Object$entries3$_i[1];
191
216
  if (typeof item === "string" && item.match(VERCEL_STEGA_REGEX)) {
192
- updateValSources(index, item, props, value);
217
+ updateValSources(index, item, props, container);
193
218
  }
194
219
  }
195
220
  }