@ditojs/admin 2.34.5 → 2.36.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.
@@ -0,0 +1,32 @@
1
+ import DitoContext from '../DitoContext.js'
2
+ import { computeValue } from '../utils/schema.js'
3
+
4
+ export default {
5
+ computed: {
6
+ value: {
7
+ get() {
8
+ const value = computeValue(
9
+ this.schema,
10
+ this.data,
11
+ this.name,
12
+ this.dataPath,
13
+ { component: this }
14
+ )
15
+ const { format } = this.schema
16
+ return format
17
+ ? format(new DitoContext(this, { value }))
18
+ : value
19
+ },
20
+
21
+ set(value) {
22
+ const { parse } = this.schema
23
+ if (parse) {
24
+ value = parse(new DitoContext(this, { value }))
25
+ }
26
+ this.parsedValue = value
27
+ // eslint-disable-next-line vue/no-mutating-props
28
+ this.data[this.name] = value
29
+ }
30
+ }
31
+ }
32
+ }
@@ -1,34 +1,63 @@
1
1
  <template lang="pug">
2
2
  .dito-code(
3
3
  :id="dataPath"
4
- ref="code"
5
4
  :style="style"
6
5
  )
6
+ .dito-code__editor(ref="editor")
7
+ .dito-resize(
8
+ v-if="resizable"
9
+ @mousedown.stop.prevent="onDragResize"
10
+ )
7
11
  </template>
8
12
 
9
13
  <script>
10
14
  import DitoTypeComponent from '../DitoTypeComponent.js'
11
15
  import DomMixin from '../mixins/DomMixin.js'
16
+ import { getSchemaAccessor } from '../utils/accessor.js'
12
17
  import CodeFlask from 'codeflask'
13
18
 
14
19
  // @vue/component
