Wiki source code of Front-End Document API

Last modified by Pierre Jeanjean on 2026/03/23 16:18

Show last authors
1 The ##DocumentService## provides operations to access information about the current document, to change the current document, and to refresh the current document content.
2
3 {{code language="typescript"}}
4 /**
5 * Provide the operation to access a document.
6 *
7 * @since 18.0.0RC1
8 */
9 interface DocumentService {
10 /**
11 * @returns the reference to the current document, the current document changes when setCurrentDocument is called
12 */
13 getCurrentDocument(): Ref<PageData | undefined>;
14
15 /**
16 * Returns a reference the document reference for the current document.
17 *
18 * @since 18.0.0RC1
19 */
20 getCurrentDocumentReference(): Ref<DocumentReference | undefined>;
21
22 /**
23 * Returns a serialized string of {@link getCurrentDocumentReference}.
24 *
25 * @since 18.0.0RC1
26 */
27 getCurrentDocumentReferenceString(): Ref<string | undefined>;
28
29 /**
30 * @returns the revision of the current document, or undefined if it's the last one
31 * @since 18.0.0RC1
32 */
33 getCurrentDocumentRevision(): Ref<string | undefined>;
34
35 /**
36 * @returns the current document action
37 * @since 18.0.0RC1
38 */
39 getCurrentDocumentAction(): Ref<string | undefined>;
40
41 /**
42 * @returns a ref to the loading state. true when the page is loading, false otherwise
43 */
44 isLoading(): Ref<boolean>;
45
46 /**
47 * @returns a ref to the error for the loading of the current document. undefined if no error happened
48 */
49 getError(): Ref<Error | undefined>;
50
51 /**
52 * Update the reference of the latest document.
53 * @param documentReference - the current document reference
54 * @param action - the current document action (default: "view")
55 * @param revision - the revision of the document, undefined for latest
56 * @since 18.0.0RC1
57 */
58 setCurrentDocument(
59 documentReference: string,
60 action?: string,
61 revision?: string,
62 ): Promise<void>;
63
64 /**
65 * Force reloading the content of the document without changing the current document reference
66 */
67 refreshCurrentDocument(): void;
68
69 /**
70 * Register a change listener that will be executed on any document change
71 * made on the whole Cristal instance.
72 * @param change - the kind of change
73 * @param listener - the listener to register
74 * @since 18.0.0RC1
75 */
76 registerDocumentChangeListener(
77 change: DocumentChange,
78 listener: (page: PageData) => Promise<void>,
79 ): void;
80
81 /**
82 * Notify that a document change happened. This will execute all registered
83 * listeners for the given kind of change.
84 * @param change - the kind of change
85 * @param page - the document changed
86 * @since 18.0.0RC1
87 */
88 notifyDocumentChange(change: DocumentChange, page: PageData): Promise<void>;
89
90 /**
91 * Unregister a document change listener.
92 * @param change - the kind of change
93 * @param listener - the listener to unregister
94 * @since 18.2.0RC1
95 */
96 removeDocumentChangeListener(
97 change: DocumentChange,
98 listener: (page: DocumentReference) => Promise<void>,
99 ): void;
100 }
101 {{/code}}

Get Connected