@primate/webc 0.2.0 → 0.4.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.
@@ -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, component: FileRef) => Promise<{
5
+ client: (text: string, view: FileRef) => Promise<{
6
6
  js: string;
7
7
  }>;
8
8
  normalize: (name: string) => Promise<string>;
@@ -1,19 +1,18 @@
1
1
  import Runtime from "#Runtime";
2
- import AppError from "@primate/core/AppError";
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, component) => {
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 new AppError("Component at {0} has no class name", component);
14
- }
15
- const tag = (await this.normalize(component
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
  `;
@@ -10,7 +10,7 @@ export default class Runtime extends FrontendModule {
10
10
  layouts: boolean;
11
11
  client: boolean;
12
12
  render: Render;
13
- get components(): FileRef | undefined;
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
@@ -1,18 +1,18 @@
1
1
  import FrontendModule from "@primate/core/frontend/Module";
2
2
  export default class Runtime extends FrontendModule {
3
- #components;
3
+ #views;
4
4
  name = "webc";
5
5
  defaultExtensions = [".webc"];
6
6
  layouts = false;
7
7
  client = true;
8
- render = (_component, _props) => {
8
+ render = (_view, _props) => {
9
9
  return { body: "", head: "" };
10
10
  };
11
- get components() {
12
- return this.#components;
11
+ get views() {
12
+ return this.#views;
13
13
  }
14
14
  init(app, next) {
15
- this.#components = app.path.components;
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 abstract class Component extends HTMLElement {
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
- abstract render(props: Dict): string;
9
+ render(props: Dict): string;
10
10
  mounted(_: ShadowRoot): void;
11
11
  toString(): string;
12
12
  }
@@ -25,6 +25,9 @@ export default class Component extends HTMLElement {
25
25
  root.innerHTML = this.render(this.props);
26
26
  this.mounted(root);
27
27
  }
28
+ render(props) {
29
+ return "";
30
+ }
28
31
  mounted(_) {
29
32
  // noop
30
33
  }
@@ -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(component: string, props: Dict): void;
6
+ static mount(view: string, props: Props): void;
4
7
  }
8
+ export {};
5
9
  //# sourceMappingURL=index.d.ts.map
@@ -1,9 +1,7 @@
1
- // @ts-expect-error esbuild vfs
2
- import * as components from "webc:components";
1
+ import * as views from "webc:views";
3
2
  export default class WebComponentsClient {
4
- static mount(component, props) {
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.2.0",
3
+ "version": "0.4.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",
@@ -16,11 +16,11 @@
16
16
  "directory": "packages/webc"
17
17
  },
18
18
  "dependencies": {
19
- "@rcompat/fs": "^0.21.1",
20
- "@primate/core": "^0.2.0"
19
+ "@rcompat/fs": "^0.22.3",
20
+ "@primate/core": "^0.4.0"
21
21
  },
22
22
  "peerDependencies": {
23
- "primate": "^0.33.0"
23
+ "primate": "^0.35.0"
24
24
  },
25
25
  "type": "module",
26
26
  "imports": {