@zzish/math-rich-input 0.1.48 → 0.1.49

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.
@@ -0,0 +1,110 @@
1
+ import React from "react";
2
+ import { createRoot } from "react-dom/client";
3
+ import { MathRichInput } from "./index.js";
4
+
5
+ // Import CSS files
6
+ import "./MathRichInput.css";
7
+ import "./EquationEditorModal.css";
8
+ import "./AccentBar.css";
9
+ import "./Toolbar.css";
10
+ import "./EquationEditor.css";
11
+ import "./SymbolButton.css";
12
+
13
+ class MathRichInputElement extends HTMLElement {
14
+ constructor() {
15
+ super();
16
+ this.root = null;
17
+ }
18
+
19
+ connectedCallback() {
20
+ this.render();
21
+ }
22
+
23
+ disconnectedCallback() {
24
+ if (this.root) {
25
+ this.root.unmount();
26
+ }
27
+ }
28
+
29
+ static get observedAttributes() {
30
+ return [
31
+ "value",
32
+ "placeholder",
33
+ "readonly",
34
+ "disabled",
35
+ "mimetype",
36
+ "outputtex",
37
+ ];
38
+ }
39
+
40
+ attributeChangedCallback(name, oldValue, newValue) {
41
+ // Avoid infinite re-render loop by checking if value actually changed
42
+ if (oldValue !== newValue) {
43
+ this.render();
44
+ }
45
+ }
46
+
47
+ render() {
48
+ const value = this.getAttribute("value") || "";
49
+ const placeholder = this.getAttribute("placeholder") || "";
50
+ const readonly = this.hasAttribute("readonly");
51
+ const disabled = this.hasAttribute("disabled");
52
+ const mimeType = this.getAttribute("mimetype") || "";
53
+ const outputTexAttr = this.getAttribute("outputtex");
54
+ const outputTex =
55
+ outputTexAttr !== "false" && this.hasAttribute("outputtex");
56
+
57
+ // Create container if it doesn't exist
58
+ if (!this.querySelector(".math-rich-input-container")) {
59
+ const container = document.createElement("div");
60
+ container.className = "math-rich-input-container";
61
+ this.appendChild(container);
62
+ }
63
+
64
+ const container = this.querySelector(".math-rich-input-container");
65
+
66
+ if (!this.root) {
67
+ this.root = createRoot(container);
68
+ }
69
+
70
+ this.root.render(
71
+ React.createElement(MathRichInput, {
72
+ value: value,
73
+ placeholder: placeholder,
74
+ readOnly: readonly,
75
+ disabled: disabled,
76
+ mimeType: mimeType,
77
+ outputTex: outputTex,
78
+ className: this.className || "",
79
+ onChange: (data, options) => {
80
+ const { value: newValue, mimeType: newMimeType } = data;
81
+
82
+ // Only update attributes if they actually changed to avoid infinite re-render
83
+ const currentValue = this.getAttribute("value") || "";
84
+ const currentMimeType = this.getAttribute("mimetype") || "";
85
+
86
+ if (newValue !== currentValue) {
87
+ this.setAttribute("value", newValue);
88
+ }
89
+ if (newMimeType !== currentMimeType) {
90
+ this.setAttribute("mimetype", newMimeType);
91
+ }
92
+
93
+ this.dispatchEvent(
94
+ new CustomEvent("change", {
95
+ detail: {
96
+ value: newValue,
97
+ mimeType: newMimeType,
98
+ },
99
+ })
100
+ );
101
+ },
102
+ })
103
+ );
104
+ }
105
+ }
106
+
107
+ // Define the web component
108
+ customElements.define("math-rich-input", MathRichInputElement);
109
+
110
+ export default MathRichInputElement;
@@ -0,0 +1,63 @@
1
+ const path = require("path");
2
+
3
+ module.exports = {
4
+ mode: "production",
5
+ entry: "./src/standalone.js",
6
+ output: {
7
+ path: path.resolve(__dirname, "dist"),
8
+ filename: "standalone.js",
9
+ library: {
10
+ type: "module",
11
+ },
12
+ environment: {
13
+ module: true,
14
+ },
15
+ },
16
+ experiments: {
17
+ outputModule: true,
18
+ },
19
+ module: {
20
+ rules: [
21
+ {
22
+ test: /\.jsx?$/,
23
+ exclude: /node_modules/,
24
+ use: {
25
+ loader: "babel-loader",
26
+ options: {
27
+ presets: [
28
+ ["@babel/preset-env", { targets: "defaults" }],
29
+ ["@babel/preset-react", { runtime: "classic" }],
30
+ ],
31
+ },
32
+ },
33
+ },
34
+ {
35
+ test: /\.css$/,
36
+ use: [
37
+ "style-loader",
38
+ "css-loader",
39
+ {
40
+ loader: "postcss-loader",
41
+ options: {
42
+ postcssOptions: {
43
+ plugins: [require("postcss-nested")],
44
+ },
45
+ },
46
+ },
47
+ ],
48
+ },
49
+ ],
50
+ },
51
+ resolve: {
52
+ extensions: [".js", ".jsx"],
53
+ alias: {
54
+ react: require.resolve("react"),
55
+ "react-dom/client": require.resolve("react-dom/client"),
56
+ "react-dom": require.resolve("react-dom"),
57
+ },
58
+ },
59
+ externals: {
60
+ // No externals - bundle everything
61
+ },
62
+ };
63
+