@tiptap/extension-placeholder 2.0.0-beta.19 → 2.0.0-beta.194

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.
@@ -6,8 +6,11 @@ export interface PlaceholderOptions {
6
6
  placeholder: ((PlaceholderProps: {
7
7
  editor: Editor;
8
8
  node: ProsemirrorNode;
9
+ pos: number;
10
+ hasAnchor: boolean;
9
11
  }) => string) | string;
10
12
  showOnlyWhenEditable: boolean;
11
13
  showOnlyCurrent: boolean;
14
+ includeChildren: boolean;
12
15
  }
13
- export declare const Placeholder: Extension<PlaceholderOptions>;
16
+ export declare const Placeholder: Extension<PlaceholderOptions, any>;
@@ -3,17 +3,20 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var core = require('@tiptap/core');
6
- var prosemirrorView = require('prosemirror-view');
7
6
  var prosemirrorState = require('prosemirror-state');
7
+ var prosemirrorView = require('prosemirror-view');
8
8
 
9
9
  const Placeholder = core.Extension.create({
10
10
  name: 'placeholder',
11
- defaultOptions: {
12
- emptyEditorClass: 'is-editor-empty',
13
- emptyNodeClass: 'is-empty',
14
- placeholder: 'Write something …',
15
- showOnlyWhenEditable: true,
16
- showOnlyCurrent: true,
11
+ addOptions() {
12
+ return {
13
+ emptyEditorClass: 'is-editor-empty',
14
+ emptyNodeClass: 'is-empty',
15
+ placeholder: 'Write something …',
16
+ showOnlyWhenEditable: true,
17
+ showOnlyCurrent: true,
18
+ includeChildren: false,
19
+ };
17
20
  },
18
21
  addProseMirrorPlugins() {
19
22
  return [
@@ -24,11 +27,11 @@ const Placeholder = core.Extension.create({
24
27
  const { anchor } = selection;
25
28
  const decorations = [];
26
29
  if (!active) {
27
- return;
30
+ return null;
28
31
  }
29
32
  doc.descendants((node, pos) => {
30
33
  const hasAnchor = anchor >= pos && anchor <= (pos + node.nodeSize);
31
- const isEmpty = !node.isLeaf && !node.textContent;
34
+ const isEmpty = !node.isLeaf && !node.childCount;
32
35
  if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
33
36
  const classes = [this.options.emptyNodeClass];
34
37
  if (this.editor.isEmpty) {
@@ -40,12 +43,14 @@ const Placeholder = core.Extension.create({
40
43
  ? this.options.placeholder({
41
44
  editor: this.editor,
42
45
  node,
46
+ pos,
47
+ hasAnchor,
43
48
  })
44
49
  : this.options.placeholder,
45
50
  });
46
51
  decorations.push(decoration);
47
52
  }
48
- return false;
53
+ return this.options.includeChildren;
49
54
  });
50
55
  return prosemirrorView.DecorationSet.create(doc, decorations);
51
56
  },
@@ -56,5 +61,5 @@ const Placeholder = core.Extension.create({
56
61
  });
57
62
 
58
63
  exports.Placeholder = Placeholder;
59
- exports.default = Placeholder;
64
+ exports["default"] = Placeholder;
60
65
  //# sourceMappingURL=tiptap-extension-placeholder.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tiptap-extension-placeholder.cjs.js","sources":["../src/placeholder.ts"],"sourcesContent":["import { Editor, Extension, isNodeEmpty } from '@tiptap/core'\nimport { Node as ProsemirrorNode } from 'prosemirror-model'\nimport { Decoration, DecorationSet } from 'prosemirror-view'\nimport { Plugin } from 'prosemirror-state'\n\nexport interface PlaceholderOptions {\n emptyEditorClass: string,\n emptyNodeClass: string,\n placeholder: ((PlaceholderProps: {\n editor: Editor,\n node: ProsemirrorNode,\n }) => string) | string,\n showOnlyWhenEditable: boolean,\n showOnlyCurrent: boolean,\n}\n\nexport const Placeholder = Extension.create<PlaceholderOptions>({\n name: 'placeholder',\n\n defaultOptions: {\n emptyEditorClass: 'is-editor-empty',\n emptyNodeClass: 'is-empty',\n placeholder: 'Write something …',\n showOnlyWhenEditable: true,\n showOnlyCurrent: true,\n },\n\n addProseMirrorPlugins() {\n return [\n new Plugin({\n props: {\n decorations: ({ doc, selection }) => {\n const active = this.editor.isEditable || !this.options.showOnlyWhenEditable\n const { anchor } = selection\n const decorations: Decoration[] = []\n\n if (!active) {\n return\n }\n\n doc.descendants((node, pos) => {\n const hasAnchor = anchor >= pos && anchor <= (pos + node.nodeSize)\n const isEmpty = !node.isLeaf && !node.textContent\n\n if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {\n const classes = [this.options.emptyNodeClass]\n\n if (this.editor.isEmpty) {\n classes.push(this.options.emptyEditorClass)\n }\n\n const decoration = Decoration.node(pos, pos + node.nodeSize, {\n class: classes.join(' '),\n 'data-placeholder': typeof this.options.placeholder === 'function'\n ? this.options.placeholder({\n editor: this.editor,\n node,\n })\n : this.options.placeholder,\n })\n\n decorations.push(decoration)\n }\n\n return false\n })\n\n return DecorationSet.create(doc, decorations)\n },\n },\n }),\n ]\n },\n})\n"],"names":["Extension","Plugin","Decoration","DecorationSet"],"mappings":";;;;;;;;MAgBa,WAAW,GAAGA,cAAS,CAAC,MAAM,CAAqB;IAC9D,IAAI,EAAE,aAAa;IAEnB,cAAc,EAAE;QACd,gBAAgB,EAAE,iBAAiB;QACnC,cAAc,EAAE,UAAU;QAC1B,WAAW,EAAE,mBAAmB;QAChC,oBAAoB,EAAE,IAAI;QAC1B,eAAe,EAAE,IAAI;KACtB;IAED,qBAAqB;QACnB,OAAO;YACL,IAAIC,uBAAM,CAAC;gBACT,KAAK,EAAE;oBACL,WAAW,EAAE,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE;wBAC9B,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAA;wBAC3E,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAAA;wBAC5B,MAAM,WAAW,GAAiB,EAAE,CAAA;wBAEpC,IAAI,CAAC,MAAM,EAAE;4BACX,OAAM;yBACP;wBAED,GAAG,CAAC,WAAW,CAAC,CAAC,IAAI,EAAE,GAAG;4BACxB,MAAM,SAAS,GAAG,MAAM,IAAI,GAAG,IAAI,MAAM,KAAK,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAA;4BAClE,MAAM,OAAO,GAAG,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,WAAW,CAAA;4BAEjD,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe,KAAK,OAAO,EAAE;gCAC3D,MAAM,OAAO,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,CAAA;gCAE7C,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE;oCACvB,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAA;iCAC5C;gCAED,MAAM,UAAU,GAAGC,0BAAU,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC,QAAQ,EAAE;oCAC3D,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC;oCACxB,kBAAkB,EAAE,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,KAAK,UAAU;0CAC9D,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC;4CACzB,MAAM,EAAE,IAAI,CAAC,MAAM;4CACnB,IAAI;yCACL,CAAC;0CACA,IAAI,CAAC,OAAO,CAAC,WAAW;iCAC7B,CAAC,CAAA;gCAEF,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;6BAC7B;4BAED,OAAO,KAAK,CAAA;yBACb,CAAC,CAAA;wBAEF,OAAOC,6BAAa,CAAC,MAAM,CAAC,GAAG,EAAE,WAAW,CAAC,CAAA;qBAC9C;iBACF;aACF,CAAC;SACH,CAAA;KACF;CACF;;;;;"}
1
+ {"version":3,"file":"tiptap-extension-placeholder.cjs.js","sources":["../src/placeholder.ts"],"sourcesContent":["import { Editor, Extension } from '@tiptap/core'\nimport { Node as ProsemirrorNode } from 'prosemirror-model'\nimport { Plugin } from 'prosemirror-state'\nimport { Decoration, DecorationSet } from 'prosemirror-view'\n\nexport interface PlaceholderOptions {\n emptyEditorClass: string,\n emptyNodeClass: string,\n placeholder: ((PlaceholderProps: {\n editor: Editor,\n node: ProsemirrorNode,\n pos: number,\n hasAnchor: boolean,\n }) => string) | string,\n showOnlyWhenEditable: boolean,\n showOnlyCurrent: boolean,\n includeChildren: boolean,\n}\n\nexport const Placeholder = Extension.create<PlaceholderOptions>({\n name: 'placeholder',\n\n addOptions() {\n return {\n emptyEditorClass: 'is-editor-empty',\n emptyNodeClass: 'is-empty',\n placeholder: 'Write something …',\n showOnlyWhenEditable: true,\n showOnlyCurrent: true,\n includeChildren: false,\n }\n },\n\n addProseMirrorPlugins() {\n return [\n new Plugin({\n props: {\n decorations: ({ doc, selection }) => {\n const active = this.editor.isEditable || !this.options.showOnlyWhenEditable\n const { anchor } = selection\n const decorations: Decoration[] = []\n\n if (!active) {\n return null\n }\n\n doc.descendants((node, pos) => {\n const hasAnchor = anchor >= pos && anchor <= (pos + node.nodeSize)\n const isEmpty = !node.isLeaf && !node.childCount\n\n if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {\n const classes = [this.options.emptyNodeClass]\n\n if (this.editor.isEmpty) {\n classes.push(this.options.emptyEditorClass)\n }\n\n const decoration = Decoration.node(pos, pos + node.nodeSize, {\n class: classes.join(' '),\n 'data-placeholder': typeof this.options.placeholder === 'function'\n ? this.options.placeholder({\n editor: this.editor,\n node,\n pos,\n hasAnchor,\n })\n : this.options.placeholder,\n })\n\n decorations.push(decoration)\n }\n\n return this.options.includeChildren\n })\n\n return DecorationSet.create(doc, decorations)\n },\n },\n }),\n ]\n },\n})\n"],"names":["Extension","Plugin","Decoration","DecorationSet"],"mappings":";;;;;;;;AAmBa,MAAA,WAAW,GAAGA,cAAS,CAAC,MAAM,CAAqB;AAC9D,IAAA,IAAI,EAAE,aAAa;IAEnB,UAAU,GAAA;QACR,OAAO;AACL,YAAA,gBAAgB,EAAE,iBAAiB;AACnC,YAAA,cAAc,EAAE,UAAU;AAC1B,YAAA,WAAW,EAAE,mBAAmB;AAChC,YAAA,oBAAoB,EAAE,IAAI;AAC1B,YAAA,eA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;oCACxB,kBAAkB,EAAE,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,KAAK,UAAU;AAChE,0CAAE,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC;4CACzB,MAAM,EAAE,IAAI,CAAC,MAAM;4CACnB,IAAI;4CACJ,GAAG;4CACH,SAAS;yCACV,CAAC;AACF,0CAAE,IAAI,CAAC,OAAO,CAAC,WAAW;AAC7B,iCAAA,CAAC,CAAA;AAEF,gCAAA,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;AAC7B,6BAAA;AAED,4BAAA,OAAO,IAAI,CAAC,OAAO,CAAC,eAAe,CAAA;AACrC,yBAAC,CAAC,CAAA;wBAEF,OAAOC,6BAAa,CAAC,MAAM,CAAC,GAAG,EAAE,WAAW,CAAC,CAAA;qBAC9C;AACF,iBAAA;aACF,CAAC;SACH,CAAA;KACF;AACF,CAAA;;;;;"}
@@ -1,15 +1,18 @@
1
1
  import { Extension } from '@tiptap/core';
2
- import { Decoration, DecorationSet } from 'prosemirror-view';
3
2
  import { Plugin } from 'prosemirror-state';
3
+ import { Decoration, DecorationSet } from 'prosemirror-view';
4
4
 
5
5
  const Placeholder = Extension.create({
6
6
  name: 'placeholder',
7
- defaultOptions: {
8
- emptyEditorClass: 'is-editor-empty',
9
- emptyNodeClass: 'is-empty',
10
- placeholder: 'Write something …',
11
- showOnlyWhenEditable: true,
12
- showOnlyCurrent: true,
7
+ addOptions() {
8
+ return {
9
+ emptyEditorClass: 'is-editor-empty',
10
+ emptyNodeClass: 'is-empty',
11
+ placeholder: 'Write something …',
12
+ showOnlyWhenEditable: true,
13
+ showOnlyCurrent: true,
14
+ includeChildren: false,
15
+ };
13
16
  },
14
17
  addProseMirrorPlugins() {
15
18
  return [
@@ -20,11 +23,11 @@ const Placeholder = Extension.create({
20
23
  const { anchor } = selection;
21
24
  const decorations = [];
22
25
  if (!active) {
23
- return;
26
+ return null;
24
27
  }
25
28
  doc.descendants((node, pos) => {
26
29
  const hasAnchor = anchor >= pos && anchor <= (pos + node.nodeSize);
27
- const isEmpty = !node.isLeaf && !node.textContent;
30
+ const isEmpty = !node.isLeaf && !node.childCount;
28
31
  if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
29
32
  const classes = [this.options.emptyNodeClass];
30
33
  if (this.editor.isEmpty) {
@@ -36,12 +39,14 @@ const Placeholder = Extension.create({
36
39
  ? this.options.placeholder({
37
40
  editor: this.editor,
38
41
  node,
42
+ pos,
43
+ hasAnchor,
39
44
  })
40
45
  : this.options.placeholder,
41
46
  });
42
47
  decorations.push(decoration);
43
48
  }
44
- return false;
49
+ return this.options.includeChildren;
45
50
  });
46
51
  return DecorationSet.create(doc, decorations);
47
52
  },
@@ -51,6 +56,5 @@ const Placeholder = Extension.create({
51
56
  },
52
57
  });
53
58
 
54
- export default Placeholder;
55
- export { Placeholder };
59
+ export { Placeholder, Placeholder as default };
56
60
  //# sourceMappingURL=tiptap-extension-placeholder.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tiptap-extension-placeholder.esm.js","sources":["../src/placeholder.ts"],"sourcesContent":["import { Editor, Extension, isNodeEmpty } from '@tiptap/core'\nimport { Node as ProsemirrorNode } from 'prosemirror-model'\nimport { Decoration, DecorationSet } from 'prosemirror-view'\nimport { Plugin } from 'prosemirror-state'\n\nexport interface PlaceholderOptions {\n emptyEditorClass: string,\n emptyNodeClass: string,\n placeholder: ((PlaceholderProps: {\n editor: Editor,\n node: ProsemirrorNode,\n }) => string) | string,\n showOnlyWhenEditable: boolean,\n showOnlyCurrent: boolean,\n}\n\nexport const Placeholder = Extension.create<PlaceholderOptions>({\n name: 'placeholder',\n\n defaultOptions: {\n emptyEditorClass: 'is-editor-empty',\n emptyNodeClass: 'is-empty',\n placeholder: 'Write something …',\n showOnlyWhenEditable: true,\n showOnlyCurrent: true,\n },\n\n addProseMirrorPlugins() {\n return [\n new Plugin({\n props: {\n decorations: ({ doc, selection }) => {\n const active = this.editor.isEditable || !this.options.showOnlyWhenEditable\n const { anchor } = selection\n const decorations: Decoration[] = []\n\n if (!active) {\n return\n }\n\n doc.descendants((node, pos) => {\n const hasAnchor = anchor >= pos && anchor <= (pos + node.nodeSize)\n const isEmpty = !node.isLeaf && !node.textContent\n\n if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {\n const classes = [this.options.emptyNodeClass]\n\n if (this.editor.isEmpty) {\n classes.push(this.options.emptyEditorClass)\n }\n\n const decoration = Decoration.node(pos, pos + node.nodeSize, {\n class: classes.join(' '),\n 'data-placeholder': typeof this.options.placeholder === 'function'\n ? this.options.placeholder({\n editor: this.editor,\n node,\n })\n : this.options.placeholder,\n })\n\n decorations.push(decoration)\n }\n\n return false\n })\n\n return DecorationSet.create(doc, decorations)\n },\n },\n }),\n ]\n },\n})\n"],"names":[],"mappings":";;;;MAgBa,WAAW,GAAG,SAAS,CAAC,MAAM,CAAqB;IAC9D,IAAI,EAAE,aAAa;IAEnB,cAAc,EAAE;QACd,gBAAgB,EAAE,iBAAiB;QACnC,cAAc,EAAE,UAAU;QAC1B,WAAW,EAAE,mBAAmB;QAChC,oBAAoB,EAAE,IAAI;QAC1B,eAAe,EAAE,IAAI;KACtB;IAED,qBAAqB;QACnB,OAAO;YACL,IAAI,MAAM,CAAC;gBACT,KAAK,EAAE;oBACL,WAAW,EAAE,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE;wBAC9B,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAA;wBAC3E,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAAA;wBAC5B,MAAM,WAAW,GAAiB,EAAE,CAAA;wBAEpC,IAAI,CAAC,MAAM,EAAE;4BACX,OAAM;yBACP;wBAED,GAAG,CAAC,WAAW,CAAC,CAAC,IAAI,EAAE,GAAG;4BACxB,MAAM,SAAS,GAAG,MAAM,IAAI,GAAG,IAAI,MAAM,KAAK,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAA;4BAClE,MAAM,OAAO,GAAG,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,WAAW,CAAA;4BAEjD,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe,KAAK,OAAO,EAAE;gCAC3D,MAAM,OAAO,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,CAAA;gCAE7C,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE;oCACvB,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAA;iCAC5C;gCAED,MAAM,UAAU,GAAG,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC,QAAQ,EAAE;oCAC3D,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC;oCACxB,kBAAkB,EAAE,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,KAAK,UAAU;0CAC9D,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC;4CACzB,MAAM,EAAE,IAAI,CAAC,MAAM;4CACnB,IAAI;yCACL,CAAC;0CACA,IAAI,CAAC,OAAO,CAAC,WAAW;iCAC7B,CAAC,CAAA;gCAEF,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;6BAC7B;4BAED,OAAO,KAAK,CAAA;yBACb,CAAC,CAAA;wBAEF,OAAO,aAAa,CAAC,MAAM,CAAC,GAAG,EAAE,WAAW,CAAC,CAAA;qBAC9C;iBACF;aACF,CAAC;SACH,CAAA;KACF;CACF;;;;;"}
1
+ {"version":3,"file":"tiptap-extension-placeholder.esm.js","sources":["../src/placeholder.ts"],"sourcesContent":["import { Editor, Extension } from '@tiptap/core'\nimport { Node as ProsemirrorNode } from 'prosemirror-model'\nimport { Plugin } from 'prosemirror-state'\nimport { Decoration, DecorationSet } from 'prosemirror-view'\n\nexport interface PlaceholderOptions {\n emptyEditorClass: string,\n emptyNodeClass: string,\n placeholder: ((PlaceholderProps: {\n editor: Editor,\n node: ProsemirrorNode,\n pos: number,\n hasAnchor: boolean,\n }) => string) | string,\n showOnlyWhenEditable: boolean,\n showOnlyCurrent: boolean,\n includeChildren: boolean,\n}\n\nexport const Placeholder = Extension.create<PlaceholderOptions>({\n name: 'placeholder',\n\n addOptions() {\n return {\n emptyEditorClass: 'is-editor-empty',\n emptyNodeClass: 'is-empty',\n placeholder: 'Write something …',\n showOnlyWhenEditable: true,\n showOnlyCurrent: true,\n includeChildren: false,\n }\n },\n\n addProseMirrorPlugins() {\n return [\n new Plugin({\n props: {\n decorations: ({ doc, selection }) => {\n const active = this.editor.isEditable || !this.options.showOnlyWhenEditable\n const { anchor } = selection\n const decorations: Decoration[] = []\n\n if (!active) {\n return null\n }\n\n doc.descendants((node, pos) => {\n const hasAnchor = anchor >= pos && anchor <= (pos + node.nodeSize)\n const isEmpty = !node.isLeaf && !node.childCount\n\n if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {\n const classes = [this.options.emptyNodeClass]\n\n if (this.editor.isEmpty) {\n classes.push(this.options.emptyEditorClass)\n }\n\n const decoration = Decoration.node(pos, pos + node.nodeSize, {\n class: classes.join(' '),\n 'data-placeholder': typeof this.options.placeholder === 'function'\n ? this.options.placeholder({\n editor: this.editor,\n node,\n pos,\n hasAnchor,\n })\n : this.options.placeholder,\n })\n\n decorations.push(decoration)\n }\n\n return this.options.includeChildren\n })\n\n return DecorationSet.create(doc, decorations)\n },\n },\n }),\n ]\n },\n})\n"],"names":[],"mappings":";;;;AAmBa,MAAA,WAAW,GAAG,SAAS,CAAC,MAAM,CAAqB;AAC9D,IAAA,IAAI,EAAE,aAAa;IAEnB,UAAU,GAAA;QACR,OAAO;AACL,YAAA,gBAAgB,EAAE,iBAAiB;AACnC,YAAA,cAAc,EAAE,UAAU;AAC1B,YAAA,WAAW,EAAE,mBAAmB;AAChC,YAAA,oBAAoB,EAAE,IAAI;AA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AG,CAAC;oCACxB,kBAAkB,EAAE,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,KAAK,UAAU;AAChE,0CAAE,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC;4CACzB,MAAM,EAAE,IAAI,CAAC,MAAM;4CACnB,IAAI;4CACJ,GAAG;4CACH,SAAS;yCACV,CAAC;AACF,0CAAE,IAAI,CAAC,OAAO,CAAC,WAAW;AAC7B,iCAAA,CAAC,CAAA;AAEF,gCAAA,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;AAC7B,6BAAA;AAED,4BAAA,OAAO,IAAI,CAAC,OAAO,CAAC,eAAe,CAAA;AACrC,yBAAC,CAAC,CAAA;wBAEF,OAAO,aAAa,CAAC,MAAM,CAAC,GAAG,EAAE,WAAW,CAAC,CAAA;qBAC9C;AACF,iBAAA;aACF,CAAC;SACH,CAAA;KACF;AACF,CAAA;;;;"}
@@ -1,17 +1,20 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@tiptap/core'), require('prosemirror-view'), require('prosemirror-state')) :
3
- typeof define === 'function' && define.amd ? define(['exports', '@tiptap/core', 'prosemirror-view', 'prosemirror-state'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global['@tiptap/extension-placeholder'] = {}, global.core, global.prosemirrorView, global.prosemirrorState));
5
- }(this, (function (exports, core, prosemirrorView, prosemirrorState) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@tiptap/core'), require('prosemirror-state'), require('prosemirror-view')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', '@tiptap/core', 'prosemirror-state', 'prosemirror-view'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@tiptap/extension-placeholder"] = {}, global.core, global.prosemirrorState, global.prosemirrorView));
5
+ })(this, (function (exports, core, prosemirrorState, prosemirrorView) { 'use strict';
6
6
 
7
7
  const Placeholder = core.Extension.create({
8
8
  name: 'placeholder',
9
- defaultOptions: {
10
- emptyEditorClass: 'is-editor-empty',
11
- emptyNodeClass: 'is-empty',
12
- placeholder: 'Write something …',
13
- showOnlyWhenEditable: true,
14
- showOnlyCurrent: true,
9
+ addOptions() {
10
+ return {
11
+ emptyEditorClass: 'is-editor-empty',
12
+ emptyNodeClass: 'is-empty',
13
+ placeholder: 'Write something …',
14
+ showOnlyWhenEditable: true,
15
+ showOnlyCurrent: true,
16
+ includeChildren: false,
17
+ };
15
18
  },
16
19
  addProseMirrorPlugins() {
17
20
  return [
@@ -22,11 +25,11 @@
22
25
  const { anchor } = selection;
23
26
  const decorations = [];
24
27
  if (!active) {
25
- return;
28
+ return null;
26
29
  }
27
30
  doc.descendants((node, pos) => {
28
31
  const hasAnchor = anchor >= pos && anchor <= (pos + node.nodeSize);
29
- const isEmpty = !node.isLeaf && !node.textContent;
32
+ const isEmpty = !node.isLeaf && !node.childCount;
30
33
  if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
31
34
  const classes = [this.options.emptyNodeClass];
32
35
  if (this.editor.isEmpty) {
@@ -38,12 +41,14 @@
38
41
  ? this.options.placeholder({
39
42
  editor: this.editor,
40
43
  node,
44
+ pos,
45
+ hasAnchor,
41
46
  })
42
47
  : this.options.placeholder,
43
48
  });
44
49
  decorations.push(decoration);
45
50
  }
46
- return false;
51
+ return this.options.includeChildren;
47
52
  });
48
53
  return prosemirrorView.DecorationSet.create(doc, decorations);
49
54
  },
@@ -54,9 +59,9 @@
54
59
  });
55
60
 
56
61
  exports.Placeholder = Placeholder;
57
- exports.default = Placeholder;
62
+ exports["default"] = Placeholder;
58
63
 
59
64
  Object.defineProperty(exports, '__esModule', { value: true });
60
65
 
61
- })));
66
+ }));
62
67
  //# sourceMappingURL=tiptap-extension-placeholder.umd.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tiptap-extension-placeholder.umd.js","sources":["../src/placeholder.ts"],"sourcesContent":["import { Editor, Extension, isNodeEmpty } from '@tiptap/core'\nimport { Node as ProsemirrorNode } from 'prosemirror-model'\nimport { Decoration, DecorationSet } from 'prosemirror-view'\nimport { Plugin } from 'prosemirror-state'\n\nexport interface PlaceholderOptions {\n emptyEditorClass: string,\n emptyNodeClass: string,\n placeholder: ((PlaceholderProps: {\n editor: Editor,\n node: ProsemirrorNode,\n }) => string) | string,\n showOnlyWhenEditable: boolean,\n showOnlyCurrent: boolean,\n}\n\nexport const Placeholder = Extension.create<PlaceholderOptions>({\n name: 'placeholder',\n\n defaultOptions: {\n emptyEditorClass: 'is-editor-empty',\n emptyNodeClass: 'is-empty',\n placeholder: 'Write something …',\n showOnlyWhenEditable: true,\n showOnlyCurrent: true,\n },\n\n addProseMirrorPlugins() {\n return [\n new Plugin({\n props: {\n decorations: ({ doc, selection }) => {\n const active = this.editor.isEditable || !this.options.showOnlyWhenEditable\n const { anchor } = selection\n const decorations: Decoration[] = []\n\n if (!active) {\n return\n }\n\n doc.descendants((node, pos) => {\n const hasAnchor = anchor >= pos && anchor <= (pos + node.nodeSize)\n const isEmpty = !node.isLeaf && !node.textContent\n\n if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {\n const classes = [this.options.emptyNodeClass]\n\n if (this.editor.isEmpty) {\n classes.push(this.options.emptyEditorClass)\n }\n\n const decoration = Decoration.node(pos, pos + node.nodeSize, {\n class: classes.join(' '),\n 'data-placeholder': typeof this.options.placeholder === 'function'\n ? this.options.placeholder({\n editor: this.editor,\n node,\n })\n : this.options.placeholder,\n })\n\n decorations.push(decoration)\n }\n\n return false\n })\n\n return DecorationSet.create(doc, decorations)\n },\n },\n }),\n ]\n },\n})\n"],"names":["Extension","Plugin","Decoration","DecorationSet"],"mappings":";;;;;;QAgBa,WAAW,GAAGA,cAAS,CAAC,MAAM,CAAqB;MAC9D,IAAI,EAAE,aAAa;MAEnB,cAAc,EAAE;UACd,gBAAgB,EAAE,iBAAiB;UACnC,cAAc,EAAE,UAAU;UAC1B,WAAW,EAAE,mBAA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AAW,CAAC;8CACzB,MAAM,EAAE,IAAI,CAAC,MAAM;8CACnB,IAAI;2CACL,CAAC;4CACA,IAAI,CAAC,OAAO,CAAC,WAAW;mCAC7B,CAAC,CAAA;kCAEF,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;+BAC7B;8BAED,OAAO,KAAK,CAAA;2BACb,CAAC,CAAA;0BAEF,OAAOC,6BAAa,CAAC,MAAM,CAAC,GAAG,EAAE,WAAW,CAAC,CAAA;uBAC9C;mBACF;eACF,CAAC;WACH,CAAA;OACF;GACF;;;;;;;;;;;"}
1
+ {"version":3,"file":"tiptap-extension-placeholder.umd.js","sources":["../src/placeholder.ts"],"sourcesContent":["import { Editor, Extension } from '@tiptap/core'\nimport { Node as ProsemirrorNode } from 'prosemirror-model'\nimport { Plugin } from 'prosemirror-state'\nimport { Decoration, DecorationSet } from 'prosemirror-view'\n\nexport interface PlaceholderOptions {\n emptyEditorClass: string,\n emptyNodeClass: string,\n placeholder: ((PlaceholderProps: {\n editor: Editor,\n node: ProsemirrorNode,\n pos: number,\n hasAnchor: boolean,\n }) => string) | string,\n showOnlyWhenEditable: boolean,\n showOnlyCurrent: boolean,\n includeChildren: boolean,\n}\n\nexport const Placeholder = Extension.create<PlaceholderOptions>({\n name: 'placeholder',\n\n addOptions() {\n return {\n emptyEditorClass: 'is-editor-empty',\n emptyNodeClass: 'is-empty',\n placeholder: 'Write something …',\n showOnlyWhenEditable: true,\n showOnlyCurrent: true,\n includeChildren: false,\n }\n },\n\n addProseMirrorPlugins() {\n return [\n new Plugin({\n props: {\n decorations: ({ doc, selection }) => {\n const active = this.editor.isEditable || !this.options.showOnlyWhenEditable\n const { anchor } = selection\n const decorations: Decoration[] = []\n\n if (!active) {\n return null\n }\n\n doc.descendants((node, pos) => {\n const hasAnchor = anchor >= pos && anchor <= (pos + node.nodeSize)\n const isEmpty = !node.isLeaf && !node.childCount\n\n if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {\n const classes = [this.options.emptyNodeClass]\n\n if (this.editor.isEmpty) {\n classes.push(this.options.emptyEditorClass)\n }\n\n const decoration = Decoration.node(pos, pos + node.nodeSize, {\n class: classes.join(' '),\n 'data-placeholder': typeof this.options.placeholder === 'function'\n ? this.options.placeholder({\n editor: this.editor,\n node,\n pos,\n hasAnchor,\n })\n : this.options.placeholder,\n })\n\n decorations.push(decoration)\n }\n\n return this.options.includeChildren\n })\n\n return DecorationSet.create(doc, decorations)\n },\n },\n }),\n ]\n },\n})\n"],"names":["Extension","Plugin","Decoration","DecorationSet"],"mappings":";;;;;;AAmBa,QAAA,WAAW,GAAGA,cAAS,CAAC,MAAM,CAAqB;EAC9D,IAAA,IAAI,EAAE,aAAa;MAEnB,UAAU,GAAA;UACR,OAAO;EACL,YAAA,gBAAgB,EAAE,iBAAiB;EACnC,YAAA,cAAc,EAAE,UAAU;EAC1B,YAAA,WAAW,EAAE,mBAAmB;EAChC,YAAA,oBAAoB,EAAE,IAAI;EAC1B,YAAA,eAAe,EAAE,IAAI;EACrB,YAAA,eAAe,EAAE,KAAK;WACvB,CAAA;OACF;MAED,qBAAqB,GAAA;UACnB,OAAO;EACL,YAAA,IAAIC,uBAAM,CAAC;EACT,gBAAA,KAAK,EAAE;sBACL,WAAW,EAAE,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,KAAI;EAClC,wBAAA,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAA;EAC3E,wBAAA,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAAA;0BAC5B,MAAM,WAAW,GAAiB,EAAE,CAAA;0BAEpC,IAAI,CAAC,MAAM,EAAE;EACX,4BAAA,OAAO,IAAI,CAAA;EACZ,yBAAA;0BAED,GAAG,CAAC,WAAW,CAAC,CAAC,IAAI,EAAE,GAAG,KAAI;EAC5B,4BAAA,MAAM,SAAS,GAAG,MAAM,IAAI,GAAG,IAAI,MAAM,K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name": "@tiptap/extension-placeholder",
3
3
  "description": "placeholder extension for tiptap",
4
- "version": "2.0.0-beta.19",
4
+ "version": "2.0.0-beta.194",
5
5
  "homepage": "https://tiptap.dev",
6
6
  "keywords": [
7
7
  "tiptap",
@@ -21,12 +21,16 @@
21
21
  "dist"
22
22
  ],
23
23
  "peerDependencies": {
24
- "@tiptap/core": "^2.0.0-beta.1"
24
+ "@tiptap/core": "^2.0.0-beta.193"
25
25
  },
26
26
  "dependencies": {
27
- "prosemirror-model": "^1.14.1",
28
- "prosemirror-state": "^1.3.4",
29
- "prosemirror-view": "^1.18.6"
27
+ "prosemirror-model": "1.18.1",
28
+ "prosemirror-state": "1.4.1",
29
+ "prosemirror-view": "1.26.2"
30
30
  },
31
- "gitHead": "6b154e4c8161fbba987e162ebebc155243432f24"
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "https://github.com/ueberdosis/tiptap",
34
+ "directory": "packages/extension-placeholder"
35
+ }
32
36
  }
@@ -1,7 +1,7 @@
1
- import { Editor, Extension, isNodeEmpty } from '@tiptap/core'
1
+ import { Editor, Extension } from '@tiptap/core'
2
2
  import { Node as ProsemirrorNode } from 'prosemirror-model'
3
- import { Decoration, DecorationSet } from 'prosemirror-view'
4
3
  import { Plugin } from 'prosemirror-state'
4
+ import { Decoration, DecorationSet } from 'prosemirror-view'
5
5
 
6
6
  export interface PlaceholderOptions {
7
7
  emptyEditorClass: string,
@@ -9,20 +9,26 @@ export interface PlaceholderOptions {
9
9
  placeholder: ((PlaceholderProps: {
10
10
  editor: Editor,
11
11
  node: ProsemirrorNode,
12
+ pos: number,
13
+ hasAnchor: boolean,
12
14
  }) => string) | string,
13
15
  showOnlyWhenEditable: boolean,
14
16
  showOnlyCurrent: boolean,
17
+ includeChildren: boolean,
15
18
  }
16
19
 
17
20
  export const Placeholder = Extension.create<PlaceholderOptions>({
18
21
  name: 'placeholder',
19
22
 
20
- defaultOptions: {
21
- emptyEditorClass: 'is-editor-empty',
22
- emptyNodeClass: 'is-empty',
23
- placeholder: 'Write something …',
24
- showOnlyWhenEditable: true,
25
- showOnlyCurrent: true,
23
+ addOptions() {
24
+ return {
25
+ emptyEditorClass: 'is-editor-empty',
26
+ emptyNodeClass: 'is-empty',
27
+ placeholder: 'Write something …',
28
+ showOnlyWhenEditable: true,
29
+ showOnlyCurrent: true,
30
+ includeChildren: false,
31
+ }
26
32
  },
27
33
 
28
34
  addProseMirrorPlugins() {
@@ -35,12 +41,12 @@ export const Placeholder = Extension.create<PlaceholderOptions>({
35
41
  const decorations: Decoration[] = []
36
42
 
37
43
  if (!active) {
38
- return
44
+ return null
39
45
  }
40
46
 
41
47
  doc.descendants((node, pos) => {
42
48
  const hasAnchor = anchor >= pos && anchor <= (pos + node.nodeSize)
43
- const isEmpty = !node.isLeaf && !node.textContent
49
+ const isEmpty = !node.isLeaf && !node.childCount
44
50
 
45
51
  if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
46
52
  const classes = [this.options.emptyNodeClass]
@@ -55,6 +61,8 @@ export const Placeholder = Extension.create<PlaceholderOptions>({
55
61
  ? this.options.placeholder({
56
62
  editor: this.editor,
57
63
  node,
64
+ pos,
65
+ hasAnchor,
58
66
  })
59
67
  : this.options.placeholder,
60
68
  })
@@ -62,7 +70,7 @@ export const Placeholder = Extension.create<PlaceholderOptions>({
62
70
  decorations.push(decoration)
63
71
  }
64
72
 
65
- return false
73
+ return this.options.includeChildren
66
74
  })
67
75
 
68
76
  return DecorationSet.create(doc, decorations)
package/CHANGELOG.md DELETED
@@ -1,164 +0,0 @@
1
- # Change Log
2
-
3
- All notable changes to this project will be documented in this file.
4
- See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
-
6
- # [2.0.0-beta.19](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-placeholder@2.0.0-beta.18...@tiptap/extension-placeholder@2.0.0-beta.19) (2021-05-18)
7
-
8
- **Note:** Version bump only for package @tiptap/extension-placeholder
9
-
10
-
11
-
12
-
13
-
14
- # [2.0.0-beta.18](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-placeholder@2.0.0-beta.17...@tiptap/extension-placeholder@2.0.0-beta.18) (2021-05-17)
15
-
16
- **Note:** Version bump only for package @tiptap/extension-placeholder
17
-
18
-
19
-
20
-
21
-
22
- # [2.0.0-beta.17](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-placeholder@2.0.0-beta.16...@tiptap/extension-placeholder@2.0.0-beta.17) (2021-05-13)
23
-
24
-
25
- ### Bug Fixes
26
-
27
- * check for empty text, fix [#1292](https://github.com/ueberdosis/tiptap/issues/1292) ([456f2b7](https://github.com/ueberdosis/tiptap/commit/456f2b702b146cc3f4a156a71cba8354990c02e0))
28
-
29
-
30
-
31
-
32
-
33
- # [2.0.0-beta.16](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-placeholder@2.0.0-beta.15...@tiptap/extension-placeholder@2.0.0-beta.16) (2021-05-13)
34
-
35
- **Note:** Version bump only for package @tiptap/extension-placeholder
36
-
37
-
38
-
39
-
40
-
41
- # [2.0.0-beta.15](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-placeholder@2.0.0-beta.14...@tiptap/extension-placeholder@2.0.0-beta.15) (2021-05-07)
42
-
43
-
44
- ### Bug Fixes
45
-
46
- * revert adding exports ([bc320d0](https://github.com/ueberdosis/tiptap/commit/bc320d0b4b80b0e37a7e47a56e0f6daec6e65d98))
47
-
48
-
49
-
50
-
51
-
52
- # [2.0.0-beta.14](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-placeholder@2.0.0-beta.13...@tiptap/extension-placeholder@2.0.0-beta.14) (2021-05-06)
53
-
54
-
55
- ### Bug Fixes
56
-
57
- * revert adding type: module ([f8d6475](https://github.com/ueberdosis/tiptap/commit/f8d6475e2151faea6f96baecdd6bd75880d50d2c))
58
-
59
-
60
-
61
-
62
-
63
- # [2.0.0-beta.13](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-placeholder@2.0.0-beta.12...@tiptap/extension-placeholder@2.0.0-beta.13) (2021-05-06)
64
-
65
-
66
- ### Bug Fixes
67
-
68
- * add exports to package.json ([1277fa4](https://github.com/ueberdosis/tiptap/commit/1277fa47151e9c039508cdb219bdd0ffe647f4ee))
69
-
70
-
71
-
72
-
73
-
74
- # [2.0.0-beta.12](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-placeholder@2.0.0-beta.11...@tiptap/extension-placeholder@2.0.0-beta.12) (2021-05-06)
75
-
76
- **Note:** Version bump only for package @tiptap/extension-placeholder
77
-
78
-
79
-
80
-
81
-
82
- # [2.0.0-beta.11](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-placeholder@2.0.0-beta.10...@tiptap/extension-placeholder@2.0.0-beta.11) (2021-05-05)
83
-
84
- **Note:** Version bump only for package @tiptap/extension-placeholder
85
-
86
-
87
-
88
-
89
-
90
- # [2.0.0-beta.10](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-placeholder@2.0.0-beta.9...@tiptap/extension-placeholder@2.0.0-beta.10) (2021-05-04)
91
-
92
- **Note:** Version bump only for package @tiptap/extension-placeholder
93
-
94
-
95
-
96
-
97
-
98
- # [2.0.0-beta.9](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-placeholder@2.0.0-beta.8...@tiptap/extension-placeholder@2.0.0-beta.9) (2021-04-27)
99
-
100
- **Note:** Version bump only for package @tiptap/extension-placeholder
101
-
102
-
103
-
104
-
105
-
106
- # [2.0.0-beta.8](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-placeholder@2.0.0-beta.7...@tiptap/extension-placeholder@2.0.0-beta.8) (2021-04-23)
107
-
108
- **Note:** Version bump only for package @tiptap/extension-placeholder
109
-
110
-
111
-
112
-
113
-
114
- # [2.0.0-beta.7](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-placeholder@2.0.0-beta.6...@tiptap/extension-placeholder@2.0.0-beta.7) (2021-04-22)
115
-
116
- **Note:** Version bump only for package @tiptap/extension-placeholder
117
-
118
-
119
-
120
-
121
-
122
- # [2.0.0-beta.6](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-placeholder@2.0.0-beta.5...@tiptap/extension-placeholder@2.0.0-beta.6) (2021-04-16)
123
-
124
- **Note:** Version bump only for package @tiptap/extension-placeholder
125
-
126
-
127
-
128
-
129
-
130
- # [2.0.0-beta.5](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-placeholder@2.0.0-beta.4...@tiptap/extension-placeholder@2.0.0-beta.5) (2021-04-15)
131
-
132
- **Note:** Version bump only for package @tiptap/extension-placeholder
133
-
134
-
135
-
136
-
137
-
138
- # [2.0.0-beta.4](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-placeholder@2.0.0-beta.3...@tiptap/extension-placeholder@2.0.0-beta.4) (2021-04-06)
139
-
140
- **Note:** Version bump only for package @tiptap/extension-placeholder
141
-
142
-
143
-
144
-
145
-
146
- # [2.0.0-beta.3](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-placeholder@2.0.0-beta.2...@tiptap/extension-placeholder@2.0.0-beta.3) (2021-03-31)
147
-
148
- **Note:** Version bump only for package @tiptap/extension-placeholder
149
-
150
-
151
-
152
-
153
-
154
- # [2.0.0-beta.2](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-placeholder@2.0.0-beta.1...@tiptap/extension-placeholder@2.0.0-beta.2) (2021-03-28)
155
-
156
- **Note:** Version bump only for package @tiptap/extension-placeholder
157
-
158
-
159
-
160
-
161
-
162
- # 2.0.0-beta.1 (2021-03-24)
163
-
164
- **Note:** Version bump only for package @tiptap/extension-placeholder
package/LICENSE.md DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2021, überdosis GbR
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.