@syware/jlib 0.17.0 → 0.17.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.
@@ -32,5 +32,9 @@ export declare function placeFloating(anchor: Element, floating: HTMLElement, pl
32
32
  * one in a shadow root (an app shell's main area) never leaves it: the window does not hear it, its element does.
33
33
  */
34
34
  export declare function whenAnchorMoves(anchor: Element, update: () => void, signal: AbortSignal): void;
35
- /** Keeps a floating element by its anchor while the page scrolls or resizes, until the signal aborts. */
35
+ /**
36
+ * Keeps a floating element by its anchor while the page scrolls or resizes, until the signal aborts. The element's
37
+ * own size is watched too: a panel whose content grows (a form that opens a second group of fields, a list that
38
+ * filters) is placed again with its new size, so it takes the side with room and stays inside the window.
39
+ */
36
40
  export declare function followAnchor(anchor: Element, floating: HTMLElement, placement: Placement, signal: AbortSignal, gap?: number): void;
@@ -1,3 +1,4 @@
1
+ import { watchSizes } from "./resize.js";
1
2
  // src/lib/floating.ts
2
3
  var PLACEMENTS = [
3
4
  "top",
@@ -209,12 +210,19 @@ function whenAnchorMoves(anchor, update, signal) {
209
210
  window.addEventListener("resize", update, options);
210
211
  for (const ancestor of flatAncestors(anchor)) ancestor.addEventListener("scroll", update, options);
211
212
  }
212
- /** Keeps a floating element by its anchor while the page scrolls or resizes, until the signal aborts. */
213
+ /**
214
+ * Keeps a floating element by its anchor while the page scrolls or resizes, until the signal aborts. The element's
215
+ * own size is watched too: a panel whose content grows (a form that opens a second group of fields, a list that
216
+ * filters) is placed again with its new size, so it takes the side with room and stays inside the window.
217
+ */
213
218
  function followAnchor(anchor, floating, placement, signal, gap) {
214
219
  const update = () => {
215
220
  placeFloating(anchor, floating, placement, gap);
216
221
  };
217
222
  whenAnchorMoves(anchor, update, signal);
223
+ const sizes = watchSizes(update);
224
+ signal.addEventListener("abort", () => sizes.disconnect(), { once: true });
225
+ sizes.observe(floating);
218
226
  forgetRoom(floating);
219
227
  update();
220
228
  }
@@ -16,6 +16,8 @@ export declare const withRowAt: (rows: readonly InputListRow[], index: number, v
16
16
  export declare const withoutRowAt: (rows: readonly InputListRow[], index: number) => InputListRow[];
17
17
  /** The rows people filled in. */
18
18
  export declare const filledRows: (rows: readonly InputListRow[]) => InputListRow[];
19
+ /** The values kept from a list given from outside: the blank ones left out, as the rows left empty are. */
20
+ export declare const filledValuesOf: (values: readonly string[]) => string[];
19
21
  /** The values kept: the rows people filled in. */
20
22
  export declare const filledValues: (rows: readonly InputListRow[]) => string[];
21
23
  /** The origin of each value kept, in the same order: what tells a value from the one it started as. */
@@ -21,12 +21,12 @@ var withoutRowAt = (rows, index) => {
21
21
  };
22
22
  /** The rows people filled in. */
23
23
  var filledRows = (rows) => rows.filter((row) => row.value.trim() !== "");
24
+ /** The values kept from a list given from outside: the blank ones left out, as the rows left empty are. */
25
+ var filledValuesOf = (values) => values.filter((value) => value.trim() !== "");
24
26
  /** The values kept: the rows people filled in. */
25
27
  var filledValues = (rows) => filledRows(rows).map((row) => row.value);
26
28
  /** The origin of each value kept, in the same order: what tells a value from the one it started as. */
27
29
  var filledOrigins = (rows) => filledRows(rows).map((row) => row.origin);
28
30
  /** Whether another row fits under `max`; none or zero means no limit. */
29
31
  var canAddRow = (count, max) => max <= 0 || count < max;
30
- /** Whether two lists hold the same values in the same order. */
31
- var sameValues = (left, right) => left.length === right.length && left.every((value, index) => value === right[index]);
32
- export { canAddRow, emptyRow, filledOrigins, filledRows, filledValues, rowsOf, sameValues, withRowAt, withoutRowAt };
32
+ export { canAddRow, emptyRow, filledOrigins, filledRows, filledValues, filledValuesOf, rowsOf, withRowAt, withoutRowAt };
@@ -2,6 +2,7 @@
2
2
  /** What a form control asks of its internals that jsdom's lack: with them, a page's unit tests can create it. */
3
3
  var FORM_METHODS = {
4
4
  checkValidity: () => true,
5
+ form: null,
5
6
  reportValidity: () => true,
6
7
  setFormValue: () => void 0,
7
8
  setValidity: () => void 0
@@ -61,6 +61,7 @@ export declare class JlInputList extends JlElement {
61
61
  }>>;
62
62
  private readonly _state;
63
63
  private readonly _drawn;
64
+ private readonly _publishing;
64
65
  private readonly _refs;
65
66
  templateHtml(): Node;
66
67
  templateCss(): string;
@@ -71,7 +72,11 @@ export declare class JlInputList extends JlElement {
71
72
  */
72
73
  origins(): (number | undefined)[];
73
74
  onConnect(): void;
74
- /** Values set from outside start the rows again; those the rows themselves gave change nothing. */
75
+ /**
76
+ * Values set from outside start the rows again, the blank ones left out of `values`; those the rows themselves
77
+ * gave change nothing. A list given the values its rows already holds takes their origins, so a page that saves
78
+ * and shows the values again gets origins that count in what it saved.
79
+ */
75
80
  private follow;
76
81
  protected drawTexts(): void;
77
82
  /**
@@ -94,4 +99,6 @@ export declare class JlInputList extends JlElement {
94
99
  private addRow;
95
100
  private removeRow;
96
101
  private publish;
102
+ /** Keeps `values` without drawing the rows again: the list's own, and the filled ones of those set from outside. */
103
+ private setValues;
97
104
  }
@@ -7,7 +7,7 @@ import { JlButton } from "../atoms/jl-button.js";
7
7
  import { INPUT_TYPES, JlInput } from "../atoms/jl-input.js";
8
8
  import { JlSelect } from "../atoms/jl-select.js";
9
9
  import { JlTextarea } from "../atoms/jl-textarea.js";
10
- import { canAddRow, emptyRow, filledOrigins, filledValues, rowsOf, sameValues, withRowAt, withoutRowAt } from "../lib/input-list.js";
10
+ import { canAddRow, emptyRow, filledOrigins, filledValues, filledValuesOf, rowsOf, withRowAt, withoutRowAt } from "../lib/input-list.js";
11
11
  import jl_input_list_default from "./jl-input-list.css.js";
12
12
  import { css } from "@jadis/core";
13
13
  import { Plus, X } from "lucide";
@@ -69,6 +69,7 @@ var JlInputList = class extends JlElement {
69
69
  kind: void 0,
70
70
  rows: []
71
71
  };
72
+ _publishing = { on: false };
72
73
  _refs = this.useRefs((ref) => ({
73
74
  add: ref(".add"),
74
75
  rows: ref(".rows")
@@ -99,10 +100,15 @@ var JlInputList = class extends JlElement {
99
100
  onConnect() {
100
101
  this._refs.add.events.register("press", () => this.addRow());
101
102
  }
102
- /** Values set from outside start the rows again; those the rows themselves gave change nothing. */
103
+ /**
104
+ * Values set from outside start the rows again, the blank ones left out of `values`; those the rows themselves
105
+ * gave change nothing. A list given the values its rows already holds takes their origins, so a page that saves
106
+ * and shows the values again gets origins that count in what it saved.
107
+ */
103
108
  follow(values) {
104
- if (sameValues(values, filledValues(this._state.rows))) return;
109
+ if (this._publishing.on) return;
105
110
  this._state.rows = rowsOf(values);
111
+ this.setValues(filledValuesOf(values));
106
112
  this.renderRows();
107
113
  }
108
114
  drawTexts() {
@@ -216,9 +222,14 @@ var JlInputList = class extends JlElement {
216
222
  this.publish();
217
223
  }
218
224
  publish() {
219
- const values = filledValues(this._state.rows);
225
+ this.setValues(filledValues(this._state.rows));
226
+ this.events.emit("change", this.values.get());
227
+ }
228
+ /** Keeps `values` without drawing the rows again: the list's own, and the filled ones of those set from outside. */
229
+ setValues(values) {
230
+ this._publishing.on = true;
220
231
  this.values.set(values);
221
- this.events.emit("change", values);
232
+ this._publishing.on = false;
222
233
  }
223
234
  };
224
235
  JlInputList.register();
@@ -30,6 +30,8 @@ export declare class JlPopover extends JlElement {
30
30
  show(): void;
31
31
  hide(): void;
32
32
  toggle(): void;
33
+ /** Places the panel again by its trigger: for content whose size changes, the panel follows it as it opens. */
34
+ place(): void;
33
35
  templateHtml(): Node;
34
36
  templateCss(): string;
35
37
  onConnect(): void;
@@ -44,6 +44,10 @@ var JlPopover = class extends JlElement {
44
44
  toggle() {
45
45
  this.open.set((open) => !open);
46
46
  }
47
+ /** Places the panel again by its trigger: for content whose size changes, the panel follows it as it opens. */
48
+ place() {
49
+ this.follow();
50
+ }
47
51
  templateHtml() {
48
52
  return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("slot", { name: "trigger" }), /* @__PURE__ */ jsxs("div", {
49
53
  class: "floating panel",
@@ -2,12 +2,12 @@ import { jlText } from "../lib/texts.js";
2
2
  import { BASE_STYLES } from "../styles/shared.js";
3
3
  import { JlElement } from "../base/jl-element.js";
4
4
  import { jsonOf, oneOf, textOf } from "../lib/attributes.js";
5
+ import { watchSizes } from "../lib/resize.js";
5
6
  import { registerIcons } from "../lib/icons.js";
6
7
  import { JlIcon } from "../atoms/jl-icon.js";
7
8
  import { setOrRemove, uniqueId } from "../lib/dom.js";
8
9
  import { JlButton } from "../atoms/jl-button.js";
9
10
  import { hotkeyLabels, isApplePlatform, matchesHotkey, parseHotkey } from "../lib/hotkey.js";
10
- import { watchSizes } from "../lib/resize.js";
11
11
  import { findItem, firstLeaf, pathInSections } from "../lib/nav-tree.js";
12
12
  import jl_side_nav_default from "./jl-side-nav.css.js";
13
13
  import { css } from "@jadis/core";
@@ -1,9 +1,9 @@
1
1
  import { jlText } from "../lib/texts.js";
2
2
  import { BASE_STYLES } from "../styles/shared.js";
3
3
  import { JlElement } from "../base/jl-element.js";
4
+ import { watchSizes } from "../lib/resize.js";
4
5
  import { registerIcons } from "../lib/icons.js";
5
6
  import { JlIcon } from "../atoms/jl-icon.js";
6
- import { watchSizes } from "../lib/resize.js";
7
7
  import jl_app_shell_default from "./jl-app-shell.css.js";
8
8
  import { css } from "@jadis/core";
9
9
  import { Menu } from "lucide";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@syware/jlib",
3
- "version": "0.17.0",
3
+ "version": "0.17.1",
4
4
  "description": "A tree-shakeable component library on Jadis and native Web Components, organised in atomic design",
5
5
  "keywords": [
6
6
  "web-components",