@marlinjai/email-editor-core 0.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 marlinjai
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # @marlinjai/email-editor-core
2
+
3
+ The framework-agnostic engine of [`@marlinjai/email-editor`](https://www.npmjs.com/package/@marlinjai/email-editor): the email document schema and its validation, `migrateTemplate` for stored documents, the block registry, the MobX State Tree store, and the MJML compiler.
4
+
5
+ Most apps install it for two things on their server: validating stored documents and compiling them to HTML.
6
+
7
+ ```ts
8
+ import { migrateTemplate, isTemplateMigrationError } from '@marlinjai/email-editor-core';
9
+ import { createMJMLCompiler } from '@marlinjai/email-editor-core/server';
10
+
11
+ const doc = migrateTemplate(storedJson); // throws TemplateMigrationError with a typed `code`
12
+ const { html, mjml, errors } = createMJMLCompiler().compile(doc);
13
+ ```
14
+
15
+ ## Two entry points
16
+
17
+ | Import | Where | Contains |
18
+ |--------|-------|----------|
19
+ | `@marlinjai/email-editor-core` | browser and server | schema, types, `validateTemplate`, `migrateTemplate`, registry, store |
20
+ | `@marlinjai/email-editor-core/server` | server only | MJML compiler and exporter, and `importMjml` (MJML source to a document), all depending on `mjml`, a Node.js-only package |
21
+
22
+ Never import `/server` from client code. In Next.js, list `mjml`, `mjml-core`, `mjml-parser-xml`, `mjml-preset-core` and `mjml-validator` in `serverExternalPackages`.
23
+
24
+ ## `migrateTemplate(doc)`
25
+
26
+ Returns the document at the current schema version (`CURRENT_TEMPLATE_VERSION`, today `"1.1"`; 1.1 added wrappers, a container around sections). For a `1.1` document it is the identity: the same object, validated. A `1.0` document comes back as a new object with only the version changed, except that a 1.0 section flagged `isWrapper` becomes a wrapper around that section. Otherwise it throws a `TemplateMigrationError` whose `code` is `INVALID_INPUT`, `MISSING_VERSION`, `UNSUPPORTED_VERSION`, `NEWER_VERSION` (written by a newer editor) or `INVALID_DOCUMENT` (with the schema `issues`). See the [editor README](https://github.com/marlinjai/email-editor/tree/main/packages/editor#readme) for how to use it in an API route.
27
+
28
+ ## `importMjml(source)`
29
+
30
+ Reads an MJML document into the editor's document model and returns `{ document, warnings }`; the document has passed `migrateTemplate`. An `mj-wrapper` becomes a wrapper holding its sections. What cannot become an editable block is kept as compiled HTML, so the mail does not change, and every such change is a warning with a path and the MJML it came from. Unreadable input throws an `MjmlImportError` with a `code` and, when it is one place, a `line` and `column`; `mj-include` is refused, never read from disk. See the [editor README](https://github.com/marlinjai/email-editor/tree/main/packages/editor#readme) for what maps.
31
+
32
+ ## License
33
+
34
+ MIT