plinth-ui 0.0.2 → 0.0.4

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.
@@ -0,0 +1,9 @@
1
+ export declare const proxyInputs: (Cmp: any, inputs: string[]) => void;
2
+ export declare const proxyMethods: (Cmp: any, methods: string[]) => void;
3
+ export declare const proxyOutputs: (instance: any, el: any, events: string[]) => void;
4
+ export declare const defineCustomElement: (tagName: string, customElement: any) => void;
5
+ export declare function ProxyCmp(opts: {
6
+ defineCustomElementFn?: () => void;
7
+ inputs?: any;
8
+ methods?: any;
9
+ }): (cls: any) => any;
@@ -0,0 +1,58 @@
1
+ /* eslint-disable */
2
+ /* tslint:disable */
3
+ import { fromEvent } from 'rxjs';
4
+ export const proxyInputs = (Cmp, inputs) => {
5
+ const Prototype = Cmp.prototype;
6
+ inputs.forEach((item) => {
7
+ Object.defineProperty(Prototype, item, {
8
+ get() {
9
+ return this.el[item];
10
+ },
11
+ set(val) {
12
+ this.z.runOutsideAngular(() => (this.el[item] = val));
13
+ },
14
+ /**
15
+ * In the event that proxyInputs is called
16
+ * multiple times re-defining these inputs
17
+ * will cause an error to be thrown. As a result
18
+ * we set configurable: true to indicate these
19
+ * properties can be changed.
20
+ */
21
+ configurable: true,
22
+ });
23
+ });
24
+ };
25
+ export const proxyMethods = (Cmp, methods) => {
26
+ const Prototype = Cmp.prototype;
27
+ methods.forEach((methodName) => {
28
+ Prototype[methodName] = function () {
29
+ const args = arguments;
30
+ return this.z.runOutsideAngular(() => this.el[methodName].apply(this.el, args));
31
+ };
32
+ });
33
+ };
34
+ export const proxyOutputs = (instance, el, events) => {
35
+ events.forEach((eventName) => (instance[eventName] = fromEvent(el, eventName)));
36
+ };
37
+ export const defineCustomElement = (tagName, customElement) => {
38
+ if (customElement !== undefined && typeof customElements !== 'undefined' && !customElements.get(tagName)) {
39
+ customElements.define(tagName, customElement);
40
+ }
41
+ };
42
+ // tslint:disable-next-line: only-arrow-functions
43
+ export function ProxyCmp(opts) {
44
+ const decorator = function (cls) {
45
+ const { defineCustomElementFn, inputs, methods } = opts;
46
+ if (defineCustomElementFn !== undefined) {
47
+ defineCustomElementFn();
48
+ }
49
+ if (inputs) {
50
+ proxyInputs(cls, inputs);
51
+ }
52
+ if (methods) {
53
+ proxyMethods(cls, methods);
54
+ }
55
+ return cls;
56
+ };
57
+ return decorator;
58
+ }
@@ -0,0 +1,9 @@
1
+ import { ChangeDetectorRef, ElementRef, NgZone } from '@angular/core';
2
+ import type { Components } from 'plinth-ui/components';
3
+ export declare class MyComponent {
4
+ protected z: NgZone;
5
+ protected el: HTMLMyComponentElement;
6
+ constructor(c: ChangeDetectorRef, r: ElementRef, z: NgZone);
7
+ }
8
+ export declare interface MyComponent extends Components.MyComponent {
9
+ }
@@ -0,0 +1,73 @@
1
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
2
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
3
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
4
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
5
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
6
+ var _, done = false;
7
+ for (var i = decorators.length - 1; i >= 0; i--) {
8
+ var context = {};
9
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
10
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
11
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
12
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
13
+ if (kind === "accessor") {
14
+ if (result === void 0) continue;
15
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
16
+ if (_ = accept(result.get)) descriptor.get = _;
17
+ if (_ = accept(result.set)) descriptor.set = _;
18
+ if (_ = accept(result.init)) initializers.unshift(_);
19
+ }
20
+ else if (_ = accept(result)) {
21
+ if (kind === "field") initializers.unshift(_);
22
+ else descriptor[key] = _;
23
+ }
24
+ }
25
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
26
+ done = true;
27
+ };
28
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
29
+ var useValue = arguments.length > 2;
30
+ for (var i = 0; i < initializers.length; i++) {
31
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
32
+ }
33
+ return useValue ? value : void 0;
34
+ };
35
+ /* tslint:disable */
36
+ /* auto-generated angular directive proxies */
37
+ import { ChangeDetectionStrategy, Component } from '@angular/core';
38
+ import { ProxyCmp } from './angular-component-lib/utils';
39
+ import { defineCustomElement as defineMyComponent } from 'plinth-ui/components/my-component.js';
40
+ let MyComponent = (() => {
41
+ let _classDecorators = [ProxyCmp({
42
+ defineCustomElementFn: defineMyComponent,
43
+ inputs: ['first', 'last', 'middle']
44
+ }), Component({
45
+ selector: 'my-component',
46
+ changeDetection: ChangeDetectionStrategy.OnPush,
47
+ template: '<ng-content></ng-content>',
48
+ // eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
49
+ inputs: ['first', 'last', 'middle'],
50
+ })];
51
+ let _classDescriptor;
52
+ let _classExtraInitializers = [];
53
+ let _classThis;
54
+ var MyComponent = class {
55
+ static { _classThis = this; }
56
+ static {
57
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
58
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
59
+ MyComponent = _classThis = _classDescriptor.value;
60
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
61
+ __runInitializers(_classThis, _classExtraInitializers);
62
+ }
63
+ z;
64
+ el;
65
+ constructor(c, r, z) {
66
+ this.z = z;
67
+ c.detach();
68
+ this.el = r.nativeElement;
69
+ }
70
+ };
71
+ return MyComponent = _classThis;
72
+ })();
73
+ export { MyComponent };
@@ -0,0 +1,2 @@
1
+ import * as d from './components';
2
+ export declare const DIRECTIVES: (typeof d.MyComponent)[];
@@ -0,0 +1,4 @@
1
+ import * as d from './components';
2
+ export const DIRECTIVES = [
3
+ d.MyComponent
4
+ ];
@@ -0,0 +1,5 @@
1
+ /**
2
+ * This file was automatically generated by the Stencil React Output Target.
3
+ * Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
4
+ */
5
+ export { MyComponent } from "./my-component.js";
@@ -0,0 +1,6 @@
1
+ /**
2
+ * This file was automatically generated by the Stencil React Output Target.
3
+ * Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
4
+ */
5
+ /* eslint-disable */
6
+ export { MyComponent } from "./my-component.js";
@@ -0,0 +1,7 @@
1
+ /**
2
+ * React proxies entrypoint.
3
+ *
4
+ * This file is written by scripts/prepare-framework-proxies.cjs
5
+ * and should be committed to the build output only.
6
+ */
7
+ export * from './components';
@@ -0,0 +1,7 @@
1
+ /**
2
+ * React proxies entrypoint.
3
+ *
4
+ * This file is written by scripts/prepare-framework-proxies.cjs
5
+ * and should be committed to the build output only.
6
+ */
7
+ export * from './components';
@@ -0,0 +1,8 @@
1
+ /**
2
+ * React proxies entrypoint.
3
+ *
4
+ * This file is written by scripts/prepare-framework-proxies.cjs
5
+ * and should be committed to the build output only.
6
+ */
7
+
8
+ export * from './components';
@@ -0,0 +1,8 @@
1
+ /**
2
+ * This file was automatically generated by the Stencil React Output Target.
3
+ * Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
4
+ */
5
+ import type { StencilReactComponent } from '@stencil/react-output-target/runtime';
6
+ import { MyComponent as MyComponentElement } from "plinth-ui/components/my-component.js";
7
+ export type MyComponentEvents = NonNullable<unknown>;
8
+ export declare const MyComponent: StencilReactComponent<MyComponentElement, MyComponentEvents>;
@@ -0,0 +1,12 @@
1
+ 'use client';
2
+ import { createComponent } from '@stencil/react-output-target/runtime';
3
+ import { MyComponent as MyComponentElement, defineCustomElement as defineMyComponent } from "plinth-ui/components/my-component.js";
4
+ import React from 'react';
5
+ export const MyComponent = /*@__PURE__*/ createComponent({
6
+ tagName: 'my-component',
7
+ elementClass: MyComponentElement,
8
+ // @ts-ignore - ignore potential React type mismatches between the Stencil Output Target and your project.
9
+ react: React,
10
+ events: {},
11
+ defineCustomElement: defineMyComponent
12
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plinth-ui",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "Stencil Component Starter",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.js",
@@ -29,20 +29,14 @@
29
29
  "require": "./dist/plinth-ui/plinth-ui.cjs.js"
30
30
  },
31
31
  "./angular": {
32
- "types": "./angular-workspace/projects/plinth-ui/src/lib/stencil-generated/public-api.ts",
33
- "import": "./angular-workspace/projects/plinth-ui/src/lib/stencil-generated/public-api.ts",
34
- "require": "./angular-workspace/projects/plinth-ui/src/lib/stencil-generated/public-api.ts",
35
- "default": "./angular-workspace/projects/plinth-ui/src/lib/stencil-generated/public-api.ts"
36
- },
37
- "./angular-workspace/projects/plinth-ui/src/lib/stencil-generated/": {
38
- "types": "./angular-workspace/projects/plinth-ui/src/lib/stencil-generated/public-api.ts",
39
- "import": "./angular-workspace/projects/plinth-ui/src/lib/stencil-generated/public-api.ts",
40
- "require": "./angular-workspace/projects/plinth-ui/src/lib/stencil-generated/public-api.ts",
41
- "default": "./angular-workspace/projects/plinth-ui/src/lib/stencil-generated/public-api.ts"
32
+ "types": "./dist/angular/index.d.ts",
33
+ "import": "./dist/angular/index.js",
34
+ "default": "./dist/angular/index.js"
42
35
  },
43
36
  "./react": {
44
- "types": "./react-library/src/components/generated/components.ts",
45
- "default": "./react-library/src/components/generated/components.ts"
37
+ "types": "./dist/react/index.d.ts",
38
+ "import": "./dist/react/index.js",
39
+ "default": "./dist/react/index.js"
46
40
  }
47
41
  },
48
42
  "repository": {
@@ -52,25 +46,34 @@
52
46
  "files": [
53
47
  "dist/",
54
48
  "loader/",
55
- "angular-workspace/projects/plinth-ui/src/lib/stencil-generated/",
56
- "react-library/src/components/generated/"
49
+ "scripts/"
57
50
  ],
58
51
  "scripts": {
59
- "build": "stencil build",
52
+ "build": "stencil build && npm run build:framework-proxies",
53
+ "build:framework-proxies": "node ./scripts/prepare-framework-proxies.cjs && tsc -p ./tsconfig.proxies.json",
60
54
  "start": "stencil build --dev --watch --serve",
61
55
  "test": "stencil test --spec --e2e",
62
56
  "test.watch": "stencil test --spec --e2e --watchAll",
63
57
  "generate": "stencil generate"
64
58
  },
65
59
  "devDependencies": {
60
+ "@angular/core": "^21.1.4",
66
61
  "@stencil/angular-output-target": "^1.3.0",
67
62
  "@stencil/core": "^4.27.1",
68
- "@stencil/react-output-target": "^1.4.1",
69
63
  "@types/jest": "^29.5.14",
70
64
  "@types/node": "^22.13.5",
65
+ "@types/react": "^19.2.14",
66
+ "@types/react-dom": "^19.2.3",
71
67
  "jest": "^29.7.0",
72
68
  "jest-cli": "^29.7.0",
73
- "puppeteer": "^24.3.0"
69
+ "puppeteer": "^24.3.0",
70
+ "react": "^19.2.4",
71
+ "react-dom": "^19.2.4",
72
+ "rxjs": "^7.8.2",
73
+ "typescript": "^5.9.3"
74
74
  },
75
- "license": "MIT"
75
+ "license": "MIT",
76
+ "dependencies": {
77
+ "@stencil/react-output-target": "^1.4.1"
78
+ }
76
79
  }
