markupeditor 0.9.32 → 0.9.34

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.
@@ -235,9 +235,14 @@ class Registry {
235
235
 
236
236
  /**
237
237
  * Add `plugin` to the registry, keyed by `name`.
238
+ * A `plugin` object has `name` and `type` string properties at minimum.
239
+ * The invoker can add additional properties to the `plugin`.
240
+ * For example, a `run` function could be part of the `plugin`, which could,
241
+ * by convention of the application environment the markupeditor is used in,
242
+ * be used to run the `plugin` to perform some action or return something.
238
243
  *
239
- * @param {object} plugin Plugin object with string values for { name, type, filename }.
240
- * @param {string} name The key used to retrieve and invoke the plugin.
244
+ * @param {object} plugin Plugin object with string properties for {name, type} at minimum.
245
+ * @param {string} name The key used to retrieve and invoke the plugin. Taken from `plugin.name` by default.
241
246
  */
242
247
  registerPlugin(plugin, name) {
243
248
  this._plugins.set(name ?? plugin.name, plugin);
@@ -256,17 +261,17 @@ class Registry {
256
261
  * Return the plugin object with `name`, or undefined if not found.
257
262
  *
258
263
  * @param {string} name The key used to identify the plugin.
259
- * @returns {object|undefined}
264
+ * @returns {object | undefined}
260
265
  */
261
266
  getPlugin(name) {
262
267
  return this._plugins.get(name)
263
268
  }
264
269
 
265
270
  /**
266
- * Return an array of registered plugins that match type, all if not specified.
267
- * Each entry contains {name, type, filename}
271
+ * Return an array of registered plugins that match `type`, all if not specified.
268
272
  *
269
- * @returns {Array<{name: string, type: string, filename: string}>}
273
+ * @param {string} type The plugin type to filter by; all plugins are returned if omitted.
274
+ * @returns {Array<object>} Array of plugin objects with string properties for {name, type} at minimum.
270
275
  */
271
276
  getPlugins(type) {
272
277
  if (type) {
@@ -512,10 +517,15 @@ const setSelectedID = _registry.setSelectedID.bind(_registry);
512
517
 
513
518
  /**
514
519
  * Add `plugin` to the registry, keyed by `name`.
520
+ * A `plugin` object has `name` and `type` string properties at minimum.
521
+ * The invoker can add additional properties to the `plugin`.
522
+ * For example, a `run` function could be part of the `plugin`, which could,
523
+ * by convention of the application environment the markupeditor is used in,
524
+ * be used to run the `plugin` to perform some action or return something.
515
525
  *
516
526
  * @function
517
- * @param {object} plugin Plugin object with string values for { name, type, filename }.
518
- * @param {string} name The key used to retrieve and invoke the plugin.
527
+ * @param {object} plugin Plugin object with string properties for {name, type} at minimum.
528
+ * @param {string} name The key used to retrieve and invoke the plugin. Taken from `plugin.name` by default.
519
529
  */
520
530
  const registerPlugin = _registry.registerPlugin.bind(_registry);
521
531
 
@@ -538,14 +548,36 @@ const getPlugin = _registry.getPlugin.bind(_registry);
538
548
 
539
549
  /**
540
550
  * Return an array of registered plugins that match `type`, all if not specified.
541
- * Each entry contains {name, type, filename}
542
551
  *
543
552
  * @function
544
- * @param {string} [type] The plugin type to filter by; all plugins are returned if omitted.
545
- * @returns {Array<{name: string, type: string, filename: string}>}
553
+ * @param {string} type The plugin type to filter by; all plugins are returned if omitted.
554
+ * @returns {Array<object>} Array of plugin objects with string properties for {name, type} at minimum.
546
555
  */
547
556
  const getPlugins = _registry.getPlugins.bind(_registry);
548
557
 
558
+ /**
559
+ * Look up the plugin with `name` and invoke its `run` function, returning/awaiting whatever
560
+ * it resolves to.
561
+ *
562
+ * Content-agnostic and plugin-type-agnostic: `runPlugin` never fetches or supplies content
563
+ * on the plugin's behalf. The plugin's `run` function is responsible for getting
564
+ * whatever content it needs, via whichever accessor (e.g. `getHTML`) fits its purpose.
565
+ *
566
+ * Returns `null`, never rejects, when there's nothing to run: no plugin registered with
567
+ * `name`, or a plugin registered without a `run` function. If `run` itself rejects, that
568
+ * rejection propagates unchanged — it is not swallowed into `null`, so a caller can't
569
+ * confuse "nothing to run" with "the plugin failed."
570
+ *
571
+ * @function
572
+ * @param {string} name The key used to identify the plugin.
573
+ * @returns {Promise<*>} Whatever `plugin.run()` resolves to, or `null`.
574
+ */
575
+ async function runPlugin(name) {
576
+ const plugin = getPlugin(name);
577
+ if (!plugin?.run) return null
578
+ return await plugin.run()
579
+ }
580
+
549
581
  /**
550
582
  * MUError captures internal errors and makes it easy to communicate them externally.
551
583
  *
@@ -42563,6 +42595,7 @@ const MU = {
42563
42595
  unregisterPlugin,
42564
42596
  getPlugin,
42565
42597
  getPlugins,
42598
+ runPlugin,
42566
42599
  };
42567
42600
 
42568
42601
  sheet.media.mediaText = '(prefers-color-scheme: dark)';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markupeditor",
3
- "version": "0.9.32",
3
+ "version": "0.9.34",
4
4
  "description": "A web component and API for WYSIWYG HTML editing.",
5
5
  "keywords": [
6
6
  "wysiwyg",