@immediately-run/sdk 0.1.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/LICENSE +21 -0
- package/README.md +36 -0
- package/dist/MDXProvider.cjs +58 -0
- package/dist/MDXProvider.cjs.map +1 -0
- package/dist/MDXProvider.d.cts +6 -0
- package/dist/MDXProvider.d.ts +6 -0
- package/dist/MDXProvider.js +33 -0
- package/dist/MDXProvider.js.map +1 -0
- package/dist/RoutingSpec.cjs +17 -0
- package/dist/RoutingSpec.cjs.map +1 -0
- package/dist/RoutingSpec.d.cts +12 -0
- package/dist/RoutingSpec.d.ts +12 -0
- package/dist/RoutingSpec.js +1 -0
- package/dist/RoutingSpec.js.map +1 -0
- package/dist/TinkerableContext.cjs +30 -0
- package/dist/TinkerableContext.cjs.map +1 -0
- package/dist/TinkerableContext.d.cts +27 -0
- package/dist/TinkerableContext.d.ts +27 -0
- package/dist/TinkerableContext.js +6 -0
- package/dist/TinkerableContext.js.map +1 -0
- package/dist/boot.cjs +119 -0
- package/dist/boot.cjs.map +1 -0
- package/dist/boot.d.cts +15 -0
- package/dist/boot.d.ts +15 -0
- package/dist/boot.js +93 -0
- package/dist/boot.js.map +1 -0
- package/dist/components/FileRouter.cjs +53 -0
- package/dist/components/FileRouter.cjs.map +1 -0
- package/dist/components/FileRouter.d.cts +5 -0
- package/dist/components/FileRouter.d.ts +5 -0
- package/dist/components/FileRouter.js +29 -0
- package/dist/components/FileRouter.js.map +1 -0
- package/dist/components/Include.cjs +57 -0
- package/dist/components/Include.cjs.map +1 -0
- package/dist/components/Include.d.cts +23 -0
- package/dist/components/Include.d.ts +23 -0
- package/dist/components/Include.js +31 -0
- package/dist/components/Include.js.map +1 -0
- package/dist/components/MDXComponents.cjs +75 -0
- package/dist/components/MDXComponents.cjs.map +1 -0
- package/dist/components/MDXComponents.d.cts +10 -0
- package/dist/components/MDXComponents.d.ts +10 -0
- package/dist/components/MDXComponents.js +49 -0
- package/dist/components/MDXComponents.js.map +1 -0
- package/dist/components/MainContent.cjs +74 -0
- package/dist/components/MainContent.cjs.map +1 -0
- package/dist/components/MainContent.d.cts +16 -0
- package/dist/components/MainContent.d.ts +16 -0
- package/dist/components/MainContent.js +48 -0
- package/dist/components/MainContent.js.map +1 -0
- package/dist/components/defaults.cjs +36 -0
- package/dist/components/defaults.cjs.map +1 -0
- package/dist/components/defaults.d.cts +7 -0
- package/dist/components/defaults.d.ts +7 -0
- package/dist/components/defaults.js +11 -0
- package/dist/components/defaults.js.map +1 -0
- package/dist/components/errors.cjs +38 -0
- package/dist/components/errors.cjs.map +1 -0
- package/dist/components/errors.d.cts +5 -0
- package/dist/components/errors.d.ts +5 -0
- package/dist/components/errors.js +14 -0
- package/dist/components/errors.js.map +1 -0
- package/dist/contextUtils.cjs +60 -0
- package/dist/contextUtils.cjs.map +1 -0
- package/dist/contextUtils.d.cts +10 -0
- package/dist/contextUtils.d.ts +10 -0
- package/dist/contextUtils.js +34 -0
- package/dist/contextUtils.js.map +1 -0
- package/dist/hooks.cjs +75 -0
- package/dist/hooks.cjs.map +1 -0
- package/dist/hooks.d.cts +6 -0
- package/dist/hooks.d.ts +6 -0
- package/dist/hooks.js +50 -0
- package/dist/hooks.js.map +1 -0
- package/dist/index.cjs +35 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +13 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/moduleCache.cjs +66 -0
- package/dist/moduleCache.cjs.map +1 -0
- package/dist/moduleCache.d.cts +20 -0
- package/dist/moduleCache.d.ts +20 -0
- package/dist/moduleCache.js +40 -0
- package/dist/moduleCache.js.map +1 -0
- package/dist/pathUtils.cjs +63 -0
- package/dist/pathUtils.cjs.map +1 -0
- package/dist/pathUtils.d.cts +4 -0
- package/dist/pathUtils.d.ts +4 -0
- package/dist/pathUtils.js +38 -0
- package/dist/pathUtils.js.map +1 -0
- package/dist/routing.cjs +84 -0
- package/dist/routing.cjs.map +1 -0
- package/dist/routing.d.cts +15 -0
- package/dist/routing.d.ts +15 -0
- package/dist/routing.js +57 -0
- package/dist/routing.js.map +1 -0
- package/dist/sandboxTypes.cjs +17 -0
- package/dist/sandboxTypes.cjs.map +1 -0
- package/dist/sandboxTypes.d.cts +24 -0
- package/dist/sandboxTypes.d.ts +24 -0
- package/dist/sandboxTypes.js +1 -0
- package/dist/sandboxTypes.js.map +1 -0
- package/dist/sandboxUtils.cjs +46 -0
- package/dist/sandboxUtils.cjs.map +1 -0
- package/dist/sandboxUtils.d.cts +5 -0
- package/dist/sandboxUtils.d.ts +5 -0
- package/dist/sandboxUtils.js +20 -0
- package/dist/sandboxUtils.js.map +1 -0
- package/dist/urlUtils.cjs +159 -0
- package/dist/urlUtils.cjs.map +1 -0
- package/dist/urlUtils.d.cts +24 -0
- package/dist/urlUtils.d.ts +24 -0
- package/dist/urlUtils.js +124 -0
- package/dist/urlUtils.js.map +1 -0
- package/package.json +53 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var defaults_exports = {};
|
|
20
|
+
__export(defaults_exports, {
|
|
21
|
+
defaultErrorComponent: () => defaultErrorComponent,
|
|
22
|
+
defaultLoadingComponent: () => defaultLoadingComponent
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(defaults_exports);
|
|
25
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
26
|
+
const defaultLoadingComponent = () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: "loading..." });
|
|
27
|
+
const defaultErrorComponent = ({ error }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
28
|
+
"ERROR ",
|
|
29
|
+
String(error)
|
|
30
|
+
] });
|
|
31
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
32
|
+
0 && (module.exports = {
|
|
33
|
+
defaultErrorComponent,
|
|
34
|
+
defaultLoadingComponent
|
|
35
|
+
});
|
|
36
|
+
//# sourceMappingURL=defaults.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/components/defaults.tsx"],"sourcesContent":["import { ErrorBoundaryPropsWithRender } from 'react-error-boundary';\n\nexport const defaultLoadingComponent = () => <>loading...</>;\n\nexport const defaultErrorComponent:ErrorBoundaryPropsWithRender[\"fallbackRender\"] = ({error}) => <>ERROR {String(error)}</>;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAE6C;AAAtC,MAAM,0BAA0B,MAAM,2EAAE,wBAAU;AAElD,MAAM,wBAAuE,CAAC,EAAC,MAAK,MAAM,4EAAE;AAAA;AAAA,EAAO,OAAO,KAAK;AAAA,GAAE;","names":[]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ErrorBoundaryPropsWithRender } from 'react-error-boundary';
|
|
3
|
+
|
|
4
|
+
declare const defaultLoadingComponent: () => react_jsx_runtime.JSX.Element;
|
|
5
|
+
declare const defaultErrorComponent: ErrorBoundaryPropsWithRender["fallbackRender"];
|
|
6
|
+
|
|
7
|
+
export { defaultErrorComponent, defaultLoadingComponent };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ErrorBoundaryPropsWithRender } from 'react-error-boundary';
|
|
3
|
+
|
|
4
|
+
declare const defaultLoadingComponent: () => react_jsx_runtime.JSX.Element;
|
|
5
|
+
declare const defaultErrorComponent: ErrorBoundaryPropsWithRender["fallbackRender"];
|
|
6
|
+
|
|
7
|
+
export { defaultErrorComponent, defaultLoadingComponent };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
const defaultLoadingComponent = () => /* @__PURE__ */ jsx(Fragment, { children: "loading..." });
|
|
3
|
+
const defaultErrorComponent = ({ error }) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
4
|
+
"ERROR ",
|
|
5
|
+
String(error)
|
|
6
|
+
] });
|
|
7
|
+
export {
|
|
8
|
+
defaultErrorComponent,
|
|
9
|
+
defaultLoadingComponent
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=defaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/components/defaults.tsx"],"sourcesContent":["import { ErrorBoundaryPropsWithRender } from 'react-error-boundary';\n\nexport const defaultLoadingComponent = () => <>loading...</>;\n\nexport const defaultErrorComponent:ErrorBoundaryPropsWithRender[\"fallbackRender\"] = ({error}) => <>ERROR {String(error)}</>;\n"],"mappings":"AAE6C,wBAEoD,YAFpD;AAAtC,MAAM,0BAA0B,MAAM,gCAAE,wBAAU;AAElD,MAAM,wBAAuE,CAAC,EAAC,MAAK,MAAM,iCAAE;AAAA;AAAA,EAAO,OAAO,KAAK;AAAA,GAAE;","names":[]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var errors_exports = {};
|
|
20
|
+
__export(errors_exports, {
|
|
21
|
+
ErrorNotFound: () => ErrorNotFound
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(errors_exports);
|
|
24
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
25
|
+
var import_react = require("react");
|
|
26
|
+
var import_TinkerableContext = require("../TinkerableContext");
|
|
27
|
+
const ErrorNotFound = () => {
|
|
28
|
+
const { navigationState: { pathParameters } } = (0, import_react.useContext)(import_TinkerableContext.TinkerableContext);
|
|
29
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
30
|
+
"No route registered for path ",
|
|
31
|
+
pathParameters?.path ?? "(unknown)"
|
|
32
|
+
] });
|
|
33
|
+
};
|
|
34
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
35
|
+
0 && (module.exports = {
|
|
36
|
+
ErrorNotFound
|
|
37
|
+
});
|
|
38
|
+
//# sourceMappingURL=errors.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/components/errors.tsx"],"sourcesContent":["import { useContext } from \"react\";\nimport { TinkerableContext } from \"../TinkerableContext\";\n\nexport const ErrorNotFound = () => {\n const {navigationState: {pathParameters}} = useContext(TinkerableContext);\n return <>No route registered for path {pathParameters?.path ?? \"(unknown)\"}</>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKS;AALT,mBAA2B;AAC3B,+BAAkC;AAE3B,MAAM,gBAAgB,MAAM;AACjC,QAAM,EAAC,iBAAiB,EAAC,eAAc,EAAC,QAAI,yBAAW,0CAAiB;AACxE,SAAO,4EAAE;AAAA;AAAA,IAA8B,gBAAgB,QAAQ;AAAA,KAAY;AAC7E;","names":[]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Fragment, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useContext } from "react";
|
|
3
|
+
import { TinkerableContext } from "../TinkerableContext";
|
|
4
|
+
const ErrorNotFound = () => {
|
|
5
|
+
const { navigationState: { pathParameters } } = useContext(TinkerableContext);
|
|
6
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
7
|
+
"No route registered for path ",
|
|
8
|
+
pathParameters?.path ?? "(unknown)"
|
|
9
|
+
] });
|
|
10
|
+
};
|
|
11
|
+
export {
|
|
12
|
+
ErrorNotFound
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/components/errors.tsx"],"sourcesContent":["import { useContext } from \"react\";\nimport { TinkerableContext } from \"../TinkerableContext\";\n\nexport const ErrorNotFound = () => {\n const {navigationState: {pathParameters}} = useContext(TinkerableContext);\n return <>No route registered for path {pathParameters?.path ?? \"(unknown)\"}</>\n}\n"],"mappings":"AAKS;AALT,SAAS,kBAAkB;AAC3B,SAAS,yBAAyB;AAE3B,MAAM,gBAAgB,MAAM;AACjC,QAAM,EAAC,iBAAiB,EAAC,eAAc,EAAC,IAAI,WAAW,iBAAiB;AACxE,SAAO,iCAAE;AAAA;AAAA,IAA8B,gBAAgB,QAAQ;AAAA,KAAY;AAC7E;","names":[]}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var contextUtils_exports = {};
|
|
20
|
+
__export(contextUtils_exports, {
|
|
21
|
+
getContextFromUrl: () => getContextFromUrl,
|
|
22
|
+
getInitialContext: () => getInitialContext,
|
|
23
|
+
updateContext: () => updateContext
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(contextUtils_exports);
|
|
26
|
+
var import_urlUtils = require("./urlUtils");
|
|
27
|
+
var import_routing = require("./routing");
|
|
28
|
+
const getContextFromUrl = (routingSpec, outerHref, filesMetadata) => {
|
|
29
|
+
const navigationState = (0, import_urlUtils.parseHref)(outerHref);
|
|
30
|
+
const appliedRoutingRule = (0, import_routing.applyRoutingRule)(routingSpec, navigationState);
|
|
31
|
+
if (!appliedRoutingRule) {
|
|
32
|
+
throw new Error(`No route registered for path ${navigationState.sandboxPath}!`);
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
filesMetadata: filesMetadata ?? {},
|
|
36
|
+
routingSpec,
|
|
37
|
+
outerHref,
|
|
38
|
+
navigationState: {
|
|
39
|
+
...navigationState,
|
|
40
|
+
...appliedRoutingRule
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
const getInitialContext = (routingSpec) => {
|
|
45
|
+
const searchParams = (0, import_urlUtils.getSearchParams)();
|
|
46
|
+
return () => getContextFromUrl(routingSpec, searchParams["href"]);
|
|
47
|
+
};
|
|
48
|
+
const updateContext = (context, href) => {
|
|
49
|
+
if (href === context.outerHref) {
|
|
50
|
+
return context;
|
|
51
|
+
}
|
|
52
|
+
return getContextFromUrl(context.routingSpec, href, context.filesMetadata);
|
|
53
|
+
};
|
|
54
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
55
|
+
0 && (module.exports = {
|
|
56
|
+
getContextFromUrl,
|
|
57
|
+
getInitialContext,
|
|
58
|
+
updateContext
|
|
59
|
+
});
|
|
60
|
+
//# sourceMappingURL=contextUtils.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/contextUtils.ts"],"sourcesContent":["import type { RoutingSpec } from './RoutingSpec';\nimport { type TinkerableState } from './TinkerableContext';\nimport { parseHref, getSearchParams } from './urlUtils';\nimport { FilesMetadata } from './sandboxTypes';\nimport { applyRoutingRule } from './routing';\n\nexport const getContextFromUrl = (routingSpec: RoutingSpec, outerHref: string, filesMetadata?: FilesMetadata):TinkerableState => {\n const navigationState = parseHref(outerHref);\n const appliedRoutingRule = applyRoutingRule(routingSpec, navigationState);\n if (!appliedRoutingRule) {\n // TODO: better error\n throw new Error(`No route registered for path ${navigationState.sandboxPath}!`);\n }\n return {\n filesMetadata: filesMetadata ?? {},\n routingSpec,\n outerHref,\n navigationState: {\n ...navigationState,\n ...appliedRoutingRule\n }\n }\n}\n\nexport const getInitialContext = (routingSpec: RoutingSpec):(() => TinkerableState) => {\n const searchParams = getSearchParams()\n // initial href is passed in 'href' search param value\n return () => getContextFromUrl(routingSpec, searchParams['href']);\n}\n\nexport const updateContext = (context: TinkerableState, href: string):TinkerableState => {\n // No update is necessary if outerHref has not changed.\n if (href === context.outerHref) {\n return context;\n }\n return getContextFromUrl(context.routingSpec, href, context.filesMetadata);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,sBAA2C;AAE3C,qBAAiC;AAE1B,MAAM,oBAAoB,CAAC,aAA0B,WAAmB,kBAAkD;AAC/H,QAAM,sBAAkB,2BAAU,SAAS;AAC3C,QAAM,yBAAqB,iCAAiB,aAAa,eAAe;AACtE,MAAI,CAAC,oBAAoB;AAEvB,UAAM,IAAI,MAAM,gCAAgC,gBAAgB,WAAW,GAAG;AAAA,EAChF;AACF,SAAO;AAAA,IACL,eAAe,iBAAiB,CAAC;AAAA,IACjC;AAAA,IACA;AAAA,IACA,iBAAiB;AAAA,MACf,GAAG;AAAA,MACH,GAAG;AAAA,IACL;AAAA,EACF;AACF;AAEO,MAAM,oBAAoB,CAAC,gBAAqD;AACrF,QAAM,mBAAe,iCAAgB;AAErC,SAAO,MAAM,kBAAkB,aAAa,aAAa,MAAM,CAAC;AAClE;AAEO,MAAM,gBAAgB,CAAC,SAA0B,SAAiC;AAEvF,MAAI,SAAS,QAAQ,WAAW;AAC9B,WAAO;AAAA,EACT;AACA,SAAO,kBAAkB,QAAQ,aAAa,MAAM,QAAQ,aAAa;AAC3E;","names":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { RoutingSpec } from './RoutingSpec.cjs';
|
|
2
|
+
import { TinkerableState } from './TinkerableContext.cjs';
|
|
3
|
+
import { FilesMetadata } from './sandboxTypes.cjs';
|
|
4
|
+
import 'react';
|
|
5
|
+
|
|
6
|
+
declare const getContextFromUrl: (routingSpec: RoutingSpec, outerHref: string, filesMetadata?: FilesMetadata) => TinkerableState;
|
|
7
|
+
declare const getInitialContext: (routingSpec: RoutingSpec) => (() => TinkerableState);
|
|
8
|
+
declare const updateContext: (context: TinkerableState, href: string) => TinkerableState;
|
|
9
|
+
|
|
10
|
+
export { getContextFromUrl, getInitialContext, updateContext };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { RoutingSpec } from './RoutingSpec.js';
|
|
2
|
+
import { TinkerableState } from './TinkerableContext.js';
|
|
3
|
+
import { FilesMetadata } from './sandboxTypes.js';
|
|
4
|
+
import 'react';
|
|
5
|
+
|
|
6
|
+
declare const getContextFromUrl: (routingSpec: RoutingSpec, outerHref: string, filesMetadata?: FilesMetadata) => TinkerableState;
|
|
7
|
+
declare const getInitialContext: (routingSpec: RoutingSpec) => (() => TinkerableState);
|
|
8
|
+
declare const updateContext: (context: TinkerableState, href: string) => TinkerableState;
|
|
9
|
+
|
|
10
|
+
export { getContextFromUrl, getInitialContext, updateContext };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { parseHref, getSearchParams } from "./urlUtils";
|
|
2
|
+
import { applyRoutingRule } from "./routing";
|
|
3
|
+
const getContextFromUrl = (routingSpec, outerHref, filesMetadata) => {
|
|
4
|
+
const navigationState = parseHref(outerHref);
|
|
5
|
+
const appliedRoutingRule = applyRoutingRule(routingSpec, navigationState);
|
|
6
|
+
if (!appliedRoutingRule) {
|
|
7
|
+
throw new Error(`No route registered for path ${navigationState.sandboxPath}!`);
|
|
8
|
+
}
|
|
9
|
+
return {
|
|
10
|
+
filesMetadata: filesMetadata ?? {},
|
|
11
|
+
routingSpec,
|
|
12
|
+
outerHref,
|
|
13
|
+
navigationState: {
|
|
14
|
+
...navigationState,
|
|
15
|
+
...appliedRoutingRule
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
const getInitialContext = (routingSpec) => {
|
|
20
|
+
const searchParams = getSearchParams();
|
|
21
|
+
return () => getContextFromUrl(routingSpec, searchParams["href"]);
|
|
22
|
+
};
|
|
23
|
+
const updateContext = (context, href) => {
|
|
24
|
+
if (href === context.outerHref) {
|
|
25
|
+
return context;
|
|
26
|
+
}
|
|
27
|
+
return getContextFromUrl(context.routingSpec, href, context.filesMetadata);
|
|
28
|
+
};
|
|
29
|
+
export {
|
|
30
|
+
getContextFromUrl,
|
|
31
|
+
getInitialContext,
|
|
32
|
+
updateContext
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=contextUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/contextUtils.ts"],"sourcesContent":["import type { RoutingSpec } from './RoutingSpec';\nimport { type TinkerableState } from './TinkerableContext';\nimport { parseHref, getSearchParams } from './urlUtils';\nimport { FilesMetadata } from './sandboxTypes';\nimport { applyRoutingRule } from './routing';\n\nexport const getContextFromUrl = (routingSpec: RoutingSpec, outerHref: string, filesMetadata?: FilesMetadata):TinkerableState => {\n const navigationState = parseHref(outerHref);\n const appliedRoutingRule = applyRoutingRule(routingSpec, navigationState);\n if (!appliedRoutingRule) {\n // TODO: better error\n throw new Error(`No route registered for path ${navigationState.sandboxPath}!`);\n }\n return {\n filesMetadata: filesMetadata ?? {},\n routingSpec,\n outerHref,\n navigationState: {\n ...navigationState,\n ...appliedRoutingRule\n }\n }\n}\n\nexport const getInitialContext = (routingSpec: RoutingSpec):(() => TinkerableState) => {\n const searchParams = getSearchParams()\n // initial href is passed in 'href' search param value\n return () => getContextFromUrl(routingSpec, searchParams['href']);\n}\n\nexport const updateContext = (context: TinkerableState, href: string):TinkerableState => {\n // No update is necessary if outerHref has not changed.\n if (href === context.outerHref) {\n return context;\n }\n return getContextFromUrl(context.routingSpec, href, context.filesMetadata);\n}\n"],"mappings":"AAEA,SAAS,WAAW,uBAAuB;AAE3C,SAAS,wBAAwB;AAE1B,MAAM,oBAAoB,CAAC,aAA0B,WAAmB,kBAAkD;AAC/H,QAAM,kBAAkB,UAAU,SAAS;AAC3C,QAAM,qBAAqB,iBAAiB,aAAa,eAAe;AACtE,MAAI,CAAC,oBAAoB;AAEvB,UAAM,IAAI,MAAM,gCAAgC,gBAAgB,WAAW,GAAG;AAAA,EAChF;AACF,SAAO;AAAA,IACL,eAAe,iBAAiB,CAAC;AAAA,IACjC;AAAA,IACA;AAAA,IACA,iBAAiB;AAAA,MACf,GAAG;AAAA,MACH,GAAG;AAAA,IACL;AAAA,EACF;AACF;AAEO,MAAM,oBAAoB,CAAC,gBAAqD;AACrF,QAAM,eAAe,gBAAgB;AAErC,SAAO,MAAM,kBAAkB,aAAa,aAAa,MAAM,CAAC;AAClE;AAEO,MAAM,gBAAgB,CAAC,SAA0B,SAAiC;AAEvF,MAAI,SAAS,QAAQ,WAAW;AAC9B,WAAO;AAAA,EACT;AACA,SAAO,kBAAkB,QAAQ,aAAa,MAAM,QAAQ,aAAa;AAC3E;","names":[]}
|
package/dist/hooks.cjs
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var hooks_exports = {};
|
|
20
|
+
__export(hooks_exports, {
|
|
21
|
+
useFileMetadata: () => useFileMetadata,
|
|
22
|
+
useMetadataQuery: () => useMetadataQuery
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(hooks_exports);
|
|
25
|
+
var import_react = require("react");
|
|
26
|
+
var import_TinkerableContext = require("./TinkerableContext");
|
|
27
|
+
const evaluateQueryFunction = (filesMetadata, queryFunction) => {
|
|
28
|
+
try {
|
|
29
|
+
return { result: queryFunction(filesMetadata) };
|
|
30
|
+
} catch (e) {
|
|
31
|
+
return { error: e };
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const arraysEqual = (a, b) => {
|
|
35
|
+
if (a.length !== b.length) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
for (let i = 0; i < a.length; i++) {
|
|
39
|
+
if (a[i] !== b[i]) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return true;
|
|
44
|
+
};
|
|
45
|
+
const useMetadataQuery = (queryFunction) => {
|
|
46
|
+
const { filesMetadata } = (0, import_react.use)(import_TinkerableContext.TinkerableContext);
|
|
47
|
+
const [queryResult, setQueryResult] = (0, import_react.useState)(null);
|
|
48
|
+
(0, import_react.useEffect)(() => {
|
|
49
|
+
setQueryResult((prevResult) => {
|
|
50
|
+
const newResult = evaluateQueryFunction(filesMetadata, queryFunction);
|
|
51
|
+
if (!prevResult) {
|
|
52
|
+
return newResult;
|
|
53
|
+
}
|
|
54
|
+
if (!("result" in newResult)) {
|
|
55
|
+
return newResult;
|
|
56
|
+
}
|
|
57
|
+
if (!("result" in prevResult)) {
|
|
58
|
+
return newResult;
|
|
59
|
+
}
|
|
60
|
+
return arraysEqual(prevResult.result, newResult.result) ? prevResult : newResult;
|
|
61
|
+
});
|
|
62
|
+
}, [filesMetadata, setQueryResult, queryFunction]);
|
|
63
|
+
return queryResult;
|
|
64
|
+
};
|
|
65
|
+
const useFileMetadata = (path) => {
|
|
66
|
+
const { filesMetadata } = (0, import_react.use)(import_TinkerableContext.TinkerableContext);
|
|
67
|
+
const result = (0, import_react.useMemo)(() => filesMetadata[path], [path, filesMetadata]);
|
|
68
|
+
return result;
|
|
69
|
+
};
|
|
70
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
71
|
+
0 && (module.exports = {
|
|
72
|
+
useFileMetadata,
|
|
73
|
+
useMetadataQuery
|
|
74
|
+
});
|
|
75
|
+
//# sourceMappingURL=hooks.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks.ts"],"sourcesContent":["import { use, useEffect, useMemo, useState } from 'react';\nimport { TinkerableContext } from './TinkerableContext';\nimport { FilesMetadata, Metadata, MetadataQueryFunction, MetadataQueryResult } from './sandboxTypes';\n\nconst evaluateQueryFunction = (filesMetadata:FilesMetadata, queryFunction: MetadataQueryFunction):MetadataQueryResult => {\n try {\n return {result: queryFunction(filesMetadata)}\n } catch (e) {\n return {error: e}\n }\n}\n\nconst arraysEqual = <T>(a: T[], b:T[]):boolean => {\n if (a.length !== b.length) {\n return false;\n }\n for (let i = 0; i < a.length; i++) {\n if (a[i] !== b[i]) {\n return false;\n }\n }\n return true;\n}\n\nexport const useMetadataQuery = (queryFunction:MetadataQueryFunction) => {\n const {filesMetadata} = use(TinkerableContext);\n // we don't care if the metadata reference has changed, we only care about the output of queryFunction()\n const [queryResult, setQueryResult] = useState<MetadataQueryResult | null>(null);\n // any time the metadata object changes,\n // recalculate the query result and update the state if necessary\n useEffect(() => {\n setQueryResult(prevResult => {\n const newResult = evaluateQueryFunction(filesMetadata, queryFunction);\n if (!prevResult) {\n return newResult;\n }\n if (!('result' in newResult)) {\n return newResult;\n }\n if (!('result' in prevResult)) {\n return newResult;\n }\n return arraysEqual(prevResult.result, newResult.result) ? prevResult : newResult;\n })\n }, [filesMetadata, setQueryResult, queryFunction])\n return queryResult;\n}\n\nexport const useFileMetadata = (path: string): Metadata|null => {\n const {filesMetadata} = use(TinkerableContext);\n const result = useMemo(() => filesMetadata[path], [path, filesMetadata]);\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkD;AAClD,+BAAkC;AAGlC,MAAM,wBAAwB,CAAC,eAA6B,kBAA6D;AACvH,MAAI;AACF,WAAO,EAAC,QAAQ,cAAc,aAAa,EAAC;AAAA,EAC9C,SAAS,GAAG;AACV,WAAO,EAAC,OAAO,EAAC;AAAA,EAClB;AACF;AAEA,MAAM,cAAc,CAAI,GAAQ,MAAkB;AAChD,MAAI,EAAE,WAAW,EAAE,QAAQ;AACzB,WAAO;AAAA,EACT;AACA,WAAS,IAAI,GAAG,IAAI,EAAE,QAAQ,KAAK;AACjC,QAAI,EAAE,CAAC,MAAM,EAAE,CAAC,GAAG;AACjB,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AAEO,MAAM,mBAAmB,CAAC,kBAAwC;AACvE,QAAM,EAAC,cAAa,QAAI,kBAAI,0CAAiB;AAE7C,QAAM,CAAC,aAAa,cAAc,QAAI,uBAAqC,IAAI;AAG/E,8BAAU,MAAM;AACd,mBAAe,gBAAc;AAC3B,YAAM,YAAY,sBAAsB,eAAe,aAAa;AACpE,UAAI,CAAC,YAAY;AACf,eAAO;AAAA,MACT;AACA,UAAI,EAAE,YAAY,YAAY;AAC5B,eAAO;AAAA,MACT;AACA,UAAI,EAAE,YAAY,aAAa;AAC7B,eAAO;AAAA,MACT;AACA,aAAO,YAAY,WAAW,QAAQ,UAAU,MAAM,IAAI,aAAa;AAAA,IACzE,CAAC;AAAA,EACH,GAAG,CAAC,eAAe,gBAAgB,aAAa,CAAC;AACjD,SAAO;AACT;AAEO,MAAM,kBAAkB,CAAC,SAAgC;AAC9D,QAAM,EAAC,cAAa,QAAI,kBAAI,0CAAiB;AAC7C,QAAM,aAAS,sBAAQ,MAAM,cAAc,IAAI,GAAG,CAAC,MAAM,aAAa,CAAC;AACvE,SAAO;AACT;","names":[]}
|
package/dist/hooks.d.cts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Metadata, MetadataQueryFunction, MetadataQueryResult } from './sandboxTypes.cjs';
|
|
2
|
+
|
|
3
|
+
declare const useMetadataQuery: (queryFunction: MetadataQueryFunction) => MetadataQueryResult | null;
|
|
4
|
+
declare const useFileMetadata: (path: string) => Metadata | null;
|
|
5
|
+
|
|
6
|
+
export { useFileMetadata, useMetadataQuery };
|
package/dist/hooks.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Metadata, MetadataQueryFunction, MetadataQueryResult } from './sandboxTypes.js';
|
|
2
|
+
|
|
3
|
+
declare const useMetadataQuery: (queryFunction: MetadataQueryFunction) => MetadataQueryResult | null;
|
|
4
|
+
declare const useFileMetadata: (path: string) => Metadata | null;
|
|
5
|
+
|
|
6
|
+
export { useFileMetadata, useMetadataQuery };
|
package/dist/hooks.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { use, useEffect, useMemo, useState } from "react";
|
|
2
|
+
import { TinkerableContext } from "./TinkerableContext";
|
|
3
|
+
const evaluateQueryFunction = (filesMetadata, queryFunction) => {
|
|
4
|
+
try {
|
|
5
|
+
return { result: queryFunction(filesMetadata) };
|
|
6
|
+
} catch (e) {
|
|
7
|
+
return { error: e };
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
const arraysEqual = (a, b) => {
|
|
11
|
+
if (a.length !== b.length) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
for (let i = 0; i < a.length; i++) {
|
|
15
|
+
if (a[i] !== b[i]) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return true;
|
|
20
|
+
};
|
|
21
|
+
const useMetadataQuery = (queryFunction) => {
|
|
22
|
+
const { filesMetadata } = use(TinkerableContext);
|
|
23
|
+
const [queryResult, setQueryResult] = useState(null);
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
setQueryResult((prevResult) => {
|
|
26
|
+
const newResult = evaluateQueryFunction(filesMetadata, queryFunction);
|
|
27
|
+
if (!prevResult) {
|
|
28
|
+
return newResult;
|
|
29
|
+
}
|
|
30
|
+
if (!("result" in newResult)) {
|
|
31
|
+
return newResult;
|
|
32
|
+
}
|
|
33
|
+
if (!("result" in prevResult)) {
|
|
34
|
+
return newResult;
|
|
35
|
+
}
|
|
36
|
+
return arraysEqual(prevResult.result, newResult.result) ? prevResult : newResult;
|
|
37
|
+
});
|
|
38
|
+
}, [filesMetadata, setQueryResult, queryFunction]);
|
|
39
|
+
return queryResult;
|
|
40
|
+
};
|
|
41
|
+
const useFileMetadata = (path) => {
|
|
42
|
+
const { filesMetadata } = use(TinkerableContext);
|
|
43
|
+
const result = useMemo(() => filesMetadata[path], [path, filesMetadata]);
|
|
44
|
+
return result;
|
|
45
|
+
};
|
|
46
|
+
export {
|
|
47
|
+
useFileMetadata,
|
|
48
|
+
useMetadataQuery
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks.ts"],"sourcesContent":["import { use, useEffect, useMemo, useState } from 'react';\nimport { TinkerableContext } from './TinkerableContext';\nimport { FilesMetadata, Metadata, MetadataQueryFunction, MetadataQueryResult } from './sandboxTypes';\n\nconst evaluateQueryFunction = (filesMetadata:FilesMetadata, queryFunction: MetadataQueryFunction):MetadataQueryResult => {\n try {\n return {result: queryFunction(filesMetadata)}\n } catch (e) {\n return {error: e}\n }\n}\n\nconst arraysEqual = <T>(a: T[], b:T[]):boolean => {\n if (a.length !== b.length) {\n return false;\n }\n for (let i = 0; i < a.length; i++) {\n if (a[i] !== b[i]) {\n return false;\n }\n }\n return true;\n}\n\nexport const useMetadataQuery = (queryFunction:MetadataQueryFunction) => {\n const {filesMetadata} = use(TinkerableContext);\n // we don't care if the metadata reference has changed, we only care about the output of queryFunction()\n const [queryResult, setQueryResult] = useState<MetadataQueryResult | null>(null);\n // any time the metadata object changes,\n // recalculate the query result and update the state if necessary\n useEffect(() => {\n setQueryResult(prevResult => {\n const newResult = evaluateQueryFunction(filesMetadata, queryFunction);\n if (!prevResult) {\n return newResult;\n }\n if (!('result' in newResult)) {\n return newResult;\n }\n if (!('result' in prevResult)) {\n return newResult;\n }\n return arraysEqual(prevResult.result, newResult.result) ? prevResult : newResult;\n })\n }, [filesMetadata, setQueryResult, queryFunction])\n return queryResult;\n}\n\nexport const useFileMetadata = (path: string): Metadata|null => {\n const {filesMetadata} = use(TinkerableContext);\n const result = useMemo(() => filesMetadata[path], [path, filesMetadata]);\n return result;\n}\n"],"mappings":"AAAA,SAAS,KAAK,WAAW,SAAS,gBAAgB;AAClD,SAAS,yBAAyB;AAGlC,MAAM,wBAAwB,CAAC,eAA6B,kBAA6D;AACvH,MAAI;AACF,WAAO,EAAC,QAAQ,cAAc,aAAa,EAAC;AAAA,EAC9C,SAAS,GAAG;AACV,WAAO,EAAC,OAAO,EAAC;AAAA,EAClB;AACF;AAEA,MAAM,cAAc,CAAI,GAAQ,MAAkB;AAChD,MAAI,EAAE,WAAW,EAAE,QAAQ;AACzB,WAAO;AAAA,EACT;AACA,WAAS,IAAI,GAAG,IAAI,EAAE,QAAQ,KAAK;AACjC,QAAI,EAAE,CAAC,MAAM,EAAE,CAAC,GAAG;AACjB,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AAEO,MAAM,mBAAmB,CAAC,kBAAwC;AACvE,QAAM,EAAC,cAAa,IAAI,IAAI,iBAAiB;AAE7C,QAAM,CAAC,aAAa,cAAc,IAAI,SAAqC,IAAI;AAG/E,YAAU,MAAM;AACd,mBAAe,gBAAc;AAC3B,YAAM,YAAY,sBAAsB,eAAe,aAAa;AACpE,UAAI,CAAC,YAAY;AACf,eAAO;AAAA,MACT;AACA,UAAI,EAAE,YAAY,YAAY;AAC5B,eAAO;AAAA,MACT;AACA,UAAI,EAAE,YAAY,aAAa;AAC7B,eAAO;AAAA,MACT;AACA,aAAO,YAAY,WAAW,QAAQ,UAAU,MAAM,IAAI,aAAa;AAAA,IACzE,CAAC;AAAA,EACH,GAAG,CAAC,eAAe,gBAAgB,aAAa,CAAC;AACjD,SAAO;AACT;AAEO,MAAM,kBAAkB,CAAC,SAAgC;AAC9D,QAAM,EAAC,cAAa,IAAI,IAAI,iBAAiB;AAC7C,QAAM,SAAS,QAAQ,MAAM,cAAc,IAAI,GAAG,CAAC,MAAM,aAAa,CAAC;AACvE,SAAO;AACT;","names":[]}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var index_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(index_exports);
|
|
18
|
+
__reExport(index_exports, require("./MDXProvider"), module.exports);
|
|
19
|
+
__reExport(index_exports, require("./routing"), module.exports);
|
|
20
|
+
__reExport(index_exports, require("./boot"), module.exports);
|
|
21
|
+
__reExport(index_exports, require("./components/Include"), module.exports);
|
|
22
|
+
__reExport(index_exports, require("./components/MDXComponents"), module.exports);
|
|
23
|
+
__reExport(index_exports, require("./hooks"), module.exports);
|
|
24
|
+
__reExport(index_exports, require("./sandboxTypes"), module.exports);
|
|
25
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
26
|
+
0 && (module.exports = {
|
|
27
|
+
...require("./MDXProvider"),
|
|
28
|
+
...require("./routing"),
|
|
29
|
+
...require("./boot"),
|
|
30
|
+
...require("./components/Include"),
|
|
31
|
+
...require("./components/MDXComponents"),
|
|
32
|
+
...require("./hooks"),
|
|
33
|
+
...require("./sandboxTypes")
|
|
34
|
+
});
|
|
35
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from \"./MDXProvider\";\nexport * from \"./routing\";\nexport * from \"./boot\";\nexport * from './components/Include';\nexport * from './components/MDXComponents';\nexport * from './hooks'\nexport * from './sandboxTypes';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,0BAAc,0BAAd;AACA,0BAAc,sBADd;AAEA,0BAAc,mBAFd;AAGA,0BAAc,iCAHd;AAIA,0BAAc,uCAJd;AAKA,0BAAc,oBALd;AAMA,0BAAc,2BANd;","names":[]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { MDXProvider, useMDXComponents } from './MDXProvider.cjs';
|
|
2
|
+
export { AppliedRoutingRule, Router, applyRoutingRule, navigate, useTinkerableLink } from './routing.cjs';
|
|
3
|
+
export { BootProps, DEFAULT_ROUTING_SPEC, TinkerableApp, boot } from './boot.cjs';
|
|
4
|
+
export { Include, RenderExportedComponent, RenderExportedComponentContext, RenderFileContextType } from './components/Include.cjs';
|
|
5
|
+
export { DEFAULT_MDX_COMPONENTS, InternalLink, Link } from './components/MDXComponents.cjs';
|
|
6
|
+
export { useFileMetadata, useMetadataQuery } from './hooks.cjs';
|
|
7
|
+
export { EvaluationContext, FileQueryResult, FilesMetadata, Metadata, MetadataQueryFunction, MetadataQueryResult, ModuleExports } from './sandboxTypes.cjs';
|
|
8
|
+
import 'react';
|
|
9
|
+
import './TinkerableContext.cjs';
|
|
10
|
+
import './RoutingSpec.cjs';
|
|
11
|
+
import 'react/jsx-runtime';
|
|
12
|
+
import './components/defaults.cjs';
|
|
13
|
+
import 'react-error-boundary';
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { MDXProvider, useMDXComponents } from './MDXProvider.js';
|
|
2
|
+
export { AppliedRoutingRule, Router, applyRoutingRule, navigate, useTinkerableLink } from './routing.js';
|
|
3
|
+
export { BootProps, DEFAULT_ROUTING_SPEC, TinkerableApp, boot } from './boot.js';
|
|
4
|
+
export { Include, RenderExportedComponent, RenderExportedComponentContext, RenderFileContextType } from './components/Include.js';
|
|
5
|
+
export { DEFAULT_MDX_COMPONENTS, InternalLink, Link } from './components/MDXComponents.js';
|
|
6
|
+
export { useFileMetadata, useMetadataQuery } from './hooks.js';
|
|
7
|
+
export { EvaluationContext, FileQueryResult, FilesMetadata, Metadata, MetadataQueryFunction, MetadataQueryResult, ModuleExports } from './sandboxTypes.js';
|
|
8
|
+
import 'react';
|
|
9
|
+
import './TinkerableContext.js';
|
|
10
|
+
import './RoutingSpec.js';
|
|
11
|
+
import 'react/jsx-runtime';
|
|
12
|
+
import './components/defaults.js';
|
|
13
|
+
import 'react-error-boundary';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./MDXProvider";
|
|
2
|
+
export * from "./routing";
|
|
3
|
+
export * from "./boot";
|
|
4
|
+
export * from "./components/Include";
|
|
5
|
+
export * from "./components/MDXComponents";
|
|
6
|
+
export * from "./hooks";
|
|
7
|
+
export * from "./sandboxTypes";
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from \"./MDXProvider\";\nexport * from \"./routing\";\nexport * from \"./boot\";\nexport * from './components/Include';\nexport * from './components/MDXComponents';\nexport * from './hooks'\nexport * from './sandboxTypes';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var moduleCache_exports = {};
|
|
20
|
+
__export(moduleCache_exports, {
|
|
21
|
+
ModuleCache: () => ModuleCache,
|
|
22
|
+
ModuleCacheContext: () => ModuleCacheContext,
|
|
23
|
+
ModuleCacheContextProvider: () => ModuleCacheContextProvider
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(moduleCache_exports);
|
|
26
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
27
|
+
var import_react = require("react");
|
|
28
|
+
var import_sandboxUtils = require("./sandboxUtils");
|
|
29
|
+
class ModuleCache {
|
|
30
|
+
constructor() {
|
|
31
|
+
this.nameResolutionPromises = {};
|
|
32
|
+
this.evaluationContextPromises = {};
|
|
33
|
+
(0, import_sandboxUtils.addListener)("compile", () => {
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
getCacheKey(mod, moduleName) {
|
|
37
|
+
return `${mod.evaluation.module.filepath}|${moduleName}`;
|
|
38
|
+
}
|
|
39
|
+
resolveModuleName(moduleName, baseModule) {
|
|
40
|
+
const mod = baseModule ?? module;
|
|
41
|
+
const cacheKey = this.getCacheKey(mod, moduleName);
|
|
42
|
+
if (!(cacheKey in this.nameResolutionPromises)) {
|
|
43
|
+
this.nameResolutionPromises[cacheKey] = mod.resolve(moduleName);
|
|
44
|
+
}
|
|
45
|
+
return this.nameResolutionPromises[cacheKey];
|
|
46
|
+
}
|
|
47
|
+
getEvaluationContext(moduleName, baseModule) {
|
|
48
|
+
const mod = baseModule ?? module;
|
|
49
|
+
const cacheKey = this.getCacheKey(mod, moduleName);
|
|
50
|
+
if (!(cacheKey in this.evaluationContextPromises)) {
|
|
51
|
+
this.evaluationContextPromises[cacheKey] = mod.getModuleEvaluationContext(moduleName);
|
|
52
|
+
}
|
|
53
|
+
return this.evaluationContextPromises[cacheKey];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const ModuleCacheContext = (0, import_react.createContext)(null);
|
|
57
|
+
const ModuleCacheContextProvider = ({ children, moduleCache }) => {
|
|
58
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ModuleCacheContext.Provider, { value: moduleCache, children });
|
|
59
|
+
};
|
|
60
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
61
|
+
0 && (module.exports = {
|
|
62
|
+
ModuleCache,
|
|
63
|
+
ModuleCacheContext,
|
|
64
|
+
ModuleCacheContextProvider
|
|
65
|
+
});
|
|
66
|
+
//# sourceMappingURL=moduleCache.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/moduleCache.tsx"],"sourcesContent":["// based on: https://www.bbss.dev/posts/react-learn-suspense/#fetchcache-provider\n\nimport { createContext, ReactNode, useCallback, useState } from \"react\"\nimport { EvaluationContext } from \"./sandboxTypes\";\nimport { addListener } from \"./sandboxUtils\";\n\nexport class ModuleCache {\n nameResolutionPromises: Record<string, Promise<string>> = {}\n evaluationContextPromises: Record<string, Promise<EvaluationContext>> = {}\n\n constructor() {\n // reset cache on compile\n addListener('compile', () => {\n // NOTE: THIS CAUSES AN UNNECESSARY RELOAD\n // the <Include> component's module evaluation context promise is replaced\n // with a new promise for the same value when a compilation occurs which\n // doesn't affect the current module. Commenting out the following lines\n // eliminates the unnecessary component state loss.\n // this.nameResolutionPromises = {};\n // this.evaluationContextPromises = {};\n })\n }\n\n private getCacheKey(mod:EvaluationContext, moduleName:string):string {\n return `${mod.evaluation.module.filepath}|${moduleName}`;\n }\n\n resolveModuleName(moduleName:string, baseModule?:EvaluationContext):Promise<string> {\n // note: uses current module as base module if none specified by caller\n // @ts-ignore\n const mod = baseModule ?? (module as EvaluationContext);\n const cacheKey = this.getCacheKey(mod, moduleName);\n if (!(cacheKey in this.nameResolutionPromises)) {\n this.nameResolutionPromises[cacheKey] = mod.resolve(moduleName);\n }\n return this.nameResolutionPromises[cacheKey];\n }\n\n getEvaluationContext(moduleName:string, baseModule?:EvaluationContext):Promise<EvaluationContext> {\n // note: uses current module as base module if none specified by caller\n // @ts-ignore\n const mod = baseModule ?? (module as EvaluationContext);\n const cacheKey = this.getCacheKey(mod, moduleName);\n if (!(cacheKey in this.evaluationContextPromises)) {\n this.evaluationContextPromises[cacheKey] = mod.getModuleEvaluationContext(moduleName);\n }\n return this.evaluationContextPromises[cacheKey];\n\n }\n}\n\nexport const ModuleCacheContext = createContext<null|ModuleCache>(null)\n\nexport const ModuleCacheContextProvider = ({ children, moduleCache }:{ children:ReactNode, moduleCache: ModuleCache }) => {\n\n return (\n <ModuleCacheContext.Provider value={moduleCache}>\n {children}\n </ModuleCacheContext.Provider>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAwDQ;AAtDR,mBAAgE;AAEhE,0BAA4B;AAErB,MAAM,YAAY;AAAA,EAIvB,cAAc;AAHd,kCAA0D,CAAC;AAC3D,qCAAwE,CAAC;AAIvE,yCAAY,WAAW,MAAM;AAAA,IAQ7B,CAAC;AAAA,EACH;AAAA,EAEQ,YAAY,KAAuB,YAA0B;AACnE,WAAO,GAAG,IAAI,WAAW,OAAO,QAAQ,IAAI,UAAU;AAAA,EACxD;AAAA,EAEA,kBAAkB,YAAmB,YAA+C;AAGlF,UAAM,MAAM,cAAe;AAC3B,UAAM,WAAW,KAAK,YAAY,KAAK,UAAU;AACjD,QAAI,EAAE,YAAY,KAAK,yBAAyB;AAC9C,WAAK,uBAAuB,QAAQ,IAAI,IAAI,QAAQ,UAAU;AAAA,IAChE;AACA,WAAO,KAAK,uBAAuB,QAAQ;AAAA,EAC7C;AAAA,EAEA,qBAAqB,YAAmB,YAA0D;AAGhG,UAAM,MAAM,cAAe;AAC3B,UAAM,WAAW,KAAK,YAAY,KAAK,UAAU;AACjD,QAAI,EAAE,YAAY,KAAK,4BAA4B;AACjD,WAAK,0BAA0B,QAAQ,IAAI,IAAI,2BAA2B,UAAU;AAAA,IACtF;AACA,WAAO,KAAK,0BAA0B,QAAQ;AAAA,EAEhD;AACF;AAEO,MAAM,yBAAqB,4BAAgC,IAAI;AAE/D,MAAM,6BAA6B,CAAC,EAAE,UAAU,YAAY,MAAuD;AAEtH,SACI,4CAAC,mBAAmB,UAAnB,EAA4B,OAAO,aAC/B,UACL;AAER;","names":[]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as react from 'react';
|
|
3
|
+
import { ReactNode } from 'react';
|
|
4
|
+
import { EvaluationContext } from './sandboxTypes.cjs';
|
|
5
|
+
|
|
6
|
+
declare class ModuleCache {
|
|
7
|
+
nameResolutionPromises: Record<string, Promise<string>>;
|
|
8
|
+
evaluationContextPromises: Record<string, Promise<EvaluationContext>>;
|
|
9
|
+
constructor();
|
|
10
|
+
private getCacheKey;
|
|
11
|
+
resolveModuleName(moduleName: string, baseModule?: EvaluationContext): Promise<string>;
|
|
12
|
+
getEvaluationContext(moduleName: string, baseModule?: EvaluationContext): Promise<EvaluationContext>;
|
|
13
|
+
}
|
|
14
|
+
declare const ModuleCacheContext: react.Context<ModuleCache | null>;
|
|
15
|
+
declare const ModuleCacheContextProvider: ({ children, moduleCache }: {
|
|
16
|
+
children: ReactNode;
|
|
17
|
+
moduleCache: ModuleCache;
|
|
18
|
+
}) => react_jsx_runtime.JSX.Element;
|
|
19
|
+
|
|
20
|
+
export { ModuleCache, ModuleCacheContext, ModuleCacheContextProvider };
|