@hanzogui/z-index-stack 2.0.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 +21 -0
- package/dist/cjs/StackZIndex.cjs +42 -0
- package/dist/cjs/StackZIndex.native.js +46 -0
- package/dist/cjs/StackZIndex.native.js.map +1 -0
- package/dist/cjs/context.cjs +29 -0
- package/dist/cjs/context.native.js +32 -0
- package/dist/cjs/context.native.js.map +1 -0
- package/dist/cjs/index.cjs +20 -0
- package/dist/cjs/index.native.js +23 -0
- package/dist/cjs/index.native.js.map +1 -0
- package/dist/cjs/types.cjs +16 -0
- package/dist/cjs/types.native.js +19 -0
- package/dist/cjs/types.native.js.map +1 -0
- package/dist/cjs/useStackedZIndex.cjs +80 -0
- package/dist/cjs/useStackedZIndex.native.js +89 -0
- package/dist/cjs/useStackedZIndex.native.js.map +1 -0
- package/dist/esm/StackZIndex.mjs +19 -0
- package/dist/esm/StackZIndex.mjs.map +1 -0
- package/dist/esm/StackZIndex.native.js +20 -0
- package/dist/esm/StackZIndex.native.js.map +1 -0
- package/dist/esm/context.mjs +5 -0
- package/dist/esm/context.mjs.map +1 -0
- package/dist/esm/context.native.js +5 -0
- package/dist/esm/context.native.js.map +1 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/index.mjs +4 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/index.native.js +4 -0
- package/dist/esm/index.native.js.map +1 -0
- package/dist/esm/types.mjs +2 -0
- package/dist/esm/types.mjs.map +1 -0
- package/dist/esm/types.native.js +2 -0
- package/dist/esm/types.native.js.map +1 -0
- package/dist/esm/useStackedZIndex.mjs +57 -0
- package/dist/esm/useStackedZIndex.mjs.map +1 -0
- package/dist/esm/useStackedZIndex.native.js +63 -0
- package/dist/esm/useStackedZIndex.native.js.map +1 -0
- package/package.json +45 -0
- package/src/StackZIndex.tsx +28 -0
- package/src/context.ts +7 -0
- package/src/index.ts +4 -0
- package/src/types.ts +16 -0
- package/src/useStackedZIndex.tsx +91 -0
- package/types/StackZIndex.d.ts +5 -0
- package/types/context.d.ts +3 -0
- package/types/index.d.ts +5 -0
- package/types/types.d.ts +17 -0
- package/types/useStackedZIndex.d.ts +6 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Nate Wienert
|
|
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.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: !0
|
|
9
|
+
});
|
|
10
|
+
},
|
|
11
|
+
__copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
13
|
+
get: () => from[key],
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
19
|
+
value: !0
|
|
20
|
+
}), mod);
|
|
21
|
+
var StackZIndex_exports = {};
|
|
22
|
+
__export(StackZIndex_exports, {
|
|
23
|
+
StackZIndexContext: () => StackZIndexContext
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(StackZIndex_exports);
|
|
26
|
+
var import_react = require("react"),
|
|
27
|
+
import_context = require("./context.cjs"),
|
|
28
|
+
import_jsx_runtime = require("react/jsx-runtime");
|
|
29
|
+
const StackZIndexContext = ({
|
|
30
|
+
children,
|
|
31
|
+
zIndex
|
|
32
|
+
}) => {
|
|
33
|
+
const existing = (0, import_react.useContext)(import_context.ZIndexStackContext);
|
|
34
|
+
let content = /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_context.ZIndexStackContext.Provider, {
|
|
35
|
+
value: existing + 1,
|
|
36
|
+
children
|
|
37
|
+
});
|
|
38
|
+
return typeof zIndex < "u" && (content = /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_context.ZIndexHardcodedContext.Provider, {
|
|
39
|
+
value: zIndex,
|
|
40
|
+
children: content
|
|
41
|
+
})), content;
|
|
42
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: !0
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
__copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
+
value: !0
|
|
22
|
+
}), mod);
|
|
23
|
+
var StackZIndex_exports = {};
|
|
24
|
+
__export(StackZIndex_exports, {
|
|
25
|
+
StackZIndexContext: () => StackZIndexContext
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(StackZIndex_exports);
|
|
28
|
+
var import_jsx_runtime = require("react/jsx-runtime"),
|
|
29
|
+
import_react = require("react"),
|
|
30
|
+
import_context = require("./context.native.js"),
|
|
31
|
+
StackZIndexContext = function (param) {
|
|
32
|
+
var {
|
|
33
|
+
children,
|
|
34
|
+
zIndex
|
|
35
|
+
} = param,
|
|
36
|
+
existing = (0, import_react.useContext)(import_context.ZIndexStackContext),
|
|
37
|
+
content = /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_context.ZIndexStackContext.Provider, {
|
|
38
|
+
value: existing + 1,
|
|
39
|
+
children
|
|
40
|
+
});
|
|
41
|
+
return typeof zIndex < "u" && (content = /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_context.ZIndexHardcodedContext.Provider, {
|
|
42
|
+
value: zIndex,
|
|
43
|
+
children: content
|
|
44
|
+
})), content;
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=StackZIndex.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","StackZIndex_exports","__export","StackZIndexContext","module","exports","import_jsx_runtime","require","import_react","import_context","param","children","zIndex","existing","useContext","ZIndexStackContext","content","jsx","Provider","ZIndexHardcodedContext"],"sources":["../../src/StackZIndex.tsx"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,mBAAA;AAAAC,QAAA,CAAAD,mBAAA;EAAAE,kBAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAT,YAA2B,CAAAK,mBAC3B;AAEO,IAAAK,kBAAM,GAAAC,OAAsB;EAAAC,YAAA,GAAAD,OAAA;EAAAE,cAAA,GAAAF,OAAA;EAAAJ,kBAAA,YAAAA,CAAAO,KAAA;IACjC;QAAAC,QAAA;QAAAC;MAAA,IAAAF,KAAA;MAAAG,QAAA,OAAAL,YAAA,CAAAM,UAAA,EAAAL,cAAA,CAAAM,kBAAA;MAAAC,OAAA,sBAAAV,kBAAA,CAAAW,GAAA,EAAAR,cAAA,CAAAM,kBAAA,CAAAG,QAAA;QACAlB,KAAA,EAAAa,QAAA;QACFF;MAIE;IAEA,OAAI,OACFC,MAAA,WAAAI,OAAA,mBAAC,GAAAV,kBAAA,CAAAW,GAAA,EAAAR,cAAmB,CAAAU,sBAA2B,CAAAD,QAC5C;MAILlB,KAAI,EAAAY,MAAO;MASbD,QAAA,EAAAK","ignoreList":[]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: !0
|
|
9
|
+
});
|
|
10
|
+
},
|
|
11
|
+
__copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
13
|
+
get: () => from[key],
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
19
|
+
value: !0
|
|
20
|
+
}), mod);
|
|
21
|
+
var context_exports = {};
|
|
22
|
+
__export(context_exports, {
|
|
23
|
+
ZIndexHardcodedContext: () => ZIndexHardcodedContext,
|
|
24
|
+
ZIndexStackContext: () => ZIndexStackContext
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(context_exports);
|
|
27
|
+
var import_react = require("react");
|
|
28
|
+
const ZIndexStackContext = (0, import_react.createContext)(1),
|
|
29
|
+
ZIndexHardcodedContext = (0, import_react.createContext)(void 0);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: !0
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
__copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
+
value: !0
|
|
22
|
+
}), mod);
|
|
23
|
+
var context_exports = {};
|
|
24
|
+
__export(context_exports, {
|
|
25
|
+
ZIndexHardcodedContext: () => ZIndexHardcodedContext,
|
|
26
|
+
ZIndexStackContext: () => ZIndexStackContext
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(context_exports);
|
|
29
|
+
var import_react = require("react"),
|
|
30
|
+
ZIndexStackContext = (0, import_react.createContext)(1),
|
|
31
|
+
ZIndexHardcodedContext = (0, import_react.createContext)(void 0);
|
|
32
|
+
//# sourceMappingURL=context.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","context_exports","__export","ZIndexHardcodedContext","ZIndexStackContext","module","exports","import_react","require","createContext"],"sources":["../../src/context.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,eAAA;AAAAC,QAAA,CAAAD,eAAA;EAAAE,sBAAA,EAAAA,CAAA,KAAAA,sBAAA;EAAAC,kBAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAV,YAA8B,CAAAK,eAAA;AAGvB,IAAAM,YAAM,GAAAC,OAAA,QAAqB;EAAAJ,kBAAA,IAAc,CAAC,EAAAG,YAGpC,CAAAE,aAAA,IAAyB;EAAAN,sBAAA,IAAkC,GAAAI,YAAS,CAAAE,aAAA","ignoreList":[]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
7
|
+
get: () => from[key],
|
|
8
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
9
|
+
});
|
|
10
|
+
return to;
|
|
11
|
+
},
|
|
12
|
+
__reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
13
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
14
|
+
value: !0
|
|
15
|
+
}), mod);
|
|
16
|
+
var index_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(index_exports);
|
|
18
|
+
__reExport(index_exports, require("./useStackedZIndex.cjs"), module.exports);
|
|
19
|
+
__reExport(index_exports, require("./StackZIndex.cjs"), module.exports);
|
|
20
|
+
__reExport(index_exports, require("./context.cjs"), module.exports);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __copyProps = (to, from, except, desc) => {
|
|
8
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
9
|
+
get: () => from[key],
|
|
10
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
11
|
+
});
|
|
12
|
+
return to;
|
|
13
|
+
},
|
|
14
|
+
__reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
16
|
+
value: !0
|
|
17
|
+
}), mod);
|
|
18
|
+
var index_exports = {};
|
|
19
|
+
module.exports = __toCommonJS(index_exports);
|
|
20
|
+
__reExport(index_exports, require("./useStackedZIndex.native.js"), module.exports);
|
|
21
|
+
__reExport(index_exports, require("./StackZIndex.native.js"), module.exports);
|
|
22
|
+
__reExport(index_exports, require("./context.native.js"), module.exports);
|
|
23
|
+
//# sourceMappingURL=index.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","index_exports","module","exports","__reExport","require"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,aAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAP,YAAc,CAAAK,aAAA;AACdG,UAAA,CAAAH,aAAA,EAAcI,OAAA,+BADd,GAAAH,MAAA,CAAAC,OAAA;AAEAC,UAAA,CAAAH,aAAA,EAAcI,OAAA,0BAFd,GAAAH,MAAA,CAAAC,OAAA","ignoreList":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
7
|
+
get: () => from[key],
|
|
8
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
9
|
+
});
|
|
10
|
+
return to;
|
|
11
|
+
};
|
|
12
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
13
|
+
value: !0
|
|
14
|
+
}), mod);
|
|
15
|
+
var types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_exports);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __copyProps = (to, from, except, desc) => {
|
|
8
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
9
|
+
get: () => from[key],
|
|
10
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
11
|
+
});
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
15
|
+
value: !0
|
|
16
|
+
}), mod);
|
|
17
|
+
var types_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(types_exports);
|
|
19
|
+
//# sourceMappingURL=types.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","types_exports"],"sources":["../../src/types.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,aAAA","ignoreList":[]}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: !0
|
|
9
|
+
});
|
|
10
|
+
},
|
|
11
|
+
__copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
13
|
+
get: () => from[key],
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
19
|
+
value: !0
|
|
20
|
+
}), mod);
|
|
21
|
+
var useStackedZIndex_exports = {};
|
|
22
|
+
__export(useStackedZIndex_exports, {
|
|
23
|
+
useStackedZIndex: () => useStackedZIndex
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(useStackedZIndex_exports);
|
|
26
|
+
var import_react = require("react"),
|
|
27
|
+
import_context = require("./context.cjs");
|
|
28
|
+
const ZIndicesByContext = {},
|
|
29
|
+
CurrentPortalZIndices = {},
|
|
30
|
+
useStackedZIndex = props => {
|
|
31
|
+
if (process.env.HANZO_GUI_STACK_Z_INDEX_GLOBAL) {
|
|
32
|
+
const {
|
|
33
|
+
stackZIndex,
|
|
34
|
+
zIndex: zIndexProp
|
|
35
|
+
} = props,
|
|
36
|
+
id = (0, import_react.useId)(),
|
|
37
|
+
zIndex = (0, import_react.useMemo)(() => {
|
|
38
|
+
if (stackZIndex && stackZIndex !== "global" && zIndexProp === void 0) {
|
|
39
|
+
const highest = Object.values(CurrentPortalZIndices).reduce((acc, cur) => Math.max(acc, cur), 0);
|
|
40
|
+
return Math.max(stackZIndex === !0 ? 1 : stackZIndex, highest + 1);
|
|
41
|
+
}
|
|
42
|
+
return zIndexProp ?? 1e3;
|
|
43
|
+
}, [stackZIndex]);
|
|
44
|
+
return (0, import_react.useEffect)(() => {
|
|
45
|
+
if (typeof stackZIndex == "number") return CurrentPortalZIndices[id] = stackZIndex, () => {
|
|
46
|
+
delete CurrentPortalZIndices[id];
|
|
47
|
+
};
|
|
48
|
+
}, [stackZIndex]), zIndex;
|
|
49
|
+
} else {
|
|
50
|
+
const {
|
|
51
|
+
stackZIndex,
|
|
52
|
+
zIndex: zIndexProp
|
|
53
|
+
} = props,
|
|
54
|
+
id = (0, import_react.useId)(),
|
|
55
|
+
stackingContextLevel = (0, import_react.useContext)(import_context.ZIndexStackContext),
|
|
56
|
+
stackLayer = stackZIndex === "global" ? 0 : stackingContextLevel,
|
|
57
|
+
hardcoded = (0, import_react.useContext)(import_context.ZIndexHardcodedContext);
|
|
58
|
+
ZIndicesByContext[stackLayer] ||= {};
|
|
59
|
+
const stackContext = ZIndicesByContext[stackLayer],
|
|
60
|
+
zIndex = (0, import_react.useMemo)(() => {
|
|
61
|
+
if (typeof zIndexProp == "number") return zIndexProp;
|
|
62
|
+
if (stackZIndex) {
|
|
63
|
+
if (hardcoded) return hardcoded + 1;
|
|
64
|
+
const entries = Object.values(stackContext),
|
|
65
|
+
baseForLayer = stackLayer * 5e3,
|
|
66
|
+
nextLayerBase = (stackLayer + 1) * 5e3,
|
|
67
|
+
validEntries = entries.filter(z => z < nextLayerBase),
|
|
68
|
+
highest = validEntries.length > 0 ? Math.max(...validEntries) : baseForLayer,
|
|
69
|
+
nextZIndex = highest === baseForLayer ? baseForLayer + 1 : highest + 1;
|
|
70
|
+
return typeof stackZIndex == "number" ? stackZIndex + nextZIndex : nextZIndex;
|
|
71
|
+
}
|
|
72
|
+
return 1;
|
|
73
|
+
}, [stackLayer, zIndexProp, stackZIndex]);
|
|
74
|
+
return (0, import_react.useEffect)(() => {
|
|
75
|
+
if (stackZIndex) return stackContext[id] = zIndex, () => {
|
|
76
|
+
delete stackContext[id];
|
|
77
|
+
};
|
|
78
|
+
}, [zIndex]), zIndex;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: !0
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
__copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
+
value: !0
|
|
22
|
+
}), mod);
|
|
23
|
+
var useStackedZIndex_exports = {};
|
|
24
|
+
__export(useStackedZIndex_exports, {
|
|
25
|
+
useStackedZIndex: () => useStackedZIndex
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(useStackedZIndex_exports);
|
|
28
|
+
var import_react = require("react"),
|
|
29
|
+
import_context = require("./context.native.js"),
|
|
30
|
+
ZIndicesByContext = {},
|
|
31
|
+
CurrentPortalZIndices = {},
|
|
32
|
+
useStackedZIndex = function (props) {
|
|
33
|
+
if (process.env.HANZO_GUI_STACK_Z_INDEX_GLOBAL) {
|
|
34
|
+
var {
|
|
35
|
+
stackZIndex,
|
|
36
|
+
zIndex: zIndexProp
|
|
37
|
+
} = props,
|
|
38
|
+
id = (0, import_react.useId)(),
|
|
39
|
+
zIndex = (0, import_react.useMemo)(function () {
|
|
40
|
+
if (stackZIndex && stackZIndex !== "global" && zIndexProp === void 0) {
|
|
41
|
+
var highest = Object.values(CurrentPortalZIndices).reduce(function (acc, cur) {
|
|
42
|
+
return Math.max(acc, cur);
|
|
43
|
+
}, 0);
|
|
44
|
+
return Math.max(stackZIndex === !0 ? 1 : stackZIndex, highest + 1);
|
|
45
|
+
}
|
|
46
|
+
return zIndexProp ?? 1e3;
|
|
47
|
+
}, [stackZIndex]);
|
|
48
|
+
return (0, import_react.useEffect)(function () {
|
|
49
|
+
if (typeof stackZIndex == "number") return CurrentPortalZIndices[id] = stackZIndex, function () {
|
|
50
|
+
delete CurrentPortalZIndices[id];
|
|
51
|
+
};
|
|
52
|
+
}, [stackZIndex]), zIndex;
|
|
53
|
+
} else {
|
|
54
|
+
var _ZIndicesByContext,
|
|
55
|
+
_stackLayer,
|
|
56
|
+
{
|
|
57
|
+
stackZIndex: stackZIndex1,
|
|
58
|
+
zIndex: zIndexProp1
|
|
59
|
+
} = props,
|
|
60
|
+
id1 = (0, import_react.useId)(),
|
|
61
|
+
stackingContextLevel = (0, import_react.useContext)(import_context.ZIndexStackContext),
|
|
62
|
+
stackLayer = stackZIndex1 === "global" ? 0 : stackingContextLevel,
|
|
63
|
+
hardcoded = (0, import_react.useContext)(import_context.ZIndexHardcodedContext);
|
|
64
|
+
(_ZIndicesByContext = ZIndicesByContext)[_stackLayer = stackLayer] || (_ZIndicesByContext[_stackLayer] = {});
|
|
65
|
+
var stackContext = ZIndicesByContext[stackLayer],
|
|
66
|
+
zIndex1 = (0, import_react.useMemo)(function () {
|
|
67
|
+
if (typeof zIndexProp1 == "number") return zIndexProp1;
|
|
68
|
+
if (stackZIndex1) {
|
|
69
|
+
if (hardcoded) return hardcoded + 1;
|
|
70
|
+
var entries = Object.values(stackContext),
|
|
71
|
+
baseForLayer = stackLayer * 5e3,
|
|
72
|
+
nextLayerBase = (stackLayer + 1) * 5e3,
|
|
73
|
+
validEntries = entries.filter(function (z) {
|
|
74
|
+
return z < nextLayerBase;
|
|
75
|
+
}),
|
|
76
|
+
highest = validEntries.length > 0 ? Math.max(...validEntries) : baseForLayer,
|
|
77
|
+
nextZIndex = highest === baseForLayer ? baseForLayer + 1 : highest + 1;
|
|
78
|
+
return typeof stackZIndex1 == "number" ? stackZIndex1 + nextZIndex : nextZIndex;
|
|
79
|
+
}
|
|
80
|
+
return 1;
|
|
81
|
+
}, [stackLayer, zIndexProp1, stackZIndex1]);
|
|
82
|
+
return (0, import_react.useEffect)(function () {
|
|
83
|
+
if (stackZIndex1) return stackContext[id1] = zIndex1, function () {
|
|
84
|
+
delete stackContext[id1];
|
|
85
|
+
};
|
|
86
|
+
}, [zIndex1]), zIndex1;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
//# sourceMappingURL=useStackedZIndex.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","useStackedZIndex_exports","__export","useStackedZIndex","module","exports","import_react","require","import_context","ZIndicesByContext","CurrentPortalZIndices","props","process","env","HANZO_GUI_STACK_Z_INDEX_GLOBAL","stackZIndex","zIndex","zIndexProp","id","useId","useMemo","highest","Object","values","reduce","acc","cur","Math","max","useEffect","_ZIndicesByContext","_stackLayer","stackZIndex1","zIndexProp1","id1","stackingContextLevel","useContext","ZIndexStackContext","stackLayer","hardcoded","ZIndexHardcodedContext","stackContext","zIndex1","entries","baseForLayer","nextLayerBase","validEntries","filter","z","length","nextZIndex"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
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
const StackZIndexContext = ({
|
|
5
|
+
children,
|
|
6
|
+
zIndex
|
|
7
|
+
}) => {
|
|
8
|
+
const existing = useContext(ZIndexStackContext);
|
|
9
|
+
let content = /* @__PURE__ */jsx(ZIndexStackContext.Provider, {
|
|
10
|
+
value: existing + 1,
|
|
11
|
+
children
|
|
12
|
+
});
|
|
13
|
+
return typeof zIndex < "u" && (content = /* @__PURE__ */jsx(ZIndexHardcodedContext.Provider, {
|
|
14
|
+
value: zIndex,
|
|
15
|
+
children: content
|
|
16
|
+
})), content;
|
|
17
|
+
};
|
|
18
|
+
export { StackZIndexContext };
|
|
19
|
+
//# sourceMappingURL=StackZIndex.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useContext","ZIndexHardcodedContext","ZIndexStackContext","jsx","StackZIndexContext","children","zIndex","existing","content","Provider","value"],"sources":["../../src/StackZIndex.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAASA,UAAA,QAAkB;AAC3B,SAASC,sBAAA,EAAwBC,kBAAA,QAA0B;AAYvD,SAAAC,GAAA;AAVG,MAAMC,kBAAA,GAAqBA,CAAC;EACjCC,QAAA;EACAC;AACF,MAGM;EACJ,MAAMC,QAAA,GAAWP,UAAA,CAAWE,kBAAkB;EAE9C,IAAIM,OAAA,GACF,eAAAL,GAAA,CAACD,kBAAA,CAAmBO,QAAA,EAAnB;IAA4BC,KAAA,EAAOH,QAAA,GAAW;IAC5CF;EAAA,CACH;EAGF,OAAI,OAAOC,MAAA,GAAW,QACpBE,OAAA,GACE,eAAAL,GAAA,CAACF,sBAAA,CAAuBQ,QAAA,EAAvB;IAAgCC,KAAA,EAAOJ,MAAA;IACrCD,QAAA,EAAAG;EAAA,CACH,IAIGA,OAAA;AACT","ignoreList":[]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useContext } from "react";
|
|
3
|
+
import { ZIndexHardcodedContext, ZIndexStackContext } from "./context.native.js";
|
|
4
|
+
var StackZIndexContext = function (param) {
|
|
5
|
+
var {
|
|
6
|
+
children,
|
|
7
|
+
zIndex
|
|
8
|
+
} = param,
|
|
9
|
+
existing = useContext(ZIndexStackContext),
|
|
10
|
+
content = /* @__PURE__ */_jsx(ZIndexStackContext.Provider, {
|
|
11
|
+
value: existing + 1,
|
|
12
|
+
children
|
|
13
|
+
});
|
|
14
|
+
return typeof zIndex < "u" && (content = /* @__PURE__ */_jsx(ZIndexHardcodedContext.Provider, {
|
|
15
|
+
value: zIndex,
|
|
16
|
+
children: content
|
|
17
|
+
})), content;
|
|
18
|
+
};
|
|
19
|
+
export { StackZIndexContext };
|
|
20
|
+
//# sourceMappingURL=StackZIndex.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["jsx","_jsx","useContext","ZIndexHardcodedContext","ZIndexStackContext","StackZIndexContext","param","children","zIndex","existing","content","Provider","value"],"sources":["../../src/StackZIndex.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAASA,GAAA,IAAAC,IAAA,QAAkB;AAC3B,SAASC,UAAA,eAAwB;AAY7B,SAAAC,sBAAA,EAAAC,kBAAA;AAVG,IAAAC,kBAAM,YAAAA,CAAsBC,KAAA;EACjC;MAAAC,QAAA;MAAAC;IAAA,IAAAF,KAAA;IAAAG,QAAA,GAAAP,UAAA,CAAAE,kBAAA;IAAAM,OAAA,kBAAAT,IAAA,CAAAG,kBAAA,CAAAO,QAAA;MACAC,KAAA,EAAAH,QAAA;MACFF;IAIE;EAEA,OAAI,OACFC,MAAA,WAAAE,OAAC,kBAAmBT,IAAA,CAAAE,sBAA2B,CAAAQ,QAC5C;IAILC,KAAI,EAAAJ,MAAO;IASbD,QAAA,EAAAG","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createContext","ZIndexStackContext","ZIndexHardcodedContext"],"sources":["../../src/context.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,aAAA,QAAqB;AAGvB,MAAMC,kBAAA,GAAqBD,aAAA,CAAc,CAAC;EAGpCE,sBAAA,GAAyBF,aAAA,CAAkC,MAAS","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createContext","ZIndexStackContext","ZIndexHardcodedContext"],"sources":["../../src/context.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,aAAA,QAAqB;AAGvB,IAAAC,kBAAM,GAAAD,aAAqB,GAAc;EAACE,sBAGpC,GAAAF,aAAyB,MAAkC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":[],"sourcesContent":[],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":[],"sourcesContent":[],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { useContext, useEffect, useId, useMemo } from "react";
|
|
2
|
+
import { ZIndexHardcodedContext, ZIndexStackContext } from "./context.mjs";
|
|
3
|
+
const ZIndicesByContext = {},
|
|
4
|
+
CurrentPortalZIndices = {},
|
|
5
|
+
useStackedZIndex = props => {
|
|
6
|
+
if (process.env.HANZO_GUI_STACK_Z_INDEX_GLOBAL) {
|
|
7
|
+
const {
|
|
8
|
+
stackZIndex,
|
|
9
|
+
zIndex: zIndexProp
|
|
10
|
+
} = props,
|
|
11
|
+
id = useId(),
|
|
12
|
+
zIndex = useMemo(() => {
|
|
13
|
+
if (stackZIndex && stackZIndex !== "global" && zIndexProp === void 0) {
|
|
14
|
+
const highest = Object.values(CurrentPortalZIndices).reduce((acc, cur) => Math.max(acc, cur), 0);
|
|
15
|
+
return Math.max(stackZIndex === !0 ? 1 : stackZIndex, highest + 1);
|
|
16
|
+
}
|
|
17
|
+
return zIndexProp ?? 1e3;
|
|
18
|
+
}, [stackZIndex]);
|
|
19
|
+
return useEffect(() => {
|
|
20
|
+
if (typeof stackZIndex == "number") return CurrentPortalZIndices[id] = stackZIndex, () => {
|
|
21
|
+
delete CurrentPortalZIndices[id];
|
|
22
|
+
};
|
|
23
|
+
}, [stackZIndex]), zIndex;
|
|
24
|
+
} else {
|
|
25
|
+
const {
|
|
26
|
+
stackZIndex,
|
|
27
|
+
zIndex: zIndexProp
|
|
28
|
+
} = props,
|
|
29
|
+
id = useId(),
|
|
30
|
+
stackingContextLevel = useContext(ZIndexStackContext),
|
|
31
|
+
stackLayer = stackZIndex === "global" ? 0 : stackingContextLevel,
|
|
32
|
+
hardcoded = useContext(ZIndexHardcodedContext);
|
|
33
|
+
ZIndicesByContext[stackLayer] ||= {};
|
|
34
|
+
const stackContext = ZIndicesByContext[stackLayer],
|
|
35
|
+
zIndex = useMemo(() => {
|
|
36
|
+
if (typeof zIndexProp == "number") return zIndexProp;
|
|
37
|
+
if (stackZIndex) {
|
|
38
|
+
if (hardcoded) return hardcoded + 1;
|
|
39
|
+
const entries = Object.values(stackContext),
|
|
40
|
+
baseForLayer = stackLayer * 5e3,
|
|
41
|
+
nextLayerBase = (stackLayer + 1) * 5e3,
|
|
42
|
+
validEntries = entries.filter(z => z < nextLayerBase),
|
|
43
|
+
highest = validEntries.length > 0 ? Math.max(...validEntries) : baseForLayer,
|
|
44
|
+
nextZIndex = highest === baseForLayer ? baseForLayer + 1 : highest + 1;
|
|
45
|
+
return typeof stackZIndex == "number" ? stackZIndex + nextZIndex : nextZIndex;
|
|
46
|
+
}
|
|
47
|
+
return 1;
|
|
48
|
+
}, [stackLayer, zIndexProp, stackZIndex]);
|
|
49
|
+
return useEffect(() => {
|
|
50
|
+
if (stackZIndex) return stackContext[id] = zIndex, () => {
|
|
51
|
+
delete stackContext[id];
|
|
52
|
+
};
|
|
53
|
+
}, [zIndex]), zIndex;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
export { useStackedZIndex };
|
|
57
|
+
//# sourceMappingURL=useStackedZIndex.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useContext","useEffect","useId","useMemo","ZIndexHardcodedContext","ZIndexStackContext","ZIndicesByContext","CurrentPortalZIndices","useStackedZIndex","props","process","env","HANZO_GUI_STACK_Z_INDEX_GLOBAL","stackZIndex","zIndex","zIndexProp","id","highest","Object","values","reduce","acc","cur","Math","max","stackingContextLevel","stackLayer","hardcoded","stackContext","entries","baseForLayer","nextLayerBase","validEntries","filter","z","length","nextZIndex"],"sources":["../../src/useStackedZIndex.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAASA,UAAA,EAAYC,SAAA,EAAWC,KAAA,EAAOC,OAAA,QAAe;AACtD,SAASC,sBAAA,EAAwBC,kBAAA,QAA0B;AAI3D,MAAMC,iBAAA,GAA4D,CAAC;EAG7DC,qBAAA,GAAgD,CAAC;EAE1CC,gBAAA,GAAoBC,KAAA,IAG3B;IACJ,IAAIC,OAAA,CAAQC,GAAA,CAAIC,8BAAA,EAAgC;MAC9C,MAAM;UAAEC,WAAA;UAAaC,MAAA,EAAQC;QAAW,IAAIN,KAAA;QACtCO,EAAA,GAAKd,KAAA,CAAM;QAEXY,MAAA,GAASX,OAAA,CAAQ,MAAM;UAC3B,IAAIU,WAAA,IAAeA,WAAA,KAAgB,YAAYE,UAAA,KAAe,QAAW;YACvE,MAAME,OAAA,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AEtDd,OAAA,GAAUe,YAAA,CAAaG,MAAA,GAAS,IAAIZ,IAAA,CAAKC,GAAA,CAAI,GAAGQ,YAAY,IAAIF,YAAA;cAGhEM,UAAA,GAAanB,OAAA,KAAYa,YAAA,GAAeA,YAAA,GAAe,IAAIb,OAAA,GAAU;YAG3E,OAAO,OAAOJ,WAAA,IAAgB,WAAWA,WAAA,GAAcuB,UAAA,GAAaA,UAAA;UACtE;UAEA,OAAO;QACT,GAAG,CAACV,UAAA,EAAYX,UAAA,EAAYF,WAAW,CAAC;MAExC,OAAAZ,SAAA,CAAU,MAAM;QACd,IAAIY,WAAA,EACF,OAAAe,YAAA,CAAaZ,EAAE,IAAIF,MAAA,EACZ,MAAM;UACX,OAAOc,YAAA,CAAaZ,EAAE;QACxB;MAEJ,GAAG,CAACF,MAAM,CAAC,GAEJA,MAAA;IACT;EACF","ignoreList":[]}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { useContext, useEffect, useId, useMemo } from "react";
|
|
2
|
+
import { ZIndexHardcodedContext, ZIndexStackContext } from "./context.native.js";
|
|
3
|
+
var ZIndicesByContext = {},
|
|
4
|
+
CurrentPortalZIndices = {},
|
|
5
|
+
useStackedZIndex = function (props) {
|
|
6
|
+
if (process.env.HANZO_GUI_STACK_Z_INDEX_GLOBAL) {
|
|
7
|
+
var {
|
|
8
|
+
stackZIndex,
|
|
9
|
+
zIndex: zIndexProp
|
|
10
|
+
} = props,
|
|
11
|
+
id = useId(),
|
|
12
|
+
zIndex = useMemo(function () {
|
|
13
|
+
if (stackZIndex && stackZIndex !== "global" && zIndexProp === void 0) {
|
|
14
|
+
var highest = Object.values(CurrentPortalZIndices).reduce(function (acc, cur) {
|
|
15
|
+
return Math.max(acc, cur);
|
|
16
|
+
}, 0);
|
|
17
|
+
return Math.max(stackZIndex === !0 ? 1 : stackZIndex, highest + 1);
|
|
18
|
+
}
|
|
19
|
+
return zIndexProp ?? 1e3;
|
|
20
|
+
}, [stackZIndex]);
|
|
21
|
+
return useEffect(function () {
|
|
22
|
+
if (typeof stackZIndex == "number") return CurrentPortalZIndices[id] = stackZIndex, function () {
|
|
23
|
+
delete CurrentPortalZIndices[id];
|
|
24
|
+
};
|
|
25
|
+
}, [stackZIndex]), zIndex;
|
|
26
|
+
} else {
|
|
27
|
+
var _ZIndicesByContext,
|
|
28
|
+
_stackLayer,
|
|
29
|
+
{
|
|
30
|
+
stackZIndex: stackZIndex1,
|
|
31
|
+
zIndex: zIndexProp1
|
|
32
|
+
} = props,
|
|
33
|
+
id1 = useId(),
|
|
34
|
+
stackingContextLevel = useContext(ZIndexStackContext),
|
|
35
|
+
stackLayer = stackZIndex1 === "global" ? 0 : stackingContextLevel,
|
|
36
|
+
hardcoded = useContext(ZIndexHardcodedContext);
|
|
37
|
+
(_ZIndicesByContext = ZIndicesByContext)[_stackLayer = stackLayer] || (_ZIndicesByContext[_stackLayer] = {});
|
|
38
|
+
var stackContext = ZIndicesByContext[stackLayer],
|
|
39
|
+
zIndex1 = useMemo(function () {
|
|
40
|
+
if (typeof zIndexProp1 == "number") return zIndexProp1;
|
|
41
|
+
if (stackZIndex1) {
|
|
42
|
+
if (hardcoded) return hardcoded + 1;
|
|
43
|
+
var entries = Object.values(stackContext),
|
|
44
|
+
baseForLayer = stackLayer * 5e3,
|
|
45
|
+
nextLayerBase = (stackLayer + 1) * 5e3,
|
|
46
|
+
validEntries = entries.filter(function (z) {
|
|
47
|
+
return z < nextLayerBase;
|
|
48
|
+
}),
|
|
49
|
+
highest = validEntries.length > 0 ? Math.max(...validEntries) : baseForLayer,
|
|
50
|
+
nextZIndex = highest === baseForLayer ? baseForLayer + 1 : highest + 1;
|
|
51
|
+
return typeof stackZIndex1 == "number" ? stackZIndex1 + nextZIndex : nextZIndex;
|
|
52
|
+
}
|
|
53
|
+
return 1;
|
|
54
|
+
}, [stackLayer, zIndexProp1, stackZIndex1]);
|
|
55
|
+
return useEffect(function () {
|
|
56
|
+
if (stackZIndex1) return stackContext[id1] = zIndex1, function () {
|
|
57
|
+
delete stackContext[id1];
|
|
58
|
+
};
|
|
59
|
+
}, [zIndex1]), zIndex1;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
export { useStackedZIndex };
|
|
63
|
+
//# sourceMappingURL=useStackedZIndex.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useContext","useEffect","useId","useMemo","ZIndexHardcodedContext","ZIndexStackContext","ZIndicesByContext","CurrentPortalZIndices","useStackedZIndex","props","process","env","HANZO_GUI_STACK_Z_INDEX_GLOBAL","stackZIndex","zIndex","zIndexProp","id","highest","Object","values","reduce","acc","cur","Math","max","_ZIndicesByContext","_stackLayer","stackZIndex1","zIndexProp1","id1","stackingContextLevel","stackLayer","hardcoded","stackContext","zIndex1","entries","baseForLayer","nextLayerBase","validEntries","filter","z","length","nextZIndex"],"sources":["../../src/useStackedZIndex.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAASA,UAAA,EAAYC,SAAA,EAAWC,KAAA,EAAOC,OAAA,QAAe;AACtD,SAASC,sBAAA,EAAwBC,kBAAA,QAA0B;AAI3D,IAAAC,iBAAM,KAA4D;EAACC,qBAG7D,KAAgD;EAACC,gBAE1C,YAAAA,CAAoBC,KAG3B;IACJ,IAAIC,OAAA,CAAQC,GAAA,CAAIC,8BAAA,EAAgC;MAC9C;UAAMC,WAAE;UAAAC,MAAa,EAAAC;QAAQ,IAAWN,KAAI;QAAAO,EACtC,GAAAd,KAAK;QAAMY,MAEX,GAAAX,OAAS,aAAc;UAC3B,IAAIU,WAAA,IAAeA,WAAA,KAAgB,YAAYE,UAAA,KAAe,QAAW;YACvE,IAAAE,OAAM,GAAAC,MAAU,CAAAC,MAAO,CAAAZ,qBAAO,EAAqBa,MAAE,WAAAC,GAAA,EAAAC,GAAA;cACnD,OAAMC,IAAA,CAAAC,GAAQ,CAAAH,GAAK,EAAAC,GAAI;YAAQ,GAC/B;YACF,OAAAC,IAAA,CAAAC,GAAA,CAAAX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AAA;UACF;UAEE;QAAsB,IAG5BX,UAAW,EAGbH,WAAA,EACFD,YAAA,C","ignoreList":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hanzogui/z-index-stack",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"source": "src/index.ts",
|
|
5
|
+
"files": [
|
|
6
|
+
"src",
|
|
7
|
+
"types",
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"type": "module",
|
|
11
|
+
"sideEffects": [
|
|
12
|
+
"*.css"
|
|
13
|
+
],
|
|
14
|
+
"main": "dist/cjs",
|
|
15
|
+
"module": "dist/esm",
|
|
16
|
+
"types": "./types/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
"./package.json": "./package.json",
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./types/index.d.ts",
|
|
21
|
+
"react-native": "./dist/esm/index.native.js",
|
|
22
|
+
"browser": "./dist/esm/index.mjs",
|
|
23
|
+
"module": "./dist/esm/index.mjs",
|
|
24
|
+
"import": "./dist/esm/index.mjs",
|
|
25
|
+
"require": "./dist/cjs/index.cjs",
|
|
26
|
+
"default": "./dist/esm/index.mjs"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "hanzo-gui-build",
|
|
34
|
+
"watch": "hanzo-gui-build --watch",
|
|
35
|
+
"clean": "hanzo-gui-build clean",
|
|
36
|
+
"clean:build": "hanzo-gui-build clean:build"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@hanzogui/build": "2.0.0-rc.29",
|
|
40
|
+
"react": ">=19"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"react": ">=19"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useContext } from 'react'
|
|
2
|
+
import { ZIndexHardcodedContext, ZIndexStackContext } from './context'
|
|
3
|
+
|
|
4
|
+
export const StackZIndexContext = ({
|
|
5
|
+
children,
|
|
6
|
+
zIndex,
|
|
7
|
+
}: {
|
|
8
|
+
children: React.ReactNode
|
|
9
|
+
zIndex?: number
|
|
10
|
+
}) => {
|
|
11
|
+
const existing = useContext(ZIndexStackContext)
|
|
12
|
+
|
|
13
|
+
let content = (
|
|
14
|
+
<ZIndexStackContext.Provider value={existing + 1}>
|
|
15
|
+
{children}
|
|
16
|
+
</ZIndexStackContext.Provider>
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
if (typeof zIndex !== 'undefined') {
|
|
20
|
+
content = (
|
|
21
|
+
<ZIndexHardcodedContext.Provider value={zIndex}>
|
|
22
|
+
{content}
|
|
23
|
+
</ZIndexHardcodedContext.Provider>
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return content
|
|
28
|
+
}
|
package/src/context.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { createContext } from 'react'
|
|
2
|
+
|
|
3
|
+
// stacks vertically through tree, based on nesting
|
|
4
|
+
export const ZIndexStackContext = createContext(1)
|
|
5
|
+
|
|
6
|
+
// if setting to overriden z index
|
|
7
|
+
export const ZIndexHardcodedContext = createContext<number | undefined>(undefined)
|
package/src/index.ts
ADDED
package/src/types.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gui will attempt to stack z-index in a smart way when true, it does this
|
|
3
|
+
* by automatically increasing z-index both horizontally and vertically in the component tree.
|
|
4
|
+
*
|
|
5
|
+
* Basically - if two stackable items are at the same level, then the order of mounting
|
|
6
|
+
* determines their z-index (later is higher). This is the horizontal logic.
|
|
7
|
+
*
|
|
8
|
+
* Below a stackable item, the z-index will always be above that specific item, but below
|
|
9
|
+
* other horizontal items that come after it.
|
|
10
|
+
*
|
|
11
|
+
* - false will avoid the stacking behavior.
|
|
12
|
+
* - number will keep the behavior, but add to the stacked z-index the given amount
|
|
13
|
+
* - 'global' will not stack things vertically and instead only stack them horizontally
|
|
14
|
+
*
|
|
15
|
+
*/
|
|
16
|
+
export type StackZIndexProp = boolean | number | 'global'
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { useContext, useEffect, useId, useMemo } from 'react'
|
|
2
|
+
import { ZIndexHardcodedContext, ZIndexStackContext } from './context'
|
|
3
|
+
import type { StackZIndexProp } from './types'
|
|
4
|
+
|
|
5
|
+
// this stacks horizontally - just based on which mounted last within a stacking context
|
|
6
|
+
const ZIndicesByContext: Record<number, Record<string, number>> = {}
|
|
7
|
+
|
|
8
|
+
// old stacking style
|
|
9
|
+
const CurrentPortalZIndices: Record<string, number> = {}
|
|
10
|
+
|
|
11
|
+
export const useStackedZIndex = (props: {
|
|
12
|
+
zIndex?: number
|
|
13
|
+
stackZIndex?: StackZIndexProp
|
|
14
|
+
}) => {
|
|
15
|
+
if (process.env.HANZO_GUI_STACK_Z_INDEX_GLOBAL) {
|
|
16
|
+
const { stackZIndex, zIndex: zIndexProp } = props
|
|
17
|
+
const id = useId()
|
|
18
|
+
|
|
19
|
+
const zIndex = useMemo(() => {
|
|
20
|
+
if (stackZIndex && stackZIndex !== 'global' && zIndexProp === undefined) {
|
|
21
|
+
const highest = Object.values(CurrentPortalZIndices).reduce(
|
|
22
|
+
(acc, cur) => Math.max(acc, cur),
|
|
23
|
+
0
|
|
24
|
+
)
|
|
25
|
+
return Math.max(stackZIndex === true ? 1 : stackZIndex, highest + 1)
|
|
26
|
+
}
|
|
27
|
+
return zIndexProp ?? 1000
|
|
28
|
+
}, [stackZIndex])
|
|
29
|
+
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (typeof stackZIndex === 'number') {
|
|
32
|
+
CurrentPortalZIndices[id] = stackZIndex
|
|
33
|
+
return () => {
|
|
34
|
+
delete CurrentPortalZIndices[id]
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}, [stackZIndex])
|
|
38
|
+
|
|
39
|
+
return zIndex
|
|
40
|
+
} else {
|
|
41
|
+
const { stackZIndex, zIndex: zIndexProp } = props
|
|
42
|
+
const id = useId()
|
|
43
|
+
const stackingContextLevel = useContext(ZIndexStackContext)
|
|
44
|
+
const stackLayer = stackZIndex === 'global' ? 0 : stackingContextLevel
|
|
45
|
+
const hardcoded = useContext(ZIndexHardcodedContext)
|
|
46
|
+
|
|
47
|
+
ZIndicesByContext[stackLayer] ||= {}
|
|
48
|
+
const stackContext = ZIndicesByContext[stackLayer]
|
|
49
|
+
|
|
50
|
+
const zIndex = useMemo(() => {
|
|
51
|
+
if (typeof zIndexProp === 'number') {
|
|
52
|
+
return zIndexProp
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (stackZIndex) {
|
|
56
|
+
if (hardcoded) {
|
|
57
|
+
return hardcoded + 1
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const entries = Object.values(stackContext)
|
|
61
|
+
const baseForLayer = stackLayer * 5000
|
|
62
|
+
const nextLayerBase = (stackLayer + 1) * 5000
|
|
63
|
+
|
|
64
|
+
// Filter out values that belong to higher layers
|
|
65
|
+
// Any value >= next layer's base is definitely not from this layer
|
|
66
|
+
const validEntries = entries.filter((z) => z < nextLayerBase)
|
|
67
|
+
|
|
68
|
+
const highest = validEntries.length > 0 ? Math.max(...validEntries) : baseForLayer
|
|
69
|
+
|
|
70
|
+
// If we only have the base value or nothing, start fresh
|
|
71
|
+
const nextZIndex = highest === baseForLayer ? baseForLayer + 1 : highest + 1
|
|
72
|
+
|
|
73
|
+
// setting stackZIndex to a number lets you increase it further
|
|
74
|
+
return typeof stackZIndex === 'number' ? stackZIndex + nextZIndex : nextZIndex
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return 1
|
|
78
|
+
}, [stackLayer, zIndexProp, stackZIndex])
|
|
79
|
+
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
if (stackZIndex) {
|
|
82
|
+
stackContext[id] = zIndex
|
|
83
|
+
return () => {
|
|
84
|
+
delete stackContext[id]
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}, [zIndex])
|
|
88
|
+
|
|
89
|
+
return zIndex
|
|
90
|
+
}
|
|
91
|
+
}
|
package/types/index.d.ts
ADDED
package/types/types.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gui will attempt to stack z-index in a smart way when true, it does this
|
|
3
|
+
* by automatically increasing z-index both horizontally and vertically in the component tree.
|
|
4
|
+
*
|
|
5
|
+
* Basically - if two stackable items are at the same level, then the order of mounting
|
|
6
|
+
* determines their z-index (later is higher). This is the horizontal logic.
|
|
7
|
+
*
|
|
8
|
+
* Below a stackable item, the z-index will always be above that specific item, but below
|
|
9
|
+
* other horizontal items that come after it.
|
|
10
|
+
*
|
|
11
|
+
* - false will avoid the stacking behavior.
|
|
12
|
+
* - number will keep the behavior, but add to the stacked z-index the given amount
|
|
13
|
+
* - 'global' will not stack things vertically and instead only stack them horizontally
|
|
14
|
+
*
|
|
15
|
+
*/
|
|
16
|
+
export type StackZIndexProp = boolean | number | 'global';
|
|
17
|
+
//# sourceMappingURL=types.d.ts.map
|