{"version":3,"file":"nestedElementExtendedJs-3b1295d5.js","sources":["../../../../../static/src/js/nestedElementExtended.ts"],"sourcesContent":["(function (window: any) {\n const {Craft, Garnish, $} = window;\n if (!Craft || !Garnish || !$) {\n return;\n }\n\n /**\n * @see https://github.com/craftcms/cms/blob/5.x/src/web/assets/cp/src/js/NestedElementManager.js\n */\n Craft.NestedElementExtended = Garnish.Base.extend({\n settings: {}, childParent: {}, helper: undefined,\n\n init: function (config: { settings: any, childParent: any }, helper: any) {\n const self = this;\n\n this.settings = config.settings || {};\n this.childParent = config.childParent || {};\n this.helper = helper;\n\n if (!Garnish.DisclosureMenu || !Craft.NestedElementManager) {\n return;\n }\n\n const nestedInitFn = Craft.NestedElementManager.prototype.init;\n Craft.NestedElementManager.prototype.init = function (...args: any[]) {\n nestedInitFn.apply(this, args);\n };\n\n const nestedCreateElementEditorFn = Craft.NestedElementManager.prototype.createElementEditor;\n Craft.NestedElementManager.prototype.createElementEditor = function ($element: any) {\n const slideout = Craft.createElementEditor(this.elementType, $element, {\n onBeforeSubmit: async () => {\n // Derives from the original method, because it is connecting the wrong owner id\n if (\n typeof this.elementEditor !== 'undefined' &&\n Garnish.hasAttr($element, 'data-owner-is-canonical') &&\n !this.elementEditor.settings.isUnpublishedDraft\n ) {\n await slideout.elementEditor.checkForm(true, true);\n await this.markAsDirty();\n }\n },\n onSubmit: (ev: any) => {\n if (ev.data.id != $element.data('id')) {\n // swap the element with the new one\n $element\n .attr('data-id', ev.data.id)\n .data('id', ev.data.id)\n .data('owner-id', ev.data.ownerId);\n Craft.refreshElementInstances(ev.data.id);\n }\n },\n });\n };\n\n const disclosureMenuShowFn = Garnish.DisclosureMenu.prototype.show;\n Garnish.DisclosureMenu.prototype.show = function (...args: any[]) {\n self.initDisclosureMenu(this);\n disclosureMenuShowFn.apply(this, args);\n };\n\n const disclosureMenuInitFn = Garnish.DisclosureMenu.prototype.init;\n Garnish.DisclosureMenu.prototype.init = function (...args: any[]) {\n disclosureMenuInitFn.apply(this, args);\n self.initAddButtonMenu(this);\n };\n },\n\n initDisclosureMenu(disclosureMenu: any) {\n const {$trigger, $container} = disclosureMenu;\n if (!$trigger || !$container || !$trigger.hasClass('action-btn')) {\n return;\n }\n\n const $element = $trigger.closest('.card-actions').parent('.card-actions-container').parent('.card');\n if (!$element.length) {\n return;\n }\n\n const {typeId, id} = $element.data();\n if (!typeId || !id) {\n return;\n }\n\n const $parent = $element.closest('.nested-element-cards');\n const nem = $parent.data('nestedElementManager');\n if (!nem) {\n return;\n }\n\n if (nem.settings.mode !== 'cards' || !nem.settings.canCreate) {\n return;\n }\n\n if (disclosureMenu._hasNestedElementExtensionButtonsInitialized) {\n this.checkPaste($container, $element, nem);\n this.checkDuplicate($container, nem);\n return;\n }\n disclosureMenu._hasNestedElementExtensionButtonsInitialized = true;\n\n this.addMenu($container, typeId, $element, nem);\n },\n\n initAddButtonMenu(disclosureMenu: any) {\n if (!this.settings.expandMenu) {\n return;\n }\n\n const {$trigger, $container} = disclosureMenu;\n const $parent = $trigger.parent();\n const $wrapper = $trigger.closest('.nested-element-cards');\n const nem = $wrapper.data('nestedElementManager');\n if (!nem || !$trigger || !$container || $parent.hasClass('card-actions') || !$wrapper.attr('id')) {\n return;\n }\n\n if (!Array.isArray(nem.settings.createAttributes)) {\n return;\n }\n\n if ($trigger._hasNestedElementExtensionButtonsInitialized) {\n return;\n }\n $trigger.hide();\n $trigger._hasNestedElementExtensionButtonsInitialized = true;\n\n const $buttonContainer = $('
');\n\n const $createBtn = Craft.ui\n .createButton({\n label: nem.settings.createButtonLabel,\n spinner: true,\n })\n .addClass('add icon disabled');\n\n const $btnContainer = $('').appendTo($container);\n $createBtn.addClass('dashed').appendTo($btnContainer);\n\n const createMenuId = `menu-${Math.floor(Math.random() * 1000000)}`;\n const $menu = $('', {\n id: createMenuId,\n class: 'menu menu--disclosure',\n }).insertAfter($createBtn);\n const $ul = $('