@elastic/isomer-sdk 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE.txt +0 -286
- package/README.md +13 -2
- package/THIRD_PARTY_LICENSES.md +1 -885
- package/dist/author/authored_fields.d.ts +93 -18
- package/dist/author/authored_fields.d.ts.map +1 -1
- package/dist/author/authored_fields.js +63 -43
- 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 +66 -0
- package/dist/author/authoring_input.js.map +1 -0
- package/dist/author/authoring_model.d.ts +33 -0
- package/dist/author/authoring_model.d.ts.map +1 -0
- package/dist/author/authoring_model.js +142 -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 +288 -0
- package/dist/author/declarations.js.map +1 -0
- package/dist/author/index.d.ts +4 -1
- package/dist/author/index.d.ts.map +1 -1
- package/dist/author/index.js +4 -1
- package/dist/author/index.js.map +1 -1
- package/dist/author/jsx_shim.d.ts +50 -30
- package/dist/author/jsx_shim.d.ts.map +1 -1
- package/dist/author/jsx_shim.js +146 -138
- package/dist/author/jsx_shim.js.map +1 -1
- package/dist/author/print_jsx.d.ts +19 -0
- package/dist/author/print_jsx.d.ts.map +1 -0
- package/dist/author/print_jsx.js +372 -0
- package/dist/author/print_jsx.js.map +1 -0
- package/dist/author/prompt.d.ts +2 -2
- package/dist/author/prompt.d.ts.map +1 -1
- package/dist/author/prompt.js +7 -2
- package/dist/author/prompt.js.map +1 -1
- package/dist/author/schema_to_typescript.d.ts +37 -0
- package/dist/author/schema_to_typescript.d.ts.map +1 -0
- package/dist/author/schema_to_typescript.js +289 -0
- package/dist/author/schema_to_typescript.js.map +1 -0
- package/dist/cjs/author/authored_fields.js +68 -47
- package/dist/cjs/author/authored_fields.js.map +1 -1
- package/dist/cjs/author/authoring_input.js +70 -0
- package/dist/cjs/author/authoring_input.js.map +1 -0
- package/dist/cjs/author/authoring_model.js +149 -0
- package/dist/cjs/author/authoring_model.js.map +1 -0
- package/dist/cjs/author/declarations.js +292 -0
- package/dist/cjs/author/declarations.js.map +1 -0
- package/dist/cjs/author/index.js +10 -1
- package/dist/cjs/author/index.js.map +1 -1
- package/dist/cjs/author/jsx_shim.js +148 -140
- package/dist/cjs/author/jsx_shim.js.map +1 -1
- package/dist/cjs/author/print_jsx.js +378 -0
- package/dist/cjs/author/print_jsx.js.map +1 -0
- package/dist/cjs/author/prompt.js +7 -2
- package/dist/cjs/author/prompt.js.map +1 -1
- package/dist/cjs/author/schema_to_typescript.js +298 -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 +2 -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/composition/structured_value.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 +24 -7
- 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 +8 -2
- package/dist/cjs/entries/index.js.map +1 -1
- package/dist/cjs/entries/markdown.js +2 -1
- package/dist/cjs/entries/markdown.js.map +1 -1
- package/dist/cjs/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 +2 -1
- package/dist/cjs/pack/index.js.map +1 -1
- package/dist/cjs/pack/primitive_pack.js +27 -5
- 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/format_number.js +2 -1
- package/dist/cjs/render/format_number.js.map +1 -1
- package/dist/cjs/render/html/envelope.js +12 -6
- package/dist/cjs/render/html/envelope.js.map +1 -1
- package/dist/cjs/render/layout_check.js.map +1 -1
- package/dist/cjs/render/markdown/builder.js +18 -8
- package/dist/cjs/render/markdown/builder.js.map +1 -1
- package/dist/cjs/render/markdown/format.js +70 -30
- package/dist/cjs/render/markdown/format.js.map +1 -1
- package/dist/cjs/render/markdown/host_tags.js +67 -0
- package/dist/cjs/render/markdown/host_tags.js.map +1 -0
- package/dist/cjs/render/markdown/index.js +3 -1
- package/dist/cjs/render/markdown/index.js.map +1 -1
- package/dist/cjs/render/markdown/split.js +325 -0
- package/dist/cjs/render/markdown/split.js.map +1 -0
- package/dist/cjs/render/primitive_dispatch.js +11 -25
- package/dist/cjs/render/primitive_dispatch.js.map +1 -1
- package/dist/cjs/render/react/content.js +3 -1
- package/dist/cjs/render/react/content.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 +172 -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/json_schema.js +10 -3
- package/dist/cjs/validate/json_schema.js.map +1 -1
- package/dist/cjs/validate/url.js +2 -1
- package/dist/cjs/validate/url.js.map +1 -1
- package/dist/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 +2 -0
- package/dist/composition/error.d.ts.map +1 -1
- package/dist/composition/error.js +2 -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/composition/structured_value.d.ts +3 -3
- package/dist/composition/structured_value.d.ts.map +1 -1
- package/dist/composition/structured_value.js.map +1 -1
- package/dist/define/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 +45 -24
- package/dist/define/primitive_module.d.ts.map +1 -1
- package/dist/define/primitive_module.js +24 -7
- 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 +3 -3
- package/dist/entries/index.js.map +1 -1
- package/dist/entries/markdown.d.ts +1 -1
- package/dist/entries/markdown.d.ts.map +1 -1
- package/dist/entries/markdown.js +1 -1
- package/dist/entries/markdown.js.map +1 -1
- package/dist/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 +2 -2
- package/dist/pack/index.d.ts.map +1 -1
- package/dist/pack/index.js +2 -2
- package/dist/pack/index.js.map +1 -1
- package/dist/pack/primitive_pack.d.ts +14 -3
- package/dist/pack/primitive_pack.d.ts.map +1 -1
- package/dist/pack/primitive_pack.js +25 -4
- 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/format_number.d.ts.map +1 -1
- package/dist/render/format_number.js +2 -1
- package/dist/render/format_number.js.map +1 -1
- package/dist/render/html/envelope.d.ts +3 -3
- package/dist/render/html/envelope.js +12 -6
- 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 +5 -4
- package/dist/render/markdown/builder.d.ts.map +1 -1
- package/dist/render/markdown/builder.js +16 -7
- package/dist/render/markdown/builder.js.map +1 -1
- package/dist/render/markdown/format.d.ts +9 -0
- package/dist/render/markdown/format.d.ts.map +1 -1
- package/dist/render/markdown/format.js +67 -31
- package/dist/render/markdown/format.js.map +1 -1
- package/dist/render/markdown/host_tags.d.ts +14 -0
- package/dist/render/markdown/host_tags.d.ts.map +1 -0
- package/dist/render/markdown/host_tags.js +63 -0
- package/dist/render/markdown/host_tags.js.map +1 -0
- package/dist/render/markdown/index.d.ts +1 -0
- package/dist/render/markdown/index.d.ts.map +1 -1
- package/dist/render/markdown/index.js +1 -0
- package/dist/render/markdown/index.js.map +1 -1
- package/dist/render/markdown/split.d.ts +32 -0
- package/dist/render/markdown/split.d.ts.map +1 -0
- package/dist/render/markdown/split.js +321 -0
- package/dist/render/markdown/split.js.map +1 -0
- package/dist/render/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/react/content.d.ts +1 -1
- package/dist/render/react/content.d.ts.map +1 -1
- package/dist/render/react/content.js +3 -1
- package/dist/render/react/content.js.map +1 -1
- package/dist/render/slack/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 +169 -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/json_schema.d.ts.map +1 -1
- package/dist/validate/json_schema.js +10 -3
- package/dist/validate/json_schema.js.map +1 -1
- package/dist/validate/url.d.ts.map +1 -1
- package/dist/validate/url.js +2 -1
- package/dist/validate/url.js.map +1 -1
- package/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
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
4
|
+
* or more contributor license agreements. Licensed under the Elastic License
|
|
5
|
+
* 2.0; you may not use this file except in compliance with the Elastic License
|
|
6
|
+
* 2.0.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.exampleNodes = exports.primitiveExamples = void 0;
|
|
10
|
+
const isPrimitiveExample = (entry) => !('type' in entry) && 'node' in entry;
|
|
11
|
+
const normalize = (entry) => {
|
|
12
|
+
if (!isPrimitiveExample(entry)) {
|
|
13
|
+
return { node: entry };
|
|
14
|
+
}
|
|
15
|
+
const { name, description, node } = entry;
|
|
16
|
+
return description === undefined
|
|
17
|
+
? { name, node }
|
|
18
|
+
: { name, description, node };
|
|
19
|
+
};
|
|
20
|
+
/** A definition's examples, bare or named, as {@link NormalizedPrimitiveExample}s. */
|
|
21
|
+
const primitiveExamples = ({ examples, }) => examples.map(normalize);
|
|
22
|
+
exports.primitiveExamples = primitiveExamples;
|
|
23
|
+
/** A definition's example nodes, without names. */
|
|
24
|
+
const exampleNodes = ({ examples, }) => examples.map((entry) => normalize(entry).node);
|
|
25
|
+
exports.exampleNodes = exampleNodes;
|
|
26
|
+
//# sourceMappingURL=primitive_example.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"primitive_example.js","sourceRoot":"","sources":["../../../src/define/primitive_example.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAqCH,MAAM,kBAAkB,GAAG,CACzB,KAAuC,EACZ,EAAE,CAAC,CAAC,CAAC,MAAM,IAAI,KAAK,CAAC,IAAI,MAAM,IAAI,KAAK,CAAC;AAEtE,MAAM,SAAS,GAAG,CAChB,KAAuC,EACX,EAAE;IAC9B,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC/B,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;IACzB,CAAC;IACD,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;IAC1C,OAAO,WAAW,KAAK,SAAS;QAC9B,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE;QAChB,CAAC,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;AAClC,CAAC,CAAC;AAEF,sFAAsF;AAC/E,MAAM,iBAAiB,GAAG,CAAmC,EAClE,QAAQ,GACI,EAAqD,EAAE,CACnE,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAsD,CAAC;AAHlE,QAAA,iBAAiB,qBAGiD;AAE/E,mDAAmD;AAC5C,MAAM,YAAY,GAAG,CAAmC,EAC7D,QAAQ,GACI,EAAyB,EAAE,CACvC,QAAQ,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,IAAI,CAA0B,CAAC;AAH7D,QAAA,YAAY,gBAGiD","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nimport type { PrimitiveNode } from '../composition/node';\n\n/** A published example with a name hosts can list it by. */\nexport interface PrimitiveExample<TNode extends PrimitiveNode = PrimitiveNode> {\n /** Short and unique within the primitive, such as `Warning tone`. */\n name: string;\n /** What the example demonstrates. */\n description?: string;\n node: TNode;\n /** Never set: an entry is a bare node exactly when it has a `type`. */\n type?: never;\n}\n\n/** An entry of `examples` read as one shape; `name` is absent for a bare node. */\nexport interface NormalizedPrimitiveExample<\n TNode extends PrimitiveNode = PrimitiveNode,\n> {\n name?: string;\n description?: string;\n node: TNode;\n}\n\n/** The node type an `examples` entry holds. */\nexport type ExampleNode<TEntry> =\n TEntry extends PrimitiveExample<infer TNode> ? TNode : TEntry;\n\ninterface WithExamples {\n readonly examples: readonly (PrimitiveNode | PrimitiveExample)[];\n}\n\n/** Distributes over a union of definitions, so a mixed registry keeps every node type. */\ntype NodeOf<TDefinition extends WithExamples> = ExampleNode<\n TDefinition['examples'][number]\n>;\n\nconst isPrimitiveExample = (\n entry: PrimitiveNode | PrimitiveExample\n): entry is PrimitiveExample => !('type' in entry) && 'node' in entry;\n\nconst normalize = (\n entry: PrimitiveNode | PrimitiveExample\n): NormalizedPrimitiveExample => {\n if (!isPrimitiveExample(entry)) {\n return { node: entry };\n }\n const { name, description, node } = entry;\n return description === undefined\n ? { name, node }\n : { name, description, node };\n};\n\n/** A definition's examples, bare or named, as {@link NormalizedPrimitiveExample}s. */\nexport const primitiveExamples = <TDefinition extends WithExamples>({\n examples,\n}: TDefinition): NormalizedPrimitiveExample<NodeOf<TDefinition>>[] =>\n examples.map(normalize) as NormalizedPrimitiveExample<NodeOf<TDefinition>>[];\n\n/** A definition's example nodes, without names. */\nexport const exampleNodes = <TDefinition extends WithExamples>({\n examples,\n}: TDefinition): NodeOf<TDefinition>[] =>\n examples.map((entry) => normalize(entry).node) as NodeOf<TDefinition>[];\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
4
|
+
* or more contributor license agreements. Licensed under the Elastic License
|
|
5
|
+
* 2.0; you may not use this file except in compliance with the Elastic License
|
|
6
|
+
* 2.0.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.ICON_VARS = void 0;
|
|
10
|
+
/** The colour slots an icon may paint with, which a host sets per theme and mode. */
|
|
11
|
+
exports.ICON_VARS = [
|
|
12
|
+
'--isomer-icon-accent',
|
|
13
|
+
'--isomer-icon-bg',
|
|
14
|
+
'--isomer-icon-fg',
|
|
15
|
+
'--isomer-icon-muted',
|
|
16
|
+
];
|
|
17
|
+
//# sourceMappingURL=primitive_icon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"primitive_icon.js","sourceRoot":"","sources":["../../../src/define/primitive_icon.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAWH,qFAAqF;AACxE,QAAA,SAAS,GAAG;IACvB,sBAAsB;IACtB,kBAAkB;IAClB,kBAAkB;IAClB,qBAAqB;CACb,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 * A 16×16 glyph a host shows beside the primitive: static SVG, inlinable without a renderer.\n *\n * Colours go through {@link ICON_VARS}, optionally with a `currentColor` or hex fallback; `assertPackIconsValid` from `./testing` enforces the rules.\n */\nexport interface PrimitiveIcon {\n svg: string;\n}\n\n/** The colour slots an icon may paint with, which a host sets per theme and mode. */\nexport const ICON_VARS = [\n '--isomer-icon-accent',\n '--isomer-icon-bg',\n '--isomer-icon-fg',\n '--isomer-icon-muted',\n] as const;\n"]}
|
|
@@ -6,12 +6,23 @@
|
|
|
6
6
|
* 2.0.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.definePrimitiveFor = exports.definePrimitive = exports.unresolvedBodyNodeSchema = exports.bodyNodeSurfacesSchema = exports.bodyNodeIdSchema = exports.validateWithSchema = void 0;
|
|
9
|
+
exports.definePrimitiveFor = exports.definePrimitive = exports.unresolvedBodyNodeSchema = exports.bodyNodeSurfacesSchema = exports.bodyNodeIdSchema = exports.validateWithSchema = exports.OPTIONAL_SURFACES = void 0;
|
|
10
10
|
const zod_1 = require("zod");
|
|
11
11
|
const body_node_base_1 = require("../composition/body_node_base");
|
|
12
12
|
const error_1 = require("../composition/error");
|
|
13
13
|
const zod_format_1 = require("./zod_format");
|
|
14
14
|
const zod_helpers_1 = require("./zod_helpers");
|
|
15
|
+
/**
|
|
16
|
+
* The surface a pack may declare beyond the mandatory three.
|
|
17
|
+
*
|
|
18
|
+
* Only `slack`, and even that stays optional per primitive: the dispatcher
|
|
19
|
+
* converts the mandatory markdown to Block Kit, so a missing Slack renderer
|
|
20
|
+
* degrades rather than disappearing. `snapshot` is not here because no primitive
|
|
21
|
+
* implements it — the surface reuses `react`.
|
|
22
|
+
*/
|
|
23
|
+
exports.OPTIONAL_SURFACES = [
|
|
24
|
+
'slack',
|
|
25
|
+
];
|
|
15
26
|
/** Parses `node` against `schema`, appending path-prefixed messages to `errors`. */
|
|
16
27
|
const validateWithSchema = (schema, node, path, errors) => {
|
|
17
28
|
const result = schema.safeParse(node, { reportInput: true });
|
|
@@ -24,8 +35,8 @@ exports.validateWithSchema = validateWithSchema;
|
|
|
24
35
|
exports.bodyNodeIdSchema = (0, zod_helpers_1.requiredString)('must be a non-empty string');
|
|
25
36
|
/** The `surfaces` allowlist on a node. Absent means every surface; empty is rejected. */
|
|
26
37
|
exports.bodyNodeSurfacesSchema = zod_1.z
|
|
27
|
-
.array(zod_1.z.enum(body_node_base_1.
|
|
28
|
-
error: () => (0, zod_format_1.oneOf)(body_node_base_1.
|
|
38
|
+
.array(zod_1.z.enum(body_node_base_1.SURFACE_NAMES, {
|
|
39
|
+
error: () => (0, zod_format_1.oneOf)(body_node_base_1.SURFACE_NAMES),
|
|
29
40
|
}))
|
|
30
41
|
.min(1, { error: 'must contain at least one surface' });
|
|
31
42
|
/**
|
|
@@ -51,10 +62,14 @@ exports.unresolvedBodyNodeSchema = zod_1.z.looseObject({
|
|
|
51
62
|
* {@link PackTypes}, so each primitive names only `TNode`.
|
|
52
63
|
*/
|
|
53
64
|
const definePrimitive = (definition) => {
|
|
54
|
-
const { schemaFor } = definition;
|
|
65
|
+
const { schemaFor, schema, catalog } = definition;
|
|
66
|
+
const described = catalog.description === undefined ? schema.description : undefined;
|
|
55
67
|
return {
|
|
56
68
|
...definition,
|
|
57
|
-
|
|
69
|
+
...(described === undefined
|
|
70
|
+
? {}
|
|
71
|
+
: { catalog: { ...catalog, description: described } }),
|
|
72
|
+
schema: withNodeFields(schema),
|
|
58
73
|
// Both forms get the node fields, or a container would accept `id` and
|
|
59
74
|
// `surfaces` standalone and reject them inside a composition.
|
|
60
75
|
...(schemaFor
|
|
@@ -87,11 +102,13 @@ const NODE_FIELDS = {
|
|
|
87
102
|
const isNodeField = (schema) => {
|
|
88
103
|
let current = schema;
|
|
89
104
|
while (current && typeof current === 'object') {
|
|
90
|
-
if (Object.hasOwn(current, NODE_FIELD))
|
|
105
|
+
if (Object.hasOwn(current, NODE_FIELD)) {
|
|
91
106
|
return true;
|
|
107
|
+
}
|
|
92
108
|
const { def } = current;
|
|
93
|
-
if (def?.type !== 'optional')
|
|
109
|
+
if (def?.type !== 'optional') {
|
|
94
110
|
return false;
|
|
111
|
+
}
|
|
95
112
|
current = def.innerType;
|
|
96
113
|
}
|
|
97
114
|
return false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"primitive_module.js","sourceRoot":"","sources":["../../../src/define/primitive_module.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAGH,6BAAsD;AAGtD,kEAIuC;AACvC,gDAAuE;AAOvE,6CAAsD;AACtD,+CAA+C;AAma/C,oFAAoF;AAC7E,MAAM,kBAAkB,GAAG,CAChC,MAAuB,EACvB,IAAa,EACb,IAAY,EACZ,MAAyB,EACnB,EAAE;IACR,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7D,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,CAAC,IAAI,CAAC,GAAG,IAAA,4BAAe,EAAC,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;IAC7D,CAAC;AACH,CAAC,CAAC;AAVW,QAAA,kBAAkB,sBAU7B;AAEF,kEAAkE;AACrD,QAAA,gBAAgB,GAAG,IAAA,4BAAc,EAAC,4BAA4B,CAAC,CAAC;AAE7E,yFAAyF;AAC5E,QAAA,sBAAsB,GAAG,OAAC;KACpC,KAAK,CACJ,OAAC,CAAC,IAAI,CAAC,mCAAqD,EAAE;IAC5D,KAAK,EAAE,GAAG,EAAE,CAAC,IAAA,kBAAK,EAAC,mCAAkB,CAAC;CACvC,CAAC,CACH;KACA,GAAG,CAAC,CAAC,EAAE,EAAE,KAAK,EAAE,mCAAmC,EAAE,CAAC,CAAC;AAE1D;;;;;;;;;GASG;AACU,QAAA,wBAAwB,GAAG,OAAC,CAAC,WAAW,CAAC;IACpD,IAAI,EAAE,IAAA,4BAAc,EAAC,4BAA4B,CAAC;CACnD,CAAC,CAAC;AAEH;;;;;;;;GAQG;AACI,MAAM,eAAe,GAAG,CAK7B,UAAkD,EACM,EAAE;IAC1D,MAAM,EAAE,SAAS,EAAE,GAAG,UAAU,CAAC;IACjC,OAAO;QACL,GAAG,UAAU;QACb,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,MAAM,CAAC;QACzC,uEAAuE;QACvE,8DAA8D;QAC9D,GAAG,CAAC,SAAS;YACX,CAAC,CAAC;gBACE,SAAS,EAAE,CAAC,cAAgC,EAAE,EAAE,CAC9C,cAAc,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;aAC5C;YACH,CAAC,CAAC,EAAE,CAAC;KACR,CAAC;AACJ,CAAC,CAAC;AApBW,QAAA,eAAe,mBAoB1B;AAEF;;;;;;;GAOG;AACI,MAAM,kBAAkB,GAC7B,GAAwB,EAAE,CAC1B,CAIE,UAAkD,EACM,EAAE,CAC1D,IAAA,uBAAe,EAAoB,UAAU,CAAC,CAAC;AARtC,QAAA,kBAAkB,sBAQoB;AAiBnD,0EAA0E;AAC1E,gFAAgF;AAChF,8BAA8B;AAC9B,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC;AAE3D,MAAM,SAAS,GAAG,CAAoB,MAAS,EAAK,EAAE,CACpD,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,UAAU,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAE7D,MAAM,WAAW,GAAG;IAClB,EAAE,EAAE,SAAS,CAAC,wBAAgB,CAAC,QAAQ,EAAE,CAAC;IAC1C,QAAQ,EAAE,SAAS,CAAC,8BAAsB,CAAC,QAAQ,EAAE,CAAC;CACvD,CAAC;AAEF,MAAM,WAAW,GAAG,CAAC,MAAe,EAAW,EAAE;IAC/C,IAAI,OAAO,GAAG,MAAM,CAAC;IACrB,OAAO,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAC9C,IAAI,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC;YAAE,OAAO,IAAI,CAAC;QACpD,MAAM,EAAE,GAAG,EAAE,GAAG,OAEf,CAAC;QACF,IAAI,GAAG,EAAE,IAAI,KAAK,UAAU;YAAE,OAAO,KAAK,CAAC;QAC3C,OAAO,GAAG,GAAG,CAAC,SAAS,CAAC;IAC1B,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,MAAM,cAAc,GAAG,CACrB,MAAe,EACU,EAAE;IAC3B,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,IAAI,CAC5C,CAAC,KAAK,EAAE,EAAE,CACR,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAC1E,CAAC;IACF,IAAI,QAAQ,EAAE,CAAC;QACb,MAAM,IAAI,mBAAW,CACnB,0BAAkB,CAAC,mBAAmB,EACtC,wDAAwD,QAAQ,6BAA6B,CAC9F,CAAC;IACJ,CAAC;IACD,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IAC5C,OAAO,CACL,MAAM,CAAC,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,QAAQ,CACtC,CAAC;AAC/B,CAAC,CAAC","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nimport type { ReactNode } from 'react';\nimport { z, type ZodObject, type ZodType } from 'zod';\n\nimport type { ActionEventRef } from '../composition/action_event';\nimport {\n BODY_NODE_SURFACES,\n type ChildNodeRef,\n type SurfaceName,\n} from '../composition/body_node_base';\nimport { ISOMER_ERROR_CODES, IsomerError } from '../composition/error';\nimport type { PrimitiveNode } from '../composition/node';\nimport type { ValidationError } from '../composition/validation_error';\n\nimport type { MarkdownContent } from './markdown_content';\nimport type { SlackAssetCollector } from './slack_assets';\nimport type { SlackBlock } from './slack_blocks';\nimport { formatZodIssues, oneOf } from './zod_format';\nimport { requiredString } from './zod_helpers';\n\nexport type { PrimitiveNode };\n\n/**\n * A primitive's entry in the catalog the authoring prompt is built from.\n *\n * Written for the model rather than for a developer: `useWhen` and `avoidWhen`\n * are what steer it away from reaching for the wrong primitive.\n */\nexport interface PrimitiveCatalogEntry {\n type: string;\n /** One line on what the primitive is for, in the model's voice. */\n purpose: string;\n /** Situations that call for this primitive. Phrase each as a user intent, not a shape. */\n useWhen: string[];\n /** Situations that look like a fit but are not, naming the primitive to reach for instead. */\n avoidWhen: string[];\n /** A node literal the authoring prompt inlines under this primitive. */\n example: unknown;\n}\n\n/** A style a renderer asks for by name, resolved to a class by the host's adapter. */\nexport interface StyleHandle {\n /** Stable lookup key. The adapter's map is keyed on this. */\n key: string;\n /** Debug-facing label, which an adapter may fold into a generated class name. */\n readableName: string;\n}\n\n/** Dotted path into a pack's theme tokens, e.g. `colors.text.subdued`. */\nexport type ThemeTokenPath = string;\n\n/**\n * The sdk's own render context, and {@link DefaultPackTypes.context}.\n *\n * A pack with real theme tokens or a richer style-handle type declares its\n * own context in its {@link PackTypes}; {@link StyledRenderContext} is the\n * sdk's own extension. The bag is what lets a pack narrow without\n * re-declaring everything that mentions a context.\n */\nexport interface PrimitiveRenderContext {\n /**\n * The progressive enhancements this render may assume, by id. A set rather\n * than a field per feature so adding an enhancement costs no plumbing:\n * containers forward the whole context, and a renderer asks\n * `context.enhancements?.has('tableSort')`.\n *\n * Empty or absent is the baseline every host can render, so a renderer must\n * still answer the question on its own. See `docs/rendering.md`.\n */\n enhancements?: ReadonlySet<string>;\n /** Turns on `nodeAnchor` outside an HTML surface render, on the React and `svg` surfaces; inside one, the surface decides. */\n anchors?: boolean;\n /** Raises an interaction for the host to route. Absent means render non-interactively. */\n onEvent?: (event: ActionEventRef) => void;\n}\n\n/**\n * The render-context argument, optional only when omitting it is sound.\n *\n * The sdk's own {@link PrimitiveRenderContext} has no required field, so `{}`\n * is a complete value and a caller may leave it out. A pack that narrows the\n * context with a required member makes the argument mandatory.\n */\nexport type ReactContextArg<TContext> =\n Record<string, never> extends TContext\n ? [context?: TContext]\n : [context: TContext];\n\n/**\n * {@link PrimitiveRenderContext} plus the CSS-in-JS hooks an HTML style adapter\n * supplies. A pack that styles differently uses its own `TContext` instead.\n */\nexport interface StyledRenderContext extends PrimitiveRenderContext {\n /** Resolves handles to a `className`. Absent means the host supplies no styling. */\n resolveClassName?: (...handles: StyleHandle[]) => string;\n /** Resolves a theme token to a CSS variable reference. Absent means inline the literal value. */\n cssVarRef?: (path: ThemeTokenPath) => `var(--${string})`;\n}\n\n/** Passed to a primitive's style collector so it can vary CSS by layout mode. */\nexport interface PrimitiveStyleCollectionContext {\n /** The render fills its container rather than sitting at a fixed width. */\n fluid?: boolean;\n}\n\n/** A pack's collected styles, opaque to the SDK. */\nexport type PrimitiveStyleCollector = object;\n\n/**\n * The types a pack binds once and writes every primitive against: the palette\n * its frames supply, the context its `react` renderers receive, the collector\n * its `collectStyles` hooks mutate, and the Slack payload and collector types.\n *\n * Extend {@link DefaultPackTypes} and narrow only what the pack needs:\n *\n * ```ts\n * interface SlidesPackTypes extends DefaultPackTypes {\n * theme: SlideTheme;\n * context: SlideRenderContext;\n * }\n * ```\n */\nexport interface PackTypes {\n theme: unknown;\n context: unknown;\n collector: PrimitiveStyleCollector;\n slackBlock: unknown;\n slackCollector: unknown;\n}\n\n/** {@link PackTypes} as the sdk itself binds them, and the default everywhere. */\nexport interface DefaultPackTypes extends PackTypes {\n theme: unknown;\n context: PrimitiveRenderContext;\n collector: PrimitiveStyleCollector;\n slackBlock: SlackBlock;\n slackCollector: SlackAssetCollector;\n}\n\n/**\n * Each surface's renderer signature: the env bag it receives beyond the node,\n * and what it returns.\n *\n * Written out per surface rather than derived through an indexed access. A bag\n * is additive: a new extra on a surface is not an arity break. {@link Renderer}\n * indexes this table for the dispatcher cast; {@link Renderers} does not.\n */\nexport interface SurfaceMap<T extends PackTypes = DefaultPackTypes> {\n react: {\n env: {\n context: T['context'];\n scope: RenderScope<T>;\n /**\n * The frame's resolved palette, when this render is reached through the\n * `svg` surface. A bare `react`/`html` render has no {@link Frame} to\n * resolve one from, so it is absent there — a pack that needs a\n * literal color outside `svg` still goes through `context`.\n */\n theme?: T['theme'];\n };\n output: ReactNode;\n };\n /**\n * Identical to `react`, and served by the same renderer: an image backend\n * lays out the pack's DOM tree and stylesheet rather than a second tree\n * authored for it. The surface stays separate so a node can be hidden from\n * images alone, and so a {@link Frame} has something to draw inside.\n */\n svg: {\n env: {\n context: T['context'];\n scope: RenderScope<T>;\n /** The frame's resolved palette for this render's mode; see `react.env.theme`. */\n theme?: T['theme'];\n };\n output: ReactNode;\n };\n text: {\n env: {\n scope: RenderScope<T>;\n };\n output: string;\n };\n /** A string is printed as written; content from `md` is escaped where it lands. */\n markdown: {\n env: {\n scope: RenderScope<T>;\n };\n output: string | MarkdownContent;\n };\n /**\n * Returns one payload or several, so a primitive need not wrap a single\n * payload in an array.\n */\n slack: {\n env: {\n collector?: T['slackCollector'];\n scope: RenderScope<T>;\n };\n output: T['slackBlock'] | readonly T['slackBlock'][];\n };\n}\n\n/**\n * The dispatcher a renderer is given so a container can recurse into a child\n * owned by another pack. Erased to {@link PrimitiveNode}: a heterogeneous\n * inventory has no single node type to name.\n *\n * Passed as `scope` on every renderer's env bag. The dispatcher's own named\n * methods stay positional.\n */\nexport interface RenderScope<T extends PackTypes = DefaultPackTypes> {\n readonly definitions: readonly AnyPrimitiveDefinition[];\n /** Throws for an unknown node type; a missing primitive is a bug, not a degradation. */\n getDefinition(node: PrimitiveNode): AnyPrimitiveDefinition;\n /** `undefined` when the node is hidden from `surface`, `sanitize` drops it, or its primitive declares no renderer for `surface`. */\n renderOn<S extends SurfaceName>(\n surface: S,\n node: PrimitiveNode,\n extras: Omit<SurfaceMap<T>[S]['env'], 'scope'>\n ): SurfaceMap<T>[S]['output'] | undefined;\n renderReact(node: PrimitiveNode, context?: T['context']): ReactNode;\n collectStyles(\n node: PrimitiveNode,\n styles: PrimitiveStyleCollector,\n context: PrimitiveStyleCollectionContext\n ): void;\n renderText(node: PrimitiveNode): string;\n renderMarkdown(node: PrimitiveNode): string;\n /** A child as content, for a container building with `md`; a string result is printed as written. */\n renderMarkdownContent(node: PrimitiveNode): MarkdownContent;\n /** Empty when the node is hidden from `slack`, `sanitize` drops it, or its renderer returns nothing; a node with no `slack` renderer degrades through its markdown. */\n renderSlack(\n node: PrimitiveNode,\n collector?: T['slackCollector']\n ): readonly T['slackBlock'][];\n /** `0` when the node is hidden from `svg` or its primitive declares no `metrics.svgHeight`. */\n estimateSvgHeight(node: PrimitiveNode): number;\n /** Appends schema failures under `path` to `errors`, each naming `node`'s type. */\n validate(node: PrimitiveNode, path: string, errors: ValidationError[]): void;\n}\n\n/**\n * One surface's renderer for one node type, per {@link SurfaceMap}.\n *\n * Indexes the env bag. Do not use this to type the renderers map: the\n * written-out signatures on {@link Renderers} are what keep the bags checked\n * per surface.\n */\nexport type Renderer<\n TNode extends PrimitiveNode,\n S extends SurfaceName,\n T extends PackTypes = DefaultPackTypes,\n> = (node: TNode, env: SurfaceMap<T>[S]['env']) => SurfaceMap<T>[S]['output'];\n\n/**\n * The surface a pack may declare beyond the mandatory three.\n *\n * Only `slack`, and even that stays optional per primitive: the dispatcher\n * converts the mandatory markdown to Block Kit, so a missing Slack renderer\n * degrades rather than disappearing. `svg` is not here because no primitive\n * implements it — the surface reuses `react`.\n */\nexport type OptionalSurface = Extract<SurfaceName, 'slack'>;\n\n/**\n * One renderer per surface a primitive implements.\n *\n * `react`, `text`, and `markdown` are always required: those three are what\n * make \"every composition degrades\" true. `react` serves the `svg` surface\n * too, so targeting images costs a primitive nothing.\n *\n * `slack` is declared method-style deliberately: method parameters are checked\n * bivariantly, which is what lets a pack narrow the collector's node type.\n */\nexport interface Renderers<\n TNode extends PrimitiveNode,\n T extends PackTypes = DefaultPackTypes,\n> {\n react(\n node: TNode,\n env: {\n context: T['context'];\n scope: RenderScope<T>;\n /** See {@link SurfaceMap.react}'s `env.theme`. */\n theme?: T['theme'];\n }\n ): ReactNode;\n text(\n node: TNode,\n env: {\n scope: RenderScope<T>;\n }\n ): string;\n markdown(\n node: TNode,\n env: {\n scope: RenderScope<T>;\n }\n ): string | MarkdownContent;\n slack?(\n node: TNode,\n env: {\n collector?: T['slackCollector'];\n scope: RenderScope<T>;\n }\n ): T['slackBlock'] | readonly T['slackBlock'][];\n}\n\n/**\n * Measurements a frame can ask of a node before drawing it.\n *\n * `svgHeight` is optional, so a frame that sums node heights sizes short when\n * it is missing — the missing `svgHeight` validation warning reports the gap.\n */\nexport interface PrimitiveMetrics<TNode extends PrimitiveNode> {\n /** The node's drawn height in pixels at the frame's width. */\n svgHeight?: (node: TNode) => number;\n}\n\n/**\n * Every primitive's schema is an object schema, because {@link definePrimitive}\n * extends it with `id` and `surfaces` and the composition builds a\n * `z.discriminatedUnion('type', …)` over them. Typed as `ZodObject` rather\n * than `ZodType<unknown>` so a union or intersection schema is a compile\n * error at the definition, not a runtime failure at the first `.extend()`.\n * Zod 4 types `z.object().superRefine(…)` as a `ZodObject` and preserves the\n * refinement through `.extend()`, so top-level refinements are unaffected.\n */\nexport type PrimitiveSchema = ZodObject;\n\n/**\n * The child-ref shape a primitive definition's own `children` returns.\n *\n * {@link ChildNodeRef} stays erased (`node: unknown`) because\n * `createChildNodeWalker` mixes children from every primitive type in the\n * runtime into one map and cannot name a single node type for them. A single\n * definition has no such excuse: its `children` should not type-check\n * against `unknown` and let something that is not a {@link PrimitiveNode} —\n * `null`, for instance — silently disappear from every tree walk.\n */\nexport interface PrimitiveChildRef extends ChildNodeRef {\n node: PrimitiveNode;\n}\n\n/**\n * One primitive: its node type, schema, catalog entry, and a renderer per\n * surface. The unit of vocabulary, and what {@link definePrimitive} takes.\n *\n * `T` is the pack's {@link PackTypes}, bound once with\n * {@link definePrimitiveFor} so each primitive names only `TNode`.\n */\nexport interface PrimitiveDefinition<\n TNode extends PrimitiveNode,\n T extends PackTypes = DefaultPackTypes,\n TSchema extends PrimitiveSchema = PrimitiveSchema,\n> {\n /** The node's discriminant, and the key this primitive occupies in an inventory. */\n type: TNode['type'];\n /** How the authoring prompt describes this primitive to the model. */\n catalog: PrimitiveCatalogEntry;\n /** Driven by the conformance harness. The catalog `example` is what the prompt shows. */\n examples: readonly TNode[];\n /**\n * This primitive on its own. A container declares\n * {@link PrimitiveDefinition.schemaFor} as well, and uses\n * {@link unresolvedBodyNodeSchema} in the child slot here.\n */\n schema: TSchema;\n /**\n * A container's schema, bound to the body-node union of the composition it is\n * being built into.\n *\n * Declaring the shape and letting each composition supply its own union is\n * what lets one primitive appear in two runtimes with different inventories:\n * `z.lazy` memoizes per instance, and an instance built here belongs to\n * exactly one union.\n */\n schemaFor?: (bodyNodeSchema: ZodType<unknown>) => PrimitiveSchema;\n /** One function per surface; `react` serves `svg` as well. */\n renderers: Renderers<TNode, T>;\n /** Sizing a frame can ask for before drawing. Absent means it cannot be measured. */\n metrics?: PrimitiveMetrics<TNode>;\n /**\n * Render-time URL trust, the second of the two layers in `validate/url.ts`.\n *\n * Returning `null` drops the node. Applied even to an unvalidated node, so a\n * renderer invoked directly still cannot emit an unsafe URL.\n */\n sanitize?: (node: TNode) => TNode | null;\n /**\n * Nested nodes, for containers, in the order the `react` renderer draws\n * them; `findNodeElementPairs` relies on it. Absent means a leaf.\n */\n children?: (node: TNode) => readonly PrimitiveChildRef[];\n /**\n * True when this node produces surface output of its own, not only via\n * {@link PrimitiveDefinition.children}. A non-empty `children` result is\n * otherwise the complete source of rendered content, so a hybrid container\n * that still owns string fields returns true to keep rendering when every\n * nested node is hidden from the surface.\n */\n hasOwnContent?: (node: TNode) => boolean;\n /** Contributes this node's CSS by mutating `styles`, once per node per render. */\n collectStyles?: (\n node: TNode,\n env: { styles: T['collector']; context: PrimitiveStyleCollectionContext }\n ) => void;\n}\n\n/**\n * {@link PrimitiveDefinition} with every type parameter erased, and the form an\n * inventory is stored in.\n *\n * A heterogeneous pack has no single `TNode` to be generic over, so the\n * renderers degrade to `unknown` here.\n *\n * Each field carries the same contract as its {@link PrimitiveDefinition}\n * counterpart; only the types are erased.\n */\nexport interface AnyPrimitiveDefinition {\n type: string;\n catalog: PrimitiveCatalogEntry;\n examples: readonly PrimitiveNode[];\n schema: PrimitiveSchema;\n schemaFor?: (bodyNodeSchema: ZodType<unknown>) => PrimitiveSchema;\n renderers: Record<'react' | 'text' | 'markdown', unknown> &\n Partial<Record<'slack', unknown>>;\n metrics?: {\n svgHeight?: unknown;\n };\n sanitize?: unknown;\n children?: unknown;\n hasOwnContent?: unknown;\n collectStyles?: unknown;\n}\n\n/** Parses `node` against `schema`, appending path-prefixed messages to `errors`. */\nexport const validateWithSchema = (\n schema: PrimitiveSchema,\n node: unknown,\n path: string,\n errors: ValidationError[]\n): void => {\n const result = schema.safeParse(node, { reportInput: true });\n if (!result.success) {\n errors.push(...formatZodIssues(result.error.issues, path));\n }\n};\n\n/** The `id` every node may carry, unique within a composition. */\nexport const bodyNodeIdSchema = requiredString('must be a non-empty string');\n\n/** The `surfaces` allowlist on a node. Absent means every surface; empty is rejected. */\nexport const bodyNodeSurfacesSchema = z\n .array(\n z.enum(BODY_NODE_SURFACES as [SurfaceName, ...SurfaceName[]], {\n error: () => oneOf(BODY_NODE_SURFACES),\n })\n )\n .min(1, { error: 'must contain at least one surface' });\n\n/**\n * The child slot in a container's standalone {@link PrimitiveDefinition.schema},\n * where no body-node union is available.\n *\n * Deliberately permissive rather than `z.unknown()`: it still rejects a child\n * that is not a node at all, which is the error worth catching without an\n * inventory. Anything that depends on *which* types are legal — the validator,\n * the parser, the JSON Schema projection — goes through\n * {@link PrimitiveDefinition.schemaFor} and sees the real union.\n */\nexport const unresolvedBodyNodeSchema = z.looseObject({\n type: requiredString('must be a non-empty string'),\n});\n\n/**\n * Declares one primitive, extending its schema with the `id` and `surfaces`\n * fields every node carries, and closing it to unknown keys so a node is held\n * to the same rule as the composition root and the JSON Schema an agent reads.\n * A schema with its own catchall (`z.looseObject`) keeps it.\n *\n * A pack normally calls the form {@link definePrimitiveFor} binds to its own\n * {@link PackTypes}, so each primitive names only `TNode`.\n */\nexport const definePrimitive = <\n TNode extends PrimitiveNode,\n T extends PackTypes = DefaultPackTypes,\n TSchema extends PrimitiveSchema = PrimitiveSchema,\n>(\n definition: PrimitiveDefinition<TNode, T, TSchema>\n): PrimitiveDefinition<TNode, T, WithNodeFields<TSchema>> => {\n const { schemaFor } = definition;\n return {\n ...definition,\n schema: withNodeFields(definition.schema),\n // Both forms get the node fields, or a container would accept `id` and\n // `surfaces` standalone and reject them inside a composition.\n ...(schemaFor\n ? {\n schemaFor: (bodyNodeSchema: ZodType<unknown>) =>\n withNodeFields(schemaFor(bodyNodeSchema)),\n }\n : {}),\n };\n};\n\n/**\n * {@link definePrimitive} bound to one pack's {@link PackTypes}.\n *\n * ```ts\n * const define = definePrimitiveFor<SlidesPackTypes>();\n * export const note = define({ type: 'note', … });\n * ```\n */\nexport const definePrimitiveFor =\n <T extends PackTypes>() =>\n <\n TNode extends PrimitiveNode,\n TSchema extends PrimitiveSchema = PrimitiveSchema,\n >(\n definition: PrimitiveDefinition<TNode, T, TSchema>\n ): PrimitiveDefinition<TNode, T, WithNodeFields<TSchema>> =>\n definePrimitive<TNode, T, TSchema>(definition);\n\n/**\n * `.extend()` on a generic `ZodObject` widens the shape to `any`, so the\n * return type is rebuilt from `TSchema`'s shape. The brand on a field schema\n * stays on that same object at runtime.\n */\nexport type WithNodeFields<TSchema extends PrimitiveSchema> =\n TSchema extends ZodObject<infer Shape>\n ? ZodObject<\n Shape & {\n id: ReturnType<typeof bodyNodeIdSchema.optional>;\n surfaces: ReturnType<typeof bodyNodeSurfacesSchema.optional>;\n }\n >\n : PrimitiveSchema;\n\n// Marks the field schemas `definePrimitive` adds. A schema derived from a\n// defined one shares them by reference, and `Symbol.for` matches across ESM and\n// CommonJS copies of the SDK.\nconst NODE_FIELD = Symbol.for('elastic.isomer.node_field');\n\nconst nodeField = <T extends ZodType>(schema: T): T =>\n Object.defineProperty(schema, NODE_FIELD, { value: true });\n\nconst NODE_FIELDS = {\n id: nodeField(bodyNodeIdSchema.optional()),\n surfaces: nodeField(bodyNodeSurfacesSchema.optional()),\n};\n\nconst isNodeField = (schema: unknown): boolean => {\n let current = schema;\n while (current && typeof current === 'object') {\n if (Object.hasOwn(current, NODE_FIELD)) return true;\n const { def } = current as {\n def?: { type?: string; innerType?: unknown };\n };\n if (def?.type !== 'optional') return false;\n current = def.innerType;\n }\n return false;\n};\n\nconst withNodeFields = <TSchema extends PrimitiveSchema>(\n schema: TSchema\n): WithNodeFields<TSchema> => {\n const reserved = Object.keys(NODE_FIELDS).find(\n (field) =>\n Object.hasOwn(schema.shape, field) && !isNodeField(schema.shape[field])\n );\n if (reserved) {\n throw new IsomerError(\n ISOMER_ERROR_CODES.RESERVED_NODE_FIELD,\n `definePrimitive: a primitive schema cannot declare \\`${reserved}\\`; every body node has it.`\n );\n }\n const extended = schema.extend(NODE_FIELDS);\n return (\n schema.def.catchall === undefined ? extended.strict() : extended\n ) as WithNodeFields<TSchema>;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"primitive_module.js","sourceRoot":"","sources":["../../../src/define/primitive_module.ts"],"names":[],"mappings":"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","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nimport type { ReactNode } from 'react';\nimport { z, type ZodObject, type ZodType } from 'zod';\n\nimport type { ActionEventRef } from '../composition/action_event';\nimport {\n type ChildNodeRef,\n SURFACE_NAMES,\n type SurfaceName,\n} from '../composition/body_node_base';\nimport { ISOMER_ERROR_CODES, IsomerError } from '../composition/error';\nimport type { PrimitiveNode } from '../composition/node';\nimport type { ValidationError } from '../composition/validation_error';\n\nimport type { MarkdownContent } from './markdown_content';\nimport type { PrimitiveExample } from './primitive_example';\nimport type { PrimitiveIcon } from './primitive_icon';\nimport type { SlackAssetCollector } from './slack_assets';\nimport type { SlackBlock } from './slack_blocks';\nimport { formatZodIssues, oneOf } from './zod_format';\nimport { requiredString } from './zod_helpers';\n\nexport type { PrimitiveNode };\n\n/**\n * A primitive's entry in the catalog the authoring prompt is built from.\n *\n * Written for the model rather than for a developer: `useWhen` and `avoidWhen`\n * are what steer it away from reaching for the wrong primitive. `name` is the\n * one host-facing field, and the prompt never prints it.\n */\nexport interface PrimitiveCatalogEntry {\n type: string;\n /** Short name a host shows for the primitive, e.g. `Stat group`. Absent means the host derives one from `type`. */\n name?: string;\n /**\n * Description of this primitive's `$def` in the authoring JSON Schema.\n *\n * `z.toJSONSchema` drops refinements, so a cross-field rule is restated here.\n * {@link definePrimitive} copies `schema.description` when this is omitted.\n */\n description?: string;\n /** One line on what the primitive is for, in the model's voice. */\n purpose: string;\n /** Situations that call for this primitive. Phrase each as a user intent, not a shape. */\n useWhen: string[];\n /** Situations that look like a fit but are not, naming the primitive to reach for instead. */\n avoidWhen: string[];\n /** A node literal the authoring prompt inlines under this primitive. */\n example: unknown;\n}\n\n/** A style a renderer asks for by name, resolved to a class by the host's adapter. */\nexport interface StyleHandle {\n /** Stable lookup key. The adapter's map is keyed on this. */\n key: string;\n /** Debug-facing label, which an adapter may fold into a generated class name. */\n readableName: string;\n}\n\n/** Dotted path into a pack's theme tokens, e.g. `colors.text.subdued`. */\nexport type ThemeTokenPath = string;\n\n/**\n * The sdk's own render context, and {@link DefaultPackTypes.context}.\n *\n * A pack with real theme tokens or a richer style-handle type declares its\n * own context in its {@link PackTypes}; {@link StyledRenderContext} is the\n * sdk's own extension. The bag is what lets a pack narrow without\n * re-declaring everything that mentions a context.\n */\nexport interface PrimitiveRenderContext {\n /**\n * The progressive enhancements this render may assume, by id. A set rather\n * than a field per feature so adding an enhancement costs no plumbing:\n * containers forward the whole context, and a renderer asks\n * `context.enhancements?.has('tableSort')`.\n *\n * Empty or absent is the baseline every host can render, so a renderer must\n * still answer the question on its own. See `docs/rendering.md`.\n */\n enhancements?: ReadonlySet<string>;\n /** Turns on `nodeAnchor` outside an HTML surface render, on the React and `snapshot` surfaces; inside one, the surface decides. */\n anchors?: boolean;\n /** Raises an interaction for the host to route. Absent means render non-interactively. */\n onEvent?: (event: ActionEventRef) => void;\n}\n\n/**\n * The render-context argument, optional only when omitting it is sound.\n *\n * The sdk's own {@link PrimitiveRenderContext} has no required field, so `{}`\n * is a complete value and a caller may leave it out. A pack that narrows the\n * context with a required member makes the argument mandatory.\n */\nexport type ReactContextArg<TContext> =\n Record<string, never> extends TContext\n ? [context?: TContext]\n : [context: TContext];\n\n/**\n * {@link PrimitiveRenderContext} plus the CSS-in-JS hooks an HTML style adapter\n * supplies. A pack that styles differently uses its own `TContext` instead.\n */\nexport interface StyledRenderContext extends PrimitiveRenderContext {\n /** Resolves handles to a `className`. Absent means the host supplies no styling. */\n resolveClassName?: (...handles: StyleHandle[]) => string;\n /** Resolves a theme token to a CSS variable reference. Absent means inline the literal value. */\n cssVarRef?: (path: ThemeTokenPath) => `var(--${string})`;\n}\n\n/** Passed to a primitive's style collector so it can vary CSS by layout mode. */\nexport interface PrimitiveStyleCollectionContext {\n /** The render fills its container rather than sitting at a fixed width. */\n fluid?: boolean;\n}\n\n/** A pack's collected styles, opaque to the SDK. */\nexport type PrimitiveStyleCollector = object;\n\n/**\n * The types a pack binds once and writes every primitive against: the palette\n * its frames supply, the context its `react` renderers receive, the collector\n * its `collectStyles` hooks mutate, and the Slack payload and collector types.\n *\n * Extend {@link DefaultPackTypes} and narrow only what the pack needs:\n *\n * ```ts\n * interface SlidesPackTypes extends DefaultPackTypes {\n * theme: SlideTheme;\n * context: SlideRenderContext;\n * }\n * ```\n */\nexport interface PackTypes {\n theme: unknown;\n context: unknown;\n collector: PrimitiveStyleCollector;\n slackBlock: unknown;\n slackCollector: unknown;\n}\n\n/** {@link PackTypes} as the sdk itself binds them, and the default everywhere. */\nexport interface DefaultPackTypes extends PackTypes {\n theme: unknown;\n context: PrimitiveRenderContext;\n collector: PrimitiveStyleCollector;\n slackBlock: SlackBlock;\n slackCollector: SlackAssetCollector;\n}\n\n/**\n * Each surface's renderer signature: the env bag it receives beyond the node,\n * and what it returns.\n *\n * Written out per surface rather than derived through an indexed access. A bag\n * is additive: a new extra on a surface is not an arity break. {@link Renderer}\n * indexes this table for the dispatcher cast; {@link Renderers} does not.\n */\nexport interface SurfaceMap<T extends PackTypes = DefaultPackTypes> {\n react: {\n env: {\n context: T['context'];\n scope: RenderScope<T>;\n /**\n * The frame's resolved palette, when this render is reached through the\n * `snapshot` surface. A bare `react`/`html` render has no {@link Frame} to\n * resolve one from, so it is absent there — a pack that needs a\n * literal color outside `snapshot` still goes through `context`.\n */\n theme?: T['theme'];\n };\n output: ReactNode;\n };\n /**\n * Identical to `react`, and served by the same renderer: an image backend\n * lays out the pack's DOM tree and stylesheet rather than a second tree\n * authored for it. The surface stays separate so a node can be hidden from\n * snapshots alone, and so a {@link Frame} has something to draw inside.\n */\n snapshot: {\n env: {\n context: T['context'];\n scope: RenderScope<T>;\n /** The frame's resolved palette for this render's mode; see `react.env.theme`. */\n theme?: T['theme'];\n };\n output: ReactNode;\n };\n text: {\n env: {\n scope: RenderScope<T>;\n };\n output: string;\n };\n /** Content built with `md`, escaped where it lands; authored Markdown source goes through `md.authored`. */\n markdown: {\n env: {\n scope: RenderScope<T>;\n };\n output: MarkdownContent;\n };\n /**\n * Returns one payload or several, so a primitive need not wrap a single\n * payload in an array.\n */\n slack: {\n env: {\n collector?: T['slackCollector'];\n scope: RenderScope<T>;\n };\n output: T['slackBlock'] | readonly T['slackBlock'][];\n };\n}\n\n/**\n * The dispatcher a renderer is given so a container can recurse into a child\n * owned by another pack. Erased to {@link PrimitiveNode}: a heterogeneous\n * inventory has no single node type to name.\n *\n * Passed as `scope` on every renderer's env bag. The dispatcher's own named\n * methods stay positional.\n */\nexport interface RenderScope<T extends PackTypes = DefaultPackTypes> {\n readonly definitions: readonly AnyPrimitiveDefinition[];\n /** Throws for an unknown node type; a missing primitive is a bug, not a degradation. */\n getDefinition(node: PrimitiveNode): AnyPrimitiveDefinition;\n /** `undefined` when the node is hidden from `surface`, `sanitize` drops it, or its primitive declares no renderer for `surface`. */\n renderOn<S extends SurfaceName>(\n surface: S,\n node: PrimitiveNode,\n extras: Omit<SurfaceMap<T>[S]['env'], 'scope'>\n ): SurfaceMap<T>[S]['output'] | undefined;\n renderReact(node: PrimitiveNode, context?: T['context']): ReactNode;\n collectStyles(\n node: PrimitiveNode,\n styles: PrimitiveStyleCollector,\n context: PrimitiveStyleCollectionContext\n ): void;\n renderText(node: PrimitiveNode): string;\n renderMarkdown(node: PrimitiveNode): string;\n /** A child as content, for a container building with `md`. */\n renderMarkdownContent(node: PrimitiveNode): MarkdownContent;\n /** Empty when the node is hidden from `slack`, `sanitize` drops it, or its renderer returns nothing; a node with no `slack` renderer degrades through its markdown. */\n renderSlack(\n node: PrimitiveNode,\n collector?: T['slackCollector']\n ): readonly T['slackBlock'][];\n /** `0` when the node is hidden from `snapshot` or its primitive declares no `metrics.snapshotHeight`. */\n estimateSnapshotHeight(node: PrimitiveNode): number;\n /** Appends schema failures under `path` to `errors`, each naming `node`'s type. */\n validate(node: PrimitiveNode, path: string, errors: ValidationError[]): void;\n}\n\n/**\n * One surface's renderer for one node type, per {@link SurfaceMap}.\n *\n * Indexes the env bag. Do not use this to type the renderers map: the\n * written-out signatures on {@link Renderers} are what keep the bags checked\n * per surface.\n */\nexport type Renderer<\n TNode extends PrimitiveNode,\n S extends SurfaceName,\n T extends PackTypes = DefaultPackTypes,\n> = (node: TNode, env: SurfaceMap<T>[S]['env']) => SurfaceMap<T>[S]['output'];\n\n/**\n * The surface a pack may declare beyond the mandatory three.\n *\n * Only `slack`, and even that stays optional per primitive: the dispatcher\n * converts the mandatory markdown to Block Kit, so a missing Slack renderer\n * degrades rather than disappearing. `snapshot` is not here because no primitive\n * implements it — the surface reuses `react`.\n */\nexport const OPTIONAL_SURFACES = [\n 'slack',\n] as const satisfies readonly SurfaceName[];\n\n/** One of the {@link OPTIONAL_SURFACES}. */\nexport type OptionalSurface = (typeof OPTIONAL_SURFACES)[number];\n\n/**\n * One renderer per surface a primitive implements.\n *\n * `react`, `text`, and `markdown` are always required: those three are what\n * make \"every composition degrades\" true. `react` serves the `snapshot` surface\n * too, so targeting images costs a primitive nothing.\n *\n * `slack` is declared method-style deliberately: method parameters are checked\n * bivariantly, which is what lets a pack narrow the collector's node type.\n */\nexport interface Renderers<\n TNode extends PrimitiveNode,\n T extends PackTypes = DefaultPackTypes,\n> {\n react(\n node: TNode,\n env: {\n context: T['context'];\n scope: RenderScope<T>;\n /** See {@link SurfaceMap.react}'s `env.theme`. */\n theme?: T['theme'];\n }\n ): ReactNode;\n text(\n node: TNode,\n env: {\n scope: RenderScope<T>;\n }\n ): string;\n markdown(\n node: TNode,\n env: {\n scope: RenderScope<T>;\n }\n ): MarkdownContent;\n slack?(\n node: TNode,\n env: {\n collector?: T['slackCollector'];\n scope: RenderScope<T>;\n }\n ): T['slackBlock'] | readonly T['slackBlock'][];\n}\n\n/**\n * Measurements a frame can ask of a node before drawing it.\n *\n * `snapshotHeight` is optional. The height estimate is `0` when it is missing, so\n * a frame that sums node heights sizes short.\n */\nexport interface PrimitiveMetrics<TNode extends PrimitiveNode> {\n /** The node's drawn height in pixels at the frame's width. */\n snapshotHeight?: (node: TNode) => number;\n}\n\n/**\n * Every primitive's schema is an object schema, because {@link definePrimitive}\n * extends it with `id` and `surfaces` and the composition builds a\n * `z.discriminatedUnion('type', …)` over them. Typed as `ZodObject` rather\n * than `ZodType<unknown>` so a union or intersection schema is a compile\n * error at the definition, not a runtime failure at the first `.extend()`.\n * Zod 4 types `z.object().superRefine(…)` as a `ZodObject` and preserves the\n * refinement through `.extend()`, so top-level refinements are unaffected.\n */\nexport type PrimitiveSchema = ZodObject;\n\n/**\n * The child-ref shape a primitive definition's own `children` returns.\n *\n * {@link ChildNodeRef} stays erased (`node: unknown`) because\n * `createChildNodeWalker` mixes children from every primitive type in the\n * runtime into one map and cannot name a single node type for them. A single\n * definition has no such excuse: its `children` should not type-check\n * against `unknown` and let something that is not a {@link PrimitiveNode} —\n * `null`, for instance — silently disappear from every tree walk.\n */\nexport interface PrimitiveChildRef extends ChildNodeRef {\n node: PrimitiveNode;\n}\n\n/**\n * One primitive: its node type, schema, catalog entry, and a renderer per\n * surface. The unit of vocabulary, and what {@link definePrimitive} takes.\n *\n * `T` is the pack's {@link PackTypes}, bound once with\n * {@link definePrimitiveFor} so each primitive names only `TNode`.\n */\nexport interface PrimitiveDefinition<\n TNode extends PrimitiveNode,\n T extends PackTypes = DefaultPackTypes,\n TSchema extends PrimitiveSchema = PrimitiveSchema,\n> {\n /** The node's discriminant, and the key this primitive occupies in an inventory. */\n type: TNode['type'];\n /** How the authoring prompt describes this primitive to the model. */\n catalog: PrimitiveCatalogEntry;\n /** Host-facing glyph, never shown to the model. Absent means the host supplies its own. */\n icon?: PrimitiveIcon;\n /**\n * Driven by the conformance harness, bare or named; read them with\n * `exampleNodes` or `primitiveExamples`. The catalog `example` is what the\n * prompt shows.\n */\n examples: readonly (TNode | PrimitiveExample<TNode>)[];\n /**\n * This primitive on its own. A container declares\n * {@link PrimitiveDefinition.schemaFor} as well, and uses\n * {@link unresolvedBodyNodeSchema} in the child slot here.\n */\n schema: TSchema;\n /**\n * A container's schema, bound to the body-node union of the composition it is\n * being built into.\n *\n * Declaring the shape and letting each composition supply its own union is\n * what lets one primitive appear in two runtimes with different inventories:\n * `z.lazy` memoizes per instance, and an instance built here belongs to\n * exactly one union.\n */\n schemaFor?: (bodyNodeSchema: ZodType<unknown>) => PrimitiveSchema;\n /** One function per surface; `react` serves `snapshot` as well. */\n renderers: Renderers<TNode, T>;\n /** Sizing a frame can ask for before drawing. Absent means it cannot be measured. */\n metrics?: PrimitiveMetrics<TNode>;\n /**\n * Render-time URL trust, the second of the two layers in `validate/url.ts`.\n *\n * Returning `null` drops the node. Applied even to an unvalidated node, so a\n * renderer invoked directly still cannot emit an unsafe URL.\n */\n sanitize?: (node: TNode) => TNode | null;\n /**\n * Nested nodes, for containers, in the order the `react` renderer draws\n * them; `findNodeElementPairs` relies on it. Absent means a leaf.\n */\n children?: (node: TNode) => readonly PrimitiveChildRef[];\n /**\n * True when this node produces surface output of its own, not only via\n * {@link PrimitiveDefinition.children}. A non-empty `children` result is\n * otherwise the complete source of rendered content, so a hybrid container\n * that still owns string fields returns true to keep rendering when every\n * nested node is hidden from the surface.\n */\n hasOwnContent?: (node: TNode) => boolean;\n /** Contributes this node's CSS by mutating `styles`, once per node per render. */\n collectStyles?: (\n node: TNode,\n env: { styles: T['collector']; context: PrimitiveStyleCollectionContext }\n ) => void;\n}\n\n/**\n * {@link PrimitiveDefinition} with every type parameter erased, and the form an\n * inventory is stored in.\n *\n * A heterogeneous pack has no single `TNode` to be generic over, so the\n * renderers degrade to `unknown` here.\n *\n * Each field carries the same contract as its {@link PrimitiveDefinition}\n * counterpart; only the types are erased.\n */\nexport interface AnyPrimitiveDefinition {\n type: string;\n catalog: PrimitiveCatalogEntry;\n icon?: PrimitiveIcon;\n examples: readonly (PrimitiveNode | PrimitiveExample)[];\n schema: PrimitiveSchema;\n schemaFor?: (bodyNodeSchema: ZodType<unknown>) => PrimitiveSchema;\n renderers: Record<'react' | 'text' | 'markdown', unknown> &\n Partial<Record<'slack', unknown>>;\n metrics?: {\n snapshotHeight?: unknown;\n };\n sanitize?: unknown;\n children?: unknown;\n hasOwnContent?: unknown;\n collectStyles?: unknown;\n}\n\n/** Parses `node` against `schema`, appending path-prefixed messages to `errors`. */\nexport const validateWithSchema = (\n schema: PrimitiveSchema,\n node: unknown,\n path: string,\n errors: ValidationError[]\n): void => {\n const result = schema.safeParse(node, { reportInput: true });\n if (!result.success) {\n errors.push(...formatZodIssues(result.error.issues, path));\n }\n};\n\n/** The `id` every node may carry, unique within a composition. */\nexport const bodyNodeIdSchema = requiredString('must be a non-empty string');\n\n/** The `surfaces` allowlist on a node. Absent means every surface; empty is rejected. */\nexport const bodyNodeSurfacesSchema = z\n .array(\n z.enum(SURFACE_NAMES, {\n error: () => oneOf(SURFACE_NAMES),\n })\n )\n .min(1, { error: 'must contain at least one surface' });\n\n/**\n * The child slot in a container's standalone {@link PrimitiveDefinition.schema},\n * where no body-node union is available.\n *\n * Deliberately permissive rather than `z.unknown()`: it still rejects a child\n * that is not a node at all, which is the error worth catching without an\n * inventory. Anything that depends on *which* types are legal — the validator,\n * the parser, the JSON Schema projection — goes through\n * {@link PrimitiveDefinition.schemaFor} and sees the real union.\n */\nexport const unresolvedBodyNodeSchema = z.looseObject({\n type: requiredString('must be a non-empty string'),\n});\n\n/**\n * Declares one primitive, extending its schema with the `id` and `surfaces`\n * fields every node carries, and closing it to unknown keys so a node is held\n * to the same rule as the composition root and the JSON Schema an agent reads.\n * A schema with its own catchall (`z.looseObject`) keeps it.\n *\n * A pack normally calls the form {@link definePrimitiveFor} binds to its own\n * {@link PackTypes}, so each primitive names only `TNode`.\n */\nexport const definePrimitive = <\n TNode extends PrimitiveNode,\n T extends PackTypes = DefaultPackTypes,\n TSchema extends PrimitiveSchema = PrimitiveSchema,\n>(\n definition: PrimitiveDefinition<TNode, T, TSchema>\n): PrimitiveDefinition<TNode, T, WithNodeFields<TSchema>> => {\n const { schemaFor, schema, catalog } = definition;\n const described =\n catalog.description === undefined ? schema.description : undefined;\n return {\n ...definition,\n ...(described === undefined\n ? {}\n : { catalog: { ...catalog, description: described } }),\n schema: withNodeFields(schema),\n // Both forms get the node fields, or a container would accept `id` and\n // `surfaces` standalone and reject them inside a composition.\n ...(schemaFor\n ? {\n schemaFor: (bodyNodeSchema: ZodType<unknown>) =>\n withNodeFields(schemaFor(bodyNodeSchema)),\n }\n : {}),\n };\n};\n\n/**\n * {@link definePrimitive} bound to one pack's {@link PackTypes}.\n *\n * ```ts\n * const define = definePrimitiveFor<SlidesPackTypes>();\n * export const note = define({ type: 'note', … });\n * ```\n */\nexport const definePrimitiveFor =\n <T extends PackTypes>() =>\n <\n TNode extends PrimitiveNode,\n TSchema extends PrimitiveSchema = PrimitiveSchema,\n >(\n definition: PrimitiveDefinition<TNode, T, TSchema>\n ): PrimitiveDefinition<TNode, T, WithNodeFields<TSchema>> =>\n definePrimitive<TNode, T, TSchema>(definition);\n\n/**\n * `.extend()` on a generic `ZodObject` widens the shape to `any`, so the\n * return type is rebuilt from `TSchema`'s shape. The brand on a field schema\n * stays on that same object at runtime.\n */\nexport type WithNodeFields<TSchema extends PrimitiveSchema> =\n TSchema extends ZodObject<infer Shape>\n ? ZodObject<\n Shape & {\n id: ReturnType<typeof bodyNodeIdSchema.optional>;\n surfaces: ReturnType<typeof bodyNodeSurfacesSchema.optional>;\n }\n >\n : PrimitiveSchema;\n\n// Marks the field schemas `definePrimitive` adds. A schema derived from a\n// defined one shares them by reference, and `Symbol.for` matches across ESM and\n// CommonJS copies of the SDK.\nconst NODE_FIELD = Symbol.for('elastic.isomer.node_field');\n\nconst nodeField = <T extends ZodType>(schema: T): T =>\n Object.defineProperty(schema, NODE_FIELD, { value: true });\n\nconst NODE_FIELDS = {\n id: nodeField(bodyNodeIdSchema.optional()),\n surfaces: nodeField(bodyNodeSurfacesSchema.optional()),\n};\n\nconst isNodeField = (schema: unknown): boolean => {\n let current = schema;\n while (current && typeof current === 'object') {\n if (Object.hasOwn(current, NODE_FIELD)) {\n return true;\n }\n const { def } = current as {\n def?: { type?: string; innerType?: unknown };\n };\n if (def?.type !== 'optional') {\n return false;\n }\n current = def.innerType;\n }\n return false;\n};\n\nconst withNodeFields = <TSchema extends PrimitiveSchema>(\n schema: TSchema\n): WithNodeFields<TSchema> => {\n const reserved = Object.keys(NODE_FIELDS).find(\n (field) =>\n Object.hasOwn(schema.shape, field) && !isNodeField(schema.shape[field])\n );\n if (reserved) {\n throw new IsomerError(\n ISOMER_ERROR_CODES.RESERVED_NODE_FIELD,\n `definePrimitive: a primitive schema cannot declare \\`${reserved}\\`; every body node has it.`\n );\n }\n const extended = schema.extend(NODE_FIELDS);\n return (\n schema.def.catchall === undefined ? extended.strict() : extended\n ) as WithNodeFields<TSchema>;\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slack_assets.js","sourceRoot":"","sources":["../../../src/define/slack_assets.ts"],"names":[],"mappings":";AAAA;;;;;GAKG","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nimport type { PrimitiveNode } from '../composition/node';\n\n/**\n * One image the host must upload before the message can be posted.\n *\n * The renderer is pure, so it emits `ref` as a placeholder and the host swaps\n * in Slack's file id once the upload lands.\n */\nexport interface SlackAssetRequest<\n TNode extends PrimitiveNode = PrimitiveNode,\n> {\n /** Placeholder the render emits, which the host replaces with Slack's file id. */\n ref: string;\n /** The node to draw as an image, to be rendered on the `
|
|
1
|
+
{"version":3,"file":"slack_assets.js","sourceRoot":"","sources":["../../../src/define/slack_assets.ts"],"names":[],"mappings":";AAAA;;;;;GAKG","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nimport type { PrimitiveNode } from '../composition/node';\n\n/**\n * One image the host must upload before the message can be posted.\n *\n * The renderer is pure, so it emits `ref` as a placeholder and the host swaps\n * in Slack's file id once the upload lands.\n */\nexport interface SlackAssetRequest<\n TNode extends PrimitiveNode = PrimitiveNode,\n> {\n /** Placeholder the render emits, which the host replaces with Slack's file id. */\n ref: string;\n /** The node to draw as an image, to be rendered on the `snapshot` surface. */\n node: TNode;\n /** Accessible description, required because Slack rejects an image block without one. */\n altText: string;\n}\n\n/**\n * Accumulates the {@link SlackAssetRequest}s a render produced.\n *\n * Opt-in: without a collector, a node that cannot draw inline degrades to text\n * instead, so default output stays safe for callers that cannot upload files.\n */\nexport interface SlackAssetCollector<\n TNode extends PrimitiveNode = PrimitiveNode,\n> {\n /** Reserves a placeholder `ref` for `node` and records the request. */\n allocate(node: TNode, altText: string): string;\n /** In allocation order, so a host can upload and swap refs in one pass. */\n readonly requests: readonly SlackAssetRequest<TNode>[];\n}\n"]}
|
|
@@ -6,13 +6,14 @@
|
|
|
6
6
|
* 2.0.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.
|
|
10
|
-
exports.warningsForSurface = exports.structuredValueSchema = exports.sanitizeNavigationHref = exports.sanitizeAssetUrl = exports.renderThemeSchema = exports.navigationHref = exports.namedColorSchema = exports.isInputRefusal = exports.getCompositionSchemaForDefinitions = void 0;
|
|
9
|
+
exports.buildAuthoringJsonSchema = exports.authoringSchemaSubset = exports.assetUrl = exports.NAVIGATION_HREF_RULE = exports.NAVIGATION_HREF_MESSAGE = exports.MAX_INPUT_VALUES = exports.MAX_INPUT_DEPTH = exports.MAX_INPUT_CHARACTERS = exports.BLOCKED_HREF = exports.ASSET_URL_RULE = exports.ASSET_URL_MESSAGE = exports.withoutAnchors = exports.withNodeAnchors = exports.rawDisplayValue = exports.nodeAnchor = exports.layoutRoom = exports.isStructuredValue = exports.formatDisplayValue = exports.createPrimitiveDispatcher = exports.checkLayout = exports.NODE_ANCHOR_ATTRIBUTE = exports.LAYOUT_ROOM_ATTRIBUTE = exports.scopeScript = exports.describeCapabilities = exports.definePrimitivePack = exports.composePacks = exports.UNCATEGORIZED_GROUP_TITLE = exports.z = exports.unresolvedBodyNodeSchema = exports.requiredString = exports.primitiveExamples = exports.formatZodIssues = exports.exampleNodes = exports.definePrimitiveFor = exports.definePrimitive = exports.bindFrame = exports.OPTIONAL_SURFACES = exports.ICON_VARS = exports.someBodyNode = exports.mapCompositionNodes = exports.isVisibleOnSurface = exports.IsomerError = exports.formatValidationError = exports.createChildNodeWalker = exports.CompositionValidationError = exports.SURFACE_NAMES = exports.STRUCTURED_VALUE_FORMATS = exports.ISOMER_ERROR_CODES = exports.BODY_NODE_SURFACES = exports.ALL_NAMED_COLORS = void 0;
|
|
10
|
+
exports.warningsForSurface = exports.structuredValueSchema = exports.sanitizeNavigationHref = exports.sanitizeAssetUrl = exports.renderThemeSchema = exports.navigationHref = exports.namedColorSchema = exports.isInputRefusal = exports.getCompositionSchemaForDefinitions = exports.displayValueSchema = exports.createCompositionValidator = exports.createCompositionParser = exports.compositionToRender = exports.checkInputBudget = exports.buildCompositionJsonSchema = void 0;
|
|
11
11
|
var composition_1 = require("../composition");
|
|
12
12
|
Object.defineProperty(exports, "ALL_NAMED_COLORS", { enumerable: true, get: function () { return composition_1.ALL_NAMED_COLORS; } });
|
|
13
13
|
Object.defineProperty(exports, "BODY_NODE_SURFACES", { enumerable: true, get: function () { return composition_1.BODY_NODE_SURFACES; } });
|
|
14
14
|
Object.defineProperty(exports, "ISOMER_ERROR_CODES", { enumerable: true, get: function () { return composition_1.ISOMER_ERROR_CODES; } });
|
|
15
15
|
Object.defineProperty(exports, "STRUCTURED_VALUE_FORMATS", { enumerable: true, get: function () { return composition_1.STRUCTURED_VALUE_FORMATS; } });
|
|
16
|
+
Object.defineProperty(exports, "SURFACE_NAMES", { enumerable: true, get: function () { return composition_1.SURFACE_NAMES; } });
|
|
16
17
|
Object.defineProperty(exports, "CompositionValidationError", { enumerable: true, get: function () { return composition_1.CompositionValidationError; } });
|
|
17
18
|
Object.defineProperty(exports, "createChildNodeWalker", { enumerable: true, get: function () { return composition_1.createChildNodeWalker; } });
|
|
18
19
|
Object.defineProperty(exports, "formatValidationError", { enumerable: true, get: function () { return composition_1.formatValidationError; } });
|
|
@@ -21,14 +22,19 @@ Object.defineProperty(exports, "isVisibleOnSurface", { enumerable: true, get: fu
|
|
|
21
22
|
Object.defineProperty(exports, "mapCompositionNodes", { enumerable: true, get: function () { return composition_1.mapCompositionNodes; } });
|
|
22
23
|
Object.defineProperty(exports, "someBodyNode", { enumerable: true, get: function () { return composition_1.someBodyNode; } });
|
|
23
24
|
var define_1 = require("../define");
|
|
25
|
+
Object.defineProperty(exports, "ICON_VARS", { enumerable: true, get: function () { return define_1.ICON_VARS; } });
|
|
26
|
+
Object.defineProperty(exports, "OPTIONAL_SURFACES", { enumerable: true, get: function () { return define_1.OPTIONAL_SURFACES; } });
|
|
24
27
|
Object.defineProperty(exports, "bindFrame", { enumerable: true, get: function () { return define_1.bindFrame; } });
|
|
25
28
|
Object.defineProperty(exports, "definePrimitive", { enumerable: true, get: function () { return define_1.definePrimitive; } });
|
|
26
29
|
Object.defineProperty(exports, "definePrimitiveFor", { enumerable: true, get: function () { return define_1.definePrimitiveFor; } });
|
|
30
|
+
Object.defineProperty(exports, "exampleNodes", { enumerable: true, get: function () { return define_1.exampleNodes; } });
|
|
27
31
|
Object.defineProperty(exports, "formatZodIssues", { enumerable: true, get: function () { return define_1.formatZodIssues; } });
|
|
32
|
+
Object.defineProperty(exports, "primitiveExamples", { enumerable: true, get: function () { return define_1.primitiveExamples; } });
|
|
28
33
|
Object.defineProperty(exports, "requiredString", { enumerable: true, get: function () { return define_1.requiredString; } });
|
|
29
34
|
Object.defineProperty(exports, "unresolvedBodyNodeSchema", { enumerable: true, get: function () { return define_1.unresolvedBodyNodeSchema; } });
|
|
30
35
|
Object.defineProperty(exports, "z", { enumerable: true, get: function () { return define_1.z; } });
|
|
31
36
|
var pack_1 = require("../pack");
|
|
37
|
+
Object.defineProperty(exports, "UNCATEGORIZED_GROUP_TITLE", { enumerable: true, get: function () { return pack_1.UNCATEGORIZED_GROUP_TITLE; } });
|
|
32
38
|
Object.defineProperty(exports, "composePacks", { enumerable: true, get: function () { return pack_1.composePacks; } });
|
|
33
39
|
Object.defineProperty(exports, "definePrimitivePack", { enumerable: true, get: function () { return pack_1.definePrimitivePack; } });
|
|
34
40
|
Object.defineProperty(exports, "describeCapabilities", { enumerable: true, get: function () { return pack_1.describeCapabilities; } });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/entries/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/entries/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,8CA6BwB;AAZtB,+GAAA,gBAAgB,OAAA;AAChB,iHAAA,kBAAkB,OAAA;AAClB,iHAAA,kBAAkB,OAAA;AAClB,uHAAA,wBAAwB,OAAA;AACxB,4GAAA,aAAa,OAAA;AACb,yHAAA,0BAA0B,OAAA;AAC1B,oHAAA,qBAAqB,OAAA;AACrB,oHAAA,qBAAqB,OAAA;AACrB,0GAAA,WAAW,OAAA;AACX,iHAAA,kBAAkB,OAAA;AAClB,kHAAA,mBAAmB,OAAA;AACnB,2GAAA,YAAY,OAAA;AAEd,oCA6CmB;AAXjB,mGAAA,SAAS,OAAA;AACT,2GAAA,iBAAiB,OAAA;AACjB,mGAAA,SAAS,OAAA;AACT,yGAAA,eAAe,OAAA;AACf,4GAAA,kBAAkB,OAAA;AAClB,sGAAA,YAAY,OAAA;AACZ,yGAAA,eAAe,OAAA;AACf,2GAAA,iBAAiB,OAAA;AACjB,wGAAA,cAAc,OAAA;AACd,kHAAA,wBAAwB,OAAA;AACxB,2FAAA,CAAC,OAAA;AAEH,gCAiBiB;AALf,iHAAA,yBAAyB,OAAA;AACzB,oGAAA,YAAY,OAAA;AACZ,2GAAA,mBAAmB,OAAA;AACnB,4GAAA,oBAAoB,OAAA;AACpB,mGAAA,WAAW,OAAA;AAEb,oCAmBmB;AAXjB,+GAAA,qBAAqB,OAAA;AACrB,+GAAA,qBAAqB,OAAA;AACrB,qGAAA,WAAW,OAAA;AACX,mHAAA,yBAAyB,OAAA;AACzB,4GAAA,kBAAkB,OAAA;AAClB,2GAAA,iBAAiB,OAAA;AACjB,oGAAA,UAAU,OAAA;AACV,oGAAA,UAAU,OAAA;AACV,yGAAA,eAAe,OAAA;AACf,yGAAA,eAAe,OAAA;AACf,wGAAA,cAAc,OAAA;AAEhB,wCAwCqB;AA1BnB,6GAAA,iBAAiB,OAAA;AACjB,0GAAA,cAAc,OAAA;AACd,wGAAA,YAAY,OAAA;AACZ,gHAAA,oBAAoB,OAAA;AACpB,2GAAA,eAAe,OAAA;AACf,4GAAA,gBAAgB,OAAA;AAChB,mHAAA,uBAAuB,OAAA;AACvB,gHAAA,oBAAoB,OAAA;AACpB,oGAAA,QAAQ,OAAA;AACR,iHAAA,qBAAqB,OAAA;AACrB,oHAAA,wBAAwB,OAAA;AACxB,sHAAA,0BAA0B,OAAA;AAC1B,4GAAA,gBAAgB,OAAA;AAChB,+GAAA,mBAAmB,OAAA;AACnB,mHAAA,uBAAuB,OAAA;AACvB,sHAAA,0BAA0B,OAAA;AAC1B,8GAAA,kBAAkB,OAAA;AAClB,8HAAA,kCAAkC,OAAA;AAClC,0GAAA,cAAc,OAAA;AACd,4GAAA,gBAAgB,OAAA;AAChB,0GAAA,cAAc,OAAA;AACd,6GAAA,iBAAiB,OAAA;AACjB,4GAAA,gBAAgB,OAAA;AAChB,kHAAA,sBAAsB,OAAA;AACtB,iHAAA,qBAAqB,OAAA;AACrB,8GAAA,kBAAkB,OAAA","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nexport {\n type ActionEventRef,\n type BodyNodeBase,\n type ChildNodeRef,\n type ChildNodeWalker,\n type Composition,\n type CompositionMeta,\n type DisplayValue,\n type IsomerErrorCode,\n type NamedColor,\n type NamedColorPalette,\n type PrimitiveNode,\n type RenderTheme,\n type StructuredValue,\n type StructuredValueFormat,\n type SurfaceName,\n type ValidationError,\n ALL_NAMED_COLORS,\n BODY_NODE_SURFACES,\n ISOMER_ERROR_CODES,\n STRUCTURED_VALUE_FORMATS,\n SURFACE_NAMES,\n CompositionValidationError,\n createChildNodeWalker,\n formatValidationError,\n IsomerError,\n isVisibleOnSurface,\n mapCompositionNodes,\n someBodyNode,\n} from '../composition';\nexport {\n type AnyPrimitiveDefinition,\n type BoundFrame,\n type DefaultPackTypes,\n type ExampleNode,\n type Frame,\n type FrameBody,\n type FrameComposition,\n type FrameDispatcher,\n type FrameHeader,\n type FrameViewport,\n type NormalizedPrimitiveExample,\n type OptionalSurface,\n type PackTypes,\n type PrimitiveCatalogEntry,\n type PrimitiveChildRef,\n type PrimitiveDefinition,\n type PrimitiveExample,\n type PrimitiveIcon,\n type PrimitiveMetrics,\n type PrimitiveRenderContext,\n type PrimitiveSchema,\n type PrimitiveStyleCollectionContext,\n type PrimitiveStyleCollector,\n type ReactContextArg,\n type Renderer,\n type Renderers,\n type RenderScope,\n type StyledRenderContext,\n type StyleHandle,\n type SurfaceMap,\n type ThemePair,\n type ThemeTokenPath,\n type WithNodeFields,\n ICON_VARS,\n OPTIONAL_SURFACES,\n bindFrame,\n definePrimitive,\n definePrimitiveFor,\n exampleNodes,\n formatZodIssues,\n primitiveExamples,\n requiredString,\n unresolvedBodyNodeSchema,\n z,\n} from '../define';\nexport {\n type AnyPrimitivePack,\n type CapabilitySources,\n type ComposedPacks,\n type EnhancementDefinition,\n type HostCapabilities,\n type PackAuthoringOptions,\n type PackStyleAdapter,\n type PrimitiveGroup,\n type PrimitivePack,\n type PrimitivePackInput,\n type SurfaceSupport,\n UNCATEGORIZED_GROUP_TITLE,\n composePacks,\n definePrimitivePack,\n describeCapabilities,\n scopeScript,\n} from '../pack';\nexport {\n type FormatDisplayValueOptions,\n type LayoutBox,\n type LayoutFinding,\n type LayoutRect,\n type PayloadMeasurement,\n type PrimitiveDispatcher,\n type PrimitiveDispatcherOptions,\n LAYOUT_ROOM_ATTRIBUTE,\n NODE_ANCHOR_ATTRIBUTE,\n checkLayout,\n createPrimitiveDispatcher,\n formatDisplayValue,\n isStructuredValue,\n layoutRoom,\n nodeAnchor,\n rawDisplayValue,\n withNodeAnchors,\n withoutAnchors,\n} from '../render';\nexport {\n type AuthoringJsonSchemaOptions,\n type CheckedComposition,\n type CheckedValidationResult,\n type CompositionJsonSchemaOptions,\n type CompositionSchemaOptions,\n type CompositionValidatorOptions,\n type InputBudget,\n type InputBudgetCheck,\n type ParsedComposition,\n type UrlSchemaOptions,\n type ValidationErrorMode,\n type ValidationResult,\n type ValidationWarning,\n ASSET_URL_MESSAGE,\n ASSET_URL_RULE,\n BLOCKED_HREF,\n MAX_INPUT_CHARACTERS,\n MAX_INPUT_DEPTH,\n MAX_INPUT_VALUES,\n NAVIGATION_HREF_MESSAGE,\n NAVIGATION_HREF_RULE,\n assetUrl,\n authoringSchemaSubset,\n buildAuthoringJsonSchema,\n buildCompositionJsonSchema,\n checkInputBudget,\n compositionToRender,\n createCompositionParser,\n createCompositionValidator,\n displayValueSchema,\n getCompositionSchemaForDefinitions,\n isInputRefusal,\n namedColorSchema,\n navigationHref,\n renderThemeSchema,\n sanitizeAssetUrl,\n sanitizeNavigationHref,\n structuredValueSchema,\n warningsForSurface,\n} from '../validate';\n"]}
|
|
@@ -6,9 +6,10 @@
|
|
|
6
6
|
* 2.0.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.serializeMarkdown = exports.renderMarkdownEnvelope = exports.md = void 0;
|
|
9
|
+
exports.splitAuthoredMarkdown = exports.serializeMarkdown = exports.renderMarkdownEnvelope = exports.md = void 0;
|
|
10
10
|
var markdown_1 = require("../render/markdown");
|
|
11
11
|
Object.defineProperty(exports, "md", { enumerable: true, get: function () { return markdown_1.md; } });
|
|
12
12
|
Object.defineProperty(exports, "renderMarkdownEnvelope", { enumerable: true, get: function () { return markdown_1.renderMarkdownEnvelope; } });
|
|
13
13
|
Object.defineProperty(exports, "serializeMarkdown", { enumerable: true, get: function () { return markdown_1.serializeMarkdown; } });
|
|
14
|
+
Object.defineProperty(exports, "splitAuthoredMarkdown", { enumerable: true, get: function () { return markdown_1.splitAuthoredMarkdown; } });
|
|
14
15
|
//# sourceMappingURL=markdown.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown.js","sourceRoot":"","sources":["../../../src/entries/markdown.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AASH,+
|
|
1
|
+
{"version":3,"file":"markdown.js","sourceRoot":"","sources":["../../../src/entries/markdown.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AASH,+CAS4B;AAJ1B,8FAAA,EAAE,OAAA;AACF,kHAAA,sBAAsB,OAAA;AACtB,6GAAA,iBAAiB,OAAA;AACjB,iHAAA,qBAAqB,OAAA","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nexport {\n type MarkdownBlock,\n type MarkdownContent,\n type MarkdownInline,\n type MarkdownInlineInput,\n} from '../define';\n\nexport {\n type AuthoredMarkdownSegment,\n type MarkdownEnvelopeDispatcher,\n type MarkdownEnvelopeOptions,\n type SplitAuthoredMarkdownOptions,\n md,\n renderMarkdownEnvelope,\n serializeMarkdown,\n splitAuthoredMarkdown,\n} from '../render/markdown';\n"]}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* 2.0.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.strike = exports.slackLinkUrl = exports.renderSlackEnvelope = exports.markdownContentToSlackBlocks = exports.link = exports.italic = exports.isSlackReachableImageUrl = exports.
|
|
9
|
+
exports.strike = exports.slackLinkUrl = exports.renderSlackEnvelope = exports.markdownContentToSlackBlocks = exports.link = exports.italic = exports.isSlackReachableImageUrl = exports.escapeMrkdwn = exports.createSlackAssetCollector = exports.codeBlock = exports.code = exports.clampSlackText = exports.bold = exports.SLACK_LIMITS = void 0;
|
|
10
10
|
var slack_1 = require("../render/slack");
|
|
11
11
|
Object.defineProperty(exports, "SLACK_LIMITS", { enumerable: true, get: function () { return slack_1.SLACK_LIMITS; } });
|
|
12
12
|
Object.defineProperty(exports, "bold", { enumerable: true, get: function () { return slack_1.bold; } });
|
|
@@ -15,7 +15,6 @@ Object.defineProperty(exports, "code", { enumerable: true, get: function () { re
|
|
|
15
15
|
Object.defineProperty(exports, "codeBlock", { enumerable: true, get: function () { return slack_1.codeBlock; } });
|
|
16
16
|
Object.defineProperty(exports, "createSlackAssetCollector", { enumerable: true, get: function () { return slack_1.createSlackAssetCollector; } });
|
|
17
17
|
Object.defineProperty(exports, "escapeMrkdwn", { enumerable: true, get: function () { return slack_1.escapeMrkdwn; } });
|
|
18
|
-
Object.defineProperty(exports, "gfmToSlackBlocks", { enumerable: true, get: function () { return slack_1.gfmToSlackBlocks; } });
|
|
19
18
|
Object.defineProperty(exports, "isSlackReachableImageUrl", { enumerable: true, get: function () { return slack_1.isSlackReachableImageUrl; } });
|
|
20
19
|
Object.defineProperty(exports, "italic", { enumerable: true, get: function () { return slack_1.italic; } });
|
|
21
20
|
Object.defineProperty(exports, "link", { enumerable: true, get: function () { return slack_1.link; } });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slack.js","sourceRoot":"","sources":["../../../src/entries/slack.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,
|
|
1
|
+
{"version":3,"file":"slack.js","sourceRoot":"","sources":["../../../src/entries/slack.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,yCA4DyB;AAdvB,qGAAA,YAAY,OAAA;AACZ,6FAAA,IAAI,OAAA;AACJ,uGAAA,cAAc,OAAA;AACd,6FAAA,IAAI,OAAA;AACJ,kGAAA,SAAS,OAAA;AACT,kHAAA,yBAAyB,OAAA;AACzB,qGAAA,YAAY,OAAA;AACZ,iHAAA,wBAAwB,OAAA;AACxB,+FAAA,MAAM,OAAA;AACN,6FAAA,IAAI,OAAA;AACJ,qHAAA,4BAA4B,OAAA;AAC5B,4GAAA,mBAAmB,OAAA;AACnB,qGAAA,YAAY,OAAA;AACZ,+FAAA,MAAM,OAAA","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 SlackActionElement,\n type SlackActionsBlock,\n type SlackAssetCollector,\n type SlackAssetRequest,\n type SlackBlock,\n type SlackButtonElement,\n type SlackCheckboxesElement,\n type SlackContextBlock,\n type SlackDividerBlock,\n type SlackEnvelopeDispatcher,\n type SlackEnvelopeOptions,\n type SlackEnvelopeResult,\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 SLACK_LIMITS,\n bold,\n clampSlackText,\n code,\n codeBlock,\n createSlackAssetCollector,\n escapeMrkdwn,\n isSlackReachableImageUrl,\n italic,\n link,\n markdownContentToSlackBlocks,\n renderSlackEnvelope,\n slackLinkUrl,\n strike,\n} from '../render/slack';\n"]}
|
|
@@ -7,22 +7,27 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.describeCapabilities = void 0;
|
|
10
|
+
/** The one surface whose output is not itself a shippable format. */
|
|
11
|
+
const SNAPSHOT = 'snapshot';
|
|
10
12
|
/**
|
|
11
|
-
* Reports the primitive types and
|
|
13
|
+
* Reports the primitive types, surfaces, and formats a set of packs supports.
|
|
12
14
|
*
|
|
13
|
-
* `
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* particular depends on a frame, which is a runtime input and not a pack's to
|
|
18
|
-
* report.
|
|
19
|
-
* @param formats Candidate formats this caller can reach.
|
|
15
|
+
* `surfaces` is passed rather than derived because only the caller knows which
|
|
16
|
+
* exist. Every surface but `snapshot` is also a format; `formats` adds the ones
|
|
17
|
+
* no surface produces on its own, so a `png` is reported only when a host
|
|
18
|
+
* registers the rasterizer that writes it.
|
|
20
19
|
*/
|
|
21
|
-
const describeCapabilities = (packs, formats) => {
|
|
20
|
+
const describeCapabilities = (packs, { surfaces, formats = [] }) => {
|
|
22
21
|
const enhancementIds = packs.flatMap((pack) => pack.enhancements.map((definition) => definition.id));
|
|
22
|
+
const definitions = packs.flatMap((pack) => pack.primitives);
|
|
23
23
|
return {
|
|
24
|
-
primitives:
|
|
25
|
-
|
|
24
|
+
primitives: definitions.map(({ type }) => type),
|
|
25
|
+
surfaces: [...surfaces],
|
|
26
|
+
formats: [...new Set([...surfaces, ...formats])].filter((format) => format !== SNAPSHOT),
|
|
27
|
+
support: Object.fromEntries(definitions.map((definition) => [
|
|
28
|
+
definition.type,
|
|
29
|
+
Object.fromEntries(surfaces.map((surface) => [surface, supportOn(definition, surface)])),
|
|
30
|
+
])),
|
|
26
31
|
...(enhancementIds.length > 0
|
|
27
32
|
? {
|
|
28
33
|
enhancements: Object.fromEntries(enhancementIds.map((id) => [id, true])),
|
|
@@ -31,4 +36,5 @@ const describeCapabilities = (packs, formats) => {
|
|
|
31
36
|
};
|
|
32
37
|
};
|
|
33
38
|
exports.describeCapabilities = describeCapabilities;
|
|
39
|
+
const supportOn = ({ renderers }, surface) => surface === 'slack' && renderers.slack === undefined ? 'fallback' : 'native';
|
|
34
40
|
//# sourceMappingURL=capabilities.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capabilities.js","sourceRoot":"","sources":["../../../src/pack/capabilities.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;
|
|
1
|
+
{"version":3,"file":"capabilities.js","sourceRoot":"","sources":["../../../src/pack/capabilities.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AA4CH,qEAAqE;AACrE,MAAM,QAAQ,GAAG,UAAU,CAAC;AAE5B;;;;;;;GAOG;AACI,MAAM,oBAAoB,GAAG,CAClC,KAAkC,EAClC,EAAE,QAAQ,EAAE,OAAO,GAAG,EAAE,EAAqB,EAC3B,EAAE;IACpB,MAAM,cAAc,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAC5C,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,CACrD,CAAC;IACF,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAC7D,OAAO;QACL,UAAU,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC;QAC/C,QAAQ,EAAE,CAAC,GAAG,QAAQ,CAAC;QACvB,OAAO,EAAE,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,QAAQ,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CACrD,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,KAAK,QAAQ,CAChC;QACD,OAAO,EAAE,MAAM,CAAC,WAAW,CACzB,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC;YAC9B,UAAU,CAAC,IAAI;YACf,MAAM,CAAC,WAAW,CAChB,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC,CACrE;SACF,CAAC,CACH;QACD,GAAG,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC;YAC3B,CAAC,CAAC;gBACE,YAAY,EAAE,MAAM,CAAC,WAAW,CAC9B,cAAc,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC,CACvC;aACF;YACH,CAAC,CAAC,EAAE,CAAC;KACR,CAAC;AACJ,CAAC,CAAC;AA9BW,QAAA,oBAAoB,wBA8B/B;AAEF,MAAM,SAAS,GAAG,CAChB,EAAE,SAAS,EAA0B,EACrC,OAAe,EACC,EAAE,CAClB,OAAO,KAAK,OAAO,IAAI,SAAS,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,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// What a host can render, reported from packs rather than asserted by hand.\n//\n// Lives in the sdk so both the assembly layer and a pack import it from the\n// same place; a pack must not have to depend on the assembly layer for it.\n\nimport type { AnyPrimitiveDefinition } from '../define/primitive_module';\n\nimport type { AnyPrimitivePack } from './primitive_pack';\n\n/** `native` renders through the primitive's own renderer, `fallback` through another surface's (Slack via markdown). */\nexport type SurfaceSupport = 'native' | 'fallback';\n\n/**\n * What a runtime or a pack supports. Enhancement ids are open strings: each\n * pack declares its own on {@link PrimitivePack.enhancements}, and a runtime\n * reports the union.\n */\nexport interface HostCapabilities<TEnhancement extends string = string> {\n /** Primitive `type` values that can be dispatched. */\n primitives: string[];\n /** Surfaces that render, e.g. `html`, `slack`, `snapshot`. */\n surfaces: string[];\n /** Formats the host can ship, e.g. `html`, `slack`, `png`. Never `snapshot`, which only a rasterizer turns into a format. */\n formats: string[];\n /**\n * How each of `surfaces` renders each primitive, keyed by `type` then surface.\n * `slack` is `fallback` for a primitive with no `slack` renderer; every other\n * surface renders from `react`, `text`, or `markdown`, which are required.\n */\n support: Record<string, Record<string, SurfaceSupport>>;\n /** Progressive enhancements the packs declare, by id, which an HTML or React render may request. */\n enhancements?: Partial<Record<TEnhancement, boolean>>;\n}\n\n/** What {@link describeCapabilities} reports beyond the packs themselves. */\nexport interface CapabilitySources {\n /** The surfaces the caller built; `snapshot` exists only when a host supplied a frame. */\n surfaces: readonly string[];\n /** Formats produced outside the surfaces, such as a rasterizer's `png`. */\n formats?: readonly string[];\n}\n\n/** The one surface whose output is not itself a shippable format. */\nconst SNAPSHOT = 'snapshot';\n\n/**\n * Reports the primitive types, surfaces, and formats a set of packs supports.\n *\n * `surfaces` is passed rather than derived because only the caller knows which\n * exist. Every surface but `snapshot` is also a format; `formats` adds the ones\n * no surface produces on its own, so a `png` is reported only when a host\n * registers the rasterizer that writes it.\n */\nexport const describeCapabilities = (\n packs: readonly AnyPrimitivePack[],\n { surfaces, formats = [] }: CapabilitySources\n): HostCapabilities => {\n const enhancementIds = packs.flatMap((pack) =>\n pack.enhancements.map((definition) => definition.id)\n );\n const definitions = packs.flatMap((pack) => pack.primitives);\n return {\n primitives: definitions.map(({ type }) => type),\n surfaces: [...surfaces],\n formats: [...new Set([...surfaces, ...formats])].filter(\n (format) => format !== SNAPSHOT\n ),\n support: Object.fromEntries(\n definitions.map((definition) => [\n definition.type,\n Object.fromEntries(\n surfaces.map((surface) => [surface, supportOn(definition, surface)])\n ),\n ])\n ),\n ...(enhancementIds.length > 0\n ? {\n enhancements: Object.fromEntries(\n enhancementIds.map((id) => [id, true])\n ),\n }\n : {}),\n };\n};\n\nconst supportOn = (\n { renderers }: AnyPrimitiveDefinition,\n surface: string\n): SurfaceSupport =>\n surface === 'slack' && renderers.slack === undefined ? 'fallback' : 'native';\n"]}
|
package/dist/cjs/pack/compose.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.composePacks = void 0;
|
|
10
10
|
const error_1 = require("../composition/error");
|
|
11
|
+
const primitive_pack_1 = require("./primitive_pack");
|
|
11
12
|
/**
|
|
12
13
|
* Flattens `packs` into one inventory, rejecting cross-pack duplicate node
|
|
13
14
|
* types and duplicate enhancement ids. Every offender is named in one error,
|
|
@@ -37,9 +38,11 @@ const composePacks = (packs) => {
|
|
|
37
38
|
}
|
|
38
39
|
assertUnique('DUPLICATE_PRIMITIVE_TYPE', 'primitive type', typeOwners);
|
|
39
40
|
assertUnique('DUPLICATE_ENHANCEMENT', 'enhancement', enhancementOwners);
|
|
41
|
+
const definitions = packs.flatMap((pack) => [...pack.primitives]);
|
|
40
42
|
return Object.freeze({
|
|
41
|
-
definitions: Object.freeze(
|
|
43
|
+
definitions: Object.freeze(definitions),
|
|
42
44
|
enhancements: Object.freeze(packs.flatMap((pack) => [...pack.enhancements])),
|
|
45
|
+
icons: (0, primitive_pack_1.iconsByType)(definitions),
|
|
43
46
|
slackAssetTypes: new Set(packs.flatMap((pack) => [...pack.slackAssetTypes])),
|
|
44
47
|
});
|
|
45
48
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compose.js","sourceRoot":"","sources":["../../../src/pack/compose.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,gDAAmD;
|
|
1
|
+
{"version":3,"file":"compose.js","sourceRoot":"","sources":["../../../src/pack/compose.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,gDAAmD;AAKnD,qDAAsE;AAgBtE;;;;GAIG;AACI,MAAM,YAAY,GAAG,CAC1B,KAAkC,EACnB,EAAE;IACjB,MAAM,UAAU,GAAG,IAAI,GAAG,EAAoB,CAAC;IAC/C,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAoB,CAAC;IACtD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,KAAK,MAAM,EAAE,IAAI,EAAE,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACvC,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;QACnE,CAAC;QACD,KAAK,MAAM,EAAE,EAAE,EAAE,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACvC,iBAAiB,CAAC,GAAG,CAAC,EAAE,EAAE;gBACxB,GAAG,CAAC,iBAAiB,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC;gBACpC,IAAI,CAAC,EAAE;aACR,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IACD,MAAM,QAAQ,GAAG;QACf,GAAG,IAAI,GAAG,CACR,KAAK;aACF,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC;aACnB,MAAM,CAAC,CAAC,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,KAAK,CAAC,CACzD;KACF,CAAC;IACF,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,mBAAW,CACnB,mBAAmB,EACnB,iBAAiB,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,oDAAoD,CAChH,CAAC;IACJ,CAAC;IACD,YAAY,CAAC,0BAA0B,EAAE,gBAAgB,EAAE,UAAU,CAAC,CAAC;IACvE,YAAY,CAAC,uBAAuB,EAAE,aAAa,EAAE,iBAAiB,CAAC,CAAC;IAExE,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;IAClE,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC;QACvC,YAAY,EAAE,MAAM,CAAC,MAAM,CACzB,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC,CAChD;QACD,KAAK,EAAE,IAAA,4BAAW,EAAC,WAAW,CAAC;QAC/B,eAAe,EAAE,IAAI,GAAG,CACtB,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,eAAe,CAAC,CAAC,CACnD;KACF,CAAC,CAAC;AACL,CAAC,CAAC;AA3CW,QAAA,YAAY,gBA2CvB;AAEF,MAAM,YAAY,GAAG,CACnB,IAA0D,EAC1D,IAAY,EACZ,MAA8C,EACxC,EAAE;IACR,MAAM,UAAU,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACvE,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5B,OAAO;IACT,CAAC;IACD,MAAM,IAAI,mBAAW,CACnB,IAAI,EACJ,UAAU;SACP,GAAG,CACF,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CACf,GAAG,IAAI,KAAK,GAAG,mBAAmB,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CACjF;SACA,IAAI,CAAC,IAAI,CAAC,CACd,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\nimport { IsomerError } from '../composition/error';\nimport type { PrimitiveIcon } from '../define/primitive_icon';\nimport type { AnyPrimitiveDefinition } from '../define/primitive_module';\n\nimport type { EnhancementDefinition } from './enhancements';\nimport { type AnyPrimitivePack, iconsByType } from './primitive_pack';\n\n/**\n * One flattened inventory owned by {@link composePacks}.\n *\n * `definitions` is a stable array identity, which is what the composition\n * schema cache keys on — pass it through rather than flattening packs per call.\n */\nexport interface ComposedPacks {\n readonly definitions: readonly AnyPrimitiveDefinition[];\n readonly enhancements: readonly EnhancementDefinition[];\n /** Every definition's `icon` by type, in one frozen null-prototype dictionary. */\n readonly icons: Readonly<Record<string, PrimitiveIcon>>;\n readonly slackAssetTypes: ReadonlySet<string>;\n}\n\n/**\n * Flattens `packs` into one inventory, rejecting cross-pack duplicate node\n * types and duplicate enhancement ids. Every offender is named in one error,\n * so a bad three-pack composition reports all three at once.\n */\nexport const composePacks = (\n packs: readonly AnyPrimitivePack[]\n): ComposedPacks => {\n const typeOwners = new Map<string, string[]>();\n const enhancementOwners = new Map<string, string[]>();\n for (const pack of packs) {\n for (const { type } of pack.primitives) {\n typeOwners.set(type, [...(typeOwners.get(type) ?? []), pack.id]);\n }\n for (const { id } of pack.enhancements) {\n enhancementOwners.set(id, [\n ...(enhancementOwners.get(id) ?? []),\n pack.id,\n ]);\n }\n }\n const repeated = [\n ...new Set(\n packs\n .map(({ id }) => id)\n .filter((id, index, ids) => ids.indexOf(id) !== index)\n ),\n ];\n if (repeated.length > 0) {\n throw new IsomerError(\n 'DUPLICATE_PACK_ID',\n `composePacks: ${repeated.map((id) => `\"${id}\"`).join(', ')} names more than one pack; pack ids must be unique`\n );\n }\n assertUnique('DUPLICATE_PRIMITIVE_TYPE', 'primitive type', typeOwners);\n assertUnique('DUPLICATE_ENHANCEMENT', 'enhancement', enhancementOwners);\n\n const definitions = packs.flatMap((pack) => [...pack.primitives]);\n return Object.freeze({\n definitions: Object.freeze(definitions),\n enhancements: Object.freeze(\n packs.flatMap((pack) => [...pack.enhancements])\n ),\n icons: iconsByType(definitions),\n slackAssetTypes: new Set(\n packs.flatMap((pack) => [...pack.slackAssetTypes])\n ),\n });\n};\n\nconst assertUnique = (\n code: 'DUPLICATE_ENHANCEMENT' | 'DUPLICATE_PRIMITIVE_TYPE',\n noun: string,\n owners: ReadonlyMap<string, readonly string[]>\n): void => {\n const duplicates = [...owners].filter(([, packs]) => packs.length > 1);\n if (duplicates.length === 0) {\n return;\n }\n throw new IsomerError(\n code,\n duplicates\n .map(\n ([key, packs]) =>\n `${noun} \"${key}\" registered by ${packs.map((id) => `\"${id}\"`).join(' and ')}`\n )\n .join('; ')\n );\n};\n"]}
|
package/dist/cjs/pack/index.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* 2.0.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.definePrimitivePack = exports.scopeScript = exports.composePacks = exports.describeCapabilities = void 0;
|
|
9
|
+
exports.definePrimitivePack = exports.UNCATEGORIZED_GROUP_TITLE = exports.scopeScript = exports.composePacks = exports.describeCapabilities = void 0;
|
|
10
10
|
var capabilities_1 = require("./capabilities");
|
|
11
11
|
Object.defineProperty(exports, "describeCapabilities", { enumerable: true, get: function () { return capabilities_1.describeCapabilities; } });
|
|
12
12
|
var compose_1 = require("./compose");
|
|
@@ -14,5 +14,6 @@ Object.defineProperty(exports, "composePacks", { enumerable: true, get: function
|
|
|
14
14
|
var enhancements_1 = require("./enhancements");
|
|
15
15
|
Object.defineProperty(exports, "scopeScript", { enumerable: true, get: function () { return enhancements_1.scopeScript; } });
|
|
16
16
|
var primitive_pack_1 = require("./primitive_pack");
|
|
17
|
+
Object.defineProperty(exports, "UNCATEGORIZED_GROUP_TITLE", { enumerable: true, get: function () { return primitive_pack_1.UNCATEGORIZED_GROUP_TITLE; } });
|
|
17
18
|
Object.defineProperty(exports, "definePrimitivePack", { enumerable: true, get: function () { return primitive_pack_1.definePrimitivePack; } });
|
|
18
19
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/pack/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,+
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/pack/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,+CAKwB;AADtB,oHAAA,oBAAoB,OAAA;AAEtB,qCAA6D;AAAhC,uGAAA,YAAY,OAAA;AACzC,+CAAyE;AAApC,2GAAA,WAAW,OAAA;AAChD,mDAS0B;AAFxB,2HAAA,yBAAyB,OAAA;AACzB,qHAAA,mBAAmB,OAAA","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nexport {\n type CapabilitySources,\n type HostCapabilities,\n type SurfaceSupport,\n describeCapabilities,\n} from './capabilities';\nexport { type ComposedPacks, composePacks } from './compose';\nexport { type EnhancementDefinition, scopeScript } from './enhancements';\nexport {\n type AnyPrimitivePack,\n type PackAuthoringOptions,\n type PackStyleAdapter,\n type PrimitiveGroup,\n type PrimitivePack,\n type PrimitivePackInput,\n UNCATEGORIZED_GROUP_TITLE,\n definePrimitivePack,\n} from './primitive_pack';\n"]}
|