@overlastic/vanilla 0.4.3 → 0.5.1
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 -23
- package/README.md +29 -101
- package/dist/index.cjs +4 -4
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.global.js +16 -15
- package/dist/index.js +3 -3
- package/package.json +2 -2
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,101 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
##
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const { resolve, reject, deferred } = usePrograms({
|
|
31
|
-
// Duration of overlays duration to avoid premature destruction of the component
|
|
32
|
-
duration: 1000,
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
// Add events that cause the overlays to end
|
|
36
|
-
element.onclick = function () {
|
|
37
|
-
resolve('ok')
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// Use setTimeout to wait for the element to be appended, then add a class name with animation
|
|
41
|
-
setTimeout(() => element.classList.add('show'))
|
|
42
|
-
// When the deferred is triggered, remove the displayed class name
|
|
43
|
-
deferred.finally(() => element.classList.remove('show'))
|
|
44
|
-
|
|
45
|
-
return element
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export default Component
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
### Step 2: Create Overlay
|
|
52
|
-
|
|
53
|
-
You can use the `defineOverlay` method to convert the component into a modal dialog in Javascript / Typescript, which allows you to call it.
|
|
54
|
-
|
|
55
|
-
```ts
|
|
56
|
-
import { defineOverlay } from '@overlastic/vanilla'
|
|
57
|
-
import Component from './overlay'
|
|
58
|
-
|
|
59
|
-
// Convert to imperative callback
|
|
60
|
-
const callback = defineOverlay(Component)
|
|
61
|
-
// Call the component and get the value of the resolve callback
|
|
62
|
-
const value = await callback({ title: 'callbackOverlay' })
|
|
63
|
-
// value === "callbackOverlay:confirmed"
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
You can also use `renderOverlay` to directly call the component and skip the `defineOverlay` method.
|
|
67
|
-
|
|
68
|
-
```ts
|
|
69
|
-
import { defineOverlay } from '@overlastic/vanilla'
|
|
70
|
-
import Component from './overlay'
|
|
71
|
-
|
|
72
|
-
const value = await renderOverlay(Component, {
|
|
73
|
-
title: 'usePrograms'
|
|
74
|
-
})
|
|
75
|
-
// value === "usePrograms:confirmed"
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
## Custom Element
|
|
79
|
-
|
|
80
|
-
After mounting a custom element, you can pass in the corresponding custom element or name through 'defineOverlay' to use the custom element.
|
|
81
|
-
|
|
82
|
-
> You can use [lit](https://lit.dev/) Quickly build custom elements.
|
|
83
|
-
|
|
84
|
-
```ts
|
|
85
|
-
const callback1 = defineOverlay('my-custom-element')
|
|
86
|
-
|
|
87
|
-
callback1({/* props(attrs) */})
|
|
88
|
-
|
|
89
|
-
const CustomComponent = (props) => {
|
|
90
|
-
const customElement = document.createElement('my-custom-element')
|
|
91
|
-
|
|
92
|
-
const { resolve, reject } = usePrograms({
|
|
93
|
-
duration: 1000,
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
// ...
|
|
97
|
-
return customElement
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const callback2 = defineOverlay(CustomComponent)
|
|
101
|
-
```
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://overlastic.vercel.app/" target="blank">
|
|
3
|
+
<img src="https://github.com/hairyf/overlastic/raw/master/docs/public/circle.svg" width="120" alt="Nest Logo" />
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
A create modal | dialog | popup promise deferred library
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="https://www.npmjs.com/@overlastic/core"><img src="https://img.shields.io/npm/v/@overlastic/core.svg" alt="NPM Version" /></a>
|
|
13
|
+
<a href="https://www.npmjs.com/@overlastic/core"><img src="https://img.shields.io/npm/l/@overlastic/core.svg" alt="Package License" /></a>
|
|
14
|
+
<a href="https://www.npmjs.com/@overlastic/core"><img src="https://img.shields.io/npm/dm/@overlastic/core.svg" alt="NPM Downloads" /></a>
|
|
15
|
+
</p>
|
|
16
|
+
|
|
17
|
+
## Description
|
|
18
|
+
|
|
19
|
+
Create messages or dialog overlays using Overlastic in native HTML.
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
$ npm install --save @overlastic/vanilla
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Quick Start
|
|
28
|
+
|
|
29
|
+
[Overview & Tutorial](https://overlastic.vercel.app/en/vanilla/)
|
package/dist/index.cjs
CHANGED
|
@@ -22,7 +22,7 @@ var src_exports = {};
|
|
|
22
22
|
__export(src_exports, {
|
|
23
23
|
defineOverlay: () => defineOverlay,
|
|
24
24
|
renderOverlay: () => renderOverlay,
|
|
25
|
-
|
|
25
|
+
useOverlayDefine: () => useOverlayDefine
|
|
26
26
|
});
|
|
27
27
|
module.exports = __toCommonJS(src_exports);
|
|
28
28
|
|
|
@@ -82,8 +82,8 @@ function parseElement(component, props) {
|
|
|
82
82
|
var defineOverlay = constructor.define;
|
|
83
83
|
var renderOverlay = constructor.render;
|
|
84
84
|
|
|
85
|
-
// src/composable/
|
|
86
|
-
function
|
|
85
|
+
// src/composable/define.ts
|
|
86
|
+
function useOverlayDefine(options) {
|
|
87
87
|
const trigger = context.trigger;
|
|
88
88
|
if (!trigger)
|
|
89
89
|
throw new Error("Please execute in the overlays constructor");
|
|
@@ -94,5 +94,5 @@ function usePrograms(options) {
|
|
|
94
94
|
0 && (module.exports = {
|
|
95
95
|
defineOverlay,
|
|
96
96
|
renderOverlay,
|
|
97
|
-
|
|
97
|
+
useOverlayDefine
|
|
98
98
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -6,7 +6,7 @@ interface EFComponent<T = any> {
|
|
|
6
6
|
}
|
|
7
7
|
type ElementComponent = HTMLElement | EFComponent | string;
|
|
8
8
|
|
|
9
|
-
declare const defineOverlay: <Props, Resolved = void>(instance: ElementComponent, options?: _overlastic_core.GlobalMountOptions | undefined) => _overlastic_core.ImperativeOverlay<Props, Resolved,
|
|
9
|
+
declare const defineOverlay: <Props, Resolved = void>(instance: ElementComponent, options?: _overlastic_core.GlobalMountOptions | undefined) => _overlastic_core.ImperativeOverlay<Props, Resolved, unknown>;
|
|
10
10
|
declare const renderOverlay: <Props, Resolved = void>(instance: ElementComponent, props?: Props | undefined, options?: _overlastic_core.GlobalMountOptions | undefined) => Promise<Resolved>;
|
|
11
11
|
|
|
12
12
|
interface Context<T = void> {
|
|
@@ -16,10 +16,10 @@ interface Context<T = void> {
|
|
|
16
16
|
vanish: Function;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
interface
|
|
19
|
+
interface OverlayDefineOptions {
|
|
20
20
|
/** animation duration to avoid premature destruction of components */
|
|
21
21
|
duration?: number;
|
|
22
22
|
}
|
|
23
|
-
declare function
|
|
23
|
+
declare function useOverlayDefine(options?: OverlayDefineOptions): Context<void>;
|
|
24
24
|
|
|
25
|
-
export { type Context, type
|
|
25
|
+
export { type Context, type OverlayDefineOptions, defineOverlay, renderOverlay, useOverlayDefine };
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ interface EFComponent<T = any> {
|
|
|
6
6
|
}
|
|
7
7
|
type ElementComponent = HTMLElement | EFComponent | string;
|
|
8
8
|
|
|
9
|
-
declare const defineOverlay: <Props, Resolved = void>(instance: ElementComponent, options?: _overlastic_core.GlobalMountOptions | undefined) => _overlastic_core.ImperativeOverlay<Props, Resolved,
|
|
9
|
+
declare const defineOverlay: <Props, Resolved = void>(instance: ElementComponent, options?: _overlastic_core.GlobalMountOptions | undefined) => _overlastic_core.ImperativeOverlay<Props, Resolved, unknown>;
|
|
10
10
|
declare const renderOverlay: <Props, Resolved = void>(instance: ElementComponent, props?: Props | undefined, options?: _overlastic_core.GlobalMountOptions | undefined) => Promise<Resolved>;
|
|
11
11
|
|
|
12
12
|
interface Context<T = void> {
|
|
@@ -16,10 +16,10 @@ interface Context<T = void> {
|
|
|
16
16
|
vanish: Function;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
interface
|
|
19
|
+
interface OverlayDefineOptions {
|
|
20
20
|
/** animation duration to avoid premature destruction of components */
|
|
21
21
|
duration?: number;
|
|
22
22
|
}
|
|
23
|
-
declare function
|
|
23
|
+
declare function useOverlayDefine(options?: OverlayDefineOptions): Context<void>;
|
|
24
24
|
|
|
25
|
-
export { type Context, type
|
|
25
|
+
export { type Context, type OverlayDefineOptions, defineOverlay, renderOverlay, useOverlayDefine };
|
package/dist/index.global.js
CHANGED
|
@@ -23,7 +23,7 @@ var OverlaysVanilla = (() => {
|
|
|
23
23
|
__export(src_exports, {
|
|
24
24
|
defineOverlay: () => defineOverlay,
|
|
25
25
|
renderOverlay: () => renderOverlay,
|
|
26
|
-
|
|
26
|
+
useOverlayDefine: () => useOverlayDefine
|
|
27
27
|
});
|
|
28
28
|
|
|
29
29
|
// ../@core/src/define/global.ts
|
|
@@ -90,14 +90,15 @@ var OverlaysVanilla = (() => {
|
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
// ../@core/src/constructor.ts
|
|
93
|
-
function createConstructor(mount) {
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
function createConstructor(mount, options = {}) {
|
|
94
|
+
const { container: globalContainer } = options;
|
|
95
|
+
function define(instance, options2) {
|
|
96
|
+
function executor(props, options3) {
|
|
96
97
|
const deferred = createDeferred();
|
|
97
|
-
const name = defineName(
|
|
98
|
-
const index = getIndex(
|
|
99
|
-
const container = defineGlobalElement(name,
|
|
100
|
-
mount(instance, props, Object.assign(
|
|
98
|
+
const name = defineName(options3.id, options3.autoIncrement);
|
|
99
|
+
const index = getIndex(options3.id);
|
|
100
|
+
const container = globalContainer ? defineGlobalElement(name, options3.root) : document.body;
|
|
101
|
+
mount(instance, props, Object.assign(options3, {
|
|
101
102
|
position: context.position,
|
|
102
103
|
id: name,
|
|
103
104
|
deferred,
|
|
@@ -107,21 +108,21 @@ var OverlaysVanilla = (() => {
|
|
|
107
108
|
return deferred;
|
|
108
109
|
}
|
|
109
110
|
let inst;
|
|
110
|
-
function only(props,
|
|
111
|
+
function only(props, options3) {
|
|
111
112
|
if (!inst) {
|
|
112
|
-
inst = executor(props,
|
|
113
|
+
inst = executor(props, options3);
|
|
113
114
|
inst.finally(() => inst = void 0);
|
|
114
115
|
}
|
|
115
116
|
return inst;
|
|
116
117
|
}
|
|
117
118
|
function caller(props, overrides) {
|
|
118
|
-
const opts = { ...
|
|
119
|
+
const opts = { ...options2, ...overrides };
|
|
119
120
|
return opts.only ? only(props, opts) : executor(props, opts);
|
|
120
121
|
}
|
|
121
122
|
return caller;
|
|
122
123
|
}
|
|
123
|
-
function render(instance, props,
|
|
124
|
-
return define(instance,
|
|
124
|
+
function render(instance, props, options2) {
|
|
125
|
+
return define(instance, options2)(props);
|
|
125
126
|
}
|
|
126
127
|
return { define, render };
|
|
127
128
|
}
|
|
@@ -185,8 +186,8 @@ var OverlaysVanilla = (() => {
|
|
|
185
186
|
var defineOverlay = constructor.define;
|
|
186
187
|
var renderOverlay = constructor.render;
|
|
187
188
|
|
|
188
|
-
// src/composable/
|
|
189
|
-
function
|
|
189
|
+
// src/composable/define.ts
|
|
190
|
+
function useOverlayDefine(options) {
|
|
190
191
|
const trigger = context2.trigger;
|
|
191
192
|
if (!trigger)
|
|
192
193
|
throw new Error("Please execute in the overlays constructor");
|
package/dist/index.js
CHANGED
|
@@ -54,8 +54,8 @@ function parseElement(component, props) {
|
|
|
54
54
|
var defineOverlay = constructor.define;
|
|
55
55
|
var renderOverlay = constructor.render;
|
|
56
56
|
|
|
57
|
-
// src/composable/
|
|
58
|
-
function
|
|
57
|
+
// src/composable/define.ts
|
|
58
|
+
function useOverlayDefine(options) {
|
|
59
59
|
const trigger = context.trigger;
|
|
60
60
|
if (!trigger)
|
|
61
61
|
throw new Error("Please execute in the overlays constructor");
|
|
@@ -65,5 +65,5 @@ function usePrograms(options) {
|
|
|
65
65
|
export {
|
|
66
66
|
defineOverlay,
|
|
67
67
|
renderOverlay,
|
|
68
|
-
|
|
68
|
+
useOverlayDefine
|
|
69
69
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@overlastic/vanilla",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.5.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/hairyf/overlastic#readme",
|
|
7
7
|
"repository": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"dist"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@overlastic/core": "^0.
|
|
28
|
+
"@overlastic/core": "^0.5.1"
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
31
|
"build": "tsup src/index.ts",
|