@valbuild/react 0.31.0 → 0.33.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-61d82ec0.esm.js → ValProvider-0620664e.esm.js} +64 -16
- package/dist/{ValProviderInternal-62bd0c14.browser.esm.js → ValProvider-14179159.browser.esm.js} +63 -15
- package/dist/{ValProviderInternal-d20f3c34.cjs.dev.js → ValProvider-7513c6ec.cjs.dev.js} +81 -16
- package/dist/ValProvider-b2e83d12.cjs.js +7 -0
- package/dist/{ValProviderInternal-757e00dc.cjs.prod.js → ValProvider-b2e83d12.cjs.prod.js} +81 -16
- package/dist/{ValProviderInternal-f64d019a.worker.esm.js → ValProvider-d46ec16a.worker.esm.js} +63 -20
- package/dist/{ValUI-82ba086a.cjs.dev.js → ValUI-33562b10.cjs.dev.js} +5 -43
- package/dist/{ValUI-eb3ed9e3.worker.esm.js → ValUI-3b9f6c17.worker.esm.js} +6 -44
- package/dist/{ValUI-c969250a.esm.js → ValUI-4ba5efea.esm.js} +6 -44
- package/dist/{ValUI-d049362e.browser.esm.js → ValUI-75338157.browser.esm.js} +6 -44
- package/dist/ValUI-8ea90ec3.cjs.js +7 -0
- package/dist/{ValUI-596c6129.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/{ValStore.d.ts → internal/ValStore.d.ts} +1 -1
- 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 +16 -5
- package/stega/dist/valbuild-react-stega.browser.esm.js +1 -1
- package/stega/dist/valbuild-react-stega.cjs.dev.js +3 -3
- package/stega/dist/valbuild-react-stega.cjs.prod.js +3 -3
- package/stega/dist/valbuild-react-stega.esm.js +1 -1
- package/stega/dist/valbuild-react-stega.worker.esm.js +1 -1
- package/dist/ValProviderInternal-757e00dc.cjs.js +0 -7
- package/dist/ValUI-596c6129.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
@@ -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"];
|
@@ -582,34 +581,83 @@ function createSubscriberId(moduleIds) {
|
|
582
581
|
}
|
583
582
|
|
584
583
|
var useValStore = function useValStore() {
|
584
|
+
if (!ValContext) {
|
585
|
+
return undefined;
|
586
|
+
}
|
585
587
|
return useContext(ValContext).valStore;
|
586
588
|
};
|
587
|
-
|
588
|
-
// NOTE: ValProviderInternal might not be defined if the user is not using ValProvider
|
589
|
-
// Addendum: This happens when this module will not be imported if the window === undefined. Not quite sure why this happens though. Some investigations might be in order.
|
590
589
|
var useValApi = function useValApi() {
|
590
|
+
if (!ValContext) {
|
591
|
+
return undefined;
|
592
|
+
}
|
591
593
|
return useContext(ValContext).valApi;
|
592
594
|
};
|
593
|
-
var ValContext = /*#__PURE__*/React.createContext({
|
595
|
+
var ValContext = typeof window !== "undefined" ? /*#__PURE__*/React.createContext({
|
594
596
|
valStore: undefined,
|
595
597
|
valApi: undefined
|
598
|
+
}) : undefined;
|
599
|
+
var ValUI = /*#__PURE__*/lazy(function () {
|
600
|
+
return import('./ValUI-4ba5efea.esm.js');
|
596
601
|
});
|
597
|
-
function
|
602
|
+
function ValProvider(_ref) {
|
598
603
|
var children = _ref.children;
|
599
604
|
var host = "/api/val";
|
600
|
-
var
|
605
|
+
var api = useMemo(function () {
|
601
606
|
return new ValApi(host);
|
602
607
|
}, [host]);
|
603
|
-
var
|
604
|
-
return new ValStore(
|
605
|
-
}, [
|
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
|
+
}
|
606
654
|
return /*#__PURE__*/jsxs(ValContext.Provider, {
|
607
655
|
value: {
|
608
|
-
valApi:
|
609
|
-
valStore:
|
656
|
+
valApi: api,
|
657
|
+
valStore: store
|
610
658
|
},
|
611
659
|
children: [children, /*#__PURE__*/jsx(ValUI, {})]
|
612
660
|
});
|
613
661
|
}
|
614
662
|
|
615
|
-
export { ValContext,
|
663
|
+
export { ValContext, ValProvider, useValApi, useValStore };
|
package/dist/{ValProviderInternal-62bd0c14.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"];
|
@@ -582,34 +581,83 @@ function createSubscriberId(moduleIds) {
|
|
582
581
|
}
|
583
582
|
|
584
583
|
var useValStore = function useValStore() {
|
584
|
+
if (!ValContext) {
|
585
|
+
return undefined;
|
586
|
+
}
|
585
587
|
return useContext(ValContext).valStore;
|
586
588
|
};
|
587
|
-
|
588
|
-
// NOTE: ValProviderInternal might not be defined if the user is not using ValProvider
|
589
|
-
// Addendum: This happens when this module will not be imported if the window === undefined. Not quite sure why this happens though. Some investigations might be in order.
|
590
589
|
var useValApi = function useValApi() {
|
590
|
+
if (!ValContext) {
|
591
|
+
return undefined;
|
592
|
+
}
|
591
593
|
return useContext(ValContext).valApi;
|
592
594
|
};
|
593
595
|
var ValContext = /*#__PURE__*/React.createContext({
|
594
596
|
valStore: undefined,
|
595
597
|
valApi: undefined
|
598
|
+
}) ;
|
599
|
+
var ValUI = /*#__PURE__*/lazy(function () {
|
600
|
+
return import('./ValUI-75338157.browser.esm.js');
|
596
601
|
});
|
597
|
-
function
|
602
|
+
function ValProvider(_ref) {
|
598
603
|
var children = _ref.children;
|
599
604
|
var host = "/api/val";
|
600
|
-
var
|
605
|
+
var api = useMemo(function () {
|
601
606
|
return new ValApi(host);
|
602
607
|
}, [host]);
|
603
|
-
var
|
604
|
-
return new ValStore(
|
605
|
-
}, [
|
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
|
+
}
|
606
654
|
return /*#__PURE__*/jsxs(ValContext.Provider, {
|
607
655
|
value: {
|
608
|
-
valApi:
|
609
|
-
valStore:
|
656
|
+
valApi: api,
|
657
|
+
valStore: store
|
610
658
|
},
|
611
659
|
children: [children, /*#__PURE__*/jsx(ValUI, {})]
|
612
660
|
});
|
613
661
|
}
|
614
662
|
|
615
|
-
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-82ba086a.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"];
|
@@ -591,37 +607,86 @@ function createSubscriberId(moduleIds) {
|
|
591
607
|
}
|
592
608
|
|
593
609
|
var useValStore = function useValStore() {
|
610
|
+
if (!ValContext) {
|
611
|
+
return undefined;
|
612
|
+
}
|
594
613
|
return React.useContext(ValContext).valStore;
|
595
614
|
};
|
596
|
-
|
597
|
-
// NOTE: ValProviderInternal might not be defined if the user is not using ValProvider
|
598
|
-
// Addendum: This happens when this module will not be imported if the window === undefined. Not quite sure why this happens though. Some investigations might be in order.
|
599
615
|
var useValApi = function useValApi() {
|
616
|
+
if (!ValContext) {
|
617
|
+
return undefined;
|
618
|
+
}
|
600
619
|
return React.useContext(ValContext).valApi;
|
601
620
|
};
|
602
|
-
var ValContext = /*#__PURE__*/React__default["default"].createContext({
|
621
|
+
var ValContext = typeof window !== "undefined" ? /*#__PURE__*/React__default["default"].createContext({
|
603
622
|
valStore: undefined,
|
604
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')); });
|
605
627
|
});
|
606
|
-
function
|
628
|
+
function ValProvider(_ref) {
|
607
629
|
var children = _ref.children;
|
608
630
|
var host = "/api/val";
|
609
|
-
var
|
631
|
+
var api = React.useMemo(function () {
|
610
632
|
return new core.ValApi(host);
|
611
633
|
}, [host]);
|
612
|
-
var
|
613
|
-
return new ValStore(
|
614
|
-
}, [
|
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
|
+
}
|
615
680
|
return /*#__PURE__*/ReactJSXRuntime.jsxs(ValContext.Provider, {
|
616
681
|
value: {
|
617
|
-
valApi:
|
618
|
-
valStore:
|
682
|
+
valApi: api,
|
683
|
+
valStore: store
|
619
684
|
},
|
620
|
-
children: [children, /*#__PURE__*/ReactJSXRuntime.jsx(
|
685
|
+
children: [children, /*#__PURE__*/ReactJSXRuntime.jsx(ValUI, {})]
|
621
686
|
});
|
622
687
|
}
|
623
688
|
|
624
689
|
exports.ValContext = ValContext;
|
625
|
-
exports
|
690
|
+
exports.ValProvider = ValProvider;
|
626
691
|
exports.useValApi = useValApi;
|
627
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-596c6129.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"];
|
@@ -591,37 +607,86 @@ function createSubscriberId(moduleIds) {
|
|
591
607
|
}
|
592
608
|
|
593
609
|
var useValStore = function useValStore() {
|
610
|
+
if (!ValContext) {
|
611
|
+
return undefined;
|
612
|
+
}
|
594
613
|
return React.useContext(ValContext).valStore;
|
595
614
|
};
|
596
|
-
|
597
|
-
// NOTE: ValProviderInternal might not be defined if the user is not using ValProvider
|
598
|
-
// Addendum: This happens when this module will not be imported if the window === undefined. Not quite sure why this happens though. Some investigations might be in order.
|
599
615
|
var useValApi = function useValApi() {
|
616
|
+
if (!ValContext) {
|
617
|
+
return undefined;
|
618
|
+
}
|
600
619
|
return React.useContext(ValContext).valApi;
|
601
620
|
};
|
602
|
-
var ValContext = /*#__PURE__*/React__default["default"].createContext({
|
621
|
+
var ValContext = typeof window !== "undefined" ? /*#__PURE__*/React__default["default"].createContext({
|
603
622
|
valStore: undefined,
|
604
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')); });
|
605
627
|
});
|
606
|
-
function
|
628
|
+
function ValProvider(_ref) {
|
607
629
|
var children = _ref.children;
|
608
630
|
var host = "/api/val";
|
609
|
-
var
|
631
|
+
var api = React.useMemo(function () {
|
610
632
|
return new core.ValApi(host);
|
611
633
|
}, [host]);
|
612
|
-
var
|
613
|
-
return new ValStore(
|
614
|
-
}, [
|
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
|
+
}
|
615
680
|
return /*#__PURE__*/ReactJSXRuntime.jsxs(ValContext.Provider, {
|
616
681
|
value: {
|
617
|
-
valApi:
|
618
|
-
valStore:
|
682
|
+
valApi: api,
|
683
|
+
valStore: store
|
619
684
|
},
|
620
|
-
children: [children, /*#__PURE__*/ReactJSXRuntime.jsx(
|
685
|
+
children: [children, /*#__PURE__*/ReactJSXRuntime.jsx(ValUI, {})]
|
621
686
|
});
|
622
687
|
}
|
623
688
|
|
624
689
|
exports.ValContext = ValContext;
|
625
|
-
exports
|
690
|
+
exports.ValProvider = ValProvider;
|
626
691
|
exports.useValApi = useValApi;
|
627
692
|
exports.useValStore = useValStore;
|
package/dist/{ValProviderInternal-f64d019a.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"];
|
@@ -582,34 +581,78 @@ function createSubscriberId(moduleIds) {
|
|
582
581
|
}
|
583
582
|
|
584
583
|
var useValStore = function useValStore() {
|
585
|
-
|
584
|
+
{
|
585
|
+
return undefined;
|
586
|
+
}
|
586
587
|
};
|
587
|
-
|
588
|
-
// NOTE: ValProviderInternal might not be defined if the user is not using ValProvider
|
589
|
-
// Addendum: This happens when this module will not be imported if the window === undefined. Not quite sure why this happens though. Some investigations might be in order.
|
590
588
|
var useValApi = function useValApi() {
|
591
|
-
|
589
|
+
{
|
590
|
+
return undefined;
|
591
|
+
}
|
592
592
|
};
|
593
|
-
var ValContext =
|
594
|
-
|
595
|
-
|
593
|
+
var ValContext = undefined;
|
594
|
+
var ValUI = /*#__PURE__*/lazy(function () {
|
595
|
+
return import('./ValUI-3b9f6c17.worker.esm.js');
|
596
596
|
});
|
597
|
-
function
|
597
|
+
function ValProvider(_ref) {
|
598
598
|
var children = _ref.children;
|
599
599
|
var host = "/api/val";
|
600
|
-
var
|
600
|
+
var api = useMemo(function () {
|
601
601
|
return new ValApi(host);
|
602
602
|
}, [host]);
|
603
|
-
var
|
604
|
-
return new ValStore(
|
605
|
-
}, [
|
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
|
+
}
|
606
649
|
return /*#__PURE__*/jsxs(ValContext.Provider, {
|
607
650
|
value: {
|
608
|
-
valApi:
|
609
|
-
valStore:
|
651
|
+
valApi: api,
|
652
|
+
valStore: store
|
610
653
|
},
|
611
654
|
children: [children, /*#__PURE__*/jsx(ValUI, {})]
|
612
655
|
});
|
613
656
|
}
|
614
657
|
|
615
|
-
export { ValContext,
|
658
|
+
export { ValContext, ValProvider, useValApi, useValStore };
|