@dataloop-ai/components 0.19.183 → 0.19.185

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.19.183",
3
+ "version": "0.19.185",
4
4
  "exports": {
5
5
  ".": "./index.ts",
6
6
  "./models": "./models.ts",
@@ -22,7 +22,7 @@
22
22
  "check-only": "if grep -E -H -r --exclude-dir=.git --exclude-dir=node_modules --exclude=*.json --exclude=*.yml '^(describe|it).only' .; then echo 'Found only in test files' && exit 1; fi"
23
23
  },
24
24
  "dependencies": {
25
- "@dataloop-ai/icons": "^3.0.31",
25
+ "@dataloop-ai/icons": "^3.0.32",
26
26
  "@types/flat": "^5.0.2",
27
27
  "@types/lodash": "^4.14.184",
28
28
  "@types/sortablejs": "^1.15.7",
@@ -30,6 +30,7 @@
30
30
  "flat": "^5.0.2",
31
31
  "highlight.js": "^11.8.0",
32
32
  "lodash": "^4.17.21",
33
+ "marked": "^11.1.1",
33
34
  "moment": "^2.29.4",
34
35
  "sass": "^1.51.0",
35
36
  "sass-loader": "^12.6.0",
@@ -39,7 +40,8 @@
39
40
  "vanilla-jsoneditor": "^0.10.2",
40
41
  "vue-demi": "^0.14.5",
41
42
  "vue-sortable": "^0.1.3",
42
- "vue2-teleport": "^1.0.1"
43
+ "vue2-teleport": "^1.0.1",
44
+ "zero-md": "^2.5.3"
43
45
  },
