domma-cms 1.38.0 → 1.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/CLAUDE.md +17 -0
- package/admin/js/api.js +1 -1
- package/admin/js/app.js +1 -1
- package/admin/js/lib/plugins-arrange.js +2 -2
- package/admin/js/lib/wordpress-import-arrange.js +1 -1
- package/admin/js/templates/docs/usage-tools.html +18 -3
- package/admin/js/templates/plugins.html +2 -0
- package/admin/js/templates/wordpress-import.html +23 -5
- package/admin/js/views/plugins.js +24 -12
- package/admin/js/views/wordpress-import.js +10 -10
- package/bin/update.js +2 -0
- package/docs/DommaFeatures.md +7 -0
- package/docs/configuration.md +1 -0
- package/docs/plugin-development.md +11 -0
- package/package.json +1 -1
- package/server/routes/api/plugin-marketplace.js +249 -19
- package/server/routes/api/wordpress-import.js +62 -3
- package/server/server.js +1 -1
- package/server/services/siteGitignore.js +2 -0
- package/server/services/storeClient.js +333 -0
- package/server/services/tools.js +1 -1
- package/server/services/wpImport/crawl.js +619 -0
- package/server/services/wpImport/index.js +53 -8
- package/server/services/wpImport/plan.js +5 -3
- package/server/services/wpImport/platforms.js +186 -0
- package/server/services/wpImport/wxr.js +6 -2
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
<!-- Start: upload, and uploads waiting -->
|
|
19
19
|
<div class="wpx-start" hidden data-bind-hidden="mode.value !== 'start'">
|
|
20
20
|
<div class="wpx-card">
|
|
21
|
-
<div class="wpx-card-title">Upload a WordPress export
|
|
22
|
-
<span data-help-title="Where the export comes from" data-help="
|
|
21
|
+
<div class="wpx-card-title">Upload a WordPress or Squarespace export
|
|
22
|
+
<span data-help-title="Where the export comes from" data-help="WordPress: go to Tools › Export, choose All content and press Download Export File. That gives you an .xml file (some hosts zip it - a .zip holding it works too). It holds your pages, posts, comments, menus and the addresses of your media - not the media files themselves; those are fetched from your old site, or from a zip of its wp-content/uploads folder, on the next screen. Squarespace: in your site's settings open Import & Export, press Export and choose WordPress. Its file holds your pages, one blog and your images' addresses; the images are fetched from Squarespace, so do this before you close the account."></span></div>
|
|
23
23
|
<p class="wpx-note">Nothing on this site changes until you have seen the preview and pressed <strong>Run import</strong>. Up to <span data-bind-text="wxrLimit.value"></span>.</p>
|
|
24
24
|
<label class="wpx-drop" data-bind-class="dropping.value && 'is-over'">
|
|
25
25
|
<input type="file" class="wpx-file" accept=".xml,.zip,application/xml,text/xml,application/zip">
|
|
@@ -33,6 +33,21 @@
|
|
|
33
33
|
<p class="wpx-note is-bad" hidden data-bind-hidden="!uploadError.value" data-bind-text="uploadError.value"></p>
|
|
34
34
|
</div>
|
|
35
35
|
|
|
36
|
+
<div class="wpx-card wpx-crawl">
|
|
37
|
+
<div class="wpx-card-title"><span data-icon="globe" data-icon-size="16"></span> Copy a live site - Wix, or any site without an export
|
|
38
|
+
<span data-help-title="Reading a live site" data-help="Wix has no export, so the importer reads the site the way a visitor's browser does: every page its sitemap lists (or, with no sitemap, every page linked from the home page), each page's words, headings, images, links and documents, blog posts with their dates and authors, and the home page's menu. Only that site is read, up to 500 pages. Nothing on your old site changes, and nothing here changes until you have seen the preview and pressed Run import. Layouts, forms, galleries that load as you scroll, shops and bookings are not copied - the preview lists what to check."></span></div>
|
|
39
|
+
<p class="wpx-note">Type the site's address. Reading takes a minute or two for most sites; you then see the same preview as for an export.</p>
|
|
40
|
+
<div class="wpx-crawl-row" hidden data-bind-hidden="crawlRunning.value">
|
|
41
|
+
<input type="text" inputmode="url" class="form-input wpx-crawl-url" placeholder="www.example.com" aria-label="The address of the site to copy" data-model="crawlUrl.value">
|
|
42
|
+
<button type="button" class="btn btn-sm btn-primary" data-on-click="startCrawl" data-bind-disabled="!crawlReady.value"><span data-icon="download" data-icon-size="14"></span> Read the site</button>
|
|
43
|
+
</div>
|
|
44
|
+
<div class="wpx-crawl-progress" hidden data-bind-hidden="!crawlRunning.value">
|
|
45
|
+
<p class="wpx-note" role="status" data-bind-text="crawlText.value"></p>
|
|
46
|
+
<button type="button" class="btn btn-sm btn-outline" data-on-click="stopCrawl">Stop</button>
|
|
47
|
+
</div>
|
|
48
|
+
<p class="wpx-note is-bad" hidden data-bind-hidden="!crawlError.value" data-bind-text="crawlError.value"></p>
|
|
49
|
+
</div>
|
|
50
|
+
|
|
36
51
|
<div class="wpx-card" hidden data-bind-hidden="!stagedRows.value.length">
|
|
37
52
|
<div class="wpx-card-title">Waiting to run
|
|
38
53
|
<span data-help="Exports you uploaded but have not imported yet. Click one to see its preview. Right-click (or ⋮, or Shift+F10) to discard it. An upload not run within a day is removed."></span></div>
|
|
@@ -78,7 +93,7 @@
|
|
|
78
93
|
<span data-help-title="Media files" data-help="From the old site: each file is downloaded from the WordPress site's own address while it is still online (only that site - never anywhere else). From a zip: zip the wp-content/uploads folder (your host's file manager or FTP) and upload it below - use this when the old site is offline. Leave out: pages keep pointing at the old site's files. SVG files are never imported (they can carry scripts)."></span></span>
|
|
79
94
|
<div class="wpx-seg" role="group" aria-label="Media files">
|
|
80
95
|
<button type="button" data-on-click="mediaDownload" data-bind-class="opt.value.media === 'download' && 'is-on'">From the old site</button>
|
|
81
|
-
<button type="button" data-on-click="mediaZip" data-bind-class="opt.value.media === 'zip' && 'is-on'">From a zip</button>
|
|
96
|
+
<button type="button" data-on-click="mediaZip" data-bind-class="opt.value.media === 'zip' && 'is-on'" hidden data-bind-hidden="!fromWp.value">From a zip</button>
|
|
82
97
|
<button type="button" data-on-click="mediaSkip" data-bind-class="opt.value.media === 'skip' && 'is-on'">Leave out</button>
|
|
83
98
|
</div>
|
|
84
99
|
<div class="wpx-zip" hidden data-bind-hidden="opt.value.media !== 'zip'">
|
|
@@ -94,7 +109,7 @@
|
|
|
94
109
|
</div>
|
|
95
110
|
</div>
|
|
96
111
|
</div>
|
|
97
|
-
<div class="wpx-option">
|
|
112
|
+
<div class="wpx-option" hidden data-bind-hidden="!fromWp.value">
|
|
98
113
|
<span class="form-label">Widgets
|
|
99
114
|
<span data-help-title="Widgets" data-help="A WordPress export has no widgets in it. To bring them across, install the free "Widget Importer & Exporter" plugin in WordPress, go to Tools › Widget Importer & Exporter, press Export Widgets and upload the .wie file it gives you here (or put it in the same zip as the export). Each widget area becomes a block named wp-…; a footer area's block is also added to the footer of every page."></span></span>
|
|
100
115
|
<div class="wpx-zip">
|
|
@@ -108,7 +123,7 @@
|
|
|
108
123
|
</div>
|
|
109
124
|
</div>
|
|
110
125
|
<div class="wpx-toggles">
|
|
111
|
-
<label class="wpx-toggle"><input type="checkbox" class="form-switch" data-model="optComments.value" data-bind-disabled="opt.value.posts !== 'blog'"> Approved comments
|
|
126
|
+
<label class="wpx-toggle" hidden data-bind-hidden="!fromWp.value"><input type="checkbox" class="form-switch" data-model="optComments.value" data-bind-disabled="opt.value.posts !== 'blog'"> Approved comments
|
|
112
127
|
<span data-help="Approved comments go to the Blog's comments, replies under the comment they answer. Spam, unapproved comments, pingbacks and trackbacks are never imported."></span></label>
|
|
113
128
|
<label class="wpx-toggle"><input type="checkbox" class="form-switch" data-model="optMenus.value"> Menus
|
|
114
129
|
<span data-help="Each WordPress menu becomes a menu here (wp-…), pointing at the new addresses. It is not put on the site until you choose it for the navbar or a footer in Menus › Locations."></span></label>
|
|
@@ -259,6 +274,9 @@
|
|
|
259
274
|
.wpx-bar { height: .5rem; border-radius: 999px; background: color-mix(in srgb, var(--dm-text) 10%, transparent); overflow: hidden; }
|
|
260
275
|
.wpx-bar-fill { display: block; height: 100%; width: 0; background: var(--dm-primary); transition: width .3s; }
|
|
261
276
|
.wpx-upload { display: flex; flex-direction: column; gap: .35rem; }
|
|
277
|
+
.wpx-crawl-row, .wpx-crawl-progress { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
|
|
278
|
+
.wpx-crawl-url { flex: 1 1 16rem; min-width: 0; }
|
|
279
|
+
.wpx-crawl-progress .wpx-note { flex: 1 1 16rem; margin: 0; }
|
|
262
280
|
.wpx-head { flex-direction: row; align-items: center; flex-wrap: wrap; }
|
|
263
281
|
.wpx-head-main { flex: 1 1 16rem; display: flex; flex-direction: column; min-width: 0; }
|
|
264
282
|
.wpx-site { font-size: var(--dm-text-lg); overflow-wrap: anywhere; }
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{api as
|
|
1
|
+
import{api as h,getUser as Y}from"../api.js";import{addBannerAction as ke}from"../lib/plugin-chrome.js";import{SHAPES as vt,whileLoading as wt}from"../lib/loading.js";import{helpPopovers as He}from"../lib/help-popover.js";import{onceClosed as xt,openMenuAt as Ve,sidebarCount as kt,viewLifetime as $t}from"../lib/tool-kit.js";import{pluginAccent as Ye}from"../lib/plugin-accent.js";import{reportRestart as Et}from"../lib/server-restart.js";import{FILTERS as St,arrangeCatalogue as Tt,arrangePlugins as Ct,catalogueAction as re,catalogueRow as Mt,checkScaffold as Nt,dependencyRows as It,formatPrice as ce,fmtReleased as Ot,needsAttention as At,planLines as Lt,pluginRow as Dt,pluginStatus as Je,readSettings as Ut,settingsFields as Qe,slugifyPlugin as Rt,storeBuyLines as Bt,updateFor as Ge}from"../lib/plugins-arrange.js";const Ze=/^#\/plugins\/?(\?.*)?$/,et=5e3,Ft=3e4,jt=20*6e4,Wt="#/plugins",$e="plugins.filter",de="plugins.draft",Pt=`
|
|
2
2
|
<div class="plx-row" data-name="{{name}}" tabindex="0" data-bind-class="rowCls" style="--plugin-accent: {{accent}}">
|
|
3
3
|
<span class="plx-icon" aria-hidden="true"><span data-icon="{{icon}}" data-icon-size="17"></span></span>
|
|
4
4
|
<span class="plx-main"><strong>{{displayName}}</strong><small data-bind-text="meta"></small></span>
|
|
@@ -10,7 +10,7 @@ import{api as v,getUser as tt}from"../api.js";import{addBannerAction as pe}from"
|
|
|
10
10
|
<span class="plx-chip" data-bind-class="statusCls" data-bind-text="statusText"></span>
|
|
11
11
|
</span>
|
|
12
12
|
<button type="button" class="plx-kebab" aria-label="Actions for {{displayName}}" title="Actions">\u22EE</button>
|
|
13
|
-
</div>`,
|
|
13
|
+
</div>`,qt=`
|
|
14
14
|
<div class="plx-row" data-tool="{{name}}" tabindex="0" data-bind-class="rowCls">
|
|
15
15
|
<span class="plx-icon" aria-hidden="true"><span data-icon="{{icon}}" data-icon-size="17"></span></span>
|
|
16
16
|
<span class="plx-main"><strong>{{displayName}}</strong><small data-bind-text="meta"></small></span>
|
|
@@ -19,7 +19,7 @@ import{api as v,getUser as tt}from"../api.js";import{addBannerAction as pe}from"
|
|
|
19
19
|
<span class="plx-chip" data-bind-class="statusCls" data-bind-text="statusText"></span>
|
|
20
20
|
</span>
|
|
21
21
|
<button type="button" class="plx-kebab" aria-label="Actions for {{displayName}}" title="Actions">\u22EE</button>
|
|
22
|
-
</div
|
|
22
|
+
</div>`,_t=`
|
|
23
23
|
<div class="plx-row" data-slug="{{slug}}" tabindex="0" data-bind-class="rowCls" style="--plugin-accent: {{accent}}">
|
|
24
24
|
<span class="plx-icon" aria-hidden="true"><span data-icon="{{icon}}" data-icon-size="17"></span></span>
|
|
25
25
|
<span class="plx-main"><strong>{{displayName}}</strong><small>{{meta}}</small></span>
|
|
@@ -29,12 +29,12 @@ import{api as v,getUser as tt}from"../api.js";import{addBannerAction as pe}from"
|
|
|
29
29
|
</span>
|
|
30
30
|
<button type="button" class="btn btn-sm plx-act" data-bind-class="actCls" data-bind-disabled="actDisabled" data-bind-text="actionText"></button>
|
|
31
31
|
<button type="button" class="plx-kebab" aria-label="Actions for {{displayName}}" title="Actions">\u22EE</button>
|
|
32
|
-
</div>`,
|
|
32
|
+
</div>`,Kt=`
|
|
33
33
|
<li class="plx-dep">
|
|
34
34
|
<strong data-bind-text="displayName"></strong>
|
|
35
35
|
<span class="plx-chip" data-bind-class="stateCls" data-bind-text="stateText"></span>
|
|
36
36
|
<small class="plx-hint" data-bind-hidden="!reason" data-bind-text="reason"></small>
|
|
37
|
-
</li>`,d=T=>String(T??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""");function me(T){const m=document.createElement("template");return m.innerHTML=T.trim(),m.content.firstElementChild}const g=it(We);export const pluginsView={templateUrl:"/admin/js/templates/plugins.html",async onMount(T){g.reset();const m=T.get(0).querySelector(".plx")||T.get(0),k=()=>We.test(location.hash)&&m.isConnected,L=M.observable([]),R=M.observable([]),he=M.computed(()=>R.value.map(e=>{const t=[...(e.requiredBy||[]).map(a=>a.displayName),...(e.usedBy||[]).map(a=>a.displayName)];return{name:e.name,displayName:e.displayName,icon:e.icon,meta:[e.description,t.length?`used by ${t.join(", ")}`:"",e.locked?"locked by your manager":"",e.staff?"your host's staff can still use it":""].filter(Boolean).join(" \xB7 "),locked:e.locked===!0,statusText:e.enabled?"On":"Off",statusCls:e.enabled?"is-ok":"is-muted",rowCls:e.enabled?"":"is-off"}})),h=M.observable({available:null,site:null,items:[]}),fe=M.observable(!0),ne=M.observable(""),b=M.observable("");let ve="all";try{ve=rt.includes(S.get(be))?S.get(be):"all"}catch{}const N=M.observable(ve),V=M.observable(""),j=M.observable("all"),ge=M.observable("");g.add(M.effect(()=>{const e=N.value;try{S.set(be,e)}catch{}}));const Y=M.computed(()=>new Map((h.value.items||[]).map(e=>[e.slug,e.version]))),W=e=>(h.peek().items||[]).find(t=>t.slug===e),se=M.observable([]);g.add(M.effect(()=>{const e=Y.value;se.value=ct(L.value,{filter:N.value,query:V.value,latest:e}).map(t=>({...vt(t,e),accent:je(t.name)}))}));const Pe=M.computed(()=>{const e=L.value,t=Y.value,a=e.filter(n=>De(n).running).length;return{all:e.length,on:a,off:e.length-a,attention:e.filter(n=>ht(n,t)).length}}),J=M.computed(()=>(h.value.items||[]).filter(e=>te(e)==="update").length),ze=M.computed(()=>L.value.length?"No plugins match.":"No plugins installed. Browse the catalogue, or Install from file in the banner."),le=M.observable([]);g.add(M.effect(()=>{le.value=dt(h.value.items,{filter:j.value,query:ge.value}).map(e=>{const t=ut(e),a=t.action==="update"||t.action==="install"||t.action==="buy";return{...t,accent:je(e.slug),actCls:a?"btn-primary":"btn-ghost",actDisabled:!a}})}));const _e=M.computed(()=>{const e=h.value.items||[];return{all:e.length,installed:e.filter(t=>t.installed).length,available:e.filter(t=>te(t)==="install").length,updates:J.value}}),Q=e=>L.peek().find(t=>t.name===e);async function ie(){try{const[e,t]=await nt(m.querySelector(".dm-loading-slot"),Promise.all([v.plugins.list(),v.tools.list().catch(()=>[])]),at.iconRows);if(!k())return;L.value=Array.isArray(e)?e:[],R.value=Array.isArray(t)?t:[],ne.value=""}catch(e){ne.value=`Could not load the plugins: ${e.message||e}`}finally{fe.value=!1}}async function ye(){try{const e=await v.marketplace.catalogue();if(!k())return;h.value={available:!!e?.available,site:e?.site||null,items:e?.catalogue||[]}}catch{h.value={available:!1,site:null,items:[],failed:!0}}}const P=async()=>{await Promise.all([ie(),ye()]),lt(wt)};async function B(e,t,a="plugin"){if(e.core)return;const n=t?"on":"off";if(e.locked){E.toast(`${e.displayName||e.name} is locked by your site's manager - ask them to switch it ${n}.`,{type:"info",duration:6e3});return}if(!await E.confirm(`Switch ${d(e.displayName||e.name)} ${n}? The server restarts to apply it, which takes a few seconds.`)||b.peek())return;const l=i=>a==="tool"?v.tools.update(e.name,{enabled:t,cascade:i}):v.plugins.update(e.name,{enabled:t,cascade:i});b.value=`Switching ${e.displayName||e.name} ${n}\u2026`;try{let i;try{i=await l(!1)}catch(c){if(c.status!==409||!c.body?.needsConfirm)throw c;const u=ft(c.body.plan);if(b.value="",!await E.confirm(`<p>Switching ${d(e.displayName||e.name)} ${n} also means:</p><ul>${u.map(o=>`<li>${d(o)}</li>`).join("")}</ul><p>Go ahead?</p>`))return;b.value=`Switching ${e.displayName||e.name} ${n}\u2026`,i=await l(!0)}await ot(i,{onStatus:c=>{b.value=c}}),E.toast(`${e.displayName||e.name} is ${n}.${t?" Reload the admin to open its screens.":""}`,{type:"success",duration:6e3});try{document.dispatchEvent(new CustomEvent("dm:sidebar-rebuild"))}catch{}}catch(i){E.toast(`Not switched ${n}: ${i.message||i}`,{type:"error"})}finally{b.value="",k()&&await P()}}async function D(e,{update:t=!1}={}){const a=d(e.displayName||e.slug),n=t?`<p>Update ${a} from ${d(e.installedVersion)} to ${d(e.version)}?</p> <p class="text-muted">The plugin keeps its data, and the current version is put back if the update fails.</p>`:`<p>Install ${a} v${d(e.version)}?</p> <p class="text-muted">It arrives licensed to this site and takes effect after a restart.</p>`;if(await E.confirm(n,{title:t?"Update plugin":"Install plugin",confirmText:t?"Update":"Install",cancelText:"Cancel",html:!0})){try{const l=await v.marketplace.install(e.slug,e.version,{update:t}),i=l?.action==="upgrade"?`${e.slug} updated${l.from?` from ${l.from}`:""} to ${l.version}.`:`${e.slug} ${l?.version??e.version} installed.`;E.toast(`${i} Restart the server to activate it.`,{type:"success",duration:6e3})}catch(l){E.toast(l.message||"Install failed.",{type:"error"})}k()&&await P()}}function we(e){e?.buyUrl&&(window.open(e.buyUrl,"_blank","noopener"),E.toast(`Manage my site opened in a new tab. We email you a sign-in link; ${e.displayName||e.slug} is ticked ready once you are in. Install it here when it is paid for.`,{type:"info",duration:9e3}))}async function xe(e,t){const n=W(e)?.tier==="paid"?` <p class="text-muted">It is a paid Tool: your site's manager is told, and if you pay for it on its own it comes off your monthly bill (the rest of this month is credited).</p>`:"";if(await E.confirm(`<p>Uninstall ${d(t||e)}?</p> <p class="text-muted">Its files are removed, and its <code>data/</code> folder with them. Roles it added are removed and their users moved to <code>user</code>. Restart the server to finish.</p>${n}`,{title:"Uninstall plugin",confirmText:"Uninstall",cancelText:"Cancel",html:!0})){try{const i=(await v.marketplace.uninstall(e))?.release?.removed?" It is off your bill.":"";E.toast(`${t||e} uninstalled.${i} Restart the server to apply.`,{type:"success",duration:6e3})}catch(l){E.toast(`Uninstall failed: ${l.message||l}`,{type:"error"})}k()&&await P()}}async function ke(e){try{await v.plugins.exportBundle(e.name)}catch(t){E.toast(t.message||"Export failed.",{type:"error"})}}const $e=e=>{location.hash=`#/plugins/code/${encodeURIComponent(e.name)}`},z=m.querySelector(".plx-file");async function He(e){if(b.peek())return;b.value=`Installing ${e.name}\u2026`;const t={};try{for(let a=0;a<4;a++)try{const n=await v.plugins.installFile(e,t),l=n.action==="upgrade"?`${n.name} updated${n.from?` from ${n.from}`:""} to ${n.version}.`:`${n.name} ${n.version} installed.`;E.toast(`${l} Restart the server to activate it.`,{type:"success",duration:6e3});return}catch(n){if(b.value="",n.code==="CONFLICT"&&!t.confirmUpgrade){if(!await E.confirm(`<p>${d(n.name)} ${d(n.installedVersion||"the installed version")} is already installed. Update it to ${d(n.incomingVersion||"this file")}?</p> <p class="text-muted">The plugin keeps its data, and the current version is put back if the update fails.</p>`,{title:"Update plugin",confirmText:"Update",cancelText:"Cancel",html:!0}))return;t.confirmUpgrade=!0}else if(/refusing to downgrade/i.test(n.message)&&!t.confirmDowngrade){if(!await E.confirm(`<p>${d(n.message)} Install it anyway?</p> <p class="text-muted">An older version may not understand data written by the newer one.</p>`,{title:"Downgrade plugin",confirmText:"Downgrade",cancelText:"Cancel",html:!0}))return;t.confirmDowngrade=!0}else if(/unsigned|signature/i.test(n.message)&&!t.confirmUnsigned){if(!await E.confirm(`<p>${d(n.message)}</p> <p class="text-muted">An unsigned plugin has not been verified as coming from the marketplace. Its code runs on this server with full access. Install it anyway?</p>`,{title:"Unsigned plugin",confirmText:"Install anyway",cancelText:"Cancel",html:!0}))return;t.confirmUnsigned=!0}else{E.toast(n.message||"Install failed.",{type:"error"});return}b.value=`Installing ${e.name}\u2026`}}finally{b.value="",k()&&await P()}}const Ee=async()=>{const e=z.files?.[0];z.value="",e&&await He(e)};z.addEventListener("change",Ee),g.add(()=>z.removeEventListener("change",Ee));const G=new Set;let U=null,Se=!1;function Me({title:e,size:t="md",panel:a,model:n,methods:l,dirty:i=()=>!1,form:c=null,cleanup:u=()=>{}}){const o=E.slideover({title:d(e),size:t,position:"right"});o.element.appendChild(a);const $=Ue(a),w=M.applyBindings(n,a,{methods:l});c&&(U=c),G.add(o),st(o,()=>{u(),w.dispose(),$(),G.delete(o),U===c&&(U=null)});const x=o.close.bind(o);let f=!1,O=!1;return o.close=async F=>{if(!f&&F!==!0&&i()){if(O)return;O=!0;const q=await E.confirm("Discard the changes you have not saved?");if(O=!1,!q)return}return f=!0,x()},I.scan(a),o.open(),o}function oe(e,t=null){const a=Q(e);if(!a)return;const n=De(a),l=Fe(a),i=W(a.name),c=qe(a,Y.peek()),u=!!(c&&i?.entitled&&!i?.needsCms),$={...Object.fromEntries(l.map(s=>[s.key,s.value])),...Object.fromEntries(Object.entries(t||{}).filter(([s])=>!l.find(p=>p.key===s)?.secret))},w=Object.fromEntries(l.map(s=>[s.key,M.observable($[s.key])])),x=M.computed(()=>gt(l,Object.fromEntries(l.map(s=>[s.key,w[s.key].value])))),f=M.observable(!1),O=()=>Object.keys(x.peek().changed).length>0||Object.keys(x.peek().errors).length>0,F=[["Version",`v${a.version}${c?` (v${c} available)`:""}`],["Status",n.text+(a.supersededBy?` - replaced by ${a.supersededBy}`:"")],["Author",a.author],["Released",mt(a.date)],["Licence",a.licence],["Slug",a.name]].filter(([,s])=>s),q=(s,p)=>{const A=`plx-set-${p}`,Z=s.help?` <span data-help="${d(s.help)}"></span>`:"",H=`<label class="form-label" for="${A}">${d(s.label)}${Z}</label>`,K=`data-model="v${p}.value"`,ee=`<small class="plx-err" data-bind-hidden="!err${p}.value" data-bind-text="err${p}.value"></small>`;if(s.type==="checkbox")return`<div class="plx-setting">${H}<input id="${A}" type="checkbox" class="form-switch" ${K}></div>`;if(s.type==="select")return`<div>${H}<select id="${A}" class="form-input" ${K}>${s.options.map(Le=>`<option value="${d(Le.value)}">${d(Le.label)}</option>`).join("")}</select>${ee}</div>`;if(s.type==="json")return`<div>${H}<textarea id="${A}" class="form-input plx-json" rows="5" spellcheck="false" ${K}></textarea>${ee}</div>`;if(s.type==="textarea")return`<div>${H}<textarea id="${A}" class="form-input" rows="3" ${K}></textarea>${ee}</div>`;const Ze=s.type==="number"?"number":s.secret?"password":"text",et=`${s.min!=null?` min="${d(s.min)}"`:""}${s.max!=null?` max="${d(s.max)}"`:""}`;return`<div>${H}<input id="${A}" type="${Ze}" class="form-input" autocomplete="${s.secret?"new-password":"off"}"${et} ${K}>${ee}</div>`},r=bt(a,{plugins:L.peek(),tools:R.peek(),catalogue:h.peek().items||[]}),C={saving:f,needs:M.observable(r.needs),worksWith:M.observable(r.worksWith),hasNeeds:r.needs.length>0,hasWorksWith:r.worksWith.length>0,hasFields:l.length>0,cannot:M.computed(()=>f.value||!Object.keys(x.value.changed).length||Object.keys(x.value.errors).length>0),...Object.fromEntries(l.flatMap((s,p)=>[[`v${p}`,w[s.key]],[`err${p}`,M.computed(()=>x.value.errors[s.key]||"")]]))},_=me(`
|
|
37
|
+
</li>`,i=O=>String(O??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""");function Ee(O){const g=document.createElement("template");return g.innerHTML=O.trim(),g.content.firstElementChild}const y=$t(Ze);export const pluginsView={templateUrl:"/admin/js/templates/plugins.html",async onMount(O){y.reset();const g=O.get(0).querySelector(".plx")||O.get(0),p=()=>Ze.test(location.hash)&&g.isConnected,R=M.observable([]),j=M.observable([]),Se=M.computed(()=>j.value.map(e=>{const t=[...(e.requiredBy||[]).map(a=>a.displayName),...(e.usedBy||[]).map(a=>a.displayName)];return{name:e.name,displayName:e.displayName,icon:e.icon,meta:[e.description,t.length?`used by ${t.join(", ")}`:"",e.locked?"locked by your manager":"",e.staff?"your host's staff can still use it":""].filter(Boolean).join(" \xB7 "),locked:e.locked===!0,statusText:e.enabled?"On":"Off",statusCls:e.enabled?"is-ok":"is-muted",rowCls:e.enabled?"":"is-off"}})),u=M.observable({available:null,site:null,items:[]}),Te=M.observable(!0),ue=M.observable(""),f=M.observable("");let Ce="all";try{Ce=St.includes(S.get($e))?S.get($e):"all"}catch{}const A=M.observable(Ce),J=M.observable(""),W=M.observable("all"),Me=M.observable("");y.add(M.effect(()=>{const e=A.value;try{S.set($e,e)}catch{}}));const Q=M.computed(()=>new Map((u.value.items||[]).map(e=>[e.slug,e.version]))),L=e=>(u.peek().items||[]).find(t=>t.slug===e),pe=M.observable([]);y.add(M.effect(()=>{const e=Q.value;pe.value=Ct(R.value,{filter:A.value,query:J.value,latest:e}).map(t=>({...Dt(t,e),accent:Ye(t.name)}))}));const tt=M.computed(()=>{const e=R.value,t=Q.value,a=e.filter(n=>Je(n).running).length;return{all:e.length,on:a,off:e.length-a,attention:e.filter(n=>At(n,t)).length}}),G=M.computed(()=>(u.value.items||[]).filter(e=>re(e)==="update").length),at=M.computed(()=>R.value.length?"No plugins match.":"No plugins installed. Browse the catalogue, or Install from file in the banner."),me=M.observable([]);y.add(M.effect(()=>{me.value=Tt(u.value.items,{filter:W.value,query:Me.value}).map(e=>{const t=Mt(e),a=t.action==="update"||t.action==="install"||t.action==="buy";return{...t,accent:Ye(e.slug),actCls:a?"btn-primary":"btn-ghost",actDisabled:!a}})}));const nt=M.computed(()=>{const e=u.value.items||[];return{all:e.length,installed:e.filter(t=>t.installed).length,available:e.filter(t=>re(t)==="install").length,updates:G.value}}),Z=e=>R.peek().find(t=>t.name===e);async function he(){try{const[e,t]=await wt(g.querySelector(".dm-loading-slot"),Promise.all([h.plugins.list(),h.tools.list().catch(()=>[])]),vt.iconRows);if(!p())return;R.value=Array.isArray(e)?e:[],j.value=Array.isArray(t)?t:[],ue.value=""}catch(e){ue.value=`Could not load the plugins: ${e.message||e}`}finally{Te.value=!1}}async function Ne(){try{const e=await h.marketplace.catalogue();if(!p())return;u.value={available:!!e?.available,site:e?.site||null,items:e?.catalogue||[],mode:e?.mode||(e?.available?"managed":"none"),siteError:e?.siteError||"",storeFailed:e?.failed||"",connection:e?.connection||null},e?.connection?.status==="pending"&&be();for(const t of e?.pending||[])Ie(t.id,{fast:!1})}catch{u.value={available:!1,site:null,items:[],failed:!0}}}const v=async()=>{await Promise.all([he(),Ne()]),kt(Wt)};async function P(e,t,a="plugin"){if(e.core)return;const n=t?"on":"off";if(e.locked){E.toast(`${e.displayName||e.name} is locked by your site's manager - ask them to switch it ${n}.`,{type:"info",duration:6e3});return}if(!await E.confirm(`Switch ${i(e.displayName||e.name)} ${n}? The server restarts to apply it, which takes a few seconds.`)||f.peek())return;const s=o=>a==="tool"?h.tools.update(e.name,{enabled:t,cascade:o}):h.plugins.update(e.name,{enabled:t,cascade:o});f.value=`Switching ${e.displayName||e.name} ${n}\u2026`;try{let o;try{o=await s(!1)}catch(d){if(d.status!==409||!d.body?.needsConfirm)throw d;const m=Lt(d.body.plan);if(f.value="",!await E.confirm(`<p>Switching ${i(e.displayName||e.name)} ${n} also means:</p><ul>${m.map(r=>`<li>${i(r)}</li>`).join("")}</ul><p>Go ahead?</p>`))return;f.value=`Switching ${e.displayName||e.name} ${n}\u2026`,o=await s(!0)}await Et(o,{onStatus:d=>{f.value=d}}),E.toast(`${e.displayName||e.name} is ${n}.${t?" Reload the admin to open its screens.":""}`,{type:"success",duration:6e3});try{document.dispatchEvent(new CustomEvent("dm:sidebar-rebuild"))}catch{}}catch(o){E.toast(`Not switched ${n}: ${o.message||o}`,{type:"error"})}finally{f.value="",p()&&await v()}}async function F(e,{update:t=!1}={}){const a=i(e.displayName||e.slug),n=t?`<p>Update ${a} from ${i(e.installedVersion)} to ${i(e.version)}?</p> <p class="text-muted">The plugin keeps its data, and the current version is put back if the update fails.</p>`:`<p>Install ${a} v${i(e.version)}?</p> <p class="text-muted">It arrives licensed to this site and takes effect after a restart.</p>`;if(await E.confirm(n,{title:t?"Update plugin":"Install plugin",confirmText:t?"Update":"Install",cancelText:"Cancel",html:!0})){try{const s=await h.marketplace.install(e.slug,e.version,{update:t}),o=s?.action==="upgrade"?`${e.slug} updated${s.from?` from ${s.from}`:""} to ${s.version}.`:`${e.slug} ${s?.version??e.version} installed.`;E.toast(`${o} Restart the server to activate it.`,{type:"success",duration:6e3})}catch(s){E.toast(s.message||"Install failed.",{type:"error"})}p()&&await v()}}const x=new Map;y.add(()=>{for(const e of x.values())clearTimeout(e.timer);x.clear()});function Ie(e,{fast:t=!0}={}){if(!e||x.has(e))return;const a={timer:null,until:Date.now()+(t?jt:0)};x.set(e,a);const n=()=>{clearTimeout(a.timer),!(!p()||!x.has(e))&&(a.timer=setTimeout(()=>te(e),Date.now()<a.until?et:Ft))};a.next=n,n()}const Oe=e=>{const t=x.get(e);t&&clearTimeout(t.timer),x.delete(e)},ee=new Set;async function te(e,{byHand:t=!1}={}){if(!p()||ee.has(e))return;ee.add(e),clearTimeout(x.get(e)?.timer);let a;try{a=await h.marketplace.claim(e)}catch(s){t&&E.toast(s.message||"The store could not be asked just now.",{type:"error"}),ee.delete(e),x.get(e)?.next?.();return}ee.delete(e);const n=L(a.slug)?.displayName||a.slug;if(a.status==="pending"){t&&E.toast(`Not paid yet - ${n} installs here as soon as the payment is through.`,{type:"info",duration:6e3}),x.get(e)?.next?.();return}if(Oe(e),a.status==="paid")if(a.kind==="renew")E.toast(`${n}: updates renewed.${a.installed&&!a.refreshed?" Update it on the Browse tab.":""}`,{type:"success",duration:8e3});else if(a.installed&&a.refreshed===!1&&a.installError)E.toast(`${n} is paid for, but the copy here could not be brought up to date: ${a.installError}. Use Update on the Browse tab.`,{type:"warning",duration:12e3});else if(a.installed){const s=(a.included||[]).filter(o=>o.installed).map(o=>L(o.slug)?.displayName||o.slug);E.toast(`${n} is paid for and installed${s.length?`, with ${s.join(" and ")} free`:""}. Restart the server to activate ${s.length?"them":"it"}.`+(s.some(o=>/mongo/i.test(o))?" Then open MongoDB in the sidebar to connect your database.":""),{type:"success",duration:12e3})}else E.toast(`${n} is paid for, but did not install: ${a.installError||"try Install on the Browse tab"}. The licence key is in your email.`,{type:"warning",duration:12e3});else a.status!=="unknown"&&E.toast(`${n}: the purchase ${a.status==="expired"?"was not paid for in time":`is ${a.status}`}.`,{type:"warning",duration:8e3});p()&&await v()}async function st(e){if(e?.pending&&await E.confirm(`<p>Stop waiting for the payment for ${i(e.displayName||e.slug)}?</p> <p class="text-muted">Nothing is cancelled at the store - if you did pay, the licence key is in your email and Install from file takes the file it links to.</p>`,{title:"Stop waiting",confirmText:"Stop waiting",cancelText:"Keep waiting",html:!0})){Oe(e.pending);try{await h.marketplace.dropPurchase(e.pending)}catch(t){E.toast(t.message||"Could not do that.",{type:"error"})}p()&&await v()}}async function lt(e){const t=await E.prompt(`Licence key for ${i(e.displayName||e.slug)} - it is in the email you had when you bought it.`,{title:"Enter licence key",inputPlaceholder:"DOMMA-XXXX-XXXX-XXXX",confirmText:"Use this key"});if(!(!t||!p()))try{const a=await h.marketplace.enterKey(e.slug,String(t).trim());await v();const n=L(e.slug);a.updates&&n&&!n.installed?(E.toast(`Licence accepted for ${e.displayName||e.slug}.`,{type:"success"}),await F(n)):E.toast(`Licence accepted for ${e.displayName||e.slug}.${n?.installed?" Restart the server for it to take effect.":""}`,{type:"success",duration:7e3})}catch(a){E.toast(a.message||"That key could not be used.",{type:"error",duration:8e3})}}async function ot(e){if(f.peek())return;const t=Bt(e,{site:u.peek().site,email:Y()?.email}),a=t.lines.map((s,o)=>`<p${o?' class="text-muted"':""}>${i(s)}</p>`).join(" ");if(!await E.confirm(a,{title:t.title,confirmText:e.owned?"Renew":"Buy",cancelText:"Cancel",html:!0}))return;const n=window.open("","_blank");try{const s=await h.marketplace.buy(e.slug);n&&!n.closed?(n.opener=null,n.location.href=s.checkoutUrl):window.open(s.checkoutUrl,"_blank","noopener")||E.toast("Your browser blocked the payment tab - allow pop-ups for this site and choose Buy again.",{type:"warning",duration:9e3}),Ie(s.id),E.toast(`Payment opened in a new tab. ${e.displayName||e.slug} ${e.owned?"renews":"installs here"} as soon as it is through - keep this page open, or come back to it.`,{type:"info",duration:9e3})}catch(s){try{n?.close()}catch{}E.toast(s.message||"The purchase could not be started.",{type:"error",duration:8e3})}p()&&await v()}let ae=null,q=0;y.add(()=>clearTimeout(ae));function be(){q||(q=Date.now()+60*6e4),clearTimeout(ae),!(!p()||Date.now()>q)&&(ae=setTimeout(()=>fe(!1),et))}let ne=!1;async function fe(e){if(ne||!p())return;ne=!0;let t;try{t=await h.marketplace.connectCheck()}catch(n){e&&E.toast(n.message||"Could not ask just now.",{type:"error"}),ne=!1,be();return}ne=!1;const a=t?.connection||null;if(a?.status==="pending"){e&&E.toast(`Not yet - open the link we emailed to ${a.email} and choose Connect.`,{type:"info",duration:6e3}),be();return}q=0,a?.status==="connected"?E.toast(`Connected to Domma as ${a.email}.`,{type:"success",duration:7e3}):E.toast("The link was not opened in time - choose Connect to Domma again.",{type:"warning",duration:7e3}),p()&&await v()}async function it(){const e=await E.prompt("The email address you bought your Tools with. We email it a link; open it and choose Connect.",{title:"Connect to Domma",inputPlaceholder:Y()?.email||"you@example.com",defaultValue:Y()?.email||"",confirmText:"Email me the link"});if(!(e==null||!p()))try{const t=await h.marketplace.connect(String(e).trim()||Y()?.email||"");E.toast(`Link emailed to ${t.connection?.email}. Open it and choose Connect - this page picks it up.`,{type:"info",duration:9e3}),q=0,await v()}catch(t){E.toast(t.message||"Could not connect.",{type:"error",duration:8e3})}}async function rt(){const e=u.peek().connection;if(e&&!(e.status!=="pending"&&!await E.confirm(`<p>Disconnect this site from Domma (${i(e.email)})?</p> <p class="text-muted">The licences it already has stay. New ones stop arriving by themselves - connect again, or enter a key.</p>`,{title:"Disconnect",confirmText:"Disconnect",cancelText:"Keep it",html:!0}))){clearTimeout(ae),q=0;try{await h.marketplace.disconnect()}catch(t){E.toast(t.message||"Could not do that.",{type:"error"})}p()&&await v()}}const Ae=()=>{for(const e of[...x.keys()])te(e);u.peek().connection?.status==="pending"&&fe(!1)};window.addEventListener("focus",Ae),y.add(()=>window.removeEventListener("focus",Ae));function Le(e){if(e?.store){ot(e);return}e?.buyUrl&&(window.open(e.buyUrl,"_blank","noopener"),E.toast(`Manage my site opened in a new tab. We email you a sign-in link; ${e.displayName||e.slug} is ticked ready once you are in. Install it here when it is paid for.`,{type:"info",duration:9e3}))}async function De(e,t){const n=L(e)?.tier==="paid"&&!L(e)?.store?` <p class="text-muted">It is a paid Tool: your site's manager is told, and if you pay for it on its own it comes off your monthly bill (the rest of this month is credited).</p>`:"";if(await E.confirm(`<p>Uninstall ${i(t||e)}?</p> <p class="text-muted">Its files are removed, and its <code>data/</code> folder with them. Roles it added are removed and their users moved to <code>user</code>. Restart the server to finish.</p>${n}`,{title:"Uninstall plugin",confirmText:"Uninstall",cancelText:"Cancel",html:!0})){try{const o=(await h.marketplace.uninstall(e))?.release?.removed?" It is off your bill.":"";E.toast(`${t||e} uninstalled.${o} Restart the server to apply.`,{type:"success",duration:6e3})}catch(s){E.toast(`Uninstall failed: ${s.message||s}`,{type:"error"})}p()&&await v()}}async function Ue(e){try{await h.plugins.exportBundle(e.name)}catch(t){E.toast(t.message||"Export failed.",{type:"error"})}}const Re=e=>{location.hash=`#/plugins/code/${encodeURIComponent(e.name)}`},X=g.querySelector(".plx-file");async function ct(e){if(f.peek())return;f.value=`Installing ${e.name}\u2026`;const t={};try{for(let a=0;a<4;a++)try{const n=await h.plugins.installFile(e,t),s=n.action==="upgrade"?`${n.name} updated${n.from?` from ${n.from}`:""} to ${n.version}.`:`${n.name} ${n.version} installed.`;E.toast(`${s} Restart the server to activate it.`,{type:"success",duration:6e3});return}catch(n){if(f.value="",n.code==="CONFLICT"&&!t.confirmUpgrade){if(!await E.confirm(`<p>${i(n.name)} ${i(n.installedVersion||"the installed version")} is already installed. Update it to ${i(n.incomingVersion||"this file")}?</p> <p class="text-muted">The plugin keeps its data, and the current version is put back if the update fails.</p>`,{title:"Update plugin",confirmText:"Update",cancelText:"Cancel",html:!0}))return;t.confirmUpgrade=!0}else if(/refusing to downgrade/i.test(n.message)&&!t.confirmDowngrade){if(!await E.confirm(`<p>${i(n.message)} Install it anyway?</p> <p class="text-muted">An older version may not understand data written by the newer one.</p>`,{title:"Downgrade plugin",confirmText:"Downgrade",cancelText:"Cancel",html:!0}))return;t.confirmDowngrade=!0}else if(/unsigned|signature/i.test(n.message)&&!t.confirmUnsigned){if(!await E.confirm(`<p>${i(n.message)}</p> <p class="text-muted">An unsigned plugin has not been verified as coming from the marketplace. Its code runs on this server with full access. Install it anyway?</p>`,{title:"Unsigned plugin",confirmText:"Install anyway",cancelText:"Cancel",html:!0}))return;t.confirmUnsigned=!0}else{E.toast(n.message||"Install failed.",{type:"error"});return}f.value=`Installing ${e.name}\u2026`}}finally{f.value="",p()&&await v()}}const Be=async()=>{const e=X.files?.[0];X.value="",e&&await ct(e)};X.addEventListener("change",Be),y.add(()=>X.removeEventListener("change",Be));const se=new Set;let B=null,Fe=!1;function je({title:e,size:t="md",panel:a,model:n,methods:s,dirty:o=()=>!1,form:d=null,cleanup:m=()=>{}}){const r=E.slideover({title:i(e),size:t,position:"right"});r.element.appendChild(a);const C=He(a),$=M.applyBindings(n,a,{methods:s});d&&(B=d),se.add(r),xt(r,()=>{m(),$.dispose(),C(),se.delete(r),B===d&&(B=null)});const T=r.close.bind(r);let w=!1,D=!1;return r.close=async _=>{if(!w&&_!==!0&&o()){if(D)return;D=!0;const K=await E.confirm("Discard the changes you have not saved?");if(D=!1,!K)return}return w=!0,T()},I.scan(a),r.open(),r}function ge(e,t=null){const a=Z(e);if(!a)return;const n=Je(a),s=Qe(a),o=L(a.name),d=Ge(a,Q.peek()),m=!!(d&&o?.entitled&&!o?.needsCms),C={...Object.fromEntries(s.map(l=>[l.key,l.value])),...Object.fromEntries(Object.entries(t||{}).filter(([l])=>!s.find(b=>b.key===l)?.secret))},$=Object.fromEntries(s.map(l=>[l.key,M.observable(C[l.key])])),T=M.computed(()=>Ut(s,Object.fromEntries(s.map(l=>[l.key,$[l.key].value])))),w=M.observable(!1),D=()=>Object.keys(T.peek().changed).length>0||Object.keys(T.peek().errors).length>0,_=[["Version",`v${a.version}${d?` (v${d} available)`:""}`],["Status",n.text+(a.supersededBy?` - replaced by ${a.supersededBy}`:"")],["Author",a.author],["Released",Ot(a.date)],["Licence",a.licence],["Slug",a.name]].filter(([,l])=>l),K=(l,b)=>{const U=`plx-set-${b}`,oe=l.help?` <span data-help="${i(l.help)}"></span>`:"",H=`<label class="form-label" for="${U}">${i(l.label)}${oe}</label>`,V=`data-model="v${b}.value"`,ie=`<small class="plx-err" data-bind-hidden="!err${b}.value" data-bind-text="err${b}.value"></small>`;if(l.type==="checkbox")return`<div class="plx-setting">${H}<input id="${U}" type="checkbox" class="form-switch" ${V}></div>`;if(l.type==="select")return`<div>${H}<select id="${U}" class="form-input" ${V}>${l.options.map(ze=>`<option value="${i(ze.value)}">${i(ze.label)}</option>`).join("")}</select>${ie}</div>`;if(l.type==="json")return`<div>${H}<textarea id="${U}" class="form-input plx-json" rows="5" spellcheck="false" ${V}></textarea>${ie}</div>`;if(l.type==="textarea")return`<div>${H}<textarea id="${U}" class="form-input" rows="3" ${V}></textarea>${ie}</div>`;const gt=l.type==="number"?"number":l.secret?"password":"text",yt=`${l.min!=null?` min="${i(l.min)}"`:""}${l.max!=null?` max="${i(l.max)}"`:""}`;return`<div>${H}<input id="${U}" type="${gt}" class="form-input" autocomplete="${l.secret?"new-password":"off"}"${yt} ${V}>${ie}</div>`},c=It(a,{plugins:R.peek(),tools:j.peek(),catalogue:u.peek().items||[]}),N={saving:w,needs:M.observable(c.needs),worksWith:M.observable(c.worksWith),hasNeeds:c.needs.length>0,hasWorksWith:c.worksWith.length>0,hasFields:s.length>0,cannot:M.computed(()=>w.value||!Object.keys(T.value.changed).length||Object.keys(T.value.errors).length>0),...Object.fromEntries(s.flatMap((l,b)=>[[`v${b}`,$[l.key]],[`err${b}`,M.computed(()=>T.value.errors[l.key]||"")]]))},z=Ee(`
|
|
38
38
|
<div class="plx-form">
|
|
39
39
|
<p class="plx-desc"></p>
|
|
40
40
|
<dl class="plx-facts"></dl>
|
|
@@ -51,13 +51,13 @@ import{api as v,getUser as tt}from"../api.js";import{addBannerAction as pe}from"
|
|
|
51
51
|
<div data-if="hasFields">
|
|
52
52
|
<p class="plx-sub">Settings
|
|
53
53
|
<span data-help-title="Settings" data-help="Saved to config/plugins.json for this site. Only what you change is stored - anything you leave keeps the plugin's own default, so a later version can improve it. Most plugins read their settings as they run; a few only at start-up."></span></p>
|
|
54
|
-
<div class="plx-form">${
|
|
54
|
+
<div class="plx-form">${s.map(K).join("")}</div>
|
|
55
55
|
</div>
|
|
56
56
|
<p class="plx-hint" data-if="!hasFields">This plugin has no settings to change here.</p>
|
|
57
57
|
<div class="plx-actions">
|
|
58
58
|
${a.core?"":`<button type="button" class="btn btn-sm btn-ghost" data-on-click="toggle"><span data-icon="${a.enabled?"pause":"play"}" data-icon-size="13"></span> ${a.enabled?"Switch off":"Switch on"}</button>`}
|
|
59
|
-
${
|
|
60
|
-
${
|
|
59
|
+
${m?`<button type="button" class="btn btn-sm btn-ghost" data-on-click="update"><span data-icon="download" data-icon-size="13"></span> Update to v${i(d)}</button>`:""}
|
|
60
|
+
${d&&o?.needsCms?`<span class="plx-hint">v${i(d)}: ${i(o.needsCms)}</span>`:""}
|
|
61
61
|
${a.sourceEditable!==!1?'<button type="button" class="btn btn-sm btn-ghost" data-on-click="source"><span data-icon="code" data-icon-size="13"></span> Source</button>':""}
|
|
62
62
|
${a.closedSource?"":'<button type="button" class="btn btn-sm btn-ghost" data-on-click="exportIt" title="Download as a .dcmsplugin file"><span data-icon="download" data-icon-size="13"></span> Export</button>'}
|
|
63
63
|
<span class="plx-spacer"></span>
|
|
@@ -65,7 +65,7 @@ import{api as v,getUser as tt}from"../api.js";import{addBannerAction as pe}from"
|
|
|
65
65
|
<button type="button" class="btn btn-sm btn-primary" data-on-click="save" data-if="hasFields" data-bind-disabled="cannot.value">
|
|
66
66
|
<span data-icon="check" data-icon-size="13"></span> Save settings</button>
|
|
67
67
|
</div>
|
|
68
|
-
</div>`);
|
|
68
|
+
</div>`);z.querySelector(".plx-desc").textContent=a.description||"",z.querySelectorAll(".plx-deps").forEach(l=>{l.innerHTML=Kt});const ft=z.querySelector(".plx-facts");for(const[l,b]of _){const U=document.createElement("dt");U.textContent=l;const oe=document.createElement("dd");oe.textContent=b,ft.append(U,oe)}async function Xe(){if(N.cannot.peek())return;const{changed:l}=T.peek();w.value=!0;try{await h.plugins.update(a.name,{settings:{...a.settings||{},...l}}),E.toast(`${a.displayName||a.name}: settings saved.`,{type:"success"}),le.close(!0),p()&&await he()}catch(b){E.toast(`Not saved: ${b.message||b}`,{type:"error"})}finally{w.value=!1}}const xe=l=>async()=>{await le.close(),se.has(le)||l()},le=je({title:a.displayName||a.name,size:"md",panel:z,model:N,dirty:D,form:s.length?{kind:"settings",name:a.name,dirty:D,values:()=>{const l={};for(const b of s)b.secret||(l[b.key]=$[b.key].peek());return l}}:null,methods:{save:Xe,cancel:()=>le.close(),toggle:xe(()=>P(a,!a.enabled)),update:xe(()=>F(o,{update:!0})),source:xe(()=>Re(a)),exportIt:()=>Ue(a)}});z.addEventListener("keydown",l=>{(l.ctrlKey||l.metaKey)&&l.key==="Enter"&&(l.preventDefault(),Xe())})}function We(e=null){const t=Y(),a={displayName:M.observable(e?.displayName??""),slug:M.observable(e?.slug??""),description:M.observable(e?.description??""),author:M.observable(e?.author??(t?.name||t?.username||"")),icon:M.observable(e?.icon??"box")},n=JSON.stringify(Object.fromEntries(Object.entries(a).map(([c,N])=>[c,N.peek()]))),s=()=>Object.fromEntries(Object.entries(a).map(([c,N])=>[c,N.peek()])),o=()=>JSON.stringify(s())!==n||!!e;let d=!!e?.slug;const m=M.effect(()=>{const c=a.displayName.value;d||(a.slug.value=Rt(c))}),r=M.observable(!1),C=M.computed(()=>Nt(Object.fromEntries(Object.entries(a).map(([c,N])=>[c,N.value])),R.value.map(c=>c.name))),$=c=>M.computed(()=>C.value.errors[c]||""),T={...a,saving:r,nameErr:$("displayName"),slugErr:$("slug"),descErr:$("description"),authorErr:$("author"),iconErr:$("icon"),cannot:M.computed(()=>r.value||Object.keys(C.value.errors).length>0)},w=Ee(`
|
|
69
69
|
<div class="plx-form">
|
|
70
70
|
<div>
|
|
71
71
|
<label class="form-label" for="plx-np-name">Display name <span class="text-danger">*</span></label>
|
|
@@ -101,10 +101,16 @@ import{api as v,getUser as tt}from"../api.js";import{addBannerAction as pe}from"
|
|
|
101
101
|
<button type="button" class="btn btn-sm btn-primary" data-on-click="create" data-bind-disabled="cannot.value">
|
|
102
102
|
<span data-icon="plus" data-icon-size="13"></span> Create plugin</button>
|
|
103
103
|
</div>
|
|
104
|
-
</div>`);async function
|
|
104
|
+
</div>`);async function D(){if(T.cannot.peek())return;r.value=!0;const{payload:c}=C.peek();try{await h.plugins.scaffold(c),E.toast(`"${c.displayName}" created. Restart the server to activate it.`,{type:"success",duration:6e3}),_.close(!0),p()&&await v()}catch(N){E.toast(N.message||"Could not create the plugin.",{type:"error"})}finally{r.value=!1}}const _=je({title:"New plugin",size:"sm",panel:w,model:T,dirty:o,form:{kind:"new",name:null,dirty:o,values:s},cleanup:()=>m(),methods:{create:D,cancel:()=>_.close()}}),K=w.querySelector("#plx-np-slug");K.addEventListener("input",()=>{d=!!K.value}),w.addEventListener("keydown",c=>{(c.ctrlKey||c.metaKey)&&c.key==="Enter"&&(c.preventDefault(),D())}),w.querySelector("#plx-np-name")?.focus()}function dt(e){const t=Z(e);if(!t)return[];const a=L(t.name),n=Ge(t,Q.peek()),s=!!f.peek();return[{header:t.displayName||t.name},{label:Qe(t).length?"Details and settings\u2026":"Details\u2026",icon:"settings",action:()=>ge(t.name)},...t.core?[]:[t.enabled?{label:"Switch off\u2026",icon:"pause",disabled:s,action:()=>P(t,!1)}:{label:"Switch on\u2026",icon:"play",disabled:s,action:()=>P(t,!0)}],...n?[{label:a?.needsCms?`Update to v${n} - needs a newer Domma CMS`:`Update to v${n}\u2026`,icon:"download",disabled:s||!a?.entitled||!!a?.needsCms,action:()=>F(a,{update:!0})}]:[],{type:"divider"},{label:"View source",icon:"code",disabled:t.sourceEditable===!1,action:()=>Re(t)},{label:"Export .dcmsplugin",icon:"download",disabled:t.closedSource===!0,action:()=>Ue(t)},...t.core?[]:[{type:"divider"},{label:"Uninstall\u2026",icon:"trash",danger:!0,disabled:s,action:()=>De(t.name,t.displayName)}]]}function ut(e){const t=j.peek().find(n=>n.name===e);if(!t)return[];const a=!!f.peek();return[{header:t.displayName},t.enabled?{label:t.locked?"Switch off (locked)":"Switch off\u2026",icon:"pause",disabled:a||t.locked,action:()=>P(t,!1,"tool")}:{label:t.locked?"Switch on (locked)":"Switch on\u2026",icon:"play",disabled:a||t.locked,action:()=>P(t,!0,"tool")}]}const pt=e=>{const t=j.peek().find(a=>a.name===e);t&&P(t,!t.enabled,"tool")};function mt(e){const t=L(e);if(!t)return[];const a=re(t),n=!!f.peek();return[{header:t.displayName||t.slug},...a==="install"?[{label:`Install v${t.version}\u2026`,icon:"download",disabled:n,action:()=>F(t)}]:[],...a==="update"?[{label:`Update to v${t.version}\u2026`,icon:"download",disabled:n,action:()=>F(t,{update:!0})}]:[],...t.installed?[{label:"Open in Installed",icon:"package",action:()=>{J.value=t.slug,A.value="all",_e.activate?.(0)}},{type:"divider"},{label:"Uninstall\u2026",icon:"trash",danger:!0,disabled:n,action:()=>De(t.slug,t.displayName)}]:[],...a==="buy"?[{label:t.store?`${t.owned?"Renew updates":"Buy"} - ${t.owned?ce(t).replace(/^Renew /,""):ce(t)}\u2026`:`${t.licenceStatus==="expired"?"Renew":"Buy"}${ce(t)!=="Paid"?` - ${ce(t)}`:""}\u2026`,icon:"shopping-cart",action:()=>Le(t)}]:[],...t.store&&t.tier==="paid"&&!t.owned?[{label:"Enter licence key\u2026",icon:"key",action:()=>lt(t)}]:[],...a==="waiting"?[{label:"Paid? Check now",icon:"refresh-cw",action:()=>te(t.pending,{byHand:!0})},{label:"Stop waiting\u2026",icon:"x",action:()=>st(t)}]:[],...a==="locked"?[{label:"Not licensed for this site",icon:"lock",disabled:!0,action:()=>{}}]:[],...a==="needs-cms"?[{label:t.needsCms,icon:"alert-triangle",disabled:!0,action:()=>{}}]:[]]}function ht(e){const t=L(e);if(!t)return;const a=re(t);a==="install"?F(t):a==="update"?F(t,{update:!0}):a==="buy"?Le(t):a==="waiting"?te(t.pending,{byHand:!0}):a==="needs-cms"?E.toast(t.needsCms,{type:"warning",duration:6e3}):t.installed&&(J.value=t.slug,A.value="all",_e.activate?.(0))}function ye(e,t,a,n){const s=E.contextMenu(e,{cursor:"glyph",match:".plx-row",inherit:!1,density:"compact",items:m=>a(m.dataset[t])});y.add(()=>s?.destroy?.());const o=m=>{const r=m.target.closest(".plx-row");if(!r)return;const C=m.target.closest(".plx-kebab");if(C){Ve(C);return}if(m.target.closest(".plx-act")){m.target.closest("button").disabled||n(r.dataset[t]);return}n(r.dataset[t])},d=m=>{const r=m.target.closest(".plx-row");r&&(m.key==="F10"&&m.shiftKey?(m.preventDefault(),Ve(r)):m.key==="Enter"&&m.target===r&&n(r.dataset[t]))};e.addEventListener("click",o),e.addEventListener("keydown",d),y.add(()=>{e.removeEventListener("click",o),e.removeEventListener("keydown",d)})}const ve=g.querySelector(".plx-browse");ve.appendChild(Ee(`
|
|
105
105
|
<div class="plx-card">
|
|
106
106
|
<p class="plx-note" data-bind-hidden="browseState.value !== 'loading'">Loading the catalogue\u2026</p>
|
|
107
107
|
<p class="plx-note" data-bind-hidden="browseState.value !== 'error'">The catalogue could not be loaded - it needs an administrator, and a manager that is reachable.</p>
|
|
108
|
+
<div data-bind-hidden="browseState.value !== 'owner'">
|
|
109
|
+
<p style="margin:0 0 .4rem"><strong>Every plugin is already here.</strong></p>
|
|
110
|
+
<p class="plx-note">This is an owner instance - the manager that the plugins are written on - so there is nothing to buy. Install from file in the banner still takes a <code>.dcmsplugin</code>.</p>
|
|
111
|
+
</div>
|
|
112
|
+
<p class="plx-note is-bad" data-bind-hidden="browseState.value !== 'list' || !catalogue.value.storeFailed" data-bind-text="catalogue.value.storeFailed"></p>
|
|
113
|
+
<p class="plx-note is-bad" data-bind-hidden="browseState.value !== 'list' || !catalogue.value.siteError" data-bind-text="catalogue.value.siteError"></p>
|
|
108
114
|
<div data-bind-hidden="browseState.value !== 'file'">
|
|
109
115
|
<p style="margin:0 0 .4rem"><strong>This site installs plugins from a file.</strong></p>
|
|
110
116
|
<p class="plx-note">Buy a plugin and you are sent a single <code>.dcmsplugin</code> file - Install from file in the banner installs it, and the same button takes an update later. Sites managed for you browse and install here instead, over their manager connection.</p>
|
|
@@ -118,10 +124,16 @@ import{api as v,getUser as tt}from"../api.js";import{addBannerAction as pe}from"
|
|
|
118
124
|
<button type="button" data-on-click="bUpdates" data-bind-class="browseFilter.value === 'updates' && 'is-on'" data-bind-hidden="!browseCounts.value.updates">Updates <b data-bind-text="browseCounts.value.updates"></b></button>
|
|
119
125
|
</div>
|
|
120
126
|
<input type="search" class="form-input plx-search" placeholder="Search the catalogue\u2026" aria-label="Search the catalogue" data-model="browseQuery.value">
|
|
121
|
-
<span data-help-title="Browse" data-help="What this site
|
|
127
|
+
<span data-help-title="Browse" data-help="What this site can get. Install brings a plugin in licensed to this site; Update replaces the installed version and keeps its data. On a site managed for you, Buy\u2026 (Renew\u2026 once expired) opens Manage my site in a new tab with that Tool ticked, and Not licensed means it has no online billing - ask for it to be added. On a self-hosted site, Buy\u2026 opens the Domma store's payment page in a new tab: the Tool is yours to keep, it installs here once the payment is through, and the licence key is emailed to you. Its updates last a term (shown on the row); Renew\u2026 buys more. Install and Update take effect after a server restart."></span>
|
|
122
128
|
</div>
|
|
123
129
|
<p class="plx-note" data-bind-text="siteText.value" data-bind-hidden="!siteText.value"></p>
|
|
130
|
+
<div class="plx-connect" data-bind-hidden="catalogue.value.mode !== 'store'">
|
|
131
|
+
<span class="plx-note" data-bind-text="connectText.value"></span>
|
|
132
|
+
<button type="button" class="btn btn-sm btn-outline" data-on-click="connectStart" data-bind-hidden="connStatus.value !== ''">Connect to Domma\u2026</button>
|
|
133
|
+
<button type="button" class="btn btn-sm btn-ghost" data-on-click="connectCheck" data-bind-hidden="connStatus.value !== 'pending'">Check now</button>
|
|
134
|
+
<button type="button" class="btn btn-sm btn-ghost" data-on-click="connectForget" data-bind-hidden="connStatus.value === ''" data-bind-text="connStatus.value === 'pending' ? 'Cancel' : 'Disconnect\u2026'"></button>
|
|
135
|
+
</div>
|
|
124
136
|
<p class="plx-note" data-bind-hidden="browseRows.value.length">Nothing in the catalogue matches.</p>
|
|
125
137
|
<div class="plx-list plx-catalogue" data-each="browseRows.value key=slug"></div>
|
|
126
138
|
</div>
|
|
127
|
-
</div>`)),
|
|
139
|
+
</div>`)),ve.querySelector(".plx-catalogue").innerHTML=_t;const Pe=g.querySelector(".plx-installed");Pe.innerHTML=Pt;const qe=g.querySelector(".plx-tools");qe.innerHTML=qt;const _e=E.tabs(g.querySelector(".plx-tabs"),{tabSelector:".tab-item",panelSelector:".tab-panel"}),bt=M.applyBindings({plugins:R,tools:j,toolRows:Se,catalogue:u,loading:Te,loadError:ue,restarting:f,filter:A,query:J,rows:pe,counts:tt,emptyText:at,updateCount:G,updateCountText:M.computed(()=>`${G.value} update${G.value===1?"":"s"}`),browseFilter:W,browseQuery:Me,browseRows:me,browseCounts:nt,siteText:M.computed(()=>u.value.site?u.value.mode==="store"?`From the Domma store, for ${u.value.site}. A Tool you buy is yours to keep, with a term of updates you can renew.`:`Licensed to ${u.value.site}.`:""),connStatus:M.computed(()=>u.value.connection?.status||""),connectText:M.computed(()=>{const e=u.value.connection;return e?e.status==="pending"?`Waiting for you to open the link we emailed to ${e.email} - choose Connect there.`:`Connected to Domma as ${e.email}: Tools bought for this site appear here by themselves.`:"Bought Tools on the Domma Marketplace? Connect this site and it picks up every licence bought for it."}),browseState:M.computed(()=>u.value.available===null?"loading":u.value.failed?"error":u.value.available?"list":u.value.mode==="owner"?"owner":"file")},g,{methods:{showAll:()=>{A.value="all"},showOn:()=>{A.value="on"},showOff:()=>{A.value="off"},showAttention:()=>{A.value="attention"},bAll:()=>{W.value="all"},bAvailable:()=>{W.value="available"},bInstalled:()=>{W.value="installed"},bUpdates:()=>{W.value="updates"},connectStart:()=>it(),connectCheck:()=>fe(!0),connectForget:()=>rt()}});y.add(()=>bt.dispose()),y.add(He(g,{position:"bottom"})),y.add(M.effect(()=>{pe.value,Se.value,me.value,requestAnimationFrame(()=>{g.isConnected&&I.scan(g)})})),ye(Pe,"name",dt,e=>ge(e)),ye(qe,"tool",ut,pt),ye(ve.querySelector(".plx-catalogue"),"slug",mt,ht),ke(O,{id:"plugins-guide",icon:"book",title:"Writing a Tool (guide)",onClick:()=>{location.hash="#/tutorials/plugin"}}),ke(O,{id:"plugins-install-file",icon:"upload",title:"Install from file (.dcmsplugin)",onClick:()=>X.click()});let we=!1;try{we=(await h.plugins.policy())?.signedOnly===!0}catch{}we||ke(O,{id:"plugins-new",icon:"plus",title:"New plugin",onClick:()=>We()});const Ke=e=>{(f.peek()||B?.dirty())&&(e.preventDefault(),e.returnValue="")};if(window.addEventListener("beforeunload",Ke),y.add(()=>window.removeEventListener("beforeunload",Ke)),y.add(()=>{if(B?.dirty())try{S.set(de,{kind:B.kind,name:B.name,values:B.values(),at:new Date().toISOString()})}catch{}Fe=!0,[...se].forEach(e=>{try{e.close(!0)}catch{}})}),I.scan(g),await Promise.all([he(),Ne()]),!p())return;let k=null;try{k=S.get(de)}catch{}if(k?.values&&!Fe){try{S.remove?S.remove(de):S.set(de,null)}catch{}const e=k.kind==="new"?"the new plugin you started":`your settings for ${i(Z(k.name)?.displayName||k.name)}`;(k.kind==="new"&&!we||Z(k.name))&&await E.confirm(`You left ${e} unsaved. Pick up where you left off?`)&&p()&&(k.kind==="new"?We(k.values):ge(k.name,k.values))}}};
|