1.0.2 • Published 1 year ago

@ewizardjs/structure-api v1.0.2

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

STRUCTURE API

Structure api is a set of methods that will allow you to simplify your work with slides, chapters, storyboard, structure.json and the structure of the eDetailer as a whole. It also can be used in content from ewizardjs module.

Install structure-api with npm

  npm i @ewizardjs/structure-api

Usage/Examples

In your ".ts"/".js" files:

import {
  getSlides,  
  getSlidesAsync,  
  getFlatSlides,  
  getVisibleSlides,  
  getFlatVisibleSlides,  
  getHiddenSlides,  
  getFlatHiddenSlides,  
  getArchivedSlides,  
  getSlide,  
  getFlatSlide,  
  getChapters,  
  getHiddenChapters,  
  getVisibleChapters,  
  getChapter,  
  getChapterSlides,  
  getFlatChapterSlides,  
  getSlideSubslides,  
  getStartSlide,  
  getStoryboard,  
  getStructureFileVersion,  
  convertToStructureV2,  
  makeStructure,  
  supportsStructureV2,  
} from '@ewizardjs/structure-api';  
  
const structure = readJson('./structure.json');  
  
const visibleSlides = getSlides(structure, { visible: true });  
const storyboard = getStoryboard(structure);  
const onlyVisisbleSlidesStructure = makeStructure(visibleSlides);  

In your ".vue" files:

  this.$structure.someMethod()

Data-structures

NameFields
NestedSlideDataid, name, chapter , type , thumbnail, template, custom, subslides
FlatSlideDataid, name, chapter , type , thumbnail, template, custom, subslides, isSubslide ,parentSlide
ChapterDataid, name, type, custom
StartSlideslide, chapter
NestedChapterDataid, name, type, slides

Available Interfaces / Types / etc

NameDescription
StructureApiNamespace under which all api methods are available, as well as data structures and their types
iStructureJSONUnion for structure.json format version 1 or 2
StructureV1Namespace under which the json structure format of the first version, the slide and chapter interface are available
StructureV2Namespace under which the json structure format of the second version, the slide and chapter interface are available as well as the Storyboard element
iStartStart slide interface

API Reference

