@umbraco-cms/backoffice 14.0.0--preview004-478ab905 → 14.0.0--preview004-2a8fbe36

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.
@@ -27,7 +27,7 @@ export class UmbDefaultCollectionContext extends UmbContextBase {
27
27
  this.#initialized ? resolve() : (this.#initResolver = resolve);
28
28
  });
29
29
  this.pagination = new UmbPaginationManager();
30
- this.selection = new UmbSelectionManager();
30
+ this.selection = new UmbSelectionManager(this);
31
31
  this.#onPageChange = (event) => {
32
32
  const target = event.target;
33
33
  const skipFilter = { skip: target.getSkip() };
@@ -13,7 +13,7 @@ let UmbSectionPickerModalElement = class UmbSectionPickerModalElement extends Um
13
13
  constructor() {
14
14
  super(...arguments);
15
15
  this._sections = [];
16
- this.#selectionManager = new UmbSelectionManager();
16
+ this.#selectionManager = new UmbSelectionManager(this);
17
17
  }
18
18
  #selectionManager;
19
19
  connectedCallback() {
@@ -25,13 +25,8 @@ let UmbSectionPickerModalElement = class UmbSectionPickerModalElement extends Um
25
25
  'umbSectionsObserver';
26
26
  }
27
27
  #submit() {
28
- this.value = {
29
- selection: this.#selectionManager.getSelection(),
30
- };
31
- this.modalContext?.submit();
32
- }
33
- #close() {
34
- this.modalContext?.reject();
28
+ this.value = { selection: this.#selectionManager.getSelection() };
29
+ this._submitModal();
35
30
  }
36
31
  render() {
37
32
  return html `
@@ -47,7 +42,7 @@ let UmbSectionPickerModalElement = class UmbSectionPickerModalElement extends Um
47
42
  `)}
48
43
  </uui-box>
49
44
  <div slot="actions">
