@@ -20,7 +20,6 @@ extern crate log;
20
20
use js_sys:: Promise ;
21
21
use std:: cell:: RefCell ;
22
22
use std:: rc:: Rc ;
23
- use std:: str:: FromStr ;
24
23
use std:: sync:: Arc ;
25
24
use wasm_bindgen:: prelude:: * ;
26
25
use wasm_bindgen_futures:: { future_to_promise, JsFuture } ;
@@ -296,37 +295,64 @@ impl Driver {
296
295
} )
297
296
}
298
297
298
+ /// @deprecated Use `previewCluster` instead
299
+ #[ wasm_bindgen( js_name = "previewCitationCluster" ) ]
300
+ pub fn preview_citation_cluster (
301
+ & self ,
302
+ cites : Box < [ JsValue ] > ,
303
+ positions : Box < [ JsValue ] > ,
304
+ format : Option < String > ,
305
+ ) -> StringResult {
306
+ typescript_serde_result ( || {
307
+ let cites = utils:: read_js_array_2 ( cites) ?;
308
+ self . preview_cluster_inner ( PreviewCluster :: new ( cites, None ) , positions, format)
309
+ } )
310
+ }
311
+
299
312
/// Previews a formatted citation cluster, in a particular position.
300
313
///
301
- /// - `cites `: The cites to go in the cluster
314
+ /// - `cluster `: A cluster, without an `id` field. You'll want this to contain some cites.
302
315
/// - `positions`: An array of `ClusterPosition`s as in set_cluster_order, but with a single
303
316
/// cluster's id set to zero. The cluster with id=0 is the position to preview the cite. It
304
317
/// can replace another cluster, or be inserted before/after/between existing clusters, in
305
318
/// any location you can think of.
319
+ /// - `format`: an optional argument, an output format as a string, that is used only for this
320
+ /// preview.
306
321
///
307
- #[ wasm_bindgen( js_name = "previewCitationCluster " ) ]
308
- pub fn preview_citation_cluster (
322
+ #[ wasm_bindgen( js_name = "previewCluster " ) ]
323
+ pub fn preview_cluster (
309
324
& self ,
310
- cites : Box < [ JsValue ] > ,
325
+ preview_cluster : TPreviewCluster ,
311
326
positions : Box < [ JsValue ] > ,
312
- format : & str ,
327
+ format : Option < String > ,
313
328
) -> StringResult {
314
329
typescript_serde_result ( || {
315
- let cites: Vec < Cite < Markup > > = utils:: read_js_array_2 ( cites) ?;
316
- let positions: Vec < string_id:: ClusterPosition > = utils:: read_js_array_2 ( positions) ?;
317
- let mut eng = self . engine . borrow_mut ( ) ;
318
- let preview = eng. preview_citation_cluster (
319
- PreviewCluster :: new ( cites, None ) ,
320
- PreviewPosition :: MarkWithZeroStr ( & positions) ,
321
- Some (
322
- SupportedFormat :: from_str ( format)
323
- . map_err ( |( ) | DriverError :: UnknownOutputFormat ( format. to_owned ( ) ) ) ?,
324
- ) ,
325
- ) ;
326
- Ok ( preview?)
330
+ let preview_cluster: PreviewCluster = preview_cluster. into_serde ( ) ?;
331
+ self . preview_cluster_inner ( preview_cluster, positions, format)
327
332
} )
328
333
}
329
334
335
+ fn preview_cluster_inner (
336
+ & self ,
337
+ preview_cluster : PreviewCluster ,
338
+ positions : Box < [ JsValue ] > ,
339
+ format : Option < String > ,
340
+ ) -> Result < Arc < SmartString > , DriverError > {
341
+ let positions: Vec < string_id:: ClusterPosition > = utils:: read_js_array_2 ( positions) ?;
342
+ let mut eng = self . engine . borrow_mut ( ) ;
343
+ let preview = eng. preview_citation_cluster (
344
+ preview_cluster,
345
+ PreviewPosition :: MarkWithZeroStr ( & positions) ,
346
+ format
347
+ . map ( |frmt| {
348
+ frmt. parse :: < SupportedFormat > ( )
349
+ . map_err ( |( ) | DriverError :: UnknownOutputFormat ( frmt) )
350
+ } )
351
+ . transpose ( ) ?,
352
+ ) ;
353
+ Ok ( preview?)
354
+ }
355
+
330
356
#[ wasm_bindgen( js_name = "makeBibliography" ) ]
331
357
pub fn make_bibliography ( & self ) -> BibEntriesResult {
332
358
typescript_serde_result ( || {
@@ -508,7 +534,7 @@ interface InitOptions {
508
534
localeOverride?: string,
509
535
510
536
/** Disables sorting in the bibliography; items appear in cited order. */
511
- bibliographyNoSort?: bool ,
537
+ bibliographyNoSort?: boolean ,
512
538
}
513
539
514
540
/** This interface lets citeproc retrieve locales or modules asynchronously,
@@ -559,7 +585,7 @@ export type Cluster = {
559
585
cites: Cite[];
560
586
} & ClusterMode;
561
587
562
- export type PreviewCluster {
588
+ export type PreviewCluster = {
563
589
cites: Cite[];
564
590
} & ClusterMode;
565
591
@@ -706,11 +732,11 @@ interface WasmResult<T> {
706
732
is_ok(): boolean;
707
733
is_err(): boolean;
708
734
/** If this is an error, returns the default value. */
709
- unwrap_or(default : T): T;
735
+ unwrap_or(defaultValue : T): T;
710
736
/** If this is Ok, returns f(ok_val), else returns Err unmodified. */
711
737
map<R>(f: (t: T) => R): WasmResult<T>;
712
738
/** If this is Ok, returns f(ok_val), else returns the default value. */
713
- map_or<R>(default : R, f: (t: T) => R): R;
739
+ map_or<R>(defaultValue : R, f: (t: T) => R): R;
714
740
}
715
741
"# ;
716
742
@@ -753,11 +779,11 @@ interface IndependentMeta {
753
779
/** A list of languages for which a locale override was specified.
754
780
* Does not include the language-less final override. */
755
781
localeOverrides: string[],
756
- hasBibliography: bool ,
782
+ hasBibliography: boolean ,
757
783
}
758
784
interface StyleMeta {
759
785
info: StyleInfo,
760
- features: { [feature: string]: bool },
786
+ features: { [feature: string]: boolean },
761
787
defaultLocale: string,
762
788
/** May be absent on a dependent style */
763
789
class?: "in-text" | "note",
0 commit comments