Skip to content

Commit

Permalink
feat: #213 挂件模式用挂载菜单的方式使用-hook挂件按钮
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Dec 15, 2022
1 parent 0de9a73 commit 0b08791
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 1 deletion.
4 changes: 4 additions & 0 deletions layouts/default/DefaultHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ onMounted(() => {
color: var(--el-button-text-color);
}
#publisher-header {
/*padding: 0;*/
}
#publisher-header .b3-button--cancel {
float: right;
}
Expand Down
73 changes: 73 additions & 0 deletions public/lib/siyuanhook.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ const fetchPost = (url, data, cb, headers) => {
})
}

/**
* 弹窗打开
*/
window.terwer = {
renderPublishHelper: () => {},
}
Expand Down Expand Up @@ -196,3 +199,73 @@ window.terwer.renderPublishHelper = () => {
// getCurrentWindow().webContents.setZoomFactor(1);
// window.siyuan.printWin.destroy();
// };

/**-- 在所有文档前面加上一个挂件插槽--**/
function showPreviousWidgetsSlot() {
setInterval(DocumentShowPreviousWidget, 300)
}

DocumentShowPreviousWidget()
showPreviousWidgetsSlot()

function DocumentShowPreviousWidget() {
var openDoc = document.querySelectorAll(
".layout-tab-container>.fn__flex-1.protyle:not(.fn__none)"
)
var allDocumentTitleElement = []
for (let index = 0; index < openDoc.length; index++) {
const element = openDoc[index]
element.setAttribute("withPreviousWidgets", true)
allDocumentTitleElement.push(element.children[1].children[1].children[1])
}

for (let index = 0; index < allDocumentTitleElement.length; index++) {
const element = allDocumentTitleElement[index]

if (
!element.parentElement.querySelector(".previous-widgets-slot") &&
element.parentElement.parentElement.querySelector("[data-node-id]")
) {
var documentPreviousWidgetsSlotElement = CreatePreviousWidgetsSlot(
element.parentElement
)
element.parentElement.appendChild(documentPreviousWidgetsSlotElement)
}
}
}

function CreatePreviousWidgetsSlot(element) {
let cloneNode = element.parentElement
.querySelector(".protyle-wysiwyg.protyle-wysiwyg--attr")
.cloneNode(false)
cloneNode.innerHTML = `
<div class="iframe-content">
<iframe src="/widgets/sy-post-publisher/" ></iframe>
</div>
`
let id = element.parentElement.parentElement
.querySelector("[data-node-id]")
.getAttribute("data-node-id")
cloneNode.setAttribute("data-node-id", id)
cloneNode.setAttribute("contenteditable", false)
cloneNode.setAttribute("style", "padding: 0;")
let div = document.createElement("div")
div.setAttribute("class", "previous-widgets-slot")
div.setAttribute("contenteditable", false)
div.setAttribute("style", "padding: 0;")
let root = div.attachShadow({ mode: "open" })
root.innerHTML = `
<style>
iframe{
width:100%;
min-height:45px;
height:45px;
border:none;
margin:0;
padding:0
}
</style>
`
root.appendChild(cloneNode)
return div
}
2 changes: 2 additions & 0 deletions scripts/ext.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ cp ./LICENSE ./dist/

# 删除siyuan挂件专属文件
rm ./dist/widget.json
rm ./dist/lib/siyuanhook.js

# 删除火狐配置
rm -rf ./dist/mv2
mv ./dist/manifest.prod.json ./dist/manifest.json
Expand Down
2 changes: 2 additions & 0 deletions scripts/extDev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ cp ./LICENSE ./dist/

# 删除siyuan挂件专属文件
rm ./dist/widget.json
rm ./dist/lib/siyuanhook.js

# 删除火狐配置
rm -rf ./dist/mv2
mv ./dist/manifest.dev.json ./dist/manifest.json
Expand Down
1 change: 1 addition & 0 deletions scripts/extFV2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ cp ./LICENSE ./dist/

# 删除siyuan挂件专属文件
rm ./dist/widget.json
rm ./dist/lib/siyuanhook.js

# 火狐配置
mv ./dist/mv2/manifest-v2-for-firefox.json ./dist/manifest.json
Expand Down
1 change: 0 additions & 1 deletion utils/platform/dynamicConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,6 @@ export function getDynPostidKey(platformKey: string): string {
export const getDynYamlConverterAdaptor = (
platformKey: string
): YamlConvertAdaptor => {
logger.error(platformKey)
let yamlConverter = new YamlConvertAdaptor()
if (platformKey.includes("-")) {
const typeArr = platformKey.split("-")
Expand Down

0 comments on commit 0b08791

Please sign in to comment.