@casual-simulation/aux-common
Advanced tools
Comparing version 0.4.15 to 0.5.0
@@ -0,10 +1,6 @@ | ||
import { CausalTree, CausalTreeOptions, StoredCausalTree, AtomId, Atom, AtomBatch, AddResult } from '@casual-simulation/causal-trees'; | ||
import { AuxOp, FileOp, TagOp, InsertOp, ValueOp, DeleteOp } from './AuxOpTypes'; | ||
import { CausalTree, CausalTreeOptions } from '../causal-trees/CausalTree'; | ||
import { FilesState, FileEvent, PartialFile, File } from '../Files'; | ||
import { AuxReducerMetadata } from './AuxReducer'; | ||
import { AtomId, Atom } from '../causal-trees/Atom'; | ||
import { StoredCausalTree } from '../causal-trees/StoredCausalTree'; | ||
import { AuxState, AuxFile } from './AuxState'; | ||
import { AtomBatch } from '../causal-trees/AtomBatch'; | ||
import { AddResult } from '../causal-trees/AddResult'; | ||
/** | ||
@@ -11,0 +7,0 @@ * Defines a Causal Tree for aux files. |
@@ -9,12 +9,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}; | ||
import { CausalTree, atomIdToString, mergeIntoBatch, } from '@casual-simulation/causal-trees'; | ||
import { AuxOpType, } from './AuxOpTypes'; | ||
import { CausalTree } from '../causal-trees/CausalTree'; | ||
import { tagsOnFile, getFileTag, hasValue, getTag, } from '../Files'; | ||
import { AuxReducer } from './AuxReducer'; | ||
import { root, file, tag, value, del, insert } from './AuxAtoms'; | ||
import { atomIdToString } from '../causal-trees/Atom'; | ||
import { insertIntoTagValue, insertIntoTagName, deleteFromTagValue, deleteFromTagName, } from './AuxTreeCalculations'; | ||
import { flatMap, keys, isEqual } from 'lodash'; | ||
import { merge } from '../utils'; | ||
import { mergeIntoBatch } from '../causal-trees/AddResult'; | ||
/** | ||
@@ -21,0 +19,0 @@ * Defines a Causal Tree for aux files. |
@@ -1,2 +0,2 @@ | ||
import { CausalTreeFactory } from '../causal-trees'; | ||
import { CausalTreeFactory } from '@casual-simulation/causal-trees'; | ||
/** | ||
@@ -3,0 +3,0 @@ * Creates a new Causal Tree Factory that can create all the tree types required for AUX applications. |
@@ -1,2 +0,2 @@ | ||
import { CausalTreeFactory } from '../causal-trees'; | ||
import { CausalTreeFactory } from '@casual-simulation/causal-trees'; | ||
import { AuxCausalTree } from './AuxCausalTree'; | ||
@@ -3,0 +3,0 @@ /** |
@@ -1,2 +0,2 @@ | ||
import { AtomOp } from '../causal-trees/Atom'; | ||
import { AtomOp } from '@casual-simulation/causal-trees'; | ||
/** | ||
@@ -3,0 +3,0 @@ * The list of operation types. |
@@ -1,7 +0,7 @@ | ||
import { AtomReducer } from '../causal-trees/AtomReducer'; | ||
import { AtomReducer } from '@casual-simulation/causal-trees'; | ||
import { AuxOp } from './AuxOpTypes'; | ||
import { Weave } from '../causal-trees/Weave'; | ||
import { WeaveTraverser } from '../causal-trees/WeaveTraverser'; | ||
import { Weave } from '@casual-simulation/causal-trees'; | ||
import { WeaveTraverser } from '@casual-simulation/causal-trees'; | ||
import { AuxState, AuxValueMetadata, AuxRef, AuxSequenceMetadata } from './AuxState'; | ||
import { Atom } from '../causal-trees/Atom'; | ||
import { Atom } from '@casual-simulation/causal-trees'; | ||
/** | ||
@@ -8,0 +8,0 @@ * Defines a type for a map from weave references to their calculated values. |
import { AuxOpType, } from './AuxOpTypes'; | ||
import { hasValue } from '../Files'; | ||
import { WeaveTraverser } from '../causal-trees/WeaveTraverser'; | ||
import { WeaveTraverser } from '@casual-simulation/causal-trees'; | ||
import { merge, splice } from '../utils'; | ||
@@ -5,0 +5,0 @@ import { fill } from 'lodash'; |
import { Object } from '../Files'; | ||
import { Atom } from '../causal-trees/Atom'; | ||
import { Atom } from '@casual-simulation/causal-trees'; | ||
import { AuxOp, FileOp, ValueOp, TagOp } from './AuxOpTypes'; | ||
@@ -4,0 +4,0 @@ export declare type AuxFile = AuxObject; |
@@ -1,6 +0,10 @@ | ||
import { Atom, PrecalculatedOp, RealtimeCausalTree, Weave } from '../causal-trees'; | ||
import { AuxFile, AuxTagMetadata } from './AuxState'; | ||
import { Atom, PrecalculatedOp, RealtimeCausalTree, Weave } from '@casual-simulation/causal-trees'; | ||
import { AuxFile, AuxTagMetadata, AuxObject } from './AuxState'; | ||
import { InsertOp, DeleteOp, AuxOp, FileOp } from './AuxOpTypes'; | ||
import { AuxCausalTree } from './AuxCausalTree'; | ||
import { File } from '../Files'; | ||
export interface AuxStateDiff { | ||
addedFiles: AuxFile[]; | ||
removedFiles: string[]; | ||
updatedFiles: AuxFile[]; | ||
} | ||
/** | ||
@@ -11,5 +15,5 @@ * Builds the fileAdded, fileRemoved, and fileUpdated observables from the given channel connection. | ||
export declare function fileChangeObservables(tree: RealtimeCausalTree<AuxCausalTree>): { | ||
filesAdded: import("rxjs").Observable<File[]>; | ||
filesAdded: import("rxjs").Observable<AuxObject[]>; | ||
filesRemoved: import("rxjs").Observable<string[]>; | ||
filesUpdated: import("rxjs").Observable<File[]>; | ||
filesUpdated: import("rxjs").Observable<AuxObject[]>; | ||
}; | ||
@@ -16,0 +20,0 @@ /** |
@@ -1,2 +0,2 @@ | ||
import { precalculatedOp, } from '../causal-trees'; | ||
import { precalculatedOp, } from '@casual-simulation/causal-trees'; | ||
import { AuxOpType } from './AuxOpTypes'; | ||
@@ -3,0 +3,0 @@ import { calculateSequenceRef, calculateSequenceRefs } from './AuxReducer'; |
@@ -1,3 +0,3 @@ | ||
import { RealtimeCausalTree } from '../causal-trees/RealtimeCausalTree'; | ||
import { RealtimeCausalTree } from '@casual-simulation/causal-trees'; | ||
import { AuxCausalTree } from './AuxCausalTree'; | ||
export declare type RealtimeAuxTree = RealtimeCausalTree<AuxCausalTree>; |
@@ -7,3 +7,3 @@ import { Object, File, Workspace, UserMode, SelectionMode, FileShape, FileTags, FileLabelAnchor } from './File'; | ||
import { AuxFile, AuxObject, AuxOp } from '../aux-format'; | ||
import { Atom } from '../causal-trees'; | ||
import { Atom } from '@casual-simulation/causal-trees'; | ||
export declare var ShortId_Length: number; | ||
@@ -119,3 +119,3 @@ /** | ||
*/ | ||
export declare function filterFilesBySelection(files: Object[], selectionId: string): File[]; | ||
export declare function filterFilesBySelection<TFile extends File>(files: TFile[], selectionId: string): TFile[]; | ||
/** | ||
@@ -380,4 +380,5 @@ * Gets a list of tags that the given files contain. | ||
* @param builderContextId The tag that should be used for contexts stored on this workspace. | ||
* @param contextFormula The formula that should be used to determine whether the workspace is allowed to be a context. | ||
*/ | ||
export declare function createWorkspace(id?: string, builderContextId?: string, contextType?: unknown): Workspace; | ||
export declare function createWorkspace(id?: string, builderContextId?: string, contextFormula?: string): Workspace; | ||
/** | ||
@@ -706,2 +707,7 @@ * Performs a pre-process step for updating the given file by nulling out falsy tags and also calculating assignments. | ||
/** | ||
* Formats the given value and returns a string representing it. | ||
* @param value The value to format. | ||
*/ | ||
export declare function formatValue(value: any): string; | ||
/** | ||
* Calculates the value of the given formula as if it was on the given file (object) and tag. | ||
@@ -708,0 +714,0 @@ * @param context The calculation context to use. |
@@ -165,3 +165,3 @@ import { DEFAULT_WORKSPACE_SCALE, DEFAULT_WORKSPACE_HEIGHT, DEFAULT_WORKSPACE_GRID_SCALE, DEFAULT_USER_MODE, DEFAULT_SELECTION_MODE, DEFAULT_FILE_SHAPE, DEFAULT_WORKSPACE_SIZE, DEFAULT_LABEL_ANCHOR, } from './File'; | ||
const value = calculateFileValue(context, file, tag); | ||
return _formatValue(value); | ||
return formatValue(value); | ||
} | ||
@@ -547,4 +547,5 @@ /** | ||
* @param builderContextId The tag that should be used for contexts stored on this workspace. | ||
* @param contextFormula The formula that should be used to determine whether the workspace is allowed to be a context. | ||
*/ | ||
export function createWorkspace(id = uuid(), builderContextId = createContextId(), contextType = '=isBuilder') { | ||
export function createWorkspace(id = uuid(), builderContextId = createContextId(), contextFormula = '=isBuilder') { | ||
// checks if given context string is empty or just whitespace | ||
@@ -561,3 +562,3 @@ if (builderContextId.length === 0 || /^\s*$/.test(builderContextId)) { | ||
[builderContextId]: true, | ||
[`${builderContextId}.config`]: contextType, | ||
[`${builderContextId}.config`]: contextFormula, | ||
[`${builderContextId}.x`]: 0, | ||
@@ -981,3 +982,3 @@ [`${builderContextId}.y`]: 0, | ||
return false; | ||
}), o => getFileIndex(calc, o, context)); | ||
}), o => getFileIndex(calc, o, context), o => o.id); | ||
} | ||
@@ -1309,6 +1310,10 @@ /** | ||
} | ||
function _formatValue(value) { | ||
/** | ||
* Formats the given value and returns a string representing it. | ||
* @param value The value to format. | ||
*/ | ||
export function formatValue(value) { | ||
if (typeof value === 'object') { | ||
if (Array.isArray(value)) { | ||
return `[${value.map(v => _formatValue(v)).join(',')}]`; | ||
return `[${value.map(v => formatValue(v)).join(',')}]`; | ||
} | ||
@@ -1315,0 +1320,0 @@ else { |
@@ -117,2 +117,3 @@ import { File, PartialFile } from './File'; | ||
fileId: string; | ||
zoomValue: number; | ||
} | ||
@@ -185,3 +186,4 @@ /** | ||
* @param fileId The ID of the file to tween to. | ||
* @param zoomValue The zoom value to use. | ||
*/ | ||
export declare function tweenTo(fileId: string): TweenToEvent; | ||
export declare function tweenTo(fileId: string, zoomValue?: number): TweenToEvent; |
@@ -270,4 +270,5 @@ import { sortBy, flatMap, mapValues } from 'lodash'; | ||
* @param fileId The ID of the file to tween to. | ||
* @param zoomValue The zoom value to use. | ||
*/ | ||
export function tweenTo(fileId) { | ||
export function tweenTo(fileId, zoomValue = -1) { | ||
return { | ||
@@ -277,4 +278,5 @@ type: 'local', | ||
fileId: fileId, | ||
zoomValue: zoomValue, | ||
}; | ||
} | ||
//# sourceMappingURL=FilesChannel.js.map |
@@ -87,21 +87,4 @@ import { File, FileTags } from '../Files/File'; | ||
*/ | ||
export declare function create(...diffs: FileDiff[]): FileProxy; | ||
export declare function create(...diffs: (FileDiff | FileDiff[])[]): FileProxy | FileProxy[]; | ||
/** | ||
* Creates a new file that contains tags from the given files or objects. | ||
* @param diffs The diffs to use for the new file's tags. | ||
*/ | ||
export declare function cloneFile(...diffs: FileDiff[]): FileProxy; | ||
/** | ||
* Creates a new file that contains tags from and is parented under the given file. | ||
* @param file The file that the clone should be a child of. | ||
* @param data The files or objects to use for the new file's tags. | ||
*/ | ||
export declare function cloneFrom(file: FileProxy, ...data: FileDiff[]): FileProxy; | ||
/** | ||
* Clones the given file or set of files and applies the given set of file diffs to them. | ||
* @param file The file or files to clone. | ||
* @param diffs The diffs to apply to the cloned files. | ||
*/ | ||
export declare function clone(file: FileProxy | FileProxy[], ...diffs: FileDiff[]): FileProxy | FileProxy[]; | ||
/** | ||
* Gets the file ID from the given file. | ||
@@ -116,3 +99,3 @@ * @param file The file or string. | ||
*/ | ||
export declare function createFrom(parent: FileProxy | string, ...datas: FileDiff[]): FileProxy; | ||
export declare function createFrom(parent: FileProxy | string, ...datas: FileDiff[]): FileProxy | FileProxy[]; | ||
/** | ||
@@ -232,4 +215,5 @@ * Combines the two given files. | ||
* @param file The file to view. | ||
* @param zoomValue The zoom value to use. | ||
*/ | ||
export declare function tweenPlayerTo(file: FileProxy | string): void; | ||
export declare function tweenPlayerTo(file: FileProxy | string, zoomValue?: number): void; | ||
/** | ||
@@ -256,3 +240,2 @@ * Defines a set of functions that are able to make File Diffs. | ||
destroy: typeof destroy; | ||
clone: typeof clone; | ||
create: typeof createFrom; | ||
@@ -259,0 +242,0 @@ combine: typeof combine; |
@@ -210,59 +210,46 @@ import { action, calculateActionEvents, fileRemoved, fileAdded, toast as toastMessage, tweenTo as calcTweenTo, } from '../Files/FilesChannel'; | ||
export function create(...diffs) { | ||
let id = uuid(); | ||
let file = { | ||
id: id, | ||
tags: {}, | ||
}; | ||
applyDiff(file.tags, ...diffs); | ||
actions.push(fileAdded(file)); | ||
const ret = calc.sandbox.interface.addFile(file); | ||
state = Object.assign({}, state, { | ||
[id]: file, | ||
}); | ||
event(CREATE_ACTION_NAME, [file]); | ||
return ret; | ||
} | ||
/** | ||
* Creates a new file that contains tags from the given files or objects. | ||
* @param diffs The diffs to use for the new file's tags. | ||
*/ | ||
export function cloneFile(...diffs) { | ||
let id = uuid(); | ||
let newFile = { | ||
id: id, | ||
tags: {}, | ||
}; | ||
applyDiff(newFile.tags, ...diffs); | ||
actions.push(fileAdded(newFile)); | ||
const ret = calc.sandbox.interface.addFile(newFile); | ||
state = Object.assign({}, state, { | ||
[id]: newFile, | ||
}); | ||
event(CREATE_ACTION_NAME, [newFile]); | ||
return ret; | ||
} | ||
/** | ||
* Creates a new file that contains tags from and is parented under the given file. | ||
* @param file The file that the clone should be a child of. | ||
* @param data The files or objects to use for the new file's tags. | ||
*/ | ||
export function cloneFrom(file, ...data) { | ||
let parent = file | ||
? { | ||
'aux._creator': file.id, | ||
let variants = new Array(1); | ||
variants[0] = []; | ||
for (let i = 0; i < diffs.length; i++) { | ||
let diff = diffs[i]; | ||
if (Array.isArray(diff)) { | ||
let newVariants = new Array(variants.length * diff.length); | ||
for (let b = 0; b < newVariants.length; b++) { | ||
let diffIdx = Math.floor(b / variants.length); | ||
let d = diff[diffIdx]; | ||
let variantIdx = b % variants.length; | ||
let newVariant = variants[variantIdx].slice(); | ||
newVariant.push(d); | ||
newVariants[b] = newVariant; | ||
} | ||
variants = newVariants; | ||
} | ||
: {}; | ||
return cloneFile(file, parent, ...data); | ||
} | ||
/** | ||
* Clones the given file or set of files and applies the given set of file diffs to them. | ||
* @param file The file or files to clone. | ||
* @param diffs The diffs to apply to the cloned files. | ||
*/ | ||
export function clone(file, ...diffs) { | ||
if (Array.isArray(file)) { | ||
return file.map(f => cloneFrom(f, ...diffs)); | ||
else { | ||
for (let b = 0; b < variants.length; b++) { | ||
variants[b].push(diff); | ||
} | ||
} | ||
} | ||
let files = variants.map(v => { | ||
let file = { | ||
id: uuid(), | ||
tags: {}, | ||
}; | ||
applyDiff(file.tags, ...v); | ||
return file; | ||
}); | ||
actions.push(...files.map(f => fileAdded(f))); | ||
let ret = new Array(files.length); | ||
for (let i = 0; i < files.length; i++) { | ||
ret[i] = calc.sandbox.interface.addFile(files[i]); | ||
state = Object.assign({}, state, { | ||
[files[i].id]: files[i], | ||
}); | ||
} | ||
event(CREATE_ACTION_NAME, files); | ||
if (ret.length === 1) { | ||
return ret[0]; | ||
} | ||
else { | ||
return cloneFrom(file, ...diffs); | ||
return ret; | ||
} | ||
@@ -515,5 +502,6 @@ } | ||
* @param file The file to view. | ||
* @param zoomValue The zoom value to use. | ||
*/ | ||
export function tweenPlayerTo(file) { | ||
actions.push(calcTweenTo(getFileId(file))); | ||
export function tweenPlayerTo(file, zoomValue) { | ||
actions.push(calcTweenTo(getFileId(file), zoomValue)); | ||
} | ||
@@ -541,3 +529,2 @@ /** | ||
destroy, | ||
clone, | ||
create: createFrom, | ||
@@ -544,0 +531,0 @@ combine, |
{ | ||
"name": "@casual-simulation/aux-common", | ||
"version": "0.4.15", | ||
"version": "0.5.0", | ||
"description": "Common library for AUX projects", | ||
@@ -9,6 +9,5 @@ "main": "index.js", | ||
"scripts": { | ||
"watch": "npm run clean && tsc --watch", | ||
"watch": "tsc --build --watch", | ||
"watch:player": "npm run watch", | ||
"clean": "gulp clean", | ||
"build": "npm run clean && tsc", | ||
"build": "echo \"Nothing to do.\"", | ||
"build:docs": "typedoc --mode file --excludeNotExported --out ../../docs/aux-common .", | ||
@@ -38,18 +37,13 @@ "test": "jest", | ||
"dependencies": { | ||
"@casual-simulation/causal-trees": "^0.5.0", | ||
"@casual-simulation/crypto": "^0.5.0", | ||
"@types/acorn": "^4.0.5", | ||
"@types/astring": "^1.3.0", | ||
"@types/estraverse": "^0.0.6", | ||
"@types/fast-json-stable-stringify": "^2.0.0", | ||
"@types/lodash": "^4.14.118", | ||
"@types/sha.js": "^2.4.0", | ||
"@types/uuid": "^3.3.2", | ||
"acorn": "^6.1.1", | ||
"astring": "^1.3.1", | ||
"base64-js": "^1.3.0", | ||
"estraverse": "^4.2.0", | ||
"fast-json-stable-stringify": "^2.0.0", | ||
"lodash": "^4.17.11", | ||
"lru-cache": "^5.1.1", | ||
"rxjs": "^6.4.0", | ||
"sha.js": "^2.4.11", | ||
"uuid": "^3.3.2" | ||
@@ -64,3 +58,3 @@ }, | ||
], | ||
"gitHead": "fb1a527f677e0445b71e12ad853886dc19939dca" | ||
"gitHead": "bc7b11342d9d3ddd85fb9918cb810a2bf9c1d31c" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
12
329040
87
6379
+ Added@casual-simulation/causal-trees@0.5.2(transitive)
+ Added@casual-simulation/crypto@0.5.2(transitive)
+ Added@types/base64-js@1.3.2(transitive)
- Removed@types/lodash@^4.14.118
- Removed@types/sha.js@^2.4.0
- Removedbase64-js@^1.3.0
- Removedfast-json-stable-stringify@^2.0.0
- Removedlodash@^4.17.11
- Removedsha.js@^2.4.11