@valbuild/react 0.62.4 → 0.62.6

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.
@@ -2,3 +2,5 @@ export { autoTagJSX } from "./autoTagJSX.js";
2
2
  export { stegaEncode, getModuleIds, stegaClean, type ValEncodedString, type StegaOfSource, } from "./stegaEncode.js";
3
3
  export { type Image } from "./stegaEncode.js";
4
4
  export { stegaDecodeString } from "./stegaDecodeString.js";
5
+ export declare function IS_AUTO_TAG_JSX_ENABLED(): boolean;
6
+ export declare function SET_AUTO_TAG_JSX_ENABLED(enabled: boolean): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valbuild/react",
3
- "version": "0.62.4",
3
+ "version": "0.62.6",
4
4
  "private": false,
5
5
  "description": "Val - React internal helpers",
6
6
  "sideEffects": false,
@@ -9,9 +9,9 @@
9
9
  "test": "jest"
10
10
  },
11
11
  "dependencies": {
12
- "@valbuild/core": "~0.62.4",
13
- "@valbuild/shared": "~0.62.4",
14
- "@valbuild/ui": "~0.62.4",
12
+ "@valbuild/core": "~0.62.6",
13
+ "@valbuild/shared": "~0.62.6",
14
+ "@valbuild/ui": "~0.62.6",
15
15
  "@vercel/stega": "^0.1.0",
16
16
  "base64-arraybuffer": "^1.0.2"
17
17
  },
@@ -18,12 +18,19 @@ function stegaDecodeString(encodedString) {
18
18
  }
19
19
  }
20
20
 
21
+ // import { IS_AUTO_TAG_JSX_ENABLED } from ".";
22
+
21
23
  var isIntrinsicElement = function isIntrinsicElement(type) {
22
24
  // TODO: think this is not correct, but good enough for now?
23
25
  return typeof type === "string";
24
26
  };