44
46
  "devDependencies": {
45
47
  "@babel/core": "^7.17.9",
@@ -37,7 +37,14 @@
37
37
  <script lang="ts">
38
38
  import { isString } from 'lodash'
39
39
  import { v4 } from 'uuid'
40
- import { defineComponent } from 'vue-demi'
40
+ import {
41
+ computed,
42
+ defineComponent,
43
+ onUnmounted,
44
+ ref,
45
+ toRefs,
46
+ watch
47
+ } from 'vue-demi'
41
48
  import { getColor, loggerFactory, stringStyleToRecord } from '../../../utils'
42
49
  import { COLORED_ICONS } from '@dataloop-ai/icons/types'
43
50
 
@@ -74,100 +81,130 @@ export default defineComponent({
74
81
  }
75
82
  },
76
83
  emits: ['click', 'mousemove', 'mouseup', 'mousedown'],
77
- data() {
78
- return {
79
- uuid: `dl-icon-${v4()}`,
80
- externalIconSource: 'material-icons',
81
- logger_: loggerFactory('dl-icon')
82
- }
83
- },
84
- computed: {
85
- computedStyles(): Record<string, string> {
86
- return isString(this.styles)
87
- ? stringStyleToRecord(this.styles)
88
- : this.styles
89
- },
90
- cssIconVars(): Record<string, string> {
84
+ setup(props) {
85
+ const { styles, color, size, icon, svg, inline, svgSource } =
86
+ toRefs(props)
87
+
88
+ const svgIcon = ref(null)
89
+ const isDestroyed = ref(false)
90
+ const uuid = `dl-icon-${v4()}`
91
+ const externalIconSource = 'material-icons'
92
+ const logger = loggerFactory('dl-icon')
93
+
94
+ const computedStyles = computed<Record<string, string>>(() => {
95
+ const generatedStyles = isString(styles.value)
96
+ ? stringStyleToRecord(styles.value)
97
+ : styles.value
98
+
99
+ return Object.assign({}, generatedStyles, {
100
+ width: size.value,
101
+ height: size.value
102
+ })
103
+ })
104
+
105
+ const cssIconVars = computed<Record<string, string>>(() => {
91
106
  return {
92
- '--dl-icon-font-size': `${this.size}`,
93
- '--dl-icon-color': this.color
107
+ '--dl-icon-font-size': `${size.value}`,
108
+ '--dl-icon-color': color.value
94
109
  ? // todo: remove this. this is needed for now until the swap of DLBTN in OA
95
110
  getColor(
96
- this.color === 'secondary'
111
+ color.value === 'secondary'
97
112
  ? 'q-color-secondary'
98
- : this.color,
113
+ : color.value,
99
114
  'dl-color-icon-default'
100
115
  )
101
116
  : 'inherit'
102
117
  }
103
- },
104
- inlineStyles(): Record<string, string> {
105
- return { display: this.inline ? 'inline-flex' : 'flex' }
106
- },
107
- // needed to allow external source of icons that do not use class based
108
- externalIcon(): boolean {
109
- return (
110
- !this.icon.startsWith('icon-dl-') &&
111
- !this.icon.startsWith('fas') &&
112
- !this.icon.startsWith('fa-')
113
- )
114
- },
115
- cleanedIconName(): string {
116
- return this.icon.startsWith('icon-dl-')
117
- ? this.icon.replace('icon-dl-', '')
118
- : this.icon
119
- },
120
- isSVG(): boolean {
121
- if (!this.icon) {
118
+ })
119
+
120
+ const cleanedIconName = computed<string>(() => {
121
+ return icon.value.startsWith('icon-dl-')
122
+ ? icon.value.replace('icon-dl-', '')
123
+ : icon.value
124
+ })
125
+
126
+ const isSVG = computed<boolean>(() => {
127
+ if (!icon.value) {
122
128
  return false
123
129
  }
124
130
 
125
- if (this.svg) {
131
+ if (svg.value) {
126
132
  return true
127
133
  }
128
134
 
129
135
  const coloredIcons = Object.values(COLORED_ICONS)
130
- return coloredIcons.includes(this.cleanedIconName as any)
131
- }
132
- },
133
- mounted() {
134
- const possibleToLoadSvg = this.isSVG && this.icon && this.icon !== ''
135
- if (possibleToLoadSvg) {
136
- this.loadSvg()
137
- }
138
- },
139
- methods: {
140
- loadSvg() {
136
+ return coloredIcons.includes(cleanedIconName.value as any)
137
+ })
138
+
139
+ const externalIcon = computed<boolean>(() => {
140
+ return (
141
+ !icon.value.startsWith('icon-dl-') &&
142
+ !icon.value.startsWith('fas') &&
143
+ !icon.value.startsWith('fa-')
144
+ )
145
+ })
146
+
147
+ const inlineStyles = computed<Record<string, string>>(() => {
148
+ return { display: inline.value ? 'inline-flex' : 'flex' }
149
+ })
150
+
151
+ watch(icon, () => {
152
+ const possibleToLoadSvg =
153
+ isSVG.value && icon.value && icon.value !== ''
154
+ if (possibleToLoadSvg) {
155
+ loadSvg()
156
+ }
157
+ })
158
+
159
+ const loadSvg = () => {
141
160
  return new Promise<void>((resolve, reject) => {
142
161
  const svgElement = new Image()
143
- svgElement.setAttribute('height', this.size)
144
- svgElement.setAttribute('width', this.size)
162
+ svgElement.setAttribute('height', size.value)
163
+ svgElement.setAttribute('width', size.value)
145
164
 
146
165
  svgElement.onload = () => {
147
- // @ts-ignore // In order to handle events and loading that occur mid unmounting.
148
- if (this._isDestroyed || this._isBeingDestroyed) {
166
+ // In order to handle events and loading that occur mid unmounting.
167
+ if (isDestroyed.value) {
149
168
  return
150
169
  }
151
- const container = this.$refs.svgIcon as HTMLDivElement
170
+ const container = svgIcon.value as HTMLDivElement
152
171
  if (!container) {
153
172
  reject(new Error('No Ref'))
154
173
  return
155
174
  }
156
- container.setAttribute('height', this.size)
157
- container.setAttribute('width', this.size)
175
+ container.setAttribute('height', size.value)
176
+ container.setAttribute('width', size.value)
158
177
  container?.firstChild?.replaceWith(svgElement)
159
178
  resolve()
160
179
  }
161
180
 
162
181
  try {
163
- svgElement.src = this.svgSource
164
- ? `${this.svgSource}/${this.cleanedIconName}.svg`
165
- : `https://raw.githubusercontent.com/dataloop-ai/icons/main/assets/${this.cleanedIconName}.svg`
182
+ svgElement.src = svgSource.value
183
+ ? `${svgSource.value}/${cleanedIconName.value}.svg`
184
+ : `https://raw.githubusercontent.com/dataloop-ai/icons/main/assets/${cleanedIconName.value}.svg`
166
185
  } catch (e) {
167
186
  reject(e)
168
187
  }
169
188
  })
170
189
  }
190
+
191
+ onUnmounted(() => {
192
+ isDestroyed.value = true
193
+ })
194
+
195
+ return {
196
+ uuid,
197
+ svgIcon,
198
+ externalIconSource,
199
+ computedStyles,
200
+ cssIconVars,
201
+ isSVG,
202
+ cleanedIconName,
203
+ loadSvg,
204
+ isDestroyed,
205
+ externalIcon,
206
+ inlineStyles
207
+ }
171
208
  }
172
209
  })
173
210
  </script>
@@ -0,0 +1,28 @@
1
+ <template>
2
+ <div class="dl-mark-down" v-html="renderedMD" />
3
+ </template>
4
+
5
+ <script lang="ts">
6
+ import { defineComponent, computed, toRefs } from 'vue-demi'
7
+ import { marked } from 'marked'
8
+
9
+ export default defineComponent({
10
+ name: 'DlMarkdown',
11
+ props: {
12
+ text: {
13
+ type: String,
14
+ default: ''
15
+ }
16
+ },
17
+ setup(props) {
18
+ const { text } = toRefs(props)
19
+
20
+ const renderedMD = computed(() => marked(text.value))
21
+ return {
22
+ renderedMD
23
+ }
24
+ }
25
+ })
26
+ </script>
27
+
28
+ <style scoped lang="scss"></style>
@@ -0,0 +1,2 @@
1
+ import DlMarkdown from './DlMarkdown.vue'
2
+ export { DlMarkdown }
@@ -19,3 +19,4 @@ export * from './DlColorPicker'
19
19
  export * from './DlSpinner'
20
20
  export * from './DlSeparator'
21
21
  export * from './DlLayout'
22
+ export * from './DlMarkDown'
@@ -0,0 +1,44 @@
1
+ <template>
2
+ <div>
3
+ <DlMarkdown :text="mdText" />
4
+ </div>
5
+ </template>
6
+
7
+ <script lang="ts">
8
+ import { DlMarkdown } from '../components'
9
+ import { defineComponent } from 'vue-demi'
10
+
11
+ export default defineComponent({
12
+ components: {
13
+ DlMarkdown
14
+ },
15
+ setup() {
16
+ const mdText = `# Hi
17
+ ## This is a markdown demo
18
+ ### It's a simple demo
19
+ #### It's a simple demo
20
+ ##### It's a simple demo
21
+
22
+ *It's a simple demo*
23
+
24
+ **It's a simple demo**
25
+
26
+ ***It's a simple demo***
27
+
28
+ > It's a simple demo
29
+ - [ ] It's a simple demo
30
+ - [x] It's a simple demo
31
+
32
+ [It's a simple demo]('https://www.google.com')
33
+
34
+ \`It's a simple demo\`
35
+ \`\`\`javascript
36
+ const highlight = "code";
37
+ \`\`\`
38
+ `
39
+ return {
40
+ mdText
41
+ }
42
+ }
43
+ })
44
+ </script>
@@ -68,6 +68,7 @@ import DlLayoutDemo from './DlLayoutDemo.vue'
68
68
  import { DlCodeEditorDemo } from './DlCodeEditor'
69
69
  import DlLabelPickerDemo from './DlLabelPickerDemo.vue'
70
70
  import DlInfiniteScrollDemo from './DlInfiniteScrollDemo.vue'
71
+ import DlMarkDownDemo from './DlMarkDownDemo.vue'
71
72
 
72
73
  export default {
73
74
  AvatarDemo,
@@ -136,5 +137,6 @@ export default {
136
137
  DlCodeEditorDemo,
137
138
  DlLayoutDemo,
138
139
  DlLabelPickerDemo,
139
- DlInfiniteScrollDemo
140
+ DlInfiniteScrollDemo,
141
+ DlMarkDownDemo
140
142
  }
package/vite.config.ts CHANGED
@@ -23,7 +23,7 @@ export default defineConfig({
23
23
  ]
24
24
  },
25
25
  optimizeDeps: {
26
- include: ['highlight.js'],
26
+ include: ['lodash', 'flat', 'highlight.js', 'sortablejs', 'marked'],
27
27
  exclude: ['vue-demi']
28
28
  },
29
29
  define: {