Constructor
new ve.dm.Surface(doc, [attachedRoot], [config])
#
DataModel surface for a node within a document
Methods do not check that ranges actually lie inside the surfaced node
Parameters:
Name | Type | Attributes | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
doc |
ve.dm.Document | Document model to create surface for |
|||||||||||
attachedRoot |
ve.dm.BranchNode |
optional |
Branch node which is editable; default is document node |
||||||||||
config |
Object |
optional |
Configuration options Properties:
|
- Mixes in:
- Source:
DataModel surface for a node within a document
Methods do not check that ranges actually lie inside the surfaced node
Methods
addInsertionAnnotations(annotations)
#
Add an annotation to be used upon insertion.
Parameters:
Name | Type | Description |
---|---|---|
annotations |
ve.dm.Annotation | ve.dm.AnnotationSet | Insertion annotation to add |
- Source:
Fires:
applyAllStaging()
#
Apply the staging stack until empty
- Source:
applyStaging()
#
Apply a level of staging from the staging stack
- Source:
Fires:
breakpoint() → {boolean}
#
Set a history state breakpoint.
- Source:
Returns:
A breakpoint was added
- Type
- boolean
Fires:
canRedo() → {boolean}
#
Check if redo is allowed in the current state.
- Source:
Returns:
Redo is allowed
- Type
- boolean
canUndo() → {boolean}
#
Check if undo is allowed in the current state.
- Source:
Returns:
Undo is allowed
- Type
- boolean
change(transactions, [selection])
#
Apply a transactions and selection changes to the document.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
transactions |
ve.dm.Transaction
|
Array.<ve.dm.Transaction>
|
null
|
One or more transactions to process, or null to process none |
|
selection |
ve.dm.Selection |
optional |
Selection to apply |
- Source:
changeInternal(transactions, [selection], [skipUndoStack])private
#
Internal implementation of change(). Do not use this, use change() instead.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
transactions |
ve.dm.Transaction
|
Array.<ve.dm.Transaction>
|
null
|
|||
selection |
ve.dm.Selection |
optional |
||
skipUndoStack |
boolean |
optional |
false | If true, do not modify the undo stack. Used by undo/redo |
- Source:
Fires:
createSynchronizer(documentId, [config])
#
Create a surface synchronizer.
Must be created before the surface model is added to a view.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
documentId |
string | Document ID |
|
config |
Object |
optional |
Configuration options |
- Source:
doesStagingAllowUndo() → {boolean|undefined
}
#
undefined
}
#
Undo is allowed at the current staging stack depth
- Source:
Returns:
Undo is allowed, or undefined if not staging
- Type
-
boolean
|
undefined
emitContextChange()private
#
Emit a contextChange event. If #startQueueingContextChanges has been called, then the event is deferred until #stopQueueingContextChanges is called.
- Source:
Fires:
fixupRangeForLinks(range) → {ve.Range}
#
getAttachedRoot() → {ve.dm.BranchNode}
#
Get the surfaced node
- Deprecated:
- Use getDocument().getAttachedRoot()
- Source:
Returns:
The surfaced node
- Type
- ve.dm.BranchNode
getAuthorId() → {number}
#
getDocument() → {ve.dm.Document}
#
getDom() → {HTMLDocument|string}
#
Get the DOM representation of the surface's current state.
- Source:
Returns:
HTML document (visual mode) or text (source mode)
- Type
- HTMLDocument | string
getFragment([selection], [noAutoSelect], [excludeInsertions]) → {ve.dm.SurfaceFragment}
#
Get a fragment for a selection.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
selection |
ve.dm.Selection |
optional |
Selection within target document, current selection used by default |
noAutoSelect |
boolean |
optional |
Don't update the surface's selection when making changes |
excludeInsertions |
boolean |
optional |
Exclude inserted content at the boundaries when updating range |
- Source:
Returns:
Surface fragment
getHistory() → {Array.<ve.dm.Surface.UndoStackItem>}
#
Get a list of all applied history states.
- Source:
Returns:
List of applied transaction stacks
- Type
- Array.<ve.dm.Surface.UndoStackItem>
getHtml() → {string}
#
Get the HTML representation of the surface's current state.
- Source:
Returns:
HTML
- Type
- string
getInsertionAnnotations() → {ve.dm.AnnotationSet}
#
Get annotations that will be used upon insertion.
- Source:
Returns:
Insertion annotations
- Type
- ve.dm.AnnotationSet
getLinearFragment(range, [noAutoSelect], [excludeInsertions]) → {ve.dm.SurfaceFragment}
#
Get a fragment for a linear selection's range.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
range |
ve.Range | Selection's range |
|
noAutoSelect |
boolean |
optional |
Don't update the surface's selection when making changes |
excludeInsertions |
boolean |
optional |
Exclude inserted content at the boundaries when updating range |
- Source:
Returns:
Surface fragment
getModifiedRanges([options]) → {Array.<ve.Range>}
#
Get a minimal set of ranges which have been modified by changes to the surface.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
optional |
Options Properties:
|
- Source:
Returns:
Modified ranges
getOffsetFromSourceOffset(offset) → {number}
#
Get a VE source-mode surface offset from a plaintext source offset.
Parameters:
Name | Type | Description |
---|---|---|
offset |
number | Source text offset |
- Source:
Returns:
Surface offset
- Type
- number
Throws:
-
Offset out of bounds
- Type
- Error
getRangeFromSourceOffsets(from, [to]) → {ve.Range}
#
Get a VE source-mode surface range from plaintext source offsets.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
from |
number | Source text from offset |
|
to |
number |
optional |
Source text to offset, omit for a collapsed range |
- Source:
Returns:
Source surface offset
- Type
- ve.Range
getSelectedNode() → {ve.dm.Node|null
}
#
null
}
#
Get the cached selected node covering the current selection, or null
- Source:
Returns:
Selected node
- Type
-
ve.dm.Node
|
null
getSelectedNodeFromSelection([selection]) → {ve.dm.Node|null
}
#
null
}
#
Get the selected node covering a specific selection, or null
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
selection |
ve.dm.Selection |
optional |
Selection, defaults to the current selection |
- Source:
Returns:
Selected node
- Type
-
ve.dm.Node
|
null
getSelection() → {ve.dm.Selection}
#
getSourceOffsetFromOffset(offset) → {number}
#
Get a plaintext source offset from a VE source-mode surface offset.
Parameters:
Name | Type | Description |
---|---|---|
offset |
number | Surface offset |
- Source:
Returns:
Source text offset
- Type
- number
Throws:
-
Offset out of bounds
- Type
- Error
getStaging() → {ve.dm.Surface.StagingState|undefined
}
#
undefined
}
#
Get the staging state at the current staging stack depth
- Source:
Returns:
staging Staging state object, or undefined if not staging
- Type
-
ve.dm.Surface.StagingState
|
undefined
getStagingTransactions() → {Array.<ve.dm.Transaction>|undefined
}
#
undefined
}
#
Get the staging transactions at the current staging stack depth
The array is returned by reference so it can be pushed to.
- Source:
Returns:
Staging transactions, or undefined if not staging
- Type
-
Array.<ve.dm.Transaction>
|
undefined
Get the staging transactions at the current staging stack depth
The array is returned by reference so it can be pushed to.
getTranslatedSelection() → {ve.dm.Selection}
#
Get the selection translated for the transaction that's being committed, if any.
- Source:
Returns:
Current selection translated for new transaction
- Type
- ve.dm.Selection
hasBeenModified() → {boolean}
#
Check if the surface has been modified.
This only checks if there are transactions which haven't been undone.
- Source:
Returns:
The surface has been modified
- Type
- boolean
initialize()
#
Initialize the surface model
- Source:
Fires:
isMultiUser() → {boolean}
#
Check if the surface is in multi-user mode
- Source:
Returns:
Surface is in multi-user mode
- Type
- boolean
isReadOnly() → {boolean}
#
isStaging() → {boolean}
#
If the surface in staging mode.
- Source:
Returns:
The surface in staging mode
- Type
- boolean
onDocumentPreCommit(tx)
#
Update translatedSelection early (before the commit actually occurs)
This is so ve.ce.ContentBranchNode#getRenderedContents can consider the translated selection for unicorn rendering.
Parameters:
Name | Type | Description |
---|---|---|
tx |
ve.dm.Transaction | Transaction that's about to be committed |
- Source:
Update translatedSelection early (before the commit actually occurs)
This is so ve.ce.ContentBranchNode#getRenderedContents can consider the translated selection for unicorn rendering.
onDocumentTransact(tx)
#
Respond to transactions processed on the document by translating the selection and updating other state.
Parameters:
Name | Type | Description |
---|---|---|
tx |
ve.dm.Transaction | Transaction that was processed |
- Source:
Fires:
Respond to transactions processed on the document by translating the selection and updating other state.
popAllStaging() → {Array.<ve.dm.Transaction>|undefined
}
#
undefined
}
#
Pop the staging stack until empty
- Source:
Returns:
Staging transactions, or undefined if not staging
- Type
-
Array.<ve.dm.Transaction>
|
undefined
popStaging() → {Array.<ve.dm.Transaction>|undefined
}
#
undefined
}
#
Pop a level of staging from the staging stack
- Source:
Returns:
Staging transactions, or undefined if not staging
- Type
-
Array.<ve.dm.Transaction>
|
undefined
Fires:
pushStaging([allowUndo])
#
Push another level of staging to the staging stack
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
allowUndo |
boolean |
optional |
false | Allow undo while staging |
- Source:
Fires:
redo()
#
Step forwards in history.
- Source:
Fires:
removeDocStateAndChanges()
#
Remove the auto-saved document state and stashed changes
- Source:
removeInsertionAnnotations(annotations)
#
Remove an annotation from those that will be used upon insertion.
Parameters:
Name | Type | Description |
---|---|---|
annotations |
ve.dm.Annotation | ve.dm.AnnotationSet | Insertion annotation to remove |
- Source:
Fires:
resetHistoryTrackingInterval()
#
Reset the timer for automatic history-tracking
- Source:
restoreChanges() → {boolean}
#
Restore transactions from session storage
- Source:
Returns:
Some changes were restored
- Type
- boolean
Throws:
-
Failed to restore auto-saved session
- Type
- Error
setAuthorId(authorId)
#
Set the author ID
Parameters:
Name | Type | Description |
---|---|---|
authorId |
number | The new author ID |
- Source:
setAutosaveDocId(docId)
#
Set an document ID for autosave.
For session storage this is only required if there is more than one document on the page.
Parameters:
Name | Type | Description |
---|---|---|
docId |
string | Document ID. |
- Source:
setInsertionAnnotations(annotations)
#
Set annotations that will be used upon insertion.
Parameters:
Name | Type | Description |
---|---|---|
annotations |
ve.dm.AnnotationSet
|
null
|
Insertion annotations to use or null to disable them |
- Source:
Fires:
setLinearSelection(range)
#
Set a linear selection at a specified range on the model
Parameters:
Name | Type | Description |
---|---|---|
range |
ve.Range | Range to create linear selection at |
- Source:
setMultiUser(multiUser)
#
Set the surface multi-user mode
Parameters:
Name | Type | Description |
---|---|---|
multiUser |
boolean | Multi-user mode |
- Source:
setNullSelection()
#
Set a null selection on the model
- Source:
setReadOnly(readOnly)
#
Set the read-only state of the surface
Parameters:
Name | Type | Description |
---|---|---|
readOnly |
boolean | Make surface read-only |
- Source:
setSelection(selection)
#
Change the selection
Parameters:
Name | Type | Description |
---|---|---|
selection |
ve.dm.Selection | New selection |
- Source:
Fires:
setStorage(storage, [storageExpiry])
#
Set the storage interface for autosave
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
storage |
ve.init.ConflictableStorage | Storage interface |
|
storageExpiry |
number |
optional |
Storage expiry time in seconds |
- Source:
startHistoryTracking()
#
Start tracking state changes in history.
- Source:
startQueueingContextChanges()private
#
Start queueing up calls to #emitContextChange until #stopQueueingContextChanges is called. While queueing is active, contextChanges are also collapsed, so if #emitContextChange is called multiple times, only one contextChange event will be emitted by #stopQueueingContextChanges.
this.emitContextChange(); // emits immediately
this.startQueueingContextChanges();
this.emitContextChange(); // doesn't emit
this.emitContextChange(); // doesn't emit
this.stopQueueingContextChanges(); // emits one contextChange event
- Source:
startStoringChanges()
#
Start storing changes after every undoStackChange
- Source:
stopHistoryTracking()
#
Stop tracking state changes in history.
- Source:
stopQueueingContextChanges()private
#
Stop queueing contextChange events. If #emitContextChange was called previously, a contextChange event will now be emitted. Any future calls to #emitContextChange will once again emit the event immediately.
- Source:
Fires:
stopStoringChanges()
#
Stop storing changes
- Source:
storeChanges()
#
Store latest transactions into session storage
- Source:
Fires:
storeDocState([state], [html]) → {boolean}
#
Store a snapshot of the current document state.
If custom HTML is provided, the caller must manually set the lastStoredChange pointer to the correct value.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
state |
Object |
optional |
JSONable object describing document state |
html |
string |
optional |
Document HTML, will generate from current state if not provided |
- Source:
Returns:
Doc state was successfully stored
- Type
- boolean
storeDocStorage()
#
Store persistent document storage into session storage
- Source:
truncateUndoStack()
#
Prevent future states from being redone.
Callers should eventually emit a 'history' event after using this method.
- Source:
Fires:
undo()
#
Step backwards in history.
- Source:
Fires:
updateDocState(state) → {boolean}
#
Update stored document state metadata, without changing the HTML
Parameters:
Name | Type | Description |
---|---|---|
state |
Object | Document state |
- Source:
Returns:
Document metadata was successfully stored
- Type
- boolean
updateExpiry([skipKeys])
#
Update the expiry value of keys in use
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
skipKeys |
Array.<string> |
optional |
Keys to skip (because they have just been updated) |
- Source:
Type Definitions
StagingState
#
Type:
Properties:
Name | Type | Description |
---|---|---|
transactions |
Array.<ve.dm.Transaction> | Staging transactions |
selectionBefore |
ve.dm.Selection | Selection before transactions were applied |
allowUndo |
boolean | Allow undo while staging |
- Source:
UndoStackItem
#
Type:
Properties:
Name | Type | Description |
---|---|---|
start |
number | |
transactions |
Array.<ve.dm.Transaction> | |
selection |
ve.dm.Selection | |
selectionBefore |
ve.dm.Selection |
- Source:
Events
autosaveFailed()
#
Auto-save failed to store a change
- Source:
blur()
#
The selection was just set to a null selection
- Source:
contextChange()
#
- Source:
documentUpdate(tx)
#
Emitted when a transaction has been processed on the document and the selection has been
translated to account for that transaction. You should only use this event if you need
to access the selection; in most cases, you should use {ve.dm
.Document#event-transact}.
Parameters:
Name | Type | Description |
---|---|---|
tx |
ve.dm.Transaction | Transaction that was processed on the document |
- Source:
Emitted when a transaction has been processed on the document and the selection has been translated to account for that transaction.
focus()
#
The selection was just set to a non-null selection
- Source:
history()
#
Emitted when the history stacks change, or the ability to use them changes.
- Source:
insertionAnnotationsChange(insertionAnnotations)
#
Parameters:
Name | Type | Description |
---|---|---|
insertionAnnotations |
ve.dm.AnnotationSet | AnnotationSet being inserted |
- Source:
select(selection)
#
undoStackChange()
#
Emitted when the main undo stack changes (this.undoStack or this.undoIndex).
- Source: