Skip to main content

tw5-typed / core / Wiki

Class: Wiki

core.Wiki

Table of contents

Constructors

Properties

Methods

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

NameTypeDescription
optionsObjectoptions include: * enableIndexers - Array of indexer names to enable, or null to use all available indexers
options.enableIndexersunknown[]-

Returns

Wiki

Memberof

Wiki

Defined in

src/wiki/index.d.ts:34

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

NameType
created?Date
creator?string

Defined in

src/modules/wiki.d.ts:19


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

NameType
modified?Date
modifier?string

Defined in

src/modules/wiki.d.ts:24


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
NameType
tagstring
Returns

string[]

Defined in

src/modules/wiki.d.ts:28

Methods

addEventListener

addEventListener(type, handler): void

Parameters

NameType
typestring
handler(event: unknown) => void | Promise<void>

Returns

void

Defined in

src/wiki/index.d.ts:334

addEventListener(type, handler): void

Parameters

NameType
type"change"
handler(change: IChangedTiddlers) => void | Promise<void>

Returns

void

Defined in

src/wiki/index.d.ts:338

addEventListener(type, handler): void

Parameters

NameType
type"lazyLoad"
handler(title: string) => void | Promise<void>

Returns

void

Defined in

src/wiki/index.d.ts:342


addIndexer

addIndexer(indexer, name): void

Parameters

NameType
indexerunknown
namestring

Returns

void

Defined in

src/wiki/index.d.ts:35


addTiddler

addTiddler(tiddler): void

Create or update tiddler. Update existed tiddler based on the title field.

Parameters

NameType
tiddlerTiddler | Partial<ITiddlerFields> | Partial<ITiddlerFieldsParam>

Returns

void

Defined in

src/wiki/index.d.ts:132


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

NameType
tiddler(Partial<ITiddlerFields> | Partial<ITiddlerFieldsParam>)[]

Returns

void

Defined in

src/wiki/index.d.ts:138


clearGlobalCache

clearGlobalCache(): void

clear all cache, will be called when a tiddler is changed

Returns

void

Defined in

src/wiki/index.d.ts:76


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

NameType
filterStringstring

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
NameType
source?(iterator: SourceIterator) => void | string[] | Record<string, unknown>
widget?widget
Returns

string[]

Defined in

src/wiki/index.d.ts:85


deleteTiddler

deleteTiddler(title): void

Parameters

NameType
titlestring

Returns

void

Defined in

src/wiki/index.d.ts:54


deserializeTiddlers

deserializeTiddlers(type, text, srcFields?, options?): ITiddlerFieldsParam[]

Extracts tiddlers from a typed block of text, specifying default field values

Parameters

NameType
typestring
textstring
srcFields?ITiddlerFieldsParam
options?IParseOptions

Returns

ITiddlerFieldsParam[]

Defined in

src/wiki/index.d.ts:227


dispatchEvent

dispatchEvent(type, dataOrEvent): void

Parameters

NameType
typestring
dataOrEventunknown

Returns

void

Defined in

src/wiki/index.d.ts:347

dispatchEvent(type, change): void

Parameters

NameType
type"change"
changeIChangedTiddlers

Returns

void

Defined in

src/wiki/index.d.ts:351

dispatchEvent(type, title): void

Parameters

NameType
type"lazyLoad"
titlestring

Returns

void

Defined in

src/wiki/index.d.ts:355


each

each(callback): void

Parameters

NameType
callback(tiddler: Tiddler, title: string) => void

Returns

void

Defined in

src/wiki/index.d.ts:55


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

NameType
filterStringstring
widget?widget
source?SourceIterator

Returns

string[]

Defined in

src/wiki/index.d.ts:113


generateNewTitle

generateNewTitle(baseTitle, options): string

Generate an unused title from the specified base options.prefix must be a string

Parameters

NameType
baseTitlestring
optionsObject
options.prefix?string

Returns

string

Defined in

src/wiki/index.d.ts:327


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

NameTypeDescription
titlestring-
cacheNamestringkey of the cache
initializer() => Twhen cache miss, this will be called to get initial value

Returns

T

Defined in

src/wiki/index.d.ts:68


getChangeCount

getChangeCount(title): number

Parameters

NameType
titlestring

Returns

number

Defined in

src/wiki/index.d.ts:322


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

NameTypeDescription
cacheNamestringkey of the cache
initializer() => Twhen cache miss, this will be called to get initial value

Returns

T

Defined in

src/wiki/index.d.ts:62


getPluginInfo

getPluginInfo(title): Object

Parameters

NameType
titlestring

Returns

Object

NameType
tiddlersRecord<string, ITiddlerFields>

Defined in

src/wiki/index.d.ts:321


getShadowSource

getShadowSource(title): string

return shadowTiddlers[title].source;

Parameters

NameType
titlestring

Returns

string

Defined in

src/wiki/index.d.ts:318


getTiddler

getTiddler<T>(title): void | T

Type parameters

NameType
Textends Tiddler

Parameters

NameType
titlestring

Returns

void | T

Defined in

src/wiki/index.d.ts:36


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

NameType
titlestring

Returns

string

a stringified JSON with type ITiddlerJSONResult. You will need to use JSON.parse on it.

Defined in

src/wiki/index.d.ts:53


getTiddlerBacklinks(targetTitle): string[]

Parameters

NameType
targetTitlestring

Returns

string[]

Defined in

