@dxup/nuxt 0.5.0 → 0.5.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/README.md +2 -0
- package/dist/module.mjs +4 -23
- package/dist/runtime/layouts.d.mts +35 -0
- package/dist/runtime/layouts.mjs +53 -0
- package/dist/typescript.cjs +2 -2
- package/package.json +1 -2
- package/dist/components/forward.d.mts +0 -4
- package/dist/components/forward.mjs +0 -10
package/README.md
CHANGED
|
@@ -89,6 +89,8 @@ Write top-level named slots in your pages:
|
|
|
89
89
|
|
|
90
90
|
And them will be forwarded to the active layout automatically.
|
|
91
91
|
|
|
92
|
+
Due to design limitations, dynamic slots are currently not supported.
|
|
93
|
+
|
|
92
94
|
### 4. nitroRoutes
|
|
93
95
|
|
|
94
96
|
Go to definition for nitro routes in data fetching methods.
|
package/dist/module.mjs
CHANGED
|
@@ -107,15 +107,15 @@ const TransformLayoutPlugin = (options) => createUnplugin(() => ({
|
|
|
107
107
|
const layout = template?.children.find((node) => node.type === NodeTypes.ELEMENT && (node.tag === "nuxt-layout" || node.tag === "NuxtLayout"));
|
|
108
108
|
if (!layout?.children.length) return;
|
|
109
109
|
const s = new MagicString(code);
|
|
110
|
-
const prefix = "\n" + genImport("#build/dxup/layouts.mjs", ["provideLayoutSlots"]);
|
|
111
|
-
const suffix = `\
|
|
110
|
+
const prefix = "\n" + genImport("#build/dxup/layouts.mjs", ["LayoutSlot", "provideLayoutSlots"]);
|
|
111
|
+
const suffix = `\nprovideLayoutSlots();\n`;
|
|
112
112
|
if (scriptSetup) {
|
|
113
113
|
s.appendLeft(scriptSetup.innerLoc.start.offset, prefix);
|
|
114
114
|
s.appendLeft(scriptSetup.innerLoc.end.offset, suffix);
|
|
115
115
|
} else s.prepend(`<script setup>${prefix + suffix}<\/script>\n\n`);
|
|
116
116
|
s.appendLeft(layout.children.at(-1).loc.end.offset, `
|
|
117
117
|
<template v-for="name in $route.meta.layoutSlots ?? []" :key="name" #[name]="props">
|
|
118
|
-
<
|
|
118
|
+
<LayoutSlot :name :props/>
|
|
119
119
|
</template>`);
|
|
120
120
|
return {
|
|
121
121
|
code: s.toString(),
|
|
@@ -180,26 +180,7 @@ function setup(nuxt, pluginsVue) {
|
|
|
180
180
|
addTemplate({
|
|
181
181
|
filename: "dxup/layouts.mjs",
|
|
182
182
|
getContents() {
|
|
183
|
-
return
|
|
184
|
-
${genImport("vue", [
|
|
185
|
-
"inject",
|
|
186
|
-
"provide",
|
|
187
|
-
"shallowRef"
|
|
188
|
-
])}
|
|
189
|
-
${genExport(resolver.resolve("components/forward"), [{
|
|
190
|
-
name: "default",
|
|
191
|
-
as: "LayoutSlotsForward"
|
|
192
|
-
}])}
|
|
193
|
-
const injectionKey = Symbol();
|
|
194
|
-
export function provideLayoutSlots() {
|
|
195
|
-
const slots = shallowRef({});
|
|
196
|
-
provide(injectionKey, slots);
|
|
197
|
-
return slots;
|
|
198
|
-
}
|
|
199
|
-
export function injectLayoutSlots() {
|
|
200
|
-
return inject(injectionKey);
|
|
201
|
-
}
|
|
202
|
-
`.trimStart();
|
|
183
|
+
return genExport(resolver.resolve("runtime/layouts.mjs"), "*");
|
|
203
184
|
}
|
|
204
185
|
});
|
|
205
186
|
addTypeTemplate({
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ShallowRef, Slots } from "vue";
|
|
2
|
+
|
|
3
|
+
//#region src/module/named-layout-slots/runtime/layouts.d.ts
|
|
4
|
+
interface LayoutSlotsRegistry {
|
|
5
|
+
slots: ShallowRef<Slots>;
|
|
6
|
+
set: (slots: Slots) => void;
|
|
7
|
+
waitFor: (name: string) => Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
declare function provideLayoutSlots(): LayoutSlotsRegistry;
|
|
10
|
+
declare const LayoutSlot: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
11
|
+
name: {
|
|
12
|
+
type: StringConstructor;
|
|
13
|
+
required: true;
|
|
14
|
+
};
|
|
15
|
+
props: {
|
|
16
|
+
type: ObjectConstructor;
|
|
17
|
+
default: () => {};
|
|
18
|
+
};
|
|
19
|
+
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
20
|
+
[key: string]: any;
|
|
21
|
+
}>[] | undefined, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
22
|
+
name: {
|
|
23
|
+
type: StringConstructor;
|
|
24
|
+
required: true;
|
|
25
|
+
};
|
|
26
|
+
props: {
|
|
27
|
+
type: ObjectConstructor;
|
|
28
|
+
default: () => {};
|
|
29
|
+
};
|
|
30
|
+
}>> & Readonly<{}>, {
|
|
31
|
+
props: Record<string, any>;
|
|
32
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
33
|
+
declare const LayoutSlotsForward: import("vue").DefineSetupFnComponent<Record<string, any>, {}, {}, Record<string, any> & {}, import("vue").PublicProps>;
|
|
34
|
+
//#endregion
|
|
35
|
+
export { LayoutSlot, LayoutSlotsForward, provideLayoutSlots };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { defineComponent, inject, provide, shallowRef } from "vue";
|
|
2
|
+
//#region src/module/named-layout-slots/runtime/layouts.ts
|
|
3
|
+
const injectionKey = Symbol();
|
|
4
|
+
function provideLayoutSlots() {
|
|
5
|
+
const slots = shallowRef({});
|
|
6
|
+
const waiters = /* @__PURE__ */ new Map();
|
|
7
|
+
const registry = {
|
|
8
|
+
slots,
|
|
9
|
+
set(value) {
|
|
10
|
+
slots.value = value;
|
|
11
|
+
for (const name of Object.keys(value)) {
|
|
12
|
+
const resolves = waiters.get(name);
|
|
13
|
+
if (!resolves?.length) continue;
|
|
14
|
+
waiters.delete(name);
|
|
15
|
+
for (const resolve of resolves) resolve();
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
waitFor(name) {
|
|
19
|
+
if (slots.value[name]) return Promise.resolve();
|
|
20
|
+
return new Promise((resolve) => {
|
|
21
|
+
let resolves = waiters.get(name);
|
|
22
|
+
if (!resolves) waiters.set(name, resolves = []);
|
|
23
|
+
resolves.push(resolve);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
provide(injectionKey, registry);
|
|
28
|
+
return registry;
|
|
29
|
+
}
|
|
30
|
+
const LayoutSlot = defineComponent({
|
|
31
|
+
props: {
|
|
32
|
+
name: {
|
|
33
|
+
type: String,
|
|
34
|
+
required: true
|
|
35
|
+
},
|
|
36
|
+
props: {
|
|
37
|
+
type: Object,
|
|
38
|
+
default: () => ({})
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
setup(props) {
|
|
42
|
+
const registry = inject(injectionKey);
|
|
43
|
+
const render = () => registry.slots.value[props.name]?.(props.props);
|
|
44
|
+
if (import.meta.server && !registry.slots.value[props.name]) return registry.waitFor(props.name).then(() => render);
|
|
45
|
+
return render;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
const LayoutSlotsForward = defineComponent((props, ctx) => {
|
|
49
|
+
inject(injectionKey).set(ctx.slots);
|
|
50
|
+
return () => ctx.slots.default?.();
|
|
51
|
+
});
|
|
52
|
+
//#endregion
|
|
53
|
+
export { LayoutSlot, LayoutSlotsForward, provideLayoutSlots };
|
package/dist/typescript.cjs
CHANGED
|
@@ -172,12 +172,12 @@ var getDefinitionAndBoundSpan_exports = /* @__PURE__ */ __exportAll({
|
|
|
172
172
|
postprocess: () => postprocess,
|
|
173
173
|
preprocess: () => preprocess$1
|
|
174
174
|
});
|
|
175
|
-
const fetchFunctions = new Set([
|
|
175
|
+
const fetchFunctions = /* @__PURE__ */ new Set([
|
|
176
176
|
"$fetch",
|
|
177
177
|
"useFetch",
|
|
178
178
|
"useLazyFetch"
|
|
179
179
|
]);
|
|
180
|
-
const pageMetaKeys = new Set(["layout", "middleware"]);
|
|
180
|
+
const pageMetaKeys = /* @__PURE__ */ new Set(["layout", "middleware"]);
|
|
181
181
|
function postprocess(context, language, getDefinitionAndBoundSpan) {
|
|
182
182
|
const { ts } = context;
|
|
183
183
|
return (...args) => {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxup/nuxt",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.1",
|
|
5
5
|
"description": "TypeScript plugin for Nuxt",
|
|
6
6
|
"author": "KazariEX",
|
|
7
7
|
"license": "MIT",
|
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
},
|
|
12
12
|
"exports": {
|
|
13
13
|
".": "./dist/module.mjs",
|
|
14
|
-
"./components/*": "./dist/components/*",
|
|
15
14
|
"./languages/*": "./dist/languages/*",
|
|
16
15
|
"./package.json": "./package.json"
|
|
17
16
|
},
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { defineComponent } from "vue";
|
|
2
|
-
import { injectLayoutSlots } from "#build/dxup/layouts.mjs";
|
|
3
|
-
//#region src/module/named-layout-slots/components/forward.ts
|
|
4
|
-
var forward_default = defineComponent((props, ctx) => {
|
|
5
|
-
const slots = injectLayoutSlots();
|
|
6
|
-
slots.value = ctx.slots;
|
|
7
|
-
return () => ctx.slots.default?.();
|
|
8
|
-
});
|
|
9
|
-
//#endregion
|
|
10
|
-
export { forward_default as default };
|