@elastic/isomer-sdk 0.0.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +93 -0
- package/NOTICE.txt +1861 -0
- package/README.md +69 -0
- package/THIRD_PARTY_LICENSES.md +957 -0
- package/dist/author/authored_fields.d.ts +153 -0
- package/dist/author/authored_fields.d.ts.map +1 -0
- package/dist/author/authored_fields.js +227 -0
- package/dist/author/authored_fields.js.map +1 -0
- package/dist/author/authoring_input.d.ts +7 -0
- package/dist/author/authoring_input.d.ts.map +1 -0
- package/dist/author/authoring_input.js +60 -0
- package/dist/author/authoring_input.js.map +1 -0
- package/dist/author/authoring_model.d.ts +27 -0
- package/dist/author/authoring_model.d.ts.map +1 -0
- package/dist/author/authoring_model.js +98 -0
- package/dist/author/authoring_model.js.map +1 -0
- package/dist/author/declarations.d.ts +13 -0
- package/dist/author/declarations.d.ts.map +1 -0
- package/dist/author/declarations.js +277 -0
- package/dist/author/declarations.js.map +1 -0
- package/dist/author/index.d.ts +7 -0
- package/dist/author/index.d.ts.map +1 -0
- package/dist/author/index.js +12 -0
- package/dist/author/index.js.map +1 -0
- package/dist/author/jsx.d.ts +21 -0
- package/dist/author/jsx.d.ts.map +1 -0
- package/dist/author/jsx.js +20 -0
- package/dist/author/jsx.js.map +1 -0
- package/dist/author/jsx_shim.d.ts +117 -0
- package/dist/author/jsx_shim.d.ts.map +1 -0
- package/dist/author/jsx_shim.js +270 -0
- package/dist/author/jsx_shim.js.map +1 -0
- package/dist/author/prompt.d.ts +58 -0
- package/dist/author/prompt.d.ts.map +1 -0
- package/dist/author/prompt.js +148 -0
- package/dist/author/prompt.js.map +1 -0
- package/dist/author/schema_to_typescript.d.ts +37 -0
- package/dist/author/schema_to_typescript.d.ts.map +1 -0
- package/dist/author/schema_to_typescript.js +286 -0
- package/dist/author/schema_to_typescript.js.map +1 -0
- package/dist/cjs/author/authored_fields.js +233 -0
- package/dist/cjs/author/authored_fields.js.map +1 -0
- package/dist/cjs/author/authoring_input.js +64 -0
- package/dist/cjs/author/authoring_input.js.map +1 -0
- package/dist/cjs/author/authoring_model.js +104 -0
- package/dist/cjs/author/authoring_model.js.map +1 -0
- package/dist/cjs/author/declarations.js +281 -0
- package/dist/cjs/author/declarations.js.map +1 -0
- package/dist/cjs/author/index.js +25 -0
- package/dist/cjs/author/index.js.map +1 -0
- package/dist/cjs/author/jsx.js +24 -0
- package/dist/cjs/author/jsx.js.map +1 -0
- package/dist/cjs/author/jsx_shim.js +276 -0
- package/dist/cjs/author/jsx_shim.js.map +1 -0
- package/dist/cjs/author/prompt.js +153 -0
- package/dist/cjs/author/prompt.js.map +1 -0
- package/dist/cjs/author/schema_to_typescript.js +295 -0
- package/dist/cjs/author/schema_to_typescript.js.map +1 -0
- package/dist/cjs/composition/action_event.js +9 -0
- package/dist/cjs/composition/action_event.js.map +1 -0
- package/dist/cjs/composition/body_node_base.js +112 -0
- package/dist/cjs/composition/body_node_base.js.map +1 -0
- package/dist/cjs/composition/composition.js +9 -0
- package/dist/cjs/composition/composition.js.map +1 -0
- package/dist/cjs/composition/error.js +73 -0
- package/dist/cjs/composition/error.js.map +1 -0
- package/dist/cjs/composition/index.js +32 -0
- package/dist/cjs/composition/index.js.map +1 -0
- package/dist/cjs/composition/map_nodes.js +85 -0
- package/dist/cjs/composition/map_nodes.js.map +1 -0
- package/dist/cjs/composition/named_color.js +20 -0
- package/dist/cjs/composition/named_color.js.map +1 -0
- package/dist/cjs/composition/node.js +9 -0
- package/dist/cjs/composition/node.js.map +1 -0
- package/dist/cjs/composition/one_line.js +23 -0
- package/dist/cjs/composition/one_line.js.map +1 -0
- package/dist/cjs/composition/structured_value.js +21 -0
- package/dist/cjs/composition/structured_value.js.map +1 -0
- package/dist/cjs/composition/validation_error.js +40 -0
- package/dist/cjs/composition/validation_error.js.map +1 -0
- package/dist/cjs/define/frame.js +31 -0
- package/dist/cjs/define/frame.js.map +1 -0
- package/dist/cjs/define/index.js +31 -0
- package/dist/cjs/define/index.js.map +1 -0
- package/dist/cjs/define/markdown_content.js +12 -0
- package/dist/cjs/define/markdown_content.js.map +1 -0
- 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 +118 -0
- package/dist/cjs/define/primitive_module.js.map +1 -0
- package/dist/cjs/define/slack_assets.js +9 -0
- package/dist/cjs/define/slack_assets.js.map +1 -0
- package/dist/cjs/define/slack_blocks.js +9 -0
- package/dist/cjs/define/slack_blocks.js.map +1 -0
- package/dist/cjs/define/zod_format.js +122 -0
- package/dist/cjs/define/zod_format.js.map +1 -0
- package/dist/cjs/define/zod_helpers.js +26 -0
- package/dist/cjs/define/zod_helpers.js.map +1 -0
- package/dist/cjs/entries/html.js +12 -0
- package/dist/cjs/entries/html.js.map +1 -0
- package/dist/cjs/entries/index.js +80 -0
- package/dist/cjs/entries/index.js.map +1 -0
- package/dist/cjs/entries/markdown.js +14 -0
- package/dist/cjs/entries/markdown.js.map +1 -0
- package/dist/cjs/entries/react.js +20 -0
- package/dist/cjs/entries/react.js.map +1 -0
- package/dist/cjs/entries/slack.js +25 -0
- package/dist/cjs/entries/slack.js.map +1 -0
- package/dist/cjs/entries/text.js +12 -0
- package/dist/cjs/entries/text.js.map +1 -0
- package/dist/cjs/pack/capabilities.js +40 -0
- package/dist/cjs/pack/capabilities.js.map +1 -0
- package/dist/cjs/pack/compose.js +59 -0
- package/dist/cjs/pack/compose.js.map +1 -0
- package/dist/cjs/pack/enhancements.js +65 -0
- package/dist/cjs/pack/enhancements.js.map +1 -0
- package/dist/cjs/pack/index.js +18 -0
- package/dist/cjs/pack/index.js.map +1 -0
- package/dist/cjs/pack/primitive_pack.js +97 -0
- package/dist/cjs/pack/primitive_pack.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/render/anchors.js +167 -0
- package/dist/cjs/render/anchors.js.map +1 -0
- package/dist/cjs/render/context_view.js +54 -0
- package/dist/cjs/render/context_view.js.map +1 -0
- package/dist/cjs/render/format_display_value.js +143 -0
- package/dist/cjs/render/format_display_value.js.map +1 -0
- package/dist/cjs/render/format_number.js +46 -0
- package/dist/cjs/render/format_number.js.map +1 -0
- package/dist/cjs/render/html/enhancements.js +30 -0
- package/dist/cjs/render/html/enhancements.js.map +1 -0
- package/dist/cjs/render/html/envelope.js +218 -0
- package/dist/cjs/render/html/envelope.js.map +1 -0
- package/dist/cjs/render/html/index.js +12 -0
- package/dist/cjs/render/html/index.js.map +1 -0
- package/dist/cjs/render/index.js +25 -0
- package/dist/cjs/render/index.js.map +1 -0
- package/dist/cjs/render/layout_check.js +133 -0
- package/dist/cjs/render/layout_check.js.map +1 -0
- package/dist/cjs/render/markdown/builder.js +195 -0
- package/dist/cjs/render/markdown/builder.js.map +1 -0
- package/dist/cjs/render/markdown/envelope.js +33 -0
- package/dist/cjs/render/markdown/envelope.js.map +1 -0
- package/dist/cjs/render/markdown/format.js +208 -0
- package/dist/cjs/render/markdown/format.js.map +1 -0
- package/dist/cjs/render/markdown/index.js +15 -0
- package/dist/cjs/render/markdown/index.js.map +1 -0
- package/dist/cjs/render/measure_dom.js +61 -0
- package/dist/cjs/render/measure_dom.js.map +1 -0
- package/dist/cjs/render/payload.js +13 -0
- package/dist/cjs/render/payload.js.map +1 -0
- package/dist/cjs/render/primitive_dispatch.js +173 -0
- package/dist/cjs/render/primitive_dispatch.js.map +1 -0
- package/dist/cjs/render/react/content.js +44 -0
- package/dist/cjs/render/react/content.js.map +1 -0
- package/dist/cjs/render/react/enhancements.js +32 -0
- package/dist/cjs/render/react/enhancements.js.map +1 -0
- package/dist/cjs/render/react/index.js +15 -0
- package/dist/cjs/render/react/index.js.map +1 -0
- package/dist/cjs/render/slack/assets.js +45 -0
- package/dist/cjs/render/slack/assets.js.map +1 -0
- package/dist/cjs/render/slack/blocks.js +80 -0
- package/dist/cjs/render/slack/blocks.js.map +1 -0
- package/dist/cjs/render/slack/envelope.js +551 -0
- package/dist/cjs/render/slack/envelope.js.map +1 -0
- package/dist/cjs/render/slack/format.js +225 -0
- package/dist/cjs/render/slack/format.js.map +1 -0
- package/dist/cjs/render/slack/index.js +30 -0
- package/dist/cjs/render/slack/index.js.map +1 -0
- package/dist/cjs/render/slack/markdown_content.js +409 -0
- package/dist/cjs/render/slack/markdown_content.js.map +1 -0
- package/dist/cjs/render/text/envelope.js +21 -0
- package/dist/cjs/render/text/envelope.js.map +1 -0
- package/dist/cjs/render/text/index.js +12 -0
- package/dist/cjs/render/text/index.js.map +1 -0
- package/dist/cjs/testing/conformance.js +312 -0
- package/dist/cjs/testing/conformance.js.map +1 -0
- package/dist/cjs/testing/icon.js +248 -0
- package/dist/cjs/testing/icon.js.map +1 -0
- package/dist/cjs/testing/index.js +18 -0
- package/dist/cjs/testing/index.js.map +1 -0
- package/dist/cjs/testing/registration.js +142 -0
- package/dist/cjs/testing/registration.js.map +1 -0
- package/dist/cjs/validate/authoring_schema.js +312 -0
- package/dist/cjs/validate/authoring_schema.js.map +1 -0
- package/dist/cjs/validate/composition_schema.js +135 -0
- package/dist/cjs/validate/composition_schema.js.map +1 -0
- package/dist/cjs/validate/index.js +53 -0
- package/dist/cjs/validate/index.js.map +1 -0
- package/dist/cjs/validate/input_budget.js +156 -0
- package/dist/cjs/validate/input_budget.js.map +1 -0
- package/dist/cjs/validate/json_schema.js +72 -0
- package/dist/cjs/validate/json_schema.js.map +1 -0
- package/dist/cjs/validate/node_issues.js +65 -0
- package/dist/cjs/validate/node_issues.js.map +1 -0
- package/dist/cjs/validate/url.js +116 -0
- package/dist/cjs/validate/url.js.map +1 -0
- package/dist/cjs/validate/validation.js +165 -0
- package/dist/cjs/validate/validation.js.map +1 -0
- package/dist/cjs/validate/value_schemas.js +53 -0
- package/dist/cjs/validate/value_schemas.js.map +1 -0
- package/dist/composition/action_event.d.ts +13 -0
- package/dist/composition/action_event.d.ts.map +1 -0
- package/dist/composition/action_event.js +8 -0
- package/dist/composition/action_event.js.map +1 -0
- package/dist/composition/body_node_base.d.ts +72 -0
- package/dist/composition/body_node_base.d.ts.map +1 -0
- package/dist/composition/body_node_base.js +104 -0
- package/dist/composition/body_node_base.js.map +1 -0
- package/dist/composition/composition.d.ts +71 -0
- package/dist/composition/composition.d.ts.map +1 -0
- package/dist/composition/composition.js +8 -0
- package/dist/composition/composition.js.map +1 -0
- package/dist/composition/error.d.ts +61 -0
- package/dist/composition/error.d.ts.map +1 -0
- package/dist/composition/error.js +69 -0
- package/dist/composition/error.js.map +1 -0
- package/dist/composition/index.d.ts +11 -0
- package/dist/composition/index.d.ts.map +1 -0
- package/dist/composition/index.js +14 -0
- package/dist/composition/index.js.map +1 -0
- package/dist/composition/map_nodes.d.ts +16 -0
- package/dist/composition/map_nodes.d.ts.map +1 -0
- package/dist/composition/map_nodes.js +81 -0
- package/dist/composition/map_nodes.js.map +1 -0
- package/dist/composition/named_color.d.ts +9 -0
- package/dist/composition/named_color.d.ts.map +1 -0
- package/dist/composition/named_color.js +17 -0
- package/dist/composition/named_color.js.map +1 -0
- package/dist/composition/node.d.ts +11 -0
- package/dist/composition/node.d.ts.map +1 -0
- package/dist/composition/node.js +8 -0
- package/dist/composition/node.js.map +1 -0
- package/dist/composition/one_line.d.ts +7 -0
- package/dist/composition/one_line.d.ts.map +1 -0
- package/dist/composition/one_line.js +17 -0
- package/dist/composition/one_line.js.map +1 -0
- package/dist/composition/structured_value.d.ts +27 -0
- package/dist/composition/structured_value.d.ts.map +1 -0
- package/dist/composition/structured_value.js +18 -0
- package/dist/composition/structured_value.js.map +1 -0
- package/dist/composition/validation_error.d.ts +33 -0
- package/dist/composition/validation_error.d.ts.map +1 -0
- package/dist/composition/validation_error.js +35 -0
- package/dist/composition/validation_error.js.map +1 -0
- package/dist/define/frame.d.ts +155 -0
- package/dist/define/frame.d.ts.map +1 -0
- package/dist/define/frame.js +27 -0
- package/dist/define/frame.js.map +1 -0
- package/dist/define/index.d.ts +10 -0
- package/dist/define/index.d.ts.map +1 -0
- package/dist/define/index.js +13 -0
- package/dist/define/index.js.map +1 -0
- package/dist/define/markdown_content.d.ts +15 -0
- package/dist/define/markdown_content.d.ts.map +1 -0
- package/dist/define/markdown_content.js +9 -0
- package/dist/define/markdown_content.js.map +1 -0
- 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 +435 -0
- package/dist/define/primitive_module.d.ts.map +1 -0
- package/dist/define/primitive_module.js +112 -0
- package/dist/define/primitive_module.js.map +1 -0
- package/dist/define/slack_assets.d.ts +28 -0
- package/dist/define/slack_assets.d.ts.map +1 -0
- package/dist/define/slack_assets.js +8 -0
- package/dist/define/slack_assets.js.map +1 -0
- package/dist/define/slack_blocks.d.ts +234 -0
- package/dist/define/slack_blocks.d.ts.map +1 -0
- package/dist/define/slack_blocks.js +8 -0
- package/dist/define/slack_blocks.js.map +1 -0
- package/dist/define/zod_format.d.ts +33 -0
- package/dist/define/zod_format.d.ts.map +1 -0
- package/dist/define/zod_format.js +114 -0
- package/dist/define/zod_format.js.map +1 -0
- package/dist/define/zod_helpers.d.ts +10 -0
- package/dist/define/zod_helpers.d.ts.map +1 -0
- package/dist/define/zod_helpers.js +22 -0
- package/dist/define/zod_helpers.js.map +1 -0
- package/dist/entries/html.d.ts +3 -0
- package/dist/entries/html.d.ts.map +1 -0
- package/dist/entries/html.js +8 -0
- package/dist/entries/html.js.map +1 -0
- package/dist/entries/index.d.ts +6 -0
- package/dist/entries/index.d.ts.map +1 -0
- package/dist/entries/index.js +12 -0
- package/dist/entries/index.js.map +1 -0
- package/dist/entries/markdown.d.ts +3 -0
- package/dist/entries/markdown.d.ts.map +1 -0
- package/dist/entries/markdown.js +8 -0
- package/dist/entries/markdown.js.map +1 -0
- package/dist/entries/react.d.ts +5 -0
- package/dist/entries/react.d.ts.map +1 -0
- package/dist/entries/react.js +11 -0
- package/dist/entries/react.js.map +1 -0
- package/dist/entries/slack.d.ts +2 -0
- package/dist/entries/slack.d.ts.map +1 -0
- package/dist/entries/slack.js +8 -0
- package/dist/entries/slack.js.map +1 -0
- package/dist/entries/text.d.ts +2 -0
- package/dist/entries/text.d.ts.map +1 -0
- package/dist/entries/text.js +8 -0
- package/dist/entries/text.js.map +1 -0
- package/dist/pack/capabilities.d.ts +41 -0
- package/dist/pack/capabilities.d.ts.map +1 -0
- package/dist/pack/capabilities.js +36 -0
- package/dist/pack/capabilities.js.map +1 -0
- package/dist/pack/compose.d.ts +24 -0
- package/dist/pack/compose.d.ts.map +1 -0
- package/dist/pack/compose.js +55 -0
- package/dist/pack/compose.js.map +1 -0
- package/dist/pack/enhancements.d.ts +65 -0
- package/dist/pack/enhancements.d.ts.map +1 -0
- package/dist/pack/enhancements.js +59 -0
- package/dist/pack/enhancements.js.map +1 -0
- package/dist/pack/index.d.ts +5 -0
- package/dist/pack/index.d.ts.map +1 -0
- package/dist/pack/index.js +11 -0
- package/dist/pack/index.js.map +1 -0
- package/dist/pack/primitive_pack.d.ts +164 -0
- package/dist/pack/primitive_pack.d.ts.map +1 -0
- package/dist/pack/primitive_pack.js +92 -0
- package/dist/pack/primitive_pack.js.map +1 -0
- package/dist/render/anchors.d.ts +82 -0
- package/dist/render/anchors.d.ts.map +1 -0
- package/dist/render/anchors.js +153 -0
- package/dist/render/anchors.js.map +1 -0
- package/dist/render/context_view.d.ts +10 -0
- package/dist/render/context_view.d.ts.map +1 -0
- package/dist/render/context_view.js +49 -0
- package/dist/render/context_view.js.map +1 -0
- package/dist/render/format_display_value.d.ts +20 -0
- package/dist/render/format_display_value.d.ts.map +1 -0
- package/dist/render/format_display_value.js +137 -0
- package/dist/render/format_display_value.js.map +1 -0
- package/dist/render/format_number.d.ts +9 -0
- package/dist/render/format_number.d.ts.map +1 -0
- package/dist/render/format_number.js +42 -0
- package/dist/render/format_number.js.map +1 -0
- package/dist/render/html/enhancements.d.ts +10 -0
- package/dist/render/html/enhancements.d.ts.map +1 -0
- package/dist/render/html/enhancements.js +25 -0
- package/dist/render/html/enhancements.js.map +1 -0
- package/dist/render/html/envelope.d.ts +182 -0
- package/dist/render/html/envelope.d.ts.map +1 -0
- package/dist/render/html/envelope.js +214 -0
- package/dist/render/html/envelope.js.map +1 -0
- package/dist/render/html/index.d.ts +3 -0
- package/dist/render/html/index.d.ts.map +1 -0
- package/dist/render/html/index.js +8 -0
- package/dist/render/html/index.js.map +1 -0
- package/dist/render/index.d.ts +6 -0
- package/dist/render/index.d.ts.map +1 -0
- package/dist/render/index.js +11 -0
- package/dist/render/index.js.map +1 -0
- package/dist/render/layout_check.d.ts +43 -0
- package/dist/render/layout_check.d.ts.map +1 -0
- package/dist/render/layout_check.js +129 -0
- package/dist/render/layout_check.js.map +1 -0
- package/dist/render/markdown/builder.d.ts +46 -0
- package/dist/render/markdown/builder.d.ts.map +1 -0
- package/dist/render/markdown/builder.js +190 -0
- package/dist/render/markdown/builder.js.map +1 -0
- package/dist/render/markdown/envelope.d.ts +20 -0
- package/dist/render/markdown/envelope.d.ts.map +1 -0
- package/dist/render/markdown/envelope.js +29 -0
- package/dist/render/markdown/envelope.js.map +1 -0
- package/dist/render/markdown/format.d.ts +10 -0
- package/dist/render/markdown/format.d.ts.map +1 -0
- package/dist/render/markdown/format.js +202 -0
- package/dist/render/markdown/format.js.map +1 -0
- package/dist/render/markdown/index.d.ts +3 -0
- package/dist/render/markdown/index.d.ts.map +1 -0
- package/dist/render/markdown/index.js +9 -0
- package/dist/render/markdown/index.js.map +1 -0
- package/dist/render/measure_dom.d.ts +10 -0
- package/dist/render/measure_dom.d.ts.map +1 -0
- package/dist/render/measure_dom.js +57 -0
- package/dist/render/measure_dom.js.map +1 -0
- package/dist/render/payload.d.ts +16 -0
- package/dist/render/payload.d.ts.map +1 -0
- package/dist/render/payload.js +9 -0
- package/dist/render/payload.js.map +1 -0
- package/dist/render/primitive_dispatch.d.ts +72 -0
- package/dist/render/primitive_dispatch.d.ts.map +1 -0
- package/dist/render/primitive_dispatch.js +169 -0
- package/dist/render/primitive_dispatch.js.map +1 -0
- package/dist/render/react/content.d.ts +40 -0
- package/dist/render/react/content.d.ts.map +1 -0
- package/dist/render/react/content.js +39 -0
- package/dist/render/react/content.js.map +1 -0
- package/dist/render/react/enhancements.d.ts +15 -0
- package/dist/render/react/enhancements.d.ts.map +1 -0
- package/dist/render/react/enhancements.js +28 -0
- package/dist/render/react/enhancements.js.map +1 -0
- package/dist/render/react/index.d.ts +3 -0
- package/dist/render/react/index.d.ts.map +1 -0
- package/dist/render/react/index.js +9 -0
- package/dist/render/react/index.js.map +1 -0
- package/dist/render/slack/assets.d.ts +16 -0
- package/dist/render/slack/assets.d.ts.map +1 -0
- package/dist/render/slack/assets.js +40 -0
- package/dist/render/slack/assets.js.map +1 -0
- package/dist/render/slack/blocks.d.ts +72 -0
- package/dist/render/slack/blocks.d.ts.map +1 -0
- package/dist/render/slack/blocks.js +77 -0
- package/dist/render/slack/blocks.js.map +1 -0
- package/dist/render/slack/envelope.d.ts +52 -0
- package/dist/render/slack/envelope.d.ts.map +1 -0
- package/dist/render/slack/envelope.js +547 -0
- package/dist/render/slack/envelope.js.map +1 -0
- package/dist/render/slack/format.d.ts +70 -0
- package/dist/render/slack/format.d.ts.map +1 -0
- package/dist/render/slack/format.js +209 -0
- package/dist/render/slack/format.js.map +1 -0
- package/dist/render/slack/index.d.ts +6 -0
- package/dist/render/slack/index.d.ts.map +1 -0
- package/dist/render/slack/index.js +12 -0
- package/dist/render/slack/index.js.map +1 -0
- package/dist/render/slack/markdown_content.d.ts +17 -0
- package/dist/render/slack/markdown_content.d.ts.map +1 -0
- package/dist/render/slack/markdown_content.js +404 -0
- package/dist/render/slack/markdown_content.js.map +1 -0
- package/dist/render/text/envelope.d.ts +15 -0
- package/dist/render/text/envelope.d.ts.map +1 -0
- package/dist/render/text/envelope.js +17 -0
- package/dist/render/text/envelope.js.map +1 -0
- package/dist/render/text/index.d.ts +2 -0
- package/dist/render/text/index.d.ts.map +1 -0
- package/dist/render/text/index.js +8 -0
- package/dist/render/text/index.js.map +1 -0
- package/dist/testing/conformance.d.ts +145 -0
- package/dist/testing/conformance.d.ts.map +1 -0
- package/dist/testing/conformance.js +303 -0
- package/dist/testing/conformance.js.map +1 -0
- 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 +4 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +10 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/registration.d.ts +32 -0
- package/dist/testing/registration.d.ts.map +1 -0
- package/dist/testing/registration.js +105 -0
- package/dist/testing/registration.js.map +1 -0
- package/dist/validate/authoring_schema.d.ts +33 -0
- package/dist/validate/authoring_schema.d.ts.map +1 -0
- package/dist/validate/authoring_schema.js +306 -0
- package/dist/validate/authoring_schema.js.map +1 -0
- package/dist/validate/composition_schema.d.ts +80 -0
- package/dist/validate/composition_schema.d.ts.map +1 -0
- package/dist/validate/composition_schema.js +127 -0
- package/dist/validate/composition_schema.js.map +1 -0
- package/dist/validate/index.d.ts +9 -0
- package/dist/validate/index.d.ts.map +1 -0
- package/dist/validate/index.js +15 -0
- package/dist/validate/index.js.map +1 -0
- package/dist/validate/input_budget.d.ts +35 -0
- package/dist/validate/input_budget.d.ts.map +1 -0
- package/dist/validate/input_budget.js +151 -0
- package/dist/validate/input_budget.js.map +1 -0
- package/dist/validate/json_schema.d.ts +32 -0
- package/dist/validate/json_schema.d.ts.map +1 -0
- package/dist/validate/json_schema.js +68 -0
- package/dist/validate/json_schema.js.map +1 -0
- package/dist/validate/node_issues.d.ts +12 -0
- package/dist/validate/node_issues.d.ts.map +1 -0
- package/dist/validate/node_issues.js +61 -0
- package/dist/validate/node_issues.js.map +1 -0
- package/dist/validate/url.d.ts +50 -0
- package/dist/validate/url.d.ts.map +1 -0
- package/dist/validate/url.js +107 -0
- package/dist/validate/url.js.map +1 -0
- package/dist/validate/validation.d.ts +95 -0
- package/dist/validate/validation.d.ts.map +1 -0
- package/dist/validate/validation.js +157 -0
- package/dist/validate/validation.js.map +1 -0
- package/dist/validate/value_schemas.d.ts +53 -0
- package/dist/validate/value_schemas.d.ts.map +1 -0
- package/dist/validate/value_schemas.js +50 -0
- package/dist/validate/value_schemas.js.map +1 -0
- package/package.json +119 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.js","sourceRoot":"","sources":["../../../../src/render/markdown/format.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAMH,uEAAwD;AACxD,mDAAiD;AACjD,qEAA8C;AAE9C,4CAI4B;AAE5B,6EAA6E;AAC7E,oCAAoC;AACpC,MAAM,eAAe,GAAG,CAAC,KAAa,EAAU,EAAE,CAChD,KAAK,CAAC,OAAO,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;AAEpC,0EAA0E;AAC1E,yEAAyE;AACzE,sDAAsD;AACtD,MAAM,qBAAqB,GAAG,CAAC,IAAY,EAAU,EAAE,CACrD,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,EAAE;IACjC,IAAI,IAAI,KAAK,GAAG;QAAE,OAAO,KAAK,CAAC;IAC/B,IAAI,IAAI,KAAK,GAAG;QAAE,OAAO,KAAK,CAAC;IAC/B,OAAO,kBAAkB,CAAC,IAAI,CAAC,CAAC;AAClC,CAAC,CAAC,CAAC;AAEL,MAAM,uBAAuB,GAAG,CAAC,IAAY,EAAU,EAAE,CACvD,qBAAqB,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAA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ACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\n// Authored Markdown source made safe to print, for `md.authored`, and the GFM\n// parse it shares with the Slack fallback.\n\nimport type { Definition, Nodes, Parents, Root } from 'mdast';\nimport { fromMarkdown } from 'mdast-util-from-markdown';\nimport { gfmFromMarkdown } from 'mdast-util-gfm';\nimport { gfm } from 'micromark-extension-gfm';\n\nimport {\n BLOCKED_HREF,\n sanitizeParsedAssetUrl,\n sanitizeParsedNavigationHref,\n} from '../../validate/url';\n\n// Escapes label characters that could close a `[...]` early and smuggle in a\n// hostile destination of their own.\nconst escapeLinkLabel = (label: string): string =>\n label.replace(/[[\\]\\\\]/g, '\\\\$&');\n\n// Percent-encodes destination characters that would terminate the `(...)`\n// early or read as a link title. `encodeURIComponent` leaves `(` and `)`\n// unescaped by spec, so those two are mapped by hand.\nconst escapeLinkDestination = (href: string): string =>\n href.replace(/[()\\s\\\\]/g, (char) => {\n if (char === '(') return '%28';\n if (char === ')') return '%29';\n return encodeURIComponent(char);\n });\n\nconst escapeParsedDestination = (href: string): string =>\n escapeLinkDestination(href.replace(/&/g, '&'));\n\nlet parseOptions: Parameters<typeof fromMarkdown>[1] | undefined;\n\nconst parse = (source: string): Root =>\n fromMarkdown(\n source,\n (parseOptions ??= {\n extensions: [gfm()],\n mdastExtensions: [gfmFromMarkdown()],\n })\n );\n\n/** `markdown` as flat GFM mdast blocks, typed `unknown` so no declaration names mdast; `null` past the parse budget or the parser's recursion depth. */\nexport const parseGfmBlocks = (markdown: string): readonly unknown[] | null => {\n if (exceedsParseBudget(markdown)) return null;\n try {\n return parse(markdown).children;\n } catch (error) {\n if (!(error instanceof RangeError)) throw error;\n return null;\n }\n};\n\n// Each pass can expose a new sink (an escaped HTML block reveals the Markdown\n// inside it; a blocked link's label may close an outer `](`), so passes repeat\n// until the source is stable.\nconst MAX_PASSES = 16;\n\nconst escapeTitle = (title: string): string =>\n `\"${title.replace(/[\"\\\\]/g, '\\\\$&')}\"`;\n\nconst offsets = (node: Nodes): [number, number] | undefined => {\n const start = node.position?.start.offset;\n const end = node.position?.end.offset;\n return start === undefined || end === undefined ? undefined : [start, end];\n};\n\nconst sanitizePass = (source: string): string => {\n const root = parse(source);\n const definitions = new Map<string, Definition>();\n const pending: Nodes[] = [...root.children].reverse();\n while (pending.length) {\n const node = pending.pop()!;\n if (node.type === 'definition' && !definitions.has(node.identifier)) {\n definitions.set(node.identifier, node);\n }\n if ('children' in node) pending.push(...[...node.children].reverse());\n }\n\n const slice = (node: Nodes): string => {\n const range = offsets(node);\n return range ? source.slice(...range) : '';\n };\n\n const emitChildren = (\n start: number,\n end: number,\n children: readonly Nodes[]\n ): string => {\n let out = '';\n let cursor = start;\n for (const child of children) {\n const range = offsets(child);\n if (!range) continue;\n out += source.slice(cursor, range[0]) + emit(child);\n cursor = range[1];\n }\n return out + source.slice(cursor, end);\n };\n\n const emitLabel = (node: Parents): string => {\n const first = node.children[0];\n const last = node.children[node.children.length - 1];\n const from = first && offsets(first);\n const to = last && offsets(last);\n return from && to ? emitChildren(from[0], to[1], node.children) : '';\n };\n\n const rewrite = (node: Nodes): string | undefined => {\n switch (node.type) {\n case 'html':\n return slice(node).replace(/</g, '<');\n case 'definition': {\n const safe =\n sanitizeParsedNavigationHref(node.url) ??\n sanitizeParsedAssetUrl(node.url);\n if (safe === node.url) return undefined;\n const title = node.title ? ` ${escapeTitle(node.title)}` : '';\n return `[${node.label ?? node.identifier}]: ${\n safe === null ? BLOCKED_HREF : escapeParsedDestination(safe)\n }${title}`;\n }\n case 'imageReference': {\n const definition = definitions.get(node.identifier);\n return definition && sanitizeParsedAssetUrl(definition.url) === null\n ? escapeLinkLabel(node.alt ?? '')\n : undefined;\n }\n case 'linkReference': {\n const definition = definitions.get(node.identifier);\n return definition &&\n sanitizeParsedNavigationHref(definition.url) === null &&\n sanitizeParsedAssetUrl(definition.url) !== null\n ? emitLabel(node)\n : undefined;\n }\n case 'image': {\n const safe = sanitizeParsedAssetUrl(node.url);\n if (safe === null) return escapeLinkLabel(node.alt ?? '');\n if (safe === node.url) return undefined;\n const title = node.title ? ` ${escapeTitle(node.title)}` : '';\n return `}${title})`;\n }\n case 'link': {\n const raw = slice(node);\n const safe = sanitizeParsedNavigationHref(node.url);\n if (raw.startsWith('<')) {\n return safe === null ? raw.slice(1, -1) : undefined;\n }\n // A GFM literal (`www.x.com`) is http(s) or mailto by construction.\n if (!raw.startsWith('[')) return undefined;\n if (safe === null) return emitLabel(node);\n if (safe === node.url) return undefined;\n const title = node.title ? ` ${escapeTitle(node.title)}` : '';\n return `[${emitLabel(node)}](${escapeParsedDestination(safe)}${title})`;\n }\n default:\n return undefined;\n }\n };\n\n const emit = (node: Nodes): string => {\n const replaced = rewrite(node);\n if (replaced !== undefined) return replaced;\n const range = offsets(node);\n if (!range) return '';\n return 'children' in node\n ? emitChildren(range[0], range[1], node.children)\n : source.slice(...range);\n };\n\n return emitChildren(0, source.length, root.children);\n};\n\n/** {@link sanitizeMarkdownSource}'s result, and whether it degraded to inert text. */\nexport const sanitizeAuthoredSource = (\n markdown: string\n): { markdown: string; inert: boolean } => {\n if (exceedsParseBudget(markdown)) {\n return { markdown: inert(markdown), inert: true };\n }\n let current = markdown;\n try {\n for (let pass = 0; pass < MAX_PASSES; pass++) {\n const next = sanitizePass(current);\n if (next === current) return { markdown: current, inert: false };\n current = next;\n }\n } catch (error) {\n // The parser recurses per nesting level, so inline nesting deep enough\n // to exhaust the stack lands here.\n if (!(error instanceof RangeError)) throw error;\n }\n return { markdown: inert(current), inert: true };\n};\n\n/** Sanitizes GFM destinations and HTML; excessive syntax or length degrades to inert text. */\nexport const sanitizeMarkdownSource = (markdown: string): string =>\n sanitizeAuthoredSource(markdown).markdown;\n\n// No link, image, definition, or tag can survive without `[` or `<`.\nconst inert = (markdown: string): string =>\n markdown.replace(/[[\\]\\\\]/g, '\\\\$&').replace(/</g, '<');\n\n// GFM parsing is superlinear for some delimiter runs, even without nesting.\nconst LINE_PREFIX_RE = /^(?:[ \\t>]|[-*+](?=[ \\t])|\\d{1,9}[.)](?=[ \\t]))+/gm;\nconst MAX_LINE_PREFIX = 256;\nconst INLINE_DELIMITER_RE =\n /[[\\]*`~<>|\\\\]|(?<![\\p{L}\\p{N}])_|_(?![\\p{L}\\p{N}])/gu;\nconst MAX_INLINE_DELIMITERS = 2048;\n\nconst MAX_PARSE_LENGTH = 16_384;\n\nconst exceedsParseBudget = (markdown: string): boolean => {\n if (markdown.length > MAX_PARSE_LENGTH) return true;\n for (const [prefix] of markdown.matchAll(LINE_PREFIX_RE)) {\n if (prefix.length > MAX_LINE_PREFIX) return true;\n }\n let delimiters = 0;\n for (const _ of markdown.matchAll(INLINE_DELIMITER_RE)) {\n if (++delimiters > MAX_INLINE_DELIMITERS) return true;\n }\n return false;\n};\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
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.renderMarkdownEnvelope = exports.serializeMarkdown = exports.md = void 0;
|
|
10
|
+
var builder_1 = require("./builder");
|
|
11
|
+
Object.defineProperty(exports, "md", { enumerable: true, get: function () { return builder_1.md; } });
|
|
12
|
+
Object.defineProperty(exports, "serializeMarkdown", { enumerable: true, get: function () { return builder_1.serializeMarkdown; } });
|
|
13
|
+
var envelope_1 = require("./envelope");
|
|
14
|
+
Object.defineProperty(exports, "renderMarkdownEnvelope", { enumerable: true, get: function () { return envelope_1.renderMarkdownEnvelope; } });
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/render/markdown/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,qCAAkD;AAAzC,6FAAA,EAAE,OAAA;AAAE,4GAAA,iBAAiB,OAAA;AAE9B,uCAIoB;AADlB,kHAAA,sBAAsB,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 { md, serializeMarkdown } from './builder';\n\nexport {\n type MarkdownEnvelopeDispatcher,\n type MarkdownEnvelopeOptions,\n renderMarkdownEnvelope,\n} from './envelope';\n"]}
|
|
@@ -0,0 +1,61 @@
|
|
|
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.measureDom = void 0;
|
|
10
|
+
const TEXT_NODE = 3;
|
|
11
|
+
const unlisted = new Set(['class', 'id', 'style']);
|
|
12
|
+
/** Drawn size over layout size, within a pixel of `offsetWidth`'s rounding. */
|
|
13
|
+
const axisScale = (drawn, laid) => laid > 0 && Math.abs(drawn - laid) > 1 ? drawn / laid : 1;
|
|
14
|
+
const scaleOf = (element, { width, height }) => {
|
|
15
|
+
if (!('offsetWidth' in element)) {
|
|
16
|
+
return 1;
|
|
17
|
+
}
|
|
18
|
+
const { offsetWidth, offsetHeight } = element;
|
|
19
|
+
const scaleX = axisScale(width, offsetWidth);
|
|
20
|
+
const scaleY = axisScale(height, offsetHeight);
|
|
21
|
+
return Math.abs(scaleY - 1) > Math.abs(scaleX - 1) ? scaleY : scaleX;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* The {@link LayoutBox} tree a browser laid `root` out as, measured from
|
|
25
|
+
* `root`'s top left, for `checkLayout`. An HTML element's `scale` is its
|
|
26
|
+
* drawn size over its layout size, so a rotated one reads as scaled; an SVG
|
|
27
|
+
* element has no layout size and is never scaled. jsdom does no layout, so
|
|
28
|
+
* every box it measures is empty.
|
|
29
|
+
*/
|
|
30
|
+
const measureDom = (root) => {
|
|
31
|
+
const origin = root.getBoundingClientRect();
|
|
32
|
+
const range = root.ownerDocument.createRange();
|
|
33
|
+
const place = ({ x, y, width, height }) => ({
|
|
34
|
+
x: x - origin.x,
|
|
35
|
+
y: y - origin.y,
|
|
36
|
+
width,
|
|
37
|
+
height,
|
|
38
|
+
});
|
|
39
|
+
const measure = (element) => {
|
|
40
|
+
const rect = element.getBoundingClientRect();
|
|
41
|
+
const scale = scaleOf(element, rect);
|
|
42
|
+
const attributes = Object.fromEntries(Array.from(element.attributes)
|
|
43
|
+
.filter(({ name }) => !unlisted.has(name))
|
|
44
|
+
.map(({ name, value }) => [name, value]));
|
|
45
|
+
return {
|
|
46
|
+
...place(rect),
|
|
47
|
+
...(scale !== 1 && { scale }),
|
|
48
|
+
runs: Array.from(element.childNodes)
|
|
49
|
+
.filter((node) => node.nodeType === TEXT_NODE && node.textContent?.trim())
|
|
50
|
+
.flatMap((node) => {
|
|
51
|
+
range.selectNodeContents(node);
|
|
52
|
+
return Array.from(range.getClientRects(), place);
|
|
53
|
+
}),
|
|
54
|
+
...(Object.keys(attributes).length > 0 && { attributes }),
|
|
55
|
+
children: Array.from(element.children, measure),
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
return measure(root);
|
|
59
|
+
};
|
|
60
|
+
exports.measureDom = measureDom;
|
|
61
|
+
//# sourceMappingURL=measure_dom.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
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YACJ,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,UAAU,EAAE,CAAC;YACzD,QAAQ,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC;SAChD,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC;AACvB,CAAC,CAAC;AAnCW,QAAA,UAAU,cAmCrB","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 { LayoutBox, LayoutRect } from './layout_check';\n\nconst TEXT_NODE = 3;\n\nconst unlisted = new Set(['class', 'id', 'style']);\n\n/** Drawn size over layout size, within a pixel of `offsetWidth`'s rounding. */\nconst axisScale = (drawn: number, laid: number): number =>\n laid > 0 && Math.abs(drawn - laid) > 1 ? drawn / laid : 1;\n\nconst scaleOf = (\n element: Element,\n { width, height }: DOMRectReadOnly\n): number => {\n if (!('offsetWidth' in element)) {\n return 1;\n }\n const { offsetWidth, offsetHeight } = element as HTMLElement;\n const scaleX = axisScale(width, offsetWidth);\n const scaleY = axisScale(height, offsetHeight);\n return Math.abs(scaleY - 1) > Math.abs(scaleX - 1) ? scaleY : scaleX;\n};\n\n/**\n * The {@link LayoutBox} tree a browser laid `root` out as, measured from\n * `root`'s top left, for `checkLayout`. An HTML element's `scale` is its\n * drawn size over its layout size, so a rotated one reads as scaled; an SVG\n * element has no layout size and is never scaled. jsdom does no layout, so\n * every box it measures is empty.\n */\nexport const measureDom = (root: Element): LayoutBox => {\n const origin = root.getBoundingClientRect();\n const range = root.ownerDocument.createRange();\n const place = ({ x, y, width, height }: DOMRectReadOnly): LayoutRect => ({\n x: x - origin.x,\n y: y - origin.y,\n width,\n height,\n });\n\n const measure = (element: Element): LayoutBox => {\n const rect = element.getBoundingClientRect();\n const scale = scaleOf(element, rect);\n const attributes = Object.fromEntries(\n Array.from(element.attributes)\n .filter(({ name }) => !unlisted.has(name))\n .map(({ name, value }): [string, string] => [name, value])\n );\n return {\n ...place(rect),\n ...(scale !== 1 && { scale }),\n runs: Array.from(element.childNodes)\n .filter(\n (node) => node.nodeType === TEXT_NODE && node.textContent?.trim()\n )\n .flatMap((node) => {\n range.selectNodeContents(node);\n return Array.from(range.getClientRects(), place);\n }),\n ...(Object.keys(attributes).length > 0 && { attributes }),\n children: Array.from(element.children, measure),\n };\n };\n\n return measure(root);\n};\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
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.byteLength = void 0;
|
|
10
|
+
/** UTF-8 byte length of `value`, which is not `length` for non-ASCII text. */
|
|
11
|
+
const byteLength = (value) => new TextEncoder().encode(value).length;
|
|
12
|
+
exports.byteLength = byteLength;
|
|
13
|
+
//# sourceMappingURL=payload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payload.js","sourceRoot":"","sources":["../../../src/render/payload.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAgBH,8EAA8E;AACvE,MAAM,UAAU,GAAG,CAAC,KAAa,EAAU,EAAE,CAClD,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC;AAD5B,QAAA,UAAU,cACkB","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 * Byte sizes of one rendered payload.\n *\n * `html` counts markup only: inlined CSS and script bytes are subtracted out\n * and reported under `css` / `js`. `total` counts each part exactly once,\n * whether or not the CSS was inlined.\n */\nexport interface PayloadMeasurement {\n html: number;\n css: number;\n js: number;\n total: number;\n}\n\n/** UTF-8 byte length of `value`, which is not `length` for non-ASCII text. */\nexport const byteLength = (value: string): number =>\n new TextEncoder().encode(value).length;\n"]}
|
|
@@ -0,0 +1,173 @@
|
|
|
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.createPrimitiveDispatcher = void 0;
|
|
10
|
+
const react_1 = require("react");
|
|
11
|
+
const body_node_base_1 = require("../composition/body_node_base");
|
|
12
|
+
const error_1 = require("../composition/error");
|
|
13
|
+
const node_issues_1 = require("../validate/node_issues");
|
|
14
|
+
const builder_1 = require("./markdown/builder");
|
|
15
|
+
const markdown_content_1 = require("./slack/markdown_content");
|
|
16
|
+
/**
|
|
17
|
+
* Which of a definition's renderers each surface dispatches to.
|
|
18
|
+
*
|
|
19
|
+
* `snapshot` maps to `react`: a rasterizer lays out the pack's DOM tree and
|
|
20
|
+
* stylesheet, so the two surfaces differ only in visibility and in what
|
|
21
|
+
* surrounds them.
|
|
22
|
+
*/
|
|
23
|
+
const RENDERER_FOR_SURFACE = {
|
|
24
|
+
react: 'react',
|
|
25
|
+
snapshot: 'react',
|
|
26
|
+
text: 'text',
|
|
27
|
+
markdown: 'markdown',
|
|
28
|
+
slack: 'slack',
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Flattens `definitions` into one type-keyed inventory.
|
|
32
|
+
*
|
|
33
|
+
* Throws on a duplicate `type`: two packs claiming one node type has no correct
|
|
34
|
+
* resolution, so it fails at construction rather than resolving arbitrarily per
|
|
35
|
+
* render.
|
|
36
|
+
*/
|
|
37
|
+
const createPrimitiveDispatcher = (definitions, options = {}) => {
|
|
38
|
+
const { isSlackAssetType } = options;
|
|
39
|
+
const formatIssues = (0, node_issues_1.createNodeIssueFormatter)(definitions);
|
|
40
|
+
const byType = new Map();
|
|
41
|
+
for (const definition of definitions) {
|
|
42
|
+
const existing = byType.get(definition.type);
|
|
43
|
+
if (existing) {
|
|
44
|
+
const label = options.label ? `${options.label}: ` : '';
|
|
45
|
+
throw new error_1.IsomerError('DUPLICATE_PRIMITIVE_TYPE', `${label}duplicate primitive type "${definition.type}" registered`);
|
|
46
|
+
}
|
|
47
|
+
byType.set(definition.type, definition);
|
|
48
|
+
}
|
|
49
|
+
const getDefinition = (node) => {
|
|
50
|
+
const definition = byType.get(node.type);
|
|
51
|
+
if (!definition) {
|
|
52
|
+
throw new error_1.IsomerError('UNKNOWN_PRIMITIVE_TYPE', `Unknown primitive type "${node.type}"`);
|
|
53
|
+
}
|
|
54
|
+
return definition;
|
|
55
|
+
};
|
|
56
|
+
const sanitizeNode = (definition, node) => {
|
|
57
|
+
const sanitize = definition.sanitize;
|
|
58
|
+
return sanitize ? sanitize(node) : node;
|
|
59
|
+
};
|
|
60
|
+
// Assigned after helpers that close over this binding.
|
|
61
|
+
// eslint-disable-next-line prefer-const
|
|
62
|
+
let self;
|
|
63
|
+
const scope = () => self;
|
|
64
|
+
const renderOn = (surface, node, extras) => {
|
|
65
|
+
if (!(0, body_node_base_1.isVisibleOnSurface)(node, surface)) {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
const definition = getDefinition(node);
|
|
69
|
+
const safeNode = sanitizeNode(definition, node);
|
|
70
|
+
return safeNode === null
|
|
71
|
+
? undefined
|
|
72
|
+
: renderSanitized(surface, definition, safeNode, extras);
|
|
73
|
+
};
|
|
74
|
+
// `renderOn` for a node its sanitizer has already run on.
|
|
75
|
+
const renderSanitized = (surface, definition, safeNode, extras) => {
|
|
76
|
+
const renderer = definition.renderers[RENDERER_FOR_SURFACE[surface]];
|
|
77
|
+
return renderer?.(safeNode, { ...extras, scope: scope() });
|
|
78
|
+
};
|
|
79
|
+
const renderMarkdownContent = (node) => renderOn('markdown', node, {}) ?? [];
|
|
80
|
+
const renderMarkdown = (node) => (0, builder_1.serializeMarkdown)(renderMarkdownContent(node));
|
|
81
|
+
self = {
|
|
82
|
+
definitions,
|
|
83
|
+
getDefinition,
|
|
84
|
+
renderOn,
|
|
85
|
+
// `{}` only ever runs when the argument was optional, which
|
|
86
|
+
// `ReactContextArg` allows exactly when `{}` is a complete context.
|
|
87
|
+
renderReact: (node, ...context) => renderOn('react', node, {
|
|
88
|
+
context: context[0] ?? {},
|
|
89
|
+
}),
|
|
90
|
+
collectStyles: (node, styles, context) => {
|
|
91
|
+
const definition = getDefinition(node);
|
|
92
|
+
const collectStyles = definition.collectStyles;
|
|
93
|
+
collectStyles?.(node, { styles, context });
|
|
94
|
+
},
|
|
95
|
+
renderSnapshot: (node, context, theme, key) => {
|
|
96
|
+
const rendered = renderOn('snapshot', node, { context, theme });
|
|
97
|
+
// The frame hands these to React as an array; a `key` has to sit on the
|
|
98
|
+
// element itself, since wrapping in a Fragment would hide the single
|
|
99
|
+
// root an image backend lays out from.
|
|
100
|
+
return (0, react_1.isValidElement)(rendered)
|
|
101
|
+
? (0, react_1.cloneElement)(rendered, { key })
|
|
102
|
+
: rendered;
|
|
103
|
+
},
|
|
104
|
+
renderText: (node) => renderOn('text', node, {}) ?? '',
|
|
105
|
+
renderMarkdown,
|
|
106
|
+
renderMarkdownContent,
|
|
107
|
+
renderSlack: (node, collector) => {
|
|
108
|
+
if (!(0, body_node_base_1.isVisibleOnSurface)(node, 'slack')) {
|
|
109
|
+
return [];
|
|
110
|
+
}
|
|
111
|
+
const assets = isSlackAssetCollector(collector) ? collector : undefined;
|
|
112
|
+
if (assets && isSlackAssetType?.(node.type)) {
|
|
113
|
+
const definition = getDefinition(node);
|
|
114
|
+
const safeNode = sanitizeNode(definition, node);
|
|
115
|
+
if (safeNode === null) {
|
|
116
|
+
return [];
|
|
117
|
+
}
|
|
118
|
+
const altText = ((0, body_node_base_1.isVisibleOnSurface)(safeNode, 'text') &&
|
|
119
|
+
renderSanitized('text', definition, safeNode, {})) ||
|
|
120
|
+
node.type;
|
|
121
|
+
const ref = assets.allocate(safeNode, altText);
|
|
122
|
+
const block = {
|
|
123
|
+
type: 'image',
|
|
124
|
+
alt_text: altText,
|
|
125
|
+
slack_file: { ref },
|
|
126
|
+
};
|
|
127
|
+
return asSlackPayload([block]);
|
|
128
|
+
}
|
|
129
|
+
const definition = getDefinition(node);
|
|
130
|
+
const slackRenderer = definition.renderers.slack;
|
|
131
|
+
if (!slackRenderer) {
|
|
132
|
+
// Degrading here rather than in the envelope is what reaches nested
|
|
133
|
+
// children: a container's `slack` renderer recurses through this
|
|
134
|
+
// method, and the envelope only ever sees the container's own output.
|
|
135
|
+
return asSlackPayload((0, markdown_content_1.markdownContentToSlackBlocks)(renderMarkdownContent(node)));
|
|
136
|
+
}
|
|
137
|
+
const safeNode = sanitizeNode(definition, node);
|
|
138
|
+
if (safeNode === null) {
|
|
139
|
+
return [];
|
|
140
|
+
}
|
|
141
|
+
const rendered = slackRenderer(safeNode, {
|
|
142
|
+
...(collector === undefined ? {} : { collector }),
|
|
143
|
+
scope: scope(),
|
|
144
|
+
});
|
|
145
|
+
return isReadonlyArray(rendered) ? rendered : [rendered];
|
|
146
|
+
},
|
|
147
|
+
estimateSnapshotHeight: (node) => {
|
|
148
|
+
if (!(0, body_node_base_1.isVisibleOnSurface)(node, 'snapshot')) {
|
|
149
|
+
return 0;
|
|
150
|
+
}
|
|
151
|
+
const snapshotHeight = getDefinition(node).metrics?.snapshotHeight;
|
|
152
|
+
return snapshotHeight?.(node) ?? 0;
|
|
153
|
+
},
|
|
154
|
+
validate: (node, path, errors) => {
|
|
155
|
+
const result = getDefinition(node).schema.safeParse(node, {
|
|
156
|
+
reportInput: true,
|
|
157
|
+
});
|
|
158
|
+
if (!result.success) {
|
|
159
|
+
errors.push(...formatIssues([[node, path]], result.error.issues, path));
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
};
|
|
163
|
+
return self;
|
|
164
|
+
};
|
|
165
|
+
exports.createPrimitiveDispatcher = createPrimitiveDispatcher;
|
|
166
|
+
const isReadonlyArray = (value) => Array.isArray(value);
|
|
167
|
+
/** The picture swap needs a collector that can allocate; any other collector type skips it. */
|
|
168
|
+
const isSlackAssetCollector = (value) => typeof value === 'object' &&
|
|
169
|
+
value !== null &&
|
|
170
|
+
typeof value.allocate === 'function';
|
|
171
|
+
/** Rebinds checked Block Kit to the erased payload parameter. */
|
|
172
|
+
const asSlackPayload = (blocks) => blocks;
|
|
173
|
+
//# sourceMappingURL=primitive_dispatch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"primitive_dispatch.js","sourceRoot":"","sources":["../../../src/render/primitive_dispatch.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,iCAAqE;AAErE,kEAGuC;AACvC,gDAAmD;AAcnD,yDAAmE;AAEnE,gDAAuD;AAGvD,+DAAwE;AAwExE;;;;;;GAMG;AACH,MAAM,oBAAoB,GAAG;IAC3B,KAAK,EAAE,OAAO;IACd,QAAQ,EAAE,OAAO;IACjB,IAAI,EAAE,MAAM;IACZ,QAAQ,EAAE,UAAU;IACpB,KAAK,EAAE,OAAO;CAIf,CAAC;AAcF;;;;;;GAMG;AACI,MAAM,yBAAyB,GAAG,CAIvC,WAA8C,EAC9C,UAAsC,EAAE,EACT,EAAE;IACjC,MAAM,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAC;IACrC,MAAM,YAAY,GAAG,IAAA,sCAAwB,EAAC,WAAW,CAAC,CAAC;IAC3D,MAAM,MAAM,GAAG,IAAI,GAAG,EAAk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yright 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 { cloneElement, isValidElement, type ReactNode } from 'react';\n\nimport {\n isVisibleOnSurface,\n type SurfaceName,\n} from '../composition/body_node_base';\nimport { IsomerError } from '../composition/error';\nimport type { ValidationError } from '../composition/validation_error';\nimport type { MarkdownContent } from '../define/markdown_content';\nimport {\n type AnyPrimitiveDefinition,\n type DefaultPackTypes,\n type PackTypes,\n type PrimitiveNode,\n type PrimitiveStyleCollectionContext,\n type ReactContextArg,\n type Renderer,\n type RenderScope,\n type SurfaceMap,\n} from '../define/primitive_module';\nimport { createNodeIssueFormatter } from '../validate/node_issues';\n\nimport { serializeMarkdown } from './markdown/builder';\nimport type { SlackAssetCollector } from './slack/assets';\nimport type { SlackBlock, SlackImageBlock } from './slack/blocks';\nimport { markdownContentToSlackBlocks } from './slack/markdown_content';\n\n/**\n * Renders a node on any surface by looking its `type` up in one flattened\n * inventory.\n *\n * The seam that makes packs composable: a container recurses through the\n * {@link RenderScope} it is passed rather than through its own pack, so a node\n * owned by another pack still renders.\n */\nexport interface PrimitiveDispatcher<\n TNode extends PrimitiveNode,\n T extends PackTypes = DefaultPackTypes,\n> {\n /** Every primitive this dispatcher can reach, across all composed packs. */\n readonly definitions: readonly AnyPrimitiveDefinition[];\n /** Throws for an unknown node type; a missing primitive is a bug, not a degradation. */\n getDefinition(node: TNode): AnyPrimitiveDefinition;\n /** `undefined` when the node is hidden from `surface`, `sanitize` drops it, or the primitive declares no renderer for `surface`. */\n renderOn<S extends SurfaceName>(\n surface: S,\n node: TNode,\n extras: Omit<SurfaceMap<T>[S]['env'], 'scope'>\n ): SurfaceMap<T>[S]['output'] | undefined;\n /** The node's `react` renderer, or `undefined` when it is hidden or has none. `context` may be omitted only when `{}` is a complete context for the pack. */\n renderReact(\n node: TNode,\n ...context: ReactContextArg<T['context']>\n ): ReactNode;\n /** Mutates `styles` with this node's contribution. */\n collectStyles(\n node: TNode,\n styles: T['collector'],\n context: PrimitiveStyleCollectionContext\n ): void;\n /**\n * The node's `react` renderer, gated on `snapshot` visibility and keyed for a\n * frame's sibling list. `key` must be unique among those siblings.\n * `theme` is the frame's resolved palette for this render, or `undefined`\n * outside a frame.\n */\n renderSnapshot(\n node: TNode,\n context: T['context'],\n theme: T['theme'] | undefined,\n key: string\n ): ReactNode;\n /** `''` when the node is hidden from `text` or its primitive declares no `text` renderer. */\n renderText(node: TNode): string;\n /** The node's content serialized as GFM. */\n renderMarkdown(node: TNode): string;\n /** Empty when the node is hidden from `markdown`. */\n renderMarkdownContent(node: TNode): MarkdownContent;\n /**\n * Empty when the node is hidden from `slack`, `sanitize` drops it, or its\n * renderer returns nothing. A node with no `slack` renderer degrades through\n * its markdown; one `isSlackAssetType` names becomes an `image` block when\n * `collector` can allocate.\n */\n renderSlack(\n node: TNode,\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: TNode): number;\n /**\n * Appends schema failures under `path` to `errors`, each naming `node`'s\n * type, and an unknown key on `node` listing the fields it declares.\n */\n validate(node: TNode, path: string, errors: ValidationError[]): void;\n}\n\n/**\n * Which of a definition's renderers each surface dispatches to.\n *\n * `snapshot` maps to `react`: a rasterizer lays out the pack's DOM tree and\n * stylesheet, so the two surfaces differ only in visibility and in what\n * surrounds them.\n */\nconst RENDERER_FOR_SURFACE = {\n react: 'react',\n snapshot: 'react',\n text: 'text',\n markdown: 'markdown',\n slack: 'slack',\n} as const satisfies Record<\n SurfaceName,\n keyof AnyPrimitiveDefinition['renderers']\n>;\n\n/** Runtime facts {@link createPrimitiveDispatcher} cannot derive from the inventory. */\nexport interface PrimitiveDispatcherOptions {\n /** Names this dispatcher in error messages. */\n label?: string;\n /**\n * Which node types render as a picture rather than as text, so the Slack\n * surface uploads an image instead of degrading to markdown. Supplied by the\n * runtime from each pack's `slackAssetTypes`.\n */\n isSlackAssetType?: ((type: string) => boolean) | undefined;\n}\n\n/**\n * Flattens `definitions` into one type-keyed inventory.\n *\n * Throws on a duplicate `type`: two packs claiming one node type has no correct\n * resolution, so it fails at construction rather than resolving arbitrarily per\n * render.\n */\nexport const createPrimitiveDispatcher = <\n TNode extends PrimitiveNode,\n T extends PackTypes = DefaultPackTypes,\n>(\n definitions: readonly AnyPrimitiveDefinition[],\n options: PrimitiveDispatcherOptions = {}\n): PrimitiveDispatcher<TNode, T> => {\n const { isSlackAssetType } = options;\n const formatIssues = createNodeIssueFormatter(definitions);\n const byType = new Map<string, AnyPrimitiveDefinition>();\n for (const definition of definitions) {\n const existing = byType.get(definition.type);\n if (existing) {\n const label = options.label ? `${options.label}: ` : '';\n throw new IsomerError(\n 'DUPLICATE_PRIMITIVE_TYPE',\n `${label}duplicate primitive type \"${definition.type}\" registered`\n );\n }\n byType.set(definition.type, definition);\n }\n\n const getDefinition = (node: TNode): AnyPrimitiveDefinition => {\n const definition = byType.get(node.type);\n if (!definition) {\n throw new IsomerError(\n 'UNKNOWN_PRIMITIVE_TYPE',\n `Unknown primitive type \"${node.type}\"`\n );\n }\n return definition;\n };\n\n const sanitizeNode = (\n definition: AnyPrimitiveDefinition,\n node: TNode\n ): TNode | null => {\n const sanitize = definition.sanitize as\n ((node: TNode) => TNode | null) | undefined;\n return sanitize ? sanitize(node) : node;\n };\n\n // Assigned after helpers that close over this binding.\n // eslint-disable-next-line prefer-const\n let self: PrimitiveDispatcher<TNode, T>;\n\n const scope = (): RenderScope<T> => self;\n\n const renderOn = <S extends SurfaceName>(\n surface: S,\n node: TNode,\n extras: Omit<SurfaceMap<T>[S]['env'], 'scope'>\n ): SurfaceMap<T>[S]['output'] | undefined => {\n if (!isVisibleOnSurface(node, surface)) {\n return undefined;\n }\n const definition = getDefinition(node);\n const safeNode = sanitizeNode(definition, node);\n return safeNode === null\n ? undefined\n : renderSanitized(surface, definition, safeNode, extras);\n };\n\n // `renderOn` for a node its sanitizer has already run on.\n const renderSanitized = <S extends SurfaceName>(\n surface: S,\n definition: AnyPrimitiveDefinition,\n safeNode: TNode,\n extras: Omit<SurfaceMap<T>[S]['env'], 'scope'>\n ): SurfaceMap<T>[S]['output'] | undefined => {\n const renderer = definition.renderers[RENDERER_FOR_SURFACE[surface]] as\n Renderer<TNode, S, T> | undefined;\n return renderer?.(safeNode, { ...extras, scope: scope() });\n };\n\n const renderMarkdownContent = (node: TNode): MarkdownContent =>\n renderOn('markdown', node, {}) ?? [];\n\n const renderMarkdown = (node: TNode): string =>\n serializeMarkdown(renderMarkdownContent(node));\n\n self = {\n definitions,\n getDefinition,\n renderOn,\n // `{}` only ever runs when the argument was optional, which\n // `ReactContextArg` allows exactly when `{}` is a complete context.\n renderReact: (node, ...context) =>\n renderOn('react', node, {\n context: context[0] ?? {},\n }),\n collectStyles: (node, styles, context) => {\n const definition = getDefinition(node);\n const collectStyles = definition.collectStyles as\n | ((\n node: TNode,\n env: {\n styles: T['collector'];\n context: PrimitiveStyleCollectionContext;\n }\n ) => void)\n | undefined;\n collectStyles?.(node, { styles, context });\n },\n renderSnapshot: (node, context, theme, key) => {\n const rendered = renderOn('snapshot', node, { context, theme });\n // The frame hands these to React as an array; a `key` has to sit on the\n // element itself, since wrapping in a Fragment would hide the single\n // root an image backend lays out from.\n return isValidElement(rendered)\n ? cloneElement(rendered, { key })\n : rendered;\n },\n renderText: (node) => renderOn('text', node, {}) ?? '',\n renderMarkdown,\n renderMarkdownContent,\n renderSlack: (node, collector) => {\n if (!isVisibleOnSurface(node, 'slack')) {\n return [];\n }\n const assets = isSlackAssetCollector(collector) ? collector : undefined;\n if (assets && isSlackAssetType?.(node.type)) {\n const definition = getDefinition(node);\n const safeNode = sanitizeNode(definition, node);\n if (safeNode === null) {\n return [];\n }\n const altText =\n (isVisibleOnSurface(safeNode, 'text') &&\n renderSanitized('text', definition, safeNode, {})) ||\n node.type;\n const ref = assets.allocate(safeNode, altText);\n const block = {\n type: 'image',\n alt_text: altText,\n slack_file: { ref },\n } satisfies SlackImageBlock;\n return asSlackPayload<T['slackBlock']>([block]);\n }\n const definition = getDefinition(node);\n const slackRenderer = definition.renderers.slack as\n Renderer<TNode, 'slack', T> | undefined;\n if (!slackRenderer) {\n // Degrading here rather than in the envelope is what reaches nested\n // children: a container's `slack` renderer recurses through this\n // method, and the envelope only ever sees the container's own output.\n return asSlackPayload<T['slackBlock']>(\n markdownContentToSlackBlocks(renderMarkdownContent(node))\n );\n }\n const safeNode = sanitizeNode(definition, node);\n if (safeNode === null) {\n return [];\n }\n const rendered = slackRenderer(safeNode, {\n ...(collector === undefined ? {} : { collector }),\n scope: scope(),\n });\n return isReadonlyArray(rendered) ? rendered : [rendered];\n },\n estimateSnapshotHeight: (node) => {\n if (!isVisibleOnSurface(node, 'snapshot')) {\n return 0;\n }\n const snapshotHeight = getDefinition(node).metrics?.snapshotHeight as\n ((node: TNode) => number) | undefined;\n return snapshotHeight?.(node) ?? 0;\n },\n validate: (node, path, errors) => {\n const result = getDefinition(node).schema.safeParse(node, {\n reportInput: true,\n });\n if (!result.success) {\n errors.push(...formatIssues([[node, path]], result.error.issues, path));\n }\n },\n };\n return self;\n};\n\nconst isReadonlyArray = <T>(value: T | readonly T[]): value is readonly T[] =>\n Array.isArray(value);\n\n/** The picture swap needs a collector that can allocate; any other collector type skips it. */\nconst isSlackAssetCollector = (value: unknown): value is SlackAssetCollector =>\n typeof value === 'object' &&\n value !== null &&\n typeof (value as { allocate?: unknown }).allocate === 'function';\n\n/** Rebinds checked Block Kit to the erased payload parameter. */\nconst asSlackPayload = <TSlackBlock>(\n blocks: readonly SlackBlock[]\n): readonly TSlackBlock[] => blocks as unknown as readonly TSlackBlock[];\n"]}
|
|
@@ -0,0 +1,44 @@
|
|
|
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.wrapCompositionContent = exports.renderCompositionContent = void 0;
|
|
10
|
+
const react_1 = require("react");
|
|
11
|
+
/**
|
|
12
|
+
* A composition's heading and body as React nodes, without the surrounding
|
|
13
|
+
* document or wrapper element.
|
|
14
|
+
*/
|
|
15
|
+
const renderCompositionContent = (composition, dispatcher, context, { heading = true } = {}) => (0, react_1.createElement)(react_1.Fragment, null, ...[
|
|
16
|
+
heading && composition.title
|
|
17
|
+
? (0, react_1.createElement)('h2', { key: 'title' }, composition.title)
|
|
18
|
+
: null,
|
|
19
|
+
heading && composition.subtitle
|
|
20
|
+
? (0, react_1.createElement)('p', { key: 'subtitle', className: 'sub' }, composition.subtitle)
|
|
21
|
+
: null,
|
|
22
|
+
...composition.body.map((node, index) => (0, react_1.createElement)((RenderedCompositionNode), {
|
|
23
|
+
key: `body-${index}`,
|
|
24
|
+
node,
|
|
25
|
+
context,
|
|
26
|
+
dispatcher,
|
|
27
|
+
})),
|
|
28
|
+
].filter(Boolean));
|
|
29
|
+
exports.renderCompositionContent = renderCompositionContent;
|
|
30
|
+
const RenderedCompositionNode = ({ node, context, dispatcher, }) => dispatcher.renderReact(node, context);
|
|
31
|
+
/**
|
|
32
|
+
* The one `.isomer[.framed][.fluid]` `section` every surface wraps rendered
|
|
33
|
+
* content in: the `html` surface's document wrapper and a React host's.
|
|
34
|
+
*/
|
|
35
|
+
const wrapCompositionContent = (content, composition, { framed = true, fluid = false, theme = composition.theme ?? 'auto', defaultAriaLabel = 'View', } = {}) => (0, react_1.createElement)('section', {
|
|
36
|
+
className: ['isomer', framed ? 'framed' : '', fluid ? 'fluid' : '']
|
|
37
|
+
.filter(Boolean)
|
|
38
|
+
.join(' '),
|
|
39
|
+
role: 'group',
|
|
40
|
+
'aria-label': composition.meta?.ariaLabel ?? composition.title ?? defaultAriaLabel,
|
|
41
|
+
...(theme === 'auto' ? {} : { 'data-theme': theme }),
|
|
42
|
+
}, content);
|
|
43
|
+
exports.wrapCompositionContent = wrapCompositionContent;
|
|
44
|
+
//# sourceMappingURL=content.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content.js","sourceRoot":"","sources":["../../../../src/render/react/content.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,iCAKe;AAyBf;;;GAGG;AACI,MAAM,wBAAwB,GAAG,CAItC,WAA+B,EAC/B,UAAmD,EACnD,OAAiB,EACjB,EAAE,OAAO,GAAG,IAAI,KAA0B,EAAE,EACjC,EAAE,CACb,IAAA,qBAAa,EACX,gBAAQ,EACR,IAAI,EACJ,GAAG;IACD,OAAO,IAAI,WAAW,CAAC,KAAK;QAC1B,CAAC,CAAC,IAAA,qBAAa,EAAC,IAAI,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,WAAW,CAAC,KAAK,CAAC;QAC1D,CAAC,CAAC,IAAI;IACR,OAAO,IAAI,WAAW,CAAC,QAAQ;QAC7B,CAAC,CAAC,IAAA,qBAAa,EACX,GAAG,EACH,EAAE,GAAG,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,EACrC,WAAW,CAAC,QAAQ,CACrB;QACH,CAAC,CAAC,IAAI;IACR,GAAG,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CACtC,IAAA,qBAAa,EAAC,CAAA,uBAAwC,CAAA,EAAE;QACtD,GAAG,EAAE,QAAQ,KAAK,EAAE;QACpB,IAAI;QACJ,OAAO;QACP,UAAU;KACX,CAAC,CACH;CACF,CAAC,MAAM,CAAC,OAAO,CAAC,CAClB,CAAC;AAhCS,QAAA,wBAAwB,4BAgCjC;AAWJ,MAAM,uBAAuB,GAAG,CAAwC,EACtE,IAAI,EACJ,OAAO,EACP,UAAU,GACoC,EAAa,EAAE,CAC7D,UAAU,CAAC,WAAW,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAcxC;;;GAGG;AACI,MAAM,sBAAsB,GAAG,CACpC,OAAkB,EAClB,WAA+B,EAC/B,EACE,MAAM,GAAG,IAAI,EACb,KAAK,GAAG,KAAK,EACb,KAAK,GAAG,WAAW,CAAC,KAAK,IAAI,MAAM,EACnC,gBAAgB,GAAG,MAAM,MACI,EAAE,EACnB,EAAE,CAChB,IAAA,qBAAa,EACX,SAAS,EACT;IACE,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;SAChE,MAAM,CAAC,OAAO,CAAC;SACf,IAAI,CAAC,GAAG,CAAC;IACZ,IAAI,EAAE,OAAO;IACb,YAAY,EACV,WAAW,CAAC,IAAI,EAAE,SAAS,IAAI,WAAW,CAAC,KAAK,IAAI,gBAAgB;IACtE,GAAG,CAAC,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC;CACrD,EACD,OAAO,CACR,CAAC;AAtBS,QAAA,sBAAsB,0BAsB/B","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nimport {\n createElement,\n Fragment,\n type ReactElement,\n type ReactNode,\n} from 'react';\n\nimport type { Composition } from '../../composition';\nimport type { RenderTheme } from '../../composition/named_color';\nimport type { PrimitiveNode, PrimitiveRenderContext } from '../../define';\n\n/** A pack's React renderer for one node of its own type. */\nexport interface ReactContentDispatcher<\n TNode extends PrimitiveNode,\n TContext = PrimitiveRenderContext,\n> {\n /** Must be side-effect free: the HTML surface calls it twice, once to collect styles and once to render. */\n renderReact(node: TNode, context?: TContext): ReactNode;\n}\n\n/** Options for {@link renderCompositionContent}. */\nexport interface ReactContentOptions {\n /**\n * Renders the composition's title and subtitle as the leading `h2` / `p.sub`.\n * Defaults to `true`. Pass `false` when the host already shows the title\n * itself; the title still backs the wrapper's `aria-label`.\n */\n heading?: boolean;\n}\n\n/**\n * A composition's heading and body as React nodes, without the surrounding\n * document or wrapper element.\n */\nexport const renderCompositionContent = <\n TNode extends PrimitiveNode,\n TContext = PrimitiveRenderContext,\n>(\n composition: Composition<TNode>,\n dispatcher: ReactContentDispatcher<TNode, TContext>,\n context: TContext,\n { heading = true }: ReactContentOptions = {}\n): ReactNode =>\n createElement(\n Fragment,\n null,\n ...[\n heading && composition.title\n ? createElement('h2', { key: 'title' }, composition.title)\n : null,\n heading && composition.subtitle\n ? createElement(\n 'p',\n { key: 'subtitle', className: 'sub' },\n composition.subtitle\n )\n : null,\n ...composition.body.map((node, index) =>\n createElement(RenderedCompositionNode<TNode, TContext>, {\n key: `body-${index}`,\n node,\n context,\n dispatcher,\n })\n ),\n ].filter(Boolean)\n );\n\ninterface RenderedCompositionNodeProps<\n TNode extends PrimitiveNode,\n TContext = PrimitiveRenderContext,\n> {\n node: TNode;\n context: TContext;\n dispatcher: ReactContentDispatcher<TNode, TContext>;\n}\n\nconst RenderedCompositionNode = <TNode extends PrimitiveNode, TContext>({\n node,\n context,\n dispatcher,\n}: RenderedCompositionNodeProps<TNode, TContext>): ReactNode =>\n dispatcher.renderReact(node, context);\n\n/** Options for {@link wrapCompositionContent}. */\nexport interface CompositionWrapperOptions {\n /** Adds the `framed` class. Defaults to `true`. */\n framed?: boolean;\n /** Adds the `fluid` class. */\n fluid?: boolean;\n /** Sets `data-theme`; defaults to the composition's `theme`, and `auto` sets nothing so the page's scheme applies. */\n theme?: RenderTheme;\n /** Used only when the composition has neither `meta.ariaLabel` nor a `title`. Defaults to `'View'`. */\n defaultAriaLabel?: string;\n}\n\n/**\n * The one `.isomer[.framed][.fluid]` `section` every surface wraps rendered\n * content in: the `html` surface's document wrapper and a React host's.\n */\nexport const wrapCompositionContent = <TNode extends PrimitiveNode>(\n content: ReactNode,\n composition: Composition<TNode>,\n {\n framed = true,\n fluid = false,\n theme = composition.theme ?? 'auto',\n defaultAriaLabel = 'View',\n }: CompositionWrapperOptions = {}\n): ReactElement =>\n createElement(\n 'section',\n {\n className: ['isomer', framed ? 'framed' : '', fluid ? 'fluid' : '']\n .filter(Boolean)\n .join(' '),\n role: 'group',\n 'aria-label':\n composition.meta?.ariaLabel ?? composition.title ?? defaultAriaLabel,\n ...(theme === 'auto' ? {} : { 'data-theme': theme }),\n },\n content\n );\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
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.applyEnhancements = void 0;
|
|
10
|
+
const enhancements_1 = require("../../pack/enhancements");
|
|
11
|
+
const anchors_1 = require("../anchors");
|
|
12
|
+
const context_view_1 = require("../context_view");
|
|
13
|
+
/**
|
|
14
|
+
* The `definitions` that apply to `body`, the first of each id and limited to
|
|
15
|
+
* `requested` ids when given, and `context` for a React render of it: carrying
|
|
16
|
+
* their ids as `context.enhancements`, with `context.anchors` on when one
|
|
17
|
+
* declares `anchors: true`. `context` is viewed, not copied, as the HTML
|
|
18
|
+
* surface does.
|
|
19
|
+
*/
|
|
20
|
+
const applyEnhancements = (context, body, walk, definitions, requested) => {
|
|
21
|
+
const applied = (0, enhancements_1.resolveEnhancements)(body, walk, definitions, requested);
|
|
22
|
+
const ids = new Set(applied.map(({ id }) => id));
|
|
23
|
+
const enhanced = (0, context_view_1.contextWith)(context, 'enhancements', ids);
|
|
24
|
+
return {
|
|
25
|
+
context: applied.some(({ anchors }) => anchors)
|
|
26
|
+
? (0, anchors_1.withNodeAnchors)(enhanced)
|
|
27
|
+
: enhanced,
|
|
28
|
+
applied,
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
exports.applyEnhancements = applyEnhancements;
|
|
32
|
+
//# sourceMappingURL=enhancements.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enhancements.js","sourceRoot":"","sources":["../../../../src/render/react/enhancements.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAIH,0DAGiC;AACjC,wCAA6C;AAC7C,kDAA8C;AAE9C;;;;;;GAMG;AACI,MAAM,iBAAiB,GAAG,CAC/B,OAAiB,EACjB,IAA8B,EAC9B,IAAqB,EACrB,WAA6C,EAC7C,SAA6B,EAC4B,EAAE;IAC3D,MAAM,OAAO,GAAG,IAAA,kCAAmB,EAAC,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC;IACxE,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACjD,MAAM,QAAQ,GAAG,IAAA,0BAAW,EAAC,OAAO,EAAE,cAAc,EAAE,GAAG,CAAC,CAAC;IAC3D,OAAO;QACL,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC;YAC7C,CAAC,CAAC,IAAA,yBAAe,EAAC,QAAQ,CAAC;YAC3B,CAAC,CAAC,QAAQ;QACZ,OAAO;KACR,CAAC;AACJ,CAAC,CAAC;AAhBW,QAAA,iBAAiB,qBAgB5B","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 { ChildNodeWalker } from '../../composition/body_node_base';\nimport type { PrimitiveNode } from '../../composition/node';\nimport {\n type EnhancementDefinition,\n resolveEnhancements,\n} from '../../pack/enhancements';\nimport { withNodeAnchors } from '../anchors';\nimport { contextWith } from '../context_view';\n\n/**\n * The `definitions` that apply to `body`, the first of each id and limited to\n * `requested` ids when given, and `context` for a React render of it: carrying\n * their ids as `context.enhancements`, with `context.anchors` on when one\n * declares `anchors: true`. `context` is viewed, not copied, as the HTML\n * surface does.\n */\nexport const applyEnhancements = <TContext>(\n context: TContext,\n body: readonly PrimitiveNode[],\n walk: ChildNodeWalker,\n definitions: readonly EnhancementDefinition[],\n requested?: readonly string[]\n): { context: TContext; applied: EnhancementDefinition[] } => {\n const applied = resolveEnhancements(body, walk, definitions, requested);\n const ids = new Set(applied.map(({ id }) => id));\n const enhanced = contextWith(context, 'enhancements', ids);\n return {\n context: applied.some(({ anchors }) => anchors)\n ? withNodeAnchors(enhanced)\n : enhanced,\n applied,\n };\n};\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
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.applyEnhancements = exports.wrapCompositionContent = exports.renderCompositionContent = void 0;
|
|
10
|
+
var content_1 = require("./content");
|
|
11
|
+
Object.defineProperty(exports, "renderCompositionContent", { enumerable: true, get: function () { return content_1.renderCompositionContent; } });
|
|
12
|
+
Object.defineProperty(exports, "wrapCompositionContent", { enumerable: true, get: function () { return content_1.wrapCompositionContent; } });
|
|
13
|
+
var enhancements_1 = require("./enhancements");
|
|
14
|
+
Object.defineProperty(exports, "applyEnhancements", { enumerable: true, get: function () { return enhancements_1.applyEnhancements; } });
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/render/react/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,qCAMmB;AAFjB,mHAAA,wBAAwB,OAAA;AACxB,iHAAA,sBAAsB,OAAA;AAExB,+CAAmD;AAA1C,iHAAA,iBAAiB,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 CompositionWrapperOptions,\n type ReactContentDispatcher,\n type ReactContentOptions,\n renderCompositionContent,\n wrapCompositionContent,\n} from './content';\nexport { applyEnhancements } from './enhancements';\n"]}
|
|
@@ -0,0 +1,45 @@
|
|
|
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.createSlackAssetCollector = exports.isSlackReachableImageUrl = void 0;
|
|
10
|
+
const blocks_1 = require("./blocks");
|
|
11
|
+
const format_1 = require("./format");
|
|
12
|
+
/**
|
|
13
|
+
* Whether Slack's servers can fetch `src` themselves: an `https:` URL with a
|
|
14
|
+
* host, so a data URL or a host-relative path has to go through an upload.
|
|
15
|
+
*/
|
|
16
|
+
const isSlackReachableImageUrl = (src) => /^https:/i.test(src) && (0, format_1.isAbsoluteHttpUrl)(src);
|
|
17
|
+
exports.isSlackReachableImageUrl = isSlackReachableImageUrl;
|
|
18
|
+
/**
|
|
19
|
+
* A fresh {@link SlackAssetCollector} handing out `{prefix}-0`, `{prefix}-1`,
|
|
20
|
+
* … in allocation order. `prefix` defaults to `asset`.
|
|
21
|
+
*/
|
|
22
|
+
const createSlackAssetCollector = (options = {}) => {
|
|
23
|
+
const prefix = options.prefix ?? 'asset';
|
|
24
|
+
const requests = [];
|
|
25
|
+
let counter = 0;
|
|
26
|
+
return {
|
|
27
|
+
allocate: (node, altText) => {
|
|
28
|
+
const ref = `${prefix}-${counter}`;
|
|
29
|
+
counter += 1;
|
|
30
|
+
// Clamped at allocation so a host reading `requests` for an upload title
|
|
31
|
+
// sees the same string as the block it accompanies.
|
|
32
|
+
requests.push({
|
|
33
|
+
ref,
|
|
34
|
+
node,
|
|
35
|
+
altText: (0, format_1.clampSlackText)(altText, blocks_1.SLACK_LIMITS.imageAltTextChars),
|
|
36
|
+
});
|
|
37
|
+
return ref;
|
|
38
|
+
},
|
|
39
|
+
get requests() {
|
|
40
|
+
return requests;
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
exports.createSlackAssetCollector = createSlackAssetCollector;
|
|
45
|
+
//# sourceMappingURL=assets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assets.js","sourceRoot":"","sources":["../../../../src/render/slack/assets.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAQH,qCAAwC;AACxC,qCAA6D;AAI7D;;;GAGG;AACI,MAAM,wBAAwB,GAAG,CAAC,GAAW,EAAW,EAAE,CAC/D,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,IAAA,0BAAiB,EAAC,GAAG,CAAC,CAAC;AADpC,QAAA,wBAAwB,4BACY;AAEjD;;;GAGG;AACI,MAAM,yBAAyB,GAAG,CAGvC,UAA+B,EAAE,EACL,EAAE;IAC9B,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC;IACzC,MAAM,QAAQ,GAA+B,EAAE,CAAC;IAChD,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,OAAO;QACL,QAAQ,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE;YAC1B,MAAM,GAAG,GAAG,GAAG,MAAM,IAAI,OAAO,EAAE,CAAC;YACnC,OAAO,IAAI,CAAC,CAAC;YACb,yEAAyE;YACzE,oDAAoD;YACpD,QAAQ,CAAC,IAAI,CAAC;gBACZ,GAAG;gBACH,IAAI;gBACJ,OAAO,EAAE,IAAA,uBAAc,EAAC,OAAO,EAAE,qBAAY,CAAC,iBAAiB,CAAC;aACjE,CAAC,CAAC;YACH,OAAO,GAAG,CAAC;QACb,CAAC;QACD,IAAI,QAAQ;YACV,OAAO,QAAQ,CAAC;QAClB,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AAzBW,QAAA,yBAAyB,6BAyBpC","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';\nimport type {\n SlackAssetCollector,\n SlackAssetRequest,\n} from '../../define/slack_assets';\n\nimport { SLACK_LIMITS } from './blocks';\nimport { clampSlackText, isAbsoluteHttpUrl } from './format';\n\nexport type { SlackAssetCollector, SlackAssetRequest };\n\n/**\n * Whether Slack's servers can fetch `src` themselves: an `https:` URL with a\n * host, so a data URL or a host-relative path has to go through an upload.\n */\nexport const isSlackReachableImageUrl = (src: string): boolean =>\n /^https:/i.test(src) && isAbsoluteHttpUrl(src);\n\n/**\n * A fresh {@link SlackAssetCollector} handing out `{prefix}-0`, `{prefix}-1`,\n * … in allocation order. `prefix` defaults to `asset`.\n */\nexport const createSlackAssetCollector = <\n TNode extends PrimitiveNode = PrimitiveNode,\n>(\n options: { prefix?: string } = {}\n): SlackAssetCollector<TNode> => {\n const prefix = options.prefix ?? 'asset';\n const requests: SlackAssetRequest<TNode>[] = [];\n let counter = 0;\n return {\n allocate: (node, altText) => {\n const ref = `${prefix}-${counter}`;\n counter += 1;\n // Clamped at allocation so a host reading `requests` for an upload title\n // sees the same string as the block it accompanies.\n requests.push({\n ref,\n node,\n altText: clampSlackText(altText, SLACK_LIMITS.imageAltTextChars),\n });\n return ref;\n },\n get requests() {\n return requests;\n },\n };\n};\n"]}
|
|
@@ -0,0 +1,80 @@
|
|
|
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.SLACK_LIMITS = void 0;
|
|
10
|
+
/**
|
|
11
|
+
* Slack's published surface limits, enforced by the renderer so a composition
|
|
12
|
+
* cannot silently trip Slack's validation.
|
|
13
|
+
*/
|
|
14
|
+
exports.SLACK_LIMITS = {
|
|
15
|
+
blocksPerMessage: 50,
|
|
16
|
+
/** `section.text`. */
|
|
17
|
+
sectionTextChars: 3000,
|
|
18
|
+
/** One entry of `section.fields`. */
|
|
19
|
+
sectionFieldChars: 2000,
|
|
20
|
+
/** One entry of `context.elements`. */
|
|
21
|
+
contextElementChars: 2000,
|
|
22
|
+
/** `header.text`, which is `plain_text`. */
|
|
23
|
+
headerTextChars: 150,
|
|
24
|
+
fieldsPerSection: 10,
|
|
25
|
+
/** Elements per `context` block. */
|
|
26
|
+
contextElements: 10,
|
|
27
|
+
buttonsPerActions: 25,
|
|
28
|
+
/** Slack truncates the top-level `text` fallback in notifications around here. */
|
|
29
|
+
fallbackTextChars: 4000,
|
|
30
|
+
/** `plain_text` option labels (selects, radio, checkboxes, overflow). */
|
|
31
|
+
optionTextChars: 75,
|
|
32
|
+
/** Options per select, or per option group of one. */
|
|
33
|
+
optionsPerSelect: 100,
|
|
34
|
+
/** Options per overflow menu (Slack caps overflow at 5). */
|
|
35
|
+
optionsPerOverflow: 5,
|
|
36
|
+
/** Options per radio button group or checkboxes element. */
|
|
37
|
+
optionsPerChoice: 10,
|
|
38
|
+
/** Option groups per select, each holding up to `optionsPerSelect` options. */
|
|
39
|
+
optionGroupsPerSelect: 100,
|
|
40
|
+
/** An option's `value`, which interactions send back. */
|
|
41
|
+
optionValueChars: 150,
|
|
42
|
+
/** A button's `value`. */
|
|
43
|
+
buttonValueChars: 2000,
|
|
44
|
+
/** A button's or overflow option's `url`. */
|
|
45
|
+
urlChars: 3000,
|
|
46
|
+
/** An interactive element's `action_id`. */
|
|
47
|
+
actionIdChars: 255,
|
|
48
|
+
/** Max indent level for `rich_text_list`. */
|
|
49
|
+
richTextListMaxIndent: 8,
|
|
50
|
+
/**
|
|
51
|
+
* Characters across every table cell in one message. Slack publishes the
|
|
52
|
+
* same 10,000 figure per table and per message, so the message-wide
|
|
53
|
+
* aggregate is the binding one.
|
|
54
|
+
* https://docs.slack.dev/reference/block-kit/blocks/table-block/
|
|
55
|
+
*/
|
|
56
|
+
tableCellCharsPerMessage: 10_000,
|
|
57
|
+
/** Rows per `table` block (includes the header row). */
|
|
58
|
+
tableRows: 100,
|
|
59
|
+
/** Cells per `table` row / columns per table. */
|
|
60
|
+
tableColumns: 20,
|
|
61
|
+
/** `image`/image-element `image_url` max length. */
|
|
62
|
+
imageUrlChars: 3000,
|
|
63
|
+
/** `image`/image-element `alt_text` max length. */
|
|
64
|
+
imageAltTextChars: 2000,
|
|
65
|
+
/** `image` block `title`. */
|
|
66
|
+
imageTitleChars: 2000,
|
|
67
|
+
/** `video` block `title`; Slack requires fewer than 200. */
|
|
68
|
+
videoTitleChars: 199,
|
|
69
|
+
/** `video` block `description`; Slack requires fewer than 200. */
|
|
70
|
+
videoDescriptionChars: 199,
|
|
71
|
+
/** `video` block `author_name`; Slack requires fewer than 50. */
|
|
72
|
+
videoAuthorNameChars: 49,
|
|
73
|
+
/** `button` element `text`. */
|
|
74
|
+
buttonTextChars: 75,
|
|
75
|
+
/** Select `placeholder`. */
|
|
76
|
+
placeholderChars: 150,
|
|
77
|
+
/** `option_groups[].label`. */
|
|
78
|
+
optionGroupLabelChars: 75,
|
|
79
|
+
};
|
|
80
|
+
//# sourceMappingURL=blocks.js.map
|