@lowdefy/blocks-basic 6.0.0 → 7.0.0

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.
Files changed (41) hide show
  1. package/dist/blocks/Anchor/Anchor.js +1 -1
  2. package/dist/blocks/Anchor/gallery.yaml +14 -14
  3. package/dist/blocks/Anchor/meta.js +11 -2
  4. package/dist/blocks/Anchor/tests/Anchor.e2e.yaml +10 -1
  5. package/dist/blocks/Anchor/tests/AnchorPathTarget.e2e.yaml +23 -0
  6. package/dist/blocks/Anchor/tests.yaml +6 -6
  7. package/dist/blocks/Box/Box.js +9 -5
  8. package/dist/blocks/Box/gallery.yaml +9 -9
  9. package/dist/blocks/Box/tests/Box.e2e.yaml +62 -0
  10. package/dist/blocks/Box/tests/BoxPageTitle.e2e.yaml +57 -0
  11. package/dist/blocks/ClickableHtml/ClickableHtml.js +34 -0
  12. package/dist/blocks/ClickableHtml/e2e.js +23 -0
  13. package/dist/blocks/ClickableHtml/gallery.yaml +199 -0
  14. package/dist/blocks/ClickableHtml/meta.js +96 -0
  15. package/dist/blocks/ClickableHtml/tests/ClickableHtml.e2e.yaml +188 -0
  16. package/dist/blocks/ClickableHtml/tests.yaml +48 -0
  17. package/dist/blocks/DangerousHtml/DangerousHtml.js +19 -19
  18. package/dist/blocks/DangerousHtml/meta.js +13 -1
  19. package/dist/blocks/Dynamic/Dynamic.js +5 -3
  20. package/dist/blocks/Dynamic/meta.js +4 -0
  21. package/dist/blocks/Html/gallery.yaml +28 -0
  22. package/dist/blocks/Html/meta.js +23 -1
  23. package/dist/blocks/Html/tests/Html.e2e.yaml +13 -0
  24. package/dist/blocks/Icon/Icon.js +21 -1
  25. package/dist/blocks/Icon/gallery.yaml +158 -64
  26. package/dist/blocks/Icon/meta.js +11 -4
  27. package/dist/blocks/Icon/tests/Icon.e2e.yaml +3 -3
  28. package/dist/blocks/Icon/tests.yaml +7 -7
  29. package/dist/blocks/Img/meta.js +12 -4
  30. package/dist/blocks/List/gallery.yaml +11 -11
  31. package/dist/blocks/PollingTimer/PollingTimer.js +120 -0
  32. package/dist/blocks/PollingTimer/e2e.js +21 -0
  33. package/dist/blocks/PollingTimer/gallery.yaml +190 -0
  34. package/dist/blocks/PollingTimer/meta.js +61 -0
  35. package/dist/blocks/PollingTimer/validateInterval.js +21 -0
  36. package/dist/blocks/Span/Span.js +5 -3
  37. package/dist/blocks/Span/gallery.yaml +7 -7
  38. package/dist/blocks.js +2 -0
  39. package/dist/e2e.js +2 -0
  40. package/dist/metas.js +2 -0
  41. package/package.json +9 -6
