text-input-guard 0.1.4 → 0.1.6

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.
@@ -156,6 +156,30 @@ type GuardContext = {
156
156
  * - IME変換中かどうか
157
157
  */
158
158
  composing: boolean;
159
+ /**
160
+ * - 直前の入力操作種別(insertText / insertFromPaste / insertCompositionText 等)
161
+ */
162
+ inputType: string | null;
163
+ /**
164
+ * - 挿入前の全文字列(置換範囲は除去済み)
165
+ */
166
+ beforeText: string;
167
+ /**
168
+ * - 挿入位置/置換開始位置(selectionStart)
169
+ */
170
+ replaceStart: number;
171
+ /**
172
+ * - 置換終了位置(selectionEnd)
173
+ */
174
+ replaceEnd: number;
175
+ /**
176
+ * - 挿入された文字列
177
+ */
178
+ insertedText: string;
179
+ /**
180
+ * - 挿入後の全文字列(後で代入する)
181
+ */
182
+ afterText: string;
159
183
  /**
160
184
  * - エラーを登録する関数
161
185
  */
@@ -566,6 +590,145 @@ type FilterRuleOptions = {
566
590
  denyFlags?: string;
567
591
  };
568
592
 
593
+ /**
594
+ * length ルールを生成する
595
+ * @param {LengthRuleOptions} [options]
596
+ * @returns {import("../text-input-guard.js").Rule}
597
+ */
598
+ declare function length(options?: LengthRuleOptions): Rule;
599
+ declare namespace length {
600
+ /**
601
+ * datasetから length ルールを生成する
602
+ * - data-tig-rules-length が無ければ null
603
+ * - オプションは data-tig-rules-length-xxx から読む
604
+ *
605
+ * 対応する data 属性(dataset 名)
606
+ * - data-tig-rules-length -> dataset.tigRulesLength
607
+ * - data-tig-rules-length-max -> dataset.tigRulesLengthMax
608
+ * - data-tig-rules-length-overflow-input -> dataset.tigRulesLengthOverflowInput
609
+ * - data-tig-rules-length-unit -> dataset.tigRulesLengthUnit
610
+ *
611
+ * @param {DOMStringMap} dataset
612
+ * @param {HTMLInputElement|HTMLTextAreaElement} _el
613
+ * @returns {import("../text-input-guard.js").Rule|null}
614
+ */
615
+ function fromDataset(dataset: DOMStringMap, _el: HTMLInputElement | HTMLTextAreaElement): Rule | null;
616
+ }
617
+ /**
618
+ * length ルールのオプション
619
+ */
620
+ type LengthRuleOptions = {
621
+ /**
622
+ * - 最大長(グラフェム数)。未指定なら制限なし
623
+ */
624
+ max?: number;
625
+ /**
626
+ * - 入力中に最大長を超えたときの挙動
627
+ */
628
+ overflowInput?: "block" | "error";
629
+ /**
630
+ * - 長さの単位
631
+ *
632
+ * block : 最大長を超える部分を切る
633
+ * error : エラーを積むだけ(値は変更しない)
634
+ */
635
+ unit?: "grapheme" | "utf-16" | "utf-32";
636
+ };
637
+
638
+ /**
639
+ * width ルールのオプション
640
+ * @typedef {Object} WidthRuleOptions
641
+ * @property {number} [max] - 最大長(全角は2, 半角は1)
642
+ * @property {"block"|"error"} [overflowInput="block"] - 入力中に最大長を超えたときの挙動
643
+ *
644
+ * block : 最大長を超える部分を切る
645
+ * error : エラーを積むだけ(値は変更しない)
646
+ */
647
+ /**
648
+ * width ルールを生成する
649
+ * @param {WidthRuleOptions} [options]
650
+ * @returns {import("../text-input-guard.js").Rule}
651
+ */
652
+ declare function width(options?: WidthRuleOptions): Rule;
653
+ declare namespace width {
654
+ /**
655
+ * datasetから length ルールを生成する
656
+ * - data-tig-rules-length が無ければ null
657
+ * - オプションは data-tig-rules-length-xxx から読む
658
+ *
659
+ * 対応する data 属性(dataset 名)
660
+ * - data-tig-rules-length -> dataset.tigRulesWidth
661
+ * - data-tig-rules-length-max -> dataset.tigRulesWidthMax
662
+ * - data-tig-rules-length-overflow-input -> dataset.tigRulesWidthOverflowInput
663
+ *
664
+ * @param {DOMStringMap} dataset
665
+ * @param {HTMLInputElement|HTMLTextAreaElement} _el
666
+ * @returns {import("../text-input-guard.js").Rule|null}
667
+ */
668
+ function fromDataset(dataset: DOMStringMap, _el: HTMLInputElement | HTMLTextAreaElement): Rule | null;
669
+ }
670
+ /**
671
+ * width ルールのオプション
672
+ */
673
+ type WidthRuleOptions = {
674
+ /**
675
+ * - 最大長(全角は2, 半角は1)
676
+ */
677
+ max?: number;
678
+ /**
679
+ * - 入力中に最大長を超えたときの挙動
680
+ *
681
+ * block : 最大長を超える部分を切る
682
+ * error : エラーを積むだけ(値は変更しない)
683
+ */
684
+ overflowInput?: "block" | "error";
685
+ };
686
+
687
+ /**
688
+ * bytes ルールを生成する
689
+ * @param {BytesRuleOptions} [options]
690
+ * @returns {import("../text-input-guard.js").Rule}
691
+ */
692
+ declare function bytes(options?: BytesRuleOptions): Rule;
693
+ declare namespace bytes {
694
+ /**
695
+ * datasetから bytes ルールを生成する
696
+ * - data-tig-rules-bytes が無ければ null
697
+ * - オプションは data-tig-rules-bytes-xxx から読む
698
+ *
699
+ * 対応する data 属性(dataset 名)
700
+ * - data-tig-rules-bytes -> dataset.tigRulesBytes
701
+ * - data-tig-rules-bytes-max -> dataset.tigRulesBytesMax
702
+ * - data-tig-rules-bytes-overflow-input -> dataset.tigRulesBytesOverflowInput
703
+ * - data-tig-rules-bytes-unit -> dataset.tigRulesBytesUnit
704
+ *
705
+ * @param {DOMStringMap} dataset
706
+ * @param {HTMLInputElement|HTMLTextAreaElement} _el
707
+ * @returns {import("../text-input-guard.js").Rule|null}
708
+ */
709
+ function fromDataset(dataset: DOMStringMap, _el: HTMLInputElement | HTMLTextAreaElement): Rule | null;
710
+ }
711
+ /**
712
+ * bytes ルールのオプション
713
+ */
714
+ type BytesRuleOptions = {
715
+ /**
716
+ * - 最大長(グラフェム数)。未指定なら制限なし
717
+ */
718
+ max?: number;
719
+ /**
720
+ * - 入力中に最大長を超えたときの挙動
721
+ */
722
+ overflowInput?: "block" | "error";
723
+ /**
724
+ * - サイズの単位(sjis系を使用する場合はfilterも必須)
725
+ *
726
+ * block : 最大長を超える部分を切る
727
+ * error : エラーを積むだけ(値は変更しない)
728
+ */
729
+ unit?: "utf-8" | "utf-16" | "utf-32" | "sjis" | "cp932";
730
+ };
731
+
569
732
  /**
570
733
  * The script is part of TextInputGuard.
571
734
  *
@@ -711,6 +874,9 @@ declare namespace rules {
711
874
  export { kana };
712
875
  export { ascii };
713
876
  export { filter };
877
+ export { length };
878
+ export { width };
879
+ export { bytes };
714
880
  export { prefix };
715
881
  export { suffix };
716
882
  export { trim };
@@ -721,4 +887,4 @@ declare namespace rules {
721
887
  */
722
888
  declare const version: any;
723
889
 
724
- export { ascii, attach, attachAll, autoAttach, comma, digits, filter, kana, numeric, prefix, rules, suffix, trim, version };
890
+ export { ascii, attach, attachAll, autoAttach, bytes, comma, digits, filter, kana, length, numeric, prefix, rules, suffix, trim, version, width };