piral-hyperapp 1.0.0-pre.2087 → 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 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 Hyperapp](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-hyperapp.svg?style=flat)](https://www.npmjs.com/package/piral-hyperapp) [![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 Hyperapp](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-hyperapp.svg?style=flat)](https://www.npmjs.com/package/piral-hyperapp) [![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-hyperapp` 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 `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
- "pilets": {
84
- "externals": [
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 type { HtmlComponent } from 'piral-core';
2
- import { createExtension } from './lib/extension';
3
- declare const convert: <TProps extends import("piral-core").BaseComponentProps>(root: import("./lib/types").Component<TProps, {}, {}>, state: any, actions: 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 HyperappConverter {
5
- (...params: Parameters<typeof convert>): HtmlComponent<any>;
11
+ (...params: Parameters<ReturnType<typeof createConverter>>): HtmlComponent<any>;
6
12
  }
7
- export declare const fromHyperapp: HyperappConverter;
8
- export declare const createHyperappExtension: typeof createExtension;
9
- export {};
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
- "use strict";
2
- exports.__esModule = true;
3
- exports.createHyperappExtension = exports.fromHyperapp = void 0;
4
- var converter_1 = require("./lib/converter");
5
- var extension_1 = require("./lib/extension");
6
- var convert = converter_1.createConverter();
7
- exports.fromHyperapp = function (root, state, actions) { return ({
8
- type: 'html',
9
- component: convert(root, state, actions)
10
- }); };
11
- exports.createHyperappExtension = extension_1.createExtension;
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 };
@@ -0,0 +1,13 @@
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
+ };
@@ -0,0 +1,17 @@
1
+ import { mountHyperapp } from './mount';
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;
15
+ return convert;
16
+ }
17
+ //# sourceMappingURL=converter.js.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,12 @@
1
+ import type { PiralPlugin } from 'piral-core';
2
+ import { HyperappConverterOptions } from './converter';
3
+ import type { PiletHyperappApi } from './types';
4
+ /**
5
+ * Available configuration options for the Hyperapp plugin.
6
+ */
7
+ export interface HyperappConfig extends HyperappConverterOptions {
8
+ }
9
+ /**
10
+ * Creates new Pilet API extensions for the Hyperapp integration.
11
+ */
12
+ export declare function createHyperappApi(config?: HyperappConfig): PiralPlugin<PiletHyperappApi>;
package/esm/create.js ADDED
@@ -0,0 +1,22 @@
1
+ import { createConverter } from './converter';
2
+ /**
3
+ * Creates new Pilet API extensions for the Hyperapp integration.
4
+ */
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,
19
+ };
20
+ };
21
+ }
22
+ //# sourceMappingURL=create.js.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,3 @@
1
+ import type { ExtensionSlotProps } from 'piral-core';
2
+ import type { Component } from './types';
3
+ export declare function createExtension(rootName: string): Component<ExtensionSlotProps>;
@@ -0,0 +1,15 @@
1
+ import { createHyperappElement } from './mount';
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
+ });
14
+ }
15
+ //# sourceMappingURL=extension.js.map
@@ -0,0 +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,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/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './create';
2
+ export * from './types';
package/esm/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from './create';
2
+ export * from './types';
3
+ //# sourceMappingURL=index.js.map
@@ -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/mount.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import type { Component } from './types';
2
+ export declare function mountHyperapp<T extends Object>(el: HTMLElement, root: Component<T>, props: T, ctx: any, state: any, actions: any): void;
3
+ export declare function createHyperappElement(name: string, props: any): any;
package/esm/mount.js ADDED
@@ -0,0 +1,8 @@
1
+ const { h, app } = require('hyperapp');
2
+ export function mountHyperapp(el, root, props, ctx, state, actions) {
3
+ app(Object.assign(Object.assign({}, ctx), state), actions, () => h(root, props), el);
4
+ }
5
+ export function createHyperappElement(name, props) {
6
+ return h(name, props, []);
7
+ }
8
+ //# sourceMappingURL=mount.js.map
@@ -0,0 +1 @@
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 ADDED
@@ -0,0 +1,68 @@
1
+ import type { ForeignComponent, ExtensionSlotProps } from 'piral-core';
2
+ declare module 'piral-core/lib/types/custom' {
3
+ interface PiletCustomApi extends PiletHyperappApi {
4
+ }
5
+ interface PiralCustomComponentConverters<TProps> {
6
+ hyperapp(component: HyperappComponent<TProps>): ForeignComponent<TProps>;
7
+ }
8
+ }
9
+ export interface HyperappComponent<TProps> {
10
+ /**
11
+ * The component root.
12
+ */
13
+ root: Component<TProps>;
14
+ /**
15
+ * The local state of the component.
16
+ */
17
+ state: any;
18
+ /**
19
+ * The actions of the component.
20
+ */
21
+ actions: any;
22
+ /**
23
+ * The type of the Hyperapp component.
24
+ */
25
+ type: 'hyperapp';
26
+ }
27
+ /**
28
+ * The view function describes the application UI as a tree of VNodes.
29
+ * @returns A VNode tree.
30
+ * @memberOf [App]
31
+ */
32
+ export interface View<State, Actions> {
33
+ (state: State, actions: Actions): VNode<object> | null;
34
+ }
35
+ /**
36
+ * The VDOM representation of an Element.
37
+ * @memberOf [VDOM]
38
+ */
39
+ export interface VNode<Attributes = {}> {
40
+ nodeName: string;
41
+ attributes?: Attributes;
42
+ children: Array<VNode | string>;
43
+ key: string | number | null;
44
+ }
45
+ /**
46
+ * A Component is a function that returns a custom VNode or View.
47
+ * @memberOf [VDOM]
48
+ */
49
+ export interface Component<Attributes = {}, State = {}, Actions = {}> {
50
+ (attributes: Attributes, children?: Array<VNode | string>): VNode<Attributes> | View<State, Actions>;
51
+ }
52
+ /**
53
+ * Defines the provided set of the Hyperapp plugin.
54
+ */
55
+ export interface PiletHyperappApi {
56
+ /**
57
+ * Wraps a Hyperapp component for use in Piral.
58
+ * @param component The component root.
59
+ * @param state The local state of the component.
60
+ * @param actions The actions available to the component.
61
+ * @returns The Piral Hyperapp component.
62
+ */
63
+ fromHyperapp<TProps>(component: Component<TProps>, state?: any, actions?: any): HyperappComponent<TProps>;
64
+ /**
65
+ * Hyperapp component for displaying extensions of the given name.
66
+ */
67
+ HyperappExtension: Component<ExtensionSlotProps>;
68
+ }
package/esm/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -1,3 +1,13 @@
1
- import { ForeignComponent, BaseComponentProps } from 'piral-core';
2
- import { Component } from './types';
3
- export declare function createConverter(): <TProps extends BaseComponentProps>(root: Component<TProps, {}, {}>, state: any, actions: any) => ForeignComponent<TProps>;
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
- var mount_1 = require("./mount");
5
- function createConverter() {
6
- var convert = function (root, state, actions) {
7
- return {
8
- mount: function (el, props, ctx) {
9
- mount_1.mountHyperapp(el, root, props, ctx, state, actions);
10
- },
11
- unmount: function (el) {
12
- el.innerHTML = '';
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;
@@ -1 +1 @@
1
- {"version":3,"file":"converter.js","sourceRoot":"","sources":["../src/converter.ts"],"names":[],"mappings":";;;AACA,iCAAwC;AAGxC,SAAgB,eAAe;IAC7B,IAAM,OAAO,GAAG,UACd,IAAuB,EACvB,KAAU,EACV,OAAY;QAEZ,OAAO;YACL,KAAK,YAAC,EAAE,EAAE,KAAK,EAAE,GAAG;gBAClB,qBAAa,CAAC,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;YACtD,CAAC;YACD,OAAO,YAAC,EAAE;gBACR,EAAE,CAAC,SAAS,GAAG,EAAE,CAAC;YACpB,CAAC;SACF,CAAC;IACJ,CAAC,CAAC;IACF,OAAO,OAAO,CAAC;AACjB,CAAC;AAhBD,0CAgBC"}
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
- 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 the Hyperapp integration.
8
7
  */
9
- function createHyperappApi(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.hyperapp = function (_a) {
15
- var root = _a.root, state = _a.state, actions = _a.actions;
16
- return convert(root, state, actions);
17
- };
18
- return function (api) {
19
- return {
20
- fromHyperapp: function (root, state, actions) {
21
- return {
22
- type: 'hyperapp',
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,yCAA8C;AAC9C,yCAA8C;AAc9C;;GAEG;AACH,SAAgB,iBAAiB,CAAC,MAA2B;IAA3B,uBAAA,EAAA,WAA2B;IACnD,IAAA,QAAQ,GAAK,MAAM,SAAX,CAAY;IAE5B,OAAO,UAAC,OAAO;QACb,IAAM,OAAO,GAAG,2BAAe,EAAE,CAAC;QAClC,OAAO,CAAC,UAAU,CAAC,QAAQ,GAAG,UAAC,EAAwB;gBAAtB,IAAI,UAAA,EAAE,KAAK,WAAA,EAAE,OAAO,aAAA;YAAO,OAAA,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC;QAA7B,CAA6B,CAAC;QAE1F,OAAO,UAAC,GAAG;YACT,OAAO;gBACL,YAAY,YAAC,IAAI,EAAE,KAAK,EAAE,OAAO;oBAC/B,OAAO;wBACL,IAAI,EAAE,UAAU;wBAChB,IAAI,MAAA;wBACJ,KAAK,OAAA;wBACL,OAAO,SAAA;qBACR,CAAC;gBACJ,CAAC;gBACD,iBAAiB,EAAE,2BAAe,CAAC,GAAG,EAAE,QAAQ,CAAC;aAClD,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AArBD,8CAqBC"}
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"}
@@ -1,3 +1,3 @@
1
- import type { PiletApi, ExtensionSlotProps } from 'piral-core';
1
+ import type { ExtensionSlotProps } from 'piral-core';
2
2
  import type { Component } from './types';
3
- export declare function createExtension(api: PiletApi, rootName?: string): Component<ExtensionSlotProps>;
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
- var mount_1 = require("./mount");
5
- function createExtension(api, rootName) {
6
- if (rootName === void 0) { rootName = 'slot'; }
7
- return function (props) {
8
- return mount_1.createHyperappElement(rootName, {
9
- oncreate: function (element) {
10
- api.renderHtmlExtension(element, props);
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
@@ -1 +1 @@
1
- {"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":";;;AACA,iCAAgD;AAGhD,SAAgB,eAAe,CAAC,GAAa,EAAE,QAAiB;IAAjB,yBAAA,EAAA,iBAAiB;IAC9D,OAAO,UAAC,KAAK;QACX,OAAA,6BAAqB,CAAC,QAAQ,EAAE;YAC9B,QAAQ,EAAR,UAAS,OAAoB;gBAC3B,GAAG,CAAC,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;YAC1C,CAAC;SACF,CAAC;IAJF,CAIE,CAAC;AACP,CAAC;AAPD,0CAOC"}
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
- 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/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
- var tslib_1 = require("tslib");
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(tslib_1.__assign(tslib_1.__assign({}, ctx), state), actions, function () { return h(root, props); }, el);
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":";;;;AAEM,IAAA,KAAa,OAAO,CAAC,UAAU,CAAC,EAA9B,CAAC,OAAA,EAAE,GAAG,SAAwB,CAAC;AAEvC,SAAgB,aAAa,CAC3B,EAAe,EACf,IAAkB,EAClB,KAAQ,EACR,GAAQ,EACR,KAAU,EACV,OAAY;IAEZ,GAAG,uCAEI,GAAG,GACH,KAAK,GAEV,OAAO,EACP,cAAM,OAAA,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAd,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"}
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
@@ -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 PiletHyperappApi {
4
4
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "piral-hyperapp",
3
- "version": "1.0.0-pre.2087",
3
+ "version": "1.0.0",
4
4
  "description": "Plugin for integrating hyperapp 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
- "build": "tsc && tsc convert.ts --skipLibCheck --declaration",
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-hyperapp.json src --exclude \"src/**/*.test.*\"",
39
64
  "test": "echo \"Error: run tests from root\" && exit 1"
40
65
  },
41
66
  "devDependencies": {
42
67
  "hyperapp": "^1.2.10",
43
- "piral-core": "^1.0.0-pre.2087"
68
+ "piral-core": "^1.0.0"
44
69
  },
45
70
  "peerDependencies": {
46
- "hyperapp": "^1.0.0",
47
- "piral-core": "1.x"
71
+ "hyperapp": "^1.0.0"
48
72
  },
49
- "gitHead": "546f80e690b5dfadb22c29f488be448a26faa3e3"
73
+ "gitHead": "67d9a2920bd5231baf10bc87ae8985666b18fa3a"
50
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 { Component } from './types';
3
+ import { createExtension } from './extension';
4
+ import type { Component } from './types';
4
5
 
5
- export function createConverter() {
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
- return {
12
- mount(el, props, ctx) {
13
- mountHyperapp(el, root, props, ctx, state, actions);
14
- },
15
- unmount(el) {
16
- el.innerHTML = '';
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 (api) => {
28
- return {
29
- fromHyperapp(root, state, actions) {
30
- return {
31
- type: 'hyperapp',
32
- root,
33
- state,
34
- actions,
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 { PiletApi, ExtensionSlotProps } from 'piral-core';
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(api: PiletApi, rootName = 'slot'): Component<ExtensionSlotProps> {
5
+ export function createExtension(rootName: string): Component<ExtensionSlotProps> {
6
6
  return (props) =>
7
7
  createHyperappElement(rootName, {
8
8
  oncreate(element: HTMLElement) {
9
- api.renderHtmlExtension(element, props);
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
@@ -1,4 +1,4 @@
1
- import { Component } from './types';
1
+ import type { Component } from './types';
2
2
 
3
3
  const { h, app } = require('hyperapp');
4
4
 
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 PiletHyperappApi {}
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;