Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): add plugin API #363

Closed
wants to merge 78 commits into from
Closed

feat(core): add plugin API #363

wants to merge 78 commits into from

Conversation

bcakmakoglu
Copy link
Owner

@bcakmakoglu bcakmakoglu commented Oct 18, 2022

To-Do's

  • update changeset (description of plugin API as in PR)

DnD

  • add touch support - will be handled in a later release!
    • touchstart
    • touchmove
  • auto-bind dragOver and drop to vue flow dom ref (in store)

What's changed?

  • Allow setting global store config that is applied as default to all stores that are created
  • A simple API to extend the vue flow store (⚠️ NOT a Vue Plugin)
  • Provide hooks to hook into store lifecycles (beforeCreate, created, beforeDestroy, destroyed)
  • Add some simple plugins to start off
    • DnD Plugin
    • Dagre Layout
    • Screenshot

Types

interface PluginHooks {
  beforeCreate: EventHookOn<[string, FlowOptions | undefined]>
  created: EventHookOn<[VueFlowStore, (plugin: Partial<VueFlowStore>) => void]>
  beforeDestroy: EventHookOn<VueFlowStore>
  destroyed: EventHookOn<string>
}

type Plugin = (hooks: PluginHooks) => void

Example

// main.ts or your App entry point
import { createVueFlow, Plugin } from '@vue-flow/core'

const plugin: Plugin = (hooks) => {
 hooks.beforeCreate(([id, preloadedState]) => {
  // do something before a store instance is created
 }
    
 // after a store has been created
 hooks.created(([store, extend]) => {})
    
 // before a store is destroyed
 hooks.beforeDestroy((store) => {})

 // after a store is destroyed
 hooks.destroyed(() => {})
}

// You can pass a factory function to set default values to each new store instance
const vueFlowApp = createVueFlow(() => ({ 
  fitViewOnInit: true,
}))

vueFlowApp.use(plugin)

Extending Store Type (TypeScript shims)

declare module '@vue-flow/core' {
  interface StoreBase {
    myProperty: boolean
    myRefProperty: Ref<boolean>
  }
}

@changeset-bot
Copy link

changeset-bot bot commented Oct 18, 2022

🦋 Changeset detected

Latest commit: 3fae582

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 10 packages
Name Type
@vue-flow/plugin-drag-n-drop Major
@vue-flow/plugin-layout Major
@vue-flow/core Major
@vue-flow/plugin-screenshot Major
@vue-flow/background Major
@vue-flow/controls Major
@vue-flow/minimap Major
@vue-flow/node-resizer Major
@vue-flow/node-toolbar Major
@vue-flow/pathfinding-edge Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Oct 18, 2022

Deployment failed with the following error:

Resource is limited - try again in 9 hours (more than 100, code: "api-deployments-free-per-day").

@bcakmakoglu bcakmakoglu self-assigned this Oct 18, 2022
@bcakmakoglu bcakmakoglu added the enhancement New feature or request label Oct 18, 2022
@bcakmakoglu bcakmakoglu added this to the Plugin API milestone Oct 18, 2022
@vercel
Copy link

vercel bot commented Oct 25, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
vue-flow-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 15, 2023 9:09pm
vue-flow-typedoc ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 15, 2023 9:09pm

@vercel vercel bot temporarily deployed to Preview – vue-flow-typedoc October 25, 2022 15:46 Inactive
@vercel vercel bot temporarily deployed to Preview – vue-flow-typedoc November 4, 2022 21:20 Inactive
@vercel vercel bot temporarily deployed to Preview – vue-flow-typedoc November 4, 2022 21:36 Inactive
@vercel vercel bot temporarily deployed to Preview – vue-flow-typedoc November 4, 2022 23:37 Inactive
@vercel vercel bot temporarily deployed to Preview – vue-flow-typedoc November 5, 2022 07:15 Inactive
@vercel vercel bot temporarily deployed to Preview – vue-flow-typedoc November 5, 2022 10:22 Inactive
@vercel vercel bot temporarily deployed to Preview – vue-flow-typedoc November 5, 2022 18:47 Inactive
@vercel vercel bot temporarily deployed to Preview – vue-flow-typedoc November 6, 2022 11:03 Inactive
@vercel vercel bot temporarily deployed to Preview – vue-flow-typedoc November 6, 2022 16:53 Inactive
@vercel vercel bot temporarily deployed to Preview – vue-flow-typedoc November 6, 2022 18:45 Inactive
Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant