piral-solid 1.0.0-pre.2107 → 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 Solid](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-solid.svg?style=flat)](https://www.npmjs.com/package/piral-solid) [![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 Solid](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-solid.svg?style=flat)](https://www.npmjs.com/package/piral-solid) [![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-solid` 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 `solid-js`. What `piral-solid` 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 a Solid converter for any component registration, as well as a `fromSolid` shortcut and a `SolidExtension` component.
8
8
 
@@ -47,7 +47,7 @@ Alternatively, if `piral-solid` has not been added to the Piral instance you can
47
47
 
48
48
  ```ts
49
49
  import { PiletApi } from '<name-of-piral-instance>';
50
- import { fromSolid } from 'piral-solid';
50
+ import { fromSolid } from 'piral-solid/convert';
51
51
  import { SolidPage } from './SolidPage';
52
52
 
53
53
  export function setup(piral: PiletApi) {
@@ -59,7 +59,7 @@ export function setup(piral: PiletApi) {
59
59
 
60
60
  ::: summary: For Piral instance developers
61
61
 
62
- Using Solid with Piral is as simple as installing `piral-solid` and `solid-js`.
62
+ Using Solid with Piral is as simple as installing `piral-solid` and `solid-js@^1`.
63
63
 
64
64
  ```ts
65
65
  import { createSolidApi } from 'piral-solid';
@@ -75,15 +75,15 @@ const instance = createInstance({
75
75
  });
76
76
  ```
77
77
 
78
- The `solid-js` and `solid-js/dom` packages should be shared with the pilets via the *package.json*:
78
+ The `solid-js` and `solid-js/web` packages should be shared with the pilets via the *package.json*:
79
79
 
80
80
  ```json
81
81
  {
82
- "pilets": {
83
- "externals": [
84
- "solid-js",
85
- "solid-js/dom"
86
- ]
82
+ "importmap": {
83
+ "imports": {
84
+ "solid-js": "",
85
+ "solid-js/web": ""
86
+ }
87
87
  }
88
88
  }
89
89
  ```
package/convert.d.ts CHANGED
@@ -1,9 +1,18 @@
1
- import type { HtmlComponent } from 'piral-core';
2
- import { createExtension } from './lib/extension';
3
- declare const convert: <TProps extends import("piral-core").BaseComponentProps>(root: import("solid-js").Component<TProps>) => import("piral-core").ForeignComponent<TProps>;
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 SolidConverter {
5
- (...params: Parameters<typeof convert>): HtmlComponent<any>;
11
+ (...params: Parameters<ReturnType<typeof createConverter>>): HtmlComponent<any>;
6
12
  }
7
- export declare const fromSolid: SolidConverter;
8
- export declare const createSolidExtension: typeof createExtension;
9
- export {};
13
+ export declare function createSolidConverter(...params: Parameters<typeof createConverter>): {
14
+ from: SolidConverter;
15
+ Extension: Component<any>;
16
+ };
17
+ declare const fromSolid: SolidConverter, SolidExtension: Component<any>;
18
+ export { fromSolid, SolidExtension };
package/convert.js CHANGED
@@ -1,11 +1,16 @@
1
- "use strict";
2
- exports.__esModule = true;
3
- exports.createSolidExtension = exports.fromSolid = void 0;
4
- var converter_1 = require("./lib/converter");
5
- var extension_1 = require("./lib/extension");
6
- var convert = converter_1.createConverter();
7
- exports.fromSolid = function (root) { return ({
8
- type: 'html',
9
- component: convert(root)
10
- }); };
11
- exports.createSolidExtension = extension_1.createExtension;
1
+ import { createConverter } from './esm/converter';
2
+ export function createSolidConverter() {
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 = createSolidConverter(), fromSolid = _a.from, SolidExtension = _a.Extension;
16
+ export { fromSolid, SolidExtension };
@@ -1,3 +1,13 @@
1
- import { ForeignComponent, BaseComponentProps } from 'piral-core';
1
+ import type { ForeignComponent, BaseComponentProps } from 'piral-core';
2
2
  import { Component } from 'solid-js';
3
- export declare function createConverter(): <TProps extends BaseComponentProps>(root: Component<TProps>) => ForeignComponent<TProps>;
3
+ export interface SolidConverterOptions {
4
+ /**
5
+ * Defines the name of the root element.
6
+ * @default piral-slot
7
+ */
8
+ rootName?: string;
9
+ }
10
+ export declare function createConverter(config?: SolidConverterOptions): {
11
+ <TProps extends BaseComponentProps>(root: Component<TProps>): ForeignComponent<TProps>;
12
+ Extension: Component<import("piral-core").ExtensionSlotProps>;
13
+ };
package/esm/converter.js CHANGED
@@ -1,16 +1,30 @@
1
- import { render, createComponent } from 'solid-js/dom';
2
- export function createConverter() {
3
- const convert = (root) => {
4
- return {
5
- mount(parent, data, context) {
6
- render(() => createComponent(root, Object.assign({ context }, data)), parent);
7
- },
8
- unmount(el) {
9
- render(() => undefined, el);
10
- el.innerHTML = '';
11
- },
12
- };
13
- };
1
+ import { onCleanup } from 'solid-js';
2
+ import { render, createComponent } from 'solid-js/web';
3
+ import { createExtension } from './extension';
4
+ export function createConverter(config = {}) {
5
+ const { rootName = 'piral-slot' } = config;
6
+ const Extension = createExtension(rootName);
7
+ const convert = (root) => ({
8
+ mount(el, props, context, locals) {
9
+ locals.update = (props, context) => {
10
+ locals.destroy = render(() => {
11
+ onCleanup(() => {
12
+ el.innerHTML = '';
13
+ });
14
+ return createComponent(root, Object.assign({ context }, props));
15
+ }, el);
16
+ };
17
+ locals.update(props, context);
18
+ },
19
+ update(el, props, context, locals) {
20
+ locals.destroy();
21
+ locals.update(props, context);
22
+ },
23
+ unmount(el, locals) {
24
+ locals.destroy();
25
+ },
26
+ });
27
+ convert.Extension = Extension;
14
28
  return convert;
15
29
  }
16
30
  //# sourceMappingURL=converter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"converter.js","sourceRoot":"","sources":["../src/converter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEvD,MAAM,UAAU,eAAe;IAC7B,MAAM,OAAO,GAAG,CAAoC,IAAuB,EAA4B,EAAE;QACvG,OAAO;YACL,KAAK,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO;gBACzB,MAAM,CAAC,GAAG,EAAE,CAAC,eAAe,CAAC,IAAI,kBAAI,OAAO,IAAK,IAAI,EAAG,EAAE,MAAM,CAAC,CAAC;YACpE,CAAC;YACD,OAAO,CAAC,EAAE;gBACR,MAAM,CAAC,GAAG,EAAE,CA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AC;QAChC,CAAC;QACD,OAAO,CAAC,EAAE,EAAE,MAAM;YAChB,MAAM,CAAC,OAAO,EAAE,CAAC;QACnB,CAAC;KACF,CAAC,CAAC;IACH,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;IAC9B,OAAO,OAAO,CAAC;AACjB,CAAC"}
package/esm/create.d.ts CHANGED
@@ -4,11 +4,6 @@ import type { PiletSolidApi } from './types';
4
4
  * Available configuration options for the Solid plugin.
5
5
  */
6
6
  export interface SolidConfig {
7
- /**
8
- * Defines the name of the root element.
9
- * @default slot
10
- */
11
- rootName?: string;
12
7
  }
13
8
  /**
14
9
  * Creates new Pilet API extensions for integration of Solid.
package/esm/create.js CHANGED
@@ -1,22 +1,20 @@
1
1
  import { createConverter } from './converter';
2
- import { createExtension } from './extension';
3
2
  /**
4
3
  * Creates new Pilet API extensions for integration of Solid.
5
4
  */
6
5
  export function createSolidApi(config = {}) {
7
- const { rootName } = config;
8
6
  return (context) => {
9
- const convert = createConverter();
7
+ const convert = createConverter(config);
10
8
  context.converters.solid = ({ root }) => convert(root);
11
- return (api) => ({
9
+ return {
12
10
  fromSolid(root) {
13
11
  return {
14
12
  type: 'solid',
15
13
  root,
16
14
  };
17
15
  },
18
- SolidExtension: createExtension(api, rootName),
19
- });
16
+ SolidExtension: convert.Extension,
17
+ };
20
18
  };
21
19
  }
22
20
  //# sourceMappingURL=create.js.map
package/esm/create.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAc9C;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,SAAsB,EAAE;IACrD,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC;IAE5B,OAAO,CAAC,OAAO,EAAE,EAAE;QACjB,MAAM,OAAO,GAAG,eAAe,EAAE,CAAC;QAClC,OAAO,CAAC,UAAU,CAAC,KAAK,GAAG,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAEvD,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YACf,SAAS,CAAC,IAAI;gBACZ,OAAO;oBACL,IAAI,EAAE,OAAO;oBACb,IAAI;iBACL,CAAC;YACJ,CAAC;YACD,cAAc,EAAE,eAAe,CAAC,GAAG,EAAE,QAAQ,CAAC;SAC/C,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAQ9C;;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,IAAI,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAEvD,OAAO;YACL,SAAS,CAAC,IAAI;gBACZ,OAAO;oBACL,IAAI,EAAE,OAAO;oBACb,IAAI;iBACL,CAAC;YACJ,CAAC;YACD,cAAc,EAAE,OAAO,CAAC,SAAS;SAClC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
@@ -1,3 +1,3 @@
1
- import type { PiletApi, ExtensionSlotProps } from 'piral-core';
1
+ import type { ExtensionSlotProps } from 'piral-core';
2
2
  import type { Component } from 'solid-js';
3
- export declare function createExtension(api: PiletApi, rootName?: string): Component<ExtensionSlotProps>;
3
+ export declare function createExtension(rootName: string): Component<ExtensionSlotProps>;
package/esm/extension.js CHANGED
@@ -1,7 +1,26 @@
1
- export function createExtension(api, rootName = 'slot') {
1
+ import { createEffect } from 'solid-js';
2
+ export function createExtension(rootName) {
2
3
  return (props) => {
3
4
  const element = document.createElement(rootName);
4
- setTimeout(() => api.renderHtmlExtension(element, props), 0);
5
+ setTimeout(() => {
6
+ element.dispatchEvent(new CustomEvent('render-html', {
7
+ bubbles: true,
8
+ detail: {
9
+ target: element,
10
+ props,
11
+ },
12
+ }));
13
+ }, 0);
14
+ createEffect(() => {
15
+ element.dispatchEvent(new CustomEvent('extension-props-changed', {
16
+ detail: {
17
+ name: props.name,
18
+ empty: props.empty,
19
+ params: props.params,
20
+ render: props.render,
21
+ },
22
+ }));
23
+ });
5
24
  return element;
6
25
  };
7
26
  }
@@ -1 +1 @@
1
- {"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,eAAe,CAAC,GAAa,EAAE,QAAQ,GAAG,MAAM;IAC9D,OAAO,CAAC,KAAK,EAAE,EAAE;QACf,MAAM,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QACjD,UAAU,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;QAC7D,OAAO,OAAc,CAAC;IACxB,CAAC,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC,MAAM,UAAU,eAAe,CAAC,QAAgB;IAC9C,OAAO,CAAC,KAAK,EAAE,EAAE;QACf,MAAM,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QACjD,UAAU,CAAC,GAAG,EAAE;YACd,OAAO,CAAC,aAAa,CACnB,IAAI,WAAW,CAAC,aAAa,EAAE;gBAC7B,OAAO,EAAE,IAAI;gBACb,MAAM,EAAE;oBACN,MAAM,EAAE,OAAO;oBACf,KAAK;iBACN;aACF,CAAC,CACH,CAAC;QACJ,CAAC,EAAE,CAAC,CAAC,CAAC;QAEN,YAAY,CAAC,GAAG,EAAE;YAChB,OAAO,CAAC,aAAa,CACnB,IAAI,WAAW,CAAC,yBAAyB,EAAE;gBACzC,MAAM,EAAE;oBACN,IAAI,EAAE,KAAK,CAAC,IAAI;oBAChB,KAAK,EAAE,KAAK,CAAC,KAAK;oBAClB,MAAM,EAAE,KAAK,CAAC,MAAM;oBACpB,MAAM,EAAE,KAAK,CAAC,MAAM;iBACrB;aACF,CAAC,CACH,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,OAAO,OAAc,CAAC;IACxB,CAAC,CAAC;AACJ,CAAC"}
package/esm/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { ForeignComponent, ExtensionSlotProps } from 'piral-core';
2
- import { Component } from 'solid-js';
1
+ import type { ForeignComponent, ExtensionSlotProps } from 'piral-core';
2
+ import type { Component } from 'solid-js';
3
3
  declare module 'piral-core/lib/types/custom' {
4
4
  interface PiletCustomApi extends PiletSolidApi {
5
5
  }
@@ -1,3 +1,13 @@
1
- import { ForeignComponent, BaseComponentProps } from 'piral-core';
1
+ import type { ForeignComponent, BaseComponentProps } from 'piral-core';
2
2
  import { Component } from 'solid-js';
3
- export declare function createConverter(): <TProps extends BaseComponentProps>(root: Component<TProps>) => ForeignComponent<TProps>;
3
+ export interface SolidConverterOptions {
4
+ /**
5
+ * Defines the name of the root element.
6
+ * @default piral-slot
7
+ */
8
+ rootName?: string;
9
+ }
10
+ export declare function createConverter(config?: SolidConverterOptions): {
11
+ <TProps extends BaseComponentProps>(root: Component<TProps>): ForeignComponent<TProps>;
12
+ Extension: Component<import("piral-core").ExtensionSlotProps>;
13
+ };
package/lib/converter.js CHANGED
@@ -1,19 +1,33 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createConverter = void 0;
4
- const dom_1 = require("solid-js/dom");
5
- function createConverter() {
6
- const convert = (root) => {
7
- return {
8
- mount(parent, data, context) {
9
- dom_1.render(() => dom_1.createComponent(root, Object.assign({ context }, data)), parent);
10
- },
11
- unmount(el) {
12
- dom_1.render(() => undefined, el);
13
- el.innerHTML = '';
14
- },
15
- };
16
- };
4
+ const solid_js_1 = require("solid-js");
5
+ const web_1 = require("solid-js/web");
6
+ const extension_1 = require("./extension");
7
+ function createConverter(config = {}) {
8
+ const { rootName = 'piral-slot' } = config;
9
+ const Extension = (0, extension_1.createExtension)(rootName);
10
+ const convert = (root) => ({
11
+ mount(el, props, context, locals) {
12
+ locals.update = (props, context) => {
13
+ locals.destroy = (0, web_1.render)(() => {
14
+ (0, solid_js_1.onCleanup)(() => {
15
+ el.innerHTML = '';
16
+ });
17
+ return (0, web_1.createComponent)(root, Object.assign({ context }, props));
18
+ }, el);
19
+ };
20
+ locals.update(props, context);
21
+ },
22
+ update(el, props, context, locals) {
23
+ locals.destroy();
24
+ locals.update(props, context);
25
+ },
26
+ unmount(el, locals) {
27
+ locals.destroy();
28
+ },
29
+ });
30
+ convert.Extension = Extension;
17
31
  return convert;
18
32
  }
19
33
  exports.createConverter = createConverter;
@@ -1 +1 @@
1
- {"version":3,"file":"converter.js","sourceRoot":"","sources":["../src/converter.ts"],"names":[],"mappings":";;;AAEA,sCAAuD;AAEvD,SAAgB,eAAe;IAC7B,MAAM,OAAO,GAAG,CAAoC,IAAuB,EAA4B,EAAE;QACvG,OAAO;YACL,KAAK,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO;gBACzB,YAAM,CAAC,GAAG,EAAE,CAAC,qBAAe,CAAC,IAAI,kBAAI,OAAO,IAAK,IAAI,EAAG,EAAE,MAAM,CAAC,CAAC;YACpE,CAAC;YACD,OAAO,CAAC,EAAE;gBACR,YAAM,CAAC,GAAG,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;gBAC5B,EAAE,CAAC,SAAS,GAAG,EAAE,CAAC;YACpB,CAAC;SACF,CAAC;IACJ,CAAC,CAAC;IACF,OAAO,OA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C"}
package/lib/create.d.ts CHANGED
@@ -4,11 +4,6 @@ import type { PiletSolidApi } from './types';
4
4
  * Available configuration options for the Solid plugin.
5
5
  */
6
6
  export interface SolidConfig {
7
- /**
8
- * Defines the name of the root element.
9
- * @default slot
10
- */
11
- rootName?: string;
12
7
  }
13
8
  /**
14
9
  * Creates new Pilet API extensions for integration of Solid.
package/lib/create.js CHANGED
@@ -2,24 +2,22 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createSolidApi = void 0;
4
4
  const converter_1 = require("./converter");
5
- const extension_1 = require("./extension");
6
5
  /**
7
6
  * Creates new Pilet API extensions for integration of Solid.
8
7
  */
9
8
  function createSolidApi(config = {}) {
10
- const { rootName } = config;
11
9
  return (context) => {
12
- const convert = converter_1.createConverter();
10
+ const convert = (0, converter_1.createConverter)(config);
13
11
  context.converters.solid = ({ root }) => convert(root);
14
- return (api) => ({
12
+ return {
15
13
  fromSolid(root) {
16
14
  return {
17
15
  type: 'solid',
18
16
  root,
19
17
  };
20
18
  },
21
- SolidExtension: extension_1.createExtension(api, rootName),
22
- });
19
+ SolidExtension: convert.Extension,
20
+ };
23
21
  };
24
22
  }
25
23
  exports.createSolidApi = createSolidApi;
package/lib/create.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":";;;AACA,2CAA8C;AAC9C,2CAA8C;AAc9C;;GAEG;AACH,SAAgB,cAAc,CAAC,SAAsB,EAAE;IACrD,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC;IAE5B,OAAO,CAAC,OAAO,EAAE,EAAE;QACjB,MAAM,OAAO,GAAG,2BAAe,EAAE,CAAC;QAClC,OAAO,CAAC,UAAU,CAAC,KAAK,GAAG,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAEvD,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YACf,SAAS,CAAC,IAAI;gBACZ,OAAO;oBACL,IAAI,EAAE,OAAO;oBACb,IAAI;iBACL,CAAC;YACJ,CAAC;YACD,cAAc,EAAE,2BAAe,CAAC,GAAG,EAAE,QAAQ,CAAC;SAC/C,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAjBD,wCAiBC"}
1
+ {"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":";;;AACA,2CAA8C;AAQ9C;;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,IAAI,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAEvD,OAAO;YACL,SAAS,CAAC,IAAI;gBACZ,OAAO;oBACL,IAAI,EAAE,OAAO;oBACb,IAAI;iBACL,CAAC;YACJ,CAAC;YACD,cAAc,EAAE,OAAO,CAAC,SAAS;SAClC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAfD,wCAeC"}
@@ -1,3 +1,3 @@
1
- import type { PiletApi, ExtensionSlotProps } from 'piral-core';
1
+ import type { ExtensionSlotProps } from 'piral-core';
2
2
  import type { Component } from 'solid-js';
3
- export declare function createExtension(api: PiletApi, rootName?: string): Component<ExtensionSlotProps>;
3
+ export declare function createExtension(rootName: string): Component<ExtensionSlotProps>;
package/lib/extension.js CHANGED
@@ -1,10 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createExtension = void 0;
4
- function createExtension(api, rootName = 'slot') {
4
+ const solid_js_1 = require("solid-js");
5
+ function createExtension(rootName) {
5
6
  return (props) => {
6
7
  const element = document.createElement(rootName);
7
- setTimeout(() => api.renderHtmlExtension(element, props), 0);
8
+ setTimeout(() => {
9
+ element.dispatchEvent(new CustomEvent('render-html', {
10
+ bubbles: true,
11
+ detail: {
12
+ target: element,
13
+ props,
14
+ },
15
+ }));
16
+ }, 0);
17
+ (0, solid_js_1.createEffect)(() => {
18
+ element.dispatchEvent(new CustomEvent('extension-props-changed', {
19
+ detail: {
20
+ name: props.name,
21
+ empty: props.empty,
22
+ params: props.params,
23
+ render: props.render,
24
+ },
25
+ }));
26
+ });
8
27
  return element;
9
28
  };
10
29
  }
@@ -1 +1 @@
1
- {"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":";;;AAGA,SAAgB,eAAe,CAAC,GAAa,EAAE,QAAQ,GAAG,MAAM;IAC9D,OAAO,CAAC,KAAK,EAAE,EAAE;QACf,MAAM,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QACjD,UAAU,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;QAC7D,OAAO,OAAc,CAAC;IACxB,CAAC,CAAC;AACJ,CAAC;AAND,0CAMC"}
1
+ {"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":";;;AAEA,uCAAwC;AAExC,SAAgB,eAAe,CAAC,QAAgB;IAC9C,OAAO,CAAC,KAAK,EAAE,EAAE;QACf,MAAM,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QACjD,UAAU,CAAC,GAAG,EAAE;YACd,OAAO,CAAC,aAAa,CACnB,IAAI,WAAW,CAAC,aAAa,EAAE;gBAC7B,OAAO,EAAE,IAAI;gBACb,MAAM,EAAE;oBACN,MAAM,EAAE,OAAO;oBACf,KAAK;iBACN;aACF,CAAC,CACH,CAAC;QACJ,CAAC,EAAE,CAAC,CAAC,CAAC;QAEN,IAAA,uBAAY,EAAC,GAAG,EAAE;YAChB,OAAO,CAAC,aAAa,CACnB,IAAI,WAAW,CAAC,yBAAyB,EAAE;gBACzC,MAAM,EAAE;oBACN,IAAI,EAAE,KAAK,CAAC,IAAI;oBAChB,KAAK,EAAE,KAAK,CAAC,KAAK;oBAClB,MAAM,EAAE,KAAK,CAAC,MAAM;oBACpB,MAAM,EAAE,KAAK,CAAC,MAAM;iBACrB;aACF,CAAC,CACH,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,OAAO,OAAc,CAAC;IACxB,CAAC,CAAC;AACJ,CAAC;AA9BD,0CA8BC"}
package/lib/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { ForeignComponent, ExtensionSlotProps } from 'piral-core';
2
- import { Component } from 'solid-js';
1
+ import type { ForeignComponent, ExtensionSlotProps } from 'piral-core';
2
+ import type { Component } from 'solid-js';
3
3
  declare module 'piral-core/lib/types/custom' {
4
4
  interface PiletCustomApi extends PiletSolidApi {
5
5
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "piral-solid",
3
- "version": "1.0.0-pre.2107",
3
+ "version": "1.0.1-beta.5640",
4
4
  "description": "Plugin for integrating Solid components in Piral.",
5
5
  "keywords": [
6
6
  "piral",
@@ -19,13 +19,32 @@
19
19
  "module": "esm/index.js",
20
20
  "main": "lib/index.js",
21
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
+ },
22
42
  "sideEffects": false,
23
43
  "files": [
24
44
  "esm",
25
45
  "lib",
26
46
  "src",
27
47
  "convert.d.ts",
28
- "convert.ts",
29
48
  "convert.js"
30
49
  ],
31
50
  "repository": {
@@ -36,20 +55,17 @@
36
55
  "url": "https://github.com/smapiot/piral/issues"
37
56
  },
38
57
  "scripts": {
58
+ "cleanup": "rimraf esm lib convert.d.ts convert.js",
39
59
  "build": "yarn build:commonjs && yarn build:esnext && yarn build:convert",
40
- "build:convert": "tsc convert.ts --skipLibCheck --declaration",
60
+ "build:convert": "tsc convert.ts --skipLibCheck --declaration --module esnext",
41
61
  "build:commonjs": "tsc --project tsconfig.json --outDir lib --module commonjs",
42
62
  "build:esnext": "tsc --project tsconfig.json --outDir esm --module esnext",
43
63
  "typedoc": "typedoc --json ../../../docs/types/piral-solid.json src --exclude \"src/**/*.test.*\"",
44
64
  "test": "echo \"Error: run tests from root\" && exit 1"
45
65
  },
46
66
  "devDependencies": {
47
- "piral-core": "^1.0.0-pre.2107",
48
- "solid-js": "^0.18.7"
49
- },
50
- "peerDependencies": {
51
- "piral-core": "1.x",
52
- "solid-js": "^0.18.0"
67
+ "piral-core": "1.0.1-beta.5640",
68
+ "solid-js": "^1.7.3"
53
69
  },
54
- "gitHead": "4ffef402378ffdeb01acb3794f334973896085e2"
70
+ "gitHead": "fa0a72b28fd0a20afec7ef491ec19e93c090fc72"
55
71
  }
package/src/converter.ts CHANGED
@@ -1,18 +1,40 @@
1
- import { ForeignComponent, BaseComponentProps } from 'piral-core';
2
- import { Component } from 'solid-js';
3
- import { render, createComponent } from 'solid-js/dom';
1
+ import type { ForeignComponent, BaseComponentProps } from 'piral-core';
2
+ import { Component, onCleanup } from 'solid-js';
3
+ import { render, createComponent } from 'solid-js/web';
4
+ import { createExtension } from './extension';
4
5
 
5
- export function createConverter() {
6
- const convert = <TProps extends BaseComponentProps>(root: Component<TProps>): ForeignComponent<TProps> => {
7
- return {
8
- mount(parent, data, context) {
9
- render(() => createComponent(root, { context, ...data }), parent);
10
- },
11
- unmount(el) {
12
- render(() => undefined, el);
13
- el.innerHTML = '';
14
- },
15
- };
16
- };
6
+ export interface SolidConverterOptions {
7
+ /**
8
+ * Defines the name of the root element.
9
+ * @default piral-slot
10
+ */
11
+ rootName?: string;
12
+ }
13
+
14
+ export function createConverter(config: SolidConverterOptions = {}) {
15
+ const { rootName = 'piral-slot' } = config;
16
+ const Extension = createExtension(rootName);
17
+ const convert = <TProps extends BaseComponentProps>(root: Component<TProps>): ForeignComponent<TProps> => ({
18
+ mount(el, props, context, locals) {
19
+ locals.update = (props, context) => {
20
+ locals.destroy = render(() => {
21
+ onCleanup(() => {
22
+ el.innerHTML = '';
23
+ });
24
+ return createComponent(root, { context, ...props });
25
+ }, el);
26
+ };
27
+
28
+ locals.update(props, context);
29
+ },
30
+ update(el, props, context, locals) {
31
+ locals.destroy();
32
+ locals.update(props, context);
33
+ },
34
+ unmount(el, locals) {
35
+ locals.destroy();
36
+ },
37
+ });
38
+ convert.Extension = Extension;
17
39
  return convert;
18
40
  }
package/src/create.ts CHANGED
@@ -1,37 +1,28 @@
1
1
  import type { PiralPlugin } from 'piral-core';
2
2
  import { createConverter } from './converter';
3
- import { createExtension } from './extension';
4
3
  import type { PiletSolidApi } from './types';
5
4
 
6
5
  /**
7
6
  * Available configuration options for the Solid plugin.
8
7
  */
9
- export interface SolidConfig {
10
- /**
11
- * Defines the name of the root element.
12
- * @default slot
13
- */
14
- rootName?: string;
15
- }
8
+ export interface SolidConfig {}
16
9
 
17
10
  /**
18
11
  * Creates new Pilet API extensions for integration of Solid.
19
12
  */
20
13
  export function createSolidApi(config: SolidConfig = {}): PiralPlugin<PiletSolidApi> {
21
- const { rootName } = config;
22
-
23
14
  return (context) => {
24
- const convert = createConverter();
15
+ const convert = createConverter(config);
25
16
  context.converters.solid = ({ root }) => convert(root);
26
17
 
27
- return (api) => ({
18
+ return {
28
19
  fromSolid(root) {
29
20
  return {
30
21
  type: 'solid',
31
22
  root,
32
23
  };
33
24
  },
34
- SolidExtension: createExtension(api, rootName),
35
- });
25
+ SolidExtension: convert.Extension,
26
+ };
36
27
  };
37
28
  }
package/src/extension.ts CHANGED
@@ -1,10 +1,35 @@
1
- import type { PiletApi, ExtensionSlotProps } from 'piral-core';
1
+ import type { ExtensionSlotProps } from 'piral-core';
2
2
  import type { Component } from 'solid-js';
3
+ import { createEffect } from 'solid-js';
3
4
 
4
- export function createExtension(api: PiletApi, rootName = 'slot'): Component<ExtensionSlotProps> {
5
+ export function createExtension(rootName: string): Component<ExtensionSlotProps> {
5
6
  return (props) => {
6
7
  const element = document.createElement(rootName);
7
- setTimeout(() => api.renderHtmlExtension(element, props), 0);
8
+ setTimeout(() => {
9
+ element.dispatchEvent(
10
+ new CustomEvent('render-html', {
11
+ bubbles: true,
12
+ detail: {
13
+ target: element,
14
+ props,
15
+ },
16
+ }),
17
+ );
18
+ }, 0);
19
+
20
+ createEffect(() => {
21
+ element.dispatchEvent(
22
+ new CustomEvent('extension-props-changed', {
23
+ detail: {
24
+ name: props.name,
25
+ empty: props.empty,
26
+ params: props.params,
27
+ render: props.render,
28
+ },
29
+ }),
30
+ );
31
+ });
32
+
8
33
  return element as any;
9
34
  };
10
35
  }
package/src/types.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { ForeignComponent, ExtensionSlotProps } from 'piral-core';
2
- import { Component } from 'solid-js';
1
+ import type { ForeignComponent, ExtensionSlotProps } from 'piral-core';
2
+ import type { Component } from 'solid-js';
3
3
 
4
4
  declare module 'piral-core/lib/types/custom' {
5
5
  interface PiletCustomApi extends PiletSolidApi {}
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 SolidConverter {
8
- (...params: Parameters<typeof convert>): HtmlComponent<any>;
9
- }
10
-
11
- export const fromSolid: SolidConverter = (root) => ({
12
- type: 'html',
13
- component: convert(root),
14
- });
15
-
16
- export const createSolidExtension = createExtension;