@viveeditor/element 0.0.0-stage → 1.0.0-rc.1

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 viveEditor contributors
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 CHANGED
@@ -1,3 +1,29 @@
1
- # Temporary Holding Version
1
+ # @viveeditor/element
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ <vive-editor> custom element for viveEditor: works in plain HTML forms and any framework.
4
+
5
+ Part of [viveEditor](https://github.com/mtvrkan/viveeditor#readme), a free, open-source rich text editor.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ npm install @viveeditor/element
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```html
16
+ <script type="module">
17
+ import '@viveeditor/element/define'
18
+ </script>
19
+
20
+ <form>
21
+ <vive-editor name="body" required locale="tr" label="Article body"></vive-editor>
22
+ </form>
23
+ ```
24
+
25
+ `<vive-editor>` sends its HTML with the form, returns to its first value when the form resets and blocks submit while `required` and empty. `defineViveEditor('my-editor')` registers it under another tag name.
26
+
27
+ ## License
28
+
29
+ MIT
@@ -0,0 +1 @@
1
+ export {}
package/dist/define.js ADDED
@@ -0,0 +1,5 @@
1
+ import { defineViveEditor } from "./index.js";
2
+ // src/define.ts
3
+ defineViveEditor();
4
+
5
+ //# sourceMappingURL=define.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"define.js","names":[],"sources":["../src/define.ts"],"sourcesContent":["import { defineViveEditor } from './index.js'\n\ndefineViveEditor()\n"],"mappings":";;AAEA,iBAAiB"}
@@ -0,0 +1,31 @@
1
+ import { Editor } from "viveeditor";
2
+ export declare class ViveEditorElement extends HTMLElement {
3
+ #private;
4
+ static readonly formAssociated: boolean;
5
+ static readonly observedAttributes: readonly string[];
6
+ constructor();
7
+ get value(): string;
8
+ set value(html: string);
9
+ get editor(): Editor | null;
10
+ get ready(): Promise<Editor>;
11
+ get form(): HTMLFormElement | null;
12
+ get name(): string;
13
+ get validity(): ValidityState;
14
+ get validationMessage(): string;
15
+ checkValidity(): boolean;
16
+ reportValidity(): boolean;
17
+ override focus(options?: FocusOptions): void;
18
+ connectedCallback(): void;
19
+ disconnectedCallback(): void;
20
+ attributeChangedCallback(): void;
21
+ formResetCallback(): void;
22
+ formDisabledCallback(disabled: boolean): void;
23
+ formStateRestoreCallback(state: unknown): void;
24
+ }
25
+ export declare function defineViveEditor(tag?: string): CustomElementConstructor;
26
+ declare global {
27
+ interface HTMLElementTagNameMap {
28
+ "vive-editor": ViveEditorElement;
29
+ }
30
+ }
31
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,146 @@
1
+ import { mountEditor, resolveLocale } from "viveeditor";
2
+ // src/index.ts
3
+ const REQUIRED_MESSAGES = {
4
+ tr: "Bu alan boş bırakılamaz.",
5
+ en: "This field is required."
6
+ };
7
+ var ViveEditorElement = class extends HTMLElement {
8
+ static formAssociated = true;
9
+ static observedAttributes = [
10
+ "readonly",
11
+ "disabled",
12
+ "required"
13
+ ];
14
+ #internals;
15
+ #mount = null;
16
+ #value = null;
17
+ #initial = null;
18
+ #formDisabled = false;
19
+ #focusValue = "";
20
+ #ready;
21
+ #resolveReady = () => void 0;
22
+ constructor() {
23
+ super();
24
+ this.#internals = this.attachInternals();
25
+ this.#ready = new Promise((resolve) => {
26
+ this.#resolveReady = resolve;
27
+ });
28
+ }
29
+ get value() {
30
+ if (this.#mount) return this.#mount.getValue();
31
+ return this.#value ?? this.getAttribute("value") ?? "";
32
+ }
33
+ set value(html) {
34
+ this.#value = String(html);
35
+ this.#mount?.setValue(this.#value);
36
+ this.#sync();
37
+ }
38
+ get editor() {
39
+ return this.#mount?.editor ?? null;
40
+ }
41
+ get ready() {
42
+ return this.#ready;
43
+ }
44
+ get form() {
45
+ return this.#internals.form;
46
+ }
47
+ get name() {
48
+ return this.getAttribute("name") ?? "";
49
+ }
50
+ get validity() {
51
+ return this.#internals.validity;
52
+ }
53
+ get validationMessage() {
54
+ return this.#internals.validationMessage;
55
+ }
56
+ checkValidity() {
57
+ return this.#internals.checkValidity();
58
+ }
59
+ reportValidity() {
60
+ return this.#internals.reportValidity();
61
+ }
62
+ focus(options) {
63
+ if (this.editor) this.editor.focus();
64
+ else super.focus(options);
65
+ }
66
+ connectedCallback() {
67
+ if (this.#mount) return;
68
+ this.#initial ??= this.getAttribute("value") ?? "";
69
+ const locale = this.getAttribute("locale") ?? void 0;
70
+ const label = this.getAttribute("label") ?? this.getAttribute("aria-label") ?? void 0;
71
+ this.#mount = mountEditor(this, {
72
+ value: this.#value ?? this.#initial,
73
+ editable: this.#editable(),
74
+ ...locale === void 0 ? {} : { locale },
75
+ ...label === void 0 ? {} : { label },
76
+ ...this.getAttribute("toolbar") === "false" ? { ui: false } : {},
77
+ onChange: () => {
78
+ this.#sync();
79
+ this.dispatchEvent(new Event("input", {
80
+ bubbles: true,
81
+ composed: true
82
+ }));
83
+ },
84
+ onFocus: () => {
85
+ this.#focusValue = this.value;
86
+ },
87
+ onBlur: () => {
88
+ if (this.value !== this.#focusValue) this.dispatchEvent(new Event("change", { bubbles: true }));
89
+ },
90
+ onReady: (editor) => {
91
+ this.#sync();
92
+ this.#resolveReady(editor);
93
+ }
94
+ });
95
+ this.#sync();
96
+ }
97
+ disconnectedCallback() {
98
+ if (!this.#mount) return;
99
+ this.#value = this.#mount.getValue();
100
+ this.#mount.destroy();
101
+ this.#mount = null;
102
+ }
103
+ attributeChangedCallback() {
104
+ this.#mount?.setEditable(this.#editable());
105
+ this.#sync();
106
+ }
107
+ formResetCallback() {
108
+ this.value = this.#initial ?? this.getAttribute("value") ?? "";
109
+ }
110
+ formDisabledCallback(disabled) {
111
+ this.#formDisabled = disabled;
112
+ this.#mount?.setEditable(this.#editable());
113
+ }
114
+ formStateRestoreCallback(state) {
115
+ if (typeof state === "string") this.value = state;
116
+ }
117
+ #editable() {
118
+ return !this.#formDisabled && !this.hasAttribute("readonly") && !this.hasAttribute("disabled");
119
+ }
120
+ #sync() {
121
+ const value = this.value;
122
+ this.#internals.setFormValue(value);
123
+ if (this.hasAttribute("required") && value === "") {
124
+ const message = REQUIRED_MESSAGES[resolveLocale(this.getAttribute("locale") ?? void 0)];
125
+ const anchor = this.editor?.dom;
126
+ this.#internals.setValidity({ valueMissing: true }, message, anchor);
127
+ } else this.#internals.setValidity({});
128
+ }
129
+ };
130
+ function defineViveEditor(tag = "vive-editor") {
131
+ const existing = customElements.get(tag);
132
+ if (existing) return existing;
133
+ const element = class extends ViveEditorElement {};
134
+ customElements.define(tag, element);
135
+ adoptDefaultStyle(tag);
136
+ return element;
137
+ }
138
+ function adoptDefaultStyle(tag) {
139
+ if (typeof CSSStyleSheet === "undefined" || !Array.isArray(document.adoptedStyleSheets)) return;
140
+ const sheet = new CSSStyleSheet();
141
+ sheet.replaceSync(`:where(${tag}){display:block;min-width:0}`);
142
+ document.adoptedStyleSheets = [...document.adoptedStyleSheets, sheet];
143
+ }
144
+ export { ViveEditorElement, defineViveEditor };
145
+
146
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { type Editor, type EditorMount, mountEditor, resolveLocale } from 'viveeditor'\n\nconst REQUIRED_MESSAGES = {\n tr: 'Bu alan boş bırakılamaz.',\n en: 'This field is required.',\n} as const\n\nexport class ViveEditorElement extends HTMLElement {\n static readonly formAssociated: boolean = true\n static readonly observedAttributes: readonly string[] = ['readonly', 'disabled', 'required']\n\n readonly #internals: ElementInternals\n #mount: EditorMount | null = null\n #value: string | null = null\n #initial: string | null = null\n #formDisabled = false\n #focusValue = ''\n #ready: Promise<Editor>\n #resolveReady: (editor: Editor) => void = () => undefined\n\n constructor() {\n super()\n this.#internals = this.attachInternals()\n this.#ready = new Promise((resolve) => {\n this.#resolveReady = resolve\n })\n }\n\n get value(): string {\n if (this.#mount) return this.#mount.getValue()\n return this.#value ?? this.getAttribute('value') ?? ''\n }\n\n set value(html: string) {\n this.#value = String(html)\n this.#mount?.setValue(this.#value)\n this.#sync()\n }\n\n get editor(): Editor | null {\n return this.#mount?.editor ?? null\n }\n\n get ready(): Promise<Editor> {\n return this.#ready\n }\n\n get form(): HTMLFormElement | null {\n return this.#internals.form\n }\n\n get name(): string {\n return this.getAttribute('name') ?? ''\n }\n\n get validity(): ValidityState {\n return this.#internals.validity\n }\n\n get validationMessage(): string {\n return this.#internals.validationMessage\n }\n\n checkValidity(): boolean {\n return this.#internals.checkValidity()\n }\n\n reportValidity(): boolean {\n return this.#internals.reportValidity()\n }\n\n override focus(options?: FocusOptions): void {\n if (this.editor) this.editor.focus()\n else super.focus(options)\n }\n\n connectedCallback(): void {\n if (this.#mount) return\n this.#initial ??= this.getAttribute('value') ?? ''\n const locale = this.getAttribute('locale') ?? undefined\n const label = this.getAttribute('label') ?? this.getAttribute('aria-label') ?? undefined\n this.#mount = mountEditor(this, {\n value: this.#value ?? this.#initial,\n editable: this.#editable(),\n ...(locale === undefined ? {} : { locale }),\n ...(label === undefined ? {} : { label }),\n ...(this.getAttribute('toolbar') === 'false' ? { ui: false as const } : {}),\n onChange: () => {\n this.#sync()\n this.dispatchEvent(new Event('input', { bubbles: true, composed: true }))\n },\n onFocus: () => {\n this.#focusValue = this.value\n },\n onBlur: () => {\n if (this.value !== this.#focusValue) {\n this.dispatchEvent(new Event('change', { bubbles: true }))\n }\n },\n onReady: (editor) => {\n this.#sync()\n this.#resolveReady(editor)\n },\n })\n this.#sync()\n }\n\n disconnectedCallback(): void {\n if (!this.#mount) return\n this.#value = this.#mount.getValue()\n this.#mount.destroy()\n this.#mount = null\n }\n\n attributeChangedCallback(): void {\n this.#mount?.setEditable(this.#editable())\n this.#sync()\n }\n\n formResetCallback(): void {\n this.value = this.#initial ?? this.getAttribute('value') ?? ''\n }\n\n formDisabledCallback(disabled: boolean): void {\n this.#formDisabled = disabled\n this.#mount?.setEditable(this.#editable())\n }\n\n formStateRestoreCallback(state: unknown): void {\n if (typeof state === 'string') this.value = state\n }\n\n #editable(): boolean {\n return !this.#formDisabled && !this.hasAttribute('readonly') && !this.hasAttribute('disabled')\n }\n\n #sync(): void {\n const value = this.value\n this.#internals.setFormValue(value)\n if (this.hasAttribute('required') && value === '') {\n const message = REQUIRED_MESSAGES[resolveLocale(this.getAttribute('locale') ?? undefined)]\n const anchor = this.editor?.dom\n this.#internals.setValidity({ valueMissing: true }, message, anchor)\n } else {\n this.#internals.setValidity({})\n }\n }\n}\n\nexport function defineViveEditor(tag = 'vive-editor'): CustomElementConstructor {\n const existing = customElements.get(tag)\n if (existing) return existing\n const element = class extends ViveEditorElement {}\n customElements.define(tag, element)\n adoptDefaultStyle(tag)\n return element\n}\n\nfunction adoptDefaultStyle(tag: string): void {\n if (typeof CSSStyleSheet === 'undefined' || !Array.isArray(document.adoptedStyleSheets)) return\n const sheet = new CSSStyleSheet()\n sheet.replaceSync(`:where(${tag}){display:block;min-width:0}`)\n document.adoptedStyleSheets = [...document.adoptedStyleSheets, sheet]\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'vive-editor': ViveEditorElement\n }\n}\n"],"mappings":";;AAEA,MAAM,oBAAoB;CACxB,IAAI;CACJ,IAAI;AACN;AAEA,IAAa,oBAAb,cAAuC,YAAY;CACjD,OAAgB,iBAA0B;CAC1C,OAAgB,qBAAwC;EAAC;EAAY;EAAY;CAAU;CAE3F;CACA,SAA6B;CAC7B,SAAwB;CACxB,WAA0B;CAC1B,gBAAgB;CAChB,cAAc;CACd;CACA,sBAAgD,KAAA;CAEhD,cAAc;EACZ,MAAM;EACN,KAAK,aAAa,KAAK,gBAAgB;EACvC,KAAK,SAAS,IAAI,SAAS,YAAY;GACrC,KAAK,gBAAgB;EACvB,CAAC;CACH;CAEA,IAAI,QAAgB;EAClB,IAAI,KAAK,QAAQ,OAAO,KAAK,OAAO,SAAS;EAC7C,OAAO,KAAK,UAAU,KAAK,aAAa,OAAO,KAAK;CACtD;CAEA,IAAI,MAAM,MAAc;EACtB,KAAK,SAAS,OAAO,IAAI;EACzB,KAAK,QAAQ,SAAS,KAAK,MAAM;EACjC,KAAK,MAAM;CACb;CAEA,IAAI,SAAwB;EAC1B,OAAO,KAAK,QAAQ,UAAU;CAChC;CAEA,IAAI,QAAyB;EAC3B,OAAO,KAAK;CACd;CAEA,IAAI,OAA+B;EACjC,OAAO,KAAK,WAAW;CACzB;CAEA,IAAI,OAAe;EACjB,OAAO,KAAK,aAAa,MAAM,KAAK;CACtC;CAEA,IAAI,WAA0B;EAC5B,OAAO,KAAK,WAAW;CACzB;CAEA,IAAI,oBAA4B;EAC9B,OAAO,KAAK,WAAW;CACzB;CAEA,gBAAyB;EACvB,OAAO,KAAK,WAAW,cAAc;CACvC;CAEA,iBAA0B;EACxB,OAAO,KAAK,WAAW,eAAe;CACxC;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EA,qBAAqB,UAAyB;EAC5C,KAAK,gBAAgB;EACrB,KAAK,QAAQ,YAAY,KAAK,UAAU,CAAC;CAC3C;CAEA,yBAAyB,OAAsB;EAC7C,IAAI,OAAO,UAAU,UAAU,KAAK,QAAQ;CAC9C;CAEA,YAAqB;EACnB,OAAO,CAAC,KAAK,iBAAiB,CAAC,KAAK,aAAa,UAAU,KAAK,CAAC,KAAK,aAAa,UAAU;CAC/F;CAEA,QAAc;EACZ,MAAM,QAAQ,KAAK;EACnB,KAAK,WAAW,aAAa,KAAK;EAClC,IAAI,KAAK,aAAa,UAAU,KAAK,UAAU,IAAI;GACjD,MAAM,UAAU,kBAAkB,cAAc,KAAK,aAAa,QAAQ,KAAK,KAAA,CAAS;GACxF,MAAM,SAAS,KAAK,QAAQ;GAC5B,KAAK,WAAW,YAAY,EAAE,cAAc,KAAK,GAAG,SAAS,MAAM;EACrE,OACE,KAAK,WAAW,YAAY,CAAC,CAAC;CAElC;AACF;AAEA,SAAgB,iBAAiB,MAAM,eAAyC;CAC9E,MAAM,WAAW,eAAe,IAAI,GAAG;CACvC,IAAI,UAAU,OAAO;CACrB,MAAM,UAAU,cAAc,kBAAkB,CAAC;CACjD,eAAe,OAAO,KAAK,OAAO;CAClC,kBAAkB,GAAG;CACrB,OAAO;AACT;AAEA,SAAS,kBAAkB,KAAmB;CAC5C,IAAI,OAAO,kBAAkB,eAAe,CAAC,MAAM,QAAQ,SAAS,kBAAkB,GAAG;CACzF,MAAM,QAAQ,IAAI,cAAc;CAChC,MAAM,YAAY,UAAU,IAAI,6BAA6B;CAC7D,SAAS,qBAAqB,CAAC,GAAG,SAAS,oBAAoB,KAAK;AACtE"}
package/package.json CHANGED
@@ -1,6 +1,77 @@
1
1
  {
2
2
  "name": "@viveeditor/element",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.0.0-rc.1",
4
+ "description": "<vive-editor> custom element for viveEditor: works in plain HTML forms and any framework.",
5
+ "license": "MIT",
6
+ "keywords": [
7
+ "viveeditor",
8
+ "rich-text-editor",
9
+ "wysiwyg",
10
+ "editor",
11
+ "prosemirror",
12
+ "web-component",
13
+ "custom-element",
14
+ "form"
15
+ ],
16
+ "homepage": "https://editor.vivepdf.com/en/docs/frameworks/",
17
+ "bugs": {
18
+ "url": "https://github.com/mtvrkan/viveeditor/issues"
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/mtvrkan/viveeditor.git",
23
+ "directory": "packages/element"
24
+ },
25
+ "type": "module",
26
+ "exports": {
27
+ ".": {
28
+ "types": "./dist/index.d.ts",
29
+ "import": "./dist/index.js",
30
+ "default": "./dist/index.js"
31
+ },
32
+ "./define": {
33
+ "types": "./dist/define.d.ts",
34
+ "import": "./dist/define.js",
35
+ "default": "./dist/define.js"
36
+ }
37
+ },
38
+ "files": [
39
+ "dist"
40
+ ],
41
+ "dependencies": {
42
+ "viveeditor": "^1.0.0-rc.1"
43
+ },
44
+ "devDependencies": {
45
+ "@size-limit/preset-small-lib": "^14.3.0",
46
+ "jsdom": "^30.1.3",
47
+ "size-limit": "^14.3.0",
48
+ "tsdown": "0.23.1",
49
+ "vitest": "^5.0.5"
50
+ },
51
+ "size-limit": [
52
+ {
53
+ "name": "@viveeditor/element",
54
+ "path": "dist/index.js",
55
+ "ignore": [
56
+ "viveeditor"
57
+ ],
58
+ "limit": "1.5 KB"
59
+ }
60
+ ],
61
+ "sideEffects": [
62
+ "./dist/define.js"
63
+ ],
64
+ "engines": {
65
+ "node": ">=22.12"
66
+ },
67
+ "publishConfig": {
68
+ "access": "public",
69
+ "provenance": true
70
+ },
71
+ "scripts": {
72
+ "build": "tsdown",
73
+ "typecheck": "tsc -p tsconfig.json",
74
+ "test": "vitest run",
75
+ "size": "size-limit"
76
+ }
6
77
  }