@d1vij/jassm 0.1.3 → 0.1.4
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/index.d.ts +59 -18
- package/dist/index.js +28 -5
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -7,30 +7,15 @@ import { MDXComponents as MDXComponents2, MDXProps } from "mdx/types";
|
|
|
7
7
|
* File extension(s) to accept
|
|
8
8
|
*/
|
|
9
9
|
type MDXFile = `${string}.mdx`;
|
|
10
|
-
/**
|
|
11
|
-
* Generated registry type
|
|
12
|
-
*/
|
|
13
|
-
type LazyRegistry<T extends Record<string, MDXFile>> = { readonly [K in keyof T] : React.LazyExoticComponent<React.ComponentType> };
|
|
14
|
-
type Expand<T> = T extends infer O ? { [K in keyof O] : O[K] } : never;
|
|
15
10
|
type MustStartWithSlash<T extends string> = T extends `/${string}` ? T : never;
|
|
16
11
|
type MustNotEndWithSlash<T extends string> = T extends `${string}/` ? never : T;
|
|
17
12
|
/**
|
|
18
|
-
*
|
|
19
|
-
* @param MDXRegistryOptions
|
|
20
|
-
* @returns
|
|
13
|
+
* Options passed to {@link generateRegistries}
|
|
21
14
|
*/
|
|
22
|
-
|
|
15
|
+
type MDXRegistryOptions<
|
|
23
16
|
S extends string,
|
|
24
17
|
M extends string,
|
|
25
18
|
R extends Record<string, string>
|
|
26
|
-
>({ modules, source, mountOn, records }: MDXRegistryOptions<S, M, R>): Expand<LazyRegistry<{ [K in keyof typeof records as `${typeof mountOn}${Extract<K, string>}`] : MDXFile }>>;
|
|
27
|
-
/**
|
|
28
|
-
* Options passed to {@link generateRegistry}
|
|
29
|
-
*/
|
|
30
|
-
type MDXRegistryOptions<
|
|
31
|
-
S extends string = string,
|
|
32
|
-
M extends string = string,
|
|
33
|
-
R extends Record<string, string> = Record<string, string>
|
|
34
19
|
> = {
|
|
35
20
|
/**
|
|
36
21
|
* Module object returned from `import.meta.glob`
|
|
@@ -50,6 +35,62 @@ type MDXRegistryOptions<
|
|
|
50
35
|
*/
|
|
51
36
|
records: { [K in keyof R] : K extends string ? MustNotEndWithSlash<K> & MustStartWithSlash<K> extends never ? never : R[K] extends MustStartWithSlash<R[K]> & MDXFile ? R[K] : never : never };
|
|
52
37
|
};
|
|
38
|
+
type RegistryKey<
|
|
39
|
+
S extends string,
|
|
40
|
+
M extends string,
|
|
41
|
+
R extends Record<string, string>
|
|
42
|
+
> = keyof RegistryOf<unknown, S, M, R>;
|
|
43
|
+
/**
|
|
44
|
+
* Constructor for any generic registry with keys in the format of `mount-path/virtual-path` for each virual path passed in {@link MDXRegistryOptions.records}
|
|
45
|
+
*/
|
|
46
|
+
type RegistryOf<
|
|
47
|
+
T,
|
|
48
|
+
S extends string,
|
|
49
|
+
M extends string,
|
|
50
|
+
R extends Record<string, string>
|
|
51
|
+
> = { [K in keyof MDXRegistryOptions<S, M, R>["records"] as `${MDXRegistryOptions<S, M, R>["mountOn"]}${Extract<K, string>}`] : T };
|
|
52
|
+
/**
|
|
53
|
+
* Registry of react components
|
|
54
|
+
*/
|
|
55
|
+
type ComponentRegistry<
|
|
56
|
+
S extends string,
|
|
57
|
+
M extends string,
|
|
58
|
+
R extends Record<string, string>
|
|
59
|
+
> = RegistryOf<React.LazyExoticComponent<React.ComponentType>, S, M, R>;
|
|
60
|
+
/**
|
|
61
|
+
* Registry of promise objects equivalent to return type of `import(<path>)`
|
|
62
|
+
*/
|
|
63
|
+
type ExportsRegistry<
|
|
64
|
+
S extends string,
|
|
65
|
+
M extends string,
|
|
66
|
+
R extends Record<string, string>
|
|
67
|
+
> = RegistryOf<Promise<Record<string, unknown>>, S, M, R>;
|
|
68
|
+
/**
|
|
69
|
+
* Function to generate Registry mappings, use {@link Registry} class instead of this.
|
|
70
|
+
* @param MDXRegistryOptions
|
|
71
|
+
* @returns Tuple of [{@link ComponentRegistry}, {@link ExportsRegistry}]
|
|
72
|
+
*/
|
|
73
|
+
declare function generateRegistries<
|
|
74
|
+
S extends string,
|
|
75
|
+
M extends string,
|
|
76
|
+
R extends Record<string, string>
|
|
77
|
+
>({ modules, source, mountOn, records }: MDXRegistryOptions<S, M, R>): [ComponentRegistry<S, M, R>, ExportsRegistry<S, M, R>];
|
|
78
|
+
/**
|
|
79
|
+
* Wrapper class over {@link generateRegistries}. Provides methods to access components and exports from typesafe keys
|
|
80
|
+
*/
|
|
81
|
+
declare class Registry<
|
|
82
|
+
S extends string,
|
|
83
|
+
M extends string,
|
|
84
|
+
R extends Record<string, string>
|
|
85
|
+
> {
|
|
86
|
+
private readonly components;
|
|
87
|
+
private readonly exports;
|
|
88
|
+
constructor(registryOpts: MDXRegistryOptions<S, M, R>);
|
|
89
|
+
getComponent(key: RegistryKey<S, M, R>): ComponentRegistry<S, M, R>[RegistryKey<S, M, R>];
|
|
90
|
+
getExport(key: RegistryKey<S, M, R>): ExportsRegistry<S, M, R>[RegistryKey<S, M, R>];
|
|
91
|
+
getComponents(): ComponentRegistry<S, M, R>;
|
|
92
|
+
getExports(): ExportsRegistry<S, M, R>;
|
|
93
|
+
}
|
|
53
94
|
/**
|
|
54
95
|
* List of default style classes
|
|
55
96
|
*/
|
|
@@ -75,4 +116,4 @@ type MDXFromComponentProps = {
|
|
|
75
116
|
* Simple way to directly load a component from the Registry
|
|
76
117
|
*/
|
|
77
118
|
declare function MDXFromComponent({ SourceComponent, styles, fallback, elements }: MDXFromComponentProps): JSX;
|
|
78
|
-
export { useStyles,
|
|
119
|
+
export { useStyles, generateRegistries, StyleContext, StyleClassesMap, StyleClassesList, StyleClasses, RegistryOf, RegistryKey, Registry, MDXRegistryOptions, MDXFromComponentProps, MDXFromComponent, MDXFile, HeaderLevels, ExportsRegistry, Elements, ComponentRegistry };
|
package/dist/index.js
CHANGED
|
@@ -296,22 +296,44 @@ import { Suspense } from "react";
|
|
|
296
296
|
|
|
297
297
|
// src/lib/Registry.ts
|
|
298
298
|
import { lazy } from "react";
|
|
299
|
-
function
|
|
299
|
+
function generateRegistries({
|
|
300
300
|
modules,
|
|
301
301
|
source,
|
|
302
302
|
mountOn,
|
|
303
303
|
records
|
|
304
304
|
}) {
|
|
305
|
-
const
|
|
305
|
+
const components = [];
|
|
306
|
+
const exports = [];
|
|
306
307
|
for (const [virtual, path] of Object.entries(records)) {
|
|
307
308
|
const src = `${source}${path}`;
|
|
308
309
|
const loader = modules[src];
|
|
309
310
|
if (!loader) {
|
|
310
311
|
throw new Error(`No such file exsits as ${src}`);
|
|
311
312
|
}
|
|
312
|
-
|
|
313
|
+
components.push([`${mountOn}${virtual}`, lazy(loader)]);
|
|
314
|
+
exports.push([`${mountOn}${virtual}`, import(src)]);
|
|
315
|
+
}
|
|
316
|
+
return [Object.fromEntries(components), Object.fromEntries(exports)];
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
class Registry {
|
|
320
|
+
components;
|
|
321
|
+
exports;
|
|
322
|
+
constructor(registryOpts) {
|
|
323
|
+
[this.components, this.exports] = generateRegistries(registryOpts);
|
|
324
|
+
}
|
|
325
|
+
getComponent(key) {
|
|
326
|
+
return this.components[key];
|
|
327
|
+
}
|
|
328
|
+
getExport(key) {
|
|
329
|
+
return this.exports[key];
|
|
330
|
+
}
|
|
331
|
+
getComponents() {
|
|
332
|
+
return this.components;
|
|
333
|
+
}
|
|
334
|
+
getExports() {
|
|
335
|
+
return this.exports;
|
|
313
336
|
}
|
|
314
|
-
return Object.fromEntries(paths);
|
|
315
337
|
}
|
|
316
338
|
// src/components/Loader.tsx
|
|
317
339
|
import { jsx as jsx14 } from "react/jsx-runtime";
|
|
@@ -333,9 +355,10 @@ function MDXFromComponent({
|
|
|
333
355
|
}
|
|
334
356
|
export {
|
|
335
357
|
useStyles,
|
|
336
|
-
|
|
358
|
+
generateRegistries,
|
|
337
359
|
StyleContext,
|
|
338
360
|
StyleClassesList,
|
|
361
|
+
Registry,
|
|
339
362
|
MDXFromComponent,
|
|
340
363
|
Elements
|
|
341
364
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d1vij/jassm",
|
|
3
3
|
"description": "Just another static site maker. Create simple content driven sites using MDX and React along with Typescript safety.",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.4",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist"
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"repository": {
|
|
25
25
|
"type": "git",
|
|
26
|
-
"url": "https://github.com/d1vij/jassm"
|
|
26
|
+
"url": "git+https://github.com/d1vij/jassm.git"
|
|
27
27
|
},
|
|
28
28
|
"homepage": "https://github.com/d1vij/jassm",
|
|
29
29
|
"license": "MIT",
|