@withstudiocms/component-registry 0.1.0-beta.1 → 0.1.0-beta.3
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/CHANGELOG.md +20 -0
- package/README.md +2 -0
- package/dist/component-proxy/decoder/decode-codepoint.js +2 -1
- package/dist/component-proxy/decoder/util.js +3 -0
- package/dist/component-proxy/index.d.ts +9 -1
- package/dist/component-proxy/index.js +4 -4
- package/dist/registry/PropsParser.js +5 -0
- package/dist/registry/Registry.js +8 -4
- package/dist/registry/handler.d.ts +14 -0
- package/dist/registry/handler.js +2 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @withstudiocms/component-registry
|
|
2
2
|
|
|
3
|
+
## 0.1.0-beta.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#788](https://github.com/withstudiocms/studiocms/pull/788) [`9d3784c`](https://github.com/withstudiocms/studiocms/commit/9d3784c1de98a4bc7bb913742c3977e16c87cc1b) Thanks [@Adammatthiesen](https://github.com/Adammatthiesen)! - Convert tests to vitest
|
|
8
|
+
|
|
9
|
+
- [#780](https://github.com/withstudiocms/studiocms/pull/780) [`627119b`](https://github.com/withstudiocms/studiocms/commit/627119bfde88e9c2ea74a29817d91fb6afbab33d) Thanks [@renovate](https://github.com/apps/renovate)! - fix(deps): update dependency ts-morph to v27
|
|
10
|
+
|
|
11
|
+
- [#798](https://github.com/withstudiocms/studiocms/pull/798) [`55885eb`](https://github.com/withstudiocms/studiocms/commit/55885eba617d8ec790e68ed0985f8530628140d8) Thanks [@Adammatthiesen](https://github.com/Adammatthiesen)! - Add tests for `@withstudiocms/component-registry`
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [[`9d3784c`](https://github.com/withstudiocms/studiocms/commit/9d3784c1de98a4bc7bb913742c3977e16c87cc1b), [`bf15ff6`](https://github.com/withstudiocms/studiocms/commit/bf15ff65a5f4ba6c2e4cd616d3c45ba0da784a1a), [`3b59fcf`](https://github.com/withstudiocms/studiocms/commit/3b59fcf7885d5c4952bd30279fa8ea2e2f0f5eaa), [`3d3612d`](https://github.com/withstudiocms/studiocms/commit/3d3612d510f4827acfb4de364d39e835a693818f), [`c2c2b73`](https://github.com/withstudiocms/studiocms/commit/c2c2b73a71009769e38ea4b30ae4010f6f0fdd14), [`47a2fed`](https://github.com/withstudiocms/studiocms/commit/47a2fedd8ed1c751def929058772ea78532e8d7d), [`fbb9ad1`](https://github.com/withstudiocms/studiocms/commit/fbb9ad10555f26c8e6261cd71a7650ab4aeb64f9), [`faf2a70`](https://github.com/withstudiocms/studiocms/commit/faf2a70ae57d136a9ccbbdebad70897e42c14c64), [`0e8e280`](https://github.com/withstudiocms/studiocms/commit/0e8e280c4a2a7552d3b78b370600019e49f5a459), [`9b85861`](https://github.com/withstudiocms/studiocms/commit/9b85861b20ca9eb2aa2c434b225ff85399bb04f0)]:
|
|
14
|
+
- @withstudiocms/effect@0.1.0-beta.3
|
|
15
|
+
|
|
16
|
+
## 0.1.0-beta.2
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- Updated dependencies [[`2ad259e`](https://github.com/withstudiocms/studiocms/commit/2ad259e9662bd4c8b58e07629491cb322eb479fa), [`d77a8c1`](https://github.com/withstudiocms/studiocms/commit/d77a8c16c97b91343f1c03b2fd9dd2fca0252647), [`c14b94c`](https://github.com/withstudiocms/studiocms/commit/c14b94c855a750b5666fffc975bebf1a556cf80f), [`e70f380`](https://github.com/withstudiocms/studiocms/commit/e70f38001d9ef80e27f701d249fda23c670dfb5e)]:
|
|
21
|
+
- @withstudiocms/effect@0.1.0-beta.2
|
|
22
|
+
|
|
3
23
|
## 0.1.0-beta.1
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# @withstudiocms/component-registry
|
|
2
2
|
|
|
3
|
+
[](https://codecov.io/github/withstudiocms/studiocms)
|
|
4
|
+
|
|
3
5
|
Create a virtual Astro Component registry with ease.
|
|
4
6
|
|
|
5
7
|
## Install
|
|
@@ -31,7 +31,8 @@ const decodeMap = /* @__PURE__ */ new Map([
|
|
|
31
31
|
]);
|
|
32
32
|
const fromCodePoint = (
|
|
33
33
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, n/no-unsupported-features/es-builtins
|
|
34
|
-
String.fromCodePoint ??
|
|
34
|
+
String.fromCodePoint ?? /* v8 ignore start */
|
|
35
|
+
((codePoint) => {
|
|
35
36
|
let output = "";
|
|
36
37
|
if (codePoint > 65535) {
|
|
37
38
|
codePoint -= 65536;
|
|
@@ -103,6 +103,7 @@ class EntityDecoder {
|
|
|
103
103
|
this.state = 4 /* NamedEntity */;
|
|
104
104
|
return this.stateNamedEntity(input, offset);
|
|
105
105
|
}
|
|
106
|
+
/* v8 ignore start */
|
|
106
107
|
case 1 /* NumericStart */: {
|
|
107
108
|
return this.stateNumericStart(input, offset);
|
|
108
109
|
}
|
|
@@ -297,6 +298,7 @@ class EntityDecoder {
|
|
|
297
298
|
}
|
|
298
299
|
return consumed;
|
|
299
300
|
}
|
|
301
|
+
/* v8 ignore start */
|
|
300
302
|
/**
|
|
301
303
|
* Signal to the parser that the end of the input was reached.
|
|
302
304
|
*
|
|
@@ -325,6 +327,7 @@ class EntityDecoder {
|
|
|
325
327
|
}
|
|
326
328
|
}
|
|
327
329
|
}
|
|
330
|
+
/* v8 ignore stop */
|
|
328
331
|
}
|
|
329
332
|
function getDecoder(decodeTree) {
|
|
330
333
|
let returnValue = "";
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import type { SSRResult } from 'astro';
|
|
2
|
+
import { jsx } from 'astro/jsx-runtime';
|
|
3
|
+
import { renderJSX } from 'astro/runtime/server/jsx.js';
|
|
4
|
+
import { __unsafeHTML } from 'ultrahtml';
|
|
2
5
|
import type { ComponentType } from '../types.js';
|
|
3
6
|
export * from './decoder/index.js';
|
|
7
|
+
interface TestProps {
|
|
8
|
+
renderJSX: typeof renderJSX;
|
|
9
|
+
jsx: typeof jsx;
|
|
10
|
+
__unsafeHTML: typeof __unsafeHTML;
|
|
11
|
+
}
|
|
4
12
|
/**
|
|
5
13
|
* Creates a proxy for components that can either be strings or functions.
|
|
6
14
|
* If the component is a string, it is directly assigned to the proxy.
|
|
@@ -11,4 +19,4 @@ export * from './decoder/index.js';
|
|
|
11
19
|
* @param _components - An optional record of components to be proxied. Defaults to an empty object.
|
|
12
20
|
* @returns A record of proxied components.
|
|
13
21
|
*/
|
|
14
|
-
export declare function createComponentProxy(result: SSRResult, _components?: ComponentType): ComponentType;
|
|
22
|
+
export declare function createComponentProxy(result: SSRResult, _components?: ComponentType, _testProps?: TestProps): ComponentType;
|
|
@@ -3,7 +3,7 @@ import { renderJSX } from "astro/runtime/server/jsx.js";
|
|
|
3
3
|
import { __unsafeHTML } from "ultrahtml";
|
|
4
4
|
import { decode } from "./decoder/index.js";
|
|
5
5
|
export * from "./decoder/index.js";
|
|
6
|
-
function createComponentProxy(result, _components = {}) {
|
|
6
|
+
function createComponentProxy(result, _components = {}, _testProps = { jsx, __unsafeHTML, renderJSX }) {
|
|
7
7
|
const components = /* @__PURE__ */ Object.create(null);
|
|
8
8
|
for (const [rawKey, value] of Object.entries(_components)) {
|
|
9
9
|
const lowerKey = rawKey.toLowerCase();
|
|
@@ -24,11 +24,11 @@ function createComponentProxy(result, _components = {}) {
|
|
|
24
24
|
props = { ...props, code: decode(safe) };
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
const output = await renderJSX(
|
|
27
|
+
const output = await _testProps.renderJSX(
|
|
28
28
|
result,
|
|
29
|
-
jsx(value, { ...props, "set:html": children?.value })
|
|
29
|
+
_testProps.jsx(value, { ...props, "set:html": children?.value })
|
|
30
30
|
);
|
|
31
|
-
return __unsafeHTML(output);
|
|
31
|
+
return _testProps.__unsafeHTML(output);
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
34
|
}
|
|
@@ -22,6 +22,7 @@ class PropsParser extends Effect.Service()("PropsParser", {
|
|
|
22
22
|
const tagName = tag.getTagName();
|
|
23
23
|
const commentText = tag.getCommentText();
|
|
24
24
|
switch (tagName) {
|
|
25
|
+
/* v8 ignore start */
|
|
25
26
|
case "param": {
|
|
26
27
|
const paramInfo = tag.getStructure();
|
|
27
28
|
jsDocTags.push({
|
|
@@ -32,6 +33,7 @@ class PropsParser extends Effect.Service()("PropsParser", {
|
|
|
32
33
|
});
|
|
33
34
|
break;
|
|
34
35
|
}
|
|
36
|
+
/* v8 ignore stop */
|
|
35
37
|
case "default": {
|
|
36
38
|
defaultValue = commentText;
|
|
37
39
|
jsDocTags.push({
|
|
@@ -52,6 +54,7 @@ class PropsParser extends Effect.Service()("PropsParser", {
|
|
|
52
54
|
case "internal":
|
|
53
55
|
case "beta":
|
|
54
56
|
case "alpha":
|
|
57
|
+
/* v8 ignore start */
|
|
55
58
|
case "experimental": {
|
|
56
59
|
jsDocTags.push({
|
|
57
60
|
tagName,
|
|
@@ -126,6 +129,7 @@ class PropsParser extends Effect.Service()("PropsParser", {
|
|
|
126
129
|
}
|
|
127
130
|
return results;
|
|
128
131
|
},
|
|
132
|
+
/* v8 ignore start */
|
|
129
133
|
catch: (error) => {
|
|
130
134
|
console.error("Error parsing component props:", error);
|
|
131
135
|
return new ComponentRegistryError({
|
|
@@ -133,6 +137,7 @@ class PropsParser extends Effect.Service()("PropsParser", {
|
|
|
133
137
|
cause: error
|
|
134
138
|
});
|
|
135
139
|
}
|
|
140
|
+
/* v8 ignore stop */
|
|
136
141
|
}),
|
|
137
142
|
extractPropsFromAstroFile: (astroFileContent) => Effect.try({
|
|
138
143
|
try: () => {
|
|
@@ -28,10 +28,14 @@ class ComponentRegistry extends Effect.Service()("ComponentRegistry", {
|
|
|
28
28
|
const name = componentName || path.basename(filePath, path.extname(filePath));
|
|
29
29
|
const parsed = yield* parser.parseComponentProps(propsDefinition).pipe(
|
|
30
30
|
Effect.mapError(
|
|
31
|
-
(error) =>
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
(error) => (
|
|
32
|
+
/* v8 ignore start */
|
|
33
|
+
new ComponentRegistryError({
|
|
34
|
+
message: `Failed to register component ${name}`,
|
|
35
|
+
cause: error
|
|
36
|
+
})
|
|
37
|
+
)
|
|
38
|
+
/* v8 ignore stop */
|
|
35
39
|
)
|
|
36
40
|
);
|
|
37
41
|
if (parsed.length > 0) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="../virtual.d.ts" preserve="true" />
|
|
2
|
+
import { Effect } from '@withstudiocms/effect';
|
|
2
3
|
import { z } from 'astro/zod';
|
|
3
4
|
export declare const ComponentRegistryHandlerOptionSchema: z.ZodObject<{
|
|
4
5
|
config: z.ZodObject<{
|
|
@@ -51,6 +52,19 @@ export declare const ComponentRegistryHandlerOptionSchema: z.ZodObject<{
|
|
|
51
52
|
builtInComponents?: Record<string, string> | undefined;
|
|
52
53
|
}>;
|
|
53
54
|
export type ComponentRegistryHandlerOptions = z.infer<typeof ComponentRegistryHandlerOptionSchema>;
|
|
55
|
+
/**
|
|
56
|
+
* Creates an Effect-based resolver function for resolving component paths.
|
|
57
|
+
*
|
|
58
|
+
* @param base - The base path used to initialize the resolver.
|
|
59
|
+
* @returns An Effect-wrapped function that accepts a callback. The callback receives a `resolve` function,
|
|
60
|
+
* which can be used to resolve component paths relative to the base. If an error occurs during resolution,
|
|
61
|
+
* it is caught, logged to the console, and an Error object is returned with the original error as its cause.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* const resolveEffect = resolver('/components');
|
|
65
|
+
* const result = yield* resolveEffect((resolve) => resolve('Button'));
|
|
66
|
+
*/
|
|
67
|
+
export declare const resolver: (base: string) => Effect.Effect<(fn: (resolve: (...path: Array<string>) => string) => string) => Effect.Effect.AsEffect<Effect.Effect<string, Error, never>>, never, never>;
|
|
54
68
|
/**
|
|
55
69
|
* Handles the setup and registration of components in the component registry during the Astro config setup phase.
|
|
56
70
|
*
|
package/dist/registry/handler.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@withstudiocms/component-registry",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.3",
|
|
4
4
|
"description": "Component Registry Utilities for Astro",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -70,9 +70,9 @@
|
|
|
70
70
|
"type": "module",
|
|
71
71
|
"dependencies": {
|
|
72
72
|
"astro-integration-kit": "^0.19.0",
|
|
73
|
-
"ts-morph": "^
|
|
73
|
+
"ts-morph": "^27.0.0",
|
|
74
74
|
"ultrahtml": "1.6.0",
|
|
75
|
-
"@withstudiocms/effect": "0.1.0-beta.
|
|
75
|
+
"@withstudiocms/effect": "0.1.0-beta.3"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
78
|
"@types/node": "^22.0.0",
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"scripts": {
|
|
85
85
|
"build": "buildkit build 'src/**/*.{ts,d.ts}'",
|
|
86
86
|
"dev": "buildkit dev 'src/**/*.{ts,d.ts}'",
|
|
87
|
-
"test": "
|
|
87
|
+
"test": "vitest",
|
|
88
88
|
"typecheck": "tspc -p tsconfig.tspc.json"
|
|
89
89
|
}
|
|
90
90
|
}
|