piral-hyperapp 1.0.0-pre.2137 → 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 +16 -7
- package/convert.js +16 -11
- package/esm/converter.d.ts +13 -3
- package/esm/converter.js +13 -11
- package/esm/converter.js.map +1 -1
- package/esm/create.d.ts +2 -6
- package/esm/create.js +14 -22
- package/esm/create.js.map +1 -1
- package/esm/extension.d.ts +2 -2
- package/esm/extension.js +12 -9
- package/esm/extension.js.map +1 -1
- package/esm/mount.d.ts +1 -1
- package/esm/mount.js +2 -3
- package/esm/mount.js.map +1 -1
- package/esm/types.d.ts +1 -1
- package/lib/converter.d.ts +13 -3
- package/lib/converter.js +14 -12
- package/lib/converter.js.map +1 -1
- package/lib/create.d.ts +2 -6
- package/lib/create.js +15 -23
- package/lib/create.js.map +1 -1
- package/lib/extension.d.ts +2 -2
- package/lib/extension.js +13 -10
- package/lib/extension.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/mount.d.ts +1 -1
- package/lib/mount.js +2 -3
- package/lib/mount.js.map +1 -1
- package/lib/types.d.ts +1 -1
- package/package.json +26 -7
- package/src/converter.ts +23 -13
- package/src/create.ts +13 -24
- package/src/extension.ts +11 -3
- package/src/mount.ts +1 -1
- 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 Hyperapp](https://piral.io) · [](https://github.com/smapiot/piral/blob/
|
|
3
|
+
# [Piral Hyperapp](https://piral.io) · [](https://github.com/smapiot/piral/blob/main/LICENSE) [](https://www.npmjs.com/package/piral-hyperapp) [](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 `hyperapp`. What `piral-hyperapp` 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 Hyperapp converter for any component registration, as well as a `fromHyperapp` shortcut and a `HyperappExtension` component.
|
|
8
8
|
|
|
@@ -47,7 +47,7 @@ Alternatively, if `piral-hyperapp` has not been added to the Piral instance you
|
|
|
47
47
|
|
|
48
48
|
```ts
|
|
49
49
|
import { PiletApi } from '<name-of-piral-instance>';
|
|
50
|
-
import { fromHyperapp } from 'piral-hyperapp';
|
|
50
|
+
import { fromHyperapp } from 'piral-hyperapp/convert';
|
|
51
51
|
import { HyperappPage } from './HyperappPage';
|
|
52
52
|
|
|
53
53
|
export function setup(piral: PiletApi) {
|
|
@@ -62,7 +62,6 @@ export function setup(piral: PiletApi) {
|
|
|
62
62
|
Using Hyperapp with Piral is as simple as installing `piral-hyperapp` and `hyperapp`.
|
|
63
63
|
|
|
64
64
|
```ts
|
|
65
|
-
import 'hyperapp';
|
|
66
65
|
import { createHyperappApi } from 'piral-hyperapp';
|
|
67
66
|
```
|
|
68
67
|
|
|
@@ -80,10 +79,10 @@ The `hyperapp` package should be shared with the pilets via the *package.json*:
|
|
|
80
79
|
|
|
81
80
|
```json
|
|
82
81
|
{
|
|
83
|
-
"
|
|
84
|
-
"
|
|
85
|
-
"hyperapp"
|
|
86
|
-
|
|
82
|
+
"importmap": {
|
|
83
|
+
"imports": {
|
|
84
|
+
"hyperapp": ""
|
|
85
|
+
}
|
|
87
86
|
}
|
|
88
87
|
}
|
|
89
88
|
```
|
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 HyperappConverter {
|
|
5
|
-
(...params: Parameters<typeof
|
|
11
|
+
(...params: Parameters<ReturnType<typeof createConverter>>): HtmlComponent<any>;
|
|
6
12
|
}
|
|
7
|
-
export declare
|
|
8
|
-
|
|
9
|
-
|
|
13
|
+
export declare function createHyperappConverter(...params: Parameters<typeof createConverter>): {
|
|
14
|
+
from: HyperappConverter;
|
|
15
|
+
Extension: import("./esm/types").Component<any, {}, {}>;
|
|
16
|
+
};
|
|
17
|
+
declare const fromHyperapp: HyperappConverter, HyperExtension: import("./esm/types").Component<any, {}, {}>;
|
|
18
|
+
export { fromHyperapp, HyperExtension };
|
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 createHyperappConverter() {
|
|
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 (root, state, actions) { return ({
|
|
10
|
+
type: 'html',
|
|
11
|
+
component: convert(root, state, actions),
|
|
12
|
+
}); };
|
|
13
|
+
return { from: from, Extension: Extension };
|
|
14
|
+
}
|
|
15
|
+
var _a = createHyperappConverter(), fromHyperapp = _a.from, HyperExtension = _a.Extension;
|
|
16
|
+
export { fromHyperapp, HyperExtension };
|
package/esm/converter.d.ts
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
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 HyperappConverterOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Defines the name of the root element.
|
|
6
|
+
* @default piral-slot
|
|
7
|
+
*/
|
|
8
|
+
rootName?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function createConverter(config?: HyperappConverterOptions): {
|
|
11
|
+
<TProps extends BaseComponentProps>(root: Component<TProps, {}, {}>, state: any, actions: any): ForeignComponent<TProps>;
|
|
12
|
+
Extension: Component<import("piral-core").ExtensionSlotProps, {}, {}>;
|
|
13
|
+
};
|
package/esm/converter.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { mountHyperapp } from './mount';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
import { createExtension } from './extension';
|
|
3
|
+
export function createConverter(config = {}) {
|
|
4
|
+
const { rootName = 'piral-slot' } = config;
|
|
5
|
+
const Extension = createExtension(rootName);
|
|
6
|
+
const convert = (root, state, actions) => ({
|
|
7
|
+
mount(el, props, ctx) {
|
|
8
|
+
mountHyperapp(el, root, props, ctx, state, actions);
|
|
9
|
+
},
|
|
10
|
+
unmount(el) {
|
|
11
|
+
el.innerHTML = '';
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
convert.Extension = Extension;
|
|
13
15
|
return convert;
|
|
14
16
|
}
|
|
15
17
|
//# 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":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"converter.js","sourceRoot":"","sources":["../src/converter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAW9C,MAAM,UAAU,eAAe,CAAC,SAAmC,EAAE;IACnE,MAAM,EAAE,QAAQ,GAAG,YAAY,EAAE,GAAG,MAAM,CAAC;IAC3C,MAAM,SAAS,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC;IAC5C,MAAM,OAAO,GAAG,CACd,IAAuB,EACvB,KAAU,EACV,OAAY,EACc,EAAE,CAAC,CAAC;QAC9B,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,GAAG;YAClB,aAAa,CAAC,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;QACtD,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
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import type { PiralPlugin } from 'piral-core';
|
|
2
|
+
import { HyperappConverterOptions } from './converter';
|
|
2
3
|
import type { PiletHyperappApi } from './types';
|
|
3
4
|
/**
|
|
4
5
|
* Available configuration options for the Hyperapp plugin.
|
|
5
6
|
*/
|
|
6
|
-
export interface HyperappConfig {
|
|
7
|
-
/**
|
|
8
|
-
* Defines the name of the root element.
|
|
9
|
-
* @default slot
|
|
10
|
-
*/
|
|
11
|
-
rootName?: string;
|
|
7
|
+
export interface HyperappConfig extends HyperappConverterOptions {
|
|
12
8
|
}
|
|
13
9
|
/**
|
|
14
10
|
* Creates new Pilet API extensions for the Hyperapp integration.
|
package/esm/create.js
CHANGED
|
@@ -1,29 +1,21 @@
|
|
|
1
1
|
import { createConverter } from './converter';
|
|
2
|
-
import { createExtension } from './extension';
|
|
3
2
|
/**
|
|
4
3
|
* Creates new Pilet API extensions for the Hyperapp integration.
|
|
5
4
|
*/
|
|
6
|
-
export function createHyperappApi(config) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
root: root,
|
|
21
|
-
state: state,
|
|
22
|
-
actions: actions,
|
|
23
|
-
};
|
|
24
|
-
},
|
|
25
|
-
HyperappExtension: createExtension(api, rootName),
|
|
26
|
-
};
|
|
5
|
+
export function createHyperappApi(config = {}) {
|
|
6
|
+
return (context) => {
|
|
7
|
+
const convert = createConverter(config);
|
|
8
|
+
context.converters.hyperapp = ({ root, state, actions }) => convert(root, state, actions);
|
|
9
|
+
return {
|
|
10
|
+
fromHyperapp(root, state, actions) {
|
|
11
|
+
return {
|
|
12
|
+
type: 'hyperapp',
|
|
13
|
+
root,
|
|
14
|
+
state,
|
|
15
|
+
actions,
|
|
16
|
+
};
|
|
17
|
+
},
|
|
18
|
+
HyperappExtension: convert.Extension,
|
|
27
19
|
};
|
|
28
20
|
};
|
|
29
21
|
}
|
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,EAA4B,MAAM,aAAa,CAAC;AAQxE;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,SAAyB,EAAE;IAC3D,OAAO,CAAC,OAAO,EAAE,EAAE;QACjB,MAAM,OAAO,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;QACxC,OAAO,CAAC,UAAU,CAAC,QAAQ,GAAG,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;QAE1F,OAAO;YACL,YAAY,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO;gBAC/B,OAAO;oBACL,IAAI,EAAE,UAAU;oBAChB,IAAI;oBACJ,KAAK;oBACL,OAAO;iBACR,CAAC;YACJ,CAAC;YACD,iBAAiB,EAAE,OAAO,CAAC,SAAS;SACrC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
|
package/esm/extension.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ExtensionSlotProps } from 'piral-core';
|
|
2
2
|
import type { Component } from './types';
|
|
3
|
-
export declare function createExtension(
|
|
3
|
+
export declare function createExtension(rootName: string): Component<ExtensionSlotProps>;
|
package/esm/extension.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { createHyperappElement } from './mount';
|
|
2
|
-
export function createExtension(
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
export function createExtension(rootName) {
|
|
3
|
+
return (props) => createHyperappElement(rootName, {
|
|
4
|
+
oncreate(element) {
|
|
5
|
+
element.dispatchEvent(new CustomEvent('render-html', {
|
|
6
|
+
bubbles: true,
|
|
7
|
+
detail: {
|
|
8
|
+
target: element,
|
|
9
|
+
props,
|
|
10
|
+
},
|
|
11
|
+
}));
|
|
12
|
+
},
|
|
13
|
+
});
|
|
11
14
|
}
|
|
12
15
|
//# 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":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAGhD,MAAM,UAAU,eAAe,CAAC,
|
|
1
|
+
{"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAGhD,MAAM,UAAU,eAAe,CAAC,QAAgB;IAC9C,OAAO,CAAC,KAAK,EAAE,EAAE,CACf,qBAAqB,CAAC,QAAQ,EAAE;QAC9B,QAAQ,CAAC,OAAoB;YAC3B,OAAO,CAAC,aAAa,CACnB,IAAI,WAAW,CAAC,aAAa,EAAE;gBAC7B,OAAO,EAAE,IAAI;gBACb,MAAM,EAAE;oBACN,MAAM,EAAE,OAAO;oBACf,KAAK;iBACN;aACF,CAAC,CACH,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;AACP,CAAC"}
|
package/esm/mount.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Component } from './types';
|
|
1
|
+
import type { Component } from './types';
|
|
2
2
|
export declare function mountHyperapp<T extends Object>(el: HTMLElement, root: Component<T>, props: T, ctx: any, state: any, actions: any): void;
|
|
3
3
|
export declare function createHyperappElement(name: string, props: any): any;
|
package/esm/mount.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
var _a = require('hyperapp'), h = _a.h, app = _a.app;
|
|
1
|
+
const { h, app } = require('hyperapp');
|
|
3
2
|
export function mountHyperapp(el, root, props, ctx, state, actions) {
|
|
4
|
-
app(
|
|
3
|
+
app(Object.assign(Object.assign({}, ctx), state), actions, () => h(root, props), el);
|
|
5
4
|
}
|
|
6
5
|
export function createHyperappElement(name, props) {
|
|
7
6
|
return h(name, props, []);
|
package/esm/mount.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mount.js","sourceRoot":"","sources":["../src/mount.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mount.js","sourceRoot":"","sources":["../src/mount.ts"],"names":[],"mappings":"AAEA,MAAM,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAEvC,MAAM,UAAU,aAAa,CAC3B,EAAe,EACf,IAAkB,EAClB,KAAQ,EACR,GAAQ,EACR,KAAU,EACV,OAAY;IAEZ,GAAG,iCAEI,GAAG,GACH,KAAK,GAEV,OAAO,EACP,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EACpB,EAAE,CACH,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,IAAY,EAAE,KAAU;IAC5D,OAAO,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;AAC5B,CAAC"}
|
package/esm/types.d.ts
CHANGED
package/lib/converter.d.ts
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
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 HyperappConverterOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Defines the name of the root element.
|
|
6
|
+
* @default piral-slot
|
|
7
|
+
*/
|
|
8
|
+
rootName?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function createConverter(config?: HyperappConverterOptions): {
|
|
11
|
+
<TProps extends BaseComponentProps>(root: Component<TProps, {}, {}>, state: any, actions: any): ForeignComponent<TProps>;
|
|
12
|
+
Extension: Component<import("piral-core").ExtensionSlotProps, {}, {}>;
|
|
13
|
+
};
|
package/lib/converter.js
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createConverter = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
4
|
+
const mount_1 = require("./mount");
|
|
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 = (root, state, actions) => ({
|
|
10
|
+
mount(el, props, ctx) {
|
|
11
|
+
(0, mount_1.mountHyperapp)(el, root, props, ctx, state, actions);
|
|
12
|
+
},
|
|
13
|
+
unmount(el) {
|
|
14
|
+
el.innerHTML = '';
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
convert.Extension = Extension;
|
|
16
18
|
return convert;
|
|
17
19
|
}
|
|
18
20
|
exports.createConverter = createConverter;
|
package/lib/converter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"converter.js","sourceRoot":"","sources":["../src/converter.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"converter.js","sourceRoot":"","sources":["../src/converter.ts"],"names":[],"mappings":";;;AACA,mCAAwC;AACxC,2CAA8C;AAW9C,SAAgB,eAAe,CAAC,SAAmC,EAAE;IACnE,MAAM,EAAE,QAAQ,GAAG,YAAY,EAAE,GAAG,MAAM,CAAC;IAC3C,MAAM,SAAS,GAAG,IAAA,2BAAe,EAAC,QAAQ,CAAC,CAAC;IAC5C,MAAM,OAAO,GAAG,CACd,IAAuB,EACvB,KAAU,EACV,OAAY,EACc,EAAE,CAAC,CAAC;QAC9B,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,GAAG;YAClB,IAAA,qBAAa,EAAC,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;QACtD,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;AAjBD,0CAiBC"}
|
package/lib/create.d.ts
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import type { PiralPlugin } from 'piral-core';
|
|
2
|
+
import { HyperappConverterOptions } from './converter';
|
|
2
3
|
import type { PiletHyperappApi } from './types';
|
|
3
4
|
/**
|
|
4
5
|
* Available configuration options for the Hyperapp plugin.
|
|
5
6
|
*/
|
|
6
|
-
export interface HyperappConfig {
|
|
7
|
-
/**
|
|
8
|
-
* Defines the name of the root element.
|
|
9
|
-
* @default slot
|
|
10
|
-
*/
|
|
11
|
-
rootName?: string;
|
|
7
|
+
export interface HyperappConfig extends HyperappConverterOptions {
|
|
12
8
|
}
|
|
13
9
|
/**
|
|
14
10
|
* Creates new Pilet API extensions for the Hyperapp integration.
|
package/lib/create.js
CHANGED
|
@@ -1,32 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createHyperappApi = 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 the Hyperapp integration.
|
|
8
7
|
*/
|
|
9
|
-
function createHyperappApi(config) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
root: root,
|
|
24
|
-
state: state,
|
|
25
|
-
actions: actions,
|
|
26
|
-
};
|
|
27
|
-
},
|
|
28
|
-
HyperappExtension: extension_1.createExtension(api, rootName),
|
|
29
|
-
};
|
|
8
|
+
function createHyperappApi(config = {}) {
|
|
9
|
+
return (context) => {
|
|
10
|
+
const convert = (0, converter_1.createConverter)(config);
|
|
11
|
+
context.converters.hyperapp = ({ root, state, actions }) => convert(root, state, actions);
|
|
12
|
+
return {
|
|
13
|
+
fromHyperapp(root, state, actions) {
|
|
14
|
+
return {
|
|
15
|
+
type: 'hyperapp',
|
|
16
|
+
root,
|
|
17
|
+
state,
|
|
18
|
+
actions,
|
|
19
|
+
};
|
|
20
|
+
},
|
|
21
|
+
HyperappExtension: convert.Extension,
|
|
30
22
|
};
|
|
31
23
|
};
|
|
32
24
|
}
|
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,2CAAwE;AAQxE;;GAEG;AACH,SAAgB,iBAAiB,CAAC,SAAyB,EAAE;IAC3D,OAAO,CAAC,OAAO,EAAE,EAAE;QACjB,MAAM,OAAO,GAAG,IAAA,2BAAe,EAAC,MAAM,CAAC,CAAC;QACxC,OAAO,CAAC,UAAU,CAAC,QAAQ,GAAG,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;QAE1F,OAAO;YACL,YAAY,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO;gBAC/B,OAAO;oBACL,IAAI,EAAE,UAAU;oBAChB,IAAI;oBACJ,KAAK;oBACL,OAAO;iBACR,CAAC;YACJ,CAAC;YACD,iBAAiB,EAAE,OAAO,CAAC,SAAS;SACrC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAjBD,8CAiBC"}
|
package/lib/extension.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ExtensionSlotProps } from 'piral-core';
|
|
2
2
|
import type { Component } from './types';
|
|
3
|
-
export declare function createExtension(
|
|
3
|
+
export declare function createExtension(rootName: string): Component<ExtensionSlotProps>;
|
package/lib/extension.js
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createExtension = void 0;
|
|
4
|
-
|
|
5
|
-
function createExtension(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
4
|
+
const mount_1 = require("./mount");
|
|
5
|
+
function createExtension(rootName) {
|
|
6
|
+
return (props) => (0, mount_1.createHyperappElement)(rootName, {
|
|
7
|
+
oncreate(element) {
|
|
8
|
+
element.dispatchEvent(new CustomEvent('render-html', {
|
|
9
|
+
bubbles: true,
|
|
10
|
+
detail: {
|
|
11
|
+
target: element,
|
|
12
|
+
props,
|
|
13
|
+
},
|
|
14
|
+
}));
|
|
15
|
+
},
|
|
16
|
+
});
|
|
14
17
|
}
|
|
15
18
|
exports.createExtension = createExtension;
|
|
16
19
|
//# 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":";;;AACA,
|
|
1
|
+
{"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":";;;AACA,mCAAgD;AAGhD,SAAgB,eAAe,CAAC,QAAgB;IAC9C,OAAO,CAAC,KAAK,EAAE,EAAE,CACf,IAAA,6BAAqB,EAAC,QAAQ,EAAE;QAC9B,QAAQ,CAAC,OAAoB;YAC3B,OAAO,CAAC,aAAa,CACnB,IAAI,WAAW,CAAC,aAAa,EAAE;gBAC7B,OAAO,EAAE,IAAI;gBACb,MAAM,EAAE;oBACN,MAAM,EAAE,OAAO;oBACf,KAAK;iBACN;aACF,CAAC,CACH,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;AACP,CAAC;AAfD,0CAeC"}
|
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/mount.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Component } from './types';
|
|
1
|
+
import type { Component } from './types';
|
|
2
2
|
export declare function mountHyperapp<T extends Object>(el: HTMLElement, root: Component<T>, props: T, ctx: any, state: any, actions: any): void;
|
|
3
3
|
export declare function createHyperappElement(name: string, props: any): any;
|
package/lib/mount.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createHyperappElement = exports.mountHyperapp = void 0;
|
|
4
|
-
|
|
5
|
-
var _a = require('hyperapp'), h = _a.h, app = _a.app;
|
|
4
|
+
const { h, app } = require('hyperapp');
|
|
6
5
|
function mountHyperapp(el, root, props, ctx, state, actions) {
|
|
7
|
-
app(
|
|
6
|
+
app(Object.assign(Object.assign({}, ctx), state), actions, () => h(root, props), el);
|
|
8
7
|
}
|
|
9
8
|
exports.mountHyperapp = mountHyperapp;
|
|
10
9
|
function createHyperappElement(name, props) {
|
package/lib/mount.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mount.js","sourceRoot":"","sources":["../src/mount.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mount.js","sourceRoot":"","sources":["../src/mount.ts"],"names":[],"mappings":";;;AAEA,MAAM,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAEvC,SAAgB,aAAa,CAC3B,EAAe,EACf,IAAkB,EAClB,KAAQ,EACR,GAAQ,EACR,KAAU,EACV,OAAY;IAEZ,GAAG,iCAEI,GAAG,GACH,KAAK,GAEV,OAAO,EACP,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EACpB,EAAE,CACH,CAAC;AACJ,CAAC;AAjBD,sCAiBC;AAED,SAAgB,qBAAqB,CAAC,IAAY,EAAE,KAAU;IAC5D,OAAO,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;AAC5B,CAAC;AAFD,sDAEC"}
|
package/lib/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "piral-hyperapp",
|
|
3
|
-
"version": "1.0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Plugin for integrating hyperapp 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-hyperapp.json src --exclude \"src/**/*.test.*\"",
|
|
@@ -45,11 +65,10 @@
|
|
|
45
65
|
},
|
|
46
66
|
"devDependencies": {
|
|
47
67
|
"hyperapp": "^1.2.10",
|
|
48
|
-
"piral-core": "^1.0.0
|
|
68
|
+
"piral-core": "^1.0.0"
|
|
49
69
|
},
|
|
50
70
|
"peerDependencies": {
|
|
51
|
-
"hyperapp": "^1.0.0"
|
|
52
|
-
"piral-core": "1.x"
|
|
71
|
+
"hyperapp": "^1.0.0"
|
|
53
72
|
},
|
|
54
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "67d9a2920bd5231baf10bc87ae8985666b18fa3a"
|
|
55
74
|
}
|
package/src/converter.ts
CHANGED
|
@@ -1,21 +1,31 @@
|
|
|
1
|
-
import { ForeignComponent, BaseComponentProps } from 'piral-core';
|
|
1
|
+
import type { ForeignComponent, BaseComponentProps } from 'piral-core';
|
|
2
2
|
import { mountHyperapp } from './mount';
|
|
3
|
-
import {
|
|
3
|
+
import { createExtension } from './extension';
|
|
4
|
+
import type { Component } from './types';
|
|
4
5
|
|
|
5
|
-
export
|
|
6
|
+
export interface HyperappConverterOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Defines the name of the root element.
|
|
9
|
+
* @default piral-slot
|
|
10
|
+
*/
|
|
11
|
+
rootName?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function createConverter(config: HyperappConverterOptions = {}) {
|
|
15
|
+
const { rootName = 'piral-slot' } = config;
|
|
16
|
+
const Extension = createExtension(rootName);
|
|
6
17
|
const convert = <TProps extends BaseComponentProps>(
|
|
7
18
|
root: Component<TProps>,
|
|
8
19
|
state: any,
|
|
9
20
|
actions: any,
|
|
10
|
-
): ForeignComponent<TProps> => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
21
|
+
): ForeignComponent<TProps> => ({
|
|
22
|
+
mount(el, props, ctx) {
|
|
23
|
+
mountHyperapp(el, root, props, ctx, state, actions);
|
|
24
|
+
},
|
|
25
|
+
unmount(el) {
|
|
26
|
+
el.innerHTML = '';
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
convert.Extension = Extension;
|
|
20
30
|
return convert;
|
|
21
31
|
}
|
package/src/create.ts
CHANGED
|
@@ -1,41 +1,30 @@
|
|
|
1
1
|
import type { PiralPlugin } from 'piral-core';
|
|
2
|
-
import { createConverter } from './converter';
|
|
3
|
-
import { createExtension } from './extension';
|
|
2
|
+
import { createConverter, HyperappConverterOptions } from './converter';
|
|
4
3
|
import type { PiletHyperappApi } from './types';
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* Available configuration options for the Hyperapp plugin.
|
|
8
7
|
*/
|
|
9
|
-
export interface HyperappConfig {
|
|
10
|
-
/**
|
|
11
|
-
* Defines the name of the root element.
|
|
12
|
-
* @default slot
|
|
13
|
-
*/
|
|
14
|
-
rootName?: string;
|
|
15
|
-
}
|
|
8
|
+
export interface HyperappConfig extends HyperappConverterOptions {}
|
|
16
9
|
|
|
17
10
|
/**
|
|
18
11
|
* Creates new Pilet API extensions for the Hyperapp integration.
|
|
19
12
|
*/
|
|
20
13
|
export function createHyperappApi(config: HyperappConfig = {}): PiralPlugin<PiletHyperappApi> {
|
|
21
|
-
const { rootName } = config;
|
|
22
|
-
|
|
23
14
|
return (context) => {
|
|
24
|
-
const convert = createConverter();
|
|
15
|
+
const convert = createConverter(config);
|
|
25
16
|
context.converters.hyperapp = ({ root, state, actions }) => convert(root, state, actions);
|
|
26
17
|
|
|
27
|
-
return
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
HyperappExtension: createExtension(api, rootName),
|
|
38
|
-
};
|
|
18
|
+
return {
|
|
19
|
+
fromHyperapp(root, state, actions) {
|
|
20
|
+
return {
|
|
21
|
+
type: 'hyperapp',
|
|
22
|
+
root,
|
|
23
|
+
state,
|
|
24
|
+
actions,
|
|
25
|
+
};
|
|
26
|
+
},
|
|
27
|
+
HyperappExtension: convert.Extension,
|
|
39
28
|
};
|
|
40
29
|
};
|
|
41
30
|
}
|
package/src/extension.ts
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ExtensionSlotProps } from 'piral-core';
|
|
2
2
|
import { createHyperappElement } from './mount';
|
|
3
3
|
import type { Component } from './types';
|
|
4
4
|
|
|
5
|
-
export function createExtension(
|
|
5
|
+
export function createExtension(rootName: string): Component<ExtensionSlotProps> {
|
|
6
6
|
return (props) =>
|
|
7
7
|
createHyperappElement(rootName, {
|
|
8
8
|
oncreate(element: HTMLElement) {
|
|
9
|
-
|
|
9
|
+
element.dispatchEvent(
|
|
10
|
+
new CustomEvent('render-html', {
|
|
11
|
+
bubbles: true,
|
|
12
|
+
detail: {
|
|
13
|
+
target: element,
|
|
14
|
+
props,
|
|
15
|
+
},
|
|
16
|
+
}),
|
|
17
|
+
);
|
|
10
18
|
},
|
|
11
19
|
});
|
|
12
20
|
}
|
package/src/mount.ts
CHANGED
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 HyperappConverter {
|
|
8
|
-
(...params: Parameters<typeof convert>): HtmlComponent<any>;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export const fromHyperapp: HyperappConverter = (root, state, actions) => ({
|
|
12
|
-
type: 'html',
|
|
13
|
-
component: convert(root, state, actions),
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
export const createHyperappExtension = createExtension;
|