@scalar/api-client 0.4.0 → 0.5.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/package.json CHANGED
@@ -1,7 +1,25 @@
1
1
  {
2
2
  "name": "@scalar/api-client",
3
- "version": "0.4.0",
4
- "author": "Scalar",
3
+ "description": "the open source API testing client",
4
+ "keywords": [
5
+ "api",
6
+ "client",
7
+ "testing",
8
+ "rest",
9
+ "graphql",
10
+ "postman alternative"
11
+ ],
12
+ "version": "0.5.0",
13
+ "author": "Scalar (https://github.com/scalar)",
14
+ "homepage": "https://github.com/scalar/scalar",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/scalar/scalar.git",
18
+ "directory": "packages/api-client"
19
+ },
20
+ "bugs": {
21
+ "url": "https://github.com/scalar/scalar/issues/new"
22
+ },
5
23
  "license": "MIT",
6
24
  "engines": {
7
25
  "node": ">=18"
@@ -19,30 +37,18 @@
19
37
  },
20
38
  "types": "dist/index.d.ts",
21
39
  "dependencies": {
22
- "@codemirror/lang-java": "^6.0.1",
23
- "@codemirror/lang-javascript": "6.1.9",
24
- "@codemirror/lang-json": "6.0.1",
25
- "@codemirror/lang-python": "6.1.3",
26
- "@codemirror/language": "6.8.0",
27
- "@codemirror/legacy-modes": "6.3.3",
28
- "@codemirror/state": "6.2.1",
29
- "@codemirror/view": "6.16.0",
30
40
  "@headlessui/vue": "1.7.14",
31
- "@lezer/highlight": "1.1.6",
32
- "@uiw/codemirror-theme-duotone": "4.21.3",
33
- "@uiw/codemirror-themes": "4.21.3",
34
41
  "@vueuse/core": "10.1.2",
35
42
  "axios": "1.4.0",
36
- "codemirror": "6.0.1",
37
43
  "javascript-time-ago": "2.5.9",
38
44
  "nanoid": "4.0.2",
39
45
  "nunjucks": "3.2.3",
40
46
  "pretty-bytes": "6.1.0",
41
47
  "pretty-ms": "8.0.0",
42
48
  "tippy.js": "6.3.7",
43
- "@scalar/default-theme": "0.2.0",
44
- "@scalar/use-codemirror": "0.4.0",
45
- "@scalar/use-keyboard-event": "0.4.0"
49
+ "@scalar/default-theme": "0.2.1",
50
+ "@scalar/use-codemirror": "0.5.0",
51
+ "@scalar/use-keyboard-event": "0.4.1"
46
52
  },
47
53
  "devDependencies": {
48
54
  "@vitejs/plugin-vue": "4.2.3",
@@ -54,7 +60,7 @@
54
60
  },
55
61
  "peerDependencies": {
56
62
  "vue": "3.3.4",
57
- "@types/nunjucks": "3.2.3"
63
+ "@types/nunjucks": "3.2.2"
58
64
  },
