piral-ngjs 1.0.0-pre.2036 → 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 +1 -1
- package/README.md +9 -9
- package/convert.d.ts +16 -7
- package/convert.js +16 -11
- package/esm/converter.d.ts +13 -0
- package/esm/converter.js +23 -0
- package/esm/converter.js.map +1 -0
- package/esm/create.d.ts +12 -0
- package/esm/create.js +21 -0
- package/esm/create.js.map +1 -0
- package/esm/extension.d.ts +2 -0
- package/esm/extension.js +30 -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 +20 -19
- package/lib/converter.js.map +1 -1
- package/lib/create.d.ts +4 -8
- package/lib/create.js +9 -16
- package/lib/create.js.map +1 -1
- package/lib/extension.d.ts +1 -1
- package/lib/extension.js +9 -11
- package/lib/extension.js.map +1 -1
- package/lib/index.js +1 -1
- package/package.json +30 -9
- package/src/converter.ts +31 -19
- package/src/create.ts +6 -16
- package/src/extension.ts +1 -1
- package/convert.ts +0 -16
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
[](https://piral.io)
|
|
2
2
|
|
|
3
|
-
# [Piral NgJS](https://piral.io) · [](https://github.com/smapiot/piral/blob/
|
|
3
|
+
# [Piral NgJS](https://piral.io) · [](https://github.com/smapiot/piral/blob/main/LICENSE) [](https://www.npmjs.com/package/piral-ngjs) [](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 `angular`. What `piral-ngjs` 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 an Angular.js converter for any component registration, as well as a `fromNgjs` shortcut and a `NgjsExtension` component.
|
|
8
8
|
|
|
@@ -48,7 +48,7 @@ Alternatively, if `piral-ngjs` 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 { fromNgjs, createNgjsExtension } from 'piral-ngjs';
|
|
51
|
+
import { fromNgjs, createNgjsExtension } from 'piral-ngjs/convert';
|
|
52
52
|
import { createAngularJsPage } from './AngularJsPage';
|
|
53
53
|
|
|
54
54
|
export function setup(piral: PiletApi) {
|
|
@@ -62,7 +62,7 @@ export function setup(piral: PiletApi) {
|
|
|
62
62
|
|
|
63
63
|
::: summary: For Piral instance developers
|
|
64
64
|
|
|
65
|
-
The provided library only brings API extensions for pilets to a Piral instance. The Piral instance still needs to be configured properly to support Angular.js 1.x.
|
|
65
|
+
The provided library only brings API extensions for pilets to a Piral instance. The Piral instance still needs to be configured properly to support Angular.js 1.x. For this you'll need to install the `angular@^1.7` package.
|
|
66
66
|
|
|
67
67
|
For the setup itself you'll need to import `createNgjsApi` from the `piral-ngjs` package.
|
|
68
68
|
|
|
@@ -84,10 +84,10 @@ The `angular` package should be shared with the pilets via the *package.json*:
|
|
|
84
84
|
|
|
85
85
|
```json
|
|
86
86
|
{
|
|
87
|
-
"
|
|
88
|
-
"
|
|
89
|
-
"angular"
|
|
90
|
-
|
|
87
|
+
"importmap": {
|
|
88
|
+
"imports": {
|
|
89
|
+
"angular": ""
|
|
90
|
+
}
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
```
|
package/convert.d.ts
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
/// <reference types="angular" />
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import { createConverter } from './esm/converter';
|
|
3
|
+
export interface HtmlComponent<TProps> {
|
|
4
|
+
component: {
|
|
5
|
+
mount(element: HTMLElement, props: TProps, ctx: any, locals: any): void;
|
|
6
|
+
update?(element: HTMLElement, props: TProps, ctx: any, locals: any): void;
|
|
7
|
+
unmount?(element: HTMLElement, locals: any): void;
|
|
8
|
+
};
|
|
9
|
+
type: 'html';
|
|
10
|
+
}
|
|
5
11
|
export interface NgjsConverter {
|
|
6
|
-
(...params: Parameters<typeof
|
|
12
|
+
(...params: Parameters<ReturnType<typeof createConverter>>): HtmlComponent<any>;
|
|
7
13
|
}
|
|
8
|
-
export declare
|
|
9
|
-
|
|
10
|
-
|
|
14
|
+
export declare function createNgjsConverter(...params: Parameters<typeof createConverter>): {
|
|
15
|
+
from: NgjsConverter;
|
|
16
|
+
Extension: import("angular").IModule;
|
|
17
|
+
};
|
|
18
|
+
declare const fromNgjs: NgjsConverter, NgjsExtension: import("angular").IModule;
|
|
19
|
+
export { fromNgjs, NgjsExtension };
|
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 createNgjsConverter() {
|
|
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 (name, root) { return ({
|
|
10
|
+
type: 'html',
|
|
11
|
+
component: convert(name, root),
|
|
12
|
+
}); };
|
|
13
|
+
return { from: from, Extension: Extension };
|
|
14
|
+
}
|
|
15
|
+
var _a = createNgjsConverter(), fromNgjs = _a.from, NgjsExtension = _a.Extension;
|
|
16
|
+
export { fromNgjs, NgjsExtension };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ForeignComponent, BaseComponentProps } from 'piral-core';
|
|
2
|
+
import { IModule } from 'angular';
|
|
3
|
+
export interface NgjsConverterOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Defines the name of the root element.
|
|
6
|
+
* @default piral-slot
|
|
7
|
+
*/
|
|
8
|
+
rootName?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function createConverter(config?: NgjsConverterOptions): {
|
|
11
|
+
<TProps extends BaseComponentProps>(name: string, root: IModule): ForeignComponent<TProps>;
|
|
12
|
+
Extension: IModule;
|
|
13
|
+
};
|
package/esm/converter.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { bootstrap } from 'angular';
|
|
2
|
+
import { createExtension } from './extension';
|
|
3
|
+
export function createConverter(config = {}) {
|
|
4
|
+
const { rootName = 'piral-slot' } = config;
|
|
5
|
+
const Extension = createExtension(rootName);
|
|
6
|
+
const convert = (name, root) => ({
|
|
7
|
+
mount(el, props, ctx, locals) {
|
|
8
|
+
el.appendChild(document.createElement(name));
|
|
9
|
+
root.value('props', props);
|
|
10
|
+
root.value('piral', props.piral);
|
|
11
|
+
root.value('ctx', ctx);
|
|
12
|
+
locals.injector = bootstrap(el, [root.name]);
|
|
13
|
+
},
|
|
14
|
+
unmount(el, locals) {
|
|
15
|
+
const rootScope = locals.injector.get('$rootScope');
|
|
16
|
+
rootScope.$destroy();
|
|
17
|
+
locals.injector = undefined;
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
convert.Extension = Extension;
|
|
21
|
+
return convert;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=converter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"converter.js","sourceRoot":"","sources":["../src/converter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAW,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAc9C,MAAM,UAAU,eAAe,CAAC,SAA+B,EAAE;IAC/D,MAAM,EAAE,QAAQ,GAAG,YAAY,EAAE,GAAG,MAAM,CAAC;IAC3C,MAAM,SAAS,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC;IAC5C,MAAM,OAAO,GAAG,CAAoC,IAAY,EAAE,IAAa,EAA4B,EAAE,CAAC,CAAC;QAC7G,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,MAAiB;YACrC,EAAE,CAAC,WAAW,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC;YAC7C,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;YAC3B,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;YACjC,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;YACvB,MAAM,CAAC,QAAQ,GAAG,SAAS,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAC/C,CAAC;QACD,OAAO,CAAC,EAAE,EAAE,MAAiB;YAC3B,MAAM,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;YACpD,SAAS,CAAC,QAAQ,EAAE,CAAC;YACrB,MAAM,CAAC,QAAQ,GAAG,SAAS,CAAC;QAC9B,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 { NgjsConverterOptions } from './converter';
|
|
3
|
+
import type { PiletNgjsApi } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* Available configuration options for the Angular.js plugin.
|
|
6
|
+
*/
|
|
7
|
+
export interface NgjsConfig extends NgjsConverterOptions {
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Creates the Pilet API extensions for Angular.js.
|
|
11
|
+
*/
|
|
12
|
+
export declare function createNgjsApi(config?: NgjsConfig): PiralPlugin<PiletNgjsApi>;
|
package/esm/create.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createConverter } from './converter';
|
|
2
|
+
/**
|
|
3
|
+
* Creates the Pilet API extensions for Angular.js.
|
|
4
|
+
*/
|
|
5
|
+
export function createNgjsApi(config = {}) {
|
|
6
|
+
return (context) => {
|
|
7
|
+
const convert = createConverter(config);
|
|
8
|
+
context.converters.ngjs = ({ name, root }) => convert(name, root);
|
|
9
|
+
return {
|
|
10
|
+
NgjsExtension: convert.Extension,
|
|
11
|
+
fromNgjs(name, root) {
|
|
12
|
+
return {
|
|
13
|
+
type: 'ngjs',
|
|
14
|
+
name,
|
|
15
|
+
root,
|
|
16
|
+
};
|
|
17
|
+
},
|
|
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,EAAwB,MAAM,aAAa,CAAC;AAQpE;;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,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAElE,OAAO;YACL,aAAa,EAAE,OAAO,CAAC,SAAS;YAChC,QAAQ,CAAC,IAAI,EAAE,IAAI;gBACjB,OAAO;oBACL,IAAI,EAAE,MAAM;oBACZ,IAAI;oBACJ,IAAI;iBACL,CAAC;YACJ,CAAC;SACF,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
|
package/esm/extension.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as angular from 'angular';
|
|
2
|
+
export function createExtension(rootName) {
|
|
3
|
+
const NgjsExtension = angular.module(`piralExtension`, []);
|
|
4
|
+
NgjsExtension.component('extensionComponent', {
|
|
5
|
+
template: `<${rootName}></${rootName}>`,
|
|
6
|
+
bindings: {
|
|
7
|
+
empty: '<',
|
|
8
|
+
params: '<',
|
|
9
|
+
render: '<',
|
|
10
|
+
name: '@',
|
|
11
|
+
},
|
|
12
|
+
controller: [
|
|
13
|
+
'$element',
|
|
14
|
+
'piral',
|
|
15
|
+
function ($element, piral) {
|
|
16
|
+
this.$onInit = () => {
|
|
17
|
+
const container = $element[0].querySelector(rootName);
|
|
18
|
+
piral.renderHtmlExtension(container, {
|
|
19
|
+
empty: this.empty,
|
|
20
|
+
params: this.params,
|
|
21
|
+
render: this.render,
|
|
22
|
+
name: this.name,
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
});
|
|
28
|
+
return NgjsExtension;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=extension.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAEnC,MAAM,UAAU,eAAe,CAAC,QAAgB;IAC9C,MAAM,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,gBAAgB,EAAE,EAAE,CAAC,CAAC;IAC3D,aAAa,CAAC,SAAS,CAAC,oBAAoB,EAAE;QAC5C,QAAQ,EAAE,IAAI,QAAQ,MAAM,QAAQ,GAAG;QACvC,QAAQ,EAAE;YACR,KAAK,EAAE,GAAG;YACV,MAAM,EAAE,GAAG;YACX,MAAM,EAAE,GAAG;YACX,IAAI,EAAE,GAAG;SACV;QACD,UAAU,EAAE;YACV,UAAU;YACV,OAAO;YACP,UAAU,QAAQ,EAAE,KAAK;gBACvB,IAAI,CAAC,OAAO,GAAG,GAAG,EAAE;oBAClB,MAAM,SAAS,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;oBACtD,KAAK,CAAC,mBAAmB,CAAC,SAAS,EAAE;wBACnC,KAAK,EAAE,IAAI,CAAC,KAAK;wBACjB,MAAM,EAAE,IAAI,CAAC,MAAM;wBACnB,MAAM,EAAE,IAAI,CAAC,MAAM;wBACnB,IAAI,EAAE,IAAI,CAAC,IAAI;qBAChB,CAAC,CAAC;gBACL,CAAC,CAAC;YACJ,CAAC;SACF;KACF,CAAC,CAAC;IACH,OAAO,aAAa,CAAC;AACvB,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 { IModule } from 'angular';
|
|
2
|
+
import type { ForeignComponent } from 'piral-core';
|
|
3
|
+
declare module 'piral-core/lib/types/custom' {
|
|
4
|
+
interface PiletCustomApi extends PiletNgjsApi {
|
|
5
|
+
}
|
|
6
|
+
interface PiralCustomComponentConverters<TProps> {
|
|
7
|
+
ngjs(component: NgjsComponent): ForeignComponent<TProps>;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export interface NgjsComponent {
|
|
11
|
+
/**
|
|
12
|
+
* The module root.
|
|
13
|
+
*/
|
|
14
|
+
root: IModule;
|
|
15
|
+
/**
|
|
16
|
+
* The name of the component.
|
|
17
|
+
*/
|
|
18
|
+
name: string;
|
|
19
|
+
/**
|
|
20
|
+
* The type of the Angular.js component.
|
|
21
|
+
*/
|
|
22
|
+
type: 'ngjs';
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Defines the provided set of Angular Pilet API extensions.
|
|
26
|
+
*/
|
|
27
|
+
export interface PiletNgjsApi {
|
|
28
|
+
/**
|
|
29
|
+
* Wraps an Angular.js module for use in Piral.
|
|
30
|
+
* @param name The name of the component.
|
|
31
|
+
* @param root The module root.
|
|
32
|
+
* @returns The Piral Ngjs component.
|
|
33
|
+
*/
|
|
34
|
+
fromNgjs(name: string, root: IModule): NgjsComponent;
|
|
35
|
+
/**
|
|
36
|
+
* Angular.js component for displaying extensions of the given name.
|
|
37
|
+
*/
|
|
38
|
+
NgjsExtension: IModule;
|
|
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
|
+
import type { ForeignComponent, BaseComponentProps } from 'piral-core';
|
|
1
2
|
import { IModule } from 'angular';
|
|
2
|
-
|
|
3
|
-
|
|
3
|
+
export interface NgjsConverterOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Defines the name of the root element.
|
|
6
|
+
* @default piral-slot
|
|
7
|
+
*/
|
|
8
|
+
rootName?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function createConverter(config?: NgjsConverterOptions): {
|
|
11
|
+
<TProps extends BaseComponentProps>(name: string, root: IModule): ForeignComponent<TProps>;
|
|
12
|
+
Extension: IModule;
|
|
13
|
+
};
|
package/lib/converter.js
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createConverter = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
};
|
|
4
|
+
const angular_1 = require("angular");
|
|
5
|
+
const extension_1 = require("./extension");
|
|
6
|
+
function createConverter(config = {}) {
|
|
7
|
+
const { rootName = 'piral-slot' } = config;
|
|
8
|
+
const Extension = (0, extension_1.createExtension)(rootName);
|
|
9
|
+
const convert = (name, root) => ({
|
|
10
|
+
mount(el, props, ctx, locals) {
|
|
11
|
+
el.appendChild(document.createElement(name));
|
|
12
|
+
root.value('props', props);
|
|
13
|
+
root.value('piral', props.piral);
|
|
14
|
+
root.value('ctx', ctx);
|
|
15
|
+
locals.injector = (0, angular_1.bootstrap)(el, [root.name]);
|
|
16
|
+
},
|
|
17
|
+
unmount(el, locals) {
|
|
18
|
+
const rootScope = locals.injector.get('$rootScope');
|
|
19
|
+
rootScope.$destroy();
|
|
20
|
+
locals.injector = undefined;
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
convert.Extension = Extension;
|
|
23
24
|
return convert;
|
|
24
25
|
}
|
|
25
26
|
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":";;;AACA,qCAA6C;AAC7C,2CAA8C;AAc9C,SAAgB,eAAe,CAAC,SAA+B,EAAE;IAC/D,MAAM,EAAE,QAAQ,GAAG,YAAY,EAAE,GAAG,MAAM,CAAC;IAC3C,MAAM,SAAS,GAAG,IAAA,2BAAe,EAAC,QAAQ,CAAC,CAAC;IAC5C,MAAM,OAAO,GAAG,CAAoC,IAAY,EAAE,IAAa,EAA4B,EAAE,CAAC,CAAC;QAC7G,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,MAAiB;YACrC,EAAE,CAAC,WAAW,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC;YAC7C,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;YAC3B,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;YACjC,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;YACvB,MAAM,CAAC,QAAQ,GAAG,IAAA,mBAAS,EAAC,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAC/C,CAAC;QACD,OAAO,CAAC,EAAE,EAAE,MAAiB;YAC3B,MAAM,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;YACpD,SAAS,CAAC,QAAQ,EAAE,CAAC;YACrB,MAAM,CAAC,QAAQ,GAAG,SAAS,CAAC;QAC9B,CAAC;KACF,CAAC,CAAC;IACH,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;IAC9B,OAAO,OAAO,CAAC;AACjB,CAAC;AAnBD,0CAmBC"}
|
package/lib/create.d.ts
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import { PiralPlugin } from 'piral-core';
|
|
2
|
-
import {
|
|
1
|
+
import type { PiralPlugin } from 'piral-core';
|
|
2
|
+
import { NgjsConverterOptions } from './converter';
|
|
3
|
+
import type { PiletNgjsApi } from './types';
|
|
3
4
|
/**
|
|
4
5
|
* Available configuration options for the Angular.js plugin.
|
|
5
6
|
*/
|
|
6
|
-
export interface NgjsConfig {
|
|
7
|
-
/**
|
|
8
|
-
* Defines the name of the root element.
|
|
9
|
-
* @default slot
|
|
10
|
-
*/
|
|
11
|
-
rootName?: string;
|
|
7
|
+
export interface NgjsConfig extends NgjsConverterOptions {
|
|
12
8
|
}
|
|
13
9
|
/**
|
|
14
10
|
* Creates the Pilet API extensions for Angular.js.
|
package/lib/create.js
CHANGED
|
@@ -1,28 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createNgjsApi = void 0;
|
|
4
|
-
|
|
5
|
-
var extension_1 = require("./extension");
|
|
4
|
+
const converter_1 = require("./converter");
|
|
6
5
|
/**
|
|
7
6
|
* Creates the Pilet API extensions for Angular.js.
|
|
8
7
|
*/
|
|
9
|
-
function createNgjsApi(config) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return function (context) {
|
|
14
|
-
var convert = converter_1.createConverter();
|
|
15
|
-
context.converters.ngjs = function (_a) {
|
|
16
|
-
var name = _a.name, root = _a.root;
|
|
17
|
-
return convert(name, root);
|
|
18
|
-
};
|
|
8
|
+
function createNgjsApi(config = {}) {
|
|
9
|
+
return (context) => {
|
|
10
|
+
const convert = (0, converter_1.createConverter)(config);
|
|
11
|
+
context.converters.ngjs = ({ name, root }) => convert(name, root);
|
|
19
12
|
return {
|
|
20
|
-
NgjsExtension:
|
|
21
|
-
fromNgjs
|
|
13
|
+
NgjsExtension: convert.Extension,
|
|
14
|
+
fromNgjs(name, root) {
|
|
22
15
|
return {
|
|
23
16
|
type: 'ngjs',
|
|
24
|
-
name
|
|
25
|
-
root
|
|
17
|
+
name,
|
|
18
|
+
root,
|
|
26
19
|
};
|
|
27
20
|
},
|
|
28
21
|
};
|
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,2CAAoE;AAQpE;;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,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAElE,OAAO;YACL,aAAa,EAAE,OAAO,CAAC,SAAS;YAChC,QAAQ,CAAC,IAAI,EAAE,IAAI;gBACjB,OAAO;oBACL,IAAI,EAAE,MAAM;oBACZ,IAAI;oBACJ,IAAI;iBACL,CAAC;YACJ,CAAC;SACF,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAhBD,sCAgBC"}
|
package/lib/extension.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import * as angular from 'angular';
|
|
2
|
-
export declare function createExtension(rootName
|
|
2
|
+
export declare function createExtension(rootName: string): angular.IModule;
|
package/lib/extension.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createExtension = void 0;
|
|
4
|
-
|
|
4
|
+
const angular = require("angular");
|
|
5
5
|
function createExtension(rootName) {
|
|
6
|
-
|
|
7
|
-
var NgjsExtension = angular.module("piralExtension", []);
|
|
6
|
+
const NgjsExtension = angular.module(`piralExtension`, []);
|
|
8
7
|
NgjsExtension.component('extensionComponent', {
|
|
9
|
-
template:
|
|
8
|
+
template: `<${rootName}></${rootName}>`,
|
|
10
9
|
bindings: {
|
|
11
10
|
empty: '<',
|
|
12
11
|
params: '<',
|
|
@@ -17,14 +16,13 @@ function createExtension(rootName) {
|
|
|
17
16
|
'$element',
|
|
18
17
|
'piral',
|
|
19
18
|
function ($element, piral) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
var container = $element[0].querySelector(rootName);
|
|
19
|
+
this.$onInit = () => {
|
|
20
|
+
const container = $element[0].querySelector(rootName);
|
|
23
21
|
piral.renderHtmlExtension(container, {
|
|
24
|
-
empty:
|
|
25
|
-
params:
|
|
26
|
-
render:
|
|
27
|
-
name:
|
|
22
|
+
empty: this.empty,
|
|
23
|
+
params: this.params,
|
|
24
|
+
render: this.render,
|
|
25
|
+
name: this.name,
|
|
28
26
|
});
|
|
29
27
|
};
|
|
30
28
|
},
|
package/lib/extension.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":";;;AAAA,mCAAmC;AAEnC,SAAgB,eAAe,CAAC,QAAgB;IAC9C,MAAM,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,gBAAgB,EAAE,EAAE,CAAC,CAAC;IAC3D,aAAa,CAAC,SAAS,CAAC,oBAAoB,EAAE;QAC5C,QAAQ,EAAE,IAAI,QAAQ,MAAM,QAAQ,GAAG;QACvC,QAAQ,EAAE;YACR,KAAK,EAAE,GAAG;YACV,MAAM,EAAE,GAAG;YACX,MAAM,EAAE,GAAG;YACX,IAAI,EAAE,GAAG;SACV;QACD,UAAU,EAAE;YACV,UAAU;YACV,OAAO;YACP,UAAU,QAAQ,EAAE,KAAK;gBACvB,IAAI,CAAC,OAAO,GAAG,GAAG,EAAE;oBAClB,MAAM,SAAS,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;oBACtD,KAAK,CAAC,mBAAmB,CAAC,SAAS,EAAE;wBACnC,KAAK,EAAE,IAAI,CAAC,KAAK;wBACjB,MAAM,EAAE,IAAI,CAAC,MAAM;wBACnB,MAAM,EAAE,IAAI,CAAC,MAAM;wBACnB,IAAI,EAAE,IAAI,CAAC,IAAI;qBAChB,CAAC,CAAC;gBACL,CAAC,CAAC;YACJ,CAAC;SACF;KACF,CAAC,CAAC;IACH,OAAO,aAAa,CAAC;AACvB,CAAC;AA3BD,0CA2BC"}
|
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "piral-ngjs",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1-beta.5640",
|
|
4
4
|
"description": "Plugin for integrating Angular.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,18 +55,18 @@
|
|
|
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-ngjs.json src --exclude \"src/**/*.test.*\"",
|
|
39
64
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
40
65
|
},
|
|
41
66
|
"devDependencies": {
|
|
42
67
|
"@types/angular": "^1.6.45",
|
|
43
68
|
"angular": "^1.7.9",
|
|
44
|
-
"piral-core": "
|
|
45
|
-
},
|
|
46
|
-
"peerDependencies": {
|
|
47
|
-
"angular": "^1.7.0",
|
|
48
|
-
"piral-core": "1.x"
|
|
69
|
+
"piral-core": "1.0.1-beta.5640"
|
|
49
70
|
},
|
|
50
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "fa0a72b28fd0a20afec7ef491ec19e93c090fc72"
|
|
51
72
|
}
|
package/src/converter.ts
CHANGED
|
@@ -1,24 +1,36 @@
|
|
|
1
|
+
import type { ForeignComponent, BaseComponentProps } from 'piral-core';
|
|
1
2
|
import { bootstrap, IModule } from 'angular';
|
|
2
|
-
import {
|
|
3
|
+
import { createExtension } from './extension';
|
|
3
4
|
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
export interface NgjsConverterOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Defines the name of the root element.
|
|
8
|
+
* @default piral-slot
|
|
9
|
+
*/
|
|
10
|
+
rootName?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface NgjsState {
|
|
14
|
+
injector: any;
|
|
15
|
+
}
|
|
7
16
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
export function createConverter(config: NgjsConverterOptions = {}) {
|
|
18
|
+
const { rootName = 'piral-slot' } = config;
|
|
19
|
+
const Extension = createExtension(rootName);
|
|
20
|
+
const convert = <TProps extends BaseComponentProps>(name: string, root: IModule): ForeignComponent<TProps> => ({
|
|
21
|
+
mount(el, props, ctx, locals: NgjsState) {
|
|
22
|
+
el.appendChild(document.createElement(name));
|
|
23
|
+
root.value('props', props);
|
|
24
|
+
root.value('piral', props.piral);
|
|
25
|
+
root.value('ctx', ctx);
|
|
26
|
+
locals.injector = bootstrap(el, [root.name]);
|
|
27
|
+
},
|
|
28
|
+
unmount(el, locals: NgjsState) {
|
|
29
|
+
const rootScope = locals.injector.get('$rootScope');
|
|
30
|
+
rootScope.$destroy();
|
|
31
|
+
locals.injector = undefined;
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
convert.Extension = Extension;
|
|
23
35
|
return convert;
|
|
24
36
|
}
|
package/src/create.ts
CHANGED
|
@@ -1,32 +1,22 @@
|
|
|
1
|
-
import { PiralPlugin } from 'piral-core';
|
|
2
|
-
import { createConverter } from './converter';
|
|
3
|
-
import { PiletNgjsApi } from './types';
|
|
4
|
-
import { createExtension } from './extension';
|
|
1
|
+
import type { PiralPlugin } from 'piral-core';
|
|
2
|
+
import { createConverter, NgjsConverterOptions } from './converter';
|
|
3
|
+
import type { PiletNgjsApi } from './types';
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* Available configuration options for the Angular.js plugin.
|
|
8
7
|
*/
|
|
9
|
-
export interface NgjsConfig {
|
|
10
|
-
/**
|
|
11
|
-
* Defines the name of the root element.
|
|
12
|
-
* @default slot
|
|
13
|
-
*/
|
|
14
|
-
rootName?: string;
|
|
15
|
-
}
|
|
8
|
+
export interface NgjsConfig extends NgjsConverterOptions {}
|
|
16
9
|
|
|
17
10
|
/**
|
|
18
11
|
* Creates the Pilet API extensions for Angular.js.
|
|
19
12
|
*/
|
|
20
13
|
export function createNgjsApi(config: NgjsConfig = {}): PiralPlugin<PiletNgjsApi> {
|
|
21
|
-
const { rootName } = config;
|
|
22
|
-
const NgjsExtension = createExtension(rootName);
|
|
23
|
-
|
|
24
14
|
return (context) => {
|
|
25
|
-
const convert = createConverter();
|
|
15
|
+
const convert = createConverter(config);
|
|
26
16
|
context.converters.ngjs = ({ name, root }) => convert(name, root);
|
|
27
17
|
|
|
28
18
|
return {
|
|
29
|
-
NgjsExtension,
|
|
19
|
+
NgjsExtension: convert.Extension,
|
|
30
20
|
fromNgjs(name, root) {
|
|
31
21
|
return {
|
|
32
22
|
type: 'ngjs',
|
package/src/extension.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as angular from 'angular';
|
|
2
2
|
|
|
3
|
-
export function createExtension(rootName
|
|
3
|
+
export function createExtension(rootName: string): angular.IModule {
|
|
4
4
|
const NgjsExtension = angular.module(`piralExtension`, []);
|
|
5
5
|
NgjsExtension.component('extensionComponent', {
|
|
6
6
|
template: `<${rootName}></${rootName}>`,
|
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 NgjsConverter {
|
|
8
|
-
(...params: Parameters<typeof convert>): HtmlComponent<any>;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export const fromNgjs: NgjsConverter = (name, root) => ({
|
|
12
|
-
type: 'html',
|
|
13
|
-
component: convert(name, root),
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
export const createNgjsExtension = createExtension;
|