@scalar/api-client 3.19.2 → 3.20.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/CHANGELOG.md +64 -0
- package/dist/components/HttpMethod/HttpMethod.vue.d.ts +2 -2
- package/dist/components/SectionFilter.vue.d.ts +2 -0
- package/dist/components/SectionFilter.vue.d.ts.map +1 -1
- package/dist/components/SectionFilter.vue.js +1 -1
- package/dist/components/SectionFilter.vue.js.map +1 -1
- package/dist/components/SectionFilter.vue.script.js +11 -8
- package/dist/components/SectionFilter.vue.script.js.map +1 -1
- package/dist/components/Server/ServerVariablesSelect.vue.d.ts.map +1 -1
- package/dist/components/Server/ServerVariablesSelect.vue.js.map +1 -1
- package/dist/components/Server/ServerVariablesSelect.vue.script.js +5 -3
- package/dist/components/Server/ServerVariablesSelect.vue.script.js.map +1 -1
- package/dist/components/Server/ServerVariablesTextbox.vue.d.ts.map +1 -1
- package/dist/components/Server/ServerVariablesTextbox.vue.js.map +1 -1
- package/dist/components/Server/ServerVariablesTextbox.vue.script.js +6 -3
- package/dist/components/Server/ServerVariablesTextbox.vue.script.js.map +1 -1
- package/dist/components/Sidebar/Actions/DeleteSidebarListElement.vue.d.ts.map +1 -1
- package/dist/components/Sidebar/Actions/DeleteSidebarListElement.vue.js.map +1 -1
- package/dist/components/Sidebar/Actions/DeleteSidebarListElement.vue.script.js +4 -2
- package/dist/components/Sidebar/Actions/DeleteSidebarListElement.vue.script.js.map +1 -1
- package/dist/components/Sidebar/Actions/SidebarListElementForm.vue.d.ts.map +1 -1
- package/dist/components/Sidebar/Actions/SidebarListElementForm.vue.js.map +1 -1
- package/dist/components/Sidebar/Actions/SidebarListElementForm.vue.script.js +3 -1
- package/dist/components/Sidebar/Actions/SidebarListElementForm.vue.script.js.map +1 -1
- package/dist/style.css +159 -135
- package/dist/v2/blocks/operation-block/OperationBlock.vue.d.ts +10 -1
- package/dist/v2/blocks/operation-block/OperationBlock.vue.d.ts.map +1 -1
- package/dist/v2/blocks/operation-block/OperationBlock.vue.js.map +1 -1
- package/dist/v2/blocks/operation-block/OperationBlock.vue.script.js +46 -5
- package/dist/v2/blocks/operation-block/OperationBlock.vue.script.js.map +1 -1
- package/dist/v2/blocks/operation-block/components/Header.vue.d.ts +2 -0
- package/dist/v2/blocks/operation-block/components/Header.vue.d.ts.map +1 -1
- package/dist/v2/blocks/operation-block/components/Header.vue.js +1 -1
- package/dist/v2/blocks/operation-block/components/Header.vue.js.map +1 -1
- package/dist/v2/blocks/operation-block/components/Header.vue.script.js +15 -8
- package/dist/v2/blocks/operation-block/components/Header.vue.script.js.map +1 -1
- package/dist/v2/blocks/operation-block/components/OpenApiClientButton.vue.d.ts.map +1 -1
- package/dist/v2/blocks/operation-block/components/OpenApiClientButton.vue.js +1 -1
- package/dist/v2/blocks/operation-block/components/OpenApiClientButton.vue.js.map +1 -1
- package/dist/v2/blocks/operation-block/components/OpenApiClientButton.vue.script.js +4 -2
- package/dist/v2/blocks/operation-block/components/OpenApiClientButton.vue.script.js.map +1 -1
- package/dist/v2/blocks/operation-block/helpers/send-request.d.ts.map +1 -1
- package/dist/v2/blocks/operation-block/helpers/send-request.js +4 -3
- package/dist/v2/blocks/operation-block/helpers/send-request.js.map +1 -1
- package/dist/v2/blocks/request-block/RequestBlock.vue.d.ts +2 -0
- package/dist/v2/blocks/request-block/RequestBlock.vue.d.ts.map +1 -1
- package/dist/v2/blocks/request-block/RequestBlock.vue.js +1 -1
- package/dist/v2/blocks/request-block/RequestBlock.vue.js.map +1 -1
- package/dist/v2/blocks/request-block/RequestBlock.vue.script.js +51 -26
- package/dist/v2/blocks/request-block/RequestBlock.vue.script.js.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestBody.vue.d.ts.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestBody.vue.js +1 -1
- package/dist/v2/blocks/request-block/components/RequestBody.vue.js.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestBody.vue.script.js +28 -8
- package/dist/v2/blocks/request-block/components/RequestBody.vue.script.js.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestBodyStructured.vue.d.ts.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestBodyStructured.vue.js.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestBodyStructured.vue.script.js +9 -3
- package/dist/v2/blocks/request-block/components/RequestBodyStructured.vue.script.js.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestBodyViewToggle.vue.d.ts.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestBodyViewToggle.vue.js.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestBodyViewToggle.vue.script.js +6 -4
- package/dist/v2/blocks/request-block/components/RequestBodyViewToggle.vue.script.js.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestCodeSnippet.vue.d.ts.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestCodeSnippet.vue.js.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestCodeSnippet.vue.script.js +3 -1
- package/dist/v2/blocks/request-block/components/RequestCodeSnippet.vue.script.js.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestParams.vue.d.ts.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestParams.vue.js.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestParams.vue.script.js +7 -5
- package/dist/v2/blocks/request-block/components/RequestParams.vue.script.js.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestTable.vue.d.ts +2 -2
- package/dist/v2/blocks/request-block/components/RequestTable.vue.d.ts.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestTable.vue.js +1 -1
- package/dist/v2/blocks/request-block/components/RequestTable.vue.js.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestTable.vue.script.js +40 -7
- package/dist/v2/blocks/request-block/components/RequestTable.vue.script.js.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestTableRow.vue.d.ts +12 -12
- package/dist/v2/blocks/request-block/components/RequestTableRow.vue.d.ts.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestTableRow.vue.js.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestTableRow.vue.script.js +24 -20
- package/dist/v2/blocks/request-block/components/RequestTableRow.vue.script.js.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestTableTooltip.vue.d.ts.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestTableTooltip.vue.js.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestTableTooltip.vue.script.js +6 -4
- package/dist/v2/blocks/request-block/components/RequestTableTooltip.vue.script.js.map +1 -1
- package/dist/v2/blocks/request-block/helpers/create-parameter-rows.d.ts.map +1 -1
- package/dist/v2/blocks/request-block/helpers/create-parameter-rows.js +1 -1
- package/dist/v2/blocks/request-block/helpers/create-parameter-rows.js.map +1 -1
- package/dist/v2/blocks/request-block/helpers/get-form-body-rows.d.ts.map +1 -1
- package/dist/v2/blocks/request-block/helpers/get-form-body-rows.js +5 -4
- package/dist/v2/blocks/request-block/helpers/get-form-body-rows.js.map +1 -1
- package/dist/v2/blocks/response-block/ResponseBlock.vue.d.ts +2 -0
- package/dist/v2/blocks/response-block/ResponseBlock.vue.d.ts.map +1 -1
- package/dist/v2/blocks/response-block/ResponseBlock.vue.js +1 -1
- package/dist/v2/blocks/response-block/ResponseBlock.vue.js.map +1 -1
- package/dist/v2/blocks/response-block/ResponseBlock.vue.script.js +37 -13
- package/dist/v2/blocks/response-block/ResponseBlock.vue.script.js.map +1 -1
- package/dist/v2/blocks/response-block/components/Headers.vue.d.ts +3 -3
- package/dist/v2/blocks/response-block/components/Headers.vue.d.ts.map +1 -1
- package/dist/v2/blocks/response-block/components/Headers.vue.js.map +1 -1
- package/dist/v2/blocks/response-block/components/Headers.vue.script.js +5 -3
- package/dist/v2/blocks/response-block/components/Headers.vue.script.js.map +1 -1
- package/dist/v2/blocks/response-block/components/ResponseBody.vue.d.ts.map +1 -1
- package/dist/v2/blocks/response-block/components/ResponseBody.vue.js +1 -1
- package/dist/v2/blocks/response-block/components/ResponseBody.vue.js.map +1 -1
- package/dist/v2/blocks/response-block/components/ResponseBody.vue.script.js +3 -1
- package/dist/v2/blocks/response-block/components/ResponseBody.vue.script.js.map +1 -1
- package/dist/v2/blocks/response-block/components/ResponseBodyDownload.vue.d.ts.map +1 -1
- package/dist/v2/blocks/response-block/components/ResponseBodyDownload.vue.js.map +1 -1
- package/dist/v2/blocks/response-block/components/ResponseBodyDownload.vue.script.js +11 -3
- package/dist/v2/blocks/response-block/components/ResponseBodyDownload.vue.script.js.map +1 -1
- package/dist/v2/blocks/response-block/components/ResponseBodyPreview.vue.d.ts.map +1 -1
- package/dist/v2/blocks/response-block/components/ResponseBodyPreview.vue.js +1 -1
- package/dist/v2/blocks/response-block/components/ResponseBodyPreview.vue.js.map +1 -1
- package/dist/v2/blocks/response-block/components/ResponseBodyPreview.vue.script.js +8 -6
- package/dist/v2/blocks/response-block/components/ResponseBodyPreview.vue.script.js.map +1 -1
- package/dist/v2/blocks/response-block/components/ResponseBodyStreaming.vue.d.ts +1 -0
- package/dist/v2/blocks/response-block/components/ResponseBodyStreaming.vue.d.ts.map +1 -1
- package/dist/v2/blocks/response-block/components/ResponseBodyStreaming.vue.js.map +1 -1
- package/dist/v2/blocks/response-block/components/ResponseBodyStreaming.vue.script.js +109 -56
- package/dist/v2/blocks/response-block/components/ResponseBodyStreaming.vue.script.js.map +1 -1
- package/dist/v2/blocks/response-block/components/ResponseBodyToggle.vue.d.ts.map +1 -1
- package/dist/v2/blocks/response-block/components/ResponseBodyToggle.vue.js.map +1 -1
- package/dist/v2/blocks/response-block/components/ResponseBodyToggle.vue.script.js +5 -3
- package/dist/v2/blocks/response-block/components/ResponseBodyToggle.vue.script.js.map +1 -1
- package/dist/v2/blocks/response-block/components/ResponseBodyVirtual.vue.d.ts.map +1 -1
- package/dist/v2/blocks/response-block/components/ResponseBodyVirtual.vue.js.map +1 -1
- package/dist/v2/blocks/response-block/components/ResponseBodyVirtual.vue.script.js +6 -3
- package/dist/v2/blocks/response-block/components/ResponseBodyVirtual.vue.script.js.map +1 -1
- package/dist/v2/blocks/response-block/components/ResponseCookies.vue.d.ts.map +1 -1
- package/dist/v2/blocks/response-block/components/ResponseCookies.vue.js.map +1 -1
- package/dist/v2/blocks/response-block/components/ResponseCookies.vue.script.js +7 -5
- package/dist/v2/blocks/response-block/components/ResponseCookies.vue.script.js.map +1 -1
- package/dist/v2/blocks/response-block/components/ResponseEmpty.vue.d.ts +4 -2
- package/dist/v2/blocks/response-block/components/ResponseEmpty.vue.d.ts.map +1 -1
- package/dist/v2/blocks/response-block/components/ResponseEmpty.vue.js +1 -1
- package/dist/v2/blocks/response-block/components/ResponseEmpty.vue.js.map +1 -1
- package/dist/v2/blocks/response-block/components/ResponseEmpty.vue.script.js +22 -14
- package/dist/v2/blocks/response-block/components/ResponseEmpty.vue.script.js.map +1 -1
- package/dist/v2/blocks/response-block/components/ResponseLoadingOverlay.vue.d.ts.map +1 -1
- package/dist/v2/blocks/response-block/components/ResponseLoadingOverlay.vue.js +1 -1
- package/dist/v2/blocks/response-block/components/ResponseLoadingOverlay.vue.js.map +1 -1
- package/dist/v2/blocks/response-block/components/ResponseLoadingOverlay.vue.script.js +4 -2
- package/dist/v2/blocks/response-block/components/ResponseLoadingOverlay.vue.script.js.map +1 -1
- package/dist/v2/blocks/response-block/components/ResponseMetaInformation.vue.d.ts.map +1 -1
- package/dist/v2/blocks/response-block/components/ResponseMetaInformation.vue.js.map +1 -1
- package/dist/v2/blocks/response-block/components/ResponseMetaInformation.vue.script.js +11 -6
- package/dist/v2/blocks/response-block/components/ResponseMetaInformation.vue.script.js.map +1 -1
- package/dist/v2/blocks/response-block/helpers/response-stream-multipart.d.ts +4 -0
- package/dist/v2/blocks/response-block/helpers/response-stream-multipart.d.ts.map +1 -0
- package/dist/v2/blocks/response-block/helpers/response-stream-multipart.js +100 -0
- package/dist/v2/blocks/response-block/helpers/response-stream-multipart.js.map +1 -0
- package/dist/v2/blocks/response-block/helpers/response-stream.d.ts +13 -0
- package/dist/v2/blocks/response-block/helpers/response-stream.d.ts.map +1 -0
- package/dist/v2/blocks/response-block/helpers/response-stream.js +97 -0
- package/dist/v2/blocks/response-block/helpers/response-stream.js.map +1 -0
- package/dist/v2/blocks/scalar-address-bar-block/components/AddressBar.vue.d.ts +3 -1
- package/dist/v2/blocks/scalar-address-bar-block/components/AddressBar.vue.d.ts.map +1 -1
- package/dist/v2/blocks/scalar-address-bar-block/components/AddressBar.vue.js +1 -1
- package/dist/v2/blocks/scalar-address-bar-block/components/AddressBar.vue.js.map +1 -1
- package/dist/v2/blocks/scalar-address-bar-block/components/AddressBar.vue.script.js +42 -29
- package/dist/v2/blocks/scalar-address-bar-block/components/AddressBar.vue.script.js.map +1 -1
- package/dist/v2/blocks/scalar-address-bar-block/components/AddressBarHistory.vue.d.ts +6 -6
- package/dist/v2/blocks/scalar-address-bar-block/components/AddressBarHistory.vue.d.ts.map +1 -1
- package/dist/v2/blocks/scalar-address-bar-block/components/AddressBarHistory.vue.js +1 -1
- package/dist/v2/blocks/scalar-address-bar-block/components/AddressBarHistory.vue.js.map +1 -1
- package/dist/v2/blocks/scalar-address-bar-block/components/AddressBarHistory.vue.script.js +7 -4
- package/dist/v2/blocks/scalar-address-bar-block/components/AddressBarHistory.vue.script.js.map +1 -1
- package/dist/v2/blocks/scalar-address-bar-block/components/EnvironmentSelector.vue.d.ts.map +1 -1
- package/dist/v2/blocks/scalar-address-bar-block/components/EnvironmentSelector.vue.js.map +1 -1
- package/dist/v2/blocks/scalar-address-bar-block/components/EnvironmentSelector.vue.script.js +21 -16
- package/dist/v2/blocks/scalar-address-bar-block/components/EnvironmentSelector.vue.script.js.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/components/AuthSelector.vue.d.ts.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/components/AuthSelector.vue.js.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/components/AuthSelector.vue.script.js +7 -5
- package/dist/v2/blocks/scalar-auth-selector-block/components/AuthSelector.vue.script.js.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/components/DeleteRequestAuthModal.vue.d.ts.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/components/DeleteRequestAuthModal.vue.js.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/components/DeleteRequestAuthModal.vue.script.js +7 -5
- package/dist/v2/blocks/scalar-auth-selector-block/components/DeleteRequestAuthModal.vue.script.js.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/components/OAuth2.vue.d.ts.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/components/OAuth2.vue.js.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/components/OAuth2.vue.script.js +105 -40
- package/dist/v2/blocks/scalar-auth-selector-block/components/OAuth2.vue.script.js.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/components/OAuthScopesAddModal.vue.d.ts.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/components/OAuthScopesAddModal.vue.js.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/components/OAuthScopesAddModal.vue.script.js +10 -8
- package/dist/v2/blocks/scalar-auth-selector-block/components/OAuthScopesAddModal.vue.script.js.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/components/OAuthScopesInput.vue.d.ts.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/components/OAuthScopesInput.vue.js.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/components/OAuthScopesInput.vue.script.js +14 -9
- package/dist/v2/blocks/scalar-auth-selector-block/components/OAuthScopesInput.vue.script.js.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/components/OpenIDConnect.vue.d.ts.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/components/OpenIDConnect.vue.js.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/components/OpenIDConnect.vue.script.js +6 -4
- package/dist/v2/blocks/scalar-auth-selector-block/components/OpenIDConnect.vue.script.js.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/components/RequestAuthDataTable.vue.d.ts.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/components/RequestAuthDataTable.vue.js.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/components/RequestAuthDataTable.vue.script.js +3 -1
- package/dist/v2/blocks/scalar-auth-selector-block/components/RequestAuthDataTable.vue.script.js.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/components/RequestAuthTab.vue.d.ts.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/components/RequestAuthTab.vue.js.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/components/RequestAuthTab.vue.script.js +40 -40
- package/dist/v2/blocks/scalar-auth-selector-block/components/RequestAuthTab.vue.script.js.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/auth-options.d.ts +108 -7
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/auth-options.d.ts.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/auth-options.js +12 -0
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/auth-options.js.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/extract-security-scheme-secrets.d.ts.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/fetch-oauth2-metadata.d.ts.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/fetch-oauth2-metadata.js +8 -5
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/fetch-oauth2-metadata.js.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/fetch-openid-connect-discovery.d.ts +2 -0
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/fetch-openid-connect-discovery.d.ts.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/fetch-openid-connect-discovery.js +2 -0
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/fetch-openid-connect-discovery.js.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/is-allowed-oauth-url.d.ts +3 -0
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/is-allowed-oauth-url.d.ts.map +1 -0
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/is-allowed-oauth-url.js +8 -0
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/is-allowed-oauth-url.js.map +1 -0
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/oauth-client-authorization.d.ts +3 -0
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/oauth-client-authorization.d.ts.map +1 -0
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/oauth-client-authorization.js +11 -0
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/oauth-client-authorization.js.map +1 -0
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/oauth-device-authorization.d.ts +19 -0
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/oauth-device-authorization.d.ts.map +1 -0
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/oauth-device-authorization.js +117 -0
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/oauth-device-authorization.js.map +1 -0
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/oauth.d.ts +2 -1
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/oauth.d.ts.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/oauth.js +15 -11
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/oauth.js.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/oauth2-metadata-to-flows.d.ts +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/oauth2-metadata-to-flows.d.ts.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/oauth2-metadata-to-flows.js +8 -1
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/oauth2-metadata-to-flows.js.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/openid-discovery-to-flows.d.ts.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/openid-discovery-to-flows.js +6 -0
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/openid-discovery-to-flows.js.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/security-scheme.d.ts +2 -1
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/security-scheme.d.ts.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/security-scheme.js +8 -6
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/security-scheme.js.map +1 -1
- package/dist/v2/components/code-input/CodeInput.vue.d.ts +4 -4
- package/dist/v2/components/code-input/CodeInput.vue.d.ts.map +1 -1
- package/dist/v2/components/code-input/CodeInput.vue.js +1 -1
- package/dist/v2/components/code-input/CodeInput.vue.js.map +1 -1
- package/dist/v2/components/code-input/CodeInput.vue.script.js +10 -10
- package/dist/v2/components/code-input/CodeInput.vue.script.js.map +1 -1
- package/dist/v2/components/code-input/CodeInputLite.vue.d.ts +4 -4
- package/dist/v2/components/code-input/CodeInputLite.vue.d.ts.map +1 -1
- package/dist/v2/components/code-input/CodeInputLite.vue.js +1 -1
- package/dist/v2/components/code-input/CodeInputLite.vue.js.map +1 -1
- package/dist/v2/components/code-input/CodeInputLite.vue.script.js +8 -5
- package/dist/v2/components/code-input/CodeInputLite.vue.script.js.map +1 -1
- package/dist/v2/components/code-input/PillTooltipHost.vue.d.ts +4 -0
- package/dist/v2/components/code-input/PillTooltipHost.vue.d.ts.map +1 -1
- package/dist/v2/components/code-input/PillTooltipHost.vue.js.map +1 -1
- package/dist/v2/components/code-input/PillTooltipHost.vue.script.js +7 -3
- package/dist/v2/components/code-input/PillTooltipHost.vue.script.js.map +1 -1
- package/dist/v2/components/code-input/code-variable-widget.d.ts +3 -0
- package/dist/v2/components/code-input/code-variable-widget.d.ts.map +1 -1
- package/dist/v2/components/code-input/code-variable-widget.js +6 -3
- package/dist/v2/components/code-input/code-variable-widget.js.map +1 -1
- package/dist/v2/components/data-table/DataTableCheckbox.vue.d.ts +0 -1
- package/dist/v2/components/data-table/DataTableCheckbox.vue.d.ts.map +1 -1
- package/dist/v2/components/data-table/DataTableCheckbox.vue.js.map +1 -1
- package/dist/v2/components/data-table/DataTableCheckbox.vue.script.js +4 -2
- package/dist/v2/components/data-table/DataTableCheckbox.vue.script.js.map +1 -1
- package/dist/v2/components/data-table/DataTableInput.vue.d.ts.map +1 -1
- package/dist/v2/components/data-table/DataTableInput.vue.js +1 -1
- package/dist/v2/components/data-table/DataTableInput.vue.js.map +1 -1
- package/dist/v2/components/data-table/DataTableInput.vue.script.js +5 -3
- package/dist/v2/components/data-table/DataTableInput.vue.script.js.map +1 -1
- package/dist/v2/components/data-table/DataTableInputSelect.vue.d.ts.map +1 -1
- package/dist/v2/components/data-table/DataTableInputSelect.vue.js.map +1 -1
- package/dist/v2/components/data-table/DataTableInputSelect.vue.script.js +12 -9
- package/dist/v2/components/data-table/DataTableInputSelect.vue.script.js.map +1 -1
- package/dist/v2/components/forms/ConfirmationForm.vue.d.ts.map +1 -1
- package/dist/v2/components/forms/ConfirmationForm.vue.js.map +1 -1
- package/dist/v2/components/forms/ConfirmationForm.vue.script.js +5 -3
- package/dist/v2/components/forms/ConfirmationForm.vue.script.js.map +1 -1
- package/dist/v2/components/layout/CollapsibleSection.vue.d.ts.map +1 -1
- package/dist/v2/components/layout/CollapsibleSection.vue.js.map +1 -1
- package/dist/v2/components/layout/CollapsibleSection.vue.script.js +3 -1
- package/dist/v2/components/layout/CollapsibleSection.vue.script.js.map +1 -1
- package/dist/v2/components/modals/DeleteModal.vue.d.ts.map +1 -1
- package/dist/v2/components/modals/DeleteModal.vue.js.map +1 -1
- package/dist/v2/components/modals/DeleteModal.vue.script.js +3 -1
- package/dist/v2/components/modals/DeleteModal.vue.script.js.map +1 -1
- package/dist/v2/components/modals/ModalClientContainer.vue.d.ts.map +1 -1
- package/dist/v2/components/modals/ModalClientContainer.vue.js +1 -1
- package/dist/v2/components/modals/ModalClientContainer.vue.js.map +1 -1
- package/dist/v2/components/modals/ModalClientContainer.vue.script.js +5 -2
- package/dist/v2/components/modals/ModalClientContainer.vue.script.js.map +1 -1
- package/dist/v2/components/server/ServerDropdown.vue.d.ts.map +1 -1
- package/dist/v2/components/server/ServerDropdown.vue.js.map +1 -1
- package/dist/v2/components/server/ServerDropdown.vue.script.js +9 -5
- package/dist/v2/components/server/ServerDropdown.vue.script.js.map +1 -1
- package/dist/v2/components/sidebar/Sidebar.vue.d.ts.map +1 -1
- package/dist/v2/components/sidebar/Sidebar.vue.js.map +1 -1
- package/dist/v2/components/sidebar/Sidebar.vue.script.js +4 -2
- package/dist/v2/components/sidebar/Sidebar.vue.script.js.map +1 -1
- package/dist/v2/components/sidebar/SidebarMenu.vue.d.ts.map +1 -1
- package/dist/v2/components/sidebar/SidebarMenu.vue.js.map +1 -1
- package/dist/v2/components/sidebar/SidebarMenu.vue.script.js +4 -2
- package/dist/v2/components/sidebar/SidebarMenu.vue.script.js.map +1 -1
- package/dist/v2/components/sidebar/SidebarToggle.vue.d.ts.map +1 -1
- package/dist/v2/components/sidebar/SidebarToggle.vue.js.map +1 -1
- package/dist/v2/components/sidebar/SidebarToggle.vue.script.js +4 -2
- package/dist/v2/components/sidebar/SidebarToggle.vue.script.js.map +1 -1
- package/dist/v2/constants.js +1 -1
- package/dist/v2/features/command-palette/components/CommandActionForm.vue.d.ts.map +1 -1
- package/dist/v2/features/command-palette/components/CommandActionForm.vue.js.map +1 -1
- package/dist/v2/features/command-palette/components/CommandActionForm.vue.script.js +4 -2
- package/dist/v2/features/command-palette/components/CommandActionForm.vue.script.js.map +1 -1
- package/dist/v2/features/command-palette/components/CommandActionInput.vue.d.ts +2 -2
- package/dist/v2/features/environments/EnvironmentsList.vue.d.ts.map +1 -1
- package/dist/v2/features/environments/EnvironmentsList.vue.js.map +1 -1
- package/dist/v2/features/environments/EnvironmentsList.vue.script.js +4 -2
- package/dist/v2/features/environments/EnvironmentsList.vue.script.js.map +1 -1
- package/dist/v2/features/environments/components/Environment.vue.d.ts.map +1 -1
- package/dist/v2/features/environments/components/Environment.vue.js.map +1 -1
- package/dist/v2/features/environments/components/Environment.vue.script.js +12 -10
- package/dist/v2/features/environments/components/Environment.vue.script.js.map +1 -1
- package/dist/v2/features/environments/components/EnvironmentCreateModal.vue.d.ts.map +1 -1
- package/dist/v2/features/environments/components/EnvironmentCreateModal.vue.js.map +1 -1
- package/dist/v2/features/environments/components/EnvironmentCreateModal.vue.script.js +5 -3
- package/dist/v2/features/environments/components/EnvironmentCreateModal.vue.script.js.map +1 -1
- package/dist/v2/features/environments/components/EnvironmentDeleteModal.vue.d.ts.map +1 -1
- package/dist/v2/features/environments/components/EnvironmentDeleteModal.vue.js.map +1 -1
- package/dist/v2/features/environments/components/EnvironmentDeleteModal.vue.script.js +9 -6
- package/dist/v2/features/environments/components/EnvironmentDeleteModal.vue.script.js.map +1 -1
- package/dist/v2/features/environments/components/EnvironmentVariablesDropdown.vue.d.ts.map +1 -1
- package/dist/v2/features/environments/components/EnvironmentVariablesDropdown.vue.js.map +1 -1
- package/dist/v2/features/environments/components/EnvironmentVariablesDropdown.vue.script.js +6 -4
- package/dist/v2/features/environments/components/EnvironmentVariablesDropdown.vue.script.js.map +1 -1
- package/dist/v2/features/environments/components/EnvironmentVariablesTable.vue.d.ts.map +1 -1
- package/dist/v2/features/environments/components/EnvironmentVariablesTable.vue.js +1 -1
- package/dist/v2/features/environments/components/EnvironmentVariablesTable.vue.js.map +1 -1
- package/dist/v2/features/environments/components/EnvironmentVariablesTable.vue.script.js +22 -10
- package/dist/v2/features/environments/components/EnvironmentVariablesTable.vue.script.js.map +1 -1
- package/dist/v2/features/localization/index.d.ts +18 -0
- package/dist/v2/features/localization/index.d.ts.map +1 -0
- package/dist/v2/features/localization/index.js +35 -0
- package/dist/v2/features/localization/index.js.map +1 -0
- package/dist/v2/features/localization/locales/ar.d.ts +385 -0
- package/dist/v2/features/localization/locales/ar.d.ts.map +1 -0
- package/dist/v2/features/localization/locales/ar.js +345 -0
- package/dist/v2/features/localization/locales/ar.js.map +1 -0
- package/dist/v2/features/localization/locales/de.d.ts +385 -0
- package/dist/v2/features/localization/locales/de.d.ts.map +1 -0
- package/dist/v2/features/localization/locales/de.js +345 -0
- package/dist/v2/features/localization/locales/de.js.map +1 -0
- package/dist/v2/features/localization/locales/es.d.ts +385 -0
- package/dist/v2/features/localization/locales/es.d.ts.map +1 -0
- package/dist/v2/features/localization/locales/es.js +345 -0
- package/dist/v2/features/localization/locales/es.js.map +1 -0
- package/dist/v2/features/localization/locales/fr.d.ts +385 -0
- package/dist/v2/features/localization/locales/fr.d.ts.map +1 -0
- package/dist/v2/features/localization/locales/fr.js +345 -0
- package/dist/v2/features/localization/locales/fr.js.map +1 -0
- package/dist/v2/features/localization/locales/pt.d.ts +385 -0
- package/dist/v2/features/localization/locales/pt.d.ts.map +1 -0
- package/dist/v2/features/localization/locales/pt.js +345 -0
- package/dist/v2/features/localization/locales/pt.js.map +1 -0
- package/dist/v2/features/localization/locales/ru.d.ts +385 -0
- package/dist/v2/features/localization/locales/ru.d.ts.map +1 -0
- package/dist/v2/features/localization/locales/ru.js +345 -0
- package/dist/v2/features/localization/locales/ru.js.map +1 -0
- package/dist/v2/features/localization/locales/zh-cn.d.ts +385 -0
- package/dist/v2/features/localization/locales/zh-cn.d.ts.map +1 -0
- package/dist/v2/features/localization/locales/zh-cn.js +345 -0
- package/dist/v2/features/localization/locales/zh-cn.js.map +1 -0
- package/dist/v2/features/localization/translations.d.ts +385 -0
- package/dist/v2/features/localization/translations.d.ts.map +1 -0
- package/dist/v2/features/localization/translations.js +345 -0
- package/dist/v2/features/localization/translations.js.map +1 -0
- package/dist/v2/features/modal/Modal.vue.d.ts.map +1 -1
- package/dist/v2/features/modal/Modal.vue.js.map +1 -1
- package/dist/v2/features/modal/Modal.vue.script.js +17 -4
- package/dist/v2/features/modal/Modal.vue.script.js.map +1 -1
- package/dist/v2/features/modal/use-lazy-api-client.d.ts +11 -0
- package/dist/v2/features/modal/use-lazy-api-client.d.ts.map +1 -0
- package/dist/v2/features/modal/use-lazy-api-client.js +48 -0
- package/dist/v2/features/modal/use-lazy-api-client.js.map +1 -0
- package/dist/v2/features/operation/Operation.vue.d.ts +2 -0
- package/dist/v2/features/operation/Operation.vue.d.ts.map +1 -1
- package/dist/v2/features/operation/Operation.vue.js.map +1 -1
- package/dist/v2/features/operation/Operation.vue.script.js +50 -12
- package/dist/v2/features/operation/Operation.vue.script.js.map +1 -1
- package/dist/v2/features/search/components/DocumentSearchModal.vue.d.ts.map +1 -1
- package/dist/v2/features/search/components/DocumentSearchModal.vue.js +1 -1
- package/dist/v2/features/search/components/DocumentSearchModal.vue.js.map +1 -1
- package/dist/v2/features/search/components/DocumentSearchModal.vue.script.js +12 -8
- package/dist/v2/features/search/components/DocumentSearchModal.vue.script.js.map +1 -1
- package/dist/v2/features/search/components/SearchResult.vue.d.ts.map +1 -1
- package/dist/v2/features/search/components/SearchResult.vue.js.map +1 -1
- package/dist/v2/features/search/components/SearchResult.vue.script.js +14 -10
- package/dist/v2/features/search/components/SearchResult.vue.script.js.map +1 -1
- package/dist/v2/types/options.d.ts +1 -1
- package/dist/v2/types/options.d.ts.map +1 -1
- package/dist/v2/workspace-events.d.ts +2 -2
- package/dist/v2/workspace-events.d.ts.map +1 -1
- package/dist/v2/workspace-events.js +8 -1
- package/dist/v2/workspace-events.js.map +1 -1
- package/dist/vue-styles.css +124 -125
- package/package.json +22 -11
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeInput.vue.js","names":[],"sources":["../../../../src/v2/components/code-input/CodeInput.vue"],"sourcesContent":["<script lang=\"ts\">\nexport type CodeInputModelValue =\n | string\n | number\n | boolean\n | Array<string | number | boolean>\n | Record<string, unknown>\n\n/**\n * CodeInput\n *\n * A versatile input component that adapts its rendering based on props:\n * - Disabled mode: Read-only text display\n * - Select mode: Dropdown for enums, booleans, or examples\n * - Editor mode: CodeMirror with environment variable support\n *\n * Type `{{` to trigger autocomplete for environment variables and runtime context functions\n * (for example `{{$guid}}`) when an environment is provided.\n * It takes in any data but always will emit a string value,\n * this string should then be parsed in accordance to the schema or content type.\n *\n * @example\n * ```vue\n * <!-- Basic input with environment variables -->\n * <CodeInput v-model=\"value\" :environment=\"env\" />\n *\n * <!-- Boolean select -->\n * <CodeInput v-model=\"flag\" type=\"boolean\" />\n *\n * <!-- JSON editor with linting -->\n * <CodeInput v-model=\"data\" language=\"json\" :lint=\"true\" />\n * ```\n */\nexport default {\n inheritAttrs: false,\n}\n</script>\n\n<script setup lang=\"ts\">\nimport { ScalarIconButton } from '@scalar/components/icon-button'\nimport { isDefined } from '@scalar/helpers/array/is-defined'\nimport { ScalarIconArrowElbowDownLeft } from '@scalar/icons'\nimport {\n colorPicker as colorPickerExtension,\n EditorView,\n useCodeMirror,\n useDropdown,\n type CodeMirrorLanguage,\n type Extension,\n} from '@scalar/use-codemirror'\nimport {\n CONTEXT_FUNCTION_NAMES,\n getContextFunctionComment,\n isContextFunctionName,\n} from '@scalar/workspace-store/request-example'\nimport type { XScalarEnvironment } from '@scalar/workspace-store/schemas/extensions/document/x-scalar-environments'\nimport { nanoid } from 'nanoid'\nimport { computed, ref, toRef, useAttrs, watch, type Ref } from 'vue'\n\nimport DataTableInputSelect from '@/v2/components/data-table/DataTableInputSelect.vue'\nimport EnvironmentVariableDropdown from '@/v2/features/environments/components/EnvironmentVariablesDropdown.vue'\nimport type { ClientLayout } from '@/v2/types/layout'\n\nimport { backspaceCommand, pillPlugin } from './code-variable-widget'\n\ntype Props = {\n modelValue: CodeInputModelValue\n /** Environment for variable substitution. Pass undefined to disable environment variables */\n environment: XScalarEnvironment | undefined\n /** Type of the input value, affects rendering mode for booleans */\n type?: string | string[]\n /** Render as disabled text display */\n disabled?: boolean\n /** Show error styling */\n error?: boolean\n /** Layout context affects styling and behavior */\n layout?: ClientLayout\n /** Predefined enum values, triggers select mode */\n enum?: string[]\n /** Example values, triggers select mode */\n examples?: string[]\n /** Default value to show in select mode */\n default?: Props['modelValue']\n /** Allow null in boolean select options */\n nullable?: boolean\n /** Placeholder text for empty input */\n placeholder?: string\n /** Show required indicator */\n required?: boolean\n /** Enable color picker extension */\n colorPicker?: boolean\n /** Show line numbers in editor */\n lineNumbers?: boolean\n /** Enable linting */\n lint?: boolean\n /** Enable line wrapping */\n lineWrapping?: boolean\n /** CodeMirror language mode */\n language?: CodeMirrorLanguage\n /** Additional CodeMirror extensions */\n extensions?: Extension[]\n /** Disable tab key for indentation */\n disableTabIndent?: boolean\n /** Disable enter key */\n disableEnter?: boolean\n /** Disable automatic bracket closing */\n disableCloseBrackets?: boolean\n /** Emit submit event on blur */\n emitOnBlur?: boolean\n /** Enable environment variable pills */\n withVariables?: boolean\n /** Enable fake data suggestions like $guid, $timestamp, etc. Should only be enabled for parameters and request bodies */\n withFakeData?: boolean\n /** Emit change event even if the value is the same */\n alwaysEmitChange?: boolean\n /** Custom change handler, prevents default emit */\n handleFieldChange?: (value: string) => void\n /** Custom submit handler, prevents default emit */\n handleFieldSubmit?: (value: string) => void\n /** Put a linethrough on the input text */\n linethrough?: boolean\n}\n\nconst {\n modelValue,\n environment,\n type,\n disabled = false,\n error = false,\n layout = 'desktop',\n enum: enumProp,\n examples,\n default: defaultProp,\n nullable = false,\n placeholder,\n required,\n colorPicker = false,\n lineNumbers = false,\n lint = false,\n lineWrapping = false,\n language,\n extensions = [],\n disableTabIndent = false,\n disableEnter = false,\n disableCloseBrackets = false,\n emitOnBlur = true,\n alwaysEmitChange = false,\n withVariables = true,\n withFakeData = false,\n handleFieldChange,\n handleFieldSubmit,\n} = defineProps<Props>()\n\nconst emit = defineEmits<{\n 'update:modelValue': [value: string]\n 'submit': [value: string, event: KeyboardEvent | FocusEvent]\n 'navigate': [route: { page: 'document'; path: 'environment' }]\n 'blur': [value: string, event: FocusEvent]\n}>()\n\n// ---------------------------------------------------------------------------\n// Component identity and focus state\n\nconst attrs = useAttrs()\nconst componentId =\n (typeof attrs.id === 'string' && attrs.id) || `id-${nanoid()}`\nconst isFocused = ref(false)\n\n// ---------------------------------------------------------------------------\n// Rendering mode detection\n\n/**\n * Determines if we should render a select dropdown for boolean types.\n */\nconst isBooleanMode = computed((): boolean => {\n if (enumProp?.length) {\n return false\n }\n return type === 'boolean' || (Array.isArray(type) && type.includes('boolean'))\n})\n\n/**\n * Options for boolean select mode.\n */\nconst booleanOptions = computed((): string[] =>\n nullable ? ['true', 'false', 'null'] : ['true', 'false'],\n)\n\n/**\n * Default type when dealing with type arrays.\n * Finds the first non-null type.\n */\nconst defaultType = computed((): string | undefined => {\n if (Array.isArray(type)) {\n return type.find((t) => t !== 'null') ?? 'string'\n }\n return type\n})\n\n// ---------------------------------------------------------------------------\n// Event handlers\n\n/**\n * Handles value changes during typing.\n */\nconst handleChange = (value: string): void => {\n if (!alwaysEmitChange && value === serializeValue(modelValue)) {\n return\n }\n\n // Use custom handler or emit update\n if (handleFieldChange) {\n handleFieldChange(value)\n } else {\n emit('update:modelValue', value)\n }\n}\n\n/**\n * Handles form submission (enter key or blur with emitOnBlur).\n */\nconst handleSubmit = (\n value: string,\n event: KeyboardEvent | FocusEvent,\n): void => {\n if (handleFieldSubmit) {\n handleFieldSubmit(value)\n } else {\n emit('submit', value, event)\n }\n}\n\n/**\n * Handles input blur event.\n */\nconst handleBlur = (value: string, event: FocusEvent): void => {\n isFocused.value = false\n\n if (emitOnBlur && modelValue) {\n handleSubmit(value, event)\n }\n\n emit('blur', value, event)\n}\n\n/**\n * Handles model value updates from select components.\n */\nconst handleSelectChange = (value: string): void =>\n emit('update:modelValue', value)\n\n// ---------------------------------------------------------------------------\n// CodeMirror setup\n\n/**\n * Build extensions array.\n * Note: Extensions are not reactive after initialization.\n */\nconst buildExtensions = (): Extension[] => {\n const extensionsList: Extension[] = [...extensions]\n\n if (colorPicker) {\n extensionsList.push(colorPickerExtension)\n }\n\n return extensionsList\n}\n\n/**\n * Reactive pill plugin for environment variable visualization.\n */\nconst contextFunctionDropdownItems = computed(() =>\n withFakeData\n ? CONTEXT_FUNCTION_NAMES.map((key) => ({\n key,\n description: getContextFunctionComment(key),\n }))\n : [],\n)\n\nconst pillPluginExtension = computed(() =>\n pillPlugin({\n environment,\n isContextFunctionName,\n isReadOnly: layout === 'modal',\n }),\n)\n\nconst isLineWrapping = ref(lineWrapping)\n\nwatch(\n () => lineWrapping,\n (val) => {\n isLineWrapping.value = val\n },\n)\n\nconst toggleLineWrapping = (): void => {\n isLineWrapping.value = !isLineWrapping.value\n}\n\nconst lineWrappingExtension = computed(() =>\n isLineWrapping.value ? [EditorView.lineWrapping] : [],\n)\n\n/**\n * Combined extensions for CodeMirror.\n */\nconst codeMirrorExtensions = computed((): Extension[] => [\n ...buildExtensions(),\n ...lineWrappingExtension.value,\n pillPluginExtension.value,\n backspaceCommand,\n])\n\nconst codeMirrorRef: Ref<HTMLDivElement | null> = ref(null)\n\n/** Converts the model value to a string for CodeMirror */\nconst serializeValue = (value: CodeInputModelValue): string => {\n if (typeof value === 'string') {\n return value\n }\n return JSON.stringify(value)\n}\n\nconst { codeMirror, setCodeMirrorContent } = useCodeMirror({\n content: toRef(() => serializeValue(modelValue)),\n onChange: (value) => {\n handleChange(value)\n updateDropdownVisibility()\n },\n onFocus: () => {\n isFocused.value = true\n },\n onBlur: handleBlur,\n codeMirrorRef,\n disableTabIndent: toRef(() => disableTabIndent),\n disableEnter: toRef(() => disableEnter),\n disableCloseBrackets: toRef(() => disableCloseBrackets),\n lineNumbers: toRef(() => lineNumbers),\n language: toRef(() => language),\n lint: toRef(() => lint),\n extensions: codeMirrorExtensions,\n placeholder: toRef(() => placeholder),\n})\n\n/**\n * Handle autofocus attribute.\n */\nwatch(codeMirror, () => {\n if (codeMirror.value && Object.hasOwn(attrs, 'autofocus')) {\n codeMirror.value.focus()\n }\n})\n\n// ---------------------------------------------------------------------------\n// Environment variable dropdown\n\nconst showDropdown = ref(false)\nconst dropdownQuery = ref('')\nconst dropdownPosition = ref({ left: 0, top: 0 })\nconst dropdownRef = ref<InstanceType<\n typeof EnvironmentVariableDropdown\n> | null>(null)\n\nconst { handleDropdownSelect, updateDropdownVisibility } = useDropdown({\n codeMirror,\n query: dropdownQuery,\n showDropdown,\n dropdownPosition,\n})\n\n/**\n * Determines if the environment variable dropdown should be visible.\n * Shows when environment is defined (for env vars) or withFakeData is true (for context functions)\n */\nconst displayVariablesDropdown = computed((): boolean => {\n return (\n showDropdown.value &&\n withVariables &&\n layout !== 'modal' &&\n (Boolean(environment) || withFakeData)\n )\n})\n\n// ---------------------------------------------------------------------------\n// Keyboard event handling\n\n/**\n * Handles keyboard navigation for dropdown and form submission.\n */\nconst handleKeyDown = (key: string, event: KeyboardEvent): void => {\n if (showDropdown.value) {\n if (key === 'down' || key === 'up') {\n event.preventDefault()\n dropdownRef.value?.handleArrowKey(key)\n } else if (key === 'enter') {\n event.preventDefault()\n dropdownRef.value?.handleSelect()\n }\n return\n }\n\n if (key === 'escape' && !disableTabIndent) {\n event.stopPropagation()\n }\n\n if (key === 'enter' && event.target instanceof HTMLDivElement) {\n handleSubmit(codeMirror.value?.state.doc.toString() ?? '', event)\n }\n}\n\n// ---------------------------------------------------------------------------\n// Public API\n\ndefineExpose({\n /**\n * Focus the codemirror element\n *\n * @param cursorAtEnd boolean place the cursor at the end of the input\n */\n focus: (position?: 'start' | 'end' | number) => {\n if (!codeMirror.value) {\n return\n }\n codeMirror.value.focus()\n\n if (!isDefined(position)) {\n return\n }\n\n const anchor = (() => {\n if (position === 'start') {\n return 0\n }\n if (position === 'end') {\n return codeMirror.value.state.doc.length\n }\n return position\n })()\n\n // Move the cursor to the specified position\n codeMirror.value.dispatch({\n selection: { anchor },\n scrollIntoView: true,\n })\n },\n isFocused,\n handleChange,\n handleSubmit,\n handleBlur,\n booleanOptions,\n codeMirror,\n codeMirrorRef,\n modelValue,\n setCodeMirrorContent,\n cursorPosition: () => codeMirror.value?.state.selection.main.head,\n serializeValue,\n})\n</script>\n\n<template>\n <!-- Disabled mode: read-only text display -->\n <div\n v-if=\"disabled\"\n class=\"text-c-2 flex cursor-default items-center justify-center\"\n :class=\"{\n 'font-code pr-2 pl-1 text-base': layout === 'modal',\n 'px-2': layout !== 'modal',\n 'line-through': linethrough,\n }\"\n data-testid=\"code-input-disabled\">\n <span class=\"whitespace-nowrap\">{{ modelValue }}</span>\n </div>\n\n <!-- Enum mode: select dropdown with predefined values -->\n <DataTableInputSelect\n v-else-if=\"enumProp?.length\"\n :default=\"defaultProp\"\n :modelValue=\"modelValue\"\n :type=\"defaultType\"\n :value=\"enumProp\"\n @update:modelValue=\"handleSelectChange\" />\n\n <!-- Boolean mode: select dropdown with true/false (and optionally null) -->\n <DataTableInputSelect\n v-else-if=\"isBooleanMode\"\n :default=\"defaultProp\"\n :modelValue=\"modelValue\"\n :value=\"booleanOptions\"\n @update:modelValue=\"handleSelectChange\" />\n\n <!-- Examples mode: select dropdown with example values -->\n <DataTableInputSelect\n v-else-if=\"examples?.length\"\n :default=\"defaultProp\"\n :modelValue=\"modelValue\"\n :value=\"examples\"\n @update:modelValue=\"handleSelectChange\" />\n\n <!-- Editor mode: CodeMirror with environment variable support -->\n <div\n v-else\n :id=\"componentId\"\n v-bind=\"$attrs\"\n ref=\"codeMirrorRef\"\n class=\"group/input group-[.alert]:outline-orange group-[.error]:outline-red font-code peer relative w-full overflow-hidden text-xs leading-[1.44] whitespace-nowrap -outline-offset-1 has-[:focus-visible]:rounded-[4px] has-[:focus-visible]:outline\"\n :class=\"{\n 'line-wrapping has-[:focus-visible]:bg-b-1 has-[:focus-visible]:absolute has-[:focus-visible]:z-1':\n lineWrapping,\n 'flow-code-input--error': error,\n 'line-through': linethrough,\n }\"\n @keydown.down.stop=\"handleKeyDown('down', $event)\"\n @keydown.enter=\"handleKeyDown('enter', $event)\"\n @keydown.escape=\"handleKeyDown('escape', $event)\"\n @keydown.up.stop=\"handleKeyDown('up', $event)\">\n <!-- Wrap toggle button for multi-line editor (e.g. Request Body) -->\n <div\n v-if=\"lineNumbers\"\n class=\"absolute top-2 right-2 z-10 flex items-center opacity-0 transition-opacity duration-150 group-hover/input:opacity-100 group-has-focus-visible/input:opacity-100\">\n <ScalarIconButton\n class=\"bg-b-2 text-c-2 hover:text-c-1\"\n :class=\"{ '!bg-b-3 !text-c-1': isLineWrapping }\"\n :icon=\"ScalarIconArrowElbowDownLeft\"\n :aria-pressed=\"isLineWrapping\"\n :aria-label=\"isLineWrapping ? 'Disable line wrap' : 'Wrap lines'\"\n :label=\"isLineWrapping ? 'Disable line wrap' : 'Wrap lines'\"\n size=\"sm\"\n tooltip\n variant=\"ghost\"\n @click.stop=\"toggleLineWrapping\" />\n </div>\n\n <!-- Tab exit hint (shown when focused) -->\n <div\n v-if=\"!disableTabIndent\"\n class=\"z-context text-c-2 absolute right-1.5 bottom-1 hidden font-sans group-has-[:focus-visible]/input:block\"\n role=\"alert\">\n Press\n <kbd class=\"-mx-0.25 rounded border px-0.5 font-mono\">Esc</kbd> then\n <kbd class=\"-mx-0.25 rounded border px-0.5 font-mono\">Tab</kbd> to exit\n </div>\n </div>\n\n <!-- Warning slot (positioned absolutely) -->\n <div\n v-if=\"$slots.warning\"\n class=\"centered-y text-orange absolute right-7 text-xs\">\n <slot name=\"warning\" />\n </div>\n\n <!-- Icon slot (positioned absolutely) -->\n <div\n v-if=\"$slots.icon\"\n class=\"centered-y absolute right-0 flex h-full items-center p-1.5 group-has-[.cm-focused]:z-1\">\n <slot name=\"icon\" />\n </div>\n\n <!-- Required indicator -->\n <div\n v-if=\"required\"\n class=\"required centered-y text-xxs text-c-3 group-[.error]:text-red bg-b-1 pointer-events-none absolute right-0 mr-0.5 pt-px pr-2 opacity-100 shadow-[-8px_0_4px_var(--scalar-background-1)] transition-opacity duration-150 group-[.alert]:bg-transparent group-[.alert]:shadow-none group-[.error]:bg-transparent group-[.error]:shadow-none peer-has-[.cm-focused]:opacity-0\">\n Required\n </div>\n\n <!-- Environment variable autocomplete dropdown -->\n <EnvironmentVariableDropdown\n v-if=\"displayVariablesDropdown\"\n ref=\"dropdownRef\"\n :contextFunctionItems=\"contextFunctionDropdownItems\"\n :dropdownPosition=\"dropdownPosition\"\n :environment=\"environment\"\n :query=\"dropdownQuery\"\n @close=\"showDropdown = false\"\n @redirect=\"emit('navigate', { page: 'document', path: 'environment' })\"\n @select=\"handleDropdownSelect\" />\n</template>\n<style scoped>\n/*\n Deep styling for customizing Codemirror\n */\n:deep(.cm-editor) {\n height: 100%;\n outline: none;\n padding: 0;\n background: transparent;\n}\n:deep(.cm-placeholder) {\n color: var(--scalar-color-3);\n}\n:deep(.cm-content) {\n font-family: var(--scalar-font-code);\n font-size: var(--scalar-small);\n max-height: 20px;\n padding: 8px 0;\n}\n/* Tooltip helper */\n:deep(.cm-tooltip) {\n background: transparent !important;\n filter: brightness(var(--scalar-lifted-brightness));\n border-radius: var(--scalar-radius);\n box-shadow: var(--scalar-shadow-2);\n border: none !important;\n outline: none !important;\n overflow: hidden !important;\n}\n:deep(.cm-tooltip-autocomplete ul li) {\n padding: 3px 6px !important;\n}\n:deep(.cm-completionIcon-type:after) {\n color: var(--scalar-color-3) !important;\n}\n:deep(.cm-tooltip-autocomplete ul li[aria-selected]) {\n background: var(--scalar-background-2) !important;\n color: var(--scalar-color-1) !important;\n}\n:deep(.cm-tooltip-autocomplete ul) {\n padding: 6px !important;\n position: relative;\n}\n:deep(.cm-tooltip-autocomplete ul li:hover) {\n border-radius: 3px;\n color: var(--scalar-color-1) !important;\n background: var(--scalar-background-3) !important;\n}\n/* Disable active line highlighting */\n:deep(.cm-activeLine),\n:deep(.cm-activeLineGutter) {\n background-color: transparent;\n}\n/* Color selection matching */\n:deep(.cm-selectionMatch),\n:deep(.cm-matchingBracket) {\n border-radius: var(--scalar-radius);\n background: var(--scalar-background-4) !important;\n}\n/* Color Picker Swatches */\n:deep(.cm-css-color-picker-wrapper) {\n display: inline-flex;\n outline: 1px solid var(--scalar-background-3);\n border-radius: 3px;\n overflow: hidden;\n}\n/* Number gutter */\n:deep(.cm-gutters) {\n background-color: transparent;\n border-right: none;\n color: var(--scalar-color-3);\n font-size: var(--scalar-small);\n line-height: 22px;\n border-radius: 0 0 0 3px;\n}\n:deep(.cm-gutters:before) {\n content: '';\n position: absolute;\n top: 2px;\n left: 2px;\n width: calc(100% - 2px);\n height: calc(100% - 4px);\n border-radius: var(--scalar-radius) 0 0 var(--scalar-radius);\n background-color: var(--scalar-background-1);\n}\n:deep(.cm-gutterElement) {\n font-family: var(--scalar-font-code) !important;\n padding-left: 0px !important;\n padding-right: 6px !important;\n display: flex;\n align-items: center;\n justify-content: flex-end;\n position: relative;\n}\n:deep(.cm-lineNumbers .cm-gutterElement) {\n min-width: fit-content;\n}\n:deep(.cm-gutter + .cm-gutter :not(.cm-foldGutter) .cm-gutterElement) {\n padding-left: 0 !important;\n}\n:deep(.cm-scroller) {\n overflow: auto;\n}\n:deep(.cm-lineWrapping .cm-line) {\n word-break: break-all;\n}\n:deep(.cm-lineWrapping .cm-content) {\n white-space: pre-wrap;\n max-height: none;\n}\n.line-wrapping:focus-within :deep(.cm-content) {\n display: inline-table;\n min-height: fit-content;\n padding: 3px 6px;\n white-space: break-spaces;\n word-break: break-all;\n}\n</style>\n<style>\n.cm-pill {\n color: var(--scalar-color-1) !important;\n padding: 0px 9px;\n display: inline-block;\n border-radius: var(--scalar-radius-full);\n font-size: var(--scalar-small);\n}\n.light-mode .cm-pill {\n background: var(--scalar-background-3) !important;\n}\n.dark-mode .cm-pill {\n background: color-mix(in srgb, var(--tw-bg-base), transparent 90%) !important;\n}\n.cm-pill--context-fn {\n border: 1px dashed color-mix(in srgb, var(--scalar-color-3), transparent 35%);\n padding: 0px 8px;\n}\n.light-mode .cm-pill--context-fn {\n background: color-mix(\n in srgb,\n var(--scalar-background-3),\n transparent 40%\n ) !important;\n}\n.dark-mode .cm-pill--context-fn {\n background: color-mix(\n in srgb,\n var(--scalar-background-3),\n transparent 55%\n ) !important;\n}\n.cm-pill:first-of-type {\n margin-left: 0;\n}\n.cm-editor .cm-widgetBuffer {\n display: none;\n}\n.cm-foldPlaceholder:hover {\n color: var(--scalar-color-1);\n}\n.cm-foldGutter .cm-gutterElement {\n font-size: var(--scalar-heading-4);\n padding: 2px !important;\n}\n.cm-foldGutter .cm-gutterElement:first-of-type {\n display: none;\n}\n.cm-foldGutter .cm-gutterElement .cm-foldMarker {\n padding: 2px;\n padding-top: 2px;\n}\n.cm-foldGutter .cm-gutterElement:hover .cm-foldMarker {\n background: var(--scalar-background-2);\n border-radius: var(--scalar-radius);\n color: var(--scalar-color-1);\n}\n</style>\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"CodeInput.vue.js","names":[],"sources":["../../../../src/v2/components/code-input/CodeInput.vue"],"sourcesContent":["<script lang=\"ts\">\nexport type CodeInputModelValue =\n | string\n | number\n | boolean\n | Array<string | number | boolean>\n | Record<string, unknown>\n\n/**\n * CodeInput\n *\n * A versatile input component that adapts its rendering based on props:\n * - Disabled mode: Read-only text display\n * - Select mode: Dropdown for enums, booleans, or examples\n * - Editor mode: CodeMirror with environment variable support\n *\n * Type `{{` to trigger autocomplete for environment variables and runtime context functions\n * (for example `{{$guid}}`) when an environment is provided.\n * It takes in any data but always will emit a string value,\n * this string should then be parsed in accordance to the schema or content type.\n *\n * @example\n * ```vue\n * <!-- Basic input with environment variables -->\n * <CodeInput v-model=\"value\" :environment=\"env\" />\n *\n * <!-- Boolean select -->\n * <CodeInput v-model=\"flag\" type=\"boolean\" />\n *\n * <!-- JSON editor with linting -->\n * <CodeInput v-model=\"data\" language=\"json\" :lint=\"true\" />\n * ```\n */\nexport default {\n inheritAttrs: false,\n}\n</script>\n\n<script setup lang=\"ts\">\nimport { ScalarIconButton } from '@scalar/components/icon-button'\nimport { isDefined } from '@scalar/helpers/array/is-defined'\nimport { ScalarIconArrowElbowDownLeft } from '@scalar/icons'\nimport {\n colorPicker as colorPickerExtension,\n EditorView,\n useCodeMirror,\n useDropdown,\n type CodeMirrorLanguage,\n type Extension,\n} from '@scalar/use-codemirror'\nimport {\n CONTEXT_FUNCTION_NAMES,\n getContextFunctionComment,\n isContextFunctionName,\n} from '@scalar/workspace-store/request-example'\nimport type { XScalarEnvironment } from '@scalar/workspace-store/schemas/extensions/document/x-scalar-environments'\nimport { nanoid } from 'nanoid'\nimport { computed, ref, toRef, useAttrs, watch, type Ref } from 'vue'\n\nimport DataTableInputSelect from '@/v2/components/data-table/DataTableInputSelect.vue'\nimport EnvironmentVariableDropdown from '@/v2/features/environments/components/EnvironmentVariablesDropdown.vue'\nimport { useLocalization } from '@/v2/features/localization'\nimport type { ClientLayout } from '@/v2/types/layout'\n\nimport { backspaceCommand, pillPlugin } from './code-variable-widget'\n\nconst {\n modelValue,\n environment,\n type,\n disabled = false,\n error = false,\n layout = 'desktop',\n enum: enumProp,\n examples,\n default: defaultProp,\n nullable = false,\n placeholder,\n required,\n colorPicker = false,\n lineNumbers = false,\n lint = false,\n lineWrapping = false,\n language,\n extensions = [],\n disableTabIndent = false,\n disableEnter = false,\n disableCloseBrackets = false,\n emitOnBlur = true,\n alwaysEmitChange = false,\n withVariables = true,\n withFakeData = false,\n handleFieldChange,\n handleFieldSubmit,\n} = defineProps<Props>()\n\nconst emit = defineEmits<{\n 'update:modelValue': [value: string]\n 'submit': [value: string, event: KeyboardEvent | FocusEvent]\n 'navigate': [route: { page: 'document'; path: 'environment' }]\n 'blur': [value: string, event: FocusEvent]\n}>()\n\nconst { translate } = useLocalization()\n\ntype Props = {\n modelValue: CodeInputModelValue\n /** Environment for variable substitution. Pass undefined to disable environment variables */\n environment: XScalarEnvironment | undefined\n /** Type of the input value, affects rendering mode for booleans */\n type?: string | string[]\n /** Render as disabled text display */\n disabled?: boolean\n /** Show error styling */\n error?: boolean\n /** Layout context affects styling and behavior */\n layout?: ClientLayout\n /** Predefined enum values, triggers select mode */\n enum?: string[]\n /** Example values, triggers select mode */\n examples?: string[]\n /** Default value to show in select mode */\n default?: Props['modelValue']\n /** Allow null in boolean select options */\n nullable?: boolean\n /** Placeholder text for empty input */\n placeholder?: string\n /** Show required indicator */\n required?: boolean\n /** Enable color picker extension */\n colorPicker?: boolean\n /** Show line numbers in editor */\n lineNumbers?: boolean\n /** Enable linting */\n lint?: boolean\n /** Enable line wrapping */\n lineWrapping?: boolean\n /** CodeMirror language mode */\n language?: CodeMirrorLanguage\n /** Additional CodeMirror extensions */\n extensions?: Extension[]\n /** Disable tab key for indentation */\n disableTabIndent?: boolean\n /** Disable enter key */\n disableEnter?: boolean\n /** Disable automatic bracket closing */\n disableCloseBrackets?: boolean\n /** Emit submit event on blur */\n emitOnBlur?: boolean\n /** Enable environment variable pills */\n withVariables?: boolean\n /** Enable fake data suggestions like $guid, $timestamp, etc. Should only be enabled for parameters and request bodies */\n withFakeData?: boolean\n /** Emit change event even if the value is the same */\n alwaysEmitChange?: boolean\n /** Custom change handler, prevents default emit */\n handleFieldChange?: (value: string) => void\n /** Custom submit handler, prevents default emit */\n handleFieldSubmit?: (value: string) => void\n /** Put a linethrough on the input text */\n linethrough?: boolean\n}\n\n// ---------------------------------------------------------------------------\n// Component identity and focus state\n\nconst attrs = useAttrs()\nconst componentId =\n (typeof attrs.id === 'string' && attrs.id) || `id-${nanoid()}`\nconst isFocused = ref(false)\n\n// ---------------------------------------------------------------------------\n// Rendering mode detection\n\n/**\n * Determines if we should render a select dropdown for boolean types.\n */\nconst isBooleanMode = computed((): boolean => {\n if (enumProp?.length) {\n return false\n }\n return type === 'boolean' || (Array.isArray(type) && type.includes('boolean'))\n})\n\n/**\n * Options for boolean select mode.\n */\nconst booleanOptions = computed((): string[] =>\n nullable ? ['true', 'false', 'null'] : ['true', 'false'],\n)\n\n/**\n * Default type when dealing with type arrays.\n * Finds the first non-null type.\n */\nconst defaultType = computed((): string | undefined => {\n if (Array.isArray(type)) {\n return type.find((t) => t !== 'null') ?? 'string'\n }\n return type\n})\n\n// ---------------------------------------------------------------------------\n// Event handlers\n\n/**\n * Handles value changes during typing.\n */\nconst handleChange = (value: string): void => {\n if (!alwaysEmitChange && value === serializeValue(modelValue)) {\n return\n }\n\n // Use custom handler or emit update\n if (handleFieldChange) {\n handleFieldChange(value)\n } else {\n emit('update:modelValue', value)\n }\n}\n\n/**\n * Handles form submission (enter key or blur with emitOnBlur).\n */\nconst handleSubmit = (\n value: string,\n event: KeyboardEvent | FocusEvent,\n): void => {\n if (handleFieldSubmit) {\n handleFieldSubmit(value)\n } else {\n emit('submit', value, event)\n }\n}\n\n/**\n * Handles input blur event.\n */\nconst handleBlur = (value: string, event: FocusEvent): void => {\n isFocused.value = false\n\n if (emitOnBlur && modelValue) {\n handleSubmit(value, event)\n }\n\n emit('blur', value, event)\n}\n\n/**\n * Handles model value updates from select components.\n */\nconst handleSelectChange = (value: string): void =>\n emit('update:modelValue', value)\n\n// ---------------------------------------------------------------------------\n// CodeMirror setup\n\n/**\n * Build extensions array.\n * Note: Extensions are not reactive after initialization.\n */\nconst buildExtensions = (): Extension[] => {\n const extensionsList: Extension[] = [...extensions]\n\n if (colorPicker) {\n extensionsList.push(colorPickerExtension)\n }\n\n return extensionsList\n}\n\n/**\n * Reactive pill plugin for environment variable visualization.\n */\nconst contextFunctionDropdownItems = computed(() =>\n withFakeData\n ? CONTEXT_FUNCTION_NAMES.map((key) => ({\n key,\n description: getContextFunctionComment(key),\n }))\n : [],\n)\n\nconst pillPluginExtension = computed(() =>\n pillPlugin({\n environment,\n isContextFunctionName,\n isReadOnly: layout === 'modal',\n translate,\n }),\n)\n\nconst isLineWrapping = ref(lineWrapping)\n\nwatch(\n () => lineWrapping,\n (val) => {\n isLineWrapping.value = val\n },\n)\n\nconst toggleLineWrapping = (): void => {\n isLineWrapping.value = !isLineWrapping.value\n}\n\nconst lineWrappingExtension = computed(() =>\n isLineWrapping.value ? [EditorView.lineWrapping] : [],\n)\n\n/**\n * Combined extensions for CodeMirror.\n */\nconst codeMirrorExtensions = computed((): Extension[] => [\n ...buildExtensions(),\n ...lineWrappingExtension.value,\n pillPluginExtension.value,\n backspaceCommand,\n])\n\nconst codeMirrorRef: Ref<HTMLDivElement | null> = ref(null)\n\n/** Converts the model value to a string for CodeMirror */\nconst serializeValue = (value: CodeInputModelValue): string => {\n if (typeof value === 'string') {\n return value\n }\n return JSON.stringify(value)\n}\n\nconst { codeMirror, setCodeMirrorContent } = useCodeMirror({\n content: toRef(() => serializeValue(modelValue)),\n onChange: (value) => {\n handleChange(value)\n updateDropdownVisibility()\n },\n onFocus: () => {\n isFocused.value = true\n },\n onBlur: handleBlur,\n codeMirrorRef,\n disableTabIndent: toRef(() => disableTabIndent),\n disableEnter: toRef(() => disableEnter),\n disableCloseBrackets: toRef(() => disableCloseBrackets),\n lineNumbers: toRef(() => lineNumbers),\n language: toRef(() => language),\n lint: toRef(() => lint),\n extensions: codeMirrorExtensions,\n placeholder: toRef(() => placeholder),\n})\n\n/**\n * Handle autofocus attribute.\n */\nwatch(codeMirror, () => {\n if (codeMirror.value && Object.hasOwn(attrs, 'autofocus')) {\n codeMirror.value.focus()\n }\n})\n\n// ---------------------------------------------------------------------------\n// Environment variable dropdown\n\nconst showDropdown = ref(false)\nconst dropdownQuery = ref('')\nconst dropdownPosition = ref({ left: 0, top: 0 })\nconst dropdownRef = ref<InstanceType<\n typeof EnvironmentVariableDropdown\n> | null>(null)\n\nconst { handleDropdownSelect, updateDropdownVisibility } = useDropdown({\n codeMirror,\n query: dropdownQuery,\n showDropdown,\n dropdownPosition,\n})\n\n/**\n * Determines if the environment variable dropdown should be visible.\n * Shows when environment is defined (for env vars) or withFakeData is true (for context functions)\n */\nconst displayVariablesDropdown = computed((): boolean => {\n return (\n showDropdown.value &&\n withVariables &&\n layout !== 'modal' &&\n (Boolean(environment) || withFakeData)\n )\n})\n\n// ---------------------------------------------------------------------------\n// Keyboard event handling\n\n/**\n * Handles keyboard navigation for dropdown and form submission.\n */\nconst handleKeyDown = (key: string, event: KeyboardEvent): void => {\n if (showDropdown.value) {\n if (key === 'down' || key === 'up') {\n event.preventDefault()\n dropdownRef.value?.handleArrowKey(key)\n } else if (key === 'enter') {\n event.preventDefault()\n dropdownRef.value?.handleSelect()\n }\n return\n }\n\n if (key === 'escape' && !disableTabIndent) {\n event.stopPropagation()\n }\n\n if (key === 'enter' && event.target instanceof HTMLDivElement) {\n handleSubmit(codeMirror.value?.state.doc.toString() ?? '', event)\n }\n}\n\n// ---------------------------------------------------------------------------\n// Public API\n\ndefineExpose({\n /**\n * Focus the codemirror element\n *\n * @param cursorAtEnd boolean place the cursor at the end of the input\n */\n focus: (position?: 'start' | 'end' | number) => {\n if (!codeMirror.value) {\n return\n }\n codeMirror.value.focus()\n\n if (!isDefined(position)) {\n return\n }\n\n const anchor = (() => {\n if (position === 'start') {\n return 0\n }\n if (position === 'end') {\n return codeMirror.value.state.doc.length\n }\n return position\n })()\n\n // Move the cursor to the specified position\n codeMirror.value.dispatch({\n selection: { anchor },\n scrollIntoView: true,\n })\n },\n isFocused,\n handleChange,\n handleSubmit,\n handleBlur,\n booleanOptions,\n codeMirror,\n codeMirrorRef,\n modelValue,\n setCodeMirrorContent,\n cursorPosition: () => codeMirror.value?.state.selection.main.head,\n serializeValue,\n})\n</script>\n\n<template>\n <!-- Disabled mode: read-only text display -->\n <div\n v-if=\"disabled\"\n class=\"text-c-2 flex cursor-default items-center justify-center\"\n :class=\"{\n 'font-code pr-2 pl-1 text-base': layout === 'modal',\n 'px-2': layout !== 'modal',\n 'line-through': linethrough,\n }\"\n data-testid=\"code-input-disabled\">\n <span class=\"whitespace-nowrap\">{{ modelValue }}</span>\n </div>\n\n <!-- Enum mode: select dropdown with predefined values -->\n <DataTableInputSelect\n v-else-if=\"enumProp?.length\"\n :default=\"defaultProp\"\n :modelValue=\"modelValue\"\n :type=\"defaultType\"\n :value=\"enumProp\"\n @update:modelValue=\"handleSelectChange\" />\n\n <!-- Boolean mode: select dropdown with true/false (and optionally null) -->\n <DataTableInputSelect\n v-else-if=\"isBooleanMode\"\n :default=\"defaultProp\"\n :modelValue=\"modelValue\"\n :value=\"booleanOptions\"\n @update:modelValue=\"handleSelectChange\" />\n\n <!-- Examples mode: select dropdown with example values -->\n <DataTableInputSelect\n v-else-if=\"examples?.length\"\n :default=\"defaultProp\"\n :modelValue=\"modelValue\"\n :value=\"examples\"\n @update:modelValue=\"handleSelectChange\" />\n\n <!-- Editor mode: CodeMirror with environment variable support -->\n <div\n v-else\n :id=\"componentId\"\n v-bind=\"$attrs\"\n ref=\"codeMirrorRef\"\n class=\"group/input group-[.alert]:outline-orange group-[.error]:outline-red font-code peer relative w-full overflow-hidden text-xs leading-[1.44] whitespace-nowrap -outline-offset-1 has-[:focus-visible]:rounded-[4px] has-[:focus-visible]:outline\"\n :class=\"{\n 'line-wrapping has-[:focus-visible]:bg-b-1 has-[:focus-visible]:absolute has-[:focus-visible]:z-1':\n lineWrapping,\n 'flow-code-input--error': error,\n 'line-through': linethrough,\n }\"\n @keydown.down.stop=\"handleKeyDown('down', $event)\"\n @keydown.enter=\"handleKeyDown('enter', $event)\"\n @keydown.escape=\"handleKeyDown('escape', $event)\"\n @keydown.up.stop=\"handleKeyDown('up', $event)\">\n <!-- Wrap toggle button for multi-line editor (e.g. Request Body) -->\n <div\n v-if=\"lineNumbers\"\n class=\"absolute top-2 right-2 z-10 flex items-center opacity-0 transition-opacity duration-150 group-hover/input:opacity-100 group-has-focus-visible/input:opacity-100\">\n <ScalarIconButton\n class=\"bg-b-2 text-c-2 hover:text-c-1\"\n :class=\"{ '!bg-b-3 !text-c-1': isLineWrapping }\"\n :icon=\"ScalarIconArrowElbowDownLeft\"\n :aria-pressed=\"isLineWrapping\"\n :aria-label=\"isLineWrapping ? 'Disable line wrap' : 'Wrap lines'\"\n :label=\"isLineWrapping ? 'Disable line wrap' : 'Wrap lines'\"\n size=\"sm\"\n tooltip\n variant=\"ghost\"\n @click.stop=\"toggleLineWrapping\" />\n </div>\n\n <!-- Tab exit hint (shown when focused) -->\n <div\n v-if=\"!disableTabIndent\"\n class=\"z-context text-c-2 absolute right-1.5 bottom-1 hidden font-sans group-has-[:focus-visible]/input:block\"\n role=\"alert\">\n {{\n translate('apiClient.codeInput.exitHint', { escape: 'Esc', tab: 'Tab' })\n }}\n </div>\n </div>\n\n <!-- Warning slot (positioned absolutely) -->\n <div\n v-if=\"$slots.warning\"\n class=\"centered-y text-orange absolute right-7 text-xs\">\n <slot name=\"warning\" />\n </div>\n\n <!-- Icon slot (positioned absolutely) -->\n <div\n v-if=\"$slots.icon\"\n class=\"centered-y absolute right-0 flex h-full items-center p-1.5 group-has-[.cm-focused]:z-1\">\n <slot name=\"icon\" />\n </div>\n\n <!-- Required indicator -->\n <div\n v-if=\"required\"\n class=\"required centered-y text-xxs text-c-3 group-[.error]:text-red bg-b-1 pointer-events-none absolute right-0 mr-0.5 pt-px pr-2 opacity-100 shadow-[-8px_0_4px_var(--scalar-background-1)] transition-opacity duration-150 group-[.alert]:bg-transparent group-[.alert]:shadow-none group-[.error]:bg-transparent group-[.error]:shadow-none peer-has-[.cm-focused]:opacity-0\">\n {{ translate('apiClient.codeInput.required') }}\n </div>\n\n <!-- Environment variable autocomplete dropdown -->\n <EnvironmentVariableDropdown\n v-if=\"displayVariablesDropdown\"\n ref=\"dropdownRef\"\n :contextFunctionItems=\"contextFunctionDropdownItems\"\n :dropdownPosition=\"dropdownPosition\"\n :environment=\"environment\"\n :query=\"dropdownQuery\"\n @close=\"showDropdown = false\"\n @redirect=\"emit('navigate', { page: 'document', path: 'environment' })\"\n @select=\"handleDropdownSelect\" />\n</template>\n<style scoped>\n/*\n Deep styling for customizing Codemirror\n */\n:deep(.cm-editor) {\n height: 100%;\n outline: none;\n padding: 0;\n background: transparent;\n}\n:deep(.cm-placeholder) {\n color: var(--scalar-color-3);\n}\n:deep(.cm-content) {\n font-family: var(--scalar-font-code);\n font-size: var(--scalar-small);\n max-height: 20px;\n padding: 8px 0;\n}\n/* Tooltip helper */\n:deep(.cm-tooltip) {\n background: transparent !important;\n filter: brightness(var(--scalar-lifted-brightness));\n border-radius: var(--scalar-radius);\n box-shadow: var(--scalar-shadow-2);\n border: none !important;\n outline: none !important;\n overflow: hidden !important;\n}\n:deep(.cm-tooltip-autocomplete ul li) {\n padding: 3px 6px !important;\n}\n:deep(.cm-completionIcon-type:after) {\n color: var(--scalar-color-3) !important;\n}\n:deep(.cm-tooltip-autocomplete ul li[aria-selected]) {\n background: var(--scalar-background-2) !important;\n color: var(--scalar-color-1) !important;\n}\n:deep(.cm-tooltip-autocomplete ul) {\n padding: 6px !important;\n position: relative;\n}\n:deep(.cm-tooltip-autocomplete ul li:hover) {\n border-radius: 3px;\n color: var(--scalar-color-1) !important;\n background: var(--scalar-background-3) !important;\n}\n/* Disable active line highlighting */\n:deep(.cm-activeLine),\n:deep(.cm-activeLineGutter) {\n background-color: transparent;\n}\n/* Color selection matching */\n:deep(.cm-selectionMatch),\n:deep(.cm-matchingBracket) {\n border-radius: var(--scalar-radius);\n background: var(--scalar-background-4) !important;\n}\n/* Color Picker Swatches */\n:deep(.cm-css-color-picker-wrapper) {\n display: inline-flex;\n outline: 1px solid var(--scalar-background-3);\n border-radius: 3px;\n overflow: hidden;\n}\n/* Number gutter */\n:deep(.cm-gutters) {\n background-color: transparent;\n border-right: none;\n color: var(--scalar-color-3);\n font-size: var(--scalar-small);\n line-height: 22px;\n border-radius: 0 0 0 3px;\n}\n:deep(.cm-gutters:before) {\n content: '';\n position: absolute;\n top: 2px;\n left: 2px;\n width: calc(100% - 2px);\n height: calc(100% - 4px);\n border-radius: var(--scalar-radius) 0 0 var(--scalar-radius);\n background-color: var(--scalar-background-1);\n}\n:deep(.cm-gutterElement) {\n font-family: var(--scalar-font-code) !important;\n padding-left: 0px !important;\n padding-right: 6px !important;\n display: flex;\n align-items: center;\n justify-content: flex-end;\n position: relative;\n}\n:deep(.cm-lineNumbers .cm-gutterElement) {\n min-width: fit-content;\n}\n:deep(.cm-gutter + .cm-gutter :not(.cm-foldGutter) .cm-gutterElement) {\n padding-left: 0 !important;\n}\n:deep(.cm-scroller) {\n overflow: auto;\n}\n:deep(.cm-lineWrapping .cm-line) {\n word-break: break-all;\n}\n:deep(.cm-lineWrapping .cm-content) {\n white-space: pre-wrap;\n max-height: none;\n}\n.line-wrapping:focus-within :deep(.cm-content) {\n display: inline-table;\n min-height: fit-content;\n padding: 3px 6px;\n white-space: break-spaces;\n word-break: break-all;\n}\n</style>\n<style>\n.cm-pill {\n color: var(--scalar-color-1) !important;\n padding: 0px 9px;\n display: inline-block;\n border-radius: var(--scalar-radius-full);\n font-size: var(--scalar-small);\n}\n.light-mode .cm-pill {\n background: var(--scalar-background-3) !important;\n}\n.dark-mode .cm-pill {\n background: color-mix(in srgb, var(--tw-bg-base), transparent 90%) !important;\n}\n.cm-pill--context-fn {\n border: 1px dashed color-mix(in srgb, var(--scalar-color-3), transparent 35%);\n padding: 0px 8px;\n}\n.light-mode .cm-pill--context-fn {\n background: color-mix(\n in srgb,\n var(--scalar-background-3),\n transparent 40%\n ) !important;\n}\n.dark-mode .cm-pill--context-fn {\n background: color-mix(\n in srgb,\n var(--scalar-background-3),\n transparent 55%\n ) !important;\n}\n.cm-pill:first-of-type {\n margin-left: 0;\n}\n.cm-editor .cm-widgetBuffer {\n display: none;\n}\n.cm-foldPlaceholder:hover {\n color: var(--scalar-color-1);\n}\n.cm-foldGutter .cm-gutterElement {\n font-size: var(--scalar-heading-4);\n padding: 2px !important;\n}\n.cm-foldGutter .cm-gutterElement:first-of-type {\n display: none;\n}\n.cm-foldGutter .cm-gutterElement .cm-foldMarker {\n padding: 2px;\n padding-top: 2px;\n}\n.cm-foldGutter .cm-gutterElement:hover .cm-foldMarker {\n background: var(--scalar-background-2);\n border-radius: var(--scalar-radius);\n color: var(--scalar-color-1);\n}\n</style>\n"],"mappings":""}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { useLocalization } from "../../features/localization/index.js";
|
|
1
2
|
import DataTableInputSelect_default from "../data-table/DataTableInputSelect.vue.js";
|
|
2
3
|
import EnvironmentVariablesDropdown_default from "../../features/environments/components/EnvironmentVariablesDropdown.vue.js";
|
|
3
4
|
import { backspaceCommand, pillPlugin } from "./code-variable-widget.js";
|
|
4
|
-
import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode,
|
|
5
|
+
import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, mergeProps, normalizeClass, openBlock, ref, renderSlot, toDisplayString, toRef, unref, useAttrs, watch, withKeys, withModifiers } from "vue";
|
|
5
6
|
import { ScalarIconArrowElbowDownLeft } from "@scalar/icons";
|
|
6
7
|
import { ScalarIconButton } from "@scalar/components/icon-button";
|
|
7
8
|
import { isDefined } from "@scalar/helpers/array/is-defined";
|
|
@@ -127,6 +128,7 @@ var CodeInput_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
|
|
|
127
128
|
],
|
|
128
129
|
setup(__props, { expose: __expose, emit: __emit }) {
|
|
129
130
|
const emit = __emit;
|
|
131
|
+
const { translate } = useLocalization();
|
|
130
132
|
const attrs = useAttrs();
|
|
131
133
|
const componentId = typeof attrs.id === "string" && attrs.id || `id-${nanoid()}`;
|
|
132
134
|
const isFocused = ref(false);
|
|
@@ -199,7 +201,8 @@ var CodeInput_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
|
|
|
199
201
|
const pillPluginExtension = computed(() => pillPlugin({
|
|
200
202
|
environment: __props.environment,
|
|
201
203
|
isContextFunctionName,
|
|
202
|
-
isReadOnly: __props.layout === "modal"
|
|
204
|
+
isReadOnly: __props.layout === "modal",
|
|
205
|
+
translate
|
|
203
206
|
}));
|
|
204
207
|
const isLineWrapping = ref(__props.lineWrapping);
|
|
205
208
|
watch(() => __props.lineWrapping, (val) => {
|
|
@@ -394,16 +397,13 @@ var CodeInput_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
|
|
|
394
397
|
"aria-pressed",
|
|
395
398
|
"aria-label",
|
|
396
399
|
"label"
|
|
397
|
-
])])) : createCommentVNode("", true), !__props.disableTabIndent ? (openBlock(), createElementBlock("div", _hoisted_4,
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
createElementVNode("kbd", { class: "-mx-0.25 rounded border px-0.5 font-mono" }, "Tab", -1),
|
|
402
|
-
createTextVNode(" to exit ", -1)
|
|
403
|
-
])])) : createCommentVNode("", true)], 16, _hoisted_2)),
|
|
400
|
+
])])) : createCommentVNode("", true), !__props.disableTabIndent ? (openBlock(), createElementBlock("div", _hoisted_4, toDisplayString(unref(translate)("apiClient.codeInput.exitHint", {
|
|
401
|
+
escape: "Esc",
|
|
402
|
+
tab: "Tab"
|
|
403
|
+
})), 1)) : createCommentVNode("", true)], 16, _hoisted_2)),
|
|
404
404
|
_ctx.$slots.warning ? (openBlock(), createElementBlock("div", _hoisted_5, [renderSlot(_ctx.$slots, "warning", {}, void 0, true)])) : createCommentVNode("", true),
|
|
405
405
|
_ctx.$slots.icon ? (openBlock(), createElementBlock("div", _hoisted_6, [renderSlot(_ctx.$slots, "icon", {}, void 0, true)])) : createCommentVNode("", true),
|
|
406
|
-
__props.required ? (openBlock(), createElementBlock("div", _hoisted_7, "
|
|
406
|
+
__props.required ? (openBlock(), createElementBlock("div", _hoisted_7, toDisplayString(unref(translate)("apiClient.codeInput.required")), 1)) : createCommentVNode("", true),
|
|
407
407
|
displayVariablesDropdown.value ? (openBlock(), createBlock(EnvironmentVariablesDropdown_default, {
|
|
408
408
|
key: 8,
|
|
409
409
|
ref_key: "dropdownRef",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeInput.vue.script.js","names":["$attrs","$slots"],"sources":["../../../../src/v2/components/code-input/CodeInput.vue"],"sourcesContent":["<script lang=\"ts\">\nexport type CodeInputModelValue =\n | string\n | number\n | boolean\n | Array<string | number | boolean>\n | Record<string, unknown>\n\n/**\n * CodeInput\n *\n * A versatile input component that adapts its rendering based on props:\n * - Disabled mode: Read-only text display\n * - Select mode: Dropdown for enums, booleans, or examples\n * - Editor mode: CodeMirror with environment variable support\n *\n * Type `{{` to trigger autocomplete for environment variables and runtime context functions\n * (for example `{{$guid}}`) when an environment is provided.\n * It takes in any data but always will emit a string value,\n * this string should then be parsed in accordance to the schema or content type.\n *\n * @example\n * ```vue\n * <!-- Basic input with environment variables -->\n * <CodeInput v-model=\"value\" :environment=\"env\" />\n *\n * <!-- Boolean select -->\n * <CodeInput v-model=\"flag\" type=\"boolean\" />\n *\n * <!-- JSON editor with linting -->\n * <CodeInput v-model=\"data\" language=\"json\" :lint=\"true\" />\n * ```\n */\nexport default {\n inheritAttrs: false,\n}\n</script>\n\n<script setup lang=\"ts\">\nimport { ScalarIconButton } from '@scalar/components/icon-button'\nimport { isDefined } from '@scalar/helpers/array/is-defined'\nimport { ScalarIconArrowElbowDownLeft } from '@scalar/icons'\nimport {\n colorPicker as colorPickerExtension,\n EditorView,\n useCodeMirror,\n useDropdown,\n type CodeMirrorLanguage,\n type Extension,\n} from '@scalar/use-codemirror'\nimport {\n CONTEXT_FUNCTION_NAMES,\n getContextFunctionComment,\n isContextFunctionName,\n} from '@scalar/workspace-store/request-example'\nimport type { XScalarEnvironment } from '@scalar/workspace-store/schemas/extensions/document/x-scalar-environments'\nimport { nanoid } from 'nanoid'\nimport { computed, ref, toRef, useAttrs, watch, type Ref } from 'vue'\n\nimport DataTableInputSelect from '@/v2/components/data-table/DataTableInputSelect.vue'\nimport EnvironmentVariableDropdown from '@/v2/features/environments/components/EnvironmentVariablesDropdown.vue'\nimport type { ClientLayout } from '@/v2/types/layout'\n\nimport { backspaceCommand, pillPlugin } from './code-variable-widget'\n\ntype Props = {\n modelValue: CodeInputModelValue\n /** Environment for variable substitution. Pass undefined to disable environment variables */\n environment: XScalarEnvironment | undefined\n /** Type of the input value, affects rendering mode for booleans */\n type?: string | string[]\n /** Render as disabled text display */\n disabled?: boolean\n /** Show error styling */\n error?: boolean\n /** Layout context affects styling and behavior */\n layout?: ClientLayout\n /** Predefined enum values, triggers select mode */\n enum?: string[]\n /** Example values, triggers select mode */\n examples?: string[]\n /** Default value to show in select mode */\n default?: Props['modelValue']\n /** Allow null in boolean select options */\n nullable?: boolean\n /** Placeholder text for empty input */\n placeholder?: string\n /** Show required indicator */\n required?: boolean\n /** Enable color picker extension */\n colorPicker?: boolean\n /** Show line numbers in editor */\n lineNumbers?: boolean\n /** Enable linting */\n lint?: boolean\n /** Enable line wrapping */\n lineWrapping?: boolean\n /** CodeMirror language mode */\n language?: CodeMirrorLanguage\n /** Additional CodeMirror extensions */\n extensions?: Extension[]\n /** Disable tab key for indentation */\n disableTabIndent?: boolean\n /** Disable enter key */\n disableEnter?: boolean\n /** Disable automatic bracket closing */\n disableCloseBrackets?: boolean\n /** Emit submit event on blur */\n emitOnBlur?: boolean\n /** Enable environment variable pills */\n withVariables?: boolean\n /** Enable fake data suggestions like $guid, $timestamp, etc. Should only be enabled for parameters and request bodies */\n withFakeData?: boolean\n /** Emit change event even if the value is the same */\n alwaysEmitChange?: boolean\n /** Custom change handler, prevents default emit */\n handleFieldChange?: (value: string) => void\n /** Custom submit handler, prevents default emit */\n handleFieldSubmit?: (value: string) => void\n /** Put a linethrough on the input text */\n linethrough?: boolean\n}\n\nconst {\n modelValue,\n environment,\n type,\n disabled = false,\n error = false,\n layout = 'desktop',\n enum: enumProp,\n examples,\n default: defaultProp,\n nullable = false,\n placeholder,\n required,\n colorPicker = false,\n lineNumbers = false,\n lint = false,\n lineWrapping = false,\n language,\n extensions = [],\n disableTabIndent = false,\n disableEnter = false,\n disableCloseBrackets = false,\n emitOnBlur = true,\n alwaysEmitChange = false,\n withVariables = true,\n withFakeData = false,\n handleFieldChange,\n handleFieldSubmit,\n} = defineProps<Props>()\n\nconst emit = defineEmits<{\n 'update:modelValue': [value: string]\n 'submit': [value: string, event: KeyboardEvent | FocusEvent]\n 'navigate': [route: { page: 'document'; path: 'environment' }]\n 'blur': [value: string, event: FocusEvent]\n}>()\n\n// ---------------------------------------------------------------------------\n// Component identity and focus state\n\nconst attrs = useAttrs()\nconst componentId =\n (typeof attrs.id === 'string' && attrs.id) || `id-${nanoid()}`\nconst isFocused = ref(false)\n\n// ---------------------------------------------------------------------------\n// Rendering mode detection\n\n/**\n * Determines if we should render a select dropdown for boolean types.\n */\nconst isBooleanMode = computed((): boolean => {\n if (enumProp?.length) {\n return false\n }\n return type === 'boolean' || (Array.isArray(type) && type.includes('boolean'))\n})\n\n/**\n * Options for boolean select mode.\n */\nconst booleanOptions = computed((): string[] =>\n nullable ? ['true', 'false', 'null'] : ['true', 'false'],\n)\n\n/**\n * Default type when dealing with type arrays.\n * Finds the first non-null type.\n */\nconst defaultType = computed((): string | undefined => {\n if (Array.isArray(type)) {\n return type.find((t) => t !== 'null') ?? 'string'\n }\n return type\n})\n\n// ---------------------------------------------------------------------------\n// Event handlers\n\n/**\n * Handles value changes during typing.\n */\nconst handleChange = (value: string): void => {\n if (!alwaysEmitChange && value === serializeValue(modelValue)) {\n return\n }\n\n // Use custom handler or emit update\n if (handleFieldChange) {\n handleFieldChange(value)\n } else {\n emit('update:modelValue', value)\n }\n}\n\n/**\n * Handles form submission (enter key or blur with emitOnBlur).\n */\nconst handleSubmit = (\n value: string,\n event: KeyboardEvent | FocusEvent,\n): void => {\n if (handleFieldSubmit) {\n handleFieldSubmit(value)\n } else {\n emit('submit', value, event)\n }\n}\n\n/**\n * Handles input blur event.\n */\nconst handleBlur = (value: string, event: FocusEvent): void => {\n isFocused.value = false\n\n if (emitOnBlur && modelValue) {\n handleSubmit(value, event)\n }\n\n emit('blur', value, event)\n}\n\n/**\n * Handles model value updates from select components.\n */\nconst handleSelectChange = (value: string): void =>\n emit('update:modelValue', value)\n\n// ---------------------------------------------------------------------------\n// CodeMirror setup\n\n/**\n * Build extensions array.\n * Note: Extensions are not reactive after initialization.\n */\nconst buildExtensions = (): Extension[] => {\n const extensionsList: Extension[] = [...extensions]\n\n if (colorPicker) {\n extensionsList.push(colorPickerExtension)\n }\n\n return extensionsList\n}\n\n/**\n * Reactive pill plugin for environment variable visualization.\n */\nconst contextFunctionDropdownItems = computed(() =>\n withFakeData\n ? CONTEXT_FUNCTION_NAMES.map((key) => ({\n key,\n description: getContextFunctionComment(key),\n }))\n : [],\n)\n\nconst pillPluginExtension = computed(() =>\n pillPlugin({\n environment,\n isContextFunctionName,\n isReadOnly: layout === 'modal',\n }),\n)\n\nconst isLineWrapping = ref(lineWrapping)\n\nwatch(\n () => lineWrapping,\n (val) => {\n isLineWrapping.value = val\n },\n)\n\nconst toggleLineWrapping = (): void => {\n isLineWrapping.value = !isLineWrapping.value\n}\n\nconst lineWrappingExtension = computed(() =>\n isLineWrapping.value ? [EditorView.lineWrapping] : [],\n)\n\n/**\n * Combined extensions for CodeMirror.\n */\nconst codeMirrorExtensions = computed((): Extension[] => [\n ...buildExtensions(),\n ...lineWrappingExtension.value,\n pillPluginExtension.value,\n backspaceCommand,\n])\n\nconst codeMirrorRef: Ref<HTMLDivElement | null> = ref(null)\n\n/** Converts the model value to a string for CodeMirror */\nconst serializeValue = (value: CodeInputModelValue): string => {\n if (typeof value === 'string') {\n return value\n }\n return JSON.stringify(value)\n}\n\nconst { codeMirror, setCodeMirrorContent } = useCodeMirror({\n content: toRef(() => serializeValue(modelValue)),\n onChange: (value) => {\n handleChange(value)\n updateDropdownVisibility()\n },\n onFocus: () => {\n isFocused.value = true\n },\n onBlur: handleBlur,\n codeMirrorRef,\n disableTabIndent: toRef(() => disableTabIndent),\n disableEnter: toRef(() => disableEnter),\n disableCloseBrackets: toRef(() => disableCloseBrackets),\n lineNumbers: toRef(() => lineNumbers),\n language: toRef(() => language),\n lint: toRef(() => lint),\n extensions: codeMirrorExtensions,\n placeholder: toRef(() => placeholder),\n})\n\n/**\n * Handle autofocus attribute.\n */\nwatch(codeMirror, () => {\n if (codeMirror.value && Object.hasOwn(attrs, 'autofocus')) {\n codeMirror.value.focus()\n }\n})\n\n// ---------------------------------------------------------------------------\n// Environment variable dropdown\n\nconst showDropdown = ref(false)\nconst dropdownQuery = ref('')\nconst dropdownPosition = ref({ left: 0, top: 0 })\nconst dropdownRef = ref<InstanceType<\n typeof EnvironmentVariableDropdown\n> | null>(null)\n\nconst { handleDropdownSelect, updateDropdownVisibility } = useDropdown({\n codeMirror,\n query: dropdownQuery,\n showDropdown,\n dropdownPosition,\n})\n\n/**\n * Determines if the environment variable dropdown should be visible.\n * Shows when environment is defined (for env vars) or withFakeData is true (for context functions)\n */\nconst displayVariablesDropdown = computed((): boolean => {\n return (\n showDropdown.value &&\n withVariables &&\n layout !== 'modal' &&\n (Boolean(environment) || withFakeData)\n )\n})\n\n// ---------------------------------------------------------------------------\n// Keyboard event handling\n\n/**\n * Handles keyboard navigation for dropdown and form submission.\n */\nconst handleKeyDown = (key: string, event: KeyboardEvent): void => {\n if (showDropdown.value) {\n if (key === 'down' || key === 'up') {\n event.preventDefault()\n dropdownRef.value?.handleArrowKey(key)\n } else if (key === 'enter') {\n event.preventDefault()\n dropdownRef.value?.handleSelect()\n }\n return\n }\n\n if (key === 'escape' && !disableTabIndent) {\n event.stopPropagation()\n }\n\n if (key === 'enter' && event.target instanceof HTMLDivElement) {\n handleSubmit(codeMirror.value?.state.doc.toString() ?? '', event)\n }\n}\n\n// ---------------------------------------------------------------------------\n// Public API\n\ndefineExpose({\n /**\n * Focus the codemirror element\n *\n * @param cursorAtEnd boolean place the cursor at the end of the input\n */\n focus: (position?: 'start' | 'end' | number) => {\n if (!codeMirror.value) {\n return\n }\n codeMirror.value.focus()\n\n if (!isDefined(position)) {\n return\n }\n\n const anchor = (() => {\n if (position === 'start') {\n return 0\n }\n if (position === 'end') {\n return codeMirror.value.state.doc.length\n }\n return position\n })()\n\n // Move the cursor to the specified position\n codeMirror.value.dispatch({\n selection: { anchor },\n scrollIntoView: true,\n })\n },\n isFocused,\n handleChange,\n handleSubmit,\n handleBlur,\n booleanOptions,\n codeMirror,\n codeMirrorRef,\n modelValue,\n setCodeMirrorContent,\n cursorPosition: () => codeMirror.value?.state.selection.main.head,\n serializeValue,\n})\n</script>\n\n<template>\n <!-- Disabled mode: read-only text display -->\n <div\n v-if=\"disabled\"\n class=\"text-c-2 flex cursor-default items-center justify-center\"\n :class=\"{\n 'font-code pr-2 pl-1 text-base': layout === 'modal',\n 'px-2': layout !== 'modal',\n 'line-through': linethrough,\n }\"\n data-testid=\"code-input-disabled\">\n <span class=\"whitespace-nowrap\">{{ modelValue }}</span>\n </div>\n\n <!-- Enum mode: select dropdown with predefined values -->\n <DataTableInputSelect\n v-else-if=\"enumProp?.length\"\n :default=\"defaultProp\"\n :modelValue=\"modelValue\"\n :type=\"defaultType\"\n :value=\"enumProp\"\n @update:modelValue=\"handleSelectChange\" />\n\n <!-- Boolean mode: select dropdown with true/false (and optionally null) -->\n <DataTableInputSelect\n v-else-if=\"isBooleanMode\"\n :default=\"defaultProp\"\n :modelValue=\"modelValue\"\n :value=\"booleanOptions\"\n @update:modelValue=\"handleSelectChange\" />\n\n <!-- Examples mode: select dropdown with example values -->\n <DataTableInputSelect\n v-else-if=\"examples?.length\"\n :default=\"defaultProp\"\n :modelValue=\"modelValue\"\n :value=\"examples\"\n @update:modelValue=\"handleSelectChange\" />\n\n <!-- Editor mode: CodeMirror with environment variable support -->\n <div\n v-else\n :id=\"componentId\"\n v-bind=\"$attrs\"\n ref=\"codeMirrorRef\"\n class=\"group/input group-[.alert]:outline-orange group-[.error]:outline-red font-code peer relative w-full overflow-hidden text-xs leading-[1.44] whitespace-nowrap -outline-offset-1 has-[:focus-visible]:rounded-[4px] has-[:focus-visible]:outline\"\n :class=\"{\n 'line-wrapping has-[:focus-visible]:bg-b-1 has-[:focus-visible]:absolute has-[:focus-visible]:z-1':\n lineWrapping,\n 'flow-code-input--error': error,\n 'line-through': linethrough,\n }\"\n @keydown.down.stop=\"handleKeyDown('down', $event)\"\n @keydown.enter=\"handleKeyDown('enter', $event)\"\n @keydown.escape=\"handleKeyDown('escape', $event)\"\n @keydown.up.stop=\"handleKeyDown('up', $event)\">\n <!-- Wrap toggle button for multi-line editor (e.g. Request Body) -->\n <div\n v-if=\"lineNumbers\"\n class=\"absolute top-2 right-2 z-10 flex items-center opacity-0 transition-opacity duration-150 group-hover/input:opacity-100 group-has-focus-visible/input:opacity-100\">\n <ScalarIconButton\n class=\"bg-b-2 text-c-2 hover:text-c-1\"\n :class=\"{ '!bg-b-3 !text-c-1': isLineWrapping }\"\n :icon=\"ScalarIconArrowElbowDownLeft\"\n :aria-pressed=\"isLineWrapping\"\n :aria-label=\"isLineWrapping ? 'Disable line wrap' : 'Wrap lines'\"\n :label=\"isLineWrapping ? 'Disable line wrap' : 'Wrap lines'\"\n size=\"sm\"\n tooltip\n variant=\"ghost\"\n @click.stop=\"toggleLineWrapping\" />\n </div>\n\n <!-- Tab exit hint (shown when focused) -->\n <div\n v-if=\"!disableTabIndent\"\n class=\"z-context text-c-2 absolute right-1.5 bottom-1 hidden font-sans group-has-[:focus-visible]/input:block\"\n role=\"alert\">\n Press\n <kbd class=\"-mx-0.25 rounded border px-0.5 font-mono\">Esc</kbd> then\n <kbd class=\"-mx-0.25 rounded border px-0.5 font-mono\">Tab</kbd> to exit\n </div>\n </div>\n\n <!-- Warning slot (positioned absolutely) -->\n <div\n v-if=\"$slots.warning\"\n class=\"centered-y text-orange absolute right-7 text-xs\">\n <slot name=\"warning\" />\n </div>\n\n <!-- Icon slot (positioned absolutely) -->\n <div\n v-if=\"$slots.icon\"\n class=\"centered-y absolute right-0 flex h-full items-center p-1.5 group-has-[.cm-focused]:z-1\">\n <slot name=\"icon\" />\n </div>\n\n <!-- Required indicator -->\n <div\n v-if=\"required\"\n class=\"required centered-y text-xxs text-c-3 group-[.error]:text-red bg-b-1 pointer-events-none absolute right-0 mr-0.5 pt-px pr-2 opacity-100 shadow-[-8px_0_4px_var(--scalar-background-1)] transition-opacity duration-150 group-[.alert]:bg-transparent group-[.alert]:shadow-none group-[.error]:bg-transparent group-[.error]:shadow-none peer-has-[.cm-focused]:opacity-0\">\n Required\n </div>\n\n <!-- Environment variable autocomplete dropdown -->\n <EnvironmentVariableDropdown\n v-if=\"displayVariablesDropdown\"\n ref=\"dropdownRef\"\n :contextFunctionItems=\"contextFunctionDropdownItems\"\n :dropdownPosition=\"dropdownPosition\"\n :environment=\"environment\"\n :query=\"dropdownQuery\"\n @close=\"showDropdown = false\"\n @redirect=\"emit('navigate', { page: 'document', path: 'environment' })\"\n @select=\"handleDropdownSelect\" />\n</template>\n<style scoped>\n/*\n Deep styling for customizing Codemirror\n */\n:deep(.cm-editor) {\n height: 100%;\n outline: none;\n padding: 0;\n background: transparent;\n}\n:deep(.cm-placeholder) {\n color: var(--scalar-color-3);\n}\n:deep(.cm-content) {\n font-family: var(--scalar-font-code);\n font-size: var(--scalar-small);\n max-height: 20px;\n padding: 8px 0;\n}\n/* Tooltip helper */\n:deep(.cm-tooltip) {\n background: transparent !important;\n filter: brightness(var(--scalar-lifted-brightness));\n border-radius: var(--scalar-radius);\n box-shadow: var(--scalar-shadow-2);\n border: none !important;\n outline: none !important;\n overflow: hidden !important;\n}\n:deep(.cm-tooltip-autocomplete ul li) {\n padding: 3px 6px !important;\n}\n:deep(.cm-completionIcon-type:after) {\n color: var(--scalar-color-3) !important;\n}\n:deep(.cm-tooltip-autocomplete ul li[aria-selected]) {\n background: var(--scalar-background-2) !important;\n color: var(--scalar-color-1) !important;\n}\n:deep(.cm-tooltip-autocomplete ul) {\n padding: 6px !important;\n position: relative;\n}\n:deep(.cm-tooltip-autocomplete ul li:hover) {\n border-radius: 3px;\n color: var(--scalar-color-1) !important;\n background: var(--scalar-background-3) !important;\n}\n/* Disable active line highlighting */\n:deep(.cm-activeLine),\n:deep(.cm-activeLineGutter) {\n background-color: transparent;\n}\n/* Color selection matching */\n:deep(.cm-selectionMatch),\n:deep(.cm-matchingBracket) {\n border-radius: var(--scalar-radius);\n background: var(--scalar-background-4) !important;\n}\n/* Color Picker Swatches */\n:deep(.cm-css-color-picker-wrapper) {\n display: inline-flex;\n outline: 1px solid var(--scalar-background-3);\n border-radius: 3px;\n overflow: hidden;\n}\n/* Number gutter */\n:deep(.cm-gutters) {\n background-color: transparent;\n border-right: none;\n color: var(--scalar-color-3);\n font-size: var(--scalar-small);\n line-height: 22px;\n border-radius: 0 0 0 3px;\n}\n:deep(.cm-gutters:before) {\n content: '';\n position: absolute;\n top: 2px;\n left: 2px;\n width: calc(100% - 2px);\n height: calc(100% - 4px);\n border-radius: var(--scalar-radius) 0 0 var(--scalar-radius);\n background-color: var(--scalar-background-1);\n}\n:deep(.cm-gutterElement) {\n font-family: var(--scalar-font-code) !important;\n padding-left: 0px !important;\n padding-right: 6px !important;\n display: flex;\n align-items: center;\n justify-content: flex-end;\n position: relative;\n}\n:deep(.cm-lineNumbers .cm-gutterElement) {\n min-width: fit-content;\n}\n:deep(.cm-gutter + .cm-gutter :not(.cm-foldGutter) .cm-gutterElement) {\n padding-left: 0 !important;\n}\n:deep(.cm-scroller) {\n overflow: auto;\n}\n:deep(.cm-lineWrapping .cm-line) {\n word-break: break-all;\n}\n:deep(.cm-lineWrapping .cm-content) {\n white-space: pre-wrap;\n max-height: none;\n}\n.line-wrapping:focus-within :deep(.cm-content) {\n display: inline-table;\n min-height: fit-content;\n padding: 3px 6px;\n white-space: break-spaces;\n word-break: break-all;\n}\n</style>\n<style>\n.cm-pill {\n color: var(--scalar-color-1) !important;\n padding: 0px 9px;\n display: inline-block;\n border-radius: var(--scalar-radius-full);\n font-size: var(--scalar-small);\n}\n.light-mode .cm-pill {\n background: var(--scalar-background-3) !important;\n}\n.dark-mode .cm-pill {\n background: color-mix(in srgb, var(--tw-bg-base), transparent 90%) !important;\n}\n.cm-pill--context-fn {\n border: 1px dashed color-mix(in srgb, var(--scalar-color-3), transparent 35%);\n padding: 0px 8px;\n}\n.light-mode .cm-pill--context-fn {\n background: color-mix(\n in srgb,\n var(--scalar-background-3),\n transparent 40%\n ) !important;\n}\n.dark-mode .cm-pill--context-fn {\n background: color-mix(\n in srgb,\n var(--scalar-background-3),\n transparent 55%\n ) !important;\n}\n.cm-pill:first-of-type {\n margin-left: 0;\n}\n.cm-editor .cm-widgetBuffer {\n display: none;\n}\n.cm-foldPlaceholder:hover {\n color: var(--scalar-color-1);\n}\n.cm-foldGutter .cm-gutterElement {\n font-size: var(--scalar-heading-4);\n padding: 2px !important;\n}\n.cm-foldGutter .cm-gutterElement:first-of-type {\n display: none;\n}\n.cm-foldGutter .cm-gutterElement .cm-foldMarker {\n padding: 2px;\n padding-top: 2px;\n}\n.cm-foldGutter .cm-gutterElement:hover .cm-foldMarker {\n background: var(--scalar-background-2);\n border-radius: var(--scalar-radius);\n color: var(--scalar-color-1);\n}\n</style>\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"CodeInput.vue.script.js","names":["$attrs","$slots"],"sources":["../../../../src/v2/components/code-input/CodeInput.vue"],"sourcesContent":["<script lang=\"ts\">\nexport type CodeInputModelValue =\n | string\n | number\n | boolean\n | Array<string | number | boolean>\n | Record<string, unknown>\n\n/**\n * CodeInput\n *\n * A versatile input component that adapts its rendering based on props:\n * - Disabled mode: Read-only text display\n * - Select mode: Dropdown for enums, booleans, or examples\n * - Editor mode: CodeMirror with environment variable support\n *\n * Type `{{` to trigger autocomplete for environment variables and runtime context functions\n * (for example `{{$guid}}`) when an environment is provided.\n * It takes in any data but always will emit a string value,\n * this string should then be parsed in accordance to the schema or content type.\n *\n * @example\n * ```vue\n * <!-- Basic input with environment variables -->\n * <CodeInput v-model=\"value\" :environment=\"env\" />\n *\n * <!-- Boolean select -->\n * <CodeInput v-model=\"flag\" type=\"boolean\" />\n *\n * <!-- JSON editor with linting -->\n * <CodeInput v-model=\"data\" language=\"json\" :lint=\"true\" />\n * ```\n */\nexport default {\n inheritAttrs: false,\n}\n</script>\n\n<script setup lang=\"ts\">\nimport { ScalarIconButton } from '@scalar/components/icon-button'\nimport { isDefined } from '@scalar/helpers/array/is-defined'\nimport { ScalarIconArrowElbowDownLeft } from '@scalar/icons'\nimport {\n colorPicker as colorPickerExtension,\n EditorView,\n useCodeMirror,\n useDropdown,\n type CodeMirrorLanguage,\n type Extension,\n} from '@scalar/use-codemirror'\nimport {\n CONTEXT_FUNCTION_NAMES,\n getContextFunctionComment,\n isContextFunctionName,\n} from '@scalar/workspace-store/request-example'\nimport type { XScalarEnvironment } from '@scalar/workspace-store/schemas/extensions/document/x-scalar-environments'\nimport { nanoid } from 'nanoid'\nimport { computed, ref, toRef, useAttrs, watch, type Ref } from 'vue'\n\nimport DataTableInputSelect from '@/v2/components/data-table/DataTableInputSelect.vue'\nimport EnvironmentVariableDropdown from '@/v2/features/environments/components/EnvironmentVariablesDropdown.vue'\nimport { useLocalization } from '@/v2/features/localization'\nimport type { ClientLayout } from '@/v2/types/layout'\n\nimport { backspaceCommand, pillPlugin } from './code-variable-widget'\n\nconst {\n modelValue,\n environment,\n type,\n disabled = false,\n error = false,\n layout = 'desktop',\n enum: enumProp,\n examples,\n default: defaultProp,\n nullable = false,\n placeholder,\n required,\n colorPicker = false,\n lineNumbers = false,\n lint = false,\n lineWrapping = false,\n language,\n extensions = [],\n disableTabIndent = false,\n disableEnter = false,\n disableCloseBrackets = false,\n emitOnBlur = true,\n alwaysEmitChange = false,\n withVariables = true,\n withFakeData = false,\n handleFieldChange,\n handleFieldSubmit,\n} = defineProps<Props>()\n\nconst emit = defineEmits<{\n 'update:modelValue': [value: string]\n 'submit': [value: string, event: KeyboardEvent | FocusEvent]\n 'navigate': [route: { page: 'document'; path: 'environment' }]\n 'blur': [value: string, event: FocusEvent]\n}>()\n\nconst { translate } = useLocalization()\n\ntype Props = {\n modelValue: CodeInputModelValue\n /** Environment for variable substitution. Pass undefined to disable environment variables */\n environment: XScalarEnvironment | undefined\n /** Type of the input value, affects rendering mode for booleans */\n type?: string | string[]\n /** Render as disabled text display */\n disabled?: boolean\n /** Show error styling */\n error?: boolean\n /** Layout context affects styling and behavior */\n layout?: ClientLayout\n /** Predefined enum values, triggers select mode */\n enum?: string[]\n /** Example values, triggers select mode */\n examples?: string[]\n /** Default value to show in select mode */\n default?: Props['modelValue']\n /** Allow null in boolean select options */\n nullable?: boolean\n /** Placeholder text for empty input */\n placeholder?: string\n /** Show required indicator */\n required?: boolean\n /** Enable color picker extension */\n colorPicker?: boolean\n /** Show line numbers in editor */\n lineNumbers?: boolean\n /** Enable linting */\n lint?: boolean\n /** Enable line wrapping */\n lineWrapping?: boolean\n /** CodeMirror language mode */\n language?: CodeMirrorLanguage\n /** Additional CodeMirror extensions */\n extensions?: Extension[]\n /** Disable tab key for indentation */\n disableTabIndent?: boolean\n /** Disable enter key */\n disableEnter?: boolean\n /** Disable automatic bracket closing */\n disableCloseBrackets?: boolean\n /** Emit submit event on blur */\n emitOnBlur?: boolean\n /** Enable environment variable pills */\n withVariables?: boolean\n /** Enable fake data suggestions like $guid, $timestamp, etc. Should only be enabled for parameters and request bodies */\n withFakeData?: boolean\n /** Emit change event even if the value is the same */\n alwaysEmitChange?: boolean\n /** Custom change handler, prevents default emit */\n handleFieldChange?: (value: string) => void\n /** Custom submit handler, prevents default emit */\n handleFieldSubmit?: (value: string) => void\n /** Put a linethrough on the input text */\n linethrough?: boolean\n}\n\n// ---------------------------------------------------------------------------\n// Component identity and focus state\n\nconst attrs = useAttrs()\nconst componentId =\n (typeof attrs.id === 'string' && attrs.id) || `id-${nanoid()}`\nconst isFocused = ref(false)\n\n// ---------------------------------------------------------------------------\n// Rendering mode detection\n\n/**\n * Determines if we should render a select dropdown for boolean types.\n */\nconst isBooleanMode = computed((): boolean => {\n if (enumProp?.length) {\n return false\n }\n return type === 'boolean' || (Array.isArray(type) && type.includes('boolean'))\n})\n\n/**\n * Options for boolean select mode.\n */\nconst booleanOptions = computed((): string[] =>\n nullable ? ['true', 'false', 'null'] : ['true', 'false'],\n)\n\n/**\n * Default type when dealing with type arrays.\n * Finds the first non-null type.\n */\nconst defaultType = computed((): string | undefined => {\n if (Array.isArray(type)) {\n return type.find((t) => t !== 'null') ?? 'string'\n }\n return type\n})\n\n// ---------------------------------------------------------------------------\n// Event handlers\n\n/**\n * Handles value changes during typing.\n */\nconst handleChange = (value: string): void => {\n if (!alwaysEmitChange && value === serializeValue(modelValue)) {\n return\n }\n\n // Use custom handler or emit update\n if (handleFieldChange) {\n handleFieldChange(value)\n } else {\n emit('update:modelValue', value)\n }\n}\n\n/**\n * Handles form submission (enter key or blur with emitOnBlur).\n */\nconst handleSubmit = (\n value: string,\n event: KeyboardEvent | FocusEvent,\n): void => {\n if (handleFieldSubmit) {\n handleFieldSubmit(value)\n } else {\n emit('submit', value, event)\n }\n}\n\n/**\n * Handles input blur event.\n */\nconst handleBlur = (value: string, event: FocusEvent): void => {\n isFocused.value = false\n\n if (emitOnBlur && modelValue) {\n handleSubmit(value, event)\n }\n\n emit('blur', value, event)\n}\n\n/**\n * Handles model value updates from select components.\n */\nconst handleSelectChange = (value: string): void =>\n emit('update:modelValue', value)\n\n// ---------------------------------------------------------------------------\n// CodeMirror setup\n\n/**\n * Build extensions array.\n * Note: Extensions are not reactive after initialization.\n */\nconst buildExtensions = (): Extension[] => {\n const extensionsList: Extension[] = [...extensions]\n\n if (colorPicker) {\n extensionsList.push(colorPickerExtension)\n }\n\n return extensionsList\n}\n\n/**\n * Reactive pill plugin for environment variable visualization.\n */\nconst contextFunctionDropdownItems = computed(() =>\n withFakeData\n ? CONTEXT_FUNCTION_NAMES.map((key) => ({\n key,\n description: getContextFunctionComment(key),\n }))\n : [],\n)\n\nconst pillPluginExtension = computed(() =>\n pillPlugin({\n environment,\n isContextFunctionName,\n isReadOnly: layout === 'modal',\n translate,\n }),\n)\n\nconst isLineWrapping = ref(lineWrapping)\n\nwatch(\n () => lineWrapping,\n (val) => {\n isLineWrapping.value = val\n },\n)\n\nconst toggleLineWrapping = (): void => {\n isLineWrapping.value = !isLineWrapping.value\n}\n\nconst lineWrappingExtension = computed(() =>\n isLineWrapping.value ? [EditorView.lineWrapping] : [],\n)\n\n/**\n * Combined extensions for CodeMirror.\n */\nconst codeMirrorExtensions = computed((): Extension[] => [\n ...buildExtensions(),\n ...lineWrappingExtension.value,\n pillPluginExtension.value,\n backspaceCommand,\n])\n\nconst codeMirrorRef: Ref<HTMLDivElement | null> = ref(null)\n\n/** Converts the model value to a string for CodeMirror */\nconst serializeValue = (value: CodeInputModelValue): string => {\n if (typeof value === 'string') {\n return value\n }\n return JSON.stringify(value)\n}\n\nconst { codeMirror, setCodeMirrorContent } = useCodeMirror({\n content: toRef(() => serializeValue(modelValue)),\n onChange: (value) => {\n handleChange(value)\n updateDropdownVisibility()\n },\n onFocus: () => {\n isFocused.value = true\n },\n onBlur: handleBlur,\n codeMirrorRef,\n disableTabIndent: toRef(() => disableTabIndent),\n disableEnter: toRef(() => disableEnter),\n disableCloseBrackets: toRef(() => disableCloseBrackets),\n lineNumbers: toRef(() => lineNumbers),\n language: toRef(() => language),\n lint: toRef(() => lint),\n extensions: codeMirrorExtensions,\n placeholder: toRef(() => placeholder),\n})\n\n/**\n * Handle autofocus attribute.\n */\nwatch(codeMirror, () => {\n if (codeMirror.value && Object.hasOwn(attrs, 'autofocus')) {\n codeMirror.value.focus()\n }\n})\n\n// ---------------------------------------------------------------------------\n// Environment variable dropdown\n\nconst showDropdown = ref(false)\nconst dropdownQuery = ref('')\nconst dropdownPosition = ref({ left: 0, top: 0 })\nconst dropdownRef = ref<InstanceType<\n typeof EnvironmentVariableDropdown\n> | null>(null)\n\nconst { handleDropdownSelect, updateDropdownVisibility } = useDropdown({\n codeMirror,\n query: dropdownQuery,\n showDropdown,\n dropdownPosition,\n})\n\n/**\n * Determines if the environment variable dropdown should be visible.\n * Shows when environment is defined (for env vars) or withFakeData is true (for context functions)\n */\nconst displayVariablesDropdown = computed((): boolean => {\n return (\n showDropdown.value &&\n withVariables &&\n layout !== 'modal' &&\n (Boolean(environment) || withFakeData)\n )\n})\n\n// ---------------------------------------------------------------------------\n// Keyboard event handling\n\n/**\n * Handles keyboard navigation for dropdown and form submission.\n */\nconst handleKeyDown = (key: string, event: KeyboardEvent): void => {\n if (showDropdown.value) {\n if (key === 'down' || key === 'up') {\n event.preventDefault()\n dropdownRef.value?.handleArrowKey(key)\n } else if (key === 'enter') {\n event.preventDefault()\n dropdownRef.value?.handleSelect()\n }\n return\n }\n\n if (key === 'escape' && !disableTabIndent) {\n event.stopPropagation()\n }\n\n if (key === 'enter' && event.target instanceof HTMLDivElement) {\n handleSubmit(codeMirror.value?.state.doc.toString() ?? '', event)\n }\n}\n\n// ---------------------------------------------------------------------------\n// Public API\n\ndefineExpose({\n /**\n * Focus the codemirror element\n *\n * @param cursorAtEnd boolean place the cursor at the end of the input\n */\n focus: (position?: 'start' | 'end' | number) => {\n if (!codeMirror.value) {\n return\n }\n codeMirror.value.focus()\n\n if (!isDefined(position)) {\n return\n }\n\n const anchor = (() => {\n if (position === 'start') {\n return 0\n }\n if (position === 'end') {\n return codeMirror.value.state.doc.length\n }\n return position\n })()\n\n // Move the cursor to the specified position\n codeMirror.value.dispatch({\n selection: { anchor },\n scrollIntoView: true,\n })\n },\n isFocused,\n handleChange,\n handleSubmit,\n handleBlur,\n booleanOptions,\n codeMirror,\n codeMirrorRef,\n modelValue,\n setCodeMirrorContent,\n cursorPosition: () => codeMirror.value?.state.selection.main.head,\n serializeValue,\n})\n</script>\n\n<template>\n <!-- Disabled mode: read-only text display -->\n <div\n v-if=\"disabled\"\n class=\"text-c-2 flex cursor-default items-center justify-center\"\n :class=\"{\n 'font-code pr-2 pl-1 text-base': layout === 'modal',\n 'px-2': layout !== 'modal',\n 'line-through': linethrough,\n }\"\n data-testid=\"code-input-disabled\">\n <span class=\"whitespace-nowrap\">{{ modelValue }}</span>\n </div>\n\n <!-- Enum mode: select dropdown with predefined values -->\n <DataTableInputSelect\n v-else-if=\"enumProp?.length\"\n :default=\"defaultProp\"\n :modelValue=\"modelValue\"\n :type=\"defaultType\"\n :value=\"enumProp\"\n @update:modelValue=\"handleSelectChange\" />\n\n <!-- Boolean mode: select dropdown with true/false (and optionally null) -->\n <DataTableInputSelect\n v-else-if=\"isBooleanMode\"\n :default=\"defaultProp\"\n :modelValue=\"modelValue\"\n :value=\"booleanOptions\"\n @update:modelValue=\"handleSelectChange\" />\n\n <!-- Examples mode: select dropdown with example values -->\n <DataTableInputSelect\n v-else-if=\"examples?.length\"\n :default=\"defaultProp\"\n :modelValue=\"modelValue\"\n :value=\"examples\"\n @update:modelValue=\"handleSelectChange\" />\n\n <!-- Editor mode: CodeMirror with environment variable support -->\n <div\n v-else\n :id=\"componentId\"\n v-bind=\"$attrs\"\n ref=\"codeMirrorRef\"\n class=\"group/input group-[.alert]:outline-orange group-[.error]:outline-red font-code peer relative w-full overflow-hidden text-xs leading-[1.44] whitespace-nowrap -outline-offset-1 has-[:focus-visible]:rounded-[4px] has-[:focus-visible]:outline\"\n :class=\"{\n 'line-wrapping has-[:focus-visible]:bg-b-1 has-[:focus-visible]:absolute has-[:focus-visible]:z-1':\n lineWrapping,\n 'flow-code-input--error': error,\n 'line-through': linethrough,\n }\"\n @keydown.down.stop=\"handleKeyDown('down', $event)\"\n @keydown.enter=\"handleKeyDown('enter', $event)\"\n @keydown.escape=\"handleKeyDown('escape', $event)\"\n @keydown.up.stop=\"handleKeyDown('up', $event)\">\n <!-- Wrap toggle button for multi-line editor (e.g. Request Body) -->\n <div\n v-if=\"lineNumbers\"\n class=\"absolute top-2 right-2 z-10 flex items-center opacity-0 transition-opacity duration-150 group-hover/input:opacity-100 group-has-focus-visible/input:opacity-100\">\n <ScalarIconButton\n class=\"bg-b-2 text-c-2 hover:text-c-1\"\n :class=\"{ '!bg-b-3 !text-c-1': isLineWrapping }\"\n :icon=\"ScalarIconArrowElbowDownLeft\"\n :aria-pressed=\"isLineWrapping\"\n :aria-label=\"isLineWrapping ? 'Disable line wrap' : 'Wrap lines'\"\n :label=\"isLineWrapping ? 'Disable line wrap' : 'Wrap lines'\"\n size=\"sm\"\n tooltip\n variant=\"ghost\"\n @click.stop=\"toggleLineWrapping\" />\n </div>\n\n <!-- Tab exit hint (shown when focused) -->\n <div\n v-if=\"!disableTabIndent\"\n class=\"z-context text-c-2 absolute right-1.5 bottom-1 hidden font-sans group-has-[:focus-visible]/input:block\"\n role=\"alert\">\n {{\n translate('apiClient.codeInput.exitHint', { escape: 'Esc', tab: 'Tab' })\n }}\n </div>\n </div>\n\n <!-- Warning slot (positioned absolutely) -->\n <div\n v-if=\"$slots.warning\"\n class=\"centered-y text-orange absolute right-7 text-xs\">\n <slot name=\"warning\" />\n </div>\n\n <!-- Icon slot (positioned absolutely) -->\n <div\n v-if=\"$slots.icon\"\n class=\"centered-y absolute right-0 flex h-full items-center p-1.5 group-has-[.cm-focused]:z-1\">\n <slot name=\"icon\" />\n </div>\n\n <!-- Required indicator -->\n <div\n v-if=\"required\"\n class=\"required centered-y text-xxs text-c-3 group-[.error]:text-red bg-b-1 pointer-events-none absolute right-0 mr-0.5 pt-px pr-2 opacity-100 shadow-[-8px_0_4px_var(--scalar-background-1)] transition-opacity duration-150 group-[.alert]:bg-transparent group-[.alert]:shadow-none group-[.error]:bg-transparent group-[.error]:shadow-none peer-has-[.cm-focused]:opacity-0\">\n {{ translate('apiClient.codeInput.required') }}\n </div>\n\n <!-- Environment variable autocomplete dropdown -->\n <EnvironmentVariableDropdown\n v-if=\"displayVariablesDropdown\"\n ref=\"dropdownRef\"\n :contextFunctionItems=\"contextFunctionDropdownItems\"\n :dropdownPosition=\"dropdownPosition\"\n :environment=\"environment\"\n :query=\"dropdownQuery\"\n @close=\"showDropdown = false\"\n @redirect=\"emit('navigate', { page: 'document', path: 'environment' })\"\n @select=\"handleDropdownSelect\" />\n</template>\n<style scoped>\n/*\n Deep styling for customizing Codemirror\n */\n:deep(.cm-editor) {\n height: 100%;\n outline: none;\n padding: 0;\n background: transparent;\n}\n:deep(.cm-placeholder) {\n color: var(--scalar-color-3);\n}\n:deep(.cm-content) {\n font-family: var(--scalar-font-code);\n font-size: var(--scalar-small);\n max-height: 20px;\n padding: 8px 0;\n}\n/* Tooltip helper */\n:deep(.cm-tooltip) {\n background: transparent !important;\n filter: brightness(var(--scalar-lifted-brightness));\n border-radius: var(--scalar-radius);\n box-shadow: var(--scalar-shadow-2);\n border: none !important;\n outline: none !important;\n overflow: hidden !important;\n}\n:deep(.cm-tooltip-autocomplete ul li) {\n padding: 3px 6px !important;\n}\n:deep(.cm-completionIcon-type:after) {\n color: var(--scalar-color-3) !important;\n}\n:deep(.cm-tooltip-autocomplete ul li[aria-selected]) {\n background: var(--scalar-background-2) !important;\n color: var(--scalar-color-1) !important;\n}\n:deep(.cm-tooltip-autocomplete ul) {\n padding: 6px !important;\n position: relative;\n}\n:deep(.cm-tooltip-autocomplete ul li:hover) {\n border-radius: 3px;\n color: var(--scalar-color-1) !important;\n background: var(--scalar-background-3) !important;\n}\n/* Disable active line highlighting */\n:deep(.cm-activeLine),\n:deep(.cm-activeLineGutter) {\n background-color: transparent;\n}\n/* Color selection matching */\n:deep(.cm-selectionMatch),\n:deep(.cm-matchingBracket) {\n border-radius: var(--scalar-radius);\n background: var(--scalar-background-4) !important;\n}\n/* Color Picker Swatches */\n:deep(.cm-css-color-picker-wrapper) {\n display: inline-flex;\n outline: 1px solid var(--scalar-background-3);\n border-radius: 3px;\n overflow: hidden;\n}\n/* Number gutter */\n:deep(.cm-gutters) {\n background-color: transparent;\n border-right: none;\n color: var(--scalar-color-3);\n font-size: var(--scalar-small);\n line-height: 22px;\n border-radius: 0 0 0 3px;\n}\n:deep(.cm-gutters:before) {\n content: '';\n position: absolute;\n top: 2px;\n left: 2px;\n width: calc(100% - 2px);\n height: calc(100% - 4px);\n border-radius: var(--scalar-radius) 0 0 var(--scalar-radius);\n background-color: var(--scalar-background-1);\n}\n:deep(.cm-gutterElement) {\n font-family: var(--scalar-font-code) !important;\n padding-left: 0px !important;\n padding-right: 6px !important;\n display: flex;\n align-items: center;\n justify-content: flex-end;\n position: relative;\n}\n:deep(.cm-lineNumbers .cm-gutterElement) {\n min-width: fit-content;\n}\n:deep(.cm-gutter + .cm-gutter :not(.cm-foldGutter) .cm-gutterElement) {\n padding-left: 0 !important;\n}\n:deep(.cm-scroller) {\n overflow: auto;\n}\n:deep(.cm-lineWrapping .cm-line) {\n word-break: break-all;\n}\n:deep(.cm-lineWrapping .cm-content) {\n white-space: pre-wrap;\n max-height: none;\n}\n.line-wrapping:focus-within :deep(.cm-content) {\n display: inline-table;\n min-height: fit-content;\n padding: 3px 6px;\n white-space: break-spaces;\n word-break: break-all;\n}\n</style>\n<style>\n.cm-pill {\n color: var(--scalar-color-1) !important;\n padding: 0px 9px;\n display: inline-block;\n border-radius: var(--scalar-radius-full);\n font-size: var(--scalar-small);\n}\n.light-mode .cm-pill {\n background: var(--scalar-background-3) !important;\n}\n.dark-mode .cm-pill {\n background: color-mix(in srgb, var(--tw-bg-base), transparent 90%) !important;\n}\n.cm-pill--context-fn {\n border: 1px dashed color-mix(in srgb, var(--scalar-color-3), transparent 35%);\n padding: 0px 8px;\n}\n.light-mode .cm-pill--context-fn {\n background: color-mix(\n in srgb,\n var(--scalar-background-3),\n transparent 40%\n ) !important;\n}\n.dark-mode .cm-pill--context-fn {\n background: color-mix(\n in srgb,\n var(--scalar-background-3),\n transparent 55%\n ) !important;\n}\n.cm-pill:first-of-type {\n margin-left: 0;\n}\n.cm-editor .cm-widgetBuffer {\n display: none;\n}\n.cm-foldPlaceholder:hover {\n color: var(--scalar-color-1);\n}\n.cm-foldGutter .cm-gutterElement {\n font-size: var(--scalar-heading-4);\n padding: 2px !important;\n}\n.cm-foldGutter .cm-gutterElement:first-of-type {\n display: none;\n}\n.cm-foldGutter .cm-gutterElement .cm-foldMarker {\n padding: 2px;\n padding-top: 2px;\n}\n.cm-foldGutter .cm-gutterElement:hover .cm-foldMarker {\n background: var(--scalar-background-2);\n border-radius: var(--scalar-radius);\n color: var(--scalar-color-1);\n}\n</style>\n"],"mappings":"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"}
|
|
@@ -61,12 +61,12 @@ declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<{
|
|
|
61
61
|
editorRef: Readonly<import("vue").ShallowRef<HTMLDivElement | null>>;
|
|
62
62
|
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
63
63
|
submit: (value: string, event: KeyboardEvent | FocusEvent) => any;
|
|
64
|
-
"update:modelValue": (value: string) => any;
|
|
65
|
-
blur: (value: string, event: FocusEvent) => any;
|
|
66
64
|
navigate: (route: {
|
|
67
65
|
page: "document";
|
|
68
66
|
path: "environment";
|
|
69
67
|
}) => any;
|
|
68
|
+
"update:modelValue": (value: string) => any;
|
|
69
|
+
blur: (value: string, event: FocusEvent) => any;
|
|
70
70
|
}, string, import("vue").PublicProps, Readonly<{
|
|
71
71
|
modelValue: CodeInputModelValue;
|
|
72
72
|
/** Environment for variable substitution. Pass undefined to disable env vars */
|
|
@@ -105,12 +105,12 @@ declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<{
|
|
|
105
105
|
nullable?: boolean;
|
|
106
106
|
}> & Readonly<{
|
|
107
107
|
onSubmit?: ((value: string, event: KeyboardEvent | FocusEvent) => any) | undefined;
|
|
108
|
-
"onUpdate:modelValue"?: ((value: string) => any) | undefined;
|
|
109
|
-
onBlur?: ((value: string, event: FocusEvent) => any) | undefined;
|
|
110
108
|
onNavigate?: ((route: {
|
|
111
109
|
page: "document";
|
|
112
110
|
path: "environment";
|
|
113
111
|
}) => any) | undefined;
|
|
112
|
+
"onUpdate:modelValue"?: ((value: string) => any) | undefined;
|
|
113
|
+
onBlur?: ((value: string, event: FocusEvent) => any) | undefined;
|
|
114
114
|
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>, {
|
|
115
115
|
warning?: (props: {}) => any;
|
|
116
116
|
} & {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeInputLite.vue.d.ts","sourceRoot":"","sources":["../../../../src/v2/components/code-input/CodeInputLite.vue"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CodeInputLite.vue.d.ts","sourceRoot":"","sources":["../../../../src/v2/components/code-input/CodeInputLite.vue"],"names":[],"mappings":"AA6kCA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2EAA2E,CAAA;AAkBnH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAErD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAQ1D;;;;;;;;GAQG;wBACkB,OAAO,YAAY;AAAxC,wBAAyC;AAKzC,QAAA,MAAM,YAAY;gBAmCJ,mBAAmB;IAC/B,gFAAgF;iBACnE,kBAAkB,GAAG,SAAS;IAC3C,kDAAkD;eACvC,OAAO;IAClB,wFAAwF;eAC7E,OAAO;IAClB,yBAAyB;YACjB,OAAO;IACf,6DAA6D;aACpD,YAAY;IACrB,0CAA0C;kBAC5B,MAAM;IACpB,8BAA8B;eACnB,OAAO;IAClB,0BAA0B;iBACb,OAAO;IACpB,6DAA6D;oBAC7C,OAAO;IACvB,4DAA4D;mBAC7C,OAAO;IACtB,+DAA+D;uBAC5C,OAAO;IAC1B,yEAAyE;kBAC3D,OAAO;IACrB,0EAA0E;WACnE,MAAM,GAAG,MAAM,EAAE;IACxB,yEAAyE;WAClE,MAAM,EAAE;IACf,uFAAuF;eAC5E,MAAM,EAAE;IACnB,+CAA+C;cACrC,mBAAmB;IAC7B,0DAA0D;eAC/C,OAAO;;IAmtBlB,6DAA6D;uBAC1C,OAAO,GAAG,KAAK,GAAG,MAAM,KAAG,IAAI;IAclD,0EAA0E;mCACjD,IAAI;IAQ7B,6DAA6D;oBAC/C,MAAM;IACpB,wCAAwC;0BACpB,MAAM,GAAG,SAAS;;;;;;cAvxBV,UAAU;cAAQ,aAAa;;;;;gBAO/C,mBAAmB;IAC/B,gFAAgF;iBACnE,kBAAkB,GAAG,SAAS;IAC3C,kDAAkD;eACvC,OAAO;IAClB,wFAAwF;eAC7E,OAAO;IAClB,yBAAyB;YACjB,OAAO;IACf,6DAA6D;aACpD,YAAY;IACrB,0CAA0C;kBAC5B,MAAM;IACpB,8BAA8B;eACnB,OAAO;IAClB,0BAA0B;iBACb,OAAO;IACpB,6DAA6D;oBAC7C,OAAO;IACvB,4DAA4D;mBAC7C,OAAO;IACtB,+DAA+D;uBAC5C,OAAO;IAC1B,yEAAyE;kBAC3D,OAAO;IACrB,0EAA0E;WACnE,MAAM,GAAG,MAAM,EAAE;IACxB,yEAAyE;WAClE,MAAM,EAAE;IACf,uFAAuF;eAC5E,MAAM,EAAE;IACnB,+CAA+C;cACrC,mBAAmB;IAC7B,0DAA0D;eAC/C,OAAO;;;;cAzCU,UAAU;cAAQ,aAAa;;;;;cAmlC/C,CAAC,KAAK,IAAiB,KAAK,GAAG;;WAClC,CAAC,KAAK,IAAiB,KAAK,GAAG;EAYtC,CAAC;AACL,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KACV,CAAA;CACD,CAAC"}
|
|
@@ -3,7 +3,7 @@ import CodeInputLite_vue_vue_type_script_setup_true_lang_default from "./CodeInp
|
|
|
3
3
|
/* empty css */
|
|
4
4
|
/* empty css */
|
|
5
5
|
//#region src/v2/components/code-input/CodeInputLite.vue
|
|
6
|
-
var CodeInputLite_default = /*#__PURE__*/ _plugin_vue_export_helper_default(CodeInputLite_vue_vue_type_script_setup_true_lang_default, [["__scopeId", "data-v-
|
|
6
|
+
var CodeInputLite_default = /*#__PURE__*/ _plugin_vue_export_helper_default(CodeInputLite_vue_vue_type_script_setup_true_lang_default, [["__scopeId", "data-v-9bca2f92"]]);
|
|
7
7
|
//#endregion
|
|
8
8
|
export { CodeInputLite_default as default };
|
|
9
9
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeInputLite.vue.js","names":[],"sources":["../../../../src/v2/components/code-input/CodeInputLite.vue"],"sourcesContent":["<script lang=\"ts\">\n/**\n * CodeInputLite\n *\n * Single-line `contenteditable` editor that renders `{{varname}}` as atomic\n * pill spans (`contenteditable=\"false\"`) and offers an env-variable\n * autocomplete on `{{`. The value is still exposed as a `{{name}}`-bearing\n * string via `update:modelValue`; DOM ↔ model conversion lives in\n * `renderModel` and `serializeEditor`.\n */\nexport default {\n inheritAttrs: false,\n}\n</script>\n\n<script setup lang=\"ts\">\nimport { isDefined } from '@scalar/helpers/array/is-defined'\nimport { REGEX } from '@scalar/helpers/regex/regex-helpers'\nimport {\n CONTEXT_FUNCTION_NAMES,\n getContextFunctionComment,\n isContextFunctionName,\n type ContextFunctionName,\n} from '@scalar/workspace-store/request-example'\nimport type { XScalarEnvironment } from '@scalar/workspace-store/schemas/extensions/document/x-scalar-environments'\nimport { nanoid } from 'nanoid'\nimport {\n computed,\n createApp,\n nextTick,\n onBeforeUnmount,\n onMounted,\n ref,\n useAttrs,\n useTemplateRef,\n watch,\n type App,\n} from 'vue'\n\nimport DataTableInputSelect from '@/v2/components/data-table/DataTableInputSelect.vue'\nimport EnvironmentVariableDropdown from '@/v2/features/environments/components/EnvironmentVariablesDropdown.vue'\nimport type { ClientLayout } from '@/v2/types/layout'\n\nimport type { CodeInputModelValue } from './CodeInput.vue'\nimport { buildPillContext } from './helpers/build-pill-context'\nimport { lookupVariableValue } from './helpers/lookup-variable-value'\nimport { pillSignature } from './helpers/pill-signature'\nimport { serializeValue } from './helpers/serialize-value'\nimport PillTooltipHost from './PillTooltipHost.vue'\n\ntype Props = {\n modelValue: CodeInputModelValue\n /** Environment for variable substitution. Pass undefined to disable env vars */\n environment: XScalarEnvironment | undefined\n /** Render as a non-interactive read-only label */\n disabled?: boolean\n /** Render the input with the native `readonly` attribute (still focusable, no edits) */\n readOnly?: boolean\n /** Show error styling */\n error?: boolean\n /** Layout context affects styling and dropdown visibility */\n layout?: ClientLayout\n /** Placeholder text for an empty input */\n placeholder?: string\n /** Show required indicator */\n required?: boolean\n /** Emit submit on blur */\n emitOnBlur?: boolean\n /** Render variable pills + show the autocomplete dropdown */\n withVariables?: boolean\n /** Include `{{$guid}}` etc. in the autocomplete dropdown */\n withFakeData?: boolean\n /** Always emit change events even if the value is unchanged */\n alwaysEmitChange?: boolean\n /** Strike-through styling for the input text (e.g. overridden values) */\n linethrough?: boolean\n /** Schema type — drives boolean select mode when `boolean` is included */\n type?: string | string[]\n /** Predefined enum values; when set the input is replaced by a select */\n enum?: string[]\n /** Example values; when set (and no enum/boolean) the input is replaced by a select */\n examples?: string[]\n /** Default value to suggest in select modes */\n default?: CodeInputModelValue\n /** Whether the boolean select includes a `null` option */\n nullable?: boolean\n}\n\nconst {\n modelValue,\n environment,\n disabled = false,\n readOnly = false,\n error = false,\n layout = 'desktop',\n placeholder,\n required = false,\n emitOnBlur = true,\n alwaysEmitChange = false,\n withVariables = true,\n withFakeData = false,\n linethrough = false,\n type,\n enum: enumProp,\n examples,\n default: defaultProp,\n nullable = false,\n} = defineProps<Props>()\n\nconst emit = defineEmits<{\n 'update:modelValue': [value: string]\n 'submit': [value: string, event: KeyboardEvent | FocusEvent]\n 'blur': [value: string, event: FocusEvent]\n 'navigate': [route: { page: 'document'; path: 'environment' }]\n}>()\n\nconst attrs = useAttrs()\nconst ariaLabel = computed(() =>\n typeof attrs['aria-label'] === 'string' ? attrs['aria-label'] : undefined,\n)\n\n/**\n * The id only matters once the dropdown opens (`aria-controls` /\n * `aria-activedescendant`), so we defer `nanoid()` until first focus to\n * keep idle instances cheap. A consumer-supplied `id` attr is preserved.\n */\nconst generatedComponentId = ref<string | null>(null)\nconst componentId = computed((): string | undefined =>\n typeof attrs.id === 'string'\n ? attrs.id\n : (generatedComponentId.value ?? undefined),\n)\nconst ensureComponentId = (): void => {\n if (\n (typeof attrs.id !== 'string' || !attrs.id) &&\n generatedComponentId.value === null\n ) {\n generatedComponentId.value = `id-${nanoid()}`\n }\n}\n\nconst editorRef = useTemplateRef<HTMLDivElement>('editorRef')\nconst dropdownRef = ref<InstanceType<\n typeof EnvironmentVariableDropdown\n> | null>(null)\n\n/** Id of the dropdown's `role=\"listbox\"` element, for the combobox wiring. */\nconst listboxId = computed((): string | undefined =>\n componentId.value ? `${componentId.value}-listbox` : undefined,\n)\n\n/**\n * Id of the option the dropdown currently highlights. Mirrors the dropdown's\n * own selection so the editor can expose it via `aria-activedescendant`.\n */\nconst activeOptionId = computed(\n (): string | undefined => dropdownRef.value?.activeOptionId,\n)\n\nconst isFocused = ref(false)\nconst isEmpty = ref(true)\n\n/**\n * True while an IME composition is in progress. Rebuilding the editor DOM\n * mid-composition (e.g. when `{{` forms a pill) cancels the composition, so we\n * defer those rebuilds until `compositionend`.\n */\nconst isComposing = ref(false)\n\n/**\n * Whether the serialized value should count as empty for placeholder display.\n *\n * `contenteditable` can leave behind invisible residue after some delete\n * sequences — most commonly a non-breaking space (` `) — which makes a\n * visually empty field report a non-zero length and silently drop its\n * placeholder. Trimming covers that case; ` ` counts as whitespace, so a\n * field that only holds editor residue is treated as empty. This affects the\n * placeholder flag only, never the value emitted via `serializeEditor`.\n */\nconst isBlankValue = (text: string): boolean => text.trim().length === 0\n\n// ───────────────────────────────────────────────────────────────────\n// Rendering-mode detection (parity with CodeInput's select dispatch)\n// ───────────────────────────────────────────────────────────────────\n\n/** True when the schema type is exactly `boolean` (or includes it in a tuple type). */\nconst isBooleanMode = computed((): boolean => {\n if (enumProp?.length) {\n return false\n }\n return type === 'boolean' || (Array.isArray(type) && type.includes('boolean'))\n})\n\nconst booleanOptions = computed((): string[] =>\n nullable ? ['true', 'false', 'null'] : ['true', 'false'],\n)\n\n/** Default type when the schema is a tuple — picks the first non-null entry. */\nconst defaultType = computed((): string | undefined => {\n if (Array.isArray(type)) {\n return type.find((t) => t !== 'null') ?? 'string'\n }\n return type\n})\n\nconst handleSelectChange = (value: string): void =>\n emit('update:modelValue', value)\n\n// ───────────────────────────────────────────────────────────────────\n// Per-pill tooltip apps\n// ───────────────────────────────────────────────────────────────────\n\nlet pillTooltipApps: App[] = []\n\n/**\n * Per-pill tooltips are the heaviest part of the render (a Vue app +\n * `useTooltip` watch + listeners each), so we defer mounting them until\n * the first interaction (focus, pointerover, or dropdown open). Once on,\n * subsequent rebuilds remount tooltips for the new pills.\n */\nlet tooltipsActive = false\n\nconst teardownPillTooltips = (): void => {\n for (const app of pillTooltipApps) {\n app.unmount()\n }\n pillTooltipApps = []\n}\n\nconst mountPillTooltips = (): void => {\n if (!editorRef.value || layout === 'modal') {\n return\n }\n const pills = editorRef.value.querySelectorAll<HTMLElement>('.scalar-pill')\n for (const pillEl of pills) {\n const variableName = pillEl.dataset.variable ?? ''\n const context = buildPillContext(variableName, environment)\n const app = createApp(PillTooltipHost, { context, target: pillEl })\n // PillTooltipHost is renderless; useTooltip attaches to `target` directly.\n app.mount(document.createElement('div'))\n pillTooltipApps.push(app)\n }\n}\n\n// ───────────────────────────────────────────────────────────────────\n// DOM ↔ model conversion\n// ───────────────────────────────────────────────────────────────────\n\n/**\n * Build a pill `<span>` for the given variable. `contentEditable = 'false'`\n * makes the browser treat it as a single atom (arrow keys jump over it,\n * Backspace deletes it whole); `{{` / `}}` only live in the model string.\n */\nconst createPillElement = (\n name: string,\n start: number,\n end: number,\n): HTMLSpanElement => {\n const isCtx = isContextFunctionName(name)\n const span = document.createElement('span')\n span.className = isCtx ? 'scalar-pill scalar-pill--context-fn' : 'scalar-pill'\n span.contentEditable = 'false'\n span.dataset.variable = name\n // Model-coordinate offsets (the pill stands in for the full `{{name}}`).\n // Used by click forwarding and tests to map a pill back to the value.\n span.dataset.pillStart = String(start)\n span.dataset.pillEnd = String(end)\n\n const color = isCtx\n ? 'var(--scalar-color-3)'\n : environment?.color || 'var(--scalar-color-1)'\n span.style.setProperty('--tw-bg-base', color)\n\n // Fade env pills with no usable value. A falsy check (not just\n // `=== undefined`) matches the tooltip path's `Boolean(value)`, so a\n // variable declared with an empty string fades here too.\n const isUndefinedEnv = !isCtx && !lookupVariableValue(environment, name)\n if (isUndefinedEnv) {\n span.style.opacity = '0.5'\n }\n\n span.textContent = name\n return span\n}\n\n/** Render a model string into the editor as a mix of text nodes + pills. */\nconst renderModel = (text: string): void => {\n const editor = editorRef.value\n if (!editor) {\n return\n }\n\n teardownPillTooltips()\n editor.replaceChildren()\n\n if (!withVariables || !text.includes('{{')) {\n if (text) {\n editor.appendChild(document.createTextNode(text))\n }\n isEmpty.value = isBlankValue(text)\n return\n }\n\n const regex = new RegExp(REGEX.VARIABLES.source, REGEX.VARIABLES.flags)\n let lastIndex = 0\n let match: RegExpExecArray | null\n\n while ((match = regex.exec(text)) !== null) {\n const start = match.index\n const end = start + match[0].length\n if (start > lastIndex) {\n editor.appendChild(document.createTextNode(text.slice(lastIndex, start)))\n }\n editor.appendChild(createPillElement(match[1] ?? '', start, end))\n lastIndex = end\n }\n\n if (lastIndex < text.length) {\n editor.appendChild(document.createTextNode(text.slice(lastIndex)))\n }\n\n isEmpty.value = false\n if (tooltipsActive) {\n mountPillTooltips()\n }\n}\n\n/** Length the given child contributes to the serialized model string. */\nconst modelLengthOf = (node: Node): number => {\n if (node.nodeType === Node.TEXT_NODE) {\n return (node.textContent ?? '').length\n }\n if (node instanceof HTMLElement && node.classList.contains('scalar-pill')) {\n return `{{${node.dataset.variable ?? ''}}}`.length\n }\n // Defensive: a stray element (e.g. browser-inserted <br>) — use its text.\n return (node.textContent ?? '').length\n}\n\n/** Read the editor DOM back into a `{{name}}`-bearing model string. */\nconst serializeEditor = (): string => {\n const editor = editorRef.value\n if (!editor) {\n return ''\n }\n let out = ''\n for (const node of Array.from(editor.childNodes)) {\n if (node.nodeType === Node.TEXT_NODE) {\n out += node.textContent ?? ''\n } else if (\n node instanceof HTMLElement &&\n node.classList.contains('scalar-pill')\n ) {\n out += `{{${node.dataset.variable ?? ''}}}`\n } else if (node instanceof HTMLElement) {\n // Flatten any stray <br> / <div> the browser may inject on paste/Enter.\n out += node.textContent ?? ''\n }\n }\n return out\n}\n\nlet lastPillSignature: string | null = null\nlet lastEnvKey = ''\n\n/**\n * Cache key for the env + `withVariables` state. Includes variable\n * name/value pairs so the watcher notices adds/removes/edits even when\n * `environment.color` is unchanged — without that, pills keep stale\n * `isDefined` opacity and tooltip values until the input itself changes.\n */\nconst computeEnvKey = (): string => {\n const color = environment?.color ?? ''\n const flag = withVariables ? '1' : '0'\n const variables = environment?.variables ?? []\n let vars = ''\n for (const v of variables) {\n const value =\n typeof v.value === 'string' ? v.value : (v.value?.default ?? '')\n // Unit separators (\\x1f / \\x1e) so values can safely contain `|` or `=`.\n vars += `\\x1f${v.name}\\x1e${value}`\n }\n return `${color}|${flag}|${vars}`\n}\n\n/** Idempotent: first call flips `tooltipsActive` and mounts pill tooltips. */\nconst ensureTooltipsActive = (): void => {\n if (tooltipsActive) {\n return\n }\n tooltipsActive = true\n mountPillTooltips()\n}\n\n// ───────────────────────────────────────────────────────────────────\n// Caret ↔ model offset\n// ───────────────────────────────────────────────────────────────────\n\n/** Selection start as a model-string offset, or `null` if not inside the editor. */\nconst getModelCaret = (): number | null => {\n const editor = editorRef.value\n if (!editor) {\n return null\n }\n const selection = window.getSelection()\n if (!selection || selection.rangeCount === 0) {\n return null\n }\n const range = selection.getRangeAt(0)\n if (\n range.startContainer !== editor &&\n !editor.contains(range.startContainer)\n ) {\n return null\n }\n\n // Anchored on the editor itself: `startOffset` is a child index.\n if (range.startContainer === editor) {\n let pos = 0\n for (\n let i = 0;\n i < range.startOffset && i < editor.childNodes.length;\n i++\n ) {\n pos += modelLengthOf(editor.childNodes.item(i))\n }\n return pos\n }\n\n let pos = 0\n for (const child of Array.from(editor.childNodes)) {\n if (child === range.startContainer) {\n return pos + range.startOffset\n }\n // Pills are non-editable; if a browser quirk still lands a selection\n // inside one, snap to the nearest boundary instead of getting stuck.\n if (child.contains(range.startContainer)) {\n return range.startOffset === 0 ? pos : pos + modelLengthOf(child)\n }\n pos += modelLengthOf(child)\n }\n return pos\n}\n\n/** Place the caret at the given model offset, walking the DOM to find it. */\nconst setModelCaret = (target: number): void => {\n const editor = editorRef.value\n if (!editor) {\n return\n }\n const range = document.createRange()\n let pos = 0\n let placed = false\n\n for (const child of Array.from(editor.childNodes)) {\n const len = modelLengthOf(child)\n if (pos + len >= target) {\n if (child.nodeType === Node.TEXT_NODE) {\n const into = Math.max(\n 0,\n Math.min(target - pos, (child.textContent ?? '').length),\n )\n range.setStart(child, into)\n } else if (target - pos <= 0) {\n range.setStartBefore(child)\n } else {\n range.setStartAfter(child)\n }\n placed = true\n break\n }\n pos += len\n }\n\n if (!placed) {\n range.selectNodeContents(editor)\n range.collapse(false)\n } else {\n range.collapse(true)\n }\n\n const selection = window.getSelection()\n if (!selection) {\n return\n }\n selection.removeAllRanges()\n selection.addRange(range)\n}\n\n// ───────────────────────────────────────────────────────────────────\n// Environment variable dropdown\n// ───────────────────────────────────────────────────────────────────\n\nconst showDropdown = ref(false)\nconst dropdownQuery = ref('')\nconst dropdownPosition = ref({ left: 0, top: 0 })\n\nconst contextFunctionDropdownItems = computed(() =>\n withFakeData\n ? CONTEXT_FUNCTION_NAMES.map((key) => ({\n key,\n description: getContextFunctionComment(key as ContextFunctionName),\n }))\n : [],\n)\n\nconst displayVariablesDropdown = computed(\n (): boolean =>\n showDropdown.value &&\n withVariables &&\n layout !== 'modal' &&\n (Boolean(environment) || withFakeData),\n)\n\nconst updateDropdownVisibility = (): void => {\n const editor = editorRef.value\n if (!editor) {\n return\n }\n const caret = getModelCaret()\n if (caret === null) {\n showDropdown.value = false\n return\n }\n const text = serializeEditor().slice(0, caret)\n const lastOpen = text.lastIndexOf('{{')\n const lastClose = text.lastIndexOf('}}')\n\n if (lastOpen <= lastClose) {\n showDropdown.value = false\n return\n }\n\n dropdownQuery.value = text.slice(lastOpen + 2)\n // Make sure the combobox has an id before it advertises `aria-expanded`, so\n // `aria-controls` always resolves to the listbox we are about to render.\n ensureComponentId()\n showDropdown.value = true\n\n // Anchor under the caret; `getBoundingClientRect` gives the caret rect in one read.\n nextTick(() => {\n const selection = window.getSelection()\n if (!selection || selection.rangeCount === 0 || !editorRef.value) {\n return\n }\n const r = selection.getRangeAt(0).cloneRange()\n r.collapse(true)\n const rect = r.getBoundingClientRect()\n const editorRect = editorRef.value.getBoundingClientRect()\n // Some browsers collapse empty ranges to a zero rect — fall back to the editor edge.\n dropdownPosition.value = {\n left: rect.left || editorRect.left,\n top: rect.bottom || editorRect.bottom,\n }\n })\n}\n\nconst handleDropdownSelect = (item: string): void => {\n if (readOnly) {\n return\n }\n const caret = getModelCaret() ?? 0\n const value = serializeEditor()\n const from = Math.max(0, caret - dropdownQuery.value.length - 2)\n const to = caret\n const next = `${value.slice(0, from)}{{${item}}}${value.slice(to)}`\n const nextCursor = from + `{{${item}}}`.length\n\n // Pill set changed — force a re-render and reposition the caret.\n lastPillSignature = pillSignature(next, withVariables)\n renderModel(next)\n setModelCaret(nextCursor)\n\n showDropdown.value = false\n emitChange(next, { skipDropdownCheck: true })\n}\n\n// ───────────────────────────────────────────────────────────────────\n// Change / focus / blur\n// ───────────────────────────────────────────────────────────────────\n\nconst emitChange = (\n value: string,\n opts: { skipDropdownCheck?: boolean } = {},\n): void => {\n const same = value === serializeValue(modelValue)\n if (alwaysEmitChange || !same) {\n emit('update:modelValue', value)\n }\n if (!opts.skipDropdownCheck) {\n updateDropdownVisibility()\n }\n}\n\nconst handleInput = (): void => {\n const text = serializeEditor()\n isEmpty.value = isBlankValue(text)\n\n // Only rebuild when the pill set changes (e.g. `}}` closed a pattern, or\n // a value was pasted). Skipping it for plain-text edits preserves the\n // live selection — important for IME composition and double-click select.\n // Also defer while composing; `handleCompositionEnd` re-runs this path so the\n // rebuild happens once the IME has committed its text.\n const sig = pillSignature(text, withVariables)\n if (!isComposing.value && sig !== lastPillSignature) {\n const caret = getModelCaret()\n lastPillSignature = sig\n renderModel(text)\n if (caret !== null) {\n setModelCaret(caret)\n }\n }\n\n emitChange(text)\n}\n\nconst handleCompositionStart = (): void => {\n isComposing.value = true\n}\n\nconst handleCompositionEnd = (): void => {\n isComposing.value = false\n // Run the deferred input path now that the composition has committed, so any\n // pill that formed during composition is rendered.\n handleInput()\n}\n\nconst handleFocus = (): void => {\n isFocused.value = true\n ensureComponentId()\n ensureTooltipsActive()\n}\n\nconst handleBlur = (event: FocusEvent): void => {\n isFocused.value = false\n showDropdown.value = false\n const value = serializeEditor()\n // Check the serialized `value`, not `modelValue` — a `0` or `false` model is\n // a valid non-empty entry that should still submit on blur.\n if (emitOnBlur && value) {\n emit('submit', value, event)\n }\n emit('blur', value, event)\n}\n\n/**\n * Strip rich content on paste; `contenteditable=\"plaintext-only\"` is not\n * reliable cross-browser, so we intercept and use `insertText` to keep undo.\n */\nconst handlePaste = (event: ClipboardEvent): void => {\n event.preventDefault()\n const text = event.clipboardData?.getData('text/plain') ?? ''\n if (!text) {\n return\n }\n document.execCommand('insertText', false, text.replace(/\\r?\\n/g, ' '))\n // `insertText` normally fires an `input` event, but that is not guaranteed\n // across browsers. Run the same path explicitly so pill rendering, emptiness,\n // `update:modelValue`, and the dropdown never lag behind the pasted DOM.\n handleInput()\n}\n\n// ───────────────────────────────────────────────────────────────────\n// Keyboard handling\n// ───────────────────────────────────────────────────────────────────\n\nconst handleKeyDown = (event: KeyboardEvent): void => {\n if (showDropdown.value) {\n if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {\n event.preventDefault()\n event.stopPropagation()\n dropdownRef.value?.handleArrowKey(\n event.key === 'ArrowDown' ? 'down' : 'up',\n )\n return\n }\n if (event.key === 'Enter') {\n event.preventDefault()\n event.stopPropagation()\n dropdownRef.value?.handleSelect()\n return\n }\n if (event.key === 'Escape') {\n event.preventDefault()\n event.stopPropagation()\n showDropdown.value = false\n return\n }\n }\n\n if (event.key === 'Enter') {\n // Block the browser default so a contenteditable div does not insert\n // <br> / <div> and break single-line semantics, then emit submit\n // (used by the table editors).\n event.preventDefault()\n emit('submit', serializeEditor(), event)\n return\n }\n\n // Backspace / Delete: pill atomicity is handled by the browser via\n // `contenteditable=\"false\"` on pills — no manual `}}`-pair handling needed.\n}\n\n// ───────────────────────────────────────────────────────────────────\n// Click forwarding & lifecycle\n// ───────────────────────────────────────────────────────────────────\n\n/**\n * Clicking a pill selects it whole, so a subsequent Backspace deletes it\n * in one keystroke and typing replaces it — the usual chip/mention model.\n */\nconst handleEditorClick = (event: MouseEvent): void => {\n const target =\n event.target instanceof Element\n ? event.target.closest<HTMLElement>('.scalar-pill')\n : null\n if (!target) {\n return\n }\n const editor = editorRef.value\n if (!editor) {\n return\n }\n editor.focus()\n const range = document.createRange()\n range.selectNode(target)\n const selection = window.getSelection()\n selection?.removeAllRanges()\n selection?.addRange(range)\n updateDropdownVisibility()\n}\n\nonMounted(() => {\n const initial = serializeValue(modelValue)\n lastPillSignature = pillSignature(initial, withVariables)\n lastEnvKey = computeEnvKey()\n renderModel(initial)\n isEmpty.value = isBlankValue(initial)\n\n // `autofocus` on a contenteditable div is not honoured natively, so focus\n // the editor ourselves when the consumer passes the attribute.\n if (Object.hasOwn(attrs, 'autofocus')) {\n editorRef.value?.focus()\n }\n})\n\nwatch(\n () => modelValue,\n (next) => {\n const serialized = serializeValue(next)\n // Always sync the placeholder flag, even when the DOM already matches and we\n // skip the rebuild below. Otherwise a value cell that switches from select\n // mode (no editor element) into the empty editor keeps a stale `isEmpty`,\n // and the placeholder silently disappears.\n isEmpty.value = isBlankValue(serialized)\n if (serializeEditor() === serialized) {\n return\n }\n lastPillSignature = pillSignature(serialized, withVariables)\n renderModel(serialized)\n },\n)\n\n// The editable surface only exists in \"editor mode\" (see template). When a row switches into editor\n// mode after mount — most notably when this component instance is reused for a different table row —\n// `onMounted` has already run and the `modelValue` watch fired while `editorRef` was still null, so\n// the model was never painted into the freshly created element and the cell renders empty.\n//\n// Paint the model when the element appears, but only into a still-empty editor: an editor that\n// already holds text is either up to date or ahead of `modelValue` with an uncommitted edit/paste,\n// and must not be clobbered.\n//\n// `flush: 'sync'` makes the paint part of the same step that creates the element. Vue assigns a\n// non-null template ref from a post-render effect, so the element is already mounted and patched\n// when this runs — deferring any further (the `pre` default, or `post`) only pushes the paint past\n// the consumer effects that run later in the same flush. A parent that focuses the cell as it\n// switches into editor mode would then place the caret in a still-empty editor, and the paint's\n// `replaceChildren` would drop that selection.\nwatch(\n editorRef,\n (editor) => {\n if (!editor || !isBlankValue(serializeEditor())) {\n return\n }\n const serialized = serializeValue(modelValue)\n if (serialized === '') {\n return\n }\n lastPillSignature = pillSignature(serialized, withVariables)\n renderModel(serialized)\n },\n { flush: 'sync' },\n)\n\nwatch(\n [() => environment, () => withVariables],\n () => {\n // Env changes affect pill colour and `isDefined` opacity — rebuild.\n const envKey = computeEnvKey()\n if (envKey === lastEnvKey) {\n return\n }\n lastEnvKey = envKey\n // Most rows are plain text; skip the DOM walk when there are no pills.\n // Pills introduced later flow through `handleInput` / the modelValue\n // watcher, which update `lastPillSignature`.\n if (lastPillSignature === '') {\n return\n }\n lastPillSignature = pillSignature(serializeEditor(), withVariables)\n // Preserve the caret across the rebuild so editing does not jump to the\n // start when the environment changes mid-edit (mirrors `handleInput`).\n const caret = getModelCaret()\n renderModel(serializeEditor())\n if (caret !== null) {\n setModelCaret(caret)\n }\n },\n // Variables are often mutated in place (e.g. editing a value in the env\n // editor) without the object reference changing — deep watch catches it.\n { deep: true },\n)\n\nonBeforeUnmount(() => {\n teardownPillTooltips()\n})\n\n// ───────────────────────────────────────────────────────────────────\n// Public API\n// ───────────────────────────────────────────────────────────────────\n\ndefineExpose({\n /** Focus the editor. `position` controls caret placement. */\n focus: (position?: 'start' | 'end' | number): void => {\n const editor = editorRef.value\n if (!editor) {\n return\n }\n editor.focus()\n if (!isDefined(position)) {\n return\n }\n const length = serializeEditor().length\n const pos =\n position === 'start' ? 0 : position === 'end' ? length : position\n setModelCaret(pos)\n },\n /** Replace the current value programmatically and re-render the pills. */\n setContent: (next = ''): void => {\n if (serializeEditor() === next) {\n return\n }\n lastPillSignature = pillSignature(next, withVariables)\n renderModel(next)\n isEmpty.value = isBlankValue(next)\n },\n /** Read the current value as a `{{name}}`-bearing string. */\n getValue: (): string => serializeEditor(),\n /** Caret offset in the model string. */\n cursorPosition: (): number | undefined => {\n const c = getModelCaret()\n return c === null ? undefined : c\n },\n isFocused,\n editorRef,\n})\n</script>\n\n<template>\n <!-- Disabled mode: read-only label -->\n <div\n v-if=\"disabled\"\n class=\"text-c-2 flex cursor-default items-center justify-center\"\n :class=\"{\n 'font-code pr-2 pl-1 text-base': layout === 'modal',\n 'px-2': layout !== 'modal',\n 'line-through': linethrough,\n }\"\n data-testid=\"code-input-lite-disabled\">\n <span class=\"whitespace-nowrap\">{{ modelValue }}</span>\n </div>\n\n <!-- Enum mode: select dropdown with predefined values -->\n <DataTableInputSelect\n v-else-if=\"enumProp?.length\"\n :default=\"defaultProp\"\n :modelValue=\"modelValue\"\n :type=\"defaultType\"\n :value=\"enumProp\"\n @update:modelValue=\"handleSelectChange\" />\n\n <!-- Boolean mode: select dropdown with true/false (and optionally null) -->\n <DataTableInputSelect\n v-else-if=\"isBooleanMode\"\n :default=\"defaultProp\"\n :modelValue=\"modelValue\"\n :value=\"booleanOptions\"\n @update:modelValue=\"handleSelectChange\" />\n\n <!-- Examples mode: select dropdown with example values -->\n <DataTableInputSelect\n v-else-if=\"examples?.length\"\n :default=\"defaultProp\"\n :modelValue=\"modelValue\"\n :value=\"examples\"\n @update:modelValue=\"handleSelectChange\" />\n\n <!-- Editor mode -->\n <div\n v-else\n :id=\"componentId\"\n v-bind=\"$attrs\"\n class=\"code-input-lite group/code-input-lite peer relative w-full leading-[1.44] -outline-offset-1 has-[:focus-visible]:rounded-[4px] has-[:focus-visible]:outline\"\n :class=\"{\n 'code-input-lite--error': error,\n 'code-input-lite--empty': isEmpty,\n 'line-through': linethrough,\n }\">\n <!-- The single editable surface; see the file header for how pills work. -->\n <div\n ref=\"editorRef\"\n :aria-activedescendant=\"\n displayVariablesDropdown ? activeOptionId : undefined\n \"\n :aria-autocomplete=\"withVariables ? 'list' : undefined\"\n :aria-controls=\"displayVariablesDropdown ? listboxId : undefined\"\n :aria-expanded=\"displayVariablesDropdown ? 'true' : undefined\"\n :aria-invalid=\"error ? 'true' : undefined\"\n :aria-label=\"ariaLabel\"\n :aria-readonly=\"readOnly ? 'true' : undefined\"\n :aria-required=\"required ? 'true' : undefined\"\n class=\"code-input-lite__editor\"\n :contenteditable=\"readOnly ? 'false' : 'true'\"\n :data-placeholder=\"placeholder\"\n :role=\"withVariables ? 'combobox' : 'textbox'\"\n spellcheck=\"false\"\n @blur=\"handleBlur\"\n @click=\"handleEditorClick\"\n @compositionend=\"handleCompositionEnd\"\n @compositionstart=\"handleCompositionStart\"\n @focus=\"handleFocus\"\n @input=\"handleInput\"\n @keydown=\"handleKeyDown\"\n @paste=\"handlePaste\"\n @pointerover=\"ensureTooltipsActive\" />\n </div>\n\n <!--\n Slots and the required indicator are siblings of the mode templates so\n they render in every mode and so `absolute right-0` anchors to the\n surrounding (relative) cell rather than the shrink-wrapped mode wrapper.\n -->\n <div\n v-if=\"$slots.warning\"\n class=\"centered-y text-orange absolute right-7 text-xs\">\n <slot name=\"warning\" />\n </div>\n <div\n v-if=\"$slots.icon\"\n class=\"centered-y absolute right-0 flex h-full items-center p-1.5 group-has-[.code-input-lite__editor:focus]:z-1\">\n <slot name=\"icon\" />\n </div>\n <div\n v-if=\"required\"\n class=\"required centered-y text-xxs text-c-3 group-[.error]:text-red bg-b-1 pointer-events-none absolute right-0 mr-0.5 pt-px pr-2 opacity-100 shadow-[-8px_0_4px_var(--scalar-background-1)] transition-opacity duration-150 peer-has-[.code-input-lite__editor:focus]:opacity-0\">\n Required\n </div>\n\n <EnvironmentVariableDropdown\n v-if=\"displayVariablesDropdown\"\n ref=\"dropdownRef\"\n :contextFunctionItems=\"contextFunctionDropdownItems\"\n :dropdownPosition=\"dropdownPosition\"\n :environment=\"environment\"\n :listboxId=\"listboxId\"\n :query=\"dropdownQuery\"\n @close=\"showDropdown = false\"\n @redirect=\"emit('navigate', { page: 'document', path: 'environment' })\"\n @select=\"handleDropdownSelect\" />\n</template>\n\n<style scoped>\n.code-input-lite {\n /* Flex so the editor centres vertically in whatever height the cell gives us.\n Font properties inherit so we adopt the surrounding typography. */\n display: flex;\n align-items: center;\n}\n\n.code-input-lite__editor {\n /* Everything font-related inherits from the surrounding context. */\n font: inherit;\n letter-spacing: inherit;\n flex: 1;\n min-width: 0;\n background: transparent;\n outline: none;\n color: var(--scalar-color-1);\n caret-color: var(--scalar-color-1);\n /* Single-line: horizontal scroll keeps the caret visible for long values;\n the scrollbar itself is hidden (would be noisy inside a table cell). */\n white-space: pre;\n overflow-x: auto;\n overflow-y: hidden;\n scrollbar-width: none;\n padding: 0 0.5em;\n box-sizing: border-box;\n line-height: 1.44;\n /* Positioning context for the absolutely positioned placeholder. */\n position: relative;\n}\n\n.code-input-lite__editor::-webkit-scrollbar {\n display: none;\n}\n\n/* Absolute so the placeholder does not occupy flow space inside the\n contenteditable; otherwise the caret would land after it on focus.\n `pointer-events: none` lets clicks fall through to focus the editor.\n Hidden on focus so it never renders on top of the text caret. */\n.code-input-lite--empty .code-input-lite__editor:not(:focus)::before {\n content: attr(data-placeholder);\n color: var(--scalar-color-3);\n pointer-events: none;\n position: absolute;\n top: 0;\n bottom: 0;\n left: 0.5em;\n display: flex;\n align-items: center;\n}\n\n.code-input-lite--error .code-input-lite__editor {\n outline: 1px solid var(--scalar-color-red);\n}\n</style>\n\n<style>\n/* Pill styling. Each pill is `<span contenteditable=\"false\">name</span>` —\n an atomic widget; the caret lands before or after it, never inside. */\n.scalar-pill {\n color: var(--scalar-color-2);\n border-radius: var(--scalar-radius-full);\n display: inline-block;\n font-family: var(--scalar-font-code);\n font-size: 0.9em;\n line-height: 1.4;\n vertical-align: baseline;\n background: var(--scalar-background-3);\n padding: 0.125em 0.6em;\n margin-right: 0.35em;\n cursor: text;\n /* Single click selects the whole pill — chip/mention model, deletes in one go. */\n user-select: all;\n -webkit-user-select: all;\n}\n\n.dark-mode .scalar-pill {\n background: color-mix(\n in srgb,\n var(--tw-bg-base, var(--scalar-color-1)),\n transparent 90%\n );\n}\n\n.light-mode .scalar-pill {\n background: var(--scalar-background-3);\n}\n\n.scalar-pill--context-fn {\n /* Inset box-shadow as a border so the layout box stays identical to plain pills. */\n box-shadow: 0 0 0 1px\n color-mix(in srgb, var(--scalar-color-3), transparent 35%) inset;\n}\n\n.dark-mode .scalar-pill--context-fn {\n background: color-mix(in srgb, var(--scalar-background-3), transparent 55%);\n}\n\n.light-mode .scalar-pill--context-fn {\n background: color-mix(in srgb, var(--scalar-background-3), transparent 40%);\n}\n</style>\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"CodeInputLite.vue.js","names":[],"sources":["../../../../src/v2/components/code-input/CodeInputLite.vue"],"sourcesContent":["<script lang=\"ts\">\n/**\n * CodeInputLite\n *\n * Single-line `contenteditable` editor that renders `{{varname}}` as atomic\n * pill spans (`contenteditable=\"false\"`) and offers an env-variable\n * autocomplete on `{{`. The value is still exposed as a `{{name}}`-bearing\n * string via `update:modelValue`; DOM ↔ model conversion lives in\n * `renderModel` and `serializeEditor`.\n */\nexport default {\n inheritAttrs: false,\n}\n</script>\n\n<script setup lang=\"ts\">\nimport { isDefined } from '@scalar/helpers/array/is-defined'\nimport { REGEX } from '@scalar/helpers/regex/regex-helpers'\nimport {\n CONTEXT_FUNCTION_NAMES,\n getContextFunctionComment,\n isContextFunctionName,\n type ContextFunctionName,\n} from '@scalar/workspace-store/request-example'\nimport type { XScalarEnvironment } from '@scalar/workspace-store/schemas/extensions/document/x-scalar-environments'\nimport { nanoid } from 'nanoid'\nimport {\n computed,\n createApp,\n nextTick,\n onBeforeUnmount,\n onMounted,\n ref,\n useAttrs,\n useTemplateRef,\n watch,\n type App,\n} from 'vue'\n\nimport DataTableInputSelect from '@/v2/components/data-table/DataTableInputSelect.vue'\nimport EnvironmentVariableDropdown from '@/v2/features/environments/components/EnvironmentVariablesDropdown.vue'\nimport { useLocalization } from '@/v2/features/localization'\nimport type { ClientLayout } from '@/v2/types/layout'\n\nimport type { CodeInputModelValue } from './CodeInput.vue'\nimport { buildPillContext } from './helpers/build-pill-context'\nimport { lookupVariableValue } from './helpers/lookup-variable-value'\nimport { pillSignature } from './helpers/pill-signature'\nimport { serializeValue } from './helpers/serialize-value'\nimport PillTooltipHost from './PillTooltipHost.vue'\n\nconst {\n modelValue,\n environment,\n disabled = false,\n readOnly = false,\n error = false,\n layout = 'desktop',\n placeholder,\n required = false,\n emitOnBlur = true,\n alwaysEmitChange = false,\n withVariables = true,\n withFakeData = false,\n linethrough = false,\n type,\n enum: enumProp,\n examples,\n default: defaultProp,\n nullable = false,\n} = defineProps<Props>()\n\nconst emit = defineEmits<{\n 'update:modelValue': [value: string]\n 'submit': [value: string, event: KeyboardEvent | FocusEvent]\n 'blur': [value: string, event: FocusEvent]\n 'navigate': [route: { page: 'document'; path: 'environment' }]\n}>()\n\nconst { translate } = useLocalization()\n\ntype Props = {\n modelValue: CodeInputModelValue\n /** Environment for variable substitution. Pass undefined to disable env vars */\n environment: XScalarEnvironment | undefined\n /** Render as a non-interactive read-only label */\n disabled?: boolean\n /** Render the input with the native `readonly` attribute (still focusable, no edits) */\n readOnly?: boolean\n /** Show error styling */\n error?: boolean\n /** Layout context affects styling and dropdown visibility */\n layout?: ClientLayout\n /** Placeholder text for an empty input */\n placeholder?: string\n /** Show required indicator */\n required?: boolean\n /** Emit submit on blur */\n emitOnBlur?: boolean\n /** Render variable pills + show the autocomplete dropdown */\n withVariables?: boolean\n /** Include `{{$guid}}` etc. in the autocomplete dropdown */\n withFakeData?: boolean\n /** Always emit change events even if the value is unchanged */\n alwaysEmitChange?: boolean\n /** Strike-through styling for the input text (e.g. overridden values) */\n linethrough?: boolean\n /** Schema type — drives boolean select mode when `boolean` is included */\n type?: string | string[]\n /** Predefined enum values; when set the input is replaced by a select */\n enum?: string[]\n /** Example values; when set (and no enum/boolean) the input is replaced by a select */\n examples?: string[]\n /** Default value to suggest in select modes */\n default?: CodeInputModelValue\n /** Whether the boolean select includes a `null` option */\n nullable?: boolean\n}\n\nconst attrs = useAttrs()\nconst ariaLabel = computed(() =>\n typeof attrs['aria-label'] === 'string' ? attrs['aria-label'] : undefined,\n)\n\n/**\n * The id only matters once the dropdown opens (`aria-controls` /\n * `aria-activedescendant`), so we defer `nanoid()` until first focus to\n * keep idle instances cheap. A consumer-supplied `id` attr is preserved.\n */\nconst generatedComponentId = ref<string | null>(null)\nconst componentId = computed((): string | undefined =>\n typeof attrs.id === 'string'\n ? attrs.id\n : (generatedComponentId.value ?? undefined),\n)\nconst ensureComponentId = (): void => {\n if (\n (typeof attrs.id !== 'string' || !attrs.id) &&\n generatedComponentId.value === null\n ) {\n generatedComponentId.value = `id-${nanoid()}`\n }\n}\n\nconst editorRef = useTemplateRef<HTMLDivElement>('editorRef')\nconst dropdownRef = ref<InstanceType<\n typeof EnvironmentVariableDropdown\n> | null>(null)\n\n/** Id of the dropdown's `role=\"listbox\"` element, for the combobox wiring. */\nconst listboxId = computed((): string | undefined =>\n componentId.value ? `${componentId.value}-listbox` : undefined,\n)\n\n/**\n * Id of the option the dropdown currently highlights. Mirrors the dropdown's\n * own selection so the editor can expose it via `aria-activedescendant`.\n */\nconst activeOptionId = computed(\n (): string | undefined => dropdownRef.value?.activeOptionId,\n)\n\nconst isFocused = ref(false)\nconst isEmpty = ref(true)\n\n/**\n * True while an IME composition is in progress. Rebuilding the editor DOM\n * mid-composition (e.g. when `{{` forms a pill) cancels the composition, so we\n * defer those rebuilds until `compositionend`.\n */\nconst isComposing = ref(false)\n\n/**\n * Whether the serialized value should count as empty for placeholder display.\n *\n * `contenteditable` can leave behind invisible residue after some delete\n * sequences — most commonly a non-breaking space (`\\u00a0`) — which makes a\n * visually empty field report a non-zero length and silently drop its\n * placeholder. Trimming covers that case; `\\u00a0` counts as whitespace, so a\n * field that only holds editor residue is treated as empty. This affects the\n * placeholder flag only, never the value emitted via `serializeEditor`.\n */\nconst isBlankValue = (text: string): boolean => text.trim().length === 0\n\n// ───────────────────────────────────────────────────────────────────\n// Rendering-mode detection (parity with CodeInput's select dispatch)\n// ───────────────────────────────────────────────────────────────────\n\n/** True when the schema type is exactly `boolean` (or includes it in a tuple type). */\nconst isBooleanMode = computed((): boolean => {\n if (enumProp?.length) {\n return false\n }\n return type === 'boolean' || (Array.isArray(type) && type.includes('boolean'))\n})\n\nconst booleanOptions = computed((): string[] =>\n nullable ? ['true', 'false', 'null'] : ['true', 'false'],\n)\n\n/** Default type when the schema is a tuple — picks the first non-null entry. */\nconst defaultType = computed((): string | undefined => {\n if (Array.isArray(type)) {\n return type.find((t) => t !== 'null') ?? 'string'\n }\n return type\n})\n\nconst handleSelectChange = (value: string): void =>\n emit('update:modelValue', value)\n\n// ───────────────────────────────────────────────────────────────────\n// Per-pill tooltip apps\n// ───────────────────────────────────────────────────────────────────\n\nlet pillTooltipApps: App[] = []\n\n/**\n * Per-pill tooltips are the heaviest part of the render (a Vue app +\n * `useTooltip` watch + listeners each), so we defer mounting them until\n * the first interaction (focus, pointerover, or dropdown open). Once on,\n * subsequent rebuilds remount tooltips for the new pills.\n */\nlet tooltipsActive = false\n\nconst teardownPillTooltips = (): void => {\n for (const app of pillTooltipApps) {\n app.unmount()\n }\n pillTooltipApps = []\n}\n\nconst mountPillTooltips = (): void => {\n if (!editorRef.value || layout === 'modal') {\n return\n }\n const pills = editorRef.value.querySelectorAll<HTMLElement>('.scalar-pill')\n for (const pillEl of pills) {\n const variableName = pillEl.dataset.variable ?? ''\n const context = buildPillContext(variableName, environment)\n const app = createApp(PillTooltipHost, {\n context,\n target: pillEl,\n translate,\n })\n // PillTooltipHost is renderless; useTooltip attaches to `target` directly.\n app.mount(document.createElement('div'))\n pillTooltipApps.push(app)\n }\n}\n\n// ───────────────────────────────────────────────────────────────────\n// DOM ↔ model conversion\n// ───────────────────────────────────────────────────────────────────\n\n/**\n * Build a pill `<span>` for the given variable. `contentEditable = 'false'`\n * makes the browser treat it as a single atom (arrow keys jump over it,\n * Backspace deletes it whole); `{{` / `}}` only live in the model string.\n */\nconst createPillElement = (\n name: string,\n start: number,\n end: number,\n): HTMLSpanElement => {\n const isCtx = isContextFunctionName(name)\n const span = document.createElement('span')\n span.className = isCtx ? 'scalar-pill scalar-pill--context-fn' : 'scalar-pill'\n span.contentEditable = 'false'\n span.dataset.variable = name\n // Model-coordinate offsets (the pill stands in for the full `{{name}}`).\n // Used by click forwarding and tests to map a pill back to the value.\n span.dataset.pillStart = String(start)\n span.dataset.pillEnd = String(end)\n\n const color = isCtx\n ? 'var(--scalar-color-3)'\n : environment?.color || 'var(--scalar-color-1)'\n span.style.setProperty('--tw-bg-base', color)\n\n // Fade env pills with no usable value. A falsy check (not just\n // `=== undefined`) matches the tooltip path's `Boolean(value)`, so a\n // variable declared with an empty string fades here too.\n const isUndefinedEnv = !isCtx && !lookupVariableValue(environment, name)\n if (isUndefinedEnv) {\n span.style.opacity = '0.5'\n }\n\n span.textContent = name\n return span\n}\n\n/** Render a model string into the editor as a mix of text nodes + pills. */\nconst renderModel = (text: string): void => {\n const editor = editorRef.value\n if (!editor) {\n return\n }\n\n teardownPillTooltips()\n editor.replaceChildren()\n\n if (!withVariables || !text.includes('{{')) {\n if (text) {\n editor.appendChild(document.createTextNode(text))\n }\n isEmpty.value = isBlankValue(text)\n return\n }\n\n const regex = new RegExp(REGEX.VARIABLES.source, REGEX.VARIABLES.flags)\n let lastIndex = 0\n let match: RegExpExecArray | null\n\n while ((match = regex.exec(text)) !== null) {\n const start = match.index\n const end = start + match[0].length\n if (start > lastIndex) {\n editor.appendChild(document.createTextNode(text.slice(lastIndex, start)))\n }\n editor.appendChild(createPillElement(match[1] ?? '', start, end))\n lastIndex = end\n }\n\n if (lastIndex < text.length) {\n editor.appendChild(document.createTextNode(text.slice(lastIndex)))\n }\n\n isEmpty.value = false\n if (tooltipsActive) {\n mountPillTooltips()\n }\n}\n\n/** Length the given child contributes to the serialized model string. */\nconst modelLengthOf = (node: Node): number => {\n if (node.nodeType === Node.TEXT_NODE) {\n return (node.textContent ?? '').length\n }\n if (node instanceof HTMLElement && node.classList.contains('scalar-pill')) {\n return `{{${node.dataset.variable ?? ''}}}`.length\n }\n // Defensive: a stray element (e.g. browser-inserted <br>) — use its text.\n return (node.textContent ?? '').length\n}\n\n/** Read the editor DOM back into a `{{name}}`-bearing model string. */\nconst serializeEditor = (): string => {\n const editor = editorRef.value\n if (!editor) {\n return ''\n }\n let out = ''\n for (const node of Array.from(editor.childNodes)) {\n if (node.nodeType === Node.TEXT_NODE) {\n out += node.textContent ?? ''\n } else if (\n node instanceof HTMLElement &&\n node.classList.contains('scalar-pill')\n ) {\n out += `{{${node.dataset.variable ?? ''}}}`\n } else if (node instanceof HTMLElement) {\n // Flatten any stray <br> / <div> the browser may inject on paste/Enter.\n out += node.textContent ?? ''\n }\n }\n return out\n}\n\nlet lastPillSignature: string | null = null\nlet lastEnvKey = ''\n\n/**\n * Cache key for the env + `withVariables` state. Includes variable\n * name/value pairs so the watcher notices adds/removes/edits even when\n * `environment.color` is unchanged — without that, pills keep stale\n * `isDefined` opacity and tooltip values until the input itself changes.\n */\nconst computeEnvKey = (): string => {\n const color = environment?.color ?? ''\n const flag = withVariables ? '1' : '0'\n const variables = environment?.variables ?? []\n let vars = ''\n for (const v of variables) {\n const value =\n typeof v.value === 'string' ? v.value : (v.value?.default ?? '')\n // Unit separators (\\x1f / \\x1e) so values can safely contain `|` or `=`.\n vars += `\\x1f${v.name}\\x1e${value}`\n }\n return `${color}|${flag}|${vars}`\n}\n\n/** Idempotent: first call flips `tooltipsActive` and mounts pill tooltips. */\nconst ensureTooltipsActive = (): void => {\n if (tooltipsActive) {\n return\n }\n tooltipsActive = true\n mountPillTooltips()\n}\n\n// ───────────────────────────────────────────────────────────────────\n// Caret ↔ model offset\n// ───────────────────────────────────────────────────────────────────\n\n/** Selection start as a model-string offset, or `null` if not inside the editor. */\nconst getModelCaret = (): number | null => {\n const editor = editorRef.value\n if (!editor) {\n return null\n }\n const selection = window.getSelection()\n if (!selection || selection.rangeCount === 0) {\n return null\n }\n const range = selection.getRangeAt(0)\n if (\n range.startContainer !== editor &&\n !editor.contains(range.startContainer)\n ) {\n return null\n }\n\n // Anchored on the editor itself: `startOffset` is a child index.\n if (range.startContainer === editor) {\n let pos = 0\n for (\n let i = 0;\n i < range.startOffset && i < editor.childNodes.length;\n i++\n ) {\n pos += modelLengthOf(editor.childNodes.item(i))\n }\n return pos\n }\n\n let pos = 0\n for (const child of Array.from(editor.childNodes)) {\n if (child === range.startContainer) {\n return pos + range.startOffset\n }\n // Pills are non-editable; if a browser quirk still lands a selection\n // inside one, snap to the nearest boundary instead of getting stuck.\n if (child.contains(range.startContainer)) {\n return range.startOffset === 0 ? pos : pos + modelLengthOf(child)\n }\n pos += modelLengthOf(child)\n }\n return pos\n}\n\n/** Place the caret at the given model offset, walking the DOM to find it. */\nconst setModelCaret = (target: number): void => {\n const editor = editorRef.value\n if (!editor) {\n return\n }\n const range = document.createRange()\n let pos = 0\n let placed = false\n\n for (const child of Array.from(editor.childNodes)) {\n const len = modelLengthOf(child)\n if (pos + len >= target) {\n if (child.nodeType === Node.TEXT_NODE) {\n const into = Math.max(\n 0,\n Math.min(target - pos, (child.textContent ?? '').length),\n )\n range.setStart(child, into)\n } else if (target - pos <= 0) {\n range.setStartBefore(child)\n } else {\n range.setStartAfter(child)\n }\n placed = true\n break\n }\n pos += len\n }\n\n if (!placed) {\n range.selectNodeContents(editor)\n range.collapse(false)\n } else {\n range.collapse(true)\n }\n\n const selection = window.getSelection()\n if (!selection) {\n return\n }\n selection.removeAllRanges()\n selection.addRange(range)\n}\n\n// ───────────────────────────────────────────────────────────────────\n// Environment variable dropdown\n// ───────────────────────────────────────────────────────────────────\n\nconst showDropdown = ref(false)\nconst dropdownQuery = ref('')\nconst dropdownPosition = ref({ left: 0, top: 0 })\n\nconst contextFunctionDropdownItems = computed(() =>\n withFakeData\n ? CONTEXT_FUNCTION_NAMES.map((key) => ({\n key,\n description: getContextFunctionComment(key as ContextFunctionName),\n }))\n : [],\n)\n\nconst displayVariablesDropdown = computed(\n (): boolean =>\n showDropdown.value &&\n withVariables &&\n layout !== 'modal' &&\n (Boolean(environment) || withFakeData),\n)\n\nconst updateDropdownVisibility = (): void => {\n const editor = editorRef.value\n if (!editor) {\n return\n }\n const caret = getModelCaret()\n if (caret === null) {\n showDropdown.value = false\n return\n }\n const text = serializeEditor().slice(0, caret)\n const lastOpen = text.lastIndexOf('{{')\n const lastClose = text.lastIndexOf('}}')\n\n if (lastOpen <= lastClose) {\n showDropdown.value = false\n return\n }\n\n dropdownQuery.value = text.slice(lastOpen + 2)\n // Make sure the combobox has an id before it advertises `aria-expanded`, so\n // `aria-controls` always resolves to the listbox we are about to render.\n ensureComponentId()\n showDropdown.value = true\n\n // Anchor under the caret; `getBoundingClientRect` gives the caret rect in one read.\n nextTick(() => {\n const selection = window.getSelection()\n if (!selection || selection.rangeCount === 0 || !editorRef.value) {\n return\n }\n const r = selection.getRangeAt(0).cloneRange()\n r.collapse(true)\n const rect = r.getBoundingClientRect()\n const editorRect = editorRef.value.getBoundingClientRect()\n // Some browsers collapse empty ranges to a zero rect — fall back to the editor edge.\n dropdownPosition.value = {\n left: rect.left || editorRect.left,\n top: rect.bottom || editorRect.bottom,\n }\n })\n}\n\nconst handleDropdownSelect = (item: string): void => {\n if (readOnly) {\n return\n }\n const caret = getModelCaret() ?? 0\n const value = serializeEditor()\n const from = Math.max(0, caret - dropdownQuery.value.length - 2)\n const to = caret\n const next = `${value.slice(0, from)}{{${item}}}${value.slice(to)}`\n const nextCursor = from + `{{${item}}}`.length\n\n // Pill set changed — force a re-render and reposition the caret.\n lastPillSignature = pillSignature(next, withVariables)\n renderModel(next)\n setModelCaret(nextCursor)\n\n showDropdown.value = false\n emitChange(next, { skipDropdownCheck: true })\n}\n\n// ───────────────────────────────────────────────────────────────────\n// Change / focus / blur\n// ───────────────────────────────────────────────────────────────────\n\nconst emitChange = (\n value: string,\n opts: { skipDropdownCheck?: boolean } = {},\n): void => {\n const same = value === serializeValue(modelValue)\n if (alwaysEmitChange || !same) {\n emit('update:modelValue', value)\n }\n if (!opts.skipDropdownCheck) {\n updateDropdownVisibility()\n }\n}\n\nconst handleInput = (): void => {\n const text = serializeEditor()\n isEmpty.value = isBlankValue(text)\n\n // Only rebuild when the pill set changes (e.g. `}}` closed a pattern, or\n // a value was pasted). Skipping it for plain-text edits preserves the\n // live selection — important for IME composition and double-click select.\n // Also defer while composing; `handleCompositionEnd` re-runs this path so the\n // rebuild happens once the IME has committed its text.\n const sig = pillSignature(text, withVariables)\n if (!isComposing.value && sig !== lastPillSignature) {\n const caret = getModelCaret()\n lastPillSignature = sig\n renderModel(text)\n if (caret !== null) {\n setModelCaret(caret)\n }\n }\n\n emitChange(text)\n}\n\nconst handleCompositionStart = (): void => {\n isComposing.value = true\n}\n\nconst handleCompositionEnd = (): void => {\n isComposing.value = false\n // Run the deferred input path now that the composition has committed, so any\n // pill that formed during composition is rendered.\n handleInput()\n}\n\nconst handleFocus = (): void => {\n isFocused.value = true\n ensureComponentId()\n ensureTooltipsActive()\n}\n\nconst handleBlur = (event: FocusEvent): void => {\n isFocused.value = false\n showDropdown.value = false\n const value = serializeEditor()\n // Check the serialized `value`, not `modelValue` — a `0` or `false` model is\n // a valid non-empty entry that should still submit on blur.\n if (emitOnBlur && value) {\n emit('submit', value, event)\n }\n emit('blur', value, event)\n}\n\n/**\n * Strip rich content on paste; `contenteditable=\"plaintext-only\"` is not\n * reliable cross-browser, so we intercept and use `insertText` to keep undo.\n */\nconst handlePaste = (event: ClipboardEvent): void => {\n event.preventDefault()\n const text = event.clipboardData?.getData('text/plain') ?? ''\n if (!text) {\n return\n }\n document.execCommand('insertText', false, text.replace(/\\r?\\n/g, ' '))\n // `insertText` normally fires an `input` event, but that is not guaranteed\n // across browsers. Run the same path explicitly so pill rendering, emptiness,\n // `update:modelValue`, and the dropdown never lag behind the pasted DOM.\n handleInput()\n}\n\n// ───────────────────────────────────────────────────────────────────\n// Keyboard handling\n// ───────────────────────────────────────────────────────────────────\n\nconst handleKeyDown = (event: KeyboardEvent): void => {\n if (showDropdown.value) {\n if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {\n event.preventDefault()\n event.stopPropagation()\n dropdownRef.value?.handleArrowKey(\n event.key === 'ArrowDown' ? 'down' : 'up',\n )\n return\n }\n if (event.key === 'Enter') {\n event.preventDefault()\n event.stopPropagation()\n dropdownRef.value?.handleSelect()\n return\n }\n if (event.key === 'Escape') {\n event.preventDefault()\n event.stopPropagation()\n showDropdown.value = false\n return\n }\n }\n\n if (event.key === 'Enter') {\n // Block the browser default so a contenteditable div does not insert\n // <br> / <div> and break single-line semantics, then emit submit\n // (used by the table editors).\n event.preventDefault()\n emit('submit', serializeEditor(), event)\n return\n }\n\n // Backspace / Delete: pill atomicity is handled by the browser via\n // `contenteditable=\"false\"` on pills — no manual `}}`-pair handling needed.\n}\n\n// ───────────────────────────────────────────────────────────────────\n// Click forwarding & lifecycle\n// ───────────────────────────────────────────────────────────────────\n\n/**\n * Clicking a pill selects it whole, so a subsequent Backspace deletes it\n * in one keystroke and typing replaces it — the usual chip/mention model.\n */\nconst handleEditorClick = (event: MouseEvent): void => {\n const target =\n event.target instanceof Element\n ? event.target.closest<HTMLElement>('.scalar-pill')\n : null\n if (!target) {\n return\n }\n const editor = editorRef.value\n if (!editor) {\n return\n }\n editor.focus()\n const range = document.createRange()\n range.selectNode(target)\n const selection = window.getSelection()\n selection?.removeAllRanges()\n selection?.addRange(range)\n updateDropdownVisibility()\n}\n\nonMounted(() => {\n const initial = serializeValue(modelValue)\n lastPillSignature = pillSignature(initial, withVariables)\n lastEnvKey = computeEnvKey()\n renderModel(initial)\n isEmpty.value = isBlankValue(initial)\n\n // `autofocus` on a contenteditable div is not honoured natively, so focus\n // the editor ourselves when the consumer passes the attribute.\n if (Object.hasOwn(attrs, 'autofocus')) {\n editorRef.value?.focus()\n }\n})\n\nwatch(\n () => modelValue,\n (next) => {\n const serialized = serializeValue(next)\n // Always sync the placeholder flag, even when the DOM already matches and we\n // skip the rebuild below. Otherwise a value cell that switches from select\n // mode (no editor element) into the empty editor keeps a stale `isEmpty`,\n // and the placeholder silently disappears.\n isEmpty.value = isBlankValue(serialized)\n if (serializeEditor() === serialized) {\n return\n }\n lastPillSignature = pillSignature(serialized, withVariables)\n renderModel(serialized)\n },\n)\n\n// The editable surface only exists in \"editor mode\" (see template). When a row switches into editor\n// mode after mount — most notably when this component instance is reused for a different table row —\n// `onMounted` has already run and the `modelValue` watch fired while `editorRef` was still null, so\n// the model was never painted into the freshly created element and the cell renders empty.\n//\n// Paint the model when the element appears, but only into a still-empty editor: an editor that\n// already holds text is either up to date or ahead of `modelValue` with an uncommitted edit/paste,\n// and must not be clobbered.\n//\n// `flush: 'sync'` makes the paint part of the same step that creates the element. Vue assigns a\n// non-null template ref from a post-render effect, so the element is already mounted and patched\n// when this runs — deferring any further (the `pre` default, or `post`) only pushes the paint past\n// the consumer effects that run later in the same flush. A parent that focuses the cell as it\n// switches into editor mode would then place the caret in a still-empty editor, and the paint's\n// `replaceChildren` would drop that selection.\nwatch(\n editorRef,\n (editor) => {\n if (!editor || !isBlankValue(serializeEditor())) {\n return\n }\n const serialized = serializeValue(modelValue)\n if (serialized === '') {\n return\n }\n lastPillSignature = pillSignature(serialized, withVariables)\n renderModel(serialized)\n },\n { flush: 'sync' },\n)\n\nwatch(\n [() => environment, () => withVariables],\n () => {\n // Env changes affect pill colour and `isDefined` opacity — rebuild.\n const envKey = computeEnvKey()\n if (envKey === lastEnvKey) {\n return\n }\n lastEnvKey = envKey\n // Most rows are plain text; skip the DOM walk when there are no pills.\n // Pills introduced later flow through `handleInput` / the modelValue\n // watcher, which update `lastPillSignature`.\n if (lastPillSignature === '') {\n return\n }\n lastPillSignature = pillSignature(serializeEditor(), withVariables)\n // Preserve the caret across the rebuild so editing does not jump to the\n // start when the environment changes mid-edit (mirrors `handleInput`).\n const caret = getModelCaret()\n renderModel(serializeEditor())\n if (caret !== null) {\n setModelCaret(caret)\n }\n },\n // Variables are often mutated in place (e.g. editing a value in the env\n // editor) without the object reference changing — deep watch catches it.\n { deep: true },\n)\n\nonBeforeUnmount(() => {\n teardownPillTooltips()\n})\n\n// ───────────────────────────────────────────────────────────────────\n// Public API\n// ───────────────────────────────────────────────────────────────────\n\ndefineExpose({\n /** Focus the editor. `position` controls caret placement. */\n focus: (position?: 'start' | 'end' | number): void => {\n const editor = editorRef.value\n if (!editor) {\n return\n }\n editor.focus()\n if (!isDefined(position)) {\n return\n }\n const length = serializeEditor().length\n const pos =\n position === 'start' ? 0 : position === 'end' ? length : position\n setModelCaret(pos)\n },\n /** Replace the current value programmatically and re-render the pills. */\n setContent: (next = ''): void => {\n if (serializeEditor() === next) {\n return\n }\n lastPillSignature = pillSignature(next, withVariables)\n renderModel(next)\n isEmpty.value = isBlankValue(next)\n },\n /** Read the current value as a `{{name}}`-bearing string. */\n getValue: (): string => serializeEditor(),\n /** Caret offset in the model string. */\n cursorPosition: (): number | undefined => {\n const c = getModelCaret()\n return c === null ? undefined : c\n },\n isFocused,\n editorRef,\n})\n</script>\n\n<template>\n <!-- Disabled mode: read-only label -->\n <div\n v-if=\"disabled\"\n class=\"text-c-2 flex cursor-default items-center justify-center\"\n :class=\"{\n 'font-code pr-2 pl-1 text-base': layout === 'modal',\n 'px-2': layout !== 'modal',\n 'line-through': linethrough,\n }\"\n data-testid=\"code-input-lite-disabled\">\n <span class=\"whitespace-nowrap\">{{ modelValue }}</span>\n </div>\n\n <!-- Enum mode: select dropdown with predefined values -->\n <DataTableInputSelect\n v-else-if=\"enumProp?.length\"\n :default=\"defaultProp\"\n :modelValue=\"modelValue\"\n :type=\"defaultType\"\n :value=\"enumProp\"\n @update:modelValue=\"handleSelectChange\" />\n\n <!-- Boolean mode: select dropdown with true/false (and optionally null) -->\n <DataTableInputSelect\n v-else-if=\"isBooleanMode\"\n :default=\"defaultProp\"\n :modelValue=\"modelValue\"\n :value=\"booleanOptions\"\n @update:modelValue=\"handleSelectChange\" />\n\n <!-- Examples mode: select dropdown with example values -->\n <DataTableInputSelect\n v-else-if=\"examples?.length\"\n :default=\"defaultProp\"\n :modelValue=\"modelValue\"\n :value=\"examples\"\n @update:modelValue=\"handleSelectChange\" />\n\n <!-- Editor mode -->\n <div\n v-else\n :id=\"componentId\"\n v-bind=\"$attrs\"\n class=\"code-input-lite group/code-input-lite peer relative w-full leading-[1.44] -outline-offset-1 has-[:focus-visible]:rounded-[4px] has-[:focus-visible]:outline\"\n :class=\"{\n 'code-input-lite--error': error,\n 'code-input-lite--empty': isEmpty,\n 'line-through': linethrough,\n }\">\n <!-- The single editable surface; see the file header for how pills work. -->\n <div\n ref=\"editorRef\"\n :aria-activedescendant=\"\n displayVariablesDropdown ? activeOptionId : undefined\n \"\n :aria-autocomplete=\"withVariables ? 'list' : undefined\"\n :aria-controls=\"displayVariablesDropdown ? listboxId : undefined\"\n :aria-expanded=\"displayVariablesDropdown ? 'true' : undefined\"\n :aria-invalid=\"error ? 'true' : undefined\"\n :aria-label=\"ariaLabel\"\n :aria-readonly=\"readOnly ? 'true' : undefined\"\n :aria-required=\"required ? 'true' : undefined\"\n class=\"code-input-lite__editor\"\n :contenteditable=\"readOnly ? 'false' : 'true'\"\n :data-placeholder=\"placeholder\"\n :role=\"withVariables ? 'combobox' : 'textbox'\"\n spellcheck=\"false\"\n @blur=\"handleBlur\"\n @click=\"handleEditorClick\"\n @compositionend=\"handleCompositionEnd\"\n @compositionstart=\"handleCompositionStart\"\n @focus=\"handleFocus\"\n @input=\"handleInput\"\n @keydown=\"handleKeyDown\"\n @paste=\"handlePaste\"\n @pointerover=\"ensureTooltipsActive\" />\n </div>\n\n <!--\n Slots and the required indicator are siblings of the mode templates so\n they render in every mode and so `absolute right-0` anchors to the\n surrounding (relative) cell rather than the shrink-wrapped mode wrapper.\n -->\n <div\n v-if=\"$slots.warning\"\n class=\"centered-y text-orange absolute right-7 text-xs\">\n <slot name=\"warning\" />\n </div>\n <div\n v-if=\"$slots.icon\"\n class=\"centered-y absolute right-0 flex h-full items-center p-1.5 group-has-[.code-input-lite__editor:focus]:z-1\">\n <slot name=\"icon\" />\n </div>\n <div\n v-if=\"required\"\n class=\"required centered-y text-xxs text-c-3 group-[.error]:text-red bg-b-1 pointer-events-none absolute right-0 mr-0.5 pt-px pr-2 opacity-100 shadow-[-8px_0_4px_var(--scalar-background-1)] transition-opacity duration-150 peer-has-[.code-input-lite__editor:focus]:opacity-0\">\n {{ translate('apiClient.codeInputLite.required') }}\n </div>\n\n <EnvironmentVariableDropdown\n v-if=\"displayVariablesDropdown\"\n ref=\"dropdownRef\"\n :contextFunctionItems=\"contextFunctionDropdownItems\"\n :dropdownPosition=\"dropdownPosition\"\n :environment=\"environment\"\n :listboxId=\"listboxId\"\n :query=\"dropdownQuery\"\n @close=\"showDropdown = false\"\n @redirect=\"emit('navigate', { page: 'document', path: 'environment' })\"\n @select=\"handleDropdownSelect\" />\n</template>\n\n<style scoped>\n.code-input-lite {\n /* Flex so the editor centres vertically in whatever height the cell gives us.\n Font properties inherit so we adopt the surrounding typography. */\n display: flex;\n align-items: center;\n}\n\n.code-input-lite__editor {\n /* Everything font-related inherits from the surrounding context. */\n font: inherit;\n letter-spacing: inherit;\n flex: 1;\n min-width: 0;\n background: transparent;\n outline: none;\n color: var(--scalar-color-1);\n caret-color: var(--scalar-color-1);\n /* Single-line: horizontal scroll keeps the caret visible for long values;\n the scrollbar itself is hidden (would be noisy inside a table cell). */\n white-space: pre;\n overflow-x: auto;\n overflow-y: hidden;\n scrollbar-width: none;\n padding: 0 0.5em;\n box-sizing: border-box;\n line-height: 1.44;\n /* Positioning context for the absolutely positioned placeholder. */\n position: relative;\n}\n\n.code-input-lite__editor::-webkit-scrollbar {\n display: none;\n}\n\n/* Absolute so the placeholder does not occupy flow space inside the\n contenteditable; otherwise the caret would land after it on focus.\n `pointer-events: none` lets clicks fall through to focus the editor.\n Hidden on focus so it never renders on top of the text caret. */\n.code-input-lite--empty .code-input-lite__editor:not(:focus)::before {\n content: attr(data-placeholder);\n color: var(--scalar-color-3);\n pointer-events: none;\n position: absolute;\n top: 0;\n bottom: 0;\n left: 0.5em;\n display: flex;\n align-items: center;\n}\n\n.code-input-lite--error .code-input-lite__editor {\n outline: 1px solid var(--scalar-color-red);\n}\n</style>\n\n<style>\n/* Pill styling. Each pill is `<span contenteditable=\"false\">name</span>` —\n an atomic widget; the caret lands before or after it, never inside. */\n.scalar-pill {\n color: var(--scalar-color-2);\n border-radius: var(--scalar-radius-full);\n display: inline-block;\n font-family: var(--scalar-font-code);\n font-size: 0.9em;\n line-height: 1.4;\n vertical-align: baseline;\n background: var(--scalar-background-3);\n padding: 0.125em 0.6em;\n margin-right: 0.35em;\n cursor: text;\n /* Single click selects the whole pill — chip/mention model, deletes in one go. */\n user-select: all;\n -webkit-user-select: all;\n}\n\n.dark-mode .scalar-pill {\n background: color-mix(\n in srgb,\n var(--tw-bg-base, var(--scalar-color-1)),\n transparent 90%\n );\n}\n\n.light-mode .scalar-pill {\n background: var(--scalar-background-3);\n}\n\n.scalar-pill--context-fn {\n /* Inset box-shadow as a border so the layout box stays identical to plain pills. */\n box-shadow: 0 0 0 1px\n color-mix(in srgb, var(--scalar-color-3), transparent 35%) inset;\n}\n\n.dark-mode .scalar-pill--context-fn {\n background: color-mix(in srgb, var(--scalar-background-3), transparent 55%);\n}\n\n.light-mode .scalar-pill--context-fn {\n background: color-mix(in srgb, var(--scalar-background-3), transparent 40%);\n}\n</style>\n"],"mappings":""}
|