@wiris/mathtype-ckeditor5 8.13.3 → 8.13.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/index.js +30 -1
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.umd.js +30 -1
- package/dist/browser/index.umd.js.map +1 -1
- package/dist/index.js +30 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/plugin.js +63 -40
package/src/plugin.js
CHANGED
|
@@ -306,57 +306,80 @@ export default class MathType extends Plugin {
|
|
|
306
306
|
});
|
|
307
307
|
|
|
308
308
|
// Data view -> Model
|
|
309
|
-
editor.data.upcastDispatcher.on(
|
|
310
|
-
|
|
311
|
-
|
|
309
|
+
editor.data.upcastDispatcher.on(
|
|
310
|
+
"element:img",
|
|
311
|
+
(evt, data, conversionApi) => {
|
|
312
|
+
const { consumable, writer } = conversionApi;
|
|
313
|
+
const { viewItem } = data;
|
|
314
|
+
|
|
315
|
+
// Only upcast when is wiris formula
|
|
316
|
+
if (viewItem.getClassNames().next().value !== "Wirisformula") {
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
312
319
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
320
|
+
// The following code ensures that the element's name, attributes, and classes are consumed.
|
|
321
|
+
// This means that they are marked as handled so that other parts of the system or plugins don't process them again.
|
|
317
322
|
|
|
318
|
-
|
|
319
|
-
|
|
323
|
+
// Check if we can consume the element name.
|
|
324
|
+
if (!consumable.test(viewItem, { name: true })) {
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
320
327
|
|
|
321
|
-
|
|
328
|
+
// Consume the name, attributes, and classes so nothing else processes it.
|
|
329
|
+
consumable.consume(viewItem, { name: true });
|
|
330
|
+
for (const attrName of viewItem.getAttributes()) {
|
|
331
|
+
consumable.consume(viewItem, { attributes: [attrName] });
|
|
332
|
+
}
|
|
322
333
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
const splitResult = conversionApi.splitToAllowedParent(modelNode, data.modelCursor);
|
|
334
|
+
for (const className of viewItem.getClassNames()) {
|
|
335
|
+
consumable.consume(viewItem, { classes: [className] });
|
|
336
|
+
}
|
|
327
337
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
return;
|
|
331
|
-
}
|
|
338
|
+
const mathAttributes = [...viewItem.getAttributes()].map(([key, value]) => ` ${key}="${value}"`).join("");
|
|
339
|
+
const htmlContent = Util.htmlSanitize(`<img${mathAttributes}>`);
|
|
332
340
|
|
|
333
|
-
|
|
334
|
-
conversionApi.writer.insert(modelNode, splitResult.position);
|
|
341
|
+
const modelNode = writer.createElement("mathml", { htmlContent });
|
|
335
342
|
|
|
336
|
-
|
|
337
|
-
|
|
343
|
+
// Find allowed parent for element that we are going to insert.
|
|
344
|
+
// If current parent does not allow to insert element but one of the ancestors does
|
|
345
|
+
// then split nodes to allowed parent.
|
|
346
|
+
const splitResult = conversionApi.splitToAllowedParent(modelNode, data.modelCursor);
|
|
338
347
|
|
|
339
|
-
|
|
348
|
+
// When there is no split result it means that we can't insert element to model tree, so let's skip it.
|
|
349
|
+
if (!splitResult) {
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
340
352
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
conversionApi.writer.createPositionBefore(modelNode),
|
|
344
|
-
conversionApi.writer.createPositionAfter(parts[parts.length - 1]),
|
|
345
|
-
);
|
|
353
|
+
// Insert element on allowed position.
|
|
354
|
+
conversionApi.writer.insert(modelNode, splitResult.position);
|
|
346
355
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
// If we split parent to insert our element then we want to continue conversion in the new part of the split parent.
|
|
350
|
-
//
|
|
351
|
-
// before: <allowed><notAllowed>foo[]</notAllowed></allowed>
|
|
352
|
-
// after: <allowed><notAllowed>foo</notAllowed><converted></converted><notAllowed>[]</notAllowed></allowed>
|
|
356
|
+
// Consume appropriate value from consumable values list.
|
|
357
|
+
consumable.consume(viewItem, { name: true });
|
|
353
358
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
//
|
|
357
|
-
data.
|
|
358
|
-
|
|
359
|
-
|
|
359
|
+
const parts = conversionApi.getSplitParts(modelNode);
|
|
360
|
+
|
|
361
|
+
// Set conversion result range.
|
|
362
|
+
data.modelRange = writer.createRange(
|
|
363
|
+
conversionApi.writer.createPositionBefore(modelNode),
|
|
364
|
+
conversionApi.writer.createPositionAfter(parts[parts.length - 1]),
|
|
365
|
+
);
|
|
366
|
+
|
|
367
|
+
// Now we need to check where the `modelCursor` should be.
|
|
368
|
+
if (splitResult.cursorParent) {
|
|
369
|
+
// If we split parent to insert our element then we want to continue conversion in the new part of the split parent.
|
|
370
|
+
//
|
|
371
|
+
// before: <allowed><notAllowed>foo[]</notAllowed></allowed>
|
|
372
|
+
// after: <allowed><notAllowed>foo</notAllowed><converted></converted><notAllowed>[]</notAllowed></allowed>
|
|
373
|
+
|
|
374
|
+
data.modelCursor = conversionApi.writer.createPositionAt(splitResult.cursorParent, 0);
|
|
375
|
+
} else {
|
|
376
|
+
// Otherwise just continue after inserted element.
|
|
377
|
+
data.modelCursor = data.modelRange.end;
|
|
378
|
+
}
|
|
379
|
+
},
|
|
380
|
+
// Ensures MathType processes the Wiris formulas before other plugins, preventing conflicts.
|
|
381
|
+
{ priority: "high" },
|
|
382
|
+
);
|
|
360
383
|
|
|
361
384
|
/**
|
|
362
385
|
* Whether the given view <math> element has a LaTeX annotation element.
|