@grucloud/bau-ui 0.63.0 → 0.63.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  import classNames from "@grucloud/bau-css/classNames.js";
2
2
 
3
3
  export default function (context, options = {}) {
4
- const { bau } = context;
4
+ const { bau, window } = context;
5
5
  const { div } = bau.tags;
6
6
  const noop = () => undefined;
7
7
 
@@ -17,36 +17,40 @@ export default function (context, options = {}) {
17
17
  [...record.removedNodes].forEach((childNode) => {
18
18
  if (!animationHide() || childNode.getAttribute("cloned")) return;
19
19
  const nodeCloned = childNode.cloneNode(true);
20
- nodeCloned.setAttribute("cloned", true);
21
- nodeCloned.style.top = 0;
22
- nodeCloned.style.left = 0;
23
- nodeCloned.style.width = childNode.getAttribute("width");
24
- nodeCloned.style.height = childNode.getAttribute("height");
25
- nodeCloned.style.position = "absolute";
26
- nodeCloned.style.animation = animationHide();
27
- record.target.appendChild(nodeCloned);
28
- nodeCloned.addEventListener("animationend", () =>
29
- nodeCloned.parentNode?.removeChild(nodeCloned)
30
- );
20
+ window.requestAnimationFrame(() => {
21
+ nodeCloned.setAttribute("cloned", true);
22
+ nodeCloned.style.top = 0;
23
+ nodeCloned.style.left = 0;
24
+ nodeCloned.style.width = childNode.getAttribute("width");
25
+ nodeCloned.style.height = childNode.getAttribute("height");
26
+ nodeCloned.style.position = "absolute";
27
+ nodeCloned.style.animation = animationHide();
28
+ record.target.appendChild(nodeCloned);
29
+ nodeCloned.addEventListener("animationend", () =>
30
+ nodeCloned.parentNode?.removeChild(nodeCloned)
31
+ );
32
+ });
31
33
  });
32
34
  // Added Nodes
33
35
  [...record.addedNodes].forEach((childNode) => {
34
36
  if (childNode.getAttribute("cloned")) return;
35
- element.style.position = "relative";
36
- const rect = childNode.getBoundingClientRect();
37
- childNode.setAttribute("width", rect.width + "px");
38
- childNode.setAttribute("height", rect.height + "px");
39
- if (animationShow()) {
40
- childNode.style.animation = animationShow();
41
- const animationEndHandler = () => {
42
- childNode.removeEventListener(
43
- "animationend",
44
- animationEndHandler
45
- );
46
- childNode.style.animation = "";
47
- };
48
- childNode.addEventListener("animationend", animationEndHandler);
49
- }
37
+ window.requestAnimationFrame(() => {
38
+ element.style.position = "relative";
39
+ const rect = childNode.getBoundingClientRect();
40
+ childNode.setAttribute("width", rect.width + "px");
41
+ childNode.setAttribute("height", rect.height + "px");
42
+ if (animationShow()) {
43
+ childNode.style.animation = animationShow();
44
+ const animationEndHandler = () => {
45
+ childNode.removeEventListener(
46
+ "animationend",
47
+ animationEndHandler
48
+ );
49
+ childNode.style.animation = "";
50
+ };
51
+ childNode.addEventListener("animationend", animationEndHandler);
52
+ }
53
+ });
50
54
  });
51
55
  },
52
56
  ...props,
@@ -1,4 +1,3 @@
1
- import { toPropsAndChildren } from "@grucloud/bau/bau.js";
2
1
  import cn from "@grucloud/bau-css/classNames.js";
3
2
  import animate from "../animate/animate.js";
4
3
  import button from "../button/button.js";
@@ -220,7 +219,7 @@ export default function (context, options = {}) {
220
219
  let currentTree = treeAddParent({})({ ...tree });
221
220
  let subTree = findSubTree(pathname)(currentTree);
222
221
  if (!subTree) {
223
- // console.error("drilldown no sub tree", pathname);
222
+ //console.error("drilldown no sub tree", pathname);
224
223
  subTree = currentTree;
225
224
  }
226
225
  return subTree;
@@ -230,23 +229,14 @@ export default function (context, options = {}) {
230
229
  window.location.pathname.replace(baseUrl, "")
231
230
  );
232
231
 
233
- window.document.addEventListener("click", (event) => {
234
- const { target } = event;
235
- const href = target.getAttribute("href");
236
- if (
237
- target.tagName === "A" &&
238
- href &&
239
- !href.startsWith("http") &&
240
- !href.startsWith("#") &&
241
- !href.startsWith("?")
242
- ) {
243
- let path = href.replace(baseUrl, "");
244
- if (!hashBased) {
245
- path = path.replace(target.hash, "");
246
- }
247
- pathnameState.val = path;
232
+ const pathFromHref = ({ target }) => {
233
+ const href = target.closest("a").getAttribute("href");
234
+ let path = href.replace(baseUrl, "");
235
+ if (!hashBased) {
236
+ path = path.replace(target.hash, "");
248
237
  }
249
- });
238
+ return path;
239
+ };
250
240
 
251
241
  return function DrillDownMenu(props) {
252
242
  const {
@@ -256,30 +246,52 @@ export default function (context, options = {}) {
256
246
  tree,
257
247
  ...otherProps
258
248
  } = props;
259
- let _currentTree;
260
- let currentTreeState = bau.derive(() => {
261
- _currentTree = findInitialTree({
262
- tree,
263
- pathname: pathnameState.val,
264
- });
265
- return _currentTree;
249
+
250
+ let _currentTree = findInitialTree({
251
+ tree,
252
+ pathname: pathnameState.val,
266
253
  });
267
254
 
268
- let directionState = bau.state(0);
255
+ let _direction;
256
+ window.document.addEventListener("click", (event) => {
257
+ const { target } = event;
258
+ const anchor = target.closest("a");
259
+ if (!anchor) return;
260
+ const href = anchor.getAttribute("href");
261
+
262
+ if (
263
+ href &&
264
+ !href.startsWith("http") &&
265
+ !href.startsWith("#") &&
266
+ !href.startsWith("?")
267
+ ) {
268
+ _currentTree = findInitialTree({
269
+ tree,
270
+ pathname: pathFromHref(event),
271
+ });
272
+ console.log("direction", _direction);
273
+
274
+ const { ischild } = event.target.dataset;
275
+
276
+ if (ischild !== "true") {
277
+ pathnameState.val = pathFromHref({ target });
278
+ }
279
+ }
280
+ });
269
281
 
270
282
  const onclick = (event) => {
271
- const { dataset } = event.target;
272
- if (dataset.buttonback == "true") {
273
- directionState.val = -1;
274
- } else if (dataset.ischild == "false") {
275
- directionState.val = 1;
276
- } else if (dataset.ischild == "true") {
277
- //direction = 0;
283
+ const { buttonback, ischild } = event.target.dataset;
284
+ if (buttonback == "true") {
285
+ _direction = -1;
286
+ } else if (ischild == "false") {
287
+ _direction = 1;
288
+ } else if (ischild == "true") {
289
+ _direction = 0;
278
290
  }
279
291
  };
280
292
 
281
- const animationHide = (directionState) => {
282
- switch (directionState.val) {
293
+ const animationHide = (direction) => {
294
+ switch (direction) {
283
295
  case 1:
284
296
  return `${hideToLeft} ${animationDuration}`;
285
297
  case -1:
@@ -289,8 +301,8 @@ export default function (context, options = {}) {
289
301
  }
290
302
  };
291
303
 
292
- const animationShow = (directionState) => {
293
- switch (directionState.val) {
304
+ const animationShow = (direction) => {
305
+ switch (direction) {
294
306
  case 1:
295
307
  return `${hideToRight} ${animationDuration} reverse`;
296
308
  case -1:
@@ -314,11 +326,11 @@ export default function (context, options = {}) {
314
326
  },
315
327
  Animate(
316
328
  {
317
- animationHide: () => animationHide(directionState),
318
- animationShow: () => animationShow(directionState),
329
+ animationHide: () => animationHide(_direction),
330
+ animationShow: () => animationShow(_direction),
319
331
  },
320
332
  bau.bind({
321
- deps: [directionState],
333
+ deps: [pathnameState],
322
334
  render: () => () =>
323
335
  Menu({
324
336
  variant,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@grucloud/bau-ui",
3
3
  "description": "Components library built with Bau",
4
- "version": "0.63.0",
4
+ "version": "0.63.1",
5
5
  "type": "module",
6
6
  "license": "BSD",
7
7
  "keywords": [
@@ -26,5 +26,5 @@
26
26
  "devDependencies": {
27
27
  "typedoc": "0.24.8"
28
28
  },
29
- "gitHead": "ba14ec686f27ecca6fba9dd765862f85ea77e554"
29
+ "gitHead": "d83473dc2d988c6e4d1c2d589c65c9e52605f4cd"
30
30
  }