@valbuild/next 0.44.0 → 0.46.0

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.
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ import NextImage from "next/image";
3
+ import { Image } from "@valbuild/react/stega";
4
+ export type ValImageProps = Omit<React.ComponentProps<typeof NextImage>, "src" | "srcset" | "layout" | "objectFit" | "objectPosition" | "lazyBoundary" | "lazyRoot"> & {
5
+ src: Image;
6
+ disableHotspot?: boolean;
7
+ };
8
+ export declare function ValImage(props: ValImageProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,2 @@
1
+ import { ValEncodedString } from "@valbuild/react/stega";
2
+ export declare function decodeValPathOfString(encodedString: ValEncodedString): string | undefined;
@@ -13,8 +13,9 @@ export { VAL_EXTENSION, type SourceArray } from "@valbuild/core";
13
13
  export { derefPatch } from "@valbuild/core";
14
14
  export { type SelectorSource, type SelectorOf, GenericSelector, } from "@valbuild/core";
15
15
  export { ValRichText } from "@valbuild/react/internal";
16
- export { type ValEncodedString } from "@valbuild/react/stega";
16
+ export { type ValEncodedString, type Image } from "@valbuild/react/stega";
17
17
  export { ValProvider } from "./ValProvider.js";
18
+ export { ValImage, type ValImageProps } from "./ValImage.js";
18
19
  export { initVal } from "./initVal.js";
19
20
  import type { UseValType } from "./client/initValClient.js";
20
21
  import { Schema, SelectorSource } from "@valbuild/core";
@@ -1,7 +1,9 @@
1
1
  import { type ValConfig, type InitVal, type ValConstructor } from "@valbuild/core";
2
- import { ValEncodedString } from "@valbuild/react/stega";
2
+ import { raw } from "./raw.js";
3
+ import { decodeValPathOfString } from "./decodeValPathOfString.js";
3
4
  export declare const initVal: (config?: ValConfig) => InitVal & {
4
5
  val: ValConstructor & {
5
- raw: (encodedString: ValEncodedString) => string;
6
+ raw: typeof raw;
7
+ decodeValPathOfString: typeof decodeValPathOfString;
6
8
  };
7
9
  };
@@ -0,0 +1,2 @@
1
+ import { ValEncodedString } from "@valbuild/react/stega";
2
+ export declare function raw(encodedString: ValEncodedString): string;
@@ -5,7 +5,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var core = require('@valbuild/core');
6
6
  var internal = require('@valbuild/react/internal');
7
7
  var ValNextProvider = require('./ValNextProvider-49d2bec1.cjs.dev.js');
8
+ var NextImage = require('next/image');
8
9
  var stega = require('@valbuild/react/stega');
10
+ var jsxRuntime = require('react/jsx-runtime');
11
+
12
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
9
13
 
10
14
  function _interopNamespace(e) {
11
15
  if (e && e.__esModule) return e;
@@ -26,6 +30,7 @@ function _interopNamespace(e) {
26
30
  }
27
31
 
28
32
  var core__namespace = /*#__PURE__*/_interopNamespace(core);
33
+ var NextImage__default = /*#__PURE__*/_interopDefault(NextImage);
29
34
 
30
35
  var ValProvider = ValNextProvider.ValNextProvider;
31
36
 
@@ -82,6 +87,83 @@ function _objectSpread2(e) {
82
87
  return e;
83
88
  }
84
89
 
90
+ function _objectWithoutPropertiesLoose(source, excluded) {
91
+ if (source == null) return {};
92
+ var target = {};
93
+ var sourceKeys = Object.keys(source);
94
+ var key, i;
95
+ for (i = 0; i < sourceKeys.length; i++) {
96
+ key = sourceKeys[i];
97
+ if (excluded.indexOf(key) >= 0) continue;
98
+ target[key] = source[key];
99
+ }
100
+ return target;
101
+ }
102
+
103
+ function _objectWithoutProperties(source, excluded) {
104
+ if (source == null) return {};
105
+ var target = _objectWithoutPropertiesLoose(source, excluded);
106
+ var key, i;
107
+ if (Object.getOwnPropertySymbols) {
108
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
109
+ for (i = 0; i < sourceSymbolKeys.length; i++) {
110
+ key = sourceSymbolKeys[i];
111
+ if (excluded.indexOf(key) >= 0) continue;
112
+ if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
113
+ target[key] = source[key];
114
+ }
115
+ }
116
+ return target;
117
+ }
118
+
119
+ function raw(encodedString) {
120
+ return stega.stegaClean(encodedString);
121
+ }
122
+
123
+ function decodeValPathOfString(encodedString) {
124
+ return stega.stegaDecodeString(encodedString);
125
+ }
126
+
127
+ var _excluded = ["src", "alt", "style", "width", "disableHotspot", "height"];
128
+ function ValImage(props) {
129
+ var _src$metadata, _src$metadata2, _src$metadata3;
130
+ var src = props.src,
131
+ alt = props.alt,
132
+ style = props.style,
133
+ width = props.width,
134
+ disableHotspot = props.disableHotspot,
135
+ height = props.height,
136
+ rest = _objectWithoutProperties(props, _excluded);
137
+ var valPathOfUrl = decodeValPathOfString(src.url);
138
+ var valPaths = [valPathOfUrl];
139
+ var maybeValPathOfAlt = decodeValPathOfString(alt);
140
+ if (maybeValPathOfAlt) {
141
+ valPaths.push(maybeValPathOfAlt);
142
+ }
143
+ var hotspot = (_src$metadata = src.metadata) === null || _src$metadata === void 0 ? void 0 : _src$metadata.hotspot;
144
+ var imageStyle = hotspot && !disableHotspot ? _objectSpread2(_objectSpread2({}, style), {}, {
145
+ objectPosition: "".concat(hotspot.x * 100, "% ").concat(hotspot.y * 100, "%")
146
+ }) : style;
147
+ var useMetadataDimensions = src.metadata !== undefined && !rest.fill && !width && !height;
148
+ return /*#__PURE__*/jsxRuntime.jsx(NextImage__default["default"], _objectSpread2(_objectSpread2({}, _objectSpread2(_objectSpread2({}, rest), {}, {
149
+ layout: undefined,
150
+ objectFit: undefined,
151
+ objectPosition: undefined,
152
+ lazyBoundary: undefined,
153
+ lazyRoot: undefined
154
+ })), {}, {
155
+ src: valPathOfUrl ? raw(src.url) : src.url,
156
+ "data-val-path": valPaths.join(","),
157
+ "data-val-attr-alt": maybeValPathOfAlt,
158
+ "data-val-attr-src": valPathOfUrl,
159
+ style: imageStyle,
160
+ alt: raw(alt),
161
+ fill: rest.fill,
162
+ width: useMetadataDimensions ? (_src$metadata2 = src.metadata) === null || _src$metadata2 === void 0 ? void 0 : _src$metadata2.width : width,
163
+ height: useMetadataDimensions ? (_src$metadata3 = src.metadata) === null || _src$metadata3 === void 0 ? void 0 : _src$metadata3.height : height
164
+ }));
165
+ }
166
+
85
167
  var initVal = function initVal(config) {
86
168
  var _createValSystem = core.initVal(),
87
169
  s = _createValSystem.s,
@@ -93,9 +175,8 @@ var initVal = function initVal(config) {
93
175
  return {
94
176
  s: s,
95
177
  val: _objectSpread2(_objectSpread2({}, val), {}, {
96
- raw: function raw(encodedString) {
97
- return stega.stegaClean(encodedString);
98
- }
178
+ decodeValPathOfString: decodeValPathOfString,
179
+ raw: raw
99
180
  }),
100
181
  config: currentConfig
101
182
  };
@@ -133,5 +214,6 @@ Object.defineProperty(exports, 'ValRichText', {
133
214
  enumerable: true,
134
215
  get: function () { return internal.ValRichText; }
135
216
  });
217
+ exports.ValImage = ValImage;
136
218
  exports.ValProvider = ValProvider;
137
219
  exports.initVal = initVal;
@@ -5,7 +5,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var core = require('@valbuild/core');
6
6
  var internal = require('@valbuild/react/internal');
7
7
  var ValNextProvider = require('./ValNextProvider-7750e412.cjs.prod.js');
8
+ var NextImage = require('next/image');
8
9
  var stega = require('@valbuild/react/stega');
10
+ var jsxRuntime = require('react/jsx-runtime');
11
+
12
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
9
13
 
10
14
  function _interopNamespace(e) {
11
15
  if (e && e.__esModule) return e;
@@ -26,6 +30,7 @@ function _interopNamespace(e) {
26
30
  }
27
31
 
28
32
  var core__namespace = /*#__PURE__*/_interopNamespace(core);
33
+ var NextImage__default = /*#__PURE__*/_interopDefault(NextImage);
29
34
 
30
35
  var ValProvider = ValNextProvider.ValNextProvider;
31
36
 
@@ -82,6 +87,83 @@ function _objectSpread2(e) {
82
87
  return e;
83
88
  }
84
89
 
90
+ function _objectWithoutPropertiesLoose(source, excluded) {
91
+ if (source == null) return {};
92
+ var target = {};
93
+ var sourceKeys = Object.keys(source);
94
+ var key, i;
95
+ for (i = 0; i < sourceKeys.length; i++) {
96
+ key = sourceKeys[i];
97
+ if (excluded.indexOf(key) >= 0) continue;
98
+ target[key] = source[key];
99
+ }
100
+ return target;
101
+ }
102
+
103
+ function _objectWithoutProperties(source, excluded) {
104
+ if (source == null) return {};
105
+ var target = _objectWithoutPropertiesLoose(source, excluded);
106
+ var key, i;
107
+ if (Object.getOwnPropertySymbols) {
108
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
109
+ for (i = 0; i < sourceSymbolKeys.length; i++) {
110
+ key = sourceSymbolKeys[i];
111
+ if (excluded.indexOf(key) >= 0) continue;
112
+ if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
113
+ target[key] = source[key];
114
+ }
115
+ }
116
+ return target;
117
+ }
118
+
119
+ function raw(encodedString) {
120
+ return stega.stegaClean(encodedString);
121
+ }
122
+
123
+ function decodeValPathOfString(encodedString) {
124
+ return stega.stegaDecodeString(encodedString);
125
+ }
126
+
127
+ var _excluded = ["src", "alt", "style", "width", "disableHotspot", "height"];
128
+ function ValImage(props) {
129
+ var _src$metadata, _src$metadata2, _src$metadata3;
130
+ var src = props.src,
131
+ alt = props.alt,
132
+ style = props.style,
133
+ width = props.width,
134
+ disableHotspot = props.disableHotspot,
135
+ height = props.height,
136
+ rest = _objectWithoutProperties(props, _excluded);
137
+ var valPathOfUrl = decodeValPathOfString(src.url);
138
+ var valPaths = [valPathOfUrl];
139
+ var maybeValPathOfAlt = decodeValPathOfString(alt);
140
+ if (maybeValPathOfAlt) {
141
+ valPaths.push(maybeValPathOfAlt);
142
+ }
143
+ var hotspot = (_src$metadata = src.metadata) === null || _src$metadata === void 0 ? void 0 : _src$metadata.hotspot;
144
+ var imageStyle = hotspot && !disableHotspot ? _objectSpread2(_objectSpread2({}, style), {}, {
145
+ objectPosition: "".concat(hotspot.x * 100, "% ").concat(hotspot.y * 100, "%")
146
+ }) : style;
147
+ var useMetadataDimensions = src.metadata !== undefined && !rest.fill && !width && !height;
148
+ return /*#__PURE__*/jsxRuntime.jsx(NextImage__default["default"], _objectSpread2(_objectSpread2({}, _objectSpread2(_objectSpread2({}, rest), {}, {
149
+ layout: undefined,
150
+ objectFit: undefined,
151
+ objectPosition: undefined,
152
+ lazyBoundary: undefined,
153
+ lazyRoot: undefined
154
+ })), {}, {
155
+ src: valPathOfUrl ? raw(src.url) : src.url,
156
+ "data-val-path": valPaths.join(","),
157
+ "data-val-attr-alt": maybeValPathOfAlt,
158
+ "data-val-attr-src": valPathOfUrl,
159
+ style: imageStyle,
160
+ alt: raw(alt),
161
+ fill: rest.fill,
162
+ width: useMetadataDimensions ? (_src$metadata2 = src.metadata) === null || _src$metadata2 === void 0 ? void 0 : _src$metadata2.width : width,
163
+ height: useMetadataDimensions ? (_src$metadata3 = src.metadata) === null || _src$metadata3 === void 0 ? void 0 : _src$metadata3.height : height
164
+ }));
165
+ }
166
+
85
167
  var initVal = function initVal(config) {
86
168
  var _createValSystem = core.initVal(),
87
169
  s = _createValSystem.s,
@@ -93,9 +175,8 @@ var initVal = function initVal(config) {
93
175
  return {
94
176
  s: s,
95
177
  val: _objectSpread2(_objectSpread2({}, val), {}, {
96
- raw: function raw(encodedString) {
97
- return stega.stegaClean(encodedString);
98
- }
178
+ decodeValPathOfString: decodeValPathOfString,
179
+ raw: raw
99
180
  }),
100
181
  config: currentConfig
101
182
  };
@@ -133,5 +214,6 @@ Object.defineProperty(exports, 'ValRichText', {
133
214
  enumerable: true,
134
215
  get: function () { return internal.ValRichText; }
135
216
  });
217
+ exports.ValImage = ValImage;
136
218
  exports.ValProvider = ValProvider;
137
219
  exports.initVal = initVal;
@@ -4,7 +4,9 @@ export { core as expr };
4
4
  export { FILE_REF_PROP, GenericSelector, Schema, VAL_EXTENSION, derefPatch } from '@valbuild/core';
5
5
  export { ValRichText } from '@valbuild/react/internal';
6
6
  import { ValNextProvider } from './ValNextProvider-c5c9fcb0.esm.js';
7
- import { stegaClean, autoTagJSX } from '@valbuild/react/stega';
7
+ import NextImage from 'next/image';
8
+ import { stegaClean, stegaDecodeString, autoTagJSX } from '@valbuild/react/stega';
9
+ import { jsx } from 'react/jsx-runtime';
8
10
 
9
11
  var ValProvider = ValNextProvider;
10
12
 
@@ -61,6 +63,83 @@ function _objectSpread2(e) {
61
63
  return e;
62
64
  }
63
65
 
66
+ function _objectWithoutPropertiesLoose(source, excluded) {
67
+ if (source == null) return {};
68
+ var target = {};
69
+ var sourceKeys = Object.keys(source);
70
+ var key, i;
71
+ for (i = 0; i < sourceKeys.length; i++) {
72
+ key = sourceKeys[i];
73
+ if (excluded.indexOf(key) >= 0) continue;
74
+ target[key] = source[key];
75
+ }
76
+ return target;
77
+ }
78
+
79
+ function _objectWithoutProperties(source, excluded) {
80
+ if (source == null) return {};
81
+ var target = _objectWithoutPropertiesLoose(source, excluded);
82
+ var key, i;
83
+ if (Object.getOwnPropertySymbols) {
84
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
85
+ for (i = 0; i < sourceSymbolKeys.length; i++) {
86
+ key = sourceSymbolKeys[i];
87
+ if (excluded.indexOf(key) >= 0) continue;
88
+ if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
89
+ target[key] = source[key];
90
+ }
91
+ }
92
+ return target;
93
+ }
94
+
95
+ function raw(encodedString) {
96
+ return stegaClean(encodedString);
97
+ }
98
+
99
+ function decodeValPathOfString(encodedString) {
100
+ return stegaDecodeString(encodedString);
101
+ }
102
+
103
+ var _excluded = ["src", "alt", "style", "width", "disableHotspot", "height"];
104
+ function ValImage(props) {
105
+ var _src$metadata, _src$metadata2, _src$metadata3;
106
+ var src = props.src,
107
+ alt = props.alt,
108
+ style = props.style,
109
+ width = props.width,
110
+ disableHotspot = props.disableHotspot,
111
+ height = props.height,
112
+ rest = _objectWithoutProperties(props, _excluded);
113
+ var valPathOfUrl = decodeValPathOfString(src.url);
114
+ var valPaths = [valPathOfUrl];
115
+ var maybeValPathOfAlt = decodeValPathOfString(alt);
116
+ if (maybeValPathOfAlt) {
117
+ valPaths.push(maybeValPathOfAlt);
118
+ }
119
+ var hotspot = (_src$metadata = src.metadata) === null || _src$metadata === void 0 ? void 0 : _src$metadata.hotspot;
120
+ var imageStyle = hotspot && !disableHotspot ? _objectSpread2(_objectSpread2({}, style), {}, {
121
+ objectPosition: "".concat(hotspot.x * 100, "% ").concat(hotspot.y * 100, "%")
122
+ }) : style;
123
+ var useMetadataDimensions = src.metadata !== undefined && !rest.fill && !width && !height;
124
+ return /*#__PURE__*/jsx(NextImage, _objectSpread2(_objectSpread2({}, _objectSpread2(_objectSpread2({}, rest), {}, {
125
+ layout: undefined,
126
+ objectFit: undefined,
127
+ objectPosition: undefined,
128
+ lazyBoundary: undefined,
129
+ lazyRoot: undefined
130
+ })), {}, {
131
+ src: valPathOfUrl ? raw(src.url) : src.url,
132
+ "data-val-path": valPaths.join(","),
133
+ "data-val-attr-alt": maybeValPathOfAlt,
134
+ "data-val-attr-src": valPathOfUrl,
135
+ style: imageStyle,
136
+ alt: raw(alt),
137
+ fill: rest.fill,
138
+ width: useMetadataDimensions ? (_src$metadata2 = src.metadata) === null || _src$metadata2 === void 0 ? void 0 : _src$metadata2.width : width,
139
+ height: useMetadataDimensions ? (_src$metadata3 = src.metadata) === null || _src$metadata3 === void 0 ? void 0 : _src$metadata3.height : height
140
+ }));
141
+ }
142
+
64
143
  var initVal = function initVal(config) {
65
144
  var _createValSystem = initVal$1(),
66
145
  s = _createValSystem.s,
@@ -72,9 +151,8 @@ var initVal = function initVal(config) {
72
151
  return {
73
152
  s: s,
74
153
  val: _objectSpread2(_objectSpread2({}, val), {}, {
75
- raw: function raw(encodedString) {
76
- return stegaClean(encodedString);
77
- }
154
+ decodeValPathOfString: decodeValPathOfString,
155
+ raw: raw
78
156
  }),
79
157
  config: currentConfig
80
158
  };
@@ -87,4 +165,4 @@ autoTagJSX();
87
165
 
88
166
  // Convenience types
89
167
 
90
- export { ValProvider, initVal };
168
+ export { ValImage, ValProvider, initVal };
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "next",
9
9
  "react"
10
10
  ],
11
- "version": "0.44.0",
11
+ "version": "0.46.0",
12
12
  "scripts": {
13
13
  "typecheck": "tsc --noEmit",
14
14
  "test": "jest"
@@ -45,9 +45,9 @@
45
45
  "exports": true
46
46
  },
47
47
  "dependencies": {
48
- "@valbuild/core": "~0.44.0",
49
- "@valbuild/react": "~0.44.0",
50
- "@valbuild/server": "~0.44.0",
48
+ "@valbuild/core": "~0.46.0",
49
+ "@valbuild/react": "~0.46.0",
50
+ "@valbuild/server": "~0.46.0",
51
51
  "client-only": "^0.0.1",
52
52
  "server-only": "^0.0.1"
53
53
  },