builder-settings-types 0.0.35 → 0.0.38
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.
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function w(o,t){for(const e in o)if(o.hasOwnProperty(e)){const i=o[e];t(e,i)}}class f{setOnChange(t){this.onChange=t,w(this.settings,(e,i)=>{i.setOnChange(t)})}constructor(t){this.title=t.title,this.settings=t.settings,Object.assign(this,t.settings)}draw(){const t=document.createElement("div");t.className="setting-group";const e=document.createElement("div");e.className="setting-group-title";const i=document.createElement("h3");i.textContent=this.title;const s=document.createElement("span");s.className="setting-group-arrow",s.innerHTML=`
|
|
2
2
|
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20" fill="none">
|
|
3
3
|
<path d="M5 7.5L10 12.5L15 7.5" stroke="#344054" stroke-width="1.66667" stroke-linecap="round" stroke-linejoin="round"/>
|
|
4
4
|
</svg>
|
|
5
|
-
`;const
|
|
5
|
+
`;const n=document.createElement("div");n.className="setting-group-content";for(const a in this.settings){const h=this.settings[a].draw();n.appendChild(h)}return e.onclick=()=>{n.classList.toggle("collapsed"),s.classList.toggle("rotated")},e.appendChild(i),e.appendChild(s),t.appendChild(e),t.appendChild(n),t}}function N(o){switch(o){case"number":return 0;case"text":return"";case"select":return null;case"color":return"#000000";case"date":return new Date().toISOString().split("T")[0]}}class g{constructor(t={}){this.props=t,this.value=this.props.default,this.title=t.title||""}setOnChange(t){this.onChange=t}setValue(t){this.value=t,this.inputEl&&(this.inputEl.value=String(t)),this.onChange&&this.onChange(t)}createInput(t){t={...this.props.inputProps,...t};const e=document.createElement("div");if(e.className=t.wrapperClassName||"",t.title||t.icon){const n=document.createElement("div");if(n.className="icon-container",t.icon){let a=this.createIcon(t.icon,t.iconClassName);n.appendChild(a)}if(t.title){const a=this.createLabel(t.title,t.labelClassName);n.appendChild(a)}e.appendChild(n)}const i=document.createElement("div");i.className=t.wrapperClassName||"";const s=document.createElement("input");return this.inputEl=s,s.value=t.value||N(t.inputType),s.type=t.inputType,s.className=t.inputClassName||"",s.oninput=n=>{const a=n.target;let l=a.value;t.inputType==="number"?l=Number(a.value):(t.inputType==="color"||t.inputType==="date")&&(l=a.value),this.value=l,this.onChange&&this.onChange(this.value)},t.inputCustomizer&&t.inputCustomizer(s),i.appendChild(s),e.appendChild(i),e}createLabel(t,e){const i=document.createElement("span");return i.textContent=t,i.className="input-label "+(e||""),i}createIcon(t,e){const i=document.createElement("span");return i.className="input-icon "+(e||""),i.innerHTML=t,i}}class u extends g{constructor(t={}){super(t),this.inputType="number"}draw(){const t=e=>{this.props.minValue!==void 0&&(e.min=String(this.props.minValue)),this.props.maxValue!==void 0&&(e.max=String(this.props.maxValue)),this.props.className&&e.classList.add(this.props.className),e.addEventListener("input",()=>{const i=this.props.minValue??Number.MIN_SAFE_INTEGER,s=this.props.maxValue??Number.MAX_SAFE_INTEGER;let n=Number(e.value);n<i&&(n=i),n>s&&(n=s),e.value=String(n)})};return this.createInput({value:this.value,inputType:this.inputType,title:this.props.title,icon:this.props.icon,inputClassName:"number-setting-input "+this.props.inputClassName,wrapperClassName:"number-setting-wrapper "+this.props.wrapperClassName,inputCustomizer:t})}}class x extends f{constructor(){super({title:"Margin",settings:{margin:new u({title:"Margin All"}),marginTop:new u({title:"Margin Top"}),marginRight:new u({title:"Margin Right"}),marginBottom:new u({title:"Margin Bottom"}),marginLeft:new u({title:"Margin Left"})}})}getCssCode(){return`
|
|
6
6
|
margin-botton: ${this.settings.marginBottom.value}px;
|
|
7
7
|
margin-top: ${this.settings.marginTop.value}px;
|
|
8
8
|
margin-right: ${this.settings.marginRight.value}px;
|
|
9
9
|
margin-left: ${this.settings.marginLeft.value}px;
|
|
10
|
-
`}}class
|
|
10
|
+
`}}class y extends g{constructor(t){super(t),this.inputType="color",this.icon="<svg xmlns='http://www.w3.org/2000/svg' width='18' height='19' viewBox='0 0 18 19' fill='none'><path d='M8.99999 15.8542C9.79613 16.5667 10.8475 17 12 17C14.4853 17 16.5 14.9853 16.5 12.5C16.5 10.4248 15.0953 8.67769 13.1849 8.15763M4.81513 8.15762C2.9047 8.67768 1.5 10.4248 1.5 12.5C1.5 14.9853 3.51472 17 6 17C8.48528 17 10.5 14.9853 10.5 12.5C10.5 11.9146 10.3882 11.3554 10.1849 10.8424M13.5 6.5C13.5 8.98528 11.4853 11 9 11C6.51472 11 4.5 8.98528 4.5 6.5C4.5 4.01472 6.51472 2 9 2C11.4853 2 13.5 4.01472 13.5 6.5Z' stroke='#667085' stroke-linecap='round' stroke-linejoin='round'/></svg>"}draw(){const t=document.createElement("div");t.className="color-setting-wrapper";const e=document.createElement("div");e.className="icon-container";const i=this.createIcon(this.icon),s=this.createLabel("Color");e.appendChild(i),e.appendChild(s);const n=document.createElement("div");n.className="color-input-wrapper";let a,l;const h=/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,d=p=>h.test(p.value)?(p.style.border="",!0):(p.style.border="1px solid red",!1);a=this.createInput({value:this.value,inputType:"text",inputClassName:"color-text-input",inputCustomizer:p=>{p.oninput=v=>{var m;let c=v.target.value.trim();if(!d(p))return;this.value=c,(m=this.onChange)==null||m.call(this,c);const C=document.getElementsByClassName("color-picker")[0];C.value=c,r.style.backgroundColor=c}}}),l=this.createInput({value:this.value,inputType:this.inputType,inputClassName:"color-picker",inputCustomizer:p=>{p.oninput=v=>{var m;let c=v.target.value;this.value=c,(m=this.onChange)==null||m.call(this,c);const C=document.getElementsByClassName("color-text-input")[0];C.value=c,r.style.backgroundColor=c,d(C)}}});const r=document.createElement("div");return r.className="color-preview",r.style.backgroundColor=this.value||"",n.appendChild(r),n.appendChild(l),n.appendChild(a),t.appendChild(e),t.appendChild(n),t}}class E extends g{constructor(t={}){super(t),this.inputType="text"}draw(){return this.createInput({value:this.value,inputType:this.inputType})}}class S extends u{constructor(t){super({...t,minValue:0,maxValue:100,icon:b,title:t.title||"Opacity"}),this.inputType="number"}}const b=`
|
|
11
11
|
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="19" viewBox="0 0 18 19" fill="none">
|
|
12
12
|
<path d="M3.69749 15.365C3.54749 15.365 3.40502 15.305 3.30002 15.2C1.77752 13.6775 0.9375 11.6525 0.9375 9.5C0.9375 5.0525 4.5525 1.4375 9 1.4375C11.1525 1.4375 13.1775 2.2775 14.7 3.8C14.805 3.905 14.865 4.0475 14.865 4.1975C14.865 4.3475 14.805 4.49 14.7 4.595L4.09502 15.2C3.99002 15.305 3.84749 15.365 3.69749 15.365ZM9 2.5625C5.175 2.5625 2.0625 5.675 2.0625 9.5C2.0625 11.165 2.64751 12.74 3.71251 13.9925L13.4925 4.2125C12.24 3.1475 10.665 2.5625 9 2.5625Z" fill="#667085"/>
|
|
13
13
|
<path d="M9.00026 17.5623C6.84776 17.5623 4.82278 16.7223 3.30028 15.1998C3.19528 15.0948 3.13525 14.9523 3.13525 14.8023C3.13525 14.6523 3.19528 14.5098 3.30028 14.4048L13.9052 3.79984C14.1227 3.58234 14.4827 3.58234 14.7002 3.79984C16.2227 5.32234 17.0628 7.34734 17.0628 9.49984C17.0628 13.9473 13.4478 17.5623 9.00026 17.5623ZM4.50777 14.7873C5.76027 15.8523 7.33526 16.4373 9.00026 16.4373C12.8253 16.4373 15.9378 13.3248 15.9378 9.49984C15.9378 7.83484 15.3527 6.25984 14.2878 5.00734L4.50777 14.7873Z" fill="#667085"/>
|
|
14
14
|
</svg>
|
|
15
|
-
`;class
|
|
15
|
+
`;class T extends g{constructor(t={}){super(t),this.inputType="select",this.props.options||(this.props.options=[]),this.props.getOptionsAsync&&this.props.getOptionsAsync().then(e=>{this.props.options=[...this.props.options,...e],e.forEach(i=>{var s;(s=this.selectNode)==null||s.appendChild(this.createOption(i))})}).catch(e=>{console.error("Failed to fetch async options:",e)})}createOption(t){const e=document.createElement("option");return e.value=t.value,e.textContent=t.name,e}draw(){var l,h;const t=document.createElement("div");t.classList.add("select-container");const e=document.createElement("div");e.className="icon-container";const i=this.createIcon(this.props.icon||""),s=this.createLabel(this.props.title||""),n=document.createElement("select");return this.selectNode=n,n.classList.add("select"),n.onchange=d=>{var r;(r=this.onChange)==null||r.call(this,d.target.value)},[...this.props.options||[],...((h=(l=this.props).getOptions)==null?void 0:h.call(l))||[]].forEach(d=>{const r=this.createOption(d);n.appendChild(r)}),this.value&&(n.value=this.value),e.appendChild(i),e.appendChild(s),t.appendChild(e),t.appendChild(n),t}}exports.ColorSetting=y;exports.MarginSettingGroup=x;exports.NumberSetting=u;exports.OpacitySetting=S;exports.SelectSetting=T;exports.Setting=g;exports.SettingGroup=f;exports.StringSetting=E;exports.iterateSettings=w;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
.setting-group{padding:16px;display:flex;flex-direction:column;gap:8px;border-bottom:solid 1px var(--color-border);border-radius:8px;background-color:var(--color-bg)}.setting-group .setting-group{margin-bottom:8px;background-color:var(--color-white)!important;padding:12px;border-bottom:unset;border:1px solid var(--color-border-secondary);box-shadow:0 12px 16px -4px #10182814,0 4px 6px -2px #10182808}.setting-group-title{display:flex;align-items:center;justify-content:space-between;cursor:pointer}.setting-group-title h3{font-size:14px;font-weight:700;line-height:24px}.setting-group-arrow{display:flex;transition:transform .3s ease-in-out}.setting-group-arrow.rotated{transform:rotate(180deg)}.setting-group-content{display:flex;flex-direction:column;gap:8px;overflow:hidden;max-height:500px;opacity:1;transition:max-height .5s ease-in-out,opacity .4s ease-in-out}.setting-group-content.collapsed{max-height:0;opacity:0}.icon-container{display:flex;align-items:center;gap:4px}.icon-container .input-icon{display:flex;align-items:center;justify-content:center;color:var(--color-text)}.icon-container .input-label{color:var(--color-text)}.number-setting-wrapper{display:flex;justify-content:space-between;align-items:center
|
|
1
|
+
.setting-group{padding:16px;display:flex;flex-direction:column;gap:8px;border-bottom:solid 1px var(--color-border);border-radius:8px;background-color:var(--color-bg)}.setting-group .setting-group{margin-bottom:8px;background-color:var(--color-white)!important;padding:12px;border-bottom:unset;border:1px solid var(--color-border-secondary);box-shadow:0 12px 16px -4px #10182814,0 4px 6px -2px #10182808}.setting-group-title{display:flex;align-items:center;justify-content:space-between;cursor:pointer}.setting-group-title h3{font-size:14px;font-weight:700;line-height:24px}.setting-group-arrow{display:flex;transition:transform .3s ease-in-out}.setting-group-arrow.rotated{transform:rotate(180deg)}.setting-group-content{display:flex;flex-direction:column;gap:8px;overflow:hidden;max-height:500px;opacity:1;transition:max-height .5s ease-in-out,opacity .4s ease-in-out}.setting-group-content.collapsed{max-height:0;opacity:0}.icon-container{display:flex;align-items:center;gap:4px}.icon-container .input-icon{display:flex;align-items:center;justify-content:center;color:var(--color-text)}.icon-container .input-label{color:var(--color-text)}.input-container{display:inline-flex;align-items:center;position:relative}.with-suffix{flex:1;padding-right:36px}.input-suffix{position:absolute;right:8px;top:50%;transform:translateY(-50%);color:#666;pointer-events:none;font-size:.9em}.number-setting-wrapper{display:flex;justify-content:space-between;align-items:center}.number-setting-wrapper input{width:120px;padding:8px;font-size:14px;border-radius:8px;color:var(--color-input-text);border:1px solid var(--color-border);background:var(--color-bg)}.color-setting-wrapper{display:flex;align-items:center;justify-content:space-between;gap:2px}.color-setting-wrapper .color-input-wrapper{position:relative;padding:8px 8px 8px 4px;width:120px;height:33px;display:flex;align-items:center;gap:8px;border:1px solid var(--color-border);border-radius:8px;background-color:var(--color-bg)}.color-setting-wrapper .color-input-wrapper .color-text-input{border:none;outline:none;width:100%;color:var(--color-input-text);font-size:14px;text-align:center;background:transparent}.color-setting-wrapper .color-input-wrapper .color-picker{position:absolute;left:0;top:0;width:25px;height:25px;opacity:0;cursor:pointer}.color-setting-wrapper .color-input-wrapper .color-preview{width:100%;height:25px;border-radius:4px}.select-container{display:flex;align-items:center;gap:4px;justify-content:space-between}.select{width:120px;padding:8px;font-size:14px;border-radius:8px;border:1px solid var(--color-border);background:var(--color-bg);cursor:pointer}.select:focus{outline:none}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
function
|
|
2
|
-
for (const e in
|
|
3
|
-
if (
|
|
4
|
-
const
|
|
5
|
-
t(e,
|
|
1
|
+
function w(o, t) {
|
|
2
|
+
for (const e in o)
|
|
3
|
+
if (o.hasOwnProperty(e)) {
|
|
4
|
+
const i = o[e];
|
|
5
|
+
t(e, i);
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
|
-
class
|
|
8
|
+
class f {
|
|
9
9
|
setOnChange(t) {
|
|
10
|
-
this.onChange = t,
|
|
11
|
-
|
|
10
|
+
this.onChange = t, w(this.settings, (e, i) => {
|
|
11
|
+
i.setOnChange(t);
|
|
12
12
|
});
|
|
13
13
|
}
|
|
14
14
|
constructor(t) {
|
|
@@ -19,27 +19,27 @@ class C {
|
|
|
19
19
|
t.className = "setting-group";
|
|
20
20
|
const e = document.createElement("div");
|
|
21
21
|
e.className = "setting-group-title";
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
22
|
+
const i = document.createElement("h3");
|
|
23
|
+
i.textContent = this.title;
|
|
24
|
+
const s = document.createElement("span");
|
|
25
|
+
s.className = "setting-group-arrow", s.innerHTML = `
|
|
26
26
|
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20" fill="none">
|
|
27
27
|
<path d="M5 7.5L10 12.5L15 7.5" stroke="#344054" stroke-width="1.66667" stroke-linecap="round" stroke-linejoin="round"/>
|
|
28
28
|
</svg>
|
|
29
29
|
`;
|
|
30
|
-
const
|
|
31
|
-
|
|
30
|
+
const n = document.createElement("div");
|
|
31
|
+
n.className = "setting-group-content";
|
|
32
32
|
for (const a in this.settings) {
|
|
33
33
|
const u = this.settings[a].draw();
|
|
34
|
-
|
|
34
|
+
n.appendChild(u);
|
|
35
35
|
}
|
|
36
36
|
return e.onclick = () => {
|
|
37
|
-
|
|
38
|
-
}, e.appendChild(
|
|
37
|
+
n.classList.toggle("collapsed"), s.classList.toggle("rotated");
|
|
38
|
+
}, e.appendChild(i), e.appendChild(s), t.appendChild(e), t.appendChild(n), t;
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
-
function
|
|
42
|
-
switch (
|
|
41
|
+
function N(o) {
|
|
42
|
+
switch (o) {
|
|
43
43
|
case "number":
|
|
44
44
|
return 0;
|
|
45
45
|
case "text":
|
|
@@ -52,56 +52,59 @@ function v(l) {
|
|
|
52
52
|
return (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
-
class
|
|
55
|
+
class C {
|
|
56
56
|
constructor(t = {}) {
|
|
57
|
-
this.props = t, this.value = this.props.default, this.title = t.title || ""
|
|
57
|
+
this.props = t, this.value = this.props.default, this.title = t.title || "";
|
|
58
58
|
}
|
|
59
59
|
setOnChange(t) {
|
|
60
60
|
this.onChange = t;
|
|
61
61
|
}
|
|
62
|
+
setValue(t) {
|
|
63
|
+
this.value = t, this.inputEl && (this.inputEl.value = String(t)), this.onChange && this.onChange(t);
|
|
64
|
+
}
|
|
62
65
|
createInput(t) {
|
|
63
66
|
t = { ...this.props.inputProps, ...t };
|
|
64
67
|
const e = document.createElement("div");
|
|
65
68
|
if (e.className = t.wrapperClassName || "", t.title || t.icon) {
|
|
66
|
-
const
|
|
67
|
-
if (
|
|
69
|
+
const n = document.createElement("div");
|
|
70
|
+
if (n.className = "icon-container", t.icon) {
|
|
68
71
|
let a = this.createIcon(t.icon, t.iconClassName);
|
|
69
|
-
|
|
72
|
+
n.appendChild(a);
|
|
70
73
|
}
|
|
71
74
|
if (t.title) {
|
|
72
75
|
const a = this.createLabel(t.title, t.labelClassName);
|
|
73
|
-
|
|
76
|
+
n.appendChild(a);
|
|
74
77
|
}
|
|
75
|
-
e.appendChild(
|
|
78
|
+
e.appendChild(n);
|
|
76
79
|
}
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
return
|
|
81
|
-
const a =
|
|
82
|
-
let
|
|
83
|
-
t.inputType === "number" ?
|
|
84
|
-
}, t.inputCustomizer && t.inputCustomizer(
|
|
80
|
+
const i = document.createElement("div");
|
|
81
|
+
i.className = t.wrapperClassName || "";
|
|
82
|
+
const s = document.createElement("input");
|
|
83
|
+
return this.inputEl = s, s.value = t.value || N(t.inputType), s.type = t.inputType, s.className = t.inputClassName || "", s.oninput = (n) => {
|
|
84
|
+
const a = n.target;
|
|
85
|
+
let l = a.value;
|
|
86
|
+
t.inputType === "number" ? l = Number(a.value) : (t.inputType === "color" || t.inputType === "date") && (l = a.value), this.value = l, this.onChange && this.onChange(this.value);
|
|
87
|
+
}, t.inputCustomizer && t.inputCustomizer(s), i.appendChild(s), e.appendChild(i), e;
|
|
85
88
|
}
|
|
86
89
|
createLabel(t, e) {
|
|
87
|
-
const
|
|
88
|
-
return
|
|
90
|
+
const i = document.createElement("span");
|
|
91
|
+
return i.textContent = t, i.className = "input-label " + (e || ""), i;
|
|
89
92
|
}
|
|
90
93
|
createIcon(t, e) {
|
|
91
|
-
const
|
|
92
|
-
return
|
|
94
|
+
const i = document.createElement("span");
|
|
95
|
+
return i.className = "input-icon " + (e || ""), i.innerHTML = t, i;
|
|
93
96
|
}
|
|
94
97
|
}
|
|
95
|
-
class
|
|
98
|
+
class d extends C {
|
|
96
99
|
constructor(t = {}) {
|
|
97
100
|
super(t), this.inputType = "number";
|
|
98
101
|
}
|
|
99
102
|
draw() {
|
|
100
103
|
const t = (e) => {
|
|
101
104
|
this.props.minValue !== void 0 && (e.min = String(this.props.minValue)), this.props.maxValue !== void 0 && (e.max = String(this.props.maxValue)), this.props.className && e.classList.add(this.props.className), e.addEventListener("input", () => {
|
|
102
|
-
const
|
|
103
|
-
let
|
|
104
|
-
|
|
105
|
+
const i = this.props.minValue ?? Number.MIN_SAFE_INTEGER, s = this.props.maxValue ?? Number.MAX_SAFE_INTEGER;
|
|
106
|
+
let n = Number(e.value);
|
|
107
|
+
n < i && (n = i), n > s && (n = s), e.value = String(n);
|
|
105
108
|
});
|
|
106
109
|
};
|
|
107
110
|
return this.createInput({
|
|
@@ -115,16 +118,16 @@ class h extends m {
|
|
|
115
118
|
});
|
|
116
119
|
}
|
|
117
120
|
}
|
|
118
|
-
class
|
|
121
|
+
class E extends f {
|
|
119
122
|
constructor() {
|
|
120
123
|
super({
|
|
121
124
|
title: "Margin",
|
|
122
125
|
settings: {
|
|
123
|
-
margin: new
|
|
124
|
-
marginTop: new
|
|
125
|
-
marginRight: new
|
|
126
|
-
marginBottom: new
|
|
127
|
-
marginLeft: new
|
|
126
|
+
margin: new d({ title: "Margin All" }),
|
|
127
|
+
marginTop: new d({ title: "Margin Top" }),
|
|
128
|
+
marginRight: new d({ title: "Margin Right" }),
|
|
129
|
+
marginBottom: new d({ title: "Margin Bottom" }),
|
|
130
|
+
marginLeft: new d({ title: "Margin Left" })
|
|
128
131
|
}
|
|
129
132
|
});
|
|
130
133
|
}
|
|
@@ -137,7 +140,7 @@ class N extends C {
|
|
|
137
140
|
`;
|
|
138
141
|
}
|
|
139
142
|
}
|
|
140
|
-
class
|
|
143
|
+
class y extends C {
|
|
141
144
|
constructor(t) {
|
|
142
145
|
super(t), this.inputType = "color", this.icon = "<svg xmlns='http://www.w3.org/2000/svg' width='18' height='19' viewBox='0 0 18 19' fill='none'><path d='M8.99999 15.8542C9.79613 16.5667 10.8475 17 12 17C14.4853 17 16.5 14.9853 16.5 12.5C16.5 10.4248 15.0953 8.67769 13.1849 8.15763M4.81513 8.15762C2.9047 8.67768 1.5 10.4248 1.5 12.5C1.5 14.9853 3.51472 17 6 17C8.48528 17 10.5 14.9853 10.5 12.5C10.5 11.9146 10.3882 11.3554 10.1849 10.8424M13.5 6.5C13.5 8.98528 11.4853 11 9 11C6.51472 11 4.5 8.98528 4.5 6.5C4.5 4.01472 6.51472 2 9 2C11.4853 2 13.5 4.01472 13.5 6.5Z' stroke='#667085' stroke-linecap='round' stroke-linejoin='round'/></svg>";
|
|
143
146
|
}
|
|
@@ -147,48 +150,49 @@ class f extends m {
|
|
|
147
150
|
t.className = "color-setting-wrapper";
|
|
148
151
|
const e = document.createElement("div");
|
|
149
152
|
e.className = "icon-container";
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
let a,
|
|
153
|
+
const i = this.createIcon(this.icon), s = this.createLabel("Color");
|
|
154
|
+
e.appendChild(i), e.appendChild(s);
|
|
155
|
+
const n = document.createElement("div");
|
|
156
|
+
n.className = "color-input-wrapper";
|
|
157
|
+
let a, l;
|
|
158
|
+
const u = /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/, h = (p) => u.test(p.value) ? (p.style.border = "", !0) : (p.style.border = "1px solid red", !1);
|
|
155
159
|
a = this.createInput({
|
|
156
160
|
value: this.value,
|
|
157
161
|
inputType: "text",
|
|
158
162
|
inputClassName: "color-text-input",
|
|
159
|
-
// icon: this.icon,
|
|
160
163
|
inputCustomizer: (p) => {
|
|
161
|
-
p.oninput = (
|
|
162
|
-
var
|
|
163
|
-
let
|
|
164
|
-
|
|
164
|
+
p.oninput = (v) => {
|
|
165
|
+
var m;
|
|
166
|
+
let c = v.target.value.trim();
|
|
167
|
+
if (!h(p)) return;
|
|
168
|
+
this.value = c, (m = this.onChange) == null || m.call(this, c);
|
|
169
|
+
const g = document.getElementsByClassName(
|
|
170
|
+
"color-picker"
|
|
171
|
+
)[0];
|
|
172
|
+
g.value = c, r.style.backgroundColor = c;
|
|
165
173
|
};
|
|
166
174
|
}
|
|
167
|
-
}),
|
|
175
|
+
}), l = this.createInput({
|
|
168
176
|
value: this.value,
|
|
169
177
|
inputType: this.inputType,
|
|
170
178
|
inputClassName: "color-picker",
|
|
171
179
|
inputCustomizer: (p) => {
|
|
172
|
-
p.oninput = (
|
|
173
|
-
var
|
|
174
|
-
let
|
|
175
|
-
this.value =
|
|
180
|
+
p.oninput = (v) => {
|
|
181
|
+
var m;
|
|
182
|
+
let c = v.target.value;
|
|
183
|
+
this.value = c, (m = this.onChange) == null || m.call(this, c);
|
|
184
|
+
const g = document.getElementsByClassName(
|
|
185
|
+
"color-text-input"
|
|
186
|
+
)[0];
|
|
187
|
+
g.value = c, r.style.backgroundColor = c, h(g);
|
|
176
188
|
};
|
|
177
189
|
}
|
|
178
190
|
});
|
|
179
|
-
const
|
|
180
|
-
return
|
|
181
|
-
var o;
|
|
182
|
-
let r = p.target.value;
|
|
183
|
-
this.value = r, (o = this.onChange) == null || o.call(this, r), u.style.backgroundColor = r;
|
|
184
|
-
}, a.oninput = (p) => {
|
|
185
|
-
var o;
|
|
186
|
-
let r = p.target.value;
|
|
187
|
-
this.value = r, (o = this.onChange) == null || o.call(this, r), u.style.backgroundColor = r;
|
|
188
|
-
}, i.appendChild(u), i.appendChild(a), i.appendChild(c), t.appendChild(e), t.appendChild(i), t;
|
|
191
|
+
const r = document.createElement("div");
|
|
192
|
+
return r.className = "color-preview", r.style.backgroundColor = this.value || "", n.appendChild(r), n.appendChild(l), n.appendChild(a), t.appendChild(e), t.appendChild(n), t;
|
|
189
193
|
}
|
|
190
194
|
}
|
|
191
|
-
class
|
|
195
|
+
class b extends C {
|
|
192
196
|
constructor(t = {}) {
|
|
193
197
|
super(t), this.inputType = "text";
|
|
194
198
|
}
|
|
@@ -199,59 +203,65 @@ class x extends m {
|
|
|
199
203
|
});
|
|
200
204
|
}
|
|
201
205
|
}
|
|
202
|
-
class
|
|
206
|
+
class T extends d {
|
|
203
207
|
constructor(t) {
|
|
204
208
|
super({
|
|
205
209
|
...t,
|
|
206
210
|
minValue: 0,
|
|
207
211
|
maxValue: 100,
|
|
208
|
-
icon:
|
|
209
|
-
title: t.title || "Opacity"
|
|
210
|
-
inputClassName: "number-setting-input",
|
|
211
|
-
wrapperClassName: "opacity-setting-wrapper"
|
|
212
|
+
icon: x,
|
|
213
|
+
title: t.title || "Opacity"
|
|
212
214
|
}), this.inputType = "number";
|
|
213
215
|
}
|
|
214
216
|
}
|
|
215
|
-
const
|
|
217
|
+
const x = `
|
|
216
218
|
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="19" viewBox="0 0 18 19" fill="none">
|
|
217
219
|
<path d="M3.69749 15.365C3.54749 15.365 3.40502 15.305 3.30002 15.2C1.77752 13.6775 0.9375 11.6525 0.9375 9.5C0.9375 5.0525 4.5525 1.4375 9 1.4375C11.1525 1.4375 13.1775 2.2775 14.7 3.8C14.805 3.905 14.865 4.0475 14.865 4.1975C14.865 4.3475 14.805 4.49 14.7 4.595L4.09502 15.2C3.99002 15.305 3.84749 15.365 3.69749 15.365ZM9 2.5625C5.175 2.5625 2.0625 5.675 2.0625 9.5C2.0625 11.165 2.64751 12.74 3.71251 13.9925L13.4925 4.2125C12.24 3.1475 10.665 2.5625 9 2.5625Z" fill="#667085"/>
|
|
218
220
|
<path d="M9.00026 17.5623C6.84776 17.5623 4.82278 16.7223 3.30028 15.1998C3.19528 15.0948 3.13525 14.9523 3.13525 14.8023C3.13525 14.6523 3.19528 14.5098 3.30028 14.4048L13.9052 3.79984C14.1227 3.58234 14.4827 3.58234 14.7002 3.79984C16.2227 5.32234 17.0628 7.34734 17.0628 9.49984C17.0628 13.9473 13.4478 17.5623 9.00026 17.5623ZM4.50777 14.7873C5.76027 15.8523 7.33526 16.4373 9.00026 16.4373C12.8253 16.4373 15.9378 13.3248 15.9378 9.49984C15.9378 7.83484 15.3527 6.25984 14.2878 5.00734L4.50777 14.7873Z" fill="#667085"/>
|
|
219
221
|
</svg>
|
|
220
222
|
`;
|
|
221
|
-
class
|
|
223
|
+
class L extends C {
|
|
222
224
|
constructor(t = {}) {
|
|
223
|
-
super(t), this.inputType = "select"
|
|
225
|
+
super(t), this.inputType = "select", this.props.options || (this.props.options = []), this.props.getOptionsAsync && this.props.getOptionsAsync().then((e) => {
|
|
226
|
+
this.props.options = [...this.props.options, ...e], e.forEach((i) => {
|
|
227
|
+
var s;
|
|
228
|
+
(s = this.selectNode) == null || s.appendChild(this.createOption(i));
|
|
229
|
+
});
|
|
230
|
+
}).catch((e) => {
|
|
231
|
+
console.error("Failed to fetch async options:", e);
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
createOption(t) {
|
|
235
|
+
const e = document.createElement("option");
|
|
236
|
+
return e.value = t.value, e.textContent = t.name, e;
|
|
224
237
|
}
|
|
225
238
|
draw() {
|
|
239
|
+
var l, u;
|
|
226
240
|
const t = document.createElement("div");
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
return this.props.getOptions && (s = this.props.getOptions()), this.props.options && s.push(...this.props.options), s.forEach(({ value: n, name: i }) => {
|
|
242
|
-
const a = document.createElement("option");
|
|
243
|
-
a.value = n, a.textContent = i, e.appendChild(a);
|
|
244
|
-
}), this.props.value && (e.value = this.props.value), t.appendChild(e), t;
|
|
241
|
+
t.classList.add("select-container");
|
|
242
|
+
const e = document.createElement("div");
|
|
243
|
+
e.className = "icon-container";
|
|
244
|
+
const i = this.createIcon(this.props.icon || ""), s = this.createLabel(this.props.title || ""), n = document.createElement("select");
|
|
245
|
+
return this.selectNode = n, n.classList.add("select"), n.onchange = (h) => {
|
|
246
|
+
var r;
|
|
247
|
+
(r = this.onChange) == null || r.call(this, h.target.value);
|
|
248
|
+
}, [
|
|
249
|
+
...this.props.options || [],
|
|
250
|
+
...((u = (l = this.props).getOptions) == null ? void 0 : u.call(l)) || []
|
|
251
|
+
].forEach((h) => {
|
|
252
|
+
const r = this.createOption(h);
|
|
253
|
+
n.appendChild(r);
|
|
254
|
+
}), this.value && (n.value = this.value), e.appendChild(i), e.appendChild(s), t.appendChild(e), t.appendChild(n), t;
|
|
245
255
|
}
|
|
246
256
|
}
|
|
247
257
|
export {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
258
|
+
y as ColorSetting,
|
|
259
|
+
E as MarginSettingGroup,
|
|
260
|
+
d as NumberSetting,
|
|
261
|
+
T as OpacitySetting,
|
|
262
|
+
L as SelectSetting,
|
|
263
|
+
C as Setting,
|
|
264
|
+
f as SettingGroup,
|
|
265
|
+
b as StringSetting,
|
|
266
|
+
w as iterateSettings
|
|
257
267
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -70,11 +70,15 @@ declare type Primitive = string | number | boolean | symbol | bigint | null | un
|
|
|
70
70
|
export declare class SelectSetting extends Setting<string, SelectSettingProps> {
|
|
71
71
|
inputType: InputTypes;
|
|
72
72
|
constructor(props?: SelectSettingProps);
|
|
73
|
+
createOption(o: {
|
|
74
|
+
value: string;
|
|
75
|
+
name: string;
|
|
76
|
+
}): HTMLOptionElement;
|
|
77
|
+
selectNode: HTMLSelectElement | undefined;
|
|
73
78
|
draw(): HTMLElement;
|
|
74
79
|
}
|
|
75
80
|
|
|
76
81
|
export declare interface SelectSettingProps extends SettingProps<string> {
|
|
77
|
-
value?: string;
|
|
78
82
|
options?: {
|
|
79
83
|
value: string;
|
|
80
84
|
name: string;
|
|
@@ -83,16 +87,22 @@ export declare interface SelectSettingProps extends SettingProps<string> {
|
|
|
83
87
|
value: string;
|
|
84
88
|
name: string;
|
|
85
89
|
}[];
|
|
90
|
+
getOptionsAsync?: () => Promise<{
|
|
91
|
+
value: string;
|
|
92
|
+
name: string;
|
|
93
|
+
}[]>;
|
|
86
94
|
}
|
|
87
95
|
|
|
88
96
|
export declare abstract class Setting<T, P extends SettingProps<T>> implements IDrawable, IChangable<T> {
|
|
89
97
|
protected props: P;
|
|
98
|
+
protected inputEl?: HTMLInputElement;
|
|
90
99
|
value: T | undefined;
|
|
91
100
|
title: string | undefined;
|
|
92
101
|
abstract inputType: T extends Primitive ? InputTypes : Record<keyof T, InputTypes>;
|
|
93
102
|
onChange: ((value: T) => void) | undefined;
|
|
94
103
|
constructor(props?: P);
|
|
95
104
|
setOnChange(onChange: (value: T) => void): void;
|
|
105
|
+
setValue(newValue: T): void;
|
|
96
106
|
abstract draw(): HTMLElement;
|
|
97
107
|
createInput(props: InputProps): HTMLElement;
|
|
98
108
|
createLabel(title: string, className?: string): HTMLSpanElement;
|
package/package.json
CHANGED