MethodArgumentsExecution resultDescription
getSlidestructureJson, slideId, systemSettingsObject of type NestedSlideData or undefinedTo retrieve information about a single, specific slide, use this method
getSlidesstructureJson[, slideTypes , systemSettings]Array of objects of type NestedSlideDataUse this method to get information about all slides
getSlidesAsyncstructureJson[, slideTypes[, systemSettings, callback]]Array of objects of type NestedSlideData or any other ObjectTo get custom slide data objects or modify slide fields, use this method. The callback code will be called for all slides, including their subslides.
getFlatSlidesstructureJson[, slideTypes, systemSettings]Array of objects of type FlatSlideDataSimilar to getSlides, but will return a set of slide objects without the "subslides" field - subslides will be returned along with the slides. Use isSubslide to distinguish between a slide and a subslide
getVisibleSlidesstructureJson, systemSettingsArray of objects of type NestedSlideDataSimilar to the getSlides method , but will only return slides of the "visible" type
getFlatVisibleSlidesstructureJson, systemSettingsArray of objects of type FlatSlideDataSimilar to the getFlatSlides method , but will only return slides of the "visible" type
getHiddenSlidesstructureJson, systemSettingsArray of objects of type NestedSlideDataSimilar to the getSlides method , but will only return slides of the "hidden" type
getFlatHiddenSlidesstructureJson, systemSettingsArray of objects of type FlatSlideDataSimilar to the getFlatSlides method , but will only return slides of the "visible" type
getArchivedSlidesstructureJson, systemSettingsArray of objects of type NestedSlideDataSimilar to the getSlides method , but will only return slides of the "archived" type
getFlatSlidestructureJson, slideId, systemSettingsObject of type FlatSlideDataTo retrieve slide data (without the "subslides" field) or to check if a given slide is a subslide or to retrieve a parent slide, use this method.
getChaptersstructureJson, chapterTypesArray of objects of type ChapterDataUse this method to get a list of chapters and define their types. The order is determined by the order in the "chapters" field
getHiddenChaptersstructureJsonArray of objects of type ChapterDataSimilar to the "getChapters" method, but it will only return "hidden" chapters
getVisibleChaptersstructureJsonArray of objects of type ChapterDataSimilar to the "getChapters" method, but it will only return "visible" chapters
getChapterstructureJson, chapterIdObject of type ChapterData or undefinedUse this method to get a chapter data or check if it exists
getChapterSlidesstructureJson, chapterId[, slideTypes, systemSettings]Array of objects of type NestedSlideDataSimilar to the getSlides method , but will only return slides of the passed chapter
getFlatChapterSlidesstructureJson, chapterId[, slideTypes, systemSettings]Array of objects of type FlatSlideDataSimilar to the getFlatSlides method , but will only return slides of the passed chapter
getSlideSubslidesstructureJson, slideId[, slideTypes, systemSettings]Array of objects of type SlideDataUse this method to get a subslide of a particular slide
getStartSlidestructureJson, systemSettingsObject of type StartSlide or undefinedUse to get a starting slide. If not specified explicitly in structure.json - it will return the first "visible" slide
getStoryboardstructureJson[, chapterTypes, systemSettings]Array of objects of type NestedChapterDataReturns the list of chapters and slides in them, based on their order in the "storyboard" and "content" fields, respectively
getStructureFileVersionstructureJsonnumberReturns the file format number of the structure.json file
convertToStructureV2structureJsonJSON of type StructureV2.iStructureJSONUse when you want to convert structure.json content to version 2
makeStructurenestedSlidesData, targetStructureVersionJSON of type iStructureJSONAccepts nestedSlidesData objects as input and builds structure.json content based on them
supportsStructureV2ewizardjsVersionbooleanUse if necessary to check if the version of "ewizardjs" transferred supports the structure of the second version. (Incompatible structure.json and content versions cause navigation problems, etc.)

Arguments of the methods

NameDescriptionExample
structureJsonstructure.json file content--
slideTypesThe filters object for the slide type{ visible?: true, hidden?: false, archived?: false }
systemSettingsFragment of the default paths object. Necessary to form a thumbnail path in slide-type structures. Can be obtained from module "@ewizardjs/system-settings". If not passed - field "thumbnail" will be empty for all slides and subslides{ path: { slides: string, slide: { thumbnail: string }}}
chapterTypesThe filters object for the chapters type{ visible?: true, hidden?: false }
slideIdString that represents target slide id'custom'
chapterIdString that represents target chapter id'home'
targetStructureVersionstructure.json format version. Default is 12
ewizardjsVersionThe full version of the "ewizardjs" module. The version must be valid for the "semver" module'5.23.0'

How does type detection works?

Structure-api methods work in 2 steps.
On the first stage the JSON version of the structure is checked.
If it is the first version, it converts to the second one.
On the second stage, they work directly with JSON of the second version.
The following describes the logic of determining the types of slides and chappers at each stage:

Defining types of slides and chappers when converting the structure of the first version to the second version: 1. Archived slides: slides that start with "!" or do not have a chapter (missing in the chapters content). 2. Chapter cannot be "archived". If the chapter is not in the storyboard, or it is, but starts with "!" - "hidden"

Defining types of slides and chappers when working with the structure of version 2: 1. A chapter cannot be an archive at all. Chapter is "visible" if it is present in the storyboard and has { hidden: false }. In other cases, it is "hidden". 2. A slide can be "archived" only if it has no chapter , or if it is listed as archived in "archivedSlides" field.

How is the order of slides determined?

There are two main methods for getting slides: getSlides and getFlatSlides (the other methods overuse these). The order of the slides is determined by the order of the chapters in the "chapters" field of the structure.json file. Getting a list of all chapters from this field collects all slides from each chapter (from the "content" field). During this assembly, if a slide from the "content" field has sub-slides, they will go right after the parent slide. After that, this set is supplemented with slides that are in the "slides" field of structure.json file, but were not included in the previous stages. If the order of chapters and slides is important to you, use the getStoryboard method