@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/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022-PRESENT Hairyf<https://github.com/hairyf>
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.
22
+
23
+
package/README.md ADDED
@@ -0,0 +1,85 @@
1
+ # Getting Started
2
+
3
+ > overlays only supports Vue3 | Vue2 Composition-api
4
+
5
+ ## Install
6
+
7
+ With pnpm:
8
+ ```sh
9
+ pnpm add @overlastic/vue
10
+ ```
11
+
12
+ With yarn:
13
+ ```sh
14
+ yarn add @overlastic/vue
15
+ ```
16
+
17
+ ## Global
18
+
19
+ You can register overlays globally, which will inherit the application context for all popups.
20
+
21
+ ```ts
22
+ // main.js
23
+ import Vue from 'vue'
24
+ import unoverlay from '@overlastic/vue'
25
+
26
+ const app = new Vue({})
27
+ app.use(unoverlay)
28
+ ```
29
+
30
+ ## Usage
31
+
32
+
33
+
34
+ ### Step 1: Define Component
35
+
36
+ overlays is suitable for most components. Using usePrograms can provide finer control over the component process.
37
+
38
+ ```vue
39
+ <!-- overlay.vue -->
40
+ <script>
41
+ import { usePrograms } from '@overlastic/vue2'
42
+ export default {
43
+ mixins: [usePrograms({ duration: 1000 })],
44
+ methods: {
45
+ onClick() {
46
+ // use this.$visible
47
+ // use this.$resolve or this.$reject
48
+ }
49
+ }
50
+ }
51
+ </script>
52
+
53
+ <template>
54
+ <div v-if="visible" @click="resolve(`${title}:confirmed`)">
55
+ {{ title }}
56
+ </div>
57
+ </template>
58
+ ```
59
+
60
+ ### Step 2: Create Overlay
61
+
62
+ You can use the `defineOverlay` method to convert the component into a modal dialog in Javascript / Typescript, which allows you to call it.
63
+
64
+ ```ts
65
+ import { defineOverlay } from '@overlastic/vue'
66
+ import OverlayComponent from './overlay.vue'
67
+
68
+ // Convert to imperative callback
69
+ const callback = defineOverlay(OverlayComponent)
70
+ // Call the component and get the value of the resolve callback
71
+ const value = await callback({ title: 'callbackOverlay' })
72
+ // value === "callbackOverlay:confirmed"
73
+ ```
74
+
75
+ You can also use `renderOverlay` to directly call the component and skip the `defineOverlay` method.
76
+
77
+ ```ts
78
+ import { renderOverlay } from '@overlastic/vue'
79
+ import OverlayComponent from './overlay.vue'
80
+
81
+ const value = await renderOverlay(OverlayComponent, {
82
+ title: 'usePrograms'
83
+ })
84
+ // value === "usePrograms:confirmed"
85
+ ```
package/dist/index.cjs ADDED
@@ -0,0 +1,191 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ Field: () => Field,
34
+ default: () => src_default,
35
+ defineOverlay: () => defineOverlay,
36
+ install: () => install,
37
+ renderOverlay: () => renderOverlay,
38
+ usePrograms: () => usePrograms
39
+ });
40
+ module.exports = __toCommonJS(src_exports);
41
+
42
+ // src/internal/index.ts
43
+ var import_vue = __toESM(require("vue"), 1);
44
+ var context = {
45
+ parent: import_vue.default
46
+ };
47
+ var ScriptsInjectionKey = "$overlay";
48
+
49
+ // src/composable/createVisibleScripts.ts
50
+ var import_mitt = __toESM(require("mitt"), 1);
51
+ function createVisibleScripts(options) {
52
+ const { reject: _reject, resolve: _resolve } = options.deferred || {};
53
+ const { vanish: _vanish } = options;
54
+ const { on, off, emit } = (0, import_mitt.default)();
55
+ function reject(value) {
56
+ emit("reject", value);
57
+ _reject == null ? void 0 : _reject(value);
58
+ }
59
+ function resolve(value) {
60
+ var _a;
61
+ (_a = options.deferred) == null ? void 0 : _a.resolve(value);
62
+ emit("resolve", value);
63
+ return _resolve == null ? void 0 : _resolve(value);
64
+ }
65
+ function vanish() {
66
+ _vanish == null ? void 0 : _vanish();
67
+ reject();
68
+ off("*");
69
+ }
70
+ if (options.deferred) {
71
+ options.deferred.resolve = resolve;
72
+ options.deferred.reject = reject;
73
+ }
74
+ return {
75
+ resolve,
76
+ reject,
77
+ vanish,
78
+ on
79
+ };
80
+ }
81
+
82
+ // src/composable/usePrograms.ts
83
+ var import_core = require("@overlastic/core");
84
+ var import_vue2 = __toESM(require("vue"), 1);
85
+ function usePrograms(options = {}) {
86
+ const { duration = 0, immediate = true, model = "visible", automatic = true, events = {} } = options;
87
+ events.reject = events.reject || "reject";
88
+ events.resolve = events.resolve || "resolve";
89
+ const mixinOptions = import_vue2.default.extend({
90
+ inject: [ScriptsInjectionKey],
91
+ model: {
92
+ prop: model,
93
+ event: "change"
94
+ },
95
+ props: { [model]: Boolean },
96
+ data() {
97
+ if (this.$overlay)
98
+ return { runtime_visible: false };
99
+ return {};
100
+ },
101
+ computed: {
102
+ $visible: {
103
+ set(value) {
104
+ this.$overlay ? this.runtime_visible = value : this.$emit("change", value);
105
+ if (value === false && automatic)
106
+ (0, import_core.delay)(duration).then(this.$overlay.vanish);
107
+ },
108
+ get() {
109
+ return this.$overlay ? this.runtime_visible : this[model];
110
+ }
111
+ }
112
+ },
113
+ created() {
114
+ if (immediate)
115
+ this.$visible = true;
116
+ if (this.$overlay)
117
+ this.$overlay.on("*", this.$runtime_effect);
118
+ },
119
+ methods: {
120
+ async $runtime_effect(type, value) {
121
+ this.$emit(events[type], value);
122
+ this.$visible = false;
123
+ },
124
+ async $resolve(value) {
125
+ var _a;
126
+ (_a = this.$overlay) == null ? void 0 : _a.resolve(value);
127
+ },
128
+ async $reject(value) {
129
+ var _a;
130
+ (_a = this.$overlay) == null ? void 0 : _a.reject(value);
131
+ }
132
+ }
133
+ });
134
+ return mixinOptions;
135
+ }
136
+
137
+ // src/define/constructor.ts
138
+ var import_core2 = require("@overlastic/core");
139
+ var import_pascal_case = require("pascal-case");
140
+ var import_vue3 = __toESM(require("vue"), 1);
141
+ var constructor = (0, import_core2.createConstructor)((Inst, props, options) => {
142
+ const { container, id, deferred } = options;
143
+ function vanish() {
144
+ childApp.$destroy();
145
+ container.remove();
146
+ }
147
+ const $overlay = createVisibleScripts({
148
+ deferred,
149
+ vanish
150
+ });
151
+ const childApp = new import_vue3.default({
152
+ name: (0, import_pascal_case.pascalCase)(id),
153
+ parent: options.parent,
154
+ provide: () => ({ $overlay }),
155
+ render: (h) => h(Inst, { props })
156
+ });
157
+ const child = document.createElement("div");
158
+ container.appendChild(child);
159
+ childApp.$mount(child);
160
+ });
161
+
162
+ // src/define/index.ts
163
+ var defineOverlay = constructor.define;
164
+ var renderOverlay = constructor.render;
165
+
166
+ // src/components/index.ts
167
+ var Field = {
168
+ name: "Field",
169
+ props: {
170
+ value: [String, Object]
171
+ },
172
+ render(h) {
173
+ return h(this.value);
174
+ }
175
+ };
176
+
177
+ // src/index.ts
178
+ var install = (_ins, parent) => {
179
+ if (parent)
180
+ context.parent = parent;
181
+ };
182
+ var unoverlay = { install };
183
+ var src_default = unoverlay;
184
+ // Annotate the CommonJS export names for ESM import in node:
185
+ 0 && (module.exports = {
186
+ Field,
187
+ defineOverlay,
188
+ install,
189
+ renderOverlay,
190
+ usePrograms
191
+ });
@@ -0,0 +1,69 @@
1
+ import * as Vue from 'vue';
2
+ import Vue__default, { Component, PluginObject } from 'vue';
3
+ import * as vue_types_vue from 'vue/types/vue';
4
+ import * as _overlastic_core from '@overlastic/core';
5
+
6
+ interface PromptifyEvents {
7
+ /**
8
+ * reject event name used by the template
9
+ *
10
+ * @default 'reject'
11
+ */
12
+ reject?: string;
13
+ /**
14
+ * resolve event name used by the template
15
+ *
16
+ * @default 'resolve'
17
+ */
18
+ resolve?: string;
19
+ }
20
+ interface ProgramsOptions {
21
+ /** duration duration to avoid premature destruction of components */
22
+ duration?: number;
23
+ /** whether to set visible to true immediately */
24
+ immediate?: boolean;
25
+ /**
26
+ * v-model fields used by template
27
+ *
28
+ * @default 'visible'
29
+ */
30
+ model?: string;
31
+ /**
32
+ * template use event name
33
+ */
34
+ events?: PromptifyEvents;
35
+ /**
36
+ * whether to automatically handle components based on visible and duration
37
+ *
38
+ * @default true
39
+ */
40
+ automatic?: boolean;
41
+ }
42
+ declare function usePrograms(options?: ProgramsOptions): vue_types_vue.ExtendedVue<Vue__default, {
43
+ runtime_visible: boolean;
44
+ } | {
45
+ runtime_visible?: undefined;
46
+ }, {
47
+ $runtime_effect(type: 'reject' | 'resolve', value: any): Promise<void>;
48
+ $resolve(value: any): Promise<void>;
49
+ $reject(value: any): Promise<void>;
50
+ }, {
51
+ $visible: any;
52
+ }, {
53
+ [x: string]: any;
54
+ }>;
55
+
56
+ interface VMountOptions {
57
+ /** current app context */
58
+ parent?: Vue__default;
59
+ }
60
+
61
+ declare const defineOverlay: <Props, Resolved = void>(instance: Vue.Component, options?: _overlastic_core.MountOptions<VMountOptions> | undefined) => _overlastic_core.ImperativeOverlay<Props, Resolved, VMountOptions>;
62
+ declare const renderOverlay: <Props, Resolved = void>(instance: Vue.Component, props?: Props | undefined, options?: _overlastic_core.MountOptions<VMountOptions> | undefined) => Promise<Resolved>;
63
+
64
+ declare const Field: Component;
65
+
66
+ declare const install: (_ins: any, parent: any) => void;
67
+ declare const unoverlay: PluginObject<Vue__default>;
68
+
69
+ export { Field, type ProgramsOptions, unoverlay as default, defineOverlay, install, renderOverlay, usePrograms };
@@ -0,0 +1,69 @@
1
+ import * as Vue from 'vue';
2
+ import Vue__default, { Component, PluginObject } from 'vue';
3
+ import * as vue_types_vue from 'vue/types/vue';
4
+ import * as _overlastic_core from '@overlastic/core';
5
+
6
+ interface PromptifyEvents {
7
+ /**
8
+ * reject event name used by the template
9
+ *
10
+ * @default 'reject'
11
+ */
12
+ reject?: string;
13
+ /**
14
+ * resolve event name used by the template
15
+ *
16
+ * @default 'resolve'
17
+ */
18
+ resolve?: string;
19
+ }
20
+ interface ProgramsOptions {
21
+ /** duration duration to avoid premature destruction of components */
22
+ duration?: number;
23
+ /** whether to set visible to true immediately */
24
+ immediate?: boolean;
25
+ /**
26
+ * v-model fields used by template
27
+ *
28
+ * @default 'visible'
29
+ */
30
+ model?: string;
31
+ /**
32
+ * template use event name
33
+ */
34
+ events?: PromptifyEvents;
35
+ /**
36
+ * whether to automatically handle components based on visible and duration
37
+ *
38
+ * @default true
39
+ */
40
+ automatic?: boolean;
41
+ }
42
+ declare function usePrograms(options?: ProgramsOptions): vue_types_vue.ExtendedVue<Vue__default, {
43
+ runtime_visible: boolean;
44
+ } | {
45
+ runtime_visible?: undefined;
46
+ }, {
47
+ $runtime_effect(type: 'reject' | 'resolve', value: any): Promise<void>;
48
+ $resolve(value: any): Promise<void>;
49
+ $reject(value: any): Promise<void>;
50
+ }, {
51
+ $visible: any;
52
+ }, {
53
+ [x: string]: any;
54
+ }>;
55
+
56
+ interface VMountOptions {
57
+ /** current app context */
58
+ parent?: Vue__default;
59
+ }
60
+
61
+ declare const defineOverlay: <Props, Resolved = void>(instance: Vue.Component, options?: _overlastic_core.MountOptions<VMountOptions> | undefined) => _overlastic_core.ImperativeOverlay<Props, Resolved, VMountOptions>;
62
+ declare const renderOverlay: <Props, Resolved = void>(instance: Vue.Component, props?: Props | undefined, options?: _overlastic_core.MountOptions<VMountOptions> | undefined) => Promise<Resolved>;
63
+
64
+ declare const Field: Component;
65
+
66
+ declare const install: (_ins: any, parent: any) => void;
67
+ declare const unoverlay: PluginObject<Vue__default>;
68
+
69
+ export { Field, type ProgramsOptions, unoverlay as default, defineOverlay, install, renderOverlay, usePrograms };