piral-elm 1.0.0-pre.2033 → 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 +1 -1
- package/README.md +4 -4
- package/convert.d.ts +16 -7
- package/convert.js +16 -11
- package/esm/converter.d.ts +13 -0
- package/esm/converter.js +20 -0
- package/esm/converter.js.map +1 -0
- package/esm/create.d.ts +12 -0
- package/esm/create.js +21 -0
- package/esm/create.js.map +1 -0
- package/esm/extension.d.ts +1 -0
- package/esm/extension.js +11 -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 +44 -0
- package/esm/types.js +2 -0
- package/esm/types.js.map +1 -0
- package/lib/converter.d.ts +13 -3
- package/lib/converter.js +17 -20
- package/lib/converter.js.map +1 -1
- package/lib/create.d.ts +2 -6
- package/lib/create.js +9 -16
- package/lib/create.js.map +1 -1
- package/lib/extension.d.ts +1 -1
- package/lib/extension.js +7 -24
- package/lib/extension.js.map +1 -1
- package/lib/index.js +1 -1
- package/package.json +30 -8
- package/src/converter.ts +31 -29
- package/src/create.ts +4 -15
- package/src/extension.ts +8 -20
- package/convert.ts +0 -16
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
[](https://piral.io)
|
|
2
2
|
|
|
3
|
-
# [Piral Elm](https://piral.io) · [](https://github.com/smapiot/piral/blob/
|
|
3
|
+
# [Piral Elm](https://piral.io) · [](https://github.com/smapiot/piral/blob/main/LICENSE) [](https://www.npmjs.com/package/piral-elm) [](https://jestjs.io) [](https://gitter.im/piral-io/community)
|
|
4
4
|
|
|
5
|
-
This is a plugin that
|
|
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
|
|
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 ElmConverter {
|
|
5
|
-
(...params: Parameters<typeof
|
|
11
|
+
(...params: Parameters<ReturnType<typeof createConverter>>): HtmlComponent<any>;
|
|
6
12
|
}
|
|
7
|
-
export declare
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
+
};
|
package/esm/converter.js
ADDED
|
@@ -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"}
|
package/esm/create.d.ts
ADDED
|
@@ -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;
|
package/esm/extension.js
ADDED
|
@@ -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
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,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
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,3 +1,13 @@
|
|
|
1
|
-
import { ForeignComponent, BaseComponentProps } from 'piral-core';
|
|
2
|
-
import { ElmModule } from './types';
|
|
3
|
-
export
|
|
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
|
-
|
|
5
|
-
function createConverter() {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
},
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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;
|
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;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
|
-
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
|
13
|
+
fromElm(main, captured) {
|
|
21
14
|
return {
|
|
22
15
|
type: 'elm',
|
|
23
|
-
captured
|
|
24
|
-
main
|
|
16
|
+
captured,
|
|
17
|
+
main,
|
|
25
18
|
};
|
|
26
19
|
},
|
|
27
|
-
ElmExtension:
|
|
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,
|
|
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"}
|
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
|
@@ -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
|
-
|
|
7
|
-
if ('customElements' in window) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
package/lib/extension.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":"
|
|
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
|
-
|
|
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
|
|
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
|
-
"
|
|
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
|
|
43
|
-
},
|
|
44
|
-
"peerDependencies": {
|
|
45
|
-
"piral-core": "1.x"
|
|
67
|
+
"piral-core": "^1.0.0"
|
|
46
68
|
},
|
|
47
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "67d9a2920bd5231baf10bc87ae8985666b18fa3a"
|
|
48
70
|
}
|
package/src/converter.ts
CHANGED
|
@@ -1,35 +1,37 @@
|
|
|
1
|
-
import { ForeignComponent, BaseComponentProps } from 'piral-core';
|
|
2
|
-
import {
|
|
1
|
+
import type { ForeignComponent, BaseComponentProps } from 'piral-core';
|
|
2
|
+
import { createExtension } from './extension';
|
|
3
|
+
import type { ElmModule } from './types';
|
|
3
4
|
|
|
4
|
-
export
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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:
|
|
26
|
+
ElmExtension: convert.Extension,
|
|
38
27
|
};
|
|
39
28
|
};
|
|
40
29
|
}
|
package/src/extension.ts
CHANGED
|
@@ -1,23 +1,11 @@
|
|
|
1
|
-
export function createExtension(selector
|
|
2
|
-
|
|
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
|
-
|
|
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;
|