tinymce-solid 0.0.6 → 0.0.8

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/README.md CHANGED
@@ -2,13 +2,15 @@
2
2
 
3
3
  [<img width="100%" src="https://raw.githubusercontent.com/thednp/tinymce-solid/main/banner.svg" alt="TinyMCE Component for SolidJS">](https://thednp.github.io/tinymce-solid)
4
4
 
5
+ [![Coverage Status](https://coveralls.io/repos/github/thednp/tinymce-solid/badge.svg)](https://coveralls.io/github/thednp/tinymce-solid)
5
6
  [![ci](https://github.com/thednp/tinymce-solid/actions/workflows/ci.yml/badge.svg)](https://github.com/thednp/tinymce-solid/actions/workflows/ci.yml)
6
7
  [![Npm Version](https://img.shields.io/npm/v/tinymce-solid)](https://www.npmjs.com/package/tinymce-solid)
7
- [![solid-js version](https://img.shields.io/badge/solid--js-1.8.18-brightgreen)](https://solidjs.com/)
8
- [![tinymce version](https://img.shields.io/badge/tinymce-7.2.1-brightgreen)](https://www.tiny.cloud/)
9
- [![typescript version](https://img.shields.io/badge/typescript-5.5.3-brightgreen)](https://www.typescriptlang.org/)
8
+ [![solid-js version](https://img.shields.io/badge/solid--js-1.8.22-brightgreen)](https://solidjs.com/)
9
+ [![tinymce version](https://img.shields.io/badge/tinymce-7.3.0-brightgreen)](https://www.tiny.cloud/)
10
+ [![typescript version](https://img.shields.io/badge/typescript-5.5.4-brightgreen)](https://www.typescriptlang.org/)
10
11
  [![prettier version](https://img.shields.io/badge/prettier-3.3.3-brightgreen)](https://prettier.io/)
11
- [![vite version](https://img.shields.io/badge/vite-5.3.4-brightgreen)](https://github.com/vitejs)
12
+ [![vitest version](https://img.shields.io/badge/vitest-2.0.5-brightgreen)](https://vitest.dev/)
13
+ [![vite version](https://img.shields.io/badge/vite-5.4.3-brightgreen)](https://github.com/vitejs)
12
14
 
13
15
  ## About
14
16
 
@@ -133,10 +135,11 @@ export default function App() {
133
135
  - This package will automatically load the TinyMCE library and its dependencies by the use of the `tinymceScriptSrc` property;
134
136
  - You can make use of the dark mode via TinyMCE skins: `skin="oxide-dark"` and `contentCss="dark"` properties, [the demo](https://thednp.github.io/tinymce-solid) is configured to make use of them via `createEffect`;
135
137
  - Like the original React adaptation, this component allows you to hook into the TinyMCE instance via an `editorRef` reference.
138
+ - We've added tests powered by Vitest, with a real coverage of ~70%, that is becasue many branches cannot be covered in Vitest browser mode and playwright won't work in some Linux distributions for some reason.
136
139
 
137
140
  ## Issues
138
141
 
139
- Have you found an issue with tinymce-solid or do you have a feature request? Open up an [issue](https://github.com/thednp/tinymce-solid/issues) and let us know or submit a [pull request](https://github.com/thednp/tinymce-solid/pulls).
142
+ Have you found an issue with **tinymce-solid** or do you have a feature request? Open up an [issue](https://github.com/thednp/tinymce-solid/issues) and let us know or submit a [pull request](https://github.com/thednp/tinymce-solid/pulls).
140
143
 
141
144
  _Note: For issues concerning TinyMCE please visit the [TinyMCE repository](https://github.com/tinymce/tinymce)._
142
145
 
package/dist/dev.js CHANGED
@@ -27,9 +27,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
  mod
28
28
  ));
29
29
 
30
- // node_modules/react-is/cjs/react-is.development.js
30
+ // node_modules/prop-types/node_modules/react-is/cjs/react-is.development.js
31
31
  var require_react_is_development = __commonJS({
32
- "node_modules/react-is/cjs/react-is.development.js"(exports) {
32
+ "node_modules/prop-types/node_modules/react-is/cjs/react-is.development.js"(exports) {
33
33
  {
34
34
  (function() {
35
35
  var hasSymbol = typeof Symbol === "function" && Symbol.for;
@@ -180,9 +180,9 @@ var require_react_is_development = __commonJS({
180
180
  }
181
181
  });
182
182
 
183
- // node_modules/react-is/index.js
183
+ // node_modules/prop-types/node_modules/react-is/index.js
184
184
  var require_react_is = __commonJS({
185
- "node_modules/react-is/index.js"(exports, module) {
185
+ "node_modules/prop-types/node_modules/react-is/index.js"(exports, module) {
186
186
  {
187
187
  module.exports = require_react_is_development();
188
188
  }
@@ -1103,7 +1103,10 @@ var ScriptLoader = createScriptLoader();
1103
1103
  // src/TinyMCE.ts
1104
1104
  var getTinymce = (view) => {
1105
1105
  const global = view;
1106
- return global && global.tinymce ? global.tinymce : null;
1106
+ return global && global.tinymce ? (
1107
+ /* istanbul ignore next -- @preserve */
1108
+ global.tinymce
1109
+ ) : null;
1107
1110
  };
1108
1111
 
1109
1112
  // src/components/Editor.tsx
@@ -1120,7 +1123,8 @@ var Editor = (props) => {
1120
1123
  const [rollbackTimer, setRollbackTimer] = createSignal();
1121
1124
  const [valueCursor, setValueCursor] = createSignal();
1122
1125
  const [boundHandlers, setBoundHandlers] = createSignal({});
1123
- const view = () => props?.elementRef?.ownerDocument.defaultView ?? window;
1126
+ const view = () => props?.elementRef?.ownerDocument.defaultView ?? /* istanbul ignore next @preserve */
1127
+ window;
1124
1128
  const getInitialValue = () => {
1125
1129
  if (typeof initialValue() === "string") {
1126
1130
  return initialValue();
@@ -1373,7 +1377,7 @@ var Editor = (props) => {
1373
1377
  handleBeforeInput(evt);
1374
1378
  }
1375
1379
  };
1376
- return createComponent(Dynamic, mergeProps({
1380
+ return createComponent(Dynamic, mergeProps(props, {
1377
1381
  get component() {
1378
1382
  return memo(() => !!props.inline)() ? tagName() : "textarea";
1379
1383
  },
@@ -1389,12 +1393,28 @@ var Editor = (props) => {
1389
1393
  ref(r$) {
1390
1394
  var _ref$ = props.elementRef;
1391
1395
  typeof _ref$ === "function" ? _ref$(r$) : props.elementRef = r$;
1396
+ },
1397
+ get ["data-disabled"]() {
1398
+ return disabled();
1399
+ },
1400
+ get ["data-skin"]() {
1401
+ return skin();
1402
+ },
1403
+ get ["data-css"]() {
1404
+ return contentCss();
1392
1405
  }
1393
- }, props));
1406
+ }));
1394
1407
  };
1395
1408
 
1396
1409
  // src/index.tsx
1397
1410
  var src_default = Editor;
1411
+ /* istanbul ignore next @preserve - this should be covered but the browser mode won't register this part */
1412
+ /* istanbul ignore next @preserve - this here seems to be for legacy browsers, we ignore it */
1413
+ /* istanbul ignore else @preserve */
1414
+ /* istanbul ignore next @preserve */
1415
+ /* istanbul ignore next @preserve - this error is thrown on every HMR so we ignore it */
1416
+ /* istanbul ignore next @preserve - this error is thrown on every HMR so we can ignore it */
1417
+ /* istanbul ignore next @preserve - exact same reason */
1398
1418
  /*! Bundled license information:
1399
1419
 
1400
1420
  react-is/cjs/react-is.development.js:
package/dist/dev.jsx CHANGED
@@ -24,9 +24,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
24
24
  mod
25
25
  ));
26
26
 
27
- // node_modules/react-is/cjs/react-is.development.js
27
+ // node_modules/prop-types/node_modules/react-is/cjs/react-is.development.js
28
28
  var require_react_is_development = __commonJS({
29
- "node_modules/react-is/cjs/react-is.development.js"(exports) {
29
+ "node_modules/prop-types/node_modules/react-is/cjs/react-is.development.js"(exports) {
30
30
  "use strict";
31
31
  if (true) {
32
32
  (function() {
@@ -179,9 +179,9 @@ var require_react_is_development = __commonJS({
179
179
  }
180
180
  });
181
181
 
182
- // node_modules/react-is/index.js
182
+ // node_modules/prop-types/node_modules/react-is/index.js
183
183
  var require_react_is = __commonJS({
184
- "node_modules/react-is/index.js"(exports, module) {
184
+ "node_modules/prop-types/node_modules/react-is/index.js"(exports, module) {
185
185
  "use strict";
186
186
  if (false) {
187
187
  module.exports = null;
@@ -1117,7 +1117,10 @@ var ScriptLoader = createScriptLoader();
1117
1117
  // src/TinyMCE.ts
1118
1118
  var getTinymce = (view) => {
1119
1119
  const global = view;
1120
- return global && global.tinymce ? global.tinymce : null;
1120
+ return global && global.tinymce ? (
1121
+ /* istanbul ignore next -- @preserve */
1122
+ global.tinymce
1123
+ ) : null;
1121
1124
  };
1122
1125
 
1123
1126
  // src/components/Editor.tsx
@@ -1134,7 +1137,8 @@ var Editor = (props) => {
1134
1137
  const [rollbackTimer, setRollbackTimer] = createSignal();
1135
1138
  const [valueCursor, setValueCursor] = createSignal();
1136
1139
  const [boundHandlers, setBoundHandlers] = createSignal({});
1137
- const view = () => props?.elementRef?.ownerDocument.defaultView ?? window;
1140
+ const view = () => props?.elementRef?.ownerDocument.defaultView ?? /* istanbul ignore next @preserve */
1141
+ window;
1138
1142
  const getInitialValue = () => {
1139
1143
  if (typeof initialValue() === "string") {
1140
1144
  return initialValue();
@@ -1398,12 +1402,15 @@ var Editor = (props) => {
1398
1402
  }
1399
1403
  };
1400
1404
  return <Dynamic
1405
+ {...props}
1401
1406
  component={props.inline ? tagName() : "textarea"}
1402
1407
  id={id()}
1403
1408
  data-testid={props.testid}
1404
1409
  tabIndex={props.tabIndex}
1405
1410
  ref={props.elementRef}
1406
- {...props}
1411
+ data-disabled={disabled()}
1412
+ data-skin={skin()}
1413
+ data-css={contentCss()}
1407
1414
  />;
1408
1415
  };
1409
1416
 
@@ -1413,6 +1420,13 @@ export {
1413
1420
  EditorPropTypes,
1414
1421
  src_default as default
1415
1422
  };
1423
+ /* istanbul ignore next @preserve - this should be covered but the browser mode won't register this part */
1424
+ /* istanbul ignore next @preserve - this here seems to be for legacy browsers, we ignore it */
1425
+ /* istanbul ignore else @preserve */
1426
+ /* istanbul ignore next @preserve */
1427
+ /* istanbul ignore next @preserve - this error is thrown on every HMR so we ignore it */
1428
+ /* istanbul ignore next @preserve - this error is thrown on every HMR so we can ignore it */
1429
+ /* istanbul ignore next @preserve - exact same reason */
1416
1430
  /*! Bundled license information:
1417
1431
 
1418
1432
  react-is/cjs/react-is.development.js:
package/dist/index.js CHANGED
@@ -407,7 +407,10 @@ var ScriptLoader = createScriptLoader();
407
407
  // src/TinyMCE.ts
408
408
  var getTinymce = (view) => {
409
409
  const global = view;
410
- return global && global.tinymce ? global.tinymce : null;
410
+ return global && global.tinymce ? (
411
+ /* istanbul ignore next -- @preserve */
412
+ global.tinymce
413
+ ) : null;
411
414
  };
412
415
 
413
416
  // src/components/Editor.tsx
@@ -424,7 +427,8 @@ var Editor = (props) => {
424
427
  const [rollbackTimer, setRollbackTimer] = createSignal();
425
428
  const [valueCursor, setValueCursor] = createSignal();
426
429
  const [boundHandlers, setBoundHandlers] = createSignal({});
427
- const view = () => props?.elementRef?.ownerDocument.defaultView ?? window;
430
+ const view = () => props?.elementRef?.ownerDocument.defaultView ?? /* istanbul ignore next @preserve */
431
+ window;
428
432
  const getInitialValue = () => {
429
433
  if (typeof initialValue() === "string") {
430
434
  return initialValue();
@@ -677,7 +681,7 @@ var Editor = (props) => {
677
681
  handleBeforeInput(evt);
678
682
  }
679
683
  };
680
- return createComponent(Dynamic, mergeProps({
684
+ return createComponent(Dynamic, mergeProps(props, {
681
685
  get component() {
682
686
  return memo(() => !!props.inline)() ? tagName() : "textarea";
683
687
  },
@@ -693,11 +697,27 @@ var Editor = (props) => {
693
697
  ref(r$) {
694
698
  var _ref$ = props.elementRef;
695
699
  typeof _ref$ === "function" ? _ref$(r$) : props.elementRef = r$;
700
+ },
701
+ get ["data-disabled"]() {
702
+ return disabled();
703
+ },
704
+ get ["data-skin"]() {
705
+ return skin();
706
+ },
707
+ get ["data-css"]() {
708
+ return contentCss();
696
709
  }
697
- }, props));
710
+ }));
698
711
  };
699
712
 
700
713
  // src/index.tsx
701
714
  var src_default = Editor;
715
+ /* istanbul ignore next @preserve - this should be covered but the browser mode won't register this part */
716
+ /* istanbul ignore next @preserve - this here seems to be for legacy browsers, we ignore it */
717
+ /* istanbul ignore else @preserve */
718
+ /* istanbul ignore next @preserve */
719
+ /* istanbul ignore next @preserve - this error is thrown on every HMR so we ignore it */
720
+ /* istanbul ignore next @preserve - this error is thrown on every HMR so we can ignore it */
721
+ /* istanbul ignore next @preserve - exact same reason */
702
722
 
703
723
  export { EditorPropTypes, src_default as default };
package/dist/index.jsx CHANGED
@@ -419,7 +419,10 @@ var ScriptLoader = createScriptLoader();
419
419
  // src/TinyMCE.ts
420
420
  var getTinymce = (view) => {
421
421
  const global = view;
422
- return global && global.tinymce ? global.tinymce : null;
422
+ return global && global.tinymce ? (
423
+ /* istanbul ignore next -- @preserve */
424
+ global.tinymce
425
+ ) : null;
423
426
  };
424
427
 
425
428
  // src/components/Editor.tsx
@@ -436,7 +439,8 @@ var Editor = (props) => {
436
439
  const [rollbackTimer, setRollbackTimer] = createSignal();
437
440
  const [valueCursor, setValueCursor] = createSignal();
438
441
  const [boundHandlers, setBoundHandlers] = createSignal({});
439
- const view = () => props?.elementRef?.ownerDocument.defaultView ?? window;
442
+ const view = () => props?.elementRef?.ownerDocument.defaultView ?? /* istanbul ignore next @preserve */
443
+ window;
440
444
  const getInitialValue = () => {
441
445
  if (typeof initialValue() === "string") {
442
446
  return initialValue();
@@ -700,12 +704,15 @@ var Editor = (props) => {
700
704
  }
701
705
  };
702
706
  return <Dynamic
707
+ {...props}
703
708
  component={props.inline ? tagName() : "textarea"}
704
709
  id={id()}
705
710
  data-testid={props.testid}
706
711
  tabIndex={props.tabIndex}
707
712
  ref={props.elementRef}
708
- {...props}
713
+ data-disabled={disabled()}
714
+ data-skin={skin()}
715
+ data-css={contentCss()}
709
716
  />;
710
717
  };
711
718
 
@@ -715,3 +722,10 @@ export {
715
722
  EditorPropTypes,
716
723
  src_default as default
717
724
  };
725
+ /* istanbul ignore next @preserve - this should be covered but the browser mode won't register this part */
726
+ /* istanbul ignore next @preserve - this here seems to be for legacy browsers, we ignore it */
727
+ /* istanbul ignore else @preserve */
728
+ /* istanbul ignore next @preserve */
729
+ /* istanbul ignore next @preserve - this error is thrown on every HMR so we ignore it */
730
+ /* istanbul ignore next @preserve - this error is thrown on every HMR so we can ignore it */
731
+ /* istanbul ignore next @preserve - exact same reason */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tinymce-solid",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "📝 TinyMCE Component for SolidJS",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -20,30 +20,37 @@
20
20
  "registry": "https://registry.npmjs.org/"
21
21
  },
22
22
  "dependencies": {
23
- "solid-js": "^1.8.18",
24
- "tinymce": "^7.2.1"
23
+ "solid-js": "^1.8.22",
24
+ "tinymce": "^7.3.0"
25
25
  },
26
26
  "devDependencies": {
27
- "@kobalte/core": "^0.13.3",
28
- "@kobalte/utils": "^0.9.0",
29
- "@types/node": "^20.14.11",
27
+ "@kobalte/core": "^0.13.6",
28
+ "@kobalte/utils": "^0.9.1",
29
+ "@testing-library/jest-dom": "^6.5.0",
30
+ "@types/node": "^20.16.5",
30
31
  "@types/prop-types": "^15.7.12",
31
- "autoprefixer": "^10.4.19",
32
+ "@vitest/browser": "^2.0.5",
33
+ "@vitest/coverage-istanbul": "^2.0.5",
34
+ "@vitest/ui": "^2.0.5",
35
+ "autoprefixer": "^10.4.20",
32
36
  "class-variance-authority": "^0.7.0",
33
37
  "clsx": "^2.1.1",
34
- "postcss": "^8.4.39",
38
+ "jsdom": "^25.0.0",
39
+ "playwright": "^1.47.0",
40
+ "postcss": "^8.4.45",
35
41
  "prettier": "^3.3.3",
36
42
  "prop-types": "^15.8.1",
37
- "tailwind-merge": "^2.4.0",
38
- "tailwindcss": "^3.4.6",
43
+ "tailwind-merge": "^2.5.2",
44
+ "tailwindcss": "^3.4.10",
39
45
  "tailwindcss-animate": "^1.0.7",
40
- "tsup": "^8.2.1",
46
+ "tsup": "^8.2.4",
41
47
  "tsup-preset-solid": "^2.2.0",
42
- "typescript": "^5.5.3",
43
- "typescript-eslint": "^7.16.1",
44
- "vite": "^5.3.4",
45
- "vite-plugin-compression2": "^1.1.3",
46
- "vite-plugin-solid": "^2.10.2"
48
+ "typescript": "^5.5.4",
49
+ "typescript-eslint": "^7.18.0",
50
+ "vite": "^5.4.3",
51
+ "vite-plugin-compression2": "^1.2.0",
52
+ "vite-plugin-solid": "^2.10.2",
53
+ "vitest": "^2.0.5"
47
54
  },
48
55
  "engines": {
49
56
  "node": ">=18"
@@ -70,6 +77,10 @@
70
77
  },
71
78
  "typesVersions": {},
72
79
  "scripts": {
80
+ "pre-test": "pnpm clean-coverage",
81
+ "test": "pnpm pre-test && vitest --config vitest.config.ts",
82
+ "test-ui": "pnpm pre-test && vitest --config vitest.config-ui.ts",
83
+ "clean-coverage": "rm -rf coverage .nyc_output",
73
84
  "format": "prettier -w \"src/**/*.{js,ts,json,css,tsx,jsx}\"",
74
85
  "build": "tsup",
75
86
  "build:all": "pnpm build && pnpm build:docs",
@@ -77,7 +88,7 @@
77
88
  "build:docs": "vite build demo --config demo/vite.config.docs.ts",
78
89
  "copy:tiny": "cp -a './node_modules/.pnpm/tinymce@7.1.1/node_modules/tinymce' './demo/public'",
79
90
  "serve:docs": "vite serve docs --port 3000",
80
- "badges": "npx -p dependency-version-badge update-badge solid-js tinymce typescript prettier vite",
91
+ "badges": "npx -p dependency-version-badge update-badge solid-js tinymce typescript prettier vitest vite",
81
92
  "lint": "pnpm lint:types && pnpm lint:code",
82
93
  "lint:code": "eslint 'src/**/*.{ts,tsx}' --max-warnings 0",
83
94
  "lint:types": "tsc --noEmit src/**/* --jsx preserve",
@@ -30,6 +30,7 @@ const injectScriptTag = (
30
30
  scriptTag.removeEventListener("error", errorHandler);
31
31
  handler(item.src);
32
32
  };
33
+ /* istanbul ignore next @preserve - this should be covered but the browser mode won't register this part */
33
34
  const errorHandler = (err: unknown) => {
34
35
  scriptTag.removeEventListener("load", loadHandler);
35
36
  scriptTag.removeEventListener("error", errorHandler);
@@ -39,6 +40,7 @@ const injectScriptTag = (
39
40
  scriptTag.addEventListener("load", loadHandler);
40
41
  scriptTag.addEventListener("error", errorHandler);
41
42
 
43
+ /* istanbul ignore else @preserve */
42
44
  if (doc.head) {
43
45
  doc.head.appendChild(scriptTag);
44
46
  }
@@ -65,6 +67,7 @@ const createDocumentScriptLoader = (doc: Document) => {
65
67
  item.handlers = [];
66
68
  };
67
69
 
70
+ /* istanbul ignore next @preserve - this should be covered but the browser mode won't register this part */
68
71
  const loadScripts = (
69
72
  items: ScriptItem[],
70
73
  success: () => void,
@@ -112,6 +115,7 @@ const createDocumentScriptLoader = (doc: Document) => {
112
115
  }
113
116
  };
114
117
 
118
+ /* istanbul ignore next @preserve - this should be covered but the browser mode won't register this part */
115
119
  const deleteScripts = () => {
116
120
  for (const item of Object.values(lookup)) {
117
121
  const scriptTag = doc.getElementById(item.id);
@@ -154,6 +158,7 @@ const createScriptLoader = () => {
154
158
  ) => {
155
159
  const doLoad = () =>
156
160
  getDocumentScriptLoader(doc).loadScripts(items, success, failure);
161
+ /* istanbul ignore next @preserve - this should be covered but the browser mode won't register this part */
157
162
  if (delay > 0) {
158
163
  setTimeout(doLoad, delay);
159
164
  } else {
@@ -161,6 +166,7 @@ const createScriptLoader = () => {
161
166
  }
162
167
  };
163
168
 
169
+ /* istanbul ignore next @preserve - this should be covered but the browser mode won't register this part */
164
170
  const reinitialize = () => {
165
171
  for (let loader = cache.pop(); loader != null; loader = cache.pop()) {
166
172
  loader.deleteScripts();
package/src/TinyMCE.ts CHANGED
@@ -2,7 +2,10 @@ import { type TinyMCE as TinyMCEGlobal } from "tinymce";
2
2
 
3
3
  const getTinymce = (view: Window): TinyMCEGlobal | null => {
4
4
  const global = view as unknown as { tinymce: TinyMCEGlobal | null };
5
- return global && global.tinymce ? global.tinymce : null;
5
+
6
+ return global && global.tinymce
7
+ ? /* istanbul ignore next -- @preserve */ global.tinymce
8
+ : null;
6
9
  };
7
10
 
8
11
  export { getTinymce };
package/src/Utils.ts CHANGED
@@ -25,9 +25,11 @@ export const configHandlers2 = <H>(
25
25
  const prevEventKeys = Object.keys(prevProps).filter(isEventProp);
26
26
  const currEventKeys = Object.keys(props).filter(isEventProp);
27
27
 
28
+ /* istanbul ignore next @preserve - this should be covered but the browser mode won't register this part */
28
29
  const removedKeys = prevEventKeys.filter((key) => props[key] === undefined);
29
30
  const addedKeys = currEventKeys.filter((key) => prevProps[key] === undefined);
30
31
 
32
+ /* istanbul ignore next @preserve - this should be covered but the browser mode won't register this part */
31
33
  removedKeys.forEach((key) => {
32
34
  // remove event handler
33
35
  const eventName = eventAttrToEventName(key);
@@ -99,6 +101,7 @@ export const isBeforeInputEventAvailable = () =>
99
101
  typeof InputEvent.prototype.getTargetRanges === "function";
100
102
 
101
103
  export const isInDoc = (elem: Node) => {
104
+ /* istanbul ignore next @preserve - this here seems to be for legacy browsers, we ignore it */
102
105
  if (!("isConnected" in Node.prototype)) {
103
106
  // Fallback for IE and old Edge
104
107
  let current = elem;
@@ -117,7 +120,9 @@ export const setMode = (
117
120
  editor: TinyMCEEditor | undefined,
118
121
  mode: "readonly" | "design",
119
122
  ) => {
123
+ /* istanbul ignore else @preserve */
120
124
  if (editor !== undefined) {
125
+ /* istanbul ignore else @preserve */
121
126
  if (
122
127
  editor.mode != null &&
123
128
  typeof editor.mode === "object" &&
@@ -37,9 +37,12 @@ export const Editor = (props: Partial<IAllProps>) => {
37
37
  const [boundHandlers, setBoundHandlers] = createSignal<
38
38
  Record<string, (event: EditorEvent<unknown>) => unknown>
39
39
  >({});
40
- const view = () => props?.elementRef?.ownerDocument.defaultView ?? window;
40
+ const view = () =>
41
+ props?.elementRef?.ownerDocument.defaultView ??
42
+ /* istanbul ignore next @preserve */ window;
41
43
 
42
44
  const getInitialValue = () => {
45
+ /* istanbul ignore else @preserve */
43
46
  if (typeof initialValue() === "string") {
44
47
  return initialValue() as string;
45
48
  } else if (typeof value() === "string") {
@@ -51,11 +54,14 @@ export const Editor = (props: Partial<IAllProps>) => {
51
54
  const getScriptSources = (): ScriptItem[] => {
52
55
  const async = props.scriptLoading?.async;
53
56
  const defer = props.scriptLoading?.defer;
57
+ /* istanbul ignore next @preserve */
54
58
  if (props.tinymceScriptSrc !== undefined) {
59
+ /* istanbul ignore next @preserve */
55
60
  if (typeof props.tinymceScriptSrc === "string") {
56
61
  return [{ src: props.tinymceScriptSrc, async, defer }];
57
62
  }
58
63
  // multiple scripts can be specified which allows for hybrid mode
64
+ /* istanbul ignore next @preserve - this should be covered but the browser mode won't register this part */
59
65
  return (props.tinymceScriptSrc as string[] | ScriptItem[]).map((item) => {
60
66
  if (typeof item === "string") {
61
67
  // async does not make sense for multiple items unless
@@ -75,6 +81,7 @@ export const Editor = (props: Partial<IAllProps>) => {
75
81
  };
76
82
 
77
83
  const bindHandlers = (prevProps: Partial<IAllProps>) => {
84
+ /* istanbul ignore else @preserve */
78
85
  if (editor() !== undefined) {
79
86
  const tinyEditor = editor()!;
80
87
 
@@ -91,6 +98,7 @@ export const Editor = (props: Partial<IAllProps>) => {
91
98
  p.onEditorChange !== undefined || p.value !== undefined;
92
99
  const wasControlled = isValueControlled(prevProps);
93
100
  const nowControlled = isValueControlled(props);
101
+ /* istanbul ignore next @preserve - this should be covered but the browser mode won't register this part */
94
102
  if (!wasControlled && nowControlled) {
95
103
  tinyEditor.on(changeEvents(), handleEditorChange);
96
104
  tinyEditor.on(beforeInputEvent(), handleBeforeInput);
@@ -110,6 +118,7 @@ export const Editor = (props: Partial<IAllProps>) => {
110
118
  props.onScriptsLoad?.();
111
119
  initialise();
112
120
  };
121
+ /* istanbul ignore next @preserve - this should be covered but the browser mode won't register this part */
113
122
  const errorHandler = (err: unknown) => {
114
123
  // console.warn(err);
115
124
  props.onScriptsLoadError?.(err);
@@ -117,9 +126,11 @@ export const Editor = (props: Partial<IAllProps>) => {
117
126
 
118
127
  const initialise = (attempts = 0) => {
119
128
  const target = props.elementRef;
129
+ /* istanbul ignore next @preserve */
120
130
  if (!target) {
121
131
  return; // Editor has been unmounted
122
132
  }
133
+ /* istanbul ignore else @preserve */
123
134
  if (!isInDoc(target)) {
124
135
  // this is probably someone trying to help by rendering us offscreen
125
136
  // but we can't do that because the editor iframe must be in the document
@@ -132,12 +143,14 @@ export const Editor = (props: Partial<IAllProps>) => {
132
143
  setTimeout(() => initialise(attempts + 1), 100);
133
144
  } else {
134
145
  // give up, at this point it seems that more polling is unlikely to help
146
+ /* istanbul ignore next @preserve - this error is thrown on every HMR so we ignore it */
135
147
  throw new Error("tinymce can only be initialised when in a document");
136
148
  }
137
149
  return;
138
150
  }
139
151
 
140
152
  const tinymce = getTinymce(view());
153
+ /* istanbul ignore next @preserve - this error is thrown on every HMR so we can ignore it */
141
154
  if (!tinymce) {
142
155
  throw new Error("tinymce should have been loaded into global scope");
143
156
  }
@@ -172,6 +185,7 @@ export const Editor = (props: Partial<IAllProps>) => {
172
185
  });
173
186
  }
174
187
 
188
+ /* istanbul ignore next @preserve */
175
189
  if (props.init && isFunction(props.init.setup)) {
176
190
  props.init.setup(editor);
177
191
  }
@@ -180,6 +194,7 @@ export const Editor = (props: Partial<IAllProps>) => {
180
194
  // check for changes that happened since tinymce.init() was called
181
195
  const initialValue = getInitialValue();
182
196
  let newCurrentValue = currentContent() ?? editor.getContent();
197
+ /* istanbul ignore next @preserve - this should be covered but the browser mode won't register this part */
183
198
  if (newCurrentValue !== initialValue) {
184
199
  newCurrentValue = initialValue;
185
200
  // same as resetContent in TinyMCE 5
@@ -192,6 +207,7 @@ export const Editor = (props: Partial<IAllProps>) => {
192
207
  const isDisabled = disabled() ?? false;
193
208
  setMode(editor, isDisabled ? "readonly" : "design");
194
209
  // ensure existing init_instance_callback is called
210
+ /* istanbul ignore next @preserve */
195
211
  if (props.init && isFunction(props.init.init_instance_callback)) {
196
212
  props.init.init_instance_callback(editor);
197
213
  }
@@ -207,6 +223,7 @@ export const Editor = (props: Partial<IAllProps>) => {
207
223
  tinymce.init(finalInit);
208
224
  };
209
225
  const mountCallback = () => {
226
+ /* istanbul ignore else @preserve */
210
227
  if (getTinymce(view()) !== null) {
211
228
  initialise();
212
229
  } else if (
@@ -230,6 +247,7 @@ export const Editor = (props: Partial<IAllProps>) => {
230
247
  };
231
248
  const cleanUpCallback = () => {
232
249
  const tinyEditor = editor()!;
250
+ /* istanbul ignore next @preserve - this should be covered but the browser mode won't register this part */
233
251
  if (typeof tinyEditor !== "undefined") {
234
252
  tinyEditor.off(changeEvents(), handleEditorChange);
235
253
  tinyEditor.off(beforeInputEvent(), handleBeforeInput);
@@ -248,6 +266,7 @@ export const Editor = (props: Partial<IAllProps>) => {
248
266
 
249
267
  createEffect(
250
268
  on(value, () => {
269
+ /* istanbul ignore next @preserve - this should be covered but the browser mode won't register this part */
251
270
  if (value() !== currentContent()) {
252
271
  setCurrentContent(value());
253
272
  editor()?.setContent(value(), { no_events: true, event_name: "input" });
@@ -290,14 +309,17 @@ export const Editor = (props: Partial<IAllProps>) => {
290
309
 
291
310
  const handleEditorChange = (event: EditorEvent<unknown>) => {
292
311
  const tinyEditor = editor();
312
+ /* istanbul ignore next @preserve - this should be covered but the browser mode won't register this part */
293
313
  if (tinyEditor && tinyEditor.initialized && !event.isDefaultPrevented()) {
294
314
  const newContent = tinyEditor.getContent();
315
+ /* istanbul ignore next @preserve */
295
316
  if (
296
317
  props.value !== undefined &&
297
318
  props.value !== newContent &&
298
319
  props.rollback !== false
299
320
  ) {
300
321
  // start a timer and revert to the value if not applied in time
322
+ /* istanbul ignore next @preserve */
301
323
  if (!rollbackTimer()) {
302
324
  setRollbackTimer(
303
325
  window.setTimeout(
@@ -308,8 +330,10 @@ export const Editor = (props: Partial<IAllProps>) => {
308
330
  }
309
331
  }
310
332
 
333
+ /* istanbul ignore next @preserve */
311
334
  if (newContent !== currentContent()) {
312
335
  setCurrentContent(newContent);
336
+ /* istanbul ignore next @preserve */
313
337
  if (isFunction(props.onEditorChange)) {
314
338
  props.onEditorChange(newContent, tinyEditor);
315
339
  }
@@ -318,13 +342,16 @@ export const Editor = (props: Partial<IAllProps>) => {
318
342
  };
319
343
 
320
344
  const rollbackChange = () => {
345
+ /* istanbul ignore next @preserve */
321
346
  const tinyEditor = editor();
322
347
  const value = props.value;
348
+ /* istanbul ignore next @preserve */
323
349
  if (tinyEditor && value && value !== currentContent()) {
324
350
  tinyEditor.undoManager.ignore(() => {
325
351
  tinyEditor.setContent(value);
326
352
  // only restore cursor on inline editors when they are focused
327
353
  // as otherwise it will cause a focus grab
354
+ /* istanbul ignore next @preserve - this should be covered but the browser mode won't register this part */
328
355
  if (valueCursor() && (!props.inline || tinyEditor.hasFocus())) {
329
356
  try {
330
357
  tinyEditor.selection.moveToBookmark(valueCursor()!);
@@ -334,11 +361,14 @@ export const Editor = (props: Partial<IAllProps>) => {
334
361
  }
335
362
  });
336
363
  }
364
+ /* istanbul ignore next @preserve */
337
365
  setRollbackTimer(undefined);
338
366
  };
339
367
 
340
368
  const handleBeforeInput = (event: EditorEvent<unknown>) => {
369
+ /* istanbul ignore next @preserve - this should be covered but the browser mode won't register this part */
341
370
  const tinyEditor = editor()!;
371
+ /* istanbul ignore next @preserve - exact same reason */
342
372
  if (
343
373
  props.value !== undefined &&
344
374
  props.value === currentContent() &&
@@ -359,6 +389,7 @@ export const Editor = (props: Partial<IAllProps>) => {
359
389
  };
360
390
 
361
391
  const handleEditorChangeSpecial = (evt: EditorEvent<KeyboardEvent>) => {
392
+ /* istanbul ignore next @preserve - this should be covered but the browser mode won't register this part */
362
393
  if (
363
394
  evt.key === "Enter" ||
364
395
  evt.key === "Backspace" ||
@@ -369,6 +400,7 @@ export const Editor = (props: Partial<IAllProps>) => {
369
400
  };
370
401
 
371
402
  const handleBeforeInputSpecial = (evt: EditorEvent<KeyboardEvent>) => {
403
+ /* istanbul ignore next @preserve - this should be covered but the browser mode won't register this part */
372
404
  if (
373
405
  evt.key === "Enter" ||
374
406
  evt.key === "Backspace" ||
@@ -380,12 +412,16 @@ export const Editor = (props: Partial<IAllProps>) => {
380
412
 
381
413
  return (
382
414
  <Dynamic
415
+ {...props}
383
416
  component={props.inline ? tagName() : "textarea"}
384
417
  id={id()}
385
418
  data-testid={props.testid}
386
419
  tabIndex={props.tabIndex}
387
420
  ref={props.elementRef}
388
- {...props}
421
+ // value={value()}
422
+ data-disabled={disabled()}
423
+ data-skin={skin()}
424
+ data-css={contentCss()}
389
425
  />
390
426
  );
391
427
  };
@@ -0,0 +1,6 @@
1
+ import SolidEditor, { type IAllProps } from '../../src/index'
2
+
3
+ const tinymceURL = import.meta.env.BASE_URL + "tinymce/tinymce.js";
4
+
5
+ export const Editor = (props: IAllProps) =>
6
+ <SolidEditor { ...props } licenseKey="gpl" tinymceScriptSrc={tinymceURL} />;
@@ -0,0 +1,227 @@
1
+ import { createSignal, Show } from 'solid-js';
2
+ import { render } from "solid-js/web";
3
+ import { describe, it, expect } from 'vitest';
4
+ import { type IAllProps } from "~/index";
5
+
6
+ import { Editor } from './fixtures/Editor';
7
+ import SolidEditor from '~/index';
8
+ import { ScriptLoader } from '~/ScriptLoader2';
9
+ import { Editor as TinyMCE } from 'tinymce';
10
+
11
+ describe("Test <SolidEditor />", () => {
12
+ const container = document.createElement('div');
13
+ document.body.append(container);
14
+
15
+ beforeEach(() => {
16
+ container.innerHTML = '';
17
+ })
18
+
19
+ it("initializes with cloud scripts", async () => {
20
+ render(() => <SolidEditor />, container);
21
+ const editorArea = await vi.waitUntil(() =>
22
+ container.querySelector('iframe')?.contentWindow?.document.getElementById('tinymce'),
23
+ { timeout: 1000, interval: 50 }
24
+ );
25
+ expect(editorArea).to.exist;
26
+ });
27
+
28
+ it("renders the editor target with DIV tag", () => {
29
+ render(() => <Editor inline />, container);
30
+ const target = container.querySelector('div');
31
+
32
+ expect(target).to.exist;
33
+ });
34
+
35
+ it("removes TinyMCE instance on unmount", async () => {
36
+ const [mounted, setMounted] = createSignal(true);
37
+ render(() => <Show fallback={'Not mounted'} when={mounted()}><Editor /></Show>, container);
38
+
39
+ const editorArea = await vi.waitUntil(() =>
40
+ container.querySelector('iframe')?.contentWindow?.document.getElementById('tinymce'),
41
+ { timeout: 1000, interval: 50 }
42
+ );
43
+ expect(editorArea).to.exist;
44
+
45
+ setTimeout(() => {
46
+ setMounted(false);
47
+ }, 1100)
48
+
49
+ setTimeout(() => {
50
+ expect(editorArea).to.not.exist;
51
+ }, 1200)
52
+ });
53
+
54
+ it("reinitialize on demand", async () => {
55
+ render(() => <SolidEditor licenseKey='gpl' tinymceScriptSrc={['tinymce/tinymce.js']} />, container);
56
+
57
+ const editorArea = await vi.waitUntil(() =>
58
+ container.querySelector('iframe')?.contentWindow?.document.getElementById('tinymce'),
59
+ { timeout: 1000, interval: 50 }
60
+ );
61
+ expect(editorArea).to.exist;
62
+
63
+ setTimeout(() => {
64
+ ScriptLoader.reinitialize();
65
+ expect(editorArea).to.not.exist;
66
+ }, 1100)
67
+
68
+ setTimeout(() => {
69
+ expect(editorArea).to.exist;
70
+ }, 1200)
71
+
72
+ });
73
+
74
+ it("reacts to CONTENT changes", async () => {
75
+ const [content, setContent] = createSignal('<p>Hello TinyMCE!</p>');
76
+
77
+ const SolidEditor = () => {
78
+ return (
79
+ <Editor
80
+ id="tiny-mce-test"
81
+ initialValue='Some initial Value'
82
+ value={content()}
83
+ init={{
84
+ height: 500,
85
+ menubar: false,
86
+ placeholder: "Type an email content here...",
87
+ file_picker_types: "image",
88
+ plugins:
89
+ "preview importcss searchreplace autolink autosave save directionality code visualblocks visualchars fullscreen image link media codesample table charmap pagebreak nonbreaking anchor insertdatetime advlist lists wordcount help charmap quickbars emoticons accordion help",
90
+ toolbar:
91
+ "undo redo | blocks fontfamily fontsize | bold italic underline strikethrough | align numlist bullist | link image | table media | lineheight outdent indent| forecolor backcolor removeformat | charmap emoticons | code fullscreen preview | save print | accordion accordionremove | pagebreak anchor codesample | ltr rtl | help",
92
+ }}
93
+ onEditorChange={(newContent: string) => {
94
+ setContent(newContent);
95
+ }}
96
+ />
97
+ );
98
+ };
99
+
100
+ render(() => <SolidEditor />, container);
101
+
102
+ const editorArea = await vi.waitUntil(() => {
103
+ return container.querySelector('iframe')?.contentWindow?.document.getElementById('tinymce');
104
+ }, { timeout: 1000, interval: 50 });
105
+ expect(editorArea).to.exist;
106
+
107
+ setTimeout(() => {
108
+ expect(editorArea?.innerText).to.contain('Hello TinyMCE!');
109
+ setContent('New Content');
110
+ }, 1100)
111
+
112
+ setTimeout(() => {
113
+ expect(editorArea?.innerText).to.contain('New Content');
114
+ }, 1200);
115
+
116
+ setTimeout(() => {
117
+ // console.log(editorArea.innerText);
118
+ expect(editorArea?.innerText).to.contain('testtext');
119
+ expect(editorArea?.innerHTML).to.equal(content());
120
+ }, 1300);
121
+
122
+ });
123
+
124
+ it("reacts to keyboard inputs", async () => {
125
+ const [content, setContent] = createSignal('');
126
+
127
+ const SolidEditor = () => {
128
+ return (
129
+ <Editor
130
+ value={content()}
131
+ onEditorChange={(newContent: string) => {
132
+ setContent(newContent);
133
+ }}
134
+ />
135
+ );
136
+ };
137
+
138
+ render(() => <SolidEditor />, container);
139
+
140
+ const editorArea = await vi.waitUntil(() => {
141
+ return container.querySelector('iframe')?.contentWindow?.document.getElementById('tinymce');
142
+ }, { timeout: 1000, interval: 50 });
143
+ expect(editorArea).to.exist;
144
+
145
+ setTimeout(() => {
146
+ editorArea.focus();
147
+ 'testtext'.split('').forEach(c => {
148
+ editorArea.dispatchEvent(new KeyboardEvent('keypress', { key: c }));
149
+ })
150
+ }, 1100);
151
+
152
+ setTimeout(() => {
153
+ expect(editorArea?.innerText).to.contain('testtext');
154
+ expect(editorArea?.innerHTML).to.equal(content());
155
+ }, 1200);
156
+
157
+ });
158
+
159
+ it("reacts to theme changes", async () => {
160
+ const [skin, setSkin] = createSignal<IAllProps["skin"]>("oxide");
161
+ const [css, setCss] = createSignal<IAllProps["contentCss"]>("default");
162
+ const ToggleDark = () => <button id="dark" onClick={() => {
163
+ setCss(prev => prev === 'default' ? 'dark' : 'default')
164
+ setSkin(prev => prev === 'oxide' ? 'oxide-dark' : 'oxide')
165
+ }}>{css() === 'default' ? "LIGHT" : "DARK"}</button>;
166
+ render(() => <><ToggleDark /><Editor skin={skin()} contentCss={css()} /></>, container);
167
+ const textarea = document.querySelector('textarea');
168
+
169
+ const editorArea = await vi.waitUntil(() =>
170
+ container.querySelector('iframe')?.contentWindow?.document.getElementById('tinymce'), { timeout: 1000, interval: 50 }
171
+ );
172
+ expect(editorArea).to.exist;
173
+
174
+ setTimeout(() => {
175
+ document.getElementById('dark')?.click()
176
+ }, 1200);
177
+
178
+ setTimeout(() => {
179
+ expect(textarea?.dataset.skin).to.equal('oxide-dark');
180
+ expect(textarea?.dataset.css).to.equal('dark');
181
+ }, 1300)
182
+
183
+ setTimeout(() => {
184
+ document.getElementById('dark')?.click()
185
+ }, 1400);
186
+
187
+ setTimeout(() => {
188
+ expect(textarea?.dataset.skin).to.equal('oxide');
189
+ expect(textarea?.dataset.css).to.equal('default');
190
+ }, 1500)
191
+ });
192
+
193
+ it("reacts to DISABLED changes", async () => {
194
+ let editorRef: TinyMCE;
195
+ const [disabled, setDisabled] = createSignal(false);
196
+ const ToggleDisabled = () => <button id="disable" onClick={() => setDisabled(prev => !prev)}>{disabled() ? 'ENABLE' : 'DISABLE'}</button>
197
+
198
+ render(() => <><ToggleDisabled /><Editor onInit={(_, ed) => editorRef = ed} disabled={disabled()} /></>, container);
199
+ const textarea = document.querySelector('textarea');
200
+
201
+ const editorArea = await vi.waitUntil(() => {
202
+ return container.querySelector('iframe')?.contentWindow?.document.getElementById('tinymce');
203
+ }, { timeout: 1000, interval: 50 });
204
+ expect(editorArea).to.exist;
205
+
206
+ document.getElementById('disable')?.click();
207
+
208
+ setTimeout(() => {
209
+ expect(editorRef).to.not.be.undefined;
210
+
211
+ expect(textarea?.dataset.disabled).to.equal('true');
212
+ document.getElementById('disable')?.click()
213
+ }, 100)
214
+
215
+ setTimeout(() => {
216
+ expect(textarea?.dataset.disabled).to.equal('false');
217
+ }, 150)
218
+
219
+ setTimeout(() => {
220
+ document.getElementById('disable')?.click()
221
+ }, 200)
222
+
223
+ setTimeout(() => {
224
+ expect(textarea?.dataset.disabled).to.equal('true');
225
+ }, 250)
226
+ });
227
+ });
package/tsconfig.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "allowJs": true,
13
13
  "strict": true,
14
14
  "noEmit": true,
15
- "types": ["vite/client", "node"],
15
+ "types": ["vite/client", "vitest/globals", "node"],
16
16
  "isolatedModules": true,
17
17
  "baseUrl": ".",
18
18
  "paths": {
@@ -20,6 +20,6 @@
20
20
  "@/*": ["./demo/*"],
21
21
  }
22
22
  },
23
- "include": ["src"],
24
- "exclude": ["node_modules", "dist", "demo", "experiments"]
23
+ "include": ["src", "test", "demo", "vitest.config-ui.ts", "vitest.config.ts"],
24
+ "exclude": ["node_modules", "dist", "experiments"]
25
25
  }
@@ -0,0 +1,31 @@
1
+ import { defineConfig } from "vitest/config";
2
+ import solid from "vite-plugin-solid";
3
+ import path from "node:path";
4
+
5
+ export default defineConfig({
6
+ plugins: [solid()],
7
+ resolve: {
8
+ conditions: ["development", "browser"],
9
+ alias: {
10
+ "~": path.resolve(__dirname, "src"),
11
+ "@": path.resolve(__dirname),
12
+ },
13
+ },
14
+ publicDir: path.resolve(__dirname, "demo/public"),
15
+ test: {
16
+ globals: true,
17
+ coverage: {
18
+ provider: "istanbul",
19
+ reporter: ["html", "text", "lcov"],
20
+ enabled: true,
21
+ include: ["src/**/*.{ts,tsx}"],
22
+ },
23
+ browser: {
24
+ provider: 'preview', // or 'webdriverio'
25
+ enabled: true,
26
+ headless: false,
27
+ name: 'chromium', // browser name is required
28
+ // enableUI: true
29
+ },
30
+ },
31
+ });
@@ -0,0 +1,30 @@
1
+ import { defineConfig } from "vitest/config";
2
+ import solid from "vite-plugin-solid";
3
+ import path from "node:path";
4
+
5
+ export default defineConfig({
6
+ plugins: [solid()],
7
+ resolve: {
8
+ conditions: ["development", "browser"],
9
+ alias: {
10
+ "~": path.resolve(__dirname, "src"),
11
+ "@": path.resolve(__dirname),
12
+ },
13
+ },
14
+ publicDir: path.resolve(__dirname, "demo/public"),
15
+ test: {
16
+ globals: true,
17
+ coverage: {
18
+ provider: "istanbul",
19
+ reporter: ["html", "text", "lcov"],
20
+ enabled: true,
21
+ include: ["src/**/*.{ts,tsx}"],
22
+ },
23
+ browser: {
24
+ provider: 'playwright', // or 'webdriverio'
25
+ enabled: true,
26
+ headless: true,
27
+ name: 'chromium', // browser name is required
28
+ },
29
+ },
30
+ });