@overlastic/vanilla 0.4.3 → 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,101 +1,100 @@
1
- # @overlastic/vanilla
2
-
3
- create imperative overlays in the native application, support custom-element!
4
-
5
- ## Install
6
-
7
- With pnpm:
8
- ```sh
9
- pnpm add @overlastic/vanilla
10
- ```
11
-
12
- With yarn:
13
- ```sh
14
- yarn add @overlastic/vanilla
15
- ```
16
-
17
- ## Usage
18
-
19
-
20
- ### Step 1: Define Component
21
-
22
- Create custom elements in the form of functions and return them.
23
-
24
- ```js
25
- // overlay.ts
26
- function Component(props) {
27
- const element = document.createElement('div')
28
- element.innerHTML = props.title
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
+ # @overlastic/vanilla
2
+
3
+ create imperative overlays in the native application, support custom-element!
4
+
5
+ ## Install
6
+
7
+ With pnpm:
8
+ ```sh
9
+ pnpm add @overlastic/vanilla
10
+ ```
11
+
12
+ With yarn:
13
+ ```sh
14
+ yarn add @overlastic/vanilla
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ### Step 1: Define Component
20
+
21
+ Create custom elements in the form of functions and return them.
22
+
23
+ ```js
24
+ // overlay.ts
25
+ function Component(props) {
26
+ const element = document.createElement('div')
27
+ element.innerHTML = props.title
28
+
29
+ const { resolve, reject, deferred } = useOverlayDefine({
30
+ // Duration of overlays duration to avoid premature destruction of the component
31
+ duration: 1000,
32
+ })
33
+
34
+ // Add events that cause the overlays to end
35
+ element.onclick = function () {
36
+ resolve('ok')
37
+ }
38
+
39
+ // Use setTimeout to wait for the element to be appended, then add a class name with animation
40
+ setTimeout(() => element.classList.add('show'))
41
+ // When the deferred is triggered, remove the displayed class name
42
+ deferred.finally(() => element.classList.remove('show'))
43
+
44
+ return element
45
+ }
46
+
47
+ export default Component
48
+ ```
49
+
50
+ ### Step 2: Create Overlay
51
+
52
+ You can use the `defineOverlay` method to convert the component into a modal dialog in Javascript / Typescript, which allows you to call it.
53
+
54
+ ```ts
55
+ import { defineOverlay } from '@overlastic/vanilla'
56
+ import Component from './overlay'
57
+
58
+ // Convert to imperative callback
59
+ const callback = defineOverlay(Component)
60
+ // Call the component and get the value of the resolve callback
61
+ const value = await callback({ title: 'callbackOverlay' })
62
+ // value === "callbackOverlay:confirmed"
63
+ ```
64
+
65
+ You can also use `renderOverlay` to directly call the component and skip the `defineOverlay` method.
66
+
67
+ ```ts
68
+ import { defineOverlay } from '@overlastic/vanilla'
69
+ import Component from './overlay'
70
+
71
+ const value = await renderOverlay(Component, {
72
+ title: 'useOverlayDefine'
73
+ })
74
+ // value === "useOverlayDefine:confirmed"
75
+ ```
76
+
77
+ ## Custom Element
78
+
79
+ After mounting a custom element, you can pass in the corresponding custom element or name through 'defineOverlay' to use the custom element.
80
+
81
+ > You can use [lit](https://lit.dev/) Quickly build custom elements.
82
+
83
+ ```ts
84
+ const callback1 = defineOverlay('my-custom-element')
85
+
86
+ callback1({/* props(attrs) */})
87
+
88
+ function CustomComponent(props) {
89
+ const customElement = document.createElement('my-custom-element')
90
+
91
+ const { resolve, reject } = useOverlayDefine({
92
+ duration: 1000,
93
+ })
94
+
95
+ // ...
96
+ return customElement
97
+ }
98
+
99
+ const callback2 = defineOverlay(CustomComponent)
100
+ ```
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
- usePrograms: () => usePrograms
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/usePrograms.ts
86
- function usePrograms(options) {
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
- usePrograms
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 ProgramsOptions {
19
+ interface OverlayDefineOptions {
20
20
  /** animation duration to avoid premature destruction of components */
21
21
  duration?: number;
22
22
  }
23
- declare function usePrograms(options?: ProgramsOptions): Context<void>;
23
+ declare function useOverlayDefine(options?: OverlayDefineOptions): Context<void>;
24
24
 
25
- export { type Context, type ProgramsOptions, defineOverlay, renderOverlay, usePrograms };
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 ProgramsOptions {
19
+ interface OverlayDefineOptions {
20
20
  /** animation duration to avoid premature destruction of components */
21
21
  duration?: number;
22
22
  }
23
- declare function usePrograms(options?: ProgramsOptions): Context<void>;
23
+ declare function useOverlayDefine(options?: OverlayDefineOptions): Context<void>;
24
24
 
25
- export { type Context, type ProgramsOptions, defineOverlay, renderOverlay, usePrograms };
25
+ export { type Context, type OverlayDefineOptions, defineOverlay, renderOverlay, useOverlayDefine };
@@ -23,7 +23,7 @@ var OverlaysVanilla = (() => {
23
23
  __export(src_exports, {
24
24
  defineOverlay: () => defineOverlay,
25
25
  renderOverlay: () => renderOverlay,
26
- usePrograms: () => usePrograms
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
- function define(instance, options) {
95
- function executor(props, options2) {
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(options2.id, options2.autoIncrement);
98
- const index = getIndex(options2.id);
99
- const container = defineGlobalElement(name, options2.root);
100
- mount(instance, props, Object.assign(options2, {
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, options2) {
111
+ function only(props, options3) {
111
112
  if (!inst) {
112
- inst = executor(props, options2);
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 = { ...options, ...overrides };
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, options) {
124
- return define(instance, options)(props);
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/usePrograms.ts
189
- function usePrograms(options) {
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/usePrograms.ts
58
- function usePrograms(options) {
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
- usePrograms
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.3",
4
+ "version": "0.5.0",
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.4.3"
28
+ "@overlastic/core": "^0.5.0"
29
29
  },
30
30
  "scripts": {
31
31
  "build": "tsup src/index.ts",