Update to use react-editor <App /> component

This commit is contained in:
Rami Bitar
2026-05-03 16:22:24 -04:00
parent a78249846a
commit 757118706e
51 changed files with 2294 additions and 2190 deletions

View File

@@ -1,15 +1,34 @@
const resolveEditorPath = (editorPath: string[] = []) => {
const hasPath = editorPath.length > 0;
const TEMPLATE_PATTERNS: { key: string; prefix: string; param: string }[] = [
{ key: "/products/*", prefix: "/products/", param: "handle" },
{ key: "/collections/*", prefix: "/collections/", param: "handle" },
];
const isEdit = hasPath ? editorPath[editorPath.length - 1] === "edit" : false;
export type ResolvedEditorPath = {
isEdit: boolean;
path: string;
templateKey: string | null;
params: Record<string, string>;
};
return {
isEdit,
path: `/${(isEdit
? [...editorPath].slice(0, editorPath.length - 1)
: [...editorPath]
).join("/")}`,
};
const resolveEditorPath = (editorPath: string[] = []): ResolvedEditorPath => {
const isEdit =
editorPath.length > 0 && editorPath[editorPath.length - 1] === "edit";
const segments = isEdit ? editorPath.slice(0, -1) : editorPath;
const path = segments.length === 0 ? "/" : `/${segments.join("/")}`;
for (const { key, prefix, param } of TEMPLATE_PATTERNS) {
if (path.startsWith(prefix) && path.length > prefix.length) {
return {
isEdit,
path,
templateKey: key,
params: { [param]: path.slice(prefix.length) },
};
}
}
return { isEdit, path, templateKey: null, params: {} };
};
export default resolveEditorPath;