Class: Wiki
core.Wiki
Table of contents
Constructors
Properties
Methods
- addEventListener
- addIndexer
- addTiddler
- addTiddlers
- clearGlobalCache
- compileFilter
- deleteTiddler
- deserializeTiddlers
- dispatchEvent
- each
- filterTiddlers
- generateNewTitle
- getCacheForTiddler
- getChangeCount
- getGlobalCache
- getPluginInfo
- getShadowSource
- getTiddler
- getTiddlerAsJson
- getTiddlerBacklinks
- getTiddlerData
- getTiddlerDataCached
- getTiddlerLinks
- getTiddlerText
- getTiddlers
- getTiddlersAsJson
- importTiddler
- isBinaryTiddler
- isImageTiddler
- isShadowTiddler
- isSystemTiddler
- isTemporaryTiddler
- isVolatileTiddler
- makeTiddlerIterator
- makeTranscludeWidget
- makeWidget
- parseText
- parseTiddler
- removeEventListener
- renderText
- renderTiddler
- setText
- setTiddlerData
- tiddlerExists
Constructors
constructor
• new Wiki(options
): Wiki
Wiki constructor. State is stored in private members that only a small number of privileged accessor methods have direct access. Methods added via the prototype have to use these accessors and cannot access the state data directly.
Parameters
Name | Type | Description |
---|---|---|
options | Object | options include: * enableIndexers - Array of indexer names to enable, or null to use all available indexers |
options.enableIndexers | unknown [] | - |
Returns
Memberof
Wiki
Defined in
Properties
getCreationFields
• getCreationFields: () => { created?
: Date
; creator?
: string
}
Return a hashmap of the fields that should be set when a tiddler is created
Type declaration
▸ (): Object
Return a hashmap of the fields that should be set when a tiddler is created
Returns
Object
Name | Type |
---|---|
created? | Date |
creator? | string |
Defined in
getModificationFields
• getModificationFields: () => { modified?
: Date
; modifier?
: string
}
Return a hashmap of the fields that should be set when a tiddler is modified.
This is used for generating modified
field when modify tiddler using actions like action-setmultiplefields
Type declaration
▸ (): Object
Return a hashmap of the fields that should be set when a tiddler is modified.
This is used for generating modified
field when modify tiddler using actions like action-setmultiplefields
Returns
Object
Name | Type |
---|---|
modified? | Date |
modifier? | string |
Defined in
getTiddlersWithTag
• getTiddlersWithTag: (tag
: string
) => string
[]
Retrieves a list of the tiddler titles that are tagged with a given tag
Type declaration
▸ (tag
): string
[]
Retrieves a list of the tiddler titles that are tagged with a given tag
Parameters
Name | Type |
---|---|
tag | string |
Returns
string
[]
Defined in
Methods
addEventListener
▸ addEventListener(type
, handler
): void
Parameters
Name | Type |
---|---|
type | string |
handler | (event : unknown ) => void | Promise <void > |
Returns
void
Defined in
▸ addEventListener(type
, handler
): void
Parameters
Name | Type |
---|---|
type | "change" |
handler | (change : IChangedTiddlers ) => void | Promise <void > |
Returns
void
Defined in
▸ addEventListener(type
, handler
): void
Parameters
Name | Type |
---|---|
type | "lazyLoad" |
handler | (title : string ) => void | Promise <void > |
Returns
void
Defined in
addIndexer
▸ addIndexer(indexer
, name
): void
Parameters
Name | Type |
---|---|
indexer | unknown |
name | string |
Returns
void
Defined in
addTiddler
▸ addTiddler(tiddler
): void
Create or update tiddler. Update existed tiddler based on the title field.
Parameters
Name | Type |
---|---|
tiddler | Tiddler | Partial <ITiddlerFields > | Partial <ITiddlerFieldsParam > |
Returns
void
Defined in
addTiddlers
▸ addTiddlers(tiddler
): void
Call addTiddler
for each iton of the list, but should passing tiddler.fields
, directly passing tiddler object may failed to add in some cases.
Parameters
Name | Type |
---|---|
tiddler | (Partial <ITiddlerFields > | Partial <ITiddlerFieldsParam >)[] |
Returns
void
Defined in
clearGlobalCache
▸ clearGlobalCache(): void
clear all cache, will be called when a tiddler is changed
Returns
void
Defined in
compileFilter
▸ compileFilter(filterString
): (source?
: (iterator
: SourceIterator
) => void
| string
[] | Record
<string
, unknown
>, widget?
: widget
) => string
[]
Compile filter string to be a function that execute the filter in the wiki. You can pass an optional iterator that provide the input to the returned function. If no iterator is provided, filter will use first operator to get input.
Parameters
Name | Type |
---|---|
filterString | string |
Returns
fn
a function with the signature fn(source,widget) where: source: an iterator function for the source tiddlers, called source(iterator), where iterator is called as iterator(tiddler,title) widget: an optional widget node for retrieving the current tiddler etc.
▸ (source?
, widget?
): string
[]
Parameters
Name | Type |
---|---|
source? | (iterator : SourceIterator ) => void | string [] | Record <string , unknown > |
widget? | widget |
Returns
string
[]
Defined in
deleteTiddler
▸ deleteTiddler(title
): void
Parameters
Name | Type |
---|---|
title | string |
Returns
void
Defined in
deserializeTiddlers
▸ deserializeTiddlers(type
, text
, srcFields?
, options?
): ITiddlerFieldsParam
[]
Extracts tiddlers from a typed block of text, specifying default field values
Parameters
Name | Type |
---|---|
type | string |
text | string |
srcFields? | ITiddlerFieldsParam |
options? | IParseOptions |
Returns
Defined in
dispatchEvent
▸ dispatchEvent(type
, dataOrEvent
): void
Parameters
Name | Type |
---|---|
type | string |
dataOrEvent | unknown |
Returns
void
Defined in
▸ dispatchEvent(type
, change
): void
Parameters
Name | Type |
---|---|
type | "change" |
change | IChangedTiddlers |
Returns
void
Defined in
▸ dispatchEvent(type
, title
): void
Parameters
Name | Type |
---|---|
type | "lazyLoad" |
title | string |
Returns
void
Defined in
each
▸ each(callback
): void
Parameters
Name | Type |
---|---|
callback | (tiddler : Tiddler , title : string ) => void |
Returns
void
Defined in
filterTiddlers
▸ filterTiddlers(filterString
, widget?
, source?
): string
[]
You can use this with makeTiddlerIterator
:
$tw.wiki.filterTiddlers(filter, undefined, $tw.wiki.makeTiddlerIterator(['title']))
This calls compileFilter
Parameters
Name | Type |
---|---|
filterString | string |
widget? | widget |
source? | SourceIterator |
Returns
string
[]
Defined in
generateNewTitle
▸ generateNewTitle(baseTitle
, options
): string
Generate an unused title from the specified base options.prefix must be a string
Parameters
Name | Type |
---|---|
baseTitle | string |
options | Object |
options.prefix? | string |
Returns
string
Defined in
getCacheForTiddler
▸ getCacheForTiddler<T
>(title
, cacheName
, initializer
): T
Return the named cache object for a tiddler. If the cache doesn't exist then the initializer function is invoked to create it
Type parameters
Name |
---|
T |
Parameters
Name | Type | Description |
---|---|---|
title | string | - |
cacheName | string | key of the cache |
initializer | () => T | when cache miss, this will be called to get initial value |
Returns
T
Defined in
getChangeCount
▸ getChangeCount(title
): number
Parameters
Name | Type |
---|---|
title | string |
Returns
number
Defined in
getGlobalCache
▸ getGlobalCache<T
>(cacheName
, initializer
): T
Return a named global cache object. Global cache objects are cleared whenever a tiddler change. You can put anything into the cache.
Type parameters
Name |
---|
T |
Parameters
Name | Type | Description |
---|---|---|
cacheName | string | key of the cache |
initializer | () => T | when cache miss, this will be called to get initial value |
Returns
T
Defined in
getPluginInfo
▸ getPluginInfo(title
): Object
Parameters
Name | Type |
---|---|
title | string |
Returns
Object
Name | Type |
---|---|
tiddlers | Record <string , ITiddlerFields > |
Defined in
getShadowSource
▸ getShadowSource(title
): string
return shadowTiddlers[title].source;
Parameters
Name | Type |
---|---|
title | string |
Returns
string
Defined in
getTiddler
▸ getTiddler<T
>(title
): void
| T
Type parameters
Name | Type |
---|---|
T | extends Tiddler |
Parameters
Name | Type |
---|---|
title | string |
Returns
void
| T
Defined in
getTiddlerAsJson
▸ getTiddlerAsJson(title
): string
Get JSON string of tiddler. Note that this will make lists like tags/list to be string, instead of array. And result is a string, not an object.
Parameters
Name | Type |
---|---|
title | string |
Returns
string
a stringified JSON with type ITiddlerJSONResult. You will need to use JSON.parse
on it.
Defined in
getTiddlerBacklinks
▸ getTiddlerBacklinks(targetTitle
): string
[]
Parameters
Name | Type |
---|---|
targetTitle | string |
Returns
string
[]
Defined in
getTiddlerData
▸ getTiddlerData<D
>(titleOrTiddler
, fallbackData?
): D
Get the content of a tiddler as a JavaScript object. How this is done depends on the type of the tiddler:
application/json: the tiddler JSON is parsed into an object application/x-tiddler-dictionary: the tiddler is parsed as sequence of name:value pairs
Other types currently just return undefined or as same as fallbackData.
titleOrTiddler: string tiddler title or a tiddler object defaultData: default data to be returned if the tiddler is missing or doesn't contain data
Alternative, uncached version of getTiddlerDataCached(). The return value can be mutated freely and reused
Type parameters
Name | Type |
---|---|
D | extends any [] | Record <any , unknown > |
Parameters
Name | Type |
---|---|
titleOrTiddler | string | Tiddler |
fallbackData? | D |
Returns
D
Defined in
getTiddlerDataCached
▸ getTiddlerDataCached<D
>(titleOrTiddler
, fallbackData?
): D
D is any JSON, like JSON object or JSON array
Get the content of a tiddler as a JavaScript object. How this is done depends on the type of the tiddler:
application/json: the tiddler JSON is parsed into an object application/x-tiddler-dictionary: the tiddler is parsed as sequence of name:value pairs
Other types currently just return undefined or as same as fallbackData.
titleOrTiddler: string tiddler title or a tiddler object defaultData: default data to be returned if the tiddler is missing or doesn't contain data
Note that the same value is returned for repeated calls for the same tiddler data. The value is frozen to prevent modification; otherwise modifications would be visible to all callers
Type parameters
Name |
---|
D |
Parameters
Name | Type |
---|---|
titleOrTiddler | string | Tiddler |
fallbackData? | D |
Returns
D
Defined in
getTiddlerLinks
▸ getTiddlerLinks(title
): string
[]
Parameters
Name | Type |
---|---|
title | string |
Returns
string
[]
Defined in
getTiddlerText
▸ getTiddlerText(title
, fallbackText
): string
Get tiddler's text field, with an optional default text. If have _is_skinny field, will just return null (this is a rare case, so not put in the return type for now).
Parameters
Name | Type | Description |
---|---|---|
title | string | will return undefined (or fallback) if the tiddler isn't found |
fallbackText | string | default text when text field is empty or undefined |
Returns
string
Defined in
▸ getTiddlerText(title
, fallbackText?
): string
Parameters
Name | Type |
---|---|
title | string |
fallbackText? | string |
Returns
string
Defined in
getTiddlers
▸ getTiddlers(): string
[]
Get full list of tiddler titles in the wiki
Returns
string
[]
Defined in
getTiddlersAsJson
▸ getTiddlersAsJson(filter
, spaces?
): string
Get JSON string of tiddlers. Note that this will make lists like tags/list to be string, instead of array. And result is a string, not an array.
Parameters
Name | Type | Description |
---|---|---|
filter | string | Filter string |
spaces? | string | Last arg of JSON.stringify , default is ' ' |
Returns
string
a stringified JSON with type ITiddlerJSONResult. You will need to use JSON.parse
on it.
Defined in
importTiddler
▸ importTiddler(title
): boolean
Like addTiddler() except it will silently reject any plugin tiddlers that are older than the currently loaded version. Returns true if the tiddler was imported
Parameters
Name | Type |
---|---|
title | string |
Returns
boolean
Defined in
isBinaryTiddler
▸ isBinaryTiddler(title
): boolean
Parameters
Name | Type |
---|---|
title | string |
Returns
boolean
Defined in
isImageTiddler
▸ isImageTiddler(title
): boolean
Parameters
Name | Type |
---|---|
title | string |
Returns
boolean
Defined in
isShadowTiddler
▸ isShadowTiddler(title
): boolean
Determines if a tiddler is a shadow tiddler, regardless of whether it has been overridden by a real tiddler
Parameters
Name | Type |
---|---|
title | string |
Returns
boolean
Defined in
isSystemTiddler
▸ isSystemTiddler(title
): boolean
Parameters
Name | Type |
---|---|
title | string |
Returns
boolean
Defined in
isTemporaryTiddler
▸ isTemporaryTiddler(title
): boolean
Parameters
Name | Type |
---|---|
title | string |
Returns
boolean
Defined in
isVolatileTiddler
▸ isVolatileTiddler(title
): boolean
Parameters
Name | Type |
---|---|
title | string |
Returns
boolean
Defined in
makeTiddlerIterator
▸ makeTiddlerIterator(titles
): SourceIterator
Returns a function iterator(callback) that iterates through the specified titles, and invokes the callback with callback(tiddler,title)
Parameters
Name | Type |
---|---|
titles | string [] |
Returns
Defined in
makeTranscludeWidget
▸ makeTranscludeWidget(title
, options
): widget
Make a widget tree for transclusion
Parameters
Name | Type |
---|---|
title | string |
options | { children? : widget [] ; field? : string ; importPageMacros? : boolean ; importVariables? : string ; mode? : "inline" | "block" ; recursionMarker? : "yes" | "no" } & IMakeWidgetOptions |
Returns
Params
title: target tiddler title
Params
options: as for wiki.makeWidget() plus:
- options.field: optional field to transclude (defaults to "text")
- options.mode: transclusion mode "inline" or "block"
- options.recursionMarker : optional flag to set a recursion marker, defaults to "yes"
- options.children: optional array of children for the transclude widget
- options.importVariables: optional importvariables filter string for macros to be included
- options.importPageMacros: optional boolean; if true, equivalent to passing "[[$:/core/ui/PageMacros]] [all[shadows+tiddlers]tag[$:/tags/Macro]!has[draft.of]]" to options.importVariables
Defined in
makeWidget
▸ makeWidget(parser
, options?
): widget
Make a widget tree for a parse tree
Parameters
Name | Type |
---|---|
parser | Object |
parser.tree | IParseTreeNode [] |
options? | IMakeWidgetOptions |
Returns
Params
parser: parser object
Params
options: see below Options include: document: optional document to use variables: hashmap of variables to set parentWidget: optional parent widget for the root node
Defined in
parseText
▸ parseText(type
, text
, options?
): WikiParser
Parse a block of text of a specified MIME type
Parameters
Name | Type |
---|---|
type | string |
text | string |
options? | IParseOptions |
Returns
Defined in
parseTiddler
▸ parseTiddler(title
, options?
): WikiParser
Parse a tiddler according to its MIME type
Parameters
Name | Type |
---|---|
title | string |
options? | IParseOptions |
Returns
Defined in
removeEventListener
▸ removeEventListener(type
, handler
): void
Parameters
Name | Type |
---|---|
type | string |
handler | (event : any ) => void | Promise <void > |
Returns
void
Defined in
renderText
▸ renderText(outputType
, textType
, text
, options?
): string
Parse text in a specified format and render it into another format
Parameters
Name | Type | Description |
---|---|---|
outputType | OutputMimeTypes | content type for the output |
textType | string | content type of the input text |
text | string | input text |
options? | Partial <IMakeWidgetOptions > & IParseOptions | see below, Options includes: - variables: hashmap of variables to set - parentWidget: optional parent widget for the root node |
Returns
string
Defined in
renderTiddler
▸ renderTiddler(outputType
, title
, options?
): string
Parse text from a tiddler and render it into another format outputType: content type for the output title: title of the tiddler to be rendered options: see below Options include: variables: hashmap of variables to set parentWidget: optional parent widget for the root node
Parameters
Name | Type |
---|---|
outputType | OutputMimeTypes |
title | string |
options? | IRenderOptions |
Returns
string
Defined in
setText
▸ setText(title
, field?
, index?
, value?
, options?
): void
Set tiddler text of any field.
Parameters
Name | Type | Description |
---|---|---|
title | string | title of tiddler |
field? | string | field name to set |
index? | string | data index(key) to set, if you are setting a JSON data tiddler. Be undefined if you are just setting a normal tiddler's field, this will be most of the case. |
value? | string | text content to set |
options? | Object | options, see tiddlywiki dev doc for details |
options.suppressTimestamp? | boolean | - |
Returns
void
Defined in
setTiddlerData
▸ setTiddlerData(title
, data?
, fields?
, options?
): void
Set JSON tiddler, Object in data field will be JSON.stringify and put into the text.
This will make tiddler to be JSON data tiddler "type":"application/json"
, so if you just want to modify existed tiddler's data, use addTiddler
instead.
Parameters
Name | Type |
---|---|
title | string |
data? | object |
fields? | ITiddlerFieldsParam |
options? | any |
Returns
void
Defined in
tiddlerExists
▸ tiddlerExists(title
): boolean
Test for the existence of a tiddler (excludes shadow tiddlers)
Parameters
Name | Type |
---|---|
title | string |
Returns
boolean