piral-litel 1.0.0-pre.2091 → 1.0.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2019 - 2021 smapiot
3
+ Copyright (c) 2019 - 2023 smapiot
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
- [![Piral Logo](https://github.com/smapiot/piral/raw/master/docs/assets/logo.png)](https://piral.io)
1
+ [![Piral Logo](https://github.com/smapiot/piral/raw/main/docs/assets/logo.png)](https://piral.io)
2
2
 
3
- # [Piral LitEl](https://piral.io) · [![GitHub License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/smapiot/piral/blob/master/LICENSE) [![npm version](https://img.shields.io/npm/v/piral-litel.svg?style=flat)](https://www.npmjs.com/package/piral-litel) [![tested with jest](https://img.shields.io/badge/tested_with-jest-99424f.svg)](https://jestjs.io) [![Gitter Chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/piral-io/community)
3
+ # [Piral LitEl](https://piral.io) · [![GitHub License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/smapiot/piral/blob/main/LICENSE) [![npm version](https://img.shields.io/npm/v/piral-litel.svg?style=flat)](https://www.npmjs.com/package/piral-litel) [![tested with jest](https://img.shields.io/badge/tested_with-jest-99424f.svg)](https://jestjs.io) [![Gitter Chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/piral-io/community)
4
4
 
5
- This is a plugin that only has a peer dependency to `piral-core`. What `piral-litel` brings to the table is a set of Pilet API extensions that can be used with `piral` or `piral-core`.
5
+ This is a plugin that only has a peer dependency to `lit-element`. What `piral-litel` brings to the table is a set of Pilet API extensions that can be used with `piral` or `piral-core`.
6
6
 
7
7
  The set includes a LitElement converter for any component registration, as well as a `fromLitEl` shortcut and a `LitElExtension` component.
8
8
 
@@ -47,7 +47,7 @@ Alternatively, if `piral-litel` has not been added to the Piral instance you can
47
47
 
48
48
  ```ts
49
49
  import { PiletApi } from '<name-of-piral-instance>';
50
- import { fromLitel } from 'piral-litel';
50
+ import { fromLitel } from 'piral-litel/convert';
51
51
  import './LitElPage';
52
52
 
53
53
  export function setup(piral: PiletApi) {
@@ -62,7 +62,6 @@ export function setup(piral: PiletApi) {
62
62
  Using LitElement with Piral is as simple as installing `piral-litel` and `lit-element`.
63
63
 
64
64
  ```ts
65
- import 'lit-element';
66
65
  import { createLitElApi } from 'piral-litel';
67
66
  ```
68
67
 
@@ -80,11 +79,11 @@ The `lit-element` and `@webcomponents/webcomponentsjs` packages should be shared
80
79
 
81
80
  ```json
82
81
  {
83
- "pilets": {
84
- "externals": [
85
- "@webcomponents/webcomponentsjs",
86
- "lit-element"
87
- ]
82
+ "importmap": {
83
+ "imports": {
84
+ "@webcomponents/webcomponentsjs": "",
85
+ "lit-element": ""
86
+ }
88
87
  }
89
88
  }
90
89
  ```
package/convert.d.ts CHANGED
@@ -1,9 +1,18 @@
1
- import type { HtmlComponent } from 'piral-core';
2
- import { createExtension } from './lib/extension';
3
- declare const convert: <TProps extends import("piral-core").BaseComponentProps>(elementName: string) => import("piral-core").ForeignComponent<TProps>;
1
+ import { createConverter } from './esm/converter';
2
+ export interface HtmlComponent<TProps> {
3
+ component: {
4
+ mount(element: HTMLElement, props: TProps, ctx: any, locals: any): void;
5
+ update?(element: HTMLElement, props: TProps, ctx: any, locals: any): void;
6
+ unmount?(element: HTMLElement, locals: any): void;
7
+ };
8
+ type: 'html';
9
+ }
4
10
  export interface LitElConverter {
5
- (...params: Parameters<typeof convert>): HtmlComponent<any>;
11
+ (...params: Parameters<ReturnType<typeof createConverter>>): HtmlComponent<any>;
6
12
  }
7
- export declare const fromLitEl: LitElConverter;
8
- export declare const createLitElExtension: typeof createExtension;
9
- export {};
13
+ export declare function createLitElConverter(...params: Parameters<typeof createConverter>): {
14
+ from: LitElConverter;
15
+ Extension: string;
16
+ };
17
+ declare const fromLitEl: LitElConverter, LitElExtension: string;
18
+ export { fromLitEl, LitElExtension };
package/convert.js CHANGED
@@ -1,11 +1,16 @@
1
- "use strict";
2
- exports.__esModule = true;
3
- exports.createLitElExtension = exports.fromLitEl = void 0;
4
- var converter_1 = require("./lib/converter");
5
- var extension_1 = require("./lib/extension");
6
- var convert = converter_1.createConverter();
7
- exports.fromLitEl = function (elementName) { return ({
8
- type: 'html',
9
- component: convert(elementName)
10
- }); };
11
- exports.createLitElExtension = extension_1.createExtension;
1
+ import { createConverter } from './esm/converter';
2
+ export function createLitElConverter() {
3
+ var params = [];
4
+ for (var _i = 0; _i < arguments.length; _i++) {
5
+ params[_i] = arguments[_i];
6
+ }
7
+ var convert = createConverter.apply(void 0, params);
8
+ var Extension = convert.Extension;
9
+ var from = function (elementName) { return ({
10
+ type: 'html',
11
+ component: convert(elementName),
12
+ }); };
13
+ return { from: from, Extension: Extension };
14
+ }
15
+ var _a = createLitElConverter(), fromLitEl = _a.from, LitElExtension = _a.Extension;
16
+ export { fromLitEl, LitElExtension };
@@ -0,0 +1,12 @@
1
+ import type { ForeignComponent, BaseComponentProps } from 'piral-core';
2
+ export interface LitElConverterOptions {
3
+ /**
4
+ * Defines the name of the extension component.
5
+ * @default litel-extension
6
+ */
7
+ selector?: string;
8
+ }
9
+ export declare function createConverter(config?: LitElConverterOptions): {
10
+ <TProps extends BaseComponentProps>(elementName: string): ForeignComponent<TProps>;
11
+ Extension: string;
12
+ };
@@ -0,0 +1,30 @@
1
+ import { createExtension } from './extension';
2
+ export function createConverter(config = {}) {
3
+ const { selector = 'litel-extension' } = config;
4
+ const Extension = createExtension(selector);
5
+ const convert = (elementName) => ({
6
+ mount(parent, data, ctx) {
7
+ const { piral } = data;
8
+ const el = parent.appendChild(document.createElement(elementName));
9
+ el.setAttribute('props', JSON.stringify(data));
10
+ el.setAttribute('ctx', JSON.stringify(ctx));
11
+ el.shadowRoot.addEventListener('render-html', (ev) => {
12
+ ev.stopPropagation();
13
+ piral.renderHtmlExtension(ev.detail.target, ev.detail.props);
14
+ }, false);
15
+ },
16
+ update(parent, data, ctx) {
17
+ const el = parent.querySelector(elementName);
18
+ if (el) {
19
+ el.setAttribute('props', JSON.stringify(data));
20
+ el.setAttribute('ctx', JSON.stringify(ctx));
21
+ }
22
+ },
23
+ unmount(el) {
24
+ el.innerHTML = '';
25
+ },
26
+ });
27
+ convert.Extension = Extension;
28
+ return convert;
29
+ }
30
+ //# sourceMappingURL=converter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"converter.js","sourceRoot":"","sources":["../src/converter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAU9C,MAAM,UAAU,eAAe,CAAC,SAAgC,EAAE;IAChE,MAAM,EAAE,QAAQ,GAAG,iBAAiB,EAAE,GAAG,MAAM,CAAC;IAChD,MAAM,SAAS,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC;IAC5C,MAAM,OAAO,GAAG,CAAoC,WAAmB,EAA4B,EAAE,CAAC,CAAC;QACrG,KAAK,CAAC,MAAM,EAAE,IAAI,EAAE,GAAG;YACrB,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;YACvB,MAAM,EAAE,GAAG,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC,CAAC;YACnE,EAAE,CAAC,YAAY,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;YAC/C,EAAE,CAAC,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;YAC5C,EAAE,CAAC,UAAU,CAAC,gBAAgB,CAC5B,aAAa,EACb,CAAC,EAAe,EAAE,EAAE;gBAClB,EAAE,CAAC,eAAe,EAAE,CAAC;gBACrB,KAAK,CAAC,mBAAmB,CAAC,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC/D,CAAC,EACD,KAAK,CACN,CAAC;QACJ,CAAC;QACD,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,GAAG;YACtB,MAAM,EAAE,GAAG,MAAM,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;YAE7C,IAAI,EAAE,EAAE;gBACN,EAAE,CAAC,YAAY,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;gBAC/C,EAAE,CAAC,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;aAC7C;QACH,CAAC;QACD,OAAO,CAAC,EAAE;YACR,EAAE,CAAC,SAAS,GAAG,EAAE,CAAC;QACpB,CAAC;KACF,CAAC,CAAC;IACH,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;IAC9B,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { PiralPlugin } from 'piral-core';
2
+ import type { PiletLitElApi } from './types';
3
+ /**
4
+ * Available configuration options for the LitElement plugin.
5
+ */
6
+ export interface LitElConfig {
7
+ }
8
+ /**
9
+ * Creates new Pilet API extensions for integration of LitElement.
10
+ */
11
+ export declare function createLitElApi(config?: LitElConfig): PiralPlugin<PiletLitElApi>;
package/esm/create.js ADDED
@@ -0,0 +1,20 @@
1
+ import { createConverter } from './converter';
2
+ /**
3
+ * Creates new Pilet API extensions for integration of LitElement.
4
+ */
5
+ export function createLitElApi(config = {}) {
6
+ return (context) => {
7
+ const convert = createConverter(config);
8
+ context.converters.litel = ({ elementName }) => convert(elementName);
9
+ return {
10
+ fromLitEl(elementName) {
11
+ return {
12
+ type: 'litel',
13
+ elementName,
14
+ };
15
+ },
16
+ LitElExtension: convert.Extension,
17
+ };
18
+ };
19
+ }
20
+ //# sourceMappingURL=create.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAQ9C;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,SAAsB,EAAE;IACrD,OAAO,CAAC,OAAO,EAAE,EAAE;QACjB,MAAM,OAAO,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;QACxC,OAAO,CAAC,UAAU,CAAC,KAAK,GAAG,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QAErE,OAAO;YACL,SAAS,CAAC,WAAW;gBACnB,OAAO;oBACL,IAAI,EAAE,OAAO;oBACb,WAAW;iBACZ,CAAC;YACJ,CAAC;YACD,cAAc,EAAE,OAAO,CAAC,SAAS;SAClC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1 @@
1
+ export declare function createExtension(selector: string): string;
@@ -0,0 +1,44 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import { LitElement, property, customElement } from 'lit-element';
3
+ export function createExtension(selector) {
4
+ let LitElExtension = class LitElExtension extends LitElement {
5
+ render() {
6
+ return undefined;
7
+ }
8
+ updated() {
9
+ this.dispatchEvent(new CustomEvent('render-html', {
10
+ bubbles: true,
11
+ detail: {
12
+ target: this.shadowRoot,
13
+ props: {
14
+ empty: this.onEmpty,
15
+ render: this.onRender,
16
+ params: this.params,
17
+ name: this.name,
18
+ },
19
+ },
20
+ }));
21
+ }
22
+ };
23
+ __decorate([
24
+ property(),
25
+ __metadata("design:type", String)
26
+ ], LitElExtension.prototype, "name", void 0);
27
+ __decorate([
28
+ property(),
29
+ __metadata("design:type", Object)
30
+ ], LitElExtension.prototype, "params", void 0);
31
+ __decorate([
32
+ property(),
33
+ __metadata("design:type", Function)
34
+ ], LitElExtension.prototype, "onEmpty", void 0);
35
+ __decorate([
36
+ property(),
37
+ __metadata("design:type", Function)
38
+ ], LitElExtension.prototype, "onRender", void 0);
39
+ LitElExtension = __decorate([
40
+ customElement(selector)
41
+ ], LitElExtension);
42
+ return selector;
43
+ }
44
+ //# sourceMappingURL=extension.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAElE,MAAM,UAAU,eAAe,CAAC,QAAgB;IAE9C,IAAM,cAAc,GAApB,MAAM,cAAe,SAAQ,UAAU;QAMrC,MAAM;YACJ,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,OAAO;YACL,IAAI,CAAC,aAAa,CAChB,IAAI,WAAW,CAAC,aAAa,EAAE;gBAC7B,OAAO,EAAE,IAAI;gBACb,MAAM,EAAE;oBACN,MAAM,EAAE,IAAI,CAAC,UAAU;oBACvB,KAAK,EAAE;wBACL,KAAK,EAAE,IAAI,CAAC,OAAO;wBACnB,MAAM,EAAE,IAAI,CAAC,QAAQ;wBACrB,MAAM,EAAE,IAAI,CAAC,MAAM;wBACnB,IAAI,EAAE,IAAI,CAAC,IAAI;qBAChB;iBACF;aACF,CAAC,CACH,CAAC;QACJ,CAAC;KACF,CAAA;IAzBa;QAAX,QAAQ,EAAE;;gDAAc;IACb;QAAX,QAAQ,EAAE;;kDAAa;IACZ;QAAX,QAAQ,EAAE;;mDAAoB;IACnB;QAAX,QAAQ,EAAE;;oDAAqB;IAJ5B,cAAc;QADnB,aAAa,CAAC,QAAQ,CAAC;OAClB,cAAc,CA0BnB;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC"}
package/esm/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './create';
2
+ export * from './types';
package/esm/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from './create';
2
+ export * from './types';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
package/esm/types.d.ts ADDED
@@ -0,0 +1,33 @@
1
+ import type { ForeignComponent } from 'piral-core';
2
+ declare module 'piral-core/lib/types/custom' {
3
+ interface PiletCustomApi extends PiletLitElApi {
4
+ }
5
+ interface PiralCustomComponentConverters<TProps> {
6
+ litel(component: LitElComponent): ForeignComponent<TProps>;
7
+ }
8
+ }
9
+ export interface LitElComponent {
10
+ /**
11
+ * The name of the LitElement root component to render.
12
+ */
13
+ elementName: string;
14
+ /**
15
+ * The type of the LitElement component.
16
+ */
17
+ type: 'litel';
18
+ }
19
+ /**
20
+ * Defines the provided set of LitElement Pilet API extensions.
21
+ */
22
+ export interface PiletLitElApi {
23
+ /**
24
+ * Wraps a LitElement component for use in Piral.
25
+ * @param component The name of the root component.
26
+ * @returns The Piral LitElement component.
27
+ */
28
+ fromLitEl(elementName: string): LitElComponent;
29
+ /**
30
+ * Gets the name of the LitElement extension.
31
+ */
32
+ LitElExtension: string;
33
+ }
package/esm/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -1,2 +1,12 @@
1
- import { ForeignComponent, BaseComponentProps } from 'piral-core';
2
- export declare function createConverter(): <TProps extends BaseComponentProps>(elementName: string) => ForeignComponent<TProps>;
1
+ import type { ForeignComponent, BaseComponentProps } from 'piral-core';
2
+ export interface LitElConverterOptions {
3
+ /**
4
+ * Defines the name of the extension component.
5
+ * @default litel-extension
6
+ */
7
+ selector?: string;
8
+ }
9
+ export declare function createConverter(config?: LitElConverterOptions): {
10
+ <TProps extends BaseComponentProps>(elementName: string): ForeignComponent<TProps>;
11
+ Extension: string;
12
+ };
package/lib/converter.js CHANGED
@@ -1,30 +1,33 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createConverter = void 0;
4
- function createConverter() {
5
- const convert = (elementName) => {
6
- return {
7
- mount(parent, data, ctx) {
8
- const { piral } = data;
9
- const el = parent.appendChild(document.createElement(elementName));
4
+ const extension_1 = require("./extension");
5
+ function createConverter(config = {}) {
6
+ const { selector = 'litel-extension' } = config;
7
+ const Extension = (0, extension_1.createExtension)(selector);
8
+ const convert = (elementName) => ({
9
+ mount(parent, data, ctx) {
10
+ const { piral } = data;
11
+ const el = parent.appendChild(document.createElement(elementName));
12
+ el.setAttribute('props', JSON.stringify(data));
13
+ el.setAttribute('ctx', JSON.stringify(ctx));
14
+ el.shadowRoot.addEventListener('render-html', (ev) => {
15
+ ev.stopPropagation();
16
+ piral.renderHtmlExtension(ev.detail.target, ev.detail.props);
17
+ }, false);
18
+ },
19
+ update(parent, data, ctx) {
20
+ const el = parent.querySelector(elementName);
21
+ if (el) {
10
22
  el.setAttribute('props', JSON.stringify(data));
11
23
  el.setAttribute('ctx', JSON.stringify(ctx));
12
- el.shadowRoot.addEventListener('render-html', (ev) => {
13
- piral.renderHtmlExtension(ev.detail.target, ev.detail.props);
14
- }, false);
15
- },
16
- update(parent, data, ctx) {
17
- const el = parent.querySelector(elementName);
18
- if (el) {
19
- el.setAttribute('props', JSON.stringify(data));
20
- el.setAttribute('ctx', JSON.stringify(ctx));
21
- }
22
- },
23
- unmount(el) {
24
- el.innerHTML = '';
25
- },
26
- };
27
- };
24
+ }
25
+ },
26
+ unmount(el) {
27
+ el.innerHTML = '';
28
+ },
29
+ });
30
+ convert.Extension = Extension;
28
31
  return convert;
29
32
  }
30
33
  exports.createConverter = createConverter;
@@ -1 +1 @@
1
- {"version":3,"file":"converter.js","sourceRoot":"","sources":["../src/converter.ts"],"names":[],"mappings":";;;AAEA,SAAgB,eAAe;IAC7B,MAAM,OAAO,GAAG,CAAoC,WAAmB,EAA4B,EAAE;QACnG,OAAO;YACL,KAAK,CAAC,MAA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CAAC;QACpB,CAAC;KACF,CAAC,CAAC;IACH,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;IAC9B,OAAO,OAAO,CAAC;AACjB,CAAC;AAhCD,0CAgCC"}
package/lib/create.d.ts CHANGED
@@ -4,11 +4,6 @@ import type { PiletLitElApi } from './types';
4
4
  * Available configuration options for the LitElement plugin.
5
5
  */
6
6
  export interface LitElConfig {
7
- /**
8
- * Defines the name of the extension component.
9
- * @default litel-extension
10
- */
11
- selector?: string;
12
7
  }
13
8
  /**
14
9
  * Creates new Pilet API extensions for integration of LitElement.
package/lib/create.js CHANGED
@@ -2,16 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createLitElApi = void 0;
4
4
  const converter_1 = require("./converter");
5
- const extension_1 = require("./extension");
6
5
  /**
7
6
  * Creates new Pilet API extensions for integration of LitElement.
8
7
  */
9
8
  function createLitElApi(config = {}) {
10
- const { selector } = config;
11
9
  return (context) => {
12
- const convert = converter_1.createConverter();
10
+ const convert = (0, converter_1.createConverter)(config);
13
11
  context.converters.litel = ({ elementName }) => convert(elementName);
14
- extension_1.createExtension(selector);
15
12
  return {
16
13
  fromLitEl(elementName) {
17
14
  return {
@@ -19,7 +16,7 @@ function createLitElApi(config = {}) {
19
16
  elementName,
20
17
  };
21
18
  },
22
- LitElExtension: selector,
19
+ LitElExtension: convert.Extension,
23
20
  };
24
21
  };
25
22
  }
package/lib/create.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":";;;AACA,2CAA8C;AAC9C,2CAA8C;AAc9C;;GAEG;AACH,SAAgB,cAAc,CAAC,SAAsB,EAAE;IACrD,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC;IAE5B,OAAO,CAAC,OAAO,EAAE,EAAE;QACjB,MAAM,OAAO,GAAG,2BAAe,EAAE,CAAC;QAClC,OAAO,CAAC,UAAU,CAAC,KAAK,GAAG,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QAErE,2BAAe,CAAC,QAAQ,CAAC,CAAC;QAE1B,OAAO;YACL,SAAS,CAAC,WAAW;gBACnB,OAAO;oBACL,IAAI,EAAE,OAAO;oBACb,WAAW;iBACZ,CAAC;YACJ,CAAC;YACD,cAAc,EAAE,QAAQ;SACzB,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAnBD,wCAmBC"}
1
+ {"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":";;;AACA,2CAA8C;AAQ9C;;GAEG;AACH,SAAgB,cAAc,CAAC,SAAsB,EAAE;IACrD,OAAO,CAAC,OAAO,EAAE,EAAE;QACjB,MAAM,OAAO,GAAG,IAAA,2BAAe,EAAC,MAAM,CAAC,CAAC;QACxC,OAAO,CAAC,UAAU,CAAC,KAAK,GAAG,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QAErE,OAAO;YACL,SAAS,CAAC,WAAW;gBACnB,OAAO;oBACL,IAAI,EAAE,OAAO;oBACb,WAAW;iBACZ,CAAC;YACJ,CAAC;YACD,cAAc,EAAE,OAAO,CAAC,SAAS;SAClC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAfD,wCAeC"}
@@ -1 +1 @@
1
- export declare function createExtension(selector?: string): any;
1
+ export declare function createExtension(selector: string): string;
package/lib/extension.js CHANGED
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createExtension = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const lit_element_1 = require("lit-element");
6
- function createExtension(selector = 'litel-extension') {
6
+ function createExtension(selector) {
7
7
  let LitElExtension = class LitElExtension extends lit_element_1.LitElement {
8
8
  render() {
9
9
  return undefined;
@@ -24,25 +24,25 @@ function createExtension(selector = 'litel-extension') {
24
24
  }
25
25
  };
26
26
  tslib_1.__decorate([
27
- lit_element_1.property(),
27
+ (0, lit_element_1.property)(),
28
28
  tslib_1.__metadata("design:type", String)
29
29
  ], LitElExtension.prototype, "name", void 0);
30
30
  tslib_1.__decorate([
31
- lit_element_1.property(),
31
+ (0, lit_element_1.property)(),
32
32
  tslib_1.__metadata("design:type", Object)
33
33
  ], LitElExtension.prototype, "params", void 0);
34
34
  tslib_1.__decorate([
35
- lit_element_1.property(),
35
+ (0, lit_element_1.property)(),
36
36
  tslib_1.__metadata("design:type", Function)
37
37
  ], LitElExtension.prototype, "onEmpty", void 0);
38
38
  tslib_1.__decorate([
39
- lit_element_1.property(),
39
+ (0, lit_element_1.property)(),
40
40
  tslib_1.__metadata("design:type", Function)
41
41
  ], LitElExtension.prototype, "onRender", void 0);
42
42
  LitElExtension = tslib_1.__decorate([
43
- lit_element_1.customElement(selector)
43
+ (0, lit_element_1.customElement)(selector)
44
44
  ], LitElExtension);
45
- return LitElExtension;
45
+ return selector;
46
46
  }
47
47
  exports.createExtension = createExtension;
48
48
  //# sourceMappingURL=extension.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":";;;;AAAA,6CAAkE;AAElE,SAAgB,eAAe,CAAC,QAAQ,GAAG,iBAAiB;IAE1D,IAAM,cAAc,GAApB,MAAM,cAAe,SAAQ,wBAAU;QAMrC,MAAM;YACJ,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,OAAO;YACL,IAAI,CAAC,aAAa,CAChB,IAAI,WAAW,CAAC,aAAa,EAAE;gBAC7B,OAAO,EAAE,IAAI;gBACb,MAAM,EAAE;oBACN,MAAM,EAAE,IAAI,CAAC,UAAU;oBACvB,KAAK,EAAE;wBACL,KAAK,EAAE,IAAI,CAAC,OAAO;wBACnB,MAAM,EAAE,IAAI,CAAC,QAAQ;wBACrB,MAAM,EAAE,IAAI,CAAC,MAAM;wBACnB,IAAI,EAAE,IAAI,CAAC,IAAI;qBAChB;iBACF;a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2
2
  "name": "piral-litel",
3
- "version": "1.0.0-pre.2091",
3
+ "version": "1.0.0",
4
4
  "description": "Plugin for integrating Lit-Element components in Piral.",
5
5
  "keywords": [
6
6
  "piral",
@@ -17,14 +17,35 @@
17
17
  "author": "smapiot",
18
18
  "homepage": "https://piral.io",
19
19
  "license": "MIT",
20
+ "module": "esm/index.js",
20
21
  "main": "lib/index.js",
21
22
  "typings": "lib/index.d.ts",
23
+ "exports": {
24
+ ".": {
25
+ "import": "./esm/index.js",
26
+ "require": "./lib/index.js"
27
+ },
28
+ "./convert": {
29
+ "import": "./convert.js"
30
+ },
31
+ "./esm/*": {
32
+ "import": "./esm/*"
33
+ },
34
+ "./lib/*": {
35
+ "require": "./lib/*"
36
+ },
37
+ "./_/*": {
38
+ "import": "./esm/*.js",
39
+ "require": "./lib/*.js"
40
+ },
41
+ "./package.json": "./package.json"
42
+ },
22
43
  "sideEffects": false,
23
44
  "files": [
45
+ "esm",
24
46
  "lib",
25
47
  "src",
26
48
  "convert.d.ts",
27
- "convert.ts",
28
49
  "convert.js"
29
50
  ],
30
51
  "repository": {
@@ -35,17 +56,20 @@
35
56
  "url": "https://github.com/smapiot/piral/issues"
36
57
  },
37
58
  "scripts": {
38
- "build": "tsc && tsc convert.ts --skipLibCheck --declaration",
59
+ "cleanup": "rimraf esm lib convert.d.ts convert.js",
60
+ "build": "yarn build:commonjs && yarn build:esnext && yarn build:convert",
61
+ "build:convert": "tsc convert.ts --skipLibCheck --declaration --module esnext",
62
+ "build:commonjs": "tsc --project tsconfig.json --outDir lib --module commonjs",
63
+ "build:esnext": "tsc --project tsconfig.json --outDir esm --module esnext",
39
64
  "typedoc": "typedoc --json ../../../docs/types/piral-litel.json src --exclude \"src/**/*.test.*\"",
40
65
  "test": "echo \"Error: run tests from root\" && exit 1"
41
66
  },
42
67
  "devDependencies": {
43
68
  "lit-element": "^2.2.1",
44
- "piral-core": "^1.0.0-pre.2091"
69
+ "piral-core": "^1.0.0"
45
70
  },
46
71
  "peerDependencies": {
47
- "lit-element": "^2.0.0",
48
- "piral-core": "1.x"
72
+ "lit-element": "^2.0.0"
49
73
  },
50
- "gitHead": "e8c2565deac87446ebb9a376d5026a51bc6b5ff2"
74
+ "gitHead": "67d9a2920bd5231baf10bc87ae8985666b18fa3a"
51
75
  }
package/src/converter.ts CHANGED
@@ -1,33 +1,44 @@
1
- import { ForeignComponent, BaseComponentProps } from 'piral-core';
1
+ import type { ForeignComponent, BaseComponentProps } from 'piral-core';
2
+ import { createExtension } from './extension';
2
3
 
3
- export function createConverter() {
4
- const convert = <TProps extends BaseComponentProps>(elementName: string): ForeignComponent<TProps> => {
5
- return {
6
- mount(parent, data, ctx) {
7
- const { piral } = data;
8
- const el = parent.appendChild(document.createElement(elementName));
4
+ export interface LitElConverterOptions {
5
+ /**
6
+ * Defines the name of the extension component.
7
+ * @default litel-extension
8
+ */
9
+ selector?: string;
10
+ }
11
+
12
+ export function createConverter(config: LitElConverterOptions = {}) {
13
+ const { selector = 'litel-extension' } = config;
14
+ const Extension = createExtension(selector);
15
+ const convert = <TProps extends BaseComponentProps>(elementName: string): ForeignComponent<TProps> => ({
16
+ mount(parent, data, ctx) {
17
+ const { piral } = data;
18
+ const el = parent.appendChild(document.createElement(elementName));
19
+ el.setAttribute('props', JSON.stringify(data));
20
+ el.setAttribute('ctx', JSON.stringify(ctx));
21
+ el.shadowRoot.addEventListener(
22
+ 'render-html',
23
+ (ev: CustomEvent) => {
24
+ ev.stopPropagation();
25
+ piral.renderHtmlExtension(ev.detail.target, ev.detail.props);
26
+ },
27
+ false,
28
+ );
29
+ },
30
+ update(parent, data, ctx) {
31
+ const el = parent.querySelector(elementName);
32
+
33
+ if (el) {
9
34
  el.setAttribute('props', JSON.stringify(data));
10
35
  el.setAttribute('ctx', JSON.stringify(ctx));
11
- el.shadowRoot.addEventListener(
12
- 'render-html',
13
- (ev: CustomEvent) => {
14
- piral.renderHtmlExtension(ev.detail.target, ev.detail.props);
15
- },
16
- false,
17
- );
18
- },
19
- update(parent, data, ctx) {
20
- const el = parent.querySelector(elementName);
21
-
22
- if (el) {
23
- el.setAttribute('props', JSON.stringify(data));
24
- el.setAttribute('ctx', JSON.stringify(ctx));
25
- }
26
- },
27
- unmount(el) {
28
- el.innerHTML = '';
29
- },
30
- };
31
- };
36
+ }
37
+ },
38
+ unmount(el) {
39
+ el.innerHTML = '';
40
+ },
41
+ });
42
+ convert.Extension = Extension;
32
43
  return convert;
33
44
  }
package/src/create.ts CHANGED
@@ -1,31 +1,20 @@
1
1
  import type { PiralPlugin } from 'piral-core';
2
2
  import { createConverter } from './converter';
3
- import { createExtension } from './extension';
4
3
  import type { PiletLitElApi } from './types';
5
4
 
6
5
  /**
7
6
  * Available configuration options for the LitElement plugin.
8
7
  */
9
- export interface LitElConfig {
10
- /**
11
- * Defines the name of the extension component.
12
- * @default litel-extension
13
- */
14
- selector?: string;
15
- }
8
+ export interface LitElConfig {}
16
9
 
17
10
  /**
18
11
  * Creates new Pilet API extensions for integration of LitElement.
19
12
  */
20
13
  export function createLitElApi(config: LitElConfig = {}): PiralPlugin<PiletLitElApi> {
21
- const { selector } = config;
22
-
23
14
  return (context) => {
24
- const convert = createConverter();
15
+ const convert = createConverter(config);
25
16
  context.converters.litel = ({ elementName }) => convert(elementName);
26
17
 
27
- createExtension(selector);
28
-
29
18
  return {
30
19
  fromLitEl(elementName) {
31
20
  return {
@@ -33,7 +22,7 @@ export function createLitElApi(config: LitElConfig = {}): PiralPlugin<PiletLitEl
33
22
  elementName,
34
23
  };
35
24
  },
36
- LitElExtension: selector,
25
+ LitElExtension: convert.Extension,
37
26
  };
38
27
  };
39
28
  }
package/src/extension.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { LitElement, property, customElement } from 'lit-element';
2
2
 
3
- export function createExtension(selector = 'litel-extension'): any {
3
+ export function createExtension(selector: string) {
4
4
  @customElement(selector)
5
5
  class LitElExtension extends LitElement {
6
6
  @property() name: string;
@@ -30,5 +30,5 @@ export function createExtension(selector = 'litel-extension'): any {
30
30
  }
31
31
  }
32
32
 
33
- return LitElExtension;
33
+ return selector;
34
34
  }
package/convert.ts DELETED
@@ -1,16 +0,0 @@
1
- import type { HtmlComponent } from 'piral-core';
2
- import { createConverter } from './lib/converter';
3
- import { createExtension } from './lib/extension';
4
-
5
- const convert = createConverter();
6
-
7
- export interface LitElConverter {
8
- (...params: Parameters<typeof convert>): HtmlComponent<any>;
9
- }
10
-
11
- export const fromLitEl: LitElConverter = (elementName) => ({
12
- type: 'html',
13
- component: convert(elementName),
14
- });
15
-
16
- export const createLitElExtension = createExtension;