@gravity-ui/markdown-editor 14.5.0 → 14.5.1

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.
Files changed (31) hide show
  1. package/build/cjs/extensions/yfm/Checkbox/CheckboxSpecs/const.d.ts +7 -0
  2. package/build/cjs/extensions/yfm/Checkbox/CheckboxSpecs/const.js +8 -1
  3. package/build/cjs/extensions/yfm/Checkbox/CheckboxSpecs/index.d.ts +1 -1
  4. package/build/cjs/extensions/yfm/Checkbox/CheckboxSpecs/index.js +2 -1
  5. package/build/cjs/extensions/yfm/Checkbox/CheckboxSpecs/schema.d.ts +1 -1
  6. package/build/cjs/extensions/yfm/Checkbox/CheckboxSpecs/schema.js +7 -7
  7. package/build/cjs/extensions/yfm/Checkbox/CheckboxSpecs/serializer.d.ts +1 -1
  8. package/build/cjs/extensions/yfm/Checkbox/CheckboxSpecs/serializer.js +2 -2
  9. package/build/cjs/extensions/yfm/Checkbox/const.d.ts +1 -1
  10. package/build/cjs/extensions/yfm/Checkbox/const.js +2 -1
  11. package/build/cjs/extensions/yfm/Checkbox/index.d.ts +2 -2
  12. package/build/cjs/extensions/yfm/Checkbox/index.js +4 -38
  13. package/build/cjs/extensions/yfm/Checkbox/nodeviews.d.ts +16 -0
  14. package/build/cjs/extensions/yfm/Checkbox/nodeviews.js +56 -0
  15. package/build/cjs/version.js +1 -1
  16. package/build/esm/extensions/yfm/Checkbox/CheckboxSpecs/const.d.ts +7 -0
  17. package/build/esm/extensions/yfm/Checkbox/CheckboxSpecs/const.js +7 -0
  18. package/build/esm/extensions/yfm/Checkbox/CheckboxSpecs/index.d.ts +1 -1
  19. package/build/esm/extensions/yfm/Checkbox/CheckboxSpecs/index.js +1 -1
  20. package/build/esm/extensions/yfm/Checkbox/CheckboxSpecs/schema.d.ts +1 -1
  21. package/build/esm/extensions/yfm/Checkbox/CheckboxSpecs/schema.js +7 -7
  22. package/build/esm/extensions/yfm/Checkbox/CheckboxSpecs/serializer.d.ts +1 -1
  23. package/build/esm/extensions/yfm/Checkbox/CheckboxSpecs/serializer.js +2 -2
  24. package/build/esm/extensions/yfm/Checkbox/const.d.ts +1 -1
  25. package/build/esm/extensions/yfm/Checkbox/const.js +1 -1
  26. package/build/esm/extensions/yfm/Checkbox/index.d.ts +2 -2
  27. package/build/esm/extensions/yfm/Checkbox/index.js +3 -38
  28. package/build/esm/extensions/yfm/Checkbox/nodeviews.d.ts +16 -0
  29. package/build/esm/extensions/yfm/Checkbox/nodeviews.js +52 -0
  30. package/build/esm/version.js +1 -1
  31. package/package.json +1 -1
@@ -3,5 +3,12 @@ export declare enum CheckboxNode {
3
3
  Input = "checkbox_input",
4
4
  Label = "checkbox_label"
5
5
  }
6
+ export declare const CheckboxAttr: {
7
+ readonly Class: "class";
8
+ readonly Type: "type";
9
+ readonly Id: "id";
10
+ readonly Checked: "checked";
11
+ readonly For: "for";
12
+ };
6
13
  export declare const idPrefix = "yfm-editor-checkbox";
7
14
  export declare const b: import("@bem-react/classname").ClassNameFormatter;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.b = exports.idPrefix = exports.CheckboxNode = void 0;
3
+ exports.b = exports.idPrefix = exports.CheckboxAttr = exports.CheckboxNode = void 0;
4
4
  const classname_1 = require("../../../../classname");
5
5
  var CheckboxNode;
