@valbuild/next 0.63.5 → 0.65.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.
Files changed (64) hide show
  1. package/README.md +42 -97
  2. package/client/dist/valbuild-next-client.cjs.d.ts +2 -2
  3. package/client/dist/valbuild-next-client.cjs.dev.js +19 -31
  4. package/client/dist/valbuild-next-client.cjs.prod.js +19 -31
  5. package/client/dist/valbuild-next-client.esm.js +19 -31
  6. package/dist/ValApp-50ec1e10.esm.js +53 -0
  7. package/dist/ValApp-9eefeefd.cjs.js +7 -0
  8. package/dist/ValApp-9eefeefd.cjs.prod.js +61 -0
  9. package/dist/ValApp-de156df4.cjs.dev.js +61 -0
  10. package/dist/ValNextProvider-0b711372.esm.js +430 -0
  11. package/dist/ValNextProvider-313af7bb.cjs.js +7 -0
  12. package/dist/ValNextProvider-313af7bb.cjs.prod.js +439 -0
  13. package/dist/ValNextProvider-abfbfdb5.cjs.dev.js +439 -0
  14. package/dist/{ValContext-06fe6f7e.cjs.dev.js → ValOverlayContext-55dae3ea.cjs.dev.js} +62 -71
  15. package/dist/ValOverlayContext-811e9be9.cjs.js +7 -0
  16. package/dist/{ValContext-12a3eca2.cjs.prod.js → ValOverlayContext-811e9be9.cjs.prod.js} +62 -71
  17. package/dist/{ValContext-8a8d9183.esm.js → ValOverlayContext-a2fdbce0.esm.js} +59 -69
  18. package/dist/{asyncToGenerator-0859ab5c.esm.js → asyncToGenerator-5f8c02f3.esm.js} +19 -24
  19. package/dist/{asyncToGenerator-ba66657c.cjs.dev.js → asyncToGenerator-67a5ff70.cjs.prod.js} +19 -24
  20. package/dist/{asyncToGenerator-3551d940.cjs.prod.js → asyncToGenerator-6ba61221.cjs.dev.js} +19 -24
  21. package/dist/declarations/src/ValApp.d.ts +1 -1
  22. package/dist/declarations/src/ValImage.d.ts +0 -1
  23. package/dist/declarations/src/ValProvider.d.ts +3 -5
  24. package/dist/declarations/src/external_exempt_from_val_quickjs.d.ts +38 -2
  25. package/dist/declarations/src/rsc/initValRsc.d.ts +5 -5
  26. package/dist/declarations/src/server/initValServer.d.ts +1 -1
  27. package/dist/{objectSpread2-bb9509e8.cjs.dev.js → objectSpread2-3c87fb4f.cjs.prod.js} +12 -18
  28. package/dist/{objectSpread2-24e737a6.cjs.prod.js → objectSpread2-792eb2c2.cjs.dev.js} +12 -18
  29. package/dist/{objectSpread2-439bdcdd.esm.js → objectSpread2-c1340c1c.esm.js} +12 -18
  30. package/dist/{slicedToArray-c03b6356.cjs.dev.js → slicedToArray-44036a76.cjs.dev.js} +5 -5
  31. package/dist/{slicedToArray-1ff80c5e.esm.js → slicedToArray-aa291011.esm.js} +5 -5
  32. package/dist/{slicedToArray-1d91551a.cjs.prod.js → slicedToArray-ce613de6.cjs.prod.js} +5 -5
  33. package/dist/unsupportedIterableToArray-0d2087a2.cjs.prod.js +17 -0
  34. package/dist/unsupportedIterableToArray-5baabfdc.esm.js +15 -0
  35. package/dist/unsupportedIterableToArray-c8ab77c9.cjs.dev.js +17 -0
  36. package/dist/valbuild-next.cjs.d.ts +2 -2
  37. package/dist/valbuild-next.cjs.dev.js +23 -28
  38. package/dist/valbuild-next.cjs.prod.js +23 -28
  39. package/dist/valbuild-next.esm.js +23 -28
  40. package/package.json +6 -5
  41. package/rsc/dist/valbuild-next-rsc.cjs.d.ts +2 -2
  42. package/rsc/dist/valbuild-next-rsc.cjs.dev.js +131 -46
  43. package/rsc/dist/valbuild-next-rsc.cjs.prod.js +131 -43
  44. package/rsc/dist/valbuild-next-rsc.esm.js +133 -48
  45. package/server/dist/valbuild-next-server.cjs.d.ts +2 -2
  46. package/server/dist/valbuild-next-server.cjs.dev.js +8 -8
  47. package/server/dist/valbuild-next-server.cjs.prod.js +8 -8
  48. package/server/dist/valbuild-next-server.esm.js +8 -8
  49. package/client/dist/valbuild-next-client.cjs.d.ts.map +0 -1
  50. package/dist/ValApp-0ec0c7f3.cjs.js +0 -7
  51. package/dist/ValApp-0ec0c7f3.cjs.prod.js +0 -34
  52. package/dist/ValApp-61103149.esm.js +0 -26
  53. package/dist/ValApp-aff60572.cjs.dev.js +0 -34
  54. package/dist/ValContext-12a3eca2.cjs.js +0 -7
  55. package/dist/ValNextProvider-5226c452.cjs.js +0 -7
  56. package/dist/ValNextProvider-5226c452.cjs.prod.js +0 -101
  57. package/dist/ValNextProvider-ccbea1bd.cjs.dev.js +0 -101
  58. package/dist/ValNextProvider-d94cd904.esm.js +0 -92
  59. package/dist/unsupportedIterableToArray-51bb61c2.esm.js +0 -16
  60. package/dist/unsupportedIterableToArray-9e97e24a.cjs.dev.js +0 -18
  61. package/dist/unsupportedIterableToArray-afbea1dd.cjs.prod.js +0 -18
  62. package/dist/valbuild-next.cjs.d.ts.map +0 -1
  63. package/rsc/dist/valbuild-next-rsc.cjs.d.ts.map +0 -1
  64. package/server/dist/valbuild-next-server.cjs.d.ts.map +0 -1
