@elastic/isomer-sdk 0.1.0 → 0.2.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/README.md +13 -2
- package/dist/author/authored_fields.d.ts +61 -11
- package/dist/author/authored_fields.d.ts.map +1 -1
- package/dist/author/authored_fields.js +73 -29
- package/dist/author/authored_fields.js.map +1 -1
- package/dist/author/authoring_input.d.ts +7 -0
- package/dist/author/authoring_input.d.ts.map +1 -0
- package/dist/author/authoring_input.js +60 -0
- package/dist/author/authoring_input.js.map +1 -0
- package/dist/author/authoring_model.d.ts +27 -0
- package/dist/author/authoring_model.d.ts.map +1 -0
- package/dist/author/authoring_model.js +98 -0
- package/dist/author/authoring_model.js.map +1 -0
- package/dist/author/declarations.d.ts +13 -0
- package/dist/author/declarations.d.ts.map +1 -0
- package/dist/author/declarations.js +277 -0
- package/dist/author/declarations.js.map +1 -0
- package/dist/author/index.d.ts +3 -1
- package/dist/author/index.d.ts.map +1 -1
- package/dist/author/index.js +3 -1
- package/dist/author/index.js.map +1 -1
- package/dist/author/jsx_shim.d.ts +6 -5
- package/dist/author/jsx_shim.d.ts.map +1 -1
- package/dist/author/jsx_shim.js +28 -111
- package/dist/author/jsx_shim.js.map +1 -1
- package/dist/author/schema_to_typescript.d.ts +37 -0
- package/dist/author/schema_to_typescript.d.ts.map +1 -0
- package/dist/author/schema_to_typescript.js +286 -0
- package/dist/author/schema_to_typescript.js.map +1 -0
- package/dist/cjs/author/authored_fields.js +77 -33
- package/dist/cjs/author/authored_fields.js.map +1 -1
- package/dist/cjs/author/authoring_input.js +64 -0
- package/dist/cjs/author/authoring_input.js.map +1 -0
- package/dist/cjs/author/authoring_model.js +104 -0
- package/dist/cjs/author/authoring_model.js.map +1 -0
- package/dist/cjs/author/declarations.js +281 -0
- package/dist/cjs/author/declarations.js.map +1 -0
- package/dist/cjs/author/index.js +6 -1
- package/dist/cjs/author/index.js.map +1 -1
- package/dist/cjs/author/jsx_shim.js +31 -114
- package/dist/cjs/author/jsx_shim.js.map +1 -1
- package/dist/cjs/author/schema_to_typescript.js +295 -0
- package/dist/cjs/author/schema_to_typescript.js.map +1 -0
- package/dist/cjs/composition/body_node_base.js +11 -4
- package/dist/cjs/composition/body_node_base.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/index.js +2 -1
- package/dist/cjs/composition/index.js.map +1 -1
- package/dist/cjs/define/frame.js +2 -3
- package/dist/cjs/define/frame.js.map +1 -1
- package/dist/cjs/define/index.js +7 -1
- package/dist/cjs/define/index.js.map +1 -1
- package/dist/cjs/define/primitive_example.js +26 -0
- package/dist/cjs/define/primitive_example.js.map +1 -0
- package/dist/cjs/define/primitive_icon.js +17 -0
- package/dist/cjs/define/primitive_icon.js.map +1 -0
- package/dist/cjs/define/primitive_module.js +14 -3
- package/dist/cjs/define/primitive_module.js.map +1 -1
- package/dist/cjs/define/slack_assets.js.map +1 -1
- package/dist/cjs/entries/index.js +7 -2
- package/dist/cjs/entries/index.js.map +1 -1
- package/dist/cjs/entries/slack.js +1 -2
- package/dist/cjs/entries/slack.js.map +1 -1
- package/dist/cjs/pack/capabilities.js +17 -11
- package/dist/cjs/pack/capabilities.js.map +1 -1
- package/dist/cjs/pack/compose.js +4 -1
- package/dist/cjs/pack/compose.js.map +1 -1
- package/dist/cjs/pack/index.js.map +1 -1
- package/dist/cjs/pack/primitive_pack.js +14 -2
- package/dist/cjs/pack/primitive_pack.js.map +1 -1
- package/dist/cjs/render/anchors.js +1 -1
- package/dist/cjs/render/anchors.js.map +1 -1
- package/dist/cjs/render/html/envelope.js.map +1 -1
- package/dist/cjs/render/layout_check.js.map +1 -1
- package/dist/cjs/render/markdown/builder.js +14 -8
- package/dist/cjs/render/markdown/builder.js.map +1 -1
- package/dist/cjs/render/markdown/format.js +30 -12
- package/dist/cjs/render/markdown/format.js.map +1 -1
- package/dist/cjs/render/primitive_dispatch.js +11 -25
- package/dist/cjs/render/primitive_dispatch.js.map +1 -1
- package/dist/cjs/render/slack/format.js +1 -601
- package/dist/cjs/render/slack/format.js.map +1 -1
- package/dist/cjs/render/slack/index.js +1 -2
- package/dist/cjs/render/slack/index.js.map +1 -1
- package/dist/cjs/render/slack/markdown_content.js +166 -115
- package/dist/cjs/render/slack/markdown_content.js.map +1 -1
- package/dist/cjs/testing/conformance.js +40 -24
- package/dist/cjs/testing/conformance.js.map +1 -1
- package/dist/cjs/testing/icon.js +248 -0
- package/dist/cjs/testing/icon.js.map +1 -0
- package/dist/cjs/testing/index.js +3 -1
- package/dist/cjs/testing/index.js.map +1 -1
- package/dist/cjs/testing/registration.js +5 -3
- package/dist/cjs/testing/registration.js.map +1 -1
- package/dist/cjs/validate/authoring_schema.js +17 -1
- package/dist/cjs/validate/authoring_schema.js.map +1 -1
- package/dist/cjs/validate/index.js +2 -1
- package/dist/cjs/validate/index.js.map +1 -1
- package/dist/cjs/validate/validation.js +2 -45
- package/dist/cjs/validate/validation.js.map +1 -1
- package/dist/composition/body_node_base.d.ts +7 -6
- package/dist/composition/body_node_base.d.ts.map +1 -1
- package/dist/composition/body_node_base.js +10 -3
- package/dist/composition/body_node_base.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/index.d.ts +1 -1
- package/dist/composition/index.d.ts.map +1 -1
- package/dist/composition/index.js +1 -1
- package/dist/composition/index.js.map +1 -1
- package/dist/define/frame.d.ts +9 -20
- package/dist/define/frame.d.ts.map +1 -1
- package/dist/define/frame.js +2 -3
- package/dist/define/frame.js.map +1 -1
- package/dist/define/index.d.ts +3 -1
- package/dist/define/index.d.ts.map +1 -1
- package/dist/define/index.js +3 -1
- package/dist/define/index.js.map +1 -1
- package/dist/define/primitive_example.d.ts +30 -0
- package/dist/define/primitive_example.d.ts.map +1 -0
- package/dist/define/primitive_example.js +21 -0
- package/dist/define/primitive_example.js.map +1 -0
- package/dist/define/primitive_icon.d.ts +11 -0
- package/dist/define/primitive_icon.d.ts.map +1 -0
- package/dist/define/primitive_icon.js +14 -0
- package/dist/define/primitive_icon.js.map +1 -0
- package/dist/define/primitive_module.d.ts +38 -24
- package/dist/define/primitive_module.d.ts.map +1 -1
- package/dist/define/primitive_module.js +14 -3
- package/dist/define/primitive_module.js.map +1 -1
- package/dist/define/slack_assets.d.ts +1 -1
- package/dist/define/slack_assets.d.ts.map +1 -1
- package/dist/define/slack_assets.js.map +1 -1
- package/dist/entries/index.d.ts +3 -3
- package/dist/entries/index.d.ts.map +1 -1
- package/dist/entries/index.js +2 -2
- package/dist/entries/index.js.map +1 -1
- package/dist/entries/slack.d.ts +1 -1
- package/dist/entries/slack.d.ts.map +1 -1
- package/dist/entries/slack.js +1 -1
- package/dist/entries/slack.js.map +1 -1
- package/dist/pack/capabilities.d.ts +24 -10
- package/dist/pack/capabilities.d.ts.map +1 -1
- package/dist/pack/capabilities.js +17 -11
- package/dist/pack/capabilities.js.map +1 -1
- package/dist/pack/compose.d.ts +4 -1
- package/dist/pack/compose.d.ts.map +1 -1
- package/dist/pack/compose.js +4 -1
- package/dist/pack/compose.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 +11 -2
- package/dist/pack/primitive_pack.d.ts.map +1 -1
- package/dist/pack/primitive_pack.js +12 -1
- package/dist/pack/primitive_pack.js.map +1 -1
- package/dist/render/anchors.d.ts +2 -2
- package/dist/render/anchors.d.ts.map +1 -1
- package/dist/render/anchors.js +1 -1
- package/dist/render/anchors.js.map +1 -1
- package/dist/render/html/envelope.d.ts +3 -3
- package/dist/render/html/envelope.js.map +1 -1
- package/dist/render/layout_check.d.ts +1 -1
- package/dist/render/layout_check.d.ts.map +1 -1
- package/dist/render/layout_check.js.map +1 -1
- package/dist/render/markdown/builder.d.ts +2 -4
- package/dist/render/markdown/builder.d.ts.map +1 -1
- package/dist/render/markdown/builder.js +14 -7
- package/dist/render/markdown/builder.js.map +1 -1
- package/dist/render/markdown/format.d.ts +7 -0
- package/dist/render/markdown/format.d.ts.map +1 -1
- package/dist/render/markdown/format.js +27 -11
- package/dist/render/markdown/format.js.map +1 -1
- package/dist/render/primitive_dispatch.d.ts +6 -6
- package/dist/render/primitive_dispatch.d.ts.map +1 -1
- package/dist/render/primitive_dispatch.js +12 -26
- package/dist/render/primitive_dispatch.js.map +1 -1
- package/dist/render/slack/format.d.ts +0 -25
- package/dist/render/slack/format.d.ts.map +1 -1
- package/dist/render/slack/format.js +1 -599
- package/dist/render/slack/format.js.map +1 -1
- package/dist/render/slack/index.d.ts +1 -1
- package/dist/render/slack/index.d.ts.map +1 -1
- package/dist/render/slack/index.js +1 -1
- package/dist/render/slack/index.js.map +1 -1
- package/dist/render/slack/markdown_content.d.ts +10 -4
- package/dist/render/slack/markdown_content.d.ts.map +1 -1
- package/dist/render/slack/markdown_content.js +163 -113
- package/dist/render/slack/markdown_content.js.map +1 -1
- package/dist/testing/conformance.d.ts +19 -14
- package/dist/testing/conformance.d.ts.map +1 -1
- package/dist/testing/conformance.js +40 -24
- package/dist/testing/conformance.js.map +1 -1
- package/dist/testing/icon.d.ts +11 -0
- package/dist/testing/icon.d.ts.map +1 -0
- package/dist/testing/icon.js +244 -0
- package/dist/testing/icon.js.map +1 -0
- package/dist/testing/index.d.ts +2 -1
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +1 -0
- package/dist/testing/index.js.map +1 -1
- package/dist/testing/registration.d.ts +1 -1
- package/dist/testing/registration.d.ts.map +1 -1
- package/dist/testing/registration.js +6 -4
- package/dist/testing/registration.js.map +1 -1
- package/dist/validate/authoring_schema.d.ts +6 -0
- package/dist/validate/authoring_schema.d.ts.map +1 -1
- package/dist/validate/authoring_schema.js +15 -0
- package/dist/validate/authoring_schema.js.map +1 -1
- package/dist/validate/index.d.ts +1 -1
- package/dist/validate/index.d.ts.map +1 -1
- package/dist/validate/index.js +1 -1
- package/dist/validate/index.js.map +1 -1
- package/dist/validate/validation.d.ts +1 -11
- package/dist/validate/validation.d.ts.map +1 -1
- package/dist/validate/validation.js +3 -46
- package/dist/validate/validation.js.map +1 -1
- package/package.json +3 -2
|
@@ -70,12 +70,7 @@ const createCompositionValidator = (definitions, options = {}) => {
|
|
|
70
70
|
if (result.success) {
|
|
71
71
|
const { body } = plain;
|
|
72
72
|
const idErrors = collectDuplicateNodeIdErrors(body, walk);
|
|
73
|
-
const warnings =
|
|
74
|
-
...collectEmptySurfaceWarnings(body, walk),
|
|
75
|
-
...(options.sizesFromNodeHeights
|
|
76
|
-
? collectMissingSvgHeightWarnings(body, definitions, walk)
|
|
77
|
-
: []),
|
|
78
|
-
];
|
|
73
|
+
const warnings = collectEmptySurfaceWarnings(body, walk);
|
|
79
74
|
return {
|
|
80
75
|
valid: idErrors.length === 0,
|
|
81
76
|
errors: idErrors,
|
|
@@ -127,48 +122,10 @@ const createCompositionParser = (definitions, { inputBudget } = {}) => {
|
|
|
127
122
|
};
|
|
128
123
|
exports.createCompositionParser = createCompositionParser;
|
|
129
124
|
/** Warns once per surface that the whole body renders nothing on. */
|
|
130
|
-
const collectEmptySurfaceWarnings = (body, walk) => body_node_base_1.
|
|
125
|
+
const collectEmptySurfaceWarnings = (body, walk) => body_node_base_1.SURFACE_NAMES.filter((surface) => !body.some((node) => (0, body_node_base_1.rendersOnSurface)(node, surface, walk))).map((surface) => ({
|
|
131
126
|
surface,
|
|
132
127
|
message: `composition renders no nodes on surface "${surface}"`,
|
|
133
128
|
}));
|
|
134
|
-
/**
|
|
135
|
-
* Warns for each node that renders to `svg` but declares no `svgHeight`.
|
|
136
|
-
*
|
|
137
|
-
* `metrics.svgHeight` is optional, so `dispatcher.estimateSvgHeight` returns
|
|
138
|
-
* `0` for such a node and a frame that sums node heights sizes short.
|
|
139
|
-
*
|
|
140
|
-
* Whether a runtime consults the metric at all is the caller's to decide; see
|
|
141
|
-
* {@link CompositionValidatorOptions.sizesFromNodeHeights}. A fixed-size frame
|
|
142
|
-
* never does, and warning about a value nothing reads is how a warning channel
|
|
143
|
-
* gets ignored.
|
|
144
|
-
*/
|
|
145
|
-
const collectMissingSvgHeightWarnings = (body, definitions, walk) => {
|
|
146
|
-
const unmeasured = new Set(definitions
|
|
147
|
-
.filter((definition) => !definition.metrics?.svgHeight)
|
|
148
|
-
.map((definition) => definition.type));
|
|
149
|
-
if (unmeasured.size === 0) {
|
|
150
|
-
return [];
|
|
151
|
-
}
|
|
152
|
-
const warnings = [];
|
|
153
|
-
const visit = (node, path) => {
|
|
154
|
-
if (!node || typeof node !== 'object' || !(0, body_node_base_1.isVisibleOnSurface)(node, 'svg')) {
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
const { type } = node;
|
|
158
|
-
if (typeof type === 'string' && unmeasured.has(type)) {
|
|
159
|
-
warnings.push({
|
|
160
|
-
surface: 'svg',
|
|
161
|
-
path,
|
|
162
|
-
message: `${path} type ${(0, one_line_1.quoteText)(type)} declares no svgHeight metric and will be measured as 0, sizing the frame short`,
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
walk(node).forEach(({ node: child, path: field }) => {
|
|
166
|
-
visit(child, (0, body_node_base_1.childNodePath)(path, field));
|
|
167
|
-
});
|
|
168
|
-
};
|
|
169
|
-
body.forEach((node, index) => visit(node, `body[${index}]`));
|
|
170
|
-
return warnings;
|
|
171
|
-
};
|
|
172
129
|
/**
|
|
173
130
|
* Errors for each node whose `id` repeats one already seen, naming the first
|
|
174
131
|
* use.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../../src/validate/validation.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,kEAOuC;AAGvC,sDAAoD;AACpD,sEAGyC;AAuEhC,2GAzEP,6CAA0B,OAyEO;AApEnC,6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C;QAC9D,IAAI,OAAO,EAAE,KAAK,QAAQ,EAAE,CAAC;YAC3B,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YAC3B,IAAI,KAAK,EAAE,CAAC;gBACV,MAAM,CAAC,IAAI,CAAC;oBACV,IAAI,EAAE,GAAG,IAAI,KAAK;oBAClB,OAAO,EAAE,iBAAiB,IAAA,oBAAS,EAAC,EAAE,CAAC,kBAAkB,KAAK,EAAE;oBAChE,GAAG,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;iBACxD,CAAC,CAAC;YACL,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;YACrB,CAAC;QACH,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE;YAClD,KAAK,CAAC,KAAK,EAAE,IAAA,8BAAa,EAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;QAC3C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;IACF,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,QAAQ,KAAK,GAAG,CAAC,CAAC,CAAC;IAC7D,OAAO,MAAM,CAAC;AAChB,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 {\n BODY_NODE_SURFACES,\n childNodePath,\n createChildNodeWalker,\n isVisibleOnSurface,\n rendersOnSurface,\n type SurfaceName,\n} from '../composition/body_node_base';\nimport type { Composition } from '../composition/composition';\nimport type { PrimitiveNode } from '../composition/node';\nimport { quoteText } from '../composition/one_line';\nimport {\n CompositionValidationError,\n type ValidationError,\n} from '../composition/validation_error';\nimport type { AnyPrimitiveDefinition } from '../define/primitive_module';\n\nimport { getCompositionSchemaForDefinitions } from './composition_schema';\nimport {\n checkInputBudget,\n type InputBudget,\n isInputRefusal,\n} from './input_budget';\nimport { createNodeIssueFormatter, type IssueRoot } from './node_issues';\n\n/**\n * A non-fatal validation finding, scoped to the surface it concerns.\n *\n * Warnings carry `surface` because every one of them is a statement about one\n * render target — a composition that draws nothing on `slack` is not news to a\n * caller rendering HTML. Without the scope a host receives every surface's\n * findings on every call and learns to ignore the channel.\n * {@link warningsForSurface} is the filter.\n */\nexport interface ValidationWarning {\n /** The render target this finding concerns, never the composition as a whole. */\n surface: SurfaceName;\n /**\n * Path of the offending node within the composition, absent for\n * whole-composition findings.\n */\n path?: string;\n /** Safe to show a user, and phrased for whoever can act on it. */\n message: string;\n}\n\n/**\n * The outcome of `validate`: errors are fatal, warnings are advisory.\n *\n * `valid` tracks `errors` only — a composition can be valid and still carry\n * warnings, which is the normal case for a surface gap.\n */\nexport interface ValidationResult {\n /** True when `errors` is empty, regardless of `warnings`. */\n valid: boolean;\n /** Fatal findings. Empty when `valid`. */\n errors: ValidationError[];\n /** Advisory findings, empty when there are none. */\n warnings: ValidationWarning[];\n}\n\nconst checkedComposition = Symbol.for('elastic.isomer.checked_composition');\n\n/** The copy {@link createCompositionValidator} checked, which a validating render draws in place of the caller's value. The brand is type-only. */\nexport type CheckedComposition<TNode extends PrimitiveNode = PrimitiveNode> =\n Composition<TNode> & { readonly [checkedComposition]: true };\n\n/** A {@link ValidationResult} with the composition it describes. */\nexport interface CheckedValidationResult<\n TNode extends PrimitiveNode = PrimitiveNode,\n> extends ValidationResult {\n /** Undefined only when {@link checkInputBudget} refused the input. */\n composition: CheckedComposition<TNode> | undefined;\n}\n\n/** Narrows a result's warnings to the surface a caller is about to render. */\nexport const warningsForSurface = (\n result: ValidationResult,\n surface: SurfaceName\n): ValidationWarning[] =>\n result.warnings.filter((warning) => warning.surface === surface);\n\n/** Whether a render reports validation findings or raises on them. */\nexport type ValidationErrorMode = 'collect' | 'throw';\n\nexport { CompositionValidationError };\n\n/** Raises {@link CompositionValidationError} when `mode` is `throw` and `result` is invalid, or in any mode when {@link checkInputBudget} refused the input, which nothing can render. */\nexport const enforceValidationMode = (\n result: ValidationResult,\n mode?: ValidationErrorMode\n): void => {\n if (\n !result.valid &&\n (mode === 'throw' || result.errors.some(isInputRefusal))\n ) {\n throw new CompositionValidationError(result.errors);\n }\n};\n\n/** The composition `result` checked, which is what a render draws. Throws {@link CompositionValidationError} when `mode` is `'throw'` and `result` is invalid, or in any mode when {@link checkInputBudget} refused the input. */\nexport const compositionToRender = <TNode extends PrimitiveNode>(\n result: CheckedValidationResult<TNode>,\n mode?: ValidationErrorMode\n): CheckedComposition<TNode> => {\n enforceValidationMode(result, mode);\n const { composition } = result;\n if (composition === undefined) {\n throw new CompositionValidationError(result.errors);\n }\n return composition;\n};\n\n/** Runtime facts the semantic passes need beyond the primitive inventory. */\nexport interface CompositionValidatorOptions {\n /**\n * Whether any frame the runtime can draw with sizes itself from node heights,\n * which is what makes a missing `metrics.svgHeight` matter.\n *\n * A runtime-wide question rather than a per-node one, because a frame is a\n * runtime input: any node can be drawn under any frame, so the metric is\n * load-bearing as soon as one frame consults it. Defaults to `false`, so a\n * runtime with no frame at all reports nothing about a value nothing reads.\n */\n sizesFromNodeHeights?: boolean;\n /** Limits checked before the schema runs; see {@link checkInputBudget}. */\n inputBudget?: InputBudget;\n}\n\n/** The body's nodes, as {@link IssueRoot}s for a node issue formatter. */\nconst bodyRoots = (value: unknown): IssueRoot[] => {\n const { body } = (value ?? {}) as { body?: unknown };\n return Array.isArray(body)\n ? body.map((node, index) => [node, `body[${index}]`] as const)\n : [];\n};\n\n/**\n * Builds the trusted-input validator: {@link checkInputBudget}, then the schema and the semantic passes on its copy, which the result carries.\n *\n * `definitions` is memoized on array identity, so a caller that rebuilds the\n * array per call (`createCompositionValidator(packs.flatMap(…))`) resolves a\n * fresh discriminated union each time. Hold the array `composePacks` returns\n * and reuse it across the validator, the parser, and the authoring context.\n */\nexport const createCompositionValidator = <\n TNode extends PrimitiveNode = PrimitiveNode,\n>(\n definitions: readonly AnyPrimitiveDefinition[],\n options: CompositionValidatorOptions = {}\n): ((composition: Composition<TNode>) => CheckedValidationResult<TNode>) => {\n const schema = getCompositionSchemaForDefinitions(definitions);\n const walk = createChildNodeWalker(definitions);\n const formatIssues = createNodeIssueFormatter(definitions);\n return (composition) => {\n const checked = checkInputBudget(composition, options.inputBudget);\n if (!checked.valid) {\n return {\n valid: false,\n errors: [checked.error],\n warnings: [],\n composition: undefined,\n };\n }\n const plain = checked.value as CheckedComposition<TNode>;\n const result = schema.safeParse(plain, { reportInput: true });\n if (result.success) {\n const { body } = plain;\n const idErrors = collectDuplicateNodeIdErrors(body, walk);\n const warnings = [\n ...collectEmptySurfaceWarnings(body, walk),\n ...(options.sizesFromNodeHeights\n ? collectMissingSvgHeightWarnings(body, definitions, walk)\n : []),\n ];\n return {\n valid: idErrors.length === 0,\n errors: idErrors,\n warnings,\n composition: plain,\n };\n }\n return {\n valid: false,\n errors: formatIssues(bodyRoots(plain), result.error.issues),\n warnings: [],\n composition: plain,\n };\n };\n};\n\n/** The outcome of `parse`. */\nexport interface ParsedComposition {\n /** True when the value matched the schema. Says nothing about id uniqueness. */\n valid: boolean;\n /** Schema failures. Empty when `valid`. */\n errors: ValidationError[];\n /** The parsed document, present only when `valid`. */\n composition?: Composition;\n}\n\n/**\n * Builds the untrusted-input parser: {@link checkInputBudget}, then the schema only on its copy, reported rather than thrown.\n *\n * Deliberately narrower than {@link createCompositionValidator}. This answers\n * \"is this a `Composition`\", not \"is this a good one\" — it does not run the\n * duplicate-id pass or produce warnings, so a composition with two nodes\n * sharing an `id` parses as valid. Id uniqueness is a `validate` guarantee, so\n * a caller that wants the semantic checks runs `validate` on the result.\n *\n * Shares {@link createCompositionValidator}'s memoization identity requirement.\n */\nexport const createCompositionParser = (\n definitions: readonly AnyPrimitiveDefinition[],\n { inputBudget }: Pick<CompositionValidatorOptions, 'inputBudget'> = {}\n): ((value: unknown) => ParsedComposition) => {\n const schema = getCompositionSchemaForDefinitions(definitions);\n const formatIssues = createNodeIssueFormatter(definitions);\n return (value) => {\n const checked = checkInputBudget(value, inputBudget);\n if (!checked.valid) {\n return { valid: false, errors: [checked.error] };\n }\n const result = schema.safeParse(checked.value, { reportInput: true });\n if (result.success) {\n return {\n valid: true,\n errors: [],\n composition: result.data as unknown as Composition,\n };\n }\n return {\n valid: false,\n errors: formatIssues(bodyRoots(checked.value), result.error.issues),\n };\n };\n};\n\n/** Warns once per surface that the whole body renders nothing on. */\nconst collectEmptySurfaceWarnings = (\n body: readonly unknown[],\n walk: ReturnType<typeof createChildNodeWalker>\n): ValidationWarning[] =>\n BODY_NODE_SURFACES.filter(\n (surface) => !body.some((node) => rendersOnSurface(node, surface, walk))\n ).map((surface) => ({\n surface,\n message: `composition renders no nodes on surface \"${surface}\"`,\n }));\n\n/**\n * Warns for each node that renders to `svg` but declares no `svgHeight`.\n *\n * `metrics.svgHeight` is optional, so `dispatcher.estimateSvgHeight` returns\n * `0` for such a node and a frame that sums node heights sizes short.\n *\n * Whether a runtime consults the metric at all is the caller's to decide; see\n * {@link CompositionValidatorOptions.sizesFromNodeHeights}. A fixed-size frame\n * never does, and warning about a value nothing reads is how a warning channel\n * gets ignored.\n */\nconst collectMissingSvgHeightWarnings = (\n body: readonly unknown[],\n definitions: readonly AnyPrimitiveDefinition[],\n walk: ReturnType<typeof createChildNodeWalker>\n): ValidationWarning[] => {\n const unmeasured = new Set(\n definitions\n .filter((definition) => !definition.metrics?.svgHeight)\n .map((definition) => definition.type)\n );\n if (unmeasured.size === 0) {\n return [];\n }\n const warnings: ValidationWarning[] = [];\n const visit = (node: unknown, path: string): void => {\n if (!node || typeof node !== 'object' || !isVisibleOnSurface(node, 'svg')) {\n return;\n }\n const { type } = node as { type?: unknown };\n if (typeof type === 'string' && unmeasured.has(type)) {\n warnings.push({\n surface: 'svg',\n path,\n message: `${path} type ${quoteText(type)} declares no svgHeight metric and will be measured as 0, sizing the frame short`,\n });\n }\n walk(node).forEach(({ node: child, path: field }) => {\n visit(child, childNodePath(path, field));\n });\n };\n body.forEach((node, index) => visit(node, `body[${index}]`));\n return warnings;\n};\n\n/**\n * Errors for each node whose `id` repeats one already seen, naming the first\n * use.\n *\n * Errors rather than warnings, because ids are what a host addresses a node by.\n * Run by `validate` and deliberately not by `parse`; see\n * {@link createCompositionParser}.\n */\nconst collectDuplicateNodeIdErrors = (\n body: readonly unknown[],\n walk: ReturnType<typeof createChildNodeWalker>\n): ValidationError[] => {\n const errors: ValidationError[] = [];\n const seen = new Map<string, string>();\n const visit = (node: unknown, path: string): void => {\n if (!node || typeof node !== 'object') {\n return;\n }\n const { id, type } = node as { id?: unknown; type?: unknown };\n if (typeof id === 'string') {\n const first = seen.get(id);\n if (first) {\n errors.push({\n path: `${path}.id`,\n message: `duplicates id ${quoteText(id)} first used at ${first}`,\n ...(typeof type === 'string' ? { nodeType: type } : {}),\n });\n } else {\n seen.set(id, path);\n }\n }\n walk(node).forEach(({ node: child, path: field }) => {\n visit(child, childNodePath(path, field));\n });\n };\n body.forEach((node, index) => visit(node, `body[${index}]`));\n return errors;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../../src/validate/validation.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,kEAMuC;AAGvC,sDAAoD;AACpD,sEAGyC;AAuEhC,2GAzEP,6CAA0B,OAyEO;AApEnC,6DAA0E;AAC1E,iDAIwB;AACxB,+CAAyE;AAsCzE,MAAM,kBAAkB,GAAG,MAAM,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAC;AAc5E,8EAA8E;AACvE,MAAM,kBAAkB,GAAG,CAChC,MAAwB,EACxB,OAAoB,EACC,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AAC,CAAC;YACrB,CAAC;QACH,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE;YAClD,KAAK,CAAC,KAAK,EAAE,IAAA,8BAAa,EAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;QAC3C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;IACF,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,QAAQ,KAAK,GAAG,CAAC,CAAC,CAAC;IAC7D,OAAO,MAAM,CAAC;AAChB,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 {\n childNodePath,\n createChildNodeWalker,\n rendersOnSurface,\n SURFACE_NAMES,\n type SurfaceName,\n} from '../composition/body_node_base';\nimport type { Composition } from '../composition/composition';\nimport type { PrimitiveNode } from '../composition/node';\nimport { quoteText } from '../composition/one_line';\nimport {\n CompositionValidationError,\n type ValidationError,\n} from '../composition/validation_error';\nimport type { AnyPrimitiveDefinition } from '../define/primitive_module';\n\nimport { getCompositionSchemaForDefinitions } from './composition_schema';\nimport {\n checkInputBudget,\n type InputBudget,\n isInputRefusal,\n} from './input_budget';\nimport { createNodeIssueFormatter, type IssueRoot } from './node_issues';\n\n/**\n * A non-fatal validation finding, scoped to the surface it concerns.\n *\n * Warnings carry `surface` because every one of them is a statement about one\n * render target — a composition that draws nothing on `slack` is not news to a\n * caller rendering HTML. Without the scope a host receives every surface's\n * findings on every call and learns to ignore the channel.\n * {@link warningsForSurface} is the filter.\n */\nexport interface ValidationWarning {\n /** The render target this finding concerns, never the composition as a whole. */\n surface: SurfaceName;\n /**\n * Path of the offending node within the composition, absent for\n * whole-composition findings.\n */\n path?: string;\n /** Safe to show a user, and phrased for whoever can act on it. */\n message: string;\n}\n\n/**\n * The outcome of `validate`: errors are fatal, warnings are advisory.\n *\n * `valid` tracks `errors` only — a composition can be valid and still carry\n * warnings, which is the normal case for a surface gap.\n */\nexport interface ValidationResult {\n /** True when `errors` is empty, regardless of `warnings`. */\n valid: boolean;\n /** Fatal findings. Empty when `valid`. */\n errors: ValidationError[];\n /** Advisory findings, empty when there are none. */\n warnings: ValidationWarning[];\n}\n\nconst checkedComposition = Symbol.for('elastic.isomer.checked_composition');\n\n/** The copy {@link createCompositionValidator} checked, which a validating render draws in place of the caller's value. The brand is type-only. */\nexport type CheckedComposition<TNode extends PrimitiveNode = PrimitiveNode> =\n Composition<TNode> & { readonly [checkedComposition]: true };\n\n/** A {@link ValidationResult} with the composition it describes. */\nexport interface CheckedValidationResult<\n TNode extends PrimitiveNode = PrimitiveNode,\n> extends ValidationResult {\n /** Undefined only when {@link checkInputBudget} refused the input. */\n composition: CheckedComposition<TNode> | undefined;\n}\n\n/** Narrows a result's warnings to the surface a caller is about to render. */\nexport const warningsForSurface = (\n result: ValidationResult,\n surface: SurfaceName\n): ValidationWarning[] =>\n result.warnings.filter((warning) => warning.surface === surface);\n\n/** Whether a render reports validation findings or raises on them. */\nexport type ValidationErrorMode = 'collect' | 'throw';\n\nexport { CompositionValidationError };\n\n/** Raises {@link CompositionValidationError} when `mode` is `throw` and `result` is invalid, or in any mode when {@link checkInputBudget} refused the input, which nothing can render. */\nexport const enforceValidationMode = (\n result: ValidationResult,\n mode?: ValidationErrorMode\n): void => {\n if (\n !result.valid &&\n (mode === 'throw' || result.errors.some(isInputRefusal))\n ) {\n throw new CompositionValidationError(result.errors);\n }\n};\n\n/** The composition `result` checked, which is what a render draws. Throws {@link CompositionValidationError} when `mode` is `'throw'` and `result` is invalid, or in any mode when {@link checkInputBudget} refused the input. */\nexport const compositionToRender = <TNode extends PrimitiveNode>(\n result: CheckedValidationResult<TNode>,\n mode?: ValidationErrorMode\n): CheckedComposition<TNode> => {\n enforceValidationMode(result, mode);\n const { composition } = result;\n if (composition === undefined) {\n throw new CompositionValidationError(result.errors);\n }\n return composition;\n};\n\n/** Options for {@link createCompositionValidator}. */\nexport interface CompositionValidatorOptions {\n /** Limits checked before the schema runs; see {@link checkInputBudget}. */\n inputBudget?: InputBudget;\n}\n\n/** The body's nodes, as {@link IssueRoot}s for a node issue formatter. */\nconst bodyRoots = (value: unknown): IssueRoot[] => {\n const { body } = (value ?? {}) as { body?: unknown };\n return Array.isArray(body)\n ? body.map((node, index) => [node, `body[${index}]`] as const)\n : [];\n};\n\n/**\n * Builds the trusted-input validator: {@link checkInputBudget}, then the schema and the semantic passes on its copy, which the result carries.\n *\n * `definitions` is memoized on array identity, so a caller that rebuilds the\n * array per call (`createCompositionValidator(packs.flatMap(…))`) resolves a\n * fresh discriminated union each time. Hold the array `composePacks` returns\n * and reuse it across the validator, the parser, and the authoring context.\n */\nexport const createCompositionValidator = <\n TNode extends PrimitiveNode = PrimitiveNode,\n>(\n definitions: readonly AnyPrimitiveDefinition[],\n options: CompositionValidatorOptions = {}\n): ((composition: Composition<TNode>) => CheckedValidationResult<TNode>) => {\n const schema = getCompositionSchemaForDefinitions(definitions);\n const walk = createChildNodeWalker(definitions);\n const formatIssues = createNodeIssueFormatter(definitions);\n return (composition) => {\n const checked = checkInputBudget(composition, options.inputBudget);\n if (!checked.valid) {\n return {\n valid: false,\n errors: [checked.error],\n warnings: [],\n composition: undefined,\n };\n }\n const plain = checked.value as CheckedComposition<TNode>;\n const result = schema.safeParse(plain, { reportInput: true });\n if (result.success) {\n const { body } = plain;\n const idErrors = collectDuplicateNodeIdErrors(body, walk);\n const warnings = collectEmptySurfaceWarnings(body, walk);\n return {\n valid: idErrors.length === 0,\n errors: idErrors,\n warnings,\n composition: plain,\n };\n }\n return {\n valid: false,\n errors: formatIssues(bodyRoots(plain), result.error.issues),\n warnings: [],\n composition: plain,\n };\n };\n};\n\n/** The outcome of `parse`. */\nexport interface ParsedComposition {\n /** True when the value matched the schema. Says nothing about id uniqueness. */\n valid: boolean;\n /** Schema failures. Empty when `valid`. */\n errors: ValidationError[];\n /** The parsed document, present only when `valid`. */\n composition?: Composition;\n}\n\n/**\n * Builds the untrusted-input parser: {@link checkInputBudget}, then the schema only on its copy, reported rather than thrown.\n *\n * Deliberately narrower than {@link createCompositionValidator}. This answers\n * \"is this a `Composition`\", not \"is this a good one\" — it does not run the\n * duplicate-id pass or produce warnings, so a composition with two nodes\n * sharing an `id` parses as valid. Id uniqueness is a `validate` guarantee, so\n * a caller that wants the semantic checks runs `validate` on the result.\n *\n * Shares {@link createCompositionValidator}'s memoization identity requirement.\n */\nexport const createCompositionParser = (\n definitions: readonly AnyPrimitiveDefinition[],\n { inputBudget }: Pick<CompositionValidatorOptions, 'inputBudget'> = {}\n): ((value: unknown) => ParsedComposition) => {\n const schema = getCompositionSchemaForDefinitions(definitions);\n const formatIssues = createNodeIssueFormatter(definitions);\n return (value) => {\n const checked = checkInputBudget(value, inputBudget);\n if (!checked.valid) {\n return { valid: false, errors: [checked.error] };\n }\n const result = schema.safeParse(checked.value, { reportInput: true });\n if (result.success) {\n return {\n valid: true,\n errors: [],\n composition: result.data as unknown as Composition,\n };\n }\n return {\n valid: false,\n errors: formatIssues(bodyRoots(checked.value), result.error.issues),\n };\n };\n};\n\n/** Warns once per surface that the whole body renders nothing on. */\nconst collectEmptySurfaceWarnings = (\n body: readonly unknown[],\n walk: ReturnType<typeof createChildNodeWalker>\n): ValidationWarning[] =>\n SURFACE_NAMES.filter(\n (surface) => !body.some((node) => rendersOnSurface(node, surface, walk))\n ).map((surface) => ({\n surface,\n message: `composition renders no nodes on surface \"${surface}\"`,\n }));\n\n/**\n * Errors for each node whose `id` repeats one already seen, naming the first\n * use.\n *\n * Errors rather than warnings, because ids are what a host addresses a node by.\n * Run by `validate` and deliberately not by `parse`; see\n * {@link createCompositionParser}.\n */\nconst collectDuplicateNodeIdErrors = (\n body: readonly unknown[],\n walk: ReturnType<typeof createChildNodeWalker>\n): ValidationError[] => {\n const errors: ValidationError[] = [];\n const seen = new Map<string, string>();\n const visit = (node: unknown, path: string): void => {\n if (!node || typeof node !== 'object') {\n return;\n }\n const { id, type } = node as { id?: unknown; type?: unknown };\n if (typeof id === 'string') {\n const first = seen.get(id);\n if (first) {\n errors.push({\n path: `${path}.id`,\n message: `duplicates id ${quoteText(id)} first used at ${first}`,\n ...(typeof type === 'string' ? { nodeType: type } : {}),\n });\n } else {\n seen.set(id, path);\n }\n }\n walk(node).forEach(({ node: child, path: field }) => {\n visit(child, childNodePath(path, field));\n });\n };\n body.forEach((node, index) => visit(node, `body[${index}]`));\n return errors;\n};\n"]}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Every surface a node renders on or is hidden from, in render order.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* instantiation transfers to another, silently widening to `any`.
|
|
4
|
+
* `html` is not here: the runtime's `html` surface wraps `react` output in a
|
|
5
|
+
* document, and no node targets it.
|
|
7
6
|
*/
|
|
8
|
-
export
|
|
9
|
-
/**
|
|
7
|
+
export declare const SURFACE_NAMES: readonly ["react", "snapshot", "text", "markdown", "slack"];
|
|
8
|
+
/** One of the {@link SURFACE_NAMES}. */
|
|
9
|
+
export type SurfaceName = (typeof SURFACE_NAMES)[number];
|
|
10
|
+
/** @deprecated Use {@link SURFACE_NAMES}. */
|
|
10
11
|
export declare const BODY_NODE_SURFACES: readonly SurfaceName[];
|
|
11
12
|
/** The two fields every primitive node carries, whatever its pack. */
|
|
12
13
|
export interface BodyNodeBase {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"body_node_base.d.ts","sourceRoot":"","sources":["../../src/composition/body_node_base.ts"],"names":[],"mappings":"AAOA
|
|
1
|
+
{"version":3,"file":"body_node_base.d.ts","sourceRoot":"","sources":["../../src/composition/body_node_base.ts"],"names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AW,KACnB,OAMF,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,GAC3B,MAAM,OAAO,EACb,SAAS,WAAW,EACpB,MAAM,eAAe,KACpB,OAWF,CAAC"}
|
|
@@ -4,14 +4,21 @@
|
|
|
4
4
|
* 2.0; you may not use this file except in compliance with the Elastic License
|
|
5
5
|
* 2.0.
|
|
6
6
|
*/
|
|
7
|
-
/**
|
|
8
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Every surface a node renders on or is hidden from, in render order.
|
|
9
|
+
*
|
|
10
|
+
* `html` is not here: the runtime's `html` surface wraps `react` output in a
|
|
11
|
+
* document, and no node targets it.
|
|
12
|
+
*/
|
|
13
|
+
export const SURFACE_NAMES = [
|
|
9
14
|
'react',
|
|
10
|
-
'
|
|
15
|
+
'snapshot',
|
|
11
16
|
'text',
|
|
12
17
|
'markdown',
|
|
13
18
|
'slack',
|
|
14
19
|
];
|
|
20
|
+
/** @deprecated Use {@link SURFACE_NAMES}. */
|
|
21
|
+
export const BODY_NODE_SURFACES = SURFACE_NAMES;
|
|
15
22
|
/**
|
|
16
23
|
* Builds the {@link ChildNodeWalker} for one composition's inventory.
|
|
17
24
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"body_node_base.js","sourceRoot":"","sources":["../../src/composition/body_node_base.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"body_node_base.js","sourceRoot":"","sources":["../../src/composition/body_node_base.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,OAAO;IACP,UAAU;IACV,MAAM;IACN,UAAU;IACV,OAAO;CACC,CAAC;AAKX,6CAA6C;AAC7C,MAAM,CAAC,MAAM,kBAAkB,GAA2B,aAAa,CAAC;AAgCxE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,WAIG,EACc,EAAE;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AI,CAAC,kBAAkB,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,CAAC;QACvC,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5B,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QACxD,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,CACvC,gBAAgB,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,CACvC,CAAC;AACJ,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/**\n * Every surface a node renders on or is hidden from, in render order.\n *\n * `html` is not here: the runtime's `html` surface wraps `react` output in a\n * document, and no node targets it.\n */\nexport const SURFACE_NAMES = [\n 'react',\n 'snapshot',\n 'text',\n 'markdown',\n 'slack',\n] as const;\n\n/** One of the {@link SURFACE_NAMES}. */\nexport type SurfaceName = (typeof SURFACE_NAMES)[number];\n\n/** @deprecated Use {@link SURFACE_NAMES}. */\nexport const BODY_NODE_SURFACES: readonly SurfaceName[] = SURFACE_NAMES;\n\n/** The two fields every primitive node carries, whatever its pack. */\nexport interface BodyNodeBase {\n /** Unique within a composition, which `validate` enforces and `parse` does not. */\n id?: string;\n /** Surfaces this node appears on. Absent means every surface. */\n surfaces?: SurfaceName[];\n}\n\n/**\n * A child node together with the field path locating it inside its parent, so\n * an error path can name the field a child actually lives under. A container\n * that returned bare nodes would leave every caller guessing the field name.\n */\nexport interface ChildNodeRef {\n /** Erased: one walker spans every pack's node types, so it can name none of them. */\n node: unknown;\n /** Relative to the parent, e.g. `items[0].node`, `items[2].description`. */\n path: string;\n}\n\n/**\n * Walks nested nodes and, for a hybrid container, reports whether the parent\n * still produces output of its own. A non-empty `children` result is the\n * complete source of rendered content unless\n * {@link ChildNodeWalker.hasOwnContent} is true for that node.\n */\nexport type ChildNodeWalker = ((node: unknown) => ChildNodeRef[]) & {\n hasOwnContent?(node: unknown): boolean;\n};\n\n/**\n * Builds the {@link ChildNodeWalker} for one composition's inventory.\n *\n * Pass every pack's definitions: a walker missing one cannot see children of a\n * container that pack defines, and a tree walk would stop at its boundary.\n */\nexport const createChildNodeWalker = (\n definitions: readonly {\n type: string;\n children?: unknown;\n hasOwnContent?: unknown;\n }[]\n): ChildNodeWalker => {\n const childrenByType = new Map<\n string,\n (node: unknown) => readonly ChildNodeRef[]\n >();\n const ownContentByType = new Map<string, (node: unknown) => boolean>();\n for (const definition of definitions) {\n if (typeof definition.children === 'function') {\n childrenByType.set(\n definition.type,\n definition.children as (node: unknown) => readonly ChildNodeRef[]\n );\n }\n if (typeof definition.hasOwnContent === 'function') {\n ownContentByType.set(\n definition.type,\n definition.hasOwnContent as (node: unknown) => boolean\n );\n }\n }\n const walk = ((node: unknown) => {\n if (!node || typeof node !== 'object') {\n return [];\n }\n const { type } = node as { type?: unknown };\n if (typeof type !== 'string') {\n return [];\n }\n return [...(childrenByType.get(type)?.(node) ?? [])];\n }) as ChildNodeWalker;\n walk.hasOwnContent = (node) => {\n if (!node || typeof node !== 'object') {\n return false;\n }\n const { type } = node as { type?: unknown };\n if (typeof type !== 'string') {\n return false;\n }\n return ownContentByType.get(type)?.(node) ?? false;\n };\n return walk;\n};\n\n/** Joins a parent path with a {@link ChildNodeRef.path} fragment. */\nexport const childNodePath = (parent: string, child: string): string =>\n `${parent}.${child}`;\n\n/**\n * Whether any node visible on `surface` matches, descending through container\n * children via `walk`. A node (or a container ancestor) hidden from `surface`\n * is skipped along with its children.\n *\n * `walk` must span every pack in the composition: a walker built from one\n * pack's definitions cannot see children of a container defined in another.\n */\nexport const someBodyNode = (\n nodes: readonly unknown[],\n surface: SurfaceName,\n predicate: (node: unknown) => boolean,\n walk: ChildNodeWalker\n): boolean =>\n nodes.some((node) => {\n if (!isVisibleOnSurface(node, surface)) {\n return false;\n }\n return (\n predicate(node) ||\n someBodyNode(\n walk(node).map((child) => child.node),\n surface,\n predicate,\n walk\n )\n );\n });\n\n/** Whether `node`'s own `surfaces` hint admits `surface`, ignoring its children. */\nexport const isVisibleOnSurface = (\n node: unknown,\n surface: SurfaceName\n): boolean => {\n if (!node || typeof node !== 'object') {\n return false;\n }\n const { surfaces } = node as { surfaces?: unknown };\n return !Array.isArray(surfaces) || surfaces.includes(surface);\n};\n\n/**\n * Whether `node` puts anything on `surface` — itself or through a descendant.\n *\n * Stronger than {@link isVisibleOnSurface}: a container every one of whose\n * children is hidden renders nothing, even though its own hint allows the\n * surface. A hybrid container that also owns string fields declares\n * {@link ChildNodeWalker.hasOwnContent} and keeps rendering regardless.\n */\nexport const rendersOnSurface = (\n node: unknown,\n surface: SurfaceName,\n walk: ChildNodeWalker\n): boolean => {\n if (!isVisibleOnSurface(node, surface)) {\n return false;\n }\n const children = walk(node);\n if (children.length === 0 || walk.hasOwnContent?.(node)) {\n return true;\n }\n return children.some(({ node: child }) =>\n rendersOnSurface(child, surface, walk)\n );\n};\n"]}
|
|
@@ -14,6 +14,7 @@ export declare const ISOMER_ERROR_CODES: {
|
|
|
14
14
|
readonly CYCLIC_COMPOSITION: "CYCLIC_COMPOSITION";
|
|
15
15
|
readonly DUPLICATE_AUTHORED_CHILD: "DUPLICATE_AUTHORED_CHILD";
|
|
16
16
|
readonly DUPLICATE_ENHANCEMENT: "DUPLICATE_ENHANCEMENT";
|
|
17
|
+
readonly DUPLICATE_FORMAT: "DUPLICATE_FORMAT";
|
|
17
18
|
readonly DUPLICATE_PACK_ID: "DUPLICATE_PACK_ID";
|
|
18
19
|
readonly DUPLICATE_PRIMITIVE_TYPE: "DUPLICATE_PRIMITIVE_TYPE";
|
|
19
20
|
readonly DUPLICATE_VIEW: "DUPLICATE_VIEW";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/composition/error.ts"],"names":[],"mappings":"AAOA;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/composition/error.ts"],"names":[],"mappings":"AAOA;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsCrB,CAAC;AAEX,yCAAyC;AACzC,MAAM,MAAM,eAAe,GACzB,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,OAAO,kBAAkB,CAAC,CAAC;AAE/D;;;;;;;GAOG;AACH,qBAAa,WAAY,SAAQ,KAAK;IACpC,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC;gBAEnB,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM;CAKnD"}
|
|
@@ -20,6 +20,7 @@ export const ISOMER_ERROR_CODES = {
|
|
|
20
20
|
CYCLIC_COMPOSITION: 'CYCLIC_COMPOSITION',
|
|
21
21
|
DUPLICATE_AUTHORED_CHILD: 'DUPLICATE_AUTHORED_CHILD',
|
|
22
22
|
DUPLICATE_ENHANCEMENT: 'DUPLICATE_ENHANCEMENT',
|
|
23
|
+
DUPLICATE_FORMAT: 'DUPLICATE_FORMAT',
|
|
23
24
|
DUPLICATE_PACK_ID: 'DUPLICATE_PACK_ID',
|
|
24
25
|
DUPLICATE_PRIMITIVE_TYPE: 'DUPLICATE_PRIMITIVE_TYPE',
|
|
25
26
|
DUPLICATE_VIEW: 'DUPLICATE_VIEW',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/composition/error.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,eAAe,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GAAG,IAAI,CAAC;IACnB,CAAC;CACF","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/**\n * Stable codes for {@link IsomerError}, {@link CompositionValidationError},\n * and the runtime's `RegisteredViewInputError`. Hosts branch on `code`, not\n * on `message`. Codes name the condition, not the throwing module: duplicate\n * type at `definePrimitivePack`, `composePacks`, and `createIsomerRuntime` is the same\n * `DUPLICATE_PRIMITIVE_TYPE`; the message names the layer.\n */\nexport const ISOMER_ERROR_CODES = {\n AMBIGUOUS_FRAME: 'AMBIGUOUS_FRAME',\n AMBIGUOUS_STYLE_ADAPTER: 'AMBIGUOUS_STYLE_ADAPTER',\n AUTHOR_TYPE_MISMATCH: 'AUTHOR_TYPE_MISMATCH',\n AUTHORED_SCHEMA_REUSED: 'AUTHORED_SCHEMA_REUSED',\n COMPOSITION_INVALID: 'COMPOSITION_INVALID',\n CYCLIC_COMPOSITION: 'CYCLIC_COMPOSITION',\n DUPLICATE_AUTHORED_CHILD: 'DUPLICATE_AUTHORED_CHILD',\n DUPLICATE_ENHANCEMENT: 'DUPLICATE_ENHANCEMENT',\n DUPLICATE_PACK_ID: 'DUPLICATE_PACK_ID',\n DUPLICATE_PRIMITIVE_TYPE: 'DUPLICATE_PRIMITIVE_TYPE',\n DUPLICATE_VIEW: 'DUPLICATE_VIEW',\n EMPTY_FRAMES: 'EMPTY_FRAMES',\n EMPTY_PACK: 'EMPTY_PACK',\n EMPTY_PACKS: 'EMPTY_PACKS',\n EMPTY_PAGES: 'EMPTY_PAGES',\n EMPTY_VOCABULARY: 'EMPTY_VOCABULARY',\n ENHANCEMENT_ROOT_MISSING: 'ENHANCEMENT_ROOT_MISSING',\n EXPECTED_AUTHOR_COMPONENT: 'EXPECTED_AUTHOR_COMPONENT',\n EXPECTED_JSX_ELEMENT: 'EXPECTED_JSX_ELEMENT',\n EXPECTED_TEXT_CHILDREN: 'EXPECTED_TEXT_CHILDREN',\n INCOMPATIBLE_STYLE_COLLECTOR: 'INCOMPATIBLE_STYLE_COLLECTOR',\n INPUT_NOT_PLAIN_DATA: 'INPUT_NOT_PLAIN_DATA',\n INPUT_OVER_BUDGET: 'INPUT_OVER_BUDGET',\n INVALID_BODY_NODE: 'INVALID_BODY_NODE',\n INVALID_FRAME_BODY: 'INVALID_FRAME_BODY',\n MISSING_AUTHORED_TEXT: 'MISSING_AUTHORED_TEXT',\n MISSING_STYLE_ADAPTER: 'MISSING_STYLE_ADAPTER',\n RESERVED_NODE_FIELD: 'RESERVED_NODE_FIELD',\n UNEXPECTED_CHILDREN: 'UNEXPECTED_CHILDREN',\n UNKNOWN_FRAME: 'UNKNOWN_FRAME',\n UNKNOWN_PRIMITIVE_TYPE: 'UNKNOWN_PRIMITIVE_TYPE',\n UNKNOWN_SURFACE: 'UNKNOWN_SURFACE',\n UNKNOWN_VIEW: 'UNKNOWN_VIEW',\n UNSUPPORTED_CHILD_PATH: 'UNSUPPORTED_CHILD_PATH',\n VIEW_INPUT_INVALID: 'VIEW_INPUT_INVALID',\n VOCABULARY_UNRESOLVED: 'VOCABULARY_UNRESOLVED',\n} as const;\n\n/** One of {@link ISOMER_ERROR_CODES}. */\nexport type IsomerErrorCode =\n (typeof ISOMER_ERROR_CODES)[keyof typeof ISOMER_ERROR_CODES];\n\n/**\n * Thrown for construction and authoring failures that are not a\n * `CompositionValidationError`.\n *\n * Identify it by `name` and `code`, never `instanceof`: the SDK ships both\n * ESM and CJS builds, so a host can hold two copies of this class and an\n * identity check would miss one.\n */\nexport class IsomerError extends Error {\n readonly code: IsomerErrorCode;\n\n constructor(code: IsomerErrorCode, message: string) {\n super(message);\n this.name = 'IsomerError';\n this.code = code;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/composition/error.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;GAM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O,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF","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/**\n * Stable codes for {@link IsomerError}, {@link CompositionValidationError},\n * and the runtime's `RegisteredViewInputError`. Hosts branch on `code`, not\n * on `message`. Codes name the condition, not the throwing module: duplicate\n * type at `definePrimitivePack`, `composePacks`, and `createIsomerRuntime` is the same\n * `DUPLICATE_PRIMITIVE_TYPE`; the message names the layer.\n */\nexport const ISOMER_ERROR_CODES = {\n AMBIGUOUS_FRAME: 'AMBIGUOUS_FRAME',\n AMBIGUOUS_STYLE_ADAPTER: 'AMBIGUOUS_STYLE_ADAPTER',\n AUTHOR_TYPE_MISMATCH: 'AUTHOR_TYPE_MISMATCH',\n AUTHORED_SCHEMA_REUSED: 'AUTHORED_SCHEMA_REUSED',\n COMPOSITION_INVALID: 'COMPOSITION_INVALID',\n CYCLIC_COMPOSITION: 'CYCLIC_COMPOSITION',\n DUPLICATE_AUTHORED_CHILD: 'DUPLICATE_AUTHORED_CHILD',\n DUPLICATE_ENHANCEMENT: 'DUPLICATE_ENHANCEMENT',\n DUPLICATE_FORMAT: 'DUPLICATE_FORMAT',\n DUPLICATE_PACK_ID: 'DUPLICATE_PACK_ID',\n DUPLICATE_PRIMITIVE_TYPE: 'DUPLICATE_PRIMITIVE_TYPE',\n DUPLICATE_VIEW: 'DUPLICATE_VIEW',\n EMPTY_FRAMES: 'EMPTY_FRAMES',\n EMPTY_PACK: 'EMPTY_PACK',\n EMPTY_PACKS: 'EMPTY_PACKS',\n EMPTY_PAGES: 'EMPTY_PAGES',\n EMPTY_VOCABULARY: 'EMPTY_VOCABULARY',\n ENHANCEMENT_ROOT_MISSING: 'ENHANCEMENT_ROOT_MISSING',\n EXPECTED_AUTHOR_COMPONENT: 'EXPECTED_AUTHOR_COMPONENT',\n EXPECTED_JSX_ELEMENT: 'EXPECTED_JSX_ELEMENT',\n EXPECTED_TEXT_CHILDREN: 'EXPECTED_TEXT_CHILDREN',\n INCOMPATIBLE_STYLE_COLLECTOR: 'INCOMPATIBLE_STYLE_COLLECTOR',\n INPUT_NOT_PLAIN_DATA: 'INPUT_NOT_PLAIN_DATA',\n INPUT_OVER_BUDGET: 'INPUT_OVER_BUDGET',\n INVALID_BODY_NODE: 'INVALID_BODY_NODE',\n INVALID_FRAME_BODY: 'INVALID_FRAME_BODY',\n MISSING_AUTHORED_TEXT: 'MISSING_AUTHORED_TEXT',\n MISSING_STYLE_ADAPTER: 'MISSING_STYLE_ADAPTER',\n RESERVED_NODE_FIELD: 'RESERVED_NODE_FIELD',\n UNEXPECTED_CHILDREN: 'UNEXPECTED_CHILDREN',\n UNKNOWN_FRAME: 'UNKNOWN_FRAME',\n UNKNOWN_PRIMITIVE_TYPE: 'UNKNOWN_PRIMITIVE_TYPE',\n UNKNOWN_SURFACE: 'UNKNOWN_SURFACE',\n UNKNOWN_VIEW: 'UNKNOWN_VIEW',\n UNSUPPORTED_CHILD_PATH: 'UNSUPPORTED_CHILD_PATH',\n VIEW_INPUT_INVALID: 'VIEW_INPUT_INVALID',\n VOCABULARY_UNRESOLVED: 'VOCABULARY_UNRESOLVED',\n} as const;\n\n/** One of {@link ISOMER_ERROR_CODES}. */\nexport type IsomerErrorCode =\n (typeof ISOMER_ERROR_CODES)[keyof typeof ISOMER_ERROR_CODES];\n\n/**\n * Thrown for construction and authoring failures that are not a\n * `CompositionValidationError`.\n *\n * Identify it by `name` and `code`, never `instanceof`: the SDK ships both\n * ESM and CJS builds, so a host can hold two copies of this class and an\n * identity check would miss one.\n */\nexport class IsomerError extends Error {\n readonly code: IsomerErrorCode;\n\n constructor(code: IsomerErrorCode, message: string) {\n super(message);\n this.name = 'IsomerError';\n this.code = code;\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { type ActionEventRef } from './action_event.js';
|
|
2
|
-
export { type BodyNodeBase, type ChildNodeRef, type ChildNodeWalker, type SurfaceName, BODY_NODE_SURFACES, createChildNodeWalker, isVisibleOnSurface, someBodyNode, } from './body_node_base.js';
|
|
2
|
+
export { type BodyNodeBase, type ChildNodeRef, type ChildNodeWalker, type SurfaceName, BODY_NODE_SURFACES, SURFACE_NAMES, createChildNodeWalker, isVisibleOnSurface, someBodyNode, } from './body_node_base.js';
|
|
3
3
|
export { type Composition, type CompositionMeta } from './composition.js';
|
|
4
4
|
export { type IsomerErrorCode, ISOMER_ERROR_CODES, IsomerError } from './error.js';
|
|
5
5
|
export { mapCompositionNodes } from './map_nodes.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/composition/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,kBAAkB,EAClB,qBAAqB,EACrB,kBAAkB,EAClB,YAAY,GACb,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,EAAE,KAAK,eAAe,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAChF,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EACL,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,gBAAgB,GACjB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,qBAAqB,EAC1B,wBAAwB,GACzB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,KAAK,eAAe,EACpB,0BAA0B,EAC1B,qBAAqB,GACtB,MAAM,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/composition/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,kBAAkB,EAClB,aAAa,EACb,qBAAqB,EACrB,kBAAkB,EAClB,YAAY,GACb,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,EAAE,KAAK,eAAe,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAChF,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EACL,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,gBAAgB,GACjB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,qBAAqB,EAC1B,wBAAwB,GACzB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,KAAK,eAAe,EACpB,0BAA0B,EAC1B,qBAAqB,GACtB,MAAM,oBAAoB,CAAC"}
|
|
@@ -4,7 +4,7 @@
|
|
|
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 { BODY_NODE_SURFACES, createChildNodeWalker, isVisibleOnSurface, someBodyNode, } from './body_node_base.js';
|
|
7
|
+
export { BODY_NODE_SURFACES, SURFACE_NAMES, createChildNodeWalker, isVisibleOnSurface, someBodyNode, } from './body_node_base.js';
|
|
8
8
|
export { ISOMER_ERROR_CODES, IsomerError } from './error.js';
|
|
9
9
|
export { mapCompositionNodes } from './map_nodes.js';
|
|
10
10
|
export { ALL_NAMED_COLORS, } from './named_color.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/composition/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAKL,kBAAkB,EAClB,qBAAqB,EACrB,kBAAkB,EAClB,YAAY,GACb,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAwB,kBAAkB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAChF,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAIL,gBAAgB,GACjB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,EAIL,wBAAwB,GACzB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAEL,0BAA0B,EAC1B,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 { type ActionEventRef } from './action_event';\nexport {\n type BodyNodeBase,\n type ChildNodeRef,\n type ChildNodeWalker,\n type SurfaceName,\n BODY_NODE_SURFACES,\n createChildNodeWalker,\n isVisibleOnSurface,\n someBodyNode,\n} from './body_node_base';\nexport { type Composition, type CompositionMeta } from './composition';\nexport { type IsomerErrorCode, ISOMER_ERROR_CODES, IsomerError } from './error';\nexport { mapCompositionNodes } from './map_nodes';\nexport {\n type NamedColor,\n type NamedColorPalette,\n type RenderTheme,\n ALL_NAMED_COLORS,\n} from './named_color';\nexport { type PrimitiveNode } from './node';\nexport { nameText, oneLine, quoteText } from './one_line';\nexport {\n type DisplayValue,\n type StructuredValue,\n type StructuredValueFormat,\n STRUCTURED_VALUE_FORMATS,\n} from './structured_value';\nexport {\n type ValidationError,\n CompositionValidationError,\n formatValidationError,\n} from './validation_error';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/composition/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAKL,kBAAkB,EAClB,aAAa,EACb,qBAAqB,EACrB,kBAAkB,EAClB,YAAY,GACb,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAwB,kBAAkB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAChF,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAIL,gBAAgB,GACjB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,EAIL,wBAAwB,GACzB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAEL,0BAA0B,EAC1B,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 { type ActionEventRef } from './action_event';\nexport {\n type BodyNodeBase,\n type ChildNodeRef,\n type ChildNodeWalker,\n type SurfaceName,\n BODY_NODE_SURFACES,\n SURFACE_NAMES,\n createChildNodeWalker,\n isVisibleOnSurface,\n someBodyNode,\n} from './body_node_base';\nexport { type Composition, type CompositionMeta } from './composition';\nexport { type IsomerErrorCode, ISOMER_ERROR_CODES, IsomerError } from './error';\nexport { mapCompositionNodes } from './map_nodes';\nexport {\n type NamedColor,\n type NamedColorPalette,\n type RenderTheme,\n ALL_NAMED_COLORS,\n} from './named_color';\nexport { type PrimitiveNode } from './node';\nexport { nameText, oneLine, quoteText } from './one_line';\nexport {\n type DisplayValue,\n type StructuredValue,\n type StructuredValueFormat,\n STRUCTURED_VALUE_FORMATS,\n} from './structured_value';\nexport {\n type ValidationError,\n CompositionValidationError,\n formatValidationError,\n} from './validation_error';\n"]}
|
package/dist/define/frame.d.ts
CHANGED
|
@@ -33,10 +33,10 @@ export interface FrameViewport<TTheme> {
|
|
|
33
33
|
* written against a narrowed node union while the runtime holds the erased form.
|
|
34
34
|
*/
|
|
35
35
|
export interface FrameDispatcher<TNode extends PrimitiveNode = PrimitiveNode> {
|
|
36
|
-
/** Draws one node on the `
|
|
37
|
-
|
|
38
|
-
/** The node's height in pixels; `0` when it is hidden from `
|
|
39
|
-
|
|
36
|
+
/** Draws one node on the `snapshot` surface. `key` must be unique among its siblings. */
|
|
37
|
+
renderSnapshot(node: TNode, key: string): ReactNode;
|
|
38
|
+
/** The node's height in pixels; `0` when it is hidden from `snapshot` or its primitive declares no `metrics.snapshotHeight`. */
|
|
39
|
+
estimateSnapshotHeight(node: TNode): number;
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
42
|
* What {@link Frame.wrap} is told about the composition it draws around.
|
|
@@ -63,7 +63,7 @@ export interface FrameComposition extends FrameHeader {
|
|
|
63
63
|
*/
|
|
64
64
|
export type FrameBody = readonly ReactNode[];
|
|
65
65
|
/**
|
|
66
|
-
* A document
|
|
66
|
+
* A document a `snapshot` render can produce: its geometry, the surround it draws
|
|
67
67
|
* around the body, and whatever it requires of a composition it is asked to
|
|
68
68
|
* draw.
|
|
69
69
|
*
|
|
@@ -77,16 +77,6 @@ export type FrameBody = readonly ReactNode[];
|
|
|
77
77
|
export interface Frame<TTheme> {
|
|
78
78
|
/** Width used when the caller passes none. */
|
|
79
79
|
defaultWidth: number;
|
|
80
|
-
/**
|
|
81
|
-
* Whether {@link Frame.estimateHeight} sums per-node heights, and so
|
|
82
|
-
* under-sizes the frame for a node whose primitive declares no
|
|
83
|
-
* `metrics.svgHeight` — `dispatcher.estimateSvgHeight` returns `0` for those.
|
|
84
|
-
*
|
|
85
|
-
* Defaults to `true`, because the gap is silent and a frame that measures
|
|
86
|
-
* nodes is the normal case. A fixed-size frame sets `false` once and stops
|
|
87
|
-
* the missing `svgHeight` warning reporting a metric nothing reads.
|
|
88
|
-
*/
|
|
89
|
-
sizesFromNodeHeights?: boolean;
|
|
90
80
|
/**
|
|
91
81
|
* Palette per mode. Frame and palette vary independently — a branded card is
|
|
92
82
|
* this geometry with a host's colors — so a host overrides one by spreading
|
|
@@ -95,8 +85,9 @@ export interface Frame<TTheme> {
|
|
|
95
85
|
theme: ThemePair<TTheme>;
|
|
96
86
|
/**
|
|
97
87
|
* Height for this body when the caller passes none, in the geometry this
|
|
98
|
-
* document defines.
|
|
99
|
-
*
|
|
88
|
+
* document defines. Calling {@link FrameDispatcher.estimateSnapshotHeight} is
|
|
89
|
+
* what makes a missing `metrics.snapshotHeight` size the frame short: that
|
|
90
|
+
* method returns `0` for a node whose primitive declares none.
|
|
100
91
|
*/
|
|
101
92
|
estimateHeight(composition: FrameComposition, dispatcher: FrameDispatcher): number;
|
|
102
93
|
/**
|
|
@@ -106,7 +97,7 @@ export interface Frame<TTheme> {
|
|
|
106
97
|
* Returned rather than thrown so a caller can decide what to do with it, but
|
|
107
98
|
* note where it is *not* checked: composition validation is frame-agnostic,
|
|
108
99
|
* and has to be, because the same composition can be valid in one frame and
|
|
109
|
-
* not another. Only the `
|
|
100
|
+
* not another. Only the `snapshot` surface consults this, on the frame a render
|
|
110
101
|
* actually names, and raises before drawing. A host that wants the answer
|
|
111
102
|
* earlier asks the frame directly.
|
|
112
103
|
*/
|
|
@@ -136,8 +127,6 @@ export interface Frame<TTheme> {
|
|
|
136
127
|
*/
|
|
137
128
|
export interface BoundFrame {
|
|
138
129
|
readonly defaultWidth: number;
|
|
139
|
-
/** See {@link Frame.sizesFromNodeHeights}; defaulted at binding. */
|
|
140
|
-
readonly sizesFromNodeHeights: boolean;
|
|
141
130
|
/** See {@link Frame.estimateHeight}. */
|
|
142
131
|
estimateHeight(composition: FrameComposition, dispatcher: FrameDispatcher): number;
|
|
143
132
|
/** See {@link Frame.validateBody}; empty when this frame states no rule. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frame.d.ts","sourceRoot":"","sources":["../../src/define/frame.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD;;;GAGG;AACH,MAAM,WAAW,SAAS,CAAC,MAAM;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;GAKG;AACH,MAAM,WAAW,aAAa,CAAC,MAAM;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,oDAAoD;IACpD,KAAK,EAAE,MAAM,CAAC;IACd,+FAA+F;IAC/F,IAAI,EAAE,WAAW,GAAG,SAAS,CAAC;CAC/B;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,eAAe,CAAC,KAAK,SAAS,aAAa,GAAG,aAAa;IAC1E,
|
|
1
|
+
{"version":3,"file":"frame.d.ts","sourceRoot":"","sources":["../../src/define/frame.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAA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M,CAAC;IACV;;;;;;;;;;OAUG;IACH,YAAY,CAAC,CAAC,IAAI,EAAE,SAAS,aAAa,EAAE,GAAG,SAAS,MAAM,EAAE,CAAC;IACjE;;;;;;;;;;;;OAYG;IACH,IAAI,EAAE,CACJ,MAAM,EAAE,WAAW,EACnB,IAAI,EAAE,SAAS,EACf,QAAQ,EAAE,aAAa,CAAC,MAAM,CAAC,KAC5B,SAAS,CAAC;CAChB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,wCAAwC;IACxC,cAAc,CACZ,WAAW,EAAE,gBAAgB,EAC7B,UAAU,EAAE,eAAe,GAC1B,MAAM,CAAC;IACV,4EAA4E;IAC5E,YAAY,CAAC,IAAI,EAAE,SAAS,aAAa,EAAE,GAAG,SAAS,MAAM,EAAE,CAAC;IAChE;;;;OAIG;IACH,YAAY,CAAC,IAAI,EAAE,WAAW,GAAG,SAAS,GAAG,OAAO,CAAC;IACrD,kEAAkE;IAClE,MAAM,CACJ,WAAW,EAAE,gBAAgB,EAC7B,QAAQ,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,WAAW,GAAG,SAAS,CAAA;KAAE,EAC1E,UAAU,EAAE,eAAe,GAC1B,SAAS,CAAC;IACb,6BAA6B;IAC7B,UAAU,CAAC,IAAI,EAAE,aAAa,EAAE,UAAU,EAAE,eAAe,GAAG,SAAS,CAAC;CACzE;AAED;;;;GAIG;AACH,eAAO,MAAM,SAAS,GAAI,MAAM,EAAE,OAAO,KAAK,CAAC,MAAM,CAAC,KAAG,UAuBxD,CAAC"}
|
package/dist/define/frame.js
CHANGED
|
@@ -13,16 +13,15 @@ export const bindFrame = (frame) => {
|
|
|
13
13
|
const themeFor = (mode) => mode === 'dark' ? frame.theme.dark : frame.theme.light;
|
|
14
14
|
return {
|
|
15
15
|
defaultWidth: frame.defaultWidth,
|
|
16
|
-
sizesFromNodeHeights: frame.sizesFromNodeHeights ?? true,
|
|
17
16
|
estimateHeight: (composition, dispatcher) => frame.estimateHeight(composition, dispatcher),
|
|
18
17
|
validateBody: (body) => frame.validateBody?.(body) ?? [],
|
|
19
18
|
resolveTheme: (mode) => themeFor(mode),
|
|
20
19
|
render: (composition, viewport, dispatcher) => {
|
|
21
20
|
const theme = themeFor(viewport.mode);
|
|
22
21
|
const { title, subtitle, theme: mode } = composition;
|
|
23
|
-
return frame.wrap({ title, subtitle, theme: mode }, composition.body.map((node, index) => dispatcher.
|
|
22
|
+
return frame.wrap({ title, subtitle, theme: mode }, composition.body.map((node, index) => dispatcher.renderSnapshot(node, `body-${index}`)), { ...viewport, theme });
|
|
24
23
|
},
|
|
25
|
-
renderNode: (node, dispatcher) => dispatcher.
|
|
24
|
+
renderNode: (node, dispatcher) => dispatcher.renderSnapshot(node, node.type),
|
|
26
25
|
};
|
|
27
26
|
};
|
|
28
27
|
//# sourceMappingURL=frame.js.map
|
package/dist/define/frame.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frame.js","sourceRoot":"","sources":["../../src/define/frame.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAyLH;;;;GAIG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAS,KAAoB,EAAc,EAAE;IACpE,MAAM,QAAQ,GAAG,CAAC,IAA6B,EAAU,EAAE,CACzD,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC;IACzD,OAAO;QACL,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,oBAAoB,EAAE,KAAK,CAAC,oBAAoB,IAAI,IAAI;QACxD,cAAc,EAAE,CAAC,WAAW,EAAE,UAAU,EAAE,EAAE,CAC1C,KAAK,CAAC,cAAc,CAAC,WAAW,EAAE,UAAU,CAAC;QAC/C,YAAY,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,YAAY,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE;QACxD,YAAY,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC;QACtC,MAAM,EAAE,CAAC,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE;YAC5C,MAAM,KAAK,GAAG,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YACtC,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,WAAW,CAAC;YACrD,OAAO,KAAK,CAAC,IAAI,CACf,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,EAChC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CACnC,UAAU,CAAC,SAAS,CAAC,IAAI,EAAE,QAAQ,KAAK,EAAE,CAAC,CAC5C,EACD,EAAE,GAAG,QAAQ,EAAE,KAAK,EAAE,CACvB,CAAC;QACJ,CAAC;QACD,UAAU,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC;KACxE,CAAC;AACJ,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// The frame an `svg` render is drawn inside, and the geometry that sizes it.\n// Frame is a runtime input, not a pack asset: vocabulary is additive, the\n// document is exclusive.\n\nimport type { ReactNode } from 'react';\n\nimport type { RenderTheme } from '../composition/named_color';\nimport type { PrimitiveNode } from '../composition/node';\n\n/**\n * A frame's palette, per mode. An image has no media queries, so it must\n * commit to one; `auto` resolves light.\n */\nexport interface ThemePair<TTheme> {\n light: TTheme;\n dark: TTheme;\n}\n\n/**\n * Geometry and resolved theme a frame draws within.\n *\n * Named for the viewport rather than the frame because {@link Frame.wrap}\n * draws *a* frame within it; the two would otherwise read as the same thing.\n */\nexport interface FrameViewport<TTheme> {\n width: number;\n height: number;\n /** Resolved from {@link Frame.theme} for `mode`. */\n theme: TTheme;\n /** What the caller asked for, before resolution. `undefined` and `auto` both resolve light. */\n mode: RenderTheme | undefined;\n}\n\n/**\n * The two dispatcher methods a frame needs.\n *\n * The render context the nodes are drawn with is bound by the caller rather\n * than passed here: it carries the class-name resolution that pairs with the\n * stylesheet emitted alongside the frame's output, which is the surface's\n * concern and not the document's. Generic in `TNode` so a helper can be\n * written against a narrowed node union while the runtime holds the erased form.\n */\nexport interface FrameDispatcher<TNode extends PrimitiveNode = PrimitiveNode> {\n /** Draws one node on the `svg` surface. `key` must be unique among its siblings. */\n renderSvg(node: TNode, key: string): ReactNode;\n /** The node's height in pixels; `0` when it is hidden from `svg` or its primitive declares no `metrics.svgHeight`. */\n estimateSvgHeight(node: TNode): number;\n}\n\n/**\n * What {@link Frame.wrap} is told about the composition it draws around.\n *\n * The body is withheld, and {@link bindFrame} copies only these fields into a\n * fresh value, so the surround cannot branch on a pack's node types.\n */\nexport interface FrameHeader {\n title?: string | undefined;\n subtitle?: string | undefined;\n /** The caller's preference, not a resolved palette. Use {@link FrameViewport.theme} to draw. */\n theme?: RenderTheme | undefined;\n}\n\n/** {@link FrameHeader} plus the body, for the sizing and validation hooks. */\nexport interface FrameComposition extends FrameHeader {\n /** Raw nodes, for measuring and checking only. {@link FrameBody} is what gets drawn. */\n body: PrimitiveNode[];\n}\n\n/**\n * Body nodes already rendered to elements, ready to be surrounded.\n *\n * Distinct from `Composition.body`, which is the raw {@link PrimitiveNode}\n * array a frame never sees.\n */\nexport type FrameBody = readonly ReactNode[];\n\n/**\n * A document an `svg` render can produce: its geometry, the surround it draws\n * around the body, and whatever it requires of a composition it is asked to\n * draw.\n *\n * A host registers frames with the runtime and picks one per render. That is\n * what lets one runtime serve a 760px card, a 1920x1080 slide, and a\n * host-branded variant of either from the same vocabulary — and what keeps a\n * vocabulary pack additive, since nothing about a primitive decides the frame.\n * A frame is named by the key a host registers it under, not by a field it\n * carries.\n */\nexport interface Frame<TTheme> {\n /** Width used when the caller passes none. */\n defaultWidth: number;\n /**\n * Whether {@link Frame.estimateHeight} sums per-node heights, and so\n * under-sizes the frame for a node whose primitive declares no\n * `metrics.svgHeight` — `dispatcher.estimateSvgHeight` returns `0` for those.\n *\n * Defaults to `true`, because the gap is silent and a frame that measures\n * nodes is the normal case. A fixed-size frame sets `false` once and stops\n * the missing `svgHeight` warning reporting a metric nothing reads.\n */\n sizesFromNodeHeights?: boolean;\n /**\n * Palette per mode. Frame and palette vary independently — a branded card is\n * this geometry with a host's colors — so a host overrides one by spreading\n * this value rather than rebuilding anything.\n */\n theme: ThemePair<TTheme>;\n /**\n * Height for this body when the caller passes none, in the geometry this\n * document defines. See {@link Frame.sizesFromNodeHeights} for what it may\n * assume of the nodes.\n */\n estimateHeight(\n composition: FrameComposition,\n dispatcher: FrameDispatcher\n ): number;\n /**\n * What this document requires of a body. A slide document's\n * exactly-one-`slideFrame` rule is the example.\n *\n * Returned rather than thrown so a caller can decide what to do with it, but\n * note where it is *not* checked: composition validation is frame-agnostic,\n * and has to be, because the same composition can be valid in one frame and\n * not another. Only the `svg` surface consults this, on the frame a render\n * actually names, and raises before drawing. A host that wants the answer\n * earlier asks the frame directly.\n */\n validateBody?(body: readonly PrimitiveNode[]): readonly string[];\n /**\n * Draws the surround around the already-rendered body nodes, including a\n * title header if this document wants one.\n *\n * Takes the nodes as an array rather than a single `ReactNode` so a frame\n * that draws no surround can return its one root element — image layout\n * starts from a single element, and an array or a fragment is not one.\n *\n * Declared property-style, so it is checked contravariantly in `TTheme` under\n * `strictFunctionTypes`. A method signature is bivariant, which would admit a\n * frame needing a richer theme into a slot typed for a narrower one, where it\n * would read a token nothing supplies.\n */\n wrap: (\n header: FrameHeader,\n body: FrameBody,\n viewport: FrameViewport<TTheme>\n ) => ReactNode;\n}\n\n/**\n * A {@link Frame} as the runtime stores it, with its theme resolved away.\n *\n * The erasure is a closure rather than a type parameter because the runtime\n * dispatches nodes through one inventory keyed by node type, which has no\n * single theme to name. A runtime's frames are homogeneous in `TTheme`, so the\n * palette is known where it is resolved and only the resolved result is stored.\n */\nexport interface BoundFrame {\n readonly defaultWidth: number;\n /** See {@link Frame.sizesFromNodeHeights}; defaulted at binding. */\n readonly sizesFromNodeHeights: boolean;\n /** See {@link Frame.estimateHeight}. */\n estimateHeight(\n composition: FrameComposition,\n dispatcher: FrameDispatcher\n ): number;\n /** See {@link Frame.validateBody}; empty when this frame states no rule. */\n validateBody(body: readonly PrimitiveNode[]): readonly string[];\n /**\n * Resolves {@link Frame.theme} for `mode`, erased to `unknown` like the rest\n * of this type. Lets a caller hand the palette to a primitive's `env.theme`\n * without itself knowing `TTheme`.\n */\n resolveTheme(mode: RenderTheme | undefined): unknown;\n /** Renders the body and its surround at `viewport`'s geometry. */\n render(\n composition: FrameComposition,\n viewport: { width: number; height: number; mode: RenderTheme | undefined },\n dispatcher: FrameDispatcher\n ): ReactNode;\n /** One node, no surround. */\n renderNode(node: PrimitiveNode, dispatcher: FrameDispatcher): ReactNode;\n}\n\n/**\n * Erases a {@link Frame}'s `TTheme` into a {@link BoundFrame}, resolving the\n * palette per render and composing the generic body walk with the frame's own\n * surround.\n */\nexport const bindFrame = <TTheme>(frame: Frame<TTheme>): BoundFrame => {\n const themeFor = (mode: RenderTheme | undefined): TTheme =>\n mode === 'dark' ? frame.theme.dark : frame.theme.light;\n return {\n defaultWidth: frame.defaultWidth,\n sizesFromNodeHeights: frame.sizesFromNodeHeights ?? true,\n estimateHeight: (composition, dispatcher) =>\n frame.estimateHeight(composition, dispatcher),\n validateBody: (body) => frame.validateBody?.(body) ?? [],\n resolveTheme: (mode) => themeFor(mode),\n render: (composition, viewport, dispatcher) => {\n const theme = themeFor(viewport.mode);\n const { title, subtitle, theme: mode } = composition;\n return frame.wrap(\n { title, subtitle, theme: mode },\n composition.body.map((node, index) =>\n dispatcher.renderSvg(node, `body-${index}`)\n ),\n { ...viewport, theme }\n );\n },\n renderNode: (node, dispatcher) => dispatcher.renderSvg(node, node.type),\n };\n};\n"]}
|
|
1
|
+
{"version":3,"file":"frame.js","sourceRoot":"","sources":["../../src/define/frame.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA8KH;;;;GAIG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAS,KAAoB,EAAc,EAAE;IACpE,MAAM,QAAQ,GAAG,CAAC,IAA6B,EAAU,EAAE,CACzD,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC;IACzD,OAAO;QACL,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,cAAc,EAAE,CAAC,WAAW,EAAE,UAAU,EAAE,EAAE,CAC1C,KAAK,CAAC,cAAc,CAAC,WAAW,EAAE,UAAU,CAAC;QAC/C,YAAY,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,YAAY,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE;QACxD,YAAY,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC;QACtC,MAAM,EAAE,CAAC,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE;YAC5C,MAAM,KAAK,GAAG,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YACtC,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,WAAW,CAAC;YACrD,OAAO,KAAK,CAAC,IAAI,CACf,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,EAChC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CACnC,UAAU,CAAC,cAAc,CAAC,IAAI,EAAE,QAAQ,KAAK,EAAE,CAAC,CACjD,EACD,EAAE,GAAG,QAAQ,EAAE,KAAK,EAAE,CACvB,CAAC;QACJ,CAAC;QACD,UAAU,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,CAC/B,UAAU,CAAC,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC;KAC7C,CAAC;AACJ,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// The frame a `snapshot` render is drawn inside, and the geometry that sizes it.\n// Frame is a runtime input, not a pack asset: vocabulary is additive, the\n// document is exclusive.\n\nimport type { ReactNode } from 'react';\n\nimport type { RenderTheme } from '../composition/named_color';\nimport type { PrimitiveNode } from '../composition/node';\n\n/**\n * A frame's palette, per mode. An image has no media queries, so it must\n * commit to one; `auto` resolves light.\n */\nexport interface ThemePair<TTheme> {\n light: TTheme;\n dark: TTheme;\n}\n\n/**\n * Geometry and resolved theme a frame draws within.\n *\n * Named for the viewport rather than the frame because {@link Frame.wrap}\n * draws *a* frame within it; the two would otherwise read as the same thing.\n */\nexport interface FrameViewport<TTheme> {\n width: number;\n height: number;\n /** Resolved from {@link Frame.theme} for `mode`. */\n theme: TTheme;\n /** What the caller asked for, before resolution. `undefined` and `auto` both resolve light. */\n mode: RenderTheme | undefined;\n}\n\n/**\n * The two dispatcher methods a frame needs.\n *\n * The render context the nodes are drawn with is bound by the caller rather\n * than passed here: it carries the class-name resolution that pairs with the\n * stylesheet emitted alongside the frame's output, which is the surface's\n * concern and not the document's. Generic in `TNode` so a helper can be\n * written against a narrowed node union while the runtime holds the erased form.\n */\nexport interface FrameDispatcher<TNode extends PrimitiveNode = PrimitiveNode> {\n /** Draws one node on the `snapshot` surface. `key` must be unique among its siblings. */\n renderSnapshot(node: TNode, key: string): ReactNode;\n /** The node's height in pixels; `0` when it is hidden from `snapshot` or its primitive declares no `metrics.snapshotHeight`. */\n estimateSnapshotHeight(node: TNode): number;\n}\n\n/**\n * What {@link Frame.wrap} is told about the composition it draws around.\n *\n * The body is withheld, and {@link bindFrame} copies only these fields into a\n * fresh value, so the surround cannot branch on a pack's node types.\n */\nexport interface FrameHeader {\n title?: string | undefined;\n subtitle?: string | undefined;\n /** The caller's preference, not a resolved palette. Use {@link FrameViewport.theme} to draw. */\n theme?: RenderTheme | undefined;\n}\n\n/** {@link FrameHeader} plus the body, for the sizing and validation hooks. */\nexport interface FrameComposition extends FrameHeader {\n /** Raw nodes, for measuring and checking only. {@link FrameBody} is what gets drawn. */\n body: PrimitiveNode[];\n}\n\n/**\n * Body nodes already rendered to elements, ready to be surrounded.\n *\n * Distinct from `Composition.body`, which is the raw {@link PrimitiveNode}\n * array a frame never sees.\n */\nexport type FrameBody = readonly ReactNode[];\n\n/**\n * A document a `snapshot` render can produce: its geometry, the surround it draws\n * around the body, and whatever it requires of a composition it is asked to\n * draw.\n *\n * A host registers frames with the runtime and picks one per render. That is\n * what lets one runtime serve a 760px card, a 1920x1080 slide, and a\n * host-branded variant of either from the same vocabulary — and what keeps a\n * vocabulary pack additive, since nothing about a primitive decides the frame.\n * A frame is named by the key a host registers it under, not by a field it\n * carries.\n */\nexport interface Frame<TTheme> {\n /** Width used when the caller passes none. */\n defaultWidth: number;\n /**\n * Palette per mode. Frame and palette vary independently — a branded card is\n * this geometry with a host's colors — so a host overrides one by spreading\n * this value rather than rebuilding anything.\n */\n theme: ThemePair<TTheme>;\n /**\n * Height for this body when the caller passes none, in the geometry this\n * document defines. Calling {@link FrameDispatcher.estimateSnapshotHeight} is\n * what makes a missing `metrics.snapshotHeight` size the frame short: that\n * method returns `0` for a node whose primitive declares none.\n */\n estimateHeight(\n composition: FrameComposition,\n dispatcher: FrameDispatcher\n ): number;\n /**\n * What this document requires of a body. A slide document's\n * exactly-one-`slideFrame` rule is the example.\n *\n * Returned rather than thrown so a caller can decide what to do with it, but\n * note where it is *not* checked: composition validation is frame-agnostic,\n * and has to be, because the same composition can be valid in one frame and\n * not another. Only the `snapshot` surface consults this, on the frame a render\n * actually names, and raises before drawing. A host that wants the answer\n * earlier asks the frame directly.\n */\n validateBody?(body: readonly PrimitiveNode[]): readonly string[];\n /**\n * Draws the surround around the already-rendered body nodes, including a\n * title header if this document wants one.\n *\n * Takes the nodes as an array rather than a single `ReactNode` so a frame\n * that draws no surround can return its one root element — image layout\n * starts from a single element, and an array or a fragment is not one.\n *\n * Declared property-style, so it is checked contravariantly in `TTheme` under\n * `strictFunctionTypes`. A method signature is bivariant, which would admit a\n * frame needing a richer theme into a slot typed for a narrower one, where it\n * would read a token nothing supplies.\n */\n wrap: (\n header: FrameHeader,\n body: FrameBody,\n viewport: FrameViewport<TTheme>\n ) => ReactNode;\n}\n\n/**\n * A {@link Frame} as the runtime stores it, with its theme resolved away.\n *\n * The erasure is a closure rather than a type parameter because the runtime\n * dispatches nodes through one inventory keyed by node type, which has no\n * single theme to name. A runtime's frames are homogeneous in `TTheme`, so the\n * palette is known where it is resolved and only the resolved result is stored.\n */\nexport interface BoundFrame {\n readonly defaultWidth: number;\n /** See {@link Frame.estimateHeight}. */\n estimateHeight(\n composition: FrameComposition,\n dispatcher: FrameDispatcher\n ): number;\n /** See {@link Frame.validateBody}; empty when this frame states no rule. */\n validateBody(body: readonly PrimitiveNode[]): readonly string[];\n /**\n * Resolves {@link Frame.theme} for `mode`, erased to `unknown` like the rest\n * of this type. Lets a caller hand the palette to a primitive's `env.theme`\n * without itself knowing `TTheme`.\n */\n resolveTheme(mode: RenderTheme | undefined): unknown;\n /** Renders the body and its surround at `viewport`'s geometry. */\n render(\n composition: FrameComposition,\n viewport: { width: number; height: number; mode: RenderTheme | undefined },\n dispatcher: FrameDispatcher\n ): ReactNode;\n /** One node, no surround. */\n renderNode(node: PrimitiveNode, dispatcher: FrameDispatcher): ReactNode;\n}\n\n/**\n * Erases a {@link Frame}'s `TTheme` into a {@link BoundFrame}, resolving the\n * palette per render and composing the generic body walk with the frame's own\n * surround.\n */\nexport const bindFrame = <TTheme>(frame: Frame<TTheme>): BoundFrame => {\n const themeFor = (mode: RenderTheme | undefined): TTheme =>\n mode === 'dark' ? frame.theme.dark : frame.theme.light;\n return {\n defaultWidth: frame.defaultWidth,\n estimateHeight: (composition, dispatcher) =>\n frame.estimateHeight(composition, dispatcher),\n validateBody: (body) => frame.validateBody?.(body) ?? [],\n resolveTheme: (mode) => themeFor(mode),\n render: (composition, viewport, dispatcher) => {\n const theme = themeFor(viewport.mode);\n const { title, subtitle, theme: mode } = composition;\n return frame.wrap(\n { title, subtitle, theme: mode },\n composition.body.map((node, index) =>\n dispatcher.renderSnapshot(node, `body-${index}`)\n ),\n { ...viewport, theme }\n );\n },\n renderNode: (node, dispatcher) =>\n dispatcher.renderSnapshot(node, node.type),\n };\n};\n"]}
|
package/dist/define/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { type BoundFrame, type Frame, type FrameBody, type FrameComposition, type FrameDispatcher, type FrameHeader, type FrameViewport, type ThemePair, bindFrame, } from './frame.js';
|
|
2
2
|
export { type MarkdownBlock, type MarkdownContent, type MarkdownInline, type MarkdownInlineInput, } from './markdown_content.js';
|
|
3
|
-
export { type
|
|
3
|
+
export { type ExampleNode, type NormalizedPrimitiveExample, type PrimitiveExample, exampleNodes, primitiveExamples, } from './primitive_example.js';
|
|
4
|
+
export { type PrimitiveIcon, ICON_VARS } from './primitive_icon.js';
|
|
5
|
+
export { type AnyPrimitiveDefinition, type DefaultPackTypes, type OptionalSurface, type PackTypes, type PrimitiveCatalogEntry, type PrimitiveChildRef, type PrimitiveDefinition, type PrimitiveMetrics, type PrimitiveNode, type PrimitiveRenderContext, type PrimitiveSchema, type PrimitiveStyleCollectionContext, type PrimitiveStyleCollector, type ReactContextArg, type Renderer, type Renderers, type RenderScope, type StyledRenderContext, type StyleHandle, type SurfaceMap, type ThemeTokenPath, type WithNodeFields, OPTIONAL_SURFACES, bodyNodeIdSchema, bodyNodeSurfacesSchema, definePrimitive, definePrimitiveFor, unresolvedBodyNodeSchema, validateWithSchema, } from './primitive_module.js';
|
|
4
6
|
export { type SlackAssetCollector, type SlackAssetRequest, } from './slack_assets.js';
|
|
5
7
|
export { type SlackActionElement, type SlackActionsBlock, type SlackBlock, type SlackButtonElement, type SlackCheckboxesElement, type SlackContextBlock, type SlackDividerBlock, type SlackFileReference, type SlackHeaderBlock, type SlackHeaderLevel, type SlackImageBlock, type SlackImageElement, type SlackMrkdwnTextObject, type SlackMultiStaticSelectElement, type SlackOptionGroup, type SlackOptionObject, type SlackOverflowElement, type SlackPlainTextObject, type SlackRadioButtonsElement, type SlackRawTextElement, type SlackRichTextBlock, type SlackRichTextBlockElement, type SlackRichTextInline, type SlackRichTextLink, type SlackRichTextList, type SlackRichTextPreformatted, type SlackRichTextQuote, type SlackRichTextSection, type SlackRichTextStyle, type SlackRichTextTag, type SlackRichTextText, type SlackSectionAccessory, type SlackSectionBlock, type SlackStaticSelectElement, type SlackTableBlock, type SlackTableCell, type SlackTableColumnSetting, type SlackTagColor, type SlackTextObject, type SlackVideoBlock, } from './slack_blocks.js';
|
|
6
8
|
export { declaredFieldsNote, formatZodIssues } from './zod_format.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/define/index.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,KAAK,UAAU,EACf,KAAK,KAAK,EACV,KAAK,SAAS,EACd,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,SAAS,GACV,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,mBAAmB,GACzB,MAA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E,eAAe,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/define/index.js
CHANGED
|
@@ -5,7 +5,9 @@
|
|
|
5
5
|
* 2.0.
|
|
6
6
|
*/
|
|
7
7
|
export { bindFrame, } from './frame.js';
|
|
8
|
-
export {
|
|
8
|
+
export { exampleNodes, primitiveExamples, } from './primitive_example.js';
|
|
9
|
+
export { ICON_VARS } from './primitive_icon.js';
|
|
10
|
+
export { OPTIONAL_SURFACES, bodyNodeIdSchema, bodyNodeSurfacesSchema, definePrimitive, definePrimitiveFor, unresolvedBodyNodeSchema, validateWithSchema, } from './primitive_module.js';
|
|
9
11
|
export { declaredFieldsNote, formatZodIssues } from './zod_format.js';
|
|
10
12
|
export { requiredString, z } from './zod_helpers.js';
|
|
11
13
|
//# sourceMappingURL=index.js.map
|
package/dist/define/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/define/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EASL,SAAS,GACV,MAAM,SAAS,CAAC;AAOjB,OAAO,EAuBL,gBAAgB,EAChB,sBAAsB,EACtB,eAAe,EACf,kBAAkB,EAClB,wBAAwB,EACxB,kBAAkB,GACnB,MAAM,oBAAoB,CAAC;AA+C5B,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,CAAC,EAAE,MAAM,eAAe,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 BoundFrame,\n type Frame,\n type FrameBody,\n type FrameComposition,\n type FrameDispatcher,\n type FrameHeader,\n type FrameViewport,\n type ThemePair,\n bindFrame,\n} from './frame';\nexport {\n type MarkdownBlock,\n type MarkdownContent,\n type MarkdownInline,\n type MarkdownInlineInput,\n} from './markdown_content';\nexport {\n type AnyPrimitiveDefinition,\n type DefaultPackTypes,\n type OptionalSurface,\n type PackTypes,\n type PrimitiveCatalogEntry,\n type PrimitiveChildRef,\n type PrimitiveDefinition,\n type PrimitiveMetrics,\n type PrimitiveNode,\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 ThemeTokenPath,\n type WithNodeFields,\n bodyNodeIdSchema,\n bodyNodeSurfacesSchema,\n definePrimitive,\n definePrimitiveFor,\n unresolvedBodyNodeSchema,\n validateWithSchema,\n} from './primitive_module';\nexport {\n type SlackAssetCollector,\n type SlackAssetRequest,\n} from './slack_assets';\nexport {\n type SlackActionElement,\n type SlackActionsBlock,\n type SlackBlock,\n type SlackButtonElement,\n type SlackCheckboxesElement,\n type SlackContextBlock,\n type SlackDividerBlock,\n type SlackFileReference,\n type SlackHeaderBlock,\n type SlackHeaderLevel,\n type SlackImageBlock,\n type SlackImageElement,\n type SlackMrkdwnTextObject,\n type SlackMultiStaticSelectElement,\n type SlackOptionGroup,\n type SlackOptionObject,\n type SlackOverflowElement,\n type SlackPlainTextObject,\n type SlackRadioButtonsElement,\n type SlackRawTextElement,\n type SlackRichTextBlock,\n type SlackRichTextBlockElement,\n type SlackRichTextInline,\n type SlackRichTextLink,\n type SlackRichTextList,\n type SlackRichTextPreformatted,\n type SlackRichTextQuote,\n type SlackRichTextSection,\n type SlackRichTextStyle,\n type SlackRichTextTag,\n type SlackRichTextText,\n type SlackSectionAccessory,\n type SlackSectionBlock,\n type SlackStaticSelectElement,\n type SlackTableBlock,\n type SlackTableCell,\n type SlackTableColumnSetting,\n type SlackTagColor,\n type SlackTextObject,\n type SlackVideoBlock,\n} from './slack_blocks';\nexport { declaredFieldsNote, formatZodIssues } from './zod_format';\nexport { requiredString, z } from './zod_helpers';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/define/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EASL,SAAS,GACV,MAAM,SAAS,CAAC;AAOjB,OAAO,EAIL,YAAY,EACZ,iBAAiB,GAClB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAsB,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAuBL,iBAAiB,EACjB,gBAAgB,EAChB,sBAAsB,EACtB,eAAe,EACf,kBAAkB,EAClB,wBAAwB,EACxB,kBAAkB,GACnB,MAAM,oBAAoB,CAAC;AA+C5B,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,CAAC,EAAE,MAAM,eAAe,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 BoundFrame,\n type Frame,\n type FrameBody,\n type FrameComposition,\n type FrameDispatcher,\n type FrameHeader,\n type FrameViewport,\n type ThemePair,\n bindFrame,\n} from './frame';\nexport {\n type MarkdownBlock,\n type MarkdownContent,\n type MarkdownInline,\n type MarkdownInlineInput,\n} from './markdown_content';\nexport {\n type ExampleNode,\n type NormalizedPrimitiveExample,\n type PrimitiveExample,\n exampleNodes,\n primitiveExamples,\n} from './primitive_example';\nexport { type PrimitiveIcon, ICON_VARS } from './primitive_icon';\nexport {\n type AnyPrimitiveDefinition,\n type DefaultPackTypes,\n type OptionalSurface,\n type PackTypes,\n type PrimitiveCatalogEntry,\n type PrimitiveChildRef,\n type PrimitiveDefinition,\n type PrimitiveMetrics,\n type PrimitiveNode,\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 ThemeTokenPath,\n type WithNodeFields,\n OPTIONAL_SURFACES,\n bodyNodeIdSchema,\n bodyNodeSurfacesSchema,\n definePrimitive,\n definePrimitiveFor,\n unresolvedBodyNodeSchema,\n validateWithSchema,\n} from './primitive_module';\nexport {\n type SlackAssetCollector,\n type SlackAssetRequest,\n} from './slack_assets';\nexport {\n type SlackActionElement,\n type SlackActionsBlock,\n type SlackBlock,\n type SlackButtonElement,\n type SlackCheckboxesElement,\n type SlackContextBlock,\n type SlackDividerBlock,\n type SlackFileReference,\n type SlackHeaderBlock,\n type SlackHeaderLevel,\n type SlackImageBlock,\n type SlackImageElement,\n type SlackMrkdwnTextObject,\n type SlackMultiStaticSelectElement,\n type SlackOptionGroup,\n type SlackOptionObject,\n type SlackOverflowElement,\n type SlackPlainTextObject,\n type SlackRadioButtonsElement,\n type SlackRawTextElement,\n type SlackRichTextBlock,\n type SlackRichTextBlockElement,\n type SlackRichTextInline,\n type SlackRichTextLink,\n type SlackRichTextList,\n type SlackRichTextPreformatted,\n type SlackRichTextQuote,\n type SlackRichTextSection,\n type SlackRichTextStyle,\n type SlackRichTextTag,\n type SlackRichTextText,\n type SlackSectionAccessory,\n type SlackSectionBlock,\n type SlackStaticSelectElement,\n type SlackTableBlock,\n type SlackTableCell,\n type SlackTableColumnSetting,\n type SlackTagColor,\n type SlackTextObject,\n type SlackVideoBlock,\n} from './slack_blocks';\nexport { declaredFieldsNote, formatZodIssues } from './zod_format';\nexport { requiredString, z } from './zod_helpers';\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { PrimitiveNode } from '../composition/node.js';
|
|
2
|
+
/** A published example with a name hosts can list it by. */
|
|
3
|
+
export interface PrimitiveExample<TNode extends PrimitiveNode = PrimitiveNode> {
|
|
4
|
+
/** Short and unique within the primitive, such as `Warning tone`. */
|
|
5
|
+
name: string;
|
|
6
|
+
/** What the example demonstrates. */
|
|
7
|
+
description?: string;
|
|
8
|
+
node: TNode;
|
|
9
|
+
/** Never set: an entry is a bare node exactly when it has a `type`. */
|
|
10
|
+
type?: never;
|
|
11
|
+
}
|
|
12
|
+
/** An entry of `examples` read as one shape; `name` is absent for a bare node. */
|
|
13
|
+
export interface NormalizedPrimitiveExample<TNode extends PrimitiveNode = PrimitiveNode> {
|
|
14
|
+
name?: string;
|
|
15
|
+
description?: string;
|
|
16
|
+
node: TNode;
|
|
17
|
+
}
|
|
18
|
+
/** The node type an `examples` entry holds. */
|
|
19
|
+
export type ExampleNode<TEntry> = TEntry extends PrimitiveExample<infer TNode> ? TNode : TEntry;
|
|
20
|
+
interface WithExamples {
|
|
21
|
+
readonly examples: readonly (PrimitiveNode | PrimitiveExample)[];
|
|
22
|
+
}
|
|
23
|
+
/** Distributes over a union of definitions, so a mixed registry keeps every node type. */
|
|
24
|
+
type NodeOf<TDefinition extends WithExamples> = ExampleNode<TDefinition['examples'][number]>;
|
|
25
|
+
/** A definition's examples, bare or named, as {@link NormalizedPrimitiveExample}s. */
|
|
26
|
+
export declare const primitiveExamples: <TDefinition extends WithExamples>({ examples, }: TDefinition) => NormalizedPrimitiveExample<NodeOf<TDefinition>>[];
|
|
27
|
+
/** A definition's example nodes, without names. */
|
|
28
|
+
export declare const exampleNodes: <TDefinition extends WithExamples>({ examples, }: TDefinition) => NodeOf<TDefinition>[];
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=primitive_example.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"primitive_example.d.ts","sourceRoot":"","sources":["../../src/define/primitive_example.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,4DAA4D;AAC5D,MAAM,WAAW,gBAAgB,CAAC,KAAK,SAAS,aAAa,GAAG,aAA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