|
1
|
|
-(()=>{"use strict";const e=window.React,t=window.ReactDOM,r=window.wp.components,l=window.wp.primitives,a=(0,e.createElement)(l.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,e.createElement)(l.Path,{d:"M12 3.2c-4.8 0-8.8 3.9-8.8 8.8 0 4.8 3.9 8.8 8.8 8.8 4.8 0 8.8-3.9 8.8-8.8 0-4.8-4-8.8-8.8-8.8zm0 16c-4 0-7.2-3.3-7.2-7.2C4.8 8 8 4.8 12 4.8s7.2 3.3 7.2 7.2c0 4-3.2 7.2-7.2 7.2zM11 17h2v-6h-2v6zm0-8h2V7h-2v2z"})),o=window.wp.i18n,i={"file-upload":{label:(0,o.__)("File Upload","tablepress"),instruction:(0,o.__)("Select files","tablepress")},url:{label:(0,o.__)("URL","tablepress"),instruction:(0,o.__)("File URL","tablepress")},server:{label:(0,o.__)("File on server","tablepress"),instruction:(0,o.__)("Server Path to file","tablepress")},"form-field":{label:(0,o.__)("Manual Input","tablepress"),instruction:(0,o.__)("Import data","tablepress")}};tp.import.showImportSourceServer||delete i.server;const p=Object.keys(tp.import.tables).length,m=Object.entries(tp.import.tables).map((([t,r])=>{""===r.trim()&&(r=(0,o.__)("(no name)","tablepress"));const l=(0,o.sprintf)((0,o.__)("ID %1$s: %2$s","tablepress"),t,r);return(0,e.createElement)("option",{key:t,value:t},l)}));((e,r)=>{const l=document.getElementById("tablepress-import-screen");l&&("function"==typeof t.createRoot?(0,t.createRoot)(l).render(r):(0,t.render)(r,l))})(0,(0,e.createElement)((()=>{const[t,l]=(0,e.useState)({importSource:tp.import.importSource,importType:tp.import.importType,importFileUpload:[],importUrl:tp.import.importUrl,importServer:tp.import.importServer,importFormField:tp.import.importFormField,importExistingTable:tp.import.importExistingTable,validationHighlighting:!1}),n=e=>{const r={...t,validationHighlighting:!1,...e};l(r)},s=(0,e.useRef)(null),c=(0,e.useRef)(null),d=(0,e.useRef)(null);(0,e.useEffect)((()=>{jSuites.dropdown(c.current,{autocomplete:!0,placeholder:(0,o.__)("— Select or type —","tablepress"),onchange:(e,t,r,a)=>{l((e=>({...e,validationHighlighting:!1,importExistingTable:a})))}})}),[]),(0,e.useEffect)((()=>{document.getElementById("tablepress_import-import-form").classList.toggle("no-validation-highlighting",!t.validationHighlighting),t.validationHighlighting||(s.current?.setCustomValidity(""),c.current.previousElementSibling.querySelector(".jdropdown-header")?.setCustomValidity(""))}),[t.validationHighlighting]);const u="file-upload"===t.importSource&&(1<t.importFileUpload.length||1===t.importFileUpload.length&&t.importFileUpload[0].name.endsWith(".zip")),b=0===p||"add"===t.importType||u;return(0,e.useEffect)((()=>{c.current.previousElementSibling.classList.toggle("disabled",b)}),[b]),(0,e.createElement)("table",{className:"tablepress-postbox-table fixed"},(0,e.createElement)("tbody",null,(0,e.createElement)("tr",null,(0,e.createElement)("th",{className:"column-1",scope:"row",id:"import-source-header"},(0,o.__)("Import Source","tablepress"),":"),(0,e.createElement)("td",{className:"column-2"},Object.entries(i).map((([r,l])=>(0,e.createElement)("label",{key:r,htmlFor:`tables-import-source-${r}`},(0,e.createElement)("input",{name:"import[source]",id:`tables-import-source-${r}`,type:"radio","aria-labelledby":"import-source-header",value:r,checked:r===t.importSource,onChange:e=>n({importSource:e.target.value})})," ",l.label))))),(0,e.createElement)("tr",{className:"top-border bottom-border"},(0,e.createElement)("th",{className:"column-1 top-align",scope:"row"},(0,e.createElement)("label",{htmlFor:`tables-import-${t.importSource}`},i[t.importSource].instruction,":")),(0,e.createElement)("td",{className:"column-2"},(0,e.createElement)("div",{className:"file-upload-area",style:{display:"file-upload"===t.importSource?"block":"none"}},(0,e.createElement)("input",{name:"import_file_upload[]",id:"tables-import-file-upload",type:"file",multiple:!0,required:"file-upload"===t.importSource,onChange:e=>e.target.files&&n({importFileUpload:e.target.files}),onDragEnter:()=>d.current.classList.add("dragover"),onDragLeave:()=>d.current.classList.remove("dragover")}),(0,e.createElement)("div",{ref:d,className:"dropzone"},(0,e.createElement)("span",null,0===t.importFileUpload.length&&(0,o.__)("Click to select files, or drag them here.","tablepress"),0<t.importFileUpload.length&&(0,o.sprintf)((0,o._n)("You have selected %1$d file:","You have selected %1$d files:",t.importFileUpload.length,"tablepress"),t.importFileUpload.length)),[...t.importFileUpload].map((t=>(0,e.createElement)("span",{key:t.name},t.name))))),"url"===t.importSource&&(0,e.createElement)("input",{type:"url",name:"import[url]",id:"tables-import-url",className:"large-text code",required:!0,value:t.importUrl,onChange:e=>n({importUrl:e.target.value})}),tp.import.showImportSourceServer&&"server"===t.importSource&&(0,e.createElement)("input",{ref:s,type:"text",name:"import[server]",id:"tables-import-server",className:"large-text code",required:!0,value:t.importServer,onChange:e=>n({importServer:e.target.value})}),"form-field"===t.importSource&&(0,e.createElement)("textarea",{name:"import[form-field]",id:"tables-import-form-field",rows:"15",cols:"40",className:"large-text code",required:!0,value:t.importFormField,onChange:e=>n({importFormField:e.target.value})}),"form-field"!==t.importSource&&(0,e.createElement)("p",{className:"info-text",style:{marginTop:"0.5em"}},(0,e.createElement)(r.Icon,{icon:a}),(0,e.createElement)("span",null,(0,o.__)("You can also import multiple tables by placing them in a ZIP file.","tablepress"))))),(0,e.createElement)("tr",{className:"top-border"},(0,e.createElement)("th",{className:"column-1",scope:"row",id:"import-type-header"},(0,o.__)("Add, Replace, or Append?","tablepress"),":"),(0,e.createElement)("td",{className:"column-2"},(0,e.createElement)("label",{htmlFor:"tables-import-type-add"},(0,e.createElement)("input",{name:"import[type]",id:"tables-import-type-add",type:"radio","aria-labelledby":"import-type-header",value:"add",checked:"add"===t.importType||0===p,onChange:e=>n({importType:e.target.value})})," ",(0,o.__)("Add as new table","tablepress")),(0,e.createElement)("label",{htmlFor:"tables-import-type-replace"},(0,e.createElement)("input",{name:"import[type]",id:"tables-import-type-replace",type:"radio","aria-labelledby":"import-type-header",value:"replace",disabled:0===p,checked:"replace"===t.importType,onChange:e=>n({importType:e.target.value})})," ",(0,o.__)("Replace existing table","tablepress")),(0,e.createElement)("label",{htmlFor:"tables-import-type-append"},(0,e.createElement)("input",{name:"import[type]",id:"tables-import-type-append",type:"radio","aria-labelledby":"import-type-header",value:"append",disabled:0===p,checked:"append"===t.importType,onChange:e=>n({importType:e.target.value})})," ",(0,o.__)("Append rows to existing table","tablepress")))),(0,e.createElement)("tr",{className:"top-border bottom-border"},(0,e.createElement)("th",{className:"column-1",scope:"row"},(0,e.createElement)("label",{htmlFor:"tables-import-existing-table"},(0,o.__)("Table to replace or append to","tablepress"),":")),(0,e.createElement)("td",{className:"column-2"},(0,e.createElement)("select",{ref:c,id:"tables-import-existing-table",name:"import[existing_table]",disabled:b,value:t.importExistingTable},(0,e.createElement)("option",{value:""}," "),m))),(0,e.createElement)("tr",{className:"top-border"},(0,e.createElement)("td",{className:"column-1"}),(0,e.createElement)("td",{className:"column-2"},(0,e.createElement)("input",{type:"hidden",name:"import[legacy_import]",value:tp.import.legacyImport}),(0,e.createElement)("input",{type:"submit",value:(0,o._x)("Import","button","tablepress"),className:"button button-primary button-large",id:"import-submit-button",onClick:()=>{n({validationHighlighting:!0}),"server"===t.importSource&&tp.import.importServer===t.importServer&&s.current.setCustomValidity((0,o.__)("You must specify a path to a file on the server.","tablepress")),b||""!==t.importExistingTable||c.current.previousElementSibling.querySelector(".jdropdown-header").setCustomValidity((0,o.__)("You must select a table.","tablepress"))}})))))}),null))})(); |
|
1
|
+(()=>{"use strict";const e={n:t=>{const o=t&&t.__esModule?()=>t.default:()=>t;return e.d(o,{a:o}),o},d:(t,o)=>{for(var r in o)e.o(o,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:o[r]})},o:(e,t)=>Object.hasOwn(e,t)},t=window.React,o=window.ReactDOM,r=window.wp.domReady;var l=e.n(r);window.wp.hooks;const i=window.ReactJSXRuntime,s=window.wp.components,a=window.wp.primitives;var n=(0,i.jsx)(a.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",style:{fill:"none"},stroke:"currentColor",strokeWidth:"1.5",children:(0,i.jsx)(a.Path,{d:"M12 16V11M12 9.5V8M19.25 12C19.25 16.0041 16.0041 19.25 12 19.25C7.99594 19.25 4.75 16.0041 4.75 12C4.75 7.99594 7.99594 4.75 12 4.75C16.0041 4.75 19.25 7.99594 19.25 12Z",strokeLinejoin:"round",vectorEffect:"non-scaling-stroke"})});const p=window.wp.i18n,m={"file-upload":{label:(0,p.__)("File Upload","tablepress"),instruction:(0,p.__)("Select files","tablepress")},url:{label:(0,p.__)("URL","tablepress"),instruction:(0,p.__)("File URL","tablepress")},server:{label:(0,p.__)("File on server","tablepress"),instruction:(0,p.__)("Server Path to file","tablepress")},"form-field":{label:(0,p.__)("Manual Input","tablepress"),instruction:(0,p.__)("Import data","tablepress")}};tp.import.showImportSourceUrl||delete m.url,tp.import.showImportSourceServer||delete m.server;const d=Object.entries(m).map(([e,t])=>({value:e,label:t.label})),c=Object.keys(tp.import.tables).length,u=Object.entries(tp.import.tables).map(([e,t])=>(""===t.trim()&&(t=(0,p.__)("(no name)","tablepress")),{value:e,label:(0,p.sprintf)((0,p.__)("ID %1$s: %2$s","tablepress"),e,t)})),b=({condition:e,children:t})=>e?(0,i.jsx)(s.Disabled,{children:t}):t,h=()=>{const[e,o]=(0,t.useState)({importSource:tp.import.importSource,importType:tp.import.importType,importFileUpload:[],importUrl:tp.import.importUrl,importServer:tp.import.importServer,importFormField:tp.import.importFormField,importExistingTable:tp.import.importExistingTable,validationHighlighting:!1}),r=e=>{o(t=>({...t,validationHighlighting:!1,...e}))},l=(0,t.useRef)(null),a=(0,t.useRef)(null);(0,t.useEffect)(()=>{document.getElementById("tablepress_import-import-form").classList.toggle("no-validation-highlighting",!e.validationHighlighting),e.validationHighlighting||(l.current?.setCustomValidity(""),document.getElementById("components-form-token-input-combobox-control-1")?.setCustomValidity(""))},[e.validationHighlighting]);const h="file-upload"===e.importSource&&(1<e.importFileUpload.length||1===e.importFileUpload.length&&e.importFileUpload[0].name.endsWith(".zip")),x=0===c||"add"===e.importType||h;return(0,i.jsx)("table",{className:"tablepress-postbox-table fixed",children:(0,i.jsxs)("tbody",{children:[(0,i.jsxs)("tr",{children:[(0,i.jsxs)("th",{className:"column-1",scope:"row",children:[(0,p.__)("Import Source","tablepress"),":"]}),(0,i.jsx)("td",{className:"column-2",children:(0,i.jsx)(s.RadioControl,{name:"import[source]",label:(0,p.__)("Import Source","tablepress"),hideLabelFromVision:!0,selected:e.importSource,onChange:e=>r({importSource:e}),options:d})})]}),(0,i.jsxs)("tr",{className:"top-border bottom-border",children:[(0,i.jsx)("th",{className:"column-1 top-align",scope:"row",children:(0,i.jsxs)("label",{htmlFor:`tables-import-${e.importSource}`,children:[m[e.importSource].instruction,":"]})}),(0,i.jsxs)("td",{className:"column-2",children:[(0,i.jsxs)("div",{className:"file-upload-area",style:{display:"file-upload"===e.importSource?"block":"none"},children:[(0,i.jsx)("input",{name:"import_file_upload[]",id:"tables-import-file-upload",type:"file",multiple:!0,required:"file-upload"===e.importSource,onChange:e=>e.target.files&&r({importFileUpload:e.target.files}),onDragEnter:()=>a.current.classList.add("dragover"),onDragLeave:()=>a.current.classList.remove("dragover")}),(0,i.jsxs)("div",{ref:a,id:"tables-import-file-upload-dropzone",className:"dropzone",children:[(0,i.jsxs)("span",{children:[0===e.importFileUpload.length&&(0,p.__)("Click to select files, or drag them here.","tablepress"),0<e.importFileUpload.length&&(0,p.sprintf)((0,p._n)("You have selected %1$d file:","You have selected %1$d files:",e.importFileUpload.length,"tablepress"),e.importFileUpload.length)]}),[...e.importFileUpload].map(e=>(0,i.jsx)("span",{children:e.name},e.name))]})]}),tp.import.showImportSourceUrl&&"url"===e.importSource&&(0,i.jsx)(s.TextControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,type:"url",name:"import[url]",id:"tables-import-url",className:"code",required:!0,value:e.importUrl,onChange:e=>r({importUrl:e})}),tp.import.showImportSourceServer&&"server"===e.importSource&&(0,i.jsx)(s.TextControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,ref:l,name:"import[server]",id:"tables-import-server",className:"code",required:!0,value:e.importServer,onChange:e=>r({importServer:e})}),"form-field"===e.importSource&&(0,i.jsx)(s.TextareaControl,{__nextHasNoMarginBottom:!0,name:"import[form-field]",id:"tables-import-form-field",rows:"15",cols:"40",className:"code",required:!0,value:e.importFormField,onChange:e=>r({importFormField:e})}),"form-field"!==e.importSource&&(0,i.jsxs)(s.__experimentalHStack,{alignment:"left",children:[(0,i.jsx)(s.Icon,{icon:n}),(0,i.jsx)("span",{children:(0,p.__)("You can also import multiple tables by placing them in a ZIP file.","tablepress")})]})]})]}),(0,i.jsxs)("tr",{className:"top-border",children:[(0,i.jsxs)("th",{className:"column-1",scope:"row",children:[(0,p.__)("Add, Replace, or Append?","tablepress"),":"]}),(0,i.jsx)("td",{className:"column-2",children:(0,i.jsx)(s.RadioControl,{name:"import[type]",label:(0,p.__)("Import Type","tablepress"),hideLabelFromVision:!0,selected:0===c?"add":e.importType,onChange:e=>r({importType:e}),options:[{value:"add",label:(0,p.__)("Add as new table","tablepress")},{value:"replace",label:(0,p.__)("Replace existing table","tablepress"),disabled:0===c},{value:"append",label:(0,p.__)("Append rows to existing table","tablepress"),disabled:0===c}]})})]}),(0,i.jsxs)("tr",{className:"top-border bottom-border",children:[(0,i.jsx)("th",{className:"column-1 top-align",scope:"row",children:(0,i.jsxs)("label",{htmlFor:"tables-import-existing-table",children:[(0,p.__)("Table to replace or append to","tablepress"),":"]})}),(0,i.jsx)("td",{className:"column-2",children:(0,i.jsx)(b,{condition:x,children:(0,i.jsx)(s.ComboboxControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,id:"tables-import-existing-table",label:(0,p.__)("Table to replace or append to","tablepress"),hideLabelFromVision:!0,placeholder:(0,p.__)("— Select or type —","tablepress"),value:e.importExistingTable,options:u,onChange:e=>r({importExistingTable:e})})})})]}),(0,i.jsxs)("tr",{className:"top-border",children:[(0,i.jsx)("td",{className:"column-1"}),(0,i.jsxs)("td",{className:"column-2",children:[(0,i.jsx)("input",{type:"hidden",name:"import[legacy_import]",value:tp.import.legacyImport}),(0,i.jsx)("input",{type:"hidden",name:"import[existing_table]",value:e.importExistingTable??""}),(0,i.jsx)(s.Button,{variant:"primary",type:"submit",text:(0,p._x)("Import","button","tablepress"),onClick:()=>{r({validationHighlighting:!0}),"server"===e.importSource&&tp.import.importServer===e.importServer&&l.current.setCustomValidity((0,p.__)("You must specify a path to a file on the server.","tablepress")),x||e.importExistingTable||document.getElementById("components-form-token-input-combobox-control-1")?.setCustomValidity((0,p.__)("You must select a table.","tablepress"))}})]})]})]})})};var x;x=(0,i.jsx)(h,{}),l()(()=>{const e=document.getElementById("tablepress-import-screen");e&&(0,o.createRoot)(e).render(x)})})(); |