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 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 NgJS](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-ngjs.svg?style=flat)](https://www.npmjs.com/package/piral-ngjs) [![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 NgJS](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-ngjs.svg?style=flat)](https://www.npmjs.com/package/piral-ngjs) [![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-ngjs` 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 `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
- "pilets": {
88
- "externals": [
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 type { HtmlComponent } from 'piral-core';
3
- import { createExtension } from './lib/extension';
4
- declare const convert: <TProps extends import("piral-core").BaseComponentProps>(name: string, root: import("angular").IModule) => import("piral-core").ForeignComponent<TProps>;
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 convert>): HtmlComponent<any>;
12
+ (...params: Parameters<ReturnType<typeof createConverter>>): HtmlComponent<any>;
7
13
  }
8
- export declare const fromNgjs: NgjsConverter;
9
- export declare const createNgjsExtension: typeof createExtension;
10
- export {};
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
- "use strict";
2
- exports.__esModule = true;
3
- exports.createNgjsExtension = exports.fromNgjs = void 0;
4
- var converter_1 = require("./lib/converter");
5
- var extension_1 = require("./lib/extension");
6
- var convert = converter_1.createConverter();
7
- exports.fromNgjs = function (name, root) { return ({
8
- type: 'html',
9
- component: convert(name, root)
10
- }); };
11
- exports.createNgjsExtension = extension_1.createExtension;
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
+ };
@@ -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"}
@@ -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"}
@@ -0,0 +1,2 @@
1
+ import * as angular from 'angular';
2
+ export declare function createExtension(rootName: string): angular.IModule;
@@ -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
@@ -0,0 +1,2 @@
1
+ export * from './create';
2
+ export * from './types';
package/esm/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from './create';
2
+ export * from './types';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
package/esm/types.d.ts ADDED
@@ -0,0 +1,39 @@
1
+ import type { 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
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -1,3 +1,13 @@
1
+ import type { ForeignComponent, BaseComponentProps } from 'piral-core';
1
2
  import { IModule } from 'angular';
2
- import { ForeignComponent, BaseComponentProps } from 'piral-core';
3
- export declare function createConverter(): <TProps extends BaseComponentProps>(name: string, root: IModule) => ForeignComponent<TProps>;
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
- var angular_1 = require("angular");
5
- function createConverter() {
6
- var convert = function (name, root) {
7
- var injector = undefined;
8
- return {
9
- mount: function (el, props, ctx) {
10
- el.appendChild(document.createElement(name));
11
- root.value('props', props);
12
- root.value('piral', props.piral);
13
- root.value('ctx', ctx);
14
- injector = angular_1.bootstrap(el, [root.name]);
15
- },
16
- unmount: function (el) {
17
- var rootScope = injector.get('$rootScope');
18
- rootScope.$destroy();
19
- injector = undefined;
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;
@@ -1 +1 @@
1
- {"version":3,"file":"converter.js","sourceRoot":"","sources":["../src/converter.ts"],"names":[],"mappings":";;;AAAA,mCAA6C;AAG7C,SAAgB,eAAe;IAC7B,IAAM,OAAO,GAAG,UAAoC,IAAY,EAAE,IAAa;QAC7E,IAAI,QAAQ,GAAQ,SAAS,CAAC;QAE9B,OAAO;YACL,KAAK,YAAC,EAAE,EAAE,KAAK,EAAE,GAAG;gBAClB,EAAE,CAAC,WAAW,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC;gBAC7C,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;gBAC3B,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;gBACjC,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;gBACvB,QAAQ,GAAG,mBAAS,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;YACxC,CAAC;YACD,O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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 { PiletNgjsApi } from './types';
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
- var converter_1 = require("./converter");
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
- if (config === void 0) { config = {}; }
11
- var rootName = config.rootName;
12
- var NgjsExtension = extension_1.createExtension(rootName);
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: NgjsExtension,
21
- fromNgjs: function (name, root) {
13
+ NgjsExtension: convert.Extension,
14
+ fromNgjs(name, root) {
22
15
  return {
23
16
  type: 'ngjs',
24
- name: name,
25
- root: 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,yCAA8C;AAE9C,yCAA8C;AAa9C;;GAEG;AACH,SAAgB,aAAa,CAAC,MAAuB;IAAvB,uBAAA,EAAA,WAAuB;IAC3C,IAAA,QAAQ,GAAK,MAAM,SAAX,CAAY;IAC5B,IAAM,aAAa,GAAG,2BAAe,CAAC,QAAQ,CAAC,CAAC;IAEhD,OAAO,UAAC,OAAO;QACb,IAAM,OAAO,GAAG,2BAAe,EAAE,CAAC;QAClC,OAAO,CAAC,UAAU,CAAC,IAAI,GAAG,UAAC,EAAc;gBAAZ,IAAI,UAAA,EAAE,IAAI,UAAA;YAAO,OAAA,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC;QAAnB,CAAmB,CAAC;QAElE,OAAO;YACL,aAAa,eAAA;YACb,QAAQ,YAAC,IAAI,EAAE,IAAI;gBACjB,OAAO;oBACL,IAAI,EAAE,MAAM;oBACZ,IAAI,MAAA;oBACJ,IAAI,MAAA;iBACL,CAAC;YACJ,CAAC;SACF,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAnBD,sCAmBC"}
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"}
@@ -1,2 +1,2 @@
1
1
  import * as angular from 'angular';
2
- export declare function createExtension(rootName?: string): angular.IModule;
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
- var angular = require("angular");
4
+ const angular = require("angular");
5
5
  function createExtension(rootName) {
6
- if (rootName === void 0) { rootName = 'slot'; }
7
- var NgjsExtension = angular.module("piralExtension", []);
6
+ const NgjsExtension = angular.module(`piralExtension`, []);
8
7
  NgjsExtension.component('extensionComponent', {
9
- template: "<" + rootName + "></" + rootName + ">",
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
- var _this = this;
21
- this.$onInit = function () {
22
- var container = $element[0].querySelector(rootName);
19
+ this.$onInit = () => {
20
+ const container = $element[0].querySelector(rootName);
23
21
  piral.renderHtmlExtension(container, {
24
- empty: _this.empty,
25
- params: _this.params,
26
- render: _this.render,
27
- name: _this.name,
22
+ empty: this.empty,
23
+ params: this.params,
24
+ render: this.render,
25
+ name: this.name,
28
26
  });
29
27
  };
30
28
  },
@@ -1 +1 @@
1
- {"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":";;;AAAA,iCAAmC;AAEnC,SAAgB,eAAe,CAAC,QAAiB;IAAjB,yBAAA,EAAA,iBAAiB;IAC/C,IAAM,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,gBAAgB,EAAE,EAAE,CAAC,CAAC;IAC3D,aAAa,CAAC,SAAS,CAAC,oBAAoB,EAAE;QAC5C,QAAQ,EAAE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AC,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
- 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "piral-ngjs",
3
- "version": "1.0.0-pre.2036",
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
- "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-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": "^1.0.0-pre.2036"
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": "117e562b48802cdd4ddc5e9e6d42e91fa170daed"
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 { ForeignComponent, BaseComponentProps } from 'piral-core';
3
+ import { createExtension } from './extension';
3
4
 
4
- export function createConverter() {
5
- const convert = <TProps extends BaseComponentProps>(name: string, root: IModule): ForeignComponent<TProps> => {
6
- let injector: any = undefined;
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
- return {
9
- mount(el, props, ctx) {
10
- el.appendChild(document.createElement(name));
11
- root.value('props', props);
12
- root.value('piral', props.piral);
13
- root.value('ctx', ctx);
14
- injector = bootstrap(el, [root.name]);
15
- },
16
- unmount(el) {
17
- const rootScope = injector.get('$rootScope');
18
- rootScope.$destroy();
19
- injector = undefined;
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 = 'slot'): angular.IModule {
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;