@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 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 MDXRegistryOptions<
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 MDXRegistryOptions.records}
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 MDXRegistryOptions.records}
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 MDXRegistryOptions.source}
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 MDXRegistryOptions.records}
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 MDXRegistryOptions<S, M, R>["records"] as `${MDXRegistryOptions<S, M, R>["mountOn"]}${Extract<K, string>}`] : T };
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 }: MDXRegistryOptions<S, M, R>): [ComponentRegistry<S, M, R>, ExportsRegistry<S, M, R>];
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
- private readonly components;
94
- private readonly exports;
95
- constructor(registryOpts: MDXRegistryOptions<S, M, R>);
96
- getComponent(key: RegistryKey<S, M, R>): ComponentRegistry<S, M, R>[RegistryKey<S, M, R>];
97
- getComponents(): ComponentRegistry<S, M, R>;
98
- getExport<T extends object = object>(key: RegistryKey<S, M, R>): ExportSingleType<T>;
99
- getExports<T extends Record<RegistryKey<S, M, R>, object> = Record<RegistryKey<S, M, R>, object>>(): ExportAllType<T>;
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, MDXRegistryOptions, MDXFromComponentProps, MDXFromComponent, MDXFile, HeaderLevels, ExportsRegistry, ExportSingleType, ExportAllType, Elements, ComponentRegistry };
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 Registry {
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
@@ -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.7",
4
+ "version": "0.1.9",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"