@lowdefy/blocks-basic 6.0.0 → 6.1.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.
@@ -0,0 +1,53 @@
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
+ */ import React from 'react';
16
+ import { withBlockDefaults, HtmlComponent } from '@lowdefy/block-utils';
17
+ // dataset keys are camelCase (data-record-id → recordId); config authors
18
+ // write the attributes in kebab-case, so hand them back as snake_case.
19
+ function toSnakeCase(key) {
20
+ return key.replace(/[A-Z]/g, (match)=>`_${match.toLowerCase()}`);
21
+ }
22
+ const ClickableHtml = ({ blockId, classNames, events, properties, methods, styles })=>{
23
+ // Each clickable element names the event it fires in its data-event
24
+ // attribute (data-event="onEditClick" → events.onEditClick), so every
25
+ // target in the markup has its own action chain. Its other data-*
26
+ // attributes are the event object.
27
+ function onClick(clickEvent) {
28
+ const target = clickEvent.target.closest('[data-event]');
29
+ if (!target || !clickEvent.currentTarget.contains(target)) return;
30
+ const { event: name, ...data } = target.dataset;
31
+ if (!name) return;
32
+ clickEvent.preventDefault();
33
+ const event = {};
34
+ Object.keys(data).forEach((key)=>{
35
+ event[toSnakeCase(key)] = data[key];
36
+ });
37
+ methods.triggerEvent({
38
+ name,
39
+ event
40
+ });
41
+ }
42
+ return /*#__PURE__*/ React.createElement(HtmlComponent, {
43
+ div: true,
44
+ events: events,
45
+ html: properties.html,
46
+ id: blockId,
47
+ methods: methods,
48
+ className: classNames?.element,
49
+ style: styles?.element,
50
+ onClick: onClick
51
+ });
52
+ };
53
+ export default withBlockDefaults(ClickableHtml);
@@ -0,0 +1,23 @@
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
+ */ import { createBlockHelper, escapeId } from '@lowdefy/e2e-utils';
16
+ import { expect } from '@playwright/test';
17
+ const locator = (page, blockId)=>page.locator(`#${escapeId(blockId)}`);
18
+ export default createBlockHelper({
19
+ locator,
20
+ expect: {
21
+ containsText: (page, blockId, text)=>expect(locator(page, blockId)).toContainText(text)
22
+ }
23
+ });
@@ -0,0 +1,113 @@
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
+ html: '<p>Pick a size: <button data-event="onSmallClick">Small</button> <button data-event="onLargeClick">Large</button></p>'
20
+ events:
21
+ onSmallClick:
22
+ - id: set_small
23
+ type: SetState
24
+ params:
25
+ buttons_basic_selected: small
26
+ onLargeClick:
27
+ - id: set_large
28
+ type: SetState
29
+ params:
30
+ buttons_basic_selected: large
31
+ - id: buttons_basic_result
32
+ type: Html
33
+ properties:
34
+ html:
35
+ _string.concat:
36
+ - '<p>State: <code>'
37
+ - _state:
38
+ key: buttons_basic_selected
39
+ default: 'nothing yet'
40
+ - '</code></p>'
41
+
42
+ - title: Data attributes are the event object
43
+ blocks:
44
+ - id: list_rows
45
+ type: ClickableHtml
46
+ properties:
47
+ 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>'
48
+ events:
49
+ onRowClick:
50
+ - id: set_clicked
51
+ type: SetState
52
+ params:
53
+ list_rows_clicked:
54
+ _event: true
55
+ - id: list_rows_result
56
+ type: Html
57
+ properties:
58
+ html:
59
+ _string.concat:
60
+ - '<p>Last event: <code>'
61
+ - _json.stringify:
62
+ _state:
63
+ key: list_rows_clicked
64
+ default: {}
65
+ - '</code></p>'
66
+
67
+ - title: Links and plain markup are left to the browser
68
+ blocks:
69
+ - id: mixed_content
70
+ type: ClickableHtml
71
+ properties:
72
+ 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>'
73
+ events:
74
+ onCommentClick:
75
+ - id: set_mixed
76
+ type: SetState
77
+ params:
78
+ mixed_content_thread:
79
+ _event: thread_id
80
+ - id: mixed_content_result
81
+ type: Html
82
+ properties:
83
+ html:
84
+ _string.concat:
85
+ - '<p>Thread: <code>'
86
+ - _state:
87
+ key: mixed_content_thread
88
+ default: 'none'
89
+ - '</code></p>'
90
+
91
+ - title: Style Overrides
92
+ blocks:
93
+ - id: style_card
94
+ type: ClickableHtml
95
+ style:
96
+ .element:
97
+ padding: 16
98
+ borderRadius: 8
99
+ border: 1px solid var(--ant-color-border)
100
+ background: var(--ant-color-bg-container)
101
+ properties:
102
+ 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>'
103
+ events:
104
+ onEditClick:
105
+ - id: set_card_edit
106
+ type: SetState
107
+ params:
108
+ style_card_action: edit
109
+ onRemoveClick:
110
+ - id: set_card_remove
111
+ type: SetState
112
+ params:
113
+ style_card_action: remove
@@ -0,0 +1,40 @@
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
+ // Each clickable element names its event in a data-event attribute, so the
23
+ // event names this block fires are authored in its html.
24
+ events: {
25
+ onTextSelection: 'Trigger action when text is selected and pass selected text to the event object.'
26
+ },
27
+ properties: {
28
+ type: 'object',
29
+ additionalProperties: false,
30
+ properties: {
31
+ html: {
32
+ type: 'string',
33
+ 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), 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" }.',
34
+ docs: {
35
+ displayType: 'text-area'
36
+ }
37
+ }
38
+ }
39
+ }
40
+ };
@@ -0,0 +1,69 @@
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
+ 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>'
22
+ events:
23
+ onGreetClick:
24
+ - id: set_greeted
25
+ type: SetState
26
+ params:
27
+ clicked:
28
+ event: greet
29
+ user_id:
30
+ _event: user_id
31
+ onWaveClick:
32
+ - id: set_waved
33
+ type: SetState
34
+ params:
35
+ clicked:
36
+ event: wave
37
+ user_id:
38
+ _event: user_id
39
+
40
+ - id: clickable_result
41
+ type: Html
42
+ properties:
43
+ html:
44
+ _string.concat:
45
+ - '<span id="clicked_event">'
46
+ - _state:
47
+ key: clicked.event
48
+ default: ''
49
+ - '</span><span id="clicked_user_id">'
50
+ - _state:
51
+ key: clicked.user_id
52
+ default: ''
53
+ - '</span>'
54
+
55
+ - id: clickable_no_event
56
+ type: ClickableHtml
57
+ properties:
58
+ html: '<p><button>Plain button</button></p>'
59
+ events:
60
+ onPlainClick:
61
+ - id: set_plain
62
+ type: SetState
63
+ params:
64
+ plain_clicked: true
65
+
66
+ - id: clickable_sanitized
67
+ type: ClickableHtml
68
+ properties:
69
+ html: <p>Safe content</p><script>alert('xss')</script>
@@ -0,0 +1,35 @@
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
+ html: |
20
+ <p>Plain markup <button data-event="onGoClick" data-item-id="1">Go</button></p>
21
+ - id: properties.html-no-events
22
+ type: ClickableHtml
23
+ properties:
24
+ html: |
25
+ <p>No data-event here, clicks do nothing.</p>
26
+ - id: properties.html-bad-code
27
+ type: ClickableHtml
28
+ properties:
29
+ html: |
30
+ <button data-event="onOkClick" onclick="alert('inline handler stripped')">Ok</button>
31
+ <script>alert('script tag');</script>
32
+ - id: properties.html is number 0
33
+ type: ClickableHtml
34
+ properties:
35
+ html: 0
package/dist/blocks.js CHANGED
@@ -14,6 +14,7 @@
14
14
  limitations under the License.
