labx-components 1.0.0 → 1.0.1

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.
@@ -30,6 +30,7 @@ LabxButton = __decorate([
30
30
  inputs: ['disabled', 'label', 'type', 'variant']
31
31
  }),
32
32
  Component({
33
+ standalone: true,
33
34
  selector: 'labx-button',
34
35
  changeDetection: ChangeDetectionStrategy.OnPush,
35
36
  template: '<ng-content></ng-content>',
@@ -54,6 +55,7 @@ LabxIcon = __decorate([
54
55
  inputs: ['filled', 'name', 'size']
55
56
  }),
56
57
  Component({
58
+ standalone: true,
57
59
  selector: 'labx-icon',
58
60
  changeDetection: ChangeDetectionStrategy.OnPush,
59
61
  template: '<ng-content></ng-content>',
@@ -81,6 +83,7 @@ LabxInput = __decorate([
81
83
  inputs: ['disabled', 'error', 'label', 'type', 'value']
82
84
  }),
83
85
  Component({
86
+ standalone: true,
84
87
  selector: 'labx-input',
85
88
  changeDetection: ChangeDetectionStrategy.OnPush,
86
89
  template: '<ng-content></ng-content>',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "labx-components",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Web Components library built with Stencil. Includes Angular wrappers and design tokens.",
5
5
  "author": "egarcia9543",
6
6
  "license": "MIT",
@@ -43,11 +43,12 @@
43
43
  "files": [
44
44
  "dist/",
45
45
  "loader/",
46
+ "src-angular/",
46
47
  "dist-angular/"
47
48
  ],
48
49
  "scripts": {
49
- "build": "stencil build && tsc -p tsconfig.angular.json",
50
- "build:angular": "tsc -p tsconfig.angular.json",
50
+ "build": "node -e \"require('fs').mkdirSync('dist-angular',{recursive:true})\" && stencil build && node scripts/patch-angular.js && tsc -p tsconfig.angular.json",
51
+ "build:angular": "node scripts/patch-angular.js && tsc -p tsconfig.angular.json",
51
52
  "start": "stencil build --dev --watch --serve",
52
53
  "test": "stencil-test",
53
54
  "test:watch": "stencil-test --watch",
@@ -0,0 +1,65 @@
1
+ /* eslint-disable */
2
+ /* tslint:disable */
3
+ import { fromEvent } from 'rxjs';
4
+
5
+ export const proxyInputs = (Cmp: any, inputs: string[]) => {
6
+ const Prototype = Cmp.prototype;
7
+ inputs.forEach((item) => {
8
+ Object.defineProperty(Prototype, item, {
9
+ get() {
10
+ return this.el[item];
11
+ },
12
+ set(val: any) {
13
+ this.z.runOutsideAngular(() => (this.el[item] = val));
14
+ },
15
+ /**
16
+ * In the event that proxyInputs is called
17
+ * multiple times re-defining these inputs
18
+ * will cause an error to be thrown. As a result
19
+ * we set configurable: true to indicate these
20
+ * properties can be changed.
21
+ */
22
+ configurable: true,
23
+ });
24
+ });
25
+ };
26
+
27
+ export const proxyMethods = (Cmp: any, methods: string[]) => {
28
+ const Prototype = Cmp.prototype;
29
+ methods.forEach((methodName) => {
30
+ Prototype[methodName] = function () {
31
+ const args = arguments;
32
+ return this.z.runOutsideAngular(() => this.el[methodName].apply(this.el, args));
33
+ };
34
+ });
35
+ };
36
+
37
+ export const proxyOutputs = (instance: any, el: any, events: string[]) => {
38
+ events.forEach((eventName) => (instance[eventName] = fromEvent(el, eventName)));
39
+ };
40
+
41
+ export const defineCustomElement = (tagName: string, customElement: any) => {
42
+ if (customElement !== undefined && typeof customElements !== 'undefined' && !customElements.get(tagName)) {
43
+ customElements.define(tagName, customElement);
44
+ }
45
+ };
46
+
47
+ // tslint:disable-next-line: only-arrow-functions
48
+ export function ProxyCmp(opts: { defineCustomElementFn?: () => void; inputs?: any; methods?: any }) {
49
+ const decorator = function (cls: any) {
50
+ const { defineCustomElementFn, inputs, methods } = opts;
51
+
52
+ if (defineCustomElementFn !== undefined) {
53
+ defineCustomElementFn();
54
+ }
55
+
56
+ if (inputs) {
57
+ proxyInputs(cls, inputs);
58
+ }
59
+ if (methods) {
60
+ proxyMethods(cls, methods);
61
+ }
62
+ return cls;
63
+ };
64
+ return decorator;
65
+ }
@@ -0,0 +1,97 @@
1
+ /* tslint:disable */
2
+ /* auto-generated angular directive proxies */
3
+ import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, EventEmitter, Output, NgZone } from '@angular/core';
4
+
5
+ import { ProxyCmp } from './angular-component-lib/utils';
6
+
7
+ import type { Components } from 'labx-components/components';
8
+
9
+ import { defineCustomElement as defineLabxButton } from 'labx-components/components/labx-button.js';
10
+ import { defineCustomElement as defineLabxIcon } from 'labx-components/components/labx-icon.js';
11
+ import { defineCustomElement as defineLabxInput } from 'labx-components/components/labx-input.js';
12
+ @ProxyCmp({
13
+ defineCustomElementFn: defineLabxButton,
14
+ inputs: ['disabled', 'label', 'type', 'variant']
15
+ })
16
+ @Component({
17
+ standalone: true,
18
+ selector: 'labx-button',
19
+ changeDetection: ChangeDetectionStrategy.OnPush,
20
+ template: '<ng-content></ng-content>',
21
+ // eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
22
+ inputs: ['disabled', 'label', 'type', 'variant'],
23
+ outputs: ['labxClick'],
24
+ })
25
+ export class LabxButton {
26
+ protected el: HTMLLabxButtonElement;
27
+ @Output() labxClick = new EventEmitter<CustomEvent<void>>();
28
+ constructor(c: ChangeDetectorRef, r: ElementRef, protected z: NgZone) {
29
+ c.detach();
30
+ this.el = r.nativeElement;
31
+ }
32
+ }
33
+
34
+
35
+ export declare interface LabxButton extends Components.LabxButton {
36
+ /**
37
+ * Se emite cuando el botón es clickeado
38
+ */
39
+ labxClick: EventEmitter<CustomEvent<void>>;
40
+ }
41
+
42
+
43
+ @ProxyCmp({
44
+ defineCustomElementFn: defineLabxIcon,
45
+ inputs: ['filled', 'name', 'size']
46
+ })
47
+ @Component({
48
+ standalone: true,
49
+ selector: 'labx-icon',
50
+ changeDetection: ChangeDetectionStrategy.OnPush,
51
+ template: '<ng-content></ng-content>',
52
+ // eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
53
+ inputs: ['filled', { name: 'name', required: true }, 'size'],
54
+ })
55
+ export class LabxIcon {
56
+ protected el: HTMLLabxIconElement;
57
+ constructor(c: ChangeDetectorRef, r: ElementRef, protected z: NgZone) {
58
+ c.detach();
59
+ this.el = r.nativeElement;
60
+ }
61
+ }
62
+
63
+
64
+ export declare interface LabxIcon extends Components.LabxIcon {}
65
+
66
+
67
+ @ProxyCmp({
68
+ defineCustomElementFn: defineLabxInput,
69
+ inputs: ['disabled', 'error', 'label', 'type', 'value']
70
+ })
71
+ @Component({
72
+ standalone: true,
73
+ selector: 'labx-input',
74
+ changeDetection: ChangeDetectionStrategy.OnPush,
75
+ template: '<ng-content></ng-content>',
76
+ // eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
77
+ inputs: ['disabled', 'error', 'label', 'type', 'value'],
78
+ outputs: ['labxChange'],
79
+ })
80
+ export class LabxInput {
81
+ protected el: HTMLLabxInputElement;
82
+ @Output() labxChange = new EventEmitter<CustomEvent<string>>();
83
+ constructor(c: ChangeDetectorRef, r: ElementRef, protected z: NgZone) {
84
+ c.detach();
85
+ this.el = r.nativeElement;
86
+ }
87
+ }
88
+
89
+
90
+ export declare interface LabxInput extends Components.LabxInput {
91
+ /**
92
+ * Se emite cuando el valor cambia
93
+ */
94
+ labxChange: EventEmitter<CustomEvent<string>>;
95
+ }
96
+
97
+
@@ -0,0 +1,8 @@
1
+
2
+ import * as d from './components';
3
+
4
+ export const DIRECTIVES = [
5
+ d.LabxButton,
6
+ d.LabxIcon,
7
+ d.LabxInput
8
+ ];
@@ -0,0 +1,24 @@
1
+ import { Directive, ElementRef, forwardRef } from '@angular/core';
2
+ import { NG_VALUE_ACCESSOR } from '@angular/forms';
3
+
4
+ import { ValueAccessor } from './value-accessor';
5
+
6
+ @Directive({
7
+ /* tslint:disable-next-line:directive-selector */
8
+ selector: 'labx-input',
9
+ host: {
10
+ '(labxChange)': 'handleChangeEvent($event.target?.["value"])'
11
+ },
12
+ providers: [
13
+ {
14
+ provide: NG_VALUE_ACCESSOR,
15
+ useExisting: forwardRef(() => TextValueAccessor),
16
+ multi: true
17
+ }
18
+ ]
19
+ })
20
+ export class TextValueAccessor extends ValueAccessor {
21
+ constructor(el: ElementRef) {
22
+ super(el);
23
+ }
24
+ }
@@ -0,0 +1,39 @@
1
+ import { Directive, ElementRef, HostListener } from '@angular/core';
2
+ import { ControlValueAccessor } from '@angular/forms';
3
+
4
+ @Directive({})
5
+ export class ValueAccessor implements ControlValueAccessor {
6
+
7
+ private onChange: (value: any) => void = () => {/**/};
8
+ private onTouched: () => void = () => {/**/};
9
+ protected lastValue: any;
10
+
11
+ constructor(protected el: ElementRef) {}
12
+
13
+ writeValue(value: any) {
14
+ this.el.nativeElement.value = this.lastValue = value == null ? '' : value;
15
+ }
16
+
17
+ handleChangeEvent(value: any) {
18
+ if (value !== this.lastValue) {
19
+ this.lastValue = value;
20
+ this.onChange(value);
21
+ }
22
+ }
23
+
24
+ @HostListener('focusout')
25
+ _handleBlurEvent() {
26
+ this.onTouched();
27
+ }
28
+
29
+ registerOnChange(fn: (value: any) => void) {
30
+ this.onChange = fn;
31
+ }
32
+ registerOnTouched(fn: () => void) {
33
+ this.onTouched = fn;
34
+ }
35
+
36
+ setDisabledState(isDisabled: boolean) {
37
+ this.el.nativeElement.disabled = isDisabled;
38
+ }
39
+ }