@chaibuilder/sdk 2.5.4 → 2.5.6
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/{apply-binding-CkrtJykq.js → apply-binding-BL-JPMms.js} +29 -26
- package/dist/apply-binding-T3HdSezj.cjs +1 -0
- package/dist/core.cjs +3 -3
- package/dist/core.js +236 -231
- package/dist/render.cjs +1 -1
- package/dist/render.js +2 -2
- package/package.json +1 -1
- package/dist/apply-binding-DpBwzIf9.cjs +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getRegisteredChaiBlock as $ } from "@chaibuilder/runtime";
|
|
2
|
-
import { memoize as k, get as
|
|
2
|
+
import { memoize as k, get as p, cloneDeep as h, forEach as _, keys as f, isString as x, startsWith as m, isArray as g, isEmpty as b, includes as C } from "lodash-es";
|
|
3
3
|
import { twMerge as D } from "tailwind-merge";
|
|
4
4
|
const E = "#styles:", P = "__ADD_BLOCK_INTERNAL_ROOT", q = "@", B = "#", I = (e) => {
|
|
5
5
|
if (e = e.replace(E, ""), !e) return { baseClasses: "", classes: "" };
|
|
@@ -45,11 +45,14 @@ import.meta.vitest && describe("getSplitChaiClasses", () => {
|
|
|
45
45
|
});
|
|
46
46
|
});
|
|
47
47
|
function w(e, s, t) {
|
|
48
|
-
const n =
|
|
48
|
+
const n = p(t, "i18nProps", []);
|
|
49
49
|
if (b(s) || b(n)) return e;
|
|
50
|
-
const a =
|
|
51
|
-
return
|
|
52
|
-
C(n, r) && !b(s)
|
|
50
|
+
const a = h(e);
|
|
51
|
+
return _(f(a), (r) => {
|
|
52
|
+
if (C(n, r) && !b(s)) {
|
|
53
|
+
const o = p(a, `${r}-${s}`, ""), l = p(a, r, "");
|
|
54
|
+
a[r] = x(o) && o.trim() || l;
|
|
55
|
+
}
|
|
53
56
|
}), a;
|
|
54
57
|
}
|
|
55
58
|
const v = k((e) => {
|
|
@@ -57,12 +60,12 @@ const v = k((e) => {
|
|
|
57
60
|
return D(s, t);
|
|
58
61
|
});
|
|
59
62
|
function T(e, s) {
|
|
60
|
-
return
|
|
63
|
+
return p(e, `${s}_attrs`, {});
|
|
61
64
|
}
|
|
62
65
|
function A(e, s = !0) {
|
|
63
66
|
const t = {};
|
|
64
67
|
return Object.keys(e).forEach((n) => {
|
|
65
|
-
if (
|
|
68
|
+
if (x(e[n]) && e[n].startsWith(E)) {
|
|
66
69
|
const a = v(e[n]), r = T(e, n);
|
|
67
70
|
t[n] = {
|
|
68
71
|
...!b(a) && { className: a },
|
|
@@ -77,48 +80,48 @@ function A(e, s = !0) {
|
|
|
77
80
|
}), t;
|
|
78
81
|
}
|
|
79
82
|
const N = k((e) => {
|
|
80
|
-
const s = $(e), t =
|
|
81
|
-
return Object.fromEntries(Object.entries(t).filter(([, n]) =>
|
|
83
|
+
const s = $(e), t = p(s, "schema.properties", {});
|
|
84
|
+
return Object.fromEntries(Object.entries(t).filter(([, n]) => p(n, "runtime", !1)));
|
|
82
85
|
}), j = (e, s) => {
|
|
83
86
|
if (!g(e)) return e;
|
|
84
87
|
let t = e, n;
|
|
85
88
|
return typeof s.limit == "number" && s.limit > 0 && (n = s.limit), n !== void 0 && (t = t.slice(0, n)), t;
|
|
86
89
|
}, z = (e, s) => {
|
|
87
|
-
const t =
|
|
88
|
-
return
|
|
89
|
-
if (
|
|
90
|
+
const t = h(e);
|
|
91
|
+
return _(f(t), (n) => {
|
|
92
|
+
if (x(t[n]) && !m(n, "_")) {
|
|
90
93
|
let a = t[n];
|
|
91
94
|
n === "repeaterItems" && (t.repeaterItemsBinding = a);
|
|
92
|
-
const r = /\{\{(.*?)\}\}/g,
|
|
93
|
-
|
|
94
|
-
let
|
|
95
|
-
const
|
|
96
|
-
a = g(
|
|
95
|
+
const r = /\{\{(.*?)\}\}/g, o = a.match(r);
|
|
96
|
+
o && o.forEach((l) => {
|
|
97
|
+
let c = l.slice(2, -2);
|
|
98
|
+
const d = p(s, c, l);
|
|
99
|
+
a = g(d) ? d : a.replace(l, d);
|
|
97
100
|
}), t[n] = a;
|
|
98
101
|
}
|
|
99
102
|
}), t;
|
|
100
103
|
}, i = (e, s, { index: t, key: n }) => {
|
|
101
|
-
if (
|
|
104
|
+
if (x(e)) {
|
|
102
105
|
let a = e;
|
|
103
|
-
const r = /\{\{(.*?)\}\}/g,
|
|
104
|
-
return
|
|
105
|
-
let
|
|
106
|
-
t !== -1 && m(
|
|
107
|
-
const
|
|
108
|
-
a = g(
|
|
106
|
+
const r = /\{\{(.*?)\}\}/g, o = e.match(r);
|
|
107
|
+
return o && o.forEach((l) => {
|
|
108
|
+
let c = l.slice(2, -2).trim(), d = n.slice(2, -2).trim();
|
|
109
|
+
t !== -1 && m(c, "$index.") ? c = `${d}.${t}.${c.slice(7)}` : t !== -1 && m(c, "$index") && (c = `${d}.${t}`);
|
|
110
|
+
const y = p(s, c, l);
|
|
111
|
+
a = g(y) ? y : a.replace(l, y);
|
|
109
112
|
}), a;
|
|
110
113
|
}
|
|
111
114
|
if (g(e))
|
|
112
115
|
return e.map((a) => i(a, s, { index: t, key: n }));
|
|
113
116
|
if (e && typeof e == "object") {
|
|
114
117
|
const a = {};
|
|
115
|
-
return
|
|
118
|
+
return _(f(e), (r) => {
|
|
116
119
|
!m(r, "_") && r !== "$repeaterItemsKey" ? a[r] = i(e[r], s, { index: t, key: n }) : a[r] = e[r];
|
|
117
120
|
}), a;
|
|
118
121
|
}
|
|
119
122
|
return e;
|
|
120
123
|
}, u = (e, s, { index: t, key: n }) => {
|
|
121
|
-
let a =
|
|
124
|
+
let a = h(e);
|
|
122
125
|
return a.repeaterItems && (a.$repeaterItemsKey = a.repeaterItems, m(a.repeaterItems, `{{${B}`) && (a.$repeaterItemsKey = a.repeaterItems = `${a.repeaterItems.replace("}}", `/${a._id}}}`)}`)), i(a, s, { index: t, key: n });
|
|
123
126
|
};
|
|
124
127
|
import.meta.vitest && (describe("applyBindingToValue", () => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const b=require("@chaibuilder/runtime"),t=require("lodash-es"),h=require("tailwind-merge"),g="#styles:",x="__ADD_BLOCK_INTERNAL_ROOT",E="@",m="#",y=e=>{if(e=e.replace(g,""),!e)return{baseClasses:"",classes:""};const i=e.split(/,(?![^\[]*\])/);if(i.length===1)return{baseClasses:"",classes:i[0].trim()};const[a,...n]=i;return{baseClasses:a.trim(),classes:n.join(",").trim().replace(/ +(?= )/g,"")}};function _(e,i,a){const n=t.get(a,"i18nProps",[]);if(t.isEmpty(i)||t.isEmpty(n))return e;const s=t.cloneDeep(e);return t.forEach(t.keys(s),l=>{if(t.includes(n,l)&&!t.isEmpty(i)){const o=t.get(s,`${l}-${i}`,""),r=t.get(s,l,"");s[l]=t.isString(o)&&o.trim()||r}}),s}const f=t.memoize(e=>{const{baseClasses:i,classes:a}=y(e);return h.twMerge(i,a)});function k(e,i){return t.get(e,`${i}_attrs`,{})}function B(e,i=!0){const a={};return Object.keys(e).forEach(n=>{if(t.isString(e[n])&&e[n].startsWith(g)){const s=f(e[n]),l=k(e,n);a[n]={...!t.isEmpty(s)&&{className:s},...l,...i?{"data-style-prop":n,"data-block-parent":e._id,"data-style-id":`${n}-${e._id}`}:{}}}}),a}const I=t.memoize(e=>{const i=b.getRegisteredChaiBlock(e),a=t.get(i,"schema.properties",{});return Object.fromEntries(Object.entries(a).filter(([,n])=>t.get(n,"runtime",!1)))}),T=(e,i)=>{if(!t.isArray(e))return e;let a=e,n;return typeof i.limit=="number"&&i.limit>0&&(n=i.limit),n!==void 0&&(a=a.slice(0,n)),a},C=(e,i)=>{const a=t.cloneDeep(e);return t.forEach(t.keys(a),n=>{if(t.isString(a[n])&&!t.startsWith(n,"_")){let s=a[n];n==="repeaterItems"&&(a.repeaterItemsBinding=s);const l=/\{\{(.*?)\}\}/g,o=s.match(l);o&&o.forEach(r=>{let c=r.slice(2,-2);const p=t.get(i,c,r);s=t.isArray(p)?p:s.replace(r,p)}),a[n]=s}}),a},u=(e,i,{index:a,key:n})=>{if(t.isString(e)){let s=e;const l=/\{\{(.*?)\}\}/g,o=e.match(l);return o&&o.forEach(r=>{let c=r.slice(2,-2).trim(),p=n.slice(2,-2).trim();a!==-1&&t.startsWith(c,"$index.")?c=`${p}.${a}.${c.slice(7)}`:a!==-1&&t.startsWith(c,"$index")&&(c=`${p}.${a}`);const d=t.get(i,c,r);s=t.isArray(d)?d:s.replace(r,d)}),s}if(t.isArray(e))return e.map(s=>u(s,i,{index:a,key:n}));if(e&&typeof e=="object"){const s={};return t.forEach(t.keys(e),l=>{!t.startsWith(l,"_")&&l!=="$repeaterItemsKey"?s[l]=u(e[l],i,{index:a,key:n}):s[l]=e[l]}),s}return e},$=(e,i,{index:a,key:n})=>{let s=t.cloneDeep(e);return s.repeaterItems&&(s.$repeaterItemsKey=s.repeaterItems,t.startsWith(s.repeaterItems,`{{${m}`)&&(s.$repeaterItemsKey=s.repeaterItems=`${s.repeaterItems.replace("}}",`/${s._id}}}`)}`)),u(s,i,{index:a,key:n})};exports.COLLECTION_PREFIX=m;exports.REPEATER_PREFIX=E;exports.ROOT_TEMP_KEY=x;exports.STYLES_KEY=g;exports.applyBindingToBlockProps=$;exports.applyChaiDataBinding=C;exports.applyLanguage=_;exports.applyLimit=T;exports.getBlockRuntimeProps=I;exports.getBlockTagAttributes=B;exports.getSplitChaiClasses=y;
|