@lowdefy/block-utils 4.0.0-rc.9 → 4.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.
@@ -0,0 +1,52 @@
1
+ /*
2
+ Copyright 2020-2024 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, { Component } from 'react';
16
+ import ErrorPage from './ErrorPage.js';
17
+ let ErrorBoundary = class ErrorBoundary extends Component {
18
+ static getDerivedStateFromError(error) {
19
+ return {
20
+ hasError: true,
21
+ error
22
+ };
23
+ }
24
+ render() {
25
+ const { children, description, fallback, fullPage, message, name } = this.props;
26
+ const { hasError, error } = this.state;
27
+ if (hasError) {
28
+ if (fallback) {
29
+ return fallback(error);
30
+ }
31
+ if (fullPage) {
32
+ return /*#__PURE__*/ React.createElement(ErrorPage, {
33
+ code: error.number,
34
+ description: description || error.description,
35
+ message: message || error.message,
36
+ name: name || error.name
37
+ });
38
+ }
39
+ // Throw to console but fail silently to user?
40
+ return '';
41
+ }
42
+ return children;
43
+ }
44
+ constructor(props){
45
+ super(props);
46
+ this.state = {
47
+ hasError: false,
48
+ error: null
49
+ };
50
+ }
51
+ };
52
+ export default ErrorBoundary;
@@ -0,0 +1,60 @@
1
+ /*
2
+ Copyright 2020-2024 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
+ const ErrorPage = ({ code, description, message, name })=>/*#__PURE__*/ React.createElement("div", {
17
+ style: {
18
+ height: '100%',
19
+ fontFamily: 'system-ui',
20
+ margin: 0,
21
+ display: 'flex',
22
+ justifyContent: 'center',
23
+ alignItems: 'center'
24
+ }
25
+ }, /*#__PURE__*/ React.createElement("div", {
26
+ style: {
27
+ flex: '0 1 auto',
28
+ fontSize: '4.3em',
29
+ fontWeight: '100',
30
+ paddingRight: 30
31
+ }
32
+ }, code ?? 500), /*#__PURE__*/ React.createElement("div", {
33
+ style: {
34
+ flex: '0 1 auto',
35
+ paddingLeft: 30,
36
+ maxWidth: 400,
37
+ borderLeft: '1px solid #aeaeae'
38
+ }
39
+ }, /*#__PURE__*/ React.createElement("div", {
40
+ style: {
41
+ fontSize: '1.3em',
42
+ fontWeight: '300',
43
+ paddingBottom: 10
44
+ }
45
+ }, name ?? 'Error'), /*#__PURE__*/ React.createElement("div", {
46
+ style: {
47
+ fontSize: '0.9em'
48
+ }
49
+ }, message ?? 'An error has occurred.'), /*#__PURE__*/ React.createElement("div", {
50
+ style: {
51
+ fontSize: '0.9em'
52
+ }
53
+ }, description), /*#__PURE__*/ React.createElement("div", {
54
+ style: {
55
+ paddingTop: 20
56
+ }
57
+ }, /*#__PURE__*/ React.createElement("a", {
58
+ href: "/"
59
+ }, "Return to home page"))));
60
+ export default ErrorPage;
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2023 Lowdefy, Inc
2
+ Copyright 2020-2024 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -24,8 +24,21 @@ let HtmlComponent = class HtmlComponent extends React.Component {
24
24
  const htmlString = type.isNone(this.props.html) ? '' : this.props.html.toString();
25
25
  this.div.innerHTML = DOMPurify.sanitize(htmlString);
26
26
  }
27
+ onTextSelection() {
28
+ if (this.props.events?.onTextSelection) {
29
+ const selection = window.getSelection().toString();
30
+ if (selection !== '') {
31
+ this.props.methods.triggerEvent({
32
+ name: 'onTextSelection',
33
+ event: {
34
+ selection
35
+ }
36
+ });
37
+ }
38
+ }
39
+ }
27
40
  render() {
28
- const { div , id , methods , style } = this.props;
41
+ const { div, id, methods, style } = this.props;
29
42
  if (div === true) {
30
43
  return /*#__PURE__*/ React.createElement("div", {
31
44
  id: id,
@@ -35,7 +48,8 @@ let HtmlComponent = class HtmlComponent extends React.Component {
35
48
  this.div = el;
36
49
  }
37
50
  },
38
- className: methods.makeCssClass(style)
51
+ className: methods.makeCssClass(style),
52
+ onMouseUp: this.onTextSelection
39
53
  });
40
54
  }
41
55
  return /*#__PURE__*/ React.createElement("span", {
@@ -46,7 +60,8 @@ let HtmlComponent = class HtmlComponent extends React.Component {
46
60
  this.div = el;
47
61
  }
48
62
  },
49
- className: methods.makeCssClass(style)
63
+ className: methods.makeCssClass(style),
64
+ onMouseUp: this.onTextSelection
50
65
  });
51
66
  }
52
67
  constructor(props){
@@ -54,6 +69,7 @@ let HtmlComponent = class HtmlComponent extends React.Component {
54
69
  this.div = {
55
70
  innerHTML: ''
56
71
  };
72
+ this.onTextSelection = this.onTextSelection.bind(this);
57
73
  }
58
74
  };