src/wiki/index.d.ts:319


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

NameType
Dextends any[] | Record<any, unknown>

Parameters

NameType
titleOrTiddlerstring | Tiddler
fallbackData?D

Returns

D

Defined in

src/wiki/index.d.ts:163


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

NameType
titleOrTiddlerstring | Tiddler
fallbackData?D

Returns

D

Defined in

src/wiki/index.d.ts:182


getTiddlerLinks(title): string[]

Parameters

NameType
titlestring

Returns

string[]

Defined in

src/wiki/index.d.ts:320


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

NameTypeDescription
titlestringwill return undefined (or fallback) if the tiddler isn't found
fallbackTextstringdefault text when text field is empty or undefined

Returns

string

Defined in

src/wiki/index.d.ts:148

getTiddlerText(title, fallbackText?): string

Parameters

NameType
titlestring
fallbackText?string

Returns

string

Defined in

src/wiki/index.d.ts:149


getTiddlers

getTiddlers(): string[]

Get full list of tiddler titles in the wiki

Returns

string[]

Defined in

src/wiki/index.d.ts:40


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

NameTypeDescription
filterstringFilter string
spaces?stringLast 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

src/wiki/index.d.ts:47


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

NameType
titlestring

Returns

boolean

Defined in

src/wiki/index.d.ts:316


isBinaryTiddler

isBinaryTiddler(title): boolean

Parameters

NameType
titlestring

Returns

boolean

Defined in

src/wiki/index.d.ts:308


isImageTiddler

isImageTiddler(title): boolean

Parameters

NameType
titlestring

Returns

boolean

Defined in

src/wiki/index.d.ts:309


isShadowTiddler

isShadowTiddler(title): boolean

Determines if a tiddler is a shadow tiddler, regardless of whether it has been overridden by a real tiddler

Parameters

NameType
titlestring

Returns

boolean

Defined in

src/wiki/index.d.ts:307


isSystemTiddler

isSystemTiddler(title): boolean

Parameters

NameType
titlestring

Returns

boolean

Defined in

src/wiki/index.d.ts:310


isTemporaryTiddler

isTemporaryTiddler(title): boolean

Parameters

NameType
titlestring

Returns

boolean

Defined in

src/wiki/index.d.ts:311


isVolatileTiddler

isVolatileTiddler(title): boolean

Parameters

NameType
titlestring

Returns

boolean

Defined in

src/wiki/index.d.ts:312


makeTiddlerIterator

makeTiddlerIterator(titles): SourceIterator

Returns a function iterator(callback) that iterates through the specified titles, and invokes the callback with callback(tiddler,title)

Parameters

NameType
titlesstring[]

Returns

SourceIterator

Defined in

src/wiki/index.d.ts:100


makeTranscludeWidget

makeTranscludeWidget(title, options): widget

Make a widget tree for transclusion

Parameters

NameType
titlestring
options{ children?: widget[] ; field?: string ; importPageMacros?: boolean ; importVariables?: string ; mode?: "inline" | "block" ; recursionMarker?: "yes" | "no" } & IMakeWidgetOptions

Returns

widget

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

src/wiki/index.d.ts:287


makeWidget

makeWidget(parser, options?): widget

Make a widget tree for a parse tree

Parameters

NameType
parserObject
parser.treeIParseTreeNode[]
options?IMakeWidgetOptions

Returns

widget

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

src/wiki/index.d.ts:271


parseText

parseText(type, text, options?): WikiParser

Parse a block of text of a specified MIME type

Parameters

NameType
typestring
textstring
options?IParseOptions

Returns

WikiParser

Defined in

src/wiki/index.d.ts:216


parseTiddler

parseTiddler(title, options?): WikiParser

Parse a tiddler according to its MIME type

Parameters

NameType
titlestring
options?IParseOptions

Returns

WikiParser

Defined in

src/wiki/index.d.ts:205


removeEventListener

removeEventListener(type, handler): void

Parameters

NameType
typestring
handler(event: any) => void | Promise<void>

Returns

void

Defined in

src/wiki/index.d.ts:329


renderText

renderText(outputType, textType, text, options?): string

Parse text in a specified format and render it into another format

Parameters

NameTypeDescription
outputTypeOutputMimeTypescontent type for the output
textTypestringcontent type of the input text
textstringinput text
options?Partial<IMakeWidgetOptions> & IParseOptionssee below, Options includes: - variables: hashmap of variables to set - parentWidget: optional parent widget for the root node

Returns

string

Defined in

src/wiki/index.d.ts:256


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

NameType
outputTypeOutputMimeTypes
titlestring
options?IRenderOptions

Returns

string

Defined in

src/wiki/index.d.ts:242


setText

setText(title, field?, index?, value?, options?): void

Set tiddler text of any field.

Parameters

NameTypeDescription
titlestringtitle of tiddler
field?stringfield name to set
index?stringdata 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?stringtext content to set
options?Objectoptions, see tiddlywiki dev doc for details
options.suppressTimestamp?boolean-

Returns

void

Defined in

src/wiki/index.d.ts:195


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

NameType
titlestring
data?object
fields?ITiddlerFieldsParam
options?any

Returns

void

Defined in

src/wiki/index.d.ts:122


tiddlerExists

tiddlerExists(title): boolean

Test for the existence of a tiddler (excludes shadow tiddlers)

Parameters

NameType
titlestring

Returns

boolean

Defined in

src/wiki/index.d.ts:305