@rg-dev/tinymce-helpers 1.0.3 → 1.0.4

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 (3) hide show
  1. package/index.d.mts +3 -1
  2. package/index.mjs +43 -8
  3. package/package.json +1 -1
package/index.d.mts CHANGED
@@ -23,10 +23,12 @@ type EditorOpts = Omit<RemoveIndexSignature<RawEditorOptions>, 'setup' | 'target
23
23
  declare class tinymceHelpers {
24
24
  private _editor;
25
25
  private _lockButton?;
26
+ private originalContextMenu;
26
27
  private constructor();
27
28
  static initMce(el: HTMLElement, customOpts?: Opts): Promise<tinymceHelpers>;
28
29
  _initMce(el: HTMLElement, customOpts?: Opts): Promise<this>;
29
- toggleEditable(lock?: 'yes' | 'no'): void;
30
+ private setContextMenu;
31
+ toggleReadOnly(lock?: 'yes' | 'no'): void;
30
32
  isEditable(): boolean;
31
33
  setContent(content: string, opts?: {
32
34
  dir?: 'rtl' | 'ltr';
package/index.mjs CHANGED
@@ -109,6 +109,7 @@ var tinymceHelpers = class _tinymceHelpers {
109
109
  constructor() {
110
110
  __publicField(this, "_editor");
111
111
  __publicField(this, "_lockButton");
112
+ __publicField(this, "originalContextMenu");
112
113
  }
113
114
  static async initMce(el, customOpts = Object()) {
114
115
  return await new _tinymceHelpers()._initMce(el, customOpts);
@@ -129,9 +130,18 @@ var tinymceHelpers = class _tinymceHelpers {
129
130
  tooltip: "Lock editing",
130
131
  icon: "lock-icon",
131
132
  onAction: () => {
132
- that.toggleEditable("yes");
133
+ that.toggleReadOnly("yes");
133
134
  }
134
135
  });
136
+ editor.on("keydown", (e) => {
137
+ if (e.key !== "Enter" || !e.shiftKey) {
138
+ return;
139
+ }
140
+ e.preventDefault();
141
+ e.stopImmediatePropagation();
142
+ editor.getDoc().execCommand("insertParagraph", false, void 0);
143
+ editor.nodeChanged();
144
+ }, true);
135
145
  editor.ui.registry.addMenuItem(
136
146
  "create-block-below",
137
147
  {
@@ -176,7 +186,7 @@ var tinymceHelpers = class _tinymceHelpers {
176
186
  {
177
187
  text: "toggle readonly",
178
188
  onAction: async () => {
179
- that.toggleEditable();
189
+ that.toggleReadOnly();
180
190
  }
181
191
  }
182
192
  );
@@ -248,7 +258,7 @@ var tinymceHelpers = class _tinymceHelpers {
248
258
  content_style: theSkin.css,
249
259
  body_class: "my-custom-styles",
250
260
  target: el,
251
- toolbar: "lockContent | undo redo | increaseFontSize decreaseFontSize bold italic underline strikethrough | fontfamily fontsize | ltr rtl alignleft aligncenter alignright alignjustify | outdent indent | numlist bullist | forecolor backcolor removeformat | charmap emoticons | fullscreen preview save print | insertfile image media template link anchor codesample",
261
+ toolbar: "lockContent | undo redo | increaseFontSize decreaseFontSize bold italic underline strikethrough | fontfamily fontsize | ltr rtl alignleft aligncenter alignright alignjustify | outdent indent | numlist bullist | forecolor backcolor removeformat | charmap emoticons | fullscreen preview print | image media link anchor codesample",
252
262
  toolbar_sticky: true,
253
263
  promotion: false,
254
264
  image_advtab: true,
@@ -287,8 +297,24 @@ var tinymceHelpers = class _tinymceHelpers {
287
297
  throw new Error("no skin");
288
298
  }
289
299
  const mce = this._editor = await tinymce.init(opts).then((x) => x[0]);
300
+ this.originalContextMenu = mce.options.get("contextmenu");
290
301
  const all = mce.ui.registry.getAll();
291
302
  const availableMenuItems = all.menuItems;
303
+ const availableButtons = all.buttons;
304
+ if (typeof opts.toolbar == "string") {
305
+ if (!isNonEmptyString(opts.toolbar.trim())) {
306
+ console.error("Toolbar is missing items");
307
+ } else {
308
+ const items = opts.toolbar.trim().split(/\s+/).filter((item) => item !== "|");
309
+ for (const item of items) {
310
+ if (!availableButtons[item.toLowerCase()] && !availableMenuItems[item.toLowerCase()]) {
311
+ console.error(
312
+ `Toolbar references unknown button "${item}"`
313
+ );
314
+ }
315
+ }
316
+ }
317
+ }
292
318
  if (typeof opts.contextmenu == "string") {
293
319
  if (!isNonEmptyString(opts.contextmenu.trim())) {
294
320
  console.error("Context menu is missing items");
@@ -325,7 +351,15 @@ var tinymceHelpers = class _tinymceHelpers {
325
351
  this.createLockButton();
326
352
  return this;
327
353
  }
328
- toggleEditable(lock) {
354
+ setContextMenu(enabled) {
355
+ var _a;
356
+ if (!enabled) {
357
+ this.editor.options.set("contextmenu", false);
358
+ } else {
359
+ this.editor.options.set("contextmenu", (_a = this.originalContextMenu) != null ? _a : "");
360
+ }
361
+ }
362
+ toggleReadOnly(lock) {
329
363
  let curr = this.editor.getBody().isContentEditable;
330
364
  if (lock) {
331
365
  if (lock == "no") {
@@ -339,6 +373,7 @@ var tinymceHelpers = class _tinymceHelpers {
339
373
  if (editorBar) {
340
374
  editorBar.style.display = curr ? "none" : "";
341
375
  }
376
+ this.setContextMenu(!curr);
342
377
  this.editor.setEditableRoot(!curr);
343
378
  this.updateLockButton();
344
379
  }
@@ -347,7 +382,7 @@ var tinymceHelpers = class _tinymceHelpers {
347
382
  }
348
383
  setContent(content, opts = Object()) {
349
384
  if (opts.lock != void 0) {
350
- this.toggleEditable(opts.lock ? "yes" : "no");
385
+ this.toggleReadOnly(opts.lock ? "yes" : "no");
351
386
  }
352
387
  if (opts.dir) {
353
388
  this.toggleTextDirection(opts.dir);
@@ -408,13 +443,13 @@ var tinymceHelpers = class _tinymceHelpers {
408
443
  padding:0;
409
444
  border-radius:6px;
410
445
  border:1px solid rgba(0,0,0,0.15);
411
- background:#fff;
412
- color:#333;
446
+ background:black;
447
+ color:rgb(255, 255, 255);;
413
448
  cursor:pointer;
414
449
  box-shadow:0 1px 3px rgba(0,0,0,0.2);
415
450
  `;
416
451
  btn.addEventListener("click", () => {
417
- this.toggleEditable();
452
+ this.toggleReadOnly();
418
453
  });
419
454
  if (getComputedStyle(container).position === "static") {
420
455
  container.style.position = "relative";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rg-dev/tinymce-helpers",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {