@bettercms-ai/convert 0.18.1 → 0.18.2
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/CHANGELOG.md +6 -0
- package/dist/cli.js +39 -15
- package/dist/cli.js.map +1 -1
- package/dist/index.js +36 -13
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -6498,7 +6498,7 @@ function* formsIn(nodes, chain = []) {
|
|
|
6498
6498
|
}
|
|
6499
6499
|
}
|
|
6500
6500
|
var isComponentTag = (dialect, tag) => dialect !== "html" && /^[A-Z]/.test(tag);
|
|
6501
|
-
function candidateOf(file, dialect, form, imported, landmark) {
|
|
6501
|
+
function candidateOf(file, dialect, form, imported, landmark, content) {
|
|
6502
6502
|
const controls = /* @__PURE__ */ new Map();
|
|
6503
6503
|
const wrapper = /* @__PURE__ */ new Map();
|
|
6504
6504
|
const foreign = /* @__PURE__ */ new Set();
|
|
@@ -6535,7 +6535,11 @@ function candidateOf(file, dialect, form, imported, landmark) {
|
|
|
6535
6535
|
const id = attrOf(control, "id")?.value;
|
|
6536
6536
|
if (id && !controls.has(id)) controls.set(id, control);
|
|
6537
6537
|
}
|
|
6538
|
-
|
|
6538
|
+
const computed = (attr) => !!attr?.expression && !!attr.expressionRange && /[A-Za-z_$]/.test(
|
|
6539
|
+
content.slice(attr.expressionRange.start, attr.expressionRange.end).replace(/\/\*[\s\S]*?\*\/|\/\/[^\n]*|"(?:[^"\\\n]|\\.)*"|'(?:[^'\\\n]|\\.)*'|`(?:[^`\\$]|\\.|\$(?!\{))*`/g, "")
|
|
6540
|
+
);
|
|
6541
|
+
const dynamic = all.some((control) => !foreign.has(control) && computed(attrOf(control, "name")));
|
|
6542
|
+
return { file, dialect, el: form, controls, wrapper, foreign, landmark, dynamic };
|
|
6539
6543
|
}
|
|
6540
6544
|
async function importedControls(source, parsed, dialect, project, cache) {
|
|
6541
6545
|
const out = /* @__PURE__ */ new Map();
|
|
@@ -6629,11 +6633,12 @@ async function wireForms(briefIn, sources, options_ = {}) {
|
|
|
6629
6633
|
}
|
|
6630
6634
|
const imported = dialect === "html" ? /* @__PURE__ */ new Map() : await importedControls(source, parsed, dialect, project, componentFiles);
|
|
6631
6635
|
for (const { el, landmark } of formsIn(parsed.roots)) {
|
|
6632
|
-
candidates.push(candidateOf(source.path, dialect, el, imported, landmark));
|
|
6636
|
+
candidates.push(candidateOf(source.path, dialect, el, imported, landmark, source.content));
|
|
6633
6637
|
}
|
|
6634
6638
|
}
|
|
6635
6639
|
const holds = (c, f) => f.fields.filter((field) => c.controls.has(field.key)).length;
|
|
6636
|
-
const
|
|
6640
|
+
const wiredTo = (c, f) => attrOf(c.el, "data-bcms-form")?.value === f.id;
|
|
6641
|
+
const covers2 = (c, f) => c.dynamic && wiredTo(c, f) || f.fields.length > 0 && holds(c, f) === f.fields.length;
|
|
6637
6642
|
const samePath = (a, b) => a.replace(/\\/g, "/").replace(/^\.\//, "") === b.replace(/\\/g, "/").replace(/^\.\//, "");
|
|
6638
6643
|
const options = new Map(forms.map((f) => [f.id, candidates.filter((c) => covers2(c, f))]));
|
|
6639
6644
|
const pinned = /* @__PURE__ */ new Map();
|
|
@@ -6716,6 +6721,11 @@ async function wireForms(briefIn, sources, options_ = {}) {
|
|
|
6716
6721
|
continue;
|
|
6717
6722
|
}
|
|
6718
6723
|
const candidate = list[0];
|
|
6724
|
+
if (wiredTo(candidate, form)) {
|
|
6725
|
+
alreadyWired++;
|
|
6726
|
+
onSite.push({ form, file: candidate.file });
|
|
6727
|
+
continue;
|
|
6728
|
+
}
|
|
6719
6729
|
if (attrOf(candidate.el, "action")?.expression) {
|
|
6720
6730
|
pend2(form, "ACTION_IS_EXPRESSION", candidate.file, "its action is an expression, so this run will not replace it.");
|
|
6721
6731
|
continue;
|
|
@@ -6728,11 +6738,6 @@ async function wireForms(briefIn, sources, options_ = {}) {
|
|
|
6728
6738
|
pend2(form, "FIELD_UNMATCHED", candidate.file, `the control for ${misnamed.key} posts under an expression, so its name cannot be set to the CMS key.`);
|
|
6729
6739
|
continue;
|
|
6730
6740
|
}
|
|
6731
|
-
if (attrOf(candidate.el, "data-bcms-form")?.value === form.id) {
|
|
6732
|
-
alreadyWired++;
|
|
6733
|
-
onSite.push({ form, file: candidate.file });
|
|
6734
|
-
continue;
|
|
6735
|
-
}
|
|
6736
6741
|
matched.push({ form, candidate });
|
|
6737
6742
|
onSite.push({ form, file: candidate.file });
|
|
6738
6743
|
}
|
|
@@ -6853,7 +6858,8 @@ var TEMPLATE_DIRS = /* @__PURE__ */ new Set([
|
|
|
6853
6858
|
"_includes",
|
|
6854
6859
|
"_layouts"
|
|
6855
6860
|
]);
|
|
6856
|
-
var
|
|
6861
|
+
var READ_CONFIG = /^astro\.config\.[^./]+$/;
|
|
6862
|
+
var isAboutTheSite = (lower) => /\.(test|spec)\.[^./]+$/.test(lower) || /^[^/]*\.config\.[^./]+$/.test(lower) && !READ_CONFIG.test(lower);
|
|
6857
6863
|
function isSourceCandidate(path) {
|
|
6858
6864
|
const lower = path.toLowerCase();
|
|
6859
6865
|
if (SKIP_DIRS.some((dir) => lower === dir.slice(0, -1) || lower.startsWith(dir) || lower.includes(`/${dir}`)))
|
|
@@ -6900,7 +6906,7 @@ function measureUnaddressable(html) {
|
|
|
6900
6906
|
let visible = 0;
|
|
6901
6907
|
let unaddressable = 0;
|
|
6902
6908
|
const buckets = /* @__PURE__ */ new Map();
|
|
6903
|
-
const visit = (node, tag, context, bound) => {
|
|
6909
|
+
const visit = (node, tag, context, bound, inForm = false) => {
|
|
6904
6910
|
if (node.type === "text") {
|
|
6905
6911
|
const text = flat2(node.value);
|
|
6906
6912
|
if (isDecorativeGlyph(text) || PLATFORM_BADGE.test(text)) return;
|
|
@@ -6920,9 +6926,10 @@ function measureUnaddressable(html) {
|
|
|
6920
6926
|
if (attrs.has("hidden") || attrs.get("aria-hidden") === "true" || /display\s*:\s*none/i.test(attrs.get("style") ?? "") || isSkipLink(node, attrs)) {
|
|
6921
6927
|
return;
|
|
6922
6928
|
}
|
|
6923
|
-
const
|
|
6929
|
+
const form = inForm || attrs.has("data-bcms-form");
|
|
6930
|
+
const owned = bound || BOUND_ATTRS.some((name) => attrs.has(name)) || form && attrs.has("data-bcms-form-part");
|
|
6924
6931
|
const chain = CONTEXT_TAGS.has(node.tag) ? context === "body" ? node.tag : `${context}>${node.tag}` : context;
|
|
6925
|
-
for (const child of node.children) visit(child, node.tag, chain, owned);
|
|
6932
|
+
for (const child of node.children) visit(child, node.tag, chain, owned, form);
|
|
6926
6933
|
};
|
|
6927
6934
|
for (const root of parsed.roots) visit(root, "body", "body", false);
|
|
6928
6935
|
return {
|
|
@@ -9420,7 +9427,23 @@ async function plan(file, content, dialect, targets, sites, importAt, outcomes,
|
|
|
9420
9427
|
continue;
|
|
9421
9428
|
}
|
|
9422
9429
|
const resolved = sharing.length === 1 ? { assigned: /* @__PURE__ */ new Map([[sharing[0].key, forLiteral]]), ambiguous: /* @__PURE__ */ new Set() } : resolvePositionally(sharing, forLiteral);
|
|
9430
|
+
const exactly = new Map(
|
|
9431
|
+
sharing.length > 1 ? sharing.flatMap((target) => {
|
|
9432
|
+
const own = forLiteral.filter(
|
|
9433
|
+
(site) => site.where === "text" && !site.partial && !site.mixed && isIntrinsic(site.tag) && declarations.some((d) => d.scope === target.scope && d.path === target.path && d.at === site.attrInsertAt)
|
|
9434
|
+
);
|
|
9435
|
+
return own.length > 0 ? [[target.key, own]] : [];
|
|
9436
|
+
}) : []
|
|
9437
|
+
);
|
|
9438
|
+
const unmarked = forLiteral.filter((site) => ![...exactly.values()].some((own) => own.includes(site)));
|
|
9439
|
+
const settled = unmarked.length <= sharing.length - exactly.size ? exactly : /* @__PURE__ */ new Map();
|
|
9423
9440
|
for (const target of sharing) {
|
|
9441
|
+
const own = settled.get(target.key);
|
|
9442
|
+
if (own) {
|
|
9443
|
+
outcomes.set(target.key, "declared");
|
|
9444
|
+
located += own.length;
|
|
9445
|
+
continue;
|
|
9446
|
+
}
|
|
9424
9447
|
if (resolved.ambiguous.has(target.key)) {
|
|
9425
9448
|
outcomes.set(target.key, "AMBIGUOUS_LITERAL");
|
|
9426
9449
|
continue;
|