@web-widget/vue 0.1.1 → 0.1.2
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/vue.client.d.ts +14 -5
- package/dist/vue.client.js +12 -6
- package/dist/vue.server.d.ts +14 -5
- package/dist/vue.server.js +33 -6
- package/package.json +2 -1
package/dist/vue.client.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as _web_widget_schema from '@web-widget/schema';
|
|
2
|
+
import { RenderContext, ComponentProps } from '@web-widget/schema';
|
|
2
3
|
import * as vue from 'vue';
|
|
3
|
-
import { PropType, VNode,
|
|
4
|
-
import { RenderContext, ComponentProps } from '@web-widget/schema/client-helpers';
|
|
4
|
+
import { PropType, VNode, Component, App } from 'vue';
|
|
5
5
|
export * from '@web-widget/schema/client-helpers';
|
|
6
6
|
import { Loader, WebWidgetContainerOptions } from '@web-widget/web-widget';
|
|
7
7
|
|
|
@@ -131,10 +131,19 @@ declare function defineWebWidget(loader: Loader, options: DefineWebWidgetOptions
|
|
|
131
131
|
renderStage: "server" | "client" | undefined;
|
|
132
132
|
}, {}>;
|
|
133
133
|
|
|
134
|
+
type JSONValue = string | number | boolean | {
|
|
135
|
+
[x: string]: JSONValue;
|
|
136
|
+
} | Array<JSONValue>;
|
|
137
|
+
type JSONProps = {
|
|
138
|
+
[x: string]: JSONValue;
|
|
139
|
+
};
|
|
134
140
|
interface DefineVueRenderOptions {
|
|
135
|
-
|
|
141
|
+
onBeforeCreateApp?: (context: RenderContext, component: Component, props: ComponentProps) => any;
|
|
142
|
+
onCreatedApp?: (app: App<Element>, context: RenderContext, component: Component, props: ComponentProps) => void;
|
|
143
|
+
onPrefetchData?: (context: RenderContext, component: Component, props: ComponentProps) => Promise<JSONProps>;
|
|
136
144
|
}
|
|
137
|
-
|
|
145
|
+
|
|
146
|
+
declare const defineVueRender: ({ onCreatedApp, onPrefetchData, }?: DefineVueRenderOptions) => (context: _web_widget_schema.ClientWidgetRenderContext<unknown> | _web_widget_schema.ClientRouteRenderContext<unknown, Record<string, string>>) => Promise<void | {
|
|
138
147
|
mount?: (() => void | Promise<void>) | undefined;
|
|
139
148
|
unmount?: (() => void | Promise<void>) | undefined;
|
|
140
149
|
update?: (({ data }: {
|
|
@@ -161,4 +170,4 @@ declare const render: (context: _web_widget_schema.ClientWidgetRenderContext<unk
|
|
|
161
170
|
}) => void | Promise<void>) | undefined;
|
|
162
171
|
}>;
|
|
163
172
|
|
|
164
|
-
export {
|
|
173
|
+
export { DefineWebWidgetOptions, WebWidget, __ENV__, defineVueRender, defineWebWidget, render };
|
package/dist/vue.client.js
CHANGED
|
@@ -142,7 +142,8 @@ Reflect.defineProperty(__ENV__, "server", {
|
|
|
142
142
|
});
|
|
143
143
|
var defineVueRender = ({
|
|
144
144
|
onCreatedApp = () => {
|
|
145
|
-
}
|
|
145
|
+
},
|
|
146
|
+
onPrefetchData
|
|
146
147
|
} = {}) => {
|
|
147
148
|
return defineRender(async (context, component, props) => {
|
|
148
149
|
if (!context.container) {
|
|
@@ -151,14 +152,19 @@ var defineVueRender = ({
|
|
|
151
152
|
let app;
|
|
152
153
|
return {
|
|
153
154
|
async mount() {
|
|
154
|
-
const
|
|
155
|
+
const shell = context.recovering && context.container.querySelector("[webwidgetshell]") || context.container;
|
|
156
|
+
const state = context.recovering ? context.container.querySelector(
|
|
157
|
+
"[webwidgetstate]"
|
|
158
|
+
) : null;
|
|
159
|
+
const stateContent = context.recovering && state ? JSON.parse(state.textContent) : onPrefetchData ? await onPrefetchData(context, component, props) : void 0;
|
|
160
|
+
const mergedProps = stateContent ? Object.assign({}, stateContent, props) : props;
|
|
155
161
|
if (context.recovering) {
|
|
156
|
-
app = createSSRApp(component,
|
|
162
|
+
app = createSSRApp(component, mergedProps);
|
|
157
163
|
} else {
|
|
158
|
-
app = createApp(component,
|
|
164
|
+
app = createApp(component, mergedProps);
|
|
159
165
|
}
|
|
160
|
-
onCreatedApp(app, context, component,
|
|
161
|
-
app.mount(
|
|
166
|
+
onCreatedApp(app, context, component, mergedProps);
|
|
167
|
+
app.mount(shell);
|
|
162
168
|
},
|
|
163
169
|
async unmount() {
|
|
164
170
|
app == null ? void 0 : app.unmount();
|
package/dist/vue.server.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as _web_widget_schema from '@web-widget/schema';
|
|
2
|
+
import { RenderContext, ComponentProps } from '@web-widget/schema';
|
|
2
3
|
import * as vue from 'vue';
|
|
3
|
-
import { PropType, VNode,
|
|
4
|
-
import { RenderContext, ComponentProps } from '@web-widget/schema/server-helpers';
|
|
4
|
+
import { PropType, VNode, Component, App } from 'vue';
|
|
5
5
|
export * from '@web-widget/schema/server-helpers';
|
|
6
6
|
import { Loader, WebWidgetContainerOptions } from '@web-widget/web-widget';
|
|
7
7
|
|
|
@@ -131,10 +131,19 @@ declare function defineWebWidget(loader: Loader, options: DefineWebWidgetOptions
|
|
|
131
131
|
renderStage: "server" | "client" | undefined;
|
|
132
132
|
}, {}>;
|
|
133
133
|
|
|
134
|
+
type JSONValue = string | number | boolean | {
|
|
135
|
+
[x: string]: JSONValue;
|
|
136
|
+
} | Array<JSONValue>;
|
|
137
|
+
type JSONProps = {
|
|
138
|
+
[x: string]: JSONValue;
|
|
139
|
+
};
|
|
134
140
|
interface DefineVueRenderOptions {
|
|
135
|
-
|
|
141
|
+
onBeforeCreateApp?: (context: RenderContext, component: Component, props: ComponentProps) => any;
|
|
142
|
+
onCreatedApp?: (app: App<Element>, context: RenderContext, component: Component, props: ComponentProps) => void;
|
|
143
|
+
onPrefetchData?: (context: RenderContext, component: Component, props: ComponentProps) => Promise<JSONProps>;
|
|
136
144
|
}
|
|
137
|
-
|
|
145
|
+
|
|
146
|
+
declare const defineVueRender: ({ onCreatedApp, onPrefetchData, }?: DefineVueRenderOptions) => (context: _web_widget_schema.ServerWidgetRenderContext<unknown> | _web_widget_schema.ServerRouteRenderContext<unknown, Record<string, string>>) => Promise<string | ReadableStream<any>>;
|
|
138
147
|
declare const render: (context: _web_widget_schema.ServerWidgetRenderContext<unknown> | _web_widget_schema.ServerRouteRenderContext<unknown, Record<string, string>>) => Promise<string | ReadableStream<any>>;
|
|
139
148
|
|
|
140
|
-
export {
|
|
149
|
+
export { DefineWebWidgetOptions, WebWidget, __ENV__, defineVueRender, defineWebWidget, render };
|
package/dist/vue.server.js
CHANGED
|
@@ -134,22 +134,49 @@ function defineWebWidget(loader, options) {
|
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
// src/server.ts
|
|
137
|
-
import { createSSRApp } from "vue";
|
|
137
|
+
import { createSSRApp, h as h2, Fragment } from "vue";
|
|
138
138
|
import { defineRender } from "@web-widget/schema/server-helpers";
|
|
139
139
|
import { renderToWebStream } from "vue/server-renderer";
|
|
140
140
|
export * from "@web-widget/schema/server-helpers";
|
|
141
141
|
Reflect.defineProperty(__ENV__, "server", {
|
|
142
142
|
value: true
|
|
143
143
|
});
|
|
144
|
+
var ESCAPE_LOOKUP = {
|
|
145
|
+
">": "\\u003e",
|
|
146
|
+
"<": "\\u003c",
|
|
147
|
+
"\u2028": "\\u2028",
|
|
148
|
+
"\u2029": "\\u2029"
|
|
149
|
+
};
|
|
150
|
+
var ESCAPE_REGEX = /[><\u2028\u2029]/g;
|
|
151
|
+
function htmlEscapeJsonString(str) {
|
|
152
|
+
return str.replace(ESCAPE_REGEX, (match) => ESCAPE_LOOKUP[match]);
|
|
153
|
+
}
|
|
144
154
|
var defineVueRender = ({
|
|
145
155
|
onCreatedApp = () => {
|
|
146
|
-
}
|
|
156
|
+
},
|
|
157
|
+
onPrefetchData
|
|
147
158
|
} = {}) => {
|
|
148
159
|
return defineRender(async (context, component, props) => {
|
|
149
|
-
const
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
|
|
160
|
+
const state = onPrefetchData ? await onPrefetchData(context, component, props) : void 0;
|
|
161
|
+
const mergedProps = state ? Object.assign({}, state, props) : props;
|
|
162
|
+
if (state) {
|
|
163
|
+
const stateStringify = htmlEscapeJsonString(JSON.stringify(state));
|
|
164
|
+
const vNode = h2(Fragment, null, [
|
|
165
|
+
h2(component, mergedProps),
|
|
166
|
+
h2("script", {
|
|
167
|
+
webwidgetstate: "",
|
|
168
|
+
type: "application/json",
|
|
169
|
+
innerHTML: stateStringify
|
|
170
|
+
})
|
|
171
|
+
]);
|
|
172
|
+
const app = createSSRApp(vNode);
|
|
173
|
+
onCreatedApp(app, context, component, props);
|
|
174
|
+
return renderToWebStream(app);
|
|
175
|
+
} else {
|
|
176
|
+
const app = createSSRApp(component, mergedProps);
|
|
177
|
+
onCreatedApp(app, context, component, props);
|
|
178
|
+
return renderToWebStream(app);
|
|
179
|
+
}
|
|
153
180
|
});
|
|
154
181
|
};
|
|
155
182
|
var render = defineVueRender();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@web-widget/vue",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
+
"@web-widget/html": "0.0.4",
|
|
25
26
|
"@web-widget/schema": "0.0.9",
|
|
26
27
|
"@web-widget/web-widget": "1.0.0-alpha.7"
|
|
27
28
|
},
|