@novaprose/tinymce-compat 0.6.0 → 0.7.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.
Files changed (43) hide show
  1. package/README.md +10 -3
  2. package/dist/index.cjs +38 -0
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +20 -6
  5. package/dist/index.d.ts +20 -6
  6. package/dist/index.js +39 -1
  7. package/dist/index.js.map +1 -1
  8. package/dist/novaprose.css +187 -31
  9. package/dist/tinymce-chunks/advlist-7a360f16.js +2 -0
  10. package/dist/tinymce-chunks/advlist-7a360f16.js.map +7 -0
  11. package/dist/tinymce-chunks/autolink-7e2e7be2.js +2 -0
  12. package/dist/tinymce-chunks/autolink-7e2e7be2.js.map +7 -0
  13. package/dist/tinymce-chunks/autoresize-d6c9537b.js +2 -0
  14. package/dist/tinymce-chunks/autoresize-d6c9537b.js.map +7 -0
  15. package/dist/tinymce-chunks/autosave-4fd46720.js +2 -0
  16. package/dist/tinymce-chunks/autosave-4fd46720.js.map +7 -0
  17. package/dist/tinymce-chunks/charmap-4b14307a.js +2 -0
  18. package/dist/tinymce-chunks/charmap-4b14307a.js.map +7 -0
  19. package/dist/tinymce-chunks/comments-panel-37cba890.js +2 -0
  20. package/dist/tinymce-chunks/comments-panel-37cba890.js.map +7 -0
  21. package/dist/tinymce-chunks/directionality-60dba768.js +2 -0
  22. package/dist/tinymce-chunks/directionality-60dba768.js.map +7 -0
  23. package/dist/tinymce-chunks/emoticons-7e6da0b6.js +2 -0
  24. package/dist/tinymce-chunks/emoticons-7e6da0b6.js.map +7 -0
  25. package/dist/tinymce-chunks/form-dialog-9cde0ef7.js +2 -0
  26. package/dist/tinymce-chunks/form-dialog-9cde0ef7.js.map +7 -0
  27. package/dist/tinymce-chunks/insertdatetime-e0dbcf63.js +2 -0
  28. package/dist/tinymce-chunks/insertdatetime-e0dbcf63.js.map +7 -0
  29. package/dist/tinymce-chunks/nonbreaking-49bdb0d2.js +2 -0
  30. package/dist/tinymce-chunks/nonbreaking-49bdb0d2.js.map +7 -0
  31. package/dist/tinymce-chunks/paste-office-a38659d6.js +3 -0
  32. package/dist/tinymce-chunks/paste-office-a38659d6.js.map +7 -0
  33. package/dist/tinymce-chunks/quickbars-d937e10a.js +2 -0
  34. package/dist/tinymce-chunks/quickbars-d937e10a.js.map +7 -0
  35. package/dist/tinymce-chunks/revisionhistory-d6306426.js +2 -0
  36. package/dist/tinymce-chunks/revisionhistory-d6306426.js.map +7 -0
  37. package/dist/tinymce-chunks/table-80284f6f.js +2 -0
  38. package/dist/tinymce-chunks/table-80284f6f.js.map +7 -0
  39. package/dist/tinymce-chunks/visualblocks-58c88e5d.js +2 -0
  40. package/dist/tinymce-chunks/visualblocks-58c88e5d.js.map +7 -0
  41. package/dist/tinymce.global.js +23 -23
  42. package/dist/tinymce.global.js.map +7 -1
  43. package/package.json +11 -6
package/README.md CHANGED
@@ -13,7 +13,7 @@ without rewriting it — then move to the native API when you are ready.
13
13
  <!-- before -->
14
14
  <script src="https://cdn.tiny.cloud/1/your-api-key/tinymce/7/tinymce.min.js"></script>
15
15
  <!-- after -->
