@d1vij/jassm 0.1.7 → 0.1.9
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 +35 -16
- package/dist/index.js +22 -7
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ type MustNotEndWithSlash<T extends string> = T extends `${string}/` ? never : T;
|
|
|
12
12
|
/**
|
|
13
13
|
* Options passed to {@link generateRegistries}
|
|
14
14
|
*/
|
|
15
|
-
type
|
|
15
|
+
type RegistryOptions<
|
|
16
16
|
S extends string,
|
|
17
17
|
M extends string,
|
|
18
18
|
R extends Record<string, string>
|
|
@@ -23,15 +23,15 @@ type MDXRegistryOptions<
|
|
|
23
23
|
*/
|
|
24
24
|
modules: Record<string, () => Promise<unknown>>;
|
|
25
25
|
/**
|
|
26
|
-
* Directory from which to resolve the source paths in {@link
|
|
26
|
+
* Directory from which to resolve the source paths in {@link RegistryOptions.records}
|
|
27
27
|
*/
|
|
28
28
|
source: MustNotEndWithSlash<S> & MustStartWithSlash<S>;
|
|
29
29
|
/**
|
|
30
|
-
* Virtual base path on which to mount the key of {@link
|
|
30
|
+
* Virtual base path on which to mount the key of {@link RegistryOptions.records}
|
|
31
31
|
*/
|
|
32
32
|
mountOn: MustNotEndWithSlash<M> & MustStartWithSlash<M>;
|
|
33
33
|
/**
|
|
34
|
-
* Mappings of virtual path to file paths under {@link
|
|
34
|
+
* Mappings of virtual path to file paths under {@link RegistryOptions.source}
|
|
35
35
|
*/
|
|
36
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 };
|
|
37
37
|
};
|
|
@@ -41,14 +41,14 @@ type RegistryKey<
|
|
|
41
41
|
R extends Record<string, string>
|
|
42
42
|
> = keyof RegistryOf<unknown, S, M, R>;
|
|
43
43
|
/**
|
|
44
|
-
* Constructor for any generic registry with keys in the format of `mount-path/virtual-path` for each virual path passed in {@link
|
|
44
|
+
* Constructor for any generic registry with keys in the format of `mount-path/virtual-path` for each virual path passed in {@link RegistryOptions.records}
|
|
45
45
|
*/
|
|
46
46
|
type RegistryOf<
|
|
47
47
|
T,
|
|
48
48
|
S extends string,
|
|
49
49
|
M extends string,
|
|
50
50
|
R extends Record<string, string>
|
|
51
|
-
> = { [K in keyof
|
|
51
|
+
> = { [K in keyof RegistryOptions<S, M, R>["records"] as `${RegistryOptions<S, M, R>["mountOn"]}${Extract<K, string>}`] : T };
|
|
52
52
|
/**
|
|
53
53
|
* Registry of react components
|
|
54
54
|
*/
|
|
@@ -74,7 +74,7 @@ declare function generateRegistries<
|
|
|
74
74
|
S extends string,
|
|
75
75
|
M extends string,
|
|
76
76
|
R extends Record<string, string>
|
|
77
|
-
>({ modules, source, mountOn, records }:
|
|
77
|
+
>({ modules, source, mountOn, records }: RegistryOptions<S, M, R>): [ComponentRegistry<S, M, R>, ExportsRegistry<S, M, R>];
|
|
78
78
|
/**
|
|
79
79
|
* The returned object has the type of {@link React.ComponentType} + whatever user passes
|
|
80
80
|
*/
|
|
@@ -82,6 +82,20 @@ type ExportSingleType<T> = Promise<T & {
|
|
|
82
82
|
default: React.ComponentType;
|
|
83
83
|
}>;
|
|
84
84
|
type ExportAllType<T> = { [K in keyof T] : ExportSingleType<T[K]> };
|
|
85
|
+
declare abstract class AbstractRegistry<
|
|
86
|
+
C extends Record<string, React.LazyExoticComponent<React.ComponentType>>,
|
|
87
|
+
E extends Record<string, unknown>
|
|
88
|
+
> {
|
|
89
|
+
abstract components: C;
|
|
90
|
+
abstract exports: E;
|
|
91
|
+
getComponent<K extends keyof C>(key: K): C[K];
|
|
92
|
+
getComponents(): C;
|
|
93
|
+
getExport<
|
|
94
|
+
T extends object,
|
|
95
|
+
K extends keyof E
|
|
96
|
+
>(key: K): ExportSingleType<T>;
|
|
97
|
+
getExports<T extends Record<keyof C, object> = Record<keyof C, object>>(): ExportAllType<T>;
|
|
98
|
+
}
|
|
85
99
|
/**
|
|
86
100
|
* Wrapper class over {@link generateRegistries}. Provides methods to access components and exports from typesafe keys
|
|
87
101
|
*/
|
|
@@ -89,14 +103,19 @@ declare class Registry<
|
|
|
89
103
|
S extends string,
|
|
90
104
|
M extends string,
|
|
91
105
|
R extends Record<string, string>
|
|
92
|
-
> {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
constructor(registryOpts:
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
106
|
+
> extends AbstractRegistry<ComponentRegistry<S, M, R>, ExportsRegistry<S, M, R>> {
|
|
107
|
+
readonly components: ComponentRegistry<S, M, R>;
|
|
108
|
+
readonly exports: ExportsRegistry<S, M, R>;
|
|
109
|
+
constructor(registryOpts: RegistryOptions<S, M, R>);
|
|
110
|
+
}
|
|
111
|
+
type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
112
|
+
/**
|
|
113
|
+
* Registry created by coalesing multiple {@link Registry} instances
|
|
114
|
+
*/
|
|
115
|
+
declare class CoalescedRegistry<R extends readonly AbstractRegistry<Record<string, React.LazyExoticComponent<React.ComponentType>>, Record<string, unknown>>[]> extends AbstractRegistry<Record<keyof UnionToIntersection<R[number]["components"]>, React.LazyExoticComponent<React.ComponentType>>, Record<keyof UnionToIntersection<R[number]["exports"]>, unknown>> {
|
|
116
|
+
readonly components: Record<keyof UnionToIntersection<R[number]["components"]>, React.LazyExoticComponent<React.ComponentType>>;
|
|
117
|
+
readonly exports: Record<keyof UnionToIntersection<R[number]["exports"]>, unknown>;
|
|
118
|
+
constructor(...registries: R);
|
|
100
119
|
}
|
|
101
120
|
/**
|
|
102
121
|
* List of default style classes
|
|
@@ -123,4 +142,4 @@ type MDXFromComponentProps = {
|
|
|
123
142
|
* Simple way to directly load a component from the Registry
|
|
124
143
|
*/
|
|
125
144
|
declare function MDXFromComponent({ SourceComponent, styles, fallback, elements }: MDXFromComponentProps): JSX;
|
|
126
|
-
export { useStyles, generateRegistries, StyleContext, StyleClassesMap, StyleClassesList, StyleClasses, RegistryOf, RegistryKey, Registry,
|
|
145
|
+
export { useStyles, generateRegistries, StyleContext, StyleClassesMap, StyleClassesList, StyleClasses, RegistryOptions, RegistryOf, RegistryKey, Registry, MDXFromComponentProps, MDXFromComponent, MDXFile, HeaderLevels, ExportsRegistry, ExportSingleType, ExportAllType, Elements, ComponentRegistry, CoalescedRegistry };
|
package/dist/index.js
CHANGED
|
@@ -316,12 +316,7 @@ function generateRegistries({
|
|
|
316
316
|
return [Object.fromEntries(components), Object.fromEntries(exports)];
|
|
317
317
|
}
|
|
318
318
|
|
|
319
|
-
class
|
|
320
|
-
components;
|
|
321
|
-
exports;
|
|
322
|
-
constructor(registryOpts) {
|
|
323
|
-
[this.components, this.exports] = generateRegistries(registryOpts);
|
|
324
|
-
}
|
|
319
|
+
class AbstractRegistry {
|
|
325
320
|
getComponent(key) {
|
|
326
321
|
return this.components[key];
|
|
327
322
|
}
|
|
@@ -335,6 +330,25 @@ class Registry {
|
|
|
335
330
|
return this.exports;
|
|
336
331
|
}
|
|
337
332
|
}
|
|
333
|
+
|
|
334
|
+
class Registry extends AbstractRegistry {
|
|
335
|
+
components;
|
|
336
|
+
exports;
|
|
337
|
+
constructor(registryOpts) {
|
|
338
|
+
super();
|
|
339
|
+
[this.components, this.exports] = generateRegistries(registryOpts);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
class CoalescedRegistry extends AbstractRegistry {
|
|
344
|
+
components;
|
|
345
|
+
exports;
|
|
346
|
+
constructor(...registries) {
|
|
347
|
+
super();
|
|
348
|
+
this.components = Object.assign({}, ...registries.map((r) => r.getComponents()));
|
|
349
|
+
this.exports = Object.assign({}, ...registries.map((r) => r.getExports()));
|
|
350
|
+
}
|
|
351
|
+
}
|
|
338
352
|
// src/components/Loader.tsx
|
|
339
353
|
import { jsx as jsx14 } from "react/jsx-runtime";
|
|
340
354
|
function MDXFromComponent({
|
|
@@ -360,5 +374,6 @@ export {
|
|
|
360
374
|
StyleClassesList,
|
|
361
375
|
Registry,
|
|
362
376
|
MDXFromComponent,
|
|
363
|
-
Elements
|
|
377
|
+
Elements,
|
|
378
|
+
CoalescedRegistry
|
|
364
379
|
};
|
package/package.json
CHANGED