piral-react-15 1.0.0-pre.2094 → 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 React 15](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-react-15.svg?style=flat)](https://www.npmjs.com/package/piral-react-15) [![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 React 15](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-react-15.svg?style=flat)](https://www.npmjs.com/package/piral-react-15) [![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-react-15` 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 `react@^15` and `react-dom@^15`. What `piral-react-15` 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 React 15.x converter for any component registration, as well as a `fromReact15` shortcut and a `React15Extension` component.
8
8
 
@@ -47,7 +47,7 @@ Alternatively, if `piral-react-15` 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 { fromReact15 } from 'piral-react-15';
50
+ import { fromReact15 } from 'piral-react-15/convert';
51
51
  import { React15Page } from './React15Page';
52
52
 
53
53
  export function setup(piral: PiletApi) {
@@ -59,10 +59,20 @@ export function setup(piral: PiletApi) {
59
59
 
60
60
  ::: summary: For Piral instance developers
61
61
 
62
- Using React v15 with Piral is as simple as installing `piral-react-15` and `react-15`.
62
+ Using React v15 with Piral is as simple as installing `piral-react-15` and `react-15`. For `react-15` add the following two packages to your project's dependencies:
63
+
64
+ ```json
65
+ {
66
+ "dependencies": {
67
+ "react-15`": "npm:react@^15",
68
+ "react-dom-15": "npm:react@^15"
69
+ }
70
+ }
71
+ ```
72
+
73
+ Now you are ready to use the `piral-react-15` converter:
63
74
 
64
75
  ```ts
65
- import 'react-15';
66
76
  import { createReact15Api } from 'piral-react-15';
67
77
  ```
68
78
 
@@ -80,10 +90,10 @@ The `react-15` package (or whatever alias you've chosen) should be shared with t
80
90
 
81
91
  ```json
82
92
  {
83
- "pilets": {
84
- "externals": [
85
- "react-15"
86
- ]
93
+ "importmap": {
94
+ "imports": {
95
+ "react-15": ""
96
+ }
87
97
  }
88
98
  }
89
99
  ```
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: 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 React15Converter {
5
- (...params: Parameters<typeof convert>): HtmlComponent<any>;
11
+ (...params: Parameters<ReturnType<typeof createConverter>>): HtmlComponent<any>;
6
12
  }
7
- export declare const fromReact15: React15Converter;
8
- export declare const createReact15Extension: typeof createExtension;
9
- export {};
13
+ export declare function createReact15Converter(...params: Parameters<typeof createConverter>): {
14
+ from: React15Converter;
15
+ Extension: any;
16
+ };
17
+ declare const fromReact15: React15Converter, React15Extension: any;
18
+ export { fromReact15, React15Extension };
package/convert.js CHANGED
@@ -1,11 +1,16 @@
1
- "use strict";
2
- exports.__esModule = true;
3
- exports.createReact15Extension = exports.fromReact15 = void 0;
4
- var converter_1 = require("./lib/converter");
5
- var extension_1 = require("./lib/extension");
6
- var convert = converter_1.createConverter();
7
- exports.fromReact15 = function (root) { return ({
8
- type: 'html',
9
- component: convert(root)
10
- }); };
11
- exports.createReact15Extension = extension_1.createExtension;
1
+ import { createConverter } from './esm/converter';
2
+ export function createReact15Converter() {
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) { return ({
10
+ type: 'html',
11
+ component: convert(root),
12
+ }); };
13
+ return { from: from, Extension: Extension };
14
+ }
15
+ var _a = createReact15Converter(), fromReact15 = _a.from, React15Extension = _a.Extension;
16
+ export { fromReact15, React15Extension };
@@ -0,0 +1,14 @@
1
+ /// <reference types="react" />
2
+ import type { ForeignComponent, BaseComponentProps } from 'piral-core';
3
+ import type { ComponentType } from 'react-15';
4
+ export interface React15ConverterOptions {
5
+ /**
6
+ * Defines the name of the root element.
7
+ * @default piral-slot
8
+ */
9
+ rootName?: string;
10
+ }
11
+ export declare function createConverter(config?: React15ConverterOptions): {
12
+ <TProps extends BaseComponentProps>(root: ComponentType<TProps>): ForeignComponent<TProps>;
13
+ Extension: any;
14
+ };
@@ -0,0 +1,20 @@
1
+ import { createExtension } from './extension';
2
+ import { mountReact15, unmountReact15 } from './mount';
3
+ export function createConverter(config = {}) {
4
+ const { rootName = 'piral-slot' } = config;
5
+ const Extension = createExtension(rootName);
6
+ const convert = (root) => ({
7
+ mount(el, props, ctx) {
8
+ mountReact15(el, root, props, ctx);
9
+ },
10
+ update(el, props, ctx) {
11
+ mountReact15(el, root, props, ctx);
12
+ },
13
+ unmount(el) {
14
+ unmountReact15(el);
15
+ },
16
+ });
17
+ convert.Extension = Extension;
18
+ return convert;
19
+ }
20
+ //# sourceMappingURL=converter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"converter.js","sourceRoot":"","sources":["../src/converter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAUvD,MAAM,UAAU,eAAe,CAAC,SAAkC,EAAE;IAClE,MAAM,EAAE,QAAQ,GAAG,YAAY,EAAE,GAAG,MAAM,CAAC;IAC3C,MAAM,SAAS,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC;IAC5C,MAAM,OAAO,GAAG,CAAoC,IAA2B,EAA4B,EAAE,CAAC,CAAC;QAC7G,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,GAAG;YAClB,YAAY,CAAC,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;QACrC,CAAC;QACD,MAAM,CAAC,EAAE,EAAE,KAAK,EAAE,GAAG;YACnB,YAAY,CAAC,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;QACrC,CAAC;QACD,OAAO,CAAC,EAAE;YACR,cAAc,CAAC,EAAE,CAAC,CAAC;QACrB,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 { React15ConverterOptions } from './converter';
3
+ import type { PiletReact15Api } from './types';
4
+ /**
5
+ * Available configuration options for the React 15.x plugin.
6
+ */
7
+ export interface React15Config extends React15ConverterOptions {
8
+ }
9
+ /**
10
+ * Creates Pilet API extensions for integrating React 15.x.
11
+ */
12
+ export declare function createReact15Api(config?: React15Config): PiralPlugin<PiletReact15Api>;
package/esm/create.js ADDED
@@ -0,0 +1,20 @@
1
+ import { createConverter } from './converter';
2
+ /**
3
+ * Creates Pilet API extensions for integrating React 15.x.
4
+ */
5
+ export function createReact15Api(config = {}) {
6
+ return (context) => {
7
+ const convert = createConverter(config);
8
+ context.converters.react15 = ({ root }) => convert(root);
9
+ return {
10
+ fromReact15(root) {
11
+ return {
12
+ type: 'react15',
13
+ root,
14
+ };
15
+ },
16
+ React15Extension: convert.Extension,
17
+ };
18
+ };
19
+ }
20
+ //# sourceMappingURL=create.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAA2B,MAAM,aAAa,CAAC;AAQvE;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,SAAwB,EAAE;IACzD,OAAO,CAAC,OAAO,EAAE,EAAE;QACjB,MAAM,OAAO,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;QACxC,OAAO,CAAC,UAAU,CAAC,OAAO,GAAG,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAEzD,OAAO;YACL,WAAW,CAAC,IAAI;gBACd,OAAO;oBACL,IAAI,EAAE,SAAS;oBACf,IAAI;iBACL,CAAC;YACJ,CAAC;YACD,gBAAgB,EAAE,OAAO,CAAC,SAAS;SACpC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1 @@
1
+ export declare function createExtension(rootName: string): any;
@@ -0,0 +1,57 @@
1
+ import { __setFunctionName } from "tslib";
2
+ import { createElement, Component } from 'react-15';
3
+ import { anyPropType } from './mount';
4
+ function compareObjects(a, b) {
5
+ for (const i in a) {
6
+ if (!(i in b)) {
7
+ return false;
8
+ }
9
+ }
10
+ for (const i in b) {
11
+ if (!compare(a[i], b[i])) {
12
+ return false;
13
+ }
14
+ }
15
+ return true;
16
+ }
17
+ function compare(a, b) {
18
+ if (a !== b) {
19
+ const ta = typeof a;
20
+ const tb = typeof b;
21
+ if (ta === tb && ta === 'object' && a && b) {
22
+ return compareObjects(a, b);
23
+ }
24
+ return false;
25
+ }
26
+ return true;
27
+ }
28
+ export function createExtension(rootName) {
29
+ var _a;
30
+ const React15Extension = (_a = class extends Component {
31
+ constructor() {
32
+ super(...arguments);
33
+ this.onRefChange = (element) => {
34
+ if (element) {
35
+ const { piral } = this.context;
36
+ element.innerHTML = '';
37
+ piral.renderHtmlExtension(element, this.props);
38
+ }
39
+ };
40
+ }
41
+ shouldComponentUpdate(nextProps) {
42
+ return !compare(this.props, nextProps);
43
+ }
44
+ render() {
45
+ return createElement(rootName, {
46
+ ref: this.onRefChange,
47
+ });
48
+ }
49
+ },
50
+ __setFunctionName(_a, "React15Extension"),
51
+ _a.contextTypes = {
52
+ piral: anyPropType,
53
+ },
54
+ _a);
55
+ return React15Extension;
56
+ }
57
+ //# sourceMappingURL=extension.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,SAAS,cAAc,CAAC,CAAM,EAAE,CAAM;IACpC,KAAK,MAAM,CAAC,IAAI,CAAC,EAAE;QACjB,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE;YACb,OAAO,KAAK,CAAC;SACd;KACF;IAED,KAAK,MAAM,CAAC,IAAI,CAAC,EAAE;QACjB,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE;YACxB,OAAO,KAAK,CAAC;SACd;KACF;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,OAAO,CAAI,CAAI,EAAE,CAAI;IAC5B,IAAI,CAAC,KAAK,CAAC,EAAE;QACX,MAAM,EAAE,GAAG,OAAO,CAAC,CAAC;QACpB,MAAM,EAAE,GAAG,OAAO,CAAC,CAAC;QAEpB,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,QAAQ,IAAI,CAAC,IAAI,CAAC,EAAE;YAC1C,OAAO,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;SAC7B;QAED,OAAO,KAAK,CAAC;KACd;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,QAAgB;;IAC9C,MAAM,gBAAgB,SAAQ,KAAM,SAAQ,SAA6B;YAA3C;;gBAKpB,gBAAW,GAAG,CAAC,OAAoB,EAAE,EAAE;oBAC7C,IAAI,OAAO,EAAE;wBACX,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,OAA8B,CAAC;wBACtD,OAAO,CAAC,SAAS,GAAG,EAAE,CAAC;wBACvB,KAAK,CAAC,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;qBAChD;gBACH,CAAC,CAAC;YAWJ,CAAC;YATC,qBAAqB,CAAC,SAA6B;gBACjD,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;YACzC,CAAC;YAED,MAAM;gBACJ,OAAO,aAAa,CAAC,QAAQ,EAAE;oBAC7B,GAAG,EAAE,IAAI,CAAC,WAAW;iBACtB,CAAC,CAAC;YACL,CAAC;SACF;;QArBQ,eAAY,GAAG;YACpB,KAAK,EAAE,WAAW;SAClB;WAmBH,CAAC;IAEF,OAAO,gBAAgB,CAAC;AAC1B,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,6 @@
1
+ /// <reference types="react" />
2
+ import type { BaseComponentProps } from 'piral-core';
3
+ import { ComponentType } from 'react-15';
4
+ export declare const anyPropType: () => any;
5
+ export declare function mountReact15<T extends BaseComponentProps>(el: HTMLElement, root: ComponentType<T>, props: T, ctx?: any): void;
6
+ export declare function unmountReact15(el: HTMLElement): void;
package/esm/mount.js ADDED
@@ -0,0 +1,25 @@
1
+ import { render } from 'react-dom-15';
2
+ import { createElement, Component } from 'react-15';
3
+ // tslint:disable-next-line:no-null-keyword
4
+ export const anyPropType = () => null;
5
+ export function mountReact15(el, root, props, ctx = {}) {
6
+ const contextTypes = {};
7
+ ['piral', ...Object.keys(ctx)].forEach((key) => {
8
+ contextTypes[key] = anyPropType;
9
+ });
10
+ class Provider extends Component {
11
+ getChildContext() {
12
+ return Object.assign({ piral: props.piral }, ctx);
13
+ }
14
+ render() {
15
+ return this.props.children;
16
+ }
17
+ }
18
+ Provider.childContextTypes = contextTypes;
19
+ render(createElement(Provider, {}, createElement(root, props)), el);
20
+ }
21
+ export function unmountReact15(el) {
22
+ // tslint:disable-next-line:no-null-keyword
23
+ render(null, el);
24
+ }
25
+ //# sourceMappingURL=mount.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mount.js","sourceRoot":"","sources":["../src/mount.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,aAAa,EAAiB,SAAS,EAAE,MAAM,UAAU,CAAC;AAEnE,2CAA2C;AAC3C,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC;AAEtC,MAAM,UAAU,YAAY,CAC1B,EAAe,EACf,IAAsB,EACtB,KAAQ,EACR,MAAW,EAAE;IAEb,MAAM,YAAY,GAAG,EAAE,CAAC;IAExB,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QAC7C,YAAY,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC;IAClC,CAAC,CAAC,CAAC;IAEH,MAAM,QAAS,SAAQ,SAA6B;QAGlD,eAAe;YACb,uBACE,KAAK,EAAE,KAAK,CAAC,KAAK,IACf,GAAG,EACN;QACJ,CAAC;QAED,MAAM;YACJ,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;QAC7B,CAAC;;IAXM,0BAAiB,GAAG,YAAY,CAAC;IAc1C,MAAM,CAAC,aAAa,CAAC,QAAQ,EAAE,EAAE,EAAE,aAAa,CAAC,IAAW,EAAE,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAC7E,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,EAAe;IAC5C,2CAA2C;IAC3C,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;AACnB,CAAC"}
package/esm/types.d.ts ADDED
@@ -0,0 +1,35 @@
1
+ /// <reference types="react" />
2
+ import type { ForeignComponent, ExtensionSlotProps } from 'piral-core';
3
+ import type { Component, ComponentType } from 'react-15';
4
+ declare module 'piral-core/lib/types/custom' {
5
+ interface PiletCustomApi extends PiletReact15Api {
6
+ }
7
+ interface PiralCustomComponentConverters<TProps> {
8
+ react15(component: React15Component<TProps>): ForeignComponent<TProps>;
9
+ }
10
+ }
11
+ export interface React15Component<TProps> {
12
+ /**
13
+ * The component root.
14
+ */
15
+ root: ComponentType<TProps>;
16
+ /**
17
+ * The type of the React 15.x component.
18
+ */
19
+ type: 'react15';
20
+ }
21
+ /**
22
+ * Defines the provided set of Pilet API extensions from the React 15.x plugin.
23
+ */
24
+ export interface PiletReact15Api {
25
+ /**
26
+ * Wraps an React 15.x component for use in Piral.
27
+ * @param component The component root.
28
+ * @returns The Piral React 15.x component.
29
+ */
30
+ fromReact15<TProps>(component: ComponentType<TProps>): React15Component<TProps>;
31
+ /**
32
+ * React 15.x component for displaying extensions of the given name.
33
+ */
34
+ React15Extension: Component<ExtensionSlotProps>;
35
+ }
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,4 +1,14 @@
1
1
  /// <reference types="react" />
2
- import { ForeignComponent, BaseComponentProps } from 'piral-core';
3
- import { ComponentType } from 'react-15';
4
- export declare function createConverter(): <TProps extends BaseComponentProps>(root: ComponentType<TProps>) => ForeignComponent<TProps>;
2
+ import type { ForeignComponent, BaseComponentProps } from 'piral-core';
3
+ import type { ComponentType } from 'react-15';
4
+ export interface React15ConverterOptions {
5
+ /**
6
+ * Defines the name of the root element.
7
+ * @default piral-slot
8
+ */
9
+ rootName?: string;
10
+ }
11
+ export declare function createConverter(config?: React15ConverterOptions): {
12
+ <TProps extends BaseComponentProps>(root: ComponentType<TProps>): ForeignComponent<TProps>;
13
+ Extension: any;
14
+ };
package/lib/converter.js CHANGED
@@ -1,21 +1,23 @@
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) {
7
- return {
8
- mount: function (el, props, ctx) {
9
- mount_1.mountReact15(el, root, props, ctx);
10
- },
11
- update: function (el, props, ctx) {
12
- mount_1.mountReact15(el, root, props, ctx);
13
- },
14
- unmount: function (el) {
15
- mount_1.unmountReact15(el);
16
- },
17
- };
18
- };
4
+ const extension_1 = require("./extension");
5
+ const mount_1 = require("./mount");
6
+ function createConverter(config = {}) {
7
+ const { rootName = 'piral-slot' } = config;
8
+ const Extension = (0, extension_1.createExtension)(rootName);
9
+ const convert = (root) => ({
10
+ mount(el, props, ctx) {
11
+ (0, mount_1.mountReact15)(el, root, props, ctx);
12
+ },
13
+ update(el, props, ctx) {
14
+ (0, mount_1.mountReact15)(el, root, props, ctx);
15
+ },
16
+ unmount(el) {
17
+ (0, mount_1.unmountReact15)(el);
18
+ },
19
+ });
20
+ convert.Extension = Extension;
19
21
  return convert;
20
22
  }
21
23
  exports.createConverter = createConverter;
@@ -1 +1 @@
1
- {"version":3,"file":"converter.js","sourceRoot":"","sources":["../src/converter.ts"],"names":[],"mappings":";;;AAEA,iCAAuD;AAEvD,SAAgB,eAAe;IAC7B,IAAM,OAAO,GAAG,UAAoC,IAA2B;QAC7E,OAAO;YACL,KAAK,YAAC,EAAE,EAAE,KAAK,EAAE,GAAG;gBAClB,oBAAY,CAAC,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;YACrC,CAAC;YACD,MAAM,YAAC,EAAE,EAAE,KAAK,EAAE,GAAG;gBACnB,oBAAY,CAAC,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;YACrC,CAAC;YACD,OAAO,YAAC,EAAE;gBACR,sBAAc,CAAC,EAAE,CAAC,CAAC;YACrB,CAAC;SACF,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO,OAAO,CAAC;AACjB,CAAC;AAhBD,0CAgBC"}
1
+ {"version":3,"file":"converter.js","sourceRoot":"","sources":["../src/converter.ts"],"names":[],"mappings":";;;AAEA,2CAA8C;AAC9C,mCAAuD;AAUvD,SAAgB,eAAe,CAAC,SAAkC,EAAE;IAClE,MAAM,EAAE,QAAQ,GAAG,YAAY,EAAE,GAAG,MAAM,CAAC;IAC3C,MAAM,SAAS,GAAG,IAAA,2BAAe,EAAC,QAAQ,CAAC,CAAC;IAC5C,MAAM,OAAO,GAAG,CAAoC,IAA2B,EAA4B,EAAE,CAAC,CAAC;QAC7G,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,GAAG;YAClB,IAAA,oBAAY,EAAC,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;QACrC,CAAC;QACD,MAAM,CAAC,EAAE,EAAE,KAAK,EAAE,GAAG;YACnB,IAAA,oBAAY,EAAC,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;QACrC,CAAC;QACD,OAAO,CAAC,EAAE;YACR,IAAA,sBAAc,EAAC,EAAE,CAAC,CAAC;QACrB,CAAC;KACF,CAAC,CAAC;IACH,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;IAC9B,OAAO,OAAO,CAAC;AACjB,CAAC;AAhBD,0CAgBC"}
package/lib/create.d.ts CHANGED
@@ -1,14 +1,10 @@
1
1
  import type { PiralPlugin } from 'piral-core';
2
+ import { React15ConverterOptions } from './converter';
2
3
  import type { PiletReact15Api } from './types';
3
4
  /**
4
5
  * Available configuration options for the React 15.x plugin.
5
6
  */
6
- export interface React15Config {
7
- /**
8
- * Defines the name of the root element.
9
- * @default slot
10
- */
11
- rootName?: string;
7
+ export interface React15Config extends React15ConverterOptions {
12
8
  }
13
9
  /**
14
10
  * Creates Pilet API extensions for integrating React 15.x.
package/lib/create.js CHANGED
@@ -1,28 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createReact15Api = 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 Pilet API extensions for integrating React 15.x.
8
7
  */
9
- function createReact15Api(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.react15 = function (_a) {
15
- var root = _a.root;
16
- return convert(root);
17
- };
8
+ function createReact15Api(config = {}) {
9
+ return (context) => {
10
+ const convert = (0, converter_1.createConverter)(config);
11
+ context.converters.react15 = ({ root }) => convert(root);
18
12
  return {
19
- fromReact15: function (root) {
13
+ fromReact15(root) {
20
14
  return {
21
15
  type: 'react15',
22
- root: root,
16
+ root,
23
17
  };
24
18
  },
25
- React15Extension: extension_1.createExtension(rootName),
19
+ React15Extension: convert.Extension,
26
20
  };
27
21
  };
28
22
  }
package/lib/create.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":";;;AACA,yCAA8C;AAC9C,yCAA8C;AAc9C;;GAEG;AACH,SAAgB,gBAAgB,CAAC,MAA0B;IAA1B,uBAAA,EAAA,WAA0B;IACjD,IAAA,QAAQ,GAAK,MAAM,SAAX,CAAY;IAE5B,OAAO,UAAC,OAAO;QACb,IAAM,OAAO,GAAG,2BAAe,EAAE,CAAC;QAClC,OAAO,CAAC,UAAU,CAAC,OAAO,GAAG,UAAC,EAAQ;gBAAN,IAAI,UAAA;YAAO,OAAA,OAAO,CAAC,IAAI,CAAC;QAAb,CAAa,CAAC;QAEzD,OAAO;YACL,WAAW,YAAC,IAAI;gBACd,OAAO;oBACL,IAAI,EAAE,SAAS;oBACf,IAAI,MAAA;iBACL,CAAC;YACJ,CAAC;YACD,gBAAgB,EAAE,2BAAe,CAAC,QAAQ,CAAC;SAC5C,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAjBD,4CAiBC"}
1
+ {"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":";;;AACA,2CAAuE;AAQvE;;GAEG;AACH,SAAgB,gBAAgB,CAAC,SAAwB,EAAE;IACzD,OAAO,CAAC,OAAO,EAAE,EAAE;QACjB,MAAM,OAAO,GAAG,IAAA,2BAAe,EAAC,MAAM,CAAC,CAAC;QACxC,OAAO,CAAC,UAAU,CAAC,OAAO,GAAG,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAEzD,OAAO;YACL,WAAW,CAAC,IAAI;gBACd,OAAO;oBACL,IAAI,EAAE,SAAS;oBACf,IAAI;iBACL,CAAC;YACJ,CAAC;YACD,gBAAgB,EAAE,OAAO,CAAC,SAAS;SACpC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAfD,4CAeC"}
@@ -1 +1 @@
1
- export declare function createExtension(rootName?: string): any;
1
+ export declare function createExtension(rootName: string): any;
package/lib/extension.js CHANGED
@@ -1,36 +1,56 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createExtension = void 0;
4
- var tslib_1 = require("tslib");
5
- var piral_core_1 = require("piral-core");
6
- var react_15_1 = require("react-15");
7
- var mount_1 = require("./mount");
4
+ const tslib_1 = require("tslib");
5
+ const react_15_1 = require("react-15");
6
+ const mount_1 = require("./mount");
7
+ function compareObjects(a, b) {
8
+ for (const i in a) {
9
+ if (!(i in b)) {
10
+ return false;
11
+ }
12
+ }
13
+ for (const i in b) {
14
+ if (!compare(a[i], b[i])) {
15
+ return false;
16
+ }
17
+ }
18
+ return true;
19
+ }
20
+ function compare(a, b) {
21
+ if (a !== b) {
22
+ const ta = typeof a;
23
+ const tb = typeof b;
24
+ if (ta === tb && ta === 'object' && a && b) {
25
+ return compareObjects(a, b);
26
+ }
27
+ return false;
28
+ }
29
+ return true;
30
+ }
8
31
  function createExtension(rootName) {
9
32
  var _a;
10
- if (rootName === void 0) { rootName = 'slot'; }
11
- var React15Extension = (_a = /** @class */ (function (_super) {
12
- tslib_1.__extends(class_1, _super);
13
- function class_1() {
14
- var _this = _super !== null && _super.apply(this, arguments) || this;
15
- _this.onRefChange = function (element) {
33
+ const React15Extension = (_a = class extends react_15_1.Component {
34
+ constructor() {
35
+ super(...arguments);
36
+ this.onRefChange = (element) => {
16
37
  if (element) {
17
- var piral = _this.context.piral;
38
+ const { piral } = this.context;
18
39
  element.innerHTML = '';
19
- piral.renderHtmlExtension(element, _this.props);
40
+ piral.renderHtmlExtension(element, this.props);
20
41
  }
21
42
  };
22
- return _this;
23
43
  }
24
- class_1.prototype.shouldComponentUpdate = function (nextProps) {
25
- return !piral_core_1.compare(this.props, nextProps);
26
- };
27
- class_1.prototype.render = function () {
28
- return react_15_1.createElement(rootName, {
44
+ shouldComponentUpdate(nextProps) {
45
+ return !compare(this.props, nextProps);
46
+ }
47
+ render() {
48
+ return (0, react_15_1.createElement)(rootName, {
29
49
  ref: this.onRefChange,
30
50
  });
31
- };
32
- return class_1;
33
- }(react_15_1.Component)),
51
+ }
52
+ },
53
+ tslib_1.__setFunctionName(_a, "React15Extension"),
34
54
  _a.contextTypes = {
35
55
  piral: mount_1.anyPropType,
36
56
  },
@@ -1 +1 @@
1
- {"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":";;;;AAAA,yCAAyD;AACzD,qCAAoD;AACpD,iCAAsC;AAEtC,SAAgB,eAAe,CAAC,QAAiB;;IAAjB,yBAAA,EAAA,iBAAiB;IAC/C,IAAM,gBAAgB;YAAsB,mCAA6B;YAA3C;gBAAA,qEAsB7B;gBAjBS,iBAAW,GAAG,UAAC,OAAoB;oBACzC,IAAI,OAAO,EAAE;wBACH,IAAA,KAAK,GAAK,KAAI,CAAC,OAAO,MAAjB,CAAkB;wBAC/B,OAAO,CAAC,SAAS,GAAG,EAAE,CAAC;wBACvB,KAAK,CAAC,mBAAmB,CAAC,OAAO,EAAE,KAAI,CAAC,KAAK,CAAC,CAAC;qBAChD;gBACH,CAAC,CAAC;;YAWJ,CAAC;YATC,uCAAqB,GAArB,UAAsB,SAA6B;gBACjD,OAAO,CAAC,oBAAO,CAAC,IAAI,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;YACzC,CAAC;YAED,wBAAM,GAAN;gBACE,OAAO,wBAAa,CAAC,QAAQ,EAAE;oBAC7B,GAAG,EAAE,IAAI,CAAC,WAAW;iBACtB,CAAC,CAAC;YACL,CAAC;YACH,cAAC;QAAD,CAAC,AAtB6B,CAAc,oBAAS;QAC5C,eAAY,GAAG;YACpB,KAAK,EAAE,mBAAW;SAClB;WAmBH,CAAC;IAEF,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AA1BD,0CA0BC"}
1
+ {"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":";;;;AACA,uCAAoD;AACpD,mCAAsC;AAEtC,SAAS,cAAc,CAAC,CAAM,EAAE,CAAM;IACpC,KAAK,MAAM,CAAC,IAAI,CAAC,EAAE;QACjB,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE;YACb,OAAO,KAAK,CAAC;SACd;KACF;IAED,KAAK,MAAM,CAAC,IAAI,CAAC,EAAE;QACjB,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE;YACxB,OAAO,KAAK,CAAC;SACd;KACF;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,OAAO,CAAI,CAAI,EAAE,CAAI;IAC5B,IAAI,CAAC,KAAK,CAAC,EAAE;QACX,MAAM,EAAE,GAAG,OAAO,CAAC,CAAC;QACpB,MAAM,EAAE,GAAG,OAAO,CAAC,CAAC;QAEpB,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,QAAQ,IAAI,CAAC,IAAI,CAAC,EAAE;YAC1C,OAAO,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;SAC7B;QAED,OAAO,KAAK,CAAC;KACd;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAgB,eAAe,CAAC,QAAgB;;IAC9C,MAAM,gBAAgB,SAAQ,KAAM,SAAQ,oBAA6B;YAA3C;;gBAKpB,gBAAW,GAAG,CAAC,OAAoB,EAAE,EAAE;oBAC7C,IAAI,OAAO,EAAE;wBACX,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,OAA8B,CAAC;wBACtD,OAAO,CAAC,SAAS,GAAG,EAAE,CAAC;wBACvB,KAAK,CAAC,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;qBAChD;gBACH,CAAC,CAAC;YAWJ,CAAC;YATC,qBAAqB,CAAC,SAA6B;gBACjD,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;YACzC,CAAC;YAED,MAAM;gBACJ,OAAO,IAAA,wBAAa,EAAC,QAAQ,EAAE;oBAC7B,GAAG,EAAE,IAAI,CAAC,WAAW;iBACtB,CAAC,CAAC;YACL,CAAC;SACF;;QArBQ,eAAY,GAAG;YACpB,KAAK,EAAE,mBAAW;SAClB;WAmBH,CAAC;IAEF,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AA1BD,0CA0BC"}
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,6 +1,6 @@
1
1
  /// <reference types="react" />
2
+ import type { BaseComponentProps } from 'piral-core';
2
3
  import { ComponentType } from 'react-15';
3
- import { BaseComponentProps } from 'piral-core';
4
4
  export declare const anyPropType: () => any;
5
5
  export declare function mountReact15<T extends BaseComponentProps>(el: HTMLElement, root: ComponentType<T>, props: T, ctx?: any): void;
6
6
  export declare function unmountReact15(el: HTMLElement): void;
package/lib/mount.js CHANGED
@@ -1,37 +1,31 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.unmountReact15 = exports.mountReact15 = exports.anyPropType = void 0;
4
- var tslib_1 = require("tslib");
5
- var react_dom_15_1 = require("react-dom-15");
6
- var react_15_1 = require("react-15");
4
+ const react_dom_15_1 = require("react-dom-15");
5
+ const react_15_1 = require("react-15");
7
6
  // tslint:disable-next-line:no-null-keyword
8
- exports.anyPropType = function () { return null; };
9
- function mountReact15(el, root, props, ctx) {
10
- if (ctx === void 0) { ctx = {}; }
11
- var contextTypes = {};
12
- tslib_1.__spreadArrays(['piral'], Object.keys(ctx)).forEach(function (key) {
7
+ const anyPropType = () => null;
8
+ exports.anyPropType = anyPropType;
9
+ function mountReact15(el, root, props, ctx = {}) {
10
+ const contextTypes = {};
11
+ ['piral', ...Object.keys(ctx)].forEach((key) => {
13
12
  contextTypes[key] = exports.anyPropType;
14
13
  });
15
- var Provider = /** @class */ (function (_super) {
16
- tslib_1.__extends(Provider, _super);
17
- function Provider() {
18
- return _super !== null && _super.apply(this, arguments) || this;
14
+ class Provider extends react_15_1.Component {
15
+ getChildContext() {
16
+ return Object.assign({ piral: props.piral }, ctx);
19
17
  }
20
- Provider.prototype.getChildContext = function () {
21
- return tslib_1.__assign({ piral: props.piral }, ctx);
22
- };
23
- Provider.prototype.render = function () {
18
+ render() {
24
19
  return this.props.children;
25
- };
26
- Provider.childContextTypes = contextTypes;
27
- return Provider;
28
- }(react_15_1.Component));
29
- react_dom_15_1.render(react_15_1.createElement(Provider, {}, react_15_1.createElement(root, props)), el);
20
+ }
21
+ }
22
+ Provider.childContextTypes = contextTypes;
23
+ (0, react_dom_15_1.render)((0, react_15_1.createElement)(Provider, {}, (0, react_15_1.createElement)(root, props)), el);
30
24
  }
31
25
  exports.mountReact15 = mountReact15;
32
26
  function unmountReact15(el) {
33
27
  // tslint:disable-next-line:no-null-keyword
34
- react_dom_15_1.render(null, el);
28
+ (0, react_dom_15_1.render)(null, el);
35
29
  }
36
30
  exports.unmountReact15 = unmountReact15;
37
31
  //# sourceMappingURL=mount.js.map
package/lib/mount.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mount.js","sourceRoot":"","sources":["../src/mount.ts"],"names":[],"mappings":";;;;AAAA,6CAAsC;AACtC,qCAAmE;AAGnE,2CAA2C;AAC9B,QAAA,WAAW,GAAG,cAAM,OAAA,IAAI,EAAJ,CAAI,CAAC;AAEtC,SAAgB,YAAY,CAC1B,EAAe,EACf,IAAsB,EACtB,KAAQ,EACR,GAAa;IAAb,oBAAA,EAAA,QAAa;IAEb,IAAM,YAAY,GAAG,EAAE,CAAC;IAExB,wBAAC,OAAO,GAAK,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,UAAC,GAAG;QACzC,YAAY,CAAC,GAAG,CAAC,GAAG,mBAAW,CAAC;IAClC,CAAC,CAAC,CAAC;IAEH;QAAuB,oCAAS;QAAhC;;QAaA,CAAC;QAVC,kCAAe,GAAf;YACE,0BACE,KAAK,EAAE,KAAK,CAAC,KAAK,IACf,GAAG,EACN;QACJ,CAAC;QAED,yBAAM,GAAN;YACE,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;QAC7B,CAAC;QAXM,0BAAiB,GAAG,YAAY,CAAC;QAY1C,eAAC;KAAA,AAbD,CAAuB,oBAAS,GAa/B;IAED,qBAAM,CAAC,wBAAa,CAAC,QAAQ,EAAE,EAAE,EAAE,wBAAa,CAAC,IAAW,EAAE,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAC7E,CAAC;AA5BD,oCA4BC;AAED,SAAgB,cAAc,CAAC,EAAe;IAC5C,2CAA2C;IAC3C,qBAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;AACnB,CAAC;AAHD,wCAGC"}
1
+ {"version":3,"file":"mount.js","sourceRoot":"","sources":["../src/mount.ts"],"names":[],"mappings":";;;AACA,+CAAsC;AACtC,uCAAmE;AAEnE,2CAA2C;AACpC,MAAM,WAAW,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC;AAAzB,QAAA,WAAW,eAAc;AAEtC,SAAgB,YAAY,CAC1B,EAAe,EACf,IAAsB,EACtB,KAAQ,EACR,MAAW,EAAE;IAEb,MAAM,YAAY,GAAG,EAAE,CAAC;IAExB,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QAC7C,YAAY,CAAC,GAAG,CAAC,GAAG,mBAAW,CAAC;IAClC,CAAC,CAAC,CAAC;IAEH,MAAM,QAAS,SAAQ,oBAA6B;QAGlD,eAAe;YACb,uBACE,KAAK,EAAE,KAAK,CAAC,KAAK,IACf,GAAG,EACN;QACJ,CAAC;QAED,MAAM;YACJ,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;QAC7B,CAAC;;IAXM,0BAAiB,GAAG,YAAY,CAAC;IAc1C,IAAA,qBAAM,EAAC,IAAA,wBAAa,EAAC,QAAQ,EAAE,EAAE,EAAE,IAAA,wBAAa,EAAC,IAAW,EAAE,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAC7E,CAAC;AA5BD,oCA4BC;AAED,SAAgB,cAAc,CAAC,EAAe;IAC5C,2CAA2C;IAC3C,IAAA,qBAAM,EAAC,IAAI,EAAE,EAAE,CAAC,CAAC;AACnB,CAAC;AAHD,wCAGC"}
package/lib/types.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
- import { ForeignComponent, ExtensionSlotProps } from 'piral-core';
3
- import { Component, ComponentType } from 'react-15';
2
+ import type { ForeignComponent, ExtensionSlotProps } from 'piral-core';
3
+ import type { Component, ComponentType } from 'react-15';
4
4
  declare module 'piral-core/lib/types/custom' {
5
5
  interface PiletCustomApi extends PiletReact15Api {
6
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "piral-react-15",
3
- "version": "1.0.0-pre.2094",
3
+ "version": "1.0.1-beta.5640",
4
4
  "description": "Plugin for integrating React v15 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,19 +55,18 @@
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-react-15.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.2094",
67
+ "piral-core": "1.0.1-beta.5640",
43
68
  "react-15": "npm:react@15",
44
69
  "react-dom-15": "npm:react-dom@15"
45
70
  },
46
- "peerDependencies": {
47
- "piral-core": "1.x",
48
- "react-15": "*",
49
- "react-dom-15": "*"
50
- },
51
- "gitHead": "5b460d05d6ee78e774a2ed51020666e9a1a25aff"
71
+ "gitHead": "fa0a72b28fd0a20afec7ef491ec19e93c090fc72"
52
72
  }
package/src/converter.ts CHANGED
@@ -1,21 +1,30 @@
1
- import { ForeignComponent, BaseComponentProps } from 'piral-core';
2
- import { ComponentType } from 'react-15';
1
+ import type { ForeignComponent, BaseComponentProps } from 'piral-core';
2
+ import type { ComponentType } from 'react-15';
3
+ import { createExtension } from './extension';
3
4
  import { mountReact15, unmountReact15 } from './mount';
4
5
 
5
- export function createConverter() {
6
- const convert = <TProps extends BaseComponentProps>(root: ComponentType<TProps>): ForeignComponent<TProps> => {
7
- return {
8
- mount(el, props, ctx) {
9
- mountReact15(el, root, props, ctx);
10
- },
11
- update(el, props, ctx) {
12
- mountReact15(el, root, props, ctx);
13
- },
14
- unmount(el) {
15
- unmountReact15(el);
16
- },
17
- };
18
- };
6
+ export interface React15ConverterOptions {
7
+ /**
8
+ * Defines the name of the root element.
9
+ * @default piral-slot
10
+ */
11
+ rootName?: string;
12
+ }
19
13
 
14
+ export function createConverter(config: React15ConverterOptions = {}) {
15
+ const { rootName = 'piral-slot' } = config;
16
+ const Extension = createExtension(rootName);
17
+ const convert = <TProps extends BaseComponentProps>(root: ComponentType<TProps>): ForeignComponent<TProps> => ({
18
+ mount(el, props, ctx) {
19
+ mountReact15(el, root, props, ctx);
20
+ },
21
+ update(el, props, ctx) {
22
+ mountReact15(el, root, props, ctx);
23
+ },
24
+ unmount(el) {
25
+ unmountReact15(el);
26
+ },
27
+ });
28
+ convert.Extension = Extension;
20
29
  return convert;
21
30
  }
package/src/create.ts CHANGED
@@ -1,27 +1,18 @@
1
1
  import type { PiralPlugin } from 'piral-core';
2
- import { createConverter } from './converter';
3
- import { createExtension } from './extension';
2
+ import { createConverter, React15ConverterOptions } from './converter';
4
3
  import type { PiletReact15Api } from './types';
5
4
 
6
5
  /**
7
6
  * Available configuration options for the React 15.x plugin.
8
7
  */
9
- export interface React15Config {
10
- /**
11
- * Defines the name of the root element.
12
- * @default slot
13
- */
14
- rootName?: string;
15
- }
8
+ export interface React15Config extends React15ConverterOptions {}
16
9
 
17
10
  /**
18
11
  * Creates Pilet API extensions for integrating React 15.x.
19
12
  */
20
13
  export function createReact15Api(config: React15Config = {}): PiralPlugin<PiletReact15Api> {
21
- const { rootName } = config;
22
-
23
14
  return (context) => {
24
- const convert = createConverter();
15
+ const convert = createConverter(config);
25
16
  context.converters.react15 = ({ root }) => convert(root);
26
17
 
27
18
  return {
@@ -31,7 +22,7 @@ export function createReact15Api(config: React15Config = {}): PiralPlugin<PiletR
31
22
  root,
32
23
  };
33
24
  },
34
- React15Extension: createExtension(rootName),
25
+ React15Extension: convert.Extension,
35
26
  };
36
27
  };
37
28
  }
package/src/extension.ts CHANGED
@@ -1,8 +1,39 @@
1
- import { ExtensionSlotProps, compare } from 'piral-core';
1
+ import type { ExtensionSlotProps, PiletApi } from 'piral-core';
2
2
  import { createElement, Component } from 'react-15';
3
3
  import { anyPropType } from './mount';
4
4
 
5
- export function createExtension(rootName = 'slot') {
5
+ function compareObjects(a: any, b: any) {
6
+ for (const i in a) {
7
+ if (!(i in b)) {
8
+ return false;
9
+ }
10
+ }
11
+
12
+ for (const i in b) {
13
+ if (!compare(a[i], b[i])) {
14
+ return false;
15
+ }
16
+ }
17
+
18
+ return true;
19
+ }
20
+
21
+ function compare<T>(a: T, b: T) {
22
+ if (a !== b) {
23
+ const ta = typeof a;
24
+ const tb = typeof b;
25
+
26
+ if (ta === tb && ta === 'object' && a && b) {
27
+ return compareObjects(a, b);
28
+ }
29
+
30
+ return false;
31
+ }
32
+
33
+ return true;
34
+ }
35
+
36
+ export function createExtension(rootName: string) {
6
37
  const React15Extension: any = class extends Component<ExtensionSlotProps> {
7
38
  static contextTypes = {
8
39
  piral: anyPropType,
@@ -10,7 +41,7 @@ export function createExtension(rootName = 'slot') {
10
41
 
11
42
  private onRefChange = (element: HTMLElement) => {
12
43
  if (element) {
13
- const { piral } = this.context;
44
+ const { piral } = this.context as { piral: PiletApi };
14
45
  element.innerHTML = '';
15
46
  piral.renderHtmlExtension(element, this.props);
16
47
  }
package/src/mount.ts CHANGED
@@ -1,6 +1,6 @@
1
+ import type { BaseComponentProps } from 'piral-core';
1
2
  import { render } from 'react-dom-15';
2
3
  import { createElement, ComponentType, Component } from 'react-15';
3
- import { BaseComponentProps } from 'piral-core';
4
4
 
5
5
  // tslint:disable-next-line:no-null-keyword
6
6
  export const anyPropType = () => null;
@@ -17,7 +17,7 @@ export function mountReact15<T extends BaseComponentProps>(
17
17
  contextTypes[key] = anyPropType;
18
18
  });
19
19
 
20
- class Provider extends Component {
20
+ class Provider extends Component<{ children?: any }> {
21
21
  static childContextTypes = contextTypes;
22
22
 
23
23
  getChildContext() {
package/src/types.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { ForeignComponent, ExtensionSlotProps } from 'piral-core';
2
- import { Component, ComponentType } from 'react-15';
1
+ import type { ForeignComponent, ExtensionSlotProps } from 'piral-core';
2
+ import type { Component, ComponentType } from 'react-15';
3
3
 
4
4
  declare module 'piral-core/lib/types/custom' {
5
5
  interface PiletCustomApi extends PiletReact15Api {}
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 React15Converter {
8
- (...params: Parameters<typeof convert>): HtmlComponent<any>;
9
- }
10
-
11
- export const fromReact15: React15Converter = (root) => ({
12
- type: 'html',
13
- component: convert(root),
14
- });
15
-
16
- export const createReact15Extension = createExtension;