6
6
  (function (CheckboxNode) {
@@ -8,5 +8,12 @@ var CheckboxNode;
8
8
  CheckboxNode["Input"] = "checkbox_input";
9
9
  CheckboxNode["Label"] = "checkbox_label";
10
10
  })(CheckboxNode = exports.CheckboxNode || (exports.CheckboxNode = {}));
11
+ exports.CheckboxAttr = {
12
+ Class: 'class',
13
+ Type: 'type',
14
+ Id: 'id',
15
+ Checked: 'checked',
16
+ For: 'for',
17
+ };
11
18
  exports.idPrefix = 'yfm-editor-checkbox';
12
19
  exports.b = (0, classname_1.cn)('checkbox');
@@ -1,6 +1,6 @@
1
1
  import type { NodeSpec } from 'prosemirror-model';
2
2
  import type { ExtensionAuto, ExtensionNodeSpec } from '../../../../core';
3
- export { CheckboxNode } from './const';
3
+ export { CheckboxAttr, CheckboxNode } from './const';
4
4
  export declare const checkboxType: (schema: import("prosemirror-model").Schema<any, any>) => import("prosemirror-model").NodeType;
5
5
  export declare const checkboxLabelType: (schema: import("prosemirror-model").Schema<any, any>) => import("prosemirror-model").NodeType;
6
6
  export declare const checkboxInputType: (schema: import("prosemirror-model").Schema<any, any>) => import("prosemirror-model").NodeType;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CheckboxSpecs = exports.checkboxInputType = exports.checkboxLabelType = exports.checkboxType = exports.CheckboxNode = void 0;
3
+ exports.CheckboxSpecs = exports.checkboxInputType = exports.checkboxLabelType = exports.checkboxType = exports.CheckboxNode = exports.CheckboxAttr = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const checkbox_1 = tslib_1.__importDefault(require("@diplodoc/transform/lib/plugins/checkbox"));
6
6
  const schema_1 = require("../../../../utils/schema");
@@ -9,6 +9,7 @@ const parser_1 = require("./parser");
9
9
  const schema_2 = require("./schema");
10
10
  const serializer_1 = require("./serializer");
11
11
  var const_2 = require("./const");
12
+ Object.defineProperty(exports, "CheckboxAttr", { enumerable: true, get: function () { return const_2.CheckboxAttr; } });
12
13
  Object.defineProperty(exports, "CheckboxNode", { enumerable: true, get: function () { return const_2.CheckboxNode; } });
13
14
  exports.checkboxType = (0, schema_1.nodeTypeFactory)(const_1.CheckboxNode.Checkbox);
14
15
  exports.checkboxLabelType = (0, schema_1.nodeTypeFactory)(const_1.CheckboxNode.Label);
@@ -1,5 +1,5 @@
1
1
  import type { NodeSpec } from 'prosemirror-model';
2
2
  import { PlaceholderOptions } from '../../../../utils/placeholder';
3
- import { CheckboxNode } from '../const';
3
+ import { CheckboxNode } from './const';
4
4
  import type { CheckboxSpecsOptions } from './index';
5
5
  export declare const getSchemaSpecs: (opts?: Pick<CheckboxSpecsOptions, 'checkboxLabelPlaceholder'>, placeholder?: PlaceholderOptions) => Record<CheckboxNode, NodeSpec>;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getSchemaSpecs = void 0;
4
- const const_1 = require("../const");
4
+ const const_1 = require("./const");
5
5
  const DEFAULT_LABEL_PLACEHOLDER = 'Checkbox';
