@gem-sdk/system 1.58.0-dev.139 → 1.58.0-dev.140
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,89 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
|
|
5
|
+
Liquid in liquid.ts
|
|
6
|
+
<div>
|
|
7
|
+
Liquid(`
|
|
8
|
+
{%-if productSelectedVariant == empty or productSelectedVariant == null -%}
|
|
9
|
+
{%- assign productSelectedVariant = product.selected_or_first_available_variant -%}
|
|
10
|
+
{%- endif -%}
|
|
11
|
+
{%-if variant == empty or variant == null -%}
|
|
12
|
+
{%- assign variant = product.selected_or_first_available_variant -%}
|
|
13
|
+
{%- endif -%}
|
|
14
|
+
`)
|
|
15
|
+
</div>
|
|
16
|
+
|
|
17
|
+
IF in tsx & liquid.ts
|
|
18
|
+
<div {...attrs}>
|
|
19
|
+
{
|
|
20
|
+
If(product.id != "", (
|
|
21
|
+
<label className={classes} style={styles}>
|
|
22
|
+
{content}
|
|
23
|
+
</label>
|
|
24
|
+
), (
|
|
25
|
+
<label className={classes} style={styles}>
|
|
26
|
+
{content}
|
|
27
|
+
</label>
|
|
28
|
+
))
|
|
29
|
+
}
|
|
30
|
+
</div>
|
|
31
|
+
|
|
32
|
+
LiquidIF in liquid.ts
|
|
33
|
+
<div {...attrs}>
|
|
34
|
+
{
|
|
35
|
+
LiquidIf("product.quanity > 0", `
|
|
36
|
+
<label className={classes} style={styles}>
|
|
37
|
+
{content}
|
|
38
|
+
</label>
|
|
39
|
+
`, `
|
|
40
|
+
<label className={classes} style={styles}>
|
|
41
|
+
{content}
|
|
42
|
+
</label>
|
|
43
|
+
`)
|
|
44
|
+
}
|
|
45
|
+
</div>
|
|
46
|
+
|
|
47
|
+
For in tsx & liquid.ts
|
|
48
|
+
{
|
|
49
|
+
For(numbers, (item, index) => (
|
|
50
|
+
<div key={index}>
|
|
51
|
+
{index + 1}: Số {item}
|
|
52
|
+
</div>
|
|
53
|
+
))
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
LiquidFor in tsx & liquid.ts
|
|
57
|
+
{
|
|
58
|
+
LiquidFor('(item, index) in items', `
|
|
59
|
+
<div key="{{ forloop.index }}">
|
|
60
|
+
{{ forloop.index + 1}}: Số {{item}}
|
|
61
|
+
</div>
|
|
62
|
+
`)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
*/ const Liquid = (code)=>{
|
|
66
|
+
return code;
|
|
67
|
+
};
|
|
68
|
+
const For = (items, renderFn)=>{
|
|
69
|
+
return items.map((item, index)=>renderFn(item, index));
|
|
70
|
+
};
|
|
71
|
+
const LiquidFor = (c, t)=>{
|
|
72
|
+
return `{% for ${c} %}${typeof t === 'string' ? t : t()}{% endfor %}`;
|
|
73
|
+
};
|
|
74
|
+
const If = (condition, trueResult, falseResult)=>{
|
|
75
|
+
if (condition) {
|
|
76
|
+
// Trả về kết quả đúng nếu điều kiện là true
|
|
77
|
+
return typeof trueResult === 'function' ? trueResult() : trueResult;
|
|
78
|
+
} else {
|
|
79
|
+
// Trả về kết quả sai nếu điều kiện là false
|
|
80
|
+
return falseResult ? typeof falseResult === 'function' ? falseResult() : falseResult : null; // Nếu không có falseResult, trả về null
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
const LiquidIf = (c, t, f)=>`{% if ${c} %}${typeof t === 'string' ? t : t()}${f ? `{% else %}${typeof f === 'string' ? f : f?.()}` : ''}{% endif %}`;
|
|
84
|
+
|
|
85
|
+
exports.For = For;
|
|
86
|
+
exports.If = If;
|
|
87
|
+
exports.Liquid = Liquid;
|
|
88
|
+
exports.LiquidFor = LiquidFor;
|
|
89
|
+
exports.LiquidIf = LiquidIf;
|
package/dist/cjs/index.js
CHANGED
|
@@ -5,6 +5,7 @@ var createStyle = require('./component/createStyle.js');
|
|
|
5
5
|
var createContent = require('./component/createContent.js');
|
|
6
6
|
var createClass = require('./component/createClass.js');
|
|
7
7
|
var createStateOrContext = require('./component/createStateOrContext.js');
|
|
8
|
+
var template = require('./component/template.js');
|
|
8
9
|
|
|
9
10
|
const createAttrReact = createAttr.createAttr;
|
|
10
11
|
const createContentReact = createContent.createContent;
|
|
@@ -16,6 +17,11 @@ exports.createStyleReact = createStyle.createStyleReact;
|
|
|
16
17
|
exports.createContent = createContent.createContent;
|
|
17
18
|
exports.createClass = createClass.createClass;
|
|
18
19
|
exports.createStateOrContext = createStateOrContext.createStateOrContext;
|
|
20
|
+
exports.For = template.For;
|
|
21
|
+
exports.If = template.If;
|
|
22
|
+
exports.Liquid = template.Liquid;
|
|
23
|
+
exports.LiquidFor = template.LiquidFor;
|
|
24
|
+
exports.LiquidIf = template.LiquidIf;
|
|
19
25
|
exports.createAttrReact = createAttrReact;
|
|
20
26
|
exports.createClassReact = createClassReact;
|
|
21
27
|
exports.createContentReact = createContentReact;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|
|
3
|
+
Liquid in liquid.ts
|
|
4
|
+
<div>
|
|
5
|
+
Liquid(`
|
|
6
|
+
{%-if productSelectedVariant == empty or productSelectedVariant == null -%}
|
|
7
|
+
{%- assign productSelectedVariant = product.selected_or_first_available_variant -%}
|
|
8
|
+
{%- endif -%}
|
|
9
|
+
{%-if variant == empty or variant == null -%}
|
|
10
|
+
{%- assign variant = product.selected_or_first_available_variant -%}
|
|
11
|
+
{%- endif -%}
|
|
12
|
+
`)
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
IF in tsx & liquid.ts
|
|
16
|
+
<div {...attrs}>
|
|
17
|
+
{
|
|
18
|
+
If(product.id != "", (
|
|
19
|
+
<label className={classes} style={styles}>
|
|
20
|
+
{content}
|
|
21
|
+
</label>
|
|
22
|
+
), (
|
|
23
|
+
<label className={classes} style={styles}>
|
|
24
|
+
{content}
|
|
25
|
+
</label>
|
|
26
|
+
))
|
|
27
|
+
}
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
LiquidIF in liquid.ts
|
|
31
|
+
<div {...attrs}>
|
|
32
|
+
{
|
|
33
|
+
LiquidIf("product.quanity > 0", `
|
|
34
|
+
<label className={classes} style={styles}>
|
|
35
|
+
{content}
|
|
36
|
+
</label>
|
|
37
|
+
`, `
|
|
38
|
+
<label className={classes} style={styles}>
|
|
39
|
+
{content}
|
|
40
|
+
</label>
|
|
41
|
+
`)
|
|
42
|
+
}
|
|
43
|
+
</div>
|
|
44
|
+
|
|
45
|
+
For in tsx & liquid.ts
|
|
46
|
+
{
|
|
47
|
+
For(numbers, (item, index) => (
|
|
48
|
+
<div key={index}>
|
|
49
|
+
{index + 1}: Số {item}
|
|
50
|
+
</div>
|
|
51
|
+
))
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
LiquidFor in tsx & liquid.ts
|
|
55
|
+
{
|
|
56
|
+
LiquidFor('(item, index) in items', `
|
|
57
|
+
<div key="{{ forloop.index }}">
|
|
58
|
+
{{ forloop.index + 1}}: Số {{item}}
|
|
59
|
+
</div>
|
|
60
|
+
`)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
*/ const Liquid = (code)=>{
|
|
64
|
+
return code;
|
|
65
|
+
};
|
|
66
|
+
const For = (items, renderFn)=>{
|
|
67
|
+
return items.map((item, index)=>renderFn(item, index));
|
|
68
|
+
};
|
|
69
|
+
const LiquidFor = (c, t)=>{
|
|
70
|
+
return `{% for ${c} %}${typeof t === 'string' ? t : t()}{% endfor %}`;
|
|
71
|
+
};
|
|
72
|
+
const If = (condition, trueResult, falseResult)=>{
|
|
73
|
+
if (condition) {
|
|
74
|
+
// Trả về kết quả đúng nếu điều kiện là true
|
|
75
|
+
return typeof trueResult === 'function' ? trueResult() : trueResult;
|
|
76
|
+
} else {
|
|
77
|
+
// Trả về kết quả sai nếu điều kiện là false
|
|
78
|
+
return falseResult ? typeof falseResult === 'function' ? falseResult() : falseResult : null; // Nếu không có falseResult, trả về null
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
const LiquidIf = (c, t, f)=>`{% if ${c} %}${typeof t === 'string' ? t : t()}${f ? `{% else %}${typeof f === 'string' ? f : f?.()}` : ''}{% endif %}`;
|
|
82
|
+
|
|
83
|
+
export { For, If, Liquid, LiquidFor, LiquidIf };
|
package/dist/esm/index.js
CHANGED
|
@@ -3,6 +3,7 @@ export { createStyle, createStyleReact } from './component/createStyle.js';
|
|
|
3
3
|
import { createContent } from './component/createContent.js';
|
|
4
4
|
import { createClass } from './component/createClass.js';
|
|
5
5
|
export { createStateOrContext } from './component/createStateOrContext.js';
|
|
6
|
+
export { For, If, Liquid, LiquidFor, LiquidIf } from './component/template.js';
|
|
6
7
|
|
|
7
8
|
const createAttrReact = createAttr;
|
|
8
9
|
const createContentReact = createContent;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -27,6 +27,13 @@ declare const createStateOrContext: (obj: {
|
|
|
27
27
|
[key: string]: any;
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
+
type CallbackCondition = () => JSX.Element | string;
|
|
31
|
+
declare const Liquid: (code: string) => string;
|
|
32
|
+
declare const For: <T>(items: T[], renderFn: (item: T, index: number) => JSX.Element) => JSX.Element[];
|
|
33
|
+
declare const LiquidFor: (c: string, t: string | CallbackCondition) => string;
|
|
34
|
+
declare const If: (condition: boolean | null | undefined, trueResult: string | JSX.Element | CallbackCondition, falseResult?: string | JSX.Element | CallbackCondition) => JSX.Element | string | null;
|
|
35
|
+
declare const LiquidIf: (c: string, t: string | CallbackCondition, f?: string | CallbackCondition) => string;
|
|
36
|
+
|
|
30
37
|
declare const createAttrReact: (obj: {
|
|
31
38
|
[key: string]: string | number;
|
|
32
39
|
}) => {
|
|
@@ -39,4 +46,4 @@ declare const createClassReact: (obj: {
|
|
|
39
46
|
[key: string]: boolean | undefined;
|
|
40
47
|
}) => string;
|
|
41
48
|
|
|
42
|
-
export { createAttr, createAttrReact, createClass, createClassReact, createContent, createContentReact, createStateOrContext, createStyle, createStyleReact };
|
|
49
|
+
export { For, If, Liquid, LiquidFor, LiquidIf, createAttr, createAttrReact, createClass, createClassReact, createContent, createContentReact, createStateOrContext, createStyle, createStyleReact };
|