attaform 0.19.0 → 0.20.0
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/chunks/devtools.cjs +1 -1
- package/dist/chunks/devtools.mjs +1 -1
- package/dist/chunks/indexeddb.cjs +1 -1
- package/dist/chunks/indexeddb.mjs +1 -1
- package/dist/chunks/local-storage.cjs +1 -1
- package/dist/chunks/local-storage.mjs +1 -1
- package/dist/chunks/session-storage.cjs +1 -1
- package/dist/chunks/session-storage.mjs +1 -1
- package/dist/index.cjs +3 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -40
- package/dist/index.d.mts +14 -40
- package/dist/index.d.ts +14 -40
- package/dist/index.mjs +5 -5
- package/dist/nuxt.d.cts +1 -1
- package/dist/nuxt.d.mts +1 -1
- package/dist/nuxt.d.ts +1 -1
- package/dist/runtime/components/AttaformDevtoolsPanel.vue +2 -2
- package/dist/runtime/components/DevtoolsValueTree.d.vue.ts +1 -3
- package/dist/runtime/components/DevtoolsValueTree.vue.d.ts +1 -3
- package/dist/runtime/plugins/attaform.cjs +2 -2
- package/dist/runtime/plugins/attaform.mjs +2 -2
- package/dist/shared/{attaform.CrpjyXdO.mjs → attaform.BKozEdTr.mjs} +275 -266
- package/dist/shared/attaform.BKozEdTr.mjs.map +1 -0
- package/dist/shared/{attaform.Bubm_slq.cjs → attaform.BM6YD9kZ.cjs} +212 -269
- package/dist/shared/attaform.BM6YD9kZ.cjs.map +1 -0
- package/dist/shared/{attaform.CoxJ8Qm8.cjs → attaform.BPxsYtTe.cjs} +2 -26
- package/dist/shared/attaform.BPxsYtTe.cjs.map +1 -0
- package/dist/shared/{attaform.BqEfHpVB.cjs → attaform.BPy-4qRx.cjs} +275 -268
- package/dist/shared/attaform.BPy-4qRx.cjs.map +1 -0
- package/dist/shared/attaform.BWgAFnsj.mjs +770 -0
- package/dist/shared/attaform.BWgAFnsj.mjs.map +1 -0
- package/dist/shared/{attaform.BTpuvGec.d.ts → attaform.Bh3ACtts.d.ts} +109 -101
- package/dist/shared/{attaform.CXpzmj38.mjs → attaform.BupwXkj_.mjs} +213 -270
- package/dist/shared/attaform.BupwXkj_.mjs.map +1 -0
- package/dist/shared/{attaform.JBx8cfMA.cjs → attaform.CIn4bMsD.cjs} +263 -799
- package/dist/shared/attaform.CIn4bMsD.cjs.map +1 -0
- package/dist/shared/{attaform.BTi-PsHr.mjs → attaform.CKFbKFb6.mjs} +1818 -1472
- package/dist/shared/attaform.CKFbKFb6.mjs.map +1 -0
- package/dist/shared/{attaform.ePUcKxId.d.cts → attaform.D5-1XGQU.d.cts} +109 -101
- package/dist/shared/{attaform.a3uBo-gw.mjs → attaform.DEBvCjeH.mjs} +257 -793
- package/dist/shared/attaform.DEBvCjeH.mjs.map +1 -0
- package/dist/shared/{attaform.C1msmO2v.cjs → attaform.DL4CQ-oW.cjs} +1823 -1477
- package/dist/shared/attaform.DL4CQ-oW.cjs.map +1 -0
- package/dist/shared/{attaform.D4I63aBV.d.ts → attaform.DSD85fHb.d.cts} +1 -19
- package/dist/shared/{attaform.CBjmobqk.d.cts → attaform.DSD85fHb.d.mts} +1 -19
- package/dist/shared/{attaform.DXYHL99q.d.mts → attaform.DSD85fHb.d.ts} +1 -19
- package/dist/shared/{attaform.B7rzpK1U.d.cts → attaform.DkA5J8NW.d.cts} +1 -17
- package/dist/shared/{attaform.B7rzpK1U.d.mts → attaform.DkA5J8NW.d.mts} +1 -17
- package/dist/shared/{attaform.B7rzpK1U.d.ts → attaform.DkA5J8NW.d.ts} +1 -17
- package/dist/shared/{attaform.CJ-e9gYI.d.ts → attaform.Dl5kDY-A.d.ts} +1 -1
- package/dist/shared/attaform.Dmb6itxC.cjs +781 -0
- package/dist/shared/attaform.Dmb6itxC.cjs.map +1 -0
- package/dist/shared/{attaform.CRNA0vrd.d.mts → attaform.DoKXru-a.d.mts} +1 -1
- package/dist/shared/attaform.DvA-CJJW.mjs +1876 -0
- package/dist/shared/attaform.DvA-CJJW.mjs.map +1 -0
- package/dist/shared/{attaform.BtBmfLQN.d.mts → attaform.EMzJcQci.d.mts} +109 -101
- package/dist/shared/attaform.EZG6fOFb.mjs +35 -0
- package/dist/shared/attaform.EZG6fOFb.mjs.map +1 -0
- package/dist/shared/{attaform.QvygsFGh.d.cts → attaform.GbDo_lJi.d.cts} +1 -1
- package/dist/shared/{attaform.C0uGZQ4M.d.ts → attaform.SfhU0OEY.d.cts} +134 -30
- package/dist/shared/{attaform.C0uGZQ4M.d.cts → attaform.SfhU0OEY.d.mts} +134 -30
- package/dist/shared/{attaform.C0uGZQ4M.d.mts → attaform.SfhU0OEY.d.ts} +134 -30
- package/dist/shared/attaform.jgzuNZVC.cjs +1882 -0
- package/dist/shared/attaform.jgzuNZVC.cjs.map +1 -0
- package/dist/transforms.cjs +2 -2
- package/dist/transforms.d.cts +22 -13
- package/dist/transforms.d.mts +22 -13
- package/dist/transforms.d.ts +22 -13
- package/dist/transforms.mjs +1 -1
- package/dist/vite.cjs +8 -7
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.mjs +8 -7
- package/dist/vite.mjs.map +1 -1
- package/dist/zod-v3.cjs +3 -3
- package/dist/zod-v3.d.cts +32 -6
- package/dist/zod-v3.d.mts +32 -6
- package/dist/zod-v3.d.ts +32 -6
- package/dist/zod-v3.mjs +3 -3
- package/dist/zod-v4.cjs +3 -3
- package/dist/zod-v4.d.cts +12 -8
- package/dist/zod-v4.d.mts +12 -8
- package/dist/zod-v4.d.ts +12 -8
- package/dist/zod-v4.mjs +3 -3
- package/dist/zod.cjs +8 -8
- package/dist/zod.cjs.map +1 -1
- package/dist/zod.d.cts +6 -6
- package/dist/zod.d.mts +6 -6
- package/dist/zod.d.ts +6 -6
- package/dist/zod.mjs +6 -6
- package/package.json +1 -1
- package/dist/shared/attaform.BTi-PsHr.mjs.map +0 -1
- package/dist/shared/attaform.BqEfHpVB.cjs.map +0 -1
- package/dist/shared/attaform.Bubm_slq.cjs.map +0 -1
- package/dist/shared/attaform.C1msmO2v.cjs.map +0 -1
- package/dist/shared/attaform.C8CyvYa_.cjs +0 -36
- package/dist/shared/attaform.C8CyvYa_.cjs.map +0 -1
- package/dist/shared/attaform.CXpzmj38.mjs.map +0 -1
- package/dist/shared/attaform.Cghpuav8.mjs +0 -57
- package/dist/shared/attaform.Cghpuav8.mjs.map +0 -1
- package/dist/shared/attaform.CiMqJHDm.mjs +0 -1594
- package/dist/shared/attaform.CiMqJHDm.mjs.map +0 -1
- package/dist/shared/attaform.CoxJ8Qm8.cjs.map +0 -1
- package/dist/shared/attaform.CrpjyXdO.mjs.map +0 -1
- package/dist/shared/attaform.D13GMFgK.mjs +0 -32
- package/dist/shared/attaform.D13GMFgK.mjs.map +0 -1
- package/dist/shared/attaform.JBx8cfMA.cjs.map +0 -1
- package/dist/shared/attaform.OznWyOPy.cjs +0 -1600
- package/dist/shared/attaform.OznWyOPy.cjs.map +0 -1
- package/dist/shared/attaform.a3uBo-gw.mjs.map +0 -1
|
@@ -2,60 +2,33 @@
|
|
|
2
2
|
|
|
3
3
|
const compilerCore = require('@vue/compiler-core');
|
|
4
4
|
|
|
5
|
-
function getSummarizedProps
|
|
5
|
+
function getSummarizedProps(node) {
|
|
6
6
|
if (!("props" in node)) return [];
|
|
7
7
|
const props = node.props;
|
|
8
8
|
const summarizedProps = props.reduce((acc, currProp) => {
|
|
9
9
|
if (currProp.type === compilerCore.NodeTypes.ATTRIBUTE) {
|
|
10
10
|
const key2 = currProp.name;
|
|
11
11
|
const value2 = currProp.value?.content ?? "";
|
|
12
|
-
return [...acc, { key: key2, value: renderAsStatic
|
|
12
|
+
return [...acc, { key: key2, value: renderAsStatic(value2, true) }];
|
|
13
13
|
}
|
|
14
14
|
if (currProp.exp === void 0) return acc;
|
|
15
|
-
const key = currProp.arg ? getSummarizedPropValue
|
|
15
|
+
const key = currProp.arg ? getSummarizedPropValue(currProp.arg) : renderAsStatic(currProp.name, true);
|
|
16
16
|
if (typeof key !== "string") return acc;
|
|
17
|
-
const value = getSummarizedPropValue
|
|
17
|
+
const value = getSummarizedPropValue(currProp.exp);
|
|
18
18
|
return [...acc, { key, value }];
|
|
19
19
|
}, []);
|
|
20
20
|
return summarizedProps;
|
|
21
21
|
}
|
|
22
|
-
function renderAsStatic
|
|
22
|
+
function renderAsStatic(val, isStatic) {
|
|
23
23
|
return isStatic ? `"${val}"` : val;
|
|
24
24
|
}
|
|
25
|
-
function getSummarizedPropValue
|
|
25
|
+
function getSummarizedPropValue(exp) {
|
|
26
26
|
if (exp.type === compilerCore.NodeTypes.SIMPLE_EXPRESSION) {
|
|
27
|
-
return renderAsStatic
|
|
27
|
+
return renderAsStatic(exp.content, exp.isStatic);
|
|
28
28
|
}
|
|
29
29
|
return exp.children;
|
|
30
30
|
}
|
|
31
|
-
function
|
|
32
|
-
const registerValueArr = Array.isArray(registerValue) ? registerValue : [registerValue];
|
|
33
|
-
const optionValueArr = Array.isArray(optionValue) ? optionValue : [optionValue];
|
|
34
|
-
const scalarTargetArr = Array.isArray(scalarTarget) ? scalarTarget : [scalarTarget];
|
|
35
|
-
return [
|
|
36
|
-
"Array.isArray((",
|
|
37
|
-
...registerValueArr,
|
|
38
|
-
")?.innerRef?.value) ? ",
|
|
39
|
-
"(",
|
|
40
|
-
...registerValueArr,
|
|
41
|
-
")?.innerRef?.value?.includes(",
|
|
42
|
-
...optionValueArr,
|
|
43
|
-
") : ",
|
|
44
|
-
"(",
|
|
45
|
-
...registerValueArr,
|
|
46
|
-
")?.innerRef?.value instanceof Set ? (",
|
|
47
|
-
...registerValueArr,
|
|
48
|
-
")?.innerRef?.value?.has(",
|
|
49
|
-
...optionValueArr,
|
|
50
|
-
") : ",
|
|
51
|
-
"((",
|
|
52
|
-
...registerValueArr,
|
|
53
|
-
")?.innerRef?.value === (",
|
|
54
|
-
...scalarTargetArr,
|
|
55
|
-
"))"
|
|
56
|
-
];
|
|
57
|
-
}
|
|
58
|
-
function removePropsByName$1(props, propNames) {
|
|
31
|
+
function removePropsByName(props, propNames) {
|
|
59
32
|
const removePropIndices = [];
|
|
60
33
|
for (let index = 0; index < props.length; index++) {
|
|
61
34
|
const prop = props[index];
|
|
@@ -68,182 +41,62 @@ function removePropsByName$1(props, propNames) {
|
|
|
68
41
|
props.splice(index, 1);
|
|
69
42
|
}
|
|
70
43
|
}
|
|
71
|
-
function isExactKey
|
|
44
|
+
function isExactKey(summarizedKey, name) {
|
|
72
45
|
return summarizedKey === name || summarizedKey === `"${name}"`;
|
|
73
46
|
}
|
|
74
|
-
function
|
|
75
|
-
if (
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return inner.toLowerCase() === "file";
|
|
91
|
-
}
|
|
92
|
-
const inputTextAreaNodeTransform = (node) => {
|
|
93
|
-
try {
|
|
94
|
-
let computeProps = function(_node, registerSummarizedProp2, elementValueSummarizedProp2) {
|
|
95
|
-
const injectedLoc = _node.loc;
|
|
96
|
-
const props = _node.props;
|
|
97
|
-
const isStaticCheckbox = typeProp !== void 0 && isStaticTypeOneOf(typeProp.value, ["checkbox"]);
|
|
98
|
-
const isStaticRadio = typeProp !== void 0 && isStaticTypeOneOf(typeProp.value, ["radio"]);
|
|
99
|
-
const keepStaticValue = isStaticCheckbox || isStaticRadio;
|
|
100
|
-
removePropsByName$1(props, keepStaticValue ? ["checked"] : ["checked", "value"]);
|
|
101
|
-
const registerValueArr = Array.isArray(registerSummarizedProp2.value) ? registerSummarizedProp2.value : [registerSummarizedProp2.value];
|
|
102
|
-
const valueExpression = compilerCore.createCompoundExpression([
|
|
103
|
-
"(",
|
|
104
|
-
...registerValueArr,
|
|
105
|
-
")?.displayValue?.value"
|
|
106
|
-
]);
|
|
107
|
-
const trueValueIndex = elementProps.findIndex((p) => isExactKey$1(p.key, "true-value"));
|
|
108
|
-
const trueValueProp = elementProps[trueValueIndex];
|
|
109
|
-
const scalarTarget = isStaticCheckbox ? trueValueProp !== void 0 ? trueValueProp.value : "true" : elementValueSummarizedProp2.value;
|
|
110
|
-
const valueOrCheckedProp = {
|
|
111
|
-
// reconstruct the `value` attribute based on the provided v-registerer, now that the computation is complete
|
|
112
|
-
arg: elementSelectionLabelExpression,
|
|
113
|
-
exp: compilerCore.createCompoundExpression([
|
|
114
|
-
"(",
|
|
115
|
-
...elementSelectionLabelExpression.children,
|
|
116
|
-
") === 'checked' ? (",
|
|
117
|
-
// resolves to a boolean
|
|
118
|
-
...generateEqualityExpression$1(
|
|
119
|
-
registerSummarizedProp2.value,
|
|
120
|
-
elementValueSummarizedProp2.value,
|
|
121
|
-
scalarTarget
|
|
122
|
-
),
|
|
123
|
-
") : (",
|
|
124
|
-
// resolves to the provided register value
|
|
125
|
-
...valueExpression.children,
|
|
126
|
-
")"
|
|
127
|
-
]),
|
|
128
|
-
name: "bind",
|
|
129
|
-
modifiers: [],
|
|
130
|
-
type: compilerCore.NodeTypes.DIRECTIVE,
|
|
131
|
-
loc: injectedLoc
|
|
132
|
-
};
|
|
133
|
-
props.push(valueOrCheckedProp);
|
|
134
|
-
};
|
|
135
|
-
if (node.type !== compilerCore.NodeTypes.ELEMENT) return;
|
|
136
|
-
const isInput = node.tag === "input";
|
|
137
|
-
const isTextArea = node.tag === "textarea";
|
|
138
|
-
if (!isInput && !isTextArea) return;
|
|
139
|
-
const elementProps = getSummarizedProps$1(node);
|
|
140
|
-
const registerIndex = elementProps.findIndex((p) => isExactKey$1(p.key, "register"));
|
|
141
|
-
const registerSummarizedProp = elementProps[registerIndex];
|
|
142
|
-
if (!registerSummarizedProp) return;
|
|
143
|
-
const typeIndex = elementProps.findIndex((p) => isExactKey$1(p.key, "type"));
|
|
144
|
-
const typeProp = elementProps[typeIndex];
|
|
145
|
-
if (typeProp !== void 0 && couldResolveToFileType(typeProp.value)) return;
|
|
146
|
-
const valueIndex = elementProps.findIndex((p) => isExactKey$1(p.key, "value"));
|
|
147
|
-
const elementValueSummarizedProp = elementProps?.[valueIndex] ?? {
|
|
148
|
-
key: "value",
|
|
149
|
-
value: "''"
|
|
150
|
-
};
|
|
151
|
-
const inputTypeIndex = typeIndex;
|
|
152
|
-
const defaultSummarizedTextProp = { key: "type", value: "'text'" };
|
|
153
|
-
const inputTypeSummarizedProp = inputTypeIndex === -1 ? defaultSummarizedTextProp : elementProps[inputTypeIndex] ?? defaultSummarizedTextProp;
|
|
154
|
-
const inputTypeExpressionArray = typeof inputTypeSummarizedProp.value === "string" ? [inputTypeSummarizedProp.value] : inputTypeSummarizedProp.value;
|
|
155
|
-
const elementSelectionLabelExpression = compilerCore.createCompoundExpression([
|
|
156
|
-
"(",
|
|
157
|
-
"String((",
|
|
158
|
-
...inputTypeExpressionArray,
|
|
159
|
-
")).toLowerCase()",
|
|
160
|
-
" === 'checkbox' || ",
|
|
161
|
-
"String((",
|
|
162
|
-
...inputTypeExpressionArray,
|
|
163
|
-
")).toLowerCase() === 'radio'",
|
|
164
|
-
") ? 'checked' : 'value'"
|
|
165
|
-
]);
|
|
166
|
-
computeProps(node, registerSummarizedProp, elementValueSummarizedProp);
|
|
167
|
-
} catch (err) {
|
|
168
|
-
console.error("[attaform] input/textarea transform failed, skipping:", err);
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
function getSummarizedProps(node) {
|
|
173
|
-
if (!("props" in node)) return [];
|
|
174
|
-
const props = node.props;
|
|
175
|
-
const summarizedProps = props.reduce((acc, currProp) => {
|
|
176
|
-
if (currProp.type === compilerCore.NodeTypes.ATTRIBUTE) {
|
|
177
|
-
const key2 = currProp.name;
|
|
178
|
-
const value2 = currProp.value?.content ?? "";
|
|
179
|
-
return [...acc, { key: key2, value: renderAsStatic(value2, true) }];
|
|
47
|
+
function flattenExpression(exp) {
|
|
48
|
+
if (exp.type === compilerCore.NodeTypes.SIMPLE_EXPRESSION) return exp.content;
|
|
49
|
+
let out = "";
|
|
50
|
+
for (const child of exp.children) {
|
|
51
|
+
if (typeof child === "string") {
|
|
52
|
+
out += child;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (typeof child === "symbol") continue;
|
|
56
|
+
const node = child;
|
|
57
|
+
if (node.type === compilerCore.NodeTypes.SIMPLE_EXPRESSION) {
|
|
58
|
+
out += node.content;
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (node.type === compilerCore.NodeTypes.COMPOUND_EXPRESSION) {
|
|
62
|
+
out += flattenExpression(node);
|
|
180
63
|
}
|
|
181
|
-
if (currProp.exp === void 0) return acc;
|
|
182
|
-
const key = currProp.arg ? getSummarizedPropValue(currProp.arg) : renderAsStatic(currProp.name, true);
|
|
183
|
-
if (typeof key !== "string") return acc;
|
|
184
|
-
const value = getSummarizedPropValue(currProp.exp);
|
|
185
|
-
return [...acc, { key, value }];
|
|
186
|
-
}, []);
|
|
187
|
-
return summarizedProps;
|
|
188
|
-
}
|
|
189
|
-
function renderAsStatic(val, isStatic) {
|
|
190
|
-
return isStatic ? `"${val}"` : val;
|
|
191
|
-
}
|
|
192
|
-
function getSummarizedPropValue(exp) {
|
|
193
|
-
if (exp.type === compilerCore.NodeTypes.SIMPLE_EXPRESSION) {
|
|
194
|
-
return renderAsStatic(exp.content, exp.isStatic);
|
|
195
64
|
}
|
|
196
|
-
return
|
|
65
|
+
return out;
|
|
197
66
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
);
|
|
205
|
-
}
|
|
206
|
-
const optExpressions = _previousOptionExpressions.slice(1);
|
|
207
|
-
const noMultipleOptExpressions = optExpressions.reduce(
|
|
208
|
-
(acc, curr, index) => {
|
|
209
|
-
if (index === 0) {
|
|
210
|
-
acc.push("(");
|
|
211
|
-
}
|
|
212
|
-
acc.push(...curr);
|
|
213
|
-
if (index < optExpressions.length - 1) {
|
|
214
|
-
acc.push(" || ");
|
|
215
|
-
}
|
|
216
|
-
if (index === optExpressions.length - 1) {
|
|
217
|
-
acc.push(")");
|
|
218
|
-
}
|
|
219
|
-
return acc;
|
|
220
|
-
},
|
|
221
|
-
[]
|
|
67
|
+
|
|
68
|
+
function generateEqualityExpression$1(selectValue, optionValue, previousOptionExpressions) {
|
|
69
|
+
const multipleExpression = previousOptionExpressions?.[0];
|
|
70
|
+
if (multipleExpression === void 0) {
|
|
71
|
+
throw new Error(
|
|
72
|
+
"Programming error: `multiple` expression for `select` node not generated while transforming AST"
|
|
222
73
|
);
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
74
|
+
}
|
|
75
|
+
const optExpressions = previousOptionExpressions.slice(1);
|
|
76
|
+
const noMultipleOptExpressions = optExpressions.reduce(
|
|
77
|
+
(acc, curr, index) => {
|
|
78
|
+
if (index === 0) {
|
|
79
|
+
acc.push("(");
|
|
80
|
+
}
|
|
81
|
+
acc.push(...curr);
|
|
82
|
+
if (index < optExpressions.length - 1) {
|
|
83
|
+
acc.push(" || ");
|
|
84
|
+
}
|
|
85
|
+
if (index === optExpressions.length - 1) {
|
|
86
|
+
acc.push(")");
|
|
87
|
+
}
|
|
88
|
+
return acc;
|
|
89
|
+
},
|
|
90
|
+
[]
|
|
91
|
+
);
|
|
92
|
+
const selectValueArr = Array.isArray(selectValue) ? selectValue : [selectValue];
|
|
93
|
+
const optionValueArr = Array.isArray(optionValue) ? optionValue : [optionValue];
|
|
94
|
+
function getImplicitTrueMultipleExpression(expression) {
|
|
95
|
+
if (expression.length === 1 && expression[0] === "") return [`true`];
|
|
96
|
+
return expression;
|
|
97
|
+
}
|
|
98
|
+
previousOptionExpressions.push(["(", ...selectValueArr, ") === (", ...optionValueArr, ")"]);
|
|
99
|
+
if (!noMultipleOptExpressions.length) {
|
|
247
100
|
return [
|
|
248
101
|
"(",
|
|
249
102
|
...getImplicitTrueMultipleExpression(multipleExpression),
|
|
@@ -251,19 +104,33 @@ function generateEqualityExpression(selectValue, optionValue, previousOptionExpr
|
|
|
251
104
|
...selectValueArr,
|
|
252
105
|
`)?.innerRef?.value?.findIndex?.(el => el === (`,
|
|
253
106
|
...optionValueArr,
|
|
254
|
-
`)) > -1) : ((`,
|
|
255
|
-
...noMultipleOptExpressions,
|
|
256
|
-
// if true, we already found the relevant option
|
|
257
|
-
`) ? false : (typeof (`,
|
|
107
|
+
`)) > -1) : (typeof (`,
|
|
258
108
|
...selectValueArr,
|
|
259
109
|
`)?.innerRef?.value !== 'object' && String((`,
|
|
260
110
|
...selectValueArr,
|
|
261
111
|
`)?.innerRef?.value) === String((`,
|
|
262
112
|
...optionValueArr,
|
|
263
|
-
`)))
|
|
113
|
+
`)))`
|
|
264
114
|
];
|
|
265
115
|
}
|
|
266
|
-
return
|
|
116
|
+
return [
|
|
117
|
+
"(",
|
|
118
|
+
...getImplicitTrueMultipleExpression(multipleExpression),
|
|
119
|
+
`) ? ((`,
|
|
120
|
+
...selectValueArr,
|
|
121
|
+
`)?.innerRef?.value?.findIndex?.(el => el === (`,
|
|
122
|
+
...optionValueArr,
|
|
123
|
+
`)) > -1) : ((`,
|
|
124
|
+
...noMultipleOptExpressions,
|
|
125
|
+
// if true, we already found the relevant option
|
|
126
|
+
`) ? false : (typeof (`,
|
|
127
|
+
...selectValueArr,
|
|
128
|
+
`)?.innerRef?.value !== 'object' && String((`,
|
|
129
|
+
...selectValueArr,
|
|
130
|
+
`)?.innerRef?.value) === String((`,
|
|
131
|
+
...optionValueArr,
|
|
132
|
+
`))))`
|
|
133
|
+
];
|
|
267
134
|
}
|
|
268
135
|
function extractMultipleFromSelectSummarizedProps(props) {
|
|
269
136
|
const multipleDirectiveIndex = props.findIndex(
|
|
@@ -277,37 +144,6 @@ function extractMultipleFromSelectSummarizedProps(props) {
|
|
|
277
144
|
const value = props[priorityIndex]?.value;
|
|
278
145
|
return typeof value === "string" ? value.replace(/'|"/g, "") : value ?? "true";
|
|
279
146
|
}
|
|
280
|
-
function removePropsByName(props, propNames) {
|
|
281
|
-
const removePropIndices = [];
|
|
282
|
-
for (let index = 0; index < props.length; index++) {
|
|
283
|
-
const prop = props[index];
|
|
284
|
-
if (!prop) continue;
|
|
285
|
-
if (propNames.includes(prop.name) || "arg" in prop && prop.arg && "content" in prop.arg && propNames.includes(prop.arg.content)) {
|
|
286
|
-
removePropIndices.push(index);
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
for (const index of removePropIndices.sort((a, z) => z - a)) {
|
|
290
|
-
props.splice(index, 1);
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
function flattenCompoundExpression(node) {
|
|
294
|
-
let result = "";
|
|
295
|
-
for (const child of node.children) {
|
|
296
|
-
if (typeof child === "string") {
|
|
297
|
-
result += child;
|
|
298
|
-
} else if (typeof child === "symbol") {
|
|
299
|
-
continue;
|
|
300
|
-
} else if (child.type === compilerCore.NodeTypes.SIMPLE_EXPRESSION) {
|
|
301
|
-
result += child.content;
|
|
302
|
-
} else if (child.type === compilerCore.NodeTypes.COMPOUND_EXPRESSION) {
|
|
303
|
-
result += flattenCompoundExpression(child);
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
return result;
|
|
307
|
-
}
|
|
308
|
-
function isExactKey(summarizedKey, name) {
|
|
309
|
-
return summarizedKey === name || summarizedKey === `"${name}"`;
|
|
310
|
-
}
|
|
311
147
|
const RECURSABLE_NODE_TYPES = /* @__PURE__ */ new Set([
|
|
312
148
|
compilerCore.NodeTypes.ELEMENT,
|
|
313
149
|
compilerCore.NodeTypes.FOR,
|
|
@@ -335,7 +171,7 @@ function inferOptionValueFromChildren(node) {
|
|
|
335
171
|
const text = only.content.trim();
|
|
336
172
|
return JSON.stringify(text);
|
|
337
173
|
}
|
|
338
|
-
const
|
|
174
|
+
const componentBridgeTransform = (node, context) => {
|
|
339
175
|
const snapshots = [];
|
|
340
176
|
const snapshotProps = (target) => {
|
|
341
177
|
if (snapshots.some((entry) => entry.target === target)) return;
|
|
@@ -373,7 +209,7 @@ const selectNodeTransform = (node, context) => {
|
|
|
373
209
|
const newProp = {
|
|
374
210
|
arg: compilerCore.createSimpleExpression("selected", true),
|
|
375
211
|
exp: compilerCore.createCompoundExpression(
|
|
376
|
-
generateEqualityExpression(
|
|
212
|
+
generateEqualityExpression$1(
|
|
377
213
|
registerSummarizedProp?.value ?? "undefined",
|
|
378
214
|
optionValueSummarizedProp?.value ?? "undefined",
|
|
379
215
|
previousOptionExpressions2
|
|
@@ -409,16 +245,13 @@ const selectNodeTransform = (node, context) => {
|
|
|
409
245
|
...valuePropExpArray,
|
|
410
246
|
")?.displayValue.value"
|
|
411
247
|
]);
|
|
412
|
-
const simpleExpression = compilerCore.createSimpleExpression(
|
|
413
|
-
flattenCompoundExpression(initExpression),
|
|
414
|
-
false
|
|
415
|
-
);
|
|
248
|
+
const simpleExpression = compilerCore.createSimpleExpression(flattenExpression(initExpression), false);
|
|
416
249
|
let outputExp;
|
|
417
250
|
try {
|
|
418
251
|
outputExp = compilerCore.processExpression(simpleExpression, { ...context, prefixIdentifiers: false });
|
|
419
252
|
} catch (err) {
|
|
420
253
|
console.error(
|
|
421
|
-
"[attaform]
|
|
254
|
+
"[attaform] component-bridge transform: processExpression failed; falling back to the unprocessed expression.",
|
|
422
255
|
err
|
|
423
256
|
);
|
|
424
257
|
outputExp = simpleExpression;
|
|
@@ -462,7 +295,134 @@ const selectNodeTransform = (node, context) => {
|
|
|
462
295
|
for (const { target, snapshot } of snapshots.slice().reverse()) {
|
|
463
296
|
target.splice(0, target.length, ...snapshot);
|
|
464
297
|
}
|
|
465
|
-
console.error("[attaform]
|
|
298
|
+
console.error("[attaform] component-bridge transform failed, skipping:", err);
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
function generateEqualityExpression(registerValue, optionValue, scalarTarget) {
|
|
303
|
+
const registerValueArr = Array.isArray(registerValue) ? registerValue : [registerValue];
|
|
304
|
+
const optionValueArr = Array.isArray(optionValue) ? optionValue : [optionValue];
|
|
305
|
+
const scalarTargetArr = Array.isArray(scalarTarget) ? scalarTarget : [scalarTarget];
|
|
306
|
+
return [
|
|
307
|
+
"Array.isArray((",
|
|
308
|
+
...registerValueArr,
|
|
309
|
+
")?.innerRef?.value) ? ",
|
|
310
|
+
"(",
|
|
311
|
+
...registerValueArr,
|
|
312
|
+
")?.innerRef?.value?.includes(",
|
|
313
|
+
...optionValueArr,
|
|
314
|
+
") : ",
|
|
315
|
+
"(",
|
|
316
|
+
...registerValueArr,
|
|
317
|
+
")?.innerRef?.value instanceof Set ? (",
|
|
318
|
+
...registerValueArr,
|
|
319
|
+
")?.innerRef?.value?.has(",
|
|
320
|
+
...optionValueArr,
|
|
321
|
+
") : ",
|
|
322
|
+
"(typeof (",
|
|
323
|
+
...registerValueArr,
|
|
324
|
+
")?.innerRef?.value !== 'object' && String((",
|
|
325
|
+
...registerValueArr,
|
|
326
|
+
")?.innerRef?.value) === String((",
|
|
327
|
+
...scalarTargetArr,
|
|
328
|
+
")))"
|
|
329
|
+
];
|
|
330
|
+
}
|
|
331
|
+
function parseStaticStringLiteral(text) {
|
|
332
|
+
const literalMatch = /^(["'`])(.*)\1$/.exec(text.trim());
|
|
333
|
+
if (literalMatch === null) return null;
|
|
334
|
+
return { quote: literalMatch[1], inner: literalMatch[2] };
|
|
335
|
+
}
|
|
336
|
+
function isStaticTypeOneOf(value, names) {
|
|
337
|
+
if (Array.isArray(value)) return false;
|
|
338
|
+
const parsed = parseStaticStringLiteral(value);
|
|
339
|
+
if (parsed === null) return false;
|
|
340
|
+
return names.includes(parsed.inner.toLowerCase());
|
|
341
|
+
}
|
|
342
|
+
function couldResolveToFileType(value) {
|
|
343
|
+
if (Array.isArray(value)) return true;
|
|
344
|
+
const parsed = parseStaticStringLiteral(value);
|
|
345
|
+
if (parsed === null) return true;
|
|
346
|
+
if (parsed.quote === "`" && parsed.inner.includes("${")) return true;
|
|
347
|
+
return parsed.inner.toLowerCase() === "file";
|
|
348
|
+
}
|
|
349
|
+
const inputTextAreaNodeTransform = (node) => {
|
|
350
|
+
try {
|
|
351
|
+
let computeProps = function(_node, registerSummarizedProp2, elementValueSummarizedProp2) {
|
|
352
|
+
const injectedLoc = _node.loc;
|
|
353
|
+
const props = _node.props;
|
|
354
|
+
const isStaticCheckbox = typeProp !== void 0 && isStaticTypeOneOf(typeProp.value, ["checkbox"]);
|
|
355
|
+
const isStaticRadio = typeProp !== void 0 && isStaticTypeOneOf(typeProp.value, ["radio"]);
|
|
356
|
+
const keepStaticValue = isStaticCheckbox || isStaticRadio;
|
|
357
|
+
removePropsByName(props, keepStaticValue ? ["checked"] : ["checked", "value"]);
|
|
358
|
+
const registerValueArr = Array.isArray(registerSummarizedProp2.value) ? registerSummarizedProp2.value : [registerSummarizedProp2.value];
|
|
359
|
+
const valueExpression = compilerCore.createCompoundExpression([
|
|
360
|
+
"(",
|
|
361
|
+
...registerValueArr,
|
|
362
|
+
")?.displayValue?.value"
|
|
363
|
+
]);
|
|
364
|
+
const trueValueIndex = elementProps.findIndex((p) => isExactKey(p.key, "true-value"));
|
|
365
|
+
const trueValueProp = elementProps[trueValueIndex];
|
|
366
|
+
const scalarTarget = isStaticCheckbox ? trueValueProp !== void 0 ? trueValueProp.value : "true" : elementValueSummarizedProp2.value;
|
|
367
|
+
const valueOrCheckedProp = {
|
|
368
|
+
// reconstruct the `value` attribute based on the provided v-registerer, now that the computation is complete
|
|
369
|
+
arg: elementSelectionLabelExpression,
|
|
370
|
+
exp: compilerCore.createCompoundExpression([
|
|
371
|
+
"(",
|
|
372
|
+
...elementSelectionLabelExpression.children,
|
|
373
|
+
") === 'checked' ? (",
|
|
374
|
+
// resolves to a boolean
|
|
375
|
+
...generateEqualityExpression(
|
|
376
|
+
registerSummarizedProp2.value,
|
|
377
|
+
elementValueSummarizedProp2.value,
|
|
378
|
+
scalarTarget
|
|
379
|
+
),
|
|
380
|
+
") : (",
|
|
381
|
+
// resolves to the provided register value
|
|
382
|
+
...valueExpression.children,
|
|
383
|
+
")"
|
|
384
|
+
]),
|
|
385
|
+
name: "bind",
|
|
386
|
+
modifiers: [],
|
|
387
|
+
type: compilerCore.NodeTypes.DIRECTIVE,
|
|
388
|
+
loc: injectedLoc
|
|
389
|
+
};
|
|
390
|
+
props.push(valueOrCheckedProp);
|
|
391
|
+
};
|
|
392
|
+
if (node.type !== compilerCore.NodeTypes.ELEMENT) return;
|
|
393
|
+
const isInput = node.tag === "input";
|
|
394
|
+
const isTextArea = node.tag === "textarea";
|
|
395
|
+
if (!isInput && !isTextArea) return;
|
|
396
|
+
const elementProps = getSummarizedProps(node);
|
|
397
|
+
const registerIndex = elementProps.findIndex((p) => isExactKey(p.key, "register"));
|
|
398
|
+
const registerSummarizedProp = elementProps[registerIndex];
|
|
399
|
+
if (!registerSummarizedProp) return;
|
|
400
|
+
const typeIndex = elementProps.findIndex((p) => isExactKey(p.key, "type"));
|
|
401
|
+
const typeProp = elementProps[typeIndex];
|
|
402
|
+
if (typeProp !== void 0 && couldResolveToFileType(typeProp.value)) return;
|
|
403
|
+
const valueIndex = elementProps.findIndex((p) => isExactKey(p.key, "value"));
|
|
404
|
+
const elementValueSummarizedProp = elementProps?.[valueIndex] ?? {
|
|
405
|
+
key: "value",
|
|
406
|
+
value: "''"
|
|
407
|
+
};
|
|
408
|
+
const inputTypeIndex = typeIndex;
|
|
409
|
+
const defaultSummarizedTextProp = { key: "type", value: "'text'" };
|
|
410
|
+
const inputTypeSummarizedProp = inputTypeIndex === -1 ? defaultSummarizedTextProp : elementProps[inputTypeIndex] ?? defaultSummarizedTextProp;
|
|
411
|
+
const inputTypeExpressionArray = typeof inputTypeSummarizedProp.value === "string" ? [inputTypeSummarizedProp.value] : inputTypeSummarizedProp.value;
|
|
412
|
+
const elementSelectionLabelExpression = compilerCore.createCompoundExpression([
|
|
413
|
+
"(",
|
|
414
|
+
"String((",
|
|
415
|
+
...inputTypeExpressionArray,
|
|
416
|
+
")).toLowerCase()",
|
|
417
|
+
" === 'checkbox' || ",
|
|
418
|
+
"String((",
|
|
419
|
+
...inputTypeExpressionArray,
|
|
420
|
+
")).toLowerCase() === 'radio'",
|
|
421
|
+
") ? 'checked' : 'value'"
|
|
422
|
+
]);
|
|
423
|
+
computeProps(node, registerSummarizedProp, elementValueSummarizedProp);
|
|
424
|
+
} catch (err) {
|
|
425
|
+
console.error("[attaform] input/textarea transform failed, skipping:", err);
|
|
466
426
|
}
|
|
467
427
|
};
|
|
468
428
|
|
|
@@ -561,23 +521,6 @@ function hasVForDirective(node) {
|
|
|
561
521
|
}
|
|
562
522
|
return false;
|
|
563
523
|
}
|
|
564
|
-
function flattenExpression(exp) {
|
|
565
|
-
if (exp.type === compilerCore.NodeTypes.SIMPLE_EXPRESSION) return exp.content;
|
|
566
|
-
let out = "";
|
|
567
|
-
for (const child of exp.children) {
|
|
568
|
-
if (typeof child === "string") {
|
|
569
|
-
out += child;
|
|
570
|
-
continue;
|
|
571
|
-
}
|
|
572
|
-
if (typeof child === "symbol") continue;
|
|
573
|
-
if ("content" in child) {
|
|
574
|
-
out += child.content;
|
|
575
|
-
continue;
|
|
576
|
-
}
|
|
577
|
-
out += flattenExpression(child);
|
|
578
|
-
}
|
|
579
|
-
return out;
|
|
580
|
-
}
|
|
581
524
|
function injectPreamble(element, captured) {
|
|
582
525
|
if (hasPreamble(element)) return;
|
|
583
526
|
const callList = captured.map((source) => `(()=>{try{(${source})?.markConnectedOptimistically?.()}catch{}})()`).join(", ");
|
|
@@ -615,8 +558,8 @@ function hasPreamble(element) {
|
|
|
615
558
|
return false;
|
|
616
559
|
}
|
|
617
560
|
|
|
561
|
+
exports.componentBridgeTransform = componentBridgeTransform;
|
|
618
562
|
exports.inputTextAreaNodeTransform = inputTextAreaNodeTransform;
|
|
619
|
-
exports.selectNodeTransform = selectNodeTransform;
|
|
620
563
|
exports.vRegisterHintTransform = vRegisterHintTransform;
|
|
621
564
|
exports.vRegisterPreambleTransform = vRegisterPreambleTransform;
|
|
622
|
-
//# sourceMappingURL=attaform.
|
|
565
|
+
//# sourceMappingURL=attaform.BM6YD9kZ.cjs.map
|