@unhead/schema 0.0.6 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { HeadTag as HeadTag$1, MergeHead, BodyAttributes as BodyAttributes$1, HtmlAttributes as HtmlAttributes$1, Merge, Base as Base$1, DefinedValueOrEmptyObject, Link as Link$1, DataKeys, Style as Style$1, Script as Script$1, Noscript as Noscript$1, Meta as Meta$1, Stringable } from '@zhead/schema';
2
2
  export { DataKeys, DefinedValueOrEmptyObject, MergeHead, TagKey } from '@zhead/schema';
3
+ import { NestedHooks, Hookable } from 'hookable';
3
4
 
4
5
  interface ResolvesDuplicates {
5
6
  /**
@@ -201,4 +202,102 @@ interface Head<E extends MergeHead = SchemaAugmentations> {
201
202
  bodyAttrs?: BodyAttributes<E['bodyAttrs']>;
202
203
  }
203
204
 
204
- export { Base, BaseBodyAttr, BaseHtmlAttr, BodyAttributes, EntryAugmentation, Head, HeadTag, HeadTagKeys, HtmlAttributes, InnerContent, Link, MaybeArray, Meta, Never, Noscript, ResolvesDuplicates, SchemaAugmentations, Script, Style, TagInternalProperties, TagPosition, TagPriority, TagUserProperties, Title, TitleTemplate, UserAttributesConfig, UserTagConfigWithoutInnerContent };
205
+ declare type HookResult = Promise<void> | void;
206
+ interface EntryResolveCtx<T> {
207
+ tags: HeadTag[];
208
+ entries: HeadEntry<T>[];
209
+ }
210
+ interface HeadHooks {
211
+ 'entries:resolve': (ctx: EntryResolveCtx<any>) => HookResult;
212
+ 'tag:normalise': (ctx: {
213
+ tag: HeadTag;
214
+ entry: HeadEntry<any>;
215
+ }) => HookResult;
216
+ 'tags:resolve': (ctx: {
217
+ tags: HeadTag[];
218
+ }) => HookResult;
219
+ }
220
+ /**
221
+ * Side effects are mapped with a key and their cleanup function.
222
+ *
223
+ * For example `meta:data-h-4h46h465`: () => { document.querySelector('meta[data-h-4h46h465]').remove() }
224
+ */
225
+ declare type SideEffectsRecord = Record<string, () => void>;
226
+ declare type RuntimeMode = 'server' | 'client' | 'all';
227
+ interface HeadEntry<T> {
228
+ /**
229
+ * User provided input for the entry.
230
+ */
231
+ input: T;
232
+ /**
233
+ * The mode that the entry should be used in.
234
+ *
235
+ * @internal
236
+ */
237
+ _m?: RuntimeMode;
238
+ /**
239
+ * Head entry index
240
+ *
241
+ * @internal
242
+ */
243
+ _i: number;
244
+ /**
245
+ * Side effects
246
+ *
247
+ * @internal
248
+ */
249
+ _sde: SideEffectsRecord;
250
+ }
251
+ declare type HeadPlugin = Omit<CreateHeadOptions, 'plugins'>;
252
+ /**
253
+ * An active head entry provides an API to manipulate it.
254
+ */
255
+ interface ActiveHeadEntry<T> {
256
+ /**
257
+ * Updates the entry with new input.
258
+ *
259
+ * Will first clear any side effects for previous input.
260
+ */
261
+ patch: (resolvedInput: T) => void;
262
+ /**
263
+ * Dispose the entry, removing it from the active head.
264
+ *
265
+ * Will queue side effects for removal.
266
+ */
267
+ dispose: () => void;
268
+ }
269
+ interface CreateHeadOptions {
270
+ plugins?: HeadPlugin[];
271
+ hooks?: NestedHooks<HeadHooks>;
272
+ }
273
+ interface HeadEntryOptions {
274
+ mode?: RuntimeMode;
275
+ }
276
+ interface HeadClient<T extends {} = Head> {
277
+ /**
278
+ * The active head entries.
279
+ */
280
+ headEntries: () => HeadEntry<T>[];
281
+ /**
282
+ * Create a new head entry.
283
+ */
284
+ push: (entry: T, options?: HeadEntryOptions) => ActiveHeadEntry<T>;
285
+ /**
286
+ * Resolve tags from head entries.
287
+ */
288
+ resolveTags: () => Promise<HeadTag[]>;
289
+ /**
290
+ * Exposed hooks for easier extension.
291
+ */
292
+ hooks: Hookable<HeadHooks>;
293
+ /**
294
+ * @internal
295
+ */
296
+ _removeQueuedSideEffect: (key: string) => void;
297
+ /**
298
+ * @internal
299
+ */
300
+ _flushQueuedSideEffects: () => void;
301
+ }
302
+
303
+ export { ActiveHeadEntry, Base, BaseBodyAttr, BaseHtmlAttr, BodyAttributes, CreateHeadOptions, EntryAugmentation, EntryResolveCtx, Head, HeadClient, HeadEntry, HeadEntryOptions, HeadHooks, HeadPlugin, HeadTag, HeadTagKeys, HookResult, HtmlAttributes, InnerContent, Link, MaybeArray, Meta, Never, Noscript, ResolvesDuplicates, RuntimeMode, SchemaAugmentations, Script, SideEffectsRecord, Style, TagInternalProperties, TagPosition, TagPriority, TagUserProperties, Title, TitleTemplate, UserAttributesConfig, UserTagConfigWithoutInnerContent };
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- export { MergeHead } from '@zhead/schema';
1
+
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unhead/schema",
3
3
  "type": "module",
4
- "version": "0.0.6",
4
+ "version": "0.1.0",
5
5
  "packageManager": "pnpm@7.14.0",
6
6
  "author": "Harlan Wilton <harlan@harlanzw.com>",
7
7
  "license": "MIT",
@@ -33,7 +33,8 @@
33
33
  "dist"
34
34
  ],
35
35
  "dependencies": {
36
- "@zhead/schema": "1.0.0-beta.4"
36
+ "@zhead/schema": "1.0.0-beta.4",
37
+ "hookable": "^5.4.1"
37
38
  },
38
39
  "scripts": {
39
40
  "build": "unbuild .",