piral-mithril 1.0.0-pre.2104 → 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 +8 -9
- package/convert.d.ts +22 -7
- package/convert.js +16 -11
- package/esm/converter.d.ts +16 -0
- package/esm/converter.js +25 -0
- package/esm/converter.js.map +1 -0
- package/esm/create.d.ts +11 -0
- package/esm/create.js +21 -0
- package/esm/create.js.map +1 -0
- package/esm/extension.d.ts +4 -0
- package/esm/extension.js +18 -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 +16 -3
- package/lib/converter.js +22 -25
- package/lib/converter.js.map +1 -1
- package/lib/create.d.ts +0 -5
- package/lib/create.js +11 -17
- package/lib/create.js.map +1 -1
- package/lib/extension.d.ts +1 -2
- package/lib/extension.js +12 -7
- package/lib/extension.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/types.d.ts +1 -1
- package/package.json +31 -7
- package/src/converter.ts +42 -33
- package/src/create.ts +5 -14
- package/src/extension.ts +11 -4
- package/src/types.ts +1 -1
- package/convert.ts +0 -16
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
[](https://piral.io)
|
|
2
2
|
|
|
3
|
-
# [Piral Mithril](https://piral.io) · [](https://github.com/smapiot/piral/blob/
|
|
3
|
+
# [Piral Mithril](https://piral.io) · [](https://github.com/smapiot/piral/blob/main/LICENSE) [](https://www.npmjs.com/package/piral-mithril) [](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 `mithril`. What `piral-mithril` 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 Mithril.js converter for any component registration, as well as a `fromMithril` shortcut and a `MithrilExtension` component.
|
|
8
8
|
|
|
@@ -47,7 +47,7 @@ Alternatively, if `piral-mithril` has not been added to the Piral instance you c
|
|
|
47
47
|
|
|
48
48
|
```ts
|
|
49
49
|
import { PiletApi } from '<name-of-piral-instance>';
|
|
50
|
-
import { fromMithril } from 'piral-mithril';
|
|
50
|
+
import { fromMithril } from 'piral-mithril/convert';
|
|
51
51
|
import { MithrilPage } from './MithrilPage';
|
|
52
52
|
|
|
53
53
|
export function setup(piral: PiletApi) {
|
|
@@ -62,7 +62,6 @@ export function setup(piral: PiletApi) {
|
|
|
62
62
|
Using Mithril.js with Piral is as simple as installing `piral-mithril` and `mithril`.
|
|
63
63
|
|
|
64
64
|
```ts
|
|
65
|
-
import 'mithril';
|
|
66
65
|
import { createMithrilApi } from 'piral-mithril';
|
|
67
66
|
```
|
|
68
67
|
|
|
@@ -80,10 +79,10 @@ The `mithril` package should be shared with the pilets via the *package.json*:
|
|
|
80
79
|
|
|
81
80
|
```json
|
|
82
81
|
{
|
|
83
|
-
"
|
|
84
|
-
"
|
|
85
|
-
"mithril"
|
|
86
|
-
|
|
82
|
+
"importmap": {
|
|
83
|
+
"imports": {
|
|
84
|
+
"mithril": ""
|
|
85
|
+
}
|
|
87
86
|
}
|
|
88
87
|
}
|
|
89
88
|
```
|
package/convert.d.ts
CHANGED
|
@@ -1,9 +1,24 @@
|
|
|
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 MithrilConverter {
|
|
5
|
-
(...params: Parameters<typeof
|
|
11
|
+
(...params: Parameters<ReturnType<typeof createConverter>>): HtmlComponent<any>;
|
|
6
12
|
}
|
|
7
|
-
export declare
|
|
8
|
-
|
|
9
|
-
|
|
13
|
+
export declare function createMithrilConverter(...params: Parameters<typeof createConverter>): {
|
|
14
|
+
from: MithrilConverter;
|
|
15
|
+
Extension: {
|
|
16
|
+
oncreate(vnode: any): void;
|
|
17
|
+
view(): any;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
declare const fromMithril: MithrilConverter, MithrilExtension: {
|
|
21
|
+
oncreate(vnode: any): void;
|
|
22
|
+
view(): any;
|
|
23
|
+
};
|
|
24
|
+
export { fromMithril, MithrilExtension };
|
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 createMithrilConverter() {
|
|
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 (component, captured) { return ({
|
|
10
|
+
type: 'html',
|
|
11
|
+
component: convert(component, captured),
|
|
12
|
+
}); };
|
|
13
|
+
return { from: from, Extension: Extension };
|
|
14
|
+
}
|
|
15
|
+
var _a = createMithrilConverter(), fromMithril = _a.from, MithrilExtension = _a.Extension;
|
|
16
|
+
export { fromMithril, MithrilExtension };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ForeignComponent, BaseComponentProps } from 'piral-core';
|
|
2
|
+
import type { Component } from './types';
|
|
3
|
+
export interface MithrilConverterOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Defines the name of the root element.
|
|
6
|
+
* @default piral-slot
|
|
7
|
+
*/
|
|
8
|
+
rootName?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function createConverter(config?: MithrilConverterOptions): {
|
|
11
|
+
<TProps extends BaseComponentProps>(component: Component<TProps>, captured?: Record<string, any>): ForeignComponent<TProps>;
|
|
12
|
+
Extension: {
|
|
13
|
+
oncreate(vnode: any): void;
|
|
14
|
+
view(): any;
|
|
15
|
+
};
|
|
16
|
+
};
|
package/esm/converter.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as mithril from 'mithril';
|
|
2
|
+
import { createExtension } from './extension';
|
|
3
|
+
export function createConverter(config = {}) {
|
|
4
|
+
const { rootName = 'piral-slot' } = config;
|
|
5
|
+
const Extension = createExtension(rootName);
|
|
6
|
+
const convert = (component, captured) => ({
|
|
7
|
+
mount(el, props, ctx) {
|
|
8
|
+
mithril.mount(el, {
|
|
9
|
+
view: () => mithril.m(component, Object.assign(Object.assign(Object.assign({}, captured), ctx), props)),
|
|
10
|
+
});
|
|
11
|
+
},
|
|
12
|
+
update(el, props, ctx) {
|
|
13
|
+
mithril.mount(el, {
|
|
14
|
+
view: () => mithril.m(component, Object.assign(Object.assign(Object.assign({}, captured), ctx), props)),
|
|
15
|
+
});
|
|
16
|
+
},
|
|
17
|
+
unmount(el) {
|
|
18
|
+
// tslint:disable-next-line:no-null-keyword
|
|
19
|
+
mithril.mount(el, null);
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
convert.Extension = Extension;
|
|
23
|
+
return convert;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=converter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"converter.js","sourceRoot":"","sources":["../src/converter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAEnC,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAW9C,MAAM,UAAU,eAAe,CAAC,SAAkC,EAAE;IAClE,MAAM,EAAE,QAAQ,GAAG,YAAY,EAAE,GAAG,MAAM,CAAC;IAC3C,MAAM,SAAS,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC;IAC5C,MAAM,OAAO,GAAG,CACd,SAA4B,EAC5B,QAA8B,EACJ,EAAE,CAAC,CAAC;QAC9B,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,GAAG;YAClB,OAAO,CAAC,KAAK,CAAC,EAAE,EAAE;gBAChB,IAAI,EAAE,GAAG,EAAE,CACT,OAAO,CAAC,CAAC,CAAC,SAAS,gDACd,QAAQ,GACR,GAAG,GACH,KAAK,EACR;aACL,CAAC,CAAC;QACL,CAAC;QACD,MAAM,CAAC,EAAE,EAAE,KAAK,EAAE,GAAG;YACnB,OAAO,CAAC,KAAK,CAAC,EAAE,EAAE;gBAChB,IAAI,EAAE,GAAG,EAAE,CACT,OAAO,CAAC,CAAC,CAAC,SAAS,gDACd,QAAQ,GACR,GAAG,GACH,KAAK,EACR;aACL,CAAC,CAAC;QACL,CAAC;QACD,OAAO,CAAC,EAAE;YACR,2CAA2C;YAC3C,OAAO,CAAC,KAAK,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;QAC1B,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 { PiletMithrilApi } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Available configuration options for the Mithril.js plugin.
|
|
5
|
+
*/
|
|
6
|
+
export interface MithrilConfig {
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Creates new Pilet API extensions for integrating Mithril.js.
|
|
10
|
+
*/
|
|
11
|
+
export declare function createMithrilApi(config?: MithrilConfig): PiralPlugin<PiletMithrilApi>;
|
package/esm/create.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createConverter } from './converter';
|
|
2
|
+
/**
|
|
3
|
+
* Creates new Pilet API extensions for integrating Mithril.js.
|
|
4
|
+
*/
|
|
5
|
+
export function createMithrilApi(config = {}) {
|
|
6
|
+
return (context) => {
|
|
7
|
+
const convert = createConverter(config);
|
|
8
|
+
context.converters.mithril = ({ component, captured }) => convert(component, captured);
|
|
9
|
+
return {
|
|
10
|
+
fromMithril(component, captured) {
|
|
11
|
+
return {
|
|
12
|
+
type: 'mithril',
|
|
13
|
+
component,
|
|
14
|
+
captured,
|
|
15
|
+
};
|
|
16
|
+
},
|
|
17
|
+
MithrilExtension: 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,EAAE,MAAM,aAAa,CAAC;AAQ9C;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,SAAwB,EAAE;IACzD,OAAO,CAAC,OAAO,EAAE,EAAE;QACjB,MAAM,OAAO,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;QACxC,OAAO,CAAC,UAAU,CAAC,OAAO,GAAG,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QAEvF,OAAO;YACL,WAAW,CAAC,SAAS,EAAE,QAAQ;gBAC7B,OAAO;oBACL,IAAI,EAAE,SAAS;oBACf,SAAS;oBACT,QAAQ;iBACT,CAAC;YACJ,CAAC;YACD,gBAAgB,EAAE,OAAO,CAAC,SAAS;SACpC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
|
package/esm/extension.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { m } from 'mithril';
|
|
2
|
+
export function createExtension(rootName) {
|
|
3
|
+
return {
|
|
4
|
+
oncreate(vnode) {
|
|
5
|
+
vnode.dom.dispatchEvent(new CustomEvent('render-html', {
|
|
6
|
+
bubbles: true,
|
|
7
|
+
detail: {
|
|
8
|
+
target: vnode.dom,
|
|
9
|
+
props: vnode.attrs,
|
|
10
|
+
},
|
|
11
|
+
}));
|
|
12
|
+
},
|
|
13
|
+
view() {
|
|
14
|
+
return m(rootName);
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=extension.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,SAAS,CAAC;AAE5B,MAAM,UAAU,eAAe,CAAC,QAAgB;IAC9C,OAAO;QACL,QAAQ,CAAC,KAAK;YACZ,KAAK,CAAC,GAAG,CAAC,aAAa,CACrB,IAAI,WAAW,CAAC,aAAa,EAAE;gBAC7B,OAAO,EAAE,IAAI;gBACb,MAAM,EAAE;oBACN,MAAM,EAAE,KAAK,CAAC,GAAG;oBACjB,KAAK,EAAE,KAAK,CAAC,KAAK;iBACnB;aACF,CAAC,CACH,CAAC;QACJ,CAAC;QACD,IAAI;YACF,OAAO,CAAC,CAAC,QAAQ,CAAC,CAAC;QACrB,CAAC;KACF,CAAC;AACJ,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, ExtensionSlotProps } from 'piral-core';
|
|
2
|
+
declare module 'piral-core/lib/types/custom' {
|
|
3
|
+
interface PiletCustomApi extends PiletMithrilApi {
|
|
4
|
+
}
|
|
5
|
+
interface PiralCustomComponentConverters<TProps> {
|
|
6
|
+
mithril(component: MithrilComponent<TProps>): ForeignComponent<TProps>;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export interface ComponentProps<TProps> {
|
|
10
|
+
attrs: TProps;
|
|
11
|
+
}
|
|
12
|
+
export interface Component<TProps> {
|
|
13
|
+
view(vnode: ComponentProps<TProps>): any;
|
|
14
|
+
}
|
|
15
|
+
export interface MithrilComponent<TProps> {
|
|
16
|
+
/**
|
|
17
|
+
* The component.
|
|
18
|
+
*/
|
|
19
|
+
component: Component<TProps>;
|
|
20
|
+
/**
|
|
21
|
+
* Captures props for transport into the Mithril.js component.
|
|
22
|
+
*/
|
|
23
|
+
captured?: Record<string, any>;
|
|
24
|
+
/**
|
|
25
|
+
* The type of the Mithril.js component.
|
|
26
|
+
*/
|
|
27
|
+
type: 'mithril';
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Defines the provided set of Mithril.js Pilet API extensions.
|
|
31
|
+
*/
|
|
32
|
+
export interface PiletMithrilApi {
|
|
33
|
+
/**
|
|
34
|
+
* Wraps an Mithril.js component for use in Piral.
|
|
35
|
+
* @param component The component root.
|
|
36
|
+
* @param captured The optionally captured props.
|
|
37
|
+
* @returns The Piral Mithril.js component.
|
|
38
|
+
*/
|
|
39
|
+
fromMithril<TProps>(component: Component<TProps>, captured?: Record<string, any>): MithrilComponent<TProps>;
|
|
40
|
+
/**
|
|
41
|
+
* Mithril.js component for displaying extensions of the given name.
|
|
42
|
+
*/
|
|
43
|
+
MithrilExtension: Component<ExtensionSlotProps>;
|
|
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,16 @@
|
|
|
1
|
-
import { ForeignComponent, BaseComponentProps } from 'piral-core';
|
|
2
|
-
import { Component } from './types';
|
|
3
|
-
export
|
|
1
|
+
import type { ForeignComponent, BaseComponentProps } from 'piral-core';
|
|
2
|
+
import type { Component } from './types';
|
|
3
|
+
export interface MithrilConverterOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Defines the name of the root element.
|
|
6
|
+
* @default piral-slot
|
|
7
|
+
*/
|
|
8
|
+
rootName?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function createConverter(config?: MithrilConverterOptions): {
|
|
11
|
+
<TProps extends BaseComponentProps>(component: Component<TProps>, captured?: Record<string, any>): ForeignComponent<TProps>;
|
|
12
|
+
Extension: {
|
|
13
|
+
oncreate(vnode: any): void;
|
|
14
|
+
view(): any;
|
|
15
|
+
};
|
|
16
|
+
};
|
package/lib/converter.js
CHANGED
|
@@ -1,31 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createConverter = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
function createConverter() {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
m.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
},
|
|
27
|
-
};
|
|
28
|
-
};
|
|
4
|
+
const mithril = require("mithril");
|
|
5
|
+
const extension_1 = require("./extension");
|
|
6
|
+
function createConverter(config = {}) {
|
|
7
|
+
const { rootName = 'piral-slot' } = config;
|
|
8
|
+
const Extension = (0, extension_1.createExtension)(rootName);
|
|
9
|
+
const convert = (component, captured) => ({
|
|
10
|
+
mount(el, props, ctx) {
|
|
11
|
+
mithril.mount(el, {
|
|
12
|
+
view: () => mithril.m(component, Object.assign(Object.assign(Object.assign({}, captured), ctx), props)),
|
|
13
|
+
});
|
|
14
|
+
},
|
|
15
|
+
update(el, props, ctx) {
|
|
16
|
+
mithril.mount(el, {
|
|
17
|
+
view: () => mithril.m(component, Object.assign(Object.assign(Object.assign({}, captured), ctx), props)),
|
|
18
|
+
});
|
|
19
|
+
},
|
|
20
|
+
unmount(el) {
|
|
21
|
+
// tslint:disable-next-line:no-null-keyword
|
|
22
|
+
mithril.mount(el, null);
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
convert.Extension = Extension;
|
|
29
26
|
return convert;
|
|
30
27
|
}
|
|
31
28
|
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":";;;AAAA,mCAAmC;AAEnC,2CAA8C;AAW9C,SAAgB,eAAe,CAAC,SAAkC,EAAE;IAClE,MAAM,EAAE,QAAQ,GAAG,YAAY,EAAE,GAAG,MAAM,CAAC;IAC3C,MAAM,SAAS,GAAG,IAAA,2BAAe,EAAC,QAAQ,CAAC,CAAC;IAC5C,MAAM,OAAO,GAAG,CACd,SAA4B,EAC5B,QAA8B,EACJ,EAAE,CAAC,CAAC;QAC9B,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,GAAG;YAClB,OAAO,CAAC,KAAK,CAAC,EAAE,EAAE;gBAChB,IAAI,EAAE,GAAG,EAAE,CACT,OAAO,CAAC,CAAC,CAAC,SAAS,gDACd,QAAQ,GACR,GAAG,GACH,KAAK,EACR;aACL,CAAC,CAAC;QACL,CAAC;QACD,MAAM,CAAC,EAAE,EAAE,KAAK,EAAE,GAAG;YACnB,OAAO,CAAC,KAAK,CAAC,EAAE,EAAE;gBAChB,IAAI,EAAE,GAAG,EAAE,CACT,OAAO,CAAC,CAAC,CAAC,SAAS,gDACd,QAAQ,GACR,GAAG,GACH,KAAK,EACR;aACL,CAAC,CAAC;QACL,CAAC;QACD,OAAO,CAAC,EAAE;YACR,2CAA2C;YAC3C,OAAO,CAAC,KAAK,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;QAC1B,CAAC;KACF,CAAC,CAAC;IACH,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;IAC9B,OAAO,OAAO,CAAC;AACjB,CAAC;AAlCD,0CAkCC"}
|
package/lib/create.d.ts
CHANGED
|
@@ -4,11 +4,6 @@ import type { PiletMithrilApi } from './types';
|
|
|
4
4
|
* Available configuration options for the Mithril.js plugin.
|
|
5
5
|
*/
|
|
6
6
|
export interface MithrilConfig {
|
|
7
|
-
/**
|
|
8
|
-
* Defines the name of the root element.
|
|
9
|
-
* @default slot
|
|
10
|
-
*/
|
|
11
|
-
rootName?: string;
|
|
12
7
|
}
|
|
13
8
|
/**
|
|
14
9
|
* Creates new Pilet API extensions for integrating Mithril.js.
|
package/lib/create.js
CHANGED
|
@@ -1,30 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createMithrilApi = 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 integrating Mithril.js.
|
|
8
7
|
*/
|
|
9
|
-
function createMithrilApi(config) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
var component = _a.component, captured = _a.captured;
|
|
16
|
-
return convert(component, captured);
|
|
17
|
-
};
|
|
18
|
-
return function (api) { return ({
|
|
19
|
-
fromMithril: function (component, captured) {
|
|
8
|
+
function createMithrilApi(config = {}) {
|
|
9
|
+
return (context) => {
|
|
10
|
+
const convert = (0, converter_1.createConverter)(config);
|
|
11
|
+
context.converters.mithril = ({ component, captured }) => convert(component, captured);
|
|
12
|
+
return {
|
|
13
|
+
fromMithril(component, captured) {
|
|
20
14
|
return {
|
|
21
15
|
type: 'mithril',
|
|
22
|
-
component
|
|
23
|
-
captured
|
|
16
|
+
component,
|
|
17
|
+
captured,
|
|
24
18
|
};
|
|
25
19
|
},
|
|
26
|
-
MithrilExtension:
|
|
27
|
-
}
|
|
20
|
+
MithrilExtension: convert.Extension,
|
|
21
|
+
};
|
|
28
22
|
};
|
|
29
23
|
}
|
|
30
24
|
exports.createMithrilApi = createMithrilApi;
|
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,2CAA8C;AAQ9C;;GAEG;AACH,SAAgB,gBAAgB,CAAC,SAAwB,EAAE;IACzD,OAAO,CAAC,OAAO,EAAE,EAAE;QACjB,MAAM,OAAO,GAAG,IAAA,2BAAe,EAAC,MAAM,CAAC,CAAC;QACxC,OAAO,CAAC,UAAU,CAAC,OAAO,GAAG,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QAEvF,OAAO;YACL,WAAW,CAAC,SAAS,EAAE,QAAQ;gBAC7B,OAAO;oBACL,IAAI,EAAE,SAAS;oBACf,SAAS;oBACT,QAAQ;iBACT,CAAC;YACJ,CAAC;YACD,gBAAgB,EAAE,OAAO,CAAC,SAAS;SACpC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAhBD,4CAgBC"}
|
package/lib/extension.d.ts
CHANGED
package/lib/extension.js
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createExtension = void 0;
|
|
4
|
-
|
|
5
|
-
function createExtension(
|
|
6
|
-
if (rootName === void 0) { rootName = 'slot'; }
|
|
4
|
+
const mithril_1 = require("mithril");
|
|
5
|
+
function createExtension(rootName) {
|
|
7
6
|
return {
|
|
8
|
-
oncreate
|
|
9
|
-
|
|
7
|
+
oncreate(vnode) {
|
|
8
|
+
vnode.dom.dispatchEvent(new CustomEvent('render-html', {
|
|
9
|
+
bubbles: true,
|
|
10
|
+
detail: {
|
|
11
|
+
target: vnode.dom,
|
|
12
|
+
props: vnode.attrs,
|
|
13
|
+
},
|
|
14
|
+
}));
|
|
10
15
|
},
|
|
11
|
-
view
|
|
12
|
-
return m(rootName);
|
|
16
|
+
view() {
|
|
17
|
+
return (0, mithril_1.m)(rootName);
|
|
13
18
|
},
|
|
14
19
|
};
|
|
15
20
|
}
|
package/lib/extension.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":";;;AAAA,qCAA4B;AAE5B,SAAgB,eAAe,CAAC,QAAgB;IAC9C,OAAO;QACL,QAAQ,CAAC,KAAK;YACZ,KAAK,CAAC,GAAG,CAAC,aAAa,CACrB,IAAI,WAAW,CAAC,aAAa,EAAE;gBAC7B,OAAO,EAAE,IAAI;gBACb,MAAM,EAAE;oBACN,MAAM,EAAE,KAAK,CAAC,GAAG;oBACjB,KAAK,EAAE,KAAK,CAAC,KAAK;iBACnB;aACF,CAAC,CACH,CAAC;QACJ,CAAC;QACD,IAAI;YACF,OAAO,IAAA,WAAC,EAAC,QAAQ,CAAC,CAAC;QACrB,CAAC;KACF,CAAC;AACJ,CAAC;AAjBD,0CAiBC"}
|
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/lib/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "piral-mithril",
|
|
3
|
-
"version": "1.0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Plugin for integrating Mithril.js 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,17 +55,20 @@
|
|
|
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-mithril.json src --exclude \"src/**/*.test.*\"",
|
|
39
64
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
40
65
|
},
|
|
41
66
|
"devDependencies": {
|
|
42
67
|
"mithril": "2.0.4",
|
|
43
|
-
"piral-core": "^1.0.0
|
|
68
|
+
"piral-core": "^1.0.0"
|
|
44
69
|
},
|
|
45
70
|
"peerDependencies": {
|
|
46
|
-
"mithril": "^2.0.0"
|
|
47
|
-
"piral-core": "1.x"
|
|
71
|
+
"mithril": "^2.0.0"
|
|
48
72
|
},
|
|
49
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "67d9a2920bd5231baf10bc87ae8985666b18fa3a"
|
|
50
74
|
}
|
package/src/converter.ts
CHANGED
|
@@ -1,39 +1,48 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import { ForeignComponent, BaseComponentProps } from 'piral-core';
|
|
3
|
-
import {
|
|
1
|
+
import * as mithril from 'mithril';
|
|
2
|
+
import type { ForeignComponent, BaseComponentProps } from 'piral-core';
|
|
3
|
+
import { createExtension } from './extension';
|
|
4
|
+
import type { Component } from './types';
|
|
4
5
|
|
|
5
|
-
export
|
|
6
|
+
export interface MithrilConverterOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Defines the name of the root element.
|
|
9
|
+
* @default piral-slot
|
|
10
|
+
*/
|
|
11
|
+
rootName?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function createConverter(config: MithrilConverterOptions = {}) {
|
|
15
|
+
const { rootName = 'piral-slot' } = config;
|
|
16
|
+
const Extension = createExtension(rootName);
|
|
6
17
|
const convert = <TProps extends BaseComponentProps>(
|
|
7
18
|
component: Component<TProps>,
|
|
8
19
|
captured?: Record<string, any>,
|
|
9
|
-
): ForeignComponent<TProps> => {
|
|
10
|
-
|
|
11
|
-
mount(el,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
};
|
|
37
|
-
|
|
20
|
+
): ForeignComponent<TProps> => ({
|
|
21
|
+
mount(el, props, ctx) {
|
|
22
|
+
mithril.mount(el, {
|
|
23
|
+
view: () =>
|
|
24
|
+
mithril.m(component, {
|
|
25
|
+
...captured,
|
|
26
|
+
...ctx,
|
|
27
|
+
...props,
|
|
28
|
+
}),
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
update(el, props, ctx) {
|
|
32
|
+
mithril.mount(el, {
|
|
33
|
+
view: () =>
|
|
34
|
+
mithril.m(component, {
|
|
35
|
+
...captured,
|
|
36
|
+
...ctx,
|
|
37
|
+
...props,
|
|
38
|
+
}),
|
|
39
|
+
});
|
|
40
|
+
},
|
|
41
|
+
unmount(el) {
|
|
42
|
+
// tslint:disable-next-line:no-null-keyword
|
|
43
|
+
mithril.mount(el, null);
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
convert.Extension = Extension;
|
|
38
47
|
return convert;
|
|
39
48
|
}
|
package/src/create.ts
CHANGED
|
@@ -1,30 +1,21 @@
|
|
|
1
1
|
import type { PiralPlugin } from 'piral-core';
|
|
2
2
|
import { createConverter } from './converter';
|
|
3
|
-
import { createExtension } from './extension';
|
|
4
3
|
import type { PiletMithrilApi } from './types';
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* Available configuration options for the Mithril.js plugin.
|
|
8
7
|
*/
|
|
9
|
-
export interface MithrilConfig {
|
|
10
|
-
/**
|
|
11
|
-
* Defines the name of the root element.
|
|
12
|
-
* @default slot
|
|
13
|
-
*/
|
|
14
|
-
rootName?: string;
|
|
15
|
-
}
|
|
8
|
+
export interface MithrilConfig {}
|
|
16
9
|
|
|
17
10
|
/**
|
|
18
11
|
* Creates new Pilet API extensions for integrating Mithril.js.
|
|
19
12
|
*/
|
|
20
13
|
export function createMithrilApi(config: MithrilConfig = {}): PiralPlugin<PiletMithrilApi> {
|
|
21
|
-
const { rootName } = config;
|
|
22
|
-
|
|
23
14
|
return (context) => {
|
|
24
|
-
const convert = createConverter();
|
|
15
|
+
const convert = createConverter(config);
|
|
25
16
|
context.converters.mithril = ({ component, captured }) => convert(component, captured);
|
|
26
17
|
|
|
27
|
-
return
|
|
18
|
+
return {
|
|
28
19
|
fromMithril(component, captured) {
|
|
29
20
|
return {
|
|
30
21
|
type: 'mithril',
|
|
@@ -32,7 +23,7 @@ export function createMithrilApi(config: MithrilConfig = {}): PiralPlugin<PiletM
|
|
|
32
23
|
captured,
|
|
33
24
|
};
|
|
34
25
|
},
|
|
35
|
-
MithrilExtension:
|
|
36
|
-
}
|
|
26
|
+
MithrilExtension: convert.Extension,
|
|
27
|
+
};
|
|
37
28
|
};
|
|
38
29
|
}
|
package/src/extension.ts
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type { PiletApi } from 'piral-core';
|
|
1
|
+
import { m } from 'mithril';
|
|
3
2
|
|
|
4
|
-
export function createExtension(
|
|
3
|
+
export function createExtension(rootName: string) {
|
|
5
4
|
return {
|
|
6
5
|
oncreate(vnode) {
|
|
7
|
-
|
|
6
|
+
vnode.dom.dispatchEvent(
|
|
7
|
+
new CustomEvent('render-html', {
|
|
8
|
+
bubbles: true,
|
|
9
|
+
detail: {
|
|
10
|
+
target: vnode.dom,
|
|
11
|
+
props: vnode.attrs,
|
|
12
|
+
},
|
|
13
|
+
}),
|
|
14
|
+
);
|
|
8
15
|
},
|
|
9
16
|
view() {
|
|
10
17
|
return m(rootName);
|
package/src/types.ts
CHANGED
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 MithrilConverter {
|
|
8
|
-
(...params: Parameters<typeof convert>): HtmlComponent<any>;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export const fromMithril: MithrilConverter = (component, captured) => ({
|
|
12
|
-
type: 'html',
|
|
13
|
-
component: convert(component, captured),
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
export const createMithrilExtension = createExtension;
|