@rogieking/figui3 6.5.0 → 6.6.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/fig.js CHANGED
@@ -3319,7 +3319,14 @@ class FigTabs extends HTMLElement {
3319
3319
  #ensureScroller() {
3320
3320
  if (this.#isStructuring) return;
3321
3321
  const existing = this.querySelector(":scope > [data-fig-tabs-scroll]");
3322
- if (existing && existing === this.#scroller) return;
3322
+ const directNodes = existing
3323
+ ? Array.from(this.childNodes).filter((node) => {
3324
+ if (node === existing) return false;
3325
+ if (node.nodeType !== Node.ELEMENT_NODE) return true;
3326
+ return !node.hasAttribute("data-fig-tabs-nav");
3327
+ })
3328
+ : null;
3329
+ if (existing && existing === this.#scroller && !directNodes?.length) return;
3323
3330
 
3324
3331
  this.#isStructuring = true;
3325
3332
  try {
@@ -3332,11 +3339,13 @@ class FigTabs extends HTMLElement {
3332
3339
  scroller.className = "fig-tabs-scroll";
3333
3340
  scroller.dataset.figTabsScroll = "";
3334
3341
 
3335
- const nodes = Array.from(this.childNodes).filter((node) => {
3336
- if (node === scroller) return false;
3337
- if (node.nodeType !== Node.ELEMENT_NODE) return true;
3338
- return !node.hasAttribute("data-fig-tabs-nav");
3339
- });
3342
+ const nodes =
3343
+ directNodes ??
3344
+ Array.from(this.childNodes).filter((node) => {
3345
+ if (node === scroller) return false;
3346
+ if (node.nodeType !== Node.ELEMENT_NODE) return true;
3347
+ return !node.hasAttribute("data-fig-tabs-nav");
3348
+ });
3340
3349
 
3341
3350
  for (const node of nodes) {
3342
3351
  scroller.appendChild(node);
@@ -14237,6 +14246,7 @@ customElements.define("fig-choice", FigChoice);
14237
14246
  * A selection controller for a list of choice elements.
14238
14247
  * @attr {string} choice-element - CSS selector for child choices (default: "fig-choice")
14239
14248
  * @attr {string} layout - Layout mode: "vertical" (default), "horizontal", "grid"
14249
+ * @attr {number} columns - Number of columns when layout="grid" (default: 2)
14240
14250
  * @attr {string} value - Value of the currently selected choice
14241
14251
  * @attr {boolean} disabled - Whether the chooser is disabled
14242
14252
  */
@@ -14262,7 +14272,9 @@ class FigChooser extends HTMLElement {
14262
14272
  "value",
14263
14273
  "disabled",
14264
14274
  "choice-element",
14275
+ "columns",
14265
14276
  "drag",
14277
+ "layout",
14266
14278
  "overflow",
14267
14279
  "loop",
14268
14280
  ];
@@ -14283,6 +14295,16 @@ class FigChooser extends HTMLElement {
14283
14295
  return this.getAttribute("choice-element") || "fig-choice";
14284
14296
  }
14285
14297
 
14298
+ #syncGridColumns() {
14299
+ const raw = this.getAttribute("columns");
14300
+ const columns = raw === null ? NaN : Number(raw);
14301
+ if (Number.isInteger(columns) && columns > 0) {
14302
+ this.style.setProperty("--fig-chooser-grid-columns", String(columns));
14303
+ } else {
14304
+ this.style.removeProperty("--fig-chooser-grid-columns");
14305
+ }
14306
+ }
14307
+
14286
14308
  get choices() {
14287
14309
  return Array.from((this.#scroller || this).querySelectorAll(this.#choiceSelector));
14288
14310
  }
@@ -14360,6 +14382,7 @@ class FigChooser extends HTMLElement {
14360
14382
 
14361
14383
  connectedCallback() {
14362
14384
  this.setAttribute("role", "listbox");
14385
+ this.#syncGridColumns();
14363
14386
  this.#ensureScroller();
14364
14387
  this.addEventListener("click", this.#boundHandleClick);
14365
14388
  this.addEventListener("keydown", this.#boundHandleKeyDown);
@@ -14436,6 +14459,9 @@ class FigChooser extends HTMLElement {
14436
14459
  if (name === "choice-element") {
14437
14460
  requestAnimationFrame(() => this.#syncSelection());
14438
14461
  }
14462
+ if (name === "columns") {
14463
+ this.#syncGridColumns();
14464
+ }
14439
14465
  if (name === "drag") {
14440
14466
  if (this.#dragEnabled) {
14441
14467
  this.#setupDrag();
@@ -14446,6 +14472,10 @@ class FigChooser extends HTMLElement {
14446
14472
  if (name === "overflow") {
14447
14473
  this.#applyOverflowMode();
14448
14474
  }
14475
+ if (name === "layout") {
14476
+ this.#applyOverflowMode();
14477
+ requestAnimationFrame(() => this.#syncOverflow());
14478
+ }
14449
14479
  }
14450
14480
 
14451
14481
  #syncSelection() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rogieking/figui3",
3
- "version": "6.5.0",
3
+ "version": "6.6.0",
4
4
  "description": "A lightweight web components library for building Figma plugin and widget UIs with native look and feel",
5
5
  "author": "Rogie King",
6
6
  "license": "MIT",