@wordpress/dataviews 7.0.0 → 7.0.1-next.f34ab90e9.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.
@@ -80,8 +80,10 @@ export declare const LayoutMixed: {
80
80
  render: () => import("react").JSX.Element;
81
81
  };
82
82
  export declare const Validation: {
83
- render: ({ required }: {
83
+ render: ({ required, type, custom, }: {
84
84
  required: boolean;
85
+ custom: boolean;
86
+ type: "regular" | "panel";
85
87
  }) => import("react").JSX.Element;
86
88
  argTypes: {
87
89
  required: {
@@ -90,9 +92,24 @@ export declare const Validation: {
90
92
  };
91
93
  description: string;
92
94
  };
95
+ type: {
96
+ control: {
97
+ type: string;
98
+ };
99
+ description: string;
100
+ options: string[];
101
+ };
102
+ custom: {
103
+ control: {
104
+ type: string;
105
+ };
106
+ description: string;
107
+ };
93
108
  };
94
109
  args: {
95
110
  required: boolean;
111
+ type: string;
112
+ custom: boolean;
96
113
  };
97
114
  };
98
115
  export declare const Visibility: {
@@ -1 +1 @@
1
- {"version":3,"file":"index.story.d.ts","sourceRoot":"","sources":["../../../../src/components/dataform/stories/index.story.tsx"],"names":[],"mappings":"AAUA;;GAEG;AACH,OAAO,QAAQ,MAAM,UAAU,CAAC;AAixBhC,QAAA,MAAM,IAAI;;;CAGT,CAAC;AACF,eAAe,IAAI,CAAC;AAEpB,eAAO,MAAM,OAAO;uCArnBjB;QACF,IAAI,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,OAAO,GAAG,MAAM,CAAC;QAChD,aAAa,EAAE,SAAS,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,CAAC;KACnD;;;;;;;;;;CA2nBA,CAAC;AAEF,eAAO,MAAM,UAAU;6BA5QuB;QAAE,UAAU,EAAE,OAAO,CAAA;KAAE;;;;;;;;;;;;CAuRpE,CAAC;AAEF,eAAO,MAAM,WAAW;yCA/hBrB;QACF,IAAI,EAAE,SAAS,GAAG,SAAS,GAAG,OAAO,GAAG,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M,EAAE,SAAS,GAAG,UAAU,GAAG,OAAO,CAAC;KACzC;;;;;;;;;;;;;;;;;CAqjBA,CAAC;AAEF,eAAO,MAAM,aAAa;uCAzqBvB;QACF,IAAI,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,OAAO,GAAG,MAAM,CAAC;QAChD,aAAa,EAAE,SAAS,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,CAAC;KACnD;;;;;;;;;;CA+qBA,CAAC;AAEF,eAAO,MAAM,WAAW;;CAEvB,CAAC;AAEF,eAAO,MAAM,UAAU;0CAtepB;QACF,QAAQ,EAAE,OAAO,CAAC;QAClB,MAAM,EAAE,OAAO,CAAC;QAChB,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC;KAC1B;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwfA,CAAC;AAEF,eAAO,MAAM,UAAU;;CAEtB,CAAC"}
package/build-wp/index.js CHANGED
@@ -5315,7 +5315,7 @@ function addContainer(ariaLive = "polite") {
5315
5315
  const container = document.createElement("div");
5316
5316
  container.id = `a11y-speak-${ariaLive}`;
5317
5317
  container.className = "a11y-speak-region";
5318
- container.setAttribute("style", "position: absolute;margin: -1px;padding: 0;height: 1px;width: 1px;overflow: hidden;clip: rect(1px, 1px, 1px, 1px);-webkit-clip-path: inset(50%);clip-path: inset(50%);border: 0;word-wrap: normal !important;");
5318
+ container.setAttribute("style", "position:absolute;margin:-1px;padding:0;height:1px;width:1px;overflow:hidden;clip-path:inset(50%);border:0;word-wrap:normal !important;");
5319
5319
  container.setAttribute("aria-live", ariaLive);
5320
5320
  container.setAttribute("aria-relevant", "additions text");
5321
5321
  container.setAttribute("aria-atomic", "true");
@@ -5335,8 +5335,8 @@ function addIntroText() {
5335
5335
  introText.id = "a11y-speak-intro-text";
5336
5336
  introText.className = "a11y-speak-intro-text";
5337
5337
  introText.textContent = __3("Notifications");
5338
- introText.setAttribute("style", "position: absolute;margin: -1px;padding: 0;height: 1px;width: 1px;overflow: hidden;clip: rect(1px, 1px, 1px, 1px);-webkit-clip-path: inset(50%);clip-path: inset(50%);border: 0;word-wrap: normal !important;");
5339
- introText.setAttribute("hidden", "hidden");
5338
+ introText.setAttribute("style", "position:absolute;margin:-1px;padding:0;height:1px;width:1px;overflow:hidden;clip-path:inset(50%);border:0;word-wrap:normal !important;");
5339
+ introText.setAttribute("hidden", "");
5340
5340
  const {
5341
5341
  body
5342
5342
  } = document;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/dataviews",
3
- "version": "7.0.0",
3
+ "version": "7.0.1-next.f34ab90e9.0",
4
4
  "description": "DataViews is a component that provides an API to render datasets using different types of layouts (table, grid, list, etc.).",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -46,19 +46,19 @@
46
46
  "dependencies": {
47
47
  "@ariakit/react": "^0.4.15",
48
48
  "@babel/runtime": "7.25.7",
49
- "@wordpress/base-styles": "^6.5.0",
50
- "@wordpress/components": "^30.2.0",
51
- "@wordpress/compose": "^7.29.0",
52
- "@wordpress/data": "^10.29.0",
53
- "@wordpress/date": "^5.29.0",
54
- "@wordpress/element": "^6.29.0",
55
- "@wordpress/i18n": "^6.2.0",
56
- "@wordpress/icons": "^10.29.0",
57
- "@wordpress/keycodes": "^4.29.0",
58
- "@wordpress/primitives": "^4.29.0",
59
- "@wordpress/private-apis": "^1.29.0",
60
- "@wordpress/url": "^4.29.0",
61
- "@wordpress/warning": "^3.29.0",
49
+ "@wordpress/base-styles": "^6.5.1-next.f34ab90e9.0",
50
+ "@wordpress/components": "^30.2.1-next.f34ab90e9.0",
51
+ "@wordpress/compose": "^7.29.1-next.f34ab90e9.0",
52
+ "@wordpress/data": "^10.29.1-next.f34ab90e9.0",
53
+ "@wordpress/date": "^5.29.1-next.f34ab90e9.0",
54
+ "@wordpress/element": "^6.29.1-next.f34ab90e9.0",
55
+ "@wordpress/i18n": "^6.2.1-next.f34ab90e9.0",
56
+ "@wordpress/icons": "^10.29.1-next.f34ab90e9.0",
57
+ "@wordpress/keycodes": "^4.29.1-next.f34ab90e9.0",
58
+ "@wordpress/primitives": "^4.29.1-next.f34ab90e9.0",
59
+ "@wordpress/private-apis": "^1.29.1-next.f34ab90e9.0",
60
+ "@wordpress/url": "^4.29.1-next.f34ab90e9.0",
61
+ "@wordpress/warning": "^3.29.1-next.f34ab90e9.0",
62
62
  "clsx": "^2.1.1",
63
63
  "date-fns": "^4.1.0",
64
64
  "fast-deep-equal": "^3.1.3",
@@ -74,5 +74,5 @@
74
74
  "scripts": {
75
75
  "build:wp": "node build"
76
76
  },
77
- "gitHead": "445ede01e8abc8e49a1101b21a3651adbe852120"
77
+ "gitHead": "91f58004986ec6faf118825f925ac7873d171986"
78
78
  }
@@ -379,25 +379,59 @@ function CustomEditControl< Item >( {
379
379
  );
380
380
  }
381
381
 
382
- const ValidationComponent = ( { required }: { required: boolean } ) => {
382
+ const ValidationComponent = ( {
383
+ required,
384
+ type,
385
+ custom,
386
+ }: {
387
+ required: boolean;
388
+ custom: boolean;
389
+ type: 'regular' | 'panel';
390
+ } ) => {
383
391
  type ValidatedItem = {
384
392
  text: string;
385
393
  email: string;
386
394
  integer: number;
387
395
  boolean: boolean;
388
396
  customEdit: string;
389
- customValidation: string;
390
397
  };
391
398
 
392
399
  const [ post, setPost ] = useState< ValidatedItem >( {
393
- text: 'Hello, World!',
400
+ text: 'Can have letters and spaces',
394
401
  email: 'hi@example.com',
395
402
  integer: 2,
396
403
  boolean: true,
397
404
  customEdit: 'custom control',
398
- customValidation: 'potato',
399
405
  } );
400
406
 
407
+ const customTextRule = ( value: ValidatedItem ) => {
408
+ if ( ! /^[a-zA-Z ]+$/.test( value.text ) ) {
409
+ return 'Value must only contain letters and spaces.';
410
+ }
411
+
412
+ return null;
413
+ };
414
+ const customEmailRule = ( value: ValidatedItem ) => {
415
+ if ( ! /^[a-zA-Z0-9._%+-]+@example\.com$/.test( value.email ) ) {
416
+ return 'Email address must be from @example.com domain.';
417
+ }
418
+
419
+ return null;
420
+ };
421
+ const customIntegerRule = ( value: ValidatedItem ) => {
422
+ if ( value.integer % 2 !== 0 ) {
423
+ return 'Integer must be an even number.';
424
+ }
425
+
426
+ return null;
427
+ };
428
+
429
+ const maybeCustomRule = (
430
+ rule: ( item: ValidatedItem ) => null | string
431
+ ) => {
432
+ return custom ? rule : undefined;
433
+ };
434
+
401
435
  const _fields: Field< ValidatedItem >[] = [
402
436
  {
403
437
  id: 'text',
@@ -405,6 +439,7 @@ const ValidationComponent = ( { required }: { required: boolean } ) => {
405
439
  label: 'Text',
406
440
  isValid: {
407
441
  required,
442
+ custom: maybeCustomRule( customTextRule ),
408
443
  },
409
444
  },
410
445
  {
@@ -413,6 +448,7 @@ const ValidationComponent = ( { required }: { required: boolean } ) => {
413
448
  label: 'e-mail',
414
449
  isValid: {
415
450
  required,
451
+ custom: maybeCustomRule( customEmailRule ),
416
452
  },
417
453
  },
418
454
  {
@@ -421,6 +457,7 @@ const ValidationComponent = ( { required }: { required: boolean } ) => {
421
457
  label: 'Integer',
422
458
  isValid: {
423
459
  required,
460
+ custom: maybeCustomRule( customIntegerRule ),
424
461
  },
425
462
  },
426
463
  {
@@ -439,36 +476,11 @@ const ValidationComponent = ( { required }: { required: boolean } ) => {
439
476
  required,
440
477
  },
441
478
  },
442
- {
443
- id: 'customValidation',
444
- type: 'text',
445
- label: 'Custom validation',
446
- isValid: {
447
- required,
448
- custom: ( value: ValidatedItem ) => {
449
- if (
450
- ! [ 'tomato', 'potato' ].includes(
451
- value.customValidation
452
- )
453
- ) {
454
- return 'Value must be one of "tomato", "potato"';
455
- }
456
-
457
- return null;
458
- },
459
- },
460
- },
461
479
  ];
462
480
 
463
481
  const form = {
464
- fields: [
465
- 'text',
466
- 'email',
467
- 'integer',
468
- 'boolean',
469
- 'customEdit',
470
- 'customValidation',
471
- ],
482
+ layout: { type },
483
+ fields: [ 'text', 'email', 'integer', 'boolean', 'customEdit' ],
472
484
  };
473
485
 
474
486
  const canSave = isItemValid( post, _fields, form );
@@ -864,9 +876,20 @@ export const Validation = {
864
876
  control: { type: 'boolean' },
865
877
  description: 'Whether or not the fields are required.',
866
878
  },
879
+ type: {
880
+ control: { type: 'select' },
881
+ description: 'Chooses the validation type.',
882
+ options: [ 'regular', 'panel' ],
883
+ },
884
+ custom: {
885
+ control: { type: 'boolean' },
886
+ description: 'Whether or not the fields have custom validation.',
887
+ },
867
888
  },
868
889
  args: {
869
890
  required: true,
891
+ type: 'regular',
892
+ custom: true,
870
893
  },
871
894
  };
872
895