piral-elm 1.0.0-pre.2096 → 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 Elm](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-elm.svg?style=flat)](https://www.npmjs.com/package/piral-elm) [![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 Elm](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-elm.svg?style=flat)](https://www.npmjs.com/package/piral-elm) [![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-elm` 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 has no peer dependencies. What `piral-elm` 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 an Elm converter for any component registration, as well as a `fromElm` shortcut together with a `elm-extension` web component.
8
8
 
@@ -43,7 +43,7 @@ Alternatively, if `piral-elm` has not been added to the Piral instance you can i
43
43
 
44
44
  ```ts
45
45
  import { PiletApi } from '<name-of-piral-instance>';
46
- import { fromElm } from 'piral-elm';
46
+ import { fromElm } from 'piral-elm/convert';
47
47
  import Elm from './Page.elm';
48
48
 
49
49
  export function setup(piral: PiletApi) {
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>(main: import("./lib/types").ElmModule<TProps>, captured?: Record<string, any>) => 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 ElmConverter {
5
- (...params: Parameters<typeof convert>): HtmlComponent<any>;
11
+ (...params: Parameters<ReturnType<typeof createConverter>>): HtmlComponent<any>;
6
12
  }
7
- export declare const fromElm: ElmConverter;
8
- export declare const createElmExtension: typeof createExtension;
9
- export {};
13
+ export declare function createElmConverter(...params: Parameters<typeof createConverter>): {
14
+ from: ElmConverter;
15
+ Extension: string;
16
+ };
17
+ declare const fromElm: ElmConverter, ElmExtension: string;
18
+ export { fromElm, ElmExtension };
package/convert.js CHANGED
@@ -1,11 +1,16 @@
1
- "use strict";
2
- exports.__esModule = true;
3
- exports.createElmExtension = exports.fromElm = void 0;
4
- var converter_1 = require("./lib/converter");
5
- var extension_1 = require("./lib/extension");
6
- var convert = converter_1.createConverter();
7
- exports.fromElm = function (main, captured) { return ({
8
- type: 'html',
9
- component: convert(main, captured)
10
- }); };
11
- exports.createElmExtension = extension_1.createExtension;
1
+ import { createConverter } from './esm/converter';
2
+ export function createElmConverter() {
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 (main, captured) { return ({
10
+ type: 'html',
11
+ component: convert(main, captured),
12
+ }); };
13
+ return { from: from, Extension: Extension };
14
+ }
15
+ var _a = createElmConverter(), fromElm = _a.from, ElmExtension = _a.Extension;
16
+ export { fromElm, ElmExtension };
@@ -0,0 +1,13 @@
1
+ import type { ForeignComponent, BaseComponentProps } from 'piral-core';
2
+ import type { ElmModule } from './types';
3
+ export interface ElmConverterOptions {
4
+ /**
5
+ * Defines the name of the extension component.
6
+ * @default elm-extension
7
+ */
8
+ selector?: string;
9
+ }
10
+ export declare function createConverter(config?: ElmConverterOptions): {
11
+ <TProps extends BaseComponentProps>(main: ElmModule<TProps>, captured?: Record<string, any>): ForeignComponent<TProps>;
12
+ Extension: string;
13
+ };
@@ -0,0 +1,20 @@
1
+ import { createExtension } from './extension';
2
+ export function createConverter(config = {}) {
3
+ const { selector = 'elm-extension' } = config;
4
+ const Extension = createExtension(selector);
5
+ const convert = (main, captured) => ({
6
+ mount(el, props, ctx) {
7
+ const node = el.appendChild(document.createElement('div'));
8
+ main.init({
9
+ node,
10
+ flags: Object.assign(Object.assign(Object.assign({}, captured), ctx), props),
11
+ });
12
+ },
13
+ unmount(el) {
14
+ el.innerHTML = '';
15
+ },
16
+ });
17
+ convert.Extension = Extension;
18
+ return convert;
19
+ }
20
+ //# 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;AAW9C,MAAM,UAAU,eAAe,CAAC,SAA8B,EAAE;IAC9D,MAAM,EAAE,QAAQ,GAAG,eAAe,EAAE,GAAG,MAAM,CAAC;IAC9C,MAAM,SAAS,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC;IAC5C,MAAM,OAAO,GAAG,CACd,IAAuB,EACvB,QAA8B,EACJ,EAAE,CAAC,CAAC;QAC9B,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,GAAG;YAClB,MAAM,IAAI,GAAG,EAAE,CAAC,WAAW,CAAC,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC;YAC3D,IAAI,CAAC,IAAI,CAAC;gBACR,IAAI;gBACJ,KAAK,gDACA,QAAQ,GACR,GAAG,GACH,KAAK,CACT;aACF,CAAC,CAAC;QACL,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,12 @@
1
+ import type { PiralPlugin } from 'piral-core';
2
+ import { ElmConverterOptions } from './converter';
3
+ import type { PiletElmApi } from './types';
4
+ /**
5
+ * Available configuration options for the Elm plugin.
6
+ */
7
+ export interface ElmConfig extends ElmConverterOptions {
8
+ }
9
+ /**
10
+ * Creates new Pilet API extensions for integration of Elm.
11
+ */
12
+ export declare function createElmApi(config?: ElmConfig): PiralPlugin<PiletElmApi>;
package/esm/create.js ADDED
@@ -0,0 +1,21 @@
1
+ import { createConverter } from './converter';
2
+ /**
3
+ * Creates new Pilet API extensions for integration of Elm.
4
+ */
5
+ export function createElmApi(config = {}) {
6
+ return (context) => {
7
+ const convert = createConverter(config);
8
+ context.converters.elm = ({ main, captured }) => convert(main, captured);
9
+ return {
10
+ fromElm(main, captured) {
11
+ return {
12
+ type: 'elm',
13
+ captured,
14
+ main,
15
+ };
16
+ },
17
+ ElmExtension: convert.Extension,
18
+ };
19
+ };
20
+ }
21
+ //# sourceMappingURL=create.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAuB,MAAM,aAAa,CAAC;AAQnE;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,SAAoB,EAAE;IACjD,OAAO,CAAC,OAAO,EAAE,EAAE;QACjB,MAAM,OAAO,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;QACxC,OAAO,CAAC,UAAU,CAAC,GAAG,GAAG,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QAEzE,OAAO;YACL,OAAO,CAAC,IAAI,EAAE,QAAQ;gBACpB,OAAO;oBACL,IAAI,EAAE,KAAK;oBACX,QAAQ;oBACR,IAAI;iBACL,CAAC;YACJ,CAAC;YACD,YAAY,EAAE,OAAO,CAAC,SAAS;SAChC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1 @@
1
+ export declare function createExtension(selector: string): string;
@@ -0,0 +1,11 @@
1
+ export function createExtension(selector) {
2
+ const defaultExtensionSelector = 'piral-extension';
3
+ if ('customElements' in window && selector && selector !== defaultExtensionSelector) {
4
+ const ExtensionBase = customElements.get(defaultExtensionSelector);
5
+ class AliasExtension extends ExtensionBase {
6
+ }
7
+ customElements.define(selector, AliasExtension);
8
+ }
9
+ return selector || defaultExtensionSelector;
10
+ }
11
+ //# sourceMappingURL=extension.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,eAAe,CAAC,QAAgB;IAC9C,MAAM,wBAAwB,GAAG,iBAAiB,CAAC;IAEnD,IAAI,gBAAgB,IAAI,MAAM,IAAI,QAAQ,IAAI,QAAQ,KAAK,wBAAwB,EAAE;QACnF,MAAM,aAAa,GAAG,cAAc,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;QACnE,MAAM,cAAe,SAAQ,aAAa;SAAG;QAC7C,cAAc,CAAC,MAAM,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;KACjD;IAED,OAAO,QAAQ,IAAI,wBAAwB,CAAC;AAC9C,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,44 @@
1
+ import type { ForeignComponent } from 'piral-core';
2
+ declare module 'piral-core/lib/types/custom' {
3
+ interface PiletCustomApi extends PiletElmApi {
4
+ }
5
+ interface PiralCustomComponentConverters<TProps> {
6
+ elm(component: ElmComponent<TProps>): ForeignComponent<TProps>;
7
+ }
8
+ }
9
+ export interface ElmModule<TProps> {
10
+ init(opts: {
11
+ node: Element;
12
+ flags?: TProps;
13
+ }): void;
14
+ }
15
+ export interface ElmComponent<TProps> {
16
+ /**
17
+ * The name of the Elm main module to render.
18
+ */
19
+ main: ElmModule<TProps>;
20
+ /**
21
+ * Captures props for transport into the Elm component.
22
+ */
23
+ captured?: Record<string, any>;
24
+ /**
25
+ * The type of the Elm component.
26
+ */
27
+ type: 'elm';
28
+ }
29
+ /**
30
+ * Defines the provided set of Elm Pilet API extensions.
31
+ */
32
+ export interface PiletElmApi {
33
+ /**
34
+ * Wraps a Elm module for use in Piral.
35
+ * @param main The name of the root component.
36
+ * @param captured The optionally captured props.
37
+ * @returns The Piral Elm component.
38
+ */
39
+ fromElm<TProps>(main: ElmModule<TProps>, captured?: Record<string, any>): ElmComponent<TProps>;
40
+ /**
41
+ * Gets the name of the Elm extension.
42
+ */
43
+ ElmExtension: string;
44
+ }
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,3 +1,13 @@
1
- import { ForeignComponent, BaseComponentProps } from 'piral-core';
2
- import { ElmModule } from './types';
3
- export declare function createConverter(): <TProps extends BaseComponentProps>(main: ElmModule<TProps>, captured?: Record<string, any>) => ForeignComponent<TProps>;
1
+ import type { ForeignComponent, BaseComponentProps } from 'piral-core';
2
+ import type { ElmModule } from './types';
3
+ export interface ElmConverterOptions {
4
+ /**
5
+ * Defines the name of the extension component.
6
+ * @default elm-extension
7
+ */
8
+ selector?: string;
9
+ }
10
+ export declare function createConverter(config?: ElmConverterOptions): {
11
+ <TProps extends BaseComponentProps>(main: ElmModule<TProps>, captured?: Record<string, any>): ForeignComponent<TProps>;
12
+ Extension: string;
13
+ };
package/lib/converter.js CHANGED
@@ -1,26 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createConverter = void 0;
4
- var tslib_1 = require("tslib");
5
- function createConverter() {
6
- var convert = function (main, captured) {
7
- return {
8
- mount: function (parent, data, ctx) {
9
- var node = parent.appendChild(document.createElement('div'));
10
- parent.addEventListener('render-html', function (ev) {
11
- var piral = data.piral;
12
- piral.renderHtmlExtension(ev.detail.target, ev.detail.props);
13
- }, false);
14
- main.init({
15
- node: node,
16
- flags: tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, captured), ctx), data),
17
- });
18
- },
19
- unmount: function (el) {
20
- el.innerHTML = '';
21
- },
22
- };
23
- };
4
+ const extension_1 = require("./extension");
5
+ function createConverter(config = {}) {
6
+ const { selector = 'elm-extension' } = config;
7
+ const Extension = (0, extension_1.createExtension)(selector);
8
+ const convert = (main, captured) => ({
9
+ mount(el, props, ctx) {
10
+ const node = el.appendChild(document.createElement('div'));
11
+ main.init({
12
+ node,
13
+ flags: Object.assign(Object.assign(Object.assign({}, captured), ctx), props),
14
+ });
15
+ },
16
+ unmount(el) {
17
+ el.innerHTML = '';
18
+ },
19
+ });
20
+ convert.Extension = Extension;
24
21
  return convert;
25
22
  }
26
23
  exports.createConverter = createConverter;
@@ -1 +1 @@
1
- {"version":3,"file":"converter.js","sourceRoot":"","sources":["../src/converter.ts"],"names":[],"mappings":";;;;AAGA,SAAgB,eAAe;IAC7B,IAAM,OAAO,GAAG,UACd,IAAuB,EACvB,QAA8B;QAE9B,OAAO;YACL,KAAK,EAAL,UAAM,MAAM,EAAE,IAAI,EAAE,GAAG;gBACrB,IAAM,IAAI,GAAG,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC;gBAC/D,MAAM,CAAC,gBAAgB,CACrB,aAAa,EACb,UAAC,EAAe;oBACN,IAAA,KAAK,GAAK,IAAI,MAAT,CAAU;oBACvB,KAAK,CAAC,mBAAmB,CAAC,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBAC/D,CAAC,EACD,KAAK,CACN,CAAC;gBACF,IAAI,CAAC,IAAI,CAAC;oBACR,IAAI,MAAA;oBACJ,KAAK,yDACA,QAAQ,GACR,GAAG,GACH,IAAI,CACR;iBACF,CAAC,CAAC;YACL,CAAC;YACD,OAAO,YAAC,EAAE;gBACR,EAAE,CAAC,SAAS,GAAG,EAAE,CAAC;YACpB,CAAC;SACF,CAAC;IACJ,CAAC,CAAC;IACF,OAAO,OAAO,CAAC;AACjB,CAAC;AA/BD,0CA+BC"}
1
+ {"version":3,"file":"converter.js","sourceRoot":"","sources":["../src/converter.ts"],"names":[],"mappings":";;;AACA,2CAA8C;AAW9C,SAAgB,eAAe,CAAC,SAA8B,EAAE;IAC9D,MAAM,EAAE,QAAQ,GAAG,eAAe,EAAE,GAAG,MAAM,CAAC;IAC9C,MAAM,SAAS,GAAG,IAAA,2BAAe,EAAC,QAAQ,CAAC,CAAC;IAC5C,MAAM,OAAO,GAAG,CACd,IAAuB,EACvB,QAA8B,EACJ,EAAE,CAAC,CAAC;QAC9B,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,GAAG;YAClB,MAAM,IAAI,GAAG,EAAE,CAAC,WAAW,CAAC,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC;YAC3D,IAAI,CAAC,IAAI,CAAC;gBACR,IAAI;gBACJ,KAAK,gDACA,QAAQ,GACR,GAAG,GACH,KAAK,CACT;aACF,CAAC,CAAC;QACL,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;AAxBD,0CAwBC"}
package/lib/create.d.ts CHANGED
@@ -1,14 +1,10 @@
1
1
  import type { PiralPlugin } from 'piral-core';
2
+ import { ElmConverterOptions } from './converter';
2
3
  import type { PiletElmApi } from './types';
3
4
  /**
4
5
  * Available configuration options for the Elm plugin.
5
6
  */
6
- export interface ElmConfig {
7
- /**
8
- * Defines the name of the extension component.
9
- * @default elm-extension
10
- */
11
- selector?: string;
7
+ export interface ElmConfig extends ElmConverterOptions {
12
8
  }
13
9
  /**
14
10
  * Creates new Pilet API extensions for integration of Elm.
package/lib/create.js CHANGED
@@ -1,30 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createElmApi = void 0;
4
- var converter_1 = require("./converter");
5
- var extension_1 = require("./extension");
4
+ const converter_1 = require("./converter");
6
5
  /**
7
6
  * Creates new Pilet API extensions for integration of Elm.
8
7
  */
9
- function createElmApi(config) {
10
- if (config === void 0) { config = {}; }
11
- var selector = config.selector;
12
- return function (context) {
13
- var convert = converter_1.createConverter();
14
- context.converters.elm = function (_a) {
15
- var main = _a.main, captured = _a.captured;
16
- return convert(main, captured);
17
- };
18
- extension_1.createExtension(selector);
8
+ function createElmApi(config = {}) {
9
+ return (context) => {
10
+ const convert = (0, converter_1.createConverter)(config);
11
+ context.converters.elm = ({ main, captured }) => convert(main, captured);
19
12
  return {
20
- fromElm: function (main, captured) {
13
+ fromElm(main, captured) {
21
14
  return {
22
15
  type: 'elm',
23
- captured: captured,
24
- main: main,
16
+ captured,
17
+ main,
25
18
  };
26
19
  },
27
- ElmExtension: selector,
20
+ ElmExtension: convert.Extension,
28
21
  };
29
22
  };
30
23
  }
package/lib/create.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":";;;AACA,yCAA8C;AAC9C,yCAA8C;AAc9C;;GAEG;AACH,SAAgB,YAAY,CAAC,MAAsB;IAAtB,uBAAA,EAAA,WAAsB;IACzC,IAAA,QAAQ,GAAK,MAAM,SAAX,CAAY;IAE5B,OAAO,UAAC,OAAO;QACb,IAAM,OAAO,GAAG,2BAAe,EAAE,CAAC;QAClC,OAAO,CAAC,UAAU,CAAC,GAAG,GAAG,UAAC,EAAkB;gBAAhB,IAAI,UAAA,EAAE,QAAQ,cAAA;YAAO,OAAA,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC;QAAvB,CAAuB,CAAC;QAEzE,2BAAe,CAAC,QAAQ,CAAC,CAAC;QAE1B,OAAO;YACL,OAAO,YAAC,IAAI,EAAE,QAAQ;gBACpB,OAAO;oBACL,IAAI,EAAE,KAAK;oBACX,QAAQ,UAAA;oBACR,IAAI,MAAA;iBACL,CAAC;YACJ,CAAC;YACD,YAAY,EAAE,QAAQ;SACvB,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AApBD,oCAoBC"}
1
+ {"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":";;;AACA,2CAAmE;AAQnE;;GAEG;AACH,SAAgB,YAAY,CAAC,SAAoB,EAAE;IACjD,OAAO,CAAC,OAAO,EAAE,EAAE;QACjB,MAAM,OAAO,GAAG,IAAA,2BAAe,EAAC,MAAM,CAAC,CAAC;QACxC,OAAO,CAAC,UAAU,CAAC,GAAG,GAAG,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QAEzE,OAAO;YACL,OAAO,CAAC,IAAI,EAAE,QAAQ;gBACpB,OAAO;oBACL,IAAI,EAAE,KAAK;oBACX,QAAQ;oBACR,IAAI;iBACL,CAAC;YACJ,CAAC;YACD,YAAY,EAAE,OAAO,CAAC,SAAS;SAChC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAhBD,oCAgBC"}
@@ -1 +1 @@
1
- export declare function createExtension(selector?: string): void;
1
+ export declare function createExtension(selector: string): string;
package/lib/extension.js CHANGED
@@ -1,32 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createExtension = void 0;
4
- var tslib_1 = require("tslib");
5
4
  function createExtension(selector) {
6
- if (selector === void 0) { selector = 'elm-extension'; }
7
- if ('customElements' in window) {
8
- var ElmExtension = /** @class */ (function (_super) {
9
- tslib_1.__extends(ElmExtension, _super);
10
- function ElmExtension() {
11
- return _super !== null && _super.apply(this, arguments) || this;
12
- }
13
- ElmExtension.prototype.connectedCallback = function () {
14
- if (this.isConnected) {
15
- this.dispatchEvent(new CustomEvent('render-html', {
16
- bubbles: true,
17
- detail: {
18
- target: this,
19
- props: {
20
- name: this.getAttribute('name'),
21
- },
22
- },
23
- }));
24
- }
25
- };
26
- return ElmExtension;
27
- }(HTMLElement));
28
- customElements.define(selector, ElmExtension);
5
+ const defaultExtensionSelector = 'piral-extension';
6
+ if ('customElements' in window && selector && selector !== defaultExtensionSelector) {
7
+ const ExtensionBase = customElements.get(defaultExtensionSelector);
8
+ class AliasExtension extends ExtensionBase {
9
+ }
10
+ customElements.define(selector, AliasExtension);
29
11
  }
12
+ return selector || defaultExtensionSelector;
30
13
  }
31
14
  exports.createExtension = createExtension;
32
15
  //# sourceMappingURL=extension.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":";;;;AAAA,SAAgB,eAAe,CAAC,QAA0B;IAA1B,yBAAA,EAAA,0BAA0B;IACxD,IAAI,gBAAgB,IAAI,MAAM,EAAE;QAC9B;YAA2B,wCAAW;YAAtC;;YAgBA,CAAC;YAfC,wCAAiB,GAAjB;gBACE,IAAI,IAAI,CAAC,WAAW,EAAE;oBACpB,IAAI,CAAC,aAAa,CAChB,IAAI,WAAW,CAAC,aAAa,EAAE;wBAC7B,OAAO,EAAE,IAAI;wBACb,MAAM,EAAE;4BACN,MAAM,EAAE,IAAI;4BACZ,KAAK,EAAE;gCACL,IAAI,EAAE,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC;6BAChC;yBACF;qBACF,CAAC,CACH,CAAC;iBACH;YACH,CAAC;YACH,mBAAC;QAAD,CAAC,AAhBD,CAA2B,WAAW,GAgBrC;QAED,cAAc,CAAC,MAAM,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;KAC/C;AACH,CAAC;AAtBD,0CAsBC"}
1
+ {"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":";;;AAAA,SAAgB,eAAe,CAAC,QAAgB;IAC9C,MAAM,wBAAwB,GAAG,iBAAiB,CAAC;IAEnD,IAAI,gBAAgB,IAAI,MAAM,IAAI,QAAQ,IAAI,QAAQ,KAAK,wBAAwB,EAAE;QACnF,MAAM,aAAa,GAAG,cAAc,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;QACnE,MAAM,cAAe,SAAQ,aAAa;SAAG;QAC7C,cAAc,CAAC,MAAM,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;KACjD;IAED,OAAO,QAAQ,IAAI,wBAAwB,CAAC;AAC9C,CAAC;AAVD,0CAUC"}
package/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var tslib_1 = require("tslib");
3
+ const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./create"), exports);
5
5
  tslib_1.__exportStar(require("./types"), exports);
6
6
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "piral-elm",
3
- "version": "1.0.0-pre.2096",
3
+ "version": "1.0.0",
4
4
  "description": "Plugin for integrating Elm components in Piral.",
5
5
  "keywords": [
6
6
  "piral",
@@ -16,14 +16,35 @@
16
16
  "author": "smapiot",
17
17
  "homepage": "https://piral.io",
18
18
  "license": "MIT",
19
+ "module": "esm/index.js",
19
20
  "main": "lib/index.js",
20
21
  "typings": "lib/index.d.ts",
22
+ "exports": {
23
+ ".": {
24
+ "import": "./esm/index.js",
25
+ "require": "./lib/index.js"
26
+ },
27
+ "./convert": {
28
+ "import": "./convert.js"
29
+ },
30
+ "./esm/*": {
31
+ "import": "./esm/*"
32
+ },
33
+ "./lib/*": {
34
+ "require": "./lib/*"
35
+ },
36
+ "./_/*": {
37
+ "import": "./esm/*.js",
38
+ "require": "./lib/*.js"
39
+ },
40
+ "./package.json": "./package.json"
41
+ },
21
42
  "sideEffects": false,
22
43
  "files": [
44
+ "esm",
23
45
  "lib",
24
46
  "src",
25
47
  "convert.d.ts",
26
- "convert.ts",
27
48
  "convert.js"
28
49
  ],
29
50
  "repository": {
@@ -34,15 +55,16 @@
34
55
  "url": "https://github.com/smapiot/piral/issues"
35
56
  },
36
57
  "scripts": {
37
- "build": "tsc && tsc convert.ts --skipLibCheck --declaration",
58
+ "cleanup": "rimraf esm lib convert.d.ts convert.js",
59
+ "build": "yarn build:commonjs && yarn build:esnext && yarn build:convert",
60
+ "build:convert": "tsc convert.ts --skipLibCheck --declaration --module esnext",
61
+ "build:commonjs": "tsc --project tsconfig.json --outDir lib --module commonjs",
62
+ "build:esnext": "tsc --project tsconfig.json --outDir esm --module esnext",
38
63
  "typedoc": "typedoc --json ../../../docs/types/piral-elm.json src --exclude \"src/**/*.test.*\"",
39
64
  "test": "echo \"Error: run tests from root\" && exit 1"
40
65
  },
41
66
  "devDependencies": {
42
- "piral-core": "^1.0.0-pre.2096"
43
- },
44
- "peerDependencies": {
45
- "piral-core": "1.x"
67
+ "piral-core": "^1.0.0"
46
68
  },
47
- "gitHead": "9ac3626cc85b5937a50e039debd32c2697b49242"
69
+ "gitHead": "67d9a2920bd5231baf10bc87ae8985666b18fa3a"
48
70
  }
package/src/converter.ts CHANGED
@@ -1,35 +1,37 @@
1
- import { ForeignComponent, BaseComponentProps } from 'piral-core';
2
- import { ElmModule } from './types';
1
+ import type { ForeignComponent, BaseComponentProps } from 'piral-core';
2
+ import { createExtension } from './extension';
3
+ import type { ElmModule } from './types';
3
4
 
4
- export function createConverter() {
5
+ export interface ElmConverterOptions {
6
+ /**
7
+ * Defines the name of the extension component.
8
+ * @default elm-extension
9
+ */
10
+ selector?: string;
11
+ }
12
+
13
+ export function createConverter(config: ElmConverterOptions = {}) {
14
+ const { selector = 'elm-extension' } = config;
15
+ const Extension = createExtension(selector);
5
16
  const convert = <TProps extends BaseComponentProps>(
6
17
  main: ElmModule<TProps>,
7
18
  captured?: Record<string, any>,
8
- ): ForeignComponent<TProps> => {
9
- return {
10
- mount(parent, data, ctx) {
11
- const node = parent.appendChild(document.createElement('div'));
12
- parent.addEventListener(
13
- 'render-html',
14
- (ev: CustomEvent) => {
15
- const { piral } = data;
16
- piral.renderHtmlExtension(ev.detail.target, ev.detail.props);
17
- },
18
- false,
19
- );
20
- main.init({
21
- node,
22
- flags: {
23
- ...captured,
24
- ...ctx,
25
- ...data,
26
- },
27
- });
28
- },
29
- unmount(el) {
30
- el.innerHTML = '';
31
- },
32
- };
33
- };
19
+ ): ForeignComponent<TProps> => ({
20
+ mount(el, props, ctx) {
21
+ const node = el.appendChild(document.createElement('div'));
22
+ main.init({
23
+ node,
24
+ flags: {
25
+ ...captured,
26
+ ...ctx,
27
+ ...props,
28
+ },
29
+ });
30
+ },
31
+ unmount(el) {
32
+ el.innerHTML = '';
33
+ },
34
+ });
35
+ convert.Extension = Extension;
34
36
  return convert;
35
37
  }
package/src/create.ts CHANGED
@@ -1,31 +1,20 @@
1
1
  import type { PiralPlugin } from 'piral-core';
2
- import { createConverter } from './converter';
3
- import { createExtension } from './extension';
2
+ import { createConverter, ElmConverterOptions } from './converter';
4
3
  import type { PiletElmApi } from './types';
5
4
 
6
5
  /**
7
6
  * Available configuration options for the Elm plugin.
8
7
  */
9
- export interface ElmConfig {
10
- /**
11
- * Defines the name of the extension component.
12
- * @default elm-extension
13
- */
14
- selector?: string;
15
- }
8
+ export interface ElmConfig extends ElmConverterOptions {}
16
9
 
17
10
  /**
18
11
  * Creates new Pilet API extensions for integration of Elm.
19
12
  */
20
13
  export function createElmApi(config: ElmConfig = {}): PiralPlugin<PiletElmApi> {
21
- const { selector } = config;
22
-
23
14
  return (context) => {
24
- const convert = createConverter();
15
+ const convert = createConverter(config);
25
16
  context.converters.elm = ({ main, captured }) => convert(main, captured);
26
17
 
27
- createExtension(selector);
28
-
29
18
  return {
30
19
  fromElm(main, captured) {
31
20
  return {
@@ -34,7 +23,7 @@ export function createElmApi(config: ElmConfig = {}): PiralPlugin<PiletElmApi> {
34
23
  main,
35
24
  };
36
25
  },
37
- ElmExtension: selector,
26
+ ElmExtension: convert.Extension,
38
27
  };
39
28
  };
40
29
  }
package/src/extension.ts CHANGED
@@ -1,23 +1,11 @@
1
- export function createExtension(selector = 'elm-extension') {
2
- if ('customElements' in window) {
3
- class ElmExtension extends HTMLElement {
4
- connectedCallback() {
5
- if (this.isConnected) {
6
- this.dispatchEvent(
7
- new CustomEvent('render-html', {
8
- bubbles: true,
9
- detail: {
10
- target: this,
11
- props: {
12
- name: this.getAttribute('name'),
13
- },
14
- },
15
- }),
16
- );
17
- }
18
- }
19
- }
1
+ export function createExtension(selector: string) {
2
+ const defaultExtensionSelector = 'piral-extension';
20
3
 
21
- customElements.define(selector, ElmExtension);
4
+ if ('customElements' in window && selector && selector !== defaultExtensionSelector) {
5
+ const ExtensionBase = customElements.get(defaultExtensionSelector);
6
+ class AliasExtension extends ExtensionBase {}
7
+ customElements.define(selector, AliasExtension);
22
8
  }
9
+
10
+ return selector || defaultExtensionSelector;
23
11
  }
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 ElmConverter {
8
- (...params: Parameters<typeof convert>): HtmlComponent<any>;
9
- }
10
-
11
- export const fromElm: ElmConverter = (main, captured) => ({
12
- type: 'html',
13
- component: convert(main, captured),
14
- });
15
-
16
- export const createElmExtension = createExtension;