@overlastic/vue 0.4.7
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 +23 -0
- package/README.md +86 -0
- package/dist/index.cjs +284 -0
- package/dist/index.d.cts +114 -0
- package/dist/index.d.ts +114 -0
- package/dist/index.global.js +17042 -0
- package/dist/index.js +249 -0
- package/package.json +45 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
// src/internal/index.ts
|
|
2
|
+
var context = {
|
|
3
|
+
appContext: null
|
|
4
|
+
};
|
|
5
|
+
var ScriptsInjectionKey = Symbol("OverlayScripts");
|
|
6
|
+
var InstancesInjectionKey = Symbol("OverlayInstances");
|
|
7
|
+
|
|
8
|
+
// src/composable/usePrograms.ts
|
|
9
|
+
import { getCurrentInstance, inject, onMounted, provide } from "vue-demi";
|
|
10
|
+
import { useVModel } from "@vueuse/core";
|
|
11
|
+
import { delay, noop } from "@overlastic/core";
|
|
12
|
+
function usePrograms(options = {}) {
|
|
13
|
+
const { duration = 0, immediate = true, model = "visible", automatic = true } = options;
|
|
14
|
+
const overlay = inject(ScriptsInjectionKey, useDeclarative(model, options));
|
|
15
|
+
const dec = Reflect.get(overlay, "in_dec");
|
|
16
|
+
const { visible, deferred, vanish } = overlay;
|
|
17
|
+
async function destroy() {
|
|
18
|
+
visible.value = false;
|
|
19
|
+
await delay(duration);
|
|
20
|
+
vanish == null ? void 0 : vanish();
|
|
21
|
+
return Promise.resolve();
|
|
22
|
+
}
|
|
23
|
+
if (!dec && automatic)
|
|
24
|
+
deferred == null ? void 0 : deferred.then(destroy).catch(destroy);
|
|
25
|
+
if (!dec && immediate)
|
|
26
|
+
onMounted(() => visible.value = true);
|
|
27
|
+
provide(ScriptsInjectionKey, null);
|
|
28
|
+
return overlay;
|
|
29
|
+
}
|
|
30
|
+
function useDeclarative(model, options = {}) {
|
|
31
|
+
const { reject = "reject", resolve = "resolve" } = options.events || {};
|
|
32
|
+
const instance = getCurrentInstance();
|
|
33
|
+
if (!instance)
|
|
34
|
+
throw new Error("Please use usePrograms in component setup");
|
|
35
|
+
const visible = useVModel(instance.props, model, instance.emit, { passive: true });
|
|
36
|
+
const _reject = (value) => {
|
|
37
|
+
instance == null ? void 0 : instance.emit(reject, value);
|
|
38
|
+
visible.value = false;
|
|
39
|
+
};
|
|
40
|
+
const _resolve = (value) => {
|
|
41
|
+
instance == null ? void 0 : instance.emit(resolve, value);
|
|
42
|
+
visible.value = false;
|
|
43
|
+
};
|
|
44
|
+
return {
|
|
45
|
+
reject: _reject,
|
|
46
|
+
resolve: _resolve,
|
|
47
|
+
vanish: noop,
|
|
48
|
+
visible,
|
|
49
|
+
in_dec: true
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// src/composable/useScripts.ts
|
|
54
|
+
import { ref } from "vue-demi";
|
|
55
|
+
function useScripts(options) {
|
|
56
|
+
const { reject: _reject } = options.deferred || {};
|
|
57
|
+
const { vanish: _vanish } = options;
|
|
58
|
+
const visible = ref(false);
|
|
59
|
+
function vanish() {
|
|
60
|
+
_vanish == null ? void 0 : _vanish();
|
|
61
|
+
_reject == null ? void 0 : _reject();
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
resolve: options.deferred.resolve,
|
|
65
|
+
reject: options.deferred.reject,
|
|
66
|
+
deferred: options.deferred,
|
|
67
|
+
visible,
|
|
68
|
+
vanish
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// src/composable/useOverlayHolder.ts
|
|
73
|
+
import { Teleport, defineComponent, h, provide as provide2, ref as ref2 } from "vue-demi";
|
|
74
|
+
import { createDeferred, defineName } from "@overlastic/core";
|
|
75
|
+
import { pascalCase } from "pascal-case";
|
|
76
|
+
function useOverlayHolder(component, options = {}) {
|
|
77
|
+
const { callback, scripts, props, refresh } = useRefreshMetadata();
|
|
78
|
+
const name = defineName(options.id, options.autoIncrement);
|
|
79
|
+
function render() {
|
|
80
|
+
return h(
|
|
81
|
+
Teleport,
|
|
82
|
+
{ to: options.root || document.body, disabled: options.root === false },
|
|
83
|
+
h("div", { id: name }, [h(component, props.value)])
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
const Holder = defineComponent({
|
|
87
|
+
name: pascalCase(name),
|
|
88
|
+
setup() {
|
|
89
|
+
provide2(ScriptsInjectionKey, scripts);
|
|
90
|
+
return () => refresh.value ? render() : null;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
return [Holder, callback];
|
|
94
|
+
}
|
|
95
|
+
function useRefreshMetadata() {
|
|
96
|
+
const visible = ref2(false);
|
|
97
|
+
const refresh = ref2(false);
|
|
98
|
+
const props = ref2();
|
|
99
|
+
const scripts = { vanish, visible };
|
|
100
|
+
function vanish() {
|
|
101
|
+
refresh.value = false;
|
|
102
|
+
props.value = {};
|
|
103
|
+
scripts.reject();
|
|
104
|
+
}
|
|
105
|
+
function callback(_props) {
|
|
106
|
+
scripts.deferred = createDeferred();
|
|
107
|
+
scripts.resolve = scripts.deferred.resolve;
|
|
108
|
+
scripts.reject = scripts.deferred.reject;
|
|
109
|
+
props.value = _props;
|
|
110
|
+
refresh.value = true;
|
|
111
|
+
return scripts.deferred;
|
|
112
|
+
}
|
|
113
|
+
return { callback, scripts, props, refresh };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// src/composable/useOverlay.ts
|
|
117
|
+
import { createConstructor } from "@overlastic/core";
|
|
118
|
+
import { defineComponent as defineComponent2, h as h2, inject as inject2, provide as provide3 } from "vue";
|
|
119
|
+
import { pascalCase as pascalCase2 } from "pascal-case";
|
|
120
|
+
var { define } = createConstructor((Instance, props, options) => {
|
|
121
|
+
const { container, id, deferred, render, vanish: _vanish } = options;
|
|
122
|
+
const InstanceWithProvider = defineComponent2({
|
|
123
|
+
name: pascalCase2(id),
|
|
124
|
+
setup: () => {
|
|
125
|
+
const scripts = useScripts({ vanish, deferred });
|
|
126
|
+
provide3(ScriptsInjectionKey, scripts);
|
|
127
|
+
},
|
|
128
|
+
render: () => h2(Instance, props)
|
|
129
|
+
});
|
|
130
|
+
function vanish() {
|
|
131
|
+
_vanish(InstanceWithProvider);
|
|
132
|
+
container.remove();
|
|
133
|
+
}
|
|
134
|
+
render(Instance, props);
|
|
135
|
+
});
|
|
136
|
+
function useOverlay(Instance) {
|
|
137
|
+
const { render, vanish } = inject2(InstancesInjectionKey);
|
|
138
|
+
return define(Instance, { render, vanish });
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// src/define/constructor.ts
|
|
142
|
+
import { createConstructor as createConstructor2 } from "@overlastic/core";
|
|
143
|
+
import { pascalCase as pascalCase3 } from "pascal-case";
|
|
144
|
+
import { createApp, defineComponent as defineComponent3, h as h3, provide as provide4 } from "vue-demi";
|
|
145
|
+
|
|
146
|
+
// src/utils/index.ts
|
|
147
|
+
function inheritParent(app, appContext) {
|
|
148
|
+
var _a;
|
|
149
|
+
const parent = (appContext == null ? void 0 : appContext.app) || ((_a = context.appContext) == null ? void 0 : _a.app);
|
|
150
|
+
if (parent) {
|
|
151
|
+
app.config.globalProperties = parent.config.globalProperties;
|
|
152
|
+
Object.assign(app._context, parent._context);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// src/define/constructor.ts
|
|
157
|
+
var constructor = createConstructor2((Instance, props, options) => {
|
|
158
|
+
const { container, id, deferred, appContext } = options;
|
|
159
|
+
function vanish() {
|
|
160
|
+
app.unmount();
|
|
161
|
+
container.remove();
|
|
162
|
+
}
|
|
163
|
+
const InstanceWithProvider = defineComponent3({
|
|
164
|
+
name: pascalCase3(id),
|
|
165
|
+
setup: () => {
|
|
166
|
+
const scripts = useScripts({
|
|
167
|
+
vanish,
|
|
168
|
+
deferred
|
|
169
|
+
});
|
|
170
|
+
provide4(ScriptsInjectionKey, scripts);
|
|
171
|
+
},
|
|
172
|
+
render: () => h3(Instance, props)
|
|
173
|
+
});
|
|
174
|
+
const app = createApp(InstanceWithProvider);
|
|
175
|
+
inheritParent(app, appContext);
|
|
176
|
+
app.mount(container);
|
|
177
|
+
return vanish;
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
// src/define/index.ts
|
|
181
|
+
var defineOverlay = constructor.define;
|
|
182
|
+
var renderOverlay = constructor.render;
|
|
183
|
+
|
|
184
|
+
// src/components/index.ts
|
|
185
|
+
import { Fragment, defineComponent as defineComponent4, getCurrentInstance as getCurrentInstance2, h as h4, provide as provide5, ref as ref3 } from "vue-demi";
|
|
186
|
+
var Provider = defineComponent4({
|
|
187
|
+
setup(_, { slots }) {
|
|
188
|
+
const { appContext } = getCurrentInstance2();
|
|
189
|
+
context.appContext = appContext;
|
|
190
|
+
return () => {
|
|
191
|
+
var _a;
|
|
192
|
+
return (_a = slots.default) == null ? void 0 : _a.call(slots);
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
var Field = defineComponent4({
|
|
197
|
+
name: "Field",
|
|
198
|
+
props: {
|
|
199
|
+
is: {
|
|
200
|
+
type: [String, Number, Object],
|
|
201
|
+
default: ""
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
setup(props) {
|
|
205
|
+
return () => {
|
|
206
|
+
if (typeof props.is === "string" || typeof props.is === "number")
|
|
207
|
+
return props.is;
|
|
208
|
+
return props.is ? h4(props.is) : null;
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
var OverlaysProvider = defineComponent4({
|
|
213
|
+
setup(_, { slots }) {
|
|
214
|
+
const instances = ref3([]);
|
|
215
|
+
function render(Instance, props) {
|
|
216
|
+
instances.value.push({ Instance, props });
|
|
217
|
+
}
|
|
218
|
+
function vanish(instance) {
|
|
219
|
+
instances.value = instances.value.filter(({ Instance }) => Instance === instance);
|
|
220
|
+
}
|
|
221
|
+
provide5(InstancesInjectionKey, { render, vanish });
|
|
222
|
+
return () => {
|
|
223
|
+
var _a;
|
|
224
|
+
return h4(Fragment, [
|
|
225
|
+
...instances.value.map(({ Instance, props }, index) => h4(Instance, { ...props, key: index })),
|
|
226
|
+
(_a = slots.default) == null ? void 0 : _a.call(slots)
|
|
227
|
+
]);
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
// src/index.ts
|
|
233
|
+
function install(app) {
|
|
234
|
+
context.appContext = app._context;
|
|
235
|
+
}
|
|
236
|
+
var unoverlay = { install };
|
|
237
|
+
var src_default = unoverlay;
|
|
238
|
+
export {
|
|
239
|
+
Field,
|
|
240
|
+
OverlaysProvider,
|
|
241
|
+
Provider,
|
|
242
|
+
src_default as default,
|
|
243
|
+
defineOverlay,
|
|
244
|
+
install,
|
|
245
|
+
renderOverlay,
|
|
246
|
+
useOverlay,
|
|
247
|
+
useOverlayHolder,
|
|
248
|
+
usePrograms
|
|
249
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@overlastic/vue",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.4.7",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://github.com/hairyf/overlastic#readme",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/hairyf/overlastic.git"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/hairyf/overlastic/issues"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"unified",
|
|
16
|
+
"overlay",
|
|
17
|
+
"vue"
|
|
18
|
+
],
|
|
19
|
+
"main": "./dist/index.cjs",
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"jsdelivr": "./dist/index.global.js",
|
|
22
|
+
"linkDirectory": false
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist"
|
|
26
|
+
],
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@vueuse/core": "^10.9.0",
|
|
29
|
+
"pascal-case": "latest",
|
|
30
|
+
"vue": "^3.3.2",
|
|
31
|
+
"vue-demi": ">=0.14.7",
|
|
32
|
+
"@overlastic/core": "^0.4.3"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "tsup src/index.ts",
|
|
36
|
+
"lint": "eslint ."
|
|
37
|
+
},
|
|
38
|
+
"exports": {
|
|
39
|
+
".": {
|
|
40
|
+
"import": "./dist/index.js",
|
|
41
|
+
"require": "./dist/index.cjs"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"types": "./dist/index.d.ts"
|
|
45
|
+
}
|