@immediately-run/sdk 0.95.0 → 0.97.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/components/DirectoryView.cjs +62 -0
- package/dist/components/DirectoryView.cjs.map +1 -0
- package/dist/components/DirectoryView.d.cts +16 -0
- package/dist/components/DirectoryView.d.ts +16 -0
- package/dist/components/DirectoryView.js +39 -0
- package/dist/components/DirectoryView.js.map +1 -0
- package/dist/components/FileRouter.cjs +30 -1
- package/dist/components/FileRouter.cjs.map +1 -1
- package/dist/components/FileRouter.js +31 -2
- package/dist/components/FileRouter.js.map +1 -1
- package/dist/components/Prose.cjs +35 -2
- package/dist/components/Prose.cjs.map +1 -1
- package/dist/components/Prose.d.cts +10 -2
- package/dist/components/Prose.d.ts +10 -2
- package/dist/components/Prose.js +36 -3
- package/dist/components/Prose.js.map +1 -1
- package/dist/directoryListing.cjs +84 -0
- package/dist/directoryListing.cjs.map +1 -0
- package/dist/directoryListing.d.cts +34 -0
- package/dist/directoryListing.d.ts +34 -0
- package/dist/directoryListing.js +56 -0
- package/dist/directoryListing.js.map +1 -0
- package/dist/proseTokens.cjs +235 -0
- package/dist/proseTokens.cjs.map +1 -0
- package/dist/proseTokens.d.cts +80 -0
- package/dist/proseTokens.d.ts +80 -0
- package/dist/proseTokens.js +204 -0
- package/dist/proseTokens.js.map +1 -0
- package/dist/proseTokensHook.cjs +116 -0
- package/dist/proseTokensHook.cjs.map +1 -0
- package/dist/proseTokensHook.d.cts +10 -0
- package/dist/proseTokensHook.d.ts +10 -0
- package/dist/proseTokensHook.js +99 -0
- package/dist/proseTokensHook.js.map +1 -0
- package/dist/version.cjs +1 -1
- package/dist/version.cjs.map +1 -1
- package/dist/version.d.cts +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,62 @@
|
|
|
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 DirectoryView_exports = {};
|
|
20
|
+
__export(DirectoryView_exports, {
|
|
21
|
+
DirectoryView: () => DirectoryView
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(DirectoryView_exports);
|
|
24
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
25
|
+
var import_react = require("react");
|
|
26
|
+
var import_react_error_boundary = require("react-error-boundary");
|
|
27
|
+
var import_directoryListing = require("../directoryListing");
|
|
28
|
+
var import_urlUtils = require("../urlUtils");
|
|
29
|
+
var import_defaults = require("./defaults");
|
|
30
|
+
var import_Include = require("./Include");
|
|
31
|
+
var import_Link = require("./Link");
|
|
32
|
+
var import_Prose = require("./Prose");
|
|
33
|
+
const DirectoryListingView = ({ listingPromise }) => {
|
|
34
|
+
const { dir, parent, entries, readme } = (0, import_react.use)(listingPromise);
|
|
35
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_Prose.Prose, { filename: readme?.slice(1), children: [
|
|
36
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("nav", { "aria-label": `Contents of ${dir}`, "data-ir-directory": dir, children: [
|
|
37
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h1", { children: dir }),
|
|
38
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("ul", { children: [
|
|
39
|
+
parent !== null && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Link.Link, { href: parent, children: "../" }) }),
|
|
40
|
+
entries.map((entry) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Link.Link, { href: entry.path, children: entry.isDirectory ? `${entry.name}/` : entry.name }) }, entry.path))
|
|
41
|
+
] }),
|
|
42
|
+
entries.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: "This folder is empty." })
|
|
43
|
+
] }),
|
|
44
|
+
readme && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
45
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("hr", {}),
|
|
46
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Include.Include, { filename: (0, import_urlUtils.underAppRoot)(readme) })
|
|
47
|
+
] })
|
|
48
|
+
] });
|
|
49
|
+
};
|
|
50
|
+
const DirectoryView = ({
|
|
51
|
+
path,
|
|
52
|
+
LoadingComponent = import_defaults.defaultLoadingComponent,
|
|
53
|
+
ErrorComponent = import_defaults.defaultErrorComponent
|
|
54
|
+
}) => {
|
|
55
|
+
const listingPromise = (0, import_react.useMemo)(() => (0, import_directoryListing.readDirectoryListing)(path), [path]);
|
|
56
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_error_boundary.ErrorBoundary, { fallbackRender: ErrorComponent, resetKeys: [path], children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, { fallback: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LoadingComponent, {}), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DirectoryListingView, { listingPromise }) }) });
|
|
57
|
+
};
|
|
58
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
59
|
+
0 && (module.exports = {
|
|
60
|
+
DirectoryView
|
|
61
|
+
});
|
|
62
|
+
//# sourceMappingURL=DirectoryView.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/components/DirectoryView.tsx"],"sourcesContent":["import { Suspense, use, useMemo } from 'react';\nimport { ErrorBoundary } from 'react-error-boundary';\n\nimport { readDirectoryListing, type DirectoryListing } from '../directoryListing';\nimport { underAppRoot } from '../urlUtils';\nimport { defaultErrorComponent, defaultLoadingComponent } from './defaults';\nimport { Include } from './Include';\nimport { Link } from './Link';\nimport { Prose } from './Prose';\n\nconst DirectoryListingView = ({ listingPromise }: { listingPromise: Promise<DirectoryListing> }) => {\n const { dir, parent, entries, readme } = use(listingPromise);\n return (\n <Prose filename={readme?.slice(1)}>\n <nav aria-label={`Contents of ${dir}`} data-ir-directory={dir}>\n <h1>{dir}</h1>\n <ul>\n {parent !== null && (\n <li>\n <Link href={parent}>../</Link>\n </li>\n )}\n {entries.map((entry) => (\n <li key={entry.path}>\n <Link href={entry.path}>{entry.isDirectory ? `${entry.name}/` : entry.name}</Link>\n </li>\n ))}\n </ul>\n {entries.length === 0 && <p>This folder is empty.</p>}\n </nav>\n {readme && (\n <>\n <hr />\n <Include filename={underAppRoot(readme)} />\n </>\n )}\n </Prose>\n );\n};\n\n/**\n * The page for a folder routed under `/files/<dir>/`: its entries as links (folders first),\n * then the folder's README if it has one — the shape a code host gives a folder URL.\n */\nexport const DirectoryView = ({\n path,\n LoadingComponent = defaultLoadingComponent,\n ErrorComponent = defaultErrorComponent,\n}: {\n /** Repo-relative folder path, e.g. `tickets/`. */\n path: string;\n LoadingComponent?: typeof defaultLoadingComponent;\n ErrorComponent?: typeof defaultErrorComponent;\n}) => {\n // Keyed on the path string, so a re-render of the same folder reuses the one read.\n const listingPromise = useMemo(() => readDirectoryListing(path), [path]);\n return (\n <ErrorBoundary fallbackRender={ErrorComponent} resetKeys={[path]}>\n <Suspense fallback={<LoadingComponent />}>\n <DirectoryListingView listingPromise={listingPromise} />\n </Suspense>\n </ErrorBoundary>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAeQ;AAfR,mBAAuC;AACvC,kCAA8B;AAE9B,8BAA4D;AAC5D,sBAA6B;AAC7B,sBAA+D;AAC/D,qBAAwB;AACxB,kBAAqB;AACrB,mBAAsB;AAEtB,MAAM,uBAAuB,CAAC,EAAE,eAAe,MAAqD;AAClG,QAAM,EAAE,KAAK,QAAQ,SAAS,OAAO,QAAI,kBAAI,cAAc;AAC3D,SACE,6CAAC,sBAAM,UAAU,QAAQ,MAAM,CAAC,GAC9B;AAAA,iDAAC,SAAI,cAAY,eAAe,GAAG,IAAI,qBAAmB,KACxD;AAAA,kDAAC,QAAI,eAAI;AAAA,MACT,6CAAC,QACE;AAAA,mBAAW,QACV,4CAAC,QACC,sDAAC,oBAAK,MAAM,QAAQ,iBAAG,GACzB;AAAA,QAED,QAAQ,IAAI,CAAC,UACZ,4CAAC,QACC,sDAAC,oBAAK,MAAM,MAAM,MAAO,gBAAM,cAAc,GAAG,MAAM,IAAI,MAAM,MAAM,MAAK,KADpE,MAAM,IAEf,CACD;AAAA,SACH;AAAA,MACC,QAAQ,WAAW,KAAK,4CAAC,OAAE,mCAAqB;AAAA,OACnD;AAAA,IACC,UACC,4EACE;AAAA,kDAAC,QAAG;AAAA,MACJ,4CAAC,0BAAQ,cAAU,8BAAa,MAAM,GAAG;AAAA,OAC3C;AAAA,KAEJ;AAEJ;AAMO,MAAM,gBAAgB,CAAC;AAAA,EAC5B;AAAA,EACA,mBAAmB;AAAA,EACnB,iBAAiB;AACnB,MAKM;AAEJ,QAAM,qBAAiB,sBAAQ,UAAM,8CAAqB,IAAI,GAAG,CAAC,IAAI,CAAC;AACvE,SACE,4CAAC,6CAAc,gBAAgB,gBAAgB,WAAW,CAAC,IAAI,GAC7D,sDAAC,yBAAS,UAAU,4CAAC,oBAAiB,GACpC,sDAAC,wBAAqB,gBAAgC,GACxD,GACF;AAEJ;","names":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { defaultLoadingComponent, defaultErrorComponent } from './defaults.cjs';
|
|
3
|
+
import 'react-error-boundary';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The page for a folder routed under `/files/<dir>/`: its entries as links (folders first),
|
|
7
|
+
* then the folder's README if it has one — the shape a code host gives a folder URL.
|
|
8
|
+
*/
|
|
9
|
+
declare const DirectoryView: ({ path, LoadingComponent, ErrorComponent, }: {
|
|
10
|
+
/** Repo-relative folder path, e.g. `tickets/`. */
|
|
11
|
+
path: string;
|
|
12
|
+
LoadingComponent?: typeof defaultLoadingComponent;
|
|
13
|
+
ErrorComponent?: typeof defaultErrorComponent;
|
|
14
|
+
}) => react.JSX.Element;
|
|
15
|
+
|
|
16
|
+
export { DirectoryView };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { defaultLoadingComponent, defaultErrorComponent } from './defaults.js';
|
|
3
|
+
import 'react-error-boundary';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The page for a folder routed under `/files/<dir>/`: its entries as links (folders first),
|
|
7
|
+
* then the folder's README if it has one — the shape a code host gives a folder URL.
|
|
8
|
+
*/
|
|
9
|
+
declare const DirectoryView: ({ path, LoadingComponent, ErrorComponent, }: {
|
|
10
|
+
/** Repo-relative folder path, e.g. `tickets/`. */
|
|
11
|
+
path: string;
|
|
12
|
+
LoadingComponent?: typeof defaultLoadingComponent;
|
|
13
|
+
ErrorComponent?: typeof defaultErrorComponent;
|
|
14
|
+
}) => react.JSX.Element;
|
|
15
|
+
|
|
16
|
+
export { DirectoryView };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import "../chunk-VHAA22YE.js";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Suspense, use, useMemo } from "react";
|
|
4
|
+
import { ErrorBoundary } from "react-error-boundary";
|
|
5
|
+
import { readDirectoryListing } from "../directoryListing.js";
|
|
6
|
+
import { underAppRoot } from "../urlUtils.js";
|
|
7
|
+
import { defaultErrorComponent, defaultLoadingComponent } from "./defaults.js";
|
|
8
|
+
import { Include } from "./Include.js";
|
|
9
|
+
import { Link } from "./Link.js";
|
|
10
|
+
import { Prose } from "./Prose.js";
|
|
11
|
+
const DirectoryListingView = ({ listingPromise }) => {
|
|
12
|
+
const { dir, parent, entries, readme } = use(listingPromise);
|
|
13
|
+
return /* @__PURE__ */ jsxs(Prose, { filename: readme?.slice(1), children: [
|
|
14
|
+
/* @__PURE__ */ jsxs("nav", { "aria-label": `Contents of ${dir}`, "data-ir-directory": dir, children: [
|
|
15
|
+
/* @__PURE__ */ jsx("h1", { children: dir }),
|
|
16
|
+
/* @__PURE__ */ jsxs("ul", { children: [
|
|
17
|
+
parent !== null && /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(Link, { href: parent, children: "../" }) }),
|
|
18
|
+
entries.map((entry) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(Link, { href: entry.path, children: entry.isDirectory ? `${entry.name}/` : entry.name }) }, entry.path))
|
|
19
|
+
] }),
|
|
20
|
+
entries.length === 0 && /* @__PURE__ */ jsx("p", { children: "This folder is empty." })
|
|
21
|
+
] }),
|
|
22
|
+
readme && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
23
|
+
/* @__PURE__ */ jsx("hr", {}),
|
|
24
|
+
/* @__PURE__ */ jsx(Include, { filename: underAppRoot(readme) })
|
|
25
|
+
] })
|
|
26
|
+
] });
|
|
27
|
+
};
|
|
28
|
+
const DirectoryView = ({
|
|
29
|
+
path,
|
|
30
|
+
LoadingComponent = defaultLoadingComponent,
|
|
31
|
+
ErrorComponent = defaultErrorComponent
|
|
32
|
+
}) => {
|
|
33
|
+
const listingPromise = useMemo(() => readDirectoryListing(path), [path]);
|
|
34
|
+
return /* @__PURE__ */ jsx(ErrorBoundary, { fallbackRender: ErrorComponent, resetKeys: [path], children: /* @__PURE__ */ jsx(Suspense, { fallback: /* @__PURE__ */ jsx(LoadingComponent, {}), children: /* @__PURE__ */ jsx(DirectoryListingView, { listingPromise }) }) });
|
|
35
|
+
};
|
|
36
|
+
export {
|
|
37
|
+
DirectoryView
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=DirectoryView.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/components/DirectoryView.tsx"],"sourcesContent":["import { Suspense, use, useMemo } from 'react';\nimport { ErrorBoundary } from 'react-error-boundary';\n\nimport { readDirectoryListing, type DirectoryListing } from '../directoryListing';\nimport { underAppRoot } from '../urlUtils';\nimport { defaultErrorComponent, defaultLoadingComponent } from './defaults';\nimport { Include } from './Include';\nimport { Link } from './Link';\nimport { Prose } from './Prose';\n\nconst DirectoryListingView = ({ listingPromise }: { listingPromise: Promise<DirectoryListing> }) => {\n const { dir, parent, entries, readme } = use(listingPromise);\n return (\n <Prose filename={readme?.slice(1)}>\n <nav aria-label={`Contents of ${dir}`} data-ir-directory={dir}>\n <h1>{dir}</h1>\n <ul>\n {parent !== null && (\n <li>\n <Link href={parent}>../</Link>\n </li>\n )}\n {entries.map((entry) => (\n <li key={entry.path}>\n <Link href={entry.path}>{entry.isDirectory ? `${entry.name}/` : entry.name}</Link>\n </li>\n ))}\n </ul>\n {entries.length === 0 && <p>This folder is empty.</p>}\n </nav>\n {readme && (\n <>\n <hr />\n <Include filename={underAppRoot(readme)} />\n </>\n )}\n </Prose>\n );\n};\n\n/**\n * The page for a folder routed under `/files/<dir>/`: its entries as links (folders first),\n * then the folder's README if it has one — the shape a code host gives a folder URL.\n */\nexport const DirectoryView = ({\n path,\n LoadingComponent = defaultLoadingComponent,\n ErrorComponent = defaultErrorComponent,\n}: {\n /** Repo-relative folder path, e.g. `tickets/`. */\n path: string;\n LoadingComponent?: typeof defaultLoadingComponent;\n ErrorComponent?: typeof defaultErrorComponent;\n}) => {\n // Keyed on the path string, so a re-render of the same folder reuses the one read.\n const listingPromise = useMemo(() => readDirectoryListing(path), [path]);\n return (\n <ErrorBoundary fallbackRender={ErrorComponent} resetKeys={[path]}>\n <Suspense fallback={<LoadingComponent />}>\n <DirectoryListingView listingPromise={listingPromise} />\n </Suspense>\n </ErrorBoundary>\n );\n};\n"],"mappings":";AAeQ,SAgBA,UAhBA,KACA,YADA;AAfR,SAAS,UAAU,KAAK,eAAe;AACvC,SAAS,qBAAqB;AAE9B,SAAS,4BAAmD;AAC5D,SAAS,oBAAoB;AAC7B,SAAS,uBAAuB,+BAA+B;AAC/D,SAAS,eAAe;AACxB,SAAS,YAAY;AACrB,SAAS,aAAa;AAEtB,MAAM,uBAAuB,CAAC,EAAE,eAAe,MAAqD;AAClG,QAAM,EAAE,KAAK,QAAQ,SAAS,OAAO,IAAI,IAAI,cAAc;AAC3D,SACE,qBAAC,SAAM,UAAU,QAAQ,MAAM,CAAC,GAC9B;AAAA,yBAAC,SAAI,cAAY,eAAe,GAAG,IAAI,qBAAmB,KACxD;AAAA,0BAAC,QAAI,eAAI;AAAA,MACT,qBAAC,QACE;AAAA,mBAAW,QACV,oBAAC,QACC,8BAAC,QAAK,MAAM,QAAQ,iBAAG,GACzB;AAAA,QAED,QAAQ,IAAI,CAAC,UACZ,oBAAC,QACC,8BAAC,QAAK,MAAM,MAAM,MAAO,gBAAM,cAAc,GAAG,MAAM,IAAI,MAAM,MAAM,MAAK,KADpE,MAAM,IAEf,CACD;AAAA,SACH;AAAA,MACC,QAAQ,WAAW,KAAK,oBAAC,OAAE,mCAAqB;AAAA,OACnD;AAAA,IACC,UACC,iCACE;AAAA,0BAAC,QAAG;AAAA,MACJ,oBAAC,WAAQ,UAAU,aAAa,MAAM,GAAG;AAAA,OAC3C;AAAA,KAEJ;AAEJ;AAMO,MAAM,gBAAgB,CAAC;AAAA,EAC5B;AAAA,EACA,mBAAmB;AAAA,EACnB,iBAAiB;AACnB,MAKM;AAEJ,QAAM,iBAAiB,QAAQ,MAAM,qBAAqB,IAAI,GAAG,CAAC,IAAI,CAAC;AACvE,SACE,oBAAC,iBAAc,gBAAgB,gBAAgB,WAAW,CAAC,IAAI,GAC7D,8BAAC,YAAS,UAAU,oBAAC,oBAAiB,GACpC,8BAAC,wBAAqB,gBAAgC,GACxD,GACF;AAEJ;","names":[]}
|
|
@@ -23,9 +23,12 @@ __export(FileRouter_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(FileRouter_exports);
|
|
24
24
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
25
25
|
var import_react = require("react");
|
|
26
|
+
var import_react_error_boundary = require("react-error-boundary");
|
|
26
27
|
var import_TinkerableContext = require("../TinkerableContext");
|
|
27
28
|
var import_urlUtils = require("../urlUtils");
|
|
28
29
|
var import_defaults = require("./defaults");
|
|
30
|
+
var import_directoryListing = require("../directoryListing");
|
|
31
|
+
var import_DirectoryView = require("./DirectoryView");
|
|
29
32
|
var import_Include = require("./Include");
|
|
30
33
|
var import_Prose = require("./Prose");
|
|
31
34
|
var import_proseStyles = require("../proseStyles");
|
|
@@ -47,6 +50,32 @@ const FileRouter = ({
|
|
|
47
50
|
}
|
|
48
51
|
);
|
|
49
52
|
}
|
|
53
|
+
if ((0, import_directoryListing.namesDirectory)(filename)) {
|
|
54
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_DirectoryView.DirectoryView, { path: filename, LoadingComponent, ErrorComponent });
|
|
55
|
+
}
|
|
56
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FileOrDirectory, { filename, LoadingComponent, ErrorComponent });
|
|
57
|
+
};
|
|
58
|
+
const FileOrDirectory = ({ filename, LoadingComponent, ErrorComponent }) => {
|
|
59
|
+
const isDirectoryPromise = (0, import_react.useMemo)(() => (0, import_directoryListing.isDirectoryPath)(filename), [filename]);
|
|
60
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_error_boundary.ErrorBoundary, { fallbackRender: ErrorComponent, resetKeys: [filename], children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, { fallback: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LoadingComponent, {}), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
61
|
+
ResolvedPath,
|
|
62
|
+
{
|
|
63
|
+
filename,
|
|
64
|
+
isDirectoryPromise,
|
|
65
|
+
LoadingComponent,
|
|
66
|
+
ErrorComponent
|
|
67
|
+
}
|
|
68
|
+
) }) });
|
|
69
|
+
};
|
|
70
|
+
const ResolvedPath = ({
|
|
71
|
+
filename,
|
|
72
|
+
isDirectoryPromise,
|
|
73
|
+
LoadingComponent,
|
|
74
|
+
ErrorComponent
|
|
75
|
+
}) => {
|
|
76
|
+
if ((0, import_react.use)(isDirectoryPromise)) {
|
|
77
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_DirectoryView.DirectoryView, { path: filename, LoadingComponent, ErrorComponent });
|
|
78
|
+
}
|
|
50
79
|
const content = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
51
80
|
import_Include.Include,
|
|
52
81
|
{
|
|
@@ -56,7 +85,7 @@ const FileRouter = ({
|
|
|
56
85
|
baseModule: module
|
|
57
86
|
}
|
|
58
87
|
);
|
|
59
|
-
return (0, import_proseStyles.isProseFile)(filename) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Prose.Prose, { children: content }) : content;
|
|
88
|
+
return (0, import_proseStyles.isProseFile)(filename) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Prose.Prose, { filename, children: content }) : content;
|
|
60
89
|
};
|
|
61
90
|
// Annotate the CommonJS export names for ESM import in node:
|
|
62
91
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/FileRouter.tsx"],"sourcesContent":["import type { FC } from 'react';\nimport { useContext } from 'react';\n\nimport { TinkerableContext } from '../TinkerableContext';\nimport { underAppRoot } from '../urlUtils';\nimport { defaultErrorComponent, defaultLoadingComponent } from './defaults';\nimport { Include } from './Include';\nimport { Prose } from './Prose';\nimport { isProseFile } from '../proseStyles';\n\nexport const FileRouter: FC = ({\n LoadingComponent = defaultLoadingComponent,\n ErrorComponent = defaultErrorComponent,\n}: {\n LoadingComponent?: typeof defaultLoadingComponent;\n ErrorComponent?: typeof defaultErrorComponent;\n} = {}) => {\n const {\n navigationState: { pathParameters, sandboxPath },\n } = useContext(TinkerableContext);\n // The default table matches `/files/*`, surfacing the file path under the `*`\n // wildcard (SANDBOX_ROUTING_SPEC §4.1/§7).\n const filename = pathParameters?.['*'];\n if (!filename) {\n return (\n <ErrorComponent\n error={new Error(`No filename could be extracted from ${sandboxPath}`)}\n resetErrorBoundary={() => {}}\n />\n );\n }\n // URL subpaths are repo-relative; the sandbox fs is rooted at `/` with the\n // repo mounted at `APP_ROOT`, so anchor the file path there before resolving.\n const content = (\n <Include\n filename={underAppRoot(filename)}\n LoadingComponent={LoadingComponent}\n ErrorComponent={ErrorComponent}\n // @ts-ignore\n baseModule={module}\n />\n );\n // Markdown gets the default typography; a routed app component or HTML file renders as\n // it always has, so an app's own interface is never restyled.\n return isProseFile(filename) ? <Prose>{content}</Prose> : content;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
1
|
+
{"version":3,"sources":["../../src/components/FileRouter.tsx"],"sourcesContent":["import type { FC } from 'react';\nimport { Suspense, use, useContext, useMemo } from 'react';\nimport { ErrorBoundary } from 'react-error-boundary';\n\nimport { TinkerableContext } from '../TinkerableContext';\nimport { underAppRoot } from '../urlUtils';\nimport { defaultErrorComponent, defaultLoadingComponent } from './defaults';\nimport { isDirectoryPath, namesDirectory } from '../directoryListing';\nimport { DirectoryView } from './DirectoryView';\nimport { Include } from './Include';\nimport { Prose } from './Prose';\nimport { isProseFile } from '../proseStyles';\n\nexport const FileRouter: FC = ({\n LoadingComponent = defaultLoadingComponent,\n ErrorComponent = defaultErrorComponent,\n}: {\n LoadingComponent?: typeof defaultLoadingComponent;\n ErrorComponent?: typeof defaultErrorComponent;\n} = {}) => {\n const {\n navigationState: { pathParameters, sandboxPath },\n } = useContext(TinkerableContext);\n // The default table matches `/files/*`, surfacing the file path under the `*`\n // wildcard (SANDBOX_ROUTING_SPEC §4.1/§7).\n const filename = pathParameters?.['*'];\n if (!filename) {\n return (\n <ErrorComponent\n error={new Error(`No filename could be extracted from ${sandboxPath}`)}\n resetErrorBoundary={() => {}}\n />\n );\n }\n // A trailing slash names a folder outright (`[tickets/](tickets/)` in a README); without\n // one the path may still be a folder, so the fs decides before the module loader is asked\n // to `require` it — which, for a folder, fails with \"Cannot find module '/app/tickets'\".\n if (namesDirectory(filename)) {\n return <DirectoryView path={filename} LoadingComponent={LoadingComponent} ErrorComponent={ErrorComponent} />;\n }\n return <FileOrDirectory filename={filename} LoadingComponent={LoadingComponent} ErrorComponent={ErrorComponent} />;\n};\n\ntype Slots = {\n LoadingComponent: typeof defaultLoadingComponent;\n ErrorComponent: typeof defaultErrorComponent;\n};\n\nconst FileOrDirectory = ({ filename, LoadingComponent, ErrorComponent }: { filename: string } & Slots) => {\n // Keyed on the path string only, so a suspended retry reuses the same probe.\n const isDirectoryPromise = useMemo(() => isDirectoryPath(filename), [filename]);\n return (\n <ErrorBoundary fallbackRender={ErrorComponent} resetKeys={[filename]}>\n <Suspense fallback={<LoadingComponent />}>\n <ResolvedPath\n filename={filename}\n isDirectoryPromise={isDirectoryPromise}\n LoadingComponent={LoadingComponent}\n ErrorComponent={ErrorComponent}\n />\n </Suspense>\n </ErrorBoundary>\n );\n};\n\nconst ResolvedPath = ({\n filename,\n isDirectoryPromise,\n LoadingComponent,\n ErrorComponent,\n}: { filename: string; isDirectoryPromise: Promise<boolean> } & Slots) => {\n if (use(isDirectoryPromise)) {\n return <DirectoryView path={filename} LoadingComponent={LoadingComponent} ErrorComponent={ErrorComponent} />;\n }\n // URL subpaths are repo-relative; the sandbox fs is rooted at `/` with the\n // repo mounted at `APP_ROOT`, so anchor the file path there before resolving.\n const content = (\n <Include\n filename={underAppRoot(filename)}\n LoadingComponent={LoadingComponent}\n ErrorComponent={ErrorComponent}\n // @ts-ignore\n baseModule={module}\n />\n );\n // Markdown gets the default typography; a routed app component or HTML file renders as\n // it always has, so an app's own interface is never restyled.\n return isProseFile(filename) ? <Prose filename={filename}>{content}</Prose> : content;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA4BM;AA3BN,mBAAmD;AACnD,kCAA8B;AAE9B,+BAAkC;AAClC,sBAA6B;AAC7B,sBAA+D;AAC/D,8BAAgD;AAChD,2BAA8B;AAC9B,qBAAwB;AACxB,mBAAsB;AACtB,yBAA4B;AAErB,MAAM,aAAiB,CAAC;AAAA,EAC7B,mBAAmB;AAAA,EACnB,iBAAiB;AACnB,IAGI,CAAC,MAAM;AACT,QAAM;AAAA,IACJ,iBAAiB,EAAE,gBAAgB,YAAY;AAAA,EACjD,QAAI,yBAAW,0CAAiB;AAGhC,QAAM,WAAW,iBAAiB,GAAG;AACrC,MAAI,CAAC,UAAU;AACb,WACE;AAAA,MAAC;AAAA;AAAA,QACC,OAAO,IAAI,MAAM,uCAAuC,WAAW,EAAE;AAAA,QACrE,oBAAoB,MAAM;AAAA,QAAC;AAAA;AAAA,IAC7B;AAAA,EAEJ;AAIA,UAAI,wCAAe,QAAQ,GAAG;AAC5B,WAAO,4CAAC,sCAAc,MAAM,UAAU,kBAAoC,gBAAgC;AAAA,EAC5G;AACA,SAAO,4CAAC,mBAAgB,UAAoB,kBAAoC,gBAAgC;AAClH;AAOA,MAAM,kBAAkB,CAAC,EAAE,UAAU,kBAAkB,eAAe,MAAoC;AAExG,QAAM,yBAAqB,sBAAQ,UAAM,yCAAgB,QAAQ,GAAG,CAAC,QAAQ,CAAC;AAC9E,SACE,4CAAC,6CAAc,gBAAgB,gBAAgB,WAAW,CAAC,QAAQ,GACjE,sDAAC,yBAAS,UAAU,4CAAC,oBAAiB,GACpC;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA;AAAA,EACF,GACF,GACF;AAEJ;AAEA,MAAM,eAAe,CAAC;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAA0E;AACxE,UAAI,kBAAI,kBAAkB,GAAG;AAC3B,WAAO,4CAAC,sCAAc,MAAM,UAAU,kBAAoC,gBAAgC;AAAA,EAC5G;AAGA,QAAM,UACJ;AAAA,IAAC;AAAA;AAAA,MACC,cAAU,8BAAa,QAAQ;AAAA,MAC/B;AAAA,MACA;AAAA,MAEA,YAAY;AAAA;AAAA,EACd;AAIF,aAAO,gCAAY,QAAQ,IAAI,4CAAC,sBAAM,UAAqB,mBAAQ,IAAW;AAChF;","names":[]}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import "../chunk-VHAA22YE.js";
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
|
-
import { useContext } from "react";
|
|
3
|
+
import { Suspense, use, useContext, useMemo } from "react";
|
|
4
|
+
import { ErrorBoundary } from "react-error-boundary";
|
|
4
5
|
import { TinkerableContext } from "../TinkerableContext.js";
|
|
5
6
|
import { underAppRoot } from "../urlUtils.js";
|
|
6
7
|
import { defaultErrorComponent, defaultLoadingComponent } from "./defaults.js";
|
|
8
|
+
import { isDirectoryPath, namesDirectory } from "../directoryListing.js";
|
|
9
|
+
import { DirectoryView } from "./DirectoryView.js";
|
|
7
10
|
import { Include } from "./Include.js";
|
|
8
11
|
import { Prose } from "./Prose.js";
|
|
9
12
|
import { isProseFile } from "../proseStyles.js";
|
|
@@ -25,6 +28,32 @@ const FileRouter = ({
|
|
|
25
28
|
}
|
|
26
29
|
);
|
|
27
30
|
}
|
|
31
|
+
if (namesDirectory(filename)) {
|
|
32
|
+
return /* @__PURE__ */ jsx(DirectoryView, { path: filename, LoadingComponent, ErrorComponent });
|
|
33
|
+
}
|
|
34
|
+
return /* @__PURE__ */ jsx(FileOrDirectory, { filename, LoadingComponent, ErrorComponent });
|
|
35
|
+
};
|
|
36
|
+
const FileOrDirectory = ({ filename, LoadingComponent, ErrorComponent }) => {
|
|
37
|
+
const isDirectoryPromise = useMemo(() => isDirectoryPath(filename), [filename]);
|
|
38
|
+
return /* @__PURE__ */ jsx(ErrorBoundary, { fallbackRender: ErrorComponent, resetKeys: [filename], children: /* @__PURE__ */ jsx(Suspense, { fallback: /* @__PURE__ */ jsx(LoadingComponent, {}), children: /* @__PURE__ */ jsx(
|
|
39
|
+
ResolvedPath,
|
|
40
|
+
{
|
|
41
|
+
filename,
|
|
42
|
+
isDirectoryPromise,
|
|
43
|
+
LoadingComponent,
|
|
44
|
+
ErrorComponent
|
|
45
|
+
}
|
|
46
|
+
) }) });
|
|
47
|
+
};
|
|
48
|
+
const ResolvedPath = ({
|
|
49
|
+
filename,
|
|
50
|
+
isDirectoryPromise,
|
|
51
|
+
LoadingComponent,
|
|
52
|
+
ErrorComponent
|
|
53
|
+
}) => {
|
|
54
|
+
if (use(isDirectoryPromise)) {
|
|
55
|
+
return /* @__PURE__ */ jsx(DirectoryView, { path: filename, LoadingComponent, ErrorComponent });
|
|
56
|
+
}
|
|
28
57
|
const content = /* @__PURE__ */ jsx(
|
|
29
58
|
Include,
|
|
30
59
|
{
|
|
@@ -34,7 +63,7 @@ const FileRouter = ({
|
|
|
34
63
|
baseModule: module
|
|
35
64
|
}
|
|
36
65
|
);
|
|
37
|
-
return isProseFile(filename) ? /* @__PURE__ */ jsx(Prose, { children: content }) : content;
|
|
66
|
+
return isProseFile(filename) ? /* @__PURE__ */ jsx(Prose, { filename, children: content }) : content;
|
|
38
67
|
};
|
|
39
68
|
export {
|
|
40
69
|
FileRouter
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/FileRouter.tsx"],"sourcesContent":["import type { FC } from 'react';\nimport { useContext } from 'react';\n\nimport { TinkerableContext } from '../TinkerableContext';\nimport { underAppRoot } from '../urlUtils';\nimport { defaultErrorComponent, defaultLoadingComponent } from './defaults';\nimport { Include } from './Include';\nimport { Prose } from './Prose';\nimport { isProseFile } from '../proseStyles';\n\nexport const FileRouter: FC = ({\n LoadingComponent = defaultLoadingComponent,\n ErrorComponent = defaultErrorComponent,\n}: {\n LoadingComponent?: typeof defaultLoadingComponent;\n ErrorComponent?: typeof defaultErrorComponent;\n} = {}) => {\n const {\n navigationState: { pathParameters, sandboxPath },\n } = useContext(TinkerableContext);\n // The default table matches `/files/*`, surfacing the file path under the `*`\n // wildcard (SANDBOX_ROUTING_SPEC §4.1/§7).\n const filename = pathParameters?.['*'];\n if (!filename) {\n return (\n <ErrorComponent\n error={new Error(`No filename could be extracted from ${sandboxPath}`)}\n resetErrorBoundary={() => {}}\n />\n );\n }\n // URL subpaths are repo-relative; the sandbox fs is rooted at `/` with the\n // repo mounted at `APP_ROOT`, so anchor the file path there before resolving.\n const content = (\n <Include\n filename={underAppRoot(filename)}\n LoadingComponent={LoadingComponent}\n ErrorComponent={ErrorComponent}\n // @ts-ignore\n baseModule={module}\n />\n );\n // Markdown gets the default typography; a routed app component or HTML file renders as\n // it always has, so an app's own interface is never restyled.\n return isProseFile(filename) ? <Prose>{content}</Prose> : content;\n};\n"],"mappings":";
|
|
1
|
+
{"version":3,"sources":["../../src/components/FileRouter.tsx"],"sourcesContent":["import type { FC } from 'react';\nimport { Suspense, use, useContext, useMemo } from 'react';\nimport { ErrorBoundary } from 'react-error-boundary';\n\nimport { TinkerableContext } from '../TinkerableContext';\nimport { underAppRoot } from '../urlUtils';\nimport { defaultErrorComponent, defaultLoadingComponent } from './defaults';\nimport { isDirectoryPath, namesDirectory } from '../directoryListing';\nimport { DirectoryView } from './DirectoryView';\nimport { Include } from './Include';\nimport { Prose } from './Prose';\nimport { isProseFile } from '../proseStyles';\n\nexport const FileRouter: FC = ({\n LoadingComponent = defaultLoadingComponent,\n ErrorComponent = defaultErrorComponent,\n}: {\n LoadingComponent?: typeof defaultLoadingComponent;\n ErrorComponent?: typeof defaultErrorComponent;\n} = {}) => {\n const {\n navigationState: { pathParameters, sandboxPath },\n } = useContext(TinkerableContext);\n // The default table matches `/files/*`, surfacing the file path under the `*`\n // wildcard (SANDBOX_ROUTING_SPEC §4.1/§7).\n const filename = pathParameters?.['*'];\n if (!filename) {\n return (\n <ErrorComponent\n error={new Error(`No filename could be extracted from ${sandboxPath}`)}\n resetErrorBoundary={() => {}}\n />\n );\n }\n // A trailing slash names a folder outright (`[tickets/](tickets/)` in a README); without\n // one the path may still be a folder, so the fs decides before the module loader is asked\n // to `require` it — which, for a folder, fails with \"Cannot find module '/app/tickets'\".\n if (namesDirectory(filename)) {\n return <DirectoryView path={filename} LoadingComponent={LoadingComponent} ErrorComponent={ErrorComponent} />;\n }\n return <FileOrDirectory filename={filename} LoadingComponent={LoadingComponent} ErrorComponent={ErrorComponent} />;\n};\n\ntype Slots = {\n LoadingComponent: typeof defaultLoadingComponent;\n ErrorComponent: typeof defaultErrorComponent;\n};\n\nconst FileOrDirectory = ({ filename, LoadingComponent, ErrorComponent }: { filename: string } & Slots) => {\n // Keyed on the path string only, so a suspended retry reuses the same probe.\n const isDirectoryPromise = useMemo(() => isDirectoryPath(filename), [filename]);\n return (\n <ErrorBoundary fallbackRender={ErrorComponent} resetKeys={[filename]}>\n <Suspense fallback={<LoadingComponent />}>\n <ResolvedPath\n filename={filename}\n isDirectoryPromise={isDirectoryPromise}\n LoadingComponent={LoadingComponent}\n ErrorComponent={ErrorComponent}\n />\n </Suspense>\n </ErrorBoundary>\n );\n};\n\nconst ResolvedPath = ({\n filename,\n isDirectoryPromise,\n LoadingComponent,\n ErrorComponent,\n}: { filename: string; isDirectoryPromise: Promise<boolean> } & Slots) => {\n if (use(isDirectoryPromise)) {\n return <DirectoryView path={filename} LoadingComponent={LoadingComponent} ErrorComponent={ErrorComponent} />;\n }\n // URL subpaths are repo-relative; the sandbox fs is rooted at `/` with the\n // repo mounted at `APP_ROOT`, so anchor the file path there before resolving.\n const content = (\n <Include\n filename={underAppRoot(filename)}\n LoadingComponent={LoadingComponent}\n ErrorComponent={ErrorComponent}\n // @ts-ignore\n baseModule={module}\n />\n );\n // Markdown gets the default typography; a routed app component or HTML file renders as\n // it always has, so an app's own interface is never restyled.\n return isProseFile(filename) ? <Prose filename={filename}>{content}</Prose> : content;\n};\n"],"mappings":";AA4BM;AA3BN,SAAS,UAAU,KAAK,YAAY,eAAe;AACnD,SAAS,qBAAqB;AAE9B,SAAS,yBAAyB;AAClC,SAAS,oBAAoB;AAC7B,SAAS,uBAAuB,+BAA+B;AAC/D,SAAS,iBAAiB,sBAAsB;AAChD,SAAS,qBAAqB;AAC9B,SAAS,eAAe;AACxB,SAAS,aAAa;AACtB,SAAS,mBAAmB;AAErB,MAAM,aAAiB,CAAC;AAAA,EAC7B,mBAAmB;AAAA,EACnB,iBAAiB;AACnB,IAGI,CAAC,MAAM;AACT,QAAM;AAAA,IACJ,iBAAiB,EAAE,gBAAgB,YAAY;AAAA,EACjD,IAAI,WAAW,iBAAiB;AAGhC,QAAM,WAAW,iBAAiB,GAAG;AACrC,MAAI,CAAC,UAAU;AACb,WACE;AAAA,MAAC;AAAA;AAAA,QACC,OAAO,IAAI,MAAM,uCAAuC,WAAW,EAAE;AAAA,QACrE,oBAAoB,MAAM;AAAA,QAAC;AAAA;AAAA,IAC7B;AAAA,EAEJ;AAIA,MAAI,eAAe,QAAQ,GAAG;AAC5B,WAAO,oBAAC,iBAAc,MAAM,UAAU,kBAAoC,gBAAgC;AAAA,EAC5G;AACA,SAAO,oBAAC,mBAAgB,UAAoB,kBAAoC,gBAAgC;AAClH;AAOA,MAAM,kBAAkB,CAAC,EAAE,UAAU,kBAAkB,eAAe,MAAoC;AAExG,QAAM,qBAAqB,QAAQ,MAAM,gBAAgB,QAAQ,GAAG,CAAC,QAAQ,CAAC;AAC9E,SACE,oBAAC,iBAAc,gBAAgB,gBAAgB,WAAW,CAAC,QAAQ,GACjE,8BAAC,YAAS,UAAU,oBAAC,oBAAiB,GACpC;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA;AAAA,EACF,GACF,GACF;AAEJ;AAEA,MAAM,eAAe,CAAC;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAA0E;AACxE,MAAI,IAAI,kBAAkB,GAAG;AAC3B,WAAO,oBAAC,iBAAc,MAAM,UAAU,kBAAoC,gBAAgC;AAAA,EAC5G;AAGA,QAAM,UACJ;AAAA,IAAC;AAAA;AAAA,MACC,UAAU,aAAa,QAAQ;AAAA,MAC/B;AAAA,MACA;AAAA,MAEA,YAAY;AAAA;AAAA,EACd;AAIF,SAAO,YAAY,QAAQ,IAAI,oBAAC,SAAM,UAAqB,mBAAQ,IAAW;AAChF;","names":[]}
|
|
@@ -24,13 +24,46 @@ module.exports = __toCommonJS(Prose_exports);
|
|
|
24
24
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
25
25
|
var import_react = require("react");
|
|
26
26
|
var import_proseStyles = require("../proseStyles");
|
|
27
|
+
var import_proseTokens = require("../proseTokens");
|
|
28
|
+
var import_proseTokensHook = require("../proseTokensHook");
|
|
27
29
|
var import_theme = require("../theme");
|
|
28
|
-
const
|
|
30
|
+
const assignRef = (ref, value) => {
|
|
31
|
+
if (typeof ref === "function") ref(value);
|
|
32
|
+
else if (ref) ref.current = value;
|
|
33
|
+
};
|
|
34
|
+
const Prose = ({ className, children, filename, ref, ...rest }) => {
|
|
29
35
|
(0, import_react.useLayoutEffect)(() => {
|
|
30
36
|
(0, import_proseStyles.ensureProseStyles)();
|
|
31
37
|
}, []);
|
|
32
38
|
const theme = (0, import_theme.useHostTheme)();
|
|
33
|
-
|
|
39
|
+
const tokens = (0, import_proseTokensHook.useProseTokens)(filename);
|
|
40
|
+
const element = (0, import_react.useRef)(null);
|
|
41
|
+
const setElement = (0, import_react.useCallback)(
|
|
42
|
+
(node) => {
|
|
43
|
+
element.current = node;
|
|
44
|
+
assignRef(ref, node);
|
|
45
|
+
},
|
|
46
|
+
[ref]
|
|
47
|
+
);
|
|
48
|
+
(0, import_react.useLayoutEffect)(() => {
|
|
49
|
+
const el = element.current;
|
|
50
|
+
if (!el || !tokens) return;
|
|
51
|
+
const entries = (0, import_proseTokens.tokensFor)(tokens, theme);
|
|
52
|
+
for (const [name, value] of entries) el.style.setProperty(name, value);
|
|
53
|
+
return () => {
|
|
54
|
+
for (const [name] of entries) el.style.removeProperty(name);
|
|
55
|
+
};
|
|
56
|
+
}, [tokens, theme]);
|
|
57
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
58
|
+
"article",
|
|
59
|
+
{
|
|
60
|
+
...rest,
|
|
61
|
+
ref: setElement,
|
|
62
|
+
className: className ? `${import_proseStyles.PROSE_CLASS} ${className}` : import_proseStyles.PROSE_CLASS,
|
|
63
|
+
"data-theme": theme,
|
|
64
|
+
children
|
|
65
|
+
}
|
|
66
|
+
);
|
|
34
67
|
};
|
|
35
68
|
// Annotate the CommonJS export names for ESM import in node:
|
|
36
69
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/Prose.tsx"],"sourcesContent":["import { useLayoutEffect, type ComponentPropsWithRef } from 'react';\n\nimport { ensureProseStyles, PROSE_CLASS } from '../proseStyles';\nimport { useHostTheme } from '../theme';\n\n/**\n * The wrapper for rendered Markdown: an `<article class=\"ir-prose\">` styled by the SDK's\n * layered default stylesheet and keyed to the host theme through `data-theme`.\n *\n * `FileRouter` uses it for every routed `.md`/`.mdx` file. An app that renders Markdown\n * itself can wrap its content in it to get the same typography; any unlayered CSS the app\n * ships overrides the defaults, and setting a token such as `--accent` or `--sans` on an\n * ancestor restyles every rule that reads it.\n */\nexport const Prose = ({ className, children, ...rest }:
|
|
1
|
+
{"version":3,"sources":["../../src/components/Prose.tsx"],"sourcesContent":["import { useCallback, useLayoutEffect, useRef, type ComponentPropsWithRef, type Ref } from 'react';\n\nimport { ensureProseStyles, PROSE_CLASS } from '../proseStyles';\nimport { tokensFor } from '../proseTokens';\nimport { useProseTokens } from '../proseTokensHook';\nimport { useHostTheme } from '../theme';\n\nexport interface ProseProps extends ComponentPropsWithRef<'article'> {\n /**\n * The repo-relative path of the Markdown file this wraps. When set, the author token\n * file that governs it (`PROSE_TOKEN_FILE`, or the file a bundle marker's `styles`\n * names — MARKDOWN_SYNTAX_SPEC §16.6) restyles this article. `FileRouter` passes it.\n */\n filename?: string;\n}\n\nconst assignRef = <T,>(ref: Ref<T> | undefined, value: T | null): void => {\n if (typeof ref === 'function') ref(value);\n else if (ref) (ref as { current: T | null }).current = value;\n};\n\n/**\n * The wrapper for rendered Markdown: an `<article class=\"ir-prose\">` styled by the SDK's\n * layered default stylesheet and keyed to the host theme through `data-theme`.\n *\n * `FileRouter` uses it for every routed `.md`/`.mdx` file. An app that renders Markdown\n * itself can wrap its content in it to get the same typography; any unlayered CSS the app\n * ships overrides the defaults, and setting a token such as `--accent` or `--sans` on an\n * ancestor restyles every rule that reads it.\n */\nexport const Prose = ({ className, children, filename, ref, ...rest }: ProseProps) => {\n useLayoutEffect(() => {\n ensureProseStyles();\n }, []);\n const theme = useHostTheme();\n const tokens = useProseTokens(filename);\n const element = useRef<HTMLElement | null>(null);\n const setElement = useCallback(\n (node: HTMLElement | null) => {\n element.current = node;\n assignRef(ref, node);\n },\n [ref],\n );\n\n // Author tokens are SET, one property at a time, on this element; never written as CSS\n // text. Each set is removed before the next (a token dropped from the file must stop\n // applying) and on unmount.\n useLayoutEffect(() => {\n const el = element.current;\n if (!el || !tokens) return;\n const entries = tokensFor(tokens, theme);\n for (const [name, value] of entries) el.style.setProperty(name, value);\n return () => {\n for (const [name] of entries) el.style.removeProperty(name);\n };\n }, [tokens, theme]);\n\n return (\n <article\n {...rest}\n ref={setElement}\n className={className ? `${PROSE_CLASS} ${className}` : PROSE_CLASS}\n data-theme={theme}\n >\n {children}\n </article>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA2DI;AA3DJ,mBAA2F;AAE3F,yBAA+C;AAC/C,yBAA0B;AAC1B,6BAA+B;AAC/B,mBAA6B;AAW7B,MAAM,YAAY,CAAK,KAAyB,UAA0B;AACxE,MAAI,OAAO,QAAQ,WAAY,KAAI,KAAK;AAAA,WAC/B,IAAK,CAAC,IAA8B,UAAU;AACzD;AAWO,MAAM,QAAQ,CAAC,EAAE,WAAW,UAAU,UAAU,KAAK,GAAG,KAAK,MAAkB;AACpF,oCAAgB,MAAM;AACpB,8CAAkB;AAAA,EACpB,GAAG,CAAC,CAAC;AACL,QAAM,YAAQ,2BAAa;AAC3B,QAAM,aAAS,uCAAe,QAAQ;AACtC,QAAM,cAAU,qBAA2B,IAAI;AAC/C,QAAM,iBAAa;AAAA,IACjB,CAAC,SAA6B;AAC5B,cAAQ,UAAU;AAClB,gBAAU,KAAK,IAAI;AAAA,IACrB;AAAA,IACA,CAAC,GAAG;AAAA,EACN;AAKA,oCAAgB,MAAM;AACpB,UAAM,KAAK,QAAQ;AACnB,QAAI,CAAC,MAAM,CAAC,OAAQ;AACpB,UAAM,cAAU,8BAAU,QAAQ,KAAK;AACvC,eAAW,CAAC,MAAM,KAAK,KAAK,QAAS,IAAG,MAAM,YAAY,MAAM,KAAK;AACrE,WAAO,MAAM;AACX,iBAAW,CAAC,IAAI,KAAK,QAAS,IAAG,MAAM,eAAe,IAAI;AAAA,IAC5D;AAAA,EACF,GAAG,CAAC,QAAQ,KAAK,CAAC;AAElB,SACE;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACJ,KAAK;AAAA,MACL,WAAW,YAAY,GAAG,8BAAW,IAAI,SAAS,KAAK;AAAA,MACvD,cAAY;AAAA,MAEX;AAAA;AAAA,EACH;AAEJ;","names":[]}
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ComponentPropsWithRef } from 'react';
|
|
3
3
|
|
|
4
|
+
interface ProseProps extends ComponentPropsWithRef<'article'> {
|
|
5
|
+
/**
|
|
6
|
+
* The repo-relative path of the Markdown file this wraps. When set, the author token
|
|
7
|
+
* file that governs it (`PROSE_TOKEN_FILE`, or the file a bundle marker's `styles`
|
|
8
|
+
* names — MARKDOWN_SYNTAX_SPEC §16.6) restyles this article. `FileRouter` passes it.
|
|
9
|
+
*/
|
|
10
|
+
filename?: string;
|
|
11
|
+
}
|
|
4
12
|
/**
|
|
5
13
|
* The wrapper for rendered Markdown: an `<article class="ir-prose">` styled by the SDK's
|
|
6
14
|
* layered default stylesheet and keyed to the host theme through `data-theme`.
|
|
@@ -10,6 +18,6 @@ import { ComponentPropsWithRef } from 'react';
|
|
|
10
18
|
* ships overrides the defaults, and setting a token such as `--accent` or `--sans` on an
|
|
11
19
|
* ancestor restyles every rule that reads it.
|
|
12
20
|
*/
|
|
13
|
-
declare const Prose: ({ className, children, ...rest }:
|
|
21
|
+
declare const Prose: ({ className, children, filename, ref, ...rest }: ProseProps) => react.JSX.Element;
|
|
14
22
|
|
|
15
|
-
export { Prose };
|
|
23
|
+
export { Prose, type ProseProps };
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ComponentPropsWithRef } from 'react';
|
|
3
3
|
|
|
4
|
+
interface ProseProps extends ComponentPropsWithRef<'article'> {
|
|
5
|
+
/**
|
|
6
|
+
* The repo-relative path of the Markdown file this wraps. When set, the author token
|
|
7
|
+
* file that governs it (`PROSE_TOKEN_FILE`, or the file a bundle marker's `styles`
|
|
8
|
+
* names — MARKDOWN_SYNTAX_SPEC §16.6) restyles this article. `FileRouter` passes it.
|
|
9
|
+
*/
|
|
10
|
+
filename?: string;
|
|
11
|
+
}
|
|
4
12
|
/**
|
|
5
13
|
* The wrapper for rendered Markdown: an `<article class="ir-prose">` styled by the SDK's
|
|
6
14
|
* layered default stylesheet and keyed to the host theme through `data-theme`.
|
|
@@ -10,6 +18,6 @@ import { ComponentPropsWithRef } from 'react';
|
|
|
10
18
|
* ships overrides the defaults, and setting a token such as `--accent` or `--sans` on an
|
|
11
19
|
* ancestor restyles every rule that reads it.
|
|
12
20
|
*/
|
|
13
|
-
declare const Prose: ({ className, children, ...rest }:
|
|
21
|
+
declare const Prose: ({ className, children, filename, ref, ...rest }: ProseProps) => react.JSX.Element;
|
|
14
22
|
|
|
15
|
-
export { Prose };
|
|
23
|
+
export { Prose, type ProseProps };
|
package/dist/components/Prose.js
CHANGED
|
@@ -1,14 +1,47 @@
|
|
|
1
1
|
import "../chunk-VHAA22YE.js";
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
|
-
import { useLayoutEffect } from "react";
|
|
3
|
+
import { useCallback, useLayoutEffect, useRef } from "react";
|
|
4
4
|
import { ensureProseStyles, PROSE_CLASS } from "../proseStyles.js";
|
|
5
|
+
import { tokensFor } from "../proseTokens.js";
|
|
6
|
+
import { useProseTokens } from "../proseTokensHook.js";
|
|
5
7
|
import { useHostTheme } from "../theme.js";
|
|
6
|
-
const
|
|
8
|
+
const assignRef = (ref, value) => {
|
|
9
|
+
if (typeof ref === "function") ref(value);
|
|
10
|
+
else if (ref) ref.current = value;
|
|
11
|
+
};
|
|
12
|
+
const Prose = ({ className, children, filename, ref, ...rest }) => {
|
|
7
13
|
useLayoutEffect(() => {
|
|
8
14
|
ensureProseStyles();
|
|
9
15
|
}, []);
|
|
10
16
|
const theme = useHostTheme();
|
|
11
|
-
|
|
17
|
+
const tokens = useProseTokens(filename);
|
|
18
|
+
const element = useRef(null);
|
|
19
|
+
const setElement = useCallback(
|
|
20
|
+
(node) => {
|
|
21
|
+
element.current = node;
|
|
22
|
+
assignRef(ref, node);
|
|
23
|
+
},
|
|
24
|
+
[ref]
|
|
25
|
+
);
|
|
26
|
+
useLayoutEffect(() => {
|
|
27
|
+
const el = element.current;
|
|
28
|
+
if (!el || !tokens) return;
|
|
29
|
+
const entries = tokensFor(tokens, theme);
|
|
30
|
+
for (const [name, value] of entries) el.style.setProperty(name, value);
|
|
31
|
+
return () => {
|
|
32
|
+
for (const [name] of entries) el.style.removeProperty(name);
|
|
33
|
+
};
|
|
34
|
+
}, [tokens, theme]);
|
|
35
|
+
return /* @__PURE__ */ jsx(
|
|
36
|
+
"article",
|
|
37
|
+
{
|
|
38
|
+
...rest,
|
|
39
|
+
ref: setElement,
|
|
40
|
+
className: className ? `${PROSE_CLASS} ${className}` : PROSE_CLASS,
|
|
41
|
+
"data-theme": theme,
|
|
42
|
+
children
|
|
43
|
+
}
|
|
44
|
+
);
|
|
12
45
|
};
|
|
13
46
|
export {
|
|
14
47
|
Prose
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/Prose.tsx"],"sourcesContent":["import { useLayoutEffect, type ComponentPropsWithRef } from 'react';\n\nimport { ensureProseStyles, PROSE_CLASS } from '../proseStyles';\nimport { useHostTheme } from '../theme';\n\n/**\n * The wrapper for rendered Markdown: an `<article class=\"ir-prose\">` styled by the SDK's\n * layered default stylesheet and keyed to the host theme through `data-theme`.\n *\n * `FileRouter` uses it for every routed `.md`/`.mdx` file. An app that renders Markdown\n * itself can wrap its content in it to get the same typography; any unlayered CSS the app\n * ships overrides the defaults, and setting a token such as `--accent` or `--sans` on an\n * ancestor restyles every rule that reads it.\n */\nexport const Prose = ({ className, children, ...rest }:
|
|
1
|
+
{"version":3,"sources":["../../src/components/Prose.tsx"],"sourcesContent":["import { useCallback, useLayoutEffect, useRef, type ComponentPropsWithRef, type Ref } from 'react';\n\nimport { ensureProseStyles, PROSE_CLASS } from '../proseStyles';\nimport { tokensFor } from '../proseTokens';\nimport { useProseTokens } from '../proseTokensHook';\nimport { useHostTheme } from '../theme';\n\nexport interface ProseProps extends ComponentPropsWithRef<'article'> {\n /**\n * The repo-relative path of the Markdown file this wraps. When set, the author token\n * file that governs it (`PROSE_TOKEN_FILE`, or the file a bundle marker's `styles`\n * names — MARKDOWN_SYNTAX_SPEC §16.6) restyles this article. `FileRouter` passes it.\n */\n filename?: string;\n}\n\nconst assignRef = <T,>(ref: Ref<T> | undefined, value: T | null): void => {\n if (typeof ref === 'function') ref(value);\n else if (ref) (ref as { current: T | null }).current = value;\n};\n\n/**\n * The wrapper for rendered Markdown: an `<article class=\"ir-prose\">` styled by the SDK's\n * layered default stylesheet and keyed to the host theme through `data-theme`.\n *\n * `FileRouter` uses it for every routed `.md`/`.mdx` file. An app that renders Markdown\n * itself can wrap its content in it to get the same typography; any unlayered CSS the app\n * ships overrides the defaults, and setting a token such as `--accent` or `--sans` on an\n * ancestor restyles every rule that reads it.\n */\nexport const Prose = ({ className, children, filename, ref, ...rest }: ProseProps) => {\n useLayoutEffect(() => {\n ensureProseStyles();\n }, []);\n const theme = useHostTheme();\n const tokens = useProseTokens(filename);\n const element = useRef<HTMLElement | null>(null);\n const setElement = useCallback(\n (node: HTMLElement | null) => {\n element.current = node;\n assignRef(ref, node);\n },\n [ref],\n );\n\n // Author tokens are SET, one property at a time, on this element; never written as CSS\n // text. Each set is removed before the next (a token dropped from the file must stop\n // applying) and on unmount.\n useLayoutEffect(() => {\n const el = element.current;\n if (!el || !tokens) return;\n const entries = tokensFor(tokens, theme);\n for (const [name, value] of entries) el.style.setProperty(name, value);\n return () => {\n for (const [name] of entries) el.style.removeProperty(name);\n };\n }, [tokens, theme]);\n\n return (\n <article\n {...rest}\n ref={setElement}\n className={className ? `${PROSE_CLASS} ${className}` : PROSE_CLASS}\n data-theme={theme}\n >\n {children}\n </article>\n );\n};\n"],"mappings":";AA2DI;AA3DJ,SAAS,aAAa,iBAAiB,cAAoD;AAE3F,SAAS,mBAAmB,mBAAmB;AAC/C,SAAS,iBAAiB;AAC1B,SAAS,sBAAsB;AAC/B,SAAS,oBAAoB;AAW7B,MAAM,YAAY,CAAK,KAAyB,UAA0B;AACxE,MAAI,OAAO,QAAQ,WAAY,KAAI,KAAK;AAAA,WAC/B,IAAK,CAAC,IAA8B,UAAU;AACzD;AAWO,MAAM,QAAQ,CAAC,EAAE,WAAW,UAAU,UAAU,KAAK,GAAG,KAAK,MAAkB;AACpF,kBAAgB,MAAM;AACpB,sBAAkB;AAAA,EACpB,GAAG,CAAC,CAAC;AACL,QAAM,QAAQ,aAAa;AAC3B,QAAM,SAAS,eAAe,QAAQ;AACtC,QAAM,UAAU,OAA2B,IAAI;AAC/C,QAAM,aAAa;AAAA,IACjB,CAAC,SAA6B;AAC5B,cAAQ,UAAU;AAClB,gBAAU,KAAK,IAAI;AAAA,IACrB;AAAA,IACA,CAAC,GAAG;AAAA,EACN;AAKA,kBAAgB,MAAM;AACpB,UAAM,KAAK,QAAQ;AACnB,QAAI,CAAC,MAAM,CAAC,OAAQ;AACpB,UAAM,UAAU,UAAU,QAAQ,KAAK;AACvC,eAAW,CAAC,MAAM,KAAK,KAAK,QAAS,IAAG,MAAM,YAAY,MAAM,KAAK;AACrE,WAAO,MAAM;AACX,iBAAW,CAAC,IAAI,KAAK,QAAS,IAAG,MAAM,eAAe,IAAI;AAAA,IAC5D;AAAA,EACF,GAAG,CAAC,QAAQ,KAAK,CAAC;AAElB,SACE;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACJ,KAAK;AAAA,MACL,WAAW,YAAY,GAAG,WAAW,IAAI,SAAS,KAAK;AAAA,MACvD,cAAY;AAAA,MAEX;AAAA;AAAA,EACH;AAEJ;","names":[]}
|
|
@@ -0,0 +1,84 @@
|
|
|
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 directoryListing_exports = {};
|
|
20
|
+
__export(directoryListing_exports, {
|
|
21
|
+
isDirectoryPath: () => isDirectoryPath,
|
|
22
|
+
namesDirectory: () => namesDirectory,
|
|
23
|
+
pickReadme: () => pickReadme,
|
|
24
|
+
readDirectoryListing: () => readDirectoryListing,
|
|
25
|
+
sortEntries: () => sortEntries,
|
|
26
|
+
toDirPath: () => toDirPath
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(directoryListing_exports);
|
|
29
|
+
var import_fs = require("./fs");
|
|
30
|
+
var import_urlUtils = require("./urlUtils");
|
|
31
|
+
const README_NAMES = ["README.md", "README.mdx", "readme.md", "index.md", "index.mdx"];
|
|
32
|
+
const toDirPath = (repoPath) => {
|
|
33
|
+
const trimmed = repoPath.replace(/^\/+|\/+$/g, "");
|
|
34
|
+
return trimmed ? `/${trimmed}/` : "/";
|
|
35
|
+
};
|
|
36
|
+
const namesDirectory = (repoPath) => repoPath === "" || repoPath.endsWith("/");
|
|
37
|
+
const fsPromises = () => {
|
|
38
|
+
const fs = (0, import_fs.sandboxFs)();
|
|
39
|
+
return fs?.promises ?? null;
|
|
40
|
+
};
|
|
41
|
+
const isDirectoryPath = async (repoPath) => {
|
|
42
|
+
const promises = fsPromises();
|
|
43
|
+
if (!promises) return false;
|
|
44
|
+
try {
|
|
45
|
+
const st = await promises.stat((0, import_urlUtils.underAppRoot)(repoPath.replace(/^\/+/, "")));
|
|
46
|
+
return typeof st?.isDirectory === "function" ? Boolean(st.isDirectory()) : false;
|
|
47
|
+
} catch {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const sortEntries = (entries) => [...entries].sort(
|
|
52
|
+
(a, b) => Number(b.isDirectory) - Number(a.isDirectory) || a.name.localeCompare(b.name, void 0, { sensitivity: "base" }) || a.name.localeCompare(b.name)
|
|
53
|
+
);
|
|
54
|
+
const pickReadme = (entries) => {
|
|
55
|
+
for (const name of README_NAMES) {
|
|
56
|
+
const hit = entries.find((e) => !e.isDirectory && e.name === name);
|
|
57
|
+
if (hit) return hit;
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
};
|
|
61
|
+
const readDirectoryListing = async (repoPath) => {
|
|
62
|
+
const promises = fsPromises();
|
|
63
|
+
if (!promises) throw new Error(`Cannot list ${repoPath || "/"}: the sandbox filesystem is unavailable`);
|
|
64
|
+
const dir = toDirPath(repoPath);
|
|
65
|
+
const raw = await promises.readdir((0, import_urlUtils.underAppRoot)(dir.slice(1)), { withFileTypes: true });
|
|
66
|
+
const entries = sortEntries(
|
|
67
|
+
raw.map((d) => {
|
|
68
|
+
const isDirectory = d.isDirectory();
|
|
69
|
+
return { name: d.name, isDirectory, path: `${dir}${d.name}${isDirectory ? "/" : ""}` };
|
|
70
|
+
})
|
|
71
|
+
);
|
|
72
|
+
const parent = dir === "/" ? null : toDirPath(dir.slice(0, -1).replace(/[^/]*$/, ""));
|
|
73
|
+
return { dir, parent, entries, readme: pickReadme(entries)?.path ?? null };
|
|
74
|
+
};
|
|
75
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
76
|
+
0 && (module.exports = {
|
|
77
|
+
isDirectoryPath,
|
|
78
|
+
namesDirectory,
|
|
79
|
+
pickReadme,
|
|
80
|
+
readDirectoryListing,
|
|
81
|
+
sortEntries,
|
|
82
|
+
toDirPath
|
|
83
|
+
});
|
|
84
|
+
//# sourceMappingURL=directoryListing.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/directoryListing.ts"],"sourcesContent":["// What `FileRouter` needs to route a DIRECTORY under `/files/*`. `files/<repo path>` is the\n// filesystem-true address for anything in the mount (REPO_CONTENT_DISPATCH_SPEC §9), and\n// a folder is part of the mount: a README that links to `tickets/` must land on something\n// other than `require('/app/tickets')`, which is what every `/files/*` path used to become.\n//\n// Kept outside the component (R13) so the decisions — what counts as a directory, entry\n// order, which file is the folder's README — are testable without rendering.\nimport { sandboxFs } from './fs';\nimport { underAppRoot } from './urlUtils';\n\n/** One entry of a listed directory. `path` is repo-relative with a leading `/`, the form\n * `Link` turns into a `/files/…` URL; a directory's path ends in `/`. */\nexport interface DirectoryEntry {\n name: string;\n path: string;\n isDirectory: boolean;\n}\n\nexport interface DirectoryListing {\n /** Repo-relative, leading `/`, trailing `/` (the root is `/`). */\n dir: string;\n /** The parent directory in the same form, or `null` at the repo root. */\n parent: string | null;\n entries: DirectoryEntry[];\n /** Repo-relative path of the README rendered under the listing, if the folder has one. */\n readme: string | null;\n}\n\n/** Shown below the listing, first match wins — GitHub's convention for a folder page. */\nconst README_NAMES = ['README.md', 'README.mdx', 'readme.md', 'index.md', 'index.mdx'];\n\n/** `tickets/` / `/tickets` / `tickets` → `/tickets/`; `''` and `/` → `/`. */\nexport const toDirPath = (repoPath: string): string => {\n const trimmed = repoPath.replace(/^\\/+|\\/+$/g, '');\n return trimmed ? `/${trimmed}/` : '/';\n};\n\n/** A trailing slash is the URL saying \"folder\" — no filesystem round-trip needed. */\nexport const namesDirectory = (repoPath: string): boolean => repoPath === '' || repoPath.endsWith('/');\n\nconst fsPromises = () => {\n const fs = sandboxFs();\n return fs?.promises ?? null;\n};\n\n/**\n * Whether a repo-relative path is a directory in the sandbox fs. `false` when the path\n * does not exist or no fs is available: the caller then renders it as a file, and the\n * module loader reports the missing file itself — this probe never hides that error.\n */\nexport const isDirectoryPath = async (repoPath: string): Promise<boolean> => {\n const promises = fsPromises();\n if (!promises) return false;\n try {\n const st = await promises.stat(underAppRoot(repoPath.replace(/^\\/+/, '')));\n return typeof st?.isDirectory === 'function' ? Boolean(st.isDirectory()) : false;\n } catch {\n // ENOENT and friends: not a directory. Include surfaces the real error for the path.\n return false;\n }\n};\n\n/** Directories first, then files; each group by name, case-insensitively. */\nexport const sortEntries = (entries: DirectoryEntry[]): DirectoryEntry[] =>\n [...entries].sort(\n (a, b) =>\n Number(b.isDirectory) - Number(a.isDirectory) ||\n a.name.localeCompare(b.name, undefined, { sensitivity: 'base' }) ||\n a.name.localeCompare(b.name),\n );\n\nexport const pickReadme = (entries: DirectoryEntry[]): DirectoryEntry | null => {\n for (const name of README_NAMES) {\n const hit = entries.find((e) => !e.isDirectory && e.name === name);\n if (hit) return hit;\n }\n return null;\n};\n\n/** Read and shape one directory. Rejects (into the caller's error boundary) when the\n * fs is unavailable or the read fails — an empty listing would be a lie. */\nexport const readDirectoryListing = async (repoPath: string): Promise<DirectoryListing> => {\n const promises = fsPromises();\n if (!promises) throw new Error(`Cannot list ${repoPath || '/'}: the sandbox filesystem is unavailable`);\n const dir = toDirPath(repoPath);\n const raw = (await promises.readdir(underAppRoot(dir.slice(1)), { withFileTypes: true })) as Array<{\n name: string;\n isDirectory(): boolean;\n }>;\n const entries = sortEntries(\n raw.map((d) => {\n const isDirectory = d.isDirectory();\n return { name: d.name, isDirectory, path: `${dir}${d.name}${isDirectory ? '/' : ''}` };\n }),\n );\n const parent = dir === '/' ? null : toDirPath(dir.slice(0, -1).replace(/[^/]*$/, ''));\n return { dir, parent, entries, readme: pickReadme(entries)?.path ?? null };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,gBAA0B;AAC1B,sBAA6B;AAqB7B,MAAM,eAAe,CAAC,aAAa,cAAc,aAAa,YAAY,WAAW;AAG9E,MAAM,YAAY,CAAC,aAA6B;AACrD,QAAM,UAAU,SAAS,QAAQ,cAAc,EAAE;AACjD,SAAO,UAAU,IAAI,OAAO,MAAM;AACpC;AAGO,MAAM,iBAAiB,CAAC,aAA8B,aAAa,MAAM,SAAS,SAAS,GAAG;AAErG,MAAM,aAAa,MAAM;AACvB,QAAM,SAAK,qBAAU;AACrB,SAAO,IAAI,YAAY;AACzB;AAOO,MAAM,kBAAkB,OAAO,aAAuC;AAC3E,QAAM,WAAW,WAAW;AAC5B,MAAI,CAAC,SAAU,QAAO;AACtB,MAAI;AACF,UAAM,KAAK,MAAM,SAAS,SAAK,8BAAa,SAAS,QAAQ,QAAQ,EAAE,CAAC,CAAC;AACzE,WAAO,OAAO,IAAI,gBAAgB,aAAa,QAAQ,GAAG,YAAY,CAAC,IAAI;AAAA,EAC7E,QAAQ;AAEN,WAAO;AAAA,EACT;AACF;AAGO,MAAM,cAAc,CAAC,YAC1B,CAAC,GAAG,OAAO,EAAE;AAAA,EACX,CAAC,GAAG,MACF,OAAO,EAAE,WAAW,IAAI,OAAO,EAAE,WAAW,KAC5C,EAAE,KAAK,cAAc,EAAE,MAAM,QAAW,EAAE,aAAa,OAAO,CAAC,KAC/D,EAAE,KAAK,cAAc,EAAE,IAAI;AAC/B;AAEK,MAAM,aAAa,CAAC,YAAqD;AAC9E,aAAW,QAAQ,cAAc;AAC/B,UAAM,MAAM,QAAQ,KAAK,CAAC,MAAM,CAAC,EAAE,eAAe,EAAE,SAAS,IAAI;AACjE,QAAI,IAAK,QAAO;AAAA,EAClB;AACA,SAAO;AACT;AAIO,MAAM,uBAAuB,OAAO,aAAgD;AACzF,QAAM,WAAW,WAAW;AAC5B,MAAI,CAAC,SAAU,OAAM,IAAI,MAAM,eAAe,YAAY,GAAG,yCAAyC;AACtG,QAAM,MAAM,UAAU,QAAQ;AAC9B,QAAM,MAAO,MAAM,SAAS,YAAQ,8BAAa,IAAI,MAAM,CAAC,CAAC,GAAG,EAAE,eAAe,KAAK,CAAC;AAIvF,QAAM,UAAU;AAAA,IACd,IAAI,IAAI,CAAC,MAAM;AACb,YAAM,cAAc,EAAE,YAAY;AAClC,aAAO,EAAE,MAAM,EAAE,MAAM,aAAa,MAAM,GAAG,GAAG,GAAG,EAAE,IAAI,GAAG,cAAc,MAAM,EAAE,GAAG;AAAA,IACvF,CAAC;AAAA,EACH;AACA,QAAM,SAAS,QAAQ,MAAM,OAAO,UAAU,IAAI,MAAM,GAAG,EAAE,EAAE,QAAQ,UAAU,EAAE,CAAC;AACpF,SAAO,EAAE,KAAK,QAAQ,SAAS,QAAQ,WAAW,OAAO,GAAG,QAAQ,KAAK;AAC3E;","names":[]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** One entry of a listed directory. `path` is repo-relative with a leading `/`, the form
|
|
2
|
+
* `Link` turns into a `/files/…` URL; a directory's path ends in `/`. */
|
|
3
|
+
interface DirectoryEntry {
|
|
4
|
+
name: string;
|
|
5
|
+
path: string;
|
|
6
|
+
isDirectory: boolean;
|
|
7
|
+
}
|
|
8
|
+
interface DirectoryListing {
|
|
9
|
+
/** Repo-relative, leading `/`, trailing `/` (the root is `/`). */
|
|
10
|
+
dir: string;
|
|
11
|
+
/** The parent directory in the same form, or `null` at the repo root. */
|
|
12
|
+
parent: string | null;
|
|
13
|
+
entries: DirectoryEntry[];
|
|
14
|
+
/** Repo-relative path of the README rendered under the listing, if the folder has one. */
|
|
15
|
+
readme: string | null;
|
|
16
|
+
}
|
|
17
|
+
/** `tickets/` / `/tickets` / `tickets` → `/tickets/`; `''` and `/` → `/`. */
|
|
18
|
+
declare const toDirPath: (repoPath: string) => string;
|
|
19
|
+
/** A trailing slash is the URL saying "folder" — no filesystem round-trip needed. */
|
|
20
|
+
declare const namesDirectory: (repoPath: string) => boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Whether a repo-relative path is a directory in the sandbox fs. `false` when the path
|
|
23
|
+
* does not exist or no fs is available: the caller then renders it as a file, and the
|
|
24
|
+
* module loader reports the missing file itself — this probe never hides that error.
|
|
25
|
+
*/
|
|
26
|
+
declare const isDirectoryPath: (repoPath: string) => Promise<boolean>;
|
|
27
|
+
/** Directories first, then files; each group by name, case-insensitively. */
|
|
28
|
+
declare const sortEntries: (entries: DirectoryEntry[]) => DirectoryEntry[];
|
|
29
|
+
declare const pickReadme: (entries: DirectoryEntry[]) => DirectoryEntry | null;
|
|
30
|
+
/** Read and shape one directory. Rejects (into the caller's error boundary) when the
|
|
31
|
+
* fs is unavailable or the read fails — an empty listing would be a lie. */
|
|
32
|
+
declare const readDirectoryListing: (repoPath: string) => Promise<DirectoryListing>;
|
|
33
|
+
|
|
34
|
+
export { type DirectoryEntry, type DirectoryListing, isDirectoryPath, namesDirectory, pickReadme, readDirectoryListing, sortEntries, toDirPath };
|