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 contextElementHTMLElement 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 namestring Workspace name
contextElementHTMLElement 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
idand the persistedworkspace, 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 workspaceIdstring Workspace ID
contextElementHTMLElement 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 namestring Workspace name
excludeIdstring <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 contextElementHTMLElement 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 idstring Workspace ID
propsstring <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.0workspace collections are not migrated automatically. Applications can use the following reference implementation, persist each returned record understx-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.nameValueStoremust be a constructor implementingget/set/removelike 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)callsGET /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)callsGET /stx-workspaces/ws1. Return the complete saved record, not an ID-keyed wrapper; returnnullif missing. Thegridandchartsvalues 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 callscb(error)on failure.set/removewrite/delete that same row by ID.Parameters:
Name Type Argument Description configobject <optional>
Chart configuration
Properties
Name Type Argument Description pluginsobject <optional>
Plugin configuration
Properties
Name Type Argument Description workspaceobject <optional>
Workspace options
Properties
Name Type Argument Default Description nameValueStorefunction <optional>
Snapshot storage constructor
loadSampleboolean <optional>
false Load read-only sample workspaces
cbfunction <optional>
Callback executed after storage loads
loadWorkspaceIdstring <optional>
Workspace ID to load when no active workspace is stored
nameValueStorefunction <optional>
Active-workspace ID storage constructor
contextElementHTMLElement <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 idstring 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 workspaceIdstring Workspace ID or "none"
contextElementHTMLElement 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 idstring Workspace ID to overwrite
contextElementHTMLElement 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
idand the persistedworkspace, 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 workspaceIdstring Workspace ID
namestring 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 activeWorkspaceIdstring ID of the workspace to overwrite
contextElementHTMLElement 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 messagestring Message to display
typestring <optional>
CIQ.Workspaces~ToastType.SUCCESS Toast type (success, error, confirmation)
contextElementHTMLElement | 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
- Since:
-
10.5.0
Properties:
Name Type Description SUCCESSstring Confirms a completed action.
ERRORstring Reports a failed action.
CONFIRMATIONstring Confirms a persisted workspace change.
