@talxis/base-controls 1.2411.1 → 1.2411.2
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useContext, useState, useEffect } from 'react';
|
|
2
|
-
import
|
|
2
|
+
import equal from 'fast-deep-equal/es6';
|
|
3
3
|
import { GridContext } from '../../GridContext.js';
|
|
4
4
|
|
|
5
5
|
const useGridController = (gridInstance) => {
|
|
@@ -9,7 +9,7 @@ const useGridController = (gridInstance) => {
|
|
|
9
9
|
useEffect(() => {
|
|
10
10
|
(async () => {
|
|
11
11
|
const newColumns = await grid.refreshColumns();
|
|
12
|
-
if (!
|
|
12
|
+
if (!equal(newColumns, columns)) {
|
|
13
13
|
setColumns(newColumns);
|
|
14
14
|
}
|
|
15
15
|
})();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGridController.js","sources":["../../../../../src/components/Grid/core/controllers/useGridController.ts"],"sourcesContent":["import { useContext, useEffect, useState } from \"react\"\nimport equal from 'fast-deep-equal/es6';\nimport { Grid } from \"../model/Grid\";\nimport { IGridColumn } from \"../interfaces/IGridColumn\";\nimport { GridContext } from \"../../GridContext\";\n\ninterface IGridController {\n columns: IGridColumn[]\n}\n\nexport const useGridController = (gridInstance?: Grid): IGridController => {\n const grid = gridInstance ?? useContext(GridContext).gridInstance;\n const [columns, setColumns] = useState<IGridColumn[]>(grid.columns);\n\n\n //only change columns and records reference if there is a change\n useEffect(() => {\n (async () => {\n const newColumns = await grid.refreshColumns();\n if(!equal(newColumns, columns)) {\n setColumns(newColumns);\n }\n })();\n }, [grid.shouldRerender]);\n return {\n columns\n }\n}"],"names":[
|
|
1
|
+
{"version":3,"file":"useGridController.js","sources":["../../../../../src/components/Grid/core/controllers/useGridController.ts"],"sourcesContent":["import { useContext, useEffect, useState } from \"react\"\nimport equal from 'fast-deep-equal/es6';\nimport { Grid } from \"../model/Grid\";\nimport { IGridColumn } from \"../interfaces/IGridColumn\";\nimport { GridContext } from \"../../GridContext\";\n\ninterface IGridController {\n columns: IGridColumn[]\n}\n\nexport const useGridController = (gridInstance?: Grid): IGridController => {\n const grid = gridInstance ?? useContext(GridContext).gridInstance;\n const [columns, setColumns] = useState<IGridColumn[]>(grid.columns);\n\n\n //only change columns and records reference if there is a change\n useEffect(() => {\n (async () => {\n const newColumns = await grid.refreshColumns();\n if(!equal(newColumns, columns)) {\n setColumns(newColumns);\n }\n })();\n }, [grid.shouldRerender]);\n return {\n columns\n }\n}"],"names":[],"mappings":";;;;AAUa,MAAA,iBAAiB,GAAG,CAAC,YAAmB,KAAqB;IACtE,MAAM,IAAI,GAAG,YAAY,IAAI,UAAU,CAAC,WAAW,CAAC,CAAC,YAAY,CAAC;AAClE,IAAA,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAgB,IAAI,CAAC,OAAO,CAAC,CAAC;;IAIpE,SAAS,CAAC,MAAK;QACX,CAAC,YAAW;AACR,YAAA,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC;AAC/C,YAAA,IAAG,CAAC,KAAK,CAAC,UAAU,EAAE,OAAO,CAAC,EAAE;gBAC5B,UAAU,CAAC,UAAU,CAAC,CAAC;AAC1B,aAAA;SACJ,GAAG,CAAC;AACT,KAAC,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC;IAC1B,OAAO;QACH,OAAO;KACV,CAAA;AACL;;;;"}
|
package/dist/hooks/useControl.js
CHANGED
|
@@ -3,8 +3,8 @@ import { merge } from 'merge-anything';
|
|
|
3
3
|
import { Liquid } from 'liquidjs';
|
|
4
4
|
import { useControlTheme } from './useControlTheme.js';
|
|
5
5
|
import { useControlSizing } from './useControlSizing.js';
|
|
6
|
-
import deepEqual from 'fast-deep-equal/es6';
|
|
7
6
|
|
|
7
|
+
const deepEqual = require('fast-deep-equal/es6');
|
|
8
8
|
/**
|
|
9
9
|
* Provides automatic checking if the given outputs are different from the provided inputs. Use the provided method any time you want
|
|
10
10
|
* to notify the framework that you wish to write changes. The hook will notify the framework only if the provided output differs from the current inputs.
|
|
@@ -56,6 +56,7 @@ const useControl = (name, props, defaultTranslations) => {
|
|
|
56
56
|
let isDirty = false;
|
|
57
57
|
for (let [key, outputValue] of Object.entries(outputs)) {
|
|
58
58
|
let parameterValue = parametersRef.current[key]?.raw;
|
|
59
|
+
//@ts-ignore - types
|
|
59
60
|
if (!deepEqual(parameterValue, outputValue)) {
|
|
60
61
|
if (outputValue === null) {
|
|
61
62
|
outputValue = undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useControl.js","sources":["../../src/hooks/useControl.ts"],"sourcesContent":["import { useEffect, useMemo, useRef } from \"react\";\nimport { IControl, IOutputs, IParameters } from \"../interfaces\";\nimport { merge } from 'merge-anything';\nimport { Liquid } from \"liquidjs\";\nimport { useControlTheme } from \"./useControlTheme\";\nimport { ITheme } from \"../interfaces/theme\";\nimport { useControlSizing } from \"./useControlSizing\";\
|
|
1
|
+
{"version":3,"file":"useControl.js","sources":["../../src/hooks/useControl.ts"],"sourcesContent":["import { useEffect, useMemo, useRef } from \"react\";\nimport { IControl, IOutputs, IParameters } from \"../interfaces\";\nimport { merge } from 'merge-anything';\nimport { Liquid } from \"liquidjs\";\nimport { useControlTheme } from \"./useControlTheme\";\nimport { ITheme } from \"../interfaces/theme\";\nimport { useControlSizing } from \"./useControlSizing\";\n\nconst deepEqual = require('fast-deep-equal/es6')\n\nexport type ITranslation<T> = {\n [Property in keyof Required<T>]: (variables?: any) => string\n};\n\nexport interface IDefaultTranslations {\n [LCID: number]: string | string[];\n [key: string]: any;\n}\n\n\nexport interface IControlController<TTranslations, TOutputs> {\n labels: Required<ITranslation<TTranslations>>,\n sizing: {\n width?: number,\n height?: number\n },\n theme: ITheme;\n onNotifyOutputChanged: (outputs: TOutputs) => void,\n}\n/**\n * Provides automatic checking if the given outputs are different from the provided inputs. Use the provided method any time you want\n * to notify the framework that you wish to write changes. The hook will notify the framework only if the provided output differs from the current inputs.\n */\nexport const useControl = <TParameters extends IParameters, TOutputs extends IOutputs, TTranslations>(name: string, props: IControl<TParameters, TOutputs, TTranslations, any>, defaultTranslations?: IDefaultTranslations): IControlController<TTranslations, TOutputs> => {\n const parametersRef = useRef<TParameters>(props.parameters);\n const sizing = useControlSizing(props.context.mode);\n const context = props.context;\n const liquid = useMemo(() => new Liquid(), []);\n const labels = useMemo(() => {\n const mergedTranslations = merge(defaultTranslations ?? {}, props.translations ?? {}) as TTranslations;\n return new Proxy(mergedTranslations as any, {\n get(target, key) {\n return (variables: any) => getLabel(key as string, mergedTranslations, variables)\n }\n }) as any;\n }, []);\n\n useEffect(() => {\n parametersRef.current = props.parameters;\n }, [props.parameters]);\n\n const getLabel = (key: string, translations: TTranslations, variables?: any): string | string[] => {\n const strigify = (value: string | string[]) => {\n if (typeof value === 'string') {\n return value;\n }\n return JSON.stringify(value);\n };\n //@ts-ignore\n const translation = translations[key];\n if (!translation) {\n console.error(`Translation for the ${key} label of the ${name} control has not been defined!`);\n return key;\n }\n if (typeof translation === 'string' || Array.isArray(translation)) {\n return strigify(translation);\n }\n let label = translation[props.context.userSettings.languageId];\n if (!label) {\n console.info(`Translation for the ${key} label of the ${name} control has not been found. Using default Czech label instead.`);\n label = translation[1029];\n }\n if (!label) {\n console.error(`Translation for the ${key} label of the ${name} control does not exists neither for Czech language and current LCID.`);\n label = key;\n }\n\n return liquid.parseAndRenderSync(strigify(label), variables);\n };\n\n const onNotifyOutputChanged = (outputs: TOutputs) => {\n let isDirty = false;\n for (let [key, outputValue] of Object.entries(outputs)) {\n let parameterValue = parametersRef.current[key]?.raw;\n //@ts-ignore - types\n if (!deepEqual(parameterValue, outputValue)) {\n if (outputValue === null) {\n outputValue = undefined;\n //@ts-ignore\n outputs[key] = undefined;\n }\n if (outputValue === \"\") {\n outputValue = undefined\n //@ts-ignore\n outputs[key] = undefined;\n }\n if (parameterValue === null) {\n parameterValue = undefined;\n }\n if (parameterValue === outputValue) {\n continue\n }\n isDirty = true;\n break;\n }\n }\n if (!isDirty) {\n return;\n }\n //console.log(`Change detected, triggering notifyOutputChanged on control ${name}.`);\n props.onNotifyOutputChanged?.(outputs);\n };\n return {\n labels,\n sizing,\n theme: useControlTheme(context.fluentDesignLanguage),\n onNotifyOutputChanged\n }\n};\n"],"names":[],"mappings":";;;;;;AAQA,MAAM,SAAS,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAA;AAqBhD;;;AAGG;AACU,MAAA,UAAU,GAAG,CAA4E,IAAY,EAAE,KAA0D,EAAE,mBAA0C,KAAiD;IACvQ,MAAM,aAAa,GAAG,MAAM,CAAc,KAAK,CAAC,UAAU,CAAC,CAAC;IAC5D,MAAM,MAAM,GAAG,gBAAgB,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AACpD,IAAA,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;AAC9B,IAAA,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC;AAC/C,IAAA,MAAM,MAAM,GAAG,OAAO,CAAC,MAAK;AACxB,QAAA,MAAM,kBAAkB,GAAG,KAAK,CAAC,mBAAmB,IAAI,EAAE,EAAE,KAAK,CAAC,YAAY,IAAI,EAAE,CAAkB,CAAC;AACvG,QAAA,OAAO,IAAI,KAAK,CAAC,kBAAyB,EAAE;YACxC,GAAG,CAAC,MAAM,EAAE,GAAG,EAAA;AACX,gBAAA,OAAO,CAAC,SAAc,KAAK,QAAQ,CAAC,GAAa,EAAE,kBAAkB,EAAE,SAAS,CAAC,CAAA;aACpF;AACJ,SAAA,CAAQ,CAAC;KACb,EAAE,EAAE,CAAC,CAAC;IAEP,SAAS,CAAC,MAAK;AACX,QAAA,aAAa,CAAC,OAAO,GAAG,KAAK,CAAC,UAAU,CAAC;AAC7C,KAAC,EAAE,CAAC,KAAK,CAAC,UAA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