Selection changed event

Are there any events produced by xd? I’m looking for selection changed event.

Do you have access to the prerelease? That’s all in the documentation for panels.

Yes, I do. Do you mean this documentation https://github.com/AdobeXD/plugin-docs/tree/uxp-panel-release?

Yes, I think that’s the right link.

Can you share more specific link? I don’t see it. In what part of documentation events were described?

There are no document events. There is an update() method that’s called when selection changes in your plugin panel. This contains all updates to a document like move, resize and selection change.

Ah, ok, I got it, so update lives here: https://github.com/AdobeXD/plugin-docs/blob/uxp-panel-release/reference/structure/handlers.md#for-panels

Yes. They will post more documentation soon. In your manifest you have something like this:

"uiEntryPoints": [
    {
        "type": "menu",
        "label": "My Plugin",
        "menuItems": [
            {
                "type": "menu",
                "label": "My Dialog",
                "commandId": "showDialog",
                "shortcut": { "mac": "", "win": "" }
            }
        ]
    },
    {
        "type": "panel",
        "label": "Panel",
        "panelId": "myPanel"
    }
]

And in your main.js you have something like this (you may or may not need async):

module.exports = {
	commands: {
		showDialog: showDialog
	},
	panels: {
		"myPanel": {
			async show(event) {
				const { selection, root } = require("scenegraph");
				var node = event.node;

				try {
					panelNode = node;
					panelVisible = true;
					
					await showDialog(selection, root, true);
				}
				catch (error) {
					log(error.stack);
				}
			},

			hide(event) {
				panelVisible = false;

				if (event.node && event.node.firstElementChild) {
					event.node.firstElementChild.remove();
				}
			},

			// entry point for selection changes, move, resize, delete
			async update() {
				const { selection, root } = require("scenegraph");

				if (panelVisible==false) {
					return;
				}

				var time = getTime();

				await showDialog(selection, root, true);

				time = getTime() - time;
			}
		}
  }
1 Like