@web-widget/react 0.0.1 → 0.0.3
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/dist/babel-plugin.d.ts +20 -0
- package/dist/babel-plugin.js +12 -7
- package/dist/react.client.d.ts +1 -1
- package/dist/react.client.js +26 -22
- package/dist/react.server.d.ts +1 -1
- package/dist/react.server.js +11 -17
- package/globals.d.ts +5 -3
- package/package.json +2 -2
package/dist/babel-plugin.d.ts
CHANGED
|
@@ -1,6 +1,26 @@
|
|
|
1
1
|
import { PluginPass } from '@babel/core';
|
|
2
2
|
import { Visitor } from '@babel/traverse';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* This adds web-widget source path to JSX tags.
|
|
6
|
+
*
|
|
7
|
+
* == JSX Literals ==
|
|
8
|
+
*
|
|
9
|
+
* import MyComponent from "../widgets/my-component.jsx";
|
|
10
|
+
* ...
|
|
11
|
+
* <MyComponent as="web-widget" title="My component" />
|
|
12
|
+
*
|
|
13
|
+
* becomes:
|
|
14
|
+
*
|
|
15
|
+
* import { defineWebWidget } from "@web-widget/react/web-widget";
|
|
16
|
+
* const MyComponent = defineWebWidget(() => import("../widgets/my-component.jsx"), "/routes/", {
|
|
17
|
+
* name: "MyComponent",
|
|
18
|
+
* recovering: true
|
|
19
|
+
* });
|
|
20
|
+
* ...
|
|
21
|
+
* <MyComponent title="My component" />
|
|
22
|
+
*/
|
|
23
|
+
|
|
4
24
|
type Config = {
|
|
5
25
|
base: string;
|
|
6
26
|
root: string;
|
package/dist/babel-plugin.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { addNamed } from "@babel/helper-module-imports";
|
|
3
3
|
import { declare } from "@babel/helper-plugin-utils";
|
|
4
4
|
import { types as t } from "@babel/core";
|
|
5
|
+
var TAGNAME = "web-widget";
|
|
5
6
|
function createWebWidgetVariableDeclaration(definer, component, source, base, options) {
|
|
6
7
|
const getType = (object) => Object.prototype.toString.call(object).slice(8, -1).toLocaleLowerCase();
|
|
7
8
|
return t.variableDeclaration("const", [
|
|
@@ -81,21 +82,25 @@ var babel_plugin_default = declare((api) => {
|
|
|
81
82
|
return;
|
|
82
83
|
}
|
|
83
84
|
const attributes = container.openingElement.attributes;
|
|
84
|
-
const
|
|
85
|
-
(attr) => t.isJSXAttribute(attr) &&
|
|
85
|
+
const widgetAttr = attributes.find(
|
|
86
|
+
(attr) => t.isJSXAttribute(attr) && attr.name.name === "as" && t.isStringLiteral(attr.value) && attr.value.value.startsWith(TAGNAME)
|
|
86
87
|
);
|
|
87
|
-
if (!
|
|
88
|
+
if (!widgetAttr) {
|
|
88
89
|
return;
|
|
89
90
|
}
|
|
91
|
+
const mode = t.isStringLiteral(widgetAttr.value) ? widgetAttr.value.value.replace(TAGNAME + ":", "") : "";
|
|
92
|
+
const loadingAttr = attributes.find(
|
|
93
|
+
(attr) => t.isJSXAttribute(attr) && attr.name.name === "loading"
|
|
94
|
+
) || void 0;
|
|
90
95
|
container.openingElement.attributes = container.openingElement.attributes.filter(
|
|
91
|
-
(attr) => attr !==
|
|
96
|
+
(attr) => attr !== widgetAttr && attr !== loadingAttr
|
|
92
97
|
);
|
|
93
98
|
const options = {
|
|
94
99
|
name: container.openingElement.name.name,
|
|
95
|
-
recovering: config.isServer &&
|
|
100
|
+
recovering: config.isServer && mode !== "client"
|
|
96
101
|
};
|
|
97
|
-
if (
|
|
98
|
-
options.loading =
|
|
102
|
+
if (loadingAttr && loadingAttr.value && t.isStringLiteral(loadingAttr.value)) {
|
|
103
|
+
options.loading = loadingAttr.value.value;
|
|
99
104
|
}
|
|
100
105
|
const importDeclaration = binding.path.parent;
|
|
101
106
|
const source = importDeclaration.source.value;
|
package/dist/react.client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _web_widget_schema from '@web-widget/schema';
|
|
2
|
-
export * from '@web-widget/schema/client';
|
|
2
|
+
export * from '@web-widget/schema/client-helpers';
|
|
3
3
|
export { C as ClientOptions, D as DefineWebWidgetOptions, W as WebWidget, b as WebWidgetClient, a as WebWidgetClientProps, c as WebWidgetProps, _ as __ENV__, W as default, e as defineClient, f as defineClientOnly, d as defineWebWidget, r as renderServerWidget } from './web-widget-ec342172.js';
|
|
4
4
|
import 'react/jsx-runtime';
|
|
5
5
|
import 'react';
|
package/dist/react.client.js
CHANGED
|
@@ -4,7 +4,7 @@ import { jsx } from "react/jsx-runtime";
|
|
|
4
4
|
var __ENV__ = {
|
|
5
5
|
server: true
|
|
6
6
|
};
|
|
7
|
-
var MODULE_REG = /\b(?:import|__vite_ssr_dynamic_import__)\(["']([^"']
|
|
7
|
+
var MODULE_REG = /\b(?:import|__vite_ssr_dynamic_import__)\(["']([^"']*)["']\)/;
|
|
8
8
|
function getFilename(loader) {
|
|
9
9
|
const match = String(loader).match(MODULE_REG);
|
|
10
10
|
const id = match?.[1];
|
|
@@ -167,34 +167,38 @@ function defineClientOnly(loader, base, { loading, name } = {}) {
|
|
|
167
167
|
// src/client.ts
|
|
168
168
|
import { createElement as createElement2 } from "react";
|
|
169
169
|
import { createRoot, hydrateRoot } from "react-dom/client";
|
|
170
|
-
import { defineRender
|
|
171
|
-
export * from "@web-widget/schema/client";
|
|
170
|
+
import { defineRender } from "@web-widget/schema/client-helpers";
|
|
171
|
+
export * from "@web-widget/schema/client-helpers";
|
|
172
172
|
Reflect.defineProperty(__ENV__, "server", {
|
|
173
173
|
value: false
|
|
174
174
|
});
|
|
175
|
-
var render = defineRender(
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
175
|
+
var render = defineRender(async (context, component, props) => {
|
|
176
|
+
const { recovering, container } = context;
|
|
177
|
+
if (!container) {
|
|
178
|
+
throw new Error(`Container required.`);
|
|
179
|
+
}
|
|
180
|
+
let root;
|
|
181
|
+
return {
|
|
182
|
+
async mount() {
|
|
183
|
+
let vnode;
|
|
184
|
+
if (typeof component === "function" && component.constructor.name === "AsyncFunction") {
|
|
184
185
|
vnode = await component(props);
|
|
185
186
|
} else {
|
|
186
|
-
|
|
187
|
+
vnode = createElement2(component, props);
|
|
187
188
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
189
|
+
if (recovering) {
|
|
190
|
+
root = hydrateRoot(container, vnode);
|
|
191
|
+
} else {
|
|
192
|
+
root = createRoot(container);
|
|
193
|
+
root.render(vnode);
|
|
194
|
+
}
|
|
195
|
+
},
|
|
196
|
+
async unmount() {
|
|
197
|
+
root?.unmount();
|
|
198
|
+
root = null;
|
|
195
199
|
}
|
|
196
|
-
}
|
|
197
|
-
);
|
|
200
|
+
};
|
|
201
|
+
});
|
|
198
202
|
export {
|
|
199
203
|
WebWidget,
|
|
200
204
|
WebWidgetClient,
|
package/dist/react.server.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _web_widget_schema from '@web-widget/schema';
|
|
2
|
-
export * from '@web-widget/schema/server';
|
|
2
|
+
export * from '@web-widget/schema/server-helpers';
|
|
3
3
|
export { C as ClientOptions, D as DefineWebWidgetOptions, W as WebWidget, b as WebWidgetClient, a as WebWidgetClientProps, c as WebWidgetProps, _ as __ENV__, W as default, e as defineClient, f as defineClientOnly, d as defineWebWidget, r as renderServerWidget } from './web-widget-ec342172.js';
|
|
4
4
|
import 'react/jsx-runtime';
|
|
5
5
|
import 'react';
|
package/dist/react.server.js
CHANGED
|
@@ -4,7 +4,7 @@ import { jsx } from "react/jsx-runtime";
|
|
|
4
4
|
var __ENV__ = {
|
|
5
5
|
server: true
|
|
6
6
|
};
|
|
7
|
-
var MODULE_REG = /\b(?:import|__vite_ssr_dynamic_import__)\(["']([^"']
|
|
7
|
+
var MODULE_REG = /\b(?:import|__vite_ssr_dynamic_import__)\(["']([^"']*)["']\)/;
|
|
8
8
|
function getFilename(loader) {
|
|
9
9
|
const match = String(loader).match(MODULE_REG);
|
|
10
10
|
const id = match?.[1];
|
|
@@ -167,26 +167,20 @@ function defineClientOnly(loader, base, { loading, name } = {}) {
|
|
|
167
167
|
// src/server.ts
|
|
168
168
|
import { createElement as createElement2 } from "react";
|
|
169
169
|
import * as ReactDOMServer from "react-dom/server.browser";
|
|
170
|
-
import { defineRender
|
|
171
|
-
export * from "@web-widget/schema/server";
|
|
170
|
+
import { defineRender } from "@web-widget/schema/server-helpers";
|
|
171
|
+
export * from "@web-widget/schema/server-helpers";
|
|
172
172
|
Reflect.defineProperty(__ENV__, "server", {
|
|
173
173
|
value: true
|
|
174
174
|
});
|
|
175
|
-
var render = defineRender(
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
} else {
|
|
182
|
-
throw new Error("Async widget components are not supported.");
|
|
183
|
-
}
|
|
184
|
-
} else {
|
|
185
|
-
vnode = createElement2(component, props);
|
|
186
|
-
}
|
|
187
|
-
return ReactDOMServer.renderToReadableStream(vnode);
|
|
175
|
+
var render = defineRender(async (context, component, props) => {
|
|
176
|
+
let vnode;
|
|
177
|
+
if (typeof component === "function" && component.constructor.name === "AsyncFunction") {
|
|
178
|
+
vnode = await component(props);
|
|
179
|
+
} else {
|
|
180
|
+
vnode = createElement2(component, props);
|
|
188
181
|
}
|
|
189
|
-
);
|
|
182
|
+
return ReactDOMServer.renderToReadableStream(vnode);
|
|
183
|
+
});
|
|
190
184
|
export {
|
|
191
185
|
WebWidget,
|
|
192
186
|
WebWidgetClient,
|
package/globals.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
|
|
1
3
|
type _IntrinsicAttributes = IntrinsicAttributes;
|
|
2
|
-
type loading = boolean | "lazy";
|
|
3
4
|
|
|
4
5
|
declare namespace JSX {
|
|
5
6
|
interface IntrinsicAttributes extends _IntrinsicAttributes {
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
as?: "web-widget" | "web-widget:server" | "web-widget:client" | any;
|
|
8
|
+
loading?: "lazy" | any;
|
|
9
|
+
fallback?: ReactNode;
|
|
8
10
|
}
|
|
9
11
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@web-widget/react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"@babel/helper-module-imports": "^7.22.5",
|
|
37
37
|
"@babel/helper-plugin-utils": "^7.22.5",
|
|
38
38
|
"@babel/traverse": "^7.22.5",
|
|
39
|
-
"@web-widget/schema": "0.0.
|
|
39
|
+
"@web-widget/schema": "0.0.5"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"@vitejs/plugin-react": "^4.0.2",
|