@zipify/wysiwyg 1.0.0-dev.56 → 1.0.0-dev.59

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.
@@ -25,7 +25,7 @@ export class Tooltip {
25
25
  static get popperStyles() {
26
26
  return {
27
27
  willChange: 'transform',
28
- zIndex: 10001
28
+ zIndex: 999999
29
29
  };
30
30
  }
31
31
 
package/lib/Wysiwyg.vue CHANGED
@@ -112,7 +112,7 @@ export default {
112
112
 
113
113
  emits: [
114
114
  'input',
115
- 'updateFavoriteColors'
115
+ 'update-favorite-colors'
116
116
  ],
117
117
 
118
118
  setup(props, { emit }) {
@@ -162,7 +162,7 @@ export default {
162
162
 
163
163
  const favoriteColors = new FavoriteColors({
164
164
  listRef: toRef(props, 'favoriteColors'),
165
- triggerUpdate: (colors) => emit('updateFavoriteColors', colors)
165
+ triggerUpdate: (colors) => emit('update-favorite-colors', colors)
166
166
  });
167
167
 
168
168
  provide(InjectionTokens.EDITOR, editor);
@@ -80,12 +80,11 @@ export const List = Node.create({
80
80
  return;
81
81
  }
82
82
 
83
- return chain().removeList()._addList(type).run();
83
+ return chain().applyDefaultPreset()._addList(type).run();
84
84
  }),
85
85
 
86
86
  _addList: createCommand(({ chain }, type) => {
87
87
  return chain()
88
- .removePreset()
89
88
  .toggleList(NodeTypes.LIST, NodeTypes.LIST_ITEM)
90
89
  .setBlockAttributes('bullet', { type })
91
90
  .run();
@@ -14,7 +14,9 @@ Object {
14
14
  "content": Array [
15
15
  Object {
16
16
  "attrs": Object {
17
- "preset": null,
17
+ "preset": Object {
18
+ "id": "regular-1",
19
+ },
18
20
  },
19
21
  "content": Array [
20
22
  Object {
@@ -49,7 +51,9 @@ Object {
49
51
  "content": Array [
50
52
  Object {
51
53
  "attrs": Object {
52
- "preset": null,
54
+ "preset": Object {
55
+ "id": "regular-1",
56
+ },
53
57
  },
54
58
  "content": Array [
55
59
  Object {
@@ -66,7 +70,9 @@ Object {
66
70
  "content": Array [
67
71
  Object {
68
72
  "attrs": Object {
69
- "preset": null,
73
+ "preset": Object {
74
+ "id": "regular-1",
75
+ },
70
76
  },
71
77
  "content": Array [
72
78
  Object {
@@ -137,7 +143,9 @@ Object {
137
143
  "content": Array [
138
144
  Object {
139
145
  "attrs": Object {
140
- "preset": null,
146
+ "preset": Object {
147
+ "id": "regular-1",
148
+ },
141
149
  },
142
150
  "content": Array [
143
151
  Object {
@@ -154,7 +162,9 @@ Object {
154
162
  "content": Array [
155
163
  Object {
156
164
  "attrs": Object {
157
- "preset": null,
165
+ "preset": Object {
166
+ "id": "regular-1",
167
+ },
158
168
  },
159
169
  "content": Array [
160
170
  Object {
@@ -1,6 +1,7 @@
1
1
  import { ContextWindow } from './ContextWidnow';
2
2
 
3
3
  export class ContentNormalizer {
4
+ static PARSER = new DOMParser();
4
5
  static BLOCK_STYLES = ['text-align', 'line-height'];
5
6
  static BLOCK_NODE_NAMES = ['P', 'H1', 'H2', 'H3', 'H4'];
6
7
 
@@ -20,11 +21,17 @@ export class ContentNormalizer {
20
21
  ];
21
22
 
22
23
  static normalize(content) {
23
- return new ContentNormalizer(content).normalize();
24
+ const options = {
25
+ content,
26
+ parser: ContentNormalizer.PARSER
27
+ };
28
+
29
+ return new ContentNormalizer(options).normalize();
24
30
  }
25
31
 
26
- constructor(content) {
32
+ constructor({ content, parser }) {
27
33
  this._content = content;
34
+ this._parser = parser;
28
35
  this._dom = null;
29
36
  }
30
37
 
@@ -36,7 +43,7 @@ export class ContentNormalizer {
36
43
  }
37
44
 
38
45
  _normalizeTextContent() {
39
- this._dom = new DOMParser().parseFromString(this._content, 'text/html');
46
+ this._dom = this._parser.parseFromString(this._content, 'text/html');
40
47
 
41
48
  this._iterateNodes(this._removeEmptyNodes, this._isBlockNode);
42
49
  this._iterateNodes(this._normalizeListItems, (node) => node.tagName === 'LI');
@@ -59,7 +66,7 @@ export class ContentNormalizer {
59
66
  }
60
67
 
61
68
  _removeEmptyNodes(node) {
62
- if (node.childNodes.length === 0) {
69
+ if (!node.innerHTML.replace(/\n/g, '').trim()) {
63
70
  node.remove();
64
71
  }
65
72
  }
@@ -74,6 +81,8 @@ export class ContentNormalizer {
74
81
  fragment.append(node);
75
82
  };
76
83
 
84
+ this._assignElementProperties(itemEl, itemEl.parentElement, ContentNormalizer.BLOCK_STYLES);
85
+
77
86
  for (const node of children) {
78
87
  if (node.tagName === 'P') {
79
88
  append(node);
@@ -79,6 +79,20 @@ describe('normalize text content', () => {
79
79
  expect(ContentNormalizer.normalize(input)).toBe(output);
80
80
  });
81
81
 
82
+ test('should ignore space only nodes', () => {
83
+ const input = '<p>lorem ipsum 1</p><p> </p><p>lorem ipsum 2</p>';
84
+ const output = '<p>lorem ipsum 1</p><p>lorem ipsum 2</p>';
85
+
86
+ expect(ContentNormalizer.normalize(input)).toBe(output);
87
+ });
88
+
89
+ test('should ignore newline chapters only nodes', () => {
90
+ const input = '<p>lorem ipsum 1</p><p>\n</p><p>lorem ipsum 2</p>';
91
+ const output = '<p>lorem ipsum 1</p><p>lorem ipsum 2</p>';
92
+
93
+ expect(ContentNormalizer.normalize(input)).toBe(output);
94
+ });
95
+
82
96
  test('should not ignore setting', () => {
83
97
  const input = '<p style="text-decoration-line: underline;">lorem ipsum</p>';
84
98
  const output = '<p><span style="text-decoration-line: underline;">lorem ipsum</span></p>';
@@ -106,4 +120,11 @@ describe('normalize text content', () => {
106
120
 
107
121
  expect(ContentNormalizer.normalize(input)).toBe(output);
108
122
  });
123
+
124
+ test('should assign block styles from list to paragraph', () => {
125
+ const input = '<ul style="line-height: 2;"><li>lorem ipsum</li></ul>';
126
+ const output = '<ul style="line-height: 2;"><li><p style="line-height: 2;">lorem ipsum</p></li></ul>';
127
+
128
+ expect(ContentNormalizer.normalize(input)).toBe(output);
129
+ });
109
130
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zipify/wysiwyg",
3
- "version": "1.0.0-dev.56",
3
+ "version": "1.0.0-dev.59",
4
4
  "description": "Zipify modification of TipTap text editor",
5
5
  "main": "dist/wysiwyg.mjs",
6
6
  "repository": {
@@ -14,11 +14,14 @@
14
14
  "url": "https://github.com/ZipifyApps/ZipifyWysiwyg/issues"
15
15
  },
16
16
  "scripts": {
17
- "lib:build": "vite build --config ./config/vite/lib.config.js",
17
+ "lib:pre-build": "npm run lint:js && npm run lint:css && npm run test:unit",
18
+ "lib:build": "npm run lib:pre-build && vite build --config ./config/vite/lib.config.js",
18
19
  "lib:release": "export $(cat ./.env | xargs) && npm run lib:build && release-it",
19
20
  "example:start": "NODE_ENV=development vite serve --config ./config/vite/example.config.js",
20
21
  "example:build": "NODE_ENV=production vite build --config ./config/vite/example.config.js",
21
22
  "test:unit": "jest .",
23
+ "lint:js": "eslint ./lib/**/*.{js,vue}",
24
+ "lint:css": "stylelint ./lib/**/*.{css,vue}",
22
25
  "optimize-svg": "svgo --config ./config/svgo.js",
23
26
  "gzip": "gzipper compress",
24
27
  "prepare": "husky install"