@yuneta/gobj-ui 7.26.5 → 7.26.7

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,37 +1,37 @@
1
1
  /***********************************************************************
2
2
  * yui_table_filter_clear.js
3
3
  *
4
- * LA ✕ DE LOS FILTROS DE CABECERA DE UNA TABULATOR.
4
+ * THE ✕ OF A TABULATOR'S HEADER FILTERS.
5
5
  *
6
- * Un filtro de columna se pone escribiendo y se quita BORRANDO lo
7
- * escrito, letra a letra, y no hay nada en la cabecera que diga
8
- * que se puede quitar. Con varias columnas filtradas, volver a
9
- * ver la tabla entera es un ejercicio de memoria: cuáles toqué.
10
- * La ✕ lo dice y lo hace.
6
+ * A column filter is set by typing and removed by DELETING what
7
+ * was typed, letter by letter, and nothing in the header says it
8
+ * can be removed. With several columns filtered, getting the
9
+ * whole table back is an exercise of memory: which ones did I
10
+ * touch. The ✕ says it and does it.
11
11
  *
12
- * TRES DECISIONES QUE NO SON OBVIAS:
12
+ * THREE DECISIONS THAT ARE NOT OBVIOUS:
13
13
  *
14
- * - **Se ve mientras el filtro tenga contenido, con foco o sin
15
- * él.** Es al revés que la ✕ de un formulario
16
- * (`yui_inputs.js`), que sólo aparece en el campo que se está
17
- * editando para no encender un aspa en cada campo relleno. Aquí
18
- * el caso de uso es justo el contrario: el filtro ya está puesto,
19
- * el foco está en otra parte, y lo que se quiere es verlo y
20
- * quitarlo. Escondida tras el foco harían falta dos clics.
14
+ * - **It shows while the filter has content, focused or not.**
15
+ * The opposite of a form's ✕ (`yui_inputs.js`), which appears
16
+ * only on the field being edited so as not to light a cross on
17
+ * every filled field. Here the use case is the reverse: the
18
+ * filter is already set, the focus is elsewhere, and what is
19
+ * wanted is to see it and remove it. Hidden behind the focus it
20
+ * would take two clicks.
21
21
  *
22
- * - **Se borra con la API, no simulando teclas.**
23
- * `setHeaderFilterValue(field, "")` es lo que Tabulator ofrece, y
24
- * deja el valor y el filtro consistentes. Sintetizar un `input`
25
- * sobre el `<input>` depende de a qué escuche el editor de ese
26
- * filtro, que cambia con el tipo de columna.
22
+ * - **It clears through the API, not by faking keys.**
23
+ * `setHeaderFilterValue(field, "")` is what Tabulator offers,
24
+ * and it keeps the value and the filter consistent. Synthesising
25
+ * an `input` on the `<input>` depends on what that filter's
26
+ * editor listens to, which changes with the column type.
27
27
  *
28
- * - **Se recorre la cabecera, no se envuelve el editor.** Las
29
- * columnas se construyen del esquema del topic, así que no hay un
30
- * sitio único donde envolver el editor; y la cabecera se rehace
31
- * sola cuando cambian las columnas. El recorrido es idempotente
32
- * -- marca lo que ya tiene aspa -- y se dispara con un
33
- * `querySelector` de una sola pasada, así que repetirlo en cada
34
- * render no cuesta nada.
28
+ * - **The header is walked, the editor is not wrapped.** The
29
+ * columns are built from the topic's schema, so there is no
30
+ * single place to wrap the editor; and the header rebuilds
31
+ * itself when the columns change. The walk is idempotent -- it
32
+ * marks what already has its cross -- and is triggered by a
33
+ * one-pass `querySelector`, so repeating it on every render
34
+ * costs nothing.
35
35
  *
36
36
  * Copyright (c) 2026, ArtGins.
37
37
  * All Rights Reserved.
@@ -47,9 +47,9 @@ const MARK = "data-yui-filter-clear";
47
47
 
48
48
 
49
49
  /***************************************************************
50
- * Pon (o repón) la ✕ de cada filtro de cabecera de `table`.
50
+ * Put (or put back) the ✕ of every header filter of `table`.
51
51
  *
52
- * Idempotente: los que ya la tienen se saltan.
52
+ * Idempotent: the ones that already have it are skipped.
53
53
  ***************************************************************/
