piral-riot 1.0.0-pre.2085 → 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 Riot](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-riot.svg?style=flat)](https://www.npmjs.com/package/piral-riot) [![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 Riot](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-riot.svg?style=flat)](https://www.npmjs.com/package/piral-riot) [![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-riot` 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 `riot`. What `piral-riot` 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 Riot.js converter for any component registration, as well as a `fromRiot` shortcut and a `RiotExtension` component.
8
8
 
@@ -48,7 +48,7 @@ Alternatively, if `piral-riot` has not been added to the Piral instance you can
48
48
 
49
49
  ```ts
50
50
  import { PiletApi } from '<name-of-piral-instance>';
51
- import { fromRiot, createRiotExtension } from 'piral-riot';
51
+ import { fromRiot, createRiotExtension } from 'piral-riot/convert';
52
52
  import { createRiotPage } from './page';
53
53
 
54
54
  export function setup(piral: PiletApi) {
@@ -62,10 +62,9 @@ export function setup(piral: PiletApi) {
62
62
 
63
63
  ::: summary: For Piral instance developers
64
64
 
65
- Using Riot.js with Piral is as simple as installing `piral-riot` and `riot`.
65
+ Using Riot.js with Piral is as simple as installing `piral-riot` and `riot@^4`.
66
66
 
67
67
  ```ts
68
- import 'riot';
69
68
  import { createRiotApi } from 'piral-riot';
70
69
  ```
71
70
 
@@ -83,10 +82,10 @@ The `riot` package should be shared with the pilets via the *package.json*:
83
82
 
84
83
  ```json
85
84
  {
86
- "pilets": {
87
- "externals": [
88
- "riot"
89
- ]
85
+ "importmap": {
86
+ "imports": {
87
+ "riot": ""
88
+ }
90
89
  }
91
90
  }
92
91
  ```
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>(component: import("riot").RiotComponentShell<TProps, object>, 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 RiotConverter {
5
- (...params: Parameters<typeof convert>): HtmlComponent<any>;
11
+ (...params: Parameters<ReturnType<typeof createConverter>>): HtmlComponent<any>;
6
12
  }
7
- export declare const fromRiot: RiotConverter;
8
- export declare const createRiotExtension: typeof createExtension;
9
- export {};
13
+ export declare function createRiotConverter(...params: Parameters<typeof createConverter>): {
14
+ from: RiotConverter;
15
+ Extension: Riot.RiotComponentShell<any, object>;
16
+ };
17
+ declare const fromRiot: RiotConverter, RiotExtension: Riot.RiotComponentShell<any, object>;
18
+ export { fromRiot, RiotExtension };
package/convert.js CHANGED
@@ -1,11 +1,16 @@
1
- "use strict";
2
- exports.__esModule = true;
3
- exports.createRiotExtension = exports.fromRiot = void 0;
4
- var converter_1 = require("./lib/converter");
5
- var extension_1 = require("./lib/extension");
6
- var convert = converter_1.createConverter();
7
- exports.fromRiot = function (component, captured) { return ({
8
- type: 'html',
9
- component: convert(component, captured)
10
- }); };
11
- exports.createRiotExtension = extension_1.createExtension;
1
+ import { createConverter } from './esm/converter';
2
+ export function createRiotConverter() {
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 = createRiotConverter(), fromRiot = _a.from, RiotExtension = _a.Extension;
16
+ export { fromRiot, RiotExtension };
@@ -0,0 +1,13 @@
1
+ import * as Riot from 'riot';
2
+ import type { ForeignComponent, BaseComponentProps } from 'piral-core';
3
+ export interface RiotConverterOptions {
4
+ /**
5
+ * Defines the name of the Riot extension element.
6
+ * @default riot-extension
7
+ */
8
+ extensionName?: string;
9
+ }
10
+ export declare function createConverter(config?: RiotConverterOptions): {
11
+ <TProps extends BaseComponentProps>(component: Riot.RiotComponentShell<TProps, object>, captured?: Record<string, any>): ForeignComponent<TProps>;
12
+ Extension: Riot.RiotComponentShell<import("piral-core").ExtensionSlotProps, object>;
13
+ };
@@ -0,0 +1,22 @@
1
+ import * as Riot from 'riot';
2
+ import { createExtension } from './extension';
3
+ export function createConverter(config = {}) {
4
+ const { extensionName = 'riot-extension' } = config;
5
+ const Extension = createExtension(extensionName);
6
+ const convert = (component, captured) => {
7
+ const mountApp = Riot.component(component);
8
+ return {
9
+ mount(el, props, ctx, locals) {
10
+ locals.app = mountApp(el, Object.assign(Object.assign(Object.assign({}, captured), ctx), props));
11
+ },
12
+ unmount(el, locals) {
13
+ locals.app.unmount(true);
14
+ el.innerHTML = '';
15
+ locals.app = undefined;
16
+ },
17
+ };
18
+ };
19
+ convert.Extension = Extension;
20
+ return convert;
21
+ }
22
+ //# sourceMappingURL=converter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"converter.js","sourceRoot":"","sources":["../src/converter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAc9C,MAAM,UAAU,eAAe,CAAC,SAA+B,EAAE;IAC/D,MAAM,EAAE,aAAa,GAAG,gBAAgB,EAAE,GAAG,MAAM,CAAC;IACpD,MAAM,SAAS,GAAG,eAAe,CAAC,aAAa,CAAC,CAAC;IACjD,MAAM,OAAO,GAAG,CACd,SAA0C,EAC1C,QAA8B,EACJ,EAAE;QAC5B,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QAE3C,OAAO;YACL,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,MAAyB;gBAC7C,MAAM,CAAC,GAAG,GAAG,QAAQ,CAAC,EAAE,gDACnB,QAAQ,GACR,GAAG,GACH,KAAK,EACR,CAAC;YACL,CAAC;YACD,OAAO,CAAC,EAAE,EAAE,MAAyB;gBACnC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;gBACzB,EAAE,CAAC,SAAS,GAAG,EAAE,CAAC;gBAClB,MAAM,CAAC,GAAG,GAAG,SAAS,CAAC;YACzB,CAAC;SACF,CAAC;IACJ,CAAC,CAAC;IACF,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;IAC9B,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { PiralPlugin } from 'piral-core';
2
+ import type { PiletRiotApi } from './types';
3
+ /**
4
+ * Available configuration options for the Riot.js plugin.
5
+ */
6
+ export interface RiotConfig {
7
+ }
8
+ /**
9
+ * Creates new Pilet API extensions for integrating Riot.js.
10
+ */
11
+ export declare function createRiotApi(config?: RiotConfig): PiralPlugin<PiletRiotApi>;
package/esm/create.js ADDED
@@ -0,0 +1,21 @@
1
+ import { createConverter } from './converter';
2
+ /**
3
+ * Creates new Pilet API extensions for integrating Riot.js.
4
+ */
5
+ export function createRiotApi(config = {}) {
6
+ return (context) => {
7
+ const convert = createConverter(config);
8
+ context.converters.riot = ({ component, captured }) => convert(component, captured);
9
+ return {
10
+ fromRiot(component, captured) {
11
+ return {
12
+ type: 'riot',
13
+ component,
14
+ captured,
15
+ };
16
+ },
17
+ RiotExtension: convert.Extension,
18
+ };
19
+ };
20
+ }
21
+ //# sourceMappingURL=create.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAQ9C;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,SAAqB,EAAE;IACnD,OAAO,CAAC,OAAO,EAAE,EAAE;QACjB,MAAM,OAAO,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;QACxC,OAAO,CAAC,UAAU,CAAC,IAAI,GAAG,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QAEpF,OAAO;YACL,QAAQ,CAAC,SAAS,EAAE,QAAQ;gBAC1B,OAAO;oBACL,IAAI,EAAE,MAAM;oBACZ,SAAS;oBACT,QAAQ;iBACT,CAAC;YACJ,CAAC;YACD,aAAa,EAAE,OAAO,CAAC,SAAS;SACjC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { ExtensionSlotProps } from 'piral-core';
2
+ import type { RiotComponentShell } from 'riot';
3
+ export declare function createExtension(extensionName: string): RiotComponentShell<ExtensionSlotProps>;
@@ -0,0 +1,33 @@
1
+ export function createExtension(extensionName) {
2
+ return {
3
+ name: extensionName,
4
+ template() {
5
+ const templateChunk = {
6
+ mount(element, scope) {
7
+ element.dispatchEvent(new CustomEvent('render-html', {
8
+ bubbles: true,
9
+ detail: {
10
+ target: element,
11
+ props: scope.props,
12
+ },
13
+ }));
14
+ return templateChunk;
15
+ },
16
+ update() {
17
+ return templateChunk;
18
+ },
19
+ unmount() {
20
+ return templateChunk;
21
+ },
22
+ createDOM() {
23
+ return templateChunk;
24
+ },
25
+ clone() {
26
+ return templateChunk;
27
+ },
28
+ };
29
+ return templateChunk;
30
+ },
31
+ };
32
+ }
33
+ //# sourceMappingURL=extension.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":"AAIA,MAAM,UAAU,eAAe,CAAC,aAAqB;IACnD,OAAO;QACL,IAAI,EAAE,aAAa;QACnB,QAAQ;YACN,MAAM,aAAa,GAAkB;gBACnC,KAAK,CAAC,OAAO,EAAE,KAAK;oBAClB,OAAO,CAAC,aAAa,CACnB,IAAI,WAAW,CAAC,aAAa,EAAE;wBAC7B,OAAO,EAAE,IAAI;wBACb,MAAM,EAAE;4BACN,MAAM,EAAE,OAAO;4BACf,KAAK,EAAE,KAAK,CAAC,KAAK;yBACnB;qBACF,CAAC,CACH,CAAC;oBACF,OAAO,aAAa,CAAC;gBACvB,CAAC;gBACD,MAAM;oBACJ,OAAO,aAAa,CAAC;gBACvB,CAAC;gBACD,OAAO;oBACL,OAAO,aAAa,CAAC;gBACvB,CAAC;gBACD,SAAS;oBACP,OAAO,aAAa,CAAC;gBACvB,CAAC;gBACD,KAAK;oBACH,OAAO,aAAa,CAAC;gBACvB,CAAC;aACF,CAAC;YACF,OAAO,aAAa,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,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/types.d.ts ADDED
@@ -0,0 +1,39 @@
1
+ import type { ForeignComponent, ExtensionSlotProps } from 'piral-core';
2
+ import type { RiotComponentShell } from 'riot';
3
+ declare module 'piral-core/lib/types/custom' {
4
+ interface PiletCustomApi extends PiletRiotApi {
5
+ }
6
+ interface PiralCustomComponentConverters<TProps> {
7
+ riot(component: RiotComponent<TProps>): ForeignComponent<TProps>;
8
+ }
9
+ }
10
+ export interface RiotComponent<TProps> {
11
+ /**
12
+ * The component.
13
+ */
14
+ component: RiotComponentShell<TProps>;
15
+ /**
16
+ * Captures props for transport into the Riot.js component.
17
+ */
18
+ captured?: Record<string, any>;
19
+ /**
20
+ * The type of the Riot.js component.
21
+ */
22
+ type: 'riot';
23
+ }
24
+ /**
25
+ * Defines the provided set of Riot.js Pilet API extensions.
26
+ */
27
+ export interface PiletRiotApi {
28
+ /**
29
+ * Wraps an Riot.js component for use in Piral.
30
+ * @param component The component root.
31
+ * @param captured The optionally captured props.
32
+ * @returns The Piral Riot.js component.
33
+ */
34
+ fromRiot<TProps>(component: RiotComponentShell<TProps>, captured?: Record<string, any>): RiotComponent<TProps>;
35
+ /**
36
+ * Riot.js component for displaying extensions of the given name.
37
+ */
38
+ RiotExtension: RiotComponentShell<ExtensionSlotProps>;
39
+ }
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
1
  import * as Riot from 'riot';
2
- import { ForeignComponent, BaseComponentProps } from 'piral-core';
3
- export declare function createConverter(): <TProps extends BaseComponentProps>(component: Riot.RiotComponentShell<TProps, object>, captured?: Record<string, any>) => ForeignComponent<TProps>;
2
+ import type { ForeignComponent, BaseComponentProps } from 'piral-core';
3
+ export interface RiotConverterOptions {
4
+ /**
5
+ * Defines the name of the Riot extension element.
6
+ * @default riot-extension
7
+ */
8
+ extensionName?: string;
9
+ }
10
+ export declare function createConverter(config?: RiotConverterOptions): {
11
+ <TProps extends BaseComponentProps>(component: Riot.RiotComponentShell<TProps, object>, captured?: Record<string, any>): ForeignComponent<TProps>;
12
+ Extension: Riot.RiotComponentShell<import("piral-core").ExtensionSlotProps, object>;
13
+ };
package/lib/converter.js CHANGED
@@ -1,22 +1,25 @@
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 Riot = require("riot");
6
- function createConverter() {
7
- var convert = function (component, captured) {
8
- var mountApp = Riot.component(component);
9
- var app = undefined;
4
+ const Riot = require("riot");
5
+ const extension_1 = require("./extension");
6
+ function createConverter(config = {}) {
7
+ const { extensionName = 'riot-extension' } = config;
8
+ const Extension = (0, extension_1.createExtension)(extensionName);
9
+ const convert = (component, captured) => {
10
+ const mountApp = Riot.component(component);
10
11
  return {
11
- mount: function (el, props, ctx) {
12
- app = mountApp(el, tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, captured), ctx), props));
12
+ mount(el, props, ctx, locals) {
13
+ locals.app = mountApp(el, Object.assign(Object.assign(Object.assign({}, captured), ctx), props));
13
14
  },
14
- unmount: function (el) {
15
- app.unmount(true);
15
+ unmount(el, locals) {
16
+ locals.app.unmount(true);
16
17
  el.innerHTML = '';
18
+ locals.app = undefined;
17
19
  },
18
20
  };
19
21
  };
22
+ convert.Extension = Extension;
20
23
  return convert;
21
24
  }
22
25
  exports.createConverter = createConverter;
@@ -1 +1 @@
1
- {"version":3,"file":"converter.js","sourceRoot":"","sources":["../src/converter.ts"],"names":[],"mappings":";;;;AAAA,2BAA6B;AAG7B,SAAgB,eAAe;IAC7B,IAAM,OAAO,GAAG,UACd,SAA0C,EAC1C,QAA8B;QAE9B,IAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QAC3C,IAAI,GAAG,GAA+B,SAAS,CAAC;QAEhD,OAAO;YACL,KAAK,YAAC,EAAE,EAAE,KAAK,EAAE,GAAG;gBAClB,GAAG,GAAG,QAAQ,CAAC,EAAE,yDACZ,QAAQ,GACR,GAAG,GACH,KAAK,EACR,CAAC;YACL,CAAC;YACD,OAAO,YAAC,EAAE;gBACR,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;gBAClB,EAAE,CAAC,SAAS,GAAG,EAAE,CAAC;YACpB,CAAC;SACF,CAAC;IACJ,CAAC,CAAC;IACF,OAAO,OAAO,CAAC;AACjB,CAAC;AAvBD,0CAuBC"}
1
+ {"version":3,"file":"converter.js","sourceRoot":"","sources":["../src/converter.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAE7B,2CAA8C;AAc9C,SAAgB,eAAe,CAAC,SAA+B,EAAE;IAC/D,MAAM,EAAE,aAAa,GAAG,gBAAgB,EAAE,GAAG,MAAM,CAAC;IACpD,MAAM,SAAS,GAAG,IAAA,2BAAe,EAAC,aAAa,CAAC,CAAC;IACjD,MAAM,OAAO,GAAG,CACd,SAA0C,EAC1C,QAA8B,EACJ,EAAE;QAC5B,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QAE3C,OAAO;YACL,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,MAAyB;gBAC7C,MAAM,CAAC,GAAG,GAAG,QAAQ,CAAC,EAAE,gDACnB,QAAQ,GACR,GAAG,GACH,KAAK,EACR,CAAC;YACL,CAAC;YACD,OAAO,CAAC,EAAE,EAAE,MAAyB;gBACnC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;gBACzB,EAAE,CAAC,SAAS,GAAG,EAAE,CAAC;gBAClB,MAAM,CAAC,GAAG,GAAG,SAAS,CAAC;YACzB,CAAC;SACF,CAAC;IACJ,CAAC,CAAC;IACF,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;IAC9B,OAAO,OAAO,CAAC;AACjB,CAAC;AA1BD,0CA0BC"}
package/lib/create.d.ts CHANGED
@@ -1,14 +1,9 @@
1
- import { PiralPlugin } from 'piral-core';
2
- import { PiletRiotApi } from './types';
1
+ import type { PiralPlugin } from 'piral-core';
2
+ import type { PiletRiotApi } from './types';
3
3
  /**
4
4
  * Available configuration options for the Riot.js plugin.
5
5
  */
6
6
  export interface RiotConfig {
7
- /**
8
- * Defines the name of the Riot extension element.
9
- * @default riot-extension
10
- */
11
- extensionName?: string;
12
7
  }
13
8
  /**
14
9
  * Creates new Pilet API extensions for integrating Riot.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.createRiotApi = 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 Riot.js.
8
7
  */
9
- function createRiotApi(config) {
10
- if (config === void 0) { config = {}; }
11
- var extensionName = config.extensionName;
12
- return function (context) {
13
- var convert = converter_1.createConverter();
14
- context.converters.riot = function (_a) {
15
- var component = _a.component, captured = _a.captured;
16
- return convert(component, captured);
17
- };
18
- return function (api) { return ({
19
- fromRiot: function (component, captured) {
8
+ function createRiotApi(config = {}) {
9
+ return (context) => {
10
+ const convert = (0, converter_1.createConverter)(config);
11
+ context.converters.riot = ({ component, captured }) => convert(component, captured);
12
+ return {
13
+ fromRiot(component, captured) {
20
14
  return {
21
15
  type: 'riot',
22
- component: component,
23
- captured: captured,
16
+ component,
17
+ captured,
24
18
  };
25
19
  },
26
- RiotExtension: extension_1.createExtension(api, extensionName),
27
- }); };
20
+ RiotExtension: convert.Extension,
21
+ };
28
22
  };
29
23
  }
30
24
  exports.createRiotApi = createRiotApi;
package/lib/create.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":";;;AACA,yCAA8C;AAE9C,yCAA8C;AAa9C;;GAEG;AACH,SAAgB,aAAa,CAAC,MAAuB;IAAvB,uBAAA,EAAA,WAAuB;IAC3C,IAAA,aAAa,GAAK,MAAM,cAAX,CAAY;IAEjC,OAAO,UAAC,OAAO;QACb,IAAM,OAAO,GAAG,2BAAe,EAAE,CAAC;QAClC,OAAO,CAAC,UAAU,CAAC,IAAI,GAAG,UAAC,EAAuB;gBAArB,SAAS,eAAA,EAAE,QAAQ,cAAA;YAAO,OAAA,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC;QAA5B,CAA4B,CAAC;QAEpF,OAAO,UAAC,GAAG,IAAK,OAAA,CAAC;YACf,QAAQ,YAAC,SAAS,EAAE,QAAQ;gBAC1B,OAAO;oBACL,IAAI,EAAE,MAAM;oBACZ,SAAS,WAAA;oBACT,QAAQ,UAAA;iBACT,CAAC;YACJ,CAAC;YACD,aAAa,EAAE,2BAAe,CAAC,GAAG,EAAE,aAAa,CAAC;SACnD,CAAC,EATc,CASd,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAlBD,sCAkBC"}
1
+ {"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":";;;AACA,2CAA8C;AAQ9C;;GAEG;AACH,SAAgB,aAAa,CAAC,SAAqB,EAAE;IACnD,OAAO,CAAC,OAAO,EAAE,EAAE;QACjB,MAAM,OAAO,GAAG,IAAA,2BAAe,EAAC,MAAM,CAAC,CAAC;QACxC,OAAO,CAAC,UAAU,CAAC,IAAI,GAAG,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QAEpF,OAAO;YACL,QAAQ,CAAC,SAAS,EAAE,QAAQ;gBAC1B,OAAO;oBACL,IAAI,EAAE,MAAM;oBACZ,SAAS;oBACT,QAAQ;iBACT,CAAC;YACJ,CAAC;YACD,aAAa,EAAE,OAAO,CAAC,SAAS;SACjC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAhBD,sCAgBC"}
@@ -1,3 +1,3 @@
1
- import type { PiletApi, ExtensionSlotProps } from 'piral-core';
1
+ import type { ExtensionSlotProps } from 'piral-core';
2
2
  import type { RiotComponentShell } from 'riot';
3
- export declare function createExtension(api: PiletApi, extensionName?: string): RiotComponentShell<ExtensionSlotProps>;
3
+ export declare function createExtension(extensionName: string): RiotComponentShell<ExtensionSlotProps>;
package/lib/extension.js CHANGED
@@ -1,26 +1,31 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createExtension = void 0;
4
- function createExtension(api, extensionName) {
5
- if (extensionName === void 0) { extensionName = 'riot-extension'; }
4
+ function createExtension(extensionName) {
6
5
  return {
7
6
  name: extensionName,
8
- template: function () {
9
- var templateChunk = {
10
- mount: function (element, scope) {
11
- api.renderHtmlExtension(element, scope.props);
7
+ template() {
8
+ const templateChunk = {
9
+ mount(element, scope) {
10
+ element.dispatchEvent(new CustomEvent('render-html', {
11
+ bubbles: true,
12
+ detail: {
13
+ target: element,
14
+ props: scope.props,
15
+ },
16
+ }));
12
17
  return templateChunk;
13
18
  },
14
- update: function () {
19
+ update() {
15
20
  return templateChunk;
16
21
  },
17
- unmount: function () {
22
+ unmount() {
18
23
  return templateChunk;
19
24
  },
20
- createDOM: function () {
25
+ createDOM() {
21
26
  return templateChunk;
22
27
  },
23
- clone: function () {
28
+ clone() {
24
29
  return templateChunk;
25
30
  },
26
31
  };
@@ -1 +1 @@
1
- {"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":";;;AAIA,SAAgB,eAAe,CAC7B,GAAa,EACb,aAAgC;IAAhC,8BAAA,EAAA,gCAAgC;IAEhC,OAAO;QACL,IAAI,EAAE,aAAa;QACnB,QAAQ,EAAR;YACE,IAAM,aAAa,GAAkB;gBACnC,KAAK,YAAC,OAAO,EAAE,KAAK;oBAClB,GAAG,CAAC,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;oBAC9C,OAAO,aAAa,CAAC;gBACvB,CAAC;gBACD,MAAM;oBACJ,OAAO,aAAa,CAAC;gBACvB,CAAC;gBACD,OAAO;oBACL,OAAO,aAAa,CAAC;gBACvB,CAAC;gBACD,SAAS;oBACP,OAAO,aAAa,CAAC;gBACvB,CAAC;gBACD,KAAK;oBACH,OAAO,aAAa,CAAC;gBACvB,CAAC;aACF,CAAC;YACF,OAAO,aAAa,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC;AA5BD,0CA4BC"}
1
+ {"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":";;;AAIA,SAAgB,eAAe,CAAC,aAAqB;IACnD,OAAO;QACL,IAAI,EAAE,aAAa;QACnB,QAAQ;YACN,MAAM,aAAa,GAAkB;gBACnC,KAAK,CAAC,OAAO,EAAE,KAAK;oBAClB,OAAO,CAAC,aAAa,CACnB,IAAI,WAAW,CAAC,aAAa,EAAE;wBAC7B,OAAO,EAAE,IAAI;wBACb,MAAM,EAAE;4BACN,MAAM,EAAE,OAAO;4BACf,KAAK,EAAE,KAAK,CAAC,KAAK;yBACnB;qBACF,CAAC,CACH,CAAC;oBACF,OAAO,aAAa,CAAC;gBACvB,CAAC;gBACD,MAAM;oBACJ,OAAO,aAAa,CAAC;gBACvB,CAAC;gBACD,OAAO;oBACL,OAAO,aAAa,CAAC;gBACvB,CAAC;gBACD,SAAS;oBACP,OAAO,aAAa,CAAC;gBACvB,CAAC;gBACD,KAAK;oBACH,OAAO,aAAa,CAAC;gBACvB,CAAC;aACF,CAAC;YACF,OAAO,aAAa,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC;AAjCD,0CAiCC"}
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,5 +1,5 @@
1
- import { ForeignComponent, ExtensionSlotProps } from 'piral-core';
2
- import { RiotComponentShell } from 'riot';
1
+ import type { ForeignComponent, ExtensionSlotProps } from 'piral-core';
2
+ import type { RiotComponentShell } from 'riot';
3
3
  declare module 'piral-core/lib/types/custom' {
4
4
  interface PiletCustomApi extends PiletRiotApi {
5
5
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "piral-riot",
3
- "version": "1.0.0-pre.2085",
3
+ "version": "1.0.1-beta.5640",
4
4
  "description": "Plugin for integrating Riot.js components in Piral.",
5
5
  "keywords": [
6
6
  "piral",
@@ -16,14 +16,35 @@
16
16
  "author": "smapiot",
17
17
  "homepage": "https://piral.io",
18
18
  "license": "MIT",
19
+ "module": "esm/index.js",
19
20
  "main": "lib/index.js",
20
21
  "typings": "lib/index.d.ts",
22
+ "exports": {
23
+ ".": {
24
+ "import": "./esm/index.js",
25
+ "require": "./lib/index.js"
26
+ },
27
+ "./convert": {
28
+ "import": "./convert.js"
29
+ },
30
+ "./esm/*": {
31
+ "import": "./esm/*"
32
+ },
33
+ "./lib/*": {
34
+ "require": "./lib/*"
35
+ },
36
+ "./_/*": {
37
+ "import": "./esm/*.js",
38
+ "require": "./lib/*.js"
39
+ },
40
+ "./package.json": "./package.json"
41
+ },
21
42
  "sideEffects": false,
22
43
  "files": [
44
+ "esm",
23
45
  "lib",
24
46
  "src",
25
47
  "convert.d.ts",
26
- "convert.ts",
27
48
  "convert.js"
28
49
  ],
29
50
  "repository": {
@@ -34,17 +55,17 @@
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-riot.json src --exclude \"src/**/*.test.*\"",
39
64
  "test": "echo \"Error: run tests from root\" && exit 1"
40
65
  },
41
66
  "devDependencies": {
42
- "piral-core": "^1.0.0-pre.2085",
67
+ "piral-core": "1.0.1-beta.5640",
43
68
  "riot": "^4.7.2"
44
69
  },
45
- "peerDependencies": {
46
- "piral-core": "1.x",
47
- "riot": "^4.0.0"
48
- },
49
- "gitHead": "140092491c51e02c298804e87070f56c8f6ce0fc"
70
+ "gitHead": "fa0a72b28fd0a20afec7ef491ec19e93c090fc72"
50
71
  }
package/src/converter.ts CHANGED
@@ -1,27 +1,43 @@
1
1
  import * as Riot from 'riot';
2
- import { ForeignComponent, BaseComponentProps } from 'piral-core';
2
+ import type { ForeignComponent, BaseComponentProps } from 'piral-core';
3
+ import { createExtension } from './extension';
3
4
 
4
- export function createConverter() {
5
+ export interface RiotConverterOptions {
6
+ /**
7
+ * Defines the name of the Riot extension element.
8
+ * @default riot-extension
9
+ */
10
+ extensionName?: string;
11
+ }
12
+
13
+ interface RiotState<TProps> {
14
+ app: Riot.RiotComponent<TProps>;
15
+ }
16
+
17
+ export function createConverter(config: RiotConverterOptions = {}) {
18
+ const { extensionName = 'riot-extension' } = config;
19
+ const Extension = createExtension(extensionName);
5
20
  const convert = <TProps extends BaseComponentProps>(
6
21
  component: Riot.RiotComponentShell<TProps>,
7
22
  captured?: Record<string, any>,
8
23
  ): ForeignComponent<TProps> => {
9
24
  const mountApp = Riot.component(component);
10
- let app: Riot.RiotComponent<TProps> = undefined;
11
25
 
12
26
  return {
13
- mount(el, props, ctx) {
14
- app = mountApp(el, {
27
+ mount(el, props, ctx, locals: RiotState<TProps>) {
28
+ locals.app = mountApp(el, {
15
29
  ...captured,
16
30
  ...ctx,
17
31
  ...props,
18
32
  });
19
33
  },
20
- unmount(el) {
21
- app.unmount(true);
34
+ unmount(el, locals: RiotState<TProps>) {
35
+ locals.app.unmount(true);
22
36
  el.innerHTML = '';
37
+ locals.app = undefined;
23
38
  },
24
39
  };
25
40
  };
41
+ convert.Extension = Extension;
26
42
  return convert;
27
43
  }
package/src/create.ts CHANGED
@@ -1,30 +1,21 @@
1
- import { PiralPlugin } from 'piral-core';
1
+ import type { PiralPlugin } from 'piral-core';
2
2
  import { createConverter } from './converter';
3
- import { PiletRiotApi } from './types';
4
- import { createExtension } from './extension';
3
+ import type { PiletRiotApi } from './types';
5
4
 
6
5
  /**
7
6
  * Available configuration options for the Riot.js plugin.
8
7
  */
9
- export interface RiotConfig {
10
- /**
11
- * Defines the name of the Riot extension element.
12
- * @default riot-extension
13
- */
14
- extensionName?: string;
15
- }
8
+ export interface RiotConfig {}
16
9
 
17
10
  /**
18
11
  * Creates new Pilet API extensions for integrating Riot.js.
19
12
  */
20
13
  export function createRiotApi(config: RiotConfig = {}): PiralPlugin<PiletRiotApi> {
21
- const { extensionName } = config;
22
-
23
14
  return (context) => {
24
- const convert = createConverter();
15
+ const convert = createConverter(config);
25
16
  context.converters.riot = ({ component, captured }) => convert(component, captured);
26
17
 
27
- return (api) => ({
18
+ return {
28
19
  fromRiot(component, captured) {
29
20
  return {
30
21
  type: 'riot',
@@ -32,7 +23,7 @@ export function createRiotApi(config: RiotConfig = {}): PiralPlugin<PiletRiotApi
32
23
  captured,
33
24
  };
34
25
  },
35
- RiotExtension: createExtension(api, extensionName),
36
- });
26
+ RiotExtension: convert.Extension,
27
+ };
37
28
  };
38
29
  }
package/src/extension.ts CHANGED
@@ -1,17 +1,22 @@
1
- import type { PiletApi, ExtensionSlotProps } from 'piral-core';
1
+ import type { ExtensionSlotProps } from 'piral-core';
2
2
  import type { RiotComponentShell } from 'riot';
3
3
  import type { TemplateChunk } from '@riotjs/dom-bindings';
4
4
 
5
- export function createExtension(
6
- api: PiletApi,
7
- extensionName = 'riot-extension',
8
- ): RiotComponentShell<ExtensionSlotProps> {
5
+ export function createExtension(extensionName: string): RiotComponentShell<ExtensionSlotProps> {
9
6
  return {
10
7
  name: extensionName,
11
8
  template() {
12
9
  const templateChunk: TemplateChunk = {
13
10
  mount(element, scope) {
14
- api.renderHtmlExtension(element, scope.props);
11
+ element.dispatchEvent(
12
+ new CustomEvent('render-html', {
13
+ bubbles: true,
14
+ detail: {
15
+ target: element,
16
+ props: scope.props,
17
+ },
18
+ }),
19
+ );
15
20
  return templateChunk;
16
21
  },
17
22
  update() {
package/src/types.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { ForeignComponent, ExtensionSlotProps } from 'piral-core';
2
- import { RiotComponentShell } from 'riot';
1
+ import type { ForeignComponent, ExtensionSlotProps } from 'piral-core';
2
+ import type { RiotComponentShell } from 'riot';
3
3
 
4
4
  declare module 'piral-core/lib/types/custom' {
5
5
  interface PiletCustomApi extends PiletRiotApi {}
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 RiotConverter {
8
- (...params: Parameters<typeof convert>): HtmlComponent<any>;
9
- }
10
-
11
- export const fromRiot: RiotConverter = (component, captured) => ({
12
- type: 'html',
13
- component: convert(component, captured),
14
- });
15
-
16
- export const createRiotExtension = createExtension;