piral-litel 1.0.0-pre.2091 → 1.0.1-beta.5640
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 +1 -1
- package/README.md +10 -11
- package/convert.d.ts +16 -7
- package/convert.js +16 -11
- package/esm/converter.d.ts +12 -0
- package/esm/converter.js +30 -0
- package/esm/converter.js.map +1 -0
- package/esm/create.d.ts +11 -0
- package/esm/create.js +20 -0
- package/esm/create.js.map +1 -0
- package/esm/extension.d.ts +1 -0
- package/esm/extension.js +44 -0
- package/esm/extension.js.map +1 -0
- package/esm/index.d.ts +2 -0
- package/esm/index.js +3 -0
- package/esm/index.js.map +1 -0
- package/esm/types.d.ts +33 -0
- package/esm/types.js +2 -0
- package/esm/types.js.map +1 -0
- package/lib/converter.d.ts +12 -2
- package/lib/converter.js +25 -22
- package/lib/converter.js.map +1 -1
- package/lib/create.d.ts +0 -5
- package/lib/create.js +2 -5
- package/lib/create.js.map +1 -1
- package/lib/extension.d.ts +1 -1
- package/lib/extension.js +7 -7
- package/lib/extension.js.map +1 -1
- package/package.json +30 -9
- package/src/converter.ts +39 -28
- package/src/create.ts +3 -14
- package/src/extension.ts +2 -2
- package/convert.ts +0 -16
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
[](https://piral.io)
|
|
2
2
|
|
|
3
|
-
# [Piral LitEl](https://piral.io) · [](https://github.com/smapiot/piral/blob/
|
|
3
|
+
# [Piral LitEl](https://piral.io) · [](https://github.com/smapiot/piral/blob/main/LICENSE) [](https://www.npmjs.com/package/piral-litel) [](https://jestjs.io) [](https://gitter.im/piral-io/community)
|
|
4
4
|
|
|
5
|
-
This is a plugin that only has a peer dependency to `
|
|
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) {
|
|
@@ -59,10 +59,9 @@ export function setup(piral: PiletApi) {
|
|
|
59
59
|
|
|
60
60
|
::: summary: For Piral instance developers
|
|
61
61
|
|
|
62
|
-
Using LitElement with Piral is as simple as installing `piral-litel` and `lit-element`.
|
|
62
|
+
Using LitElement with Piral is as simple as installing `piral-litel` and `lit-element@^2`.
|
|
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
|
-
"
|
|
84
|
-
"
|
|
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
|
|
2
|
-
|
|
3
|
-
|
|
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
|
|
11
|
+
(...params: Parameters<ReturnType<typeof createConverter>>): HtmlComponent<any>;
|
|
6
12
|
}
|
|
7
|
-
export declare
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
+
};
|
package/esm/converter.js
ADDED
|
@@ -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"}
|
package/esm/create.d.ts
ADDED
|
@@ -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;
|
package/esm/extension.js
ADDED
|
@@ -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
package/esm/index.js
ADDED
package/esm/index.js.map
ADDED
|
@@ -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
package/esm/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/lib/converter.d.ts
CHANGED
|
@@ -1,2 +1,12 @@
|
|
|
1
|
-
import { ForeignComponent, BaseComponentProps } from 'piral-core';
|
|
2
|
-
export
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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;
|
package/lib/converter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"converter.js","sourceRoot":"","sources":["../src/converter.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"converter.js","sourceRoot":"","sources":["../src/converter.ts"],"names":[],"mappings":";;;AACA,2CAA8C;AAU9C,SAAgB,eAAe,CAAC,SAAgC,EAAE;IAChE,MAAM,EAAE,QAAQ,GAAG,iBAAiB,EAAE,GAAG,MAAM,CAAC;IAChD,MAAM,SAAS,GAAG,IAAA,2BAAe,EAAC,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;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:
|
|
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;
|
|
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"}
|
package/lib/extension.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function createExtension(selector
|
|
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
|
|
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
|
|
45
|
+
return selector;
|
|
46
46
|
}
|
|
47
47
|
exports.createExtension = createExtension;
|
|
48
48
|
//# sourceMappingURL=extension.js.map
|
package/lib/extension.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":";;;;AAAA,6CAAkE;AAElE,SAAgB,eAAe,CAAC,
|
|
1
|
+
{"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":";;;;AAAA,6CAAkE;AAElE,SAAgB,eAAe,CAAC,QAAgB;IAE9C,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;aACF,CAAC,CACH,CAAC;QACJ,CAAC;KACF,CAAA;IAzBa;QAAX,IAAA,sBAAQ,GAAE;;gDAAc;IACb;QAAX,IAAA,sBAAQ,GAAE;;kDAAa;IACZ;QAAX,IAAA,sBAAQ,GAAE;;mDAAoB;IACnB;QAAX,IAAA,sBAAQ,GAAE;;oDAAqB;IAJ5B,cAAc;QADnB,IAAA,2BAAa,EAAC,QAAQ,CAAC;OAClB,cAAc,CA0BnB;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC;AA/BD,0CA+BC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "piral-litel",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1-beta.5640",
|
|
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,17 @@
|
|
|
35
56
|
"url": "https://github.com/smapiot/piral/issues"
|
|
36
57
|
},
|
|
37
58
|
"scripts": {
|
|
38
|
-
"
|
|
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": "
|
|
45
|
-
},
|
|
46
|
-
"peerDependencies": {
|
|
47
|
-
"lit-element": "^2.0.0",
|
|
48
|
-
"piral-core": "1.x"
|
|
69
|
+
"piral-core": "1.0.1-beta.5640"
|
|
49
70
|
},
|
|
50
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "fa0a72b28fd0a20afec7ef491ec19e93c090fc72"
|
|
51
72
|
}
|
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
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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:
|
|
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
|
|
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
|
|
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;
|