@dosgato/dialog 1.4.4 → 1.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.
Files changed (61) hide show
  1. package/dist/Dialog.svelte +3 -3
  2. package/dist/FieldAutocomplete.svelte +19 -15
  3. package/dist/FieldCheckbox.svelte +4 -4
  4. package/dist/FieldChoices.svelte +11 -7
  5. package/dist/FieldChooserLink.svelte +30 -32
  6. package/dist/FieldDate.svelte +3 -3
  7. package/dist/FieldDateTime.svelte +3 -4
  8. package/dist/FieldDualListbox.svelte +9 -11
  9. package/dist/FieldIdentifier.svelte +2 -2
  10. package/dist/FieldMultiple.svelte +6 -5
  11. package/dist/FieldMultiselect.svelte +5 -5
  12. package/dist/FieldNumber.svelte +3 -3
  13. package/dist/FieldRadio.svelte +3 -7
  14. package/dist/FieldSelect.svelte +4 -8
  15. package/dist/FieldStandard.svelte +5 -3
  16. package/dist/FieldStandard.svelte.d.ts +4 -2
  17. package/dist/FieldText.svelte +6 -5
  18. package/dist/FieldText.svelte.d.ts +2 -1
  19. package/dist/FieldTextArea.svelte +3 -4
  20. package/dist/FileIcon.svelte +1 -1
  21. package/dist/Form.svelte +4 -4
  22. package/dist/FormDialog.svelte +2 -2
  23. package/dist/Icon.svelte +10 -6
  24. package/dist/InlineMessage.svelte +3 -3
  25. package/dist/InlineMessages.svelte +1 -1
  26. package/dist/Input.svelte +3 -3
  27. package/dist/Input.svelte.d.ts +2 -1
  28. package/dist/Listbox.svelte +3 -4
  29. package/dist/Radio.svelte +0 -1
  30. package/dist/Switcher.svelte +1 -1
  31. package/dist/Tabs.svelte +3 -4
  32. package/dist/Tooltip.svelte +9 -9
  33. package/dist/chooser/AssetTabs.svelte +19 -17
  34. package/dist/chooser/AssetTabs.svelte.d.ts +1 -1
  35. package/dist/chooser/Chooser.svelte +3 -3
  36. package/dist/chooser/Chooser.svelte.d.ts +5 -5
  37. package/dist/chooser/ChooserStore.js +2 -2
  38. package/dist/chooser/UploadUI.svelte +4 -4
  39. package/dist/code/FieldCodeEditor.svelte +3 -3
  40. package/dist/code/FieldGraphQLEditor.svelte +28 -0
  41. package/dist/code/FieldGraphQLEditor.svelte.d.ts +36 -0
  42. package/dist/code/FieldTypeScriptEditor.svelte +27 -0
  43. package/dist/code/FieldTypeScriptEditor.svelte.d.ts +34 -0
  44. package/dist/code/GraphQLEditor.svelte +145 -0
  45. package/dist/code/GraphQLEditor.svelte.d.ts +35 -0
  46. package/dist/code/TypeScriptEditor.svelte +186 -0
  47. package/dist/code/TypeScriptEditor.svelte.d.ts +33 -0
  48. package/dist/code/index.d.ts +2 -0
  49. package/dist/code/index.js +2 -0
  50. package/dist/colorpicker/FieldColorPicker.svelte +2 -2
  51. package/dist/cropper/FieldCropper.svelte +8 -10
  52. package/dist/cropper/cropper.js +9 -11
  53. package/dist/iconpicker/FieldIconPicker.svelte +7 -11
  54. package/dist/imageposition/FieldImagePosition.svelte +4 -5
  55. package/dist/imageposition/index.d.ts +1 -1
  56. package/dist/imageposition/index.js +0 -1
  57. package/dist/tagpicker/FieldTagPicker.svelte +1 -2
  58. package/dist/tree/Tree.svelte +2 -3
  59. package/dist/tree/TreeCell.svelte +2 -2
  60. package/dist/tree/TreeNode.svelte +16 -17
  61. package/package.json +14 -7