@@ -0,0 +1,199 @@
1
+ # Copyright 2020-2026 Lowdefy, Inc
2
+
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ - title: A named event per button
15
+ blocks:
16
+ - id: buttons_basic
17
+ type: ClickableHtml
18
+ properties:
19
+ dataEvents:
20
+ - onSmallClick
21
+ - onLargeClick
22
+ html: '<p>Pick a size: <button data-event="onSmallClick">Small</button> <button data-event="onLargeClick">Large</button></p>'
23
+ events:
24
+ onSmallClick:
25
+ - id: set_small
26
+ type: SetState
27
+ params:
28
+ buttons_basic_selected: small
29
+ onLargeClick:
30
+ - id: set_large
31
+ type: SetState
32
+ params:
33
+ buttons_basic_selected: large
34
+ - id: buttons_basic_result
35
+ type: Html
36
+ properties:
37
+ html:
38
+ _string.concat:
39
+ - '<p>State: <code>'
40
+ - _state:
41
+ key: buttons_basic_selected
42
+ default: 'nothing yet'
43
+ - '</code></p>'
44
+
45
+ - title: Data attributes are the event object
46
+ blocks:
47
+ - id: list_rows
48
+ type: ClickableHtml
49
+ properties:
50
+ dataEvents:
51
+ - onRowClick
52
+ html: '<ul style="list-style: none; padding: 0; margin: 0;"><li data-event="onRowClick" data-record-id="rec_1" style="padding: 8px; cursor: pointer; border-bottom: 1px solid var(--ant-color-border);">First record</li><li data-event="onRowClick" data-record-id="rec_2" style="padding: 8px; cursor: pointer; border-bottom: 1px solid var(--ant-color-border);">Second record</li><li data-event="onRowClick" data-record-id="rec_3" style="padding: 8px; cursor: pointer;">Third record</li></ul>'
53
+ events:
54
+ onRowClick:
55
+ - id: set_clicked
56
+ type: SetState
57
+ params:
58
+ list_rows_clicked:
59
+ _event: true
60
+ - id: list_rows_result
61
+ type: Html
62
+ properties:
63
+ html:
64
+ _string.concat:
65
+ - '<p>Last event: <code>'
66
+ - _json.stringify:
67
+ _state:
68
+ key: list_rows_clicked
69
+ default: {}
70
+ - '</code></p>'
71
+
72
+ - title: Links and plain markup are left to the browser
73
+ blocks:
74
+ - id: mixed_content
75
+ type: ClickableHtml
76
+ properties:
77
+ dataEvents:
78
+ - onCommentClick
79
+ html: '<p>This <a href="https://lowdefy.com" target="_blank">link</a> navigates normally, but <a href="#" data-event="onCommentClick" data-thread-id="t_9">this one</a> fires onCommentClick instead.</p>'
80
+ events:
81
+ onCommentClick:
82
+ - id: set_mixed
83
+ type: SetState
84
+ params:
85
+ mixed_content_thread:
86
+ _event: thread_id
87
+ - id: mixed_content_result
88
+ type: Html
89
+ properties:
90
+ html:
91
+ _string.concat:
92
+ - '<p>Thread: <code>'
93
+ - _state:
94
+ key: mixed_content_thread
95
+ default: 'none'
96
+ - '</code></p>'
97
+
98
+ - title: Style Overrides
99
+ blocks:
100
+ - id: style_card
101
+ type: ClickableHtml
102
+ style:
103
+ .element:
104
+ padding: 16
105
+ borderRadius: 8
106
+ border: 1px solid var(--ant-color-border)
107
+ background: var(--ant-color-bg-container)
108
+ properties:
109
+ dataEvents:
110
+ - onEditClick
111
+ - onRemoveClick
112
+ html: '<h4 style="margin: 0 0 8px 0;">Card</h4><p style="margin: 0 0 8px 0; color: var(--ant-color-text-secondary);">Yours to change or remove until tomorrow.</p><button data-event="onEditClick">Edit</button> <button data-event="onRemoveClick">Remove</button>'
113
+ events:
114
+ onEditClick:
115
+ - id: set_card_edit
116
+ type: SetState
117
+ params:
118
+ style_card_action: edit
119
+ onRemoveClick:
120
+ - id: set_card_remove
121
+ type: SetState
122
+ params:
123
+ style_card_action: remove
124
+
125
+ - title: Clickable icons and a popover menu
126
+ blocks:
127
+ - id: row_actions
128
+ type: ClickableHtml
129
+ properties:
130
+ dataEvents:
131
+ - onEdit
132
+ - onDuplicate
133
+ - name: onDelete
134
+ confirm: Delete invoice INV-042?
135
+ html: '<p>Invoice INV-042 <i data-icon="edit" data-event="onEdit" data-id="42" data-tooltip="Edit" style="cursor: pointer"></i> <span data-popover="more" style="cursor: pointer"><i data-icon="more-vertical"></i></span></p><div data-popover-content="more" hidden><p data-event="onDuplicate" data-id="42" style="cursor: pointer; margin: 0 0 8px"><i data-icon="copy"></i> Duplicate</p><p data-event="onDelete" data-id="42" style="cursor: pointer; margin: 0; color: var(--ant-color-error)"><i data-icon="delete"></i> Delete</p></div>'
136
+ events:
137
+ onEdit:
138
+ - id: set_edit
139
+ type: SetState
140
+ params:
141
+ row_actions_last: { _string.concat: ['edit ', { _event: id }] }
142
+ onDuplicate:
143
+ - id: set_duplicate
144
+ type: SetState
145
+ params:
146
+ row_actions_last: { _string.concat: ['duplicate ', { _event: id }] }
147
+ onDelete:
148
+ - id: set_delete
149
+ type: SetState
150
+ params:
151
+ row_actions_last: { _string.concat: ['delete ', { _event: id }] }
152
+ - id: row_actions_result
153
+ type: Html
154
+ properties:
155
+ html:
156
+ _string.concat:
157
+ - '<p>Last action: <code>'
158
+ - _state:
159
+ key: row_actions_last
160
+ default: 'none yet'
161
+ - '</code></p>'
162
+
163
+ - title: Confirm before an event
164
+ blocks:
165
+ - id: confirm_actions
166
+ type: ClickableHtml
167
+ properties:
168
+ dataEvents:
169
+ - name: onDelete
170
+ confirm: true
171
+ - onArchive
172
+ html: '<p>INV-2026-0042 <i data-icon="delete" data-event="onDelete" data-id="42" data-tooltip="Delete" data-confirm="Delete invoice INV-2026-0042?" style="cursor: pointer; color: var(--ant-color-error)"></i> <span data-event="onArchive" data-id="42" data-confirm style="cursor: pointer; color: var(--ant-color-primary)">Archive</span></p>'
173
+ events:
174
+ onDelete:
175
+ - id: deleted
176
+ type: SetState
177
+ params:
178
+ confirm_last:
179
+ _string.concat:
180
+ - 'deleted '
181
+ - _event: id
182
+ onArchive:
183
+ - id: archived
184
+ type: SetState
185
+ params:
186
+ confirm_last:
187
+ _string.concat:
188
+ - 'archived '
189
+ - _event: id
190
+ - id: confirm_result
191
+ type: Html
192
+ properties:
193
+ html:
194
+ _string.concat:
195
+ - '<p>Last action: <code>'
196
+ - _state:
197
+ key: confirm_last
198
+ default: 'none yet'
199
+ - '</code></p>'
@@ -0,0 +1,96 @@
1
+ /*
2
+ Copyright 2020-2026 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ export default {
16
+ category: 'display',
17
+ icons: [],
18
+ valueType: null,
19
+ cssKeys: {
20
+ element: 'The Html element.'
21
+ },
22
+ hazards: [
23
+ {
24
+ id: 'html-style-stripped',
25
+ message: 'Content is sanitised with DOMPurify, so <style>, <script> and inline event handlers are removed before render. Clicks are wired through data-event attributes instead of inline handlers.',
26
+ see: 'display-blocks/clickablehtml'
27
+ },
28
+ {
29
+ id: 'clickable-html-data-events',
30
+ message: 'List every event the HTML fires in properties.dataEvents: a data-event whose name is not listed does nothing. HTML built from user or request data must escape that data, so the data cannot add data-event elements of its own: _nunjucks escapes {{ values }} unless they are marked safe, while _string.concat and _js do not escape.',
31
+ see: 'display-blocks/clickablehtml'
32
+ },
33
+ {
34
+ id: 'clickable-html-confirm-destructive',
35
+ message: 'Give an event that deletes or changes data confirm in dataEvents ({ name: onDelete, confirm: "Delete this row?" }), so every click on it asks first and only OK fires it. data-confirm="Delete this row?" on the element asks too, but only where the markup says so.',
36
+ see: 'concepts/html-attributes'
37
+ }
38
+ ],
39
+ // Each clickable element names its event in a data-event attribute, so the
40
+ // event names this block fires are authored in its html.
41
+ dynamicEvents: true,
42
+ events: {
43
+ onTextSelection: 'Trigger action when text is selected and pass selected text to the event object.'
44
+ },
45
+ properties: {
46
+ type: 'object',
47
+ additionalProperties: false,
48
+ properties: {
49
+ dataEvents: {
50
+ type: 'array',
51
+ description: 'The events the HTML may fire. A data-event whose name is not listed does nothing, and a click on it logs a console warning; with no dataEvents the HTML fires no events. List an event by name, or as { name, confirm } to make every click on it ask first.',
52
+ items: {
53
+ oneOf: [
54
+ {
55
+ type: 'string',
56
+ description: 'An event name, as written in data-event.'
57
+ },
58
+ {
59
+ type: 'object',
60
+ additionalProperties: false,
61
+ required: [
62
+ 'name'
63
+ ],
64
+ properties: {
65
+ name: {
66
+ type: 'string',
67
+ description: 'An event name, as written in data-event.'
68
+ },
69
+ confirm: {
70
+ oneOf: [
71
+ {
72
+ type: 'boolean',
73
+ description: 'Ask before the event fires, whatever the HTML says, with the element\'s data-confirm message or "Are you sure?".'
74
+ },
75
+ {
76
+ type: 'string',
77
+ minLength: 1,
78
+ description: 'Ask before the event fires, whatever the HTML says, with this message.'
79
+ }
80
+ ]
81
+ }
82
+ }
83
+ }
84
+ ]
85
+ }
86
+ },
87
+ html: {
88
+ type: 'string',
89
+ description: 'Content to be rendered as Html. An element with a data-event attribute fires the event it names when clicked (data-event="onEditClick" fires events.onEditClick), if dataEvents lists it, and its default browser action is prevented. The event object holds the element\'s other data-* attributes with snake_case keys, so data-event="onEditClick" data-record-id="42" gives { record_id: "42" }. Targets that are not links or buttons become keyboard focusable, and Enter or Space clicks them. A data-event inside popover content fires too, then closes the popover. A link with data-event fires the event and does not navigate. data-confirm="Delete this row?" on a data-event element asks first: only OK fires the event (bare data-confirm asks "Are you sure?"). Escape user and request data in the HTML, so it cannot add data-event elements of its own. All Html block attributes work too: data-icon, data-tooltip, data-popover, data-page-id links, data-new-tab, data-tag, data-status, data-time, data-format, data-avatar, data-copy, data-truncate and data-tone. See the HTML attributes docs page.',
90
+ docs: {
91
+ displayType: 'text-area'
92
+ }
93
+ }
94
+ }
95
+ }
96
+ };
@@ -0,0 +1,188 @@
1
+ # Copyright 2020-2026 Lowdefy, Inc
2
+
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ id: clickablehtml
15
+ type: Box
16
+
17
+ blocks:
18
+ - id: clickable_basic
19
+ type: ClickableHtml
20
+ properties:
21
+ dataEvents:
22
+ - onGreetClick
23
+ - onWaveClick
24
+ html: '<p>Hello <button data-event="onGreetClick" data-user-id="u_1">World</button> <button data-event="onWaveClick" data-user-id="u_2">Wave</button></p>'
25
+ events:
26
+ onGreetClick:
27
+ - id: set_greeted
28
+ type: SetState
29
+ params:
30
+ clicked:
31
+ event: greet
32
+ user_id:
33
+ _event: user_id
34
+ onWaveClick:
35
+ - id: set_waved
36
+ type: SetState
37
+ params:
38
+ clicked:
39
+ event: wave
40
+ user_id:
41
+ _event: user_id
42
+
43
+ - id: clickable_result
44
+ type: Html
45
+ properties:
46
+ html:
47
+ _string.concat:
48
+ - '<span id="clicked_event">'
49
+ - _state:
50
+ key: clicked.event
51
+ default: ''
52
+ - '</span><span id="clicked_user_id">'
53
+ - _state:
54
+ key: clicked.user_id
55
+ default: ''
56
+ - '</span>'
57
+
58
+ - id: clickable_no_event
59
+ type: ClickableHtml
60
+ properties:
61
+ html: '<p><button>Plain button</button></p>'
62
+ events:
63
+ onPlainClick:
64
+ - id: set_plain
65
+ type: SetState
66
+ params:
67
+ plain_clicked: true
68
+
69
+ - id: clickable_sanitized
70
+ type: ClickableHtml
71
+ properties:
72
+ html: <p>Safe content</p><script>alert('xss')</script>
73
+
74
+ - id: clickable_confirm
75
+ type: ClickableHtml
76
+ properties:
77
+ dataEvents:
78
+ - onDelete
79
+ html: '<button id="confirm_delete" data-event="onDelete" data-row-id="7" data-confirm="Delete row 7?">Delete</button> <button id="proto_event" data-event="__proto__">Proto</button>'
80
+ events:
81
+ onDelete:
82
+ - id: count_delete
83
+ type: SetState
84
+ params:
85
+ delete_count:
86
+ _sum:
87
+ - _state:
88
+ key: delete_count
89
+ default: 0
90
+ - 1
91
+
92
+ - id: clickable_confirm_result
93
+ type: Html
94
+ properties:
95
+ html:
96
+ _string.concat:
97
+ - '<span id="delete_count">'
98
+ - _json.stringify:
99
+ - _state:
100
+ key: delete_count
101
+ default: 0
102
+ - '</span>'
103
+
104
+ - id: clickable_allowlist
105
+ type: ClickableHtml
106
+ properties:
107
+ dataEvents:
108
+ - onListedClick
109
+ html: '<span id="listed_target" data-event="onListedClick">Listed</span> <span id="unlisted_target" data-event="onUnlistedClick">Unlisted</span>'
110
+ events:
111
+ onListedClick:
112
+ - id: set_listed
113
+ type: SetState
114
+ params:
115
+ allowlist_fired: listed
116
+ onUnlistedClick:
117
+ - id: set_unlisted
118
+ type: SetState
119
+ params:
120
+ allowlist_fired: unlisted
121
+
122
+ - id: clickable_declared_confirm
123
+ type: ClickableHtml
124
+ properties:
125
+ dataEvents:
126
+ - name: onRemove
127
+ confirm: Remove row 3?
128
+ html: '<button id="declared_remove" data-event="onRemove" data-row-id="3">Remove</button>'
129
+ events:
130
+ onRemove:
131
+ - id: set_removed
132
+ type: SetState
133
+ params:
134
+ removed_row:
135
+ _event: row_id
136
+
137
+ - id: clickable_refresh
138
+ type: ClickableHtml
139
+ properties:
140
+ dataEvents:
141
+ - onRefreshSoon
142
+ - onRefreshDelete
143
+ html:
144
+ _string.concat:
145
+ - '<button id="refresh_soon" data-event="onRefreshSoon">Refresh soon</button><p id="refresh_count">Refreshed '
146
+ - _state:
147
+ key: refresh_count
148
+ default: 0
149
+ - '</p><button id="refresh_delete" data-event="onRefreshDelete" data-id="5" data-confirm="Delete 5?">Delete</button> <span id="refresh_more" data-popover="more">More</span><div data-popover-content="more" hidden><span class="refresh-menu">Menu after '
150
+ - _state:
151
+ key: refresh_count
152
+ default: 0
153
+ - '</span></div>'
154
+ events:
155
+ onRefreshSoon:
156
+ - id: wait
157
+ type: Wait
158
+ params:
159
+ ms: 1000
160
+ - id: refresh
161
+ type: SetState
162
+ params:
163
+ refresh_count: 1
164
+ onRefreshDelete:
165
+ - id: set_refresh_deleted
166
+ type: SetState
167
+ params:
168
+ refresh_deleted:
169
+ _event: id
170
+
171
+ - id: clickable_events_result
172
+ type: Html
173
+ properties:
174
+ html:
175
+ _string.concat:
176
+ - '<span id="allowlist_fired">'
177
+ - _state:
178
+ key: allowlist_fired
179
+ default: ''
180
+ - '</span><span id="removed_row">'
181
+ - _state:
182
+ key: removed_row
183
+ default: ''
184
+ - '</span><span id="refresh_deleted">'
185
+ - _state:
186
+ key: refresh_deleted
187
+ default: ''
188
+ - '</span>'
@@ -0,0 +1,48 @@
1
+ # Copyright 2020-2026 Lowdefy, Inc
2
+
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ - id: default
15
+ type: ClickableHtml
16
+ - id: properties.html
17
+ type: ClickableHtml
18
+ properties:
19
+ dataEvents:
20
+ - onGoClick
21
+ html: |
22
+ <p>Plain markup <button data-event="onGoClick" data-item-id="1">Go</button></p>
23
+ - id: properties.html-no-events
24
+ type: ClickableHtml
25
+ properties:
26
+ html: |
27
+ <p>No data-event here, clicks do nothing.</p>
28
+ - id: properties.html-bad-code
29
+ type: ClickableHtml
30
+ properties:
31
+ dataEvents:
32
+ - onOkClick
33
+ html: |
34
+ <button data-event="onOkClick" onclick="alert('inline handler stripped')">Ok</button>
35
+ <script>alert('script tag');</script>
36
+ - id: properties.html is number 0
37
+ type: ClickableHtml
38
+ properties:
39
+ html: 0
40
+ - id: properties.dataEvents
41
+ type: ClickableHtml
42
+ properties:
43
+ dataEvents:
44
+ - onEditClick
45
+ - name: onDeleteClick
46
+ confirm: Delete this row?
47
+ html: |
48
+ <p><button data-event="onEditClick">Edit</button> <button data-event="onDeleteClick">Delete</button></p>
@@ -13,39 +13,39 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import React from 'react';
16
- import DOMPurify from 'dompurify';
17
- import { withBlockDefaults } from '@lowdefy/block-utils';
18
- import { type } from '@lowdefy/helpers';
16
+ import { HtmlComponent, withBlockDefaults } from '@lowdefy/block-utils';
19
17
  let DangerousHtml = class DangerousHtml extends React.Component {
18
+ warnOnOptionsChange() {
19
+ const { DOMPurifyOptions } = this.props.properties;
20
+ if (!this.warnedOptionsChange && JSON.stringify(DOMPurifyOptions) !== JSON.stringify(this.DOMPurifyOptions)) {
21
+ this.warnedOptionsChange = true;
22
+ console.warn(`DangerousHtml block "${this.props.blockId}": DOMPurifyOptions changed after mount and the change is ignored. The sanitizer options are fixed at the first render; write them as a literal, not from state.`);
23
+ }
24
+ }
20
25
  componentDidMount() {
21
- const htmlString = type.isNone(this.props.properties.html) ? '' : this.props.properties.html.toString();
22
- this.div.innerHTML = DOMPurify.sanitize(htmlString, this.DOMPurifyOptions);
26
+ this.warnOnOptionsChange();
23
27
  }
24
28
  componentDidUpdate() {
25
- const htmlString = type.isNone(this.props.properties.html) ? '' : this.props.properties.html.toString();
26
- this.div.innerHTML = DOMPurify.sanitize(htmlString, this.DOMPurifyOptions);
29
+ this.warnOnOptionsChange();
27
30
  }
28
31
  render() {
29
- const { blockId, classNames, styles } = this.props;
30
- return /*#__PURE__*/ React.createElement("div", {
32
+ const { blockId, classNames, properties, styles } = this.props;
33
+ return /*#__PURE__*/ React.createElement(HtmlComponent, {
34
+ div: true,
35
+ html: properties.html,
31
36
  id: blockId,
32
- "data-testid": blockId,
33
- ref: (el)=>{
34
- if (el) {
35
- this.div = el;
36
- }
37
- },
38
37
  className: classNames?.element,
38
+ sanitizeOptions: this.DOMPurifyOptions,
39
39
  style: styles?.element
40
40
  });
41
41
  }
42
42
  constructor(props){
43
43
  super(props);
44
- this.div = {
45
- innerHTML: ''
46
- };
47
- // we do not revaluate DOMPurifyOptions improve options safety by not making options dynamic.
44
+ // The sanitizer options are fixed at mount on purpose: a later, operator-driven
45
+ // value could loosen the sanitizer from state. A change is refused loudly
46
+ // rather than ignored silently.
48
47
  this.DOMPurifyOptions = props.properties.DOMPurifyOptions;
48
+ this.warnedOptionsChange = false;
49
49
  }
50
50
  };
51
51
  export default withBlockDefaults(DangerousHtml);
@@ -19,13 +19,25 @@
19
19
  cssKeys: {
20
20
  element: 'The DangerousHtml element.'
21
21
  },
22
+ hazards: [
23
+ {
24
+ id: 'dangerous-html-unsanitised',
25
+ message: 'Content is rendered without sanitising, so never pass caller-supplied or database HTML through it. Use Html for anything a user could have written.',
26
+ see: 'display-blocks/dangeroushtml'
27
+ },
28
+ {
29
+ id: 'dompurify-options-first-render',
30
+ message: 'DOMPurifyOptions is read once when the block mounts, so a value that changes after the first render has no effect. Set it statically or remount the block.',
31
+ see: 'display-blocks/dangeroushtml'
32
+ }
33
+ ],
22
34
  properties: {
23
35
  type: 'object',
24
36
  additionalProperties: false,
25
37
  properties: {
26
38
  html: {
27
39
  type: 'string',
28
- description: 'Content to be rendered as Html.',
40
+ description: 'Content to be rendered as Html. The Html block attributes (data-icon, data-tooltip, data-popover, data-page-id links, data-new-tab, data-tag, data-status, data-time, data-format, data-avatar, data-copy, data-truncate, data-tone) work here too, unless DOMPurifyOptions removes data attributes.',
29
41
  docs: {
30
42
  displayType: 'text-area'
31
43
  }
@@ -13,7 +13,7 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import React from 'react';
16
- import { withBlockDefaults } from '@lowdefy/block-utils';
16
+ import { isEventFromDomDescendant, withBlockDefaults } from '@lowdefy/block-utils';
17
17
  // Server-resolved container. The server fills the content slot at page get by
18
18
  // calling the configured api endpoint — by the time config reaches the client,
19
19
  // content holds the resolved blocks (or the fallback blocks on failure).
@@ -21,9 +21,11 @@ const Dynamic = ({ blockId, classNames, content, events, methods, styles })=>{
21
21
  return /*#__PURE__*/ React.createElement("div", {
22
22
  id: blockId,
23
23
  "data-testid": blockId,
24
- onClick: ()=>methods.triggerEvent({
24
+ onClick: (event)=>{
25
+ if (isEventFromDomDescendant(event)) methods.triggerEvent({
25
26
  name: 'onClick'
26
- }),
27
+ });
28
+ },
27
29
  className: classNames?.element,
28
30
  style: {
29
31
  outline: 'none',
@@ -38,6 +38,10 @@
38
38
  type: 'object',
39
39
  description: 'Static values passed to the endpoint payload as params. Operators are not allowed — read runtime values in the endpoint routine with _payload, _user or _secret.'
40
40
  },
41
+ policy: {
42
+ type: 'string',
43
+ description: 'Id of a policies.dynamicBlocks entry in lowdefy.yaml. The resolved content must pass the policy on every page get. The endpoint returns stored content as config by reading the blocks of a ValidateDynamic step with the same policy. Replaces types: the policy lists are bundled.'
44
+ },
41
45
  required: {
42
46
  type: 'boolean',
43
47
  default: false,