25
27
  var addValPathIfFound = function addValPathIfFound(type, props) {
26
- var valSources = [];
28
+ // TODO: increases performance. Unsure about the implications right now - seems to work. Remember to look at RSC and client (and pages/?).
29
+ // if (!IS_AUTO_TAG_JSX_ENABLED()) {
30
+ // return;
31
+ // }
32
+
33
+ var valSources = new Set();
27
34
 
28
35
  // skip auto-tagging fragments since we can't add attributes to them
29
36
  if (type === Symbol["for"]("react.fragment")) {
@@ -39,20 +46,27 @@ var addValPathIfFound = function addValPathIfFound(type, props) {
39
46
  return;
40
47
  }
41
48
  var valPath = stegaDecodeString(value);
42
- var attr = "data-val-attr-".concat(key.toString().toLowerCase());
43
- if (valPath && !props[attr]) {
44
- valSources.push(valPath);
45
- var cleanValue = isIntrinsicElement(type) ? vercelStegaSplit(value).cleaned : value;
46
- // we do Object.entries earlier over props so props that are arrays have string keys:
47
- var numberOfKey = Number(key);
48
- if (Array.isArray(container) && numberOfKey > -1) {
49
- container[numberOfKey] = cleanValue;
50
- } else if (typeof key === "string" && !Array.isArray(container)) {
51
- container[key] = cleanValue;
52
- } else {
53
- console.error("Val: Could not auto tag. Reason: unexpected types found while cleaning and / or adding val path data props.");
49
+ if (valPath) {
50
+ // Found val path - this is a stega encoded string
51
+ // The logic below is as follows:
52
+ // if this is an intrinsic element (a, div, etc.), add data attrs will be on the DOM element
53
+ // always add to sources (intrinsic or not)
54
+ // if this is not an intrinsic element, we pass the stega encoded value downwards until we hit an intrinsic element
55
+ valSources.add(valPath);
56
+ if (isIntrinsicElement(type)) {
57
+ // clean values before adding them to the props
58
+ // we cannot do this
59
+ var cleanValue = vercelStegaSplit(value).cleaned;
60
+ // we do Object.entries earlier over props so props that are arrays have string keys:
61
+ var numberOfKey = Number(key);
62
+ if (Array.isArray(container) && numberOfKey > -1) {
63
+ container[numberOfKey] = cleanValue;
64
+ } else if (typeof key === "string" && !Array.isArray(container)) {
65
+ container[key] = cleanValue;
66
+ } else {
67
+ console.error("Val: Could not auto tag. Reason: unexpected types found while cleaning and / or adding val path data props.");
68
+ }
54
69
  }
55
- props[attr] = valPath;
56
70
  }
57
71
  }
58
72
  if (props && _typeof(props) === "object") {
@@ -84,8 +98,8 @@ var addValPathIfFound = function addValPathIfFound(type, props) {
84
98
  }
85
99
  }
86
100
  }
87
- if (valSources.length > 0 && !props["data-val-path"]) {
88
- props["data-val-path"] = valSources.join(",");
101
+ if (valSources.size > 0 && !props["data-val-path"]) {
102
+ props["data-val-path"] = Array.from(valSources).join(",");
89
103
  }
90
104
  }
91
105
  };
@@ -183,6 +197,9 @@ function _objectSpread2(e) {
183
197
 
184
198
  function stegaEncode(input, opts) {
185
199
  function rec(sourceOrSelector, recOpts) {
200
+ if (recOpts !== null && recOpts !== void 0 && recOpts.schema && isKeyOfSchema(recOpts === null || recOpts === void 0 ? void 0 : recOpts.schema)) {
201
+ return sourceOrSelector;
202
+ }
186
203
  if (recOpts !== null && recOpts !== void 0 && recOpts.schema && isLiteralSchema(recOpts === null || recOpts === void 0 ? void 0 : recOpts.schema)) {
187
204
  return sourceOrSelector;
188
205
  }
@@ -325,6 +342,9 @@ function unknownSchema(schema) {
325
342
  function isUnionSchema(schema) {
326
343
  return (schema === null || schema === void 0 ? void 0 : schema.type) === "union";
327
344
  }
345
+ function isKeyOfSchema(schema) {
346
+ return (schema === null || schema === void 0 ? void 0 : schema.type) === "keyOf";
347
+ }
328
348
  function isObjectSchema(schema) {
329
349
  return (schema === null || schema === void 0 ? void 0 : schema.type) === "object";
330
350
  }
@@ -381,4 +401,13 @@ function getModuleIds(input) {
381
401
  return Array.from(modules);
382
402
  }
383
403
 
384
- export { autoTagJSX, getModuleIds, stegaClean, stegaDecodeString, stegaEncode };
404
+ // NOTE: the exports of this file needs to be kept in sync with ValQuickJSRuntime
405
+ var autoTagJSXEnabled = false;
406
+ function IS_AUTO_TAG_JSX_ENABLED() {
407
+ return autoTagJSXEnabled;
408
+ }
409
+ function SET_AUTO_TAG_JSX_ENABLED(enabled) {
410
+ autoTagJSXEnabled = enabled;
411
+ }
412
+
413
+ export { IS_AUTO_TAG_JSX_ENABLED, SET_AUTO_TAG_JSX_ENABLED, autoTagJSX, getModuleIds, stegaClean, stegaDecodeString, stegaEncode };
@@ -28,12 +28,19 @@ function stegaDecodeString(encodedString) {
28
28
  }
29
29
  }
30
30
 
31
+ // import { IS_AUTO_TAG_JSX_ENABLED } from ".";
32
+
31
33
  var isIntrinsicElement = function isIntrinsicElement(type) {
32
34
  // TODO: think this is not correct, but good enough for now?
33
35
  return typeof type === "string";
34
36
  };
35
37
  var addValPathIfFound = function addValPathIfFound(type, props) {
36
- var valSources = [];
38
+ // TODO: increases performance. Unsure about the implications right now - seems to work. Remember to look at RSC and client (and pages/?).
39
+ // if (!IS_AUTO_TAG_JSX_ENABLED()) {
40
+ // return;
41
+ // }
42
+
43
+ var valSources = new Set();
37
44
 
38
45
  // skip auto-tagging fragments since we can't add attributes to them
39
46
  if (type === Symbol["for"]("react.fragment")) {
@@ -49,20 +56,27 @@ var addValPathIfFound = function addValPathIfFound(type, props) {
49
56
  return;
50
57
  }
51
58
  var valPath = stegaDecodeString(value);
52
- var attr = "data-val-attr-".concat(key.toString().toLowerCase());
53
- if (valPath && !props[attr]) {
54
- valSources.push(valPath);
55
- var cleanValue = isIntrinsicElement(type) ? stega.vercelStegaSplit(value).cleaned : value;
56
- // we do Object.entries earlier over props so props that are arrays have string keys:
57
- var numberOfKey = Number(key);
58
- if (Array.isArray(container) && numberOfKey > -1) {
59
- container[numberOfKey] = cleanValue;
60
- } else if (typeof key === "string" && !Array.isArray(container)) {
61
- container[key] = cleanValue;
62
- } else {
63
- console.error("Val: Could not auto tag. Reason: unexpected types found while cleaning and / or adding val path data props.");
59
+ if (valPath) {
60
+ // Found val path - this is a stega encoded string
61
+ // The logic below is as follows:
62
+ // if this is an intrinsic element (a, div, etc.), add data attrs will be on the DOM element
63
+ // always add to sources (intrinsic or not)
64
+ // if this is not an intrinsic element, we pass the stega encoded value downwards until we hit an intrinsic element
65
+ valSources.add(valPath);
66
+ if (isIntrinsicElement(type)) {
67
+ // clean values before adding them to the props
68
+ // we cannot do this
69
+ var cleanValue = stega.vercelStegaSplit(value).cleaned;
70
+ // we do Object.entries earlier over props so props that are arrays have string keys:
71
+ var numberOfKey = Number(key);
72
+ if (Array.isArray(container) && numberOfKey > -1) {
73
+ container[numberOfKey] = cleanValue;
74
+ } else if (typeof key === "string" && !Array.isArray(container)) {
75
+ container[key] = cleanValue;
76
+ } else {
77
+ console.error("Val: Could not auto tag. Reason: unexpected types found while cleaning and / or adding val path data props.");
78
+ }
64
79
  }
65
- props[attr] = valPath;
66
80
  }
67
81
  }
68
82
  if (props && slicedToArray._typeof(props) === "object") {
@@ -94,8 +108,8 @@ var addValPathIfFound = function addValPathIfFound(type, props) {
94
108
  }
95
109
  }
96
110
  }
97
- if (valSources.length > 0 && !props["data-val-path"]) {
98
- props["data-val-path"] = valSources.join(",");
111
+ if (valSources.size > 0 && !props["data-val-path"]) {
112
+ props["data-val-path"] = Array.from(valSources).join(",");
99
113
  }
100
114
  }
101
115
  };
@@ -193,6 +207,9 @@ function _objectSpread2(e) {
193
207
 
194
208
  function stegaEncode(input, opts) {
195
209
  function rec(sourceOrSelector, recOpts) {
210
+ if (recOpts !== null && recOpts !== void 0 && recOpts.schema && isKeyOfSchema(recOpts === null || recOpts === void 0 ? void 0 : recOpts.schema)) {
211
+ return sourceOrSelector;
212
+ }
196
213
  if (recOpts !== null && recOpts !== void 0 && recOpts.schema && isLiteralSchema(recOpts === null || recOpts === void 0 ? void 0 : recOpts.schema)) {
197
214
  return sourceOrSelector;
198
215
  }
@@ -335,6 +352,9 @@ function unknownSchema(schema) {
335
352
  function isUnionSchema(schema) {
336
353
  return (schema === null || schema === void 0 ? void 0 : schema.type) === "union";
337
354
  }
355
+ function isKeyOfSchema(schema) {
356
+ return (schema === null || schema === void 0 ? void 0 : schema.type) === "keyOf";
357
+ }
338
358
  function isObjectSchema(schema) {
339
359
  return (schema === null || schema === void 0 ? void 0 : schema.type) === "object";
340
360
  }
@@ -391,6 +411,17 @@ function getModuleIds(input) {
391
411
  return Array.from(modules);
392
412
  }
393
413
 
414
+ // NOTE: the exports of this file needs to be kept in sync with ValQuickJSRuntime
415
+ var autoTagJSXEnabled = false;
416
+ function IS_AUTO_TAG_JSX_ENABLED() {
417
+ return autoTagJSXEnabled;
418
+ }
419
+ function SET_AUTO_TAG_JSX_ENABLED(enabled) {
420
+ autoTagJSXEnabled = enabled;
421
+ }
422
+
423
+ exports.IS_AUTO_TAG_JSX_ENABLED = IS_AUTO_TAG_JSX_ENABLED;
424
+ exports.SET_AUTO_TAG_JSX_ENABLED = SET_AUTO_TAG_JSX_ENABLED;
394
425
  exports.autoTagJSX = autoTagJSX;
395
426
  exports.getModuleIds = getModuleIds;
396
427
  exports.stegaClean = stegaClean;
@@ -28,12 +28,19 @@ function stegaDecodeString(encodedString) {
28
28
  }
29
29
  }
30
30
 
31
+ // import { IS_AUTO_TAG_JSX_ENABLED } from ".";
32
+
31
33
  var isIntrinsicElement = function isIntrinsicElement(type) {
32
34
  // TODO: think this is not correct, but good enough for now?
33
35
  return typeof type === "string";
34
36
  };
35
37
  var addValPathIfFound = function addValPathIfFound(type, props) {
36
- var valSources = [];
38
+ // TODO: increases performance. Unsure about the implications right now - seems to work. Remember to look at RSC and client (and pages/?).
39
+ // if (!IS_AUTO_TAG_JSX_ENABLED()) {
40
+ // return;
41
+ // }
42
+
43
+ var valSources = new Set();
37
44
 
38
45
  // skip auto-tagging fragments since we can't add attributes to them
39
46
  if (type === Symbol["for"]("react.fragment")) {
@@ -49,20 +56,27 @@ var addValPathIfFound = function addValPathIfFound(type, props) {
49
56
  return;
50
57
  }
51
58
  var valPath = stegaDecodeString(value);
52
- var attr = "data-val-attr-".concat(key.toString().toLowerCase());
53
- if (valPath && !props[attr]) {
54
- valSources.push(valPath);
55
- var cleanValue = isIntrinsicElement(type) ? stega.vercelStegaSplit(value).cleaned : value;
56
- // we do Object.entries earlier over props so props that are arrays have string keys:
57
- var numberOfKey = Number(key);
58
- if (Array.isArray(container) && numberOfKey > -1) {
59
- container[numberOfKey] = cleanValue;
60
- } else if (typeof key === "string" && !Array.isArray(container)) {
61
- container[key] = cleanValue;
62
- } else {
63
- console.error("Val: Could not auto tag. Reason: unexpected types found while cleaning and / or adding val path data props.");
59
+ if (valPath) {
60
+ // Found val path - this is a stega encoded string
61
+ // The logic below is as follows:
62
+ // if this is an intrinsic element (a, div, etc.), add data attrs will be on the DOM element
63
+ // always add to sources (intrinsic or not)
64
+ // if this is not an intrinsic element, we pass the stega encoded value downwards until we hit an intrinsic element
65
+ valSources.add(valPath);
66
+ if (isIntrinsicElement(type)) {
67
+ // clean values before adding them to the props
68
+ // we cannot do this
69
+ var cleanValue = stega.vercelStegaSplit(value).cleaned;
70
+ // we do Object.entries earlier over props so props that are arrays have string keys:
71
+ var numberOfKey = Number(key);
72
+ if (Array.isArray(container) && numberOfKey > -1) {
73
+ container[numberOfKey] = cleanValue;
74
+ } else if (typeof key === "string" && !Array.isArray(container)) {
75
+ container[key] = cleanValue;
76
+ } else {
77
+ console.error("Val: Could not auto tag. Reason: unexpected types found while cleaning and / or adding val path data props.");
78
+ }
64
79
  }
65
- props[attr] = valPath;
66
80
  }
67
81
  }
68
82
  if (props && slicedToArray._typeof(props) === "object") {
@@ -94,8 +108,8 @@ var addValPathIfFound = function addValPathIfFound(type, props) {
94
108
  }
95
109
  }
96
110
  }
97
- if (valSources.length > 0 && !props["data-val-path"]) {
98
- props["data-val-path"] = valSources.join(",");
111
+ if (valSources.size > 0 && !props["data-val-path"]) {
112
+ props["data-val-path"] = Array.from(valSources).join(",");
99
113
  }
100
114
  }
101
115
  };
@@ -193,6 +207,9 @@ function _objectSpread2(e) {
193
207
 
194
208
  function stegaEncode(input, opts) {
195
209
  function rec(sourceOrSelector, recOpts) {
210
+ if (recOpts !== null && recOpts !== void 0 && recOpts.schema && isKeyOfSchema(recOpts === null || recOpts === void 0 ? void 0 : recOpts.schema)) {
211
+ return sourceOrSelector;
212
+ }
196
213
  if (recOpts !== null && recOpts !== void 0 && recOpts.schema && isLiteralSchema(recOpts === null || recOpts === void 0 ? void 0 : recOpts.schema)) {
197
214
  return sourceOrSelector;
198
215
  }
@@ -335,6 +352,9 @@ function unknownSchema(schema) {
335
352
  function isUnionSchema(schema) {
336
353
  return (schema === null || schema === void 0 ? void 0 : schema.type) === "union";
337
354
  }
355
+ function isKeyOfSchema(schema) {
356
+ return (schema === null || schema === void 0 ? void 0 : schema.type) === "keyOf";
357
+ }
338
358
  function isObjectSchema(schema) {
339
359
  return (schema === null || schema === void 0 ? void 0 : schema.type) === "object";
340
360
  }
@@ -391,6 +411,17 @@ function getModuleIds(input) {
391
411
  return Array.from(modules);
392
412
  }
393
413
 
414
+ // NOTE: the exports of this file needs to be kept in sync with ValQuickJSRuntime
415
+ var autoTagJSXEnabled = false;
416
+ function IS_AUTO_TAG_JSX_ENABLED() {
417
+ return autoTagJSXEnabled;
418
+ }
419
+ function SET_AUTO_TAG_JSX_ENABLED(enabled) {
420
+ autoTagJSXEnabled = enabled;
421
+ }
422
+
423
+ exports.IS_AUTO_TAG_JSX_ENABLED = IS_AUTO_TAG_JSX_ENABLED;
424
+ exports.SET_AUTO_TAG_JSX_ENABLED = SET_AUTO_TAG_JSX_ENABLED;
394
425
  exports.autoTagJSX = autoTagJSX;
395
426
  exports.getModuleIds = getModuleIds;
396
427
  exports.stegaClean = stegaClean;
@@ -18,12 +18,19 @@ function stegaDecodeString(encodedString) {
18
18
  }
19
19
  }
20
20
 
21
+ // import { IS_AUTO_TAG_JSX_ENABLED } from ".";
22
+
21
23
  var isIntrinsicElement = function isIntrinsicElement(type) {
22
24
  // TODO: think this is not correct, but good enough for now?
23
25
  return typeof type === "string";
24
26
  };
25
27
  var addValPathIfFound = function addValPathIfFound(type, props) {
26
- var valSources = [];
28
+ // TODO: increases performance. Unsure about the implications right now - seems to work. Remember to look at RSC and client (and pages/?).
29
+ // if (!IS_AUTO_TAG_JSX_ENABLED()) {
30
+ // return;
31
+ // }
32
+
33
+ var valSources = new Set();
27
34
 
28
35
  // skip auto-tagging fragments since we can't add attributes to them
29
36
  if (type === Symbol["for"]("react.fragment")) {
@@ -39,20 +46,27 @@ var addValPathIfFound = function addValPathIfFound(type, props) {
39
46
  return;
40
47
  }
41
48
  var valPath = stegaDecodeString(value);
42
- var attr = "data-val-attr-".concat(key.toString().toLowerCase());
43
- if (valPath && !props[attr]) {
44
- valSources.push(valPath);
45
- var cleanValue = isIntrinsicElement(type) ? vercelStegaSplit(value).cleaned : value;
46
- // we do Object.entries earlier over props so props that are arrays have string keys:
47
- var numberOfKey = Number(key);
48
- if (Array.isArray(container) && numberOfKey > -1) {
49
- container[numberOfKey] = cleanValue;
50
- } else if (typeof key === "string" && !Array.isArray(container)) {
51
- container[key] = cleanValue;
52
- } else {
53
- console.error("Val: Could not auto tag. Reason: unexpected types found while cleaning and / or adding val path data props.");
49
+ if (valPath) {
50
+ // Found val path - this is a stega encoded string
51
+ // The logic below is as follows:
52
+ // if this is an intrinsic element (a, div, etc.), add data attrs will be on the DOM element
53
+ // always add to sources (intrinsic or not)
54
+ // if this is not an intrinsic element, we pass the stega encoded value downwards until we hit an intrinsic element
55
+ valSources.add(valPath);
56
+ if (isIntrinsicElement(type)) {
57
+ // clean values before adding them to the props
58
+ // we cannot do this
59
+ var cleanValue = vercelStegaSplit(value).cleaned;
60
+ // we do Object.entries earlier over props so props that are arrays have string keys:
61
+ var numberOfKey = Number(key);
62
+ if (Array.isArray(container) && numberOfKey > -1) {
63
+ container[numberOfKey] = cleanValue;
64
+ } else if (typeof key === "string" && !Array.isArray(container)) {
65
+ container[key] = cleanValue;
66
+ } else {
67
+ console.error("Val: Could not auto tag. Reason: unexpected types found while cleaning and / or adding val path data props.");
68
+ }
54
69
  }
55
- props[attr] = valPath;
56
70
  }
57
71
  }
58
72
  if (props && _typeof(props) === "object") {
@@ -84,8 +98,8 @@ var addValPathIfFound = function addValPathIfFound(type, props) {
84
98
  }
85
99
  }
86
100
  }
87
- if (valSources.length > 0 && !props["data-val-path"]) {
88
- props["data-val-path"] = valSources.join(",");
101
+ if (valSources.size > 0 && !props["data-val-path"]) {
102
+ props["data-val-path"] = Array.from(valSources).join(",");
89
103
  }
90
104
  }
91
105
  };
@@ -183,6 +197,9 @@ function _objectSpread2(e) {
183
197
 
184
198
  function stegaEncode(input, opts) {
185
199
  function rec(sourceOrSelector, recOpts) {
200
+ if (recOpts !== null && recOpts !== void 0 && recOpts.schema && isKeyOfSchema(recOpts === null || recOpts === void 0 ? void 0 : recOpts.schema)) {
201
+ return sourceOrSelector;
202
+ }
186
203
  if (recOpts !== null && recOpts !== void 0 && recOpts.schema && isLiteralSchema(recOpts === null || recOpts === void 0 ? void 0 : recOpts.schema)) {
187
204
  return sourceOrSelector;
188
205
  }
@@ -325,6 +342,9 @@ function unknownSchema(schema) {
325
342
  function isUnionSchema(schema) {
326
343
  return (schema === null || schema === void 0 ? void 0 : schema.type) === "union";
327
344
  }
345
+ function isKeyOfSchema(schema) {
346
+ return (schema === null || schema === void 0 ? void 0 : schema.type) === "keyOf";
347
+ }
328
348
  function isObjectSchema(schema) {
329
349
  return (schema === null || schema === void 0 ? void 0 : schema.type) === "object";
330
350
  }
@@ -381,4 +401,13 @@ function getModuleIds(input) {
381
401
  return Array.from(modules);
382
402
  }
383
403
 
384
- export { autoTagJSX, getModuleIds, stegaClean, stegaDecodeString, stegaEncode };
404
+ // NOTE: the exports of this file needs to be kept in sync with ValQuickJSRuntime
405
+ var autoTagJSXEnabled = false;
406
+ function IS_AUTO_TAG_JSX_ENABLED() {
407
+ return autoTagJSXEnabled;
408
+ }
409
+ function SET_AUTO_TAG_JSX_ENABLED(enabled) {
410
+ autoTagJSXEnabled = enabled;
411
+ }
412
+
413
+ export { IS_AUTO_TAG_JSX_ENABLED, SET_AUTO_TAG_JSX_ENABLED, autoTagJSX, getModuleIds, stegaClean, stegaDecodeString, stegaEncode };
@@ -18,12 +18,19 @@ function stegaDecodeString(encodedString) {
18
18
  }
19
19
  }
20
20
 
21
+ // import { IS_AUTO_TAG_JSX_ENABLED } from ".";
22
+
21
23
  var isIntrinsicElement = function isIntrinsicElement(type) {
22
24
  // TODO: think this is not correct, but good enough for now?
23
25
  return typeof type === "string";
24
26
  };
25
27
  var addValPathIfFound = function addValPathIfFound(type, props) {
26
- var valSources = [];
28
+ // TODO: increases performance. Unsure about the implications right now - seems to work. Remember to look at RSC and client (and pages/?).
29
+ // if (!IS_AUTO_TAG_JSX_ENABLED()) {
30
+ // return;
31
+ // }
32
+
33
+ var valSources = new Set();
27
34
 
28
35
  // skip auto-tagging fragments since we can't add attributes to them
29
36
  if (type === Symbol["for"]("react.fragment")) {
@@ -39,20 +46,27 @@ var addValPathIfFound = function addValPathIfFound(type, props) {
39
46
  return;
40
47
  }
41
48
  var valPath = stegaDecodeString(value);
42
- var attr = "data-val-attr-".concat(key.toString().toLowerCase());
43
- if (valPath && !props[attr]) {
44
- valSources.push(valPath);
45
- var cleanValue = isIntrinsicElement(type) ? vercelStegaSplit(value).cleaned : value;
46
- // we do Object.entries earlier over props so props that are arrays have string keys:
47
- var numberOfKey = Number(key);
48
- if (Array.isArray(container) && numberOfKey > -1) {
49
- container[numberOfKey] = cleanValue;
50
- } else if (typeof key === "string" && !Array.isArray(container)) {
51
- container[key] = cleanValue;
52
- } else {
53
- console.error("Val: Could not auto tag. Reason: unexpected types found while cleaning and / or adding val path data props.");
49
+ if (valPath) {
50
+ // Found val path - this is a stega encoded string
51
+ // The logic below is as follows:
52
+ // if this is an intrinsic element (a, div, etc.), add data attrs will be on the DOM element
53
+ // always add to sources (intrinsic or not)
54
+ // if this is not an intrinsic element, we pass the stega encoded value downwards until we hit an intrinsic element
55
+ valSources.add(valPath);
56
+ if (isIntrinsicElement(type)) {
57
+ // clean values before adding them to the props
58
+ // we cannot do this
59
+ var cleanValue = vercelStegaSplit(value).cleaned;
60
+ // we do Object.entries earlier over props so props that are arrays have string keys:
61
+ var numberOfKey = Number(key);
62
+ if (Array.isArray(container) && numberOfKey > -1) {
63
+ container[numberOfKey] = cleanValue;
64
+ } else if (typeof key === "string" && !Array.isArray(container)) {
65
+ container[key] = cleanValue;
66
+ } else {
67
+ console.error("Val: Could not auto tag. Reason: unexpected types found while cleaning and / or adding val path data props.");
68
+ }
54
69
  }
55
- props[attr] = valPath;
56
70
  }
57
71
  }
58
72
  if (props && _typeof(props) === "object") {
@@ -84,8 +98,8 @@ var addValPathIfFound = function addValPathIfFound(type, props) {
84
98
  }
85
99
  }
86
100
  }
87
- if (valSources.length > 0 && !props["data-val-path"]) {
88
- props["data-val-path"] = valSources.join(",");
101
+ if (valSources.size > 0 && !props["data-val-path"]) {
102
+ props["data-val-path"] = Array.from(valSources).join(",");
89
103
  }
90
104
  }
91
105
  };
@@ -183,6 +197,9 @@ function _objectSpread2(e) {
183
197
 
184
198
  function stegaEncode(input, opts) {
185
199
  function rec(sourceOrSelector, recOpts) {
200
+ if (recOpts !== null && recOpts !== void 0 && recOpts.schema && isKeyOfSchema(recOpts === null || recOpts === void 0 ? void 0 : recOpts.schema)) {
201
+ return sourceOrSelector;
202
+ }
186
203
  if (recOpts !== null && recOpts !== void 0 && recOpts.schema && isLiteralSchema(recOpts === null || recOpts === void 0 ? void 0 : recOpts.schema)) {
187
204
  return sourceOrSelector;
188
205
  }
@@ -325,6 +342,9 @@ function unknownSchema(schema) {
325
342
  function isUnionSchema(schema) {
326
343
  return (schema === null || schema === void 0 ? void 0 : schema.type) === "union";
327
344
  }
345
+ function isKeyOfSchema(schema) {
346
+ return (schema === null || schema === void 0 ? void 0 : schema.type) === "keyOf";
347
+ }
328
348
  function isObjectSchema(schema) {
329
349
  return (schema === null || schema === void 0 ? void 0 : schema.type) === "object";
330
350
  }
@@ -381,4 +401,13 @@ function getModuleIds(input) {
381
401
  return Array.from(modules);
382
402
  }
383
403
 
384
- export { autoTagJSX, getModuleIds, stegaClean, stegaDecodeString, stegaEncode };
404
+ // NOTE: the exports of this file needs to be kept in sync with ValQuickJSRuntime
405
+ var autoTagJSXEnabled = false;
406
+ function IS_AUTO_TAG_JSX_ENABLED() {
407
+ return autoTagJSXEnabled;
408
+ }
409
+ function SET_AUTO_TAG_JSX_ENABLED(enabled) {
410
+ autoTagJSXEnabled = enabled;
411
+ }
412
+
413
+ export { IS_AUTO_TAG_JSX_ENABLED, SET_AUTO_TAG_JSX_ENABLED, autoTagJSX, getModuleIds, stegaClean, stegaDecodeString, stegaEncode };