fix
This commit is contained in:
parent
978e58086c
commit
040db38e08
|
|
@ -86,6 +86,12 @@ export const EDGlobal = {
|
||||||
ui: {
|
ui: {
|
||||||
tree: {
|
tree: {
|
||||||
search: "",
|
search: "",
|
||||||
|
searchMode: {
|
||||||
|
Name: true,
|
||||||
|
JS: false,
|
||||||
|
HTML: false,
|
||||||
|
CSS: false,
|
||||||
|
},
|
||||||
open: {} as Record<string, string[]>,
|
open: {} as Record<string, string[]>,
|
||||||
},
|
},
|
||||||
popup: {
|
popup: {
|
||||||
|
|
|
||||||
|
|
@ -21,93 +21,175 @@ export const EdTreeSearch = () => {
|
||||||
}, [local.sref, local.cursor, p.ui.tree.search]);
|
}, [local.sref, local.cursor, p.ui.tree.search]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex items-stretch h-[24px] border-b">
|
<div
|
||||||
<input
|
className="flex flex-col items-stretch border-b"
|
||||||
name="search"
|
onMouseOver={() => {
|
||||||
ref={(ref) => {
|
if (local.focus) {
|
||||||
local.sref = ref;
|
local.hover = true;
|
||||||
}}
|
|
||||||
type="search"
|
|
||||||
autoComplete="off"
|
|
||||||
className={cx("flex-1 outline-none px-2 text-[13px] ")}
|
|
||||||
placeholder="Search..."
|
|
||||||
value={p.ui.tree.search}
|
|
||||||
spellCheck={false}
|
|
||||||
onInput={(e) => {
|
|
||||||
local.cursor = e.currentTarget.selectionStart;
|
|
||||||
p.ui.tree.search = e.currentTarget.value;
|
|
||||||
p.render();
|
|
||||||
}}
|
|
||||||
onFocus={() => {
|
|
||||||
local.focus = true;
|
|
||||||
local.render();
|
local.render();
|
||||||
}}
|
}
|
||||||
onBlur={() => {
|
}}
|
||||||
if (!local.hover && !p.ui.tree.search) {
|
onMouseLeave={() => {
|
||||||
local.focus = false;
|
local.hover = false;
|
||||||
|
local.render();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div className="flex items-stretch h-[24px] ">
|
||||||
|
<input
|
||||||
|
name="search"
|
||||||
|
ref={(ref) => {
|
||||||
|
local.sref = ref;
|
||||||
|
}}
|
||||||
|
type="search"
|
||||||
|
autoComplete="off"
|
||||||
|
className={cx("flex-1 outline-none px-2 text-[13px] ")}
|
||||||
|
placeholder="Search..."
|
||||||
|
value={p.ui.tree.search}
|
||||||
|
spellCheck={false}
|
||||||
|
onInput={(e) => {
|
||||||
|
local.cursor = e.currentTarget.selectionStart;
|
||||||
|
p.ui.tree.search = e.currentTarget.value;
|
||||||
|
p.render();
|
||||||
|
}}
|
||||||
|
onFocus={() => {
|
||||||
|
local.focus = true;
|
||||||
local.render();
|
local.render();
|
||||||
}
|
}}
|
||||||
}}
|
onBlur={() => {
|
||||||
/>
|
if (!local.hover && !p.ui.tree.search) {
|
||||||
|
local.focus = false;
|
||||||
|
local.render();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{(local.focus || local.hover || p.ui.tree.search) && (
|
||||||
|
<div className="p-1 bg-white text-xs border-t flex space-x-1 justify-between">
|
||||||
|
<div className="flex space-x-1">
|
||||||
|
{Object.entries(p.ui.tree.searchMode).map(([name, active]) => {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={cx(
|
||||||
|
"px-1 cursor-pointer rounded-sm border-blue-500 border",
|
||||||
|
active ? "bg-blue-500 text-white" : "hover:bg-blue-100"
|
||||||
|
)}
|
||||||
|
onClick={() => {
|
||||||
|
(p.ui.tree.searchMode as any)[name] = !active;
|
||||||
|
local.render();
|
||||||
|
local.sref?.focus();
|
||||||
|
}}
|
||||||
|
key={name}
|
||||||
|
>
|
||||||
|
{name}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const doTreeSearch = (p: PG) => {
|
export const doTreeSearch = (p: PG) => {
|
||||||
let tree: NodeModel<EdMeta>[] = [];
|
let tree: Record<string, { idx: number; node: NodeModel<EdMeta> }> = {};
|
||||||
const [idxs, info] = uf.search(
|
|
||||||
p.page.tree.map((e) => e.text),
|
|
||||||
p.ui.tree.search
|
|
||||||
);
|
|
||||||
if (idxs && info) {
|
|
||||||
let i = 0;
|
|
||||||
for (const idx of idxs) {
|
|
||||||
const item = p.page.tree[idx];
|
|
||||||
const range = info.ranges[i++];
|
|
||||||
let text = "";
|
|
||||||
|
|
||||||
let cur = range.shift();
|
if (p.ui.tree.searchMode.Name) {
|
||||||
let open = true;
|
const [idxs, info] = uf.search(
|
||||||
for (let i = 0; i < item.text.length; i++) {
|
p.page.tree.map((e) => e.text),
|
||||||
if (typeof cur === "number") {
|
p.ui.tree.search
|
||||||
if (i === cur) {
|
);
|
||||||
if (open) {
|
if (idxs && info) {
|
||||||
text += `<b>`;
|
let i = 0;
|
||||||
open = false;
|
for (const idx of idxs) {
|
||||||
} else {
|
const item = p.page.tree[idx];
|
||||||
text += `</b>`;
|
const range = info.ranges[i];
|
||||||
open = true;
|
let text = "";
|
||||||
|
|
||||||
|
let cur = range.shift();
|
||||||
|
let open = true;
|
||||||
|
for (let i = 0; i < item.text.length; i++) {
|
||||||
|
if (typeof cur === "number") {
|
||||||
|
if (i === cur) {
|
||||||
|
if (open) {
|
||||||
|
text += `<b>`;
|
||||||
|
open = false;
|
||||||
|
} else {
|
||||||
|
text += `</b>`;
|
||||||
|
open = true;
|
||||||
|
}
|
||||||
|
cur = range.shift();
|
||||||
}
|
}
|
||||||
cur = range.shift();
|
text += item.text[i];
|
||||||
|
} else {
|
||||||
|
text += item.text[i];
|
||||||
}
|
}
|
||||||
text += item.text[i];
|
|
||||||
} else {
|
|
||||||
text += item.text[i];
|
|
||||||
}
|
}
|
||||||
|
const el = (
|
||||||
|
<div
|
||||||
|
className={css`
|
||||||
|
b {
|
||||||
|
font-weight: bold;
|
||||||
|
color: #df9100;
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
`}
|
||||||
|
dangerouslySetInnerHTML={{ __html: text }}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
tree[item.id] = {
|
||||||
|
idx: i,
|
||||||
|
node: {
|
||||||
|
...item,
|
||||||
|
parent: "root",
|
||||||
|
data: item.data
|
||||||
|
? {
|
||||||
|
...item.data,
|
||||||
|
el,
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
const el = (
|
|
||||||
<div
|
|
||||||
className={css`
|
|
||||||
b {
|
|
||||||
font-weight: bold;
|
|
||||||
color: #df9100;
|
|
||||||
text-decoration: underline;
|
|
||||||
}
|
|
||||||
`}
|
|
||||||
dangerouslySetInnerHTML={{ __html: text }}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
tree.push({
|
|
||||||
...item,
|
|
||||||
parent: "root",
|
|
||||||
data: item.data
|
|
||||||
? {
|
|
||||||
...item.data,
|
|
||||||
el,
|
|
||||||
}
|
|
||||||
: undefined,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tree;
|
|
||||||
|
const search = p.ui.tree.search.toLowerCase();
|
||||||
|
let i = 0;
|
||||||
|
for (const row of p.page.tree) {
|
||||||
|
const item = row.data?.item;
|
||||||
|
if (item) {
|
||||||
|
const js = item.adv?.js;
|
||||||
|
if (js) {
|
||||||
|
if (p.ui.tree.searchMode.JS) {
|
||||||
|
if ((js as string).toLowerCase().includes(search)) {
|
||||||
|
console.log(js);
|
||||||
|
tree[item.id] = { idx: i++, node: { ...row, parent: "root" } };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const css = item.adv?.css;
|
||||||
|
if (css) {
|
||||||
|
if (p.ui.tree.searchMode.CSS) {
|
||||||
|
if (css.toString().toLowerCase().includes(search)) {
|
||||||
|
tree[item.id] = { idx: i++, node: { ...row, parent: "root" } };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const html = item.adv?.html;
|
||||||
|
if (html) {
|
||||||
|
if (p.ui.tree.searchMode.HTML) {
|
||||||
|
if (html.toString().toLowerCase().includes(search)) {
|
||||||
|
tree[item.id] = { idx: i++, node: { ...row, parent: "root" } };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Object.values(tree)
|
||||||
|
.sort((a, b) => a.idx - b.idx)
|
||||||
|
.map((e) => e.node);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue