vue-layerx 0.0.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/LICENSE +21 -0
- package/README.md +85 -0
- package/dist/index.cjs +546 -0
- package/dist/index.d.cts +107 -0
- package/dist/index.d.ts +107 -0
- package/dist/index.js +521 -0
- package/package.json +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 vue-layerx contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# vue-layerx
|
|
2
|
+
|
|
3
|
+
Vue 3 弹层工厂:用 **一个 content 组件 + 一个 `createLayer` 工厂** 覆盖详情、编辑、新建等场景,无需维护 `v-model` 和重复的 dialog 模板。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add vue-layerx
|
|
9
|
+
# or
|
|
10
|
+
npm install vue-layerx
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
**Peer dependency:** Vue `^3.5.0`
|
|
14
|
+
|
|
15
|
+
## 快速开始
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
// layers/detail.ts
|
|
19
|
+
import { createLayer } from 'vue-layerx'
|
|
20
|
+
import BaseDialog from './BaseDialog.vue'
|
|
21
|
+
|
|
22
|
+
export const useDetailLayer = createLayer(BaseDialog)
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
// UserList.vue
|
|
27
|
+
import { useDetailLayer } from './layers/detail'
|
|
28
|
+
import UserForm from './UserForm.vue'
|
|
29
|
+
|
|
30
|
+
const userLayer = useDetailLayer(UserForm)
|
|
31
|
+
|
|
32
|
+
userLayer.show({ props: { mode: 'view', ...row } }) // 详情
|
|
33
|
+
userLayer.show({ props: { mode: 'edit', onSubmit } }) // 编辑
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
```vue
|
|
37
|
+
<!-- UserForm.vue -->
|
|
38
|
+
<script setup lang="ts">
|
|
39
|
+
import { defineLayer, LayerTemplate } from 'vue-layerx'
|
|
40
|
+
|
|
41
|
+
defineLayer({ props: { title: '用户' }, hideOn: ['submit'] })
|
|
42
|
+
</script>
|
|
43
|
+
|
|
44
|
+
<template>
|
|
45
|
+
<ElInput v-model="name" :disabled="mode === 'view'" />
|
|
46
|
+
<LayerTemplate v-if="mode !== 'view'" name="footer" #default="{ inLayer }">
|
|
47
|
+
<ElButton v-if="inLayer" type="primary" @click="submit">保存</ElButton>
|
|
48
|
+
</LayerTemplate>
|
|
49
|
+
</template>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## 核心 API
|
|
53
|
+
|
|
54
|
+
| 导出 | 用途 |
|
|
55
|
+
|------|------|
|
|
56
|
+
| `createLayer(Layer, defaults?, adapt?)` | 创建弹层工厂,返回 `useX(Content)` |
|
|
57
|
+
| `defineLayer(options)` | 在 content 内声明默认 layer 配置 |
|
|
58
|
+
| `LayerTemplate` | 声明式投递 layer / content 插槽 |
|
|
59
|
+
| `LayerBind` | 调用方填充 content 插槽 |
|
|
60
|
+
|
|
61
|
+
## 文档
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
pnpm docs:dev # 本地文档站
|
|
65
|
+
pnpm playground # 交互式 demo
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
教程与 API 详见仓库内 [docs/](docs/) 目录,或克隆后运行 `pnpm docs:dev`。
|
|
69
|
+
|
|
70
|
+
## 已知限制
|
|
71
|
+
|
|
72
|
+
- **不支持 SSR**
|
|
73
|
+
- 0.0.x 为早期版本,公共 API 可能调整
|
|
74
|
+
|
|
75
|
+
## 开发
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
pnpm install
|
|
79
|
+
pnpm test
|
|
80
|
+
pnpm build
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## License
|
|
84
|
+
|
|
85
|
+
[MIT](LICENSE)
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,546 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
LayerBind: () => LayerBind,
|
|
24
|
+
LayerTemplate: () => LayerTemplate,
|
|
25
|
+
createLayer: () => createLayer,
|
|
26
|
+
defineLayer: () => defineLayer
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(index_exports);
|
|
29
|
+
|
|
30
|
+
// src/runtime/create-use-layer.ts
|
|
31
|
+
var import_vue5 = require("vue");
|
|
32
|
+
|
|
33
|
+
// src/vue/instance/instance-registry.ts
|
|
34
|
+
var registry = /* @__PURE__ */ new WeakMap();
|
|
35
|
+
function attachInternal(instance, internal) {
|
|
36
|
+
registry.set(instance, internal);
|
|
37
|
+
}
|
|
38
|
+
function getInternal(instance) {
|
|
39
|
+
const internal = registry.get(instance);
|
|
40
|
+
if (!internal) {
|
|
41
|
+
throw new Error("[vue-layerx] Invalid LayerInstance passed to LayerBind");
|
|
42
|
+
}
|
|
43
|
+
return internal;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// src/vue/instance/internal-state.ts
|
|
47
|
+
var import_vue = require("vue");
|
|
48
|
+
function warnDuplicate(name, scope) {
|
|
49
|
+
if (typeof process !== "undefined" && process.env?.NODE_ENV === "production") return;
|
|
50
|
+
console.warn(
|
|
51
|
+
`[vue-layerx] Duplicate LayerTemplate name="${name}" in ${scope} scope; latter wins`
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
function createLayerInternalState() {
|
|
55
|
+
const slotsVersion = (0, import_vue.ref)(0);
|
|
56
|
+
const layerTemplates = {};
|
|
57
|
+
const contentTemplates = {};
|
|
58
|
+
const bumpSlots = () => {
|
|
59
|
+
slotsVersion.value++;
|
|
60
|
+
};
|
|
61
|
+
const registerLayerTemplate = (name, entry) => {
|
|
62
|
+
if (layerTemplates[name]) warnDuplicate(name, "layer");
|
|
63
|
+
layerTemplates[name] = entry;
|
|
64
|
+
bumpSlots();
|
|
65
|
+
};
|
|
66
|
+
const registerContentTemplate = (name, entry) => {
|
|
67
|
+
if (contentTemplates[name]) warnDuplicate(name, "content");
|
|
68
|
+
contentTemplates[name] = entry;
|
|
69
|
+
bumpSlots();
|
|
70
|
+
};
|
|
71
|
+
return {
|
|
72
|
+
layerTemplates,
|
|
73
|
+
contentTemplates,
|
|
74
|
+
slotsVersion,
|
|
75
|
+
bumpSlots,
|
|
76
|
+
registerLayerTemplate,
|
|
77
|
+
registerContentTemplate
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// src/runtime/layer-root.ts
|
|
82
|
+
var import_vue3 = require("vue");
|
|
83
|
+
|
|
84
|
+
// src/core/config/merge-node-config.ts
|
|
85
|
+
function mergeProps(...sources) {
|
|
86
|
+
const result = {};
|
|
87
|
+
for (const source of sources) {
|
|
88
|
+
if (!source) continue;
|
|
89
|
+
Object.assign(result, source);
|
|
90
|
+
}
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
function mergeNodeConfig(...sources) {
|
|
94
|
+
const result = {};
|
|
95
|
+
for (const source of sources) {
|
|
96
|
+
if (!source) continue;
|
|
97
|
+
if (source.component !== void 0) result.component = source.component;
|
|
98
|
+
result.props = mergeProps(result.props, source.props);
|
|
99
|
+
if (source.slots) {
|
|
100
|
+
result.slots = { ...result.slots, ...source.slots };
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// src/core/config/merge-config.ts
|
|
107
|
+
function pickContentConfig(payload) {
|
|
108
|
+
if (!payload) return void 0;
|
|
109
|
+
const result = {};
|
|
110
|
+
if (payload.component !== void 0) result.component = payload.component;
|
|
111
|
+
if (payload.props !== void 0) result.props = payload.props;
|
|
112
|
+
if (payload.slots !== void 0) result.slots = payload.slots;
|
|
113
|
+
if (Object.keys(result).length === 0) return void 0;
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
116
|
+
function pickLayerConfig(payload) {
|
|
117
|
+
return payload?.layer;
|
|
118
|
+
}
|
|
119
|
+
function defineLayerToConfig(defineLayer2) {
|
|
120
|
+
if (!defineLayer2) return void 0;
|
|
121
|
+
const result = {
|
|
122
|
+
layer: mergeNodeConfig(
|
|
123
|
+
defineLayer2.props ? { props: defineLayer2.props } : void 0,
|
|
124
|
+
defineLayer2.layer
|
|
125
|
+
)
|
|
126
|
+
};
|
|
127
|
+
if (defineLayer2.hideOn) result.hideOn = defineLayer2.hideOn;
|
|
128
|
+
return result;
|
|
129
|
+
}
|
|
130
|
+
function mergeConfig(ctx) {
|
|
131
|
+
const defineLayerConfig = defineLayerToConfig(ctx.defineLayer);
|
|
132
|
+
const content = mergeNodeConfig(
|
|
133
|
+
ctx.layerDefaults.content,
|
|
134
|
+
pickContentConfig(ctx.useOptions),
|
|
135
|
+
pickContentConfig(ctx.partial),
|
|
136
|
+
pickContentConfig(ctx.showOptions)
|
|
137
|
+
);
|
|
138
|
+
const layer = mergeNodeConfig(
|
|
139
|
+
ctx.layerDefaults.layer,
|
|
140
|
+
defineLayerConfig?.layer,
|
|
141
|
+
pickLayerConfig(ctx.useOptions),
|
|
142
|
+
pickLayerConfig(ctx.partial),
|
|
143
|
+
pickLayerConfig(ctx.showOptions)
|
|
144
|
+
);
|
|
145
|
+
const hideOn = ctx.showOptions.hideOn ?? ctx.partial?.hideOn ?? ctx.useOptions.hideOn ?? defineLayerConfig?.hideOn;
|
|
146
|
+
return { content, layer, hideOn };
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// src/core/config/bind-hide-on.ts
|
|
150
|
+
function bindHideOn(contentProps, events, hide) {
|
|
151
|
+
if (!events?.length) return contentProps;
|
|
152
|
+
const listeners = {};
|
|
153
|
+
for (const event of events) {
|
|
154
|
+
const key = `on${event.charAt(0).toUpperCase()}${event.slice(1)}`;
|
|
155
|
+
const prev = contentProps[key];
|
|
156
|
+
listeners[key] = (...args) => {
|
|
157
|
+
prev?.(...args);
|
|
158
|
+
hide();
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
return { ...contentProps, ...listeners };
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// src/core/config/default-resolve.ts
|
|
165
|
+
function materializeTemplates(templates) {
|
|
166
|
+
const slots = {};
|
|
167
|
+
for (const [name, entry] of Object.entries(templates)) {
|
|
168
|
+
slots[name] = (slotProps) => entry.render(slotProps ?? {});
|
|
169
|
+
}
|
|
170
|
+
return slots;
|
|
171
|
+
}
|
|
172
|
+
function resolveNodeSlots(templates, mergedSlots) {
|
|
173
|
+
return {
|
|
174
|
+
...materializeTemplates(templates),
|
|
175
|
+
...mergedSlots
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
function defaultResolve(ctx) {
|
|
179
|
+
const { merged, LayerComponent, boundContent, layerTemplates, contentTemplates, hide } = ctx;
|
|
180
|
+
const contentComponent = merged.content.component ?? boundContent;
|
|
181
|
+
const layerNormalized = {
|
|
182
|
+
component: merged.layer.component ?? LayerComponent,
|
|
183
|
+
props: merged.layer.props ?? {},
|
|
184
|
+
slots: resolveNodeSlots(layerTemplates, merged.layer.slots)
|
|
185
|
+
};
|
|
186
|
+
if (!contentComponent) {
|
|
187
|
+
return {
|
|
188
|
+
layer: layerNormalized,
|
|
189
|
+
content: {
|
|
190
|
+
component: LayerComponent,
|
|
191
|
+
props: {},
|
|
192
|
+
slots: {}
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
const contentProps = bindHideOn(merged.content.props ?? {}, merged.hideOn, hide);
|
|
197
|
+
return {
|
|
198
|
+
layer: layerNormalized,
|
|
199
|
+
content: {
|
|
200
|
+
component: contentComponent,
|
|
201
|
+
props: contentProps,
|
|
202
|
+
slots: resolveNodeSlots(contentTemplates, merged.content.slots)
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
function hasContentComponent(ctx) {
|
|
207
|
+
return !!(ctx.merged.content.component ?? ctx.boundContent);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// src/vue/render/render-layer-tree.ts
|
|
211
|
+
var import_vue2 = require("vue");
|
|
212
|
+
|
|
213
|
+
// src/core/constants/markers.ts
|
|
214
|
+
var LAYERX_DIRECT_CONTENT = "__layerxDirect";
|
|
215
|
+
|
|
216
|
+
// src/vue/render/build-visible-props.ts
|
|
217
|
+
function buildVisibleProps(layerProps, visible, visibleProp, visibleEvent, hide) {
|
|
218
|
+
return {
|
|
219
|
+
...layerProps,
|
|
220
|
+
[visibleProp]: visible,
|
|
221
|
+
[visibleEvent]: (value) => {
|
|
222
|
+
if (value === false || value === void 0) hide();
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// src/vue/render/render-layer-tree.ts
|
|
228
|
+
function renderLayerTree({
|
|
229
|
+
plan,
|
|
230
|
+
hasContent,
|
|
231
|
+
contentMountKey
|
|
232
|
+
}) {
|
|
233
|
+
const layerProps = buildVisibleProps(
|
|
234
|
+
plan.layer.props,
|
|
235
|
+
plan.visible,
|
|
236
|
+
plan.visibleProp,
|
|
237
|
+
plan.visibleEvent,
|
|
238
|
+
plan.onHide
|
|
239
|
+
);
|
|
240
|
+
const defaultSlot = hasContent ? () => (0, import_vue2.h)(
|
|
241
|
+
plan.content.component,
|
|
242
|
+
{
|
|
243
|
+
...plan.content.props,
|
|
244
|
+
key: contentMountKey,
|
|
245
|
+
[LAYERX_DIRECT_CONTENT]: true
|
|
246
|
+
},
|
|
247
|
+
plan.content.slots
|
|
248
|
+
) : () => null;
|
|
249
|
+
return (0, import_vue2.h)(plan.layer.component, layerProps, {
|
|
250
|
+
default: defaultSlot,
|
|
251
|
+
...plan.layer.slots
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// src/vue/di/injection-keys.ts
|
|
256
|
+
var LAYER_DEFINE_KEY = /* @__PURE__ */ Symbol("vue-layerx-define");
|
|
257
|
+
var LAYER_TEMPLATE_REGISTRY_KEY = /* @__PURE__ */ Symbol("vue-layerx-layer-template");
|
|
258
|
+
var LAYER_BIND_REGISTRY_KEY = /* @__PURE__ */ Symbol("vue-layerx-content-template");
|
|
259
|
+
|
|
260
|
+
// src/runtime/layer-root.ts
|
|
261
|
+
function buildLayerRoot(ctx, opts, internal, state, defineLayerConfig, hide) {
|
|
262
|
+
return (0, import_vue3.defineComponent)({
|
|
263
|
+
name: `LayerRoot_${opts.Content ? opts.Content.name ?? "Anonymous" : "Shell"}`,
|
|
264
|
+
setup() {
|
|
265
|
+
(0, import_vue3.provide)(LAYER_DEFINE_KEY, {
|
|
266
|
+
register(config) {
|
|
267
|
+
defineLayerConfig.value = config;
|
|
268
|
+
internal.bumpSlots();
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
(0, import_vue3.provide)(LAYER_TEMPLATE_REGISTRY_KEY, {
|
|
272
|
+
registerLayerTemplate: internal.registerLayerTemplate
|
|
273
|
+
});
|
|
274
|
+
return () => {
|
|
275
|
+
if (!state.visible) return null;
|
|
276
|
+
void internal.slotsVersion.value;
|
|
277
|
+
const merged = mergeConfig({
|
|
278
|
+
layerDefaults: ctx.layerDefaults,
|
|
279
|
+
defineLayer: defineLayerConfig.value,
|
|
280
|
+
useOptions: opts.useOptions,
|
|
281
|
+
showOptions: state.showOptions,
|
|
282
|
+
partial: opts.partial
|
|
283
|
+
});
|
|
284
|
+
const resolveCtx = {
|
|
285
|
+
merged,
|
|
286
|
+
LayerComponent: ctx.LayerComponent,
|
|
287
|
+
boundContent: opts.Content,
|
|
288
|
+
layerTemplates: internal.layerTemplates,
|
|
289
|
+
contentTemplates: internal.contentTemplates,
|
|
290
|
+
hide
|
|
291
|
+
};
|
|
292
|
+
const resolved = defaultResolve(resolveCtx);
|
|
293
|
+
const normalized = ctx.adapt ? ctx.adapt(resolved) : resolved;
|
|
294
|
+
const contentPresent = hasContentComponent(resolveCtx);
|
|
295
|
+
const plan = {
|
|
296
|
+
...normalized,
|
|
297
|
+
visible: true,
|
|
298
|
+
visibleProp: ctx.visibleProp,
|
|
299
|
+
visibleEvent: ctx.visibleEvent,
|
|
300
|
+
onHide: hide
|
|
301
|
+
};
|
|
302
|
+
return renderLayerTree({
|
|
303
|
+
plan,
|
|
304
|
+
hasContent: contentPresent,
|
|
305
|
+
contentMountKey: contentPresent ? state.contentMountKey : void 0
|
|
306
|
+
});
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// src/runtime/layer-runtime.ts
|
|
313
|
+
var import_vue4 = require("vue");
|
|
314
|
+
function createLayerRuntime(root, appContext) {
|
|
315
|
+
let container = null;
|
|
316
|
+
return {
|
|
317
|
+
get mounted() {
|
|
318
|
+
return container !== null;
|
|
319
|
+
},
|
|
320
|
+
mount() {
|
|
321
|
+
if (!container) {
|
|
322
|
+
container = document.createElement("div");
|
|
323
|
+
document.body.appendChild(container);
|
|
324
|
+
}
|
|
325
|
+
const vnode = (0, import_vue4.h)(root);
|
|
326
|
+
if (appContext) vnode.appContext = appContext;
|
|
327
|
+
(0, import_vue4.render)(vnode, container);
|
|
328
|
+
},
|
|
329
|
+
unmount() {
|
|
330
|
+
if (!container) return;
|
|
331
|
+
(0, import_vue4.render)(null, container);
|
|
332
|
+
container.remove();
|
|
333
|
+
container = null;
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// src/runtime/create-use-layer.ts
|
|
339
|
+
function createInstanceLifecycle() {
|
|
340
|
+
const disposers = [];
|
|
341
|
+
return {
|
|
342
|
+
register(dispose) {
|
|
343
|
+
disposers.push(dispose);
|
|
344
|
+
},
|
|
345
|
+
dispose() {
|
|
346
|
+
for (const dispose of disposers.splice(0)) dispose();
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
function createInstance(ctx, opts) {
|
|
351
|
+
const internal = createLayerInternalState();
|
|
352
|
+
const state = (0, import_vue5.reactive)({
|
|
353
|
+
visible: false,
|
|
354
|
+
showOptions: {},
|
|
355
|
+
contentMountKey: 0
|
|
356
|
+
});
|
|
357
|
+
const defineLayerConfig = (0, import_vue5.shallowRef)(null);
|
|
358
|
+
const hide = () => {
|
|
359
|
+
state.visible = false;
|
|
360
|
+
};
|
|
361
|
+
const LayerRoot = buildLayerRoot(ctx, opts, internal, state, defineLayerConfig, hide);
|
|
362
|
+
const runtime = createLayerRuntime(LayerRoot, opts.appContext);
|
|
363
|
+
const dispose = () => {
|
|
364
|
+
state.visible = false;
|
|
365
|
+
runtime.unmount();
|
|
366
|
+
};
|
|
367
|
+
const show = (payload) => {
|
|
368
|
+
defineLayerConfig.value = null;
|
|
369
|
+
if (payload) state.showOptions = payload;
|
|
370
|
+
state.contentMountKey++;
|
|
371
|
+
state.visible = true;
|
|
372
|
+
if (!runtime.mounted) runtime.mount();
|
|
373
|
+
};
|
|
374
|
+
const instance = {
|
|
375
|
+
show,
|
|
376
|
+
hide,
|
|
377
|
+
clone(partial) {
|
|
378
|
+
const bundle = createInstance(ctx, {
|
|
379
|
+
Content: opts.Content,
|
|
380
|
+
useOptions: opts.useOptions,
|
|
381
|
+
partial: partial ?? {},
|
|
382
|
+
appContext: opts.appContext,
|
|
383
|
+
lifecycle: opts.lifecycle
|
|
384
|
+
});
|
|
385
|
+
opts.lifecycle.register(bundle.dispose);
|
|
386
|
+
return bundle.instance;
|
|
387
|
+
},
|
|
388
|
+
get visible() {
|
|
389
|
+
return state.visible;
|
|
390
|
+
}
|
|
391
|
+
};
|
|
392
|
+
attachInternal(instance, internal);
|
|
393
|
+
return { instance, dispose };
|
|
394
|
+
}
|
|
395
|
+
function createUseLayer(ctx) {
|
|
396
|
+
return function useLayer(Content, useOptions = {}) {
|
|
397
|
+
const hostInstance = (0, import_vue5.getCurrentInstance)();
|
|
398
|
+
const appContext = hostInstance?.appContext ?? null;
|
|
399
|
+
const lifecycle = createInstanceLifecycle();
|
|
400
|
+
const { instance, dispose } = createInstance(ctx, {
|
|
401
|
+
Content,
|
|
402
|
+
useOptions,
|
|
403
|
+
partial: {},
|
|
404
|
+
appContext,
|
|
405
|
+
lifecycle
|
|
406
|
+
});
|
|
407
|
+
lifecycle.register(dispose);
|
|
408
|
+
if (hostInstance) {
|
|
409
|
+
(0, import_vue5.onUnmounted)(() => lifecycle.dispose());
|
|
410
|
+
}
|
|
411
|
+
return instance;
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// src/api/create-layer.ts
|
|
416
|
+
var DEFAULT_VISIBLE = ["modelValue", "onUpdate:modelValue"];
|
|
417
|
+
function createLayer(LayerComponent, defaults = {}, adapt) {
|
|
418
|
+
const [visibleProp, visibleEvent] = defaults.visible ?? DEFAULT_VISIBLE;
|
|
419
|
+
return createUseLayer({
|
|
420
|
+
LayerComponent,
|
|
421
|
+
layerDefaults: defaults,
|
|
422
|
+
visibleProp,
|
|
423
|
+
visibleEvent,
|
|
424
|
+
adapt
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
// src/api/define-layer.ts
|
|
429
|
+
var import_vue6 = require("vue");
|
|
430
|
+
|
|
431
|
+
// src/vue/context/layer-marker.ts
|
|
432
|
+
function hasDirectLayerMarker(instance) {
|
|
433
|
+
if (!instance) return false;
|
|
434
|
+
if (instance.props?.[LAYERX_DIRECT_CONTENT] === true) return true;
|
|
435
|
+
const attrs = instance.attrs;
|
|
436
|
+
if (attrs?.[LAYERX_DIRECT_CONTENT] === true) return true;
|
|
437
|
+
const vnodeProps = instance.vnode?.props;
|
|
438
|
+
if (vnodeProps?.[LAYERX_DIRECT_CONTENT] === true) return true;
|
|
439
|
+
return false;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
// src/api/define-layer.ts
|
|
443
|
+
function defineLayer(options = {}) {
|
|
444
|
+
const registry2 = (0, import_vue6.inject)(LAYER_DEFINE_KEY, null);
|
|
445
|
+
const instance = (0, import_vue6.getCurrentInstance)();
|
|
446
|
+
if (!registry2 || !hasDirectLayerMarker(instance)) return;
|
|
447
|
+
registry2.register(options);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
// src/components/layer-template.ts
|
|
451
|
+
var import_vue7 = require("vue");
|
|
452
|
+
|
|
453
|
+
// src/vue/context/owning-content.ts
|
|
454
|
+
function getOwningContentInstance(instance) {
|
|
455
|
+
let cur = instance?.parent ?? null;
|
|
456
|
+
while (cur) {
|
|
457
|
+
const type = cur.type;
|
|
458
|
+
if (typeof type === "object" || typeof type === "function") {
|
|
459
|
+
return cur;
|
|
460
|
+
}
|
|
461
|
+
cur = cur.parent;
|
|
462
|
+
}
|
|
463
|
+
return null;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
// src/vue/context/in-layer-content.ts
|
|
467
|
+
function isInDirectLayerContent(instance) {
|
|
468
|
+
return hasDirectLayerMarker(getOwningContentInstance(instance));
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
// src/components/layer-template.ts
|
|
472
|
+
function buildTemplateScope(slotProps, layer) {
|
|
473
|
+
return {
|
|
474
|
+
slotProps,
|
|
475
|
+
inLayer: layer.inLayer,
|
|
476
|
+
outsideLayer: layer.outsideLayer
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
var LayerTemplate = (0, import_vue7.defineComponent)({
|
|
480
|
+
name: "LayerTemplate",
|
|
481
|
+
props: {
|
|
482
|
+
name: {
|
|
483
|
+
type: String,
|
|
484
|
+
required: true
|
|
485
|
+
},
|
|
486
|
+
visibleOutside: {
|
|
487
|
+
type: Boolean,
|
|
488
|
+
default: false
|
|
489
|
+
}
|
|
490
|
+
},
|
|
491
|
+
setup(props, { slots }) {
|
|
492
|
+
const layerRegistry = (0, import_vue7.inject)(LAYER_TEMPLATE_REGISTRY_KEY, null);
|
|
493
|
+
const bindRegistry = (0, import_vue7.inject)(LAYER_BIND_REGISTRY_KEY, null);
|
|
494
|
+
const instance = (0, import_vue7.getCurrentInstance)();
|
|
495
|
+
const inLayer = (0, import_vue7.computed)(
|
|
496
|
+
() => layerRegistry !== null && isInDirectLayerContent(instance)
|
|
497
|
+
);
|
|
498
|
+
const inBind = (0, import_vue7.computed)(() => bindRegistry !== null);
|
|
499
|
+
const renderSlot = (templateScope) => slots.default?.(templateScope) ?? null;
|
|
500
|
+
(0, import_vue7.onMounted)(() => {
|
|
501
|
+
const renderWithScope = (layer) => (slotProps = {}) => renderSlot(buildTemplateScope(slotProps, layer));
|
|
502
|
+
if (inLayer.value && layerRegistry) {
|
|
503
|
+
layerRegistry.registerLayerTemplate(props.name, {
|
|
504
|
+
render: renderWithScope({ inLayer: true, outsideLayer: false })
|
|
505
|
+
});
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
if (inBind.value && bindRegistry) {
|
|
509
|
+
bindRegistry.registerContentTemplate(props.name, {
|
|
510
|
+
render: renderWithScope({ inLayer: true, outsideLayer: false })
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
});
|
|
514
|
+
return () => {
|
|
515
|
+
if (inLayer.value || inBind.value) return null;
|
|
516
|
+
if (!props.visibleOutside) return null;
|
|
517
|
+
return renderSlot(buildTemplateScope({}, { inLayer: false, outsideLayer: true }));
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
});
|
|
521
|
+
|
|
522
|
+
// src/components/layer-bind.ts
|
|
523
|
+
var import_vue8 = require("vue");
|
|
524
|
+
var LayerBind = (0, import_vue8.defineComponent)({
|
|
525
|
+
name: "LayerBind",
|
|
526
|
+
props: {
|
|
527
|
+
to: {
|
|
528
|
+
type: Object,
|
|
529
|
+
required: true
|
|
530
|
+
}
|
|
531
|
+
},
|
|
532
|
+
setup(props, { slots }) {
|
|
533
|
+
const internal = getInternal(props.to);
|
|
534
|
+
(0, import_vue8.provide)(LAYER_BIND_REGISTRY_KEY, {
|
|
535
|
+
registerContentTemplate: internal.registerContentTemplate
|
|
536
|
+
});
|
|
537
|
+
return () => slots.default?.();
|
|
538
|
+
}
|
|
539
|
+
});
|
|
540
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
541
|
+
0 && (module.exports = {
|
|
542
|
+
LayerBind,
|
|
543
|
+
LayerTemplate,
|
|
544
|
+
createLayer,
|
|
545
|
+
defineLayer
|
|
546
|
+
});
|