59
65
  "scripts": {
60
66
  "build": "vite build && pnpm types:build && tsc-alias -p tsconfig.build.json",
@@ -1,4 +1,5 @@
1
1
  <script setup lang="ts">
2
+ import { CodeMirror } from '@scalar/use-codemirror'
2
3
  import { useKeyboardEvent } from '@scalar/use-keyboard-event'
3
4
  import { useMediaQuery } from '@vueuse/core'
4
5
  import TimeAgo from 'javascript-time-ago'
@@ -7,7 +8,6 @@ import { computed, ref } from 'vue'
7
8
 
8
9
  import { sendRequest } from '../../helpers/sendRequest'
9
10
  import { useApiClientRequestStore } from '../../stores/apiClientRequestStore'
10
- import { CodeMirror } from '../CodeMirror'
11
11
  import FlowModal, { useModalState } from '../FlowModal.vue'
12
12
  import RequestHistory from './RequestHistory.vue'
13
13
 
@@ -1,6 +1,7 @@
1
1
  <script setup lang="ts">
2
+ import { CodeMirror } from '@scalar/use-codemirror'
3
+
2
4
  import { useApiClientRequestStore } from '../../../stores/apiClientRequestStore'
3
- import { CodeMirror } from '../../CodeMirror'
4
5
  import { CollapsibleSection } from '../../CollapsibleSection'
5
6
  import { Grid } from '../../Grid'
6
7
 
@@ -33,7 +34,7 @@ const updateActiveRequest = (value: string) => {
33
34
  v-else
34
35
  :content="activeRequest.body"
35
36
  :languages="['json']"
36
- :lineNumbers="true"
37
+ lineNumbers
37
38
  @change="updateActiveRequest" />
38
39
  </CollapsibleSection>
39
40
  </template>
@@ -1,5 +1,6 @@
1
1
  <script lang="ts" setup>
2
- import { CodeMirror } from '../../CodeMirror'
2
+ import { CodeMirror } from '@scalar/use-codemirror'
3
+
3
4
  import { CollapsibleSection } from '../../CollapsibleSection'
4
5
 
5
6
  withDefaults(defineProps<{ active: boolean; data: any }>(), {
@@ -13,7 +14,7 @@ withDefaults(defineProps<{ active: boolean; data: any }>(), {
13
14
  v-if="active"
14
15
  :content="data"
15
16
  :languages="['json']"
16
- :readOnly="true" />
17
+ readOnly />
17
18
  <div
18
19
  v-else
19
20
  class="scalar-api-client__empty-state">
package/src/index.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  export { ApiClient } from './components/ApiClient'
2
- export { CodeMirror } from './components/CodeMirror'
3
2
 
4
3
  export * from './helpers'
5
4
  export * from './hooks'
@@ -1,56 +0,0 @@
1
- type Language = 'axios' | 'c' | 'clojure' | 'csharp' | 'go' | 'http' | 'java' | 'javascript' | 'json' | 'kotlin' | 'node' | 'objc' | 'ocaml' | 'powershell' | 'python' | 'r' | 'ruby' | 'shell' | 'swift' | 'php';
2
- declare const _default: import("vue").DefineComponent<{
3
- content: {
4
- type: import("vue").PropType<string>;
5
- };
6
- readOnly: {
7
- type: import("vue").PropType<boolean>;
8
- };
9
- languages: {
10
- type: import("vue").PropType<Language[]>;
11
- };
12
- withVariables: {
13
- type: import("vue").PropType<boolean>;
14
- };
15
- lineNumbers: {
16
- type: import("vue").PropType<boolean>;
17
- };
18
- withoutTheme: {
19
- type: import("vue").PropType<boolean>;
20
- };
21
- disableEnter: {
22
- type: import("vue").PropType<boolean>;
23
- default: boolean;
24
- };
25
- }, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
26
- change: (value: string) => void;
27
- }, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
28
- content: {
29
- type: import("vue").PropType<string>;
30
- };
31
- readOnly: {
32
- type: import("vue").PropType<boolean>;
33
- };
34
- languages: {
35
- type: import("vue").PropType<Language[]>;
36
- };
37
- withVariables: {
38
- type: import("vue").PropType<boolean>;
39
- };
40
- lineNumbers: {
41
- type: import("vue").PropType<boolean>;
42
- };
43
- withoutTheme: {
44
- type: import("vue").PropType<boolean>;
45
- };
46
- disableEnter: {
47
- type: import("vue").PropType<boolean>;
48
- default: boolean;
49
- };
50
- }>> & {
51
- onChange?: ((value: string) => any) | undefined;
52
- }, {
53
- disableEnter: boolean;
54
- }, {}>;
55
- export default _default;
56
- //# sourceMappingURL=CodeMirror.vue.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"CodeMirror.vue.d.ts","sourceRoot":"","sources":["../../../src/components/CodeMirror/CodeMirror.vue.ts"],"names":[],"mappings":"AA+EA,KAAK,QAAQ,GACT,OAAO,GACP,GAAG,GACH,SAAS,GACT,QAAQ,GACR,IAAI,GACJ,MAAM,GACN,MAAM,GACN,YAAY,GACZ,MAAM,GACN,QAAQ,GACR,MAAM,GACN,MAAM,GACN,OAAO,GACP,YAAY,GACZ,QAAQ,GACR,GAAG,GACH,MAAM,GACN,OAAO,GACP,OAAO,GACP,KAAK,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4JT,wBAAkD"}
@@ -1,6 +0,0 @@
1
- import { type DecorationSet, ViewPlugin, type ViewUpdate } from '@codemirror/view';
2
- export declare const variables: () => ViewPlugin<{
3
- variables: DecorationSet;
4
- update(update: ViewUpdate): void;
5
- }>;
6
- //# sourceMappingURL=variables.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"variables.d.ts","sourceRoot":"","sources":["../../../../src/components/CodeMirror/extensions/variables.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,aAAa,EAGlB,UAAU,EACV,KAAK,UAAU,EAChB,MAAM,kBAAkB,CAAA;AAYzB,eAAO,MAAM,SAAS;;mBAOD,UAAU;EAc5B,CAAA"}
@@ -1,2 +0,0 @@
1
- export { default as CodeMirror } from './CodeMirror.vue';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/CodeMirror/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,kBAAkB,CAAA"}
@@ -1,232 +0,0 @@
1
- <script lang="ts" setup>
2
- import { java } from '@codemirror/lang-java'
3
- import { javascript } from '@codemirror/lang-javascript'
4
- import { json } from '@codemirror/lang-json'
5
- import { python } from '@codemirror/lang-python'
6
- import { type LanguageSupport, StreamLanguage } from '@codemirror/language'
7
- import {
8
- c,
9
- csharp,
10
- kotlin,
11
- objectiveC,
12
- } from '@codemirror/legacy-modes/mode/clike'
13
- import { clojure } from '@codemirror/legacy-modes/mode/clojure'
14
- import { go } from '@codemirror/legacy-modes/mode/go'
15
- import { http } from '@codemirror/legacy-modes/mode/http'
16
- import { oCaml } from '@codemirror/legacy-modes/mode/mllike'
17
- import { powerShell } from '@codemirror/legacy-modes/mode/powershell'
18
- import { r } from '@codemirror/legacy-modes/mode/r'
19
- import { ruby } from '@codemirror/legacy-modes/mode/ruby'
20
- import { shell } from '@codemirror/legacy-modes/mode/shell'
21
- import { swift } from '@codemirror/legacy-modes/mode/swift'
22
- import { type Extension } from '@codemirror/state'
23
- import {
24
- EditorView,
25
- type ViewUpdate,
26
- keymap,
27
- lineNumbers as lineNumbersExtension,
28
- } from '@codemirror/view'
29
- import { useCodeMirror } from '@scalar/use-codemirror'
30
- import { watch } from 'vue'
31
-
32
- import { variables } from './extensions/variables'
33
-
34
- const props = withDefaults(
35
- defineProps<{
36
- content?: string
37
- readOnly?: boolean
38
- languages?: Language[]
39
- withVariables?: boolean
40
- lineNumbers?: boolean
41
- withoutTheme?: boolean
42
- disableEnter?: boolean
43
- }>(),
44
- {
45
- disableEnter: false,
46
- },
47
- )
48
-
49
- const emit = defineEmits<{
50
- (e: 'change', value: string): void
51
- }>()
52
-
53
- // TODO: Add 'php' and 'laravel'
54
- const syntaxHighlighting: Partial<
55
- Record<Language, LanguageSupport | StreamLanguage<any>>
56
- > = {
57
- axios: javascript(),
58
- c: StreamLanguage.define(c),
59
- clojure: StreamLanguage.define(clojure),
60
- csharp: StreamLanguage.define(csharp),
61
- go: StreamLanguage.define(go),
62
- http: StreamLanguage.define(http),
63
- java: java(),
64
- javascript: javascript(),
65
- json: json(),
66
- kotlin: StreamLanguage.define(kotlin),
67
- node: javascript(),
68
- objc: StreamLanguage.define(objectiveC),
69
- ocaml: StreamLanguage.define(oCaml),
70
- powershell: StreamLanguage.define(powerShell),
71
- python: python(),
72
- r: StreamLanguage.define(r),
73
- ruby: StreamLanguage.define(ruby),
74
- shell: StreamLanguage.define(shell),
75
- swift: StreamLanguage.define(swift),
76
- }
77
-
78
- type Language =
79
- | 'axios'
80
- | 'c'
81
- | 'clojure'
82
- | 'csharp'
83
- | 'go'
84
- | 'http'
85
- | 'java'
86
- | 'javascript'
87
- | 'json'
88
- | 'kotlin'
89
- | 'node'
90
- | 'objc'
91
- | 'ocaml'
92
- | 'powershell'
93
- | 'python'
94
- | 'r'
95
- | 'ruby'
96
- | 'shell'
97
- | 'swift'
98
- | 'php'
99
-
100
- // CSS Class
101
- const classes = ['scalar-api-client__codemirror']
102
-
103
- if (props.readOnly) {
104
- classes.push('scalar-api-client__codemirror--read-only')
105
- }
106
-
107
- const getCodeMirrorExtensions = () => {
108
- const extensions: Extension[] = []
109
-
110
- extensions.push(EditorView.editorAttributes.of({ class: classes.join(' ') }))
111
-
112
- // Read only
113
- if (props.readOnly) {
114
- extensions.push(EditorView.editable.of(false))
115
- }
116
-
117
- // Syntax highlighting
118
- if (props.languages) {
119
- props.languages
120
- .filter((language) => typeof syntaxHighlighting[language] !== 'undefined')
121
- .forEach((language) => {
122
- extensions.push(syntaxHighlighting[language] as Extension)
123
- })
124
- }
125
-
126
- // Line numbers
127
- if (props.lineNumbers) {
128
- extensions.push(lineNumbersExtension())
129
- }
130
-
131
- // Highlight variables
132
- if (props.withVariables) {
133
- extensions.push(variables())
134
- }
135
-
136
- if (props.disableEnter) {
137
- extensions.push(
138
- keymap.of([
139
- {
140
- key: 'Enter',
141
- run: () => {
142
- return true
143
- },
144
- },
145
- {
146
- key: 'Ctrl-Enter',
147
- mac: 'Cmd-Enter',
148
- run: () => {
149
- return true
150
- },
151
- },
152
- {
153
- key: 'Shift-Enter',
154
- run: () => {
155
- return true
156
- },
157
- },
158
- ]),
159
- )
160
- }
161
-
162
- // Listen to updates
163
- extensions.push(
164
- EditorView.updateListener.of((v: ViewUpdate) => {
165
- if (!v.docChanged) {
166
- return
167
- }
168
-
169
- emit('change', v.state.doc.toString())
170
- }),
171
- )
172
-
173
- return extensions
174
- }
175
-
176
- const { codeMirrorRef, setCodeMirrorContent, reconfigureCodeMirror } =
177
- useCodeMirror({
178
- content: props.content ?? '',
179
- extensions: getCodeMirrorExtensions(),
180
- withoutTheme: props.withoutTheme,
181
- })
182
-
183
- watch(props, () => {
184
- setCodeMirrorContent(props.content ?? '')
185
- reconfigureCodeMirror(getCodeMirrorExtensions())
186
- })
187
- </script>
188
-
189
- <template>
190
- <div
191
- ref="codeMirrorRef"
192
- class="scalar-api-client__codemirror__wrapper" />
193
- </template>
194
-
195
- <style>
196
- /** Basics */
197
- .scalar-api-client__codemirror__wrapper {
198
- width: 100%;
199
- display: flex;
200
- align-items: stretch;
201
- }
202
-
203
- .scalar-api-client__codemirror {
204
- flex-grow: 1;
205
- max-width: 100%;
206
- }
207
-
208
- .scalar-api-client__codemirror.ͼw {
209
- background-color: var(--theme-background-1);
210
- }
211
-
212
- .scalar-api-client__codemirror--read-only.ͼw {
213
- background-color: var(--theme-background-2);
214
- }
215
-
216
- /** URL input */
217
- .scalar-api-client__url-input {
218
- font-weight: var(--theme-semibold);
219
- }
220
-
221
- .scalar-api-client__url-input .cm-scroller {
222
- padding-left: 6px;
223
- }
224
-
225
- .scalar-api-client__url-input .ͼ1 .cm-scroller {
226
- align-items: center !important;
227
- }
228
-
229
- .scalar-api-client__variable {
230
- color: var(--scalar-api-client-color);
231
- }
232
- </style>
@@ -1,41 +0,0 @@
1
- import {
2
- Decoration,
3
- type DecorationSet,
4
- EditorView,
5
- MatchDecorator,
6
- ViewPlugin,
7
- type ViewUpdate,
8
- } from '@codemirror/view'
9
-
10
- const variableHighlighterDecoration = new MatchDecorator({
11
- regexp: /(\{[^}]+\})/g,
12
- decoration: () =>
13
- Decoration.mark({
14
- attributes: {
15
- class: 'scalar-api-client__variable',
16
- },
17
- }),
18
- })
19
-
20
- export const variables = () =>
21
- ViewPlugin.fromClass(
22
- class {
23
- variables: DecorationSet
24
- constructor(view: EditorView) {
25
- this.variables = variableHighlighterDecoration.createDeco(view)
26
- }
27
- update(update: ViewUpdate) {
28
- this.variables = variableHighlighterDecoration.updateDeco(
29
- update,
30
- this.variables,
31
- )
32
- }
33
- },
34
- {
35
- decorations: (instance) => instance.variables,
36
- provide: (plugin) =>
37
- EditorView.atomicRanges.of(
38
- (view) => view.plugin(plugin)?.variables || Decoration.none,
39
- ),
40
- },
41
- )
@@ -1 +0,0 @@
1
- export { default as CodeMirror } from './CodeMirror.vue'