@overlastic/vue2 0.4.4 → 0.5.0

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 CHANGED
@@ -1,23 +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
-
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 CHANGED
@@ -1,85 +1,83 @@
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
- ```
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
+ ### Step 1: Define Component
33
+
34
+ overlays is suitable for most components. Using useOverlayDefine can provide finer control over the component process.
35
+
36
+ ```vue
37
+ <!-- overlay.vue -->
38
+ <script>
39
+ import { useOverlayDefine } from '@overlastic/vue2'
40
+ export default {
41
+ mixins: [useOverlayDefine({ duration: 1000 })],
42
+ methods: {
43
+ onClick() {
44
+ // use this.$visible
45
+ // use this.$resolve or this.$reject
46
+ }
47
+ }
48
+ }
49
+ </script>
50
+
51
+ <template>
52
+ <div v-if="visible" @click="resolve(`${title}:confirmed`)">
53
+ {{ title }}
54
+ </div>
55
+ </template>
56
+ ```
57
+
58
+ ### Step 2: Create Overlay
59
+
60
+ You can use the `defineOverlay` method to convert the component into a modal dialog in Javascript / Typescript, which allows you to call it.
61
+
62
+ ```ts
63
+ import { defineOverlay } from '@overlastic/vue'
64
+ import OverlayComponent from './overlay.vue'
65
+
66
+ // Convert to imperative callback
67
+ const callback = defineOverlay(OverlayComponent)
68
+ // Call the component and get the value of the resolve callback
69
+ const value = await callback({ title: 'callbackOverlay' })
70
+ // value === "callbackOverlay:confirmed"
71
+ ```
72
+
73
+ You can also use `renderOverlay` to directly call the component and skip the `defineOverlay` method.
74
+
75
+ ```ts
76
+ import { renderOverlay } from '@overlastic/vue'
77
+ import OverlayComponent from './overlay.vue'
78
+
79
+ const value = await renderOverlay(OverlayComponent, {
80
+ title: 'useOverlayDefine'
81
+ })
82
+ // value === "useOverlayDefine:confirmed"
83
+ ```
package/dist/index.cjs CHANGED
@@ -35,7 +35,7 @@ __export(src_exports, {
35
35
  defineOverlay: () => defineOverlay,
36
36
  install: () => install,
37
37
  renderOverlay: () => renderOverlay,
38
- usePrograms: () => usePrograms
38
+ useOverlayDefine: () => useOverlayDefine
39
39
  });
40
40
  module.exports = __toCommonJS(src_exports);
41
41
 
@@ -46,7 +46,7 @@ var context = {
46
46
  };
47
47
  var ScriptsInjectionKey = "$overlay";
48
48
 
49
- // src/composable/createVisibleScripts.ts
49
+ // src/composable/create.ts
50
50
  var import_mitt = __toESM(require("mitt"), 1);
51
51
  function createVisibleScripts(options) {
52
52
  const { reject: _reject, resolve: _resolve } = options.deferred || {};
@@ -79,10 +79,10 @@ function createVisibleScripts(options) {
79
79
  };
80
80
  }
81
81
 
82
- // src/composable/usePrograms.ts
82
+ // src/composable/define.ts
83
83
  var import_core = require("@overlastic/core");
84
84
  var import_vue2 = __toESM(require("vue"), 1);
85
- function usePrograms(options = {}) {
85
+ function useOverlayDefine(options = {}) {
86
86
  const { duration = 0, immediate = true, model = "visible", automatic = true, events = {} } = options;
87
87
  events.reject = events.reject || "reject";
88
88
  events.resolve = events.resolve || "resolve";
@@ -141,14 +141,14 @@ var import_vue3 = __toESM(require("vue"), 1);
141
141
  var constructor = (0, import_core2.createConstructor)((Inst, props, options) => {
142
142
  const { container, id, deferred } = options;
143
143
  function vanish() {
144
- childApp.$destroy();
144
+ app.$destroy();
145
145
  container.remove();
146
146
  }
147
147
  const $overlay = createVisibleScripts({
148
148
  deferred,
149
149
  vanish
150
150
  });
151
- const childApp = new import_vue3.default({
151
+ const app = new import_vue3.default({
152
152
  name: (0, import_pascal_case.pascalCase)(id),
153
153
  parent: options.parent,
154
154
  provide: () => ({ $overlay }),
@@ -156,7 +156,7 @@ var constructor = (0, import_core2.createConstructor)((Inst, props, options) =>
156
156
  });
157
157
  const child = document.createElement("div");
158
158
  container.appendChild(child);
159
- childApp.$mount(child);
159
+ app.$mount(child);
160
160
  });
161
161
 
162
162
  // src/define/index.ts
@@ -175,10 +175,10 @@ var Field = {
175
175
  };
176
176
 
177
177
  // src/index.ts
178
- var install = (_ins, parent) => {
178
+ function install(_ins, parent) {
179
179
  if (parent)
180
180
  context.parent = parent;
181
- };
181
+ }
182
182
  var unoverlay = { install };
183
183
  var src_default = unoverlay;
184
184
  // Annotate the CommonJS export names for ESM import in node:
@@ -187,5 +187,5 @@ var src_default = unoverlay;
187
187
  defineOverlay,
188
188
  install,
189
189
  renderOverlay,
190
- usePrograms
190
+ useOverlayDefine
191
191
  });
package/dist/index.d.cts CHANGED
@@ -17,7 +17,7 @@ interface PromptifyEvents {
17
17
  */
18
18
  resolve?: string;
19
19
  }
20
- interface ProgramsOptions {
20
+ interface OverlayDefineOptions {
21
21
  /** duration duration to avoid premature destruction of components */
22
22
  duration?: number;
23
23
  /** whether to set visible to true immediately */
@@ -39,7 +39,7 @@ interface ProgramsOptions {
39
39
  */
40
40
  automatic?: boolean;
41
41
  }
42
- declare function usePrograms(options?: ProgramsOptions): vue_types_vue.ExtendedVue<Vue__default, {
42
+ declare function useOverlayDefine(options?: OverlayDefineOptions): vue_types_vue.ExtendedVue<Vue__default, {
43
43
  runtime_visible: boolean;
44
44
  } | {
45
45
  runtime_visible?: undefined;
@@ -63,7 +63,7 @@ declare const renderOverlay: <Props, Resolved = void>(instance: Vue.Component, p
63
63
 
64
64
  declare const Field: Component;
65
65
 
66
- declare const install: (_ins: any, parent: any) => void;
66
+ declare function install(_ins: any, parent: any): void;
67
67
  declare const unoverlay: PluginObject<Vue__default>;
68
68
 
69
- export { Field, type ProgramsOptions, unoverlay as default, defineOverlay, install, renderOverlay, usePrograms };
69
+ export { Field, type OverlayDefineOptions, unoverlay as default, defineOverlay, install, renderOverlay, useOverlayDefine };
package/dist/index.d.ts CHANGED
@@ -17,7 +17,7 @@ interface PromptifyEvents {
17
17
  */
18
18
  resolve?: string;
19
19
  }
20
- interface ProgramsOptions {
20
+ interface OverlayDefineOptions {
21
21
  /** duration duration to avoid premature destruction of components */
22
22
  duration?: number;
23
23
  /** whether to set visible to true immediately */
@@ -39,7 +39,7 @@ interface ProgramsOptions {
39
39
  */
40
40
  automatic?: boolean;
41
41
  }
42
- declare function usePrograms(options?: ProgramsOptions): vue_types_vue.ExtendedVue<Vue__default, {
42
+ declare function useOverlayDefine(options?: OverlayDefineOptions): vue_types_vue.ExtendedVue<Vue__default, {
43
43
  runtime_visible: boolean;
44
44
  } | {
45
45
  runtime_visible?: undefined;
@@ -63,7 +63,7 @@ declare const renderOverlay: <Props, Resolved = void>(instance: Vue.Component, p
63
63
 
64
64
  declare const Field: Component;
65
65
 
66
- declare const install: (_ins: any, parent: any) => void;
66
+ declare function install(_ins: any, parent: any): void;
67
67
  declare const unoverlay: PluginObject<Vue__default>;
68
68
 
69
- export { Field, type ProgramsOptions, unoverlay as default, defineOverlay, install, renderOverlay, usePrograms };
69
+ export { Field, type OverlayDefineOptions, unoverlay as default, defineOverlay, install, renderOverlay, useOverlayDefine };
@@ -26,7 +26,7 @@ var OverlaysVue = (() => {
26
26
  defineOverlay: () => defineOverlay,
27
27
  install: () => install,
28
28
  renderOverlay: () => renderOverlay,
29
- usePrograms: () => usePrograms
29
+ useOverlayDefine: () => useOverlayDefine
30
30
  });
31
31
 
32
32
  // ../../node_modules/.pnpm/vue@2.6.0/node_modules/vue/dist/vue.runtime.esm.js
@@ -6068,7 +6068,7 @@ var OverlaysVue = (() => {
6068
6068
  } };
6069
6069
  }
6070
6070
 
6071
- // src/composable/createVisibleScripts.ts
6071
+ // src/composable/create.ts
6072
6072
  function createVisibleScripts(options) {
6073
6073
  const { reject: _reject, resolve: _resolve } = options.deferred || {};
6074
6074
  const { vanish: _vanish } = options;
@@ -6164,14 +6164,15 @@ var OverlaysVue = (() => {
6164
6164
  }
6165
6165
 
6166
6166
  // ../@core/src/constructor.ts
6167
- function createConstructor(mount) {
6168
- function define(instance, options) {
6169
- function executor(props2, options2) {
6167
+ function createConstructor(mount, options = {}) {
6168
+ const { container: globalContainer } = options;
6169
+ function define(instance, options2) {
6170
+ function executor(props2, options3) {
6170
6171
  const deferred = createDeferred();
6171
- const name = defineName(options2.id, options2.autoIncrement);
6172
- const index2 = getIndex(options2.id);
6173
- const container = defineGlobalElement(name, options2.root);
6174
- mount(instance, props2, Object.assign(options2, {
6172
+ const name = defineName(options3.id, options3.autoIncrement);
6173
+ const index2 = getIndex(options3.id);
6174
+ const container = globalContainer ? defineGlobalElement(name, options3.root) : document.body;
6175
+ mount(instance, props2, Object.assign(options3, {
6175
6176
  position: context2.position,
6176
6177
  id: name,
6177
6178
  deferred,
@@ -6181,21 +6182,21 @@ var OverlaysVue = (() => {
6181
6182
  return deferred;
6182
6183
  }
6183
6184
  let inst;
6184
- function only(props2, options2) {
6185
+ function only(props2, options3) {
6185
6186
  if (!inst) {
6186
- inst = executor(props2, options2);
6187
+ inst = executor(props2, options3);
6187
6188
  inst.finally(() => inst = void 0);
6188
6189
  }
6189
6190
  return inst;
6190
6191
  }
6191
6192
  function caller(props2, overrides) {
6192
- const opts = { ...options, ...overrides };
6193
+ const opts = { ...options2, ...overrides };
6193
6194
  return opts.only ? only(props2, opts) : executor(props2, opts);
6194
6195
  }
6195
6196
  return caller;
6196
6197
  }
6197
- function render4(instance, props2, options) {
6198
- return define(instance, options)(props2);
6198
+ function render4(instance, props2, options2) {
6199
+ return define(instance, options2)(props2);
6199
6200
  }
6200
6201
  return { define, render: render4 };
6201
6202
  }
@@ -6206,8 +6207,8 @@ var OverlaysVue = (() => {
6206
6207
  return new Promise((resolve) => setTimeout(resolve, milliseconds));
6207
6208
  }
6208
6209
 
6209
- // src/composable/usePrograms.ts
6210
- function usePrograms(options = {}) {
6210
+ // src/composable/define.ts
6211
+ function useOverlayDefine(options = {}) {
6211
6212
  const { duration = 0, immediate = true, model = "visible", automatic = true, events: events2 = {} } = options;
6212
6213
  events2.reject = events2.reject || "reject";
6213
6214
  events2.resolve = events2.resolve || "resolve";
@@ -6323,14 +6324,14 @@ var OverlaysVue = (() => {
6323
6324
  var constructor = createConstructor((Inst, props2, options) => {
6324
6325
  const { container, id, deferred } = options;
6325
6326
  function vanish() {
6326
- childApp.$destroy();
6327
+ app.$destroy();
6327
6328
  container.remove();
6328
6329
  }
6329
6330
  const $overlay = createVisibleScripts({
6330
6331
  deferred,
6331
6332
  vanish
6332
6333
  });
6333
- const childApp = new vue_runtime_esm_default({
6334
+ const app = new vue_runtime_esm_default({
6334
6335
  name: pascalCase(id),
6335
6336
  parent: options.parent,
6336
6337
  provide: () => ({ $overlay }),
@@ -6338,7 +6339,7 @@ var OverlaysVue = (() => {
6338
6339
  });
6339
6340
  const child = document.createElement("div");
6340
6341
  container.appendChild(child);
6341
- childApp.$mount(child);
6342
+ app.$mount(child);
6342
6343
  });
6343
6344
 
6344
6345
  // src/define/index.ts
@@ -6357,10 +6358,10 @@ var OverlaysVue = (() => {
6357
6358
  };
6358
6359
 
6359
6360
  // src/index.ts
6360
- var install = (_ins, parent) => {
6361
+ function install(_ins, parent) {
6361
6362
  if (parent)
6362
6363
  context.parent = parent;
6363
- };
6364
+ }
6364
6365
  var unoverlay = { install };
6365
6366
  var src_default = unoverlay;
6366
6367
  return __toCommonJS(src_exports);
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ var context = {
5
5
  };
6
6
  var ScriptsInjectionKey = "$overlay";
7
7
 
8
- // src/composable/createVisibleScripts.ts
8
+ // src/composable/create.ts
9
9
  import mitt from "mitt";
10
10
  function createVisibleScripts(options) {
11
11
  const { reject: _reject, resolve: _resolve } = options.deferred || {};
@@ -38,10 +38,10 @@ function createVisibleScripts(options) {
38
38
  };
39
39
  }
40
40
 
41
- // src/composable/usePrograms.ts
41
+ // src/composable/define.ts
42
42
  import { delay } from "@overlastic/core";
43
43
  import Vue2 from "vue";
44
- function usePrograms(options = {}) {
44
+ function useOverlayDefine(options = {}) {
45
45
  const { duration = 0, immediate = true, model = "visible", automatic = true, events = {} } = options;
46
46
  events.reject = events.reject || "reject";
47
47
  events.resolve = events.resolve || "resolve";
@@ -100,14 +100,14 @@ import Vue3 from "vue";
100
100
  var constructor = createConstructor((Inst, props, options) => {
101
101
  const { container, id, deferred } = options;
102
102
  function vanish() {
103
- childApp.$destroy();
103
+ app.$destroy();
104
104
  container.remove();
105
105
  }
106
106
  const $overlay = createVisibleScripts({
107
107
  deferred,
108
108
  vanish
109
109
  });
110
- const childApp = new Vue3({
110
+ const app = new Vue3({
111
111
  name: pascalCase(id),
112
112
  parent: options.parent,
113
113
  provide: () => ({ $overlay }),
@@ -115,7 +115,7 @@ var constructor = createConstructor((Inst, props, options) => {
115
115
  });
116
116
  const child = document.createElement("div");
117
117
  container.appendChild(child);
118
- childApp.$mount(child);
118
+ app.$mount(child);
119
119
  });
120
120
 
121
121
  // src/define/index.ts
@@ -134,10 +134,10 @@ var Field = {
134
134
  };
135
135
 
136
136
  // src/index.ts
137
- var install = (_ins, parent) => {
137
+ function install(_ins, parent) {
138
138
  if (parent)
139
139
  context.parent = parent;
140
- };
140
+ }
141
141
  var unoverlay = { install };
142
142
  var src_default = unoverlay;
143
143
  export {
@@ -146,5 +146,5 @@ export {
146
146
  defineOverlay,
147
147
  install,
148
148
  renderOverlay,
149
- usePrograms
149
+ useOverlayDefine
150
150
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@overlastic/vue2",
3
3
  "type": "module",
4
- "version": "0.4.4",
4
+ "version": "0.5.0",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/hairyf/overlastic#readme",
7
7
  "repository": {
@@ -30,7 +30,7 @@
30
30
  "dependencies": {
31
31
  "mitt": "^3.0.1",
32
32
  "pascal-case": "3.1.2",
33
- "@overlastic/core": "^0.4.3"
33
+ "@overlastic/core": "^0.5.0"
34
34
  },
35
35
  "devDependencies": {
36
36
  "vue": "^2.6"