@valbuild/react 0.30.0 → 0.32.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.
- package/dist/{ValProviderInternal-06aa7448.esm.js → ValProvider-0620664e.esm.js} +68 -17
- package/dist/{ValProviderInternal-4c19d576.browser.esm.js → ValProvider-14179159.browser.esm.js} +67 -16
- package/dist/{ValProviderInternal-2faf106c.cjs.dev.js → ValProvider-7513c6ec.cjs.dev.js} +85 -17
- package/dist/ValProvider-b2e83d12.cjs.js +7 -0
- package/dist/{ValProviderInternal-172144ad.cjs.prod.js → ValProvider-b2e83d12.cjs.prod.js} +85 -17
- package/dist/{ValProviderInternal-5a5100ab.worker.esm.js → ValProvider-d46ec16a.worker.esm.js} +67 -21
- package/dist/{ValUI-ab7ef83f.cjs.dev.js → ValUI-33562b10.cjs.dev.js} +5 -43
- package/dist/{ValUI-b8544437.worker.esm.js → ValUI-3b9f6c17.worker.esm.js} +4 -42
- package/dist/{ValUI-9a231a97.esm.js → ValUI-4ba5efea.esm.js} +4 -42
- package/dist/{ValUI-697700f4.browser.esm.js → ValUI-75338157.browser.esm.js} +4 -42
- package/dist/ValUI-8ea90ec3.cjs.js +7 -0
- package/dist/{ValUI-46395962.cjs.prod.js → ValUI-8ea90ec3.cjs.prod.js} +5 -43
- package/dist/declarations/src/index.d.ts +11 -3
- package/dist/declarations/src/internal/ValProvider.d.ts +16 -0
- package/dist/declarations/src/internal/index.d.ts +2 -0
- package/dist/declarations/src/stega/stegaEncode.d.ts +1 -1
- package/dist/valbuild-react.browser.esm.js +11 -160
- package/dist/valbuild-react.cjs.d.ts +1 -0
- package/dist/valbuild-react.cjs.dev.js +12 -192
- package/dist/valbuild-react.cjs.prod.js +12 -192
- package/dist/valbuild-react.esm.js +11 -160
- package/dist/valbuild-react.worker.esm.js +11 -152
- package/internal/dist/valbuild-react-internal.browser.esm.js +146 -0
- package/internal/dist/valbuild-react-internal.cjs.d.ts +2 -0
- package/internal/dist/valbuild-react-internal.cjs.d.ts.map +1 -0
- package/internal/dist/valbuild-react-internal.cjs.dev.js +166 -0
- package/internal/dist/valbuild-react-internal.cjs.js +7 -0
- package/internal/dist/valbuild-react-internal.cjs.prod.js +166 -0
- package/internal/dist/valbuild-react-internal.esm.js +146 -0
- package/internal/dist/valbuild-react-internal.worker.esm.js +146 -0
- package/internal/package.json +7 -0
- package/package.json +15 -5
- package/dist/ValProviderInternal-172144ad.cjs.js +0 -7
- package/dist/ValUI-46395962.cjs.js +0 -7
- package/dist/declarations/src/ValProvider.d.ts +0 -3
- package/dist/declarations/src/ValProviderInternal.d.ts +0 -15
- /package/dist/declarations/src/{ValRichText.d.ts → internal/ValRichText.d.ts} +0 -0
- /package/dist/declarations/src/{ValStore.d.ts → internal/ValStore.d.ts} +0 -0
@@ -1,11 +1,10 @@
|
|
1
1
|
'use client';
|
2
|
-
import React, { useContext, useMemo } from 'react';
|
3
2
|
import { a as _unsupportedIterableToArray, _ as _slicedToArray } from './slicedToArray-331bebbb.esm.js';
|
3
|
+
import React, { useContext, useMemo, useState, useEffect, lazy } from 'react';
|
4
4
|
import { a as _toPropertyKey, _ as _defineProperty } from './defineProperty-12b5bd29.esm.js';
|
5
5
|
import { result } from '@valbuild/core/fp';
|
6
|
-
import { ValApi } from '@valbuild/core';
|
7
|
-
import
|
8
|
-
import { jsxs, jsx } from 'react/jsx-runtime';
|
6
|
+
import { ValApi, Internal } from '@valbuild/core';
|
7
|
+
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
9
8
|
|
10
9
|
function _createForOfIteratorHelper(o, allowArrayLike) {
|
11
10
|
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
@@ -581,32 +580,84 @@ function createSubscriberId(moduleIds) {
|
|
581
580
|
return moduleIds.slice().sort().join("&");
|
582
581
|
}
|
583
582
|
|
584
|
-
function useValStore() {
|
583
|
+
var useValStore = function useValStore() {
|
584
|
+
if (!ValContext) {
|
585
|
+
return undefined;
|
586
|
+
}
|
585
587
|
return useContext(ValContext).valStore;
|
586
|
-
}
|
587
|
-
function useValApi() {
|
588
|
+
};
|
589
|
+
var useValApi = function useValApi() {
|
590
|
+
if (!ValContext) {
|
591
|
+
return undefined;
|
592
|
+
}
|
588
593
|
return useContext(ValContext).valApi;
|
589
|
-
}
|
590
|
-
var ValContext = /*#__PURE__*/React.createContext({
|
594
|
+
};
|
595
|
+
var ValContext = typeof window !== "undefined" ? /*#__PURE__*/React.createContext({
|
591
596
|
valStore: undefined,
|
592
597
|
valApi: undefined
|
598
|
+
}) : undefined;
|
599
|
+
var ValUI = /*#__PURE__*/lazy(function () {
|
600
|
+
return import('./ValUI-4ba5efea.esm.js');
|
593
601
|
});
|
594
|
-
function
|
602
|
+
function ValProvider(_ref) {
|
595
603
|
var children = _ref.children;
|
596
604
|
var host = "/api/val";
|
597
|
-
var
|
605
|
+
var api = useMemo(function () {
|
598
606
|
return new ValApi(host);
|
599
607
|
}, [host]);
|
600
|
-
var
|
601
|
-
return new ValStore(
|
602
|
-
}, [
|
608
|
+
var store = useMemo(function () {
|
609
|
+
return new ValStore(api);
|
610
|
+
}, [api]);
|
611
|
+
var _useState = useState(false),
|
612
|
+
_useState2 = _slicedToArray(_useState, 2),
|
613
|
+
isClient = _useState2[0],
|
614
|
+
setIsClient = _useState2[1];
|
615
|
+
var _useState3 = useState(false),
|
616
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
617
|
+
enabled = _useState4[0],
|
618
|
+
setEnabled = _useState4[1];
|
619
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
620
|
+
var _useState5 = useState(false),
|
621
|
+
_useState6 = _slicedToArray(_useState5, 2);
|
622
|
+
_useState6[0];
|
623
|
+
var setDraftMode = _useState6[1]; // TODO: if enabled, but not in draft mode: show something
|
624
|
+
|
625
|
+
useEffect(function () {
|
626
|
+
setIsClient(true);
|
627
|
+
try {
|
628
|
+
var _document$cookie;
|
629
|
+
var valEnabled = (_document$cookie = document.cookie) === null || _document$cookie === void 0 ? void 0 : _document$cookie.includes("".concat(Internal.VAL_ENABLE_COOKIE_NAME, "=true"));
|
630
|
+
setEnabled(valEnabled);
|
631
|
+
} catch (e) {
|
632
|
+
console.warn("Could not read Val enabled state", e);
|
633
|
+
}
|
634
|
+
try {
|
635
|
+
var _document$cookie2;
|
636
|
+
var valDraftMode = (_document$cookie2 = document.cookie) === null || _document$cookie2 === void 0 ? void 0 : _document$cookie2.includes("".concat(Internal.VAL_DRAFT_MODE_COOKIE, "=true"));
|
637
|
+
setDraftMode(valDraftMode);
|
638
|
+
} catch (e) {
|
639
|
+
console.warn("Could not read Val draft mode", e);
|
640
|
+
}
|
641
|
+
}, []);
|
642
|
+
if (isClient && !enabled && process.env.NODE_ENV === "development") {
|
643
|
+
if (!api) {
|
644
|
+
console.warn("Val does not seem to be configured properly! Please check that you have wrapper your root layout (or _app) with the ValProvider.");
|
645
|
+
} else {
|
646
|
+
console.log("Val is disabled. Enable it by going here ".concat(window.origin).concat(api.host, "/enable?redirect_to=").concat(encodeURIComponent(window.location.href), ". NOTE: this message appears because NODE_ENV is set to development."));
|
647
|
+
}
|
648
|
+
}
|
649
|
+
if (!isClient || !enabled || !store || !api || !ValContext) {
|
650
|
+
return /*#__PURE__*/jsx(Fragment, {
|
651
|
+
children: children
|
652
|
+
});
|
653
|
+
}
|
603
654
|
return /*#__PURE__*/jsxs(ValContext.Provider, {
|
604
655
|
value: {
|
605
|
-
valApi:
|
606
|
-
valStore:
|
656
|
+
valApi: api,
|
657
|
+
valStore: store
|
607
658
|
},
|
608
659
|
children: [children, /*#__PURE__*/jsx(ValUI, {})]
|
609
660
|
});
|
610
661
|
}
|
611
662
|
|
612
|
-
export { ValContext,
|
663
|
+
export { ValContext, ValProvider, useValApi, useValStore };
|
package/dist/{ValProviderInternal-4c19d576.browser.esm.js → ValProvider-14179159.browser.esm.js}
RENAMED
@@ -1,11 +1,10 @@
|
|
1
1
|
'use client';
|
2
|
-
import React, { useContext, useMemo } from 'react';
|
3
2
|
import { a as _unsupportedIterableToArray, _ as _slicedToArray } from './slicedToArray-85f6bb43.browser.esm.js';
|
3
|
+
import React, { useContext, useMemo, useState, useEffect, lazy } from 'react';
|
4
4
|
import { a as _toPropertyKey, _ as _defineProperty } from './defineProperty-f319cb47.browser.esm.js';
|
5
5
|
import { result } from '@valbuild/core/fp';
|
6
|
-
import { ValApi } from '@valbuild/core';
|
7
|
-
import
|
8
|
-
import { jsxs, jsx } from 'react/jsx-runtime';
|
6
|
+
import { ValApi, Internal } from '@valbuild/core';
|
7
|
+
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
9
8
|
|
10
9
|
function _createForOfIteratorHelper(o, allowArrayLike) {
|
11
10
|
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
@@ -581,32 +580,84 @@ function createSubscriberId(moduleIds) {
|
|
581
580
|
return moduleIds.slice().sort().join("&");
|
582
581
|
}
|
583
582
|
|
584
|
-
function useValStore() {
|
583
|
+
var useValStore = function useValStore() {
|
584
|
+
if (!ValContext) {
|
585
|
+
return undefined;
|
586
|
+
}
|
585
587
|
return useContext(ValContext).valStore;
|
586
|
-
}
|
587
|
-
function useValApi() {
|
588
|
+
};
|
589
|
+
var useValApi = function useValApi() {
|
590
|
+
if (!ValContext) {
|
591
|
+
return undefined;
|
592
|
+
}
|
588
593
|
return useContext(ValContext).valApi;
|
589
|
-
}
|
594
|
+
};
|
590
595
|
var ValContext = /*#__PURE__*/React.createContext({
|
591
596
|
valStore: undefined,
|
592
597
|
valApi: undefined
|
598
|
+
}) ;
|
599
|
+
var ValUI = /*#__PURE__*/lazy(function () {
|
600
|
+
return import('./ValUI-75338157.browser.esm.js');
|
593
601
|
});
|
594
|
-
function
|
602
|
+
function ValProvider(_ref) {
|
595
603
|
var children = _ref.children;
|
596
604
|
var host = "/api/val";
|
597
|
-
var
|
605
|
+
var api = useMemo(function () {
|
598
606
|
return new ValApi(host);
|
599
607
|
}, [host]);
|
600
|
-
var
|
601
|
-
return new ValStore(
|
602
|
-
}, [
|
608
|
+
var store = useMemo(function () {
|
609
|
+
return new ValStore(api);
|
610
|
+
}, [api]);
|
611
|
+
var _useState = useState(false),
|
612
|
+
_useState2 = _slicedToArray(_useState, 2),
|
613
|
+
isClient = _useState2[0],
|
614
|
+
setIsClient = _useState2[1];
|
615
|
+
var _useState3 = useState(false),
|
616
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
617
|
+
enabled = _useState4[0],
|
618
|
+
setEnabled = _useState4[1];
|
619
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
620
|
+
var _useState5 = useState(false),
|
621
|
+
_useState6 = _slicedToArray(_useState5, 2);
|
622
|
+
_useState6[0];
|
623
|
+
var setDraftMode = _useState6[1]; // TODO: if enabled, but not in draft mode: show something
|
624
|
+
|
625
|
+
useEffect(function () {
|
626
|
+
setIsClient(true);
|
627
|
+
try {
|
628
|
+
var _document$cookie;
|
629
|
+
var valEnabled = (_document$cookie = document.cookie) === null || _document$cookie === void 0 ? void 0 : _document$cookie.includes("".concat(Internal.VAL_ENABLE_COOKIE_NAME, "=true"));
|
630
|
+
setEnabled(valEnabled);
|
631
|
+
} catch (e) {
|
632
|
+
console.warn("Could not read Val enabled state", e);
|
633
|
+
}
|
634
|
+
try {
|
635
|
+
var _document$cookie2;
|
636
|
+
var valDraftMode = (_document$cookie2 = document.cookie) === null || _document$cookie2 === void 0 ? void 0 : _document$cookie2.includes("".concat(Internal.VAL_DRAFT_MODE_COOKIE, "=true"));
|
637
|
+
setDraftMode(valDraftMode);
|
638
|
+
} catch (e) {
|
639
|
+
console.warn("Could not read Val draft mode", e);
|
640
|
+
}
|
641
|
+
}, []);
|
642
|
+
if (isClient && !enabled && process.env.NODE_ENV === "development") {
|
643
|
+
if (!api) {
|
644
|
+
console.warn("Val does not seem to be configured properly! Please check that you have wrapper your root layout (or _app) with the ValProvider.");
|
645
|
+
} else {
|
646
|
+
console.log("Val is disabled. Enable it by going here ".concat(window.origin).concat(api.host, "/enable?redirect_to=").concat(encodeURIComponent(window.location.href), ". NOTE: this message appears because NODE_ENV is set to development."));
|
647
|
+
}
|
648
|
+
}
|
649
|
+
if (!isClient || !enabled || !store || !api || !ValContext) {
|
650
|
+
return /*#__PURE__*/jsx(Fragment, {
|
651
|
+
children: children
|
652
|
+
});
|
653
|
+
}
|
603
654
|
return /*#__PURE__*/jsxs(ValContext.Provider, {
|
604
655
|
value: {
|
605
|
-
valApi:
|
606
|
-
valStore:
|
656
|
+
valApi: api,
|
657
|
+
valStore: store
|
607
658
|
},
|
608
659
|
children: [children, /*#__PURE__*/jsx(ValUI, {})]
|
609
660
|
});
|
610
661
|
}
|
611
662
|
|
612
|
-
export { ValContext,
|
663
|
+
export { ValContext, ValProvider, useValApi, useValStore };
|
@@ -3,18 +3,34 @@
|
|
3
3
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
5
5
|
|
6
|
-
var React = require('react');
|
7
6
|
var slicedToArray = require('./slicedToArray-a9d0d9cd.cjs.dev.js');
|
7
|
+
var React = require('react');
|
8
8
|
var defineProperty = require('./defineProperty-c82a49b0.cjs.dev.js');
|
9
9
|
var fp = require('@valbuild/core/fp');
|
10
10
|
var core = require('@valbuild/core');
|
11
|
-
var ValUI = require('./ValUI-ab7ef83f.cjs.dev.js');
|
12
11
|
var ReactJSXRuntime = require('react/jsx-runtime');
|
13
12
|
|
14
13
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
15
14
|
|
15
|
+
function _interopNamespace(e) {
|
16
|
+
if (e && e.__esModule) return e;
|
17
|
+
var n = Object.create(null);
|
18
|
+
if (e) {
|
19
|
+
Object.keys(e).forEach(function (k) {
|
20
|
+
if (k !== 'default') {
|
21
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
22
|
+
Object.defineProperty(n, k, d.get ? d : {
|
23
|
+
enumerable: true,
|
24
|
+
get: function () { return e[k]; }
|
25
|
+
});
|
26
|
+
}
|
27
|
+
});
|
28
|
+
}
|
29
|
+
n["default"] = e;
|
30
|
+
return Object.freeze(n);
|
31
|
+
}
|
32
|
+
|
16
33
|
var React__default = /*#__PURE__*/_interopDefault(React);
|
17
|
-
var ValUI__default = /*#__PURE__*/_interopDefault(ValUI);
|
18
34
|
|
19
35
|
function _createForOfIteratorHelper(o, allowArrayLike) {
|
20
36
|
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
@@ -590,35 +606,87 @@ function createSubscriberId(moduleIds) {
|
|
590
606
|
return moduleIds.slice().sort().join("&");
|
591
607
|
}
|
592
608
|
|
593
|
-
function useValStore() {
|
609
|
+
var useValStore = function useValStore() {
|
610
|
+
if (!ValContext) {
|
611
|
+
return undefined;
|
612
|
+
}
|
594
613
|
return React.useContext(ValContext).valStore;
|
595
|
-
}
|
596
|
-
function useValApi() {
|
614
|
+
};
|
615
|
+
var useValApi = function useValApi() {
|
616
|
+
if (!ValContext) {
|
617
|
+
return undefined;
|
618
|
+
}
|
597
619
|
return React.useContext(ValContext).valApi;
|
598
|
-
}
|
599
|
-
var ValContext = /*#__PURE__*/React__default["default"].createContext({
|
620
|
+
};
|
621
|
+
var ValContext = typeof window !== "undefined" ? /*#__PURE__*/React__default["default"].createContext({
|
600
622
|
valStore: undefined,
|
601
623
|
valApi: undefined
|
624
|
+
}) : undefined;
|
625
|
+
var ValUI = /*#__PURE__*/React.lazy(function () {
|
626
|
+
return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('./ValUI-33562b10.cjs.dev.js')); });
|
602
627
|
});
|
603
|
-
function
|
628
|
+
function ValProvider(_ref) {
|
604
629
|
var children = _ref.children;
|
605
630
|
var host = "/api/val";
|
606
|
-
var
|
631
|
+
var api = React.useMemo(function () {
|
607
632
|
return new core.ValApi(host);
|
608
633
|
}, [host]);
|
609
|
-
var
|
610
|
-
return new ValStore(
|
611
|
-
}, [
|
634
|
+
var store = React.useMemo(function () {
|
635
|
+
return new ValStore(api);
|
636
|
+
}, [api]);
|
637
|
+
var _useState = React.useState(false),
|
638
|
+
_useState2 = slicedToArray._slicedToArray(_useState, 2),
|
639
|
+
isClient = _useState2[0],
|
640
|
+
setIsClient = _useState2[1];
|
641
|
+
var _useState3 = React.useState(false),
|
642
|
+
_useState4 = slicedToArray._slicedToArray(_useState3, 2),
|
643
|
+
enabled = _useState4[0],
|
644
|
+
setEnabled = _useState4[1];
|
645
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
646
|
+
var _useState5 = React.useState(false),
|
647
|
+
_useState6 = slicedToArray._slicedToArray(_useState5, 2);
|
648
|
+
_useState6[0];
|
649
|
+
var setDraftMode = _useState6[1]; // TODO: if enabled, but not in draft mode: show something
|
650
|
+
|
651
|
+
React.useEffect(function () {
|
652
|
+
setIsClient(true);
|
653
|
+
try {
|
654
|
+
var _document$cookie;
|
655
|
+
var valEnabled = (_document$cookie = document.cookie) === null || _document$cookie === void 0 ? void 0 : _document$cookie.includes("".concat(core.Internal.VAL_ENABLE_COOKIE_NAME, "=true"));
|
656
|
+
setEnabled(valEnabled);
|
657
|
+
} catch (e) {
|
658
|
+
console.warn("Could not read Val enabled state", e);
|
659
|
+
}
|
660
|
+
try {
|
661
|
+
var _document$cookie2;
|
662
|
+
var valDraftMode = (_document$cookie2 = document.cookie) === null || _document$cookie2 === void 0 ? void 0 : _document$cookie2.includes("".concat(core.Internal.VAL_DRAFT_MODE_COOKIE, "=true"));
|
663
|
+
setDraftMode(valDraftMode);
|
664
|
+
} catch (e) {
|
665
|
+
console.warn("Could not read Val draft mode", e);
|
666
|
+
}
|
667
|
+
}, []);
|
668
|
+
if (isClient && !enabled && process.env.NODE_ENV === "development") {
|
669
|
+
if (!api) {
|
670
|
+
console.warn("Val does not seem to be configured properly! Please check that you have wrapper your root layout (or _app) with the ValProvider.");
|
671
|
+
} else {
|
672
|
+
console.log("Val is disabled. Enable it by going here ".concat(window.origin).concat(api.host, "/enable?redirect_to=").concat(encodeURIComponent(window.location.href), ". NOTE: this message appears because NODE_ENV is set to development."));
|
673
|
+
}
|
674
|
+
}
|
675
|
+
if (!isClient || !enabled || !store || !api || !ValContext) {
|
676
|
+
return /*#__PURE__*/ReactJSXRuntime.jsx(ReactJSXRuntime.Fragment, {
|
677
|
+
children: children
|
678
|
+
});
|
679
|
+
}
|
612
680
|
return /*#__PURE__*/ReactJSXRuntime.jsxs(ValContext.Provider, {
|
613
681
|
value: {
|
614
|
-
valApi:
|
615
|
-
valStore:
|
682
|
+
valApi: api,
|
683
|
+
valStore: store
|
616
684
|
},
|
617
|
-
children: [children, /*#__PURE__*/ReactJSXRuntime.jsx(
|
685
|
+
children: [children, /*#__PURE__*/ReactJSXRuntime.jsx(ValUI, {})]
|
618
686
|
});
|
619
687
|
}
|
620
688
|
|
621
689
|
exports.ValContext = ValContext;
|
622
|
-
exports
|
690
|
+
exports.ValProvider = ValProvider;
|
623
691
|
exports.useValApi = useValApi;
|
624
692
|
exports.useValStore = useValStore;
|
@@ -3,18 +3,34 @@
|
|
3
3
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
5
5
|
|
6
|
-
var React = require('react');
|
7
6
|
var slicedToArray = require('./slicedToArray-a2a426c7.cjs.prod.js');
|
7
|
+
var React = require('react');
|
8
8
|
var defineProperty = require('./defineProperty-36ed93cd.cjs.prod.js');
|
9
9
|
var fp = require('@valbuild/core/fp');
|
10
10
|
var core = require('@valbuild/core');
|
11
|
-
var ValUI = require('./ValUI-46395962.cjs.prod.js');
|
12
11
|
var ReactJSXRuntime = require('react/jsx-runtime');
|
13
12
|
|
14
13
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
15
14
|
|
15
|
+
function _interopNamespace(e) {
|
16
|
+
if (e && e.__esModule) return e;
|
17
|
+
var n = Object.create(null);
|
18
|
+
if (e) {
|
19
|
+
Object.keys(e).forEach(function (k) {
|
20
|
+
if (k !== 'default') {
|
21
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
22
|
+
Object.defineProperty(n, k, d.get ? d : {
|
23
|
+
enumerable: true,
|
24
|
+
get: function () { return e[k]; }
|
25
|
+
});
|
26
|
+
}
|
27
|
+
});
|
28
|
+
}
|
29
|
+
n["default"] = e;
|
30
|
+
return Object.freeze(n);
|
31
|
+
}
|
32
|
+
|
16
33
|
var React__default = /*#__PURE__*/_interopDefault(React);
|
17
|
-
var ValUI__default = /*#__PURE__*/_interopDefault(ValUI);
|
18
34
|
|
19
35
|
function _createForOfIteratorHelper(o, allowArrayLike) {
|
20
36
|
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
@@ -590,35 +606,87 @@ function createSubscriberId(moduleIds) {
|
|
590
606
|
return moduleIds.slice().sort().join("&");
|
591
607
|
}
|
592
608
|
|
593
|
-
function useValStore() {
|
609
|
+
var useValStore = function useValStore() {
|
610
|
+
if (!ValContext) {
|
611
|
+
return undefined;
|
612
|
+
}
|
594
613
|
return React.useContext(ValContext).valStore;
|
595
|
-
}
|
596
|
-
function useValApi() {
|
614
|
+
};
|
615
|
+
var useValApi = function useValApi() {
|
616
|
+
if (!ValContext) {
|
617
|
+
return undefined;
|
618
|
+
}
|
597
619
|
return React.useContext(ValContext).valApi;
|
598
|
-
}
|
599
|
-
var ValContext = /*#__PURE__*/React__default["default"].createContext({
|
620
|
+
};
|
621
|
+
var ValContext = typeof window !== "undefined" ? /*#__PURE__*/React__default["default"].createContext({
|
600
622
|
valStore: undefined,
|
601
623
|
valApi: undefined
|
624
|
+
}) : undefined;
|
625
|
+
var ValUI = /*#__PURE__*/React.lazy(function () {
|
626
|
+
return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('./ValUI-8ea90ec3.cjs.prod.js')); });
|
602
627
|
});
|
603
|
-
function
|
628
|
+
function ValProvider(_ref) {
|
604
629
|
var children = _ref.children;
|
605
630
|
var host = "/api/val";
|
606
|
-
var
|
631
|
+
var api = React.useMemo(function () {
|
607
632
|
return new core.ValApi(host);
|
608
633
|
}, [host]);
|
609
|
-
var
|
610
|
-
return new ValStore(
|
611
|
-
}, [
|
634
|
+
var store = React.useMemo(function () {
|
635
|
+
return new ValStore(api);
|
636
|
+
}, [api]);
|
637
|
+
var _useState = React.useState(false),
|
638
|
+
_useState2 = slicedToArray._slicedToArray(_useState, 2),
|
639
|
+
isClient = _useState2[0],
|
640
|
+
setIsClient = _useState2[1];
|
641
|
+
var _useState3 = React.useState(false),
|
642
|
+
_useState4 = slicedToArray._slicedToArray(_useState3, 2),
|
643
|
+
enabled = _useState4[0],
|
644
|
+
setEnabled = _useState4[1];
|
645
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
646
|
+
var _useState5 = React.useState(false),
|
647
|
+
_useState6 = slicedToArray._slicedToArray(_useState5, 2);
|
648
|
+
_useState6[0];
|
649
|
+
var setDraftMode = _useState6[1]; // TODO: if enabled, but not in draft mode: show something
|
650
|
+
|
651
|
+
React.useEffect(function () {
|
652
|
+
setIsClient(true);
|
653
|
+
try {
|
654
|
+
var _document$cookie;
|
655
|
+
var valEnabled = (_document$cookie = document.cookie) === null || _document$cookie === void 0 ? void 0 : _document$cookie.includes("".concat(core.Internal.VAL_ENABLE_COOKIE_NAME, "=true"));
|
656
|
+
setEnabled(valEnabled);
|
657
|
+
} catch (e) {
|
658
|
+
console.warn("Could not read Val enabled state", e);
|
659
|
+
}
|
660
|
+
try {
|
661
|
+
var _document$cookie2;
|
662
|
+
var valDraftMode = (_document$cookie2 = document.cookie) === null || _document$cookie2 === void 0 ? void 0 : _document$cookie2.includes("".concat(core.Internal.VAL_DRAFT_MODE_COOKIE, "=true"));
|
663
|
+
setDraftMode(valDraftMode);
|
664
|
+
} catch (e) {
|
665
|
+
console.warn("Could not read Val draft mode", e);
|
666
|
+
}
|
667
|
+
}, []);
|
668
|
+
if (isClient && !enabled && "production" === "development") {
|
669
|
+
if (!api) {
|
670
|
+
console.warn("Val does not seem to be configured properly! Please check that you have wrapper your root layout (or _app) with the ValProvider.");
|
671
|
+
} else {
|
672
|
+
console.log("Val is disabled. Enable it by going here ".concat(window.origin).concat(api.host, "/enable?redirect_to=").concat(encodeURIComponent(window.location.href), ". NOTE: this message appears because NODE_ENV is set to development."));
|
673
|
+
}
|
674
|
+
}
|
675
|
+
if (!isClient || !enabled || !store || !api || !ValContext) {
|
676
|
+
return /*#__PURE__*/ReactJSXRuntime.jsx(ReactJSXRuntime.Fragment, {
|
677
|
+
children: children
|
678
|
+
});
|
679
|
+
}
|
612
680
|
return /*#__PURE__*/ReactJSXRuntime.jsxs(ValContext.Provider, {
|
613
681
|
value: {
|
614
|
-
valApi:
|
615
|
-
valStore:
|
682
|
+
valApi: api,
|
683
|
+
valStore: store
|
616
684
|
},
|
617
|
-
children: [children, /*#__PURE__*/ReactJSXRuntime.jsx(
|
685
|
+
children: [children, /*#__PURE__*/ReactJSXRuntime.jsx(ValUI, {})]
|
618
686
|
});
|
619
687
|
}
|
620
688
|
|
621
689
|
exports.ValContext = ValContext;
|
622
|
-
exports
|
690
|
+
exports.ValProvider = ValProvider;
|
623
691
|
exports.useValApi = useValApi;
|
624
692
|
exports.useValStore = useValStore;
|
package/dist/{ValProviderInternal-5a5100ab.worker.esm.js → ValProvider-d46ec16a.worker.esm.js}
RENAMED
@@ -1,11 +1,10 @@
|
|
1
1
|
'use client';
|
2
|
-
import React, { useContext, useMemo } from 'react';
|
3
2
|
import { a as _unsupportedIterableToArray, _ as _slicedToArray } from './slicedToArray-d4c4a4ed.worker.esm.js';
|
3
|
+
import { useMemo, useState, useEffect, lazy } from 'react';
|
4
4
|
import { a as _toPropertyKey, _ as _defineProperty } from './defineProperty-a4bf59bc.worker.esm.js';
|
5
5
|
import { result } from '@valbuild/core/fp';
|
6
|
-
import { ValApi } from '@valbuild/core';
|
7
|
-
import
|
8
|
-
import { jsxs, jsx } from 'react/jsx-runtime';
|
6
|
+
import { ValApi, Internal } from '@valbuild/core';
|
7
|
+
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
9
8
|
|
10
9
|
function _createForOfIteratorHelper(o, allowArrayLike) {
|
11
10
|
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
@@ -581,32 +580,79 @@ function createSubscriberId(moduleIds) {
|
|
581
580
|
return moduleIds.slice().sort().join("&");
|
582
581
|
}
|
583
582
|
|
584
|
-
function useValStore() {
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
583
|
+
var useValStore = function useValStore() {
|
584
|
+
{
|
585
|
+
return undefined;
|
586
|
+
}
|
587
|
+
};
|
588
|
+
var useValApi = function useValApi() {
|
589
|
+
{
|
590
|
+
return undefined;
|
591
|
+
}
|
592
|
+
};
|
593
|
+
var ValContext = undefined;
|
594
|
+
var ValUI = /*#__PURE__*/lazy(function () {
|
595
|
+
return import('./ValUI-3b9f6c17.worker.esm.js');
|
593
596
|
});
|
594
|
-
function
|
597
|
+
function ValProvider(_ref) {
|
595
598
|
var children = _ref.children;
|
596
599
|
var host = "/api/val";
|
597
|
-
var
|
600
|
+
var api = useMemo(function () {
|
598
601
|
return new ValApi(host);
|
599
602
|
}, [host]);
|
600
|
-
var
|
601
|
-
return new ValStore(
|
602
|
-
}, [
|
603
|
+
var store = useMemo(function () {
|
604
|
+
return new ValStore(api);
|
605
|
+
}, [api]);
|
606
|
+
var _useState = useState(false),
|
607
|
+
_useState2 = _slicedToArray(_useState, 2),
|
608
|
+
isClient = _useState2[0],
|
609
|
+
setIsClient = _useState2[1];
|
610
|
+
var _useState3 = useState(false),
|
611
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
612
|
+
enabled = _useState4[0],
|
613
|
+
setEnabled = _useState4[1];
|
614
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
615
|
+
var _useState5 = useState(false),
|
616
|
+
_useState6 = _slicedToArray(_useState5, 2);
|
617
|
+
_useState6[0];
|
618
|
+
var setDraftMode = _useState6[1]; // TODO: if enabled, but not in draft mode: show something
|
619
|
+
|
620
|
+
useEffect(function () {
|
621
|
+
setIsClient(true);
|
622
|
+
try {
|
623
|
+
var _document$cookie;
|
624
|
+
var valEnabled = (_document$cookie = document.cookie) === null || _document$cookie === void 0 ? void 0 : _document$cookie.includes("".concat(Internal.VAL_ENABLE_COOKIE_NAME, "=true"));
|
625
|
+
setEnabled(valEnabled);
|
626
|
+
} catch (e) {
|
627
|
+
console.warn("Could not read Val enabled state", e);
|
628
|
+
}
|
629
|
+
try {
|
630
|
+
var _document$cookie2;
|
631
|
+
var valDraftMode = (_document$cookie2 = document.cookie) === null || _document$cookie2 === void 0 ? void 0 : _document$cookie2.includes("".concat(Internal.VAL_DRAFT_MODE_COOKIE, "=true"));
|
632
|
+
setDraftMode(valDraftMode);
|
633
|
+
} catch (e) {
|
634
|
+
console.warn("Could not read Val draft mode", e);
|
635
|
+
}
|
636
|
+
}, []);
|
637
|
+
if (isClient && !enabled && process.env.NODE_ENV === "development") {
|
638
|
+
if (!api) {
|
639
|
+
console.warn("Val does not seem to be configured properly! Please check that you have wrapper your root layout (or _app) with the ValProvider.");
|
640
|
+
} else {
|
641
|
+
console.log("Val is disabled. Enable it by going here ".concat(window.origin).concat(api.host, "/enable?redirect_to=").concat(encodeURIComponent(window.location.href), ". NOTE: this message appears because NODE_ENV is set to development."));
|
642
|
+
}
|
643
|
+
}
|
644
|
+
if (!isClient || !enabled || !store || !api || !ValContext) {
|
645
|
+
return /*#__PURE__*/jsx(Fragment, {
|
646
|
+
children: children
|
647
|
+
});
|
648
|
+
}
|
603
649
|
return /*#__PURE__*/jsxs(ValContext.Provider, {
|
604
650
|
value: {
|
605
|
-
valApi:
|
606
|
-
valStore:
|
651
|
+
valApi: api,
|
652
|
+
valStore: store
|
607
653
|
},
|
608
654
|
children: [children, /*#__PURE__*/jsx(ValUI, {})]
|
609
655
|
});
|
610
656
|
}
|
611
657
|
|
612
|
-
export { ValContext,
|
658
|
+
export { ValContext, ValProvider, useValApi, useValStore };
|