@feezal/feezal-element 3.0.9 → 3.0.11
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/feezal-element.js +26 -0
- package/feezal-friendly-name.js +24 -0
- package/package.json +2 -1
package/feezal-element.js
CHANGED
|
@@ -502,6 +502,32 @@ export const publishLocalAttribute = {
|
|
|
502
502
|
help: 'Publish page-locally instead of to the broker: the payload reaches only subscribers in THIS browser tab (dialog triggers, view switches, wiring elements together). Nothing is sent over MQTT, nothing is retained, and it works while disconnected.'
|
|
503
503
|
};
|
|
504
504
|
|
|
505
|
+
/**
|
|
506
|
+
* E142: shared descriptor for a dialog's editor-only `label` — spread into every
|
|
507
|
+
* dialog element's `feezal.attributes` so the wording never drifts. The element
|
|
508
|
+
* declares `label: {type: String, reflect: true}` and renders its placeholder
|
|
509
|
+
* text through `dialogPlaceholderLabel()`. Distinct from a dialog's `title`,
|
|
510
|
+
* which IS shown to the user as the heading — `label` is never rendered in the
|
|
511
|
+
* viewer; it exists purely to tell multiple dialogs apart on the canvas.
|
|
512
|
+
*/
|
|
513
|
+
export const dialogLabelAttribute = {
|
|
514
|
+
name: 'label',
|
|
515
|
+
type: 'string',
|
|
516
|
+
default: '',
|
|
517
|
+
help: 'Editor-only label shown on the canvas placeholder to tell multiple dialogs apart (e.g. "Dialog: Confirm delete"). Never shown in the viewer — unlike "title", which is the dialog heading users see.'
|
|
518
|
+
};
|
|
519
|
+
|
|
520
|
+
/**
|
|
521
|
+
* E142: editor-only placeholder text for a dialog pseudo-element. Appends the
|
|
522
|
+
* disambiguating `label` when set ("Dialog" → "Dialog: Confirm delete"), else
|
|
523
|
+
* returns the base word unchanged. Used only inside the `feezal.isEditor`
|
|
524
|
+
* placeholder branch — never in the viewer.
|
|
525
|
+
*/
|
|
526
|
+
export function dialogPlaceholderLabel(base, label) {
|
|
527
|
+
const l = (label || '').trim();
|
|
528
|
+
return l ? `${base}: ${l}` : base;
|
|
529
|
+
}
|
|
530
|
+
|
|
505
531
|
/**
|
|
506
532
|
* E137 — payload comparison, cross-controller shared machinery: string
|
|
507
533
|
* coercion (case-insensitive) plus boolean true/false matching the HA/z2m
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Shared friendly-label normalization (U62 / E135 device-health).
|
|
2
|
+
//
|
|
3
|
+
// Lives in @feezal/feezal-element so BOTH the editor (discovery stamping,
|
|
4
|
+
// www/src/feezal-discovery-stamp.js re-exports this) and element packages
|
|
5
|
+
// (e.g. the device-health inspector building its device list) derive labels
|
|
6
|
+
// the SAME way. Pure, dependency-free.
|
|
7
|
+
//
|
|
8
|
+
// Normalize a discovered device/entity name into a friendly, human label:
|
|
9
|
+
// 1. strip a trailing Homematic channel suffix (`…:14` / `…:0` → drop only a
|
|
10
|
+
// trailing `:<digits>`, never a colon elsewhere),
|
|
11
|
+
// 2. underscores → spaces, collapse whitespace runs,
|
|
12
|
+
// 3. capitalize the first letter of each *all-lowercase* word — words that
|
|
13
|
+
// already carry an uppercase letter are left entirely alone, so acronyms
|
|
14
|
+
// and units survive (`kWh`, `CO2`, `WLED` unchanged; `licht` → `Licht`),
|
|
15
|
+
// 4. idempotent — an already-friendly name (`Wohnzimmer Lampe`) is unchanged.
|
|
16
|
+
export function friendlyName(raw) {
|
|
17
|
+
let s = String(raw ?? '').trim();
|
|
18
|
+
if (!s) return '';
|
|
19
|
+
s = s.replace(/:\d+$/, ''); // 1. trailing HM channel suffix
|
|
20
|
+
s = s.replace(/_/g, ' ').replace(/\s+/g, ' ').trim(); // 2. underscores → spaces
|
|
21
|
+
// 3. capitalize the first letter only of words with no existing uppercase.
|
|
22
|
+
s = s.replace(/\S+/g, w => (/[A-Z]/.test(w) ? w : w.charAt(0).toUpperCase() + w.slice(1)));
|
|
23
|
+
return s;
|
|
24
|
+
}
|
package/package.json
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"files": [
|
|
16
16
|
"feezal-element.js",
|
|
17
17
|
"feezal-conditions.js",
|
|
18
|
+
"feezal-friendly-name.js",
|
|
18
19
|
"feezal-polymer-element.js",
|
|
19
20
|
"feezal-topic-input.js",
|
|
20
21
|
"LICENSE"
|
|
@@ -35,5 +36,5 @@
|
|
|
35
36
|
"url": "git+https://github.com/feezal/feezal.git",
|
|
36
37
|
"directory": "www/packages/@feezal/feezal-element"
|
|
37
38
|
},
|
|
38
|
-
"version": "3.0.
|
|
39
|
+
"version": "3.0.11"
|
|
39
40
|
}
|