CreateProperties constructor

CreateProperties({
  1. ItemType? type,
  2. String? id,
  3. String? title,
  4. bool? checked,
  5. List<ContextType>? contexts,
  6. bool? visible,
  7. JSFunction? onclick,
  8. Object? parentId,
  9. List<String>? documentUrlPatterns,
  10. List<String>? targetUrlPatterns,
  11. bool? enabled,
})

Implementation

CreateProperties({
  /// The type of menu item. Defaults to `normal`.
  ItemType? type,

  /// The unique ID to assign to this item. Mandatory for event pages. Cannot
  /// be the same as another ID for this extension.
  String? id,

  /// The text to display in the item; this is _required_ unless `type` is
  /// `separator`. When the context is `selection`, use `%s` within the string
  /// to show the selected text. For example, if this parameter's value is
  /// "Translate '%s' to Pig Latin" and the user selects the word "cool", the
  /// context menu item for the selection is "Translate 'cool' to Pig Latin".
  String? title,

  /// The initial state of a checkbox or radio button: `true` for selected,
  /// `false` for unselected. Only one radio button can be selected at a time
  /// in a given group.
  bool? checked,

  /// List of contexts this menu item will appear in. Defaults to `['page']`.
  List<ContextType>? contexts,

  /// Whether the item is visible in the menu.
  bool? visible,

  /// A function that is called back when the menu item is clicked. This is
  /// not available inside of a service worker; instead, they should register
  /// a listener for [contextMenus.onClicked].
  JSFunction? onclick,

  /// The ID of a parent menu item; this makes the item a child of a
  /// previously added item.
  Object? parentId,

  /// Restricts the item to apply only to documents or frames whose URL
  /// matches one of the given patterns. For details on pattern formats, see
  /// [Match Patterns](/docs/extensions/develop/concepts/match-patterns).
  List<String>? documentUrlPatterns,

  /// Similar to `documentUrlPatterns`, filters based on the `src` attribute
  /// of `img`, `audio`, and `video` tags and the `href` attribute of `a`
  /// tags.
  List<String>? targetUrlPatterns,

  /// Whether this context menu item is enabled or disabled. Defaults to
  /// `true`.
  bool? enabled,
}) : _wrapped = $js.CreateProperties(
        type: type?.toJS,
        id: id,
        title: title,
        checked: checked,
        contexts: contexts?.toJSArray((e) => e.toJS),
        visible: visible,
        onclick: onclick,
        parentId: switch (parentId) {
          int() => parentId.jsify()!,
          String() => parentId.jsify()!,
          null => null,
          _ => throw UnsupportedError(
              'Received type: ${parentId.runtimeType}. Supported types are: int, String')
        },
        documentUrlPatterns: documentUrlPatterns?.toJSArray((e) => e),
        targetUrlPatterns: targetUrlPatterns?.toJSArray((e) => e),
        enabled: enabled,
      );