text-input-guard 0.1.6 → 0.2.0

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.
@@ -288,6 +288,26 @@ class SwapState {
288
288
  * @property {any} [detail] - 追加情報(制限値など)
289
289
  */
290
290
 
291
+ /**
292
+ * バリデーションがどの評価タイミングから呼び出されたかを表す識別子
293
+ *
294
+ * - "input" : 入力中の評価(inputイベントなど)
295
+ * - "commit" : 確定時の評価(blurなど)
296
+ *
297
+ * @typedef {"input"|"commit"} ValidateSource
298
+ */
299
+
300
+ /**
301
+ * バリデーション結果を表すオブジェクト
302
+ * - 各ルールの評価が完了したタイミングでコールバックに渡される
303
+ *
304
+ * @typedef {Object} ValidateResult
305
+ * @property {Guard} guard - この結果を発生させた Guard インスタンス
306
+ * @property {ValidateSource} source - 評価が実行されたタイミング(input / commit)
307
+ * @property {TigError[]} errors - 発生したエラー一覧
308
+ * @property {boolean} isValid - エラーが存在しない場合は true
309
+ */
310
+
291
311
  /**
292
312
  * setValue で設定できる値型
293
313
  * - number は String に変換して設定する
@@ -380,6 +400,7 @@ class SwapState {
380
400
  * @property {boolean} [warn] - 非対応ルールなどを console.warn するか
381
401
  * @property {string} [invalidClass] - エラー時に付けるclass名
382
402
  * @property {SeparateValueOptions} [separateValue] - 表示値と内部値の分離設定
403
+ * @property {(result: ValidateResult) => void} [onValidate] - 評価完了時の通知(input/commitごと)
383
404
  */
384
405
 
385
406
  /**
@@ -434,7 +455,7 @@ function warnLog(msg, warn) {
434
455
  function attach(element, options = {}) {
435
456
  const guard = new InputGuard(element, options);
436
457
  guard.init();
437
- return guard.toGuard();
458
+ return guard.getGuard();
438
459
  }
439
460
 
440
461
  /**
@@ -514,6 +535,12 @@ class InputGuard {
514
535
  */
515
536
  this.rules = Array.isArray(options.rules) ? options.rules : [];
516
537
 
538
+ /**
539
+ * attach時に登録されたバリデーション結果コールバック
540
+ * @type {(result: ValidateResult) => void | undefined}
541
+ */
542
+ this.onValidate = options.onValidate;
543
+
517
544
  /**
518
545
  * 実際に送信を担う要素(swap時は hidden(raw) 側)
519
546
  * swapしない場合は originalElement と同一
@@ -549,6 +576,12 @@ class InputGuard {
549
576
  */
550
577
  this.errors = [];
551
578
 
579
+ /**
580
+ * attach の返却値
581
+ * @type {Guard|null}
582
+ */
583
+ this._guard = null;
584
+
552
585
  // --------------------------------------------------
553
586
  // pipeline(フェーズごとのルール配列)
554
587
  // --------------------------------------------------
@@ -1018,6 +1051,31 @@ class InputGuard {
1018
1051
  this.errors = [];
1019
1052
  }
1020
1053
 
1054
+ /**
1055
+ * バリデーション結果をコールバックへ通知する
1056
+ *
1057
+ * - attach() の options.onValidate が指定されている場合のみ呼び出す
1058
+ * - evaluateInput / evaluateCommit の評価完了時に実行される
1059
+ * - エラーが存在しない場合でも呼び出される
1060
+ *
1061
+ * @param {ValidateSource} source - 評価が実行されたタイミング("input" | "commit")
1062
+ * @returns {void}
1063
+ */
1064
+ notifyValidate(source) {
1065
+ if (!this.onValidate) {
1066
+ return;
1067
+ }
1068
+
1069
+ const errors = this.getErrors();
1070
+
1071
+ this.onValidate({
1072
+ guard: this.getGuard(),
1073
+ source,
1074
+ errors,
1075
+ isValid: errors.length === 0
1076
+ });
1077
+ }
1078
+
1021
1079
  /**
1022
1080
  * normalize.char フェーズを実行する(文字の正規化)
1023
1081
  * @param {string} value
@@ -1387,6 +1445,9 @@ class InputGuard {
1387
1445
  // 受理値は常にrawとして保存(revert先・getRawValueの一貫性)
1388
1446
  this.lastAcceptedValue = raw;
1389
1447
  this.lastAcceptedSelection = this.readSelection(display);
1448
+
1449
+ // コールバック関数処理
1450
+ this.notifyValidate("input");
1390
1451
  }
1391
1452
 
1392
1453
  /**
@@ -1451,6 +1512,9 @@ class InputGuard {
1451
1512
  // 8) 受理値は raw を保持(revertやgetRawValueが安定する)
1452
1513
  this.lastAcceptedValue = raw;
1453
1514
  this.lastAcceptedSelection = this.readSelection(display);
1515
+
1516
+ // コールバック関数処理
1517
+ this.notifyValidate("commit");
1454
1518
  }
1455
1519
 
1456
1520
  /**
@@ -1526,8 +1590,13 @@ class InputGuard {
1526
1590
  * - InputGuard 自体を公開せず、最小の操作だけを渡す
1527
1591
  * @returns {Guard}
1528
1592
  */
1529
- toGuard() {
1530
- return {
1593
+ getGuard() {
1594
+ if (this._guard) {
1595
+ return this._guard;
1596
+ }
1597
+
1598
+ // ここで “this” を閉じ込めた関数群を一度だけ作る
1599
+ this._guard = {
1531
1600
  detach: () => this.detach(),
1532
1601
  isValid: () => this.isValid(),
1533
1602
  getErrors: () => this.getErrors(),
@@ -1539,6 +1608,8 @@ class InputGuard {
1539
1608
  commit: () => this.evaluateCommit(),
1540
1609
  setValue: (value, mode) => this.setValue(value, mode)
1541
1610
  };
1611
+
1612
+ return this._guard;
1542
1613
  }
1543
1614
  }
1544
1615
 
@@ -2168,8 +2239,8 @@ numeric.fromDataset = function fromDataset(dataset, _el) {
2168
2239
  * @property {boolean} [countLeadingZeros=true] - 整数部の先頭ゼロを桁数に含める
2169
2240
  * @property {"none"|"truncateLeft"|"truncateRight"|"clamp"} [fixIntOnBlur="none"] - blur時の整数部補正
2170
2241
  * @property {"none"|"truncate"|"round"} [fixFracOnBlur="none"] - blur時の小数部補正
2171
- * @property {"none"|"block"} [overflowInputInt="none"] - 入力中:整数部が最大桁を超える入力をブロックする
2172
- * @property {"none"|"block"} [overflowInputFrac="none"] - 入力中:小数部が最大桁を超える入力をブロックする
2242
+ * @property {"block"|"error"} [modeInt="block"] - 整数部が最大桁を超える入力の挙動
2243
+ * @property {"block"|"error"} [modeFrac="block"] - 小数部が最大桁を超える入力の挙動
2173
2244
  * @property {boolean} [forceFracOnBlur=false] - blur時に小数部を必ず表示(frac桁まで0埋め)
2174
2245
  */
2175
2246
 
@@ -2311,8 +2382,8 @@ function digits(options = {}) {
2311
2382
  countLeadingZeros: options.countLeadingZeros ?? true,
2312
2383
  fixIntOnBlur: options.fixIntOnBlur ?? "none",
2313
2384
  fixFracOnBlur: options.fixFracOnBlur ?? "none",
2314
- overflowInputInt: options.overflowInputInt ?? "none",
2315
- overflowInputFrac: options.overflowInputFrac ?? "none",
2385
+ modeInt: options.modeInt ?? "block",
2386
+ modeFrac: options.modeFrac ?? "block",
2316
2387
  forceFracOnBlur: options.forceFracOnBlur ?? false
2317
2388
  };
2318
2389
 
@@ -2339,7 +2410,7 @@ function digits(options = {}) {
2339
2410
  const intDigits = countIntDigits(intPart, opt.countLeadingZeros);
2340
2411
  if (intDigits > opt.int) {
2341
2412
  // 入力ブロック(int)
2342
- if (opt.overflowInputInt === "block") {
2413
+ if (opt.modeInt === "block") {
2343
2414
  ctx.requestRevert({
2344
2415
  reason: "digits.int_overflow",
2345
2416
  detail: { limit: opt.int, actual: intDigits }
@@ -2362,7 +2433,7 @@ function digits(options = {}) {
2362
2433
  const fracDigits = (fracPart ?? "").length;
2363
2434
  if (fracDigits > opt.frac) {
2364
2435
  // 入力ブロック(frac)
2365
- if (opt.overflowInputFrac === "block") {
2436
+ if (opt.modeFrac === "block") {
2366
2437
  ctx.requestRevert({
2367
2438
  reason: "digits.frac_overflow",
2368
2439
  detail: { limit: opt.frac, actual: fracDigits }
@@ -2479,8 +2550,8 @@ function digits(options = {}) {
2479
2550
  * - data-tig-rules-digits-count-leading-zeros -> dataset.tigRulesDigitsCountLeadingZeros
2480
2551
  * - data-tig-rules-digits-fix-int-on-blur -> dataset.tigRulesDigitsFixIntOnBlur
2481
2552
  * - data-tig-rules-digits-fix-frac-on-blur -> dataset.tigRulesDigitsFixFracOnBlur
2482
- * - data-tig-rules-digits-overflow-input-int -> dataset.tigRulesDigitsOverflowInputInt
2483
- * - data-tig-rules-digits-overflow-input-frac -> dataset.tigRulesDigitsOverflowInputFrac
2553
+ * - data-tig-rules-digits-mode-int -> dataset.tigRulesDigitsModeInt
2554
+ * - data-tig-rules-digits-mode-frac -> dataset.tigRulesDigitsModeFrac
2484
2555
  * - data-tig-rules-digits-force-frac-on-blur -> dataset.tigRulesDigitsForceFracOnBlur
2485
2556
  *
2486
2557
  * @param {DOMStringMap} dataset
@@ -2533,15 +2604,15 @@ digits.fromDataset = function fromDataset(dataset, _el) {
2533
2604
  options.fixFracOnBlur = fixFrac;
2534
2605
  }
2535
2606
 
2536
- // overflowInputInt / overflowInputFrac
2537
- const ovInt = parseDatasetEnum(dataset.tigRulesDigitsOverflowInputInt, ["none", "block"]);
2538
- if (ovInt != null) {
2539
- options.overflowInputInt = ovInt;
2607
+ // modeInt / modeFrac
2608
+ const modeInt = parseDatasetEnum(dataset.tigRulesDigitsModeInt, ["block", "error"]);
2609
+ if (modeInt != null) {
2610
+ options.modeInt = modeInt;
2540
2611
  }
2541
2612
 
2542
- const ovFrac = parseDatasetEnum(dataset.tigRulesDigitsOverflowInputFrac, ["none", "block"]);
2543
- if (ovFrac != null) {
2544
- options.overflowInputFrac = ovFrac;
2613
+ const modeFrac = parseDatasetEnum(dataset.tigRulesDigitsModeFrac, ["block", "error"]);
2614
+ if (modeFrac != null) {
2615
+ options.modeFrac = modeFrac;
2545
2616
  }
2546
2617
 
2547
2618
  // forceFracOnBlur
@@ -5771,13 +5842,10 @@ function kana(options = {}) {
5771
5842
  }
5772
5843
  s = Mojix.toKatakana(s);
5773
5844
  if (opt.target === "katakana-full") {
5774
- s = Mojix.toFullWidthSpace(s);
5775
5845
  s = Mojix.toFullWidthKana(s);
5776
5846
  } else if (opt.target === "katakana-half") {
5777
- s = Mojix.toHalfWidthSpace(s);
5778
5847
  s = Mojix.toHalfWidthKana(s);
5779
5848
  } else {
5780
- s = Mojix.toFullWidthSpace(s);
5781
5849
  s = Mojix.toFullWidthKana(s);
5782
5850
  s = Mojix.toHiragana(s);
5783
5851
  }
@@ -5921,6 +5989,23 @@ ascii.fromDataset = function fromDataset(dataset, _el) {
5921
5989
  */
5922
5990
 
5923
5991
 
5992
+ /**
5993
+ * filter ルールのオプション
5994
+ * - category は和集合で扱う(複数指定OK)
5995
+ * - allow は追加許可(和集合)
5996
+ * - deny は除外(差集合)
5997
+ *
5998
+ * allowed = (category の和集合 ∪ allow) − deny
5999
+ *
6000
+ * @typedef {Object} FilterRuleOptions
6001
+ * @property {"block"|"error"} [mode="block"] - 不要文字を入力中した場合の挙動
6002
+ * @property {FilterCategory[]} [category] - カテゴリ(配列)
6003
+ * @property {RegExp|string} [allow] - 追加で許可する正規表現(1文字にマッチさせる想定)
6004
+ * @property {string} [allowFlags] - allow が文字列のときの flags("iu" など。g/y は無視)
6005
+ * @property {RegExp|string} [deny] - 除外する正規表現(1文字にマッチさせる想定)
6006
+ * @property {string} [denyFlags] - deny が文字列のときの flags("iu" など。g/y は無視)
6007
+ */
6008
+
5924
6009
  /**
5925
6010
  * filter ルールのカテゴリ名
5926
6011
  *
@@ -5959,28 +6044,6 @@ const FILTER_CATEGORIES = [
5959
6044
  "single-codepoint-only"
5960
6045
  ];
5961
6046
 
5962
- /**
5963
- * filter ルールの動作モード
5964
- * @typedef {"drop"|"error"} FilterMode
5965
- */
5966
-
5967
- /**
5968
- * filter ルールのオプション
5969
- * - category は和集合で扱う(複数指定OK)
5970
- * - allow は追加許可(和集合)
5971
- * - deny は除外(差集合)
5972
- *
5973
- * allowed = (category の和集合 ∪ allow) − deny
5974
- *
5975
- * @typedef {Object} FilterRuleOptions
5976
- * @property {FilterMode} [mode="drop"] - drop: 不要文字を削除 / error: 削除せずエラーを積む
5977
- * @property {FilterCategory[]} [category] - カテゴリ(配列)
5978
- * @property {RegExp|string} [allow] - 追加で許可する正規表現(1文字にマッチさせる想定)
5979
- * @property {string} [allowFlags] - allow が文字列のときの flags("iu" など。g/y は無視)
5980
- * @property {RegExp|string} [deny] - 除外する正規表現(1文字にマッチさせる想定)
5981
- * @property {string} [denyFlags] - deny が文字列のときの flags("iu" など。g/y は無視)
5982
- */
5983
-
5984
6047
  /**
5985
6048
  * /g や /y は lastIndex の罠があるので除去して使う
5986
6049
  * @param {string} flags
@@ -6182,16 +6245,13 @@ const scanByAllowed = function (value, isAllowed, maxInvalidChars = 20) {
6182
6245
 
6183
6246
  /**
6184
6247
  * filter ルールを生成する
6185
- * - mode="drop": 不要文字を落とすだけ
6186
- * - mode="error": 文字は落とさず validate でエラーを積む
6187
- *
6188
6248
  * @param {FilterRuleOptions} [options]
6189
6249
  * @returns {Rule}
6190
6250
  */
6191
6251
  function filter(options = {}) {
6192
6252
  /** @type {FilterRuleOptions} */
6193
6253
  const opt = {
6194
- mode: options.mode ?? "drop",
6254
+ mode: options.mode ?? "block",
6195
6255
  category: options.category ?? [],
6196
6256
  allow: options.allow,
6197
6257
  allowFlags: options.allowFlags,
@@ -6276,7 +6336,7 @@ function filter(options = {}) {
6276
6336
  *
6277
6337
  * 対応する data 属性(dataset 名)
6278
6338
  * - data-tig-rules-filter -> dataset.tigRulesFilter
6279
- * - data-tig-rules-filter-mode -> dataset.tigRulesFilterMode ("drop"|"error")
6339
+ * - data-tig-rules-filter-mode -> dataset.tigRulesFilterMode
6280
6340
  * - data-tig-rules-filter-category -> dataset.tigRulesFilterCategory ("a,b,c")
6281
6341
  * - data-tig-rules-filter-allow -> dataset.tigRulesFilterAllow
6282
6342
  * - data-tig-rules-filter-allow-flags -> dataset.tigRulesFilterAllowFlags
@@ -6295,7 +6355,7 @@ filter.fromDataset = function fromDataset(dataset, _el) {
6295
6355
  /** @type {FilterRuleOptions} */
6296
6356
  const options = {};
6297
6357
 
6298
- const mode = parseDatasetEnum(dataset.tigRulesFilterMode, ["drop", "error"]);
6358
+ const mode = parseDatasetEnum(dataset.tigRulesFilterMode, ["block", "error"]);
6299
6359
  if (mode != null) {
6300
6360
  options.mode = mode;
6301
6361
  }
@@ -6351,11 +6411,8 @@ filter.fromDataset = function fromDataset(dataset, _el) {
6351
6411
  * length ルールのオプション
6352
6412
  * @typedef {Object} LengthRuleOptions
6353
6413
  * @property {number} [max] - 最大長(グラフェム数)。未指定なら制限なし
6354
- * @property {"block"|"error"} [overflowInput="block"] - 入力中に最大長を超えたときの挙動
6414
+ * @property {"block"|"error"} [mode="block"] - 入力中に最大長を超えたときの挙動
6355
6415
  * @property {"grapheme"|"utf-16"|"utf-32"} [unit="grapheme"] - 長さの単位
6356
- *
6357
- * block : 最大長を超える部分を切る
6358
- * error : エラーを積むだけ(値は変更しない)
6359
6416
  */
6360
6417
 
6361
6418
  /**
@@ -6476,7 +6533,7 @@ function length(options = {}) {
6476
6533
  /** @type {LengthRuleOptions} */
6477
6534
  const opt = {
6478
6535
  max: typeof options.max === "number" ? options.max : undefined,
6479
- overflowInput: options.overflowInput ?? "block",
6536
+ mode: options.mode ?? "block",
6480
6537
  unit: options.unit ?? "grapheme"
6481
6538
  };
6482
6539
 
@@ -6486,7 +6543,7 @@ function length(options = {}) {
6486
6543
 
6487
6544
  normalizeChar(value, ctx) {
6488
6545
  // block 以外は何もしない
6489
- if (opt.overflowInput !== "block") {
6546
+ if (opt.mode !== "block") {
6490
6547
  return value;
6491
6548
  }
6492
6549
  // max 未指定なら制限なし
@@ -6500,8 +6557,8 @@ function length(options = {}) {
6500
6557
 
6501
6558
  validate(value, ctx) {
6502
6559
  // error 以外は何もしない
6503
- if (opt.overflowInput !== "error") {
6504
- return value;
6560
+ if (opt.mode !== "error") {
6561
+ return;
6505
6562
  }
6506
6563
  // max 未指定なら制限なし
6507
6564
  if (typeof opt.max !== "number") {
@@ -6514,7 +6571,7 @@ function length(options = {}) {
6514
6571
  code: "length.max_overflow",
6515
6572
  rule: "length",
6516
6573
  phase: "validate",
6517
- detail: { max: opt.max, actual: len }
6574
+ detail: { limit: opt.max, actual: len }
6518
6575
  });
6519
6576
  }
6520
6577
  }
@@ -6529,7 +6586,7 @@ function length(options = {}) {
6529
6586
  * 対応する data 属性(dataset 名)
6530
6587
  * - data-tig-rules-length -> dataset.tigRulesLength
6531
6588
  * - data-tig-rules-length-max -> dataset.tigRulesLengthMax
6532
- * - data-tig-rules-length-overflow-input -> dataset.tigRulesLengthOverflowInput
6589
+ * - data-tig-rules-length-mode -> dataset.tigRulesLengthMode
6533
6590
  * - data-tig-rules-length-unit -> dataset.tigRulesLengthUnit
6534
6591
  *
6535
6592
  * @param {DOMStringMap} dataset
@@ -6550,12 +6607,9 @@ length.fromDataset = function fromDataset(dataset, _el) {
6550
6607
  options.max = max;
6551
6608
  }
6552
6609
 
6553
- const overflowInput = parseDatasetEnum(
6554
- dataset.tigRulesLengthOverflowInput,
6555
- ["block", "error"]
6556
- );
6557
- if (overflowInput != null) {
6558
- options.overflowInput = overflowInput;
6610
+ const mode = parseDatasetEnum(dataset.tigRulesLengthMode, ["block", "error"]);
6611
+ if (mode != null) {
6612
+ options.mode = mode;
6559
6613
  }
6560
6614
 
6561
6615
  const unit = parseDatasetEnum(
@@ -6584,10 +6638,7 @@ length.fromDataset = function fromDataset(dataset, _el) {
6584
6638
  * width ルールのオプション
6585
6639
  * @typedef {Object} WidthRuleOptions
6586
6640
  * @property {number} [max] - 最大長(全角は2, 半角は1)
6587
- * @property {"block"|"error"} [overflowInput="block"] - 入力中に最大長を超えたときの挙動
6588
- *
6589
- * block : 最大長を超える部分を切る
6590
- * error : エラーを積むだけ(値は変更しない)
6641
+ * @property {"block"|"error"} [mode="block"] - 入力中に最大長を超えたときの挙動
6591
6642
  */
6592
6643
 
6593
6644
  /**
@@ -6599,7 +6650,7 @@ function width(options = {}) {
6599
6650
  /** @type {WidthRuleOptions} */
6600
6651
  const opt = {
6601
6652
  max: typeof options.max === "number" ? options.max : undefined,
6602
- overflowInput: options.overflowInput ?? "block"
6653
+ mode: options.mode ?? "block"
6603
6654
  };
6604
6655
 
6605
6656
  return {
@@ -6608,7 +6659,7 @@ function width(options = {}) {
6608
6659
 
6609
6660
  normalizeChar(value, ctx) {
6610
6661
  // block 以外は何もしない
6611
- if (opt.overflowInput !== "block") {
6662
+ if (opt.mode !== "block") {
6612
6663
  return value;
6613
6664
  }
6614
6665
  // max 未指定なら制限なし
@@ -6632,8 +6683,8 @@ function width(options = {}) {
6632
6683
 
6633
6684
  validate(value, ctx) {
6634
6685
  // error 以外は何もしない
6635
- if (opt.overflowInput !== "error") {
6636
- return value;
6686
+ if (opt.mode !== "error") {
6687
+ return;
6637
6688
  }
6638
6689
  // max 未指定なら制限なし
6639
6690
  if (typeof opt.max !== "number") {
@@ -6653,10 +6704,10 @@ function width(options = {}) {
6653
6704
  const len = Mojix.getWidth(value);
6654
6705
  if (len > opt.max) {
6655
6706
  ctx.pushError({
6656
- code: "length.max_overflow",
6657
- rule: "length",
6707
+ code: "width.max_overflow",
6708
+ rule: "width",
6658
6709
  phase: "validate",
6659
- detail: { max: opt.max, actual: len }
6710
+ detail: { limit: opt.max, actual: len }
6660
6711
  });
6661
6712
  }
6662
6713
  }
@@ -6671,7 +6722,7 @@ function width(options = {}) {
6671
6722
  * 対応する data 属性(dataset 名)
6672
6723
  * - data-tig-rules-length -> dataset.tigRulesWidth
6673
6724
  * - data-tig-rules-length-max -> dataset.tigRulesWidthMax
6674
- * - data-tig-rules-length-overflow-input -> dataset.tigRulesWidthOverflowInput
6725
+ * - data-tig-rules-length-mode -> dataset.tigRulesWidthMode
6675
6726
  *
6676
6727
  * @param {DOMStringMap} dataset
6677
6728
  * @param {HTMLInputElement|HTMLTextAreaElement} _el
@@ -6691,12 +6742,9 @@ width.fromDataset = function fromDataset(dataset, _el) {
6691
6742
  options.max = max;
6692
6743
  }
6693
6744
 
6694
- const overflowInput = parseDatasetEnum(
6695
- dataset.tigRulesWidthOverflowInput,
6696
- ["block", "error"]
6697
- );
6698
- if (overflowInput != null) {
6699
- options.overflowInput = overflowInput;
6745
+ const mode = parseDatasetEnum(dataset.tigRulesWidthMode, ["block", "error"]);
6746
+ if (mode != null) {
6747
+ options.mode = mode;
6700
6748
  }
6701
6749
 
6702
6750
  return width(options);
@@ -6717,11 +6765,8 @@ width.fromDataset = function fromDataset(dataset, _el) {
6717
6765
  * bytes ルールのオプション
6718
6766
  * @typedef {Object} BytesRuleOptions
6719
6767
  * @property {number} [max] - 最大長(グラフェム数)。未指定なら制限なし
6720
- * @property {"block"|"error"} [overflowInput="block"] - 入力中に最大長を超えたときの挙動
6768
+ * @property {"block"|"error"} [mode="block"] - 入力中に最大長を超えたときの挙動
6721
6769
  * @property {"utf-8"|"utf-16"|"utf-32"|"sjis"|"cp932"} [unit="utf-8"] - サイズの単位(sjis系を使用する場合はfilterも必須)
6722
- *
6723
- * block : 最大長を超える部分を切る
6724
- * error : エラーを積むだけ(値は変更しない)
6725
6770
  */
6726
6771
 
6727
6772
  /**
@@ -6846,7 +6891,7 @@ function bytes(options = {}) {
6846
6891
  /** @type {BytesRuleOptions} */
6847
6892
  const opt = {
6848
6893
  max: typeof options.max === "number" ? options.max : undefined,
6849
- overflowInput: options.overflowInput ?? "block",
6894
+ mode: options.mode ?? "block",
6850
6895
  unit: options.unit ?? "utf-8"
6851
6896
  };
6852
6897
 
@@ -6856,7 +6901,7 @@ function bytes(options = {}) {
6856
6901
 
6857
6902
  normalizeChar(value, ctx) {
6858
6903
  // block 以外は何もしない
6859
- if (opt.overflowInput !== "block") {
6904
+ if (opt.mode !== "block") {
6860
6905
  return value;
6861
6906
  }
6862
6907
  // max 未指定なら制限なし
@@ -6870,8 +6915,8 @@ function bytes(options = {}) {
6870
6915
 
6871
6916
  validate(value, ctx) {
6872
6917
  // error 以外は何もしない
6873
- if (opt.overflowInput !== "error") {
6874
- return value;
6918
+ if (opt.mode !== "error") {
6919
+ return;
6875
6920
  }
6876
6921
  // max 未指定なら制限なし
6877
6922
  if (typeof opt.max !== "number") {
@@ -6899,7 +6944,7 @@ function bytes(options = {}) {
6899
6944
  * 対応する data 属性(dataset 名)
6900
6945
  * - data-tig-rules-bytes -> dataset.tigRulesBytes
6901
6946
  * - data-tig-rules-bytes-max -> dataset.tigRulesBytesMax
6902
- * - data-tig-rules-bytes-overflow-input -> dataset.tigRulesBytesOverflowInput
6947
+ * - data-tig-rules-bytes-mode -> dataset.tigRulesBytesMode
6903
6948
  * - data-tig-rules-bytes-unit -> dataset.tigRulesBytesUnit
6904
6949
  *
6905
6950
  * @param {DOMStringMap} dataset
@@ -6920,12 +6965,9 @@ bytes.fromDataset = function fromDataset(dataset, _el) {
6920
6965
  options.max = max;
6921
6966
  }
6922
6967
 
6923
- const overflowInput = parseDatasetEnum(
6924
- dataset.tigRulesBytesOverflowInput,
6925
- ["block", "error"]
6926
- );
6927
- if (overflowInput != null) {
6928
- options.overflowInput = overflowInput;
6968
+ const mode = parseDatasetEnum(dataset.tigRulesBytesMode, ["block", "error"]);
6969
+ if (mode != null) {
6970
+ options.mode = mode;
6929
6971
  }
6930
6972
 
6931
6973
  const unit = parseDatasetEnum(
@@ -7231,11 +7273,11 @@ const rules = {
7231
7273
 
7232
7274
  /**
7233
7275
  * バージョン(ビルド時に置換したいならここを差し替える)
7234
- * 例: rollup replace で ""0.1.6"" を package.json の version に置換
7276
+ * 例: rollup replace で ""0.2.0"" を package.json の version に置換
7235
7277
  */
7236
7278
  // @ts-ignore
7237
7279
  // eslint-disable-next-line no-undef
7238
- const version = "0.1.6" ;
7280
+ const version = "0.2.0" ;
7239
7281
 
7240
7282
  exports.ascii = ascii;
7241
7283
  exports.attach = attach;