piral-svelte 1.0.0-pre.2137 → 1.0.1-beta.5640
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +66 -5
- package/convert.d.ts +16 -7
- package/convert.js +16 -11
- package/esm/converter.d.ts +13 -3
- package/esm/converter.js +23 -27
- package/esm/converter.js.map +1 -1
- package/esm/create.d.ts +2 -6
- package/esm/create.js +8 -15
- package/esm/create.js.map +1 -1
- package/esm/extension.d.ts +1 -1
- package/esm/extension.js +7 -24
- package/esm/extension.js.map +1 -1
- package/esm/types.d.ts +1 -1
- package/extend-webpack.js +72 -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 +9 -16
- 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/types.d.ts +1 -1
- package/package.json +30 -9
- package/src/converter.ts +41 -37
- 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 Svelte](https://piral.io) · [](https://github.com/smapiot/piral/blob/
|
|
3
|
+
# [Piral Svelte](https://piral.io) · [](https://github.com/smapiot/piral/blob/main/LICENSE) [](https://www.npmjs.com/package/piral-svelte) [](https://jestjs.io) [](https://gitter.im/piral-io/community)
|
|
4
4
|
|
|
5
|
-
This is a plugin that
|
|
5
|
+
This is a plugin that has no peer dependencies. What `piral-svelte` 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 Svelte converter for any component registration, as well as a `fromSvelte` shortcut together with a `svelte-extension` web component.
|
|
8
8
|
|
|
@@ -43,7 +43,7 @@ Alternatively, if `piral-svelte` has not been added to the Piral instance you ca
|
|
|
43
43
|
|
|
44
44
|
```ts
|
|
45
45
|
import { PiletApi } from '<name-of-piral-instance>';
|
|
46
|
-
import { fromSvelte } from 'piral-svelte';
|
|
46
|
+
import { fromSvelte } from 'piral-svelte/convert';
|
|
47
47
|
import SveltePage from './Page.svelte';
|
|
48
48
|
|
|
49
49
|
export function setup(piral: PiletApi) {
|
|
@@ -51,6 +51,67 @@ export function setup(piral: PiletApi) {
|
|
|
51
51
|
}
|
|
52
52
|
```
|
|
53
53
|
|
|
54
|
+
How you built your Svelte-pilet is up to you. If you use Webpack then the bundler options such as `piral-cli-webpack` or `piral-cli-webpack5` can be leveraged. In these cases you'd need to install the `svelte-loader` package and create a custom *webpack.config.js*:
|
|
55
|
+
|
|
56
|
+
```sh
|
|
57
|
+
npm i svelte-loader --save-dev
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
The Webpack configuration can be rather simplistic, as shown on the [svelte-loader readme](https://github.com/sveltejs/svelte-loader). In many cases you can use the convenience `extend-webpack` module.
|
|
61
|
+
|
|
62
|
+
This is how your *webpack.config.js* can look like with the convenience module:
|
|
63
|
+
|
|
64
|
+
```js
|
|
65
|
+
const extendWebpack = require('piral-svelte/extend-webpack');
|
|
66
|
+
|
|
67
|
+
module.exports = extendWebpack({});
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
For using `piral-svelte/extend-webpack` you must have installed:
|
|
71
|
+
|
|
72
|
+
- `svelte-loader`
|
|
73
|
+
- `webpack`, e.g., via `piral-cli-webpack5`
|
|
74
|
+
|
|
75
|
+
You can do that via:
|
|
76
|
+
|
|
77
|
+
```sh
|
|
78
|
+
npm i svelte-loader piral-cli-webpack5 --save-dev
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
The available options for `piral-svelte/extend-webpack` are the same as for the options of the `svelte-loader`, e.g.:
|
|
82
|
+
|
|
83
|
+
```js
|
|
84
|
+
const extendWebpack = require('piral-svelte/extend-webpack');
|
|
85
|
+
|
|
86
|
+
module.exports = extendWebpack({
|
|
87
|
+
emitCss: false,
|
|
88
|
+
compilerOptions: {
|
|
89
|
+
css: false,
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
You can also customize the options even more:
|
|
95
|
+
|
|
96
|
+
```js
|
|
97
|
+
const extendWebpack = require('piral-svelte/extend-webpack');
|
|
98
|
+
|
|
99
|
+
const applySvelte = extendWebpack({
|
|
100
|
+
emitCss: false,
|
|
101
|
+
compilerOptions: {
|
|
102
|
+
css: false,
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
module.exports = config => {
|
|
107
|
+
config = applySvelte(config);
|
|
108
|
+
|
|
109
|
+
// your changes to config
|
|
110
|
+
|
|
111
|
+
return config;
|
|
112
|
+
};
|
|
113
|
+
```
|
|
114
|
+
|
|
54
115
|
:::
|
|
55
116
|
|
|
56
117
|
::: summary: For Piral instance developers
|
|
@@ -113,7 +174,7 @@ For Svelte to work the Svelte compiler and the associated Parcel plugin need to
|
|
|
113
174
|
npm i svelte parcel-plugin-svelte --save-dev
|
|
114
175
|
```
|
|
115
176
|
|
|
116
|
-
Furthermore, since Svelte distributes its source code as ES6 we need to change the
|
|
177
|
+
Furthermore, since Svelte distributes its source code as ES6 we need to change the `browserslist` setting in the *package.json* of the pilet:
|
|
117
178
|
|
|
118
179
|
```json
|
|
119
180
|
{
|
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 SvelteConverter {
|
|
5
|
-
(...params: Parameters<typeof
|
|
11
|
+
(...params: Parameters<ReturnType<typeof createConverter>>): HtmlComponent<any>;
|
|
6
12
|
}
|
|
7
|
-
export declare
|
|
8
|
-
|
|
9
|
-
|
|
13
|
+
export declare function createSvelteConverter(...params: Parameters<typeof createConverter>): {
|
|
14
|
+
from: SvelteConverter;
|
|
15
|
+
Extension: string;
|
|
16
|
+
};
|
|
17
|
+
declare const fromSvelte: SvelteConverter, SvelteExtension: string;
|
|
18
|
+
export { fromSvelte, SvelteExtension };
|
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 createSvelteConverter() {
|
|
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 (Component, captured) { return ({
|
|
10
|
+
type: 'html',
|
|
11
|
+
component: convert(Component, captured),
|
|
12
|
+
}); };
|
|
13
|
+
return { from: from, Extension: Extension };
|
|
14
|
+
}
|
|
15
|
+
var _a = createSvelteConverter(), fromSvelte = _a.from, SvelteExtension = _a.Extension;
|
|
16
|
+
export { fromSvelte, SvelteExtension };
|
package/esm/converter.d.ts
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
-
import { ForeignComponent, BaseComponentProps } from 'piral-core';
|
|
2
|
-
import { SvelteModule } from './types';
|
|
3
|
-
export
|
|
1
|
+
import type { ForeignComponent, BaseComponentProps } from 'piral-core';
|
|
2
|
+
import type { SvelteModule } from './types';
|
|
3
|
+
export interface SvelteConverterOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Defines the name of the extension component.
|
|
6
|
+
* @default svelte-extension
|
|
7
|
+
*/
|
|
8
|
+
selector?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function createConverter(config?: SvelteConverterOptions): {
|
|
11
|
+
<TProps extends BaseComponentProps>(Component: SvelteModule<TProps>, captured?: Record<string, any>): ForeignComponent<TProps>;
|
|
12
|
+
Extension: string;
|
|
13
|
+
};
|
package/esm/converter.js
CHANGED
|
@@ -1,30 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export function createConverter() {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
el.innerHTML = '';
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
};
|
|
1
|
+
import { createExtension } from './extension';
|
|
2
|
+
export function createConverter(config = {}) {
|
|
3
|
+
const { selector = 'svelte-extension' } = config;
|
|
4
|
+
const Extension = createExtension(selector);
|
|
5
|
+
const convert = (Component, captured) => ({
|
|
6
|
+
mount(parent, data, ctx, locals) {
|
|
7
|
+
locals.instance = new Component({
|
|
8
|
+
target: parent,
|
|
9
|
+
props: Object.assign(Object.assign(Object.assign({}, captured), ctx), data),
|
|
10
|
+
});
|
|
11
|
+
},
|
|
12
|
+
update(el, data, ctx, locals) {
|
|
13
|
+
Object.keys(data).forEach((key) => {
|
|
14
|
+
locals.instance[key] = data[key];
|
|
15
|
+
});
|
|
16
|
+
},
|
|
17
|
+
unmount(el, locals) {
|
|
18
|
+
locals.instance.$destroy();
|
|
19
|
+
locals.instance = undefined;
|
|
20
|
+
el.innerHTML = '';
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
convert.Extension = Extension;
|
|
28
24
|
return convert;
|
|
29
25
|
}
|
|
30
26
|
//# sourceMappingURL=converter.js.map
|
package/esm/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,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAe9C,MAAM,UAAU,eAAe,CAAC,SAAiC,EAAE;IACjE,MAAM,EAAE,QAAQ,GAAG,kBAAkB,EAAE,GAAG,MAAM,CAAC;IACjD,MAAM,SAAS,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC;IAC5C,MAAM,OAAO,GAAG,CACd,SAA+B,EAC/B,QAA8B,EACJ,EAAE,CAAC,CAAC;QAC9B,KAAK,CAAC,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,MAAmB;YAC1C,MAAM,CAAC,QAAQ,GAAG,IAAI,SAAS,CAAC;gBAC9B,MAAM,EAAE,MAAM;gBACd,KAAK,gDACA,QAAQ,GACR,GAAG,GACH,IAAI,CACR;aACF,CAAC,CAAC;QACL,CAAC;QACD,MAAM,CAAC,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,MAAmB;YACvC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;gBAChC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;YACnC,CAAC,CAAC,CAAC;QACL,CAAC;QACD,OAAO,CAAC,EAAE,EAAE,MAAmB;YAC7B,MAAM,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;YAC3B,MAAM,CAAC,QAAQ,GAAG,SAAS,CAAC;YAC5B,EAAE,CAAC,SAAS,GAAG,EAAE,CAAC;QACpB,CAAC;KACF,CAAC,CAAC;IACH,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;IAC9B,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/esm/create.d.ts
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import type { PiralPlugin } from 'piral-core';
|
|
2
|
+
import { SvelteConverterOptions } from './converter';
|
|
2
3
|
import type { PiletSvelteApi } from './types';
|
|
3
4
|
/**
|
|
4
5
|
* Available configuration options for the Svelte plugin.
|
|
5
6
|
*/
|
|
6
|
-
export interface SvelteConfig {
|
|
7
|
-
/**
|
|
8
|
-
* Defines the name of the extension component.
|
|
9
|
-
* @default svelte-extension
|
|
10
|
-
*/
|
|
11
|
-
selector?: string;
|
|
7
|
+
export interface SvelteConfig extends SvelteConverterOptions {
|
|
12
8
|
}
|
|
13
9
|
/**
|
|
14
10
|
* Creates new Pilet API extensions for integration of Svelte.
|
package/esm/create.js
CHANGED
|
@@ -1,27 +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 Svelte.
|
|
5
4
|
*/
|
|
6
|
-
export function createSvelteApi(config) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var convert = createConverter();
|
|
11
|
-
context.converters.svelte = function (_a) {
|
|
12
|
-
var Component = _a.Component, captured = _a.captured;
|
|
13
|
-
return convert(Component, captured);
|
|
14
|
-
};
|
|
15
|
-
createExtension(selector);
|
|
5
|
+
export function createSvelteApi(config = {}) {
|
|
6
|
+
return (context) => {
|
|
7
|
+
const convert = createConverter(config);
|
|
8
|
+
context.converters.svelte = ({ Component, captured }) => convert(Component, captured);
|
|
16
9
|
return {
|
|
17
|
-
fromSvelte
|
|
10
|
+
fromSvelte(Component, captured) {
|
|
18
11
|
return {
|
|
19
12
|
type: 'svelte',
|
|
20
|
-
Component
|
|
21
|
-
captured
|
|
13
|
+
Component,
|
|
14
|
+
captured,
|
|
22
15
|
};
|
|
23
16
|
},
|
|
24
|
-
SvelteExtension:
|
|
17
|
+
SvelteExtension: convert.Extension,
|
|
25
18
|
};
|
|
26
19
|
};
|
|
27
20
|
}
|
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,
|
|
1
|
+
{"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAA0B,MAAM,aAAa,CAAC;AAQtE;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,SAAuB,EAAE;IACvD,OAAO,CAAC,OAAO,EAAE,EAAE;QACjB,MAAM,OAAO,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;QACxC,OAAO,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QAEtF,OAAO;YACL,UAAU,CAAC,SAAS,EAAE,QAAQ;gBAC5B,OAAO;oBACL,IAAI,EAAE,QAAQ;oBACd,SAAS;oBACT,QAAQ;iBACT,CAAC;YACJ,CAAC;YACD,eAAe,EAAE,OAAO,CAAC,SAAS;SACnC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
|
package/esm/extension.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function createExtension(selector
|
|
1
|
+
export declare function createExtension(selector: string): string;
|
package/esm/extension.js
CHANGED
|
@@ -1,28 +1,11 @@
|
|
|
1
|
-
import { __extends } from "tslib";
|
|
2
1
|
export function createExtension(selector) {
|
|
3
|
-
|
|
4
|
-
if ('customElements' in window) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
SvelteExtension.prototype.connectedCallback = function () {
|
|
11
|
-
if (this.isConnected) {
|
|
12
|
-
this.dispatchEvent(new CustomEvent('render-html', {
|
|
13
|
-
bubbles: true,
|
|
14
|
-
detail: {
|
|
15
|
-
target: this,
|
|
16
|
-
props: {
|
|
17
|
-
name: this.getAttribute('name'),
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
}));
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
return SvelteExtension;
|
|
24
|
-
}(HTMLElement));
|
|
25
|
-
customElements.define(selector, SvelteExtension);
|
|
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);
|
|
26
8
|
}
|
|
9
|
+
return selector || defaultExtensionSelector;
|
|
27
10
|
}
|
|
28
11
|
//# sourceMappingURL=extension.js.map
|
package/esm/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,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/types.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export interface SvelteOptions<TProps> {
|
|
|
10
10
|
target: Element;
|
|
11
11
|
props: TProps;
|
|
12
12
|
}
|
|
13
|
-
export
|
|
13
|
+
export type SvelteComponentInstance<TProps> = TProps & {
|
|
14
14
|
$destroy(): void;
|
|
15
15
|
};
|
|
16
16
|
export interface SvelteModule<TProps> {
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
const { resolve } = require('path');
|
|
2
|
+
|
|
3
|
+
const svelteLoader = require.resolve('svelte-loader');
|
|
4
|
+
|
|
5
|
+
module.exports =
|
|
6
|
+
(options = {}) =>
|
|
7
|
+
(config) => {
|
|
8
|
+
if (!config.resolve.alias) {
|
|
9
|
+
config.resolve.alias = {};
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (!config.resolve.extensions) {
|
|
13
|
+
config.resolve.extensions = ['.mjs', '.js'];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (!config.resolve.mainFields) {
|
|
17
|
+
config.resolve.mainFields = ['browser', 'module', 'main'];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (!config.resolve.conditionNames) {
|
|
21
|
+
config.resolve.conditionNames = ['import', 'module', 'require', 'node'];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
config.resolve.alias.svelte = resolve('node_modules', 'svelte');
|
|
25
|
+
config.resolve.extensions.push('.svelte');
|
|
26
|
+
config.resolve.mainFields.unshift('svelte');
|
|
27
|
+
config.resolve.conditionNames.push('svelte');
|
|
28
|
+
|
|
29
|
+
function findRule(tester, changer) {
|
|
30
|
+
config.module.rules.forEach((rule) => {
|
|
31
|
+
if (rule.oneOf) {
|
|
32
|
+
rule.oneOf.forEach((r) => {
|
|
33
|
+
if (r.test && tester(r)) {
|
|
34
|
+
changer(r, rule.oneOf);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
} else if (rule.test && tester(rule)) {
|
|
38
|
+
changer(rule, config.module.rules);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
findRule(
|
|
44
|
+
(m) => m.test && m.test.toString() === /\.tsx?$/i.toString(),
|
|
45
|
+
(m, all) => {
|
|
46
|
+
const ruleIndex = all.indexOf(m);
|
|
47
|
+
|
|
48
|
+
all.splice(
|
|
49
|
+
ruleIndex,
|
|
50
|
+
0,
|
|
51
|
+
{
|
|
52
|
+
test: /\.(html|svelte)$/,
|
|
53
|
+
use: {
|
|
54
|
+
loader: svelteLoader,
|
|
55
|
+
options: {
|
|
56
|
+
emitCss: true,
|
|
57
|
+
...options,
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
test: /node_modules\/svelte\/.*\.mjs$/,
|
|
63
|
+
resolve: {
|
|
64
|
+
fullySpecified: false,
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
);
|
|
68
|
+
},
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
return config;
|
|
72
|
+
};
|
package/lib/converter.d.ts
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
-
import { ForeignComponent, BaseComponentProps } from 'piral-core';
|
|
2
|
-
import { SvelteModule } from './types';
|
|
3
|
-
export
|
|
1
|
+
import type { ForeignComponent, BaseComponentProps } from 'piral-core';
|
|
2
|
+
import type { SvelteModule } from './types';
|
|
3
|
+
export interface SvelteConverterOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Defines the name of the extension component.
|
|
6
|
+
* @default svelte-extension
|
|
7
|
+
*/
|
|
8
|
+
selector?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function createConverter(config?: SvelteConverterOptions): {
|
|
11
|
+
<TProps extends BaseComponentProps>(Component: SvelteModule<TProps>, captured?: Record<string, 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
|
-
el.innerHTML = '';
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
};
|
|
4
|
+
const extension_1 = require("./extension");
|
|
5
|
+
function createConverter(config = {}) {
|
|
6
|
+
const { selector = 'svelte-extension' } = config;
|
|
7
|
+
const Extension = (0, extension_1.createExtension)(selector);
|
|
8
|
+
const convert = (Component, captured) => ({
|
|
9
|
+
mount(parent, data, ctx, locals) {
|
|
10
|
+
locals.instance = new Component({
|
|
11
|
+
target: parent,
|
|
12
|
+
props: Object.assign(Object.assign(Object.assign({}, captured), ctx), data),
|
|
13
|
+
});
|
|
14
|
+
},
|
|
15
|
+
update(el, data, ctx, locals) {
|
|
16
|
+
Object.keys(data).forEach((key) => {
|
|
17
|
+
locals.instance[key] = data[key];
|
|
18
|
+
});
|
|
19
|
+
},
|
|
20
|
+
unmount(el, locals) {
|
|
21
|
+
locals.instance.$destroy();
|
|
22
|
+
locals.instance = undefined;
|
|
23
|
+
el.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,SAAiC,EAAE;IACjE,MAAM,EAAE,QAAQ,GAAG,kBAAkB,EAAE,GAAG,MAAM,CAAC;IACjD,MAAM,SAAS,GAAG,IAAA,2BAAe,EAAC,QAAQ,CAAC,CAAC;IAC5C,MAAM,OAAO,GAAG,CACd,SAA+B,EAC/B,QAA8B,EACJ,EAAE,CAAC,CAAC;QAC9B,KAAK,CAAC,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,MAAmB;YAC1C,MAAM,CAAC,QAAQ,GAAG,IAAI,SAAS,CAAC;gBAC9B,MAAM,EAAE,MAAM;gBACd,KAAK,gDACA,QAAQ,GACR,GAAG,GACH,IAAI,CACR;aACF,CAAC,CAAC;QACL,CAAC;QACD,MAAM,CAAC,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,MAAmB;YACvC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;gBAChC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;YACnC,CAAC,CAAC,CAAC;QACL,CAAC;QACD,OAAO,CAAC,EAAE,EAAE,MAAmB;YAC7B,MAAM,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;YAC3B,MAAM,CAAC,QAAQ,GAAG,SAAS,CAAC;YAC5B,EAAE,CAAC,SAAS,GAAG,EAAE,CAAC;QACpB,CAAC;KACF,CAAC,CAAC;IACH,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;IAC9B,OAAO,OAAO,CAAC;AACjB,CAAC;AA9BD,0CA8BC"}
|
package/lib/create.d.ts
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import type { PiralPlugin } from 'piral-core';
|
|
2
|
+
import { SvelteConverterOptions } from './converter';
|
|
2
3
|
import type { PiletSvelteApi } from './types';
|
|
3
4
|
/**
|
|
4
5
|
* Available configuration options for the Svelte plugin.
|
|
5
6
|
*/
|
|
6
|
-
export interface SvelteConfig {
|
|
7
|
-
/**
|
|
8
|
-
* Defines the name of the extension component.
|
|
9
|
-
* @default svelte-extension
|
|
10
|
-
*/
|
|
11
|
-
selector?: string;
|
|
7
|
+
export interface SvelteConfig extends SvelteConverterOptions {
|
|
12
8
|
}
|
|
13
9
|
/**
|
|
14
10
|
* Creates new Pilet API extensions for integration of Svelte.
|
package/lib/create.js
CHANGED
|
@@ -1,30 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createSvelteApi = void 0;
|
|
4
|
-
|
|
5
|
-
var extension_1 = require("./extension");
|
|
4
|
+
const converter_1 = require("./converter");
|
|
6
5
|
/**
|
|
7
6
|
* Creates new Pilet API extensions for integration of Svelte.
|
|
8
7
|
*/
|
|
9
|
-
function createSvelteApi(config) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var convert = converter_1.createConverter();
|
|
14
|
-
context.converters.svelte = function (_a) {
|
|
15
|
-
var Component = _a.Component, captured = _a.captured;
|
|
16
|
-
return convert(Component, captured);
|
|
17
|
-
};
|
|
18
|
-
extension_1.createExtension(selector);
|
|
8
|
+
function createSvelteApi(config = {}) {
|
|
9
|
+
return (context) => {
|
|
10
|
+
const convert = (0, converter_1.createConverter)(config);
|
|
11
|
+
context.converters.svelte = ({ Component, captured }) => convert(Component, captured);
|
|
19
12
|
return {
|
|
20
|
-
fromSvelte
|
|
13
|
+
fromSvelte(Component, captured) {
|
|
21
14
|
return {
|
|
22
15
|
type: 'svelte',
|
|
23
|
-
Component
|
|
24
|
-
captured
|
|
16
|
+
Component,
|
|
17
|
+
captured,
|
|
25
18
|
};
|
|
26
19
|
},
|
|
27
|
-
SvelteExtension:
|
|
20
|
+
SvelteExtension: convert.Extension,
|
|
28
21
|
};
|
|
29
22
|
};
|
|
30
23
|
}
|
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,2CAAsE;AAQtE;;GAEG;AACH,SAAgB,eAAe,CAAC,SAAuB,EAAE;IACvD,OAAO,CAAC,OAAO,EAAE,EAAE;QACjB,MAAM,OAAO,GAAG,IAAA,2BAAe,EAAC,MAAM,CAAC,CAAC;QACxC,OAAO,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QAEtF,OAAO;YACL,UAAU,CAAC,SAAS,EAAE,QAAQ;gBAC5B,OAAO;oBACL,IAAI,EAAE,QAAQ;oBACd,SAAS;oBACT,QAAQ;iBACT,CAAC;YACJ,CAAC;YACD,eAAe,EAAE,OAAO,CAAC,SAAS;SACnC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAhBD,0CAgBC"}
|
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
|
-
SvelteExtension.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 SvelteExtension;
|
|
27
|
-
}(HTMLElement));
|
|
28
|
-
customElements.define(selector, SvelteExtension);
|
|
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/types.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export interface SvelteOptions<TProps> {
|
|
|
10
10
|
target: Element;
|
|
11
11
|
props: TProps;
|
|
12
12
|
}
|
|
13
|
-
export
|
|
13
|
+
export type SvelteComponentInstance<TProps> = TProps & {
|
|
14
14
|
$destroy(): void;
|
|
15
15
|
};
|
|
16
16
|
export interface SvelteModule<TProps> {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "piral-svelte",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1-beta.5640",
|
|
4
4
|
"description": "Plugin for integrating Svelte components in Piral.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"piral",
|
|
@@ -19,14 +19,37 @@
|
|
|
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
|
+
"./extend-webpack": {
|
|
31
|
+
"require": "./extend-webpack.js"
|
|
32
|
+
},
|
|
33
|
+
"./esm/*": {
|
|
34
|
+
"import": "./esm/*"
|
|
35
|
+
},
|
|
36
|
+
"./lib/*": {
|
|
37
|
+
"require": "./lib/*"
|
|
38
|
+
},
|
|
39
|
+
"./_/*": {
|
|
40
|
+
"import": "./esm/*.js",
|
|
41
|
+
"require": "./lib/*.js"
|
|
42
|
+
},
|
|
43
|
+
"./package.json": "./package.json"
|
|
44
|
+
},
|
|
22
45
|
"sideEffects": false,
|
|
23
46
|
"files": [
|
|
24
47
|
"esm",
|
|
25
48
|
"lib",
|
|
26
49
|
"src",
|
|
27
50
|
"convert.d.ts",
|
|
28
|
-
"convert.
|
|
29
|
-
"
|
|
51
|
+
"convert.js",
|
|
52
|
+
"extend-webpack.js"
|
|
30
53
|
],
|
|
31
54
|
"repository": {
|
|
32
55
|
"type": "git",
|
|
@@ -36,18 +59,16 @@
|
|
|
36
59
|
"url": "https://github.com/smapiot/piral/issues"
|
|
37
60
|
},
|
|
38
61
|
"scripts": {
|
|
62
|
+
"cleanup": "rimraf esm lib convert.d.ts convert.js",
|
|
39
63
|
"build": "yarn build:commonjs && yarn build:esnext && yarn build:convert",
|
|
40
|
-
"build:convert": "tsc convert.ts --skipLibCheck --declaration",
|
|
64
|
+
"build:convert": "tsc convert.ts --skipLibCheck --declaration --module esnext",
|
|
41
65
|
"build:commonjs": "tsc --project tsconfig.json --outDir lib --module commonjs",
|
|
42
66
|
"build:esnext": "tsc --project tsconfig.json --outDir esm --module esnext",
|
|
43
67
|
"typedoc": "typedoc --json ../../../docs/types/piral-svelte.json src --exclude \"src/**/*.test.*\"",
|
|
44
68
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
45
69
|
},
|
|
46
70
|
"devDependencies": {
|
|
47
|
-
"piral-core": "
|
|
48
|
-
},
|
|
49
|
-
"peerDependencies": {
|
|
50
|
-
"piral-core": "1.x"
|
|
71
|
+
"piral-core": "1.0.1-beta.5640"
|
|
51
72
|
},
|
|
52
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "fa0a72b28fd0a20afec7ef491ec19e93c090fc72"
|
|
53
74
|
}
|
package/src/converter.ts
CHANGED
|
@@ -1,43 +1,47 @@
|
|
|
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 { SvelteComponentInstance, SvelteModule } from './types';
|
|
3
4
|
|
|
4
|
-
export
|
|
5
|
+
export interface SvelteConverterOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Defines the name of the extension component.
|
|
8
|
+
* @default svelte-extension
|
|
9
|
+
*/
|
|
10
|
+
selector?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface SvelteState {
|
|
14
|
+
instance: SvelteComponentInstance<any>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function createConverter(config: SvelteConverterOptions = {}) {
|
|
18
|
+
const { selector = 'svelte-extension' } = config;
|
|
19
|
+
const Extension = createExtension(selector);
|
|
5
20
|
const convert = <TProps extends BaseComponentProps>(
|
|
6
21
|
Component: SvelteModule<TProps>,
|
|
7
22
|
captured?: Record<string, any>,
|
|
8
|
-
): ForeignComponent<TProps> => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
instance =
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
Object.keys(data).forEach((key) => {
|
|
32
|
-
instance[key] = data[key];
|
|
33
|
-
});
|
|
34
|
-
},
|
|
35
|
-
unmount(el) {
|
|
36
|
-
instance.$destroy();
|
|
37
|
-
instance = undefined;
|
|
38
|
-
el.innerHTML = '';
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
};
|
|
23
|
+
): ForeignComponent<TProps> => ({
|
|
24
|
+
mount(parent, data, ctx, locals: SvelteState) {
|
|
25
|
+
locals.instance = new Component({
|
|
26
|
+
target: parent,
|
|
27
|
+
props: {
|
|
28
|
+
...captured,
|
|
29
|
+
...ctx,
|
|
30
|
+
...data,
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
update(el, data, ctx, locals: SvelteState) {
|
|
35
|
+
Object.keys(data).forEach((key) => {
|
|
36
|
+
locals.instance[key] = data[key];
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
unmount(el, locals: SvelteState) {
|
|
40
|
+
locals.instance.$destroy();
|
|
41
|
+
locals.instance = undefined;
|
|
42
|
+
el.innerHTML = '';
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
convert.Extension = Extension;
|
|
42
46
|
return convert;
|
|
43
47
|
}
|
package/src/create.ts
CHANGED
|
@@ -1,31 +1,20 @@
|
|
|
1
1
|
import type { PiralPlugin } from 'piral-core';
|
|
2
|
-
import { createConverter } from './converter';
|
|
3
|
-
import { createExtension } from './extension';
|
|
2
|
+
import { createConverter, SvelteConverterOptions } from './converter';
|
|
4
3
|
import type { PiletSvelteApi } from './types';
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* Available configuration options for the Svelte plugin.
|
|
8
7
|
*/
|
|
9
|
-
export interface SvelteConfig {
|
|
10
|
-
/**
|
|
11
|
-
* Defines the name of the extension component.
|
|
12
|
-
* @default svelte-extension
|
|
13
|
-
*/
|
|
14
|
-
selector?: string;
|
|
15
|
-
}
|
|
8
|
+
export interface SvelteConfig extends SvelteConverterOptions {}
|
|
16
9
|
|
|
17
10
|
/**
|
|
18
11
|
* Creates new Pilet API extensions for integration of Svelte.
|
|
19
12
|
*/
|
|
20
13
|
export function createSvelteApi(config: SvelteConfig = {}): PiralPlugin<PiletSvelteApi> {
|
|
21
|
-
const { selector } = config;
|
|
22
|
-
|
|
23
14
|
return (context) => {
|
|
24
|
-
const convert = createConverter();
|
|
15
|
+
const convert = createConverter(config);
|
|
25
16
|
context.converters.svelte = ({ Component, captured }) => convert(Component, captured);
|
|
26
17
|
|
|
27
|
-
createExtension(selector);
|
|
28
|
-
|
|
29
18
|
return {
|
|
30
19
|
fromSvelte(Component, captured) {
|
|
31
20
|
return {
|
|
@@ -34,7 +23,7 @@ export function createSvelteApi(config: SvelteConfig = {}): PiralPlugin<PiletSve
|
|
|
34
23
|
captured,
|
|
35
24
|
};
|
|
36
25
|
},
|
|
37
|
-
SvelteExtension:
|
|
26
|
+
SvelteExtension: convert.Extension,
|
|
38
27
|
};
|
|
39
28
|
};
|
|
40
29
|
}
|
package/src/extension.ts
CHANGED
|
@@ -1,23 +1,11 @@
|
|
|
1
|
-
export function createExtension(selector
|
|
2
|
-
|
|
3
|
-
class SvelteExtension 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 SvelteConverter {
|
|
8
|
-
(...params: Parameters<typeof convert>): HtmlComponent<any>;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export const fromSvelte: SvelteConverter = (Component, captured) => ({
|
|
12
|
-
type: 'html',
|
|
13
|
-
component: convert(Component, captured),
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
export const createSvelteExtension = createExtension;
|