@valbuild/react 0.62.3 → 0.62.5

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.3",
3
+ "version": "0.62.5",
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.3",
13
- "@valbuild/shared": "~0.62.3",
14
- "@valbuild/ui": "~0.62.3",
12
+ "@valbuild/core": "~0.62.5",
13
+ "@valbuild/shared": "~0.62.5",
14
+ "@valbuild/ui": "~0.62.5",
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
  };
@@ -381,4 +395,13 @@ function getModuleIds(input) {
381
395
  return Array.from(modules);
382
396
  }
383
397
 
384
- export { autoTagJSX, getModuleIds, stegaClean, stegaDecodeString, stegaEncode };
398
+ // NOTE: the exports of this file needs to be kept in sync with ValQuickJSRuntime
399
+ var autoTagJSXEnabled = false;
400
+ function IS_AUTO_TAG_JSX_ENABLED() {
401
+ return autoTagJSXEnabled;
402
+ }
403
+ function SET_AUTO_TAG_JSX_ENABLED(enabled) {
404
+ autoTagJSXEnabled = enabled;
405
+ }
406
+
407
+ 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
  };
@@ -391,6 +405,17 @@ function getModuleIds(input) {
391
405
  return Array.from(modules);
392
406
  }
393
407
 
408
+ // NOTE: the exports of this file needs to be kept in sync with ValQuickJSRuntime
409
+ var autoTagJSXEnabled = false;
410
+ function IS_AUTO_TAG_JSX_ENABLED() {
411
+ return autoTagJSXEnabled;
412
+ }
413
+ function SET_AUTO_TAG_JSX_ENABLED(enabled) {
414
+ autoTagJSXEnabled = enabled;
415
+ }
416
+
417
+ exports.IS_AUTO_TAG_JSX_ENABLED = IS_AUTO_TAG_JSX_ENABLED;
418
+ exports.SET_AUTO_TAG_JSX_ENABLED = SET_AUTO_TAG_JSX_ENABLED;
394
419
  exports.autoTagJSX = autoTagJSX;
395
420
  exports.getModuleIds = getModuleIds;
396
421
  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
  };
@@ -391,6 +405,17 @@ function getModuleIds(input) {
391
405
  return Array.from(modules);
392
406
  }
393
407
 
408
+ // NOTE: the exports of this file needs to be kept in sync with ValQuickJSRuntime
409
+ var autoTagJSXEnabled = false;
410
+ function IS_AUTO_TAG_JSX_ENABLED() {
411
+ return autoTagJSXEnabled;
412
+ }
413
+ function SET_AUTO_TAG_JSX_ENABLED(enabled) {
414
+ autoTagJSXEnabled = enabled;
415
+ }
416
+
417
+ exports.IS_AUTO_TAG_JSX_ENABLED = IS_AUTO_TAG_JSX_ENABLED;
418
+ exports.SET_AUTO_TAG_JSX_ENABLED = SET_AUTO_TAG_JSX_ENABLED;
394
419
  exports.autoTagJSX = autoTagJSX;
395
420
  exports.getModuleIds = getModuleIds;
396
421
  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
  };
@@ -381,4 +395,13 @@ function getModuleIds(input) {
381
395
  return Array.from(modules);
382
396
  }
383
397
 
384
- export { autoTagJSX, getModuleIds, stegaClean, stegaDecodeString, stegaEncode };
398
+ // NOTE: the exports of this file needs to be kept in sync with ValQuickJSRuntime
399
+ var autoTagJSXEnabled = false;
400
+ function IS_AUTO_TAG_JSX_ENABLED() {
401
+ return autoTagJSXEnabled;
402
+ }
403
+ function SET_AUTO_TAG_JSX_ENABLED(enabled) {
404
+ autoTagJSXEnabled = enabled;
405
+ }
406
+
407
+ 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
  };
@@ -381,4 +395,13 @@ function getModuleIds(input) {
381
395
  return Array.from(modules);
382
396
  }
383
397
 
384
- export { autoTagJSX, getModuleIds, stegaClean, stegaDecodeString, stegaEncode };
398
+ // NOTE: the exports of this file needs to be kept in sync with ValQuickJSRuntime
399
+ var autoTagJSXEnabled = false;
400
+ function IS_AUTO_TAG_JSX_ENABLED() {
401
+ return autoTagJSXEnabled;
402
+ }
403
+ function SET_AUTO_TAG_JSX_ENABLED(enabled) {
404
+ autoTagJSXEnabled = enabled;
405
+ }
406
+
407
+ export { IS_AUTO_TAG_JSX_ENABLED, SET_AUTO_TAG_JSX_ENABLED, autoTagJSX, getModuleIds, stegaClean, stegaDecodeString, stegaEncode };