feat(editor): add lossless bounded CSV table editing
This commit is contained in:
1 parent
bd80ff6a0c
commit
2d6ceac0d7
19 files changed
+520
-40
No files matched your search
@@ -0,0 +1,17 @@
|
||||
.csv-edit-pane{padding:0!important;display:flex;flex-direction:column;min-width:0;min-height:0;overflow:hidden}
|
||||
.csv-edit-pane[hidden]{display:none!important}
|
||||
.csv-edit-toolbar{display:flex;flex-wrap:wrap;align-items:center;gap:.2rem;padding:.3rem;border-bottom:1px solid var(--border,#444);flex:none;background:var(--bg,#fff);color:var(--fg,#222)}
|
||||
.csv-edit-toolbar button{font:inherit;min-width:2rem;min-height:2rem;padding:.2rem .4rem;border:1px solid var(--border,#777);border-radius:.25rem;color:inherit;background:transparent;cursor:pointer}
|
||||
.csv-edit-toolbar button:disabled{opacity:.4;cursor:default}
|
||||
.csv-edit-toolbar svg{width:1.2rem;height:1.2rem;fill:none;stroke:currentColor;stroke-width:1.7;vertical-align:middle}
|
||||
.csv-edit-toolbar button:focus-visible,.csv-edit-scroll textarea:focus-visible{outline:2px solid var(--accent,#768ad7);outline-offset:-2px}
|
||||
.csv-edit-toolbar output{font-variant-numeric:tabular-nums;font-size:.8rem;white-space:nowrap}
|
||||
.csv-edit-toolbar span{font-size:.8rem}
|
||||
.csv-edit-scroll{overflow:auto;min-height:0;flex:1;overscroll-behavior:contain}
|
||||
.csv-edit-scroll table{border-collapse:separate;border-spacing:0;width:max-content;min-width:100%;font-size:.85rem}
|
||||
.csv-edit-scroll th,.csv-edit-scroll td{border-right:1px solid var(--border,#777);border-bottom:1px solid var(--border,#777);padding:0;vertical-align:top}
|
||||
.csv-edit-scroll th{padding:.2rem .4rem;font-weight:normal;font-variant-numeric:tabular-nums;background:var(--bg,#fff);color:var(--fg,#222)}
|
||||
.csv-edit-scroll thead th{position:sticky;top:0;z-index:1}
|
||||
.csv-edit-scroll textarea{display:block;width:11rem;min-width:6rem;max-width:30rem;min-height:2rem;margin:0;padding:.3rem;border:0;border-radius:0;font:inherit;line-height:1.4;color:inherit;background:transparent;resize:both;box-sizing:border-box}
|
||||
@media(max-width:600px){.csv-edit-toolbar button{min-width:2.75rem;min-height:2.75rem}.csv-edit-scroll textarea{min-height:2.75rem;font-size:16px}}
|
||||
@media(max-width:700px){.csv-editor .editor-grid:not(.preview-hidden){grid-template-columns:1fr!important}.csv-editor .editor-grid:not(.preview-hidden)>.editor-pane{display:none}}
|
||||
@@ -0,0 +1,58 @@
|
||||
(function(root) {
|
||||
'use strict';
|
||||
const limits={bytes:256*1024,rows:200,columns:32,cellBytes:16*1024};
|
||||
const bytes=s=>new TextEncoder().encode(s).length;
|
||||
function parse(source) {
|
||||
if(typeof source!=='string'||bytes(source)>limits.bytes||source.includes('\0'))throw Error('size');
|
||||
const bom=source.startsWith('\ufeff')?'\ufeff':'',rows=[];
|
||||
let i=bom.length,lineEnding='',cells=[];
|
||||
while(i<source.length||cells.length){
|
||||
const start=i;let value='';
|
||||
if(source[i]==='"'){
|
||||
i++;let closed=false;
|
||||
while(i<source.length){const c=source[i++];if(c==='"'){if(source[i]==='"'){value+='"';i++;}else{closed=true;break;}}else value+=c;}
|
||||
if(!closed||i<source.length&&![',','\r','\n'].includes(source[i]))throw Error('syntax');
|
||||
value=value.replace(/\r\n/g,'\n');
|
||||
}else{
|
||||
while(i<source.length&&![',','\r','\n'].includes(source[i])){if(source[i]==='"')throw Error('syntax');value+=source[i++];}
|
||||
}
|
||||
if(bytes(value)>limits.cellBytes||cells.length>=limits.columns)throw Error('size');
|
||||
cells.push({value,raw:source.slice(start,i),original:value});
|
||||
if(source[i]===','){i++;continue;}
|
||||
let end='';
|
||||
if(source[i]==='\r'){if(source[i+1]!=='\n')throw Error('syntax');end='\r\n';i+=2;}
|
||||
else if(source[i]==='\n'){end='\n';i++;}
|
||||
if(!lineEnding&&end)lineEnding=end;
|
||||
rows.push({cells,end});cells=[];if(rows.length>limits.rows)throw Error('size');
|
||||
}
|
||||
return {source,bom,lineEnding:lineEnding||'\r\n',rows};
|
||||
}
|
||||
function encode(value){return /[",\r\n]/.test(value)||/^\s/.test(value)?'"'+value.replace(/"/g,'""')+'"':value;}
|
||||
function serialize(model){
|
||||
const source=model.bom+model.rows.map(row=>{const record=row.cells.map(c=>c.value===c.original?c.raw:encode(c.value)).join(',');return record+(row.end||(!record?model.lineEnding:''));}).join('');
|
||||
parse(source);return source;
|
||||
}
|
||||
function edit(source,action,row=0,column=0,value=''){
|
||||
const m=parse(source),blank=()=>({value:'',raw:'',original:''});
|
||||
if(action==='cell'){
|
||||
if(!m.rows[row]?.cells[column]||typeof value!=='string')throw Error('cell');
|
||||
m.rows[row].cells[column].value=value;
|
||||
}else if(action==='add-row'){
|
||||
const last=m.rows.at(-1),cols=Math.max(1,...m.rows.map(r=>r.cells.length));
|
||||
if(last&&!last.end)last.end=m.lineEnding;
|
||||
// A newline is necessary to distinguish a blank final row from no row.
|
||||
m.rows.push({cells:Array.from({length:cols},blank),end:m.lineEnding});
|
||||
}else if(action==='add-column'){
|
||||
if(!m.rows.length)m.rows.push({cells:[blank()],end:m.lineEnding});
|
||||
const cols=Math.max(...m.rows.map(r=>r.cells.length));
|
||||
for(const r of m.rows){while(r.cells.length<cols)r.cells.push(blank());r.cells.push(blank());}
|
||||
}else if(action==='delete-row'){
|
||||
if(!m.rows[row])throw Error('row');m.rows.splice(row,1);
|
||||
}else if(action==='delete-column'){
|
||||
if(!m.rows.some(r=>r.cells[column]))throw Error('column');
|
||||
for(const r of m.rows){r.cells.splice(column,1);if(!r.cells.length)r.cells.push(blank());}
|
||||
}else throw Error('action');
|
||||
return serialize(m);
|
||||
}
|
||||
root.PagesCSV={parse,edit,serialize,limits};
|
||||
})(typeof window==='undefined'?globalThis:window);
|
||||
@@ -0,0 +1,31 @@
|
||||
const test=require('node:test'),assert=require('node:assert/strict');
|
||||
require('./csv-core.js');const csv=globalThis.PagesCSV;
|
||||
test('CSV parsing preserves untouched bytes and logical field values',()=>{
|
||||
for(const source of ['', '\ufeff', 'a', 'a,', '\n', '""', 'a\r\nb\n', '\ufeff"name",description\r\n日本語,"a,b\r\nnext"\r\n', '"a""b",=1+1\n'])assert.equal(csv.serialize(csv.parse(source)),source);
|
||||
const s='\ufeff"name",description\r\n日本語,"a,b\r\nnext"\r\n';
|
||||
assert.equal(csv.parse(s).rows[1].cells[1].value,'a,b\nnext');
|
||||
assert.equal(csv.edit(s,'cell',1,0,'新しい,名前'),'\ufeff"name",description\r\n"新しい,名前","a,b\r\nnext"\r\n');
|
||||
assert.equal(csv.edit(s,'cell',1,1,'a,b\nnext'),s);
|
||||
assert.equal(csv.edit('a','cell',0,0,''),'\r\n');
|
||||
});
|
||||
test('Row and column operations preserve fields; empty and ragged data are explicit',()=>{
|
||||
assert.equal(csv.edit('a,b\nc\n','add-column'),'a,b,\nc,,\n');
|
||||
assert.equal(csv.edit('a,b\nc\n','delete-column',0,1),'a\nc\n');
|
||||
assert.equal(csv.edit('a,b\r\n"c",d','delete-row',0),'"c",d');
|
||||
assert.equal(csv.edit('a,b','add-row'),'a,b\r\n,\r\n');
|
||||
assert.equal(csv.parse(csv.edit('','add-row')).rows.length,1);
|
||||
assert.equal(csv.edit('a\n','delete-row',0),'');
|
||||
});
|
||||
test('Malformed and excessive data fail without truncation',()=>{
|
||||
for(const source of ['"unfinished','a"b','"a"x','a\rb','a\0b','x'.repeat(256*1024+1),'x'.repeat(16385), 'a,'.repeat(32), 'a\n'.repeat(201)])assert.throws(()=>csv.parse(source));
|
||||
assert.throws(()=>csv.edit('a\n'.repeat(200),'add-row'));
|
||||
assert.throws(()=>csv.edit('a','cell',0,0,'x'.repeat(16385)));
|
||||
assert.throws(()=>csv.edit('a','cell',2,0,'bad'));
|
||||
});
|
||||
test('Quotes, HTML, formulas and newlines remain inert CSV data',()=>{
|
||||
for(const value of ['"','a,b','<img src=x onerror=alert(1)>','{{children}}','=SUM(A1:A9)',' leading','日本語\n次の行','a\r\nb']){
|
||||
const source=csv.edit('old,unchanged\r\n','cell',0,0,value);
|
||||
assert.equal(csv.parse(source).rows[0].cells[0].value,value.replace(/\r\n/g,'\n'));
|
||||
assert.ok(source.endsWith(',unchanged\r\n'));
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,81 @@
|
||||
(() => {
|
||||
'use strict';
|
||||
const views=new WeakMap(),pageSize=25;
|
||||
const el=(tag,text)=>{const n=document.createElement(tag);if(text!==undefined)n.textContent=text;return n;};
|
||||
class TableEditor {
|
||||
constructor(editor){this.editor=editor;this.page=0;this.selected=null;this.last=null;this.undo=[];this.redo=[];}
|
||||
t(en,ja){return this.editor.ja?ja:en;}
|
||||
render(text){
|
||||
if(this.last===text)return;
|
||||
this.last=text;this.selected=null;
|
||||
const pane=this.editor.preview;pane.classList.remove('code-preview');pane.classList.add('csv-edit-pane');pane.replaceChildren();
|
||||
try{this.model=PagesCSV.parse(text);}catch{
|
||||
const error=el('p',this.t('Table unavailable: check CSV syntax or limits (200 rows, 32 columns, 16 KiB per cell). Edit the source; no data was truncated.','表を表示できません。CSVの構文・上限(200行、32列、セル16 KiB)を確認してください。ソースで編集できます。データは切り捨てていません。'));
|
||||
error.role='status';pane.append(error);return;
|
||||
}
|
||||
const toolbar=el('div');toolbar.className='csv-edit-toolbar';
|
||||
const button=(icon,en,ja,fn)=>{const b=el('button',icon);b.type='button';b.title=b.ariaLabel=this.t(en,ja);b.onclick=fn;toolbar.append(b);return b;};
|
||||
const save=button('','Save','保存',async()=>{save.disabled=true;try{await this.editor.saveNow();}finally{save.disabled=false;}});
|
||||
save.innerHTML='<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5 4h12l2 2v14H5zM8 4v6h8V4M8 20v-6h8v6"/></svg>';
|
||||
button('+↧','Add row','行を追加',()=>this.change('add-row'));
|
||||
button('+→','Add column','列を追加',()=>this.change('add-column'));
|
||||
this.deleteRow=button('−↧','Delete selected row','選択行を削除',()=>this.change('delete-row'));
|
||||
this.deleteColumn=button('−→','Delete selected column','選択列を削除',()=>this.change('delete-column'));
|
||||
this.deleteRow.disabled=this.deleteColumn.disabled=true;
|
||||
const undo=button('↶','Undo table edit','表の編集を元に戻す',()=>this.history(false));undo.disabled=!this.undo.length;
|
||||
const redo=button('↷','Redo table edit','表の編集をやり直す',()=>this.history(true));redo.disabled=!this.redo.length;
|
||||
this.undoButton=undo;this.redoButton=redo;
|
||||
this.page=Math.max(0,Math.min(this.page,Math.ceil(this.model.rows.length/pageSize)-1));
|
||||
const previous=button('‹','Previous rows','前の行',()=>{this.page--;this.last=null;this.render(this.editor.text());});previous.disabled=this.page===0;
|
||||
const first=this.page*pageSize,end=Math.min(first+pageSize,this.model.rows.length);
|
||||
this.position=el('output',this.model.rows.length?`${first+1}–${end} / ${this.model.rows.length}`:'0');toolbar.append(this.position);
|
||||
const next=button('›','Next rows','次の行',()=>{this.page++;this.last=null;this.render(this.editor.text());});next.disabled=end>=this.model.rows.length;
|
||||
this.message=el('span');this.message.role='status';toolbar.append(this.message);
|
||||
const saved=el('span',document.getElementById('editor-save-status')?.textContent||'');saved.dataset.csvSaveStatus='';saved.role='status';toolbar.append(saved);pane.append(toolbar);
|
||||
const scroll=el('div');scroll.className='csv-edit-scroll';const table=el('table');table.setAttribute('aria-label',this.t('CSV cells','CSVのセル'));
|
||||
const head=el('thead'),hr=el('tr');hr.append(el('th','#'));
|
||||
const width=Math.max(0,...this.model.rows.map(r=>r.cells.length));
|
||||
for(let c=0;c<width;c++){const th=el('th',String(c+1));th.scope='col';hr.append(th);}head.append(hr);table.append(head);
|
||||
const body=el('tbody');
|
||||
for(let r=first;r<end;r++){
|
||||
const tr=el('tr'),number=el('th',String(r+1));number.scope='row';tr.append(number);
|
||||
for(let c=0;c<width;c++){
|
||||
const td=el('td'),cell=this.model.rows[r].cells[c];
|
||||
if(cell){const input=el('textarea');input.value=cell.value;input.rows=cell.value.includes('\n')?3:1;input.spellcheck=false;input.dataset.row=r;input.dataset.column=c;input.ariaLabel=this.t(`Row ${r+1}, column ${c+1}`,`${r+1}行 ${c+1}列`);
|
||||
input.addEventListener('focus',()=>{this.selected=[r,c];this.deleteRow.disabled=this.deleteColumn.disabled=false;});
|
||||
input.addEventListener('input',()=>this.change('cell',r,c,input.value,input));td.append(input);
|
||||
}
|
||||
tr.append(td);
|
||||
}
|
||||
body.append(tr);
|
||||
}
|
||||
table.append(body);scroll.append(table);pane.append(scroll);
|
||||
}
|
||||
change(action,row=this.selected?.[0],column=this.selected?.[1],value,input){
|
||||
const source=this.editor.text();
|
||||
if(source!==this.last){this.last=null;this.render(source);return;}
|
||||
try{
|
||||
const next=PagesCSV.edit(source,action,row,column,value);if(next===source)return;
|
||||
this.undo.push({before:source,after:next});if(this.undo.length>20)this.undo.shift();this.redo=[];
|
||||
if(action==='cell'){
|
||||
// Keep the active textarea and its caret; delayed preview is a no-op.
|
||||
this.model=PagesCSV.parse(next);this.last=next;this.editor.setText(next);
|
||||
this.undoButton.disabled=false;this.redoButton.disabled=true;this.message.textContent='';
|
||||
}else{
|
||||
if(action==='add-row')this.page=Math.floor((PagesCSV.parse(next).rows.length-1)/pageSize);
|
||||
this.last=null;this.editor.setText(next);this.render(next);
|
||||
}
|
||||
}catch{
|
||||
if(input)input.value=this.model.rows[row].cells[column].value;
|
||||
this.message.textContent=this.t('Edit exceeds CSV limits. Source retained.','CSVの上限を超えます。元の内容を保持しました。');
|
||||
}
|
||||
}
|
||||
history(forward){
|
||||
const from=forward?this.redo:this.undo,to=forward?this.undo:this.redo;if(!from.length)return;
|
||||
const item=from.at(-1),current=this.editor.text();
|
||||
if(current!==(forward?item.before:item.after)){this.message.textContent=this.t('Source changed. Use source editor undo.','ソースが変更されています。ソース側の取り消しを使ってください。');return;}
|
||||
from.pop();to.push(item);const text=forward?item.after:item.before;this.last=null;this.editor.setText(text);this.render(text);
|
||||
}
|
||||
}
|
||||
window.PagesCSVEditor={render(editor,text){let view=views.get(editor);if(!view){view=new TableEditor(editor);views.set(editor,view);}view.render(text);}};
|
||||
})();
|
||||
+28
-10
@@ -6,8 +6,12 @@ window.PagesEditor = {
|
||||
this.mount = document.getElementById('editor-mount')
|
||||
if (!this.editor || !this.preview || !this.mount) return
|
||||
this.baseRevision = this.mount.dataset.baseRevision || ''
|
||||
this.baseBody = document.getElementById('editor-base')?.value || ''
|
||||
this.initialText = this.editor.value
|
||||
// HTML textarea parsing and CodeMirror's default input both normalize
|
||||
// CRLF. CSV receives an escaped JS string and uses LF-only splitting.
|
||||
this.csvInitialSource = this.mount.dataset.csv === 'true' ? window.PagesCSVSource : undefined
|
||||
delete window.PagesCSVSource
|
||||
this.baseBody = this.csvInitialSource ?? (document.getElementById('editor-base')?.value || '')
|
||||
this.initialText = this.csvInitialSource ?? this.editor.value
|
||||
this.owner = this.mount.dataset.owner || ''
|
||||
this.serial = 0
|
||||
this.paused = false
|
||||
@@ -65,17 +69,21 @@ window.PagesEditor = {
|
||||
exists:['指定言語には既に本文があります。編集として開いてください','This language already exists. Open it for editing'], history:['過去のリビジョンを復元','Restore a previous revision'],
|
||||
signin:['再ログイン(別タブ)','Sign in again (new tab)'], insert:['挿入','Insert'], invalid:['言語タグを確認してください','Check the language tag'], identity:['別アカウントに切り替わっています。元のアカウントで開き直してください','Account changed. Reopen using the original account'],
|
||||
incompatible:['ファイル形式が変更されています。下書きを退避して開き直してください','File type changed. Download your draft and reopen'], older:['さらに古い履歴','Older revisions'],
|
||||
csvlimit:['CSVは256 KiB以内で保存してください。下書きは保持しています','CSV must be at most 256 KiB. Your draft is retained'],
|
||||
children:['子ページ一覧','Children'], table:['表','Table'], figure:['画像とキャプション','Image + caption'], note:['補足','Note'], code:['コードブロック','Code block'], quote:['引用','Quote'],
|
||||
csv:['CSVの表を埋め込む','Embed CSV table'],
|
||||
protected:['Markdown で表せない HTML は {=html} ブロックに保持します。ブロック内も編集でき、保存・プレビュー時に HTML として扱います。','HTML not representable in Markdown is retained in editable {=html} blocks and rendered as HTML on save / preview.'],
|
||||
}
|
||||
return text[key]?.[this.ja ? 0 : 1] || key
|
||||
},
|
||||
value(id) { return document.getElementById(id)?.value || '' },
|
||||
format() {return this.value('edit-type')},
|
||||
text() {return window.PagesWikiCodeMirror?.state.doc.toString() ?? this.editor.value},
|
||||
text() {return window.PagesWikiCodeMirror?.state.doc.toString() ?? this.csvInitialSource ?? this.editor.value},
|
||||
status(key) {
|
||||
const status = document.getElementById('editor-save-status')
|
||||
if (status) {status.textContent = this.t(key); status.dataset.state = key}
|
||||
const csvStatus=this.preview?.querySelector('[data-csv-save-status]')
|
||||
if (csvStatus) csvStatus.textContent=this.t(key)
|
||||
},
|
||||
keyPrefix() {return 'pageswiki.draft.v1:'+JSON.stringify([this.mount.dataset.domain,this.owner,this.value('object-uuid'),this.value('page-language')||'und'])+':'},
|
||||
expireDrafts() {
|
||||
@@ -180,6 +188,7 @@ window.PagesEditor = {
|
||||
}
|
||||
},
|
||||
async canonical(text = this.text(), format = this.format()) {
|
||||
if (this.mount.dataset.csv === 'true' && (new TextEncoder().encode(text).length > 256*1024 || text.includes('\0'))) throw {kind:'csvlimit'}
|
||||
if (text === this.initialText && format === this.initialFormat) return this.baseBody
|
||||
if (format !== 'markdown') return text
|
||||
const data = await this.post('/_/api/v1/render/markdown',{markdown:text,authoring:true})
|
||||
@@ -192,6 +201,7 @@ window.PagesEditor = {
|
||||
const controller = new AbortController()
|
||||
this.previewController = controller
|
||||
const text = this.text()
|
||||
if (this.mount.dataset.csv === 'true' && window.PagesCSVEditor) {window.PagesCSVEditor.render(this,text); return}
|
||||
if (this.format() === 'code' || this.format() === 'plain') {this.preview.classList.add('code-preview'); this.preview.textContent=text; return}
|
||||
try {
|
||||
const data = await this.post('/_/api/v1/render/markdown',{
|
||||
@@ -270,7 +280,9 @@ window.PagesEditor = {
|
||||
this.dirty=false; this.paused=false; this.clearDraft(); this.status('saved'); return
|
||||
}
|
||||
if (serial !== this.serial) {this.status('remote'); this.persist(); return}
|
||||
const merged = PagesEditorCore.merge(this.baseBody,local,remote.body)
|
||||
// Text ranges do not describe CSV record boundaries. Review competing
|
||||
// table edits rather than silently combining rows/columns incorrectly.
|
||||
const merged = this.mount.dataset.csv === 'true' ? null : PagesEditorCore.merge(this.baseBody,local,remote.body)
|
||||
const apply = result => {
|
||||
this.baseRevision=remote.revision_uuid; this.baseBody=remote.body
|
||||
document.getElementById('page-filename').value=remote.filename||''
|
||||
@@ -301,12 +313,13 @@ window.PagesEditor = {
|
||||
const oldFormat = this.format()
|
||||
document.getElementById('edit-type').value=format
|
||||
const status=document.getElementById('editor-format-status')
|
||||
if (status) status.textContent=format
|
||||
if (status) status.textContent=this.mount.dataset.csv === 'true' ? 'CSV' : format
|
||||
this.editor.value=text
|
||||
if (this.mount.dataset.csv === 'true') this.csvInitialSource=text
|
||||
if (oldFormat !== format && window.PagesWikiCodeMirror) {
|
||||
window.PagesWikiCodeMirror.destroy()
|
||||
window.PagesWikiCodeMirror = window.PagesWikiEditor.create(this.mount,text,format,{
|
||||
keymap:this.mount.dataset.keymap,syntax:this.mount.dataset.syntax==='true',autocomplete:this.mount.dataset.autocomplete==='true',
|
||||
keymap:this.mount.dataset.keymap,syntax:this.mount.dataset.syntax==='true',autocomplete:this.mount.dataset.autocomplete==='true',preserveLineEndings:this.mount.dataset.csv==='true',
|
||||
})
|
||||
} else if (window.PagesWikiCodeMirror) {
|
||||
const cm=window.PagesWikiCodeMirror
|
||||
@@ -368,19 +381,24 @@ window.PagesEditor = {
|
||||
const {dialog,content,button}=this.dialog('tools')
|
||||
this.paragraph(content,this.t('privacy'))
|
||||
const select=document.createElement('select'); select.setAttribute('aria-label',this.t('insert'))
|
||||
this.paragraph(content,this.t('protected'))
|
||||
const csvFile=this.mount.dataset.csv==='true'
|
||||
if (!csvFile) this.paragraph(content,this.t('protected'))
|
||||
const parts=[['children','{{children}}'],['table','<table>\n<thead><tr><th>Column</th></tr></thead>\n<tbody><tr><td>Value</td></tr></tbody>\n</table>'],['figure','<figure><img src="/_/obj/sha256:HASH" alt="Description"><figcaption>Caption</figcaption></figure>'],['note','<aside class="note"><p>Note</p></aside>'],['code','<pre><code class="language-text">code</code></pre>'],['quote','<blockquote><p>Quote</p></blockquote>']]
|
||||
parts.push(['csv','{{csv:/data/table.csv range=A1:H200 header=true}}'])
|
||||
parts.forEach(([label],i) => {const option=document.createElement('option'); option.value=i; option.textContent=this.t(label); select.append(option)})
|
||||
content.append(select)
|
||||
select.hidden=csvFile
|
||||
const login=document.createElement('a'); login.href='/_/auth/login?return='+encodeURIComponent(location.pathname+location.search); login.target='_blank'; login.rel='noopener'; login.textContent=this.t('signin'); content.append(login)
|
||||
button('insert',() => {
|
||||
const insert=button('insert',() => {
|
||||
if (csvFile) return
|
||||
const part=parts[Number(select.value)]
|
||||
const source=this.format()==='markdown' && part[0]!=='children' ? '```{=html}\n'+part[1]+'\n```' : part[1]
|
||||
const source=this.format()==='markdown' && !['children','csv'].includes(part[0]) ? '```{=html}\n'+part[1]+'\n```' : part[1]
|
||||
const text='\n\n'+source+'\n\n'
|
||||
const cm=window.PagesWikiCodeMirror
|
||||
if (cm) cm.dispatch(cm.state.replaceSelection(text)); else this.setText(this.text()+text)
|
||||
dialog.close(); cm?.focus()
|
||||
})
|
||||
insert.hidden=csvFile
|
||||
button('export',() => this.download())
|
||||
button('discard',() => {
|
||||
this.clearDraft()
|
||||
@@ -429,7 +447,7 @@ window.PagesEditor = {
|
||||
const serial=this.serial
|
||||
const old=await this.state({revision:select.value})
|
||||
if (serial!==this.serial || this.saving) return
|
||||
if (!old.editable) throw {kind:'incompatible'}
|
||||
if (!old.editable || this.mount.dataset.csv === 'true' && (old.content_type||'').split(';')[0] !== this.value('page-content-type').split(';')[0]) throw {kind:'incompatible'}
|
||||
this.setText(this.format()==='markdown'?old.markdown:old.body)
|
||||
this.persist(); dialog.close()
|
||||
})
|
||||
|
||||
+3
@@ -38953,6 +38953,9 @@
|
||||
}
|
||||
})
|
||||
];
|
||||
if (options.preserveLineEndings) {
|
||||
extensions.push(EditorState.lineSeparator.of("\n"));
|
||||
}
|
||||
if (keymapName === "vim") {
|
||||
installVimCommands();
|
||||
extensions.push(vim());
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"version": 3,
|
||||
"sources": ["../../../assets/editor/node_modules/@marijn/find-cluster-break/src/index.js", "../../../assets/editor/node_modules/@codemirror/state/dist/index.js", "../../../assets/editor/node_modules/style-mod/src/style-mod.js", "../../../assets/editor/node_modules/w3c-keyname/index.js", "../../../assets/editor/node_modules/@codemirror/view/dist/index.js", "../../../assets/editor/node_modules/@lezer/common/dist/index.js", "../../../assets/editor/node_modules/@lezer/highlight/dist/index.js", "../../../assets/editor/node_modules/@codemirror/language/dist/index.js", "../../../assets/editor/node_modules/@codemirror/commands/dist/index.js", "../../../assets/editor/node_modules/@codemirror/autocomplete/dist/index.js", "../../../assets/editor/node_modules/@lezer/lr/dist/index.js", "../../../assets/editor/node_modules/@lezer/html/dist/index.js", "../../../assets/editor/node_modules/@lezer/css/dist/index.js", "../../../assets/editor/node_modules/@codemirror/lang-css/dist/index.js", "../../../assets/editor/node_modules/@lezer/javascript/dist/index.js", "../../../assets/editor/node_modules/@codemirror/lang-javascript/dist/index.js", "../../../assets/editor/node_modules/@codemirror/lang-html/dist/index.js", "../../../assets/editor/node_modules/@lezer/markdown/dist/index.js", "../../../assets/editor/node_modules/@codemirror/lang-markdown/dist/index.js", "../../../assets/editor/node_modules/@lezer/python/dist/index.js", "../../../assets/editor/node_modules/@codemirror/lang-python/dist/index.js", "../../../assets/editor/node_modules/@lezer/json/dist/index.js", "../../../assets/editor/node_modules/@codemirror/lang-json/dist/index.js", "../../../assets/editor/node_modules/@codemirror/lang-sql/dist/index.js", "../../../assets/editor/node_modules/@lezer/yaml/dist/index.js", "../../../assets/editor/node_modules/@codemirror/lang-yaml/dist/index.js", "../../../assets/editor/node_modules/@lezer/go/dist/index.js", "../../../assets/editor/node_modules/@codemirror/lang-go/dist/index.js", "../../../assets/editor/node_modules/@lezer/rust/dist/index.js", "../../../assets/editor/node_modules/@codemirror/lang-rust/dist/index.js", "../../../assets/editor/node_modules/@lezer/java/dist/index.js", "../../../assets/editor/node_modules/@codemirror/lang-java/dist/index.js", "../../../assets/editor/node_modules/@lezer/cpp/dist/index.js", "../../../assets/editor/node_modules/@codemirror/lang-cpp/dist/index.js", "../../../assets/editor/node_modules/@codemirror/legacy-modes/mode/shell.js", "../../../assets/editor/node_modules/@codemirror/legacy-modes/mode/toml.js", "../../../assets/editor/node_modules/@codemirror/search/dist/index.js", "../../../assets/editor/node_modules/@replit/codemirror-vim/dist/index.js", "../../../assets/editor/src/editor.js"],
|
||||
"sourcesContent": ["// These are filled with ranges (rangeFrom[i] up to but not including\n// rangeTo[i]) of code points that count as extending characters.\nlet rangeFrom = [], rangeTo = []\n\n;(() => {\n // Compressed representation of the Grapheme_Cluster_Break=Extend\n // information from\n // http://www.unicode.org/Public/16.0.0/ucd/auxiliary/GraphemeBreakProperty.txt.\n // Each pair of elements represents a range, as an offet from the\n // previous range and a length. Numbers are in base-36, with the empty\n // string being a shorthand for 1.\n let numbers = \"lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,3b,f,,w,1j,,,,4,8,4,,3,7,a,2,t,,1m,,,,2,4,8,,9,,a,2,q,,2,2,1l,,4,2,4,2,2,3,3,,u,2,3,,b,2,1l,,4,5,,2,4,,k,2,m,6,,,1m,,,2,,4,8,,7,3,a,2,u,,1n,,,,c,,9,,14,,3,,1l,3,5,3,,4,7,2,b,2,t,,1m,,2,,2,,3,,5,2,7,2,b,2,s,2,1l,2,,,2,4,8,,9,,a,2,t,,20,,4,,2,3,,,8,,29,,2,7,c,8,2q,,2,9,b,6,22,2,r,,,,,,1j,e,,5,,2,5,b,,10,9,,2u,4,,6,,2,2,2,p,2,4,3,g,4,d,,2,2,6,,f,,jj,3,qa,3,t,3,t,2,u,2,1s,2,,7,8,,2,b,9,,19,3,3b,2,y,,3a,3,4,2,9,,6,3,63,2,2,,1m,,,7,,,,,2,8,6,a,2,,1c,h,1r,4,1c,7,,,5,,14,9,c,2,w,4,2,2,,3,1k,,,2,3,,,3,1m,8,2,2,48,3,,d,,7,4,,6,,3,2,5i,1m,,5,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,p,2,5,,47,2,q,i,d,,12,8,p,b,1a,3,1c,,2,4,2,2,13,,1v,6,2,2,2,2,c,,8,,1b,,1f,,,3,2,2,5,2,,,16,2,8,,6m,,2,,4,,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,ar,2,49,b,4w,,1i,f,1k,3,1d,4,2,2,1x,3,10,5,,8,1q,,c,2,1g,9,a,4,2,,2n,3,2,,,2,6,,4g,,3,8,l,2,1l,2,,,,,m,,e,7,3,5,5f,8,2,3,,,n,,29,,2,6,,,2,,,2,,2,6j,,2,4,6,2,,2,r,2,2d,8,2,,,2,2y,,,,2,6,,,2t,3,2,4,,5,77,9,,2,6t,,a,2,,,4,,40,4,2,2,4,,w,a,14,6,2,4,8,,9,6,2,3,1a,d,,2,ba,7,,6,,,2a,m,2,7,,2,,2,3e,6,3,,,2,,7,,,20,2,3,,,,9n,2,f0b,5,1n,7,t4,,1r,4,29,,f5k,2,43q,,,3,4,5,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,79,7,c5,4,15s,7,31,7,240,5,gx7k,2o,3k,6o\".split(\",\").map(s => s ? parseInt(s, 36) : 1)\n for (let i = 0, n = 0; i < numbers.length; i++)\n (i % 2 ? rangeTo : rangeFrom).push(n = n + numbers[i])\n})()\n\nexport function isExtendingChar(code) {\n if (code < 768) return false\n for (let from = 0, to = rangeFrom.length;;) {\n let mid = (from + to) >> 1\n if (code < rangeFrom[mid]) to = mid\n else if (code >= rangeTo[mid]) from = mid + 1\n else return true\n if (from == to) return false\n }\n}\n\nfunction isRegionalIndicator(code) {\n return code >= 0x1F1E6 && code <= 0x1F1FF\n}\n\nfunction check(code) {\n for (let i = 0; i < rangeFrom.length; i++) {\n if (rangeTo[i] > code) return rangeFrom[i] <= code\n }\n return false\n}\n\nconst ZWJ = 0x200d\n\nexport function findClusterBreak(str, pos, forward = true, includeExtending = true) {\n return (forward ? nextClusterBreak : prevClusterBreak)(str, pos, includeExtending)\n}\n\nfunction nextClusterBreak(str, pos, includeExtending) {\n if (pos == str.length) return pos\n // If pos is in the middle of a surrogate pair, move to its start\n if (pos && surrogateLow(str.charCodeAt(pos)) && surrogateHigh(str.charCodeAt(pos - 1))) pos--\n let prev = codePointAt(str, pos)\n pos += codePointSize(prev)\n while (pos < str.length) {\n let next = codePointAt(str, pos)\n if (prev == ZWJ || next == ZWJ || includeExtending && isExtendingChar(next)) {\n pos += codePointSize(next)\n prev = next\n } else if (isRegionalIndicator(next)) {\n let countBefore = 0, i = pos - 2\n while (i >= 0 && isRegionalIndicator(codePointAt(str, i))) { countBefore++; i -= 2 }\n if (countBefore % 2 == 0) break\n else pos += 2\n } else {\n break\n }\n }\n return pos\n}\n\nfunction prevClusterBreak(str, pos, includeExtending) {\n while (pos > 0) {\n let found = nextClusterBreak(str, pos - 2, includeExtending)\n if (found < pos) return found\n pos--\n }\n return 0\n}\n\nfunction codePointAt(str, pos) {\n let code0 = str.charCodeAt(pos)\n if (!surrogateHigh(code0) || pos + 1 == str.length) return code0\n let code1 = str.charCodeAt(pos + 1)\n if (!surrogateLow(code1)) return code0\n return ((code0 - 0xd800) << 10) + (code1 - 0xdc00) + 0x10000\n}\n\nfunction surrogateLow(ch) { return ch >= 0xDC00 && ch < 0xE000 }\nfunction surrogateHigh(ch) { return ch >= 0xD800 && ch < 0xDC00 }\nfunction codePointSize(code) { return code < 0x10000 ? 1 : 2 }\n", "import { findClusterBreak as findClusterBreak$1 } from '@marijn/find-cluster-break';\n\n/**\nThe data structure for documents. @nonabstract\n*/\nclass Text {\n /**\n Get the line description around the given position.\n */\n lineAt(pos) {\n if (pos < 0 || pos > this.length)\n throw new RangeError(`Invalid position ${pos} in document of length ${this.length}`);\n return this.lineInner(pos, false, 1, 0);\n }\n /**\n Get the description for the given (1-based) line number.\n */\n line(n) {\n if (n < 1 || n > this.lines)\n throw new RangeError(`Invalid line number ${n}Line truncated
|
||||
"mappings": ";;AAEA,MAAI,YAAY,CAAC;AAAjB,MAAoB,UAAU,CAAC;AAE9B,GAAC,MAAM;AAON,QAAI,UAAU,izCAAizC,MAAM,GAAG,EAAE,IAAI,OAAK,IAAI,SAAS,GAAG,EAAE,IAAI,CAAC;AAC12C,aAAS,IAAI,GAAG,IAAI,GAAG,IAAI,QAAQ,QAAQ;AACzC,OAAC,IAAI,IAAI,UAAU,WAAW,KAAK,IAAI,IAAI,QAAQ,CAAC,CAAC;AAAA,EACzD,GAAG;AAEI,WAAS,gBAAgB,MAAM;AACpC,QAAI,OAAO,IAAK,QAAO;AACvB,aAAS,OAAO,GAAG,KAAK,UAAU,YAAU;AAC1C,UAAI,MAAO,OAAO,MAAO;AACzB,UAAI,OAAO,UAAU,GAAG,EAAG,MAAK;AAAA,eACvB,QAAQ,QAAQ,GAAG,EAAG,QAAO,MAAM;AAAA,UACvC,QAAO;AACZ,UAAI,QAAQ,GAAI,QAAO;AAAA,IACzB;AAAA,EACF;AAEA,WAAS,oBAAoB,MAAM;AACjC,WAAO,QAAQ,UAAW,QAAQ;AAAA,EACpC;AASA,MAAM,MAAM;AAEL,WAAS,iBAAiB,KAAK,KAAK,UAAU,MAAM,mBAAmB,MAAM;AAClF,YAAQ,UAAU,mBAAmB,kBAAkB,KAAK,KAAK,gBAAgB;AAAA,EACnF;AAEA,WAAS,iBAAiB,KAAK,KAAK,kBAAkB;AACpD,QAAI,OAAO,IAAI,OAAQ,QAAO;AAE9B,QAAI,OAAO,aAAa,IAAI,WAAW,GAAG,CAAC,KAAK,cAAc,IAAI,WAAW,MAAM,CAAC,CAAC,EAAG;AACxF,QAAI,OAAO,YAAY,KAAK,GAAG;AAC/B,WAAO,cAAc,IAAI;A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// rangeTo[i]) of code points that count as extending characters.\nlet rangeFrom = [], rangeTo = []\n\n;(() => {\n // Compressed representation of the Grapheme_Cluster_Break=Extend\n // information from\n // http://www.unicode.org/Public/16.0.0/ucd/auxiliary/GraphemeBreakProperty.txt.\n // Each pair of elements represents a range, as an offet from the\n // previous range and a length. Numbers are in base-36, with the empty\n // string being a shorthand for 1.\n let numbers = \"lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,3b,f,,w,1j,,,,4,8,4,,3,7,a,2,t,,1m,,,,2,4,8,,9,,a,2,q,,2,2,1l,,4,2,4,2,2,3,3,,u,2,3,,b,2,1l,,4,5,,2,4,,k,2,m,6,,,1m,,,2,,4,8,,7,3,a,2,u,,1n,,,,c,,9,,14,,3,,1l,3,5,3,,4,7,2,b,2,t,,1m,,2,,2,,3,,5,2,7,2,b,2,s,2,1l,2,,,2,4,8,,9,,a,2,t,,20,,4,,2,3,,,8,,29,,2,7,c,8,2q,,2,9,b,6,22,2,r,,,,,,1j,e,,5,,2,5,b,,10,9,,2u,4,,6,,2,2,2,p,2,4,3,g,4,d,,2,2,6,,f,,jj,3,qa,3,t,3,t,2,u,2,1s,2,,7,8,,2,b,9,,19,3,3b,2,y,,3a,3,4,2,9,,6,3,63,2,2,,1m,,,7,,,,,2,8,6,a,2,,1c,h,1r,4,1c,7,,,5,,14,9,c,2,w,4,2,2,,3,1k,,,2,3,,,3,1m,8,2,2,48,3,,d,,7,4,,6,,3,2,5i,1m,,5,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,p,2,5,,47,2,q,i,d,,12,8,p,b,1a,3,1c,,2,4,2,2,13,,1v,6,2,2,2,2,c,,8,,1b,,1f,,,3,2,2,5,2,,,16,2,8,,6m,,2,,4,,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,ar,2,49,b,4w,,1i,f,1k,3,1d,4,2,2,1x,3,10,5,,8,1q,,c,2,1g,9,a,4,2,,2n,3,2,,,2,6,,4g,,3,8,l,2,1l,2,,,,,m,,e,7,3,5,5f,8,2,3,,,n,,29,,2,6,,,2,,,2,,2,6j,,2,4,6,2,,2,r,2,2d,8,2,,,2,2y,,,,2,6,,,2t,3,2,4,,5,77,9,,2,6t,,a,2,,,4,,40,4,2,2,4,,w,a,14,6,2,4,8,,9,6,2,3,1a,d,,2,ba,7,,6,,,2a,m,2,7,,2,,2,3e,6,3,,,2,,7,,,20,2,3,,,,9n,2,f0b,5,1n,7,t4,,1r,4,29,,f5k,2,43q,,,3,4,5,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,79,7,c5,4,15s,7,31,7,240,5,gx7k,2o,3k,6o\".split(\",\").map(s => s ? parseInt(s, 36) : 1)\n for (let i = 0, n = 0; i < numbers.length; i++)\n (i % 2 ? rangeTo : rangeFrom).push(n = n + numbers[i])\n})()\n\nexport function isExtendingChar(code) {\n if (code < 768) return false\n for (let from = 0, to = rangeFrom.length;;) {\n let mid = (from + to) >> 1\n if (code < rangeFrom[mid]) to = mid\n else if (code >= rangeTo[mid]) from = mid + 1\n else return true\n if (from == to) return false\n }\n}\n\nfunction isRegionalIndicator(code) {\n return code >= 0x1F1E6 && code <= 0x1F1FF\n}\n\nfunction check(code) {\n for (let i = 0; i < rangeFrom.length; i++) {\n if (rangeTo[i] > code) return rangeFrom[i] <= code\n }\n return false\n}\n\nconst ZWJ = 0x200d\n\nexport function findClusterBreak(str, pos, forward = true, includeExtending = true) {\n return (forward ? nextClusterBreak : prevClusterBreak)(str, pos, includeExtending)\n}\n\nfunction nextClusterBreak(str, pos, includeExtending) {\n if (pos == str.length) return pos\n // If pos is in the middle of a surrogate pair, move to its start\n if (pos && surrogateLow(str.charCodeAt(pos)) && surrogateHigh(str.charCodeAt(pos - 1))) pos--\n let prev = codePointAt(str, pos)\n pos += codePointSize(prev)\n while (pos < str.length) {\n let next = codePointAt(str, pos)\n if (prev == ZWJ || next == ZWJ || includeExtending && isExtendingChar(next)) {\n pos += codePointSize(next)\n prev = next\n } else if (isRegionalIndicator(next)) {\n let countBefore = 0, i = pos - 2\n while (i >= 0 && isRegionalIndicator(codePointAt(str, i))) { countBefore++; i -= 2 }\n if (countBefore % 2 == 0) break\n else pos += 2\n } else {\n break\n }\n }\n return pos\n}\n\nfunction prevClusterBreak(str, pos, includeExtending) {\n while (pos > 0) {\n let found = nextClusterBreak(str, pos - 2, includeExtending)\n if (found < pos) return found\n pos--\n }\n return 0\n}\n\nfunction codePointAt(str, pos) {\n let code0 = str.charCodeAt(pos)\n if (!surrogateHigh(code0) || pos + 1 == str.length) return code0\n let code1 = str.charCodeAt(pos + 1)\n if (!surrogateLow(code1)) return code0\n return ((code0 - 0xd800) << 10) + (code1 - 0xdc00) + 0x10000\n}\n\nfunction surrogateLow(ch) { return ch >= 0xDC00 && ch < 0xE000 }\nfunction surrogateHigh(ch) { return ch >= 0xD800 && ch < 0xDC00 }\nfunction codePointSize(code) { return code < 0x10000 ? 1 : 2 }\n", "import { findClusterBreak as findClusterBreak$1 } from '@marijn/find-cluster-break';\n\n/**\nThe data structure for documents. @nonabstract\n*/\nclass Text {\n /**\n Get the line description around the given position.\n */\n lineAt(pos) {\n if (pos < 0 || pos > this.length)\n throw new RangeError(`Invalid position ${pos} in document of length ${this.length}`);\n return this.lineInner(pos, false, 1, 0);\n }\n /**\n Get the description for the given (1-based) line number.\n */\n line(n) {\n if (n < 1 || n > this.lines)\n throw new RangeError(`Invalid line number ${n}Line truncated
|
||||
"mappings": ";;AAEA,MAAI,YAAY,CAAC;AAAjB,MAAoB,UAAU,CAAC;AAE9B,GAAC,MAAM;AAON,QAAI,UAAU,izCAAizC,MAAM,GAAG,EAAE,IAAI,OAAK,IAAI,SAAS,GAAG,EAAE,IAAI,CAAC;AAC12C,aAAS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AAC,KAAK,CAAC;AAC3B,eAAO,MAAK;AAChB,aAAO,KAAK,UAAU,KAAuB,IAAI,SAAS,IAAI,IAAI,SAAS,KAAK,SAAS,MAAM,MAAM,CAAC,CAAC,CAAC;AAAA,IAC5G;AAAA,EACJ;AAIA,MAAM,WAAN,MAAM,kBAAiBD,MAAK;AAAA,IACxB,YAAY,MAAM,SAAS,WAAW,IAAI,GAAG;AACzC,YAAM;AACN,WAAK,OAAO;AACZ,WAAK,SAAS;AAAA,IAClB;AAAA,IACA,IAAI,QAAQ;AAAE,aAAO,KAAK,KAAK;AAAA,IAAQ;AAAA,IACvC,IAAI,WAAW;AAAE,aAAO;AAAA,IAAM;AAAA,IAC9B,UAAU,QAAQ,QAAQ,MAAM,QAAQ;AACpC,eAAS,IAAI,KAAI,KAAK;AAClB,YAAIE,UAAS,KAAK,KAAK,CAAC,GAAG,MAAM,SAASA,QAAO;AACjD,aAAK,SAAS,OAAO,QAAQ;AACzB,iBAAO,IAAI,KAAK,QAAQ,KAAK,MAAMA,OAAM;AAC7C,iBAAS,MAAM;AACf;AAAA,MACJ;AAAA,IACJ;AAAA,IACA,UAAU,MAAM,IAAI,QAAQ,MAAM;AAC9B,UAAI,OAAO,QAAQ,KAAK,MAAM,KAAK,SAAS,OACtC,IAAI,UAAS,UAAU,KAAK,MAAM,MAAM,EAALine truncated
|
||||
"names": ["Text", "a", "string", "top", "number", "findClusterBreak", "surrogateLow", "surrogateHigh", "codePointAt", "codePointSize", "MapMode", "json", "doc", "process", "insert", "i", "values", "compare", "config", "_a", "id", "prec", "content", "base", "scrollIntoView", "CharCategory", "require", "name", "defaults", "cur", "spec", "a", "id", "doc", "name", "ie", "name", "a", "BlockType", "off", "elt", "doc", "cur", "top", "rect", "Direction", "replace", "type", "isNum", "_a", "findClusterBreak", "values", "t", "id", "pos", "flatten", "Text", "dist", "cache", "blockWrappers", "marks", "tile", "decorations", "from", "to", "offset", "textHeight", "i", "content", "child", "scrollIntoView", "base", "handlers", "observers", "insert", "event", "data", "_b", "QueryType", "DecorationComparator", "gap", "key", "view", "config", "shift", "meta", "command", "codePointAt", "codePointSize", "cmd", "a", "t", "_a", "i", "values", "_a", "_b", "config", "t", "space", "top", "elt", "top", "values", "config", "gutter", "cur", "gutters", "asArray", "marker", "elt", "a", "event", "number", "marks", "Range", "config", "parser", "bracketed", "name", "id", "types", "IterMode", "data", "_a", "mounted", "cur", "cache", "nodeSet", "children", "positions", "node", "buffer", "contextHash", "length", "lookAhead", "base", "pair", "nodeSize", "nodeStart", "from", "to", "off", "string", "done", "inner", "r", "pos", "a", "name", "base", "t", "a", "sameArray", "config", "tags", "cur", "hasChild", "rangeFrom", "rangeTo", "name", "values", "data", "parser", "name", "top", "base", "_a", "doc", "stringStart", "parser", "_a", "language", "name", "a", "values", "cur", "base", "lineEnd", "space", "closing", "cur", "lineEnd", "a", "_a", "from", "to", "a", "values", "config", "baseTheme$1", "baseTheme$1", "values", "from", "to", "baseTheme", "decorations", "config", "cur", "matching", "bracket", "pos", "string", "indentUnit", "_a", "parser", "data", "line", "indentation", "off", "eol", "rangeEnd", "id", "name", "t", "config", "data", "tokens", "comment", "indent", "empty", "isAdjacent", "a", "config", "json", "command", "_a", "_b", "json", "none", "a", "isAdjacent", "t", "_f", "config", "bracket", "space", "matching", "cur", "findClusterBreak", "findClusterBreak", "nextChar", "lineEnd", "Text", "findClusterBreak", "dist", "indent", "insert", "Text", "changes", "cur", "space", "types", "words", "score", "_a", "codePointAt", "codePointSize", "a", "space", "config", "content", "off", "applyCompletion", "options", "id", "scrollIntoView", "name", "compare", "cur", "none", "noAttrs", "baseTheme", "indent", "pos", "m", "snippet", "Text", "inputHandler", "insert", "codePointSize", "codePointAt", "tokens", "bracket", "doc", "config", "content", "baseTheme", "score", "_a", "parser", "base", "count", "top", "off", "i", "Type", "data", "id", "readToken", "dialect", "FragmentCursor", "nodeSet", "Parse", "a", "tokens", "insert", "name", "config", "t", "prec", "values", "name", "getAttrs", "tags", "id", "attrs", "dash", "id", "callee", "parser", "name", "tags", "identifier", "doc", "_a", "callee", "cur", "node", "parser", "newline", "space", "slash", "question", "bracketL", "spec_identifier", "parser", "id", "doc", "top", "node", "name", "parser", "_a", "name", "config", "doc", "android", "base", "empty", "insert", "a", "elementName", "doc", "name", "identifier", "elt", "_a", "base", "config", "cur", "dialect", "autoCloseTags", "selfClosers", "_b", "to", "insert", "hash", "nodeSet", "Type", "content", "Line", "indent", "elt", "space", "count", "marks", "base", "empty", "off", "parser", "FragmentCursor", "eol", "none", "top", "rangeEnd", "t", "config", "nodeTypes", "name", "id", "rm", "spec", "a", "conc", "Element", "comment", "cur", "node", "m", "next", "parser", "heading", "doc", "number", "cur", "node", "content", "space", "config", "insert", "changes", "empty", "_a", "newline", "space", "hash", "dot", "backslash", "isHex", "spaces", "Context", "indent", "topIndent", "off", "spec_identifier", "parser", "cache", "ScopeNodes", "defID", "id", "gatherCompletions", "_a", "_b", "getScope", "doc", "top", "node", "name", "Identifier", "dontComplete", "localCompletionSource", "snippets", "base", "parser", "parser", "parser", "LineComment", "BlockComment", "String$1", "Number", "Bool", "ParenL", "BraceL", "BracketL", "Punctuation", "Identifier", "Type", "isAlpha", "keywords", "types", "defaults", "dialect", "_a", "cur", "doc", "id", "name", "top", "empty", "keyword", "parser", "language", "config", "eof", "Tag", "BracketL", "BraceL", "Context", "findColumn", "indentation", "indent", "off", "newlines", "parser", "parser", "identifier", "String", "Number", "newline", "carriageReturn", "space", "tab", "slash", "semicolon", "spec_identifier", "parser", "snippets", "cache", "ScopeNodes", "cur", "gatherCompletions", "getScope", "doc", "top", "node", "name", "Identifier", "dontComplete", "localCompletionSource", "parser", "kwCompletion", "keywords", "Dot", "count", "spec_idLine truncated
|
||||
}
|
||||
Reference in new issue
Block a user