piral-riot 1.0.0-pre.2024 → 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 -0
- package/esm/converter.js +22 -0
- package/esm/converter.js.map +1 -0
- package/esm/create.d.ts +11 -0
- package/esm/create.js +21 -0
- package/esm/create.js.map +1 -0
- package/esm/extension.d.ts +3 -0
- package/esm/extension.js +33 -0
- package/esm/extension.js.map +1 -0
- package/esm/index.d.ts +2 -0
- package/esm/index.js +3 -0
- package/esm/index.js.map +1 -0
- package/esm/types.d.ts +39 -0
- package/esm/types.js +2 -0
- package/esm/types.js.map +1 -0
- package/lib/converter.d.ts +12 -2
- package/lib/converter.js +13 -10
- package/lib/converter.js.map +1 -1
- package/lib/create.d.ts +2 -7
- package/lib/create.js +11 -17
- package/lib/create.js.map +1 -1
- package/lib/extension.d.ts +2 -2
- package/lib/extension.js +15 -10
- package/lib/extension.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/types.d.ts +2 -2
- package/package.json +30 -6
- package/src/converter.ts +23 -7
- package/src/create.ts +7 -16
- package/src/extension.ts +11 -6
- package/src/types.ts +2 -2
- package/convert.ts +0 -16
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
[](https://piral.io)
|
|
2
2
|
|
|
3
|
-
# [Piral Riot](https://piral.io) · [](https://github.com/smapiot/piral/blob/
|
|
3
|
+
# [Piral Riot](https://piral.io) · [](https://github.com/smapiot/piral/blob/main/LICENSE) [](https://www.npmjs.com/package/piral-riot) [](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 `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) {
|
|
@@ -65,7 +65,6 @@ export function setup(piral: PiletApi) {
|
|
|
65
65
|
Using Riot.js with Piral is as simple as installing `piral-riot` and `riot`.
|
|
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
|
-
"
|
|
87
|
-
"
|
|
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
|
|
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 RiotConverter {
|
|
5
|
-
(...params: Parameters<typeof
|
|
11
|
+
(...params: Parameters<ReturnType<typeof createConverter>>): HtmlComponent<any>;
|
|
6
12
|
}
|
|
7
|
-
export declare
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
+
};
|
package/esm/converter.js
ADDED
|
@@ -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"}
|
package/esm/create.d.ts
ADDED
|
@@ -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"}
|
package/esm/extension.js
ADDED
|
@@ -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
package/esm/index.js
ADDED
package/esm/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
|
package/esm/types.d.ts
ADDED
|
@@ -0,0 +1,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
package/esm/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/lib/converter.d.ts
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
1
|
import * as Riot from 'riot';
|
|
2
|
-
import { ForeignComponent, BaseComponentProps } from 'piral-core';
|
|
3
|
-
export
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
function createConverter() {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
|
12
|
-
app = mountApp(el,
|
|
12
|
+
mount(el, props, ctx, locals) {
|
|
13
|
+
locals.app = mountApp(el, Object.assign(Object.assign(Object.assign({}, captured), ctx), props));
|
|
13
14
|
},
|
|
14
|
-
unmount
|
|
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;
|
package/lib/converter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"converter.js","sourceRoot":"","sources":["../src/converter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"converter.js","sourceRoot":"","sources":["../src/converter.ts"],"names":[],"mappings":";;;AAAA,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
|
-
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
|
23
|
-
captured
|
|
16
|
+
component,
|
|
17
|
+
captured,
|
|
24
18
|
};
|
|
25
19
|
},
|
|
26
|
-
RiotExtension:
|
|
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,
|
|
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"}
|
package/lib/extension.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ExtensionSlotProps } from 'piral-core';
|
|
2
2
|
import type { RiotComponentShell } from 'riot';
|
|
3
|
-
export declare function createExtension(
|
|
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(
|
|
5
|
-
if (extensionName === void 0) { extensionName = 'riot-extension'; }
|
|
4
|
+
function createExtension(extensionName) {
|
|
6
5
|
return {
|
|
7
6
|
name: extensionName,
|
|
8
|
-
template
|
|
9
|
-
|
|
10
|
-
mount
|
|
11
|
-
|
|
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
|
|
19
|
+
update() {
|
|
15
20
|
return templateChunk;
|
|
16
21
|
},
|
|
17
|
-
unmount
|
|
22
|
+
unmount() {
|
|
18
23
|
return templateChunk;
|
|
19
24
|
},
|
|
20
|
-
createDOM
|
|
25
|
+
createDOM() {
|
|
21
26
|
return templateChunk;
|
|
22
27
|
},
|
|
23
|
-
clone
|
|
28
|
+
clone() {
|
|
24
29
|
return templateChunk;
|
|
25
30
|
},
|
|
26
31
|
};
|
package/lib/extension.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":";;;AAIA,SAAgB,eAAe,
|
|
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
|
-
|
|
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
|
|
3
|
+
"version": "1.0.0",
|
|
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,20 @@
|
|
|
34
55
|
"url": "https://github.com/smapiot/piral/issues"
|
|
35
56
|
},
|
|
36
57
|
"scripts": {
|
|
37
|
-
"
|
|
58
|
+
"cleanup": "rimraf esm lib convert.d.ts convert.js",
|
|
59
|
+
"build": "yarn build:commonjs && yarn build:esnext && yarn build:convert",
|
|
60
|
+
"build:convert": "tsc convert.ts --skipLibCheck --declaration --module esnext",
|
|
61
|
+
"build:commonjs": "tsc --project tsconfig.json --outDir lib --module commonjs",
|
|
62
|
+
"build:esnext": "tsc --project tsconfig.json --outDir esm --module esnext",
|
|
38
63
|
"typedoc": "typedoc --json ../../../docs/types/piral-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
|
|
67
|
+
"piral-core": "^1.0.0",
|
|
43
68
|
"riot": "^4.7.2"
|
|
44
69
|
},
|
|
45
70
|
"peerDependencies": {
|
|
46
|
-
"piral-core": "1.x",
|
|
47
71
|
"riot": "^4.0.0"
|
|
48
72
|
},
|
|
49
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "67d9a2920bd5231baf10bc87ae8985666b18fa3a"
|
|
50
74
|
}
|
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
|
|
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
|
|
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:
|
|
36
|
-
}
|
|
26
|
+
RiotExtension: convert.Extension,
|
|
27
|
+
};
|
|
37
28
|
};
|
|
38
29
|
}
|
package/src/extension.ts
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
|
-
import type {
|
|
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
|
-
|
|
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;
|