markdown-flow-ui 0.1.100 → 0.1.101
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/hast-util-to-jsx-runtime@2.3.6/node_modules/hast-util-to-jsx-runtime/lib/index.cjs.js +1 -1
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/hast-util-to-jsx-runtime@2.3.6/node_modules/hast-util-to-jsx-runtime/lib/index.es.js +1 -1
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/lucide-react@0.525.0_react@19.0.1/node_modules/lucide-react/dist/esm/icons/ellipsis-vertical.cjs.js +7 -0
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/lucide-react@0.525.0_react@19.0.1/node_modules/lucide-react/dist/esm/icons/ellipsis-vertical.cjs.js.map +1 -0
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/lucide-react@0.525.0_react@19.0.1/node_modules/lucide-react/dist/esm/icons/ellipsis-vertical.es.js +17 -0
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/lucide-react@0.525.0_react@19.0.1/node_modules/lucide-react/dist/esm/icons/ellipsis-vertical.es.js.map +1 -0
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/lucide-react@0.525.0_react@19.0.1/node_modules/lucide-react/dist/esm/icons/file-pen-line.cjs.js +7 -0
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/lucide-react@0.525.0_react@19.0.1/node_modules/lucide-react/dist/esm/icons/file-pen-line.cjs.js.map +1 -0
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/lucide-react@0.525.0_react@19.0.1/node_modules/lucide-react/dist/esm/icons/file-pen-line.es.js +29 -0
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/lucide-react@0.525.0_react@19.0.1/node_modules/lucide-react/dist/esm/icons/file-pen-line.es.js.map +1 -0
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/lucide-react@0.525.0_react@19.0.1/node_modules/lucide-react/dist/esm/icons/maximize.cjs.js +7 -0
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/lucide-react@0.525.0_react@19.0.1/node_modules/lucide-react/dist/esm/icons/maximize.cjs.js.map +1 -0
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/lucide-react@0.525.0_react@19.0.1/node_modules/lucide-react/dist/esm/icons/maximize.es.js +18 -0
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/lucide-react@0.525.0_react@19.0.1/node_modules/lucide-react/dist/esm/icons/maximize.es.js.map +1 -0
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/lucide-react@0.525.0_react@19.0.1/node_modules/lucide-react/dist/esm/icons/rotate-ccw.cjs.js +7 -0
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/lucide-react@0.525.0_react@19.0.1/node_modules/lucide-react/dist/esm/icons/rotate-ccw.cjs.js.map +1 -0
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/lucide-react@0.525.0_react@19.0.1/node_modules/lucide-react/dist/esm/icons/rotate-ccw.es.js +16 -0
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/lucide-react@0.525.0_react@19.0.1/node_modules/lucide-react/dist/esm/icons/rotate-ccw.es.js.map +1 -0
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/lucide-react@0.525.0_react@19.0.1/node_modules/lucide-react/dist/esm/icons/rotate-cw.cjs.js +7 -0
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/lucide-react@0.525.0_react@19.0.1/node_modules/lucide-react/dist/esm/icons/rotate-cw.cjs.js.map +1 -0
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/lucide-react@0.525.0_react@19.0.1/node_modules/lucide-react/dist/esm/icons/rotate-cw.es.js +16 -0
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/lucide-react@0.525.0_react@19.0.1/node_modules/lucide-react/dist/esm/icons/rotate-cw.es.js.map +1 -0
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/lucide-react@0.525.0_react@19.0.1/node_modules/lucide-react/dist/esm/icons/volume-2.cjs.js +7 -0
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/lucide-react@0.525.0_react@19.0.1/node_modules/lucide-react/dist/esm/icons/volume-2.cjs.js.map +1 -0
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/lucide-react@0.525.0_react@19.0.1/node_modules/lucide-react/dist/esm/icons/volume-2.es.js +23 -0
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/lucide-react@0.525.0_react@19.0.1/node_modules/lucide-react/dist/esm/icons/volume-2.es.js.map +1 -0
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/rc-input@1.8.0_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-input/es/BaseInput.cjs.js +1 -1
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/rc-input@1.8.0_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-input/es/BaseInput.es.js +1 -1
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/rc-textarea@1.10.2_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-textarea/es/ResizableTextArea.cjs.js +1 -1
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/rc-textarea@1.10.2_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-textarea/es/ResizableTextArea.es.js +1 -1
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/rc-textarea@1.10.2_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-textarea/es/TextArea.cjs.js +1 -1
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/rc-textarea@1.10.2_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-textarea/es/TextArea.es.js +1 -1
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/rc-textarea@1.10.2_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-textarea/es/index.cjs.js +1 -1
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/rc-textarea@1.10.2_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-textarea/es/index.es.js +1 -1
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/remark-flow@0.1.6/node_modules/remark-flow/dist/remark-custom-variable.cjs.js +1 -1
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/remark-flow@0.1.6/node_modules/remark-flow/dist/remark-custom-variable.es.js +1 -1
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/remark-flow@0.1.6/node_modules/remark-flow/dist/remark-interaction.cjs.js +1 -1
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/remark-flow@0.1.6/node_modules/remark-flow/dist/remark-interaction.es.js +1 -1
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/unified@11.0.5/node_modules/unified/lib/index.cjs.js +1 -1
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/unified@11.0.5/node_modules/unified/lib/index.es.js +1 -1
- package/dist/_virtual/index.cjs.js +1 -1
- package/dist/_virtual/index.cjs3.js +1 -1
- package/dist/_virtual/index.cjs4.js +1 -1
- package/dist/_virtual/index.cjs5.js +1 -1
- package/dist/_virtual/index.cjs6.js +1 -1
- package/dist/_virtual/index.es.js +1 -0
- package/dist/_virtual/index.es3.js +4 -5
- package/dist/_virtual/index.es3.js.map +1 -1
- package/dist/_virtual/index.es4.js +5 -4
- package/dist/_virtual/index.es4.js.map +1 -1
- package/dist/_virtual/index.es5.js +4 -4
- package/dist/_virtual/index.es6.js +5 -5
- package/dist/assets/markdown-flow-ui.css +1 -1
- package/dist/components/ContentRender/ContentRender.cjs.js +2 -2
- package/dist/components/ContentRender/ContentRender.cjs.js.map +1 -1
- package/dist/components/ContentRender/ContentRender.d.ts +13 -10
- package/dist/components/ContentRender/ContentRender.es.js +172 -155
- package/dist/components/ContentRender/ContentRender.es.js.map +1 -1
- package/dist/components/ContentRender/ContentRender.stories.d.ts +1 -0
- package/dist/components/ContentRender/IframeSandbox.cjs.js +4 -4
- package/dist/components/ContentRender/IframeSandbox.cjs.js.map +1 -1
- package/dist/components/ContentRender/IframeSandbox.d.ts +1 -0
- package/dist/components/ContentRender/IframeSandbox.es.js +214 -192
- package/dist/components/ContentRender/IframeSandbox.es.js.map +1 -1
- package/dist/components/ContentRender/SandboxApp.cjs.js +3 -3
- package/dist/components/ContentRender/SandboxApp.cjs.js.map +1 -1
- package/dist/components/ContentRender/SandboxApp.d.ts +1 -0
- package/dist/components/ContentRender/SandboxApp.es.js +90 -90
- package/dist/components/ContentRender/SandboxApp.es.js.map +1 -1
- package/dist/components/ContentRender/plugins/CustomVariable.cjs.js +1 -1
- package/dist/components/ContentRender/plugins/CustomVariable.cjs.js.map +1 -1
- package/dist/components/ContentRender/plugins/CustomVariable.es.js +94 -86
- package/dist/components/ContentRender/plugins/CustomVariable.es.js.map +1 -1
- package/dist/components/ContentRender/utils/iframe-viewport-height.cjs.js +2 -0
- package/dist/components/ContentRender/utils/iframe-viewport-height.cjs.js.map +1 -0
- package/dist/components/ContentRender/utils/iframe-viewport-height.d.ts +24 -0
- package/dist/components/ContentRender/utils/iframe-viewport-height.es.js +127 -0
- package/dist/components/ContentRender/utils/iframe-viewport-height.es.js.map +1 -0
- package/dist/components/ContentRender/utils/iframe-viewport-height.test.d.ts +1 -0
- package/dist/components/MarkdownFlow/MarkdownFlow.cjs.js +1 -1
- package/dist/components/MarkdownFlow/MarkdownFlow.cjs.js.map +1 -1
- package/dist/components/MarkdownFlow/MarkdownFlow.d.ts +3 -0
- package/dist/components/MarkdownFlow/MarkdownFlow.es.js +19 -16
- package/dist/components/MarkdownFlow/MarkdownFlow.es.js.map +1 -1
- package/dist/components/Slide/Player.cjs.js +2 -0
- package/dist/components/Slide/Player.cjs.js.map +1 -0
- package/dist/components/Slide/Player.d.ts +21 -0
- package/dist/components/Slide/Player.es.js +386 -0
- package/dist/components/Slide/Player.es.js.map +1 -0
- package/dist/components/Slide/Slide.cjs.js +2 -0
- package/dist/components/Slide/Slide.cjs.js.map +1 -0
- package/dist/components/Slide/Slide.d.ts +27 -0
- package/dist/components/Slide/Slide.es.js +583 -0
- package/dist/components/Slide/Slide.es.js.map +1 -0
- package/dist/components/Slide/Slide.stories.d.ts +79 -0
- package/dist/components/Slide/diff-utils.cjs.js +5 -0
- package/dist/components/Slide/diff-utils.cjs.js.map +1 -0
- package/dist/components/Slide/diff-utils.d.ts +18 -0
- package/dist/components/Slide/diff-utils.es.js +113 -0
- package/dist/components/Slide/diff-utils.es.js.map +1 -0
- package/dist/components/Slide/index.cjs.js +2 -0
- package/dist/components/Slide/index.cjs.js.map +1 -0
- package/dist/components/Slide/index.d.ts +12 -0
- package/dist/components/Slide/index.es.js +12 -0
- package/dist/components/Slide/index.es.js.map +1 -0
- package/dist/components/Slide/types.d.ts +24 -0
- package/dist/components/Slide/useSlide.cjs.js +2 -0
- package/dist/components/Slide/useSlide.cjs.js.map +1 -0
- package/dist/components/Slide/useSlide.d.ts +24 -0
- package/dist/components/Slide/useSlide.es.js +144 -0
- package/dist/components/Slide/useSlide.es.js.map +1 -0
- package/dist/components/Slide/useWakePlayerFromIframe.cjs.js +2 -0
- package/dist/components/Slide/useWakePlayerFromIframe.cjs.js.map +1 -0
- package/dist/components/Slide/useWakePlayerFromIframe.d.ts +7 -0
- package/dist/components/Slide/useWakePlayerFromIframe.es.js +89 -0
- package/dist/components/Slide/useWakePlayerFromIframe.es.js.map +1 -0
- package/dist/components/Slide/utils/interactionPlayback.cjs.js +2 -0
- package/dist/components/Slide/utils/interactionPlayback.cjs.js.map +1 -0
- package/dist/components/Slide/utils/interactionPlayback.d.ts +9 -0
- package/dist/components/Slide/utils/interactionPlayback.es.js +11 -0
- package/dist/components/Slide/utils/interactionPlayback.es.js.map +1 -0
- package/dist/components/Slide/utils/interactionPlayback.test.d.ts +1 -0
- package/dist/components/Slide/utils/listenModeElementList.d.ts +81 -0
- package/dist/components/Slide/utils/listenModeElementList.test.d.ts +1 -0
- package/dist/components/Slide/utils/playbackSequence.cjs.js +2 -0
- package/dist/components/Slide/utils/playbackSequence.cjs.js.map +1 -0
- package/dist/components/Slide/utils/playbackSequence.d.ts +11 -0
- package/dist/components/Slide/utils/playbackSequence.es.js +16 -0
- package/dist/components/Slide/utils/playbackSequence.es.js.map +1 -0
- package/dist/components/Slide/utils/playbackSequence.test.d.ts +1 -0
- package/dist/components/Slide/utils/playerCustomActions.cjs.js +2 -0
- package/dist/components/Slide/utils/playerCustomActions.cjs.js.map +1 -0
- package/dist/components/Slide/utils/playerCustomActions.d.ts +3 -0
- package/dist/components/Slide/utils/playerCustomActions.es.js +7 -0
- package/dist/components/Slide/utils/playerCustomActions.es.js.map +1 -0
- package/dist/components/index.d.ts +7 -0
- package/dist/components/ui/inputGroup/textarea.cjs.js +1 -1
- package/dist/components/ui/inputGroup/textarea.es.js +1 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.es.js +13 -10
- package/dist/index.es.js.map +1 -1
- package/dist/lib/browserUserActivation.d.ts +5 -0
- package/dist/lib/interaction-defaults.cjs.js +2 -0
- package/dist/lib/interaction-defaults.cjs.js.map +1 -0
- package/dist/lib/interaction-defaults.d.ts +23 -0
- package/dist/lib/interaction-defaults.es.js +145 -0
- package/dist/lib/interaction-defaults.es.js.map +1 -0
- package/dist/lib/sandboxInteraction.cjs.js +2 -0
- package/dist/lib/sandboxInteraction.cjs.js.map +1 -0
- package/dist/lib/sandboxInteraction.d.ts +8 -0
- package/dist/lib/sandboxInteraction.es.js +12 -0
- package/dist/lib/sandboxInteraction.es.js.map +1 -0
- package/dist/markdown-flow-ui-lib.css +1 -1
- package/dist/renderer.cjs.js +1 -1
- package/dist/renderer.d.ts +3 -1
- package/dist/renderer.es.js +9 -6
- package/dist/renderer.es.js.map +1 -1
- package/dist/slide.cjs.js +2 -0
- package/dist/slide.cjs.js.map +1 -0
- package/dist/slide.d.ts +2 -0
- package/dist/slide.es.js +18 -0
- package/dist/slide.es.js.map +1 -0
- package/package.json +25 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interaction-defaults.cjs.js","sources":["../../src/lib/interaction-defaults.ts"],"sourcesContent":["import { createInteractionParser } from \"remark-flow\";\n\nexport interface InteractionParseResult {\n buttonTexts?: string[];\n buttonValues?: string[];\n placeholder?: string;\n variableName?: string;\n isMultiSelect?: boolean;\n}\n\nexport interface InteractionDefaultValues {\n buttonText?: string;\n inputText?: string;\n selectedValues?: string[];\n}\n\nexport interface InteractionDefaultResolverParams {\n content?: string | null;\n rawValue?: string | null;\n interactionInfo?: InteractionParseResult | null;\n}\n\nexport type InteractionDefaultResolver = (\n params: InteractionDefaultResolverParams\n) => InteractionDefaultValues | null | undefined;\n\nexport interface InteractionDefaultValueOptions {\n resolveDefaultValues?: InteractionDefaultResolver;\n}\n\ninterface StructuredInteractionPayload {\n buttonText?: unknown;\n inputText?: unknown;\n selectedValues?: unknown;\n}\n\nconst interactionParser = createInteractionParser();\nconst INTERACTION_TAG_PATTERN = /<custom-variable\\b/i;\nconst INTERACTION_SHORTCODE_PATTERN = /\\?\\[%\\{\\{([^}]+)\\}\\}([\\s\\S]*?)\\]/;\nconst JSON_LIKE_VALUE_PATTERN = /^[\\[{]/;\n\nconst parseInteractionShortcode = (\n content?: string | null\n): InteractionParseResult | null => {\n if (!content) {\n return null;\n }\n\n const matched = content.match(INTERACTION_SHORTCODE_PATTERN);\n const variableName = matched?.[1]?.trim();\n const interactionBody = matched?.[2]?.trim();\n\n if (!interactionBody) {\n return null;\n }\n\n const isMultiSelect = interactionBody.includes(\"||\");\n const separator = isMultiSelect ? \"||\" : \"|\";\n const rawOptions = interactionBody\n .split(separator)\n .map((item) => item.trim())\n .filter(Boolean);\n\n if (!rawOptions.length) {\n return null;\n }\n\n const buttonTexts: string[] = [];\n const buttonValues: string[] = [];\n let placeholder: string | undefined;\n\n rawOptions.forEach((option) => {\n if (option.startsWith(\"...\")) {\n const normalizedPlaceholder = option.replace(/^\\.\\.\\./, \"\").trim();\n if (normalizedPlaceholder) {\n placeholder = normalizedPlaceholder;\n }\n return;\n }\n\n buttonTexts.push(option);\n buttonValues.push(option);\n });\n\n return {\n variableName,\n buttonTexts: buttonTexts.length ? buttonTexts : undefined,\n buttonValues: buttonValues.length ? buttonValues : undefined,\n placeholder,\n isMultiSelect,\n };\n};\n\nconst parseInteractionBlock = (\n content?: string | null\n): InteractionParseResult | null => {\n if (!content) {\n return null;\n }\n\n try {\n return interactionParser.parseToRemarkFormat(\n content\n ) as InteractionParseResult;\n } catch (error) {\n console.warn(\"Failed to parse interaction block\", error);\n }\n\n return parseInteractionShortcode(content);\n};\n\nconst normalizeButtonValue = (\n token: string,\n info: InteractionParseResult\n): { value: string; display?: string } | null => {\n if (!token) {\n return null;\n }\n\n const cleaned = token.trim();\n const buttonValues = info.buttonValues || [];\n const buttonTexts = info.buttonTexts || [];\n const valueIndex = buttonValues.indexOf(cleaned);\n\n if (valueIndex > -1) {\n return {\n value: buttonValues[valueIndex],\n display: buttonTexts[valueIndex],\n };\n }\n\n const textIndex = buttonTexts.indexOf(cleaned);\n\n if (textIndex > -1) {\n return {\n value: buttonValues[textIndex] || buttonTexts[textIndex],\n display: buttonTexts[textIndex],\n };\n }\n\n return null;\n};\n\nconst splitPresetValues = (raw: string) => {\n return raw\n .split(/[,,\\n]/)\n .map((item) => item.trim())\n .filter(Boolean);\n};\n\nconst normalizeStructuredInteractionDefaults = (\n payload?: StructuredInteractionPayload | null\n): InteractionDefaultValues | null => {\n if (!payload || Array.isArray(payload)) {\n return null;\n }\n\n const selectedValues = Array.isArray(payload.selectedValues)\n ? payload.selectedValues\n .map((item) => `${item ?? \"\"}`.trim())\n .filter(Boolean)\n : undefined;\n const buttonText = `${payload.buttonText ?? \"\"}`.trim();\n const inputText =\n typeof payload.inputText === \"string\" ? payload.inputText : undefined;\n\n if (!selectedValues?.length && !buttonText && !inputText) {\n return null;\n }\n\n return {\n buttonText: buttonText || undefined,\n inputText,\n selectedValues: selectedValues?.length ? selectedValues : undefined,\n };\n};\n\nconst parseStructuredInteractionDefaults = (rawValue?: string | null) => {\n if (!rawValue) {\n return null;\n }\n\n if (!JSON_LIKE_VALUE_PATTERN.test(rawValue.trim())) {\n return null;\n }\n\n try {\n const parsed = JSON.parse(rawValue) as StructuredInteractionPayload;\n return normalizeStructuredInteractionDefaults(parsed);\n } catch {\n return null;\n }\n};\n\nconst hasPotentialInteractionBlock = (content?: string | null) =>\n Boolean(\n content &&\n (INTERACTION_TAG_PATTERN.test(content) ||\n INTERACTION_SHORTCODE_PATTERN.test(content))\n );\n\nconst resolveCustomInteractionDefaults = (\n content?: string | null,\n rawValue?: string | null,\n interactionInfo?: InteractionParseResult | null,\n options?: InteractionDefaultValueOptions\n) => {\n return (\n options?.resolveDefaultValues?.({\n content,\n rawValue,\n interactionInfo,\n }) ?? null\n );\n};\n\nexport const getInteractionDefaultValues = (\n content?: string | null,\n rawValue?: string | null,\n options?: InteractionDefaultValueOptions\n): InteractionDefaultValues => {\n const normalized = rawValue?.toString().trim();\n\n if (!normalized) {\n return {};\n }\n\n const structuredDefaults = parseStructuredInteractionDefaults(normalized);\n\n if (structuredDefaults) {\n return structuredDefaults;\n }\n\n const customDefaults = resolveCustomInteractionDefaults(\n content,\n normalized,\n null,\n options\n );\n\n if (customDefaults) {\n return customDefaults;\n }\n\n if (!hasPotentialInteractionBlock(content)) {\n return {\n buttonText: normalized,\n inputText: normalized,\n };\n }\n\n const interactionInfo = parseInteractionBlock(content);\n const customDefaultsWithInteraction = resolveCustomInteractionDefaults(\n content,\n normalized,\n interactionInfo,\n options\n );\n\n if (customDefaultsWithInteraction) {\n return customDefaultsWithInteraction;\n }\n\n if (!interactionInfo) {\n return {\n buttonText: normalized,\n inputText: normalized,\n };\n }\n\n if (interactionInfo.isMultiSelect) {\n const tokens = splitPresetValues(normalized);\n\n if (!tokens.length) {\n return {};\n }\n\n const selectedValues: string[] = [];\n const customInputs: string[] = [];\n\n tokens.forEach((token) => {\n const mapped = normalizeButtonValue(token, interactionInfo);\n\n if (mapped) {\n selectedValues.push(mapped.value);\n return;\n }\n\n if (interactionInfo.placeholder) {\n customInputs.push(token);\n return;\n }\n\n selectedValues.push(token);\n });\n\n return {\n selectedValues: selectedValues.length ? selectedValues : undefined,\n inputText: customInputs.length ? customInputs.join(\", \") : undefined,\n };\n }\n\n const mapped = normalizeButtonValue(normalized, interactionInfo);\n\n if (mapped) {\n return {\n buttonText: mapped.value || mapped.display || normalized,\n };\n }\n\n if (interactionInfo.placeholder) {\n return {\n inputText: normalized,\n };\n }\n\n return {\n buttonText: normalized,\n inputText: normalized,\n };\n};\n\nexport const getInteractionDefaultSelectedValues = (\n content?: string | null,\n rawValue?: string | null,\n options?: InteractionDefaultValueOptions\n) => {\n const defaults = getInteractionDefaultValues(content, rawValue, options);\n\n if (defaults.selectedValues) {\n return defaults.selectedValues;\n }\n\n return rawValue\n ? rawValue\n .split(\",\")\n .map((value) => value.trim())\n .filter(Boolean)\n : undefined;\n};\n"],"names":["interactionParser","createInteractionParser","INTERACTION_TAG_PATTERN","INTERACTION_SHORTCODE_PATTERN","JSON_LIKE_VALUE_PATTERN","parseInteractionShortcode","content","matched","variableName","interactionBody","isMultiSelect","separator","rawOptions","item","buttonTexts","buttonValues","placeholder","option","normalizedPlaceholder","parseInteractionBlock","error","normalizeButtonValue","token","info","cleaned","valueIndex","textIndex","splitPresetValues","raw","normalizeStructuredInteractionDefaults","payload","selectedValues","buttonText","inputText","parseStructuredInteractionDefaults","rawValue","parsed","hasPotentialInteractionBlock","resolveCustomInteractionDefaults","interactionInfo","options","getInteractionDefaultValues","normalized","structuredDefaults","customDefaults","customDefaultsWithInteraction","tokens","customInputs","mapped","getInteractionDefaultSelectedValues","defaults","value"],"mappings":"4HAoCMA,EAAoBC,EAAAA,YAAAA,wBAAA,EACpBC,EAA0B,sBAC1BC,EAAgC,mCAChCC,EAA0B,SAE1BC,EACJC,GACkC,CAClC,GAAI,CAACA,EACH,OAAO,KAGT,MAAMC,EAAUD,EAAQ,MAAMH,CAA6B,EACrDK,EAAeD,IAAU,CAAC,GAAG,KAAA,EAC7BE,EAAkBF,IAAU,CAAC,GAAG,KAAA,EAEtC,GAAI,CAACE,EACH,OAAO,KAGT,MAAMC,EAAgBD,EAAgB,SAAS,IAAI,EAC7CE,EAAYD,EAAgB,KAAO,IACnCE,EAAaH,EAChB,MAAME,CAAS,EACf,IAAKE,GAASA,EAAK,KAAA,CAAM,EACzB,OAAO,OAAO,EAEjB,GAAI,CAACD,EAAW,OACd,OAAO,KAGT,MAAME,EAAwB,CAAA,EACxBC,EAAyB,CAAA,EAC/B,IAAIC,EAEJ,OAAAJ,EAAW,QAASK,GAAW,CAC7B,GAAIA,EAAO,WAAW,KAAK,EAAG,CAC5B,MAAMC,EAAwBD,EAAO,QAAQ,UAAW,EAAE,EAAE,KAAA,EACxDC,IACFF,EAAcE,GAEhB,MACF,CAEAJ,EAAY,KAAKG,CAAM,EACvBF,EAAa,KAAKE,CAAM,CAC1B,CAAC,EAEM,CACL,aAAAT,EACA,YAAaM,EAAY,OAASA,EAAc,OAChD,aAAcC,EAAa,OAASA,EAAe,OACnD,YAAAC,EACA,cAAAN,CAAA,CAEJ,EAEMS,EACJb,GACkC,CAClC,GAAI,CAACA,EACH,OAAO,KAGT,GAAI,CACF,OAAON,EAAkB,oBACvBM,CAAA,CAEJ,OAASc,EAAO,CACd,QAA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AWgB,EAAa,OAASA,EAAa,KAAK,IAAI,EAAI,MAAA,CAE/D,CAEA,MAAMC,EAAS3B,EAAqBqB,EAAYH,CAAe,EAE/D,OAAIS,EACK,CACL,WAAYA,EAAO,OAASA,EAAO,SAAWN,CAAA,EAI9CH,EAAgB,YACX,CACL,UAAWG,CAAA,EAIR,CACL,WAAYA,EACZ,UAAWA,CAAA,CAEf,EAEaO,EAAsC,CACjD3C,EACA6B,EACAK,IACG,CACH,MAAMU,EAAWT,EAA4BnC,EAAS6B,EAAUK,CAAO,EAEvE,OAAIU,EAAS,eACJA,EAAS,eAGXf,EACHA,EACG,MAAM,GAAG,EACT,IAAKgB,GAAUA,EAAM,KAAA,CAAM,EAC3B,OAAO,OAAO,EACjB,MACN"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface InteractionParseResult {
|
|
2
|
+
buttonTexts?: string[];
|
|
3
|
+
buttonValues?: string[];
|
|
4
|
+
placeholder?: string;
|
|
5
|
+
variableName?: string;
|
|
6
|
+
isMultiSelect?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface InteractionDefaultValues {
|
|
9
|
+
buttonText?: string;
|
|
10
|
+
inputText?: string;
|
|
11
|
+
selectedValues?: string[];
|
|
12
|
+
}
|
|
13
|
+
export interface InteractionDefaultResolverParams {
|
|
14
|
+
content?: string | null;
|
|
15
|
+
rawValue?: string | null;
|
|
16
|
+
interactionInfo?: InteractionParseResult | null;
|
|
17
|
+
}
|
|
18
|
+
export type InteractionDefaultResolver = (params: InteractionDefaultResolverParams) => InteractionDefaultValues | null | undefined;
|
|
19
|
+
export interface InteractionDefaultValueOptions {
|
|
20
|
+
resolveDefaultValues?: InteractionDefaultResolver;
|
|
21
|
+
}
|
|
22
|
+
export declare const getInteractionDefaultValues: (content?: string | null, rawValue?: string | null, options?: InteractionDefaultValueOptions) => InteractionDefaultValues;
|
|
23
|
+
export declare const getInteractionDefaultSelectedValues: (content?: string | null, rawValue?: string | null, options?: InteractionDefaultValueOptions) => string[] | undefined;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { d as x } from "../_virtual/index.es.js";
|
|
2
|
+
const b = x.createInteractionParser(), I = /<custom-variable\b/i, h = /\?\[%\{\{([^}]+)\}\}([\s\S]*?)\]/, v = /^[\[{]/, V = (t) => {
|
|
3
|
+
if (!t)
|
|
4
|
+
return null;
|
|
5
|
+
const r = t.match(h), s = r?.[1]?.trim(), e = r?.[2]?.trim();
|
|
6
|
+
if (!e)
|
|
7
|
+
return null;
|
|
8
|
+
const u = e.includes("||"), o = u ? "||" : "|", n = e.split(o).map((l) => l.trim()).filter(Boolean);
|
|
9
|
+
if (!n.length)
|
|
10
|
+
return null;
|
|
11
|
+
const c = [], i = [];
|
|
12
|
+
let f;
|
|
13
|
+
return n.forEach((l) => {
|
|
14
|
+
if (l.startsWith("...")) {
|
|
15
|
+
const a = l.replace(/^\.\.\./, "").trim();
|
|
16
|
+
a && (f = a);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
c.push(l), i.push(l);
|
|
20
|
+
}), {
|
|
21
|
+
variableName: s,
|
|
22
|
+
buttonTexts: c.length ? c : void 0,
|
|
23
|
+
buttonValues: i.length ? i : void 0,
|
|
24
|
+
placeholder: f,
|
|
25
|
+
isMultiSelect: u
|
|
26
|
+
};
|
|
27
|
+
}, g = (t) => {
|
|
28
|
+
if (!t)
|
|
29
|
+
return null;
|
|
30
|
+
try {
|
|
31
|
+
return b.parseToRemarkFormat(
|
|
32
|
+
t
|
|
33
|
+
);
|
|
34
|
+
} catch (r) {
|
|
35
|
+
console.warn("Failed to parse interaction block", r);
|
|
36
|
+
}
|
|
37
|
+
return V(t);
|
|
38
|
+
}, m = (t, r) => {
|
|
39
|
+
if (!t)
|
|
40
|
+
return null;
|
|
41
|
+
const s = t.trim(), e = r.buttonValues || [], u = r.buttonTexts || [], o = e.indexOf(s);
|
|
42
|
+
if (o > -1)
|
|
43
|
+
return {
|
|
44
|
+
value: e[o],
|
|
45
|
+
display: u[o]
|
|
46
|
+
};
|
|
47
|
+
const n = u.indexOf(s);
|
|
48
|
+
return n > -1 ? {
|
|
49
|
+
value: e[n] || u[n],
|
|
50
|
+
display: u[n]
|
|
51
|
+
} : null;
|
|
52
|
+
}, A = (t) => t.split(/[,,\n]/).map((r) => r.trim()).filter(Boolean), E = (t) => {
|
|
53
|
+
if (!t || Array.isArray(t))
|
|
54
|
+
return null;
|
|
55
|
+
const r = Array.isArray(t.selectedValues) ? t.selectedValues.map((u) => `${u ?? ""}`.trim()).filter(Boolean) : void 0, s = `${t.buttonText ?? ""}`.trim(), e = typeof t.inputText == "string" ? t.inputText : void 0;
|
|
56
|
+
return !r?.length && !s && !e ? null : {
|
|
57
|
+
buttonText: s || void 0,
|
|
58
|
+
inputText: e,
|
|
59
|
+
selectedValues: r?.length ? r : void 0
|
|
60
|
+
};
|
|
61
|
+
}, S = (t) => {
|
|
62
|
+
if (!t || !v.test(t.trim()))
|
|
63
|
+
return null;
|
|
64
|
+
try {
|
|
65
|
+
const r = JSON.parse(t);
|
|
66
|
+
return E(r);
|
|
67
|
+
} catch {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
}, D = (t) => !!(t && (I.test(t) || h.test(t))), T = (t, r, s, e) => e?.resolveDefaultValues?.({
|
|
71
|
+
content: t,
|
|
72
|
+
rawValue: r,
|
|
73
|
+
interactionInfo: s
|
|
74
|
+
}) ?? null, N = (t, r, s) => {
|
|
75
|
+
const e = r?.toString().trim();
|
|
76
|
+
if (!e)
|
|
77
|
+
return {};
|
|
78
|
+
const u = S(e);
|
|
79
|
+
if (u)
|
|
80
|
+
return u;
|
|
81
|
+
const o = T(
|
|
82
|
+
t,
|
|
83
|
+
e,
|
|
84
|
+
null,
|
|
85
|
+
s
|
|
86
|
+
);
|
|
87
|
+
if (o)
|
|
88
|
+
return o;
|
|
89
|
+
if (!D(t))
|
|
90
|
+
return {
|
|
91
|
+
buttonText: e,
|
|
92
|
+
inputText: e
|
|
93
|
+
};
|
|
94
|
+
const n = g(t), c = T(
|
|
95
|
+
t,
|
|
96
|
+
e,
|
|
97
|
+
n,
|
|
98
|
+
s
|
|
99
|
+
);
|
|
100
|
+
if (c)
|
|
101
|
+
return c;
|
|
102
|
+
if (!n)
|
|
103
|
+
return {
|
|
104
|
+
buttonText: e,
|
|
105
|
+
inputText: e
|
|
106
|
+
};
|
|
107
|
+
if (n.isMultiSelect) {
|
|
108
|
+
const f = A(e);
|
|
109
|
+
if (!f.length)
|
|
110
|
+
return {};
|
|
111
|
+
const l = [], a = [];
|
|
112
|
+
return f.forEach((d) => {
|
|
113
|
+
const p = m(d, n);
|
|
114
|
+
if (p) {
|
|
115
|
+
l.push(p.value);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (n.placeholder) {
|
|
119
|
+
a.push(d);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
l.push(d);
|
|
123
|
+
}), {
|
|
124
|
+
selectedValues: l.length ? l : void 0,
|
|
125
|
+
inputText: a.length ? a.join(", ") : void 0
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
const i = m(e, n);
|
|
129
|
+
return i ? {
|
|
130
|
+
buttonText: i.value || i.display || e
|
|
131
|
+
} : n.placeholder ? {
|
|
132
|
+
inputText: e
|
|
133
|
+
} : {
|
|
134
|
+
buttonText: e,
|
|
135
|
+
inputText: e
|
|
136
|
+
};
|
|
137
|
+
}, O = (t, r, s) => {
|
|
138
|
+
const e = N(t, r, s);
|
|
139
|
+
return e.selectedValues ? e.selectedValues : r ? r.split(",").map((u) => u.trim()).filter(Boolean) : void 0;
|
|
140
|
+
};
|
|
141
|
+
export {
|
|
142
|
+
O as getInteractionDefaultSelectedValues,
|
|
143
|
+
N as getInteractionDefaultValues
|
|
144
|
+
};
|
|
145
|
+
//# sourceMappingURL=interaction-defaults.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interaction-defaults.es.js","sources":["../../src/lib/interaction-defaults.ts"],"sourcesContent":["import { createInteractionParser } from \"remark-flow\";\n\nexport interface InteractionParseResult {\n buttonTexts?: string[];\n buttonValues?: string[];\n placeholder?: string;\n variableName?: string;\n isMultiSelect?: boolean;\n}\n\nexport interface InteractionDefaultValues {\n buttonText?: string;\n inputText?: string;\n selectedValues?: string[];\n}\n\nexport interface InteractionDefaultResolverParams {\n content?: string | null;\n rawValue?: string | null;\n interactionInfo?: InteractionParseResult | null;\n}\n\nexport type InteractionDefaultResolver = (\n params: InteractionDefaultResolverParams\n) => InteractionDefaultValues | null | undefined;\n\nexport interface InteractionDefaultValueOptions {\n resolveDefaultValues?: InteractionDefaultResolver;\n}\n\ninterface StructuredInteractionPayload {\n buttonText?: unknown;\n inputText?: unknown;\n selectedValues?: unknown;\n}\n\nconst interactionParser = createInteractionParser();\nconst INTERACTION_TAG_PATTERN = /<custom-variable\\b/i;\nconst INTERACTION_SHORTCODE_PATTERN = /\\?\\[%\\{\\{([^}]+)\\}\\}([\\s\\S]*?)\\]/;\nconst JSON_LIKE_VALUE_PATTERN = /^[\\[{]/;\n\nconst parseInteractionShortcode = (\n content?: string | null\n): InteractionParseResult | null => {\n if (!content) {\n return null;\n }\n\n const matched = content.match(INTERACTION_SHORTCODE_PATTERN);\n const variableName = matched?.[1]?.trim();\n const interactionBody = matched?.[2]?.trim();\n\n if (!interactionBody) {\n return null;\n }\n\n const isMultiSelect = interactionBody.includes(\"||\");\n const separator = isMultiSelect ? \"||\" : \"|\";\n const rawOptions = interactionBody\n .split(separator)\n .map((item) => item.trim())\n .filter(Boolean);\n\n if (!rawOptions.length) {\n return null;\n }\n\n const buttonTexts: string[] = [];\n const buttonValues: string[] = [];\n let placeholder: string | undefined;\n\n rawOptions.forEach((option) => {\n if (option.startsWith(\"...\")) {\n const normalizedPlaceholder = option.replace(/^\\.\\.\\./, \"\").trim();\n if (normalizedPlaceholder) {\n placeholder = normalizedPlaceholder;\n }\n return;\n }\n\n buttonTexts.push(option);\n buttonValues.push(option);\n });\n\n return {\n variableName,\n buttonTexts: buttonTexts.length ? buttonTexts : undefined,\n buttonValues: buttonValues.length ? buttonValues : undefined,\n placeholder,\n isMultiSelect,\n };\n};\n\nconst parseInteractionBlock = (\n content?: string | null\n): InteractionParseResult | null => {\n if (!content) {\n return null;\n }\n\n try {\n return interactionParser.parseToRemarkFormat(\n content\n ) as InteractionParseResult;\n } catch (error) {\n console.warn(\"Failed to parse interaction block\", error);\n }\n\n return parseInteractionShortcode(content);\n};\n\nconst normalizeButtonValue = (\n token: string,\n info: InteractionParseResult\n): { value: string; display?: string } | null => {\n if (!token) {\n return null;\n }\n\n const cleaned = token.trim();\n const buttonValues = info.buttonValues || [];\n const buttonTexts = info.buttonTexts || [];\n const valueIndex = buttonValues.indexOf(cleaned);\n\n if (valueIndex > -1) {\n return {\n value: buttonValues[valueIndex],\n display: buttonTexts[valueIndex],\n };\n }\n\n const textIndex = buttonTexts.indexOf(cleaned);\n\n if (textIndex > -1) {\n return {\n value: buttonValues[textIndex] || buttonTexts[textIndex],\n display: buttonTexts[textIndex],\n };\n }\n\n return null;\n};\n\nconst splitPresetValues = (raw: string) => {\n return raw\n .split(/[,,\\n]/)\n .map((item) => item.trim())\n .filter(Boolean);\n};\n\nconst normalizeStructuredInteractionDefaults = (\n payload?: StructuredInteractionPayload | null\n): InteractionDefaultValues | null => {\n if (!payload || Array.isArray(payload)) {\n return null;\n }\n\n const selectedValues = Array.isArray(payload.selectedValues)\n ? payload.selectedValues\n .map((item) => `${item ?? \"\"}`.trim())\n .filter(Boolean)\n : undefined;\n const buttonText = `${payload.buttonText ?? \"\"}`.trim();\n const inputText =\n typeof payload.inputText === \"string\" ? payload.inputText : undefined;\n\n if (!selectedValues?.length && !buttonText && !inputText) {\n return null;\n }\n\n return {\n buttonText: buttonText || undefined,\n inputText,\n selectedValues: selectedValues?.length ? selectedValues : undefined,\n };\n};\n\nconst parseStructuredInteractionDefaults = (rawValue?: string | null) => {\n if (!rawValue) {\n return null;\n }\n\n if (!JSON_LIKE_VALUE_PATTERN.test(rawValue.trim())) {\n return null;\n }\n\n try {\n const parsed = JSON.parse(rawValue) as StructuredInteractionPayload;\n return normalizeStructuredInteractionDefaults(parsed);\n } catch {\n return null;\n }\n};\n\nconst hasPotentialInteractionBlock = (content?: string | null) =>\n Boolean(\n content &&\n (INTERACTION_TAG_PATTERN.test(content) ||\n INTERACTION_SHORTCODE_PATTERN.test(content))\n );\n\nconst resolveCustomInteractionDefaults = (\n content?: string | null,\n rawValue?: string | null,\n interactionInfo?: InteractionParseResult | null,\n options?: InteractionDefaultValueOptions\n) => {\n return (\n options?.resolveDefaultValues?.({\n content,\n rawValue,\n interactionInfo,\n }) ?? null\n );\n};\n\nexport const getInteractionDefaultValues = (\n content?: string | null,\n rawValue?: string | null,\n options?: InteractionDefaultValueOptions\n): InteractionDefaultValues => {\n const normalized = rawValue?.toString().trim();\n\n if (!normalized) {\n return {};\n }\n\n const structuredDefaults = parseStructuredInteractionDefaults(normalized);\n\n if (structuredDefaults) {\n return structuredDefaults;\n }\n\n const customDefaults = resolveCustomInteractionDefaults(\n content,\n normalized,\n null,\n options\n );\n\n if (customDefaults) {\n return customDefaults;\n }\n\n if (!hasPotentialInteractionBlock(content)) {\n return {\n buttonText: normalized,\n inputText: normalized,\n };\n }\n\n const interactionInfo = parseInteractionBlock(content);\n const customDefaultsWithInteraction = resolveCustomInteractionDefaults(\n content,\n normalized,\n interactionInfo,\n options\n );\n\n if (customDefaultsWithInteraction) {\n return customDefaultsWithInteraction;\n }\n\n if (!interactionInfo) {\n return {\n buttonText: normalized,\n inputText: normalized,\n };\n }\n\n if (interactionInfo.isMultiSelect) {\n const tokens = splitPresetValues(normalized);\n\n if (!tokens.length) {\n return {};\n }\n\n const selectedValues: string[] = [];\n const customInputs: string[] = [];\n\n tokens.forEach((token) => {\n const mapped = normalizeButtonValue(token, interactionInfo);\n\n if (mapped) {\n selectedValues.push(mapped.value);\n return;\n }\n\n if (interactionInfo.placeholder) {\n customInputs.push(token);\n return;\n }\n\n selectedValues.push(token);\n });\n\n return {\n selectedValues: selectedValues.length ? selectedValues : undefined,\n inputText: customInputs.length ? customInputs.join(\", \") : undefined,\n };\n }\n\n const mapped = normalizeButtonValue(normalized, interactionInfo);\n\n if (mapped) {\n return {\n buttonText: mapped.value || mapped.display || normalized,\n };\n }\n\n if (interactionInfo.placeholder) {\n return {\n inputText: normalized,\n };\n }\n\n return {\n buttonText: normalized,\n inputText: normalized,\n };\n};\n\nexport const getInteractionDefaultSelectedValues = (\n content?: string | null,\n rawValue?: string | null,\n options?: InteractionDefaultValueOptions\n) => {\n const defaults = getInteractionDefaultValues(content, rawValue, options);\n\n if (defaults.selectedValues) {\n return defaults.selectedValues;\n }\n\n return rawValue\n ? rawValue\n .split(\",\")\n .map((value) => value.trim())\n .filter(Boolean)\n : undefined;\n};\n"],"names":["interactionParser","createInteractionParser","INTERACTION_TAG_PATTERN","INTERACTION_SHORTCODE_PATTERN","JSON_LIKE_VALUE_PATTERN","parseInteractionShortcode","content","matched","variableName","interactionBody","isMultiSelect","separator","rawOptions","item","buttonTexts","buttonValues","placeholder","option","normalizedPlaceholder","parseInteractionBlock","error","normalizeButtonValue","token","info","cleaned","valueIndex","textIndex","splitPresetValues","raw","normalizeStructuredInteractionDefaults","payload","selectedValues","buttonText","inputText","parseStructuredInteractionDefaults","rawValue","parsed","hasPotentialInteractionBlock","resolveCustomInteractionDefaults","interactionInfo","options","getInteractionDefaultValues","normalized","structuredDefaults","customDefaults","customDefaultsWithInteraction","tokens","customInputs","mapped","getInteractionDefaultSelectedValues","defaults","value"],"mappings":";AAoCA,MAAMA,IAAoBC,EAAAA,wBAAA,GACpBC,IAA0B,uBAC1BC,IAAgC,oCAChCC,IAA0B,UAE1BC,IAA4B,CAChCC,MACkC;AAClC,MAAI,CAACA;AACH,WAAO;AAGT,QAAMC,IAAUD,EAAQ,MAAMH,CAA6B,GACrDK,IAAeD,IAAU,CAAC,GAAG,KAAA,GAC7BE,IAAkBF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;AAEA,QAAMC,IAAS3B,EAAqBqB,GAAYH,CAAe;AAE/D,SAAIS,IACK;AAAA,IACL,YAAYA,EAAO,SAASA,EAAO,WAAWN;AAAA,EAAA,IAI9CH,EAAgB,cACX;AAAA,IACL,WAAWG;AAAA,EAAA,IAIR;AAAA,IACL,YAAYA;AAAA,IACZ,WAAWA;AAAA,EAAA;AAEf,GAEaO,IAAsC,CACjD3C,GACA6B,GACAK,MACG;AACH,QAAMU,IAAWT,EAA4BnC,GAAS6B,GAAUK,CAAO;AAEvE,SAAIU,EAAS,iBACJA,EAAS,iBAGXf,IACHA,EACG,MAAM,GAAG,EACT,IAAI,CAACgB,MAAUA,EAAM,KAAA,CAAM,EAC3B,OAAO,OAAO,IACjB;AACN;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n="markdown-flow-ui:sandbox",o="interaction",s=e=>{if(!e||typeof e!="object")return!1;const t=e;return t.source===n&&t.type===o&&typeof t.eventType=="string"};exports.SANDBOX_INTERACTION_MESSAGE_SOURCE=n;exports.SANDBOX_INTERACTION_MESSAGE_TYPE=o;exports.isSandboxInteractionMessage=s;
|
|
2
|
+
//# sourceMappingURL=sandboxInteraction.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sandboxInteraction.cjs.js","sources":["../../src/lib/sandboxInteraction.ts"],"sourcesContent":["export const SANDBOX_INTERACTION_MESSAGE_SOURCE = \"markdown-flow-ui:sandbox\";\nexport const SANDBOX_INTERACTION_MESSAGE_TYPE = \"interaction\";\n\nexport interface SandboxInteractionMessage {\n source: typeof SANDBOX_INTERACTION_MESSAGE_SOURCE;\n type: typeof SANDBOX_INTERACTION_MESSAGE_TYPE;\n eventType: string;\n}\n\nexport const isSandboxInteractionMessage = (\n data: unknown\n): data is SandboxInteractionMessage => {\n if (!data || typeof data !== \"object\") {\n return false;\n }\n\n const message = data as Partial<SandboxInteractionMessage>;\n\n return (\n message.source === SANDBOX_INTERACTION_MESSAGE_SOURCE &&\n message.type === SANDBOX_INTERACTION_MESSAGE_TYPE &&\n typeof message.eventType === \"string\"\n );\n};\n"],"names":["SANDBOX_INTERACTION_MESSAGE_SOURCE","SANDBOX_INTERACTION_MESSAGE_TYPE","isSandboxInteractionMessage","data","message"],"mappings":"gFAAO,MAAMA,EAAqC,2BACrCC,EAAmC,cAQnCC,EACXC,GACsC,CACtC,GAAI,CAACA,GAAQ,OAAOA,GAAS,SAC3B,MAAO,GAGT,MAAMC,EAAUD,EAEhB,OACEC,EAAQ,SAAWJ,GACnBI,EAAQ,OAASH,GACjB,OAAOG,EAAQ,WAAc,QAEjC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const SANDBOX_INTERACTION_MESSAGE_SOURCE = "markdown-flow-ui:sandbox";
|
|
2
|
+
export declare const SANDBOX_INTERACTION_MESSAGE_TYPE = "interaction";
|
|
3
|
+
export interface SandboxInteractionMessage {
|
|
4
|
+
source: typeof SANDBOX_INTERACTION_MESSAGE_SOURCE;
|
|
5
|
+
type: typeof SANDBOX_INTERACTION_MESSAGE_TYPE;
|
|
6
|
+
eventType: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const isSandboxInteractionMessage: (data: unknown) => data is SandboxInteractionMessage;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const o = "markdown-flow-ui:sandbox", t = "interaction", s = (e) => {
|
|
2
|
+
if (!e || typeof e != "object")
|
|
3
|
+
return !1;
|
|
4
|
+
const n = e;
|
|
5
|
+
return n.source === o && n.type === t && typeof n.eventType == "string";
|
|
6
|
+
};
|
|
7
|
+
export {
|
|
8
|
+
o as SANDBOX_INTERACTION_MESSAGE_SOURCE,
|
|
9
|
+
t as SANDBOX_INTERACTION_MESSAGE_TYPE,
|
|
10
|
+
s as isSandboxInteractionMessage
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=sandboxInteraction.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sandboxInteraction.es.js","sources":["../../src/lib/sandboxInteraction.ts"],"sourcesContent":["export const SANDBOX_INTERACTION_MESSAGE_SOURCE = \"markdown-flow-ui:sandbox\";\nexport const SANDBOX_INTERACTION_MESSAGE_TYPE = \"interaction\";\n\nexport interface SandboxInteractionMessage {\n source: typeof SANDBOX_INTERACTION_MESSAGE_SOURCE;\n type: typeof SANDBOX_INTERACTION_MESSAGE_TYPE;\n eventType: string;\n}\n\nexport const isSandboxInteractionMessage = (\n data: unknown\n): data is SandboxInteractionMessage => {\n if (!data || typeof data !== \"object\") {\n return false;\n }\n\n const message = data as Partial<SandboxInteractionMessage>;\n\n return (\n message.source === SANDBOX_INTERACTION_MESSAGE_SOURCE &&\n message.type === SANDBOX_INTERACTION_MESSAGE_TYPE &&\n typeof message.eventType === \"string\"\n );\n};\n"],"names":["SANDBOX_INTERACTION_MESSAGE_SOURCE","SANDBOX_INTERACTION_MESSAGE_TYPE","isSandboxInteractionMessage","data","message"],"mappings":"AAAO,MAAMA,IAAqC,4BACrCC,IAAmC,eAQnCC,IAA8B,CACzCC,MACsC;AACtC,MAAI,CAACA,KAAQ,OAAOA,KAAS;AAC3B,WAAO;AAGT,QAAMC,IAAUD;AAEhB,SACEC,EAAQ,WAAWJ,KACnBI,EAAQ,SAASH,KACjB,OAAOG,EAAQ,aAAc;AAEjC;"}
|