added mind map
This commit is contained in:
1 parent
ed5c0a4223
commit
f55873a425
12 files changed
+132
-38
No files matched your search
@@ -29,14 +29,29 @@ export const INITIAL_MIND = {
|
||||
|
||||
// 模擬打 API
|
||||
// Simulate an API call to search based on the query
|
||||
export async function mockSearchApi(query) {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve([
|
||||
{ text: `${query} 建議1`, link: `https://example.com/${query}1` },
|
||||
{ text: `${query} 建議2`, link: `https://example.com/${query}2` },
|
||||
{ text: `${query} 建議3`, link: `https://example.com/${query}3` },
|
||||
])
|
||||
}, 500)
|
||||
})
|
||||
export async function mockSearchApi(query, tableUID) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", '/admin/universal_tables/get_entries?uid=' + tableUID + "&q=" + query + "&links=true");
|
||||
xhr.setRequestHeader("Accept", "application/json");
|
||||
|
||||
xhr.onload = function () {
|
||||
if (xhr.status >= 200 && xhr.status < 300) {
|
||||
try {
|
||||
const data = JSON.parse(xhr.responseText);
|
||||
resolve(data); // success
|
||||
} catch (e) {
|
||||
reject(new Error("Invalid JSON response"));
|
||||
}
|
||||
} else {
|
||||
reject(new Error(`Request failed with status ${xhr.status}`));
|
||||
}
|
||||
};
|
||||
|
||||
xhr.onerror = function () {
|
||||
reject(new Error("Network error"));
|
||||
};
|
||||
|
||||
xhr.send();
|
||||
});
|
||||
}
|
||||
@@ -33,8 +33,8 @@ export function initJsmind(mind, options, isEditable) {
|
||||
// 掛載附加模組(遠程搜尋 & 工具列)
|
||||
// Attach additional modules (Remote search & Toolbar)
|
||||
if (isEditable) {
|
||||
new JsmindSearch(jm, mockSearchApi)
|
||||
new JsmindToolbar(jm)
|
||||
new JsmindSearch(jm, mockSearchApi, options.tableUID);
|
||||
new JsmindToolbar(jm, options)
|
||||
}
|
||||
|
||||
return jm
|
||||
|
||||
@@ -14,13 +14,14 @@ export class JsmindSearch {
|
||||
* Constructor for search
|
||||
* @param {Object} jm - jsMind 實例 (jsMind instance)
|
||||
* @param {Function} searchAPI - 遠程搜尋 API 函式 (Remote search API function)
|
||||
* @param {string} tableUID
|
||||
*/
|
||||
constructor(jm, searchAPI) {
|
||||
constructor(jm, searchAPI, tableUID) {
|
||||
this.jm = jm
|
||||
this.searchAPI = searchAPI
|
||||
this.container = document.getElementById(jm.options.container)
|
||||
this.suggestionBox = null
|
||||
|
||||
this.tableUID = tableUID
|
||||
this.init()
|
||||
}
|
||||
|
||||
@@ -77,8 +78,9 @@ export class JsmindSearch {
|
||||
async onInput(node, e) {
|
||||
const query = e.target.value.trim()
|
||||
if (!query) return
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
try {
|
||||
const results = await this.searchAPI(query)
|
||||
const results = await this.searchAPI(query, this.tableUID)
|
||||
this.showSuggestion(node, e.target, results)
|
||||
} catch (error) {
|
||||
// Search API error handling
|
||||
|
||||
@@ -13,8 +13,9 @@ export class JsmindToolbar {
|
||||
* 建構工具列
|
||||
* Constructor for toolbar
|
||||
* @param {Object} jm - jsMind 實例 (jsMind instance)
|
||||
* @param {Object} options - jsMind 實例 (options)
|
||||
*/
|
||||
constructor(jm) {
|
||||
constructor(jm, options) {
|
||||
this.jm = jm
|
||||
this.container = document.getElementById(jm.options.container)
|
||||
this.toolbarNodeId = null
|
||||
@@ -22,7 +23,7 @@ export class JsmindToolbar {
|
||||
this.bgColorPalette = null
|
||||
this.strokeColorPalette = null
|
||||
this.textColorPalette = null
|
||||
|
||||
this.options = options
|
||||
this.init()
|
||||
}
|
||||
|
||||
@@ -78,21 +79,21 @@ export class JsmindToolbar {
|
||||
// 建立工具列按鈕
|
||||
// Create toolbar buttons
|
||||
const buttons = [
|
||||
{ id: 'toolbar-add-child-btn', text: '新增', onClick: this.handleAddChild.bind(this) },
|
||||
{ id: 'toolbar-delete-btn', text: '刪除', onClick: this.handleDelete.bind(this) },
|
||||
{ id: 'toolbar-add-child-btn', text: this.options.text.addNode, onClick: this.handleAddChild.bind(this) },
|
||||
{ id: 'toolbar-delete-btn', text: this.options.text.deleteNode, onClick: this.handleDelete.bind(this) },
|
||||
{
|
||||
id: 'toolbar-stroke-color-btn',
|
||||
text: '線條顏色',
|
||||
text: this.options.text.strokeColor,
|
||||
onClick: this.handleStrokeColor.bind(this),
|
||||
},
|
||||
{
|
||||
id: 'toolbar-bg-color-btn',
|
||||
text: '背景顏色',
|
||||
text: this.options.text.bgColor,
|
||||
onClick: this.handleBgColor.bind(this),
|
||||
},
|
||||
{
|
||||
id: 'toolbar-text-color-btn',
|
||||
text: '文字顏色',
|
||||
text: this.options.text.textColor,
|
||||
onClick: this.handleTextColor.bind(this),
|
||||
},
|
||||
]
|
||||
|
||||
Reference in new issue
Block a user