@yuneta/gobj-ui 5.8.1 → 5.8.2

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/README.md CHANGED
@@ -520,6 +520,43 @@ keeps working afterwards. With no guard a modal closes exactly as it always
520
520
  did, and the returned `close()` always closes **unconditionally** — the veto is
521
521
  for the user's dismiss, not for the code's.
522
522
 
523
+ ### Confirmations — and the red one, `yui_shell_confirm_danger`
524
+
525
+ `yui_shell_confirm_yesno(shell, message, opts)` asks a question and resolves to
526
+ a boolean. Its yes is `is-link`, the right colour for *"do you want to
527
+ continue"*.
528
+
529
+ **`yui_shell_confirm_danger(shell, message, opts)`** is the same call with a
530
+ **red** confirm button and the error icon (`type: "danger"` by default). Use it
531
+ whenever the yes destroys something — deleting an account, dropping a record.
532
+ The two must not look alike: the destructive one is precisely the one that must
533
+ not be clicked by reflex.
534
+
535
+ In both, the **safe answer is the last button**, so Escape, the backdrop and
536
+ the X all resolve to it.
537
+
538
+ ```js
539
+ if(await yui_shell_confirm_danger(shell, t("delete account detail"))) {
540
+ /* only here has the red button been pressed */
541
+ }
542
+ ```
543
+
544
+ ### `C_YUI_FORM` — choosing the bottom toolbar
545
+
546
+ By default the form shows **save + undo + clear + copy + paste**. The
547
+ `toolbar` attr takes the button names you want, in the order you want them:
548
+
549
+ ```js
550
+ gobj_create("form", "C_YUI_FORM", {toolbar: ["save"]}, parent); // one action
551
+ gobj_create("form", "C_YUI_FORM", {toolbar: []}, parent); // no toolbar
552
+ ```
553
+
554
+ Save/undo/clear stay on the left of the bar and copy/paste on the right — the
555
+ split the layout has always drawn — so dropping a whole group leaves no hole in
556
+ the middle, and **a toolbar left with a single group is centred**. An unknown
557
+ name is reported, not silently dropped: a typo would otherwise remove the save
558
+ button with no trace of why.
559
+
523
560
  ## Conventions
524
561
 
525
562
  ### i18n: a string must be able to CHANGE language, not just be translated once
@@ -2003,6 +2003,16 @@ function open_toolbar_dropdown(gobj, item, action, $trigger) {
2003
2003
  } else style_parts.push(`left:${Math.max(0, Math.round(rect.left))}px`);
2004
2004
  $panel.setAttribute("style", style_parts.join(";"));
2005
2005
  priv.layers.popup.appendChild($panel);
2006
+ let margin = 8;
2007
+ let pw = $panel.offsetWidth;
2008
+ let pos = $panel.getBoundingClientRect();
2009
+ let left = pos.left;
2010
+ if (left + pw > window.innerWidth - margin) left = window.innerWidth - pw - margin;
2011
+ if (left < margin) left = margin;
2012
+ if (Math.round(left) !== Math.round(pos.left)) {
2013
+ $panel.style.right = "auto";
2014
+ $panel.style.left = `${Math.round(left)}px`;
2015
+ }
2006
2016
  yui_shell_translate(gobj, $panel);
2007
2017
  let backdrop = (ev) => {
2008
2018
  if ($panel.contains(ev.target)) return;
@@ -1998,6 +1998,16 @@ function open_toolbar_dropdown(gobj, item, action, $trigger) {
1998
1998
  } else style_parts.push(`left:${Math.max(0, Math.round(rect.left))}px`);
1999
1999
  $panel.setAttribute("style", style_parts.join(";"));
2000
2000
  priv.layers.popup.appendChild($panel);
2001
+ let margin = 8;
2002
+ let pw = $panel.offsetWidth;
2003
+ let pos = $panel.getBoundingClientRect();
2004
+ let left = pos.left;
2005
+ if (left + pw > window.innerWidth - margin) left = window.innerWidth - pw - margin;
2006
+ if (left < margin) left = margin;
2007
+ if (Math.round(left) !== Math.round(pos.left)) {
2008
+ $panel.style.right = "auto";
2009
+ $panel.style.left = `${Math.round(left)}px`;
2010
+ }
2001
2011
  yui_shell_translate(gobj, $panel);
2002
2012
  let backdrop = (ev) => {
2003
2013
  if ($panel.contains(ev.target)) return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuneta/gobj-ui",
3
- "version": "5.8.1",
3
+ "version": "5.8.2",
4
4
  "type": "module",
5
5
  "main": "dist/gobj-ui.cjs.js",
6
6
  "module": "dist/gobj-ui.es.js",
@@ -2099,6 +2099,28 @@ function open_toolbar_dropdown(gobj, item, action, $trigger)
2099
2099
 
2100
2100
  priv.layers.popup.appendChild($panel);
2101
2101
 
2102
+ /* Now that it HAS a width, keep it inside the viewport on both
2103
+ * edges. The anchoring above guards only the edge it aligns to,
2104
+ * so a right-aligned panel whose trigger sits near the LEFT of the
2105
+ * bar hangs off the left side — which is what every navbar-end
2106
+ * trigger does under dir="rtl": in Arabic the language menu opened
2107
+ * at left:-60px with its first characters unreachable. Measure,
2108
+ * clamp, and pin with `left` so there is one source of truth. */
2109
+ let margin = 8;
2110
+ let pw = $panel.offsetWidth;
2111
+ let pos = $panel.getBoundingClientRect();
2112
+ let left = pos.left;
2113
+ if(left + pw > window.innerWidth - margin) {
2114
+ left = window.innerWidth - pw - margin;
2115
+ }
2116
+ if(left < margin) {
2117
+ left = margin;
2118
+ }
2119
+ if(Math.round(left) !== Math.round(pos.left)) {
2120
+ $panel.style.right = "auto";
2121
+ $panel.style.left = `${Math.round(left)}px`;
2122
+ }
2123
+
2102
2124
  /* Translate the lazily-built panel (see the note above). */
2103
2125
  yui_shell_translate(gobj, $panel);
2104
2126
 
@@ -345,6 +345,11 @@ function build_ui(gobj)
345
345
  $table_toolbar = createElement2(
346
346
  ['div', {id: `${toolbar_id}`, class: 'TREEDB_TABLE_ACTIONS buttons mb-0'}]
347
347
  );
348
+ /* Edit is a MODE TOGGLE, not one more action: it arms/disarms
349
+ * the buttons that modify the table (new/delete/copy/paste),
350
+ * which is why it comes first and why delete sits among them
351
+ * instead of being pushed away from the harmless ones. Do not
352
+ * reorder this group as if they were peer actions. */
348
353
  let $edit_button = createElement2(
349
354
  ['button', {id: ``, class: 'button button-edit-record mr-1'}, [
350
355
  ['i', {class: 'yi-pen'}],