attaform 0.27.6 → 0.29.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/abstract.d.mts +5 -4
- package/dist/abstract.mjs +4 -3
- package/dist/chunks/fingerprint.mjs +1 -2
- package/dist/chunks/fingerprint2.mjs +2 -3
- package/dist/dev/abstract.mjs +4 -0
- package/dist/{chunks → dev/chunks}/dev-key-collision-warnings.mjs +0 -1
- package/dist/{chunks → dev/chunks}/devtools.mjs +5 -6
- package/dist/{chunks/fingerprint.cjs → dev/chunks/fingerprint.mjs} +7 -10
- package/dist/{chunks/fingerprint2.cjs → dev/chunks/fingerprint2.mjs} +32 -35
- package/dist/dev/directive.mjs +1 -0
- package/dist/dev/history.mjs +89 -0
- package/dist/dev/index.mjs +5 -0
- package/dist/dev/runtime/plugins/attaform.mjs +40 -0
- package/dist/dev/shared/attaform-dev.A-TpJW0B.mjs +207 -0
- package/dist/dev/shared/attaform-dev.BO-71R54.mjs +820 -0
- package/dist/{shared/attaform.D6tk90Rc.cjs → dev/shared/attaform-dev.BgM6FdtA.mjs} +324 -73
- package/dist/dev/shared/attaform-dev.ButTkwHd.mjs +375 -0
- package/dist/{shared/attaform.BJGA_UOS.mjs → dev/shared/attaform-dev.BxfsuwBR.mjs} +8 -1
- package/dist/{shared/attaform.nMaz2C5P.mjs → dev/shared/attaform-dev.D8aoKb89.mjs} +190 -400
- package/dist/dev/shared/attaform-dev.DD5m2W51.mjs +220 -0
- package/dist/{shared/attaform.CKH2lGdL.mjs → dev/shared/attaform-dev.DHuydLAC.mjs} +3867 -4731
- package/dist/{shared/attaform.DYEr28Pt.mjs → dev/shared/attaform-dev.DrzObAZo.mjs} +6 -7
- package/dist/{shared/attaform.B1ZYt2Li.mjs → dev/shared/attaform-dev.q6UutkCx.mjs} +274 -672
- package/dist/dev/zod-v3.mjs +17 -0
- package/dist/dev/zod-v4.mjs +16 -0
- package/dist/dev/zod.mjs +5 -0
- package/dist/directive.d.mts +20 -0
- package/dist/directive.mjs +1 -0
- package/dist/esbuild.mjs +0 -1
- package/dist/history.d.mts +59 -0
- package/dist/history.mjs +89 -0
- package/dist/index.d.mts +14 -6
- package/dist/index.mjs +5 -4
- package/dist/nuxt.d.mts +10 -10
- package/dist/nuxt.mjs +5 -2
- package/dist/rollup.mjs +0 -1
- package/dist/rspack.d.mts +6 -1
- package/dist/rspack.mjs +0 -1
- package/dist/runtime/components/AttaformDevtoolsPanel.vue +9 -8
- package/dist/runtime/plugins/attaform.mjs +1 -2
- package/dist/shared/{attaform.CoR4mWfv.mjs → attaform.B0dKL8ST.mjs} +309 -46
- package/dist/shared/{attaform.Cs2Rbdlo.mjs → attaform.BK0cgu2K.mjs} +123 -140
- package/dist/shared/{attaform.B9Wyhfro.cjs → attaform.BndjUUYX.mjs} +11 -16
- package/dist/shared/{attaform.CQN9R62B.cjs → attaform.BxfsuwBR.mjs} +9 -4
- package/dist/shared/attaform.C2MVyuxC.mjs +811 -0
- package/dist/shared/{attaform.Fp3sCrVs.d.ts → attaform.CIWLMY-R.d.mts} +2 -2
- package/dist/shared/attaform.CZMAYwSK.mjs +6383 -0
- package/dist/shared/attaform.CZYt_5N_.mjs +207 -0
- package/dist/shared/{attaform.DniawQLP.d.cts → attaform.CsoeRi3P.d.mts} +490 -98
- package/dist/shared/attaform.Cvao8bW5.mjs +358 -0
- package/dist/shared/attaform.D0x-qSXm.mjs +197 -0
- package/dist/shared/{attaform.D8kliaKw.cjs → attaform.D1fnTifF.mjs} +279 -692
- package/dist/shared/{attaform.CHlJLAiv.d.mts → attaform.DDtqHYv1.d.mts} +155 -184
- package/dist/shared/{attaform.Biytrv0-.cjs → attaform.DffRL5pP.mjs} +215 -547
- package/dist/shared/attaform.DhnPb6nK.mjs +0 -1
- package/dist/shared/attaform.KvlEedlF.mjs +0 -1
- package/dist/shared/attaform.axHXVQO7.d.mts +44 -0
- package/dist/shared/attaform.v0fQtWyA.mjs +0 -1
- package/dist/transforms.d.mts +0 -22
- package/dist/transforms.mjs +1 -2
- package/dist/vite.d.mts +30 -9
- package/dist/vite.mjs +27 -4
- package/dist/webpack.d.mts +6 -1
- package/dist/webpack.mjs +0 -1
- package/dist/zod-v3.d.mts +13 -6
- package/dist/zod-v3.mjs +17 -4
- package/dist/zod-v4.d.mts +19 -26
- package/dist/zod-v4.mjs +16 -4
- package/dist/zod.d.mts +4 -3
- package/dist/zod.mjs +5 -4
- package/package.json +38 -20
- package/skills/attaform/SKILL.md +6 -2
- package/skills/attaform/references/custom-components.md +7 -2
- package/skills/attaform/references/errors.md +8 -3
- package/skills/attaform/references/saving.md +77 -0
- package/skills/attaform/references/wizards.md +10 -8
- package/dist/abstract.cjs +0 -48
- package/dist/abstract.cjs.map +0 -1
- package/dist/abstract.d.cts +0 -42
- package/dist/abstract.d.ts +0 -42
- package/dist/abstract.mjs.map +0 -1
- package/dist/chunks/dev-key-collision-warnings.cjs +0 -25
- package/dist/chunks/dev-key-collision-warnings.cjs.map +0 -1
- package/dist/chunks/dev-key-collision-warnings.mjs.map +0 -1
- package/dist/chunks/devtools.cjs +0 -157
- package/dist/chunks/devtools.cjs.map +0 -1
- package/dist/chunks/devtools.mjs.map +0 -1
- package/dist/chunks/fingerprint.cjs.map +0 -1
- package/dist/chunks/fingerprint.mjs.map +0 -1
- package/dist/chunks/fingerprint2.cjs.map +0 -1
- package/dist/chunks/fingerprint2.mjs.map +0 -1
- package/dist/esbuild.cjs +0 -28
- package/dist/esbuild.cjs.map +0 -1
- package/dist/esbuild.d.cts +0 -56
- package/dist/esbuild.d.ts +0 -56
- package/dist/esbuild.mjs.map +0 -1
- package/dist/index.cjs +0 -51
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -249
- package/dist/index.d.ts +0 -249
- package/dist/index.mjs.map +0 -1
- package/dist/nuxt.cjs +0 -84
- package/dist/nuxt.cjs.map +0 -1
- package/dist/nuxt.d.cts +0 -66
- package/dist/nuxt.d.ts +0 -66
- package/dist/nuxt.mjs.map +0 -1
- package/dist/rollup.cjs +0 -24
- package/dist/rollup.cjs.map +0 -1
- package/dist/rollup.d.cts +0 -35
- package/dist/rollup.d.ts +0 -35
- package/dist/rollup.mjs.map +0 -1
- package/dist/rspack.cjs +0 -10
- package/dist/rspack.cjs.map +0 -1
- package/dist/rspack.d.cts +0 -40
- package/dist/rspack.d.ts +0 -40
- package/dist/rspack.mjs.map +0 -1
- package/dist/runtime/components/AttaformDevtoolsPanel.vue.d.ts +0 -7
- package/dist/runtime/components/DevtoolsValueTree.vue.d.ts +0 -35
- package/dist/runtime/plugins/attaform.cjs +0 -43
- package/dist/runtime/plugins/attaform.cjs.map +0 -1
- package/dist/runtime/plugins/attaform.d.cts +0 -5
- package/dist/runtime/plugins/attaform.d.ts +0 -5
- package/dist/runtime/plugins/attaform.mjs.map +0 -1
- package/dist/shared/attaform.B1ZYt2Li.mjs.map +0 -1
- package/dist/shared/attaform.B9Wyhfro.cjs.map +0 -1
- package/dist/shared/attaform.BGDV42hI.d.cts +0 -232
- package/dist/shared/attaform.BJGA_UOS.mjs.map +0 -1
- package/dist/shared/attaform.Biytrv0-.cjs.map +0 -1
- package/dist/shared/attaform.Bn0IzhD_.cjs +0 -800
- package/dist/shared/attaform.Bn0IzhD_.cjs.map +0 -1
- package/dist/shared/attaform.C9fPTxjB.d.cts +0 -41
- package/dist/shared/attaform.C9fPTxjB.d.ts +0 -41
- package/dist/shared/attaform.CKH2lGdL.mjs.map +0 -1
- package/dist/shared/attaform.CQN9R62B.cjs.map +0 -1
- package/dist/shared/attaform.CoR4mWfv.mjs.map +0 -1
- package/dist/shared/attaform.Cs2Rbdlo.mjs.map +0 -1
- package/dist/shared/attaform.D6tk90Rc.cjs.map +0 -1
- package/dist/shared/attaform.D8kliaKw.cjs.map +0 -1
- package/dist/shared/attaform.DLknk9nF.d.mts +0 -232
- package/dist/shared/attaform.DMxM2kol.mjs +0 -1275
- package/dist/shared/attaform.DMxM2kol.mjs.map +0 -1
- package/dist/shared/attaform.DRUT703x.d.cts +0 -56
- package/dist/shared/attaform.DRUT703x.d.ts +0 -56
- package/dist/shared/attaform.DYEr28Pt.mjs.map +0 -1
- package/dist/shared/attaform.DdQN7sgN.cjs +0 -1302
- package/dist/shared/attaform.DdQN7sgN.cjs.map +0 -1
- package/dist/shared/attaform.DhnPb6nK.mjs.map +0 -1
- package/dist/shared/attaform.DniawQLP.d.mts +0 -4763
- package/dist/shared/attaform.DniawQLP.d.ts +0 -4763
- package/dist/shared/attaform.DoQm_Vkd.cjs +0 -58
- package/dist/shared/attaform.DoQm_Vkd.cjs.map +0 -1
- package/dist/shared/attaform.DrvMscNX.cjs +0 -7697
- package/dist/shared/attaform.DrvMscNX.cjs.map +0 -1
- package/dist/shared/attaform.F2Q8iv38.d.ts +0 -2494
- package/dist/shared/attaform.FmqKO1Ex.d.cts +0 -2494
- package/dist/shared/attaform.KvlEedlF.mjs.map +0 -1
- package/dist/shared/attaform.RaTzp1WF.cjs +0 -26
- package/dist/shared/attaform.RaTzp1WF.cjs.map +0 -1
- package/dist/shared/attaform.nMaz2C5P.mjs.map +0 -1
- package/dist/shared/attaform.v0fQtWyA.mjs.map +0 -1
- package/dist/shared/attaform.yUrz7C2z.cjs +0 -29
- package/dist/shared/attaform.yUrz7C2z.cjs.map +0 -1
- package/dist/transforms.cjs +0 -12
- package/dist/transforms.cjs.map +0 -1
- package/dist/transforms.d.cts +0 -73
- package/dist/transforms.d.ts +0 -73
- package/dist/transforms.mjs.map +0 -1
- package/dist/vite.cjs +0 -363
- package/dist/vite.cjs.map +0 -1
- package/dist/vite.d.cts +0 -133
- package/dist/vite.d.ts +0 -133
- package/dist/vite.mjs.map +0 -1
- package/dist/webpack.cjs +0 -10
- package/dist/webpack.cjs.map +0 -1
- package/dist/webpack.d.cts +0 -37
- package/dist/webpack.d.ts +0 -37
- package/dist/webpack.mjs.map +0 -1
- package/dist/zod-v3.cjs +0 -53
- package/dist/zod-v3.cjs.map +0 -1
- package/dist/zod-v3.d.cts +0 -246
- package/dist/zod-v3.d.ts +0 -246
- package/dist/zod-v3.mjs.map +0 -1
- package/dist/zod-v4.cjs +0 -55
- package/dist/zod-v4.cjs.map +0 -1
- package/dist/zod-v4.d.cts +0 -172
- package/dist/zod-v4.d.ts +0 -172
- package/dist/zod-v4.mjs.map +0 -1
- package/dist/zod.cjs +0 -51
- package/dist/zod.cjs.map +0 -1
- package/dist/zod.d.cts +0 -7
- package/dist/zod.d.ts +0 -7
- package/dist/zod.mjs.map +0 -1
|
@@ -1,800 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const compilerCore = require('@vue/compiler-core');
|
|
4
|
-
const registerProtocol = require('./attaform.yUrz7C2z.cjs');
|
|
5
|
-
|
|
6
|
-
function getSummarizedProps(node) {
|
|
7
|
-
if (!("props" in node)) return [];
|
|
8
|
-
const props = node.props;
|
|
9
|
-
const summarizedProps = props.reduce((acc, currProp) => {
|
|
10
|
-
if (currProp.type === compilerCore.NodeTypes.ATTRIBUTE) {
|
|
11
|
-
const key2 = currProp.name;
|
|
12
|
-
const value2 = currProp.value?.content ?? "";
|
|
13
|
-
return [...acc, { key: key2, value: renderAsStatic(value2, true) }];
|
|
14
|
-
}
|
|
15
|
-
if (currProp.exp === void 0) return acc;
|
|
16
|
-
const key = currProp.arg ? getSummarizedPropValue(currProp.arg) : renderAsStatic(currProp.name, true);
|
|
17
|
-
if (typeof key !== "string") return acc;
|
|
18
|
-
const value = getSummarizedPropValue(currProp.exp);
|
|
19
|
-
return [...acc, { key, value }];
|
|
20
|
-
}, []);
|
|
21
|
-
return summarizedProps;
|
|
22
|
-
}
|
|
23
|
-
function renderAsStatic(val, isStatic) {
|
|
24
|
-
return isStatic ? `"${val}"` : val;
|
|
25
|
-
}
|
|
26
|
-
function getSummarizedPropValue(exp) {
|
|
27
|
-
if (exp.type === compilerCore.NodeTypes.SIMPLE_EXPRESSION) {
|
|
28
|
-
return renderAsStatic(exp.content, exp.isStatic);
|
|
29
|
-
}
|
|
30
|
-
return exp.children;
|
|
31
|
-
}
|
|
32
|
-
function removePropsByName(props, propNames) {
|
|
33
|
-
const removePropIndices = [];
|
|
34
|
-
for (let index = 0; index < props.length; index++) {
|
|
35
|
-
const prop = props[index];
|
|
36
|
-
if (!prop) continue;
|
|
37
|
-
if (propNames.includes(prop.name) || "arg" in prop && prop.arg && "content" in prop.arg && propNames.includes(prop.arg.content)) {
|
|
38
|
-
removePropIndices.push(index);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
for (const index of removePropIndices.sort((a, z) => z - a)) {
|
|
42
|
-
props.splice(index, 1);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
function isExactKey(summarizedKey, name) {
|
|
46
|
-
return summarizedKey === name || summarizedKey === `"${name}"`;
|
|
47
|
-
}
|
|
48
|
-
function flattenExpression(exp) {
|
|
49
|
-
if (exp.type === compilerCore.NodeTypes.SIMPLE_EXPRESSION) return exp.content;
|
|
50
|
-
let out = "";
|
|
51
|
-
for (const child of exp.children) {
|
|
52
|
-
if (typeof child === "string") {
|
|
53
|
-
out += child;
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
if (typeof child === "symbol") continue;
|
|
57
|
-
const node = child;
|
|
58
|
-
if (node.type === compilerCore.NodeTypes.SIMPLE_EXPRESSION) {
|
|
59
|
-
out += node.content;
|
|
60
|
-
continue;
|
|
61
|
-
}
|
|
62
|
-
if (node.type === compilerCore.NodeTypes.COMPOUND_EXPRESSION) {
|
|
63
|
-
out += flattenExpression(node);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return out;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function generateEqualityExpression$1(selectValue, optionValue, previousOptionExpressions) {
|
|
70
|
-
const multipleExpression = previousOptionExpressions?.[0];
|
|
71
|
-
if (multipleExpression === void 0) {
|
|
72
|
-
throw new Error(
|
|
73
|
-
"Programming error: `multiple` expression for `select` node not generated while transforming AST"
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
const optExpressions = previousOptionExpressions.slice(1);
|
|
77
|
-
const noMultipleOptExpressions = optExpressions.reduce(
|
|
78
|
-
(acc, curr, index) => {
|
|
79
|
-
if (index === 0) {
|
|
80
|
-
acc.push("(");
|
|
81
|
-
}
|
|
82
|
-
acc.push(...curr);
|
|
83
|
-
if (index < optExpressions.length - 1) {
|
|
84
|
-
acc.push(" || ");
|
|
85
|
-
}
|
|
86
|
-
if (index === optExpressions.length - 1) {
|
|
87
|
-
acc.push(")");
|
|
88
|
-
}
|
|
89
|
-
return acc;
|
|
90
|
-
},
|
|
91
|
-
[]
|
|
92
|
-
);
|
|
93
|
-
const selectValueArr = Array.isArray(selectValue) ? selectValue : [selectValue];
|
|
94
|
-
const optionValueArr = Array.isArray(optionValue) ? optionValue : [optionValue];
|
|
95
|
-
function getImplicitTrueMultipleExpression(expression) {
|
|
96
|
-
if (expression.length === 1 && expression[0] === "") return [`true`];
|
|
97
|
-
return expression;
|
|
98
|
-
}
|
|
99
|
-
previousOptionExpressions.push(["(", ...selectValueArr, ") === (", ...optionValueArr, ")"]);
|
|
100
|
-
if (!noMultipleOptExpressions.length) {
|
|
101
|
-
return [
|
|
102
|
-
"(",
|
|
103
|
-
...getImplicitTrueMultipleExpression(multipleExpression),
|
|
104
|
-
`) ? ((`,
|
|
105
|
-
...selectValueArr,
|
|
106
|
-
`)?.innerRef?.value?.findIndex?.(el => el === (`,
|
|
107
|
-
...optionValueArr,
|
|
108
|
-
`)) > -1) : (typeof (`,
|
|
109
|
-
...selectValueArr,
|
|
110
|
-
`)?.innerRef?.value !== 'object' && String((`,
|
|
111
|
-
...selectValueArr,
|
|
112
|
-
`)?.innerRef?.value) === String((`,
|
|
113
|
-
...optionValueArr,
|
|
114
|
-
`)))`
|
|
115
|
-
];
|
|
116
|
-
}
|
|
117
|
-
return [
|
|
118
|
-
"(",
|
|
119
|
-
...getImplicitTrueMultipleExpression(multipleExpression),
|
|
120
|
-
`) ? ((`,
|
|
121
|
-
...selectValueArr,
|
|
122
|
-
`)?.innerRef?.value?.findIndex?.(el => el === (`,
|
|
123
|
-
...optionValueArr,
|
|
124
|
-
`)) > -1) : ((`,
|
|
125
|
-
...noMultipleOptExpressions,
|
|
126
|
-
// if true, we already found the relevant option
|
|
127
|
-
`) ? false : (typeof (`,
|
|
128
|
-
...selectValueArr,
|
|
129
|
-
`)?.innerRef?.value !== 'object' && String((`,
|
|
130
|
-
...selectValueArr,
|
|
131
|
-
`)?.innerRef?.value) === String((`,
|
|
132
|
-
...optionValueArr,
|
|
133
|
-
`))))`
|
|
134
|
-
];
|
|
135
|
-
}
|
|
136
|
-
function extractMultipleFromSelectSummarizedProps(props) {
|
|
137
|
-
const multipleDirectiveIndex = props.findIndex(
|
|
138
|
-
(prop) => prop.key.replace(/"/g, `'`) === "'multiple'"
|
|
139
|
-
);
|
|
140
|
-
const multipleAttributeIndex = props.findIndex((prop) => prop.key === "multiple");
|
|
141
|
-
if (multipleDirectiveIndex === -1 && multipleAttributeIndex === -1) {
|
|
142
|
-
return "false";
|
|
143
|
-
}
|
|
144
|
-
const priorityIndex = multipleDirectiveIndex >= 0 ? multipleDirectiveIndex : multipleAttributeIndex;
|
|
145
|
-
const value = props[priorityIndex]?.value;
|
|
146
|
-
return typeof value === "string" ? value.replace(/'|"/g, "") : value ?? "true";
|
|
147
|
-
}
|
|
148
|
-
const RECURSABLE_NODE_TYPES$1 = /* @__PURE__ */ new Set([
|
|
149
|
-
compilerCore.NodeTypes.ELEMENT,
|
|
150
|
-
compilerCore.NodeTypes.FOR,
|
|
151
|
-
compilerCore.NodeTypes.IF,
|
|
152
|
-
compilerCore.NodeTypes.IF_BRANCH
|
|
153
|
-
]);
|
|
154
|
-
const NATIVE_FORM_TAGS = /* @__PURE__ */ new Set([
|
|
155
|
-
"input",
|
|
156
|
-
"textarea",
|
|
157
|
-
"select",
|
|
158
|
-
"option",
|
|
159
|
-
"form",
|
|
160
|
-
"fieldset",
|
|
161
|
-
"label",
|
|
162
|
-
"button"
|
|
163
|
-
]);
|
|
164
|
-
function inferOptionValueFromChildren(node) {
|
|
165
|
-
if (!("children" in node)) return null;
|
|
166
|
-
const children = node.children;
|
|
167
|
-
if (children.length !== 1) return null;
|
|
168
|
-
const only = children[0];
|
|
169
|
-
if (only === void 0) return null;
|
|
170
|
-
if (typeof only === "string" || typeof only === "symbol") return null;
|
|
171
|
-
if (only.type !== compilerCore.NodeTypes.TEXT) return null;
|
|
172
|
-
const text = only.content.trim();
|
|
173
|
-
return JSON.stringify(text);
|
|
174
|
-
}
|
|
175
|
-
const componentBridgeTransform = (node, context) => {
|
|
176
|
-
const snapshots = [];
|
|
177
|
-
const snapshotProps = (target) => {
|
|
178
|
-
if (snapshots.some((entry) => entry.target === target)) return;
|
|
179
|
-
snapshots.push({ target, snapshot: [...target] });
|
|
180
|
-
};
|
|
181
|
-
try {
|
|
182
|
-
let traverseSelectNode = function(_node, previousOptionExpressions2) {
|
|
183
|
-
const isOption = _node.type === compilerCore.NodeTypes.ELEMENT && _node.tag === "option";
|
|
184
|
-
if (!isOption) {
|
|
185
|
-
if (!RECURSABLE_NODE_TYPES$1.has(_node.type)) return;
|
|
186
|
-
const hasChildren = "children" in _node;
|
|
187
|
-
if (!hasChildren) return;
|
|
188
|
-
for (const child of _node.children) {
|
|
189
|
-
if (typeof child === "symbol" || typeof child === "string") continue;
|
|
190
|
-
if (child.type === compilerCore.NodeTypes.SIMPLE_EXPRESSION) continue;
|
|
191
|
-
traverseSelectNode(child, previousOptionExpressions2);
|
|
192
|
-
}
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
hasSlottedOptions = true;
|
|
196
|
-
const optionProps = getSummarizedProps(_node);
|
|
197
|
-
const valueIndex = optionProps.findIndex((p) => isExactKey(p.key, "value"));
|
|
198
|
-
let optionValueSummarizedProp;
|
|
199
|
-
if (valueIndex >= 0 && valueIndex < optionProps.length) {
|
|
200
|
-
optionValueSummarizedProp = optionProps[valueIndex];
|
|
201
|
-
} else {
|
|
202
|
-
const fallback = inferOptionValueFromChildren(_node);
|
|
203
|
-
if (fallback === null) {
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
optionValueSummarizedProp = { key: "value", value: fallback };
|
|
207
|
-
}
|
|
208
|
-
const props = _node.props;
|
|
209
|
-
snapshotProps(props);
|
|
210
|
-
removePropsByName(props, ["selected"]);
|
|
211
|
-
const newProp = {
|
|
212
|
-
arg: compilerCore.createSimpleExpression("selected", true),
|
|
213
|
-
exp: compilerCore.createCompoundExpression(
|
|
214
|
-
generateEqualityExpression$1(
|
|
215
|
-
registerSummarizedProp?.value ?? "undefined",
|
|
216
|
-
optionValueSummarizedProp?.value ?? "undefined",
|
|
217
|
-
previousOptionExpressions2
|
|
218
|
-
)
|
|
219
|
-
),
|
|
220
|
-
name: "bind",
|
|
221
|
-
modifiers: [],
|
|
222
|
-
type: compilerCore.NodeTypes.DIRECTIVE,
|
|
223
|
-
loc: _node.loc
|
|
224
|
-
};
|
|
225
|
-
props.push(newProp);
|
|
226
|
-
};
|
|
227
|
-
const isSelect = node.type === compilerCore.NodeTypes.ELEMENT && node.tag === "select";
|
|
228
|
-
const isCustomComponent = node.type === compilerCore.NodeTypes.ELEMENT && node.tagType === compilerCore.ElementTypes.COMPONENT;
|
|
229
|
-
const isKebabCustomElement = node.type === compilerCore.NodeTypes.ELEMENT && node.tagType === compilerCore.ElementTypes.ELEMENT && node.tag.includes("-") && !NATIVE_FORM_TAGS.has(node.tag);
|
|
230
|
-
if (!(isSelect || isCustomComponent || isKebabCustomElement)) return;
|
|
231
|
-
const selectSummarizedProps = getSummarizedProps(node);
|
|
232
|
-
const registerIndex = selectSummarizedProps.findIndex((p) => isExactKey(p.key, "register"));
|
|
233
|
-
if (selectSummarizedProps.length === 0 || registerIndex < 0 || registerIndex >= selectSummarizedProps.length)
|
|
234
|
-
return;
|
|
235
|
-
const registerSummarizedProp = selectSummarizedProps[registerIndex];
|
|
236
|
-
const selectLoc = node.loc;
|
|
237
|
-
let hasSlottedOptions = false;
|
|
238
|
-
const multipleExpression = extractMultipleFromSelectSummarizedProps(selectSummarizedProps);
|
|
239
|
-
const previousOptionExpressions = typeof multipleExpression === "string" ? [[multipleExpression]] : [multipleExpression];
|
|
240
|
-
for (const child of node.children) {
|
|
241
|
-
traverseSelectNode(child, previousOptionExpressions);
|
|
242
|
-
}
|
|
243
|
-
const isStaticallyNonMultiple = multipleExpression === "false";
|
|
244
|
-
const isComponentHost = isCustomComponent || isKebabCustomElement;
|
|
245
|
-
const isSelectLikeHost = isSelect || isComponentHost && hasSlottedOptions;
|
|
246
|
-
const isPlainComponentHost = isComponentHost && !hasSlottedOptions;
|
|
247
|
-
const selectProps = node.props;
|
|
248
|
-
snapshotProps(selectProps);
|
|
249
|
-
removePropsByName(selectProps, ["value"]);
|
|
250
|
-
if (isStaticallyNonMultiple && isSelectLikeHost) {
|
|
251
|
-
const valuePropExpArray = Array.isArray(registerSummarizedProp?.value) ? registerSummarizedProp.value : [registerSummarizedProp?.value ?? "undefined"];
|
|
252
|
-
const initExpression = compilerCore.createCompoundExpression([
|
|
253
|
-
"(",
|
|
254
|
-
...valuePropExpArray,
|
|
255
|
-
")?.displayValue.value"
|
|
256
|
-
]);
|
|
257
|
-
const simpleExpression = compilerCore.createSimpleExpression(flattenExpression(initExpression), false);
|
|
258
|
-
let outputExp;
|
|
259
|
-
try {
|
|
260
|
-
outputExp = compilerCore.processExpression(simpleExpression, { ...context, prefixIdentifiers: false });
|
|
261
|
-
} catch (err) {
|
|
262
|
-
console.error(
|
|
263
|
-
"[attaform] component-bridge transform: processExpression failed; falling back to the unprocessed expression.",
|
|
264
|
-
err
|
|
265
|
-
);
|
|
266
|
-
outputExp = simpleExpression;
|
|
267
|
-
}
|
|
268
|
-
const valueProp = {
|
|
269
|
-
rawName: ":value",
|
|
270
|
-
arg: compilerCore.createSimpleExpression("value", true),
|
|
271
|
-
exp: outputExp,
|
|
272
|
-
name: "bind",
|
|
273
|
-
modifiers: [],
|
|
274
|
-
type: compilerCore.NodeTypes.DIRECTIVE,
|
|
275
|
-
loc: selectLoc
|
|
276
|
-
};
|
|
277
|
-
node.props.push(valueProp);
|
|
278
|
-
}
|
|
279
|
-
if (isPlainComponentHost) {
|
|
280
|
-
removePropsByName(node.props, [
|
|
281
|
-
"model",
|
|
282
|
-
"modelValue",
|
|
283
|
-
"onUpdate:modelValue",
|
|
284
|
-
"update:modelValue"
|
|
285
|
-
]);
|
|
286
|
-
const modelValuePropExpArray = Array.isArray(registerSummarizedProp?.value) ? registerSummarizedProp.value : [registerSummarizedProp?.value ?? "undefined"];
|
|
287
|
-
const modelInitExpression = compilerCore.createCompoundExpression([
|
|
288
|
-
"(",
|
|
289
|
-
...modelValuePropExpArray,
|
|
290
|
-
")?.hostModelValue?.value"
|
|
291
|
-
]);
|
|
292
|
-
const modelSimpleExpression = compilerCore.createSimpleExpression(
|
|
293
|
-
flattenExpression(modelInitExpression),
|
|
294
|
-
false
|
|
295
|
-
);
|
|
296
|
-
let modelOutputExp;
|
|
297
|
-
try {
|
|
298
|
-
modelOutputExp = compilerCore.processExpression(modelSimpleExpression, {
|
|
299
|
-
...context,
|
|
300
|
-
prefixIdentifiers: false
|
|
301
|
-
});
|
|
302
|
-
} catch (err) {
|
|
303
|
-
console.error(
|
|
304
|
-
"[attaform] component-bridge transform: processExpression failed for :modelValue; falling back to the unprocessed expression.",
|
|
305
|
-
err
|
|
306
|
-
);
|
|
307
|
-
modelOutputExp = modelSimpleExpression;
|
|
308
|
-
}
|
|
309
|
-
const modelValueProp = {
|
|
310
|
-
rawName: ":modelValue",
|
|
311
|
-
arg: compilerCore.createSimpleExpression("modelValue", true),
|
|
312
|
-
exp: modelOutputExp,
|
|
313
|
-
name: "bind",
|
|
314
|
-
modifiers: [],
|
|
315
|
-
type: compilerCore.NodeTypes.DIRECTIVE,
|
|
316
|
-
loc: selectLoc
|
|
317
|
-
};
|
|
318
|
-
node.props.push(modelValueProp);
|
|
319
|
-
const updateInitExpression = compilerCore.createCompoundExpression([
|
|
320
|
-
"$event => (",
|
|
321
|
-
...modelValuePropExpArray,
|
|
322
|
-
")?.setValueFromHost?.($event)"
|
|
323
|
-
]);
|
|
324
|
-
const updateSimpleExpression = compilerCore.createSimpleExpression(
|
|
325
|
-
flattenExpression(updateInitExpression),
|
|
326
|
-
false
|
|
327
|
-
);
|
|
328
|
-
let updateOutputExp;
|
|
329
|
-
try {
|
|
330
|
-
updateOutputExp = compilerCore.processExpression(updateSimpleExpression, {
|
|
331
|
-
...context,
|
|
332
|
-
prefixIdentifiers: false
|
|
333
|
-
});
|
|
334
|
-
} catch (err) {
|
|
335
|
-
console.error(
|
|
336
|
-
"[attaform] component-bridge transform: processExpression failed for onUpdate:modelValue; falling back to the unprocessed expression.",
|
|
337
|
-
err
|
|
338
|
-
);
|
|
339
|
-
updateOutputExp = updateSimpleExpression;
|
|
340
|
-
}
|
|
341
|
-
const updateModelValueProp = {
|
|
342
|
-
rawName: "@update:modelValue",
|
|
343
|
-
arg: compilerCore.createSimpleExpression("onUpdate:modelValue", true),
|
|
344
|
-
exp: updateOutputExp,
|
|
345
|
-
name: "bind",
|
|
346
|
-
modifiers: [],
|
|
347
|
-
type: compilerCore.NodeTypes.DIRECTIVE,
|
|
348
|
-
loc: selectLoc
|
|
349
|
-
};
|
|
350
|
-
node.props.push(updateModelValueProp);
|
|
351
|
-
}
|
|
352
|
-
const registerExprArray = Array.isArray(registerSummarizedProp?.value) ? registerSummarizedProp.value : [registerSummarizedProp?.value ?? "undefined"];
|
|
353
|
-
const hasAuthorDisabled = selectSummarizedProps.findIndex((p) => isExactKey(p.key, "disabled")) !== -1;
|
|
354
|
-
if (!hasAuthorDisabled) {
|
|
355
|
-
const disabledInitExpression = compilerCore.createCompoundExpression([
|
|
356
|
-
"(",
|
|
357
|
-
...registerExprArray,
|
|
358
|
-
")?.disabled?.value"
|
|
359
|
-
]);
|
|
360
|
-
const disabledSimpleExpression = compilerCore.createSimpleExpression(
|
|
361
|
-
flattenExpression(disabledInitExpression),
|
|
362
|
-
false
|
|
363
|
-
);
|
|
364
|
-
let disabledOutputExp;
|
|
365
|
-
try {
|
|
366
|
-
disabledOutputExp = compilerCore.processExpression(disabledSimpleExpression, {
|
|
367
|
-
...context,
|
|
368
|
-
prefixIdentifiers: false
|
|
369
|
-
});
|
|
370
|
-
} catch (err) {
|
|
371
|
-
console.error(
|
|
372
|
-
"[attaform] component-bridge transform: processExpression failed for :disabled; falling back to the unprocessed expression.",
|
|
373
|
-
err
|
|
374
|
-
);
|
|
375
|
-
disabledOutputExp = disabledSimpleExpression;
|
|
376
|
-
}
|
|
377
|
-
const disabledProp = {
|
|
378
|
-
rawName: ":disabled",
|
|
379
|
-
arg: compilerCore.createSimpleExpression("disabled", true),
|
|
380
|
-
exp: disabledOutputExp,
|
|
381
|
-
name: "bind",
|
|
382
|
-
modifiers: [],
|
|
383
|
-
type: compilerCore.NodeTypes.DIRECTIVE,
|
|
384
|
-
loc: selectLoc
|
|
385
|
-
};
|
|
386
|
-
node.props.push(disabledProp);
|
|
387
|
-
}
|
|
388
|
-
if (isSelect) {
|
|
389
|
-
return;
|
|
390
|
-
}
|
|
391
|
-
const registerProps = node.props.filter(
|
|
392
|
-
(x) => x.type === compilerCore.NodeTypes.DIRECTIVE && x.name === "register"
|
|
393
|
-
);
|
|
394
|
-
const registerProp = registerProps[0];
|
|
395
|
-
if (!registerProp) return;
|
|
396
|
-
const alreadyInjected = node.props.some(
|
|
397
|
-
(p) => p.type === compilerCore.NodeTypes.DIRECTIVE && p.name === "bind" && p.arg !== void 0 && "content" in p.arg && p.arg.content === "registerValue"
|
|
398
|
-
);
|
|
399
|
-
if (alreadyInjected) return;
|
|
400
|
-
if (registerProp.type === compilerCore.NodeTypes.DIRECTIVE && !registerProp.modifiers.some(
|
|
401
|
-
(m) => m.type === compilerCore.NodeTypes.SIMPLE_EXPRESSION && m.content === registerProtocol.SSR_COMPONENT_HOST_MODIFIER
|
|
402
|
-
)) {
|
|
403
|
-
registerProp.modifiers.push(compilerCore.createSimpleExpression(registerProtocol.SSR_COMPONENT_HOST_MODIFIER, true));
|
|
404
|
-
}
|
|
405
|
-
const customElementProp = {
|
|
406
|
-
arg: compilerCore.createSimpleExpression("registerValue", true),
|
|
407
|
-
exp: "exp" in registerProp ? registerProp.exp : compilerCore.createSimpleExpression("undefined", false),
|
|
408
|
-
name: "bind",
|
|
409
|
-
modifiers: [],
|
|
410
|
-
type: compilerCore.NodeTypes.DIRECTIVE,
|
|
411
|
-
loc: selectLoc
|
|
412
|
-
};
|
|
413
|
-
node.props.push(customElementProp);
|
|
414
|
-
} catch (err) {
|
|
415
|
-
for (const { target, snapshot } of snapshots.slice().reverse()) {
|
|
416
|
-
target.splice(0, target.length, ...snapshot);
|
|
417
|
-
}
|
|
418
|
-
console.error("[attaform] component-bridge transform failed, skipping:", err);
|
|
419
|
-
}
|
|
420
|
-
};
|
|
421
|
-
|
|
422
|
-
function generateEqualityExpression(registerValue, optionValue, scalarTarget) {
|
|
423
|
-
const registerValueArr = Array.isArray(registerValue) ? registerValue : [registerValue];
|
|
424
|
-
const optionValueArr = Array.isArray(optionValue) ? optionValue : [optionValue];
|
|
425
|
-
const scalarTargetArr = Array.isArray(scalarTarget) ? scalarTarget : [scalarTarget];
|
|
426
|
-
return [
|
|
427
|
-
"Array.isArray((",
|
|
428
|
-
...registerValueArr,
|
|
429
|
-
")?.innerRef?.value) ? ",
|
|
430
|
-
"(",
|
|
431
|
-
...registerValueArr,
|
|
432
|
-
")?.innerRef?.value?.includes(",
|
|
433
|
-
...optionValueArr,
|
|
434
|
-
") : ",
|
|
435
|
-
"(",
|
|
436
|
-
...registerValueArr,
|
|
437
|
-
")?.innerRef?.value instanceof Set ? (",
|
|
438
|
-
...registerValueArr,
|
|
439
|
-
")?.innerRef?.value?.has(",
|
|
440
|
-
...optionValueArr,
|
|
441
|
-
") : ",
|
|
442
|
-
"(typeof (",
|
|
443
|
-
...registerValueArr,
|
|
444
|
-
")?.innerRef?.value !== 'object' && String((",
|
|
445
|
-
...registerValueArr,
|
|
446
|
-
")?.innerRef?.value) === String((",
|
|
447
|
-
...scalarTargetArr,
|
|
448
|
-
")))"
|
|
449
|
-
];
|
|
450
|
-
}
|
|
451
|
-
function parseStaticStringLiteral(text) {
|
|
452
|
-
const literalMatch = /^(["'`])(.*)\1$/.exec(text.trim());
|
|
453
|
-
if (literalMatch === null) return null;
|
|
454
|
-
return { quote: literalMatch[1], inner: literalMatch[2] };
|
|
455
|
-
}
|
|
456
|
-
function isStaticTypeOneOf(value, names) {
|
|
457
|
-
if (Array.isArray(value)) return false;
|
|
458
|
-
const parsed = parseStaticStringLiteral(value);
|
|
459
|
-
if (parsed === null) return false;
|
|
460
|
-
return names.includes(parsed.inner.toLowerCase());
|
|
461
|
-
}
|
|
462
|
-
function isDynamicTypeValue(value) {
|
|
463
|
-
if (Array.isArray(value)) return true;
|
|
464
|
-
return parseStaticStringLiteral(value) === null;
|
|
465
|
-
}
|
|
466
|
-
const inputTextAreaNodeTransform = (node) => {
|
|
467
|
-
try {
|
|
468
|
-
let computeProps = function(_node, registerSummarizedProp2, elementValueSummarizedProp2) {
|
|
469
|
-
const injectedLoc = _node.loc;
|
|
470
|
-
const props = _node.props;
|
|
471
|
-
const isStaticCheckbox = typeProp !== void 0 && isStaticTypeOneOf(typeProp.value, ["checkbox"]);
|
|
472
|
-
const isStaticRadio = typeProp !== void 0 && isStaticTypeOneOf(typeProp.value, ["radio"]);
|
|
473
|
-
const isDynamicType = typeProp !== void 0 && isDynamicTypeValue(typeProp.value);
|
|
474
|
-
const keepStaticValue = isStaticCheckbox || isStaticRadio || isDynamicType;
|
|
475
|
-
removePropsByName(props, keepStaticValue ? ["checked"] : ["checked", "value"]);
|
|
476
|
-
const registerValueArr = Array.isArray(registerSummarizedProp2.value) ? registerSummarizedProp2.value : [registerSummarizedProp2.value];
|
|
477
|
-
const valueExpression = compilerCore.createCompoundExpression([
|
|
478
|
-
"(",
|
|
479
|
-
...registerValueArr,
|
|
480
|
-
")?.displayValue?.value"
|
|
481
|
-
]);
|
|
482
|
-
const trueValueIndex = elementProps.findIndex((p) => isExactKey(p.key, "true-value"));
|
|
483
|
-
const trueValueProp = elementProps[trueValueIndex];
|
|
484
|
-
const scalarTarget = isStaticCheckbox ? trueValueProp !== void 0 ? trueValueProp.value : "true" : elementValueSummarizedProp2.value;
|
|
485
|
-
const coreExpression = [
|
|
486
|
-
"(",
|
|
487
|
-
...elementSelectionLabelExpression.children,
|
|
488
|
-
") === 'checked' ? (",
|
|
489
|
-
// resolves to a boolean
|
|
490
|
-
...generateEqualityExpression(
|
|
491
|
-
registerSummarizedProp2.value,
|
|
492
|
-
elementValueSummarizedProp2.value,
|
|
493
|
-
scalarTarget
|
|
494
|
-
),
|
|
495
|
-
") : (",
|
|
496
|
-
// resolves to the provided register value
|
|
497
|
-
...valueExpression.children,
|
|
498
|
-
")"
|
|
499
|
-
];
|
|
500
|
-
const exp = isDynamicType ? compilerCore.createCompoundExpression([
|
|
501
|
-
"String((",
|
|
502
|
-
...inputTypeExpressionArray,
|
|
503
|
-
")).toLowerCase() === 'file' ? undefined : (",
|
|
504
|
-
...coreExpression,
|
|
505
|
-
")"
|
|
506
|
-
]) : compilerCore.createCompoundExpression(coreExpression);
|
|
507
|
-
const valueOrCheckedProp = {
|
|
508
|
-
// reconstruct the `value` attribute based on the provided v-registerer, now that the computation is complete
|
|
509
|
-
arg: elementSelectionLabelExpression,
|
|
510
|
-
exp,
|
|
511
|
-
name: "bind",
|
|
512
|
-
modifiers: [],
|
|
513
|
-
type: compilerCore.NodeTypes.DIRECTIVE,
|
|
514
|
-
loc: injectedLoc
|
|
515
|
-
};
|
|
516
|
-
props.push(valueOrCheckedProp);
|
|
517
|
-
const hasAuthorDisabled = elementProps.findIndex((p) => isExactKey(p.key, "disabled")) !== -1;
|
|
518
|
-
if (!hasAuthorDisabled) {
|
|
519
|
-
const disabledProp = {
|
|
520
|
-
arg: compilerCore.createSimpleExpression("disabled", true, injectedLoc),
|
|
521
|
-
exp: compilerCore.createCompoundExpression(["(", ...registerValueArr, ")?.disabled?.value"]),
|
|
522
|
-
name: "bind",
|
|
523
|
-
modifiers: [],
|
|
524
|
-
type: compilerCore.NodeTypes.DIRECTIVE,
|
|
525
|
-
loc: injectedLoc
|
|
526
|
-
};
|
|
527
|
-
props.push(disabledProp);
|
|
528
|
-
}
|
|
529
|
-
};
|
|
530
|
-
if (node.type !== compilerCore.NodeTypes.ELEMENT) return;
|
|
531
|
-
const isInput = node.tag === "input";
|
|
532
|
-
const isTextArea = node.tag === "textarea";
|
|
533
|
-
if (!isInput && !isTextArea) return;
|
|
534
|
-
const elementProps = getSummarizedProps(node);
|
|
535
|
-
const registerIndex = elementProps.findIndex((p) => isExactKey(p.key, "register"));
|
|
536
|
-
const registerSummarizedProp = elementProps[registerIndex];
|
|
537
|
-
if (!registerSummarizedProp) return;
|
|
538
|
-
const typeIndex = elementProps.findIndex((p) => isExactKey(p.key, "type"));
|
|
539
|
-
const typeProp = elementProps[typeIndex];
|
|
540
|
-
if (typeProp !== void 0 && isStaticTypeOneOf(typeProp.value, ["file"])) return;
|
|
541
|
-
const valueIndex = elementProps.findIndex((p) => isExactKey(p.key, "value"));
|
|
542
|
-
const elementValueSummarizedProp = elementProps?.[valueIndex] ?? {
|
|
543
|
-
key: "value",
|
|
544
|
-
value: "''"
|
|
545
|
-
};
|
|
546
|
-
const inputTypeIndex = typeIndex;
|
|
547
|
-
const defaultSummarizedTextProp = { key: "type", value: "'text'" };
|
|
548
|
-
const inputTypeSummarizedProp = inputTypeIndex === -1 ? defaultSummarizedTextProp : elementProps[inputTypeIndex] ?? defaultSummarizedTextProp;
|
|
549
|
-
const inputTypeExpressionArray = typeof inputTypeSummarizedProp.value === "string" ? [inputTypeSummarizedProp.value] : inputTypeSummarizedProp.value;
|
|
550
|
-
const elementSelectionLabelExpression = compilerCore.createCompoundExpression([
|
|
551
|
-
"(",
|
|
552
|
-
"String((",
|
|
553
|
-
...inputTypeExpressionArray,
|
|
554
|
-
")).toLowerCase()",
|
|
555
|
-
" === 'checkbox' || ",
|
|
556
|
-
"String((",
|
|
557
|
-
...inputTypeExpressionArray,
|
|
558
|
-
")).toLowerCase() === 'radio'",
|
|
559
|
-
") ? 'checked' : 'value'"
|
|
560
|
-
]);
|
|
561
|
-
computeProps(node, registerSummarizedProp, elementValueSummarizedProp);
|
|
562
|
-
} catch (err) {
|
|
563
|
-
console.error("[attaform] input/textarea transform failed, skipping:", err);
|
|
564
|
-
}
|
|
565
|
-
};
|
|
566
|
-
|
|
567
|
-
const RECURSABLE_NODE_TYPES = /* @__PURE__ */ new Set([
|
|
568
|
-
compilerCore.NodeTypes.ELEMENT,
|
|
569
|
-
compilerCore.NodeTypes.FOR,
|
|
570
|
-
compilerCore.NodeTypes.IF,
|
|
571
|
-
compilerCore.NodeTypes.IF_BRANCH
|
|
572
|
-
]);
|
|
573
|
-
function findRedundantStateBinding(props, stateNames) {
|
|
574
|
-
for (const prop of props) {
|
|
575
|
-
if (prop.type === compilerCore.NodeTypes.ATTRIBUTE) {
|
|
576
|
-
if (stateNames.includes(prop.name)) return prop.name;
|
|
577
|
-
continue;
|
|
578
|
-
}
|
|
579
|
-
if (prop.name === "model") return "v-model";
|
|
580
|
-
if (prop.name === "bind" && prop.arg?.type === compilerCore.NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic && stateNames.includes(prop.arg.content)) {
|
|
581
|
-
return `:${prop.arg.content}`;
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
return null;
|
|
585
|
-
}
|
|
586
|
-
function classifyInput(props) {
|
|
587
|
-
let staticType = null;
|
|
588
|
-
for (const prop of props) {
|
|
589
|
-
if (prop.type === compilerCore.NodeTypes.ATTRIBUTE) {
|
|
590
|
-
if (prop.name === "type") staticType = prop.value?.content ?? null;
|
|
591
|
-
continue;
|
|
592
|
-
}
|
|
593
|
-
if (prop.name === "bind" && prop.arg?.type === compilerCore.NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic && prop.arg.content === "type") {
|
|
594
|
-
return "dynamic";
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
if (staticType === "checkbox") return "checkbox";
|
|
598
|
-
if (staticType === "radio") return "radio";
|
|
599
|
-
if (staticType === "file") return "file";
|
|
600
|
-
return "text";
|
|
601
|
-
}
|
|
602
|
-
function emitRedundantWarning(tag, binding) {
|
|
603
|
-
console.warn(
|
|
604
|
-
`[attaform] \`${binding}\` is redundant beside v-register on <${tag}>. v-register already drives this field's value, so keep v-register alone and drop \`${binding}\`. (An identity \`:value\` on a radio or <option> is expected and stays silent.)`
|
|
605
|
-
);
|
|
606
|
-
}
|
|
607
|
-
function walkOptionsForSelected(selectNode) {
|
|
608
|
-
const visit = (candidate) => {
|
|
609
|
-
if (candidate.type === compilerCore.NodeTypes.ELEMENT && candidate.tag === "option") {
|
|
610
|
-
const found = findRedundantStateBinding(candidate.props, ["selected"]);
|
|
611
|
-
if (found !== null) emitRedundantWarning("option", found);
|
|
612
|
-
return;
|
|
613
|
-
}
|
|
614
|
-
if (!RECURSABLE_NODE_TYPES.has(candidate.type)) return;
|
|
615
|
-
if (!("children" in candidate)) return;
|
|
616
|
-
for (const child of candidate.children) {
|
|
617
|
-
if (typeof child === "string" || typeof child === "symbol") continue;
|
|
618
|
-
if (child.type === compilerCore.NodeTypes.SIMPLE_EXPRESSION) continue;
|
|
619
|
-
visit(child);
|
|
620
|
-
}
|
|
621
|
-
};
|
|
622
|
-
for (const child of selectNode.children) visit(child);
|
|
623
|
-
}
|
|
624
|
-
function warnIfRedundant(node) {
|
|
625
|
-
if (node.tagType !== compilerCore.ElementTypes.ELEMENT) return;
|
|
626
|
-
const tag = node.tag;
|
|
627
|
-
if (tag === "select") {
|
|
628
|
-
const found2 = findRedundantStateBinding(node.props, ["value"]);
|
|
629
|
-
if (found2 !== null) emitRedundantWarning("select", found2);
|
|
630
|
-
walkOptionsForSelected(node);
|
|
631
|
-
return;
|
|
632
|
-
}
|
|
633
|
-
if (tag === "textarea") {
|
|
634
|
-
const found2 = findRedundantStateBinding(node.props, ["value"]);
|
|
635
|
-
if (found2 !== null) emitRedundantWarning("textarea", found2);
|
|
636
|
-
return;
|
|
637
|
-
}
|
|
638
|
-
if (tag !== "input") return;
|
|
639
|
-
const kind = classifyInput(node.props);
|
|
640
|
-
if (kind === "dynamic" || kind === "file") return;
|
|
641
|
-
const stateNames = kind === "checkbox" || kind === "radio" ? ["checked"] : ["value"];
|
|
642
|
-
const found = findRedundantStateBinding(node.props, stateNames);
|
|
643
|
-
if (found !== null) emitRedundantWarning("input", found);
|
|
644
|
-
}
|
|
645
|
-
const redundantBindingWarnTransform = (node) => {
|
|
646
|
-
try {
|
|
647
|
-
if (node.type !== compilerCore.NodeTypes.ELEMENT) return;
|
|
648
|
-
const registerProp = node.props.find(
|
|
649
|
-
(prop) => prop.type === compilerCore.NodeTypes.DIRECTIVE && prop.name === "register"
|
|
650
|
-
);
|
|
651
|
-
if (registerProp === void 0) return;
|
|
652
|
-
const alreadyProcessed = registerProp.modifiers.some(
|
|
653
|
-
(modifier) => modifier.type === compilerCore.NodeTypes.SIMPLE_EXPRESSION && modifier.content === registerProtocol.V_REGISTER_COMPILED_MODIFIER
|
|
654
|
-
);
|
|
655
|
-
if (alreadyProcessed) return;
|
|
656
|
-
warnIfRedundant(node);
|
|
657
|
-
registerProp.modifiers.push(compilerCore.createSimpleExpression(registerProtocol.V_REGISTER_COMPILED_MODIFIER, true));
|
|
658
|
-
} catch (err) {
|
|
659
|
-
console.error("[attaform] redundant-binding warn transform failed, skipping:", err);
|
|
660
|
-
}
|
|
661
|
-
};
|
|
662
|
-
|
|
663
|
-
const HINT_MARKER = "__attaRv";
|
|
664
|
-
const HINT_PREFIX = `((${HINT_MARKER}) => (${HINT_MARKER}?.markConnectedOptimistically?.(), ${HINT_MARKER}))(`;
|
|
665
|
-
const HINT_SUFFIX = `)`;
|
|
666
|
-
const vRegisterHintTransform = (node) => {
|
|
667
|
-
try {
|
|
668
|
-
if (node.type !== compilerCore.NodeTypes.ELEMENT) return;
|
|
669
|
-
for (const prop of node.props) {
|
|
670
|
-
if (prop.type !== compilerCore.NodeTypes.DIRECTIVE) continue;
|
|
671
|
-
if (prop.name !== "register") continue;
|
|
672
|
-
if (prop.exp === void 0) continue;
|
|
673
|
-
if (isAlreadyWrapped(prop.exp)) continue;
|
|
674
|
-
prop.exp = wrapWithOptimisticHint(prop.exp);
|
|
675
|
-
}
|
|
676
|
-
} catch (err) {
|
|
677
|
-
console.error("[attaform] v-register hint transform failed, skipping:", err);
|
|
678
|
-
}
|
|
679
|
-
};
|
|
680
|
-
function isAlreadyWrapped(exp) {
|
|
681
|
-
if (exp.type === compilerCore.NodeTypes.SIMPLE_EXPRESSION) {
|
|
682
|
-
return exp.content.includes(HINT_MARKER);
|
|
683
|
-
}
|
|
684
|
-
for (const child of exp.children) {
|
|
685
|
-
if (typeof child === "string" && child.includes(HINT_MARKER)) return true;
|
|
686
|
-
}
|
|
687
|
-
return false;
|
|
688
|
-
}
|
|
689
|
-
function wrapWithOptimisticHint(exp) {
|
|
690
|
-
const innerChildren = exp.type === compilerCore.NodeTypes.SIMPLE_EXPRESSION ? [exp] : [...exp.children];
|
|
691
|
-
return compilerCore.createCompoundExpression([HINT_PREFIX, ...innerChildren, HINT_SUFFIX], exp.loc);
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
const stateByRoot = /* @__PURE__ */ new WeakMap();
|
|
695
|
-
const PREAMBLE_ATTR = "data-atta-pre-mark";
|
|
696
|
-
const vRegisterPreambleTransform = (node, context) => {
|
|
697
|
-
try {
|
|
698
|
-
if (node.type === compilerCore.NodeTypes.ROOT) {
|
|
699
|
-
if (stateByRoot.has(node)) return;
|
|
700
|
-
stateByRoot.set(node, {
|
|
701
|
-
captured: [],
|
|
702
|
-
capturedElements: /* @__PURE__ */ new WeakSet(),
|
|
703
|
-
vForDepth: 0,
|
|
704
|
-
firstRootElementVisited: false
|
|
705
|
-
});
|
|
706
|
-
return () => {
|
|
707
|
-
stateByRoot.delete(node);
|
|
708
|
-
};
|
|
709
|
-
}
|
|
710
|
-
const state = stateByRoot.get(context.root);
|
|
711
|
-
if (state === void 0) return;
|
|
712
|
-
if (node.type === compilerCore.NodeTypes.FOR) {
|
|
713
|
-
state.vForDepth += 1;
|
|
714
|
-
return () => {
|
|
715
|
-
state.vForDepth -= 1;
|
|
716
|
-
};
|
|
717
|
-
}
|
|
718
|
-
if (node.type !== compilerCore.NodeTypes.ELEMENT) return;
|
|
719
|
-
captureVRegisterIfStatic(node, state);
|
|
720
|
-
if (!state.firstRootElementVisited && context.parent?.type === compilerCore.NodeTypes.ROOT) {
|
|
721
|
-
state.firstRootElementVisited = true;
|
|
722
|
-
return () => {
|
|
723
|
-
const finalState = stateByRoot.get(context.root);
|
|
724
|
-
if (finalState === void 0 || finalState.captured.length === 0) return;
|
|
725
|
-
injectPreamble(node, finalState.captured);
|
|
726
|
-
};
|
|
727
|
-
}
|
|
728
|
-
return;
|
|
729
|
-
} catch (err) {
|
|
730
|
-
console.error("[attaform] v-register preamble transform failed, skipping:", err);
|
|
731
|
-
return;
|
|
732
|
-
}
|
|
733
|
-
};
|
|
734
|
-
function captureVRegisterIfStatic(node, state) {
|
|
735
|
-
if (state.vForDepth > 0) return;
|
|
736
|
-
if (hasVForDirective(node)) return;
|
|
737
|
-
if (state.capturedElements.has(node)) return;
|
|
738
|
-
const exp = findVRegisterExpression(node);
|
|
739
|
-
if (exp === null) return;
|
|
740
|
-
state.capturedElements.add(node);
|
|
741
|
-
state.captured.push(flattenExpression(exp));
|
|
742
|
-
}
|
|
743
|
-
function findVRegisterExpression(node) {
|
|
744
|
-
for (const prop of node.props) {
|
|
745
|
-
if (prop.type !== compilerCore.NodeTypes.DIRECTIVE) continue;
|
|
746
|
-
if (prop.name !== "register") continue;
|
|
747
|
-
if (prop.exp === void 0) continue;
|
|
748
|
-
return prop.exp;
|
|
749
|
-
}
|
|
750
|
-
return null;
|
|
751
|
-
}
|
|
752
|
-
function hasVForDirective(node) {
|
|
753
|
-
for (const prop of node.props) {
|
|
754
|
-
if (prop.type === compilerCore.NodeTypes.DIRECTIVE && prop.name === "for") return true;
|
|
755
|
-
}
|
|
756
|
-
return false;
|
|
757
|
-
}
|
|
758
|
-
function injectPreamble(element, captured) {
|
|
759
|
-
if (hasPreamble(element)) return;
|
|
760
|
-
const callList = captured.map((source) => `(()=>{try{(${source})?.markConnectedOptimistically?.()}catch{}})()`).join(", ");
|
|
761
|
-
const expressionText = `(${callList}, undefined)`;
|
|
762
|
-
const exp = compilerCore.createSimpleExpression(
|
|
763
|
-
expressionText,
|
|
764
|
-
false
|
|
765
|
-
/* not static */
|
|
766
|
-
);
|
|
767
|
-
const directive = {
|
|
768
|
-
type: compilerCore.NodeTypes.DIRECTIVE,
|
|
769
|
-
name: "bind",
|
|
770
|
-
arg: compilerCore.createSimpleExpression(
|
|
771
|
-
PREAMBLE_ATTR,
|
|
772
|
-
true
|
|
773
|
-
/* static arg */
|
|
774
|
-
),
|
|
775
|
-
exp,
|
|
776
|
-
modifiers: [],
|
|
777
|
-
// Reuse the host element's source location so any runtime error
|
|
778
|
-
// in the synthesized expression points at the consumer's template
|
|
779
|
-
// line, not at the dummyLoc that pre-fix was line 0.
|
|
780
|
-
loc: element.loc
|
|
781
|
-
};
|
|
782
|
-
element.props.unshift(directive);
|
|
783
|
-
}
|
|
784
|
-
function hasPreamble(element) {
|
|
785
|
-
for (const prop of element.props) {
|
|
786
|
-
if (prop.type !== compilerCore.NodeTypes.DIRECTIVE) continue;
|
|
787
|
-
if (prop.name !== "bind") continue;
|
|
788
|
-
if (prop.arg === void 0) continue;
|
|
789
|
-
if (prop.arg.type !== compilerCore.NodeTypes.SIMPLE_EXPRESSION) continue;
|
|
790
|
-
if (prop.arg.content === PREAMBLE_ATTR) return true;
|
|
791
|
-
}
|
|
792
|
-
return false;
|
|
793
|
-
}
|
|
794
|
-
|
|
795
|
-
exports.componentBridgeTransform = componentBridgeTransform;
|
|
796
|
-
exports.inputTextAreaNodeTransform = inputTextAreaNodeTransform;
|
|
797
|
-
exports.redundantBindingWarnTransform = redundantBindingWarnTransform;
|
|
798
|
-
exports.vRegisterHintTransform = vRegisterHintTransform;
|
|
799
|
-
exports.vRegisterPreambleTransform = vRegisterPreambleTransform;
|
|
800
|
-
//# sourceMappingURL=attaform.Bn0IzhD_.cjs.map
|