API Reference
Namespaces
Modules
Classes
Events
Global
Externals

Class: Workspaces

CIQ. Workspaces ()

Manages saved workspaces (complete template snapshots) including multi-chart layouts, drawings, and preferences. This is a singleton service that handles all workspace-related operations.

Data Model:

  • sharedWorkspaces: Metadata keyed by workspace ID, shared across all charts
  • loadedWorkspacePerChart: Object mapping chartId → active workspace ID
  • "none" is UI state only, not stored

Full records are stored individually under stx-workspaces/{id}. The collection key stx-workspaces returns metadata keyed by ID, refetched after each save/delete. See CIQ.Workspaces#initialize for the storage adapter contract.


new Workspaces()

Since:
  • 10.5.0
  • 10.6.0 Stores individual workspace records and caches queried metadata.

Members


<static> ToastType :ToastType

READ ONLY. Toast notification types accepted by CIQ.Workspaces#showToast.

Type:
  • ToastType
Since:
  • 10.5.0


<static> description :string

Sentence shown in the workspace menu's info blurb, shared by every chart on the page using the workspace plugin. Set before calling getDefaultConfig().

Type:
  • string
Since:
  • 10.6.0


<static> displayName :string

User-facing feature name, shared by every chart on the page using the workspace plugin. Set before calling getDefaultConfig() to rename the feature everywhere (menus, dialogs, toasts, error messages) without invoking a separate setup function; getDefaultConfig() bakes this value into the toggle markup, menu entry, and dialog titles once, so changing it afterward has no effect.

Type:
  • string
Since:
  • 10.6.0

Methods


collectCurrentState(contextElement)

Collect current state from all charts

Parameters:
Name Type Description
contextElement HTMLElement

cq-context or multiChartContainer element

Since:
  • 10.5.0

Throws:

A chart fails to export its layout, drawings, or preferences.

Type
Error
Returns:

Current state with grid and charts

Type
object

<async> createWorkspace(name, contextElement)

Create a new workspace with current chart state

Parameters:
Name Type Description
name string

Workspace name

contextElement HTMLElement

cq-context or multiChartContainer element

Since:
  • 10.5.0
  • 10.6.0 Returns the ID and saved record after persistence, without caching full records.
Returns:

Result containing id and the persisted workspace, or null when state collection fails; rejects on storage errors

Type
Promise.<(object|null)>
Example
const result = await manager.createWorkspace("My Workspace", contextElement);
if (result) console.log(result.id, result.workspace);

deleteWorkspace(workspaceId, contextElement)

Delete a workspace

Parameters:
Name Type Description
workspaceId string

Workspace ID

contextElement HTMLElement

cq-context or multiChartContainer element

Since:
  • 10.5.0
  • 10.6.0 Removes the selected record without fetching it.
Returns:

Whether deletion succeeded; rejects on storage errors

Type
Promise.<boolean>

findUserWorkspaceByName(name [, excludeId])

Find a user-created (non-admin) workspace by trimmed, case-insensitive name.

Parameters:
Name Type Argument Description
name string

Workspace name

excludeId string <optional>

Workspace ID to exclude from the match

Since:
  • 10.5.0
  • 10.6.0 Matches names consistently across create and rename flows.
Returns:

Workspace ID if found, null otherwise

Type
string | null

generateId()

Generate unique workspace ID

Since:
  • 10.5.0

Returns:

Workspace ID prefixed with "ws_"

Type
string

getActiveWorkspaceId(contextElement)

Get the active workspace ID for a given context element

Parameters:
Name Type Description
contextElement HTMLElement

cq-context or multiChartContainer element

Since:
  • 10.5.0

Returns:

Active workspace ID or "none"

Type
string

getWorkspaceMetadataById(id, props)

Get workspace metadata or specific metadata properties by ID.

Parameters:
Name Type Argument Description
id string

Workspace ID

props string <repeatable>

Metadata property names to extract. If omitted, returns all metadata. If single prop, returns value directly. If multiple, returns object with those props.

Since:
  • 10.5.0
  • 10.6.0 Returns cached metadata synchronously; full records are read only when loading a workspace.
Returns:

Cloned metadata, selected metadata properties, or undefined when the workspace or a requested property is unavailable

Type
*
Example
manager.getWorkspaceMetadataById(id)                    // → workspace metadata
manager.getWorkspaceMetadataById(id, 'name')            // → "My Workspace" (string)
manager.getWorkspaceMetadataById(id, 'name', 'isAdmin') // → {name: "...", isAdmin: false}

getWorkspaces()

Get workspace metadata as an array without retrieving full records.

Since:
  • 10.5.0
  • 10.6.0 Returns metadata only.
Returns:

Metadata entries including workspace IDs; empty before initialization

Type
Array.<object>

initialize( [config])

Initialize metadata before applying startup selection.

Legacy 1.0.0 workspace collections are not migrated automatically. Applications can use the following reference implementation, persist each returned record under stx-workspaces/{id}, and remove the legacy collection before initialization:

function migrateWorkspaces(legacy) {
	if (
		legacy?.schemaVersion !== "1.0.0" ||
		!legacy.workspaces ||
		typeof legacy.workspaces !== "object" ||
		Array.isArray(legacy.workspaces)
	) {
		throw new Error("Invalid v1 workspace collection");
	}
	return Object.entries(legacy.workspaces).map(([id, record]) => {
		return { ...structuredClone(record), id, schemaVersion: "2.0.0" };
	});
}

