@instructure/ui-source-code-editor 11.6.0 → 11.6.1-snapshot-129

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 (78) hide show
  1. package/CHANGELOG.md +40 -293
  2. package/es/SourceCodeEditor/{SearchPanel.js → v1/SearchPanel.js} +2 -2
  3. package/es/SourceCodeEditor/{index.js → v1/index.js} +1 -1
  4. package/es/SourceCodeEditor/v2/SearchPanel.js +118 -0
  5. package/es/SourceCodeEditor/v2/customKeybinding.js +100 -0
  6. package/es/SourceCodeEditor/v2/index.js +535 -0
  7. package/es/SourceCodeEditor/v2/props.js +28 -0
  8. package/es/SourceCodeEditor/v2/styles.js +228 -0
  9. package/es/{index.js → exports/a.js} +1 -1
  10. package/{src/index.ts → es/exports/b.js} +1 -2
  11. package/lib/SourceCodeEditor/{SearchPanel.js → v1/SearchPanel.js} +8 -8
  12. package/lib/SourceCodeEditor/{index.js → v1/index.js} +1 -1
  13. package/lib/SourceCodeEditor/v2/SearchPanel.js +126 -0
  14. package/lib/SourceCodeEditor/v2/customKeybinding.js +105 -0
  15. package/lib/SourceCodeEditor/v2/index.js +541 -0
  16. package/lib/SourceCodeEditor/v2/props.js +33 -0
  17. package/lib/SourceCodeEditor/v2/styles.js +234 -0
  18. package/lib/{index.js → exports/a.js} +2 -2
  19. package/lib/exports/b.js +12 -0
  20. package/package.json +42 -20
  21. package/src/SourceCodeEditor/{SearchPanel.tsx → v1/SearchPanel.tsx} +2 -2
  22. package/src/SourceCodeEditor/{index.tsx → v1/index.tsx} +1 -1
  23. package/src/SourceCodeEditor/v2/README.md +799 -0
  24. package/src/SourceCodeEditor/v2/SearchPanel.tsx +150 -0
  25. package/src/SourceCodeEditor/v2/customKeybinding.ts +125 -0
  26. package/src/SourceCodeEditor/v2/index.tsx +685 -0
  27. package/src/SourceCodeEditor/v2/props.ts +263 -0
  28. package/src/SourceCodeEditor/v2/styles.ts +239 -0
  29. package/src/exports/a.ts +25 -0
  30. package/src/exports/b.ts +25 -0
  31. package/tsconfig.build.tsbuildinfo +1 -1
  32. package/types/SourceCodeEditor/v1/SearchPanel.d.ts.map +1 -0
  33. package/types/SourceCodeEditor/v1/customKeybinding.d.ts.map +1 -0
  34. package/types/SourceCodeEditor/v1/index.d.ts.map +1 -0
  35. package/types/SourceCodeEditor/v1/props.d.ts.map +1 -0
  36. package/types/SourceCodeEditor/v1/styles.d.ts.map +1 -0
  37. package/types/SourceCodeEditor/v1/theme.d.ts.map +1 -0
  38. package/types/SourceCodeEditor/v2/SearchPanel.d.ts +7 -0
  39. package/types/SourceCodeEditor/v2/SearchPanel.d.ts.map +1 -0
  40. package/types/SourceCodeEditor/v2/customKeybinding.d.ts +4 -0
  41. package/types/SourceCodeEditor/v2/customKeybinding.d.ts.map +1 -0
  42. package/types/SourceCodeEditor/v2/index.d.ts +103 -0
  43. package/types/SourceCodeEditor/v2/index.d.ts.map +1 -0
  44. package/types/SourceCodeEditor/v2/props.d.ts +142 -0
  45. package/types/SourceCodeEditor/v2/props.d.ts.map +1 -0
  46. package/types/SourceCodeEditor/v2/styles.d.ts +14 -0
  47. package/types/SourceCodeEditor/v2/styles.d.ts.map +1 -0
  48. package/types/exports/a.d.ts +3 -0
  49. package/types/exports/a.d.ts.map +1 -0
  50. package/types/exports/b.d.ts +3 -0
  51. package/types/exports/b.d.ts.map +1 -0
  52. package/types/SourceCodeEditor/SearchPanel.d.ts.map +0 -1
  53. package/types/SourceCodeEditor/customKeybinding.d.ts.map +0 -1
  54. package/types/SourceCodeEditor/index.d.ts.map +0 -1
  55. package/types/SourceCodeEditor/props.d.ts.map +0 -1
  56. package/types/SourceCodeEditor/styles.d.ts.map +0 -1
  57. package/types/SourceCodeEditor/theme.d.ts.map +0 -1
  58. package/types/index.d.ts +0 -3
  59. package/types/index.d.ts.map +0 -1
  60. /package/es/SourceCodeEditor/{customKeybinding.js → v1/customKeybinding.js} +0 -0
  61. /package/es/SourceCodeEditor/{props.js → v1/props.js} +0 -0
  62. /package/es/SourceCodeEditor/{styles.js → v1/styles.js} +0 -0
  63. /package/es/SourceCodeEditor/{theme.js → v1/theme.js} +0 -0
  64. /package/lib/SourceCodeEditor/{customKeybinding.js → v1/customKeybinding.js} +0 -0
  65. /package/lib/SourceCodeEditor/{props.js → v1/props.js} +0 -0
  66. /package/lib/SourceCodeEditor/{styles.js → v1/styles.js} +0 -0
  67. /package/lib/SourceCodeEditor/{theme.js → v1/theme.js} +0 -0
  68. /package/src/SourceCodeEditor/{README.md → v1/README.md} +0 -0
  69. /package/src/SourceCodeEditor/{customKeybinding.ts → v1/customKeybinding.ts} +0 -0
  70. /package/src/SourceCodeEditor/{props.ts → v1/props.ts} +0 -0
  71. /package/src/SourceCodeEditor/{styles.ts → v1/styles.ts} +0 -0
  72. /package/src/SourceCodeEditor/{theme.ts → v1/theme.ts} +0 -0
  73. /package/types/SourceCodeEditor/{SearchPanel.d.ts → v1/SearchPanel.d.ts} +0 -0
  74. /package/types/SourceCodeEditor/{customKeybinding.d.ts → v1/customKeybinding.d.ts} +0 -0
  75. /package/types/SourceCodeEditor/{index.d.ts → v1/index.d.ts} +0 -0
  76. /package/types/SourceCodeEditor/{props.d.ts → v1/props.d.ts} +0 -0
  77. /package/types/SourceCodeEditor/{styles.d.ts → v1/styles.d.ts} +0 -0
  78. /package/types/SourceCodeEditor/{theme.d.ts → v1/theme.d.ts} +0 -0
