@api-client/ui 0.0.10 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc +8 -1
- package/demo/index.html +3 -0
- package/demo/layout/index.html +91 -0
- package/demo/layout/index.ts +182 -0
- package/dist/elements/layout/SplitItem.d.ts +1 -9
- package/dist/elements/layout/SplitItem.d.ts.map +1 -1
- package/dist/elements/layout/SplitItem.js +27 -20
- package/dist/elements/layout/SplitItem.js.map +1 -1
- package/dist/elements/layout/SplitLayout.d.ts +16 -14
- package/dist/elements/layout/SplitLayout.d.ts.map +1 -1
- package/dist/elements/layout/SplitLayout.js +47 -42
- package/dist/elements/layout/SplitLayout.js.map +1 -1
- package/dist/elements/layout/SplitPanel.d.ts +7 -2
- package/dist/elements/layout/SplitPanel.d.ts.map +1 -1
- package/dist/elements/layout/SplitPanel.js +130 -52
- package/dist/elements/layout/SplitPanel.js.map +1 -1
- package/dist/elements/layout/SplitView.d.ts.map +1 -1
- package/dist/elements/layout/SplitView.js +18 -14
- package/dist/elements/layout/SplitView.js.map +1 -1
- package/dist/elements/layout/type.d.ts +3 -3
- package/dist/elements/layout/type.d.ts.map +1 -1
- package/dist/elements/layout/type.js.map +1 -1
- package/dist/pages/http-project/HttpClientCommands.d.ts.map +1 -1
- package/dist/pages/http-project/HttpClientCommands.js +28 -12
- package/dist/pages/http-project/HttpClientCommands.js.map +1 -1
- package/package.json +2 -1
- package/src/elements/layout/SplitItem.ts +29 -21
- package/src/elements/layout/SplitLayout.ts +53 -43
- package/src/elements/layout/SplitPanel.ts +140 -57
- package/src/elements/layout/SplitView.ts +18 -15
- package/src/elements/layout/type.ts +3 -4
- package/src/pages/http-project/HttpClientCommands.ts +28 -12
- package/test/elements/layout/SplitItem.test.ts +76 -75
- package/test/elements/layout/SplitLayoutManager.test.ts +70 -69
- package/test/elements/layout/SplitPanel.test.ts +10 -7
- package/tsconfig.eslint.json +8 -0
- package/web-test-runner.config.mjs +4 -1
- package/dist/define/layout/layout-panel.d.ts +0 -7
- package/dist/define/layout/layout-panel.d.ts.map +0 -1
- package/dist/define/layout/layout-panel.js +0 -3
- package/dist/define/layout/layout-panel.js.map +0 -1
- package/dist/elements/layout/LayoutManager.d.ts +0 -327
- package/dist/elements/layout/LayoutManager.d.ts.map +0 -1
- package/dist/elements/layout/LayoutManager.js +0 -747
- package/dist/elements/layout/LayoutManager.js.map +0 -1
- package/dist/elements/layout/LayoutPanelElement.d.ts +0 -62
- package/dist/elements/layout/LayoutPanelElement.d.ts.map +0 -1
- package/dist/elements/layout/LayoutPanelElement.js +0 -628
- package/dist/elements/layout/LayoutPanelElement.js.map +0 -1
- package/src/define/layout/layout-panel.ts +0 -9
- package/src/elements/layout/LayoutManager.ts +0 -930
- package/src/elements/layout/LayoutPanelElement.ts +0 -651
|
@@ -62,7 +62,7 @@ export class SplitLayout extends EventTarget {
|
|
|
62
62
|
return value;
|
|
63
63
|
}
|
|
64
64
|
const item = value;
|
|
65
|
-
return this.
|
|
65
|
+
return this.getParents(item.key)[0];
|
|
66
66
|
}
|
|
67
67
|
/**
|
|
68
68
|
* An active panel item that the user last interacted with.
|
|
@@ -260,22 +260,25 @@ export class SplitLayout extends EventTarget {
|
|
|
260
260
|
return layout || undefined;
|
|
261
261
|
}
|
|
262
262
|
/**
|
|
263
|
-
* Finds
|
|
264
|
-
*
|
|
265
|
-
*
|
|
263
|
+
* Finds parents an item or another panel is anchored to.
|
|
264
|
+
* An item can have multiple parents. A panel can only have a single parent.
|
|
265
|
+
*
|
|
266
|
+
* @param itemOrPanelKey The key of the panel or an item.
|
|
267
|
+
* @returns THe list of panels the item is added. It can only return up to 1 result when looking for a panel's parent.
|
|
266
268
|
*/
|
|
267
|
-
|
|
269
|
+
getParents(itemOrPanelKey) {
|
|
270
|
+
const result = [];
|
|
268
271
|
for (const { type, value } of this.definitions.values()) {
|
|
269
272
|
if (type !== LayoutType.panel) {
|
|
270
273
|
continue;
|
|
271
274
|
}
|
|
272
275
|
const panel = value;
|
|
273
|
-
const
|
|
274
|
-
if (
|
|
275
|
-
|
|
276
|
+
const has = panel.items.some(i => i.key === itemOrPanelKey);
|
|
277
|
+
if (has) {
|
|
278
|
+
result.push(panel);
|
|
276
279
|
}
|
|
277
280
|
}
|
|
278
|
-
return
|
|
281
|
+
return result;
|
|
279
282
|
}
|
|
280
283
|
/**
|
|
281
284
|
* Finds a panel by id.
|
|
@@ -335,12 +338,15 @@ export class SplitLayout extends EventTarget {
|
|
|
335
338
|
* Do not call this method from the outside of the layout manager logic.
|
|
336
339
|
* It is a way to communicate a tab was closed.
|
|
337
340
|
*/
|
|
338
|
-
notifyTabClose(itemKey) {
|
|
341
|
+
notifyTabClose(itemKey, panel) {
|
|
339
342
|
this.dispatchEvent(new CustomEvent('closetab', {
|
|
340
343
|
bubbles: true,
|
|
341
344
|
cancelable: true,
|
|
342
345
|
composed: true,
|
|
343
|
-
detail:
|
|
346
|
+
detail: {
|
|
347
|
+
tab: itemKey,
|
|
348
|
+
panel,
|
|
349
|
+
},
|
|
344
350
|
}));
|
|
345
351
|
}
|
|
346
352
|
/**
|
|
@@ -368,10 +374,8 @@ export class SplitLayout extends EventTarget {
|
|
|
368
374
|
const before = item.label;
|
|
369
375
|
this.dispatchNameItem(item);
|
|
370
376
|
if (before !== item.label) {
|
|
371
|
-
const
|
|
372
|
-
|
|
373
|
-
this.updateView(panel.key);
|
|
374
|
-
}
|
|
377
|
+
const panels = this.getParents(item.key);
|
|
378
|
+
panels.forEach(panel => this.updateView(panel.key));
|
|
375
379
|
}
|
|
376
380
|
}
|
|
377
381
|
/**
|
|
@@ -386,8 +390,8 @@ export class SplitLayout extends EventTarget {
|
|
|
386
390
|
const before = item.label;
|
|
387
391
|
this.dispatchNameItem(item);
|
|
388
392
|
if (before !== item.label) {
|
|
389
|
-
const
|
|
390
|
-
updatePanels.add(panel);
|
|
393
|
+
const panels = this.getParents(item.key);
|
|
394
|
+
panels.forEach(panel => updatePanels.add(panel));
|
|
391
395
|
}
|
|
392
396
|
}
|
|
393
397
|
for (const panel of updatePanels) {
|
|
@@ -465,7 +469,9 @@ export class SplitLayout extends EventTarget {
|
|
|
465
469
|
return panel.addItem(item);
|
|
466
470
|
}
|
|
467
471
|
/**
|
|
468
|
-
* Removes an item from layout.
|
|
472
|
+
* Removes an item from the layout. This means removing an item from all panels.
|
|
473
|
+
* If you want to remove an item from a specific panel then find the panel first and then call `removeItem()`.
|
|
474
|
+
*
|
|
469
475
|
* @param key The key of the item to remove.
|
|
470
476
|
*/
|
|
471
477
|
removeItem(key) {
|
|
@@ -473,26 +479,25 @@ export class SplitLayout extends EventTarget {
|
|
|
473
479
|
if (!item) {
|
|
474
480
|
return;
|
|
475
481
|
}
|
|
476
|
-
const
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
}
|
|
482
|
+
const parents = this.getParents(key);
|
|
483
|
+
parents.forEach(parent => parent.removeChildItem(item));
|
|
484
|
+
}
|
|
485
|
+
// /**
|
|
486
|
+
// * Removes other items relative to the `key` item.
|
|
487
|
+
// * @param key The key of the item to perform a relative operation from.
|
|
488
|
+
// * @param dir The direction to which close other items. Default to both directions leaving only the `key` item
|
|
489
|
+
// * @deprecated this function does not work as intended. Find the parent panel first and then call the `removeRelative()`.
|
|
490
|
+
// */
|
|
491
|
+
// removeRelative(key: string, dir?: SplitCloseDirection): void {
|
|
492
|
+
// const item = this.findItem(key);
|
|
493
|
+
// if (!item) {
|
|
494
|
+
// return;
|
|
495
|
+
// }
|
|
496
|
+
// const panel = item.getParent();
|
|
497
|
+
// if (panel) {
|
|
498
|
+
// panel.removeRelative(key, dir);
|
|
499
|
+
// }
|
|
500
|
+
// }
|
|
496
501
|
/**
|
|
497
502
|
* Moves a tab between panels or inside a panel
|
|
498
503
|
*
|
|
@@ -501,14 +506,14 @@ export class SplitLayout extends EventTarget {
|
|
|
501
506
|
* @param itemKey The key of the item
|
|
502
507
|
* @param toIndex The index to which add the item. Default as the last.
|
|
503
508
|
*/
|
|
504
|
-
moveItem(fromPanelKey, toPanelKey, itemKey,
|
|
509
|
+
moveItem(fromPanelKey, toPanelKey, itemKey, opts) {
|
|
505
510
|
const singlePanel = fromPanelKey === toPanelKey;
|
|
506
511
|
const from = this.findPanel(fromPanelKey);
|
|
507
512
|
if (!from) {
|
|
508
513
|
throw new Error(`Source layout panel not found.`);
|
|
509
514
|
}
|
|
510
515
|
if (singlePanel) {
|
|
511
|
-
from.moveItem(itemKey,
|
|
516
|
+
from.moveItem(itemKey, opts);
|
|
512
517
|
}
|
|
513
518
|
else {
|
|
514
519
|
const to = this.findPanel(toPanelKey);
|
|
@@ -519,7 +524,7 @@ export class SplitLayout extends EventTarget {
|
|
|
519
524
|
if (!removed) {
|
|
520
525
|
throw new Error(`Item not found.`);
|
|
521
526
|
}
|
|
522
|
-
to.addItem(removed,
|
|
527
|
+
to.addItem(removed, opts);
|
|
523
528
|
}
|
|
524
529
|
this.notifyChange();
|
|
525
530
|
}
|
|
@@ -615,7 +620,7 @@ export class SplitLayout extends EventTarget {
|
|
|
615
620
|
}
|
|
616
621
|
else {
|
|
617
622
|
// any panel that has the item
|
|
618
|
-
panel = this.
|
|
623
|
+
[panel] = this.getParents(itemKey);
|
|
619
624
|
}
|
|
620
625
|
if (!panel) {
|
|
621
626
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SplitLayout.js","sourceRoot":"","sources":["../../../src/elements/layout/SplitLayout.ts"],"names":[],"mappings":"AAEA,OAAO,EAAc,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAe,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE1D,OAAO,EAAgB,UAA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K,GAAG,WAAW,CAAC;SACrB;aAAM;YACL,8BAA8B;YAC9B,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;SACjC;QACD,IAAI,CAAC,KAAK,EAAE;YACV,OAAO;SACR;QACD,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC;QACzB,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC3B,IAAI,CAAC,YAAY,EAAE,CAAC;IACtB,CAAC;IAED;;;;OAIG;IACH,OAAO;QACL,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,aAAa,EAAE,EAAE;YACxC,IAAI,KAAK,CAAC,QAAQ,EAAE;gBAClB,OAAO,KAAK,CAAC;aACd;SACF;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,CAAC,YAAqC;QAC1C,MAAM,MAAM,GAAqB,EAAE,CAAC;QACpC,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;QACvB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;YACxB,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACvC,MAAM,OAAO,GAAG,KAAK,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC;YAC5C,IAAI,OAAO,EAAE;gBACX,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;aACtB;SACF;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF","sourcesContent":["/* eslint-disable import/no-cycle */\nimport { TemplateResult } from \"lit\";\nimport { ISplitItem, SplitItem } from \"./SplitItem.js\";\nimport { ISplitPanel, SplitPanel } from \"./SplitPanel.js\";\nimport SplitView from \"./SplitView.js\";\nimport { IPanelObject, LayoutType, SplitCloseDirection, SplitDirection, SplitItemRenderCallback, SplitLayoutInit, SplitPanelAddOptions } from \"./type.js\";\n\ninterface LayoutObject {\n type: LayoutType;\n value: SplitItem | SplitPanel;\n}\n\ninterface SerializedLayoutObject {\n type: LayoutType;\n value: ISplitItem | ISplitPanel;\n}\n\nexport interface ISplitLayout {\n /**\n * The map of all definitions of panels and \n */\n definitions: SerializedLayoutObject[];\n\n /**\n * The ordered list of panel keys in the view.\n */\n items: string[];\n\n /**\n * The key of the active panel or item.\n * From here it can be deduced whether the active item is a panel or an item and what's the active panel.\n */\n active?: string;\n}\n\n/**\n * Split layout manager creates a view where the application can put \"items\" into\n * and render them inside \"panels\". The application can create as many panels as needed.\n * Panels can be layout vertically or horizontally.\n * \n * ## Basic usage\n * \n * ```javascript\n * const layout = new SplitLayout({\n * stateCallback: async (state: ISplitLayout): Promise<void> => { \n * localStorage.setItem('layout', JSON.stringify(state));\n * }\n * });\n * const restored = await readStoredState(); // a function that reads the state from the store\n * await layout.initialize(restored);\n * \n * const content = layout.render((itemToRender: SplitItem): TemplateResult => { return html`...` });\n * ```\n * \n * Each time the layout configuration change the optional `stateCallback` function \n * is called.\n * It's not mandatory to set this callback function but if you want the state to\n * persist you have to serialize the manager manually when needed.\n * Since the manage implement the `toJSON()` method it is safe to pass the instance of the manager\n * to a idb store or serialize with `JSON.stringify()`.\n * \n * @fires change - When the layout configuration change. This is the best time to perform DOM update.\n * @fires nameitem - When the layout requests to name an item. This usually happens then a code calls the `requestNameUpdate()` method after the item's name changed.\n * @fires closetab - When a tab wa closed via a user interaction.\n */\nexport class SplitLayout extends EventTarget {\n /**\n * The list of all definitions of panels and items.\n */\n definitions = new Map<string, LayoutObject>();\n\n /**\n * Holds an ordered list of panels in the layout.\n * Though, this interface is consistent with other panels, it can only keep panels, not items.\n */\n items: IPanelObject[] = [];\n\n private activeInternal?: string;\n\n /**\n * The key of the panel that is marked as \"active\", that is, \n * the panel the user last interacted with.\n */\n get active(): string | undefined {\n return this.activeInternal;\n }\n\n /**\n * Returns an object that is marked as active or undefined if none is marked as active.\n */\n get activeObject(): LayoutObject | undefined {\n const { activeInternal } = this;\n if (!activeInternal) {\n return undefined;\n }\n return this.definitions.get(activeInternal);\n }\n\n /**\n * An active panel that the user last interacted with.\n */\n get activePanel(): SplitPanel | undefined {\n const { activeObject } = this;\n if (!activeObject) {\n return undefined;\n }\n const { type, value } = activeObject;\n if (type === LayoutType.panel) {\n return value as SplitPanel;\n }\n const item = value as SplitItem;\n return this.getParent(item.key);\n }\n\n /**\n * An active panel item that the user last interacted with.\n */\n get activeItem(): SplitItem | undefined {\n const { activeObject } = this;\n if (!activeObject) {\n return undefined;\n }\n const { type, value } = activeObject;\n if (type === LayoutType.item) {\n return value as SplitItem;\n }\n return undefined;\n }\n\n /**\n * Whether the manager is dirty, that is, a change ocurred\n * while storing the layout.\n */\n protected isDirty = false;\n\n /**\n * A flag that determines that the state is being stored in the store.\n */\n protected storing = false;\n\n /**\n * The value of the debouncer timeout.\n */\n protected debouncer?: number;\n\n constructor(public options: SplitLayoutInit = {}) {\n super();\n this.handleFocusIn = this.handleFocusIn.bind(this);\n }\n\n /**\n * Initializes the split layout manager.\n * When passed the `state` parameter it restores the previously serialized state.\n * \n * @param state A state to restore. When not set an empty layout is rendered.\n */\n initialize(state?: ISplitLayout): void {\n if (state) {\n this.new(state);\n }\n document.body.addEventListener('focusin', this.handleFocusIn);\n }\n\n protected reset(): void {\n this.definitions = new Map();\n this.items = [];\n this.activeInternal = undefined;\n }\n\n /**\n * Clears the state and disposes of all resources.\n */\n dispose(): void {\n this.reset();\n document.body.removeEventListener('focusin', this.handleFocusIn);\n }\n\n /**\n * Overrides the current state.\n * Note, this operation does not call the `stateCallback()` callback.\n * @param state the state to set.\n */\n new(state: ISplitLayout): void {\n this.reset();\n const { definitions, items, active } = state;\n if (definitions) {\n // in the first step restore definitions\n definitions.forEach((value) => {\n if (value.type === LayoutType.item) {\n const instance = new SplitItem(this, value.value as ISplitItem);\n this.definitions.set(instance.key, {\n type: LayoutType.item,\n value: instance,\n });\n } else if (value.type === LayoutType.panel) {\n const instance = new SplitPanel(this, value.value as ISplitPanel);\n this.definitions.set(instance.key, {\n type: LayoutType.panel,\n value: instance,\n });\n }\n });\n }\n // now that definitions are set we can restore panels.\n if (Array.isArray(items)) {\n items.forEach((key) => {\n this.items.push({\n type: LayoutType.panel,\n key\n });\n });\n }\n this.activeInternal = active;\n }\n\n toJSON(): ISplitLayout {\n const result: ISplitLayout = {\n definitions: [],\n items: this.items.map(i => i.key),\n };\n if (this.activeInternal) {\n result.active = this.activeInternal;\n }\n this.definitions.forEach((value) => {\n const serialized = value.value.toJSON();\n result.definitions.push({\n type: value.type,\n value: serialized,\n });\n });\n return result;\n }\n\n /**\n * Schedules a layout store operation in a debouncer.\n * Once active all other request to store the layout are ignored until \n * the timeout is triggered.\n */\n scheduleStore(): void {\n if (typeof this.debouncer === 'number') {\n return;\n }\n this.debouncer = requestAnimationFrame(() => {\n delete this.debouncer;\n this.storeLayout();\n });\n }\n\n /**\n * This function is called automatically when the store configuration\n * change. There's no need to call it manually unless you want to trigger\n * the storing state flow. However, at that moment the state is already stored\n * (unless there was an error).\n */\n async storeLayout(): Promise<void> {\n const { stateCallback } = this.options;\n if (!stateCallback) {\n return;\n }\n if (this.storing) {\n this.isDirty = true;\n return;\n }\n this.storing = true;\n try {\n await stateCallback(this.toJSON());\n } finally {\n this.storing = false;\n }\n if (this.isDirty) {\n this.isDirty = false;\n await this.storeLayout();\n }\n }\n\n protected handleFocusIn(e: Event): void {\n const layout = this.findViewFromEvent(e);\n if (layout) {\n const key = layout.key as string;\n const def = this.definitions.get(key);\n if (def) {\n this.setActive(key);\n }\n }\n }\n\n /**\n * Sets an active panel or item.\n * @param panelOrItemKey the key of the panel or item that is active.\n */\n setActive(panelOrItemKey: string): void {\n this.activeInternal = panelOrItemKey;\n }\n\n protected findViewFromEvent(e: Event): SplitView | undefined {\n const path = e.composedPath();\n while (path.length) {\n const node = path.shift() as Element;\n if (node.nodeType !== Node.ELEMENT_NODE) {\n continue;\n }\n if (node.localName === 'split-view') {\n return node as SplitView;\n }\n }\n return undefined;\n }\n\n /**\n * @param panelKey The panel key to search for the view for.\n * @returns The `split-view` element in the document\n */\n findView(panelKey: string): SplitView | undefined {\n const layout = document.querySelector(`split-view[key=\"${panelKey}\"]`) as SplitView | null;\n return layout || undefined;\n }\n\n /**\n * Finds a parent for an item.\n * @param panelKey The key of the item (panel or panel's item) to find a parent for.\n * @returns The parent panel or `undefined` when the item was removed or the panel has no parents.\n */\n getParent(panelKey: string): SplitPanel | undefined {\n for (const { type, value } of this.definitions.values()) {\n if (type !== LayoutType.panel) {\n continue;\n }\n const panel = value as SplitPanel;\n const result = panel.items.some(i => i.key === panelKey);\n if (result) {\n return panel;\n }\n }\n return undefined;\n }\n\n /**\n * Finds a panel by id.\n * \n * @param panelKey The id of the panel.\n * @returns The panel if found\n */\n findPanel(panelKey: string): SplitPanel | undefined {\n const result = this.definitions.get(panelKey);\n if (!result) {\n return undefined;\n }\n if (result.type !== LayoutType.panel) {\n return undefined;\n }\n return result.value as SplitPanel;\n }\n\n /**\n * Finds a panel item by id.\n * \n * @param itemKey The id of the panel item.\n * @returns The item if found\n */\n findItem(itemKey: string): SplitItem | undefined {\n const result = this.definitions.get(itemKey);\n if (!result) {\n return undefined;\n }\n if (result.type !== LayoutType.item) {\n return undefined;\n }\n return result.value as SplitItem;\n }\n\n /**\n * Informs the screen that something has changed\n */\n notifyChange(): void {\n this.dispatchEvent(new Event('change'));\n this.scheduleStore();\n }\n\n /**\n * Dispatches the `nameitem` event.\n * The detail object has the item to be added to the items.\n * The event handler can manipulate properties of the item, except for the index which will be set by the manager.\n * \n * Note, use the `requestNameUpdate()` when requesting a name update. The other method includes side\n * effects like updating the view.\n * \n * @param item The item to notify.\n */\n dispatchNameItem(item: SplitItem): void {\n this.dispatchEvent(new CustomEvent('nameitem', {\n detail: item,\n }));\n }\n\n /**\n * Do not call this method from the outside of the layout manager logic.\n * It is a way to communicate a tab was closed.\n */\n notifyTabClose(itemKey: string): void {\n this.dispatchEvent(new CustomEvent('closetab', {\n bubbles: true,\n cancelable: true,\n composed: true,\n detail: itemKey,\n }));\n }\n\n /**\n * Requests an update on the view element.\n * \n * @param panelKey The id of the panel. When not set it uses the active panel\n */\n updateView(panelKey?: string): void {\n const panel = panelKey ? this.findPanel(panelKey) : this.activePanel;\n if (!panel) {\n return;\n }\n panel.updateView();\n }\n\n /**\n * Requests to dispatch the `nameitem` event so the application can update the name of the tab.\n * \n * @param itemKey The key of the item.\n */\n requestNameUpdate(itemKey: string): void {\n const item = this.findItem(itemKey);\n if (!item) {\n return;\n }\n const before = item.label;\n this.dispatchNameItem(item);\n if (before !== item.label) {\n const panel = item.getParent();\n if (panel) {\n this.updateView(panel.key);\n }\n }\n }\n\n /**\n * Dispatches the `nameitem` event so the application \n * can update the name of an item that has a specific `parent`.\n * \n * @param parentValue The key of the `parent` property to look for.\n */\n requestNameUpdateByParent(parentValue: string): void {\n const updatePanels = new Set<SplitPanel>();\n for (const item of this.parentItemsIterator(parentValue)) {\n const before = item.label;\n this.dispatchNameItem(item);\n if (before !== item.label) {\n const panel = item.getParent() as SplitPanel;\n updatePanels.add(panel);\n }\n }\n\n for (const panel of updatePanels) {\n this.updateView(panel.key);\n }\n this.notifyChange();\n }\n\n /**\n * A shortcut to rename an item.\n * @param itemKey The key of the item to rename\n * @param label The label to set. It won't trigger side effects if the label is the same.\n */\n setItemLabel(itemKey: string, label: string): void {\n const item = this.findItem(itemKey);\n if (!item) {\n return;\n }\n item.setLabel(label);\n }\n\n addPanel(opts: SplitPanelAddOptions = {}): SplitPanel {\n const { layout = SplitDirection.horizontal, parent } = opts;\n let parentInstance: SplitPanel | SplitLayout;\n if (parent) {\n parentInstance = this.findPanel(parent) as SplitPanel;\n if (!parentInstance) {\n throw new Error(`Parent panel not found.`);\n }\n if (parentInstance.hasItems) {\n throw new Error(`Unable to create panel in a panel that has items.`);\n }\n } else {\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n parentInstance = this;\n }\n const panel = SplitPanel.fromLayout(this, layout);\n this.definitions.set(panel.key, {\n type: LayoutType.panel,\n value: panel,\n });\n parentInstance.items.push({\n key: panel.key,\n type: LayoutType.panel,\n });\n return panel;\n }\n\n /**\n * Adds an item to the active panel.\n * \n * To add an item to a specific panel find a reference to \n * the panel instance and call `addItem()` there.\n * \n * @param item The item to add.\n */\n addItem(item: ISplitItem): SplitItem {\n let panel: SplitPanel | undefined;\n const { activePanel } = this;\n // try the active panel\n if (activePanel) {\n panel = activePanel;\n } else {\n // try any panel that has no panels in it.\n for (const p of this.panelIterator()) {\n if (!p.hasPanels) {\n panel = p;\n break;\n }\n }\n }\n // finally add a new panel.\n if (!panel) {\n panel = this.addPanel();\n }\n return panel.addItem(item);\n }\n\n /**\n * Removes an item from layout.\n * @param key The key of the item to remove.\n */\n removeItem(key: string): void {\n const item = this.findItem(key);\n if (!item) {\n return;\n }\n const panel = item.getParent();\n if (panel) {\n panel.removeItem(key);\n }\n }\n\n /**\n * Removes other items relative to the `key` item.\n * @param key The key of the item to perform a relative operation from.\n * @param dir The direction to which close other items. Default to both directions leaving only the `key` item\n */\n removeRelative(key: string, dir?: SplitCloseDirection): void {\n const item = this.findItem(key);\n if (!item) {\n return;\n }\n const panel = item.getParent();\n if (panel) {\n panel.removeRelative(key, dir);\n }\n }\n\n /**\n * Moves a tab between panels or inside a panel\n * \n * @param fromPanelKey The id of the source panel of the item\n * @param toPanelKey The id of the target panel of the item\n * @param itemKey The key of the item\n * @param toIndex The index to which add the item. Default as the last.\n */\n moveItem(fromPanelKey: string, toPanelKey: string, itemKey: string, toIndex?: number): void {\n const singlePanel = fromPanelKey === toPanelKey;\n const from = this.findPanel(fromPanelKey);\n if (!from) {\n throw new Error(`Source layout panel not found.`);\n }\n if (singlePanel) {\n from.moveItem(itemKey, toIndex);\n } else {\n const to = this.findPanel(toPanelKey);\n if (!to) {\n throw new Error(`Target layout panel not found.`);\n }\n const removed = from.removeItem(itemKey);\n if (!removed) {\n throw new Error(`Item not found.`);\n }\n to.addItem(removed, { index: toIndex });\n }\n this.notifyChange();\n }\n\n /**\n * Iterates over panels from the root. \n * This iterates the panels structure in order defined in the `items` array on \n * each panel.\n * \n * @param parentPanel The parent SplitLayout to start the iteration from.\n */\n * panelIterator(parentPanel?: SplitPanel): Generator<SplitPanel> {\n const root = parentPanel || this;\n const { items } = root;\n for (const info of items) {\n if (info.type === LayoutType.panel) {\n const panel = this.findPanel(info.key);\n if (panel) {\n yield panel;\n for (const result of this.panelIterator(panel)) {\n yield result;\n }\n }\n }\n }\n }\n\n /**\n * Iterates over items that have specific `parent` property set.\n * \n * This is useful to close multiple object that belong to a parent.\n * \n * @param key The key of the `parent` property of a `SplitItem` to include in the iteration\n * @param parentPanel The `SplitPanel` to start the iteration from.\n */\n * parentItemsIterator(key: string, parentPanel?: SplitPanel): Generator<SplitItem> {\n const root = parentPanel || this;\n const { items } = root;\n for (const info of items) {\n const def = this.definitions.get(info.key);\n if (!def) {\n continue;\n }\n if (def.type === LayoutType.item && (def.value as SplitItem).parent === key) {\n yield def.value as SplitItem;\n }\n if (def.type === LayoutType.panel) {\n for (const result of this.parentItemsIterator(key, def.value as SplitPanel)) {\n yield result;\n }\n }\n }\n }\n\n /**\n * Finds all items in all panels that have specified parent.\n * @param parentValue The key of the parent to search for.\n */\n removeByParent(parentValue: string): void {\n for (const item of this.parentItemsIterator(parentValue)) {\n this.removeItem(item.key);\n }\n }\n\n /**\n * Checks whether the item with the given key is already managed by the manager.\n * @param itemKey The key of the item to check\n * @returns true if the item is in the definitions.\n */\n hasItem(itemKey: string): boolean {\n const def = this.definitions.get(itemKey);\n if (!def) {\n return false;\n }\n return def.type === LayoutType.item;\n }\n\n /**\n * Selects an item in a panel.\n * \n * When the parent is give then it tries to select the item on that panel.\n * Otherwise it checks whether the item is in the current panel and if so it selects it.\n * Otherwise, it selects the item on a first panel the item is in.\n * \n * @param itemKey The key of the item to set selected in the view.\n * @param panelKey The optional panel key. When not set it finds the first panel the item is on.\n */\n selectItem(itemKey: string, panelKey?: string): void {\n const { activePanel } = this;\n let panel: SplitPanel | undefined;\n if (panelKey) {\n // specified panel\n panel = this.findPanel(panelKey);\n } else if (activePanel?.hasItem(itemKey)) {\n // try the current active panel\n panel = activePanel;\n } else {\n // any panel that has the item\n panel = this.getParent(itemKey);\n }\n if (!panel) {\n return;\n }\n panel.selected = itemKey;\n this.updateView(panel.key);\n this.notifyChange();\n }\n\n /**\n * Checks whether the manager has at least one panel that has items.\n * \n * This is useful to render the empty state when no items are added.\n */\n isEmpty(): boolean {\n for (const panel of this.panelIterator()) {\n if (panel.hasItems) {\n return false;\n }\n }\n return true;\n }\n\n render(itemCallback: SplitItemRenderCallback): TemplateResult[] {\n const result: TemplateResult[] = [];\n const { items } = this;\n for (const info of items) {\n const panel = this.findPanel(info.key);\n const content = panel?.render(itemCallback);\n if (content) {\n result.push(content);\n }\n }\n return result;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SplitLayout.js","sourceRoot":"","sources":["../../../src/elements/layout/SplitLayout.ts"],"names":[],"mappings":"AAEA,OAAO,EAAc,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAe,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE1D,OAAO,EAAgB,UAAU,EAAE,cAAc,EAAyF,MAAM,WAAW,CAAC;AAmC5J;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,OAAO,WAAY,SAAQ,WAAW;IAc1C;;;OAGG;IACH,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;IAED;;OAEG;IACH,IAAI,YAAY;QACd,MAAM,EAAE,cAAc,EAAE,GAAG,IAAI,CAAC;QAChC,IAAI,CAAC,cAAc,EAAE;YACnB,OAAO,SAAS,CAAC;SAClB;QACD,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IAC9C,CAAC;IAED;;OAEG;IACH,IAAI,WAAW;QACb,MAAM,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC;QAC9B,IAAI,CAAC,YAAY,EAAE;YACjB,O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KAAK,IAAI,IAAI,CAAC,aAAa,EAAE,EAAE;YACxC,IAAI,KAAK,CAAC,QAAQ,EAAE;gBAClB,OAAO,KAAK,CAAC;aACd;SACF;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,CAAC,YAAqC;QAC1C,MAAM,MAAM,GAAqB,EAAE,CAAC;QACpC,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;QACvB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;YACxB,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACvC,MAAM,OAAO,GAAG,KAAK,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC;YAC5C,IAAI,OAAO,EAAE;gBACX,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;aACtB;SACF;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF","sourcesContent":["/* eslint-disable import/no-cycle */\nimport { TemplateResult } from \"lit\";\nimport { ISplitItem, SplitItem } from \"./SplitItem.js\";\nimport { ISplitPanel, SplitPanel } from \"./SplitPanel.js\";\nimport SplitView from \"./SplitView.js\";\nimport { IPanelObject, LayoutType, SplitDirection, SplitItemRenderCallback, SplitLayoutAddOptions, SplitLayoutInit, SplitPanelAddOptions } from \"./type.js\";\n\ninterface LayoutObject {\n type: LayoutType;\n value: SplitItem | SplitPanel;\n}\n\ninterface SerializedLayoutObject {\n type: LayoutType;\n value: ISplitItem | ISplitPanel;\n}\n\nexport interface ISplitLayout {\n /**\n * The map of all definitions of panels and \n */\n definitions: SerializedLayoutObject[];\n\n /**\n * The ordered list of panel keys in the view.\n */\n items: string[];\n\n /**\n * The key of the active panel or item.\n * From here it can be deduced whether the active item is a panel or an item and what's the active panel.\n */\n active?: string;\n}\n\nexport interface ITabCloseDetail {\n tab: string;\n panel: string;\n}\n\n/**\n * Split layout manager creates a view where the application can put \"items\" into\n * and render them inside \"panels\". The application can create as many panels as needed.\n * Panels can be layout vertically or horizontally.\n * \n * ## Basic usage\n * \n * ```javascript\n * const layout = new SplitLayout({\n * stateCallback: async (state: ISplitLayout): Promise<void> => { \n * localStorage.setItem('layout', JSON.stringify(state));\n * }\n * });\n * const restored = await readStoredState(); // a function that reads the state from the store\n * await layout.initialize(restored);\n * \n * const content = layout.render((itemToRender: SplitItem): TemplateResult => { return html`...` });\n * ```\n * \n * Each time the layout configuration change the optional `stateCallback` function \n * is called.\n * It's not mandatory to set this callback function but if you want the state to\n * persist you have to serialize the manager manually when needed.\n * Since the manage implement the `toJSON()` method it is safe to pass the instance of the manager\n * to a idb store or serialize with `JSON.stringify()`.\n * \n * @fires change - When the layout configuration change. This is the best time to perform DOM update.\n * @fires nameitem - When the layout requests to name an item. This usually happens then a code calls the `requestNameUpdate()` method after the item's name changed.\n * @fires closetab - When a tab wa closed via a user interaction.\n */\nexport class SplitLayout extends EventTarget {\n /**\n * The list of all definitions of panels and items.\n */\n definitions = new Map<string, LayoutObject>();\n\n /**\n * Holds an ordered list of panels in the layout.\n * Though, this interface is consistent with other panels, it can only keep panels, not items.\n */\n items: IPanelObject[] = [];\n\n private activeInternal?: string;\n\n /**\n * The key of the panel that is marked as \"active\", that is, \n * the panel the user last interacted with.\n */\n get active(): string | undefined {\n return this.activeInternal;\n }\n\n /**\n * Returns an object that is marked as active or undefined if none is marked as active.\n */\n get activeObject(): LayoutObject | undefined {\n const { activeInternal } = this;\n if (!activeInternal) {\n return undefined;\n }\n return this.definitions.get(activeInternal);\n }\n\n /**\n * An active panel that the user last interacted with.\n */\n get activePanel(): SplitPanel | undefined {\n const { activeObject } = this;\n if (!activeObject) {\n return undefined;\n }\n const { type, value } = activeObject;\n if (type === LayoutType.panel) {\n return value as SplitPanel;\n }\n const item = value as SplitItem;\n return this.getParents(item.key)[0];\n }\n\n /**\n * An active panel item that the user last interacted with.\n */\n get activeItem(): SplitItem | undefined {\n const { activeObject } = this;\n if (!activeObject) {\n return undefined;\n }\n const { type, value } = activeObject;\n if (type === LayoutType.item) {\n return value as SplitItem;\n }\n return undefined;\n }\n\n /**\n * Whether the manager is dirty, that is, a change ocurred\n * while storing the layout.\n */\n protected isDirty = false;\n\n /**\n * A flag that determines that the state is being stored in the store.\n */\n protected storing = false;\n\n /**\n * The value of the debouncer timeout.\n */\n protected debouncer?: number;\n\n constructor(public options: SplitLayoutInit = {}) {\n super();\n this.handleFocusIn = this.handleFocusIn.bind(this);\n }\n\n /**\n * Initializes the split layout manager.\n * When passed the `state` parameter it restores the previously serialized state.\n * \n * @param state A state to restore. When not set an empty layout is rendered.\n */\n initialize(state?: ISplitLayout): void {\n if (state) {\n this.new(state);\n }\n document.body.addEventListener('focusin', this.handleFocusIn);\n }\n\n protected reset(): void {\n this.definitions = new Map();\n this.items = [];\n this.activeInternal = undefined;\n }\n\n /**\n * Clears the state and disposes of all resources.\n */\n dispose(): void {\n this.reset();\n document.body.removeEventListener('focusin', this.handleFocusIn);\n }\n\n /**\n * Overrides the current state.\n * Note, this operation does not call the `stateCallback()` callback.\n * @param state the state to set.\n */\n new(state: ISplitLayout): void {\n this.reset();\n const { definitions, items, active } = state;\n if (definitions) {\n // in the first step restore definitions\n definitions.forEach((value) => {\n if (value.type === LayoutType.item) {\n const instance = new SplitItem(this, value.value as ISplitItem);\n this.definitions.set(instance.key, {\n type: LayoutType.item,\n value: instance,\n });\n } else if (value.type === LayoutType.panel) {\n const instance = new SplitPanel(this, value.value as ISplitPanel);\n this.definitions.set(instance.key, {\n type: LayoutType.panel,\n value: instance,\n });\n }\n });\n }\n // now that definitions are set we can restore panels.\n if (Array.isArray(items)) {\n items.forEach((key) => {\n this.items.push({\n type: LayoutType.panel,\n key\n });\n });\n }\n this.activeInternal = active;\n }\n\n toJSON(): ISplitLayout {\n const result: ISplitLayout = {\n definitions: [],\n items: this.items.map(i => i.key),\n };\n if (this.activeInternal) {\n result.active = this.activeInternal;\n }\n this.definitions.forEach((value) => {\n const serialized = value.value.toJSON();\n result.definitions.push({\n type: value.type,\n value: serialized,\n });\n });\n return result;\n }\n\n /**\n * Schedules a layout store operation in a debouncer.\n * Once active all other request to store the layout are ignored until \n * the timeout is triggered.\n */\n scheduleStore(): void {\n if (typeof this.debouncer === 'number') {\n return;\n }\n this.debouncer = requestAnimationFrame(() => {\n delete this.debouncer;\n this.storeLayout();\n });\n }\n\n /**\n * This function is called automatically when the store configuration\n * change. There's no need to call it manually unless you want to trigger\n * the storing state flow. However, at that moment the state is already stored\n * (unless there was an error).\n */\n async storeLayout(): Promise<void> {\n const { stateCallback } = this.options;\n if (!stateCallback) {\n return;\n }\n if (this.storing) {\n this.isDirty = true;\n return;\n }\n this.storing = true;\n try {\n await stateCallback(this.toJSON());\n } finally {\n this.storing = false;\n }\n if (this.isDirty) {\n this.isDirty = false;\n await this.storeLayout();\n }\n }\n\n protected handleFocusIn(e: Event): void {\n const layout = this.findViewFromEvent(e);\n if (layout) {\n const key = layout.key as string;\n const def = this.definitions.get(key);\n if (def) {\n this.setActive(key);\n }\n }\n }\n\n /**\n * Sets an active panel or item.\n * @param panelOrItemKey the key of the panel or item that is active.\n */\n setActive(panelOrItemKey: string): void {\n this.activeInternal = panelOrItemKey;\n }\n\n protected findViewFromEvent(e: Event): SplitView | undefined {\n const path = e.composedPath();\n while (path.length) {\n const node = path.shift() as Element;\n if (node.nodeType !== Node.ELEMENT_NODE) {\n continue;\n }\n if (node.localName === 'split-view') {\n return node as SplitView;\n }\n }\n return undefined;\n }\n\n /**\n * @param panelKey The panel key to search for the view for.\n * @returns The `split-view` element in the document\n */\n findView(panelKey: string): SplitView | undefined {\n const layout = document.querySelector(`split-view[key=\"${panelKey}\"]`) as SplitView | null;\n return layout || undefined;\n }\n\n /**\n * Finds parents an item or another panel is anchored to.\n * An item can have multiple parents. A panel can only have a single parent.\n * \n * @param itemOrPanelKey The key of the panel or an item.\n * @returns THe list of panels the item is added. It can only return up to 1 result when looking for a panel's parent.\n */\n getParents(itemOrPanelKey: string): SplitPanel[] {\n const result: SplitPanel[] = [];\n for (const { type, value } of this.definitions.values()) {\n if (type !== LayoutType.panel) {\n continue;\n }\n const panel = value as SplitPanel;\n const has = panel.items.some(i => i.key === itemOrPanelKey);\n if (has) {\n result.push(panel);\n }\n }\n return result;\n }\n\n /**\n * Finds a panel by id.\n * \n * @param panelKey The id of the panel.\n * @returns The panel if found\n */\n findPanel(panelKey: string): SplitPanel | undefined {\n const result = this.definitions.get(panelKey);\n if (!result) {\n return undefined;\n }\n if (result.type !== LayoutType.panel) {\n return undefined;\n }\n return result.value as SplitPanel;\n }\n\n /**\n * Finds a panel item by id.\n * \n * @param itemKey The id of the panel item.\n * @returns The item if found\n */\n findItem(itemKey: string): SplitItem | undefined {\n const result = this.definitions.get(itemKey);\n if (!result) {\n return undefined;\n }\n if (result.type !== LayoutType.item) {\n return undefined;\n }\n return result.value as SplitItem;\n }\n\n /**\n * Informs the screen that something has changed\n */\n notifyChange(): void {\n this.dispatchEvent(new Event('change'));\n this.scheduleStore();\n }\n\n /**\n * Dispatches the `nameitem` event.\n * The detail object has the item to be added to the items.\n * The event handler can manipulate properties of the item, except for the index which will be set by the manager.\n * \n * Note, use the `requestNameUpdate()` when requesting a name update. The other method includes side\n * effects like updating the view.\n * \n * @param item The item to notify.\n */\n dispatchNameItem(item: SplitItem): void {\n this.dispatchEvent(new CustomEvent('nameitem', {\n detail: item,\n }));\n }\n\n /**\n * Do not call this method from the outside of the layout manager logic.\n * It is a way to communicate a tab was closed.\n */\n notifyTabClose(itemKey: string, panel: string): void {\n this.dispatchEvent(new CustomEvent<ITabCloseDetail>('closetab', {\n bubbles: true,\n cancelable: true,\n composed: true,\n detail: {\n tab: itemKey,\n panel,\n },\n }));\n }\n\n /**\n * Requests an update on the view element.\n * \n * @param panelKey The id of the panel. When not set it uses the active panel\n */\n updateView(panelKey?: string): void {\n const panel = panelKey ? this.findPanel(panelKey) : this.activePanel;\n if (!panel) {\n return;\n }\n panel.updateView();\n }\n\n /**\n * Requests to dispatch the `nameitem` event so the application can update the name of the tab.\n * \n * @param itemKey The key of the item.\n */\n requestNameUpdate(itemKey: string): void {\n const item = this.findItem(itemKey);\n if (!item) {\n return;\n }\n const before = item.label;\n this.dispatchNameItem(item);\n if (before !== item.label) {\n const panels = this.getParents(item.key);\n panels.forEach(panel => this.updateView(panel.key));\n }\n }\n\n /**\n * Dispatches the `nameitem` event so the application \n * can update the name of an item that has a specific `parent`.\n * \n * @param parentValue The key of the `parent` property to look for.\n */\n requestNameUpdateByParent(parentValue: string): void {\n const updatePanels = new Set<SplitPanel>();\n for (const item of this.parentItemsIterator(parentValue)) {\n const before = item.label;\n this.dispatchNameItem(item);\n if (before !== item.label) {\n const panels = this.getParents(item.key);\n panels.forEach(panel => updatePanels.add(panel));\n }\n }\n\n for (const panel of updatePanels) {\n this.updateView(panel.key);\n }\n this.notifyChange();\n }\n\n /**\n * A shortcut to rename an item.\n * @param itemKey The key of the item to rename\n * @param label The label to set. It won't trigger side effects if the label is the same.\n */\n setItemLabel(itemKey: string, label: string): void {\n const item = this.findItem(itemKey);\n if (!item) {\n return;\n }\n item.setLabel(label);\n }\n\n addPanel(opts: SplitPanelAddOptions = {}): SplitPanel {\n const { layout = SplitDirection.horizontal, parent } = opts;\n let parentInstance: SplitPanel | SplitLayout;\n if (parent) {\n parentInstance = this.findPanel(parent) as SplitPanel;\n if (!parentInstance) {\n throw new Error(`Parent panel not found.`);\n }\n if (parentInstance.hasItems) {\n throw new Error(`Unable to create panel in a panel that has items.`);\n }\n } else {\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n parentInstance = this;\n }\n const panel = SplitPanel.fromLayout(this, layout);\n this.definitions.set(panel.key, {\n type: LayoutType.panel,\n value: panel,\n });\n parentInstance.items.push({\n key: panel.key,\n type: LayoutType.panel,\n });\n return panel;\n }\n\n /**\n * Adds an item to the active panel.\n * \n * To add an item to a specific panel find a reference to \n * the panel instance and call `addItem()` there.\n * \n * @param item The item to add.\n */\n addItem(item: ISplitItem): SplitItem {\n let panel: SplitPanel | undefined;\n const { activePanel } = this;\n // try the active panel\n if (activePanel) {\n panel = activePanel;\n } else {\n // try any panel that has no panels in it.\n for (const p of this.panelIterator()) {\n if (!p.hasPanels) {\n panel = p;\n break;\n }\n }\n }\n // finally add a new panel.\n if (!panel) {\n panel = this.addPanel();\n }\n return panel.addItem(item);\n }\n\n /**\n * Removes an item from the layout. This means removing an item from all panels.\n * If you want to remove an item from a specific panel then find the panel first and then call `removeItem()`.\n * \n * @param key The key of the item to remove.\n */\n removeItem(key: string): void {\n const item = this.findItem(key);\n if (!item) {\n return;\n }\n const parents = this.getParents(key);\n parents.forEach(parent => parent.removeChildItem(item));\n }\n\n // /**\n // * Removes other items relative to the `key` item.\n // * @param key The key of the item to perform a relative operation from.\n // * @param dir The direction to which close other items. Default to both directions leaving only the `key` item\n // * @deprecated this function does not work as intended. Find the parent panel first and then call the `removeRelative()`.\n // */\n // removeRelative(key: string, dir?: SplitCloseDirection): void {\n // const item = this.findItem(key);\n // if (!item) {\n // return;\n // }\n // const panel = item.getParent();\n // if (panel) {\n // panel.removeRelative(key, dir);\n // }\n // }\n\n /**\n * Moves a tab between panels or inside a panel\n * \n * @param fromPanelKey The id of the source panel of the item\n * @param toPanelKey The id of the target panel of the item\n * @param itemKey The key of the item\n * @param toIndex The index to which add the item. Default as the last.\n */\n moveItem(fromPanelKey: string, toPanelKey: string, itemKey: string, opts?: SplitLayoutAddOptions): void {\n const singlePanel = fromPanelKey === toPanelKey;\n const from = this.findPanel(fromPanelKey);\n if (!from) {\n throw new Error(`Source layout panel not found.`);\n }\n if (singlePanel) {\n from.moveItem(itemKey, opts);\n } else {\n const to = this.findPanel(toPanelKey);\n if (!to) {\n throw new Error(`Target layout panel not found.`);\n }\n const removed = from.removeItem(itemKey);\n if (!removed) {\n throw new Error(`Item not found.`);\n }\n to.addItem(removed, opts);\n }\n this.notifyChange();\n }\n\n /**\n * Iterates over panels from the root. \n * This iterates the panels structure in order defined in the `items` array on \n * each panel.\n * \n * @param parentPanel The parent SplitLayout to start the iteration from.\n */\n * panelIterator(parentPanel?: SplitPanel): Generator<SplitPanel> {\n const root = parentPanel || this;\n const { items } = root;\n for (const info of items) {\n if (info.type === LayoutType.panel) {\n const panel = this.findPanel(info.key);\n if (panel) {\n yield panel;\n for (const result of this.panelIterator(panel)) {\n yield result;\n }\n }\n }\n }\n }\n\n /**\n * Iterates over items that have specific `parent` property set.\n * \n * This is useful to close multiple object that belong to a parent.\n * \n * @param key The key of the `parent` property of a `SplitItem` to include in the iteration\n * @param parentPanel The `SplitPanel` to start the iteration from.\n */\n * parentItemsIterator(key: string, parentPanel?: SplitPanel): Generator<SplitItem> {\n const root = parentPanel || this;\n const { items } = root;\n for (const info of items) {\n const def = this.definitions.get(info.key);\n if (!def) {\n continue;\n }\n if (def.type === LayoutType.item && (def.value as SplitItem).parent === key) {\n yield def.value as SplitItem;\n }\n if (def.type === LayoutType.panel) {\n for (const result of this.parentItemsIterator(key, def.value as SplitPanel)) {\n yield result;\n }\n }\n }\n }\n\n /**\n * Finds all items in all panels that have specified parent.\n * @param parentValue The key of the parent to search for.\n */\n removeByParent(parentValue: string): void {\n for (const item of this.parentItemsIterator(parentValue)) {\n this.removeItem(item.key);\n }\n }\n\n /**\n * Checks whether the item with the given key is already managed by the manager.\n * @param itemKey The key of the item to check\n * @returns true if the item is in the definitions.\n */\n hasItem(itemKey: string): boolean {\n const def = this.definitions.get(itemKey);\n if (!def) {\n return false;\n }\n return def.type === LayoutType.item;\n }\n\n /**\n * Selects an item in a panel.\n * \n * When the parent is give then it tries to select the item on that panel.\n * Otherwise it checks whether the item is in the current panel and if so it selects it.\n * Otherwise, it selects the item on a first panel the item is in.\n * \n * @param itemKey The key of the item to set selected in the view.\n * @param panelKey The optional panel key. When not set it finds the first panel the item is on.\n */\n selectItem(itemKey: string, panelKey?: string): void {\n const { activePanel } = this;\n let panel: SplitPanel | undefined;\n if (panelKey) {\n // specified panel\n panel = this.findPanel(panelKey);\n } else if (activePanel?.hasItem(itemKey)) {\n // try the current active panel\n panel = activePanel;\n } else {\n // any panel that has the item\n [panel] = this.getParents(itemKey);\n }\n if (!panel) {\n return;\n }\n panel.selected = itemKey;\n this.updateView(panel.key);\n this.notifyChange();\n }\n\n /**\n * Checks whether the manager has at least one panel that has items.\n * \n * This is useful to render the empty state when no items are added.\n */\n isEmpty(): boolean {\n for (const panel of this.panelIterator()) {\n if (panel.hasItems) {\n return false;\n }\n }\n return true;\n }\n\n render(itemCallback: SplitItemRenderCallback): TemplateResult[] {\n const result: TemplateResult[] = [];\n const { items } = this;\n for (const info of items) {\n const panel = this.findPanel(info.key);\n const content = panel?.render(itemCallback);\n if (content) {\n result.push(content);\n }\n }\n return result;\n }\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TemplateResult } from "lit";
|
|
2
2
|
import { ISplitItem, SplitItem } from "./SplitItem.js";
|
|
3
|
-
import { IPanelObject, PanelState, SplitCloseDirection, SplitDirection, SplitItemRenderCallback, SplitLayoutAddOptions, SplitPanelRemoveItemOptions, SplitPanelSplitOptions } from "./type.js";
|
|
3
|
+
import { IPanelObject, PanelState, SplitCloseDirection, SplitDirection, SplitItemRenderCallback, SplitLayoutAddOptions, SplitPanelRemoveItemOptions, SplitPanelSplitOptions, SplitRegion } from "./type.js";
|
|
4
4
|
import { SplitLayout } from './SplitLayout.js';
|
|
5
5
|
import '../../define/layout/split-view.js';
|
|
6
6
|
export interface ISplitPanel {
|
|
@@ -83,6 +83,7 @@ export declare class SplitPanel {
|
|
|
83
83
|
* @returns Whether a new item was added to the layout. false when the item is already in the layout panel.
|
|
84
84
|
*/
|
|
85
85
|
addItem(item: ISplitItem | SplitItem, opts?: SplitLayoutAddOptions): SplitItem;
|
|
86
|
+
protected splitByRegion(region: SplitRegion): SplitPanel;
|
|
86
87
|
/**
|
|
87
88
|
* Splits this panel into 2 panels.
|
|
88
89
|
* This to be used when the panel has no other panels. Only items are allowed.
|
|
@@ -100,6 +101,7 @@ export declare class SplitPanel {
|
|
|
100
101
|
* @param fromIndex The minimal index to affect.
|
|
101
102
|
*/
|
|
102
103
|
increaseIndex(fromIndex: number): void;
|
|
104
|
+
removeChildItem(item: SplitItem, opts?: SplitPanelRemoveItemOptions): SplitItem | undefined;
|
|
103
105
|
/**
|
|
104
106
|
* Removes an item from the layout
|
|
105
107
|
* @param key The `key` of the item.
|
|
@@ -119,7 +121,10 @@ export declare class SplitPanel {
|
|
|
119
121
|
* @param key The item key
|
|
120
122
|
* @param toIndex The new index. When not set it moves the item to the end.
|
|
121
123
|
*/
|
|
122
|
-
moveItem(key: string,
|
|
124
|
+
moveItem(key: string, opts?: SplitLayoutAddOptions): void;
|
|
125
|
+
moveToRegion(item: SplitItem, region: SplitRegion): void;
|
|
126
|
+
moveToIndex(item: SplitItem, index: number): void;
|
|
127
|
+
moveToEnd(item: SplitItem): void;
|
|
123
128
|
updateView(): void;
|
|
124
129
|
addPanel(layout?: SplitDirection): SplitPanel;
|
|
125
130
|
panelTemplate(panel: SplitPanel, itemCallback: SplitItemRenderCallback): TemplateResult | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SplitPanel.d.ts","sourceRoot":"","sources":["../../../src/elements/layout/SplitPanel.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SplitPanel.d.ts","sourceRoot":"","sources":["../../../src/elements/layout/SplitPanel.ts"],"names":[],"mappings":"AAEA,OAAO,EAAQ,cAAc,EAAE,MAAM,KAAK,CAAC;AAE3C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAc,UAAU,EAAE,mBAAmB,EAAE,cAAc,EAAE,uBAAuB,EAAE,qBAAqB,EAAE,2BAA2B,EAAE,sBAAsB,EAAoB,WAAW,EAAE,MAAM,WAAW,CAAC;AAC1O,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,mCAAmC,CAAC;AAE3C,MAAM,WAAW,WAA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