@pie-lib/editable-html 9.3.1-next.39 → 9.3.1-next.53
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/lib/editor.js +114 -244
- package/lib/editor.js.map +1 -1
- package/lib/index.js +5 -51
- package/lib/index.js.map +1 -1
- package/lib/parse-html.js +6 -5
- package/lib/parse-html.js.map +1 -1
- package/lib/plugins/characters/custom-popper.js +2 -12
- package/lib/plugins/characters/custom-popper.js.map +1 -1
- package/lib/plugins/characters/index.js +3 -50
- package/lib/plugins/characters/index.js.map +1 -1
- package/lib/plugins/characters/utils.js.map +1 -1
- package/lib/plugins/image/alt-dialog.js +0 -26
- package/lib/plugins/image/alt-dialog.js.map +1 -1
- package/lib/plugins/image/component.js +29 -82
- package/lib/plugins/image/component.js.map +1 -1
- package/lib/plugins/image/image-toolbar.js +7 -45
- package/lib/plugins/image/image-toolbar.js.map +1 -1
- package/lib/plugins/image/index.js +2 -41
- package/lib/plugins/image/index.js.map +1 -1
- package/lib/plugins/image/insert-image-handler.js +2 -22
- package/lib/plugins/image/insert-image-handler.js.map +1 -1
- package/lib/plugins/index.js +13 -34
- package/lib/plugins/index.js.map +1 -1
- package/lib/plugins/list/index.js +13 -42
- package/lib/plugins/list/index.js.map +1 -1
- package/lib/plugins/math/index.js +30 -75
- package/lib/plugins/math/index.js.map +1 -1
- package/lib/plugins/media/index.js +18 -75
- package/lib/plugins/media/index.js.map +1 -1
- package/lib/plugins/media/media-dialog.js +100 -188
- package/lib/plugins/media/media-dialog.js.map +1 -1
- package/lib/plugins/media/media-toolbar.js +4 -24
- package/lib/plugins/media/media-toolbar.js.map +1 -1
- package/lib/plugins/media/media-wrapper.js +5 -29
- package/lib/plugins/media/media-wrapper.js.map +1 -1
- package/lib/plugins/respArea/drag-in-the-blank/choice.js +10 -50
- package/lib/plugins/respArea/drag-in-the-blank/choice.js.map +1 -1
- package/lib/plugins/respArea/drag-in-the-blank/index.js +4 -18
- package/lib/plugins/respArea/drag-in-the-blank/index.js.map +1 -1
- package/lib/plugins/respArea/explicit-constructed-response/index.js +2 -8
- package/lib/plugins/respArea/explicit-constructed-response/index.js.map +1 -1
- package/lib/plugins/respArea/icons/index.js +1 -18
- package/lib/plugins/respArea/icons/index.js.map +1 -1
- package/lib/plugins/respArea/index.js +1 -47
- package/lib/plugins/respArea/index.js.map +1 -1
- package/lib/plugins/respArea/inline-dropdown/index.js +1 -8
- package/lib/plugins/respArea/inline-dropdown/index.js.map +1 -1
- package/lib/plugins/respArea/utils.js +0 -22
- package/lib/plugins/respArea/utils.js.map +1 -1
- package/lib/plugins/table/icons/index.js +0 -7
- package/lib/plugins/table/icons/index.js.map +1 -1
- package/lib/plugins/table/index.js +15 -94
- package/lib/plugins/table/index.js.map +1 -1
- package/lib/plugins/table/table-toolbar.js +11 -43
- package/lib/plugins/table/table-toolbar.js.map +1 -1
- package/lib/plugins/toolbar/default-toolbar.js +8 -30
- package/lib/plugins/toolbar/default-toolbar.js.map +1 -1
- package/lib/plugins/toolbar/done-button.js +1 -9
- package/lib/plugins/toolbar/done-button.js.map +1 -1
- package/lib/plugins/toolbar/editor-and-toolbar.js +18 -48
- package/lib/plugins/toolbar/editor-and-toolbar.js.map +1 -1
- package/lib/plugins/toolbar/index.js +0 -5
- package/lib/plugins/toolbar/index.js.map +1 -1
- package/lib/plugins/toolbar/toolbar-buttons.js +8 -39
- package/lib/plugins/toolbar/toolbar-buttons.js.map +1 -1
- package/lib/plugins/toolbar/toolbar.js +19 -67
- package/lib/plugins/toolbar/toolbar.js.map +1 -1
- package/lib/plugins/utils.js +0 -15
- package/lib/plugins/utils.js.map +1 -1
- package/lib/serialization.js +8 -69
- package/lib/serialization.js.map +1 -1
- package/lib/theme.js.map +1 -1
- package/package.json +3 -3
- package/src/plugins/media/index.jsx +0 -1
|
@@ -1,26 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.isNumber = exports.insertSnackBar = exports.getDefaultElement = exports.defaultIDD = exports.defaultECR = exports.defaultDIB = void 0;
|
|
9
|
-
|
|
10
8
|
var _react = _interopRequireDefault(require("react"));
|
|
11
|
-
|
|
12
9
|
var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
13
|
-
|
|
14
10
|
var _slate = require("slate");
|
|
15
|
-
|
|
16
11
|
var _Snackbar = _interopRequireDefault(require("@material-ui/core/Snackbar"));
|
|
17
|
-
|
|
18
12
|
var isNumber = function isNumber(val) {
|
|
19
13
|
return !isNaN(parseFloat(val)) && isFinite(val);
|
|
20
14
|
};
|
|
21
|
-
|
|
22
15
|
exports.isNumber = isNumber;
|
|
23
|
-
|
|
24
16
|
var insertSnackBar = function insertSnackBar(message) {
|
|
25
17
|
var prevSnacks = document.querySelectorAll('.response-area-alert');
|
|
26
18
|
prevSnacks.forEach(function (s) {
|
|
@@ -28,7 +20,6 @@ var insertSnackBar = function insertSnackBar(message) {
|
|
|
28
20
|
});
|
|
29
21
|
var newEl = document.createElement('div');
|
|
30
22
|
newEl.className = 'response-area-alert';
|
|
31
|
-
|
|
32
23
|
var el = /*#__PURE__*/_react["default"].createElement(_Snackbar["default"], {
|
|
33
24
|
anchorOrigin: {
|
|
34
25
|
vertical: 'top',
|
|
@@ -42,17 +33,13 @@ var insertSnackBar = function insertSnackBar(message) {
|
|
|
42
33
|
id: "message-id"
|
|
43
34
|
}, message)
|
|
44
35
|
});
|
|
45
|
-
|
|
46
36
|
_reactDom["default"].render(el, newEl);
|
|
47
|
-
|
|
48
37
|
document.body.appendChild(newEl);
|
|
49
38
|
setTimeout(function () {
|
|
50
39
|
newEl.remove();
|
|
51
40
|
}, 2000);
|
|
52
41
|
};
|
|
53
|
-
|
|
54
42
|
exports.insertSnackBar = insertSnackBar;
|
|
55
|
-
|
|
56
43
|
var defaultECR = function defaultECR(index) {
|
|
57
44
|
return _slate.Inline.create({
|
|
58
45
|
type: 'explicit_constructed_response',
|
|
@@ -62,9 +49,7 @@ var defaultECR = function defaultECR(index) {
|
|
|
62
49
|
}
|
|
63
50
|
});
|
|
64
51
|
};
|
|
65
|
-
|
|
66
52
|
exports.defaultECR = defaultECR;
|
|
67
|
-
|
|
68
53
|
var defaultDIB = function defaultDIB(opts, index) {
|
|
69
54
|
return _slate.Inline.create({
|
|
70
55
|
type: 'drag_in_the_blank',
|
|
@@ -76,9 +61,7 @@ var defaultDIB = function defaultDIB(opts, index) {
|
|
|
76
61
|
}
|
|
77
62
|
});
|
|
78
63
|
};
|
|
79
|
-
|
|
80
64
|
exports.defaultDIB = defaultDIB;
|
|
81
|
-
|
|
82
65
|
var defaultIDD = function defaultIDD(index) {
|
|
83
66
|
return _slate.Inline.create({
|
|
84
67
|
object: 'inline',
|
|
@@ -89,22 +72,17 @@ var defaultIDD = function defaultIDD(index) {
|
|
|
89
72
|
}
|
|
90
73
|
});
|
|
91
74
|
};
|
|
92
|
-
|
|
93
75
|
exports.defaultIDD = defaultIDD;
|
|
94
|
-
|
|
95
76
|
var getDefaultElement = function getDefaultElement(opts, index) {
|
|
96
77
|
switch (opts.type) {
|
|
97
78
|
case 'explicit-constructed-response':
|
|
98
79
|
return defaultECR(index);
|
|
99
|
-
|
|
100
80
|
case 'drag-in-the-blank':
|
|
101
81
|
return defaultDIB(opts, index);
|
|
102
|
-
|
|
103
82
|
default:
|
|
104
83
|
// inline-dropdown
|
|
105
84
|
return defaultIDD(index);
|
|
106
85
|
}
|
|
107
86
|
};
|
|
108
|
-
|
|
109
87
|
exports.getDefaultElement = getDefaultElement;
|
|
110
88
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"utils.js","names":["isNumber","val","isNaN","parseFloat","isFinite","insertSnackBar","message","prevSnacks","document","querySelectorAll","forEach","s","remove","newEl","createElement","className","el","vertical","horizontal","ReactDOM","render","body","appendChild","setTimeout","defaultECR","index","Inline","create","type","isVoid","data","defaultDIB","opts","duplicates","options","value","defaultIDD","object","getDefaultElement"],"sources":["../../../src/plugins/respArea/utils.jsx"],"sourcesContent":["import React from 'react';\nimport ReactDOM from 'react-dom';\nimport { Inline } from 'slate';\nimport Snackbar from '@material-ui/core/Snackbar';\n\nexport const isNumber = (val) => !isNaN(parseFloat(val)) && isFinite(val);\n\nexport const insertSnackBar = (message) => {\n const prevSnacks = document.querySelectorAll('.response-area-alert');\n\n prevSnacks.forEach((s) => s.remove());\n\n const newEl = document.createElement('div');\n\n newEl.className = 'response-area-alert';\n\n const el = (\n <Snackbar\n anchorOrigin={{ vertical: 'top', horizontal: 'center' }}\n open={true}\n ContentProps={{\n 'aria-describedby': 'message-id',\n }}\n message={<span id=\"message-id\">{message}</span>}\n />\n );\n\n ReactDOM.render(el, newEl);\n\n document.body.appendChild(newEl);\n\n setTimeout(() => {\n newEl.remove();\n }, 2000);\n};\n\nexport const defaultECR = (index) =>\n Inline.create({\n type: 'explicit_constructed_response',\n isVoid: true,\n data: {\n index,\n },\n });\n\nexport const defaultDIB = (opts, index) =>\n Inline.create({\n type: 'drag_in_the_blank',\n isVoid: true,\n data: {\n index,\n duplicates: opts.options.duplicates,\n value: null,\n },\n });\n\nexport const defaultIDD = (index) =>\n Inline.create({\n object: 'inline',\n type: 'inline_dropdown',\n isVoid: true,\n data: {\n index,\n },\n });\n\nexport const getDefaultElement = (opts, index) => {\n switch (opts.type) {\n case 'explicit-constructed-response':\n return defaultECR(index);\n case 'drag-in-the-blank':\n return defaultDIB(opts, index);\n default:\n // inline-dropdown\n return defaultIDD(index);\n }\n};\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AAEO,IAAMA,QAAQ,GAAG,SAAXA,QAAQ,CAAIC,GAAG;EAAA,OAAK,CAACC,KAAK,CAACC,UAAU,CAACF,GAAG,CAAC,CAAC,IAAIG,QAAQ,CAACH,GAAG,CAAC;AAAA;AAAC;AAEnE,IAAMI,cAAc,GAAG,SAAjBA,cAAc,CAAIC,OAAO,EAAK;EACzC,IAAMC,UAAU,GAAGC,QAAQ,CAACC,gBAAgB,CAAC,sBAAsB,CAAC;EAEpEF,UAAU,CAACG,OAAO,CAAC,UAACC,CAAC;IAAA,OAAKA,CAAC,CAACC,MAAM,EAAE;EAAA,EAAC;EAErC,IAAMC,KAAK,GAAGL,QAAQ,CAACM,aAAa,CAAC,KAAK,CAAC;EAE3CD,KAAK,CAACE,SAAS,GAAG,qBAAqB;EAEvC,IAAMC,EAAE,gBACN,gCAAC,oBAAQ;IACP,YAAY,EAAE;MAAEC,QAAQ,EAAE,KAAK;MAAEC,UAAU,EAAE;IAAS,CAAE;IACxD,IAAI,EAAE,IAAK;IACX,YAAY,EAAE;MACZ,kBAAkB,EAAE;IACtB,CAAE;IACF,OAAO,eAAE;MAAM,EAAE,EAAC;IAAY,GAAEZ,OAAO;EAAS,EAEnD;EAEDa,oBAAQ,CAACC,MAAM,CAACJ,EAAE,EAAEH,KAAK,CAAC;EAE1BL,QAAQ,CAACa,IAAI,CAACC,WAAW,CAACT,KAAK,CAAC;EAEhCU,UAAU,CAAC,YAAM;IACfV,KAAK,CAACD,MAAM,EAAE;EAChB,CAAC,EAAE,IAAI,CAAC;AACV,CAAC;AAAC;AAEK,IAAMY,UAAU,GAAG,SAAbA,UAAU,CAAIC,KAAK;EAAA,OAC9BC,aAAM,CAACC,MAAM,CAAC;IACZC,IAAI,EAAE,+BAA+B;IACrCC,MAAM,EAAE,IAAI;IACZC,IAAI,EAAE;MACJL,KAAK,EAALA;IACF;EACF,CAAC,CAAC;AAAA;AAAC;AAEE,IAAMM,UAAU,GAAG,SAAbA,UAAU,CAAIC,IAAI,EAAEP,KAAK;EAAA,OACpCC,aAAM,CAACC,MAAM,CAAC;IACZC,IAAI,EAAE,mBAAmB;IACzBC,MAAM,EAAE,IAAI;IACZC,IAAI,EAAE;MACJL,KAAK,EAALA,KAAK;MACLQ,UAAU,EAAED,IAAI,CAACE,OAAO,CAACD,UAAU;MACnCE,KAAK,EAAE;IACT;EACF,CAAC,CAAC;AAAA;AAAC;AAEE,IAAMC,UAAU,GAAG,SAAbA,UAAU,CAAIX,KAAK;EAAA,OAC9BC,aAAM,CAACC,MAAM,CAAC;IACZU,MAAM,EAAE,QAAQ;IAChBT,IAAI,EAAE,iBAAiB;IACvBC,MAAM,EAAE,IAAI;IACZC,IAAI,EAAE;MACJL,KAAK,EAALA;IACF;EACF,CAAC,CAAC;AAAA;AAAC;AAEE,IAAMa,iBAAiB,GAAG,SAApBA,iBAAiB,CAAIN,IAAI,EAAEP,KAAK,EAAK;EAChD,QAAQO,IAAI,CAACJ,IAAI;IACf,KAAK,+BAA+B;MAClC,OAAOJ,UAAU,CAACC,KAAK,CAAC;IAC1B,KAAK,mBAAmB;MACtB,OAAOM,UAAU,CAACC,IAAI,EAAEP,KAAK,CAAC;IAChC;MACE;MACA,OAAOW,UAAU,CAACX,KAAK,CAAC;EAAC;AAE/B,CAAC;AAAC"}
|
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.RemoveTable = exports.RemoveRow = exports.RemoveColumn = exports.AddRow = exports.AddColumn = void 0;
|
|
9
|
-
|
|
10
8
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
11
|
-
|
|
12
9
|
var _react = _interopRequireDefault(require("react"));
|
|
13
|
-
|
|
14
10
|
var _styles = require("@material-ui/core/styles");
|
|
15
|
-
|
|
16
11
|
var styles = {
|
|
17
12
|
icon: {
|
|
18
13
|
fill: 'grey',
|
|
@@ -21,7 +16,6 @@ var styles = {
|
|
|
21
16
|
}
|
|
22
17
|
}
|
|
23
18
|
};
|
|
24
|
-
|
|
25
19
|
var SvgIcon = function SvgIcon(Component) {
|
|
26
20
|
return (0, _styles.withStyles)(styles)(function (props) {
|
|
27
21
|
return /*#__PURE__*/_react["default"].createElement("svg", {
|
|
@@ -35,7 +29,6 @@ var SvgIcon = function SvgIcon(Component) {
|
|
|
35
29
|
}));
|
|
36
30
|
});
|
|
37
31
|
};
|
|
38
|
-
|
|
39
32
|
var AddRow = SvgIcon(function (props) {
|
|
40
33
|
return /*#__PURE__*/_react["default"].createElement("path", (0, _extends2["default"])({}, props, {
|
|
41
34
|
d: "M22,10A2,2 0 0,1 20,12H4A2,2 0 0,1 2,10V3H4V5H8V3H10V5H14V3H16V5H20V3H22V10M4,10H8V7H4V10M10,10H14V7H10V10M20,10V7H16V10H20M11,14H13V17H16V19H13V22H11V19H8V17H11V14Z"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","names":["styles","icon","fill","SvgIcon","Component","withStyles","props","classes","AddRow","RemoveRow","AddColumn","RemoveColumn","RemoveTable"],"sources":["../../../../src/plugins/table/icons/index.jsx"],"sourcesContent":["import React from 'react';\nimport { withStyles } from '@material-ui/core/styles';\n\nconst styles = {\n icon: {\n fill: 'grey',\n '&:hover': {\n fill: 'black',\n },\n },\n};\n\nconst SvgIcon = (Component) => {\n return withStyles(styles)((props) => (\n <svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\">\n <Component className={props.classes.icon} />\n </svg>\n ));\n};\nexport const AddRow = SvgIcon((props) => (\n <path\n {...props}\n d=\"M22,10A2,2 0 0,1 20,12H4A2,2 0 0,1 2,10V3H4V5H8V3H10V5H14V3H16V5H20V3H22V10M4,10H8V7H4V10M10,10H14V7H10V10M20,10V7H16V10H20M11,14H13V17H16V19H13V22H11V19H8V17H11V14Z\"\n />\n));\n\nexport const RemoveRow = SvgIcon((props) => (\n <path\n {...props}\n d=\"M9.41,13L12,15.59L14.59,13L16,14.41L13.41,17L16,19.59L14.59,21L12,18.41L9.41,21L8,19.59L10.59,17L8,14.41L9.41,13M22,9A2,2 0 0,1 20,11H4A2,2 0 0,1 2,9V6A2,2 0 0,1 4,4H20A2,2 0 0,1 22,6V9M4,9H8V6H4V9M10,9H14V6H10V9M16,9H20V6H16V9Z\"\n />\n));\n\nexport const AddColumn = SvgIcon((props) => (\n <path\n {...props}\n d=\"M11,2A2,2 0 0,1 13,4V20A2,2 0 0,1 11,22H2V2H11M4,10V14H11V10H4M4,16V20H11V16H4M4,4V8H11V4H4M15,11H18V8H20V11H23V13H20V16H18V13H15V11Z\"\n />\n));\n\nexport const RemoveColumn = SvgIcon((props) => (\n <path\n {...props}\n d=\"M4,2H11A2,2 0 0,1 13,4V20A2,2 0 0,1 11,22H4A2,2 0 0,1 2,20V4A2,2 0 0,1 4,2M4,10V14H11V10H4M4,16V20H11V16H4M4,4V8H11V4H4M17.59,12L15,9.41L16.41,8L19,10.59L21.59,8L23,9.41L20.41,12L23,14.59L21.59,16L19,13.41L16.41,16L15,14.59L17.59,12Z\"\n />\n));\n\nexport const RemoveTable = SvgIcon((props) => (\n <path\n {...props}\n d=\"M15.46,15.88L16.88,14.46L19,16.59L21.12,14.46L22.54,15.88L20.41,18L22.54,20.12L21.12,21.54L19,19.41L16.88,21.54L15.46,20.12L17.59,18L15.46,15.88M4,3H18A2,2 0 0,1 20,5V12.08C18.45,11.82 16.92,12.18 15.68,13H12V17H13.08C12.97,17.68 12.97,18.35 13.08,19H4A2,2 0 0,1 2,17V5A2,2 0 0,1 4,3M4,7V11H10V7H4M12,7V11H18V7H12M4,13V17H10V13H4Z\"\n />\n));\n"],"mappings":";;;;;;;;AAAA;AACA;AAEA,IAAMA,MAAM,GAAG;EACbC,IAAI,EAAE;IACJC,IAAI,EAAE,MAAM;IACZ,SAAS,EAAE;MACTA,IAAI,EAAE;IACR;EACF;AACF,CAAC;AAED,IAAMC,OAAO,GAAG,SAAVA,OAAO,CAAIC,SAAS,EAAK;EAC7B,OAAO,IAAAC,kBAAU,EAACL,MAAM,CAAC,CAAC,UAACM,KAAK;IAAA,oBAC9B;MAAK,KAAK,EAAC,4BAA4B;MAAC,OAAO,EAAC,KAAK;MAAC,KAAK,EAAC,IAAI;MAAC,MAAM,EAAC,IAAI;MAAC,OAAO,EAAC;IAAW,gBAC9F,gCAAC,SAAS;MAAC,SAAS,EAAEA,KAAK,CAACC,OAAO,CAACN;IAAK,EAAG,CACxC;EAAA,CACP,CAAC;AACJ,CAAC;AACM,IAAMO,MAAM,GAAGL,OAAO,CAAC,UAACG,KAAK;EAAA,oBAClC,sEACMA,KAAK;IACT,CAAC,EAAC;EAAuK,GACzK;AAAA,CACH,CAAC;AAAC;AAEI,IAAMG,SAAS,GAAGN,OAAO,CAAC,UAACG,KAAK;EAAA,oBACrC,sEACMA,KAAK;IACT,CAAC,EAAC;EAAsO,GACxO;AAAA,CACH,CAAC;AAAC;AAEI,IAAMI,SAAS,GAAGP,OAAO,CAAC,UAACG,KAAK;EAAA,oBACrC,sEACMA,KAAK;IACT,CAAC,EAAC;EAAuI,GACzI;AAAA,CACH,CAAC;AAAC;AAEI,IAAMK,YAAY,GAAGR,OAAO,CAAC,UAACG,KAAK;EAAA,oBACxC,sEACMA,KAAK;IACT,CAAC,EAAC;EAA2O,GAC7O;AAAA,CACH,CAAC;AAAC;AAEI,IAAMM,WAAW,GAAGT,OAAO,CAAC,UAACG,KAAK;EAAA,oBACvC,sEACMA,KAAK;IACT,CAAC,EAAC;EAA4U,GAC9U;AAAA,CACH,CAAC;AAAC"}
|
|
@@ -1,42 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.serialization = exports.reactAttributes = exports.parseStyleString = exports.moveFocusToBeginningOfTable = exports["default"] = void 0;
|
|
9
|
-
|
|
10
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
12
9
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
13
|
-
|
|
14
10
|
var _react = _interopRequireDefault(require("react"));
|
|
15
|
-
|
|
16
11
|
var _slateEditTable = _interopRequireDefault(require("slate-edit-table"));
|
|
17
|
-
|
|
18
12
|
var _slate = require("slate");
|
|
19
|
-
|
|
20
13
|
var _debug = _interopRequireDefault(require("debug"));
|
|
21
|
-
|
|
22
14
|
var _GridOn = _interopRequireDefault(require("@material-ui/icons/GridOn"));
|
|
23
|
-
|
|
24
15
|
var _tableToolbar = _interopRequireDefault(require("./table-toolbar"));
|
|
25
|
-
|
|
26
16
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
27
|
-
|
|
28
17
|
var _slatePropTypes = _interopRequireDefault(require("slate-prop-types"));
|
|
29
|
-
|
|
30
18
|
var _styles = require("@material-ui/core/styles");
|
|
31
|
-
|
|
32
19
|
var _reactAttrConverter = _interopRequireDefault(require("react-attr-converter"));
|
|
33
|
-
|
|
34
20
|
var _toStyle = require("to-style");
|
|
35
|
-
|
|
36
21
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
37
|
-
|
|
38
22
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
39
|
-
|
|
40
23
|
var log = (0, _debug["default"])('@pie-lib:editable-html:plugins:table');
|
|
41
24
|
var Table = (0, _styles.withStyles)(function () {
|
|
42
25
|
return {
|
|
@@ -58,11 +41,9 @@ Table.propTypes = {
|
|
|
58
41
|
node: _slatePropTypes["default"].node,
|
|
59
42
|
children: _propTypes["default"].oneOfType([_propTypes["default"].arrayOf(_propTypes["default"].node), _propTypes["default"].node]).isRequired
|
|
60
43
|
};
|
|
61
|
-
|
|
62
44
|
var TableRow = function TableRow(props) {
|
|
63
45
|
return /*#__PURE__*/_react["default"].createElement("tr", props.attributes, props.children);
|
|
64
46
|
};
|
|
65
|
-
|
|
66
47
|
TableRow.propTypes = {
|
|
67
48
|
attributes: _propTypes["default"].object,
|
|
68
49
|
onFocus: _propTypes["default"].func,
|
|
@@ -92,49 +73,41 @@ TableCell.propTypes = {
|
|
|
92
73
|
onBlur: _propTypes["default"].func,
|
|
93
74
|
children: _propTypes["default"].oneOfType([_propTypes["default"].arrayOf(_propTypes["default"].node), _propTypes["default"].node]).isRequired
|
|
94
75
|
};
|
|
95
|
-
|
|
96
76
|
var moveFocusToBeginningOfTable = function moveFocusToBeginningOfTable(change) {
|
|
97
77
|
var addedTable = change.value.document.findDescendant(function (d) {
|
|
98
78
|
return !!d.data && !!d.data.get('newTable');
|
|
99
79
|
});
|
|
100
|
-
|
|
101
80
|
if (!addedTable) {
|
|
102
81
|
return;
|
|
103
82
|
}
|
|
104
|
-
|
|
105
83
|
change.collapseToStartOf(addedTable);
|
|
106
84
|
var update = addedTable.data.remove('newTable');
|
|
107
85
|
change.setNodeByKey(addedTable.key, {
|
|
108
86
|
data: update
|
|
109
87
|
});
|
|
110
88
|
};
|
|
111
|
-
|
|
112
89
|
exports.moveFocusToBeginningOfTable = moveFocusToBeginningOfTable;
|
|
113
|
-
|
|
114
|
-
var _default = function _default(opts, toolbarPlugins
|
|
115
|
-
/* : {toolbar: {}}[] */
|
|
116
|
-
) {
|
|
90
|
+
var _default = function _default(opts, toolbarPlugins /* : {toolbar: {}}[] */) {
|
|
117
91
|
var core = (0, _slateEditTable["default"])({
|
|
118
92
|
typeContent: 'div'
|
|
119
|
-
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// fix outdated schema
|
|
120
96
|
|
|
121
97
|
if (core.schema && core.schema.blocks) {
|
|
122
98
|
Object.keys(core.schema.blocks).forEach(function (key) {
|
|
123
99
|
var block = core.schema.blocks[key];
|
|
124
|
-
|
|
125
100
|
if (block.parent) {
|
|
126
101
|
if (block.nodes[0].types) {
|
|
127
102
|
block.nodes[0] = {
|
|
128
103
|
type: block.nodes[0].types[0]
|
|
129
104
|
};
|
|
130
105
|
}
|
|
131
|
-
|
|
132
106
|
if (block.nodes[0].objects) {
|
|
133
107
|
block.nodes[0] = {
|
|
134
108
|
object: block.nodes[0].objects[0]
|
|
135
109
|
};
|
|
136
110
|
}
|
|
137
|
-
|
|
138
111
|
block.parent = {
|
|
139
112
|
type: block.parent.types[0]
|
|
140
113
|
};
|
|
@@ -145,7 +118,6 @@ var _default = function _default(opts, toolbarPlugins
|
|
|
145
118
|
}
|
|
146
119
|
});
|
|
147
120
|
}
|
|
148
|
-
|
|
149
121
|
core.utils.getTableBlock = function (containerNode, key) {
|
|
150
122
|
var node = containerNode.getDescendant(key);
|
|
151
123
|
var ancestors = containerNode.getAncestors(key).push(node);
|
|
@@ -153,15 +125,11 @@ var _default = function _default(opts, toolbarPlugins
|
|
|
153
125
|
return p.type === 'table';
|
|
154
126
|
});
|
|
155
127
|
};
|
|
156
|
-
|
|
157
128
|
core.utils.createTableWithOptions = function (row, columns, extra) {
|
|
158
129
|
var createdTable = core.utils.createTable(row, columns);
|
|
159
|
-
|
|
160
130
|
var newTable = _slate.Block.create(_objectSpread(_objectSpread({}, createdTable.toJSON()), extra));
|
|
161
|
-
|
|
162
131
|
return newTable;
|
|
163
132
|
};
|
|
164
|
-
|
|
165
133
|
core.toolbar = {
|
|
166
134
|
icon: /*#__PURE__*/_react["default"].createElement(_GridOn["default"], null),
|
|
167
135
|
onClick: function onClick(value, onChange) {
|
|
@@ -180,7 +148,6 @@ var _default = function _default(opts, toolbarPlugins
|
|
|
180
148
|
supports: function supports(node, value) {
|
|
181
149
|
return node && node.object === 'block' && core.utils.isSelectionInTable(value);
|
|
182
150
|
},
|
|
183
|
-
|
|
184
151
|
/**
|
|
185
152
|
* Note - the node may not be a table node - it may be a node inside a table.
|
|
186
153
|
*/
|
|
@@ -188,36 +155,29 @@ var _default = function _default(opts, toolbarPlugins
|
|
|
188
155
|
log('[customToolbar] node.data: ', node.data);
|
|
189
156
|
var tableBlock = core.utils.getTableBlock(value.document, node === null || node === void 0 ? void 0 : node.key);
|
|
190
157
|
log('[customToolbar] tableBlock: ', tableBlock);
|
|
191
|
-
|
|
192
158
|
var hasBorder = function hasBorder() {
|
|
193
159
|
return tableBlock.data.get('border') && tableBlock.data.get('border') !== '0';
|
|
194
160
|
};
|
|
195
|
-
|
|
196
161
|
var addRow = function addRow() {
|
|
197
162
|
var change = core.changes.insertRow(value.change());
|
|
198
163
|
onToolbarDone(change, false);
|
|
199
164
|
};
|
|
200
|
-
|
|
201
165
|
var addColumn = function addColumn() {
|
|
202
166
|
var change = core.changes.insertColumn(value.change());
|
|
203
167
|
onToolbarDone(change, false);
|
|
204
168
|
};
|
|
205
|
-
|
|
206
169
|
var removeRow = function removeRow() {
|
|
207
170
|
var change = core.changes.removeRow(value.change());
|
|
208
171
|
onToolbarDone(change, false);
|
|
209
172
|
};
|
|
210
|
-
|
|
211
173
|
var removeColumn = function removeColumn() {
|
|
212
174
|
var change = core.changes.removeColumn(value.change());
|
|
213
175
|
onToolbarDone(change, false);
|
|
214
176
|
};
|
|
215
|
-
|
|
216
177
|
var removeTable = function removeTable() {
|
|
217
178
|
var change = core.changes.removeTable(value.change());
|
|
218
179
|
onToolbarDone(change, false);
|
|
219
180
|
};
|
|
220
|
-
|
|
221
181
|
var toggleBorder = function toggleBorder() {
|
|
222
182
|
var data = tableBlock.data;
|
|
223
183
|
var update = data.set('border', hasBorder() ? '0' : '1');
|
|
@@ -227,12 +187,10 @@ var _default = function _default(opts, toolbarPlugins
|
|
|
227
187
|
});
|
|
228
188
|
onToolbarDone(change, false);
|
|
229
189
|
};
|
|
230
|
-
|
|
231
190
|
var onDone = function onDone() {
|
|
232
191
|
log('[onDone] call onToolbarDone...');
|
|
233
192
|
onToolbarDone(null, true);
|
|
234
193
|
};
|
|
235
|
-
|
|
236
194
|
var Tb = function Tb() {
|
|
237
195
|
return /*#__PURE__*/_react["default"].createElement(_tableToolbar["default"], {
|
|
238
196
|
plugins: toolbarPlugins,
|
|
@@ -250,11 +208,9 @@ var _default = function _default(opts, toolbarPlugins
|
|
|
250
208
|
onDone: onDone
|
|
251
209
|
});
|
|
252
210
|
};
|
|
253
|
-
|
|
254
211
|
return Tb;
|
|
255
212
|
}
|
|
256
213
|
};
|
|
257
|
-
|
|
258
214
|
var Node = function Node(props) {
|
|
259
215
|
switch (props.node.type) {
|
|
260
216
|
case 'table':
|
|
@@ -262,81 +218,71 @@ var _default = function _default(opts, toolbarPlugins
|
|
|
262
218
|
onFocus: opts.onFocus,
|
|
263
219
|
onBlur: opts.onBlur
|
|
264
220
|
}));
|
|
265
|
-
|
|
266
221
|
case 'table_row':
|
|
267
222
|
return /*#__PURE__*/_react["default"].createElement(TableRow, props);
|
|
268
|
-
|
|
269
223
|
case 'table_cell':
|
|
270
224
|
return /*#__PURE__*/_react["default"].createElement(TableCell, (0, _extends2["default"])({}, props, {
|
|
271
225
|
onFocus: opts.onFocus,
|
|
272
226
|
onBlur: opts.onBlur
|
|
273
227
|
}));
|
|
274
|
-
|
|
275
228
|
default:
|
|
276
229
|
return null;
|
|
277
230
|
}
|
|
278
231
|
};
|
|
279
|
-
|
|
280
232
|
Node.propTypes = {
|
|
281
233
|
node: _propTypes["default"].object
|
|
282
234
|
};
|
|
283
|
-
|
|
284
235
|
core.normalizeNode = function (node) {
|
|
285
236
|
if (node.object !== 'document') {
|
|
286
237
|
return;
|
|
287
238
|
}
|
|
288
|
-
|
|
289
239
|
var tableAdded = node.findDescendant(function (d) {
|
|
290
240
|
return d.data && d.data.get('newTable');
|
|
291
241
|
});
|
|
292
|
-
|
|
293
242
|
if (!tableAdded) {
|
|
294
243
|
return;
|
|
295
244
|
}
|
|
296
|
-
|
|
297
245
|
var nodeToSearch = node.getParent(tableAdded.key) || node;
|
|
298
246
|
var shouldAddTextAfterNode = false;
|
|
299
247
|
var indexToNotHaveTableOn = nodeToSearch.nodes.size - 1;
|
|
300
248
|
var indexOfLastTable = nodeToSearch.nodes.findLastIndex(function (d) {
|
|
301
249
|
return d.type === 'table';
|
|
302
|
-
});
|
|
250
|
+
});
|
|
303
251
|
|
|
252
|
+
// if the last table in the document is of type table, we need to do the change
|
|
304
253
|
if (indexOfLastTable === indexToNotHaveTableOn) {
|
|
305
254
|
shouldAddTextAfterNode = true;
|
|
306
255
|
}
|
|
307
|
-
|
|
308
256
|
if (!shouldAddTextAfterNode) {
|
|
309
257
|
return;
|
|
310
258
|
}
|
|
311
|
-
|
|
312
259
|
return function (change) {
|
|
313
260
|
if (shouldAddTextAfterNode) {
|
|
314
|
-
var tableJSON = tableAdded.toJSON();
|
|
315
|
-
// we need a block that contains text in order to do it
|
|
261
|
+
var tableJSON = tableAdded.toJSON();
|
|
316
262
|
|
|
263
|
+
// we remove the table node because otherwise we can't add the empty block after it
|
|
264
|
+
// we need a block that contains text in order to do it
|
|
317
265
|
change.removeNodeByKey(tableAdded.key);
|
|
318
|
-
|
|
319
266
|
var newBlock = _slate.Block.create({
|
|
320
267
|
object: 'block',
|
|
321
268
|
type: 'div'
|
|
322
|
-
});
|
|
323
|
-
// because it will add the empty text to it like it should
|
|
324
|
-
|
|
269
|
+
});
|
|
325
270
|
|
|
271
|
+
// we add an empty block but that it's going to be normalized
|
|
272
|
+
// because it will add the empty text to it like it should
|
|
326
273
|
change.insertBlock(newBlock);
|
|
327
274
|
change.withoutNormalization(function () {
|
|
328
275
|
// we do these changes without normalization
|
|
276
|
+
|
|
329
277
|
// we get the text previous to the new block added
|
|
330
278
|
var prevText = change.value.document.getPreviousText(newBlock.key);
|
|
331
|
-
|
|
332
279
|
if (prevText) {
|
|
333
280
|
var _prevText$text, _prevText$text2;
|
|
334
|
-
|
|
335
281
|
// we move focus to the previous text
|
|
336
282
|
change.moveFocusTo(prevText.key, (_prevText$text = prevText.text) === null || _prevText$text === void 0 ? void 0 : _prevText$text.length).moveAnchorTo(prevText.key, (_prevText$text2 = prevText.text) === null || _prevText$text2 === void 0 ? void 0 : _prevText$text2.length);
|
|
337
|
-
}
|
|
338
|
-
|
|
283
|
+
}
|
|
339
284
|
|
|
285
|
+
// we insert the table block between the first block with text and the last block with text
|
|
340
286
|
change.insertBlock(_objectSpread(_objectSpread({}, tableJSON), {}, {
|
|
341
287
|
data: _objectSpread(_objectSpread({}, tableJSON.data), {}, {
|
|
342
288
|
newTable: true
|
|
@@ -347,40 +293,30 @@ var _default = function _default(opts, toolbarPlugins
|
|
|
347
293
|
}
|
|
348
294
|
};
|
|
349
295
|
};
|
|
350
|
-
|
|
351
296
|
core.renderNode = Node;
|
|
352
297
|
return core;
|
|
353
298
|
};
|
|
354
|
-
|
|
355
299
|
exports["default"] = _default;
|
|
356
|
-
|
|
357
300
|
var parseStyleString = function parseStyleString(s) {
|
|
358
301
|
var regex = /([\w-]*)\s*:\s*([^;]*)/g;
|
|
359
302
|
var match;
|
|
360
303
|
var result = {};
|
|
361
|
-
|
|
362
304
|
while (match = regex.exec(s)) {
|
|
363
305
|
result[match[1]] = match[2].trim();
|
|
364
306
|
}
|
|
365
|
-
|
|
366
307
|
return result;
|
|
367
308
|
};
|
|
368
|
-
|
|
369
309
|
exports.parseStyleString = parseStyleString;
|
|
370
|
-
|
|
371
310
|
var reactAttributes = function reactAttributes(o) {
|
|
372
311
|
return (0, _toStyle.object)(o, {
|
|
373
312
|
camelize: true,
|
|
374
313
|
addUnits: false
|
|
375
314
|
});
|
|
376
315
|
};
|
|
377
|
-
|
|
378
316
|
exports.reactAttributes = reactAttributes;
|
|
379
|
-
|
|
380
317
|
var attributesToMap = function attributesToMap(el) {
|
|
381
318
|
return function (acc, attribute) {
|
|
382
319
|
var value = el.getAttribute(attribute);
|
|
383
|
-
|
|
384
320
|
if (value) {
|
|
385
321
|
if (attribute === 'style') {
|
|
386
322
|
var styleString = el.getAttribute(attribute);
|
|
@@ -390,31 +326,25 @@ var attributesToMap = function attributesToMap(el) {
|
|
|
390
326
|
acc[attribute] = el.getAttribute(attribute);
|
|
391
327
|
}
|
|
392
328
|
}
|
|
393
|
-
|
|
394
329
|
return acc;
|
|
395
330
|
};
|
|
396
331
|
};
|
|
397
|
-
|
|
398
332
|
var dataToAttributes = function dataToAttributes(data) {
|
|
399
333
|
if (!data || !data.get) {
|
|
400
334
|
return {};
|
|
401
335
|
}
|
|
402
|
-
|
|
403
336
|
return data.reduce(function (acc, v, name) {
|
|
404
337
|
if (v) {
|
|
405
338
|
acc[(0, _reactAttrConverter["default"])(name)] = v;
|
|
406
339
|
}
|
|
407
|
-
|
|
408
340
|
return acc;
|
|
409
341
|
}, {});
|
|
410
342
|
};
|
|
411
|
-
|
|
412
343
|
var attributes = ['border', 'cellpadding', 'cellspacing', 'class', 'style'];
|
|
413
344
|
var cellAttributes = ['colspan', 'rowspan', 'class', 'style'];
|
|
414
345
|
var serialization = {
|
|
415
346
|
deserialize: function deserialize(el, next) {
|
|
416
347
|
var tag = el.tagName.toLowerCase();
|
|
417
|
-
|
|
418
348
|
switch (tag) {
|
|
419
349
|
case 'table':
|
|
420
350
|
{
|
|
@@ -427,7 +357,6 @@ var serialization = {
|
|
|
427
357
|
data: attributes.reduce(attributesToMap(el), {})
|
|
428
358
|
};
|
|
429
359
|
}
|
|
430
|
-
|
|
431
360
|
case 'th':
|
|
432
361
|
{
|
|
433
362
|
return {
|
|
@@ -439,7 +368,6 @@ var serialization = {
|
|
|
439
368
|
})
|
|
440
369
|
};
|
|
441
370
|
}
|
|
442
|
-
|
|
443
371
|
case 'tr':
|
|
444
372
|
{
|
|
445
373
|
return {
|
|
@@ -448,7 +376,6 @@ var serialization = {
|
|
|
448
376
|
nodes: next(Array.from(el.children))
|
|
449
377
|
};
|
|
450
378
|
}
|
|
451
|
-
|
|
452
379
|
case 'td':
|
|
453
380
|
{
|
|
454
381
|
return {
|
|
@@ -466,26 +393,20 @@ var serialization = {
|
|
|
466
393
|
if (object.object !== 'block') {
|
|
467
394
|
return;
|
|
468
395
|
}
|
|
469
|
-
|
|
470
396
|
switch (object.type) {
|
|
471
397
|
case 'table':
|
|
472
398
|
{
|
|
473
399
|
var _attributes = dataToAttributes(object.data);
|
|
474
|
-
|
|
475
400
|
return /*#__PURE__*/_react["default"].createElement("table", _attributes, /*#__PURE__*/_react["default"].createElement("tbody", null, children));
|
|
476
401
|
}
|
|
477
|
-
|
|
478
402
|
case 'table_row':
|
|
479
403
|
{
|
|
480
404
|
return /*#__PURE__*/_react["default"].createElement("tr", null, children);
|
|
481
405
|
}
|
|
482
|
-
|
|
483
406
|
case 'table_cell':
|
|
484
407
|
{
|
|
485
408
|
var _attributes2 = dataToAttributes(object.data);
|
|
486
|
-
|
|
487
409
|
delete _attributes2.header;
|
|
488
|
-
|
|
489
410
|
if (object.data.get('header')) {
|
|
490
411
|
return /*#__PURE__*/_react["default"].createElement("th", _attributes2, children);
|
|
491
412
|
} else {
|