diff options
author | srichman333 <sarah_n_richman@brown.edu> | 2024-04-16 17:44:30 -0400 |
---|---|---|
committer | srichman333 <sarah_n_richman@brown.edu> | 2024-04-16 17:44:30 -0400 |
commit | eb55f45eb18e07a006225713deedaf0083a74bf2 (patch) | |
tree | c15135ba2e2b9a7add6938c3567b2acb38cc4f14 /src/fields/util.ts | |
parent | 17cca384290a98b28c4f4a4d6bc4cf5edaef4573 (diff) | |
parent | 8925cc306bd7ee9a044a3fb2bc19dbb09c495515 (diff) |
Merge branch 'master' into sarah-ai-visualization
Diffstat (limited to 'src/fields/util.ts')
-rw-r--r-- | src/fields/util.ts | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/fields/util.ts b/src/fields/util.ts index c2ec3f13a..ad592391e 100644 --- a/src/fields/util.ts +++ b/src/fields/util.ts @@ -1,4 +1,4 @@ -import { $mobx, action, observable, runInAction, trace } from 'mobx'; +import { $mobx, action, observable, runInAction, trace, values } from 'mobx'; import { computedFn } from 'mobx-utils'; import { returnZero } from '../Utils'; import { DocServer } from '../client/DocServer'; @@ -16,6 +16,7 @@ import { RichTextField } from './RichTextField'; import { SchemaHeaderField } from './SchemaHeaderField'; import { ComputedField } from './ScriptField'; import { DocCast, ScriptCast, StrCast } from './Types'; +import { BaseException } from 'pdfjs-dist/types/src/shared/util'; function _readOnlySetter(): never { throw new Error("Documents can't be modified in read-only mode"); @@ -56,6 +57,8 @@ const _setterImpl = action(function (target: any, prop: string | symbol | number delete curValue[FieldChanged]; } + if (typeof prop === 'string' && _propSetterCB.has(prop)) _propSetterCB.get(prop)!(target[SelfProxy], value); + const effectiveAcl = GetEffectiveAcl(target); const writeMode = DocServer.getFieldWriteMode(prop as string); @@ -282,6 +285,17 @@ export function distributeAcls(key: string, acl: SharingPermissions, target: Doc dataDocChanged && updateCachedAcls(dataDoc); } +export var _propSetterCB = new Map<string, ((target: any, value: any) => void) | undefined>(); +/** + * sets a callback function to be called whenever a value is assigned to the specified field key. + * For example, this is used to "publish" documents with titles that start with '@' + * @param prop + * @param setter + */ +export function SetPropSetterCb(prop: string, setter: ((target: any, value: any) => void) | undefined) { + _propSetterCB.set(prop, setter); +} + // // target should be either a Doc or ListImpl. receiver should be a Proxy<Doc> Or List. // |