@@ -0,0 +1,150 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import { useState } from 'react'
26
+ import {
27
+ setSearchQuery,
28
+ search,
29
+ findNext,
30
+ findPrevious,
31
+ SearchQuery,
32
+ closeSearchPanel
33
+ } from '@codemirror/search'
34
+ import { EditorView } from '@codemirror/view'
35
+ import { TextInput } from '@instructure/ui-text-input/latest'
36
+ import { IconButton } from '@instructure/ui-buttons/latest'
37
+ import {
38
+ IconArrowOpenDownLine,
39
+ IconArrowOpenUpLine,
40
+ IconSearchLine
41
+ } from '@instructure/ui-icons'
42
+ import { createRoot } from 'react-dom/client'
43
+
44
+ export type SearchConfig = {
45
+ placeholder: string
46
+ nextResultLabel: string
47
+ prevResultLabel: string
48
+ }
49
+
50
+ function SearchPanel({
51
+ view,
52
+ searchConfig
53
+ }: {
54
+ view: EditorView
55
+ searchConfig: SearchConfig
56
+ }) {
57
+ const [searchQueryStr, setSearchQueryStr] = useState('')
58
+
59
+ const handleChange = (
60
+ _e: React.ChangeEvent<HTMLInputElement>,
61
+ value: string
62
+ ) => {
63
+ setSearchQueryStr(value)
64
+ handleHighlightSearch(value)
65
+ }
66
+
67
+ const handleHighlightSearch = (searchStr: string) => {
68
+ view.dispatch({
69
+ effects: setSearchQuery.of(
70
+ new SearchQuery({
71
+ search: searchStr
72
+ })
73
+ )
74
+ })
75
+ }
76
+
77
+ const handleKeyDown = (e: React.KeyboardEvent) => {
78
+ if (e.key !== 'Enter') return
79
+ if (!e.shiftKey) handleFindNext()
80
+ else handleFindPrev()
81
+ }
82
+
83
+ const handleKeyUp = (e: React.KeyboardEvent) => {
84
+ if (e.key !== 'Escape') return
85
+ closeSearchPanel(view)
86
+ }
87
+
88
+ const handleFindNext = () => {
89
+ handleHighlightSearch(searchQueryStr)
90
+ findNext(view)
91
+ }
92
+
93
+ const handleFindPrev = () => {
94
+ handleHighlightSearch(searchQueryStr)
95
+ findPrevious(view)
96
+ }
97
+
98
+ return (
99
+ <TextInput
100
+ renderLabel=""
101
+ inputRef={(r: HTMLInputElement | null) => {
102
+ setTimeout(() => r?.focus(), 0)
103
+ }}
104
+ size="small"
105
+ display="inline-block"
106
+ width="20rem"
107
+ placeholder={searchConfig.placeholder}
108
+ onChange={handleChange}
109
+ onKeyDown={handleKeyDown}
110
+ onKeyUp={handleKeyUp}
111
+ renderBeforeInput={<IconSearchLine size="x-small" />}
112
+ renderAfterInput={
113
+ <span>
114
+ <IconButton
115
+ size="small"
116
+ withBorder={false}
117
+ withBackground={false}
118
+ onClick={handleFindNext}
119
+ screenReaderLabel={searchConfig.nextResultLabel}
120
+ >
121
+ <IconArrowOpenDownLine />
122
+ </IconButton>
123
+ <IconButton
124
+ size="small"
125
+ withBorder={false}
126
+ withBackground={false}
127
+ onClick={handleFindPrev}
128
+ screenReaderLabel={searchConfig.prevResultLabel}
129
+ >
130
+ <IconArrowOpenUpLine />
131
+ </IconButton>
132
+ </span>
133
+ }
134
+ />
135
+ )
136
+ }
137
+
138
+ export default function customSearch(searchConfig: SearchConfig | undefined) {
139
+ return searchConfig
140
+ ? search({
141
+ createPanel: (view) => {
142
+ const dom = document.createElement('div')
143
+ dom.style.padding = '8px'
144
+ const root = createRoot(dom)
145
+ root.render(<SearchPanel view={view} searchConfig={searchConfig} />)
146
+ return { dom }
147
+ }
148
+ })
149
+ : []
150
+ }
@@ -0,0 +1,125 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import {
26
+ cursorCharLeft,
27
+ cursorCharRight,
28
+ cursorGroupLeft,
29
+ cursorGroupRight,
30
+ cursorLineBoundaryLeft,
31
+ cursorLineBoundaryRight,
32
+ cursorLineBoundaryBackward,
33
+ cursorLineBoundaryForward,
34
+ cursorSyntaxLeft,
35
+ cursorSyntaxRight,
36
+ deleteCharBackward,
37
+ deleteCharForward,
38
+ deleteGroupBackward,
39
+ deleteGroupForward,
40
+ deleteToLineEnd,
41
+ deleteToLineStart,
42
+ selectCharLeft,
43
+ selectCharRight,
44
+ selectGroupLeft,
45
+ selectGroupRight,
46
+ selectLineBoundaryLeft,
47
+ selectLineBoundaryRight,
48
+ selectLineBoundaryBackward,
49
+ selectLineBoundaryForward,
50
+ selectSyntaxLeft,
51
+ selectSyntaxRight
52
+ } from '@codemirror/commands'
53
+ import type { KeyBinding } from '@codemirror/view'
54
+
55
+ const rtlHorizontalArrowKeymap: KeyBinding[] = [
56
+ // Left/Start/Forward
57
+ {
58
+ key: 'ArrowLeft',
59
+ run: cursorCharRight,
60
+ shift: selectCharRight,
61
+ preventDefault: true
62
+ },
63
+ {
64
+ key: 'Mod-ArrowLeft',
65
+ mac: 'Alt-ArrowLeft',
66
+ run: cursorGroupRight,
67
+ shift: selectGroupRight
68
+ },
69
+ {
70
+ key: 'Alt-ArrowLeft',
71
+ mac: 'Ctrl-ArrowLeft',
72
+ run: cursorSyntaxRight,
73
+ shift: selectSyntaxRight
74
+ },
75
+ {
76
+ mac: 'Cmd-ArrowLeft',
77
+ run: cursorLineBoundaryRight,
78
+ shift: selectLineBoundaryRight
79
+ },
80
+ {
81
+ key: 'Home',
82
+ run: cursorLineBoundaryForward,
83
+ shift: selectLineBoundaryForward
84
+ },
85
+
86
+ // Right/End/Backward
87
+ {
88
+ key: 'ArrowRight',
89
+ run: cursorCharLeft,
90
+ shift: selectCharLeft,
91
+ preventDefault: true
92
+ },
93
+ {
94
+ key: 'Mod-ArrowRight',
95
+ mac: 'Alt-ArrowRight',
96
+ run: cursorGroupLeft,
97
+ shift: selectGroupLeft
98
+ },
99
+ {
100
+ key: 'Alt-ArrowRight',
101
+ mac: 'Ctrl-ArrowRight',
102
+ run: cursorSyntaxLeft,
103
+ shift: selectSyntaxLeft
104
+ },
105
+ {
106
+ mac: 'Cmd-ArrowRight',
107
+ run: cursorLineBoundaryLeft,
108
+ shift: selectLineBoundaryLeft
109
+ },
110
+ {
111
+ key: 'End',
112
+ run: cursorLineBoundaryBackward,
113
+ shift: selectLineBoundaryBackward
114
+ },
115
+
116
+ // Delete/Backspace
117
+ { key: 'Delete', run: deleteCharBackward },
118
+ { key: 'Mod-Delete', mac: 'Alt-Delete', run: deleteGroupBackward },
119
+ { key: 'Backspace', run: deleteCharForward, shift: deleteCharForward },
120
+ { key: 'Mod-Backspace', mac: 'Alt-Backspace', run: deleteGroupForward },
121
+ { mac: 'Mod-Delete', run: deleteToLineStart },
122
+ { mac: 'Mod-Backspace', run: deleteToLineEnd }
123
+ ]
124
+
125
+ export { rtlHorizontalArrowKeymap }