config.plugins.workspace.nameValueStore must be a constructor implementing get/set/remove like CIQ.NameValueStoreLarge (the default; requires IndexedDB). A custom HTTP adapter can map the two read operations to these GET endpoints:

Metadata list: get("stx-workspaces", cb, metadataKeys) calls GET /stx-workspaces?metadataKeys=name,isAdmin,isFavorite,createdAt,modifiedAt. Return only the requested fields, keyed by workspace ID; return {} when empty.

{
  "ws1": {
    "name": "Trading",
    "isAdmin": false,
    "isFavorite": true,
    "createdAt": 1789344000000,
    "modifiedAt": 1789344060000
  }
}

Full workspace: get("stx-workspaces/ws1", cb) calls GET /stx-workspaces/ws1. Return the complete saved record, not an ID-keyed wrapper; return null if missing. The grid and charts values below are abbreviated; return their saved contents.

{
  "id": "ws1",
  "schemaVersion": "2.0.0",
  "name": "Trading",
  "isAdmin": false,
  "isFavorite": true,
  "createdAt": 1789344000000,
  "modifiedAt": 1789344060000,
  "grid": {},
  "charts": {}
}

The adapter passes the parsed response to cb(null, data) or calls cb(error) on failure. set/remove write/delete that same row by ID.

Parameters:
Name Type Argument Description
config object <optional>

Chart configuration

Properties
Name Type Argument Description
plugins object <optional>

Plugin configuration

Properties
Name Type Argument Description
workspace object <optional>

Workspace options

Properties
Name Type Argument Default Description
nameValueStore function <optional>

Snapshot storage constructor

loadSample boolean <optional>
false

Load read-only sample workspaces

cb function <optional>

Callback executed after storage loads

loadWorkspaceId string <optional>

Workspace ID to load when no active workspace is stored

nameValueStore function <optional>

Active-workspace ID storage constructor

contextElement HTMLElement <optional>

Specific chart or multichart context element to use

Since:
  • 10.5.0
  • 10.6.0 Supplies the workspace store name and loads metadata only. Captures the configurable info-blurb description
Returns:

Resolves when metadata and configured startup selection are ready; rejects when metadata cannot be read, in which case the manager stays uninitialized and a later call retries

Type
Promise.<void>

isWorkspaceReadOnly(id)

Check if workspace is read-only (admin workspace)

Parameters:
Name Type Description
id string

Workspace ID

Since:
  • 10.5.0

Returns:

True if workspace is admin/read-only

Type
boolean

loadSampleAdminWorkspace()

Create (if missing) a sample read-only admin workspace for demos/examples. Uses plugin-local static sample data.

Since:
  • 10.5.0
  • 10.6.0 Stores the sample as an individual record.
Returns:
Type
Promise.<void>

<async> loadWorkspace(workspaceId, contextElement)

Load a workspace and restore its state

Parameters:
Name Type Description
workspaceId string

Workspace ID or "none"

contextElement HTMLElement

cq-context or multiChartContainer element

Since:
  • 10.5.0
  • 10.6.0 Retrieves only the requested full record, reports missing workspaces consistently, and ignores superseded reads.
Returns:

Whether the selection was applied; rejects on missing workspaces or storage errors

Type
Promise.<boolean>

<async> overwriteWorkspaceById(id, contextElement)

Overwrite an existing workspace with current chart state

Parameters:
Name Type Description
id string

Workspace ID to overwrite

contextElement HTMLElement

cq-context or multiChartContainer element

Since:
  • 10.5.0
  • 10.6.0 Persists only the selected workspace and returns its ID and saved record.
Returns:

Result containing id and the persisted workspace, or null if missing/admin/collection error; rejects on storage errors

Type
Promise.<(object|null)>
Example
const result = await manager.overwriteWorkspaceById(id, contextElement);
if (result) console.log(result.id, result.workspace);

renameWorkspace(workspaceId, name)

Rename a workspace while preserving its complete saved state.

Parameters:
Name Type Description
workspaceId string

Workspace ID

name string

New workspace name

Since:
  • 10.5.0
  • 10.6.0 Fetches and updates the selected full record so chart state is preserved.
Returns:

Whether the workspace was renamed; rejects on storage errors

Type
Promise.<boolean>

<async> saveActiveWorkspace(activeWorkspaceId, contextElement)

Save current state to active workspace

Parameters:
Name Type Description
activeWorkspaceId string

ID of the workspace to overwrite

contextElement HTMLElement

cq-context or multiChartContainer element

Since:
  • 10.5.0
  • 10.6.0 Writes only the active record and awaits persistence.
Returns:

Whether the workspace was saved; rejects on storage errors

Type
Promise.<boolean>

showToast(message [, type] [, contextElement])

Show toast notification

Parameters:
Name Type Argument Default Description
message string

Message to display

type string <optional>
CIQ.Workspaces~ToastType.SUCCESS

Toast type (success, error, confirmation)

contextElement HTMLElement | null <optional>
null

cq-context or multiChartContainer element; omit to suppress toast

Since:
  • 10.5.0
  • 10.6.0 Selects the primary chart directly from the context's charts.
Returns:
Type
void

<static> getInstance()

Returns the shared workspace snapshot service.

Since:
  • 10.6.0

Returns:

Singleton workspace manager.

Type
CIQ.Workspaces

Type Definitions


ToastType

Toast notification types used with CIQ.Workspaces#showToast.

Type:
  • object
Properties:
Name Type Description
SUCCESS string

Confirms a completed action.

ERROR string

Reports a failed action.

CONFIRMATION string

Confirms a persisted workspace change.

Since:
  • 10.5.0