Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
zzlb0224 committed Jun 10, 2024
1 parent d1e985e commit 9bb81b1
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 66 deletions.
83 changes: 82 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
},
"dependencies": {
"@types/react": "^18.3.3",
"@types/react-color": "^3.0.12",
"@types/react-dom": "^18.3.0",
"react": "^18.3.1",
"react-color": "^2.19.3",
"react-dom": "^18.3.1",
"use-immer": "^0.9.0",
"zotero-plugin-toolkit": "^2.3.32"
Expand Down
85 changes: 27 additions & 58 deletions src/modules/AnnotationPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ import * as React from "react";
import { useEffect, useRef, useState } from "react";
import { getString } from "../utils/locale";
import { useImmer } from "use-immer";
import { ChromePicker } from "react-color"



export class AnnotationPopup {
reader?: _ZoteroTypes.ReaderInstance;
Expand Down Expand Up @@ -81,6 +84,8 @@ export class AnnotationPopup {
: [];
// 这里引发的 #38 ,可能是json循环输出的问题?
// ztoolkit.log(this, this.existAnnotations);
ztoolkit.log("bbbb", params)


this.fontSize =
(Zotero.Prefs.get(
Expand Down Expand Up @@ -110,7 +115,8 @@ export class AnnotationPopup {
}
public createDiv() {
if (!this.doc) return;

Zotero.test_doc = this.doc
Zotero.test_params = this.params
this.clearDiv();

this.rootDiv = ztoolkit.UI.createElement(this.doc, "div", {
Expand Down Expand Up @@ -472,8 +478,8 @@ export class AnnotationPopup {
if (this.isExistAnno) {
rootStyle.zIndex = "99990";
rootStyle.position = "fixed";
rootStyle.top = this.params?.y + "px";
rootStyle.left = this.params?.x + "px"; //只有左边需要改,其它的固定
rootStyle.top = (this.params?.y || 0) + "px";
rootStyle.left = (this.params?.x || 0) + "px"; //只有左边需要改,其它的固定

//对已有标签处理 防止出现右边超出边界
if (this.params?.x || 0 > clientWidthWithSlider - maxWidth) {
Expand Down Expand Up @@ -1919,12 +1925,18 @@ function PopupRoot({
placeholder='搜索标签,按回车添加'
onKeyDown={(e) => {
// ztoolkit.log(e)
if (time > 0) { setTime(-1) }
if (e.code == "Enter") {
saveAnnotationTags(searchTag, [], [], reader, params, doc);
if (params.ids) {
root.remove();
}
}
if (e.code == "Escape") {
//@ts-ignore _onSetSelectionPopup
reader?._primaryView._onSetSelectionPopup(null);
root.remove()
}
}}
/>
<span style={tagStyle}>固定标签来自【{currentPosition}</span>{" "}
Expand All @@ -1945,72 +1957,29 @@ function PopupRoot({
// borderRadius: "3px",
}}
onClick={() => {
if (isShowConfig) return;
saveAnnotationTags(tag.key, [], [], reader, params, doc);
if (params.ids) {
root.remove();
}
}}
>
<span>[{tag.values.length}]</span>
<span> {tag.key}</span>
</span>
))}
</span>
</div>
</>
);
}
function Config() {
return (
<>
<div>通用配置功能启用</div>
<div>颜色条配置</div>
<div>字体大小</div>
</>
);
}

function ExistingTags() {
return (
<>
<div>已存在的标签</div>
<ExistingTagsConfig></ExistingTagsConfig>
</>
);
}
<span>{tag.key}</span>

function ExistingTagsConfig() {
return (
<>
<div>已存在的标签配置</div>
</>
);
}
{isShowConfig && (<>
<span style={{ background: "#fff", color: "#000", border: "1px solid #000" }}>选择颜色</span>
{memFixedTags().includes(tag.key) ? (<><span style={{ background: "#fff", color: "#000", border: "1px solid #000" }}>移除固定</span>
<span style={{ background: "#fff", color: "#000", border: "1px solid #000" }}>左移</span>
<span style={{ background: "#fff", color: "#000", border: "1px solid #000" }}>右移</span>

function SearchDiv({
isShowConfig,
onChangeShowConfig,
}: {
isShowConfig: boolean;
onChangeShowConfig: () => void;
}) {
return (
<>
<div>
搜索窗口
<span onClick={() => onChangeShowConfig()}>
{isShowConfig ? "关闭配置" : "打开配置"}
</>) :
<span style={{ background: "#fff", color: "#000", border: "1px solid #000" }}>设置固定</span>}
</>)}
</span>
))}
</span>
</div>
<SearchResult searchText=""></SearchResult>
</>
);
}

function SearchResult({ searchText = "" }) {
return (
<>
<div>搜索结果</div>
</>
);
}
4 changes: 2 additions & 2 deletions src/modules/DebounceInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ export function DebounceInput() {
// 设置文本
function handleText(event: React.ChangeEvent<HTMLInputElement>) {
event.persist();
ztoolkit.log("handleText", event.target.value);
// ztoolkit.log("handleText", event.target.value);
debounceHandleText(event);
}

const debounceHandleText = Zotero.Utilities.debounce(
(event: React.ChangeEvent<HTMLInputElement>) => {
ztoolkit.log("debounceHandleText", event.target.value);
// ztoolkit.log("debounceHandleText", event.target.value);
setText(event.target.value);
},
500,
Expand Down
10 changes: 5 additions & 5 deletions src/modules/preferenceScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -671,11 +671,11 @@ async function replaceTagsPreviewDiv(doc?: Document) {
preview.appendChild(rootDiv);
rootDiv.innerText = `预览批注来自:${from}。条目:${ann.parentItem?.parentItem?.getDisplayTitle()}
包含标签: [${ann
.getTags()
.map((a) => a.tag)
.join(
",",
)}]内容:${ann.annotationType} ${ann.annotationText || ""} ${ann.annotationComment || ""}
.getTags()
.map((a) => a.tag)
.join(
",",
)}]内容:${ann.annotationType} ${ann.annotationText || ""} ${ann.annotationComment || ""}
`;
rootDiv.style.position = "";
rootDiv.style.width = "";
Expand Down

0 comments on commit 9bb81b1

Please sign in to comment.