15
15
  */ export { default as Anchor } from './blocks/Anchor/Anchor.js';
16
16
  export { default as Box } from './blocks/Box/Box.js';
17
+ export { default as ClickableHtml } from './blocks/ClickableHtml/ClickableHtml.js';
17
18
  export { default as DangerousHtml } from './blocks/DangerousHtml/DangerousHtml.js';
18
19
  export { default as Dynamic } from './blocks/Dynamic/Dynamic.js';
19
20
  export { default as Html } from './blocks/Html/Html.js';
package/dist/e2e.js CHANGED
@@ -14,6 +14,7 @@
14
14
  limitations under the License.
15
15
  */ export { default as Anchor } from './blocks/Anchor/e2e.js';
16
16
  export { default as Box } from './blocks/Box/e2e.js';
17
+ export { default as ClickableHtml } from './blocks/ClickableHtml/e2e.js';
17
18
  export { default as DangerousHtml } from './blocks/DangerousHtml/e2e.js';
18
19
  export { default as Dynamic } from './blocks/Dynamic/e2e.js';
19
20
  export { default as Html } from './blocks/Html/e2e.js';
package/dist/metas.js CHANGED
@@ -14,6 +14,7 @@
14
14
  limitations under the License.
15
15
  */ export { default as Anchor } from './blocks/Anchor/meta.js';
16
16
  export { default as Box } from './blocks/Box/meta.js';
17
+ export { default as ClickableHtml } from './blocks/ClickableHtml/meta.js';
17
18
  export { default as DangerousHtml } from './blocks/DangerousHtml/meta.js';
18
19
  export { default as Dynamic } from './blocks/Dynamic/meta.js';
19
20
  export { default as Html } from './blocks/Html/meta.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/blocks-basic",
3
- "version": "6.0.0",
3
+ "version": "6.1.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Basic html Lowdefy blocks.",
6
6
  "homepage": "https://lowdefy.com",
@@ -42,17 +42,17 @@
42
42
  "dist/*"
43
43
  ],
44
44
  "dependencies": {
45
- "@lowdefy/block-utils": "6.0.0",
46
- "@lowdefy/helpers": "6.0.0",
47
- "dompurify": "3.4.2"
45
+ "@lowdefy/block-utils": "6.1.0",
46
+ "@lowdefy/helpers": "6.1.0",
47
+ "dompurify": "3.4.13"
48
48
  },
49
49
  "peerDependencies": {
50
50
  "react": ">=18",
51
51
  "react-dom": ">=18"
52
52
  },
53
53
  "devDependencies": {
54
- "@lowdefy/block-dev-e2e": "6.0.0",
55
- "@lowdefy/e2e-utils": "6.0.0",
54
+ "@lowdefy/block-dev-e2e": "6.1.0",
55
+ "@lowdefy/e2e-utils": "6.1.0",
56
56
  "@playwright/test": "1.59.1",
57
57
  "@swc/cli": "0.8.1",
58
58
  "@swc/core": "1.15.32",