@yuneta/gobj-ui 7.26.8 → 7.26.10

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
@@ -3309,6 +3309,92 @@ text is in the yunetas `CLAUDE.md` ("JS GUI conventions"); in short:
3309
3309
  reuse a glyph because it is there.
3310
3310
  - **Bulma helpers carry `!important`** (`.is-hidden`, `.is-flex`): toggle
3311
3311
  `is-hidden`, or use `style.setProperty('display', 'none', 'important')`.
3312
+ - **Data goes into the DOM as text, never as a string.** `createElement2()`
3313
+ parses a string that starts with `<` as markup, and Tabulator puts a string
3314
+ column title in with `innerHTML`. A value from outside (a backend answer, a
3315
+ treedb node, a schema `header`, a name somebody typed) goes in as a Text
3316
+ node, in the CONTENT slot of a description (gobj-js before 7.26.2 drops a
3317
+ Text node inside a children array):
3318
+
3319
+ ```js
3320
+ import {text_node, text_title_formatter} from "@yuneta/gobj-ui/src/yui_text.js";
3321
+ createElement2(["span", {class: "FOO_NAME", i18n: name}, text_node(name)]);
3322
+ columns.push({field: "x", title: header, titleFormatter: text_title_formatter});
3323
+ ```
3324
+
3325
+ - **Markup is said out loud: `html_markup()`.** Deliberate markup (an icon,
3326
+ an svg) goes into a description wrapped in `html_markup()` (gobj-js
3327
+ 7.26.3+), never as a bare string, in the content slot or in a list of
3328
+ children:
3329
+
3330
+ ```js
3331
+ import {html_markup} from "@yuneta/gobj-js";
3332
+ createElement2(["span", {class: "icon"}, html_markup('<i class="yi-copy"></i>')]);
3333
+ ```
3334
+
3335
+ This library passes every markup it builds through `html_markup()`, so it
3336
+ renders the same with **`set_strings_are_text(true)`** (gobj-js), the mode in
3337
+ which a plain string is ALWAYS text and a datum that starts with `<` can no
3338
+ longer run. The test-app runs in that mode. An app turns it on at startup,
3339
+ before it builds anything, once its own code is migrated:
3340
+
3341
+ 1. Run the static check on the app's sources:
3342
+ `node node_modules/@yuneta/gobj-ui/scripts/check-markup-strings.mjs src`
3343
+ (it needs `acorn`). It lists a markup string literal in a description
3344
+ (`literal`, wrap it in `html_markup()`), markup built with values
3345
+ (`built`, build the element with `createElement2()` and pass the value
3346
+ as text) and a markup string in a list of children (`in-list`, which is
3347
+ text since gobj-js 7.26.2). It cannot see a variable that holds a
3348
+ string.
3349
+ 2. Call `set_strings_are_text(true)` before the first `createElement2()`.
3350
+ 3. Walk the app and read the console: each string that starts with `<` is
3351
+ logged once (*"use html_markup() if it is markup"*). A logged string is
3352
+ either a deliberate markup not migrated yet (wrap it) or a datum that
3353
+ used to run as html (keep it as text).
3354
+
3355
+ `npm run check-markup` runs the check here, and `prebuild` / `pretest` run
3356
+ it, so a new markup literal fails the build.
3357
+
3358
+ ### `index.html`: title, metadata and the Content-Security-Policy
3359
+
3360
+ The vite plugin `yunetaHtmlPlugin` (`vite-plugin-yuneta-html.js`) fills
3361
+ `index.html` from the app's `config.json` at build time. The page needs the
3362
+ three placeholders `<title></title>`, `<!-- METADATA_PLACEHOLDER -->` and
3363
+ `<!-- CSP_PLACEHOLDER -->`.
3364
+
3365
+ ```js
3366
+ // vite.config.js
3367
+ import { yunetaHtmlPlugin } from "@yuneta/gobj-ui/vite-plugin-yuneta-html.js";
3368
+ export default { plugins: [ yunetaHtmlPlugin({ defaultTitle: "My App" }) ] };
3369
+ ```
3370
+
3371
+ ```json
3372
+ {
3373
+ "title": "My App",
3374
+ "metadata": {"description": "What the app does"},
3375
+ "csp_connect_src": [
3376
+ "_comment: the backend this SPA talks to",
3377
+ "wss://my.host:1620",
3378
+ "https://auth.my.host"
3379
+ ]
3380
+ }
3381
+ ```
3382
+
3383
+ - **The policy is always emitted** (since 7.26.7). Without `csp_connect_src`,
3384
+ or without a `config.json` at all, the page gets the same policy with
3385
+ `connect-src 'self'` only, and the build prints a warning. So a page that
3386
+ talks to a backend on another origin must declare that origin here, or
3387
+ the browser refuses the connection.
3388
+ - **`csp_connect_src` is a list of CSP sources**, one per entry: an origin
3389
+ (`wss://host:port`) or a scheme (`wss:`). An entry that starts with
3390
+ `_comment` is ignored. An entry that holds a `;`, a `,` or a space is
3391
+ refused with an error (since 7.26.9): it is not one source, and a `;`
3392
+ would add a directive of its own (`wss://a; base-uri *`).
3393
+ - The rest of the policy is fixed: `script-src 'self'` (no inline script:
3394
+ put pre-paint code in `public/<name>.js` and load it with `<script src>`),
3395
+ `style-src 'self' 'unsafe-inline'`, and `blob:`/`data:` where workers,
3396
+ images, media and fonts need them.
3397
+ - Every text from `config.json` is escaped where it lands in the markup.
3312
3398
 
3313
3399
  ### Releasing
3314
3400