@@ -0,0 +1,28 @@
1
+ <script lang="ts">
2
+ import type { HTMLActionEntry } from '@txstate-mws/svelte-components'
3
+ import type { GraphQLSchema } from 'graphql'
4
+ import { FieldStandard } from '..'
5
+ import GraphQLEditor from './GraphQLEditor.svelte'
6
+ let className = ''
7
+ export { className as class }
8
+ export let id: string | undefined = undefined
9
+ export let path: string
10
+ export let label = ''
11
+ export let notNull = false
12
+ export let defaultValue: any = notNull ? '' : undefined
13
+ export let rows = 8
14
+ export let conditional: boolean | undefined = undefined
15
+ export let required = false
16
+ export let use: HTMLActionEntry[] = []
17
+ export let inputelement: HTMLElement = undefined as any
18
+ export let related: true | number = 0
19
+ export let extradescid: string | undefined = undefined
20
+ export let helptext: string | undefined = undefined
21
+ export let schema: GraphQLSchema | undefined = undefined
22
+ export let noMutations = false
23
+ export let allowInvalid = false
24
+ </script>
25
+
26
+ <FieldStandard bind:id {label} {path} {required} {defaultValue} {conditional} {related} {helptext} {notNull} let:value let:valid let:invalid let:id={fieldid} let:onBlur let:setVal let:messagesid let:helptextid let:deserialize>
27
+ <GraphQLEditor id={fieldid} bind:inputelement {schema} {noMutations} {allowInvalid} {rows} class={className} {value} {valid} {invalid} {helptextid} {messagesid} {extradescid} on:paste on:focusout={onBlur} {use} on:change={e => { console.log(e.detail); setVal(deserialize?.(e.detail)) }}/>
28
+ </FieldStandard>
@@ -0,0 +1,36 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { HTMLActionEntry } from '@txstate-mws/svelte-components';
3
+ import type { GraphQLSchema } from 'graphql';
4
+ declare const __propDef: {
5
+ props: {
6
+ class?: string;
7
+ id?: string | undefined;
8
+ path: string;
9
+ label?: string;
10
+ notNull?: boolean;
11
+ defaultValue?: any;
12
+ rows?: number;
13
+ conditional?: boolean | undefined;
14
+ required?: boolean;
15
+ use?: HTMLActionEntry[];
16
+ inputelement?: HTMLElement;
17
+ related?: true | number;
18
+ extradescid?: string | undefined;
19
+ helptext?: string | undefined;
20
+ schema?: GraphQLSchema | undefined;
21
+ noMutations?: boolean;
22
+ allowInvalid?: boolean;
23
+ };
24
+ events: {
25
+ paste: ClipboardEvent;
26
+ } & {
27
+ [evt: string]: CustomEvent<any>;
28
+ };
29
+ slots: {};
30
+ };
31
+ export type FieldGraphQLEditorProps = typeof __propDef.props;
32
+ export type FieldGraphQLEditorEvents = typeof __propDef.events;
33
+ export type FieldGraphQLEditorSlots = typeof __propDef.slots;
34
+ export default class FieldGraphQLEditor extends SvelteComponentTyped<FieldGraphQLEditorProps, FieldGraphQLEditorEvents, FieldGraphQLEditorSlots> {
35
+ }
36
+ export {};
@@ -0,0 +1,27 @@
1
+ <script lang="ts">
2
+ import type { HTMLActionEntry } from '@txstate-mws/svelte-components'
3
+ import { nullableSerialize, nullableDeserialize } from '@txstate-mws/svelte-forms'
4
+ import { FieldStandard } from '..'
5
+ import TypeScriptEditor from './TypeScriptEditor.svelte'
6
+ let className = ''
7
+ export { className as class }
8
+ export let id: string | undefined = undefined
9
+ export let path: string
10
+ export let label = ''
11
+ export let notNull = false
12
+ export let defaultValue: any = notNull ? '' : undefined
13
+ export let rows = 8
14
+ export let conditional: boolean | undefined = undefined
15
+ export let required = false
16
+ export let use: HTMLActionEntry[] = []
17
+ export let inputelement: HTMLElement = undefined as any
18
+ export let related: true | number = 0
19
+ export let extradescid: string | undefined = undefined
20
+ export let helptext: string | undefined = undefined
21
+ export let preamble = ''
22
+ export let sandbox = false
23
+ </script>
24
+
25
+ <FieldStandard bind:id {label} {path} {required} {defaultValue} {conditional} {related} {helptext} serialize={!notNull ? nullableSerialize : undefined} deserialize={!notNull ? nullableDeserialize : undefined} let:value let:valid let:invalid let:id={fieldid} let:onBlur let:setVal let:messagesid let:helptextid>
26
+ <TypeScriptEditor id={fieldid} bind:inputelement {preamble} {sandbox} {rows} class={className} {value} {valid} {invalid} {helptextid} {messagesid} {extradescid} on:paste on:focusout={onBlur} {use} on:change={e => setVal(e.detail)}/>
27
+ </FieldStandard>
@@ -0,0 +1,34 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { HTMLActionEntry } from '@txstate-mws/svelte-components';
3
+ declare const __propDef: {
4
+ props: {
5
+ class?: string;
6
+ id?: string | undefined;
7
+ path: string;
8
+ label?: string;
9
+ notNull?: boolean;
10
+ defaultValue?: any;
11
+ rows?: number;
12
+ conditional?: boolean | undefined;
13
+ required?: boolean;
14
+ use?: HTMLActionEntry[];
15
+ inputelement?: HTMLElement;
16
+ related?: true | number;
17
+ extradescid?: string | undefined;
18
+ helptext?: string | undefined;
19
+ preamble?: string;
20
+ sandbox?: boolean;
21
+ };
22
+ events: {
23
+ paste: ClipboardEvent;
24
+ } & {
25
+ [evt: string]: CustomEvent<any>;
26
+ };
27
+ slots: {};
28
+ };
29
+ export type FieldTypeScriptEditorProps = typeof __propDef.props;
30
+ export type FieldTypeScriptEditorEvents = typeof __propDef.events;
31
+ export type FieldTypeScriptEditorSlots = typeof __propDef.slots;
32
+ export default class FieldTypeScriptEditor extends SvelteComponentTyped<FieldTypeScriptEditorProps, FieldTypeScriptEditorEvents, FieldTypeScriptEditorSlots> {
33
+ }
34
+ export {};
@@ -0,0 +1,145 @@
1
+ <script lang="ts">
2
+ import { type HTMLActionEntry, passActions } from '@txstate-mws/svelte-components'
3
+ import type { EditorView, ViewUpdate } from '@codemirror/view'
4
+
5
+ import type { GraphQLSchema } from 'graphql'
6
+ import { createEventDispatcher, onDestroy, onMount } from 'svelte'
7
+ import { getDescribedBy } from '..'
8
+ let className = ''
9
+ export { className as class }
10
+ export let id: string | undefined = undefined
11
+ export let rows = 8
12
+ export let schema: GraphQLSchema | undefined = undefined
13
+ export let noMutations = false
14
+ export let allowInvalid = false
15
+ export let use: HTMLActionEntry[] = []
16
+ export let inputelement: HTMLElement | undefined = undefined
17
+ export let extradescid: string | undefined = undefined
18
+ export let helptextid: string | undefined = undefined
19
+ export let messagesid: string | undefined = undefined
20
+ export let valid: boolean | undefined = undefined
21
+ export let invalid: boolean | undefined = undefined
22
+ export let value: any
23
+
24
+ const dispatch = createEventDispatcher()
25
+
26
+ let editorInvalid = false
27
+ let updateCode: (code: string) => void
28
+ let updateEditorSchema: (schema?: GraphQLSchema) => void
29
+ let editorelement: HTMLElement | undefined
30
+ let editor: EditorView
31
+ onMount(async () => {
32
+ const { EditorView, minimalSetup } = await import('codemirror')
33
+ const { EditorState } = await import('@codemirror/state')
34
+ const { indentWithTab } = await import('@codemirror/commands')
35
+ const { lineNumbers, highlightActiveLine, highlightActiveLineGutter, keymap, hoverTooltip } = await import('@codemirror/view')
36
+ const { autocompletion, completionKeymap, closeBracketsKeymap } = await import('@codemirror/autocomplete')
37
+ const { setDiagnosticsEffect } = await import('@codemirror/lint')
38
+ const { indentOnInput } = await import('@codemirror/language')
39
+ const { graphql, updateSchema, getSchema, offsetToPos } = await import('cm6-graphql')
40
+ const { getHoverInformation, getDiagnostics } = await import('graphql-language-service')
41
+ const { GraphQLSchema: GQLSchema, GraphQLObjectType, GraphQLString } = await import('graphql')
42
+
43
+ function stripMutations (s?: GraphQLSchema): GraphQLSchema | undefined {
44
+ if (!s || !noMutations) return s
45
+ const config = s.toConfig()
46
+ const emptyMutation = new GraphQLObjectType({ name: 'Mutation', fields: { _: { type: GraphQLString } } })
47
+ const types = config.types.filter(t => t.name !== 'Mutation')
48
+ return new GQLSchema({ ...config, mutation: emptyMutation, types: [...types, emptyMutation] })
49
+ }
50
+
51
+ const graphqlHover = hoverTooltip((view, pos) => {
52
+ const s = getSchema(view.state)
53
+ if (!s) return null
54
+ const queryText = view.state.doc.toString()
55
+ const cursor = offsetToPos(view.state.doc, pos)
56
+ const info = getHoverInformation(s, queryText, cursor, undefined, { useMarkdown: false })
57
+ const content = Array.isArray(info) ? info.map(i => typeof i === 'string' ? i : i.value).join('\n') : typeof info === 'string' ? info : ''
58
+ if (!content) return null
59
+ return {
60
+ pos,
61
+ above: true,
62
+ create () {
63
+ const dom = document.createElement('div')
64
+ dom.style.cssText = 'padding: 4px 8px; font-size: 0.85em; font-family: monospace; white-space: pre-wrap;'
65
+ dom.textContent = content
66
+ return { dom }
67
+ }
68
+ }
69
+ })
70
+
71
+ editor = new EditorView({
72
+ extensions: [
73
+ minimalSetup,
74
+ lineNumbers(),
75
+ highlightActiveLine(),
76
+ highlightActiveLineGutter(),
77
+ autocompletion(),
78
+ indentOnInput(),
79
+ graphqlHover,
80
+ ...graphql(stripMutations(schema)),
81
+ EditorState.transactionFilter.of(tr => {
82
+ if (!tr.newDoc.toString().trim() && tr.effects.some(e => e.is(setDiagnosticsEffect))) {
83
+ return { changes: tr.changes, effects: tr.effects.filter(e => !e.is(setDiagnosticsEffect)) }
84
+ }
85
+ return tr
86
+ }),
87
+ keymap.of([...completionKeymap, ...closeBracketsKeymap, indentWithTab]),
88
+ EditorView.updateListener.of((v: ViewUpdate) => {
89
+ if (v.docChanged) {
90
+ const newval = editor.state.doc.toString()
91
+ if (value === newval) return
92
+ if (!allowInvalid) {
93
+ const effectiveSchema = getSchema(v.state)
94
+ if (!effectiveSchema || !newval.trim() || getDiagnostics(newval, effectiveSchema).some(e => e.severity === 1)) {
95
+ editorInvalid = true
96
+ dispatch('change', '')
97
+ return
98
+ }
99
+ }
100
+ editorInvalid = false
101
+ dispatch('change', newval)
102
+ }
103
+ })
104
+ ],
105
+ parent: editorelement
106
+ })
107
+ updateEditorSchema = (s?: GraphQLSchema) => { updateSchema(editor, stripMutations(s)) }
108
+ updateCode = code => {
109
+ if (editorInvalid) return
110
+ if (editor.state.doc.toString() !== code) editor.update([editor.state.update({ changes: { from: 0, to: editor.state.doc.length, insert: code } })])
111
+ }
112
+ inputelement = editorelement?.querySelector('.cm-content') ?? undefined
113
+ if (id) inputelement?.setAttribute('id', id)
114
+ if (className) inputelement?.classList.add(...className.split(' '), ...[])
115
+ updateValidState()
116
+ })
117
+ onDestroy(() => {
118
+ editor?.destroy()
119
+ })
120
+ $: updateCode?.(value ?? '')
121
+ $: updateEditorSchema?.(schema)
122
+ function updateValidState (..._: any[]) {
123
+ inputelement?.setAttribute('aria-invalid', String(!!invalid))
124
+ const descby = getDescribedBy([messagesid, helptextid, extradescid])
125
+ if (descby) inputelement?.setAttribute('aria-describedby', descby)
126
+ else inputelement?.removeAttribute('aria-describedby')
127
+ }
128
+ $: updateValidState(invalid, messagesid)
129
+ </script>
130
+
131
+ <div bind:this={editorelement} style:--cm-editor-minh="{rows * 1.5}em" class:valid class:invalid on:paste on:focusout use:passActions={use}></div>
132
+
133
+ <style>
134
+ div {
135
+ background-color: white;
136
+ }
137
+ div :global(.cm-content), div :global(.cm-gutter) {
138
+ min-height: var(--cm-editor-minh, 10em);
139
+ }
140
+
141
+ div :global(.cm-scroller) {
142
+ overflow: auto;
143
+ resize: vertical;
144
+ }
145
+ </style>
@@ -0,0 +1,35 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import { type HTMLActionEntry } from '@txstate-mws/svelte-components';
3
+ import type { GraphQLSchema } from 'graphql';
4
+ declare const __propDef: {
5
+ props: {
6
+ class?: string;
7
+ id?: string | undefined;
8
+ rows?: number;
9
+ schema?: GraphQLSchema | undefined;
10
+ noMutations?: boolean;
11
+ allowInvalid?: boolean;
12
+ use?: HTMLActionEntry[];
13
+ inputelement?: HTMLElement | undefined;
14
+ extradescid?: string | undefined;
15
+ helptextid?: string | undefined;
16
+ messagesid?: string | undefined;
17
+ valid?: boolean | undefined;
18
+ invalid?: boolean | undefined;
19
+ value: any;
20
+ };
21
+ events: {
22
+ paste: ClipboardEvent;
23
+ focusout: FocusEvent;
24
+ change: CustomEvent<any>;
25
+ } & {
26
+ [evt: string]: CustomEvent<any>;
27
+ };
28
+ slots: {};
29
+ };
30
+ export type GraphQLEditorProps = typeof __propDef.props;
31
+ export type GraphQLEditorEvents = typeof __propDef.events;
32
+ export type GraphQLEditorSlots = typeof __propDef.slots;
33
+ export default class GraphQLEditor extends SvelteComponentTyped<GraphQLEditorProps, GraphQLEditorEvents, GraphQLEditorSlots> {
34
+ }
35
+ export {};
@@ -0,0 +1,186 @@
1
+ <script lang="ts">
2
+ import { type HTMLActionEntry, passActions } from '@txstate-mws/svelte-components'
3
+ import type { EditorView, ViewUpdate } from '@codemirror/view'
4
+ import type { CompletionSource } from '@codemirror/autocomplete'
5
+ import type { CompilerOptions } from 'typescript'
6
+ import type { Diagnostic } from '@codemirror/lint'
7
+ import { createEventDispatcher, onDestroy, onMount } from 'svelte'
8
+ import { getDescribedBy } from '..'
9
+ let className = ''
10
+ export { className as class }
11
+ export let id: string | undefined = undefined
12
+ export let rows = 8
13
+ export let preamble = ''
14
+ export let sandbox = false
15
+ export let use: HTMLActionEntry[] = []
16
+ export let inputelement: HTMLElement | undefined = undefined
17
+ export let extradescid: string | undefined = undefined
18
+ export let helptextid: string | undefined = undefined
19
+ export let messagesid: string | undefined = undefined
20
+ export let valid: boolean | undefined = undefined
21
+ export let invalid: boolean | undefined = undefined
22
+ export let value: any
23
+
24
+ const dispatch = createEventDispatcher()
25
+
26
+ const PREAMBLE_PATH = '/preamble.ts'
27
+ const FILE_PATH = '/input.ts'
28
+
29
+ let updateCode: (code: string) => void
30
+ let updatePreamble: (preamble: string) => void
31
+ let editorelement: HTMLElement | undefined
32
+ let editor: EditorView
33
+ onMount(async () => {
34
+ const [
35
+ { EditorView, minimalSetup },
36
+ { indentWithTab },
37
+ { lineNumbers, highlightActiveLine, highlightActiveLineGutter, keymap },
38
+ { autocompletion, completionKeymap, closeBracketsKeymap },
39
+ { indentOnInput },
40
+ { javascript },
41
+ { tsFacet, tsSync, tsHover },
42
+ ts,
43
+ { createDefaultMapFromCDN, createSystem, createVirtualTypeScriptEnvironment }
44
+ ] = await Promise.all([
45
+ import('codemirror'),
46
+ import('@codemirror/commands'),
47
+ import('@codemirror/view'),
48
+ import('@codemirror/autocomplete'),
49
+ import('@codemirror/language'),
50
+ import('@codemirror/lang-javascript'),
51
+ import('@valtown/codemirror-ts'),
52
+ import('typescript'),
53
+ import('@typescript/vfs')
54
+ ])
55
+
56
+ const compilerOptions: CompilerOptions = {
57
+ target: ts.ScriptTarget.ES2024,
58
+ module: ts.ModuleKind.ESNext,
59
+ lib: ['es2024'],
60
+ strict: true
61
+ }
62
+
63
+ const fsMap = await createDefaultMapFromCDN(compilerOptions, ts.version, true, ts, undefined, fetch)
64
+ fsMap.set(PREAMBLE_PATH, preamble)
65
+ fsMap.set(FILE_PATH, value ?? '')
66
+
67
+ // knownLibFilesForCompilerOptions may include legacy files not on CDN
68
+ // ensure all expected lib files exist so TS doesn't throw
69
+ // note: @typescript/vfs has a bug where empty string content is treated as
70
+ // missing (falsy check in getScriptSnapshot), so we use a space
71
+ const { knownLibFilesForCompilerOptions } = await import('@typescript/vfs')
72
+ for (const lib of knownLibFilesForCompilerOptions(compilerOptions, ts)) {
73
+ if (!fsMap.has('/' + lib)) fsMap.set('/' + lib, ' ')
74
+ }
75
+
76
+ fsMap.set(PREAMBLE_PATH, preamble || ' ')
77
+ fsMap.set(FILE_PATH, value || ' ')
78
+
79
+ const system = createSystem(fsMap)
80
+ const env = createVirtualTypeScriptEnvironment(system, [PREAMBLE_PATH, FILE_PATH], ts, compilerOptions)
81
+
82
+ const tsComplete: CompletionSource = context => {
83
+ const content = env.getSourceFile(FILE_PATH)?.getFullText()
84
+ if (!content) return null
85
+ const line = context.state.doc.lineAt(context.pos)
86
+ const textBefore = line.text.slice(0, context.pos - line.from)
87
+ const wordMatch = textBefore.match(/\w*$/v)
88
+ const dotMatch = textBefore.match(/\.\s*$/v)
89
+ if (!wordMatch?.[0] && !dotMatch && !context.explicit) return null
90
+ const from = context.pos - (wordMatch?.[0].length ?? 0)
91
+ const completions = env.languageService.getCompletionsAtPosition(FILE_PATH, context.pos, {})
92
+ if (!completions) return null
93
+ return {
94
+ from,
95
+ options: completions.entries.map(entry => ({
96
+ label: entry.name,
97
+ type: entry.kind
98
+ }))
99
+ }
100
+ }
101
+
102
+ const { linter } = await import('@codemirror/lint')
103
+ const importPattern = /\b(import|require)\s*(\(|['"]|\{?\s*['"])/gv
104
+ const sandboxLinter = linter(view => {
105
+ if (!sandbox) return []
106
+ const diagnostics: Diagnostic[] = []
107
+ const doc = view.state.doc
108
+ for (let i = 1; i <= doc.lines; i++) {
109
+ const line = doc.line(i)
110
+ let match: RegExpExecArray | null
111
+ importPattern.lastIndex = 0
112
+ while ((match = importPattern.exec(line.text)) !== null) {
113
+ diagnostics.push({
114
+ from: line.from + match.index,
115
+ to: line.from + match.index + match[0].length,
116
+ severity: 'error',
117
+ message: 'Imports are not allowed in this editor'
118
+ })
119
+ }
120
+ }
121
+ return diagnostics
122
+ })
123
+
124
+ editor = new EditorView({
125
+ extensions: [
126
+ minimalSetup,
127
+ lineNumbers(),
128
+ highlightActiveLine(),
129
+ highlightActiveLineGutter(),
130
+ javascript({ typescript: true }),
131
+ autocompletion({ override: [tsComplete] }),
132
+ sandboxLinter,
133
+ indentOnInput(),
134
+ tsFacet.of({ env, path: FILE_PATH }),
135
+ tsSync(),
136
+ tsHover(),
137
+ keymap.of([...completionKeymap, ...closeBracketsKeymap, indentWithTab]),
138
+ EditorView.updateListener.of((v: ViewUpdate) => {
139
+ if (v.docChanged) {
140
+ const newval = editor.state.doc.toString()
141
+ if (value !== newval) dispatch('change', newval)
142
+ }
143
+ })
144
+ ],
145
+ parent: editorelement
146
+ })
147
+ updatePreamble = (text: string) => {
148
+ env.updateFile(PREAMBLE_PATH, text)
149
+ }
150
+ updateCode = code => {
151
+ if (editor.state.doc.toString() !== code) editor.update([editor.state.update({ changes: { from: 0, to: editor.state.doc.length, insert: code } })])
152
+ }
153
+ inputelement = editorelement?.querySelector('.cm-content') ?? undefined
154
+ if (id) inputelement?.setAttribute('id', id)
155
+ if (className) inputelement?.classList.add(...className.split(' '), ...[])
156
+ updateValidState()
157
+ })
158
+ onDestroy(() => {
159
+ editor?.destroy()
160
+ })
161
+ $: updateCode?.(value ?? '')
162
+ $: updatePreamble?.(preamble)
163
+ function updateValidState (..._: any[]) {
164
+ inputelement?.setAttribute('aria-invalid', String(!!invalid))
165
+ const descby = getDescribedBy([messagesid, helptextid, extradescid])
166
+ if (descby) inputelement?.setAttribute('aria-describedby', descby)
167
+ else inputelement?.removeAttribute('aria-describedby')
168
+ }
169
+ $: updateValidState(invalid, messagesid)
170
+ </script>
171
+
172
+ <div bind:this={editorelement} style:--cm-editor-minh="{rows * 1.5}em" class:valid class:invalid on:paste on:focusout use:passActions={use}></div>
173
+
174
+ <style>
175
+ div {
176
+ background-color: white;
177
+ }
178
+ div :global(.cm-content), div :global(.cm-gutter) {
179
+ min-height: var(--cm-editor-minh, 10em);
180
+ }
181
+
182
+ div :global(.cm-scroller) {
183
+ overflow: auto;
184
+ resize: vertical;
185
+ }
186
+ </style>
@@ -0,0 +1,33 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import { type HTMLActionEntry } from '@txstate-mws/svelte-components';
3
+ declare const __propDef: {
4
+ props: {
5
+ class?: string;
6
+ id?: string | undefined;
7
+ rows?: number;
8
+ preamble?: string;
9
+ sandbox?: boolean;
10
+ use?: HTMLActionEntry[];
11
+ inputelement?: HTMLElement | undefined;
12
+ extradescid?: string | undefined;
13
+ helptextid?: string | undefined;
14
+ messagesid?: string | undefined;
15
+ valid?: boolean | undefined;
16
+ invalid?: boolean | undefined;
17
+ value: any;
18
+ };
19
+ events: {
20
+ paste: ClipboardEvent;
21
+ focusout: FocusEvent;
22
+ change: CustomEvent<any>;
23
+ } & {
24
+ [evt: string]: CustomEvent<any>;
25
+ };
26
+ slots: {};
27
+ };
28
+ export type TypeScriptEditorProps = typeof __propDef.props;
29
+ export type TypeScriptEditorEvents = typeof __propDef.events;
30
+ export type TypeScriptEditorSlots = typeof __propDef.slots;
31
+ export default class TypeScriptEditor extends SvelteComponentTyped<TypeScriptEditorProps, TypeScriptEditorEvents, TypeScriptEditorSlots> {
32
+ }
33
+ export {};
@@ -1 +1,3 @@
1
1
  export { default as FieldCodeEditor } from './FieldCodeEditor.svelte';
2
+ export { default as FieldGraphQLEditor } from './FieldGraphQLEditor.svelte';
3
+ export { default as FieldTypeScriptEditor } from './FieldTypeScriptEditor.svelte';
@@ -1 +1,3 @@
1
1
  export { default as FieldCodeEditor } from './FieldCodeEditor.svelte';
2
+ export { default as FieldGraphQLEditor } from './FieldGraphQLEditor.svelte';
3
+ export { default as FieldTypeScriptEditor } from './FieldTypeScriptEditor.svelte';
@@ -11,8 +11,8 @@
11
11
  export { className as class }
12
12
  export let path: string
13
13
  export let options: ColorPickerOption[]
14
- export let addAllOption: boolean = false
15
- export let label: string = ''
14
+ export let addAllOption = false
15
+ export let label = ''
16
16
  export let required = false
17
17
  export let notNull = false
18
18
  export let defaultValue: any = notNull ? (addAllOption ? 'alternating' : options[0].value) : undefined
@@ -12,9 +12,9 @@
12
12
  export let id: string | undefined = undefined
13
13
  export let path: string
14
14
  export let imageSrc: string | undefined
15
- export let selectionAspectRatio: number = 1
16
- export let minSelection: number = 0 // percentage of image, a value 0-1
17
- export let label: string = ''
15
+ export let selectionAspectRatio = 1
16
+ export let minSelection = 0 // percentage of image, a value 0-1
17
+ export let label = ''
18
18
  export let required = false
19
19
  export let conditional: boolean | undefined = undefined
20
20
  export let helptext: string | undefined = undefined
@@ -29,7 +29,7 @@
29
29
 
30
30
  $: cropperStore.setOutput($val)
31
31
  function reactToOutput (...args: any[]) {
32
- if (mounted) store.setField(finalPath, $output)
32
+ if (mounted) void store.setField(finalPath, $output)
33
33
  }
34
34
  $: reactToOutput($output)
35
35
 
@@ -132,12 +132,10 @@
132
132
  if (initialLoad) {
133
133
  initialVal = e.target.src
134
134
  initialLoad = false
135
- } else {
136
- if (e.target.src !== initialVal || srcChanged) {
137
- await tick()
138
- cropperStore.maximize()
139
- srcChanged = true
140
- }
135
+ } else if (e.target.src !== initialVal || srcChanged) {
136
+ await tick()
137
+ cropperStore.maximize()
138
+ srcChanged = true
141
139
  }
142
140
  }
143
141
  </script>
@@ -4,9 +4,7 @@ const edgeSensitivity = 4;
4
4
  export class CropperStore extends Store {
5
5
  // coordinates of the selection edges relative to the top left of the draw area, in pixels
6
6
  // e.g. { left: 0, right: 10 } means the selection is 10 pixels wide
7
- selection = derivedStore(this, v => {
8
- return this.convertToPx(v.selection, v.width, v.height);
9
- });
7
+ selection = derivedStore(this, v => this.convertToPx(v.selection, v.width, v.height));
10
8
  output = derivedStore(this, 'selection');
11
9
  outputPct = derivedStore(this, v => v.selection ? ({ left: v.selection.left * 100, top: v.selection.top * 100, right: v.selection.right * 100, bottom: v.selection.bottom * 100 }) : undefined);
12
10
  constructor(initialValue) {
@@ -39,8 +37,8 @@ export class CropperStore extends Store {
39
37
  selection.bottom = centerY + newHeight / 2;
40
38
  // shrink the box until its width and height are less than the width and height of the drawing area
41
39
  // maintaining the center
42
- let selWidth = selection.right - selection.left;
43
- let selHeight = selection.bottom - selection.top;
40
+ const selWidth = selection.right - selection.left;
41
+ const selHeight = selection.bottom - selection.top;
44
42
  if (selWidth > v.width || selHeight > v.height) {
45
43
  const scale = Math.min(v.width / selWidth, v.height / selHeight);
46
44
  const cX = (selection.left + selection.right) / 2;
@@ -82,12 +80,12 @@ export class CropperStore extends Store {
82
80
  right: Math.abs(selection.right - x) < edgeSensitivity,
83
81
  bottom: Math.abs(selection.bottom - y) < edgeSensitivity
84
82
  };
85
- if ((r.drag.edge.left && r.drag.edge.top) ||
86
- (r.drag.edge.top && r.drag.edge.right) ||
87
- (r.drag.edge.right && r.drag.edge.bottom) ||
88
- (r.drag.edge.bottom && r.drag.edge.left) ||
89
- (x > selection.left && x < selection.right &&
90
- y > selection.top && y < selection.bottom))
83
+ if ((r.drag.edge.left && r.drag.edge.top)
84
+ || (r.drag.edge.top && r.drag.edge.right)
85
+ || (r.drag.edge.right && r.drag.edge.bottom)
86
+ || (r.drag.edge.bottom && r.drag.edge.left)
87
+ || (x > selection.left && x < selection.right
88
+ && y > selection.top && y < selection.bottom))
91
89
  r.drag.selection = selection;
92
90
  }
93
91
  return r;