piral-elm 0.13.9 → 0.14.0-beta.3157
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/convert.d.ts +8 -6
- package/convert.js +17 -8
- package/esm/converter.d.ts +13 -3
- package/esm/converter.js +11 -12
- package/esm/converter.js.map +1 -1
- package/esm/create.d.ts +2 -6
- package/esm/create.js +8 -15
- package/esm/create.js.map +1 -1
- package/esm/extension.d.ts +1 -1
- package/esm/extension.js +7 -24
- package/esm/extension.js.map +1 -1
- package/lib/converter.d.ts +13 -3
- package/lib/converter.js +11 -12
- 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 +3 -3
- package/lib/index.js.map +1 -1
- package/package.json +4 -4
- package/src/converter.ts +18 -14
- package/src/create.ts +4 -15
- package/src/extension.ts +8 -20
package/convert.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { HtmlComponent } from 'piral-core';
|
|
2
|
-
import {
|
|
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>;
|
|
2
|
+
import { createConverter } from './lib/converter';
|
|
4
3
|
export interface ElmConverter {
|
|
5
|
-
(...params: Parameters<typeof
|
|
4
|
+
(...params: Parameters<ReturnType<typeof createConverter>>): HtmlComponent<any>;
|
|
6
5
|
}
|
|
7
|
-
export declare
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
export declare function createElmConverter(...params: Parameters<typeof createConverter>): {
|
|
7
|
+
from: ElmConverter;
|
|
8
|
+
Extension: string;
|
|
9
|
+
};
|
|
10
|
+
declare const fromElm: ElmConverter, ElmExtension: string;
|
|
11
|
+
export { fromElm, ElmExtension };
|
package/convert.js
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
exports.__esModule = true;
|
|
3
|
-
exports.
|
|
3
|
+
exports.ElmExtension = exports.fromElm = exports.createElmConverter = void 0;
|
|
4
4
|
var converter_1 = require("./lib/converter");
|
|
5
|
-
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
function createElmConverter() {
|
|
6
|
+
var params = [];
|
|
7
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
8
|
+
params[_i] = arguments[_i];
|
|
9
|
+
}
|
|
10
|
+
var convert = converter_1.createConverter.apply(void 0, params);
|
|
11
|
+
var Extension = convert.Extension;
|
|
12
|
+
var from = function (main, captured) { return ({
|
|
13
|
+
type: 'html',
|
|
14
|
+
component: convert(main, captured)
|
|
15
|
+
}); };
|
|
16
|
+
return { from: from, Extension: Extension };
|
|
17
|
+
}
|
|
18
|
+
exports.createElmConverter = createElmConverter;
|
|
19
|
+
var _a = createElmConverter(), fromElm = _a.from, ElmExtension = _a.Extension;
|
|
11
20
|
exports.fromElm = fromElm;
|
|
12
|
-
exports.
|
|
21
|
+
exports.ElmExtension = ElmExtension;
|
package/esm/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/esm/converter.js
CHANGED
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export function createConverter() {
|
|
3
|
-
|
|
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) => {
|
|
4
6
|
return {
|
|
5
|
-
mount
|
|
6
|
-
|
|
7
|
-
parent.addEventListener('render-html', function (ev) {
|
|
8
|
-
var piral = data.piral;
|
|
9
|
-
piral.renderHtmlExtension(ev.detail.target, ev.detail.props);
|
|
10
|
-
}, false);
|
|
7
|
+
mount(el, props, ctx) {
|
|
8
|
+
const node = el.appendChild(document.createElement('div'));
|
|
11
9
|
main.init({
|
|
12
|
-
node
|
|
13
|
-
flags:
|
|
10
|
+
node,
|
|
11
|
+
flags: Object.assign(Object.assign(Object.assign({}, captured), ctx), props),
|
|
14
12
|
});
|
|
15
13
|
},
|
|
16
|
-
unmount
|
|
14
|
+
unmount(el) {
|
|
17
15
|
el.innerHTML = '';
|
|
18
16
|
},
|
|
19
17
|
};
|
|
20
18
|
};
|
|
19
|
+
convert.Extension = Extension;
|
|
21
20
|
return convert;
|
|
22
21
|
}
|
|
23
22
|
//# sourceMappingURL=converter.js.map
|
package/esm/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,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;QAC5B,OAAO;YACL,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,GAAG;gBAClB,MAAM,IAAI,GAAG,EAAE,CAAC,WAAW,CAAC,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC;gBAC3D,IAAI,CAAC,IAAI,CAAC;oBACR,IAAI;oBACJ,KAAK,gDACA,QAAQ,GACR,GAAG,GACH,KAAK,CACT;iBACF,CAAC,CAAC;YACL,CAAC;YACD,OAAO,CAAC,EAAE;gBACR,EAAE,CAAC,SAAS,GAAG,EAAE,CAAC;YACpB,CAAC;SACF,CAAC;IACJ,CAAC,CAAC;IACF,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;IAC9B,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/esm/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/esm/create.js
CHANGED
|
@@ -1,27 +1,20 @@
|
|
|
1
1
|
import { createConverter } from './converter';
|
|
2
|
-
import { createExtension } from './extension';
|
|
3
2
|
/**
|
|
4
3
|
* Creates new Pilet API extensions for integration of Elm.
|
|
5
4
|
*/
|
|
6
|
-
export function createElmApi(config) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var convert = createConverter();
|
|
11
|
-
context.converters.elm = function (_a) {
|
|
12
|
-
var main = _a.main, captured = _a.captured;
|
|
13
|
-
return convert(main, captured);
|
|
14
|
-
};
|
|
15
|
-
createExtension(selector);
|
|
5
|
+
export function createElmApi(config = {}) {
|
|
6
|
+
return (context) => {
|
|
7
|
+
const convert = createConverter(config);
|
|
8
|
+
context.converters.elm = ({ main, captured }) => convert(main, captured);
|
|
16
9
|
return {
|
|
17
|
-
fromElm
|
|
10
|
+
fromElm(main, captured) {
|
|
18
11
|
return {
|
|
19
12
|
type: 'elm',
|
|
20
|
-
captured
|
|
21
|
-
main
|
|
13
|
+
captured,
|
|
14
|
+
main,
|
|
22
15
|
};
|
|
23
16
|
},
|
|
24
|
-
ElmExtension:
|
|
17
|
+
ElmExtension: convert.Extension,
|
|
25
18
|
};
|
|
26
19
|
};
|
|
27
20
|
}
|
package/esm/create.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,
|
|
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"}
|
package/esm/extension.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function createExtension(selector
|
|
1
|
+
export declare function createExtension(selector: string): string;
|
package/esm/extension.js
CHANGED
|
@@ -1,28 +1,11 @@
|
|
|
1
|
-
import { __extends } from "tslib";
|
|
2
1
|
export function createExtension(selector) {
|
|
3
|
-
|
|
4
|
-
if ('customElements' in window) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
ElmExtension.prototype.connectedCallback = function () {
|
|
11
|
-
if (this.isConnected) {
|
|
12
|
-
this.dispatchEvent(new CustomEvent('render-html', {
|
|
13
|
-
bubbles: true,
|
|
14
|
-
detail: {
|
|
15
|
-
target: this,
|
|
16
|
-
props: {
|
|
17
|
-
name: this.getAttribute('name'),
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
}));
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
return ElmExtension;
|
|
24
|
-
}(HTMLElement));
|
|
25
|
-
customElements.define(selector, ElmExtension);
|
|
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);
|
|
26
8
|
}
|
|
9
|
+
return selector || defaultExtensionSelector;
|
|
27
10
|
}
|
|
28
11
|
//# sourceMappingURL=extension.js.map
|
package/esm/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,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/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,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createConverter = void 0;
|
|
4
|
-
|
|
5
|
-
function createConverter() {
|
|
6
|
-
|
|
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) => {
|
|
7
9
|
return {
|
|
8
|
-
mount
|
|
9
|
-
|
|
10
|
-
parent.addEventListener('render-html', function (ev) {
|
|
11
|
-
var piral = data.piral;
|
|
12
|
-
piral.renderHtmlExtension(ev.detail.target, ev.detail.props);
|
|
13
|
-
}, false);
|
|
10
|
+
mount(el, props, ctx) {
|
|
11
|
+
const node = el.appendChild(document.createElement('div'));
|
|
14
12
|
main.init({
|
|
15
|
-
node
|
|
16
|
-
flags:
|
|
13
|
+
node,
|
|
14
|
+
flags: Object.assign(Object.assign(Object.assign({}, captured), ctx), props),
|
|
17
15
|
});
|
|
18
16
|
},
|
|
19
|
-
unmount
|
|
17
|
+
unmount(el) {
|
|
20
18
|
el.innerHTML = '';
|
|
21
19
|
},
|
|
22
20
|
};
|
|
23
21
|
};
|
|
22
|
+
convert.Extension = Extension;
|
|
24
23
|
return convert;
|
|
25
24
|
}
|
|
26
25
|
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;QAC5B,OAAO;YACL,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,GAAG;gBAClB,MAAM,IAAI,GAAG,EAAE,CAAC,WAAW,CAAC,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC;gBAC3D,IAAI,CAAC,IAAI,CAAC;oBACR,IAAI;oBACJ,KAAK,gDACA,QAAQ,GACR,GAAG,GACH,KAAK,CACT;iBACF,CAAC,CAAC;YACL,CAAC;YACD,OAAO,CAAC,EAAE;gBACR,EAAE,CAAC,SAAS,GAAG,EAAE,CAAC;YACpB,CAAC;SACF,CAAC;IACJ,CAAC,CAAC;IACF,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;IAC9B,OAAO,OAAO,CAAC;AACjB,CAAC;AA1BD,0CA0BC"}
|
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
|
-
|
|
4
|
-
tslib_1.__exportStar(require("./create"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./types"), exports);
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
(0, tslib_1.__exportStar)(require("./create"), exports);
|
|
5
|
+
(0, tslib_1.__exportStar)(require("./types"), exports);
|
|
6
6
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,wDAAyB;AACzB,uDAAwB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "piral-elm",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0-beta.3157",
|
|
4
4
|
"description": "Plugin for integrating Elm components in Piral.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"piral",
|
|
@@ -43,10 +43,10 @@
|
|
|
43
43
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"piral-core": "^0.
|
|
46
|
+
"piral-core": "^0.14.0-beta.3157"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
|
-
"piral-core": "0.
|
|
49
|
+
"piral-core": "0.14.x"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "1928e46becee1444f84df8e80a81aa12712d17e2"
|
|
52
52
|
}
|
package/src/converter.ts
CHANGED
|
@@ -1,28 +1,31 @@
|
|
|
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
19
|
): ForeignComponent<TProps> => {
|
|
9
20
|
return {
|
|
10
|
-
mount(
|
|
11
|
-
const node =
|
|
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
|
-
);
|
|
21
|
+
mount(el, props, ctx) {
|
|
22
|
+
const node = el.appendChild(document.createElement('div'));
|
|
20
23
|
main.init({
|
|
21
24
|
node,
|
|
22
25
|
flags: {
|
|
23
26
|
...captured,
|
|
24
27
|
...ctx,
|
|
25
|
-
...
|
|
28
|
+
...props,
|
|
26
29
|
},
|
|
27
30
|
});
|
|
28
31
|
},
|
|
@@ -31,5 +34,6 @@ export function createConverter() {
|
|
|
31
34
|
},
|
|
32
35
|
};
|
|
33
36
|
};
|
|
37
|
+
convert.Extension = Extension;
|
|
34
38
|
return convert;
|
|
35
39
|
}
|
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
|
}
|