piral-ember 1.0.0-pre.2094 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +4 -8
- package/convert.d.ts +16 -7
- package/convert.js +16 -11
- package/esm/converter.d.ts +13 -0
- package/esm/converter.js +26 -0
- package/esm/converter.js.map +1 -0
- package/esm/create.d.ts +12 -0
- package/esm/create.js +23 -0
- package/esm/create.js.map +1 -0
- package/esm/extension.d.ts +1 -0
- package/esm/extension.js +11 -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/load.d.ts +1 -0
- package/esm/load.js +26 -0
- package/esm/load.js.map +1 -0
- package/esm/types.d.ts +57 -0
- package/esm/types.js +2 -0
- package/esm/types.js.map +1 -0
- package/lib/converter.d.ts +13 -3
- package/lib/converter.js +23 -27
- package/lib/converter.js.map +1 -1
- package/lib/create.d.ts +2 -6
- package/lib/create.js +10 -17
- package/lib/create.js.map +1 -1
- package/lib/extension.d.ts +1 -1
- package/lib/extension.js +7 -24
- package/lib/extension.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/load.js +4 -4
- package/lib/load.js.map +1 -1
- package/package.json +31 -7
- package/src/converter.ts +42 -36
- package/src/create.ts +4 -15
- package/src/extension.ts +8 -20
- package/convert.ts +0 -16
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
[](https://piral.io)
|
|
2
2
|
|
|
3
|
-
# [Piral Ember](https://piral.io) · [](https://github.com/smapiot/piral/blob/
|
|
3
|
+
# [Piral Ember](https://piral.io) · [](https://github.com/smapiot/piral/blob/main/LICENSE) [](https://www.npmjs.com/package/piral-ember) [](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 `ember-source`. What `piral-ember` 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 Ember.js converter for any component registration, as well as a `fromEmber` shortcut and a `EmberExtension` component.
|
|
8
8
|
|
|
@@ -16,10 +16,6 @@ The following functions are brought to the Pilet API.
|
|
|
16
16
|
|
|
17
17
|
Transforms a standard Ember.js component into a component that can be used in Piral, essentially wrapping it with a reference to the corresponding converter.
|
|
18
18
|
|
|
19
|
-
### `EmberExtension`
|
|
20
|
-
|
|
21
|
-
(tbd)
|
|
22
|
-
|
|
23
19
|
## Usage
|
|
24
20
|
|
|
25
21
|
::: summary: For pilet authors
|
|
@@ -47,7 +43,7 @@ Alternatively, if `piral-ember` has not been added to the Piral instance you can
|
|
|
47
43
|
|
|
48
44
|
```ts
|
|
49
45
|
import { PiletApi } from '<name-of-piral-instance>';
|
|
50
|
-
import { fromEmber } from 'piral-ember';
|
|
46
|
+
import { fromEmber } from 'piral-ember/convert';
|
|
51
47
|
import { Page } from './Page';
|
|
52
48
|
|
|
53
49
|
export function setup(piral: PiletApi) {
|
package/convert.d.ts
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { createConverter } from './esm/converter';
|
|
2
|
+
export interface HtmlComponent<TProps> {
|
|
3
|
+
component: {
|
|
4
|
+
mount(element: HTMLElement, props: TProps, ctx: any, locals: any): void;
|
|
5
|
+
update?(element: HTMLElement, props: TProps, ctx: any, locals: any): void;
|
|
6
|
+
unmount?(element: HTMLElement, locals: any): void;
|
|
7
|
+
};
|
|
8
|
+
type: 'html';
|
|
9
|
+
}
|
|
4
10
|
export interface EmberConverter {
|
|
5
|
-
(...params: Parameters<typeof
|
|
11
|
+
(...params: Parameters<ReturnType<typeof createConverter>>): HtmlComponent<any>;
|
|
6
12
|
}
|
|
7
|
-
export declare
|
|
8
|
-
|
|
9
|
-
|
|
13
|
+
export declare function createEmberConverter(...params: Parameters<typeof createConverter>): {
|
|
14
|
+
from: EmberConverter;
|
|
15
|
+
Extension: string;
|
|
16
|
+
};
|
|
17
|
+
declare const fromEmber: EmberConverter, EmberExtension: string;
|
|
18
|
+
export { fromEmber, EmberExtension };
|
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 createEmberConverter() {
|
|
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 (App, opts) { return ({
|
|
10
|
+
type: 'html',
|
|
11
|
+
component: convert(App, opts),
|
|
12
|
+
}); };
|
|
13
|
+
return { from: from, Extension: Extension };
|
|
14
|
+
}
|
|
15
|
+
var _a = createEmberConverter(), fromEmber = _a.from, EmberExtension = _a.Extension;
|
|
16
|
+
export { fromEmber, EmberExtension };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ForeignComponent, BaseComponentProps } from 'piral-core';
|
|
2
|
+
import type { EmberModule } from './types';
|
|
3
|
+
export interface EmberConverterOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Defines the name of the extension component.
|
|
6
|
+
* @default ember-extension
|
|
7
|
+
*/
|
|
8
|
+
selector?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function createConverter(config?: EmberConverterOptions): {
|
|
11
|
+
<TProps extends BaseComponentProps>(App: EmberModule<TProps>, opts: any): ForeignComponent<TProps>;
|
|
12
|
+
Extension: string;
|
|
13
|
+
};
|
package/esm/converter.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { createExtension } from './extension';
|
|
2
|
+
export function createConverter(config = {}) {
|
|
3
|
+
const { selector = 'ember-extension' } = config;
|
|
4
|
+
const Extension = createExtension(selector);
|
|
5
|
+
const convert = (App, opts) => ({
|
|
6
|
+
mount(rootElement, props, ctx, locals) {
|
|
7
|
+
locals.app = App.create(Object.assign(Object.assign({}, opts), { rootElement,
|
|
8
|
+
props,
|
|
9
|
+
ctx }));
|
|
10
|
+
},
|
|
11
|
+
update(rootElement, props, ctx, locals) {
|
|
12
|
+
locals.app.setProperties({
|
|
13
|
+
props,
|
|
14
|
+
ctx,
|
|
15
|
+
});
|
|
16
|
+
},
|
|
17
|
+
unmount(rootElement, locals) {
|
|
18
|
+
locals.app.destroy();
|
|
19
|
+
locals.app = undefined;
|
|
20
|
+
rootElement.innerHTML = '';
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
convert.Extension = Extension;
|
|
24
|
+
return convert;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=converter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"converter.js","sourceRoot":"","sources":["../src/converter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAe9C,MAAM,UAAU,eAAe,CAAC,SAAgC,EAAE;IAChE,MAAM,EAAE,QAAQ,GAAG,iBAAiB,EAAE,GAAG,MAAM,CAAC;IAEhD,MAAM,SAAS,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC;IAE5C,MAAM,OAAO,GAAG,CACd,GAAwB,EACxB,IAAS,EACiB,EAAE,CAAC,CAAC;QAC9B,KAAK,CAAC,WAAW,EAAE,KAAK,EAAE,GAAG,EAAE,MAA0B;YACvD,MAAM,CAAC,GAAG,GAAG,GAAG,CAAC,MAAM,iCAClB,IAAI,KACP,WAAW;gBACX,KAAK;gBACL,GAAG,IACH,CAAC;QACL,CAAC;QACD,MAAM,CAAC,WAAW,EAAE,KAAK,EAAE,GAAG,EAAE,MAA0B;YACxD,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC;gBACvB,KAAK;gBACL,GAAG;aACJ,CAAC,CAAC;QACL,CAAC;QACD,OAAO,CAAC,WAAW,EAAE,MAA0B;YAC7C,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;YACrB,MAAM,CAAC,GAAG,GAAG,SAAS,CAAC;YACvB,WAAW,CAAC,SAAS,GAAG,EAAE,CAAC;QAC7B,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 { EmberConverterOptions } from './converter';
|
|
3
|
+
import type { PiletEmberApi } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* Available configuration options for the Ember.js plugin.
|
|
6
|
+
*/
|
|
7
|
+
export interface EmberConfig extends EmberConverterOptions {
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Creates Pilet API extensions for integrating Ember.js.
|
|
11
|
+
*/
|
|
12
|
+
export declare function createEmberApi(config?: EmberConfig): PiralPlugin<PiletEmberApi>;
|
package/esm/create.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { loadEmberApp } from './load';
|
|
2
|
+
import { createConverter } from './converter';
|
|
3
|
+
/**
|
|
4
|
+
* Creates Pilet API extensions for integrating Ember.js.
|
|
5
|
+
*/
|
|
6
|
+
export function createEmberApi(config = {}) {
|
|
7
|
+
return (context) => {
|
|
8
|
+
const convert = createConverter(config);
|
|
9
|
+
context.converters.ember = ({ App, opts }) => convert(App, opts);
|
|
10
|
+
return {
|
|
11
|
+
fromEmber(App, opts) {
|
|
12
|
+
return {
|
|
13
|
+
type: 'ember',
|
|
14
|
+
App,
|
|
15
|
+
opts,
|
|
16
|
+
};
|
|
17
|
+
},
|
|
18
|
+
loadEmberApp,
|
|
19
|
+
EmberExtension: convert.Extension,
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=create.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,eAAe,EAAyB,MAAM,aAAa,CAAC;AAQrE;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,SAAsB,EAAE;IACrD,OAAO,CAAC,OAAO,EAAE,EAAE;QACjB,MAAM,OAAO,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;QACxC,OAAO,CAAC,UAAU,CAAC,KAAK,GAAG,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QAEjE,OAAO;YACL,SAAS,CAAC,GAAG,EAAE,IAAI;gBACjB,OAAO;oBACL,IAAI,EAAE,OAAO;oBACb,GAAG;oBACH,IAAI;iBACL,CAAC;YACJ,CAAC;YACD,YAAY;YACZ,cAAc,EAAE,OAAO,CAAC,SAAS;SAClC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function createExtension(selector: string): string;
|
package/esm/extension.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function createExtension(selector) {
|
|
2
|
+
const defaultExtensionSelector = 'piral-extension';
|
|
3
|
+
if ('customElements' in window && selector && selector !== defaultExtensionSelector) {
|
|
4
|
+
const ExtensionBase = customElements.get(defaultExtensionSelector);
|
|
5
|
+
class AliasExtension extends ExtensionBase {
|
|
6
|
+
}
|
|
7
|
+
customElements.define(selector, AliasExtension);
|
|
8
|
+
}
|
|
9
|
+
return selector || defaultExtensionSelector;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=extension.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,eAAe,CAAC,QAAgB;IAC9C,MAAM,wBAAwB,GAAG,iBAAiB,CAAC;IAEnD,IAAI,gBAAgB,IAAI,MAAM,IAAI,QAAQ,IAAI,QAAQ,KAAK,wBAAwB,EAAE;QACnF,MAAM,aAAa,GAAG,cAAc,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;QACnE,MAAM,cAAe,SAAQ,aAAa;SAAG;QAC7C,cAAc,CAAC,MAAM,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;KACjD;IAED,OAAO,QAAQ,IAAI,wBAAwB,CAAC;AAC9C,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/load.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function loadEmberApp(appName: string, appUrl: string, vendorUrl?: string): Promise<any>;
|
package/esm/load.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export function loadEmberApp(appName, appUrl, vendorUrl) {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
if (vendorUrl) {
|
|
4
|
+
const scriptVendor = document.createElement('script');
|
|
5
|
+
scriptVendor.src = vendorUrl;
|
|
6
|
+
scriptVendor.async = true;
|
|
7
|
+
scriptVendor.onload = loadApp;
|
|
8
|
+
scriptVendor.onerror = reject;
|
|
9
|
+
document.head.appendChild(scriptVendor);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
loadApp();
|
|
13
|
+
}
|
|
14
|
+
function loadApp() {
|
|
15
|
+
const scriptEl = document.createElement('script');
|
|
16
|
+
scriptEl.src = appUrl;
|
|
17
|
+
scriptEl.async = true;
|
|
18
|
+
scriptEl.onload = () => {
|
|
19
|
+
resolve(window.require(appName + '/app'));
|
|
20
|
+
};
|
|
21
|
+
scriptEl.onerror = reject;
|
|
22
|
+
document.head.appendChild(scriptEl);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=load.js.map
|
package/esm/load.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load.js","sourceRoot":"","sources":["../src/load.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,YAAY,CAAC,OAAe,EAAE,MAAc,EAAE,SAAkB;IAC9E,OAAO,IAAI,OAAO,CAAM,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC1C,IAAI,SAAS,EAAE;YACb,MAAM,YAAY,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;YACtD,YAAY,CAAC,GAAG,GAAG,SAAS,CAAC;YAC7B,YAAY,CAAC,KAAK,GAAG,IAAI,CAAC;YAC1B,YAAY,CAAC,MAAM,GAAG,OAAO,CAAC;YAC9B,YAAY,CAAC,OAAO,GAAG,MAAM,CAAC;YAC9B,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;SACzC;aAAM;YACL,OAAO,EAAE,CAAC;SACX;QAED,SAAS,OAAO;YACd,MAAM,QAAQ,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;YAClD,QAAQ,CAAC,GAAG,GAAG,MAAM,CAAC;YACtB,QAAQ,CAAC,KAAK,GAAG,IAAI,CAAC;YACtB,QAAQ,CAAC,MAAM,GAAG,GAAG,EAAE;gBACrB,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC;YAC5C,CAAC,CAAC;YACF,QAAQ,CAAC,OAAO,GAAG,MAAM,CAAC;YAC1B,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;QACtC,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/esm/types.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { ForeignComponent } from 'piral-core';
|
|
2
|
+
declare module 'piral-core/lib/types/custom' {
|
|
3
|
+
interface PiletCustomApi extends PiletEmberApi {
|
|
4
|
+
}
|
|
5
|
+
interface PiralCustomComponentConverters<TProps> {
|
|
6
|
+
ember(component: PiralEmberComponent<TProps>): ForeignComponent<TProps>;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export interface EmberOptions<TProps> {
|
|
10
|
+
props: TProps;
|
|
11
|
+
ctx: any;
|
|
12
|
+
}
|
|
13
|
+
export interface EmberInstance<TProps> {
|
|
14
|
+
setProperties(opts: EmberOptions<TProps>): void;
|
|
15
|
+
destroy(): void;
|
|
16
|
+
}
|
|
17
|
+
export interface EmberModule<TProps> {
|
|
18
|
+
create(opts: EmberOptions<TProps>): EmberInstance<TProps>;
|
|
19
|
+
}
|
|
20
|
+
export interface PiralEmberComponent<TProps> {
|
|
21
|
+
/**
|
|
22
|
+
* The Ember.js component App.
|
|
23
|
+
*/
|
|
24
|
+
App: EmberModule<TProps>;
|
|
25
|
+
/**
|
|
26
|
+
* The Ember.js component options.
|
|
27
|
+
*/
|
|
28
|
+
opts: any;
|
|
29
|
+
/**
|
|
30
|
+
* The type of the Ember.js component.
|
|
31
|
+
*/
|
|
32
|
+
type: 'ember';
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Defines the provided set of Pilet API extensions from the Ember.js plugin.
|
|
36
|
+
*/
|
|
37
|
+
export interface PiletEmberApi {
|
|
38
|
+
/**
|
|
39
|
+
* Loads an ember application via it's URLs.
|
|
40
|
+
* @param appName The name of the ember application.
|
|
41
|
+
* @param appUrl The URL of the main ember application.
|
|
42
|
+
* @param vendorUrl The optional URL of the (shared) ember vendor bundle.
|
|
43
|
+
* @returns The promise resolving to the loaded ember application.
|
|
44
|
+
*/
|
|
45
|
+
loadEmberApp<T = any>(appName: string, appUrl: string, vendorUrl?: string): Promise<T>;
|
|
46
|
+
/**
|
|
47
|
+
* Wraps an Emberjs component for use in Piral.
|
|
48
|
+
* @param App The component root.
|
|
49
|
+
* @param opts The component options.
|
|
50
|
+
* @returns The Piral Ember.js component.
|
|
51
|
+
*/
|
|
52
|
+
fromEmber<TProps>(App: EmberModule<TProps>, opts: any): PiralEmberComponent<TProps>;
|
|
53
|
+
/**
|
|
54
|
+
* Gets the name of the Ember.js extension.
|
|
55
|
+
*/
|
|
56
|
+
EmberExtension: string;
|
|
57
|
+
}
|
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 { ForeignComponent, BaseComponentProps } from 'piral-core';
|
|
2
|
-
import { EmberModule } from './types';
|
|
3
|
-
export
|
|
1
|
+
import type { ForeignComponent, BaseComponentProps } from 'piral-core';
|
|
2
|
+
import type { EmberModule } from './types';
|
|
3
|
+
export interface EmberConverterOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Defines the name of the extension component.
|
|
6
|
+
* @default ember-extension
|
|
7
|
+
*/
|
|
8
|
+
selector?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function createConverter(config?: EmberConverterOptions): {
|
|
11
|
+
<TProps extends BaseComponentProps>(App: EmberModule<TProps>, opts: any): ForeignComponent<TProps>;
|
|
12
|
+
Extension: string;
|
|
13
|
+
};
|
package/lib/converter.js
CHANGED
|
@@ -1,33 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createConverter = void 0;
|
|
4
|
-
|
|
5
|
-
function createConverter() {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
rootElement.innerHTML = '';
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
};
|
|
4
|
+
const extension_1 = require("./extension");
|
|
5
|
+
function createConverter(config = {}) {
|
|
6
|
+
const { selector = 'ember-extension' } = config;
|
|
7
|
+
const Extension = (0, extension_1.createExtension)(selector);
|
|
8
|
+
const convert = (App, opts) => ({
|
|
9
|
+
mount(rootElement, props, ctx, locals) {
|
|
10
|
+
locals.app = App.create(Object.assign(Object.assign({}, opts), { rootElement,
|
|
11
|
+
props,
|
|
12
|
+
ctx }));
|
|
13
|
+
},
|
|
14
|
+
update(rootElement, props, ctx, locals) {
|
|
15
|
+
locals.app.setProperties({
|
|
16
|
+
props,
|
|
17
|
+
ctx,
|
|
18
|
+
});
|
|
19
|
+
},
|
|
20
|
+
unmount(rootElement, locals) {
|
|
21
|
+
locals.app.destroy();
|
|
22
|
+
locals.app = undefined;
|
|
23
|
+
rootElement.innerHTML = '';
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
convert.Extension = Extension;
|
|
31
27
|
return convert;
|
|
32
28
|
}
|
|
33
29
|
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,2CAA8C;AAe9C,SAAgB,eAAe,CAAC,SAAgC,EAAE;IAChE,MAAM,EAAE,QAAQ,GAAG,iBAAiB,EAAE,GAAG,MAAM,CAAC;IAEhD,MAAM,SAAS,GAAG,IAAA,2BAAe,EAAC,QAAQ,CAAC,CAAC;IAE5C,MAAM,OAAO,GAAG,CACd,GAAwB,EACxB,IAAS,EACiB,EAAE,CAAC,CAAC;QAC9B,KAAK,CAAC,WAAW,EAAE,KAAK,EAAE,GAAG,EAAE,MAA0B;YACvD,MAAM,CAAC,GAAG,GAAG,GAAG,CAAC,MAAM,iCAClB,IAAI,KACP,WAAW;gBACX,KAAK;gBACL,GAAG,IACH,CAAC;QACL,CAAC;QACD,MAAM,CAAC,WAAW,EAAE,KAAK,EAAE,GAAG,EAAE,MAA0B;YACxD,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC;gBACvB,KAAK;gBACL,GAAG;aACJ,CAAC,CAAC;QACL,CAAC;QACD,OAAO,CAAC,WAAW,EAAE,MAA0B;YAC7C,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;YACrB,MAAM,CAAC,GAAG,GAAG,SAAS,CAAC;YACvB,WAAW,CAAC,SAAS,GAAG,EAAE,CAAC;QAC7B,CAAC;KACF,CAAC,CAAC;IACH,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;IAC9B,OAAO,OAAO,CAAC;AACjB,CAAC;AA/BD,0CA+BC"}
|
package/lib/create.d.ts
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import type { PiralPlugin } from 'piral-core';
|
|
2
|
+
import { EmberConverterOptions } from './converter';
|
|
2
3
|
import type { PiletEmberApi } from './types';
|
|
3
4
|
/**
|
|
4
5
|
* Available configuration options for the Ember.js plugin.
|
|
5
6
|
*/
|
|
6
|
-
export interface EmberConfig {
|
|
7
|
-
/**
|
|
8
|
-
* Defines the name of the extension component.
|
|
9
|
-
* @default ember-extension
|
|
10
|
-
*/
|
|
11
|
-
selector?: string;
|
|
7
|
+
export interface EmberConfig extends EmberConverterOptions {
|
|
12
8
|
}
|
|
13
9
|
/**
|
|
14
10
|
* Creates Pilet API extensions for integrating Ember.js.
|
package/lib/create.js
CHANGED
|
@@ -1,32 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createEmberApi = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var extension_1 = require("./extension");
|
|
4
|
+
const load_1 = require("./load");
|
|
5
|
+
const converter_1 = require("./converter");
|
|
7
6
|
/**
|
|
8
7
|
* Creates Pilet API extensions for integrating Ember.js.
|
|
9
8
|
*/
|
|
10
|
-
function createEmberApi(config) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var convert = converter_1.createConverter();
|
|
15
|
-
context.converters.ember = function (_a) {
|
|
16
|
-
var App = _a.App, opts = _a.opts;
|
|
17
|
-
return convert(App, opts);
|
|
18
|
-
};
|
|
19
|
-
extension_1.createExtension(selector);
|
|
9
|
+
function createEmberApi(config = {}) {
|
|
10
|
+
return (context) => {
|
|
11
|
+
const convert = (0, converter_1.createConverter)(config);
|
|
12
|
+
context.converters.ember = ({ App, opts }) => convert(App, opts);
|
|
20
13
|
return {
|
|
21
|
-
fromEmber
|
|
14
|
+
fromEmber(App, opts) {
|
|
22
15
|
return {
|
|
23
16
|
type: 'ember',
|
|
24
|
-
App
|
|
25
|
-
opts
|
|
17
|
+
App,
|
|
18
|
+
opts,
|
|
26
19
|
};
|
|
27
20
|
},
|
|
28
21
|
loadEmberApp: load_1.loadEmberApp,
|
|
29
|
-
EmberExtension:
|
|
22
|
+
EmberExtension: convert.Extension,
|
|
30
23
|
};
|
|
31
24
|
};
|
|
32
25
|
}
|
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,iCAAsC;AACtC,2CAAqE;AAQrE;;GAEG;AACH,SAAgB,cAAc,CAAC,SAAsB,EAAE;IACrD,OAAO,CAAC,OAAO,EAAE,EAAE;QACjB,MAAM,OAAO,GAAG,IAAA,2BAAe,EAAC,MAAM,CAAC,CAAC;QACxC,OAAO,CAAC,UAAU,CAAC,KAAK,GAAG,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QAEjE,OAAO;YACL,SAAS,CAAC,GAAG,EAAE,IAAI;gBACjB,OAAO;oBACL,IAAI,EAAE,OAAO;oBACb,GAAG;oBACH,IAAI;iBACL,CAAC;YACJ,CAAC;YACD,YAAY,EAAZ,mBAAY;YACZ,cAAc,EAAE,OAAO,CAAC,SAAS;SAClC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAjBD,wCAiBC"}
|
package/lib/extension.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function createExtension(selector
|
|
1
|
+
export declare function createExtension(selector: string): string;
|
package/lib/extension.js
CHANGED
|
@@ -1,32 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createExtension = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
4
|
function createExtension(selector) {
|
|
6
|
-
|
|
7
|
-
if ('customElements' in window) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
EmberExtension.prototype.connectedCallback = function () {
|
|
14
|
-
if (this.isConnected) {
|
|
15
|
-
this.dispatchEvent(new CustomEvent('render-html', {
|
|
16
|
-
bubbles: true,
|
|
17
|
-
detail: {
|
|
18
|
-
target: this,
|
|
19
|
-
props: {
|
|
20
|
-
name: this.getAttribute('name'),
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
}));
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
return EmberExtension;
|
|
27
|
-
}(HTMLElement));
|
|
28
|
-
customElements.define(selector, EmberExtension);
|
|
5
|
+
const defaultExtensionSelector = 'piral-extension';
|
|
6
|
+
if ('customElements' in window && selector && selector !== defaultExtensionSelector) {
|
|
7
|
+
const ExtensionBase = customElements.get(defaultExtensionSelector);
|
|
8
|
+
class AliasExtension extends ExtensionBase {
|
|
9
|
+
}
|
|
10
|
+
customElements.define(selector, AliasExtension);
|
|
29
11
|
}
|
|
12
|
+
return selector || defaultExtensionSelector;
|
|
30
13
|
}
|
|
31
14
|
exports.createExtension = createExtension;
|
|
32
15
|
//# sourceMappingURL=extension.js.map
|
package/lib/extension.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":";;;AAAA,SAAgB,eAAe,CAAC,QAAgB;IAC9C,MAAM,wBAAwB,GAAG,iBAAiB,CAAC;IAEnD,IAAI,gBAAgB,IAAI,MAAM,IAAI,QAAQ,IAAI,QAAQ,KAAK,wBAAwB,EAAE;QACnF,MAAM,aAAa,GAAG,cAAc,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;QACnE,MAAM,cAAe,SAAQ,aAAa;SAAG;QAC7C,cAAc,CAAC,MAAM,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;KACjD;IAED,OAAO,QAAQ,IAAI,wBAAwB,CAAC;AAC9C,CAAC;AAVD,0CAUC"}
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./create"), exports);
|
|
5
5
|
tslib_1.__exportStar(require("./types"), exports);
|
|
6
6
|
//# sourceMappingURL=index.js.map
|
package/lib/load.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.loadEmberApp = void 0;
|
|
4
4
|
function loadEmberApp(appName, appUrl, vendorUrl) {
|
|
5
|
-
return new Promise(
|
|
5
|
+
return new Promise((resolve, reject) => {
|
|
6
6
|
if (vendorUrl) {
|
|
7
|
-
|
|
7
|
+
const scriptVendor = document.createElement('script');
|
|
8
8
|
scriptVendor.src = vendorUrl;
|
|
9
9
|
scriptVendor.async = true;
|
|
10
10
|
scriptVendor.onload = loadApp;
|
|
@@ -15,10 +15,10 @@ function loadEmberApp(appName, appUrl, vendorUrl) {
|
|
|
15
15
|
loadApp();
|
|
16
16
|
}
|
|
17
17
|
function loadApp() {
|
|
18
|
-
|
|
18
|
+
const scriptEl = document.createElement('script');
|
|
19
19
|
scriptEl.src = appUrl;
|
|
20
20
|
scriptEl.async = true;
|
|
21
|
-
scriptEl.onload =
|
|
21
|
+
scriptEl.onload = () => {
|
|
22
22
|
resolve(window.require(appName + '/app'));
|
|
23
23
|
};
|
|
24
24
|
scriptEl.onerror = reject;
|
package/lib/load.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load.js","sourceRoot":"","sources":["../src/load.ts"],"names":[],"mappings":";;;AAAA,SAAgB,YAAY,CAAC,OAAe,EAAE,MAAc,EAAE,SAAkB;IAC9E,OAAO,IAAI,OAAO,CAAM,
|
|
1
|
+
{"version":3,"file":"load.js","sourceRoot":"","sources":["../src/load.ts"],"names":[],"mappings":";;;AAAA,SAAgB,YAAY,CAAC,OAAe,EAAE,MAAc,EAAE,SAAkB;IAC9E,OAAO,IAAI,OAAO,CAAM,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC1C,IAAI,SAAS,EAAE;YACb,MAAM,YAAY,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;YACtD,YAAY,CAAC,GAAG,GAAG,SAAS,CAAC;YAC7B,YAAY,CAAC,KAAK,GAAG,IAAI,CAAC;YAC1B,YAAY,CAAC,MAAM,GAAG,OAAO,CAAC;YAC9B,YAAY,CAAC,OAAO,GAAG,MAAM,CAAC;YAC9B,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;SACzC;aAAM;YACL,OAAO,EAAE,CAAC;SACX;QAED,SAAS,OAAO;YACd,MAAM,QAAQ,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;YAClD,QAAQ,CAAC,GAAG,GAAG,MAAM,CAAC;YACtB,QAAQ,CAAC,KAAK,GAAG,IAAI,CAAC;YACtB,QAAQ,CAAC,MAAM,GAAG,GAAG,EAAE;gBACrB,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC;YAC5C,CAAC,CAAC;YACF,QAAQ,CAAC,OAAO,GAAG,MAAM,CAAC;YAC1B,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;QACtC,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAxBD,oCAwBC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "piral-ember",
|
|
3
|
-
"version": "1.0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Plugin for integrating Ember.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,21 @@
|
|
|
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-ember.json src --exclude \"src/**/*.test.*\"",
|
|
39
64
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
40
65
|
},
|
|
41
66
|
"devDependencies": {
|
|
42
67
|
"@types/ember": "^3.1.1",
|
|
43
68
|
"ember-source": "^3.15.0",
|
|
44
|
-
"piral-core": "^1.0.0
|
|
69
|
+
"piral-core": "^1.0.0"
|
|
45
70
|
},
|
|
46
71
|
"peerDependencies": {
|
|
47
|
-
"ember-source": "^3.0.0"
|
|
48
|
-
"piral-core": "1.x"
|
|
72
|
+
"ember-source": "^3.0.0"
|
|
49
73
|
},
|
|
50
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "67d9a2920bd5231baf10bc87ae8985666b18fa3a"
|
|
51
75
|
}
|
package/src/converter.ts
CHANGED
|
@@ -1,42 +1,48 @@
|
|
|
1
|
-
import { ForeignComponent, BaseComponentProps } from 'piral-core';
|
|
2
|
-
import {
|
|
1
|
+
import type { ForeignComponent, BaseComponentProps } from 'piral-core';
|
|
2
|
+
import { createExtension } from './extension';
|
|
3
|
+
import type { EmberInstance, EmberModule } from './types';
|
|
4
|
+
|
|
5
|
+
export interface EmberConverterOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Defines the name of the extension component.
|
|
8
|
+
* @default ember-extension
|
|
9
|
+
*/
|
|
10
|
+
selector?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface EmberState<TProps> {
|
|
14
|
+
app: EmberInstance<TProps>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function createConverter(config: EmberConverterOptions = {}) {
|
|
18
|
+
const { selector = 'ember-extension' } = config;
|
|
19
|
+
|
|
20
|
+
const Extension = createExtension(selector);
|
|
3
21
|
|
|
4
|
-
export function createConverter() {
|
|
5
22
|
const convert = <TProps extends BaseComponentProps>(
|
|
6
23
|
App: EmberModule<TProps>,
|
|
7
24
|
opts: any,
|
|
8
|
-
): ForeignComponent<TProps> => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
props,
|
|
31
|
-
ctx,
|
|
32
|
-
});
|
|
33
|
-
},
|
|
34
|
-
unmount(rootElement) {
|
|
35
|
-
app.destroy();
|
|
36
|
-
app = undefined;
|
|
37
|
-
rootElement.innerHTML = '';
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
};
|
|
25
|
+
): ForeignComponent<TProps> => ({
|
|
26
|
+
mount(rootElement, props, ctx, locals: EmberState<TProps>) {
|
|
27
|
+
locals.app = App.create({
|
|
28
|
+
...opts,
|
|
29
|
+
rootElement,
|
|
30
|
+
props,
|
|
31
|
+
ctx,
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
update(rootElement, props, ctx, locals: EmberState<TProps>) {
|
|
35
|
+
locals.app.setProperties({
|
|
36
|
+
props,
|
|
37
|
+
ctx,
|
|
38
|
+
});
|
|
39
|
+
},
|
|
40
|
+
unmount(rootElement, locals: EmberState<TProps>) {
|
|
41
|
+
locals.app.destroy();
|
|
42
|
+
locals.app = undefined;
|
|
43
|
+
rootElement.innerHTML = '';
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
convert.Extension = Extension;
|
|
41
47
|
return convert;
|
|
42
48
|
}
|
package/src/create.ts
CHANGED
|
@@ -1,32 +1,21 @@
|
|
|
1
1
|
import type { PiralPlugin } from 'piral-core';
|
|
2
2
|
import { loadEmberApp } from './load';
|
|
3
|
-
import { createConverter } from './converter';
|
|
4
|
-
import { createExtension } from './extension';
|
|
3
|
+
import { createConverter, EmberConverterOptions } from './converter';
|
|
5
4
|
import type { PiletEmberApi } from './types';
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* Available configuration options for the Ember.js plugin.
|
|
9
8
|
*/
|
|
10
|
-
export interface EmberConfig {
|
|
11
|
-
/**
|
|
12
|
-
* Defines the name of the extension component.
|
|
13
|
-
* @default ember-extension
|
|
14
|
-
*/
|
|
15
|
-
selector?: string;
|
|
16
|
-
}
|
|
9
|
+
export interface EmberConfig extends EmberConverterOptions {}
|
|
17
10
|
|
|
18
11
|
/**
|
|
19
12
|
* Creates Pilet API extensions for integrating Ember.js.
|
|
20
13
|
*/
|
|
21
14
|
export function createEmberApi(config: EmberConfig = {}): PiralPlugin<PiletEmberApi> {
|
|
22
|
-
const { selector } = config;
|
|
23
|
-
|
|
24
15
|
return (context) => {
|
|
25
|
-
const convert = createConverter();
|
|
16
|
+
const convert = createConverter(config);
|
|
26
17
|
context.converters.ember = ({ App, opts }) => convert(App, opts);
|
|
27
18
|
|
|
28
|
-
createExtension(selector);
|
|
29
|
-
|
|
30
19
|
return {
|
|
31
20
|
fromEmber(App, opts) {
|
|
32
21
|
return {
|
|
@@ -36,7 +25,7 @@ export function createEmberApi(config: EmberConfig = {}): PiralPlugin<PiletEmber
|
|
|
36
25
|
};
|
|
37
26
|
},
|
|
38
27
|
loadEmberApp,
|
|
39
|
-
EmberExtension:
|
|
28
|
+
EmberExtension: convert.Extension,
|
|
40
29
|
};
|
|
41
30
|
};
|
|
42
31
|
}
|
package/src/extension.ts
CHANGED
|
@@ -1,23 +1,11 @@
|
|
|
1
|
-
export function createExtension(selector
|
|
2
|
-
|
|
3
|
-
class EmberExtension extends HTMLElement {
|
|
4
|
-
connectedCallback() {
|
|
5
|
-
if (this.isConnected) {
|
|
6
|
-
this.dispatchEvent(
|
|
7
|
-
new CustomEvent('render-html', {
|
|
8
|
-
bubbles: true,
|
|
9
|
-
detail: {
|
|
10
|
-
target: this,
|
|
11
|
-
props: {
|
|
12
|
-
name: this.getAttribute('name'),
|
|
13
|
-
},
|
|
14
|
-
},
|
|
15
|
-
}),
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
1
|
+
export function createExtension(selector: string) {
|
|
2
|
+
const defaultExtensionSelector = 'piral-extension';
|
|
20
3
|
|
|
21
|
-
|
|
4
|
+
if ('customElements' in window && selector && selector !== defaultExtensionSelector) {
|
|
5
|
+
const ExtensionBase = customElements.get(defaultExtensionSelector);
|
|
6
|
+
class AliasExtension extends ExtensionBase {}
|
|
7
|
+
customElements.define(selector, AliasExtension);
|
|
22
8
|
}
|
|
9
|
+
|
|
10
|
+
return selector || defaultExtensionSelector;
|
|
23
11
|
}
|
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 EmberConverter {
|
|
8
|
-
(...params: Parameters<typeof convert>): HtmlComponent<any>;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export const fromEmber: EmberConverter = (App, opts) => ({
|
|
12
|
-
type: 'html',
|
|
13
|
-
component: convert(App, opts),
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
export const createEmberExtension = createExtension;
|