PocketBlocks Docs
English
English
  • Overview
  • Installation
  • Build apps
    • Create a new app
    • App editor
    • Event handlers
    • Write JavaScript
      • Write JavaScript in {{ }}
      • JavaScript query
      • Transformers
      • Temporary state
      • Data responder
      • Built-in JavaScript functions
      • Use third-party libraries
    • Component guides
      • Option lists
      • List View
      • Drawer
      • Image
      • Charts and graphs
      • File upload
      • Custom component
      • Use Markdown
    • Module
    • Design app UI
      • Style, theme, and usability
      • Design an efficient and user-friendly form
    • Navigation
    • Keyboard shortcuts
    • Version and release management
  • Build plugins
    • Develop UI component plugins
  • Workspace management
    • Authentication
    • Members and groups
    • Permissions for resources
    • Custom branding
  • Miscellaneous
    • Where are the Data Sources/Query Library?
    • Embedding Apps
Powered by GitBook
On this page
  • Built-in libraries
  • Manually import third-party libraries
  • At app-level
  • At workspace-level
  1. Build apps
  2. Write JavaScript

Use third-party libraries

Every developer learns one of the most important principles of software engineering early in their career: DRY (Don’t Repeat Yourself). Using third-party libraries can save your time as you do not need to develop the functionality that the library provides. PocketBlocks provides some built-in third-party libraries for common uses, and you can manually import other libraries on demand.

Built-in libraries

PocketBlocks provides some JavaScript built-in libraries for use.

Library
Docs
Version

lodash

4.17.21

moment

2.29.3

uuid

8.3.2(Support v1/v3/v4/v5)

numbro

2.3.6

papaparse(Papa)

5.3.2

PocketBase SDK(pb)

0.21.3

TanStack QueryClient(qc)

5.44.0

Manually import third-party libraries

PocketBlocks supports setting up preloaded JavaScript and libraries which can be at app-level or workspace-level.

  • App-level libraries get loaded only in the app where defined. Plus, app A cannot use libraries that are set up for app B.

  • Workspace-level libraries will be loaded when you open any application in your workspace. All the apps can access those libraries. There can be a certain impact on app performance, especially when you have complex JavaScript functions that aren't being used in every app.

Tips you should know before setting up libraries:

  • External libraries are loaded and run in the browser.

  • NodeJS-only libraries are not supported now.

  • URLs of external libraries need to support cross-domain.

  • The export of the library must be set directly on the window object, global variables like var xxx = xxx do not take effect.

  • The external libraries run in a restricted sandbox environment and the following global variables are not available:

    parent

    document

    location

    chrome

    setTimeout

    fetch

    setInterval

    clearInterval

    setImmediate

    XMLHttpRequest

    importScripts

    Navigator

    MutationObserver

Now let's take cowsay as an example and import it at app-level and workspace-level.

At app-level

Navigate to the settings page and then click the plus sign + under the JavaScript library tab. Paste the cowsay link and click Add New.

Create a JS query and insert code.

You can obtain the same result by calling the cowsay.say() method in the value of the text component.

Note that the cowsay library is imported at app-level and you can not use it in any other app within your workspace.

At workspace-level

Go to PocketBlocks Homepage, select Settings > Advanced, and then click Add under the JavaScript library tab. Paste the link of the third-party JS library and click Add New to add it to your workspace. The installed libraries are accessible from any app within your workspace.

PreviousBuilt-in JavaScript functionsNextComponent guides

Last updated 11 months ago

GitHub page:

Library link:

https://github.com/piuccio/cowsay
https://unpkg.com/cowsay@1.5.0/build/cowsay.umd.js
https://lodash.com/docs/
https://momentjs.com/docs/
https://github.com/uuidjs/uuid
https://numbrojs.com/format.html
https://www.papaparse.com/docs
https://pocketbase.io/docs/client-side-sdks
https://tanstack.com/query/v5/docs/reference/QueryClient