shelving 1.187.1 → 1.187.3
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/markup/rule/inline.js +1 -1
- package/package.json +2 -2
- package/schema/ChoiceSchema.d.ts +1 -5
- package/schema/ChoiceSchema.js +2 -2
- package/util/template.d.ts +1 -1
- package/util/template.js +26 -17
package/markup/rule/inline.js
CHANGED
|
@@ -3,7 +3,7 @@ import { REACT_ELEMENT_TYPE } from "../util/internal.js";
|
|
|
3
3
|
import { getWordRegExp } from "../util/regexp.js";
|
|
4
4
|
import { getMarkupRule } from "../util/rule.js";
|
|
5
5
|
/** Map characters, e.g. `*`, to their coresponding HTML tag, e.g. `strong` */
|
|
6
|
-
const INLINE_CHARS = { "-": "del", "~": "del", "+": "ins", "*": "strong", _: "em", "=": "mark"
|
|
6
|
+
const INLINE_CHARS = { "-": "del", "~": "del", "+": "ins", "*": "strong", _: "em", "=": "mark" }; // Hyphen must be first so it works when we use the keys as a character class.
|
|
7
7
|
const INLINE_REGEXP = getWordRegExp(`(?<wrap>(?<char>[${Object.keys(INLINE_CHARS).join("")}])+)(?<text>(?!\\k<char>)\\S(?:[\\s\\S]*?(?!\\k<char>)\\S)?)\\k<wrap>`);
|
|
8
8
|
/**
|
|
9
9
|
* Inline strong, emphasis, insert, delete, highlight.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shelving",
|
|
3
|
-
"version": "1.187.
|
|
3
|
+
"version": "1.187.3",
|
|
4
4
|
"author": "Dave Houlbrooke <dave@shax.com>",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"@types/bun": "^1.3.12",
|
|
15
15
|
"@types/react": "^19.2.14",
|
|
16
16
|
"@types/react-dom": "^19.2.3",
|
|
17
|
-
"@typescript/native-preview": "^7.0.0-dev.
|
|
17
|
+
"@typescript/native-preview": "^7.0.0-dev.20260418.1",
|
|
18
18
|
"firebase": "^12.12.0",
|
|
19
19
|
"react": "^19.2.5",
|
|
20
20
|
"react-dom": "^19.2.5",
|
package/schema/ChoiceSchema.d.ts
CHANGED
|
@@ -13,10 +13,6 @@ export type ChoiceOptions<K extends string> = {
|
|
|
13
13
|
* - Array of string options in `[key]` format (`key` will be used as the `title` too).
|
|
14
14
|
*/
|
|
15
15
|
export type PossibleChoiceOptions<K extends string> = ImmutableArray<K> | ChoiceOptions<K>;
|
|
16
|
-
/** A single tuple for a choice option in `[key, title]` format. */
|
|
17
|
-
export type ChoiceOption<K extends string> = readonly [title: K, title: string];
|
|
18
|
-
/** Get a `ChoiceOptions` object for a set of `PossibleChoiceOptions`. */
|
|
19
|
-
export declare function getChoiceOptions<K extends string>(options: PossibleChoiceOptions<K>): ChoiceOptions<K>;
|
|
20
16
|
/** Allowed options for `ChoiceSchema` */
|
|
21
17
|
export interface ChoiceSchemaOptions<K extends string> extends Omit<SchemaOptions, "value"> {
|
|
22
18
|
/** Specify correct options using a dictionary of entries. */
|
|
@@ -33,4 +29,4 @@ export declare class ChoiceSchema<K extends string> extends Schema<K> {
|
|
|
33
29
|
format(value: K): string;
|
|
34
30
|
}
|
|
35
31
|
/** Choose from an allowed set of values. */
|
|
36
|
-
export declare function CHOICE<K extends string>(options: PossibleChoiceOptions<K>
|
|
32
|
+
export declare function CHOICE<K extends string>(options: PossibleChoiceOptions<K>): ChoiceSchema<K>;
|
package/schema/ChoiceSchema.js
CHANGED
|
@@ -2,7 +2,7 @@ import { isArray } from "../util/array.js";
|
|
|
2
2
|
import { isProp } from "../util/object.js";
|
|
3
3
|
import { Schema } from "./Schema.js";
|
|
4
4
|
/** Get a `ChoiceOptions` object for a set of `PossibleChoiceOptions`. */
|
|
5
|
-
|
|
5
|
+
function _getChoiceOptions(options) {
|
|
6
6
|
return isArray(options) ? Object.fromEntries(options.map(_getChoiceOption)) : options;
|
|
7
7
|
}
|
|
8
8
|
function _getChoiceOption(k) {
|
|
@@ -13,7 +13,7 @@ export class ChoiceSchema extends Schema {
|
|
|
13
13
|
options;
|
|
14
14
|
constructor({ one = "choice", title = "Choice", placeholder = `No ${one}`, options, value, ...rest }) {
|
|
15
15
|
super({ one, title, value, placeholder, ...rest });
|
|
16
|
-
this.options =
|
|
16
|
+
this.options = _getChoiceOptions(options);
|
|
17
17
|
}
|
|
18
18
|
validate(unsafeValue = this.value) {
|
|
19
19
|
if (typeof unsafeValue === "string" && isProp(this.options, unsafeValue))
|
package/util/template.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ImmutableArray } from "./array.js";
|
|
2
2
|
import { type ImmutableDictionary } from "./dictionary.js";
|
|
3
3
|
import { type AnyCaller } from "./function.js";
|
|
4
4
|
import { type NotString, type PossibleString } from "./string.js";
|
package/util/template.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { RequiredError } from "../error/RequiredError.js";
|
|
2
2
|
import { ValueError } from "../error/ValueError.js";
|
|
3
|
+
import { isArray } from "./array.js";
|
|
4
|
+
import { getDataProp, isData } from "./data.js";
|
|
3
5
|
import { EMPTY_DICTIONARY } from "./dictionary.js";
|
|
4
6
|
import { isFunction } from "./function.js";
|
|
5
7
|
import { setMapItem } from "./map.js";
|
|
6
|
-
import { isObject } from "./object.js";
|
|
7
8
|
import { getString } from "./string.js";
|
|
8
9
|
// RegExp to find named variables in several formats e.g. `:a`, `${b}`, `{{c}}` or `{d}`
|
|
9
10
|
const R_PLACEHOLDERS = /(\*\*?|:[a-z][a-z0-9]*|\$\{[a-z][a-z0-9]*\}|\{\{[a-z][a-z0-9]*\}\}|\{[a-z][a-z0-9]*\})/i;
|
|
@@ -114,24 +115,32 @@ export function renderTemplate(template, values, caller = renderTemplate) {
|
|
|
114
115
|
if (!chunks.length)
|
|
115
116
|
return template;
|
|
116
117
|
let output = template;
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
118
|
+
if (isFunction(values)) {
|
|
119
|
+
for (const { name, placeholder } of chunks)
|
|
120
|
+
output = output.replace(placeholder, values(name));
|
|
121
|
+
}
|
|
122
|
+
else if (isData(values)) {
|
|
123
|
+
for (const { name, placeholder } of chunks) {
|
|
124
|
+
const v = getString(getDataProp(values, name));
|
|
125
|
+
if (v === undefined)
|
|
126
|
+
throw new RequiredError(`Template placeholder "${name}" not found in object`, { received: values, name, caller });
|
|
127
|
+
output = output.replace(placeholder, v);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
else if (isArray(values)) {
|
|
131
|
+
for (const { name, placeholder } of chunks) {
|
|
132
|
+
const v = getString(values[Number(name)]);
|
|
133
|
+
if (v === undefined)
|
|
134
|
+
throw new RequiredError(`Template placeholder "${name}" not found in array`, { received: values, name, caller });
|
|
135
|
+
output = output.replace(placeholder, v);
|
|
136
|
+
}
|
|
129
137
|
}
|
|
130
138
|
else {
|
|
131
|
-
// Single value for all placeholders.
|
|
132
139
|
const v = getString(values);
|
|
133
|
-
if (v
|
|
134
|
-
|
|
140
|
+
if (v === undefined)
|
|
141
|
+
throw new RequiredError(`Template value must be string`, { received: values, caller });
|
|
142
|
+
for (const { placeholder } of chunks)
|
|
143
|
+
output = output.replace(placeholder, v);
|
|
135
144
|
}
|
|
136
|
-
|
|
145
|
+
return output;
|
|
137
146
|
}
|