|
| 1 | +import type { PostHTMLExpressions } from 'posthtml-expressions'; |
| 2 | +import type { Options as PostHTMLParserOptions } from 'posthtml-parser'; |
| 3 | + |
| 4 | +interface AnyObject { |
| 5 | + [key: string]: string | AnyObject; |
| 6 | +} |
| 7 | + |
| 8 | +export type PostHTMLComponents = { |
| 9 | + /** |
| 10 | + * Root path where to look for folders containing component files. |
| 11 | + * |
| 12 | + * @default './' |
| 13 | + */ |
| 14 | + root?: string; |
| 15 | + |
| 16 | + /** |
| 17 | + * Paths where to look for component files. Must be relative to `root`. |
| 18 | + * |
| 19 | + * @default [''] |
| 20 | + */ |
| 21 | + folders?: string[]; |
| 22 | + |
| 23 | + /** |
| 24 | + * Prefix to use for component tags. |
| 25 | + * |
| 26 | + * @default 'x-' |
| 27 | + */ |
| 28 | + tagPrefix?: string; |
| 29 | + |
| 30 | + /** |
| 31 | + * Tag name to be used in HTML when using a component. |
| 32 | + * |
| 33 | + * @default false |
| 34 | + */ |
| 35 | + tag?: string|false; |
| 36 | + |
| 37 | + /** |
| 38 | + * Attribute name to be used when referencing a component via its path. |
| 39 | + * |
| 40 | + * @default 'src' |
| 41 | + */ |
| 42 | + attribute?: string; |
| 43 | + |
| 44 | + /** |
| 45 | + * Array of namespace root paths, fallback paths and custom override paths. |
| 46 | + * |
| 47 | + * @default [] |
| 48 | + */ |
| 49 | + namespaces?: string[]; |
| 50 | + |
| 51 | + /** |
| 52 | + * Separator to use between namespace and component name. |
| 53 | + * |
| 54 | + * @default '::' |
| 55 | + */ |
| 56 | + namespaceSeparator?: string; |
| 57 | + |
| 58 | + /** |
| 59 | + * File extension that component files must use. |
| 60 | + * |
| 61 | + * @default 'html' |
| 62 | + */ |
| 63 | + fileExtension?: string; |
| 64 | + |
| 65 | + /** |
| 66 | + * Name of the tag that will be replaced with the content that is passed to the component. |
| 67 | + * |
| 68 | + * @default 'yield' |
| 69 | + */ |
| 70 | + yield?: string; |
| 71 | + |
| 72 | + /** |
| 73 | + * Name of the slot tag, where the content will be injected. |
| 74 | + * |
| 75 | + * @default 'slot' |
| 76 | + */ |
| 77 | + slot?: string; |
| 78 | + |
| 79 | + /** |
| 80 | + * Name of the fill tag, where the content to be injected is defined. |
| 81 | + * |
| 82 | + * @default 'fill' |
| 83 | + */ |
| 84 | + fill?: string; |
| 85 | + |
| 86 | + /** |
| 87 | + * String to use as a separator between the slot tag and its name. |
| 88 | + * |
| 89 | + * @default ':' |
| 90 | + */ |
| 91 | + slotSeparator?: string; |
| 92 | + |
| 93 | + /** |
| 94 | + * Tag name for pushing content to a stack. |
| 95 | + * |
| 96 | + * @default 'push' |
| 97 | + */ |
| 98 | + push?: string; |
| 99 | + |
| 100 | + /** |
| 101 | + * Tag name for popping (rendering) content from a stack. |
| 102 | + * |
| 103 | + * @default 'stack' |
| 104 | + */ |
| 105 | + stack?: string; |
| 106 | + |
| 107 | + /** |
| 108 | + * Name of the props attribute to use in the `<script>` tag of a component. |
| 109 | + * |
| 110 | + * @default 'props' |
| 111 | + */ |
| 112 | + propsScriptAttribute?: string; |
| 113 | + |
| 114 | + /** |
| 115 | + * Name of the object that will be used to store the props of a component. |
| 116 | + * |
| 117 | + * @default 'props' |
| 118 | + */ |
| 119 | + propsContext?: string; |
| 120 | + |
| 121 | + /** |
| 122 | + * Name of the attribute that will be used to pass props to a component as JSON. |
| 123 | + * |
| 124 | + * @default 'locals' |
| 125 | + */ |
| 126 | + propsAttribute?: string; |
| 127 | + |
| 128 | + /** |
| 129 | + * Name of the key to use when retrieving props passed to a slot via `$slots.slotName.props`. |
| 130 | + * |
| 131 | + * @default 'props' |
| 132 | + */ |
| 133 | + propsSlot?: string; |
| 134 | + |
| 135 | + /** |
| 136 | + * Configure [`posthtml-parser`](https://github.com/posthtml/posthtml-parser). |
| 137 | + * |
| 138 | + * @default |
| 139 | + * { |
| 140 | + * recognizeSelfClosing: true |
| 141 | + * } |
| 142 | + */ |
| 143 | + parserOptions?: PostHTMLParserOptions; |
| 144 | + |
| 145 | + /** |
| 146 | + * Configure [`posthtml-expressions`](https://github.com/posthtml/posthtml-expressions). |
| 147 | + * |
| 148 | + * @default {} |
| 149 | + */ |
| 150 | + expressions?: PostHTMLExpressions; |
| 151 | + |
| 152 | + /** |
| 153 | + * PostHTML plugins to apply to each parsed component. |
| 154 | + * |
| 155 | + * @default [] |
| 156 | + */ |
| 157 | + plugins?: Array<() => void>; |
| 158 | + |
| 159 | + /** |
| 160 | + * Array of objects used to match tags. |
| 161 | + * |
| 162 | + * @default [{tag: options.tagPrefix}] |
| 163 | + */ |
| 164 | + matcher?: object; |
| 165 | + |
| 166 | + /** |
| 167 | + * Extra rules for the PostHTML plugin that is used by components to parse attributes. |
| 168 | + * |
| 169 | + * @default {} |
| 170 | + */ |
| 171 | + attrsParserRules?: Record<string, AnyObject>; |
| 172 | + |
| 173 | + /** |
| 174 | + * In strict mode, an error will be thrown if a component cannot be rendered. |
| 175 | + * |
| 176 | + * @default true |
| 177 | + */ |
| 178 | + strict?: boolean; |
| 179 | + |
| 180 | + /** |
| 181 | + * Callback for lodash `mergeWith` to merge `options.expressions.locals` and props. |
| 182 | + * |
| 183 | + * |
| 184 | + */ |
| 185 | + mergeCustomizer?: (objValue: any, srcValue: any) => any; |
| 186 | + |
| 187 | + /** |
| 188 | + * Utility methods to be passed to `<script props>` in a component. |
| 189 | + * |
| 190 | + * @default {merge: _.mergeWith, template: _.template} |
| 191 | + */ |
| 192 | + utilities?: Record<string, unknown>; |
| 193 | + |
| 194 | + /** |
| 195 | + * Define additional attributes that should be preserved for specific HTML elements. |
| 196 | + * |
| 197 | + * @default {} |
| 198 | + */ |
| 199 | + elementAttributes?: Record<string, void>; |
| 200 | + |
| 201 | + /** |
| 202 | + * Attributes that should be preserved on all elements in components. |
| 203 | + * |
| 204 | + * @default ['data-*'] |
| 205 | + */ |
| 206 | + safelistAttributes?: string[]; |
| 207 | + |
| 208 | + /** |
| 209 | + * Attributes that should be removed from all elements in components. |
| 210 | + * |
| 211 | + * @default [] |
| 212 | + */ |
| 213 | + blocklistAttributes?: string[]; |
| 214 | +} |
0 commit comments