@zipify/wysiwyg 1.0.0-dev.61 → 1.0.0-dev.62

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.
@@ -16,6 +16,11 @@
16
16
  Load Content
17
17
  </button>
18
18
 
19
+ <label class="zw-readonly-switcher">
20
+ <input type="checkbox" v-model="isReadonly">
21
+ readonly
22
+ </label>
23
+
19
24
  <span>Deployed at {{ updatedAt }}</span>
20
25
 
21
26
  <Wysiwyg
@@ -23,6 +28,7 @@
23
28
  base-list-class="zpa-text__list--"
24
29
  base-preset-class="zp ts-"
25
30
  default-preset-id="regular-1"
31
+ link-preset-id="link"
26
32
  ref="wswgRef"
27
33
  :fonts="fonts"
28
34
  :presets="presets"
@@ -31,7 +37,8 @@
31
37
  :device="device"
32
38
  :page-blocks="pageBlocks"
33
39
  :active="isActive"
34
- @updateFavoriteColors="updateFavoriteColors"
40
+ :readonly="isReadonly"
41
+ @update-favorite-colors="updateFavoriteColors"
35
42
  />
36
43
  <pre class="zw-content-structure" v-html="structurePreview" />
37
44
  </div>
@@ -71,6 +78,7 @@ export default {
71
78
  const device = ref('desktop');
72
79
  const updatedAt = new Date(ZW_UPDATED_AT).toLocaleString('ua-UA');
73
80
  const isActive = ref(false);
81
+ const isReadonly = ref(false);
74
82
 
75
83
  const structurePreview = computed(() => {
76
84
  const json = JSON.stringify(content.value, null, ' ');
@@ -115,7 +123,8 @@ export default {
115
123
  updatedAt,
116
124
  presets,
117
125
  isActive,
118
- pageBlocks
126
+ pageBlocks,
127
+ isReadonly
119
128
  };
120
129
  }
121
130
  };
@@ -141,6 +150,16 @@ body {
141
150
  margin-right: 20px;
142
151
  }
143
152
 
153
+ .zw-readonly-switcher {
154
+ margin-right: 20px;
155
+ display: inline-flex;
156
+ align-items: center;
157
+ }
158
+
159
+ .zw-readonly-switcher input {
160
+ margin-right: 5px;
161
+ }
162
+
144
163
  .zw-content-structure {
145
164
  background-color: #F1F1F1;
146
165
  padding: 8px;
package/lib/Wysiwyg.vue CHANGED
@@ -53,6 +53,11 @@ export default {
53
53
  required: true
54
54
  },
55
55
 
56
+ linkPresetId: {
57
+ type: [Number, String],
58
+ required: true
59
+ },
60
+
56
61
  basePresetClass: {
57
62
  type: String,
58
63
  required: true
@@ -102,6 +107,12 @@ export default {
102
107
  required: true
103
108
  },
104
109
 
110
+ readonly: {
111
+ type: Boolean,
112
+ required: false,
113
+ default: false
114
+ },
115
+
105
116
  // Requires Window type but it different in iframe and outside
106
117
  // eslint-disable-next-line vue/require-prop-types
107
118
  window: {
@@ -122,10 +133,11 @@ export default {
122
133
  const toolbarRef = ref(null);
123
134
  const wysiwygRef = ref(null);
124
135
  const wrapperRef = computed(() => wysiwygRef.value?.$el || document.body);
136
+ const isToolbarActiveRef = computed(() => props.active && !props.readonly);
125
137
 
126
138
  const toolbar = useToolbar({
127
139
  wrapperRef: wysiwygRef,
128
- isActiveRef: toRef(props, 'active'),
140
+ isActiveRef: isToolbarActiveRef,
129
141
  offsets: props.toolbarOffsets
130
142
  });
131
143
  const updateToolbar = () => toolbar.update();
@@ -140,6 +152,7 @@ export default {
140
152
  const editor = useEditor({
141
153
  content: toRef(props, 'value'),
142
154
  onChange: (content) => onChange(content),
155
+ isReadonlyRef: toRef(props, 'readonly'),
143
156
 
144
157
  extensions: buildExtensions({
145
158
  fonts,
@@ -147,6 +160,7 @@ export default {
147
160
  maxFontSize: MAX_FONT_SIZE,
148
161
  presetsRef: toRef(props, 'presets'),
149
162
  defaultPresetId: props.defaultPresetId,
163
+ linkPresetId: props.linkPresetId,
150
164
  makePresetVariable: props.makePresetVariable,
151
165
  basePresetClass: props.basePresetClass,
152
166
  baseListClass: props.baseListClass,
@@ -1,4 +1,4 @@
1
- import { h, toRef } from 'vue';
1
+ import { h, ref, toRef } from 'vue';
2
2
  import { EditorContent } from '@tiptap/vue-2';
3
3
  import { shallowMount } from '@vue/test-utils';
4
4
  import { useEditor } from '../useEditor';
@@ -18,6 +18,7 @@ const TestComponent = {
18
18
 
19
19
  setup(props, { emit }) {
20
20
  const editor = useEditor({
21
+ isReadonlyRef: ref(false),
21
22
  content: toRef(props, 'value'),
22
23
  extensions: buildCoreExtensions(),
23
24
  onChange: (content) => emit('input', content),
@@ -2,7 +2,7 @@ import { Editor } from '@tiptap/vue-2';
2
2
  import { onUnmounted, watch, reactive } from 'vue';
3
3
  import { ContentNormalizer } from '../services';
4
4
 
5
- export function useEditor({ content, onChange, extensions }) {
5
+ export function useEditor({ content, onChange, extensions, isReadonlyRef }) {
6
6
  const editor = reactive(new Editor({
7
7
  content: ContentNormalizer.normalize(content.value),
8
8
  onUpdate: () => onChange(editor.getJSON()),
@@ -22,5 +22,7 @@ export function useEditor({ content, onChange, extensions }) {
22
22
  }
23
23
  });
24
24
 
25
+ watch(isReadonlyRef, (isReadonly) => editor.setEditable(!isReadonly), { immediate: true });
26
+
25
27
  return editor;
26
28
  }
@@ -18,7 +18,7 @@ import { buildCoreExtensions } from './core';
18
18
  export function buildExtensions(options) {
19
19
  const getPresetById = (id) => options.presetsRef.value.find((preset) => preset.id === id);
20
20
  const defaultPreset = getPresetById(options.defaultPresetId);
21
- const linkPreset = getPresetById('link');
21
+ const linkPreset = getPresetById(options.linkPresetId);
22
22
 
23
23
  return buildCoreExtensions(options).concat([
24
24
  StylePreset.configure({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zipify/wysiwyg",
3
- "version": "1.0.0-dev.61",
3
+ "version": "1.0.0-dev.62",
4
4
  "description": "Zipify modification of TipTap text editor",
5
5
  "main": "dist/wysiwyg.mjs",
6
6
  "repository": {