package/README.md CHANGED
@@ -40,13 +40,10 @@
40
40
 
41
41
  # 🐉 HERE BE DRAGONS 🐉
42
42
 
43
- Val is PRE-ALPHA - MOST features are broken and in state of flux.
44
-
45
- This is release is only for **INTERNAL** **TESTING** PURPOSES.
43
+ This version of Val is currently an alpha version - the API can be considered relatively stable, but expect some features to be broken and the UX to be changing.
46
44
 
47
45
  ## Table of contents
48
46
 
49
- - [Introduction](#introduction)
50
47
  - [Installation](#installation)
51
48
  - [Getting started](#getting-started)
52
49
  - [Schema types](#schema-types):
@@ -61,88 +58,6 @@ This is release is only for **INTERNAL** **TESTING** PURPOSES.
61
58
  - [Image](#image)
62
59
  - [keyOf](#keyof)
63
60
 
64
- ## Content as code
65
-
66
- Val is a CMS library where **content** is **TypeScript** / **JavaScript** files stored in your git repo.
67
-
68
- As a CMS, Val is useful because:
69
-
70
- - editors can **change content** without having to ask developers to do it for them (and nobody wants that)
71
- - a **well-documented** way to **structure content**
72
- - **image** support is built-in
73
- - **richtext** support is built-in
74
- - built-in **visual editing** which lets editors click-then-edit content (and therefore **code**!) directly in your app
75
-
76
- ![Visual editing](https://val.build/docs/images/overlay.png)
77
-
78
- <details>
79
- <summary>Definition: editor</summary>
80
- An editor in this context, is a non-technical person that edits content in your application (technical writer, proof-reader, legal, ...).
81
- </details>
82
-
83
- <br />
84
-
85
- But, with the benefits of **hard-coded** content:
86
-
87
- - works seamlessly **locally** or with git **branches**
88
- - content is **type-checked** so you can spend less time on figuring out why something isn't working
89
- ![Type check error](https://val.build/docs/images/type-check-error.png)
90
- - content can be refactored (change names, etc) just as if it was hard-coded (because it is)
91
- ![Renaming](https://val.build/docs/images/renaming.gif)
92
- - works as normal with your **favorite IDE** without any plugins: search for content, references to usages, ...
93
- ![References](https://val.build/docs/images/references.gif)
94
- - **no** need for **code-gen** and extra build steps
95
- - **fast** since the content is literally hosted with the application
96
- - content is **always there** and can never fail (since it is not loaded from somewhere)
97
- - no need to manage different **environments** containing different versions of content
98
- - **resolve conflicts** like you normally resolve conflicts: **in git**
99
-
100
- Compared to other CMSs, Val has the following advantages:
101
-
102
- - **easy** to setup and to _grok_: Val is designed to have a minimum of boilerplate and there's **0** query languages to learn. If you know your way around JSON that's enough (if you don't you might want to learn it)
103
- - **no signup** required to use it locally
104
- - **no fees** for content that is in your code: your content is your code, and your code is... yours
105
- - **minimal** API surface: Val is designed to not "infect" your code base
106
- - **easy to remove**: since your content is already in your code and Val is designed to have a minimal surface, it's easy to remove if you want to switch
107
-
108
- <details>
109
- <summary>Upcoming feature: <strong>i18n</strong></summary>
110
- Val will soon have support for i18n. Follow this repository to get notified when this is the case.
111
- </details>
112
-
113
- <details>
114
- <summary>Upcoming feature: <strong>remote content</strong></summary>
115
- Having hard-coded content is great for landing pages, product pages and other pages where the amount of content is manageable.
116
-
117
- However, checking in the 10 000th blog entry in git might feel wrong (though we would say it is ok).
118
-
119
- Therefore, Val will add `remote content` support which enables you to seamlessly move content to the cloud and back again as desired.
120
- You code will still be the one truth, but the actual content will be hosted on [val.build](https://val.build).
121
-
122
- `.remote()` support will also make it possible to have remote images to avoid having to put them in your repository.
123
-
124
- There will also be specific support for remote i18n, which will make it possible to split which languages are defined in code, and which are fetched from remote.
125
-
126
- More details on `.remote()` will follow later.
127
-
128
- </details>
129
-
130
- ## When to NOT use Val
131
-
132
- Val is designed to work well on a single web-app, and currently only supports Next 13.4+ (more meta-frameworks will supported) and GitHub (more Git providers will follow).
133
-
134
- Unless your application fits these requirements, you should have a look elsewhere (at least for now).
135
-
136
- In addition, if you have a "content model", i.e. content schemas, that rarely change and you plan on using them in a lot of different applications (web, mobile, etc), Val will most likely not be a great fit.
137
-
138
- If that is the case, we recommend having a look at [sanity](https://sanity.io) instead (we have no affiliation, but if we didn't have Val we would use Sanity).
139
-
140
- **NOTE**: Our experience is that, however nice it sounds, it is hard to "nail" the content model down. Usually content is derived from what you want to present, not vice-versa. In addition, you should think carefully whether you _really_ want to present the exact same content on all these different surfaces.
141
-
142
- ## Examples
143
-
144
- Check out this README or the [examples](./examples) directory for examples.
145
-
146
61
  ## Installation
147
62
 
148
63
  - Make sure you have TypeScript 5+, Next 13.4+ (other meta frameworks will come), React 18.20.+ (other frontend frameworks will come)
@@ -158,9 +73,9 @@ npm install @valbuild/core@latest @valbuild/next@latest @valbuild/eslint-plugin@
158
73
  npx @valbuild/init@latest
159
74
  ```
160
75
 
161
- ### Add editor support
76
+ ### Online mode
162
77
 
163
- To make it possible to do non-local edits, head over to [val.build](https://val.build), sign up and import your repository.
78
+ To make it possible to do online edits directly in your app, head over to [val.build](https://app.val.build), sign up and import your repository.
164
79
 
165
80
  **NOTE**: your content is yours. No subscription (or similar) is required to host content from your repository.
166
81
 
@@ -168,6 +83,36 @@ If you do not need to edit content online (i.e. not locally), you do not need to
168
83
 
169
84
  **WHY**: to update your code, we need to create a commit. This requires a server. We opted to create a service that does this easily, instead of having a self-hosted alternative, since time spent is money used. Also, the company behind [val.build](https://val.build) is the company that funds the development of this software.
170
85
 
86
+ #### Online mode configuration
87
+
88
+ Once you have setup your project in [val.build](https://app.val.build), you must configure your application to use this project.
89
+
90
+ To do this, you must set the following environment variables:
91
+
92
+ - `VAL_API_KEY`: you get this in your project configuration page.
93
+ - `VAL_SECRET`: this is a random secret you can generate. It is used for communication between the UX client and your Next.js application.
94
+
95
+ In addition, you need to set the following properties in the `val.config` file:
96
+
97
+ - project: This is the fully qualified name of your project. It should look like this: `<team>/<name>`.
98
+ - gitBranch: This is the git branch your application is using. In Vercel you can use: `VERCEL_GIT_COMMIT_REF`.
99
+ - gitCommit: This is the current git commit your application is running on. In Vercel you can use: `VERCEL_GIT_COMMIT_SHA`
100
+
101
+ Example of `val.config.ts`:
102
+
103
+ ```ts
104
+ import { initVal } from "@valbuild/next";
105
+
106
+ const { s, c, val, config } = initVal({
107
+ project: "myteam/myproject",
108
+ gitBranch: process.env.VERCEL_GIT_COMMIT_REF,
109
+ gitCommit: process.env.VERCEL_GIT_COMMIT_SHA,
110
+ });
111
+
112
+ export type { t } from "@valbuild/next";
113
+ export { s, c, val, config };
114
+ ```
115
+
171
116
  ## Getting started
172
117
 
173
118
  ### Create your first Val content file
@@ -200,7 +145,7 @@ export const schema = s.object({
200
145
  bold: true, // <- Enables bold in richtext
201
146
  },
202
147
  }),
203
- })
148
+ }),
204
149
  ),
205
150
  });
206
151
 
@@ -223,7 +168,7 @@ export default c.define(
223
168
  ],
224
169
  },
225
170
  ],
226
- }
171
+ },
227
172
  );
228
173
  ```
229
174
 
@@ -524,7 +469,7 @@ export function ValRichText({
524
469
  }) {
525
470
  function build(
526
471
  node: RichTextNode<MyRichTextOptions>,
527
- key?: number
472
+ key?: number,
528
473
  ): JSX.Element | string {
529
474
  if (typeof node === "string") {
530
475
  return node;
@@ -543,7 +488,7 @@ export function ValRichText({
543
488
  key,
544
489
  className,
545
490
  },
546
- "children" in node ? node.children.map(build) : null
491
+ "children" in node ? node.children.map(build) : null,
547
492
  );
548
493
  }
549
494
  return <div {...val.attrs(root)}>{root.children.map(build)}</div>;
@@ -571,7 +516,7 @@ export const schema = s.image();
571
516
  export default c.define("/image", schema, c.file("/public/myfile.jpg"));
572
517
  ```
573
518
 
574
- **NOTE**: This will not validate, since images requires `width`, `height` and a `sha256` checksum. You can fix validation errors like this by using the CLI or by using the VS Code plugin.
519
+ **NOTE**: This will not validate, since images requires `width`, `height` and `mimeType`. You can fix validation errors like this by using the CLI or by using the VS Code plugin.
575
520
 
576
521
  ### Rendering images
577
522
 
@@ -622,7 +567,7 @@ s.union(
622
567
  type: s.literal("productPage"),
623
568
  sku: s.number(),
624
569
  // ...
625
- })
570
+ }),
626
571
  ); // <- Schema<{ type: "blogPage", author: string } | { type: "productPage", sku: number }>
627
572
  ```
628
573
 
@@ -633,7 +578,7 @@ You can also use a union to create a union of string literals. This is useful if
633
578
  ```ts
634
579
  s.union(
635
580
  s.literal("one"),
636
- s.literal("two")
581
+ s.literal("two"),
637
582
  //...
638
583
  ); // <- Schema<"one" | "two">
639
584
  ```
@@ -645,7 +590,7 @@ If you need to reference content in another `.val` file you can use the `keyOf`
645
590
  ### KeyOf Schema
646
591
 
647
592
  ```ts
648
- import otherVal from "./other.val"; // NOTE: this must be an array or a record
593
+ import otherVal from "./other.val"; // NOTE: this must be a record
649
594
 
650
595
  s.keyOf(otherVal);
651
596
  ```
@@ -656,7 +601,7 @@ s.keyOf(otherVal);
656
601
 
657
602
  ```tsx
658
603
  const article = useVal(articleVal); // s.object({ author: s.keyOf(otherVal) })
659
- const authors = useVal(otherVal); // s.array(s.object({ name: s.string() }))
604
+ const authors = useVal(otherVal); // s.record(s.object({ name: s.string() }))
660
605
 
661
606
  const nameOfAuthor = authors[articleVal.author].name;
662
607
  ```
@@ -1,2 +1,2 @@
1
- export * from "../../dist/declarations/src/client/index";
2
- //# sourceMappingURL=valbuild-next-client.cjs.d.ts.map
1
+ export * from "../../dist/declarations/src/client/index.js";
2
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidmFsYnVpbGQtbmV4dC1jbGllbnQuY2pzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9kaXN0L2RlY2xhcmF0aW9ucy9zcmMvY2xpZW50L2luZGV4LmQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEifQ==
@@ -3,46 +3,34 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  require('client-only');
6
- var slicedToArray = require('../../dist/slicedToArray-c03b6356.cjs.dev.js');
7
- var core = require('@valbuild/core');
8
6
  var stega = require('@valbuild/react/stega');
9
7
  var React = require('react');
10
- var ValContext = require('../../dist/ValContext-06fe6f7e.cjs.dev.js');
11
- require('../../dist/unsupportedIterableToArray-9e97e24a.cjs.dev.js');
8
+ var ValOverlayContext = require('../../dist/ValOverlayContext-55dae3ea.cjs.dev.js');
12
9
 
13
10
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
14
11
 
15
12
  var React__default = /*#__PURE__*/_interopDefault(React);
16
13
 
17
14
  function useValStega(selector) {
18
- var _React$useState = React__default["default"].useState(false),
19
- _React$useState2 = slicedToArray._slicedToArray(_React$useState, 2),
20
- enabled = _React$useState2[0],
21
- setEnabled = _React$useState2[1];
22
- var valEvents = ValContext.useValEvents();
23
- React__default["default"].useEffect(function () {
24
- setEnabled(document.cookie.includes("".concat(core.Internal.VAL_ENABLE_COOKIE_NAME, "=true")));
25
- }, [valEvents]);
26
- if (valEvents) {
27
- var moduleIds = stega.getModuleIds(selector);
28
- React__default["default"].useEffect(function () {
29
- // NOTE: reload if a component using this starts rendering: this happens if you navigate to a page with this component
30
- if (enabled) {
31
- valEvents.reloadPaths(moduleIds);
32
- }
33
- }, [enabled]);
34
- var moduleMap = React__default["default"].useSyncExternalStore(valEvents.subscribe(moduleIds), valEvents.getSnapshot(moduleIds), valEvents.getServerSnapshot(moduleIds));
35
- return stega.stegaEncode(selector, {
36
- disabled: !enabled,
37
- getModule: function getModule(moduleId) {
38
- if (moduleMap && enabled) {
39
- return moduleMap[moduleId];
40
- }
41
- }
42
- });
43
- }
15
+ var valOverlayContext = ValOverlayContext.useValOverlayContext();
16
+ var moduleIds = React__default["default"].useMemo(function () {
17
+ return stega.getModuleIds(selector);
18
+ }, [selector]);
19
+ var store = valOverlayContext.store;
20
+ var moduleMap = React__default["default"].useSyncExternalStore(store ? store.subscribe(moduleIds) : function () {
21
+ return function () {};
22
+ }, store ? store.getSnapshot(moduleIds) : function () {
23
+ return;
24
+ }, store ? store.getServerSnapshot(moduleIds) : function () {
25
+ return;
26
+ });
44
27
  return stega.stegaEncode(selector, {
45
- disabled: !enabled
28
+ disabled: !valOverlayContext.draftMode,
29
+ getModule: function getModule(moduleId) {
30
+ if (moduleMap && valOverlayContext.draftMode) {
31
+ return moduleMap[moduleId];
32
+ }
33
+ }
46
34
  });
47
35
  }
48
36
 
@@ -3,46 +3,34 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  require('client-only');
6
- var slicedToArray = require('../../dist/slicedToArray-1d91551a.cjs.prod.js');
7
- var core = require('@valbuild/core');
8
6
  var stega = require('@valbuild/react/stega');
9
7
  var React = require('react');
10
- var ValContext = require('../../dist/ValContext-12a3eca2.cjs.prod.js');
11
- require('../../dist/unsupportedIterableToArray-afbea1dd.cjs.prod.js');
8
+ var ValOverlayContext = require('../../dist/ValOverlayContext-811e9be9.cjs.prod.js');
12
9
 
13
10
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
14
11
 
15
12
  var React__default = /*#__PURE__*/_interopDefault(React);
16
13
 
17
14
  function useValStega(selector) {
18
- var _React$useState = React__default["default"].useState(false),
19
- _React$useState2 = slicedToArray._slicedToArray(_React$useState, 2),
20
- enabled = _React$useState2[0],
21
- setEnabled = _React$useState2[1];
22
- var valEvents = ValContext.useValEvents();
23
- React__default["default"].useEffect(function () {
24
- setEnabled(document.cookie.includes("".concat(core.Internal.VAL_ENABLE_COOKIE_NAME, "=true")));
25
- }, [valEvents]);
26
- if (valEvents) {
27
- var moduleIds = stega.getModuleIds(selector);
28
- React__default["default"].useEffect(function () {
29
- // NOTE: reload if a component using this starts rendering: this happens if you navigate to a page with this component
30
- if (enabled) {
31
- valEvents.reloadPaths(moduleIds);
32
- }
33
- }, [enabled]);
34
- var moduleMap = React__default["default"].useSyncExternalStore(valEvents.subscribe(moduleIds), valEvents.getSnapshot(moduleIds), valEvents.getServerSnapshot(moduleIds));
35
- return stega.stegaEncode(selector, {
36
- disabled: !enabled,
37
- getModule: function getModule(moduleId) {
38
- if (moduleMap && enabled) {
39
- return moduleMap[moduleId];
40
- }
41
- }
42
- });
43
- }
15
+ var valOverlayContext = ValOverlayContext.useValOverlayContext();
16
+ var moduleIds = React__default["default"].useMemo(function () {
17
+ return stega.getModuleIds(selector);
18
+ }, [selector]);
19
+ var store = valOverlayContext.store;
20
+ var moduleMap = React__default["default"].useSyncExternalStore(store ? store.subscribe(moduleIds) : function () {
21
+ return function () {};
22
+ }, store ? store.getSnapshot(moduleIds) : function () {
23
+ return;
24
+ }, store ? store.getServerSnapshot(moduleIds) : function () {
25
+ return;
26
+ });
44
27
  return stega.stegaEncode(selector, {
45
- disabled: !enabled
28
+ disabled: !valOverlayContext.draftMode,
29
+ getModule: function getModule(moduleId) {
30
+ if (moduleMap && valOverlayContext.draftMode) {
31
+ return moduleMap[moduleId];
32
+ }
33
+ }
46
34
  });
47
35
  }
48
36
 
@@ -1,40 +1,28 @@
1
1
  import 'client-only';
2
- import { _ as _slicedToArray } from '../../dist/slicedToArray-1ff80c5e.esm.js';
3
- import { Internal } from '@valbuild/core';
4
2
  import { getModuleIds, stegaEncode } from '@valbuild/react/stega';
5
3
  import React from 'react';
6
- import { useValEvents } from '../../dist/ValContext-8a8d9183.esm.js';
7
- import '../../dist/unsupportedIterableToArray-51bb61c2.esm.js';
4
+ import { useValOverlayContext } from '../../dist/ValOverlayContext-a2fdbce0.esm.js';
8
5
 
9
6
  function useValStega(selector) {
10
- var _React$useState = React.useState(false),
11
- _React$useState2 = _slicedToArray(_React$useState, 2),
12
- enabled = _React$useState2[0],
13
- setEnabled = _React$useState2[1];
14
- var valEvents = useValEvents();
15
- React.useEffect(function () {
16
- setEnabled(document.cookie.includes("".concat(Internal.VAL_ENABLE_COOKIE_NAME, "=true")));
17
- }, [valEvents]);
18
- if (valEvents) {
19
- var moduleIds = getModuleIds(selector);
20
- React.useEffect(function () {
21
- // NOTE: reload if a component using this starts rendering: this happens if you navigate to a page with this component
22
- if (enabled) {
23
- valEvents.reloadPaths(moduleIds);
24
- }
25
- }, [enabled]);
26
- var moduleMap = React.useSyncExternalStore(valEvents.subscribe(moduleIds), valEvents.getSnapshot(moduleIds), valEvents.getServerSnapshot(moduleIds));
27
- return stegaEncode(selector, {
28
- disabled: !enabled,
29
- getModule: function getModule(moduleId) {
30
- if (moduleMap && enabled) {
31
- return moduleMap[moduleId];
32
- }
33
- }
34
- });
35
- }
7
+ var valOverlayContext = useValOverlayContext();
8
+ var moduleIds = React.useMemo(function () {
9
+ return getModuleIds(selector);
10
+ }, [selector]);
11
+ var store = valOverlayContext.store;
12
+ var moduleMap = React.useSyncExternalStore(store ? store.subscribe(moduleIds) : function () {
13
+ return function () {};
14
+ }, store ? store.getSnapshot(moduleIds) : function () {
15
+ return;
16
+ }, store ? store.getServerSnapshot(moduleIds) : function () {
17
+ return;
18
+ });
36
19
  return stegaEncode(selector, {
37
- disabled: !enabled
20
+ disabled: !valOverlayContext.draftMode,
21
+ getModule: function getModule(moduleId) {
22
+ if (moduleMap && valOverlayContext.draftMode) {
23
+ return moduleMap[moduleId];
24
+ }
25
+ }
38
26
  });
39
27
  }
40
28
 
@@ -0,0 +1,53 @@
1
+ 'use client';
2
+ import { _ as _slicedToArray } from './slicedToArray-aa291011.esm.js';
3
+ import { VAL_APP_PATH, VAL_APP_ID } from '@valbuild/ui';
4
+ import Script from 'next/script';
5
+ import { useState, useEffect } from 'react';
6
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
7
+ import './unsupportedIterableToArray-5baabfdc.esm.js';
8
+
9
+ function _objectDestructuringEmpty(t) {
10
+ if (null == t) throw new TypeError("Cannot destructure " + t);
11
+ }
12
+
13
+ var ValApp = function ValApp(_ref) {
14
+ _objectDestructuringEmpty(_ref);
15
+ var route = "/api/val";
16
+ var _useState = useState(),
17
+ _useState2 = _slicedToArray(_useState, 2),
18
+ inMessageMode = _useState2[0],
19
+ setInMessageMode = _useState2[1];
20
+ useEffect(function () {
21
+ if (location.search === "?message_onready=true") {
22
+ setInMessageMode(true);
23
+ var interval = setInterval(function () {
24
+ window.parent.postMessage({
25
+ type: "val-ready"
26
+ }, "*");
27
+ });
28
+ return function () {
29
+ clearInterval(interval);
30
+ };
31
+ } else {
32
+ setInMessageMode(false);
33
+ }
34
+ }, []);
35
+ if (inMessageMode === undefined) {
36
+ return null;
37
+ }
38
+ if (inMessageMode === true) {
39
+ return /*#__PURE__*/jsx("div", {
40
+ children: "Val Studio is disabled: in message mode"
41
+ });
42
+ }
43
+ return /*#__PURE__*/jsxs(Fragment, {
44
+ children: [/*#__PURE__*/jsx(Script, {
45
+ type: "module",
46
+ src: "".concat(route, "/static").concat(VAL_APP_PATH)
47
+ }), /*#__PURE__*/jsx("div", {
48
+ id: VAL_APP_ID
49
+ })]
50
+ });
51
+ };
52
+
53
+ export { ValApp };
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ if (process.env.NODE_ENV === "production") {
4
+ module.exports = require("./ValApp-9eefeefd.cjs.prod.js");
5
+ } else {
6
+ module.exports = require("./ValApp-9eefeefd.cjs.dev.js");
7
+ }
@@ -0,0 +1,61 @@
1
+ 'use client';
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var slicedToArray = require('./slicedToArray-ce613de6.cjs.prod.js');
7
+ var ui = require('@valbuild/ui');
8
+ var Script = require('next/script');
9
+ var React = require('react');
10
+ var jsxRuntime = require('react/jsx-runtime');
11
+ require('./unsupportedIterableToArray-0d2087a2.cjs.prod.js');
12
+
13
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
14
+
15
+ var Script__default = /*#__PURE__*/_interopDefault(Script);
16
+
17
+ function _objectDestructuringEmpty(t) {
18
+ if (null == t) throw new TypeError("Cannot destructure " + t);
19
+ }
20
+
21
+ var ValApp = function ValApp(_ref) {
22
+ _objectDestructuringEmpty(_ref);
23
+ var route = "/api/val";
24
+ var _useState = React.useState(),
25
+ _useState2 = slicedToArray._slicedToArray(_useState, 2),
26
+ inMessageMode = _useState2[0],
27
+ setInMessageMode = _useState2[1];
28
+ React.useEffect(function () {
29
+ if (location.search === "?message_onready=true") {
30
+ setInMessageMode(true);
31
+ var interval = setInterval(function () {
32
+ window.parent.postMessage({
33
+ type: "val-ready"
34
+ }, "*");
35
+ });
36
+ return function () {
37
+ clearInterval(interval);
38
+ };
39
+ } else {
40
+ setInMessageMode(false);
41
+ }
42
+ }, []);
43
+ if (inMessageMode === undefined) {
44
+ return null;
45
+ }
46
+ if (inMessageMode === true) {
47
+ return /*#__PURE__*/jsxRuntime.jsx("div", {
48
+ children: "Val Studio is disabled: in message mode"
49
+ });
50
+ }
51
+ return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
52
+ children: [/*#__PURE__*/jsxRuntime.jsx(Script__default["default"], {
53
+ type: "module",
54
+ src: "".concat(route, "/static").concat(ui.VAL_APP_PATH)
55
+ }), /*#__PURE__*/jsxRuntime.jsx("div", {
56
+ id: ui.VAL_APP_ID
57
+ })]
58
+ });
59
+ };
60
+
61
+ exports.ValApp = ValApp;
@@ -0,0 +1,61 @@
1
+ 'use client';
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var slicedToArray = require('./slicedToArray-44036a76.cjs.dev.js');
7
+ var ui = require('@valbuild/ui');
8
+ var Script = require('next/script');
9
+ var React = require('react');
10
+ var jsxRuntime = require('react/jsx-runtime');
11
+ require('./unsupportedIterableToArray-c8ab77c9.cjs.dev.js');
12
+
13
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
14
+
15
+ var Script__default = /*#__PURE__*/_interopDefault(Script);
16
+
17
+ function _objectDestructuringEmpty(t) {
18
+ if (null == t) throw new TypeError("Cannot destructure " + t);
19
+ }
20
+
21
+ var ValApp = function ValApp(_ref) {
22
+ _objectDestructuringEmpty(_ref);
23
+ var route = "/api/val";
24
+ var _useState = React.useState(),
25
+ _useState2 = slicedToArray._slicedToArray(_useState, 2),
26
+ inMessageMode = _useState2[0],
27
+ setInMessageMode = _useState2[1];
28
+ React.useEffect(function () {
29
+ if (location.search === "?message_onready=true") {
30
+ setInMessageMode(true);
31
+ var interval = setInterval(function () {
32
+ window.parent.postMessage({
33
+ type: "val-ready"
34
+ }, "*");
35
+ });
36
+ return function () {
37
+ clearInterval(interval);
38
+ };
39
+ } else {
40
+ setInMessageMode(false);
41
+ }
42
+ }, []);
43
+ if (inMessageMode === undefined) {
44
+ return null;
45
+ }
46
+ if (inMessageMode === true) {
47
+ return /*#__PURE__*/jsxRuntime.jsx("div", {
48
+ children: "Val Studio is disabled: in message mode"
49
+ });
50
+ }
51
+ return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
52
+ children: [/*#__PURE__*/jsxRuntime.jsx(Script__default["default"], {
53
+ type: "module",
54
+ src: "".concat(route, "/static").concat(ui.VAL_APP_PATH)
55
+ }), /*#__PURE__*/jsxRuntime.jsx("div", {
56
+ id: ui.VAL_APP_ID
57
+ })]
58
+ });
59
+ };
60
+
61
+ exports.ValApp = ValApp;