@enso-ui/wysiwyg 3.2.0 → 3.2.2
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/CHANGELOG.md +10 -0
- package/README.md +18 -0
- package/package.json +1 -1
- package/src/bulma/TrixEditor.vue +43 -32
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 3.2.0
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- added optional Trix editor support through the `editor` prop
|
|
8
|
+
- kept TinyMCE as the default editor for backward compatibility
|
|
9
|
+
- added Trix styling aligned with the Bulma theme tokens used by the existing WYSIWYG field
|
|
10
|
+
|
package/README.md
CHANGED
|
@@ -19,6 +19,7 @@ yarn add @enso-ui/wysiwyg
|
|
|
19
19
|
## Features
|
|
20
20
|
- exports `Wysiwyg` as its public surface
|
|
21
21
|
- supports `tinymce` and `trix` editor engines
|
|
22
|
+
- keeps TinyMCE as the default editor for backward compatibility
|
|
22
23
|
- keeps the Bulma presentation layer separate from the renderless/stateful layer where applicable
|
|
23
24
|
## Usage
|
|
24
25
|
```vue
|
|
@@ -46,6 +47,23 @@ Props:
|
|
|
46
47
|
- `toolbar`
|
|
47
48
|
|
|
48
49
|
`editor` defaults to `tinymce`. Set it to `trix` to use the Trix editor.
|
|
50
|
+
|
|
51
|
+
### Trix
|
|
52
|
+
|
|
53
|
+
Trix uses the same `v-model` contract as TinyMCE:
|
|
54
|
+
|
|
55
|
+
```vue
|
|
56
|
+
<Wysiwyg v-model="content"
|
|
57
|
+
editor="trix"
|
|
58
|
+
:has-error="false"/>
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Form renderers may pass this through backend metadata as `meta.editor: 'trix'`.
|
|
62
|
+
|
|
63
|
+
## Changelog
|
|
64
|
+
|
|
65
|
+
See [CHANGELOG.md](CHANGELOG.md).
|
|
66
|
+
|
|
49
67
|
## Depends On
|
|
50
68
|
- No additional Enso UI package dependencies.
|
|
51
69
|
- [`trix`](https://github.com/basecamp/trix)
|
package/package.json
CHANGED
package/src/bulma/TrixEditor.vue
CHANGED
|
@@ -1,42 +1,53 @@
|
|
|
1
|
-
<
|
|
2
|
-
<input :id="inputId"
|
|
3
|
-
type="hidden"
|
|
4
|
-
:value="normalizedValue">
|
|
5
|
-
<trix-editor :input="inputId"
|
|
6
|
-
ref="trix"
|
|
7
|
-
@trix-change="update"/>
|
|
8
|
-
</template>
|
|
9
|
-
|
|
10
|
-
<script setup>
|
|
1
|
+
<script>
|
|
11
2
|
|
|
12
3
|
import 'trix/dist/trix.css';
|
|
13
4
|
import 'trix';
|
|
14
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
computed, h, nextTick, ref, watch,
|
|
7
|
+
} from 'vue';
|
|
8
|
+
|
|
9
|
+
export default {
|
|
10
|
+
name: 'EnsoTrixEditor',
|
|
15
11
|
|
|
16
|
-
defineOptions({
|
|
17
12
|
inheritAttrs: false,
|
|
18
|
-
});
|
|
19
13
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
14
|
+
props: {
|
|
15
|
+
modelValue: {
|
|
16
|
+
type: [String, null],
|
|
17
|
+
default: '',
|
|
18
|
+
},
|
|
24
19
|
},
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
const emit = defineEmits(['update:modelValue']);
|
|
28
|
-
const inputId = `trix-${Math.random().toString(36).slice(2)}`;
|
|
29
|
-
const trix = ref(null);
|
|
30
|
-
const normalizedValue = computed(() => props.modelValue ?? '');
|
|
31
20
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
21
|
+
emits: ['update:modelValue'],
|
|
22
|
+
|
|
23
|
+
setup(props, { emit }) {
|
|
24
|
+
const inputId = `trix-${Math.random().toString(36).slice(2)}`;
|
|
25
|
+
const trix = ref(null);
|
|
26
|
+
const normalizedValue = computed(() => props.modelValue ?? '');
|
|
27
|
+
|
|
28
|
+
const update = event => emit('update:modelValue', event.target.value);
|
|
29
|
+
|
|
30
|
+
watch(() => props.modelValue, value => nextTick(() => {
|
|
31
|
+
const html = value ?? '';
|
|
32
|
+
|
|
33
|
+
if (trix.value && trix.value.value !== html) {
|
|
34
|
+
trix.value.editor.loadHTML(html);
|
|
35
|
+
}
|
|
36
|
+
}));
|
|
37
|
+
|
|
38
|
+
return () => [
|
|
39
|
+
h('input', {
|
|
40
|
+
id: inputId,
|
|
41
|
+
type: 'hidden',
|
|
42
|
+
value: normalizedValue.value,
|
|
43
|
+
}),
|
|
44
|
+
h('trix-editor', {
|
|
45
|
+
input: inputId,
|
|
46
|
+
ref: trix,
|
|
47
|
+
onTrixChange: update,
|
|
48
|
+
}),
|
|
49
|
+
];
|
|
50
|
+
},
|
|
51
|
+
};
|
|
41
52
|
|
|
42
53
|
</script>
|