59
75
  export default HtmlComponent;
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2023 Lowdefy, Inc
2
+ Copyright 2020-2024 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -22,7 +22,7 @@ const blockDefaultProps = {
22
22
  list: [],
23
23
  menus: [],
24
24
  methods: {
25
- makeCssClass: makeCssClass,
25
+ makeCssClass,
26
26
  registerEvent: ()=>undefined,
27
27
  registerMethod: ()=>undefined,
28
28
  triggerEvent: ()=>undefined
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2023 Lowdefy, Inc
2
+ Copyright 2020-2024 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2023 Lowdefy, Inc
2
+ Copyright 2020-2024 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -15,7 +15,8 @@
15
15
  */ import blockDefaultProps from './blockDefaultProps.js';
16
16
  import blockSchema from './blockSchema.js';
17
17
  import HtmlComponent from './HtmlComponent.js';
18
+ import ErrorBoundary from './ErrorBoundary.js';
18
19
  import makeCssClass from './makeCssClass.js';
19
20
  import mediaToCssObject from './mediaToCssObject.js';
20
21
  import renderHtml from './renderHtml.js';
21
- export { blockDefaultProps, blockSchema, HtmlComponent, makeCssClass, mediaToCssObject, renderHtml };
22
+ export { blockDefaultProps, blockSchema, ErrorBoundary, HtmlComponent, makeCssClass, mediaToCssObject, renderHtml };
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2023 Lowdefy, Inc
2
+ Copyright 2020-2024 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable no-undef */ /*
2
- Copyright 2020-2023 Lowdefy, Inc
2
+ Copyright 2020-2024 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -62,7 +62,7 @@ const mediaToCssObject = (styles, styleObjectOnly)=>{
62
62
  if (styleObjectOnly) {
63
63
  mq = mediaReact;
64
64
  }
65
- const { xs , sm , md , lg , xl , xxl , ...others } = style;
65
+ const { xs, sm, md, lg, xl, xxl, ...others } = style;
66
66
  if (xs) {
67
67
  others[mq.xs] = xs;
68
68
  }
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2023 Lowdefy, Inc
2
+ Copyright 2020-2024 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -15,8 +15,9 @@
15
15
  */ import React from 'react';
16
16
  import { type } from '@lowdefy/helpers';
17
17
  import HtmlComponent from './HtmlComponent.js';
18
- const renderHtml = ({ div , html , id , methods , style })=>type.isNone(html) ? undefined : /*#__PURE__*/ React.createElement(HtmlComponent, {
18
+ const renderHtml = ({ div, events, html, id, methods, style })=>type.isNone(html) ? undefined : /*#__PURE__*/ React.createElement(HtmlComponent, {
19
19
  div: div,
20
+ events: events,
20
21
  html: html,
21
22
  id: id,
22
23
  methods: methods,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/block-utils",
3
- "version": "4.0.0-rc.9",
3
+ "version": "4.0.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Lowdefy Block Utils",
6
6
  "homepage": "https://lowdefy.com",
@@ -33,36 +33,34 @@
33
33
  "files": [
34
34
  "dist/*"
35
35
  ],
36
- "scripts": {
37
- "build": "swc src --out-dir dist --config-file ../../../.swcrc --delete-dir-on-start && pnpm copyfiles",
38
- "clean": "rm -rf dist",
39
- "copyfiles": "copyfiles -u 1 \"./src/**/*\" dist -e \"./src/**/*.js\" -e \"./src/**/*.yaml\" -e \"./src/**/*.snap\"",
40
- "prepublishOnly": "pnpm build",
41
- "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js"
42
- },
43
36
  "dependencies": {
44
- "@emotion/css": "11.10.5",
45
- "@lowdefy/helpers": "4.0.0-rc.9",
46
- "dompurify": "2.4.1",
37
+ "@emotion/css": "11.11.2",
38
+ "@lowdefy/helpers": "4.0.0",
39
+ "dompurify": "3.0.6",
47
40
  "react": "18.2.0",
48
41
  "react-dom": "18.2.0"
49
42
  },
50
43
  "devDependencies": {
51
- "@babel/core": "7.20.7",
44
+ "@babel/core": "7.23.3",
52
45
  "@emotion/jest": "11.10.5",
53
- "@swc/cli": "0.1.59",
54
- "@swc/core": "1.3.24",
55
- "@swc/jest": "0.2.24",
46
+ "@swc/cli": "0.1.63",
47
+ "@swc/core": "1.3.99",
48
+ "@swc/jest": "0.2.29",
56
49
  "@testing-library/dom": "8.19.1",
57
50
  "@testing-library/react": "13.4.0",
58
51
  "@testing-library/user-event": "14.4.3",
59
52
  "copyfiles": "2.4.1",
60
- "jest": "28.1.0",
61
- "jest-environment-jsdom": "28.1.0",
53
+ "jest": "28.1.3",
54
+ "jest-environment-jsdom": "28.1.3",
62
55
  "jest-serializer-html": "7.1.0"
63
56
  },
64
57
  "publishConfig": {
65
58
  "access": "public"
66
59
  },
67
- "gitHead": "d20e6ac424643feca527a732dc2b0710713c8243"
68
- }
60
+ "scripts": {
61
+ "build": "swc src --out-dir dist --config-file ../../../.swcrc --delete-dir-on-start && pnpm copyfiles",
62
+ "clean": "rm -rf dist",
63
+ "copyfiles": "copyfiles -u 1 \"./src/**/*\" dist -e \"./src/**/*.js\" -e \"./src/**/*.yaml\" -e \"./src/**/*.snap\"",
64
+ "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js"
65
+ }
66
+ }