@vinena/knobs 0.6.0 → 0.6.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # changelog
2
2
 
3
+ ## 0.6.1
4
+
5
+ - the `keep edits after reload` switch is in the settings now, with a short hint under it, and no longer at the top of the Elements view. as before, it is not there in fresh mode or in the copy of devknobs inside its own frame, which keeps nothing itself; the page's keeper still keeps edits made in the frame
6
+ - the line between the DOM tree and the styles is a full-width drag handle, also moved with ↑ ↓
7
+
3
8
  ## 0.6.0
4
9
 
5
10
  - every edit field in inspect, the DOM tree's texts and attributes, the html editor and the styles' values, wraps its lines and grows down, so a long value or address never scrolls sideways, at any panel width and in the width knob's frame
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Edits kept after a reload. With the Elements view's switch on, the edits
2
+ * Edits kept after a reload. With the settings' keep switch on, the edits
3
3
  * in force are kept for the page, its address without the query, as plain
4
4
  * json: each one's kind, target, property and values, no node of the page.
5
5
  * As the page loads again and settles, the kept edits are made again in
@@ -91,7 +91,6 @@ import {
91
91
  filterField,
92
92
  sectionFold,
93
93
  segments,
94
- switchLine,
95
94
  toolToggle,
96
95
  toolbar
97
96
  } from "./index-4a4x1bt2.js";