16
- <script src="https://cdn.jsdelivr.net/npm/@novaprose/tinymce-compat/dist/tinymce.global.js"></script>
16
+ <script src="https://cdn.jsdelivr.net/npm/@novaprose/tinymce-compat@0.7/dist/tinymce.global.js"></script>
17
17
 
18
18
  <script>
19
19
  tinymce.init({
@@ -27,6 +27,11 @@ without rewriting it — then move to the native API when you are ready.
27
27
  The script sets `window.tinymce` and loads its stylesheet (`novaprose.css`, next to the script).
28
28
  `init()` can run in `<head>`: it waits for the document like TinyMCE.
29
29
 
30
+ Parts that most pages never need (table editing, optional plugins, Office paste cleanup, plugin
31
+ dialogs) are separate files in `dist/tinymce-chunks/`, loaded on demand from the same address as the script.
32
+ To host the files yourself, copy the whole `dist` folder — the script, `novaprose.css` and `tinymce-chunks/`.
33
+ Chunk file names include a content hash, so caches never mix files from different versions.
34
+
30
35
  ## npm
31
36
 
32
37
  ```bash
@@ -60,7 +65,8 @@ editor.on('change', () => console.log(editor.getContent()));
60
65
  (`formats` option, `formatter.register`). **`editor.selection`**: `getContent`, `setContent`, `getNode`,
61
66
  `isCollapsed`, `collapse`, `setCursorLocation`, `select`.
62
67
  - **`editor.ui.registry`**: `addButton`, `addToggleButton` (with `onSetup` and `api.setActive`),
63
- `addMenuButton` (`fetch`), `addMenuItem`, `addContextToolbar`, `addIcon`; TinyMCE icon names map to
68
+ `addMenuButton` (`fetch`), `addMenuItem`, `addContextToolbar`, `addSidebar` (with
69
+ `ToggleSidebar` and `queryCommandValue`), `addIcon`; TinyMCE icon names map to
64
70
  NovaProse icons.
65
71
  - **Events**: `init`, `input`, `change` (on blur after edits), `NodeChange`, `focus`, `blur`,
66
72
  `keydown`, `keyup`, `click`, `paste`, `SetContent`, `GetContent`, `SaveContent`, `ExecCommand`,
@@ -70,7 +76,8 @@ editor.on('change', () => console.log(editor.getContent()));
70
76
  `style_formats_merge`, `valid_classes`, `table_class_list`, `table_cell_class_list` (without it all classes are kept, as in TinyMCE), `language`,
71
77
  `inline`, `height`/`min_height`/`max_height`/`width`, `content_style`, `content_css` (your files; skin names
72
78
  like `default` or `dark` are ignored), `images_upload_handler`,
73
- `paste_as_text`, `paste_preprocess`, `valid_elements`/`invalid_elements`/`valid_styles`,
79
+ `paste_as_text`, `paste_preprocess`, `valid_elements` (with attribute rules)/`invalid_elements`/`valid_styles`,
80
+ `extended_valid_elements`, `custom_elements`, `directionality`,
74
81
  `font_family_formats`, `font_size_formats`, `line_height_formats`, `color_map`, `toolbar_mode`,
75
82
  `setup`, `init_instance_callback`, `autosave_*`, `quickbars_*`, `mentions_fetch`.
76
83
  - Form submit writes the HTML back into the textarea.
package/dist/index.cjs CHANGED
@@ -27,6 +27,7 @@ __export(src_exports, {
27
27
  });
28
28
  module.exports = __toCommonJS(src_exports);
29
29
  var import_core3 = require("@novaprose/core");
30
+ var import_html_rules = require("@novaprose/core/html-rules");
30
31
 
31
32
  // src/options.ts
32
33
  var import_core = require("@novaprose/core");
@@ -112,6 +113,9 @@ var IGNORED = /* @__PURE__ */ new Set([
112
113
  "paste_postprocess",
113
114
  "invalid_elements",
114
115
  "valid_elements",
116
+ "directionality",
117
+ "extended_valid_elements",
118
+ "custom_elements",
115
119
  "valid_styles",
116
120
  "toolbar_mode",
117
121
  "toolbar_sticky",
@@ -283,6 +287,11 @@ function mapOptions(config) {
283
287
  if (typeof config.invalid_elements === "string")
284
288
  options.invalidElements = config.invalid_elements;
285
289
  if (typeof config.valid_elements === "string") options.validElements = config.valid_elements;
290
+ if (typeof config.extended_valid_elements === "string")
291
+ options.extendedValidElements = config.extended_valid_elements;
292
+ if (typeof config.custom_elements === "string") options.customElements = config.custom_elements;
293
+ if (config.directionality === "rtl" || config.directionality === "ltr")
294
+ options.direction = config.directionality;
286
295
  if (config.valid_styles) options.validStyles = config.valid_styles;
287
296
  const fonts = parseFormats(config.font_family_formats);
288
297
  if (fonts) options.fontFamilies = fonts;
@@ -873,6 +882,11 @@ var CompatEditor = class {
873
882
  return this.core.root.ownerDocument.defaultView;
874
883
  }
875
884
  // ---------- команды ----------
885
+ /** Значение команды: ToggleSidebar — имя открытой боковой панели. */
886
+ queryCommandValue(command) {
887
+ if (command.toLowerCase() === "togglesidebar") return this.core.ui.sidebar.active ?? "";
888
+ return "";
889
+ }
876
890
  execCommand(command, _ui, value) {
877
891
  const name = command.toLowerCase();
878
892
  let done = false;
@@ -883,6 +897,9 @@ var CompatEditor = class {
883
897
  } else if (name === "mceinsertcontent" || name === "inserthtml") {
884
898
  this.insertContent(String(value ?? ""));
885
899
  done = true;
900
+ } else if (name === "togglesidebar") {
901
+ void this.core.ui.sidebar.toggle(String(value ?? ""));
902
+ done = true;
886
903
  } else if (name === "mcesetcontent") {
887
904
  this.setContent(String(value ?? ""));
888
905
  done = true;
@@ -1169,6 +1186,26 @@ var CompatEditor = class {
1169
1186
  }
1170
1187
  });
1171
1188
  },
1189
+ /**
1190
+ * Боковая панель: onSetup(api) рисует содержимое в api.element() (один раз), onShow/onHide —
1191
+ * при показе. Кнопка-переключатель с именем панели — для toolbar; ToggleSidebar — командой.
1192
+ */
1193
+ addSidebar: (name, spec) => {
1194
+ let element = null;
1195
+ const api = { element: () => element };
1196
+ const icon = resolveIcon(spec.icon);
1197
+ this.core.ui.registry.addSidebar(name, {
1198
+ title: spec.tooltip ?? name,
1199
+ ...icon ? { icon } : {},
1200
+ render: (container) => {
1201
+ element = container;
1202
+ const cleanup = spec.onSetup?.(api);
1203
+ return typeof cleanup === "function" ? cleanup : void 0;
1204
+ },
1205
+ onShow: () => spec.onShow?.(api),
1206
+ onHide: () => spec.onHide?.(api)
1207
+ });
1208
+ },
1172
1209
  addContextForm: () => {
1173
1210
  console.warn("[nova] tinymce-compat: addContextForm is not supported yet");
1174
1211
  },
@@ -1363,6 +1400,7 @@ function warnOnce(message) {
1363
1400
  var counter = 0;
1364
1401
  var px = (value) => typeof value === "number" ? `${value}px` : String(value);
1365
1402
  function createTinymce() {
1403
+ (0, import_core3.registerHtmlRules)(import_html_rules.htmlRules);
1366
1404
  const all = [];
1367
1405
  const plugins = /* @__PURE__ */ new Map();
1368
1406
  let active = null;