@pie-lib/mask-markup 3.1.6-beta.2 → 4.0.0-next.20261002094057
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/dist/_virtual/_rolldown/runtime.js +4 -0
- package/dist/choices/choice.d.ts +28 -0
- package/dist/choices/choice.js +92 -0
- package/dist/choices/index.d.ts +29 -0
- package/dist/choices/index.js +59 -0
- package/dist/componentize.d.ts +12 -0
- package/dist/componentize.js +4 -0
- package/dist/components/blank.d.ts +45 -0
- package/dist/components/blank.js +273 -0
- package/dist/components/dropdown.d.ts +37 -0
- package/dist/components/dropdown.js +311 -0
- package/dist/constructed-response.d.ts +44 -0
- package/dist/constructed-response.js +56 -0
- package/dist/customizable.d.ts +43 -0
- package/dist/customizable.js +8 -0
- package/dist/drag-in-the-blank.d.ts +47 -0
- package/dist/drag-in-the-blank.js +220 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +7 -0
- package/dist/inline-dropdown.d.ts +44 -0
- package/dist/inline-dropdown.js +24 -0
- package/dist/keyboard-coordinates.d.ts +25 -0
- package/dist/keyboard-coordinates.js +49 -0
- package/dist/mask.d.ts +30 -0
- package/dist/mask.js +95 -0
- package/dist/node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.js +16 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/index.js +17 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/cssPrefix.js +9 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/cssUnitless.js +26 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/hasOwn.js +11 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/isFunction.js +11 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/isObject.js +11 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/prefixInfo.js +24 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/prefixProperties.js +32 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/prefixer.js +29 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/camelize.js +14 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/hyphenRe.js +8 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/hyphenate.js +12 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/separate.js +11 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/toLowerFirst.js +10 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/toUpperFirst.js +10 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/toStyleObject.js +55 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/toStyleString.js +16 -0
- package/dist/serialization.d.ts +34 -0
- package/dist/serialization.js +132 -0
- package/dist/with-mask.d.ts +55 -0
- package/dist/with-mask.js +45 -0
- package/package.json +35 -19
- package/CHANGELOG.json +0 -17
- package/CHANGELOG.md +0 -1256
- package/lib/choices/choice.js +0 -120
- package/lib/choices/choice.js.map +0 -1
- package/lib/choices/index.js +0 -103
- package/lib/choices/index.js.map +0 -1
- package/lib/componentize.js +0 -21
- package/lib/componentize.js.map +0 -1
- package/lib/components/blank.js +0 -412
- package/lib/components/blank.js.map +0 -1
- package/lib/components/correct-input.js +0 -94
- package/lib/components/correct-input.js.map +0 -1
- package/lib/components/dropdown.js +0 -483
- package/lib/components/dropdown.js.map +0 -1
- package/lib/components/input.js +0 -50
- package/lib/components/input.js.map +0 -1
- package/lib/constructed-response.js +0 -101
- package/lib/constructed-response.js.map +0 -1
- package/lib/customizable.js +0 -42
- package/lib/customizable.js.map +0 -1
- package/lib/drag-in-the-blank.js +0 -254
- package/lib/drag-in-the-blank.js.map +0 -1
- package/lib/index.js +0 -55
- package/lib/index.js.map +0 -1
- package/lib/inline-dropdown.js +0 -40
- package/lib/inline-dropdown.js.map +0 -1
- package/lib/keyboard-coordinates.js +0 -156
- package/lib/mask.js +0 -198
- package/lib/mask.js.map +0 -1
- package/lib/serialization.js +0 -261
- package/lib/serialization.js.map +0 -1
- package/lib/with-mask.js +0 -97
- package/lib/with-mask.js.map +0 -1
- package/src/choices/choice.jsx +0 -100
- package/src/choices/index.jsx +0 -64
- package/src/componentize.js +0 -13
- package/src/components/blank.jsx +0 -431
- package/src/components/correct-input.jsx +0 -82
- package/src/components/dropdown.jsx +0 -423
- package/src/components/input.jsx +0 -48
- package/src/constructed-response.jsx +0 -87
- package/src/customizable.jsx +0 -34
- package/src/drag-in-the-blank.jsx +0 -241
- package/src/index.js +0 -16
- package/src/inline-dropdown.jsx +0 -29
- package/src/mask.jsx +0 -172
- package/src/serialization.js +0 -260
- package/src/with-mask.jsx +0 -75
package/lib/serialization.js
DELETED
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.reactAttributes = exports.parseStyleString = exports.deserialize = exports.MARK_TAGS = void 0;
|
|
8
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
10
|
-
var _toStyle = require("to-style");
|
|
11
|
-
var _debug = _interopRequireDefault(require("debug"));
|
|
12
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
13
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
14
|
-
var log = (0, _debug["default"])('@pie-lib:mask-markup:serialization');
|
|
15
|
-
var INLINE = ['span'];
|
|
16
|
-
var MARK = ['em', 'strong', 'u'];
|
|
17
|
-
var TEXT_NODE = 3;
|
|
18
|
-
var COMMENT_NODE = 8;
|
|
19
|
-
var ELEMENT_NODE = 1;
|
|
20
|
-
var attr = function attr(el) {
|
|
21
|
-
if (!el.attributes || el.attributes.length <= 0) {
|
|
22
|
-
return undefined;
|
|
23
|
-
}
|
|
24
|
-
var out = {};
|
|
25
|
-
var i;
|
|
26
|
-
for (i = 0; i < el.attributes.length; i++) {
|
|
27
|
-
var a = el.attributes[i];
|
|
28
|
-
out[a.name] = a.value;
|
|
29
|
-
}
|
|
30
|
-
return out;
|
|
31
|
-
};
|
|
32
|
-
var getObject = function getObject(type) {
|
|
33
|
-
if (INLINE.includes(type)) {
|
|
34
|
-
return 'inline';
|
|
35
|
-
} else if (MARK.includes(type)) {
|
|
36
|
-
return 'mark';
|
|
37
|
-
}
|
|
38
|
-
return 'block';
|
|
39
|
-
};
|
|
40
|
-
var parseStyleString = exports.parseStyleString = function parseStyleString(s) {
|
|
41
|
-
var regex = /([\w-]*)\s*:\s*([^;]*)/g;
|
|
42
|
-
var match;
|
|
43
|
-
var result = {};
|
|
44
|
-
while (match = regex.exec(s)) {
|
|
45
|
-
result[match[1]] = match[2].trim();
|
|
46
|
-
}
|
|
47
|
-
return result;
|
|
48
|
-
};
|
|
49
|
-
var reactAttributes = exports.reactAttributes = function reactAttributes(o) {
|
|
50
|
-
return (0, _toStyle.object)(o, {
|
|
51
|
-
camelize: true,
|
|
52
|
-
addUnits: false
|
|
53
|
-
});
|
|
54
|
-
};
|
|
55
|
-
var handleStyles = function handleStyles(el, attribute) {
|
|
56
|
-
var styleString = el.getAttribute(attribute);
|
|
57
|
-
return reactAttributes(parseStyleString(styleString));
|
|
58
|
-
};
|
|
59
|
-
var handleClass = function handleClass(el, acc, attribute) {
|
|
60
|
-
var classNames = el.getAttribute(attribute);
|
|
61
|
-
delete acc["class"];
|
|
62
|
-
return classNames;
|
|
63
|
-
};
|
|
64
|
-
var attributesToMap = function attributesToMap(el) {
|
|
65
|
-
return function (acc, attribute) {
|
|
66
|
-
if (!el.getAttribute) {
|
|
67
|
-
return acc;
|
|
68
|
-
}
|
|
69
|
-
var value = el.getAttribute(attribute);
|
|
70
|
-
if (value) {
|
|
71
|
-
switch (attribute) {
|
|
72
|
-
case 'style':
|
|
73
|
-
acc.style = handleStyles(el, attribute);
|
|
74
|
-
break;
|
|
75
|
-
case 'class':
|
|
76
|
-
acc.className = handleClass(el, acc, attribute);
|
|
77
|
-
break;
|
|
78
|
-
default:
|
|
79
|
-
acc[attribute] = el.getAttribute(attribute);
|
|
80
|
-
break;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return acc;
|
|
84
|
-
};
|
|
85
|
-
};
|
|
86
|
-
var attributes = ['border', 'class', 'style'];
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Tags to marks.
|
|
90
|
-
*
|
|
91
|
-
* @type {Object}
|
|
92
|
-
*/
|
|
93
|
-
|
|
94
|
-
var MARK_TAGS = exports.MARK_TAGS = {
|
|
95
|
-
b: 'bold',
|
|
96
|
-
em: 'italic',
|
|
97
|
-
u: 'underline',
|
|
98
|
-
s: 'strikethrough',
|
|
99
|
-
code: 'code',
|
|
100
|
-
strong: 'strong'
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Recursively process DOM nodes and convert them to Slate JSON format
|
|
105
|
-
*/
|
|
106
|
-
var processNode = function processNode(node) {
|
|
107
|
-
var marks = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
108
|
-
// Skip comment nodes
|
|
109
|
-
if (node.nodeType === COMMENT_NODE) {
|
|
110
|
-
return null;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// Handle text nodes
|
|
114
|
-
if (node.nodeType === TEXT_NODE) {
|
|
115
|
-
var text = node.textContent;
|
|
116
|
-
var leaf = {
|
|
117
|
-
text: text
|
|
118
|
-
};
|
|
119
|
-
if (marks.length > 0) {
|
|
120
|
-
leaf.marks = marks.map(function (m) {
|
|
121
|
-
return {
|
|
122
|
-
type: m,
|
|
123
|
-
data: undefined
|
|
124
|
-
};
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
return {
|
|
128
|
-
object: 'text',
|
|
129
|
-
leaves: [leaf]
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// Handle element nodes
|
|
134
|
-
if (node.nodeType === ELEMENT_NODE) {
|
|
135
|
-
var type = node.tagName.toLowerCase();
|
|
136
|
-
|
|
137
|
-
// Check if this is a mark tag
|
|
138
|
-
var markType = MARK_TAGS[type];
|
|
139
|
-
if (markType) {
|
|
140
|
-
log('[deserialize] mark: ', markType);
|
|
141
|
-
// Process children with this mark added and return them flattened
|
|
142
|
-
var _childNodes = processNodes(node.childNodes, [].concat((0, _toConsumableArray2["default"])(marks), [markType]));
|
|
143
|
-
// Return an array indicator with the nodes (will be flattened by parent)
|
|
144
|
-
return {
|
|
145
|
-
_flatten: true,
|
|
146
|
-
nodes: _childNodes
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// Handle math elements specially
|
|
151
|
-
if (type === 'math') {
|
|
152
|
-
return {
|
|
153
|
-
isMath: true,
|
|
154
|
-
nodes: [node]
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// Process regular elements
|
|
159
|
-
var normalAttrs = attr(node) || {};
|
|
160
|
-
if (type === 'audio' && normalAttrs.controls === '') {
|
|
161
|
-
normalAttrs.controls = true;
|
|
162
|
-
}
|
|
163
|
-
var allAttrs = attributes.reduce(attributesToMap(node), _objectSpread({}, normalAttrs));
|
|
164
|
-
var object = getObject(type);
|
|
165
|
-
var childNodes = processNodes(node.childNodes, marks);
|
|
166
|
-
return {
|
|
167
|
-
object: object,
|
|
168
|
-
type: type,
|
|
169
|
-
data: {
|
|
170
|
-
dataset: _objectSpread({}, node.dataset),
|
|
171
|
-
attributes: _objectSpread({}, allAttrs)
|
|
172
|
-
},
|
|
173
|
-
nodes: childNodes
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
return null;
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Process a NodeList and convert to array of Slate nodes
|
|
181
|
-
*/
|
|
182
|
-
var processNodes = function processNodes(nodeList) {
|
|
183
|
-
var marks = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
184
|
-
var nodes = [];
|
|
185
|
-
for (var i = 0; i < nodeList.length; i++) {
|
|
186
|
-
var result = processNode(nodeList[i], marks);
|
|
187
|
-
if (result !== null) {
|
|
188
|
-
// Handle flattening for mark nodes
|
|
189
|
-
if (result._flatten && result.nodes) {
|
|
190
|
-
nodes.push.apply(nodes, (0, _toConsumableArray2["default"])(result.nodes));
|
|
191
|
-
} else {
|
|
192
|
-
nodes.push(result);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
return nodes;
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Deserialize HTML string to Slate JSON format
|
|
201
|
-
*/
|
|
202
|
-
var deserialize = exports.deserialize = function deserialize(htmlString) {
|
|
203
|
-
// Handle empty or whitespace-only strings
|
|
204
|
-
if (!htmlString || !htmlString.trim()) {
|
|
205
|
-
return {
|
|
206
|
-
object: 'value',
|
|
207
|
-
document: {
|
|
208
|
-
object: 'document',
|
|
209
|
-
data: {},
|
|
210
|
-
nodes: [{
|
|
211
|
-
object: 'block',
|
|
212
|
-
type: 'span',
|
|
213
|
-
data: {},
|
|
214
|
-
isVoid: false,
|
|
215
|
-
nodes: []
|
|
216
|
-
}]
|
|
217
|
-
}
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// Use DOMParser to parse the HTML
|
|
222
|
-
var parser = new DOMParser();
|
|
223
|
-
var doc = parser.parseFromString(htmlString, 'text/html');
|
|
224
|
-
|
|
225
|
-
// Process all nodes in the body
|
|
226
|
-
var nodes = processNodes(doc.body.childNodes);
|
|
227
|
-
|
|
228
|
-
// If we only have text nodes (no block elements), wrap in default span block
|
|
229
|
-
var hasBlockElements = nodes.some(function (node) {
|
|
230
|
-
return node.object === 'block' || node.object === 'inline';
|
|
231
|
-
});
|
|
232
|
-
if (!hasBlockElements && nodes.length > 0) {
|
|
233
|
-
nodes = [{
|
|
234
|
-
object: 'block',
|
|
235
|
-
type: 'span',
|
|
236
|
-
data: {},
|
|
237
|
-
isVoid: false,
|
|
238
|
-
nodes: nodes
|
|
239
|
-
}];
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
// If no nodes were produced, add a default span block
|
|
243
|
-
if (nodes.length === 0) {
|
|
244
|
-
nodes = [{
|
|
245
|
-
object: 'block',
|
|
246
|
-
type: 'span',
|
|
247
|
-
data: {},
|
|
248
|
-
isVoid: false,
|
|
249
|
-
nodes: []
|
|
250
|
-
}];
|
|
251
|
-
}
|
|
252
|
-
return {
|
|
253
|
-
object: 'value',
|
|
254
|
-
document: {
|
|
255
|
-
object: 'document',
|
|
256
|
-
data: {},
|
|
257
|
-
nodes: nodes
|
|
258
|
-
}
|
|
259
|
-
};
|
|
260
|
-
};
|
|
261
|
-
//# sourceMappingURL=serialization.js.map
|
package/lib/serialization.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"serialization.js","names":["_toStyle","require","_debug","_interopRequireDefault","ownKeys","e","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty2","getOwnPropertyDescriptors","defineProperties","defineProperty","log","debug","INLINE","MARK","TEXT_NODE","COMMENT_NODE","ELEMENT_NODE","attr","el","attributes","undefined","out","i","a","name","value","getObject","type","includes","parseStyleString","exports","s","regex","match","result","exec","trim","reactAttributes","toStyleObject","camelize","addUnits","handleStyles","attribute","styleString","getAttribute","handleClass","acc","classNames","attributesToMap","style","className","MARK_TAGS","b","em","u","code","strong","processNode","node","marks","nodeType","text","textContent","leaf","map","m","data","object","leaves","tagName","toLowerCase","markType","childNodes","processNodes","concat","_toConsumableArray2","_flatten","nodes","isMath","normalAttrs","controls","allAttrs","reduce","dataset","nodeList","deserialize","htmlString","document","isVoid","parser","DOMParser","doc","parseFromString","body","hasBlockElements","some"],"sources":["../src/serialization.js"],"sourcesContent":["import { object as toStyleObject } from 'to-style';\nimport debug from 'debug';\n\nconst log = debug('@pie-lib:mask-markup:serialization');\n\nconst INLINE = ['span'];\nconst MARK = ['em', 'strong', 'u'];\nconst TEXT_NODE = 3;\nconst COMMENT_NODE = 8;\nconst ELEMENT_NODE = 1;\n\nconst attr = (el) => {\n if (!el.attributes || el.attributes.length <= 0) {\n return undefined;\n }\n\n const out = {};\n let i;\n\n for (i = 0; i < el.attributes.length; i++) {\n const a = el.attributes[i];\n\n out[a.name] = a.value;\n }\n\n return out;\n};\n\nconst getObject = (type) => {\n if (INLINE.includes(type)) {\n return 'inline';\n } else if (MARK.includes(type)) {\n return 'mark';\n }\n return 'block';\n};\n\nexport const parseStyleString = (s) => {\n const regex = /([\\w-]*)\\s*:\\s*([^;]*)/g;\n let match;\n const result = {};\n while ((match = regex.exec(s))) {\n result[match[1]] = match[2].trim();\n }\n return result;\n};\n\nexport const reactAttributes = (o) => toStyleObject(o, { camelize: true, addUnits: false });\n\nconst handleStyles = (el, attribute) => {\n const styleString = el.getAttribute(attribute);\n\n return reactAttributes(parseStyleString(styleString));\n};\n\nconst handleClass = (el, acc, attribute) => {\n const classNames = el.getAttribute(attribute);\n\n delete acc.class;\n\n return classNames;\n};\n\nconst attributesToMap = (el) => (acc, attribute) => {\n if (!el.getAttribute) {\n return acc;\n }\n\n const value = el.getAttribute(attribute);\n\n if (value) {\n switch (attribute) {\n case 'style':\n acc.style = handleStyles(el, attribute);\n break;\n case 'class':\n acc.className = handleClass(el, acc, attribute);\n break;\n default:\n acc[attribute] = el.getAttribute(attribute);\n break;\n }\n }\n\n return acc;\n};\n\nconst attributes = ['border', 'class', 'style'];\n\n/**\n * Tags to marks.\n *\n * @type {Object}\n */\n\nexport const MARK_TAGS = {\n b: 'bold',\n em: 'italic',\n u: 'underline',\n s: 'strikethrough',\n code: 'code',\n strong: 'strong',\n};\n\n/**\n * Recursively process DOM nodes and convert them to Slate JSON format\n */\nconst processNode = (node, marks = []) => {\n // Skip comment nodes\n if (node.nodeType === COMMENT_NODE) {\n return null;\n }\n\n // Handle text nodes\n if (node.nodeType === TEXT_NODE) {\n const text = node.textContent;\n const leaf = { text };\n\n if (marks.length > 0) {\n leaf.marks = marks.map((m) => ({ type: m, data: undefined }));\n }\n\n return {\n object: 'text',\n leaves: [leaf],\n };\n }\n\n // Handle element nodes\n if (node.nodeType === ELEMENT_NODE) {\n const type = node.tagName.toLowerCase();\n\n // Check if this is a mark tag\n const markType = MARK_TAGS[type];\n if (markType) {\n log('[deserialize] mark: ', markType);\n // Process children with this mark added and return them flattened\n const childNodes = processNodes(node.childNodes, [...marks, markType]);\n // Return an array indicator with the nodes (will be flattened by parent)\n return { _flatten: true, nodes: childNodes };\n }\n\n // Handle math elements specially\n if (type === 'math') {\n return {\n isMath: true,\n nodes: [node],\n };\n }\n\n // Process regular elements\n const normalAttrs = attr(node) || {};\n\n if (type === 'audio' && normalAttrs.controls === '') {\n normalAttrs.controls = true;\n }\n\n const allAttrs = attributes.reduce(attributesToMap(node), { ...normalAttrs });\n const object = getObject(type);\n\n const childNodes = processNodes(node.childNodes, marks);\n\n return {\n object,\n type,\n data: { dataset: { ...node.dataset }, attributes: { ...allAttrs } },\n nodes: childNodes,\n };\n }\n\n return null;\n};\n\n/**\n * Process a NodeList and convert to array of Slate nodes\n */\nconst processNodes = (nodeList, marks = []) => {\n const nodes = [];\n for (let i = 0; i < nodeList.length; i++) {\n const result = processNode(nodeList[i], marks);\n if (result !== null) {\n // Handle flattening for mark nodes\n if (result._flatten && result.nodes) {\n nodes.push(...result.nodes);\n } else {\n nodes.push(result);\n }\n }\n }\n return nodes;\n};\n\n/**\n * Deserialize HTML string to Slate JSON format\n */\nexport const deserialize = (htmlString) => {\n // Handle empty or whitespace-only strings\n if (!htmlString || !htmlString.trim()) {\n return {\n object: 'value',\n document: {\n object: 'document',\n data: {},\n nodes: [\n {\n object: 'block',\n type: 'span',\n data: {},\n isVoid: false,\n nodes: [],\n },\n ],\n },\n };\n }\n\n // Use DOMParser to parse the HTML\n const parser = new DOMParser();\n const doc = parser.parseFromString(htmlString, 'text/html');\n\n // Process all nodes in the body\n let nodes = processNodes(doc.body.childNodes);\n\n // If we only have text nodes (no block elements), wrap in default span block\n const hasBlockElements = nodes.some((node) => node.object === 'block' || node.object === 'inline');\n\n if (!hasBlockElements && nodes.length > 0) {\n nodes = [\n {\n object: 'block',\n type: 'span',\n data: {},\n isVoid: false,\n nodes: nodes,\n },\n ];\n }\n\n // If no nodes were produced, add a default span block\n if (nodes.length === 0) {\n nodes = [\n {\n object: 'block',\n type: 'span',\n data: {},\n isVoid: false,\n nodes: [],\n },\n ];\n }\n\n return {\n object: 'value',\n document: {\n object: 'document',\n data: {},\n nodes,\n },\n };\n};\n"],"mappings":";;;;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAC,sBAAA,CAAAF,OAAA;AAA0B,SAAAG,QAAAC,CAAA,EAAAC,CAAA,QAAAC,CAAA,GAAAC,MAAA,CAAA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AAI,CAACrB,UAAU,CAAC;;EAE7C;EACA,IAAMsB,gBAAgB,GAAGjB,KAAK,CAACkB,IAAI,CAAC,UAACrC,IAAI;IAAA,OAAKA,IAAI,CAACS,MAAM,KAAK,OAAO,IAAIT,IAAI,CAACS,MAAM,KAAK,QAAQ;EAAA,EAAC;EAElG,IAAI,CAAC2B,gBAAgB,IAAIjB,KAAK,CAACzE,MAAM,GAAG,CAAC,EAAE;IACzCyE,KAAK,GAAG,CACN;MACEV,MAAM,EAAE,OAAO;MACfxC,IAAI,EAAE,MAAM;MACZuC,IAAI,EAAE,CAAC,CAAC;MACRsB,MAAM,EAAE,KAAK;MACbX,KAAK,EAAEA;IACT,CAAC,CACF;EACH;;EAEA;EACA,IAAIA,KAAK,CAACzE,MAAM,KAAK,CAAC,EAAE;IACtByE,KAAK,GAAG,CACN;MACEV,MAAM,EAAE,OAAO;MACfxC,IAAI,EAAE,MAAM;MACZuC,IAAI,EAAE,CAAC,CAAC;MACRsB,MAAM,EAAE,KAAK;MACbX,KAAK,EAAE;IACT,CAAC,CACF;EACH;EAEA,OAAO;IACLV,MAAM,EAAE,OAAO;IACfoB,QAAQ,EAAE;MACRpB,MAAM,EAAE,UAAU;MAClBD,IAAI,EAAE,CAAC,CAAC;MACRW,KAAK,EAALA;IACF;EACF,CAAC;AACH,CAAC","ignoreList":[]}
|
package/lib/with-mask.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.withMask = exports.buildLayoutFromMarkup = void 0;
|
|
8
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
9
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
11
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
12
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
13
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
14
|
-
var _react = _interopRequireDefault(require("react"));
|
|
15
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
16
|
-
var _mask = _interopRequireDefault(require("./mask"));
|
|
17
|
-
var _componentize2 = _interopRequireDefault(require("./componentize"));
|
|
18
|
-
var _serialization = require("./serialization");
|
|
19
|
-
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); }
|
|
20
|
-
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
21
|
-
var buildLayoutFromMarkup = exports.buildLayoutFromMarkup = function buildLayoutFromMarkup(markup, type) {
|
|
22
|
-
var _componentize = (0, _componentize2["default"])(markup, type),
|
|
23
|
-
processed = _componentize.markup;
|
|
24
|
-
var value = (0, _serialization.deserialize)(processed);
|
|
25
|
-
return value.document;
|
|
26
|
-
};
|
|
27
|
-
var withMask = exports.withMask = function withMask(type, renderChildren) {
|
|
28
|
-
var _WithMask;
|
|
29
|
-
return _WithMask = /*#__PURE__*/function (_React$Component) {
|
|
30
|
-
function WithMask(props) {
|
|
31
|
-
var _this;
|
|
32
|
-
(0, _classCallCheck2["default"])(this, WithMask);
|
|
33
|
-
_this = _callSuper(this, WithMask, [props]);
|
|
34
|
-
_this.containerRef = /*#__PURE__*/_react["default"].createRef();
|
|
35
|
-
return _this;
|
|
36
|
-
}
|
|
37
|
-
(0, _inherits2["default"])(WithMask, _React$Component);
|
|
38
|
-
return (0, _createClass2["default"])(WithMask, [{
|
|
39
|
-
key: "componentDidUpdate",
|
|
40
|
-
value: function componentDidUpdate(prevProps) {
|
|
41
|
-
if (this.props.markup !== prevProps.markup) {
|
|
42
|
-
var domNode = this.containerRef.current;
|
|
43
|
-
var mathElements = domNode && domNode.querySelectorAll('[data-latex][data-math-handled="true"]');
|
|
44
|
-
|
|
45
|
-
// Clean up for fresh MathJax processing
|
|
46
|
-
(mathElements || []).forEach(function (el) {
|
|
47
|
-
// Remove the MathJax container to allow for clean updates
|
|
48
|
-
var mjxContainer = el.querySelector('mjx-container');
|
|
49
|
-
if (mjxContainer) {
|
|
50
|
-
el.removeChild(mjxContainer);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Update the innerHTML to match the raw LaTeX data, ensuring it is reprocessed correctly
|
|
54
|
-
var latexCode = el.getAttribute('data-raw');
|
|
55
|
-
el.innerHTML = latexCode;
|
|
56
|
-
|
|
57
|
-
// Remove the attribute to signal that MathJax should reprocess this element
|
|
58
|
-
el.removeAttribute('data-math-handled');
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}, {
|
|
63
|
-
key: "render",
|
|
64
|
-
value: function render() {
|
|
65
|
-
var _this$props = this.props,
|
|
66
|
-
markup = _this$props.markup,
|
|
67
|
-
layout = _this$props.layout,
|
|
68
|
-
value = _this$props.value,
|
|
69
|
-
onChange = _this$props.onChange,
|
|
70
|
-
elementType = _this$props.elementType;
|
|
71
|
-
var maskLayout = layout ? layout : buildLayoutFromMarkup(markup, type);
|
|
72
|
-
return /*#__PURE__*/_react["default"].createElement(_mask["default"], {
|
|
73
|
-
containerRef: this.containerRef,
|
|
74
|
-
elementType: elementType,
|
|
75
|
-
layout: maskLayout,
|
|
76
|
-
value: value,
|
|
77
|
-
onChange: onChange,
|
|
78
|
-
renderChildren: renderChildren(this.props)
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
}]);
|
|
82
|
-
}(_react["default"].Component), (0, _defineProperty2["default"])(_WithMask, "propTypes", {
|
|
83
|
-
/**
|
|
84
|
-
* At the start we'll probably work with markup
|
|
85
|
-
*/
|
|
86
|
-
markup: _propTypes["default"].string,
|
|
87
|
-
/**
|
|
88
|
-
* Once we start authoring, it may make sense for use to us layout, which will be a simple js object that maps to `slate.Value`.
|
|
89
|
-
*/
|
|
90
|
-
layout: _propTypes["default"].object,
|
|
91
|
-
value: _propTypes["default"].object,
|
|
92
|
-
onChange: _propTypes["default"].func,
|
|
93
|
-
customMarkMarkupComponent: _propTypes["default"].func,
|
|
94
|
-
elementType: _propTypes["default"].string
|
|
95
|
-
}), _WithMask;
|
|
96
|
-
};
|
|
97
|
-
//# sourceMappingURL=with-mask.js.map
|
package/lib/with-mask.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"with-mask.js","names":["_react","_interopRequireDefault","require","_propTypes","_mask","_componentize2","_serialization","_callSuper","t","o","e","_getPrototypeOf2","_possibleConstructorReturn2","_isNativeReflectConstruct","Reflect","construct","constructor","apply","Boolean","prototype","valueOf","call","buildLayoutFromMarkup","exports","markup","type","_componentize","componentize","processed","value","deserialize","document","withMask","renderChildren","_WithMask","_React$Component","WithMask","props","_this","_classCallCheck2","containerRef","React","createRef","_inherits2","_createClass2","key","componentDidUpdate","prevProps","domNode","current","mathElements","querySelectorAll","forEach","el","mjxContainer","querySelector","removeChild","latexCode","getAttribute","innerHTML","removeAttribute","render","_this$props","layout","onChange","elementType","maskLayout","createElement","Component","_defineProperty2","PropTypes","string","object","func","customMarkMarkupComponent"],"sources":["../src/with-mask.jsx"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport Mask from './mask';\nimport componentize from './componentize';\nimport { deserialize } from './serialization';\n\nexport const buildLayoutFromMarkup = (markup, type) => {\n const { markup: processed } = componentize(markup, type);\n const value = deserialize(processed);\n return value.document;\n};\n\nexport const withMask = (type, renderChildren) => {\n return class WithMask extends React.Component {\n static propTypes = {\n /**\n * At the start we'll probably work with markup\n */\n markup: PropTypes.string,\n /**\n * Once we start authoring, it may make sense for use to us layout, which will be a simple js object that maps to `slate.Value`.\n */\n layout: PropTypes.object,\n value: PropTypes.object,\n onChange: PropTypes.func,\n customMarkMarkupComponent: PropTypes.func,\n elementType: PropTypes.string,\n };\n\n constructor(props) {\n super(props);\n this.containerRef = React.createRef();\n }\n\n componentDidUpdate(prevProps) {\n if (this.props.markup !== prevProps.markup) {\n const domNode = this.containerRef.current;\n const mathElements = domNode && domNode.querySelectorAll('[data-latex][data-math-handled=\"true\"]');\n\n // Clean up for fresh MathJax processing\n (mathElements || []).forEach((el) => {\n // Remove the MathJax container to allow for clean updates\n const mjxContainer = el.querySelector('mjx-container');\n\n if (mjxContainer) {\n el.removeChild(mjxContainer);\n }\n\n // Update the innerHTML to match the raw LaTeX data, ensuring it is reprocessed correctly\n const latexCode = el.getAttribute('data-raw');\n el.innerHTML = latexCode;\n\n // Remove the attribute to signal that MathJax should reprocess this element\n el.removeAttribute('data-math-handled');\n });\n }\n }\n\n render() {\n const { markup, layout, value, onChange, elementType } = this.props;\n\n const maskLayout = layout ? layout : buildLayoutFromMarkup(markup, type);\n return (\n <Mask\n containerRef={this.containerRef}\n elementType={elementType}\n layout={maskLayout}\n value={value}\n onChange={onChange}\n renderChildren={renderChildren(this.props)}\n />\n );\n }\n };\n};\n"],"mappings":";;;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,KAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,cAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,cAAA,GAAAJ,OAAA;AAA8C,SAAAK,WAAAC,CAAA,EAAAC,CAAA,EAAAC,CAAA,WAAAD,CAAA,O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KAAM;UACbmC,QAAQ,EAAEA,QAAS;UACnB/B,cAAc,EAAEA,cAAc,CAAC,IAAI,CAACI,KAAK;QAAE,CAC5C,CAAC;MAEN;IAAC;EAAA,EA3D2BI,iBAAK,CAAC2B,SAAS,OAAAC,gBAAA,aAAAnC,SAAA,eACxB;IACjB;AACN;AACA;IACMV,MAAM,EAAE8C,qBAAS,CAACC,MAAM;IACxB;AACN;AACA;IACMR,MAAM,EAAEO,qBAAS,CAACE,MAAM;IACxB3C,KAAK,EAAEyC,qBAAS,CAACE,MAAM;IACvBR,QAAQ,EAAEM,qBAAS,CAACG,IAAI;IACxBC,yBAAyB,EAAEJ,qBAAS,CAACG,IAAI;IACzCR,WAAW,EAAEK,qBAAS,CAACC;EACzB,CAAC,GAAArC,SAAA;AA+CL,CAAC","ignoreList":[]}
|
package/src/choices/choice.jsx
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useRef } from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import { useDraggable } from '@dnd-kit/core';
|
|
4
|
-
import { styled } from '@mui/material/styles';
|
|
5
|
-
import Chip from '@mui/material/Chip';
|
|
6
|
-
import { renderMath } from '@pie-lib/math-rendering';
|
|
7
|
-
import { color } from '@pie-lib/render-ui';
|
|
8
|
-
|
|
9
|
-
export const DRAG_TYPE = 'MaskBlank';
|
|
10
|
-
|
|
11
|
-
const StyledChoice = styled('span')(({ theme, disabled }) => ({
|
|
12
|
-
border: `solid 0px ${theme.palette.primary.main}`,
|
|
13
|
-
borderRadius: theme.spacing(2),
|
|
14
|
-
margin: theme.spacing(0.5),
|
|
15
|
-
transform: 'translate(0, 0)',
|
|
16
|
-
display: 'inline-flex',
|
|
17
|
-
...(disabled && {}),
|
|
18
|
-
}));
|
|
19
|
-
|
|
20
|
-
const StyledChip = styled(Chip)(() => ({
|
|
21
|
-
backgroundColor: color.white(),
|
|
22
|
-
border: `1px solid ${color.text()}`,
|
|
23
|
-
color: color.text(),
|
|
24
|
-
alignItems: 'center',
|
|
25
|
-
display: 'inline-flex',
|
|
26
|
-
height: 'initial',
|
|
27
|
-
minHeight: '32px',
|
|
28
|
-
fontSize: 'inherit',
|
|
29
|
-
whiteSpace: 'pre-wrap',
|
|
30
|
-
maxWidth: '374px',
|
|
31
|
-
// Added for touch devices, for image content.
|
|
32
|
-
// This will prevent the context menu from appearing and not allowing other interactions with the image.
|
|
33
|
-
// If interactions with the image in the token will be requested we should handle only the context Menu.
|
|
34
|
-
pointerEvents: 'none',
|
|
35
|
-
borderRadius: '3px',
|
|
36
|
-
paddingTop: '12px',
|
|
37
|
-
paddingBottom: '12px',
|
|
38
|
-
|
|
39
|
-
'&.Mui-disabled': {
|
|
40
|
-
opacity: 1,
|
|
41
|
-
},
|
|
42
|
-
}));
|
|
43
|
-
|
|
44
|
-
const StyledChipLabel = styled('span')(() => ({
|
|
45
|
-
whiteSpace: 'normal',
|
|
46
|
-
'& img': {
|
|
47
|
-
display: 'block',
|
|
48
|
-
padding: '2px 0',
|
|
49
|
-
},
|
|
50
|
-
'& mjx-frac': {
|
|
51
|
-
fontSize: '120% !important',
|
|
52
|
-
},
|
|
53
|
-
'& mjx-mn:has(~ mjx-mfrac), mjx-mfrac ~ mjx-mn': {
|
|
54
|
-
fontSize: '120% !important',
|
|
55
|
-
},
|
|
56
|
-
}));
|
|
57
|
-
|
|
58
|
-
export default function Choice({ choice, disabled, instanceId }) {
|
|
59
|
-
const rootRef = useRef(null);
|
|
60
|
-
|
|
61
|
-
const { attributes, listeners, setNodeRef, isDragging } = useDraggable({
|
|
62
|
-
id: `choice-${choice.id}`,
|
|
63
|
-
data: { choice, instanceId, fromChoice: true, type: DRAG_TYPE },
|
|
64
|
-
disabled,
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
useEffect(() => {
|
|
68
|
-
renderMath(rootRef.current);
|
|
69
|
-
}, [choice.value]);
|
|
70
|
-
|
|
71
|
-
return (
|
|
72
|
-
<StyledChoice
|
|
73
|
-
ref={setNodeRef}
|
|
74
|
-
style={
|
|
75
|
-
isDragging
|
|
76
|
-
? {
|
|
77
|
-
width: rootRef.current?.offsetWidth || 90, // min-width of chip is 90px, so if we don't have the width, we can use 90px as a fallback
|
|
78
|
-
height: rootRef.current?.offsetHeight || 32, // min-height of chip is 32px, so if we don't have the height, we can use 32px as a fallback
|
|
79
|
-
}
|
|
80
|
-
: {}
|
|
81
|
-
}
|
|
82
|
-
disabled={disabled}
|
|
83
|
-
{...listeners}
|
|
84
|
-
{...attributes}
|
|
85
|
-
>
|
|
86
|
-
<StyledChip
|
|
87
|
-
clickable={false}
|
|
88
|
-
disabled={disabled}
|
|
89
|
-
ref={rootRef}
|
|
90
|
-
label={<StyledChipLabel dangerouslySetInnerHTML={{ __html: choice.value }} />}
|
|
91
|
-
/>
|
|
92
|
-
</StyledChoice>
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
Choice.propTypes = {
|
|
97
|
-
choice: PropTypes.object.isRequired,
|
|
98
|
-
disabled: PropTypes.bool,
|
|
99
|
-
instanceId: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
100
|
-
};
|
package/src/choices/index.jsx
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import { findKey } from 'lodash-es';
|
|
4
|
-
import Choice from './choice';
|
|
5
|
-
import { DragDroppablePlaceholder } from '@pie-lib/drag';
|
|
6
|
-
|
|
7
|
-
export default class Choices extends React.Component {
|
|
8
|
-
static propTypes = {
|
|
9
|
-
disabled: PropTypes.bool,
|
|
10
|
-
duplicates: PropTypes.bool,
|
|
11
|
-
choices: PropTypes.arrayOf(PropTypes.shape({ label: PropTypes.string, value: PropTypes.string })),
|
|
12
|
-
value: PropTypes.object,
|
|
13
|
-
choicePosition: PropTypes.string.isRequired,
|
|
14
|
-
instanceId: PropTypes.string, // Added for drag isolation
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
getStyleForWrapper = () => {
|
|
18
|
-
const { choicePosition } = this.props;
|
|
19
|
-
|
|
20
|
-
switch (choicePosition) {
|
|
21
|
-
case 'above':
|
|
22
|
-
return {
|
|
23
|
-
margin: '0 0 40px 0',
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
case 'below':
|
|
27
|
-
return {
|
|
28
|
-
margin: '40px 0 0 0',
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
case 'right':
|
|
32
|
-
return {
|
|
33
|
-
margin: '0 0 0 40px',
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
default:
|
|
37
|
-
return {
|
|
38
|
-
margin: '0 40px 0 0',
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
render() {
|
|
44
|
-
const { disabled, duplicates, choices, value, instanceId } = this.props;
|
|
45
|
-
const filteredChoices = choices.filter((c) => {
|
|
46
|
-
if (duplicates === true) {
|
|
47
|
-
return true;
|
|
48
|
-
}
|
|
49
|
-
const foundChoice = findKey(value, (v) => v === c.id);
|
|
50
|
-
return foundChoice === undefined;
|
|
51
|
-
});
|
|
52
|
-
const elementStyle = { ...this.getStyleForWrapper(), minWidth: '100px' };
|
|
53
|
-
|
|
54
|
-
return (
|
|
55
|
-
<div style={elementStyle}>
|
|
56
|
-
<DragDroppablePlaceholder disabled={disabled} instanceId={instanceId}>
|
|
57
|
-
{filteredChoices.map((c, index) => (
|
|
58
|
-
<Choice key={`${c.value}-${index}`} disabled={disabled} choice={c} instanceId={instanceId} />
|
|
59
|
-
))}
|
|
60
|
-
</DragDroppablePlaceholder>
|
|
61
|
-
</div>
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
}
|
package/src/componentize.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
const REGEX = /\{\{(\d+)\}\}/g;
|
|
2
|
-
|
|
3
|
-
export default (s, t) => {
|
|
4
|
-
if (!s) {
|
|
5
|
-
return { markup: '' };
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
const markup = s.replace(REGEX, (match, g) => {
|
|
9
|
-
return `<span data-component="${t}" data-id="${g}"></span>`;
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
return { markup };
|
|
13
|
-
};
|