{"version":3,"file":"tree-picker-modal.element-BqBl5tTA.js","sources":["../../../src/packages/core/tree/tree-item-picker/tree-item-picker.context.ts","../../../src/packages/core/tree/tree-picker-modal/tree-picker-modal.element.ts"],"sourcesContent":["import { UmbPickerContext } from '@umbraco-cms/backoffice/picker';\nimport type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';\n\nexport class UmbTreeItemPickerContext extends UmbPickerContext {\n\tconstructor(host: UmbControllerHost) {\n\t\tsuper(host);\n\t}\n}\n\nexport { UmbTreeItemPickerContext as api };\n","import type { UmbTreeSelectionConfiguration } from '../types.js';\nimport { UmbTreeItemPickerContext } from '../tree-item-picker/index.js';\nimport type { UmbTreePickerModalData, UmbTreePickerModalValue } from './tree-picker-modal.token.js';\nimport type { PropertyValueMap } from '@umbraco-cms/backoffice/external/lit';\nimport { html, customElement, state, ifDefined, nothing } from '@umbraco-cms/backoffice/external/lit';\nimport { UMB_WORKSPACE_MODAL, UmbModalBaseElement } from '@umbraco-cms/backoffice/modal';\nimport { UmbModalRouteRegistrationController } from '@umbraco-cms/backoffice/router';\nimport { UmbDeselectedEvent, UmbSelectedEvent } from '@umbraco-cms/backoffice/event';\nimport type { UmbTreeItemModelBase } from '@umbraco-cms/backoffice/tree';\n\n@customElement('umb-tree-picker-modal')\nexport class UmbTreePickerModalElement extends UmbModalBaseElement<\n\tUmbTreePickerModalData,\n\tUmbTreePickerModalValue\n> {\n\t@state()\n\t_selectionConfiguration: UmbTreeSelectionConfiguration = {\n\t\tmultiple: false,\n\t\tselectable: true,\n\t\tselection: [],\n\t};\n\n\t@state()\n\t_hasSelection: boolean = false;\n\n\t@state()\n\t_createPath?: string;\n\n\t@state()\n\t_createLabel?: string;\n\n\t@state()\n\t_searchQuery?: string;\n\n\t#pickerContext = new UmbTreeItemPickerContext(this);\n\n\tconstructor() {\n\t\tsuper();\n\t\tthis.#pickerContext.selection.setSelectable(true);\n\t\tthis.observe(this.#pickerContext.selection.hasSelection, (hasSelection) => {\n\t\t\tthis._hasSelection = hasSelection;\n\t\t});\n\t\tthis.#observePickerSelection();\n\t\tthis.#observeSearch();\n\t}\n\n\toverride connectedCallback(): void {\n\t\tsuper.connectedCallback();\n\t\tthis.#initCreateAction();\n\t}\n\n\tprotected override async updated(_changedProperties: PropertyValueMap | Map) {\n\t\tsuper.updated(_changedProperties);\n\n\t\tif (_changedProperties.has('data')) {\n\t\t\tif (this.data?.search) {\n\t\t\t\tthis.#pickerContext.search.updateConfig({ ...this.data?.search });\n\t\t\t}\n\n\t\t\tconst multiple = this.data?.multiple ?? false;\n\t\t\tthis.#pickerContext.selection.setMultiple(multiple);\n\n\t\t\tthis._selectionConfiguration = {\n\t\t\t\t...this._selectionConfiguration,\n\t\t\t\tmultiple,\n\t\t\t};\n\t\t}\n\n\t\tif (_changedProperties.has('value')) {\n\t\t\tconst selection = this.value?.selection ?? [];\n\t\t\tthis.#pickerContext.selection.setSelection(selection);\n\t\t\tthis._selectionConfiguration = {\n\t\t\t\t...this._selectionConfiguration,\n\t\t\t\tselection: [...selection],\n\t\t\t};\n\t\t}\n\t}\n\n\t#observePickerSelection() {\n\t\tthis.observe(\n\t\t\tthis.#pickerContext.selection.selection,\n\t\t\t(selection) => {\n\t\t\t\tthis.updateValue({ selection });\n\t\t\t\tthis.requestUpdate();\n\t\t\t},\n\t\t\t'umbPickerSelectionObserver',\n\t\t);\n\t}\n\n\t#observeSearch() {\n\t\tthis.observe(\n\t\t\tthis.#pickerContext.search.query,\n\t\t\t(query) => {\n\t\t\t\tthis._searchQuery = query?.query;\n\t\t\t},\n\t\t\t'umbPickerSearchQueryObserver',\n\t\t);\n\t}\n\n\t// Tree Selection\n\t#onTreeItemSelected(event: UmbSelectedEvent) {\n\t\tevent.stopPropagation();\n\t\tthis.#pickerContext.selection.select(event.unique);\n\t\tthis.modalContext?.dispatchEvent(new UmbSelectedEvent(event.unique));\n\t}\n\n\t#onTreeItemDeselected(event: UmbDeselectedEvent) {\n\t\tevent.stopPropagation();\n\t\tthis.#pickerContext.selection.deselect(event.unique);\n\t\tthis.modalContext?.dispatchEvent(new UmbDeselectedEvent(event.unique));\n\t}\n\n\t// Create action\n\t#initCreateAction() {\n\t\t// TODO: If data.enableCreate is true, we should add a button to create a new item. [NL]\n\t\t// Does the tree know enough about this, for us to be able to create a new item? [NL]\n\t\t// I think we need to be able to get entityType and a parentId?, or do we only allow creation in the root? and then create via entity actions? [NL]\n\t\t// To remove the hardcoded URLs for workspaces of entity types, we could make an create event from the tree, which either this or the sidebar impl. will pick up and react to. [NL]\n\t\t// Or maybe the tree item context base can handle this? [NL]\n\t\t// Maybe its a general item context problem to be solved. [NL]\n\t\tconst createAction = this.data?.createAction;\n\t\tif (createAction) {\n\t\t\tthis._createLabel = createAction.label;\n\t\t\tnew UmbModalRouteRegistrationController(\n\t\t\t\tthis,\n\t\t\t\t(createAction.modalToken as typeof UMB_WORKSPACE_MODAL) ?? UMB_WORKSPACE_MODAL,\n\t\t\t)\n\t\t\t\t.onSetup(() => {\n\t\t\t\t\treturn { data: createAction.modalData };\n\t\t\t\t})\n\t\t\t\t.onSubmit((value) => {\n\t\t\t\t\tif (value) {\n\t\t\t\t\t\tthis.value = { selection: [value.unique] };\n\t\t\t\t\t\tthis._submitModal();\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis._rejectModal();\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t\t.observeRouteBuilder((routeBuilder) => {\n\t\t\t\t\tconst oldPath = this._createPath;\n\t\t\t\t\tthis._createPath =\n\t\t\t\t\t\trouteBuilder({}) + createAction.extendWithPathPattern.generateLocal(createAction.extendWithPathParams);\n\t\t\t\t\tthis.requestUpdate('_createPath', oldPath);\n\t\t\t\t});\n\t\t}\n\t}\n\n\toverride render() {\n\t\treturn html`\n\t\t\t\n\t\t\t\t ${this.#renderSearch()} ${this.#renderTree()}\n\t\t\t\t${this.#renderActions()}\n\t\t\t\n\t\t`;\n\t}\n\t#renderSearch() {\n\t\treturn html`\n\t\t\t\n\t\t\t\n\t\t`;\n\t}\n\n\t#renderTree() {\n\t\tif (this._searchQuery) {\n\t\t\treturn nothing;\n\t\t}\n\n\t\treturn html`\n\t\t\t\n\t\t`;\n\t}\n\n\t#renderActions() {\n\t\treturn html`\n\t\t\t
\n\t\t\t\t\n\t\t\t\t${this._createPath\n\t\t\t\t\t? html` `\n\t\t\t\t\t: nothing}\n\t\t\t\t\n\t\t\t
\n\t\t`;\n\t}\n}\n\nexport default UmbTreePickerModalElement;\n\ndeclare global {\n\tinterface HTMLElementTagNameMap {\n\t\t'umb-tree-picker-modal': UmbTreePickerModalElement;\n\t}\n}\n"],"names":["UmbTreeItemPickerContext","UmbPickerContext","host","_pickerContext","_UmbTreePickerModalElement_instances","observePickerSelection_fn","observeSearch_fn","onTreeItemSelected_fn","onTreeItemDeselected_fn","initCreateAction_fn","renderSearch_fn","renderTree_fn","renderActions_fn","UmbTreePickerModalElement","UmbModalBaseElement","__privateAdd","__privateGet","hasSelection","__privateMethod","_changedProperties","multiple","selection","html","query","event","UmbSelectedEvent","UmbDeselectedEvent","createAction","UmbModalRouteRegistrationController","UMB_WORKSPACE_MODAL","value","routeBuilder","oldPath","nothing","ifDefined","__decorateClass","state","customElement","UmbTreePickerModalElement$1"],"mappings":";;;;;AAGO,MAAMA,UAAiCC,EAAiB;AAAA,EAC9D,YAAYC,GAAyB;AACpC,UAAMA,CAAI;AAAA,EACX;AACD;;;;;;;+TCPAC,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC;AAWa,IAAAC,IAAN,cAAmFC,EAGxF;AAAA,EAsBD,cAAc;AACP,aA1BDC,EAAA,MAAAX,CAAA,GAKmD,KAAA,0BAAA;AAAA,MACxD,UAAU;AAAA,MACV,YAAY;AAAA,MACZ,WAAW,CAAC;AAAA,IAAA,GAIY,KAAA,gBAAA,IAWRW,EAAA,MAAAZ,GAAA,IAAIH,EAAyB,IAAI,CAAA,GAI5CgB,EAAA,MAAAb,CAAA,EAAe,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