piral-million 0.15.0-beta.4574
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 +21 -0
- package/README.md +95 -0
- package/convert.d.ts +18 -0
- package/convert.js +16 -0
- package/esm/converter.d.ts +13 -0
- package/esm/converter.js +20 -0
- package/esm/converter.js.map +1 -0
- package/esm/create.d.ts +12 -0
- package/esm/create.js +20 -0
- package/esm/create.js.map +1 -0
- package/esm/extension.d.ts +3 -0
- package/esm/extension.js +45 -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/mount.d.ts +5 -0
- package/esm/mount.js +15 -0
- package/esm/mount.js.map +1 -0
- package/esm/types.d.ts +34 -0
- package/esm/types.js +2 -0
- package/esm/types.js.map +1 -0
- package/lib/converter.d.ts +13 -0
- package/lib/converter.js +24 -0
- package/lib/converter.js.map +1 -0
- package/lib/create.d.ts +12 -0
- package/lib/create.js +24 -0
- package/lib/create.js.map +1 -0
- package/lib/extension.d.ts +3 -0
- package/lib/extension.js +49 -0
- package/lib/extension.js.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +6 -0
- package/lib/index.js.map +1 -0
- package/lib/mount.d.ts +5 -0
- package/lib/mount.js +21 -0
- package/lib/mount.js.map +1 -0
- package/lib/types.d.ts +34 -0
- package/lib/types.js +3 -0
- package/lib/types.js.map +1 -0
- package/package.json +74 -0
- package/src/converter.ts +30 -0
- package/src/create.ts +28 -0
- package/src/extension.ts +53 -0
- package/src/index.ts +2 -0
- package/src/mount.ts +23 -0
- package/src/types.ts +37 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 - 2022 smapiot
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
[](https://piral.io)
|
|
2
|
+
|
|
3
|
+
# [Piral Million](https://piral.io) · [](https://github.com/smapiot/piral/blob/main/LICENSE) [](https://www.npmjs.com/package/piral-million) [](https://jestjs.io) [](https://gitter.im/piral-io/community)
|
|
4
|
+
|
|
5
|
+
This is a plugin that only has a peer dependency to `million`. What `piral-million` brings to the table is a set of Pilet API extensions that can be used with `piral` or `piral-core`.
|
|
6
|
+
|
|
7
|
+
The set includes a Million converter for any component registration, as well as a `fromMillion` shortcut and a `MillionExtension` component.
|
|
8
|
+
|
|
9
|
+
By default, these API extensions are not integrated in `piral`, so you'd need to add them to your Piral instance.
|
|
10
|
+
|
|
11
|
+
## Documentation
|
|
12
|
+
|
|
13
|
+
The following functions are brought to the Pilet API.
|
|
14
|
+
|
|
15
|
+
### `fromMillion()`
|
|
16
|
+
|
|
17
|
+
Transforms a standard Million component into a component that can be used in Piral, essentially wrapping it with a reference to the corresponding converter.
|
|
18
|
+
|
|
19
|
+
### `MillionExtension`
|
|
20
|
+
|
|
21
|
+
The extension slot component to be used in Million component.
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
::: summary: For pilet authors
|
|
26
|
+
|
|
27
|
+
You can use the `fromMillion` function from the Pilet API to convert your Million components to components usable by your Piral instance.
|
|
28
|
+
|
|
29
|
+
Example use:
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import { PiletApi } from '<name-of-piral-instance>';
|
|
33
|
+
import { MillionPage } from './MillionPage';
|
|
34
|
+
|
|
35
|
+
export function setup(piral: PiletApi) {
|
|
36
|
+
piral.registerPage('/sample', piral.fromMillion(MillionPage));
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Within Million components the Piral Million extension component can be used by referring to `MillionExtension`, e.g.,
|
|
41
|
+
|
|
42
|
+
```jsx
|
|
43
|
+
<MillionExtension name="name-of-extension" />
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Alternatively, if `piral-million` has not been added to the Piral instance you can install and use the package also from a pilet directly.
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
import { PiletApi } from '<name-of-piral-instance>';
|
|
50
|
+
import { fromMillion } from 'piral-million/convert';
|
|
51
|
+
import { MillionPage } from './MillionPage';
|
|
52
|
+
|
|
53
|
+
export function setup(piral: PiletApi) {
|
|
54
|
+
piral.registerPage('/sample', fromMillion(MillionPage));
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
:::
|
|
59
|
+
|
|
60
|
+
::: summary: For Piral instance developers
|
|
61
|
+
|
|
62
|
+
Using Million with Piral is as simple as installing `piral-million` and `million`.
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
import 'million';
|
|
66
|
+
import { createMillionApi } from 'piral-million';
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
The integration looks like:
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
const instance = createInstance({
|
|
73
|
+
// important part
|
|
74
|
+
plugins: [createMillionApi()],
|
|
75
|
+
// ...
|
|
76
|
+
});
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
The `million` package should be shared with the pilets via the *package.json*:
|
|
80
|
+
|
|
81
|
+
```json
|
|
82
|
+
{
|
|
83
|
+
"pilets": {
|
|
84
|
+
"externals": [
|
|
85
|
+
"million"
|
|
86
|
+
]
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
:::
|
|
92
|
+
|
|
93
|
+
## License
|
|
94
|
+
|
|
95
|
+
Piral is released using the MIT license. For more information see the [license file](./LICENSE).
|
package/convert.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
}
|
|
10
|
+
export interface MillionConverter {
|
|
11
|
+
(...params: Parameters<ReturnType<typeof createConverter>>): HtmlComponent<any>;
|
|
12
|
+
}
|
|
13
|
+
export declare function createMillionConverter(...params: Parameters<typeof createConverter>): {
|
|
14
|
+
from: MillionConverter;
|
|
15
|
+
Extension: (props: any) => VNode;
|
|
16
|
+
};
|
|
17
|
+
declare const fromMillion: MillionConverter, MillionExtension: (props: any) => VNode;
|
|
18
|
+
export { fromMillion, MillionExtension };
|
package/convert.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createConverter } from './esm/converter';
|
|
2
|
+
export function createMillionConverter() {
|
|
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 = createMillionConverter(), fromMillion = _a.from, MillionExtension = _a.Extension;
|
|
16
|
+
export { fromMillion, MillionExtension };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ForeignComponent, BaseComponentProps } from 'piral-core';
|
|
2
|
+
import type { VNode } from 'million';
|
|
3
|
+
export interface MillionConverterOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Defines the name of the root element.
|
|
6
|
+
* @default slot
|
|
7
|
+
*/
|
|
8
|
+
rootName?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function createConverter(config?: MillionConverterOptions): {
|
|
11
|
+
<TProps extends BaseComponentProps>(root: (props: TProps) => VNode): ForeignComponent<TProps>;
|
|
12
|
+
Extension: (props: import("piral-core").ExtensionSlotProps<string>) => VNode;
|
|
13
|
+
};
|
package/esm/converter.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { mountMillion, updateMillion, unmountMillion } from './mount';
|
|
2
|
+
import { createExtension } from './extension';
|
|
3
|
+
export function createConverter(config = {}) {
|
|
4
|
+
const { rootName = 'slot' } = config;
|
|
5
|
+
const Extension = createExtension(rootName);
|
|
6
|
+
const convert = (root) => ({
|
|
7
|
+
mount(el, props, ctx, locals) {
|
|
8
|
+
locals.node = mountMillion(el, root, props);
|
|
9
|
+
},
|
|
10
|
+
update(el, props, ctx, locals) {
|
|
11
|
+
locals.node = updateMillion(el, root, props, locals.node);
|
|
12
|
+
},
|
|
13
|
+
unmount(el, locals) {
|
|
14
|
+
unmountMillion(el, locals.node);
|
|
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,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAU9C,MAAM,UAAU,eAAe,CAAC,SAAkC,EAAE;IAClE,MAAM,EAAE,QAAQ,GAAG,MAAM,EAAE,GAAG,MAAM,CAAC;IACrC,MAAM,SAAS,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC;IAC5C,MAAM,OAAO,GAAG,CAAoC,IAA8B,EAA4B,EAAE,CAAC,CAAC;QAChH,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM;YAC1B,MAAM,CAAC,IAAI,GAAG,YAAY,CAAC,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;QAC9C,CAAC;QACD,MAAM,CAAC,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM;YAC3B,MAAM,CAAC,IAAI,GAAG,aAAa,CAAC,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;QAC5D,CAAC;QACD,OAAO,CAAC,EAAE,EAAE,MAAM;YAChB,cAAc,CAAC,EAAE,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;QAClC,CAAC;KACF,CAAC,CAAC;IACH,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;IAC9B,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/esm/create.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { PiralPlugin } from 'piral-core';
|
|
2
|
+
import { MillionConverterOptions } from './converter';
|
|
3
|
+
import type { PiletMillionApi } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* Available configuration options for the Million plugin.
|
|
6
|
+
*/
|
|
7
|
+
export interface MillionConfig extends MillionConverterOptions {
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Creates new Pilet API extensions for integrating Million.
|
|
11
|
+
*/
|
|
12
|
+
export declare function createMillionApi(config?: MillionConfig): PiralPlugin<PiletMillionApi>;
|
package/esm/create.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createConverter } from './converter';
|
|
2
|
+
/**
|
|
3
|
+
* Creates new Pilet API extensions for integrating Million.
|
|
4
|
+
*/
|
|
5
|
+
export function createMillionApi(config = {}) {
|
|
6
|
+
return (context) => {
|
|
7
|
+
const convert = createConverter(config);
|
|
8
|
+
context.converters.million = ({ root }) => convert(root);
|
|
9
|
+
return {
|
|
10
|
+
fromMillion(root) {
|
|
11
|
+
return {
|
|
12
|
+
type: 'million',
|
|
13
|
+
root,
|
|
14
|
+
};
|
|
15
|
+
},
|
|
16
|
+
MillionExtension: 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"}
|
package/esm/extension.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { m, _ } from 'million';
|
|
2
|
+
function compareObjects(a, b) {
|
|
3
|
+
for (const i in a) {
|
|
4
|
+
if (!(i in b)) {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
for (const i in b) {
|
|
9
|
+
if (!compare(a[i], b[i])) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
function compare(a, b) {
|
|
16
|
+
if (a !== b) {
|
|
17
|
+
const ta = typeof a;
|
|
18
|
+
const tb = typeof b;
|
|
19
|
+
if (ta === tb && ta === 'object' && a && b) {
|
|
20
|
+
return compareObjects(a, b);
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
export function createExtension(rootName) {
|
|
27
|
+
return (props) => {
|
|
28
|
+
return m(rootName, props, _, _, _, {
|
|
29
|
+
create(node) {
|
|
30
|
+
const { piral } = props;
|
|
31
|
+
node.textContent = '';
|
|
32
|
+
node.childNodes.forEach((n) => node.removeChild(n));
|
|
33
|
+
piral.renderHtmlExtension(node, this.props);
|
|
34
|
+
return true;
|
|
35
|
+
},
|
|
36
|
+
update(node, newNode, oldNode) {
|
|
37
|
+
if (!compare(newNode.props, oldNode.props)) {
|
|
38
|
+
//TODO render extension
|
|
39
|
+
}
|
|
40
|
+
return true;
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=extension.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAS,CAAC,EAAE,MAAM,SAAS,CAAC;AAGtC,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,OAAO,CAAC,KAAK,EAAE,EAAE;QACf,OAAO,CAAC,CAAC,QAAQ,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE;YACjC,MAAM,CAAC,IAAI;gBACT,MAAM,EAAE,KAAK,EAAE,GAAG,KAAY,CAAC;gBAC/B,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;gBACtB,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;gBACpD,KAAK,CAAC,mBAAmB,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;gBAC5C,OAAO,IAAI,CAAC;YACd,CAAC;YACD,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO;gBAC3B,IAAI,CAAC,OAAO,CAAE,OAAe,CAAC,KAAK,EAAG,OAAe,CAAC,KAAK,CAAC,EAAE;oBAC5D,uBAAuB;iBACxB;gBACD,OAAO,IAAI,CAAC;YACd,CAAC;SACF,CAAC,CAAC;IACL,CAAC,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/mount.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { VNode } from 'million';
|
|
2
|
+
import type { BaseComponentProps } from 'piral-core';
|
|
3
|
+
export declare function mountMillion<T extends BaseComponentProps>(el: HTMLElement, root: (props: T) => VNode, props: T): import("million/dist/types-1b5601ee").a;
|
|
4
|
+
export declare function updateMillion<T extends BaseComponentProps>(el: HTMLElement, root: (props: T) => VNode, props: T, oldNode: VNode): import("million/dist/types-1b5601ee").a;
|
|
5
|
+
export declare function unmountMillion(el: HTMLElement, oldNode: VNode): void;
|
package/esm/mount.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { render, m } from 'million';
|
|
2
|
+
export function mountMillion(el, root, props) {
|
|
3
|
+
const node = m(root, props);
|
|
4
|
+
render(el, node);
|
|
5
|
+
return node;
|
|
6
|
+
}
|
|
7
|
+
export function updateMillion(el, root, props, oldNode) {
|
|
8
|
+
const newNode = m(root, props);
|
|
9
|
+
render(el, newNode, oldNode);
|
|
10
|
+
return newNode;
|
|
11
|
+
}
|
|
12
|
+
export function unmountMillion(el, oldNode) {
|
|
13
|
+
render(el, '', oldNode);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=mount.js.map
|
package/esm/mount.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mount.js","sourceRoot":"","sources":["../src/mount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,CAAC,EAAS,MAAM,SAAS,CAAC;AAG3C,MAAM,UAAU,YAAY,CAA+B,EAAe,EAAE,IAAyB,EAAE,KAAQ;IAC7G,MAAM,IAAI,GAAG,CAAC,CAAC,IAAW,EAAE,KAAK,CAAC,CAAC;IACnC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IACjB,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,aAAa,CAC3B,EAAe,EACf,IAAyB,EACzB,KAAQ,EACR,OAAc;IAEd,MAAM,OAAO,GAAG,CAAC,CAAC,IAAW,EAAE,KAAK,CAAC,CAAC;IACtC,MAAM,CAAC,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAC7B,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,EAAe,EAAE,OAAc;IAC5D,MAAM,CAAC,EAAE,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;AAC1B,CAAC"}
|
package/esm/types.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { VNode } from 'million';
|
|
2
|
+
import type { ForeignComponent, ExtensionSlotProps } from 'piral-core';
|
|
3
|
+
declare module 'piral-core/lib/types/custom' {
|
|
4
|
+
interface PiletCustomApi extends PiletMillionApi {
|
|
5
|
+
}
|
|
6
|
+
interface PiralCustomComponentConverters<TProps> {
|
|
7
|
+
million(component: MillionComponent<TProps>): ForeignComponent<TProps>;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export interface MillionComponent<TProps> {
|
|
11
|
+
/**
|
|
12
|
+
* The component root.
|
|
13
|
+
*/
|
|
14
|
+
root: (props: TProps) => VNode;
|
|
15
|
+
/**
|
|
16
|
+
* The type of the Million component.
|
|
17
|
+
*/
|
|
18
|
+
type: 'million';
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Defines the provided set of Million Pilet API extensions.
|
|
22
|
+
*/
|
|
23
|
+
export interface PiletMillionApi {
|
|
24
|
+
/**
|
|
25
|
+
* Wraps an Million component for use in Piral.
|
|
26
|
+
* @param component The component root.
|
|
27
|
+
* @returns The Piral Million component.
|
|
28
|
+
*/
|
|
29
|
+
fromMillion<TProps>(component: (props: TProps) => VNode): MillionComponent<TProps>;
|
|
30
|
+
/**
|
|
31
|
+
* Million component for displaying extensions of the given name.
|
|
32
|
+
*/
|
|
33
|
+
MillionExtension: (props: ExtensionSlotProps) => VNode;
|
|
34
|
+
}
|
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":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ForeignComponent, BaseComponentProps } from 'piral-core';
|
|
2
|
+
import type { VNode } from 'million';
|
|
3
|
+
export interface MillionConverterOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Defines the name of the root element.
|
|
6
|
+
* @default slot
|
|
7
|
+
*/
|
|
8
|
+
rootName?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function createConverter(config?: MillionConverterOptions): {
|
|
11
|
+
<TProps extends BaseComponentProps>(root: (props: TProps) => VNode): ForeignComponent<TProps>;
|
|
12
|
+
Extension: (props: import("piral-core").ExtensionSlotProps<string>) => VNode;
|
|
13
|
+
};
|
package/lib/converter.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createConverter = void 0;
|
|
4
|
+
const mount_1 = require("./mount");
|
|
5
|
+
const extension_1 = require("./extension");
|
|
6
|
+
function createConverter(config = {}) {
|
|
7
|
+
const { rootName = 'slot' } = config;
|
|
8
|
+
const Extension = (0, extension_1.createExtension)(rootName);
|
|
9
|
+
const convert = (root) => ({
|
|
10
|
+
mount(el, props, ctx, locals) {
|
|
11
|
+
locals.node = (0, mount_1.mountMillion)(el, root, props);
|
|
12
|
+
},
|
|
13
|
+
update(el, props, ctx, locals) {
|
|
14
|
+
locals.node = (0, mount_1.updateMillion)(el, root, props, locals.node);
|
|
15
|
+
},
|
|
16
|
+
unmount(el, locals) {
|
|
17
|
+
(0, mount_1.unmountMillion)(el, locals.node);
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
convert.Extension = Extension;
|
|
21
|
+
return convert;
|
|
22
|
+
}
|
|
23
|
+
exports.createConverter = createConverter;
|
|
24
|
+
//# sourceMappingURL=converter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"converter.js","sourceRoot":"","sources":["../src/converter.ts"],"names":[],"mappings":";;;AAEA,mCAAsE;AACtE,2CAA8C;AAU9C,SAAgB,eAAe,CAAC,SAAkC,EAAE;IAClE,MAAM,EAAE,QAAQ,GAAG,MAAM,EAAE,GAAG,MAAM,CAAC;IACrC,MAAM,SAAS,GAAG,IAAA,2BAAe,EAAC,QAAQ,CAAC,CAAC;IAC5C,MAAM,OAAO,GAAG,CAAoC,IAA8B,EAA4B,EAAE,CAAC,CAAC;QAChH,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM;YAC1B,MAAM,CAAC,IAAI,GAAG,IAAA,oBAAY,EAAC,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;QAC9C,CAAC;QACD,MAAM,CAAC,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM;YAC3B,MAAM,CAAC,IAAI,GAAG,IAAA,qBAAa,EAAC,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;QAC5D,CAAC;QACD,OAAO,CAAC,EAAE,EAAE,MAAM;YAChB,IAAA,sBAAc,EAAC,EAAE,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;QAClC,CAAC;KACF,CAAC,CAAC;IACH,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;IAC9B,OAAO,OAAO,CAAC;AACjB,CAAC;AAhBD,0CAgBC"}
|
package/lib/create.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { PiralPlugin } from 'piral-core';
|
|
2
|
+
import { MillionConverterOptions } from './converter';
|
|
3
|
+
import type { PiletMillionApi } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* Available configuration options for the Million plugin.
|
|
6
|
+
*/
|
|
7
|
+
export interface MillionConfig extends MillionConverterOptions {
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Creates new Pilet API extensions for integrating Million.
|
|
11
|
+
*/
|
|
12
|
+
export declare function createMillionApi(config?: MillionConfig): PiralPlugin<PiletMillionApi>;
|
package/lib/create.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createMillionApi = void 0;
|
|
4
|
+
const converter_1 = require("./converter");
|
|
5
|
+
/**
|
|
6
|
+
* Creates new Pilet API extensions for integrating Million.
|
|
7
|
+
*/
|
|
8
|
+
function createMillionApi(config = {}) {
|
|
9
|
+
return (context) => {
|
|
10
|
+
const convert = (0, converter_1.createConverter)(config);
|
|
11
|
+
context.converters.million = ({ root }) => convert(root);
|
|
12
|
+
return {
|
|
13
|
+
fromMillion(root) {
|
|
14
|
+
return {
|
|
15
|
+
type: 'million',
|
|
16
|
+
root,
|
|
17
|
+
};
|
|
18
|
+
},
|
|
19
|
+
MillionExtension: convert.Extension,
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
exports.createMillionApi = createMillionApi;
|
|
24
|
+
//# sourceMappingURL=create.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
package/lib/extension.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createExtension = void 0;
|
|
4
|
+
const million_1 = require("million");
|
|
5
|
+
function compareObjects(a, b) {
|
|
6
|
+
for (const i in a) {
|
|
7
|
+
if (!(i in b)) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
for (const i in b) {
|
|
12
|
+
if (!compare(a[i], b[i])) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
function compare(a, b) {
|
|
19
|
+
if (a !== b) {
|
|
20
|
+
const ta = typeof a;
|
|
21
|
+
const tb = typeof b;
|
|
22
|
+
if (ta === tb && ta === 'object' && a && b) {
|
|
23
|
+
return compareObjects(a, b);
|
|
24
|
+
}
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
function createExtension(rootName) {
|
|
30
|
+
return (props) => {
|
|
31
|
+
return (0, million_1.m)(rootName, props, million_1._, million_1._, million_1._, {
|
|
32
|
+
create(node) {
|
|
33
|
+
const { piral } = props;
|
|
34
|
+
node.textContent = '';
|
|
35
|
+
node.childNodes.forEach((n) => node.removeChild(n));
|
|
36
|
+
piral.renderHtmlExtension(node, this.props);
|
|
37
|
+
return true;
|
|
38
|
+
},
|
|
39
|
+
update(node, newNode, oldNode) {
|
|
40
|
+
if (!compare(newNode.props, oldNode.props)) {
|
|
41
|
+
//TODO render extension
|
|
42
|
+
}
|
|
43
|
+
return true;
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
exports.createExtension = createExtension;
|
|
49
|
+
//# sourceMappingURL=extension.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":";;;AAAA,qCAAsC;AAGtC,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,OAAO,CAAC,KAAK,EAAE,EAAE;QACf,OAAO,IAAA,WAAC,EAAC,QAAQ,EAAE,KAAK,EAAE,WAAC,EAAE,WAAC,EAAE,WAAC,EAAE;YACjC,MAAM,CAAC,IAAI;gBACT,MAAM,EAAE,KAAK,EAAE,GAAG,KAAY,CAAC;gBAC/B,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;gBACtB,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;gBACpD,KAAK,CAAC,mBAAmB,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;gBAC5C,OAAO,IAAI,CAAC;YACd,CAAC;YACD,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO;gBAC3B,IAAI,CAAC,OAAO,CAAE,OAAe,CAAC,KAAK,EAAG,OAAe,CAAC,KAAK,CAAC,EAAE;oBAC5D,uBAAuB;iBACxB;gBACD,OAAO,IAAI,CAAC;YACd,CAAC;SACF,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAlBD,0CAkBC"}
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mDAAyB;AACzB,kDAAwB"}
|
package/lib/mount.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { VNode } from 'million';
|
|
2
|
+
import type { BaseComponentProps } from 'piral-core';
|
|
3
|
+
export declare function mountMillion<T extends BaseComponentProps>(el: HTMLElement, root: (props: T) => VNode, props: T): import("million/dist/types-1b5601ee").a;
|
|
4
|
+
export declare function updateMillion<T extends BaseComponentProps>(el: HTMLElement, root: (props: T) => VNode, props: T, oldNode: VNode): import("million/dist/types-1b5601ee").a;
|
|
5
|
+
export declare function unmountMillion(el: HTMLElement, oldNode: VNode): void;
|
package/lib/mount.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.unmountMillion = exports.updateMillion = exports.mountMillion = void 0;
|
|
4
|
+
const million_1 = require("million");
|
|
5
|
+
function mountMillion(el, root, props) {
|
|
6
|
+
const node = (0, million_1.m)(root, props);
|
|
7
|
+
(0, million_1.render)(el, node);
|
|
8
|
+
return node;
|
|
9
|
+
}
|
|
10
|
+
exports.mountMillion = mountMillion;
|
|
11
|
+
function updateMillion(el, root, props, oldNode) {
|
|
12
|
+
const newNode = (0, million_1.m)(root, props);
|
|
13
|
+
(0, million_1.render)(el, newNode, oldNode);
|
|
14
|
+
return newNode;
|
|
15
|
+
}
|
|
16
|
+
exports.updateMillion = updateMillion;
|
|
17
|
+
function unmountMillion(el, oldNode) {
|
|
18
|
+
(0, million_1.render)(el, '', oldNode);
|
|
19
|
+
}
|
|
20
|
+
exports.unmountMillion = unmountMillion;
|
|
21
|
+
//# sourceMappingURL=mount.js.map
|
package/lib/mount.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mount.js","sourceRoot":"","sources":["../src/mount.ts"],"names":[],"mappings":";;;AAAA,qCAA2C;AAG3C,SAAgB,YAAY,CAA+B,EAAe,EAAE,IAAyB,EAAE,KAAQ;IAC7G,MAAM,IAAI,GAAG,IAAA,WAAC,EAAC,IAAW,EAAE,KAAK,CAAC,CAAC;IACnC,IAAA,gBAAM,EAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IACjB,OAAO,IAAI,CAAC;AACd,CAAC;AAJD,oCAIC;AAED,SAAgB,aAAa,CAC3B,EAAe,EACf,IAAyB,EACzB,KAAQ,EACR,OAAc;IAEd,MAAM,OAAO,GAAG,IAAA,WAAC,EAAC,IAAW,EAAE,KAAK,CAAC,CAAC;IACtC,IAAA,gBAAM,EAAC,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAC7B,OAAO,OAAO,CAAC;AACjB,CAAC;AATD,sCASC;AAED,SAAgB,cAAc,CAAC,EAAe,EAAE,OAAc;IAC5D,IAAA,gBAAM,EAAC,EAAE,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;AAC1B,CAAC;AAFD,wCAEC"}
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { VNode } from 'million';
|
|
2
|
+
import type { ForeignComponent, ExtensionSlotProps } from 'piral-core';
|
|
3
|
+
declare module 'piral-core/lib/types/custom' {
|
|
4
|
+
interface PiletCustomApi extends PiletMillionApi {
|
|
5
|
+
}
|
|
6
|
+
interface PiralCustomComponentConverters<TProps> {
|
|
7
|
+
million(component: MillionComponent<TProps>): ForeignComponent<TProps>;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export interface MillionComponent<TProps> {
|
|
11
|
+
/**
|
|
12
|
+
* The component root.
|
|
13
|
+
*/
|
|
14
|
+
root: (props: TProps) => VNode;
|
|
15
|
+
/**
|
|
16
|
+
* The type of the Million component.
|
|
17
|
+
*/
|
|
18
|
+
type: 'million';
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Defines the provided set of Million Pilet API extensions.
|
|
22
|
+
*/
|
|
23
|
+
export interface PiletMillionApi {
|
|
24
|
+
/**
|
|
25
|
+
* Wraps an Million component for use in Piral.
|
|
26
|
+
* @param component The component root.
|
|
27
|
+
* @returns The Piral Million component.
|
|
28
|
+
*/
|
|
29
|
+
fromMillion<TProps>(component: (props: TProps) => VNode): MillionComponent<TProps>;
|
|
30
|
+
/**
|
|
31
|
+
* Million component for displaying extensions of the given name.
|
|
32
|
+
*/
|
|
33
|
+
MillionExtension: (props: ExtensionSlotProps) => VNode;
|
|
34
|
+
}
|
package/lib/types.js
ADDED
package/lib/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "piral-million",
|
|
3
|
+
"version": "0.15.0-beta.4574",
|
|
4
|
+
"description": "Plugin for integrating Million components in Piral.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"piral",
|
|
7
|
+
"pilet-api",
|
|
8
|
+
"smapiot",
|
|
9
|
+
"portal",
|
|
10
|
+
"modules",
|
|
11
|
+
"api",
|
|
12
|
+
"plugin",
|
|
13
|
+
"plugin-converter",
|
|
14
|
+
"million"
|
|
15
|
+
],
|
|
16
|
+
"author": "smapiot",
|
|
17
|
+
"homepage": "https://piral.io",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"module": "esm/index.js",
|
|
20
|
+
"main": "lib/index.js",
|
|
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
|
+
},
|
|
42
|
+
"sideEffects": false,
|
|
43
|
+
"files": [
|
|
44
|
+
"esm",
|
|
45
|
+
"lib",
|
|
46
|
+
"src",
|
|
47
|
+
"convert.d.ts",
|
|
48
|
+
"convert.js"
|
|
49
|
+
],
|
|
50
|
+
"repository": {
|
|
51
|
+
"type": "git",
|
|
52
|
+
"url": "git+https://github.com/smapiot/piral.git"
|
|
53
|
+
},
|
|
54
|
+
"bugs": {
|
|
55
|
+
"url": "https://github.com/smapiot/piral/issues"
|
|
56
|
+
},
|
|
57
|
+
"scripts": {
|
|
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",
|
|
63
|
+
"typedoc": "typedoc --json ../../../docs/types/piral-million.json src --exclude \"src/**/*.test.*\"",
|
|
64
|
+
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
65
|
+
},
|
|
66
|
+
"devDependencies": {
|
|
67
|
+
"million": "^1.12.0",
|
|
68
|
+
"piral-core": "0.15.0-beta.4574"
|
|
69
|
+
},
|
|
70
|
+
"peerDependencies": {
|
|
71
|
+
"million": "^1.0.0"
|
|
72
|
+
},
|
|
73
|
+
"gitHead": "914a7b4c14d9b161731f80756f3e175f0444e874"
|
|
74
|
+
}
|
package/src/converter.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ForeignComponent, BaseComponentProps } from 'piral-core';
|
|
2
|
+
import type { VNode } from 'million';
|
|
3
|
+
import { mountMillion, updateMillion, unmountMillion } from './mount';
|
|
4
|
+
import { createExtension } from './extension';
|
|
5
|
+
|
|
6
|
+
export interface MillionConverterOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Defines the name of the root element.
|
|
9
|
+
* @default slot
|
|
10
|
+
*/
|
|
11
|
+
rootName?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function createConverter(config: MillionConverterOptions = {}) {
|
|
15
|
+
const { rootName = 'slot' } = config;
|
|
16
|
+
const Extension = createExtension(rootName);
|
|
17
|
+
const convert = <TProps extends BaseComponentProps>(root: (props: TProps) => VNode): ForeignComponent<TProps> => ({
|
|
18
|
+
mount(el, props, ctx, locals) {
|
|
19
|
+
locals.node = mountMillion(el, root, props);
|
|
20
|
+
},
|
|
21
|
+
update(el, props, ctx, locals) {
|
|
22
|
+
locals.node = updateMillion(el, root, props, locals.node);
|
|
23
|
+
},
|
|
24
|
+
unmount(el, locals) {
|
|
25
|
+
unmountMillion(el, locals.node);
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
convert.Extension = Extension;
|
|
29
|
+
return convert;
|
|
30
|
+
}
|
package/src/create.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { PiralPlugin } from 'piral-core';
|
|
2
|
+
import { createConverter, MillionConverterOptions } from './converter';
|
|
3
|
+
import type { PiletMillionApi } from './types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Available configuration options for the Million plugin.
|
|
7
|
+
*/
|
|
8
|
+
export interface MillionConfig extends MillionConverterOptions {}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Creates new Pilet API extensions for integrating Million.
|
|
12
|
+
*/
|
|
13
|
+
export function createMillionApi(config: MillionConfig = {}): PiralPlugin<PiletMillionApi> {
|
|
14
|
+
return (context) => {
|
|
15
|
+
const convert = createConverter(config);
|
|
16
|
+
context.converters.million = ({ root }) => convert(root);
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
fromMillion(root) {
|
|
20
|
+
return {
|
|
21
|
+
type: 'million',
|
|
22
|
+
root,
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
MillionExtension: convert.Extension,
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
}
|
package/src/extension.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { m, VNode, _ } from 'million';
|
|
2
|
+
import type { ExtensionSlotProps } from 'piral-core';
|
|
3
|
+
|
|
4
|
+
function compareObjects(a: any, b: any) {
|
|
5
|
+
for (const i in a) {
|
|
6
|
+
if (!(i in b)) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
for (const i in b) {
|
|
12
|
+
if (!compare(a[i], b[i])) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function compare<T>(a: T, b: T) {
|
|
21
|
+
if (a !== b) {
|
|
22
|
+
const ta = typeof a;
|
|
23
|
+
const tb = typeof b;
|
|
24
|
+
|
|
25
|
+
if (ta === tb && ta === 'object' && a && b) {
|
|
26
|
+
return compareObjects(a, b);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function createExtension(rootName: string): (props: ExtensionSlotProps) => VNode {
|
|
36
|
+
return (props) => {
|
|
37
|
+
return m(rootName, props, _, _, _, {
|
|
38
|
+
create(node) {
|
|
39
|
+
const { piral } = props as any;
|
|
40
|
+
node.textContent = '';
|
|
41
|
+
node.childNodes.forEach((n) => node.removeChild(n));
|
|
42
|
+
piral.renderHtmlExtension(node, this.props);
|
|
43
|
+
return true;
|
|
44
|
+
},
|
|
45
|
+
update(node, newNode, oldNode) {
|
|
46
|
+
if (!compare((newNode as any).props, (oldNode as any).props)) {
|
|
47
|
+
//TODO render extension
|
|
48
|
+
}
|
|
49
|
+
return true;
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
}
|
package/src/index.ts
ADDED
package/src/mount.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { render, m, VNode } from 'million';
|
|
2
|
+
import type { BaseComponentProps } from 'piral-core';
|
|
3
|
+
|
|
4
|
+
export function mountMillion<T extends BaseComponentProps>(el: HTMLElement, root: (props: T) => VNode, props: T) {
|
|
5
|
+
const node = m(root as any, props);
|
|
6
|
+
render(el, node);
|
|
7
|
+
return node;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function updateMillion<T extends BaseComponentProps>(
|
|
11
|
+
el: HTMLElement,
|
|
12
|
+
root: (props: T) => VNode,
|
|
13
|
+
props: T,
|
|
14
|
+
oldNode: VNode,
|
|
15
|
+
) {
|
|
16
|
+
const newNode = m(root as any, props);
|
|
17
|
+
render(el, newNode, oldNode);
|
|
18
|
+
return newNode;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function unmountMillion(el: HTMLElement, oldNode: VNode) {
|
|
22
|
+
render(el, '', oldNode);
|
|
23
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { VNode } from 'million';
|
|
2
|
+
import type { ForeignComponent, ExtensionSlotProps } from 'piral-core';
|
|
3
|
+
|
|
4
|
+
declare module 'piral-core/lib/types/custom' {
|
|
5
|
+
interface PiletCustomApi extends PiletMillionApi {}
|
|
6
|
+
|
|
7
|
+
interface PiralCustomComponentConverters<TProps> {
|
|
8
|
+
million(component: MillionComponent<TProps>): ForeignComponent<TProps>;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface MillionComponent<TProps> {
|
|
13
|
+
/**
|
|
14
|
+
* The component root.
|
|
15
|
+
*/
|
|
16
|
+
root: (props: TProps) => VNode;
|
|
17
|
+
/**
|
|
18
|
+
* The type of the Million component.
|
|
19
|
+
*/
|
|
20
|
+
type: 'million';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Defines the provided set of Million Pilet API extensions.
|
|
25
|
+
*/
|
|
26
|
+
export interface PiletMillionApi {
|
|
27
|
+
/**
|
|
28
|
+
* Wraps an Million component for use in Piral.
|
|
29
|
+
* @param component The component root.
|
|
30
|
+
* @returns The Piral Million component.
|
|
31
|
+
*/
|
|
32
|
+
fromMillion<TProps>(component: (props: TProps) => VNode): MillionComponent<TProps>;
|
|
33
|
+
/**
|
|
34
|
+
* Million component for displaying extensions of the given name.
|
|
35
|
+
*/
|
|
36
|
+
MillionExtension: (props: ExtensionSlotProps) => VNode;
|
|
37
|
+
}
|