@pie-lib/editable-html 9.3.1-next.53 → 9.4.0
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/CHANGELOG.md +17 -0
- package/lib/editor.js +244 -114
- package/lib/editor.js.map +1 -1
- package/lib/index.js +51 -5
- package/lib/index.js.map +1 -1
- package/lib/parse-html.js +5 -6
- package/lib/parse-html.js.map +1 -1
- package/lib/plugins/characters/custom-popper.js +12 -2
- package/lib/plugins/characters/custom-popper.js.map +1 -1
- package/lib/plugins/characters/index.js +50 -3
- 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 +26 -0
- package/lib/plugins/image/alt-dialog.js.map +1 -1
- package/lib/plugins/image/component.js +82 -29
- package/lib/plugins/image/component.js.map +1 -1
- package/lib/plugins/image/image-toolbar.js +45 -7
- package/lib/plugins/image/image-toolbar.js.map +1 -1
- package/lib/plugins/image/index.js +41 -2
- package/lib/plugins/image/index.js.map +1 -1
- package/lib/plugins/image/insert-image-handler.js +22 -2
- package/lib/plugins/image/insert-image-handler.js.map +1 -1
- package/lib/plugins/index.js +34 -13
- package/lib/plugins/index.js.map +1 -1
- package/lib/plugins/list/index.js +42 -13
- package/lib/plugins/list/index.js.map +1 -1
- package/lib/plugins/math/index.js +75 -30
- package/lib/plugins/math/index.js.map +1 -1
- package/lib/plugins/media/index.js +75 -18
- package/lib/plugins/media/index.js.map +1 -1
- package/lib/plugins/media/media-dialog.js +188 -100
- package/lib/plugins/media/media-dialog.js.map +1 -1
- package/lib/plugins/media/media-toolbar.js +24 -4
- package/lib/plugins/media/media-toolbar.js.map +1 -1
- package/lib/plugins/media/media-wrapper.js +29 -5
- package/lib/plugins/media/media-wrapper.js.map +1 -1
- package/lib/plugins/respArea/drag-in-the-blank/choice.js +50 -10
- package/lib/plugins/respArea/drag-in-the-blank/choice.js.map +1 -1
- package/lib/plugins/respArea/drag-in-the-blank/index.js +18 -4
- package/lib/plugins/respArea/drag-in-the-blank/index.js.map +1 -1
- package/lib/plugins/respArea/explicit-constructed-response/index.js +8 -2
- package/lib/plugins/respArea/explicit-constructed-response/index.js.map +1 -1
- package/lib/plugins/respArea/icons/index.js +18 -1
- package/lib/plugins/respArea/icons/index.js.map +1 -1
- package/lib/plugins/respArea/index.js +47 -1
- package/lib/plugins/respArea/index.js.map +1 -1
- package/lib/plugins/respArea/inline-dropdown/index.js +8 -1
- package/lib/plugins/respArea/inline-dropdown/index.js.map +1 -1
- package/lib/plugins/respArea/utils.js +22 -0
- package/lib/plugins/respArea/utils.js.map +1 -1
- package/lib/plugins/table/icons/index.js +7 -0
- package/lib/plugins/table/icons/index.js.map +1 -1
- package/lib/plugins/table/index.js +94 -15
- package/lib/plugins/table/index.js.map +1 -1
- package/lib/plugins/table/table-toolbar.js +43 -11
- package/lib/plugins/table/table-toolbar.js.map +1 -1
- package/lib/plugins/toolbar/default-toolbar.js +30 -8
- package/lib/plugins/toolbar/default-toolbar.js.map +1 -1
- package/lib/plugins/toolbar/done-button.js +9 -1
- package/lib/plugins/toolbar/done-button.js.map +1 -1
- package/lib/plugins/toolbar/editor-and-toolbar.js +48 -18
- package/lib/plugins/toolbar/editor-and-toolbar.js.map +1 -1
- package/lib/plugins/toolbar/index.js +5 -0
- package/lib/plugins/toolbar/index.js.map +1 -1
- package/lib/plugins/toolbar/toolbar-buttons.js +39 -8
- package/lib/plugins/toolbar/toolbar-buttons.js.map +1 -1
- package/lib/plugins/toolbar/toolbar.js +67 -19
- package/lib/plugins/toolbar/toolbar.js.map +1 -1
- package/lib/plugins/utils.js +15 -0
- package/lib/plugins/utils.js.map +1 -1
- package/lib/serialization.js +69 -8
- package/lib/serialization.js.map +1 -1
- package/lib/theme.js.map +1 -1
- package/package.json +4 -4
- package/src/plugins/media/index.jsx +1 -0
|
@@ -1,18 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
4
5
|
Object.defineProperty(exports, "__esModule", {
|
|
5
6
|
value: true
|
|
6
7
|
});
|
|
7
8
|
exports.isNumber = exports.insertSnackBar = exports.getDefaultElement = exports.defaultIDD = exports.defaultECR = exports.defaultDIB = void 0;
|
|
9
|
+
|
|
8
10
|
var _react = _interopRequireDefault(require("react"));
|
|
11
|
+
|
|
9
12
|
var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
13
|
+
|
|
10
14
|
var _slate = require("slate");
|
|
15
|
+
|
|
11
16
|
var _Snackbar = _interopRequireDefault(require("@material-ui/core/Snackbar"));
|
|
17
|
+
|
|
12
18
|
var isNumber = function isNumber(val) {
|
|
13
19
|
return !isNaN(parseFloat(val)) && isFinite(val);
|
|
14
20
|
};
|
|
21
|
+
|
|
15
22
|
exports.isNumber = isNumber;
|
|
23
|
+
|
|
16
24
|
var insertSnackBar = function insertSnackBar(message) {
|
|
17
25
|
var prevSnacks = document.querySelectorAll('.response-area-alert');
|
|
18
26
|
prevSnacks.forEach(function (s) {
|
|
@@ -20,6 +28,7 @@ var insertSnackBar = function insertSnackBar(message) {
|
|
|
20
28
|
});
|
|
21
29
|
var newEl = document.createElement('div');
|
|
22
30
|
newEl.className = 'response-area-alert';
|
|
31
|
+
|
|
23
32
|
var el = /*#__PURE__*/_react["default"].createElement(_Snackbar["default"], {
|
|
24
33
|
anchorOrigin: {
|
|
25
34
|
vertical: 'top',
|
|
@@ -33,13 +42,17 @@ var insertSnackBar = function insertSnackBar(message) {
|
|
|
33
42
|
id: "message-id"
|
|
34
43
|
}, message)
|
|
35
44
|
});
|
|
45
|
+
|
|
36
46
|
_reactDom["default"].render(el, newEl);
|
|
47
|
+
|
|
37
48
|
document.body.appendChild(newEl);
|
|
38
49
|
setTimeout(function () {
|
|
39
50
|
newEl.remove();
|
|
40
51
|
}, 2000);
|
|
41
52
|
};
|
|
53
|
+
|
|
42
54
|
exports.insertSnackBar = insertSnackBar;
|
|
55
|
+
|
|
43
56
|
var defaultECR = function defaultECR(index) {
|
|
44
57
|
return _slate.Inline.create({
|
|
45
58
|
type: 'explicit_constructed_response',
|
|
@@ -49,7 +62,9 @@ var defaultECR = function defaultECR(index) {
|
|
|
49
62
|
}
|
|
50
63
|
});
|
|
51
64
|
};
|
|
65
|
+
|
|
52
66
|
exports.defaultECR = defaultECR;
|
|
67
|
+
|
|
53
68
|
var defaultDIB = function defaultDIB(opts, index) {
|
|
54
69
|
return _slate.Inline.create({
|
|
55
70
|
type: 'drag_in_the_blank',
|
|
@@ -61,7 +76,9 @@ var defaultDIB = function defaultDIB(opts, index) {
|
|
|
61
76
|
}
|
|
62
77
|
});
|
|
63
78
|
};
|
|
79
|
+
|
|
64
80
|
exports.defaultDIB = defaultDIB;
|
|
81
|
+
|
|
65
82
|
var defaultIDD = function defaultIDD(index) {
|
|
66
83
|
return _slate.Inline.create({
|
|
67
84
|
object: 'inline',
|
|
@@ -72,17 +89,22 @@ var defaultIDD = function defaultIDD(index) {
|
|
|
72
89
|
}
|
|
73
90
|
});
|
|
74
91
|
};
|
|
92
|
+
|
|
75
93
|
exports.defaultIDD = defaultIDD;
|
|
94
|
+
|
|
76
95
|
var getDefaultElement = function getDefaultElement(opts, index) {
|
|
77
96
|
switch (opts.type) {
|
|
78
97
|
case 'explicit-constructed-response':
|
|
79
98
|
return defaultECR(index);
|
|
99
|
+
|
|
80
100
|
case 'drag-in-the-blank':
|
|
81
101
|
return defaultDIB(opts, index);
|
|
102
|
+
|
|
82
103
|
default:
|
|
83
104
|
// inline-dropdown
|
|
84
105
|
return defaultIDD(index);
|
|
85
106
|
}
|
|
86
107
|
};
|
|
108
|
+
|
|
87
109
|
exports.getDefaultElement = getDefaultElement;
|
|
88
110
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/respArea/utils.jsx"],"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"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AAEO,IAAMA,QAAQ,GAAG,SAAXA,QAAW,CAACC,GAAD;AAAA,SAAS,CAACC,KAAK,CAACC,UAAU,CAACF,GAAD,CAAX,CAAN,IAA2BG,QAAQ,CAACH,GAAD,CAA5C;AAAA,CAAjB;;;;AAEA,IAAMI,cAAc,GAAG,SAAjBA,cAAiB,CAACC,OAAD,EAAa;AACzC,MAAMC,UAAU,GAAGC,QAAQ,CAACC,gBAAT,CAA0B,sBAA1B,CAAnB;AAEAF,EAAAA,UAAU,CAACG,OAAX,CAAmB,UAACC,CAAD;AAAA,WAAOA,CAAC,CAACC,MAAF,EAAP;AAAA,GAAnB;AAEA,MAAMC,KAAK,GAAGL,QAAQ,CAACM,aAAT,CAAuB,KAAvB,CAAd;AAEAD,EAAAA,KAAK,CAACE,SAAN,GAAkB,qBAAlB;;AAEA,MAAMC,EAAE,gBACN,gCAAC,oBAAD;AACE,IAAA,YAAY,EAAE;AAAEC,MAAAA,QAAQ,EAAE,KAAZ;AAAmBC,MAAAA,UAAU,EAAE;AAA/B,KADhB;AAEE,IAAA,IAAI,EAAE,IAFR;AAGE,IAAA,YAAY,EAAE;AACZ,0BAAoB;AADR,KAHhB;AAME,IAAA,OAAO,eAAE;AAAM,MAAA,EAAE,EAAC;AAAT,OAAuBZ,OAAvB;AANX,IADF;;AAWAa,uBAASC,MAAT,CAAgBJ,EAAhB,EAAoBH,KAApB;;AAEAL,EAAAA,QAAQ,CAACa,IAAT,CAAcC,WAAd,CAA0BT,KAA1B;AAEAU,EAAAA,UAAU,CAAC,YAAM;AACfV,IAAAA,KAAK,CAACD,MAAN;AACD,GAFS,EAEP,IAFO,CAAV;AAGD,CA3BM;;;;AA6BA,IAAMY,UAAU,GAAG,SAAbA,UAAa,CAACC,KAAD;AAAA,SACxBC,cAAOC,MAAP,CAAc;AACZC,IAAAA,IAAI,EAAE,+BADM;AAEZC,IAAAA,MAAM,EAAE,IAFI;AAGZC,IAAAA,IAAI,EAAE;AACJL,MAAAA,KAAK,EAALA;AADI;AAHM,GAAd,CADwB;AAAA,CAAnB;;;;AASA,IAAMM,UAAU,GAAG,SAAbA,UAAa,CAACC,IAAD,EAAOP,KAAP;AAAA,SACxBC,cAAOC,MAAP,CAAc;AACZC,IAAAA,IAAI,EAAE,mBADM;AAEZC,IAAAA,MAAM,EAAE,IAFI;AAGZC,IAAAA,IAAI,EAAE;AACJL,MAAAA,KAAK,EAALA,KADI;AAEJQ,MAAAA,UAAU,EAAED,IAAI,CAACE,OAAL,CAAaD,UAFrB;AAGJE,MAAAA,KAAK,EAAE;AAHH;AAHM,GAAd,CADwB;AAAA,CAAnB;;;;AAWA,IAAMC,UAAU,GAAG,SAAbA,UAAa,CAACX,KAAD;AAAA,SACxBC,cAAOC,MAAP,CAAc;AACZU,IAAAA,MAAM,EAAE,QADI;AAEZT,IAAAA,IAAI,EAAE,iBAFM;AAGZC,IAAAA,MAAM,EAAE,IAHI;AAIZC,IAAAA,IAAI,EAAE;AACJL,MAAAA,KAAK,EAALA;AADI;AAJM,GAAd,CADwB;AAAA,CAAnB;;;;AAUA,IAAMa,iBAAiB,GAAG,SAApBA,iBAAoB,CAACN,IAAD,EAAOP,KAAP,EAAiB;AAChD,UAAQO,IAAI,CAACJ,IAAb;AACE,SAAK,+BAAL;AACE,aAAOJ,UAAU,CAACC,KAAD,CAAjB;;AACF,SAAK,mBAAL;AACE,aAAOM,UAAU,CAACC,IAAD,EAAOP,KAAP,CAAjB;;AACF;AACE;AACA,aAAOW,UAAU,CAACX,KAAD,CAAjB;AAPJ;AASD,CAVM","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"],"file":"utils.js"}
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
4
5
|
Object.defineProperty(exports, "__esModule", {
|
|
5
6
|
value: true
|
|
6
7
|
});
|
|
7
8
|
exports.RemoveTable = exports.RemoveRow = exports.RemoveColumn = exports.AddRow = exports.AddColumn = void 0;
|
|
9
|
+
|
|
8
10
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
11
|
+
|
|
9
12
|
var _react = _interopRequireDefault(require("react"));
|
|
13
|
+
|
|
10
14
|
var _styles = require("@material-ui/core/styles");
|
|
15
|
+
|
|
11
16
|
var styles = {
|
|
12
17
|
icon: {
|
|
13
18
|
fill: 'grey',
|
|
@@ -16,6 +21,7 @@ var styles = {
|
|
|
16
21
|
}
|
|
17
22
|
}
|
|
18
23
|
};
|
|
24
|
+
|
|
19
25
|
var SvgIcon = function SvgIcon(Component) {
|
|
20
26
|
return (0, _styles.withStyles)(styles)(function (props) {
|
|
21
27
|
return /*#__PURE__*/_react["default"].createElement("svg", {
|
|
@@ -29,6 +35,7 @@ var SvgIcon = function SvgIcon(Component) {
|
|
|
29
35
|
}));
|
|
30
36
|
});
|
|
31
37
|
};
|
|
38
|
+
|
|
32
39
|
var AddRow = SvgIcon(function (props) {
|
|
33
40
|
return /*#__PURE__*/_react["default"].createElement("path", (0, _extends2["default"])({}, props, {
|
|
34
41
|
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,"sources":["../../../../src/plugins/table/icons/index.jsx"],"names":["styles","icon","fill","SvgIcon","Component","props","classes","AddRow","RemoveRow","AddColumn","RemoveColumn","RemoveTable"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAEA,IAAMA,MAAM,GAAG;AACbC,EAAAA,IAAI,EAAE;AACJC,IAAAA,IAAI,EAAE,MADF;AAEJ,eAAW;AACTA,MAAAA,IAAI,EAAE;AADG;AAFP;AADO,CAAf;;AASA,IAAMC,OAAO,GAAG,SAAVA,OAAU,CAACC,SAAD,EAAe;AAC7B,SAAO,wBAAWJ,MAAX,EAAmB,UAACK,KAAD;AAAA,wBACxB;AAAK,MAAA,KAAK,EAAC,4BAAX;AAAwC,MAAA,OAAO,EAAC,KAAhD;AAAsD,MAAA,KAAK,EAAC,IAA5D;AAAiE,MAAA,MAAM,EAAC,IAAxE;AAA6E,MAAA,OAAO,EAAC;AAArF,oBACE,gCAAC,SAAD;AAAW,MAAA,SAAS,EAAEA,KAAK,CAACC,OAAN,CAAcL;AAApC,MADF,CADwB;AAAA,GAAnB,CAAP;AAKD,CAND;;AAOO,IAAMM,MAAM,GAAGJ,OAAO,CAAC,UAACE,KAAD;AAAA,sBAC5B,sEACMA,KADN;AAEE,IAAA,CAAC,EAAC;AAFJ,KAD4B;AAAA,CAAD,CAAtB;;AAOA,IAAMG,SAAS,GAAGL,OAAO,CAAC,UAACE,KAAD;AAAA,sBAC/B,sEACMA,KADN;AAEE,IAAA,CAAC,EAAC;AAFJ,KAD+B;AAAA,CAAD,CAAzB;;AAOA,IAAMI,SAAS,GAAGN,OAAO,CAAC,UAACE,KAAD;AAAA,sBAC/B,sEACMA,KADN;AAEE,IAAA,CAAC,EAAC;AAFJ,KAD+B;AAAA,CAAD,CAAzB;;AAOA,IAAMK,YAAY,GAAGP,OAAO,CAAC,UAACE,KAAD;AAAA,sBAClC,sEACMA,KADN;AAEE,IAAA,CAAC,EAAC;AAFJ,KADkC;AAAA,CAAD,CAA5B;;AAOA,IAAMM,WAAW,GAAGR,OAAO,CAAC,UAACE,KAAD;AAAA,sBACjC,sEACMA,KADN;AAEE,IAAA,CAAC,EAAC;AAFJ,KADiC;AAAA,CAAD,CAA3B","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"],"file":"index.js"}
|
|
@@ -1,25 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
4
5
|
Object.defineProperty(exports, "__esModule", {
|
|
5
6
|
value: true
|
|
6
7
|
});
|
|
7
8
|
exports.serialization = exports.reactAttributes = exports.parseStyleString = exports.moveFocusToBeginningOfTable = exports["default"] = void 0;
|
|
9
|
+
|
|
8
10
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
9
12
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
13
|
+
|
|
10
14
|
var _react = _interopRequireDefault(require("react"));
|
|
15
|
+
|
|
11
16
|
var _slateEditTable = _interopRequireDefault(require("slate-edit-table"));
|
|
17
|
+
|
|
12
18
|
var _slate = require("slate");
|
|
19
|
+
|
|
13
20
|
var _debug = _interopRequireDefault(require("debug"));
|
|
21
|
+
|
|
14
22
|
var _GridOn = _interopRequireDefault(require("@material-ui/icons/GridOn"));
|
|
23
|
+
|
|
15
24
|
var _tableToolbar = _interopRequireDefault(require("./table-toolbar"));
|
|
25
|
+
|
|
16
26
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
27
|
+
|
|
17
28
|
var _slatePropTypes = _interopRequireDefault(require("slate-prop-types"));
|
|
29
|
+
|
|
18
30
|
var _styles = require("@material-ui/core/styles");
|
|
31
|
+
|
|
19
32
|
var _reactAttrConverter = _interopRequireDefault(require("react-attr-converter"));
|
|
33
|
+
|
|
20
34
|
var _toStyle = require("to-style");
|
|
35
|
+
|
|
21
36
|
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
|
+
|
|
22
38
|
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
|
+
|
|
23
40
|
var log = (0, _debug["default"])('@pie-lib:editable-html:plugins:table');
|
|
24
41
|
var Table = (0, _styles.withStyles)(function () {
|
|
25
42
|
return {
|
|
@@ -41,9 +58,11 @@ Table.propTypes = {
|
|
|
41
58
|
node: _slatePropTypes["default"].node,
|
|
42
59
|
children: _propTypes["default"].oneOfType([_propTypes["default"].arrayOf(_propTypes["default"].node), _propTypes["default"].node]).isRequired
|
|
43
60
|
};
|
|
61
|
+
|
|
44
62
|
var TableRow = function TableRow(props) {
|
|
45
63
|
return /*#__PURE__*/_react["default"].createElement("tr", props.attributes, props.children);
|
|
46
64
|
};
|
|
65
|
+
|
|
47
66
|
TableRow.propTypes = {
|
|
48
67
|
attributes: _propTypes["default"].object,
|
|
49
68
|
onFocus: _propTypes["default"].func,
|
|
@@ -73,41 +92,49 @@ TableCell.propTypes = {
|
|
|
73
92
|
onBlur: _propTypes["default"].func,
|
|
74
93
|
children: _propTypes["default"].oneOfType([_propTypes["default"].arrayOf(_propTypes["default"].node), _propTypes["default"].node]).isRequired
|
|
75
94
|
};
|
|
95
|
+
|
|
76
96
|
var moveFocusToBeginningOfTable = function moveFocusToBeginningOfTable(change) {
|
|
77
97
|
var addedTable = change.value.document.findDescendant(function (d) {
|
|
78
98
|
return !!d.data && !!d.data.get('newTable');
|
|
79
99
|
});
|
|
100
|
+
|
|
80
101
|
if (!addedTable) {
|
|
81
102
|
return;
|
|
82
103
|
}
|
|
104
|
+
|
|
83
105
|
change.collapseToStartOf(addedTable);
|
|
84
106
|
var update = addedTable.data.remove('newTable');
|
|
85
107
|
change.setNodeByKey(addedTable.key, {
|
|
86
108
|
data: update
|
|
87
109
|
});
|
|
88
110
|
};
|
|
111
|
+
|
|
89
112
|
exports.moveFocusToBeginningOfTable = moveFocusToBeginningOfTable;
|
|
90
|
-
|
|
113
|
+
|
|
114
|
+
var _default = function _default(opts, toolbarPlugins
|
|
115
|
+
/* : {toolbar: {}}[] */
|
|
116
|
+
) {
|
|
91
117
|
var core = (0, _slateEditTable["default"])({
|
|
92
118
|
typeContent: 'div'
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
// fix outdated schema
|
|
119
|
+
}); // fix outdated schema
|
|
96
120
|
|
|
97
121
|
if (core.schema && core.schema.blocks) {
|
|
98
122
|
Object.keys(core.schema.blocks).forEach(function (key) {
|
|
99
123
|
var block = core.schema.blocks[key];
|
|
124
|
+
|
|
100
125
|
if (block.parent) {
|
|
101
126
|
if (block.nodes[0].types) {
|
|
102
127
|
block.nodes[0] = {
|
|
103
128
|
type: block.nodes[0].types[0]
|
|
104
129
|
};
|
|
105
130
|
}
|
|
131
|
+
|
|
106
132
|
if (block.nodes[0].objects) {
|
|
107
133
|
block.nodes[0] = {
|
|
108
134
|
object: block.nodes[0].objects[0]
|
|
109
135
|
};
|
|
110
136
|
}
|
|
137
|
+
|
|
111
138
|
block.parent = {
|
|
112
139
|
type: block.parent.types[0]
|
|
113
140
|
};
|
|
@@ -118,6 +145,7 @@ var _default = function _default(opts, toolbarPlugins /* : {toolbar: {}}[] */)
|
|
|
118
145
|
}
|
|
119
146
|
});
|
|
120
147
|
}
|
|
148
|
+
|
|
121
149
|
core.utils.getTableBlock = function (containerNode, key) {
|
|
122
150
|
var node = containerNode.getDescendant(key);
|
|
123
151
|
var ancestors = containerNode.getAncestors(key).push(node);
|
|
@@ -125,11 +153,15 @@ var _default = function _default(opts, toolbarPlugins /* : {toolbar: {}}[] */)
|
|
|
125
153
|
return p.type === 'table';
|
|
126
154
|
});
|
|
127
155
|
};
|
|
156
|
+
|
|
128
157
|
core.utils.createTableWithOptions = function (row, columns, extra) {
|
|
129
158
|
var createdTable = core.utils.createTable(row, columns);
|
|
159
|
+
|
|
130
160
|
var newTable = _slate.Block.create(_objectSpread(_objectSpread({}, createdTable.toJSON()), extra));
|
|
161
|
+
|
|
131
162
|
return newTable;
|
|
132
163
|
};
|
|
164
|
+
|
|
133
165
|
core.toolbar = {
|
|
134
166
|
icon: /*#__PURE__*/_react["default"].createElement(_GridOn["default"], null),
|
|
135
167
|
onClick: function onClick(value, onChange) {
|
|
@@ -148,6 +180,7 @@ var _default = function _default(opts, toolbarPlugins /* : {toolbar: {}}[] */)
|
|
|
148
180
|
supports: function supports(node, value) {
|
|
149
181
|
return node && node.object === 'block' && core.utils.isSelectionInTable(value);
|
|
150
182
|
},
|
|
183
|
+
|
|
151
184
|
/**
|
|
152
185
|
* Note - the node may not be a table node - it may be a node inside a table.
|
|
153
186
|
*/
|
|
@@ -155,29 +188,36 @@ var _default = function _default(opts, toolbarPlugins /* : {toolbar: {}}[] */)
|
|
|
155
188
|
log('[customToolbar] node.data: ', node.data);
|
|
156
189
|
var tableBlock = core.utils.getTableBlock(value.document, node === null || node === void 0 ? void 0 : node.key);
|
|
157
190
|
log('[customToolbar] tableBlock: ', tableBlock);
|
|
191
|
+
|
|
158
192
|
var hasBorder = function hasBorder() {
|
|
159
193
|
return tableBlock.data.get('border') && tableBlock.data.get('border') !== '0';
|
|
160
194
|
};
|
|
195
|
+
|
|
161
196
|
var addRow = function addRow() {
|
|
162
197
|
var change = core.changes.insertRow(value.change());
|
|
163
198
|
onToolbarDone(change, false);
|
|
164
199
|
};
|
|
200
|
+
|
|
165
201
|
var addColumn = function addColumn() {
|
|
166
202
|
var change = core.changes.insertColumn(value.change());
|
|
167
203
|
onToolbarDone(change, false);
|
|
168
204
|
};
|
|
205
|
+
|
|
169
206
|
var removeRow = function removeRow() {
|
|
170
207
|
var change = core.changes.removeRow(value.change());
|
|
171
208
|
onToolbarDone(change, false);
|
|
172
209
|
};
|
|
210
|
+
|
|
173
211
|
var removeColumn = function removeColumn() {
|
|
174
212
|
var change = core.changes.removeColumn(value.change());
|
|
175
213
|
onToolbarDone(change, false);
|
|
176
214
|
};
|
|
215
|
+
|
|
177
216
|
var removeTable = function removeTable() {
|
|
178
217
|
var change = core.changes.removeTable(value.change());
|
|
179
218
|
onToolbarDone(change, false);
|
|
180
219
|
};
|
|
220
|
+
|
|
181
221
|
var toggleBorder = function toggleBorder() {
|
|
182
222
|
var data = tableBlock.data;
|
|
183
223
|
var update = data.set('border', hasBorder() ? '0' : '1');
|
|
@@ -187,10 +227,12 @@ var _default = function _default(opts, toolbarPlugins /* : {toolbar: {}}[] */)
|
|
|
187
227
|
});
|
|
188
228
|
onToolbarDone(change, false);
|
|
189
229
|
};
|
|
230
|
+
|
|
190
231
|
var onDone = function onDone() {
|
|
191
232
|
log('[onDone] call onToolbarDone...');
|
|
192
233
|
onToolbarDone(null, true);
|
|
193
234
|
};
|
|
235
|
+
|
|
194
236
|
var Tb = function Tb() {
|
|
195
237
|
return /*#__PURE__*/_react["default"].createElement(_tableToolbar["default"], {
|
|
196
238
|
plugins: toolbarPlugins,
|
|
@@ -208,9 +250,11 @@ var _default = function _default(opts, toolbarPlugins /* : {toolbar: {}}[] */)
|
|
|
208
250
|
onDone: onDone
|
|
209
251
|
});
|
|
210
252
|
};
|
|
253
|
+
|
|
211
254
|
return Tb;
|
|
212
255
|
}
|
|
213
256
|
};
|
|
257
|
+
|
|
214
258
|
var Node = function Node(props) {
|
|
215
259
|
switch (props.node.type) {
|
|
216
260
|
case 'table':
|
|
@@ -218,71 +262,81 @@ var _default = function _default(opts, toolbarPlugins /* : {toolbar: {}}[] */)
|
|
|
218
262
|
onFocus: opts.onFocus,
|
|
219
263
|
onBlur: opts.onBlur
|
|
220
264
|
}));
|
|
265
|
+
|
|
221
266
|
case 'table_row':
|
|
222
267
|
return /*#__PURE__*/_react["default"].createElement(TableRow, props);
|
|
268
|
+
|
|
223
269
|
case 'table_cell':
|
|
224
270
|
return /*#__PURE__*/_react["default"].createElement(TableCell, (0, _extends2["default"])({}, props, {
|
|
225
271
|
onFocus: opts.onFocus,
|
|
226
272
|
onBlur: opts.onBlur
|
|
227
273
|
}));
|
|
274
|
+
|
|
228
275
|
default:
|
|
229
276
|
return null;
|
|
230
277
|
}
|
|
231
278
|
};
|
|
279
|
+
|
|
232
280
|
Node.propTypes = {
|
|
233
281
|
node: _propTypes["default"].object
|
|
234
282
|
};
|
|
283
|
+
|
|
235
284
|
core.normalizeNode = function (node) {
|
|
236
285
|
if (node.object !== 'document') {
|
|
237
286
|
return;
|
|
238
287
|
}
|
|
288
|
+
|
|
239
289
|
var tableAdded = node.findDescendant(function (d) {
|
|
240
290
|
return d.data && d.data.get('newTable');
|
|
241
291
|
});
|
|
292
|
+
|
|
242
293
|
if (!tableAdded) {
|
|
243
294
|
return;
|
|
244
295
|
}
|
|
296
|
+
|
|
245
297
|
var nodeToSearch = node.getParent(tableAdded.key) || node;
|
|
246
298
|
var shouldAddTextAfterNode = false;
|
|
247
299
|
var indexToNotHaveTableOn = nodeToSearch.nodes.size - 1;
|
|
248
300
|
var indexOfLastTable = nodeToSearch.nodes.findLastIndex(function (d) {
|
|
249
301
|
return d.type === 'table';
|
|
250
|
-
});
|
|
302
|
+
}); // if the last table in the document is of type table, we need to do the change
|
|
251
303
|
|
|
252
|
-
// if the last table in the document is of type table, we need to do the change
|
|
253
304
|
if (indexOfLastTable === indexToNotHaveTableOn) {
|
|
254
305
|
shouldAddTextAfterNode = true;
|
|
255
306
|
}
|
|
307
|
+
|
|
256
308
|
if (!shouldAddTextAfterNode) {
|
|
257
309
|
return;
|
|
258
310
|
}
|
|
311
|
+
|
|
259
312
|
return function (change) {
|
|
260
313
|
if (shouldAddTextAfterNode) {
|
|
261
|
-
var tableJSON = tableAdded.toJSON();
|
|
262
|
-
|
|
263
|
-
// we remove the table node because otherwise we can't add the empty block after it
|
|
314
|
+
var tableJSON = tableAdded.toJSON(); // we remove the table node because otherwise we can't add the empty block after it
|
|
264
315
|
// we need a block that contains text in order to do it
|
|
316
|
+
|
|
265
317
|
change.removeNodeByKey(tableAdded.key);
|
|
318
|
+
|
|
266
319
|
var newBlock = _slate.Block.create({
|
|
267
320
|
object: 'block',
|
|
268
321
|
type: 'div'
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
// we add an empty block but that it's going to be normalized
|
|
322
|
+
}); // we add an empty block but that it's going to be normalized
|
|
272
323
|
// because it will add the empty text to it like it should
|
|
324
|
+
|
|
325
|
+
|
|
273
326
|
change.insertBlock(newBlock);
|
|
274
327
|
change.withoutNormalization(function () {
|
|
275
328
|
// we do these changes without normalization
|
|
276
|
-
|
|
277
329
|
// we get the text previous to the new block added
|
|
278
330
|
var prevText = change.value.document.getPreviousText(newBlock.key);
|
|
331
|
+
|
|
279
332
|
if (prevText) {
|
|
280
333
|
var _prevText$text, _prevText$text2;
|
|
334
|
+
|
|
281
335
|
// we move focus to the previous text
|
|
282
336
|
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);
|
|
283
|
-
}
|
|
337
|
+
} // we insert the table block between the first block with text and the last block with text
|
|
338
|
+
|
|
284
339
|
|
|
285
|
-
// we insert the table block between the first block with text and the last block with text
|
|
286
340
|
change.insertBlock(_objectSpread(_objectSpread({}, tableJSON), {}, {
|
|
287
341
|
data: _objectSpread(_objectSpread({}, tableJSON.data), {}, {
|
|
288
342
|
newTable: true
|
|
@@ -293,30 +347,40 @@ var _default = function _default(opts, toolbarPlugins /* : {toolbar: {}}[] */)
|
|
|
293
347
|
}
|
|
294
348
|
};
|
|
295
349
|
};
|
|
350
|
+
|
|
296
351
|
core.renderNode = Node;
|
|
297
352
|
return core;
|
|
298
353
|
};
|
|
354
|
+
|
|
299
355
|
exports["default"] = _default;
|
|
356
|
+
|
|
300
357
|
var parseStyleString = function parseStyleString(s) {
|
|
301
358
|
var regex = /([\w-]*)\s*:\s*([^;]*)/g;
|
|
302
359
|
var match;
|
|
303
360
|
var result = {};
|
|
361
|
+
|
|
304
362
|
while (match = regex.exec(s)) {
|
|
305
363
|
result[match[1]] = match[2].trim();
|
|
306
364
|
}
|
|
365
|
+
|
|
307
366
|
return result;
|
|
308
367
|
};
|
|
368
|
+
|
|
309
369
|
exports.parseStyleString = parseStyleString;
|
|
370
|
+
|
|
310
371
|
var reactAttributes = function reactAttributes(o) {
|
|
311
372
|
return (0, _toStyle.object)(o, {
|
|
312
373
|
camelize: true,
|
|
313
374
|
addUnits: false
|
|
314
375
|
});
|
|
315
376
|
};
|
|
377
|
+
|
|
316
378
|
exports.reactAttributes = reactAttributes;
|
|
379
|
+
|
|
317
380
|
var attributesToMap = function attributesToMap(el) {
|
|
318
381
|
return function (acc, attribute) {
|
|
319
382
|
var value = el.getAttribute(attribute);
|
|
383
|
+
|
|
320
384
|
if (value) {
|
|
321
385
|
if (attribute === 'style') {
|
|
322
386
|
var styleString = el.getAttribute(attribute);
|
|
@@ -326,25 +390,31 @@ var attributesToMap = function attributesToMap(el) {
|
|
|
326
390
|
acc[attribute] = el.getAttribute(attribute);
|
|
327
391
|
}
|
|
328
392
|
}
|
|
393
|
+
|
|
329
394
|
return acc;
|
|
330
395
|
};
|
|
331
396
|
};
|
|
397
|
+
|
|
332
398
|
var dataToAttributes = function dataToAttributes(data) {
|
|
333
399
|
if (!data || !data.get) {
|
|
334
400
|
return {};
|
|
335
401
|
}
|
|
402
|
+
|
|
336
403
|
return data.reduce(function (acc, v, name) {
|
|
337
404
|
if (v) {
|
|
338
405
|
acc[(0, _reactAttrConverter["default"])(name)] = v;
|
|
339
406
|
}
|
|
407
|
+
|
|
340
408
|
return acc;
|
|
341
409
|
}, {});
|
|
342
410
|
};
|
|
411
|
+
|
|
343
412
|
var attributes = ['border', 'cellpadding', 'cellspacing', 'class', 'style'];
|
|
344
413
|
var cellAttributes = ['colspan', 'rowspan', 'class', 'style'];
|
|
345
414
|
var serialization = {
|
|
346
415
|
deserialize: function deserialize(el, next) {
|
|
347
416
|
var tag = el.tagName.toLowerCase();
|
|
417
|
+
|
|
348
418
|
switch (tag) {
|
|
349
419
|
case 'table':
|
|
350
420
|
{
|
|
@@ -357,6 +427,7 @@ var serialization = {
|
|
|
357
427
|
data: attributes.reduce(attributesToMap(el), {})
|
|
358
428
|
};
|
|
359
429
|
}
|
|
430
|
+
|
|
360
431
|
case 'th':
|
|
361
432
|
{
|
|
362
433
|
return {
|
|
@@ -368,6 +439,7 @@ var serialization = {
|
|
|
368
439
|
})
|
|
369
440
|
};
|
|
370
441
|
}
|
|
442
|
+
|
|
371
443
|
case 'tr':
|
|
372
444
|
{
|
|
373
445
|
return {
|
|
@@ -376,6 +448,7 @@ var serialization = {
|
|
|
376
448
|
nodes: next(Array.from(el.children))
|
|
377
449
|
};
|
|
378
450
|
}
|
|
451
|
+
|
|
379
452
|
case 'td':
|
|
380
453
|
{
|
|
381
454
|
return {
|
|
@@ -393,20 +466,26 @@ var serialization = {
|
|
|
393
466
|
if (object.object !== 'block') {
|
|
394
467
|
return;
|
|
395
468
|
}
|
|
469
|
+
|
|
396
470
|
switch (object.type) {
|
|
397
471
|
case 'table':
|
|
398
472
|
{
|
|
399
473
|
var _attributes = dataToAttributes(object.data);
|
|
474
|
+
|
|
400
475
|
return /*#__PURE__*/_react["default"].createElement("table", _attributes, /*#__PURE__*/_react["default"].createElement("tbody", null, children));
|
|
401
476
|
}
|
|
477
|
+
|
|
402
478
|
case 'table_row':
|
|
403
479
|
{
|
|
404
480
|
return /*#__PURE__*/_react["default"].createElement("tr", null, children);
|
|
405
481
|
}
|
|
482
|
+
|
|
406
483
|
case 'table_cell':
|
|
407
484
|
{
|
|
408
485
|
var _attributes2 = dataToAttributes(object.data);
|
|
486
|
+
|
|
409
487
|
delete _attributes2.header;
|
|
488
|
+
|
|
410
489
|
if (object.data.get('header')) {
|
|
411
490
|
return /*#__PURE__*/_react["default"].createElement("th", _attributes2, children);
|
|
412
491
|
} else {
|