@gem-sdk/core 1.45.0-dev.104 → 1.45.0-dev.105
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.
|
@@ -20,6 +20,7 @@ require('dayjs');
|
|
|
20
20
|
var composeAdvanceStyle = require('../helpers/compose-advance-style.js');
|
|
21
21
|
var convert = require('../helpers/convert.js');
|
|
22
22
|
var render = require('../helpers/render.js');
|
|
23
|
+
var cssjson = require('cssjson');
|
|
23
24
|
|
|
24
25
|
const componentsRenderWithParentId = [
|
|
25
26
|
'CarouselItem'
|
|
@@ -192,19 +193,28 @@ const Render = ({ uid, builder, components, parentId, extraFiles = {}, pageConte
|
|
|
192
193
|
};
|
|
193
194
|
}
|
|
194
195
|
};
|
|
196
|
+
const isEmptyCSS = (cssString)=>{
|
|
197
|
+
if (!cssString) return true;
|
|
198
|
+
const cssJSON = cssjson.toJSON(cssString);
|
|
199
|
+
const isObjectEmpty = (obj)=>{
|
|
200
|
+
if (typeof obj !== 'object' || obj === null) return true;
|
|
201
|
+
return !Object.keys(obj).some((key)=>{
|
|
202
|
+
return key === 'attributes' && Object.keys(obj[key]).length > 0 || typeof obj[key] === 'object' && !isObjectEmpty(obj[key]);
|
|
203
|
+
});
|
|
204
|
+
};
|
|
205
|
+
return isObjectEmpty(cssJSON.children);
|
|
206
|
+
};
|
|
195
207
|
const RenderCustomCode = (item)=>{
|
|
196
208
|
const { css, javascript, rootClassName } = item.advanced?.editorData || {};
|
|
197
209
|
const replacedCSS = css?.replaceAll(rootClassName, item.uid);
|
|
198
210
|
const replacedJS = javascript?.replaceAll(rootClassName, item.uid);
|
|
199
|
-
const cssCode = render.RenderIf(!!css, render.template`
|
|
200
|
-
<style
|
|
201
|
-
|
|
202
|
-
|
|
211
|
+
const cssCode = render.RenderIf(!!css && !isEmptyCSS(replacedCSS), render.template`
|
|
212
|
+
<style id="${`custom-css-${item?.uid}`}">
|
|
213
|
+
${replacedCSS}
|
|
214
|
+
</style>
|
|
203
215
|
`);
|
|
204
216
|
const jsCode = render.RenderIf(!!javascript, render.template`
|
|
205
|
-
<script
|
|
206
|
-
id="${`custom-js-${item?.uid}`}"
|
|
207
|
-
>
|
|
217
|
+
<script id="${`custom-js-${item?.uid}`}">
|
|
208
218
|
try {
|
|
209
219
|
${replacedJS}
|
|
210
220
|
} catch(err){}
|
|
@@ -16,6 +16,7 @@ import 'dayjs';
|
|
|
16
16
|
import { composeAdvanceStyle } from '../helpers/compose-advance-style.js';
|
|
17
17
|
import { baseAssetURL, isLocalEnv } from '../helpers/convert.js';
|
|
18
18
|
import { RenderIf, template } from '../helpers/render.js';
|
|
19
|
+
import { toJSON } from 'cssjson';
|
|
19
20
|
|
|
20
21
|
const componentsRenderWithParentId = [
|
|
21
22
|
'CarouselItem'
|
|
@@ -188,19 +189,28 @@ const Render = ({ uid, builder, components, parentId, extraFiles = {}, pageConte
|
|
|
188
189
|
};
|
|
189
190
|
}
|
|
190
191
|
};
|
|
192
|
+
const isEmptyCSS = (cssString)=>{
|
|
193
|
+
if (!cssString) return true;
|
|
194
|
+
const cssJSON = toJSON(cssString);
|
|
195
|
+
const isObjectEmpty = (obj)=>{
|
|
196
|
+
if (typeof obj !== 'object' || obj === null) return true;
|
|
197
|
+
return !Object.keys(obj).some((key)=>{
|
|
198
|
+
return key === 'attributes' && Object.keys(obj[key]).length > 0 || typeof obj[key] === 'object' && !isObjectEmpty(obj[key]);
|
|
199
|
+
});
|
|
200
|
+
};
|
|
201
|
+
return isObjectEmpty(cssJSON.children);
|
|
202
|
+
};
|
|
191
203
|
const RenderCustomCode = (item)=>{
|
|
192
204
|
const { css, javascript, rootClassName } = item.advanced?.editorData || {};
|
|
193
205
|
const replacedCSS = css?.replaceAll(rootClassName, item.uid);
|
|
194
206
|
const replacedJS = javascript?.replaceAll(rootClassName, item.uid);
|
|
195
|
-
const cssCode = RenderIf(!!css, template`
|
|
196
|
-
<style
|
|
197
|
-
|
|
198
|
-
|
|
207
|
+
const cssCode = RenderIf(!!css && !isEmptyCSS(replacedCSS), template`
|
|
208
|
+
<style id="${`custom-css-${item?.uid}`}">
|
|
209
|
+
${replacedCSS}
|
|
210
|
+
</style>
|
|
199
211
|
`);
|
|
200
212
|
const jsCode = RenderIf(!!javascript, template`
|
|
201
|
-
<script
|
|
202
|
-
id="${`custom-js-${item?.uid}`}"
|
|
203
|
-
>
|
|
213
|
+
<script id="${`custom-js-${item?.uid}`}">
|
|
204
214
|
try {
|
|
205
215
|
${replacedJS}
|
|
206
216
|
} catch(err){}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gem-sdk/core",
|
|
3
|
-
"version": "1.45.0-dev.
|
|
3
|
+
"version": "1.45.0-dev.105",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "dist/cjs/index.js",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"classnames": "^2.5.1",
|
|
36
|
+
"cssjson": "2.1.3",
|
|
36
37
|
"dayjs": "^1.11.11",
|
|
37
38
|
"react-error-boundary": "4.0.10",
|
|
38
39
|
"swr": "2.1.2",
|