@dfosco/storyboard-core 1.19.0 → 1.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/devtools.js +6 -1
- package/src/devtools.test.js +7 -0
- package/src/index.js +2 -2
- package/src/loader.js +13 -0
- package/src/loader.test.js +33 -1
package/package.json
CHANGED
package/src/devtools.js
CHANGED
|
@@ -17,7 +17,7 @@ import { loadScene } from './loader.js'
|
|
|
17
17
|
import { isCommentsEnabled } from './comments/config.js'
|
|
18
18
|
import { isHideMode, activateHideMode, deactivateHideMode } from './hideMode.js'
|
|
19
19
|
import { getAllFlags, toggleFlag, getFlagKeys } from './featureFlags.js'
|
|
20
|
-
import { isPluginEnabled } from './plugins.js'
|
|
20
|
+
import { isPluginEnabled, initPlugins } from './plugins.js'
|
|
21
21
|
|
|
22
22
|
const STYLES = `
|
|
23
23
|
.sb-devtools-wrapper {
|
|
@@ -190,8 +190,13 @@ function getSceneName() {
|
|
|
190
190
|
*
|
|
191
191
|
* @param {object} [options]
|
|
192
192
|
* @param {HTMLElement} [options.container=document.body] - Where to mount
|
|
193
|
+
* @param {Record<string, boolean>} [options.plugins] - Plugin config from storyboard.config.json
|
|
193
194
|
*/
|
|
194
195
|
export function mountDevTools(options = {}) {
|
|
196
|
+
// Allow callers to pass plugins config directly (avoids timing issues
|
|
197
|
+
// where mountDevTools runs before the Vite virtual module calls initPlugins)
|
|
198
|
+
if (options.plugins) initPlugins(options.plugins)
|
|
199
|
+
|
|
195
200
|
// Skip when devtools plugin is disabled via storyboard.config.json
|
|
196
201
|
if (!isPluginEnabled('devtools')) return
|
|
197
202
|
|
package/src/devtools.test.js
CHANGED
|
@@ -97,4 +97,11 @@ describe('mountDevTools', () => {
|
|
|
97
97
|
const wrapper = document.body.querySelector('.sb-devtools-wrapper')
|
|
98
98
|
expect(wrapper).not.toBeNull()
|
|
99
99
|
})
|
|
100
|
+
|
|
101
|
+
it('does not mount when plugins option disables devtools', () => {
|
|
102
|
+
mountDevTools({ plugins: { devtools: false } })
|
|
103
|
+
|
|
104
|
+
const wrapper = document.body.querySelector('.sb-devtools-wrapper')
|
|
105
|
+
expect(wrapper).toBeNull()
|
|
106
|
+
})
|
|
100
107
|
})
|
package/src/index.js
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
// Data index initialization
|
|
9
9
|
export { init } from './loader.js'
|
|
10
10
|
|
|
11
|
-
// Scene & record loading
|
|
12
|
-
export { loadScene, listScenes, sceneExists, loadRecord, findRecord, deepMerge } from './loader.js'
|
|
11
|
+
// Scene, object & record loading
|
|
12
|
+
export { loadScene, listScenes, sceneExists, loadRecord, findRecord, loadObject, deepMerge } from './loader.js'
|
|
13
13
|
|
|
14
14
|
// Dot-notation path utilities
|
|
15
15
|
export { getByPath, setByPath, deepClone } from './dotPath.js'
|
package/src/loader.js
CHANGED
|
@@ -209,4 +209,17 @@ export function findRecord(recordName, id) {
|
|
|
209
209
|
return records.find((entry) => entry.id === id) ?? null
|
|
210
210
|
}
|
|
211
211
|
|
|
212
|
+
/**
|
|
213
|
+
* Loads an object data file by name, resolves any nested $ref references,
|
|
214
|
+
* and returns a deep clone.
|
|
215
|
+
*
|
|
216
|
+
* @param {string} objectName - Name of the object file (e.g., "jane-doe")
|
|
217
|
+
* @returns {object|Array} Resolved object data
|
|
218
|
+
*/
|
|
219
|
+
export function loadObject(objectName) {
|
|
220
|
+
const data = loadDataFile(objectName, 'objects')
|
|
221
|
+
const resolved = resolveRefs(structuredClone(data))
|
|
222
|
+
return resolved
|
|
223
|
+
}
|
|
224
|
+
|
|
212
225
|
export { deepMerge }
|
package/src/loader.test.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { init, loadScene, listScenes, sceneExists, loadRecord, findRecord, deepMerge } from './loader.js'
|
|
1
|
+
import { init, loadScene, listScenes, sceneExists, loadRecord, findRecord, loadObject, deepMerge } from './loader.js'
|
|
2
2
|
|
|
3
3
|
const makeIndex = () => ({
|
|
4
4
|
scenes: {
|
|
@@ -36,6 +36,10 @@ const makeIndex = () => ({
|
|
|
36
36
|
'circular-obj-b': {
|
|
37
37
|
nested: { $ref: 'circular-obj-a' },
|
|
38
38
|
},
|
|
39
|
+
'team-info': {
|
|
40
|
+
team: 'Engineering',
|
|
41
|
+
lead: { $ref: 'jane-doe' },
|
|
42
|
+
},
|
|
39
43
|
},
|
|
40
44
|
records: {
|
|
41
45
|
posts: [
|
|
@@ -243,3 +247,31 @@ describe('deepMerge', () => {
|
|
|
243
247
|
expect(result.c).toBeUndefined()
|
|
244
248
|
})
|
|
245
249
|
})
|
|
250
|
+
|
|
251
|
+
describe('loadObject', () => {
|
|
252
|
+
it('loads object by name', () => {
|
|
253
|
+
const obj = loadObject('jane-doe')
|
|
254
|
+
expect(obj).toEqual({ name: 'Jane Doe', role: 'admin' })
|
|
255
|
+
})
|
|
256
|
+
|
|
257
|
+
it('resolves $ref within object', () => {
|
|
258
|
+
const obj = loadObject('team-info')
|
|
259
|
+
expect(obj.team).toBe('Engineering')
|
|
260
|
+
expect(obj.lead).toEqual({ name: 'Jane Doe', role: 'admin' })
|
|
261
|
+
})
|
|
262
|
+
|
|
263
|
+
it('throws for missing object', () => {
|
|
264
|
+
expect(() => loadObject('nonexistent')).toThrow()
|
|
265
|
+
})
|
|
266
|
+
|
|
267
|
+
it('returns deep clone (mutations do not affect index)', () => {
|
|
268
|
+
const obj1 = loadObject('jane-doe')
|
|
269
|
+
obj1.name = 'Modified'
|
|
270
|
+
const obj2 = loadObject('jane-doe')
|
|
271
|
+
expect(obj2.name).toBe('Jane Doe')
|
|
272
|
+
})
|
|
273
|
+
|
|
274
|
+
it('detects circular $ref and throws', () => {
|
|
275
|
+
expect(() => loadObject('circular-obj-a')).toThrow(/circular/i)
|
|
276
|
+
})
|
|
277
|
+
})
|