Wiki source code of Front-End Model Reference
Last modified by superadmin on 2026/05/18 17:05
Show last authors
| author | version | line-number | content |
|---|---|---|---|
| 1 | == Parser == | ||
| 2 | |||
| 3 | === ModelReferenceParser === | ||
| 4 | |||
| 5 | {{code language="typescript"}} | ||
| 6 | /** | ||
| 7 | * @since 18.0.0RC1 | ||
| 8 | */ | ||
| 9 | interface ModelReferenceParser { | ||
| 10 | /** | ||
| 11 | * @param reference - an entity reference | ||
| 12 | * @param options - (since 0.22) an optional configuration object | ||
| 13 | */ | ||
| 14 | parse( | ||
| 15 | reference: string, | ||
| 16 | options?: ModelReferenceParserOptions, | ||
| 17 | ): EntityReference; | ||
| 18 | |||
| 19 | /** | ||
| 20 | * Parse a reference with additional analysis that can only be performed asynchronously | ||
| 21 | * @param reference - an entity reference | ||
| 22 | * @param options - an optional configuration object | ||
| 23 | * @since 18.0.0RC1 | ||
| 24 | */ | ||
| 25 | parseAsync( | ||
| 26 | reference: string, | ||
| 27 | options?: ModelReferenceParserOptions, | ||
| 28 | ): Promise<EntityReference>; | ||
| 29 | } | ||
| 30 | {{/code}} | ||
| 31 | |||
| 32 | === ModelReferenceParserOptions === | ||
| 33 | |||
| 34 | {{code language="typescript"}} | ||
| 35 | /** | ||
| 36 | * @since 18.0.0RC1 | ||
| 37 | */ | ||
| 38 | type ModelReferenceParserOptions = { | ||
| 39 | /** | ||
| 40 | * an optional type, helping to remove ambiguity when parsing the reference | ||
| 41 | */ | ||
| 42 | type?: EntityType; | ||
| 43 | /** | ||
| 44 | * When false, the model reference is parsed as an absolute reference. | ||
| 45 | * When true, the model reference is parsed relatively to the current document. | ||
| 46 | * The default value is true. | ||
| 47 | */ | ||
| 48 | relative?: boolean; | ||
| 49 | }; | ||
| 50 | {{/code}} | ||
| 51 | |||
| 52 | === ModelReferenceParserProvider === | ||
| 53 | |||
| 54 | {{code language="typescript"}} | ||
| 55 | /** | ||
| 56 | * @since 18.0.0RC1 | ||
| 57 | */ | ||
| 58 | interface ModelReferenceParserProvider { | ||
| 59 | get(type?: string): ModelReferenceParser | undefined; | ||
| 60 | } | ||
| 61 | {{/code}} | ||
| 62 | |||
| 63 | == Serializer == | ||
| 64 | |||
| 65 | === ModelReferenceSerializer === | ||
| 66 | |||
| 67 | {{code language="typescript"}} | ||
| 68 | /** | ||
| 69 | * @since 18.0.0RC1 | ||
| 70 | */ | ||
| 71 | interface ModelReferenceSerializer { | ||
| 72 | serialize(reference?: EntityReference): string | undefined; | ||
| 73 | } | ||
| 74 | {{/code}} | ||
| 75 | |||
| 76 | === ModelReferenceSerializerProvider === | ||
| 77 | |||
| 78 | {{code language="typescript"}} | ||
| 79 | /** | ||
| 80 | * @since 18.0.0RC1 | ||
| 81 | */ | ||
| 82 | interface ModelReferenceSerializerProvider { | ||
| 83 | get(type?: string): ModelReferenceSerializer | undefined; | ||
| 84 | } | ||
| 85 | {{/code}} | ||
| 86 | |||
| 87 | == Handler == | ||
| 88 | |||
| 89 | === ModelReferenceHandler === | ||
| 90 | |||
| 91 | {{code language="typescript"}} | ||
| 92 | /** | ||
| 93 | * A ModelReferenceHandler can do backend-specific operations involving | ||
| 94 | * {@link @xwiki/platform-model-api#EntityReference | EntityReferences}. | ||
| 95 | * | ||
| 96 | * @since 18.0.0RC1 | ||
| 97 | */ | ||
| 98 | interface ModelReferenceHandler { | ||
| 99 | /** | ||
| 100 | * Returns a {@link DocumentReference} with a specific name and a parent | ||
| 101 | * {@link SpaceReference}. | ||
| 102 | * | ||
| 103 | * @param name - the name of the document reference | ||
| 104 | * @param space - the parent space of the document reference | ||
| 105 | * @returns the document reference | ||
| 106 | */ | ||
| 107 | createDocumentReference( | ||
| 108 | name: string, | ||
| 109 | space: SpaceReference, | ||
| 110 | ): DocumentReference; | ||
| 111 | |||
| 112 | /** | ||
| 113 | * Return the title of a reference | ||
| 114 | */ | ||
| 115 | getTitle(reference: EntityReference): string; | ||
| 116 | |||
| 117 | /** | ||
| 118 | * Returns the {@link DocumentReference} considered as the direct parent of | ||
| 119 | * the given document reference. | ||
| 120 | * @param reference - the reference for which we want the parent | ||
| 121 | * @returns the parent for the given reference, undefined if there is none | ||
| 122 | * | ||
| 123 | * @since 18.4.0RC1 | ||
| 124 | */ | ||
| 125 | getParentDocumentReference( | ||
| 126 | reference: DocumentReference, | ||
| 127 | ): DocumentReference | undefined; | ||
| 128 | |||
| 129 | /** | ||
| 130 | * Returns the {@link SpaceReference} considered as the direct parent of | ||
| 131 | * the given space reference. | ||
| 132 | * @param reference - the reference for which we want the parent | ||
| 133 | * @returns the parent for the given reference, undefined if there is none | ||
| 134 | * | ||
| 135 | * @since 18.4.0RC1 | ||
| 136 | */ | ||
| 137 | getParentSpaceReference( | ||
| 138 | reference: SpaceReference, | ||
| 139 | ): SpaceReference | undefined; | ||
| 140 | } | ||
| 141 | {{/code}} | ||
| 142 | |||
| 143 | === ModelReferenceHandlerProvider === | ||
| 144 | |||
| 145 | {{code language="typescript"}} | ||
| 146 | /** | ||
| 147 | * A ModelReferenceHandlerProvider returns the expected instance of | ||
| 148 | * {@link ModelReferenceHandler}. | ||
| 149 | * | ||
| 150 | * @since 18.0.0RC1 | ||
| 151 | */ | ||
| 152 | interface ModelReferenceHandlerProvider { | ||
| 153 | /** | ||
| 154 | * Returns the instance of {@link ModelReferenceHandler} matching the | ||
| 155 | * requested wiki configuration type, or the current one if empty. | ||
| 156 | * | ||
| 157 | * @param type - the wiki configuration type | ||
| 158 | * @returns the instance of model reference handler | ||
| 159 | */ | ||
| 160 | get(type?: string): ModelReferenceHandler | undefined; | ||
| 161 | } | ||
| 162 | {{/code}} |