@overlastic/vue2 0.4.4

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/index.js ADDED
@@ -0,0 +1,150 @@
1
+ // src/internal/index.ts
2
+ import Vue from "vue";
3
+ var context = {
4
+ parent: Vue
5
+ };
6
+ var ScriptsInjectionKey = "$overlay";
7
+
8
+ // src/composable/createVisibleScripts.ts
9
+ import mitt from "mitt";
10
+ function createVisibleScripts(options) {
11
+ const { reject: _reject, resolve: _resolve } = options.deferred || {};
12
+ const { vanish: _vanish } = options;
13
+ const { on, off, emit } = mitt();
14
+ function reject(value) {
15
+ emit("reject", value);
16
+ _reject == null ? void 0 : _reject(value);
17
+ }
18
+ function resolve(value) {
19
+ var _a;
20
+ (_a = options.deferred) == null ? void 0 : _a.resolve(value);
21
+ emit("resolve", value);
22
+ return _resolve == null ? void 0 : _resolve(value);
23
+ }
24
+ function vanish() {
25
+ _vanish == null ? void 0 : _vanish();
26
+ reject();
27
+ off("*");
28
+ }
29
+ if (options.deferred) {
30
+ options.deferred.resolve = resolve;
31
+ options.deferred.reject = reject;
32
+ }
33
+ return {
34
+ resolve,
35
+ reject,
36
+ vanish,
37
+ on
38
+ };
39
+ }
40
+
41
+ // src/composable/usePrograms.ts
42
+ import { delay } from "@overlastic/core";
43
+ import Vue2 from "vue";
44
+ function usePrograms(options = {}) {
45
+ const { duration = 0, immediate = true, model = "visible", automatic = true, events = {} } = options;
46
+ events.reject = events.reject || "reject";
47
+ events.resolve = events.resolve || "resolve";
48
+ const mixinOptions = Vue2.extend({
49
+ inject: [ScriptsInjectionKey],
50
+ model: {
51
+ prop: model,
52
+ event: "change"
53
+ },
54
+ props: { [model]: Boolean },
55
+ data() {
56
+ if (this.$overlay)
57
+ return { runtime_visible: false };
58
+ return {};
59
+ },
60
+ computed: {
61
+ $visible: {
62
+ set(value) {
63
+ this.$overlay ? this.runtime_visible = value : this.$emit("change", value);
64
+ if (value === false && automatic)
65
+ delay(duration).then(this.$overlay.vanish);
66
+ },
67
+ get() {
68
+ return this.$overlay ? this.runtime_visible : this[model];
69
+ }
70
+ }
71
+ },
72
+ created() {
73
+ if (immediate)
74
+ this.$visible = true;
75
+ if (this.$overlay)
76
+ this.$overlay.on("*", this.$runtime_effect);
77
+ },
78
+ methods: {
79
+ async $runtime_effect(type, value) {
80
+ this.$emit(events[type], value);
81
+ this.$visible = false;
82
+ },
83
+ async $resolve(value) {
84
+ var _a;
85
+ (_a = this.$overlay) == null ? void 0 : _a.resolve(value);
86
+ },
87
+ async $reject(value) {
88
+ var _a;
89
+ (_a = this.$overlay) == null ? void 0 : _a.reject(value);
90
+ }
91
+ }
92
+ });
93
+ return mixinOptions;
94
+ }
95
+
96
+ // src/define/constructor.ts
97
+ import { createConstructor } from "@overlastic/core";
98
+ import { pascalCase } from "pascal-case";
99
+ import Vue3 from "vue";
100
+ var constructor = createConstructor((Inst, props, options) => {
101
+ const { container, id, deferred } = options;
102
+ function vanish() {
103
+ childApp.$destroy();
104
+ container.remove();
105
+ }
106
+ const $overlay = createVisibleScripts({
107
+ deferred,
108
+ vanish
109
+ });
110
+ const childApp = new Vue3({
111
+ name: pascalCase(id),
112
+ parent: options.parent,
113
+ provide: () => ({ $overlay }),
114
+ render: (h) => h(Inst, { props })
115
+ });
116
+ const child = document.createElement("div");
117
+ container.appendChild(child);
118
+ childApp.$mount(child);
119
+ });
120
+
121
+ // src/define/index.ts
122
+ var defineOverlay = constructor.define;
123
+ var renderOverlay = constructor.render;
124
+
125
+ // src/components/index.ts
126
+ var Field = {
127
+ name: "Field",
128
+ props: {
129
+ value: [String, Object]
130
+ },
131
+ render(h) {
132
+ return h(this.value);
133
+ }
134
+ };
135
+
136
+ // src/index.ts
137
+ var install = (_ins, parent) => {
138
+ if (parent)
139
+ context.parent = parent;
140
+ };
141
+ var unoverlay = { install };
142
+ var src_default = unoverlay;
143
+ export {
144
+ Field,
145
+ src_default as default,
146
+ defineOverlay,
147
+ install,
148
+ renderOverlay,
149
+ usePrograms
150
+ };
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@overlastic/vue2",
3
+ "type": "module",
4
+ "version": "0.4.4",
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
+ "peerDependencies": {
28
+ "vue": "^2.6"
29
+ },
30
+ "dependencies": {
31
+ "mitt": "^3.0.1",
32
+ "pascal-case": "3.1.2",
33
+ "@overlastic/core": "^0.4.3"
34
+ },
35
+ "devDependencies": {
36
+ "vue": "^2.6"
37
+ },
38
+ "scripts": {
39
+ "build": "tsup src/index.ts",
40
+ "lint": "eslint ."
41
+ },
42
+ "exports": {
43
+ ".": {
44
+ "import": "./dist/index.js",
45
+ "require": "./dist/index.cjs"
46
+ }
47
+ },
48
+ "types": "./dist/index.d.ts"
49
+ }