@primate/webc 0.2.0 → 0.3.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/lib/private/Default.d.ts +1 -1
- package/lib/private/Default.js +6 -7
- package/lib/private/Runtime.d.ts +1 -1
- package/lib/private/Runtime.js +5 -5
- package/lib/private/client/Component.d.ts +2 -2
- package/lib/private/client/Component.js +3 -0
- package/lib/private/client/index.d.ts +5 -1
- package/lib/private/client/index.js +3 -5
- package/package.json +3 -3
package/lib/private/Default.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import Runtime from "#Runtime";
|
|
|
2
2
|
import type FileRef from "@rcompat/fs/FileRef";
|
|
3
3
|
export default class Default extends Runtime {
|
|
4
4
|
compile: {
|
|
5
|
-
client: (text: string,
|
|
5
|
+
client: (text: string, view: FileRef) => Promise<{
|
|
6
6
|
js: string;
|
|
7
7
|
}>;
|
|
8
8
|
normalize: (name: string) => Promise<string>;
|
package/lib/private/Default.js
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import Runtime from "#Runtime";
|
|
2
|
-
import
|
|
2
|
+
import fail from "@primate/core/fail";
|
|
3
3
|
const script_re = /(?<=<script)>(?<code>.*?)(?=<\/script>)/gus;
|
|
4
4
|
const webc_class_name_re = /export default class (?<name>.*?) extends/u;
|
|
5
5
|
export default class Default extends Runtime {
|
|
6
6
|
compile = {
|
|
7
|
-
client: async (text,
|
|
7
|
+
client: async (text, view) => {
|
|
8
8
|
const [script] = [...text.matchAll(script_re)]
|
|
9
9
|
.map(({ groups }) => groups.code);
|
|
10
10
|
const { name } = script.match(webc_class_name_re)?.groups
|
|
11
11
|
?? { name: undefined };
|
|
12
|
-
if (name === undefined)
|
|
13
|
-
throw
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
.debase(component.directory, "/").path)).replace("_", "-");
|
|
12
|
+
if (name === undefined)
|
|
13
|
+
throw fail("view at {0} has no class name", view);
|
|
14
|
+
const tag = (await this.normalize(view
|
|
15
|
+
.debase(view.directory, "/").path)).replace("_", "-");
|
|
17
16
|
const js = `${script}
|
|
18
17
|
globalThis.customElements.define("${tag}", ${name});
|
|
19
18
|
`;
|
package/lib/private/Runtime.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export default class Runtime extends FrontendModule {
|
|
|
10
10
|
layouts: boolean;
|
|
11
11
|
client: boolean;
|
|
12
12
|
render: Render;
|
|
13
|
-
get
|
|
13
|
+
get views(): FileRef | undefined;
|
|
14
14
|
init<T extends App>(app: T, next: Next<T>): import("@rcompat/type/MaybePromise").default<T>;
|
|
15
15
|
}
|
|
16
16
|
//# sourceMappingURL=Runtime.d.ts.map
|
package/lib/private/Runtime.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import FrontendModule from "@primate/core/frontend/Module";
|
|
2
2
|
export default class Runtime extends FrontendModule {
|
|
3
|
-
#
|
|
3
|
+
#views;
|
|
4
4
|
name = "webc";
|
|
5
5
|
defaultExtensions = [".webc"];
|
|
6
6
|
layouts = false;
|
|
7
7
|
client = true;
|
|
8
|
-
render = (
|
|
8
|
+
render = (_view, _props) => {
|
|
9
9
|
return { body: "", head: "" };
|
|
10
10
|
};
|
|
11
|
-
get
|
|
12
|
-
return this.#
|
|
11
|
+
get views() {
|
|
12
|
+
return this.#views;
|
|
13
13
|
}
|
|
14
14
|
init(app, next) {
|
|
15
|
-
this.#
|
|
15
|
+
this.#views = app.path.views;
|
|
16
16
|
return super.init(app, next);
|
|
17
17
|
}
|
|
18
18
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type Dict from "@rcompat/type/Dict";
|
|
2
|
-
export default
|
|
2
|
+
export default class Component extends HTMLElement {
|
|
3
3
|
#private;
|
|
4
4
|
static tag: string;
|
|
5
5
|
constructor(props?: Dict);
|
|
6
6
|
get props(): Dict;
|
|
7
7
|
set props(props: Dict);
|
|
8
8
|
connectedCallback(): void;
|
|
9
|
-
|
|
9
|
+
render(props: Dict): string;
|
|
10
10
|
mounted(_: ShadowRoot): void;
|
|
11
11
|
toString(): string;
|
|
12
12
|
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import type Dict from "@rcompat/type/Dict";
|
|
2
|
+
type Props = {
|
|
3
|
+
props: Dict;
|
|
4
|
+
};
|
|
2
5
|
export default class WebComponentsClient {
|
|
3
|
-
static mount(
|
|
6
|
+
static mount(view: string, props: Props): void;
|
|
4
7
|
}
|
|
8
|
+
export {};
|
|
5
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
import * as components from "webc:components";
|
|
1
|
+
import * as views from "webc:views";
|
|
3
2
|
export default class WebComponentsClient {
|
|
4
|
-
static mount(
|
|
5
|
-
globalThis.document.body
|
|
6
|
-
.appendChild(new components[component](props.props));
|
|
3
|
+
static mount(view, props) {
|
|
4
|
+
globalThis.document.body.appendChild(new views[view](props.props));
|
|
7
5
|
}
|
|
8
6
|
}
|
|
9
7
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primate/webc",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Primate web components frontend",
|
|
5
5
|
"homepage": "https://primate.run/docs/frontend/web-components",
|
|
6
6
|
"bugs": "https://github.com/primate-run/primate/issues",
|
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@rcompat/fs": "^0.21.1",
|
|
20
|
-
"@primate/core": "^0.
|
|
20
|
+
"@primate/core": "^0.3.0"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
|
-
"primate": "^0.
|
|
23
|
+
"primate": "^0.34.0"
|
|
24
24
|
},
|
|
25
25
|
"type": "module",
|
|
26
26
|
"imports": {
|