@lowdefy/block-utils 4.7.2 → 5.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.
@@ -38,7 +38,7 @@ let HtmlComponent = class HtmlComponent extends React.Component {
38
38
  }
39
39
  }
40
40
  render() {
41
- const { div, id, methods, style } = this.props;
41
+ const { className, div, id, style } = this.props;
42
42
  if (div === true) {
43
43
  return /*#__PURE__*/ React.createElement("div", {
44
44
  id: id,
@@ -48,7 +48,8 @@ let HtmlComponent = class HtmlComponent extends React.Component {
48
48
  this.div = el;
49
49
  }
50
50
  },
51
- className: methods.makeCssClass(style),
51
+ className: className,
52
+ style: style,
52
53
  onMouseUp: this.onTextSelection
53
54
  });
54
55
  }
@@ -60,7 +61,8 @@ let HtmlComponent = class HtmlComponent extends React.Component {
60
61
  this.div = el;
61
62
  }
62
63
  },
63
- className: methods.makeCssClass(style),
64
+ className: className,
65
+ style: style,
64
66
  onMouseUp: this.onTextSelection
65
67
  });
66
68
  }
@@ -12,17 +12,17 @@
12
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
- */ import makeCssClass from './makeCssClass.js';
16
- const blockDefaultProps = {
15
+ */ const blockDefaultProps = {
17
16
  basePath: '',
18
17
  blockId: 'undefined_id',
19
- components: {},
18
+ components: {
19
+ ShortcutBadge: ()=>null
20
+ },
20
21
  content: {},
21
22
  events: {},
22
23
  list: [],
23
24
  menus: [],
24
25
  methods: {
25
- makeCssClass,
26
26
  registerEvent: ()=>undefined,
27
27
  registerMethod: ()=>undefined,
28
28
  triggerEvent: ()=>undefined
@@ -38,6 +38,41 @@
38
38
  style: {
39
39
  type: 'object'
40
40
  },
41
+ class: {
42
+ oneOf: [
43
+ {
44
+ type: 'string'
45
+ },
46
+ {
47
+ type: 'array',
48
+ items: {
49
+ type: 'string'
50
+ }
51
+ },
52
+ {
53
+ type: 'object',
54
+ additionalProperties: {
55
+ oneOf: [
56
+ {
57
+ type: 'string'
58
+ },
59
+ {
60
+ type: 'array',
61
+ items: {
62
+ type: 'string'
63
+ }
64
+ }
65
+ ]
66
+ }
67
+ }
68
+ ]
69
+ },
70
+ styles: {
71
+ type: 'object',
72
+ additionalProperties: {
73
+ type: 'object'
74
+ }
75
+ },
41
76
  layout: {
42
77
  type: 'object'
43
78
  },
@@ -0,0 +1,178 @@
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
+ */ const operatorSchema = {
16
+ type: 'object',
17
+ patternProperties: {
18
+ '^_': {}
19
+ },
20
+ additionalProperties: false,
21
+ minProperties: 1,
22
+ maxProperties: 1
23
+ };
24
+ const classValueSchema = {
25
+ oneOf: [
26
+ {
27
+ type: 'string'
28
+ },
29
+ {
30
+ type: 'array',
31
+ items: {
32
+ type: 'string'
33
+ }
34
+ },
35
+ operatorSchema
36
+ ]
37
+ };
38
+ const styleValueSchema = {
39
+ type: 'object'
40
+ };
41
+ const eventValueSchema = {
42
+ oneOf: [
43
+ {
44
+ type: 'array'
45
+ },
46
+ operatorSchema
47
+ ]
48
+ };
49
+ function buildBlockSchema(meta) {
50
+ const cssEntries = Object.entries({
51
+ block: 'The block layout wrapper.',
52
+ ...meta.cssKeys ?? {}
53
+ });
54
+ const classProperties = Object.fromEntries(cssEntries.map(([key, desc])=>[
55
+ `.${key}`,
56
+ {
57
+ ...classValueSchema,
58
+ description: desc
59
+ }
60
+ ]));
61
+ const styleProperties = Object.fromEntries(cssEntries.map(([key, desc])=>[
62
+ `.${key}`,
63
+ {
64
+ ...styleValueSchema,
65
+ description: desc
66
+ }
67
+ ]));
68
+ const eventProperties = Object.fromEntries(Object.entries(meta.events ?? {}).map(([name, desc])=>[
69
+ name,
70
+ {
71
+ ...eventValueSchema,
72
+ description: desc
73
+ }
74
+ ]));
75
+ const schema = {
76
+ type: 'object',
77
+ additionalProperties: false,
78
+ required: [
79
+ 'id',
80
+ 'type'
81
+ ],
82
+ properties: {
83
+ id: {
84
+ type: 'string'
85
+ },
86
+ type: {
87
+ type: 'string'
88
+ },
89
+ layout: {
90
+ oneOf: [
91
+ {
92
+ type: 'object'
93
+ },
94
+ operatorSchema
95
+ ]
96
+ },
97
+ visible: {
98
+ oneOf: [
99
+ {
100
+ type: 'boolean'
101
+ },
102
+ operatorSchema
103
+ ]
104
+ },
105
+ required: {
106
+ oneOf: [
107
+ {
108
+ type: 'boolean'
109
+ },
110
+ operatorSchema
111
+ ]
112
+ },
113
+ properties: meta.properties ?? {
114
+ type: 'object'
115
+ },
116
+ class: {
117
+ oneOf: [
118
+ {
119
+ type: 'string'
120
+ },
121
+ {
122
+ type: 'array',
123
+ items: {
124
+ type: 'string'
125
+ }
126
+ },
127
+ operatorSchema,
128
+ {
129
+ type: 'object',
130
+ additionalProperties: false,
131
+ properties: classProperties
132
+ }
133
+ ]
134
+ },
135
+ style: {
136
+ oneOf: [
137
+ operatorSchema,
138
+ {
139
+ type: 'object',
140
+ additionalProperties: false,
141
+ properties: styleProperties
142
+ },
143
+ {
144
+ type: 'object',
145
+ patternProperties: {
146
+ '^(?!_)(?!\\.)': {}
147
+ },
148
+ additionalProperties: false,
149
+ minProperties: 1
150
+ }
151
+ ]
152
+ },
153
+ events: {
154
+ oneOf: [
155
+ operatorSchema,
156
+ {
157
+ type: 'object',
158
+ additionalProperties: false,
159
+ properties: eventProperties
160
+ }
161
+ ]
162
+ }
163
+ }
164
+ };
165
+ if (meta.category === 'container') {
166
+ schema.properties.blocks = {
167
+ type: 'array',
168
+ items: {
169
+ type: 'object'
170
+ }
171
+ };
172
+ schema.properties.areas = {
173
+ type: 'object'
174
+ };
175
+ }
176
+ return schema;
177
+ }
178
+ export default buildBlockSchema;
@@ -12,8 +12,9 @@
12
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
- */ import { css } from '@emotion/css';
16
- import { mergeObjects } from '@lowdefy/helpers';
17
- import mediaToCssObject from './mediaToCssObject.js';
18
- const makeCssClass = (styles, styleObjectOnly)=>styleObjectOnly ? mediaToCssObject(mergeObjects(styles), true)[0] : css(mediaToCssObject(styles));
19
- export default makeCssClass;
15
+ */ import { clsx } from 'clsx';
16
+ import { twMerge } from 'tailwind-merge';
17
+ function cn(...inputs) {
18
+ return twMerge(clsx(inputs));
19
+ }
20
+ export default cn;
@@ -0,0 +1,37 @@
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
+ */ function extractBlockTypes(metas) {
16
+ const entries = Object.entries(metas);
17
+ const blocks = entries.map(([name])=>name);
18
+ const icons = {};
19
+ const blockMetas = {};
20
+ for (const [name, meta] of entries){
21
+ icons[name] = meta.icons ?? [];
22
+ const entry = {
23
+ category: meta.category
24
+ };
25
+ if (meta.valueType != null) entry.valueType = meta.valueType;
26
+ if (meta.initValue !== undefined) entry.initValue = meta.initValue;
27
+ if (meta.slots !== undefined) entry.slots = meta.slots;
28
+ if (meta.cssKeys) entry.cssKeys = Object.keys(meta.cssKeys);
29
+ blockMetas[name] = entry;
30
+ }
31
+ return {
32
+ blocks,
33
+ icons,
34
+ blockMetas
35
+ };
36
+ }
37
+ export default extractBlockTypes;
package/dist/index.js CHANGED
@@ -14,10 +14,12 @@
14
14
  limitations under the License.
15
15
  */ import blockDefaultProps from './blockDefaultProps.js';
16
16
  import blockSchema from './blockSchema.js';
17
+ import buildBlockSchema from './buildBlockSchema.js';
18
+ import cn from './cn.js';
17
19
  import ErrorBoundary from './ErrorBoundary.js';
18
20
  import ErrorPage from './ErrorPage.js';
21
+ import extractBlockTypes from './extractBlockTypes.js';
19
22
  import HtmlComponent from './HtmlComponent.js';
20
- import makeCssClass from './makeCssClass.js';
21
- import mediaToCssObject from './mediaToCssObject.js';
22
23
  import renderHtml from './renderHtml.js';
23
- export { blockDefaultProps, blockSchema, ErrorBoundary, ErrorPage, HtmlComponent, makeCssClass, mediaToCssObject, renderHtml };
24
+ import withBlockDefaults from './withBlockDefaults.js';
25
+ export { blockDefaultProps, blockSchema, buildBlockSchema, cn, ErrorBoundary, ErrorPage, extractBlockTypes, HtmlComponent, renderHtml, withBlockDefaults };
@@ -15,7 +15,8 @@
15
15
  */ import React from 'react';
16
16
  import { type } from '@lowdefy/helpers';
17
17
  import HtmlComponent from './HtmlComponent.js';
18
- const renderHtml = ({ div, events, html, id, methods, style })=>type.isNone(html) ? undefined : /*#__PURE__*/ React.createElement(HtmlComponent, {
18
+ const renderHtml = ({ className, div, events, html, id, methods, style })=>type.isNone(html) ? undefined : /*#__PURE__*/ React.createElement(HtmlComponent, {
19
+ className: className,
19
20
  div: div,
20
21
  events: events,
21
22
  html: html,
@@ -0,0 +1,31 @@
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 blockDefaultProps from './blockDefaultProps.js';
17
+ // Note: Unlike React's defaultProps, this does not replace explicitly-passed
18
+ // undefined values. { ...defaults, ...props } keeps undefined if props has the key.
19
+ // This matches production behavior where the framework always passes defined values.
20
+ function withBlockDefaults(Component) {
21
+ const Wrapped = (props)=>{
22
+ return /*#__PURE__*/ React.createElement(Component, {
23
+ ...blockDefaultProps,
24
+ ...props
25
+ });
26
+ };
27
+ Wrapped.meta = Component.meta;
28
+ Wrapped.displayName = Component.displayName || Component.name;
29
+ return Wrapped;
30
+ }
31
+ export default withBlockDefaults;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/block-utils",
3
- "version": "4.7.2",
3
+ "version": "5.0.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Lowdefy Block Utils",
6
6
  "homepage": "https://lowdefy.com",
@@ -34,19 +34,21 @@
34
34
  "dist/*"
35
35
  ],
36
36
  "dependencies": {
37
- "@emotion/css": "11.11.2",
38
- "@lowdefy/errors": "4.7.2",
39
- "@lowdefy/helpers": "4.7.2",
37
+ "@lowdefy/errors": "5.0.0",
38
+ "@lowdefy/helpers": "5.0.0",
39
+ "clsx": "2.1.1",
40
40
  "dompurify": "3.2.4",
41
- "react": "18.2.0",
42
- "react-dom": "18.2.0"
41
+ "tailwind-merge": "2.6.0"
42
+ },
43
+ "peerDependencies": {
44
+ "react": ">=18",
45
+ "react-dom": ">=18"
43
46
  },
44
47
  "devDependencies": {
45
48
  "@babel/core": "7.23.3",
46
- "@emotion/jest": "11.10.5",
47
- "@swc/cli": "0.1.63",
48
- "@swc/core": "1.3.99",
49
- "@swc/jest": "0.2.29",
49
+ "@swc/cli": "0.8.0",
50
+ "@swc/core": "1.15.18",
51
+ "@swc/jest": "0.2.39",
50
52
  "@testing-library/dom": "8.19.1",
51
53
  "@testing-library/react": "13.4.0",
52
54
  "@testing-library/user-event": "14.4.3",
@@ -59,7 +61,7 @@
59
61
  "access": "public"
60
62
  },
61
63
  "scripts": {
62
- "build": "swc src --out-dir dist --config-file ../../../.swcrc --delete-dir-on-start && pnpm copyfiles",
64
+ "build": "swc src --out-dir dist --config-file ../../../.swcrc --cli-config-file ../../../.swc-cli.json && pnpm copyfiles",
63
65
  "clean": "rm -rf dist",
64
66
  "copyfiles": "copyfiles -u 1 \"./src/**/*\" dist -e \"./src/**/*.js\" -e \"./src/**/*.yaml\" -e \"./src/**/*.snap\"",
65
67
  "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js"
@@ -1,87 +0,0 @@
1
- /* eslint-disable no-undef */ /*
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 { type } from '@lowdefy/helpers';
16
- const breakpoints = {
17
- xs: 576,
18
- sm: 768,
19
- md: 992,
20
- lg: 1200,
21
- xl: 1600
22
- };
23
- const mediaReact = {
24
- xs: `@media screen and (maxWidth: ${breakpoints.xs}px)`,
25
- sm: `@media screen and (minWidth: ${breakpoints.xs}px)`,
26
- md: `@media screen and (minWidth: ${breakpoints.sm}px)`,
27
- lg: `@media screen and (minWidth: ${breakpoints.md}px)`,
28
- xl: `@media screen and (minWidth: ${breakpoints.lg}px)`,
29
- xxl: `@media screen and (minWidth: ${breakpoints.xl}px)`
30
- };
31
- const media = {
32
- xs: `@media screen and (max-width: ${breakpoints.xs}px)`,
33
- sm: `@media screen and (min-width: ${breakpoints.xs}px)`,
34
- md: `@media screen and (min-width: ${breakpoints.sm}px)`,
35
- lg: `@media screen and (min-width: ${breakpoints.md}px)`,
36
- xl: `@media screen and (min-width: ${breakpoints.lg}px)`,
37
- xxl: `@media screen and (min-width: ${breakpoints.xl}px)`
38
- };
39
- const mediaRegex = /@media\s+(xs|sm|md|lg|xl|xxl)\s*{/gm;
40
- const setReplacer = (_, group)=>media[group] + ' {';
41
- const mediaToCssObject = (styles, styleObjectOnly)=>{
42
- if (type.isString(styles)) {
43
- return styles.replace(mediaRegex, setReplacer);
44
- }
45
- let styleObjects = styles;
46
- if (type.isObject(styles)) {
47
- styleObjects = [
48
- styles
49
- ];
50
- }
51
- if (!type.isArray(styleObjects)) {
52
- return [];
53
- }
54
- return styleObjects.map((style)=>{
55
- if (type.isString(style)) {
56
- return style.replace(mediaRegex, setReplacer);
57
- }
58
- if (!type.isObject(style)) {
59
- return {};
60
- }
61
- let mq = media;
62
- if (styleObjectOnly) {
63
- mq = mediaReact;
64
- }
65
- const { xs, sm, md, lg, xl, xxl, ...others } = style;
66
- if (xs) {
67
- others[mq.xs] = xs;
68
- }
69
- if (sm) {
70
- others[mq.sm] = sm;
71
- }
72
- if (md) {
73
- others[mq.md] = md;
74
- }
75
- if (lg) {
76
- others[mq.lg] = lg;
77
- }
78
- if (xl) {
79
- others[mq.xl] = xl;
80
- }
81
- if (xxl) {
82
- others[mq.xxl] = xxl;
83
- }
84
- return others;
85
- });
86
- };
87
- export default mediaToCssObject;