piral-mithril 1.0.0-pre.2108 → 1.0.1-beta.5640

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE 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 Mithril](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-mithril.svg?style=flat)](https://www.npmjs.com/package/piral-mithril) [![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 Mithril](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-mithril.svg?style=flat)](https://www.npmjs.com/package/piral-mithril) [![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-mithril` 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 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) {
@@ -59,10 +59,9 @@ export function setup(piral: PiletApi) {
59
59
 
60
60
  ::: summary: For Piral instance developers
61
61
 
62
- Using Mithril.js with Piral is as simple as installing `piral-mithril` and `mithril`.
62
+ Using Mithril.js with Piral is as simple as installing `piral-mithril` and `mithril@^2`.
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
- "pilets": {
84
- "externals": [
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 type { HtmlComponent } from 'piral-core';
2
- import { createExtension } from './lib/extension';
3
- declare const convert: <TProps extends import("piral-core").BaseComponentProps>(component: import("./lib/types").Component<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 MithrilConverter {
5
- (...params: Parameters<typeof convert>): HtmlComponent<any>;
11
+ (...params: Parameters<ReturnType<typeof createConverter>>): HtmlComponent<any>;
6
12
  }
7
- export declare const fromMithril: MithrilConverter;
8
- export declare const createMithrilExtension: typeof createExtension;
9
- export {};
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
- "use strict";
2
- exports.__esModule = true;
3
- exports.createMithrilExtension = exports.fromMithril = void 0;
4
- var converter_1 = require("./lib/converter");
5
- var extension_1 = require("./lib/extension");
6
- var convert = converter_1.createConverter();
7
- exports.fromMithril = function (component, captured) { return ({
8
- type: 'html',
9
- component: convert(component, captured)
10
- }); };
11
- exports.createMithrilExtension = extension_1.createExtension;
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 };
@@ -1,3 +1,16 @@
1
- import { ForeignComponent, BaseComponentProps } from 'piral-core';
2
- import { Component } from './types';
3
- export declare function createConverter(): <TProps extends BaseComponentProps>(component: Component<TProps>, captured?: Record<string, any>) => ForeignComponent<TProps>;
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 CHANGED
@@ -1,28 +1,25 @@
1
- import { __assign } from "tslib";
2
- import * as m from 'mithril';
3
- export function createConverter() {
4
- var convert = function (component, captured) {
5
- return {
6
- mount: function (el, props, ctx) {
7
- m.mount(el, {
8
- view: function () {
9
- return m(component, __assign(__assign(__assign({}, captured), ctx), props));
10
- },
11
- });
12
- },
13
- update: function (el, props, ctx) {
14
- m.mount(el, {
15
- view: function () {
16
- return m(component, __assign(__assign(__assign({}, captured), ctx), props));
17
- },
18
- });
19
- },
20
- unmount: function (el) {
21
- // tslint:disable-next-line:no-null-keyword
22
- m.mount(el, null);
23
- },
24
- };
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;
26
23
  return convert;
27
24
  }
28
25
  //# sourceMappingURL=converter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"converter.js","sourceRoot":"","sources":["../src/converter.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAI7B,MAAM,UAAU,eAAe;IAC7B,IAAM,OAAO,GAAG,UACd,SAA4B,EAC5B,QAA8B;QAE9B,OA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;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 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/esm/create.js CHANGED
@@ -1,27 +1,21 @@
1
1
  import { createConverter } from './converter';
2
- import { createExtension } from './extension';
3
2
  /**
4
3
  * Creates new Pilet API extensions for integrating Mithril.js.
5
4
  */
6
- export function createMithrilApi(config) {
7
- if (config === void 0) { config = {}; }
8
- var rootName = config.rootName;
9
- return function (context) {
10
- var convert = createConverter();
11
- context.converters.mithril = function (_a) {
12
- var component = _a.component, captured = _a.captured;
13
- return convert(component, captured);
14
- };
15
- return function (api) { return ({
16
- fromMithril: function (component, captured) {
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) {
17
11
  return {
18
12
  type: 'mithril',
19
- component: component,
20
- captured: captured,
13
+ component,
14
+ captured,
21
15
  };
22
16
  },
23
- MithrilExtension: createExtension(api, rootName),
24
- }); };
17
+ MithrilExtension: convert.Extension,
18
+ };
25
19
  };
26
20
  }
27
21
  //# sourceMappingURL=create.js.map
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,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAc9C;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAA0B;IAA1B,uBAAA,EAAA,WAA0B;IACjD,IAAA,QAAQ,GAAK,MAAM,SAAX,CAAY;IAE5B,OAAO,UAAC,OAAO;QACb,IAAM,OAAO,GAAG,eAAe,EAAE,CAAC;QAClC,OAAO,CAAC,UAAU,CAAC,OAAO,GAAG,UAAC,EAAuB;gBAArB,SAAS,eAAA,EAAE,QAAQ,cAAA;YAAO,OAAA,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC;QAA5B,CAA4B,CAAC;QAEvF,OAAO,UAAC,GAAG,IAAK,OAAA,CAAC;YACf,WAAW,YAAC,SAAS,EAAE,QAAQ;gBAC7B,OAAO;oBACL,IAAI,EAAE,SAAS;oBACf,SAAS,WAAA;oBACT,QAAQ,UAAA;iBACT,CAAC;YACJ,CAAC;YACD,gBAAgB,EAAE,eAAe,CAAC,GAAG,EAAE,QAAQ,CAAC;SACjD,CAAC,EATc,CASd,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
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"}
@@ -1,5 +1,4 @@
1
- import type { PiletApi } from 'piral-core';
2
- export declare function createExtension(api: PiletApi, rootName?: string): {
1
+ export declare function createExtension(rootName: string): {
3
2
  oncreate(vnode: any): void;
4
3
  view(): any;
5
4
  };
package/esm/extension.js CHANGED
@@ -1,11 +1,16 @@
1
- import * as m from 'mithril';
2
- export function createExtension(api, rootName) {
3
- if (rootName === void 0) { rootName = 'slot'; }
1
+ import { m } from 'mithril';
2
+ export function createExtension(rootName) {
4
3
  return {
5
- oncreate: function (vnode) {
6
- api.renderHtmlExtension(vnode.dom, vnode.attrs);
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
+ }));
7
12
  },
8
- view: function () {
13
+ view() {
9
14
  return m(rootName);
10
15
  },
11
16
  };
@@ -1 +1 @@
1
- {"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAG7B,MAAM,UAAU,eAAe,CAAC,GAAa,EAAE,QAAiB;IAAjB,yBAAA,EAAA,iBAAiB;IAC9D,OAAO;QACL,QAAQ,YAAC,KAAK;YACZ,GAAG,CAAC,mBAAmB,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;QAClD,CAAC;QACD,IAAI;YACF,OAAO,CAAC,CAAC,QAAQ,CAAC,CAAC;QACrB,CAAC;KACF,CAAC;AACJ,CAAC"}
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/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ForeignComponent, ExtensionSlotProps } from 'piral-core';
1
+ import type { ForeignComponent, ExtensionSlotProps } from 'piral-core';
2
2
  declare module 'piral-core/lib/types/custom' {
3
3
  interface PiletCustomApi extends PiletMithrilApi {
4
4
  }
@@ -1,3 +1,16 @@
1
- import { ForeignComponent, BaseComponentProps } from 'piral-core';
2
- import { Component } from './types';
3
- export declare function createConverter(): <TProps extends BaseComponentProps>(component: Component<TProps>, captured?: Record<string, any>) => ForeignComponent<TProps>;
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
- var tslib_1 = require("tslib");
5
- var m = require("mithril");
6
- function createConverter() {
7
- var convert = function (component, captured) {
8
- return {
9
- mount: function (el, props, ctx) {
10
- m.mount(el, {
11
- view: function () {
12
- return m(component, tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, captured), ctx), props));
13
- },
14
- });
15
- },
16
- update: function (el, props, ctx) {
17
- m.mount(el, {
18
- view: function () {
19
- return m(component, tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, captured), ctx), props));
20
- },
21
- });
22
- },
23
- unmount: function (el) {
24
- // tslint:disable-next-line:no-null-keyword
25
- m.mount(el, null);
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;
@@ -1 +1 @@
1
- {"version":3,"file":"converter.js","sourceRoot":"","sources":["../src/converter.ts"],"names":[],"mappings":";;;;AAAA,2BAA6B;AAI7B,SAAgB,eAAe;IAC7B,IAAM,OAAO,GAAG,UACd,SAA4B,EAC5B,QAA8B;QAE9B,OAAO;YACL,KAAK,YAAC,EAAE,EAAE,KAAK,EAAE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AAC,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
- 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 integrating Mithril.js.
8
7
  */
9
- function createMithrilApi(config) {
10
- if (config === void 0) { config = {}; }
11
- var rootName = config.rootName;
12
- return function (context) {
13
- var convert = converter_1.createConverter();
14
- context.converters.mithril = function (_a) {
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: component,
23
- captured: captured,
16
+ component,
17
+ captured,
24
18
  };
25
19
  },
26
- MithrilExtension: extension_1.createExtension(api, rootName),
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,yCAA8C;AAC9C,yCAA8C;AAc9C;;GAEG;AACH,SAAgB,gBAAgB,CAAC,MAA0B;IAA1B,uBAAA,EAAA,WAA0B;IACjD,IAAA,QAAQ,GAAK,MAAM,SAAX,CAAY;IAE5B,OAAO,UAAC,OAAO;QACb,IAAM,OAAO,GAAG,2BAAe,EAAE,CAAC;QAClC,OAAO,CAAC,UAAU,CAAC,OAAO,GAAG,UAAC,EAAuB;gBAArB,SAAS,eAAA,EAAE,QAAQ,cAAA;YAAO,OAAA,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC;QAA5B,CAA4B,CAAC;QAEvF,OAAO,UAAC,GAAG,IAAK,OAAA,CAAC;YACf,WAAW,YAAC,SAAS,EAAE,QAAQ;gBAC7B,OAAO;oBACL,IAAI,EAAE,SAAS;oBACf,SAAS,WAAA;oBACT,QAAQ,UAAA;iBACT,CAAC;YACJ,CAAC;YACD,gBAAgB,EAAE,2BAAe,CAAC,GAAG,EAAE,QAAQ,CAAC;SACjD,CAAC,EATc,CASd,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAlBD,4CAkBC"}
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"}
@@ -1,5 +1,4 @@
1
- import type { PiletApi } from 'piral-core';
2
- export declare function createExtension(api: PiletApi, rootName?: string): {
1
+ export declare function createExtension(rootName: string): {
3
2
  oncreate(vnode: any): void;
4
3
  view(): any;
5
4
  };
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
- var m = require("mithril");
5
- function createExtension(api, rootName) {
6
- if (rootName === void 0) { rootName = 'slot'; }
4
+ const mithril_1 = require("mithril");
5
+ function createExtension(rootName) {
7
6
  return {
8
- oncreate: function (vnode) {
9
- api.renderHtmlExtension(vnode.dom, vnode.attrs);
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: function () {
12
- return m(rootName);
16
+ view() {
17
+ return (0, mithril_1.m)(rootName);
13
18
  },
14
19
  };
15
20
  }
@@ -1 +1 @@
1
- {"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":";;;AAAA,2BAA6B;AAG7B,SAAgB,eAAe,CAAC,GAAa,EAAE,QAAiB;IAAjB,yBAAA,EAAA,iBAAiB;IAC9D,OAAO;QACL,QAAQ,YAAC,KAAK;YACZ,GAAG,CAAC,mBAAmB,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;QAClD,CAAC;QACD,IAAI;YACF,OAAO,CAAC,CAAC,QAAQ,CAAC,CAAC;QACrB,CAAC;KACF,CAAC;AACJ,CAAC;AATD,0CASC"}
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
- 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/lib/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ForeignComponent, ExtensionSlotProps } from 'piral-core';
1
+ import type { ForeignComponent, ExtensionSlotProps } from 'piral-core';
2
2
  declare module 'piral-core/lib/types/custom' {
3
3
  interface PiletCustomApi extends PiletMithrilApi {
4
4
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "piral-mithril",
3
- "version": "1.0.0-pre.2108",
3
+ "version": "1.0.1-beta.5640",
4
4
  "description": "Plugin for integrating Mithril.js components in Piral.",
5
5
  "keywords": [
6
6
  "piral",
@@ -19,13 +19,32 @@
19
19
  "module": "esm/index.js",
20
20
  "main": "lib/index.js",
21
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
+ },
22
42
  "sideEffects": false,
23
43
  "files": [
24
44
  "esm",
25
45
  "lib",
26
46
  "src",
27
47
  "convert.d.ts",
28
- "convert.ts",
29
48
  "convert.js"
30
49
  ],
31
50
  "repository": {
@@ -36,8 +55,9 @@
36
55
  "url": "https://github.com/smapiot/piral/issues"
37
56
  },
38
57
  "scripts": {
58
+ "cleanup": "rimraf esm lib convert.d.ts convert.js",
39
59
  "build": "yarn build:commonjs && yarn build:esnext && yarn build:convert",
40
- "build:convert": "tsc convert.ts --skipLibCheck --declaration",
60
+ "build:convert": "tsc convert.ts --skipLibCheck --declaration --module esnext",
41
61
  "build:commonjs": "tsc --project tsconfig.json --outDir lib --module commonjs",
42
62
  "build:esnext": "tsc --project tsconfig.json --outDir esm --module esnext",
43
63
  "typedoc": "typedoc --json ../../../docs/types/piral-mithril.json src --exclude \"src/**/*.test.*\"",
@@ -45,11 +65,7 @@
45
65
  },
46
66
  "devDependencies": {
47
67
  "mithril": "2.0.4",
48
- "piral-core": "^1.0.0-pre.2108"
49
- },
50
- "peerDependencies": {
51
- "mithril": "^2.0.0",
52
- "piral-core": "1.x"
68
+ "piral-core": "1.0.1-beta.5640"
53
69
  },
54
- "gitHead": "ef3c6274568822db4b8ccc95297254d05b0c7c0c"
70
+ "gitHead": "fa0a72b28fd0a20afec7ef491ec19e93c090fc72"
55
71
  }
package/src/converter.ts CHANGED
@@ -1,39 +1,48 @@
1
- import * as m from 'mithril';
2
- import { ForeignComponent, BaseComponentProps } from 'piral-core';
3
- import { Component } from './types';
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 function createConverter() {
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
- return {
11
- mount(el, props, ctx) {
12
- m.mount(el, {
13
- view: () =>
14
- m(component, {
15
- ...captured,
16
- ...ctx,
17
- ...props,
18
- }),
19
- });
20
- },
21
- update(el, props, ctx) {
22
- m.mount(el, {
23
- view: () =>
24
- m(component, {
25
- ...captured,
26
- ...ctx,
27
- ...props,
28
- }),
29
- });
30
- },
31
- unmount(el) {
32
- // tslint:disable-next-line:no-null-keyword
33
- m.mount(el, null);
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 (api) => ({
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: createExtension(api, rootName),
36
- });
26
+ MithrilExtension: convert.Extension,
27
+ };
37
28
  };
38
29
  }
package/src/extension.ts CHANGED
@@ -1,10 +1,17 @@
1
- import * as m from 'mithril';
2
- import type { PiletApi } from 'piral-core';
1
+ import { m } from 'mithril';
3
2
 
4
- export function createExtension(api: PiletApi, rootName = 'slot') {
3
+ export function createExtension(rootName: string) {
5
4
  return {
6
5
  oncreate(vnode) {
7
- api.renderHtmlExtension(vnode.dom, vnode.attrs);
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
@@ -1,4 +1,4 @@
1
- import { ForeignComponent, ExtensionSlotProps } from 'piral-core';
1
+ import type { ForeignComponent, ExtensionSlotProps } from 'piral-core';
2
2
 
3
3
  declare module 'piral-core/lib/types/custom' {
4
4
  interface PiletCustomApi extends PiletMithrilApi {}
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;