@@ -3562,7 +3561,7 @@ function createStylesView(context, page = PAGE) {
3562
3561
 
3563
3562
  // src/ui/elementsview.ts
3564
3563
  var DOLLAR = "$0";
3565
- var KEEP_LABEL = "keep edits after reload";
3564
+ var TREE_MIN = 96;
3566
3565
  function undoKey(event) {
3567
3566
  if (!letterMatches(event, "z") || event.metaKey || event.ctrlKey || event.altKey)
3568
3567
  return null;
@@ -3641,19 +3640,76 @@ function createElementsView(context, parts = {}) {
3641
3640
  }, parts.page);
3642
3641
  const keep = parts.keep === undefined ? keeper() : parts.keep;
3643
3642
  const changes = createChanges(log, copy, undefined, keep, context.diff ?? null);
3644
- const keepSwitch = keep ? switchLine({ label: KEEP_LABEL, on: keep.on(), onChange: (on) => keep.set(on) }) : null;
3645
- keepSwitch?.node.classList.add("keep-line");
3646
- const syncKeep = () => {
3647
- if (!keep || !keepSwitch)
3643
+ const split = el("div", "dom-split");
3644
+ split.setAttribute("role", "separator");
3645
+ split.setAttribute("aria-orientation", "horizontal");
3646
+ split.setAttribute("aria-label", "drag to resize the DOM tree");
3647
+ split.setAttribute("aria-valuemin", String(TREE_MIN));
3648
+ split.tabIndex = 0;
3649
+ node.append(tree.node, split, styles.node, changes.node);
3650
+ function tallest() {
3651
+ const view = tree.node.ownerDocument?.defaultView ?? window;
3652
+ return Math.max(TREE_MIN, Math.round(view.innerHeight * 0.85));
3653
+ }
3654
+ function tell(most, now) {
3655
+ split.setAttribute("aria-valuemax", String(most));
3656
+ split.setAttribute("aria-valuenow", String(now));
3657
+ }
3658
+ function measure() {
3659
+ tell(tallest(), Math.round(tree.node.offsetHeight));
3660
+ }
3661
+ function size(height) {
3662
+ const most = tallest();
3663
+ const next = Math.round(Math.min(most, Math.max(TREE_MIN, height)));
3664
+ tree.node.style.height = `${next}px`;
3665
+ tell(most, next);
3666
+ }
3667
+ const frameView = tree.node.ownerDocument?.defaultView ?? window;
3668
+ const firstFrame = frameView.requestAnimationFrame?.(measure);
3669
+ let stopDrag = null;
3670
+ function onSplitDown(event) {
3671
+ if (event.button !== 0)
3648
3672
  return;
3649
- keepSwitch.set(keep.on());
3650
- keepSwitch.control.disabled = !keep.known();
3651
- };
3652
- syncKeep();
3653
- const stopKeep = keep ? keep.subscribe(syncKeep) : null;
3654
- if (keepSwitch)
3655
- node.append(keepSwitch.node);
3656
- node.append(tree.node, styles.node, changes.node);
3673
+ stopDrag?.();
3674
+ event.preventDefault();
3675
+ const id = event.pointerId;
3676
+ const from = event.clientY;
3677
+ const was = tree.node.offsetHeight;
3678
+ split.setPointerCapture?.(id);
3679
+ split.setAttribute("data-drag", "true");
3680
+ const move = (next) => {
3681
+ if (next.pointerId === id)
3682
+ size(was + next.clientY - from);
3683
+ };
3684
+ const end = (next) => {
3685
+ if (next.pointerId === id)
3686
+ up();
3687
+ };
3688
+ const up = () => {
3689
+ split.removeEventListener("pointermove", move);
3690
+ split.removeEventListener("pointerup", end);
3691
+ split.removeEventListener("pointercancel", end);
3692
+ split.removeEventListener("lostpointercapture", end);
3693
+ split.removeAttribute("data-drag");
3694
+ stopDrag = null;
3695
+ };
3696
+ stopDrag = up;
3697
+ split.addEventListener("pointermove", move);
3698
+ split.addEventListener("pointerup", end);
3699
+ split.addEventListener("pointercancel", end);
3700
+ split.addEventListener("lostpointercapture", end);
3701
+ }
3702
+ function onSplitKey(event) {
3703
+ if (event.key !== "ArrowUp" && event.key !== "ArrowDown")
3704
+ return;
3705
+ event.preventDefault();
3706
+ event.stopPropagation();
3707
+ const step = event.shiftKey ? 64 : 16;
3708
+ size(tree.node.offsetHeight + (event.key === "ArrowDown" ? step : -step));
3709
+ }
3710
+ split.addEventListener("pointerdown", onSplitDown);
3711
+ split.addEventListener("keydown", onSplitKey);
3712
+ split.addEventListener("focus", measure);
3657
3713
  function onKeydown(event) {
3658
3714
  const key = undoKey(event);
3659
3715
  if (!key)
@@ -3683,8 +3739,13 @@ function createElementsView(context, parts = {}) {
3683
3739
  focus: () => styles.focus(),
3684
3740
  destroy() {
3685
3741
  node.removeEventListener("keydown", onKeydown);
3742
+ stopDrag?.();
3743
+ split.removeEventListener("pointerdown", onSplitDown);
3744
+ split.removeEventListener("keydown", onSplitKey);
3745
+ split.removeEventListener("focus", measure);
3746
+ if (firstFrame !== undefined)
3747
+ frameView.cancelAnimationFrame?.(firstFrame);
3686
3748
  stopFollow();
3687
- stopKeep?.();
3688
3749
  tree.destroy();
3689
3750
  styles.destroy();
3690
3751
  changes.destroy();
@@ -3696,6 +3757,5 @@ export {
3696
3757
  undoKey,
3697
3758
  createElementsView,
3698
3759
  createDollar,
3699
- KEEP_LABEL,
3700
3760
  DOLLAR
3701
3761
  };
@@ -92,7 +92,6 @@ import {
92
92
  filterField,
93
93
  sectionFold,
94
94
  segments,
95
- switchLine,
96
95
  toolToggle,
97
96
  toolbar
98
97
  } from "./react-bxzn8vq5.js";
@@ -3563,7 +3562,7 @@ function createStylesView(context, page = PAGE) {
3563
3562
 
3564
3563
  // src/ui/elementsview.ts
3565
3564
  var DOLLAR = "$0";
3566
- var KEEP_LABEL = "keep edits after reload";
3565
+ var TREE_MIN = 96;
3567
3566
  function undoKey(event) {
3568
3567
  if (!letterMatches(event, "z") || event.metaKey || event.ctrlKey || event.altKey)
3569
3568
  return null;
@@ -3642,19 +3641,76 @@ function createElementsView(context, parts = {}) {
3642
3641
  }, parts.page);
3643
3642
  const keep = parts.keep === undefined ? keeper() : parts.keep;
3644
3643
  const changes = createChanges(log, copy, undefined, keep, context.diff ?? null);
3645
- const keepSwitch = keep ? switchLine({ label: KEEP_LABEL, on: keep.on(), onChange: (on) => keep.set(on) }) : null;
3646
- keepSwitch?.node.classList.add("keep-line");
3647
- const syncKeep = () => {
3648
- if (!keep || !keepSwitch)
3644
+ const split = el("div", "dom-split");
3645
+ split.setAttribute("role", "separator");
3646
+ split.setAttribute("aria-orientation", "horizontal");
3647
+ split.setAttribute("aria-label", "drag to resize the DOM tree");
3648
+ split.setAttribute("aria-valuemin", String(TREE_MIN));
3649
+ split.tabIndex = 0;
3650
+ node.append(tree.node, split, styles.node, changes.node);
3651
+ function tallest() {
3652
+ const view = tree.node.ownerDocument?.defaultView ?? window;
3653
+ return Math.max(TREE_MIN, Math.round(view.innerHeight * 0.85));
3654
+ }
3655
+ function tell(most, now) {
3656
+ split.setAttribute("aria-valuemax", String(most));
3657
+ split.setAttribute("aria-valuenow", String(now));
3658
+ }
3659
+ function measure() {
3660
+ tell(tallest(), Math.round(tree.node.offsetHeight));
3661
+ }
3662
+ function size(height) {
3663
+ const most = tallest();
3664
+ const next = Math.round(Math.min(most, Math.max(TREE_MIN, height)));
3665
+ tree.node.style.height = `${next}px`;
3666
+ tell(most, next);
3667
+ }
3668
+ const frameView = tree.node.ownerDocument?.defaultView ?? window;
3669
+ const firstFrame = frameView.requestAnimationFrame?.(measure);
3670
+ let stopDrag = null;
3671
+ function onSplitDown(event) {
3672
+ if (event.button !== 0)
3649
3673
  return;
3650
- keepSwitch.set(keep.on());
3651
- keepSwitch.control.disabled = !keep.known();
3652
- };
3653
- syncKeep();
3654
- const stopKeep = keep ? keep.subscribe(syncKeep) : null;
3655
- if (keepSwitch)
3656
- node.append(keepSwitch.node);
3657
- node.append(tree.node, styles.node, changes.node);
3674
+ stopDrag?.();
3675
+ event.preventDefault();
3676
+ const id = event.pointerId;
3677
+ const from = event.clientY;
3678
+ const was = tree.node.offsetHeight;
3679
+ split.setPointerCapture?.(id);
3680
+ split.setAttribute("data-drag", "true");
3681
+ const move = (next) => {
3682
+ if (next.pointerId === id)
3683
+ size(was + next.clientY - from);
3684
+ };
3685
+ const end = (next) => {
3686
+ if (next.pointerId === id)
3687
+ up();
3688
+ };
3689
+ const up = () => {
3690
+ split.removeEventListener("pointermove", move);
3691
+ split.removeEventListener("pointerup", end);
3692
+ split.removeEventListener("pointercancel", end);
3693
+ split.removeEventListener("lostpointercapture", end);
3694
+ split.removeAttribute("data-drag");
3695
+ stopDrag = null;
3696
+ };
3697
+ stopDrag = up;
3698
+ split.addEventListener("pointermove", move);
3699
+ split.addEventListener("pointerup", end);
3700
+ split.addEventListener("pointercancel", end);
3701
+ split.addEventListener("lostpointercapture", end);
3702
+ }
3703
+ function onSplitKey(event) {
3704
+ if (event.key !== "ArrowUp" && event.key !== "ArrowDown")
3705
+ return;
3706
+ event.preventDefault();
3707
+ event.stopPropagation();
3708
+ const step = event.shiftKey ? 64 : 16;
3709
+ size(tree.node.offsetHeight + (event.key === "ArrowDown" ? step : -step));
3710
+ }
3711
+ split.addEventListener("pointerdown", onSplitDown);
3712
+ split.addEventListener("keydown", onSplitKey);
3713
+ split.addEventListener("focus", measure);
3658
3714
  function onKeydown(event) {
3659
3715
  const key = undoKey(event);
3660
3716
  if (!key)
@@ -3684,8 +3740,13 @@ function createElementsView(context, parts = {}) {
3684
3740
  focus: () => styles.focus(),
3685
3741
  destroy() {
3686
3742
  node.removeEventListener("keydown", onKeydown);
3743
+ stopDrag?.();
3744
+ split.removeEventListener("pointerdown", onSplitDown);
3745
+ split.removeEventListener("keydown", onSplitKey);
3746
+ split.removeEventListener("focus", measure);
3747
+ if (firstFrame !== undefined)
3748
+ frameView.cancelAnimationFrame?.(firstFrame);
3687
3749
  stopFollow();
3688
- stopKeep?.();
3689
3750
  tree.destroy();
3690
3751
  styles.destroy();
3691
3752
  changes.destroy();
@@ -3697,6 +3758,5 @@ export {
3697
3758
  undoKey,
3698
3759
  createElementsView,
3699
3760
  createDollar,
3700
- KEEP_LABEL,
3701
3761
  DOLLAR
3702
3762
  };