{"version":3,"file":"pane_controller-CWqOhT32.js","sources":["../../../app/javascript/controllers/step/request/pane_controller.js"],"sourcesContent":["import PaneController from \"../../journeys/pane_controller\"\n\nexport default class extends PaneController {\n static values = {\n method: { type: String, default: \"\" },\n url: { type: String, default: \"\" },\n headers: Object,\n contentType: String,\n stepName: String,\n }\n\n static targets = [\n \"header\",\n \"headersList\",\n \"addButton\",\n \"template\",\n \"request\",\n \"url\",\n \"headers\",\n \"headersNote\",\n \"addHeadersButton\",\n \"submit\",\n \"method\",\n \"body\",\n \"addBodyButton\",\n \"contentTypeSelect\",\n \"bodyContent\",\n \"bodyRow\",\n \"bodyTextarea\",\n \"addFieldButton\",\n \"bodyField\",\n \"stepNameInput\",\n ]\n\n initialize() {\n super.initialize()\n\n this.state = {\n method: this.methodValue,\n url: this.urlValue,\n headerVisible: this.headersTarget.classList.contains(\"hidden\") === false,\n bodyVisible: this.bodyTarget.classList.contains(\"hidden\") === false,\n contentType: this.contentTypeValue,\n rawBody: this.bodyTextareaTarget.value,\n }\n\n this.changedState = {...this.state}\n }\n\n sync(commit = false) {\n this.dispatch(\"sync\", {\n detail: {\n commit,\n stepId: this.stepIdValue,\n method: this.state.method,\n url: this.state.url,\n name: this.stepNameValue,\n },\n target: document.documentElement,\n })\n }\n\n saveAndHide() {\n if(this.invalidFields.length > 0) {\n this.invalidFields.forEach(field => {\n this.dispatch(\"invalidate\", { target: field })\n })\n\n return\n }\n\n const oldHeaderVisibility = this.state.headerVisible\n const oldBodyVisibility = this.state.bodyVisible\n\n this.state = { ...this.changedState }\n this.stepNameValue = this.stepNameInputTarget.value.trim()\n\n this.clearQueue()\n this.sync(true)\n this._hide()\n\n if(oldHeaderVisibility !== this.state.headerVisible && this.state.headerVisible === false) {\n this.dispatch(\"headers:clear\", {\n target: this.headersTarget\n })\n }\n\n if(oldBodyVisibility !== this.state.bodyVisible && this.state.bodyVisible === false) {\n this.dispatch(\"content-type:clear\", {\n target: this.contentTypeSelectTarget\n })\n\n this.dispatch(\"body:clear\", {\n target: this.bodyContentTarget\n })\n\n this.bodyTextareaTarget.value = \"\"\n this.bodyTextareaTarget.disabled = true\n this.bodyTextareaTarget.classList.add(\"hidden\")\n this.bodyContentTarget.classList.add(\"hidden\")\n\n this.hideBody()\n }\n\n if(this.state.headerVisible) {\n this.dispatch(\"headers:save\", {\n target: this.headersTarget\n })\n }\n\n if(this.state.bodyVisible) {\n this.dispatch(\"body:save\", {\n target: this.bodyContentTarget\n })\n }\n\n if(this.state.contentType) {\n this.showBodyContent(this.state.contentType, true)\n }\n }\n\n cancel() {\n this._abort()\n this._hide()\n\n setTimeout(this.clearQueue, 1000)\n\n this.urlTarget.value = this.state.url\n\n if(this.changedState.method !== this.state.method) {\n this.dispatch(\"select\", {\n target: this.methodTarget,\n detail: this.state.method\n })\n }\n\n if(this.state.headerVisible && !this.changedState.headerVisible) {\n this.showHeaders()\n }\n\n if(!this.state.headerVisible && this.changedState.headerVisible) {\n this.hideHeaders()\n }\n\n if(this.state.bodyVisible && !this.changedState.bodyVisible) {\n this.showBody()\n }\n\n if(!this.state.bodyVisible && this.changedState.bodyVisible) {\n this.hideBody()\n }\n\n if(this.state.contentType !== this.changedState.contentType) {\n this.dispatch(\"content-type:set\", {\n detail: this.state.contentType,\n target: this.contentTypeSelectTarget\n })\n\n this.showBodyContent(this.state.contentType, true)\n }\n\n this.dispatch(\"headers:restore\", {\n target: this.headersTarget\n })\n\n this.dispatch(\"body:restore\", {\n target: this.bodyContentTarget\n })\n\n this.bodyTextareaTarget.value = this.state.rawBody\n\n this.changedState = { ...this.state }\n }\n\n syncValues() {\n if (this.hasUnsavedChanges) {\n window.paneId = this.element.id\n }\n }\n\n _abort() {\n this.dispatch(\"sync:abort\", {\n detail: this.stepIdValue,\n target: document.documentElement,\n })\n\n super._abort()\n }\n\n methodChanged({ target: { value } }) {\n this.changedState = {\n ...this.changedState,\n method: value,\n }\n\n this.submitTarget.disabled = this.changedState.method.length === 0 || this.changedState.url.length === 0\n }\n\n showHeaders() {\n this.changedState = {\n ...this.changedState,\n headerVisible: true,\n }\n\n if(this.headers.length === 0) {\n this.dispatch(\"headers:add\", { target: this.headersTarget })\n }\n\n this.headersTarget.classList.remove(\"hidden\")\n this.headersNoteTarget.classList.remove(\"hidden\")\n\n this.addHeadersButtonTarget.classList.add(\"hidden\")\n }\n\n showBody() {\n this.changedState = {\n ...this.changedState,\n bodyVisible: true,\n }\n\n this.bodyTarget.classList.remove(\"hidden\")\n this.addBodyButtonTarget.classList.add(\"hidden\")\n }\n\n hideBody() {\n this.changedState = {\n ...this.changedState,\n bodyVisible: false,\n contentType: null\n }\n\n this.bodyTarget.classList.add(\"hidden\")\n this.addBodyButtonTarget.classList.remove(\"hidden\")\n }\n\n hideHeaders() {\n this.changedState = {\n ...this.changedState,\n headerVisible: false,\n }\n\n this.headersTarget.classList.add(\"hidden\")\n this.headersNoteTarget.classList.add(\"hidden\")\n\n this.addHeadersButtonTarget.classList.remove(\"hidden\")\n }\n\n onUrlChange() {\n this.changedState = {\n ...this.changedState,\n url: this.urlTarget.value,\n }\n\n this.submitTarget.disabled = this.changedState.method.length === 0 || this.changedState.url.length === 0\n }\n\n onRawBodyChange() {\n this.changedState = {\n ...this.changedState,\n rawBody: this.bodyTextareaTarget.value,\n }\n }\n\n setContentType({ currentTarget: { dataset } }) {\n this.changedState = {\n ...this.changedState,\n contentType: dataset.contentType,\n }\n\n if(this.bodyFields.length === 0) {\n this.dispatch(\"body:add\", { target: this.bodyContentTarget })\n }\n\n this.dispatch(\"content-type:set\", {\n detail: dataset.contentType,\n target: this.headersTarget\n })\n\n if(!this.state.headerVisible) {\n this.showHeaders()\n }\n\n this.bodyContentTarget.classList.remove(\"hidden\")\n this.showBodyContent(dataset.contentType)\n }\n\n showBodyContent(contentType, commitChanges = false) {\n if([\"multipart/form-data\", \"application/x-www-form-urlencoded\"].includes(contentType)) {\n this.bodyRowTarget.querySelectorAll(\"input\").forEach((input) => input.disabled = false)\n this.bodyRowTarget.classList.remove(\"hidden\")\n\n this.bodyTextareaTarget.classList.add(\"hidden\")\n this.addFieldButtonTarget.classList.remove(\"hidden\")\n\n if(commitChanges) {\n this.bodyTextareaTarget.value = \"\"\n this.bodyTextareaTarget.disabled = true\n }\n } else {\n this.bodyRowTarget.classList.add(\"hidden\")\n this.addFieldButtonTarget.classList.add(\"hidden\")\n\n if(commitChanges) {\n this.bodyRowTarget.querySelectorAll(\"input\").forEach((input) => {\n input.value = \"\"\n input.disabled = true\n })\n }\n\n this.bodyTextareaTarget.classList.remove(\"hidden\")\n this.bodyTextareaTarget.disabled = false\n }\n }\n\n get hasUnsavedChanges() {\n return this.nameChanged\n || Object.keys(this.state).some((key) => this.state[key] !== this.changedState[key])\n || this.element.querySelectorAll(\"[data-changed]\").length > 0\n || this.changedState.headerVisible && this.headers.some((header) => !header.hasAttribute(\"data-saved\")) || this.headers.some((header) => header.hasAttribute(\"data-saved\") && header.classList.contains(\"hidden\"))\n || this.hasRows && this.changedState.bodyVisible && this.bodyFields.some((field) => !field.hasAttribute(\"data-saved\")) || this.bodyFields.some((field) => field.hasAttribute(\"data-saved\") && field.classList.contains(\"hidden\"))\n }\n\n get nameChanged() {\n return this.stepNameValue !== this.stepNameInputTarget.value.trim()\n }\n\n get invalidFields() {\n return [\n ...(this.changedState.headerVisible ? this.headers.filter(header => header.hasAttribute(\"data-invalid\")) : []),\n ...(this.hasRows ? this.bodyFields.filter(field => field.hasAttribute(\"data-invalid\")) : []),\n ]\n }\n\n get headers() {\n return this.headerTargets.filter((header) => !header.hasAttribute(\"data-template\"))\n }\n\n get bodyFields() {\n return this.bodyFieldTargets.filter((field) => !field.hasAttribute(\"data-template\"))\n }\n\n get hasRows() {\n return [\"multipart/form-data\", \"application/x-www-form-urlencoded\"].includes(this.changedState.contentType)\n }\n}\n"],"names":["pane_controller","PaneController","commit","field","oldHeaderVisibility","oldBodyVisibility","value","dataset","contentType","commitChanges","input","key","header","__publicField"],"mappings":"sNAEe,MAAKA,UAASC,CAAe,CAg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