@elastic/isomer-sdk 0.2.0 → 0.3.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/NOTICE.txt +0 -286
- package/THIRD_PARTY_LICENSES.md +1 -885
- package/dist/author/authored_fields.d.ts +37 -12
- package/dist/author/authored_fields.d.ts.map +1 -1
- package/dist/author/authored_fields.js +45 -69
- package/dist/author/authored_fields.js.map +1 -1
- package/dist/author/authoring_input.d.ts.map +1 -1
- package/dist/author/authoring_input.js +12 -6
- package/dist/author/authoring_input.js.map +1 -1
- package/dist/author/authoring_model.d.ts +8 -2
- package/dist/author/authoring_model.d.ts.map +1 -1
- package/dist/author/authoring_model.js +67 -23
- package/dist/author/authoring_model.js.map +1 -1
- package/dist/author/declarations.d.ts.map +1 -1
- package/dist/author/declarations.js +45 -34
- package/dist/author/declarations.js.map +1 -1
- package/dist/author/index.d.ts +2 -1
- package/dist/author/index.d.ts.map +1 -1
- package/dist/author/index.js +2 -1
- package/dist/author/index.js.map +1 -1
- package/dist/author/jsx_shim.d.ts +49 -30
- package/dist/author/jsx_shim.d.ts.map +1 -1
- package/dist/author/jsx_shim.js +131 -40
- package/dist/author/jsx_shim.js.map +1 -1
- package/dist/author/print_jsx.d.ts +19 -0
- package/dist/author/print_jsx.d.ts.map +1 -0
- package/dist/author/print_jsx.js +372 -0
- package/dist/author/print_jsx.js.map +1 -0
- package/dist/author/prompt.d.ts +2 -2
- package/dist/author/prompt.d.ts.map +1 -1
- package/dist/author/prompt.js +7 -2
- package/dist/author/prompt.js.map +1 -1
- package/dist/author/schema_to_typescript.d.ts.map +1 -1
- package/dist/author/schema_to_typescript.js +6 -3
- package/dist/author/schema_to_typescript.js.map +1 -1
- package/dist/cjs/author/authored_fields.js +47 -70
- package/dist/cjs/author/authored_fields.js.map +1 -1
- package/dist/cjs/author/authoring_input.js +12 -6
- package/dist/cjs/author/authoring_input.js.map +1 -1
- package/dist/cjs/author/authoring_model.js +69 -24
- package/dist/cjs/author/authoring_model.js.map +1 -1
- package/dist/cjs/author/declarations.js +44 -33
- package/dist/cjs/author/declarations.js.map +1 -1
- package/dist/cjs/author/index.js +5 -1
- package/dist/cjs/author/index.js.map +1 -1
- package/dist/cjs/author/jsx_shim.js +130 -39
- package/dist/cjs/author/jsx_shim.js.map +1 -1
- package/dist/cjs/author/print_jsx.js +378 -0
- package/dist/cjs/author/print_jsx.js.map +1 -0
- package/dist/cjs/author/prompt.js +7 -2
- package/dist/cjs/author/prompt.js.map +1 -1
- package/dist/cjs/author/schema_to_typescript.js +6 -3
- package/dist/cjs/author/schema_to_typescript.js.map +1 -1
- package/dist/cjs/composition/error.js +1 -0
- package/dist/cjs/composition/error.js.map +1 -1
- package/dist/cjs/composition/structured_value.js.map +1 -1
- package/dist/cjs/define/primitive_module.js +10 -4
- package/dist/cjs/define/primitive_module.js.map +1 -1
- package/dist/cjs/entries/index.js +3 -2
- package/dist/cjs/entries/index.js.map +1 -1
- package/dist/cjs/entries/markdown.js +2 -1
- package/dist/cjs/entries/markdown.js.map +1 -1
- package/dist/cjs/pack/index.js +2 -1
- package/dist/cjs/pack/index.js.map +1 -1
- package/dist/cjs/pack/primitive_pack.js +14 -4
- package/dist/cjs/pack/primitive_pack.js.map +1 -1
- package/dist/cjs/render/format_number.js +2 -1
- package/dist/cjs/render/format_number.js.map +1 -1
- package/dist/cjs/render/html/envelope.js +12 -6
- package/dist/cjs/render/html/envelope.js.map +1 -1
- package/dist/cjs/render/markdown/builder.js +6 -2
- package/dist/cjs/render/markdown/builder.js.map +1 -1
- package/dist/cjs/render/markdown/format.js +46 -24
- package/dist/cjs/render/markdown/format.js.map +1 -1
- package/dist/cjs/render/markdown/host_tags.js +67 -0
- package/dist/cjs/render/markdown/host_tags.js.map +1 -0
- package/dist/cjs/render/markdown/index.js +3 -1
- package/dist/cjs/render/markdown/index.js.map +1 -1
- package/dist/cjs/render/markdown/split.js +325 -0
- package/dist/cjs/render/markdown/split.js.map +1 -0
- package/dist/cjs/render/react/content.js +3 -1
- package/dist/cjs/render/react/content.js.map +1 -1
- package/dist/cjs/render/slack/markdown_content.js +7 -1
- package/dist/cjs/render/slack/markdown_content.js.map +1 -1
- package/dist/cjs/validate/json_schema.js +10 -3
- package/dist/cjs/validate/json_schema.js.map +1 -1
- package/dist/cjs/validate/url.js +2 -1
- package/dist/cjs/validate/url.js.map +1 -1
- package/dist/composition/error.d.ts +1 -0
- package/dist/composition/error.d.ts.map +1 -1
- package/dist/composition/error.js +1 -0
- package/dist/composition/error.js.map +1 -1
- package/dist/composition/structured_value.d.ts +3 -3
- package/dist/composition/structured_value.d.ts.map +1 -1
- package/dist/composition/structured_value.js.map +1 -1
- package/dist/define/primitive_module.d.ts +7 -0
- package/dist/define/primitive_module.d.ts.map +1 -1
- package/dist/define/primitive_module.js +10 -4
- package/dist/define/primitive_module.js.map +1 -1
- package/dist/entries/index.d.ts +1 -1
- package/dist/entries/index.d.ts.map +1 -1
- package/dist/entries/index.js +1 -1
- package/dist/entries/index.js.map +1 -1
- package/dist/entries/markdown.d.ts +1 -1
- package/dist/entries/markdown.d.ts.map +1 -1
- package/dist/entries/markdown.js +1 -1
- package/dist/entries/markdown.js.map +1 -1
- package/dist/pack/index.d.ts +1 -1
- package/dist/pack/index.d.ts.map +1 -1
- package/dist/pack/index.js +1 -1
- package/dist/pack/index.js.map +1 -1
- package/dist/pack/primitive_pack.d.ts +3 -1
- package/dist/pack/primitive_pack.d.ts.map +1 -1
- package/dist/pack/primitive_pack.js +13 -3
- package/dist/pack/primitive_pack.js.map +1 -1
- package/dist/render/format_number.d.ts.map +1 -1
- package/dist/render/format_number.js +2 -1
- package/dist/render/format_number.js.map +1 -1
- package/dist/render/html/envelope.js +12 -6
- package/dist/render/html/envelope.js.map +1 -1
- package/dist/render/markdown/builder.d.ts +3 -0
- package/dist/render/markdown/builder.d.ts.map +1 -1
- package/dist/render/markdown/builder.js +3 -1
- package/dist/render/markdown/builder.js.map +1 -1
- package/dist/render/markdown/format.d.ts +2 -0
- package/dist/render/markdown/format.d.ts.map +1 -1
- package/dist/render/markdown/format.js +42 -22
- package/dist/render/markdown/format.js.map +1 -1
- package/dist/render/markdown/host_tags.d.ts +14 -0
- package/dist/render/markdown/host_tags.d.ts.map +1 -0
- package/dist/render/markdown/host_tags.js +63 -0
- package/dist/render/markdown/host_tags.js.map +1 -0
- package/dist/render/markdown/index.d.ts +1 -0
- package/dist/render/markdown/index.d.ts.map +1 -1
- package/dist/render/markdown/index.js +1 -0
- package/dist/render/markdown/index.js.map +1 -1
- package/dist/render/markdown/split.d.ts +32 -0
- package/dist/render/markdown/split.d.ts.map +1 -0
- package/dist/render/markdown/split.js +321 -0
- package/dist/render/markdown/split.js.map +1 -0
- package/dist/render/react/content.d.ts +1 -1
- package/dist/render/react/content.d.ts.map +1 -1
- package/dist/render/react/content.js +3 -1
- package/dist/render/react/content.js.map +1 -1
- package/dist/render/slack/markdown_content.d.ts.map +1 -1
- package/dist/render/slack/markdown_content.js +7 -1
- package/dist/render/slack/markdown_content.js.map +1 -1
- package/dist/validate/json_schema.d.ts.map +1 -1
- package/dist/validate/json_schema.js +10 -3
- package/dist/validate/json_schema.js.map +1 -1
- package/dist/validate/url.d.ts.map +1 -1
- package/dist/validate/url.js +2 -1
- package/dist/validate/url.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"primitive_module.js","sourceRoot":"","sources":["../../src/define/primitive_module.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,CAAC,EAAgC,MAAM,KAAK,CAAC;AAGtD,OAAO,EAEL,aAAa,GAEd,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AASvE,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAgP/C;;;;;;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,EAAE;IAC3B,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,IAAI,CAC5C,CAAC,KAAK,EAAE,EAAE,CACR,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAC1E,CAAC;IACF,IAAI,QAAQ,EAAE,CAAC;QACb,MAAM,IAAI,WAAW,CACnB,kBAAkB,CAAC,mBAAmB,EACtC,wDAAwD,QAAQ,6BAA6B,CAC9F,CAAC;IACJ,CAAC;IACD,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IAC5C,OAAO,CACL,MAAM,CAAC,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,QAAQ,CACtC,CAAC;AAC/B,CAAC,CAAC","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nimport type { ReactNode } from 'react';\nimport { z, type ZodObject, type ZodType } from 'zod';\n\nimport type { ActionEventRef } from '../composition/action_event';\nimport {\n type ChildNodeRef,\n SURFACE_NAMES,\n type SurfaceName,\n} from '../composition/body_node_base';\nimport { ISOMER_ERROR_CODES, IsomerError } from '../composition/error';\nimport type { PrimitiveNode } from '../composition/node';\nimport type { ValidationError } from '../composition/validation_error';\n\nimport type { MarkdownContent } from './markdown_content';\nimport type { PrimitiveExample } from './primitive_example';\nimport type { PrimitiveIcon } from './primitive_icon';\nimport type { SlackAssetCollector } from './slack_assets';\nimport type { SlackBlock } from './slack_blocks';\nimport { formatZodIssues, oneOf } from './zod_format';\nimport { requiredString } from './zod_helpers';\n\nexport type { PrimitiveNode };\n\n/**\n * A primitive's entry in the catalog the authoring prompt is built from.\n *\n * Written for the model rather than for a developer: `useWhen` and `avoidWhen`\n * are what steer it away from reaching for the wrong primitive. `name` is the\n * one host-facing field, and the prompt never prints it.\n */\nexport interface PrimitiveCatalogEntry {\n type: string;\n /** Short name a host shows for the primitive, e.g. `Stat group`. Absent means the host derives one from `type`. */\n name?: string;\n /** One line on what the primitive is for, in the model's voice. */\n purpose: string;\n /** Situations that call for this primitive. Phrase each as a user intent, not a shape. */\n useWhen: string[];\n /** Situations that look like a fit but are not, naming the primitive to reach for instead. */\n avoidWhen: string[];\n /** A node literal the authoring prompt inlines under this primitive. */\n example: unknown;\n}\n\n/** A style a renderer asks for by name, resolved to a class by the host's adapter. */\nexport interface StyleHandle {\n /** Stable lookup key. The adapter's map is keyed on this. */\n key: string;\n /** Debug-facing label, which an adapter may fold into a generated class name. */\n readableName: string;\n}\n\n/** Dotted path into a pack's theme tokens, e.g. `colors.text.subdued`. */\nexport type ThemeTokenPath = string;\n\n/**\n * The sdk's own render context, and {@link DefaultPackTypes.context}.\n *\n * A pack with real theme tokens or a richer style-handle type declares its\n * own context in its {@link PackTypes}; {@link StyledRenderContext} is the\n * sdk's own extension. The bag is what lets a pack narrow without\n * re-declaring everything that mentions a context.\n */\nexport interface PrimitiveRenderContext {\n /**\n * The progressive enhancements this render may assume, by id. A set rather\n * than a field per feature so adding an enhancement costs no plumbing:\n * containers forward the whole context, and a renderer asks\n * `context.enhancements?.has('tableSort')`.\n *\n * Empty or absent is the baseline every host can render, so a renderer must\n * still answer the question on its own. See `docs/rendering.md`.\n */\n enhancements?: ReadonlySet<string>;\n /** Turns on `nodeAnchor` outside an HTML surface render, on the React and `snapshot` surfaces; inside one, the surface decides. */\n anchors?: boolean;\n /** Raises an interaction for the host to route. Absent means render non-interactively. */\n onEvent?: (event: ActionEventRef) => void;\n}\n\n/**\n * The render-context argument, optional only when omitting it is sound.\n *\n * The sdk's own {@link PrimitiveRenderContext} has no required field, so `{}`\n * is a complete value and a caller may leave it out. A pack that narrows the\n * context with a required member makes the argument mandatory.\n */\nexport type ReactContextArg<TContext> =\n Record<string, never> extends TContext\n ? [context?: TContext]\n : [context: TContext];\n\n/**\n * {@link PrimitiveRenderContext} plus the CSS-in-JS hooks an HTML style adapter\n * supplies. A pack that styles differently uses its own `TContext` instead.\n */\nexport interface StyledRenderContext extends PrimitiveRenderContext {\n /** Resolves handles to a `className`. Absent means the host supplies no styling. */\n resolveClassName?: (...handles: StyleHandle[]) => string;\n /** Resolves a theme token to a CSS variable reference. Absent means inline the literal value. */\n cssVarRef?: (path: ThemeTokenPath) => `var(--${string})`;\n}\n\n/** Passed to a primitive's style collector so it can vary CSS by layout mode. */\nexport interface PrimitiveStyleCollectionContext {\n /** The render fills its container rather than sitting at a fixed width. */\n fluid?: boolean;\n}\n\n/** A pack's collected styles, opaque to the SDK. */\nexport type PrimitiveStyleCollector = object;\n\n/**\n * The types a pack binds once and writes every primitive against: the palette\n * its frames supply, the context its `react` renderers receive, the collector\n * its `collectStyles` hooks mutate, and the Slack payload and collector types.\n *\n * Extend {@link DefaultPackTypes} and narrow only what the pack needs:\n *\n * ```ts\n * interface SlidesPackTypes extends DefaultPackTypes {\n * theme: SlideTheme;\n * context: SlideRenderContext;\n * }\n * ```\n */\nexport interface PackTypes {\n theme: unknown;\n context: unknown;\n collector: PrimitiveStyleCollector;\n slackBlock: unknown;\n slackCollector: unknown;\n}\n\n/** {@link PackTypes} as the sdk itself binds them, and the default everywhere. */\nexport interface DefaultPackTypes extends PackTypes {\n theme: unknown;\n context: PrimitiveRenderContext;\n collector: PrimitiveStyleCollector;\n slackBlock: SlackBlock;\n slackCollector: SlackAssetCollector;\n}\n\n/**\n * Each surface's renderer signature: the env bag it receives beyond the node,\n * and what it returns.\n *\n * Written out per surface rather than derived through an indexed access. A bag\n * is additive: a new extra on a surface is not an arity break. {@link Renderer}\n * indexes this table for the dispatcher cast; {@link Renderers} does not.\n */\nexport interface SurfaceMap<T extends PackTypes = DefaultPackTypes> {\n react: {\n env: {\n context: T['context'];\n scope: RenderScope<T>;\n /**\n * The frame's resolved palette, when this render is reached through the\n * `snapshot` surface. A bare `react`/`html` render has no {@link Frame} to\n * resolve one from, so it is absent there — a pack that needs a\n * literal color outside `snapshot` still goes through `context`.\n */\n theme?: T['theme'];\n };\n output: ReactNode;\n };\n /**\n * Identical to `react`, and served by the same renderer: an image backend\n * lays out the pack's DOM tree and stylesheet rather than a second tree\n * authored for it. The surface stays separate so a node can be hidden from\n * snapshots alone, and so a {@link Frame} has something to draw inside.\n */\n snapshot: {\n env: {\n context: T['context'];\n scope: RenderScope<T>;\n /** The frame's resolved palette for this render's mode; see `react.env.theme`. */\n theme?: T['theme'];\n };\n output: ReactNode;\n };\n text: {\n env: {\n scope: RenderScope<T>;\n };\n output: string;\n };\n /** Content built with `md`, escaped where it lands; authored Markdown source goes through `md.authored`. */\n markdown: {\n env: {\n scope: RenderScope<T>;\n };\n output: MarkdownContent;\n };\n /**\n * Returns one payload or several, so a primitive need not wrap a single\n * payload in an array.\n */\n slack: {\n env: {\n collector?: T['slackCollector'];\n scope: RenderScope<T>;\n };\n output: T['slackBlock'] | readonly T['slackBlock'][];\n };\n}\n\n/**\n * The dispatcher a renderer is given so a container can recurse into a child\n * owned by another pack. Erased to {@link PrimitiveNode}: a heterogeneous\n * inventory has no single node type to name.\n *\n * Passed as `scope` on every renderer's env bag. The dispatcher's own named\n * methods stay positional.\n */\nexport interface RenderScope<T extends PackTypes = DefaultPackTypes> {\n readonly definitions: readonly AnyPrimitiveDefinition[];\n /** Throws for an unknown node type; a missing primitive is a bug, not a degradation. */\n getDefinition(node: PrimitiveNode): AnyPrimitiveDefinition;\n /** `undefined` when the node is hidden from `surface`, `sanitize` drops it, or its primitive declares no renderer for `surface`. */\n renderOn<S extends SurfaceName>(\n surface: S,\n node: PrimitiveNode,\n extras: Omit<SurfaceMap<T>[S]['env'], 'scope'>\n ): SurfaceMap<T>[S]['output'] | undefined;\n renderReact(node: PrimitiveNode, context?: T['context']): ReactNode;\n collectStyles(\n node: PrimitiveNode,\n styles: PrimitiveStyleCollector,\n context: PrimitiveStyleCollectionContext\n ): void;\n renderText(node: PrimitiveNode): string;\n renderMarkdown(node: PrimitiveNode): string;\n /** A child as content, for a container building with `md`. */\n renderMarkdownContent(node: PrimitiveNode): MarkdownContent;\n /** Empty when the node is hidden from `slack`, `sanitize` drops it, or its renderer returns nothing; a node with no `slack` renderer degrades through its markdown. */\n renderSlack(\n node: PrimitiveNode,\n collector?: T['slackCollector']\n ): readonly T['slackBlock'][];\n /** `0` when the node is hidden from `snapshot` or its primitive declares no `metrics.snapshotHeight`. */\n estimateSnapshotHeight(node: PrimitiveNode): number;\n /** Appends schema failures under `path` to `errors`, each naming `node`'s type. */\n validate(node: PrimitiveNode, path: string, errors: ValidationError[]): void;\n}\n\n/**\n * One surface's renderer for one node type, per {@link SurfaceMap}.\n *\n * Indexes the env bag. Do not use this to type the renderers map: the\n * written-out signatures on {@link Renderers} are what keep the bags checked\n * per surface.\n */\nexport type Renderer<\n TNode extends PrimitiveNode,\n S extends SurfaceName,\n T extends PackTypes = DefaultPackTypes,\n> = (node: TNode, env: SurfaceMap<T>[S]['env']) => SurfaceMap<T>[S]['output'];\n\n/**\n * The surface a pack may declare beyond the mandatory three.\n *\n * Only `slack`, and even that stays optional per primitive: the dispatcher\n * converts the mandatory markdown to Block Kit, so a missing Slack renderer\n * degrades rather than disappearing. `snapshot` is not here because no primitive\n * implements it — the surface reuses `react`.\n */\nexport const OPTIONAL_SURFACES = [\n 'slack',\n] as const satisfies readonly SurfaceName[];\n\n/** One of the {@link OPTIONAL_SURFACES}. */\nexport type OptionalSurface = (typeof OPTIONAL_SURFACES)[number];\n\n/**\n * One renderer per surface a primitive implements.\n *\n * `react`, `text`, and `markdown` are always required: those three are what\n * make \"every composition degrades\" true. `react` serves the `snapshot` surface\n * too, so targeting images costs a primitive nothing.\n *\n * `slack` is declared method-style deliberately: method parameters are checked\n * bivariantly, which is what lets a pack narrow the collector's node type.\n */\nexport interface Renderers<\n TNode extends PrimitiveNode,\n T extends PackTypes = DefaultPackTypes,\n> {\n react(\n node: TNode,\n env: {\n context: T['context'];\n scope: RenderScope<T>;\n /** See {@link SurfaceMap.react}'s `env.theme`. */\n theme?: T['theme'];\n }\n ): ReactNode;\n text(\n node: TNode,\n env: {\n scope: RenderScope<T>;\n }\n ): string;\n markdown(\n node: TNode,\n env: {\n scope: RenderScope<T>;\n }\n ): MarkdownContent;\n slack?(\n node: TNode,\n env: {\n collector?: T['slackCollector'];\n scope: RenderScope<T>;\n }\n ): T['slackBlock'] | readonly T['slackBlock'][];\n}\n\n/**\n * Measurements a frame can ask of a node before drawing it.\n *\n * `snapshotHeight` is optional. The height estimate is `0` when it is missing, so\n * a frame that sums node heights sizes short.\n */\nexport interface PrimitiveMetrics<TNode extends PrimitiveNode> {\n /** The node's drawn height in pixels at the frame's width. */\n snapshotHeight?: (node: TNode) => number;\n}\n\n/**\n * Every primitive's schema is an object schema, because {@link definePrimitive}\n * extends it with `id` and `surfaces` and the composition builds a\n * `z.discriminatedUnion('type', …)` over them. Typed as `ZodObject` rather\n * than `ZodType<unknown>` so a union or intersection schema is a compile\n * error at the definition, not a runtime failure at the first `.extend()`.\n * Zod 4 types `z.object().superRefine(…)` as a `ZodObject` and preserves the\n * refinement through `.extend()`, so top-level refinements are unaffected.\n */\nexport type PrimitiveSchema = ZodObject;\n\n/**\n * The child-ref shape a primitive definition's own `children` returns.\n *\n * {@link ChildNodeRef} stays erased (`node: unknown`) because\n * `createChildNodeWalker` mixes children from every primitive type in the\n * runtime into one map and cannot name a single node type for them. A single\n * definition has no such excuse: its `children` should not type-check\n * against `unknown` and let something that is not a {@link PrimitiveNode} —\n * `null`, for instance — silently disappear from every tree walk.\n */\nexport interface PrimitiveChildRef extends ChildNodeRef {\n node: PrimitiveNode;\n}\n\n/**\n * One primitive: its node type, schema, catalog entry, and a renderer per\n * surface. The unit of vocabulary, and what {@link definePrimitive} takes.\n *\n * `T` is the pack's {@link PackTypes}, bound once with\n * {@link definePrimitiveFor} so each primitive names only `TNode`.\n */\nexport interface PrimitiveDefinition<\n TNode extends PrimitiveNode,\n T extends PackTypes = DefaultPackTypes,\n TSchema extends PrimitiveSchema = PrimitiveSchema,\n> {\n /** The node's discriminant, and the key this primitive occupies in an inventory. */\n type: TNode['type'];\n /** How the authoring prompt describes this primitive to the model. */\n catalog: PrimitiveCatalogEntry;\n /** Host-facing glyph, never shown to the model. Absent means the host supplies its own. */\n icon?: PrimitiveIcon;\n /**\n * Driven by the conformance harness, bare or named; read them with\n * `exampleNodes` or `primitiveExamples`. The catalog `example` is what the\n * prompt shows.\n */\n examples: readonly (TNode | PrimitiveExample<TNode>)[];\n /**\n * This primitive on its own. A container declares\n * {@link PrimitiveDefinition.schemaFor} as well, and uses\n * {@link unresolvedBodyNodeSchema} in the child slot here.\n */\n schema: TSchema;\n /**\n * A container's schema, bound to the body-node union of the composition it is\n * being built into.\n *\n * Declaring the shape and letting each composition supply its own union is\n * what lets one primitive appear in two runtimes with different inventories:\n * `z.lazy` memoizes per instance, and an instance built here belongs to\n * exactly one union.\n */\n schemaFor?: (bodyNodeSchema: ZodType<unknown>) => PrimitiveSchema;\n /** One function per surface; `react` serves `snapshot` as well. */\n renderers: Renderers<TNode, T>;\n /** Sizing a frame can ask for before drawing. Absent means it cannot be measured. */\n metrics?: PrimitiveMetrics<TNode>;\n /**\n * Render-time URL trust, the second of the two layers in `validate/url.ts`.\n *\n * Returning `null` drops the node. Applied even to an unvalidated node, so a\n * renderer invoked directly still cannot emit an unsafe URL.\n */\n sanitize?: (node: TNode) => TNode | null;\n /**\n * Nested nodes, for containers, in the order the `react` renderer draws\n * them; `findNodeElementPairs` relies on it. Absent means a leaf.\n */\n children?: (node: TNode) => readonly PrimitiveChildRef[];\n /**\n * True when this node produces surface output of its own, not only via\n * {@link PrimitiveDefinition.children}. A non-empty `children` result is\n * otherwise the complete source of rendered content, so a hybrid container\n * that still owns string fields returns true to keep rendering when every\n * nested node is hidden from the surface.\n */\n hasOwnContent?: (node: TNode) => boolean;\n /** Contributes this node's CSS by mutating `styles`, once per node per render. */\n collectStyles?: (\n node: TNode,\n env: { styles: T['collector']; context: PrimitiveStyleCollectionContext }\n ) => void;\n}\n\n/**\n * {@link PrimitiveDefinition} with every type parameter erased, and the form an\n * inventory is stored in.\n *\n * A heterogeneous pack has no single `TNode` to be generic over, so the\n * renderers degrade to `unknown` here.\n *\n * Each field carries the same contract as its {@link PrimitiveDefinition}\n * counterpart; only the types are erased.\n */\nexport interface AnyPrimitiveDefinition {\n type: string;\n catalog: PrimitiveCatalogEntry;\n icon?: PrimitiveIcon;\n examples: readonly (PrimitiveNode | PrimitiveExample)[];\n schema: PrimitiveSchema;\n schemaFor?: (bodyNodeSchema: ZodType<unknown>) => PrimitiveSchema;\n renderers: Record<'react' | 'text' | 'markdown', unknown> &\n Partial<Record<'slack', unknown>>;\n metrics?: {\n snapshotHeight?: unknown;\n };\n sanitize?: unknown;\n children?: unknown;\n hasOwnContent?: unknown;\n collectStyles?: unknown;\n}\n\n/** Parses `node` against `schema`, appending path-prefixed messages to `errors`. */\nexport const validateWithSchema = (\n schema: PrimitiveSchema,\n node: unknown,\n path: string,\n errors: ValidationError[]\n): void => {\n const result = schema.safeParse(node, { reportInput: true });\n if (!result.success) {\n errors.push(...formatZodIssues(result.error.issues, path));\n }\n};\n\n/** The `id` every node may carry, unique within a composition. */\nexport const bodyNodeIdSchema = requiredString('must be a non-empty string');\n\n/** The `surfaces` allowlist on a node. Absent means every surface; empty is rejected. */\nexport const bodyNodeSurfacesSchema = z\n .array(\n z.enum(SURFACE_NAMES, {\n error: () => oneOf(SURFACE_NAMES),\n })\n )\n .min(1, { error: 'must contain at least one surface' });\n\n/**\n * The child slot in a container's standalone {@link PrimitiveDefinition.schema},\n * where no body-node union is available.\n *\n * Deliberately permissive rather than `z.unknown()`: it still rejects a child\n * that is not a node at all, which is the error worth catching without an\n * inventory. Anything that depends on *which* types are legal — the validator,\n * the parser, the JSON Schema projection — goes through\n * {@link PrimitiveDefinition.schemaFor} and sees the real union.\n */\nexport const unresolvedBodyNodeSchema = z.looseObject({\n type: requiredString('must be a non-empty string'),\n});\n\n/**\n * Declares one primitive, extending its schema with the `id` and `surfaces`\n * fields every node carries, and closing it to unknown keys so a node is held\n * to the same rule as the composition root and the JSON Schema an agent reads.\n * A schema with its own catchall (`z.looseObject`) keeps it.\n *\n * A pack normally calls the form {@link definePrimitiveFor} binds to its own\n * {@link PackTypes}, so each primitive names only `TNode`.\n */\nexport const definePrimitive = <\n TNode extends PrimitiveNode,\n T extends PackTypes = DefaultPackTypes,\n TSchema extends PrimitiveSchema = PrimitiveSchema,\n>(\n definition: PrimitiveDefinition<TNode, T, TSchema>\n): PrimitiveDefinition<TNode, T, WithNodeFields<TSchema>> => {\n const { schemaFor } = definition;\n return {\n ...definition,\n schema: withNodeFields(definition.schema),\n // Both forms get the node fields, or a container would accept `id` and\n // `surfaces` standalone and reject them inside a composition.\n ...(schemaFor\n ? {\n schemaFor: (bodyNodeSchema: ZodType<unknown>) =>\n withNodeFields(schemaFor(bodyNodeSchema)),\n }\n : {}),\n };\n};\n\n/**\n * {@link definePrimitive} bound to one pack's {@link PackTypes}.\n *\n * ```ts\n * const define = definePrimitiveFor<SlidesPackTypes>();\n * export const note = define({ type: 'note', … });\n * ```\n */\nexport const definePrimitiveFor =\n <T extends PackTypes>() =>\n <\n TNode extends PrimitiveNode,\n TSchema extends PrimitiveSchema = PrimitiveSchema,\n >(\n definition: PrimitiveDefinition<TNode, T, TSchema>\n ): PrimitiveDefinition<TNode, T, WithNodeFields<TSchema>> =>\n definePrimitive<TNode, T, TSchema>(definition);\n\n/**\n * `.extend()` on a generic `ZodObject` widens the shape to `any`, so the\n * return type is rebuilt from `TSchema`'s shape. The brand on a field schema\n * stays on that same object at runtime.\n */\nexport type WithNodeFields<TSchema extends PrimitiveSchema> =\n TSchema extends ZodObject<infer Shape>\n ? ZodObject<\n Shape & {\n id: ReturnType<typeof bodyNodeIdSchema.optional>;\n surfaces: ReturnType<typeof bodyNodeSurfacesSchema.optional>;\n }\n >\n : PrimitiveSchema;\n\n// Marks the field schemas `definePrimitive` adds. A schema derived from a\n// defined one shares them by reference, and `Symbol.for` matches across ESM and\n// CommonJS copies of the SDK.\nconst NODE_FIELD = Symbol.for('elastic.isomer.node_field');\n\nconst nodeField = <T extends ZodType>(schema: T): T =>\n Object.defineProperty(schema, NODE_FIELD, { value: true });\n\nconst NODE_FIELDS = {\n id: nodeField(bodyNodeIdSchema.optional()),\n surfaces: nodeField(bodyNodeSurfacesSchema.optional()),\n};\n\nconst isNodeField = (schema: unknown): boolean => {\n let current = schema;\n while (current && typeof current === 'object') {\n if (Object.hasOwn(current, NODE_FIELD)) return true;\n const { def } = current as {\n def?: { type?: string; innerType?: unknown };\n };\n if (def?.type !== 'optional') return false;\n current = def.innerType;\n }\n return false;\n};\n\nconst withNodeFields = <TSchema extends PrimitiveSchema>(\n schema: TSchema\n): WithNodeFields<TSchema> => {\n const reserved = Object.keys(NODE_FIELDS).find(\n (field) =>\n Object.hasOwn(schema.shape, field) && !isNodeField(schema.shape[field])\n );\n if (reserved) {\n throw new IsomerError(\n ISOMER_ERROR_CODES.RESERVED_NODE_FIELD,\n `definePrimitive: a primitive schema cannot declare \\`${reserved}\\`; every body node has it.`\n );\n }\n const extended = schema.extend(NODE_FIELDS);\n return (\n schema.def.catchall === undefined ? extended.strict() : extended\n ) as WithNodeFields<TSchema>;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"primitive_module.js","sourceRoot":"","sources":["../../src/define/primitive_module.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,CAAC,EAAgC,MAAM,KAAK,CAAC;AAGtD,OAAO,EAEL,aAAa,GAEd,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AASvE,OAAO,EAAE,eAAe,EAAE,KAAK,EA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,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAC9C,IAAI,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,EAAE,CAAC;YACvC,OAAO,IAAI,CAAC;QACd,CAAC;QACD,MAAM,EAAE,GAAG,EAAE,GAAG,OAEf,CAAC;QACF,IAAI,GAAG,EAAE,IAAI,KAAK,UAAU,EAAE,CAAC;YAC7B,OAAO,KAAK,CAAC;QACf,CAAC;QACD,OAAO,GAAG,GAAG,CAAC,SAAS,CAAC;IAC1B,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,MAAM,cAAc,GAAG,CACrB,MAAe,EACU,EAAE;IAC3B,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,IAAI,CAC5C,CAAC,KAAK,EAAE,EAAE,CACR,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAC1E,CAAC;IACF,IAAI,QAAQ,EAAE,CAAC;QACb,MAAM,IAAI,WAAW,CACnB,kBAAkB,CAAC,mBAAmB,EACtC,wDAAwD,QAAQ,6BAA6B,CAC9F,CAAC;IACJ,CAAC;IACD,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IAC5C,OAAO,CACL,MAAM,CAAC,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,QAAQ,CACtC,CAAC;AAC/B,CAAC,CAAC","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nimport type { ReactNode } from 'react';\nimport { z, type ZodObject, type ZodType } from 'zod';\n\nimport type { ActionEventRef } from '../composition/action_event';\nimport {\n type ChildNodeRef,\n SURFACE_NAMES,\n type SurfaceName,\n} from '../composition/body_node_base';\nimport { ISOMER_ERROR_CODES, IsomerError } from '../composition/error';\nimport type { PrimitiveNode } from '../composition/node';\nimport type { ValidationError } from '../composition/validation_error';\n\nimport type { MarkdownContent } from './markdown_content';\nimport type { PrimitiveExample } from './primitive_example';\nimport type { PrimitiveIcon } from './primitive_icon';\nimport type { SlackAssetCollector } from './slack_assets';\nimport type { SlackBlock } from './slack_blocks';\nimport { formatZodIssues, oneOf } from './zod_format';\nimport { requiredString } from './zod_helpers';\n\nexport type { PrimitiveNode };\n\n/**\n * A primitive's entry in the catalog the authoring prompt is built from.\n *\n * Written for the model rather than for a developer: `useWhen` and `avoidWhen`\n * are what steer it away from reaching for the wrong primitive. `name` is the\n * one host-facing field, and the prompt never prints it.\n */\nexport interface PrimitiveCatalogEntry {\n type: string;\n /** Short name a host shows for the primitive, e.g. `Stat group`. Absent means the host derives one from `type`. */\n name?: string;\n /**\n * Description of this primitive's `$def` in the authoring JSON Schema.\n *\n * `z.toJSONSchema` drops refinements, so a cross-field rule is restated here.\n * {@link definePrimitive} copies `schema.description` when this is omitted.\n */\n description?: string;\n /** One line on what the primitive is for, in the model's voice. */\n purpose: string;\n /** Situations that call for this primitive. Phrase each as a user intent, not a shape. */\n useWhen: string[];\n /** Situations that look like a fit but are not, naming the primitive to reach for instead. */\n avoidWhen: string[];\n /** A node literal the authoring prompt inlines under this primitive. */\n example: unknown;\n}\n\n/** A style a renderer asks for by name, resolved to a class by the host's adapter. */\nexport interface StyleHandle {\n /** Stable lookup key. The adapter's map is keyed on this. */\n key: string;\n /** Debug-facing label, which an adapter may fold into a generated class name. */\n readableName: string;\n}\n\n/** Dotted path into a pack's theme tokens, e.g. `colors.text.subdued`. */\nexport type ThemeTokenPath = string;\n\n/**\n * The sdk's own render context, and {@link DefaultPackTypes.context}.\n *\n * A pack with real theme tokens or a richer style-handle type declares its\n * own context in its {@link PackTypes}; {@link StyledRenderContext} is the\n * sdk's own extension. The bag is what lets a pack narrow without\n * re-declaring everything that mentions a context.\n */\nexport interface PrimitiveRenderContext {\n /**\n * The progressive enhancements this render may assume, by id. A set rather\n * than a field per feature so adding an enhancement costs no plumbing:\n * containers forward the whole context, and a renderer asks\n * `context.enhancements?.has('tableSort')`.\n *\n * Empty or absent is the baseline every host can render, so a renderer must\n * still answer the question on its own. See `docs/rendering.md`.\n */\n enhancements?: ReadonlySet<string>;\n /** Turns on `nodeAnchor` outside an HTML surface render, on the React and `snapshot` surfaces; inside one, the surface decides. */\n anchors?: boolean;\n /** Raises an interaction for the host to route. Absent means render non-interactively. */\n onEvent?: (event: ActionEventRef) => void;\n}\n\n/**\n * The render-context argument, optional only when omitting it is sound.\n *\n * The sdk's own {@link PrimitiveRenderContext} has no required field, so `{}`\n * is a complete value and a caller may leave it out. A pack that narrows the\n * context with a required member makes the argument mandatory.\n */\nexport type ReactContextArg<TContext> =\n Record<string, never> extends TContext\n ? [context?: TContext]\n : [context: TContext];\n\n/**\n * {@link PrimitiveRenderContext} plus the CSS-in-JS hooks an HTML style adapter\n * supplies. A pack that styles differently uses its own `TContext` instead.\n */\nexport interface StyledRenderContext extends PrimitiveRenderContext {\n /** Resolves handles to a `className`. Absent means the host supplies no styling. */\n resolveClassName?: (...handles: StyleHandle[]) => string;\n /** Resolves a theme token to a CSS variable reference. Absent means inline the literal value. */\n cssVarRef?: (path: ThemeTokenPath) => `var(--${string})`;\n}\n\n/** Passed to a primitive's style collector so it can vary CSS by layout mode. */\nexport interface PrimitiveStyleCollectionContext {\n /** The render fills its container rather than sitting at a fixed width. */\n fluid?: boolean;\n}\n\n/** A pack's collected styles, opaque to the SDK. */\nexport type PrimitiveStyleCollector = object;\n\n/**\n * The types a pack binds once and writes every primitive against: the palette\n * its frames supply, the context its `react` renderers receive, the collector\n * its `collectStyles` hooks mutate, and the Slack payload and collector types.\n *\n * Extend {@link DefaultPackTypes} and narrow only what the pack needs:\n *\n * ```ts\n * interface SlidesPackTypes extends DefaultPackTypes {\n * theme: SlideTheme;\n * context: SlideRenderContext;\n * }\n * ```\n */\nexport interface PackTypes {\n theme: unknown;\n context: unknown;\n collector: PrimitiveStyleCollector;\n slackBlock: unknown;\n slackCollector: unknown;\n}\n\n/** {@link PackTypes} as the sdk itself binds them, and the default everywhere. */\nexport interface DefaultPackTypes extends PackTypes {\n theme: unknown;\n context: PrimitiveRenderContext;\n collector: PrimitiveStyleCollector;\n slackBlock: SlackBlock;\n slackCollector: SlackAssetCollector;\n}\n\n/**\n * Each surface's renderer signature: the env bag it receives beyond the node,\n * and what it returns.\n *\n * Written out per surface rather than derived through an indexed access. A bag\n * is additive: a new extra on a surface is not an arity break. {@link Renderer}\n * indexes this table for the dispatcher cast; {@link Renderers} does not.\n */\nexport interface SurfaceMap<T extends PackTypes = DefaultPackTypes> {\n react: {\n env: {\n context: T['context'];\n scope: RenderScope<T>;\n /**\n * The frame's resolved palette, when this render is reached through the\n * `snapshot` surface. A bare `react`/`html` render has no {@link Frame} to\n * resolve one from, so it is absent there — a pack that needs a\n * literal color outside `snapshot` still goes through `context`.\n */\n theme?: T['theme'];\n };\n output: ReactNode;\n };\n /**\n * Identical to `react`, and served by the same renderer: an image backend\n * lays out the pack's DOM tree and stylesheet rather than a second tree\n * authored for it. The surface stays separate so a node can be hidden from\n * snapshots alone, and so a {@link Frame} has something to draw inside.\n */\n snapshot: {\n env: {\n context: T['context'];\n scope: RenderScope<T>;\n /** The frame's resolved palette for this render's mode; see `react.env.theme`. */\n theme?: T['theme'];\n };\n output: ReactNode;\n };\n text: {\n env: {\n scope: RenderScope<T>;\n };\n output: string;\n };\n /** Content built with `md`, escaped where it lands; authored Markdown source goes through `md.authored`. */\n markdown: {\n env: {\n scope: RenderScope<T>;\n };\n output: MarkdownContent;\n };\n /**\n * Returns one payload or several, so a primitive need not wrap a single\n * payload in an array.\n */\n slack: {\n env: {\n collector?: T['slackCollector'];\n scope: RenderScope<T>;\n };\n output: T['slackBlock'] | readonly T['slackBlock'][];\n };\n}\n\n/**\n * The dispatcher a renderer is given so a container can recurse into a child\n * owned by another pack. Erased to {@link PrimitiveNode}: a heterogeneous\n * inventory has no single node type to name.\n *\n * Passed as `scope` on every renderer's env bag. The dispatcher's own named\n * methods stay positional.\n */\nexport interface RenderScope<T extends PackTypes = DefaultPackTypes> {\n readonly definitions: readonly AnyPrimitiveDefinition[];\n /** Throws for an unknown node type; a missing primitive is a bug, not a degradation. */\n getDefinition(node: PrimitiveNode): AnyPrimitiveDefinition;\n /** `undefined` when the node is hidden from `surface`, `sanitize` drops it, or its primitive declares no renderer for `surface`. */\n renderOn<S extends SurfaceName>(\n surface: S,\n node: PrimitiveNode,\n extras: Omit<SurfaceMap<T>[S]['env'], 'scope'>\n ): SurfaceMap<T>[S]['output'] | undefined;\n renderReact(node: PrimitiveNode, context?: T['context']): ReactNode;\n collectStyles(\n node: PrimitiveNode,\n styles: PrimitiveStyleCollector,\n context: PrimitiveStyleCollectionContext\n ): void;\n renderText(node: PrimitiveNode): string;\n renderMarkdown(node: PrimitiveNode): string;\n /** A child as content, for a container building with `md`. */\n renderMarkdownContent(node: PrimitiveNode): MarkdownContent;\n /** Empty when the node is hidden from `slack`, `sanitize` drops it, or its renderer returns nothing; a node with no `slack` renderer degrades through its markdown. */\n renderSlack(\n node: PrimitiveNode,\n collector?: T['slackCollector']\n ): readonly T['slackBlock'][];\n /** `0` when the node is hidden from `snapshot` or its primitive declares no `metrics.snapshotHeight`. */\n estimateSnapshotHeight(node: PrimitiveNode): number;\n /** Appends schema failures under `path` to `errors`, each naming `node`'s type. */\n validate(node: PrimitiveNode, path: string, errors: ValidationError[]): void;\n}\n\n/**\n * One surface's renderer for one node type, per {@link SurfaceMap}.\n *\n * Indexes the env bag. Do not use this to type the renderers map: the\n * written-out signatures on {@link Renderers} are what keep the bags checked\n * per surface.\n */\nexport type Renderer<\n TNode extends PrimitiveNode,\n S extends SurfaceName,\n T extends PackTypes = DefaultPackTypes,\n> = (node: TNode, env: SurfaceMap<T>[S]['env']) => SurfaceMap<T>[S]['output'];\n\n/**\n * The surface a pack may declare beyond the mandatory three.\n *\n * Only `slack`, and even that stays optional per primitive: the dispatcher\n * converts the mandatory markdown to Block Kit, so a missing Slack renderer\n * degrades rather than disappearing. `snapshot` is not here because no primitive\n * implements it — the surface reuses `react`.\n */\nexport const OPTIONAL_SURFACES = [\n 'slack',\n] as const satisfies readonly SurfaceName[];\n\n/** One of the {@link OPTIONAL_SURFACES}. */\nexport type OptionalSurface = (typeof OPTIONAL_SURFACES)[number];\n\n/**\n * One renderer per surface a primitive implements.\n *\n * `react`, `text`, and `markdown` are always required: those three are what\n * make \"every composition degrades\" true. `react` serves the `snapshot` surface\n * too, so targeting images costs a primitive nothing.\n *\n * `slack` is declared method-style deliberately: method parameters are checked\n * bivariantly, which is what lets a pack narrow the collector's node type.\n */\nexport interface Renderers<\n TNode extends PrimitiveNode,\n T extends PackTypes = DefaultPackTypes,\n> {\n react(\n node: TNode,\n env: {\n context: T['context'];\n scope: RenderScope<T>;\n /** See {@link SurfaceMap.react}'s `env.theme`. */\n theme?: T['theme'];\n }\n ): ReactNode;\n text(\n node: TNode,\n env: {\n scope: RenderScope<T>;\n }\n ): string;\n markdown(\n node: TNode,\n env: {\n scope: RenderScope<T>;\n }\n ): MarkdownContent;\n slack?(\n node: TNode,\n env: {\n collector?: T['slackCollector'];\n scope: RenderScope<T>;\n }\n ): T['slackBlock'] | readonly T['slackBlock'][];\n}\n\n/**\n * Measurements a frame can ask of a node before drawing it.\n *\n * `snapshotHeight` is optional. The height estimate is `0` when it is missing, so\n * a frame that sums node heights sizes short.\n */\nexport interface PrimitiveMetrics<TNode extends PrimitiveNode> {\n /** The node's drawn height in pixels at the frame's width. */\n snapshotHeight?: (node: TNode) => number;\n}\n\n/**\n * Every primitive's schema is an object schema, because {@link definePrimitive}\n * extends it with `id` and `surfaces` and the composition builds a\n * `z.discriminatedUnion('type', …)` over them. Typed as `ZodObject` rather\n * than `ZodType<unknown>` so a union or intersection schema is a compile\n * error at the definition, not a runtime failure at the first `.extend()`.\n * Zod 4 types `z.object().superRefine(…)` as a `ZodObject` and preserves the\n * refinement through `.extend()`, so top-level refinements are unaffected.\n */\nexport type PrimitiveSchema = ZodObject;\n\n/**\n * The child-ref shape a primitive definition's own `children` returns.\n *\n * {@link ChildNodeRef} stays erased (`node: unknown`) because\n * `createChildNodeWalker` mixes children from every primitive type in the\n * runtime into one map and cannot name a single node type for them. A single\n * definition has no such excuse: its `children` should not type-check\n * against `unknown` and let something that is not a {@link PrimitiveNode} —\n * `null`, for instance — silently disappear from every tree walk.\n */\nexport interface PrimitiveChildRef extends ChildNodeRef {\n node: PrimitiveNode;\n}\n\n/**\n * One primitive: its node type, schema, catalog entry, and a renderer per\n * surface. The unit of vocabulary, and what {@link definePrimitive} takes.\n *\n * `T` is the pack's {@link PackTypes}, bound once with\n * {@link definePrimitiveFor} so each primitive names only `TNode`.\n */\nexport interface PrimitiveDefinition<\n TNode extends PrimitiveNode,\n T extends PackTypes = DefaultPackTypes,\n TSchema extends PrimitiveSchema = PrimitiveSchema,\n> {\n /** The node's discriminant, and the key this primitive occupies in an inventory. */\n type: TNode['type'];\n /** How the authoring prompt describes this primitive to the model. */\n catalog: PrimitiveCatalogEntry;\n /** Host-facing glyph, never shown to the model. Absent means the host supplies its own. */\n icon?: PrimitiveIcon;\n /**\n * Driven by the conformance harness, bare or named; read them with\n * `exampleNodes` or `primitiveExamples`. The catalog `example` is what the\n * prompt shows.\n */\n examples: readonly (TNode | PrimitiveExample<TNode>)[];\n /**\n * This primitive on its own. A container declares\n * {@link PrimitiveDefinition.schemaFor} as well, and uses\n * {@link unresolvedBodyNodeSchema} in the child slot here.\n */\n schema: TSchema;\n /**\n * A container's schema, bound to the body-node union of the composition it is\n * being built into.\n *\n * Declaring the shape and letting each composition supply its own union is\n * what lets one primitive appear in two runtimes with different inventories:\n * `z.lazy` memoizes per instance, and an instance built here belongs to\n * exactly one union.\n */\n schemaFor?: (bodyNodeSchema: ZodType<unknown>) => PrimitiveSchema;\n /** One function per surface; `react` serves `snapshot` as well. */\n renderers: Renderers<TNode, T>;\n /** Sizing a frame can ask for before drawing. Absent means it cannot be measured. */\n metrics?: PrimitiveMetrics<TNode>;\n /**\n * Render-time URL trust, the second of the two layers in `validate/url.ts`.\n *\n * Returning `null` drops the node. Applied even to an unvalidated node, so a\n * renderer invoked directly still cannot emit an unsafe URL.\n */\n sanitize?: (node: TNode) => TNode | null;\n /**\n * Nested nodes, for containers, in the order the `react` renderer draws\n * them; `findNodeElementPairs` relies on it. Absent means a leaf.\n */\n children?: (node: TNode) => readonly PrimitiveChildRef[];\n /**\n * True when this node produces surface output of its own, not only via\n * {@link PrimitiveDefinition.children}. A non-empty `children` result is\n * otherwise the complete source of rendered content, so a hybrid container\n * that still owns string fields returns true to keep rendering when every\n * nested node is hidden from the surface.\n */\n hasOwnContent?: (node: TNode) => boolean;\n /** Contributes this node's CSS by mutating `styles`, once per node per render. */\n collectStyles?: (\n node: TNode,\n env: { styles: T['collector']; context: PrimitiveStyleCollectionContext }\n ) => void;\n}\n\n/**\n * {@link PrimitiveDefinition} with every type parameter erased, and the form an\n * inventory is stored in.\n *\n * A heterogeneous pack has no single `TNode` to be generic over, so the\n * renderers degrade to `unknown` here.\n *\n * Each field carries the same contract as its {@link PrimitiveDefinition}\n * counterpart; only the types are erased.\n */\nexport interface AnyPrimitiveDefinition {\n type: string;\n catalog: PrimitiveCatalogEntry;\n icon?: PrimitiveIcon;\n examples: readonly (PrimitiveNode | PrimitiveExample)[];\n schema: PrimitiveSchema;\n schemaFor?: (bodyNodeSchema: ZodType<unknown>) => PrimitiveSchema;\n renderers: Record<'react' | 'text' | 'markdown', unknown> &\n Partial<Record<'slack', unknown>>;\n metrics?: {\n snapshotHeight?: unknown;\n };\n sanitize?: unknown;\n children?: unknown;\n hasOwnContent?: unknown;\n collectStyles?: unknown;\n}\n\n/** Parses `node` against `schema`, appending path-prefixed messages to `errors`. */\nexport const validateWithSchema = (\n schema: PrimitiveSchema,\n node: unknown,\n path: string,\n errors: ValidationError[]\n): void => {\n const result = schema.safeParse(node, { reportInput: true });\n if (!result.success) {\n errors.push(...formatZodIssues(result.error.issues, path));\n }\n};\n\n/** The `id` every node may carry, unique within a composition. */\nexport const bodyNodeIdSchema = requiredString('must be a non-empty string');\n\n/** The `surfaces` allowlist on a node. Absent means every surface; empty is rejected. */\nexport const bodyNodeSurfacesSchema = z\n .array(\n z.enum(SURFACE_NAMES, {\n error: () => oneOf(SURFACE_NAMES),\n })\n )\n .min(1, { error: 'must contain at least one surface' });\n\n/**\n * The child slot in a container's standalone {@link PrimitiveDefinition.schema},\n * where no body-node union is available.\n *\n * Deliberately permissive rather than `z.unknown()`: it still rejects a child\n * that is not a node at all, which is the error worth catching without an\n * inventory. Anything that depends on *which* types are legal — the validator,\n * the parser, the JSON Schema projection — goes through\n * {@link PrimitiveDefinition.schemaFor} and sees the real union.\n */\nexport const unresolvedBodyNodeSchema = z.looseObject({\n type: requiredString('must be a non-empty string'),\n});\n\n/**\n * Declares one primitive, extending its schema with the `id` and `surfaces`\n * fields every node carries, and closing it to unknown keys so a node is held\n * to the same rule as the composition root and the JSON Schema an agent reads.\n * A schema with its own catchall (`z.looseObject`) keeps it.\n *\n * A pack normally calls the form {@link definePrimitiveFor} binds to its own\n * {@link PackTypes}, so each primitive names only `TNode`.\n */\nexport const definePrimitive = <\n TNode extends PrimitiveNode,\n T extends PackTypes = DefaultPackTypes,\n TSchema extends PrimitiveSchema = PrimitiveSchema,\n>(\n definition: PrimitiveDefinition<TNode, T, TSchema>\n): PrimitiveDefinition<TNode, T, WithNodeFields<TSchema>> => {\n const { schemaFor, schema, catalog } = definition;\n const described =\n catalog.description === undefined ? schema.description : undefined;\n return {\n ...definition,\n ...(described === undefined\n ? {}\n : { catalog: { ...catalog, description: described } }),\n schema: withNodeFields(schema),\n // Both forms get the node fields, or a container would accept `id` and\n // `surfaces` standalone and reject them inside a composition.\n ...(schemaFor\n ? {\n schemaFor: (bodyNodeSchema: ZodType<unknown>) =>\n withNodeFields(schemaFor(bodyNodeSchema)),\n }\n : {}),\n };\n};\n\n/**\n * {@link definePrimitive} bound to one pack's {@link PackTypes}.\n *\n * ```ts\n * const define = definePrimitiveFor<SlidesPackTypes>();\n * export const note = define({ type: 'note', … });\n * ```\n */\nexport const definePrimitiveFor =\n <T extends PackTypes>() =>\n <\n TNode extends PrimitiveNode,\n TSchema extends PrimitiveSchema = PrimitiveSchema,\n >(\n definition: PrimitiveDefinition<TNode, T, TSchema>\n ): PrimitiveDefinition<TNode, T, WithNodeFields<TSchema>> =>\n definePrimitive<TNode, T, TSchema>(definition);\n\n/**\n * `.extend()` on a generic `ZodObject` widens the shape to `any`, so the\n * return type is rebuilt from `TSchema`'s shape. The brand on a field schema\n * stays on that same object at runtime.\n */\nexport type WithNodeFields<TSchema extends PrimitiveSchema> =\n TSchema extends ZodObject<infer Shape>\n ? ZodObject<\n Shape & {\n id: ReturnType<typeof bodyNodeIdSchema.optional>;\n surfaces: ReturnType<typeof bodyNodeSurfacesSchema.optional>;\n }\n >\n : PrimitiveSchema;\n\n// Marks the field schemas `definePrimitive` adds. A schema derived from a\n// defined one shares them by reference, and `Symbol.for` matches across ESM and\n// CommonJS copies of the SDK.\nconst NODE_FIELD = Symbol.for('elastic.isomer.node_field');\n\nconst nodeField = <T extends ZodType>(schema: T): T =>\n Object.defineProperty(schema, NODE_FIELD, { value: true });\n\nconst NODE_FIELDS = {\n id: nodeField(bodyNodeIdSchema.optional()),\n surfaces: nodeField(bodyNodeSurfacesSchema.optional()),\n};\n\nconst isNodeField = (schema: unknown): boolean => {\n let current = schema;\n while (current && typeof current === 'object') {\n if (Object.hasOwn(current, NODE_FIELD)) {\n return true;\n }\n const { def } = current as {\n def?: { type?: string; innerType?: unknown };\n };\n if (def?.type !== 'optional') {\n return false;\n }\n current = def.innerType;\n }\n return false;\n};\n\nconst withNodeFields = <TSchema extends PrimitiveSchema>(\n schema: TSchema\n): WithNodeFields<TSchema> => {\n const reserved = Object.keys(NODE_FIELDS).find(\n (field) =>\n Object.hasOwn(schema.shape, field) && !isNodeField(schema.shape[field])\n );\n if (reserved) {\n throw new IsomerError(\n ISOMER_ERROR_CODES.RESERVED_NODE_FIELD,\n `definePrimitive: a primitive schema cannot declare \\`${reserved}\\`; every body node has it.`\n );\n }\n const extended = schema.extend(NODE_FIELDS);\n return (\n schema.def.catchall === undefined ? extended.strict() : extended\n ) as WithNodeFields<TSchema>;\n};\n"]}
|
package/dist/entries/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { type ActionEventRef, type BodyNodeBase, type ChildNodeRef, type ChildNodeWalker, type Composition, type CompositionMeta, type DisplayValue, type IsomerErrorCode, type NamedColor, type NamedColorPalette, type PrimitiveNode, type RenderTheme, type StructuredValue, type StructuredValueFormat, type SurfaceName, type ValidationError, ALL_NAMED_COLORS, BODY_NODE_SURFACES, ISOMER_ERROR_CODES, STRUCTURED_VALUE_FORMATS, SURFACE_NAMES, CompositionValidationError, createChildNodeWalker, formatValidationError, IsomerError, isVisibleOnSurface, mapCompositionNodes, someBodyNode, } from '../composition/index.js';
|
|
2
2
|
export { type AnyPrimitiveDefinition, type BoundFrame, type DefaultPackTypes, type ExampleNode, type Frame, type FrameBody, type FrameComposition, type FrameDispatcher, type FrameHeader, type FrameViewport, type NormalizedPrimitiveExample, type OptionalSurface, type PackTypes, type PrimitiveCatalogEntry, type PrimitiveChildRef, type PrimitiveDefinition, type PrimitiveExample, type PrimitiveIcon, type PrimitiveMetrics, type PrimitiveRenderContext, type PrimitiveSchema, type PrimitiveStyleCollectionContext, type PrimitiveStyleCollector, type ReactContextArg, type Renderer, type Renderers, type RenderScope, type StyledRenderContext, type StyleHandle, type SurfaceMap, type ThemePair, type ThemeTokenPath, type WithNodeFields, ICON_VARS, OPTIONAL_SURFACES, bindFrame, definePrimitive, definePrimitiveFor, exampleNodes, formatZodIssues, primitiveExamples, requiredString, unresolvedBodyNodeSchema, z, } from '../define/index.js';
|
|
3
|
-
export { type AnyPrimitivePack, type CapabilitySources, type ComposedPacks, type EnhancementDefinition, type HostCapabilities, type PackAuthoringOptions, type PackStyleAdapter, type PrimitiveGroup, type PrimitivePack, type PrimitivePackInput, type SurfaceSupport, composePacks, definePrimitivePack, describeCapabilities, scopeScript, } from '../pack/index.js';
|
|
3
|
+
export { type AnyPrimitivePack, type CapabilitySources, type ComposedPacks, type EnhancementDefinition, type HostCapabilities, type PackAuthoringOptions, type PackStyleAdapter, type PrimitiveGroup, type PrimitivePack, type PrimitivePackInput, type SurfaceSupport, UNCATEGORIZED_GROUP_TITLE, composePacks, definePrimitivePack, describeCapabilities, scopeScript, } from '../pack/index.js';
|
|
4
4
|
export { type FormatDisplayValueOptions, type LayoutBox, type LayoutFinding, type LayoutRect, type PayloadMeasurement, type PrimitiveDispatcher, type PrimitiveDispatcherOptions, LAYOUT_ROOM_ATTRIBUTE, NODE_ANCHOR_ATTRIBUTE, checkLayout, createPrimitiveDispatcher, formatDisplayValue, isStructuredValue, layoutRoom, nodeAnchor, rawDisplayValue, withNodeAnchors, withoutAnchors, } from '../render/index.js';
|
|
5
5
|
export { type AuthoringJsonSchemaOptions, type CheckedComposition, type CheckedValidationResult, type CompositionJsonSchemaOptions, type CompositionSchemaOptions, type CompositionValidatorOptions, type InputBudget, type InputBudgetCheck, type ParsedComposition, type UrlSchemaOptions, type ValidationErrorMode, type ValidationResult, type ValidationWarning, ASSET_URL_MESSAGE, ASSET_URL_RULE, BLOCKED_HREF, MAX_INPUT_CHARACTERS, MAX_INPUT_DEPTH, MAX_INPUT_VALUES, NAVIGATION_HREF_MESSAGE, NAVIGATION_HREF_RULE, assetUrl, authoringSchemaSubset, buildAuthoringJsonSchema, buildCompositionJsonSchema, checkInputBudget, compositionToRender, createCompositionParser, createCompositionValidator, displayValueSchema, getCompositionSchemaForDefinitions, isInputRefusal, namedColorSchema, navigationHref, renderThemeSchema, sanitizeAssetUrl, sanitizeNavigationHref, structuredValueSchema, warningsForSurface, } from '../validate/index.js';
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/entries/index.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,qBAAqB,EAC1B,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EAClB,wBAAwB,EACxB,aAAa,EACb,0BAA0B,EAC1B,qBAAqB,EACrB,qBAAqB,EACrB,WAAW,EACX,kBAAkB,EAClB,mBAAmB,EACnB,YAAY,GACb,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,KAAK,sBAAsB,EAC3B,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,KAAK,KAAK,EACV,KAAK,SAAS,EACd,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,0BAA0B,EAC/B,KAAK,eAAe,EACpB,KAAK,SAAS,EACd,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,sBAAsB,EAC3B,KAAK,eAAe,EACpB,KAAK,+BAA+B,EACpC,KAAK,uBAAuB,EAC5B,KAAK,eAAe,EACpB,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,KAAK,WAAW,EAChB,KAAK,mBA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,EACvB,oBAAoB,EACpB,QAAQ,EACR,qBAAqB,EACrB,wBAAwB,EACxB,0BAA0B,EAC1B,gBAAgB,EAChB,mBAAmB,EACnB,uBAAuB,EACvB,0BAA0B,EAC1B,kBAAkB,EAClB,kCAAkC,EAClC,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,sBAAsB,EACtB,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/entries/index.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,qBAAqB,EAC1B,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EAClB,wBAAwB,EACxB,aAAa,EACb,0BAA0B,EAC1B,qBAAqB,EACrB,qBAAqB,EACrB,WAAW,EACX,kBAAkB,EAClB,mBAAmB,EACnB,YAAY,GACb,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,KAAK,sBAAsB,EAC3B,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,KAAK,KAAK,EACV,KAAK,SAAS,EACd,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,0BAA0B,EAC/B,KAAK,eAAe,EACpB,KAAK,SAAS,EACd,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,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ACrB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,iBAAiB,EACjB,cAAc,EACd,YAAY,EACZ,oBAAoB,EACpB,eAAe,EACf,gBAAgB,EAChB,uBAAuB,EACvB,oBAAoB,EACpB,QAAQ,EACR,qBAAqB,EACrB,wBAAwB,EACxB,0BAA0B,EAC1B,gBAAgB,EAChB,mBAAmB,EACnB,uBAAuB,EACvB,0BAA0B,EAC1B,kBAAkB,EAClB,kCAAkC,EAClC,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,sBAAsB,EACtB,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,aAAa,CAAC"}
|
package/dist/entries/index.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export { ALL_NAMED_COLORS, BODY_NODE_SURFACES, ISOMER_ERROR_CODES, STRUCTURED_VALUE_FORMATS, SURFACE_NAMES, CompositionValidationError, createChildNodeWalker, formatValidationError, IsomerError, isVisibleOnSurface, mapCompositionNodes, someBodyNode, } from '../composition/index.js';
|
|
8
8
|
export { ICON_VARS, OPTIONAL_SURFACES, bindFrame, definePrimitive, definePrimitiveFor, exampleNodes, formatZodIssues, primitiveExamples, requiredString, unresolvedBodyNodeSchema, z, } from '../define/index.js';
|
|
9
|
-
export { composePacks, definePrimitivePack, describeCapabilities, scopeScript, } from '../pack/index.js';
|
|
9
|
+
export { UNCATEGORIZED_GROUP_TITLE, composePacks, definePrimitivePack, describeCapabilities, scopeScript, } from '../pack/index.js';
|
|
10
10
|
export { LAYOUT_ROOM_ATTRIBUTE, NODE_ANCHOR_ATTRIBUTE, checkLayout, createPrimitiveDispatcher, formatDisplayValue, isStructuredValue, layoutRoom, nodeAnchor, rawDisplayValue, withNodeAnchors, withoutAnchors, } from '../render/index.js';
|
|
11
11
|
export { ASSET_URL_MESSAGE, ASSET_URL_RULE, BLOCKED_HREF, MAX_INPUT_CHARACTERS, MAX_INPUT_DEPTH, MAX_INPUT_VALUES, NAVIGATION_HREF_MESSAGE, NAVIGATION_HREF_RULE, assetUrl, authoringSchemaSubset, buildAuthoringJsonSchema, buildCompositionJsonSchema, checkInputBudget, compositionToRender, createCompositionParser, createCompositionValidator, displayValueSchema, getCompositionSchemaForDefinitions, isInputRefusal, namedColorSchema, navigationHref, renderThemeSchema, sanitizeAssetUrl, sanitizeNavigationHref, structuredValueSchema, warningsForSurface, } from '../validate/index.js';
|
|
12
12
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/entries/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAiBL,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EAClB,wBAAwB,EACxB,aAAa,EACb,0BAA0B,EAC1B,qBAAqB,EACrB,qBAAqB,EACrB,WAAW,EACX,kBAAkB,EAClB,mBAAmB,EACnB,YAAY,GACb,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAkCL,SAAS,EACT,iBAAiB,EACjB,SAAS,EACT,eAAe,EACf,kBAAkB,EAClB,YAAY,EACZ,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,wBAAwB,EACxB,CAAC,GACF,MAAM,WAAW,CAAC;AACnB,OAAO,EAYL,YAAY,EACZ,mBAAmB,EACnB,oBAAoB,EACpB,WAAW,GACZ,MAAM,SAAS,CAAC;AACjB,OAAO,EAQL,qBAAqB,EACrB,qBAAqB,EACrB,WAAW,EACX,yBAAyB,EACzB,kBAAkB,EAClB,iBAAiB,EACjB,UAAU,EACV,UAAU,EACV,eAAe,EACf,eAAe,EACf,cAAc,GACf,MAAM,WAAW,CAAC;AACnB,OAAO,EAcL,iBAAiB,EACjB,cAAc,EACd,YAAY,EACZ,oBAAoB,EACpB,eAAe,EACf,gBAAgB,EAChB,uBAAuB,EACvB,oBAAoB,EACpB,QAAQ,EACR,qBAAqB,EACrB,wBAAwB,EACxB,0BAA0B,EAC1B,gBAAgB,EAChB,mBAAmB,EACnB,uBAAuB,EACvB,0BAA0B,EAC1B,kBAAkB,EAClB,kCAAkC,EAClC,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,sBAAsB,EACtB,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,aAAa,CAAC","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nexport {\n type ActionEventRef,\n type BodyNodeBase,\n type ChildNodeRef,\n type ChildNodeWalker,\n type Composition,\n type CompositionMeta,\n type DisplayValue,\n type IsomerErrorCode,\n type NamedColor,\n type NamedColorPalette,\n type PrimitiveNode,\n type RenderTheme,\n type StructuredValue,\n type StructuredValueFormat,\n type SurfaceName,\n type ValidationError,\n ALL_NAMED_COLORS,\n BODY_NODE_SURFACES,\n ISOMER_ERROR_CODES,\n STRUCTURED_VALUE_FORMATS,\n SURFACE_NAMES,\n CompositionValidationError,\n createChildNodeWalker,\n formatValidationError,\n IsomerError,\n isVisibleOnSurface,\n mapCompositionNodes,\n someBodyNode,\n} from '../composition';\nexport {\n type AnyPrimitiveDefinition,\n type BoundFrame,\n type DefaultPackTypes,\n type ExampleNode,\n type Frame,\n type FrameBody,\n type FrameComposition,\n type FrameDispatcher,\n type FrameHeader,\n type FrameViewport,\n type NormalizedPrimitiveExample,\n type OptionalSurface,\n type PackTypes,\n type PrimitiveCatalogEntry,\n type PrimitiveChildRef,\n type PrimitiveDefinition,\n type PrimitiveExample,\n type PrimitiveIcon,\n type PrimitiveMetrics,\n type PrimitiveRenderContext,\n type PrimitiveSchema,\n type PrimitiveStyleCollectionContext,\n type PrimitiveStyleCollector,\n type ReactContextArg,\n type Renderer,\n type Renderers,\n type RenderScope,\n type StyledRenderContext,\n type StyleHandle,\n type SurfaceMap,\n type ThemePair,\n type ThemeTokenPath,\n type WithNodeFields,\n ICON_VARS,\n OPTIONAL_SURFACES,\n bindFrame,\n definePrimitive,\n definePrimitiveFor,\n exampleNodes,\n formatZodIssues,\n primitiveExamples,\n requiredString,\n unresolvedBodyNodeSchema,\n z,\n} from '../define';\nexport {\n type AnyPrimitivePack,\n type CapabilitySources,\n type ComposedPacks,\n type EnhancementDefinition,\n type HostCapabilities,\n type PackAuthoringOptions,\n type PackStyleAdapter,\n type PrimitiveGroup,\n type PrimitivePack,\n type PrimitivePackInput,\n type SurfaceSupport,\n composePacks,\n definePrimitivePack,\n describeCapabilities,\n scopeScript,\n} from '../pack';\nexport {\n type FormatDisplayValueOptions,\n type LayoutBox,\n type LayoutFinding,\n type LayoutRect,\n type PayloadMeasurement,\n type PrimitiveDispatcher,\n type PrimitiveDispatcherOptions,\n LAYOUT_ROOM_ATTRIBUTE,\n NODE_ANCHOR_ATTRIBUTE,\n checkLayout,\n createPrimitiveDispatcher,\n formatDisplayValue,\n isStructuredValue,\n layoutRoom,\n nodeAnchor,\n rawDisplayValue,\n withNodeAnchors,\n withoutAnchors,\n} from '../render';\nexport {\n type AuthoringJsonSchemaOptions,\n type CheckedComposition,\n type CheckedValidationResult,\n type CompositionJsonSchemaOptions,\n type CompositionSchemaOptions,\n type CompositionValidatorOptions,\n type InputBudget,\n type InputBudgetCheck,\n type ParsedComposition,\n type UrlSchemaOptions,\n type ValidationErrorMode,\n type ValidationResult,\n type ValidationWarning,\n ASSET_URL_MESSAGE,\n ASSET_URL_RULE,\n BLOCKED_HREF,\n MAX_INPUT_CHARACTERS,\n MAX_INPUT_DEPTH,\n MAX_INPUT_VALUES,\n NAVIGATION_HREF_MESSAGE,\n NAVIGATION_HREF_RULE,\n assetUrl,\n authoringSchemaSubset,\n buildAuthoringJsonSchema,\n buildCompositionJsonSchema,\n checkInputBudget,\n compositionToRender,\n createCompositionParser,\n createCompositionValidator,\n displayValueSchema,\n getCompositionSchemaForDefinitions,\n isInputRefusal,\n namedColorSchema,\n navigationHref,\n renderThemeSchema,\n sanitizeAssetUrl,\n sanitizeNavigationHref,\n structuredValueSchema,\n warningsForSurface,\n} from '../validate';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/entries/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAiBL,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EAClB,wBAAwB,EACxB,aAAa,EACb,0BAA0B,EAC1B,qBAAqB,EACrB,qBAAqB,EACrB,WAAW,EACX,kBAAkB,EAClB,mBAAmB,EACnB,YAAY,GACb,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAkCL,SAAS,EACT,iBAAiB,EACjB,SAAS,EACT,eAAe,EACf,kBAAkB,EAClB,YAAY,EACZ,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,wBAAwB,EACxB,CAAC,GACF,MAAM,WAAW,CAAC;AACnB,OAAO,EAYL,yBAAyB,EACzB,YAAY,EACZ,mBAAmB,EACnB,oBAAoB,EACpB,WAAW,GACZ,MAAM,SAAS,CAAC;AACjB,OAAO,EAQL,qBAAqB,EACrB,qBAAqB,EACrB,WAAW,EACX,yBAAyB,EACzB,kBAAkB,EAClB,iBAAiB,EACjB,UAAU,EACV,UAAU,EACV,eAAe,EACf,eAAe,EACf,cAAc,GACf,MAAM,WAAW,CAAC;AACnB,OAAO,EAcL,iBAAiB,EACjB,cAAc,EACd,YAAY,EACZ,oBAAoB,EACpB,eAAe,EACf,gBAAgB,EAChB,uBAAuB,EACvB,oBAAoB,EACpB,QAAQ,EACR,qBAAqB,EACrB,wBAAwB,EACxB,0BAA0B,EAC1B,gBAAgB,EAChB,mBAAmB,EACnB,uBAAuB,EACvB,0BAA0B,EAC1B,kBAAkB,EAClB,kCAAkC,EAClC,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,sBAAsB,EACtB,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,aAAa,CAAC","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nexport {\n type ActionEventRef,\n type BodyNodeBase,\n type ChildNodeRef,\n type ChildNodeWalker,\n type Composition,\n type CompositionMeta,\n type DisplayValue,\n type IsomerErrorCode,\n type NamedColor,\n type NamedColorPalette,\n type PrimitiveNode,\n type RenderTheme,\n type StructuredValue,\n type StructuredValueFormat,\n type SurfaceName,\n type ValidationError,\n ALL_NAMED_COLORS,\n BODY_NODE_SURFACES,\n ISOMER_ERROR_CODES,\n STRUCTURED_VALUE_FORMATS,\n SURFACE_NAMES,\n CompositionValidationError,\n createChildNodeWalker,\n formatValidationError,\n IsomerError,\n isVisibleOnSurface,\n mapCompositionNodes,\n someBodyNode,\n} from '../composition';\nexport {\n type AnyPrimitiveDefinition,\n type BoundFrame,\n type DefaultPackTypes,\n type ExampleNode,\n type Frame,\n type FrameBody,\n type FrameComposition,\n type FrameDispatcher,\n type FrameHeader,\n type FrameViewport,\n type NormalizedPrimitiveExample,\n type OptionalSurface,\n type PackTypes,\n type PrimitiveCatalogEntry,\n type PrimitiveChildRef,\n type PrimitiveDefinition,\n type PrimitiveExample,\n type PrimitiveIcon,\n type PrimitiveMetrics,\n type PrimitiveRenderContext,\n type PrimitiveSchema,\n type PrimitiveStyleCollectionContext,\n type PrimitiveStyleCollector,\n type ReactContextArg,\n type Renderer,\n type Renderers,\n type RenderScope,\n type StyledRenderContext,\n type StyleHandle,\n type SurfaceMap,\n type ThemePair,\n type ThemeTokenPath,\n type WithNodeFields,\n ICON_VARS,\n OPTIONAL_SURFACES,\n bindFrame,\n definePrimitive,\n definePrimitiveFor,\n exampleNodes,\n formatZodIssues,\n primitiveExamples,\n requiredString,\n unresolvedBodyNodeSchema,\n z,\n} from '../define';\nexport {\n type AnyPrimitivePack,\n type CapabilitySources,\n type ComposedPacks,\n type EnhancementDefinition,\n type HostCapabilities,\n type PackAuthoringOptions,\n type PackStyleAdapter,\n type PrimitiveGroup,\n type PrimitivePack,\n type PrimitivePackInput,\n type SurfaceSupport,\n UNCATEGORIZED_GROUP_TITLE,\n composePacks,\n definePrimitivePack,\n describeCapabilities,\n scopeScript,\n} from '../pack';\nexport {\n type FormatDisplayValueOptions,\n type LayoutBox,\n type LayoutFinding,\n type LayoutRect,\n type PayloadMeasurement,\n type PrimitiveDispatcher,\n type PrimitiveDispatcherOptions,\n LAYOUT_ROOM_ATTRIBUTE,\n NODE_ANCHOR_ATTRIBUTE,\n checkLayout,\n createPrimitiveDispatcher,\n formatDisplayValue,\n isStructuredValue,\n layoutRoom,\n nodeAnchor,\n rawDisplayValue,\n withNodeAnchors,\n withoutAnchors,\n} from '../render';\nexport {\n type AuthoringJsonSchemaOptions,\n type CheckedComposition,\n type CheckedValidationResult,\n type CompositionJsonSchemaOptions,\n type CompositionSchemaOptions,\n type CompositionValidatorOptions,\n type InputBudget,\n type InputBudgetCheck,\n type ParsedComposition,\n type UrlSchemaOptions,\n type ValidationErrorMode,\n type ValidationResult,\n type ValidationWarning,\n ASSET_URL_MESSAGE,\n ASSET_URL_RULE,\n BLOCKED_HREF,\n MAX_INPUT_CHARACTERS,\n MAX_INPUT_DEPTH,\n MAX_INPUT_VALUES,\n NAVIGATION_HREF_MESSAGE,\n NAVIGATION_HREF_RULE,\n assetUrl,\n authoringSchemaSubset,\n buildAuthoringJsonSchema,\n buildCompositionJsonSchema,\n checkInputBudget,\n compositionToRender,\n createCompositionParser,\n createCompositionValidator,\n displayValueSchema,\n getCompositionSchemaForDefinitions,\n isInputRefusal,\n namedColorSchema,\n navigationHref,\n renderThemeSchema,\n sanitizeAssetUrl,\n sanitizeNavigationHref,\n structuredValueSchema,\n warningsForSurface,\n} from '../validate';\n"]}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { type MarkdownBlock, type MarkdownContent, type MarkdownInline, type MarkdownInlineInput, } from '../define/index.js';
|
|
2
|
-
export { type MarkdownEnvelopeDispatcher, type MarkdownEnvelopeOptions, md, renderMarkdownEnvelope, serializeMarkdown, } from '../render/markdown/index.js';
|
|
2
|
+
export { type AuthoredMarkdownSegment, type MarkdownEnvelopeDispatcher, type MarkdownEnvelopeOptions, type SplitAuthoredMarkdownOptions, md, renderMarkdownEnvelope, serializeMarkdown, splitAuthoredMarkdown, } from '../render/markdown/index.js';
|
|
3
3
|
//# sourceMappingURL=markdown.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/entries/markdown.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,mBAAmB,GACzB,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,KAAK,0BAA0B,EAC/B,KAAK,uBAAuB,EAC5B,EAAE,EACF,sBAAsB,EACtB,iBAAiB,
|
|
1
|
+
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/entries/markdown.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,mBAAmB,GACzB,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,KAAK,uBAAuB,EAC5B,KAAK,0BAA0B,EAC/B,KAAK,uBAAuB,EAC5B,KAAK,4BAA4B,EACjC,EAAE,EACF,sBAAsB,EACtB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,oBAAoB,CAAC"}
|
package/dist/entries/markdown.js
CHANGED
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
* 2.0; you may not use this file except in compliance with the Elastic License
|
|
5
5
|
* 2.0.
|
|
6
6
|
*/
|
|
7
|
-
export { md, renderMarkdownEnvelope, serializeMarkdown, } from '../render/markdown/index.js';
|
|
7
|
+
export { md, renderMarkdownEnvelope, serializeMarkdown, splitAuthoredMarkdown, } from '../render/markdown/index.js';
|
|
8
8
|
//# sourceMappingURL=markdown.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown.js","sourceRoot":"","sources":["../../src/entries/markdown.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AASH,OAAO,
|
|
1
|
+
{"version":3,"file":"markdown.js","sourceRoot":"","sources":["../../src/entries/markdown.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AASH,OAAO,EAKL,EAAE,EACF,sBAAsB,EACtB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,oBAAoB,CAAC","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nexport {\n type MarkdownBlock,\n type MarkdownContent,\n type MarkdownInline,\n type MarkdownInlineInput,\n} from '../define';\n\nexport {\n type AuthoredMarkdownSegment,\n type MarkdownEnvelopeDispatcher,\n type MarkdownEnvelopeOptions,\n type SplitAuthoredMarkdownOptions,\n md,\n renderMarkdownEnvelope,\n serializeMarkdown,\n splitAuthoredMarkdown,\n} from '../render/markdown';\n"]}
|
package/dist/pack/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { type CapabilitySources, type HostCapabilities, type SurfaceSupport, describeCapabilities, } from './capabilities.js';
|
|
2
2
|
export { type ComposedPacks, composePacks } from './compose.js';
|
|
3
3
|
export { type EnhancementDefinition, scopeScript } from './enhancements.js';
|
|
4
|
-
export { type AnyPrimitivePack, type PackAuthoringOptions, type PackStyleAdapter, type PrimitiveGroup, type PrimitivePack, type PrimitivePackInput, definePrimitivePack, } from './primitive_pack.js';
|
|
4
|
+
export { type AnyPrimitivePack, type PackAuthoringOptions, type PackStyleAdapter, type PrimitiveGroup, type PrimitivePack, type PrimitivePackInput, UNCATEGORIZED_GROUP_TITLE, definePrimitivePack, } from './primitive_pack.js';
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/pack/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pack/index.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,oBAAoB,GACrB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,KAAK,aAAa,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EAAE,KAAK,qBAAqB,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACzE,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,mBAAmB,GACpB,MAAM,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pack/index.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,oBAAoB,GACrB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,KAAK,aAAa,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EAAE,KAAK,qBAAqB,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACzE,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,yBAAyB,EACzB,mBAAmB,GACpB,MAAM,kBAAkB,CAAC"}
|
package/dist/pack/index.js
CHANGED
|
@@ -7,5 +7,5 @@
|
|
|
7
7
|
export { describeCapabilities, } from './capabilities.js';
|
|
8
8
|
export { composePacks } from './compose.js';
|
|
9
9
|
export { scopeScript } from './enhancements.js';
|
|
10
|
-
export { definePrimitivePack, } from './primitive_pack.js';
|
|
10
|
+
export { UNCATEGORIZED_GROUP_TITLE, definePrimitivePack, } from './primitive_pack.js';
|
|
11
11
|
//# sourceMappingURL=index.js.map
|
package/dist/pack/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/pack/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAIL,oBAAoB,GACrB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAsB,YAAY,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EAA8B,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACzE,OAAO,EAOL,mBAAmB,GACpB,MAAM,kBAAkB,CAAC","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nexport {\n type CapabilitySources,\n type HostCapabilities,\n type SurfaceSupport,\n describeCapabilities,\n} from './capabilities';\nexport { type ComposedPacks, composePacks } from './compose';\nexport { type EnhancementDefinition, scopeScript } from './enhancements';\nexport {\n type AnyPrimitivePack,\n type PackAuthoringOptions,\n type PackStyleAdapter,\n type PrimitiveGroup,\n type PrimitivePack,\n type PrimitivePackInput,\n definePrimitivePack,\n} from './primitive_pack';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/pack/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAIL,oBAAoB,GACrB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAsB,YAAY,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EAA8B,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACzE,OAAO,EAOL,yBAAyB,EACzB,mBAAmB,GACpB,MAAM,kBAAkB,CAAC","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nexport {\n type CapabilitySources,\n type HostCapabilities,\n type SurfaceSupport,\n describeCapabilities,\n} from './capabilities';\nexport { type ComposedPacks, composePacks } from './compose';\nexport { type EnhancementDefinition, scopeScript } from './enhancements';\nexport {\n type AnyPrimitivePack,\n type PackAuthoringOptions,\n type PackStyleAdapter,\n type PrimitiveGroup,\n type PrimitivePack,\n type PrimitivePackInput,\n UNCATEGORIZED_GROUP_TITLE,\n definePrimitivePack,\n} from './primitive_pack';\n"]}
|
|
@@ -14,7 +14,7 @@ export interface PackAuthoringOptions {
|
|
|
14
14
|
describe?: Readonly<Record<string, string>>;
|
|
15
15
|
/** `$defId.property` paths to drop, from this pack's own primitives. */
|
|
16
16
|
omitProperties?: readonly string[];
|
|
17
|
-
/** Headings an index catalog sorts this pack's primitives under, in order. */
|
|
17
|
+
/** Headings an index catalog sorts this pack's primitives under, in order. A type in none is listed under {@link UNCATEGORIZED_GROUP_TITLE}. */
|
|
18
18
|
groups?: readonly PrimitiveGroup[];
|
|
19
19
|
}
|
|
20
20
|
/** A titled set of primitive types, listed together in an index catalog. */
|
|
@@ -22,6 +22,8 @@ export interface PrimitiveGroup {
|
|
|
22
22
|
title: string;
|
|
23
23
|
types: readonly string[];
|
|
24
24
|
}
|
|
25
|
+
/** The index heading for primitives in no group. A pack cannot declare a group with this title. */
|
|
26
|
+
export declare const UNCATEGORIZED_GROUP_TITLE = "Uncategorized";
|
|
25
27
|
/**
|
|
26
28
|
* The HTML style-adapter hooks a pack may declare. Typed loosely here so `pack/` does not import `render/`.
|
|
27
29
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"primitive_pack.d.ts","sourceRoot":"","sources":["../../src/pack/primitive_pack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AC,CAAC;IACpC;;;;OAIG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC;IACzD,mDAAmD;IACnD,QAAQ,CAAC,YAAY,EAAE,SAAS,qBAAqB,EAAE,CAAC;IACxD,sDAAsD;IACtD,QAAQ,CAAC,eAAe,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC9C,mDAAmD;IACnD,QAAQ,CAAC,YAAY,CAAC,EAAE,gBAAgB,CAAC;IACzC,qDAAqD;IACrD,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,gDAAgD;IAChD,QAAQ,CAAC,SAAS,CAAC,EAAE,oBAAoB,CAAC;IAC1C;;;;;;;OAOG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CAC5C;AAED;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;AAEpD;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,GAAI,MAAM,GAAG,OAAO,EAClD,OAAO,kBAAkB,KACxB,aAAa,CAAC,MAAM,CAoCtB,CAAC;AAEF,yGAAyG;AACzG,eAAO,MAAM,WAAW,GACtB,YAAY,SAAS,sBAAsB,EAAE,KAC5C,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAQxC,CAAC"}
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
// primitive in it implements. Additive: a runtime composes any number of packs,
|
|
9
9
|
// and nothing about a pack decides how a composition is framed.
|
|
10
10
|
import { IsomerError } from '../composition/error.js';
|
|
11
|
+
/** The index heading for primitives in no group. A pack cannot declare a group with this title. */
|
|
12
|
+
export const UNCATEGORIZED_GROUP_TITLE = 'Uncategorized';
|
|
11
13
|
/**
|
|
12
14
|
* Builds a {@link PrimitivePack}.
|
|
13
15
|
*
|
|
@@ -22,7 +24,7 @@ export const definePrimitivePack = (input) => {
|
|
|
22
24
|
assertUniquePrimitiveTypes(input.id, input.primitives);
|
|
23
25
|
assertUniqueEnhancementIds(input.id, input.enhancements ?? []);
|
|
24
26
|
const types = new Set(input.primitives.map((definition) => definition.type));
|
|
25
|
-
|
|
27
|
+
assertValidGroups(input.id, input.authoring?.groups ?? [], types);
|
|
26
28
|
for (const type of input.slackAssetTypes ?? []) {
|
|
27
29
|
if (!types.has(type)) {
|
|
28
30
|
throw new IsomerError('UNKNOWN_PRIMITIVE_TYPE', `primitive pack "${input.id}": slackAssetTypes names primitive type "${type}", which the pack does not register`);
|
|
@@ -64,10 +66,18 @@ const assertUniquePrimitiveTypes = (id, primitives) => {
|
|
|
64
66
|
seen.add(type);
|
|
65
67
|
}
|
|
66
68
|
};
|
|
67
|
-
/** Throws if a group names a type outside `types`, or
|
|
68
|
-
const
|
|
69
|
+
/** Throws if a group repeats or reserves a title, names a type outside `types`, or shares a type with another. */
|
|
70
|
+
const assertValidGroups = (id, groups, types) => {
|
|
71
|
+
const titles = new Set();
|
|
69
72
|
const grouped = new Set();
|
|
70
73
|
for (const { title, types: members } of groups) {
|
|
74
|
+
if (title === UNCATEGORIZED_GROUP_TITLE) {
|
|
75
|
+
throw new IsomerError('INVALID_PACK_GROUPS', `primitive pack "${id}": group title "${title}" is reserved for primitives in no group`);
|
|
76
|
+
}
|
|
77
|
+
if (titles.has(title)) {
|
|
78
|
+
throw new IsomerError('INVALID_PACK_GROUPS', `primitive pack "${id}": group title "${title}" is used twice`);
|
|
79
|
+
}
|
|
80
|
+
titles.add(title);
|
|
71
81
|
for (const type of members) {
|
|
72
82
|
if (!types.has(type)) {
|
|
73
83
|
throw new IsomerError('UNKNOWN_PRIMITIVE_TYPE', `primitive pack "${id}": group "${title}" names primitive type "${type}", which the pack does not register`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"primitive_pack.js","sourceRoot":"","sources":["../../src/pack/primitive_pack.ts"],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uBAAuB,EACvB,mBAAmB,EAAE,mBAAmB,UAAU,CAAC,EAAE,oBAAoB,CAC1E,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;IAC1B,CAAC;AACH,CAAC,CAAC","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\n// A primitive pack as a value: a vocabulary, and the optional surfaces every\n// primitive in it implements. Additive: a runtime composes any number of packs,\n// and nothing about a pack decides how a composition is framed.\n\nimport { IsomerError } from '../composition/error';\nimport type { PrimitiveIcon } from '../define/primitive_icon';\nimport type {\n AnyPrimitiveDefinition,\n OptionalSurface,\n StyleHandle,\n} from '../define/primitive_module';\n\nimport type { EnhancementDefinition } from './enhancements';\n\n/**\n * The authoring-schema material a pack contributes for its own primitives.\n *\n * A subset of `AuthoringJsonSchemaOptions`: `$id`, `title`, `description`, and\n * `composition` describe the whole authoring schema a runtime builds, which is\n * a host decision, not a pack one. `pack/` does not import `validate/` for\n * this, so the shape is declared here rather than reused by reference.\n */\nexport interface PackAuthoringOptions {\n /** `$def` id to `description`, for this pack's own primitives. */\n describe?: Readonly<Record<string, string>>;\n /** `$defId.property` paths to drop, from this pack's own primitives. */\n omitProperties?: readonly string[];\n /** Headings an index catalog sorts this pack's primitives under, in order. */\n groups?: readonly PrimitiveGroup[];\n}\n\n/** A titled set of primitive types, listed together in an index catalog. */\nexport interface PrimitiveGroup {\n title: string;\n types: readonly string[];\n}\n\n/**\n * The HTML style-adapter hooks a pack may declare. Typed loosely here so `pack/` does not import `render/`.\n */\nexport type PackStyleAdapter = {\n /** See {@link PrimitivePackInput.styleCollector}. */\n styleCollector?: string;\n /** The hooks of `HTMLStyleAdapter` from `./html`, erased: a fresh collector per render, the context renderers receive, and the stylesheet the collector produced. */\n createCollector: (...args: never[]) => object;\n createRenderContext: (...args: never[]) => unknown;\n renderStyles: (...args: never[]) => string;\n /**\n * Whether `handle` belongs to this adapter's stylesheet. Required for a runtime to combine several packs' CSS: without it their handles cannot be routed and the host must pick one adapter.\n */\n ownsHandle?: (handle: StyleHandle) => boolean;\n};\n\n/** What a pack author passes to {@link definePrimitivePack}. */\nexport interface PrimitivePackInput {\n /** Stable identifier, used in capability reports and error messages. */\n id: string;\n /**\n * The optional surfaces this pack's primitives implement.\n *\n * Only `slack`, and it stays optional per primitive: the dispatcher converts\n * the mandatory markdown to Block Kit, so declaring it reports an intent\n * rather than imposing a requirement. Omit it entirely for a pack that\n * renders Slack through that fallback.\n */\n surfaces?: readonly OptionalSurface[];\n /** This pack's vocabulary. Node types must be unique within it, or construction throws. */\n primitives: readonly AnyPrimitiveDefinition[];\n /**\n * Progressive enhancements this pack's primitives can apply, by id.\n *\n * Declared by the pack because an enhancement is a fact about its\n * vocabulary — a sortable table, a copyable code block — and a host\n * composing packs it did not write cannot be expected to know the ids.\n * The runtime flattens these across packs; duplicate ids are rejected.\n */\n enhancements?: readonly EnhancementDefinition[];\n /**\n * Types that render as a self-contained picture rather than as text.\n *\n * A channel that cannot draw them inline uploads an image instead: the Slack\n * dispatcher swaps such a node for an `image` block and an upload request, so\n * a chart arrives as a PNG rather than as a markdown approximation of one.\n *\n * Declared by the pack because it is a fact about the vocabulary, and a host\n * composing packs it did not write cannot be expected to know it.\n */\n slackAssetTypes?: readonly string[];\n /**\n * Default HTML style adapter for this pack. A runtime that omits\n * `styleAdapter` runs the packs' own adapters, combined when more than one\n * pack declares one and each answers `ownsHandle`. Pass `styleAdapter` on\n * the runtime to replace them all.\n */\n styleAdapter?: PackStyleAdapter;\n /**\n * Names the collector shape this pack's `collectStyles` hooks mutate, so a\n * runtime can reject a pack paired with an adapter of a different tag.\n * Defaults to `styleAdapter.styleCollector`; a pack with neither opts out of\n * the check.\n */\n styleCollector?: string;\n /**\n * This pack's own contribution to the runtime's authoring JSON Schema.\n *\n * Merged across every composed pack, so a host does not hand-merge each\n * pack's `describe`/`omitProperties` into one options object itself. The\n * runtime-level `authoring` option is merged in last and wins on conflict.\n */\n authoring?: PackAuthoringOptions;\n}\n\n/**\n * A pack as the runtime sees it.\n *\n * `TTheme` is the palette this pack's `react` renderers read as `env.theme`\n * when drawn through the `snapshot` surface — a *lower bound* on whatever theme\n * the runtime holding it supplies. It is carried by\n * {@link PrimitivePack.__theme} rather than by any real field, because\n * `primitives` is erased to `AnyPrimitiveDefinition[]` and a heterogeneous\n * inventory has no single node type to be generic over.\n *\n * The bound is declared, not derived: nothing checks it against what the\n * renderers actually read. State it at the definition as\n * `definePrimitivePack<T>(input)`.\n * Bare `PrimitivePack` requires nothing and fits any runtime; a slot that must\n * hold packs of every palette is typed {@link AnyPrimitivePack}.\n */\nexport interface PrimitivePack<TTheme = unknown> {\n /** Unique among the packs a runtime composes, and used in error messages. */\n readonly id: string;\n /** See {@link PrimitivePackInput.surfaces}. */\n readonly surfaces: readonly OptionalSurface[];\n /** See {@link PrimitivePackInput.primitives}. */\n readonly primitives: readonly AnyPrimitiveDefinition[];\n /** Node types this pack owns, for duplicate detection across packs. */\n readonly types: ReadonlySet<string>;\n /**\n * Each primitive's `icon` by type, for the primitives that declare one, so a host listing them need not walk `primitives`.\n *\n * A frozen null-prototype dictionary: an absent type reads `undefined`, even `constructor`. Absent on a pack built by an SDK that predates icons; {@link iconsByType} derives it from `primitives`.\n */\n readonly icons?: Readonly<Record<string, PrimitiveIcon>>;\n /** See {@link PrimitivePackInput.enhancements}. */\n readonly enhancements: readonly EnhancementDefinition[];\n /** See {@link PrimitivePackInput.slackAssetTypes}. */\n readonly slackAssetTypes: ReadonlySet<string>;\n /** See {@link PrimitivePackInput.styleAdapter}. */\n readonly styleAdapter?: PackStyleAdapter;\n /** See {@link PrimitivePackInput.styleCollector}. */\n readonly styleCollector?: string;\n /** See {@link PrimitivePackInput.authoring}. */\n readonly authoring?: PackAuthoringOptions;\n /**\n * Phantom: never present at runtime, never read.\n *\n * A property rather than a method so `strictFunctionTypes` checks it\n * contravariantly. A method signature is bivariant, which would let a pack\n * needing richer tokens sit in a slot supplying fewer and then read a field\n * nothing supplies — the exact failure this marker exists to prevent.\n */\n readonly __theme?: (theme: TTheme) => void;\n}\n\n/**\n * A pack of any palette, for storage positions: `never` is assignable to every\n * requirement, so a slot typed this way holds every pack.\n */\nexport type AnyPrimitivePack = PrimitivePack<never>;\n\n/**\n * Builds a {@link PrimitivePack}.\n *\n * `TTheme` is the palette a frame must supply for this pack's nodes to be drawn\n * on the `snapshot` surface: `definePrimitivePack<CoreTokens>(input)`. Omitted, it is\n * `unknown`, which requires nothing.\n */\nexport const definePrimitivePack = <TTheme = unknown>(\n input: PrimitivePackInput\n): PrimitivePack<TTheme> => {\n if (input.primitives.length === 0) {\n throw new IsomerError(\n 'EMPTY_PACK',\n `primitive pack \"${input.id}\": at least one primitive is required`\n );\n }\n assertUniquePrimitiveTypes(input.id, input.primitives);\n assertUniqueEnhancementIds(input.id, input.enhancements ?? []);\n const types = new Set(input.primitives.map((definition) => definition.type));\n assertGroupedOnce(input.id, input.authoring?.groups ?? [], types);\n for (const type of input.slackAssetTypes ?? []) {\n if (!types.has(type)) {\n throw new IsomerError(\n 'UNKNOWN_PRIMITIVE_TYPE',\n `primitive pack \"${input.id}\": slackAssetTypes names primitive type \"${type}\", which the pack does not register`\n );\n }\n }\n const styleCollector =\n input.styleCollector ?? input.styleAdapter?.styleCollector;\n\n return {\n id: input.id,\n surfaces: input.surfaces ?? [],\n primitives: input.primitives,\n types,\n icons: iconsByType(input.primitives),\n enhancements: input.enhancements ?? [],\n slackAssetTypes: new Set(input.slackAssetTypes ?? []),\n ...(input.styleAdapter !== undefined\n ? { styleAdapter: input.styleAdapter }\n : {}),\n ...(styleCollector !== undefined ? { styleCollector } : {}),\n ...(input.authoring !== undefined ? { authoring: input.authoring } : {}),\n };\n};\n\n/** Each definition's `icon` by type, null-prototype so a type such as `__proto__` is an ordinary key. */\nexport const iconsByType = (\n primitives: readonly AnyPrimitiveDefinition[]\n): Readonly<Record<string, PrimitiveIcon>> => {\n const icons = Object.create(null) as Record<string, PrimitiveIcon>;\n for (const { type, icon } of primitives) {\n if (icon !== undefined) {\n icons[type] = icon;\n }\n }\n return Object.freeze(icons);\n};\n\n/** Throws if `primitives` repeats a type. */\nconst assertUniquePrimitiveTypes = (\n id: string,\n primitives: readonly AnyPrimitiveDefinition[]\n): void => {\n const seen = new Set<string>();\n for (const { type } of primitives) {\n if (seen.has(type)) {\n throw new IsomerError(\n 'DUPLICATE_PRIMITIVE_TYPE',\n `primitive pack \"${id}\": primitive type \"${type}\" registered twice`\n );\n }\n seen.add(type);\n }\n};\n\n/** Throws if a group names a type outside `types`, or two groups share a type. */\nconst assertGroupedOnce = (\n id: string,\n groups: readonly PrimitiveGroup[],\n types: ReadonlySet<string>\n): void => {\n const grouped = new Set<string>();\n for (const { title, types: members } of groups) {\n for (const type of members) {\n if (!types.has(type)) {\n throw new IsomerError(\n 'UNKNOWN_PRIMITIVE_TYPE',\n `primitive pack \"${id}\": group \"${title}\" names primitive type \"${type}\", which the pack does not register`\n );\n }\n if (grouped.has(type)) {\n throw new IsomerError(\n 'DUPLICATE_PRIMITIVE_TYPE',\n `primitive pack \"${id}\": primitive type \"${type}\" is in two groups`\n );\n }\n grouped.add(type);\n }\n }\n};\n\n/** Throws if this pack registers the same enhancement id twice. */\nconst assertUniqueEnhancementIds = (\n id: string,\n enhancements: readonly EnhancementDefinition[]\n): void => {\n const seen = new Set<string>();\n for (const definition of enhancements) {\n if (seen.has(definition.id)) {\n throw new IsomerError(\n 'DUPLICATE_ENHANCEMENT',\n `primitive pack \"${id}\": enhancement \"${definition.id}\" registered twice`\n );\n }\n seen.add(definition.id);\n }\n};\n"]}
|
|
1
|
+
{"version":3,"file":"primitive_pack.js","sourceRoot":"","sources":["../../src/pack/primitive_pack.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,6EAA6E;AAC7E,gFAAgF;AAChF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AE,sBAAsB,IAAI,oBAAoB,CACpE,CAAC;YACJ,CAAC;YACD,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACpB,CAAC;IACH,CAAC;AACH,CAAC,CAAC;AAEF,mEAAmE;AACnE,MAAM,0BAA0B,GAAG,CACjC,EAAU,EACV,YAA8C,EACxC,EAAE;IACR,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,KAAK,MAAM,UAAU,IAAI,YAAY,EAAE,CAAC;QACtC,IAAI,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC,EAAE,CAAC;YAC5B,MAAM,IAAI,WAAW,CACnB,uBAAuB,EACvB,mBAAmB,EAAE,mBAAmB,UAAU,CAAC,EAAE,oBAAoB,CAC1E,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;IAC1B,CAAC;AACH,CAAC,CAAC","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\n// A primitive pack as a value: a vocabulary, and the optional surfaces every\n// primitive in it implements. Additive: a runtime composes any number of packs,\n// and nothing about a pack decides how a composition is framed.\n\nimport { IsomerError } from '../composition/error';\nimport type { PrimitiveIcon } from '../define/primitive_icon';\nimport type {\n AnyPrimitiveDefinition,\n OptionalSurface,\n StyleHandle,\n} from '../define/primitive_module';\n\nimport type { EnhancementDefinition } from './enhancements';\n\n/**\n * The authoring-schema material a pack contributes for its own primitives.\n *\n * A subset of `AuthoringJsonSchemaOptions`: `$id`, `title`, `description`, and\n * `composition` describe the whole authoring schema a runtime builds, which is\n * a host decision, not a pack one. `pack/` does not import `validate/` for\n * this, so the shape is declared here rather than reused by reference.\n */\nexport interface PackAuthoringOptions {\n /** `$def` id to `description`, for this pack's own primitives. */\n describe?: Readonly<Record<string, string>>;\n /** `$defId.property` paths to drop, from this pack's own primitives. */\n omitProperties?: readonly string[];\n /** Headings an index catalog sorts this pack's primitives under, in order. A type in none is listed under {@link UNCATEGORIZED_GROUP_TITLE}. */\n groups?: readonly PrimitiveGroup[];\n}\n\n/** A titled set of primitive types, listed together in an index catalog. */\nexport interface PrimitiveGroup {\n title: string;\n types: readonly string[];\n}\n\n/** The index heading for primitives in no group. A pack cannot declare a group with this title. */\nexport const UNCATEGORIZED_GROUP_TITLE = 'Uncategorized';\n\n/**\n * The HTML style-adapter hooks a pack may declare. Typed loosely here so `pack/` does not import `render/`.\n */\nexport type PackStyleAdapter = {\n /** See {@link PrimitivePackInput.styleCollector}. */\n styleCollector?: string;\n /** The hooks of `HTMLStyleAdapter` from `./html`, erased: a fresh collector per render, the context renderers receive, and the stylesheet the collector produced. */\n createCollector: (...args: never[]) => object;\n createRenderContext: (...args: never[]) => unknown;\n renderStyles: (...args: never[]) => string;\n /**\n * Whether `handle` belongs to this adapter's stylesheet. Required for a runtime to combine several packs' CSS: without it their handles cannot be routed and the host must pick one adapter.\n */\n ownsHandle?: (handle: StyleHandle) => boolean;\n};\n\n/** What a pack author passes to {@link definePrimitivePack}. */\nexport interface PrimitivePackInput {\n /** Stable identifier, used in capability reports and error messages. */\n id: string;\n /**\n * The optional surfaces this pack's primitives implement.\n *\n * Only `slack`, and it stays optional per primitive: the dispatcher converts\n * the mandatory markdown to Block Kit, so declaring it reports an intent\n * rather than imposing a requirement. Omit it entirely for a pack that\n * renders Slack through that fallback.\n */\n surfaces?: readonly OptionalSurface[];\n /** This pack's vocabulary. Node types must be unique within it, or construction throws. */\n primitives: readonly AnyPrimitiveDefinition[];\n /**\n * Progressive enhancements this pack's primitives can apply, by id.\n *\n * Declared by the pack because an enhancement is a fact about its\n * vocabulary — a sortable table, a copyable code block — and a host\n * composing packs it did not write cannot be expected to know the ids.\n * The runtime flattens these across packs; duplicate ids are rejected.\n */\n enhancements?: readonly EnhancementDefinition[];\n /**\n * Types that render as a self-contained picture rather than as text.\n *\n * A channel that cannot draw them inline uploads an image instead: the Slack\n * dispatcher swaps such a node for an `image` block and an upload request, so\n * a chart arrives as a PNG rather than as a markdown approximation of one.\n *\n * Declared by the pack because it is a fact about the vocabulary, and a host\n * composing packs it did not write cannot be expected to know it.\n */\n slackAssetTypes?: readonly string[];\n /**\n * Default HTML style adapter for this pack. A runtime that omits\n * `styleAdapter` runs the packs' own adapters, combined when more than one\n * pack declares one and each answers `ownsHandle`. Pass `styleAdapter` on\n * the runtime to replace them all.\n */\n styleAdapter?: PackStyleAdapter;\n /**\n * Names the collector shape this pack's `collectStyles` hooks mutate, so a\n * runtime can reject a pack paired with an adapter of a different tag.\n * Defaults to `styleAdapter.styleCollector`; a pack with neither opts out of\n * the check.\n */\n styleCollector?: string;\n /**\n * This pack's own contribution to the runtime's authoring JSON Schema.\n *\n * Merged across every composed pack, so a host does not hand-merge each\n * pack's `describe`/`omitProperties` into one options object itself. The\n * runtime-level `authoring` option is merged in last and wins on conflict.\n */\n authoring?: PackAuthoringOptions;\n}\n\n/**\n * A pack as the runtime sees it.\n *\n * `TTheme` is the palette this pack's `react` renderers read as `env.theme`\n * when drawn through the `snapshot` surface — a *lower bound* on whatever theme\n * the runtime holding it supplies. It is carried by\n * {@link PrimitivePack.__theme} rather than by any real field, because\n * `primitives` is erased to `AnyPrimitiveDefinition[]` and a heterogeneous\n * inventory has no single node type to be generic over.\n *\n * The bound is declared, not derived: nothing checks it against what the\n * renderers actually read. State it at the definition as\n * `definePrimitivePack<T>(input)`.\n * Bare `PrimitivePack` requires nothing and fits any runtime; a slot that must\n * hold packs of every palette is typed {@link AnyPrimitivePack}.\n */\nexport interface PrimitivePack<TTheme = unknown> {\n /** Unique among the packs a runtime composes, and used in error messages. */\n readonly id: string;\n /** See {@link PrimitivePackInput.surfaces}. */\n readonly surfaces: readonly OptionalSurface[];\n /** See {@link PrimitivePackInput.primitives}. */\n readonly primitives: readonly AnyPrimitiveDefinition[];\n /** Node types this pack owns, for duplicate detection across packs. */\n readonly types: ReadonlySet<string>;\n /**\n * Each primitive's `icon` by type, for the primitives that declare one, so a host listing them need not walk `primitives`.\n *\n * A frozen null-prototype dictionary: an absent type reads `undefined`, even `constructor`. Absent on a pack built by an SDK that predates icons; {@link iconsByType} derives it from `primitives`.\n */\n readonly icons?: Readonly<Record<string, PrimitiveIcon>>;\n /** See {@link PrimitivePackInput.enhancements}. */\n readonly enhancements: readonly EnhancementDefinition[];\n /** See {@link PrimitivePackInput.slackAssetTypes}. */\n readonly slackAssetTypes: ReadonlySet<string>;\n /** See {@link PrimitivePackInput.styleAdapter}. */\n readonly styleAdapter?: PackStyleAdapter;\n /** See {@link PrimitivePackInput.styleCollector}. */\n readonly styleCollector?: string;\n /** See {@link PrimitivePackInput.authoring}. */\n readonly authoring?: PackAuthoringOptions;\n /**\n * Phantom: never present at runtime, never read.\n *\n * A property rather than a method so `strictFunctionTypes` checks it\n * contravariantly. A method signature is bivariant, which would let a pack\n * needing richer tokens sit in a slot supplying fewer and then read a field\n * nothing supplies — the exact failure this marker exists to prevent.\n */\n readonly __theme?: (theme: TTheme) => void;\n}\n\n/**\n * A pack of any palette, for storage positions: `never` is assignable to every\n * requirement, so a slot typed this way holds every pack.\n */\nexport type AnyPrimitivePack = PrimitivePack<never>;\n\n/**\n * Builds a {@link PrimitivePack}.\n *\n * `TTheme` is the palette a frame must supply for this pack's nodes to be drawn\n * on the `snapshot` surface: `definePrimitivePack<CoreTokens>(input)`. Omitted, it is\n * `unknown`, which requires nothing.\n */\nexport const definePrimitivePack = <TTheme = unknown>(\n input: PrimitivePackInput\n): PrimitivePack<TTheme> => {\n if (input.primitives.length === 0) {\n throw new IsomerError(\n 'EMPTY_PACK',\n `primitive pack \"${input.id}\": at least one primitive is required`\n );\n }\n assertUniquePrimitiveTypes(input.id, input.primitives);\n assertUniqueEnhancementIds(input.id, input.enhancements ?? []);\n const types = new Set(input.primitives.map((definition) => definition.type));\n assertValidGroups(input.id, input.authoring?.groups ?? [], types);\n for (const type of input.slackAssetTypes ?? []) {\n if (!types.has(type)) {\n throw new IsomerError(\n 'UNKNOWN_PRIMITIVE_TYPE',\n `primitive pack \"${input.id}\": slackAssetTypes names primitive type \"${type}\", which the pack does not register`\n );\n }\n }\n const styleCollector =\n input.styleCollector ?? input.styleAdapter?.styleCollector;\n\n return {\n id: input.id,\n surfaces: input.surfaces ?? [],\n primitives: input.primitives,\n types,\n icons: iconsByType(input.primitives),\n enhancements: input.enhancements ?? [],\n slackAssetTypes: new Set(input.slackAssetTypes ?? []),\n ...(input.styleAdapter !== undefined\n ? { styleAdapter: input.styleAdapter }\n : {}),\n ...(styleCollector !== undefined ? { styleCollector } : {}),\n ...(input.authoring !== undefined ? { authoring: input.authoring } : {}),\n };\n};\n\n/** Each definition's `icon` by type, null-prototype so a type such as `__proto__` is an ordinary key. */\nexport const iconsByType = (\n primitives: readonly AnyPrimitiveDefinition[]\n): Readonly<Record<string, PrimitiveIcon>> => {\n const icons = Object.create(null) as Record<string, PrimitiveIcon>;\n for (const { type, icon } of primitives) {\n if (icon !== undefined) {\n icons[type] = icon;\n }\n }\n return Object.freeze(icons);\n};\n\n/** Throws if `primitives` repeats a type. */\nconst assertUniquePrimitiveTypes = (\n id: string,\n primitives: readonly AnyPrimitiveDefinition[]\n): void => {\n const seen = new Set<string>();\n for (const { type } of primitives) {\n if (seen.has(type)) {\n throw new IsomerError(\n 'DUPLICATE_PRIMITIVE_TYPE',\n `primitive pack \"${id}\": primitive type \"${type}\" registered twice`\n );\n }\n seen.add(type);\n }\n};\n\n/** Throws if a group repeats or reserves a title, names a type outside `types`, or shares a type with another. */\nconst assertValidGroups = (\n id: string,\n groups: readonly PrimitiveGroup[],\n types: ReadonlySet<string>\n): void => {\n const titles = new Set<string>();\n const grouped = new Set<string>();\n for (const { title, types: members } of groups) {\n if (title === UNCATEGORIZED_GROUP_TITLE) {\n throw new IsomerError(\n 'INVALID_PACK_GROUPS',\n `primitive pack \"${id}\": group title \"${title}\" is reserved for primitives in no group`\n );\n }\n if (titles.has(title)) {\n throw new IsomerError(\n 'INVALID_PACK_GROUPS',\n `primitive pack \"${id}\": group title \"${title}\" is used twice`\n );\n }\n titles.add(title);\n for (const type of members) {\n if (!types.has(type)) {\n throw new IsomerError(\n 'UNKNOWN_PRIMITIVE_TYPE',\n `primitive pack \"${id}\": group \"${title}\" names primitive type \"${type}\", which the pack does not register`\n );\n }\n if (grouped.has(type)) {\n throw new IsomerError(\n 'DUPLICATE_PRIMITIVE_TYPE',\n `primitive pack \"${id}\": primitive type \"${type}\" is in two groups`\n );\n }\n grouped.add(type);\n }\n }\n};\n\n/** Throws if this pack registers the same enhancement id twice. */\nconst assertUniqueEnhancementIds = (\n id: string,\n enhancements: readonly EnhancementDefinition[]\n): void => {\n const seen = new Set<string>();\n for (const definition of enhancements) {\n if (seen.has(definition.id)) {\n throw new IsomerError(\n 'DUPLICATE_ENHANCEMENT',\n `primitive pack \"${id}\": enhancement \"${definition.id}\" registered twice`\n );\n }\n seen.add(definition.id);\n }\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format_number.d.ts","sourceRoot":"","sources":["../../src/render/format_number.ts"],"names":[],"mappings":"AAyBA;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,GAC9B,OAAO,MAAM,EACb,aAAS,EACT,kBAAa,KACZ,
|
|
1
|
+
{"version":3,"file":"format_number.d.ts","sourceRoot":"","sources":["../../src/render/format_number.ts"],"names":[],"mappings":"AAyBA;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,GAC9B,OAAO,MAAM,EACb,aAAS,EACT,kBAAa,KACZ,MAiBF,CAAC"}
|
|
@@ -28,8 +28,9 @@ const trimDecimal = (value, precision) => Number.isInteger(value)
|
|
|
28
28
|
export const formatCompactNumber = (value, unit = '', precision = 1) => {
|
|
29
29
|
const abs = Math.abs(value);
|
|
30
30
|
let index = TIERS.findIndex(({ size }) => abs >= size);
|
|
31
|
-
if (index === -1)
|
|
31
|
+
if (index === -1) {
|
|
32
32
|
index = TIERS.length - 1;
|
|
33
|
+
}
|
|
33
34
|
// A value that rounds up to the tier's next power, `999.96k`, reads as `1m`.
|
|
34
35
|
if (index > 0 &&
|
|
35
36
|
Math.abs(Number((value / TIERS[index].size).toFixed(precision))) >= 1_000) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format_number.js","sourceRoot":"","sources":["../../src/render/format_number.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,+EAA+E;AAC/E,6EAA6E;AAC7E,2BAA2B;AAE3B,MAAM,KAAK,GAAG;IACZ,EAAE,IAAI,EAAE,iBAAiB,EAAE,MAAM,EAAE,GAAG,EAAE;IACxC,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,GAAG,EAAE;IACpC,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE;IAChC,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE;IAC5B,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE;CACf,CAAC;AAEX,2DAA2D;AAC3D,MAAM,WAAW,GAAG,CAAC,KAAa,EAAE,SAAiB,EAAU,EAAE,CAC/D,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC;IACrB,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;IACf,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;AAE/C;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,KAAa,EACb,IAAI,GAAG,EAAE,EACT,SAAS,GAAG,CAAC,EACL,EAAE;IACV,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC5B,IAAI,KAAK,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC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;IACD,6EAA6E;IAC7E,IACE,KAAK,GAAG,CAAC;QACT,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAE,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,KAAK,EAC1E,CAAC;QACD,KAAK,IAAI,CAAC,CAAC;IACb,CAAC;IACD,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC,KAAK,CAAE,CAAC;IACvC,MAAM,MAAM,GAAG,GAAG,WAAW,CAAC,KAAK,GAAG,IAAI,EAAE,SAAS,CAAC,GAAG,MAAM,EAAE,CAAC;IAElE,OAAO,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,GAAG,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,IAAI,EAAE,CAAC;AAC7E,CAAC,CAAC","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\n// Compact numeric formatting, shared by anything that has to fit a number into\n// a small space — chart axis labels, a `compact` structured display value, a\n// text-surface trend line.\n\nconst TIERS = [\n { size: 1_000_000_000_000, suffix: 't' },\n { size: 1_000_000_000, suffix: 'b' },\n { size: 1_000_000, suffix: 'm' },\n { size: 1_000, suffix: 'k' },\n { size: 1, suffix: '' },\n] as const;\n\n// Rounded to `precision` decimals, trailing zeros dropped.\nconst trimDecimal = (value: number, precision: number): string =>\n Number.isInteger(value)\n ? String(value)\n : String(Number(value.toFixed(precision)));\n\n/**\n * `1_284` to `1.3k`, `18_200_000` to `18.2m`, through `b` and `t`, with an\n * optional unit appended. `precision` is the decimals kept, `1` by default.\n *\n * `%` joins without a space because \"99.2 %\" reads wrong; every other unit gets\n * one.\n */\nexport const formatCompactNumber = (\n value: number,\n unit = '',\n precision = 1\n): string => {\n const abs = Math.abs(value);\n let index = TIERS.findIndex(({ size }) => abs >= size);\n if (index === -1) {\n index = TIERS.length - 1;\n }\n // A value that rounds up to the tier's next power, `999.96k`, reads as `1m`.\n if (\n index > 0 &&\n Math.abs(Number((value / TIERS[index]!.size).toFixed(precision))) >= 1_000\n ) {\n index -= 1;\n }\n const { size, suffix } = TIERS[index]!;\n const scaled = `${trimDecimal(value / size, precision)}${suffix}`;\n\n return unit === '' ? scaled : `${scaled}${unit === '%' ? '' : ' '}${unit}`;\n};\n"]}
|
|
@@ -108,8 +108,9 @@ export const renderHTMLWithDispatcher = (input, { dispatcher, validate = createC
|
|
|
108
108
|
const embedCss = (css) => css.replace(/<\/(?=style)/gi, '<\\/');
|
|
109
109
|
// Tagged templates observe raw spelling and reuse the same frozen object per site.
|
|
110
110
|
const embedJs = (js) => {
|
|
111
|
-
if (!/<\/script|<!--/i.test(js))
|
|
111
|
+
if (!/<\/script|<!--/i.test(js)) {
|
|
112
112
|
return js;
|
|
113
|
+
}
|
|
113
114
|
const comments = [];
|
|
114
115
|
const tree = parse(js, { ecmaVersion: 'latest', onComment: comments });
|
|
115
116
|
const sites = [];
|
|
@@ -117,11 +118,13 @@ const embedJs = (js) => {
|
|
|
117
118
|
const pending = [tree];
|
|
118
119
|
while (pending.length) {
|
|
119
120
|
const node = pending.pop();
|
|
120
|
-
if (node.type === 'Identifier' && node.name)
|
|
121
|
+
if (node.type === 'Identifier' && node.name) {
|
|
121
122
|
identifiers.add(node.name);
|
|
123
|
+
}
|
|
122
124
|
if (node.type === 'TaggedTemplateExpression' &&
|
|
123
|
-
node.quasi.quasis.some(({ value: { raw } }) => /<\/script|<!--/i.test(raw)))
|
|
125
|
+
node.quasi.quasis.some(({ value: { raw } }) => /<\/script|<!--/i.test(raw))) {
|
|
124
126
|
sites.push(node);
|
|
127
|
+
}
|
|
125
128
|
for (const value of Object.values(node)) {
|
|
126
129
|
for (const child of Array.isArray(value) ? value : [value]) {
|
|
127
130
|
if (child &&
|
|
@@ -135,8 +138,9 @@ const embedJs = (js) => {
|
|
|
135
138
|
}
|
|
136
139
|
sites.sort((a, b) => a.start - b.start);
|
|
137
140
|
let prefix = '__isomerTemplate';
|
|
138
|
-
while ([...identifiers].some((name) => name.startsWith(prefix)))
|
|
141
|
+
while ([...identifiers].some((name) => name.startsWith(prefix))) {
|
|
139
142
|
prefix += '_';
|
|
143
|
+
}
|
|
140
144
|
const literal = (value) => value === null ? 'void 0' : JSON.stringify(value).replace(/</g, '\\u003c');
|
|
141
145
|
const rewrite = (start, end) => {
|
|
142
146
|
let cursor = start;
|
|
@@ -152,8 +156,9 @@ const embedJs = (js) => {
|
|
|
152
156
|
.map((comment) => ({ ...comment, index: -1, comment: comment.value })),
|
|
153
157
|
].sort((a, b) => a.start - b.start);
|
|
154
158
|
for (const edit of edits) {
|
|
155
|
-
if (edit.start < cursor || edit.end > end)
|
|
159
|
+
if (edit.start < cursor || edit.end > end) {
|
|
156
160
|
continue;
|
|
161
|
+
}
|
|
157
162
|
result += js.slice(cursor, edit.start);
|
|
158
163
|
if (edit.comment !== undefined) {
|
|
159
164
|
result += `//${edit.comment}`;
|
|
@@ -184,8 +189,9 @@ const embedJs = (js) => {
|
|
|
184
189
|
};
|
|
185
190
|
const escapedBy = (source, at) => {
|
|
186
191
|
let slashes = 0;
|
|
187
|
-
while (source[at - slashes - 1] === '\\')
|
|
192
|
+
while (source[at - slashes - 1] === '\\') {
|
|
188
193
|
slashes += 1;
|
|
194
|
+
}
|
|
189
195
|
return slashes % 2 === 1;
|
|
190
196
|
};
|
|
191
197
|
const RenderedHtmlView = ({ composition, theme, fluid, framed, styleText, scriptText, defaultAriaLabel, body, }) => wrapCompositionContent(createElement(Fragment, null, styleText
|