@zipify/wysiwyg 2.0.0-15 → 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) {
@@ -26766,57 +26766,6 @@ const Text = Node.create({
26766
26766
  name: "text",
26767
26767
  group: "inline"
26768
26768
  });
26769
- const Placeholder = Extension.create({
26770
- name: "placeholder",
26771
- addOptions() {
26772
- return {
26773
- emptyEditorClass: "is-editor-empty",
26774
- emptyNodeClass: "is-empty",
26775
- placeholder: "Write something \u2026",
26776
- showOnlyWhenEditable: true,
26777
- showOnlyCurrent: true,
26778
- includeChildren: false
26779
- };
26780
- },
26781
- addProseMirrorPlugins() {
26782
- return [
26783
- new Plugin({
26784
- props: {
26785
- decorations: ({ doc: doc2, selection }) => {
26786
- const active = this.editor.isEditable || !this.options.showOnlyWhenEditable;
26787
- const { anchor } = selection;
26788
- const decorations = [];
26789
- if (!active) {
26790
- return null;
26791
- }
26792
- doc2.descendants((node, pos) => {
26793
- const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize;
26794
- const isEmpty = !node.isLeaf && !node.childCount;
26795
- if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
26796
- const classes = [this.options.emptyNodeClass];
26797
- if (this.editor.isEmpty) {
26798
- classes.push(this.options.emptyEditorClass);
26799
- }
26800
- const decoration = Decoration.node(pos, pos + node.nodeSize, {
26801
- class: classes.join(" "),
26802
- "data-placeholder": typeof this.options.placeholder === "function" ? this.options.placeholder({
26803
- editor: this.editor,
26804
- node,
26805
- pos,
26806
- hasAnchor
26807
- }) : this.options.placeholder
26808
- });
26809
- decorations.push(decoration);
26810
- }
26811
- return this.options.includeChildren;
26812
- });
26813
- return DecorationSet.create(doc2, decorations);
26814
- }
26815
- }
26816
- })
26817
- ];
26818
- }
26819
- });
26820
26769
  var GOOD_LEAF_SIZE = 200;
26821
26770
  var RopeSequence = function RopeSequence2() {
26822
26771
  };
@@ -27547,85 +27496,6 @@ const SelectionProcessor = Extension.create({
27547
27496
  };
27548
27497
  }
27549
27498
  });
27550
- class ProseMirrorPlugin {
27551
- static create(options) {
27552
- const plugin = new this(options || {});
27553
- return new Plugin({
27554
- key: new PluginKey(this.name),
27555
- props: plugin.buildProps()
27556
- });
27557
- }
27558
- constructor(options) {
27559
- this.options = options;
27560
- }
27561
- buildProps() {
27562
- return {};
27563
- }
27564
- }
27565
- class PastePlugin extends ProseMirrorPlugin {
27566
- buildProps() {
27567
- return {
27568
- transformPastedHTML: this._transformPastedHTML.bind(this),
27569
- handlePaste: this._handlePaste.bind(this)
27570
- };
27571
- }
27572
- _transformPastedHTML(html2) {
27573
- if (html2.includes("data-pm-slice") && html2.includes("zw-style")) {
27574
- return html2;
27575
- }
27576
- const normalizer = ContentNormalizer.build(html2);
27577
- normalizer.normalizeHTML();
27578
- this._removeDeprecatedStyles(normalizer);
27579
- return normalizer.normalizedHTML;
27580
- }
27581
- _removeDeprecatedStyles(normalizer) {
27582
- const elements = normalizer.dom.querySelectorAll('[style*="margin"]');
27583
- for (const element of Array.from(elements)) {
27584
- element.style.removeProperty("margin");
27585
- element.style.removeProperty("margin-top");
27586
- element.style.removeProperty("margin-right");
27587
- element.style.removeProperty("margin-bottom");
27588
- element.style.removeProperty("margin-left");
27589
- }
27590
- }
27591
- _handlePaste(view, _, slice2) {
27592
- const transaction = this._insertPastedContent(view, slice2).scrollIntoView().setMeta("paste", true).setMeta("uiEvent", "paste");
27593
- view.dispatch(transaction);
27594
- return true;
27595
- }
27596
- _insertPastedContent({ state, input }, slice2) {
27597
- if (!this._isFullBlockSelected(state)) {
27598
- return state.tr.replaceSelection(slice2);
27599
- }
27600
- return state.tr.replaceSelectionWith(slice2.content, input.shiftKey);
27601
- }
27602
- _isFullBlockSelected(state) {
27603
- const blocksSelection = this._expandSelectionToBlocks(state);
27604
- const isFromMatch = this._isMatchPosition(blocksSelection.from, state.selection.from);
27605
- const isToMatch = this._isMatchPosition(blocksSelection.to, state.selection.to);
27606
- return isFromMatch && isToMatch;
27607
- }
27608
- _expandSelectionToBlocks({ selection, doc: doc2 }) {
27609
- let from2 = selection.from;
27610
- let to = selection.to;
27611
- doc2.nodesBetween(from2, to, (node, position, parent) => {
27612
- if (parent.type.name !== NodeTypes.DOCUMENT)
27613
- return;
27614
- from2 = Math.min(from2, position + 1);
27615
- to = Math.max(to, position + node.nodeSize - 1);
27616
- });
27617
- return { from: from2, to };
27618
- }
27619
- _isMatchPosition(position1, position2) {
27620
- return Math.abs(position1 - position2) < 5;
27621
- }
27622
- }
27623
- const CopyPasteProcessor = Extension.create({
27624
- name: "copy_paste_processor",
27625
- addProseMirrorPlugins() {
27626
- return [PastePlugin.create()];
27627
- }
27628
- });
27629
27499
  const Document$1 = Node.create({
27630
27500
  name: "doc",
27631
27501
  topNode: true,
@@ -27744,12 +27614,119 @@ const Heading = Heading$1.extend({
27744
27614
  HTMLAttributes: { class: "zw-style" }
27745
27615
  })
27746
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
+ });
27747
27728
  const buildCoreExtensions = () => [
27748
27729
  Document,
27749
- Placeholder.configure({
27750
- placeholder: "Type your text here...",
27751
- emptyNodeClass: "zw-wysiwyg__placeholder"
27752
- }),
27753
27730
  Paragraph,
27754
27731
  Heading,
27755
27732
  Text,
@@ -27757,7 +27734,7 @@ const buildCoreExtensions = () => [
27757
27734
  NodeProcessor,
27758
27735
  TextProcessor,
27759
27736
  SelectionProcessor,
27760
- CopyPasteProcessor
27737
+ ProseMirrorPlugins
27761
27738
  ];
27762
27739
  const Margin = Extension.create({
27763
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
  ];
@@ -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';
@@ -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-15",
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
- });