@svgrid/enterprise 3.1.70 → 3.1.72
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/dist/SvGridBoard.svelte +22 -3
- package/dist/SvGridGallery.svelte +1 -1
- package/dist/card-look.d.ts +18 -0
- package/dist/card-look.js +2 -0
- package/dist/cdn/svgrid-enterprise.svelte-external.js +487 -484
- package/dist/designer/assets/GridMenus-BWRHlEUz.js +1 -0
- package/dist/designer/assets/PinSplitter-DFIcNVPE.js +1 -0
- package/dist/designer/assets/{index-0ETkK4qg.js → index-BQsNM94_.js} +3 -3
- package/dist/designer/index.html +1 -1
- package/dist/fields/BaseTableView.svelte +1 -1
- package/dist/fields/BaseTableView.svelte.d.ts +1 -1
- package/dist/fields/FieldsHeaderEnd.svelte +2 -2
- package/dist/fields/RecordView.svelte +134 -3
- package/dist/fields/RecordView.svelte.d.ts +3 -0
- package/dist/fields/SvBase.svelte +5 -3
- package/dist/fields/SvBase.svelte.d.ts +11 -0
- package/dist/fields/SvBaseViewBar.svelte +2 -2
- package/dist/fields/base-tables.d.ts +19 -0
- package/dist/fields/editor-request.svelte.d.ts +4 -1
- package/dist/fields/index.d.ts +1 -1
- package/dist/fields/index.js +1 -1
- package/dist/fields/messages/record.d.ts +118 -0
- package/dist/fields/messages/record.js +1 -1
- package/dist/fields/messages/shell.d.ts +2 -0
- package/dist/fields/messages/shell.js +1 -1
- package/dist/fields/messages/viewbar.d.ts +2 -0
- package/dist/fields/messages/viewbar.js +1 -1
- package/dist/fields/messages.svelte.d.ts +122 -0
- package/dist/fields/page/EmojiPicker.svelte +22 -0
- package/dist/fields/page/EmojiPicker.svelte.d.ts +8 -0
- package/dist/fields/page/PageEditor.svelte +155 -0
- package/dist/fields/page/PageEditor.svelte.d.ts +20 -0
- package/dist/fields/page/PageSettings.svelte +34 -0
- package/dist/fields/page/PageSettings.svelte.d.ts +17 -0
- package/dist/fields/page/embed-url.d.ts +20 -0
- package/dist/fields/page/embed-url.js +1 -0
- package/dist/fields/page/page-editor.d.ts +159 -0
- package/dist/fields/page/page-editor.js +10 -0
- package/dist/fields/page/page-schema.d.ts +35 -0
- package/dist/fields/page/page-schema.js +1 -0
- package/dist/fields/rich-html-write.js +1 -1
- package/dist/fields/sources.svelte.d.ts +3 -1
- package/dist/fields/view-model.d.ts +14 -4
- package/dist/fields/view-model.js +1 -1
- package/dist/fields/viewbar/BoardPanel.svelte +30 -2
- package/dist/node/studio.js +1 -1
- package/dist/version.d.ts +2 -2
- package/dist/version.js +1 -1
- package/dist/wc/CardMenu-D9GMS8U3.js +1 -0
- package/dist/wc/GridMenus-BcOloz5b.js +16 -0
- package/dist/wc/GridMenus-CaWxHkj0.js +16 -0
- package/dist/wc/PageEditor-9QJDKhtZ.js +10 -0
- package/dist/wc/PinSplitter-BmwDy-Ow.js +11 -0
- package/dist/wc/PinSplitter-D7UYjmiP.js +11 -0
- package/dist/wc/SvForm-CgshrajJ.js +46 -0
- package/dist/wc/board-DZKHA_nQ.js +31 -0
- package/dist/wc/card-look-CtMsGc56.js +6 -0
- package/dist/wc/date-locale-HgJNFY2n.js +1 -0
- package/dist/wc/dist-38sT7vmy.js +1 -0
- package/dist/wc/dist-BeUwTaC6.js +1 -0
- package/dist/wc/dist-Bl8aVOmr.js +2 -0
- package/dist/wc/dist-C7Z0Guly.js +1 -0
- package/dist/wc/dist-CEyUgQt3.js +2 -0
- package/dist/wc/dist-D2lK5znU.js +4 -0
- package/dist/wc/dist-DdZ3e9iY.js +5 -0
- package/dist/wc/dist-DgLsWEqp.js +1 -0
- package/dist/wc/dist-Jl2k94vj.js +1 -0
- package/dist/wc/dist-ZVYC9b49.js +1 -0
- package/dist/wc/dist-z_tOCaGG.js +1 -0
- package/dist/wc/embed-url-BTRiV8zf.js +1 -0
- package/dist/wc/gallery-B-VEjOws.js +14 -0
- package/dist/wc/{gantt-D0gdx_Tq.js → gantt-BZfS6Kbz.js} +2 -2
- package/dist/wc/{scheduler-BCY96peY.js → scheduler-BzuGk1RZ.js} +2 -2
- package/dist/wc/sv-base-element.js +109 -95
- package/dist/wc/sv-sheet-element.js +1 -1
- package/package.json +58 -3
- package/dist/designer/assets/GridMenus-Cx3LyUQM.js +0 -1
- package/dist/designer/assets/PinSplitter-oi6ffxQy.js +0 -1
- package/dist/wc/CardMenu-DC9pBy2r.js +0 -5
- package/dist/wc/GridMenus-BJsnJOkz.js +0 -16
- package/dist/wc/GridMenus-sqW-Y7S5.js +0 -16
- package/dist/wc/PinSplitter-3i65naKl.js +0 -11
- package/dist/wc/PinSplitter-CLTE0bRc.js +0 -11
- package/dist/wc/board-B-lyDG1V.js +0 -28
- package/dist/wc/date-locale-CKE0m3Dc.js +0 -46
- package/dist/wc/gallery-BpWvIrwO.js +0 -15
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import{onDestroy,onMount,tick}from"svelte";import{createPageEditor,loadPageEditor}from"./page-editor";import{PAGE_COLORS}from"./page-schema";import{bm}from"../messages.svelte";let{html,editable=true,onSave,onUnavailable,upload,preview,onError,records}=$props();let uploading=$state(0);let root=$state(null);let mount=$state(null);let ed=$state.raw(null);let saved=html;let pending=null;let timer;const PAUSE=1500;function changed(next){pending=next;clearTimeout(timer);if(!theirs)timer=setTimeout(flush,PAUSE)}let theirs=$state(null);function keepMine(){const mine=pending??ed?.html()??saved;theirs=null;pending=mine;saved="\0";flush()}function showTheirs(){const t=theirs;theirs=null;pending=null;if(t==null)return;saved=t;ed?.setHtml(t)}function flush(){clearTimeout(timer);if(theirs!=null)return;if(pending==null||pending===saved)return void(pending=null);saved=pending;pending=null;onSave(saved)}onMount(()=>{let gone=false;void loadPageEditor().then(pm=>{if(gone||!mount)return;if(!pm)return onUnavailable?.();ed=createPageEditor(pm,mount,{html,editable,placeholder:bm("record.pagePlaceholder"),onChange:changed,onSlash:s=>void slashChanged(s),onSelection:()=>selTick+=1,upload,records,onMention:s=>void mentionChanged(s),onUploading:n=>uploading=n,onError,onEscape:()=>{if(blockMenu){blockMenu=null;return true}if(linking){linking=false;return true}return false}})});return()=>{gone=true}});onDestroy(()=>{flush();ed?.destroy()});$effect(()=>{const now=html;if(!ed||now===saved)return;if(pending==null){saved=now;ed.setHtml(now)}else{clearTimeout(timer);theirs=now}});$effect(()=>{ed?.setEditable(editable)});const ITEMS=$derived([{kind:"text",label:bm("record.blockText"),hint:bm("record.blockTextHint"),words:"text paragraph plain",icon:"T"},{kind:"h1",label:bm("record.blockH1"),hint:bm("record.blockH1Hint"),words:"heading title h1 #",icon:"H1"},{kind:"h2",label:bm("record.blockH2"),hint:bm("record.blockH2Hint"),words:"heading subtitle h2 ##",icon:"H2"},{kind:"h3",label:bm("record.blockH3"),hint:bm("record.blockH3Hint"),words:"heading h3 ###",icon:"H3"},{kind:"bullet",label:bm("record.blockBullet"),hint:bm("record.blockBulletHint"),words:"bulleted list unordered ul -",icon:"•"},{kind:"numbered",label:bm("record.blockNumbered"),hint:bm("record.blockNumberedHint"),words:"numbered list ordered ol 1.",icon:"1."},{kind:"todo",label:bm("record.blockTodo"),hint:bm("record.blockTodoHint"),words:"todo to-do task checkbox check []",icon:"☑"},{kind:"toggle",label:bm("record.blockToggle"),hint:bm("record.blockToggleHint"),words:"toggle fold collapse details",icon:"▸"},{kind:"toggleH1",label:bm("record.blockToggleH1"),hint:bm("record.blockToggleHHint"),words:"toggle heading h1",icon:"▸H1"},{kind:"toggleH2",label:bm("record.blockToggleH2"),hint:bm("record.blockToggleHHint"),words:"toggle heading h2",icon:"▸H2"},{kind:"toggleH3",label:bm("record.blockToggleH3"),hint:bm("record.blockToggleHHint"),words:"toggle heading h3",icon:"▸H3"},{kind:"quote",label:bm("record.blockQuote"),hint:bm("record.blockQuoteHint"),words:"quote blockquote >",icon:"“"},{kind:"callout",label:bm("record.blockCallout"),hint:bm("record.blockCalloutHint"),words:"callout note tip warning box",icon:"💡"},{kind:"divider",label:bm("record.blockDivider"),hint:bm("record.blockDividerHint"),words:"divider line separator hr ---",icon:"—"},{kind:"code",label:bm("record.blockCode"),hint:bm("record.blockCodeHint"),words:"code snippet pre ```",icon:"</>"},{kind:"columns2",label:bm("record.blockColumns2"),hint:bm("record.blockColumnsHint"),words:"columns two side by side layout",icon:"▥"},{kind:"columns3",label:bm("record.blockColumns3"),hint:bm("record.blockColumnsHint"),words:"columns three side by side layout",icon:"▥"},...upload?[{kind:"image",label:bm("record.blockImage"),hint:bm("record.blockImageHint"),words:"image picture photo upload",icon:"🖼"},{kind:"file",label:bm("record.blockFile"),hint:bm("record.blockFileHint"),words:"file upload attachment pdf document",icon:"📎"}]:[],...records?[{kind:"page",label:bm("record.blockPage"),hint:bm("record.blockPageHint"),words:"page subpage sub-page child nested",icon:"📄"}]:[],{kind:"toc",label:bm("record.blockToc"),hint:bm("record.blockTocHint"),words:"table of contents toc headings outline",icon:"☰"},{kind:"video",label:bm("record.blockVideo"),hint:bm("record.blockVideoHint"),words:"video youtube vimeo loom",icon:"▶"},{kind:"embed",label:bm("record.blockEmbed"),hint:bm("record.blockEmbedHint"),words:"embed google docs sheets maps figma miro spotify calendly",icon:"⧉"},{kind:"bookmark",label:bm("record.blockBookmark"),hint:bm("record.blockBookmarkHint"),words:"bookmark link web page url",icon:"🔖"}]);let asking=$state(null);let askText=$state("");let askBusy=$state(false);let picker=$state(null);let pickFor=null;async function askDone(e){e.preventDefault();const a=asking;const v=askText.trim();if(!a||!v||!ed)return;const href=/^[a-z][a-z0-9+.-]*:/i.test(v)?v:`https://${v}`;if(a.kind==="bookmark"){askBusy=true;let card={title:href,description:"",site:""};try{if(preview)card=await preview(href)}catch{}askBusy=false;ed.insertBookmark(href,card,a.range)}else ed.insertEmbed(href,a.range);asking=null;askText=""}function picked(e){const input=e.currentTarget;const files=Array.from(input.files??[]);input.value="";if(files.length&&ed&&pickFor)void ed.insertFiles(files,pickFor.range);pickFor=null}let slash=$state(null);let slashAt=$state(null);let slashIndex=$state(0);const found=$derived.by(()=>{const q=(slash?.query??"").trim().toLocaleLowerCase();if(!q)return ITEMS;return ITEMS.filter(i=>i.label.toLocaleLowerCase().includes(q)||i.words.split(" ").some(w=>w.startsWith(q)))});async function slashChanged(s){const opening=s&&!slash;slash=s;if(!s||!ed||!root)return void(slashAt=null);if(opening)slashIndex=0;slashIndex=Math.min(slashIndex,Math.max(0,found.length-1));await tick();slashAt=placeAt(s.from)}function closeSlash(){slash=null;slashAt=null;ed?.closeSlash()}function pick(i){if(!ed||!slash)return;const range={from:slash.from,to:slash.to};if(i.kind==="image"||i.kind==="file"){pickFor={range};if(picker){picker.accept=i.kind==="image"?"image/*":"";picker.click()}closeSlash();return}if(i.kind==="page"){closeSlash();void ed.insertSubpage(range);return}if(i.kind==="embed"||i.kind==="video"||i.kind==="bookmark"){const at2=slashAt??{top:0,left:0};asking={kind:i.kind,range,top:at2.top,left:at2.left};askText="";closeSlash();return}ed.insertBlock(i.kind,range)}function placeAt(pos){if(!ed||!root)return null;try{const c=ed.view.coordsAtPos(pos);const box=root.getBoundingClientRect();return{top:c.bottom-box.top+4,left:Math.max(0,c.left-box.left)}}catch{return{top:0,left:0}}}let at=$state(null);let atPlace=$state(null);let atIndex=$state(0);const people=$derived(at&&records?records.find(at.query).slice(0,8):[]);async function mentionChanged(s){const opening=s&&!at;at=s;if(!s)return void(atPlace=null);if(opening)atIndex=0;atIndex=Math.min(atIndex,Math.max(0,people.length-1));await tick();atPlace=placeAt(s.from)}function name(r){if(!ed||!at)return;ed.insertMention(r,{from:at.from,to:at.to})}function keysFirst(e){if(at){if(e.key==="ArrowDown"||e.key==="ArrowUp"){e.preventDefault();e.stopPropagation();const n=people.length;if(n)atIndex=(atIndex+(e.key==="ArrowDown"?1:-1)+n)%n;return}if((e.key==="Enter"||e.key==="Tab")&&people.length){e.preventDefault();e.stopPropagation();name(people[atIndex]??people[0]);return}if(e.key==="Escape"){e.preventDefault();e.stopPropagation();ed?.closeMention();return}}if(e.key==="Escape"&&asking){e.preventDefault();e.stopPropagation();asking=null;ed?.view.focus();return}if(e.key==="Escape"&&(slash||blockMenu||linking||colorsOpen)){e.preventDefault();e.stopPropagation();blockMenu=null;linking=false;colorsOpen=false;if(slash)closeSlash();ed?.view.focus();return}if(!slash)return;if(e.key==="ArrowDown"||e.key==="ArrowUp"){e.preventDefault();e.stopPropagation();const n=found.length;if(n)slashIndex=(slashIndex+(e.key==="ArrowDown"?1:-1)+n)%n}else if((e.key==="Enter"||e.key==="Tab")&&found.length){e.preventDefault();e.stopPropagation();pick(found[slashIndex]??found[0])}}let selTick=$state(0);let focused=$state(false);let linking=$state(false);let linkText=$state("");let colorsOpen=$state(false);const bar=$derived.by(()=>{void selTick;if(!ed||!root||!focused||!editable)return null;const sel=ed.view.state.selection;if(sel.empty||sel.node)return null;const at2=placeAt(sel.from);if(!at2)return null;return{top:Math.max(0,at2.top-48),left:at2.left,marks:ed.marksHere()}});const MARKS=[{mark:"strong",key:"record.markBold",text:"B",style:"font-weight:700"},{mark:"em",key:"record.markItalic",text:"i",style:"font-style:italic;font-family:Georgia,serif"},{mark:"underline",key:"record.markUnderline",text:"U",style:"text-decoration:underline"},{mark:"strike",key:"record.markStrike",text:"S",style:"text-decoration:line-through"},{mark:"code",key:"record.markCode",text:"<>",style:"font-family:monospace;font-size:12px"}];function startLink(){linking=true;linkText="";colorsOpen=false}function saveLink(e){e.preventDefault();const v=linkText.trim();if(v)ed?.setLink(/^[a-z][a-z0-9+.-]*:|^\/|^#/i.test(v)?v:`https://${v}`);linking=false}let handle=$state(null);let blockMenu=$state(null);function moved(e){if(!ed||!editable||blockMenu||e.pointerType==="touch")return;const r=ed.view.dom.getBoundingClientRect();if(e.clientY<r.top||e.clientY>r.bottom)return;const hit=ed.blockAt(r.left+12,e.clientY);if(!hit||!root)return;const b=hit.dom.getBoundingClientRect();handle={pos:hit.pos,top:b.top-root.getBoundingClientRect().top}}const COLOR_KEYS={gray:"record.colorGray",brown:"record.colorBrown",orange:"record.colorOrange",yellow:"record.colorYellow",green:"record.colorGreen",blue:"record.colorBlue",purple:"record.colorPurple",pink:"record.colorPink",red:"record.colorRed"};const TURN=["text","h1","h2","h3","bullet","numbered","todo","toggle","quote","callout","code"];function menuDo(f){f();blockMenu=null}$effect(()=>{if(!blockMenu)return;const away=e=>{if(!e.target?.closest?.(".sv-pe-menu, .sv-pe-grip"))blockMenu=null};const t=setTimeout(()=>document.addEventListener("pointerdown",away,true),0);return()=>{clearTimeout(t);document.removeEventListener("pointerdown",away,true)}});
|
|
3
|
+
</script>
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
<div
|
|
7
|
+
class="sv-pe"
|
|
8
|
+
bind:this={root}
|
|
9
|
+
onkeydowncapture={keysFirst}
|
|
10
|
+
onpointermove={moved}
|
|
11
|
+
onpointerleave={() => {
|
|
12
|
+
if (!blockMenu) handle = null
|
|
13
|
+
}}
|
|
14
|
+
onfocusin={() => (focused = true)}
|
|
15
|
+
onfocusout={(e) => {
|
|
16
|
+
if (root && !root.contains(e.relatedTarget as Node)) {
|
|
17
|
+
focused = false
|
|
18
|
+
linking = false
|
|
19
|
+
colorsOpen = false
|
|
20
|
+
flush()
|
|
21
|
+
}
|
|
22
|
+
}}
|
|
23
|
+
>
|
|
24
|
+
{#if theirs != null}
|
|
25
|
+
<div class="sv-pe-conflict" role="alert">
|
|
26
|
+
<span>{bm('record.pageConflict')}</span>
|
|
27
|
+
<button type="button" onclick={keepMine}>{bm('record.pageKeepMine')}</button>
|
|
28
|
+
<button type="button" onclick={showTheirs}>{bm('record.pageShowTheirs')}</button>
|
|
29
|
+
</div>
|
|
30
|
+
{/if}
|
|
31
|
+
<div class="sv-pe-mount" bind:this={mount} aria-label={bm('record.pageEditor')}></div>
|
|
32
|
+
|
|
33
|
+
{#if handle && editable && ed}
|
|
34
|
+
{@const at = handle}
|
|
35
|
+
<div class="sv-pe-handle" style:top={`${at.top}px`}>
|
|
36
|
+
<button type="button" class="sv-pe-plus" title={bm('record.blockAdd')} aria-label={bm('record.blockAdd')} onclick={() => ed?.addBelow(at.pos)}>+</button>
|
|
37
|
+
<button
|
|
38
|
+
type="button"
|
|
39
|
+
class="sv-pe-grip"
|
|
40
|
+
draggable="true"
|
|
41
|
+
title={bm('record.blockHandle')}
|
|
42
|
+
aria-label={bm('record.blockMenu')}
|
|
43
|
+
aria-haspopup="menu"
|
|
44
|
+
aria-expanded={blockMenu?.pos === at.pos}
|
|
45
|
+
ondragstart={(e) => ed?.dragBlock(at.pos, e)}
|
|
46
|
+
ondragend={() => (handle = null)}
|
|
47
|
+
onclick={() => (blockMenu = blockMenu?.pos === at.pos ? null : { pos: at.pos, top: at.top, part: 'main' })}
|
|
48
|
+
>⋮⋮</button>
|
|
49
|
+
</div>
|
|
50
|
+
{/if}
|
|
51
|
+
|
|
52
|
+
{#if blockMenu && ed}
|
|
53
|
+
{@const m = blockMenu}
|
|
54
|
+
<div class="sv-pe-menu" role="menu" aria-label={bm('record.blockMenu')} style:top={`${m.top}px`}>
|
|
55
|
+
{#if m.part === 'main'}
|
|
56
|
+
<button type="button" role="menuitem" onclick={() => (blockMenu = { ...m, part: 'turn' })}>{bm('record.turnInto')} ›</button>
|
|
57
|
+
<button type="button" role="menuitem" onclick={() => (blockMenu = { ...m, part: 'color' })}>{bm('record.blockColor')} ›</button>
|
|
58
|
+
<button type="button" role="menuitem" onclick={() => menuDo(() => ed!.duplicateBlock(m.pos))}>{bm('record.blockDuplicate')}</button>
|
|
59
|
+
<button type="button" role="menuitem" class="is-danger" onclick={() => menuDo(() => ed!.deleteBlock(m.pos))}>{bm('record.blockDelete')}</button>
|
|
60
|
+
{:else if m.part === 'turn'}
|
|
61
|
+
{#each ITEMS.filter((i) => TURN.includes(i.kind as BlockKind)) as i (i.kind)}
|
|
62
|
+
<button type="button" role="menuitem" onclick={() => menuDo(() => ed!.turnInto(m.pos, i.kind as BlockKind))}><span class="sv-pe-ico">{i.icon}</span>{i.label}</button>
|
|
63
|
+
{/each}
|
|
64
|
+
{:else}
|
|
65
|
+
<button type="button" role="menuitem" onclick={() => menuDo(() => ed!.setBlockColor(m.pos, null))}><span class="sv-pe-swatch"></span>{bm('record.colorDefault')}</button>
|
|
66
|
+
{#each PAGE_COLORS as c (c)}
|
|
67
|
+
<button type="button" role="menuitem" onclick={() => menuDo(() => ed!.setBlockColor(m.pos, c))}><span class="sv-pe-swatch sv-c-{c}">A</span>{bm(COLOR_KEYS[c] as never)}</button>
|
|
68
|
+
{/each}
|
|
69
|
+
{/if}
|
|
70
|
+
</div>
|
|
71
|
+
{/if}
|
|
72
|
+
|
|
73
|
+
<input type="file" class="sv-pe-picker" bind:this={picker} multiple tabindex="-1" aria-hidden="true" onchange={picked} />
|
|
74
|
+
{#if uploading}
|
|
75
|
+
<p class="sv-pe-uploading" role="status">{bm('record.coverUploading')}</p>
|
|
76
|
+
{/if}
|
|
77
|
+
{#if asking}
|
|
78
|
+
<form class="sv-pe-ask" style:top={`${asking.top}px`} style:left={`${asking.left}px`} onsubmit={(e) => void askDone(e)}>
|
|
79
|
+
|
|
80
|
+
<input class="sv-fvb-input" autofocus disabled={askBusy} placeholder={bm(asking.kind === 'bookmark' ? 'record.askBookmark' : asking.kind === 'video' ? 'record.askVideo' : 'record.askEmbed')} aria-label={bm(asking.kind === 'bookmark' ? 'record.askBookmark' : asking.kind === 'video' ? 'record.askVideo' : 'record.askEmbed')} bind:value={askText} />
|
|
81
|
+
<button type="submit" disabled={askBusy || !askText.trim()}>{bm(asking.kind === 'bookmark' ? 'record.makeBookmark' : 'record.makeEmbed')}</button>
|
|
82
|
+
{#if asking.kind !== 'bookmark'}<small>{bm('record.embedWhich')}</small>{/if}
|
|
83
|
+
</form>
|
|
84
|
+
{/if}
|
|
85
|
+
{#if at && atPlace}
|
|
86
|
+
<div class="sv-pe-slash sv-pe-at" role="listbox" aria-label={bm('record.mentionMenu')} style:top={`${atPlace.top}px`} style:left={`${atPlace.left}px`}>
|
|
87
|
+
{#each people as r, n (r.id)}
|
|
88
|
+
<button type="button" role="option" aria-selected={n === atIndex} class:is-on={n === atIndex} onmousedown={(e) => e.preventDefault()} onpointerenter={() => (atIndex = n)} onclick={() => name(r)}>
|
|
89
|
+
<span class="sv-pe-ico">{r.icon || '📄'}</span>
|
|
90
|
+
<span class="sv-pe-what"><strong>{r.title}</strong></span>
|
|
91
|
+
</button>
|
|
92
|
+
{:else}
|
|
93
|
+
<p class="sv-pe-none">{bm('record.mentionNone')}</p>
|
|
94
|
+
{/each}
|
|
95
|
+
</div>
|
|
96
|
+
{/if}
|
|
97
|
+
{#if slash && slashAt}
|
|
98
|
+
<div class="sv-pe-slash" role="listbox" aria-label={bm('record.slashMenu')} style:top={`${slashAt.top}px`} style:left={`${slashAt.left}px`}>
|
|
99
|
+
{#each found as i, n (i.kind)}
|
|
100
|
+
<button
|
|
101
|
+
type="button"
|
|
102
|
+
role="option"
|
|
103
|
+
aria-selected={n === slashIndex}
|
|
104
|
+
class:is-on={n === slashIndex}
|
|
105
|
+
onmousedown={(e) => e.preventDefault()}
|
|
106
|
+
onpointerenter={() => (slashIndex = n)}
|
|
107
|
+
onclick={() => pick(i)}
|
|
108
|
+
>
|
|
109
|
+
<span class="sv-pe-ico">{i.icon}</span>
|
|
110
|
+
<span class="sv-pe-what"><strong>{i.label}</strong><small>{i.hint}</small></span>
|
|
111
|
+
</button>
|
|
112
|
+
{:else}
|
|
113
|
+
<p class="sv-pe-none">{bm('record.slashNone')}</p>
|
|
114
|
+
{/each}
|
|
115
|
+
</div>
|
|
116
|
+
{/if}
|
|
117
|
+
|
|
118
|
+
{#if bar && ed}
|
|
119
|
+
|
|
120
|
+
<div class="sv-pe-bar" role="toolbar" aria-label={bm('record.blockMenu')} style:top={`${bar.top}px`} style:left={`${bar.left}px`} onmousedown={(e) => { if (!(e.target as Element).closest('input')) e.preventDefault() }}>
|
|
121
|
+
{#if linking}
|
|
122
|
+
<form class="sv-pe-link" onsubmit={saveLink}>
|
|
123
|
+
|
|
124
|
+
<input class="sv-fvb-input" autofocus placeholder={bm('record.linkAsk')} aria-label={bm('record.linkAsk')} bind:value={linkText} onkeydown={(e) => { if (e.key === 'Escape') { e.stopPropagation(); linking = false; ed?.view.focus() } }} />
|
|
125
|
+
</form>
|
|
126
|
+
{#if bar.marks.has('link')}<button type="button" onclick={() => { ed?.setLink(null); linking = false }}>{bm('record.linkRemove')}</button>{/if}
|
|
127
|
+
{:else}
|
|
128
|
+
{#each MARKS as m (m.mark)}
|
|
129
|
+
<button type="button" class:is-on={bar.marks.has(m.mark)} aria-pressed={bar.marks.has(m.mark)} title={bm(m.key)} aria-label={bm(m.key)} onclick={() => ed?.toggleMark(m.mark)}><span style={m.style}>{m.text}</span></button>
|
|
130
|
+
{/each}
|
|
131
|
+
<button type="button" class:is-on={bar.marks.has('link')} title={bm('record.markLink')} aria-label={bm('record.markLink')} onclick={startLink}>🔗</button>
|
|
132
|
+
<span class="sv-pe-colors">
|
|
133
|
+
<button type="button" title={bm('record.textColor')} aria-label={bm('record.textColor')} aria-expanded={colorsOpen} onclick={() => (colorsOpen = !colorsOpen)}>A▾</button>
|
|
134
|
+
{#if colorsOpen}
|
|
135
|
+
<div class="sv-pe-palette" role="menu">
|
|
136
|
+
<span class="sv-pe-palette-h">{bm('record.textColor')}</span>
|
|
137
|
+
<button type="button" role="menuitem" onclick={() => { ed?.setTextColor(null); colorsOpen = false }}><span class="sv-pe-swatch">A</span>{bm('record.colorDefault')}</button>
|
|
138
|
+
{#each PAGE_COLORS as c (c)}
|
|
139
|
+
<button type="button" role="menuitem" onclick={() => { ed?.setTextColor(c); colorsOpen = false }}><span class="sv-pe-swatch sv-c-{c}">A</span>{bm(COLOR_KEYS[c] as never)}</button>
|
|
140
|
+
{/each}
|
|
141
|
+
<span class="sv-pe-palette-h">{bm('record.highlight')}</span>
|
|
142
|
+
{#each PAGE_COLORS as c (c)}
|
|
143
|
+
<button type="button" role="menuitem" onclick={() => { ed?.setTextColor(c, true); colorsOpen = false }}><span class="sv-pe-swatch sv-h-{c}">A</span>{bm(COLOR_KEYS[c] as never)}</button>
|
|
144
|
+
{/each}
|
|
145
|
+
</div>
|
|
146
|
+
{/if}
|
|
147
|
+
</span>
|
|
148
|
+
{/if}
|
|
149
|
+
</div>
|
|
150
|
+
{/if}
|
|
151
|
+
</div>
|
|
152
|
+
|
|
153
|
+
<style>
|
|
154
|
+
.sv-pe{position:relative;padding-inline-start:48px;margin-inline-start:-48px}.sv-pe-mount{min-height:160px}.sv-pe-picker{position:absolute;width:1px;height:1px;opacity:0;pointer-events:none}.sv-pe-uploading{margin:0 0 6px 48px;font-size:12px;color:var(--sg-muted, #64748b)}.sv-pe-ask{position:absolute;z-index:7;display:grid;grid-template-columns:1fr auto;gap:6px;width:min(420px,90%);padding:8px;border:1px solid var(--sg-border, #e2e8f0);border-radius:10px;background:var(--sg-bg, #fff);box-shadow:0 12px 32px #0f172a29}.sv-pe-ask button{padding:0 12px;border:0;border-radius:6px;background:var(--sg-accent, #2563eb);color:#fff;font:inherit;font-size:13px;cursor:pointer}.sv-pe-ask button:disabled{opacity:.5;cursor:default}.sv-pe-ask small{grid-column:1 / -1;color:var(--sg-muted, #64748b);font-size:12px}.sv-pe-conflict{display:flex;flex-wrap:wrap;align-items:center;gap:8px;margin:0 0 8px 48px;padding:8px 10px;border-radius:8px;background:color-mix(in srgb,#cb912f 16%,transparent);font-size:13px}.sv-pe-conflict span{flex:1;min-width:200px}.sv-pe-conflict button{padding:4px 10px;border:1px solid var(--sg-border, #e2e8f0);border-radius:6px;background:var(--sg-bg, #fff);color:inherit;font:inherit;cursor:pointer}.sv-pe :global(.sv-page-doc){outline:none;min-height:160px;padding:4px 4px 48px;white-space:pre-wrap}.sv-pe :global(.sv-page-doc .is-empty:before){content:attr(data-placeholder);float:left;height:0;pointer-events:none;color:var(--sg-muted, #94a3b8)}.sv-pe :global(.ProseMirror-selectednode){outline:2px solid color-mix(in srgb,var(--sg-accent, #2563eb) 40%,transparent);border-radius:4px}.sv-pe :global(.ProseMirror-gapcursor){display:none;pointer-events:none;position:absolute}.sv-pe :global(.ProseMirror-focused .ProseMirror-gapcursor){display:block}.sv-pe :global(.ProseMirror-gapcursor:after){content:"";display:block;position:absolute;top:-2px;width:20px;border-top:1px solid currentColor}.sv-pe-handle{position:absolute;left:0;display:flex;gap:0;height:26px;align-items:center}.sv-pe-plus,.sv-pe-grip{width:22px;height:24px;padding:0;border:0;border-radius:4px;background:none;color:var(--sg-muted, #94a3b8);cursor:pointer;font-size:16px;line-height:1}.sv-pe-grip{cursor:grab;font-size:12px;letter-spacing:-2px}.sv-pe-plus:hover,.sv-pe-grip:hover,.sv-pe-grip[aria-expanded=true]{background:var(--sg-row-hover-bg, #f1f5f9);color:var(--sg-fg, #0f172a)}.sv-pe-slash,.sv-pe-menu,.sv-pe-palette{position:absolute;z-index:7;display:flex;flex-direction:column;padding:4px;border:1px solid var(--sg-border, #e2e8f0);border-radius:10px;background:var(--sg-bg, #fff);color:var(--sg-fg, #0f172a);box-shadow:0 12px 32px #0f172a29;font-size:13px}.sv-pe-slash{width:280px;max-height:320px;overflow:auto}.sv-pe-menu{left:0;margin-top:28px;width:220px;max-height:360px;overflow:auto}.sv-pe-slash button,.sv-pe-menu button,.sv-pe-palette button{display:flex;align-items:center;gap:10px;width:100%;padding:6px 8px;border:0;border-radius:6px;background:none;color:inherit;font:inherit;text-align:start;cursor:pointer}.sv-pe-slash button.is-on,.sv-pe-menu button:hover,.sv-pe-palette button:hover{background:var(--sg-row-hover-bg, #f1f5f9)}.sv-pe-menu .is-danger{color:var(--sg-danger, #dc2626)}.sv-pe-ico{display:inline-grid;place-items:center;flex:none;width:34px;height:30px;border:1px solid var(--sg-border, #e2e8f0);border-radius:6px;background:var(--sg-bg, #fff);font-size:13px;font-weight:600}.sv-pe-menu .sv-pe-ico{width:24px;height:22px;font-size:11px}.sv-pe-what{display:flex;flex-direction:column;min-width:0}.sv-pe-what small{color:var(--sg-muted, #64748b);font-size:12px}.sv-pe-none{margin:6px 8px;color:var(--sg-muted, #64748b)}.sv-pe-swatch{display:inline-grid;place-items:center;width:22px;height:22px;border:1px solid var(--sg-border, #e2e8f0);border-radius:4px;font-weight:600}.sv-pe-bar{position:absolute;z-index:7;display:flex;align-items:center;gap:2px;padding:3px;border:1px solid var(--sg-border, #e2e8f0);border-radius:8px;background:var(--sg-bg, #fff);box-shadow:0 8px 24px #0f172a29}.sv-pe-bar>button,.sv-pe-colors>button{min-width:28px;height:28px;padding:0 6px;border:0;border-radius:6px;background:none;color:inherit;font:inherit;font-size:14px;cursor:pointer}.sv-pe-bar>button:hover,.sv-pe-bar>button.is-on,.sv-pe-colors>button:hover{background:var(--sg-row-hover-bg, #f1f5f9);color:var(--sg-accent, #2563eb)}.sv-pe-link input{width:240px}.sv-pe-colors{position:relative}.sv-pe-palette{top:100%;left:0;margin-top:4px;width:180px;max-height:300px;overflow:auto}.sv-pe-palette-h{padding:6px 8px 2px;font-size:11px;color:var(--sg-muted, #64748b)}
|
|
155
|
+
</style>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type LinkCard, type PageEditor, type PageFile, type PageRecords } from './page-editor.js';
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
html: string;
|
|
4
|
+
editable?: boolean;
|
|
5
|
+
/** The page's HTML after a pause in typing, or as the focus leaves. */
|
|
6
|
+
onSave: (html: string) => void;
|
|
7
|
+
/** ProseMirror is not there: the caller shows its usual editor. */
|
|
8
|
+
onUnavailable?: () => void;
|
|
9
|
+
/** Store a picture or file given to the page; without it the page takes none. */
|
|
10
|
+
upload?: (file: File) => Promise<PageFile>;
|
|
11
|
+
/** A link's title and description for a bookmark; without it a bookmark is the address. */
|
|
12
|
+
preview?: (url: string) => Promise<LinkCard>;
|
|
13
|
+
/** Something went wrong (an upload refused): for the host to say. */
|
|
14
|
+
onError?: (message: string) => void;
|
|
15
|
+
/** The table's records, for sub-pages and @ mentions. */
|
|
16
|
+
records?: PageRecords;
|
|
17
|
+
};
|
|
18
|
+
declare const PageEditor: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
19
|
+
type PageEditor = ReturnType<typeof PageEditor>;
|
|
20
|
+
export default PageEditor;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import{onMount}from"svelte";import{bm}from"../messages.svelte";let{page,fields,onChange,onMakeBody,onClose}=$props();const texts=$derived(fields.filter(f=>f.type==="richText"));const pictures=$derived(fields.filter(f=>f.type==="attachment"));let box=$state(null);onMount(()=>{box?.querySelector("input, select, button")?.focus();const away=e=>{if(box&&!box.contains(e.target)&&!e.target?.closest?.(".sv-fpg-open"))onClose()};const t=setTimeout(()=>document.addEventListener("pointerdown",away,true),0);return()=>{clearTimeout(t);document.removeEventListener("pointerdown",away,true)}});function turn(on){if(!on)return onChange(void 0);const body=texts[0];if(body)onChange({body:body.id,...pictures[0]?{cover:pictures[0].id}:{}});else onMakeBody()}function pickBody(id){if(id==="__new")return onMakeBody();if(page)onChange({...page,body:id})}function pickCover(id){if(!page)return;const{cover:_c,...rest}=page;onChange(id?{...rest,cover:id}:rest)}
|
|
3
|
+
</script>
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
<div class="sv-fpg-settings" role="dialog" aria-label={bm('record.pageMenu')} bind:this={box} onkeydown={(e) => { if (e.key === 'Escape') { e.preventDefault(); e.stopPropagation(); onClose() } }}>
|
|
7
|
+
<label class="sv-fpg-row">
|
|
8
|
+
<input type="checkbox" role="switch" class="sv-fvb-switch" checked={!!page} onchange={(e) => turn((e.currentTarget as HTMLInputElement).checked)} />
|
|
9
|
+
<span>{bm('record.asPages')}</span>
|
|
10
|
+
</label>
|
|
11
|
+
<p class="sv-fpg-hint">{bm('record.asPagesHint')}</p>
|
|
12
|
+
{#if page}
|
|
13
|
+
<label class="sv-fpg-field">
|
|
14
|
+
<span>{bm('record.pageBody')}</span>
|
|
15
|
+
<select class="sv-fvb-select" value={page.body} onchange={(e) => pickBody((e.currentTarget as HTMLSelectElement).value)}>
|
|
16
|
+
{#each texts as f (f.id)}<option value={f.id}>{f.name}</option>{/each}
|
|
17
|
+
<option value="__new">{bm('record.pageNewBody')}</option>
|
|
18
|
+
</select>
|
|
19
|
+
</label>
|
|
20
|
+
{#if pictures.length}
|
|
21
|
+
<label class="sv-fpg-field">
|
|
22
|
+
<span>{bm('record.pageCover')}</span>
|
|
23
|
+
<select class="sv-fvb-select" value={page.cover ?? ''} onchange={(e) => pickCover((e.currentTarget as HTMLSelectElement).value)}>
|
|
24
|
+
<option value="">{bm('record.pageNoCover')}</option>
|
|
25
|
+
{#each pictures as f (f.id)}<option value={f.id}>{f.name}</option>{/each}
|
|
26
|
+
</select>
|
|
27
|
+
</label>
|
|
28
|
+
{/if}
|
|
29
|
+
{/if}
|
|
30
|
+
</div>
|
|
31
|
+
|
|
32
|
+
<style>
|
|
33
|
+
.sv-fpg-settings{position:absolute;z-index:6;top:100%;inset-inline-end:0;margin-top:4px;width:300px;padding:10px 12px;border:1px solid var(--sg-border, #e2e8f0);border-radius:10px;background:var(--sg-bg, #fff);color:var(--sg-fg, #0f172a);box-shadow:0 12px 32px #0f172a29;display:grid;gap:8px;font-size:13px;text-align:start}.sv-fpg-row{display:flex;align-items:center;gap:8px;cursor:pointer;font-weight:600}.sv-fpg-hint{margin:0;font-size:12px;color:var(--sg-muted, #64748b)}.sv-fpg-field{display:grid;grid-template-columns:100px 1fr;align-items:center;gap:8px}.sv-fpg-field>span{color:var(--sg-muted, #64748b)}
|
|
34
|
+
</style>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { BasePage } from '../base-tables.js';
|
|
2
|
+
type Field = {
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
type?: string;
|
|
6
|
+
};
|
|
7
|
+
type $$ComponentProps = {
|
|
8
|
+
page: BasePage | undefined;
|
|
9
|
+
fields: Field[];
|
|
10
|
+
onChange: (page: BasePage | undefined) => void;
|
|
11
|
+
/** Make a rich text field "Page" and use it. */
|
|
12
|
+
onMakeBody: () => void;
|
|
13
|
+
onClose: () => void;
|
|
14
|
+
};
|
|
15
|
+
declare const PageSettings: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
16
|
+
type PageSettings = ReturnType<typeof PageSettings>;
|
|
17
|
+
export default PageSettings;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which links a page may show inside it (records as pages, `/embed`, `/video`):
|
|
3
|
+
* a short list of services, each turned into its own embed address. Any other
|
|
4
|
+
* link stays a link (or a bookmark): a page never frames a site nobody chose.
|
|
5
|
+
*
|
|
6
|
+
* The page keeps the link as the person gave it (`<p class="sv-embed"><a href>`);
|
|
7
|
+
* the frame is made when the page is shown, from this list, so a stored page
|
|
8
|
+
* holds no frame and the list can change without touching what was written.
|
|
9
|
+
*/
|
|
10
|
+
export type Embed = {
|
|
11
|
+
src: string;
|
|
12
|
+
provider: string;
|
|
13
|
+
height: number;
|
|
14
|
+
ratio?: number;
|
|
15
|
+
};
|
|
16
|
+
export declare function embedOf(link: string): Embed | null;
|
|
17
|
+
/** A sandboxed frame for an embed: scripts for the player, nothing to reach the page around it. */
|
|
18
|
+
export declare function embedFrame(e: Embed, title: string): HTMLIFrameElement;
|
|
19
|
+
/** Frames for the embeds of a page shown without the editor (`<p class="sv-embed"><a href>`). */
|
|
20
|
+
export declare function frameEmbeds(root: HTMLElement): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const s=/^[A-Za-z0-9_-]{4,64}$/,c=encodeURIComponent;export function embedOf(i){let t;try{t=new URL(i.trim())}catch{return null}if(t.protocol!=="https:"&&t.protocol!=="http:")return null;const o=t.hostname.replace(/^www\./,"").replace(/^m\./,""),e=t.pathname.split("/").filter(Boolean);if(o==="youtube.com"||o==="youtu.be"||o==="youtube-nocookie.com"){const r=o==="youtu.be"?e[0]:t.searchParams.get("v")??(["shorts","embed","live"].includes(e[0]??"")?e[1]:void 0);return r&&s.test(r)?{src:`https://www.youtube-nocookie.com/embed/${r}`,provider:"YouTube",height:0,ratio:16/9}:null}if(o==="vimeo.com"||o==="player.vimeo.com"){const r=e.find(n=>/^\d{5,12}$/.test(n));return r?{src:`https://player.vimeo.com/video/${r}?dnt=1`,provider:"Vimeo",height:0,ratio:16/9}:null}if(o==="loom.com"&&(e[0]==="share"||e[0]==="embed")&&e[1]&&s.test(e[1]))return{src:`https://www.loom.com/embed/${e[1]}`,provider:"Loom",height:0,ratio:16/9};if(o==="docs.google.com"&&e[1]==="d"&&e[2]&&s.test(e[2])){const r=e[0];if(r==="document")return{src:`https://docs.google.com/document/d/${e[2]}/preview`,provider:"Google Docs",height:560};if(r==="spreadsheets")return{src:`https://docs.google.com/spreadsheets/d/${e[2]}/preview`,provider:"Google Sheets",height:480};if(r==="presentation")return{src:`https://docs.google.com/presentation/d/${e[2]}/embed`,provider:"Google Slides",height:0,ratio:16/9+.05};if(r==="forms")return{src:`https://docs.google.com/forms/d/${e[2]}/viewform?embedded=true`,provider:"Google Forms",height:640}}if((o==="google.com"||/^google\.[a-z.]{2,6}$/.test(o)||o==="maps.google.com")&&(e[0]==="maps"||o==="maps.google.com")){const r=e[0]==="maps"&&e[1]==="place"&&e[2]?decodeURIComponent(e[2]).replace(/\+/g," "):t.searchParams.get("q");return r?{src:`https://maps.google.com/maps?q=${c(r)}&output=embed`,provider:"Google Maps",height:380}:null}return o==="figma.com"&&["file","design","proto","board"].includes(e[0]??"")?{src:`https://www.figma.com/embed?embed_host=svgrid&url=${c(t.href)}`,provider:"Figma",height:450}:o==="miro.com"&&e[0]==="app"&&e[1]==="board"&&e[2]?{src:`https://miro.com/app/live-embed/${c(e[2])}/`,provider:"Miro",height:450}:o==="open.spotify.com"&&["track","album","playlist","episode","show"].includes(e[0]??"")&&e[1]&&s.test(e[1])?{src:`https://open.spotify.com/embed/${e[0]}/${e[1]}`,provider:"Spotify",height:e[0]==="track"||e[0]==="episode"?152:352}:o==="calendly.com"&&e[0]?{src:`https://calendly.com/${e.map(c).join("/")}?hide_gdpr_banner=1`,provider:"Calendly",height:640}:null}export function embedFrame(i,t){const o=document.createElement("iframe");return o.src=i.src,o.title=t||i.provider,o.loading="lazy",o.referrerPolicy="strict-origin-when-cross-origin",o.setAttribute("sandbox","allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox allow-presentation allow-forms"),o.setAttribute("allow","fullscreen; picture-in-picture; encrypted-media; clipboard-write"),o.allowFullscreen=!0,o.className="sv-embed-frame",i.ratio?o.style.aspectRatio=String(i.ratio):o.style.height=`${i.height}px`,o}export function frameEmbeds(i){for(const t of Array.from(i.querySelectorAll(".sv-embed > a[href]"))){const o=embedOf(t.getAttribute("href")??"");!o||t.parentElement?.querySelector("iframe")||(t.parentElement.insertBefore(embedFrame(o,t.textContent??""),t),t.classList.add("sv-embed-link"))}}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The page editor's engine (records as pages): ProseMirror with the page's
|
|
3
|
+
* blocks (page-schema.ts), its keys, Markdown as you type, the "/" menu's
|
|
4
|
+
* state, Turn into, colours, to-dos that tick, toggles that fold, and the
|
|
5
|
+
* block under the pointer for the drag handle. No Svelte here: PageEditor.svelte
|
|
6
|
+
* draws the menus over it.
|
|
7
|
+
*
|
|
8
|
+
* ProseMirror is an optional peer: `loadPageEditor()` imports it on first use
|
|
9
|
+
* and answers null when the app has not installed it, so the page falls back
|
|
10
|
+
* to the rich text field's own editor.
|
|
11
|
+
*/
|
|
12
|
+
import type * as PMModel from 'prosemirror-model';
|
|
13
|
+
import type * as PMState from 'prosemirror-state';
|
|
14
|
+
import type * as PMView from 'prosemirror-view';
|
|
15
|
+
import { type PageColor } from './page-schema.js';
|
|
16
|
+
export type PM = {
|
|
17
|
+
model: typeof PMModel;
|
|
18
|
+
state: typeof PMState;
|
|
19
|
+
view: typeof PMView;
|
|
20
|
+
transform: typeof import('prosemirror-transform');
|
|
21
|
+
commands: typeof import('prosemirror-commands');
|
|
22
|
+
keymap: typeof import('prosemirror-keymap');
|
|
23
|
+
history: typeof import('prosemirror-history');
|
|
24
|
+
inputrules: typeof import('prosemirror-inputrules');
|
|
25
|
+
lists: typeof import('prosemirror-schema-list');
|
|
26
|
+
dropcursor: typeof import('prosemirror-dropcursor');
|
|
27
|
+
gapcursor: typeof import('prosemirror-gapcursor');
|
|
28
|
+
};
|
|
29
|
+
/** ProseMirror, once; null when the app has not installed it. */
|
|
30
|
+
export declare function loadPageEditor(): Promise<PM | null>;
|
|
31
|
+
/** A file the host stored for the page (into its files field): where it is served, its name and size. */
|
|
32
|
+
export type PageFile = {
|
|
33
|
+
url: string;
|
|
34
|
+
name: string;
|
|
35
|
+
size?: number;
|
|
36
|
+
type?: string;
|
|
37
|
+
};
|
|
38
|
+
/** A link's bookmark: its title, description and site, read by the host's server. */
|
|
39
|
+
export type LinkCard = {
|
|
40
|
+
title: string;
|
|
41
|
+
description: string;
|
|
42
|
+
site: string;
|
|
43
|
+
};
|
|
44
|
+
/** A record a page links to (a sub-page, an @ mention): its id, its name and its icon. */
|
|
45
|
+
export type PageRecord = {
|
|
46
|
+
id: string;
|
|
47
|
+
title: string;
|
|
48
|
+
icon?: string;
|
|
49
|
+
};
|
|
50
|
+
/** What the host knows of the table's records, for sub-pages and mentions. */
|
|
51
|
+
export type PageRecords = {
|
|
52
|
+
/** Records whose name has these words, for the @ menu (a few). */
|
|
53
|
+
find(query: string): PageRecord[];
|
|
54
|
+
/** A record by id, with its name now (a link shows the name the record has, not the one it had). */
|
|
55
|
+
get(id: string): PageRecord | null;
|
|
56
|
+
/** Open that record (as a page, in the same window). */
|
|
57
|
+
open(id: string): void;
|
|
58
|
+
/** A new record under this one (its sub-page); null when one cannot be made. */
|
|
59
|
+
makeSubpage(): Promise<PageRecord | null>;
|
|
60
|
+
};
|
|
61
|
+
/** What the "/" menu is asked for: the text typed after the slash, and where it sits. */
|
|
62
|
+
export type SlashState = {
|
|
63
|
+
from: number;
|
|
64
|
+
to: number;
|
|
65
|
+
query: string;
|
|
66
|
+
} | null;
|
|
67
|
+
/** A kind of block the "/" menu and Turn into make. */
|
|
68
|
+
export type BlockKind = 'text' | 'h1' | 'h2' | 'h3' | 'bullet' | 'numbered' | 'todo' | 'toggle' | 'toggleH1' | 'toggleH2' | 'toggleH3' | 'quote' | 'callout' | 'divider' | 'code' | 'columns2' | 'columns3' | 'toc';
|
|
69
|
+
export type PageEditor = {
|
|
70
|
+
view: PMView.EditorView;
|
|
71
|
+
/** The page as the field keeps it. */
|
|
72
|
+
html(): string;
|
|
73
|
+
/** Put other HTML in (a change from elsewhere), keeping the place of the caret when it can. */
|
|
74
|
+
setHtml(html: string): void;
|
|
75
|
+
setEditable(on: boolean): void;
|
|
76
|
+
/** Close the "/" menu, leaving what was typed. */
|
|
77
|
+
closeSlash(): void;
|
|
78
|
+
/** Files given to the page (pasted, dropped, picked): stored by the host, then a picture or a file block each. */
|
|
79
|
+
insertFiles(files: File[], range?: {
|
|
80
|
+
from: number;
|
|
81
|
+
to: number;
|
|
82
|
+
}): Promise<void>;
|
|
83
|
+
/** A link shown inside the page (embed-url.ts), or as a link when its site is not one that can be. */
|
|
84
|
+
insertEmbed(href: string, range?: {
|
|
85
|
+
from: number;
|
|
86
|
+
to: number;
|
|
87
|
+
}): void;
|
|
88
|
+
/** A link as a card with its title and description. */
|
|
89
|
+
insertBookmark(href: string, card: LinkCard, range?: {
|
|
90
|
+
from: number;
|
|
91
|
+
to: number;
|
|
92
|
+
}): void;
|
|
93
|
+
/** A new sub-page (a record under this one), linked where the "/" was. */
|
|
94
|
+
insertSubpage(range: {
|
|
95
|
+
from: number;
|
|
96
|
+
to: number;
|
|
97
|
+
}): Promise<void>;
|
|
98
|
+
/** A record named where the "@" was. */
|
|
99
|
+
insertMention(record: PageRecord, range: {
|
|
100
|
+
from: number;
|
|
101
|
+
to: number;
|
|
102
|
+
}): void;
|
|
103
|
+
/** Close the @ menu, leaving what was typed. */
|
|
104
|
+
closeMention(): void;
|
|
105
|
+
/** Draw the record links again (a record was renamed). */
|
|
106
|
+
refreshRecords(): void;
|
|
107
|
+
/** Replace the "/" and what was typed after it with a block of that kind. */
|
|
108
|
+
insertBlock(kind: BlockKind, range: {
|
|
109
|
+
from: number;
|
|
110
|
+
to: number;
|
|
111
|
+
}): void;
|
|
112
|
+
/** Turn the block at `pos` into another kind, keeping its words. */
|
|
113
|
+
turnInto(pos: number, kind: BlockKind): void;
|
|
114
|
+
setBlockColor(pos: number, color: PageColor | null): void;
|
|
115
|
+
duplicateBlock(pos: number): void;
|
|
116
|
+
deleteBlock(pos: number): void;
|
|
117
|
+
/** A text block under the block at `pos`, with "/" typed to open the menu. */
|
|
118
|
+
addBelow(pos: number, slash?: boolean): void;
|
|
119
|
+
/** The block a pointer at (x, y) is over: its position and its DOM, for the drag handle. */
|
|
120
|
+
blockAt(x: number, y: number): {
|
|
121
|
+
pos: number;
|
|
122
|
+
dom: HTMLElement;
|
|
123
|
+
} | null;
|
|
124
|
+
/** Start dragging the block at `pos` (the drag handle's dragstart). */
|
|
125
|
+
dragBlock(pos: number, e: DragEvent): void;
|
|
126
|
+
toggleMark(mark: 'strong' | 'em' | 'underline' | 'strike' | 'code'): void;
|
|
127
|
+
setLink(href: string | null): void;
|
|
128
|
+
setTextColor(color: PageColor | null, highlight?: boolean): void;
|
|
129
|
+
/** Which marks the selection has, for the bar over it. */
|
|
130
|
+
marksHere(): Set<string>;
|
|
131
|
+
destroy(): void;
|
|
132
|
+
};
|
|
133
|
+
export type PageEditorOptions = {
|
|
134
|
+
html: string;
|
|
135
|
+
editable: boolean;
|
|
136
|
+
/** The page's words changed (each edit; the caller waits for a pause before saving). */
|
|
137
|
+
onChange: (html: string) => void;
|
|
138
|
+
/** The "/" menu: what is typed after the slash, or null when it closes. */
|
|
139
|
+
onSlash: (s: SlashState) => void;
|
|
140
|
+
/** The selection changed (the bar over selected text follows it). */
|
|
141
|
+
onSelection?: () => void;
|
|
142
|
+
/** A heading's placeholder and the empty line's ("Type / for blocks"). */
|
|
143
|
+
placeholder: string;
|
|
144
|
+
/** Escape with no menu open: the record window may close. */
|
|
145
|
+
onEscape?: () => boolean;
|
|
146
|
+
/** Store a file given to the page; without it, files cannot be added. */
|
|
147
|
+
upload?: (file: File) => Promise<PageFile>;
|
|
148
|
+
/** The table's records, for sub-pages and @ mentions; without it neither is offered. */
|
|
149
|
+
records?: PageRecords;
|
|
150
|
+
/** The @ menu: what is typed after the "@", or null when it closes. */
|
|
151
|
+
onMention?: (s: SlashState) => void;
|
|
152
|
+
/** Files being stored, for "Uploading..." (0 when none). */
|
|
153
|
+
onUploading?: (count: number) => void;
|
|
154
|
+
/** A failed upload, for the host to say. */
|
|
155
|
+
onError?: (message: string) => void;
|
|
156
|
+
};
|
|
157
|
+
/** Markdown as a page's HTML: the grid's Markdown, with "- [ ]" lines as to-dos. */
|
|
158
|
+
export declare function markdownToPage(text: string): string;
|
|
159
|
+
export declare function createPageEditor(pm: PM, mount: HTMLElement, o: PageEditorOptions): PageEditor;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import{renderMarkdown as ut,sanitizeHtml as U}from"@svgrid/grid";import{pageSchema as pt,parsePage as j,serializePage as H}from"./page-schema.js";import{embedFrame as ft,embedOf as J}from"./embed-url.js";const mt=/^(?:#{1,6}\s|[-*+]\s|\d+\.\s|>\s?|```|---\s*$|- \[[ xX]\]\s)/m;let G=null;export function loadPageEditor(){return G??(G=Promise.all([import("prosemirror-model"),import("prosemirror-state"),import("prosemirror-view"),import("prosemirror-transform"),import("prosemirror-commands"),import("prosemirror-keymap"),import("prosemirror-history"),import("prosemirror-inputrules"),import("prosemirror-schema-list"),import("prosemirror-dropcursor"),import("prosemirror-gapcursor")]).then(([d,w,p,h,l,u,m,f,M,y,E])=>({model:d,state:w,view:p,transform:h,commands:l,keymap:u,history:m,inputrules:f,lists:M,dropcursor:y,gapcursor:E}),()=>null))}const gt=d=>d==null?"":d<1024?`${d} B`:d<1048576?`${Math.round(d/1024)} KB`:`${(d/1048576).toFixed(1)} MB`,ht=d=>(d.type??"").startsWith("image/")||/\.(png|jpe?g|gif|webp|avif)$/i.test(d.name??""),yt=new Set(["doc","column","toggle_body","callout","blockquote"]),I=new Set(["list_item","todo_item"]);export function markdownToPage(d){const w=[];d=d.replace(/^```([a-z0-9+#-]*)[ \t]*\r?\n([\s\S]*?)\r?\n```[ \t]*$/gim,(u,m,f)=>(w.push({lang:m.toLowerCase(),code:f}),`SVPAGECODE${w.length-1}`));const p=u=>u.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">"),h=ut(d.replace(/^(\s*)[-*+] \[([ xX])\] /gm,(u,m,f)=>`${m}- ${f.trim()?"☑":"☐"} `)),l=document.createElement("div");l.innerHTML=U(h);for(const u of Array.from(l.querySelectorAll("ul"))){const m=Array.from(u.children);if(!(!m.length||!m.every(f=>/^[\u2610\u2611]\s?/.test(f.textContent??"")))){u.className="sv-todo";for(const f of m){(f.textContent??"").startsWith("☑")&&(f.className="sv-done");const E=document.createTreeWalker(f,NodeFilter.SHOW_TEXT).nextNode();E&&(E.data=E.data.replace(/^[\u2610\u2611]\s?/,""))}}}for(const u of Array.from(l.querySelectorAll("p"))){const m=/^SVPAGECODE(\d+)$/.exec((u.textContent??"").trim()),f=m?w[Number(m[1])]:void 0;if(!f)continue;const M=document.createElement("pre");M.innerHTML=`<code${f.lang?` class="language-${p(f.lang)}"`:""}>${p(f.code)}</code>`,u.replaceWith(M)}for(const u of Array.from(l.querySelectorAll("p"))){if(!/^>\s?/.test(u.textContent??""))continue;const m=u.previousElementSibling,f=m?.tagName==="BLOCKQUOTE"?m:document.createElement("blockquote");f!==m&&u.before(f);const y=document.createTreeWalker(u,NodeFilter.SHOW_TEXT).nextNode();y&&(y.data=y.data.replace(/^>\s?/,"")),f.appendChild(u)}return l.innerHTML}export function createPageEditor(d,w,p){const h=pt(d.model),l=h.nodes,u=h.marks,{Plugin:m,PluginKey:f,EditorState:M,TextSelection:y,NodeSelection:E}=d.state,{Decoration:Q,DecorationSet:Y,EditorView:Z}=d.view,{InputRule:W,inputRules:tt,wrappingInputRule:$,textblockTypeInputRule:V}=d.inputrules,{splitListItem:et,liftListItem:q,sinkListItem:nt,wrapInList:vt}=d.lists,v=d.commands,b=new f("page-slash");let T=null;const rt=new m({key:b,state:{init:()=>null,apply(t,e,o,r){const n=t.getMeta(b);if(n==="close")return null;if(n)return n;if(!e)return null;const a=r.selection;if(!a.empty)return null;const i=t.mapping.map(e.from);if(a.from<=i)return null;const c=r.doc.textBetween(i,a.from,`
|
|
2
|
+
`,`
|
|
3
|
+
`);return!c.startsWith("/")||/\s{2}|\n/.test(c)||c.length>30?null:{from:i,to:a.from,query:c.slice(1)}}},props:{handleTextInput(t,e,o,r){if(r!=="/")return!1;const n=t.state.doc.resolve(e),a=n.parent.textBetween(Math.max(0,n.parentOffset-1),n.parentOffset,`
|
|
4
|
+
`,`
|
|
5
|
+
`);if(a&&!/\s/.test(a)||n.parent.type.spec.code)return!1;const i=t.state.tr.insertText("/",e,o);return i.setMeta(b,{from:e,to:e+1,query:""}),t.dispatch(i),!0}}}),S=new f("page-mention");let N=null;const ot=new m({key:S,state:{init:()=>null,apply(t,e,o,r){const n=t.getMeta(S);if(n==="close")return null;if(n)return n;if(!e)return null;const a=r.selection;if(!a.empty)return null;const i=t.mapping.map(e.from);if(a.from<=i)return null;const c=r.doc.textBetween(i,a.from,`
|
|
6
|
+
`,`
|
|
7
|
+
`);return!c.startsWith("@")||/\s{2}|\n/.test(c)||c.length>40?null:{from:i,to:a.from,query:c.slice(1)}}},props:{handleTextInput(t,e,o,r){if(r!=="@"||!p.records)return!1;const n=t.state.doc.resolve(e),a=n.parent.textBetween(Math.max(0,n.parentOffset-1),n.parentOffset,`
|
|
8
|
+
`,`
|
|
9
|
+
`);if(a&&!/\s/.test(a)||n.parent.type.spec.code)return!1;const i=t.state.tr.insertText("@",e,o);return i.setMeta(S,{from:e,to:e+1,query:""}),t.dispatch(i),!0}}}),st=new m({props:{decorations(t){const{$from:e,empty:o}=t.selection;if(!o)return null;const r=e.parent;if(!r.isTextblock||r.content.size>0||r.type.spec.code)return null;const n=r.type===l.heading?`Heading ${r.attrs.level}`:r.type===l.toggle_title?"Toggle":p.placeholder;return Y.create(t.doc,[Q.node(e.before(),e.after(),{class:"is-empty","data-placeholder":n})])}}}),at=tt({rules:[V(/^(#{1,3})\s$/,l.heading,t=>({level:t[1].length})),$(/^\s*>\s$/,l.blockquote),$(/^\s*([-+*])\s$/,l.bullet_list),$(/^(\d+)\.\s$/,l.ordered_list,t=>({order:+t[1]}),(t,e)=>e.childCount+e.attrs.order===+t[1]),$(/^\s*\[([ xX]?)\]\s$/,l.todo_list),V(/^```([a-z0-9-]*)\s$/i,l.code_block,t=>({language:t[1]??""})),new W(/^---$/,(t,e,o,r)=>{const n=t.doc.resolve(o);return n.parent.type!==l.paragraph||n.parent.content.size!==3?null:t.tr.replaceRangeWith(n.before(),n.after(),l.horizontal_rule.create()).scrollIntoView()}),A(/\*\*([^*]+)\*\*$/,u.strong),A(/(?<![*\w])\*([^*\s][^*]*)\*$/,u.em),A(/~~([^~]+)~~$/,u.strike),A(/`([^`]+)`$/,u.code)]});function A(t,e){return new W(t,(o,r,n,a)=>{const i=r[1];return o.tr.replaceWith(n,a,h.text(i,[e.create()])).removeStoredMark(e)})}const _=t=>{const{$from:e}=t.selection;for(let o=e.depth;o>0;o--)if(I.has(e.node(o).type.name))return e.node(o).type;return null},ct=d.keymap.keymap({"Mod-z":d.history.undo,"Shift-Mod-z":d.history.redo,"Mod-y":d.history.redo,"Mod-b":v.toggleMark(u.strong),"Mod-i":v.toggleMark(u.em),"Mod-u":v.toggleMark(u.underline),"Mod-Shift-s":v.toggleMark(u.strike),"Mod-e":v.toggleMark(u.code),Enter:(t,e)=>{const o=_(t);if(o&&et(o)(t,e))return!0;const{$from:r,empty:n}=t.selection;if(n&&r.parent.type===l.toggle_title&&r.parentOffset===r.parent.content.size){const a=r.after();if(e){const i=t.tr.insert(a+1,l.paragraph.create());i.setSelection(y.create(i.doc,a+2));const c=r.node(r.depth-1);c.attrs.open||i.setNodeMarkup(r.before(r.depth-1),void 0,{...c.attrs,open:!0}),e(i.scrollIntoView())}return!0}return!1},"Shift-Enter":(t,e)=>(e&&e(t.tr.replaceSelectionWith(l.hard_break.create()).scrollIntoView()),!0),Tab:(t,e)=>{const o=_(t);return o?nt(o)(t,e):!0},"Shift-Tab":(t,e)=>{const o=_(t);return o?q(o)(t,e):!0},Backspace:(t,e)=>{const{$from:o,empty:r}=t.selection;if(!r||o.parentOffset>0)return!1;const n=_(t);return n&&q(n)(t,e)?!0:o.parent.type===l.heading||o.parent.type===l.code_block?v.setBlockType(l.paragraph)(t,e):v.lift(t,e)},"Mod-Enter":(t,e)=>{const{$from:o}=t.selection;for(let r=o.depth;r>0;r--){const n=o.node(r);if(n.type===l.todo_item)return e&&e(t.tr.setNodeMarkup(o.before(r),void 0,{...n.attrs,done:!n.attrs.done})),!0}return!1},Escape:()=>T?(s.dispatch(s.state.tr.setMeta(b,"close")),!0):N?(s.dispatch(s.state.tr.setMeta(S,"close")),!0):p.onEscape?.()??!1}),it={todo_item:(t,e,o)=>{const r=document.createElement("li");r.className=t.attrs.done?"sv-done":"";const n=document.createElement("input");n.type="checkbox",n.className="sv-todo-box",n.checked=!!t.attrs.done,n.contentEditable="false",n.setAttribute("aria-label",t.attrs.done?"Done":"To do"),n.addEventListener("mousedown",i=>i.preventDefault()),n.addEventListener("change",()=>{const i=o();if(i==null||!e.editable)return void(n.checked=!!t.attrs.done);e.dispatch(e.state.tr.setNodeMarkup(i,void 0,{...t.attrs,done:n.checked}))});const a=document.createElement("div");return a.className="sv-todo-text",r.append(n,a),{dom:r,contentDOM:a,update(i){return i.type!==t.type?!1:(t=i,r.className=i.attrs.done?"sv-done":"",n.checked=!!i.attrs.done,n.setAttribute("aria-label",i.attrs.done?"Done":"To do"),!0)},ignoreMutation:i=>i.target===n||i.type==="attributes"&&i.target===r}},toggle:(t,e,o)=>{const r=document.createElement("div"),n=document.createElement("button");n.type="button",n.className="sv-toggle-arrow",n.contentEditable="false";const a=c=>{r.className=["sv-toggle",c.attrs.open?"sv-open":"",c.attrs.color?`sv-c-${c.attrs.color}`:""].filter(Boolean).join(" "),n.setAttribute("aria-expanded",String(!!c.attrs.open)),n.setAttribute("aria-label",c.attrs.open?"Fold":"Unfold")};a(t),n.addEventListener("mousedown",c=>c.preventDefault()),n.addEventListener("click",()=>{const c=o();c!=null&&e.dispatch(e.state.tr.setNodeMarkup(c,void 0,{...t.attrs,open:!t.attrs.open}))});const i=document.createElement("div");return i.className="sv-toggle-inner",r.append(n,i),{dom:r,contentDOM:i,update(c){return c.type!==t.type?!1:(t=c,a(c),!0)},ignoreMutation:c=>c.target===n||c.type==="attributes"&&c.target===r}},image:(t,e,o)=>{const r=document.createElement("div");r.className="sv-page-image";const n=document.createElement("img"),a=document.createElement("span");a.className="sv-page-image-grip",a.setAttribute("aria-hidden","true");const i=c=>{n.src=c.attrs.src,n.alt=c.attrs.alt??"",n.style.width=c.attrs.width?`${c.attrs.width}px`:""};return i(t),a.addEventListener("pointerdown",c=>{if(!e.editable)return;c.preventDefault();const g=c.clientX,k=n.getBoundingClientRect().width,dt=(r.parentElement?.getBoundingClientRect().width??2e3)||2e3,F=L=>n.style.width=`${Math.round(Math.max(80,Math.min(dt,k+L.clientX-g)))}px`,X=()=>{window.removeEventListener("pointermove",F),window.removeEventListener("pointerup",X);const L=o(),K=Math.round(n.getBoundingClientRect().width);L!=null&&K>0&&e.dispatch(e.state.tr.setNodeMarkup(L,void 0,{...t.attrs,width:K}))};window.addEventListener("pointermove",F),window.addEventListener("pointerup",X)}),r.append(n,a),{dom:r,update(c){return c.type!==t.type?!1:(t=c,i(c),!0)},stopEvent:c=>c.target===a,ignoreMutation:()=>!0}},embed:t=>{const e=document.createElement("div");e.className="sv-embed";const o=J(t.attrs.href),r=document.createElement("a");return r.href=t.attrs.href,r.target="_blank",r.rel="noopener noreferrer",r.textContent=o?o.provider:t.attrs.href,r.className="sv-embed-link",o&&e.append(ft(o,t.attrs.href)),e.append(r),{dom:e,ignoreMutation:()=>!0,stopEvent:n=>n.target instanceof HTMLIFrameElement}},subpage:t=>{const e=document.createElement("p");e.className="sv-subpage";const o=document.createElement("a");o.href=`#svrec:${t.attrs.id}`;const r=n=>{const a=p.records?.get(n.attrs.id);o.textContent=`${a?.icon||"📄"} ${a?.title||n.attrs.title||"Untitled"}`,o.dataset.svrec=n.attrs.id};return r(t),o.addEventListener("click",n=>{n.preventDefault(),p.records?.open(t.attrs.id)}),e.append(o),{dom:e,update(n){return n.type!==t.type?!1:(t=n,r(n),!0)},ignoreMutation:()=>!0}},mention:t=>{const e=document.createElement("a");e.className="sv-mention",e.href=`#svrec:${t.attrs.id}`;const o=r=>{const n=p.records?.get(r.attrs.id);e.textContent=n?.title||r.attrs.title||"Untitled",e.dataset.svrec=r.attrs.id};return o(t),e.addEventListener("click",r=>{r.preventDefault(),p.records?.open(t.attrs.id)}),{dom:e,update(r){return r.type!==t.type?!1:(t=r,o(r),!0)},ignoreMutation:()=>!0}},toc:()=>{const t=document.createElement("div");return t.className="sv-toc",t.contentEditable="false",{dom:t,update:e=>e.type===l.toc,ignoreMutation:()=>!0}},callout:(t,e,o)=>{const r=document.createElement("div"),n=document.createElement("button");n.type="button",n.className="sv-callout-icon",n.contentEditable="false";const a=c=>{r.className=["sv-callout",`sv-c-${c.attrs.color??"gray"}`].join(" "),n.textContent=c.attrs.icon};a(t),n.addEventListener("mousedown",c=>c.preventDefault()),n.addEventListener("click",()=>{const c=o();if(c==null||!e.editable)return;const g=["💡","⚠️","✅","📌","❗","ℹ️","🔥","🗒️"],k=g[(g.indexOf(t.attrs.icon)+1)%g.length];e.dispatch(e.state.tr.setNodeMarkup(c,void 0,{...t.attrs,icon:k}))});const i=document.createElement("div");return i.className="sv-callout-body",r.append(n,i),{dom:r,contentDOM:i,update(c){return c.type!==t.type?!1:(t=c,a(c),!0)},ignoreMutation:c=>c.target===n||n.contains(c.target)||c.type==="attributes"&&c.target===r}}},P=M.create({doc:j(d.model,h,p.html),plugins:[rt,ot,at,ct,d.keymap.keymap(v.baseKeymap),d.history.history(),d.dropcursor.dropCursor({color:"var(--sg-accent, #2563eb)",width:3}),d.gapcursor.gapCursor(),st]});let C=H(d.model,P.doc),x=p.editable;const s=new Z(w,{state:P,nodeViews:it,editable:()=>x,attributes:{class:"sv-page-doc",role:"textbox","aria-multiline":"true"},handlePaste(t,e){const o=Array.from(e.clipboardData?.files??[]);return!o.length||!p.upload||!x?!1:(B.insertFiles(o),!0)},handleDrop(t,e,o,r){const n=Array.from(e.dataTransfer?.files??[]);if(r||!n.length||!p.upload||!x)return!1;const a=t.posAtCoords({left:e.clientX,top:e.clientY});return a&&t.dispatch(t.state.tr.setSelection(y.near(t.state.doc.resolve(a.pos)))),e.preventDefault(),B.insertFiles(n),!0},clipboardTextParser(t,e){const o=mt.test(t)?markdownToPage(t):t.split(/\r?\n/).map(n=>`<p>${n.replace(/&/g,"&").replace(/</g,"<")}</p>`).join(""),r=document.createElement("div");return r.innerHTML=U(o),d.model.DOMParser.fromSchema(h).parseSlice(r,{preserveWhitespace:!0,context:e})},dispatchTransaction(t){const e=s.state.apply(t);s.updateState(e);const o=b.getState(e)??null;JSON.stringify(o)!==JSON.stringify(T)&&(T=o,p.onSlash(o));const r=S.getState(e)??null;if(JSON.stringify(r)!==JSON.stringify(N)&&(N=r,p.onMention?.(r)),t.docChanged&&R(),t.docChanged){const n=H(d.model,e.doc);n!==C&&(C=n,p.onChange(n))}(t.selectionSet||t.docChanged)&&p.onSelection?.()}});function O(t,e){const o=n=>l.paragraph.create(null,n),r=e??void 0;switch(t){case"h1":case"h2":case"h3":return l.heading.create({level:Number(t[1])},r);case"bullet":return l.bullet_list.create(null,l.list_item.create(null,o(r)));case"numbered":return l.ordered_list.create(null,l.list_item.create(null,o(r)));case"todo":return l.todo_list.create(null,l.todo_item.create(null,o(r)));case"toggle":case"toggleH1":case"toggleH2":case"toggleH3":return l.toggle.create({open:!0},[l.toggle_title.create({level:t==="toggle"?0:Number(t.slice(-1))},r),l.toggle_body.create()]);case"quote":return l.blockquote.create(null,o(r));case"callout":return l.callout.create({icon:"💡",color:"gray"},o(r));case"divider":return l.horizontal_rule.create();case"code":{const n=r?r.textBetween(0,r.size,`
|
|
10
|
+
`):"";return l.code_block.create(null,n?h.text(n):void 0)}case"toc":return l.toc.create();case"columns2":case"columns3":{const n=t==="columns2"?2:3;return l.columns.create(null,Array.from({length:n},(a,i)=>l.column.create(null,o(i===0?r:void 0))))}default:return o(r)}}function D(t,e){const o=t.doc.resolve(Math.min(e+1,t.doc.content.size)),r=y.findFrom(o,1,!0);r&&t.setSelection(r)}function lt(t){let e;return t.descendants(o=>e?!1:o.isTextblock?(e=o.content,!1):!0),t.isTextblock&&(e=t.content),e}function R(){const t=s?.dom?Array.from(s.dom.querySelectorAll(".sv-toc")):[];if(!t.length)return;const e=[];s.state.doc.descendants((o,r)=>(o.type===l.heading&&e.push({level:o.attrs.level,text:o.textContent,pos:r}),!o.isTextblock));for(const o of t)o.replaceChildren(...e.map(r=>{const n=document.createElement("a");return n.href="#",n.className=`sv-toc-l${r.level}`,n.textContent=r.text||`Heading ${r.level}`,n.addEventListener("mousedown",a=>a.preventDefault()),n.addEventListener("click",a=>{a.preventDefault();const i=s.nodeDOM(r.pos);i instanceof HTMLElement&&i.scrollIntoView({block:"start",behavior:"smooth"})}),n}))}function z(t){const e=s.state.doc.resolve(t.from),o=e.parent.isTextblock&&e.parent.content.size===t.to-t.from&&e.depth>=1,r=s.state.tr.delete(t.from,t.to).setMeta(b,"close");if(o){const n=r.mapping.map(e.before());return r.delete(n,n+r.doc.resolve(n).nodeAfter.nodeSize),s.dispatch(r),n}return s.dispatch(r),s.state.doc.resolve(Math.min(t.from,s.state.doc.content.size)).after(1)}const B={view:s,html:()=>H(d.model,s.state.doc),setHtml(t){if(t===C)return;const e=j(d.model,h,t),o=Math.min(s.state.selection.from,e.content.size),r=s.state.tr.replaceWith(0,s.state.doc.content.size,e.content).setMeta("addToHistory",!1);r.setSelection(y.near(r.doc.resolve(Math.max(0,Math.min(o,r.doc.content.size))))),C=t,s.dispatch(r)},setEditable(t){x=t,s.setProps({editable:()=>x})},closeSlash(){T&&s.dispatch(s.state.tr.setMeta(b,"close"))},async insertFiles(t,e){if(!p.upload||!t.length)return;let o=e?z(e):s.state.selection.from,r=t.length;p.onUploading?.(r);for(const n of t)try{const a=await p.upload(n),i=ht({type:a.type??n.type,name:a.name})?l.image.create({src:a.url,alt:a.name??n.name}):l.file.create({href:a.url,name:a.name||n.name,size:gt(a.size??n.size)});o=Math.min(o,s.state.doc.content.size);const c=s.state.tr.insert(o,i);o+=i.nodeSize,s.dispatch(c.scrollIntoView())}catch(a){p.onError?.(a instanceof Error?a.message:String(a))}finally{p.onUploading?.(r-=1)}},insertEmbed(t,e){const o=e?z(e):s.state.selection.from;s.dispatch(s.state.tr.insert(o,J(t)?l.embed.create({href:t}):l.paragraph.create(null,h.text(t,[u.link.create({href:t})]))).scrollIntoView()),s.focus()},insertBookmark(t,e,o){const r=o?z(o):s.state.selection.from;s.dispatch(s.state.tr.insert(r,l.bookmark.create({href:t,title:e.title||t,description:e.description,site:e.site})).scrollIntoView()),s.focus()},async insertSubpage(t){if(!p.records)return;const e=await p.records.makeSubpage();if(!e)return;const o=z(t);s.dispatch(s.state.tr.insert(Math.min(o,s.state.doc.content.size),l.subpage.create({id:e.id,title:e.title})).scrollIntoView())},insertMention(t,e){const o=s.state.tr.replaceWith(e.from,e.to,[l.mention.create({id:t.id,title:t.title}),h.text(" ")]).setMeta(S,"close");s.dispatch(o),s.focus()},closeMention(){N&&s.dispatch(s.state.tr.setMeta(S,"close"))},refreshRecords(){s.dispatch(s.state.tr.setMeta("refresh",!0));for(const t of Array.from(s.dom.querySelectorAll("[data-svrec]"))){const e=p.records?.get(t.dataset.svrec);e&&(t.textContent=t.classList.contains("sv-mention")?e.title:`${e.icon||"📄"} ${e.title}`)}},insertBlock(t,e){const o=s.state,r=o.doc.resolve(e.from),n=o.tr.delete(e.from,e.to).setMeta(b,"close"),a=r.parent,i=a.isTextblock&&a.content.size===e.to-e.from,c=n.mapping.map(r.before());if(i&&r.depth>=1){const g=O(t);n.replaceWith(c,c+n.doc.resolve(c).nodeAfter.nodeSize,g),t==="divider"&&n.insert(c+g.nodeSize,l.paragraph.create()),D(n,c)}else{const g=n.mapping.map(r.after()),k=O(t);n.insert(g,k),D(n,g)}s.dispatch(n.scrollIntoView()),s.focus()},turnInto(t,e){const o=s.state,r=o.doc.nodeAt(t);if(!r||e==="divider")return;const n=I.has(r.type.name)?o.doc.resolve(t).parent:r,a=I.has(r.type.name)?o.doc.resolve(t).before():t,i=O(e,lt(n)),c=o.tr.replaceWith(a,a+n.nodeSize,i);D(c,a),s.dispatch(c.scrollIntoView()),s.focus()},setBlockColor(t,e){const o=s.state.doc.nodeAt(t);!o||!("color"in o.attrs)||s.dispatch(s.state.tr.setNodeMarkup(t,void 0,{...o.attrs,color:e??(o.type===l.callout?"gray":null)}))},duplicateBlock(t){const e=s.state.doc.nodeAt(t);e&&s.dispatch(s.state.tr.insert(t+e.nodeSize,e.copy(e.content)).scrollIntoView())},deleteBlock(t){const e=s.state.doc.nodeAt(t);if(!e)return;const o=s.state.tr.delete(t,t+e.nodeSize);o.doc.childCount===0&&o.insert(0,l.paragraph.create()),s.dispatch(o.scrollIntoView()),s.focus()},addBelow(t,e=!0){const o=s.state.doc.nodeAt(t);if(!o)return;const r=t+o.nodeSize,n=s.state.tr.insert(r,l.paragraph.create());if(n.setSelection(y.create(n.doc,r+1)),s.dispatch(n.scrollIntoView()),s.focus(),e){const a=s.state.tr.insertText("/",r+1);a.setMeta(b,{from:r+1,to:r+2,query:""}),s.dispatch(a)}},blockAt(t,e){const o=s.posAtCoords({left:t,top:e});if(!o)return null;const r=s.state.doc;if(o.inside>=0){const a=r.nodeAt(o.inside),i=s.nodeDOM(o.inside);if(a&&a.isBlock&&a.isAtom&&i instanceof HTMLElement)return{pos:o.inside,dom:i}}const n=r.resolve(o.pos);for(let a=n.depth;a>=1;a--){const i=n.node(a),c=n.node(a-1);if(I.has(i.type.name)||yt.has(c.type.name)&&i.type!==l.column){const g=n.before(a),k=s.nodeDOM(g);if(k instanceof HTMLElement)return{pos:g,dom:k}}}return null},dragBlock(t,e){const o=E.create(s.state.doc,t);s.dispatch(s.state.tr.setSelection(o));const r=o.content();s.dragging={slice:r,move:!0};const n=s.nodeDOM(t);e.dataTransfer&&(e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/plain",o.node.textContent),n instanceof HTMLElement&&e.dataTransfer.setDragImage(n,0,0))},toggleMark(t){v.toggleMark(u[t])(s.state,s.dispatch),s.focus()},setLink(t){const{from:e,to:o,empty:r}=s.state.selection;if(r)return;const n=s.state.tr.removeMark(e,o,u.link);t&&n.addMark(e,o,u.link.create({href:t})),s.dispatch(n),s.focus()},setTextColor(t,e=!1){const{from:o,to:r,empty:n}=s.state.selection;if(n)return;const a=e?u.highlight:u.color,i=s.state.tr.removeMark(o,r,u.color).removeMark(o,r,u.highlight);t&&i.addMark(o,r,a.create({color:t})),s.dispatch(i),s.focus()},marksHere(){const{from:t,to:e,empty:o,$from:r}=s.state.selection,n=new Set;if(o)for(const a of s.state.storedMarks??r.marks())n.add(a.type.name);else s.state.doc.nodesBetween(t,e,a=>{a.marks.forEach(i=>n.add(i.type.name))});return n},destroy(){s.destroy()}};return R(),B}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The blocks of a page (records as pages, `BaseTable.page`) as a ProseMirror
|
|
3
|
+
* schema, and how each reads from and writes to the HTML a rich text field
|
|
4
|
+
* keeps. Every block is plain HTML marked by a class (the grid's sanitizer
|
|
5
|
+
* keeps `class` on every tag and nothing else new), so a reader that does
|
|
6
|
+
* not know blocks (an export, an e-mail, a cell) still shows all the words:
|
|
7
|
+
*
|
|
8
|
+
* to-do list <ul class="sv-todo"><li class="sv-done">...</li></ul>
|
|
9
|
+
* toggle <div class="sv-toggle sv-open"><p class="sv-toggle-title">...</p><div class="sv-toggle-body">...</div></div>
|
|
10
|
+
* callout <div class="sv-callout sv-c-blue"><span class="sv-callout-icon">💡</span><div class="sv-callout-body">...</div></div>
|
|
11
|
+
* columns <div class="sv-columns"><div class="sv-column">...</div>...</div>
|
|
12
|
+
* code <pre><code class="language-js">...</code></pre>
|
|
13
|
+
* file <p class="sv-file"><a href="...">name.pdf</a> <small>1.2 MB</small></p>
|
|
14
|
+
* embed <p class="sv-embed"><a href="https://youtu.be/...">https://youtu.be/...</a></p> (framed when shown, embed-url.ts)
|
|
15
|
+
* bookmark <div class="sv-bookmark"><a href="...">Title</a><p>Description</p><small>site</small></div>
|
|
16
|
+
* sub-page <p class="sv-subpage"><a href="#svrec:rec123">Title</a></p> (a record of the same table)
|
|
17
|
+
* mention <a class="sv-mention" href="#svrec:rec123">Title</a> (inline, any record of the table)
|
|
18
|
+
* contents <div class="sv-toc"></div> (the page's headings, listed when shown)
|
|
19
|
+
* colour <span class="sv-c-red">...</span>, highlight <mark class="sv-h-yellow">...</mark>
|
|
20
|
+
*
|
|
21
|
+
* ProseMirror is an optional peer of the package: this module is loaded only
|
|
22
|
+
* when a page is written in (`loadPageEditor`), and takes the library as an
|
|
23
|
+
* argument rather than importing it, so nothing of it lands in the grid's bundle.
|
|
24
|
+
*/
|
|
25
|
+
import type * as PMModel from 'prosemirror-model';
|
|
26
|
+
/** The colours a block or a piece of text can take, as Notion's. */
|
|
27
|
+
export declare const PAGE_COLORS: readonly ["gray", "brown", "orange", "yellow", "green", "blue", "purple", "pink", "red"];
|
|
28
|
+
export type PageColor = (typeof PAGE_COLORS)[number];
|
|
29
|
+
export declare function pageSchema(pm: typeof PMModel): PMModel.Schema;
|
|
30
|
+
/** The record a page's link names (`#svrec:<id>`), or null. */
|
|
31
|
+
export declare function recordIdOf(href: string | null | undefined): string | null;
|
|
32
|
+
/** The page's HTML as a document of this schema (what the field holds, cleaned by the caller). */
|
|
33
|
+
export declare function parsePage(pm: typeof PMModel, schema: PMModel.Schema, html: string): PMModel.Node;
|
|
34
|
+
/** The document as the HTML the field keeps. An empty page is ''. */
|
|
35
|
+
export declare function serializePage(pm: typeof PMModel, doc: PMModel.Node): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const PAGE_COLORS=["gray","brown","orange","yellow","green","blue","purple","pink","red"];const g=r=>!!r&&PAGE_COLORS.includes(r);function a(r,o){for(const t of Array.from(r.classList))if(t.startsWith(o)&&g(t.slice(o.length)))return t.slice(o.length);return null}const c=(r,o)=>r.classList.contains(o),l={color:{default:null}},n=r=>g(r)?`sv-c-${r}`:"",i=(...r)=>r.filter(Boolean).join(" ")||void 0;export function pageSchema(r){const{Schema:o}=r;return new o({nodes:{doc:{content:"block+"},paragraph:{group:"block",content:"inline*",attrs:{...l},parseDOM:[{tag:"p",getAttrs:t=>({color:a(t,"sv-c-")})},{tag:"div",priority:10,getAttrs:t=>p(t)?{color:a(t,"sv-c-")}:!1}],toDOM:t=>["p",{class:i(n(t.attrs.color))},0]},heading:{group:"block",content:"inline*",attrs:{level:{default:2},...l},defining:!0,parseDOM:[1,2,3].map(t=>({tag:`h${t}`,getAttrs:e=>({level:t,color:a(e,"sv-c-")})})).concat([4,5,6].map(t=>({tag:`h${t}`,getAttrs:e=>({level:3,color:a(e,"sv-c-")})}))),toDOM:t=>[`h${t.attrs.level}`,{class:i(n(t.attrs.color))},0]},blockquote:{group:"block",content:"block+",attrs:{...l},defining:!0,parseDOM:[{tag:"blockquote",getAttrs:t=>({color:a(t,"sv-c-")})}],toDOM:t=>["blockquote",{class:i(n(t.attrs.color))},0]},horizontal_rule:{group:"block",parseDOM:[{tag:"hr"}],toDOM:()=>["hr"]},code_block:{group:"block",content:"text*",marks:"",code:!0,defining:!0,attrs:{language:{default:""}},parseDOM:[{tag:"pre",preserveWhitespace:"full",getAttrs:t=>{const e=t.querySelector("code"),s=Array.from(e?.classList??[]).find(u=>u.startsWith("language-"));return{language:s?s.slice(9):""}}}],toDOM:t=>["pre",["code",{class:t.attrs.language?`language-${t.attrs.language}`:void 0},0]]},bullet_list:{group:"block",content:"list_item+",parseDOM:[{tag:"ul",getAttrs:t=>c(t,"sv-todo")?!1:null}],toDOM:()=>["ul",0]},ordered_list:{group:"block",content:"list_item+",attrs:{order:{default:1}},parseDOM:[{tag:"ol",getAttrs:t=>({order:Number(t.getAttribute("start")??1)||1})}],toDOM:t=>["ol",t.attrs.order===1?{}:{start:t.attrs.order},0]},list_item:{content:"paragraph block*",defining:!0,parseDOM:[{tag:"li",getAttrs:t=>t.parentElement&&c(t.parentElement,"sv-todo")?!1:null}],toDOM:()=>["li",0]},todo_list:{group:"block",content:"todo_item+",parseDOM:[{tag:"ul.sv-todo",priority:60}],toDOM:()=>["ul",{class:"sv-todo"},0]},todo_item:{content:"paragraph block*",defining:!0,attrs:{done:{default:!1}},parseDOM:[{tag:"ul.sv-todo > li",priority:60,getAttrs:t=>({done:c(t,"sv-done")})}],toDOM:t=>["li",{class:t.attrs.done?"sv-done":void 0},0]},toggle:{group:"block",content:"toggle_title toggle_body",attrs:{open:{default:!0},...l},defining:!0,parseDOM:[{tag:"div.sv-toggle",priority:60,getAttrs:t=>({open:c(t,"sv-open"),color:a(t,"sv-c-")})}],toDOM:t=>["div",{class:i("sv-toggle",t.attrs.open&&"sv-open",n(t.attrs.color))},0]},toggle_title:{content:"inline*",attrs:{level:{default:0}},defining:!0,parseDOM:[{tag:"p.sv-toggle-title",priority:60,getAttrs:()=>({level:0})},...[1,2,3].map(t=>({tag:`h${t}.sv-toggle-title`,priority:60,getAttrs:()=>({level:t})}))],toDOM:t=>[t.attrs.level?`h${t.attrs.level}`:"p",{class:"sv-toggle-title"},0]},toggle_body:{content:"block*",parseDOM:[{tag:"div.sv-toggle-body",priority:60}],toDOM:()=>["div",{class:"sv-toggle-body"},0]},callout:{group:"block",content:"block+",attrs:{icon:{default:"💡"},...l},defining:!0,parseDOM:[{tag:"div.sv-callout",priority:60,contentElement:".sv-callout-body",getAttrs:t=>({icon:t.querySelector(".sv-callout-icon")?.textContent?.trim()||"💡",color:a(t,"sv-c-")??"gray"})}],toDOM:t=>["div",{class:i("sv-callout",n(t.attrs.color??"gray"))},["span",{class:"sv-callout-icon"},t.attrs.icon],["div",{class:"sv-callout-body"},0]]},columns:{group:"block",content:"column column+",defining:!0,isolating:!0,parseDOM:[{tag:"div.sv-columns",priority:60}],toDOM:t=>["div",{class:`sv-columns sv-columns-${t.childCount}`},0]},column:{content:"block+",isolating:!0,parseDOM:[{tag:"div.sv-column",priority:60}],toDOM:()=>["div",{class:"sv-column"},0]},image:{group:"block",draggable:!0,attrs:{src:{},alt:{default:""},width:{default:null}},parseDOM:[{tag:"img[src]",getAttrs:t=>{const e=Number(t.getAttribute("width"));return{src:t.getAttribute("src"),alt:t.getAttribute("alt")??"",width:e>0?e:null}}}],toDOM:t=>["img",{src:t.attrs.src,alt:t.attrs.alt||void 0,width:t.attrs.width??void 0}]},file:{group:"block",atom:!0,draggable:!0,attrs:{href:{},name:{default:""},size:{default:""}},parseDOM:[{tag:"p.sv-file",priority:70,getAttrs:t=>{const e=t.querySelector("a");return e?{href:e.getAttribute("href"),name:e.textContent??"",size:t.querySelector("small")?.textContent??""}:!1}}],toDOM:t=>["p",{class:"sv-file"},["a",{href:t.attrs.href,target:"_blank",rel:"noopener noreferrer"},t.attrs.name||t.attrs.href],...t.attrs.size?[" ",["small",t.attrs.size]]:[]]},embed:{group:"block",atom:!0,draggable:!0,attrs:{href:{}},parseDOM:[{tag:"p.sv-embed",priority:70,getAttrs:t=>{const e=t.querySelector("a");return e?{href:e.getAttribute("href")}:!1}}],toDOM:t=>["p",{class:"sv-embed"},["a",{href:t.attrs.href,target:"_blank",rel:"noopener noreferrer"},t.attrs.href]]},bookmark:{group:"block",atom:!0,draggable:!0,attrs:{href:{},title:{default:""},description:{default:""},site:{default:""}},parseDOM:[{tag:"div.sv-bookmark",priority:70,getAttrs:t=>{const e=t,s=e.querySelector("a");return s?{href:s.getAttribute("href"),title:s.textContent??"",description:e.querySelector("p")?.textContent??"",site:e.querySelector("small")?.textContent??""}:!1}}],toDOM:t=>["div",{class:"sv-bookmark"},["a",{href:t.attrs.href,target:"_blank",rel:"noopener noreferrer"},t.attrs.title||t.attrs.href],...t.attrs.description?[["p",t.attrs.description]]:[],...t.attrs.site?[["small",t.attrs.site]]:[]]},subpage:{group:"block",atom:!0,draggable:!0,attrs:{id:{},title:{default:""}},parseDOM:[{tag:"p.sv-subpage",priority:70,getAttrs:t=>{const e=t.querySelector("a"),s=recordIdOf(e?.getAttribute("href"));return s?{id:s,title:e.textContent??""}:!1}}],toDOM:t=>["p",{class:"sv-subpage"},["a",{href:`#svrec:${t.attrs.id}`},t.attrs.title||"Untitled"]]},toc:{group:"block",atom:!0,parseDOM:[{tag:"div.sv-toc",priority:70}],toDOM:()=>["div",{class:"sv-toc"}]},mention:{group:"inline",inline:!0,atom:!0,attrs:{id:{},title:{default:""}},parseDOM:[{tag:"a.sv-mention",priority:70,getAttrs:t=>{const e=recordIdOf(t.getAttribute("href"));return e?{id:e,title:t.textContent??""}:!1}}],toDOM:t=>["a",{class:"sv-mention",href:`#svrec:${t.attrs.id}`},t.attrs.title||"Untitled"]},text:{group:"inline"},hard_break:{inline:!0,group:"inline",selectable:!1,parseDOM:[{tag:"br"}],toDOM:()=>["br"]}},marks:{link:{attrs:{href:{}},inclusive:!1,parseDOM:[{tag:"a[href]",getAttrs:t=>t.classList.contains("sv-mention")?!1:{href:t.getAttribute("href")}}],toDOM:t=>["a",{href:t.attrs.href,target:"_blank",rel:"noopener noreferrer"},0]},strong:{parseDOM:[{tag:"strong"},{tag:"b",getAttrs:t=>t.style.fontWeight!=="normal"&&null}],toDOM:()=>["strong",0]},em:{parseDOM:[{tag:"em"},{tag:"i"}],toDOM:()=>["em",0]},underline:{parseDOM:[{tag:"u"}],toDOM:()=>["u",0]},strike:{parseDOM:[{tag:"s"},{tag:"del"},{tag:"strike"}],toDOM:()=>["s",0]},code:{parseDOM:[{tag:"code",getAttrs:t=>t.parentElement?.tagName==="PRE"?!1:null}],toDOM:()=>["code",0]},color:{attrs:{color:{}},parseDOM:[{tag:"span",getAttrs:t=>{const e=a(t,"sv-c-");return e?{color:e}:!1}}],toDOM:t=>["span",{class:`sv-c-${t.attrs.color}`},0]},highlight:{attrs:{color:{default:"yellow"}},parseDOM:[{tag:"mark",getAttrs:t=>({color:a(t,"sv-h-")??"yellow"})}],toDOM:t=>["mark",{class:`sv-h-${t.attrs.color}`},0]}}})}export function recordIdOf(r){const o=/^#svrec:([A-Za-z0-9_.:-]{1,64})$/.exec(r??"");return o?o[1]:null}function p(r){return!Array.from(r.classList).some(o=>/^sv-(toggle|callout|columns?|toggle-body|callout-body|bookmark|toc)$/.test(o))}export function parsePage(r,o,t){const e=document.createElement("div");return e.innerHTML=t||"<p></p>",r.DOMParser.fromSchema(o).parse(e)}export function serializePage(r,o){if(o.childCount===1&&o.firstChild.type.name==="paragraph"&&o.firstChild.content.size===0)return"";const t=document.createElement("div");return t.appendChild(r.DOMSerializer.fromSchema(o.type.schema).serializeFragment(o.content)),t.innerHTML}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{renderMarkdown as a,sanitizeHtml as
|
|
1
|
+
import{renderMarkdown as a,sanitizeHtml as u,trustedHtml as i}from"@svgrid/grid";import{isEmptyRich as f}from"./rich-html.js";const m=/<\/?(?:p|div|br|span|strong|b|em|i|u|s|del|mark|small|sub|sup|a|ul|ol|li|h[1-6]|blockquote|pre|code|img|script|style|iframe)(?=[\s/>])[^>]*>/i,p=r=>r.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">"),g=/^(?:sv-(?:todo|done|toggle|open|toggle-title|toggle-body|callout|callout-icon|callout-body|columns|columns-[23]|column|file|embed|bookmark|subpage|mention|toc|[ch]-(?:gray|brown|orange|yellow|green|blue|purple|pink|red))|language-[a-z0-9+#-]{1,20})$/;function s(r){const o=u(r);if(typeof DOMParser>"u"||!/\sclass\s*=|<img\b/i.test(o))return o;const t=new DOMParser().parseFromString(i(o),"text/html");for(const e of t.body.querySelectorAll("[class]")){const n=Array.from(e.classList).filter(l=>g.test(l));n.length?e.setAttribute("class",n.join(" ")):e.removeAttribute("class")}for(const e of t.body.querySelectorAll("img")){const n=e.getAttribute("src")??"";if(!/^(https?:)?\/\//i.test(n)||typeof location<"u"&&new URL(n,location.href).origin===location.origin)continue;const l=t.createElement("a");l.setAttribute("href",n),l.setAttribute("target","_blank"),l.setAttribute("rel","noopener noreferrer"),l.textContent=e.getAttribute("alt")||n,e.replaceWith(l)}return t.body.innerHTML}export function richHtml(r){return r==null?"":s(String(r))}const c=new Map,d=1e3;export function richCellHtml(r){if(r==null)return i("");const o=String(r);let t=c.get(o);return t!==void 0||(t=i(o),typeof DOMParser<"u"&&/\sclass\s*=|<img\b/i.test(String(t))&&(t=i(s(o))),c.size>=d&&c.clear(),c.set(o,t)),t}export function toRichHtml(r,o=!1){if(r==null||r==="")return null;const t=String(r);let e;return m.test(t)?e=s(t):o?e=s(a(t)):e=t.split(/\r?\n/).filter(n=>n.trim()!=="").map(n=>`<p>${p(n)}</p>`).join(""),f(e)?null:e.trimStart().startsWith("<")?e:`<p>${e}</p>`}
|
|
@@ -68,7 +68,9 @@ export type LinkedTable = {
|
|
|
68
68
|
* Show a record of this table where it lives (another tab of a base): the
|
|
69
69
|
* linked record view then offers "Open in {name}".
|
|
70
70
|
*/
|
|
71
|
-
open?: (rowId: string
|
|
71
|
+
open?: (rowId: string, o?: {
|
|
72
|
+
dock?: 'center' | 'right' | 'full';
|
|
73
|
+
}) => void;
|
|
72
74
|
/** Its saved views: a link field can let people pick only the records one of them shows (`pickFrom`). */
|
|
73
75
|
views?: () => ReadonlyArray<{
|
|
74
76
|
id: string;
|