studiokit-scaffolding-js 4.5.2-next.3.3 → 4.5.2-next.3.4

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.
@@ -1,4 +1,9 @@
1
+ import { Blot } from 'parchment/dist/src/blot/abstract/blot';
2
+ import { BlotConstructor } from 'parchment/dist/src/registry';
1
3
  declare const Container: typeof import("parchment/dist/src/blot/abstract/container").default;
4
+ export interface BaseTableBlotConstructor extends BlotConstructor {
5
+ dataValue(): string;
6
+ }
2
7
  /**
3
8
  * A base class for all Table module blots to inherit.
4
9
  *
@@ -7,13 +12,16 @@ declare const Container: typeof import("parchment/dist/src/blot/abstract/contain
7
12
  */
8
13
  export declare class BaseTableBlot extends Container {
9
14
  static scope: import("parchment/dist/src/registry").Scope;
10
- static requiredParent: string | null;
11
- static allowedChildren: (typeof import("parchment/dist/src/blot/embed").default | typeof import("parchment/dist/src/blot/abstract/container").default)[];
15
+ static requiredParentName: string | null;
16
+ /** alternate to `allowedChildren`, to avoid circular class refs */
17
+ static allowedChildrenNames: string[];
18
+ static create(value: string): Node;
12
19
  static createWithValue(tagName: string, value: string): HTMLElement;
13
20
  /**
14
21
  * Check if the blot only contains `<p><br></p>`
15
22
  */
16
23
  static containsOnlyEmptyBlock(blot: BaseTableBlot): boolean | null;
24
+ insertBefore(childBlot: Blot, refBlot?: Blot): void;
17
25
  optimize(_context: {
18
26
  [key: string]: any;
19
27
  }): void;
@@ -20,8 +20,6 @@ var constants_1 = require("../constants");
20
20
  var utils_1 = require("../utils");
21
21
  var Parchment = react_quill_1.Quill.import('parchment');
22
22
  var Container = react_quill_1.Quill.import('blots/container');
23
- var Block = react_quill_1.Quill.import('blots/block');
24
- var BlockEmbed = react_quill_1.Quill.import('blots/block/embed');
25
23
  /**
26
24
  * A base class for all Table module blots to inherit.
27
25
  *
@@ -33,6 +31,9 @@ var BaseTableBlot = /** @class */ (function (_super) {
33
31
  function BaseTableBlot() {
34
32
  return _super !== null && _super.apply(this, arguments) || this;
35
33
  }
34
+ BaseTableBlot.create = function (value) {
35
+ return _super.create.call(this, value);
36
+ };
36
37
  BaseTableBlot.createWithValue = function (tagName, value) {
37
38
  var node = _super.create.call(this, tagName);
38
39
  node.setAttribute(constants_1.ATTRIBUTE.DATA_VALUE, value);
@@ -50,6 +51,16 @@ var BaseTableBlot = /** @class */ (function (_super) {
50
51
  blot.children.head.length() === 1 &&
51
52
  ((_a = blot.children.head.children.head) === null || _a === void 0 ? void 0 : _a.domNode).tagName === constants_1.TAG_NAME.BR);
52
53
  };
54
+ BaseTableBlot.prototype.insertBefore = function (childBlot, refBlot) {
55
+ // override super.insertBefore to change `allowedChildren` to use blotName strings, instead of class constructors
56
+ if (this.statics.allowedChildrenNames != null &&
57
+ !this.statics.allowedChildrenNames.some(function (allowedBlotName) {
58
+ return childBlot.statics.blotName === allowedBlotName;
59
+ })) {
60
+ throw new Error("Cannot insert " + childBlot.statics.blotName + " into " + this.statics.blotName);
61
+ }
62
+ childBlot.insertInto(this, refBlot);
63
+ };
53
64
  BaseTableBlot.prototype.optimize = function (_context) {
54
65
  // @ts-ignore: copied from Parchment.ShadowBlot
55
66
  if (this.domNode['__blot'] != null) {
@@ -90,15 +101,15 @@ var BaseTableBlot = /** @class */ (function (_super) {
90
101
  };
91
102
  BaseTableBlot.prototype.optimizeWrapInRequiredParent = function (value) {
92
103
  if (this.parent &&
93
- this.statics.requiredParent !== null &&
94
- !utils_1.isInstanceOfBlot(this.parent, this.statics.requiredParent)) {
95
- logger_1.getLogger().debug(this.statics.tagName + " optimize: parent not " + this.statics.requiredParent + ". wrap in new " + this.statics.requiredParent + ".", {
104
+ this.statics.requiredParentName !== null &&
105
+ !utils_1.isInstanceOfBlot(this.parent, this.statics.requiredParentName)) {
106
+ logger_1.getLogger().debug(this.statics.tagName + " optimize: parent not " + this.statics.requiredParentName + ". wrap in new " + this.statics.requiredParentName + ".", {
96
107
  this: this,
97
108
  parent: this.parent,
98
109
  prev: this.prev,
99
110
  next: this.next
100
111
  });
101
- var newParent = Parchment.create(this.statics.requiredParent, value);
112
+ var newParent = Parchment.create(this.statics.requiredParentName, value);
102
113
  this.parent.removeChild(this);
103
114
  this.parent.insertBefore(newParent, this.next);
104
115
  newParent.appendChild(this);
@@ -110,8 +121,9 @@ var BaseTableBlot = /** @class */ (function (_super) {
110
121
  return this.domNode.getAttribute(constants_1.ATTRIBUTE.DATA_VALUE);
111
122
  };
112
123
  BaseTableBlot.scope = Parchment.Scope.BLOCK_BLOT;
113
- BaseTableBlot.requiredParent = null;
114
- BaseTableBlot.allowedChildren = [Block, BlockEmbed, Container];
124
+ BaseTableBlot.requiredParentName = null;
125
+ /** alternate to `allowedChildren`, to avoid circular class refs */
126
+ BaseTableBlot.allowedChildrenNames = [];
115
127
  return BaseTableBlot;
116
128
  }(Container));
117
129
  exports.BaseTableBlot = BaseTableBlot;
@@ -1,12 +1,13 @@
1
1
  import { TABLE_BLOT_NAME, TAG_NAME } from '../constants';
2
2
  import { BaseTableBlot } from './BaseTableBlot';
3
3
  import { TableBodyBlot } from './TableBodyBlot';
4
+ import { TableContainerBlot } from './TableContainer';
4
5
  export declare class TableBlot extends BaseTableBlot {
5
6
  static blotName: TABLE_BLOT_NAME;
6
7
  static tagName: TAG_NAME;
7
8
  static scope: import("parchment/dist/src/registry").Scope;
8
- static requiredParent: string | null;
9
- static allowedChildren: (typeof TableBodyBlot)[];
9
+ static requiredParentName: string | null;
10
+ static allowedChildrenNames: string[];
10
11
  static create(value: string): HTMLTableElement;
11
12
  static createWithChildren(id: string, rows: number, cols: number): TableBlot;
12
13
  optimize(context: {
@@ -14,6 +15,6 @@ export declare class TableBlot extends BaseTableBlot {
14
15
  }): void;
15
16
  unwrap(): void;
16
17
  id(): string;
17
- tableContainer(): import("parchment/dist/src/blot/abstract/blot").Parent | undefined;
18
+ tableContainer(): TableContainerBlot | undefined;
18
19
  tableBody(): TableBodyBlot;
19
20
  }
@@ -16,9 +16,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
16
16
  exports.TableBlot = void 0;
17
17
  var react_quill_1 = require("react-quill");
18
18
  var constants_1 = require("../constants");
19
- var utils_1 = require("../utils");
20
19
  var BaseTableBlot_1 = require("./BaseTableBlot");
21
20
  var TableBodyBlot_1 = require("./TableBodyBlot");
21
+ var TableContainer_1 = require("./TableContainer");
22
22
  var Parchment = react_quill_1.Quill.import('parchment');
23
23
  var TableBlot = /** @class */ (function (_super) {
24
24
  __extends(TableBlot, _super);
@@ -54,8 +54,7 @@ var TableBlot = /** @class */ (function (_super) {
54
54
  return this.domNode.getAttribute(constants_1.ATTRIBUTE.ID);
55
55
  };
56
56
  TableBlot.prototype.tableContainer = function () {
57
- // avoid a circular import issue by not casting parent to `TableContainerBlot`
58
- return utils_1.isInstanceOfBlot(this.parent, constants_1.TABLE_BLOT_NAME.TABLE_CONTAINER) ? this.parent : undefined;
57
+ return this.parent instanceof TableContainer_1.TableContainerBlot ? this.parent : undefined;
59
58
  };
60
59
  TableBlot.prototype.tableBody = function () {
61
60
  return this.children.head;
@@ -63,8 +62,8 @@ var TableBlot = /** @class */ (function (_super) {
63
62
  TableBlot.blotName = constants_1.TABLE_BLOT_NAME.TABLE;
64
63
  TableBlot.tagName = constants_1.TAG_NAME.TABLE;
65
64
  TableBlot.scope = Parchment.Scope.BLOCK_BLOT;
66
- TableBlot.requiredParent = constants_1.TABLE_BLOT_NAME.TABLE_CONTAINER;
67
- TableBlot.allowedChildren = [TableBodyBlot_1.TableBodyBlot];
65
+ TableBlot.requiredParentName = constants_1.TABLE_BLOT_NAME.TABLE_CONTAINER;
66
+ TableBlot.allowedChildrenNames = [constants_1.TABLE_BLOT_NAME.TBODY];
68
67
  return TableBlot;
69
68
  }(BaseTableBlot_1.BaseTableBlot));
70
69
  exports.TableBlot = TableBlot;
@@ -1,13 +1,12 @@
1
1
  import { TABLE_BLOT_NAME, TAG_NAME } from '../constants';
2
2
  import { BaseTableBlot } from './BaseTableBlot';
3
3
  import { TableBlot } from './TableBlot';
4
- import { TableRowBlot } from './TableRowBlot';
5
4
  export declare class TableBodyBlot extends BaseTableBlot {
6
5
  static blotName: TABLE_BLOT_NAME;
7
6
  static tagName: TAG_NAME;
8
7
  static scope: import("parchment/dist/src/registry").Scope;
9
- static requiredParent: string | null;
10
- static allowedChildren: (typeof TableRowBlot)[];
8
+ static requiredParentName: string | null;
9
+ static allowedChildrenNames: string[];
11
10
  static create(value: string): HTMLElement;
12
11
  static createWithChildren(id: string, rows: number, cols: number): TableBodyBlot;
13
12
  optimize(context: {
@@ -64,8 +64,8 @@ var TableBodyBlot = /** @class */ (function (_super) {
64
64
  TableBodyBlot.blotName = constants_1.TABLE_BLOT_NAME.TBODY;
65
65
  TableBodyBlot.tagName = constants_1.TAG_NAME.TBODY;
66
66
  TableBodyBlot.scope = Parchment.Scope.BLOCK_BLOT;
67
- TableBodyBlot.requiredParent = constants_1.TABLE_BLOT_NAME.TABLE;
68
- TableBodyBlot.allowedChildren = [TableRowBlot_1.TableRowBlot];
67
+ TableBodyBlot.requiredParentName = constants_1.TABLE_BLOT_NAME.TABLE;
68
+ TableBodyBlot.allowedChildrenNames = [constants_1.TABLE_BLOT_NAME.TR];
69
69
  return TableBodyBlot;
70
70
  }(BaseTableBlot_1.BaseTableBlot));
71
71
  exports.TableBodyBlot = TableBodyBlot;
@@ -7,8 +7,9 @@ export declare class TableCellBlot extends BaseTableBlot {
7
7
  static blotName: TABLE_BLOT_NAME;
8
8
  static tagName: TAG_NAME;
9
9
  static scope: import("parchment/dist/src/registry").Scope;
10
- static requiredParent: string | null;
11
- static defaultChild: string;
10
+ static requiredParentName: string | null;
11
+ static defaultChildName: string;
12
+ /** use normal `allowedChildren` instead of `allowedChildrenNames` */
12
13
  static allowedChildren: (typeof import("parchment/dist/src/blot/embed").default | typeof import("parchment/dist/src/blot/abstract/container").default)[];
13
14
  static create(value: string): HTMLElement;
14
15
  static createWithChildren(tableId: string, rowId: string): TableCellBlot;
@@ -80,8 +80,8 @@ var TableCellBlot = /** @class */ (function (_super) {
80
80
  lastChild.optimize({});
81
81
  lastChild = this.children.tail;
82
82
  }
83
- if (this.parent && !utils_1.isInstanceOfBlot(this.parent, this.statics.requiredParent)) {
84
- logger_1.getLogger().debug(this.statics.tagName + " optimize: parent is not " + this.statics.requiredParent, {
83
+ if (this.parent && !utils_1.isInstanceOfBlot(this.parent, this.statics.requiredParentName)) {
84
+ logger_1.getLogger().debug(this.statics.tagName + " optimize: parent is not " + this.statics.requiredParentName, {
85
85
  this: this,
86
86
  context: context,
87
87
  parent: this.parent,
@@ -98,7 +98,7 @@ var TableCellBlot = /** @class */ (function (_super) {
98
98
  this.parent.optimize(context);
99
99
  }
100
100
  else {
101
- var newRow = Parchment.create(this.statics.requiredParent, this.tableId() + "|" + this.rowId());
101
+ var newRow = Parchment.create(this.statics.requiredParentName, this.tableId() + "|" + this.rowId());
102
102
  logger_1.getLogger().debug(this.statics.tagName + " optimize: wrap in new TR.", {
103
103
  this: this,
104
104
  newRow: newRow,
@@ -111,6 +111,7 @@ var TableCellBlot = /** @class */ (function (_super) {
111
111
  }
112
112
  };
113
113
  TableCellBlot.prototype.insertBefore = function (child, refNode) {
114
+ // does not inherit from super, uses allowedChildren instead of allowedChildrenNames
114
115
  logger_1.getLogger().debug(this.statics.tagName + " insertBefore: " + child.statics.tagName, {
115
116
  this: this,
116
117
  child: child,
@@ -128,14 +129,14 @@ var TableCellBlot = /** @class */ (function (_super) {
128
129
  ref: refNode
129
130
  });
130
131
  newChild.appendChild(child);
131
- _super.prototype.insertBefore.call(this, newChild, refNode);
132
+ newChild.insertInto(this, refNode);
132
133
  }
133
134
  else {
134
- _super.prototype.insertBefore.call(this, child, refNode);
135
+ child.insertInto(this, refNode);
135
136
  }
136
137
  };
137
138
  TableCellBlot.prototype.createDefaultChild = function () {
138
- return Parchment.create(this.statics.defaultChild);
139
+ return Parchment.create(this.statics.defaultChildName);
139
140
  };
140
141
  TableCellBlot.prototype.replace = function (target) {
141
142
  logger_1.getLogger().debug(this.statics.tagName + " replace: " + target.statics.tagName, {
@@ -226,8 +227,9 @@ var TableCellBlot = /** @class */ (function (_super) {
226
227
  TableCellBlot.blotName = constants_1.TABLE_BLOT_NAME.TD;
227
228
  TableCellBlot.tagName = constants_1.TAG_NAME.TD;
228
229
  TableCellBlot.scope = Parchment.Scope.BLOCK_BLOT;
229
- TableCellBlot.requiredParent = constants_1.TABLE_BLOT_NAME.TR;
230
- TableCellBlot.defaultChild = Block.blotName;
230
+ TableCellBlot.requiredParentName = constants_1.TABLE_BLOT_NAME.TR;
231
+ TableCellBlot.defaultChildName = Block.blotName;
232
+ /** use normal `allowedChildren` instead of `allowedChildrenNames` */
231
233
  TableCellBlot.allowedChildren = [Block, BlockEmbed, Container];
232
234
  return TableCellBlot;
233
235
  }(BaseTableBlot_1.BaseTableBlot));
@@ -1,4 +1,3 @@
1
- import { Blot } from 'parchment/dist/src/blot/abstract/blot';
2
1
  import { TABLE_BLOT_NAME, TAG_NAME } from '../constants';
3
2
  import { BaseTableBlot } from './BaseTableBlot';
4
3
  import { TableBlot } from './TableBlot';
@@ -6,10 +5,9 @@ export declare class TableContainerBlot extends BaseTableBlot {
6
5
  static blotName: TABLE_BLOT_NAME;
7
6
  static tagName: TAG_NAME;
8
7
  static scope: import("parchment/dist/src/registry").Scope;
9
- static allowedChildren: (typeof TableBlot)[];
8
+ static allowedChildrenNames: string[];
10
9
  static create(value: string): HTMLDivElement;
11
10
  static createWithChildren(rows: number, cols: number): TableContainerBlot;
12
- insertBefore(childBlot: Blot, refBlot?: Blot): void;
13
11
  optimize(context: {
14
12
  [key: string]: any;
15
13
  }): void;
@@ -42,10 +42,6 @@ var TableContainerBlot = /** @class */ (function (_super) {
42
42
  tableContainer.appendChild(table);
43
43
  return tableContainer;
44
44
  };
45
- TableContainerBlot.prototype.insertBefore = function (childBlot, refBlot) {
46
- logger_1.getLogger().debug('insertBefore', { childBlot: childBlot, refBlot: refBlot });
47
- _super.prototype.insertBefore.call(this, childBlot, refBlot);
48
- };
49
45
  TableContainerBlot.prototype.optimize = function (context) {
50
46
  _super.prototype.optimize.call(this, context);
51
47
  var didRemove = this.optimizeRemoveIfEmpty();
@@ -101,7 +97,7 @@ var TableContainerBlot = /** @class */ (function (_super) {
101
97
  TableContainerBlot.blotName = constants_1.TABLE_BLOT_NAME.TABLE_CONTAINER;
102
98
  TableContainerBlot.tagName = constants_1.TAG_NAME.DIV;
103
99
  TableContainerBlot.scope = Parchment.Scope.BLOCK_BLOT;
104
- TableContainerBlot.allowedChildren = [TableBlot_1.TableBlot];
100
+ TableContainerBlot.allowedChildrenNames = [constants_1.TABLE_BLOT_NAME.TABLE];
105
101
  return TableContainerBlot;
106
102
  }(BaseTableBlot_1.BaseTableBlot));
107
103
  exports.TableContainerBlot = TableContainerBlot;
@@ -1,13 +1,12 @@
1
1
  import { TABLE_BLOT_NAME, TAG_NAME } from '../constants';
2
2
  import { BaseTableBlot } from './BaseTableBlot';
3
3
  import { TableBodyBlot } from './TableBodyBlot';
4
- import { TableCellBlot } from './TableCellBlot';
5
4
  export declare class TableRowBlot extends BaseTableBlot {
6
5
  static blotName: TABLE_BLOT_NAME;
7
6
  static tagName: TAG_NAME;
8
7
  static scope: import("parchment/dist/src/registry").Scope;
9
- static requiredParent: string | null;
10
- static allowedChildren: (typeof TableCellBlot)[];
8
+ static requiredParentName: string | null;
9
+ static allowedChildrenNames: string[];
11
10
  static create(value: string): HTMLElement;
12
11
  static createWithChildren(tableId: string, cols: number): TableRowBlot;
13
12
  static createFromReference(reference: TableRowBlot): TableRowBlot;
@@ -84,8 +84,8 @@ var TableRowBlot = /** @class */ (function (_super) {
84
84
  TableRowBlot.blotName = constants_1.TABLE_BLOT_NAME.TR;
85
85
  TableRowBlot.tagName = constants_1.TAG_NAME.TR;
86
86
  TableRowBlot.scope = Parchment.Scope.BLOCK_BLOT;
87
- TableRowBlot.requiredParent = constants_1.TABLE_BLOT_NAME.TBODY;
88
- TableRowBlot.allowedChildren = [TableCellBlot_1.TableCellBlot];
87
+ TableRowBlot.requiredParentName = constants_1.TABLE_BLOT_NAME.TBODY;
88
+ TableRowBlot.allowedChildrenNames = [constants_1.TABLE_BLOT_NAME.TD];
89
89
  return TableRowBlot;
90
90
  }(BaseTableBlot_1.BaseTableBlot));
91
91
  exports.TableRowBlot = TableRowBlot;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "studiokit-scaffolding-js",
3
- "version": "4.5.2-next.3.3",
3
+ "version": "4.5.2-next.3.4",
4
4
  "description": "Common scaffolding for Studio apps at Purdue",
5
5
  "repository": "https://gitlab.com/purdue-informatics/studiokit/studiokit-scaffolding-js",
6
6
  "license": "MIT",