framepexls-ui-lib 0.1.17 → 0.1.19

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/dist/Dropdown.js CHANGED
@@ -39,7 +39,7 @@ __export(Dropdown_exports, {
39
39
  });
40
40
  module.exports = __toCommonJS(Dropdown_exports);
41
41
  var import_jsx_runtime = require("react/jsx-runtime");
42
- var import_react = require("react");
42
+ var import_react = __toESM(require("react"));
43
43
  var import_react_dom = require("react-dom");
44
44
  var import_iconos = require("./iconos/index");
45
45
  var import_Button = __toESM(require("./Button"));
@@ -165,7 +165,7 @@ function Content({
165
165
  className = "",
166
166
  maxHeight = 360
167
167
  }) {
168
- const { open, setOpen, triggerRef, menuRef, menuId, labelId, align } = useDropdown();
168
+ const { open, setOpen, triggerRef, menuRef, menuId, labelId, align, isAllowed, defaultHideUnauthorized } = useDropdown();
169
169
  const [pos, setPos] = (0, import_react.useState)({ top: 0, left: 0, origin: "top-left", maxH: maxHeight });
170
170
  const computePosition = (0, import_react.useCallback)(() => {
171
171
  var _a, _b;
@@ -220,6 +220,49 @@ function Content({
220
220
  (_e = items[(i - 1 + items.length) % items.length]) == null ? void 0 : _e.focus();
221
221
  }
222
222
  };
223
+ const normalizedChildren = (0, import_react.useMemo)(() => {
224
+ const arr = import_react.default.Children.toArray(children);
225
+ const list = arr.map((ch) => {
226
+ var _a, _b, _c;
227
+ if (import_react.default.isValidElement(ch)) {
228
+ const el = ch;
229
+ if (el.type === Separator) {
230
+ return { node: ch, kind: "SEP", visible: true };
231
+ }
232
+ if (el.type === Item) {
233
+ const require2 = (_a = el.props) == null ? void 0 : _a.require;
234
+ const hideIfUnauthorized = (_c = (_b = el.props) == null ? void 0 : _b.hideIfUnauthorized) != null ? _c : defaultHideUnauthorized;
235
+ const allowed = typeof isAllowed === "function" ? isAllowed(require2) : true;
236
+ const visible = hideIfUnauthorized ? !!allowed : true;
237
+ return { node: ch, kind: "ITEM", visible };
238
+ }
239
+ }
240
+ return { node: ch, kind: "OTHER", visible: true };
241
+ });
242
+ let filtered = list.filter((it) => it.visible);
243
+ const out = [];
244
+ for (const it of filtered) {
245
+ if (it.kind === "SEP") {
246
+ const prev = out.length > 0 ? out[out.length - 1] : null;
247
+ const prevIsSep = prev && import_react.default.isValidElement(prev) && prev.type === Separator;
248
+ if (prevIsSep) continue;
249
+ out.push(it.node);
250
+ } else {
251
+ out.push(it.node);
252
+ }
253
+ }
254
+ while (out.length > 0) {
255
+ const first = out[0];
256
+ if (import_react.default.isValidElement(first) && first.type === Separator) out.shift();
257
+ else break;
258
+ }
259
+ while (out.length > 0) {
260
+ const last = out[out.length - 1];
261
+ if (import_react.default.isValidElement(last) && last.type === Separator) out.pop();
262
+ else break;
263
+ }
264
+ return out;
265
+ }, [children, isAllowed, defaultHideUnauthorized]);
223
266
  if (!open) return null;
224
267
  return (0, import_react_dom.createPortal)(
225
268
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
@@ -246,7 +289,7 @@ function Content({
246
289
  className
247
290
  ].join(" "),
248
291
  "data-open": "true",
249
- children
292
+ children: normalizedChildren
250
293
  }
251
294
  ),
252
295
  document.body
package/dist/Dropdown.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { jsx, jsxs } from "react/jsx-runtime";
3
- import {
3
+ import React, {
4
4
  createContext,
5
5
  useCallback,
6
6
  useContext,
@@ -135,7 +135,7 @@ function Content({
135
135
  className = "",
136
136
  maxHeight = 360
137
137
  }) {
138
- const { open, setOpen, triggerRef, menuRef, menuId, labelId, align } = useDropdown();
138
+ const { open, setOpen, triggerRef, menuRef, menuId, labelId, align, isAllowed, defaultHideUnauthorized } = useDropdown();
139
139
  const [pos, setPos] = useState({ top: 0, left: 0, origin: "top-left", maxH: maxHeight });
140
140
  const computePosition = useCallback(() => {
141
141
  var _a, _b;
@@ -190,6 +190,49 @@ function Content({
190
190
  (_e = items[(i - 1 + items.length) % items.length]) == null ? void 0 : _e.focus();
191
191
  }
192
192
  };
193
+ const normalizedChildren = useMemo(() => {
194
+ const arr = React.Children.toArray(children);
195
+ const list = arr.map((ch) => {
196
+ var _a, _b, _c;
197
+ if (React.isValidElement(ch)) {
198
+ const el = ch;
199
+ if (el.type === Separator) {
200
+ return { node: ch, kind: "SEP", visible: true };
201
+ }
202
+ if (el.type === Item) {
203
+ const require2 = (_a = el.props) == null ? void 0 : _a.require;
204
+ const hideIfUnauthorized = (_c = (_b = el.props) == null ? void 0 : _b.hideIfUnauthorized) != null ? _c : defaultHideUnauthorized;
205
+ const allowed = typeof isAllowed === "function" ? isAllowed(require2) : true;
206
+ const visible = hideIfUnauthorized ? !!allowed : true;
207
+ return { node: ch, kind: "ITEM", visible };
208
+ }
209
+ }
210
+ return { node: ch, kind: "OTHER", visible: true };
211
+ });
212
+ let filtered = list.filter((it) => it.visible);
213
+ const out = [];
214
+ for (const it of filtered) {
215
+ if (it.kind === "SEP") {
216
+ const prev = out.length > 0 ? out[out.length - 1] : null;
217
+ const prevIsSep = prev && React.isValidElement(prev) && prev.type === Separator;
218
+ if (prevIsSep) continue;
219
+ out.push(it.node);
220
+ } else {
221
+ out.push(it.node);
222
+ }
223
+ }
224
+ while (out.length > 0) {
225
+ const first = out[0];
226
+ if (React.isValidElement(first) && first.type === Separator) out.shift();
227
+ else break;
228
+ }
229
+ while (out.length > 0) {
230
+ const last = out[out.length - 1];
231
+ if (React.isValidElement(last) && last.type === Separator) out.pop();
232
+ else break;
233
+ }
234
+ return out;
235
+ }, [children, isAllowed, defaultHideUnauthorized]);
193
236
  if (!open) return null;
194
237
  return createPortal(
195
238
  /* @__PURE__ */ jsx(
@@ -216,7 +259,7 @@ function Content({
216
259
  className
217
260
  ].join(" "),
218
261
  "data-open": "true",
219
- children
262
+ children: normalizedChildren
220
263
  }
221
264
  ),
222
265
  document.body
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "framepexls-ui-lib",
3
- "version": "0.1.17",
3
+ "version": "0.1.19",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "description": "Componentes UI de Framepexls para React/Next.",