@overlastic/svelte 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 -102
- package/dist/index.cjs +6 -6
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.global.js +18 -17
- package/dist/index.js +5 -5
- 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,102 +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
|
-
|
|
31
|
-
// duration of overlay duration, helps prevent premature component destroy
|
|
32
|
-
const { resolve, reject } = usePrograms({ duration })
|
|
33
|
-
|
|
34
|
-
function onClick() {
|
|
35
|
-
resolve(`${title}:confirmed`)
|
|
36
|
-
}
|
|
37
|
-
</script>
|
|
38
|
-
|
|
39
|
-
<Overlay>
|
|
40
|
-
<div transition:fly={{ opacity: 0, duration }} on:click={onClick}>
|
|
41
|
-
<slot name="title">
|
|
42
|
-
{ title }
|
|
43
|
-
</slot>
|
|
44
|
-
</div>
|
|
45
|
-
</Overlay>
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
### Step 2: Create Overlay
|
|
49
|
-
|
|
50
|
-
You can use the `defineOverlay` method to convert the component into a modal dialog in Javascript / Typescript, which allows you to call it.
|
|
51
|
-
|
|
52
|
-
```ts
|
|
53
|
-
import { defineOverlay } from '@overlastic/svelte'
|
|
54
|
-
import OverlayComponent from './overlay.svelte'
|
|
55
|
-
|
|
56
|
-
// Convert to imperative callback
|
|
57
|
-
const callback = defineOverlay(OverlayComponent)
|
|
58
|
-
// Call the component and get the value of the resolve callback
|
|
59
|
-
const value = await callback({ title: 'callbackOverlay' })
|
|
60
|
-
// value === "callbackOverlay:confirmed"
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
You can also use `renderOverlay` to directly call the component and skip the `defineOverlay` method.
|
|
64
|
-
|
|
65
|
-
```ts
|
|
66
|
-
import { renderOverlay } from '@overlastic/svelte'
|
|
67
|
-
import OverlayComponent from './overlay.svelte'
|
|
68
|
-
|
|
69
|
-
const value = await renderOverlay(OverlayComponent, {
|
|
70
|
-
title: 'usePrograms'
|
|
71
|
-
})
|
|
72
|
-
// value === "usePrograms:confirmed"
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
## Controlled manner
|
|
76
|
-
|
|
77
|
-
By default, you do not need to control the display and hiding of the `visible` variable. The value is controlled by the component `Overlay`, and you can pass in `visible` to control the display
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
```svelte
|
|
81
|
-
<script lang="ts">
|
|
82
|
-
import { usePrograms, Overlay } from "@overlastic/svelte";
|
|
83
|
-
|
|
84
|
-
let visible = false
|
|
85
|
-
|
|
86
|
-
const { resolve, reject, deferred, vanish } = usePrograms({
|
|
87
|
-
// close the transition duration, at this point you need to manually destroy it
|
|
88
|
-
duration: false,
|
|
89
|
-
// cancel setting visible to true immediately
|
|
90
|
-
immediate: false
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
// Manually set vanish (when promise ends)
|
|
94
|
-
deferred.finally(() => vanish())
|
|
95
|
-
</script>
|
|
96
|
-
|
|
97
|
-
<Overlay bind:visible={visible}>
|
|
98
|
-
<div on:click={() => resolve(`${title}:confirmed`)}>
|
|
99
|
-
...
|
|
100
|
-
</div>
|
|
101
|
-
</Overlay>
|
|
102
|
-
```
|
|
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/svelte"><img src="https://img.shields.io/npm/v/@overlastic/svelte.svg" alt="NPM Version" /></a>
|
|
13
|
+
<a href="https://www.npmjs.com/@overlastic/svelte"><img src="https://img.shields.io/npm/l/@overlastic/svelte.svg" alt="Package License" /></a>
|
|
14
|
+
<a href="https://www.npmjs.com/@overlastic/svelte"><img src="https://img.shields.io/npm/dm/@overlastic/svelte.svg" alt="NPM Downloads" /></a>
|
|
15
|
+
</p>
|
|
16
|
+
|
|
17
|
+
## Description
|
|
18
|
+
|
|
19
|
+
Create messages or dialog overlays using Overlastic in Svelte APP.
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
$ npm install --save @overlastic/svelte
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Quick Start
|
|
28
|
+
|
|
29
|
+
[Overview & Tutorial](https://overlastic.vercel.app/en/svelte/)
|
package/dist/index.cjs
CHANGED
|
@@ -23,7 +23,7 @@ __export(src_exports, {
|
|
|
23
23
|
Overlay: () => Overlay,
|
|
24
24
|
defineOverlay: () => defineOverlay,
|
|
25
25
|
renderOverlay: () => renderOverlay,
|
|
26
|
-
|
|
26
|
+
useOverlayDefine: () => useOverlayDefine
|
|
27
27
|
});
|
|
28
28
|
module.exports = __toCommonJS(src_exports);
|
|
29
29
|
|
|
@@ -38,7 +38,7 @@ var injectOptionsKey = Symbol("overlays:options");
|
|
|
38
38
|
var constructor = (0, import_core.createConstructor)((Inst, props, options) => {
|
|
39
39
|
const { container, deferred, context: _context = /* @__PURE__ */ new Map() } = options;
|
|
40
40
|
function vanish() {
|
|
41
|
-
|
|
41
|
+
app.$destroy();
|
|
42
42
|
container.remove();
|
|
43
43
|
}
|
|
44
44
|
const context = new Map([..._context.entries()]);
|
|
@@ -49,7 +49,7 @@ var constructor = (0, import_core.createConstructor)((Inst, props, options) => {
|
|
|
49
49
|
visible: false,
|
|
50
50
|
vanish
|
|
51
51
|
});
|
|
52
|
-
const
|
|
52
|
+
const app = new Inst({
|
|
53
53
|
target: container,
|
|
54
54
|
props,
|
|
55
55
|
context
|
|
@@ -60,9 +60,9 @@ var constructor = (0, import_core.createConstructor)((Inst, props, options) => {
|
|
|
60
60
|
var defineOverlay = constructor.define;
|
|
61
61
|
var renderOverlay = constructor.render;
|
|
62
62
|
|
|
63
|
-
// src/composable/
|
|
63
|
+
// src/composable/define.ts
|
|
64
64
|
var import_svelte = require("svelte");
|
|
65
|
-
function
|
|
65
|
+
function useOverlayDefine(options = {}) {
|
|
66
66
|
(0, import_svelte.setContext)(injectOptionsKey, options);
|
|
67
67
|
return (0, import_svelte.getContext)(injectOverlayKey);
|
|
68
68
|
}
|
|
@@ -226,5 +226,5 @@ var Overlay = class extends import_internal3.SvelteComponentTyped {
|
|
|
226
226
|
Overlay,
|
|
227
227
|
defineOverlay,
|
|
228
228
|
renderOverlay,
|
|
229
|
-
|
|
229
|
+
useOverlayDefine
|
|
230
230
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -23,13 +23,13 @@ interface ProgramsReturn {
|
|
|
23
23
|
deferred?: Deferred<any>;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
interface
|
|
26
|
+
interface OverlayDefineOptions {
|
|
27
27
|
/** animation duration to avoid premature destruction of components */
|
|
28
28
|
duration?: number;
|
|
29
29
|
/** whether to set visible to true immediately */
|
|
30
30
|
immediate?: boolean;
|
|
31
31
|
}
|
|
32
|
-
declare function
|
|
32
|
+
declare function useOverlayDefine(options?: OverlayDefineOptions): ProgramsReturn;
|
|
33
33
|
|
|
34
34
|
declare class Overlay extends SvelteComponentTyped<{
|
|
35
35
|
visible?: boolean;
|
|
@@ -37,4 +37,4 @@ declare class Overlay extends SvelteComponentTyped<{
|
|
|
37
37
|
constructor(options: ComponentConstructorOptions);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
export { Overlay, type
|
|
40
|
+
export { Overlay, type OverlayDefineOptions, type ProgramsReturn, defineOverlay, renderOverlay, useOverlayDefine };
|
package/dist/index.d.ts
CHANGED
|
@@ -23,13 +23,13 @@ interface ProgramsReturn {
|
|
|
23
23
|
deferred?: Deferred<any>;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
interface
|
|
26
|
+
interface OverlayDefineOptions {
|
|
27
27
|
/** animation duration to avoid premature destruction of components */
|
|
28
28
|
duration?: number;
|
|
29
29
|
/** whether to set visible to true immediately */
|
|
30
30
|
immediate?: boolean;
|
|
31
31
|
}
|
|
32
|
-
declare function
|
|
32
|
+
declare function useOverlayDefine(options?: OverlayDefineOptions): ProgramsReturn;
|
|
33
33
|
|
|
34
34
|
declare class Overlay extends SvelteComponentTyped<{
|
|
35
35
|
visible?: boolean;
|
|
@@ -37,4 +37,4 @@ declare class Overlay extends SvelteComponentTyped<{
|
|
|
37
37
|
constructor(options: ComponentConstructorOptions);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
export { Overlay, type
|
|
40
|
+
export { Overlay, type OverlayDefineOptions, type ProgramsReturn, defineOverlay, renderOverlay, useOverlayDefine };
|
package/dist/index.global.js
CHANGED
|
@@ -24,7 +24,7 @@ var OverlaysSvelte = (() => {
|
|
|
24
24
|
Overlay: () => Overlay,
|
|
25
25
|
defineOverlay: () => defineOverlay,
|
|
26
26
|
renderOverlay: () => renderOverlay,
|
|
27
|
-
|
|
27
|
+
useOverlayDefine: () => useOverlayDefine
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
// ../@core/src/define/global.ts
|
|
@@ -91,14 +91,15 @@ var OverlaysSvelte = (() => {
|
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
// ../@core/src/constructor.ts
|
|
94
|
-
function createConstructor(mount) {
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
function createConstructor(mount, options = {}) {
|
|
95
|
+
const { container: globalContainer } = options;
|
|
96
|
+
function define(instance2, options2) {
|
|
97
|
+
function executor(props, options3) {
|
|
97
98
|
const deferred = createDeferred();
|
|
98
|
-
const name = defineName(
|
|
99
|
-
const index = getIndex(
|
|
100
|
-
const container = defineGlobalElement(name,
|
|
101
|
-
mount(instance2, props, Object.assign(
|
|
99
|
+
const name = defineName(options3.id, options3.autoIncrement);
|
|
100
|
+
const index = getIndex(options3.id);
|
|
101
|
+
const container = globalContainer ? defineGlobalElement(name, options3.root) : document.body;
|
|
102
|
+
mount(instance2, props, Object.assign(options3, {
|
|
102
103
|
position: context.position,
|
|
103
104
|
id: name,
|
|
104
105
|
deferred,
|
|
@@ -108,21 +109,21 @@ var OverlaysSvelte = (() => {
|
|
|
108
109
|
return deferred;
|
|
109
110
|
}
|
|
110
111
|
let inst;
|
|
111
|
-
function only(props,
|
|
112
|
+
function only(props, options3) {
|
|
112
113
|
if (!inst) {
|
|
113
|
-
inst = executor(props,
|
|
114
|
+
inst = executor(props, options3);
|
|
114
115
|
inst.finally(() => inst = void 0);
|
|
115
116
|
}
|
|
116
117
|
return inst;
|
|
117
118
|
}
|
|
118
119
|
function caller(props, overrides) {
|
|
119
|
-
const opts = { ...
|
|
120
|
+
const opts = { ...options2, ...overrides };
|
|
120
121
|
return opts.only ? only(props, opts) : executor(props, opts);
|
|
121
122
|
}
|
|
122
123
|
return caller;
|
|
123
124
|
}
|
|
124
|
-
function render(instance2, props,
|
|
125
|
-
return define(instance2,
|
|
125
|
+
function render(instance2, props, options2) {
|
|
126
|
+
return define(instance2, options2)(props);
|
|
126
127
|
}
|
|
127
128
|
return { define, render };
|
|
128
129
|
}
|
|
@@ -141,7 +142,7 @@ var OverlaysSvelte = (() => {
|
|
|
141
142
|
var constructor = createConstructor((Inst, props, options) => {
|
|
142
143
|
const { container, deferred, context: _context = /* @__PURE__ */ new Map() } = options;
|
|
143
144
|
function vanish() {
|
|
144
|
-
|
|
145
|
+
app.$destroy();
|
|
145
146
|
container.remove();
|
|
146
147
|
}
|
|
147
148
|
const context2 = new Map([..._context.entries()]);
|
|
@@ -152,7 +153,7 @@ var OverlaysSvelte = (() => {
|
|
|
152
153
|
visible: false,
|
|
153
154
|
vanish
|
|
154
155
|
});
|
|
155
|
-
const
|
|
156
|
+
const app = new Inst({
|
|
156
157
|
target: container,
|
|
157
158
|
props,
|
|
158
159
|
context: context2
|
|
@@ -605,8 +606,8 @@ var OverlaysSvelte = (() => {
|
|
|
605
606
|
function onMount() {
|
|
606
607
|
}
|
|
607
608
|
|
|
608
|
-
// src/composable/
|
|
609
|
-
function
|
|
609
|
+
// src/composable/define.ts
|
|
610
|
+
function useOverlayDefine(options = {}) {
|
|
610
611
|
setContext(injectOptionsKey, options);
|
|
611
612
|
return getContext(injectOverlayKey);
|
|
612
613
|
}
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ var injectOptionsKey = Symbol("overlays:options");
|
|
|
9
9
|
var constructor = createConstructor((Inst, props, options) => {
|
|
10
10
|
const { container, deferred, context: _context = /* @__PURE__ */ new Map() } = options;
|
|
11
11
|
function vanish() {
|
|
12
|
-
|
|
12
|
+
app.$destroy();
|
|
13
13
|
container.remove();
|
|
14
14
|
}
|
|
15
15
|
const context = new Map([..._context.entries()]);
|
|
@@ -20,7 +20,7 @@ var constructor = createConstructor((Inst, props, options) => {
|
|
|
20
20
|
visible: false,
|
|
21
21
|
vanish
|
|
22
22
|
});
|
|
23
|
-
const
|
|
23
|
+
const app = new Inst({
|
|
24
24
|
target: container,
|
|
25
25
|
props,
|
|
26
26
|
context
|
|
@@ -31,9 +31,9 @@ var constructor = createConstructor((Inst, props, options) => {
|
|
|
31
31
|
var defineOverlay = constructor.define;
|
|
32
32
|
var renderOverlay = constructor.render;
|
|
33
33
|
|
|
34
|
-
// src/composable/
|
|
34
|
+
// src/composable/define.ts
|
|
35
35
|
import { getContext, setContext } from "svelte";
|
|
36
|
-
function
|
|
36
|
+
function useOverlayDefine(options = {}) {
|
|
37
37
|
setContext(injectOptionsKey, options);
|
|
38
38
|
return getContext(injectOverlayKey);
|
|
39
39
|
}
|
|
@@ -212,5 +212,5 @@ export {
|
|
|
212
212
|
Overlay,
|
|
213
213
|
defineOverlay,
|
|
214
214
|
renderOverlay,
|
|
215
|
-
|
|
215
|
+
useOverlayDefine
|
|
216
216
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@overlastic/svelte",
|
|
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": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"svelte": "^3.57.0",
|
|
29
|
-
"@overlastic/core": "^0.
|
|
29
|
+
"@overlastic/core": "^0.5.1"
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
32
|
"build": "tsup src/index.ts",
|