Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Support cross-region dock entry sorting https://github.com/siyuan-note/siyuan/issues/18285

Daniel87fa1678318c
diff --git a/app/src/assets/scss/business/_config.scss b/app/src/assets/scss/business/_config.scss
index c6c476917e..efde792980 100644
--- a/app/src/assets/scss/business/_config.scss
+++ b/app/src/assets/scss/business/_config.scss
@@ -1034,6 +1034,45 @@
}
}
+ &__dock-column {
+ flex-basis: clamp(180px, 20vw, 240px);
+ }
+
+ &__dock-group {
+ border-bottom: 1px solid var(--b3-border-color);
+ min-height: 72px;
+
+ &--drop {
+ box-shadow: inset 0 0 0 2px var(--b3-theme-primary);
+ }
+
+ &-title {
+ align-items: center;
+ background-color: var(--b3-theme-surface-lighter);
+ color: var(--b3-theme-on-surface-light);
+ display: flex;
+ font-size: 12px;
+ height: 32px;
+ overflow: hidden;
+ padding: 0 12px;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+ }
+ }
+
+ &__dock-list {
+ min-height: 40px;
+ }
+
+ &__dock-empty {
+ align-items: center;
+ color: var(--b3-theme-on-surface-light);
+ display: flex;
+ font-size: 12px;
+ height: 40px;
+ justify-content: center;
+ }
+
&__location {
border-bottom: 1px solid var(--b3-border-color);
border-radius: 0;
diff --git a/app/src/config/entryVisibility/dockOrder.test.ts b/app/src/config/entryVisibility/dockOrder.test.ts
index aac767f3e9..6dc2e2679d 100644
--- a/app/src/config/entryVisibility/dockOrder.test.ts
+++ b/app/src/config/entryVisibility/dockOrder.test.ts
@@ -7,11 +7,14 @@ import {
createDockEntryOrderSnapshot,
DOCK_ORDER_SCOPE_BY_POSITION,
DOCK_ORDER_SCOPES,
+ getCurrentDockEntryOrderSnapshot,
getDockEntryOrderSnapshot,
getDockOrderContainer,
isDockOrderScope,
mergeCurrentDockEntryOrders,
mergeDockEntryOrderSnapshot,
+ moveDockEntryOrderSnapshot,
+ type TDockEntryMover,
type IDockOrderLayout,
type TDockOrderSnapshot,
} from "./dockOrder";
@@ -36,6 +39,18 @@ class FakeDockItem {
}
return null;
}
+
+ public before(item: FakeDockItem) {
+ this.parent?.insertBefore(item, this);
+ }
+
+ public after(item: FakeDockItem) {
+ this.parent?.insertBefore(item, this.parent.children[this.parent.children.indexOf(this) + 1]);
+ }
+
+ public get parentElement() {
+ return this.parent;
+ }
}
class FakeDockContainer {
@@ -46,13 +61,21 @@ class FakeDockContainer {
}
public append(item: FakeDockItem) {
+ this.insertBefore(item);
+ }
+
+ public insertBefore(item: FakeDockItem, reference?: FakeDockItem) {
+ let index = reference ? this.children.indexOf(reference) : this.children.length;
if (item.parent) {
const oldIndex = item.parent.children.indexOf(item);
if (oldIndex > -1) {
item.parent.children.splice(oldIndex, 1);
+ if (item.parent === this && oldIndex < index) {
+ index--;
+ }
}
}
- this.children.push(item);
+ this.children.splice(index < 0 ? this.children.length : index, 0, item);
item.parent = this;
}
}
@@ -129,6 +152,22 @@ test("runtime dock snapshot reads direct items, keeps hidden items, and uses sta
assert.equal(hiddenOutline.classList.contains("fn__none"), true);
});
+test("current dock snapshot contains only DOM entries without catalog defaults", () => {
+ const plugin = new FakeDockItem("plugin-runtime-type", {entryId: "plugin:sample:dock"});
+ const outline = new FakeDockItem("outline");
+ const containers = [
+ new FakeDockContainer([outline, plugin]),
+ ...Array.from({length: 5}, () => new FakeDockContainer()),
+ ];
+
+ const current = getCurrentDockEntryOrderSnapshot(layoutWith(containers));
+
+ assert.deepEqual(current[DOCK_ORDER_SCOPE_BY_POSITION.LeftTop], ["outline", "plugin:sample:dock"]);
+ assert.deepEqual(DOCK_ORDER_SCOPES.flatMap((scope) => current[scope]), ["outline", "plugin:sample:dock"]);
+ assert.equal(getDockEntryOrderSnapshot(layoutWith(containers))[DOCK_ORDER_SCOPE_BY_POSITION.LeftTop]
+ .includes("file"), true);
+});
+
test("merging a dock snapshot preserves an unavailable plugin key at its saved slot", () => {
const defaults = emptySnapshot();
defaults[DOCK_ORDER_SCOPE_BY_POSITION.LeftTop] = ["file", "outline"];
@@ -151,6 +190,36 @@ test("synchronizing a dock snapshot keeps the current loaded order and preserves
["outline", "plugin:disabled:dock", "file"]);
});
+test("synchronizing uses current placement while preserving globally unique unavailable plugins", () => {
+ const current = emptySnapshot();
+ current[DOCK_ORDER_SCOPE_BY_POSITION.LeftTop] = ["outline"];
+ current[DOCK_ORDER_SCOPE_BY_POSITION.RightBottom] = ["file"];
+ const merged = mergeCurrentDockEntryOrders(current, {
+ [DOCK_ORDER_SCOPE_BY_POSITION.LeftTop]: ["file", "plugin:disabled:dock", "outline"],
+ [DOCK_ORDER_SCOPE_BY_POSITION.RightBottom]: ["plugin:disabled:dock", "file"],
+ });
+
+ assert.deepEqual(merged[DOCK_ORDER_SCOPE_BY_POSITION.LeftTop], ["plugin:disabled:dock", "outline"]);
+ assert.deepEqual(merged[DOCK_ORDER_SCOPE_BY_POSITION.RightBottom], ["file"]);
+ assert.equal(DOCK_ORDER_SCOPES.flatMap((scope) => merged[scope])
+ .filter((key) => key === "plugin:disabled:dock").length, 1);
+ assert.equal(DOCK_ORDER_SCOPES.flatMap((scope) => merged[scope])
+ .filter((key) => key === "file").length, 1);
+});
+
+test("synchronizing filters stale loaded placements before preserving unknown slots", () => {
+ const current = emptySnapshot();
+ current[DOCK_ORDER_SCOPE_BY_POSITION.RightTop] = ["loaded"];
+ const merged = mergeCurrentDockEntryOrders(current, {
+ [DOCK_ORDER_SCOPE_BY_POSITION.LeftTop]: ["loaded"],
+ [DOCK_ORDER_SCOPE_BY_POSITION.RightTop]: ["unknown-before", "loaded", "unknown-after"],
+ });
+
+ assert.deepEqual(merged[DOCK_ORDER_SCOPE_BY_POSITION.LeftTop], []);
+ assert.deepEqual(merged[DOCK_ORDER_SCOPE_BY_POSITION.RightTop],
+ ["unknown-before", "loaded", "unknown-after"]);
+});
+
test("profiles without dock orders preserve the current six-slot layout", () => {
const current = emptySnapshot();
current[DOCK_ORDER_SCOPE_BY_POSITION.LeftTop] = ["outline", "file"];
@@ -159,17 +228,119 @@ test("profiles without dock orders preserve the current six-slot layout", () =>
assert.deepEqual(mergeDockEntryOrderSnapshot(current), current);
});
-test("merging a dock snapshot removes a loaded entry from its stale previous slot", () => {
+test("merging a dock snapshot applies saved placement and the first saved scope owns duplicate keys", () => {
const current = emptySnapshot();
- current[DOCK_ORDER_SCOPE_BY_POSITION.LeftTop] = ["outline"];
+ current[DOCK_ORDER_SCOPE_BY_POSITION.LeftTop] = ["file", "outline"];
current[DOCK_ORDER_SCOPE_BY_POSITION.RightTop] = ["file", "graph"];
const merged = mergeDockEntryOrderSnapshot(current, {
- [DOCK_ORDER_SCOPE_BY_POSITION.LeftTop]: ["file", "outline", "plugin:disabled:dock"],
- [DOCK_ORDER_SCOPE_BY_POSITION.RightTop]: ["graph", "file"],
+ [DOCK_ORDER_SCOPE_BY_POSITION.LeftBottom]: ["file", "plugin:disabled:dock"],
+ [DOCK_ORDER_SCOPE_BY_POSITION.RightTop]: ["graph", "file", "plugin:disabled:dock"],
+ });
+
+ assert.deepEqual(merged[DOCK_ORDER_SCOPE_BY_POSITION.LeftTop], ["outline"]);
+ assert.deepEqual(merged[DOCK_ORDER_SCOPE_BY_POSITION.LeftBottom], ["file", "plugin:disabled:dock"]);
+ assert.deepEqual(merged[DOCK_ORDER_SCOPE_BY_POSITION.RightTop], ["graph"]);
+ assert.equal(DOCK_ORDER_SCOPES.flatMap((scope) => merged[scope]).filter((key) => key === "file").length, 1);
+ assert.equal(DOCK_ORDER_SCOPES.flatMap((scope) => merged[scope])
+ .filter((key) => key === "plugin:disabled:dock").length, 1);
+});
+
+test("merging a partial saved snapshot moves declared entries and keeps undeclared current entries", () => {
+ const current = emptySnapshot();
+ current[DOCK_ORDER_SCOPE_BY_POSITION.LeftTop] = ["file", "outline"];
+ current[DOCK_ORDER_SCOPE_BY_POSITION.RightTop] = ["graph"];
+
+ const merged = mergeDockEntryOrderSnapshot(current, {
+ [DOCK_ORDER_SCOPE_BY_POSITION.RightTop]: ["file", "graph"],
+ });
+
+ assert.deepEqual(merged[DOCK_ORDER_SCOPE_BY_POSITION.LeftTop], ["outline"]);
+ assert.deepEqual(merged[DOCK_ORDER_SCOPE_BY_POSITION.RightTop], ["file", "graph"]);
+});
+
+test("merging keeps the saved order of loaded entries moved from another scope", () => {
+ const current = emptySnapshot();
+ current[DOCK_ORDER_SCOPE_BY_POSITION.LeftTop] = ["new-entry", "file", "outline"];
+ current[DOCK_ORDER_SCOPE_BY_POSITION.RightTop] = ["graph"];
+
+ const merged = mergeDockEntryOrderSnapshot(current, {
+ [DOCK_ORDER_SCOPE_BY_POSITION.LeftTop]: ["file", "graph", "outline"],
});
- assert.deepEqual(merged[DOCK_ORDER_SCOPE_BY_POSITION.LeftTop], ["outline", "plugin:disabled:dock"]);
- assert.deepEqual(merged[DOCK_ORDER_SCOPE_BY_POSITION.RightTop], ["graph", "file"]);
+ assert.deepEqual(merged[DOCK_ORDER_SCOPE_BY_POSITION.LeftTop],
+ ["new-entry", "file", "graph", "outline"]);
+ assert.deepEqual(merged[DOCK_ORDER_SCOPE_BY_POSITION.RightTop], []);
+});
+
+test("merging saved placement is idempotent and keeps new current entries", () => {
+ const current = emptySnapshot();
+ current[DOCK_ORDER_SCOPE_BY_POSITION.LeftTop] = ["outline", "new-left"];
+ current[DOCK_ORDER_SCOPE_BY_POSITION.RightTop] = ["file", "graph"];
+ const saved = {
+ [DOCK_ORDER_SCOPE_BY_POSITION.LeftTop]: ["file", "plugin:disabled:dock", "outline"],
+ [DOCK_ORDER_SCOPE_BY_POSITION.RightTop]: ["graph", "file"],
+ };
+
+ const merged = mergeDockEntryOrderSnapshot(current, saved);
+
+ assert.deepEqual(merged[DOCK_ORDER_SCOPE_BY_POSITION.LeftTop],
+ ["file", "plugin:disabled:dock", "outline", "new-left"]);
+ assert.deepEqual(merged[DOCK_ORDER_SCOPE_BY_POSITION.RightTop], ["graph"]);
+ assert.deepEqual(mergeDockEntryOrderSnapshot(merged, saved), merged);
+});
+
+test("moving a dock entry snapshot is atomic across scopes and supports empty targets", () => {
+ const snapshot = emptySnapshot();
+ snapshot[DOCK_ORDER_SCOPE_BY_POSITION.LeftTop] = ["file", "outline"];
+ snapshot[DOCK_ORDER_SCOPE_BY_POSITION.RightBottom] = ["backlink"];
+
+ const crossed = moveDockEntryOrderSnapshot(
+ snapshot,
+ "file",
+ DOCK_ORDER_SCOPE_BY_POSITION.RightBottom,
+ "backlink",
+ );
+ assert.deepEqual(crossed?.[DOCK_ORDER_SCOPE_BY_POSITION.LeftTop], ["outline"]);
+ assert.deepEqual(crossed?.[DOCK_ORDER_SCOPE_BY_POSITION.RightBottom], ["file", "backlink"]);
+ assert.equal(DOCK_ORDER_SCOPES.flatMap((scope) => crossed?.[scope] || [])
+ .filter((key) => key === "file").length, 1);
+
+ const emptied = moveDockEntryOrderSnapshot(
+ crossed,
+ "file",
+ DOCK_ORDER_SCOPE_BY_POSITION.BottomLeft,
+ );
+ assert.deepEqual(emptied?.[DOCK_ORDER_SCOPE_BY_POSITION.RightBottom], ["backlink"]);
+ assert.deepEqual(emptied?.[DOCK_ORDER_SCOPE_BY_POSITION.BottomLeft], ["file"]);
+});
+
+test("moving within one dock scope detects invalid and no-op drops", () => {
+ const snapshot = emptySnapshot();
+ snapshot[DOCK_ORDER_SCOPE_BY_POSITION.LeftTop] = ["file", "outline", "inbox"];
+
+ assert.deepEqual(moveDockEntryOrderSnapshot(
+ snapshot,
+ "inbox",
+ DOCK_ORDER_SCOPE_BY_POSITION.LeftTop,
+ "file",
+ )?.[DOCK_ORDER_SCOPE_BY_POSITION.LeftTop], ["inbox", "file", "outline"]);
+ assert.equal(moveDockEntryOrderSnapshot(
+ snapshot,
+ "file",
+ DOCK_ORDER_SCOPE_BY_POSITION.LeftTop,
+ "outline",
+ ), undefined);
+ assert.equal(moveDockEntryOrderSnapshot(
+ snapshot,
+ "file",
+ DOCK_ORDER_SCOPE_BY_POSITION.LeftTop,
+ "file",
+ ), undefined);
+ assert.equal(moveDockEntryOrderSnapshot(
+ snapshot,
+ "missing",
+ DOCK_ORDER_SCOPE_BY_POSITION.LeftTop,
+ ), undefined);
});
test("applying dock order sorts hidden items and keeps an unknown plugin in its current slot", () => {
@@ -190,11 +361,100 @@ test("applying dock order sorts hidden items and keeps an unknown plugin in its
assert.equal(asElement(file).dataset.type, "file");
});
+test("applying dock order moves entries across containers and is idempotent", () => {
+ const file = new FakeDockItem("file");
+ const outline = new FakeDockItem("outline", {hidden: true});
+ const graph = new FakeDockItem("graph");
+ const leftTop = new FakeDockContainer([file, outline]);
+ const rightTop = new FakeDockContainer([graph]);
+ const containers = [
+ leftTop,
+ new FakeDockContainer(),
+ rightTop,
+ ...Array.from({length: 3}, () => new FakeDockContainer()),
+ ];
+ const layout = layoutWith(containers);
+ const snapshot = emptySnapshot();
+ snapshot[DOCK_ORDER_SCOPE_BY_POSITION.LeftTop] = ["outline"];
+ snapshot[DOCK_ORDER_SCOPE_BY_POSITION.RightTop] = ["graph", "file"];
+
+ assert.equal(applyDockEntryOrderSnapshot(snapshot, layout), true);
+ assert.deepEqual(leftTop.children, [outline]);
+ assert.deepEqual(rightTop.children, [graph, file]);
+ assert.equal(file.parent, rightTop);
+ assert.equal(outline.classList.contains("fn__none"), true);
+ assert.equal(applyDockEntryOrderSnapshot(snapshot, layout), false);
+});
+
+test("applying dock order invokes the mover for cross-scope and same-scope changes", () => {
+ const first = new FakeDockItem("first");
+ const second = new FakeDockItem("second");
+ const third = new FakeDockItem("third");
+ const fourth = new FakeDockItem("fourth");
+ const leftTop = new FakeDockContainer([first, second]);
+ const rightTop = new FakeDockContainer([third, fourth]);
+ const containers = [
+ leftTop,
+ new FakeDockContainer(),
+ rightTop,
+ ...Array.from({length: 3}, () => new FakeDockContainer()),
+ ];
+ const layout = layoutWith(containers);
+ const snapshot = emptySnapshot();
+ snapshot[DOCK_ORDER_SCOPE_BY_POSITION.LeftTop] = [
+ "fourth",
+ "plugin:disabled:dock",
+ "second",
+ "first",
+ "third",
+ ];
+ const calls: Array<{scope: string; type?: string; previousType?: string}> = [];
+ const mover: TDockEntryMover = (scope, item, previousItem) => {
+ calls.push({
+ scope,
+ type: item.dataset.type,
+ previousType: previousItem?.dataset.type,
+ });
+ const target = getDockOrderContainer(scope, layout) as unknown as FakeDockContainer;
+ if (previousItem) {
+ (previousItem as unknown as FakeDockItem).after(item as unknown as FakeDockItem);
+ } else {
+ target.insertBefore(item as unknown as FakeDockItem, target.children[0]);
+ }
+ };
+
+ applyDockEntryOrderSnapshot(snapshot, layout, mover);
+
+ assert.deepEqual(calls, [{
+ scope: DOCK_ORDER_SCOPE_BY_POSITION.LeftTop,
+ type: "fourth",
+ previousType: undefined,
+ }, {
+ scope: DOCK_ORDER_SCOPE_BY_POSITION.LeftTop,
+ type: "third",
+ previousType: "first",
+ }, {
+ scope: DOCK_ORDER_SCOPE_BY_POSITION.LeftTop,
+ type: "second",
+ previousType: "fourth",
+ }]);
+ assert.deepEqual(leftTop.children, [fourth, second, first, third]);
+ assert.deepEqual(rightTop.children, []);
+ calls.length = 0;
+ assert.equal(applyDockEntryOrderSnapshot(snapshot, layout, mover), false);
+ assert.deepEqual(calls, []);
+});
+
test("dock ordering is applied at runtime and synchronized after direct dock moves", () => {
const runtimeSource = readFileSync(resolve(process.cwd(), "src/config/entryVisibility/runtime.ts"), "utf8");
const dockSource = readFileSync(resolve(process.cwd(), "src/layout/dock/index.ts"), "utf8");
+ const uiSource = readFileSync(resolve(process.cwd(), "src/config/entryVisibility/ui.ts"), "utf8");
assert.match(runtimeSource, /applyDockEntryOrderSnapshot\(mergeDockEntryOrderSnapshot\(/);
+ assert.match(runtimeSource, /const currentOrders = getCurrentDockEntryOrderSnapshot\(\);/);
+ assert.match(runtimeSource, /\{syncEntryOrders: false\}/);
assert.match(runtimeSource, /const key = getDockEntryKey\(item\);/);
- assert.match(dockSource, /syncDockEntryOrders\(\);/);
+ assert.match(dockSource, /options\.syncEntryOrders !== false/);
+ assert.match(uiSource, /data-entry-drop-scope/);
+ assert.match(uiSource, /moveDockEntryOrderSnapshot\(/);
});
diff --git a/app/src/config/entryVisibility/dockOrder.ts b/app/src/config/entryVisibility/dockOrder.ts
index 17040051ab..93e48584d7 100644
--- a/app/src/config/entryVisibility/dockOrder.ts
+++ b/app/src/config/entryVisibility/dockOrder.ts
@@ -16,6 +16,11 @@ export const DOCK_ORDER_SCOPE_BY_POSITION = {
export type TDockOrderScope = typeof DOCK_ORDER_SCOPE_BY_POSITION[TPluginDockPosition];
export type TDockOrderSnapshot = Record<TDockOrderScope, string[]>;
+export type TDockEntryMover = (
+ scope: TDockOrderScope,
+ item: HTMLElement,
+ previousItem?: HTMLElement,
+) => void;
export const DOCK_ORDER_SCOPES_BY_SIDE: Record<"left" | "right", readonly TDockOrderScope[]> = {
left: [
@@ -66,6 +71,59 @@ const createEmptySnapshot = (): TDockOrderSnapshot => Object.fromEntries(
DOCK_ORDER_SCOPES.map((scope) => [scope, []]),
) as TDockOrderSnapshot;
+const normalizeDockEntryOrderSnapshot = (
+ orders?: Partial<Record<string, readonly string[]>>,
+) => {
+ const snapshot = createEmptySnapshot();
+ const seen = new Set<string>();
+ DOCK_ORDER_SCOPES.forEach((scope) => {
+ const order = orders?.[scope];
+ if (!Array.isArray(order)) {
+ return;
+ }
+ order.forEach((key) => {
+ if (typeof key !== "string" || !key || seen.has(key)) {
+ return;
+ }
+ seen.add(key);
+ snapshot[scope].push(key);
+ });
+ });
+ return snapshot;
+};
+
+const getDockEntryOwners = (snapshot: TDockOrderSnapshot) => {
+ const owners = new Map<string, TDockOrderScope>();
+ DOCK_ORDER_SCOPES.forEach((scope) => snapshot[scope].forEach((key) => owners.set(key, scope)));
+ return owners;
+};
+
+const hasDockEntryOrders = (orders?: Partial<Record<string, readonly string[]>>) =>
+ DOCK_ORDER_SCOPES.some((scope) => Array.isArray(orders?.[scope]));
+
+const normalizeCurrentPlacementSavedOrders = (
+ orders: Partial<Record<string, readonly string[]>>,
+ currentOwners: ReadonlyMap<string, TDockOrderScope>,
+) => {
+ const snapshot = createEmptySnapshot();
+ const seen = new Set<string>();
+ DOCK_ORDER_SCOPES.forEach((scope) => {
+ const order = orders[scope];
+ if (!Array.isArray(order)) {
+ return;
+ }
+ order.forEach((key) => {
+ const currentOwner = currentOwners.get(key);
+ if (!key || seen.has(key) || currentOwner && currentOwner !== scope) {
+ return;
+ }
+ seen.add(key);
+ snapshot[scope].push(key);
+ });
+ });
+ return snapshot;
+};
+
export const getDockOrderScopePosition = (scope: TDockOrderScope) => DOCK_ORDER_SCOPE_META[scope].position;
export const getDockOrderScopeLabelKey = (scope: TDockOrderScope) => DOCK_ORDER_SCOPE_META[scope].labelKey;
@@ -121,20 +179,40 @@ export const createDockEntryOrderSnapshot = (
const mergeDockEntryOrders = (
current: TDockOrderSnapshot,
savedOrders?: Partial<Record<string, readonly string[]>>,
- useCurrentOrder = false,
- loadedKeys: ReadonlySet<string> = new Set(DOCK_ORDER_SCOPES.flatMap((scope) => current[scope])),
+ useCurrentPlacement = false,
) => {
+ const normalizedCurrent = normalizeDockEntryOrderSnapshot(current);
+ if (!hasDockEntryOrders(savedOrders)) {
+ return normalizedCurrent;
+ }
+ const currentOwners = getDockEntryOwners(normalizedCurrent);
+ const normalizedSaved = useCurrentPlacement
+ ? normalizeCurrentPlacementSavedOrders(savedOrders, currentOwners)
+ : normalizeDockEntryOrderSnapshot(savedOrders);
+ const savedOwners = getDockEntryOwners(normalizedSaved);
const snapshot = createEmptySnapshot();
DOCK_ORDER_SCOPES.forEach((scope) => {
- const currentKeys = new Set(current[scope]);
- const savedOrder = savedOrders?.[scope]?.filter((key) => !loadedKeys.has(key) || currentKeys.has(key));
+ const currentOrder = normalizedCurrent[scope];
+ const savedOrder = normalizedSaved[scope];
+ const defaultOrder = useCurrentPlacement
+ ? currentOrder
+ : currentOrder.filter((key) => !savedOwners.has(key) || savedOwners.get(key) === scope);
+ if (!useCurrentPlacement) {
+ const defaultKeys = new Set(defaultOrder);
+ savedOrder.forEach((key) => {
+ if (currentOwners.has(key) && !defaultKeys.has(key)) {
+ defaultKeys.add(key);
+ defaultOrder.push(key);
+ }
+ });
+ }
snapshot[scope] = mergeEntryOrderPreservingUnknown(
- current[scope],
- savedOrder ? [...savedOrder] : undefined,
- useCurrentOrder ? current[scope] : undefined,
+ defaultOrder,
+ savedOrder,
+ useCurrentPlacement ? currentOrder : undefined,
);
});
- return snapshot;
+ return normalizeDockEntryOrderSnapshot(snapshot);
};
export const mergeDockEntryOrderSnapshot = (
@@ -147,6 +225,39 @@ export const mergeCurrentDockEntryOrders = (
savedOrders?: Partial<Record<string, readonly string[]>>,
) => mergeDockEntryOrders(current, savedOrders, true);
+export const moveDockEntryOrderSnapshot = (
+ snapshot: TDockOrderSnapshot,
+ sourceKey: string,
+ targetScope: TDockOrderScope,
+ targetKey?: string,
+ after = false,
+) => {
+ if (!sourceKey || !isDockOrderScope(targetScope) || sourceKey === targetKey) {
+ return;
+ }
+ const normalized = normalizeDockEntryOrderSnapshot(snapshot);
+ const sourceScope = DOCK_ORDER_SCOPES.find((scope) => normalized[scope].includes(sourceKey));
+ if (!sourceScope) {
+ return;
+ }
+ if (targetKey && !normalized[targetScope].includes(targetKey)) {
+ return;
+ }
+ const moved = normalizeDockEntryOrderSnapshot(normalized);
+ DOCK_ORDER_SCOPES.forEach((scope) => {
+ moved[scope] = moved[scope].filter((key) => key !== sourceKey);
+ });
+ const targetOrder = moved[targetScope];
+ const targetIndex = targetKey
+ ? targetOrder.indexOf(targetKey) + (after ? 1 : 0)
+ : targetOrder.length;
+ targetOrder.splice(targetIndex, 0, sourceKey);
+ const changed = DOCK_ORDER_SCOPES.some((scope) =>
+ normalized[scope].length !== moved[scope].length ||
+ normalized[scope].some((key, index) => key !== moved[scope][index]));
+ return changed ? moved : undefined;
+};
+
const getContainerEntryKeys = (container?: HTMLElement) => {
if (!container) {
return [];
@@ -163,38 +274,110 @@ const getContainerEntryKeys = (container?: HTMLElement) => {
}, []);
};
-export const getDockEntryOrderSnapshot = (
+export const getCurrentDockEntryOrderSnapshot = (
layout: IDockOrderLayout = window.siyuan.layout,
) => {
const current: TDockOrdersByPosition = {};
DOCK_ORDER_SCOPES.forEach((scope) => {
current[getDockOrderScopePosition(scope)] = getContainerEntryKeys(getDockOrderContainer(scope, layout));
});
+ return createDockEntryOrderSnapshot(current);
+};
+
+export const getDockEntryOrderSnapshot = (
+ layout: IDockOrderLayout = window.siyuan.layout,
+) => {
+ const snapshot = getCurrentDockEntryOrderSnapshot(layout);
+ const seen = new Set(DOCK_ORDER_SCOPES.flatMap((scope) => snapshot[scope]));
const defaults = (getEntryCatalogChildren("dock") || []).map((item) => ({
key: item.key,
position: getDockEntryPosition(item.key),
}));
- return createDockEntryOrderSnapshot(current, defaults);
+ defaults.forEach((item) => {
+ if (!item.key || !item.position || seen.has(item.key)) {
+ return;
+ }
+ seen.add(item.key);
+ snapshot[DOCK_ORDER_SCOPE_BY_POSITION[item.position]].push(item.key);
+ });
+ return snapshot;
};
export const applyDockEntryOrderSnapshot = (
snapshot: TDockOrderSnapshot,
layout: IDockOrderLayout = window.siyuan.layout,
+ mover?: TDockEntryMover,
) => {
+ const normalized = normalizeDockEntryOrderSnapshot(snapshot);
+ const moveItem: TDockEntryMover = mover || ((scope, item, previousItem) => {
+ const container = getDockOrderContainer(scope, layout);
+ if (!container) {
+ return;
+ }
+ if (previousItem && Array.from(container.children).includes(previousItem)) {
+ previousItem.after(item);
+ return;
+ }
+ const firstItem = Array.from(container.children).find((child) => child.classList.contains("dock__item"));
+ if (firstItem && firstItem !== item) {
+ firstItem.before(item);
+ } else if (!Array.from(container.children).includes(item)) {
+ container.append(item);
+ }
+ });
+ const itemsByKey = new Map<string, HTMLElement>();
+ DOCK_ORDER_SCOPES.forEach((scope) => {
+ const container = getDockOrderContainer(scope, layout);
+ if (!container) {
+ return;
+ }
+ Array.from(container.children).forEach((item) => {
+ if (!item.classList.contains("dock__item")) {
+ return;
+ }
+ const key = getDockEntryKey(item);
+ if (key && !itemsByKey.has(key)) {
+ itemsByKey.set(key, item as HTMLElement);
+ }
+ });
+ });
let changed = false;
DOCK_ORDER_SCOPES.forEach((scope) => {
const container = getDockOrderContainer(scope, layout);
if (!container) {
return;
}
- const items = Array.from(container.children).filter((item): item is HTMLElement =>
- item.classList.contains("dock__item"));
- const ordered = reorderEntrySlots(items, snapshot[scope], getDockEntryKey);
- if (ordered.every((item, index) => item === items[index])) {
+ let previousItem: HTMLElement | undefined;
+ normalized[scope].forEach((key) => {
+ const item = itemsByKey.get(key);
+ if (!item) {
+ return;
+ }
+ if (!Array.from(container.children).includes(item)) {
+ moveItem(scope, item, previousItem);
+ changed = true;
+ }
+ previousItem = item;
+ });
+ });
+ DOCK_ORDER_SCOPES.forEach((scope) => {
+ const container = getDockOrderContainer(scope, layout);
+ if (!container) {
return;
}
- ordered.forEach((item) => container.append(item));
- changed = true;
+ const items = Array.from(container.children).filter((item): item is HTMLElement =>
+ item.classList.contains("dock__item"));
+ const ordered = reorderEntrySlots<HTMLElement>(items, normalized[scope], getDockEntryKey);
+ let previousItem: HTMLElement | undefined;
+ ordered.forEach((item, index) => {
+ const liveItems = Array.from(container.children).filter((child) =>
+ child.classList.contains("dock__item"));
+ if (liveItems[index] !== item) {
+ moveItem(scope, item, previousItem);
+ changed = true;
+ }
+ previousItem = item;
+ });
});
return changed;
};
diff --git a/app/src/config/entryVisibility/runtime.ts b/app/src/config/entryVisibility/runtime.ts
index eb0df9add4..b3cc387fa8 100644
--- a/app/src/config/entryVisibility/runtime.ts
+++ b/app/src/config/entryVisibility/runtime.ts
@@ -27,7 +27,9 @@ import {syncDockBarVisibility} from "../../layout/dock/barVisibility";
import {genUUID} from "../../util/genID";
import {
applyDockEntryOrderSnapshot,
+ getCurrentDockEntryOrderSnapshot,
getDockEntryOrderSnapshot,
+ getDockOrderScopePosition,
isDockOrderScope,
mergeCurrentDockEntryOrders,
mergeDockEntryOrderSnapshot,
@@ -201,7 +203,7 @@ export const syncDockEntryOrders = () => {
return;
}
refreshDockCatalog(window.siyuan.ws?.app?.plugins || []);
- const currentOrders = getDockEntryOrderSnapshot();
+ const currentOrders = getCurrentDockEntryOrderSnapshot();
const config = cloneEntryVisibilityConfig();
const profile = getWritableEntryProfile(config);
profile.orders ||= {};
@@ -344,7 +346,16 @@ export const applyDockEntryVisibility = () => {
applyDockEntryOrderSnapshot(mergeDockEntryOrderSnapshot(
getDockEntryOrderSnapshot(),
getActiveEntryProfile()?.orders,
- ));
+ ), undefined, (scope, item, previousItem) => {
+ const position = getDockOrderScopePosition(scope);
+ const dock = position.startsWith("Left")
+ ? window.siyuan.layout.leftDock
+ : position.startsWith("Right")
+ ? window.siyuan.layout.rightDock
+ : window.siyuan.layout.bottomDock;
+ const index = position === "LeftBottom" || position === "RightBottom" || position === "BottomRight" ? 1 : 0;
+ dock?.add(index, item, previousItem?.getAttribute("data-type") || undefined, {syncEntryOrders: false});
+ });
document.querySelectorAll<HTMLElement>(".dock__item[data-type]").forEach((item) => {
const type = item.dataset.type;
const key = getDockEntryKey(item);
diff --git a/app/src/config/entryVisibility/ui.ts b/app/src/config/entryVisibility/ui.ts
index e505a6a66b..00c544aa7c 100644
--- a/app/src/config/entryVisibility/ui.ts
+++ b/app/src/config/entryVisibility/ui.ts
@@ -41,11 +41,13 @@ import {
} from "./profile";
import {getHostCapabilities} from "../../util/hostCapabilities";
import {
+ DOCK_ORDER_SCOPES,
DOCK_ORDER_SCOPES_BY_SIDE,
getDockEntryOrderSnapshot,
getDockOrderScopeLabelKey,
isDockOrderScope,
mergeDockEntryOrderSnapshot,
+ moveDockEntryOrderSnapshot,
TDockOrderScope,
TDockOrderSnapshot,
} from "./dockOrder";
@@ -234,16 +236,10 @@ const renderEntrySwitch = (profile: Config.IEntryVisibilityProfile, path: string
getEntryCatalogDefaultVisibility(path)) ? " checked" : ""}>`;
};
-const renderEntryColumn = (profile: Config.IEntryVisibilityProfile, title: string, prefix: string,
- nodes: IEntryCatalogNode[], depth: number, selectedPaths: string[],
- parentEnabled: boolean, readOnly: boolean, sortable: boolean,
- getItemPath = (item: IEntryCatalogNode) => `${prefix}.${item.key}`) => `<section class="config-entry-visibility__column"
- data-entry-column data-entry-depth="${depth}">
- <div class="config-entry-visibility__column-title">
- <span class="fn__ellipsis fn__flex-1" title="${escapeAttr(title)}">${escapeHtml(title)}</span>
- </div>
- <div class="config-entry-visibility__column-list">
- ${nodes.map((item) => {
+const renderEntryRows = (profile: Config.IEntryVisibilityProfile, prefix: string,
+ nodes: IEntryCatalogNode[], depth: number, selectedPaths: string[],
+ parentEnabled: boolean, readOnly: boolean, sortable: boolean,
+ getItemPath = (item: IEntryCatalogNode) => `${prefix}.${item.key}`) => nodes.map((item) => {
const path = getItemPath(item);
const configurable = isEntryCatalogNodeConfigurable(item);
const draggable = sortable && parentEnabled && configurable;
@@ -274,7 +270,18 @@ const renderEntryColumn = (profile: Config.IEntryVisibilityProfile, title: strin
<svg><use xlink:href="#iconRight"></use></svg>
</button>` : '<span class="config-entry-visibility__arrow-space"></span>'}
</${rowTag}>`;
- }).join("")}
+ }).join("");
+
+const renderEntryColumn = (profile: Config.IEntryVisibilityProfile, title: string, prefix: string,
+ nodes: IEntryCatalogNode[], depth: number, selectedPaths: string[],
+ parentEnabled: boolean, readOnly: boolean, sortable: boolean,
+ getItemPath = (item: IEntryCatalogNode) => `${prefix}.${item.key}`) => `<section class="config-entry-visibility__column"
+ data-entry-column data-entry-depth="${depth}">
+ <div class="config-entry-visibility__column-title">
+ <span class="fn__ellipsis fn__flex-1" title="${escapeAttr(title)}">${escapeHtml(title)}</span>
+ </div>
+ <div class="config-entry-visibility__column-list">
+ ${renderEntryRows(profile, prefix, nodes, depth, selectedPaths, parentEnabled, readOnly, sortable, getItemPath)}
</div>
</section>`;
@@ -315,7 +322,6 @@ type TDockSide = keyof typeof DOCK_ORDER_SCOPES_BY_SIDE;
const DOCK_SECTION_KEY = "dock";
const DOCK_SIDES = Object.keys(DOCK_ORDER_SCOPES_BY_SIDE) as TDockSide[];
-const getDockSidePath = (side: TDockSide) => `${DOCK_SECTION_KEY}.side.${side}`;
const getDockSideLabel = (side: TDockSide) => `${window.siyuan.languages.entryDock} - ${
window.siyuan.languages[side === "left" ? "marginLeft" : "marginRight"]}`;
@@ -338,45 +344,17 @@ const getEntryOrderContext = (parentPath: string, dockOrderSnapshot: TDockOrderS
};
};
-const renderEntryNavigationColumn = (
- title: string,
- items: Array<{label: string; path: string}>,
- depth: number,
- selectedPath?: string,
-) => `<section class="config-entry-visibility__column" data-entry-column data-entry-depth="${depth}">
- <div class="config-entry-visibility__column-title">
- <span class="fn__ellipsis fn__flex-1" title="${escapeAttr(title)}">${escapeHtml(title)}</span>
- </div>
- <div class="config-entry-visibility__column-list">
- ${items.map((item) => `<div class="config-entry-visibility__row config-entry-visibility__row--navigable${
- selectedPath === item.path ? " config-entry-visibility__row--current" : ""}"
- data-action="navigate-entry" data-entry-path="${escapeAttr(item.path)}" data-entry-depth="${depth}">
- <button class="config-entry-visibility__navigate" data-action="navigate-entry"
- data-entry-path="${escapeAttr(item.path)}" data-entry-depth="${depth}" title="${escapeAttr(item.label)}">
- <span>${escapeHtml(item.label)}</span>
- </button>
- <button class="block__icon block__icon--show config-entry-visibility__arrow" data-action="navigate-entry"
- data-entry-path="${escapeAttr(item.path)}" data-entry-depth="${depth}"
- aria-label="${escapeAttr(window.siyuan.languages.expand)}">
- <svg><use xlink:href="#iconRight"></use></svg>
- </button>
- </div>`).join("")}
- </div>
-</section>`;
-
const getDockScopeLabel = (scope: TDockOrderScope) => {
const labelKey = getDockOrderScopeLabelKey(scope);
return window.siyuan.languages[labelKey] || labelKey;
};
const getDockScopeNodes = (
- profile: Config.IEntryVisibilityProfile,
scope: TDockOrderScope,
snapshot: TDockOrderSnapshot,
) => {
- const context = getEntryOrderContext(scope, snapshot);
- const nodes = new Map(context.nodes.map((item) => [item.key, item]));
- return resolveProfileEntryOrder(profile, scope, context.defaultOrder, context.separatorKeys)
+ const nodes = new Map((getEntryCatalogChildren(DOCK_SECTION_KEY) || []).map((item) => [item.key, item]));
+ return snapshot[scope]
.map((key) => nodes.get(key))
.filter((item): item is IEntryCatalogNode => Boolean(item));
};
@@ -384,57 +362,49 @@ const getDockScopeNodes = (
const renderDockColumns = (
columns: string[],
profile: Config.IEntryVisibilityProfile,
- section: IEntryCatalogSection,
selectedPaths: string[],
readOnly: boolean,
snapshot: TDockOrderSnapshot,
visiblePaths?: Set<string>,
) => {
- const sideItems = DOCK_SIDES.map((side) => ({
- label: getDockSideLabel(side),
- path: getDockSidePath(side),
- }));
- columns.push(renderEntryNavigationColumn(section.label(), sideItems, 0, selectedPaths[0]));
- const selectedSide = DOCK_SIDES.find((side) => getDockSidePath(side) === selectedPaths[0]);
- if (!selectedSide) {
- return;
- }
- const scopes = DOCK_ORDER_SCOPES_BY_SIDE[selectedSide];
- const scopeItems = scopes.map((scope) => ({
- label: getDockScopeLabel(scope),
- path: scope,
- }));
- columns.push(renderEntryNavigationColumn(getDockSideLabel(selectedSide), scopeItems, 1, selectedPaths[1]));
- const selectedScope = scopes.find((scope) => scope === selectedPaths[1]);
- if (!selectedScope) {
- return;
- }
- const nodes = getDockScopeNodes(profile, selectedScope, snapshot);
- const visibleNodes = visiblePaths
- ? nodes.filter((item) => visiblePaths.has(`${DOCK_SECTION_KEY}.${item.key}`))
- : nodes;
- columns.push(renderEntryColumn(
+ const profileSnapshot = mergeDockEntryOrderSnapshot(snapshot, profile.orders);
+ DOCK_SIDES.forEach((side) => {
+ const groups = DOCK_ORDER_SCOPES_BY_SIDE[side].map((scope) => {
+ const scopeLabel = getDockScopeLabel(scope);
+ const nodes = getDockScopeNodes(scope, profileSnapshot);
+ const visibleNodes = visiblePaths
+ ? nodes.filter((item) => visiblePaths.has(`${DOCK_SECTION_KEY}.${item.key}`))
+ : nodes;
+ return `<section class="config-entry-visibility__dock-group" data-entry-drop-scope="${scope}">
+ <div class="config-entry-visibility__dock-group-title" title="${escapeAttr(scopeLabel)}">${escapeHtml(scopeLabel)}</div>
+ <div class="config-entry-visibility__dock-list" data-entry-drop-scope="${scope}">
+ ${renderEntryRows(
profile,
- getDockScopeLabel(selectedScope),
- selectedScope,
+ scope,
visibleNodes,
- 2,
+ 0,
selectedPaths,
true,
readOnly,
!visiblePaths && !readOnly,
(item) => `${DOCK_SECTION_KEY}.${item.key}`,
- ));
+ )}
+ ${visibleNodes.length === 0
+ ? `<div class="config-entry-visibility__dock-empty">${window.siyuan.languages.emptyContent}</div>`
+ : ""}
+ </div>
+ </section>`;
+ }).join("");
+ columns.push(`<section class="config-entry-visibility__column config-entry-visibility__dock-column" data-entry-column>
+ <div class="config-entry-visibility__column-title">
+ <span class="fn__ellipsis fn__flex-1" title="${escapeAttr(getDockSideLabel(side))}">${escapeHtml(getDockSideLabel(side))}</span>
+ </div>
+ <div class="config-entry-visibility__column-list">${groups}</div>
+ </section>`);
+ });
};
-const getDockEntrySelectedPaths = (snapshot: TDockOrderSnapshot, key: string) => {
- for (const side of DOCK_SIDES) {
- const scope = DOCK_ORDER_SCOPES_BY_SIDE[side].find((item) => snapshot[item].includes(key));
- if (scope) {
- return [getDockSidePath(side), scope, `${DOCK_SECTION_KEY}.${key}`];
- }
- }
-};
+const getDockEntrySelectedPaths = (key: string) => [`${DOCK_SECTION_KEY}.${key}`];
const renderEntryColumns = (profile: Config.IEntryVisibilityProfile, sectionKey: string,
selectedPaths: string[], readOnly: boolean, visiblePaths?: Set<string>,
@@ -451,7 +421,7 @@ const renderEntryColumns = (profile: Config.IEntryVisibilityProfile, sectionKey:
</section>`;
const columns = [locationColumn];
if (section.key === DOCK_SECTION_KEY) {
- renderDockColumns(columns, profile, section, selectedPaths, readOnly, dockOrderSnapshot, visiblePaths);
+ renderDockColumns(columns, profile, selectedPaths, readOnly, dockOrderSnapshot, visiblePaths);
return `<div class="config-entry-visibility__columns">${columns.join("")}</div>`;
}
const directDisplayRoot = getDirectDisplayRoot(section);
@@ -595,11 +565,19 @@ const openProfileEditor = (root: HTMLElement, profileID?: string) => {
let selectedSectionKey = entryCatalog[0].key;
let selectedPaths: string[] = [];
let previousQuery = "";
- let dragging: {parentPath: string; sourceKey: string; defaultOrder?: string[]; order?: string[]} | undefined;
+ let dragging: {
+ parentPath: string;
+ sourceKey: string;
+ defaultOrder?: string[];
+ order?: string[];
+ dockOrder?: TDockOrderSnapshot;
+ } | undefined;
const clearDropTarget = () => {
browser.querySelectorAll(".config-entry-visibility__row--drop-before, .config-entry-visibility__row--drop-after")
.forEach((item) => item.classList.remove("config-entry-visibility__row--drop-before",
"config-entry-visibility__row--drop-after"));
+ browser.querySelectorAll(".config-entry-visibility__dock-group--drop")
+ .forEach((item) => item.classList.remove("config-entry-visibility__dock-group--drop"));
};
const renderBrowser = (scrollToEnd = false, resetEntryColumns = false, revealSelection = false) => {
const oldColumns = Array.from(browser.querySelectorAll<HTMLElement>("[data-entry-column]"));
@@ -619,7 +597,7 @@ const openProfileEditor = (root: HTMLElement, profileID?: string) => {
const target = filter.results.find((item) => item.section.key === selectedSectionKey) || filter.results[0];
selectedSectionKey = target.section.key;
selectedPaths = target.section.key === DOCK_SECTION_KEY
- ? getDockEntrySelectedPaths(dockOrderSnapshot, target.item.key) || []
+ ? getDockEntrySelectedPaths(target.item.key)
: getEntryCatalogPathChain(target.section.key, target.path);
scrollToEnd = true;
resetEntryColumns = true;
@@ -678,6 +656,40 @@ const openProfileEditor = (root: HTMLElement, profileID?: string) => {
return;
}
const row = (event.target as Element).closest<HTMLElement>("[data-entry-row]");
+ if (isDockOrderScope(dragging.parentPath)) {
+ const dropScopeElement = (event.target as Element).closest<HTMLElement>("[data-entry-drop-scope]");
+ const targetScopeValue = row?.dataset.entryParent || dropScopeElement?.dataset.entryDropScope || "";
+ if (!isDockOrderScope(targetScopeValue)) {
+ clearDropTarget();
+ dragging.dockOrder = undefined;
+ return;
+ }
+ const targetKey = row?.dataset.entryParent === targetScopeValue ? row.dataset.entryKey : undefined;
+ const after = targetKey
+ ? event.clientY >= row.getBoundingClientRect().top + row.offsetHeight / 2
+ : undefined;
+ const movedOrder = moveDockEntryOrderSnapshot(
+ mergeDockEntryOrderSnapshot(dockOrderSnapshot, draft.orders),
+ dragging.sourceKey,
+ targetScopeValue,
+ targetKey,
+ after,
+ );
+ clearDropTarget();
+ dragging.dockOrder = movedOrder;
+ if (!movedOrder) {
+ return;
+ }
+ event.preventDefault();
+ event.dataTransfer.dropEffect = "move";
+ if (targetKey) {
+ row.classList.add(`config-entry-visibility__row--drop-${after ? "after" : "before"}`);
+ } else {
+ dropScopeElement?.closest(".config-entry-visibility__dock-group")
+ ?.classList.add("config-entry-visibility__dock-group--drop");
+ }
+ return;
+ }
if (!row || row.dataset.entryParent !== dragging.parentPath || !row.dataset.entryKey) {
clearDropTarget();
dragging.order = undefined;
@@ -704,6 +716,19 @@ const openProfileEditor = (root: HTMLElement, profileID?: string) => {
row.classList.add(`config-entry-visibility__row--drop-${after ? "after" : "before"}`);
});
browser.addEventListener("drop", (event: DragEvent) => {
+ if (dragging && isDockOrderScope(dragging.parentPath)) {
+ if (!dragging.dockOrder) {
+ return;
+ }
+ event.preventDefault();
+ draft.orders ||= {};
+ DOCK_ORDER_SCOPES.forEach((scope) => {
+ draft.orders[scope] = [...dragging.dockOrder[scope]];
+ });
+ dragging = undefined;
+ renderBrowser();
+ return;
+ }
if (!dragging?.defaultOrder || !dragging.order) {
return;
}
@@ -722,9 +747,6 @@ const openProfileEditor = (root: HTMLElement, profileID?: string) => {
dragging.order,
separatorKeys,
);
- if (isDockOrderScope(dragging.parentPath)) {
- Object.assign(draft.orders, mergeDockEntryOrderSnapshot(dockOrderSnapshot, draft.orders));
- }
dragging = undefined;
renderBrowser();
});
diff --git a/app/src/layout/dock/index.ts b/app/src/layout/dock/index.ts
index 0b04c15a85..38845d3cc3 100644
--- a/app/src/layout/dock/index.ts
+++ b/app/src/layout/dock/index.ts
@@ -1001,7 +1001,9 @@ export class Dock {
}
}
- public add(index: number, sourceElement: Element, previousType?: string) {
+ public add(index: number, sourceElement: Element, previousType?: string, options: {
+ syncEntryOrders?: boolean,
+ } = {}) {
const type = sourceElement.getAttribute("data-type") as TDock;
const sourceDock = getDockByType(type);
// 仅在左右轴与下轴之间跨轴移动时清除尺寸:左右侧之间或下侧内部移动,原有尺寸维度仍然有效
@@ -1032,7 +1034,13 @@ export class Dock {
sourceElement.setAttribute("data-index", index.toString());
sourceElement.setAttribute("data-position", this.getTooltipPosition(index));
if (previousType) {
- this.elements[index].parentElement.querySelector(`[data-type="${previousType}"]`).after(sourceElement);
+ const previousElement = Array.from(this.elements[index].children)
+ .find((item) => item.getAttribute("data-type") === previousType);
+ if (previousElement) {
+ previousElement.after(sourceElement);
+ } else {
+ this.elements[index].insertAdjacentElement("afterbegin", sourceElement);
+ }
} else {
this.elements[index].insertAdjacentElement("afterbegin", sourceElement);
}
@@ -1064,7 +1072,9 @@ export class Dock {
adjustDockPadding();
this.adjustSplit();
sourceDock.adjustSplit();
- syncDockEntryOrders();
+ if (options.syncEntryOrders !== false) {
+ syncDockEntryOrders();
+ }
}
public remove(key: TDock | string) {