6
6
  const getSchemaSpecs = (opts, placeholder) => {
7
7
  var _a, _b;
@@ -13,7 +13,7 @@ const getSchemaSpecs = (opts, placeholder) => {
13
13
  allowSelection: false,
14
14
  parseDOM: [],
15
15
  attrs: {
16
- class: { default: (0, const_1.b)() },
16
+ [const_1.CheckboxAttr.Class]: { default: (0, const_1.b)() },
17
17
  },
18
18
  toDOM(node) {
19
19
  return ['div', node.attrs, 0];
@@ -24,9 +24,9 @@ const getSchemaSpecs = (opts, placeholder) => {
24
24
  group: 'block',
25
25
  parseDOM: [],
26
26
  attrs: {
27
- type: { default: 'checkbox' },
28
- id: { default: null },
29
- checked: { default: null },
27
+ [const_1.CheckboxAttr.Type]: { default: 'checkbox' },
28
+ [const_1.CheckboxAttr.Id]: { default: null },
29
+ [const_1.CheckboxAttr.Checked]: { default: null },
30
30
  },
31
31
  toDOM(node) {
32
32
  return ['div', node.attrs];
@@ -42,12 +42,12 @@ const getSchemaSpecs = (opts, placeholder) => {
42
42
  {
43
43
  tag: `span[class="${(0, const_1.b)('label')}"]`,
44
44
  getAttrs: (node) => ({
45
- for: node.getAttribute('for') || '',
45
+ [const_1.CheckboxAttr.For]: node.getAttribute(const_1.CheckboxAttr.For) || '',
46
46
  }),
47
47
  },
48
48
  ],
49
49
  attrs: {
50
- for: { default: null },
50
+ [const_1.CheckboxAttr.For]: { default: null },
51
51
  },
52
52
  escapeText: false,
53
53
  placeholder: {
@@ -1,3 +1,3 @@
1
1
  import { SerializerNodeToken } from '../../../../core';
2
- import { CheckboxNode } from '../const';
2
+ import { CheckboxNode } from './const';
3
3
  export declare const serializerTokens: Record<CheckboxNode, SerializerNodeToken>;
@@ -2,14 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.serializerTokens = void 0;
4
4
  const placeholder_1 = require("../../../../utils/placeholder");
5
- const const_1 = require("../const");
5
+ const const_1 = require("./const");
6
6
  exports.serializerTokens = {
7
7
  [const_1.CheckboxNode.Checkbox]: (state, node) => {
8
8
  state.renderInline(node);
9
9
  state.closeBlock(node);
10
10
  },
11
11
  [const_1.CheckboxNode.Input]: (state, node) => {
12
- const checked = node.attrs.checked === 'true';
12
+ const checked = node.attrs[const_1.CheckboxAttr.Checked] === 'true';
13
13
  state.write(`[${checked ? 'X' : ' '}] `);
14
14
  },
15
15
  [const_1.CheckboxNode.Label]: (state, node, _, idx) => {
@@ -1 +1 @@
1
- export { CheckboxNode, b } from './CheckboxSpecs/const';
1
+ export { CheckboxAttr, CheckboxNode, b } from './CheckboxSpecs/const';
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.b = exports.CheckboxNode = void 0;
3
+ exports.b = exports.CheckboxNode = exports.CheckboxAttr = void 0;
4
4
  var const_1 = require("./CheckboxSpecs/const");
5
+ Object.defineProperty(exports, "CheckboxAttr", { enumerable: true, get: function () { return const_1.CheckboxAttr; } });
5
6
  Object.defineProperty(exports, "CheckboxNode", { enumerable: true, get: function () { return const_1.CheckboxNode; } });
6
7
  Object.defineProperty(exports, "b", { enumerable: true, get: function () { return const_1.b; } });
@@ -1,7 +1,7 @@
1
1
  import type { Action, ExtensionAuto } from '../../../core';
2
- import { CheckboxSpecsOptions } from './CheckboxSpecs';
2
+ import { type CheckboxSpecsOptions } from './CheckboxSpecs';
3
3
  declare const checkboxAction = "addCheckbox";
4
- export { CheckboxNode, checkboxType, checkboxLabelType, checkboxInputType } from './CheckboxSpecs';
4
+ export { CheckboxAttr, CheckboxNode, checkboxType, checkboxLabelType, checkboxInputType, } from './CheckboxSpecs';
5
5
  export declare type CheckboxOptions = Pick<CheckboxSpecsOptions, 'checkboxLabelPlaceholder'> & {};
6
6
  export declare const Checkbox: ExtensionAuto<CheckboxOptions>;
7
7
  declare global {
@@ -1,55 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Checkbox = exports.checkboxInputType = exports.checkboxLabelType = exports.checkboxType = exports.CheckboxNode = void 0;
4
- const prosemirror_utils_1 = require("prosemirror-utils");
3
+ exports.Checkbox = exports.checkboxInputType = exports.checkboxLabelType = exports.checkboxType = exports.CheckboxNode = exports.CheckboxAttr = void 0;
5
4
  const inputrules_1 = require("../../../utils/inputrules");
6
- const BaseSchema_1 = require("../../base/BaseSchema");
7
5
  const CheckboxSpecs_1 = require("./CheckboxSpecs");
8
6
  const actions_1 = require("./actions");
9
- const const_1 = require("./const");
7
+ const nodeviews_1 = require("./nodeviews");
10
8
  const plugin_1 = require("./plugin");
11
9
  const utils_1 = require("./utils");
12
10
  const checkboxAction = 'addCheckbox';
13
11
  var CheckboxSpecs_2 = require("./CheckboxSpecs");
12
+ Object.defineProperty(exports, "CheckboxAttr", { enumerable: true, get: function () { return CheckboxSpecs_2.CheckboxAttr; } });
14
13
  Object.defineProperty(exports, "CheckboxNode", { enumerable: true, get: function () { return CheckboxSpecs_2.CheckboxNode; } });
15
14
  Object.defineProperty(exports, "checkboxType", { enumerable: true, get: function () { return CheckboxSpecs_2.checkboxType; } });
16
15
  Object.defineProperty(exports, "checkboxLabelType", { enumerable: true, get: function () { return CheckboxSpecs_2.checkboxLabelType; } });
17
16
  Object.defineProperty(exports, "checkboxInputType", { enumerable: true, get: function () { return CheckboxSpecs_2.checkboxInputType; } });
18
17
  const Checkbox = (builder, opts) => {
19
- builder.use(CheckboxSpecs_1.CheckboxSpecs, Object.assign(Object.assign({}, opts), { inputView: () => (node, view, getPos) => {
20
- const dom = document.createElement('input');
21
- for (const attr in node.attrs) {
22
- if (node.attrs[attr])
23
- dom.setAttribute(attr, node.attrs[attr]);
24
- }
25
- dom.setAttribute('class', (0, const_1.b)('input'));
26
- dom.addEventListener('click', (e) => {
27
- const elem = e.target;
28
- const checkedAttr = elem.getAttribute('checked');
29
- const checked = checkedAttr ? '' : 'true';
30
- const pos = getPos();
31
- if (pos !== undefined) {
32
- view.dispatch(view.state.tr.setNodeMarkup(pos, undefined, Object.assign(Object.assign({}, node.attrs), { checked })));
33
- }
34
- elem.setAttribute('checked', checked);
35
- });
36
- return {
37
- dom,
38
- ignoreMutation: () => true,
39
- update: () => true,
40
- destroy() {
41
- const pos = getPos();
42
- if (pos !== undefined) {
43
- const resolved = view.state.doc.resolve(pos);
44
- if (resolved.parent.type.name === const_1.CheckboxNode.Checkbox &&
45
- resolved.parent.lastChild) {
46
- view.dispatch((0, prosemirror_utils_1.replaceParentNodeOfType)(resolved.parent.type, (0, BaseSchema_1.pType)(view.state.schema).create(resolved.parent.lastChild.content))(view.state.tr));
47
- }
48
- }
49
- dom.remove();
50
- },
51
- };
52
- } }));
18
+ builder.use(CheckboxSpecs_1.CheckboxSpecs, Object.assign(Object.assign({}, opts), { inputView: () => nodeviews_1.CheckboxInputView.create }));
53
19
  builder
54
20
  .addPlugin(plugin_1.keymapPlugin, builder.Priority.High)
55
21
  .addAction(checkboxAction, () => (0, actions_1.addCheckbox)())
@@ -0,0 +1,16 @@
1
+ import type { Node } from 'prosemirror-model';
2
+ import type { NodeView, NodeViewConstructor } from 'prosemirror-view';
3
+ export declare class CheckboxInputView implements NodeView {
4
+ static create: NodeViewConstructor;
5
+ dom: HTMLInputElement;
6
+ private _node;
7
+ private _view;
8
+ private _getPos;
9
+ private constructor();
10
+ ignoreMutation(): boolean;
11
+ update(node: Node): boolean;
12
+ destroy(): void;
13
+ private _createDomElem;
14
+ private _applyNodeAttrsToDomElem;
15
+ private _onInputClick;
16
+ }
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.CheckboxInputView = void 0;
5
+ const const_1 = require("./const");
6
+ class CheckboxInputView {
7
+ constructor(node, view, getPos) {
8
+ this._onInputClick = (event) => {
9
+ if (event.target instanceof HTMLInputElement) {
10
+ const { checked } = event.target;
11
+ const pos = this._getPos();
12
+ if (pos !== undefined)
13
+ this._view.dispatch(this._view.state.tr.setNodeAttribute(pos, const_1.CheckboxAttr.Checked, checked ? 'true' : null));
14
+ }
15
+ this._view.focus();
16
+ };
17
+ this._node = node;
18
+ this._view = view;
19
+ this._getPos = getPos;
20
+ this.dom = this._createDomElem();
21
+ this._applyNodeAttrsToDomElem();
22
+ }
23
+ ignoreMutation() {
24
+ return true;
25
+ }
26
+ update(node) {
27
+ if (node.type !== this._node.type)
28
+ return false;
29
+ this._node = node;
30
+ this._applyNodeAttrsToDomElem();
31
+ return true;
32
+ }
33
+ destroy() {
34
+ this.dom.removeEventListener('click', this._onInputClick);
35
+ }
36
+ _createDomElem() {
37
+ const dom = document.createElement('input');
38
+ dom.setAttribute('class', (0, const_1.b)('input'));
39
+ dom.addEventListener('click', this._onInputClick);
40
+ return dom;
41
+ }
42
+ _applyNodeAttrsToDomElem() {
43
+ const { dom, _node: node } = this;
44
+ for (const [key, value] of Object.entries(node.attrs)) {
45
+ if (value)
46
+ dom.setAttribute(key, value);
47
+ else
48
+ dom.removeAttribute(key);
49
+ }
50
+ const checked = node.attrs[const_1.CheckboxAttr.Checked] === 'true';
51
+ this.dom.checked = checked;
52
+ }
53
+ }
54
+ exports.CheckboxInputView = CheckboxInputView;
55
+ _a = CheckboxInputView;
56
+ CheckboxInputView.create = (node, view, getPos) => new _a(node, view, getPos);
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
4
  /** During build process, the current version will be injected here */
5
- exports.VERSION = typeof '14.5.0' !== 'undefined' ? '14.5.0' : 'unknown';
5
+ exports.VERSION = typeof '14.5.1' !== 'undefined' ? '14.5.1' : 'unknown';
@@ -3,5 +3,12 @@ export declare enum CheckboxNode {
3
3
  Input = "checkbox_input",
4
4
  Label = "checkbox_label"
5
5
  }
6
+ export declare const CheckboxAttr: {
7
+ readonly Class: "class";
8
+ readonly Type: "type";
9
+ readonly Id: "id";
10
+ readonly Checked: "checked";
11
+ readonly For: "for";
12
+ };
6
13
  export declare const idPrefix = "yfm-editor-checkbox";
7
14
  export declare const b: import("@bem-react/classname").ClassNameFormatter;
@@ -5,5 +5,12 @@ export var CheckboxNode;
5
5
  CheckboxNode["Input"] = "checkbox_input";
6
6
  CheckboxNode["Label"] = "checkbox_label";
7
7
  })(CheckboxNode || (CheckboxNode = {}));
8
+ export const CheckboxAttr = {
9
+ Class: 'class',
10
+ Type: 'type',
11
+ Id: 'id',
12
+ Checked: 'checked',
13
+ For: 'for',
14
+ };
8
15
  export const idPrefix = 'yfm-editor-checkbox';
9
16
  export const b = cn('checkbox');
@@ -1,6 +1,6 @@
1
1
  import type { NodeSpec } from 'prosemirror-model';
2
2
  import type { ExtensionAuto, ExtensionNodeSpec } from '../../../../core';
3
- export { CheckboxNode } from './const';
3
+ export { CheckboxAttr, CheckboxNode } from './const';
4
4
  export declare const checkboxType: (schema: import("prosemirror-model").Schema<any, any>) => import("prosemirror-model").NodeType;
5
5
  export declare const checkboxLabelType: (schema: import("prosemirror-model").Schema<any, any>) => import("prosemirror-model").NodeType;
6
6
  export declare const checkboxInputType: (schema: import("prosemirror-model").Schema<any, any>) => import("prosemirror-model").NodeType;
@@ -4,7 +4,7 @@ import { CheckboxNode, b, idPrefix } from './const';
4
4
  import { parserTokens } from './parser';
5
5
  import { getSchemaSpecs } from './schema';
6
6
  import { serializerTokens } from './serializer';
7
- export { CheckboxNode } from './const';
7
+ export { CheckboxAttr, CheckboxNode } from './const';
8
8
  export const checkboxType = nodeTypeFactory(CheckboxNode.Checkbox);
9
9
  export const checkboxLabelType = nodeTypeFactory(CheckboxNode.Label);
10
10
  export const checkboxInputType = nodeTypeFactory(CheckboxNode.Input);
@@ -1,5 +1,5 @@
1
1
  import type { NodeSpec } from 'prosemirror-model';
2
2
  import { PlaceholderOptions } from '../../../../utils/placeholder';
3
- import { CheckboxNode } from '../const';
3
+ import { CheckboxNode } from './const';
4
4
  import type { CheckboxSpecsOptions } from './index';
5
5
  export declare const getSchemaSpecs: (opts?: Pick<CheckboxSpecsOptions, 'checkboxLabelPlaceholder'>, placeholder?: PlaceholderOptions) => Record<CheckboxNode, NodeSpec>;
@@ -1,4 +1,4 @@
1
- import { CheckboxNode, b } from '../const';
1
+ import { CheckboxAttr, CheckboxNode, b } from './const';
2
2
  const DEFAULT_LABEL_PLACEHOLDER = 'Checkbox';
3
3
  export const getSchemaSpecs = (opts, placeholder) => {
4
4
  var _a, _b;
@@ -10,7 +10,7 @@ export const getSchemaSpecs = (opts, placeholder) => {
10
10
  allowSelection: false,
11
11
  parseDOM: [],
12
12
  attrs: {
13
- class: { default: b() },
13
+ [CheckboxAttr.Class]: { default: b() },
14
14
  },
15
15
  toDOM(node) {
16
16
  return ['div', node.attrs, 0];
@@ -21,9 +21,9 @@ export const getSchemaSpecs = (opts, placeholder) => {
21
21
  group: 'block',
22
22
  parseDOM: [],
23
23
  attrs: {
24
- type: { default: 'checkbox' },
25
- id: { default: null },
26
- checked: { default: null },
24
+ [CheckboxAttr.Type]: { default: 'checkbox' },
25
+ [CheckboxAttr.Id]: { default: null },
26
+ [CheckboxAttr.Checked]: { default: null },
27
27
  },
28
28
  toDOM(node) {
29
29
  return ['div', node.attrs];
@@ -39,12 +39,12 @@ export const getSchemaSpecs = (opts, placeholder) => {
39
39
  {
40
40
  tag: `span[class="${b('label')}"]`,
41
41
  getAttrs: (node) => ({
42
- for: node.getAttribute('for') || '',
42
+ [CheckboxAttr.For]: node.getAttribute(CheckboxAttr.For) || '',
43
43
  }),
44
44
  },
45
45
  ],
46
46
  attrs: {
47
- for: { default: null },
47
+ [CheckboxAttr.For]: { default: null },
48
48
  },
49
49
  escapeText: false,
50
50
  placeholder: {
@@ -1,3 +1,3 @@
1
1
  import { SerializerNodeToken } from '../../../../core';
2
- import { CheckboxNode } from '../const';
2
+ import { CheckboxNode } from './const';
3
3
  export declare const serializerTokens: Record<CheckboxNode, SerializerNodeToken>;
@@ -1,12 +1,12 @@
1
1
  import { getPlaceholderContent } from '../../../../utils/placeholder';
2
- import { CheckboxNode } from '../const';
2
+ import { CheckboxAttr, CheckboxNode } from './const';
3
3
  export const serializerTokens = {
4
4
  [CheckboxNode.Checkbox]: (state, node) => {
5
5
  state.renderInline(node);
6
6
  state.closeBlock(node);
7
7
  },
8
8
  [CheckboxNode.Input]: (state, node) => {
9
- const checked = node.attrs.checked === 'true';
9
+ const checked = node.attrs[CheckboxAttr.Checked] === 'true';
10
10
  state.write(`[${checked ? 'X' : ' '}] `);
11
11
  },
12
12
  [CheckboxNode.Label]: (state, node, _, idx) => {
@@ -1 +1 @@
1
- export { CheckboxNode, b } from './CheckboxSpecs/const';
1
+ export { CheckboxAttr, CheckboxNode, b } from './CheckboxSpecs/const';
@@ -1 +1 @@
1
- export { CheckboxNode, b } from './CheckboxSpecs/const';
1
+ export { CheckboxAttr, CheckboxNode, b } from './CheckboxSpecs/const';
@@ -1,8 +1,8 @@
1
1
  import type { Action, ExtensionAuto } from '../../../core';
2
- import { CheckboxSpecsOptions } from './CheckboxSpecs';
2
+ import { type CheckboxSpecsOptions } from './CheckboxSpecs';
3
3
  import './index.css';
4
4
  declare const checkboxAction = "addCheckbox";
5
- export { CheckboxNode, checkboxType, checkboxLabelType, checkboxInputType } from './CheckboxSpecs';
5
+ export { CheckboxAttr, CheckboxNode, checkboxType, checkboxLabelType, checkboxInputType, } from './CheckboxSpecs';
6
6
  export declare type CheckboxOptions = Pick<CheckboxSpecsOptions, 'checkboxLabelPlaceholder'> & {};
7
7
  export declare const Checkbox: ExtensionAuto<CheckboxOptions>;
8
8
  declare global {
@@ -1,49 +1,14 @@
1
- import { replaceParentNodeOfType } from 'prosemirror-utils';
2
1
  import { nodeInputRule } from '../../../utils/inputrules';
3
- import { pType } from '../../base/BaseSchema';
4
2
  import { CheckboxSpecs } from './CheckboxSpecs';
5
3
  import { addCheckbox } from './actions';
6
- import { CheckboxNode, b } from './const';
4
+ import { CheckboxInputView } from './nodeviews';
7
5
  import { keymapPlugin } from './plugin';
8
6
  import { checkboxInputType, checkboxType } from './utils';
9
7
  import './index.css';
10
8
  const checkboxAction = 'addCheckbox';
11
- export { CheckboxNode, checkboxType, checkboxLabelType, checkboxInputType } from './CheckboxSpecs';
9
+ export { CheckboxAttr, CheckboxNode, checkboxType, checkboxLabelType, checkboxInputType, } from './CheckboxSpecs';
12
10
  export const Checkbox = (builder, opts) => {
13
- builder.use(CheckboxSpecs, Object.assign(Object.assign({}, opts), { inputView: () => (node, view, getPos) => {
14
- const dom = document.createElement('input');
15
- for (const attr in node.attrs) {
16
- if (node.attrs[attr])
17
- dom.setAttribute(attr, node.attrs[attr]);
18
- }
19
- dom.setAttribute('class', b('input'));
20
- dom.addEventListener('click', (e) => {
21
- const elem = e.target;
22
- const checkedAttr = elem.getAttribute('checked');
23
- const checked = checkedAttr ? '' : 'true';
24
- const pos = getPos();
25
- if (pos !== undefined) {
26
- view.dispatch(view.state.tr.setNodeMarkup(pos, undefined, Object.assign(Object.assign({}, node.attrs), { checked })));
27
- }
28
- elem.setAttribute('checked', checked);
29
- });
30
- return {
31
- dom,
32
- ignoreMutation: () => true,
33
- update: () => true,
34
- destroy() {
35
- const pos = getPos();
36
- if (pos !== undefined) {
37
- const resolved = view.state.doc.resolve(pos);
38
- if (resolved.parent.type.name === CheckboxNode.Checkbox &&
39
- resolved.parent.lastChild) {
40
- view.dispatch(replaceParentNodeOfType(resolved.parent.type, pType(view.state.schema).create(resolved.parent.lastChild.content))(view.state.tr));
41
- }
42
- }
43
- dom.remove();
44
- },
45
- };
46
- } }));
11
+ builder.use(CheckboxSpecs, Object.assign(Object.assign({}, opts), { inputView: () => CheckboxInputView.create }));
47
12
  builder
48
13
  .addPlugin(keymapPlugin, builder.Priority.High)
49
14
  .addAction(checkboxAction, () => addCheckbox())
@@ -0,0 +1,16 @@
1
+ import type { Node } from 'prosemirror-model';
2
+ import type { NodeView, NodeViewConstructor } from 'prosemirror-view';
3
+ export declare class CheckboxInputView implements NodeView {
4
+ static create: NodeViewConstructor;
5
+ dom: HTMLInputElement;
6
+ private _node;
7
+ private _view;
8
+ private _getPos;
9
+ private constructor();
10
+ ignoreMutation(): boolean;
11
+ update(node: Node): boolean;
12
+ destroy(): void;
13
+ private _createDomElem;
14
+ private _applyNodeAttrsToDomElem;
15
+ private _onInputClick;
16
+ }
@@ -0,0 +1,52 @@
1
+ var _a;
2
+ import { CheckboxAttr, b } from './const';
3
+ export class CheckboxInputView {
4
+ constructor(node, view, getPos) {
5
+ this._onInputClick = (event) => {
6
+ if (event.target instanceof HTMLInputElement) {
7
+ const { checked } = event.target;
8
+ const pos = this._getPos();
9
+ if (pos !== undefined)
10
+ this._view.dispatch(this._view.state.tr.setNodeAttribute(pos, CheckboxAttr.Checked, checked ? 'true' : null));
11
+ }
12
+ this._view.focus();
13
+ };
14
+ this._node = node;
15
+ this._view = view;
16
+ this._getPos = getPos;
17
+ this.dom = this._createDomElem();
18
+ this._applyNodeAttrsToDomElem();
19
+ }
20
+ ignoreMutation() {
21
+ return true;
22
+ }
23
+ update(node) {
24
+ if (node.type !== this._node.type)
25
+ return false;
26
+ this._node = node;
27
+ this._applyNodeAttrsToDomElem();
28
+ return true;
29
+ }
30
+ destroy() {
31
+ this.dom.removeEventListener('click', this._onInputClick);
32
+ }
33
+ _createDomElem() {
34
+ const dom = document.createElement('input');
35
+ dom.setAttribute('class', b('input'));
36
+ dom.addEventListener('click', this._onInputClick);
37
+ return dom;
38
+ }
39
+ _applyNodeAttrsToDomElem() {
40
+ const { dom, _node: node } = this;
41
+ for (const [key, value] of Object.entries(node.attrs)) {
42
+ if (value)
43
+ dom.setAttribute(key, value);
44
+ else
45
+ dom.removeAttribute(key);
46
+ }
47
+ const checked = node.attrs[CheckboxAttr.Checked] === 'true';
48
+ this.dom.checked = checked;
49
+ }
50
+ }
51
+ _a = CheckboxInputView;
52
+ CheckboxInputView.create = (node, view, getPos) => new _a(node, view, getPos);
@@ -1,2 +1,2 @@
1
1
  /** During build process, the current version will be injected here */
2
- export const VERSION = typeof '14.5.0' !== 'undefined' ? '14.5.0' : 'unknown';
2
+ export const VERSION = typeof '14.5.1' !== 'undefined' ? '14.5.1' : 'unknown';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/markdown-editor",
3
- "version": "14.5.0",
3
+ "version": "14.5.1",
4
4
  "description": "Markdown wysiwyg and markup editor",
5
5
  "license": "MIT",
6
6
  "repository": {