50
- <uui-button label="Close" @click=${this.#close}></uui-button>
45
+ <uui-button label="Close" @click=${this._rejectModal}></uui-button>
51
46
  <uui-button label="Submit" look="primary" color="positive" @click=${this.#submit}></uui-button>
52
47
  </div>
53
48
  </umb-body-layout>
@@ -81,13 +81,13 @@ export class UmbTreeItemContextBase extends UmbBaseController {
81
81
  }
82
82
  select() {
83
83
  if (this.unique === undefined)
84
- throw new Error('Could not select, unique key is missing');
85
- this.treeContext?.select(this.unique);
84
+ throw new Error('Could not select. Unique is missing');
85
+ this.treeContext?.selection.select(this.unique);
86
86
  }
87
87
  deselect() {
88
88
  if (this.unique === undefined)
89
- throw new Error('Could not deselect, unique key is missing');
90
- this.treeContext?.deselect(this.unique);
89
+ throw new Error('Could not deselect. Unique is missing');
90
+ this.treeContext?.selection.deselect(this.unique);
91
91
  }
92
92
  #consumeContexts() {
93
93
  this.consumeContext(UMB_SECTION_CONTEXT_TOKEN, (instance) => {
@@ -110,7 +110,7 @@ export class UmbTreeItemContextBase extends UmbBaseController {
110
110
  #observeIsSelectable() {
111
111
  if (!this.treeContext)
112
112
  return;
113
- this.observe(this.treeContext.selectable, (value) => {
113
+ this.observe(this.treeContext.selection.selectable, (value) => {
114
114
  this.#isSelectableContext.next(value);
115
115
  // If the tree is selectable, check if this item is selectable
116
116
  if (value === true) {
@@ -122,7 +122,7 @@ export class UmbTreeItemContextBase extends UmbBaseController {
122
122
  #observeIsSelected() {
123
123
  if (!this.treeContext || !this.unique)
124
124
  return;
125
- this.observe(this.treeContext.selection.pipe(map((selection) => selection.includes(this.unique))), (isSelected) => {
125
+ this.observe(this.treeContext.selection.selection.pipe(map((selection) => selection.includes(this.unique))), (isSelected) => {
126
126
  this.#isSelected.next(isSelected);
127
127
  }, 'observeIsSelected');
128
128
  }
@@ -5,17 +5,9 @@ import { UmbPagedData } from '../repository/index.js';
5
5
  import { UmbBaseController } from '../../../libs/class-api/index.js';
6
6
  import { type UmbControllerHostElement } from '../../../libs/controller-api/index.js';
7
7
  import { ProblemDetails } from '../../../external/backend-api/index.js';
8
+ import { UmbSelectionManager } from '../../../shared/utils/index.js';
8
9
  export interface UmbTreeContext<TreeItemType extends UmbTreeItemModelBase> extends UmbBaseController {
9
- readonly selectable: Observable<boolean>;
10
- readonly selection: Observable<Array<string | null>>;
11
- setSelectable(value: boolean): void;
12
- getSelectable(): boolean;
13
- setMultiple(value: boolean): void;
14
- getMultiple(): boolean;
15
- setSelection(value: Array<string | null>): void;
16
- getSelection(): Array<string | null>;
17
- select(unique: string | null): void;
18
- deselect(unique: string | null): void;
10
+ selection: UmbSelectionManager;
19
11
  requestChildrenOf: (parentUnique: string | null) => Promise<{
20
12
  data?: UmbPagedData<TreeItemType>;
21
13
  error?: ProblemDetails;
@@ -24,22 +16,12 @@ export interface UmbTreeContext<TreeItemType extends UmbTreeItemModelBase> exten
24
16
  }
25
17
  export declare class UmbTreeContextBase<TreeItemType extends UmbTreeItemModelBase> extends UmbBaseController implements UmbTreeContext<TreeItemType> {
26
18
  #private;
27
- readonly selectable: Observable<boolean>;
28
- readonly multiple: Observable<boolean>;
29
- readonly selection: Observable<(string | null)[]>;
30
19
  repository?: UmbTreeRepository<TreeItemType>;
31
20
  selectableFilter?: (item: TreeItemType) => boolean;
21
+ readonly selection: UmbSelectionManager;
32
22
  constructor(host: UmbControllerHostElement);
33
23
  setTreeAlias(treeAlias?: string): Promise<void>;
34
24
  getTreeAlias(): string | undefined;
35
- setSelectable(value: boolean): void;
36
- getSelectable(): boolean;
37
- setMultiple(value: boolean): void;
38
- getMultiple(): boolean;
39
- setSelection(value: Array<string | null>): void;
40
- getSelection(): (string | null)[];
41
- select(unique: string | null): void;
42
- deselect(unique: string | null): void;
43
25
  requestTreeRoot(): Promise<{
44
26
  data?: UmbTreeItemModelBase | undefined;
45
27
  error?: ProblemDetails | undefined;
@@ -1,24 +1,16 @@
1
1
  import { umbExtensionsRegistry, } from '../extension-registry/index.js';
2
- import { UmbBooleanState } from '../../../libs/observable-api/index.js';
3
2
  import { UmbBaseController } from '../../../libs/class-api/index.js';
4
3
  import { UmbExtensionApiInitializer } from '../../../libs/extension-api/index.js';
5
4
  import { UmbSelectionManager } from '../../../shared/utils/index.js';
6
- import { UmbSelectionChangeEvent } from '../event/index.js';
7
5
  export class UmbTreeContextBase extends UmbBaseController {
8
- #selectionManager;
9
- #selectable;
10
6
  #treeAlias;
11
7
  #initResolver;
12
8
  #initialized;
13
9
  #init;
14
10
  constructor(host) {
15
11
  super(host);
16
- this.#selectionManager = new UmbSelectionManager();
17
- this.#selectable = new UmbBooleanState(false);
18
- this.selectable = this.#selectable.asObservable();
19
- this.multiple = this.#selectionManager.multiple;
20
- this.selection = this.#selectionManager.selection;
21
12
  this.selectableFilter = () => true;
13
+ this.selection = new UmbSelectionManager(this._host);
22
14
  this.#initialized = false;
23
15
  this.#init = new Promise((resolve) => {
24
16
  this.#initialized ? resolve() : (this.#initResolver = resolve);
@@ -41,34 +33,6 @@ export class UmbTreeContextBase extends UmbBaseController {
41
33
  getTreeAlias() {
42
34
  return this.#treeAlias;
43
35
  }
44
- setSelectable(value) {
45
- this.#selectable.next(value);
46
- }
47
- getSelectable() {
48
- return this.#selectable.getValue();
49
- }
50
- setMultiple(value) {
51
- this.#selectionManager.setMultiple(value);
52
- }
53
- getMultiple() {
54
- return this.#selectionManager.getMultiple();
55
- }
56
- setSelection(value) {
57
- this.#selectionManager.setSelection(value);
58
- }
59
- getSelection() {
60
- return this.#selectionManager.getSelection();
61
- }
62
- select(unique) {
63
- if (!this.getSelectable())
64
- return;
65
- this.#selectionManager.select(unique);
66
- this._host.getHostElement().dispatchEvent(new UmbSelectionChangeEvent());
67
- }
68
- deselect(unique) {
69
- this.#selectionManager.deselect(unique);
70
- this._host.getHostElement().dispatchEvent(new UmbSelectionChangeEvent());
71
- }
72
36
  async requestTreeRoot() {
73
37
  await this.#init;
74
38
  return this.repository.requestTreeRoot();
@@ -17,24 +17,24 @@ let UmbTreeElement = class UmbTreeElement extends UmbLitElement {
17
17
  this.#treeContext.setTreeAlias(newVal);
18
18
  }
19
19
  get selectable() {
20
- return this.#treeContext.getSelectable();
20
+ return this.#treeContext.selection.getSelectable();
21
21
  }
22
22
  set selectable(newVal) {
23
- this.#treeContext.setSelectable(newVal);
23
+ this.#treeContext.selection.setSelectable(newVal);
24
24
  }
25
25
  get selection() {
26
- return this.#treeContext.getSelection();
26
+ return this.#treeContext.selection.getSelection();
27
27
  }
28
28
  set selection(newVal) {
29
29
  if (!Array.isArray(newVal))
30
30
  return;
31
- this.#treeContext?.setSelection(newVal);
31
+ this.#treeContext?.selection.setSelection(newVal);
32
32
  }
33
33
  get multiple() {
34
- return this.#treeContext.getMultiple();
34
+ return this.#treeContext.selection.getMultiple();
35
35
  }
36
36
  set multiple(newVal) {
37
- this.#treeContext.setMultiple(newVal);
37
+ this.#treeContext.selection.setMultiple(newVal);
38
38
  }
39
39
  get hideTreeRoot() {
40
40
  return this._hideTreeRoot;
@@ -14,7 +14,7 @@ let UmbLanguagePickerModalElement = class UmbLanguagePickerModalElement extends
14
14
  super(...arguments);
15
15
  this._languages = [];
16
16
  this.#languageRepository = new UmbLanguageRepository(this);
17
- this.#selectionManager = new UmbSelectionManager();
17
+ this.#selectionManager = new UmbSelectionManager(this);
18
18
  }
19
19
  #languageRepository;
20
20
  #selectionManager;
@@ -13,7 +13,7 @@ let UmbUserPickerModalElement = class UmbUserPickerModalElement extends UmbModal
13
13
  constructor() {
14
14
  super(...arguments);
15
15
  this._users = [];
16
- this.#selectionManager = new UmbSelectionManager();
16
+ this.#selectionManager = new UmbSelectionManager(this);
17
17
  this.#userCollectionRepository = new UmbUserCollectionRepository(this);
18
18
  }
19
19
  #selectionManager;
@@ -14,7 +14,7 @@ let UmbUserGroupPickerModalElement = class UmbUserGroupPickerModalElement extend
14
14
  constructor() {
15
15
  super(...arguments);
16
16
  this._userGroups = [];
17
- this.#selectionManager = new UmbSelectionManager();
17
+ this.#selectionManager = new UmbSelectionManager(this);
18
18
  this.#userGroupCollectionRepository = new UmbUserGroupCollectionRepository(this);
19
19
  }
20
20
  #selectionManager;
@@ -8,7 +8,7 @@ export * from './pagination-manager/pagination.manager.js';
8
8
  export * from './path-decode.function.js';
9
9
  export * from './path-encode.function.js';
10
10
  export * from './path-folder-name.function.js';
11
- export * from './selection-manager.js';
11
+ export * from './selection-manager/selection.manager.js';
12
12
  export * from './udi-service.js';
13
13
  export * from './umbraco-path.function.js';
14
14
  export * from './split-string-to-array.js';
@@ -8,7 +8,7 @@ export * from './pagination-manager/pagination.manager.js';
8
8
  export * from './path-decode.function.js';
9
9
  export * from './path-encode.function.js';
10
10
  export * from './path-folder-name.function.js';
11
- export * from './selection-manager.js';
11
+ export * from './selection-manager/selection.manager.js';
12
12
  export * from './udi-service.js';
13
13
  export * from './umbraco-path.function.js';
14
14
  export * from './split-string-to-array.js';
@@ -1,12 +1,28 @@
1
+ import { UmbBaseController } from '../../../libs/class-api/index.js';
2
+ import { UmbControllerHost } from '../../../libs/controller-api/index.js';
1
3
  /**
2
4
  * Manages the selection of items.
3
5
  * @export
4
6
  * @class UmbSelectionManager
5
7
  */
6
- export declare class UmbSelectionManager {
8
+ export declare class UmbSelectionManager extends UmbBaseController {
7
9
  #private;
10
+ readonly selectable: import("rxjs").Observable<boolean>;
8
11
  readonly selection: import("rxjs").Observable<(string | null)[]>;
9
12
  readonly multiple: import("rxjs").Observable<boolean>;
13
+ constructor(host: UmbControllerHost);
14
+ /**
15
+ * Returns whether items can be selected.
16
+ * @return {*}
17
+ * @memberof UmbSelectionManager
18
+ */
19
+ getSelectable(): boolean;
20
+ /**
21
+ * Sets whether items can be selected.
22
+ * @param {boolean} value
23
+ * @memberof UmbSelectionManager
24
+ */
25
+ setSelectable(value: boolean): void;
10
26
  /**
11
27
  * Returns the current selection.
12
28
  * @return {*}
@@ -1,18 +1,40 @@
1
- import { UmbArrayState, UmbBooleanState } from '../../libs/observable-api/index.js';
1
+ import { UmbBaseController } from '../../../libs/class-api/index.js';
2
+ import { UmbSelectionChangeEvent } from '../../../packages/core/event/index.js';
3
+ import { UmbArrayState, UmbBooleanState } from '../../../libs/observable-api/index.js';
2
4
  /**
3
5
  * Manages the selection of items.
4
6
  * @export
5
7
  * @class UmbSelectionManager
6
8
  */
7
- export class UmbSelectionManager {
8
- constructor() {
9
+ export class UmbSelectionManager extends UmbBaseController {
10
+ #selectable;
11
+ #selection;
12
+ #multiple;
13
+ constructor(host) {
14
+ super(host);
15
+ this.#selectable = new UmbBooleanState(false);
16
+ this.selectable = this.#selectable.asObservable();
9
17
  this.#selection = new UmbArrayState([], (x) => x);
10
18
  this.selection = this.#selection.asObservable();
11
19
  this.#multiple = new UmbBooleanState(false);
12
20
  this.multiple = this.#multiple.asObservable();
13
21
  }
14
- #selection;
15
- #multiple;
22
+ /**
23
+ * Returns whether items can be selected.
24
+ * @return {*}
25
+ * @memberof UmbSelectionManager
26
+ */
27
+ getSelectable() {
28
+ return this.#selectable.getValue();
29
+ }
30
+ /**
31
+ * Sets whether items can be selected.
32
+ * @param {boolean} value
33
+ * @memberof UmbSelectionManager
34
+ */
35
+ setSelectable(value) {
36
+ this.#selectable.next(value);
37
+ }
16
38
  /**
17
39
  * Returns the current selection.
18
40
  * @return {*}
@@ -27,9 +49,12 @@ export class UmbSelectionManager {
27
49
  * @memberof UmbSelectionManager
28
50
  */
29
51
  setSelection(value) {
52
+ if (this.getSelectable() === false)
53
+ return;
30
54
  if (value === undefined)
31
55
  throw new Error('Value cannot be undefined');
32
- this.#selection.next(value);
56
+ const newSelection = this.getMultiple() ? value : [value[0]];
57
+ this.#selection.next(newSelection);
33
58
  }
34
59
  /**
35
60
  * Returns whether multiple items can be selected.
@@ -46,6 +71,11 @@ export class UmbSelectionManager {
46
71
  */
47
72
  setMultiple(value) {
48
73
  this.#multiple.next(value);
74
+ /* If multiple is set to false, and the current selection is more than one,
75
+ then we need to set the selection to the first item. */
76
+ if (value === false && this.getSelection().length > 1) {
77
+ this.setSelection([this.getSelection()[0]]);
78
+ }
49
79
  }
50
80
  /**
51
81
  * Toggles the given unique id in the current selection.
@@ -53,6 +83,8 @@ export class UmbSelectionManager {
53
83
  * @memberof UmbSelectionManager
54
84
  */
55
85
  toggleSelect(unique) {
86
+ if (this.getSelectable() === false)
87
+ return;
56
88
  this.isSelected(unique) ? this.deselect(unique) : this.select(unique);
57
89
  }
58
90
  /**
@@ -61,8 +93,13 @@ export class UmbSelectionManager {
61
93
  * @memberof UmbSelectionManager
62
94
  */
63
95
  select(unique) {
96
+ if (this.getSelectable() === false)
97
+ return;
98
+ if (this.isSelected(unique))
99
+ return;
64
100
  const newSelection = this.getMultiple() ? [...this.getSelection(), unique] : [unique];
65
101
  this.#selection.next(newSelection);
102
+ this.getHostElement().dispatchEvent(new UmbSelectionChangeEvent());
66
103
  }
67
104
  /**
68
105
  * Removes the given unique id from the current selection.
@@ -70,8 +107,11 @@ export class UmbSelectionManager {
70
107
  * @memberof UmbSelectionManager
71
108
  */
72
109
  deselect(unique) {
110
+ if (this.getSelectable() === false)
111
+ return;
73
112
  const newSelection = this.getSelection().filter((x) => x !== unique);
74
113
  this.#selection.next(newSelection);
114
+ this.getHostElement().dispatchEvent(new UmbSelectionChangeEvent());
75
115
  }
76
116
  /**
77
117
  * Returns true if the given unique id is selected.
@@ -87,6 +127,8 @@ export class UmbSelectionManager {
87
127
  * @memberof UmbSelectionManager
88
128
  */
89
129
  clearSelection() {
130
+ if (this.getSelectable() === false)
131
+ return;
90
132
  this.#selection.next([]);
91
133
  }
92
134
  }