54
54
  function decorate(table)
55
55
  {
@@ -58,7 +58,7 @@ function decorate(table)
58
58
  }
59
59
  let $pending = table.element.querySelector(`.tabulator-header-filter:not([${MARK}])`);
60
60
  if(!$pending) {
61
- return; /* nada nuevo en la cabecera */
61
+ return; /* nothing new in the header */
62
62
  }
63
63
 
64
64
  let list = table.element.querySelectorAll(`.tabulator-header-filter:not([${MARK}])`);
@@ -67,22 +67,22 @@ function decorate(table)
67
67
 
68
68
  let $input = $filter.querySelector("input");
69
69
  if(!$input) {
70
- continue; /* un filtro que no se escribe: un select, un rango */
70
+ continue; /* a filter that is not typed: a select, a range */
71
71
  }
72
72
 
73
- /* El campo se lee del `.tabulator-col` que lo contiene, que es
74
- * quien lo lleva; el `<input>` no sabe de qué columna es. */
73
+ /* The field is read from the `.tabulator-col` holding it, which
74
+ * is what carries it; the `<input>` does not know its column. */
75
75
  let $col = $filter.closest(".tabulator-col");
76
76
  let field = $col? $col.getAttribute("tabulator-field"): "";
77
77
  if(!field) {
78
- continue; /* sin campo no hay a quién decirle que se limpie */
78
+ continue; /* without a field there is nobody to tell to clear */
79
79
  }
80
80
 
81
81
  $filter.classList.add("yui-filter-has-clear");
82
82
 
