@unseenco/theatre-core 0.1.18 → 0.2.1
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/dist/index.d.ts +21 -0
- package/dist/index.js +110 -10
- package/dist/index.js.map +4 -4
- package/dist/index.mjs +110 -10
- package/dist/index.mjs.map +4 -4
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -3445,6 +3445,15 @@ var number = (defaultValue, opts = {}) => {
|
|
|
3445
3445
|
);
|
|
3446
3446
|
}
|
|
3447
3447
|
}
|
|
3448
|
+
if (Object.prototype.hasOwnProperty.call(opts, "precision")) {
|
|
3449
|
+
if (typeof opts.precision !== "number" || !isFinite(opts.precision) || opts.precision < 0 || Math.floor(opts.precision) !== opts.precision) {
|
|
3450
|
+
throw new Error(
|
|
3451
|
+
"opts.precision in t.number(defaultValue, opts) must be a non-negative integer. ".concat(userReadableTypeOfValue_default(
|
|
3452
|
+
opts.precision
|
|
3453
|
+
), " given.")
|
|
3454
|
+
);
|
|
3455
|
+
}
|
|
3456
|
+
}
|
|
3448
3457
|
}
|
|
3449
3458
|
}
|
|
3450
3459
|
return {
|
|
@@ -3456,6 +3465,7 @@ var number = (defaultValue, opts = {}) => {
|
|
|
3456
3465
|
label: opts.label,
|
|
3457
3466
|
nudgeFn: opts.nudgeFn ?? defaultNumberNudgeFn,
|
|
3458
3467
|
nudgeMultiplier: typeof opts.nudgeMultiplier === "number" ? opts.nudgeMultiplier : void 0,
|
|
3468
|
+
precision: typeof opts.precision === "number" ? opts.precision : void 0,
|
|
3459
3469
|
interpolate: _interpolateNumber,
|
|
3460
3470
|
deserializeAndSanitize: numberDeserializer(opts.range)
|
|
3461
3471
|
};
|
|
@@ -5059,6 +5069,69 @@ function registerObjectPropConfig(projectId, sheetId, objectKey, config) {
|
|
|
5059
5069
|
);
|
|
5060
5070
|
}
|
|
5061
5071
|
|
|
5072
|
+
// shared/src/propTypes/numberPrecision.ts
|
|
5073
|
+
var DEFAULT_NUMBER_PRECISION = 3;
|
|
5074
|
+
function resolveNumberPrecision(propPrecision, projectPrecision) {
|
|
5075
|
+
if (propPrecision !== void 0)
|
|
5076
|
+
return propPrecision;
|
|
5077
|
+
if (projectPrecision !== void 0)
|
|
5078
|
+
return projectPrecision;
|
|
5079
|
+
return DEFAULT_NUMBER_PRECISION;
|
|
5080
|
+
}
|
|
5081
|
+
function applyNumberPrecisionDefaultsToPropConfig(config, projectNumberPrecision) {
|
|
5082
|
+
const defaultPrecision = resolveNumberPrecision(
|
|
5083
|
+
void 0,
|
|
5084
|
+
projectNumberPrecision
|
|
5085
|
+
);
|
|
5086
|
+
if (config.type === "number") {
|
|
5087
|
+
if (config.precision !== void 0)
|
|
5088
|
+
return config;
|
|
5089
|
+
return {
|
|
5090
|
+
...config,
|
|
5091
|
+
precision: defaultPrecision
|
|
5092
|
+
};
|
|
5093
|
+
}
|
|
5094
|
+
if (config.type === "compound") {
|
|
5095
|
+
return {
|
|
5096
|
+
...config,
|
|
5097
|
+
props: mapCompoundProps(
|
|
5098
|
+
config,
|
|
5099
|
+
(subConfig) => applyNumberPrecisionDefaultsToPropConfig(
|
|
5100
|
+
subConfig,
|
|
5101
|
+
projectNumberPrecision
|
|
5102
|
+
)
|
|
5103
|
+
)
|
|
5104
|
+
};
|
|
5105
|
+
}
|
|
5106
|
+
if (config.type === "enum") {
|
|
5107
|
+
return {
|
|
5108
|
+
...config,
|
|
5109
|
+
cases: mapEnumCases(
|
|
5110
|
+
config,
|
|
5111
|
+
(subConfig) => applyNumberPrecisionDefaultsToPropConfig(
|
|
5112
|
+
subConfig,
|
|
5113
|
+
projectNumberPrecision
|
|
5114
|
+
)
|
|
5115
|
+
)
|
|
5116
|
+
};
|
|
5117
|
+
}
|
|
5118
|
+
return config;
|
|
5119
|
+
}
|
|
5120
|
+
function mapCompoundProps(config, fn2) {
|
|
5121
|
+
const props = {};
|
|
5122
|
+
for (const [key, subConfig] of Object.entries(config.props)) {
|
|
5123
|
+
props[key] = fn2(subConfig);
|
|
5124
|
+
}
|
|
5125
|
+
return props;
|
|
5126
|
+
}
|
|
5127
|
+
function mapEnumCases(config, fn2) {
|
|
5128
|
+
const cases = {};
|
|
5129
|
+
for (const [key, subConfig] of Object.entries(config.cases)) {
|
|
5130
|
+
cases[key] = fn2(subConfig);
|
|
5131
|
+
}
|
|
5132
|
+
return cases;
|
|
5133
|
+
}
|
|
5134
|
+
|
|
5062
5135
|
// core/src/sheetObjects/SheetObjectTemplate.ts
|
|
5063
5136
|
function isObjectEmpty(obj) {
|
|
5064
5137
|
return typeof obj === "object" && obj !== null && Object.keys(obj).length === 0;
|
|
@@ -5085,7 +5158,11 @@ var SheetObjectTemplate = class {
|
|
|
5085
5158
|
__publicField(this, "_staticPropPaths", /* @__PURE__ */ new Set());
|
|
5086
5159
|
__publicField(this, "_visibleInOutline", true);
|
|
5087
5160
|
this.address = { ...sheetTemplate.address, objectKey };
|
|
5088
|
-
|
|
5161
|
+
const configWithPrecisionDefaults = this._withNumberPrecisionDefaults(
|
|
5162
|
+
config,
|
|
5163
|
+
sheetTemplate.project
|
|
5164
|
+
);
|
|
5165
|
+
this._config = new Atom4(configWithPrecisionDefaults);
|
|
5089
5166
|
this._temp_actions_atom = new Atom4(_temp_actions);
|
|
5090
5167
|
this.showPropsOf_atom = new Atom4([]);
|
|
5091
5168
|
this._transientPropPaths = normalizeTransientPropPaths(
|
|
@@ -5109,7 +5186,7 @@ var SheetObjectTemplate = class {
|
|
|
5109
5186
|
this.address.projectId,
|
|
5110
5187
|
this.address.sheetId,
|
|
5111
5188
|
objectKey,
|
|
5112
|
-
|
|
5189
|
+
configWithPrecisionDefaults
|
|
5113
5190
|
);
|
|
5114
5191
|
this.pointerToSheetState = this.sheetTemplate.project.pointers.historic.sheetsById[this.address.sheetId];
|
|
5115
5192
|
this.pointerToStaticOverrides = this.pointerToSheetState.staticOverrides.byObject[this.address.objectKey];
|
|
@@ -5122,6 +5199,12 @@ var SheetObjectTemplate = class {
|
|
|
5122
5199
|
get staticConfig() {
|
|
5123
5200
|
return this._config.get();
|
|
5124
5201
|
}
|
|
5202
|
+
_withNumberPrecisionDefaults(config, project = this.project) {
|
|
5203
|
+
return applyNumberPrecisionDefaultsToPropConfig(
|
|
5204
|
+
config,
|
|
5205
|
+
project.config.numberPrecision
|
|
5206
|
+
);
|
|
5207
|
+
}
|
|
5125
5208
|
get configPointer() {
|
|
5126
5209
|
return this._config.pointer;
|
|
5127
5210
|
}
|
|
@@ -5169,16 +5252,17 @@ var SheetObjectTemplate = class {
|
|
|
5169
5252
|
);
|
|
5170
5253
|
}
|
|
5171
5254
|
createInstance(sheet, nativeObject, config) {
|
|
5172
|
-
this._config.set(config);
|
|
5255
|
+
this._config.set(this._withNumberPrecisionDefaults(config));
|
|
5173
5256
|
return new SheetObject(sheet, this, nativeObject);
|
|
5174
5257
|
}
|
|
5175
5258
|
reconfigure(config) {
|
|
5176
|
-
this.
|
|
5259
|
+
const configWithPrecisionDefaults = this._withNumberPrecisionDefaults(config);
|
|
5260
|
+
this._config.set(configWithPrecisionDefaults);
|
|
5177
5261
|
this._stripNonPersistingPropsFromAhistoricState();
|
|
5178
5262
|
this.project._stripPropsMissingFromConfig(
|
|
5179
5263
|
this.address.sheetId,
|
|
5180
5264
|
this.address.objectKey,
|
|
5181
|
-
|
|
5265
|
+
configWithPrecisionDefaults
|
|
5182
5266
|
);
|
|
5183
5267
|
}
|
|
5184
5268
|
addProps(config) {
|
|
@@ -5191,10 +5275,12 @@ var SheetObjectTemplate = class {
|
|
|
5191
5275
|
);
|
|
5192
5276
|
}
|
|
5193
5277
|
}
|
|
5194
|
-
const merged =
|
|
5195
|
-
|
|
5196
|
-
|
|
5197
|
-
|
|
5278
|
+
const merged = this._withNumberPrecisionDefaults(
|
|
5279
|
+
compoundFromSanitizedProps({
|
|
5280
|
+
...existing.props,
|
|
5281
|
+
...additional.props
|
|
5282
|
+
})
|
|
5283
|
+
);
|
|
5198
5284
|
this._config.set(merged);
|
|
5199
5285
|
registerObjectPropConfig(
|
|
5200
5286
|
this.address.projectId,
|
|
@@ -8378,6 +8464,9 @@ function getProject(id, config = {}) {
|
|
|
8378
8464
|
} else {
|
|
8379
8465
|
plogger._debug("no config.state");
|
|
8380
8466
|
}
|
|
8467
|
+
if (process.env.NODE_ENV !== "production") {
|
|
8468
|
+
validateProjectNumberPrecisionOrThrow(config.numberPrecision);
|
|
8469
|
+
}
|
|
8381
8470
|
return new TheatreProject(id, config);
|
|
8382
8471
|
}
|
|
8383
8472
|
var shallowValidateOnDiskState = (projectId, s2) => {
|
|
@@ -8392,6 +8481,17 @@ var shallowValidateOnDiskState = (projectId, s2) => {
|
|
|
8392
8481
|
var deepValidateOnDiskState = (projectId, s2) => {
|
|
8393
8482
|
shallowValidateOnDiskState(projectId, s2);
|
|
8394
8483
|
};
|
|
8484
|
+
var validateProjectNumberPrecisionOrThrow = (numberPrecision) => {
|
|
8485
|
+
if (numberPrecision === void 0)
|
|
8486
|
+
return;
|
|
8487
|
+
if (typeof numberPrecision !== "number" || !isFinite(numberPrecision) || numberPrecision < 0 || Math.floor(numberPrecision) !== numberPrecision) {
|
|
8488
|
+
throw new InvalidArgumentError(
|
|
8489
|
+
"Argument config.numberPrecision in Theatre.getProject(projectId, config) must be a non-negative integer. ".concat(userReadableTypeOfValue_default(
|
|
8490
|
+
numberPrecision
|
|
8491
|
+
), " given.")
|
|
8492
|
+
);
|
|
8493
|
+
}
|
|
8494
|
+
};
|
|
8395
8495
|
var validateProjectIdOrThrow = (value) => {
|
|
8396
8496
|
if (typeof value !== "string") {
|
|
8397
8497
|
throw new InvalidArgumentError(
|
|
@@ -8442,7 +8542,7 @@ var CoreBundle = class {
|
|
|
8442
8542
|
return "Theatre_CoreBundle";
|
|
8443
8543
|
}
|
|
8444
8544
|
get version() {
|
|
8445
|
-
return "0.1
|
|
8545
|
+
return "0.2.1";
|
|
8446
8546
|
}
|
|
8447
8547
|
getBitsForStudio(studio, callback) {
|
|
8448
8548
|
if (this._studio) {
|