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