83
- /* La clave viaja con el botón: un `title` puesto con t() al
84
- * construir es invisible para refresh_language(), y se queda en
85
- * el idioma de aquel momento para siempre. */
83
+ /* The key travels with the button: a `title` set with t() at
84
+ * build time is invisible to refresh_language(), and stays in
85
+ * the language of that moment for ever. */
86
86
  let $btn = createElement2(["button", {
87
87
  type: "button",
88
88
  class: "delete is-small yui-filter-clear",
@@ -100,7 +100,7 @@ function decorate(table)
100
100
  $input.addEventListener("input", sync);
101
101
  $input.addEventListener("change", sync);
102
102
  $btn.addEventListener("click", (event) => {
103
- event.stopPropagation(); /* no ordenar la columna al pulsar */
103
+ event.stopPropagation(); /* a press must not sort the column */
104
104
  table.setHeaderFilterValue(field, "");
105
105
  sync();
106
106
  });
@@ -111,11 +111,11 @@ function decorate(table)
111
111
  }
112
112
 
113
113
  /***************************************************************
114
- * Engancha la ✕ a una tabla ya creada.
114
+ * Hook the ✕ onto a table already created.
115
115
  *
116
- * Se llama una vez, con la tabla construida. Los enganches
117
- * cubren los dos momentos en que la cabecera aparece o se
118
- * rehace: cuando se construye y cuando cambian las columnas.
116
+ * Called once, with the table built. The hooks cover the two
117
+ * moments the header appears or is rebuilt: when it is built
118
+ * and when the columns change.
119
119
  ***************************************************************/
120
120
  export function yui_table_filter_clear(table)
121
121
  {
@@ -132,9 +132,9 @@ export function yui_table_filter_clear(table)
132
132
  }
133
133
 
134
134
  /***************************************************************
135
- * Repasa el estado de las ✕ tras un cambio que no vino del
136
- * teclado -- limpiar todos los filtros, cargar una vista
137
- * guardada -- porque eso no dispara `input`.
135
+ * Go over the state of the ✕s after a change that did not come
136
+ * from the keyboard -- clearing every filter, loading a saved
137
+ * view -- because that fires no `input`.
138
138
  ***************************************************************/
139
139
  export function yui_table_filter_clear_refresh(table)
140
140
  {
@@ -6,17 +6,28 @@
6
6
  * - <title> from config.title
7
7
  * - <meta> tags from config.metadata
8
8
  * - Content-Security-Policy from config.csp_connect_src
9
+ * (always emitted: connect-src 'self' alone when the
10
+ * list is missing, with a warning)
9
11
  *
10
12
  * Usage in vite.config.js (vendored copy):
11
13
  * import { yunetaHtmlPlugin } from "./src/gobj-ui/vite-plugin-yuneta-html.js";
12
14
  * plugins: [ yunetaHtmlPlugin({ defaultTitle: "My App" }) ]
13
15
  *
14
- * Copyright (c) 2025, ArtGins.
16
+ * Copyright (c) 2025-2026, ArtGins.
15
17
  * All Rights Reserved.
16
18
  ***********************************************************************/
17
19
  import fs from "fs";
18
20
  import path from "path";
19
21
 
22
+ /* config.json is build input, but its text lands inside markup. */
23
+ function escape_html(value) {
24
+ return String(value)
25
+ .replace(/&/g, "&amp;")
26
+ .replace(/</g, "&lt;")
27
+ .replace(/>/g, "&gt;")
28
+ .replace(/"/g, "&quot;");
29
+ }
30
+
20
31
  /**
21
32
  * @param {object} [options]
22
33
  * @param {string} [options.defaultTitle] - Fallback title if config.json is missing
@@ -52,7 +63,7 @@ export function yunetaHtmlPlugin(options = {}) {
52
63
  if (config.metadata) {
53
64
  for (const [key, value] of Object.entries(config.metadata)) {
54
65
  if (value) {
55
- metadataHtml += ` <meta name="${key}" content="${value}">\n`;
66
+ metadataHtml += ` <meta name="${escape_html(key)}" content="${escape_html(value)}">\n`;
56
67
  }
57
68
  }
58
69
  }
@@ -83,10 +94,21 @@ export function yunetaHtmlPlugin(options = {}) {
83
94
  * injected style blocks. Don't loosen the script
84
95
  * side without a strong reason.
85
96
  *------------------------------------------*/
97
+ /* A config with no csp_connect_src used to get NO policy
98
+ * at all, silently. It gets the same policy with
99
+ * connect-src 'self' only, and a warning. */
86
100
  let cspHtml = "";
87
- if (config.csp_connect_src) {
88
- const origins = config.csp_connect_src
89
- .filter(s => !s.startsWith("_comment"));
101
+ {
102
+ let origins = [];
103
+ if (Array.isArray(config.csp_connect_src)) {
104
+ origins = config.csp_connect_src
105
+ .filter(s => !s.startsWith("_comment"));
106
+ } else {
107
+ console.warn(
108
+ "⚠️ config.json has no csp_connect_src array: " +
109
+ "the Content-Security-Policy allows connect-src 'self' only"
110
+ );
111
+ }
90
112
 
91
113
  const connectSrc = ["'self'", ...origins].join("\n ");
92
114
 
@@ -112,7 +134,7 @@ export function yunetaHtmlPlugin(options = {}) {
112
134
  * Apply replacements
113
135
  *------------------------------------------*/
114
136
  return html
115
- .replace("<title></title>", `<title>${title}</title>`)
137
+ .replace("<title></title>", `<title>${escape_html(title)}</title>`)
116
138
  .replace("<!-- METADATA_PLACEHOLDER -->", metadataHtml)
117
139
  .replace("<!-- CSP_PLACEHOLDER -->", cspHtml);
118
140
  }