New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@openstax/highlighter

Package Overview
Dependencies
Maintainers
3
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@openstax/highlighter - npm Package Compare versions

Comparing version 1.3.2 to 1.4.0

dist/api.d.ts

5

dist/Highlight.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const uuid = require("uuid/v4");
const dom_1 = require("./dom");

@@ -10,5 +11,3 @@ const SerializedHighlight_1 = require("./SerializedHighlight");

this.range = range;
this.data = Object.assign({}, data, {
// TODO - something more random here
id: data.id || (new Date()).getTime().toString() });
this.data = Object.assign({}, data, { id: data.id || uuid() });
}

@@ -15,0 +14,0 @@ get id() {

21

dist/SerializedHighlight.d.ts

@@ -0,1 +1,2 @@

import { Highlight as ApiHighlight, NewHighlight as NewApiHighlight } from './api';
import Highlight, { IHighlightData } from './Highlight';

@@ -5,11 +6,21 @@ import Highlighter from './Highlighter';

import { serialize as defaultSerializer } from './serializationStrategies/XpathRangeSelector';
declare type IData = IHighlightData & ISerializationData;
declare type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
interface IOptionalApiData {
annotation?: string;
}
declare type IData = IHighlightData & ISerializationData & IOptionalApiData;
export default class SerializedHighlight {
readonly data: IData;
readonly id: string;
readonly content: string;
static defaultSerializer: typeof defaultSerializer;
static fromApiResponse(highlight: ApiHighlight): SerializedHighlight;
private _data;
private deserializer;
constructor(data: IData);
readonly data: IData;
readonly id: string;
readonly content: string;
constructor(data: IData & {
[key: string]: any;
});
getApiPayload(highlighter: Highlighter): Omit<NewApiHighlight, 'sourceType' | 'sourceId'> & {
id: string;
};
isLoadable(highlighter: Highlighter): boolean;

@@ -16,0 +27,0 @@ load(highlighter: Highlighter): Highlight;

"use strict";
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
t[p[i]] = s[p[i]];
return t;
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -20,2 +29,40 @@ const Highlight_1 = require("./Highlight");

}
/*
* when (if?) tutor starts using the api, remove this method and
* pull these property names down through the rest of the logic
*/
static fromApiResponse(highlight) {
if (!highlight.locationStrategies) {
throw new Error('highlight with no location strategies');
}
if (!highlight.highlightedContent) {
throw new Error('highlight with no location strategies');
}
if (!highlight.anchor) {
throw new Error('highlight with no location strategies');
}
return new SerializedHighlight(Object.assign({}, highlight.locationStrategies[0], { annotation: highlight.annotation, content: highlight.highlightedContent, id: highlight.id, referenceElementId: highlight.anchor, style: highlight.color }));
}
/*
* when (if?) tutor starts using the api, rename these fields in the rest of the code
* so that less mapping is necessary
*/
getApiPayload(highlighter) {
const _a = this.data, { id, content, style, annotation, referenceElementId } = _a, serializationData = __rest(_a, ["id", "content", "style", "annotation", "referenceElementId"]);
const highlights = highlighter.getHighlights();
const thisIndex = highlights.findIndex((search) => search.id === id);
if (!style) {
throw new Error('a style is requred to create an api payload');
}
return {
anchor: referenceElementId,
annotation,
color: style,
highlightedContent: content,
id,
locationStrategies: [serializationData],
nextHighlightId: thisIndex < highlights.length - 1 ? highlights[thisIndex + 1].id : undefined,
prevHighlightId: thisIndex > 0 ? highlights[thisIndex - 1].id : undefined,
};
}
isLoadable(highlighter) {

@@ -22,0 +69,0 @@ return this.deserializer.isLoadable(highlighter);

{
"name": "@openstax/highlighter",
"version": "1.3.2",
"version": "1.4.0",
"main": "dist/index.js",

@@ -21,3 +21,5 @@ "license": "MIT",

"watch": "tsc --noEmit --watch",
"watch:test": "jest --watchAll"
"watch:test": "jest --watchAll",
"preinstall": "./script/build-client.bash",
"prepublish": "npm-run-all lint build:clean"
},

@@ -32,2 +34,3 @@ "devDependencies": {

"@types/jest": "^23.3.7",
"@types/uuid": "^3.4.6",
"babel-jest": "^23.6.0",

@@ -72,4 +75,6 @@ "babel-loader": "^8.0.4",

"dependencies": {
"serialize-selection": "^1.1.1"
"@openstax/highlights-client": "./highlights-client/",
"serialize-selection": "^1.1.1",
"uuid": "^3.3.3"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc