@panneau/core 5.0.0-alpha.0 → 5.0.0-alpha.10
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/README.md +2 -0
- package/dist/commands.d.ts +38 -0
- package/dist/commands.d.ts.map +1 -0
- package/dist/commands.js +22 -0
- package/dist/commands.js.map +1 -0
- package/dist/definition/abilities.d.ts +15 -4
- package/dist/definition/abilities.d.ts.map +1 -1
- package/dist/definition/abilities.js +18 -5
- package/dist/definition/abilities.js.map +1 -1
- package/dist/definition/form.d.ts +3 -2
- package/dist/definition/form.d.ts.map +1 -1
- package/dist/definition/form.js +24 -2
- package/dist/definition/form.js.map +1 -1
- package/dist/definition/itemActions.d.ts +53 -0
- package/dist/definition/itemActions.d.ts.map +1 -0
- package/dist/definition/itemActions.js +64 -0
- package/dist/definition/itemActions.js.map +1 -0
- package/dist/definition/list.d.ts +16 -0
- package/dist/definition/list.d.ts.map +1 -1
- package/dist/definition/list.js +64 -3
- package/dist/definition/list.js.map +1 -1
- package/dist/definition/resource.d.ts +2 -2
- package/dist/definition/resource.js +1 -1
- package/dist/definition/resource.js.map +1 -1
- package/dist/form/form.d.ts +9 -4
- package/dist/form/form.d.ts.map +1 -1
- package/dist/form/form.js +2 -1
- package/dist/form/form.js.map +1 -1
- package/dist/form/messages.d.ts.map +1 -1
- package/dist/form/messages.js +1 -0
- package/dist/form/messages.js.map +1 -1
- package/dist/form/problem.d.ts +2 -2
- package/dist/form/problem.d.ts.map +1 -1
- package/dist/form/problem.js +1 -1
- package/dist/form/problem.js.map +1 -1
- package/dist/form/selectors.d.ts +2 -2
- package/dist/form/selectors.d.ts.map +1 -1
- package/dist/form/selectors.js +1 -1
- package/dist/form/selectors.js.map +1 -1
- package/dist/form/store.d.ts +1 -1
- package/dist/form/store.js.map +1 -1
- package/dist/index.d.ts +20 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -3
- package/dist/list/list.d.ts +14 -3
- package/dist/list/list.d.ts.map +1 -1
- package/dist/list/list.js +39 -11
- package/dist/list/list.js.map +1 -1
- package/dist/list/router.js.map +1 -1
- package/dist/plugins.d.ts +22 -10
- package/dist/plugins.d.ts.map +1 -1
- package/dist/plugins.js +23 -3
- package/dist/plugins.js.map +1 -1
- package/dist/preview.d.ts +14 -0
- package/dist/preview.d.ts.map +1 -0
- package/dist/react/leaveGuards.d.ts +34 -0
- package/dist/react/leaveGuards.d.ts.map +1 -0
- package/dist/react/leaveGuards.js +84 -0
- package/dist/react/leaveGuards.js.map +1 -0
- package/dist/react/provider.d.ts +4 -4
- package/dist/react/provider.js +3 -1
- package/dist/react/provider.js.map +1 -1
- package/dist/react/useForm.d.ts +1 -1
- package/dist/react/useForm.js.map +1 -1
- package/dist/react/useList.d.ts +1 -1
- package/dist/react/useList.js.map +1 -1
- package/dist/values.d.ts +1 -1
- package/dist/values.d.ts.map +1 -1
- package/dist/values.js +5 -1
- package/dist/values.js.map +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","names":["_c"],"sources":["../../src/react/provider.tsx"],"sourcesContent":["import { type ReactNode, createContext, use } from 'react';\n\nimport type { Definition } from '@panneau/protocol';\n\nimport { type ResolveFormOptions } from '../definition/form';\nimport { type ResolvedResource, findResource, resolveResource } from '../definition/resource';\nimport type { Router } from '../list/router';\nimport { type PanneauPlugin, type PluginRegistry, createPluginRegistry } from '../plugins';\n\n/** What `PanneauProvider` gives to the hooks below it. */\nexport interface PanneauContextValue {\n plugins: PluginRegistry;\n /** The plugins as passed, including those of parent providers. */\n pluginList: readonly PanneauPlugin[];\n definition: Definition | null;\n router: Router | null;\n}\n\nconst PanneauContext = createContext<PanneauContextValue | null>(null);\n\nexport interface PanneauProviderProps {\n /** Plugins, added after those of a parent provider (so they override them). */\n plugins?: readonly PanneauPlugin[];\n /** The definition, for `useResource()`. Defaults to the parent provider's. */\n definition?: Definition | null;\n /** The router that lists keep their query in. Defaults to the parent provider's. */\n router?: Router | null;\n children?: ReactNode;\n}\n\n/**\n * Provides plugins, the definition and the router to the hooks of `@panneau/core`. Providers can\n * be nested: a nested provider adds its plugins to those of its parent.\n */\nexport function PanneauProvider({\n plugins = [],\n definition,\n router,\n children,\n}: PanneauProviderProps) {\n const parent = use(PanneauContext);\n const pluginList = [...(parent?.pluginList ?? []), ...plugins];\n const value: PanneauContextValue = {\n plugins: createPluginRegistry(pluginList),\n pluginList,\n definition: definition === undefined ? (parent?.definition ?? null) : definition,\n router: router === undefined ? (parent?.router ?? null) : router,\n };\n return <PanneauContext value={value}>{children}</PanneauContext>;\n}\n\nconst EMPTY: PanneauContextValue = {\n plugins: createPluginRegistry([]),\n pluginList: [],\n definition: null,\n router: null,\n};\n\n/** The context of the closest `PanneauProvider`, or an empty one without a provider. */\nexport function usePanneau(): PanneauContextValue {\n return use(PanneauContext) ?? EMPTY;\n}\n\n/** The plugins of the closest `PanneauProvider`, merged. */\nexport function usePlugins(): PluginRegistry {\n return usePanneau().plugins;\n}\n\n/**\n * A resource of the definition, with its form, list and abilities resolved. Throws when there is\n * no definition or no such resource.\n */\nexport function useResource(id: string, formOptions?: ResolveFormOptions): ResolvedResource {\n const { definition } = usePanneau();\n if (definition === null) {\n throw new Error('useResource() needs a definition: pass one to <PanneauProvider>.');\n }\n const resource = findResource(definition, id);\n if (resource === undefined) {\n throw new Error(`The definition has no resource \\`${id}\\`.`);\n }\n return resolveResource(resource, formOptions);\n}\n"],"mappings":";;;;;;AAkBA,
|
|
1
|
+
{"version":3,"file":"provider.js","names":["ReactNode","createContext","use","Definition","ResolveFormOptions","ResolvedResource","findResource","resolveResource","Router","PanneauPlugin","PluginRegistry","createPluginRegistry","PanneauContextValue","plugins","pluginList","definition","router","PanneauContext","PanneauProviderProps","children","PanneauProvider","t0","t1","undefined","parent","value","EMPTY","usePanneau","usePlugins","useResource","id","formOptions","$","_c","Error","resource","_c"],"sources":["../../src/react/provider.tsx"],"sourcesContent":["import { type ReactNode, createContext, use } from 'react';\n\nimport type { Definition } from '@panneau/protocol';\n\nimport { type ResolveFormOptions } from '../definition/form';\nimport { type ResolvedResource, findResource, resolveResource } from '../definition/resource';\nimport type { Router } from '../list/router';\nimport { type PanneauPlugin, type PluginRegistry, createPluginRegistry } from '../plugins';\n\n/** What `PanneauProvider` gives to the hooks below it. */\nexport interface PanneauContextValue {\n plugins: PluginRegistry;\n /** The plugins as passed, including those of parent providers. */\n pluginList: readonly PanneauPlugin[];\n definition: Definition | null;\n router: Router | null;\n}\n\nconst PanneauContext = createContext<PanneauContextValue | null>(null);\n\nexport interface PanneauProviderProps {\n /** Plugins, added after those of a parent provider (so they override them). */\n plugins?: readonly PanneauPlugin[];\n /** The definition, for `useResource()`. Defaults to the parent provider's. */\n definition?: Definition | null;\n /** The router that lists keep their query in. Defaults to the parent provider's. */\n router?: Router | null;\n children?: ReactNode;\n}\n\n/**\n * Provides plugins, the definition and the router to the hooks of `@panneau/core`. Providers can\n * be nested: a nested provider adds its plugins to those of its parent.\n */\nexport function PanneauProvider({\n plugins = [],\n definition,\n router,\n children,\n}: PanneauProviderProps) {\n const parent = use(PanneauContext);\n const pluginList = [...(parent?.pluginList ?? []), ...plugins];\n const value: PanneauContextValue = {\n plugins: createPluginRegistry(pluginList),\n pluginList,\n definition: definition === undefined ? (parent?.definition ?? null) : definition,\n router: router === undefined ? (parent?.router ?? null) : router,\n };\n return <PanneauContext value={value}>{children}</PanneauContext>;\n}\n\nconst EMPTY: PanneauContextValue = {\n plugins: createPluginRegistry([]),\n pluginList: [],\n definition: null,\n router: null,\n};\n\n/** The context of the closest `PanneauProvider`, or an empty one without a provider. */\nexport function usePanneau(): PanneauContextValue {\n return use(PanneauContext) ?? EMPTY;\n}\n\n/** The plugins of the closest `PanneauProvider`, merged. */\nexport function usePlugins(): PluginRegistry {\n return usePanneau().plugins;\n}\n\n/**\n * A resource of the definition, with its form, list and abilities resolved. Throws when there is\n * no definition or no such resource.\n */\nexport function useResource(id: string, formOptions?: ResolveFormOptions): ResolvedResource {\n const { definition } = usePanneau();\n if (definition === null) {\n throw new Error('useResource() needs a definition: pass one to <PanneauProvider>.');\n }\n const resource = findResource(definition, id);\n if (resource === undefined) {\n throw new Error(`The definition has no resource \\`${id}\\`.`);\n }\n return resolveResource(resource, formOptions);\n}\n"],"mappings":";;;;;;AAkBA,IAAMiB,iBAAiBhB,cAA0C,IAAI;;;;;AAgBrE,SAAOmB,gBAAAC,IAAA;CAAyB,MAAA,EAAAR,SAAAS,IAAAP,YAAAC,QAAAG,aAAAE;CAC5B,MAAAR,UAAAS,OAAAC,KAAAA,IAAA,CAAA,IAAAD;CAKA,MAAAE,SAAetB,IAAIe,cAAc;CACjC,MAAAH,aAAmB,CAAA,GAAKU,QAAMV,cAAN,CAAA,GAAwB,GAAMD,OAAO;CAC7D,MAAAY,QAAmC;EAAAZ,SACtBF,qBAAqBG,UAAU;EAACA;EAAAC,YAE7BA,eAAeQ,KAAAA,IAAaC,QAAMT,cAAN,OAA5BA;EAAoEC,QACxEA,WAAWO,KAAAA,IAAaC,QAAMR,UAAN,OAAxBA;CACZ;CAAE,OACK,oBAAC,gBAAD;EAAuBS;EAAQN;CAAhB,CAAA;AAA0C;AAGpE,IAAMO,QAA6B;CAC/Bb,SAASF,qBAAqB,CAAA,CAAE;CAChCG,YAAY,CAAA;CACZC,YAAY;CACZC,QAAQ;AACZ;;AAGA,SAAgBW,aAAkC;CAC9C,OAAOzB,IAAIe,cAAc,KAAKS;AAClC;;AAGA,SAAOE,aAAA;CAAA,OACID,WAAW,CAAC,CAAAd;AAAQ;;;;;AAO/B,SAAOgB,YAAAC,IAAAC,aAAA;CAAA,MAAAC,IAAAC,EAAA,CAAA;CACH,MAAA,EAAAlB,eAAuBY,WAAW;CAClC,IAAIZ,eAAe,MACf,MAAM,IAAImB,MAAM,kEAAkE;CACrF,IAAAb;CAAA,IAAAW,EAAA,OAAAjB,cAAAiB,EAAA,OAAAD,eAAAC,EAAA,OAAAF,IAAA;EACD,MAAAK,WAAiB7B,aAAaS,YAAYe,EAAE;EAC5C,IAAIK,aAAaZ,KAAAA,GACb,MAAM,IAAIW,MAAM,oCAAoCJ,GAAE,IAAK;EAExDT,KAAAd,gBAAgB4B,UAAUJ,WAAW;EAACC,EAAA,KAAAjB;EAAAiB,EAAA,KAAAD;EAAAC,EAAA,KAAAF;EAAAE,EAAA,KAAAX;CAAA,OAAAA,KAAAW,EAAA;CAAA,OAAtCX;AAAsC"}
|
package/dist/react/useForm.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Form, type FormOptions, type FormState } from '../form/form';
|
|
1
|
+
import { type Form, type FormOptions, type FormState } from '../form/form.js';
|
|
2
2
|
export interface UseFormResult extends FormState {
|
|
3
3
|
/** The form, to change values, submit, reset or resolve a conflict. */
|
|
4
4
|
form: Form;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useForm.js","names":["_c"],"sources":["../../src/react/useForm.ts"],"sourcesContent":["import { useLayoutEffect, useState, useSyncExternalStore } from 'react';\n\nimport { type Form, type FormOptions, type FormState, createForm } from '../form/form';\nimport { selectErrors, selectValue } from '../form/selectors';\n\nexport interface UseFormResult extends FormState {\n /** The form, to change values, submit, reset or resolve a conflict. */\n form: Form;\n}\n\n/**\n * Creates a form for the life of the component. `fields`, `locales`, `formatError` and `onSubmit`\n * follow the latest render; initial values and the version don't: call `form.reset()`, or give\n * the component a new `key`, to start from another item.\n *\n * Read the returned state with the selectors (`selectErrors(state, path)`,\n * `selectVisible(state, field)`…), not with the form's reading methods, which go stale with the\n * React Compiler (see {@link Form}).\n */\nexport function useForm(options: FormOptions): UseFormResult {\n const [form] = useState(() => createForm(options));\n const { fields, locales, formatError, onSubmit } = options;\n useLayoutEffect(() => {\n form.setOptions({ fields, locales, formatError, onSubmit });\n });\n const state = useSyncExternalStore(form.subscribe, form.getState, form.getState);\n return { ...state, form };\n}\n\nexport interface UseFormFieldResult {\n value: unknown;\n onChange: (value: unknown) => void;\n onBlur: () => void;\n /** Errors at the path, and at nested paths (`title.fr` for `title`). */\n errors: string[];\n touched: boolean;\n}\n\n/** Props for a controlled field at a dot path of a form. */\nexport function useFormField(form: Form, path: string): UseFormFieldResult {\n const state = useSyncExternalStore(form.subscribe, form.getState, form.getState);\n return {\n value: selectValue(state, path),\n onChange: (value) => form.setValue(path, value),\n onBlur: () => form.blur(path),\n errors: selectErrors(state, path, { nested: true }),\n touched: state.touched.has(path),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;AAmBA,
|
|
1
|
+
{"version":3,"file":"useForm.js","names":["useLayoutEffect","useState","useSyncExternalStore","Form","FormOptions","FormState","createForm","selectErrors","selectValue","UseFormResult","form","useForm","options","$","_c","t0","fields","locales","formatError","onSubmit","t1","setOptions","state","subscribe","getState","t2","UseFormFieldResult","value","onChange","onBlur","errors","touched","useFormField","path","setValue","blur","t3","nested","t4","has","t5","_c"],"sources":["../../src/react/useForm.ts"],"sourcesContent":["import { useLayoutEffect, useState, useSyncExternalStore } from 'react';\n\nimport { type Form, type FormOptions, type FormState, createForm } from '../form/form';\nimport { selectErrors, selectValue } from '../form/selectors';\n\nexport interface UseFormResult extends FormState {\n /** The form, to change values, submit, reset or resolve a conflict. */\n form: Form;\n}\n\n/**\n * Creates a form for the life of the component. `fields`, `locales`, `formatError` and `onSubmit`\n * follow the latest render; initial values and the version don't: call `form.reset()`, or give\n * the component a new `key`, to start from another item.\n *\n * Read the returned state with the selectors (`selectErrors(state, path)`,\n * `selectVisible(state, field)`…), not with the form's reading methods, which go stale with the\n * React Compiler (see {@link Form}).\n */\nexport function useForm(options: FormOptions): UseFormResult {\n const [form] = useState(() => createForm(options));\n const { fields, locales, formatError, onSubmit } = options;\n useLayoutEffect(() => {\n form.setOptions({ fields, locales, formatError, onSubmit });\n });\n const state = useSyncExternalStore(form.subscribe, form.getState, form.getState);\n return { ...state, form };\n}\n\nexport interface UseFormFieldResult {\n value: unknown;\n onChange: (value: unknown) => void;\n onBlur: () => void;\n /** Errors at the path, and at nested paths (`title.fr` for `title`). */\n errors: string[];\n touched: boolean;\n}\n\n/** Props for a controlled field at a dot path of a form. */\nexport function useFormField(form: Form, path: string): UseFormFieldResult {\n const state = useSyncExternalStore(form.subscribe, form.getState, form.getState);\n return {\n value: selectValue(state, path),\n onChange: (value) => form.setValue(path, value),\n onBlur: () => form.blur(path),\n errors: selectErrors(state, path, { nested: true }),\n touched: state.touched.has(path),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;AAmBA,SAAOW,QAAAC,SAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAAA,IAAAC;CAAA,IAAAF,EAAA,OAAAD,SAAA;EACqBG,WAAMT,WAAWM,OAAO;EAACC,EAAA,KAAAD;EAAAC,EAAA,KAAAE;CAAA,OAAAA,KAAAF,EAAA;CAAjD,MAAA,CAAAH,QAAeT,SAASc,EAAyB;CACjD,MAAA,EAAAC,QAAAC,SAAAC,aAAAC,aAAmDP;CAAQ,IAAAQ;CAAA,IAAAP,EAAA,OAAAG,UAAAH,EAAA,OAAAH,QAAAG,EAAA,OAAAK,eAAAL,EAAA,OAAAI,WAAAJ,EAAA,OAAAM,UAAA;EAC3CC,WAAA;GACZV,KAAIW,WAAY;IAAAL;IAAAC;IAAAC;IAAAC;GAAyC,CAAC;EAAC;EAC9DN,EAAA,KAAAG;EAAAH,EAAA,KAAAH;EAAAG,EAAA,KAAAK;EAAAL,EAAA,KAAAI;EAAAJ,EAAA,KAAAM;EAAAN,EAAA,KAAAO;CAAA,OAAAA,KAAAP,EAAA;CAFDb,gBAAgBoB,EAEf;CACD,MAAAE,QAAcpB,qBAAqBQ,KAAIa,WAAYb,KAAIc,UAAWd,KAAIc,QAAS;CAAE,IAAAC;CAAA,IAAAZ,EAAA,OAAAH,QAAAG,EAAA,OAAAS,OAAA;EAC1EG,KAAA;GAAA,GAAKH;GAAKZ;EAAO;EAACG,EAAA,KAAAH;EAAAG,EAAA,KAAAS;EAAAT,EAAA,MAAAY;CAAA,OAA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QAAAuB,MAAAvB,EAAA,QAAAyB,IAAA;EAL7BE,KAAA;GAAAb,OACIZ;GAAwBa,UACrBR;GAAqCS,QACvCJ;GAAqBK,QACrBM;GAA2CL,SAC1CO;EACb;EAACzB,EAAA,MAAAE;EAAAF,EAAA,MAAAO;EAAAP,EAAA,MAAAY;EAAAZ,EAAA,MAAAuB;EAAAvB,EAAA,MAAAyB;EAAAzB,EAAA,MAAA2B;CAAA,OAAAA,KAAA3B,EAAA;CAAA,OANM2B;AAMN"}
|
package/dist/react/useList.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type List, type ListOptions, type ListState } from '../list/list';
|
|
1
|
+
import { type List, type ListOptions, type ListState } from '../list/list.js';
|
|
2
2
|
export interface UseListResult extends ListState {
|
|
3
3
|
/** The list, to change the query and the selection. */
|
|
4
4
|
list: List;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useList.js","names":["_c"],"sources":["../../src/react/useList.ts"],"sourcesContent":["import { useState, useSyncExternalStore } from 'react';\n\nimport { type List, type ListOptions, type ListState, createList } from '../list/list';\nimport { usePanneau } from './provider';\n\nexport interface UseListResult extends ListState {\n /** The list, to change the query and the selection. */\n list: List;\n}\n\n/**\n * Creates a list for the life of the component. Without a `router` option, the query is kept in\n * the router of the closest `PanneauProvider`, if any. Pass `router: null` to keep it in memory.\n */\nexport function useList(options: ListOptions = {}): UseListResult {\n const context = usePanneau();\n const [list] = useState(() =>\n createList({\n ...options,\n router: options.router === undefined ? context.router : options.router,\n }),\n );\n const state = useSyncExternalStore(list.subscribe, list.getState, list.getState);\n return { ...state, list };\n}\n"],"mappings":";;;;;;;;;AAcA,
|
|
1
|
+
{"version":3,"file":"useList.js","names":["useState","useSyncExternalStore","List","ListOptions","ListState","createList","usePanneau","UseListResult","list","useList","t0","$","_c","t1","undefined","options","context","t2","router","state","subscribe","getState","t3","_c"],"sources":["../../src/react/useList.ts"],"sourcesContent":["import { useState, useSyncExternalStore } from 'react';\n\nimport { type List, type ListOptions, type ListState, createList } from '../list/list';\nimport { usePanneau } from './provider';\n\nexport interface UseListResult extends ListState {\n /** The list, to change the query and the selection. */\n list: List;\n}\n\n/**\n * Creates a list for the life of the component. Without a `router` option, the query is kept in\n * the router of the closest `PanneauProvider`, if any. Pass `router: null` to keep it in memory.\n */\nexport function useList(options: ListOptions = {}): UseListResult {\n const context = usePanneau();\n const [list] = useState(() =>\n createList({\n ...options,\n router: options.router === undefined ? context.router : options.router,\n }),\n );\n const state = useSyncExternalStore(list.subscribe, list.getState, list.getState);\n return { ...state, list };\n}\n"],"mappings":";;;;;;;;;AAcA,SAAOS,QAAAC,IAAA;CAAA,MAAAC,IAAAC,EAAA,CAAA;CAAA,IAAAC;CAAA,IAAAF,EAAA,OAAAD,IAAA;EAAiBG,KAAAH,OAAAI,KAAAA,IAAA,CAAwB,IAAxBJ;EAAyBC,EAAA,KAAAD;EAAAC,EAAA,KAAAE;CAAA,OAAAA,KAAAF,EAAA;CAAzB,MAAAI,UAAAF;CACpB,MAAAG,UAAgBV,WAAW;CAAE,IAAAW;CAAA,IAAAN,EAAA,OAAAK,WAAAL,EAAA,OAAAI,SAAA;EACLE,WACpBZ,WAAW;GAAA,GACJU;GAAOG,QACFH,QAAOG,WAAYJ,KAAAA,IAAYE,QAAOE,SAAUH,QAAOG;EACnE,CAAC;EAACP,EAAA,KAAAK;EAAAL,EAAA,KAAAI;EAAAJ,EAAA,KAAAM;CAAA,OAAAA,KAAAN,EAAA;CAJN,MAAA,CAAAH,QAAeR,SAASiB,EAKxB;CACA,MAAAE,QAAclB,qBAAqBO,KAAIY,WAAYZ,KAAIa,UAAWb,KAAIa,QAAS;CAAE,IAAAC;CAAA,IAAAX,EAAA,OAAAH,QAAAG,EAAA,OAAAQ,OAAA;EAC1EG,KAAA;GAAA,GAAKH;GAAKX;EAAO;EAACG,EAAA,KAAAH;EAAAG,EAAA,KAAAQ;EAAAR,EAAA,KAAAW;CAAA,OAAAA,KAAAX,EAAA;CAAA,OAAlBW;AAAkB"}
|
package/dist/values.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export type Values = Record<string, unknown>;
|
|
|
5
5
|
* objects and arrays are created: numeric segments create arrays.
|
|
6
6
|
*/
|
|
7
7
|
export declare function setValue<T extends Values>(values: T, path: string, value: unknown): T;
|
|
8
|
-
/** Deep equality of JSON-like values. */
|
|
8
|
+
/** Deep equality of JSON-like values. Files (`Blob`, `File`) are only equal to themselves. */
|
|
9
9
|
export declare function isEqual(a: unknown, b: unknown): boolean;
|
|
10
10
|
/** Whether `path` is `parent` or inside it (`title.fr` is inside `title`). */
|
|
11
11
|
export declare function isPathWithin(path: string, parent: string): boolean;
|
package/dist/values.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"values.d.ts","sourceRoot":"","sources":["../src/values.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAuB7C;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,CAAC,CAKrF;
|
|
1
|
+
{"version":3,"file":"values.d.ts","sourceRoot":"","sources":["../src/values.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAuB7C;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,CAAC,CAKrF;AAMD,8FAA8F;AAC9F,wBAAgB,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAoBvD;AAED,8EAA8E;AAC9E,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAElE"}
|
package/dist/values.js
CHANGED
|
@@ -24,10 +24,14 @@ function setValue(values, path, value) {
|
|
|
24
24
|
if (path === "") return value;
|
|
25
25
|
return setIn(values, path.split("."), value);
|
|
26
26
|
}
|
|
27
|
-
|
|
27
|
+
function isBlob(value) {
|
|
28
|
+
return typeof Blob !== "undefined" && value instanceof Blob;
|
|
29
|
+
}
|
|
30
|
+
/** Deep equality of JSON-like values. Files (`Blob`, `File`) are only equal to themselves. */
|
|
28
31
|
function isEqual(a, b) {
|
|
29
32
|
if (Object.is(a, b)) return true;
|
|
30
33
|
if (a === null || b === null || typeof a !== "object" || typeof b !== "object") return false;
|
|
34
|
+
if (isBlob(a) || isBlob(b)) return false;
|
|
31
35
|
if (Array.isArray(a) !== Array.isArray(b)) return false;
|
|
32
36
|
if (Array.isArray(a) && Array.isArray(b)) return a.length === b.length && a.every((item, index) => isEqual(item, b[index]));
|
|
33
37
|
const left = a;
|
package/dist/values.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"values.js","names":[],"sources":["../src/values.ts"],"sourcesContent":["/** Values of a form or an item, keyed by field name. */\nexport type Values = Record<string, unknown>;\n\nfunction isIndex(segment: string): boolean {\n return /^\\d+$/.test(segment);\n}\n\nfunction setIn(current: unknown, segments: string[], value: unknown): unknown {\n const [segment, ...rest] = segments;\n if (segment === undefined) {\n return value;\n }\n if (isIndex(segment)) {\n const array = Array.isArray(current) ? [...(current as unknown[])] : [];\n array[Number(segment)] = setIn(array[Number(segment)], rest, value);\n return array;\n }\n const record =\n current !== null && typeof current === 'object' && !Array.isArray(current)\n ? (current as Record<string, unknown>)\n : {};\n return { ...record, [segment]: setIn(record[segment], rest, value) };\n}\n\n/**\n * Returns a copy of `values` with `value` at a dot path (`title.fr`, `blocks.2.body`). Missing\n * objects and arrays are created: numeric segments create arrays.\n */\nexport function setValue<T extends Values>(values: T, path: string, value: unknown): T {\n if (path === '') {\n return value as T;\n }\n return setIn(values, path.split('.'), value) as T;\n}\n\n/** Deep equality of JSON-like values. */\nexport function isEqual(a: unknown, b: unknown): boolean {\n if (Object.is(a, b)) {\n return true;\n }\n if (a === null || b === null || typeof a !== 'object' || typeof b !== 'object') {\n return false;\n }\n if (Array.isArray(a) !== Array.isArray(b)) {\n return false;\n }\n if (Array.isArray(a) && Array.isArray(b)) {\n return a.length === b.length && a.every((item, index) => isEqual(item, b[index]));\n }\n const left = a as Record<string, unknown>;\n const right = b as Record<string, unknown>;\n const keys = new Set([...Object.keys(left), ...Object.keys(right)]);\n return [...keys].every((key) => isEqual(left[key], right[key]));\n}\n\n/** Whether `path` is `parent` or inside it (`title.fr` is inside `title`). */\nexport function isPathWithin(path: string, parent: string): boolean {\n return parent === '' || path === parent || path.startsWith(`${parent}.`);\n}\n"],"mappings":";AAGA,
|
|
1
|
+
{"version":3,"file":"values.js","names":["Values","Record","isIndex","segment","test","setIn","current","segments","value","rest","undefined","array","Array","isArray","Number","record","setValue","values","T","path","split","isBlob","Blob","isEqual","a","b","Object","is","length","every","item","index","left","right","keys","Set","key","isPathWithin","parent","startsWith"],"sources":["../src/values.ts"],"sourcesContent":["/** Values of a form or an item, keyed by field name. */\nexport type Values = Record<string, unknown>;\n\nfunction isIndex(segment: string): boolean {\n return /^\\d+$/.test(segment);\n}\n\nfunction setIn(current: unknown, segments: string[], value: unknown): unknown {\n const [segment, ...rest] = segments;\n if (segment === undefined) {\n return value;\n }\n if (isIndex(segment)) {\n const array = Array.isArray(current) ? [...(current as unknown[])] : [];\n array[Number(segment)] = setIn(array[Number(segment)], rest, value);\n return array;\n }\n const record =\n current !== null && typeof current === 'object' && !Array.isArray(current)\n ? (current as Record<string, unknown>)\n : {};\n return { ...record, [segment]: setIn(record[segment], rest, value) };\n}\n\n/**\n * Returns a copy of `values` with `value` at a dot path (`title.fr`, `blocks.2.body`). Missing\n * objects and arrays are created: numeric segments create arrays.\n */\nexport function setValue<T extends Values>(values: T, path: string, value: unknown): T {\n if (path === '') {\n return value as T;\n }\n return setIn(values, path.split('.'), value) as T;\n}\n\nfunction isBlob(value: unknown): value is Blob {\n return typeof Blob !== 'undefined' && value instanceof Blob;\n}\n\n/** Deep equality of JSON-like values. Files (`Blob`, `File`) are only equal to themselves. */\nexport function isEqual(a: unknown, b: unknown): boolean {\n if (Object.is(a, b)) {\n return true;\n }\n if (a === null || b === null || typeof a !== 'object' || typeof b !== 'object') {\n return false;\n }\n if (isBlob(a) || isBlob(b)) {\n return false;\n }\n if (Array.isArray(a) !== Array.isArray(b)) {\n return false;\n }\n if (Array.isArray(a) && Array.isArray(b)) {\n return a.length === b.length && a.every((item, index) => isEqual(item, b[index]));\n }\n const left = a as Record<string, unknown>;\n const right = b as Record<string, unknown>;\n const keys = new Set([...Object.keys(left), ...Object.keys(right)]);\n return [...keys].every((key) => isEqual(left[key], right[key]));\n}\n\n/** Whether `path` is `parent` or inside it (`title.fr` is inside `title`). */\nexport function isPathWithin(path: string, parent: string): boolean {\n return parent === '' || path === parent || path.startsWith(`${parent}.`);\n}\n"],"mappings":";AAGA,SAASE,QAAQC,SAA0B;CACvC,OAAO,QAAQC,KAAKD,OAAO;AAC/B;AAEA,SAASE,MAAMC,SAAkBC,UAAoBC,OAAyB;CAC1E,MAAM,CAACL,SAAS,GAAGM,QAAQF;CAC3B,IAAIJ,YAAYO,KAAAA,GACZ,OAAOF;CAEX,IAAIN,QAAQC,OAAO,GAAG;EAClB,MAAMQ,QAAQC,MAAMC,QAAQP,OAAO,IAAI,CAAC,GAAIA,OAAqB,IAAI,CAAA;EACrEK,MAAMG,OAAOX,OAAO,KAAKE,MAAMM,MAAMG,OAAOX,OAAO,IAAIM,MAAMD,KAAK;EAClE,OAAOG;CACX;CACA,MAAMI,SACFT,YAAY,QAAQ,OAAOA,YAAY,YAAY,CAACM,MAAMC,QAAQP,OAAO,IAClEA,UACD,CAAC;CACX,OAAO;EAAE,GAAGS;GA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-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.10",
|
|
4
4
|
"description": "The engine of Panneau: plugin registry, definition to forms and lists, form and list state, with React hooks. No UI.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"scripts": {
|
|
25
|
-
"build": "vite build &&
|
|
25
|
+
"build": "vite build && node ../../scripts/declarations.js",
|
|
26
26
|
"typecheck": "tsc --noEmit",
|
|
27
|
-
"api": "
|
|
27
|
+
"api": "node ../../scripts/declarations.js && node ../../scripts/api-report.js"
|
|
28
28
|
},
|
|
29
29
|
"publishConfig": {
|
|
30
30
|
"access": "public"
|
|
@@ -33,6 +33,6 @@
|
|
|
33
33
|
"react": "^19.2.0"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@panneau/protocol": "5.0.0-alpha.
|
|
36
|
+
"@panneau/protocol": "5.0.0-alpha.10"
|
|
37
37
|
}
|
|
38
38
|
}
|