15
20
  export default DitoTypeComponent.register('code', {
16
21
  mixins: [DomMixin],
17
22
 
23
+ data() {
24
+ return {
25
+ height: null
26
+ }
27
+ },
28
+
18
29
  computed: {
19
- lines() {
20
- return this.schema.lines || 3
21
- },
30
+ lines: getSchemaAccessor('lines', {
31
+ type: Number,
32
+ default: 3
33
+ }),
34
+
35
+ language: getSchemaAccessor('language', {
36
+ type: String,
37
+ default: 'javascript'
38
+ }),
39
+
40
+ indentSize: getSchemaAccessor('indentSize', {
41
+ type: Number,
42
+ default: 2
43
+ }),
44
+
45
+ resizable: getSchemaAccessor('resizable', {
46
+ type: Boolean,
47
+ default: false
48
+ }),
22
49
 
23
50
  style() {
24
- return `height: calc(${this.lines}em * var(--line-height))`
51
+ return {
52
+ height: this.height || `calc(${this.lines}em * var(--line-height))`
53
+ }
25
54
  }
26
55
  },
27
56
 
28
57
  mounted() {
29
- const flask = new CodeFlask(this.$refs.code, {
30
- language: this.schema.language || 'javascript',
31
- tabSize: this.schema.indentSize || 2,
58
+ const flask = new CodeFlask(this.$refs.editor, {
59
+ language: this.language,
60
+ indentSize: this.indentSize,
32
61
  lineNumbers: false
33
62
  })
34
63
 
@@ -50,7 +79,7 @@ export default DitoTypeComponent.register('code', {
50
79
  onChange()
51
80
  }
52
81
 
53
- this.domOn(this.$refs.code.querySelector('textarea'), {
82
+ this.domOn(this.$refs.editor.querySelector('textarea'), {
54
83
  focus: onFocus,
55
84
  blur: onBlur
56
85
  })
@@ -87,6 +116,10 @@ export default DitoTypeComponent.register('code', {
87
116
  }
88
117
  })
89
118
 
119
+ this.$watch('language', language => {
120
+ flask.updateLanguage(language)
121
+ })
122
+
90
123
  setCode(this.value || '')
91
124
  },
92
125
 
@@ -96,7 +129,30 @@ export default DitoTypeComponent.register('code', {
96
129
  },
97
130
 
98
131
  blurElement() {
99
- this.$el.querySelector('textarea')?.focus()
132
+ this.$el.querySelector('textarea')?.blur()
133
+ },
134
+
135
+ onDragResize(event) {
136
+ const getPoint = ({ clientX: x, clientY: y }) => ({ x, y })
137
+
138
+ let prevY = getPoint(event).y
139
+ let height = parseFloat(getComputedStyle(this.$el).height)
140
+
141
+ const mousemove = event => {
142
+ const { y } = getPoint(event)
143
+ height += y - prevY
144
+ prevY = y
145
+ this.height = `${Math.max(height, 0)}px`
146
+ }
147
+
148
+ const handlers = this.domOn(document, {
149
+ mousemove,
150
+
151
+ mouseup(event) {
152
+ mousemove(event)
153
+ handlers.remove()
154
+ }
155
+ })
100
156
  }
101
157
  }
102
158
  })
@@ -112,6 +168,7 @@ export default DitoTypeComponent.register('code', {
112
168
  // For proper sizing of content along with :style="style" setting above,
113
169
  // for proper line-height calculation.
114
170
  padding: $input-padding;
171
+ min-height: calc(1em * var(--line-height) + 2 * $input-padding-ver);
115
172
 
116
173
  .codeflask {
117
174
  background: none;
@@ -119,24 +176,24 @@ export default DitoTypeComponent.register('code', {
119
176
  // the desired height with :style="style".
120
177
  top: 0;
121
178
  left: 0;
122
- }
123
179
 
124
- .codeflask__textarea,
125
- .codeflask__pre {
126
- // Use same padding as .dito-code
127
- padding: $input-padding;
128
- }
180
+ &__textarea,
181
+ &__pre {
182
+ // Use same padding as .dito-code
183
+ padding: $input-padding;
184
+ }
129
185
 
130
- .codeflask__textarea,
131
- .codeflask__code,
132
- .codeflask__lines {
133
- font-family: $font-family-mono;
134
- font-size: var(--font-size);
135
- line-height: var(--line-height);
136
- }
186
+ &__textarea,
187
+ &__code,
188
+ &__lines {
189
+ font-family: $font-family-mono;
190
+ font-size: var(--font-size);
191
+ line-height: var(--line-height);
192
+ }
137
193
 
138
- .codeflask__lines {
139
- padding: $input-padding;
194
+ &__lines {
195
+ padding: $input-padding;
196
+ }
140
197
  }
141
198
  }
142
199
  </style>
@@ -14,7 +14,7 @@ input.dito-text.dito-input(
14
14
 
15
15
  <script>
16
16
  import DitoTypeComponent from '../DitoTypeComponent.js'
17
- import TypeMixin from '../mixins/TypeMixin.js'
17
+ import ValueMixin from '../mixins/ValueMixin.js'
18
18
  import DataMixin from '../mixins/DataMixin.js'
19
19
 
20
20
  export default DitoTypeComponent.register(
@@ -37,11 +37,11 @@ export default DitoTypeComponent.register(
37
37
  // eslint-disable-next-line vue/no-side-effects-in-computed-properties
38
38
  this.data[this.name] = value
39
39
  }
40
- return TypeMixin.computed.value.get.call(this)
40
+ return ValueMixin.computed.value.get.call(this)
41
41
  },
42
42
 
43
43
  set(value) {
44
- TypeMixin.computed.value.set.call(this, value)
44
+ ValueMixin.computed.value.set.call(this, value)
45
45
  }
46
46
  }
47
47
  }
@@ -132,6 +132,7 @@
132
132
  :data="listData"
133
133
  :meta="meta"
134
134
  :store="store"
135
+ :nested="nested"
135
136
  :disabled="disabled || isLoading"
136
137
  :creatable="creatable"
137
138
  :createPath="path"
@@ -526,18 +526,6 @@ const LinkWithTitle = Link.extend({
526
526
 
527
527
  position: relative;
528
528
 
529
- .dito-resize {
530
- @extend %icon-resize;
531
-
532
- position: absolute;
533
- top: unset;
534
- left: unset;
535
- right: 0;
536
- bottom: 0;
537
- width: 1em;
538
- height: 1em;
539
- }
540
-
541
529
  .ProseMirror {
542
530
  height: 100%;
543
531
  outline: none;