@gem-sdk/system 1.58.0-dev.109 → 1.58.0-dev.135
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.
- package/dist/cjs/component/createAttr.js +34 -0
- package/dist/cjs/component/createClass.js +38 -0
- package/dist/cjs/component/createContent.js +19 -0
- package/dist/cjs/component/createStateOrContext.js +55 -0
- package/dist/cjs/component/createStyle.js +42 -0
- package/dist/cjs/component/utils/toCamelCaseKeys.js +15 -0
- package/dist/cjs/index.js +19 -0
- package/dist/esm/component/createAttr.js +32 -0
- package/dist/esm/component/createClass.js +36 -0
- package/dist/esm/component/createContent.js +17 -0
- package/dist/esm/component/createStateOrContext.js +53 -0
- package/dist/esm/component/createStyle.js +39 -0
- package/dist/esm/component/utils/toCamelCaseKeys.js +13 -0
- package/dist/esm/index.js +5 -0
- package/dist/types/index.d.ts +30 -0
- package/package.json +10 -6
- package/src/component/Research.txt +53 -0
- package/src/component/__tests__/createAttr.test.ts +62 -0
- package/src/component/__tests__/createClass.test.ts +68 -0
- package/src/component/__tests__/createContent.test.ts +52 -0
- package/src/component/__tests__/createStateOrContext.test.ts +129 -0
- package/src/component/__tests__/createStyle.test.ts +63 -0
- package/src/component/createAttr.ts +44 -0
- package/src/component/createClass.ts +48 -0
- package/src/component/createContent.ts +20 -0
- package/src/component/createStateOrContext.ts +70 -0
- package/src/component/createStyle.ts +53 -0
- package/src/component/types.ts +9 -0
- package/src/component/utils/__tests__/toCamelCaseKeys.test.ts +79 -0
- package/src/component/utils/toCamelCaseKeys.ts +20 -0
- package/src/e2e-tests/README.md +1 -0
- package/src/examples/components/text/DemoText.liquid.ts +40 -0
- package/src/examples/components/text/DemoText.tsx +41 -0
- package/src/examples/components/text/common/__tests__/globalTypoClasses.test.ts +11 -0
- package/src/examples/components/text/common/getAttr.ts +7 -0
- package/src/examples/components/text/common/getStyle.ts +5 -0
- package/src/examples/components/text/common/globalTypoClasses.ts +5 -0
- package/src/examples/components/text/e2e-tests/DemoText.spec.tsx +23 -0
- package/src/examples/components/text/e2e-tests/DemoText.tsx +23 -0
- package/src/validator/README.md +1 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const createAttr = (obj)=>{
|
|
4
|
+
if (typeof obj !== 'object' || obj === null) {
|
|
5
|
+
console.error('Expected an object as input.');
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
const isDevOrStaging = !process.env.APP_ENV || process.env.APP_ENV === 'development' || process.env.APP_ENV === 'staging';
|
|
9
|
+
if (isDevOrStaging) {
|
|
10
|
+
for(const key in obj){
|
|
11
|
+
const value = obj[key];
|
|
12
|
+
// 1. Check if the key starts with "data-gp-"
|
|
13
|
+
if (!key.startsWith('data-gp-')) {
|
|
14
|
+
console.error(`Invalid attribute key: "${key}". Must start with "data-gp-".`);
|
|
15
|
+
}
|
|
16
|
+
// 2. Check if the key contains uppercase letters
|
|
17
|
+
if (key !== key.toLowerCase()) {
|
|
18
|
+
console.error(`Invalid attribute key: "${key}". Must not contain uppercase letters.`);
|
|
19
|
+
}
|
|
20
|
+
// 3. Check if the value is an object (nested object check)
|
|
21
|
+
if (typeof value === 'object' && value !== null) {
|
|
22
|
+
console.error(`Invalid nested attribute for key "${key}". Nested objects are not supported.`);
|
|
23
|
+
}
|
|
24
|
+
// 4. Check if the value is a valid type (string or number)
|
|
25
|
+
const isValidType = typeof value === 'string' || typeof value === 'number';
|
|
26
|
+
if (!isValidType) {
|
|
27
|
+
console.error(`Invalid attribute value for key "${key}": ${value}. Must be a string or number.`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return obj;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
exports.createAttr = createAttr;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function toVal(mix) {
|
|
4
|
+
if (typeof mix === 'string') {
|
|
5
|
+
return mix;
|
|
6
|
+
} else if (typeof mix === 'object' && mix !== null) {
|
|
7
|
+
return Object.keys(mix).filter((key)=>mix[key]).join(' ');
|
|
8
|
+
} else {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function cls(...classes) {
|
|
13
|
+
return classes.map(toVal).filter(Boolean).join(' ');
|
|
14
|
+
}
|
|
15
|
+
const createClass = (obj)=>{
|
|
16
|
+
if (typeof obj !== 'object' || obj === null) {
|
|
17
|
+
console.error('Expected an object as input.');
|
|
18
|
+
return '';
|
|
19
|
+
}
|
|
20
|
+
const isDevOrStaging = !process.env.APP_ENV || process.env.APP_ENV === 'development' || process.env.APP_ENV === 'staging';
|
|
21
|
+
if (isDevOrStaging) {
|
|
22
|
+
// Validate each class name length
|
|
23
|
+
for(const className in obj){
|
|
24
|
+
if (className.length > 30) {
|
|
25
|
+
console.error(`Class name "${className}" exceeds the maximum length of 30 characters.`);
|
|
26
|
+
}
|
|
27
|
+
if (className.includes(' ')) {
|
|
28
|
+
console.error(`Class name "${className}" should not contain spaces.`);
|
|
29
|
+
}
|
|
30
|
+
if (className !== className.toLowerCase()) {
|
|
31
|
+
console.error(`Class name "${className}" should be in lowercase.`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return cls(obj);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
exports.createClass = createClass;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const createContent = (content)=>{
|
|
4
|
+
// Check if content is a string
|
|
5
|
+
if (typeof content !== 'string') {
|
|
6
|
+
console.error('Invalid content type: Content must be a string.');
|
|
7
|
+
return '';
|
|
8
|
+
}
|
|
9
|
+
// Regex to match {{}} pattern with only letters inside, e.g., {{Hello}}
|
|
10
|
+
const invalidPattern = /\{\{[A-Za-z]+\}\}/g;
|
|
11
|
+
// Check if content contains any invalid patterns
|
|
12
|
+
if (invalidPattern.test(content)) {
|
|
13
|
+
console.error('Invalid content format: "{{}}" placeholders must not contain only letters, e.g., "{{Hello}}".');
|
|
14
|
+
return '';
|
|
15
|
+
}
|
|
16
|
+
return content;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
exports.createContent = createContent;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const createStateOrContext = (obj)=>{
|
|
4
|
+
const isDevOrStaging = !process.env.APP_ENV || process.env.APP_ENV === 'development' || process.env.APP_ENV === 'staging';
|
|
5
|
+
const isValid = (value)=>{
|
|
6
|
+
// Ensure value is neither undefined, null, empty string, nor false (except 0)
|
|
7
|
+
return value !== undefined && value !== null && value !== '' && value !== false;
|
|
8
|
+
};
|
|
9
|
+
const validateKey = (key)=>{
|
|
10
|
+
// Check key length
|
|
11
|
+
if (key.length > 20) {
|
|
12
|
+
console.error(`Invalid key "${key}": Key length must not exceed 20 characters.`);
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
// Ensure no special characters or numbers
|
|
16
|
+
const validKeyRegex = /^[a-zA-Z]+$/;
|
|
17
|
+
if (!validKeyRegex.test(key)) {
|
|
18
|
+
console.error(`Invalid key "${key}": Key must contain only alphabetic characters (no numbers or special characters).`);
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
// Check camelCase format (should start with lowercase)
|
|
22
|
+
const camelCaseRegex = /^[a-z][a-zA-Z]*$/;
|
|
23
|
+
if (!camelCaseRegex.test(key)) {
|
|
24
|
+
console.error(`Invalid key "${key}": Key must be in camelCase format.`);
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
return true;
|
|
28
|
+
};
|
|
29
|
+
const validateObject = (data, depth)=>{
|
|
30
|
+
if (depth > 3) {
|
|
31
|
+
console.error('Invalid structure: Data must not be nested deeper than 3 levels.');
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
for(const key in data){
|
|
35
|
+
const value = data[key];
|
|
36
|
+
// Key validation
|
|
37
|
+
if (!validateKey(key)) continue;
|
|
38
|
+
// Value validation
|
|
39
|
+
if (!isValid(value)) {
|
|
40
|
+
console.error(`Invalid value for key "${key}": Value must not be undefined, null, blank, or false.`);
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
// Recursive check if the value is an object
|
|
44
|
+
if (typeof value === 'object' && !Array.isArray(value)) {
|
|
45
|
+
validateObject(value, depth + 1);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
if (isDevOrStaging) {
|
|
50
|
+
validateObject(obj, 1);
|
|
51
|
+
}
|
|
52
|
+
return obj;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
exports.createStateOrContext = createStateOrContext;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var toCamelCaseKeys = require('./utils/toCamelCaseKeys.js');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Properties to ignore with explanations for each
|
|
7
|
+
*/ const ignoredProperties = {
|
|
8
|
+
ignore: 'This property is not supported in the current styling setup.'
|
|
9
|
+
};
|
|
10
|
+
const createStyle = (obj)=>{
|
|
11
|
+
const isDevOrStaging = !process.env.APP_ENV || process.env.APP_ENV === 'development' || process.env.APP_ENV === 'staging';
|
|
12
|
+
if (isDevOrStaging) {
|
|
13
|
+
for(const key in obj){
|
|
14
|
+
const value = obj[key];
|
|
15
|
+
// Check if the property is in the ignored list and log the explanation
|
|
16
|
+
if (Object.prototype.hasOwnProperty.call(ignoredProperties, key)) {
|
|
17
|
+
console.error(`Ignored property detected: "${key}". ${ignoredProperties[key]}`);
|
|
18
|
+
}
|
|
19
|
+
// Check for uppercase letters, numbers, and special characters (only allow lowercase letters and "-"
|
|
20
|
+
const isValidKey = /^[a-z-]+$/.test(key);
|
|
21
|
+
if (!isValidKey) {
|
|
22
|
+
console.error(`Invalid key "${key}": Keys must be lowercase letters and may only contain "-".`);
|
|
23
|
+
}
|
|
24
|
+
// Check for nested objects (only support single-level properties)
|
|
25
|
+
if (typeof value === 'object' && value !== null) {
|
|
26
|
+
console.error(`Invalid nested object for property "${key}". Nested objects are not supported.`);
|
|
27
|
+
}
|
|
28
|
+
// Check if the value is a valid type
|
|
29
|
+
const isValidType = typeof value === 'string' || typeof value === 'number';
|
|
30
|
+
if (!isValidType) {
|
|
31
|
+
console.error(`Invalid style value for "${key}": ${value}. Must be a string or number.`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return obj;
|
|
36
|
+
};
|
|
37
|
+
const createStyleReact = (obj)=>{
|
|
38
|
+
return toCamelCaseKeys.toCamelCaseKeys(createStyle(obj));
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
exports.createStyle = createStyle;
|
|
42
|
+
exports.createStyleReact = createStyleReact;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const toCamelCaseKeys = (obj)=>{
|
|
4
|
+
const newObj = {};
|
|
5
|
+
for(const key in obj){
|
|
6
|
+
const value = obj[key];
|
|
7
|
+
// If the key starts with "--", keep it as is
|
|
8
|
+
const newKey = key.startsWith('--') ? key : key.replace(/-([a-z])/g, (_, char)=>char.toUpperCase());
|
|
9
|
+
// Recursively apply to nested objects
|
|
10
|
+
newObj[newKey] = typeof value === 'object' && value !== null && !Array.isArray(value) ? toCamelCaseKeys(value) : value;
|
|
11
|
+
}
|
|
12
|
+
return newObj;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
exports.toCamelCaseKeys = toCamelCaseKeys;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var createAttr = require('./component/createAttr.js');
|
|
4
|
+
var createStyle = require('./component/createStyle.js');
|
|
5
|
+
var createContent = require('./component/createContent.js');
|
|
6
|
+
var createClass = require('./component/createClass.js');
|
|
7
|
+
var createStateOrContext = require('./component/createStateOrContext.js');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
exports.createAttr = createAttr.createAttr;
|
|
12
|
+
exports.createAttrReact = createAttr.createAttr;
|
|
13
|
+
exports.createStyle = createStyle.createStyle;
|
|
14
|
+
exports.createStyleReact = createStyle.createStyleReact;
|
|
15
|
+
exports.createContent = createContent.createContent;
|
|
16
|
+
exports.createContentReact = createContent.createContent;
|
|
17
|
+
exports.createClass = createClass.createClass;
|
|
18
|
+
exports.createClassReact = createClass.createClass;
|
|
19
|
+
exports.createStateOrContext = createStateOrContext.createStateOrContext;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const createAttr = (obj)=>{
|
|
2
|
+
if (typeof obj !== 'object' || obj === null) {
|
|
3
|
+
console.error('Expected an object as input.');
|
|
4
|
+
return;
|
|
5
|
+
}
|
|
6
|
+
const isDevOrStaging = !process.env.APP_ENV || process.env.APP_ENV === 'development' || process.env.APP_ENV === 'staging';
|
|
7
|
+
if (isDevOrStaging) {
|
|
8
|
+
for(const key in obj){
|
|
9
|
+
const value = obj[key];
|
|
10
|
+
// 1. Check if the key starts with "data-gp-"
|
|
11
|
+
if (!key.startsWith('data-gp-')) {
|
|
12
|
+
console.error(`Invalid attribute key: "${key}". Must start with "data-gp-".`);
|
|
13
|
+
}
|
|
14
|
+
// 2. Check if the key contains uppercase letters
|
|
15
|
+
if (key !== key.toLowerCase()) {
|
|
16
|
+
console.error(`Invalid attribute key: "${key}". Must not contain uppercase letters.`);
|
|
17
|
+
}
|
|
18
|
+
// 3. Check if the value is an object (nested object check)
|
|
19
|
+
if (typeof value === 'object' && value !== null) {
|
|
20
|
+
console.error(`Invalid nested attribute for key "${key}". Nested objects are not supported.`);
|
|
21
|
+
}
|
|
22
|
+
// 4. Check if the value is a valid type (string or number)
|
|
23
|
+
const isValidType = typeof value === 'string' || typeof value === 'number';
|
|
24
|
+
if (!isValidType) {
|
|
25
|
+
console.error(`Invalid attribute value for key "${key}": ${value}. Must be a string or number.`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return obj;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export { createAttr };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
function toVal(mix) {
|
|
2
|
+
if (typeof mix === 'string') {
|
|
3
|
+
return mix;
|
|
4
|
+
} else if (typeof mix === 'object' && mix !== null) {
|
|
5
|
+
return Object.keys(mix).filter((key)=>mix[key]).join(' ');
|
|
6
|
+
} else {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
function cls(...classes) {
|
|
11
|
+
return classes.map(toVal).filter(Boolean).join(' ');
|
|
12
|
+
}
|
|
13
|
+
const createClass = (obj)=>{
|
|
14
|
+
if (typeof obj !== 'object' || obj === null) {
|
|
15
|
+
console.error('Expected an object as input.');
|
|
16
|
+
return '';
|
|
17
|
+
}
|
|
18
|
+
const isDevOrStaging = !process.env.APP_ENV || process.env.APP_ENV === 'development' || process.env.APP_ENV === 'staging';
|
|
19
|
+
if (isDevOrStaging) {
|
|
20
|
+
// Validate each class name length
|
|
21
|
+
for(const className in obj){
|
|
22
|
+
if (className.length > 30) {
|
|
23
|
+
console.error(`Class name "${className}" exceeds the maximum length of 30 characters.`);
|
|
24
|
+
}
|
|
25
|
+
if (className.includes(' ')) {
|
|
26
|
+
console.error(`Class name "${className}" should not contain spaces.`);
|
|
27
|
+
}
|
|
28
|
+
if (className !== className.toLowerCase()) {
|
|
29
|
+
console.error(`Class name "${className}" should be in lowercase.`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return cls(obj);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export { createClass };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const createContent = (content)=>{
|
|
2
|
+
// Check if content is a string
|
|
3
|
+
if (typeof content !== 'string') {
|
|
4
|
+
console.error('Invalid content type: Content must be a string.');
|
|
5
|
+
return '';
|
|
6
|
+
}
|
|
7
|
+
// Regex to match {{}} pattern with only letters inside, e.g., {{Hello}}
|
|
8
|
+
const invalidPattern = /\{\{[A-Za-z]+\}\}/g;
|
|
9
|
+
// Check if content contains any invalid patterns
|
|
10
|
+
if (invalidPattern.test(content)) {
|
|
11
|
+
console.error('Invalid content format: "{{}}" placeholders must not contain only letters, e.g., "{{Hello}}".');
|
|
12
|
+
return '';
|
|
13
|
+
}
|
|
14
|
+
return content;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export { createContent };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
const createStateOrContext = (obj)=>{
|
|
2
|
+
const isDevOrStaging = !process.env.APP_ENV || process.env.APP_ENV === 'development' || process.env.APP_ENV === 'staging';
|
|
3
|
+
const isValid = (value)=>{
|
|
4
|
+
// Ensure value is neither undefined, null, empty string, nor false (except 0)
|
|
5
|
+
return value !== undefined && value !== null && value !== '' && value !== false;
|
|
6
|
+
};
|
|
7
|
+
const validateKey = (key)=>{
|
|
8
|
+
// Check key length
|
|
9
|
+
if (key.length > 20) {
|
|
10
|
+
console.error(`Invalid key "${key}": Key length must not exceed 20 characters.`);
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
// Ensure no special characters or numbers
|
|
14
|
+
const validKeyRegex = /^[a-zA-Z]+$/;
|
|
15
|
+
if (!validKeyRegex.test(key)) {
|
|
16
|
+
console.error(`Invalid key "${key}": Key must contain only alphabetic characters (no numbers or special characters).`);
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
// Check camelCase format (should start with lowercase)
|
|
20
|
+
const camelCaseRegex = /^[a-z][a-zA-Z]*$/;
|
|
21
|
+
if (!camelCaseRegex.test(key)) {
|
|
22
|
+
console.error(`Invalid key "${key}": Key must be in camelCase format.`);
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
return true;
|
|
26
|
+
};
|
|
27
|
+
const validateObject = (data, depth)=>{
|
|
28
|
+
if (depth > 3) {
|
|
29
|
+
console.error('Invalid structure: Data must not be nested deeper than 3 levels.');
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
for(const key in data){
|
|
33
|
+
const value = data[key];
|
|
34
|
+
// Key validation
|
|
35
|
+
if (!validateKey(key)) continue;
|
|
36
|
+
// Value validation
|
|
37
|
+
if (!isValid(value)) {
|
|
38
|
+
console.error(`Invalid value for key "${key}": Value must not be undefined, null, blank, or false.`);
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
// Recursive check if the value is an object
|
|
42
|
+
if (typeof value === 'object' && !Array.isArray(value)) {
|
|
43
|
+
validateObject(value, depth + 1);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
if (isDevOrStaging) {
|
|
48
|
+
validateObject(obj, 1);
|
|
49
|
+
}
|
|
50
|
+
return obj;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export { createStateOrContext };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { toCamelCaseKeys } from './utils/toCamelCaseKeys.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Properties to ignore with explanations for each
|
|
5
|
+
*/ const ignoredProperties = {
|
|
6
|
+
ignore: 'This property is not supported in the current styling setup.'
|
|
7
|
+
};
|
|
8
|
+
const createStyle = (obj)=>{
|
|
9
|
+
const isDevOrStaging = !process.env.APP_ENV || process.env.APP_ENV === 'development' || process.env.APP_ENV === 'staging';
|
|
10
|
+
if (isDevOrStaging) {
|
|
11
|
+
for(const key in obj){
|
|
12
|
+
const value = obj[key];
|
|
13
|
+
// Check if the property is in the ignored list and log the explanation
|
|
14
|
+
if (Object.prototype.hasOwnProperty.call(ignoredProperties, key)) {
|
|
15
|
+
console.error(`Ignored property detected: "${key}". ${ignoredProperties[key]}`);
|
|
16
|
+
}
|
|
17
|
+
// Check for uppercase letters, numbers, and special characters (only allow lowercase letters and "-"
|
|
18
|
+
const isValidKey = /^[a-z-]+$/.test(key);
|
|
19
|
+
if (!isValidKey) {
|
|
20
|
+
console.error(`Invalid key "${key}": Keys must be lowercase letters and may only contain "-".`);
|
|
21
|
+
}
|
|
22
|
+
// Check for nested objects (only support single-level properties)
|
|
23
|
+
if (typeof value === 'object' && value !== null) {
|
|
24
|
+
console.error(`Invalid nested object for property "${key}". Nested objects are not supported.`);
|
|
25
|
+
}
|
|
26
|
+
// Check if the value is a valid type
|
|
27
|
+
const isValidType = typeof value === 'string' || typeof value === 'number';
|
|
28
|
+
if (!isValidType) {
|
|
29
|
+
console.error(`Invalid style value for "${key}": ${value}. Must be a string or number.`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return obj;
|
|
34
|
+
};
|
|
35
|
+
const createStyleReact = (obj)=>{
|
|
36
|
+
return toCamelCaseKeys(createStyle(obj));
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export { createStyle, createStyleReact };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const toCamelCaseKeys = (obj)=>{
|
|
2
|
+
const newObj = {};
|
|
3
|
+
for(const key in obj){
|
|
4
|
+
const value = obj[key];
|
|
5
|
+
// If the key starts with "--", keep it as is
|
|
6
|
+
const newKey = key.startsWith('--') ? key : key.replace(/-([a-z])/g, (_, char)=>char.toUpperCase());
|
|
7
|
+
// Recursively apply to nested objects
|
|
8
|
+
newObj[newKey] = typeof value === 'object' && value !== null && !Array.isArray(value) ? toCamelCaseKeys(value) : value;
|
|
9
|
+
}
|
|
10
|
+
return newObj;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export { toCamelCaseKeys };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { createAttr, createAttr as createAttrReact } from './component/createAttr.js';
|
|
2
|
+
export { createStyle, createStyleReact } from './component/createStyle.js';
|
|
3
|
+
export { createContent, createContent as createContentReact } from './component/createContent.js';
|
|
4
|
+
export { createClass, createClass as createClassReact } from './component/createClass.js';
|
|
5
|
+
export { createStateOrContext } from './component/createStateOrContext.js';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
declare const createAttr: (obj: {
|
|
2
|
+
[key: string]: string | number;
|
|
3
|
+
}) => {
|
|
4
|
+
[key: string]: string | number;
|
|
5
|
+
} | undefined;
|
|
6
|
+
|
|
7
|
+
declare const createStyle: (obj: {
|
|
8
|
+
[key: string]: string | number;
|
|
9
|
+
}) => {
|
|
10
|
+
[key: string]: string | number;
|
|
11
|
+
};
|
|
12
|
+
declare const createStyleReact: (obj: {
|
|
13
|
+
[key: string]: string | number;
|
|
14
|
+
}) => {
|
|
15
|
+
[key: string]: any;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
declare const createContent: (content: string) => string;
|
|
19
|
+
|
|
20
|
+
declare const createClass: (obj: {
|
|
21
|
+
[key: string]: boolean | undefined;
|
|
22
|
+
}) => string;
|
|
23
|
+
|
|
24
|
+
declare const createStateOrContext: (obj: {
|
|
25
|
+
[key: string]: any;
|
|
26
|
+
}) => {
|
|
27
|
+
[key: string]: any;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export { createAttr, createAttr as createAttrReact, createClass, createClass as createClassReact, createContent, createContent as createContentReact, createStateOrContext, createStyle, createStyleReact };
|
package/package.json
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gem-sdk/system",
|
|
3
|
-
"version": "1.58.0-dev.
|
|
3
|
+
"version": "1.58.0-dev.135",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "src/index.ts",
|
|
7
7
|
"files": [
|
|
8
|
-
"dist"
|
|
8
|
+
"dist",
|
|
9
|
+
"src"
|
|
9
10
|
],
|
|
10
11
|
"scripts": {
|
|
12
|
+
"cleanup": "rimraf es dist lib",
|
|
13
|
+
"prebuild": "yarn cleanup",
|
|
14
|
+
"build": "rollup -c ./../../helpers/rollup.config.mjs --environment NODE_ENV:production",
|
|
11
15
|
"test": "jest -c ./../../helpers/jest.config.ts",
|
|
12
16
|
"type-check": "yarn tsc --noEmit"
|
|
13
17
|
},
|
|
14
|
-
"dependencies": {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@gem-sdk/core": "1.58.0-dev.135"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {}
|
|
18
22
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
<div id={`shopify-text-element-${builderProps?.uid}`} data-product-id={currentProductId}>
|
|
2
|
+
{!product ? null : setting?.linkProduct ? (
|
|
3
|
+
<Link href={destination} title={product?.title}>
|
|
4
|
+
<Text
|
|
5
|
+
builderProps={builderProps}
|
|
6
|
+
styles={styles}
|
|
7
|
+
setting={{ ...setting, text: product.title, excludeFlex: true }}
|
|
8
|
+
/>
|
|
9
|
+
</Link>
|
|
10
|
+
) : (
|
|
11
|
+
<Text
|
|
12
|
+
builderProps={builderProps}
|
|
13
|
+
styles={styles}
|
|
14
|
+
setting={{ ...setting, text: product.title, excludeFlex: true }}
|
|
15
|
+
/>
|
|
16
|
+
)}
|
|
17
|
+
</div>
|
|
18
|
+
|
|
19
|
+
<div>
|
|
20
|
+
<If>
|
|
21
|
+
|
|
22
|
+
</If>
|
|
23
|
+
<For>
|
|
24
|
+
|
|
25
|
+
</For>
|
|
26
|
+
</div>
|
|
27
|
+
|
|
28
|
+
{%- unless product -%}
|
|
29
|
+
<p>${getStaticLocale('ProductTitle', 'product_not_found')}</p>
|
|
30
|
+
{%- else -%}
|
|
31
|
+
${
|
|
32
|
+
setting?.linkProduct
|
|
33
|
+
? `
|
|
34
|
+
<a href="{{ product.url }}" title="{{ product.title }}" class="gp-product-title-link-wrapper">
|
|
35
|
+
${Text({
|
|
36
|
+
styles: styles,
|
|
37
|
+
setting: { ...setting, text: '{{ product.title }}', excludeFlex: true },
|
|
38
|
+
advanced: advanced,
|
|
39
|
+
builderProps
|
|
40
|
+
})}
|
|
41
|
+
</a>
|
|
42
|
+
`
|
|
43
|
+
: `
|
|
44
|
+
${Text({
|
|
45
|
+
styles: styles,
|
|
46
|
+
setting: { ...setting, text: '{{ product.title }}', excludeFlex: true },
|
|
47
|
+
advanced: advanced,
|
|
48
|
+
className: 'gp-product-title',
|
|
49
|
+
builderProps
|
|
50
|
+
})}
|
|
51
|
+
`
|
|
52
|
+
}
|
|
53
|
+
{%- endunless -%}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { describe, test, expect, beforeEach, jest } from '@jest/globals';
|
|
2
|
+
import { createAttr } from '../createAttr';
|
|
3
|
+
|
|
4
|
+
// Mock console.error to capture error messages
|
|
5
|
+
global.console.error = jest.fn();
|
|
6
|
+
|
|
7
|
+
describe('createAttr', () => {
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
// Clear the console.error mock before each test
|
|
10
|
+
(console.error as jest.Mock).mockClear();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test('should log error for key without "data-gp-" prefix', () => {
|
|
14
|
+
createAttr({ invalidKey: 'some value' });
|
|
15
|
+
expect(console.error).toHaveBeenCalledWith(
|
|
16
|
+
'Invalid attribute key: "invalidKey". Must start with "data-gp-".',
|
|
17
|
+
);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test('should log error for key with uppercase letters', () => {
|
|
21
|
+
createAttr({ 'data-gp-UppercaseKey': 'some value' });
|
|
22
|
+
expect(console.error).toHaveBeenCalledWith(
|
|
23
|
+
'Invalid attribute key: "data-gp-UppercaseKey". Must not contain uppercase letters.',
|
|
24
|
+
);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test('should log error for nested object', () => {
|
|
28
|
+
createAttr({ 'data-gp-nested': { fontSize: '12px' } } as any);
|
|
29
|
+
expect(console.error).toHaveBeenCalledWith(
|
|
30
|
+
'Invalid nested attribute for key "data-gp-nested". Nested objects are not supported.',
|
|
31
|
+
);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('should log error for invalid value type', () => {
|
|
35
|
+
createAttr({ 'data-gp-invalidType': true as any });
|
|
36
|
+
expect(console.error).toHaveBeenCalledWith(
|
|
37
|
+
'Invalid attribute value for key "data-gp-invalidType": true. Must be a string or number.',
|
|
38
|
+
);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('should handle multiple errors in one call', () => {
|
|
42
|
+
createAttr({
|
|
43
|
+
invalidKey: 'some value', // Invalid prefix
|
|
44
|
+
'data-gp-UppercaseKey': 'some value', // Uppercase in key
|
|
45
|
+
'data-gp-nested': { fontSize: '12px' }, // Nested object
|
|
46
|
+
'data-gp-invalidType': true as any, // Invalid value type
|
|
47
|
+
} as any);
|
|
48
|
+
|
|
49
|
+
expect(console.error).toHaveBeenCalledWith(
|
|
50
|
+
'Invalid attribute key: "invalidKey". Must start with "data-gp-".',
|
|
51
|
+
);
|
|
52
|
+
expect(console.error).toHaveBeenCalledWith(
|
|
53
|
+
'Invalid attribute key: "data-gp-UppercaseKey". Must not contain uppercase letters.',
|
|
54
|
+
);
|
|
55
|
+
expect(console.error).toHaveBeenCalledWith(
|
|
56
|
+
'Invalid nested attribute for key "data-gp-nested". Nested objects are not supported.',
|
|
57
|
+
);
|
|
58
|
+
expect(console.error).toHaveBeenCalledWith(
|
|
59
|
+
'Invalid attribute value for key "data-gp-invalidType": true. Must be a string or number.',
|
|
60
|
+
);
|
|
61
|
+
});
|
|
62
|
+
});
|