@zipify/wysiwyg 2.0.0-14 → 2.0.0-16

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/dist/wysiwyg.css CHANGED
@@ -743,7 +743,7 @@ $font-height--xs: 1.33;
743
743
  $font-height--sm: 1.43;
744
744
  $font-height--md: 1.72;
745
745
  */
746
- .zw-wysiwyg__placeholder:first-child:last-child::before {
746
+ .zw-wysiwyg__placeholder::before {
747
747
  content: attr(data-placeholder);
748
748
  color: rgb(var(--zw-color-n70));
749
749
  float: left;
package/dist/wysiwyg.mjs CHANGED
@@ -26,7 +26,7 @@ var __privateMethod = (obj, member, method) => {
26
26
  __accessCheck(obj, member, "access private method");
27
27
  return method;
28
28
  };
29
- var _domParser, _parser, _NodeFilter, NodeFilter_get, _Node, Node_get, _removeComments, removeComments_fn, _normalizeRootTags, normalizeRootTags_fn, _createNodeIterator, createNodeIterator_fn, _iterateNodes, iterateNodes_fn, _runIterator, runIterator_fn, _removeEmptyNodes, removeEmptyNodes_fn, _normalizeListItems, normalizeListItems_fn, _isBlockNode, isBlockNode_fn, _isRootNode, isRootNode_fn, _assignElementProperties, assignElementProperties_fn, _removeStyleProperties, removeStyleProperties_fn, _normalizeBreakLines, normalizeBreakLines_fn, _normalizeBlockTextDecoration, normalizeBlockTextDecoration_fn, _moveTextDecorationToChildren, moveTextDecorationToChildren_fn, _parseTextDecoration, parseTextDecoration_fn, _normalizeBlockBackgroundColor, normalizeBlockBackgroundColor_fn, _moveBackgroundColorToChildren, moveBackgroundColorToChildren_fn, _wrapTextNode, wrapTextNode_fn, _iterateNodes2, iterateNodes_fn2, _iterateChildNodes, iterateChildNodes_fn, _bubbleMarks, bubbleMarks_fn, _canBubbleMark, canBubbleMark_fn, _includesMark, includesMark_fn, _includesMarkType, includesMarkType_fn, _removeMark, removeMark_fn, _addMark, addMark_fn, _findMarkIndexByType, findMarkIndexByType_fn, _buildHtml, buildHtml_fn, _buildJson, buildJson_fn, _textBlock, textBlock_fn, _normalizeTextBlockArgs, normalizeTextBlockArgs_fn;
29
+ var _domParser, _parser, _NodeFilter, NodeFilter_get, _Node, Node_get, _removeComments, removeComments_fn, _normalizeRootTags, normalizeRootTags_fn, _createNodeIterator, createNodeIterator_fn, _iterateNodes, iterateNodes_fn, _runIterator, runIterator_fn, _removeEmptyNodes, removeEmptyNodes_fn, _normalizeListItems, normalizeListItems_fn, _isBlockNode, isBlockNode_fn, _isRootNode, isRootNode_fn, _assignElementProperties, assignElementProperties_fn, _removeStyleProperties, removeStyleProperties_fn, _normalizeBreakLines, normalizeBreakLines_fn, _normalizeBlockTextDecoration, normalizeBlockTextDecoration_fn, _moveTextDecorationToChildren, moveTextDecorationToChildren_fn, _parseTextDecoration, parseTextDecoration_fn, _normalizeBlockBackgroundColor, normalizeBlockBackgroundColor_fn, _moveBackgroundColorToChildren, moveBackgroundColorToChildren_fn, _wrapTextNode, wrapTextNode_fn, _iterateNodes2, iterateNodes_fn2, _iterateChildNodes, iterateChildNodes_fn, _bubbleMarks, bubbleMarks_fn, _canBubbleMark, canBubbleMark_fn, _includesMark, includesMark_fn, _includesMarkType, includesMarkType_fn, _removeMark, removeMark_fn, _addMark, addMark_fn, _findMarkIndexByType, findMarkIndexByType_fn, _buildHtml, buildHtml_fn, _buildJson, buildJson_fn, _textBlock, textBlock_fn, _normalizeTextBlockArgs, normalizeTextBlockArgs_fn, _buildDecorations, buildDecorations_fn;
30
30
  import { computed, ref, watch, inject, onUnmounted, nextTick, provide, onMounted, toRef, unref, reactive } from "vue";
31
31
  import { ColorModel, ZipifyColorPicker } from "@zipify/colorpicker";
32
32
  function OrderedMap(content) {
@@ -25495,10 +25495,11 @@ const ListItem = ListItem$1.extend({
25495
25495
  }),
25496
25496
  addKeyboardShortcuts: () => ({
25497
25497
  Enter: (context) => {
25498
+ var _a;
25498
25499
  const { state, commands: commands2 } = context.editor;
25499
- const isListSelected = state.selection.$cursor.path.some((node) => {
25500
- var _a;
25501
- return ((_a = node.type) == null ? void 0 : _a.name) === NodeTypes.LIST;
25500
+ const isListSelected = (_a = state.selection.$cursor) == null ? void 0 : _a.path.some((node) => {
25501
+ var _a2;
25502
+ return ((_a2 = node.type) == null ? void 0 : _a2.name) === NodeTypes.LIST;
25502
25503
  });
25503
25504
  if (isListSelected) {
25504
25505
  commands2.listItemNewline();
@@ -26765,57 +26766,6 @@ const Text = Node.create({
26765
26766
  name: "text",
26766
26767
  group: "inline"
26767
26768
  });
26768
- const Placeholder = Extension.create({
26769
- name: "placeholder",
26770
- addOptions() {
26771
- return {
26772
- emptyEditorClass: "is-editor-empty",
26773
- emptyNodeClass: "is-empty",
26774
- placeholder: "Write something \u2026",
26775
- showOnlyWhenEditable: true,
26776
- showOnlyCurrent: true,
26777
- includeChildren: false
26778
- };
26779
- },
26780
- addProseMirrorPlugins() {
26781
- return [
26782
- new Plugin({
26783
- props: {
26784
- decorations: ({ doc: doc2, selection }) => {
26785
- const active = this.editor.isEditable || !this.options.showOnlyWhenEditable;
26786
- const { anchor } = selection;
26787
- const decorations = [];
26788
- if (!active) {
26789
- return null;
26790
- }
26791
- doc2.descendants((node, pos) => {
26792
- const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize;
26793
- const isEmpty = !node.isLeaf && !node.childCount;
26794
- if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
26795
- const classes = [this.options.emptyNodeClass];
26796
- if (this.editor.isEmpty) {
26797
- classes.push(this.options.emptyEditorClass);
26798
- }
26799
- const decoration = Decoration.node(pos, pos + node.nodeSize, {
26800
- class: classes.join(" "),
26801
- "data-placeholder": typeof this.options.placeholder === "function" ? this.options.placeholder({
26802
- editor: this.editor,
26803
- node,
26804
- pos,
26805
- hasAnchor
26806
- }) : this.options.placeholder
26807
- });
26808
- decorations.push(decoration);
26809
- }
26810
- return this.options.includeChildren;
26811
- });
26812
- return DecorationSet.create(doc2, decorations);
26813
- }
26814
- }
26815
- })
26816
- ];
26817
- }
26818
- });
26819
26769
  var GOOD_LEAF_SIZE = 200;
26820
26770
  var RopeSequence = function RopeSequence2() {
26821
26771
  };
@@ -27546,82 +27496,6 @@ const SelectionProcessor = Extension.create({
27546
27496
  };
27547
27497
  }
27548
27498
  });
27549
- class ProseMirrorPlugin {
27550
- static create(options) {
27551
- const plugin = new this(options || {});
27552
- return new Plugin({
27553
- key: new PluginKey(this.name),
27554
- props: plugin.buildProps()
27555
- });
27556
- }
27557
- constructor(options) {
27558
- this.options = options;
27559
- }
27560
- buildProps() {
27561
- return {};
27562
- }
27563
- }
27564
- class PastePlugin extends ProseMirrorPlugin {
27565
- buildProps() {
27566
- return {
27567
- transformPastedHTML: this._transformPastedHTML.bind(this),
27568
- handlePaste: this._handlePaste.bind(this)
27569
- };
27570
- }
27571
- _transformPastedHTML(html2) {
27572
- const normalizer = ContentNormalizer.build(html2);
27573
- normalizer.normalizeHTML();
27574
- this._removeDeprecatedStyles(normalizer);
27575
- return normalizer.normalizedHTML;
27576
- }
27577
- _removeDeprecatedStyles(normalizer) {
27578
- const elements = normalizer.dom.querySelectorAll('[style*="margin"]');
27579
- for (const element of Array.from(elements)) {
27580
- element.style.removeProperty("margin");
27581
- element.style.removeProperty("margin-top");
27582
- element.style.removeProperty("margin-right");
27583
- element.style.removeProperty("margin-bottom");
27584
- element.style.removeProperty("margin-left");
27585
- }
27586
- }
27587
- _handlePaste(view, _, slice2) {
27588
- const transaction = this._insertPastedContent(view, slice2).scrollIntoView().setMeta("paste", true).setMeta("uiEvent", "paste");
27589
- view.dispatch(transaction);
27590
- return true;
27591
- }
27592
- _insertPastedContent({ state, input }, slice2) {
27593
- if (!this._isFullBlockSelected(state)) {
27594
- return state.tr.replaceSelection(slice2);
27595
- }
27596
- return state.tr.replaceSelectionWith(slice2.content, input.shiftKey);
27597
- }
27598
- _isFullBlockSelected(state) {
27599
- const blocksSelection = this._expandSelectionToBlocks(state);
27600
- const isFromMatch = this._isMatchPosition(blocksSelection.from, state.selection.from);
27601
- const isToMatch = this._isMatchPosition(blocksSelection.to, state.selection.to);
27602
- return isFromMatch && isToMatch;
27603
- }
27604
- _expandSelectionToBlocks({ selection, doc: doc2 }) {
27605
- let from2 = selection.from;
27606
- let to = selection.to;
27607
- doc2.nodesBetween(from2, to, (node, position, parent) => {
27608
- if (parent.type.name !== NodeTypes.DOCUMENT)
27609
- return;
27610
- from2 = Math.min(from2, position + 1);
27611
- to = Math.max(to, position + node.nodeSize - 1);
27612
- });
27613
- return { from: from2, to };
27614
- }
27615
- _isMatchPosition(position1, position2) {
27616
- return Math.abs(position1 - position2) < 5;
27617
- }
27618
- }
27619
- const CopyPasteProcessor = Extension.create({
27620
- name: "copy_paste_processor",
27621
- addProseMirrorPlugins() {
27622
- return [PastePlugin.create()];
27623
- }
27624
- });
27625
27499
  const Document$1 = Node.create({
27626
27500
  name: "doc",
27627
27501
  topNode: true,
@@ -27740,12 +27614,119 @@ const Heading = Heading$1.extend({
27740
27614
  HTMLAttributes: { class: "zw-style" }
27741
27615
  })
27742
27616
  });
27617
+ class ProseMirrorPlugin {
27618
+ static create(editor, options) {
27619
+ const plugin = new this(editor, options || {});
27620
+ return new Plugin({
27621
+ key: new PluginKey(this.name),
27622
+ props: plugin.buildProps()
27623
+ });
27624
+ }
27625
+ constructor(editor, options) {
27626
+ this.options = options;
27627
+ this.editor = editor;
27628
+ }
27629
+ buildProps() {
27630
+ return {};
27631
+ }
27632
+ }
27633
+ class PastePlugin extends ProseMirrorPlugin {
27634
+ buildProps() {
27635
+ return {
27636
+ transformPastedHTML: this._transformPastedHTML.bind(this),
27637
+ handlePaste: this._handlePaste.bind(this)
27638
+ };
27639
+ }
27640
+ _transformPastedHTML(html2) {
27641
+ if (html2.includes("data-pm-slice") && html2.includes("zw-style")) {
27642
+ return html2;
27643
+ }
27644
+ const normalizer = ContentNormalizer.build(html2);
27645
+ normalizer.normalizeHTML();
27646
+ this._removeDeprecatedStyles(normalizer);
27647
+ return normalizer.normalizedHTML;
27648
+ }
27649
+ _removeDeprecatedStyles(normalizer) {
27650
+ const elements = normalizer.dom.querySelectorAll('[style*="margin"]');
27651
+ for (const element of Array.from(elements)) {
27652
+ element.style.removeProperty("margin");
27653
+ element.style.removeProperty("margin-top");
27654
+ element.style.removeProperty("margin-right");
27655
+ element.style.removeProperty("margin-bottom");
27656
+ element.style.removeProperty("margin-left");
27657
+ }
27658
+ }
27659
+ _handlePaste(view, _, slice2) {
27660
+ const transaction = this._insertPastedContent(view, slice2).scrollIntoView().setMeta("paste", true).setMeta("uiEvent", "paste");
27661
+ view.dispatch(transaction);
27662
+ return true;
27663
+ }
27664
+ _insertPastedContent({ state, input }, slice2) {
27665
+ if (!this._isFullBlockSelected(state)) {
27666
+ return state.tr.replaceSelection(slice2);
27667
+ }
27668
+ return state.tr.replaceSelectionWith(slice2.content, input.shiftKey);
27669
+ }
27670
+ _isFullBlockSelected(state) {
27671
+ const blocksSelection = this._expandSelectionToBlocks(state);
27672
+ const isFromMatch = this._isMatchPosition(blocksSelection.from, state.selection.from);
27673
+ const isToMatch = this._isMatchPosition(blocksSelection.to, state.selection.to);
27674
+ return isFromMatch && isToMatch;
27675
+ }
27676
+ _expandSelectionToBlocks({ selection, doc: doc2 }) {
27677
+ let from2 = selection.from;
27678
+ let to = selection.to;
27679
+ doc2.nodesBetween(from2, to, (node, position, parent) => {
27680
+ if (parent.type.name !== NodeTypes.DOCUMENT)
27681
+ return;
27682
+ from2 = Math.min(from2, position + 1);
27683
+ to = Math.max(to, position + node.nodeSize - 1);
27684
+ });
27685
+ return { from: from2, to };
27686
+ }
27687
+ _isMatchPosition(position1, position2) {
27688
+ return Math.abs(position1 - position2) < 5;
27689
+ }
27690
+ }
27691
+ class PlaceholderPlugin extends ProseMirrorPlugin {
27692
+ constructor() {
27693
+ super(...arguments);
27694
+ __privateAdd(this, _buildDecorations);
27695
+ }
27696
+ buildProps() {
27697
+ return { decorations: __privateMethod(this, _buildDecorations, buildDecorations_fn).bind(this) };
27698
+ }
27699
+ }
27700
+ _buildDecorations = new WeakSet();
27701
+ buildDecorations_fn = function({ doc: doc2 }) {
27702
+ const decorations = [];
27703
+ if (!this.editor.isEditable)
27704
+ return null;
27705
+ if (doc2.childCount > 1)
27706
+ return;
27707
+ doc2.descendants((node, pos) => {
27708
+ if (!node.childCount) {
27709
+ const decoration = Decoration.node(pos, pos + node.nodeSize, {
27710
+ class: "zw-wysiwyg__placeholder",
27711
+ "data-placeholder": "Type your text here..."
27712
+ });
27713
+ decorations.push(decoration);
27714
+ }
27715
+ return false;
27716
+ });
27717
+ return DecorationSet.create(doc2, decorations);
27718
+ };
27719
+ const ProseMirrorPlugins = Extension.create({
27720
+ name: "prose_mirror_plugins",
27721
+ addProseMirrorPlugins() {
27722
+ return [
27723
+ PastePlugin.create(this.editor),
27724
+ PlaceholderPlugin.create(this.editor)
27725
+ ];
27726
+ }
27727
+ });
27743
27728
  const buildCoreExtensions = () => [
27744
27729
  Document,
27745
- Placeholder.configure({
27746
- placeholder: "Type your text here...",
27747
- emptyNodeClass: "zw-wysiwyg__placeholder"
27748
- }),
27749
27730
  Paragraph,
27750
27731
  Heading,
27751
27732
  Text,
@@ -27753,7 +27734,7 @@ const buildCoreExtensions = () => [
27753
27734
  NodeProcessor,
27754
27735
  TextProcessor,
27755
27736
  SelectionProcessor,
27756
- CopyPasteProcessor
27737
+ ProseMirrorPlugins
27757
27738
  ];
27758
27739
  const Margin = Extension.create({
27759
27740
  name: TextSettings.MARGIN,
@@ -1,20 +1,27 @@
1
+ import { Extension } from '@tiptap/vue-2';
1
2
  import Text from '@tiptap/extension-text';
2
- import Placeholder from '@tiptap/extension-placeholder';
3
3
  import History from '@tiptap/extension-history';
4
4
  import { NodeProcessor } from './NodeProcessor';
5
5
  import { TextProcessor } from './TextProcessor';
6
6
  import { SelectionProcessor } from './SelectionProcessor';
7
- import { CopyPasteProcessor } from './CopyPasteProcessor';
8
7
  import { Document } from './Document';
9
8
  import { Paragraph } from './Paragraph';
10
9
  import { Heading } from './Heading';
10
+ import { PastePlugin, PlaceholderPlugin } from './plugins';
11
+
12
+ const ProseMirrorPlugins = Extension.create({
13
+ name: 'prose_mirror_plugins',
14
+
15
+ addProseMirrorPlugins() {
16
+ return [
17
+ PastePlugin.create(this.editor),
18
+ PlaceholderPlugin.create(this.editor)
19
+ ];
20
+ }
21
+ });
11
22
 
12
23
  export const buildCoreExtensions = () => [
13
24
  Document,
14
- Placeholder.configure({
15
- placeholder: 'Type your text here...',
16
- emptyNodeClass: 'zw-wysiwyg__placeholder'
17
- }),
18
25
  Paragraph,
19
26
  Heading,
20
27
  Text,
@@ -22,5 +29,5 @@ export const buildCoreExtensions = () => [
22
29
  NodeProcessor,
23
30
  TextProcessor,
24
31
  SelectionProcessor,
25
- CopyPasteProcessor
32
+ ProseMirrorPlugins
26
33
  ];
@@ -11,6 +11,10 @@ export class PastePlugin extends ProseMirrorPlugin {
11
11
  }
12
12
 
13
13
  _transformPastedHTML(html) {
14
+ if (html.includes('data-pm-slice') && html.includes('zw-style')) {
15
+ return html;
16
+ }
17
+
14
18
  const normalizer = ContentNormalizer.build(html);
15
19
 
16
20
  normalizer.normalizeHTML();
@@ -0,0 +1,30 @@
1
+ import { Decoration, DecorationSet } from 'prosemirror-view';
2
+ import { ProseMirrorPlugin } from './ProseMirrorPlugin';
3
+
4
+ export class PlaceholderPlugin extends ProseMirrorPlugin {
5
+ buildProps() {
6
+ return { decorations: this.#buildDecorations.bind(this) };
7
+ }
8
+
9
+ #buildDecorations({ doc }) {
10
+ const decorations = [];
11
+
12
+ if (!this.editor.isEditable) return null;
13
+ if (doc.childCount > 1) return;
14
+
15
+ doc.descendants((node, pos) => {
16
+ if (!node.childCount) {
17
+ const decoration = Decoration.node(pos, pos + node.nodeSize, {
18
+ class: 'zw-wysiwyg__placeholder',
19
+ 'data-placeholder': 'Type your text here...'
20
+ });
21
+
22
+ decorations.push(decoration);
23
+ }
24
+
25
+ return false;
26
+ });
27
+
28
+ return DecorationSet.create(doc, decorations);
29
+ }
30
+ }
@@ -1,8 +1,8 @@
1
1
  import { Plugin, PluginKey } from 'prosemirror-state';
2
2
 
3
3
  export class ProseMirrorPlugin {
4
- static create(options) {
5
- const plugin = new this(options || {});
4
+ static create(editor, options) {
5
+ const plugin = new this(editor, options || {});
6
6
 
7
7
  return new Plugin({
8
8
  key: new PluginKey(this.name),
@@ -10,8 +10,9 @@ export class ProseMirrorPlugin {
10
10
  });
11
11
  }
12
12
 
13
- constructor(options) {
13
+ constructor(editor, options) {
14
14
  this.options = options;
15
+ this.editor = editor;
15
16
  }
16
17
 
17
18
  buildProps() {
@@ -1 +1,2 @@
1
1
  export { PastePlugin } from './PastePlugin';
2
+ export { PlaceholderPlugin } from './PlaceholderPlugin';
@@ -33,7 +33,7 @@ export const ListItem = Base.extend({
33
33
  Enter: (context) => {
34
34
  const { state, commands } = context.editor;
35
35
 
36
- const isListSelected = state.selection.$cursor.path.some((node) => {
36
+ const isListSelected = state.selection.$cursor?.path.some((node) => {
37
37
  return node.type?.name === NodeTypes.LIST;
38
38
  });
39
39
 
@@ -1,4 +1,4 @@
1
- .zw-wysiwyg__placeholder:first-child:last-child::before {
1
+ .zw-wysiwyg__placeholder::before {
2
2
  content: attr(data-placeholder);
3
3
  color: rgb(var(--zw-color-n70));
4
4
  float: left;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zipify/wysiwyg",
3
- "version": "2.0.0-14",
3
+ "version": "2.0.0-16",
4
4
  "description": "Zipify modification of TipTap text editor",
5
5
  "main": "dist/wysiwyg.mjs",
6
6
  "bin": {
@@ -41,7 +41,6 @@
41
41
  "@tiptap/extension-link": "^2.0.0-beta.195",
42
42
  "@tiptap/extension-list-item": "^2.0.0-beta.195",
43
43
  "@tiptap/extension-paragraph": "^2.0.0-beta.195",
44
- "@tiptap/extension-placeholder": "^2.0.0-beta.195",
45
44
  "@tiptap/extension-superscript": "^2.0.0-beta.195",
46
45
  "@tiptap/extension-text": "^2.0.0-beta.195",
47
46
  "@tiptap/vue-2": "^2.0.0-beta.195",
@@ -1,10 +0,0 @@
1
- import { Extension } from '@tiptap/vue-2';
2
- import { PastePlugin } from './plugins';
3
-
4
- export const CopyPasteProcessor = Extension.create({
5
- name: 'copy_paste_processor',
6
-
7
- addProseMirrorPlugins() {
8
- return [PastePlugin.create()];
9
- }
10
- });