@dataloop-ai/components 0.18.63 → 0.18.65

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@dataloop-ai/components",
3
- "version": "0.18.63",
3
+ "version": "0.18.65",
4
4
  "exports": {
5
5
  ".": "./index.ts",
6
6
  "./models": "./models.ts",
@@ -0,0 +1,73 @@
1
+ import { computed, reactive } from 'vue-demi'
2
+
3
+ export interface DlComponentsState {
4
+ theme: 'light' | 'dark'
5
+ locale: 'en' | 'es'
6
+ disableDebounce: boolean
7
+ }
8
+
9
+ export class StateManager {
10
+ private static _instance: StateManager | null = null
11
+ public static get instance(): StateManager {
12
+ if (StateManager._instance === null) {
13
+ StateManager._instance = new StateManager()
14
+ }
15
+ return StateManager._instance
16
+ }
17
+
18
+ private _state: DlComponentsState = null
19
+
20
+ private constructor() {
21
+ this._state = reactive({
22
+ theme: 'light',
23
+ locale: 'en',
24
+ disableDebounce: false
25
+ })
26
+ }
27
+
28
+ public get state(): DlComponentsState {
29
+ return this._state
30
+ }
31
+
32
+ // public theme = computed({
33
+ // get: () => this._state.theme,
34
+ // set: (theme: 'light' | 'dark') => {
35
+ // this._state.theme = theme
36
+ // }
37
+ // })
38
+
39
+ // public disableDebounce = computed({
40
+ // get: () => this._state.disableDebounce,
41
+ // set: (disableDebounce: boolean) => {
42
+ // this._state.disableDebounce = disableDebounce
43
+ // }
44
+ // })
45
+
46
+ // public isDarkTheme = computed(() => this._state.theme === 'dark')
47
+ // public isLightTheme = computed(() => this._state.theme === 'light')
48
+
49
+ public get theme(): 'light' | 'dark' {
50
+ return this._state.theme
51
+ }
52
+ public set theme(theme: 'light' | 'dark') {
53
+ this._state.theme = theme
54
+ }
55
+
56
+ public get disableDebounce(): boolean {
57
+ return this._state.disableDebounce
58
+ }
59
+ public set disableDebounce(value: boolean) {
60
+ this._state.disableDebounce = value
61
+ }
62
+
63
+ public get isDarkTheme(): boolean {
64
+ return this._state.theme === 'dark'
65
+ }
66
+ public get isLightTheme(): boolean {
67
+ return this._state.theme === 'light'
68
+ }
69
+ }
70
+
71
+ export const stateManager = StateManager.instance
72
+ // @ts-ignore
73
+ window.DlComponents = StateManager.instance
@@ -15,9 +15,10 @@
15
15
  :class="classes"
16
16
  :style="styles"
17
17
  >
18
- <draggable-upper
19
- v-if="draggable"
20
- @move="movePopup"
18
+ <draggable-upper
19
+ v-if="draggable"
20
+ class="popup-dialog-upper"
21
+ @move="movePopup"
21
22
  />
22
23
  <popup-header
23
24
  v-if="
@@ -376,7 +377,7 @@ export default defineComponent({
376
377
 
377
378
  function configureScrollTarget() {
378
379
  if (anchorEl.value !== null || props.scrollTarget) {
379
- (localScrollTarget as Ref<any>).value = getScrollTarget(
380
+ localScrollTarget.value = getScrollTarget(
380
381
  anchorEl.value as HTMLElement,
381
382
  props.scrollTarget
382
383
  )
@@ -505,6 +506,16 @@ export default defineComponent({
505
506
  border-radius: 2px;
506
507
  }
507
508
 
509
+ .popup-dialog-upper {
510
+ opacity: 0;
511
+ position: absolute;
512
+ top: 2px;
513
+ cursor: pointer;
514
+ }
515
+ .popup-dialog-upper:hover {
516
+ opacity: 1;
517
+ }
518
+
508
519
  .popup-content {
509
520
  max-width: 100%;
510
521
  padding: 0 16px;
@@ -1,56 +1,86 @@
1
1
  <template>
2
- <div
3
- ref="draggableUpper"
4
- class="root"
5
- />
2
+ <div
3
+ ref="draggableUpper"
4
+ class="root"
5
+ @mouseenter="visibleDragIcon = true"
6
+ @mouseleave="visibleDragIcon = false"
7
+ >
8
+ <dl-icon
9
+ class="draggable-icon"
10
+ color="dl-color-medium"
11
+ icon="icon-dl-drag"
12
+ size="12px"
13
+ @mousedown="startDragElement"
14
+ />
15
+ </div>
6
16
  </template>
7
17
 
8
18
  <script lang="ts">
9
- import { defineComponent, getCurrentInstance, onMounted } from 'vue-demi'
19
+ import { throttle } from 'lodash'
20
+ import { defineComponent, getCurrentInstance, ref } from 'vue-demi'
21
+ import { DlIcon } from '../../../essential/DlIcon'
10
22
 
11
23
  export default defineComponent({
24
+ components: {
25
+ DlIcon
26
+ },
12
27
  emits: ['move'],
13
- setup() {
14
- const vm = getCurrentInstance()
28
+ setup(props, { emit }) {
29
+ const visibleDragIcon = ref(false)
15
30
 
16
- onMounted(() => {
17
- const root = vm!.refs.draggableUpper as HTMLElement
18
- let newX = 0
19
- let newY = 0
20
- let offsetX = 0
21
- let offsetY = 0
31
+ const draggableOptions = ref({
32
+ draggableX: 0,
33
+ draggableY: 0,
34
+ originalX: 0,
35
+ originalY: 0,
36
+ draggableCursor: 'pointer'
37
+ })
22
38
 
23
- if (root) {
24
- root.onmousedown = dragMouseDown
39
+ const iconStyles = (): Record<string, string> => {
40
+ return {
41
+ cursor: draggableOptions.value.draggableCursor,
42
+ visibility: visibleDragIcon.value ? 'visible' : 'hidden'
25
43
  }
44
+ }
26
45
 
27
- function dragMouseDown(e: any) {
28
- e = e || window.event
29
- e.preventDefault()
30
-
31
- offsetX = e.layerX
32
- offsetY = e.layerY
46
+ const startDragElement = (e: MouseEvent) => {
47
+ e.preventDefault()
33
48
 
34
- newX = e.clientX
35
- newY = e.clientY
36
- document.onmouseup = closeDragElement
49
+ const target: HTMLElement = e.currentTarget as any
50
+ const iconOffsetX = target.parentElement.clientWidth / 2
51
+ const iconOffsetY = target.parentElement.clientHeight / 2
37
52
 
38
- document.onmousemove = elementDrag
53
+ if (
54
+ !draggableOptions.value.originalY &&
55
+ !draggableOptions.value.originalX
56
+ ) {
57
+ draggableOptions.value.originalY = e.y
58
+ draggableOptions.value.originalX = e.x
39
59
  }
40
60
 
41
- function elementDrag(e: any) {
42
- e = e || window.event
61
+ draggableOptions.value.draggableCursor = 'grabbing'
62
+ document.onmousemove = throttle((e: MouseEvent) => {
63
+ e = e || (window.event as MouseEvent)
43
64
  e.preventDefault()
44
- newX = e.clientX - offsetX
45
- newY = e.clientY - offsetY
46
- vm!.emit('move', newX, newY)
47
- }
65
+ const x = e.x - iconOffsetX
66
+ const y = e.y - iconOffsetY
67
+ emit('move', x, y)
68
+ }, 5)
69
+ document.onmouseup = stopDragElement
70
+ }
71
+ const stopDragElement = () => {
72
+ document.onmousemove = null
73
+ document.onmouseup = null
74
+ draggableOptions.value.draggableCursor = 'pointer'
75
+ }
48
76
 
49
- function closeDragElement() {
50
- document.onmouseup = null
51
- document.onmousemove = null
52
- }
53
- })
77
+ return {
78
+ visibleDragIcon,
79
+ draggableOptions,
80
+ iconStyles,
81
+ startDragElement,
82
+ stopDragElement
83
+ }
54
84
  }
55
85
  })
56
86
  </script>
@@ -59,6 +89,16 @@ export default defineComponent({
59
89
  .root {
60
90
  width: 100%;
61
91
  height: 10px;
92
+ display: flex;
93
+ justify-content: center;
94
+ }
95
+ .draggable-icon {
96
+ display: none;
97
+ padding: 0px 10px;
98
+ transform: rotate(90deg);
99
+ }
100
+ .draggable-icon:hover {
62
101
  cursor: move;
102
+ display: flex;
63
103
  }
64
104
  </style>
@@ -256,6 +256,7 @@ import { DlMenu, DlIcon, DlList, DlEllipsis } from '../../essential'
256
256
  import { DlButton } from '../../basic'
257
257
  import { InputSizes, TInputSizes } from '../../../utils/input-sizes'
258
258
  import { v4 } from 'uuid'
259
+ import { stateManager } from '../../../StateManager'
259
260
 
260
261
  export default defineComponent({
261
262
  name: 'DlInput',
@@ -545,6 +546,9 @@ export default defineComponent({
545
546
  return !!this.suggestItems.length && !!this.modelValue
546
547
  },
547
548
  debouncedBlur(): any {
549
+ if (stateManager.disableDebounce) {
550
+ return this.onBlur.bind(this)
551
+ }
548
552
  const debounced = debounce(this.onBlur.bind(this), 50)
549
553
  return debounced
550
554
  },
@@ -572,6 +576,9 @@ export default defineComponent({
572
576
  return classes
573
577
  },
574
578
  debouncedInput(): any {
579
+ if (stateManager.disableDebounce) {
580
+ return this.onChange.bind(this)
581
+ }
575
582
  const debounced = debounce(this.onChange.bind(this), this.debounce)
576
583
  return debounced
577
584
  }
@@ -25,6 +25,7 @@ import {
25
25
  TextContent
26
26
  } from 'vanilla-jsoneditor'
27
27
  import { debounce } from 'lodash'
28
+ import { stateManager } from '../../../StateManager'
28
29
 
29
30
  export default defineComponent({
30
31
  model: {
@@ -110,11 +111,16 @@ export default defineComponent({
110
111
  emit('change', (content as TextContent).text)
111
112
  }
112
113
 
113
- const debouncedHandleJSONChange = debounce(handleJSONChange, 100)
114
+ const debouncedHandleJSONChange = computed(() => {
115
+ if (stateManager.disableDebounce) {
116
+ return handleJSONChange
117
+ }
118
+ return debounce(handleJSONChange, 100)
119
+ })
114
120
 
115
121
  const initJsonEditor = () => {
116
122
  const initialAttrs: JSONEditorPropsOptional = {
117
- onChange: debouncedHandleJSONChange,
123
+ onChange: debouncedHandleJSONChange.value,
118
124
  indentation: indentation.value,
119
125
  mode: mode.value,
120
126
  readOnly: readonly.value || mode.value === Mode.tree,
@@ -9,6 +9,7 @@ import { defineComponent, onMounted, watch, provide, ref } from 'vue-demi'
9
9
  import { getThemeModeAttr } from '../../../utils'
10
10
  import '@dataloop-ai/icons/style.css'
11
11
  import { v4 } from 'uuid'
12
+ import { stateManager } from '../../../StateManager'
12
13
 
13
14
  export default defineComponent({
14
15
  props: {
@@ -26,8 +27,7 @@ export default defineComponent({
26
27
 
27
28
  const isDarkTheme = ref(props.isDark)
28
29
 
29
- // @ts-ignore
30
- window.DlComponents?.setTheme(props.isDark ? 'dark' : 'light')
30
+ stateManager.theme = props.isDark ? 'dark' : 'light'
31
31
 
32
32
  provide('theme', isDarkTheme)
33
33
 
@@ -40,8 +40,7 @@ export default defineComponent({
40
40
  getThemeModeAttr(isDark)
41
41
  ) // sets the dl data-theme attr
42
42
 
43
- // @ts-ignore
44
- window.DlComponents?.setTheme(props.isDark ? 'dark' : 'light')
43
+ stateManager.theme = props.isDark ? 'dark' : 'light'
45
44
  }
46
45
  )
47
46
  },
@@ -1,9 +1,5 @@
1
1
  <template>
2
2
  <div>
3
- <dl-switch
4
- v-model="isDark"
5
- left-label="Dark Mode"
6
- />
7
3
  <dl-switch
8
4
  v-model="lines"
9
5
  left-label="code lines"
@@ -17,7 +13,7 @@
17
13
  width="45vw"
18
14
  height="75vh"
19
15
  :language="language"
20
- :theme="'atom-one-dark'"
16
+ :theme="theme"
21
17
  :readonly="readonly"
22
18
  :options="options"
23
19
  />
@@ -28,6 +24,7 @@
28
24
  import { computed, defineComponent, ref, watch } from 'vue-demi'
29
25
  import { DlCodeEditor, DlSwitch } from '../../components'
30
26
  import { DlCodeEditorOptions, DlCodeEditorTheme } from '../../components/types'
27
+ import { stateManager } from '../../StateManager'
31
28
 
32
29
  export default defineComponent({
33
30
  name: 'DlCodeEditorDemo',
@@ -37,7 +34,6 @@ export default defineComponent({
37
34
  },
38
35
  setup() {
39
36
  const readonly = ref(false)
40
- const isDark = ref(false)
41
37
  const lines = ref(false)
42
38
 
43
39
  const codeEditorValue = ref(
@@ -213,7 +209,7 @@ export default defineComponent({
213
209
  const language = ref('python')
214
210
 
215
211
  const theme = computed(() => {
216
- return isDark.value
212
+ return stateManager.isDarkTheme
217
213
  ? DlCodeEditorTheme.Dark
218
214
  : DlCodeEditorTheme.Light
219
215
  })
@@ -230,7 +226,6 @@ export default defineComponent({
230
226
  lines,
231
227
  codeEditorValue,
232
228
  language,
233
- isDark,
234
229
  theme,
235
230
  readonly,
236
231
  options
@@ -20,6 +20,7 @@ import { computed, defineComponent, ref } from 'vue-demi'
20
20
  import UploadData from './UploadData.vue'
21
21
  import { DlCodeEditor } from '../../../../../components'
22
22
  import { DlCodeEditorTheme } from '../../../../../components/types'
23
+ import { stateManager } from '../../../../../StateManager'
23
24
 
24
25
  export default defineComponent({
25
26
  name: 'LayoutEmptyState',
@@ -201,13 +202,9 @@ export default defineComponent({
201
202
  const language = ref('python')
202
203
 
203
204
  const theme = computed(() => {
204
- if (
205
- // @ts-ignore
206
- window.DlComponents.isDark.value
207
- ) {
208
- return DlCodeEditorTheme.Dark
209
- }
210
- return DlCodeEditorTheme.Light
205
+ return stateManager.isDarkTheme
206
+ ? DlCodeEditorTheme.Dark
207
+ : DlCodeEditorTheme.Light
211
208
  })
212
209
 
213
210
  return {
@@ -6,6 +6,7 @@
6
6
  additional-info="Some additional information"
7
7
  subtitle="Some text for better explanation."
8
8
  with-close-button
9
+ draggable
9
10
  @close-button-click="handleClear"
10
11
  >
11
12
  <dl-text-area
package/src/index.ts CHANGED
@@ -1,28 +1,7 @@
1
- import { computed, install, reactive } from 'vue-demi'
1
+ import { install } from 'vue-demi'
2
2
 
3
3
  install()
4
4
 
5
- // @ts-ignore
6
- window.DlComponents = window.DlComponents || {
7
- state: reactive({}),
8
- setTheme: (theme: 'light' | 'dark') => {
9
- // @ts-ignore
10
- window.DlComponents.state.theme = theme
11
- },
12
- get theme(): 'light' | 'dark' {
13
- // @ts-ignore
14
- return window.DlComponents.state.theme
15
- },
16
- isDark: computed(() => {
17
- // @ts-ignore
18
- return window.DlComponents.state.theme === 'dark'
19
- }),
20
- isLight: computed(() => {
21
- // @ts-ignore
22
- return window.DlComponents.state.theme === 'light'
23
- })
24
- }
25
-
26
5
  export * from './components'
27
6
  export * from './layouts'
28
7