iobroker.smartcontrol 1.2.0 → 1.2.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/.github/ISSUE_TEMPLATE/BugReport.md +36 -36
- package/.github/ISSUE_TEMPLATE/Enhancement.md +19 -19
- package/.github/auto-merge.yml +17 -17
- package/.github/workflows/dependabot-auto-merge.yml +22 -22
- package/.github/workflows/npmpublish.yml +30 -30
- package/.github/workflows/test-and-release.yml +92 -129
- package/.releaseconfig.json +3 -0
- package/LICENSE +21 -21
- package/README.md +374 -402
- package/admin/doc-md/readme.txt +6 -6
- package/admin/doc-md/start_de.md +124 -124
- package/admin/doc-md/start_en.md +126 -126
- package/admin/doc-md/table-conditions_de.md +10 -10
- package/admin/doc-md/table-conditions_en.md +10 -10
- package/admin/doc-md/table-execution_de.md +12 -12
- package/admin/doc-md/table-execution_en.md +12 -12
- package/admin/doc-md/table-target-devices_de.md +18 -18
- package/admin/doc-md/table-target-devices_en.md +21 -21
- package/admin/doc-md/table-target-enums_de.md +13 -13
- package/admin/doc-md/table-target-enums_en.md +15 -15
- package/admin/doc-md/table-target-url_de.md +29 -29
- package/admin/doc-md/table-target-url_en.md +27 -27
- package/admin/doc-md/table-trigger-devices_de.md +12 -12
- package/admin/doc-md/table-trigger-devices_en.md +10 -10
- package/admin/doc-md/table-trigger-motion_de.md +23 -23
- package/admin/doc-md/table-trigger-motion_en.md +24 -24
- package/admin/doc-md/table-trigger-times_de.md +13 -13
- package/admin/doc-md/table-trigger-times_en.md +11 -11
- package/admin/doc-md/table-zones_de.md +14 -14
- package/admin/doc-md/table-zones_en.md +13 -13
- package/admin/doc-md/table-zones_select-targets_de.md +18 -18
- package/admin/doc-md/table-zones_select-targets_en.md +18 -18
- package/admin/index_m.html +1 -1
- package/admin/index_m.js +118 -88
- package/admin/zero-md/webcomponents-loader.min.js +8 -8
- package/admin/zero-md/zero-md.min.js.js +8 -8
- package/io-package.json +461 -433
- package/lib/adapter-config.d.ts +15 -15
- package/lib/constants.js +128 -125
- package/lib/helper.js +1069 -1059
- package/lib/tools.js +93 -93
- package/lib/trigger-class.js +964 -964
- package/main.js +105 -48
- package/main.test.js +30 -30
- package/package.json +73 -70
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
Hier definierst du alle "Zonen" (z.B. Badezimmer 1.OG, Kaffeeecke, usw.) und weist Auslöser und zu schaltende Zielgeräte zu.
|
|
2
|
-
|
|
3
|
-
| Spalte | Pflichtfeld | Beschreibung |
|
|
4
|
-
|----------|:------------:|-------|
|
|
5
|
-
| : Falls aktiviert, dann wird immer ausgeführt, sofern etwaige zuvor definierte Bedingungen zutreffen. Falls nicht aktiviert, musst du im Dialog 'Ausführung' mindestens eine aktive Zeile anlegen. |
|
|
1
|
+
Hier definierst du alle "Zonen" (z.B. Badezimmer 1.OG, Kaffeeecke, usw.) und weist Auslöser und zu schaltende Zielgeräte zu.
|
|
2
|
+
|
|
3
|
+
| Spalte | Pflichtfeld | Beschreibung |
|
|
4
|
+
|----------|:------------:|-------|
|
|
5
|
+
|  | Ja | Aktiviert/Deaktiviert diese Tabellenzeile. Falls nicht aktiviert, wird diese Tabellenzeile vom Adapter nicht beachtet. In den Adapter-Optionen, unter 'WEITERE OPTIONEN > Eingabe-Validierung' kannst du übrigens einstellen, dass auch deaktivierte Zeilen auf Gültigkeit geprüft werden. |
|
|
6
|
+
| Name der Zone | Ja | Beliebiger Name für die Zone. |
|
|
7
|
+
| Auslöser | Ja | Wähle hier einen oder mehrere Auslöser aus, um dieser Zone zuzuordnen. Falls du hier mehrere Bewegungsmelder einträgst, wird nur dann wieder ausgeschaltet, wenn keiner dieser Bewegungsmelder mehr eine Bewegung registriert hat. |
|
|
8
|
+
| Zielgeräte | Ja | Wähle hier ein oder mehrere zu schaltende Zielgeräte aus, die geschalten werden, sobald ein Auslöser auslöst und die Bedingungen zutreffen.<br><br>Mit dem blauen Button links daneben kannst du bei vielen Zielgeräten deutlich schneller auswählen. Es öffnet sich ein Dialog, in dem du die Zielgeräte leichter finden, filtern und auswählen kannst.<br><br>**Funktion 'Individuelle Optionen für Zielgerät setzen'**:<br>Im Dialog, der erscheint, wenn man auf den blauen Button links daneben klickt, kann man durch Doppelklick oder `F2` individuelle Werte für Zielgeräte setzen, Beispiel **{**`val:Radio Chillout, delay:20`**}**.<br>Mit `val` wird der *Wert für 'an'* von *1. ZIELGERÄTE* überschrieben.<br>Mit `delay` wird das Zielgerät bei Aktivierung der Zone um diese Anzahl an Sekunden verzögert eingeschaltet.<br><br>Deine eingetragenen Optionen erscheinen dann in geschweiften Klammern hinter dem Namen.<br><br><br>**Tipp**: Wähle im Reiter "1. ZIELGERÄTE" für die Zielgeräte-Namen Punkte als Trennung und organisere diese z.B. nach Räumen und Geräten, z.B. "Wohnzimmer.Lichter.Decke", "Wohnzimmer.Lichter.Wand links", etc. Damit werden dir hier die Zielgeräte dann als Ordner angezeigt: "Wohnzimmer > Lichter > Decke", etc. |
|
|
9
|
+
| | Nein | **Verzögertes Einschalten der Zone (in Sekunden)**: Hiermit kannst du eine Verzögerung einstellen: erst nach dieser Anzahl an Sekunden wird die Zone tatsächlich eingeschaltet.<br>Durch leer lassen oder `0` wird diese Option ignoriert. |
|
|
10
|
+
|  | Nein | **Zone aus nach x Sekunden**: Hiermit wird die Zone nach der angegebenen Anzahl an Sekunden ausgeschaltet (unabhängig von etwaigen Bewegungsmeldern). Der Timer zum Ausschalten startet, sobald die Zone eingeschaltet wurde. Gibt es zwischendurch ein erneutes Einschalten der Zone, wird dieser Timer neu gestartet.<br>Durch leer lassen oder `0` wird diese Option ignoriert. |
|
|
11
|
+
| Nie ausschalten wenn... | Nein | Hier kannst du zusätzliche Bedingungen eintragen, z.B.: Keiner zu Hause, Radio läuft, usw. Wenn diese Bedingungen zutreffen, werden die Zielgeräte dieser Zone **nicht** ausgeschaltet, wenn ein Timer abgelaufen ist. Dies betrifft sowohl den Timer *Zone aus nach x Sekunden* als auch etwaige Bewegungsmelder-Timer. |
|
|
12
|
+
|  | Nein | Für *Nie ausschalten wenn...*: Wenn aktiviert, müssen alle Bedingungen zutreffen ('und'). Wenn deaktiviert, reicht es, wenn eine der Bedingungen zutrifft.<br>Falls du nur eine Bedingung auswählst, ist es egal, ob du das aktivierst oder nicht.|
|
|
13
|
+
| Ausführung | Nein | Durch Klicken auf diesen Button öffnet sich ein Dialog, in dem du weitere Bedingungen definieren kannst, wann die in der Zone definierten Zielgeräte geschaltet werden, sobald ein Auslöser auslöst. Detail-Informationen findest du hierzu in diesem Dialog. |
|
|
14
|
+
| Immer | Ja | Diese Option ist identisch mit "Immer ausführen" im Dialog 'Ausführung' (siehe oben): Falls aktiviert, dann wird immer ausgeführt, sofern etwaige zuvor definierte Bedingungen zutreffen. Falls nicht aktiviert, musst du im Dialog 'Ausführung' mindestens eine aktive Zeile anlegen. |
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
Here you bring everything together by defining all "zones" (e.g. bathroom 1st floor, coffee corner, etc.) and assigning triggers and target devices to be switched, as well as defining further conditions for execution.
|
|
2
|
-
|
|
3
|
-
| Column | Mandatory | Description |
|
|
4
|
-
|----------|:------------:|-------|
|
|
5
|
-
| . If disabled, it is enough if one of the conditions applies.<br>If you select only one condition, it doesn't matter if you enable it or not.|
|
|
13
|
-
| Execution | Yes | Clicking this button opens a dialog where you can define further conditions when the target devices, as defined in the zone, will be switched as soon as a trigger is triggered. Details are described in this dialog. |
|
|
1
|
+
Here you bring everything together by defining all "zones" (e.g. bathroom 1st floor, coffee corner, etc.) and assigning triggers and target devices to be switched, as well as defining further conditions for execution.
|
|
2
|
+
|
|
3
|
+
| Column | Mandatory | Description |
|
|
4
|
+
|----------|:------------:|-------|
|
|
5
|
+
|  | Yes | Enables/disables this table row. If not activated, this table row is ignored by the adapter. In the Adapter Options, under 'FURTHER OPTIONS > Input Validation', you can set that even disabled rows are checked for validity. |
|
|
6
|
+
| Name of zone | Yes | Any zone name. |
|
|
7
|
+
| Trigger | Yes | Select one or more triggers to assign to this zone. If you enter more than one motion sensors here, the zone will only be switched off again if none of these motion sensors has registered any more motion.|
|
|
8
|
+
| Target devices | Yes | Here you select one or more target devices to be switched, which will be switched as soon as a trigger is triggered and the conditions are met.<br><br>With the blue button to the left you can select much faster in case of many target devices. A dialog opens where you can find, filter and select the target devices more easily.<br><br>**Function 'Set individual options für target device'**:<br>In the dialog that appears when you click on the blue button to the left, you can set individual values for target devices by double clicking or 'F2', example: **{**`val:Radio Chillout, delay:20`**}**.<br>`val` overwrites the *Value for 'on'* of *1. TARGET DEVICES*.<br>`delay` the target device is switched on delayed by this number of seconds when the zone is activated.<br><br>Your entered options will appear in curly brackets after the name.<br><br><br>**Tip**: Use dots as separators in tab "1. TARGET DEVICES" for the target device names and organize them e.g. by rooms and devices, e.g. "Bathroom.Lights.Ceiling", "Bathroom.Lights.Wall left", etc. The target devices will then be displayed here as folders: "Bathroom > Lights > Ceiling", etc. |
|
|
9
|
+
| | Nein | **Delay for switching zone on (in seconds)** This allows you to set a delay: after this number of seconds the zone will actually be switched on.<br>Leave empty or set `0` to ignore this option. |
|
|
10
|
+
|  | No | **Switch zone off after x seconds**: This switches the zone off after the specified number of seconds (independent of any motion sensors). The timer for switching off starts as soon as the zone is switched on. If the zone is switched on again in between, this timer will be restarted.<br>Leave empty or set `0` to ignore this option. |
|
|
11
|
+
| Never switch off if... | No | Here you can enter additional conditions, for example: No one at home, radio is on, etc. If these conditions apply, the target devices of this zone **will not** be turned off when a timer expires. This applies to both the timer *Switch zone off after x seconds* and motion sensor timers. |
|
|
12
|
+
| ✓✓ | No | For *Never switch off if...*: If activated, all conditions must apply ('and'). If disabled, it is enough if one of the conditions applies.<br>If you select only one condition, it doesn't matter if you enable it or not.|
|
|
13
|
+
| Execution | Yes | Clicking this button opens a dialog where you can define further conditions when the target devices, as defined in the zone, will be switched as soon as a trigger is triggered. Details are described in this dialog. |
|
|
14
14
|
| Always | Yes | This option is identical to "Execute always" in the 'Execution' dialog (see above): If activated, the adapter will always execute if any previously defined conditions apply. If not activated, you must create at least one active line in the 'Execution' dialog. |
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
Durch Doppelklick oder F2 kannst du hier individuelle Optionen für Zielgeräte setzen.<br>
|
|
2
|
-
<details>
|
|
3
|
-
<summary style="padding-bottom:-20px">Weitere Erklärung (hier klicken)</summary> <!-- Header -->
|
|
4
|
-
<!-- Markdown Collapsible Section - We must have an empty line below -->
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
### Beispiele
|
|
8
|
-
* **{** `val:Radio Chillout, delay:20` **}**
|
|
9
|
-
* **{** `delay:30` **}**
|
|
10
|
-
* **{** `val:true` **}**
|
|
11
|
-
|
|
12
|
-
### Erklärung
|
|
13
|
-
* **val**: Hiermit wird der *Wert für 'an'* von *1. ZIELGERÄTE* überschrieben.
|
|
14
|
-
* **delay**: Hiermit wird *Verzögertes Einschalten des Zielgerätes* von *1. ZIELGERÄTE* durch die angegebene Anzahl Sekunden überschrieben. Zum Deaktivieren kannst du `delay:0` eintragen.<br>*Beispiel-Anwendungsfall (Use Case)*: Schalte den Strom-Zwischenstecker sofort ein, warte 30 Sekunden und schalte dann den Fernseher ein (weil er z.B. vorher noch nicht auf IR-Befehle reagiert) und dimme nach 50 Sekunden das Licht im TV-Eck.
|
|
15
|
-
|
|
16
|
-
#### Hinweis
|
|
17
|
-
Diese Funktion wurde mit Adapter-Version 0.5.3 erweitert, in den Vor-Versionen konnte man hier lediglich einen neuen Zielwert setzen mit z.B. **{** `Radio Chillout` **}**. Dies unterstützt der Adapter weiterhin. Falls du also nur den Zielwert überschreiben willst, kannst du einfach **{** `Radio Chillout` **}** eingeben, anstatt **{** `val:Radio Chillout` **}**. Aber wenn du auch ein **delay** (Verzögertes Einschalten) setzen willst, musst du **{** `val:Radio Chillout, delay:20` **}** eingeben. Delay alleine, also **{** `delay:20` **}** geht natürlich auch, dann wird der Zielwert natürlich nicht überschrieben.
|
|
18
|
-
|
|
1
|
+
Durch Doppelklick oder F2 kannst du hier individuelle Optionen für Zielgeräte setzen.<br>
|
|
2
|
+
<details>
|
|
3
|
+
<summary style="padding-bottom:-20px">Weitere Erklärung (hier klicken)</summary> <!-- Header -->
|
|
4
|
+
<!-- Markdown Collapsible Section - We must have an empty line below -->
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
### Beispiele
|
|
8
|
+
* **{** `val:Radio Chillout, delay:20` **}**
|
|
9
|
+
* **{** `delay:30` **}**
|
|
10
|
+
* **{** `val:true` **}**
|
|
11
|
+
|
|
12
|
+
### Erklärung
|
|
13
|
+
* **val**: Hiermit wird der *Wert für 'an'* von *1. ZIELGERÄTE* überschrieben.
|
|
14
|
+
* **delay**: Hiermit wird *Verzögertes Einschalten des Zielgerätes* von *1. ZIELGERÄTE* durch die angegebene Anzahl Sekunden überschrieben. Zum Deaktivieren kannst du `delay:0` eintragen.<br>*Beispiel-Anwendungsfall (Use Case)*: Schalte den Strom-Zwischenstecker sofort ein, warte 30 Sekunden und schalte dann den Fernseher ein (weil er z.B. vorher noch nicht auf IR-Befehle reagiert) und dimme nach 50 Sekunden das Licht im TV-Eck.
|
|
15
|
+
|
|
16
|
+
#### Hinweis
|
|
17
|
+
Diese Funktion wurde mit Adapter-Version 0.5.3 erweitert, in den Vor-Versionen konnte man hier lediglich einen neuen Zielwert setzen mit z.B. **{** `Radio Chillout` **}**. Dies unterstützt der Adapter weiterhin. Falls du also nur den Zielwert überschreiben willst, kannst du einfach **{** `Radio Chillout` **}** eingeben, anstatt **{** `val:Radio Chillout` **}**. Aber wenn du auch ein **delay** (Verzögertes Einschalten) setzen willst, musst du **{** `val:Radio Chillout, delay:20` **}** eingeben. Delay alleine, also **{** `delay:20` **}** geht natürlich auch, dann wird der Zielwert natürlich nicht überschrieben.
|
|
18
|
+
|
|
19
19
|
</details>
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
Double click or hit F2 on a selected target device to set individual values.<br>
|
|
2
|
-
<details>
|
|
3
|
-
<summary style="padding-bottom:-20px">Further explanation (click me)</summary> <!-- Header -->
|
|
4
|
-
<!-- Markdown Collapsible Section - We must have an empty line below -->
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
### Examples
|
|
8
|
-
* **{** `val:Radio Chillout, delay:20` **}**
|
|
9
|
-
* **{** `delay:30` **}**
|
|
10
|
-
* **{** `val:true` **}**
|
|
11
|
-
|
|
12
|
-
### Explanation
|
|
13
|
-
* **val**: Overwrites *Value for 'on'* of *1. TARGET DEVICES*.
|
|
14
|
-
* **delay**: Overwrites *Delay for switching target device on* of *1. TARGET DEVICES* by the number of seconds set. To deactivate, use `delay:0`. <br>*Example use case*: Switch on a power plug immediately, wait 30 seconds and then switch on the TV (e.g. because it does not react to IR commands before) and dim the light in the TV corner after 50 seconds.
|
|
15
|
-
|
|
16
|
-
#### Please note
|
|
17
|
-
This function was extended with adapter version 0.5.3, in the previous versions you could only set a new target value with e.g. **{** `Radio Chillout` **}**. This is still supported by the adapter. So if you only want to overwrite the target value you can simply enter **{** `Radio Chillout` **}** instead of **{** `val:Radio Chillout` **}**. But if you also want to set a **delay** you have to enter **{** `val:Radio Chillout, delay:20` **}**. Delay alone, i.e. **{** `delay:20` **}** works too, but then the target value will not be overwritten, of course.
|
|
18
|
-
|
|
1
|
+
Double click or hit F2 on a selected target device to set individual values.<br>
|
|
2
|
+
<details>
|
|
3
|
+
<summary style="padding-bottom:-20px">Further explanation (click me)</summary> <!-- Header -->
|
|
4
|
+
<!-- Markdown Collapsible Section - We must have an empty line below -->
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
### Examples
|
|
8
|
+
* **{** `val:Radio Chillout, delay:20` **}**
|
|
9
|
+
* **{** `delay:30` **}**
|
|
10
|
+
* **{** `val:true` **}**
|
|
11
|
+
|
|
12
|
+
### Explanation
|
|
13
|
+
* **val**: Overwrites *Value for 'on'* of *1. TARGET DEVICES*.
|
|
14
|
+
* **delay**: Overwrites *Delay for switching target device on* of *1. TARGET DEVICES* by the number of seconds set. To deactivate, use `delay:0`. <br>*Example use case*: Switch on a power plug immediately, wait 30 seconds and then switch on the TV (e.g. because it does not react to IR commands before) and dim the light in the TV corner after 50 seconds.
|
|
15
|
+
|
|
16
|
+
#### Please note
|
|
17
|
+
This function was extended with adapter version 0.5.3, in the previous versions you could only set a new target value with e.g. **{** `Radio Chillout` **}**. This is still supported by the adapter. So if you only want to overwrite the target value you can simply enter **{** `Radio Chillout` **}** instead of **{** `val:Radio Chillout` **}**. But if you also want to set a **delay** you have to enter **{** `val:Radio Chillout, delay:20` **}**. Delay alone, i.e. **{** `delay:20` **}** works too, but then the target value will not be overwritten, of course.
|
|
18
|
+
|
|
19
19
|
</details>
|
package/admin/index_m.html
CHANGED
|
@@ -783,7 +783,7 @@
|
|
|
783
783
|
<div class="row error-section" style="padding-left:12px; padding-right:12px">
|
|
784
784
|
<p class="translate">log.verifyOptions.header</p>
|
|
785
785
|
<div id="save-errors" class="translate">Place holder, being replaced in save() function</div>
|
|
786
|
-
<p class="further-info translate">log.verifyOptions.info</p>
|
|
786
|
+
<!-- <p class="further-info translate">log.verifyOptions.info</p> -->
|
|
787
787
|
</div>
|
|
788
788
|
</div>
|
|
789
789
|
<div class="modal-footer">
|
package/admin/index_m.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable no-irregular-whitespace */
|
|
2
2
|
/* eslint-disable-next-line no-undef */
|
|
3
3
|
/* eslint-env jquery, browser */ // https://eslint.org/docs/user-guide/configuring#specifying-environments
|
|
4
|
-
/* global getEnums, common, systemLang, socket, values2table, table2values, M, _, instance */ // for eslint
|
|
4
|
+
/* global sendTo, getEnums, common, systemLang, socket, values2table, table2values, M, _, instance */ // for eslint
|
|
5
5
|
/**
|
|
6
6
|
* List of some global constants
|
|
7
7
|
*
|
|
@@ -110,7 +110,7 @@ function load2(settings, onChange) {
|
|
|
110
110
|
<p class='translation-required'>
|
|
111
111
|
Your current ioBroker language is <strong>${systemLang.toUpperCase()}</strong>, however, the following instructions have not yet been translated into your language, so English is used as fallback.
|
|
112
112
|
If you are fluently speaking ${systemLang.toUpperCase()}, please help and translate into your language.
|
|
113
|
-
The English file is <a target="_blank" href="https://github.com/
|
|
113
|
+
The English file is <a target="_blank" href="https://github.com/iobroker-community-adapters/ioBroker.smartcontrol/blob/master/admin/${mdFilePath}">located on Github</a>: <code>https://github.com/iobroker-community-adapters/ioBroker.smartcontrol/blob/master/admin/${mdFilePath}</code>.
|
|
114
114
|
Please translate and provide a Github pull request for adding a new file '${newFilePath}' with your ${systemLang.toUpperCase()} translation. Thank you!
|
|
115
115
|
</p>
|
|
116
116
|
`).insertBefore('zero-md#' + mdId);
|
|
@@ -690,107 +690,137 @@ function load2(settings, onChange) {
|
|
|
690
690
|
* Save Options - Called by the admin adapter when the user clicks save
|
|
691
691
|
* @param {function} callback(settingsObject) - callback function containing the settings object to be saved.
|
|
692
692
|
*/
|
|
693
|
-
function save(callback) { /*eslint-disable-line no-unused-vars*/
|
|
693
|
+
async function save(callback) { /*eslint-disable-line no-unused-vars*/
|
|
694
694
|
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
695
|
+
try {
|
|
696
|
+
|
|
697
|
+
/**
|
|
698
|
+
* Select elements with class=value and build settings object
|
|
699
|
+
* (from Adapter Creator)
|
|
700
|
+
*/
|
|
701
|
+
let obj = {};
|
|
702
|
+
$('.value').each(function() {
|
|
703
|
+
const $this = $(this);
|
|
704
|
+
if ($this.attr('type') === 'checkbox') {
|
|
705
|
+
obj[$this.attr('id')] = $this.prop('checked');
|
|
706
|
+
} else {
|
|
707
|
+
obj[$this.attr('id')] = $this.val();
|
|
708
|
+
}
|
|
709
|
+
});
|
|
710
|
+
|
|
711
|
+
// Set Option Table values
|
|
712
|
+
for (const tableId of tableIds) {
|
|
713
|
+
obj[tableId] = table2values(tableId);
|
|
706
714
|
}
|
|
707
|
-
});
|
|
708
715
|
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
obj[
|
|
712
|
-
}
|
|
716
|
+
// Set g_zonesTargetsOverwrite
|
|
717
|
+
// ! Must be after setting the Option Table Values
|
|
718
|
+
for (let i = 0; i < obj['tableZones'].length; i++) {
|
|
713
719
|
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
720
|
+
// get g_zonesTargetsOverwrite value for zone row
|
|
721
|
+
const overwriteObject = g_zonesTargetsOverwrite[obj['tableZones'][i]['name']]; // Like {'Hallway.Light':'new val' 'Hallway.Radio':'Radio XYZ'}
|
|
722
|
+
if (overwriteObject && !isLikeEmpty(overwriteObject)) {
|
|
723
|
+
obj['tableZones'][i]['targetsOverwrite'] = overwriteObject;
|
|
724
|
+
} else {
|
|
725
|
+
delete obj['tableZones'][i]['targetsOverwrite'];
|
|
726
|
+
}
|
|
717
727
|
|
|
718
|
-
// get g_zonesTargetsOverwrite value for zone row
|
|
719
|
-
const overwriteObject = g_zonesTargetsOverwrite[obj['tableZones'][i]['name']]; // Like {'Hallway.Light':'new val' 'Hallway.Radio':'Radio XYZ'}
|
|
720
|
-
if (overwriteObject && !isLikeEmpty(overwriteObject)) {
|
|
721
|
-
obj['tableZones'][i]['targetsOverwrite'] = overwriteObject;
|
|
722
|
-
} else {
|
|
723
|
-
delete obj['tableZones'][i]['targetsOverwrite'];
|
|
724
728
|
}
|
|
725
729
|
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
730
|
+
/*****************************
|
|
731
|
+
* Input Validation
|
|
732
|
+
* We use sendTo() to use adapter's node.js code for validation.
|
|
733
|
+
*****************************/
|
|
734
|
+
|
|
735
|
+
let verifyConfigResultObj = undefined;
|
|
736
|
+
let errors = [];
|
|
737
|
+
|
|
738
|
+
// Adapter must be alive
|
|
739
|
+
const aliveStateObj = await getStateAsync(`system.adapter.${adapterNamespace}.alive`);
|
|
740
|
+
if (aliveStateObj == null) throw(`'getStateAsync(${adapterNamespace}.alive)' returned error.`);
|
|
741
|
+
if (aliveStateObj && aliveStateObj.val) {
|
|
742
|
+
// Adapter is alive, so verify the config.
|
|
743
|
+
verifyConfigResultObj = await sendToAsync('verifyConfig', obj);
|
|
744
|
+
if (verifyConfigResultObj == null) throw(`'sendToAsync('verifyConfig', obj)' returned null`);
|
|
745
|
+
if (verifyConfigResultObj.passed) {
|
|
746
|
+
console.debug(`Verifying Config: successfully passed.`);
|
|
747
|
+
// Low priority (nice to have) enhancement idea: we may want to also update configuration by refreshing all tabs / tables.
|
|
748
|
+
// set the altered object
|
|
749
|
+
// obj = objResult.obj;
|
|
750
|
+
} else {
|
|
751
|
+
errors = verifyConfigResultObj.issues;
|
|
752
|
+
console.warn(`Verifying Config: failed!`);
|
|
753
|
+
}
|
|
732
754
|
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
{tabName:'3. TRIGGERS', tableRows:obj.tableTriggerMotion.concat(obj.tableTriggerDevices, obj.tableTriggerTimes)},
|
|
737
|
-
{tabName:'4. ZONES', tableRows:obj.tableZones},
|
|
738
|
-
];
|
|
739
|
-
for (const lpCheckObj of tablesToCheck) {
|
|
740
|
-
let activeRows = 0;
|
|
741
|
-
let rowCounter = 0;
|
|
742
|
-
const tabName = lpCheckObj.tabName;
|
|
743
|
-
const tableRows = lpCheckObj.tableRows;
|
|
744
|
-
for (const lpTableRow of tableRows) {
|
|
745
|
-
rowCounter++;
|
|
746
|
-
if (lpTableRow.active) activeRows++;
|
|
747
|
-
}
|
|
748
|
-
if (rowCounter == 0 || activeRows == 0) {
|
|
749
|
-
errors.push(`<strong>Tab "${tabName}"</strong> - Total number of rows: ${rowCounter}, active rows: ${activeRows}. At least one active row is required.`);
|
|
755
|
+
} else {
|
|
756
|
+
// Adapter is NOT alive
|
|
757
|
+
errors = [`Adapter instance ${adapterNamespace} is not running, so we cannot verify the configuration and cannot save your changes. Please turn the adapter instance on. Hint: To not lose your changes, keep this browser window/tab open, open ioBroker in a new browser window/tab, turn the adapter instance on, and try again to save the changes.`];
|
|
750
758
|
}
|
|
751
|
-
}
|
|
752
759
|
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
let countValid = 0;
|
|
762
|
-
for (const lpExecRow of executionArr) {
|
|
763
|
-
if(
|
|
764
|
-
lpExecRow.active
|
|
765
|
-
&& (lpExecRow.start && lpExecRow.start.trim().length > 0)
|
|
766
|
-
&& (lpExecRow.end && lpExecRow.end.trim().length > 0)
|
|
767
|
-
&& (lpExecRow.mon || lpExecRow.tue || lpExecRow.wed || lpExecRow.thu || lpExecRow.fri || lpExecRow.sat || lpExecRow.sun)
|
|
768
|
-
) {
|
|
769
|
-
countValid++;
|
|
770
|
-
}
|
|
771
|
-
}
|
|
772
|
-
if (countValid == 0) {
|
|
773
|
-
errors.push(`<strong>Tab "4. ZONES"</strong> - Zone '${lpZonesRow.name}': Invalid or no execution defined.`);
|
|
774
|
-
}
|
|
760
|
+
if(errors.length === 0) {
|
|
761
|
+
// Finally, save settings by calling callback function and provide the settings object
|
|
762
|
+
callback(obj);
|
|
763
|
+
} else {
|
|
764
|
+
// Errors occurred, so do not save settings but provide dialog with the errors
|
|
765
|
+
let errorHtml = '<ol>\n';
|
|
766
|
+
for (const errorEntry of errors) {
|
|
767
|
+
errorHtml += `<li>${errorEntry}</li>`;
|
|
775
768
|
}
|
|
769
|
+
errorHtml += '\n</ol>';
|
|
770
|
+
// open error dialog
|
|
771
|
+
$('#dialog-save-verification #save-errors').html(errorHtml);
|
|
772
|
+
$('#dialog-save-verification').modal();
|
|
773
|
+
$('#dialog-save-verification').modal('open');
|
|
776
774
|
}
|
|
775
|
+
|
|
776
|
+
} catch (error) {
|
|
777
|
+
console.error(`[save()] - ${error}`);
|
|
778
|
+
return;
|
|
777
779
|
}
|
|
778
780
|
|
|
779
781
|
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
|
|
785
|
+
/**
|
|
786
|
+
* Promise Wrapping:
|
|
787
|
+
* async sendTo
|
|
788
|
+
* Mic - 25-Nov-2020
|
|
789
|
+
* @param {string} cmd - Command
|
|
790
|
+
* @param {object} obj - Object
|
|
791
|
+
* @return {Promise<object|null>}
|
|
792
|
+
*/
|
|
793
|
+
function sendToAsync(cmd, obj) {
|
|
794
|
+
return new Promise((resolve, reject) => {
|
|
795
|
+
sendTo(adapterNamespace, cmd, obj, (result) => {
|
|
796
|
+
if (result.error) {
|
|
797
|
+
console.error('sendToAsync(): ' + result.error);
|
|
798
|
+
reject(null);
|
|
799
|
+
} else {
|
|
800
|
+
resolve(result);
|
|
801
|
+
}
|
|
802
|
+
});
|
|
803
|
+
});
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
/**
|
|
807
|
+
* Promise Wrapping:
|
|
808
|
+
* async getState
|
|
809
|
+
* Mic - 01-Dec-2020
|
|
810
|
+
* @param {string} id - state id
|
|
811
|
+
* @return {Promise<object|null>} state object, or null if error
|
|
812
|
+
*/
|
|
813
|
+
function getStateAsync(id) {
|
|
814
|
+
return new Promise((resolve, reject) => {
|
|
815
|
+
socket.emit('getState', id, (err, stateObj) => {
|
|
816
|
+
if (err) {
|
|
817
|
+
console.error('getStateAsync(): ' + err);
|
|
818
|
+
reject(null);
|
|
819
|
+
} else {
|
|
820
|
+
resolve(stateObj);
|
|
821
|
+
}
|
|
822
|
+
});
|
|
823
|
+
});
|
|
794
824
|
}
|
|
795
825
|
|
|
796
826
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Minified by jsDelivr using Terser v3.14.1.
|
|
4
|
-
* Original file: /npm/@webcomponents/webcomponentsjs@2.4.4/webcomponents-loader.js
|
|
5
|
-
*
|
|
6
|
-
* Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
|
|
7
|
-
*/
|
|
8
|
-
!function(){"use strict";var e,n=!1,t=[],o=!1;function d(){window.WebComponents.ready=!0,document.dispatchEvent(new CustomEvent("WebComponentsReady",{bubbles:!0}))}function i(){window.customElements&&customElements.polyfillWrapFlushCallback&&customElements.polyfillWrapFlushCallback(function(n){e=n,o&&e()})}function r(){window.HTMLTemplateElement&&HTMLTemplateElement.bootstrap&&HTMLTemplateElement.bootstrap(window.document),n=!0,c().then(d)}function c(){o=!1;var n=t.map(function(e){return e instanceof Function?e():e});return t=[],Promise.all(n).then(function(){o=!0,e&&e()}).catch(function(e){console.error(e)})}window.WebComponents=window.WebComponents||{},window.WebComponents.ready=window.WebComponents.ready||!1,window.WebComponents.waitFor=window.WebComponents.waitFor||function(e){e&&(t.push(e),n&&c())},window.WebComponents._batchCustomElements=i;var a="webcomponents-loader.js",l=[];(!("attachShadow"in Element.prototype&&"getRootNode"in Element.prototype)||window.ShadyDOM&&window.ShadyDOM.force)&&l.push("sd"),window.customElements&&!window.customElements.forcePolyfill||l.push("ce");var s=function(){var e=document.createElement("template");if(!("content"in e))return!0;if(!(e.content.cloneNode()instanceof DocumentFragment))return!0;var n=document.createElement("template");n.content.appendChild(document.createElement("div")),e.content.appendChild(n);var t=e.cloneNode(!0);return 0===t.content.childNodes.length||0===t.content.firstChild.content.childNodes.length}();if(window.Promise&&Array.from&&window.URL&&window.Symbol&&!s||(l=["sd-ce-pf"]),l.length){var m,w="bundles/webcomponents-"+l.join("-")+".js";if(window.WebComponents.root)m=window.WebComponents.root+w;else{var u=document.querySelector('script[src*="'+a+'"]');m=u.src.replace(a,w)}var p=document.createElement("script");p.src=m,"loading"===document.readyState?(p.setAttribute("onload","window.WebComponents._batchCustomElements()"),document.write(p.outerHTML),document.addEventListener("DOMContentLoaded",r)):(p.addEventListener("load",function(){i(),r()}),p.addEventListener("error",function(){throw new Error("Could not load polyfill bundle"+m)}),document.head.appendChild(p))}else"complete"===document.readyState?(n=!0,d()):(window.addEventListener("load",r),window.addEventListener("DOMContentLoaded",function(){window.removeEventListener("load",r),r()}))}();
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* Minified by jsDelivr using Terser v3.14.1.
|
|
4
|
+
* Original file: /npm/@webcomponents/webcomponentsjs@2.4.4/webcomponents-loader.js
|
|
5
|
+
*
|
|
6
|
+
* Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
|
|
7
|
+
*/
|
|
8
|
+
!function(){"use strict";var e,n=!1,t=[],o=!1;function d(){window.WebComponents.ready=!0,document.dispatchEvent(new CustomEvent("WebComponentsReady",{bubbles:!0}))}function i(){window.customElements&&customElements.polyfillWrapFlushCallback&&customElements.polyfillWrapFlushCallback(function(n){e=n,o&&e()})}function r(){window.HTMLTemplateElement&&HTMLTemplateElement.bootstrap&&HTMLTemplateElement.bootstrap(window.document),n=!0,c().then(d)}function c(){o=!1;var n=t.map(function(e){return e instanceof Function?e():e});return t=[],Promise.all(n).then(function(){o=!0,e&&e()}).catch(function(e){console.error(e)})}window.WebComponents=window.WebComponents||{},window.WebComponents.ready=window.WebComponents.ready||!1,window.WebComponents.waitFor=window.WebComponents.waitFor||function(e){e&&(t.push(e),n&&c())},window.WebComponents._batchCustomElements=i;var a="webcomponents-loader.js",l=[];(!("attachShadow"in Element.prototype&&"getRootNode"in Element.prototype)||window.ShadyDOM&&window.ShadyDOM.force)&&l.push("sd"),window.customElements&&!window.customElements.forcePolyfill||l.push("ce");var s=function(){var e=document.createElement("template");if(!("content"in e))return!0;if(!(e.content.cloneNode()instanceof DocumentFragment))return!0;var n=document.createElement("template");n.content.appendChild(document.createElement("div")),e.content.appendChild(n);var t=e.cloneNode(!0);return 0===t.content.childNodes.length||0===t.content.firstChild.content.childNodes.length}();if(window.Promise&&Array.from&&window.URL&&window.Symbol&&!s||(l=["sd-ce-pf"]),l.length){var m,w="bundles/webcomponents-"+l.join("-")+".js";if(window.WebComponents.root)m=window.WebComponents.root+w;else{var u=document.querySelector('script[src*="'+a+'"]');m=u.src.replace(a,w)}var p=document.createElement("script");p.src=m,"loading"===document.readyState?(p.setAttribute("onload","window.WebComponents._batchCustomElements()"),document.write(p.outerHTML),document.addEventListener("DOMContentLoaded",r)):(p.addEventListener("load",function(){i(),r()}),p.addEventListener("error",function(){throw new Error("Could not load polyfill bundle"+m)}),document.head.appendChild(p))}else"complete"===document.readyState?(n=!0,d()):(window.addEventListener("load",r),window.addEventListener("DOMContentLoaded",function(){window.removeEventListener("load",r),r()}))}();
|
|
9
9
|
//# sourceMappingURL=/sm/1a92a68f67d0deedb11065efad6be1c738c60921df9284a68170191521d7fbb7.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Minified by jsDelivr using Terser v3.14.1.
|
|
4
|
-
* Original file: /gh/zerodevx/zero-md@1.3.4/src/zero-md.js
|
|
5
|
-
*
|
|
6
|
-
* Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
|
|
7
|
-
*/
|
|
8
|
-
window,document,window.customElements.define("zero-md",class extends HTMLElement{get version(){return"v1.3.4"}get src(){return this.getAttribute("src")}get manualRender(){return this.hasAttribute("manual-render")}get noShadow(){return this.hasAttribute("no-shadow")}get markedUrl(){return this.getAttribute("marked-url")||window.ZeroMd.config.markedUrl}get prismUrl(){return this.getAttribute("prism-url")||window.ZeroMd.config.prismUrl}get cssUrls(){let e=this.getAttribute("css-urls");return e?JSON.parse(e):window.ZeroMd.config.cssUrls}constructor(){super(),window.ZeroMd=window.ZeroMd||{},window.ZeroMd.config=window.ZeroMd.config||{},window.ZeroMd.config.markedUrl=window.ZeroMd.config.markedUrl||"https://cdn.jsdelivr.net/npm/marked@0/marked.min.js",window.ZeroMd.config.prismUrl=window.ZeroMd.config.prismUrl||"https://cdn.jsdelivr.net/npm/prismjs@1/prism.min.js",window.ZeroMd.config.cssUrls=window.ZeroMd.config.cssUrls||["https://cdn.jsdelivr.net/npm/github-markdown-css@2/github-markdown.min.css","https://cdn.jsdelivr.net/npm/prismjs@1/themes/prism.min.css"],window.ZeroMd.cache=window.ZeroMd.cache||{}}connectedCallback(){this.addEventListener("click",this._hijackLinks.bind(this)),this.addEventListener("zero-md-rendered",function e(){this.removeEventListener("zero-md-rendered",e),window.setTimeout(()=>{this._scrollTo(window.location.hash)})}.bind(this)),this.manualRender||this.render(),this._fire("zero-md-ready")}_fire(e){this.dispatchEvent(new CustomEvent(e,{bubbles:!0,composed:!0}))}_ajaxGet(e){return new Promise((t,r)=>{if(!e)return void r(e);let i=new XMLHttpRequest,n=t=>{console.warn("[zero-md] Error getting file",e),r(t)};i.open("GET",e,!0),i.onload=(()=>{i.status>=200&&i.status<400?t(i.responseText):n(i)}),i.onerror=(e=>n(e)),i.send()})}_loadScript(e,t,r,...i){return new Promise((n,s)=>{if("undefined"===t)if(window.ZeroMd.cache.hasOwnProperty(r))window.addEventListener(r,function e(){window.removeEventListener(r,e),n()});else{window.ZeroMd.cache[r]=!0;let t=document.createElement("script");for(let e of i)t.setAttribute(e,"");t.onload=(()=>{this._fire(r),n()}),t.onerror=(t=>{console.warn("[zero-md] Error loading script",e),s(t)}),t.src=e,document.head.appendChild(t)}else n()})}_getStylesheet(e){return new Promise((t,r)=>{window.ZeroMd.cache[e]?window.ZeroMd.cache[e].loaded?t(window.ZeroMd.cache[e].data):window.addEventListener(e,function r(){window.removeEventListener(e,r),t(window.ZeroMd.cache[e].data)}):(window.ZeroMd.cache[e]={loaded:!1,data:""},this._ajaxGet(e).then(r=>{window.ZeroMd.cache[e].data=r,window.ZeroMd.cache[e].loaded=!0,this._fire(e),t(r)},e=>r(e)))})}_getInputs(){return new Promise((e,t)=>{let r=this.querySelector("template")&&this.querySelector("template").content.querySelector("xmp")||!1;r?e(r.textContent):this._ajaxGet(this.src).then(t=>e(t)).catch(e=>t(e))})}_prismHighlight(e,t){return window.Prism.highlight(e,this._detectLang(e,t))}_detectLang(e,t){return t?window.Prism.languages.hasOwnProperty(t)?window.Prism.languages[t]:"es"===t.substr(0,2)?window.Prism.languages.javascript:"c"===t?window.Prism.languages.clike:window.Prism.languages.markup:e.match(/^\s*</)?window.Prism.languages.markup:window.Prism.languages.javascript}_stampDom(e){let t=this.querySelectorAll("[class^=markdown]");t&&t.forEach(e=>this.removeChild(e)),this.shadowRoot&&(this.shadowRoot.innerHTML=""),this.noShadow?this.insertAdjacentHTML("afterbegin",e):(this.shadowRoot||this.attachShadow({mode:"open"})).innerHTML=e}_buildMd(){return new Promise((e,t)=>{Promise.all([this._getInputs(),this._loadScript(this.markedUrl,typeof window.marked,"zero-md-marked-ready","async"),this._loadScript(this.prismUrl,typeof window.Prism,"zero-md-prism-ready","async","data-manual")]).then(t=>{e('<div class="markdown-body">'+window.marked(t[0],{highlight:this._prismHighlight.bind(this)})+"</div>")},e=>{t(e)})})}_buildStyles(){return new Promise(e=>{let t='<style class="markdown-style">:host{display:block;position:relative;contain:content;}',r="</style>",i=this.querySelector("template")&&this.querySelector("template").content.querySelector("style")||!1;i?e(t+i.textContent+r):Array.isArray(this.cssUrls)&&this.cssUrls.length?Promise.all(this.cssUrls.map(e=>this._getStylesheet(e))).then(i=>e(t+i.join("")+r)).catch(()=>e(t+r)):(console.warn("[zero-md] No styles are defined"),e(t+r))})}_scrollTo(e){if(!e||!this.shadowRoot)return;let t=this.shadowRoot.getElementById(e.substr(1));t&&t.scrollIntoView()}_hijackLinks(e){let t=e.path||e.composedPath();if("A"!==t[0].tagName)return;const r=t[0];r.hash&&r.origin+r.pathname===window.location.origin+window.location.pathname&&(e.metaKey?window.open(r.href,"_blank"):(this._scrollTo(r.hash),window.location=r.href),e.preventDefault())}render(){Promise.all([this._buildStyles(),this._buildMd()]).then(e=>{this._stampDom(e[0]+e[1]),this._fire("zero-md-rendered")})}});
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* Minified by jsDelivr using Terser v3.14.1.
|
|
4
|
+
* Original file: /gh/zerodevx/zero-md@1.3.4/src/zero-md.js
|
|
5
|
+
*
|
|
6
|
+
* Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
|
|
7
|
+
*/
|
|
8
|
+
window,document,window.customElements.define("zero-md",class extends HTMLElement{get version(){return"v1.3.4"}get src(){return this.getAttribute("src")}get manualRender(){return this.hasAttribute("manual-render")}get noShadow(){return this.hasAttribute("no-shadow")}get markedUrl(){return this.getAttribute("marked-url")||window.ZeroMd.config.markedUrl}get prismUrl(){return this.getAttribute("prism-url")||window.ZeroMd.config.prismUrl}get cssUrls(){let e=this.getAttribute("css-urls");return e?JSON.parse(e):window.ZeroMd.config.cssUrls}constructor(){super(),window.ZeroMd=window.ZeroMd||{},window.ZeroMd.config=window.ZeroMd.config||{},window.ZeroMd.config.markedUrl=window.ZeroMd.config.markedUrl||"https://cdn.jsdelivr.net/npm/marked@0/marked.min.js",window.ZeroMd.config.prismUrl=window.ZeroMd.config.prismUrl||"https://cdn.jsdelivr.net/npm/prismjs@1/prism.min.js",window.ZeroMd.config.cssUrls=window.ZeroMd.config.cssUrls||["https://cdn.jsdelivr.net/npm/github-markdown-css@2/github-markdown.min.css","https://cdn.jsdelivr.net/npm/prismjs@1/themes/prism.min.css"],window.ZeroMd.cache=window.ZeroMd.cache||{}}connectedCallback(){this.addEventListener("click",this._hijackLinks.bind(this)),this.addEventListener("zero-md-rendered",function e(){this.removeEventListener("zero-md-rendered",e),window.setTimeout(()=>{this._scrollTo(window.location.hash)})}.bind(this)),this.manualRender||this.render(),this._fire("zero-md-ready")}_fire(e){this.dispatchEvent(new CustomEvent(e,{bubbles:!0,composed:!0}))}_ajaxGet(e){return new Promise((t,r)=>{if(!e)return void r(e);let i=new XMLHttpRequest,n=t=>{console.warn("[zero-md] Error getting file",e),r(t)};i.open("GET",e,!0),i.onload=(()=>{i.status>=200&&i.status<400?t(i.responseText):n(i)}),i.onerror=(e=>n(e)),i.send()})}_loadScript(e,t,r,...i){return new Promise((n,s)=>{if("undefined"===t)if(window.ZeroMd.cache.hasOwnProperty(r))window.addEventListener(r,function e(){window.removeEventListener(r,e),n()});else{window.ZeroMd.cache[r]=!0;let t=document.createElement("script");for(let e of i)t.setAttribute(e,"");t.onload=(()=>{this._fire(r),n()}),t.onerror=(t=>{console.warn("[zero-md] Error loading script",e),s(t)}),t.src=e,document.head.appendChild(t)}else n()})}_getStylesheet(e){return new Promise((t,r)=>{window.ZeroMd.cache[e]?window.ZeroMd.cache[e].loaded?t(window.ZeroMd.cache[e].data):window.addEventListener(e,function r(){window.removeEventListener(e,r),t(window.ZeroMd.cache[e].data)}):(window.ZeroMd.cache[e]={loaded:!1,data:""},this._ajaxGet(e).then(r=>{window.ZeroMd.cache[e].data=r,window.ZeroMd.cache[e].loaded=!0,this._fire(e),t(r)},e=>r(e)))})}_getInputs(){return new Promise((e,t)=>{let r=this.querySelector("template")&&this.querySelector("template").content.querySelector("xmp")||!1;r?e(r.textContent):this._ajaxGet(this.src).then(t=>e(t)).catch(e=>t(e))})}_prismHighlight(e,t){return window.Prism.highlight(e,this._detectLang(e,t))}_detectLang(e,t){return t?window.Prism.languages.hasOwnProperty(t)?window.Prism.languages[t]:"es"===t.substr(0,2)?window.Prism.languages.javascript:"c"===t?window.Prism.languages.clike:window.Prism.languages.markup:e.match(/^\s*</)?window.Prism.languages.markup:window.Prism.languages.javascript}_stampDom(e){let t=this.querySelectorAll("[class^=markdown]");t&&t.forEach(e=>this.removeChild(e)),this.shadowRoot&&(this.shadowRoot.innerHTML=""),this.noShadow?this.insertAdjacentHTML("afterbegin",e):(this.shadowRoot||this.attachShadow({mode:"open"})).innerHTML=e}_buildMd(){return new Promise((e,t)=>{Promise.all([this._getInputs(),this._loadScript(this.markedUrl,typeof window.marked,"zero-md-marked-ready","async"),this._loadScript(this.prismUrl,typeof window.Prism,"zero-md-prism-ready","async","data-manual")]).then(t=>{e('<div class="markdown-body">'+window.marked(t[0],{highlight:this._prismHighlight.bind(this)})+"</div>")},e=>{t(e)})})}_buildStyles(){return new Promise(e=>{let t='<style class="markdown-style">:host{display:block;position:relative;contain:content;}',r="</style>",i=this.querySelector("template")&&this.querySelector("template").content.querySelector("style")||!1;i?e(t+i.textContent+r):Array.isArray(this.cssUrls)&&this.cssUrls.length?Promise.all(this.cssUrls.map(e=>this._getStylesheet(e))).then(i=>e(t+i.join("")+r)).catch(()=>e(t+r)):(console.warn("[zero-md] No styles are defined"),e(t+r))})}_scrollTo(e){if(!e||!this.shadowRoot)return;let t=this.shadowRoot.getElementById(e.substr(1));t&&t.scrollIntoView()}_hijackLinks(e){let t=e.path||e.composedPath();if("A"!==t[0].tagName)return;const r=t[0];r.hash&&r.origin+r.pathname===window.location.origin+window.location.pathname&&(e.metaKey?window.open(r.href,"_blank"):(this._scrollTo(r.hash),window.location=r.href),e.preventDefault())}render(){Promise.all([this._buildStyles(),this._buildMd()]).then(e=>{this._stampDom(e[0]+e[1]),this._fire("zero-md-rendered")})}});
|
|
9
9
|
//# sourceMappingURL=/sm/4ea87c94a5676c3bbd7b8ef6009ea5891783fbe1fa7f72cb94912411c81b7de0.map
|