@@ -0,0 +1,47 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ const repoRoot = path.join(__dirname, '..');
5
+
6
+ function ensureDir(dir) {
7
+ fs.mkdirSync(dir, { recursive: true });
8
+ }
9
+
10
+ function writeReactEntrypoint() {
11
+ const reactDistDir = path.join(repoRoot, 'dist', 'react');
12
+ ensureDir(reactDistDir);
13
+
14
+ const indexTsPath = path.join(reactDistDir, 'index.ts');
15
+ const contents = `/**
16
+ * React proxies entrypoint.
17
+ *
18
+ * This file is written by scripts/prepare-framework-proxies.cjs
19
+ * and should be committed to the build output only.
20
+ */
21
+
22
+ export * from './components';
23
+ `;
24
+
25
+ fs.writeFileSync(indexTsPath, contents, 'utf8');
26
+ }
27
+
28
+ function copyAngularUtils() {
29
+ const src = path.join(
30
+ repoRoot,
31
+ 'node_modules',
32
+ '@stencil',
33
+ 'angular-output-target',
34
+ 'angular-component-lib',
35
+ 'utils.ts'
36
+ );
37
+
38
+ const angularLibDir = path.join(repoRoot, 'dist', 'angular', 'angular-component-lib');
39
+ ensureDir(angularLibDir);
40
+
41
+ const dest = path.join(angularLibDir, 'utils.ts');
42
+ fs.copyFileSync(src, dest);
43
+ }
44
+
45
+ writeReactEntrypoint();
46
+ copyAngularUtils();
47
+