@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Peter Neumark
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# @immediately-run/sdk
|
|
2
|
+
|
|
3
|
+
Runtime SDK for code executing inside an [immediately.run](https://immediately.run) sandbox.
|
|
4
|
+
It is the API that user code running in the sandboxed preview iframe imports to
|
|
5
|
+
query files by MDX frontmatter, dynamically `require` JS modules, navigate, and
|
|
6
|
+
hook into the immediately.run runtime.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
npm install @immediately-run/sdk
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
`react` and `react-dom` (v19+) are peer dependencies — the host app provides them.
|
|
15
|
+
|
|
16
|
+
## Top-level exports
|
|
17
|
+
|
|
18
|
+
The public surface is re-exported from the package root (`@immediately-run/sdk`) and
|
|
19
|
+
also reachable via subpaths (`@immediately-run/sdk/boot`, `@immediately-run/sdk/hooks`, …):
|
|
20
|
+
|
|
21
|
+
- `boot` — entry point that mounts an immediately.run app into the sandbox.
|
|
22
|
+
- `Include` (`components/Include`) — render another file's exported component inline.
|
|
23
|
+
- `MDXComponents` (`Link`, …) — MDX component overrides.
|
|
24
|
+
- `useMetadataQuery`, `useFileMetadata` (`hooks`) — query files by frontmatter metadata.
|
|
25
|
+
- routing helpers (`Router`, `SandboxRouter`, …).
|
|
26
|
+
- `MDXProvider` — the MDX context provider used by transformed `.mdx` files.
|
|
27
|
+
- `sandboxTypes` — shared TypeScript types for the sandbox runtime.
|
|
28
|
+
|
|
29
|
+
## API documentation
|
|
30
|
+
|
|
31
|
+
Full API reference is published to GitHub Pages:
|
|
32
|
+
<https://immediately-run.github.io/immediately-run-sdk/>
|
|
33
|
+
|
|
34
|
+
## License
|
|
35
|
+
|
|
36
|
+
[MIT](./LICENSE)
|
|
@@ -0,0 +1,58 @@
|
|
|
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 MDXProvider_exports = {};
|
|
20
|
+
__export(MDXProvider_exports, {
|
|
21
|
+
MDXProvider: () => MDXProvider,
|
|
22
|
+
useMDXComponents: () => useMDXComponents
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(MDXProvider_exports);
|
|
25
|
+
var import_react = require("react");
|
|
26
|
+
const emptyComponents = {};
|
|
27
|
+
const MDXContext = (0, import_react.createContext)(emptyComponents);
|
|
28
|
+
function useMDXComponents(components) {
|
|
29
|
+
const contextComponents = (0, import_react.useContext)(MDXContext);
|
|
30
|
+
return (0, import_react.useMemo)(
|
|
31
|
+
function() {
|
|
32
|
+
if (typeof components === "function") {
|
|
33
|
+
return components(contextComponents);
|
|
34
|
+
}
|
|
35
|
+
return { ...contextComponents, ...components };
|
|
36
|
+
},
|
|
37
|
+
[contextComponents, components]
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
function MDXProvider(properties) {
|
|
41
|
+
let allComponents;
|
|
42
|
+
if (properties.disableParentContext) {
|
|
43
|
+
allComponents = typeof properties.components === "function" ? properties.components(emptyComponents) : properties.components || emptyComponents;
|
|
44
|
+
} else {
|
|
45
|
+
allComponents = useMDXComponents(properties.components);
|
|
46
|
+
}
|
|
47
|
+
return (0, import_react.createElement)(
|
|
48
|
+
MDXContext.Provider,
|
|
49
|
+
{ value: allComponents },
|
|
50
|
+
properties.children
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
54
|
+
0 && (module.exports = {
|
|
55
|
+
MDXProvider,
|
|
56
|
+
useMDXComponents
|
|
57
|
+
});
|
|
58
|
+
//# sourceMappingURL=MDXProvider.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/MDXProvider.ts"],"sourcesContent":["// Based on https://github.com/mdx-js/mdx/blob/main/packages/react/lib/index.js\n// since sandpack-bundler cannot import @mdx-js/react as it chokes on the\n// transitive dependency on VFile.\nimport {createContext, useContext, useMemo, createElement} from 'react'\nconst emptyComponents = {}\n\nconst MDXContext = createContext(emptyComponents);\n\nexport function useMDXComponents(components:any) {\n const contextComponents = useContext(MDXContext)\n\n // Memoize to avoid unnecessary top-level context changes\n return useMemo(\n function () {\n // Custom merge via a function prop\n if (typeof components === 'function') {\n return components(contextComponents)\n }\n\n return {...contextComponents, ...components}\n },\n [contextComponents, components]\n )\n}\n\nexport function MDXProvider(properties:any) {\n\n let allComponents: any\n\n if (properties.disableParentContext) {\n allComponents =\n typeof properties.components === 'function'\n ? properties.components(emptyComponents)\n : properties.components || emptyComponents\n } else {\n allComponents = useMDXComponents(properties.components)\n }\n\n return createElement(\n MDXContext.Provider,\n {value: allComponents},\n properties.children\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAAgE;AAChE,MAAM,kBAAkB,CAAC;AAEzB,MAAM,iBAAa,4BAAc,eAAe;AAEzC,SAAS,iBAAiB,YAAgB;AAC/C,QAAM,wBAAoB,yBAAW,UAAU;AAG/C,aAAO;AAAA,IACL,WAAY;AAEV,UAAI,OAAO,eAAe,YAAY;AACpC,eAAO,WAAW,iBAAiB;AAAA,MACrC;AAEA,aAAO,EAAC,GAAG,mBAAmB,GAAG,WAAU;AAAA,IAC7C;AAAA,IACA,CAAC,mBAAmB,UAAU;AAAA,EAChC;AACF;AAEO,SAAS,YAAY,YAAgB;AAE1C,MAAI;AAEJ,MAAI,WAAW,sBAAsB;AACnC,oBACE,OAAO,WAAW,eAAe,aAC7B,WAAW,WAAW,eAAe,IACrC,WAAW,cAAc;AAAA,EACjC,OAAO;AACL,oBAAgB,iBAAiB,WAAW,UAAU;AAAA,EACxD;AAEA,aAAO;AAAA,IACL,WAAW;AAAA,IACX,EAAC,OAAO,cAAa;AAAA,IACrB,WAAW;AAAA,EACb;AACF;","names":[]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createContext, useContext, useMemo, createElement } from "react";
|
|
2
|
+
const emptyComponents = {};
|
|
3
|
+
const MDXContext = createContext(emptyComponents);
|
|
4
|
+
function useMDXComponents(components) {
|
|
5
|
+
const contextComponents = useContext(MDXContext);
|
|
6
|
+
return useMemo(
|
|
7
|
+
function() {
|
|
8
|
+
if (typeof components === "function") {
|
|
9
|
+
return components(contextComponents);
|
|
10
|
+
}
|
|
11
|
+
return { ...contextComponents, ...components };
|
|
12
|
+
},
|
|
13
|
+
[contextComponents, components]
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
function MDXProvider(properties) {
|
|
17
|
+
let allComponents;
|
|
18
|
+
if (properties.disableParentContext) {
|
|
19
|
+
allComponents = typeof properties.components === "function" ? properties.components(emptyComponents) : properties.components || emptyComponents;
|
|
20
|
+
} else {
|
|
21
|
+
allComponents = useMDXComponents(properties.components);
|
|
22
|
+
}
|
|
23
|
+
return createElement(
|
|
24
|
+
MDXContext.Provider,
|
|
25
|
+
{ value: allComponents },
|
|
26
|
+
properties.children
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
export {
|
|
30
|
+
MDXProvider,
|
|
31
|
+
useMDXComponents
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=MDXProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/MDXProvider.ts"],"sourcesContent":["// Based on https://github.com/mdx-js/mdx/blob/main/packages/react/lib/index.js\n// since sandpack-bundler cannot import @mdx-js/react as it chokes on the\n// transitive dependency on VFile.\nimport {createContext, useContext, useMemo, createElement} from 'react'\nconst emptyComponents = {}\n\nconst MDXContext = createContext(emptyComponents);\n\nexport function useMDXComponents(components:any) {\n const contextComponents = useContext(MDXContext)\n\n // Memoize to avoid unnecessary top-level context changes\n return useMemo(\n function () {\n // Custom merge via a function prop\n if (typeof components === 'function') {\n return components(contextComponents)\n }\n\n return {...contextComponents, ...components}\n },\n [contextComponents, components]\n )\n}\n\nexport function MDXProvider(properties:any) {\n\n let allComponents: any\n\n if (properties.disableParentContext) {\n allComponents =\n typeof properties.components === 'function'\n ? properties.components(emptyComponents)\n : properties.components || emptyComponents\n } else {\n allComponents = useMDXComponents(properties.components)\n }\n\n return createElement(\n MDXContext.Provider,\n {value: allComponents},\n properties.children\n )\n}\n"],"mappings":"AAGA,SAAQ,eAAe,YAAY,SAAS,qBAAoB;AAChE,MAAM,kBAAkB,CAAC;AAEzB,MAAM,aAAa,cAAc,eAAe;AAEzC,SAAS,iBAAiB,YAAgB;AAC/C,QAAM,oBAAoB,WAAW,UAAU;AAG/C,SAAO;AAAA,IACL,WAAY;AAEV,UAAI,OAAO,eAAe,YAAY;AACpC,eAAO,WAAW,iBAAiB;AAAA,MACrC;AAEA,aAAO,EAAC,GAAG,mBAAmB,GAAG,WAAU;AAAA,IAC7C;AAAA,IACA,CAAC,mBAAmB,UAAU;AAAA,EAChC;AACF;AAEO,SAAS,YAAY,YAAgB;AAE1C,MAAI;AAEJ,MAAI,WAAW,sBAAsB;AACnC,oBACE,OAAO,WAAW,eAAe,aAC7B,WAAW,WAAW,eAAe,IACrC,WAAW,cAAc;AAAA,EACjC,OAAO;AACL,oBAAgB,iBAAiB,WAAW,UAAU;AAAA,EACxD;AAEA,SAAO;AAAA,IACL,WAAW;AAAA,IACX,EAAC,OAAO,cAAa;AAAA,IACrB,WAAW;AAAA,EACb;AACF;","names":[]}
|
|
@@ -0,0 +1,17 @@
|
|
|
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var RoutingSpec_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(RoutingSpec_exports);
|
|
17
|
+
//# sourceMappingURL=RoutingSpec.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/RoutingSpec.ts"],"sourcesContent":["import type { ReactNode } from 'react';\n\nexport type RoutingRule = {\n name?: string;\n pattern: string | RegExp;\n reactNode: ReactNode | string;\n};\n\nexport type RoutingSpec = {\n routes: RoutingRule[];\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=RoutingSpec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,30 @@
|
|
|
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 TinkerableContext_exports = {};
|
|
20
|
+
__export(TinkerableContext_exports, {
|
|
21
|
+
TinkerableContext: () => TinkerableContext
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(TinkerableContext_exports);
|
|
24
|
+
var import_react = require("react");
|
|
25
|
+
const TinkerableContext = (0, import_react.createContext)({});
|
|
26
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
27
|
+
0 && (module.exports = {
|
|
28
|
+
TinkerableContext
|
|
29
|
+
});
|
|
30
|
+
//# sourceMappingURL=TinkerableContext.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/TinkerableContext.ts"],"sourcesContent":["import {createContext} from 'react';\nimport { RoutingRule, RoutingSpec } from './RoutingSpec';\nimport { FilesMetadata } from './sandboxTypes';\n\n\nexport type PathState = {\n mode:string,\n namespace:string,\n provider:string,\n repository:string,\n ref:string,\n sandboxPath:string,\n pathParameters?: Record<string, string>\n routingRule?: RoutingRule\n}\n\nexport type NavigationState = PathState & {\n hash:string,\n search:string,\n}\n\nexport type TinkerableState = {\n outerHref: string,\n navigationState: NavigationState,\n routingSpec: RoutingSpec,\n filesMetadata: FilesMetadata;\n}\n\nexport const TinkerableContext = createContext<TinkerableState>({} as TinkerableState);\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA4B;AA4BrB,MAAM,wBAAoB,4BAA+B,CAAC,CAAoB;","names":[]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { RoutingRule, RoutingSpec } from './RoutingSpec.cjs';
|
|
3
|
+
import { FilesMetadata } from './sandboxTypes.cjs';
|
|
4
|
+
|
|
5
|
+
type PathState = {
|
|
6
|
+
mode: string;
|
|
7
|
+
namespace: string;
|
|
8
|
+
provider: string;
|
|
9
|
+
repository: string;
|
|
10
|
+
ref: string;
|
|
11
|
+
sandboxPath: string;
|
|
12
|
+
pathParameters?: Record<string, string>;
|
|
13
|
+
routingRule?: RoutingRule;
|
|
14
|
+
};
|
|
15
|
+
type NavigationState = PathState & {
|
|
16
|
+
hash: string;
|
|
17
|
+
search: string;
|
|
18
|
+
};
|
|
19
|
+
type TinkerableState = {
|
|
20
|
+
outerHref: string;
|
|
21
|
+
navigationState: NavigationState;
|
|
22
|
+
routingSpec: RoutingSpec;
|
|
23
|
+
filesMetadata: FilesMetadata;
|
|
24
|
+
};
|
|
25
|
+
declare const TinkerableContext: react.Context<TinkerableState>;
|
|
26
|
+
|
|
27
|
+
export { type NavigationState, type PathState, TinkerableContext, type TinkerableState };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { RoutingRule, RoutingSpec } from './RoutingSpec.js';
|
|
3
|
+
import { FilesMetadata } from './sandboxTypes.js';
|
|
4
|
+
|
|
5
|
+
type PathState = {
|
|
6
|
+
mode: string;
|
|
7
|
+
namespace: string;
|
|
8
|
+
provider: string;
|
|
9
|
+
repository: string;
|
|
10
|
+
ref: string;
|
|
11
|
+
sandboxPath: string;
|
|
12
|
+
pathParameters?: Record<string, string>;
|
|
13
|
+
routingRule?: RoutingRule;
|
|
14
|
+
};
|
|
15
|
+
type NavigationState = PathState & {
|
|
16
|
+
hash: string;
|
|
17
|
+
search: string;
|
|
18
|
+
};
|
|
19
|
+
type TinkerableState = {
|
|
20
|
+
outerHref: string;
|
|
21
|
+
navigationState: NavigationState;
|
|
22
|
+
routingSpec: RoutingSpec;
|
|
23
|
+
filesMetadata: FilesMetadata;
|
|
24
|
+
};
|
|
25
|
+
declare const TinkerableContext: react.Context<TinkerableState>;
|
|
26
|
+
|
|
27
|
+
export { type NavigationState, type PathState, TinkerableContext, type TinkerableState };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/TinkerableContext.ts"],"sourcesContent":["import {createContext} from 'react';\nimport { RoutingRule, RoutingSpec } from './RoutingSpec';\nimport { FilesMetadata } from './sandboxTypes';\n\n\nexport type PathState = {\n mode:string,\n namespace:string,\n provider:string,\n repository:string,\n ref:string,\n sandboxPath:string,\n pathParameters?: Record<string, string>\n routingRule?: RoutingRule\n}\n\nexport type NavigationState = PathState & {\n hash:string,\n search:string,\n}\n\nexport type TinkerableState = {\n outerHref: string,\n navigationState: NavigationState,\n routingSpec: RoutingSpec,\n filesMetadata: FilesMetadata;\n}\n\nexport const TinkerableContext = createContext<TinkerableState>({} as TinkerableState);\n"],"mappings":"AAAA,SAAQ,qBAAoB;AA4BrB,MAAM,oBAAoB,cAA+B,CAAC,CAAoB;","names":[]}
|
package/dist/boot.cjs
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
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 boot_exports = {};
|
|
20
|
+
__export(boot_exports, {
|
|
21
|
+
DEFAULT_ROUTING_SPEC: () => DEFAULT_ROUTING_SPEC,
|
|
22
|
+
TinkerableApp: () => TinkerableApp,
|
|
23
|
+
boot: () => boot
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(boot_exports);
|
|
26
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
27
|
+
var import_react = require("react");
|
|
28
|
+
var import_client = require("react-dom/client");
|
|
29
|
+
var import_errors = require("./components/errors");
|
|
30
|
+
var import_FileRouter = require("./components/FileRouter");
|
|
31
|
+
var import_MainContent = require("./components/MainContent");
|
|
32
|
+
var import_MDXComponents = require("./components/MDXComponents");
|
|
33
|
+
var import_contextUtils = require("./contextUtils");
|
|
34
|
+
var import_MDXProvider = require("./MDXProvider");
|
|
35
|
+
var import_moduleCache = require("./moduleCache");
|
|
36
|
+
var import_routing = require("./routing");
|
|
37
|
+
var import_sandboxUtils = require("./sandboxUtils");
|
|
38
|
+
var import_TinkerableContext = require("./TinkerableContext");
|
|
39
|
+
var import_urlUtils = require("./urlUtils");
|
|
40
|
+
const updateAlreadyApplied = (filesMetadata, update) => {
|
|
41
|
+
for (let [key, value] of Object.entries(update)) {
|
|
42
|
+
if (filesMetadata[key] !== value) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return true;
|
|
47
|
+
};
|
|
48
|
+
const TinkerableApp = ({ routingSpec }) => {
|
|
49
|
+
const [context, setContext] = (0, import_react.useState)((0, import_contextUtils.getInitialContext)(routingSpec));
|
|
50
|
+
(0, import_react.useEffect)(() => {
|
|
51
|
+
const removeListener = (0, import_sandboxUtils.addListener)("urlchange", ({ url }) => {
|
|
52
|
+
setContext((context2) => {
|
|
53
|
+
const updatedContext = (0, import_contextUtils.updateContext)(context2, url);
|
|
54
|
+
if (updatedContext !== context2) {
|
|
55
|
+
console.log(
|
|
56
|
+
`[Sandbox] Updating path from ${context2.navigationState.sandboxPath} to ${updatedContext.navigationState.sandboxPath}`
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
return updatedContext;
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
return removeListener;
|
|
63
|
+
}, [setContext]);
|
|
64
|
+
(0, import_react.useEffect)(() => {
|
|
65
|
+
const dispose = (0, import_sandboxUtils.addListener)(
|
|
66
|
+
"metadata-update",
|
|
67
|
+
({ update }) => {
|
|
68
|
+
setContext(
|
|
69
|
+
(prevContext) => updateAlreadyApplied(prevContext.filesMetadata, update) ? prevContext : {
|
|
70
|
+
...prevContext,
|
|
71
|
+
filesMetadata: {
|
|
72
|
+
// TODO: file deletion!
|
|
73
|
+
...prevContext.filesMetadata,
|
|
74
|
+
...update
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
);
|
|
78
|
+
},
|
|
79
|
+
// @ts-ignore
|
|
80
|
+
module.evaluation.module.bundler.onMetadataChange
|
|
81
|
+
);
|
|
82
|
+
module.evaluation.module.bundler.onMetadataChangeEmitter.enable();
|
|
83
|
+
return dispose;
|
|
84
|
+
}, [setContext]);
|
|
85
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TinkerableContext.TinkerableContext, { value: context, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_routing.Router, {}) });
|
|
86
|
+
};
|
|
87
|
+
const escapeForRegexp = (str) => str.replace(/[.*+\-?^${}()|[\]\\]/g, "\\$&");
|
|
88
|
+
const DEFAULT_ROUTING_SPEC = {
|
|
89
|
+
routes: [
|
|
90
|
+
{ name: "MainContent", pattern: /^\/$/, reactNode: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_MainContent.MainContent, {}) },
|
|
91
|
+
{
|
|
92
|
+
name: "FileRouter",
|
|
93
|
+
pattern: new RegExp(`^${escapeForRegexp(import_urlUtils.FILES_PREFIX)}(?<filename>/.+)$`),
|
|
94
|
+
reactNode: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_FileRouter.FileRouter, {})
|
|
95
|
+
},
|
|
96
|
+
{ name: "ErrorNotFound", pattern: /^(?<path>.+)$/, reactNode: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_errors.ErrorNotFound, {}) }
|
|
97
|
+
]
|
|
98
|
+
};
|
|
99
|
+
const boot = ({
|
|
100
|
+
mdxComponents = import_MDXComponents.DEFAULT_MDX_COMPONENTS,
|
|
101
|
+
routingSpec = DEFAULT_ROUTING_SPEC
|
|
102
|
+
} = {}) => {
|
|
103
|
+
const rootElement = document.getElementById("root");
|
|
104
|
+
if (!rootElement) {
|
|
105
|
+
throw new Error("boot requires root HTML element to exist");
|
|
106
|
+
}
|
|
107
|
+
const moduleCache = new import_moduleCache.ModuleCache();
|
|
108
|
+
const root = (0, import_client.createRoot)(rootElement);
|
|
109
|
+
root.render(
|
|
110
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.StrictMode, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_moduleCache.ModuleCacheContextProvider, { moduleCache, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_MDXProvider.MDXProvider, { components: mdxComponents, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TinkerableApp, { routingSpec }) }) }) })
|
|
111
|
+
);
|
|
112
|
+
};
|
|
113
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
114
|
+
0 && (module.exports = {
|
|
115
|
+
DEFAULT_ROUTING_SPEC,
|
|
116
|
+
TinkerableApp,
|
|
117
|
+
boot
|
|
118
|
+
});
|
|
119
|
+
//# sourceMappingURL=boot.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/boot.tsx"],"sourcesContent":["import { FC, StrictMode, useEffect, useState } from 'react';\nimport { createRoot } from 'react-dom/client';\n\nimport { ErrorNotFound } from './components/errors';\nimport { FileRouter } from './components/FileRouter';\nimport { MainContent } from './components/MainContent';\nimport { DEFAULT_MDX_COMPONENTS } from './components/MDXComponents';\nimport { getInitialContext, updateContext } from './contextUtils';\nimport { MDXProvider } from './MDXProvider';\nimport { ModuleCache, ModuleCacheContextProvider } from './moduleCache';\nimport { Router } from './routing';\nimport type { RoutingSpec } from './RoutingSpec';\nimport { FilesMetadata } from './sandboxTypes';\nimport { addListener } from './sandboxUtils';\nimport { TinkerableContext, TinkerableState } from './TinkerableContext';\nimport { FILES_PREFIX } from './urlUtils';\n\nexport type BootProps = {\n mdxComponents?: Record<string, FC>;\n routingSpec?: RoutingSpec;\n};\n\nconst updateAlreadyApplied = (filesMetadata: FilesMetadata, update: FilesMetadata) => {\n for (let [key, value] of Object.entries(update)) {\n if (filesMetadata[key] !== value) {\n return false;\n }\n }\n return true;\n};\n\nexport const TinkerableApp = ({ routingSpec }: { routingSpec: RoutingSpec }) => {\n const [context, setContext] = useState<TinkerableState>(getInitialContext(routingSpec));\n useEffect(() => {\n const removeListener = addListener('urlchange', ({ url }) => {\n setContext((context) => {\n const updatedContext = updateContext(context, url);\n if (updatedContext !== context) {\n console.log(\n `[Sandbox] Updating path from ${context.navigationState.sandboxPath} to ${updatedContext.navigationState.sandboxPath}`\n );\n }\n return updatedContext;\n });\n });\n return removeListener;\n }, [setContext]);\n useEffect(() => {\n const dispose = addListener(\n 'metadata-update',\n ({ update }: Record<string, any>) => {\n setContext((prevContext) =>\n updateAlreadyApplied(prevContext.filesMetadata, update)\n ? prevContext\n : {\n ...prevContext,\n filesMetadata: {\n // TODO: file deletion!\n ...prevContext.filesMetadata,\n ...update,\n },\n }\n );\n },\n // @ts-ignore\n module.evaluation.module.bundler.onMetadataChange\n );\n // @ts-ignore\n module.evaluation.module.bundler.onMetadataChangeEmitter.enable();\n return dispose;\n }, [setContext]);\n\n return (\n <TinkerableContext value={context}>\n <Router />\n </TinkerableContext>\n );\n};\n\n// from: https://stackoverflow.com/a/63838890\nconst escapeForRegexp = (str: string) => str.replace(/[.*+\\-?^${}()|[\\]\\\\]/g, '\\\\$&');\n\nexport const DEFAULT_ROUTING_SPEC: RoutingSpec = {\n routes: [\n { name: 'MainContent', pattern: /^\\/$/, reactNode: <MainContent /> },\n {\n name: 'FileRouter',\n pattern: new RegExp(`^${escapeForRegexp(FILES_PREFIX)}(?<filename>\\/.+)$`),\n reactNode: <FileRouter />,\n },\n { name: 'ErrorNotFound', pattern: /^(?<path>.+)$/, reactNode: <ErrorNotFound /> },\n ],\n};\n\nexport const boot = ({\n mdxComponents = DEFAULT_MDX_COMPONENTS,\n routingSpec = DEFAULT_ROUTING_SPEC,\n}: BootProps = {}) => {\n const rootElement = document.getElementById('root');\n if (!rootElement) {\n throw new Error('boot requires root HTML element to exist');\n }\n const moduleCache = new ModuleCache();\n const root = createRoot(rootElement);\n root.render(\n <StrictMode>\n <ModuleCacheContextProvider moduleCache={moduleCache}>\n <MDXProvider components={mdxComponents}>\n <TinkerableApp routingSpec={routingSpec} />\n </MDXProvider>\n </ModuleCacheContextProvider>\n </StrictMode>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA0EM;AA1EN,mBAAoD;AACpD,oBAA2B;AAE3B,oBAA8B;AAC9B,wBAA2B;AAC3B,yBAA4B;AAC5B,2BAAuC;AACvC,0BAAiD;AACjD,yBAA4B;AAC5B,yBAAwD;AACxD,qBAAuB;AAGvB,0BAA4B;AAC5B,+BAAmD;AACnD,sBAA6B;AAO7B,MAAM,uBAAuB,CAAC,eAA8B,WAA0B;AACpF,WAAS,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,MAAM,GAAG;AAC/C,QAAI,cAAc,GAAG,MAAM,OAAO;AAChC,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AAEO,MAAM,gBAAgB,CAAC,EAAE,YAAY,MAAoC;AAC9E,QAAM,CAAC,SAAS,UAAU,QAAI,2BAA0B,uCAAkB,WAAW,CAAC;AACtF,8BAAU,MAAM;AACd,UAAM,qBAAiB,iCAAY,aAAa,CAAC,EAAE,IAAI,MAAM;AAC3D,iBAAW,CAACA,aAAY;AACtB,cAAM,qBAAiB,mCAAcA,UAAS,GAAG;AACjD,YAAI,mBAAmBA,UAAS;AAC9B,kBAAQ;AAAA,YACN,gCAAgCA,SAAQ,gBAAgB,WAAW,OAAO,eAAe,gBAAgB,WAAW;AAAA,UACtH;AAAA,QACF;AACA,eAAO;AAAA,MACT,CAAC;AAAA,IACH,CAAC;AACD,WAAO;AAAA,EACT,GAAG,CAAC,UAAU,CAAC;AACf,8BAAU,MAAM;AACd,UAAM,cAAU;AAAA,MACd;AAAA,MACA,CAAC,EAAE,OAAO,MAA2B;AACnC;AAAA,UAAW,CAAC,gBACV,qBAAqB,YAAY,eAAe,MAAM,IAClD,cACA;AAAA,YACE,GAAG;A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from 'react';
|
|
3
|
+
import { RoutingSpec } from './RoutingSpec.cjs';
|
|
4
|
+
|
|
5
|
+
type BootProps = {
|
|
6
|
+
mdxComponents?: Record<string, FC>;
|
|
7
|
+
routingSpec?: RoutingSpec;
|
|
8
|
+
};
|
|
9
|
+
declare const TinkerableApp: ({ routingSpec }: {
|
|
10
|
+
routingSpec: RoutingSpec;
|
|
11
|
+
}) => react_jsx_runtime.JSX.Element;
|
|
12
|
+
declare const DEFAULT_ROUTING_SPEC: RoutingSpec;
|
|
13
|
+
declare const boot: ({ mdxComponents, routingSpec, }?: BootProps) => void;
|
|
14
|
+
|
|
15
|
+
export { type BootProps, DEFAULT_ROUTING_SPEC, TinkerableApp, boot };
|
package/dist/boot.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { FC } from 'react';
|
|
3
|
+
import { RoutingSpec } from './RoutingSpec.js';
|
|
4
|
+
|
|
5
|
+
type BootProps = {
|
|
6
|
+
mdxComponents?: Record<string, FC>;
|
|
7
|
+
routingSpec?: RoutingSpec;
|
|
8
|
+
};
|
|
9
|
+
declare const TinkerableApp: ({ routingSpec }: {
|
|
10
|
+
routingSpec: RoutingSpec;
|
|
11
|
+
}) => react_jsx_runtime.JSX.Element;
|
|
12
|
+
declare const DEFAULT_ROUTING_SPEC: RoutingSpec;
|
|
13
|
+
declare const boot: ({ mdxComponents, routingSpec, }?: BootProps) => void;
|
|
14
|
+
|
|
15
|
+
export { type BootProps, DEFAULT_ROUTING_SPEC, TinkerableApp, boot };
|
package/dist/boot.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { StrictMode, useEffect, useState } from "react";
|
|
3
|
+
import { createRoot } from "react-dom/client";
|
|
4
|
+
import { ErrorNotFound } from "./components/errors";
|
|
5
|
+
import { FileRouter } from "./components/FileRouter";
|
|
6
|
+
import { MainContent } from "./components/MainContent";
|
|
7
|
+
import { DEFAULT_MDX_COMPONENTS } from "./components/MDXComponents";
|
|
8
|
+
import { getInitialContext, updateContext } from "./contextUtils";
|
|
9
|
+
import { MDXProvider } from "./MDXProvider";
|
|
10
|
+
import { ModuleCache, ModuleCacheContextProvider } from "./moduleCache";
|
|
11
|
+
import { Router } from "./routing";
|
|
12
|
+
import { addListener } from "./sandboxUtils";
|
|
13
|
+
import { TinkerableContext } from "./TinkerableContext";
|
|
14
|
+
import { FILES_PREFIX } from "./urlUtils";
|
|
15
|
+
const updateAlreadyApplied = (filesMetadata, update) => {
|
|
16
|
+
for (let [key, value] of Object.entries(update)) {
|
|
17
|
+
if (filesMetadata[key] !== value) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return true;
|
|
22
|
+
};
|
|
23
|
+
const TinkerableApp = ({ routingSpec }) => {
|
|
24
|
+
const [context, setContext] = useState(getInitialContext(routingSpec));
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
const removeListener = addListener("urlchange", ({ url }) => {
|
|
27
|
+
setContext((context2) => {
|
|
28
|
+
const updatedContext = updateContext(context2, url);
|
|
29
|
+
if (updatedContext !== context2) {
|
|
30
|
+
console.log(
|
|
31
|
+
`[Sandbox] Updating path from ${context2.navigationState.sandboxPath} to ${updatedContext.navigationState.sandboxPath}`
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
return updatedContext;
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
return removeListener;
|
|
38
|
+
}, [setContext]);
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
const dispose = addListener(
|
|
41
|
+
"metadata-update",
|
|
42
|
+
({ update }) => {
|
|
43
|
+
setContext(
|
|
44
|
+
(prevContext) => updateAlreadyApplied(prevContext.filesMetadata, update) ? prevContext : {
|
|
45
|
+
...prevContext,
|
|
46
|
+
filesMetadata: {
|
|
47
|
+
// TODO: file deletion!
|
|
48
|
+
...prevContext.filesMetadata,
|
|
49
|
+
...update
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
},
|
|
54
|
+
// @ts-ignore
|
|
55
|
+
module.evaluation.module.bundler.onMetadataChange
|
|
56
|
+
);
|
|
57
|
+
module.evaluation.module.bundler.onMetadataChangeEmitter.enable();
|
|
58
|
+
return dispose;
|
|
59
|
+
}, [setContext]);
|
|
60
|
+
return /* @__PURE__ */ jsx(TinkerableContext, { value: context, children: /* @__PURE__ */ jsx(Router, {}) });
|
|
61
|
+
};
|
|
62
|
+
const escapeForRegexp = (str) => str.replace(/[.*+\-?^${}()|[\]\\]/g, "\\$&");
|
|
63
|
+
const DEFAULT_ROUTING_SPEC = {
|
|
64
|
+
routes: [
|
|
65
|
+
{ name: "MainContent", pattern: /^\/$/, reactNode: /* @__PURE__ */ jsx(MainContent, {}) },
|
|
66
|
+
{
|
|
67
|
+
name: "FileRouter",
|
|
68
|
+
pattern: new RegExp(`^${escapeForRegexp(FILES_PREFIX)}(?<filename>/.+)$`),
|
|
69
|
+
reactNode: /* @__PURE__ */ jsx(FileRouter, {})
|
|
70
|
+
},
|
|
71
|
+
{ name: "ErrorNotFound", pattern: /^(?<path>.+)$/, reactNode: /* @__PURE__ */ jsx(ErrorNotFound, {}) }
|
|
72
|
+
]
|
|
73
|
+
};
|
|
74
|
+
const boot = ({
|
|
75
|
+
mdxComponents = DEFAULT_MDX_COMPONENTS,
|
|
76
|
+
routingSpec = DEFAULT_ROUTING_SPEC
|
|
77
|
+
} = {}) => {
|
|
78
|
+
const rootElement = document.getElementById("root");
|
|
79
|
+
if (!rootElement) {
|
|
80
|
+
throw new Error("boot requires root HTML element to exist");
|
|
81
|
+
}
|
|
82
|
+
const moduleCache = new ModuleCache();
|
|
83
|
+
const root = createRoot(rootElement);
|
|
84
|
+
root.render(
|
|
85
|
+
/* @__PURE__ */ jsx(StrictMode, { children: /* @__PURE__ */ jsx(ModuleCacheContextProvider, { moduleCache, children: /* @__PURE__ */ jsx(MDXProvider, { components: mdxComponents, children: /* @__PURE__ */ jsx(TinkerableApp, { routingSpec }) }) }) })
|
|
86
|
+
);
|
|
87
|
+
};
|
|
88
|
+
export {
|
|
89
|
+
DEFAULT_ROUTING_SPEC,
|
|
90
|
+
TinkerableApp,
|
|
91
|
+
boot
|
|
92
|
+
};
|
|
93
|
+
//# sourceMappingURL=boot.js.map
|
package/dist/boot.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/boot.tsx"],"sourcesContent":["import { FC, StrictMode, useEffect, useState } from 'react';\nimport { createRoot } from 'react-dom/client';\n\nimport { ErrorNotFound } from './components/errors';\nimport { FileRouter } from './components/FileRouter';\nimport { MainContent } from './components/MainContent';\nimport { DEFAULT_MDX_COMPONENTS } from './components/MDXComponents';\nimport { getInitialContext, updateContext } from './contextUtils';\nimport { MDXProvider } from './MDXProvider';\nimport { ModuleCache, ModuleCacheContextProvider } from './moduleCache';\nimport { Router } from './routing';\nimport type { RoutingSpec } from './RoutingSpec';\nimport { FilesMetadata } from './sandboxTypes';\nimport { addListener } from './sandboxUtils';\nimport { TinkerableContext, TinkerableState } from './TinkerableContext';\nimport { FILES_PREFIX } from './urlUtils';\n\nexport type BootProps = {\n mdxComponents?: Record<string, FC>;\n routingSpec?: RoutingSpec;\n};\n\nconst updateAlreadyApplied = (filesMetadata: FilesMetadata, update: FilesMetadata) => {\n for (let [key, value] of Object.entries(update)) {\n if (filesMetadata[key] !== value) {\n return false;\n }\n }\n return true;\n};\n\nexport const TinkerableApp = ({ routingSpec }: { routingSpec: RoutingSpec }) => {\n const [context, setContext] = useState<TinkerableState>(getInitialContext(routingSpec));\n useEffect(() => {\n const removeListener = addListener('urlchange', ({ url }) => {\n setContext((context) => {\n const updatedContext = updateContext(context, url);\n if (updatedContext !== context) {\n console.log(\n `[Sandbox] Updating path from ${context.navigationState.sandboxPath} to ${updatedContext.navigationState.sandboxPath}`\n );\n }\n return updatedContext;\n });\n });\n return removeListener;\n }, [setContext]);\n useEffect(() => {\n const dispose = addListener(\n 'metadata-update',\n ({ update }: Record<string, any>) => {\n setContext((prevContext) =>\n updateAlreadyApplied(prevContext.filesMetadata, update)\n ? prevContext\n : {\n ...prevContext,\n filesMetadata: {\n // TODO: file deletion!\n ...prevContext.filesMetadata,\n ...update,\n },\n }\n );\n },\n // @ts-ignore\n module.evaluation.module.bundler.onMetadataChange\n );\n // @ts-ignore\n module.evaluation.module.bundler.onMetadataChangeEmitter.enable();\n return dispose;\n }, [setContext]);\n\n return (\n <TinkerableContext value={context}>\n <Router />\n </TinkerableContext>\n );\n};\n\n// from: https://stackoverflow.com/a/63838890\nconst escapeForRegexp = (str: string) => str.replace(/[.*+\\-?^${}()|[\\]\\\\]/g, '\\\\$&');\n\nexport const DEFAULT_ROUTING_SPEC: RoutingSpec = {\n routes: [\n { name: 'MainContent', pattern: /^\\/$/, reactNode: <MainContent /> },\n {\n name: 'FileRouter',\n pattern: new RegExp(`^${escapeForRegexp(FILES_PREFIX)}(?<filename>\\/.+)$`),\n reactNode: <FileRouter />,\n },\n { name: 'ErrorNotFound', pattern: /^(?<path>.+)$/, reactNode: <ErrorNotFound /> },\n ],\n};\n\nexport const boot = ({\n mdxComponents = DEFAULT_MDX_COMPONENTS,\n routingSpec = DEFAULT_ROUTING_SPEC,\n}: BootProps = {}) => {\n const rootElement = document.getElementById('root');\n if (!rootElement) {\n throw new Error('boot requires root HTML element to exist');\n }\n const moduleCache = new ModuleCache();\n const root = createRoot(rootElement);\n root.render(\n <StrictMode>\n <ModuleCacheContextProvider moduleCache={moduleCache}>\n <MDXProvider components={mdxComponents}>\n <TinkerableApp routingSpec={routingSpec} />\n </MDXProvider>\n </ModuleCacheContextProvider>\n </StrictMode>\n );\n};\n"],"mappings":"AA0EM;AA1EN,SAAa,YAAY,WAAW,gBAAgB;AACpD,SAAS,kBAAkB;AAE3B,SAAS,qBAAqB;AAC9B,SAAS,kBAAkB;AAC3B,SAAS,mBAAmB;AAC5B,SAAS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