piral-gea 0.0.1

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 - 2026 smapiot
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,85 @@
1
+ [![Piral Logo](https://github.com/smapiot/piral/raw/main/docs/assets/logo.png)](https://piral.io)
2
+
3
+ # [Piral Gea](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-gea.svg?style=flat)](https://www.npmjs.com/package/piral-gea) [![tested with vitest](https://img.shields.io/badge/tested_with-vitest-99424f.svg)](https://vitest.dev/) [![Community Chat](https://img.shields.io/discord/1222632475449229352)](https://discord.gg/kKJ2FZmK8t)
4
+
5
+ This is a plugin that only has a dependency to `@geajs/core`. What `piral-gea` brings to the table is a set of Pilet API extensions that can be used with `piral` or `piral-core`.
6
+
7
+ The set includes a Gea converter for any component registration, as well as a `fromGea` shortcut and a `GeaExtension` component.
8
+
9
+ By default, these API extensions are not integrated in `piral`, so you'd need to add them to your Piral instance.
10
+
11
+ ## Documentation
12
+
13
+ The following functions are brought to the Pilet API.
14
+
15
+ ### `fromGea()`
16
+
17
+ Transforms a standard Gea component into a component that can be used in Piral, essentially wrapping it with a reference to the corresponding converter.
18
+
19
+ ### `GeaExtension`
20
+
21
+ The extension slot component to be used in Gea components.
22
+
23
+ ## Usage
24
+
25
+ ::: summary: Modern Use (recommended)
26
+
27
+ The recommended way is to use `piral-gea` from your pilets. In this case, no registration in the Piral instance is required.
28
+
29
+ Example use:
30
+
31
+ ```ts
32
+ import { PiletApi } from '<name-of-piral-instance>';
33
+ import { fromGea } from 'piral-gea/convert';
34
+ import { GeaPage } from './GeaPage';
35
+
36
+ export function setup(piral: PiletApi) {
37
+ piral.registerPage('/sample', fromGea(GeaPage));
38
+ }
39
+ ```
40
+
41
+ Within Gea components the Piral Gea extension component can be used by referring to `GeaExtension`, e.g.,
42
+
43
+ ```jsx
44
+ <GeaExtension name="name-of-extension" />
45
+ ```
46
+ :::
47
+
48
+ ::: summary: Legacy Use
49
+
50
+ For backwards compatibility, you can also install `piral-gea` in your Piral instance.
51
+
52
+ Using Gea with Piral is as simple as installing `piral-gea` and the Gea package:
53
+
54
+ - `@geajs/core`
55
+
56
+ ```ts
57
+ import { createGeaApi } from 'piral-gea';
58
+ ```
59
+
60
+ The integration looks like:
61
+
62
+ ```ts
63
+ const instance = createInstance({
64
+ // important part
65
+ plugins: [createGeaApi()],
66
+ // ...
67
+ });
68
+ ```
69
+
70
+ The `@geajs/core` package should be shared with the pilets via the *package.json*:
71
+
72
+ ```json
73
+ {
74
+ "importmap": {
75
+ "imports": {
76
+ "@geajs/core": ""
77
+ }
78
+ }
79
+ }
80
+ ```
81
+ :::
82
+
83
+ ## License
84
+
85
+ Piral is released using the MIT license. For more information see the [license file](./LICENSE).
package/convert.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ import { createConverter } from './lib/converter';
2
+ export interface HtmlComponent<TProps> {
3
+ component: {
4
+ mount(element: HTMLElement, props: TProps, ctx: any, locals: any): void;
5
+ update?(element: HTMLElement, props: TProps, ctx: any, locals: any): void;
6
+ unmount?(element: HTMLElement, locals: any): void;
7
+ };
8
+ type: 'html';
9
+ }
10
+ export interface GeaConverter {
11
+ (...params: Parameters<ReturnType<typeof createConverter>>): HtmlComponent<any>;
12
+ }
13
+ export declare function createGeaConverter(...params: Parameters<typeof createConverter>): {
14
+ from: GeaConverter;
15
+ Extension: any;
16
+ };
17
+ declare const fromGea: GeaConverter, GeaExtension: any;
18
+ export { fromGea, GeaExtension };
package/convert.js ADDED
@@ -0,0 +1,16 @@
1
+ import { createConverter } from './lib/converter';
2
+ export function createGeaConverter() {
3
+ var params = [];
4
+ for (var _i = 0; _i < arguments.length; _i++) {
5
+ params[_i] = arguments[_i];
6
+ }
7
+ var convert = createConverter.apply(void 0, params);
8
+ var Extension = convert.Extension;
9
+ var from = function (root) { return ({
10
+ type: 'html',
11
+ component: convert(root),
12
+ }); };
13
+ return { from: from, Extension: Extension };
14
+ }
15
+ var _a = createGeaConverter(), fromGea = _a.from, GeaExtension = _a.Extension;
16
+ export { fromGea, GeaExtension };
@@ -0,0 +1,14 @@
1
+ import type { ForeignComponent, BaseComponentProps } from 'piral-core';
2
+ import type { GeaComponentType } from './types';
3
+ export interface GeaConverterOptions {
4
+ /**
5
+ * Defines the name of the root element.
6
+ * @default piral-slot
7
+ */
8
+ rootName?: string;
9
+ }
10
+ export interface GeaConverter {
11
+ <TProps extends BaseComponentProps>(root: GeaComponentType<TProps>): ForeignComponent<TProps>;
12
+ Extension: any;
13
+ }
14
+ export declare function createConverter(config?: GeaConverterOptions): GeaConverter;
@@ -0,0 +1,20 @@
1
+ import { mountGea, unmountGea } from './mount';
2
+ import { createExtension } from './extension';
3
+ export function createConverter(config = {}) {
4
+ const { rootName = 'piral-slot' } = config;
5
+ const Extension = createExtension(rootName);
6
+ const convert = ((root) => ({
7
+ mount(el, props, ctx, locals) {
8
+ mountGea(el, root, props, ctx, locals);
9
+ },
10
+ update(el, props, ctx, locals) {
11
+ mountGea(el, root, props, ctx, locals);
12
+ },
13
+ unmount(_el, locals) {
14
+ unmountGea(locals);
15
+ },
16
+ }));
17
+ convert.Extension = Extension;
18
+ return convert;
19
+ }
20
+ //# sourceMappingURL=converter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"converter.js","sourceRoot":"","sources":["../src/converter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAkB,MAAM,SAAS,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAe9C,MAAM,UAAU,eAAe,CAAC,SAA8B,EAAE;IAC9D,MAAM,EAAE,QAAQ,GAAG,YAAY,EAAE,GAAG,MAAM,CAAC;IAC3C,MAAM,SAAS,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC;IAC5C,MAAM,OAAO,GAAG,CAAC,CAAoC,IAA8B,EAA4B,EAAE,CAAC,CAAC;QACjH,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,MAAyB;YAC7C,QAAQ,CAAC,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;QACzC,CAAC;QACD,MAAM,CAAC,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,MAAyB;YAC9C,QAAQ,CAAC,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;QACzC,CAAC;QACD,OAAO,CAAC,GAAG,EAAE,MAAyB;YACpC,UAAU,CAAC,MAAM,CAAC,CAAC;QACrB,CAAC;KACF,CAAC,CAAiB,CAAC;IACpB,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 { GeaConverterOptions } from './converter';
3
+ import type { PiletGeaApi } from './types';
4
+ /**
5
+ * Available configuration options for the Gea plugin.
6
+ */
7
+ export interface GeaConfig extends GeaConverterOptions {
8
+ }
9
+ /**
10
+ * Creates Pilet API extensions for integrating Gea.
11
+ */
12
+ export declare function createGeaApi(config?: GeaConfig): PiralPlugin<PiletGeaApi>;
package/lib/create.js ADDED
@@ -0,0 +1,20 @@
1
+ import { createConverter } from './converter';
2
+ /**
3
+ * Creates Pilet API extensions for integrating Gea.
4
+ */
5
+ export function createGeaApi(config = {}) {
6
+ return (context) => {
7
+ const convert = createConverter(config);
8
+ context.converters.gea = ({ root }) => convert(root);
9
+ return {
10
+ fromGea(root) {
11
+ return {
12
+ type: 'gea',
13
+ root,
14
+ };
15
+ },
16
+ GeaExtension: convert.Extension,
17
+ };
18
+ };
19
+ }
20
+ //# sourceMappingURL=create.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAuB,MAAM,aAAa,CAAC;AAQnE;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,SAAoB,EAAE;IACjD,OAAO,CAAC,OAAO,EAAE,EAAE;QACjB,MAAM,OAAO,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;QACxC,OAAO,CAAC,UAAU,CAAC,GAAG,GAAG,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAErD,OAAO;YACL,OAAO,CAAC,IAAI;gBACV,OAAO;oBACL,IAAI,EAAE,KAAK;oBACX,IAAI;iBACL,CAAC;YACJ,CAAC;YACD,YAAY,EAAE,OAAO,CAAC,SAAS;SAChC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1 @@
1
+ export declare function createExtension(rootName: string): any;
@@ -0,0 +1,22 @@
1
+ import { Component } from '@geajs/core';
2
+ export function createExtension(rootName) {
3
+ class GeaExtension extends Component {
4
+ render(parent) {
5
+ if (!this.host) {
6
+ this.host = document.createElement(rootName);
7
+ }
8
+ if (this.host.parentNode !== parent) {
9
+ parent.appendChild(this.host);
10
+ }
11
+ this.host.innerHTML = '';
12
+ this.props.piral.renderHtmlExtension(this.host, this.props);
13
+ }
14
+ dispose() {
15
+ this.host?.remove();
16
+ this.host = undefined;
17
+ super.dispose();
18
+ }
19
+ }
20
+ return GeaExtension;
21
+ }
22
+ //# sourceMappingURL=extension.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAQxC,MAAM,UAAU,eAAe,CAAC,QAAgB;IAC9C,MAAM,YAAa,SAAQ,SAA4B;QAGrD,MAAM,CAAC,MAAY;YACjB,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;gBACf,IAAI,CAAC,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;YAC/C,CAAC;YAED,IAAI,IAAI,CAAC,IAAI,CAAC,UAAU,KAAK,MAAM,EAAE,CAAC;gBACpC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAChC,CAAC;YAED,IAAI,CAAC,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;YACzB,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,mBAAmB,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QAC9D,CAAC;QAED,OAAO;YACL,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC;YACpB,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC;YACtB,KAAK,CAAC,OAAO,EAAE,CAAC;QAClB,CAAC;KACF;IAED,OAAO,YAAY,CAAC;AACtB,CAAC"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './create';
2
+ export * from './types';
package/lib/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/lib/mount.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import type { BaseComponentProps } from 'piral-core';
2
+ import type { GeaComponentInstance } from './types';
3
+ export interface GeaLocals<T extends BaseComponentProps = BaseComponentProps> {
4
+ instance?: GeaComponentInstance<T>;
5
+ }
6
+ export declare function mountGea<T extends BaseComponentProps>(el: HTMLElement, root: new () => GeaComponentInstance<T>, props: T, _ctx?: any, locals?: GeaLocals<T>): void;
7
+ export declare function unmountGea<T extends BaseComponentProps>(locals: GeaLocals<T>): void;
package/lib/mount.js ADDED
@@ -0,0 +1,16 @@
1
+ export function mountGea(el, root, props, _ctx = {}, locals = {}) {
2
+ if (!locals.instance) {
3
+ locals.instance = new root();
4
+ locals.instance.props = props;
5
+ locals.instance.render(el);
6
+ }
7
+ else {
8
+ locals.instance.props = props;
9
+ locals.instance.flushSync();
10
+ }
11
+ }
12
+ export function unmountGea(locals) {
13
+ locals.instance?.dispose();
14
+ locals.instance = undefined;
15
+ }
16
+ //# sourceMappingURL=mount.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mount.js","sourceRoot":"","sources":["../src/mount.ts"],"names":[],"mappings":"AAOA,MAAM,UAAU,QAAQ,CACtB,EAAe,EACf,IAAuC,EACvC,KAAQ,EACR,OAAY,EAAE,EACd,SAAuB,EAAE;IAEzB,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;QACrB,MAAM,CAAC,QAAQ,GAAG,IAAI,IAAI,EAAE,CAAC;QAC7B,MAAM,CAAC,QAAQ,CAAC,KAAK,GAAG,KAAK,CAAC;QAC9B,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAC7B,CAAC;SAAM,CAAC;QACN,MAAM,CAAC,QAAQ,CAAC,KAAK,GAAG,KAAK,CAAC;QAC9B,MAAM,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC;IAC9B,CAAC;AACH,CAAC;AAED,MAAM,UAAU,UAAU,CAA+B,MAAoB;IAC3E,MAAM,CAAC,QAAQ,EAAE,OAAO,EAAE,CAAC;IAC3B,MAAM,CAAC,QAAQ,GAAG,SAAS,CAAC;AAC9B,CAAC"}
package/lib/types.d.ts ADDED
@@ -0,0 +1,40 @@
1
+ import type { ForeignComponent, ExtensionSlotProps } from 'piral-core';
2
+ export interface GeaComponentInstance<TProps> {
3
+ props: TProps;
4
+ render(parent: Node, index?: number): void;
5
+ flushSync(): void;
6
+ dispose(): void;
7
+ }
8
+ export type GeaComponentType<TProps> = new () => GeaComponentInstance<TProps>;
9
+ declare module 'piral-core/lib/types/custom' {
10
+ interface PiletCustomApi extends PiletGeaApi {
11
+ }
12
+ interface PiralCustomComponentConverters<TProps> {
13
+ gea(component: GeaComponent<TProps>): ForeignComponent<TProps>;
14
+ }
15
+ }
16
+ export interface GeaComponent<TProps> {
17
+ /**
18
+ * The component root.
19
+ */
20
+ root: GeaComponentType<TProps>;
21
+ /**
22
+ * The type of the Gea component.
23
+ */
24
+ type: 'gea';
25
+ }
26
+ /**
27
+ * Defines the provided set of Pilet API extensions from the Gea plugin.
28
+ */
29
+ export interface PiletGeaApi {
30
+ /**
31
+ * Wraps a Gea component for use in Piral.
32
+ * @param component The component root.
33
+ * @returns The Piral Gea component.
34
+ */
35
+ fromGea<TProps>(component: GeaComponentType<TProps>): GeaComponent<TProps>;
36
+ /**
37
+ * Gea component for displaying extensions of the given name.
38
+ */
39
+ GeaExtension: GeaComponentType<ExtensionSlotProps>;
40
+ }
package/lib/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":""}
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "piral-gea",
3
+ "version": "0.0.1",
4
+ "description": "Plugin for integrating Gea components in Piral.",
5
+ "keywords": [
6
+ "piral",
7
+ "pilet-api",
8
+ "smapiot",
9
+ "portal",
10
+ "modules",
11
+ "api",
12
+ "plugin",
13
+ "plugin-converter",
14
+ "gea"
15
+ ],
16
+ "author": "smapiot",
17
+ "homepage": "https://piral.io",
18
+ "license": "MIT",
19
+ "module": "lib/index.js",
20
+ "main": "lib/index.js",
21
+ "typings": "lib/index.d.ts",
22
+ "exports": {
23
+ ".": "./lib/index.js",
24
+ "./convert": "./convert.js",
25
+ "./lib/*": {
26
+ "types": "./lib/*.d.ts",
27
+ "import": "./lib/*"
28
+ },
29
+ "./package.json": "./package.json"
30
+ },
31
+ "sideEffects": false,
32
+ "files": [
33
+ "lib",
34
+ "src",
35
+ "convert.d.ts",
36
+ "convert.js"
37
+ ],
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "https://github.com/smapiot/piral.git"
41
+ },
42
+ "bugs": {
43
+ "url": "https://github.com/smapiot/piral/issues"
44
+ },
45
+ "scripts": {
46
+ "cleanup": "rimraf esm lib convert.d.ts convert.js",
47
+ "build": "yarn build:esnext && yarn build:convert",
48
+ "build:convert": "tsc convert.ts --skipLibCheck --declaration --module esnext",
49
+ "build:esnext": "tsc --project tsconfig.json --outDir lib --module esnext",
50
+ "typedoc": "typedoc --json ../../../docs/types/piral-gea.json src --exclude \"src/**/*.test.*\"",
51
+ "test": "echo \"Error: run tests from root\" && exit 1"
52
+ },
53
+ "devDependencies": {
54
+ "@geajs/core": "^1.4.0",
55
+ "piral-core": "^1.11.2"
56
+ }
57
+ }
@@ -0,0 +1,35 @@
1
+ import type { ForeignComponent, BaseComponentProps } from 'piral-core';
2
+ import type { GeaComponentType } from './types';
3
+ import { mountGea, unmountGea, type GeaLocals } from './mount';
4
+ import { createExtension } from './extension';
5
+
6
+ export interface GeaConverterOptions {
7
+ /**
8
+ * Defines the name of the root element.
9
+ * @default piral-slot
10
+ */
11
+ rootName?: string;
12
+ }
13
+
14
+ export interface GeaConverter {
15
+ <TProps extends BaseComponentProps>(root: GeaComponentType<TProps>): ForeignComponent<TProps>;
16
+ Extension: any;
17
+ }
18
+
19
+ export function createConverter(config: GeaConverterOptions = {}): GeaConverter {
20
+ const { rootName = 'piral-slot' } = config;
21
+ const Extension = createExtension(rootName);
22
+ const convert = (<TProps extends BaseComponentProps>(root: GeaComponentType<TProps>): ForeignComponent<TProps> => ({
23
+ mount(el, props, ctx, locals: GeaLocals<TProps>) {
24
+ mountGea(el, root, props, ctx, locals);
25
+ },
26
+ update(el, props, ctx, locals: GeaLocals<TProps>) {
27
+ mountGea(el, root, props, ctx, locals);
28
+ },
29
+ unmount(_el, locals: GeaLocals<TProps>) {
30
+ unmountGea(locals);
31
+ },
32
+ })) as GeaConverter;
33
+ convert.Extension = Extension;
34
+ return convert;
35
+ }
package/src/create.ts ADDED
@@ -0,0 +1,28 @@
1
+ import type { PiralPlugin } from 'piral-core';
2
+ import { createConverter, GeaConverterOptions } from './converter';
3
+ import type { PiletGeaApi } from './types';
4
+
5
+ /**
6
+ * Available configuration options for the Gea plugin.
7
+ */
8
+ export interface GeaConfig extends GeaConverterOptions {}
9
+
10
+ /**
11
+ * Creates Pilet API extensions for integrating Gea.
12
+ */
13
+ export function createGeaApi(config: GeaConfig = {}): PiralPlugin<PiletGeaApi> {
14
+ return (context) => {
15
+ const convert = createConverter(config);
16
+ context.converters.gea = ({ root }) => convert(root);
17
+
18
+ return {
19
+ fromGea(root) {
20
+ return {
21
+ type: 'gea',
22
+ root,
23
+ };
24
+ },
25
+ GeaExtension: convert.Extension,
26
+ };
27
+ };
28
+ }
@@ -0,0 +1,35 @@
1
+ import type { ExtensionSlotProps } from 'piral-core';
2
+ import { Component } from '@geajs/core';
3
+
4
+ type GeaExtensionProps = ExtensionSlotProps & {
5
+ piral: {
6
+ renderHtmlExtension(element: HTMLElement, props: ExtensionSlotProps): void;
7
+ };
8
+ };
9
+
10
+ export function createExtension(rootName: string): any {
11
+ class GeaExtension extends Component<GeaExtensionProps> {
12
+ host?: HTMLElement;
13
+
14
+ render(parent: Node) {
15
+ if (!this.host) {
16
+ this.host = document.createElement(rootName);
17
+ }
18
+
19
+ if (this.host.parentNode !== parent) {
20
+ parent.appendChild(this.host);
21
+ }
22
+
23
+ this.host.innerHTML = '';
24
+ this.props.piral.renderHtmlExtension(this.host, this.props);
25
+ }
26
+
27
+ dispose() {
28
+ this.host?.remove();
29
+ this.host = undefined;
30
+ super.dispose();
31
+ }
32
+ }
33
+
34
+ return GeaExtension;
35
+ }
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './create';
2
+ export * from './types';
package/src/mount.ts ADDED
@@ -0,0 +1,28 @@
1
+ import type { BaseComponentProps } from 'piral-core';
2
+ import type { GeaComponentInstance } from './types';
3
+
4
+ export interface GeaLocals<T extends BaseComponentProps = BaseComponentProps> {
5
+ instance?: GeaComponentInstance<T>;
6
+ }
7
+
8
+ export function mountGea<T extends BaseComponentProps>(
9
+ el: HTMLElement,
10
+ root: new () => GeaComponentInstance<T>,
11
+ props: T,
12
+ _ctx: any = {},
13
+ locals: GeaLocals<T> = {},
14
+ ) {
15
+ if (!locals.instance) {
16
+ locals.instance = new root();
17
+ locals.instance.props = props;
18
+ locals.instance.render(el);
19
+ } else {
20
+ locals.instance.props = props;
21
+ locals.instance.flushSync();
22
+ }
23
+ }
24
+
25
+ export function unmountGea<T extends BaseComponentProps>(locals: GeaLocals<T>) {
26
+ locals.instance?.dispose();
27
+ locals.instance = undefined;
28
+ }
package/src/types.ts ADDED
@@ -0,0 +1,45 @@
1
+ import type { ForeignComponent, ExtensionSlotProps } from 'piral-core';
2
+
3
+ export interface GeaComponentInstance<TProps> {
4
+ props: TProps;
5
+ render(parent: Node, index?: number): void;
6
+ flushSync(): void;
7
+ dispose(): void;
8
+ }
9
+
10
+ export type GeaComponentType<TProps> = new () => GeaComponentInstance<TProps>;
11
+
12
+ declare module 'piral-core/lib/types/custom' {
13
+ interface PiletCustomApi extends PiletGeaApi {}
14
+
15
+ interface PiralCustomComponentConverters<TProps> {
16
+ gea(component: GeaComponent<TProps>): ForeignComponent<TProps>;
17
+ }
18
+ }
19
+
20
+ export interface GeaComponent<TProps> {
21
+ /**
22
+ * The component root.
23
+ */
24
+ root: GeaComponentType<TProps>;
25
+ /**
26
+ * The type of the Gea component.
27
+ */
28
+ type: 'gea';
29
+ }
30
+
31
+ /**
32
+ * Defines the provided set of Pilet API extensions from the Gea plugin.
33
+ */
34
+ export interface PiletGeaApi {
35
+ /**
36
+ * Wraps a Gea component for use in Piral.
37
+ * @param component The component root.
38
+ * @returns The Piral Gea component.
39
+ */
40
+ fromGea<TProps>(component: GeaComponentType<TProps>): GeaComponent<TProps>;
41
+ /**
42
+ * Gea component for displaying extensions of the given name.
43
+ */
44
+ GeaExtension: GeaComponentType<ExtensionSlotProps>;
45
+ }