@overlastic/react 0.4.8 → 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,175 +1,183 @@
1
- # @overlastic/react
2
-
3
- @overlastic/react is used to define Overlay components in react and supports both imperative and declarative usage!
4
-
5
- ## Install
6
-
7
- With pnpm:
8
- ```sh
9
- pnpm add @overlastic/react
10
- ```
11
-
12
- With yarn:
13
- ```sh
14
- yarn add @overlastic/react
15
- ```
16
-
17
- ## Usage
18
-
19
- ### Step 1: Define Component
20
-
21
- ```tsx
22
- // overlay.tsx
23
- export function Component(props) {
24
- const { visible, resolve, reject } = usePrograms({
25
- // Duration of overlay duration, helps prevent premature component destruction
26
- duration: 200,
27
- })
28
-
29
- return <div className={visible && 'is--visible'}>
30
- <span onClick={() => resolve(`${props.title}:confirmed`)}> Confirm </span>
31
- </div>
32
- }
33
- ```
34
-
35
- ### Step 2: Create Overlay
36
-
37
- You can convert the component into a modal dialog box by using the `defineOverlay` method, which allows you to call it in Javascript / Typescript.
38
- ```ts
39
- import { defineOverlay } from '@overlastic/react'
40
- import { Component } from './overlay'
41
-
42
- // Convert to imperative callback
43
- const callback = defineOverlay(Component)
44
- // Call the component and get the resolve callback value
45
- const value = await callback({ title: 'callbackOverlay' })
46
- // value === "callbackOverlay:confirmed"
47
- ```
48
-
49
- You can also directly call the component through `renderOverlay`, bypassing the `defineOverlay` method.
50
-
51
- ```ts
52
- import { renderOverlay } from '@overlastic/react'
53
- import { Component } from './overlay'
54
-
55
- const value = await renderOverlay(Component, {
56
- title: 'usePrograms'
57
- })
58
- // value === "usePrograms:confirmed"
59
- ```
60
-
61
- ## Injection Holder
62
-
63
- In addition to using `defineOverlay` and `renderOverlay` to create popup components, you can also use useOverlayHolder to create popup components within a component and inherit the current context of the application.
64
-
65
- ```tsx
66
- import { useOverlayHolder } from '@overlastic/react'
67
- import { OverlayComponent } from './overlay'
68
-
69
- export function Main() {
70
- // Use useOverlayHolder(Component) to create a component holder that supports the current context.
71
- const [holder, overlayApi] = useOverlayHolder(OverlayComponent)
72
-
73
- function open() {
74
- // Open the popup component
75
- overlayApi()
76
- .then((result) => {})
77
- }
78
- return (<>
79
- <div onClick={open}> open </div>
80
- {/* Mount the holder */}
81
- {holder}
82
- </>)
83
- }
84
- ```
85
-
86
- ## Define Component
87
-
88
- Components created using `@overlastic/react` support both imperative and declarative methods of calling. In addition to imperative methods, these components can also be used in JSX.
89
-
90
- > This is an optional option that is very useful when porting old components.
91
-
92
- ```tsx
93
- // If using Typescript, use PropsWithOverlays to define props type
94
- import type { PropsWithOverlays } from '@overlastic/react'
95
- import { usePrograms } from '@overlastic/react'
96
-
97
- export function Component(props: PropsWithOverlays<{ /* ...you props */ }>) {
98
- const { visible, resolve, reject } = usePrograms({
99
- // pass props to usePrograms for processing
100
- props
101
- })
102
-
103
- return <div className={visible && 'is--visible'}>
104
- ...
105
- </div>
106
- }
107
- ```
108
-
109
- Once the Overlay component has received props, the popup layer component can be used in JSX.
110
-
111
- ```tsx
112
- import { useState } from 'react'
113
- import { Component } from './overlay'
114
-
115
- export function Main() {
116
- const [visible, setVisible] = useState(false)
117
-
118
- function openOverlay() {
119
- setVisible(true)
120
- }
121
-
122
- function onResolve(value) {
123
- setVisible(false)
124
- }
125
-
126
- function onReject(value) {
127
- setVisible(false)
128
- }
129
-
130
- return (
131
- <Component visible={visible} onResolve={onResolve} onReject={onReject} />
132
- )
133
- }
134
- ```
135
-
136
- If you want to replace other fields and event names, you can do so using the `model` and `events` config of usePrograms.
137
-
138
- ```jsx
139
- function Component(props: { onOn?: Function; onNook?: Function; open: boolean }) {
140
- const { visible, resolve, reject } = usePrograms({
141
- events: { resolve: 'onOk', reject: 'onNook' },
142
- model: 'open',
143
- props,
144
- })
145
- // ...
146
- }
147
- ```
148
-
149
- ## Customized
150
-
151
- You can use `@overlastic/react` to modify existing components or component libraries
152
-
153
- Take [antd(drawer)](https://ant.design/components/drawer-cn) as an example:
154
-
155
- ```tsx
156
- import type { PropsWithOverlays } from '@overlastic/react'
157
- import { usePrograms } from '@overlastic/react'
158
- import { Button, Drawer } from 'antd'
159
-
160
- function MyDrawer(props: PropsWithOverlays<{ title: string }>) {
161
- const { visible, resolve, reject } = usePrograms({
162
- duration: 200,
163
- props,
164
- })
165
-
166
- return (
167
- <Drawer title={props.title} onClose={reject} open={visible}>
168
- {/* Custom contents.... */}
169
- <Button type="primary" onClick={() => resolve(`${props.title}:confirmed`)}>
170
- Confirm
171
- </Button>
172
- </Drawer>
173
- )
174
- }
175
- ```
1
+ # @overlastic/react
2
+
3
+ @overlastic/react is used to define Overlay components in react and supports both imperative and declarative usage!
4
+
5
+ ## Install
6
+
7
+ With pnpm:
8
+ ```sh
9
+ pnpm add @overlastic/react
10
+ ```
11
+
12
+ With yarn:
13
+ ```sh
14
+ yarn add @overlastic/react
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ### Step 1: Define Component
20
+
21
+ ```tsx
22
+ // overlay.tsx
23
+ export function Component(props) {
24
+ const { visible, resolve, reject } = useOverlayDefine({
25
+ // Duration of overlay duration, helps prevent premature component destruction
26
+ duration: 200,
27
+ })
28
+
29
+ return (
30
+ <div className={visible && 'is--visible'}>
31
+ <span onClick={() => resolve(`${props.title}:confirmed`)}> Confirm </span>
32
+ </div>
33
+ )
34
+ }
35
+ ```
36
+
37
+ ### Step 2: Create Overlay
38
+
39
+ You can convert the component into a modal dialog box by using the `defineOverlay` method, which allows you to call it in Javascript / Typescript.
40
+ ```ts
41
+ import { defineOverlay } from '@overlastic/react'
42
+ import { Component } from './overlay'
43
+
44
+ // Convert to imperative callback
45
+ const callback = defineOverlay(Component)
46
+ // Call the component and get the resolve callback value
47
+ const value = await callback({ title: 'callbackOverlay' })
48
+ // value === "callbackOverlay:confirmed"
49
+ ```
50
+
51
+ You can also directly call the component through `renderOverlay`, bypassing the `defineOverlay` method.
52
+
53
+ ```ts
54
+ import { renderOverlay } from '@overlastic/react'
55
+ import { Component } from './overlay'
56
+
57
+ const value = await renderOverlay(Component, {
58
+ title: 'useOverlayDefine'
59
+ })
60
+ // value === "useOverlayDefine:confirmed"
61
+ ```
62
+
63
+ ## Injection Holder
64
+
65
+ In addition to using `defineOverlay` and `renderOverlay` to create popup components, you can also use useOverlayHolder to create popup components within a component and inherit the current context of the application.
66
+
67
+ ```tsx
68
+ import { useOverlayHolder } from '@overlastic/react'
69
+ import { OverlayComponent } from './overlay'
70
+
71
+ export function Main() {
72
+ // Use useOverlayHolder(Component) to create a component holder that supports the current context.
73
+ const [holder, overlayApi] = useOverlayHolder(OverlayComponent)
74
+
75
+ function open() {
76
+ // Open the popup component
77
+ overlayApi()
78
+ .then((result) => {})
79
+ }
80
+ return (
81
+ <>
82
+ <div onClick={open}> open </div>
83
+ {/* Mount the holder */}
84
+ {holder}
85
+ </>
86
+ )
87
+ }
88
+ ```
89
+
90
+ ## Define Component
91
+
92
+ Components created using `@overlastic/react` support both imperative and declarative methods of calling. In addition to imperative methods, these components can also be used in JSX.
93
+
94
+ > This is an optional option that is very useful when porting old components.
95
+
96
+ ```tsx
97
+ // If using Typescript, use PropsWithOverlays to define props type
98
+ import type { PropsWithOverlays } from '@overlastic/react'
99
+ import { useOverlayDefine } from '@overlastic/react'
100
+
101
+ export function Component(props: PropsWithOverlays<{ /* ...you props */ }>) {
102
+ const { visible, resolve, reject } = useOverlayDefine({
103
+ // pass props to useOverlayDefine for processing
104
+ props
105
+ })
106
+
107
+ return (
108
+ <div className={visible && 'is--visible'}>
109
+ ...
110
+ </div>
111
+ )
112
+ }
113
+ ```
114
+
115
+ Once the Overlay component has received props, the popup layer component can be used in JSX.
116
+
117
+ ```tsx
118
+ import { useState } from 'react'
119
+ import { Component } from './overlay'
120
+
121
+ export function Main() {
122
+ const [visible, setVisible] = useState(false)
123
+
124
+ function openOverlay() {
125
+ setVisible(true)
126
+ }
127
+
128
+ function onResolve(value) {
129
+ setVisible(false)
130
+ }
131
+
132
+ function onReject(value) {
133
+ setVisible(false)
134
+ }
135
+
136
+ return (
137
+ <Component visible={visible} onResolve={onResolve} onReject={onReject} />
138
+ )
139
+ }
140
+ ```
141
+
142
+ If you want to replace other fields and event names, you can do so using the `model` and `events` config of useOverlayDefine.
143
+
144
+ ```jsx
145
+ function Component(props: { onOn?: Function, onNook?: Function, open: boolean }) {
146
+ const { visible, resolve, reject } = useOverlayDefine({
147
+ events: { resolve: 'onOk', reject: 'onNook' },
148
+ model: 'open',
149
+ props,
150
+ })
151
+ // ...
152
+ }
153
+ ```
154
+
155
+ ## Customized
156
+
157
+ You can use `@overlastic/react` to modify existing components or component libraries
158
+
159
+ Take [antd(drawer)](https://ant.design/components/drawer-cn) as an example:
160
+
161
+ ```tsx
162
+ import type { PropsWithOverlays } from '@overlastic/react'
163
+ import { useOverlayDefine } from '@overlastic/react'
164
+ import { Button, Drawer } from 'antd'
165
+
166
+ function MyDrawer(props: PropsWithOverlays<{ title: string }>) {
167
+ const { visible, resolve, reject } = useOverlayDefine({
168
+ duration: 200,
169
+ props,
170
+ })
171
+
172
+ return (
173
+ <Drawer title={props.title} onClose={reject} open={visible}>
174
+ {/* Custom contents.... */}
175
+ <Button type="primary" onClick={() => resolve(`${props.title}:confirmed`)}>
176
+ Confirm
177
+ </Button>
178
+ </Drawer>
179
+ )
180
+ }
181
+
182
+ export default MyDrawer
183
+ ```
package/dist/index.cjs CHANGED
@@ -20,15 +20,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var src_exports = {};
22
22
  __export(src_exports, {
23
+ OverlayProvider: () => OverlayProvider,
23
24
  defineOverlay: () => defineOverlay,
24
25
  renderOverlay: () => renderOverlay,
25
26
  useOverlay: () => useOverlay,
26
- useOverlayHolder: () => useOverlayHolder,
27
- usePrograms: () => usePrograms
27
+ useOverlayDefine: () => useOverlayDefine,
28
+ useOverlayHolder: () => useOverlayHolder
28
29
  });
29
30
  module.exports = __toCommonJS(src_exports);
30
31
 
31
- // src/composable/usePrograms.ts
32
+ // src/composable/define.ts
32
33
  var import_core2 = require("@overlastic/core");
33
34
  var import_react2 = require("react");
34
35
 
@@ -52,8 +53,8 @@ function defineAnonymousComponent(component) {
52
53
  return { "--": component }["--"];
53
54
  }
54
55
 
55
- // src/composable/usePrograms.ts
56
- function usePrograms(options = {}) {
56
+ // src/composable/define.ts
57
+ function useOverlayDefine(options = {}) {
57
58
  const { immediate = true, duration = 0, automatic = true } = options;
58
59
  const context = (0, import_react2.useContext)(ScriptsContext);
59
60
  const dec = Reflect.get(context, "in_dec");
@@ -96,7 +97,7 @@ function useMount(callback = import_core2.noop) {
96
97
  (0, import_react2.useEffect)(() => callback(), []);
97
98
  }
98
99
 
99
- // src/composable/useScripts.ts
100
+ // src/composable/scripts.ts
100
101
  var import_react3 = require("react");
101
102
  function useScripts(options) {
102
103
  const { reject: _reject } = options.deferred || {};
@@ -116,69 +117,39 @@ function useScripts(options) {
116
117
  };
117
118
  }
118
119
 
119
- // src/composable/useOverlay.tsx
120
+ // src/composable/holder.tsx
120
121
  var import_core3 = require("@overlastic/core");
121
- var import_react4 = require("react");
122
122
  var import_pascal_case = require("pascal-case");
123
+ var import_react4 = require("react");
123
124
  var import_react_dom = require("react-dom");
124
125
  var import_jsx_runtime = require("react/jsx-runtime");
125
- var { define } = (0, import_core3.createConstructor)((Instance, props, options) => {
126
- const { container, id, deferred, render, vanish: _vanish } = options;
127
- const InstanceWithProvider = defineAnonymousComponent(() => {
128
- const content = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
129
- ScriptsContext.Provider,
130
- {
131
- value: useScripts({ deferred, vanish }),
132
- ...{ id: (0, import_pascal_case.pascalCase)(id) },
133
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Instance, { ...props })
134
- }
135
- );
136
- return (0, import_react_dom.createPortal)(content, container);
137
- });
138
- function vanish() {
139
- _vanish(InstanceWithProvider);
140
- container.remove();
141
- }
142
- render(InstanceWithProvider, props);
143
- });
144
- function useOverlay(Instance) {
145
- const { render, vanish } = (0, import_react4.useContext)(InstancesContext);
146
- return define(Instance, { render, vanish });
147
- }
148
-
149
- // src/composable/useOverlayHolder.tsx
150
- var import_core4 = require("@overlastic/core");
151
- var import_pascal_case2 = require("pascal-case");
152
- var import_react5 = require("react");
153
- var import_react_dom2 = require("react-dom");
154
- var import_jsx_runtime2 = require("react/jsx-runtime");
155
126
  function useOverlayHolder(Component, options = {}) {
156
127
  const { callback, scripts, props, refresh } = useRefreshMetadata();
157
- const name = (0, import_core4.defineName)(options.id, options.autoIncrement);
128
+ const name = (0, import_core3.defineName)(options.id, options.autoIncrement);
158
129
  function render() {
159
130
  const root = options.root || (typeof document !== "undefined" ? document.body : void 0);
160
- const content = /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { id: name, children: [
131
+ const content = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { id: name, children: [
161
132
  " ",
162
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Component, { ...props }),
133
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, { ...props }),
163
134
  " "
164
135
  ] });
165
- return options.root !== false && root ? (0, import_react_dom2.createPortal)(content, root) : content;
136
+ return options.root !== false && root ? (0, import_react_dom.createPortal)(content, root) : content;
166
137
  }
167
- const holder = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
138
+ const holder = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
168
139
  ScriptsContext.Provider,
169
140
  {
170
141
  value: scripts,
171
- ...{ id: (0, import_pascal_case2.pascalCase)(name) },
142
+ ...{ id: (0, import_pascal_case.pascalCase)(name) },
172
143
  children: refresh ? render() : null
173
144
  }
174
145
  );
175
146
  return [holder, callback];
176
147
  }
177
148
  function useRefreshMetadata() {
178
- const [props, setProps] = (0, import_react5.useState)();
179
- const [refresh, setRefresh] = (0, import_react5.useState)(false);
180
- const [visible, setVisible] = (0, import_react5.useState)(false);
181
- const deferred = (0, import_react5.useRef)({});
149
+ const [props, setProps] = (0, import_react4.useState)();
150
+ const [refresh, setRefresh] = (0, import_react4.useState)(false);
151
+ const [visible, setVisible] = (0, import_react4.useState)(false);
152
+ const deferred = (0, import_react4.useRef)({});
182
153
  const scripts = {
183
154
  deferred: deferred.current,
184
155
  resolve: deferred.current.resolve,
@@ -194,7 +165,7 @@ function useRefreshMetadata() {
194
165
  (_a = scripts.reject) == null ? void 0 : _a.call(scripts);
195
166
  }
196
167
  async function callback(props2) {
197
- deferred.current = (0, import_core4.createDeferred)();
168
+ deferred.current = (0, import_core3.createDeferred)();
198
169
  setProps(props2);
199
170
  setRefresh(true);
200
171
  return deferred.current;
@@ -202,6 +173,34 @@ function useRefreshMetadata() {
202
173
  return { callback, scripts, props, refresh };
203
174
  }
204
175
 
176
+ // src/composable/overlay.tsx
177
+ var import_core4 = require("@overlastic/core");
178
+ var import_react5 = require("react");
179
+ var import_pascal_case2 = require("pascal-case");
180
+ var import_jsx_runtime2 = require("react/jsx-runtime");
181
+ var { define } = (0, import_core4.createConstructor)((Instance, props, options) => {
182
+ const { id, deferred, render, vanish: _vanish } = options;
183
+ const InstanceWithProvider = defineAnonymousComponent(() => {
184
+ const content = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
185
+ ScriptsContext.Provider,
186
+ {
187
+ value: useScripts({ deferred, vanish }),
188
+ ...{ id: (0, import_pascal_case2.pascalCase)(id) },
189
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Instance, { ...props })
190
+ }
191
+ );
192
+ return content;
193
+ });
194
+ function vanish() {
195
+ _vanish(InstanceWithProvider);
196
+ }
197
+ render(InstanceWithProvider, props);
198
+ }, { container: false });
199
+ function useOverlay(Instance) {
200
+ const { render, vanish } = (0, import_react5.useContext)(InstancesContext);
201
+ return define(Instance, { render, vanish });
202
+ }
203
+
205
204
  // src/define/constructor.tsx
206
205
  var import_core5 = require("@overlastic/core");
207
206
  var import_client = require("react-dom/client");
@@ -233,11 +232,29 @@ var constructor = (0, import_core5.createConstructor)((Instance, props, options)
233
232
  // src/define/index.ts
234
233
  var defineOverlay = constructor.define;
235
234
  var renderOverlay = constructor.render;
235
+
236
+ // src/components/OverlayProvider.tsx
237
+ var import_react6 = require("react");
238
+ var import_jsx_runtime4 = require("react/jsx-runtime");
239
+ function OverlayProvider(props) {
240
+ const [instances, setInstances] = (0, import_react6.useState)([]);
241
+ function render(Instance, props2) {
242
+ setInstances((instances2) => [...instances2, { Instance, props: props2 }]);
243
+ }
244
+ function vanish(instance) {
245
+ setInstances((instances2) => [...instances2.filter(({ Instance }) => instance !== Instance)]);
246
+ }
247
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(InstancesContext.Provider, { value: { render, vanish }, children: [
248
+ instances.map(({ Instance, props: props2 }, index) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Instance, { ...props2 }, index)),
249
+ props.children
250
+ ] });
251
+ }
236
252
  // Annotate the CommonJS export names for ESM import in node:
237
253
  0 && (module.exports = {
254
+ OverlayProvider,
238
255
  defineOverlay,
239
256
  renderOverlay,
240
257
  useOverlay,
241
- useOverlayHolder,
242
- usePrograms
258
+ useOverlayDefine,
259
+ useOverlayHolder
243
260
  });
package/dist/index.d.cts CHANGED
@@ -1,7 +1,8 @@
1
1
  import * as react from 'react';
2
- import { Dispatch, SetStateAction, FC } from 'react';
2
+ import { Dispatch, SetStateAction, FC, PropsWithChildren } from 'react';
3
3
  import * as _overlastic_core from '@overlastic/core';
4
4
  import { ImperativeOverlay, MountOptions } from '@overlastic/core';
5
+ import * as react_jsx_runtime from 'react/jsx-runtime';
5
6
 
6
7
  type PropsWidthOverlays<P = unknown> = P & {
7
8
  visible?: boolean;
@@ -23,7 +24,7 @@ interface PromptifyEvents {
23
24
  */
24
25
  resolve?: string;
25
26
  }
26
- interface ProgramsOptions {
27
+ interface OverlayDefineOptions {
27
28
  /** animation duration to avoid premature destruction of components */
28
29
  duration?: number;
29
30
  /** whether to set visible to true immediately */
@@ -63,7 +64,10 @@ interface ProgramsReturn {
63
64
  /** current deferred */
64
65
  deferred?: Promise<any>;
65
66
  }
66
- declare function usePrograms(options?: ProgramsOptions): ProgramsReturn;
67
+ declare function useOverlayDefine(options?: OverlayDefineOptions): ProgramsReturn;
68
+
69
+ type InjectionHolder<Props, Resolved> = [JSX.Element, ImperativeOverlay<Props, Resolved>];
70
+ declare function useOverlayHolder<Props, Resolved = void>(Component: FC<Props>, options?: MountOptions): InjectionHolder<Props, Resolved>;
67
71
 
68
72
  interface Options {
69
73
  render: (instance: FC, props: any) => void;
@@ -71,10 +75,9 @@ interface Options {
71
75
  }
72
76
  declare function useOverlay<Props, Resolved>(Instance: FC<Props>): _overlastic_core.ImperativeOverlay<Props, Resolved, Options>;
73
77
 
74
- type InjectionHolder<Props, Resolved> = [JSX.Element, ImperativeOverlay<Props, Resolved>];
75
- declare function useOverlayHolder<Props, Resolved = void>(Component: FC<Props>, options?: MountOptions): InjectionHolder<Props, Resolved>;
76
-
77
- declare const defineOverlay: <Props, Resolved = void>(instance: react.FC<any>, options?: _overlastic_core.GlobalMountOptions | undefined) => _overlastic_core.ImperativeOverlay<Props, Resolved, {}>;
78
+ declare const defineOverlay: <Props, Resolved = void>(instance: react.FC<any>, options?: _overlastic_core.GlobalMountOptions | undefined) => _overlastic_core.ImperativeOverlay<Props, Resolved, unknown>;
78
79
  declare const renderOverlay: <Props, Resolved = void>(instance: react.FC<any>, props?: Props | undefined, options?: _overlastic_core.GlobalMountOptions | undefined) => Promise<Resolved>;
79
80
 
80
- export { type InjectionHolder, type ProgramsOptions, type ProgramsReturn, type PropsWidthOverlays, defineOverlay, renderOverlay, useOverlay, useOverlayHolder, usePrograms };
81
+ declare function OverlayProvider(props: PropsWithChildren): react_jsx_runtime.JSX.Element;
82
+
83
+ export { type InjectionHolder, type OverlayDefineOptions, OverlayProvider, type ProgramsReturn, type PropsWidthOverlays, defineOverlay, renderOverlay, useOverlay, useOverlayDefine, useOverlayHolder };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import * as react from 'react';
2
- import { Dispatch, SetStateAction, FC } from 'react';
2
+ import { Dispatch, SetStateAction, FC, PropsWithChildren } from 'react';
3
3
  import * as _overlastic_core from '@overlastic/core';
4
4
  import { ImperativeOverlay, MountOptions } from '@overlastic/core';
5
+ import * as react_jsx_runtime from 'react/jsx-runtime';
5
6
 
6
7
  type PropsWidthOverlays<P = unknown> = P & {
7
8
  visible?: boolean;
@@ -23,7 +24,7 @@ interface PromptifyEvents {
23
24
  */
24
25
  resolve?: string;
25
26
  }
26
- interface ProgramsOptions {
27
+ interface OverlayDefineOptions {
27
28
  /** animation duration to avoid premature destruction of components */
28
29
  duration?: number;
29
30
  /** whether to set visible to true immediately */
@@ -63,7 +64,10 @@ interface ProgramsReturn {
63
64
  /** current deferred */
64
65
  deferred?: Promise<any>;
65
66
  }
66
- declare function usePrograms(options?: ProgramsOptions): ProgramsReturn;
67
+ declare function useOverlayDefine(options?: OverlayDefineOptions): ProgramsReturn;
68
+
69
+ type InjectionHolder<Props, Resolved> = [JSX.Element, ImperativeOverlay<Props, Resolved>];
70
+ declare function useOverlayHolder<Props, Resolved = void>(Component: FC<Props>, options?: MountOptions): InjectionHolder<Props, Resolved>;
67
71
 
68
72
  interface Options {
69
73
  render: (instance: FC, props: any) => void;
@@ -71,10 +75,9 @@ interface Options {
71
75
  }
72
76
  declare function useOverlay<Props, Resolved>(Instance: FC<Props>): _overlastic_core.ImperativeOverlay<Props, Resolved, Options>;
73
77
 
74
- type InjectionHolder<Props, Resolved> = [JSX.Element, ImperativeOverlay<Props, Resolved>];
75
- declare function useOverlayHolder<Props, Resolved = void>(Component: FC<Props>, options?: MountOptions): InjectionHolder<Props, Resolved>;
76
-
77
- declare const defineOverlay: <Props, Resolved = void>(instance: react.FC<any>, options?: _overlastic_core.GlobalMountOptions | undefined) => _overlastic_core.ImperativeOverlay<Props, Resolved, {}>;
78
+ declare const defineOverlay: <Props, Resolved = void>(instance: react.FC<any>, options?: _overlastic_core.GlobalMountOptions | undefined) => _overlastic_core.ImperativeOverlay<Props, Resolved, unknown>;
78
79
  declare const renderOverlay: <Props, Resolved = void>(instance: react.FC<any>, props?: Props | undefined, options?: _overlastic_core.GlobalMountOptions | undefined) => Promise<Resolved>;
79
80
 
80
- export { type InjectionHolder, type ProgramsOptions, type ProgramsReturn, type PropsWidthOverlays, defineOverlay, renderOverlay, useOverlay, useOverlayHolder, usePrograms };
81
+ declare function OverlayProvider(props: PropsWithChildren): react_jsx_runtime.JSX.Element;
82
+
83
+ export { type InjectionHolder, type OverlayDefineOptions, OverlayProvider, type ProgramsReturn, type PropsWidthOverlays, defineOverlay, renderOverlay, useOverlay, useOverlayDefine, useOverlayHolder };
@@ -1389,7 +1389,7 @@ var OverlaysReact = (() => {
1389
1389
  }
1390
1390
  return dispatcher.useContext(Context);
1391
1391
  }
1392
- function useState3(initialState) {
1392
+ function useState4(initialState) {
1393
1393
  var dispatcher = resolveDispatcher();
1394
1394
  return dispatcher.useState(initialState);
1395
1395
  }
@@ -2192,7 +2192,7 @@ var OverlaysReact = (() => {
2192
2192
  exports.useMemo = useMemo;
2193
2193
  exports.useReducer = useReducer;
2194
2194
  exports.useRef = useRef2;
2195
- exports.useState = useState3;
2195
+ exports.useState = useState4;
2196
2196
  exports.useSyncExternalStore = useSyncExternalStore;
2197
2197
  exports.useTransition = useTransition;
2198
2198
  exports.version = ReactVersion;
@@ -30296,7 +30296,7 @@ var OverlaysReact = (() => {
30296
30296
  return root2;
30297
30297
  }
30298
30298
  var ReactVersion = "18.3.1";
30299
- function createPortal3(children, containerInfo, implementation) {
30299
+ function createPortal2(children, containerInfo, implementation) {
30300
30300
  var key = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : null;
30301
30301
  {
30302
30302
  checkKeyStringCoercion(key);
@@ -31153,7 +31153,7 @@ var OverlaysReact = (() => {
31153
31153
  if (!isValidContainer(container)) {
31154
31154
  throw new Error("Target container is not a DOM element.");
31155
31155
  }
31156
- return createPortal3(children, container, null, key);
31156
+ return createPortal2(children, container, null, key);
31157
31157
  }
31158
31158
  function renderSubtreeIntoContainer(parentComponent, element, containerNode, callback) {
31159
31159
  return unstable_renderSubtreeIntoContainer(parentComponent, element, containerNode, callback);
@@ -32161,11 +32161,11 @@ var OverlaysReact = (() => {
32161
32161
  return jsxWithValidation(type, props, key, false);
32162
32162
  }
32163
32163
  }
32164
- var jsx4 = jsxWithValidationDynamic;
32165
- var jsxs2 = jsxWithValidationStatic;
32164
+ var jsx5 = jsxWithValidationDynamic;
32165
+ var jsxs3 = jsxWithValidationStatic;
32166
32166
  exports.Fragment = REACT_FRAGMENT_TYPE;
32167
- exports.jsx = jsx4;
32168
- exports.jsxs = jsxs2;
32167
+ exports.jsx = jsx5;
32168
+ exports.jsxs = jsxs3;
32169
32169
  })();
32170
32170
  }
32171
32171
  }
@@ -32217,11 +32217,12 @@ var OverlaysReact = (() => {
32217
32217
  // src/index.ts
32218
32218
  var src_exports = {};
32219
32219
  __export(src_exports, {
32220
+ OverlayProvider: () => OverlayProvider,
32220
32221
  defineOverlay: () => defineOverlay,
32221
32222
  renderOverlay: () => renderOverlay,
32222
32223
  useOverlay: () => useOverlay,
32223
- useOverlayHolder: () => useOverlayHolder,
32224
- usePrograms: () => usePrograms
32224
+ useOverlayDefine: () => useOverlayDefine,
32225
+ useOverlayHolder: () => useOverlayHolder
32225
32226
  });
32226
32227
 
32227
32228
  // ../@core/src/define/global.ts
@@ -32288,14 +32289,15 @@ var OverlaysReact = (() => {
32288
32289
  }
32289
32290
 
32290
32291
  // ../@core/src/constructor.ts
32291
- function createConstructor(mount) {
32292
- function define2(instance, options) {
32293
- function executor(props, options2) {
32292
+ function createConstructor(mount, options = {}) {
32293
+ const { container: globalContainer } = options;
32294
+ function define2(instance, options2) {
32295
+ function executor(props, options3) {
32294
32296
  const deferred = createDeferred();
32295
- const name = defineName(options2.id, options2.autoIncrement);
32296
- const index = getIndex(options2.id);
32297
- const container = defineGlobalElement(name, options2.root);
32298
- mount(instance, props, Object.assign(options2, {
32297
+ const name = defineName(options3.id, options3.autoIncrement);
32298
+ const index = getIndex(options3.id);
32299
+ const container = globalContainer ? defineGlobalElement(name, options3.root) : document.body;
32300
+ mount(instance, props, Object.assign(options3, {
32299
32301
  position: context.position,
32300
32302
  id: name,
32301
32303
  deferred,
@@ -32305,21 +32307,21 @@ var OverlaysReact = (() => {
32305
32307
  return deferred;
32306
32308
  }
32307
32309
  let inst;
32308
- function only(props, options2) {
32310
+ function only(props, options3) {
32309
32311
  if (!inst) {
32310
- inst = executor(props, options2);
32312
+ inst = executor(props, options3);
32311
32313
  inst.finally(() => inst = void 0);
32312
32314
  }
32313
32315
  return inst;
32314
32316
  }
32315
32317
  function caller(props, overrides) {
32316
- const opts = { ...options, ...overrides };
32318
+ const opts = { ...options2, ...overrides };
32317
32319
  return opts.only ? only(props, opts) : executor(props, opts);
32318
32320
  }
32319
32321
  return caller;
32320
32322
  }
32321
- function render(instance, props, options) {
32322
- return define2(instance, options)(props);
32323
+ function render(instance, props, options2) {
32324
+ return define2(instance, options2)(props);
32323
32325
  }
32324
32326
  return { define: define2, render };
32325
32327
  }
@@ -32332,7 +32334,7 @@ var OverlaysReact = (() => {
32332
32334
  return new Promise((resolve) => setTimeout(resolve, milliseconds));
32333
32335
  }
32334
32336
 
32335
- // src/composable/usePrograms.ts
32337
+ // src/composable/define.ts
32336
32338
  var import_react2 = __toESM(require_react(), 1);
32337
32339
 
32338
32340
  // src/internal/contexts.tsx
@@ -32354,8 +32356,8 @@ var OverlaysReact = (() => {
32354
32356
  return { "--": component }["--"];
32355
32357
  }
32356
32358
 
32357
- // src/composable/usePrograms.ts
32358
- function usePrograms(options = {}) {
32359
+ // src/composable/define.ts
32360
+ function useOverlayDefine(options = {}) {
32359
32361
  const { immediate = true, duration = 0, automatic = true } = options;
32360
32362
  const context2 = (0, import_react2.useContext)(ScriptsContext);
32361
32363
  const dec = Reflect.get(context2, "in_dec");
@@ -32398,7 +32400,7 @@ var OverlaysReact = (() => {
32398
32400
  (0, import_react2.useEffect)(() => callback(), []);
32399
32401
  }
32400
32402
 
32401
- // src/composable/useScripts.ts
32403
+ // src/composable/scripts.ts
32402
32404
  var import_react3 = __toESM(require_react(), 1);
32403
32405
  function useScripts(options) {
32404
32406
  const { reject: _reject } = options.deferred || {};
@@ -32418,9 +32420,6 @@ var OverlaysReact = (() => {
32418
32420
  };
32419
32421
  }
32420
32422
 
32421
- // src/composable/useOverlay.tsx
32422
- var import_react4 = __toESM(require_react(), 1);
32423
-
32424
32423
  // ../../node_modules/.pnpm/tslib@2.5.0/node_modules/tslib/tslib.es6.js
32425
32424
  var __assign = function() {
32426
32425
  __assign = Object.assign || function __assign2(t) {
@@ -32481,50 +32480,23 @@ var OverlaysReact = (() => {
32481
32480
  return noCase(input, __assign({ delimiter: "", transform: pascalCaseTransform }, options));
32482
32481
  }
32483
32482
 
32484
- // src/composable/useOverlay.tsx
32483
+ // src/composable/holder.tsx
32484
+ var import_react4 = __toESM(require_react(), 1);
32485
32485
  var import_react_dom = __toESM(require_react_dom(), 1);
32486
32486
  var import_jsx_runtime = __toESM(require_jsx_runtime(), 1);
32487
- var { define } = createConstructor((Instance, props, options) => {
32488
- const { container, id, deferred, render, vanish: _vanish } = options;
32489
- const InstanceWithProvider = defineAnonymousComponent(() => {
32490
- const content = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
32491
- ScriptsContext.Provider,
32492
- {
32493
- value: useScripts({ deferred, vanish }),
32494
- ...{ id: pascalCase(id) },
32495
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Instance, { ...props })
32496
- }
32497
- );
32498
- return (0, import_react_dom.createPortal)(content, container);
32499
- });
32500
- function vanish() {
32501
- _vanish(InstanceWithProvider);
32502
- container.remove();
32503
- }
32504
- render(InstanceWithProvider, props);
32505
- });
32506
- function useOverlay(Instance) {
32507
- const { render, vanish } = (0, import_react4.useContext)(InstancesContext);
32508
- return define(Instance, { render, vanish });
32509
- }
32510
-
32511
- // src/composable/useOverlayHolder.tsx
32512
- var import_react5 = __toESM(require_react(), 1);
32513
- var import_react_dom2 = __toESM(require_react_dom(), 1);
32514
- var import_jsx_runtime2 = __toESM(require_jsx_runtime(), 1);
32515
32487
  function useOverlayHolder(Component, options = {}) {
32516
32488
  const { callback, scripts, props, refresh } = useRefreshMetadata();
32517
32489
  const name = defineName(options.id, options.autoIncrement);
32518
32490
  function render() {
32519
32491
  const root = options.root || (typeof document !== "undefined" ? document.body : void 0);
32520
- const content = /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { id: name, children: [
32492
+ const content = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { id: name, children: [
32521
32493
  " ",
32522
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Component, { ...props }),
32494
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, { ...props }),
32523
32495
  " "
32524
32496
  ] });
32525
- return options.root !== false && root ? (0, import_react_dom2.createPortal)(content, root) : content;
32497
+ return options.root !== false && root ? (0, import_react_dom.createPortal)(content, root) : content;
32526
32498
  }
32527
- const holder = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
32499
+ const holder = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
32528
32500
  ScriptsContext.Provider,
32529
32501
  {
32530
32502
  value: scripts,
@@ -32535,10 +32507,10 @@ var OverlaysReact = (() => {
32535
32507
  return [holder, callback];
32536
32508
  }
32537
32509
  function useRefreshMetadata() {
32538
- const [props, setProps] = (0, import_react5.useState)();
32539
- const [refresh, setRefresh] = (0, import_react5.useState)(false);
32540
- const [visible, setVisible] = (0, import_react5.useState)(false);
32541
- const deferred = (0, import_react5.useRef)({});
32510
+ const [props, setProps] = (0, import_react4.useState)();
32511
+ const [refresh, setRefresh] = (0, import_react4.useState)(false);
32512
+ const [visible, setVisible] = (0, import_react4.useState)(false);
32513
+ const deferred = (0, import_react4.useRef)({});
32542
32514
  const scripts = {
32543
32515
  deferred: deferred.current,
32544
32516
  resolve: deferred.current.resolve,
@@ -32562,6 +32534,32 @@ var OverlaysReact = (() => {
32562
32534
  return { callback, scripts, props, refresh };
32563
32535
  }
32564
32536
 
32537
+ // src/composable/overlay.tsx
32538
+ var import_react5 = __toESM(require_react(), 1);
32539
+ var import_jsx_runtime2 = __toESM(require_jsx_runtime(), 1);
32540
+ var { define } = createConstructor((Instance, props, options) => {
32541
+ const { id, deferred, render, vanish: _vanish } = options;
32542
+ const InstanceWithProvider = defineAnonymousComponent(() => {
32543
+ const content = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
32544
+ ScriptsContext.Provider,
32545
+ {
32546
+ value: useScripts({ deferred, vanish }),
32547
+ ...{ id: pascalCase(id) },
32548
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Instance, { ...props })
32549
+ }
32550
+ );
32551
+ return content;
32552
+ });
32553
+ function vanish() {
32554
+ _vanish(InstanceWithProvider);
32555
+ }
32556
+ render(InstanceWithProvider, props);
32557
+ }, { container: false });
32558
+ function useOverlay(Instance) {
32559
+ const { render, vanish } = (0, import_react5.useContext)(InstancesContext);
32560
+ return define(Instance, { render, vanish });
32561
+ }
32562
+
32565
32563
  // src/define/constructor.tsx
32566
32564
  var import_client = __toESM(require_client(), 1);
32567
32565
  var import_jsx_runtime3 = __toESM(require_jsx_runtime(), 1);
@@ -32591,6 +32589,23 @@ var OverlaysReact = (() => {
32591
32589
  // src/define/index.ts
32592
32590
  var defineOverlay = constructor.define;
32593
32591
  var renderOverlay = constructor.render;
32592
+
32593
+ // src/components/OverlayProvider.tsx
32594
+ var import_react6 = __toESM(require_react(), 1);
32595
+ var import_jsx_runtime4 = __toESM(require_jsx_runtime(), 1);
32596
+ function OverlayProvider(props) {
32597
+ const [instances, setInstances] = (0, import_react6.useState)([]);
32598
+ function render(Instance, props2) {
32599
+ setInstances((instances2) => [...instances2, { Instance, props: props2 }]);
32600
+ }
32601
+ function vanish(instance) {
32602
+ setInstances((instances2) => [...instances2.filter(({ Instance }) => instance !== Instance)]);
32603
+ }
32604
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(InstancesContext.Provider, { value: { render, vanish }, children: [
32605
+ instances.map(({ Instance, props: props2 }, index) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Instance, { ...props2 }, index)),
32606
+ props.children
32607
+ ] });
32608
+ }
32594
32609
  return __toCommonJS(src_exports);
32595
32610
  })();
32596
32611
  /*! Bundled license information:
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- // src/composable/usePrograms.ts
1
+ // src/composable/define.ts
2
2
  import { delay, noop as noop2 } from "@overlastic/core";
3
3
  import { useContext, useEffect } from "react";
4
4
 
@@ -22,8 +22,8 @@ function defineAnonymousComponent(component) {
22
22
  return { "--": component }["--"];
23
23
  }
24
24
 
25
- // src/composable/usePrograms.ts
26
- function usePrograms(options = {}) {
25
+ // src/composable/define.ts
26
+ function useOverlayDefine(options = {}) {
27
27
  const { immediate = true, duration = 0, automatic = true } = options;
28
28
  const context = useContext(ScriptsContext);
29
29
  const dec = Reflect.get(context, "in_dec");
@@ -66,7 +66,7 @@ function useMount(callback = noop2) {
66
66
  useEffect(() => callback(), []);
67
67
  }
68
68
 
69
- // src/composable/useScripts.ts
69
+ // src/composable/scripts.ts
70
70
  import { useState } from "react";
71
71
  function useScripts(options) {
72
72
  const { reject: _reject } = options.deferred || {};
@@ -86,42 +86,12 @@ function useScripts(options) {
86
86
  };
87
87
  }
88
88
 
89
- // src/composable/useOverlay.tsx
90
- import { createConstructor } from "@overlastic/core";
91
- import { useContext as useContext2 } from "react";
92
- import { pascalCase } from "pascal-case";
93
- import { createPortal } from "react-dom";
94
- import { jsx } from "react/jsx-runtime";
95
- var { define } = createConstructor((Instance, props, options) => {
96
- const { container, id, deferred, render, vanish: _vanish } = options;
97
- const InstanceWithProvider = defineAnonymousComponent(() => {
98
- const content = /* @__PURE__ */ jsx(
99
- ScriptsContext.Provider,
100
- {
101
- value: useScripts({ deferred, vanish }),
102
- ...{ id: pascalCase(id) },
103
- children: /* @__PURE__ */ jsx(Instance, { ...props })
104
- }
105
- );
106
- return createPortal(content, container);
107
- });
108
- function vanish() {
109
- _vanish(InstanceWithProvider);
110
- container.remove();
111
- }
112
- render(InstanceWithProvider, props);
113
- });
114
- function useOverlay(Instance) {
115
- const { render, vanish } = useContext2(InstancesContext);
116
- return define(Instance, { render, vanish });
117
- }
118
-
119
- // src/composable/useOverlayHolder.tsx
89
+ // src/composable/holder.tsx
120
90
  import { createDeferred, defineName } from "@overlastic/core";
121
- import { pascalCase as pascalCase2 } from "pascal-case";
91
+ import { pascalCase } from "pascal-case";
122
92
  import { useRef, useState as useState2 } from "react";
123
- import { createPortal as createPortal2 } from "react-dom";
124
- import { jsx as jsx2, jsxs } from "react/jsx-runtime";
93
+ import { createPortal } from "react-dom";
94
+ import { jsx, jsxs } from "react/jsx-runtime";
125
95
  function useOverlayHolder(Component, options = {}) {
126
96
  const { callback, scripts, props, refresh } = useRefreshMetadata();
127
97
  const name = defineName(options.id, options.autoIncrement);
@@ -129,16 +99,16 @@ function useOverlayHolder(Component, options = {}) {
129
99
  const root = options.root || (typeof document !== "undefined" ? document.body : void 0);
130
100
  const content = /* @__PURE__ */ jsxs("div", { id: name, children: [
131
101
  " ",
132
- /* @__PURE__ */ jsx2(Component, { ...props }),
102
+ /* @__PURE__ */ jsx(Component, { ...props }),
133
103
  " "
134
104
  ] });
135
- return options.root !== false && root ? createPortal2(content, root) : content;
105
+ return options.root !== false && root ? createPortal(content, root) : content;
136
106
  }
137
- const holder = /* @__PURE__ */ jsx2(
107
+ const holder = /* @__PURE__ */ jsx(
138
108
  ScriptsContext.Provider,
139
109
  {
140
110
  value: scripts,
141
- ...{ id: pascalCase2(name) },
111
+ ...{ id: pascalCase(name) },
142
112
  children: refresh ? render() : null
143
113
  }
144
114
  );
@@ -172,6 +142,34 @@ function useRefreshMetadata() {
172
142
  return { callback, scripts, props, refresh };
173
143
  }
174
144
 
145
+ // src/composable/overlay.tsx
146
+ import { createConstructor } from "@overlastic/core";
147
+ import { useContext as useContext2 } from "react";
148
+ import { pascalCase as pascalCase2 } from "pascal-case";
149
+ import { jsx as jsx2 } from "react/jsx-runtime";
150
+ var { define } = createConstructor((Instance, props, options) => {
151
+ const { id, deferred, render, vanish: _vanish } = options;
152
+ const InstanceWithProvider = defineAnonymousComponent(() => {
153
+ const content = /* @__PURE__ */ jsx2(
154
+ ScriptsContext.Provider,
155
+ {
156
+ value: useScripts({ deferred, vanish }),
157
+ ...{ id: pascalCase2(id) },
158
+ children: /* @__PURE__ */ jsx2(Instance, { ...props })
159
+ }
160
+ );
161
+ return content;
162
+ });
163
+ function vanish() {
164
+ _vanish(InstanceWithProvider);
165
+ }
166
+ render(InstanceWithProvider, props);
167
+ }, { container: false });
168
+ function useOverlay(Instance) {
169
+ const { render, vanish } = useContext2(InstancesContext);
170
+ return define(Instance, { render, vanish });
171
+ }
172
+
175
173
  // src/define/constructor.tsx
176
174
  import { createConstructor as createConstructor2 } from "@overlastic/core";
177
175
  import { createRoot } from "react-dom/client";
@@ -203,10 +201,28 @@ var constructor = createConstructor2((Instance, props, options) => {
203
201
  // src/define/index.ts
204
202
  var defineOverlay = constructor.define;
205
203
  var renderOverlay = constructor.render;
204
+
205
+ // src/components/OverlayProvider.tsx
206
+ import { useState as useState3 } from "react";
207
+ import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
208
+ function OverlayProvider(props) {
209
+ const [instances, setInstances] = useState3([]);
210
+ function render(Instance, props2) {
211
+ setInstances((instances2) => [...instances2, { Instance, props: props2 }]);
212
+ }
213
+ function vanish(instance) {
214
+ setInstances((instances2) => [...instances2.filter(({ Instance }) => instance !== Instance)]);
215
+ }
216
+ return /* @__PURE__ */ jsxs2(InstancesContext.Provider, { value: { render, vanish }, children: [
217
+ instances.map(({ Instance, props: props2 }, index) => /* @__PURE__ */ jsx4(Instance, { ...props2 }, index)),
218
+ props.children
219
+ ] });
220
+ }
206
221
  export {
222
+ OverlayProvider,
207
223
  defineOverlay,
208
224
  renderOverlay,
209
225
  useOverlay,
210
- useOverlayHolder,
211
- usePrograms
226
+ useOverlayDefine,
227
+ useOverlayHolder
212
228
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@overlastic/react",
3
3
  "type": "module",
4
- "version": "0.4.8",
4
+ "version": "0.5.0",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/hairyf/overlastic#readme",
7
7
  "repository": {
@@ -32,7 +32,7 @@
32
32
  "pascal-case": "3.1.2",
33
33
  "react": "^18.3.1",
34
34
  "react-dom": "^18.3.1",
35
- "@overlastic/core": "^0.4.3"
35
+ "@overlastic/core": "^0.5.0"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@types/react": "^18.3.2",