File Editor
Directories:
.. (Back)
Files:
add.asset.php
add.js
codemirror.asset.php
codemirror.js
common.asset.php
common.js
edit.asset.php
edit.js
export.asset.php
export.js
import.asset.php
import.js
index.php
jspreadsheet.asset.php
jspreadsheet.js
jsuites.asset.php
jsuites.js
list.asset.php
list.js
options.asset.php
options.js
quicktags-button.asset.php
quicktags-button.js
tinymce-button.asset.php
tinymce-button.js
Create New File
Create
Edit File: import.js
(()=>{"use strict";const e=window.React,t=window.ReactDOM,o=(window.wp.hooks,window.ReactJSXRuntime),r=window.wp.components,l=window.wp.primitives,i=(0,o.jsx)(l.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,o.jsx)(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"})}),s=window.wp.i18n,a={"file-upload":{label:(0,s.__)("File Upload","tablepress"),instruction:(0,s.__)("Select files","tablepress")},url:{label:(0,s.__)("URL","tablepress"),instruction:(0,s.__)("File URL","tablepress")},server:{label:(0,s.__)("File on server","tablepress"),instruction:(0,s.__)("Server Path to file","tablepress")},"form-field":{label:(0,s.__)("Manual Input","tablepress"),instruction:(0,s.__)("Import data","tablepress")}};tp.import.showImportSourceUrl||delete a.url,tp.import.showImportSourceServer||delete a.server;const p=Object.entries(a).map((([e,t])=>({value:e,label:t.label}))),n=Object.keys(tp.import.tables).length,m=Object.entries(tp.import.tables).map((([e,t])=>(""===t.trim()&&(t=(0,s.__)("(no name)","tablepress")),{value:e,label:(0,s.sprintf)((0,s.__)("ID %1$s: %2$s","tablepress"),e,t)}))),d=({condition:e,children:t})=>e?(0,o.jsx)(r.Disabled,{children:t}):t,c=()=>{var t;const[l,c]=(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}),u=e=>{c((t=>({...t,validationHighlighting:!1,...e})))},b=(0,e.useRef)(null),h=(0,e.useRef)(null);(0,e.useEffect)((()=>{document.getElementById("tablepress_import-import-form").classList.toggle("no-validation-highlighting",!l.validationHighlighting),l.validationHighlighting||(b.current?.setCustomValidity(""),document.getElementById("components-form-token-input-combobox-control-1")?.setCustomValidity(""))}),[l.validationHighlighting]);const g="file-upload"===l.importSource&&(1<l.importFileUpload.length||1===l.importFileUpload.length&&l.importFileUpload[0].name.endsWith(".zip")),x=0===n||"add"===l.importType||g;return(0,o.jsx)("table",{className:"tablepress-postbox-table fixed",children:(0,o.jsxs)("tbody",{children:[(0,o.jsxs)("tr",{children:[(0,o.jsxs)("th",{className:"column-1",scope:"row",children:[(0,s.__)("Import Source","tablepress"),":"]}),(0,o.jsx)("td",{className:"column-2",children:(0,o.jsx)(r.RadioControl,{name:"import[source]",label:(0,s.__)("Import Source","tablepress"),hideLabelFromVision:!0,selected:l.importSource,onChange:e=>u({importSource:e}),options:p})})]}),(0,o.jsxs)("tr",{className:"top-border bottom-border",children:[(0,o.jsx)("th",{className:"column-1 top-align",scope:"row",children:(0,o.jsxs)("label",{htmlFor:`tables-import-${l.importSource}`,children:[a[l.importSource].instruction,":"]})}),(0,o.jsxs)("td",{className:"column-2",children:[(0,o.jsxs)("div",{className:"file-upload-area",style:{display:"file-upload"===l.importSource?"block":"none"},children:[(0,o.jsx)("input",{name:"import_file_upload[]",id:"tables-import-file-upload",type:"file",multiple:!0,required:"file-upload"===l.importSource,onChange:e=>e.target.files&&u({importFileUpload:e.target.files}),onDragEnter:()=>h.current.classList.add("dragover"),onDragLeave:()=>h.current.classList.remove("dragover")}),(0,o.jsxs)("div",{ref:h,id:"tables-import-file-upload-dropzone",className:"dropzone",children:[(0,o.jsxs)("span",{children:[0===l.importFileUpload.length&&(0,s.__)("Click to select files, or drag them here.","tablepress"),0<l.importFileUpload.length&&(0,s.sprintf)((0,s._n)("You have selected %1$d file:","You have selected %1$d files:",l.importFileUpload.length,"tablepress"),l.importFileUpload.length)]}),[...l.importFileUpload].map((e=>(0,o.jsx)("span",{children:e.name},e.name)))]})]}),tp.import.showImportSourceUrl&&"url"===l.importSource&&(0,o.jsx)(r.TextControl,{__nextHasNoMarginBottom:!0,type:"url",name:"import[url]",id:"tables-import-url",className:"code",required:!0,value:l.importUrl,onChange:e=>u({importUrl:e})}),tp.import.showImportSourceServer&&"server"===l.importSource&&(0,o.jsx)(r.TextControl,{__nextHasNoMarginBottom:!0,ref:b,name:"import[server]",id:"tables-import-server",className:"code",required:!0,value:l.importServer,onChange:e=>u({importServer:e})}),"form-field"===l.importSource&&(0,o.jsx)(r.TextareaControl,{__nextHasNoMarginBottom:!0,name:"import[form-field]",id:"tables-import-form-field",rows:"15",cols:"40",className:"code",required:!0,value:l.importFormField,onChange:e=>u({importFormField:e})}),"form-field"!==l.importSource&&(0,o.jsxs)(r.__experimentalHStack,{alignment:"left",children:[(0,o.jsx)(r.Icon,{icon:i}),(0,o.jsx)("span",{children:(0,s.__)("You can also import multiple tables by placing them in a ZIP file.","tablepress")})]})]})]}),(0,o.jsxs)("tr",{className:"top-border",children:[(0,o.jsxs)("th",{className:"column-1",scope:"row",children:[(0,s.__)("Add, Replace, or Append?","tablepress"),":"]}),(0,o.jsx)("td",{className:"column-2",children:(0,o.jsx)(r.RadioControl,{name:"import[type]",label:(0,s.__)("Import Type","tablepress"),hideLabelFromVision:!0,selected:0===n?"add":l.importType,onChange:e=>u({importType:e}),options:[{value:"add",label:(0,s.__)("Add as new table","tablepress")},{value:"replace",label:(0,s.__)("Replace existing table","tablepress"),disabled:0===n},{value:"append",label:(0,s.__)("Append rows to existing table","tablepress"),disabled:0===n}]})})]}),(0,o.jsxs)("tr",{className:"top-border bottom-border",children:[(0,o.jsx)("th",{className:"column-1 top-align",scope:"row",children:(0,o.jsxs)("label",{htmlFor:"tables-import-existing-table",children:[(0,s.__)("Table to replace or append to","tablepress"),":"]})}),(0,o.jsx)("td",{className:"column-2",children:(0,o.jsx)(d,{condition:x,children:(0,o.jsx)(r.ComboboxControl,{__nextHasNoMarginBottom:!0,id:"tables-import-existing-table",label:(0,s.__)("Table to replace or append to","tablepress"),hideLabelFromVision:!0,placeholder:(0,s.__)("— Select or type —","tablepress"),value:l.importExistingTable,options:m,onChange:e=>u({importExistingTable:e})})})})]}),(0,o.jsxs)("tr",{className:"top-border",children:[(0,o.jsx)("td",{className:"column-1"}),(0,o.jsxs)("td",{className:"column-2",children:[(0,o.jsx)("input",{type:"hidden",name:"import[legacy_import]",value:tp.import.legacyImport}),(0,o.jsx)("input",{type:"hidden",name:"import[existing_table]",value:null!==(t=l.importExistingTable)&&void 0!==t?t:""}),(0,o.jsx)(r.Button,{variant:"primary",type:"submit",text:(0,s._x)("Import","button","tablepress"),onClick:()=>{u({validationHighlighting:!0}),"server"===l.importSource&&tp.import.importServer===l.importServer&&b.current.setCustomValidity((0,s.__)("You must specify a path to a file on the server.","tablepress")),x||l.importExistingTable||document.getElementById("components-form-token-input-combobox-control-1")?.setCustomValidity((0,s.__)("You must select a table.","tablepress"))}})]})]})]})})};((e,o)=>{const r=document.getElementById("tablepress-import-screen");r&&(0,t.createRoot)(r).render(o)})(0,(0,o.jsx)(c,{}))})();
Save Changes
Rename File
Rename